1 /* $NetBSD: if_de.c,v 1.86 1999/06/01 19:17:59 thorpej Exp $ */
3 /* $FreeBSD: src/sys/pci/if_de.c,v 1.123.2.4 2000/08/04 23:25:09 peter Exp $ */
6 * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com)
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Id: if_de.c,v 1.94 1997/07/03 16:55:07 thomas Exp
33 * DEC 21040 PCI Ethernet Controller
35 * Written by Matt Thomas
36 * BPF support code stolen directly from if_ec.c
38 * This driver supports the DEC DE435 or any other PCI
39 * board which support 21040, 21041, or 21140 (mostly).
42 #include <sys/param.h>
43 #include <sys/systm.h>
45 #include <sys/socket.h>
46 #include <sys/sockio.h>
47 #include <sys/malloc.h>
48 #include <sys/kernel.h>
49 #include <sys/eventhandler.h>
52 #include <sys/thread2.h>
53 #include <sys/interrupt.h>
58 #include <net/if_media.h>
59 #include <net/if_dl.h>
60 #include <net/ifq_var.h>
64 #include <netinet/in.h>
65 #include <netinet/if_ether.h>
70 #include <net/if_var.h>
72 #include <bus/pci/pcivar.h>
73 #include <bus/pci/pcireg.h>
74 #include <dev/netif/de/dc21040reg.h>
77 * Intel CPUs should use I/O mapped access.
80 #define TULIP_IOMAPPED
87 static tulip_softc_t *tulips[TULIP_MAX_DEVICES];
90 * This module supports
91 * the DEC 21040 PCI Ethernet Controller.
92 * the DEC 21041 PCI Ethernet Controller.
93 * the DEC 21140 PCI Fast Ethernet Controller.
95 static void tulip_mii_autonegotiate(tulip_softc_t *, u_int);
96 static void tulip_intr_shared(void *);
97 static void tulip_intr_normal(void *);
98 static void tulip_init(tulip_softc_t *);
99 static void tulip_reset(tulip_softc_t *);
100 static void tulip_ifstart(struct ifnet *, struct ifaltq_subque *);
101 static struct mbuf *tulip_txput(tulip_softc_t *, struct mbuf *);
102 static void tulip_txput_setup(tulip_softc_t *);
103 static void tulip_rx_intr(tulip_softc_t *);
104 static void tulip_addr_filter(tulip_softc_t *);
105 static u_int tulip_mii_readreg(tulip_softc_t *, u_int, u_int);
106 static void tulip_mii_writereg(tulip_softc_t *, u_int, u_int, u_int);
107 static int tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities);
108 static tulip_media_t tulip_mii_phy_readspecific(tulip_softc_t *);
109 static int tulip_srom_decode(tulip_softc_t *);
110 static int tulip_ifmedia_change(struct ifnet *);
111 static void tulip_ifmedia_status(struct ifnet *, struct ifmediareq *);
112 /* static void tulip_21140_map_media(tulip_softc_t *sc); */
115 tulip_timeout_callback(void *arg)
117 tulip_softc_t *sc = arg;
119 lwkt_serialize_enter(sc->tulip_if.if_serializer);
120 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING;
121 sc->tulip_probe_timeout -= 1000 / TULIP_HZ;
122 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER);
123 lwkt_serialize_exit(sc->tulip_if.if_serializer);
127 tulip_timeout(tulip_softc_t *sc)
129 if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
131 sc->tulip_flags |= TULIP_TIMEOUTPENDING;
132 callout_reset(&sc->tulip_timer, (hz + TULIP_HZ / 2) / TULIP_HZ,
133 tulip_timeout_callback, sc);
137 tulip_txprobe(tulip_softc_t *sc)
142 * Before we are sure this is the right media we need
143 * to send a small packet to make sure there's carrier.
144 * Strangely, BNC and AUI will "see" receive data if
145 * either is connected so the transmit is the only way
146 * to verify the connectivity.
148 MGETHDR(m, MB_DONTWAIT, MT_DATA);
152 * Construct a LLC TEST message which will point to ourselves.
154 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_dhost, 6);
155 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_shost, 6);
156 mtod(m, struct ether_header *)->ether_type = htons(3);
157 mtod(m, unsigned char *)[14] = 0;
158 mtod(m, unsigned char *)[15] = 0;
159 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
160 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
164 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
165 sc->tulip_intrmask |= TULIP_STS_TXINTR;
166 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
167 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
168 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
169 if ((m = tulip_txput(sc, m)) != NULL)
171 sc->tulip_probe.probe_txprobes++;
176 #define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0)
178 #define TULIP_SIAGEN_WATCHDOG 0
182 tulip_media_set(tulip_softc_t *sc, tulip_media_t media)
184 const tulip_media_info_t *mi = sc->tulip_mediums[media];
190 * If we are switching media, make sure we don't think there's
191 * any stale RX activity
193 sc->tulip_flags &= ~TULIP_RXACT;
194 if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
195 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
196 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx);
197 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
198 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
200 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
202 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
204 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity);
205 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
206 #define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL)
208 * If the cmdmode bits don't match the currently operating mode,
209 * set the cmdmode appropriately and reset the chip.
211 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
212 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
213 sc->tulip_cmdmode |= mi->mi_cmdmode;
216 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
218 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata);
219 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
221 * If the cmdmode bits don't match the currently operating mode,
222 * set the cmdmode appropriately and reset the chip.
224 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
225 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
226 sc->tulip_cmdmode |= mi->mi_cmdmode;
229 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol);
230 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata);
231 } else if (mi->mi_type == TULIP_MEDIAINFO_MII
232 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) {
234 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
236 dp = &sc->tulip_rombuf[mi->mi_reset_offset];
237 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) {
239 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
241 sc->tulip_phyaddr = mi->mi_phyaddr;
242 dp = &sc->tulip_rombuf[mi->mi_gpr_offset];
243 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) {
245 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
248 for (idx = 0; idx < mi->mi_reset_length; idx++) {
250 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]);
252 sc->tulip_phyaddr = mi->mi_phyaddr;
253 for (idx = 0; idx < mi->mi_gpr_length; idx++) {
255 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]);
258 if (sc->tulip_flags & TULIP_TRYNWAY) {
259 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
260 } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
261 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL);
262 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE);
263 sc->tulip_flags &= ~TULIP_DIDNWAY;
264 if (TULIP_IS_MEDIA_FD(media))
265 data |= PHYCTL_FULL_DUPLEX;
266 if (TULIP_IS_MEDIA_100MB(media))
267 data |= PHYCTL_SELECT_100MB;
268 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data);
274 tulip_linkup(tulip_softc_t *sc, tulip_media_t media)
276 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
277 sc->tulip_flags |= TULIP_PRINTLINKUP;
278 sc->tulip_flags |= TULIP_LINKUP;
279 ifq_clr_oactive(&sc->tulip_if.if_snd);
280 #if 0 /* XXX how does with work with ifmedia? */
281 if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
282 if (sc->tulip_if.if_flags & IFF_FULLDUPLEX) {
283 if (TULIP_CAN_MEDIA_FD(media)
284 && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL)
285 media = TULIP_FD_MEDIA_OF(media);
287 if (TULIP_IS_MEDIA_FD(media)
288 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL)
289 media = TULIP_HD_MEDIA_OF(media);
293 if (sc->tulip_media != media) {
294 sc->tulip_media = media;
295 sc->tulip_flags |= TULIP_PRINTMEDIA;
296 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) {
297 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
298 } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) {
299 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
303 * We could set probe_timeout to 0 but setting to 3000 puts this
304 * in one central place and the only matters is tulip_link is
305 * followed by a tulip_timeout. Therefore setting it should not
306 * result in aberrant behavour.
308 sc->tulip_probe_timeout = 3000;
309 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
310 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY);
311 if (sc->tulip_flags & TULIP_INRESET) {
312 tulip_media_set(sc, sc->tulip_media);
313 } else if (sc->tulip_probe_media != sc->tulip_media) {
315 * No reason to change media if we have the right media.
323 tulip_media_print(tulip_softc_t *sc)
325 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
327 if (sc->tulip_flags & TULIP_PRINTMEDIA) {
328 if_printf(&sc->tulip_if, "enabling %s port\n",
329 tulip_mediums[sc->tulip_media]);
330 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
331 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
332 if_printf(&sc->tulip_if, "link up\n");
333 sc->tulip_flags &= ~TULIP_PRINTLINKUP;
337 #if defined(TULIP_DO_GPR_SENSE)
339 tulip_21140_gpr_media_sense(tulip_softc_t *sc)
341 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
342 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
346 * If one of the media blocks contained a default media flag,
349 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
350 const tulip_media_info_t *mi;
352 * Media is not supported (or is full-duplex).
354 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media))
356 if (mi->mi_type != TULIP_MEDIAINFO_GPR)
360 * Remember the media is this is the "default" media.
362 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
366 * No activity mask? Can't see if it is active if there's no mask.
368 if (mi->mi_actmask == 0)
372 * Does the activity data match?
374 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
378 * It does! If this is the first media we detected, then
379 * remember this media. If isn't the first, then there were
380 * multiple matches which we equate to no match (since we don't
381 * which to select (if any).
383 if (last_media == TULIP_MEDIA_UNKNOWN) {
385 } else if (last_media != media) {
386 last_media = TULIP_MEDIA_UNKNOWN;
389 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
391 #endif /* TULIP_DO_GPR_SENSE */
393 static tulip_link_status_t
394 tulip_media_link_monitor(tulip_softc_t *sc)
396 const tulip_media_info_t *mi = sc->tulip_mediums[sc->tulip_media];
397 tulip_link_status_t linkup = TULIP_LINK_DOWN;
400 #if defined(DIAGNOSTIC)
401 panic("tulip_media_link_monitor: %s: botch at line %d",
402 tulip_mediums[sc->tulip_media],__LINE__);
404 return TULIP_LINK_UNKNOWN;
409 * Have we seen some packets? If so, the link must be good.
411 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) {
412 sc->tulip_flags &= ~TULIP_RXACT;
413 sc->tulip_probe_timeout = 3000;
414 return TULIP_LINK_UP;
417 sc->tulip_flags &= ~TULIP_RXACT;
418 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
421 * Read the PHY status register.
423 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
424 if (status & PHYSTS_AUTONEG_DONE) {
426 * If the PHY has completed autonegotiation, see the if the
427 * remote systems abilities have changed. If so, upgrade or
428 * downgrade as appropriate.
430 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
431 abilities = (abilities << 6) & status;
432 if (abilities != sc->tulip_abilities) {
433 if (tulip_mii_map_abilities(sc, abilities)) {
434 tulip_linkup(sc, sc->tulip_probe_media);
435 return TULIP_LINK_UP;
438 * if we had selected media because of autonegotiation,
439 * we need to probe for the new media.
441 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
442 if (sc->tulip_flags & TULIP_DIDNWAY)
443 return TULIP_LINK_DOWN;
447 * The link is now up. If was down, say its back up.
449 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP)
450 linkup = TULIP_LINK_UP;
451 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
453 * No activity sensor? Assume all's well.
455 if (mi->mi_actmask == 0)
456 return TULIP_LINK_UNKNOWN;
458 * Does the activity data match?
460 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata)
461 linkup = TULIP_LINK_UP;
462 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
464 * Assume non TP ok for now.
466 if (!TULIP_IS_MEDIA_TP(sc->tulip_media))
467 return TULIP_LINK_UNKNOWN;
468 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
469 linkup = TULIP_LINK_UP;
470 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
471 return TULIP_LINK_UNKNOWN;
474 * We will wait for 3 seconds until the link goes into suspect mode.
476 if (sc->tulip_flags & TULIP_LINKUP) {
477 if (linkup == TULIP_LINK_UP)
478 sc->tulip_probe_timeout = 3000;
479 if (sc->tulip_probe_timeout > 0)
480 return TULIP_LINK_UP;
482 sc->tulip_flags &= ~TULIP_LINKUP;
483 if_printf(&sc->tulip_if, "link down: cable problem?\n");
485 return TULIP_LINK_DOWN;
489 tulip_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
491 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
492 && event == TULIP_MEDIAPOLL_TIMER) {
493 switch (tulip_media_link_monitor(sc)) {
494 case TULIP_LINK_DOWN: {
496 * Link Monitor failed. Probe for new media.
498 event = TULIP_MEDIAPOLL_LINKFAIL;
501 case TULIP_LINK_UP: {
508 case TULIP_LINK_UNKNOWN: {
510 * We can't tell so don't bother.
517 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
518 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
519 if (TULIP_DO_AUTOSENSE(sc)) {
520 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
521 if (sc->tulip_if.if_flags & IFF_UP)
522 tulip_reset(sc); /* restart probe */
528 if (event == TULIP_MEDIAPOLL_START) {
529 ifq_set_oactive(&sc->tulip_if.if_snd);
530 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
532 sc->tulip_probe_mediamask = 0;
533 sc->tulip_probe_passes = 0;
535 * If the SROM contained an explicit media to use, use it.
537 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX);
538 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS;
539 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
541 * connidx is defaulted to a media_unknown type.
543 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media;
544 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) {
545 tulip_linkup(sc, sc->tulip_probe_media);
550 if (sc->tulip_features & TULIP_HAVE_GPR) {
551 sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
552 sc->tulip_probe_timeout = 2000;
554 sc->tulip_probe_media = TULIP_MEDIA_MAX;
555 sc->tulip_probe_timeout = 0;
556 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
561 * Ignore txprobe failures or spurious callbacks.
563 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED
564 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) {
565 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
570 * If we really transmitted a packet, then that's the media we'll use.
572 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) {
573 if (event == TULIP_MEDIAPOLL_LINKPASS) {
574 /* XXX Check media status just to be sure */
575 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
577 tulip_linkup(sc, sc->tulip_probe_media);
582 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) {
583 #if defined(TULIP_DO_GPR_SENSE)
585 * Check for media via the general purpose register.
587 * Try to sense the media via the GPR. If the same value
588 * occurs 3 times in a row then just use that.
590 if (sc->tulip_probe_timeout > 0) {
591 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
592 if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
593 if (new_probe_media == sc->tulip_probe_media) {
594 if (--sc->tulip_probe_count == 0)
595 tulip_linkup(sc, sc->tulip_probe_media);
597 sc->tulip_probe_count = 10;
600 sc->tulip_probe_media = new_probe_media;
604 #endif /* TULIP_DO_GPR_SENSE */
606 * Brute force. We cycle through each of the media types
607 * and try to transmit a packet.
609 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
610 sc->tulip_probe_media = TULIP_MEDIA_MAX;
611 sc->tulip_probe_timeout = 0;
616 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST
617 && (sc->tulip_features & TULIP_HAVE_MII)) {
618 tulip_media_t old_media = sc->tulip_probe_media;
619 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
620 switch (sc->tulip_probe_state) {
621 case TULIP_PROBE_FAILED:
622 case TULIP_PROBE_MEDIATEST: {
624 * Try the next media.
626 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask;
627 sc->tulip_probe_timeout = 0;
629 if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
631 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
633 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
637 case TULIP_PROBE_PHYAUTONEG: {
640 case TULIP_PROBE_INACTIVE: {
642 * Only probe if we autonegotiated a media that hasn't failed.
644 sc->tulip_probe_timeout = 0;
645 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) {
646 sc->tulip_probe_media = old_media;
649 tulip_linkup(sc, sc->tulip_probe_media);
654 #if defined(DIAGNOSTIC)
655 panic("tulip_media_poll: botch at line %d", __LINE__);
662 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
663 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
668 * switch to another media if we tried this one enough.
670 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
672 * Find the next media type to check for. Full Duplex
673 * types are not allowed.
676 sc->tulip_probe_media -= 1;
677 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
678 if (++sc->tulip_probe_passes == 3) {
679 if_printf(&sc->tulip_if, "autosense failed: cable problem?\n");
680 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
681 sc->tulip_if.if_flags &= ~IFF_RUNNING;
682 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
686 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */
687 sc->tulip_probe_mediamask = 0;
688 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1;
690 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL
691 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
692 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
694 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
695 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
696 sc->tulip_probe.probe_txprobes = 0;
698 tulip_media_set(sc, sc->tulip_probe_media);
699 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
704 * If this is hanging off a phy, we know are doing NWAY and we have
705 * forced the phy to a specific speed. Wait for link up before
706 * before sending a packet.
708 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) {
709 case TULIP_MEDIAINFO_MII: {
710 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
714 case TULIP_MEDIAINFO_SIA: {
715 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) {
716 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL)
718 tulip_linkup(sc, sc->tulip_probe_media);
720 if (sc->tulip_features & TULIP_HAVE_MII)
727 case TULIP_MEDIAINFO_RESET:
728 case TULIP_MEDIAINFO_SYM:
729 case TULIP_MEDIAINFO_NONE:
730 case TULIP_MEDIAINFO_GPR: {
735 * Try to send a packet.
741 tulip_media_select(tulip_softc_t *sc)
743 if (sc->tulip_features & TULIP_HAVE_GPR) {
744 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
746 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata);
749 * If this board has no media, just return
751 if (sc->tulip_features & TULIP_HAVE_NOMEDIA)
754 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
755 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
756 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START);
758 tulip_media_set(sc, sc->tulip_media);
763 tulip_21040_mediainfo_init(tulip_softc_t *sc, tulip_media_t media)
765 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
766 |TULIP_CMD_BACKOFFCTR;
767 sc->tulip_if.if_baudrate = 10000000;
769 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) {
770 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET);
771 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD);
772 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
775 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) {
776 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC);
779 if (media == TULIP_MEDIA_UNKNOWN) {
780 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA);
785 tulip_21040_media_probe(tulip_softc_t *sc)
787 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
791 tulip_21040_10baset_only_media_probe(tulip_softc_t *sc)
793 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
794 tulip_media_set(sc, TULIP_MEDIA_10BASET);
795 sc->tulip_media = TULIP_MEDIA_10BASET;
799 tulip_21040_10baset_only_media_select(tulip_softc_t *sc)
801 sc->tulip_flags |= TULIP_LINKUP;
802 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
803 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
804 sc->tulip_flags &= ~TULIP_SQETEST;
806 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
807 sc->tulip_flags |= TULIP_SQETEST;
809 tulip_media_set(sc, sc->tulip_media);
813 tulip_21040_auibnc_only_media_probe(tulip_softc_t *sc)
815 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
816 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
817 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
818 sc->tulip_media = TULIP_MEDIA_AUIBNC;
822 tulip_21040_auibnc_only_media_select(tulip_softc_t *sc)
824 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
825 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
828 static const tulip_boardsw_t tulip_21040_boardsw = {
830 tulip_21040_media_probe,
835 static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = {
837 tulip_21040_10baset_only_media_probe,
838 tulip_21040_10baset_only_media_select,
842 static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = {
844 tulip_21040_auibnc_only_media_probe,
845 tulip_21040_auibnc_only_media_select,
850 tulip_21041_mediainfo_init(tulip_softc_t *sc)
852 tulip_media_info_t *mi = sc->tulip_mediainfo;
855 if (sc->tulip_revinfo >= 0x20) {
856 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET);
857 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD);
858 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI);
859 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC);
863 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET);
864 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD);
865 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
866 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
870 tulip_21041_media_probe(tulip_softc_t *sc)
872 sc->tulip_if.if_baudrate = 10000000;
873 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
874 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
875 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
876 tulip_21041_mediainfo_init(sc);
880 tulip_21041_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
884 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
885 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
886 || !TULIP_DO_AUTOSENSE(sc))
888 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
889 tulip_reset(sc); /* start probe */
894 * If we've been been asked to start a poll or link change interrupt
895 * restart the probe (and reset the tulip to a known state).
897 if (event == TULIP_MEDIAPOLL_START) {
898 ifq_set_oactive(&sc->tulip_if.if_snd);
899 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN);
901 if (sc->tulip_revinfo >= 0x20) {
902 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
903 sc->tulip_flags |= TULIP_DIDNWAY;
906 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
907 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
908 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
909 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT;
910 tulip_media_set(sc, TULIP_MEDIA_10BASET);
915 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
918 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
919 tulip_linkup(sc, sc->tulip_probe_media);
923 sia_status = TULIP_CSR_READ(sc, csr_sia_status);
924 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status);
925 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) {
926 if (sc->tulip_revinfo >= 0x20) {
927 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6)))
928 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
931 * If the link has passed LinkPass, 10baseT is the
932 * proper media to use.
934 tulip_linkup(sc, sc->tulip_probe_media);
939 * wait for up to 2.4 seconds for the link to reach pass state.
940 * Only then start scanning the other media for activity.
941 * choose media with receive activity over those without.
943 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) {
944 if (event != TULIP_MEDIAPOLL_TIMER)
946 if (sc->tulip_probe_timeout > 0
947 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
951 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
952 sc->tulip_flags |= TULIP_WANTRXACT;
953 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) {
954 sc->tulip_probe_media = TULIP_MEDIA_BNC;
956 sc->tulip_probe_media = TULIP_MEDIA_AUI;
958 tulip_media_set(sc, sc->tulip_probe_media);
964 * If we failed, clear the txprobe active flag.
966 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED)
967 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
970 if (event == TULIP_MEDIAPOLL_TIMER) {
972 * If we've received something, then that's our link!
974 if (sc->tulip_flags & TULIP_RXACT) {
975 tulip_linkup(sc, sc->tulip_probe_media);
979 * if no txprobe active
981 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0
982 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0
983 || (sia_status & TULIP_SIASTS_RXACTIVITY))) {
984 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
990 * Take 2 passes through before deciding to not
991 * wait for receive activity. Then take another
992 * two passes before spitting out a warning.
994 if (sc->tulip_probe_timeout <= 0) {
995 if (sc->tulip_flags & TULIP_WANTRXACT) {
996 sc->tulip_flags &= ~TULIP_WANTRXACT;
997 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
999 if_printf(&sc->tulip_if, "autosense failed: cable problem?\n");
1000 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
1001 sc->tulip_if.if_flags &= ~IFF_RUNNING;
1002 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1010 * Since this media failed to probe, try the other one.
1012 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1013 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) {
1014 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1016 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1018 tulip_media_set(sc, sc->tulip_probe_media);
1019 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1023 static const tulip_boardsw_t tulip_21041_boardsw = {
1024 TULIP_21041_GENERIC,
1025 tulip_21041_media_probe,
1027 tulip_21041_media_poll
1030 static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
1031 { 0x20005c00, 0, /* 08-00-17 */
1033 { 0x19, 0x0040, 0x0040 }, /* 10TX */
1034 { 0x19, 0x0040, 0x0000 }, /* 100TX */
1037 { 0x0281F400, 0, /* 00-A0-7D */
1039 { 0x12, 0x0010, 0x0000 }, /* 10T */
1041 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1042 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1046 { 0x0015F420, 0, /* 00-A0-7D */
1048 { 0x12, 0x0010, 0x0000 }, /* 10T */
1050 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1051 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1055 { 0x0281F400, 0, /* 00-A0-BE */
1057 { 0x11, 0x8000, 0x0000 }, /* 10T */
1058 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1060 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1066 static tulip_media_t
1067 tulip_mii_phy_readspecific(tulip_softc_t *sc)
1069 const tulip_phy_attr_t *attr;
1073 static const tulip_media_t table[] = {
1074 TULIP_MEDIA_UNKNOWN,
1075 TULIP_MEDIA_10BASET,
1076 TULIP_MEDIA_100BASETX,
1077 TULIP_MEDIA_100BASET4,
1078 TULIP_MEDIA_UNKNOWN,
1079 TULIP_MEDIA_10BASET_FD,
1080 TULIP_MEDIA_100BASETX_FD,
1085 * Don't read phy specific registers if link is not up.
1087 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
1088 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS))
1089 return TULIP_MEDIA_UNKNOWN;
1091 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) |
1092 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH);
1093 for (attr = tulip_mii_phy_attrlist;; attr++) {
1094 if (attr->attr_id == 0)
1095 return TULIP_MEDIA_UNKNOWN;
1096 if ((id & ~0x0F) == attr->attr_id)
1100 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
1101 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_100TX];
1102 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1103 if ((data & pm->pm_mask) == pm->pm_value)
1106 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) {
1107 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_100T4];
1108 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1109 if ((data & pm->pm_mask) == pm->pm_value)
1112 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) {
1113 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_10T];
1114 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1115 if ((data & pm->pm_mask) == pm->pm_value)
1118 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) {
1119 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
1120 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1121 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
1127 tulip_mii_get_phyaddr(tulip_softc_t *sc, u_int offset)
1131 for (phyaddr = 1; phyaddr < 32; phyaddr++) {
1132 u_int status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1133 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1140 u_int status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
1141 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1142 return TULIP_MII_NOPHY;
1145 return TULIP_MII_NOPHY;
1149 tulip_mii_map_abilities(tulip_softc_t *sc, u_int abilities)
1151 sc->tulip_abilities = abilities;
1152 if (abilities & PHYSTS_100BASETX_FD) {
1153 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD;
1154 } else if (abilities & PHYSTS_100BASET4) {
1155 sc->tulip_probe_media = TULIP_MEDIA_100BASET4;
1156 } else if (abilities & PHYSTS_100BASETX) {
1157 sc->tulip_probe_media = TULIP_MEDIA_100BASETX;
1158 } else if (abilities & PHYSTS_10BASET_FD) {
1159 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1160 } else if (abilities & PHYSTS_10BASET) {
1161 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1163 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1166 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1171 tulip_mii_autonegotiate(tulip_softc_t *sc, u_int phyaddr)
1173 switch (sc->tulip_probe_state) {
1174 case TULIP_PROBE_MEDIATEST:
1175 case TULIP_PROBE_INACTIVE: {
1176 sc->tulip_flags |= TULIP_DIDNWAY;
1177 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET);
1178 sc->tulip_probe_timeout = 3000;
1179 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR;
1180 sc->tulip_probe_state = TULIP_PROBE_PHYRESET;
1183 case TULIP_PROBE_PHYRESET: {
1185 uint32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1186 if (data & PHYCTL_RESET) {
1187 if (sc->tulip_probe_timeout > 0) {
1191 if_printf(&sc->tulip_if,
1192 "(phy%d): error: reset of PHY never completed!\n", phyaddr);
1193 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1194 sc->tulip_probe_state = TULIP_PROBE_FAILED;
1195 sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
1198 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1199 if ((status & PHYSTS_CAN_AUTONEG) == 0) {
1200 sc->tulip_flags &= ~TULIP_DIDNWAY;
1201 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1204 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01))
1205 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
1206 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
1207 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1208 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
1209 sc->tulip_probe_timeout = 3000;
1212 case TULIP_PROBE_PHYAUTONEG: {
1213 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1215 if ((status & PHYSTS_AUTONEG_DONE) == 0) {
1216 if (sc->tulip_probe_timeout > 0) {
1220 sc->tulip_flags &= ~TULIP_DIDNWAY;
1221 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1224 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
1225 data = (data << 6) & status;
1226 if (!tulip_mii_map_abilities(sc, data))
1227 sc->tulip_flags &= ~TULIP_DIDNWAY;
1231 #if defined(DIAGNOSTIC)
1232 panic("tulip_media_poll: botch at line %d", __LINE__);
1240 tulip_2114x_media_preset(tulip_softc_t *sc)
1242 const tulip_media_info_t *mi = NULL;
1243 tulip_media_t media;
1245 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1246 media = sc->tulip_media;
1248 media = sc->tulip_probe_media;
1250 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
1251 sc->tulip_flags &= ~TULIP_SQETEST;
1252 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
1253 mi = sc->tulip_mediums[media];
1254 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
1255 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1256 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR
1257 || mi->mi_type == TULIP_MEDIAINFO_SYM) {
1258 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
1259 sc->tulip_cmdmode |= mi->mi_cmdmode;
1260 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
1261 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
1265 case TULIP_MEDIA_BNC:
1266 case TULIP_MEDIA_AUI:
1267 case TULIP_MEDIA_10BASET: {
1268 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1269 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
1270 sc->tulip_if.if_baudrate = 10000000;
1271 sc->tulip_flags |= TULIP_SQETEST;
1274 case TULIP_MEDIA_10BASET_FD: {
1275 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
1276 sc->tulip_if.if_baudrate = 10000000;
1279 case TULIP_MEDIA_100BASEFX:
1280 case TULIP_MEDIA_100BASET4:
1281 case TULIP_MEDIA_100BASETX: {
1282 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL);
1283 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1284 sc->tulip_if.if_baudrate = 100000000;
1287 case TULIP_MEDIA_100BASEFX_FD:
1288 case TULIP_MEDIA_100BASETX_FD: {
1289 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT;
1290 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
1291 sc->tulip_if.if_baudrate = 100000000;
1298 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1302 ********************************************************************
1303 * Start of 21140/21140A support which does not use the MII interface
1307 tulip_null_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
1309 #if defined(DIAGNOSTIC)
1310 if_printf(&sc->tulip_if, "botch(media_poll) at line %d\n", __LINE__);
1315 tulip_21140_mediainit(tulip_softc_t *sc, tulip_media_info_t *mip,
1316 tulip_media_t media, u_int gpdata, u_int cmdmode)
1318 sc->tulip_mediums[media] = mip;
1319 mip->mi_type = TULIP_MEDIAINFO_GPR;
1320 mip->mi_cmdmode = cmdmode;
1321 mip->mi_gpdata = gpdata;
1325 tulip_21140_evalboard_media_probe(tulip_softc_t *sc)
1327 tulip_media_info_t *mip = sc->tulip_mediainfo;
1329 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1330 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1331 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1332 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1333 TULIP_CSR_WRITE(sc, csr_command,
1334 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1335 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1336 TULIP_CSR_WRITE(sc, csr_command,
1337 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1339 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
1340 sc->tulip_media = TULIP_MEDIA_10BASET;
1342 sc->tulip_media = TULIP_MEDIA_100BASETX;
1344 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1346 TULIP_CMD_TXTHRSHLDCTL);
1347 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1349 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1350 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1352 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1353 |TULIP_CMD_SCRAMBLER);
1354 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1356 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1357 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1360 static const tulip_boardsw_t tulip_21140_eb_boardsw = {
1362 tulip_21140_evalboard_media_probe,
1364 tulip_null_media_poll,
1365 tulip_2114x_media_preset,
1369 tulip_21140_accton_media_probe(tulip_softc_t *sc)
1371 tulip_media_info_t *mip = sc->tulip_mediainfo;
1374 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1375 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1376 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1377 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1378 TULIP_CSR_WRITE(sc, csr_command,
1379 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1380 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1381 TULIP_CSR_WRITE(sc, csr_command,
1382 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1384 gpdata = TULIP_CSR_READ(sc, csr_gp);
1385 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) {
1386 sc->tulip_media = TULIP_MEDIA_10BASET;
1388 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) {
1389 sc->tulip_media = TULIP_MEDIA_BNC;
1391 sc->tulip_media = TULIP_MEDIA_100BASETX;
1394 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC,
1395 TULIP_GP_EN1207_BNC_INIT,
1396 TULIP_CMD_TXTHRSHLDCTL);
1397 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1398 TULIP_GP_EN1207_UTP_INIT,
1399 TULIP_CMD_TXTHRSHLDCTL);
1400 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1401 TULIP_GP_EN1207_UTP_INIT,
1402 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1403 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1404 TULIP_GP_EN1207_100_INIT,
1405 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1406 |TULIP_CMD_SCRAMBLER);
1407 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1408 TULIP_GP_EN1207_100_INIT,
1409 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1410 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1413 static const tulip_boardsw_t tulip_21140_accton_boardsw = {
1415 tulip_21140_accton_media_probe,
1417 tulip_null_media_poll,
1418 tulip_2114x_media_preset,
1422 tulip_21140_smc9332_media_probe(tulip_softc_t *sc)
1424 tulip_media_info_t *mip = sc->tulip_mediainfo;
1427 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE);
1428 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
1429 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
1430 33MHz that comes to two microseconds but wait a
1431 bit longer anyways) */
1432 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT |
1433 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1434 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS;
1435 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT;
1436 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET);
1437 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT);
1439 for (idx = 1000; idx > 0; idx--) {
1440 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1441 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) {
1444 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
1451 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1452 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1453 TULIP_GP_SMC_9332_INIT,
1454 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1455 |TULIP_CMD_SCRAMBLER);
1456 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1457 TULIP_GP_SMC_9332_INIT,
1458 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1459 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1460 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1461 TULIP_GP_SMC_9332_INIT,
1462 TULIP_CMD_TXTHRSHLDCTL);
1463 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1464 TULIP_GP_SMC_9332_INIT,
1465 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1468 static const tulip_boardsw_t tulip_21140_smc9332_boardsw = {
1469 TULIP_21140_SMC_9332,
1470 tulip_21140_smc9332_media_probe,
1472 tulip_null_media_poll,
1473 tulip_2114x_media_preset,
1477 tulip_21140_cogent_em100_media_probe(tulip_softc_t *sc)
1479 tulip_media_info_t *mip = sc->tulip_mediainfo;
1482 sc->tulip_gpinit = TULIP_GP_EM100_PINS;
1483 sc->tulip_gpdata = TULIP_GP_EM100_INIT;
1484 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS);
1485 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT);
1487 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE;
1488 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER);
1489 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1490 TULIP_CSR_WRITE(sc, csr_command, cmdmode);
1491 sc->tulip_media = TULIP_MEDIA_100BASEFX;
1493 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX,
1494 TULIP_GP_EM100_INIT,
1495 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION);
1496 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD,
1497 TULIP_GP_EM100_INIT,
1498 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1499 |TULIP_CMD_FULLDUPLEX);
1501 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);
1502 sc->tulip_media = TULIP_MEDIA_100BASETX;
1503 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1504 TULIP_GP_EM100_INIT,
1505 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1506 |TULIP_CMD_SCRAMBLER);
1507 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1508 TULIP_GP_EM100_INIT,
1509 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1510 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1514 static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {
1515 TULIP_21140_COGENT_EM100,
1516 tulip_21140_cogent_em100_media_probe,
1518 tulip_null_media_poll,
1519 tulip_2114x_media_preset
1523 tulip_21140_znyx_zx34x_media_probe(tulip_softc_t *sc)
1525 tulip_media_info_t *mip = sc->tulip_mediainfo;
1526 int cnt10 = 0, cnt100 = 0, idx;
1528 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS;
1529 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT;
1530 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS);
1531 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT);
1532 TULIP_CSR_WRITE(sc, csr_command,
1533 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1534 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1535 TULIP_CSR_WRITE(sc, csr_command,
1536 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1539 for (idx = 1000; idx > 0; idx--) {
1540 uint32_t csr = TULIP_CSR_READ(sc, csr_gp);
1541 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)) {
1544 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
1553 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1554 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1555 TULIP_GP_ZX34X_INIT,
1556 TULIP_CMD_TXTHRSHLDCTL);
1557 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1558 TULIP_GP_ZX34X_INIT,
1559 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1560 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1561 TULIP_GP_ZX34X_INIT,
1562 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1563 |TULIP_CMD_SCRAMBLER);
1564 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1565 TULIP_GP_ZX34X_INIT,
1566 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1567 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1570 static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = {
1571 TULIP_21140_ZNYX_ZX34X,
1572 tulip_21140_znyx_zx34x_media_probe,
1574 tulip_null_media_poll,
1575 tulip_2114x_media_preset,
1579 tulip_2114x_media_probe(tulip_softc_t *sc)
1581 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE | TULIP_CMD_BACKOFFCTR |
1582 TULIP_CMD_THRSHLD72;
1585 static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
1587 tulip_2114x_media_probe,
1590 tulip_2114x_media_preset,
1594 * ******** END of chip-specific handlers. ***********
1598 * Code the read the SROM and MII bit streams (I2C)
1601 TULIP_CSR_WRITE(sc, csr_srom_mii, csr); \
1606 tulip_srom_idle(tulip_softc_t *sc)
1610 csr = SROMSEL ; EMIT;
1611 csr = SROMSEL | SROMRD; EMIT;
1612 csr ^= SROMCS; EMIT;
1613 csr ^= SROMCLKON; EMIT;
1616 * Write 25 cycles of 0 which will force the SROM to be idle.
1618 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1619 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1620 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1622 csr ^= SROMCLKOFF; EMIT;
1623 csr ^= SROMCS; EMIT;
1629 tulip_srom_read(tulip_softc_t *sc)
1631 const u_int bitwidth = SROM_BITWIDTH;
1632 const u_int cmdmask = (SROMCMD_RD << bitwidth);
1633 const u_int msb = 1 << (bitwidth + 3 - 1);
1634 u_int idx, lastidx = (1 << bitwidth) - 1;
1636 tulip_srom_idle(sc);
1638 for (idx = 0; idx <= lastidx; idx++) {
1639 u_int lastbit, data, bits, bit, csr;
1640 csr = SROMSEL ; EMIT;
1641 csr = SROMSEL | SROMRD; EMIT;
1642 csr ^= SROMCSON; EMIT;
1643 csr ^= SROMCLKON; EMIT;
1646 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
1647 u_int thisbit = bits & msb;
1648 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1649 if (thisbit != lastbit) {
1650 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1654 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1657 csr ^= SROMCLKOFF; EMIT;
1659 for (data = 0, bits = 0; bits < 16; bits++) {
1661 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1662 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1663 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1665 sc->tulip_rombuf[idx*2] = data & 0xFF;
1666 sc->tulip_rombuf[idx*2+1] = data >> 8;
1667 csr = SROMSEL | SROMRD; EMIT;
1670 tulip_srom_idle(sc);
1673 #define MII_EMIT do { \
1674 TULIP_CSR_WRITE(sc, csr_srom_mii, csr); \
1679 tulip_mii_writebits(tulip_softc_t *sc, u_int data, u_int bits)
1681 u_int csr, msb, lastbit;
1683 msb = 1 << (bits - 1);
1684 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1685 lastbit = (csr & MII_DOUT) ? msb : 0;
1686 csr |= MII_WR; MII_EMIT; /* clock low; assert write */
1688 for (; bits > 0; bits--, data <<= 1) {
1689 const unsigned thisbit = data & msb;
1690 if (thisbit != lastbit) {
1691 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */
1693 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1695 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1700 tulip_mii_turnaround(tulip_softc_t *sc, u_int cmd)
1704 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1706 if (cmd == MII_WRCMD) {
1707 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
1708 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1709 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1710 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */
1712 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */
1714 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1715 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1719 tulip_mii_readbits(tulip_softc_t *sc)
1721 u_int csr, data, idx;
1723 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1725 for (idx = 0, data = 0; idx < 16; idx++) {
1726 data <<= 1; /* this is NOOP on the first pass through */
1727 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1728 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)
1730 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1732 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
1738 tulip_mii_readreg(tulip_softc_t *sc, u_int devaddr, u_int regno)
1743 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1744 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1745 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1746 tulip_mii_writebits(sc, MII_RDCMD, 8);
1747 tulip_mii_writebits(sc, devaddr, 5);
1748 tulip_mii_writebits(sc, regno, 5);
1749 tulip_mii_turnaround(sc, MII_RDCMD);
1751 data = tulip_mii_readbits(sc);
1756 tulip_mii_writereg(tulip_softc_t *sc, u_int devaddr, u_int regno, u_int data)
1760 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1761 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1762 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1763 tulip_mii_writebits(sc, MII_WRCMD, 8);
1764 tulip_mii_writebits(sc, devaddr, 5);
1765 tulip_mii_writebits(sc, regno, 5);
1766 tulip_mii_turnaround(sc, MII_WRCMD);
1767 tulip_mii_writebits(sc, data, 16);
1770 #define tulip_mchash(mca) (ether_crc32_le(mca, 6) & 0x1FF)
1771 #define tulip_srom_crcok(databuf) ( \
1772 ((ether_crc32_le(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
1773 ((databuf)[126] | ((databuf)[127] << 8)))
1776 tulip_identify_dec_nic(tulip_softc_t *sc)
1778 strcpy(sc->tulip_boardid, "DEC ");
1780 if (sc->tulip_chipid <= TULIP_21040)
1782 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0
1783 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {
1784 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);
1785 sc->tulip_boardid[D0+8] = ' ';
1791 tulip_identify_znyx_nic(tulip_softc_t * const sc)
1794 strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
1795 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
1797 sc->tulip_boardid[8] = '4';
1798 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
1799 if (znyx_ptr < 26 || znyx_ptr > 116) {
1800 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1803 /* ZX344 = 0010 .. 0013FF
1805 if (sc->tulip_rombuf[znyx_ptr] == 0x4A
1806 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52
1807 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) {
1808 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4];
1809 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) {
1810 sc->tulip_boardid[9] = '2';
1811 if (id == TULIP_ZNYX_ID_ZX342B) {
1812 sc->tulip_boardid[10] = 'B';
1813 sc->tulip_boardid[11] = ' ';
1815 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1816 } else if (id == TULIP_ZNYX_ID_ZX344) {
1817 sc->tulip_boardid[10] = '4';
1818 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1819 } else if (id == TULIP_ZNYX_ID_ZX345) {
1820 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5';
1821 } else if (id == TULIP_ZNYX_ID_ZX346) {
1822 sc->tulip_boardid[9] = '6';
1823 } else if (id == TULIP_ZNYX_ID_ZX351) {
1824 sc->tulip_boardid[8] = '5';
1825 sc->tulip_boardid[9] = '1';
1830 * Assume it's a ZX342...
1832 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1836 sc->tulip_boardid[8] = '1';
1837 if (sc->tulip_chipid == TULIP_21041) {
1838 sc->tulip_boardid[10] = '1';
1841 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) {
1842 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36];
1843 if (id == TULIP_ZNYX_ID_ZX312T) {
1844 sc->tulip_boardid[9] = '2';
1845 sc->tulip_boardid[10] = 'T';
1846 sc->tulip_boardid[11] = ' ';
1847 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1848 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) {
1849 sc->tulip_boardid[9] = '4';
1850 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1851 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1852 } else if (id == TULIP_ZNYX_ID_ZX314) {
1853 sc->tulip_boardid[9] = '4';
1854 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1855 sc->tulip_features |= TULIP_HAVE_BASEROM;
1856 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) {
1857 sc->tulip_boardid[9] = '5';
1858 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1859 } else if (id == TULIP_ZNYX_ID_ZX315) {
1860 sc->tulip_boardid[9] = '5';
1861 sc->tulip_features |= TULIP_HAVE_BASEROM;
1867 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) {
1868 sc->tulip_boardid[9] = '4';
1869 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1870 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1871 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) {
1872 sc->tulip_boardid[9] = '5';
1873 sc->tulip_boardsw = &tulip_21040_boardsw;
1874 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1875 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) {
1876 sc->tulip_boardid[9] = '2';
1877 sc->tulip_boardsw = &tulip_21040_boardsw;
1883 tulip_identify_smc_nic(tulip_softc_t * const sc)
1885 uint32_t id1, id2, ei;
1886 int auibnc = 0, utp = 0;
1889 strcpy(sc->tulip_boardid, "SMC ");
1890 if (sc->tulip_chipid == TULIP_21041)
1892 if (sc->tulip_chipid != TULIP_21040) {
1893 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
1894 strcpy(&sc->tulip_boardid[4], "9332DST ");
1895 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;
1896 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {
1897 strcpy(&sc->tulip_boardid[4], "9334BDT ");
1899 strcpy(&sc->tulip_boardid[4], "9332BDT ");
1903 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);
1904 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);
1905 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);
1907 strcpy(&sc->tulip_boardid[4], "8432");
1908 cp = &sc->tulip_boardid[8];
1910 *cp++ = 'B', auibnc = 1;
1911 if ((id1 & 0xFF) > 0x32)
1912 *cp++ = 'T', utp = 1;
1913 if ((id1 & 0x4000) == 0)
1914 *cp++ = 'A', auibnc = 1;
1916 sc->tulip_boardid[7] = '4';
1920 *cp++ = (ei ? '2' : '1');
1925 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1926 else if (!utp && auibnc)
1927 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
1931 tulip_identify_cogent_nic(tulip_softc_t * const sc)
1933 strcpy(sc->tulip_boardid, "Cogent ");
1934 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
1935 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {
1936 strcat(sc->tulip_boardid, "EM100TX ");
1937 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1938 #if defined(TULIP_COGENT_EM110TX_ID)
1939 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {
1940 strcat(sc->tulip_boardid, "EM110TX ");
1941 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1943 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1944 strcat(sc->tulip_boardid, "EM100FX ");
1945 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1948 * Magic number (0x24001109U) is the SubVendor (0x2400) and
1949 * SubDevId (0x1109) for the ANA6944TX (EM440TX).
1951 if (*(uint32_t *) sc->tulip_rombuf == 0x24001109U
1952 && (sc->tulip_features & TULIP_HAVE_BASEROM)) {
1954 * Cogent (Adaptec) is still mapping all INTs to INTA of
1955 * first 21140. Dumb! Dumb!
1957 strcat(sc->tulip_boardid, "EM440TX ");
1958 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
1960 } else if (sc->tulip_chipid == TULIP_21040) {
1961 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1966 tulip_identify_accton_nic(tulip_softc_t * const sc)
1968 strcpy(sc->tulip_boardid, "ACCTON ");
1969 switch (sc->tulip_chipid) {
1971 strcat(sc->tulip_boardid, "EN1207 ");
1972 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
1973 sc->tulip_boardsw = &tulip_21140_accton_boardsw;
1976 strcat(sc->tulip_boardid, "EN1207TX ");
1977 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
1978 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
1981 strcat(sc->tulip_boardid, "EN1203 ");
1982 sc->tulip_boardsw = &tulip_21040_boardsw;
1985 strcat(sc->tulip_boardid, "EN1203 ");
1986 sc->tulip_boardsw = &tulip_21041_boardsw;
1989 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
1995 tulip_identify_asante_nic(tulip_softc_t * const sc)
1997 strcpy(sc->tulip_boardid, "Asante ");
1998 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
1999 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2000 tulip_media_info_t *mi = sc->tulip_mediainfo;
2003 * The Asante Fast Ethernet doesn't always ship with a valid
2004 * new format SROM. So if isn't in the new format, we cheat
2005 * set it up as if we had.
2008 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;
2009 sc->tulip_gpdata = 0;
2011 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);
2012 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);
2014 TULIP_CSR_WRITE(sc, csr_gp, 0);
2016 mi->mi_type = TULIP_MEDIAINFO_MII;
2017 mi->mi_gpr_length = 0;
2018 mi->mi_gpr_offset = 0;
2019 mi->mi_reset_length = 0;
2020 mi->mi_reset_offset = 0;
2022 mi->mi_phyaddr = TULIP_MII_NOPHY;
2023 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) {
2025 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
2027 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2028 if_printf(&sc->tulip_if, "can't find phy 0\n");
2032 sc->tulip_features |= TULIP_HAVE_MII;
2033 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2034 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2035 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD;
2036 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD;
2037 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2038 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2039 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2040 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2041 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2042 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2043 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2045 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2050 tulip_identify_compex_nic(tulip_softc_t *sc)
2052 strcpy(sc->tulip_boardid, "COMPEX ");
2053 if (sc->tulip_chipid == TULIP_21140A) {
2055 tulip_softc_t *root_sc = NULL;
2057 strcat(sc->tulip_boardid, "400TX/PCI ");
2059 * All 4 chips on these boards share an interrupt. This code
2060 * copied from tulip_read_macaddr.
2062 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2063 for (root_unit = device_get_unit(sc->tulip_dev) - 1; root_unit >= 0; root_unit--) {
2064 root_sc = tulips[root_unit];
2066 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
2071 && root_sc->tulip_chipid == sc->tulip_chipid
2072 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2073 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2074 sc->tulip_slaves = root_sc->tulip_slaves;
2075 root_sc->tulip_slaves = sc;
2076 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
2077 if_printf(&sc->tulip_if, "can't find master device for interrupts");
2080 strcat(sc->tulip_boardid, "unknown ");
2082 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */
2087 tulip_srom_decode(tulip_softc_t *sc)
2089 u_int idx1, idx2, idx3;
2091 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
2092 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
2093 tulip_srom_media_t srom_media;
2094 tulip_media_info_t *mi = sc->tulip_mediainfo;
2096 uint32_t leaf_offset, blocks, data;
2098 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
2099 if (shp->sh_adapter_count == 1)
2101 if (saip->sai_device == sc->tulip_pci_devno)
2105 * Didn't find the right media block for this card.
2107 if (idx1 == shp->sh_adapter_count)
2111 * Save the hardware address.
2113 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6);
2115 * If this is a multiple port card, add the adapter index to the last
2116 * byte of the hardware address. (if it isn't multiport, adding 0
2119 sc->tulip_enaddr[5] += idx1;
2121 leaf_offset = saip->sai_leaf_offset_lowbyte
2122 + saip->sai_leaf_offset_highbyte * 256;
2123 dp = sc->tulip_rombuf + leaf_offset;
2125 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2;
2127 for (idx2 = 0;; idx2++) {
2128 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype
2129 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED)
2132 sc->tulip_connidx = idx2;
2134 if (sc->tulip_chipid == TULIP_21041) {
2136 for (idx2 = 0; idx2 < blocks; idx2++) {
2137 tulip_media_t media;
2139 srom_media = (tulip_srom_media_t) (data & 0x3F);
2140 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2141 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2144 media = tulip_srom_mediums[idx3].sm_type;
2145 if (media != TULIP_MEDIA_UNKNOWN) {
2146 if (data & TULIP_SROM_21041_EXTENDED) {
2147 mi->mi_type = TULIP_MEDIAINFO_SIA;
2148 sc->tulip_mediums[media] = mi;
2149 mi->mi_sia_connectivity = dp[0] + dp[1] * 256;
2150 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256;
2151 mi->mi_sia_general = dp[4] + dp[5] * 256;
2155 case TULIP_MEDIA_BNC: {
2156 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
2160 case TULIP_MEDIA_AUI: {
2161 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
2165 case TULIP_MEDIA_10BASET: {
2166 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
2170 case TULIP_MEDIA_10BASET_FD: {
2171 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
2181 if (data & TULIP_SROM_21041_EXTENDED)
2186 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++;
2187 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++;
2188 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++;
2189 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++;
2193 unsigned length, type;
2194 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN;
2195 if (sc->tulip_features & TULIP_HAVE_GPR)
2196 sc->tulip_gpinit = *dp++;
2198 for (idx2 = 0; idx2 < blocks; idx2++) {
2200 if ((*dp & 0x80) == 0) {
2204 length = (*dp++ & 0x7f) - 1;
2205 type = *dp++ & 0x3f;
2208 switch (type & 0x3f) {
2209 case 0: { /* 21140[A] GPR block */
2210 tulip_media_t media;
2211 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2212 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2213 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2216 media = tulip_srom_mediums[idx3].sm_type;
2217 if (media == TULIP_MEDIA_UNKNOWN)
2219 mi->mi_type = TULIP_MEDIAINFO_GPR;
2220 sc->tulip_mediums[media] = mi;
2221 mi->mi_gpdata = dp[1];
2222 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) {
2223 sc->tulip_gpdata = mi->mi_gpdata;
2226 data = dp[2] + dp[3] * 256;
2227 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2228 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2232 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2234 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2235 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2240 case 1: { /* 21140[A] MII block */
2241 const u_int phyno = *dp++;
2242 mi->mi_type = TULIP_MEDIAINFO_MII;
2243 mi->mi_gpr_length = *dp++;
2244 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2245 dp += mi->mi_gpr_length;
2246 mi->mi_reset_length = *dp++;
2247 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2248 dp += mi->mi_reset_length;
2251 * Before we probe for a PHY, use the GPR information
2252 * to select it. If we don't, it may be inaccessible.
2254 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET);
2255 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) {
2257 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]);
2259 sc->tulip_phyaddr = mi->mi_phyaddr;
2260 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) {
2262 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]);
2266 * At least write something!
2268 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2269 TULIP_CSR_WRITE(sc, csr_gp, 0);
2271 mi->mi_phyaddr = TULIP_MII_NOPHY;
2272 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2274 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2276 if (mi->mi_phyaddr == TULIP_MII_NOPHY)
2278 sc->tulip_features |= TULIP_HAVE_MII;
2279 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2280 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2281 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2282 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2283 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2284 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2285 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2286 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2287 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2288 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2289 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2293 case 2: { /* 2114[23] SIA block */
2294 tulip_media_t media;
2295 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2296 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2297 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2300 media = tulip_srom_mediums[idx3].sm_type;
2301 if (media == TULIP_MEDIA_UNKNOWN)
2303 mi->mi_type = TULIP_MEDIAINFO_SIA;
2304 sc->tulip_mediums[media] = mi;
2306 mi->mi_sia_connectivity = dp[1] + dp[2] * 256;
2307 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256;
2308 mi->mi_sia_general = dp[5] + dp[6] * 256;
2312 case TULIP_MEDIA_BNC: {
2313 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
2316 case TULIP_MEDIA_AUI: {
2317 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
2320 case TULIP_MEDIA_10BASET: {
2321 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
2322 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2325 case TULIP_MEDIA_10BASET_FD: {
2326 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
2327 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2335 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16;
2336 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16;
2341 case 3: { /* 2114[23] MII PHY block */
2342 const u_int phyno = *dp++;
2344 mi->mi_type = TULIP_MEDIAINFO_MII;
2345 mi->mi_gpr_length = *dp++;
2346 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2347 dp += 2 * mi->mi_gpr_length;
2348 mi->mi_reset_length = *dp++;
2349 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2350 dp += 2 * mi->mi_reset_length;
2352 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset];
2353 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) {
2355 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2357 sc->tulip_phyaddr = mi->mi_phyaddr;
2358 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset];
2359 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) {
2361 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2364 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2365 TULIP_CSR_WRITE(sc, csr_sia_general, 0);
2367 mi->mi_phyaddr = TULIP_MII_NOPHY;
2368 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2370 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2372 if (mi->mi_phyaddr == TULIP_MII_NOPHY)
2374 sc->tulip_features |= TULIP_HAVE_MII;
2375 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2376 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2377 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2378 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2379 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2;
2380 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2381 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2382 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2383 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2384 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2385 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2386 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2390 case 4: { /* 21143 SYM block */
2391 tulip_media_t media;
2392 srom_media = (tulip_srom_media_t) dp[0];
2393 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2394 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2397 media = tulip_srom_mediums[idx3].sm_type;
2398 if (media == TULIP_MEDIA_UNKNOWN)
2400 mi->mi_type = TULIP_MEDIAINFO_SYM;
2401 sc->tulip_mediums[media] = mi;
2402 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16;
2403 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16;
2404 data = dp[5] + dp[6] * 256;
2405 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2406 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2409 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2410 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2411 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2413 if (TULIP_IS_MEDIA_TP(media))
2414 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2419 case 5: { /* 21143 Reset block */
2420 mi->mi_type = TULIP_MEDIAINFO_RESET;
2421 mi->mi_reset_length = *dp++;
2422 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2423 dp += 2 * mi->mi_reset_length;
2434 return mi - sc->tulip_mediainfo;
2437 static const struct {
2438 void (*vendor_identify_nic)(tulip_softc_t * const sc);
2439 unsigned char vendor_oui[3];
2440 } tulip_vendors[] = {
2441 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } },
2442 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } },
2443 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } },
2444 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } },
2445 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } },
2446 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } },
2447 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } },
2448 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } },
2449 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } },
2450 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } },
2455 * This deals with the vagaries of the address roms and the
2456 * brain-deadness that various vendors commit in using them.
2459 tulip_read_macaddr(tulip_softc_t *sc)
2461 u_int cksum, rom_cksum, idx;
2463 unsigned char tmpbuf[8];
2464 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
2466 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX;
2468 if (sc->tulip_chipid == TULIP_21040) {
2469 TULIP_CSR_WRITE(sc, csr_enetrom, 1);
2470 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2472 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
2474 sc->tulip_rombuf[idx] = csr & 0xFF;
2476 sc->tulip_boardsw = &tulip_21040_boardsw;
2478 if (sc->tulip_chipid == TULIP_21041) {
2480 * Thankfully all 21041's act the same.
2482 sc->tulip_boardsw = &tulip_21041_boardsw;
2485 * Assume all 21140 board are compatible with the
2486 * DEC 10/100 evaluation board. Not really valid but
2487 * it's the best we can do until every one switches to
2488 * the new SROM format.
2491 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2493 tulip_srom_read(sc);
2494 if (tulip_srom_crcok(sc->tulip_rombuf)) {
2496 * SROM CRC is valid therefore it must be in the
2499 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM;
2500 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
2502 * No checksum is present. See if the SROM id checks out;
2503 * the first 18 bytes should be 0 followed by a 1 followed
2504 * by the number of adapters (which we don't deal with yet).
2506 for (idx = 0; idx < 18; idx++) {
2507 if (sc->tulip_rombuf[idx] != 0)
2510 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
2511 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2512 } else if (sc->tulip_chipid >= TULIP_21142) {
2513 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2514 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2516 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) {
2517 if (sc->tulip_chipid != TULIP_21041)
2518 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2521 * If the SROM specifies more than one adapter, tag this as a
2524 if (sc->tulip_rombuf[19] > 1)
2525 sc->tulip_features |= TULIP_HAVE_BASEROM;
2526 if (sc->tulip_boardsw == NULL)
2533 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
2535 * Some folks don't use the standard ethernet rom format
2536 * but instead just put the address in the first 6 bytes
2537 * of the rom and let the rest be all 0xffs. (Can we say
2538 * ZNYX?) (well sometimes they put in a checksum so we'll
2541 for (idx = 8; idx < 32; idx++) {
2542 if (sc->tulip_rombuf[idx] != 0xFF)
2546 * Make sure the address is not multicast or locally assigned
2547 * that the OUI is not 00-00-00.
2549 if ((sc->tulip_rombuf[0] & 3) != 0)
2551 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
2552 && sc->tulip_rombuf[2] == 0)
2554 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2555 sc->tulip_features |= TULIP_HAVE_OKROM;
2559 * A number of makers of multiport boards (ZNYX and Cogent)
2560 * only put on one address ROM on their 21040 boards. So
2561 * if the ROM is all zeros (or all 0xFFs), look at the
2562 * previous configured boards (as long as they are on the same
2563 * PCI bus and the bus number is non-zero) until we find the
2564 * master board with address ROM. We then use its address ROM
2565 * as the base for this board. (we add our relative board
2566 * to the last byte of its address).
2568 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2569 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF)
2572 if (idx == sizeof(sc->tulip_rombuf)) {
2574 tulip_softc_t *root_sc = NULL;
2575 for (root_unit = device_get_unit(sc->tulip_dev) - 1; root_unit >= 0; root_unit--) {
2576 root_sc = tulips[root_unit];
2577 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
2581 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM)
2582 && root_sc->tulip_chipid == sc->tulip_chipid
2583 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2584 sc->tulip_features |= TULIP_HAVE_SLAVEDROM;
2585 sc->tulip_boardsw = root_sc->tulip_boardsw;
2586 strcpy(sc->tulip_boardid, root_sc->tulip_boardid);
2587 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) {
2588 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf,
2589 sizeof(sc->tulip_rombuf));
2590 if (!tulip_srom_decode(sc))
2593 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
2594 sc->tulip_enaddr[5] += device_get_unit(sc->tulip_dev) - device_get_unit(root_sc->tulip_dev);
2597 * Now for a truly disgusting kludge: all 4 21040s on
2598 * the ZX314 share the same INTA line so the mapping
2599 * setup by the BIOS on the PCI bridge is worthless.
2600 * Rather than reprogramming the value in the config
2601 * register, we will handle this internally.
2603 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) {
2604 sc->tulip_slaves = root_sc->tulip_slaves;
2605 root_sc->tulip_slaves = sc;
2606 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2614 * This is the standard DEC address ROM test.
2617 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
2620 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
2621 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
2622 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
2623 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
2624 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
2627 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2629 cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
2631 if (cksum > 65535) cksum -= 65535;
2632 cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
2633 if (cksum > 65535) cksum -= 65535;
2635 if (cksum > 65535) cksum -= 65535;
2636 cksum += *(u_int16_t *) &sc->tulip_enaddr[4];
2637 if (cksum >= 65535) cksum -= 65535;
2639 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6];
2641 if (cksum != rom_cksum)
2646 * Check for various boards based on OUI. Did I say braindead?
2648 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) {
2649 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) {
2650 (*tulip_vendors[idx].vendor_identify_nic)(sc);
2655 sc->tulip_features |= TULIP_HAVE_OKROM;
2660 tulip_ifmedia_add(tulip_softc_t * const sc)
2662 tulip_media_t media;
2665 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2666 if (sc->tulip_mediums[media] != NULL) {
2667 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media],
2673 sc->tulip_features |= TULIP_HAVE_NOMEDIA;
2674 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0);
2675 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE);
2676 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
2677 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0);
2678 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO);
2680 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]);
2681 sc->tulip_flags |= TULIP_PRINTMEDIA;
2682 tulip_linkup(sc, sc->tulip_media);
2687 tulip_ifmedia_change(struct ifnet *ifp)
2689 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2691 sc->tulip_flags |= TULIP_NEEDRESET;
2692 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
2693 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
2694 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) {
2695 tulip_media_t media;
2696 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2697 if (sc->tulip_mediums[media] != NULL
2698 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) {
2699 sc->tulip_flags |= TULIP_PRINTMEDIA;
2700 sc->tulip_flags &= ~TULIP_DIDNWAY;
2701 tulip_linkup(sc, media);
2706 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
2713 * Media status callback
2716 tulip_ifmedia_status(struct ifnet *ifp, struct ifmediareq *req)
2718 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2720 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN)
2723 req->ifm_status = IFM_AVALID;
2724 if (sc->tulip_flags & TULIP_LINKUP)
2725 req->ifm_status |= IFM_ACTIVE;
2727 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
2731 tulip_addr_filter(tulip_softc_t *sc)
2733 struct ifmultiaddr *ifma;
2737 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI);
2738 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART;
2739 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
2740 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
2741 #if defined(IFF_ALLMULTI)
2742 if (sc->tulip_if.if_flags & IFF_ALLMULTI)
2743 sc->tulip_flags |= TULIP_ALLMULTI ;
2747 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
2748 if (ifma->ifma_addr->sa_family == AF_LINK)
2752 sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */
2753 if (multicnt > 14) {
2754 uint32_t *sp = sc->tulip_setupdata;
2757 * Some early passes of the 21140 have broken implementations of
2758 * hash-perfect mode. When we get too many multicasts for perfect
2759 * filtering with these chips, we need to switch into hash-only
2760 * mode (this is better than all-multicast on network with lots
2761 * of multicast traffic).
2763 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
2764 sc->tulip_flags |= TULIP_WANTHASHONLY;
2766 sc->tulip_flags |= TULIP_WANTHASHPERFECT;
2768 * If we have more than 14 multicasts, we have
2769 * go into hash perfect mode (512 bit multicast
2770 * hash and one perfect hardware).
2772 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
2774 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
2775 if (ifma->ifma_addr->sa_family != AF_LINK)
2778 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
2779 #if BYTE_ORDER == BIG_ENDIAN
2780 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2782 sp[hash >> 4] |= 1 << (hash & 0xF);
2786 * No reason to use a hash if we are going to be
2787 * receiving every multicast.
2789 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
2790 hash = tulip_mchash(sc->tulip_if.if_broadcastaddr);
2791 #if BYTE_ORDER == BIG_ENDIAN
2792 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2794 sp[hash >> 4] |= 1 << (hash & 0xF);
2796 if (sc->tulip_flags & TULIP_WANTHASHONLY) {
2797 hash = tulip_mchash(sc->tulip_enaddr);
2798 #if BYTE_ORDER == BIG_ENDIAN
2799 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2801 sp[hash >> 4] |= 1 << (hash & 0xF);
2804 #if BYTE_ORDER == BIG_ENDIAN
2805 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
2806 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
2807 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
2809 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0];
2810 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1];
2811 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2];
2816 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
2817 uint32_t *sp = sc->tulip_setupdata;
2819 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
2821 * Else can get perfect filtering for 16 addresses.
2823 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
2824 if (ifma->ifma_addr->sa_family != AF_LINK)
2826 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
2827 #if BYTE_ORDER == BIG_ENDIAN
2828 *sp++ = ((u_int16_t *) addrp)[0] << 16;
2829 *sp++ = ((u_int16_t *) addrp)[1] << 16;
2830 *sp++ = ((u_int16_t *) addrp)[2] << 16;
2832 *sp++ = ((u_int16_t *) addrp)[0];
2833 *sp++ = ((u_int16_t *) addrp)[1];
2834 *sp++ = ((u_int16_t *) addrp)[2];
2839 * Add the broadcast address.
2842 #if BYTE_ORDER == BIG_ENDIAN
2843 *sp++ = 0xFFFF << 16;
2844 *sp++ = 0xFFFF << 16;
2845 *sp++ = 0xFFFF << 16;
2853 * Pad the rest with our hardware address
2855 for (; idx < 16; idx++) {
2856 #if BYTE_ORDER == BIG_ENDIAN
2857 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
2858 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
2859 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
2861 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0];
2862 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1];
2863 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2];
2867 #if defined(IFF_ALLMULTI)
2868 if (sc->tulip_flags & TULIP_ALLMULTI)
2869 sc->tulip_if.if_flags |= IFF_ALLMULTI;
2874 tulip_reset(tulip_softc_t *sc)
2876 tulip_ringinfo_t *ri;
2878 uint32_t inreset = (sc->tulip_flags & TULIP_INRESET);
2881 * Brilliant. Simply brilliant. When switching modes/speeds
2882 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
2883 * bits in CSR6 and then do a software reset to get the 21140
2884 * to properly reset its internal pathways to the right places.
2887 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
2888 && sc->tulip_boardsw->bd_media_preset != NULL)
2889 (*sc->tulip_boardsw->bd_media_preset)(sc);
2891 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2892 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
2893 33MHz that comes to two microseconds but wait a
2894 bit longer anyways) */
2897 sc->tulip_flags |= TULIP_INRESET;
2898 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
2899 ifq_clr_oactive(&sc->tulip_if.if_snd);
2900 sc->tulip_if.if_start = tulip_ifstart;
2903 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
2904 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
2905 TULIP_CSR_WRITE(sc, csr_busmode,
2906 (1 << (3 /*pci_max_burst_len*/ + 8))
2907 |TULIP_BUSMODE_CACHE_ALIGN8
2908 |TULIP_BUSMODE_READMULTIPLE
2909 |(BYTE_ORDER != LITTLE_ENDIAN ?
2910 TULIP_BUSMODE_DESC_BIGENDIAN : 0));
2912 sc->tulip_txtimer = 0;
2913 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
2915 * Free all the mbufs that were on the transmit ring.
2917 IF_DRAIN(&sc->tulip_txq);
2919 ri = &sc->tulip_txinfo;
2920 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
2921 ri->ri_free = ri->ri_max;
2922 for (di = ri->ri_first; di < ri->ri_last; di++)
2926 * We need to collect all the mbufs were on the
2927 * receive ring before we reinit it either to put
2928 * them back on or to know if we have to allocate
2931 ri = &sc->tulip_rxinfo;
2932 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
2933 ri->ri_free = ri->ri_max;
2934 for (di = ri->ri_first; di < ri->ri_last; di++) {
2936 di->d_length1 = 0; di->d_addr1 = 0;
2937 di->d_length2 = 0; di->d_addr2 = 0;
2939 IF_DRAIN(&sc->tulip_rxq);
2942 * If tulip_reset is being called recurisvely, exit quickly knowing
2943 * that when the outer tulip_reset returns all the right stuff will
2949 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
2950 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
2951 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
2952 |TULIP_STS_RXSTOPPED;
2954 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
2955 (*sc->tulip_boardsw->bd_media_select)(sc);
2956 tulip_media_print(sc);
2957 if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
2958 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
2960 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
2962 tulip_addr_filter(sc);
2966 tulip_init(tulip_softc_t * const sc)
2968 if (sc->tulip_if.if_flags & IFF_UP) {
2969 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) {
2970 /* initialize the media */
2973 sc->tulip_if.if_flags |= IFF_RUNNING;
2974 if (sc->tulip_if.if_flags & IFF_PROMISC) {
2975 sc->tulip_flags |= TULIP_PROMISC;
2976 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
2977 sc->tulip_intrmask |= TULIP_STS_TXINTR;
2979 sc->tulip_flags &= ~TULIP_PROMISC;
2980 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
2981 if (sc->tulip_flags & TULIP_ALLMULTI) {
2982 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
2984 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
2987 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
2988 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
2990 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
2991 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
2993 ifq_set_oactive(&sc->tulip_if.if_snd);
2994 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
2995 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
2997 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
2998 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
2999 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3000 tulip_txput_setup(sc);
3002 sc->tulip_if.if_flags &= ~IFF_RUNNING;
3008 tulip_rx_intr(tulip_softc_t *sc)
3010 tulip_ringinfo_t *ri = &sc->tulip_rxinfo;
3011 struct ifnet *ifp = &sc->tulip_if;
3015 tulip_desc_t *eop = ri->ri_nextin;
3016 int total_len = 0, last_offset = 0;
3017 struct mbuf *ms = NULL, *me = NULL;
3020 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
3024 * If the TULIP has no descriptors, there can't be any receive
3025 * descriptors to process.
3027 if (eop == ri->ri_nextout)
3031 * 90% of the packets will fit in one descriptor. So we optimize
3034 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3035 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
3036 IF_DEQUEUE(&sc->tulip_rxq, ms);
3040 * If still owned by the TULIP, don't touch it.
3042 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
3046 * It is possible (though improbable unless the BIG_PACKET support
3047 * is enabled or MCLBYTES < 1518) for a received packet to cross
3048 * more than one receive descriptor.
3050 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) {
3051 if (++eop == ri->ri_last)
3053 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3054 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
3061 * Dequeue the first buffer for the start of the packet. Hopefully
3062 * this will be the only one we need to dequeue. However, if the
3063 * packet consumed multiple descriptors, then we need to dequeue
3064 * those buffers and chain to the starting mbuf. All buffers but
3065 * the last buffer have the same length so we can set that now.
3066 * (we add to last_offset instead of multiplying since we normally
3067 * won't go into the loop and thereby saving a ourselves from
3068 * doing a multiplication by 0 in the normal case).
3070 IF_DEQUEUE(&sc->tulip_rxq, ms);
3071 for (me = ms; total_len > 0; total_len--) {
3072 me->m_len = TULIP_RX_BUFLEN;
3073 last_offset += TULIP_RX_BUFLEN;
3074 IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
3080 * Now get the size of received packet (minus the CRC).
3082 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
3083 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
3084 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0
3086 || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) &&
3087 (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT|
3088 TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC|
3089 TULIP_DSTS_RxOVERFLOW)) == 0)
3092 me->m_len = total_len - last_offset;
3094 sc->tulip_flags |= TULIP_RXACT;
3097 IFNET_STAT_INC(ifp, ierrors, 1);
3098 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3099 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3101 if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
3102 sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
3104 if (eop->d_status & TULIP_DSTS_RxBADCRC) {
3105 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
3106 sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
3108 sc->tulip_dot3stats.dot3StatsFCSErrors++;
3113 IFNET_STAT_INC(ifp, ipackets, 1);
3114 if (++eop == ri->ri_last)
3116 ri->ri_nextin = eop;
3119 * Either we are priming the TULIP with mbufs (m == NULL)
3120 * or we are about to accept an mbuf for the upper layers
3121 * so we need to allocate an mbuf to replace it. If we
3122 * can't replace it, send up it anyways. This may cause
3123 * us to drop packets in the future but that's better than
3124 * being caught in livelock.
3126 * Note that if this packet crossed multiple descriptors
3127 * we don't even try to reallocate all the mbufs here.
3128 * Instead we rely on the test of the beginning of
3129 * the loop to refill for the extra consumed mbufs.
3131 if (accept || ms == NULL) {
3134 #if defined(TULIP_COPY_RXDATA)
3135 if (!accept || total_len >= (MHLEN - 2))
3136 m0 = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
3138 m0 = m_gethdr(MB_DONTWAIT, MT_DATA);
3140 m0 = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
3144 #if defined(TULIP_COPY_RXDATA)
3148 #if !defined(TULIP_COPY_RXDATA)
3149 ms->m_pkthdr.len = total_len;
3150 ifp->if_input(ifp, ms, NULL, -1);
3153 #error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
3155 m0->m_data += 2; /* align data after header */
3156 m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
3157 m0->m_len = m0->m_pkthdr.len = total_len;
3158 m0->m_pkthdr.rcvif = ifp;
3159 ifp->if_input(ifp, m0, NULL, -1);
3161 #endif /* ! TULIP_COPY_RXDATA */
3167 * Couldn't allocate a new buffer. Don't bother
3168 * trying to replenish the receive queue.
3171 sc->tulip_flags |= TULIP_RXBUFSLOW;
3175 * Now give the buffer(s) to the TULIP and save in our
3179 tulip_desc_t * const nextout = ri->ri_nextout;
3180 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
3181 nextout->d_length1 = TULIP_RX_BUFLEN;
3182 nextout->d_status = TULIP_DSTS_OWNER;
3183 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
3184 if (++ri->ri_nextout == ri->ri_last)
3185 ri->ri_nextout = ri->ri_first;
3188 IF_ENQUEUE(&sc->tulip_rxq, ms);
3189 } while ((ms = me) != NULL);
3191 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
3192 sc->tulip_flags &= ~TULIP_RXBUFSLOW;
3197 tulip_tx_intr(tulip_softc_t *sc)
3199 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3204 while (ri->ri_free < ri->ri_max) {
3207 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
3208 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
3213 d_flag = ri->ri_nextin->d_flag;
3214 if (d_flag & TULIP_DFLAG_TxLASTSEG) {
3215 if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
3217 * We've just finished processing a setup packet.
3218 * Mark that we finished it. If there's not
3219 * another pending, startup the TULIP receiver.
3220 * Make sure we ack the RXSTOPPED so we won't get
3221 * an abormal interrupt indication.
3223 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap);
3224 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
3225 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT)
3226 sc->tulip_flags |= TULIP_HASHONLY;
3227 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
3229 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3230 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3231 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3232 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3233 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3236 const uint32_t d_status = ri->ri_nextin->d_status;
3237 IF_DEQUEUE(&sc->tulip_txq, m);
3241 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3242 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
3243 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
3244 event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
3246 (*sc->tulip_boardsw->bd_media_poll)(sc, event);
3248 * Escape from the loop before media poll has reset the TULIP!
3253 if (d_status & TULIP_DSTS_ERRSUM) {
3254 IFNET_STAT_INC(&sc->tulip_if, oerrors, 1);
3255 if (d_status & TULIP_DSTS_TxEXCCOLL)
3256 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
3257 if (d_status & TULIP_DSTS_TxLATECOLL)
3258 sc->tulip_dot3stats.dot3StatsLateCollisions++;
3259 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
3260 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
3261 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
3262 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
3263 if (d_status & TULIP_DSTS_TxUNDERFLOW)
3264 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
3265 if (d_status & TULIP_DSTS_TxBABBLE)
3266 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
3268 u_int32_t collisions =
3269 (d_status & TULIP_DSTS_TxCOLLMASK)
3270 >> TULIP_DSTS_V_TxCOLLCNT;
3271 IFNET_STAT_INC(&sc->tulip_if, collisions, collisions);
3272 if (collisions == 1)
3273 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
3274 else if (collisions > 1)
3275 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
3276 else if (d_status & TULIP_DSTS_TxDEFERRED)
3277 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
3279 * SQE is only valid for 10baseT/BNC/AUI when not
3280 * running in full-duplex. In order to speed up the
3281 * test, the corresponding bit in tulip_flags needs to
3282 * set as well to get us to count SQE Test Errors.
3284 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
3285 sc->tulip_dot3stats.dot3StatsSQETestErrors++;
3291 if (++ri->ri_nextin == ri->ri_last)
3292 ri->ri_nextin = ri->ri_first;
3294 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3295 ifq_clr_oactive(&sc->tulip_if.if_snd);
3298 * If nothing left to transmit, disable the timer.
3299 * Else if progress, reset the timer back to 2 ticks.
3301 * XXX 2 bit field, TXTIMER is 4?
3303 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
3304 sc->tulip_txtimer = 0;
3306 sc->tulip_txtimer = (TULIP_TXTIMER & 3);
3307 IFNET_STAT_INC(&sc->tulip_if, opackets, xmits);
3312 tulip_print_abnormal_interrupt(tulip_softc_t *sc, uint32_t csr)
3314 const char * const *msgp = tulip_status_bits;
3317 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
3319 csr &= (1 << (NELEM(tulip_status_bits))) - 1;
3320 if_printf(&sc->tulip_if, "abnormal interrupt:");
3321 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
3322 if ((csr & mask) && *msgp != NULL) {
3323 kprintf("%s%s", sep, *msgp);
3324 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
3325 sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
3326 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
3327 kprintf(" (switching to store-and-forward mode)");
3329 kprintf(" (raising TX threshold to %s)",
3330 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
3340 tulip_intr_handler(tulip_softc_t *sc)
3344 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3345 TULIP_CSR_WRITE(sc, csr_status, csr);
3347 if (csr & TULIP_STS_SYSERROR) {
3348 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
3349 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3350 sc->tulip_flags |= TULIP_SYSTEMERROR;
3352 if_printf(&sc->tulip_if, "system error: %s\n",
3353 tulip_system_errors[sc->tulip_last_system_error]);
3355 sc->tulip_flags |= TULIP_NEEDRESET;
3356 sc->tulip_system_errors++;
3359 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
3360 if (sc->tulip_boardsw->bd_media_poll != NULL) {
3361 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
3362 ? TULIP_MEDIAPOLL_LINKFAIL
3363 : TULIP_MEDIAPOLL_LINKPASS);
3364 csr &= ~TULIP_STS_ABNRMLINTR;
3366 tulip_media_print(sc);
3368 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
3369 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
3370 if (csr & TULIP_STS_RXNOBUF)
3371 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
3373 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3374 * on receive overflows.
3376 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
3377 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3379 * Stop the receiver process and spin until it's stopped.
3380 * Tell rx_intr to drop the packets it dequeues.
3382 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
3383 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
3385 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3386 sc->tulip_flags |= TULIP_RXIGNORE;
3389 if (sc->tulip_flags & TULIP_RXIGNORE) {
3391 * Restart the receiver.
3393 sc->tulip_flags &= ~TULIP_RXIGNORE;
3394 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3397 if (csr & TULIP_STS_ABNRMLINTR) {
3398 u_int32_t tmp = csr & sc->tulip_intrmask
3399 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
3400 if (csr & TULIP_STS_TXUNDERFLOW) {
3401 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
3402 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
3403 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3404 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
3405 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
3406 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3409 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3410 sc->tulip_statusbits |= tmp;
3412 tulip_print_abnormal_interrupt(sc, tmp);
3413 sc->tulip_flags |= TULIP_NOMESSAGES;
3415 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3417 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
3419 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3420 if_devstart(&sc->tulip_if);
3423 if (sc->tulip_flags & TULIP_NEEDRESET) {
3430 tulip_intr_shared(void *arg)
3434 for (sc = arg; sc != NULL; sc = sc->tulip_slaves)
3435 tulip_intr_handler(sc);
3439 tulip_intr_normal(void *arg)
3441 tulip_softc_t *sc = (tulip_softc_t *)arg;
3443 tulip_intr_handler(sc);
3446 static struct mbuf *
3447 tulip_txput(tulip_softc_t *sc, struct mbuf *m)
3449 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3450 tulip_desc_t *eop, *nextout;
3456 * Now we try to fill in our transmit descriptors. This is
3457 * a bit reminiscent of going on the Ark two by two
3458 * since each descriptor for the TULIP can describe
3459 * two buffers. So we advance through packet filling
3460 * each of the two entries at a time to to fill each
3461 * descriptor. Clear the first and last segment bits
3462 * in each descriptor (actually just clear everything
3463 * but the end-of-ring or chain bits) to make sure
3464 * we don't get messed up by previously sent packets.
3466 * We may fail to put the entire packet on the ring if
3467 * there is either not enough ring entries free or if the
3468 * packet has more than MAX_TXSEG segments. In the former
3469 * case we will just wait for the ring to empty. In the
3470 * latter case we have to recopy.
3475 eop = nextout = ri->ri_nextout;
3480 int len = m0->m_len;
3481 caddr_t addr = mtod(m0, caddr_t);
3482 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1));
3485 unsigned slen = min(len, clsize);
3489 slen = 2040, partial = 1;
3492 if (segcnt > TULIP_MAX_TXSEG) {
3494 * The packet exceeds the number of transmit buffer
3495 * entries that we can use for one packet, so we have
3496 * recopy it into one mbuf and then try again.
3498 m0 = m_defrag(m, MB_DONTWAIT);
3507 * See if there's any unclaimed space in the
3510 if ((free += tulip_tx_intr(sc)) == 0) {
3512 * There's no more room but since nothing
3513 * has been committed at this point, just
3514 * show output is active, put back the
3517 sc->tulip_flags |= TULIP_WANTTXSTART;
3522 if (++nextout == ri->ri_last)
3523 nextout = ri->ri_first;
3524 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
3525 eop->d_status = d_status;
3526 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr);
3527 eop->d_length1 = slen;
3530 * Fill in second half of descriptor
3532 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr);
3533 eop->d_length2 = slen;
3535 d_status = TULIP_DSTS_OWNER;
3544 } while ((m0 = m0->m_next) != NULL);
3546 BPF_MTAP(&sc->tulip_if, m);
3549 * The descriptors have been filled in. Now get ready
3552 IF_ENQUEUE(&sc->tulip_txq, m);
3556 * Make sure the next descriptor after this packet is owned
3557 * by us since it may have been set up above if we ran out
3558 * of room in the ring.
3560 nextout->d_status = 0;
3561 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
3564 * If we only used the first segment of the last descriptor,
3565 * make sure the second segment will not be used.
3573 * Mark the last and first segments, indicate we want a transmit
3574 * complete interrupt, and tell it to transmit!
3576 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
3579 * Note that ri->ri_nextout is still the start of the packet
3580 * and until we set the OWNER bit, we can still back out of
3581 * everything we have done.
3583 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
3584 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
3585 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
3588 * This advances the ring for us.
3590 ri->ri_nextout = nextout;
3593 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3594 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3595 ifq_set_oactive(&sc->tulip_if.if_snd);
3596 sc->tulip_if.if_start = tulip_ifstart;
3601 * switch back to the single queueing ifstart.
3603 * XXX 2 bit field, TXTIMER is 4?
3605 sc->tulip_flags &= ~TULIP_WANTTXSTART;
3606 if (sc->tulip_txtimer == 0)
3607 sc->tulip_txtimer = TULIP_TXTIMER & 3;
3610 * If we want a txstart, there must be not enough space in the
3611 * transmit ring. So we want to enable transmit done interrupts
3612 * so we can immediately reclaim some space. When the transmit
3613 * interrupt is posted, the interrupt handler will call tx_intr
3614 * to reclaim space and then txstart (since WANTTXSTART is set).
3615 * txstart will move the packet into the transmit ring and clear
3616 * WANTTXSTART thereby causing TXINTR to be cleared.
3619 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
3620 ifq_set_oactive(&sc->tulip_if.if_snd);
3621 sc->tulip_if.if_start = tulip_ifstart;
3622 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
3623 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3624 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3626 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) {
3627 if (sc->tulip_intrmask & TULIP_STS_TXINTR) {
3628 sc->tulip_intrmask &= ~TULIP_STS_TXINTR;
3629 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3632 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3637 tulip_txput_setup(tulip_softc_t *sc)
3639 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3640 tulip_desc_t *nextout;
3643 * We will transmit, at most, one setup packet per call to ifstart.
3647 * Try to reclaim some free descriptors..
3649 if (ri->ri_free < 2)
3651 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
3652 sc->tulip_flags |= TULIP_WANTTXSTART;
3653 sc->tulip_if.if_start = tulip_ifstart;
3656 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
3657 sizeof(sc->tulip_setupbuf));
3659 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is
3660 * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
3662 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP;
3664 nextout = ri->ri_nextout;
3665 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
3666 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
3667 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
3668 if (sc->tulip_flags & TULIP_WANTHASHPERFECT)
3669 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
3670 else if (sc->tulip_flags & TULIP_WANTHASHONLY)
3671 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT;
3673 nextout->d_length2 = 0;
3674 nextout->d_addr2 = 0;
3675 nextout->d_length1 = sizeof(sc->tulip_setupbuf);
3676 nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
3679 * Advance the ring for the next transmit packet.
3681 if (++ri->ri_nextout == ri->ri_last)
3682 ri->ri_nextout = ri->ri_first;
3685 * Make sure the next descriptor is owned by us since it
3686 * may have been set up above if we ran out of room in the
3689 ri->ri_nextout->d_status = 0;
3690 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
3691 nextout->d_status = TULIP_DSTS_OWNER;
3693 * Flush the ownwership of the current descriptor
3695 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
3696 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3697 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
3698 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3699 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3704 tulip_ifioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred * cr)
3706 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
3707 struct ifreq *ifr = (struct ifreq *)data;
3712 bcopy((caddr_t) sc->tulip_enaddr,
3713 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
3718 case SIOCSIFFLAGS: {
3719 tulip_addr_filter(sc); /* reinit multicast filter */
3725 case SIOCGIFMEDIA: {
3726 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
3731 case SIOCDELMULTI: {
3733 * Update multicast listeners
3735 tulip_addr_filter(sc); /* reset multicast filtering */
3743 * Set the interface MTU.
3745 if (ifr->ifr_mtu > ETHERMTU
3747 && sc->tulip_chipid != TULIP_21140
3748 && sc->tulip_chipid != TULIP_21140A
3749 && sc->tulip_chipid != TULIP_21041
3755 ifp->if_mtu = ifr->ifr_mtu;
3763 case SIOCGADDRROM: {
3764 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
3770 ifr->ifr_metric = (int) sc->tulip_chipid;
3775 error = ether_ioctl(ifp, cmd, data);
3783 tulip_ifstart(struct ifnet *ifp, struct ifaltq_subque *ifsq)
3785 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
3787 ASSERT_ALTQ_SQ_DEFAULT(ifp, ifsq);
3788 if (sc->tulip_if.if_flags & IFF_RUNNING) {
3790 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3791 tulip_txput_setup(sc);
3793 while (!ifq_is_empty(&sc->tulip_if.if_snd)) {
3796 m = ifq_dequeue(&sc->tulip_if.if_snd);
3800 if ((m = tulip_txput(sc, m)) != NULL) {
3801 ifq_prepend(&sc->tulip_if.if_snd, m);
3809 tulip_ifwatchdog(struct ifnet *ifp)
3811 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
3813 sc->tulip_if.if_timer = 1;
3815 * These should be rare so do a bulk test up front so we can just skip
3818 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) {
3820 * If the number of receive buffer is low, try to refill
3822 if (sc->tulip_flags & TULIP_RXBUFSLOW)
3825 if (sc->tulip_flags & TULIP_SYSTEMERROR) {
3826 if_printf(ifp, "%d system errors: last was %s\n",
3827 sc->tulip_system_errors,
3828 tulip_system_errors[sc->tulip_last_system_error]);
3830 if (sc->tulip_statusbits) {
3831 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
3832 sc->tulip_statusbits = 0;
3835 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR);
3838 if (sc->tulip_txtimer)
3840 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
3841 if_printf(ifp, "transmission timeout\n");
3842 if (TULIP_DO_AUTOSENSE(sc)) {
3843 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
3844 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
3845 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP);
3853 tulip_attach(tulip_softc_t *sc)
3855 struct ifnet *ifp = &sc->tulip_if;
3857 callout_init(&sc->tulip_timer);
3858 callout_init(&sc->tulip_fast_timer);
3860 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
3861 ifp->if_ioctl = tulip_ifioctl;
3862 ifp->if_start = tulip_ifstart;
3863 ifp->if_watchdog = tulip_ifwatchdog;
3866 if_printf(ifp, "%s%s pass %d.%d%s\n",
3868 tulip_chipdescs[sc->tulip_chipid],
3869 (sc->tulip_revinfo & 0xF0) >> 4,
3870 sc->tulip_revinfo & 0x0F,
3871 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM))
3872 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "");
3874 (*sc->tulip_boardsw->bd_media_probe)(sc);
3875 ifmedia_init(&sc->tulip_ifmedia, 0,
3876 tulip_ifmedia_change,
3877 tulip_ifmedia_status);
3878 sc->tulip_flags &= ~TULIP_DEVICEPROBE;
3879 tulip_ifmedia_add(sc);
3881 ifq_set_maxlen(&ifp->if_snd, ifqmaxlen);
3882 ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr, NULL);
3888 tulip_detach(tulip_softc_t *sc)
3890 ifmedia_removeall(&sc->tulip_ifmedia);
3891 ether_ifdetach(&sc->tulip_if);
3895 tulip_initcsrs(tulip_softc_t *sc, tulip_csrptr_t csr_base, size_t csr_size)
3897 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
3898 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
3899 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
3900 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
3901 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
3902 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
3903 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
3904 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
3905 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size;
3906 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size;
3907 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size;
3908 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size;
3909 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size;
3910 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size;
3911 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
3912 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
3916 tulip_initring(tulip_softc_t *sc, tulip_ringinfo_t *ri, tulip_desc_t *descs,
3919 ri->ri_max = ndescs;
3920 ri->ri_first = descs;
3921 ri->ri_last = ri->ri_first + ri->ri_max;
3922 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
3923 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
3927 * This is the PCI configuration support.
3930 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
3931 #define PCI_CBMA 0x14 /* Configuration Base Memory Address */
3932 #define PCI_CFDA 0x40 /* Configuration Driver Area */
3935 tulip_pci_probe(device_t dev)
3937 const char *name = NULL;
3939 if (pci_get_vendor(dev) != DEC_VENDORID)
3943 * Some LanMedia WAN cards use the Tulip chip, but they have
3944 * their own driver, and we should not recognize them
3946 if (pci_get_subvendor(dev) == 0x1376)
3949 switch (pci_get_device(dev)) {
3951 name = "Digital 21040 Ethernet";
3954 name = "Digital 21041 Ethernet";
3957 if (pci_get_revid(dev) >= 0x20)
3958 name = "Digital 21140A Fast Ethernet";
3960 name = "Digital 21140 Fast Ethernet";
3963 if (pci_get_revid(dev) >= 0x20)
3964 name = "Digital 21143 Fast Ethernet";
3966 name = "Digital 21142 Fast Ethernet";
3970 device_set_desc(dev, name);
3977 tulip_shutdown(device_t dev)
3979 tulip_softc_t *sc = device_get_softc(dev);
3981 lwkt_serialize_enter(sc->tulip_if.if_serializer);
3982 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
3983 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
3984 33MHz that comes to two microseconds but wait a
3985 bit longer anyways) */
3986 lwkt_serialize_exit(sc->tulip_if.if_serializer);
3991 tulip_pci_attach(device_t dev)
3995 uint32_t revinfo, cfdainfo;
3996 u_int csroffset = TULIP_PCI_CSROFFSET;
3997 u_int csrsize = TULIP_PCI_CSRSIZE;
3998 tulip_csrptr_t csr_base;
3999 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
4000 struct resource *res;
4003 if (device_get_unit(dev) >= TULIP_MAX_DEVICES) {
4004 device_printf(dev, "not configured; limit of %d reached or exceeded\n",
4009 revinfo = pci_get_revid(dev);
4010 cfdainfo = pci_read_config(dev, PCI_CFDA, 4);
4012 /* turn busmaster on in case BIOS doesn't set it */
4013 pci_enable_busmaster(dev);
4015 if (pci_get_vendor(dev) == DEC_VENDORID) {
4016 if (pci_get_device(dev) == CHIPID_21040)
4017 chipid = TULIP_21040;
4018 else if (pci_get_device(dev) == CHIPID_21041)
4019 chipid = TULIP_21041;
4020 else if (pci_get_device(dev) == CHIPID_21140)
4021 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140;
4022 else if (pci_get_device(dev) == CHIPID_21142)
4023 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142;
4025 if (chipid == TULIP_CHIPID_UNKNOWN)
4028 if (chipid == TULIP_21040 && revinfo < 0x20) {
4029 device_printf(dev, "not configured; 21040 pass 2.0 required (%d.%d found)\n",
4030 revinfo >> 4, revinfo & 0x0f);
4032 } else if (chipid == TULIP_21140 && revinfo < 0x11) {
4033 device_printf(dev, "not configured; 21140 pass 1.1 required (%d.%d found)\n",
4034 revinfo >> 4, revinfo & 0x0f);
4038 sc = device_get_softc(dev);
4039 sc->tulip_dev = dev;
4040 sc->tulip_pci_busno = pci_get_bus(dev);
4041 sc->tulip_pci_devno = pci_get_slot(dev);
4042 sc->tulip_chipid = chipid;
4043 sc->tulip_flags |= TULIP_DEVICEPROBE;
4044 if (chipid == TULIP_21140 || chipid == TULIP_21140A)
4045 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD;
4046 if (chipid == TULIP_21140A && revinfo <= 0x22)
4047 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW;
4048 if (chipid == TULIP_21140)
4049 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH;
4050 if (chipid != TULIP_21040 && chipid != TULIP_21140)
4051 sc->tulip_features |= TULIP_HAVE_POWERMGMT;
4052 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) {
4053 sc->tulip_features |= TULIP_HAVE_DUALSENSE;
4054 if (chipid != TULIP_21041 || revinfo >= 0x20)
4055 sc->tulip_features |= TULIP_HAVE_SIANWAY;
4056 if (chipid != TULIP_21041)
4057 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD;
4058 if (chipid != TULIP_21041 && revinfo >= 0x20)
4059 sc->tulip_features |= TULIP_HAVE_SIA100;
4062 if (sc->tulip_features & TULIP_HAVE_POWERMGMT
4063 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) {
4064 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE);
4065 pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
4068 if_initname(&sc->tulip_if, device_get_name(dev), device_get_unit(dev));
4069 sc->tulip_revinfo = revinfo;
4070 sc->tulip_if.if_softc = sc;
4071 #if defined(TULIP_IOMAPPED)
4073 res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
4076 res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
4080 sc->tulip_csrs_bst = rman_get_bustag(res);
4081 sc->tulip_csrs_bsh = rman_get_bushandle(res);
4084 tulips[device_get_unit(dev)] = sc;
4086 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
4088 sc->tulip_rxdescs = kmalloc(sizeof(tulip_desc_t) * TULIP_RXDESCS,
4089 M_DEVBUF, M_INTWAIT);
4090 sc->tulip_txdescs = kmalloc(sizeof(tulip_desc_t) * TULIP_TXDESCS,
4091 M_DEVBUF, M_INTWAIT);
4093 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS);
4094 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS);
4097 * Make sure there won't be any interrupts or such...
4099 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4100 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
4101 33MHz that comes to two microseconds but wait a
4102 bit longer anyways) */
4104 if ((retval = tulip_read_macaddr(sc)) < 0) {
4105 device_printf(dev, "can't read ENET ROM (why=%d) (", retval);
4106 for (idx = 0; idx < 32; idx++)
4107 kprintf("%02x", sc->tulip_rombuf[idx]);
4109 device_printf(dev, "%s%s pass %d.%d\n",
4110 sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
4111 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
4112 device_printf(dev, "address unknown\n");
4114 void (*intr_rtn)(void *) = tulip_intr_normal;
4116 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
4117 intr_rtn = tulip_intr_shared;
4120 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) {
4124 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
4125 RF_SHAREABLE | RF_ACTIVE);
4126 if (res == NULL || bus_setup_intr(dev, res, INTR_MPSAFE,
4128 sc->tulip_if.if_serializer)) {
4129 device_printf(dev, "couldn't map interrupt\n");
4131 kfree((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
4132 kfree((caddr_t) sc->tulip_txdescs, M_DEVBUF);
4136 ifq_set_cpuid(&sc->tulip_if.if_snd, rman_get_cpuid(res));
4142 static device_method_t tulip_pci_methods[] = {
4143 /* Device interface */
4144 DEVMETHOD(device_probe, tulip_pci_probe),
4145 DEVMETHOD(device_attach, tulip_pci_attach),
4146 DEVMETHOD(device_shutdown, tulip_shutdown),
4149 static driver_t tulip_pci_driver = {
4152 sizeof(tulip_softc_t),
4154 static devclass_t tulip_devclass;
4156 DECLARE_DUMMY_MODULE(if_de);
4157 DRIVER_MODULE(if_de, pci, tulip_pci_driver, tulip_devclass, NULL, NULL);