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>
59 #include <net/if_media.h>
60 #include <net/if_dl.h>
61 #include <net/ifq_var.h>
65 #include <netinet/in.h>
66 #include <netinet/if_ether.h>
70 #include <netproto/ipx/ipx.h>
71 #include <netproto/ipx/ipx_if.h>
76 #include <net/if_var.h>
78 #include <bus/pci/pcivar.h>
79 #include <bus/pci/pcireg.h>
80 #include <dev/netif/de/dc21040reg.h>
83 * Intel CPUs should use I/O mapped access.
86 #define TULIP_IOMAPPED
93 static tulip_softc_t *tulips[TULIP_MAX_DEVICES];
96 * This module supports
97 * the DEC 21040 PCI Ethernet Controller.
98 * the DEC 21041 PCI Ethernet Controller.
99 * the DEC 21140 PCI Fast Ethernet Controller.
101 static void tulip_mii_autonegotiate(tulip_softc_t *, u_int);
102 static void tulip_intr_shared(void *);
103 static void tulip_intr_normal(void *);
104 static void tulip_init(tulip_softc_t *);
105 static void tulip_reset(tulip_softc_t *);
106 static void tulip_ifstart(struct ifnet *, struct ifaltq_subque *);
107 static struct mbuf *tulip_txput(tulip_softc_t *, struct mbuf *);
108 static void tulip_txput_setup(tulip_softc_t *);
109 static void tulip_rx_intr(tulip_softc_t *);
110 static void tulip_addr_filter(tulip_softc_t *);
111 static u_int tulip_mii_readreg(tulip_softc_t *, u_int, u_int);
112 static void tulip_mii_writereg(tulip_softc_t *, u_int, u_int, u_int);
113 static int tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities);
114 static tulip_media_t tulip_mii_phy_readspecific(tulip_softc_t *);
115 static int tulip_srom_decode(tulip_softc_t *);
116 static int tulip_ifmedia_change(struct ifnet *);
117 static void tulip_ifmedia_status(struct ifnet *, struct ifmediareq *);
118 /* static void tulip_21140_map_media(tulip_softc_t *sc); */
121 tulip_timeout_callback(void *arg)
123 tulip_softc_t *sc = arg;
125 lwkt_serialize_enter(sc->tulip_if.if_serializer);
126 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING;
127 sc->tulip_probe_timeout -= 1000 / TULIP_HZ;
128 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER);
129 lwkt_serialize_exit(sc->tulip_if.if_serializer);
133 tulip_timeout(tulip_softc_t *sc)
135 if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
137 sc->tulip_flags |= TULIP_TIMEOUTPENDING;
138 callout_reset(&sc->tulip_timer, (hz + TULIP_HZ / 2) / TULIP_HZ,
139 tulip_timeout_callback, sc);
143 tulip_txprobe(tulip_softc_t *sc)
148 * Before we are sure this is the right media we need
149 * to send a small packet to make sure there's carrier.
150 * Strangely, BNC and AUI will "see" receive data if
151 * either is connected so the transmit is the only way
152 * to verify the connectivity.
154 MGETHDR(m, MB_DONTWAIT, MT_DATA);
158 * Construct a LLC TEST message which will point to ourselves.
160 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_dhost, 6);
161 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_shost, 6);
162 mtod(m, struct ether_header *)->ether_type = htons(3);
163 mtod(m, unsigned char *)[14] = 0;
164 mtod(m, unsigned char *)[15] = 0;
165 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
166 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
170 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
171 sc->tulip_intrmask |= TULIP_STS_TXINTR;
172 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
173 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
174 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
175 if ((m = tulip_txput(sc, m)) != NULL)
177 sc->tulip_probe.probe_txprobes++;
182 #define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0)
184 #define TULIP_SIAGEN_WATCHDOG 0
188 tulip_media_set(tulip_softc_t *sc, tulip_media_t media)
190 const tulip_media_info_t *mi = sc->tulip_mediums[media];
196 * If we are switching media, make sure we don't think there's
197 * any stale RX activity
199 sc->tulip_flags &= ~TULIP_RXACT;
200 if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
201 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
202 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx);
203 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
204 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
206 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
208 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
210 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity);
211 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
212 #define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL)
214 * If the cmdmode bits don't match the currently operating mode,
215 * set the cmdmode appropriately and reset the chip.
217 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
218 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
219 sc->tulip_cmdmode |= mi->mi_cmdmode;
222 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
224 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata);
225 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
227 * If the cmdmode bits don't match the currently operating mode,
228 * set the cmdmode appropriately and reset the chip.
230 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
231 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
232 sc->tulip_cmdmode |= mi->mi_cmdmode;
235 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol);
236 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata);
237 } else if (mi->mi_type == TULIP_MEDIAINFO_MII
238 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) {
240 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
242 dp = &sc->tulip_rombuf[mi->mi_reset_offset];
243 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) {
245 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
247 sc->tulip_phyaddr = mi->mi_phyaddr;
248 dp = &sc->tulip_rombuf[mi->mi_gpr_offset];
249 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) {
251 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
254 for (idx = 0; idx < mi->mi_reset_length; idx++) {
256 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]);
258 sc->tulip_phyaddr = mi->mi_phyaddr;
259 for (idx = 0; idx < mi->mi_gpr_length; idx++) {
261 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]);
264 if (sc->tulip_flags & TULIP_TRYNWAY) {
265 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
266 } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
267 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL);
268 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE);
269 sc->tulip_flags &= ~TULIP_DIDNWAY;
270 if (TULIP_IS_MEDIA_FD(media))
271 data |= PHYCTL_FULL_DUPLEX;
272 if (TULIP_IS_MEDIA_100MB(media))
273 data |= PHYCTL_SELECT_100MB;
274 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data);
280 tulip_linkup(tulip_softc_t *sc, tulip_media_t media)
282 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
283 sc->tulip_flags |= TULIP_PRINTLINKUP;
284 sc->tulip_flags |= TULIP_LINKUP;
285 ifq_clr_oactive(&sc->tulip_if.if_snd);
286 #if 0 /* XXX how does with work with ifmedia? */
287 if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
288 if (sc->tulip_if.if_flags & IFF_FULLDUPLEX) {
289 if (TULIP_CAN_MEDIA_FD(media)
290 && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL)
291 media = TULIP_FD_MEDIA_OF(media);
293 if (TULIP_IS_MEDIA_FD(media)
294 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL)
295 media = TULIP_HD_MEDIA_OF(media);
299 if (sc->tulip_media != media) {
300 sc->tulip_media = media;
301 sc->tulip_flags |= TULIP_PRINTMEDIA;
302 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) {
303 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
304 } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) {
305 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
309 * We could set probe_timeout to 0 but setting to 3000 puts this
310 * in one central place and the only matters is tulip_link is
311 * followed by a tulip_timeout. Therefore setting it should not
312 * result in aberrant behavour.
314 sc->tulip_probe_timeout = 3000;
315 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
316 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY);
317 if (sc->tulip_flags & TULIP_INRESET) {
318 tulip_media_set(sc, sc->tulip_media);
319 } else if (sc->tulip_probe_media != sc->tulip_media) {
321 * No reason to change media if we have the right media.
329 tulip_media_print(tulip_softc_t *sc)
331 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
333 if (sc->tulip_flags & TULIP_PRINTMEDIA) {
334 if_printf(&sc->tulip_if, "enabling %s port\n",
335 tulip_mediums[sc->tulip_media]);
336 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
337 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
338 if_printf(&sc->tulip_if, "link up\n");
339 sc->tulip_flags &= ~TULIP_PRINTLINKUP;
343 #if defined(TULIP_DO_GPR_SENSE)
345 tulip_21140_gpr_media_sense(tulip_softc_t *sc)
347 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
348 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
352 * If one of the media blocks contained a default media flag,
355 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
356 const tulip_media_info_t *mi;
358 * Media is not supported (or is full-duplex).
360 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media))
362 if (mi->mi_type != TULIP_MEDIAINFO_GPR)
366 * Remember the media is this is the "default" media.
368 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
372 * No activity mask? Can't see if it is active if there's no mask.
374 if (mi->mi_actmask == 0)
378 * Does the activity data match?
380 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
384 * It does! If this is the first media we detected, then
385 * remember this media. If isn't the first, then there were
386 * multiple matches which we equate to no match (since we don't
387 * which to select (if any).
389 if (last_media == TULIP_MEDIA_UNKNOWN) {
391 } else if (last_media != media) {
392 last_media = TULIP_MEDIA_UNKNOWN;
395 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
397 #endif /* TULIP_DO_GPR_SENSE */
399 static tulip_link_status_t
400 tulip_media_link_monitor(tulip_softc_t *sc)
402 const tulip_media_info_t *mi = sc->tulip_mediums[sc->tulip_media];
403 tulip_link_status_t linkup = TULIP_LINK_DOWN;
406 #if defined(DIAGNOSTIC)
407 panic("tulip_media_link_monitor: %s: botch at line %d",
408 tulip_mediums[sc->tulip_media],__LINE__);
410 return TULIP_LINK_UNKNOWN;
415 * Have we seen some packets? If so, the link must be good.
417 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) {
418 sc->tulip_flags &= ~TULIP_RXACT;
419 sc->tulip_probe_timeout = 3000;
420 return TULIP_LINK_UP;
423 sc->tulip_flags &= ~TULIP_RXACT;
424 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
427 * Read the PHY status register.
429 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
430 if (status & PHYSTS_AUTONEG_DONE) {
432 * If the PHY has completed autonegotiation, see the if the
433 * remote systems abilities have changed. If so, upgrade or
434 * downgrade as appropriate.
436 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
437 abilities = (abilities << 6) & status;
438 if (abilities != sc->tulip_abilities) {
439 if (tulip_mii_map_abilities(sc, abilities)) {
440 tulip_linkup(sc, sc->tulip_probe_media);
441 return TULIP_LINK_UP;
444 * if we had selected media because of autonegotiation,
445 * we need to probe for the new media.
447 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
448 if (sc->tulip_flags & TULIP_DIDNWAY)
449 return TULIP_LINK_DOWN;
453 * The link is now up. If was down, say its back up.
455 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP)
456 linkup = TULIP_LINK_UP;
457 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
459 * No activity sensor? Assume all's well.
461 if (mi->mi_actmask == 0)
462 return TULIP_LINK_UNKNOWN;
464 * Does the activity data match?
466 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata)
467 linkup = TULIP_LINK_UP;
468 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
470 * Assume non TP ok for now.
472 if (!TULIP_IS_MEDIA_TP(sc->tulip_media))
473 return TULIP_LINK_UNKNOWN;
474 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
475 linkup = TULIP_LINK_UP;
476 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
477 return TULIP_LINK_UNKNOWN;
480 * We will wait for 3 seconds until the link goes into suspect mode.
482 if (sc->tulip_flags & TULIP_LINKUP) {
483 if (linkup == TULIP_LINK_UP)
484 sc->tulip_probe_timeout = 3000;
485 if (sc->tulip_probe_timeout > 0)
486 return TULIP_LINK_UP;
488 sc->tulip_flags &= ~TULIP_LINKUP;
489 if_printf(&sc->tulip_if, "link down: cable problem?\n");
491 return TULIP_LINK_DOWN;
495 tulip_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
497 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
498 && event == TULIP_MEDIAPOLL_TIMER) {
499 switch (tulip_media_link_monitor(sc)) {
500 case TULIP_LINK_DOWN: {
502 * Link Monitor failed. Probe for new media.
504 event = TULIP_MEDIAPOLL_LINKFAIL;
507 case TULIP_LINK_UP: {
514 case TULIP_LINK_UNKNOWN: {
516 * We can't tell so don't bother.
523 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
524 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
525 if (TULIP_DO_AUTOSENSE(sc)) {
526 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
527 if (sc->tulip_if.if_flags & IFF_UP)
528 tulip_reset(sc); /* restart probe */
534 if (event == TULIP_MEDIAPOLL_START) {
535 ifq_set_oactive(&sc->tulip_if.if_snd);
536 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
538 sc->tulip_probe_mediamask = 0;
539 sc->tulip_probe_passes = 0;
541 * If the SROM contained an explicit media to use, use it.
543 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX);
544 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS;
545 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
547 * connidx is defaulted to a media_unknown type.
549 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media;
550 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) {
551 tulip_linkup(sc, sc->tulip_probe_media);
556 if (sc->tulip_features & TULIP_HAVE_GPR) {
557 sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
558 sc->tulip_probe_timeout = 2000;
560 sc->tulip_probe_media = TULIP_MEDIA_MAX;
561 sc->tulip_probe_timeout = 0;
562 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
567 * Ignore txprobe failures or spurious callbacks.
569 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED
570 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) {
571 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
576 * If we really transmitted a packet, then that's the media we'll use.
578 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) {
579 if (event == TULIP_MEDIAPOLL_LINKPASS) {
580 /* XXX Check media status just to be sure */
581 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
583 tulip_linkup(sc, sc->tulip_probe_media);
588 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) {
589 #if defined(TULIP_DO_GPR_SENSE)
591 * Check for media via the general purpose register.
593 * Try to sense the media via the GPR. If the same value
594 * occurs 3 times in a row then just use that.
596 if (sc->tulip_probe_timeout > 0) {
597 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
598 if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
599 if (new_probe_media == sc->tulip_probe_media) {
600 if (--sc->tulip_probe_count == 0)
601 tulip_linkup(sc, sc->tulip_probe_media);
603 sc->tulip_probe_count = 10;
606 sc->tulip_probe_media = new_probe_media;
610 #endif /* TULIP_DO_GPR_SENSE */
612 * Brute force. We cycle through each of the media types
613 * and try to transmit a packet.
615 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
616 sc->tulip_probe_media = TULIP_MEDIA_MAX;
617 sc->tulip_probe_timeout = 0;
622 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST
623 && (sc->tulip_features & TULIP_HAVE_MII)) {
624 tulip_media_t old_media = sc->tulip_probe_media;
625 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
626 switch (sc->tulip_probe_state) {
627 case TULIP_PROBE_FAILED:
628 case TULIP_PROBE_MEDIATEST: {
630 * Try the next media.
632 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask;
633 sc->tulip_probe_timeout = 0;
635 if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
637 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
639 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
643 case TULIP_PROBE_PHYAUTONEG: {
646 case TULIP_PROBE_INACTIVE: {
648 * Only probe if we autonegotiated a media that hasn't failed.
650 sc->tulip_probe_timeout = 0;
651 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) {
652 sc->tulip_probe_media = old_media;
655 tulip_linkup(sc, sc->tulip_probe_media);
660 #if defined(DIAGNOSTIC)
661 panic("tulip_media_poll: botch at line %d", __LINE__);
668 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
669 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
674 * switch to another media if we tried this one enough.
676 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
678 * Find the next media type to check for. Full Duplex
679 * types are not allowed.
682 sc->tulip_probe_media -= 1;
683 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
684 if (++sc->tulip_probe_passes == 3) {
685 if_printf(&sc->tulip_if, "autosense failed: cable problem?\n");
686 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
687 sc->tulip_if.if_flags &= ~IFF_RUNNING;
688 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
692 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */
693 sc->tulip_probe_mediamask = 0;
694 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1;
696 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL
697 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
698 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
700 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
701 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
702 sc->tulip_probe.probe_txprobes = 0;
704 tulip_media_set(sc, sc->tulip_probe_media);
705 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
710 * If this is hanging off a phy, we know are doing NWAY and we have
711 * forced the phy to a specific speed. Wait for link up before
712 * before sending a packet.
714 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) {
715 case TULIP_MEDIAINFO_MII: {
716 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
720 case TULIP_MEDIAINFO_SIA: {
721 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) {
722 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL)
724 tulip_linkup(sc, sc->tulip_probe_media);
726 if (sc->tulip_features & TULIP_HAVE_MII)
733 case TULIP_MEDIAINFO_RESET:
734 case TULIP_MEDIAINFO_SYM:
735 case TULIP_MEDIAINFO_NONE:
736 case TULIP_MEDIAINFO_GPR: {
741 * Try to send a packet.
747 tulip_media_select(tulip_softc_t *sc)
749 if (sc->tulip_features & TULIP_HAVE_GPR) {
750 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
752 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata);
755 * If this board has no media, just return
757 if (sc->tulip_features & TULIP_HAVE_NOMEDIA)
760 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
761 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
762 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START);
764 tulip_media_set(sc, sc->tulip_media);
769 tulip_21040_mediainfo_init(tulip_softc_t *sc, tulip_media_t media)
771 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
772 |TULIP_CMD_BACKOFFCTR;
773 sc->tulip_if.if_baudrate = 10000000;
775 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) {
776 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET);
777 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD);
778 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
781 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) {
782 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC);
785 if (media == TULIP_MEDIA_UNKNOWN) {
786 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA);
791 tulip_21040_media_probe(tulip_softc_t *sc)
793 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
797 tulip_21040_10baset_only_media_probe(tulip_softc_t *sc)
799 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
800 tulip_media_set(sc, TULIP_MEDIA_10BASET);
801 sc->tulip_media = TULIP_MEDIA_10BASET;
805 tulip_21040_10baset_only_media_select(tulip_softc_t *sc)
807 sc->tulip_flags |= TULIP_LINKUP;
808 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
809 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
810 sc->tulip_flags &= ~TULIP_SQETEST;
812 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
813 sc->tulip_flags |= TULIP_SQETEST;
815 tulip_media_set(sc, sc->tulip_media);
819 tulip_21040_auibnc_only_media_probe(tulip_softc_t *sc)
821 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
822 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
823 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
824 sc->tulip_media = TULIP_MEDIA_AUIBNC;
828 tulip_21040_auibnc_only_media_select(tulip_softc_t *sc)
830 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
831 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
834 static const tulip_boardsw_t tulip_21040_boardsw = {
836 tulip_21040_media_probe,
841 static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = {
843 tulip_21040_10baset_only_media_probe,
844 tulip_21040_10baset_only_media_select,
848 static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = {
850 tulip_21040_auibnc_only_media_probe,
851 tulip_21040_auibnc_only_media_select,
856 tulip_21041_mediainfo_init(tulip_softc_t *sc)
858 tulip_media_info_t *mi = sc->tulip_mediainfo;
861 if (sc->tulip_revinfo >= 0x20) {
862 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET);
863 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD);
864 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI);
865 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC);
869 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET);
870 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD);
871 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
872 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
876 tulip_21041_media_probe(tulip_softc_t *sc)
878 sc->tulip_if.if_baudrate = 10000000;
879 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
880 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
881 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
882 tulip_21041_mediainfo_init(sc);
886 tulip_21041_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
890 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
891 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
892 || !TULIP_DO_AUTOSENSE(sc))
894 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
895 tulip_reset(sc); /* start probe */
900 * If we've been been asked to start a poll or link change interrupt
901 * restart the probe (and reset the tulip to a known state).
903 if (event == TULIP_MEDIAPOLL_START) {
904 ifq_set_oactive(&sc->tulip_if.if_snd);
905 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN);
907 if (sc->tulip_revinfo >= 0x20) {
908 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
909 sc->tulip_flags |= TULIP_DIDNWAY;
912 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
913 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
914 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
915 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT;
916 tulip_media_set(sc, TULIP_MEDIA_10BASET);
921 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
924 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
925 tulip_linkup(sc, sc->tulip_probe_media);
929 sia_status = TULIP_CSR_READ(sc, csr_sia_status);
930 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status);
931 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) {
932 if (sc->tulip_revinfo >= 0x20) {
933 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6)))
934 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
937 * If the link has passed LinkPass, 10baseT is the
938 * proper media to use.
940 tulip_linkup(sc, sc->tulip_probe_media);
945 * wait for up to 2.4 seconds for the link to reach pass state.
946 * Only then start scanning the other media for activity.
947 * choose media with receive activity over those without.
949 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) {
950 if (event != TULIP_MEDIAPOLL_TIMER)
952 if (sc->tulip_probe_timeout > 0
953 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
957 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
958 sc->tulip_flags |= TULIP_WANTRXACT;
959 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) {
960 sc->tulip_probe_media = TULIP_MEDIA_BNC;
962 sc->tulip_probe_media = TULIP_MEDIA_AUI;
964 tulip_media_set(sc, sc->tulip_probe_media);
970 * If we failed, clear the txprobe active flag.
972 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED)
973 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
976 if (event == TULIP_MEDIAPOLL_TIMER) {
978 * If we've received something, then that's our link!
980 if (sc->tulip_flags & TULIP_RXACT) {
981 tulip_linkup(sc, sc->tulip_probe_media);
985 * if no txprobe active
987 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0
988 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0
989 || (sia_status & TULIP_SIASTS_RXACTIVITY))) {
990 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
996 * Take 2 passes through before deciding to not
997 * wait for receive activity. Then take another
998 * two passes before spitting out a warning.
1000 if (sc->tulip_probe_timeout <= 0) {
1001 if (sc->tulip_flags & TULIP_WANTRXACT) {
1002 sc->tulip_flags &= ~TULIP_WANTRXACT;
1003 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1005 if_printf(&sc->tulip_if, "autosense failed: cable problem?\n");
1006 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
1007 sc->tulip_if.if_flags &= ~IFF_RUNNING;
1008 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1016 * Since this media failed to probe, try the other one.
1018 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1019 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) {
1020 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1022 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1024 tulip_media_set(sc, sc->tulip_probe_media);
1025 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1029 static const tulip_boardsw_t tulip_21041_boardsw = {
1030 TULIP_21041_GENERIC,
1031 tulip_21041_media_probe,
1033 tulip_21041_media_poll
1036 static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
1037 { 0x20005c00, 0, /* 08-00-17 */
1039 { 0x19, 0x0040, 0x0040 }, /* 10TX */
1040 { 0x19, 0x0040, 0x0000 }, /* 100TX */
1043 { 0x0281F400, 0, /* 00-A0-7D */
1045 { 0x12, 0x0010, 0x0000 }, /* 10T */
1047 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1048 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1052 { 0x0015F420, 0, /* 00-A0-7D */
1054 { 0x12, 0x0010, 0x0000 }, /* 10T */
1056 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1057 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1061 { 0x0281F400, 0, /* 00-A0-BE */
1063 { 0x11, 0x8000, 0x0000 }, /* 10T */
1064 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1066 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1072 static tulip_media_t
1073 tulip_mii_phy_readspecific(tulip_softc_t *sc)
1075 const tulip_phy_attr_t *attr;
1079 static const tulip_media_t table[] = {
1080 TULIP_MEDIA_UNKNOWN,
1081 TULIP_MEDIA_10BASET,
1082 TULIP_MEDIA_100BASETX,
1083 TULIP_MEDIA_100BASET4,
1084 TULIP_MEDIA_UNKNOWN,
1085 TULIP_MEDIA_10BASET_FD,
1086 TULIP_MEDIA_100BASETX_FD,
1091 * Don't read phy specific registers if link is not up.
1093 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
1094 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS))
1095 return TULIP_MEDIA_UNKNOWN;
1097 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) |
1098 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH);
1099 for (attr = tulip_mii_phy_attrlist;; attr++) {
1100 if (attr->attr_id == 0)
1101 return TULIP_MEDIA_UNKNOWN;
1102 if ((id & ~0x0F) == attr->attr_id)
1106 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
1107 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_100TX];
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_100T4].pm_regno) {
1113 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_100T4];
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_10T].pm_regno) {
1119 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_10T];
1120 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1121 if ((data & pm->pm_mask) == pm->pm_value)
1124 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) {
1125 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
1126 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1127 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
1133 tulip_mii_get_phyaddr(tulip_softc_t *sc, u_int offset)
1137 for (phyaddr = 1; phyaddr < 32; phyaddr++) {
1138 u_int status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1139 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1146 u_int status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
1147 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1148 return TULIP_MII_NOPHY;
1151 return TULIP_MII_NOPHY;
1155 tulip_mii_map_abilities(tulip_softc_t *sc, u_int abilities)
1157 sc->tulip_abilities = abilities;
1158 if (abilities & PHYSTS_100BASETX_FD) {
1159 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD;
1160 } else if (abilities & PHYSTS_100BASET4) {
1161 sc->tulip_probe_media = TULIP_MEDIA_100BASET4;
1162 } else if (abilities & PHYSTS_100BASETX) {
1163 sc->tulip_probe_media = TULIP_MEDIA_100BASETX;
1164 } else if (abilities & PHYSTS_10BASET_FD) {
1165 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1166 } else if (abilities & PHYSTS_10BASET) {
1167 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1169 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1172 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1177 tulip_mii_autonegotiate(tulip_softc_t *sc, u_int phyaddr)
1179 switch (sc->tulip_probe_state) {
1180 case TULIP_PROBE_MEDIATEST:
1181 case TULIP_PROBE_INACTIVE: {
1182 sc->tulip_flags |= TULIP_DIDNWAY;
1183 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET);
1184 sc->tulip_probe_timeout = 3000;
1185 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR;
1186 sc->tulip_probe_state = TULIP_PROBE_PHYRESET;
1189 case TULIP_PROBE_PHYRESET: {
1191 uint32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1192 if (data & PHYCTL_RESET) {
1193 if (sc->tulip_probe_timeout > 0) {
1197 if_printf(&sc->tulip_if,
1198 "(phy%d): error: reset of PHY never completed!\n", phyaddr);
1199 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1200 sc->tulip_probe_state = TULIP_PROBE_FAILED;
1201 sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
1204 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1205 if ((status & PHYSTS_CAN_AUTONEG) == 0) {
1206 sc->tulip_flags &= ~TULIP_DIDNWAY;
1207 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1210 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01))
1211 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
1212 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
1213 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1214 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
1215 sc->tulip_probe_timeout = 3000;
1218 case TULIP_PROBE_PHYAUTONEG: {
1219 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1221 if ((status & PHYSTS_AUTONEG_DONE) == 0) {
1222 if (sc->tulip_probe_timeout > 0) {
1226 sc->tulip_flags &= ~TULIP_DIDNWAY;
1227 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1230 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
1231 data = (data << 6) & status;
1232 if (!tulip_mii_map_abilities(sc, data))
1233 sc->tulip_flags &= ~TULIP_DIDNWAY;
1237 #if defined(DIAGNOSTIC)
1238 panic("tulip_media_poll: botch at line %d", __LINE__);
1246 tulip_2114x_media_preset(tulip_softc_t *sc)
1248 const tulip_media_info_t *mi = NULL;
1249 tulip_media_t media;
1251 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1252 media = sc->tulip_media;
1254 media = sc->tulip_probe_media;
1256 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
1257 sc->tulip_flags &= ~TULIP_SQETEST;
1258 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
1259 mi = sc->tulip_mediums[media];
1260 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
1261 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1262 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR
1263 || mi->mi_type == TULIP_MEDIAINFO_SYM) {
1264 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
1265 sc->tulip_cmdmode |= mi->mi_cmdmode;
1266 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
1267 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
1271 case TULIP_MEDIA_BNC:
1272 case TULIP_MEDIA_AUI:
1273 case TULIP_MEDIA_10BASET: {
1274 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1275 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
1276 sc->tulip_if.if_baudrate = 10000000;
1277 sc->tulip_flags |= TULIP_SQETEST;
1280 case TULIP_MEDIA_10BASET_FD: {
1281 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
1282 sc->tulip_if.if_baudrate = 10000000;
1285 case TULIP_MEDIA_100BASEFX:
1286 case TULIP_MEDIA_100BASET4:
1287 case TULIP_MEDIA_100BASETX: {
1288 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL);
1289 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1290 sc->tulip_if.if_baudrate = 100000000;
1293 case TULIP_MEDIA_100BASEFX_FD:
1294 case TULIP_MEDIA_100BASETX_FD: {
1295 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT;
1296 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
1297 sc->tulip_if.if_baudrate = 100000000;
1304 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1308 ********************************************************************
1309 * Start of 21140/21140A support which does not use the MII interface
1313 tulip_null_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
1315 #if defined(DIAGNOSTIC)
1316 if_printf(&sc->tulip_if, "botch(media_poll) at line %d\n", __LINE__);
1321 tulip_21140_mediainit(tulip_softc_t *sc, tulip_media_info_t *mip,
1322 tulip_media_t media, u_int gpdata, u_int cmdmode)
1324 sc->tulip_mediums[media] = mip;
1325 mip->mi_type = TULIP_MEDIAINFO_GPR;
1326 mip->mi_cmdmode = cmdmode;
1327 mip->mi_gpdata = gpdata;
1331 tulip_21140_evalboard_media_probe(tulip_softc_t *sc)
1333 tulip_media_info_t *mip = sc->tulip_mediainfo;
1335 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1336 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1337 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1338 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1339 TULIP_CSR_WRITE(sc, csr_command,
1340 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1341 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1342 TULIP_CSR_WRITE(sc, csr_command,
1343 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1345 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
1346 sc->tulip_media = TULIP_MEDIA_10BASET;
1348 sc->tulip_media = TULIP_MEDIA_100BASETX;
1350 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1352 TULIP_CMD_TXTHRSHLDCTL);
1353 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1355 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1356 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1358 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1359 |TULIP_CMD_SCRAMBLER);
1360 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1362 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1363 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1366 static const tulip_boardsw_t tulip_21140_eb_boardsw = {
1368 tulip_21140_evalboard_media_probe,
1370 tulip_null_media_poll,
1371 tulip_2114x_media_preset,
1375 tulip_21140_accton_media_probe(tulip_softc_t *sc)
1377 tulip_media_info_t *mip = sc->tulip_mediainfo;
1380 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1381 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1382 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1383 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1384 TULIP_CSR_WRITE(sc, csr_command,
1385 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1386 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1387 TULIP_CSR_WRITE(sc, csr_command,
1388 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1390 gpdata = TULIP_CSR_READ(sc, csr_gp);
1391 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) {
1392 sc->tulip_media = TULIP_MEDIA_10BASET;
1394 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) {
1395 sc->tulip_media = TULIP_MEDIA_BNC;
1397 sc->tulip_media = TULIP_MEDIA_100BASETX;
1400 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC,
1401 TULIP_GP_EN1207_BNC_INIT,
1402 TULIP_CMD_TXTHRSHLDCTL);
1403 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1404 TULIP_GP_EN1207_UTP_INIT,
1405 TULIP_CMD_TXTHRSHLDCTL);
1406 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1407 TULIP_GP_EN1207_UTP_INIT,
1408 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1409 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1410 TULIP_GP_EN1207_100_INIT,
1411 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1412 |TULIP_CMD_SCRAMBLER);
1413 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1414 TULIP_GP_EN1207_100_INIT,
1415 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1416 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1419 static const tulip_boardsw_t tulip_21140_accton_boardsw = {
1421 tulip_21140_accton_media_probe,
1423 tulip_null_media_poll,
1424 tulip_2114x_media_preset,
1428 tulip_21140_smc9332_media_probe(tulip_softc_t *sc)
1430 tulip_media_info_t *mip = sc->tulip_mediainfo;
1433 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE);
1434 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
1435 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
1436 33MHz that comes to two microseconds but wait a
1437 bit longer anyways) */
1438 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT |
1439 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1440 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS;
1441 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT;
1442 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET);
1443 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT);
1445 for (idx = 1000; idx > 0; idx--) {
1446 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1447 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) {
1450 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
1457 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1458 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1459 TULIP_GP_SMC_9332_INIT,
1460 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1461 |TULIP_CMD_SCRAMBLER);
1462 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1463 TULIP_GP_SMC_9332_INIT,
1464 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1465 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1466 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1467 TULIP_GP_SMC_9332_INIT,
1468 TULIP_CMD_TXTHRSHLDCTL);
1469 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1470 TULIP_GP_SMC_9332_INIT,
1471 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1474 static const tulip_boardsw_t tulip_21140_smc9332_boardsw = {
1475 TULIP_21140_SMC_9332,
1476 tulip_21140_smc9332_media_probe,
1478 tulip_null_media_poll,
1479 tulip_2114x_media_preset,
1483 tulip_21140_cogent_em100_media_probe(tulip_softc_t *sc)
1485 tulip_media_info_t *mip = sc->tulip_mediainfo;
1488 sc->tulip_gpinit = TULIP_GP_EM100_PINS;
1489 sc->tulip_gpdata = TULIP_GP_EM100_INIT;
1490 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS);
1491 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT);
1493 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE;
1494 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER);
1495 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1496 TULIP_CSR_WRITE(sc, csr_command, cmdmode);
1497 sc->tulip_media = TULIP_MEDIA_100BASEFX;
1499 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX,
1500 TULIP_GP_EM100_INIT,
1501 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION);
1502 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD,
1503 TULIP_GP_EM100_INIT,
1504 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1505 |TULIP_CMD_FULLDUPLEX);
1507 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);
1508 sc->tulip_media = TULIP_MEDIA_100BASETX;
1509 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1510 TULIP_GP_EM100_INIT,
1511 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1512 |TULIP_CMD_SCRAMBLER);
1513 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1514 TULIP_GP_EM100_INIT,
1515 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1516 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1520 static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {
1521 TULIP_21140_COGENT_EM100,
1522 tulip_21140_cogent_em100_media_probe,
1524 tulip_null_media_poll,
1525 tulip_2114x_media_preset
1529 tulip_21140_znyx_zx34x_media_probe(tulip_softc_t *sc)
1531 tulip_media_info_t *mip = sc->tulip_mediainfo;
1532 int cnt10 = 0, cnt100 = 0, idx;
1534 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS;
1535 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT;
1536 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS);
1537 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT);
1538 TULIP_CSR_WRITE(sc, csr_command,
1539 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1540 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1541 TULIP_CSR_WRITE(sc, csr_command,
1542 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1545 for (idx = 1000; idx > 0; idx--) {
1546 uint32_t csr = TULIP_CSR_READ(sc, csr_gp);
1547 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)) {
1550 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
1559 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1560 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1561 TULIP_GP_ZX34X_INIT,
1562 TULIP_CMD_TXTHRSHLDCTL);
1563 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1564 TULIP_GP_ZX34X_INIT,
1565 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1566 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1567 TULIP_GP_ZX34X_INIT,
1568 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1569 |TULIP_CMD_SCRAMBLER);
1570 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1571 TULIP_GP_ZX34X_INIT,
1572 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1573 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1576 static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = {
1577 TULIP_21140_ZNYX_ZX34X,
1578 tulip_21140_znyx_zx34x_media_probe,
1580 tulip_null_media_poll,
1581 tulip_2114x_media_preset,
1585 tulip_2114x_media_probe(tulip_softc_t *sc)
1587 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE | TULIP_CMD_BACKOFFCTR |
1588 TULIP_CMD_THRSHLD72;
1591 static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
1593 tulip_2114x_media_probe,
1596 tulip_2114x_media_preset,
1600 * ******** END of chip-specific handlers. ***********
1604 * Code the read the SROM and MII bit streams (I2C)
1607 TULIP_CSR_WRITE(sc, csr_srom_mii, csr); \
1612 tulip_srom_idle(tulip_softc_t *sc)
1616 csr = SROMSEL ; EMIT;
1617 csr = SROMSEL | SROMRD; EMIT;
1618 csr ^= SROMCS; EMIT;
1619 csr ^= SROMCLKON; EMIT;
1622 * Write 25 cycles of 0 which will force the SROM to be idle.
1624 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1625 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1626 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1628 csr ^= SROMCLKOFF; EMIT;
1629 csr ^= SROMCS; EMIT;
1635 tulip_srom_read(tulip_softc_t *sc)
1637 const u_int bitwidth = SROM_BITWIDTH;
1638 const u_int cmdmask = (SROMCMD_RD << bitwidth);
1639 const u_int msb = 1 << (bitwidth + 3 - 1);
1640 u_int idx, lastidx = (1 << bitwidth) - 1;
1642 tulip_srom_idle(sc);
1644 for (idx = 0; idx <= lastidx; idx++) {
1645 u_int lastbit, data, bits, bit, csr;
1646 csr = SROMSEL ; EMIT;
1647 csr = SROMSEL | SROMRD; EMIT;
1648 csr ^= SROMCSON; EMIT;
1649 csr ^= SROMCLKON; EMIT;
1652 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
1653 u_int thisbit = bits & msb;
1654 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1655 if (thisbit != lastbit) {
1656 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1660 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1663 csr ^= SROMCLKOFF; EMIT;
1665 for (data = 0, bits = 0; bits < 16; bits++) {
1667 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1668 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1669 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1671 sc->tulip_rombuf[idx*2] = data & 0xFF;
1672 sc->tulip_rombuf[idx*2+1] = data >> 8;
1673 csr = SROMSEL | SROMRD; EMIT;
1676 tulip_srom_idle(sc);
1679 #define MII_EMIT do { \
1680 TULIP_CSR_WRITE(sc, csr_srom_mii, csr); \
1685 tulip_mii_writebits(tulip_softc_t *sc, u_int data, u_int bits)
1687 u_int csr, msb, lastbit;
1689 msb = 1 << (bits - 1);
1690 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1691 lastbit = (csr & MII_DOUT) ? msb : 0;
1692 csr |= MII_WR; MII_EMIT; /* clock low; assert write */
1694 for (; bits > 0; bits--, data <<= 1) {
1695 const unsigned thisbit = data & msb;
1696 if (thisbit != lastbit) {
1697 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */
1699 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1701 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1706 tulip_mii_turnaround(tulip_softc_t *sc, u_int cmd)
1710 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1712 if (cmd == MII_WRCMD) {
1713 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
1714 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1715 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1716 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */
1718 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */
1720 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1721 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1725 tulip_mii_readbits(tulip_softc_t *sc)
1727 u_int csr, data, idx;
1729 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1731 for (idx = 0, data = 0; idx < 16; idx++) {
1732 data <<= 1; /* this is NOOP on the first pass through */
1733 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1734 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)
1736 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1738 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
1744 tulip_mii_readreg(tulip_softc_t *sc, u_int devaddr, u_int regno)
1749 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1750 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1751 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1752 tulip_mii_writebits(sc, MII_RDCMD, 8);
1753 tulip_mii_writebits(sc, devaddr, 5);
1754 tulip_mii_writebits(sc, regno, 5);
1755 tulip_mii_turnaround(sc, MII_RDCMD);
1757 data = tulip_mii_readbits(sc);
1762 tulip_mii_writereg(tulip_softc_t *sc, u_int devaddr, u_int regno, u_int data)
1766 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1767 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1768 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1769 tulip_mii_writebits(sc, MII_WRCMD, 8);
1770 tulip_mii_writebits(sc, devaddr, 5);
1771 tulip_mii_writebits(sc, regno, 5);
1772 tulip_mii_turnaround(sc, MII_WRCMD);
1773 tulip_mii_writebits(sc, data, 16);
1776 #define tulip_mchash(mca) (ether_crc32_le(mca, 6) & 0x1FF)
1777 #define tulip_srom_crcok(databuf) ( \
1778 ((ether_crc32_le(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
1779 ((databuf)[126] | ((databuf)[127] << 8)))
1782 tulip_identify_dec_nic(tulip_softc_t *sc)
1784 strcpy(sc->tulip_boardid, "DEC ");
1786 if (sc->tulip_chipid <= TULIP_21040)
1788 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0
1789 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {
1790 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);
1791 sc->tulip_boardid[D0+8] = ' ';
1797 tulip_identify_znyx_nic(tulip_softc_t * const sc)
1800 strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
1801 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
1803 sc->tulip_boardid[8] = '4';
1804 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
1805 if (znyx_ptr < 26 || znyx_ptr > 116) {
1806 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1809 /* ZX344 = 0010 .. 0013FF
1811 if (sc->tulip_rombuf[znyx_ptr] == 0x4A
1812 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52
1813 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) {
1814 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4];
1815 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) {
1816 sc->tulip_boardid[9] = '2';
1817 if (id == TULIP_ZNYX_ID_ZX342B) {
1818 sc->tulip_boardid[10] = 'B';
1819 sc->tulip_boardid[11] = ' ';
1821 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1822 } else if (id == TULIP_ZNYX_ID_ZX344) {
1823 sc->tulip_boardid[10] = '4';
1824 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1825 } else if (id == TULIP_ZNYX_ID_ZX345) {
1826 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5';
1827 } else if (id == TULIP_ZNYX_ID_ZX346) {
1828 sc->tulip_boardid[9] = '6';
1829 } else if (id == TULIP_ZNYX_ID_ZX351) {
1830 sc->tulip_boardid[8] = '5';
1831 sc->tulip_boardid[9] = '1';
1836 * Assume it's a ZX342...
1838 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1842 sc->tulip_boardid[8] = '1';
1843 if (sc->tulip_chipid == TULIP_21041) {
1844 sc->tulip_boardid[10] = '1';
1847 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) {
1848 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36];
1849 if (id == TULIP_ZNYX_ID_ZX312T) {
1850 sc->tulip_boardid[9] = '2';
1851 sc->tulip_boardid[10] = 'T';
1852 sc->tulip_boardid[11] = ' ';
1853 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1854 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) {
1855 sc->tulip_boardid[9] = '4';
1856 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1857 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1858 } else if (id == TULIP_ZNYX_ID_ZX314) {
1859 sc->tulip_boardid[9] = '4';
1860 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1861 sc->tulip_features |= TULIP_HAVE_BASEROM;
1862 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) {
1863 sc->tulip_boardid[9] = '5';
1864 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1865 } else if (id == TULIP_ZNYX_ID_ZX315) {
1866 sc->tulip_boardid[9] = '5';
1867 sc->tulip_features |= TULIP_HAVE_BASEROM;
1873 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) {
1874 sc->tulip_boardid[9] = '4';
1875 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1876 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1877 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) {
1878 sc->tulip_boardid[9] = '5';
1879 sc->tulip_boardsw = &tulip_21040_boardsw;
1880 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1881 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) {
1882 sc->tulip_boardid[9] = '2';
1883 sc->tulip_boardsw = &tulip_21040_boardsw;
1889 tulip_identify_smc_nic(tulip_softc_t * const sc)
1891 uint32_t id1, id2, ei;
1892 int auibnc = 0, utp = 0;
1895 strcpy(sc->tulip_boardid, "SMC ");
1896 if (sc->tulip_chipid == TULIP_21041)
1898 if (sc->tulip_chipid != TULIP_21040) {
1899 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
1900 strcpy(&sc->tulip_boardid[4], "9332DST ");
1901 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;
1902 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {
1903 strcpy(&sc->tulip_boardid[4], "9334BDT ");
1905 strcpy(&sc->tulip_boardid[4], "9332BDT ");
1909 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);
1910 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);
1911 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);
1913 strcpy(&sc->tulip_boardid[4], "8432");
1914 cp = &sc->tulip_boardid[8];
1916 *cp++ = 'B', auibnc = 1;
1917 if ((id1 & 0xFF) > 0x32)
1918 *cp++ = 'T', utp = 1;
1919 if ((id1 & 0x4000) == 0)
1920 *cp++ = 'A', auibnc = 1;
1922 sc->tulip_boardid[7] = '4';
1926 *cp++ = (ei ? '2' : '1');
1931 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1932 else if (!utp && auibnc)
1933 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
1937 tulip_identify_cogent_nic(tulip_softc_t * const sc)
1939 strcpy(sc->tulip_boardid, "Cogent ");
1940 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
1941 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {
1942 strcat(sc->tulip_boardid, "EM100TX ");
1943 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1944 #if defined(TULIP_COGENT_EM110TX_ID)
1945 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {
1946 strcat(sc->tulip_boardid, "EM110TX ");
1947 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1949 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1950 strcat(sc->tulip_boardid, "EM100FX ");
1951 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1954 * Magic number (0x24001109U) is the SubVendor (0x2400) and
1955 * SubDevId (0x1109) for the ANA6944TX (EM440TX).
1957 if (*(uint32_t *) sc->tulip_rombuf == 0x24001109U
1958 && (sc->tulip_features & TULIP_HAVE_BASEROM)) {
1960 * Cogent (Adaptec) is still mapping all INTs to INTA of
1961 * first 21140. Dumb! Dumb!
1963 strcat(sc->tulip_boardid, "EM440TX ");
1964 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
1966 } else if (sc->tulip_chipid == TULIP_21040) {
1967 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1972 tulip_identify_accton_nic(tulip_softc_t * const sc)
1974 strcpy(sc->tulip_boardid, "ACCTON ");
1975 switch (sc->tulip_chipid) {
1977 strcat(sc->tulip_boardid, "EN1207 ");
1978 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
1979 sc->tulip_boardsw = &tulip_21140_accton_boardsw;
1982 strcat(sc->tulip_boardid, "EN1207TX ");
1983 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
1984 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
1987 strcat(sc->tulip_boardid, "EN1203 ");
1988 sc->tulip_boardsw = &tulip_21040_boardsw;
1991 strcat(sc->tulip_boardid, "EN1203 ");
1992 sc->tulip_boardsw = &tulip_21041_boardsw;
1995 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2001 tulip_identify_asante_nic(tulip_softc_t * const sc)
2003 strcpy(sc->tulip_boardid, "Asante ");
2004 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
2005 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2006 tulip_media_info_t *mi = sc->tulip_mediainfo;
2009 * The Asante Fast Ethernet doesn't always ship with a valid
2010 * new format SROM. So if isn't in the new format, we cheat
2011 * set it up as if we had.
2014 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;
2015 sc->tulip_gpdata = 0;
2017 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);
2018 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);
2020 TULIP_CSR_WRITE(sc, csr_gp, 0);
2022 mi->mi_type = TULIP_MEDIAINFO_MII;
2023 mi->mi_gpr_length = 0;
2024 mi->mi_gpr_offset = 0;
2025 mi->mi_reset_length = 0;
2026 mi->mi_reset_offset = 0;
2028 mi->mi_phyaddr = TULIP_MII_NOPHY;
2029 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) {
2031 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
2033 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2034 if_printf(&sc->tulip_if, "can't find phy 0\n");
2038 sc->tulip_features |= TULIP_HAVE_MII;
2039 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2040 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2041 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD;
2042 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD;
2043 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2044 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2045 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2046 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2047 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2048 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2049 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2051 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2056 tulip_identify_compex_nic(tulip_softc_t *sc)
2058 strcpy(sc->tulip_boardid, "COMPEX ");
2059 if (sc->tulip_chipid == TULIP_21140A) {
2061 tulip_softc_t *root_sc = NULL;
2063 strcat(sc->tulip_boardid, "400TX/PCI ");
2065 * All 4 chips on these boards share an interrupt. This code
2066 * copied from tulip_read_macaddr.
2068 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2069 for (root_unit = device_get_unit(sc->tulip_dev) - 1; root_unit >= 0; root_unit--) {
2070 root_sc = tulips[root_unit];
2072 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
2077 && root_sc->tulip_chipid == sc->tulip_chipid
2078 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2079 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2080 sc->tulip_slaves = root_sc->tulip_slaves;
2081 root_sc->tulip_slaves = sc;
2082 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
2083 if_printf(&sc->tulip_if, "can't find master device for interrupts");
2086 strcat(sc->tulip_boardid, "unknown ");
2088 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */
2093 tulip_srom_decode(tulip_softc_t *sc)
2095 u_int idx1, idx2, idx3;
2097 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
2098 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
2099 tulip_srom_media_t srom_media;
2100 tulip_media_info_t *mi = sc->tulip_mediainfo;
2102 uint32_t leaf_offset, blocks, data;
2104 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
2105 if (shp->sh_adapter_count == 1)
2107 if (saip->sai_device == sc->tulip_pci_devno)
2111 * Didn't find the right media block for this card.
2113 if (idx1 == shp->sh_adapter_count)
2117 * Save the hardware address.
2119 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6);
2121 * If this is a multiple port card, add the adapter index to the last
2122 * byte of the hardware address. (if it isn't multiport, adding 0
2125 sc->tulip_enaddr[5] += idx1;
2127 leaf_offset = saip->sai_leaf_offset_lowbyte
2128 + saip->sai_leaf_offset_highbyte * 256;
2129 dp = sc->tulip_rombuf + leaf_offset;
2131 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2;
2133 for (idx2 = 0;; idx2++) {
2134 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype
2135 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED)
2138 sc->tulip_connidx = idx2;
2140 if (sc->tulip_chipid == TULIP_21041) {
2142 for (idx2 = 0; idx2 < blocks; idx2++) {
2143 tulip_media_t media;
2145 srom_media = (tulip_srom_media_t) (data & 0x3F);
2146 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2147 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2150 media = tulip_srom_mediums[idx3].sm_type;
2151 if (media != TULIP_MEDIA_UNKNOWN) {
2152 if (data & TULIP_SROM_21041_EXTENDED) {
2153 mi->mi_type = TULIP_MEDIAINFO_SIA;
2154 sc->tulip_mediums[media] = mi;
2155 mi->mi_sia_connectivity = dp[0] + dp[1] * 256;
2156 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256;
2157 mi->mi_sia_general = dp[4] + dp[5] * 256;
2161 case TULIP_MEDIA_BNC: {
2162 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
2166 case TULIP_MEDIA_AUI: {
2167 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
2171 case TULIP_MEDIA_10BASET: {
2172 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
2176 case TULIP_MEDIA_10BASET_FD: {
2177 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
2187 if (data & TULIP_SROM_21041_EXTENDED)
2192 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++;
2193 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++;
2194 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++;
2195 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++;
2199 unsigned length, type;
2200 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN;
2201 if (sc->tulip_features & TULIP_HAVE_GPR)
2202 sc->tulip_gpinit = *dp++;
2204 for (idx2 = 0; idx2 < blocks; idx2++) {
2206 if ((*dp & 0x80) == 0) {
2210 length = (*dp++ & 0x7f) - 1;
2211 type = *dp++ & 0x3f;
2214 switch (type & 0x3f) {
2215 case 0: { /* 21140[A] GPR block */
2216 tulip_media_t media;
2217 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2218 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2219 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2222 media = tulip_srom_mediums[idx3].sm_type;
2223 if (media == TULIP_MEDIA_UNKNOWN)
2225 mi->mi_type = TULIP_MEDIAINFO_GPR;
2226 sc->tulip_mediums[media] = mi;
2227 mi->mi_gpdata = dp[1];
2228 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) {
2229 sc->tulip_gpdata = mi->mi_gpdata;
2232 data = dp[2] + dp[3] * 256;
2233 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2234 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2238 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2240 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2241 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2246 case 1: { /* 21140[A] MII block */
2247 const u_int phyno = *dp++;
2248 mi->mi_type = TULIP_MEDIAINFO_MII;
2249 mi->mi_gpr_length = *dp++;
2250 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2251 dp += mi->mi_gpr_length;
2252 mi->mi_reset_length = *dp++;
2253 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2254 dp += mi->mi_reset_length;
2257 * Before we probe for a PHY, use the GPR information
2258 * to select it. If we don't, it may be inaccessible.
2260 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET);
2261 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) {
2263 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]);
2265 sc->tulip_phyaddr = mi->mi_phyaddr;
2266 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) {
2268 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]);
2272 * At least write something!
2274 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2275 TULIP_CSR_WRITE(sc, csr_gp, 0);
2277 mi->mi_phyaddr = TULIP_MII_NOPHY;
2278 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2280 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2282 if (mi->mi_phyaddr == TULIP_MII_NOPHY)
2284 sc->tulip_features |= TULIP_HAVE_MII;
2285 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2286 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2287 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2288 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2289 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2290 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2291 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2292 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2293 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2294 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2295 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2299 case 2: { /* 2114[23] SIA block */
2300 tulip_media_t media;
2301 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2302 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2303 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2306 media = tulip_srom_mediums[idx3].sm_type;
2307 if (media == TULIP_MEDIA_UNKNOWN)
2309 mi->mi_type = TULIP_MEDIAINFO_SIA;
2310 sc->tulip_mediums[media] = mi;
2312 mi->mi_sia_connectivity = dp[1] + dp[2] * 256;
2313 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256;
2314 mi->mi_sia_general = dp[5] + dp[6] * 256;
2318 case TULIP_MEDIA_BNC: {
2319 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
2322 case TULIP_MEDIA_AUI: {
2323 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
2326 case TULIP_MEDIA_10BASET: {
2327 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
2328 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2331 case TULIP_MEDIA_10BASET_FD: {
2332 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
2333 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2341 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16;
2342 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16;
2347 case 3: { /* 2114[23] MII PHY block */
2348 const u_int phyno = *dp++;
2350 mi->mi_type = TULIP_MEDIAINFO_MII;
2351 mi->mi_gpr_length = *dp++;
2352 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2353 dp += 2 * mi->mi_gpr_length;
2354 mi->mi_reset_length = *dp++;
2355 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2356 dp += 2 * mi->mi_reset_length;
2358 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset];
2359 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) {
2361 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2363 sc->tulip_phyaddr = mi->mi_phyaddr;
2364 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset];
2365 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) {
2367 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2370 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2371 TULIP_CSR_WRITE(sc, csr_sia_general, 0);
2373 mi->mi_phyaddr = TULIP_MII_NOPHY;
2374 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2376 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2378 if (mi->mi_phyaddr == TULIP_MII_NOPHY)
2380 sc->tulip_features |= TULIP_HAVE_MII;
2381 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2382 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2383 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2384 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2385 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2;
2386 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2387 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2388 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2389 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2390 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2391 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2392 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2396 case 4: { /* 21143 SYM block */
2397 tulip_media_t media;
2398 srom_media = (tulip_srom_media_t) dp[0];
2399 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2400 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2403 media = tulip_srom_mediums[idx3].sm_type;
2404 if (media == TULIP_MEDIA_UNKNOWN)
2406 mi->mi_type = TULIP_MEDIAINFO_SYM;
2407 sc->tulip_mediums[media] = mi;
2408 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16;
2409 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16;
2410 data = dp[5] + dp[6] * 256;
2411 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2412 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2415 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2416 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2417 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2419 if (TULIP_IS_MEDIA_TP(media))
2420 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2425 case 5: { /* 21143 Reset block */
2426 mi->mi_type = TULIP_MEDIAINFO_RESET;
2427 mi->mi_reset_length = *dp++;
2428 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2429 dp += 2 * mi->mi_reset_length;
2440 return mi - sc->tulip_mediainfo;
2443 static const struct {
2444 void (*vendor_identify_nic)(tulip_softc_t * const sc);
2445 unsigned char vendor_oui[3];
2446 } tulip_vendors[] = {
2447 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } },
2448 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } },
2449 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } },
2450 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } },
2451 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } },
2452 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } },
2453 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } },
2454 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } },
2455 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } },
2456 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } },
2461 * This deals with the vagaries of the address roms and the
2462 * brain-deadness that various vendors commit in using them.
2465 tulip_read_macaddr(tulip_softc_t *sc)
2467 u_int cksum, rom_cksum, idx;
2469 unsigned char tmpbuf[8];
2470 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
2472 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX;
2474 if (sc->tulip_chipid == TULIP_21040) {
2475 TULIP_CSR_WRITE(sc, csr_enetrom, 1);
2476 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2478 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
2480 sc->tulip_rombuf[idx] = csr & 0xFF;
2482 sc->tulip_boardsw = &tulip_21040_boardsw;
2484 if (sc->tulip_chipid == TULIP_21041) {
2486 * Thankfully all 21041's act the same.
2488 sc->tulip_boardsw = &tulip_21041_boardsw;
2491 * Assume all 21140 board are compatible with the
2492 * DEC 10/100 evaluation board. Not really valid but
2493 * it's the best we can do until every one switches to
2494 * the new SROM format.
2497 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2499 tulip_srom_read(sc);
2500 if (tulip_srom_crcok(sc->tulip_rombuf)) {
2502 * SROM CRC is valid therefore it must be in the
2505 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM;
2506 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
2508 * No checksum is present. See if the SROM id checks out;
2509 * the first 18 bytes should be 0 followed by a 1 followed
2510 * by the number of adapters (which we don't deal with yet).
2512 for (idx = 0; idx < 18; idx++) {
2513 if (sc->tulip_rombuf[idx] != 0)
2516 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
2517 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2518 } else if (sc->tulip_chipid >= TULIP_21142) {
2519 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2520 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2522 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) {
2523 if (sc->tulip_chipid != TULIP_21041)
2524 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2527 * If the SROM specifies more than one adapter, tag this as a
2530 if (sc->tulip_rombuf[19] > 1)
2531 sc->tulip_features |= TULIP_HAVE_BASEROM;
2532 if (sc->tulip_boardsw == NULL)
2539 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
2541 * Some folks don't use the standard ethernet rom format
2542 * but instead just put the address in the first 6 bytes
2543 * of the rom and let the rest be all 0xffs. (Can we say
2544 * ZNYX?) (well sometimes they put in a checksum so we'll
2547 for (idx = 8; idx < 32; idx++) {
2548 if (sc->tulip_rombuf[idx] != 0xFF)
2552 * Make sure the address is not multicast or locally assigned
2553 * that the OUI is not 00-00-00.
2555 if ((sc->tulip_rombuf[0] & 3) != 0)
2557 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
2558 && sc->tulip_rombuf[2] == 0)
2560 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2561 sc->tulip_features |= TULIP_HAVE_OKROM;
2565 * A number of makers of multiport boards (ZNYX and Cogent)
2566 * only put on one address ROM on their 21040 boards. So
2567 * if the ROM is all zeros (or all 0xFFs), look at the
2568 * previous configured boards (as long as they are on the same
2569 * PCI bus and the bus number is non-zero) until we find the
2570 * master board with address ROM. We then use its address ROM
2571 * as the base for this board. (we add our relative board
2572 * to the last byte of its address).
2574 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2575 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF)
2578 if (idx == sizeof(sc->tulip_rombuf)) {
2580 tulip_softc_t *root_sc = NULL;
2581 for (root_unit = device_get_unit(sc->tulip_dev) - 1; root_unit >= 0; root_unit--) {
2582 root_sc = tulips[root_unit];
2583 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
2587 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM)
2588 && root_sc->tulip_chipid == sc->tulip_chipid
2589 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2590 sc->tulip_features |= TULIP_HAVE_SLAVEDROM;
2591 sc->tulip_boardsw = root_sc->tulip_boardsw;
2592 strcpy(sc->tulip_boardid, root_sc->tulip_boardid);
2593 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) {
2594 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf,
2595 sizeof(sc->tulip_rombuf));
2596 if (!tulip_srom_decode(sc))
2599 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
2600 sc->tulip_enaddr[5] += device_get_unit(sc->tulip_dev) - device_get_unit(root_sc->tulip_dev);
2603 * Now for a truly disgusting kludge: all 4 21040s on
2604 * the ZX314 share the same INTA line so the mapping
2605 * setup by the BIOS on the PCI bridge is worthless.
2606 * Rather than reprogramming the value in the config
2607 * register, we will handle this internally.
2609 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) {
2610 sc->tulip_slaves = root_sc->tulip_slaves;
2611 root_sc->tulip_slaves = sc;
2612 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2620 * This is the standard DEC address ROM test.
2623 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
2626 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
2627 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
2628 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
2629 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
2630 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
2633 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2635 cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
2637 if (cksum > 65535) cksum -= 65535;
2638 cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
2639 if (cksum > 65535) cksum -= 65535;
2641 if (cksum > 65535) cksum -= 65535;
2642 cksum += *(u_int16_t *) &sc->tulip_enaddr[4];
2643 if (cksum >= 65535) cksum -= 65535;
2645 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6];
2647 if (cksum != rom_cksum)
2652 * Check for various boards based on OUI. Did I say braindead?
2654 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) {
2655 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) {
2656 (*tulip_vendors[idx].vendor_identify_nic)(sc);
2661 sc->tulip_features |= TULIP_HAVE_OKROM;
2666 tulip_ifmedia_add(tulip_softc_t * const sc)
2668 tulip_media_t media;
2671 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2672 if (sc->tulip_mediums[media] != NULL) {
2673 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media],
2679 sc->tulip_features |= TULIP_HAVE_NOMEDIA;
2680 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0);
2681 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE);
2682 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
2683 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0);
2684 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO);
2686 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]);
2687 sc->tulip_flags |= TULIP_PRINTMEDIA;
2688 tulip_linkup(sc, sc->tulip_media);
2693 tulip_ifmedia_change(struct ifnet *ifp)
2695 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2697 sc->tulip_flags |= TULIP_NEEDRESET;
2698 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
2699 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
2700 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) {
2701 tulip_media_t media;
2702 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2703 if (sc->tulip_mediums[media] != NULL
2704 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) {
2705 sc->tulip_flags |= TULIP_PRINTMEDIA;
2706 sc->tulip_flags &= ~TULIP_DIDNWAY;
2707 tulip_linkup(sc, media);
2712 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
2719 * Media status callback
2722 tulip_ifmedia_status(struct ifnet *ifp, struct ifmediareq *req)
2724 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2726 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN)
2729 req->ifm_status = IFM_AVALID;
2730 if (sc->tulip_flags & TULIP_LINKUP)
2731 req->ifm_status |= IFM_ACTIVE;
2733 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
2737 tulip_addr_filter(tulip_softc_t *sc)
2739 struct ifmultiaddr *ifma;
2743 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI);
2744 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART;
2745 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
2746 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
2747 #if defined(IFF_ALLMULTI)
2748 if (sc->tulip_if.if_flags & IFF_ALLMULTI)
2749 sc->tulip_flags |= TULIP_ALLMULTI ;
2753 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
2754 if (ifma->ifma_addr->sa_family == AF_LINK)
2758 sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */
2759 if (multicnt > 14) {
2760 uint32_t *sp = sc->tulip_setupdata;
2763 * Some early passes of the 21140 have broken implementations of
2764 * hash-perfect mode. When we get too many multicasts for perfect
2765 * filtering with these chips, we need to switch into hash-only
2766 * mode (this is better than all-multicast on network with lots
2767 * of multicast traffic).
2769 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
2770 sc->tulip_flags |= TULIP_WANTHASHONLY;
2772 sc->tulip_flags |= TULIP_WANTHASHPERFECT;
2774 * If we have more than 14 multicasts, we have
2775 * go into hash perfect mode (512 bit multicast
2776 * hash and one perfect hardware).
2778 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
2780 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
2781 if (ifma->ifma_addr->sa_family != AF_LINK)
2784 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
2785 #if BYTE_ORDER == BIG_ENDIAN
2786 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2788 sp[hash >> 4] |= 1 << (hash & 0xF);
2792 * No reason to use a hash if we are going to be
2793 * receiving every multicast.
2795 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
2796 hash = tulip_mchash(sc->tulip_if.if_broadcastaddr);
2797 #if BYTE_ORDER == BIG_ENDIAN
2798 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2800 sp[hash >> 4] |= 1 << (hash & 0xF);
2802 if (sc->tulip_flags & TULIP_WANTHASHONLY) {
2803 hash = tulip_mchash(sc->tulip_enaddr);
2804 #if BYTE_ORDER == BIG_ENDIAN
2805 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2807 sp[hash >> 4] |= 1 << (hash & 0xF);
2810 #if BYTE_ORDER == BIG_ENDIAN
2811 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
2812 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
2813 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
2815 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0];
2816 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1];
2817 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2];
2822 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
2823 uint32_t *sp = sc->tulip_setupdata;
2825 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
2827 * Else can get perfect filtering for 16 addresses.
2829 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
2830 if (ifma->ifma_addr->sa_family != AF_LINK)
2832 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
2833 #if BYTE_ORDER == BIG_ENDIAN
2834 *sp++ = ((u_int16_t *) addrp)[0] << 16;
2835 *sp++ = ((u_int16_t *) addrp)[1] << 16;
2836 *sp++ = ((u_int16_t *) addrp)[2] << 16;
2838 *sp++ = ((u_int16_t *) addrp)[0];
2839 *sp++ = ((u_int16_t *) addrp)[1];
2840 *sp++ = ((u_int16_t *) addrp)[2];
2845 * Add the broadcast address.
2848 #if BYTE_ORDER == BIG_ENDIAN
2849 *sp++ = 0xFFFF << 16;
2850 *sp++ = 0xFFFF << 16;
2851 *sp++ = 0xFFFF << 16;
2859 * Pad the rest with our hardware address
2861 for (; idx < 16; idx++) {
2862 #if BYTE_ORDER == BIG_ENDIAN
2863 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
2864 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
2865 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
2867 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0];
2868 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1];
2869 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2];
2873 #if defined(IFF_ALLMULTI)
2874 if (sc->tulip_flags & TULIP_ALLMULTI)
2875 sc->tulip_if.if_flags |= IFF_ALLMULTI;
2880 tulip_reset(tulip_softc_t *sc)
2882 tulip_ringinfo_t *ri;
2884 uint32_t inreset = (sc->tulip_flags & TULIP_INRESET);
2887 * Brilliant. Simply brilliant. When switching modes/speeds
2888 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
2889 * bits in CSR6 and then do a software reset to get the 21140
2890 * to properly reset its internal pathways to the right places.
2893 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
2894 && sc->tulip_boardsw->bd_media_preset != NULL)
2895 (*sc->tulip_boardsw->bd_media_preset)(sc);
2897 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2898 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
2899 33MHz that comes to two microseconds but wait a
2900 bit longer anyways) */
2903 sc->tulip_flags |= TULIP_INRESET;
2904 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
2905 ifq_clr_oactive(&sc->tulip_if.if_snd);
2906 sc->tulip_if.if_start = tulip_ifstart;
2909 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
2910 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
2911 TULIP_CSR_WRITE(sc, csr_busmode,
2912 (1 << (3 /*pci_max_burst_len*/ + 8))
2913 |TULIP_BUSMODE_CACHE_ALIGN8
2914 |TULIP_BUSMODE_READMULTIPLE
2915 |(BYTE_ORDER != LITTLE_ENDIAN ?
2916 TULIP_BUSMODE_DESC_BIGENDIAN : 0));
2918 sc->tulip_txtimer = 0;
2919 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
2921 * Free all the mbufs that were on the transmit ring.
2923 IF_DRAIN(&sc->tulip_txq);
2925 ri = &sc->tulip_txinfo;
2926 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
2927 ri->ri_free = ri->ri_max;
2928 for (di = ri->ri_first; di < ri->ri_last; di++)
2932 * We need to collect all the mbufs were on the
2933 * receive ring before we reinit it either to put
2934 * them back on or to know if we have to allocate
2937 ri = &sc->tulip_rxinfo;
2938 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
2939 ri->ri_free = ri->ri_max;
2940 for (di = ri->ri_first; di < ri->ri_last; di++) {
2942 di->d_length1 = 0; di->d_addr1 = 0;
2943 di->d_length2 = 0; di->d_addr2 = 0;
2945 IF_DRAIN(&sc->tulip_rxq);
2948 * If tulip_reset is being called recurisvely, exit quickly knowing
2949 * that when the outer tulip_reset returns all the right stuff will
2955 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
2956 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
2957 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
2958 |TULIP_STS_RXSTOPPED;
2960 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
2961 (*sc->tulip_boardsw->bd_media_select)(sc);
2962 tulip_media_print(sc);
2963 if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
2964 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
2966 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
2968 tulip_addr_filter(sc);
2972 tulip_init(tulip_softc_t * const sc)
2974 if (sc->tulip_if.if_flags & IFF_UP) {
2975 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) {
2976 /* initialize the media */
2979 sc->tulip_if.if_flags |= IFF_RUNNING;
2980 if (sc->tulip_if.if_flags & IFF_PROMISC) {
2981 sc->tulip_flags |= TULIP_PROMISC;
2982 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
2983 sc->tulip_intrmask |= TULIP_STS_TXINTR;
2985 sc->tulip_flags &= ~TULIP_PROMISC;
2986 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
2987 if (sc->tulip_flags & TULIP_ALLMULTI) {
2988 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
2990 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
2993 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
2994 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
2996 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
2997 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
2999 ifq_set_oactive(&sc->tulip_if.if_snd);
3000 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3001 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3003 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3004 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3005 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3006 tulip_txput_setup(sc);
3008 sc->tulip_if.if_flags &= ~IFF_RUNNING;
3014 tulip_rx_intr(tulip_softc_t *sc)
3016 tulip_ringinfo_t *ri = &sc->tulip_rxinfo;
3017 struct ifnet *ifp = &sc->tulip_if;
3021 tulip_desc_t *eop = ri->ri_nextin;
3022 int total_len = 0, last_offset = 0;
3023 struct mbuf *ms = NULL, *me = NULL;
3026 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
3030 * If the TULIP has no descriptors, there can't be any receive
3031 * descriptors to process.
3033 if (eop == ri->ri_nextout)
3037 * 90% of the packets will fit in one descriptor. So we optimize
3040 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3041 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
3042 IF_DEQUEUE(&sc->tulip_rxq, ms);
3046 * If still owned by the TULIP, don't touch it.
3048 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
3052 * It is possible (though improbable unless the BIG_PACKET support
3053 * is enabled or MCLBYTES < 1518) for a received packet to cross
3054 * more than one receive descriptor.
3056 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) {
3057 if (++eop == ri->ri_last)
3059 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3060 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
3067 * Dequeue the first buffer for the start of the packet. Hopefully
3068 * this will be the only one we need to dequeue. However, if the
3069 * packet consumed multiple descriptors, then we need to dequeue
3070 * those buffers and chain to the starting mbuf. All buffers but
3071 * the last buffer have the same length so we can set that now.
3072 * (we add to last_offset instead of multiplying since we normally
3073 * won't go into the loop and thereby saving a ourselves from
3074 * doing a multiplication by 0 in the normal case).
3076 IF_DEQUEUE(&sc->tulip_rxq, ms);
3077 for (me = ms; total_len > 0; total_len--) {
3078 me->m_len = TULIP_RX_BUFLEN;
3079 last_offset += TULIP_RX_BUFLEN;
3080 IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
3086 * Now get the size of received packet (minus the CRC).
3088 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
3089 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
3090 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0
3092 || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) &&
3093 (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT|
3094 TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC|
3095 TULIP_DSTS_RxOVERFLOW)) == 0)
3098 me->m_len = total_len - last_offset;
3100 sc->tulip_flags |= TULIP_RXACT;
3103 IFNET_STAT_INC(ifp, ierrors, 1);
3104 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3105 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3107 if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
3108 sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
3110 if (eop->d_status & TULIP_DSTS_RxBADCRC) {
3111 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
3112 sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
3114 sc->tulip_dot3stats.dot3StatsFCSErrors++;
3119 IFNET_STAT_INC(ifp, ipackets, 1);
3120 if (++eop == ri->ri_last)
3122 ri->ri_nextin = eop;
3125 * Either we are priming the TULIP with mbufs (m == NULL)
3126 * or we are about to accept an mbuf for the upper layers
3127 * so we need to allocate an mbuf to replace it. If we
3128 * can't replace it, send up it anyways. This may cause
3129 * us to drop packets in the future but that's better than
3130 * being caught in livelock.
3132 * Note that if this packet crossed multiple descriptors
3133 * we don't even try to reallocate all the mbufs here.
3134 * Instead we rely on the test of the beginning of
3135 * the loop to refill for the extra consumed mbufs.
3137 if (accept || ms == NULL) {
3140 #if defined(TULIP_COPY_RXDATA)
3141 if (!accept || total_len >= (MHLEN - 2))
3142 m0 = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
3144 m0 = m_gethdr(MB_DONTWAIT, MT_DATA);
3146 m0 = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
3150 #if defined(TULIP_COPY_RXDATA)
3154 #if !defined(TULIP_COPY_RXDATA)
3155 ms->m_pkthdr.len = total_len;
3156 ifp->if_input(ifp, ms);
3159 #error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
3161 m0->m_data += 2; /* align data after header */
3162 m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
3163 m0->m_len = m0->m_pkthdr.len = total_len;
3164 m0->m_pkthdr.rcvif = ifp;
3165 ifp->if_input(ifp, m0);
3167 #endif /* ! TULIP_COPY_RXDATA */
3173 * Couldn't allocate a new buffer. Don't bother
3174 * trying to replenish the receive queue.
3177 sc->tulip_flags |= TULIP_RXBUFSLOW;
3181 * Now give the buffer(s) to the TULIP and save in our
3185 tulip_desc_t * const nextout = ri->ri_nextout;
3186 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
3187 nextout->d_length1 = TULIP_RX_BUFLEN;
3188 nextout->d_status = TULIP_DSTS_OWNER;
3189 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
3190 if (++ri->ri_nextout == ri->ri_last)
3191 ri->ri_nextout = ri->ri_first;
3194 IF_ENQUEUE(&sc->tulip_rxq, ms);
3195 } while ((ms = me) != NULL);
3197 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
3198 sc->tulip_flags &= ~TULIP_RXBUFSLOW;
3203 tulip_tx_intr(tulip_softc_t *sc)
3205 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3210 while (ri->ri_free < ri->ri_max) {
3213 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
3214 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
3219 d_flag = ri->ri_nextin->d_flag;
3220 if (d_flag & TULIP_DFLAG_TxLASTSEG) {
3221 if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
3223 * We've just finished processing a setup packet.
3224 * Mark that we finished it. If there's not
3225 * another pending, startup the TULIP receiver.
3226 * Make sure we ack the RXSTOPPED so we won't get
3227 * an abormal interrupt indication.
3229 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap);
3230 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
3231 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT)
3232 sc->tulip_flags |= TULIP_HASHONLY;
3233 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
3235 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3236 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3237 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3238 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3239 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3242 const uint32_t d_status = ri->ri_nextin->d_status;
3243 IF_DEQUEUE(&sc->tulip_txq, m);
3247 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3248 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
3249 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
3250 event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
3252 (*sc->tulip_boardsw->bd_media_poll)(sc, event);
3254 * Escape from the loop before media poll has reset the TULIP!
3259 if (d_status & TULIP_DSTS_ERRSUM) {
3260 IFNET_STAT_INC(&sc->tulip_if, oerrors, 1);
3261 if (d_status & TULIP_DSTS_TxEXCCOLL)
3262 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
3263 if (d_status & TULIP_DSTS_TxLATECOLL)
3264 sc->tulip_dot3stats.dot3StatsLateCollisions++;
3265 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
3266 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
3267 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
3268 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
3269 if (d_status & TULIP_DSTS_TxUNDERFLOW)
3270 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
3271 if (d_status & TULIP_DSTS_TxBABBLE)
3272 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
3274 u_int32_t collisions =
3275 (d_status & TULIP_DSTS_TxCOLLMASK)
3276 >> TULIP_DSTS_V_TxCOLLCNT;
3277 IFNET_STAT_INC(&sc->tulip_if, collisions, collisions);
3278 if (collisions == 1)
3279 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
3280 else if (collisions > 1)
3281 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
3282 else if (d_status & TULIP_DSTS_TxDEFERRED)
3283 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
3285 * SQE is only valid for 10baseT/BNC/AUI when not
3286 * running in full-duplex. In order to speed up the
3287 * test, the corresponding bit in tulip_flags needs to
3288 * set as well to get us to count SQE Test Errors.
3290 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
3291 sc->tulip_dot3stats.dot3StatsSQETestErrors++;
3297 if (++ri->ri_nextin == ri->ri_last)
3298 ri->ri_nextin = ri->ri_first;
3300 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3301 ifq_clr_oactive(&sc->tulip_if.if_snd);
3304 * If nothing left to transmit, disable the timer.
3305 * Else if progress, reset the timer back to 2 ticks.
3307 * XXX 2 bit field, TXTIMER is 4?
3309 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
3310 sc->tulip_txtimer = 0;
3312 sc->tulip_txtimer = (TULIP_TXTIMER & 3);
3313 IFNET_STAT_INC(&sc->tulip_if, opackets, xmits);
3318 tulip_print_abnormal_interrupt(tulip_softc_t *sc, uint32_t csr)
3320 const char * const *msgp = tulip_status_bits;
3323 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
3325 csr &= (1 << (NELEM(tulip_status_bits))) - 1;
3326 if_printf(&sc->tulip_if, "abnormal interrupt:");
3327 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
3328 if ((csr & mask) && *msgp != NULL) {
3329 kprintf("%s%s", sep, *msgp);
3330 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
3331 sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
3332 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
3333 kprintf(" (switching to store-and-forward mode)");
3335 kprintf(" (raising TX threshold to %s)",
3336 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
3346 tulip_intr_handler(tulip_softc_t *sc)
3350 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3351 TULIP_CSR_WRITE(sc, csr_status, csr);
3353 if (csr & TULIP_STS_SYSERROR) {
3354 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
3355 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3356 sc->tulip_flags |= TULIP_SYSTEMERROR;
3358 if_printf(&sc->tulip_if, "system error: %s\n",
3359 tulip_system_errors[sc->tulip_last_system_error]);
3361 sc->tulip_flags |= TULIP_NEEDRESET;
3362 sc->tulip_system_errors++;
3365 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
3366 if (sc->tulip_boardsw->bd_media_poll != NULL) {
3367 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
3368 ? TULIP_MEDIAPOLL_LINKFAIL
3369 : TULIP_MEDIAPOLL_LINKPASS);
3370 csr &= ~TULIP_STS_ABNRMLINTR;
3372 tulip_media_print(sc);
3374 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
3375 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
3376 if (csr & TULIP_STS_RXNOBUF)
3377 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
3379 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3380 * on receive overflows.
3382 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
3383 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3385 * Stop the receiver process and spin until it's stopped.
3386 * Tell rx_intr to drop the packets it dequeues.
3388 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
3389 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
3391 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3392 sc->tulip_flags |= TULIP_RXIGNORE;
3395 if (sc->tulip_flags & TULIP_RXIGNORE) {
3397 * Restart the receiver.
3399 sc->tulip_flags &= ~TULIP_RXIGNORE;
3400 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3403 if (csr & TULIP_STS_ABNRMLINTR) {
3404 u_int32_t tmp = csr & sc->tulip_intrmask
3405 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
3406 if (csr & TULIP_STS_TXUNDERFLOW) {
3407 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
3408 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
3409 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3410 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
3411 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
3412 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3415 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3416 sc->tulip_statusbits |= tmp;
3418 tulip_print_abnormal_interrupt(sc, tmp);
3419 sc->tulip_flags |= TULIP_NOMESSAGES;
3421 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3423 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
3425 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3426 if_devstart(&sc->tulip_if);
3429 if (sc->tulip_flags & TULIP_NEEDRESET) {
3436 tulip_intr_shared(void *arg)
3440 for (sc = arg; sc != NULL; sc = sc->tulip_slaves)
3441 tulip_intr_handler(sc);
3445 tulip_intr_normal(void *arg)
3447 tulip_softc_t *sc = (tulip_softc_t *)arg;
3449 tulip_intr_handler(sc);
3452 static struct mbuf *
3453 tulip_txput(tulip_softc_t *sc, struct mbuf *m)
3455 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3456 tulip_desc_t *eop, *nextout;
3462 * Now we try to fill in our transmit descriptors. This is
3463 * a bit reminiscent of going on the Ark two by two
3464 * since each descriptor for the TULIP can describe
3465 * two buffers. So we advance through packet filling
3466 * each of the two entries at a time to to fill each
3467 * descriptor. Clear the first and last segment bits
3468 * in each descriptor (actually just clear everything
3469 * but the end-of-ring or chain bits) to make sure
3470 * we don't get messed up by previously sent packets.
3472 * We may fail to put the entire packet on the ring if
3473 * there is either not enough ring entries free or if the
3474 * packet has more than MAX_TXSEG segments. In the former
3475 * case we will just wait for the ring to empty. In the
3476 * latter case we have to recopy.
3481 eop = nextout = ri->ri_nextout;
3486 int len = m0->m_len;
3487 caddr_t addr = mtod(m0, caddr_t);
3488 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1));
3491 unsigned slen = min(len, clsize);
3495 slen = 2040, partial = 1;
3498 if (segcnt > TULIP_MAX_TXSEG) {
3500 * The packet exceeds the number of transmit buffer
3501 * entries that we can use for one packet, so we have
3502 * recopy it into one mbuf and then try again.
3504 m0 = m_defrag(m, MB_DONTWAIT);
3513 * See if there's any unclaimed space in the
3516 if ((free += tulip_tx_intr(sc)) == 0) {
3518 * There's no more room but since nothing
3519 * has been committed at this point, just
3520 * show output is active, put back the
3523 sc->tulip_flags |= TULIP_WANTTXSTART;
3528 if (++nextout == ri->ri_last)
3529 nextout = ri->ri_first;
3530 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
3531 eop->d_status = d_status;
3532 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr);
3533 eop->d_length1 = slen;
3536 * Fill in second half of descriptor
3538 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr);
3539 eop->d_length2 = slen;
3541 d_status = TULIP_DSTS_OWNER;
3550 } while ((m0 = m0->m_next) != NULL);
3552 BPF_MTAP(&sc->tulip_if, m);
3555 * The descriptors have been filled in. Now get ready
3558 IF_ENQUEUE(&sc->tulip_txq, m);
3562 * Make sure the next descriptor after this packet is owned
3563 * by us since it may have been set up above if we ran out
3564 * of room in the ring.
3566 nextout->d_status = 0;
3567 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
3570 * If we only used the first segment of the last descriptor,
3571 * make sure the second segment will not be used.
3579 * Mark the last and first segments, indicate we want a transmit
3580 * complete interrupt, and tell it to transmit!
3582 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
3585 * Note that ri->ri_nextout is still the start of the packet
3586 * and until we set the OWNER bit, we can still back out of
3587 * everything we have done.
3589 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
3590 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
3591 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
3594 * This advances the ring for us.
3596 ri->ri_nextout = nextout;
3599 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3600 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3601 ifq_set_oactive(&sc->tulip_if.if_snd);
3602 sc->tulip_if.if_start = tulip_ifstart;
3607 * switch back to the single queueing ifstart.
3609 * XXX 2 bit field, TXTIMER is 4?
3611 sc->tulip_flags &= ~TULIP_WANTTXSTART;
3612 if (sc->tulip_txtimer == 0)
3613 sc->tulip_txtimer = TULIP_TXTIMER & 3;
3616 * If we want a txstart, there must be not enough space in the
3617 * transmit ring. So we want to enable transmit done interrupts
3618 * so we can immediately reclaim some space. When the transmit
3619 * interrupt is posted, the interrupt handler will call tx_intr
3620 * to reclaim space and then txstart (since WANTTXSTART is set).
3621 * txstart will move the packet into the transmit ring and clear
3622 * WANTTXSTART thereby causing TXINTR to be cleared.
3625 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
3626 ifq_set_oactive(&sc->tulip_if.if_snd);
3627 sc->tulip_if.if_start = tulip_ifstart;
3628 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
3629 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3630 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3632 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) {
3633 if (sc->tulip_intrmask & TULIP_STS_TXINTR) {
3634 sc->tulip_intrmask &= ~TULIP_STS_TXINTR;
3635 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3638 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3643 tulip_txput_setup(tulip_softc_t *sc)
3645 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3646 tulip_desc_t *nextout;
3649 * We will transmit, at most, one setup packet per call to ifstart.
3653 * Try to reclaim some free descriptors..
3655 if (ri->ri_free < 2)
3657 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
3658 sc->tulip_flags |= TULIP_WANTTXSTART;
3659 sc->tulip_if.if_start = tulip_ifstart;
3662 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
3663 sizeof(sc->tulip_setupbuf));
3665 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is
3666 * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
3668 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP;
3670 nextout = ri->ri_nextout;
3671 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
3672 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
3673 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
3674 if (sc->tulip_flags & TULIP_WANTHASHPERFECT)
3675 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
3676 else if (sc->tulip_flags & TULIP_WANTHASHONLY)
3677 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT;
3679 nextout->d_length2 = 0;
3680 nextout->d_addr2 = 0;
3681 nextout->d_length1 = sizeof(sc->tulip_setupbuf);
3682 nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
3685 * Advance the ring for the next transmit packet.
3687 if (++ri->ri_nextout == ri->ri_last)
3688 ri->ri_nextout = ri->ri_first;
3691 * Make sure the next descriptor is owned by us since it
3692 * may have been set up above if we ran out of room in the
3695 ri->ri_nextout->d_status = 0;
3696 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
3697 nextout->d_status = TULIP_DSTS_OWNER;
3699 * Flush the ownwership of the current descriptor
3701 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
3702 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3703 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
3704 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3705 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3710 tulip_ifioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred * cr)
3712 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
3713 struct ifreq *ifr = (struct ifreq *)data;
3718 bcopy((caddr_t) sc->tulip_enaddr,
3719 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
3724 case SIOCSIFFLAGS: {
3725 tulip_addr_filter(sc); /* reinit multicast filter */
3731 case SIOCGIFMEDIA: {
3732 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
3737 case SIOCDELMULTI: {
3739 * Update multicast listeners
3741 tulip_addr_filter(sc); /* reset multicast filtering */
3749 * Set the interface MTU.
3751 if (ifr->ifr_mtu > ETHERMTU
3753 && sc->tulip_chipid != TULIP_21140
3754 && sc->tulip_chipid != TULIP_21140A
3755 && sc->tulip_chipid != TULIP_21041
3761 ifp->if_mtu = ifr->ifr_mtu;
3769 case SIOCGADDRROM: {
3770 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
3776 ifr->ifr_metric = (int) sc->tulip_chipid;
3781 error = ether_ioctl(ifp, cmd, data);
3789 tulip_ifstart(struct ifnet *ifp, struct ifaltq_subque *ifsq)
3791 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
3793 ASSERT_ALTQ_SQ_DEFAULT(ifp, ifsq);
3794 if (sc->tulip_if.if_flags & IFF_RUNNING) {
3796 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3797 tulip_txput_setup(sc);
3799 while (!ifq_is_empty(&sc->tulip_if.if_snd)) {
3802 m = ifq_dequeue(&sc->tulip_if.if_snd, NULL);
3806 if ((m = tulip_txput(sc, m)) != NULL) {
3807 ifq_prepend(&sc->tulip_if.if_snd, m);
3815 tulip_ifwatchdog(struct ifnet *ifp)
3817 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
3819 sc->tulip_if.if_timer = 1;
3821 * These should be rare so do a bulk test up front so we can just skip
3824 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) {
3826 * If the number of receive buffer is low, try to refill
3828 if (sc->tulip_flags & TULIP_RXBUFSLOW)
3831 if (sc->tulip_flags & TULIP_SYSTEMERROR) {
3832 if_printf(ifp, "%d system errors: last was %s\n",
3833 sc->tulip_system_errors,
3834 tulip_system_errors[sc->tulip_last_system_error]);
3836 if (sc->tulip_statusbits) {
3837 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
3838 sc->tulip_statusbits = 0;
3841 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR);
3844 if (sc->tulip_txtimer)
3846 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
3847 if_printf(ifp, "transmission timeout\n");
3848 if (TULIP_DO_AUTOSENSE(sc)) {
3849 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
3850 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
3851 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP);
3859 tulip_attach(tulip_softc_t *sc)
3861 struct ifnet *ifp = &sc->tulip_if;
3863 callout_init(&sc->tulip_timer);
3864 callout_init(&sc->tulip_fast_timer);
3866 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
3867 ifp->if_ioctl = tulip_ifioctl;
3868 ifp->if_start = tulip_ifstart;
3869 ifp->if_watchdog = tulip_ifwatchdog;
3872 if_printf(ifp, "%s%s pass %d.%d%s\n",
3874 tulip_chipdescs[sc->tulip_chipid],
3875 (sc->tulip_revinfo & 0xF0) >> 4,
3876 sc->tulip_revinfo & 0x0F,
3877 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM))
3878 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "");
3880 (*sc->tulip_boardsw->bd_media_probe)(sc);
3881 ifmedia_init(&sc->tulip_ifmedia, 0,
3882 tulip_ifmedia_change,
3883 tulip_ifmedia_status);
3884 sc->tulip_flags &= ~TULIP_DEVICEPROBE;
3885 tulip_ifmedia_add(sc);
3889 ifq_set_maxlen(&ifp->if_snd, ifqmaxlen);
3890 ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr, NULL);
3894 tulip_detach(tulip_softc_t *sc)
3896 ifmedia_removeall(&sc->tulip_ifmedia);
3897 ether_ifdetach(&sc->tulip_if);
3901 tulip_initcsrs(tulip_softc_t *sc, tulip_csrptr_t csr_base, size_t csr_size)
3903 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
3904 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
3905 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
3906 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
3907 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
3908 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
3909 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
3910 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
3911 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size;
3912 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size;
3913 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size;
3914 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size;
3915 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size;
3916 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size;
3917 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
3918 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
3922 tulip_initring(tulip_softc_t *sc, tulip_ringinfo_t *ri, tulip_desc_t *descs,
3925 ri->ri_max = ndescs;
3926 ri->ri_first = descs;
3927 ri->ri_last = ri->ri_first + ri->ri_max;
3928 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
3929 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
3933 * This is the PCI configuration support.
3936 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
3937 #define PCI_CBMA 0x14 /* Configuration Base Memory Address */
3938 #define PCI_CFDA 0x40 /* Configuration Driver Area */
3941 tulip_pci_probe(device_t dev)
3943 const char *name = NULL;
3945 if (pci_get_vendor(dev) != DEC_VENDORID)
3949 * Some LanMedia WAN cards use the Tulip chip, but they have
3950 * their own driver, and we should not recognize them
3952 if (pci_get_subvendor(dev) == 0x1376)
3955 switch (pci_get_device(dev)) {
3957 name = "Digital 21040 Ethernet";
3960 name = "Digital 21041 Ethernet";
3963 if (pci_get_revid(dev) >= 0x20)
3964 name = "Digital 21140A Fast Ethernet";
3966 name = "Digital 21140 Fast Ethernet";
3969 if (pci_get_revid(dev) >= 0x20)
3970 name = "Digital 21143 Fast Ethernet";
3972 name = "Digital 21142 Fast Ethernet";
3976 device_set_desc(dev, name);
3983 tulip_shutdown(device_t dev)
3985 tulip_softc_t *sc = device_get_softc(dev);
3987 lwkt_serialize_enter(sc->tulip_if.if_serializer);
3988 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
3989 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
3990 33MHz that comes to two microseconds but wait a
3991 bit longer anyways) */
3992 lwkt_serialize_exit(sc->tulip_if.if_serializer);
3997 tulip_pci_attach(device_t dev)
4001 uint32_t revinfo, cfdainfo;
4002 u_int csroffset = TULIP_PCI_CSROFFSET;
4003 u_int csrsize = TULIP_PCI_CSRSIZE;
4004 tulip_csrptr_t csr_base;
4005 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
4006 struct resource *res;
4009 if (device_get_unit(dev) >= TULIP_MAX_DEVICES) {
4010 device_printf(dev, "not configured; limit of %d reached or exceeded\n",
4015 revinfo = pci_get_revid(dev);
4016 cfdainfo = pci_read_config(dev, PCI_CFDA, 4);
4018 /* turn busmaster on in case BIOS doesn't set it */
4019 pci_enable_busmaster(dev);
4021 if (pci_get_vendor(dev) == DEC_VENDORID) {
4022 if (pci_get_device(dev) == CHIPID_21040)
4023 chipid = TULIP_21040;
4024 else if (pci_get_device(dev) == CHIPID_21041)
4025 chipid = TULIP_21041;
4026 else if (pci_get_device(dev) == CHIPID_21140)
4027 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140;
4028 else if (pci_get_device(dev) == CHIPID_21142)
4029 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142;
4031 if (chipid == TULIP_CHIPID_UNKNOWN)
4034 if (chipid == TULIP_21040 && revinfo < 0x20) {
4035 device_printf(dev, "not configured; 21040 pass 2.0 required (%d.%d found)\n",
4036 revinfo >> 4, revinfo & 0x0f);
4038 } else if (chipid == TULIP_21140 && revinfo < 0x11) {
4039 device_printf(dev, "not configured; 21140 pass 1.1 required (%d.%d found)\n",
4040 revinfo >> 4, revinfo & 0x0f);
4044 sc = device_get_softc(dev);
4045 sc->tulip_dev = dev;
4046 sc->tulip_pci_busno = pci_get_bus(dev);
4047 sc->tulip_pci_devno = pci_get_slot(dev);
4048 sc->tulip_chipid = chipid;
4049 sc->tulip_flags |= TULIP_DEVICEPROBE;
4050 if (chipid == TULIP_21140 || chipid == TULIP_21140A)
4051 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD;
4052 if (chipid == TULIP_21140A && revinfo <= 0x22)
4053 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW;
4054 if (chipid == TULIP_21140)
4055 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH;
4056 if (chipid != TULIP_21040 && chipid != TULIP_21140)
4057 sc->tulip_features |= TULIP_HAVE_POWERMGMT;
4058 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) {
4059 sc->tulip_features |= TULIP_HAVE_DUALSENSE;
4060 if (chipid != TULIP_21041 || revinfo >= 0x20)
4061 sc->tulip_features |= TULIP_HAVE_SIANWAY;
4062 if (chipid != TULIP_21041)
4063 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD;
4064 if (chipid != TULIP_21041 && revinfo >= 0x20)
4065 sc->tulip_features |= TULIP_HAVE_SIA100;
4068 if (sc->tulip_features & TULIP_HAVE_POWERMGMT
4069 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) {
4070 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE);
4071 pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
4074 if_initname(&sc->tulip_if, device_get_name(dev), device_get_unit(dev));
4075 sc->tulip_revinfo = revinfo;
4076 sc->tulip_if.if_softc = sc;
4077 #if defined(TULIP_IOMAPPED)
4079 res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
4082 res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
4086 sc->tulip_csrs_bst = rman_get_bustag(res);
4087 sc->tulip_csrs_bsh = rman_get_bushandle(res);
4090 tulips[device_get_unit(dev)] = sc;
4092 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
4094 sc->tulip_rxdescs = kmalloc(sizeof(tulip_desc_t) * TULIP_RXDESCS,
4095 M_DEVBUF, M_INTWAIT);
4096 sc->tulip_txdescs = kmalloc(sizeof(tulip_desc_t) * TULIP_TXDESCS,
4097 M_DEVBUF, M_INTWAIT);
4099 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS);
4100 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS);
4103 * Make sure there won't be any interrupts or such...
4105 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4106 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
4107 33MHz that comes to two microseconds but wait a
4108 bit longer anyways) */
4110 if ((retval = tulip_read_macaddr(sc)) < 0) {
4111 device_printf(dev, "can't read ENET ROM (why=%d) (", retval);
4112 for (idx = 0; idx < 32; idx++)
4113 kprintf("%02x", sc->tulip_rombuf[idx]);
4115 device_printf(dev, "%s%s pass %d.%d\n",
4116 sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
4117 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
4118 device_printf(dev, "address unknown\n");
4120 void (*intr_rtn)(void *) = tulip_intr_normal;
4122 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
4123 intr_rtn = tulip_intr_shared;
4126 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) {
4130 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
4131 RF_SHAREABLE | RF_ACTIVE);
4132 if (res == NULL || bus_setup_intr(dev, res, INTR_MPSAFE,
4134 sc->tulip_if.if_serializer)) {
4135 device_printf(dev, "couldn't map interrupt\n");
4137 kfree((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
4138 kfree((caddr_t) sc->tulip_txdescs, M_DEVBUF);
4142 ifq_set_cpuid(&sc->tulip_if.if_snd, rman_get_cpuid(res));
4148 static device_method_t tulip_pci_methods[] = {
4149 /* Device interface */
4150 DEVMETHOD(device_probe, tulip_pci_probe),
4151 DEVMETHOD(device_attach, tulip_pci_attach),
4152 DEVMETHOD(device_shutdown, tulip_shutdown),
4155 static driver_t tulip_pci_driver = {
4158 sizeof(tulip_softc_t),
4160 static devclass_t tulip_devclass;
4162 DECLARE_DUMMY_MODULE(if_de);
4163 DRIVER_MODULE(if_de, pci, tulip_pci_driver, tulip_devclass, NULL, NULL);