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);
131 static void tulip_start(tulip_softc_t * const sc);
133 tulip_txput(tulip_softc_t * const sc, struct mbuf *m);
134 static void tulip_txput_setup(tulip_softc_t * const sc);
137 tulip_timeout_callback(
140 tulip_softc_t * const sc = arg;
142 TULIP_PERFSTART(timeout)
145 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING;
146 sc->tulip_probe_timeout -= 1000 / TULIP_HZ;
147 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER);
149 TULIP_PERFEND(timeout);
155 tulip_softc_t * const sc)
157 TULIP_LOCK_ASSERT(sc);
158 if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
160 sc->tulip_flags |= TULIP_TIMEOUTPENDING;
161 callout_reset(&sc->tulip_callout, (hz + TULIP_HZ / 2) / TULIP_HZ,
162 tulip_timeout_callback, sc);
168 tulip_softc_t * const sc)
172 * Before we are sure this is the right media we need
173 * to send a small packet to make sure there's carrier.
174 * Strangely, BNC and AUI will "see" receive data if
175 * either is connected so the transmit is the only way
176 * to verify the connectivity.
178 TULIP_LOCK_ASSERT(sc);
179 MGETHDR(m, M_DONTWAIT, MT_DATA);
183 * Construct a LLC TEST message which will point to ourselves.
185 bcopy(IFP2ENADDR(sc->tulip_ifp), mtod(m, struct ether_header *)->ether_dhost, 6);
186 bcopy(IFP2ENADDR(sc->tulip_ifp), mtod(m, struct ether_header *)->ether_shost, 6);
187 mtod(m, struct ether_header *)->ether_type = htons(3);
188 mtod(m, unsigned char *)[14] = 0;
189 mtod(m, unsigned char *)[15] = 0;
190 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
191 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
195 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
196 sc->tulip_intrmask |= TULIP_STS_TXINTR;
197 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
198 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
199 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
200 if ((m = tulip_txput(sc, m)) != NULL)
202 sc->tulip_probe.probe_txprobes++;
209 tulip_softc_t * const sc,
212 const tulip_media_info_t *mi = sc->tulip_mediums[media];
214 TULIP_LOCK_ASSERT(sc);
219 * If we are switching media, make sure we don't think there's
220 * any stale RX activity
222 sc->tulip_flags &= ~TULIP_RXACT;
223 if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
224 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
225 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx);
226 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
227 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general);
229 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general);
231 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general);
233 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity);
234 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
235 #define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL)
237 * If the cmdmode bits don't match the currently operating mode,
238 * set the cmdmode appropriately and reset the chip.
240 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
241 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
242 sc->tulip_cmdmode |= mi->mi_cmdmode;
245 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
247 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata);
248 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
250 * If the cmdmode bits don't match the currently operating mode,
251 * set the cmdmode appropriately and reset the chip.
253 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
254 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
255 sc->tulip_cmdmode |= mi->mi_cmdmode;
258 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol);
259 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata);
260 } else if (mi->mi_type == TULIP_MEDIAINFO_MII
261 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) {
263 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
265 dp = &sc->tulip_rombuf[mi->mi_reset_offset];
266 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) {
268 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
270 sc->tulip_phyaddr = mi->mi_phyaddr;
271 dp = &sc->tulip_rombuf[mi->mi_gpr_offset];
272 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) {
274 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
277 for (idx = 0; idx < mi->mi_reset_length; idx++) {
279 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]);
281 sc->tulip_phyaddr = mi->mi_phyaddr;
282 for (idx = 0; idx < mi->mi_gpr_length; idx++) {
284 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]);
287 if (sc->tulip_flags & TULIP_TRYNWAY) {
288 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
289 } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
290 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL);
291 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE);
292 sc->tulip_flags &= ~TULIP_DIDNWAY;
293 if (TULIP_IS_MEDIA_FD(media))
294 data |= PHYCTL_FULL_DUPLEX;
295 if (TULIP_IS_MEDIA_100MB(media))
296 data |= PHYCTL_SELECT_100MB;
297 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data);
304 tulip_softc_t * const sc,
307 TULIP_LOCK_ASSERT(sc);
308 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
309 sc->tulip_flags |= TULIP_PRINTLINKUP;
310 sc->tulip_flags |= TULIP_LINKUP;
311 sc->tulip_ifp->if_flags &= ~IFF_OACTIVE;
312 #if 0 /* XXX how does with work with ifmedia? */
313 if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
314 if (sc->tulip_ifp->if_flags & IFF_FULLDUPLEX) {
315 if (TULIP_CAN_MEDIA_FD(media)
316 && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL)
317 media = TULIP_FD_MEDIA_OF(media);
319 if (TULIP_IS_MEDIA_FD(media)
320 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL)
321 media = TULIP_HD_MEDIA_OF(media);
325 if (sc->tulip_media != media) {
327 sc->tulip_dbg.dbg_last_media = sc->tulip_media;
329 sc->tulip_media = media;
330 sc->tulip_flags |= TULIP_PRINTMEDIA;
331 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) {
332 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
333 } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) {
334 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
338 * We could set probe_timeout to 0 but setting to 3000 puts this
339 * in one central place and the only matters is tulip_link is
340 * followed by a tulip_timeout. Therefore setting it should not
341 * result in aberrant behavour.
343 sc->tulip_probe_timeout = 3000;
344 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
345 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY);
346 if (sc->tulip_flags & TULIP_INRESET) {
347 tulip_media_set(sc, sc->tulip_media);
348 } else if (sc->tulip_probe_media != sc->tulip_media) {
350 * No reason to change media if we have the right media.
359 tulip_softc_t * const sc)
361 struct ifnet *ifp = sc->tulip_ifp;
363 TULIP_LOCK_ASSERT(sc);
364 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
366 if (sc->tulip_flags & TULIP_PRINTMEDIA) {
367 if_printf(ifp, "enabling %s port\n",
368 tulip_mediums[sc->tulip_media]);
369 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
370 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
371 if_printf(ifp, "link up\n");
372 sc->tulip_flags &= ~TULIP_PRINTLINKUP;
376 #if defined(TULIP_DO_GPR_SENSE)
378 tulip_21140_gpr_media_sense(
379 tulip_softc_t * const sc)
381 struct ifnet *ifp sc->tulip_ifp;
382 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
383 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
386 TULIP_LOCK_ASSERT(sc);
389 * If one of the media blocks contained a default media flag,
392 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
393 const tulip_media_info_t *mi;
395 * Media is not supported (or is full-duplex).
397 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media))
399 if (mi->mi_type != TULIP_MEDIAINFO_GPR)
403 * Remember the media is this is the "default" media.
405 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
409 * No activity mask? Can't see if it is active if there's no mask.
411 if (mi->mi_actmask == 0)
415 * Does the activity data match?
417 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
420 #if defined(TULIP_DEBUG)
421 if_printf(ifp, "gpr_media_sense: %s: 0x%02x & 0x%02x == 0x%02x\n",
422 tulip_mediums[media],
423 TULIP_CSR_READ(sc, csr_gp) & 0xFF,
424 mi->mi_actmask, mi->mi_actdata);
427 * It does! If this is the first media we detected, then
428 * remember this media. If isn't the first, then there were
429 * multiple matches which we equate to no match (since we don't
430 * which to select (if any).
432 if (last_media == TULIP_MEDIA_UNKNOWN) {
434 } else if (last_media != media) {
435 last_media = TULIP_MEDIA_UNKNOWN;
438 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
440 #endif /* TULIP_DO_GPR_SENSE */
442 static tulip_link_status_t
443 tulip_media_link_monitor(
444 tulip_softc_t * const sc)
446 struct ifnet *ifp = sc->tulip_ifp;
447 const tulip_media_info_t * const mi = sc->tulip_mediums[sc->tulip_media];
448 tulip_link_status_t linkup = TULIP_LINK_DOWN;
450 TULIP_LOCK_ASSERT(sc);
452 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
453 panic("tulip_media_link_monitor: %s: botch at line %d\n",
454 tulip_mediums[sc->tulip_media],__LINE__);
456 return TULIP_LINK_UNKNOWN;
462 * Have we seen some packets? If so, the link must be good.
464 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) {
465 sc->tulip_flags &= ~TULIP_RXACT;
466 sc->tulip_probe_timeout = 3000;
467 return TULIP_LINK_UP;
470 sc->tulip_flags &= ~TULIP_RXACT;
471 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
474 * Read the PHY status register.
476 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
477 if (status & PHYSTS_AUTONEG_DONE) {
479 * If the PHY has completed autonegotiation, see the if the
480 * remote systems abilities have changed. If so, upgrade or
481 * downgrade as appropriate.
483 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
484 abilities = (abilities << 6) & status;
485 if (abilities != sc->tulip_abilities) {
486 #if defined(TULIP_DEBUG)
487 loudprintf("%s(phy%d): autonegotiation changed: 0x%04x -> 0x%04x\n",
488 ifp->if_xname, sc->tulip_phyaddr,
489 sc->tulip_abilities, abilities);
491 if (tulip_mii_map_abilities(sc, abilities)) {
492 tulip_linkup(sc, sc->tulip_probe_media);
493 return TULIP_LINK_UP;
496 * if we had selected media because of autonegotiation,
497 * we need to probe for the new media.
499 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
500 if (sc->tulip_flags & TULIP_DIDNWAY)
501 return TULIP_LINK_DOWN;
505 * The link is now up. If was down, say its back up.
507 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP)
508 linkup = TULIP_LINK_UP;
509 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
511 * No activity sensor? Assume all's well.
513 if (mi->mi_actmask == 0)
514 return TULIP_LINK_UNKNOWN;
516 * Does the activity data match?
518 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata)
519 linkup = TULIP_LINK_UP;
520 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
522 * Assume non TP ok for now.
524 if (!TULIP_IS_MEDIA_TP(sc->tulip_media))
525 return TULIP_LINK_UNKNOWN;
526 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
527 linkup = TULIP_LINK_UP;
528 #if defined(TULIP_DEBUG)
529 if (sc->tulip_probe_timeout <= 0)
530 if_printf(ifp, "sia status = 0x%08x\n",
531 TULIP_CSR_READ(sc, csr_sia_status));
533 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
534 return TULIP_LINK_UNKNOWN;
537 * We will wait for 3 seconds until the link goes into suspect mode.
539 if (sc->tulip_flags & TULIP_LINKUP) {
540 if (linkup == TULIP_LINK_UP)
541 sc->tulip_probe_timeout = 3000;
542 if (sc->tulip_probe_timeout > 0)
543 return TULIP_LINK_UP;
545 sc->tulip_flags &= ~TULIP_LINKUP;
546 if_printf(ifp, "link down: cable problem?\n");
548 #if defined(TULIP_DEBUG)
549 sc->tulip_dbg.dbg_link_downed++;
551 return TULIP_LINK_DOWN;
556 tulip_softc_t * const sc,
557 tulip_mediapoll_event_t event)
559 struct ifnet *ifp = sc->tulip_ifp;
561 TULIP_LOCK_ASSERT(sc);
562 #if defined(TULIP_DEBUG)
563 sc->tulip_dbg.dbg_events[event]++;
565 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
566 && event == TULIP_MEDIAPOLL_TIMER) {
567 switch (tulip_media_link_monitor(sc)) {
568 case TULIP_LINK_DOWN: {
570 * Link Monitor failed. Probe for new media.
572 event = TULIP_MEDIAPOLL_LINKFAIL;
575 case TULIP_LINK_UP: {
582 case TULIP_LINK_UNKNOWN: {
584 * We can't tell so don't bother.
591 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
592 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
593 if (TULIP_DO_AUTOSENSE(sc)) {
594 #if defined(TULIP_DEBUG)
595 sc->tulip_dbg.dbg_link_failures++;
597 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
598 if (sc->tulip_ifp->if_flags & IFF_UP)
599 tulip_reset(sc); /* restart probe */
603 #if defined(TULIP_DEBUG)
604 sc->tulip_dbg.dbg_link_pollintrs++;
608 if (event == TULIP_MEDIAPOLL_START) {
609 sc->tulip_ifp->if_flags |= IFF_OACTIVE;
610 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
612 sc->tulip_probe_mediamask = 0;
613 sc->tulip_probe_passes = 0;
614 #if defined(TULIP_DEBUG)
615 sc->tulip_dbg.dbg_media_probes++;
618 * If the SROM contained an explicit media to use, use it.
620 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX);
621 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS;
622 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
624 * connidx is defaulted to a media_unknown type.
626 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media;
627 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) {
628 tulip_linkup(sc, sc->tulip_probe_media);
633 if (sc->tulip_features & TULIP_HAVE_GPR) {
634 sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
635 sc->tulip_probe_timeout = 2000;
637 sc->tulip_probe_media = TULIP_MEDIA_MAX;
638 sc->tulip_probe_timeout = 0;
639 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
644 * Ignore txprobe failures or spurious callbacks.
646 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED
647 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) {
648 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
653 * If we really transmitted a packet, then that's the media we'll use.
655 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) {
656 if (event == TULIP_MEDIAPOLL_LINKPASS) {
657 /* XXX Check media status just to be sure */
658 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
659 #if defined(TULIP_DEBUG)
661 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
664 tulip_linkup(sc, sc->tulip_probe_media);
669 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) {
670 #if defined(TULIP_DO_GPR_SENSE)
672 * Check for media via the general purpose register.
674 * Try to sense the media via the GPR. If the same value
675 * occurs 3 times in a row then just use that.
677 if (sc->tulip_probe_timeout > 0) {
678 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
679 #if defined(TULIP_DEBUG)
680 if_printf(ifp, "media_poll: gpr sensing = %s\n",
681 tulip_mediums[new_probe_media]);
683 if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
684 if (new_probe_media == sc->tulip_probe_media) {
685 if (--sc->tulip_probe_count == 0)
686 tulip_linkup(sc, sc->tulip_probe_media);
688 sc->tulip_probe_count = 10;
691 sc->tulip_probe_media = new_probe_media;
695 #endif /* TULIP_DO_GPR_SENSE */
697 * Brute force. We cycle through each of the media types
698 * and try to transmit a packet.
700 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
701 sc->tulip_probe_media = TULIP_MEDIA_MAX;
702 sc->tulip_probe_timeout = 0;
707 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST
708 && (sc->tulip_features & TULIP_HAVE_MII)) {
709 tulip_media_t old_media = sc->tulip_probe_media;
710 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
711 switch (sc->tulip_probe_state) {
712 case TULIP_PROBE_FAILED:
713 case TULIP_PROBE_MEDIATEST: {
715 * Try the next media.
717 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask;
718 sc->tulip_probe_timeout = 0;
720 if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
722 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
724 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
728 case TULIP_PROBE_PHYAUTONEG: {
731 case TULIP_PROBE_INACTIVE: {
733 * Only probe if we autonegotiated a media that hasn't failed.
735 sc->tulip_probe_timeout = 0;
736 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) {
737 sc->tulip_probe_media = old_media;
740 tulip_linkup(sc, sc->tulip_probe_media);
745 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
746 panic("tulip_media_poll: botch at line %d\n", __LINE__);
753 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
754 #if defined(TULIP_DEBUG)
755 sc->tulip_dbg.dbg_txprobes_failed[sc->tulip_probe_media]++;
757 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
762 * switch to another media if we tried this one enough.
764 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
765 #if defined(TULIP_DEBUG)
766 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
767 if_printf(ifp, "poll media unknown!\n");
768 sc->tulip_probe_media = TULIP_MEDIA_MAX;
772 * Find the next media type to check for. Full Duplex
773 * types are not allowed.
776 sc->tulip_probe_media -= 1;
777 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
778 if (++sc->tulip_probe_passes == 3) {
779 if_printf(ifp, "autosense failed: cable problem?\n");
780 if ((sc->tulip_ifp->if_flags & IFF_UP) == 0) {
781 sc->tulip_ifp->if_flags &= ~IFF_RUNNING;
782 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
786 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */
787 sc->tulip_probe_mediamask = 0;
788 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1;
790 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL
791 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
792 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
794 #if defined(TULIP_DEBUG)
795 if_printf(ifp, "%s: probing %s\n",
796 event == TULIP_MEDIAPOLL_TXPROBE_FAILED ? "txprobe failed" : "timeout",
797 tulip_mediums[sc->tulip_probe_media]);
799 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
800 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
801 sc->tulip_probe.probe_txprobes = 0;
803 tulip_media_set(sc, sc->tulip_probe_media);
804 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
809 * If this is hanging off a phy, we know are doing NWAY and we have
810 * forced the phy to a specific speed. Wait for link up before
811 * before sending a packet.
813 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) {
814 case TULIP_MEDIAINFO_MII: {
815 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
819 case TULIP_MEDIAINFO_SIA: {
820 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) {
821 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL)
823 tulip_linkup(sc, sc->tulip_probe_media);
825 if (sc->tulip_features & TULIP_HAVE_MII)
832 case TULIP_MEDIAINFO_RESET:
833 case TULIP_MEDIAINFO_SYM:
834 case TULIP_MEDIAINFO_NONE:
835 case TULIP_MEDIAINFO_GPR: {
840 * Try to send a packet.
847 tulip_softc_t * const sc)
849 TULIP_LOCK_ASSERT(sc);
850 if (sc->tulip_features & TULIP_HAVE_GPR) {
851 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
853 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata);
856 * If this board has no media, just return
858 if (sc->tulip_features & TULIP_HAVE_NOMEDIA)
861 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
862 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
863 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START);
865 tulip_media_set(sc, sc->tulip_media);
870 tulip_21040_mediainfo_init(
871 tulip_softc_t * const sc,
874 TULIP_LOCK_ASSERT(sc);
875 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
876 |TULIP_CMD_BACKOFFCTR;
877 sc->tulip_ifp->if_baudrate = 10000000;
879 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) {
880 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET);
881 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD);
882 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
885 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) {
886 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC);
889 if (media == TULIP_MEDIA_UNKNOWN) {
890 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA);
895 tulip_21040_media_probe(
896 tulip_softc_t * const sc)
898 TULIP_LOCK_ASSERT(sc);
899 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
904 tulip_21040_10baset_only_media_probe(
905 tulip_softc_t * const sc)
907 TULIP_LOCK_ASSERT(sc);
908 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
909 tulip_media_set(sc, TULIP_MEDIA_10BASET);
910 sc->tulip_media = TULIP_MEDIA_10BASET;
914 tulip_21040_10baset_only_media_select(
915 tulip_softc_t * const sc)
917 TULIP_LOCK_ASSERT(sc);
918 sc->tulip_flags |= TULIP_LINKUP;
919 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
920 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
921 sc->tulip_flags &= ~TULIP_SQETEST;
923 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
924 sc->tulip_flags |= TULIP_SQETEST;
926 tulip_media_set(sc, sc->tulip_media);
930 tulip_21040_auibnc_only_media_probe(
931 tulip_softc_t * const sc)
933 TULIP_LOCK_ASSERT(sc);
934 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
935 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
936 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
937 sc->tulip_media = TULIP_MEDIA_AUIBNC;
941 tulip_21040_auibnc_only_media_select(
942 tulip_softc_t * const sc)
944 TULIP_LOCK_ASSERT(sc);
945 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
946 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
949 static const tulip_boardsw_t tulip_21040_boardsw = {
951 tulip_21040_media_probe,
956 static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = {
958 tulip_21040_10baset_only_media_probe,
959 tulip_21040_10baset_only_media_select,
963 static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = {
965 tulip_21040_auibnc_only_media_probe,
966 tulip_21040_auibnc_only_media_select,
971 tulip_21041_mediainfo_init(
972 tulip_softc_t * const sc)
974 tulip_media_info_t * const mi = sc->tulip_mediainfo;
976 TULIP_LOCK_ASSERT(sc);
978 if (sc->tulip_revinfo >= 0x20) {
979 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET);
980 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD);
981 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI);
982 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC);
986 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET);
987 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD);
988 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
989 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
993 tulip_21041_media_probe(
994 tulip_softc_t * const sc)
996 TULIP_LOCK_ASSERT(sc);
997 sc->tulip_ifp->if_baudrate = 10000000;
998 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
999 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
1000 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
1001 tulip_21041_mediainfo_init(sc);
1005 tulip_21041_media_poll(
1006 tulip_softc_t * const sc,
1007 const tulip_mediapoll_event_t event)
1009 u_int32_t sia_status;
1011 TULIP_LOCK_ASSERT(sc);
1012 #if defined(TULIP_DEBUG)
1013 sc->tulip_dbg.dbg_events[event]++;
1016 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
1017 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
1018 || !TULIP_DO_AUTOSENSE(sc))
1020 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
1021 tulip_reset(sc); /* start probe */
1026 * If we've been been asked to start a poll or link change interrupt
1027 * restart the probe (and reset the tulip to a known state).
1029 if (event == TULIP_MEDIAPOLL_START) {
1030 sc->tulip_ifp->if_flags |= IFF_OACTIVE;
1031 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN);
1033 if (sc->tulip_revinfo >= 0x20) {
1034 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
1035 sc->tulip_flags |= TULIP_DIDNWAY;
1038 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1039 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1040 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1041 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT;
1042 tulip_media_set(sc, TULIP_MEDIA_10BASET);
1047 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1050 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
1051 #if defined(TULIP_DEBUG)
1052 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
1054 tulip_linkup(sc, sc->tulip_probe_media);
1058 sia_status = TULIP_CSR_READ(sc, csr_sia_status);
1059 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status);
1060 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) {
1061 if (sc->tulip_revinfo >= 0x20) {
1062 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6)))
1063 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1066 * If the link has passed LinkPass, 10baseT is the
1067 * proper media to use.
1069 tulip_linkup(sc, sc->tulip_probe_media);
1074 * wait for up to 2.4 seconds for the link to reach pass state.
1075 * Only then start scanning the other media for activity.
1076 * choose media with receive activity over those without.
1078 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) {
1079 if (event != TULIP_MEDIAPOLL_TIMER)
1081 if (sc->tulip_probe_timeout > 0
1082 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
1086 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1087 sc->tulip_flags |= TULIP_WANTRXACT;
1088 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) {
1089 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1091 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1093 tulip_media_set(sc, sc->tulip_probe_media);
1099 * If we failed, clear the txprobe active flag.
1101 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED)
1102 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1105 if (event == TULIP_MEDIAPOLL_TIMER) {
1107 * If we've received something, then that's our link!
1109 if (sc->tulip_flags & TULIP_RXACT) {
1110 tulip_linkup(sc, sc->tulip_probe_media);
1114 * if no txprobe active
1116 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0
1117 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0
1118 || (sia_status & TULIP_SIASTS_RXACTIVITY))) {
1119 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1125 * Take 2 passes through before deciding to not
1126 * wait for receive activity. Then take another
1127 * two passes before spitting out a warning.
1129 if (sc->tulip_probe_timeout <= 0) {
1130 if (sc->tulip_flags & TULIP_WANTRXACT) {
1131 sc->tulip_flags &= ~TULIP_WANTRXACT;
1132 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1134 if_printf(sc->tulip_ifp,
1135 "autosense failed: cable problem?\n");
1136 if ((sc->tulip_ifp->if_flags & IFF_UP) == 0) {
1137 sc->tulip_ifp->if_flags &= ~IFF_RUNNING;
1138 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1146 * Since this media failed to probe, try the other one.
1148 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1149 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) {
1150 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1152 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1154 tulip_media_set(sc, sc->tulip_probe_media);
1155 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1159 static const tulip_boardsw_t tulip_21041_boardsw = {
1160 TULIP_21041_GENERIC,
1161 tulip_21041_media_probe,
1163 tulip_21041_media_poll
1166 static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
1167 { 0x20005c00, 0, /* 08-00-17 */
1169 { 0x19, 0x0040, 0x0040 }, /* 10TX */
1170 { 0x19, 0x0040, 0x0000 }, /* 100TX */
1172 #if defined(TULIP_DEBUG)
1176 { 0x0281F400, 0, /* 00-A0-7D */
1178 { 0x12, 0x0010, 0x0000 }, /* 10T */
1180 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1181 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1183 #if defined(TULIP_DEBUG)
1188 { 0x0015F420, 0, /* 00-A0-7D */
1190 { 0x12, 0x0010, 0x0000 }, /* 10T */
1192 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1193 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1195 #if defined(TULIP_DEBUG)
1200 { 0x0281F400, 0, /* 00-A0-BE */
1202 { 0x11, 0x8000, 0x0000 }, /* 10T */
1203 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1205 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1207 #if defined(TULIP_DEBUG)
1214 static tulip_media_t
1215 tulip_mii_phy_readspecific(
1216 tulip_softc_t * const sc)
1218 const tulip_phy_attr_t *attr;
1222 static const tulip_media_t table[] = {
1223 TULIP_MEDIA_UNKNOWN,
1224 TULIP_MEDIA_10BASET,
1225 TULIP_MEDIA_100BASETX,
1226 TULIP_MEDIA_100BASET4,
1227 TULIP_MEDIA_UNKNOWN,
1228 TULIP_MEDIA_10BASET_FD,
1229 TULIP_MEDIA_100BASETX_FD,
1233 TULIP_LOCK_ASSERT(sc);
1236 * Don't read phy specific registers if link is not up.
1238 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
1239 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS))
1240 return TULIP_MEDIA_UNKNOWN;
1242 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) |
1243 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH);
1244 for (attr = tulip_mii_phy_attrlist;; attr++) {
1245 if (attr->attr_id == 0)
1246 return TULIP_MEDIA_UNKNOWN;
1247 if ((id & ~0x0F) == attr->attr_id)
1251 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
1252 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100TX];
1253 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1254 if ((data & pm->pm_mask) == pm->pm_value)
1257 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) {
1258 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100T4];
1259 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1260 if ((data & pm->pm_mask) == pm->pm_value)
1263 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) {
1264 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_10T];
1265 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1266 if ((data & pm->pm_mask) == pm->pm_value)
1269 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) {
1270 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
1271 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1272 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
1278 tulip_mii_get_phyaddr(
1279 tulip_softc_t * const sc,
1284 TULIP_LOCK_ASSERT(sc);
1285 for (phyaddr = 1; phyaddr < 32; phyaddr++) {
1286 unsigned status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1287 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1294 unsigned status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
1295 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1296 return TULIP_MII_NOPHY;
1299 return TULIP_MII_NOPHY;
1303 tulip_mii_map_abilities(
1304 tulip_softc_t * const sc,
1307 TULIP_LOCK_ASSERT(sc);
1308 sc->tulip_abilities = abilities;
1309 if (abilities & PHYSTS_100BASETX_FD) {
1310 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD;
1311 } else if (abilities & PHYSTS_100BASET4) {
1312 sc->tulip_probe_media = TULIP_MEDIA_100BASET4;
1313 } else if (abilities & PHYSTS_100BASETX) {
1314 sc->tulip_probe_media = TULIP_MEDIA_100BASETX;
1315 } else if (abilities & PHYSTS_10BASET_FD) {
1316 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1317 } else if (abilities & PHYSTS_10BASET) {
1318 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1320 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1323 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1328 tulip_mii_autonegotiate(
1329 tulip_softc_t * const sc,
1330 const unsigned phyaddr)
1332 struct ifnet *ifp = sc->tulip_ifp;
1334 TULIP_LOCK_ASSERT(sc);
1335 switch (sc->tulip_probe_state) {
1336 case TULIP_PROBE_MEDIATEST:
1337 case TULIP_PROBE_INACTIVE: {
1338 sc->tulip_flags |= TULIP_DIDNWAY;
1339 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET);
1340 sc->tulip_probe_timeout = 3000;
1341 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR;
1342 sc->tulip_probe_state = TULIP_PROBE_PHYRESET;
1345 case TULIP_PROBE_PHYRESET: {
1347 u_int32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1348 if (data & PHYCTL_RESET) {
1349 if (sc->tulip_probe_timeout > 0) {
1353 printf("%s(phy%d): error: reset of PHY never completed!\n",
1354 ifp->if_xname, phyaddr);
1355 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1356 sc->tulip_probe_state = TULIP_PROBE_FAILED;
1357 sc->tulip_ifp->if_flags &= ~(IFF_UP|IFF_RUNNING);
1360 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1361 if ((status & PHYSTS_CAN_AUTONEG) == 0) {
1362 #if defined(TULIP_DEBUG)
1363 loudprintf("%s(phy%d): autonegotiation disabled\n",
1364 ifp->if_xname, phyaddr);
1366 sc->tulip_flags &= ~TULIP_DIDNWAY;
1367 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1370 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01))
1371 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
1372 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
1373 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1374 #if defined(TULIP_DEBUG)
1375 if ((data & PHYCTL_AUTONEG_ENABLE) == 0)
1376 loudprintf("%s(phy%d): oops: enable autonegotiation failed: 0x%04x\n",
1377 ifp->if_xname, phyaddr, data);
1379 loudprintf("%s(phy%d): autonegotiation restarted: 0x%04x\n",
1380 ifp->if_xname, phyaddr, data);
1381 sc->tulip_dbg.dbg_nway_starts++;
1383 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
1384 sc->tulip_probe_timeout = 3000;
1387 case TULIP_PROBE_PHYAUTONEG: {
1388 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1390 if ((status & PHYSTS_AUTONEG_DONE) == 0) {
1391 if (sc->tulip_probe_timeout > 0) {
1395 #if defined(TULIP_DEBUG)
1396 loudprintf("%s(phy%d): autonegotiation timeout: sts=0x%04x, ctl=0x%04x\n",
1397 ifp->if_xname, phyaddr, status,
1398 tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL));
1400 sc->tulip_flags &= ~TULIP_DIDNWAY;
1401 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1404 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
1405 #if defined(TULIP_DEBUG)
1406 loudprintf("%s(phy%d): autonegotiation complete: 0x%04x\n",
1407 ifp->if_xname, phyaddr, data);
1409 data = (data << 6) & status;
1410 if (!tulip_mii_map_abilities(sc, data))
1411 sc->tulip_flags &= ~TULIP_DIDNWAY;
1415 #if defined(DIAGNOSTIC)
1416 panic("tulip_media_poll: botch at line %d\n", __LINE__);
1421 #if defined(TULIP_DEBUG)
1422 loudprintf("%s(phy%d): autonegotiation failure: state = %d\n",
1423 ifp->if_xname, phyaddr, sc->tulip_probe_state);
1424 sc->tulip_dbg.dbg_nway_failures++;
1429 tulip_2114x_media_preset(
1430 tulip_softc_t * const sc)
1432 const tulip_media_info_t *mi = NULL;
1433 tulip_media_t media = sc->tulip_media;
1435 TULIP_LOCK_ASSERT(sc);
1436 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1437 media = sc->tulip_media;
1439 media = sc->tulip_probe_media;
1441 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
1442 sc->tulip_flags &= ~TULIP_SQETEST;
1443 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
1444 #if defined(TULIP_DEBUG)
1445 if (media < TULIP_MEDIA_MAX && sc->tulip_mediums[media] != NULL) {
1447 mi = sc->tulip_mediums[media];
1448 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
1449 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1450 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR
1451 || mi->mi_type == TULIP_MEDIAINFO_SYM) {
1452 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
1453 sc->tulip_cmdmode |= mi->mi_cmdmode;
1454 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
1455 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
1457 #if defined(TULIP_DEBUG)
1459 if_printf(sc->tulip_ifp, "preset: bad media %d!\n", media);
1464 case TULIP_MEDIA_BNC:
1465 case TULIP_MEDIA_AUI:
1466 case TULIP_MEDIA_10BASET: {
1467 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1468 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
1469 sc->tulip_ifp->if_baudrate = 10000000;
1470 sc->tulip_flags |= TULIP_SQETEST;
1473 case TULIP_MEDIA_10BASET_FD: {
1474 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
1475 sc->tulip_ifp->if_baudrate = 10000000;
1478 case TULIP_MEDIA_100BASEFX:
1479 case TULIP_MEDIA_100BASET4:
1480 case TULIP_MEDIA_100BASETX: {
1481 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL);
1482 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1483 sc->tulip_ifp->if_baudrate = 100000000;
1486 case TULIP_MEDIA_100BASEFX_FD:
1487 case TULIP_MEDIA_100BASETX_FD: {
1488 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT;
1489 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
1490 sc->tulip_ifp->if_baudrate = 100000000;
1497 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1501 ********************************************************************
1502 * Start of 21140/21140A support which does not use the MII interface
1506 tulip_null_media_poll(
1507 tulip_softc_t * const sc,
1508 tulip_mediapoll_event_t event)
1510 #if defined(TULIP_DEBUG)
1511 sc->tulip_dbg.dbg_events[event]++;
1513 #if defined(DIAGNOSTIC)
1514 if_printf(sc->tulip_ifp, "botch(media_poll) at line %d\n", __LINE__);
1518 __inline static void
1519 tulip_21140_mediainit(
1520 tulip_softc_t * const sc,
1521 tulip_media_info_t * const mip,
1522 tulip_media_t const media,
1526 TULIP_LOCK_ASSERT(sc);
1527 sc->tulip_mediums[media] = mip;
1528 mip->mi_type = TULIP_MEDIAINFO_GPR;
1529 mip->mi_cmdmode = cmdmode;
1530 mip->mi_gpdata = gpdata;
1534 tulip_21140_evalboard_media_probe(
1535 tulip_softc_t * const sc)
1537 tulip_media_info_t *mip = sc->tulip_mediainfo;
1539 TULIP_LOCK_ASSERT(sc);
1540 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1541 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1542 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1543 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1544 TULIP_CSR_WRITE(sc, csr_command,
1545 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1546 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1547 TULIP_CSR_WRITE(sc, csr_command,
1548 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1550 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
1551 sc->tulip_media = TULIP_MEDIA_10BASET;
1553 sc->tulip_media = TULIP_MEDIA_100BASETX;
1555 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1557 TULIP_CMD_TXTHRSHLDCTL);
1558 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1560 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1561 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1563 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1564 |TULIP_CMD_SCRAMBLER);
1565 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1567 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1568 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1571 static const tulip_boardsw_t tulip_21140_eb_boardsw = {
1573 tulip_21140_evalboard_media_probe,
1575 tulip_null_media_poll,
1576 tulip_2114x_media_preset,
1580 tulip_21140_accton_media_probe(
1581 tulip_softc_t * const sc)
1583 tulip_media_info_t *mip = sc->tulip_mediainfo;
1586 TULIP_LOCK_ASSERT(sc);
1587 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1588 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1589 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1590 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1591 TULIP_CSR_WRITE(sc, csr_command,
1592 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1593 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1594 TULIP_CSR_WRITE(sc, csr_command,
1595 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1597 gpdata = TULIP_CSR_READ(sc, csr_gp);
1598 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) {
1599 sc->tulip_media = TULIP_MEDIA_10BASET;
1601 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) {
1602 sc->tulip_media = TULIP_MEDIA_BNC;
1604 sc->tulip_media = TULIP_MEDIA_100BASETX;
1607 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC,
1608 TULIP_GP_EN1207_BNC_INIT,
1609 TULIP_CMD_TXTHRSHLDCTL);
1610 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1611 TULIP_GP_EN1207_UTP_INIT,
1612 TULIP_CMD_TXTHRSHLDCTL);
1613 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1614 TULIP_GP_EN1207_UTP_INIT,
1615 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1616 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1617 TULIP_GP_EN1207_100_INIT,
1618 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1619 |TULIP_CMD_SCRAMBLER);
1620 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1621 TULIP_GP_EN1207_100_INIT,
1622 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1623 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1626 static const tulip_boardsw_t tulip_21140_accton_boardsw = {
1628 tulip_21140_accton_media_probe,
1630 tulip_null_media_poll,
1631 tulip_2114x_media_preset,
1635 tulip_21140_smc9332_media_probe(
1636 tulip_softc_t * const sc)
1638 tulip_media_info_t *mip = sc->tulip_mediainfo;
1641 TULIP_LOCK_ASSERT(sc);
1642 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE);
1643 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
1644 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
1645 33MHz that comes to two microseconds but wait a
1646 bit longer anyways) */
1647 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT |
1648 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1649 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS;
1650 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT;
1651 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET);
1652 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT);
1654 for (idx = 1000; idx > 0; idx--) {
1655 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1656 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) {
1659 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
1666 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1667 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1668 TULIP_GP_SMC_9332_INIT,
1669 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1670 |TULIP_CMD_SCRAMBLER);
1671 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1672 TULIP_GP_SMC_9332_INIT,
1673 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1674 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1675 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1676 TULIP_GP_SMC_9332_INIT,
1677 TULIP_CMD_TXTHRSHLDCTL);
1678 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1679 TULIP_GP_SMC_9332_INIT,
1680 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1683 static const tulip_boardsw_t tulip_21140_smc9332_boardsw = {
1684 TULIP_21140_SMC_9332,
1685 tulip_21140_smc9332_media_probe,
1687 tulip_null_media_poll,
1688 tulip_2114x_media_preset,
1692 tulip_21140_cogent_em100_media_probe(
1693 tulip_softc_t * const sc)
1695 tulip_media_info_t *mip = sc->tulip_mediainfo;
1696 u_int32_t cmdmode = TULIP_CSR_READ(sc, csr_command);
1698 TULIP_LOCK_ASSERT(sc);
1699 sc->tulip_gpinit = TULIP_GP_EM100_PINS;
1700 sc->tulip_gpdata = TULIP_GP_EM100_INIT;
1701 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS);
1702 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT);
1704 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE;
1705 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER);
1706 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1707 TULIP_CSR_WRITE(sc, csr_command, cmdmode);
1708 sc->tulip_media = TULIP_MEDIA_100BASEFX;
1710 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX,
1711 TULIP_GP_EM100_INIT,
1712 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION);
1713 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD,
1714 TULIP_GP_EM100_INIT,
1715 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1716 |TULIP_CMD_FULLDUPLEX);
1718 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);
1719 sc->tulip_media = TULIP_MEDIA_100BASETX;
1720 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1721 TULIP_GP_EM100_INIT,
1722 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1723 |TULIP_CMD_SCRAMBLER);
1724 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1725 TULIP_GP_EM100_INIT,
1726 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1727 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1731 static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {
1732 TULIP_21140_COGENT_EM100,
1733 tulip_21140_cogent_em100_media_probe,
1735 tulip_null_media_poll,
1736 tulip_2114x_media_preset
1740 tulip_21140_znyx_zx34x_media_probe(
1741 tulip_softc_t * const sc)
1743 tulip_media_info_t *mip = sc->tulip_mediainfo;
1744 int cnt10 = 0, cnt100 = 0, idx;
1746 TULIP_LOCK_ASSERT(sc);
1747 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS;
1748 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT;
1749 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS);
1750 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT);
1751 TULIP_CSR_WRITE(sc, csr_command,
1752 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1753 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1754 TULIP_CSR_WRITE(sc, csr_command,
1755 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1758 for (idx = 1000; idx > 0; idx--) {
1759 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1760 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)) {
1763 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
1772 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1773 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1774 TULIP_GP_ZX34X_INIT,
1775 TULIP_CMD_TXTHRSHLDCTL);
1776 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1777 TULIP_GP_ZX34X_INIT,
1778 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1779 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1780 TULIP_GP_ZX34X_INIT,
1781 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1782 |TULIP_CMD_SCRAMBLER);
1783 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1784 TULIP_GP_ZX34X_INIT,
1785 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1786 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1789 static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = {
1790 TULIP_21140_ZNYX_ZX34X,
1791 tulip_21140_znyx_zx34x_media_probe,
1793 tulip_null_media_poll,
1794 tulip_2114x_media_preset,
1798 tulip_2114x_media_probe(
1799 tulip_softc_t * const sc)
1801 TULIP_LOCK_ASSERT(sc);
1802 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE
1803 |TULIP_CMD_BACKOFFCTR|TULIP_CMD_THRSHLD72;
1806 static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
1808 tulip_2114x_media_probe,
1811 tulip_2114x_media_preset,
1815 * ******** END of chip-specific handlers. ***********
1819 * Code the read the SROM and MII bit streams (I2C)
1821 #define EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
1825 tulip_softc_t * const sc)
1829 csr = SROMSEL ; EMIT;
1830 csr = SROMSEL | SROMRD; EMIT;
1831 csr ^= SROMCS; EMIT;
1832 csr ^= SROMCLKON; EMIT;
1835 * Write 25 cycles of 0 which will force the SROM to be idle.
1837 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1838 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1839 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1841 csr ^= SROMCLKOFF; EMIT;
1842 csr ^= SROMCS; EMIT;
1849 tulip_softc_t * const sc)
1852 const unsigned bitwidth = SROM_BITWIDTH;
1853 const unsigned cmdmask = (SROMCMD_RD << bitwidth);
1854 const unsigned msb = 1 << (bitwidth + 3 - 1);
1855 unsigned lastidx = (1 << bitwidth) - 1;
1857 tulip_srom_idle(sc);
1859 for (idx = 0; idx <= lastidx; idx++) {
1860 unsigned lastbit, data, bits, bit, csr;
1861 csr = SROMSEL ; EMIT;
1862 csr = SROMSEL | SROMRD; EMIT;
1863 csr ^= SROMCSON; EMIT;
1864 csr ^= SROMCLKON; EMIT;
1867 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
1868 const unsigned thisbit = bits & msb;
1869 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1870 if (thisbit != lastbit) {
1871 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1875 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1878 csr ^= SROMCLKOFF; EMIT;
1880 for (data = 0, bits = 0; bits < 16; bits++) {
1882 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1883 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1884 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1886 sc->tulip_rombuf[idx*2] = data & 0xFF;
1887 sc->tulip_rombuf[idx*2+1] = data >> 8;
1888 csr = SROMSEL | SROMRD; EMIT;
1891 tulip_srom_idle(sc);
1894 #define MII_EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
1897 tulip_mii_writebits(
1898 tulip_softc_t * const sc,
1902 unsigned msb = 1 << (bits - 1);
1903 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1904 unsigned lastbit = (csr & MII_DOUT) ? msb : 0;
1906 TULIP_LOCK_ASSERT(sc);
1907 csr |= MII_WR; MII_EMIT; /* clock low; assert write */
1909 for (; bits > 0; bits--, data <<= 1) {
1910 const unsigned thisbit = data & msb;
1911 if (thisbit != lastbit) {
1912 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */
1914 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1916 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1921 tulip_mii_turnaround(
1922 tulip_softc_t * const sc,
1925 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1927 TULIP_LOCK_ASSERT(sc);
1928 if (cmd == MII_WRCMD) {
1929 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
1930 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1931 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1932 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */
1934 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */
1936 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1937 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1942 tulip_softc_t * const sc)
1945 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1948 TULIP_LOCK_ASSERT(sc);
1949 for (idx = 0, data = 0; idx < 16; idx++) {
1950 data <<= 1; /* this is NOOP on the first pass through */
1951 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1952 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)
1954 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1956 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
1963 tulip_softc_t * const sc,
1967 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1970 TULIP_LOCK_ASSERT(sc);
1971 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1972 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1973 tulip_mii_writebits(sc, MII_RDCMD, 8);
1974 tulip_mii_writebits(sc, devaddr, 5);
1975 tulip_mii_writebits(sc, regno, 5);
1976 tulip_mii_turnaround(sc, MII_RDCMD);
1978 data = tulip_mii_readbits(sc);
1979 #if defined(TULIP_DEBUG)
1980 sc->tulip_dbg.dbg_phyregs[regno][0] = data;
1981 sc->tulip_dbg.dbg_phyregs[regno][1]++;
1988 tulip_softc_t * const sc,
1993 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1995 TULIP_LOCK_ASSERT(sc);
1996 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1997 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1998 tulip_mii_writebits(sc, MII_WRCMD, 8);
1999 tulip_mii_writebits(sc, devaddr, 5);
2000 tulip_mii_writebits(sc, regno, 5);
2001 tulip_mii_turnaround(sc, MII_WRCMD);
2002 tulip_mii_writebits(sc, data, 16);
2003 #if defined(TULIP_DEBUG)
2004 sc->tulip_dbg.dbg_phyregs[regno][2] = data;
2005 sc->tulip_dbg.dbg_phyregs[regno][3]++;
2009 #define tulip_mchash(mca) (ether_crc32_le(mca, 6) & 0x1FF)
2010 #define tulip_srom_crcok(databuf) ( \
2011 ((ether_crc32_le(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
2012 ((databuf)[126] | ((databuf)[127] << 8)))
2015 tulip_identify_dec_nic(
2016 tulip_softc_t * const sc)
2018 TULIP_LOCK_ASSERT(sc);
2019 strcpy(sc->tulip_boardid, "DEC ");
2021 if (sc->tulip_chipid <= TULIP_21040)
2023 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0
2024 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {
2025 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);
2026 sc->tulip_boardid[D0+8] = ' ';
2032 tulip_identify_znyx_nic(
2033 tulip_softc_t * const sc)
2037 TULIP_LOCK_ASSERT(sc);
2038 strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
2039 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
2041 sc->tulip_boardid[8] = '4';
2042 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
2043 if (znyx_ptr < 26 || znyx_ptr > 116) {
2044 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2047 /* ZX344 = 0010 .. 0013FF
2049 if (sc->tulip_rombuf[znyx_ptr] == 0x4A
2050 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52
2051 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) {
2052 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4];
2053 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) {
2054 sc->tulip_boardid[9] = '2';
2055 if (id == TULIP_ZNYX_ID_ZX342B) {
2056 sc->tulip_boardid[10] = 'B';
2057 sc->tulip_boardid[11] = ' ';
2059 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2060 } else if (id == TULIP_ZNYX_ID_ZX344) {
2061 sc->tulip_boardid[10] = '4';
2062 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2063 } else if (id == TULIP_ZNYX_ID_ZX345) {
2064 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5';
2065 } else if (id == TULIP_ZNYX_ID_ZX346) {
2066 sc->tulip_boardid[9] = '6';
2067 } else if (id == TULIP_ZNYX_ID_ZX351) {
2068 sc->tulip_boardid[8] = '5';
2069 sc->tulip_boardid[9] = '1';
2074 * Assume it's a ZX342...
2076 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2080 sc->tulip_boardid[8] = '1';
2081 if (sc->tulip_chipid == TULIP_21041) {
2082 sc->tulip_boardid[10] = '1';
2085 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) {
2086 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36];
2087 if (id == TULIP_ZNYX_ID_ZX312T) {
2088 sc->tulip_boardid[9] = '2';
2089 sc->tulip_boardid[10] = 'T';
2090 sc->tulip_boardid[11] = ' ';
2091 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2092 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) {
2093 sc->tulip_boardid[9] = '4';
2094 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2095 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2096 } else if (id == TULIP_ZNYX_ID_ZX314) {
2097 sc->tulip_boardid[9] = '4';
2098 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2099 sc->tulip_features |= TULIP_HAVE_BASEROM;
2100 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) {
2101 sc->tulip_boardid[9] = '5';
2102 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2103 } else if (id == TULIP_ZNYX_ID_ZX315) {
2104 sc->tulip_boardid[9] = '5';
2105 sc->tulip_features |= TULIP_HAVE_BASEROM;
2111 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) {
2112 sc->tulip_boardid[9] = '4';
2113 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2114 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2115 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) {
2116 sc->tulip_boardid[9] = '5';
2117 sc->tulip_boardsw = &tulip_21040_boardsw;
2118 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2119 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) {
2120 sc->tulip_boardid[9] = '2';
2121 sc->tulip_boardsw = &tulip_21040_boardsw;
2127 tulip_identify_smc_nic(
2128 tulip_softc_t * const sc)
2130 u_int32_t id1, id2, ei;
2131 int auibnc = 0, utp = 0;
2134 TULIP_LOCK_ASSERT(sc);
2135 strcpy(sc->tulip_boardid, "SMC ");
2136 if (sc->tulip_chipid == TULIP_21041)
2138 if (sc->tulip_chipid != TULIP_21040) {
2139 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2140 strcpy(&sc->tulip_boardid[4], "9332DST ");
2141 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;
2142 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {
2143 strcpy(&sc->tulip_boardid[4], "9334BDT ");
2145 strcpy(&sc->tulip_boardid[4], "9332BDT ");
2149 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);
2150 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);
2151 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);
2153 strcpy(&sc->tulip_boardid[4], "8432");
2154 cp = &sc->tulip_boardid[8];
2156 *cp++ = 'B', auibnc = 1;
2157 if ((id1 & 0xFF) > 0x32)
2158 *cp++ = 'T', utp = 1;
2159 if ((id1 & 0x4000) == 0)
2160 *cp++ = 'A', auibnc = 1;
2162 sc->tulip_boardid[7] = '4';
2166 *cp++ = (ei ? '2' : '1');
2171 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2172 else if (!utp && auibnc)
2173 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
2177 tulip_identify_cogent_nic(
2178 tulip_softc_t * const sc)
2180 TULIP_LOCK_ASSERT(sc);
2181 strcpy(sc->tulip_boardid, "Cogent ");
2182 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
2183 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {
2184 strcat(sc->tulip_boardid, "EM100TX ");
2185 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2186 #if defined(TULIP_COGENT_EM110TX_ID)
2187 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {
2188 strcat(sc->tulip_boardid, "EM110TX ");
2189 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2191 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
2192 strcat(sc->tulip_boardid, "EM100FX ");
2193 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2196 * Magic number (0x24001109U) is the SubVendor (0x2400) and
2197 * SubDevId (0x1109) for the ANA6944TX (EM440TX).
2199 if (*(u_int32_t *) sc->tulip_rombuf == 0x24001109U
2200 && (sc->tulip_features & TULIP_HAVE_BASEROM)) {
2202 * Cogent (Adaptec) is still mapping all INTs to INTA of
2203 * first 21140. Dumb! Dumb!
2205 strcat(sc->tulip_boardid, "EM440TX ");
2206 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2208 } else if (sc->tulip_chipid == TULIP_21040) {
2209 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2214 tulip_identify_accton_nic(
2215 tulip_softc_t * const sc)
2217 TULIP_LOCK_ASSERT(sc);
2218 strcpy(sc->tulip_boardid, "ACCTON ");
2219 switch (sc->tulip_chipid) {
2221 strcat(sc->tulip_boardid, "EN1207 ");
2222 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
2223 sc->tulip_boardsw = &tulip_21140_accton_boardsw;
2226 strcat(sc->tulip_boardid, "EN1207TX ");
2227 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
2228 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2231 strcat(sc->tulip_boardid, "EN1203 ");
2232 sc->tulip_boardsw = &tulip_21040_boardsw;
2235 strcat(sc->tulip_boardid, "EN1203 ");
2236 sc->tulip_boardsw = &tulip_21041_boardsw;
2239 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2245 tulip_identify_asante_nic(
2246 tulip_softc_t * const sc)
2248 TULIP_LOCK_ASSERT(sc);
2249 strcpy(sc->tulip_boardid, "Asante ");
2250 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
2251 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2252 tulip_media_info_t *mi = sc->tulip_mediainfo;
2255 * The Asante Fast Ethernet doesn't always ship with a valid
2256 * new format SROM. So if isn't in the new format, we cheat
2257 * set it up as if we had.
2260 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;
2261 sc->tulip_gpdata = 0;
2263 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);
2264 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);
2266 TULIP_CSR_WRITE(sc, csr_gp, 0);
2268 mi->mi_type = TULIP_MEDIAINFO_MII;
2269 mi->mi_gpr_length = 0;
2270 mi->mi_gpr_offset = 0;
2271 mi->mi_reset_length = 0;
2272 mi->mi_reset_offset = 0;;
2274 mi->mi_phyaddr = TULIP_MII_NOPHY;
2275 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) {
2277 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
2279 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2280 if_printf(sc->tulip_ifp, "can't find phy 0\n");
2284 sc->tulip_features |= TULIP_HAVE_MII;
2285 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2286 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2287 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD;
2288 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD;
2289 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2290 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2291 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2292 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2293 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2294 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2295 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2297 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2302 tulip_identify_compex_nic(
2303 tulip_softc_t * const sc)
2305 TULIP_LOCK_ASSERT(sc);
2306 strcpy(sc->tulip_boardid, "COMPEX ");
2307 if (sc->tulip_chipid == TULIP_21140A) {
2309 tulip_softc_t *root_sc = NULL;
2311 strcat(sc->tulip_boardid, "400TX/PCI ");
2313 * All 4 chips on these boards share an interrupt. This code
2314 * copied from tulip_read_macaddr.
2316 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2317 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2318 root_sc = tulips[root_unit];
2320 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
2325 && root_sc->tulip_chipid == sc->tulip_chipid
2326 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2327 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2328 sc->tulip_slaves = root_sc->tulip_slaves;
2329 root_sc->tulip_slaves = sc;
2330 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
2331 printf("\nCannot find master device for %s interrupts",
2332 sc->tulip_ifp->if_xname);
2335 strcat(sc->tulip_boardid, "unknown ");
2337 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */
2343 tulip_softc_t * const sc)
2345 unsigned idx1, idx2, idx3;
2347 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
2348 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
2349 tulip_srom_media_t srom_media;
2350 tulip_media_info_t *mi = sc->tulip_mediainfo;
2352 u_int32_t leaf_offset, blocks, data;
2354 TULIP_LOCK_ASSERT(sc);
2355 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
2356 if (shp->sh_adapter_count == 1)
2358 if (saip->sai_device == sc->tulip_pci_devno)
2362 * Didn't find the right media block for this card.
2364 if (idx1 == shp->sh_adapter_count)
2368 * Save the hardware address.
2370 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6);
2372 * If this is a multiple port card, add the adapter index to the last
2373 * byte of the hardware address. (if it isn't multiport, adding 0
2376 sc->tulip_enaddr[5] += idx1;
2378 leaf_offset = saip->sai_leaf_offset_lowbyte
2379 + saip->sai_leaf_offset_highbyte * 256;
2380 dp = sc->tulip_rombuf + leaf_offset;
2382 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2;
2384 for (idx2 = 0;; idx2++) {
2385 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype
2386 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED)
2389 sc->tulip_connidx = idx2;
2391 if (sc->tulip_chipid == TULIP_21041) {
2393 for (idx2 = 0; idx2 < blocks; idx2++) {
2394 tulip_media_t media;
2396 srom_media = (tulip_srom_media_t) (data & 0x3F);
2397 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2398 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2401 media = tulip_srom_mediums[idx3].sm_type;
2402 if (media != TULIP_MEDIA_UNKNOWN) {
2403 if (data & TULIP_SROM_21041_EXTENDED) {
2404 mi->mi_type = TULIP_MEDIAINFO_SIA;
2405 sc->tulip_mediums[media] = mi;
2406 mi->mi_sia_connectivity = dp[0] + dp[1] * 256;
2407 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256;
2408 mi->mi_sia_general = dp[4] + dp[5] * 256;
2412 case TULIP_MEDIA_BNC: {
2413 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
2417 case TULIP_MEDIA_AUI: {
2418 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
2422 case TULIP_MEDIA_10BASET: {
2423 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
2427 case TULIP_MEDIA_10BASET_FD: {
2428 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
2438 if (data & TULIP_SROM_21041_EXTENDED)
2443 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++;
2444 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++;
2445 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++;
2446 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++;
2450 unsigned length, type;
2451 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN;
2452 if (sc->tulip_features & TULIP_HAVE_GPR)
2453 sc->tulip_gpinit = *dp++;
2455 for (idx2 = 0; idx2 < blocks; idx2++) {
2457 if ((*dp & 0x80) == 0) {
2461 length = (*dp++ & 0x7f) - 1;
2462 type = *dp++ & 0x3f;
2465 switch (type & 0x3f) {
2466 case 0: { /* 21140[A] GPR block */
2467 tulip_media_t media;
2468 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2469 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2470 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2473 media = tulip_srom_mediums[idx3].sm_type;
2474 if (media == TULIP_MEDIA_UNKNOWN)
2476 mi->mi_type = TULIP_MEDIAINFO_GPR;
2477 sc->tulip_mediums[media] = mi;
2478 mi->mi_gpdata = dp[1];
2479 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) {
2480 sc->tulip_gpdata = mi->mi_gpdata;
2483 data = dp[2] + dp[3] * 256;
2484 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2485 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2489 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2491 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2492 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2497 case 1: { /* 21140[A] MII block */
2498 const unsigned phyno = *dp++;
2499 mi->mi_type = TULIP_MEDIAINFO_MII;
2500 mi->mi_gpr_length = *dp++;
2501 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2502 dp += mi->mi_gpr_length;
2503 mi->mi_reset_length = *dp++;
2504 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2505 dp += mi->mi_reset_length;
2508 * Before we probe for a PHY, use the GPR information
2509 * to select it. If we don't, it may be inaccessible.
2511 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET);
2512 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) {
2514 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]);
2516 sc->tulip_phyaddr = mi->mi_phyaddr;
2517 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) {
2519 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]);
2523 * At least write something!
2525 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2526 TULIP_CSR_WRITE(sc, csr_gp, 0);
2528 mi->mi_phyaddr = TULIP_MII_NOPHY;
2529 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2531 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2533 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2534 #if defined(TULIP_DEBUG)
2535 if_printf(sc->tulip_ifp, "can't find phy %d\n",
2540 sc->tulip_features |= TULIP_HAVE_MII;
2541 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2542 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2543 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2544 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2545 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2546 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2547 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2548 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2549 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2550 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2551 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2555 case 2: { /* 2114[23] SIA block */
2556 tulip_media_t media;
2557 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2558 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2559 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2562 media = tulip_srom_mediums[idx3].sm_type;
2563 if (media == TULIP_MEDIA_UNKNOWN)
2565 mi->mi_type = TULIP_MEDIAINFO_SIA;
2566 sc->tulip_mediums[media] = mi;
2568 mi->mi_sia_connectivity = dp[1] + dp[2] * 256;
2569 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256;
2570 mi->mi_sia_general = dp[5] + dp[6] * 256;
2574 case TULIP_MEDIA_BNC: {
2575 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
2578 case TULIP_MEDIA_AUI: {
2579 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
2582 case TULIP_MEDIA_10BASET: {
2583 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
2584 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2587 case TULIP_MEDIA_10BASET_FD: {
2588 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
2589 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2597 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16;
2598 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16;
2603 case 3: { /* 2114[23] MII PHY block */
2604 const unsigned phyno = *dp++;
2605 const u_int8_t *dp0;
2606 mi->mi_type = TULIP_MEDIAINFO_MII;
2607 mi->mi_gpr_length = *dp++;
2608 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2609 dp += 2 * mi->mi_gpr_length;
2610 mi->mi_reset_length = *dp++;
2611 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2612 dp += 2 * mi->mi_reset_length;
2614 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset];
2615 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) {
2617 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2619 sc->tulip_phyaddr = mi->mi_phyaddr;
2620 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset];
2621 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) {
2623 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2626 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2627 TULIP_CSR_WRITE(sc, csr_sia_general, 0);
2629 mi->mi_phyaddr = TULIP_MII_NOPHY;
2630 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2632 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2634 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2635 #if defined(TULIP_DEBUG)
2636 if_printf(sc->tulip_ifp, "can't find phy %d\n",
2641 sc->tulip_features |= TULIP_HAVE_MII;
2642 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2643 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2644 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2645 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2646 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2;
2647 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2648 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2649 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2650 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2651 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2652 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2653 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2657 case 4: { /* 21143 SYM block */
2658 tulip_media_t media;
2659 srom_media = (tulip_srom_media_t) dp[0];
2660 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2661 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2664 media = tulip_srom_mediums[idx3].sm_type;
2665 if (media == TULIP_MEDIA_UNKNOWN)
2667 mi->mi_type = TULIP_MEDIAINFO_SYM;
2668 sc->tulip_mediums[media] = mi;
2669 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16;
2670 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16;
2671 data = dp[5] + dp[6] * 256;
2672 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2673 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2676 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2677 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2678 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2680 if (TULIP_IS_MEDIA_TP(media))
2681 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2686 case 5: { /* 21143 Reset block */
2687 mi->mi_type = TULIP_MEDIAINFO_RESET;
2688 mi->mi_reset_length = *dp++;
2689 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2690 dp += 2 * mi->mi_reset_length;
2701 return mi - sc->tulip_mediainfo;
2704 static const struct {
2705 void (*vendor_identify_nic)(tulip_softc_t * const sc);
2706 unsigned char vendor_oui[3];
2707 } tulip_vendors[] = {
2708 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } },
2709 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } },
2710 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } },
2711 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } },
2712 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } },
2713 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } },
2714 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } },
2715 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } },
2716 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } },
2717 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } },
2722 * This deals with the vagaries of the address roms and the
2723 * brain-deadness that various vendors commit in using them.
2727 tulip_softc_t * const sc)
2729 unsigned cksum, rom_cksum, idx;
2731 unsigned char tmpbuf[8];
2732 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
2734 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX;
2736 if (sc->tulip_chipid == TULIP_21040) {
2737 TULIP_CSR_WRITE(sc, csr_enetrom, 1);
2738 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2740 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
2742 sc->tulip_rombuf[idx] = csr & 0xFF;
2744 sc->tulip_boardsw = &tulip_21040_boardsw;
2746 if (sc->tulip_chipid == TULIP_21041) {
2748 * Thankfully all 21041's act the same.
2750 sc->tulip_boardsw = &tulip_21041_boardsw;
2753 * Assume all 21140 board are compatible with the
2754 * DEC 10/100 evaluation board. Not really valid but
2755 * it's the best we can do until every one switches to
2756 * the new SROM format.
2759 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2761 tulip_srom_read(sc);
2762 if (tulip_srom_crcok(sc->tulip_rombuf)) {
2764 * SROM CRC is valid therefore it must be in the
2767 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM;
2768 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
2770 * No checksum is present. See if the SROM id checks out;
2771 * the first 18 bytes should be 0 followed by a 1 followed
2772 * by the number of adapters (which we don't deal with yet).
2774 for (idx = 0; idx < 18; idx++) {
2775 if (sc->tulip_rombuf[idx] != 0)
2778 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
2779 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2780 } else if (sc->tulip_chipid >= TULIP_21142) {
2781 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2782 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2784 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) {
2785 if (sc->tulip_chipid != TULIP_21041)
2786 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2789 * If the SROM specifies more than one adapter, tag this as a
2792 if (sc->tulip_rombuf[19] > 1)
2793 sc->tulip_features |= TULIP_HAVE_BASEROM;
2794 if (sc->tulip_boardsw == NULL)
2801 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
2803 * Some folks don't use the standard ethernet rom format
2804 * but instead just put the address in the first 6 bytes
2805 * of the rom and let the rest be all 0xffs. (Can we say
2806 * ZNYX?) (well sometimes they put in a checksum so we'll
2809 for (idx = 8; idx < 32; idx++) {
2810 if (sc->tulip_rombuf[idx] != 0xFF)
2814 * Make sure the address is not multicast or locally assigned
2815 * that the OUI is not 00-00-00.
2817 if ((sc->tulip_rombuf[0] & 3) != 0)
2819 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
2820 && sc->tulip_rombuf[2] == 0)
2822 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2823 sc->tulip_features |= TULIP_HAVE_OKROM;
2827 * A number of makers of multiport boards (ZNYX and Cogent)
2828 * only put on one address ROM on their 21040 boards. So
2829 * if the ROM is all zeros (or all 0xFFs), look at the
2830 * previous configured boards (as long as they are on the same
2831 * PCI bus and the bus number is non-zero) until we find the
2832 * master board with address ROM. We then use its address ROM
2833 * as the base for this board. (we add our relative board
2834 * to the last byte of its address).
2836 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2837 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF)
2840 if (idx == sizeof(sc->tulip_rombuf)) {
2842 tulip_softc_t *root_sc = NULL;
2843 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2844 root_sc = tulips[root_unit];
2845 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
2849 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM)
2850 && root_sc->tulip_chipid == sc->tulip_chipid
2851 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2852 sc->tulip_features |= TULIP_HAVE_SLAVEDROM;
2853 sc->tulip_boardsw = root_sc->tulip_boardsw;
2854 strcpy(sc->tulip_boardid, root_sc->tulip_boardid);
2855 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) {
2856 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf,
2857 sizeof(sc->tulip_rombuf));
2858 if (!tulip_srom_decode(sc))
2861 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
2862 sc->tulip_enaddr[5] += sc->tulip_unit - root_sc->tulip_unit;
2865 * Now for a truly disgusting kludge: all 4 21040s on
2866 * the ZX314 share the same INTA line so the mapping
2867 * setup by the BIOS on the PCI bridge is worthless.
2868 * Rather than reprogramming the value in the config
2869 * register, we will handle this internally.
2871 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) {
2872 sc->tulip_slaves = root_sc->tulip_slaves;
2873 root_sc->tulip_slaves = sc;
2874 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2882 * This is the standard DEC address ROM test.
2885 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
2888 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
2889 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
2890 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
2891 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
2892 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
2895 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2897 cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
2899 if (cksum > 65535) cksum -= 65535;
2900 cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
2901 if (cksum > 65535) cksum -= 65535;
2903 if (cksum > 65535) cksum -= 65535;
2904 cksum += *(u_int16_t *) &sc->tulip_enaddr[4];
2905 if (cksum >= 65535) cksum -= 65535;
2907 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6];
2909 if (cksum != rom_cksum)
2914 * Check for various boards based on OUI. Did I say braindead?
2916 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) {
2917 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) {
2918 (*tulip_vendors[idx].vendor_identify_nic)(sc);
2923 sc->tulip_features |= TULIP_HAVE_OKROM;
2929 tulip_softc_t * const sc)
2931 tulip_media_t media;
2934 TULIP_LOCK_ASSERT(sc);
2935 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2936 if (sc->tulip_mediums[media] != NULL) {
2937 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media],
2943 sc->tulip_features |= TULIP_HAVE_NOMEDIA;
2944 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0);
2945 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE);
2946 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
2947 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0);
2948 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO);
2950 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]);
2951 sc->tulip_flags |= TULIP_PRINTMEDIA;
2952 tulip_linkup(sc, sc->tulip_media);
2957 tulip_ifmedia_change(
2958 struct ifnet * const ifp)
2960 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
2963 sc->tulip_flags |= TULIP_NEEDRESET;
2964 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
2965 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
2966 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) {
2967 tulip_media_t media;
2968 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2969 if (sc->tulip_mediums[media] != NULL
2970 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) {
2971 sc->tulip_flags |= TULIP_PRINTMEDIA;
2972 sc->tulip_flags &= ~TULIP_DIDNWAY;
2973 tulip_linkup(sc, media);
2979 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
2987 * Media status callback
2990 tulip_ifmedia_status(
2991 struct ifnet * const ifp,
2992 struct ifmediareq *req)
2994 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2997 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
3002 req->ifm_status = IFM_AVALID;
3003 if (sc->tulip_flags & TULIP_LINKUP)
3004 req->ifm_status |= IFM_ACTIVE;
3006 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
3012 tulip_softc_t * const sc)
3014 struct ifmultiaddr *ifma;
3018 TULIP_LOCK_ASSERT(sc);
3019 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI);
3020 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART;
3021 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3022 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3023 #if defined(IFF_ALLMULTI)
3024 if (sc->tulip_ifp->if_flags & IFF_ALLMULTI)
3025 sc->tulip_flags |= TULIP_ALLMULTI ;
3029 TAILQ_FOREACH(ifma, &sc->tulip_ifp->if_multiaddrs, ifma_link) {
3031 if (ifma->ifma_addr->sa_family == AF_LINK)
3035 if (multicnt > 14) {
3036 u_int32_t *sp = sc->tulip_setupdata;
3039 * Some early passes of the 21140 have broken implementations of
3040 * hash-perfect mode. When we get too many multicasts for perfect
3041 * filtering with these chips, we need to switch into hash-only
3042 * mode (this is better than all-multicast on network with lots
3043 * of multicast traffic).
3045 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
3046 sc->tulip_flags |= TULIP_WANTHASHONLY;
3048 sc->tulip_flags |= TULIP_WANTHASHPERFECT;
3050 * If we have more than 14 multicasts, we have
3051 * go into hash perfect mode (512 bit multicast
3052 * hash and one perfect hardware).
3054 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
3056 TAILQ_FOREACH(ifma, &sc->tulip_ifp->if_multiaddrs, ifma_link) {
3058 if (ifma->ifma_addr->sa_family != AF_LINK)
3061 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
3062 #if BYTE_ORDER == BIG_ENDIAN
3063 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3065 sp[hash >> 4] |= 1 << (hash & 0xF);
3069 * No reason to use a hash if we are going to be
3070 * receiving every multicast.
3072 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
3073 hash = tulip_mchash(sc->tulip_ifp->if_broadcastaddr);
3074 #if BYTE_ORDER == BIG_ENDIAN
3075 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3077 sp[hash >> 4] |= 1 << (hash & 0xF);
3079 if (sc->tulip_flags & TULIP_WANTHASHONLY) {
3080 hash = tulip_mchash(IFP2ENADDR(sc->tulip_ifp));
3081 #if BYTE_ORDER == BIG_ENDIAN
3082 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3084 sp[hash >> 4] |= 1 << (hash & 0xF);
3087 #if BYTE_ORDER == BIG_ENDIAN
3088 sp[39] = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[0] << 16;
3089 sp[40] = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[1] << 16;
3090 sp[41] = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[2] << 16;
3092 sp[39] = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[0];
3093 sp[40] = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[1];
3094 sp[41] = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[2];
3099 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
3100 u_int32_t *sp = sc->tulip_setupdata;
3102 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
3104 * Else can get perfect filtering for 16 addresses.
3106 TAILQ_FOREACH(ifma, &sc->tulip_ifp->if_multiaddrs, ifma_link) {
3107 if (ifma->ifma_addr->sa_family != AF_LINK)
3109 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
3110 #if BYTE_ORDER == BIG_ENDIAN
3111 *sp++ = ((u_int16_t *) addrp)[0] << 16;
3112 *sp++ = ((u_int16_t *) addrp)[1] << 16;
3113 *sp++ = ((u_int16_t *) addrp)[2] << 16;
3115 *sp++ = ((u_int16_t *) addrp)[0];
3116 *sp++ = ((u_int16_t *) addrp)[1];
3117 *sp++ = ((u_int16_t *) addrp)[2];
3122 * Add the broadcast address.
3125 #if BYTE_ORDER == BIG_ENDIAN
3126 *sp++ = 0xFFFF << 16;
3127 *sp++ = 0xFFFF << 16;
3128 *sp++ = 0xFFFF << 16;
3136 * Pad the rest with our hardware address
3138 for (; idx < 16; idx++) {
3139 #if BYTE_ORDER == BIG_ENDIAN
3140 *sp++ = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[0] << 16;
3141 *sp++ = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[1] << 16;
3142 *sp++ = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[2] << 16;
3144 *sp++ = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[0];
3145 *sp++ = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[1];
3146 *sp++ = ((u_int16_t *) IFP2ENADDR(sc->tulip_ifp))[2];
3150 #if defined(IFF_ALLMULTI)
3151 if (sc->tulip_flags & TULIP_ALLMULTI)
3152 sc->tulip_ifp->if_flags |= IFF_ALLMULTI;
3158 tulip_softc_t * const sc)
3160 tulip_ringinfo_t *ri;
3162 u_int32_t inreset = (sc->tulip_flags & TULIP_INRESET);
3164 TULIP_LOCK_ASSERT(sc);
3167 * Brilliant. Simply brilliant. When switching modes/speeds
3168 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
3169 * bits in CSR6 and then do a software reset to get the 21140
3170 * to properly reset its internal pathways to the right places.
3173 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
3174 && sc->tulip_boardsw->bd_media_preset != NULL)
3175 (*sc->tulip_boardsw->bd_media_preset)(sc);
3177 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
3178 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
3179 33MHz that comes to two microseconds but wait a
3180 bit longer anyways) */
3183 sc->tulip_flags |= TULIP_INRESET;
3184 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
3185 sc->tulip_ifp->if_flags &= ~IFF_OACTIVE;
3188 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3189 TULIP_CSR_WRITE(sc, csr_txlist, sc->tulip_txdescmap->dm_segs[0].ds_addr);
3191 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
3193 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3194 TULIP_CSR_WRITE(sc, csr_rxlist, sc->tulip_rxdescmap->dm_segs[0].ds_addr);
3196 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
3198 TULIP_CSR_WRITE(sc, csr_busmode,
3199 (1 << (3 /*pci_max_burst_len*/ + 8))
3200 |TULIP_BUSMODE_CACHE_ALIGN8
3201 |TULIP_BUSMODE_READMULTIPLE
3202 |(BYTE_ORDER != LITTLE_ENDIAN ?
3203 TULIP_BUSMODE_DESC_BIGENDIAN : 0));
3205 sc->tulip_txtimer = 0;
3206 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
3208 * Free all the mbufs that were on the transmit ring.
3211 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3215 _IF_DEQUEUE(&sc->tulip_txq, m);
3218 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3219 map = M_GETCTX(m, bus_dmamap_t);
3220 bus_dmamap_unload(sc->tulip_dmatag, map);
3221 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
3226 ri = &sc->tulip_txinfo;
3227 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
3228 ri->ri_free = ri->ri_max;
3229 for (di = ri->ri_first; di < ri->ri_last; di++)
3231 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3232 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_txdescmap,
3233 0, sc->tulip_txdescmap->dm_mapsize,
3234 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
3238 * We need to collect all the mbufs were on the
3239 * receive ring before we reinit it either to put
3240 * them back on or to know if we have to allocate
3243 ri = &sc->tulip_rxinfo;
3244 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
3245 ri->ri_free = ri->ri_max;
3246 for (di = ri->ri_first; di < ri->ri_last; di++) {
3248 di->d_length1 = 0; di->d_addr1 = 0;
3249 di->d_length2 = 0; di->d_addr2 = 0;
3251 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3252 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_rxdescmap,
3253 0, sc->tulip_rxdescmap->dm_mapsize,
3254 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
3257 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3261 _IF_DEQUEUE(&sc->tulip_rxq, m);
3264 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3265 map = M_GETCTX(m, bus_dmamap_t);
3266 bus_dmamap_unload(sc->tulip_dmatag, map);
3267 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3273 * If tulip_reset is being called recurisvely, exit quickly knowing
3274 * that when the outer tulip_reset returns all the right stuff will
3280 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
3281 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
3282 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
3283 |TULIP_STS_RXSTOPPED;
3285 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
3286 (*sc->tulip_boardsw->bd_media_select)(sc);
3287 #if defined(TULIP_DEBUG)
3288 if ((sc->tulip_flags & TULIP_NEEDRESET) == TULIP_NEEDRESET)
3289 if_printf(sc->tulip_ifp,
3290 "tulip_reset: additional reset needed?!?\n");
3293 tulip_media_print(sc);
3294 if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
3295 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
3297 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
3299 tulip_addr_filter(sc);
3307 tulip_softc_t *sc = (tulip_softc_t *)arg;
3316 tulip_softc_t * const sc)
3318 if (sc->tulip_ifp->if_flags & IFF_UP) {
3319 if ((sc->tulip_ifp->if_flags & IFF_RUNNING) == 0) {
3320 /* initialize the media */
3323 sc->tulip_ifp->if_flags |= IFF_RUNNING;
3324 if (sc->tulip_ifp->if_flags & IFF_PROMISC) {
3325 sc->tulip_flags |= TULIP_PROMISC;
3326 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
3327 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3329 sc->tulip_flags &= ~TULIP_PROMISC;
3330 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
3331 if (sc->tulip_flags & TULIP_ALLMULTI) {
3332 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
3334 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
3337 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
3338 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
3340 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3341 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3343 sc->tulip_ifp->if_flags |= IFF_OACTIVE;
3344 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3345 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3347 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3348 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3349 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3350 tulip_txput_setup(sc);
3352 sc->tulip_ifp->if_flags &= ~IFF_RUNNING;
3359 tulip_softc_t * const sc)
3361 TULIP_PERFSTART(rxintr)
3362 tulip_ringinfo_t * const ri = &sc->tulip_rxinfo;
3363 struct ifnet * const ifp = sc->tulip_ifp;
3365 #if defined(TULIP_DEBUG)
3369 TULIP_LOCK_ASSERT(sc);
3371 TULIP_PERFSTART(rxget)
3372 tulip_desc_t *eop = ri->ri_nextin;
3373 int total_len = 0, last_offset = 0;
3374 struct mbuf *ms = NULL, *me = NULL;
3376 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3381 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
3384 #if defined(TULIP_DEBUG)
3385 if (cnt == ri->ri_max)
3389 * If the TULIP has no descriptors, there can't be any receive
3390 * descriptors to process.
3392 if (eop == ri->ri_nextout)
3396 * 90% of the packets will fit in one descriptor. So we optimize
3399 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3400 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
3401 _IF_DEQUEUE(&sc->tulip_rxq, ms);
3405 * If still owned by the TULIP, don't touch it.
3407 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
3411 * It is possible (though improbable unless MCLBYTES < 1518) for
3412 * a received packet to cross more than one receive descriptor.
3414 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) {
3415 if (++eop == ri->ri_last)
3417 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3418 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
3419 #if defined(TULIP_DEBUG)
3420 sc->tulip_dbg.dbg_rxintrs++;
3421 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
3423 TULIP_PERFEND(rxget);
3424 TULIP_PERFEND(rxintr);
3431 * Dequeue the first buffer for the start of the packet. Hopefully
3432 * this will be the only one we need to dequeue. However, if the
3433 * packet consumed multiple descriptors, then we need to dequeue
3434 * those buffers and chain to the starting mbuf. All buffers but
3435 * the last buffer have the same length so we can set that now.
3436 * (we add to last_offset instead of multiplying since we normally
3437 * won't go into the loop and thereby saving ourselves from
3438 * doing a multiplication by 0 in the normal case).
3440 _IF_DEQUEUE(&sc->tulip_rxq, ms);
3441 for (me = ms; total_len > 0; total_len--) {
3442 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3443 map = M_GETCTX(me, bus_dmamap_t);
3444 TULIP_RXMAP_POSTSYNC(sc, map);
3445 bus_dmamap_unload(sc->tulip_dmatag, map);
3446 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3447 #if defined(DIAGNOSTIC)
3450 #endif /* TULIP_BUS_DMA */
3451 me->m_len = TULIP_RX_BUFLEN;
3452 last_offset += TULIP_RX_BUFLEN;
3453 _IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
3459 * Now get the size of received packet (minus the CRC).
3461 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
3462 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
3463 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0)) {
3464 me->m_len = total_len - last_offset;
3466 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3467 map = M_GETCTX(me, bus_dmamap_t);
3468 bus_dmamap_sync(sc->tulip_dmatag, map, 0, me->m_len,
3469 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
3470 bus_dmamap_unload(sc->tulip_dmatag, map);
3471 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3472 #if defined(DIAGNOSTIC)
3475 #endif /* TULIP_BUS_DMA */
3477 sc->tulip_flags |= TULIP_RXACT;
3481 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3482 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3484 #if defined(TULIP_VERBOSE)
3485 const char *error = NULL;
3487 if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
3488 sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
3489 #if defined(TULIP_VERBOSE)
3490 error = "frame too long";
3493 if (eop->d_status & TULIP_DSTS_RxBADCRC) {
3494 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
3495 sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
3496 #if defined(TULIP_VERBOSE)
3497 error = "alignment error";
3500 sc->tulip_dot3stats.dot3StatsFCSErrors++;
3501 #if defined(TULIP_VERBOSE)
3506 #if defined(TULIP_VERBOSE)
3507 if (error != NULL && (sc->tulip_flags & TULIP_NOMESSAGES) == 0) {
3508 if_printf(sc->tulip_ifp, "receive: %6D: %s\n",
3509 mtod(ms, u_char *) + 6, ":",
3511 sc->tulip_flags |= TULIP_NOMESSAGES;
3516 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3517 map = M_GETCTX(me, bus_dmamap_t);
3518 bus_dmamap_unload(sc->tulip_dmatag, map);
3519 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3520 #if defined(DIAGNOSTIC)
3523 #endif /* TULIP_BUS_DMA */
3525 #if defined(TULIP_DEBUG)
3529 if (++eop == ri->ri_last)
3531 ri->ri_nextin = eop;
3534 * Either we are priming the TULIP with mbufs (m == NULL)
3535 * or we are about to accept an mbuf for the upper layers
3536 * so we need to allocate an mbuf to replace it. If we
3537 * can't replace it, send up it anyways. This may cause
3538 * us to drop packets in the future but that's better than
3539 * being caught in livelock.
3541 * Note that if this packet crossed multiple descriptors
3542 * we don't even try to reallocate all the mbufs here.
3543 * Instead we rely on the test of the beginning of
3544 * the loop to refill for the extra consumed mbufs.
3546 if (accept || ms == NULL) {
3548 MGETHDR(m0, M_DONTWAIT, MT_DATA);
3550 #if defined(TULIP_COPY_RXDATA)
3551 if (!accept || total_len >= (MHLEN - 2)) {
3553 MCLGET(m0, M_DONTWAIT);
3554 if ((m0->m_flags & M_EXT) == 0) {
3558 #if defined(TULIP_COPY_RXDATA)
3563 #if defined(TULIP_COPY_RXDATA)
3568 #if !defined(TULIP_COPY_RXDATA)
3569 ms->m_pkthdr.len = total_len;
3570 ms->m_pkthdr.rcvif = ifp;
3571 (*ifp->if_input)(ifp, ms);
3573 m0->m_data += 2; /* align data after header */
3574 m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
3575 m0->m_len = m0->m_pkthdr.len = total_len;
3576 m0->m_pkthdr.rcvif = ifp;
3577 (*ifp->if_input)(ifp, m0);
3579 #endif /* ! TULIP_COPY_RXDATA */
3586 * Couldn't allocate a new buffer. Don't bother
3587 * trying to replenish the receive queue.
3590 sc->tulip_flags |= TULIP_RXBUFSLOW;
3591 #if defined(TULIP_DEBUG)
3592 sc->tulip_dbg.dbg_rxlowbufs++;
3594 TULIP_PERFEND(rxget);
3598 * Now give the buffer(s) to the TULIP and save in our
3602 tulip_desc_t * const nextout = ri->ri_nextout;
3603 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3604 if (sc->tulip_rxmaps_free > 0) {
3605 map = sc->tulip_rxmaps[--sc->tulip_rxmaps_free];
3608 sc->tulip_flags |= TULIP_RXBUFSLOW;
3609 #if defined(TULIP_DEBUG)
3610 sc->tulip_dbg.dbg_rxlowbufs++;
3615 error = bus_dmamap_load(sc->tulip_dmatag, map, mtod(ms, void *),
3616 TULIP_RX_BUFLEN, NULL, BUS_DMA_NOWAIT);
3618 if_printf(sc->tulip_ifp,
3619 "unable to load rx map, error = %d\n", error);
3620 panic("tulip_rx_intr"); /* XXX */
3622 nextout->d_addr1 = map->dm_segs[0].ds_addr;
3623 nextout->d_length1 = map->dm_segs[0].ds_len;
3624 if (map->dm_nsegs == 2) {
3625 nextout->d_addr2 = map->dm_segs[1].ds_addr;
3626 nextout->d_length2 = map->dm_segs[1].ds_len;
3628 nextout->d_addr2 = 0;
3629 nextout->d_length2 = 0;
3631 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(*nextout));
3632 #else /* TULIP_BUS_DMA */
3633 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
3634 nextout->d_length1 = TULIP_RX_BUFLEN;
3635 #endif /* TULIP_BUS_DMA */
3636 nextout->d_status = TULIP_DSTS_OWNER;
3637 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
3638 if (++ri->ri_nextout == ri->ri_last)
3639 ri->ri_nextout = ri->ri_first;
3642 _IF_ENQUEUE(&sc->tulip_rxq, ms);
3643 } while ((ms = me) != NULL);
3645 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
3646 sc->tulip_flags &= ~TULIP_RXBUFSLOW;
3647 TULIP_PERFEND(rxget);
3650 #if defined(TULIP_DEBUG)
3651 sc->tulip_dbg.dbg_rxintrs++;
3652 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
3654 TULIP_PERFEND(rxintr);
3659 tulip_softc_t * const sc)
3661 TULIP_PERFSTART(txintr)
3662 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
3667 TULIP_LOCK_ASSERT(sc);
3668 while (ri->ri_free < ri->ri_max) {
3671 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
3672 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
3677 d_flag = ri->ri_nextin->d_flag;
3678 if (d_flag & TULIP_DFLAG_TxLASTSEG) {
3679 if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
3681 * We've just finished processing a setup packet.
3682 * Mark that we finished it. If there's not
3683 * another pending, startup the TULIP receiver.
3684 * Make sure we ack the RXSTOPPED so we won't get
3685 * an abormal interrupt indication.
3687 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap);
3688 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
3689 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT)
3690 sc->tulip_flags |= TULIP_HASHONLY;
3691 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
3693 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3694 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3695 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3696 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3697 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3700 const u_int32_t d_status = ri->ri_nextin->d_status;
3701 _IF_DEQUEUE(&sc->tulip_txq, m);
3703 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3704 bus_dmamap_t map = M_GETCTX(m, bus_dmamap_t);
3705 TULIP_TXMAP_POSTSYNC(sc, map);
3706 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
3707 #endif /* TULIP_BUS_DMA */
3709 #if defined(TULIP_DEBUG)
3711 if_printf(sc->tulip_ifp,
3712 "tx_intr: failed to dequeue mbuf?!?\n");
3715 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3716 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
3717 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
3718 #if defined(TULIP_DEBUG)
3719 if (d_status & TULIP_DSTS_TxNOCARR)
3720 sc->tulip_dbg.dbg_txprobe_nocarr++;
3721 if (d_status & TULIP_DSTS_TxEXCCOLL)
3722 sc->tulip_dbg.dbg_txprobe_exccoll++;
3724 event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
3726 (*sc->tulip_boardsw->bd_media_poll)(sc, event);
3728 * Escape from the loop before media poll has reset the TULIP!
3733 if (d_status & TULIP_DSTS_ERRSUM) {
3734 sc->tulip_ifp->if_oerrors++;
3735 if (d_status & TULIP_DSTS_TxEXCCOLL)
3736 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
3737 if (d_status & TULIP_DSTS_TxLATECOLL)
3738 sc->tulip_dot3stats.dot3StatsLateCollisions++;
3739 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
3740 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
3741 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
3742 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
3743 if (d_status & TULIP_DSTS_TxUNDERFLOW)
3744 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
3745 if (d_status & TULIP_DSTS_TxBABBLE)
3746 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
3748 u_int32_t collisions =
3749 (d_status & TULIP_DSTS_TxCOLLMASK)
3750 >> TULIP_DSTS_V_TxCOLLCNT;
3751 sc->tulip_ifp->if_collisions += collisions;
3752 if (collisions == 1)
3753 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
3754 else if (collisions > 1)
3755 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
3756 else if (d_status & TULIP_DSTS_TxDEFERRED)
3757 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
3759 * SQE is only valid for 10baseT/BNC/AUI when not
3760 * running in full-duplex. In order to speed up the
3761 * test, the corresponding bit in tulip_flags needs to
3762 * set as well to get us to count SQE Test Errors.
3764 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
3765 sc->tulip_dot3stats.dot3StatsSQETestErrors++;
3771 if (++ri->ri_nextin == ri->ri_last)
3772 ri->ri_nextin = ri->ri_first;
3774 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3775 sc->tulip_ifp->if_flags &= ~IFF_OACTIVE;
3778 * If nothing left to transmit, disable the timer.
3779 * Else if progress, reset the timer back to 2 ticks.
3781 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
3782 sc->tulip_txtimer = 0;
3784 sc->tulip_txtimer = TULIP_TXTIMER;
3785 sc->tulip_ifp->if_opackets += xmits;
3786 TULIP_PERFEND(txintr);
3791 tulip_print_abnormal_interrupt(
3792 tulip_softc_t * const sc,
3795 const char * const *msgp = tulip_status_bits;
3798 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
3800 TULIP_LOCK_ASSERT(sc);
3801 csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1;
3802 if_printf(sc->tulip_ifp, "abnormal interrupt:");
3803 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
3804 if ((csr & mask) && *msgp != NULL) {
3805 printf("%s%s", sep, *msgp);
3806 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
3807 sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
3808 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
3809 printf(" (switching to store-and-forward mode)");
3811 printf(" (raising TX threshold to %s)",
3812 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
3823 tulip_softc_t * const sc)
3825 TULIP_PERFSTART(intr)
3828 TULIP_LOCK_ASSERT(sc);
3829 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3830 TULIP_CSR_WRITE(sc, csr_status, csr);
3832 if (csr & TULIP_STS_SYSERROR) {
3833 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
3834 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3835 sc->tulip_flags |= TULIP_SYSTEMERROR;
3837 if_printf(sc->tulip_ifp, "system error: %s\n",
3838 tulip_system_errors[sc->tulip_last_system_error]);
3840 sc->tulip_flags |= TULIP_NEEDRESET;
3841 sc->tulip_system_errors++;
3844 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
3845 #if defined(TULIP_DEBUG)
3846 sc->tulip_dbg.dbg_link_intrs++;
3848 if (sc->tulip_boardsw->bd_media_poll != NULL) {
3849 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
3850 ? TULIP_MEDIAPOLL_LINKFAIL
3851 : TULIP_MEDIAPOLL_LINKPASS);
3852 csr &= ~TULIP_STS_ABNRMLINTR;
3854 tulip_media_print(sc);
3856 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
3857 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
3858 if (csr & TULIP_STS_RXNOBUF)
3859 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
3861 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3862 * on receive overflows.
3864 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
3865 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3867 * Stop the receiver process and spin until it's stopped.
3868 * Tell rx_intr to drop the packets it dequeues.
3870 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
3871 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
3873 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3874 sc->tulip_flags |= TULIP_RXIGNORE;
3877 if (sc->tulip_flags & TULIP_RXIGNORE) {
3879 * Restart the receiver.
3881 sc->tulip_flags &= ~TULIP_RXIGNORE;
3882 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3885 if (csr & TULIP_STS_ABNRMLINTR) {
3886 u_int32_t tmp = csr & sc->tulip_intrmask
3887 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
3888 if (csr & TULIP_STS_TXUNDERFLOW) {
3889 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
3890 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
3891 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3892 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
3893 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
3894 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3897 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3898 sc->tulip_statusbits |= tmp;
3900 tulip_print_abnormal_interrupt(sc, tmp);
3901 sc->tulip_flags |= TULIP_NOMESSAGES;
3903 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3905 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
3907 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3908 tulip_ifstart(sc->tulip_ifp);
3911 if (sc->tulip_flags & TULIP_NEEDRESET) {
3915 TULIP_PERFEND(intr);
3922 tulip_softc_t * sc = arg;
3924 for (; sc != NULL; sc = sc->tulip_slaves) {
3926 #if defined(TULIP_DEBUG)
3927 sc->tulip_dbg.dbg_intrs++;
3929 tulip_intr_handler(sc);
3938 tulip_softc_t * sc = (tulip_softc_t *) arg;
3941 #if defined(TULIP_DEBUG)
3942 sc->tulip_dbg.dbg_intrs++;
3944 tulip_intr_handler(sc);
3948 static struct mbuf *
3949 tulip_mbuf_compress(
3954 #if MCLBYTES >= ETHERMTU + 18
3955 MGETHDR(m0, M_DONTWAIT, MT_DATA);
3957 if (m->m_pkthdr.len > MHLEN) {
3958 MCLGET(m0, M_DONTWAIT);
3959 if ((m0->m_flags & M_EXT) == 0) {
3965 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t));
3966 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len;
3970 int len = m->m_pkthdr.len;
3971 struct mbuf **mp = &m0;
3974 if (mlen == MHLEN) {
3975 MGETHDR(*mp, M_DONTWAIT, MT_DATA);
3977 MGET(*mp, M_DONTWAIT, MT_DATA);
3985 MCLGET(*mp, M_DONTWAIT);
3986 if (((*mp)->m_flags & M_EXT) == 0) {
3991 (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES;
3993 (*mp)->m_len = len <= mlen ? len : mlen;
3995 m_copydata(m, m->m_pkthdr.len - len,
3996 (*mp)->m_len, mtod((*mp), caddr_t));
3997 len -= (*mp)->m_len;
3998 mp = &(*mp)->m_next;
4006 static struct mbuf *
4008 tulip_softc_t * const sc,
4011 TULIP_PERFSTART(txput)
4012 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
4013 tulip_desc_t *eop, *nextout;
4016 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
4023 TULIP_LOCK_ASSERT(sc);
4024 #if defined(TULIP_DEBUG)
4025 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
4026 if_printf(sc->tulip_ifp, "txput%s: tx not running\n",
4027 (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : "");
4028 sc->tulip_flags |= TULIP_WANTTXSTART;
4029 sc->tulip_dbg.dbg_txput_finishes[0]++;
4035 * Now we try to fill in our transmit descriptors. This is
4036 * a bit reminiscent of going on the Ark two by two
4037 * since each descriptor for the TULIP can describe
4038 * two buffers. So we advance through packet filling
4039 * each of the two entries at a time to to fill each
4040 * descriptor. Clear the first and last segment bits
4041 * in each descriptor (actually just clear everything
4042 * but the end-of-ring or chain bits) to make sure
4043 * we don't get messed up by previously sent packets.
4045 * We may fail to put the entire packet on the ring if
4046 * there is either not enough ring entries free or if the
4047 * packet has more than MAX_TXSEG segments. In the former
4048 * case we will just wait for the ring to empty. In the
4049 * latter case we have to recopy.
4051 #if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX)
4056 eop = nextout = ri->ri_nextout;
4060 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
4062 * Reclaim some dma maps from if we are out.
4064 if (sc->tulip_txmaps_free == 0) {
4065 #if defined(TULIP_DEBUG)
4066 sc->tulip_dbg.dbg_no_txmaps++;
4068 free += tulip_tx_intr(sc);
4070 if (sc->tulip_txmaps_free > 0) {
4071 map = sc->tulip_txmaps[sc->tulip_txmaps_free-1];
4073 sc->tulip_flags |= TULIP_WANTTXSTART;
4074 #if defined(TULIP_DEBUG)
4075 sc->tulip_dbg.dbg_txput_finishes[1]++;
4079 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT);
4081 if (error == EFBIG) {
4083 * The packet exceeds the number of transmit buffer
4084 * entries that we can use for one packet, so we have
4085 * to recopy it into one mbuf and then try again.
4087 m = tulip_mbuf_compress(m);
4089 #if defined(TULIP_DEBUG)
4090 sc->tulip_dbg.dbg_txput_finishes[2]++;
4094 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT);
4097 if_printf(sc->tulip_ifp,
4098 "unable to load tx map, error = %d\n", error);
4099 #if defined(TULIP_DEBUG)
4100 sc->tulip_dbg.dbg_txput_finishes[3]++;
4105 if ((free -= (map->dm_nsegs + 1) / 2) <= 0
4107 * See if there's any unclaimed space in the transmit ring.
4109 && (free += tulip_tx_intr(sc)) <= 0) {
4111 * There's no more room but since nothing
4112 * has been committed at this point, just
4113 * show output is active, put back the
4116 sc->tulip_flags |= TULIP_WANTTXSTART;
4117 #if defined(TULIP_DEBUG)
4118 sc->tulip_dbg.dbg_txput_finishes[4]++;
4120 bus_dmamap_unload(sc->tulip_dmatag, map);
4123 for (; map->dm_nsegs - segcnt > 1; segcnt += 2) {
4125 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4126 eop->d_status = d_status;
4127 eop->d_addr1 = map->dm_segs[segcnt].ds_addr;
4128 eop->d_length1 = map->dm_segs[segcnt].ds_len;
4129 eop->d_addr2 = map->dm_segs[segcnt+1].ds_addr;
4130 eop->d_length2 = map->dm_segs[segcnt+1].ds_len;
4131 d_status = TULIP_DSTS_OWNER;
4132 if (++nextout == ri->ri_last)
4133 nextout = ri->ri_first;
4135 if (segcnt < map->dm_nsegs) {
4137 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4138 eop->d_status = d_status;
4139 eop->d_addr1 = map->dm_segs[segcnt].ds_addr;
4140 eop->d_length1 = map->dm_segs[segcnt].ds_len;
4143 if (++nextout == ri->ri_last)
4144 nextout = ri->ri_first;
4146 TULIP_TXMAP_PRESYNC(sc, map);
4149 --sc->tulip_txmaps_free; /* commit to using the dmamap */
4151 #else /* !TULIP_BUS_DMA */
4154 int len = m0->m_len;
4155 caddr_t addr = mtod(m0, caddr_t);
4156 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1));
4159 unsigned slen = min(len, clsize);
4161 if (segcnt > TULIP_MAX_TXSEG) {
4163 * The packet exceeds the number of transmit buffer
4164 * entries that we can use for one packet, so we have
4165 * recopy it into one mbuf and then try again.
4167 m = tulip_mbuf_compress(m);
4175 * See if there's any unclaimed space in the
4178 if ((free += tulip_tx_intr(sc)) == 0) {
4180 * There's no more room but since nothing
4181 * has been committed at this point, just
4182 * show output is active, put back the
4185 sc->tulip_flags |= TULIP_WANTTXSTART;
4186 #if defined(TULIP_DEBUG)
4187 sc->tulip_dbg.dbg_txput_finishes[1]++;
4193 if (++nextout == ri->ri_last)
4194 nextout = ri->ri_first;
4195 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4196 eop->d_status = d_status;
4197 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr);
4198 eop->d_length1 = slen;
4201 * Fill in second half of descriptor
4203 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr);
4204 eop->d_length2 = slen;
4206 d_status = TULIP_DSTS_OWNER;
4211 } while ((m0 = m0->m_next) != NULL);
4212 #endif /* TULIP_BUS_DMA */
4215 * bounce a copy to the bpf listener, if any.
4217 BPF_MTAP(sc->tulip_ifp, m);
4220 * The descriptors have been filled in. Now get ready
4223 _IF_ENQUEUE(&sc->tulip_txq, m);
4227 * Make sure the next descriptor after this packet is owned
4228 * by us since it may have been set up above if we ran out
4229 * of room in the ring.
4231 nextout->d_status = 0;
4232 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
4234 #if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX)
4236 * If we only used the first segment of the last descriptor,
4237 * make sure the second segment will not be used.
4243 #endif /* TULIP_BUS_DMA */
4246 * Mark the last and first segments, indicate we want a transmit
4247 * complete interrupt, and tell it to transmit!
4249 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
4252 * Note that ri->ri_nextout is still the start of the packet
4253 * and until we set the OWNER bit, we can still back out of
4254 * everything we have done.
4256 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
4257 #if defined(TULIP_BUS_MAP) && !defined(TULIP_BUS_DMA_NOTX)
4258 if (eop < ri->ri_nextout) {
4259 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout,
4260 (caddr_t) ri->ri_last - (caddr_t) ri->ri_nextout);
4261 TULIP_TXDESC_PRESYNC(sc, ri->ri_first,
4262 (caddr_t) (eop + 1) - (caddr_t) ri->ri_first);
4264 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout,
4265 (caddr_t) (eop + 1) - (caddr_t) ri->ri_nextout);
4268 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
4269 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
4272 * This advances the ring for us.
4274 ri->ri_nextout = nextout;
4277 TULIP_PERFEND(txput);
4279 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
4280 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4281 sc->tulip_ifp->if_flags |= IFF_OACTIVE;
4282 TULIP_PERFEND(txput);
4287 * switch back to the single queueing ifstart.
4289 sc->tulip_flags &= ~TULIP_WANTTXSTART;
4290 if (sc->tulip_txtimer == 0)
4291 sc->tulip_txtimer = TULIP_TXTIMER;
4292 #if defined(TULIP_DEBUG)
4293 sc->tulip_dbg.dbg_txput_finishes[5]++;
4297 * If we want a txstart, there must be not enough space in the
4298 * transmit ring. So we want to enable transmit done interrupts
4299 * so we can immediately reclaim some space. When the transmit
4300 * interrupt is posted, the interrupt handler will call tx_intr
4301 * to reclaim space and then txstart (since WANTTXSTART is set).
4302 * txstart will move the packet into the transmit ring and clear
4303 * WANTTXSTART thereby causing TXINTR to be cleared.
4306 #if defined(TULIP_DEBUG)
4307 sc->tulip_dbg.dbg_txput_finishes[6]++;
4309 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
4310 sc->tulip_ifp->if_flags |= IFF_OACTIVE;
4311 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
4312 sc->tulip_intrmask |= TULIP_STS_TXINTR;
4313 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4315 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) {
4316 if (sc->tulip_intrmask & TULIP_STS_TXINTR) {
4317 sc->tulip_intrmask &= ~TULIP_STS_TXINTR;
4318 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4321 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4322 TULIP_PERFEND(txput);
4328 tulip_softc_t * const sc)
4330 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
4331 tulip_desc_t *nextout;
4333 TULIP_LOCK_ASSERT(sc);
4336 * We will transmit, at most, one setup packet per call to ifstart.
4339 #if defined(TULIP_DEBUG)
4340 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
4341 if_printf(sc->tulip_ifp, "txput_setup: tx not running\n");
4342 sc->tulip_flags |= TULIP_WANTTXSTART;
4347 * Try to reclaim some free descriptors..
4349 if (ri->ri_free < 2)
4351 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
4352 sc->tulip_flags |= TULIP_WANTTXSTART;
4355 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
4356 sizeof(sc->tulip_setupbuf));
4358 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is
4359 * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
4361 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP;
4363 nextout = ri->ri_nextout;
4364 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4365 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
4366 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
4367 if (sc->tulip_flags & TULIP_WANTHASHPERFECT)
4368 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
4369 else if (sc->tulip_flags & TULIP_WANTHASHONLY)
4370 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT;
4372 nextout->d_length2 = 0;
4373 nextout->d_addr2 = 0;
4374 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
4375 nextout->d_length1 = sc->tulip_setupmap->dm_segs[0].ds_len;
4376 nextout->d_addr1 = sc->tulip_setupmap->dm_segs[0].ds_addr;
4377 if (sc->tulip_setupmap->dm_nsegs == 2) {
4378 nextout->d_length2 = sc->tulip_setupmap->dm_segs[1].ds_len;
4379 nextout->d_addr2 = sc->tulip_setupmap->dm_segs[1].ds_addr;
4381 TULIP_TXMAP_PRESYNC(sc, sc->tulip_setupmap);
4382 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(*nextout));
4384 nextout->d_length1 = sizeof(sc->tulip_setupbuf);
4385 nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
4389 * Advance the ring for the next transmit packet.
4391 if (++ri->ri_nextout == ri->ri_last)
4392 ri->ri_nextout = ri->ri_first;
4395 * Make sure the next descriptor is owned by us since it
4396 * may have been set up above if we ran out of room in the
4399 ri->ri_nextout->d_status = 0;
4400 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
4401 nextout->d_status = TULIP_DSTS_OWNER;
4403 * Flush the ownwership of the current descriptor
4405 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
4406 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4407 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
4408 sc->tulip_intrmask |= TULIP_STS_TXINTR;
4409 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4420 TULIP_PERFSTART(ifioctl)
4421 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4422 struct ifreq *ifr = (struct ifreq *) data;
4426 case SIOCSIFFLAGS: {
4428 tulip_addr_filter(sc); /* reinit multicast filter */
4435 case SIOCGIFMEDIA: {
4436 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
4441 case SIOCDELMULTI: {
4443 * Update multicast listeners
4446 tulip_addr_filter(sc); /* reset multicast filtering */
4455 * Set the interface MTU.
4458 if (ifr->ifr_mtu > ETHERMTU) {
4462 ifp->if_mtu = ifr->ifr_mtu;
4467 case SIOCGADDRROM: {
4468 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
4474 ifr->ifr_metric = (int) sc->tulip_chipid;
4479 error = ether_ioctl(ifp, cmd, data);
4484 TULIP_PERFEND(ifioctl);
4490 struct ifnet * const ifp)
4492 TULIP_PERFSTART(ifstart)
4493 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4495 if (ifp->if_flags & IFF_RUNNING) {
4501 TULIP_PERFEND(ifstart);
4505 tulip_start(tulip_softc_t * const sc)
4509 TULIP_LOCK_ASSERT(sc);
4511 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
4512 tulip_txput_setup(sc);
4514 while (!IFQ_DRV_IS_EMPTY(&sc->tulip_ifp->if_snd)) {
4515 IFQ_DRV_DEQUEUE(&sc->tulip_ifp->if_snd, m);
4518 if ((m = tulip_txput(sc, m)) != NULL) {
4519 IFQ_DRV_PREPEND(&sc->tulip_ifp->if_snd, m);
4526 * Even though this routine runs at device spl, it does not break
4527 * our use of splnet (splsoftnet under NetBSD) for the majority
4528 * of this driver since
4529 * if_watcbog is called from if_watchdog which is called from
4530 * splsoftclock which is below spl[soft]net.
4536 TULIP_PERFSTART(ifwatchdog)
4537 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4538 #if defined(TULIP_DEBUG)
4543 #if defined(TULIP_DEBUG)
4544 rxintrs = sc->tulip_dbg.dbg_rxintrs - sc->tulip_dbg.dbg_last_rxintrs;
4545 if (rxintrs > sc->tulip_dbg.dbg_high_rxintrs_hz)
4546 sc->tulip_dbg.dbg_high_rxintrs_hz = rxintrs;
4547 sc->tulip_dbg.dbg_last_rxintrs = sc->tulip_dbg.dbg_rxintrs;
4548 #endif /* TULIP_DEBUG */
4550 sc->tulip_ifp->if_timer = 1;
4552 * These should be rare so do a bulk test up front so we can just skip
4555 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) {
4557 * If the number of receive buffer is low, try to refill
4559 if (sc->tulip_flags & TULIP_RXBUFSLOW)
4562 if (sc->tulip_flags & TULIP_SYSTEMERROR) {
4563 if_printf(sc->tulip_ifp, "%d system errors: last was %s\n",
4564 sc->tulip_system_errors,
4565 tulip_system_errors[sc->tulip_last_system_error]);
4567 if (sc->tulip_statusbits) {
4568 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
4569 sc->tulip_statusbits = 0;
4572 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR);
4575 if (sc->tulip_txtimer)
4577 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
4578 if_printf(sc->tulip_ifp, "transmission timeout\n");
4579 if (TULIP_DO_AUTOSENSE(sc)) {
4580 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
4581 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
4582 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP);
4588 TULIP_PERFEND(ifwatchdog);
4589 TULIP_PERFMERGE(sc, perf_intr_cycles);
4590 TULIP_PERFMERGE(sc, perf_ifstart_cycles);
4591 TULIP_PERFMERGE(sc, perf_ifioctl_cycles);
4592 TULIP_PERFMERGE(sc, perf_ifwatchdog_cycles);
4593 TULIP_PERFMERGE(sc, perf_timeout_cycles);
4594 TULIP_PERFMERGE(sc, perf_ifstart_one_cycles);
4595 TULIP_PERFMERGE(sc, perf_txput_cycles);
4596 TULIP_PERFMERGE(sc, perf_txintr_cycles);
4597 TULIP_PERFMERGE(sc, perf_rxintr_cycles);
4598 TULIP_PERFMERGE(sc, perf_rxget_cycles);
4599 TULIP_PERFMERGE(sc, perf_intr);
4600 TULIP_PERFMERGE(sc, perf_ifstart);
4601 TULIP_PERFMERGE(sc, perf_ifioctl);
4602 TULIP_PERFMERGE(sc, perf_ifwatchdog);
4603 TULIP_PERFMERGE(sc, perf_timeout);
4604 TULIP_PERFMERGE(sc, perf_ifstart_one);
4605 TULIP_PERFMERGE(sc, perf_txput);
4606 TULIP_PERFMERGE(sc, perf_txintr);
4607 TULIP_PERFMERGE(sc, perf_rxintr);
4608 TULIP_PERFMERGE(sc, perf_rxget);
4613 * All printf's are real as of now!
4621 tulip_softc_t * const sc)
4625 ifp = sc->tulip_ifp = if_alloc(IFT_ETHER);
4627 /* XXX: driver name/unit should be set some other way */
4628 if_initname(ifp, "de", sc->tulip_unit);
4630 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
4631 ifp->if_ioctl = tulip_ifioctl;
4632 ifp->if_start = tulip_ifstart;
4633 ifp->if_watchdog = tulip_ifwatchdog;
4635 ifp->if_init = tulip_ifinit;
4636 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
4637 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
4638 IFQ_SET_READY(&ifp->if_snd);
4640 if_printf(ifp, "%s%s pass %d.%d%s\n",
4642 tulip_chipdescs[sc->tulip_chipid],
4643 (sc->tulip_revinfo & 0xF0) >> 4,
4644 sc->tulip_revinfo & 0x0F,
4645 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM))
4646 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "");
4649 #if defined(__alpha__)
4651 * In case the SRM console told us about a bogus media,
4652 * we need to check to be safe.
4654 if (sc->tulip_mediums[sc->tulip_media] == NULL)
4655 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
4658 (*sc->tulip_boardsw->bd_media_probe)(sc);
4659 ifmedia_init(&sc->tulip_ifmedia, 0,
4660 tulip_ifmedia_change,
4661 tulip_ifmedia_status);
4662 sc->tulip_flags &= ~TULIP_DEVICEPROBE;
4663 tulip_ifmedia_add(sc);
4668 ether_ifattach(sc->tulip_ifp, sc->tulip_enaddr);
4671 #if defined(TULIP_BUS_DMA)
4672 #if !defined(TULIP_BUS_DMA_NOTX) || !defined(TULIP_BUS_DMA_NORX)
4674 tulip_busdma_allocmem(
4675 tulip_softc_t * const sc,
4677 bus_dmamap_t *map_p,
4678 tulip_desc_t **desc_p)
4680 bus_dma_segment_t segs[1];
4682 error = bus_dmamem_alloc(sc->tulip_dmatag, size, 1, PAGE_SIZE,
4683 segs, sizeof(segs)/sizeof(segs[0]),
4684 &nsegs, BUS_DMA_NOWAIT);
4687 error = bus_dmamem_map(sc->tulip_dmatag, segs, nsegs, size,
4688 (void *) &desc, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
4691 error = bus_dmamap_create(sc->tulip_dmatag, size, 1, size, 0,
4692 BUS_DMA_NOWAIT, &map);
4694 error = bus_dmamap_load(sc->tulip_dmatag, map, desc,
4695 size, NULL, BUS_DMA_NOWAIT);
4697 bus_dmamap_destroy(sc->tulip_dmatag, map);
4702 bus_dmamem_unmap(sc->tulip_dmatag, desc, size);
4705 bus_dmamem_free(sc->tulip_dmatag, segs, nsegs);
4715 tulip_softc_t * const sc)
4719 #if !defined(TULIP_BUS_DMA_NOTX)
4721 * Allocate dmamap for setup descriptor
4723 error = bus_dmamap_create(sc->tulip_dmatag, sizeof(sc->tulip_setupbuf), 2,
4724 sizeof(sc->tulip_setupbuf), 0, BUS_DMA_NOWAIT,
4725 &sc->tulip_setupmap);
4727 error = bus_dmamap_load(sc->tulip_dmatag, sc->tulip_setupmap,
4728 sc->tulip_setupbuf, sizeof(sc->tulip_setupbuf),
4729 NULL, BUS_DMA_NOWAIT);
4731 bus_dmamap_destroy(sc->tulip_dmatag, sc->tulip_setupmap);
4734 * Allocate space and dmamap for transmit ring
4737 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_TXDESCS,
4738 &sc->tulip_txdescmap,
4739 &sc->tulip_txdescs);
4743 * Allocate dmamaps for each transmit descriptors
4746 while (error == 0 && sc->tulip_txmaps_free < TULIP_TXDESCS) {
4748 if ((error = TULIP_TXMAP_CREATE(sc, &map)) == 0)
4749 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
4752 while (sc->tulip_txmaps_free > 0)
4753 bus_dmamap_destroy(sc->tulip_dmatag,
4754 sc->tulip_txmaps[--sc->tulip_txmaps_free]);
4759 sc->tulip_txdescs = (tulip_desc_t *) malloc(TULIP_TXDESCS * sizeof(tulip_desc_t), M_DEVBUF, M_NOWAIT);
4760 if (sc->tulip_txdescs == NULL)
4764 #if !defined(TULIP_BUS_DMA_NORX)
4766 * Allocate space and dmamap for receive ring
4769 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_RXDESCS,
4770 &sc->tulip_rxdescmap,
4771 &sc->tulip_rxdescs);
4775 * Allocate dmamaps for each receive descriptors
4778 while (error == 0 && sc->tulip_rxmaps_free < TULIP_RXDESCS) {
4780 if ((error = TULIP_RXMAP_CREATE(sc, &map)) == 0)
4781 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
4784 while (sc->tulip_rxmaps_free > 0)
4785 bus_dmamap_destroy(sc->tulip_dmatag,
4786 sc->tulip_rxmaps[--sc->tulip_rxmaps_free]);
4791 sc->tulip_rxdescs = (tulip_desc_t *) malloc(TULIP_RXDESCS * sizeof(tulip_desc_t), M_DEVBUF, M_NOWAIT);
4792 if (sc->tulip_rxdescs == NULL)
4798 #endif /* TULIP_BUS_DMA */
4802 tulip_softc_t * const sc,
4803 tulip_csrptr_t csr_base,
4806 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
4807 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
4808 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
4809 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
4810 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
4811 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
4812 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
4813 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
4814 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size;
4815 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size;
4816 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size;
4817 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size;
4818 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size;
4819 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size;
4820 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
4821 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
4826 tulip_softc_t * const sc,
4827 tulip_ringinfo_t * const ri,
4828 tulip_desc_t *descs,
4831 ri->ri_max = ndescs;
4832 ri->ri_first = descs;
4833 ri->ri_last = ri->ri_first + ri->ri_max;
4834 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
4835 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
4839 * This is the PCI configuration support.
4842 #define PCI_CBIO PCIR_BAR(0) /* Configuration Base IO Address */
4843 #define PCI_CBMA PCIR_BAR(1) /* Configuration Base Memory Address */
4844 #define PCI_CFDA 0x40 /* Configuration Driver Area */
4847 tulip_pci_probe(device_t dev)
4849 const char *name = NULL;
4851 if (pci_get_vendor(dev) != DEC_VENDORID)
4855 * Some LanMedia WAN cards use the Tulip chip, but they have
4856 * their own driver, and we should not recognize them
4858 if (pci_get_subvendor(dev) == 0x1376)
4861 switch (pci_get_device(dev)) {
4863 name = "Digital 21040 Ethernet";
4866 name = "Digital 21041 Ethernet";
4869 if (pci_get_revid(dev) >= 0x20)
4870 name = "Digital 21140A Fast Ethernet";
4872 name = "Digital 21140 Fast Ethernet";
4875 if (pci_get_revid(dev) >= 0x20)
4876 name = "Digital 21143 Fast Ethernet";
4878 name = "Digital 21142 Fast Ethernet";
4882 device_set_desc(dev, name);
4883 return BUS_PROBE_LOW_PRIORITY;
4889 tulip_shutdown(device_t dev)
4891 tulip_softc_t * const sc = device_get_softc(dev);
4892 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4893 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
4894 33MHz that comes to two microseconds but wait a
4895 bit longer anyways) */
4900 tulip_pci_attach(device_t dev)
4903 #if defined(__alpha__)
4904 tulip_media_t media = TULIP_MEDIA_UNKNOWN;
4907 u_int32_t revinfo, cfdainfo;
4908 unsigned csroffset = TULIP_PCI_CSROFFSET;
4909 unsigned csrsize = TULIP_PCI_CSRSIZE;
4910 tulip_csrptr_t csr_base;
4911 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
4912 struct resource *res;
4915 unit = device_get_unit(dev);
4917 if (unit >= TULIP_MAX_DEVICES) {
4918 device_printf(dev, "not configured; limit of %d reached or exceeded\n",
4923 revinfo = pci_get_revid(dev);
4924 cfdainfo = pci_read_config(dev, PCI_CFDA, 4);
4926 /* turn busmaster on in case BIOS doesn't set it */
4927 pci_enable_busmaster(dev);
4929 if (pci_get_vendor(dev) == DEC_VENDORID) {
4930 if (pci_get_device(dev) == CHIPID_21040)
4931 chipid = TULIP_21040;
4932 else if (pci_get_device(dev) == CHIPID_21041)
4933 chipid = TULIP_21041;
4934 else if (pci_get_device(dev) == CHIPID_21140)
4935 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140;
4936 else if (pci_get_device(dev) == CHIPID_21142)
4937 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142;
4939 if (chipid == TULIP_CHIPID_UNKNOWN)
4942 if (chipid == TULIP_21040 && revinfo < 0x20) {
4944 "not configured; 21040 pass 2.0 required (%d.%d found)\n",
4945 revinfo >> 4, revinfo & 0x0f);
4947 } else if (chipid == TULIP_21140 && revinfo < 0x11) {
4949 "not configured; 21140 pass 1.1 required (%d.%d found)\n",
4950 revinfo >> 4, revinfo & 0x0f);
4954 sc = device_get_softc(dev);
4955 sc->tulip_pci_busno = pci_get_bus(dev);
4956 sc->tulip_pci_devno = pci_get_slot(dev);
4957 sc->tulip_chipid = chipid;
4958 sc->tulip_flags |= TULIP_DEVICEPROBE;
4959 if (chipid == TULIP_21140 || chipid == TULIP_21140A)
4960 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD;
4961 if (chipid == TULIP_21140A && revinfo <= 0x22)
4962 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW;
4963 if (chipid == TULIP_21140)
4964 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH;
4965 if (chipid != TULIP_21040 && chipid != TULIP_21140)
4966 sc->tulip_features |= TULIP_HAVE_POWERMGMT;
4967 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) {
4968 sc->tulip_features |= TULIP_HAVE_DUALSENSE;
4969 if (chipid != TULIP_21041 || revinfo >= 0x20)
4970 sc->tulip_features |= TULIP_HAVE_SIANWAY;
4971 if (chipid != TULIP_21041)
4972 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD;
4973 if (chipid != TULIP_21041 && revinfo >= 0x20)
4974 sc->tulip_features |= TULIP_HAVE_SIA100;
4977 if (sc->tulip_features & TULIP_HAVE_POWERMGMT
4978 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) {
4979 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE);
4980 pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
4983 #if defined(__alpha__)
4985 * The Alpha SRM console encodes a console set media in the driver
4986 * part of the CFDA register. Note that the Multia presents a
4987 * problem in that its BNC mode is really EXTSIA. So in that case
4990 switch ((cfdainfo >> 8) & 0xff) {
4991 case 1: media = chipid > TULIP_21040 ? TULIP_MEDIA_AUI : TULIP_MEDIA_AUIBNC; break;
4992 case 2: media = chipid > TULIP_21040 ? TULIP_MEDIA_BNC : TULIP_MEDIA_UNKNOWN; break;
4993 case 3: media = TULIP_MEDIA_10BASET; break;
4994 case 4: media = TULIP_MEDIA_10BASET_FD; break;
4995 case 5: media = TULIP_MEDIA_100BASETX; break;
4996 case 6: media = TULIP_MEDIA_100BASETX_FD; break;
4997 default: media = TULIP_MEDIA_UNKNOWN; break;
5001 sc->tulip_unit = unit;
5002 sc->tulip_revinfo = revinfo;
5003 #if defined(TULIP_IOMAPPED)
5005 res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
5008 res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
5012 sc->tulip_csrs_bst = rman_get_bustag(res);
5013 sc->tulip_csrs_bsh = rman_get_bushandle(res);
5016 mtx_init(TULIP_MUTEX(sc), MTX_NETWORK_LOCK, device_get_nameunit(dev),
5018 callout_init(&sc->tulip_callout, CALLOUT_MPSAFE);
5021 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
5023 #if defined(TULIP_BUS_DMA)
5024 if ((retval = tulip_busdma_init(sc)) != 0) {
5025 printf("error initing bus_dma: %d\n", retval);
5026 mtx_destroy(TULIP_MUTEX(sc));
5030 sc->tulip_rxdescs = (tulip_desc_t *) malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS, M_DEVBUF, M_NOWAIT);
5031 sc->tulip_txdescs = (tulip_desc_t *) malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS, M_DEVBUF, M_NOWAIT);
5032 if (sc->tulip_rxdescs == NULL || sc->tulip_txdescs == NULL) {
5033 device_printf(dev, "malloc failed\n");
5034 if (sc->tulip_rxdescs)
5035 free((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
5036 if (sc->tulip_txdescs)
5037 free((caddr_t) sc->tulip_txdescs, M_DEVBUF);
5038 mtx_destroy(TULIP_MUTEX(sc));
5043 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS);
5044 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS);
5047 * Make sure there won't be any interrupts or such...
5049 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
5050 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
5051 33MHz that comes to two microseconds but wait a
5052 bit longer anyways) */
5055 retval = tulip_read_macaddr(sc);
5058 device_printf(dev, "can't read ENET ROM (why=%d) (", retval);
5059 for (idx = 0; idx < 32; idx++)
5060 printf("%02x", sc->tulip_rombuf[idx]);
5062 device_printf(dev, "%s%s pass %d.%d\n",
5063 sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
5064 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
5065 device_printf(dev, "address unknown\n");
5067 void (*intr_rtn)(void *) = tulip_intr_normal;
5069 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
5070 intr_rtn = tulip_intr_shared;
5072 #if defined(__alpha__)
5073 sc->tulip_media = media;
5077 /* Setup interrupt last. */
5078 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) {
5082 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
5083 RF_SHAREABLE | RF_ACTIVE);
5084 if (res == 0 || bus_setup_intr(dev, res, INTR_TYPE_NET |
5085 INTR_MPSAFE, intr_rtn, sc, &ih)) {
5086 device_printf(dev, "couldn't map interrupt\n");
5087 free((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
5088 free((caddr_t) sc->tulip_txdescs, M_DEVBUF);
5089 ether_ifdetach(sc->tulip_ifp);
5090 if_free(sc->tulip_ifp);
5091 mtx_destroy(TULIP_MUTEX(sc));
5096 #if defined(__alpha__)
5098 if (sc->tulip_media != TULIP_MEDIA_UNKNOWN)
5099 tulip_linkup(sc, media);
5106 static device_method_t tulip_pci_methods[] = {
5107 /* Device interface */
5108 DEVMETHOD(device_probe, tulip_pci_probe),
5109 DEVMETHOD(device_attach, tulip_pci_attach),
5110 DEVMETHOD(device_shutdown, tulip_shutdown),
5113 static driver_t tulip_pci_driver = {
5116 sizeof(tulip_softc_t),
5118 static devclass_t tulip_devclass;
5119 DRIVER_MODULE(de, pci, tulip_pci_driver, tulip_devclass, 0, 0);