1 /* $NetBSD: if_de.c,v 1.86 1999/06/01 19:17:59 thorpej Exp $ */
3 * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. The name of the author may not be used to endorse or promote products
12 * derived from this software without specific prior written permission
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 * Id: if_de.c,v 1.94 1997/07/03 16:55:07 thomas Exp
29 * DEC 21040 PCI Ethernet Controller
31 * Written by Matt Thomas
32 * BPF support code stolen directly from if_ec.c
34 * This driver supports the DEC DE435 or any other PCI
35 * board which support 21040, 21041, or 21140 (mostly).
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
41 #define TULIP_HDR_DATA
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/endian.h>
47 #include <sys/socket.h>
48 #include <sys/sockio.h>
49 #include <sys/malloc.h>
50 #include <sys/kernel.h>
51 #include <sys/module.h>
52 #include <sys/eventhandler.h>
53 #include <machine/bus.h>
54 #include <machine/resource.h>
59 #include <net/if_arp.h>
60 #include <net/ethernet.h>
61 #include <net/if_media.h>
62 #include <net/if_types.h>
63 #include <net/if_dl.h>
68 #include <netinet/in.h>
69 #include <netinet/if_ether.h>
74 #include <net/if_var.h>
76 #include <dev/pci/pcivar.h>
77 #include <dev/pci/pcireg.h>
78 #include <pci/dc21040reg.h>
81 * Intel CPUs should use I/O mapped access.
84 #define TULIP_IOMAPPED
89 * This turns on all sort of debugging stuff and make the
96 #define TULIP_PERFSTATS
101 #include <pci/if_devar.h>
104 * This module supports
105 * the DEC 21040 PCI Ethernet Controller.
106 * the DEC 21041 PCI Ethernet Controller.
107 * the DEC 21140 PCI Fast Ethernet Controller.
109 static void tulip_addr_filter(tulip_softc_t * const sc);
110 static void tulip_ifinit(void *);
111 static int tulip_ifmedia_change(struct ifnet * const ifp);
112 static void tulip_ifmedia_status(struct ifnet * const ifp,
113 struct ifmediareq *req);
114 static void tulip_ifstart(struct ifnet *ifp);
115 static void tulip_init(tulip_softc_t * const sc);
116 static void tulip_intr_shared(void *arg);
117 static void tulip_intr_normal(void *arg);
118 static void tulip_mii_autonegotiate(tulip_softc_t * const sc,
119 const unsigned phyaddr);
120 static int tulip_mii_map_abilities(tulip_softc_t * const sc,
123 tulip_mii_phy_readspecific(tulip_softc_t * const sc);
124 static unsigned tulip_mii_readreg(tulip_softc_t * const sc, unsigned devaddr,
126 static void tulip_mii_writereg(tulip_softc_t * const sc, unsigned devaddr,
127 unsigned regno, unsigned data);
128 static void tulip_reset(tulip_softc_t * const sc);
129 static void tulip_rx_intr(tulip_softc_t * const sc);
130 static int tulip_srom_decode(tulip_softc_t * const sc);
132 tulip_txput(tulip_softc_t * const sc, struct mbuf *m);
133 static void tulip_txput_setup(tulip_softc_t * const sc);
136 tulip_timeout_callback(
139 tulip_softc_t * const sc = arg;
142 TULIP_PERFSTART(timeout)
144 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING;
145 sc->tulip_probe_timeout -= 1000 / TULIP_HZ;
146 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER);
148 TULIP_PERFEND(timeout);
154 tulip_softc_t * const sc)
156 if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
158 sc->tulip_flags |= TULIP_TIMEOUTPENDING;
159 timeout(tulip_timeout_callback, sc, (hz + TULIP_HZ / 2) / TULIP_HZ);
165 tulip_softc_t * const sc)
169 * Before we are sure this is the right media we need
170 * to send a small packet to make sure there's carrier.
171 * Strangely, BNC and AUI will "see" receive data if
172 * either is connected so the transmit is the only way
173 * to verify the connectivity.
175 MGETHDR(m, M_DONTWAIT, MT_DATA);
179 * Construct a LLC TEST message which will point to ourselves.
181 bcopy(IFP2ENADDR(sc->tulip_ifp), mtod(m, struct ether_header *)->ether_dhost, 6);
182 bcopy(IFP2ENADDR(sc->tulip_ifp), mtod(m, struct ether_header *)->ether_shost, 6);
183 mtod(m, struct ether_header *)->ether_type = htons(3);
184 mtod(m, unsigned char *)[14] = 0;
185 mtod(m, unsigned char *)[15] = 0;
186 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
187 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
191 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
192 sc->tulip_intrmask |= TULIP_STS_TXINTR;
193 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
194 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
195 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
196 if ((m = tulip_txput(sc, m)) != NULL)
198 sc->tulip_probe.probe_txprobes++;
205 tulip_softc_t * const sc,
208 const tulip_media_info_t *mi = sc->tulip_mediums[media];
214 * If we are switching media, make sure we don't think there's
215 * any stale RX activity
217 sc->tulip_flags &= ~TULIP_RXACT;
218 if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
219 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
220 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx);
221 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
222 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general);
224 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general);
226 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general);
228 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity);
229 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
230 #define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL)
232 * If the cmdmode bits don't match the currently operating mode,
233 * set the cmdmode appropriately and reset the chip.
235 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
236 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
237 sc->tulip_cmdmode |= mi->mi_cmdmode;
240 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
242 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata);
243 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
245 * If the cmdmode bits don't match the currently operating mode,
246 * set the cmdmode appropriately and reset the chip.
248 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
249 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
250 sc->tulip_cmdmode |= mi->mi_cmdmode;
253 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol);
254 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata);
255 } else if (mi->mi_type == TULIP_MEDIAINFO_MII
256 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) {
258 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
260 dp = &sc->tulip_rombuf[mi->mi_reset_offset];
261 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) {
263 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
265 sc->tulip_phyaddr = mi->mi_phyaddr;
266 dp = &sc->tulip_rombuf[mi->mi_gpr_offset];
267 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) {
269 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
272 for (idx = 0; idx < mi->mi_reset_length; idx++) {
274 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]);
276 sc->tulip_phyaddr = mi->mi_phyaddr;
277 for (idx = 0; idx < mi->mi_gpr_length; idx++) {
279 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]);
282 if (sc->tulip_flags & TULIP_TRYNWAY) {
283 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
284 } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
285 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL);
286 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE);
287 sc->tulip_flags &= ~TULIP_DIDNWAY;
288 if (TULIP_IS_MEDIA_FD(media))
289 data |= PHYCTL_FULL_DUPLEX;
290 if (TULIP_IS_MEDIA_100MB(media))
291 data |= PHYCTL_SELECT_100MB;
292 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data);
299 tulip_softc_t * const sc,
302 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
303 sc->tulip_flags |= TULIP_PRINTLINKUP;
304 sc->tulip_flags |= TULIP_LINKUP;
305 sc->tulip_ifp->if_flags &= ~IFF_OACTIVE;
306 #if 0 /* XXX how does with work with ifmedia? */
307 if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
308 if (sc->tulip_ifp->if_flags & IFF_FULLDUPLEX) {
309 if (TULIP_CAN_MEDIA_FD(media)
310 && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL)
311 media = TULIP_FD_MEDIA_OF(media);
313 if (TULIP_IS_MEDIA_FD(media)
314 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL)
315 media = TULIP_HD_MEDIA_OF(media);
319 if (sc->tulip_media != media) {
321 sc->tulip_dbg.dbg_last_media = sc->tulip_media;
323 sc->tulip_media = media;
324 sc->tulip_flags |= TULIP_PRINTMEDIA;
325 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) {
326 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
327 } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) {
328 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
332 * We could set probe_timeout to 0 but setting to 3000 puts this
333 * in one central place and the only matters is tulip_link is
334 * followed by a tulip_timeout. Therefore setting it should not
335 * result in aberrant behavour.
337 sc->tulip_probe_timeout = 3000;
338 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
339 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY);
340 if (sc->tulip_flags & TULIP_INRESET) {
341 tulip_media_set(sc, sc->tulip_media);
342 } else if (sc->tulip_probe_media != sc->tulip_media) {
344 * No reason to change media if we have the right media.
353 tulip_softc_t * const sc)
355 struct ifnet *ifp = sc->tulip_ifp;
357 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
359 if (sc->tulip_flags & TULIP_PRINTMEDIA) {
360 if_printf(ifp, "enabling %s port\n",
361 tulip_mediums[sc->tulip_media]);
362 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
363 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
364 if_printf(ifp, "link up\n");
365 sc->tulip_flags &= ~TULIP_PRINTLINKUP;
369 #if defined(TULIP_DO_GPR_SENSE)
371 tulip_21140_gpr_media_sense(
372 tulip_softc_t * const sc)
374 struct ifnet *ifp sc->tulip_ifp;
375 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
376 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
380 * If one of the media blocks contained a default media flag,
383 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
384 const tulip_media_info_t *mi;
386 * Media is not supported (or is full-duplex).
388 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media))
390 if (mi->mi_type != TULIP_MEDIAINFO_GPR)
394 * Remember the media is this is the "default" media.
396 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
400 * No activity mask? Can't see if it is active if there's no mask.
402 if (mi->mi_actmask == 0)
406 * Does the activity data match?
408 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
411 #if defined(TULIP_DEBUG)
412 if_printf(ifp, "gpr_media_sense: %s: 0x%02x & 0x%02x == 0x%02x\n",
413 tulip_mediums[media],
414 TULIP_CSR_READ(sc, csr_gp) & 0xFF,
415 mi->mi_actmask, mi->mi_actdata);
418 * It does! If this is the first media we detected, then
419 * remember this media. If isn't the first, then there were
420 * multiple matches which we equate to no match (since we don't
421 * which to select (if any).
423 if (last_media == TULIP_MEDIA_UNKNOWN) {
425 } else if (last_media != media) {
426 last_media = TULIP_MEDIA_UNKNOWN;
429 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
431 #endif /* TULIP_DO_GPR_SENSE */
433 static tulip_link_status_t
434 tulip_media_link_monitor(
435 tulip_softc_t * const sc)
437 struct ifnet *ifp = sc->tulip_ifp;
438 const tulip_media_info_t * const mi = sc->tulip_mediums[sc->tulip_media];
439 tulip_link_status_t linkup = TULIP_LINK_DOWN;
442 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
443 panic("tulip_media_link_monitor: %s: botch at line %d\n",
444 tulip_mediums[sc->tulip_media],__LINE__);
446 return TULIP_LINK_UNKNOWN;
452 * Have we seen some packets? If so, the link must be good.
454 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) {
455 sc->tulip_flags &= ~TULIP_RXACT;
456 sc->tulip_probe_timeout = 3000;
457 return TULIP_LINK_UP;
460 sc->tulip_flags &= ~TULIP_RXACT;
461 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
464 * Read the PHY status register.
466 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
467 if (status & PHYSTS_AUTONEG_DONE) {
469 * If the PHY has completed autonegotiation, see the if the
470 * remote systems abilities have changed. If so, upgrade or
471 * downgrade as appropriate.
473 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
474 abilities = (abilities << 6) & status;
475 if (abilities != sc->tulip_abilities) {
476 #if defined(TULIP_DEBUG)
477 loudprintf("%s(phy%d): autonegotiation changed: 0x%04x -> 0x%04x\n",
478 ifp->if_xname, sc->tulip_phyaddr,
479 sc->tulip_abilities, abilities);
481 if (tulip_mii_map_abilities(sc, abilities)) {
482 tulip_linkup(sc, sc->tulip_probe_media);
483 return TULIP_LINK_UP;
486 * if we had selected media because of autonegotiation,
487 * we need to probe for the new media.
489 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
490 if (sc->tulip_flags & TULIP_DIDNWAY)
491 return TULIP_LINK_DOWN;
495 * The link is now up. If was down, say its back up.
497 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP)
498 linkup = TULIP_LINK_UP;
499 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
501 * No activity sensor? Assume all's well.
503 if (mi->mi_actmask == 0)
504 return TULIP_LINK_UNKNOWN;
506 * Does the activity data match?
508 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata)
509 linkup = TULIP_LINK_UP;
510 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
512 * Assume non TP ok for now.
514 if (!TULIP_IS_MEDIA_TP(sc->tulip_media))
515 return TULIP_LINK_UNKNOWN;
516 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
517 linkup = TULIP_LINK_UP;
518 #if defined(TULIP_DEBUG)
519 if (sc->tulip_probe_timeout <= 0)
520 if_printf(ifp, "sia status = 0x%08x\n",
521 TULIP_CSR_READ(sc, csr_sia_status));
523 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
524 return TULIP_LINK_UNKNOWN;
527 * We will wait for 3 seconds until the link goes into suspect mode.
529 if (sc->tulip_flags & TULIP_LINKUP) {
530 if (linkup == TULIP_LINK_UP)
531 sc->tulip_probe_timeout = 3000;
532 if (sc->tulip_probe_timeout > 0)
533 return TULIP_LINK_UP;
535 sc->tulip_flags &= ~TULIP_LINKUP;
536 if_printf(ifp, "link down: cable problem?\n");
538 #if defined(TULIP_DEBUG)
539 sc->tulip_dbg.dbg_link_downed++;
541 return TULIP_LINK_DOWN;
546 tulip_softc_t * const sc,
547 tulip_mediapoll_event_t event)
549 struct ifnet *ifp = sc->tulip_ifp;
551 #if defined(TULIP_DEBUG)
552 sc->tulip_dbg.dbg_events[event]++;
554 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
555 && event == TULIP_MEDIAPOLL_TIMER) {
556 switch (tulip_media_link_monitor(sc)) {
557 case TULIP_LINK_DOWN: {
559 * Link Monitor failed. Probe for new media.
561 event = TULIP_MEDIAPOLL_LINKFAIL;
564 case TULIP_LINK_UP: {
571 case TULIP_LINK_UNKNOWN: {
573 * We can't tell so don't bother.
580 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
581 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
582 if (TULIP_DO_AUTOSENSE(sc)) {
583 #if defined(TULIP_DEBUG)
584 sc->tulip_dbg.dbg_link_failures++;
586 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
587 if (sc->tulip_ifp->if_flags & IFF_UP)
588 tulip_reset(sc); /* restart probe */
592 #if defined(TULIP_DEBUG)
593 sc->tulip_dbg.dbg_link_pollintrs++;
597 if (event == TULIP_MEDIAPOLL_START) {
598 sc->tulip_ifp->if_flags |= IFF_OACTIVE;
599 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
601 sc->tulip_probe_mediamask = 0;
602 sc->tulip_probe_passes = 0;
603 #if defined(TULIP_DEBUG)
604 sc->tulip_dbg.dbg_media_probes++;
607 * If the SROM contained an explicit media to use, use it.
609 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX);
610 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS;
611 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
613 * connidx is defaulted to a media_unknown type.
615 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media;
616 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) {
617 tulip_linkup(sc, sc->tulip_probe_media);
622 if (sc->tulip_features & TULIP_HAVE_GPR) {
623 sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
624 sc->tulip_probe_timeout = 2000;
626 sc->tulip_probe_media = TULIP_MEDIA_MAX;
627 sc->tulip_probe_timeout = 0;
628 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
633 * Ignore txprobe failures or spurious callbacks.
635 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED
636 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) {
637 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
642 * If we really transmitted a packet, then that's the media we'll use.
644 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) {
645 if (event == TULIP_MEDIAPOLL_LINKPASS) {
646 /* XXX Check media status just to be sure */
647 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
648 #if defined(TULIP_DEBUG)
650 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
653 tulip_linkup(sc, sc->tulip_probe_media);
658 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) {
659 #if defined(TULIP_DO_GPR_SENSE)
661 * Check for media via the general purpose register.
663 * Try to sense the media via the GPR. If the same value
664 * occurs 3 times in a row then just use that.
666 if (sc->tulip_probe_timeout > 0) {
667 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
668 #if defined(TULIP_DEBUG)
669 if_printf(ifp, "media_poll: gpr sensing = %s\n",
670 tulip_mediums[new_probe_media]);
672 if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
673 if (new_probe_media == sc->tulip_probe_media) {
674 if (--sc->tulip_probe_count == 0)
675 tulip_linkup(sc, sc->tulip_probe_media);
677 sc->tulip_probe_count = 10;
680 sc->tulip_probe_media = new_probe_media;
684 #endif /* TULIP_DO_GPR_SENSE */
686 * Brute force. We cycle through each of the media types
687 * and try to transmit a packet.
689 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
690 sc->tulip_probe_media = TULIP_MEDIA_MAX;
691 sc->tulip_probe_timeout = 0;
696 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST
697 && (sc->tulip_features & TULIP_HAVE_MII)) {
698 tulip_media_t old_media = sc->tulip_probe_media;
699 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
700 switch (sc->tulip_probe_state) {
701 case TULIP_PROBE_FAILED:
702 case TULIP_PROBE_MEDIATEST: {
704 * Try the next media.
706 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask;
707 sc->tulip_probe_timeout = 0;
709 if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
711 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
713 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
717 case TULIP_PROBE_PHYAUTONEG: {
720 case TULIP_PROBE_INACTIVE: {
722 * Only probe if we autonegotiated a media that hasn't failed.
724 sc->tulip_probe_timeout = 0;
725 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) {
726 sc->tulip_probe_media = old_media;
729 tulip_linkup(sc, sc->tulip_probe_media);
734 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
735 panic("tulip_media_poll: botch at line %d\n", __LINE__);
742 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
743 #if defined(TULIP_DEBUG)
744 sc->tulip_dbg.dbg_txprobes_failed[sc->tulip_probe_media]++;
746 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
751 * switch to another media if we tried this one enough.
753 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
754 #if defined(TULIP_DEBUG)
755 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
756 if_printf(ifp, "poll media unknown!\n");
757 sc->tulip_probe_media = TULIP_MEDIA_MAX;
761 * Find the next media type to check for. Full Duplex
762 * types are not allowed.
765 sc->tulip_probe_media -= 1;
766 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
767 if (++sc->tulip_probe_passes == 3) {
768 if_printf(ifp, "autosense failed: cable problem?\n");
769 if ((sc->tulip_ifp->if_flags & IFF_UP) == 0) {
770 sc->tulip_ifp->if_flags &= ~IFF_RUNNING;
771 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
775 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */
776 sc->tulip_probe_mediamask = 0;
777 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1;
779 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL
780 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
781 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
783 #if defined(TULIP_DEBUG)
784 if_printf(ifp, "%s: probing %s\n",
785 event == TULIP_MEDIAPOLL_TXPROBE_FAILED ? "txprobe failed" : "timeout",
786 tulip_mediums[sc->tulip_probe_media]);
788 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
789 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
790 sc->tulip_probe.probe_txprobes = 0;
792 tulip_media_set(sc, sc->tulip_probe_media);
793 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
798 * If this is hanging off a phy, we know are doing NWAY and we have
799 * forced the phy to a specific speed. Wait for link up before
800 * before sending a packet.
802 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) {
803 case TULIP_MEDIAINFO_MII: {
804 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
808 case TULIP_MEDIAINFO_SIA: {
809 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) {
810 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL)
812 tulip_linkup(sc, sc->tulip_probe_media);
814 if (sc->tulip_features & TULIP_HAVE_MII)
821 case TULIP_MEDIAINFO_RESET:
822 case TULIP_MEDIAINFO_SYM:
823 case TULIP_MEDIAINFO_NONE:
824 case TULIP_MEDIAINFO_GPR: {
829 * Try to send a packet.
836 tulip_softc_t * const sc)
838 if (sc->tulip_features & TULIP_HAVE_GPR) {
839 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
841 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata);
844 * If this board has no media, just return
846 if (sc->tulip_features & TULIP_HAVE_NOMEDIA)
849 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
850 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
851 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START);
853 tulip_media_set(sc, sc->tulip_media);
858 tulip_21040_mediainfo_init(
859 tulip_softc_t * const sc,
862 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
863 |TULIP_CMD_BACKOFFCTR;
864 sc->tulip_ifp->if_baudrate = 10000000;
866 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) {
867 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET);
868 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD);
869 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
872 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) {
873 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC);
876 if (media == TULIP_MEDIA_UNKNOWN) {
877 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA);
882 tulip_21040_media_probe(
883 tulip_softc_t * const sc)
885 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
890 tulip_21040_10baset_only_media_probe(
891 tulip_softc_t * const sc)
893 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
894 tulip_media_set(sc, TULIP_MEDIA_10BASET);
895 sc->tulip_media = TULIP_MEDIA_10BASET;
899 tulip_21040_10baset_only_media_select(
900 tulip_softc_t * const sc)
902 sc->tulip_flags |= TULIP_LINKUP;
903 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
904 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
905 sc->tulip_flags &= ~TULIP_SQETEST;
907 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
908 sc->tulip_flags |= TULIP_SQETEST;
910 tulip_media_set(sc, sc->tulip_media);
914 tulip_21040_auibnc_only_media_probe(
915 tulip_softc_t * const sc)
917 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
918 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
919 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
920 sc->tulip_media = TULIP_MEDIA_AUIBNC;
924 tulip_21040_auibnc_only_media_select(
925 tulip_softc_t * const sc)
927 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
928 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
931 static const tulip_boardsw_t tulip_21040_boardsw = {
933 tulip_21040_media_probe,
938 static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = {
940 tulip_21040_10baset_only_media_probe,
941 tulip_21040_10baset_only_media_select,
945 static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = {
947 tulip_21040_auibnc_only_media_probe,
948 tulip_21040_auibnc_only_media_select,
953 tulip_21041_mediainfo_init(
954 tulip_softc_t * const sc)
956 tulip_media_info_t * const mi = sc->tulip_mediainfo;
959 if (sc->tulip_revinfo >= 0x20) {
960 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET);
961 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD);
962 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI);
963 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC);
967 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET);
968 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD);
969 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
970 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
974 tulip_21041_media_probe(
975 tulip_softc_t * const sc)
977 sc->tulip_ifp->if_baudrate = 10000000;
978 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
979 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
980 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
981 tulip_21041_mediainfo_init(sc);
985 tulip_21041_media_poll(
986 tulip_softc_t * const sc,
987 const tulip_mediapoll_event_t event)
989 u_int32_t sia_status;
991 #if defined(TULIP_DEBUG)
992 sc->tulip_dbg.dbg_events[event]++;
995 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
996 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
997 || !TULIP_DO_AUTOSENSE(sc))
999 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
1000 tulip_reset(sc); /* start probe */
1005 * If we've been been asked to start a poll or link change interrupt
1006 * restart the probe (and reset the tulip to a known state).
1008 if (event == TULIP_MEDIAPOLL_START) {
1009 sc->tulip_ifp->if_flags |= IFF_OACTIVE;
1010 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN);
1012 if (sc->tulip_revinfo >= 0x20) {
1013 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
1014 sc->tulip_flags |= TULIP_DIDNWAY;
1017 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1018 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1019 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1020 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT;
1021 tulip_media_set(sc, TULIP_MEDIA_10BASET);
1026 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1029 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
1030 #if defined(TULIP_DEBUG)
1031 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
1033 tulip_linkup(sc, sc->tulip_probe_media);
1037 sia_status = TULIP_CSR_READ(sc, csr_sia_status);
1038 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status);
1039 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) {
1040 if (sc->tulip_revinfo >= 0x20) {
1041 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6)))
1042 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1045 * If the link has passed LinkPass, 10baseT is the
1046 * proper media to use.
1048 tulip_linkup(sc, sc->tulip_probe_media);
1053 * wait for up to 2.4 seconds for the link to reach pass state.
1054 * Only then start scanning the other media for activity.
1055 * choose media with receive activity over those without.
1057 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) {
1058 if (event != TULIP_MEDIAPOLL_TIMER)
1060 if (sc->tulip_probe_timeout > 0
1061 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
1065 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1066 sc->tulip_flags |= TULIP_WANTRXACT;
1067 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) {
1068 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1070 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1072 tulip_media_set(sc, sc->tulip_probe_media);
1078 * If we failed, clear the txprobe active flag.
1080 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED)
1081 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1084 if (event == TULIP_MEDIAPOLL_TIMER) {
1086 * If we've received something, then that's our link!
1088 if (sc->tulip_flags & TULIP_RXACT) {
1089 tulip_linkup(sc, sc->tulip_probe_media);
1093 * if no txprobe active
1095 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0
1096 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0
1097 || (sia_status & TULIP_SIASTS_RXACTIVITY))) {
1098 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1104 * Take 2 passes through before deciding to not
1105 * wait for receive activity. Then take another
1106 * two passes before spitting out a warning.
1108 if (sc->tulip_probe_timeout <= 0) {
1109 if (sc->tulip_flags & TULIP_WANTRXACT) {
1110 sc->tulip_flags &= ~TULIP_WANTRXACT;
1111 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1113 if_printf(sc->tulip_ifp,
1114 "autosense failed: cable problem?\n");
1115 if ((sc->tulip_ifp->if_flags & IFF_UP) == 0) {
1116 sc->tulip_ifp->if_flags &= ~IFF_RUNNING;
1117 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1125 * Since this media failed to probe, try the other one.
1127 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1128 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) {
1129 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1131 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1133 tulip_media_set(sc, sc->tulip_probe_media);
1134 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1138 static const tulip_boardsw_t tulip_21041_boardsw = {
1139 TULIP_21041_GENERIC,
1140 tulip_21041_media_probe,
1142 tulip_21041_media_poll
1145 static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
1146 { 0x20005c00, 0, /* 08-00-17 */
1148 { 0x19, 0x0040, 0x0040 }, /* 10TX */
1149 { 0x19, 0x0040, 0x0000 }, /* 100TX */
1151 #if defined(TULIP_DEBUG)
1155 { 0x0281F400, 0, /* 00-A0-7D */
1157 { 0x12, 0x0010, 0x0000 }, /* 10T */
1159 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1160 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1162 #if defined(TULIP_DEBUG)
1167 { 0x0015F420, 0, /* 00-A0-7D */
1169 { 0x12, 0x0010, 0x0000 }, /* 10T */
1171 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1172 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1174 #if defined(TULIP_DEBUG)
1179 { 0x0281F400, 0, /* 00-A0-BE */
1181 { 0x11, 0x8000, 0x0000 }, /* 10T */
1182 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1184 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1186 #if defined(TULIP_DEBUG)
1193 static tulip_media_t
1194 tulip_mii_phy_readspecific(
1195 tulip_softc_t * const sc)
1197 const tulip_phy_attr_t *attr;
1201 static const tulip_media_t table[] = {
1202 TULIP_MEDIA_UNKNOWN,
1203 TULIP_MEDIA_10BASET,
1204 TULIP_MEDIA_100BASETX,
1205 TULIP_MEDIA_100BASET4,
1206 TULIP_MEDIA_UNKNOWN,
1207 TULIP_MEDIA_10BASET_FD,
1208 TULIP_MEDIA_100BASETX_FD,
1213 * Don't read phy specific registers if link is not up.
1215 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
1216 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS))
1217 return TULIP_MEDIA_UNKNOWN;
1219 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) |
1220 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH);
1221 for (attr = tulip_mii_phy_attrlist;; attr++) {
1222 if (attr->attr_id == 0)
1223 return TULIP_MEDIA_UNKNOWN;
1224 if ((id & ~0x0F) == attr->attr_id)
1228 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
1229 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100TX];
1230 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1231 if ((data & pm->pm_mask) == pm->pm_value)
1234 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) {
1235 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100T4];
1236 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1237 if ((data & pm->pm_mask) == pm->pm_value)
1240 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) {
1241 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_10T];
1242 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1243 if ((data & pm->pm_mask) == pm->pm_value)
1246 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) {
1247 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
1248 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1249 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
1255 tulip_mii_get_phyaddr(
1256 tulip_softc_t * const sc,
1261 for (phyaddr = 1; phyaddr < 32; phyaddr++) {
1262 unsigned status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1263 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1270 unsigned status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
1271 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1272 return TULIP_MII_NOPHY;
1275 return TULIP_MII_NOPHY;
1279 tulip_mii_map_abilities(
1280 tulip_softc_t * const sc,
1283 sc->tulip_abilities = abilities;
1284 if (abilities & PHYSTS_100BASETX_FD) {
1285 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD;
1286 } else if (abilities & PHYSTS_100BASET4) {
1287 sc->tulip_probe_media = TULIP_MEDIA_100BASET4;
1288 } else if (abilities & PHYSTS_100BASETX) {
1289 sc->tulip_probe_media = TULIP_MEDIA_100BASETX;
1290 } else if (abilities & PHYSTS_10BASET_FD) {
1291 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1292 } else if (abilities & PHYSTS_10BASET) {
1293 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1295 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1298 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1303 tulip_mii_autonegotiate(
1304 tulip_softc_t * const sc,
1305 const unsigned phyaddr)
1307 struct ifnet *ifp = sc->tulip_ifp;
1309 switch (sc->tulip_probe_state) {
1310 case TULIP_PROBE_MEDIATEST:
1311 case TULIP_PROBE_INACTIVE: {
1312 sc->tulip_flags |= TULIP_DIDNWAY;
1313 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET);
1314 sc->tulip_probe_timeout = 3000;
1315 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR;
1316 sc->tulip_probe_state = TULIP_PROBE_PHYRESET;
1319 case TULIP_PROBE_PHYRESET: {
1321 u_int32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1322 if (data & PHYCTL_RESET) {
1323 if (sc->tulip_probe_timeout > 0) {
1327 printf("%s(phy%d): error: reset of PHY never completed!\n",
1328 ifp->if_xname, phyaddr);
1329 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1330 sc->tulip_probe_state = TULIP_PROBE_FAILED;
1331 sc->tulip_ifp->if_flags &= ~(IFF_UP|IFF_RUNNING);
1334 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1335 if ((status & PHYSTS_CAN_AUTONEG) == 0) {
1336 #if defined(TULIP_DEBUG)
1337 loudprintf("%s(phy%d): autonegotiation disabled\n",
1338 ifp->if_xname, phyaddr);
1340 sc->tulip_flags &= ~TULIP_DIDNWAY;
1341 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1344 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01))
1345 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
1346 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
1347 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1348 #if defined(TULIP_DEBUG)
1349 if ((data & PHYCTL_AUTONEG_ENABLE) == 0)
1350 loudprintf("%s(phy%d): oops: enable autonegotiation failed: 0x%04x\n",
1351 ifp->if_xname, phyaddr, data);
1353 loudprintf("%s(phy%d): autonegotiation restarted: 0x%04x\n",
1354 ifp->if_xname, phyaddr, data);
1355 sc->tulip_dbg.dbg_nway_starts++;
1357 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
1358 sc->tulip_probe_timeout = 3000;
1361 case TULIP_PROBE_PHYAUTONEG: {
1362 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1364 if ((status & PHYSTS_AUTONEG_DONE) == 0) {
1365 if (sc->tulip_probe_timeout > 0) {
1369 #if defined(TULIP_DEBUG)
1370 loudprintf("%s(phy%d): autonegotiation timeout: sts=0x%04x, ctl=0x%04x\n",
1371 ifp->if_xname, phyaddr, status,
1372 tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL));
1374 sc->tulip_flags &= ~TULIP_DIDNWAY;
1375 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1378 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
1379 #if defined(TULIP_DEBUG)
1380 loudprintf("%s(phy%d): autonegotiation complete: 0x%04x\n",
1381 ifp->if_xname, phyaddr, data);
1383 data = (data << 6) & status;
1384 if (!tulip_mii_map_abilities(sc, data))
1385 sc->tulip_flags &= ~TULIP_DIDNWAY;
1389 #if defined(DIAGNOSTIC)
1390 panic("tulip_media_poll: botch at line %d\n", __LINE__);
1395 #if defined(TULIP_DEBUG)
1396 loudprintf("%s(phy%d): autonegotiation failure: state = %d\n",
1397 ifp->if_xname, phyaddr, sc->tulip_probe_state);
1398 sc->tulip_dbg.dbg_nway_failures++;
1403 tulip_2114x_media_preset(
1404 tulip_softc_t * const sc)
1406 const tulip_media_info_t *mi = NULL;
1407 tulip_media_t media = sc->tulip_media;
1409 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1410 media = sc->tulip_media;
1412 media = sc->tulip_probe_media;
1414 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
1415 sc->tulip_flags &= ~TULIP_SQETEST;
1416 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
1417 #if defined(TULIP_DEBUG)
1418 if (media < TULIP_MEDIA_MAX && sc->tulip_mediums[media] != NULL) {
1420 mi = sc->tulip_mediums[media];
1421 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
1422 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1423 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR
1424 || mi->mi_type == TULIP_MEDIAINFO_SYM) {
1425 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
1426 sc->tulip_cmdmode |= mi->mi_cmdmode;
1427 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
1428 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
1430 #if defined(TULIP_DEBUG)
1432 if_printf(sc->tulip_ifp, "preset: bad media %d!\n", media);
1437 case TULIP_MEDIA_BNC:
1438 case TULIP_MEDIA_AUI:
1439 case TULIP_MEDIA_10BASET: {
1440 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1441 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
1442 sc->tulip_ifp->if_baudrate = 10000000;
1443 sc->tulip_flags |= TULIP_SQETEST;
1446 case TULIP_MEDIA_10BASET_FD: {
1447 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
1448 sc->tulip_ifp->if_baudrate = 10000000;
1451 case TULIP_MEDIA_100BASEFX:
1452 case TULIP_MEDIA_100BASET4:
1453 case TULIP_MEDIA_100BASETX: {
1454 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL);
1455 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1456 sc->tulip_ifp->if_baudrate = 100000000;
1459 case TULIP_MEDIA_100BASEFX_FD:
1460 case TULIP_MEDIA_100BASETX_FD: {
1461 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT;
1462 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
1463 sc->tulip_ifp->if_baudrate = 100000000;
1470 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1474 ********************************************************************
1475 * Start of 21140/21140A support which does not use the MII interface
1479 tulip_null_media_poll(
1480 tulip_softc_t * const sc,
1481 tulip_mediapoll_event_t event)
1483 #if defined(TULIP_DEBUG)
1484 sc->tulip_dbg.dbg_events[event]++;
1486 #if defined(DIAGNOSTIC)
1487 if_printf(sc->tulip_ifp, "botch(media_poll) at line %d\n", __LINE__);
1491 __inline static void
1492 tulip_21140_mediainit(
1493 tulip_softc_t * const sc,
1494 tulip_media_info_t * const mip,
1495 tulip_media_t const media,
1499 sc->tulip_mediums[media] = mip;
1500 mip->mi_type = TULIP_MEDIAINFO_GPR;
1501 mip->mi_cmdmode = cmdmode;
1502 mip->mi_gpdata = gpdata;
1506 tulip_21140_evalboard_media_probe(
1507 tulip_softc_t * const sc)
1509 tulip_media_info_t *mip = sc->tulip_mediainfo;
1511 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1512 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1513 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1514 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1515 TULIP_CSR_WRITE(sc, csr_command,
1516 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1517 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1518 TULIP_CSR_WRITE(sc, csr_command,
1519 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1521 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
1522 sc->tulip_media = TULIP_MEDIA_10BASET;
1524 sc->tulip_media = TULIP_MEDIA_100BASETX;
1526 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1528 TULIP_CMD_TXTHRSHLDCTL);
1529 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1531 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1532 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1534 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1535 |TULIP_CMD_SCRAMBLER);
1536 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1538 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1539 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1542 static const tulip_boardsw_t tulip_21140_eb_boardsw = {
1544 tulip_21140_evalboard_media_probe,
1546 tulip_null_media_poll,
1547 tulip_2114x_media_preset,
1551 tulip_21140_accton_media_probe(
1552 tulip_softc_t * const sc)
1554 tulip_media_info_t *mip = sc->tulip_mediainfo;
1557 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1558 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1559 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1560 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1561 TULIP_CSR_WRITE(sc, csr_command,
1562 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1563 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1564 TULIP_CSR_WRITE(sc, csr_command,
1565 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1567 gpdata = TULIP_CSR_READ(sc, csr_gp);
1568 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) {
1569 sc->tulip_media = TULIP_MEDIA_10BASET;
1571 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) {
1572 sc->tulip_media = TULIP_MEDIA_BNC;
1574 sc->tulip_media = TULIP_MEDIA_100BASETX;
1577 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC,
1578 TULIP_GP_EN1207_BNC_INIT,
1579 TULIP_CMD_TXTHRSHLDCTL);
1580 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1581 TULIP_GP_EN1207_UTP_INIT,
1582 TULIP_CMD_TXTHRSHLDCTL);
1583 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1584 TULIP_GP_EN1207_UTP_INIT,
1585 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1586 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1587 TULIP_GP_EN1207_100_INIT,
1588 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1589 |TULIP_CMD_SCRAMBLER);
1590 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1591 TULIP_GP_EN1207_100_INIT,
1592 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1593 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1596 static const tulip_boardsw_t tulip_21140_accton_boardsw = {
1598 tulip_21140_accton_media_probe,
1600 tulip_null_media_poll,
1601 tulip_2114x_media_preset,
1605 tulip_21140_smc9332_media_probe(
1606 tulip_softc_t * const sc)
1608 tulip_media_info_t *mip = sc->tulip_mediainfo;
1611 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE);
1612 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
1613 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
1614 33MHz that comes to two microseconds but wait a
1615 bit longer anyways) */
1616 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT |
1617 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1618 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS;
1619 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT;
1620 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET);
1621 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT);
1623 for (idx = 1000; idx > 0; idx--) {
1624 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1625 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) {
1628 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
1635 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1636 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1637 TULIP_GP_SMC_9332_INIT,
1638 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1639 |TULIP_CMD_SCRAMBLER);
1640 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1641 TULIP_GP_SMC_9332_INIT,
1642 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1643 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1644 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1645 TULIP_GP_SMC_9332_INIT,
1646 TULIP_CMD_TXTHRSHLDCTL);
1647 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1648 TULIP_GP_SMC_9332_INIT,
1649 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1652 static const tulip_boardsw_t tulip_21140_smc9332_boardsw = {
1653 TULIP_21140_SMC_9332,
1654 tulip_21140_smc9332_media_probe,
1656 tulip_null_media_poll,
1657 tulip_2114x_media_preset,
1661 tulip_21140_cogent_em100_media_probe(
1662 tulip_softc_t * const sc)
1664 tulip_media_info_t *mip = sc->tulip_mediainfo;
1665 u_int32_t cmdmode = TULIP_CSR_READ(sc, csr_command);
1667 sc->tulip_gpinit = TULIP_GP_EM100_PINS;
1668 sc->tulip_gpdata = TULIP_GP_EM100_INIT;
1669 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS);
1670 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT);
1672 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE;
1673 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER);
1674 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1675 TULIP_CSR_WRITE(sc, csr_command, cmdmode);
1676 sc->tulip_media = TULIP_MEDIA_100BASEFX;
1678 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX,
1679 TULIP_GP_EM100_INIT,
1680 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION);
1681 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD,
1682 TULIP_GP_EM100_INIT,
1683 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1684 |TULIP_CMD_FULLDUPLEX);
1686 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);
1687 sc->tulip_media = TULIP_MEDIA_100BASETX;
1688 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1689 TULIP_GP_EM100_INIT,
1690 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1691 |TULIP_CMD_SCRAMBLER);
1692 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1693 TULIP_GP_EM100_INIT,
1694 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1695 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1699 static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {
1700 TULIP_21140_COGENT_EM100,
1701 tulip_21140_cogent_em100_media_probe,
1703 tulip_null_media_poll,
1704 tulip_2114x_media_preset
1708 tulip_21140_znyx_zx34x_media_probe(
1709 tulip_softc_t * const sc)
1711 tulip_media_info_t *mip = sc->tulip_mediainfo;
1712 int cnt10 = 0, cnt100 = 0, idx;
1714 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS;
1715 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT;
1716 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS);
1717 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT);
1718 TULIP_CSR_WRITE(sc, csr_command,
1719 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1720 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1721 TULIP_CSR_WRITE(sc, csr_command,
1722 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1725 for (idx = 1000; idx > 0; idx--) {
1726 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1727 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)) {
1730 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
1739 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1740 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1741 TULIP_GP_ZX34X_INIT,
1742 TULIP_CMD_TXTHRSHLDCTL);
1743 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1744 TULIP_GP_ZX34X_INIT,
1745 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1746 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1747 TULIP_GP_ZX34X_INIT,
1748 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1749 |TULIP_CMD_SCRAMBLER);
1750 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1751 TULIP_GP_ZX34X_INIT,
1752 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1753 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1756 static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = {
1757 TULIP_21140_ZNYX_ZX34X,
1758 tulip_21140_znyx_zx34x_media_probe,
1760 tulip_null_media_poll,
1761 tulip_2114x_media_preset,
1765 tulip_2114x_media_probe(
1766 tulip_softc_t * const sc)
1768 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE
1769 |TULIP_CMD_BACKOFFCTR|TULIP_CMD_THRSHLD72;
1772 static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
1774 tulip_2114x_media_probe,
1777 tulip_2114x_media_preset,
1781 * ******** END of chip-specific handlers. ***********
1785 * Code the read the SROM and MII bit streams (I2C)
1787 #define EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
1791 tulip_softc_t * const sc)
1795 csr = SROMSEL ; EMIT;
1796 csr = SROMSEL | SROMRD; EMIT;
1797 csr ^= SROMCS; EMIT;
1798 csr ^= SROMCLKON; EMIT;
1801 * Write 25 cycles of 0 which will force the SROM to be idle.
1803 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1804 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1805 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1807 csr ^= SROMCLKOFF; EMIT;
1808 csr ^= SROMCS; EMIT;
1815 tulip_softc_t * const sc)
1818 const unsigned bitwidth = SROM_BITWIDTH;
1819 const unsigned cmdmask = (SROMCMD_RD << bitwidth);
1820 const unsigned msb = 1 << (bitwidth + 3 - 1);
1821 unsigned lastidx = (1 << bitwidth) - 1;
1823 tulip_srom_idle(sc);
1825 for (idx = 0; idx <= lastidx; idx++) {
1826 unsigned lastbit, data, bits, bit, csr;
1827 csr = SROMSEL ; EMIT;
1828 csr = SROMSEL | SROMRD; EMIT;
1829 csr ^= SROMCSON; EMIT;
1830 csr ^= SROMCLKON; EMIT;
1833 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
1834 const unsigned thisbit = bits & msb;
1835 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1836 if (thisbit != lastbit) {
1837 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1841 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1844 csr ^= SROMCLKOFF; EMIT;
1846 for (data = 0, bits = 0; bits < 16; bits++) {
1848 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1849 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1850 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1852 sc->tulip_rombuf[idx*2] = data & 0xFF;
1853 sc->tulip_rombuf[idx*2+1] = data >> 8;
1854 csr = SROMSEL | SROMRD; EMIT;
1857 tulip_srom_idle(sc);
1860 #define MII_EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
1863 tulip_mii_writebits(
1864 tulip_softc_t * const sc,
1868 unsigned msb = 1 << (bits - 1);
1869 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1870 unsigned lastbit = (csr & MII_DOUT) ? msb : 0;
1872 csr |= MII_WR; MII_EMIT; /* clock low; assert write */
1874 for (; bits > 0; bits--, data <<= 1) {
1875 const unsigned thisbit = data & msb;
1876 if (thisbit != lastbit) {
1877 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */
1879 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1881 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1886 tulip_mii_turnaround(
1887 tulip_softc_t * const sc,
1890 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1892 if (cmd == MII_WRCMD) {
1893 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
1894 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1895 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1896 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */
1898 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */
1900 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1901 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1906 tulip_softc_t * const sc)
1909 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1912 for (idx = 0, data = 0; idx < 16; idx++) {
1913 data <<= 1; /* this is NOOP on the first pass through */
1914 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1915 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)
1917 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1919 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
1926 tulip_softc_t * const sc,
1930 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1933 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1934 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1935 tulip_mii_writebits(sc, MII_RDCMD, 8);
1936 tulip_mii_writebits(sc, devaddr, 5);
1937 tulip_mii_writebits(sc, regno, 5);
1938 tulip_mii_turnaround(sc, MII_RDCMD);
1940 data = tulip_mii_readbits(sc);
1941 #if defined(TULIP_DEBUG)
1942 sc->tulip_dbg.dbg_phyregs[regno][0] = data;
1943 sc->tulip_dbg.dbg_phyregs[regno][1]++;
1950 tulip_softc_t * const sc,
1955 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1956 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1957 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1958 tulip_mii_writebits(sc, MII_WRCMD, 8);
1959 tulip_mii_writebits(sc, devaddr, 5);
1960 tulip_mii_writebits(sc, regno, 5);
1961 tulip_mii_turnaround(sc, MII_WRCMD);
1962 tulip_mii_writebits(sc, data, 16);
1963 #if defined(TULIP_DEBUG)
1964 sc->tulip_dbg.dbg_phyregs[regno][2] = data;
1965 sc->tulip_dbg.dbg_phyregs[regno][3]++;
1969 #define tulip_mchash(mca) (ether_crc32_le(mca, 6) & 0x1FF)
1970 #define tulip_srom_crcok(databuf) ( \
1971 ((ether_crc32_le(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
1972 ((databuf)[126] | ((databuf)[127] << 8)))
1975 tulip_identify_dec_nic(
1976 tulip_softc_t * const sc)
1978 strcpy(sc->tulip_boardid, "DEC ");
1980 if (sc->tulip_chipid <= TULIP_21040)
1982 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0
1983 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {
1984 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);
1985 sc->tulip_boardid[D0+8] = ' ';
1991 tulip_identify_znyx_nic(
1992 tulip_softc_t * const sc)
1995 strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
1996 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
1998 sc->tulip_boardid[8] = '4';
1999 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
2000 if (znyx_ptr < 26 || znyx_ptr > 116) {
2001 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2004 /* ZX344 = 0010 .. 0013FF
2006 if (sc->tulip_rombuf[znyx_ptr] == 0x4A
2007 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52
2008 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) {
2009 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4];
2010 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) {
2011 sc->tulip_boardid[9] = '2';
2012 if (id == TULIP_ZNYX_ID_ZX342B) {
2013 sc->tulip_boardid[10] = 'B';
2014 sc->tulip_boardid[11] = ' ';
2016 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2017 } else if (id == TULIP_ZNYX_ID_ZX344) {
2018 sc->tulip_boardid[10] = '4';
2019 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2020 } else if (id == TULIP_ZNYX_ID_ZX345) {
2021 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5';
2022 } else if (id == TULIP_ZNYX_ID_ZX346) {
2023 sc->tulip_boardid[9] = '6';
2024 } else if (id == TULIP_ZNYX_ID_ZX351) {
2025 sc->tulip_boardid[8] = '5';
2026 sc->tulip_boardid[9] = '1';
2031 * Assume it's a ZX342...
2033 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2037 sc->tulip_boardid[8] = '1';
2038 if (sc->tulip_chipid == TULIP_21041) {
2039 sc->tulip_boardid[10] = '1';
2042 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) {
2043 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36];
2044 if (id == TULIP_ZNYX_ID_ZX312T) {
2045 sc->tulip_boardid[9] = '2';
2046 sc->tulip_boardid[10] = 'T';
2047 sc->tulip_boardid[11] = ' ';
2048 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2049 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) {
2050 sc->tulip_boardid[9] = '4';
2051 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2052 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2053 } else if (id == TULIP_ZNYX_ID_ZX314) {
2054 sc->tulip_boardid[9] = '4';
2055 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2056 sc->tulip_features |= TULIP_HAVE_BASEROM;
2057 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) {
2058 sc->tulip_boardid[9] = '5';
2059 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2060 } else if (id == TULIP_ZNYX_ID_ZX315) {
2061 sc->tulip_boardid[9] = '5';
2062 sc->tulip_features |= TULIP_HAVE_BASEROM;
2068 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) {
2069 sc->tulip_boardid[9] = '4';
2070 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2071 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2072 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) {
2073 sc->tulip_boardid[9] = '5';
2074 sc->tulip_boardsw = &tulip_21040_boardsw;
2075 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2076 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) {
2077 sc->tulip_boardid[9] = '2';
2078 sc->tulip_boardsw = &tulip_21040_boardsw;
2084 tulip_identify_smc_nic(
2085 tulip_softc_t * const sc)
2087 u_int32_t id1, id2, ei;
2088 int auibnc = 0, utp = 0;
2091 strcpy(sc->tulip_boardid, "SMC ");
2092 if (sc->tulip_chipid == TULIP_21041)
2094 if (sc->tulip_chipid != TULIP_21040) {
2095 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2096 strcpy(&sc->tulip_boardid[4], "9332DST ");
2097 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;
2098 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {
2099 strcpy(&sc->tulip_boardid[4], "9334BDT ");
2101 strcpy(&sc->tulip_boardid[4], "9332BDT ");
2105 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);
2106 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);
2107 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);
2109 strcpy(&sc->tulip_boardid[4], "8432");
2110 cp = &sc->tulip_boardid[8];
2112 *cp++ = 'B', auibnc = 1;
2113 if ((id1 & 0xFF) > 0x32)
2114 *cp++ = 'T', utp = 1;
2115 if ((id1 & 0x4000) == 0)
2116 *cp++ = 'A', auibnc = 1;
2118 sc->tulip_boardid[7] = '4';
2122 *cp++ = (ei ? '2' : '1');
2127 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2128 else if (!utp && auibnc)
2129 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
2133 tulip_identify_cogent_nic(
2134 tulip_softc_t * const sc)
2136 strcpy(sc->tulip_boardid, "Cogent ");
2137 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
2138 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {
2139 strcat(sc->tulip_boardid, "EM100TX ");
2140 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2141 #if defined(TULIP_COGENT_EM110TX_ID)
2142 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {
2143 strcat(sc->tulip_boardid, "EM110TX ");
2144 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2146 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
2147 strcat(sc->tulip_boardid, "EM100FX ");
2148 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2151 * Magic number (0x24001109U) is the SubVendor (0x2400) and
2152 * SubDevId (0x1109) for the ANA6944TX (EM440TX).
2154 if (*(u_int32_t *) sc->tulip_rombuf == 0x24001109U
2155 && (sc->tulip_features & TULIP_HAVE_BASEROM)) {
2157 * Cogent (Adaptec) is still mapping all INTs to INTA of
2158 * first 21140. Dumb! Dumb!
2160 strcat(sc->tulip_boardid, "EM440TX ");
2161 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2163 } else if (sc->tulip_chipid == TULIP_21040) {
2164 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2169 tulip_identify_accton_nic(
2170 tulip_softc_t * const sc)
2172 strcpy(sc->tulip_boardid, "ACCTON ");
2173 switch (sc->tulip_chipid) {
2175 strcat(sc->tulip_boardid, "EN1207 ");
2176 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
2177 sc->tulip_boardsw = &tulip_21140_accton_boardsw;
2180 strcat(sc->tulip_boardid, "EN1207TX ");
2181 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
2182 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2185 strcat(sc->tulip_boardid, "EN1203 ");
2186 sc->tulip_boardsw = &tulip_21040_boardsw;
2189 strcat(sc->tulip_boardid, "EN1203 ");
2190 sc->tulip_boardsw = &tulip_21041_boardsw;
2193 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2199 tulip_identify_asante_nic(
2200 tulip_softc_t * const sc)
2202 strcpy(sc->tulip_boardid, "Asante ");
2203 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
2204 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2205 tulip_media_info_t *mi = sc->tulip_mediainfo;
2208 * The Asante Fast Ethernet doesn't always ship with a valid
2209 * new format SROM. So if isn't in the new format, we cheat
2210 * set it up as if we had.
2213 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;
2214 sc->tulip_gpdata = 0;
2216 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);
2217 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);
2219 TULIP_CSR_WRITE(sc, csr_gp, 0);
2221 mi->mi_type = TULIP_MEDIAINFO_MII;
2222 mi->mi_gpr_length = 0;
2223 mi->mi_gpr_offset = 0;
2224 mi->mi_reset_length = 0;
2225 mi->mi_reset_offset = 0;;
2227 mi->mi_phyaddr = TULIP_MII_NOPHY;
2228 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) {
2230 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
2232 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2233 if_printf(sc->tulip_ifp, "can't find phy 0\n");
2237 sc->tulip_features |= TULIP_HAVE_MII;
2238 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2239 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2240 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD;
2241 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD;
2242 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2243 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2244 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2245 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2246 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2247 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2248 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2250 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2255 tulip_identify_compex_nic(
2256 tulip_softc_t * const sc)
2258 strcpy(sc->tulip_boardid, "COMPEX ");
2259 if (sc->tulip_chipid == TULIP_21140A) {
2261 tulip_softc_t *root_sc = NULL;
2263 strcat(sc->tulip_boardid, "400TX/PCI ");
2265 * All 4 chips on these boards share an interrupt. This code
2266 * copied from tulip_read_macaddr.
2268 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2269 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2270 root_sc = tulips[root_unit];
2272 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
2277 && root_sc->tulip_chipid == sc->tulip_chipid
2278 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2279 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2280 sc->tulip_slaves = root_sc->tulip_slaves;
2281 root_sc->tulip_slaves = sc;
2282 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
2283 printf("\nCannot find master device for %s interrupts",
2284 sc->tulip_ifp->if_xname);
2287 strcat(sc->tulip_boardid, "unknown ");
2289 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */
2295 tulip_softc_t * const sc)
2297 unsigned idx1, idx2, idx3;
2299 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
2300 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
2301 tulip_srom_media_t srom_media;
2302 tulip_media_info_t *mi = sc->tulip_mediainfo;
2304 u_int32_t leaf_offset, blocks, data;
2306 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
2307 if (shp->sh_adapter_count == 1)
2309 if (saip->sai_device == sc->tulip_pci_devno)
2313 * Didn't find the right media block for this card.
2315 if (idx1 == shp->sh_adapter_count)
2319 * Save the hardware address.
2321 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6);
2323 * If this is a multiple port card, add the adapter index to the last
2324 * byte of the hardware address. (if it isn't multiport, adding 0
2327 sc->tulip_enaddr[5] += idx1;
2329 leaf_offset = saip->sai_leaf_offset_lowbyte
2330 + saip->sai_leaf_offset_highbyte * 256;
2331 dp = sc->tulip_rombuf + leaf_offset;
2333 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2;
2335 for (idx2 = 0;; idx2++) {
2336 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype
2337 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED)
2340 sc->tulip_connidx = idx2;
2342 if (sc->tulip_chipid == TULIP_21041) {
2344 for (idx2 = 0; idx2 < blocks; idx2++) {
2345 tulip_media_t media;
2347 srom_media = (tulip_srom_media_t) (data & 0x3F);
2348 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2349 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2352 media = tulip_srom_mediums[idx3].sm_type;
2353 if (media != TULIP_MEDIA_UNKNOWN) {
2354 if (data & TULIP_SROM_21041_EXTENDED) {
2355 mi->mi_type = TULIP_MEDIAINFO_SIA;
2356 sc->tulip_mediums[media] = mi;
2357 mi->mi_sia_connectivity = dp[0] + dp[1] * 256;
2358 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256;
2359 mi->mi_sia_general = dp[4] + dp[5] * 256;
2363 case TULIP_MEDIA_BNC: {
2364 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
2368 case TULIP_MEDIA_AUI: {
2369 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
2373 case TULIP_MEDIA_10BASET: {
2374 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
2378 case TULIP_MEDIA_10BASET_FD: {
2379 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
2389 if (data & TULIP_SROM_21041_EXTENDED)
2394 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++;
2395 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++;
2396 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++;
2397 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++;
2401 unsigned length, type;
2402 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN;
2403 if (sc->tulip_features & TULIP_HAVE_GPR)
2404 sc->tulip_gpinit = *dp++;
2406 for (idx2 = 0; idx2 < blocks; idx2++) {
2408 if ((*dp & 0x80) == 0) {
2412 length = (*dp++ & 0x7f) - 1;
2413 type = *dp++ & 0x3f;
2416 switch (type & 0x3f) {
2417 case 0: { /* 21140[A] GPR block */
2418 tulip_media_t media;
2419 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2420 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2421 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2424 media = tulip_srom_mediums[idx3].sm_type;
2425 if (media == TULIP_MEDIA_UNKNOWN)
2427 mi->mi_type = TULIP_MEDIAINFO_GPR;
2428 sc->tulip_mediums[media] = mi;
2429 mi->mi_gpdata = dp[1];
2430 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) {
2431 sc->tulip_gpdata = mi->mi_gpdata;
2434 data = dp[2] + dp[3] * 256;
2435 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2436 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2440 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2442 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2443 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2448 case 1: { /* 21140[A] MII block */
2449 const unsigned phyno = *dp++;
2450 mi->mi_type = TULIP_MEDIAINFO_MII;
2451 mi->mi_gpr_length = *dp++;
2452 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2453 dp += mi->mi_gpr_length;
2454 mi->mi_reset_length = *dp++;
2455 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2456 dp += mi->mi_reset_length;
2459 * Before we probe for a PHY, use the GPR information
2460 * to select it. If we don't, it may be inaccessible.
2462 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET);
2463 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) {
2465 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]);
2467 sc->tulip_phyaddr = mi->mi_phyaddr;
2468 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) {
2470 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]);
2474 * At least write something!
2476 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2477 TULIP_CSR_WRITE(sc, csr_gp, 0);
2479 mi->mi_phyaddr = TULIP_MII_NOPHY;
2480 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2482 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2484 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2485 #if defined(TULIP_DEBUG)
2486 if_printf(sc->tulip_ifp, "can't find phy %d\n",
2491 sc->tulip_features |= TULIP_HAVE_MII;
2492 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2493 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2494 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2495 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2496 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2497 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2498 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2499 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2500 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2501 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2502 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2506 case 2: { /* 2114[23] SIA block */
2507 tulip_media_t media;
2508 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2509 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2510 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2513 media = tulip_srom_mediums[idx3].sm_type;
2514 if (media == TULIP_MEDIA_UNKNOWN)
2516 mi->mi_type = TULIP_MEDIAINFO_SIA;
2517 sc->tulip_mediums[media] = mi;
2519 mi->mi_sia_connectivity = dp[1] + dp[2] * 256;
2520 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256;
2521 mi->mi_sia_general = dp[5] + dp[6] * 256;
2525 case TULIP_MEDIA_BNC: {
2526 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
2529 case TULIP_MEDIA_AUI: {
2530 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
2533 case TULIP_MEDIA_10BASET: {
2534 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
2535 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2538 case TULIP_MEDIA_10BASET_FD: {
2539 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
2540 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2548 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16;
2549 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16;
2554 case 3: { /* 2114[23] MII PHY block */
2555 const unsigned phyno = *dp++;
2556 const u_int8_t *dp0;
2557 mi->mi_type = TULIP_MEDIAINFO_MII;
2558 mi->mi_gpr_length = *dp++;
2559 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2560 dp += 2 * mi->mi_gpr_length;
2561 mi->mi_reset_length = *dp++;
2562 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2563 dp += 2 * mi->mi_reset_length;
2565 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset];
2566 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) {
2568 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2570 sc->tulip_phyaddr = mi->mi_phyaddr;
2571 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset];
2572 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) {
2574 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2577 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2578 TULIP_CSR_WRITE(sc, csr_sia_general, 0);
2580 mi->mi_phyaddr = TULIP_MII_NOPHY;
2581 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2583 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2585 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2586 #if defined(TULIP_DEBUG)
2587 if_printf(sc->tulip_ifp, "can't find phy %d\n",
2592 sc->tulip_features |= TULIP_HAVE_MII;
2593 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2594 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2595 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2596 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2597 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2;
2598 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2599 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2600 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2601 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2602 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2603 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2604 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2608 case 4: { /* 21143 SYM block */
2609 tulip_media_t media;
2610 srom_media = (tulip_srom_media_t) dp[0];
2611 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2612 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2615 media = tulip_srom_mediums[idx3].sm_type;
2616 if (media == TULIP_MEDIA_UNKNOWN)
2618 mi->mi_type = TULIP_MEDIAINFO_SYM;
2619 sc->tulip_mediums[media] = mi;
2620 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16;
2621 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16;
2622 data = dp[5] + dp[6] * 256;
2623 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2624 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2627 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2628 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2629 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2631 if (TULIP_IS_MEDIA_TP(media))
2632 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2637 case 5: { /* 21143 Reset block */
2638 mi->mi_type = TULIP_MEDIAINFO_RESET;
2639 mi->mi_reset_length = *dp++;
2640 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2641 dp += 2 * mi->mi_reset_length;
2652 return mi - sc->tulip_mediainfo;
2655 static const struct {
2656 void (*vendor_identify_nic)(tulip_softc_t * const sc);
2657 unsigned char vendor_oui[3];
2658 } tulip_vendors[] = {
2659 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } },
2660 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } },
2661 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } },
2662 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } },
2663 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } },
2664 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } },
2665 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } },
2666 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } },
2667 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } },
2668 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } },
2673 * This deals with the vagaries of the address roms and the
2674 * brain-deadness that various vendors commit in using them.
2678 tulip_softc_t * const sc)
2680 unsigned cksum, rom_cksum, idx;
2682 unsigned char tmpbuf[8];
2683 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
2685 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX;
2687 if (sc->tulip_chipid == TULIP_21040) {
2688 TULIP_CSR_WRITE(sc, csr_enetrom, 1);
2689 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2691 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
2693 sc->tulip_rombuf[idx] = csr & 0xFF;
2695 sc->tulip_boardsw = &tulip_21040_boardsw;
2697 if (sc->tulip_chipid == TULIP_21041) {
2699 * Thankfully all 21041's act the same.
2701 sc->tulip_boardsw = &tulip_21041_boardsw;
2704 * Assume all 21140 board are compatible with the
2705 * DEC 10/100 evaluation board. Not really valid but
2706 * it's the best we can do until every one switches to
2707 * the new SROM format.
2710 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2712 tulip_srom_read(sc);
2713 if (tulip_srom_crcok(sc->tulip_rombuf)) {
2715 * SROM CRC is valid therefore it must be in the
2718 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM;
2719 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
2721 * No checksum is present. See if the SROM id checks out;
2722 * the first 18 bytes should be 0 followed by a 1 followed
2723 * by the number of adapters (which we don't deal with yet).
2725 for (idx = 0; idx < 18; idx++) {
2726 if (sc->tulip_rombuf[idx] != 0)
2729 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
2730 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2731 } else if (sc->tulip_chipid >= TULIP_21142) {
2732 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2733 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2735 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) {
2736 if (sc->tulip_chipid != TULIP_21041)
2737 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2740 * If the SROM specifies more than one adapter, tag this as a
2743 if (sc->tulip_rombuf[19] > 1)
2744 sc->tulip_features |= TULIP_HAVE_BASEROM;
2745 if (sc->tulip_boardsw == NULL)
2752 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
2754 * Some folks don't use the standard ethernet rom format
2755 * but instead just put the address in the first 6 bytes
2756 * of the rom and let the rest be all 0xffs. (Can we say
2757 * ZNYX?) (well sometimes they put in a checksum so we'll
2760 for (idx = 8; idx < 32; idx++) {
2761 if (sc->tulip_rombuf[idx] != 0xFF)
2765 * Make sure the address is not multicast or locally assigned
2766 * that the OUI is not 00-00-00.
2768 if ((sc->tulip_rombuf[0] & 3) != 0)
2770 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
2771 && sc->tulip_rombuf[2] == 0)
2773 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2774 sc->tulip_features |= TULIP_HAVE_OKROM;
2778 * A number of makers of multiport boards (ZNYX and Cogent)
2779 * only put on one address ROM on their 21040 boards. So
2780 * if the ROM is all zeros (or all 0xFFs), look at the
2781 * previous configured boards (as long as they are on the same
2782 * PCI bus and the bus number is non-zero) until we find the
2783 * master board with address ROM. We then use its address ROM
2784 * as the base for this board. (we add our relative board
2785 * to the last byte of its address).
2787 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2788 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF)
2791 if (idx == sizeof(sc->tulip_rombuf)) {
2793 tulip_softc_t *root_sc = NULL;
2794 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2795 root_sc = tulips[root_unit];
2796 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
2800 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM)
2801 && root_sc->tulip_chipid == sc->tulip_chipid
2802 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2803 sc->tulip_features |= TULIP_HAVE_SLAVEDROM;
2804 sc->tulip_boardsw = root_sc->tulip_boardsw;
2805 strcpy(sc->tulip_boardid, root_sc->tulip_boardid);
2806 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) {
2807 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf,
2808 sizeof(sc->tulip_rombuf));
2809 if (!tulip_srom_decode(sc))
2812 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
2813 sc->tulip_enaddr[5] += sc->tulip_unit - root_sc->tulip_unit;
2816 * Now for a truly disgusting kludge: all 4 21040s on
2817 * the ZX314 share the same INTA line so the mapping
2818 * setup by the BIOS on the PCI bridge is worthless.
2819 * Rather than reprogramming the value in the config
2820 * register, we will handle this internally.
2822 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) {
2823 sc->tulip_slaves = root_sc->tulip_slaves;
2824 root_sc->tulip_slaves = sc;
2825 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2833 * This is the standard DEC address ROM test.
2836 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
2839 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
2840 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
2841 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
2842 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
2843 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
2846 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2848 cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
2850 if (cksum > 65535) cksum -= 65535;
2851 cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
2852 if (cksum > 65535) cksum -= 65535;
2854 if (cksum > 65535) cksum -= 65535;
2855 cksum += *(u_int16_t *) &sc->tulip_enaddr[4];
2856 if (cksum >= 65535) cksum -= 65535;
2858 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6];
2860 if (cksum != rom_cksum)
2865 * Check for various boards based on OUI. Did I say braindead?
2867 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) {
2868 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) {
2869 (*tulip_vendors[idx].vendor_identify_nic)(sc);
2874 sc->tulip_features |= TULIP_HAVE_OKROM;
2880 tulip_softc_t * const sc)
2882 tulip_media_t media;
2885 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2886 if (sc->tulip_mediums[media] != NULL) {
2887 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media],
2893 sc->tulip_features |= TULIP_HAVE_NOMEDIA;
2894 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0);
2895 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE);
2896 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
2897 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0);
2898 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO);
2900 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]);
2901 sc->tulip_flags |= TULIP_PRINTMEDIA;
2902 tulip_linkup(sc, sc->tulip_media);
2907 tulip_ifmedia_change(
2908 struct ifnet * const ifp)
2910 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
2912 sc->tulip_flags |= TULIP_NEEDRESET;
2913 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
2914 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
2915 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) {
2916 tulip_media_t media;
2917 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2918 if (sc->tulip_mediums[media] != NULL
2919 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) {
2920 sc->tulip_flags |= TULIP_PRINTMEDIA;
2921 sc->tulip_flags &= ~TULIP_DIDNWAY;
2922 tulip_linkup(sc, media);
2927 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
2934 * Media status callback
2937 tulip_ifmedia_status(
2938 struct ifnet * const ifp,
2939 struct ifmediareq *req)
2941 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2943 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN)
2946 req->ifm_status = IFM_AVALID;
2947 if (sc->tulip_flags & TULIP_LINKUP)
2948 req->ifm_status |= IFM_ACTIVE;
2950 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
2955 tulip_softc_t * const sc)
2957 struct ifmultiaddr *ifma;
2961 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI);
2962 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART;
2963 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
2964 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
2965 #if defined(IFF_ALLMULTI)
2966 if (sc->tulip_ifp->if_flags & IFF_ALLMULTI)
2967 sc->tulip_flags |= TULIP_ALLMULTI ;
2971 TAILQ_FOREACH(ifma, &sc->tulip_ifp->if_multiaddrs, ifma_link) {
2973 if (ifma->ifma_addr->sa_family == AF_LINK)
2977 sc->tulip_ifp->if_start = tulip_ifstart; /* so the setup packet gets queued */
2978 if (multicnt > 14) {
2979 u_int32_t *sp = sc->tulip_setupdata;
2982 * Some early passes of the 21140 have broken implementations of
2983 * hash-perfect mode. When we get too many multicasts for perfect
2984 * filtering with these chips, we need to switch into hash-only
2985 * mode (this is better than all-multicast on network with lots
2986 * of multicast traffic).
2988 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
2989 sc->tulip_flags |= TULIP_WANTHASHONLY;
2991 sc->tulip_flags |= TULIP_WANTHASHPERFECT;
2993 * If we have more than 14 multicasts, we have
2994 * go into hash perfect mode (512 bit multicast
2995 * hash and one perfect hardware).
2997 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
2999 TAILQ_FOREACH(ifma, &sc->tulip_ifp->if_multiaddrs, ifma_link) {
3001 if (ifma->ifma_addr->sa_family != AF_LINK)
3004 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
3005 #if BYTE_ORDER == BIG_ENDIAN
3006 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3008 sp[hash >> 4] |= 1 << (hash & 0xF);
3012 * No reason to use a hash if we are going to be
3013 * receiving every multicast.
3015 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
3016 hash = tulip_mchash(sc->tulip_ifp->if_broadcastaddr);
3017 #if BYTE_ORDER == BIG_ENDIAN
3018 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3020 sp[hash >> 4] |= 1 << (hash & 0xF);
3022 if (sc->tulip_flags & TULIP_WANTHASHONLY) {
3023 hash = tulip_mchash(IFP2ENADDR(sc->tulip_ifp));
3024 #if BYTE_ORDER == BIG_ENDIAN
3025 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3027 sp[hash >> 4] |= 1 << (hash & 0xF);
3030 #if BYTE_ORDER == BIG_ENDIAN
3031 sp[39] = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[0] << 16;
3032 sp[40] = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[1] << 16;
3033 sp[41] = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[2] << 16;
3035 sp[39] = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[0];
3036 sp[40] = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[1];
3037 sp[41] = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[2];
3042 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
3043 u_int32_t *sp = sc->tulip_setupdata;
3045 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
3047 * Else can get perfect filtering for 16 addresses.
3049 TAILQ_FOREACH(ifma, &sc->tulip_ifp->if_multiaddrs, ifma_link) {
3050 if (ifma->ifma_addr->sa_family != AF_LINK)
3052 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
3053 #if BYTE_ORDER == BIG_ENDIAN
3054 *sp++ = ((u_int16_t *) addrp)[0] << 16;
3055 *sp++ = ((u_int16_t *) addrp)[1] << 16;
3056 *sp++ = ((u_int16_t *) addrp)[2] << 16;
3058 *sp++ = ((u_int16_t *) addrp)[0];
3059 *sp++ = ((u_int16_t *) addrp)[1];
3060 *sp++ = ((u_int16_t *) addrp)[2];
3065 * Add the broadcast address.
3068 #if BYTE_ORDER == BIG_ENDIAN
3069 *sp++ = 0xFFFF << 16;
3070 *sp++ = 0xFFFF << 16;
3071 *sp++ = 0xFFFF << 16;
3079 * Pad the rest with our hardware address
3081 for (; idx < 16; idx++) {
3082 #if BYTE_ORDER == BIG_ENDIAN
3083 *sp++ = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[0] << 16;
3084 *sp++ = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[1] << 16;
3085 *sp++ = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[2] << 16;
3087 *sp++ = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[0];
3088 *sp++ = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[1];
3089 *sp++ = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[2];
3093 #if defined(IFF_ALLMULTI)
3094 if (sc->tulip_flags & TULIP_ALLMULTI)
3095 sc->tulip_ifp->if_flags |= IFF_ALLMULTI;
3101 tulip_softc_t * const sc)
3103 tulip_ringinfo_t *ri;
3105 u_int32_t inreset = (sc->tulip_flags & TULIP_INRESET);
3108 * Brilliant. Simply brilliant. When switching modes/speeds
3109 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
3110 * bits in CSR6 and then do a software reset to get the 21140
3111 * to properly reset its internal pathways to the right places.
3114 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
3115 && sc->tulip_boardsw->bd_media_preset != NULL)
3116 (*sc->tulip_boardsw->bd_media_preset)(sc);
3118 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
3119 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
3120 33MHz that comes to two microseconds but wait a
3121 bit longer anyways) */
3124 sc->tulip_flags |= TULIP_INRESET;
3125 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
3126 sc->tulip_ifp->if_flags &= ~IFF_OACTIVE;
3127 sc->tulip_ifp->if_start = tulip_ifstart;
3130 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3131 TULIP_CSR_WRITE(sc, csr_txlist, sc->tulip_txdescmap->dm_segs[0].ds_addr);
3133 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
3135 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3136 TULIP_CSR_WRITE(sc, csr_rxlist, sc->tulip_rxdescmap->dm_segs[0].ds_addr);
3138 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
3140 TULIP_CSR_WRITE(sc, csr_busmode,
3141 (1 << (3 /*pci_max_burst_len*/ + 8))
3142 |TULIP_BUSMODE_CACHE_ALIGN8
3143 |TULIP_BUSMODE_READMULTIPLE
3144 |(BYTE_ORDER != LITTLE_ENDIAN ?
3145 TULIP_BUSMODE_DESC_BIGENDIAN : 0));
3147 sc->tulip_txtimer = 0;
3148 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
3150 * Free all the mbufs that were on the transmit ring.
3153 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3157 _IF_DEQUEUE(&sc->tulip_txq, m);
3160 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3161 map = M_GETCTX(m, bus_dmamap_t);
3162 bus_dmamap_unload(sc->tulip_dmatag, map);
3163 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
3168 ri = &sc->tulip_txinfo;
3169 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
3170 ri->ri_free = ri->ri_max;
3171 for (di = ri->ri_first; di < ri->ri_last; di++)
3173 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3174 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_txdescmap,
3175 0, sc->tulip_txdescmap->dm_mapsize,
3176 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
3180 * We need to collect all the mbufs were on the
3181 * receive ring before we reinit it either to put
3182 * them back on or to know if we have to allocate
3185 ri = &sc->tulip_rxinfo;
3186 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
3187 ri->ri_free = ri->ri_max;
3188 for (di = ri->ri_first; di < ri->ri_last; di++) {
3190 di->d_length1 = 0; di->d_addr1 = 0;
3191 di->d_length2 = 0; di->d_addr2 = 0;
3193 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3194 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_rxdescmap,
3195 0, sc->tulip_rxdescmap->dm_mapsize,
3196 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
3199 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3203 _IF_DEQUEUE(&sc->tulip_rxq, m);
3206 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3207 map = M_GETCTX(m, bus_dmamap_t);
3208 bus_dmamap_unload(sc->tulip_dmatag, map);
3209 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3215 * If tulip_reset is being called recurisvely, exit quickly knowing
3216 * that when the outer tulip_reset returns all the right stuff will
3222 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
3223 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
3224 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
3225 |TULIP_STS_RXSTOPPED;
3227 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
3228 (*sc->tulip_boardsw->bd_media_select)(sc);
3229 #if defined(TULIP_DEBUG)
3230 if ((sc->tulip_flags & TULIP_NEEDRESET) == TULIP_NEEDRESET)
3231 if_printf(sc->tulip_ifp,
3232 "tulip_reset: additional reset needed?!?\n");
3235 tulip_media_print(sc);
3236 if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
3237 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
3239 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
3241 tulip_addr_filter(sc);
3249 tulip_init((tulip_softc_t *)sc);
3254 tulip_softc_t * const sc)
3256 if (sc->tulip_ifp->if_flags & IFF_UP) {
3257 if ((sc->tulip_ifp->if_flags & IFF_RUNNING) == 0) {
3258 /* initialize the media */
3261 sc->tulip_ifp->if_flags |= IFF_RUNNING;
3262 if (sc->tulip_ifp->if_flags & IFF_PROMISC) {
3263 sc->tulip_flags |= TULIP_PROMISC;
3264 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
3265 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3267 sc->tulip_flags &= ~TULIP_PROMISC;
3268 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
3269 if (sc->tulip_flags & TULIP_ALLMULTI) {
3270 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
3272 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
3275 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
3276 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
3278 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3279 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3281 sc->tulip_ifp->if_flags |= IFF_OACTIVE;
3282 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3283 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3285 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3286 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3287 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3288 tulip_txput_setup(sc);
3290 sc->tulip_ifp->if_flags &= ~IFF_RUNNING;
3297 tulip_softc_t * const sc)
3299 TULIP_PERFSTART(rxintr)
3300 tulip_ringinfo_t * const ri = &sc->tulip_rxinfo;
3301 struct ifnet * const ifp = sc->tulip_ifp;
3303 #if defined(TULIP_DEBUG)
3308 TULIP_PERFSTART(rxget)
3309 tulip_desc_t *eop = ri->ri_nextin;
3310 int total_len = 0, last_offset = 0;
3311 struct mbuf *ms = NULL, *me = NULL;
3313 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3318 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
3321 #if defined(TULIP_DEBUG)
3322 if (cnt == ri->ri_max)
3326 * If the TULIP has no descriptors, there can't be any receive
3327 * descriptors to process.
3329 if (eop == ri->ri_nextout)
3333 * 90% of the packets will fit in one descriptor. So we optimize
3336 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3337 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
3338 _IF_DEQUEUE(&sc->tulip_rxq, ms);
3342 * If still owned by the TULIP, don't touch it.
3344 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
3348 * It is possible (though improbable unless MCLBYTES < 1518) for
3349 * a received packet to cross more than one receive descriptor.
3351 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) {
3352 if (++eop == ri->ri_last)
3354 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3355 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
3356 #if defined(TULIP_DEBUG)
3357 sc->tulip_dbg.dbg_rxintrs++;
3358 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
3360 TULIP_PERFEND(rxget);
3361 TULIP_PERFEND(rxintr);
3368 * Dequeue the first buffer for the start of the packet. Hopefully
3369 * this will be the only one we need to dequeue. However, if the
3370 * packet consumed multiple descriptors, then we need to dequeue
3371 * those buffers and chain to the starting mbuf. All buffers but
3372 * the last buffer have the same length so we can set that now.
3373 * (we add to last_offset instead of multiplying since we normally
3374 * won't go into the loop and thereby saving ourselves from
3375 * doing a multiplication by 0 in the normal case).
3377 _IF_DEQUEUE(&sc->tulip_rxq, ms);
3378 for (me = ms; total_len > 0; total_len--) {
3379 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3380 map = M_GETCTX(me, bus_dmamap_t);
3381 TULIP_RXMAP_POSTSYNC(sc, map);
3382 bus_dmamap_unload(sc->tulip_dmatag, map);
3383 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3384 #if defined(DIAGNOSTIC)
3387 #endif /* TULIP_BUS_DMA */
3388 me->m_len = TULIP_RX_BUFLEN;
3389 last_offset += TULIP_RX_BUFLEN;
3390 _IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
3396 * Now get the size of received packet (minus the CRC).
3398 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
3399 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
3400 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0)) {
3401 me->m_len = total_len - last_offset;
3403 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3404 map = M_GETCTX(me, bus_dmamap_t);
3405 bus_dmamap_sync(sc->tulip_dmatag, map, 0, me->m_len,
3406 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
3407 bus_dmamap_unload(sc->tulip_dmatag, map);
3408 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3409 #if defined(DIAGNOSTIC)
3412 #endif /* TULIP_BUS_DMA */
3414 sc->tulip_flags |= TULIP_RXACT;
3418 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3419 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3421 #if defined(TULIP_VERBOSE)
3422 const char *error = NULL;
3424 if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
3425 sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
3426 #if defined(TULIP_VERBOSE)
3427 error = "frame too long";
3430 if (eop->d_status & TULIP_DSTS_RxBADCRC) {
3431 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
3432 sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
3433 #if defined(TULIP_VERBOSE)
3434 error = "alignment error";
3437 sc->tulip_dot3stats.dot3StatsFCSErrors++;
3438 #if defined(TULIP_VERBOSE)
3443 #if defined(TULIP_VERBOSE)
3444 if (error != NULL && (sc->tulip_flags & TULIP_NOMESSAGES) == 0) {
3445 if_printf(sc->tulip_ifp, "receive: %6D: %s\n",
3446 mtod(ms, u_char *) + 6, ":",
3448 sc->tulip_flags |= TULIP_NOMESSAGES;
3453 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3454 map = M_GETCTX(me, bus_dmamap_t);
3455 bus_dmamap_unload(sc->tulip_dmatag, map);
3456 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3457 #if defined(DIAGNOSTIC)
3460 #endif /* TULIP_BUS_DMA */
3462 #if defined(TULIP_DEBUG)
3466 if (++eop == ri->ri_last)
3468 ri->ri_nextin = eop;
3471 * Either we are priming the TULIP with mbufs (m == NULL)
3472 * or we are about to accept an mbuf for the upper layers
3473 * so we need to allocate an mbuf to replace it. If we
3474 * can't replace it, send up it anyways. This may cause
3475 * us to drop packets in the future but that's better than
3476 * being caught in livelock.
3478 * Note that if this packet crossed multiple descriptors
3479 * we don't even try to reallocate all the mbufs here.
3480 * Instead we rely on the test of the beginning of
3481 * the loop to refill for the extra consumed mbufs.
3483 if (accept || ms == NULL) {
3485 MGETHDR(m0, M_DONTWAIT, MT_DATA);
3487 #if defined(TULIP_COPY_RXDATA)
3488 if (!accept || total_len >= (MHLEN - 2)) {
3490 MCLGET(m0, M_DONTWAIT);
3491 if ((m0->m_flags & M_EXT) == 0) {
3495 #if defined(TULIP_COPY_RXDATA)
3500 #if defined(TULIP_COPY_RXDATA)
3504 #if !defined(TULIP_COPY_RXDATA)
3505 ms->m_pkthdr.len = total_len;
3506 ms->m_pkthdr.rcvif = ifp;
3507 (*ifp->if_input)(ifp, ms);
3509 m0->m_data += 2; /* align data after header */
3510 m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
3511 m0->m_len = m0->m_pkthdr.len = total_len;
3512 m0->m_pkthdr.rcvif = ifp;
3513 (*ifp->if_input)(ifp, m0);
3515 #endif /* ! TULIP_COPY_RXDATA */
3521 * Couldn't allocate a new buffer. Don't bother
3522 * trying to replenish the receive queue.
3525 sc->tulip_flags |= TULIP_RXBUFSLOW;
3526 #if defined(TULIP_DEBUG)
3527 sc->tulip_dbg.dbg_rxlowbufs++;
3529 TULIP_PERFEND(rxget);
3533 * Now give the buffer(s) to the TULIP and save in our
3537 tulip_desc_t * const nextout = ri->ri_nextout;
3538 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3539 if (sc->tulip_rxmaps_free > 0) {
3540 map = sc->tulip_rxmaps[--sc->tulip_rxmaps_free];
3543 sc->tulip_flags |= TULIP_RXBUFSLOW;
3544 #if defined(TULIP_DEBUG)
3545 sc->tulip_dbg.dbg_rxlowbufs++;
3550 error = bus_dmamap_load(sc->tulip_dmatag, map, mtod(ms, void *),
3551 TULIP_RX_BUFLEN, NULL, BUS_DMA_NOWAIT);
3553 if_printf(sc->tulip_ifp,
3554 "unable to load rx map, error = %d\n", error);
3555 panic("tulip_rx_intr"); /* XXX */
3557 nextout->d_addr1 = map->dm_segs[0].ds_addr;
3558 nextout->d_length1 = map->dm_segs[0].ds_len;
3559 if (map->dm_nsegs == 2) {
3560 nextout->d_addr2 = map->dm_segs[1].ds_addr;
3561 nextout->d_length2 = map->dm_segs[1].ds_len;
3563 nextout->d_addr2 = 0;
3564 nextout->d_length2 = 0;
3566 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(*nextout));
3567 #else /* TULIP_BUS_DMA */
3568 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
3569 nextout->d_length1 = TULIP_RX_BUFLEN;
3570 #endif /* TULIP_BUS_DMA */
3571 nextout->d_status = TULIP_DSTS_OWNER;
3572 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
3573 if (++ri->ri_nextout == ri->ri_last)
3574 ri->ri_nextout = ri->ri_first;
3577 _IF_ENQUEUE(&sc->tulip_rxq, ms);
3578 } while ((ms = me) != NULL);
3580 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
3581 sc->tulip_flags &= ~TULIP_RXBUFSLOW;
3582 TULIP_PERFEND(rxget);
3585 #if defined(TULIP_DEBUG)
3586 sc->tulip_dbg.dbg_rxintrs++;
3587 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
3589 TULIP_PERFEND(rxintr);
3594 tulip_softc_t * const sc)
3596 TULIP_PERFSTART(txintr)
3597 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
3602 while (ri->ri_free < ri->ri_max) {
3605 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
3606 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
3611 d_flag = ri->ri_nextin->d_flag;
3612 if (d_flag & TULIP_DFLAG_TxLASTSEG) {
3613 if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
3615 * We've just finished processing a setup packet.
3616 * Mark that we finished it. If there's not
3617 * another pending, startup the TULIP receiver.
3618 * Make sure we ack the RXSTOPPED so we won't get
3619 * an abormal interrupt indication.
3621 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap);
3622 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
3623 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT)
3624 sc->tulip_flags |= TULIP_HASHONLY;
3625 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
3627 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3628 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3629 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3630 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3631 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3634 const u_int32_t d_status = ri->ri_nextin->d_status;
3635 _IF_DEQUEUE(&sc->tulip_txq, m);
3637 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3638 bus_dmamap_t map = M_GETCTX(m, bus_dmamap_t);
3639 TULIP_TXMAP_POSTSYNC(sc, map);
3640 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
3641 #endif /* TULIP_BUS_DMA */
3643 #if defined(TULIP_DEBUG)
3645 if_printf(sc->tulip_ifp,
3646 "tx_intr: failed to dequeue mbuf?!?\n");
3649 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3650 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
3651 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
3652 #if defined(TULIP_DEBUG)
3653 if (d_status & TULIP_DSTS_TxNOCARR)
3654 sc->tulip_dbg.dbg_txprobe_nocarr++;
3655 if (d_status & TULIP_DSTS_TxEXCCOLL)
3656 sc->tulip_dbg.dbg_txprobe_exccoll++;
3658 event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
3660 (*sc->tulip_boardsw->bd_media_poll)(sc, event);
3662 * Escape from the loop before media poll has reset the TULIP!
3667 if (d_status & TULIP_DSTS_ERRSUM) {
3668 sc->tulip_ifp->if_oerrors++;
3669 if (d_status & TULIP_DSTS_TxEXCCOLL)
3670 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
3671 if (d_status & TULIP_DSTS_TxLATECOLL)
3672 sc->tulip_dot3stats.dot3StatsLateCollisions++;
3673 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
3674 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
3675 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
3676 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
3677 if (d_status & TULIP_DSTS_TxUNDERFLOW)
3678 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
3679 if (d_status & TULIP_DSTS_TxBABBLE)
3680 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
3682 u_int32_t collisions =
3683 (d_status & TULIP_DSTS_TxCOLLMASK)
3684 >> TULIP_DSTS_V_TxCOLLCNT;
3685 sc->tulip_ifp->if_collisions += collisions;
3686 if (collisions == 1)
3687 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
3688 else if (collisions > 1)
3689 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
3690 else if (d_status & TULIP_DSTS_TxDEFERRED)
3691 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
3693 * SQE is only valid for 10baseT/BNC/AUI when not
3694 * running in full-duplex. In order to speed up the
3695 * test, the corresponding bit in tulip_flags needs to
3696 * set as well to get us to count SQE Test Errors.
3698 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
3699 sc->tulip_dot3stats.dot3StatsSQETestErrors++;
3705 if (++ri->ri_nextin == ri->ri_last)
3706 ri->ri_nextin = ri->ri_first;
3708 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3709 sc->tulip_ifp->if_flags &= ~IFF_OACTIVE;
3712 * If nothing left to transmit, disable the timer.
3713 * Else if progress, reset the timer back to 2 ticks.
3715 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
3716 sc->tulip_txtimer = 0;
3718 sc->tulip_txtimer = TULIP_TXTIMER;
3719 sc->tulip_ifp->if_opackets += xmits;
3720 TULIP_PERFEND(txintr);
3725 tulip_print_abnormal_interrupt(
3726 tulip_softc_t * const sc,
3729 const char * const *msgp = tulip_status_bits;
3732 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
3734 csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1;
3735 if_printf(sc->tulip_ifp, "abnormal interrupt:");
3736 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
3737 if ((csr & mask) && *msgp != NULL) {
3738 printf("%s%s", sep, *msgp);
3739 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
3740 sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
3741 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
3742 printf(" (switching to store-and-forward mode)");
3744 printf(" (raising TX threshold to %s)",
3745 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
3756 tulip_softc_t * const sc)
3758 TULIP_PERFSTART(intr)
3761 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3762 TULIP_CSR_WRITE(sc, csr_status, csr);
3764 if (csr & TULIP_STS_SYSERROR) {
3765 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
3766 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3767 sc->tulip_flags |= TULIP_SYSTEMERROR;
3769 if_printf(sc->tulip_ifp, "system error: %s\n",
3770 tulip_system_errors[sc->tulip_last_system_error]);
3772 sc->tulip_flags |= TULIP_NEEDRESET;
3773 sc->tulip_system_errors++;
3776 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
3777 #if defined(TULIP_DEBUG)
3778 sc->tulip_dbg.dbg_link_intrs++;
3780 if (sc->tulip_boardsw->bd_media_poll != NULL) {
3781 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
3782 ? TULIP_MEDIAPOLL_LINKFAIL
3783 : TULIP_MEDIAPOLL_LINKPASS);
3784 csr &= ~TULIP_STS_ABNRMLINTR;
3786 tulip_media_print(sc);
3788 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
3789 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
3790 if (csr & TULIP_STS_RXNOBUF)
3791 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
3793 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3794 * on receive overflows.
3796 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
3797 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3799 * Stop the receiver process and spin until it's stopped.
3800 * Tell rx_intr to drop the packets it dequeues.
3802 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
3803 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
3805 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3806 sc->tulip_flags |= TULIP_RXIGNORE;
3809 if (sc->tulip_flags & TULIP_RXIGNORE) {
3811 * Restart the receiver.
3813 sc->tulip_flags &= ~TULIP_RXIGNORE;
3814 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3817 if (csr & TULIP_STS_ABNRMLINTR) {
3818 u_int32_t tmp = csr & sc->tulip_intrmask
3819 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
3820 if (csr & TULIP_STS_TXUNDERFLOW) {
3821 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
3822 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
3823 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3824 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
3825 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
3826 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3829 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3830 sc->tulip_statusbits |= tmp;
3832 tulip_print_abnormal_interrupt(sc, tmp);
3833 sc->tulip_flags |= TULIP_NOMESSAGES;
3835 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3837 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
3839 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3840 tulip_ifstart(sc->tulip_ifp);
3843 if (sc->tulip_flags & TULIP_NEEDRESET) {
3847 TULIP_PERFEND(intr);
3854 tulip_softc_t * sc = arg;
3856 for (; sc != NULL; sc = sc->tulip_slaves) {
3857 #if defined(TULIP_DEBUG)
3858 sc->tulip_dbg.dbg_intrs++;
3860 tulip_intr_handler(sc);
3868 tulip_softc_t * sc = (tulip_softc_t *) arg;
3870 #if defined(TULIP_DEBUG)
3871 sc->tulip_dbg.dbg_intrs++;
3873 tulip_intr_handler(sc);
3876 static struct mbuf *
3877 tulip_mbuf_compress(
3882 #if MCLBYTES >= ETHERMTU + 18
3883 MGETHDR(m0, M_DONTWAIT, MT_DATA);
3885 if (m->m_pkthdr.len > MHLEN) {
3886 MCLGET(m0, M_DONTWAIT);
3887 if ((m0->m_flags & M_EXT) == 0) {
3893 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t));
3894 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len;
3898 int len = m->m_pkthdr.len;
3899 struct mbuf **mp = &m0;
3902 if (mlen == MHLEN) {
3903 MGETHDR(*mp, M_DONTWAIT, MT_DATA);
3905 MGET(*mp, M_DONTWAIT, MT_DATA);
3913 MCLGET(*mp, M_DONTWAIT);
3914 if (((*mp)->m_flags & M_EXT) == 0) {
3919 (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES;
3921 (*mp)->m_len = len <= mlen ? len : mlen;
3923 m_copydata(m, m->m_pkthdr.len - len,
3924 (*mp)->m_len, mtod((*mp), caddr_t));
3925 len -= (*mp)->m_len;
3926 mp = &(*mp)->m_next;
3934 static struct mbuf *
3936 tulip_softc_t * const sc,
3939 TULIP_PERFSTART(txput)
3940 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
3941 tulip_desc_t *eop, *nextout;
3944 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3951 #if defined(TULIP_DEBUG)
3952 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
3953 if_printf(sc->tulip_ifp, "txput%s: tx not running\n",
3954 (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : "");
3955 sc->tulip_flags |= TULIP_WANTTXSTART;
3956 sc->tulip_dbg.dbg_txput_finishes[0]++;
3962 * Now we try to fill in our transmit descriptors. This is
3963 * a bit reminiscent of going on the Ark two by two
3964 * since each descriptor for the TULIP can describe
3965 * two buffers. So we advance through packet filling
3966 * each of the two entries at a time to to fill each
3967 * descriptor. Clear the first and last segment bits
3968 * in each descriptor (actually just clear everything
3969 * but the end-of-ring or chain bits) to make sure
3970 * we don't get messed up by previously sent packets.
3972 * We may fail to put the entire packet on the ring if
3973 * there is either not enough ring entries free or if the
3974 * packet has more than MAX_TXSEG segments. In the former
3975 * case we will just wait for the ring to empty. In the
3976 * latter case we have to recopy.
3978 #if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX)
3983 eop = nextout = ri->ri_nextout;
3987 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3989 * Reclaim some dma maps from if we are out.
3991 if (sc->tulip_txmaps_free == 0) {
3992 #if defined(TULIP_DEBUG)
3993 sc->tulip_dbg.dbg_no_txmaps++;
3995 free += tulip_tx_intr(sc);
3997 if (sc->tulip_txmaps_free > 0) {
3998 map = sc->tulip_txmaps[sc->tulip_txmaps_free-1];
4000 sc->tulip_flags |= TULIP_WANTTXSTART;
4001 #if defined(TULIP_DEBUG)
4002 sc->tulip_dbg.dbg_txput_finishes[1]++;
4006 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT);
4008 if (error == EFBIG) {
4010 * The packet exceeds the number of transmit buffer
4011 * entries that we can use for one packet, so we have
4012 * to recopy it into one mbuf and then try again.
4014 m = tulip_mbuf_compress(m);
4016 #if defined(TULIP_DEBUG)
4017 sc->tulip_dbg.dbg_txput_finishes[2]++;
4021 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT);
4024 if_printf(sc->tulip_ifp,
4025 "unable to load tx map, error = %d\n", error);
4026 #if defined(TULIP_DEBUG)
4027 sc->tulip_dbg.dbg_txput_finishes[3]++;
4032 if ((free -= (map->dm_nsegs + 1) / 2) <= 0
4034 * See if there's any unclaimed space in the transmit ring.
4036 && (free += tulip_tx_intr(sc)) <= 0) {
4038 * There's no more room but since nothing
4039 * has been committed at this point, just
4040 * show output is active, put back the
4043 sc->tulip_flags |= TULIP_WANTTXSTART;
4044 #if defined(TULIP_DEBUG)
4045 sc->tulip_dbg.dbg_txput_finishes[4]++;
4047 bus_dmamap_unload(sc->tulip_dmatag, map);
4050 for (; map->dm_nsegs - segcnt > 1; segcnt += 2) {
4052 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4053 eop->d_status = d_status;
4054 eop->d_addr1 = map->dm_segs[segcnt].ds_addr;
4055 eop->d_length1 = map->dm_segs[segcnt].ds_len;
4056 eop->d_addr2 = map->dm_segs[segcnt+1].ds_addr;
4057 eop->d_length2 = map->dm_segs[segcnt+1].ds_len;
4058 d_status = TULIP_DSTS_OWNER;
4059 if (++nextout == ri->ri_last)
4060 nextout = ri->ri_first;
4062 if (segcnt < map->dm_nsegs) {
4064 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4065 eop->d_status = d_status;
4066 eop->d_addr1 = map->dm_segs[segcnt].ds_addr;
4067 eop->d_length1 = map->dm_segs[segcnt].ds_len;
4070 if (++nextout == ri->ri_last)
4071 nextout = ri->ri_first;
4073 TULIP_TXMAP_PRESYNC(sc, map);
4076 --sc->tulip_txmaps_free; /* commit to using the dmamap */
4078 #else /* !TULIP_BUS_DMA */
4081 int len = m0->m_len;
4082 caddr_t addr = mtod(m0, caddr_t);
4083 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1));
4086 unsigned slen = min(len, clsize);
4088 if (segcnt > TULIP_MAX_TXSEG) {
4090 * The packet exceeds the number of transmit buffer
4091 * entries that we can use for one packet, so we have
4092 * recopy it into one mbuf and then try again.
4094 m = tulip_mbuf_compress(m);
4102 * See if there's any unclaimed space in the
4105 if ((free += tulip_tx_intr(sc)) == 0) {
4107 * There's no more room but since nothing
4108 * has been committed at this point, just
4109 * show output is active, put back the
4112 sc->tulip_flags |= TULIP_WANTTXSTART;
4113 #if defined(TULIP_DEBUG)
4114 sc->tulip_dbg.dbg_txput_finishes[1]++;
4120 if (++nextout == ri->ri_last)
4121 nextout = ri->ri_first;
4122 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4123 eop->d_status = d_status;
4124 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr);
4125 eop->d_length1 = slen;
4128 * Fill in second half of descriptor
4130 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr);
4131 eop->d_length2 = slen;
4133 d_status = TULIP_DSTS_OWNER;
4138 } while ((m0 = m0->m_next) != NULL);
4139 #endif /* TULIP_BUS_DMA */
4142 * bounce a copy to the bpf listener, if any.
4144 BPF_MTAP(sc->tulip_ifp, m);
4147 * The descriptors have been filled in. Now get ready
4150 _IF_ENQUEUE(&sc->tulip_txq, m);
4154 * Make sure the next descriptor after this packet is owned
4155 * by us since it may have been set up above if we ran out
4156 * of room in the ring.
4158 nextout->d_status = 0;
4159 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
4161 #if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX)
4163 * If we only used the first segment of the last descriptor,
4164 * make sure the second segment will not be used.
4170 #endif /* TULIP_BUS_DMA */
4173 * Mark the last and first segments, indicate we want a transmit
4174 * complete interrupt, and tell it to transmit!
4176 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
4179 * Note that ri->ri_nextout is still the start of the packet
4180 * and until we set the OWNER bit, we can still back out of
4181 * everything we have done.
4183 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
4184 #if defined(TULIP_BUS_MAP) && !defined(TULIP_BUS_DMA_NOTX)
4185 if (eop < ri->ri_nextout) {
4186 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout,
4187 (caddr_t) ri->ri_last - (caddr_t) ri->ri_nextout);
4188 TULIP_TXDESC_PRESYNC(sc, ri->ri_first,
4189 (caddr_t) (eop + 1) - (caddr_t) ri->ri_first);
4191 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout,
4192 (caddr_t) (eop + 1) - (caddr_t) ri->ri_nextout);
4195 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
4196 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
4199 * This advances the ring for us.
4201 ri->ri_nextout = nextout;
4204 TULIP_PERFEND(txput);
4206 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
4207 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4208 sc->tulip_ifp->if_flags |= IFF_OACTIVE;
4209 sc->tulip_ifp->if_start = tulip_ifstart;
4210 TULIP_PERFEND(txput);
4215 * switch back to the single queueing ifstart.
4217 sc->tulip_flags &= ~TULIP_WANTTXSTART;
4218 if (sc->tulip_txtimer == 0)
4219 sc->tulip_txtimer = TULIP_TXTIMER;
4220 #if defined(TULIP_DEBUG)
4221 sc->tulip_dbg.dbg_txput_finishes[5]++;
4225 * If we want a txstart, there must be not enough space in the
4226 * transmit ring. So we want to enable transmit done interrupts
4227 * so we can immediately reclaim some space. When the transmit
4228 * interrupt is posted, the interrupt handler will call tx_intr
4229 * to reclaim space and then txstart (since WANTTXSTART is set).
4230 * txstart will move the packet into the transmit ring and clear
4231 * WANTTXSTART thereby causing TXINTR to be cleared.
4234 #if defined(TULIP_DEBUG)
4235 sc->tulip_dbg.dbg_txput_finishes[6]++;
4237 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
4238 sc->tulip_ifp->if_flags |= IFF_OACTIVE;
4239 sc->tulip_ifp->if_start = tulip_ifstart;
4240 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
4241 sc->tulip_intrmask |= TULIP_STS_TXINTR;
4242 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4244 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) {
4245 if (sc->tulip_intrmask & TULIP_STS_TXINTR) {
4246 sc->tulip_intrmask &= ~TULIP_STS_TXINTR;
4247 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4250 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4251 TULIP_PERFEND(txput);
4257 tulip_softc_t * const sc)
4259 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
4260 tulip_desc_t *nextout;
4263 * We will transmit, at most, one setup packet per call to ifstart.
4266 #if defined(TULIP_DEBUG)
4267 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
4268 if_printf(sc->tulip_ifp, "txput_setup: tx not running\n");
4269 sc->tulip_flags |= TULIP_WANTTXSTART;
4270 sc->tulip_ifp->if_start = tulip_ifstart;
4275 * Try to reclaim some free descriptors..
4277 if (ri->ri_free < 2)
4279 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
4280 sc->tulip_flags |= TULIP_WANTTXSTART;
4281 sc->tulip_ifp->if_start = tulip_ifstart;
4284 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
4285 sizeof(sc->tulip_setupbuf));
4287 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is
4288 * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
4290 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP;
4292 nextout = ri->ri_nextout;
4293 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4294 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
4295 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
4296 if (sc->tulip_flags & TULIP_WANTHASHPERFECT)
4297 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
4298 else if (sc->tulip_flags & TULIP_WANTHASHONLY)
4299 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT;
4301 nextout->d_length2 = 0;
4302 nextout->d_addr2 = 0;
4303 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
4304 nextout->d_length1 = sc->tulip_setupmap->dm_segs[0].ds_len;
4305 nextout->d_addr1 = sc->tulip_setupmap->dm_segs[0].ds_addr;
4306 if (sc->tulip_setupmap->dm_nsegs == 2) {
4307 nextout->d_length2 = sc->tulip_setupmap->dm_segs[1].ds_len;
4308 nextout->d_addr2 = sc->tulip_setupmap->dm_segs[1].ds_addr;
4310 TULIP_TXMAP_PRESYNC(sc, sc->tulip_setupmap);
4311 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(*nextout));
4313 nextout->d_length1 = sizeof(sc->tulip_setupbuf);
4314 nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
4318 * Advance the ring for the next transmit packet.
4320 if (++ri->ri_nextout == ri->ri_last)
4321 ri->ri_nextout = ri->ri_first;
4324 * Make sure the next descriptor is owned by us since it
4325 * may have been set up above if we ran out of room in the
4328 ri->ri_nextout->d_status = 0;
4329 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
4330 nextout->d_status = TULIP_DSTS_OWNER;
4332 * Flush the ownwership of the current descriptor
4334 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
4335 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4336 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
4337 sc->tulip_intrmask |= TULIP_STS_TXINTR;
4338 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4349 TULIP_PERFSTART(ifioctl)
4350 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4351 struct ifreq *ifr = (struct ifreq *) data;
4357 case SIOCSIFFLAGS: {
4358 tulip_addr_filter(sc); /* reinit multicast filter */
4364 case SIOCGIFMEDIA: {
4365 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
4370 case SIOCDELMULTI: {
4372 * Update multicast listeners
4374 tulip_addr_filter(sc); /* reset multicast filtering */
4382 * Set the interface MTU.
4384 if (ifr->ifr_mtu > ETHERMTU) {
4388 ifp->if_mtu = ifr->ifr_mtu;
4392 case SIOCGADDRROM: {
4393 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
4399 ifr->ifr_metric = (int) sc->tulip_chipid;
4404 error = ether_ioctl(ifp, cmd, data);
4410 TULIP_PERFEND(ifioctl);
4416 struct ifnet * const ifp)
4418 TULIP_PERFSTART(ifstart)
4419 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4421 if (sc->tulip_ifp->if_flags & IFF_RUNNING) {
4423 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
4424 tulip_txput_setup(sc);
4426 while (!IFQ_DRV_IS_EMPTY(&sc->tulip_ifp->if_snd)) {
4428 IFQ_DRV_DEQUEUE(&sc->tulip_ifp->if_snd, m);
4431 if ((m = tulip_txput(sc, m)) != NULL) {
4432 IFQ_DRV_PREPEND(&sc->tulip_ifp->if_snd, m);
4438 TULIP_PERFEND(ifstart);
4442 * Even though this routine runs at device spl, it does not break
4443 * our use of splnet (splsoftnet under NetBSD) for the majority
4444 * of this driver since
4445 * if_watcbog is called from if_watchdog which is called from
4446 * splsoftclock which is below spl[soft]net.
4452 TULIP_PERFSTART(ifwatchdog)
4453 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4455 #if defined(TULIP_DEBUG)
4456 u_int32_t rxintrs = sc->tulip_dbg.dbg_rxintrs - sc->tulip_dbg.dbg_last_rxintrs;
4457 if (rxintrs > sc->tulip_dbg.dbg_high_rxintrs_hz)
4458 sc->tulip_dbg.dbg_high_rxintrs_hz = rxintrs;
4459 sc->tulip_dbg.dbg_last_rxintrs = sc->tulip_dbg.dbg_rxintrs;
4460 #endif /* TULIP_DEBUG */
4462 sc->tulip_ifp->if_timer = 1;
4464 * These should be rare so do a bulk test up front so we can just skip
4467 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) {
4469 * If the number of receive buffer is low, try to refill
4471 if (sc->tulip_flags & TULIP_RXBUFSLOW)
4474 if (sc->tulip_flags & TULIP_SYSTEMERROR) {
4475 if_printf(sc->tulip_ifp, "%d system errors: last was %s\n",
4476 sc->tulip_system_errors,
4477 tulip_system_errors[sc->tulip_last_system_error]);
4479 if (sc->tulip_statusbits) {
4480 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
4481 sc->tulip_statusbits = 0;
4484 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR);
4487 if (sc->tulip_txtimer)
4489 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
4490 if_printf(sc->tulip_ifp, "transmission timeout\n");
4491 if (TULIP_DO_AUTOSENSE(sc)) {
4492 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
4493 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
4494 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP);
4500 TULIP_PERFEND(ifwatchdog);
4501 TULIP_PERFMERGE(sc, perf_intr_cycles);
4502 TULIP_PERFMERGE(sc, perf_ifstart_cycles);
4503 TULIP_PERFMERGE(sc, perf_ifioctl_cycles);
4504 TULIP_PERFMERGE(sc, perf_ifwatchdog_cycles);
4505 TULIP_PERFMERGE(sc, perf_timeout_cycles);
4506 TULIP_PERFMERGE(sc, perf_ifstart_one_cycles);
4507 TULIP_PERFMERGE(sc, perf_txput_cycles);
4508 TULIP_PERFMERGE(sc, perf_txintr_cycles);
4509 TULIP_PERFMERGE(sc, perf_rxintr_cycles);
4510 TULIP_PERFMERGE(sc, perf_rxget_cycles);
4511 TULIP_PERFMERGE(sc, perf_intr);
4512 TULIP_PERFMERGE(sc, perf_ifstart);
4513 TULIP_PERFMERGE(sc, perf_ifioctl);
4514 TULIP_PERFMERGE(sc, perf_ifwatchdog);
4515 TULIP_PERFMERGE(sc, perf_timeout);
4516 TULIP_PERFMERGE(sc, perf_ifstart_one);
4517 TULIP_PERFMERGE(sc, perf_txput);
4518 TULIP_PERFMERGE(sc, perf_txintr);
4519 TULIP_PERFMERGE(sc, perf_rxintr);
4520 TULIP_PERFMERGE(sc, perf_rxget);
4524 * All printf's are real as of now!
4532 tulip_softc_t * const sc)
4536 ifp = sc->tulip_ifp = if_alloc(IFT_ETHER);
4538 /* XXX: driver name/unit should be set some other way */
4539 if_initname(ifp, "de", sc->tulip_unit);
4541 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST|IFF_NEEDSGIANT;
4542 ifp->if_ioctl = tulip_ifioctl;
4543 ifp->if_start = tulip_ifstart;
4544 ifp->if_watchdog = tulip_ifwatchdog;
4546 ifp->if_init = tulip_ifinit;
4548 if_printf(ifp, "%s%s pass %d.%d%s\n",
4550 tulip_chipdescs[sc->tulip_chipid],
4551 (sc->tulip_revinfo & 0xF0) >> 4,
4552 sc->tulip_revinfo & 0x0F,
4553 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM))
4554 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "");
4556 #if defined(__alpha__)
4558 * In case the SRM console told us about a bogus media,
4559 * we need to check to be safe.
4561 if (sc->tulip_mediums[sc->tulip_media] == NULL)
4562 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
4565 (*sc->tulip_boardsw->bd_media_probe)(sc);
4566 ifmedia_init(&sc->tulip_ifmedia, 0,
4567 tulip_ifmedia_change,
4568 tulip_ifmedia_status);
4569 sc->tulip_flags &= ~TULIP_DEVICEPROBE;
4570 tulip_ifmedia_add(sc);
4574 ether_ifattach(sc->tulip_ifp, sc->tulip_enaddr);
4575 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
4576 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
4577 IFQ_SET_READY(&ifp->if_snd);
4580 #if defined(TULIP_BUS_DMA)
4581 #if !defined(TULIP_BUS_DMA_NOTX) || !defined(TULIP_BUS_DMA_NORX)
4583 tulip_busdma_allocmem(
4584 tulip_softc_t * const sc,
4586 bus_dmamap_t *map_p,
4587 tulip_desc_t **desc_p)
4589 bus_dma_segment_t segs[1];
4591 error = bus_dmamem_alloc(sc->tulip_dmatag, size, 1, PAGE_SIZE,
4592 segs, sizeof(segs)/sizeof(segs[0]),
4593 &nsegs, BUS_DMA_NOWAIT);
4596 error = bus_dmamem_map(sc->tulip_dmatag, segs, nsegs, size,
4597 (void *) &desc, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
4600 error = bus_dmamap_create(sc->tulip_dmatag, size, 1, size, 0,
4601 BUS_DMA_NOWAIT, &map);
4603 error = bus_dmamap_load(sc->tulip_dmatag, map, desc,
4604 size, NULL, BUS_DMA_NOWAIT);
4606 bus_dmamap_destroy(sc->tulip_dmatag, map);
4611 bus_dmamem_unmap(sc->tulip_dmatag, desc, size);
4614 bus_dmamem_free(sc->tulip_dmatag, segs, nsegs);
4624 tulip_softc_t * const sc)
4628 #if !defined(TULIP_BUS_DMA_NOTX)
4630 * Allocate dmamap for setup descriptor
4632 error = bus_dmamap_create(sc->tulip_dmatag, sizeof(sc->tulip_setupbuf), 2,
4633 sizeof(sc->tulip_setupbuf), 0, BUS_DMA_NOWAIT,
4634 &sc->tulip_setupmap);
4636 error = bus_dmamap_load(sc->tulip_dmatag, sc->tulip_setupmap,
4637 sc->tulip_setupbuf, sizeof(sc->tulip_setupbuf),
4638 NULL, BUS_DMA_NOWAIT);
4640 bus_dmamap_destroy(sc->tulip_dmatag, sc->tulip_setupmap);
4643 * Allocate space and dmamap for transmit ring
4646 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_TXDESCS,
4647 &sc->tulip_txdescmap,
4648 &sc->tulip_txdescs);
4652 * Allocate dmamaps for each transmit descriptors
4655 while (error == 0 && sc->tulip_txmaps_free < TULIP_TXDESCS) {
4657 if ((error = TULIP_TXMAP_CREATE(sc, &map)) == 0)
4658 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
4661 while (sc->tulip_txmaps_free > 0)
4662 bus_dmamap_destroy(sc->tulip_dmatag,
4663 sc->tulip_txmaps[--sc->tulip_txmaps_free]);
4668 sc->tulip_txdescs = (tulip_desc_t *) malloc(TULIP_TXDESCS * sizeof(tulip_desc_t), M_DEVBUF, M_NOWAIT);
4669 if (sc->tulip_txdescs == NULL)
4673 #if !defined(TULIP_BUS_DMA_NORX)
4675 * Allocate space and dmamap for receive ring
4678 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_RXDESCS,
4679 &sc->tulip_rxdescmap,
4680 &sc->tulip_rxdescs);
4684 * Allocate dmamaps for each receive descriptors
4687 while (error == 0 && sc->tulip_rxmaps_free < TULIP_RXDESCS) {
4689 if ((error = TULIP_RXMAP_CREATE(sc, &map)) == 0)
4690 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
4693 while (sc->tulip_rxmaps_free > 0)
4694 bus_dmamap_destroy(sc->tulip_dmatag,
4695 sc->tulip_rxmaps[--sc->tulip_rxmaps_free]);
4700 sc->tulip_rxdescs = (tulip_desc_t *) malloc(TULIP_RXDESCS * sizeof(tulip_desc_t), M_DEVBUF, M_NOWAIT);
4701 if (sc->tulip_rxdescs == NULL)
4707 #endif /* TULIP_BUS_DMA */
4711 tulip_softc_t * const sc,
4712 tulip_csrptr_t csr_base,
4715 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
4716 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
4717 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
4718 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
4719 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
4720 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
4721 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
4722 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
4723 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size;
4724 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size;
4725 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size;
4726 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size;
4727 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size;
4728 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size;
4729 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
4730 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
4735 tulip_softc_t * const sc,
4736 tulip_ringinfo_t * const ri,
4737 tulip_desc_t *descs,
4740 ri->ri_max = ndescs;
4741 ri->ri_first = descs;
4742 ri->ri_last = ri->ri_first + ri->ri_max;
4743 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
4744 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
4748 * This is the PCI configuration support.
4751 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
4752 #define PCI_CBMA 0x14 /* Configuration Base Memory Address */
4753 #define PCI_CFDA 0x40 /* Configuration Driver Area */
4756 tulip_pci_probe(device_t dev)
4758 const char *name = NULL;
4760 if (pci_get_vendor(dev) != DEC_VENDORID)
4764 * Some LanMedia WAN cards use the Tulip chip, but they have
4765 * their own driver, and we should not recognize them
4767 if (pci_get_subvendor(dev) == 0x1376)
4770 switch (pci_get_device(dev)) {
4772 name = "Digital 21040 Ethernet";
4775 name = "Digital 21041 Ethernet";
4778 if (pci_get_revid(dev) >= 0x20)
4779 name = "Digital 21140A Fast Ethernet";
4781 name = "Digital 21140 Fast Ethernet";
4784 if (pci_get_revid(dev) >= 0x20)
4785 name = "Digital 21143 Fast Ethernet";
4787 name = "Digital 21142 Fast Ethernet";
4791 device_set_desc(dev, name);
4792 return BUS_PROBE_LOW_PRIORITY;
4798 tulip_shutdown(device_t dev)
4800 tulip_softc_t * const sc = device_get_softc(dev);
4801 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4802 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
4803 33MHz that comes to two microseconds but wait a
4804 bit longer anyways) */
4809 tulip_pci_attach(device_t dev)
4812 #if defined(__alpha__)
4813 tulip_media_t media = TULIP_MEDIA_UNKNOWN;
4816 u_int32_t revinfo, cfdainfo, cfcsinfo;
4817 unsigned csroffset = TULIP_PCI_CSROFFSET;
4818 unsigned csrsize = TULIP_PCI_CSRSIZE;
4819 tulip_csrptr_t csr_base;
4820 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
4821 struct resource *res;
4824 unit = device_get_unit(dev);
4826 if (unit >= TULIP_MAX_DEVICES) {
4827 device_printf(dev, "not configured; limit of %d reached or exceeded\n",
4832 revinfo = pci_get_revid(dev);
4833 cfdainfo = pci_read_config(dev, PCI_CFDA, 4);
4834 cfcsinfo = pci_read_config(dev, PCIR_COMMAND, 4);
4836 /* turn busmaster on in case BIOS doesn't set it */
4837 if(!(cfcsinfo & PCIM_CMD_BUSMASTEREN)) {
4838 cfcsinfo |= PCIM_CMD_BUSMASTEREN;
4839 pci_write_config(dev, PCIR_COMMAND, cfcsinfo, 4);
4842 if (pci_get_vendor(dev) == DEC_VENDORID) {
4843 if (pci_get_device(dev) == CHIPID_21040)
4844 chipid = TULIP_21040;
4845 else if (pci_get_device(dev) == CHIPID_21041)
4846 chipid = TULIP_21041;
4847 else if (pci_get_device(dev) == CHIPID_21140)
4848 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140;
4849 else if (pci_get_device(dev) == CHIPID_21142)
4850 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142;
4852 if (chipid == TULIP_CHIPID_UNKNOWN)
4855 if (chipid == TULIP_21040 && revinfo < 0x20) {
4857 "not configured; 21040 pass 2.0 required (%d.%d found)\n",
4858 revinfo >> 4, revinfo & 0x0f);
4860 } else if (chipid == TULIP_21140 && revinfo < 0x11) {
4862 "not configured; 21140 pass 1.1 required (%d.%d found)\n",
4863 revinfo >> 4, revinfo & 0x0f);
4867 sc = device_get_softc(dev);
4868 sc->tulip_pci_busno = pci_get_bus(dev);
4869 sc->tulip_pci_devno = pci_get_slot(dev);
4870 sc->tulip_chipid = chipid;
4871 sc->tulip_flags |= TULIP_DEVICEPROBE;
4872 if (chipid == TULIP_21140 || chipid == TULIP_21140A)
4873 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD;
4874 if (chipid == TULIP_21140A && revinfo <= 0x22)
4875 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW;
4876 if (chipid == TULIP_21140)
4877 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH;
4878 if (chipid != TULIP_21040 && chipid != TULIP_21140)
4879 sc->tulip_features |= TULIP_HAVE_POWERMGMT;
4880 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) {
4881 sc->tulip_features |= TULIP_HAVE_DUALSENSE;
4882 if (chipid != TULIP_21041 || revinfo >= 0x20)
4883 sc->tulip_features |= TULIP_HAVE_SIANWAY;
4884 if (chipid != TULIP_21041)
4885 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD;
4886 if (chipid != TULIP_21041 && revinfo >= 0x20)
4887 sc->tulip_features |= TULIP_HAVE_SIA100;
4890 if (sc->tulip_features & TULIP_HAVE_POWERMGMT
4891 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) {
4892 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE);
4893 pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
4896 #if defined(__alpha__)
4898 * The Alpha SRM console encodes a console set media in the driver
4899 * part of the CFDA register. Note that the Multia presents a
4900 * problem in that its BNC mode is really EXTSIA. So in that case
4903 switch ((cfdainfo >> 8) & 0xff) {
4904 case 1: media = chipid > TULIP_21040 ? TULIP_MEDIA_AUI : TULIP_MEDIA_AUIBNC; break;
4905 case 2: media = chipid > TULIP_21040 ? TULIP_MEDIA_BNC : TULIP_MEDIA_UNKNOWN; break;
4906 case 3: media = TULIP_MEDIA_10BASET; break;
4907 case 4: media = TULIP_MEDIA_10BASET_FD; break;
4908 case 5: media = TULIP_MEDIA_100BASETX; break;
4909 case 6: media = TULIP_MEDIA_100BASETX_FD; break;
4910 default: media = TULIP_MEDIA_UNKNOWN; break;
4914 sc->tulip_unit = unit;
4915 sc->tulip_revinfo = revinfo;
4916 #if defined(TULIP_IOMAPPED)
4918 res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
4921 res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
4925 sc->tulip_csrs_bst = rman_get_bustag(res);
4926 sc->tulip_csrs_bsh = rman_get_bushandle(res);
4931 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
4933 #if defined(TULIP_BUS_DMA)
4934 if ((retval = tulip_busdma_init(sc)) != 0) {
4935 printf("error initing bus_dma: %d\n", retval);
4939 sc->tulip_rxdescs = (tulip_desc_t *) malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS, M_DEVBUF, M_NOWAIT);
4940 sc->tulip_txdescs = (tulip_desc_t *) malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS, M_DEVBUF, M_NOWAIT);
4941 if (sc->tulip_rxdescs == NULL || sc->tulip_txdescs == NULL) {
4942 device_printf(dev, "malloc failed\n");
4943 if (sc->tulip_rxdescs)
4944 free((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
4945 if (sc->tulip_txdescs)
4946 free((caddr_t) sc->tulip_txdescs, M_DEVBUF);
4951 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS);
4952 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS);
4955 * Make sure there won't be any interrupts or such...
4957 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4958 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
4959 33MHz that comes to two microseconds but wait a
4960 bit longer anyways) */
4962 if ((retval = tulip_read_macaddr(sc)) < 0) {
4963 device_printf(dev, "can't read ENET ROM (why=%d) (", retval);
4964 for (idx = 0; idx < 32; idx++)
4965 printf("%02x", sc->tulip_rombuf[idx]);
4967 device_printf(dev, "%s%s pass %d.%d\n",
4968 sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
4969 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
4970 device_printf(dev, "address unknown\n");
4973 void (*intr_rtn)(void *) = tulip_intr_normal;
4975 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
4976 intr_rtn = tulip_intr_shared;
4978 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) {
4982 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
4983 RF_SHAREABLE | RF_ACTIVE);
4984 if (res == 0 || bus_setup_intr(dev, res, INTR_TYPE_NET,
4985 intr_rtn, sc, &ih)) {
4986 device_printf(dev, "couldn't map interrupt\n");
4987 free((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
4988 free((caddr_t) sc->tulip_txdescs, M_DEVBUF);
4994 #if defined(__alpha__)
4995 sc->tulip_media = media;
4998 #if defined(__alpha__)
4999 if (sc->tulip_media != TULIP_MEDIA_UNKNOWN)
5000 tulip_linkup(sc, media);
5007 static device_method_t tulip_pci_methods[] = {
5008 /* Device interface */
5009 DEVMETHOD(device_probe, tulip_pci_probe),
5010 DEVMETHOD(device_attach, tulip_pci_attach),
5011 DEVMETHOD(device_shutdown, tulip_shutdown),
5014 static driver_t tulip_pci_driver = {
5017 sizeof(tulip_softc_t),
5019 static devclass_t tulip_devclass;
5020 DRIVER_MODULE(de, pci, tulip_pci_driver, tulip_devclass, 0, 0);