1 /* $NetBSD: if_de.c,v 1.86 1999/06/01 19:17:59 thorpej Exp $ */
3 /* $FreeBSD: src/sys/pci/if_de.c,v 1.123.2.4 2000/08/04 23:25:09 peter Exp $ */
4 /* $DragonFly: src/sys/dev/netif/de/if_de.c,v 1.49 2008/08/17 04:32:33 sephe Exp $ */
7 * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com)
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * Id: if_de.c,v 1.94 1997/07/03 16:55:07 thomas Exp
34 * DEC 21040 PCI Ethernet Controller
36 * Written by Matt Thomas
37 * BPF support code stolen directly from if_ec.c
39 * This driver supports the DEC DE435 or any other PCI
40 * board which support 21040, 21041, or 21140 (mostly).
43 #include <sys/param.h>
44 #include <sys/systm.h>
46 #include <sys/socket.h>
47 #include <sys/sockio.h>
48 #include <sys/malloc.h>
49 #include <sys/kernel.h>
50 #include <sys/eventhandler.h>
53 #include <sys/thread2.h>
54 #include <sys/interrupt.h>
60 #include <net/if_media.h>
61 #include <net/if_dl.h>
62 #include <net/ifq_var.h>
66 #include <netinet/in.h>
67 #include <netinet/if_ether.h>
71 #include <netproto/ipx/ipx.h>
72 #include <netproto/ipx/ipx_if.h>
77 #include <net/if_var.h>
79 #include <bus/pci/pcivar.h>
80 #include <bus/pci/pcireg.h>
81 #include <bus/pci/dc21040reg.h>
84 * Intel CPUs should use I/O mapped access.
87 #define TULIP_IOMAPPED
94 static tulip_softc_t *tulips[TULIP_MAX_DEVICES];
97 * This module supports
98 * the DEC 21040 PCI Ethernet Controller.
99 * the DEC 21041 PCI Ethernet Controller.
100 * the DEC 21140 PCI Fast Ethernet Controller.
102 static void tulip_mii_autonegotiate(tulip_softc_t *, u_int);
103 static void tulip_intr_shared(void *);
104 static void tulip_intr_normal(void *);
105 static void tulip_init(tulip_softc_t *);
106 static void tulip_reset(tulip_softc_t *);
107 static void tulip_ifstart(struct ifnet *);
108 static struct mbuf *tulip_txput(tulip_softc_t *, struct mbuf *);
109 static void tulip_txput_setup(tulip_softc_t *);
110 static void tulip_rx_intr(tulip_softc_t *);
111 static void tulip_addr_filter(tulip_softc_t *);
112 static u_int tulip_mii_readreg(tulip_softc_t *, u_int, u_int);
113 static void tulip_mii_writereg(tulip_softc_t *, u_int, u_int, u_int);
114 static int tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities);
115 static tulip_media_t tulip_mii_phy_readspecific(tulip_softc_t *);
116 static int tulip_srom_decode(tulip_softc_t *);
117 static int tulip_ifmedia_change(struct ifnet *);
118 static void tulip_ifmedia_status(struct ifnet *, struct ifmediareq *);
119 /* static void tulip_21140_map_media(tulip_softc_t *sc); */
122 tulip_timeout_callback(void *arg)
124 tulip_softc_t *sc = arg;
126 lwkt_serialize_enter(sc->tulip_if.if_serializer);
127 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING;
128 sc->tulip_probe_timeout -= 1000 / TULIP_HZ;
129 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER);
130 lwkt_serialize_exit(sc->tulip_if.if_serializer);
134 tulip_timeout(tulip_softc_t *sc)
136 if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
138 sc->tulip_flags |= TULIP_TIMEOUTPENDING;
139 callout_reset(&sc->tulip_timer, (hz + TULIP_HZ / 2) / TULIP_HZ,
140 tulip_timeout_callback, sc);
144 tulip_txprobe(tulip_softc_t *sc)
149 * Before we are sure this is the right media we need
150 * to send a small packet to make sure there's carrier.
151 * Strangely, BNC and AUI will "see" receive data if
152 * either is connected so the transmit is the only way
153 * to verify the connectivity.
155 MGETHDR(m, MB_DONTWAIT, MT_DATA);
159 * Construct a LLC TEST message which will point to ourselves.
161 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_dhost, 6);
162 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_shost, 6);
163 mtod(m, struct ether_header *)->ether_type = htons(3);
164 mtod(m, unsigned char *)[14] = 0;
165 mtod(m, unsigned char *)[15] = 0;
166 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
167 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
171 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
172 sc->tulip_intrmask |= TULIP_STS_TXINTR;
173 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
174 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
175 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
176 if ((m = tulip_txput(sc, m)) != NULL)
178 sc->tulip_probe.probe_txprobes++;
183 #define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0)
185 #define TULIP_SIAGEN_WATCHDOG 0
189 tulip_media_set(tulip_softc_t *sc, tulip_media_t media)
191 const tulip_media_info_t *mi = sc->tulip_mediums[media];
197 * If we are switching media, make sure we don't think there's
198 * any stale RX activity
200 sc->tulip_flags &= ~TULIP_RXACT;
201 if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
202 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
203 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx);
204 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
205 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
207 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
209 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
211 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity);
212 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
213 #define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL)
215 * If the cmdmode bits don't match the currently operating mode,
216 * set the cmdmode appropriately and reset the chip.
218 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
219 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
220 sc->tulip_cmdmode |= mi->mi_cmdmode;
223 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
225 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata);
226 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
228 * If the cmdmode bits don't match the currently operating mode,
229 * set the cmdmode appropriately and reset the chip.
231 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
232 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
233 sc->tulip_cmdmode |= mi->mi_cmdmode;
236 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol);
237 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata);
238 } else if (mi->mi_type == TULIP_MEDIAINFO_MII
239 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) {
241 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
243 dp = &sc->tulip_rombuf[mi->mi_reset_offset];
244 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) {
246 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
248 sc->tulip_phyaddr = mi->mi_phyaddr;
249 dp = &sc->tulip_rombuf[mi->mi_gpr_offset];
250 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) {
252 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
255 for (idx = 0; idx < mi->mi_reset_length; idx++) {
257 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]);
259 sc->tulip_phyaddr = mi->mi_phyaddr;
260 for (idx = 0; idx < mi->mi_gpr_length; idx++) {
262 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]);
265 if (sc->tulip_flags & TULIP_TRYNWAY) {
266 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
267 } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
268 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL);
269 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE);
270 sc->tulip_flags &= ~TULIP_DIDNWAY;
271 if (TULIP_IS_MEDIA_FD(media))
272 data |= PHYCTL_FULL_DUPLEX;
273 if (TULIP_IS_MEDIA_100MB(media))
274 data |= PHYCTL_SELECT_100MB;
275 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data);
281 tulip_linkup(tulip_softc_t *sc, tulip_media_t media)
283 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
284 sc->tulip_flags |= TULIP_PRINTLINKUP;
285 sc->tulip_flags |= TULIP_LINKUP;
286 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
287 #if 0 /* XXX how does with work with ifmedia? */
288 if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
289 if (sc->tulip_if.if_flags & IFF_FULLDUPLEX) {
290 if (TULIP_CAN_MEDIA_FD(media)
291 && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL)
292 media = TULIP_FD_MEDIA_OF(media);
294 if (TULIP_IS_MEDIA_FD(media)
295 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL)
296 media = TULIP_HD_MEDIA_OF(media);
300 if (sc->tulip_media != media) {
301 sc->tulip_media = media;
302 sc->tulip_flags |= TULIP_PRINTMEDIA;
303 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) {
304 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
305 } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) {
306 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
310 * We could set probe_timeout to 0 but setting to 3000 puts this
311 * in one central place and the only matters is tulip_link is
312 * followed by a tulip_timeout. Therefore setting it should not
313 * result in aberrant behavour.
315 sc->tulip_probe_timeout = 3000;
316 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
317 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY);
318 if (sc->tulip_flags & TULIP_INRESET) {
319 tulip_media_set(sc, sc->tulip_media);
320 } else if (sc->tulip_probe_media != sc->tulip_media) {
322 * No reason to change media if we have the right media.
330 tulip_media_print(tulip_softc_t *sc)
332 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
334 if (sc->tulip_flags & TULIP_PRINTMEDIA) {
335 if_printf(&sc->tulip_if, "enabling %s port\n",
336 tulip_mediums[sc->tulip_media]);
337 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
338 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
339 if_printf(&sc->tulip_if, "link up\n");
340 sc->tulip_flags &= ~TULIP_PRINTLINKUP;
344 #if defined(TULIP_DO_GPR_SENSE)
346 tulip_21140_gpr_media_sense(tulip_softc_t *sc)
348 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
349 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
353 * If one of the media blocks contained a default media flag,
356 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
357 const tulip_media_info_t *mi;
359 * Media is not supported (or is full-duplex).
361 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media))
363 if (mi->mi_type != TULIP_MEDIAINFO_GPR)
367 * Remember the media is this is the "default" media.
369 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
373 * No activity mask? Can't see if it is active if there's no mask.
375 if (mi->mi_actmask == 0)
379 * Does the activity data match?
381 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
385 * It does! If this is the first media we detected, then
386 * remember this media. If isn't the first, then there were
387 * multiple matches which we equate to no match (since we don't
388 * which to select (if any).
390 if (last_media == TULIP_MEDIA_UNKNOWN) {
392 } else if (last_media != media) {
393 last_media = TULIP_MEDIA_UNKNOWN;
396 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
398 #endif /* TULIP_DO_GPR_SENSE */
400 static tulip_link_status_t
401 tulip_media_link_monitor(tulip_softc_t *sc)
403 const tulip_media_info_t *mi = sc->tulip_mediums[sc->tulip_media];
404 tulip_link_status_t linkup = TULIP_LINK_DOWN;
407 #if defined(DIAGNOSTIC)
408 panic("tulip_media_link_monitor: %s: botch at line %d\n",
409 tulip_mediums[sc->tulip_media],__LINE__);
411 return TULIP_LINK_UNKNOWN;
416 * Have we seen some packets? If so, the link must be good.
418 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) {
419 sc->tulip_flags &= ~TULIP_RXACT;
420 sc->tulip_probe_timeout = 3000;
421 return TULIP_LINK_UP;
424 sc->tulip_flags &= ~TULIP_RXACT;
425 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
428 * Read the PHY status register.
430 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
431 if (status & PHYSTS_AUTONEG_DONE) {
433 * If the PHY has completed autonegotiation, see the if the
434 * remote systems abilities have changed. If so, upgrade or
435 * downgrade as appropriate.
437 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
438 abilities = (abilities << 6) & status;
439 if (abilities != sc->tulip_abilities) {
440 if (tulip_mii_map_abilities(sc, abilities)) {
441 tulip_linkup(sc, sc->tulip_probe_media);
442 return TULIP_LINK_UP;
445 * if we had selected media because of autonegotiation,
446 * we need to probe for the new media.
448 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
449 if (sc->tulip_flags & TULIP_DIDNWAY)
450 return TULIP_LINK_DOWN;
454 * The link is now up. If was down, say its back up.
456 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP)
457 linkup = TULIP_LINK_UP;
458 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
460 * No activity sensor? Assume all's well.
462 if (mi->mi_actmask == 0)
463 return TULIP_LINK_UNKNOWN;
465 * Does the activity data match?
467 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata)
468 linkup = TULIP_LINK_UP;
469 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
471 * Assume non TP ok for now.
473 if (!TULIP_IS_MEDIA_TP(sc->tulip_media))
474 return TULIP_LINK_UNKNOWN;
475 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
476 linkup = TULIP_LINK_UP;
477 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
478 return TULIP_LINK_UNKNOWN;
481 * We will wait for 3 seconds until the link goes into suspect mode.
483 if (sc->tulip_flags & TULIP_LINKUP) {
484 if (linkup == TULIP_LINK_UP)
485 sc->tulip_probe_timeout = 3000;
486 if (sc->tulip_probe_timeout > 0)
487 return TULIP_LINK_UP;
489 sc->tulip_flags &= ~TULIP_LINKUP;
490 if_printf(&sc->tulip_if, "link down: cable problem?\n");
492 return TULIP_LINK_DOWN;
496 tulip_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
498 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
499 && event == TULIP_MEDIAPOLL_TIMER) {
500 switch (tulip_media_link_monitor(sc)) {
501 case TULIP_LINK_DOWN: {
503 * Link Monitor failed. Probe for new media.
505 event = TULIP_MEDIAPOLL_LINKFAIL;
508 case TULIP_LINK_UP: {
515 case TULIP_LINK_UNKNOWN: {
517 * We can't tell so don't bother.
524 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
525 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
526 if (TULIP_DO_AUTOSENSE(sc)) {
527 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
528 if (sc->tulip_if.if_flags & IFF_UP)
529 tulip_reset(sc); /* restart probe */
535 if (event == TULIP_MEDIAPOLL_START) {
536 sc->tulip_if.if_flags |= IFF_OACTIVE;
537 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
539 sc->tulip_probe_mediamask = 0;
540 sc->tulip_probe_passes = 0;
542 * If the SROM contained an explicit media to use, use it.
544 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX);
545 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS;
546 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
548 * connidx is defaulted to a media_unknown type.
550 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media;
551 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) {
552 tulip_linkup(sc, sc->tulip_probe_media);
557 if (sc->tulip_features & TULIP_HAVE_GPR) {
558 sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
559 sc->tulip_probe_timeout = 2000;
561 sc->tulip_probe_media = TULIP_MEDIA_MAX;
562 sc->tulip_probe_timeout = 0;
563 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
568 * Ignore txprobe failures or spurious callbacks.
570 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED
571 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) {
572 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
577 * If we really transmitted a packet, then that's the media we'll use.
579 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) {
580 if (event == TULIP_MEDIAPOLL_LINKPASS) {
581 /* XXX Check media status just to be sure */
582 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
584 tulip_linkup(sc, sc->tulip_probe_media);
589 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) {
590 #if defined(TULIP_DO_GPR_SENSE)
592 * Check for media via the general purpose register.
594 * Try to sense the media via the GPR. If the same value
595 * occurs 3 times in a row then just use that.
597 if (sc->tulip_probe_timeout > 0) {
598 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
599 if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
600 if (new_probe_media == sc->tulip_probe_media) {
601 if (--sc->tulip_probe_count == 0)
602 tulip_linkup(sc, sc->tulip_probe_media);
604 sc->tulip_probe_count = 10;
607 sc->tulip_probe_media = new_probe_media;
611 #endif /* TULIP_DO_GPR_SENSE */
613 * Brute force. We cycle through each of the media types
614 * and try to transmit a packet.
616 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
617 sc->tulip_probe_media = TULIP_MEDIA_MAX;
618 sc->tulip_probe_timeout = 0;
623 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST
624 && (sc->tulip_features & TULIP_HAVE_MII)) {
625 tulip_media_t old_media = sc->tulip_probe_media;
626 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
627 switch (sc->tulip_probe_state) {
628 case TULIP_PROBE_FAILED:
629 case TULIP_PROBE_MEDIATEST: {
631 * Try the next media.
633 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask;
634 sc->tulip_probe_timeout = 0;
636 if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
638 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
640 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
644 case TULIP_PROBE_PHYAUTONEG: {
647 case TULIP_PROBE_INACTIVE: {
649 * Only probe if we autonegotiated a media that hasn't failed.
651 sc->tulip_probe_timeout = 0;
652 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) {
653 sc->tulip_probe_media = old_media;
656 tulip_linkup(sc, sc->tulip_probe_media);
661 #if defined(DIAGNOSTIC)
662 panic("tulip_media_poll: botch at line %d\n", __LINE__);
669 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
670 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
675 * switch to another media if we tried this one enough.
677 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
679 * Find the next media type to check for. Full Duplex
680 * types are not allowed.
683 sc->tulip_probe_media -= 1;
684 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
685 if (++sc->tulip_probe_passes == 3) {
686 if_printf(&sc->tulip_if, "autosense failed: cable problem?\n");
687 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
688 sc->tulip_if.if_flags &= ~IFF_RUNNING;
689 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
693 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */
694 sc->tulip_probe_mediamask = 0;
695 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1;
697 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL
698 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
699 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
701 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
702 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
703 sc->tulip_probe.probe_txprobes = 0;
705 tulip_media_set(sc, sc->tulip_probe_media);
706 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
711 * If this is hanging off a phy, we know are doing NWAY and we have
712 * forced the phy to a specific speed. Wait for link up before
713 * before sending a packet.
715 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) {
716 case TULIP_MEDIAINFO_MII: {
717 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
721 case TULIP_MEDIAINFO_SIA: {
722 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) {
723 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL)
725 tulip_linkup(sc, sc->tulip_probe_media);
727 if (sc->tulip_features & TULIP_HAVE_MII)
734 case TULIP_MEDIAINFO_RESET:
735 case TULIP_MEDIAINFO_SYM:
736 case TULIP_MEDIAINFO_NONE:
737 case TULIP_MEDIAINFO_GPR: {
742 * Try to send a packet.
748 tulip_media_select(tulip_softc_t *sc)
750 if (sc->tulip_features & TULIP_HAVE_GPR) {
751 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
753 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata);
756 * If this board has no media, just return
758 if (sc->tulip_features & TULIP_HAVE_NOMEDIA)
761 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
762 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
763 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START);
765 tulip_media_set(sc, sc->tulip_media);
770 tulip_21040_mediainfo_init(tulip_softc_t *sc, tulip_media_t media)
772 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
773 |TULIP_CMD_BACKOFFCTR;
774 sc->tulip_if.if_baudrate = 10000000;
776 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) {
777 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET);
778 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD);
779 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
782 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) {
783 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC);
786 if (media == TULIP_MEDIA_UNKNOWN) {
787 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA);
792 tulip_21040_media_probe(tulip_softc_t *sc)
794 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
798 tulip_21040_10baset_only_media_probe(tulip_softc_t *sc)
800 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
801 tulip_media_set(sc, TULIP_MEDIA_10BASET);
802 sc->tulip_media = TULIP_MEDIA_10BASET;
806 tulip_21040_10baset_only_media_select(tulip_softc_t *sc)
808 sc->tulip_flags |= TULIP_LINKUP;
809 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
810 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
811 sc->tulip_flags &= ~TULIP_SQETEST;
813 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
814 sc->tulip_flags |= TULIP_SQETEST;
816 tulip_media_set(sc, sc->tulip_media);
820 tulip_21040_auibnc_only_media_probe(tulip_softc_t *sc)
822 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
823 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
824 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
825 sc->tulip_media = TULIP_MEDIA_AUIBNC;
829 tulip_21040_auibnc_only_media_select(tulip_softc_t *sc)
831 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
832 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
835 static const tulip_boardsw_t tulip_21040_boardsw = {
837 tulip_21040_media_probe,
842 static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = {
844 tulip_21040_10baset_only_media_probe,
845 tulip_21040_10baset_only_media_select,
849 static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = {
851 tulip_21040_auibnc_only_media_probe,
852 tulip_21040_auibnc_only_media_select,
857 tulip_21041_mediainfo_init(tulip_softc_t *sc)
859 tulip_media_info_t *mi = sc->tulip_mediainfo;
862 if (sc->tulip_revinfo >= 0x20) {
863 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET);
864 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD);
865 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI);
866 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC);
870 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET);
871 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD);
872 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
873 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
877 tulip_21041_media_probe(tulip_softc_t *sc)
879 sc->tulip_if.if_baudrate = 10000000;
880 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
881 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
882 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
883 tulip_21041_mediainfo_init(sc);
887 tulip_21041_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
891 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
892 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
893 || !TULIP_DO_AUTOSENSE(sc))
895 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
896 tulip_reset(sc); /* start probe */
901 * If we've been been asked to start a poll or link change interrupt
902 * restart the probe (and reset the tulip to a known state).
904 if (event == TULIP_MEDIAPOLL_START) {
905 sc->tulip_if.if_flags |= IFF_OACTIVE;
906 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN);
908 if (sc->tulip_revinfo >= 0x20) {
909 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
910 sc->tulip_flags |= TULIP_DIDNWAY;
913 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
914 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
915 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
916 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT;
917 tulip_media_set(sc, TULIP_MEDIA_10BASET);
922 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
925 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
926 tulip_linkup(sc, sc->tulip_probe_media);
930 sia_status = TULIP_CSR_READ(sc, csr_sia_status);
931 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status);
932 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) {
933 if (sc->tulip_revinfo >= 0x20) {
934 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6)))
935 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
938 * If the link has passed LinkPass, 10baseT is the
939 * proper media to use.
941 tulip_linkup(sc, sc->tulip_probe_media);
946 * wait for up to 2.4 seconds for the link to reach pass state.
947 * Only then start scanning the other media for activity.
948 * choose media with receive activity over those without.
950 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) {
951 if (event != TULIP_MEDIAPOLL_TIMER)
953 if (sc->tulip_probe_timeout > 0
954 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
958 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
959 sc->tulip_flags |= TULIP_WANTRXACT;
960 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) {
961 sc->tulip_probe_media = TULIP_MEDIA_BNC;
963 sc->tulip_probe_media = TULIP_MEDIA_AUI;
965 tulip_media_set(sc, sc->tulip_probe_media);
971 * If we failed, clear the txprobe active flag.
973 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED)
974 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
977 if (event == TULIP_MEDIAPOLL_TIMER) {
979 * If we've received something, then that's our link!
981 if (sc->tulip_flags & TULIP_RXACT) {
982 tulip_linkup(sc, sc->tulip_probe_media);
986 * if no txprobe active
988 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0
989 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0
990 || (sia_status & TULIP_SIASTS_RXACTIVITY))) {
991 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
997 * Take 2 passes through before deciding to not
998 * wait for receive activity. Then take another
999 * two passes before spitting out a warning.
1001 if (sc->tulip_probe_timeout <= 0) {
1002 if (sc->tulip_flags & TULIP_WANTRXACT) {
1003 sc->tulip_flags &= ~TULIP_WANTRXACT;
1004 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1006 if_printf(&sc->tulip_if, "autosense failed: cable problem?\n");
1007 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
1008 sc->tulip_if.if_flags &= ~IFF_RUNNING;
1009 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1017 * Since this media failed to probe, try the other one.
1019 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1020 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) {
1021 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1023 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1025 tulip_media_set(sc, sc->tulip_probe_media);
1026 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1030 static const tulip_boardsw_t tulip_21041_boardsw = {
1031 TULIP_21041_GENERIC,
1032 tulip_21041_media_probe,
1034 tulip_21041_media_poll
1037 static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
1038 { 0x20005c00, 0, /* 08-00-17 */
1040 { 0x19, 0x0040, 0x0040 }, /* 10TX */
1041 { 0x19, 0x0040, 0x0000 }, /* 100TX */
1044 { 0x0281F400, 0, /* 00-A0-7D */
1046 { 0x12, 0x0010, 0x0000 }, /* 10T */
1048 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1049 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1053 { 0x0015F420, 0, /* 00-A0-7D */
1055 { 0x12, 0x0010, 0x0000 }, /* 10T */
1057 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1058 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1062 { 0x0281F400, 0, /* 00-A0-BE */
1064 { 0x11, 0x8000, 0x0000 }, /* 10T */
1065 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1067 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1073 static tulip_media_t
1074 tulip_mii_phy_readspecific(tulip_softc_t *sc)
1076 const tulip_phy_attr_t *attr;
1080 static const tulip_media_t table[] = {
1081 TULIP_MEDIA_UNKNOWN,
1082 TULIP_MEDIA_10BASET,
1083 TULIP_MEDIA_100BASETX,
1084 TULIP_MEDIA_100BASET4,
1085 TULIP_MEDIA_UNKNOWN,
1086 TULIP_MEDIA_10BASET_FD,
1087 TULIP_MEDIA_100BASETX_FD,
1092 * Don't read phy specific registers if link is not up.
1094 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
1095 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS))
1096 return TULIP_MEDIA_UNKNOWN;
1098 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) |
1099 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH);
1100 for (attr = tulip_mii_phy_attrlist;; attr++) {
1101 if (attr->attr_id == 0)
1102 return TULIP_MEDIA_UNKNOWN;
1103 if ((id & ~0x0F) == attr->attr_id)
1107 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
1108 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_100TX];
1109 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1110 if ((data & pm->pm_mask) == pm->pm_value)
1113 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) {
1114 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_100T4];
1115 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1116 if ((data & pm->pm_mask) == pm->pm_value)
1119 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) {
1120 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_10T];
1121 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1122 if ((data & pm->pm_mask) == pm->pm_value)
1125 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) {
1126 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
1127 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1128 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
1134 tulip_mii_get_phyaddr(tulip_softc_t *sc, u_int offset)
1138 for (phyaddr = 1; phyaddr < 32; phyaddr++) {
1139 u_int status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1140 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1147 u_int status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
1148 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1149 return TULIP_MII_NOPHY;
1152 return TULIP_MII_NOPHY;
1156 tulip_mii_map_abilities(tulip_softc_t *sc, u_int abilities)
1158 sc->tulip_abilities = abilities;
1159 if (abilities & PHYSTS_100BASETX_FD) {
1160 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD;
1161 } else if (abilities & PHYSTS_100BASET4) {
1162 sc->tulip_probe_media = TULIP_MEDIA_100BASET4;
1163 } else if (abilities & PHYSTS_100BASETX) {
1164 sc->tulip_probe_media = TULIP_MEDIA_100BASETX;
1165 } else if (abilities & PHYSTS_10BASET_FD) {
1166 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1167 } else if (abilities & PHYSTS_10BASET) {
1168 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1170 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1173 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1178 tulip_mii_autonegotiate(tulip_softc_t *sc, u_int phyaddr)
1180 switch (sc->tulip_probe_state) {
1181 case TULIP_PROBE_MEDIATEST:
1182 case TULIP_PROBE_INACTIVE: {
1183 sc->tulip_flags |= TULIP_DIDNWAY;
1184 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET);
1185 sc->tulip_probe_timeout = 3000;
1186 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR;
1187 sc->tulip_probe_state = TULIP_PROBE_PHYRESET;
1190 case TULIP_PROBE_PHYRESET: {
1192 uint32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1193 if (data & PHYCTL_RESET) {
1194 if (sc->tulip_probe_timeout > 0) {
1198 if_printf(&sc->tulip_if,
1199 "(phy%d): error: reset of PHY never completed!\n", phyaddr);
1200 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1201 sc->tulip_probe_state = TULIP_PROBE_FAILED;
1202 sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
1205 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1206 if ((status & PHYSTS_CAN_AUTONEG) == 0) {
1207 sc->tulip_flags &= ~TULIP_DIDNWAY;
1208 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1211 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01))
1212 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
1213 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
1214 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1215 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
1216 sc->tulip_probe_timeout = 3000;
1219 case TULIP_PROBE_PHYAUTONEG: {
1220 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1222 if ((status & PHYSTS_AUTONEG_DONE) == 0) {
1223 if (sc->tulip_probe_timeout > 0) {
1227 sc->tulip_flags &= ~TULIP_DIDNWAY;
1228 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1231 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
1232 data = (data << 6) & status;
1233 if (!tulip_mii_map_abilities(sc, data))
1234 sc->tulip_flags &= ~TULIP_DIDNWAY;
1238 #if defined(DIAGNOSTIC)
1239 panic("tulip_media_poll: botch at line %d\n", __LINE__);
1247 tulip_2114x_media_preset(tulip_softc_t *sc)
1249 const tulip_media_info_t *mi = NULL;
1250 tulip_media_t media;
1252 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1253 media = sc->tulip_media;
1255 media = sc->tulip_probe_media;
1257 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
1258 sc->tulip_flags &= ~TULIP_SQETEST;
1259 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
1260 mi = sc->tulip_mediums[media];
1261 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
1262 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1263 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR
1264 || mi->mi_type == TULIP_MEDIAINFO_SYM) {
1265 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
1266 sc->tulip_cmdmode |= mi->mi_cmdmode;
1267 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
1268 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
1272 case TULIP_MEDIA_BNC:
1273 case TULIP_MEDIA_AUI:
1274 case TULIP_MEDIA_10BASET: {
1275 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1276 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
1277 sc->tulip_if.if_baudrate = 10000000;
1278 sc->tulip_flags |= TULIP_SQETEST;
1281 case TULIP_MEDIA_10BASET_FD: {
1282 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
1283 sc->tulip_if.if_baudrate = 10000000;
1286 case TULIP_MEDIA_100BASEFX:
1287 case TULIP_MEDIA_100BASET4:
1288 case TULIP_MEDIA_100BASETX: {
1289 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL);
1290 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1291 sc->tulip_if.if_baudrate = 100000000;
1294 case TULIP_MEDIA_100BASEFX_FD:
1295 case TULIP_MEDIA_100BASETX_FD: {
1296 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT;
1297 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
1298 sc->tulip_if.if_baudrate = 100000000;
1305 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1309 ********************************************************************
1310 * Start of 21140/21140A support which does not use the MII interface
1314 tulip_null_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
1316 #if defined(DIAGNOSTIC)
1317 if_printf(&sc->tulip_if, "botch(media_poll) at line %d\n", __LINE__);
1322 tulip_21140_mediainit(tulip_softc_t *sc, tulip_media_info_t *mip,
1323 tulip_media_t media, u_int gpdata, u_int cmdmode)
1325 sc->tulip_mediums[media] = mip;
1326 mip->mi_type = TULIP_MEDIAINFO_GPR;
1327 mip->mi_cmdmode = cmdmode;
1328 mip->mi_gpdata = gpdata;
1332 tulip_21140_evalboard_media_probe(tulip_softc_t *sc)
1334 tulip_media_info_t *mip = sc->tulip_mediainfo;
1336 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1337 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1338 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1339 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1340 TULIP_CSR_WRITE(sc, csr_command,
1341 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1342 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1343 TULIP_CSR_WRITE(sc, csr_command,
1344 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1346 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
1347 sc->tulip_media = TULIP_MEDIA_10BASET;
1349 sc->tulip_media = TULIP_MEDIA_100BASETX;
1351 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1353 TULIP_CMD_TXTHRSHLDCTL);
1354 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1356 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1357 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1359 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1360 |TULIP_CMD_SCRAMBLER);
1361 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1363 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1364 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1367 static const tulip_boardsw_t tulip_21140_eb_boardsw = {
1369 tulip_21140_evalboard_media_probe,
1371 tulip_null_media_poll,
1372 tulip_2114x_media_preset,
1376 tulip_21140_accton_media_probe(tulip_softc_t *sc)
1378 tulip_media_info_t *mip = sc->tulip_mediainfo;
1381 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1382 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1383 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1384 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1385 TULIP_CSR_WRITE(sc, csr_command,
1386 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1387 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1388 TULIP_CSR_WRITE(sc, csr_command,
1389 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1391 gpdata = TULIP_CSR_READ(sc, csr_gp);
1392 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) {
1393 sc->tulip_media = TULIP_MEDIA_10BASET;
1395 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) {
1396 sc->tulip_media = TULIP_MEDIA_BNC;
1398 sc->tulip_media = TULIP_MEDIA_100BASETX;
1401 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC,
1402 TULIP_GP_EN1207_BNC_INIT,
1403 TULIP_CMD_TXTHRSHLDCTL);
1404 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1405 TULIP_GP_EN1207_UTP_INIT,
1406 TULIP_CMD_TXTHRSHLDCTL);
1407 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1408 TULIP_GP_EN1207_UTP_INIT,
1409 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1410 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1411 TULIP_GP_EN1207_100_INIT,
1412 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1413 |TULIP_CMD_SCRAMBLER);
1414 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1415 TULIP_GP_EN1207_100_INIT,
1416 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1417 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1420 static const tulip_boardsw_t tulip_21140_accton_boardsw = {
1422 tulip_21140_accton_media_probe,
1424 tulip_null_media_poll,
1425 tulip_2114x_media_preset,
1429 tulip_21140_smc9332_media_probe(tulip_softc_t *sc)
1431 tulip_media_info_t *mip = sc->tulip_mediainfo;
1434 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE);
1435 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
1436 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
1437 33MHz that comes to two microseconds but wait a
1438 bit longer anyways) */
1439 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT |
1440 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1441 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS;
1442 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT;
1443 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET);
1444 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT);
1446 for (idx = 1000; idx > 0; idx--) {
1447 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1448 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) {
1451 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
1458 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1459 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1460 TULIP_GP_SMC_9332_INIT,
1461 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1462 |TULIP_CMD_SCRAMBLER);
1463 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1464 TULIP_GP_SMC_9332_INIT,
1465 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1466 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1467 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1468 TULIP_GP_SMC_9332_INIT,
1469 TULIP_CMD_TXTHRSHLDCTL);
1470 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1471 TULIP_GP_SMC_9332_INIT,
1472 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1475 static const tulip_boardsw_t tulip_21140_smc9332_boardsw = {
1476 TULIP_21140_SMC_9332,
1477 tulip_21140_smc9332_media_probe,
1479 tulip_null_media_poll,
1480 tulip_2114x_media_preset,
1484 tulip_21140_cogent_em100_media_probe(tulip_softc_t *sc)
1486 tulip_media_info_t *mip = sc->tulip_mediainfo;
1489 sc->tulip_gpinit = TULIP_GP_EM100_PINS;
1490 sc->tulip_gpdata = TULIP_GP_EM100_INIT;
1491 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS);
1492 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT);
1494 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE;
1495 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER);
1496 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1497 TULIP_CSR_WRITE(sc, csr_command, cmdmode);
1498 sc->tulip_media = TULIP_MEDIA_100BASEFX;
1500 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX,
1501 TULIP_GP_EM100_INIT,
1502 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION);
1503 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD,
1504 TULIP_GP_EM100_INIT,
1505 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1506 |TULIP_CMD_FULLDUPLEX);
1508 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);
1509 sc->tulip_media = TULIP_MEDIA_100BASETX;
1510 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1511 TULIP_GP_EM100_INIT,
1512 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1513 |TULIP_CMD_SCRAMBLER);
1514 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1515 TULIP_GP_EM100_INIT,
1516 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1517 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1521 static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {
1522 TULIP_21140_COGENT_EM100,
1523 tulip_21140_cogent_em100_media_probe,
1525 tulip_null_media_poll,
1526 tulip_2114x_media_preset
1530 tulip_21140_znyx_zx34x_media_probe(tulip_softc_t *sc)
1532 tulip_media_info_t *mip = sc->tulip_mediainfo;
1533 int cnt10 = 0, cnt100 = 0, idx;
1535 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS;
1536 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT;
1537 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS);
1538 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT);
1539 TULIP_CSR_WRITE(sc, csr_command,
1540 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1541 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1542 TULIP_CSR_WRITE(sc, csr_command,
1543 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1546 for (idx = 1000; idx > 0; idx--) {
1547 uint32_t csr = TULIP_CSR_READ(sc, csr_gp);
1548 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)) {
1551 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
1560 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1561 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1562 TULIP_GP_ZX34X_INIT,
1563 TULIP_CMD_TXTHRSHLDCTL);
1564 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1565 TULIP_GP_ZX34X_INIT,
1566 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1567 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1568 TULIP_GP_ZX34X_INIT,
1569 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1570 |TULIP_CMD_SCRAMBLER);
1571 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1572 TULIP_GP_ZX34X_INIT,
1573 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1574 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1577 static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = {
1578 TULIP_21140_ZNYX_ZX34X,
1579 tulip_21140_znyx_zx34x_media_probe,
1581 tulip_null_media_poll,
1582 tulip_2114x_media_preset,
1586 tulip_2114x_media_probe(tulip_softc_t *sc)
1588 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE | TULIP_CMD_BACKOFFCTR |
1589 TULIP_CMD_THRSHLD72;
1592 static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
1594 tulip_2114x_media_probe,
1597 tulip_2114x_media_preset,
1601 * ******** END of chip-specific handlers. ***********
1605 * Code the read the SROM and MII bit streams (I2C)
1608 TULIP_CSR_WRITE(sc, csr_srom_mii, csr); \
1613 tulip_srom_idle(tulip_softc_t *sc)
1617 csr = SROMSEL ; EMIT;
1618 csr = SROMSEL | SROMRD; EMIT;
1619 csr ^= SROMCS; EMIT;
1620 csr ^= SROMCLKON; EMIT;
1623 * Write 25 cycles of 0 which will force the SROM to be idle.
1625 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1626 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1627 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1629 csr ^= SROMCLKOFF; EMIT;
1630 csr ^= SROMCS; EMIT;
1636 tulip_srom_read(tulip_softc_t *sc)
1638 const u_int bitwidth = SROM_BITWIDTH;
1639 const u_int cmdmask = (SROMCMD_RD << bitwidth);
1640 const u_int msb = 1 << (bitwidth + 3 - 1);
1641 u_int idx, lastidx = (1 << bitwidth) - 1;
1643 tulip_srom_idle(sc);
1645 for (idx = 0; idx <= lastidx; idx++) {
1646 u_int lastbit, data, bits, bit, csr;
1647 csr = SROMSEL ; EMIT;
1648 csr = SROMSEL | SROMRD; EMIT;
1649 csr ^= SROMCSON; EMIT;
1650 csr ^= SROMCLKON; EMIT;
1653 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
1654 u_int thisbit = bits & msb;
1655 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1656 if (thisbit != lastbit) {
1657 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1661 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1664 csr ^= SROMCLKOFF; EMIT;
1666 for (data = 0, bits = 0; bits < 16; bits++) {
1668 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1669 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1670 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1672 sc->tulip_rombuf[idx*2] = data & 0xFF;
1673 sc->tulip_rombuf[idx*2+1] = data >> 8;
1674 csr = SROMSEL | SROMRD; EMIT;
1677 tulip_srom_idle(sc);
1680 #define MII_EMIT do { \
1681 TULIP_CSR_WRITE(sc, csr_srom_mii, csr); \
1686 tulip_mii_writebits(tulip_softc_t *sc, u_int data, u_int bits)
1688 u_int csr, msb, lastbit;
1690 msb = 1 << (bits - 1);
1691 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1692 lastbit = (csr & MII_DOUT) ? msb : 0;
1693 csr |= MII_WR; MII_EMIT; /* clock low; assert write */
1695 for (; bits > 0; bits--, data <<= 1) {
1696 const unsigned thisbit = data & msb;
1697 if (thisbit != lastbit) {
1698 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */
1700 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1702 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1707 tulip_mii_turnaround(tulip_softc_t *sc, u_int cmd)
1711 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1713 if (cmd == MII_WRCMD) {
1714 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
1715 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1716 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1717 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */
1719 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */
1721 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1722 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1726 tulip_mii_readbits(tulip_softc_t *sc)
1728 u_int csr, data, idx;
1730 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1732 for (idx = 0, data = 0; idx < 16; idx++) {
1733 data <<= 1; /* this is NOOP on the first pass through */
1734 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1735 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)
1737 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1739 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
1745 tulip_mii_readreg(tulip_softc_t *sc, u_int devaddr, u_int regno)
1750 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1751 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1752 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1753 tulip_mii_writebits(sc, MII_RDCMD, 8);
1754 tulip_mii_writebits(sc, devaddr, 5);
1755 tulip_mii_writebits(sc, regno, 5);
1756 tulip_mii_turnaround(sc, MII_RDCMD);
1758 data = tulip_mii_readbits(sc);
1763 tulip_mii_writereg(tulip_softc_t *sc, u_int devaddr, u_int regno, u_int data)
1767 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1768 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1769 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1770 tulip_mii_writebits(sc, MII_WRCMD, 8);
1771 tulip_mii_writebits(sc, devaddr, 5);
1772 tulip_mii_writebits(sc, regno, 5);
1773 tulip_mii_turnaround(sc, MII_WRCMD);
1774 tulip_mii_writebits(sc, data, 16);
1777 #define tulip_mchash(mca) (ether_crc32_le(mca, 6) & 0x1FF)
1778 #define tulip_srom_crcok(databuf) ( \
1779 ((ether_crc32_le(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
1780 ((databuf)[126] | ((databuf)[127] << 8)))
1783 tulip_identify_dec_nic(tulip_softc_t *sc)
1785 strcpy(sc->tulip_boardid, "DEC ");
1787 if (sc->tulip_chipid <= TULIP_21040)
1789 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0
1790 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {
1791 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);
1792 sc->tulip_boardid[D0+8] = ' ';
1798 tulip_identify_znyx_nic(tulip_softc_t * const sc)
1801 strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
1802 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
1804 sc->tulip_boardid[8] = '4';
1805 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
1806 if (znyx_ptr < 26 || znyx_ptr > 116) {
1807 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1810 /* ZX344 = 0010 .. 0013FF
1812 if (sc->tulip_rombuf[znyx_ptr] == 0x4A
1813 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52
1814 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) {
1815 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4];
1816 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) {
1817 sc->tulip_boardid[9] = '2';
1818 if (id == TULIP_ZNYX_ID_ZX342B) {
1819 sc->tulip_boardid[10] = 'B';
1820 sc->tulip_boardid[11] = ' ';
1822 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1823 } else if (id == TULIP_ZNYX_ID_ZX344) {
1824 sc->tulip_boardid[10] = '4';
1825 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1826 } else if (id == TULIP_ZNYX_ID_ZX345) {
1827 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5';
1828 } else if (id == TULIP_ZNYX_ID_ZX346) {
1829 sc->tulip_boardid[9] = '6';
1830 } else if (id == TULIP_ZNYX_ID_ZX351) {
1831 sc->tulip_boardid[8] = '5';
1832 sc->tulip_boardid[9] = '1';
1837 * Assume it's a ZX342...
1839 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1843 sc->tulip_boardid[8] = '1';
1844 if (sc->tulip_chipid == TULIP_21041) {
1845 sc->tulip_boardid[10] = '1';
1848 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) {
1849 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36];
1850 if (id == TULIP_ZNYX_ID_ZX312T) {
1851 sc->tulip_boardid[9] = '2';
1852 sc->tulip_boardid[10] = 'T';
1853 sc->tulip_boardid[11] = ' ';
1854 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1855 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) {
1856 sc->tulip_boardid[9] = '4';
1857 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1858 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1859 } else if (id == TULIP_ZNYX_ID_ZX314) {
1860 sc->tulip_boardid[9] = '4';
1861 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1862 sc->tulip_features |= TULIP_HAVE_BASEROM;
1863 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) {
1864 sc->tulip_boardid[9] = '5';
1865 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1866 } else if (id == TULIP_ZNYX_ID_ZX315) {
1867 sc->tulip_boardid[9] = '5';
1868 sc->tulip_features |= TULIP_HAVE_BASEROM;
1874 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) {
1875 sc->tulip_boardid[9] = '4';
1876 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1877 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1878 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) {
1879 sc->tulip_boardid[9] = '5';
1880 sc->tulip_boardsw = &tulip_21040_boardsw;
1881 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1882 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) {
1883 sc->tulip_boardid[9] = '2';
1884 sc->tulip_boardsw = &tulip_21040_boardsw;
1890 tulip_identify_smc_nic(tulip_softc_t * const sc)
1892 uint32_t id1, id2, ei;
1893 int auibnc = 0, utp = 0;
1896 strcpy(sc->tulip_boardid, "SMC ");
1897 if (sc->tulip_chipid == TULIP_21041)
1899 if (sc->tulip_chipid != TULIP_21040) {
1900 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
1901 strcpy(&sc->tulip_boardid[4], "9332DST ");
1902 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;
1903 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {
1904 strcpy(&sc->tulip_boardid[4], "9334BDT ");
1906 strcpy(&sc->tulip_boardid[4], "9332BDT ");
1910 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);
1911 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);
1912 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);
1914 strcpy(&sc->tulip_boardid[4], "8432");
1915 cp = &sc->tulip_boardid[8];
1917 *cp++ = 'B', auibnc = 1;
1918 if ((id1 & 0xFF) > 0x32)
1919 *cp++ = 'T', utp = 1;
1920 if ((id1 & 0x4000) == 0)
1921 *cp++ = 'A', auibnc = 1;
1923 sc->tulip_boardid[7] = '4';
1927 *cp++ = (ei ? '2' : '1');
1932 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1933 else if (!utp && auibnc)
1934 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
1938 tulip_identify_cogent_nic(tulip_softc_t * const sc)
1940 strcpy(sc->tulip_boardid, "Cogent ");
1941 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
1942 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {
1943 strcat(sc->tulip_boardid, "EM100TX ");
1944 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1945 #if defined(TULIP_COGENT_EM110TX_ID)
1946 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {
1947 strcat(sc->tulip_boardid, "EM110TX ");
1948 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1950 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1951 strcat(sc->tulip_boardid, "EM100FX ");
1952 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1955 * Magic number (0x24001109U) is the SubVendor (0x2400) and
1956 * SubDevId (0x1109) for the ANA6944TX (EM440TX).
1958 if (*(uint32_t *) sc->tulip_rombuf == 0x24001109U
1959 && (sc->tulip_features & TULIP_HAVE_BASEROM)) {
1961 * Cogent (Adaptec) is still mapping all INTs to INTA of
1962 * first 21140. Dumb! Dumb!
1964 strcat(sc->tulip_boardid, "EM440TX ");
1965 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
1967 } else if (sc->tulip_chipid == TULIP_21040) {
1968 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1973 tulip_identify_accton_nic(tulip_softc_t * const sc)
1975 strcpy(sc->tulip_boardid, "ACCTON ");
1976 switch (sc->tulip_chipid) {
1978 strcat(sc->tulip_boardid, "EN1207 ");
1979 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
1980 sc->tulip_boardsw = &tulip_21140_accton_boardsw;
1983 strcat(sc->tulip_boardid, "EN1207TX ");
1984 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
1985 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
1988 strcat(sc->tulip_boardid, "EN1203 ");
1989 sc->tulip_boardsw = &tulip_21040_boardsw;
1992 strcat(sc->tulip_boardid, "EN1203 ");
1993 sc->tulip_boardsw = &tulip_21041_boardsw;
1996 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2002 tulip_identify_asante_nic(tulip_softc_t * const sc)
2004 strcpy(sc->tulip_boardid, "Asante ");
2005 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
2006 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2007 tulip_media_info_t *mi = sc->tulip_mediainfo;
2010 * The Asante Fast Ethernet doesn't always ship with a valid
2011 * new format SROM. So if isn't in the new format, we cheat
2012 * set it up as if we had.
2015 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;
2016 sc->tulip_gpdata = 0;
2018 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);
2019 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);
2021 TULIP_CSR_WRITE(sc, csr_gp, 0);
2023 mi->mi_type = TULIP_MEDIAINFO_MII;
2024 mi->mi_gpr_length = 0;
2025 mi->mi_gpr_offset = 0;
2026 mi->mi_reset_length = 0;
2027 mi->mi_reset_offset = 0;
2029 mi->mi_phyaddr = TULIP_MII_NOPHY;
2030 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) {
2032 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
2034 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2035 if_printf(&sc->tulip_if, "can't find phy 0\n");
2039 sc->tulip_features |= TULIP_HAVE_MII;
2040 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2041 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2042 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD;
2043 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD;
2044 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2045 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2046 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2047 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2048 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2049 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2050 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2052 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2057 tulip_identify_compex_nic(tulip_softc_t *sc)
2059 strcpy(sc->tulip_boardid, "COMPEX ");
2060 if (sc->tulip_chipid == TULIP_21140A) {
2062 tulip_softc_t *root_sc = NULL;
2064 strcat(sc->tulip_boardid, "400TX/PCI ");
2066 * All 4 chips on these boards share an interrupt. This code
2067 * copied from tulip_read_macaddr.
2069 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2070 for (root_unit = device_get_unit(sc->tulip_dev) - 1; root_unit >= 0; root_unit--) {
2071 root_sc = tulips[root_unit];
2073 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
2078 && root_sc->tulip_chipid == sc->tulip_chipid
2079 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2080 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2081 sc->tulip_slaves = root_sc->tulip_slaves;
2082 root_sc->tulip_slaves = sc;
2083 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
2084 if_printf(&sc->tulip_if, "can't find master device for interrupts");
2087 strcat(sc->tulip_boardid, "unknown ");
2089 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */
2094 tulip_srom_decode(tulip_softc_t *sc)
2096 u_int idx1, idx2, idx3;
2098 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
2099 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
2100 tulip_srom_media_t srom_media;
2101 tulip_media_info_t *mi = sc->tulip_mediainfo;
2103 uint32_t leaf_offset, blocks, data;
2105 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
2106 if (shp->sh_adapter_count == 1)
2108 if (saip->sai_device == sc->tulip_pci_devno)
2112 * Didn't find the right media block for this card.
2114 if (idx1 == shp->sh_adapter_count)
2118 * Save the hardware address.
2120 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6);
2122 * If this is a multiple port card, add the adapter index to the last
2123 * byte of the hardware address. (if it isn't multiport, adding 0
2126 sc->tulip_enaddr[5] += idx1;
2128 leaf_offset = saip->sai_leaf_offset_lowbyte
2129 + saip->sai_leaf_offset_highbyte * 256;
2130 dp = sc->tulip_rombuf + leaf_offset;
2132 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2;
2134 for (idx2 = 0;; idx2++) {
2135 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype
2136 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED)
2139 sc->tulip_connidx = idx2;
2141 if (sc->tulip_chipid == TULIP_21041) {
2143 for (idx2 = 0; idx2 < blocks; idx2++) {
2144 tulip_media_t media;
2146 srom_media = (tulip_srom_media_t) (data & 0x3F);
2147 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2148 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2151 media = tulip_srom_mediums[idx3].sm_type;
2152 if (media != TULIP_MEDIA_UNKNOWN) {
2153 if (data & TULIP_SROM_21041_EXTENDED) {
2154 mi->mi_type = TULIP_MEDIAINFO_SIA;
2155 sc->tulip_mediums[media] = mi;
2156 mi->mi_sia_connectivity = dp[0] + dp[1] * 256;
2157 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256;
2158 mi->mi_sia_general = dp[4] + dp[5] * 256;
2162 case TULIP_MEDIA_BNC: {
2163 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
2167 case TULIP_MEDIA_AUI: {
2168 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
2172 case TULIP_MEDIA_10BASET: {
2173 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
2177 case TULIP_MEDIA_10BASET_FD: {
2178 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
2188 if (data & TULIP_SROM_21041_EXTENDED)
2193 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++;
2194 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++;
2195 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++;
2196 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++;
2200 unsigned length, type;
2201 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN;
2202 if (sc->tulip_features & TULIP_HAVE_GPR)
2203 sc->tulip_gpinit = *dp++;
2205 for (idx2 = 0; idx2 < blocks; idx2++) {
2207 if ((*dp & 0x80) == 0) {
2211 length = (*dp++ & 0x7f) - 1;
2212 type = *dp++ & 0x3f;
2215 switch (type & 0x3f) {
2216 case 0: { /* 21140[A] GPR block */
2217 tulip_media_t media;
2218 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2219 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2220 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2223 media = tulip_srom_mediums[idx3].sm_type;
2224 if (media == TULIP_MEDIA_UNKNOWN)
2226 mi->mi_type = TULIP_MEDIAINFO_GPR;
2227 sc->tulip_mediums[media] = mi;
2228 mi->mi_gpdata = dp[1];
2229 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) {
2230 sc->tulip_gpdata = mi->mi_gpdata;
2233 data = dp[2] + dp[3] * 256;
2234 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2235 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2239 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2241 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2242 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2247 case 1: { /* 21140[A] MII block */
2248 const u_int phyno = *dp++;
2249 mi->mi_type = TULIP_MEDIAINFO_MII;
2250 mi->mi_gpr_length = *dp++;
2251 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2252 dp += mi->mi_gpr_length;
2253 mi->mi_reset_length = *dp++;
2254 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2255 dp += mi->mi_reset_length;
2258 * Before we probe for a PHY, use the GPR information
2259 * to select it. If we don't, it may be inaccessible.
2261 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET);
2262 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) {
2264 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]);
2266 sc->tulip_phyaddr = mi->mi_phyaddr;
2267 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) {
2269 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]);
2273 * At least write something!
2275 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2276 TULIP_CSR_WRITE(sc, csr_gp, 0);
2278 mi->mi_phyaddr = TULIP_MII_NOPHY;
2279 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2281 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2283 if (mi->mi_phyaddr == TULIP_MII_NOPHY)
2285 sc->tulip_features |= TULIP_HAVE_MII;
2286 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2287 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2288 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2289 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2290 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2291 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2292 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2293 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2294 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2295 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2296 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2300 case 2: { /* 2114[23] SIA block */
2301 tulip_media_t media;
2302 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2303 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2304 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2307 media = tulip_srom_mediums[idx3].sm_type;
2308 if (media == TULIP_MEDIA_UNKNOWN)
2310 mi->mi_type = TULIP_MEDIAINFO_SIA;
2311 sc->tulip_mediums[media] = mi;
2313 mi->mi_sia_connectivity = dp[1] + dp[2] * 256;
2314 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256;
2315 mi->mi_sia_general = dp[5] + dp[6] * 256;
2319 case TULIP_MEDIA_BNC: {
2320 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
2323 case TULIP_MEDIA_AUI: {
2324 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
2327 case TULIP_MEDIA_10BASET: {
2328 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
2329 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2332 case TULIP_MEDIA_10BASET_FD: {
2333 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
2334 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2342 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16;
2343 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16;
2348 case 3: { /* 2114[23] MII PHY block */
2349 const u_int phyno = *dp++;
2351 mi->mi_type = TULIP_MEDIAINFO_MII;
2352 mi->mi_gpr_length = *dp++;
2353 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2354 dp += 2 * mi->mi_gpr_length;
2355 mi->mi_reset_length = *dp++;
2356 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2357 dp += 2 * mi->mi_reset_length;
2359 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset];
2360 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) {
2362 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2364 sc->tulip_phyaddr = mi->mi_phyaddr;
2365 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset];
2366 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) {
2368 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2371 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2372 TULIP_CSR_WRITE(sc, csr_sia_general, 0);
2374 mi->mi_phyaddr = TULIP_MII_NOPHY;
2375 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2377 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2379 if (mi->mi_phyaddr == TULIP_MII_NOPHY)
2381 sc->tulip_features |= TULIP_HAVE_MII;
2382 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2383 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2384 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2385 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2386 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2;
2387 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2388 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2389 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2390 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2391 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2392 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2393 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2397 case 4: { /* 21143 SYM block */
2398 tulip_media_t media;
2399 srom_media = (tulip_srom_media_t) dp[0];
2400 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2401 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2404 media = tulip_srom_mediums[idx3].sm_type;
2405 if (media == TULIP_MEDIA_UNKNOWN)
2407 mi->mi_type = TULIP_MEDIAINFO_SYM;
2408 sc->tulip_mediums[media] = mi;
2409 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16;
2410 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16;
2411 data = dp[5] + dp[6] * 256;
2412 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2413 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2416 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2417 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2418 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2420 if (TULIP_IS_MEDIA_TP(media))
2421 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2426 case 5: { /* 21143 Reset block */
2427 mi->mi_type = TULIP_MEDIAINFO_RESET;
2428 mi->mi_reset_length = *dp++;
2429 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2430 dp += 2 * mi->mi_reset_length;
2441 return mi - sc->tulip_mediainfo;
2444 static const struct {
2445 void (*vendor_identify_nic)(tulip_softc_t * const sc);
2446 unsigned char vendor_oui[3];
2447 } tulip_vendors[] = {
2448 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } },
2449 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } },
2450 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } },
2451 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } },
2452 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } },
2453 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } },
2454 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } },
2455 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } },
2456 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } },
2457 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } },
2462 * This deals with the vagaries of the address roms and the
2463 * brain-deadness that various vendors commit in using them.
2466 tulip_read_macaddr(tulip_softc_t *sc)
2468 u_int cksum, rom_cksum, idx;
2470 unsigned char tmpbuf[8];
2471 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
2473 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX;
2475 if (sc->tulip_chipid == TULIP_21040) {
2476 TULIP_CSR_WRITE(sc, csr_enetrom, 1);
2477 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2479 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
2481 sc->tulip_rombuf[idx] = csr & 0xFF;
2483 sc->tulip_boardsw = &tulip_21040_boardsw;
2485 if (sc->tulip_chipid == TULIP_21041) {
2487 * Thankfully all 21041's act the same.
2489 sc->tulip_boardsw = &tulip_21041_boardsw;
2492 * Assume all 21140 board are compatible with the
2493 * DEC 10/100 evaluation board. Not really valid but
2494 * it's the best we can do until every one switches to
2495 * the new SROM format.
2498 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2500 tulip_srom_read(sc);
2501 if (tulip_srom_crcok(sc->tulip_rombuf)) {
2503 * SROM CRC is valid therefore it must be in the
2506 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM;
2507 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
2509 * No checksum is present. See if the SROM id checks out;
2510 * the first 18 bytes should be 0 followed by a 1 followed
2511 * by the number of adapters (which we don't deal with yet).
2513 for (idx = 0; idx < 18; idx++) {
2514 if (sc->tulip_rombuf[idx] != 0)
2517 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
2518 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2519 } else if (sc->tulip_chipid >= TULIP_21142) {
2520 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2521 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2523 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) {
2524 if (sc->tulip_chipid != TULIP_21041)
2525 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2528 * If the SROM specifies more than one adapter, tag this as a
2531 if (sc->tulip_rombuf[19] > 1)
2532 sc->tulip_features |= TULIP_HAVE_BASEROM;
2533 if (sc->tulip_boardsw == NULL)
2540 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
2542 * Some folks don't use the standard ethernet rom format
2543 * but instead just put the address in the first 6 bytes
2544 * of the rom and let the rest be all 0xffs. (Can we say
2545 * ZNYX?) (well sometimes they put in a checksum so we'll
2548 for (idx = 8; idx < 32; idx++) {
2549 if (sc->tulip_rombuf[idx] != 0xFF)
2553 * Make sure the address is not multicast or locally assigned
2554 * that the OUI is not 00-00-00.
2556 if ((sc->tulip_rombuf[0] & 3) != 0)
2558 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
2559 && sc->tulip_rombuf[2] == 0)
2561 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2562 sc->tulip_features |= TULIP_HAVE_OKROM;
2566 * A number of makers of multiport boards (ZNYX and Cogent)
2567 * only put on one address ROM on their 21040 boards. So
2568 * if the ROM is all zeros (or all 0xFFs), look at the
2569 * previous configured boards (as long as they are on the same
2570 * PCI bus and the bus number is non-zero) until we find the
2571 * master board with address ROM. We then use its address ROM
2572 * as the base for this board. (we add our relative board
2573 * to the last byte of its address).
2575 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2576 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF)
2579 if (idx == sizeof(sc->tulip_rombuf)) {
2581 tulip_softc_t *root_sc = NULL;
2582 for (root_unit = device_get_unit(sc->tulip_dev) - 1; root_unit >= 0; root_unit--) {
2583 root_sc = tulips[root_unit];
2584 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
2588 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM)
2589 && root_sc->tulip_chipid == sc->tulip_chipid
2590 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2591 sc->tulip_features |= TULIP_HAVE_SLAVEDROM;
2592 sc->tulip_boardsw = root_sc->tulip_boardsw;
2593 strcpy(sc->tulip_boardid, root_sc->tulip_boardid);
2594 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) {
2595 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf,
2596 sizeof(sc->tulip_rombuf));
2597 if (!tulip_srom_decode(sc))
2600 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
2601 sc->tulip_enaddr[5] += device_get_unit(sc->tulip_dev) - device_get_unit(root_sc->tulip_dev);
2604 * Now for a truly disgusting kludge: all 4 21040s on
2605 * the ZX314 share the same INTA line so the mapping
2606 * setup by the BIOS on the PCI bridge is worthless.
2607 * Rather than reprogramming the value in the config
2608 * register, we will handle this internally.
2610 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) {
2611 sc->tulip_slaves = root_sc->tulip_slaves;
2612 root_sc->tulip_slaves = sc;
2613 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2621 * This is the standard DEC address ROM test.
2624 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
2627 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
2628 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
2629 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
2630 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
2631 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
2634 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2636 cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
2638 if (cksum > 65535) cksum -= 65535;
2639 cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
2640 if (cksum > 65535) cksum -= 65535;
2642 if (cksum > 65535) cksum -= 65535;
2643 cksum += *(u_int16_t *) &sc->tulip_enaddr[4];
2644 if (cksum >= 65535) cksum -= 65535;
2646 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6];
2648 if (cksum != rom_cksum)
2653 * Check for various boards based on OUI. Did I say braindead?
2655 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) {
2656 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) {
2657 (*tulip_vendors[idx].vendor_identify_nic)(sc);
2662 sc->tulip_features |= TULIP_HAVE_OKROM;
2667 tulip_ifmedia_add(tulip_softc_t * const sc)
2669 tulip_media_t media;
2672 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2673 if (sc->tulip_mediums[media] != NULL) {
2674 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media],
2680 sc->tulip_features |= TULIP_HAVE_NOMEDIA;
2681 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0);
2682 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE);
2683 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
2684 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0);
2685 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO);
2687 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]);
2688 sc->tulip_flags |= TULIP_PRINTMEDIA;
2689 tulip_linkup(sc, sc->tulip_media);
2694 tulip_ifmedia_change(struct ifnet *ifp)
2696 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2698 sc->tulip_flags |= TULIP_NEEDRESET;
2699 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
2700 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
2701 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) {
2702 tulip_media_t media;
2703 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2704 if (sc->tulip_mediums[media] != NULL
2705 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) {
2706 sc->tulip_flags |= TULIP_PRINTMEDIA;
2707 sc->tulip_flags &= ~TULIP_DIDNWAY;
2708 tulip_linkup(sc, media);
2713 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
2720 * Media status callback
2723 tulip_ifmedia_status(struct ifnet *ifp, struct ifmediareq *req)
2725 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2727 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN)
2730 req->ifm_status = IFM_AVALID;
2731 if (sc->tulip_flags & TULIP_LINKUP)
2732 req->ifm_status |= IFM_ACTIVE;
2734 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
2738 tulip_addr_filter(tulip_softc_t *sc)
2740 struct ifmultiaddr *ifma;
2744 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI);
2745 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART;
2746 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
2747 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
2748 #if defined(IFF_ALLMULTI)
2749 if (sc->tulip_if.if_flags & IFF_ALLMULTI)
2750 sc->tulip_flags |= TULIP_ALLMULTI ;
2754 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
2755 if (ifma->ifma_addr->sa_family == AF_LINK)
2759 sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */
2760 if (multicnt > 14) {
2761 uint32_t *sp = sc->tulip_setupdata;
2764 * Some early passes of the 21140 have broken implementations of
2765 * hash-perfect mode. When we get too many multicasts for perfect
2766 * filtering with these chips, we need to switch into hash-only
2767 * mode (this is better than all-multicast on network with lots
2768 * of multicast traffic).
2770 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
2771 sc->tulip_flags |= TULIP_WANTHASHONLY;
2773 sc->tulip_flags |= TULIP_WANTHASHPERFECT;
2775 * If we have more than 14 multicasts, we have
2776 * go into hash perfect mode (512 bit multicast
2777 * hash and one perfect hardware).
2779 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
2781 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
2782 if (ifma->ifma_addr->sa_family != AF_LINK)
2785 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
2786 #if BYTE_ORDER == BIG_ENDIAN
2787 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2789 sp[hash >> 4] |= 1 << (hash & 0xF);
2793 * No reason to use a hash if we are going to be
2794 * receiving every multicast.
2796 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
2797 hash = tulip_mchash(sc->tulip_if.if_broadcastaddr);
2798 #if BYTE_ORDER == BIG_ENDIAN
2799 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2801 sp[hash >> 4] |= 1 << (hash & 0xF);
2803 if (sc->tulip_flags & TULIP_WANTHASHONLY) {
2804 hash = tulip_mchash(sc->tulip_enaddr);
2805 #if BYTE_ORDER == BIG_ENDIAN
2806 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2808 sp[hash >> 4] |= 1 << (hash & 0xF);
2811 #if BYTE_ORDER == BIG_ENDIAN
2812 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
2813 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
2814 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
2816 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0];
2817 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1];
2818 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2];
2823 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
2824 uint32_t *sp = sc->tulip_setupdata;
2826 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
2828 * Else can get perfect filtering for 16 addresses.
2830 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
2831 if (ifma->ifma_addr->sa_family != AF_LINK)
2833 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
2834 #if BYTE_ORDER == BIG_ENDIAN
2835 *sp++ = ((u_int16_t *) addrp)[0] << 16;
2836 *sp++ = ((u_int16_t *) addrp)[1] << 16;
2837 *sp++ = ((u_int16_t *) addrp)[2] << 16;
2839 *sp++ = ((u_int16_t *) addrp)[0];
2840 *sp++ = ((u_int16_t *) addrp)[1];
2841 *sp++ = ((u_int16_t *) addrp)[2];
2846 * Add the broadcast address.
2849 #if BYTE_ORDER == BIG_ENDIAN
2850 *sp++ = 0xFFFF << 16;
2851 *sp++ = 0xFFFF << 16;
2852 *sp++ = 0xFFFF << 16;
2860 * Pad the rest with our hardware address
2862 for (; idx < 16; idx++) {
2863 #if BYTE_ORDER == BIG_ENDIAN
2864 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
2865 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
2866 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
2868 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0];
2869 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1];
2870 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2];
2874 #if defined(IFF_ALLMULTI)
2875 if (sc->tulip_flags & TULIP_ALLMULTI)
2876 sc->tulip_if.if_flags |= IFF_ALLMULTI;
2881 tulip_reset(tulip_softc_t *sc)
2883 tulip_ringinfo_t *ri;
2885 uint32_t inreset = (sc->tulip_flags & TULIP_INRESET);
2888 * Brilliant. Simply brilliant. When switching modes/speeds
2889 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
2890 * bits in CSR6 and then do a software reset to get the 21140
2891 * to properly reset its internal pathways to the right places.
2894 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
2895 && sc->tulip_boardsw->bd_media_preset != NULL)
2896 (*sc->tulip_boardsw->bd_media_preset)(sc);
2898 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2899 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
2900 33MHz that comes to two microseconds but wait a
2901 bit longer anyways) */
2904 sc->tulip_flags |= TULIP_INRESET;
2905 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
2906 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
2907 sc->tulip_if.if_start = tulip_ifstart;
2910 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
2911 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
2912 TULIP_CSR_WRITE(sc, csr_busmode,
2913 (1 << (3 /*pci_max_burst_len*/ + 8))
2914 |TULIP_BUSMODE_CACHE_ALIGN8
2915 |TULIP_BUSMODE_READMULTIPLE
2916 |(BYTE_ORDER != LITTLE_ENDIAN ?
2917 TULIP_BUSMODE_DESC_BIGENDIAN : 0));
2919 sc->tulip_txtimer = 0;
2920 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
2922 * Free all the mbufs that were on the transmit ring.
2924 IF_DRAIN(&sc->tulip_txq);
2926 ri = &sc->tulip_txinfo;
2927 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
2928 ri->ri_free = ri->ri_max;
2929 for (di = ri->ri_first; di < ri->ri_last; di++)
2933 * We need to collect all the mbufs were on the
2934 * receive ring before we reinit it either to put
2935 * them back on or to know if we have to allocate
2938 ri = &sc->tulip_rxinfo;
2939 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
2940 ri->ri_free = ri->ri_max;
2941 for (di = ri->ri_first; di < ri->ri_last; di++) {
2943 di->d_length1 = 0; di->d_addr1 = 0;
2944 di->d_length2 = 0; di->d_addr2 = 0;
2946 IF_DRAIN(&sc->tulip_rxq);
2949 * If tulip_reset is being called recurisvely, exit quickly knowing
2950 * that when the outer tulip_reset returns all the right stuff will
2956 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
2957 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
2958 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
2959 |TULIP_STS_RXSTOPPED;
2961 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
2962 (*sc->tulip_boardsw->bd_media_select)(sc);
2963 tulip_media_print(sc);
2964 if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
2965 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
2967 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
2969 tulip_addr_filter(sc);
2973 tulip_init(tulip_softc_t * const sc)
2975 if (sc->tulip_if.if_flags & IFF_UP) {
2976 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) {
2977 /* initialize the media */
2980 sc->tulip_if.if_flags |= IFF_RUNNING;
2981 if (sc->tulip_if.if_flags & IFF_PROMISC) {
2982 sc->tulip_flags |= TULIP_PROMISC;
2983 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
2984 sc->tulip_intrmask |= TULIP_STS_TXINTR;
2986 sc->tulip_flags &= ~TULIP_PROMISC;
2987 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
2988 if (sc->tulip_flags & TULIP_ALLMULTI) {
2989 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
2991 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
2994 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
2995 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
2997 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
2998 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3000 sc->tulip_if.if_flags |= IFF_OACTIVE;
3001 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3002 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3004 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3005 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3006 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3007 tulip_txput_setup(sc);
3009 sc->tulip_if.if_flags &= ~IFF_RUNNING;
3015 tulip_rx_intr(tulip_softc_t *sc)
3017 tulip_ringinfo_t *ri = &sc->tulip_rxinfo;
3018 struct ifnet *ifp = &sc->tulip_if;
3022 tulip_desc_t *eop = ri->ri_nextin;
3023 int total_len = 0, last_offset = 0;
3024 struct mbuf *ms = NULL, *me = NULL;
3027 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
3031 * If the TULIP has no descriptors, there can't be any receive
3032 * descriptors to process.
3034 if (eop == ri->ri_nextout)
3038 * 90% of the packets will fit in one descriptor. So we optimize
3041 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3042 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
3043 IF_DEQUEUE(&sc->tulip_rxq, ms);
3047 * If still owned by the TULIP, don't touch it.
3049 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
3053 * It is possible (though improbable unless the BIG_PACKET support
3054 * is enabled or MCLBYTES < 1518) for a received packet to cross
3055 * more than one receive descriptor.
3057 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) {
3058 if (++eop == ri->ri_last)
3060 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3061 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
3068 * Dequeue the first buffer for the start of the packet. Hopefully
3069 * this will be the only one we need to dequeue. However, if the
3070 * packet consumed multiple descriptors, then we need to dequeue
3071 * those buffers and chain to the starting mbuf. All buffers but
3072 * the last buffer have the same length so we can set that now.
3073 * (we add to last_offset instead of multiplying since we normally
3074 * won't go into the loop and thereby saving a ourselves from
3075 * doing a multiplication by 0 in the normal case).
3077 IF_DEQUEUE(&sc->tulip_rxq, ms);
3078 for (me = ms; total_len > 0; total_len--) {
3079 me->m_len = TULIP_RX_BUFLEN;
3080 last_offset += TULIP_RX_BUFLEN;
3081 IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
3087 * Now get the size of received packet (minus the CRC).
3089 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
3090 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
3091 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0
3093 || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) &&
3094 (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT|
3095 TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC|
3096 TULIP_DSTS_RxOVERFLOW)) == 0)
3099 me->m_len = total_len - last_offset;
3101 sc->tulip_flags |= TULIP_RXACT;
3105 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3106 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3108 if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
3109 sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
3111 if (eop->d_status & TULIP_DSTS_RxBADCRC) {
3112 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
3113 sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
3115 sc->tulip_dot3stats.dot3StatsFCSErrors++;
3121 if (++eop == ri->ri_last)
3123 ri->ri_nextin = eop;
3126 * Either we are priming the TULIP with mbufs (m == NULL)
3127 * or we are about to accept an mbuf for the upper layers
3128 * so we need to allocate an mbuf to replace it. If we
3129 * can't replace it, send up it anyways. This may cause
3130 * us to drop packets in the future but that's better than
3131 * being caught in livelock.
3133 * Note that if this packet crossed multiple descriptors
3134 * we don't even try to reallocate all the mbufs here.
3135 * Instead we rely on the test of the beginning of
3136 * the loop to refill for the extra consumed mbufs.
3138 if (accept || ms == NULL) {
3141 #if defined(TULIP_COPY_RXDATA)
3142 if (!accept || total_len >= (MHLEN - 2))
3143 m0 = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
3145 m0 = m_gethdr(MB_DONTWAIT, MT_DATA);
3147 m0 = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
3151 #if defined(TULIP_COPY_RXDATA)
3155 #if !defined(TULIP_COPY_RXDATA)
3156 ms->m_pkthdr.len = total_len;
3157 ifp->if_input(ifp, ms);
3160 #error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
3162 m0->m_data += 2; /* align data after header */
3163 m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
3164 m0->m_len = m0->m_pkthdr.len = total_len;
3165 m0->m_pkthdr.rcvif = ifp;
3166 ifp->if_input(ifp, m0);
3168 #endif /* ! TULIP_COPY_RXDATA */
3174 * Couldn't allocate a new buffer. Don't bother
3175 * trying to replenish the receive queue.
3178 sc->tulip_flags |= TULIP_RXBUFSLOW;
3182 * Now give the buffer(s) to the TULIP and save in our
3186 tulip_desc_t * const nextout = ri->ri_nextout;
3187 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
3188 nextout->d_length1 = TULIP_RX_BUFLEN;
3189 nextout->d_status = TULIP_DSTS_OWNER;
3190 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
3191 if (++ri->ri_nextout == ri->ri_last)
3192 ri->ri_nextout = ri->ri_first;
3195 IF_ENQUEUE(&sc->tulip_rxq, ms);
3196 } while ((ms = me) != NULL);
3198 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
3199 sc->tulip_flags &= ~TULIP_RXBUFSLOW;
3204 tulip_tx_intr(tulip_softc_t *sc)
3206 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3211 while (ri->ri_free < ri->ri_max) {
3214 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
3215 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
3220 d_flag = ri->ri_nextin->d_flag;
3221 if (d_flag & TULIP_DFLAG_TxLASTSEG) {
3222 if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
3224 * We've just finished processing a setup packet.
3225 * Mark that we finished it. If there's not
3226 * another pending, startup the TULIP receiver.
3227 * Make sure we ack the RXSTOPPED so we won't get
3228 * an abormal interrupt indication.
3230 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap);
3231 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
3232 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT)
3233 sc->tulip_flags |= TULIP_HASHONLY;
3234 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
3236 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3237 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3238 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3239 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3240 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3243 const uint32_t d_status = ri->ri_nextin->d_status;
3244 IF_DEQUEUE(&sc->tulip_txq, m);
3248 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3249 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
3250 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
3251 event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
3253 (*sc->tulip_boardsw->bd_media_poll)(sc, event);
3255 * Escape from the loop before media poll has reset the TULIP!
3260 if (d_status & TULIP_DSTS_ERRSUM) {
3261 sc->tulip_if.if_oerrors++;
3262 if (d_status & TULIP_DSTS_TxEXCCOLL)
3263 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
3264 if (d_status & TULIP_DSTS_TxLATECOLL)
3265 sc->tulip_dot3stats.dot3StatsLateCollisions++;
3266 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
3267 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
3268 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
3269 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
3270 if (d_status & TULIP_DSTS_TxUNDERFLOW)
3271 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
3272 if (d_status & TULIP_DSTS_TxBABBLE)
3273 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
3275 u_int32_t collisions =
3276 (d_status & TULIP_DSTS_TxCOLLMASK)
3277 >> TULIP_DSTS_V_TxCOLLCNT;
3278 sc->tulip_if.if_collisions += collisions;
3279 if (collisions == 1)
3280 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
3281 else if (collisions > 1)
3282 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
3283 else if (d_status & TULIP_DSTS_TxDEFERRED)
3284 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
3286 * SQE is only valid for 10baseT/BNC/AUI when not
3287 * running in full-duplex. In order to speed up the
3288 * test, the corresponding bit in tulip_flags needs to
3289 * set as well to get us to count SQE Test Errors.
3291 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
3292 sc->tulip_dot3stats.dot3StatsSQETestErrors++;
3298 if (++ri->ri_nextin == ri->ri_last)
3299 ri->ri_nextin = ri->ri_first;
3301 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3302 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
3305 * If nothing left to transmit, disable the timer.
3306 * Else if progress, reset the timer back to 2 ticks.
3308 * XXX 2 bit field, TXTIMER is 4?
3310 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
3311 sc->tulip_txtimer = 0;
3313 sc->tulip_txtimer = (TULIP_TXTIMER & 3);
3314 sc->tulip_if.if_opackets += xmits;
3319 tulip_print_abnormal_interrupt(tulip_softc_t *sc, uint32_t csr)
3321 const char * const *msgp = tulip_status_bits;
3324 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
3326 csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1;
3327 if_printf(&sc->tulip_if, "abnormal interrupt:");
3328 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
3329 if ((csr & mask) && *msgp != NULL) {
3330 kprintf("%s%s", sep, *msgp);
3331 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
3332 sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
3333 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
3334 kprintf(" (switching to store-and-forward mode)");
3336 kprintf(" (raising TX threshold to %s)",
3337 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
3347 tulip_intr_handler(tulip_softc_t *sc)
3351 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3352 TULIP_CSR_WRITE(sc, csr_status, csr);
3354 if (csr & TULIP_STS_SYSERROR) {
3355 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
3356 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3357 sc->tulip_flags |= TULIP_SYSTEMERROR;
3359 if_printf(&sc->tulip_if, "system error: %s\n",
3360 tulip_system_errors[sc->tulip_last_system_error]);
3362 sc->tulip_flags |= TULIP_NEEDRESET;
3363 sc->tulip_system_errors++;
3366 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
3367 if (sc->tulip_boardsw->bd_media_poll != NULL) {
3368 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
3369 ? TULIP_MEDIAPOLL_LINKFAIL
3370 : TULIP_MEDIAPOLL_LINKPASS);
3371 csr &= ~TULIP_STS_ABNRMLINTR;
3373 tulip_media_print(sc);
3375 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
3376 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
3377 if (csr & TULIP_STS_RXNOBUF)
3378 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
3380 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3381 * on receive overflows.
3383 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
3384 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3386 * Stop the receiver process and spin until it's stopped.
3387 * Tell rx_intr to drop the packets it dequeues.
3389 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
3390 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
3392 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3393 sc->tulip_flags |= TULIP_RXIGNORE;
3396 if (sc->tulip_flags & TULIP_RXIGNORE) {
3398 * Restart the receiver.
3400 sc->tulip_flags &= ~TULIP_RXIGNORE;
3401 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3404 if (csr & TULIP_STS_ABNRMLINTR) {
3405 u_int32_t tmp = csr & sc->tulip_intrmask
3406 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
3407 if (csr & TULIP_STS_TXUNDERFLOW) {
3408 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
3409 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
3410 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3411 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
3412 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
3413 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3416 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3417 sc->tulip_statusbits |= tmp;
3419 tulip_print_abnormal_interrupt(sc, tmp);
3420 sc->tulip_flags |= TULIP_NOMESSAGES;
3422 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3424 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
3426 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3427 if_devstart(&sc->tulip_if);
3430 if (sc->tulip_flags & TULIP_NEEDRESET) {
3437 tulip_intr_shared(void *arg)
3441 for (sc = arg; sc != NULL; sc = sc->tulip_slaves)
3442 tulip_intr_handler(sc);
3446 tulip_intr_normal(void *arg)
3448 tulip_softc_t *sc = (tulip_softc_t *)arg;
3450 tulip_intr_handler(sc);
3453 static struct mbuf *
3454 tulip_txput(tulip_softc_t *sc, struct mbuf *m)
3456 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3457 tulip_desc_t *eop, *nextout;
3463 * Now we try to fill in our transmit descriptors. This is
3464 * a bit reminiscent of going on the Ark two by two
3465 * since each descriptor for the TULIP can describe
3466 * two buffers. So we advance through packet filling
3467 * each of the two entries at a time to to fill each
3468 * descriptor. Clear the first and last segment bits
3469 * in each descriptor (actually just clear everything
3470 * but the end-of-ring or chain bits) to make sure
3471 * we don't get messed up by previously sent packets.
3473 * We may fail to put the entire packet on the ring if
3474 * there is either not enough ring entries free or if the
3475 * packet has more than MAX_TXSEG segments. In the former
3476 * case we will just wait for the ring to empty. In the
3477 * latter case we have to recopy.
3482 eop = nextout = ri->ri_nextout;
3487 int len = m0->m_len;
3488 caddr_t addr = mtod(m0, caddr_t);
3489 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1));
3492 unsigned slen = min(len, clsize);
3496 slen = 2040, partial = 1;
3499 if (segcnt > TULIP_MAX_TXSEG) {
3501 * The packet exceeds the number of transmit buffer
3502 * entries that we can use for one packet, so we have
3503 * recopy it into one mbuf and then try again.
3505 m0 = m_defrag(m, MB_DONTWAIT);
3514 * See if there's any unclaimed space in the
3517 if ((free += tulip_tx_intr(sc)) == 0) {
3519 * There's no more room but since nothing
3520 * has been committed at this point, just
3521 * show output is active, put back the
3524 sc->tulip_flags |= TULIP_WANTTXSTART;
3529 if (++nextout == ri->ri_last)
3530 nextout = ri->ri_first;
3531 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
3532 eop->d_status = d_status;
3533 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr);
3534 eop->d_length1 = slen;
3537 * Fill in second half of descriptor
3539 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr);
3540 eop->d_length2 = slen;
3542 d_status = TULIP_DSTS_OWNER;
3551 } while ((m0 = m0->m_next) != NULL);
3553 BPF_MTAP(&sc->tulip_if, m);
3556 * The descriptors have been filled in. Now get ready
3559 IF_ENQUEUE(&sc->tulip_txq, m);
3563 * Make sure the next descriptor after this packet is owned
3564 * by us since it may have been set up above if we ran out
3565 * of room in the ring.
3567 nextout->d_status = 0;
3568 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
3571 * If we only used the first segment of the last descriptor,
3572 * make sure the second segment will not be used.
3580 * Mark the last and first segments, indicate we want a transmit
3581 * complete interrupt, and tell it to transmit!
3583 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
3586 * Note that ri->ri_nextout is still the start of the packet
3587 * and until we set the OWNER bit, we can still back out of
3588 * everything we have done.
3590 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
3591 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
3592 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
3595 * This advances the ring for us.
3597 ri->ri_nextout = nextout;
3600 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3601 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3602 sc->tulip_if.if_flags |= IFF_OACTIVE;
3603 sc->tulip_if.if_start = tulip_ifstart;
3608 * switch back to the single queueing ifstart.
3610 * XXX 2 bit field, TXTIMER is 4?
3612 sc->tulip_flags &= ~TULIP_WANTTXSTART;
3613 if (sc->tulip_txtimer == 0)
3614 sc->tulip_txtimer = TULIP_TXTIMER & 3;
3617 * If we want a txstart, there must be not enough space in the
3618 * transmit ring. So we want to enable transmit done interrupts
3619 * so we can immediately reclaim some space. When the transmit
3620 * interrupt is posted, the interrupt handler will call tx_intr
3621 * to reclaim space and then txstart (since WANTTXSTART is set).
3622 * txstart will move the packet into the transmit ring and clear
3623 * WANTTXSTART thereby causing TXINTR to be cleared.
3626 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
3627 sc->tulip_if.if_flags |= IFF_OACTIVE;
3628 sc->tulip_if.if_start = tulip_ifstart;
3629 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
3630 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3631 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3633 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) {
3634 if (sc->tulip_intrmask & TULIP_STS_TXINTR) {
3635 sc->tulip_intrmask &= ~TULIP_STS_TXINTR;
3636 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3639 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3644 tulip_txput_setup(tulip_softc_t *sc)
3646 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3647 tulip_desc_t *nextout;
3650 * We will transmit, at most, one setup packet per call to ifstart.
3654 * Try to reclaim some free descriptors..
3656 if (ri->ri_free < 2)
3658 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
3659 sc->tulip_flags |= TULIP_WANTTXSTART;
3660 sc->tulip_if.if_start = tulip_ifstart;
3663 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
3664 sizeof(sc->tulip_setupbuf));
3666 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is
3667 * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
3669 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP;
3671 nextout = ri->ri_nextout;
3672 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
3673 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
3674 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
3675 if (sc->tulip_flags & TULIP_WANTHASHPERFECT)
3676 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
3677 else if (sc->tulip_flags & TULIP_WANTHASHONLY)
3678 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT;
3680 nextout->d_length2 = 0;
3681 nextout->d_addr2 = 0;
3682 nextout->d_length1 = sizeof(sc->tulip_setupbuf);
3683 nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
3686 * Advance the ring for the next transmit packet.
3688 if (++ri->ri_nextout == ri->ri_last)
3689 ri->ri_nextout = ri->ri_first;
3692 * Make sure the next descriptor is owned by us since it
3693 * may have been set up above if we ran out of room in the
3696 ri->ri_nextout->d_status = 0;
3697 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
3698 nextout->d_status = TULIP_DSTS_OWNER;
3700 * Flush the ownwership of the current descriptor
3702 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
3703 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3704 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
3705 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3706 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3711 tulip_ifioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred * cr)
3713 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
3714 struct ifaddr *ifa = (struct ifaddr *)data;
3715 struct ifreq *ifr = (struct ifreq *)data;
3720 ifp->if_flags |= IFF_UP;
3721 switch(ifa->ifa_addr->sa_family) {
3725 arp_ifinit(&(sc)->tulip_ac.ac_if, ifa);
3732 struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr);
3733 if (ipx_nullhost(*ina)) {
3734 ina->x_host = *(union ipx_host *)(sc->tulip_enaddr);
3736 ifp->if_flags &= ~IFF_RUNNING;
3737 bcopy((caddr_t)ina->x_host.c_host,
3738 (caddr_t)sc->tulip_enaddr,
3739 sizeof(sc->tulip_enaddr));
3754 bcopy((caddr_t) sc->tulip_enaddr,
3755 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
3760 case SIOCSIFFLAGS: {
3761 tulip_addr_filter(sc); /* reinit multicast filter */
3767 case SIOCGIFMEDIA: {
3768 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
3773 case SIOCDELMULTI: {
3775 * Update multicast listeners
3777 tulip_addr_filter(sc); /* reset multicast filtering */
3785 * Set the interface MTU.
3787 if (ifr->ifr_mtu > ETHERMTU
3789 && sc->tulip_chipid != TULIP_21140
3790 && sc->tulip_chipid != TULIP_21140A
3791 && sc->tulip_chipid != TULIP_21041
3797 ifp->if_mtu = ifr->ifr_mtu;
3805 case SIOCGADDRROM: {
3806 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
3812 ifr->ifr_metric = (int) sc->tulip_chipid;
3825 tulip_ifstart(struct ifnet *ifp)
3827 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
3829 if (sc->tulip_if.if_flags & IFF_RUNNING) {
3831 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3832 tulip_txput_setup(sc);
3834 while (sc->tulip_if.if_snd.ifq_head != NULL) {
3837 ALTQ_LOCK(&sc->tulip_if.if_snd);
3838 IF_DEQUEUE(&sc->tulip_if.if_snd, m);
3839 ALTQ_UNLOCK(&sc->tulip_if.if_snd);
3841 if ((m = tulip_txput(sc, m)) != NULL) {
3842 ALTQ_LOCK(&sc->tulip_if.if_snd);
3843 IF_PREPEND(&sc->tulip_if.if_snd, m);
3844 ALTQ_UNLOCK(&sc->tulip_if.if_snd);
3852 tulip_ifwatchdog(struct ifnet *ifp)
3854 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
3856 sc->tulip_if.if_timer = 1;
3858 * These should be rare so do a bulk test up front so we can just skip
3861 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) {
3863 * If the number of receive buffer is low, try to refill
3865 if (sc->tulip_flags & TULIP_RXBUFSLOW)
3868 if (sc->tulip_flags & TULIP_SYSTEMERROR) {
3869 if_printf(ifp, "%d system errors: last was %s\n",
3870 sc->tulip_system_errors,
3871 tulip_system_errors[sc->tulip_last_system_error]);
3873 if (sc->tulip_statusbits) {
3874 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
3875 sc->tulip_statusbits = 0;
3878 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR);
3881 if (sc->tulip_txtimer)
3883 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
3884 if_printf(ifp, "transmission timeout\n");
3885 if (TULIP_DO_AUTOSENSE(sc)) {
3886 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
3887 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
3888 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP);
3896 tulip_attach(tulip_softc_t *sc)
3898 struct ifnet *ifp = &sc->tulip_if;
3900 callout_init(&sc->tulip_timer);
3901 callout_init(&sc->tulip_fast_timer);
3903 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
3904 ifp->if_ioctl = tulip_ifioctl;
3905 ifp->if_start = tulip_ifstart;
3906 ifp->if_watchdog = tulip_ifwatchdog;
3909 if_printf(ifp, "%s%s pass %d.%d%s\n",
3911 tulip_chipdescs[sc->tulip_chipid],
3912 (sc->tulip_revinfo & 0xF0) >> 4,
3913 sc->tulip_revinfo & 0x0F,
3914 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM))
3915 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "");
3917 (*sc->tulip_boardsw->bd_media_probe)(sc);
3918 ifmedia_init(&sc->tulip_ifmedia, 0,
3919 tulip_ifmedia_change,
3920 tulip_ifmedia_status);
3921 sc->tulip_flags &= ~TULIP_DEVICEPROBE;
3922 tulip_ifmedia_add(sc);
3926 ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr, NULL);
3927 ifp->if_snd.ifq_maxlen = ifqmaxlen;
3931 tulip_detach(tulip_softc_t *sc)
3933 ifmedia_removeall(&sc->tulip_ifmedia);
3934 ether_ifdetach(&sc->tulip_if);
3938 tulip_initcsrs(tulip_softc_t *sc, tulip_csrptr_t csr_base, size_t csr_size)
3940 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
3941 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
3942 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
3943 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
3944 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
3945 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
3946 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
3947 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
3948 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size;
3949 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size;
3950 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size;
3951 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size;
3952 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size;
3953 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size;
3954 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
3955 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
3959 tulip_initring(tulip_softc_t *sc, tulip_ringinfo_t *ri, tulip_desc_t *descs,
3962 ri->ri_max = ndescs;
3963 ri->ri_first = descs;
3964 ri->ri_last = ri->ri_first + ri->ri_max;
3965 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
3966 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
3970 * This is the PCI configuration support.
3973 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
3974 #define PCI_CBMA 0x14 /* Configuration Base Memory Address */
3975 #define PCI_CFDA 0x40 /* Configuration Driver Area */
3978 tulip_pci_probe(device_t dev)
3980 const char *name = NULL;
3982 if (pci_get_vendor(dev) != DEC_VENDORID)
3986 * Some LanMedia WAN cards use the Tulip chip, but they have
3987 * their own driver, and we should not recognize them
3989 if (pci_get_subvendor(dev) == 0x1376)
3992 switch (pci_get_device(dev)) {
3994 name = "Digital 21040 Ethernet";
3997 name = "Digital 21041 Ethernet";
4000 if (pci_get_revid(dev) >= 0x20)
4001 name = "Digital 21140A Fast Ethernet";
4003 name = "Digital 21140 Fast Ethernet";
4006 if (pci_get_revid(dev) >= 0x20)
4007 name = "Digital 21143 Fast Ethernet";
4009 name = "Digital 21142 Fast Ethernet";
4013 device_set_desc(dev, name);
4020 tulip_shutdown(device_t dev)
4022 tulip_softc_t *sc = device_get_softc(dev);
4024 lwkt_serialize_enter(sc->tulip_if.if_serializer);
4025 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4026 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
4027 33MHz that comes to two microseconds but wait a
4028 bit longer anyways) */
4029 lwkt_serialize_exit(sc->tulip_if.if_serializer);
4034 tulip_pci_attach(device_t dev)
4038 uint32_t revinfo, cfdainfo, cfcsinfo;
4039 u_int csroffset = TULIP_PCI_CSROFFSET;
4040 u_int csrsize = TULIP_PCI_CSRSIZE;
4041 tulip_csrptr_t csr_base;
4042 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
4043 struct resource *res;
4046 if (device_get_unit(dev) >= TULIP_MAX_DEVICES) {
4047 device_printf(dev, "not configured; limit of %d reached or exceeded\n",
4052 revinfo = pci_get_revid(dev);
4053 cfdainfo = pci_read_config(dev, PCI_CFDA, 4);
4054 cfcsinfo = pci_read_config(dev, PCIR_COMMAND, 4);
4056 /* turn busmaster on in case BIOS doesn't set it */
4057 pci_enable_busmaster(dev);
4059 if (pci_get_vendor(dev) == DEC_VENDORID) {
4060 if (pci_get_device(dev) == CHIPID_21040)
4061 chipid = TULIP_21040;
4062 else if (pci_get_device(dev) == CHIPID_21041)
4063 chipid = TULIP_21041;
4064 else if (pci_get_device(dev) == CHIPID_21140)
4065 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140;
4066 else if (pci_get_device(dev) == CHIPID_21142)
4067 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142;
4069 if (chipid == TULIP_CHIPID_UNKNOWN)
4072 if (chipid == TULIP_21040 && revinfo < 0x20) {
4073 device_printf(dev, "not configured; 21040 pass 2.0 required (%d.%d found)\n",
4074 revinfo >> 4, revinfo & 0x0f);
4076 } else if (chipid == TULIP_21140 && revinfo < 0x11) {
4077 device_printf(dev, "not configured; 21140 pass 1.1 required (%d.%d found)\n",
4078 revinfo >> 4, revinfo & 0x0f);
4082 sc = device_get_softc(dev);
4083 sc->tulip_dev = dev;
4084 sc->tulip_pci_busno = pci_get_bus(dev);
4085 sc->tulip_pci_devno = pci_get_slot(dev);
4086 sc->tulip_chipid = chipid;
4087 sc->tulip_flags |= TULIP_DEVICEPROBE;
4088 if (chipid == TULIP_21140 || chipid == TULIP_21140A)
4089 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD;
4090 if (chipid == TULIP_21140A && revinfo <= 0x22)
4091 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW;
4092 if (chipid == TULIP_21140)
4093 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH;
4094 if (chipid != TULIP_21040 && chipid != TULIP_21140)
4095 sc->tulip_features |= TULIP_HAVE_POWERMGMT;
4096 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) {
4097 sc->tulip_features |= TULIP_HAVE_DUALSENSE;
4098 if (chipid != TULIP_21041 || revinfo >= 0x20)
4099 sc->tulip_features |= TULIP_HAVE_SIANWAY;
4100 if (chipid != TULIP_21041)
4101 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD;
4102 if (chipid != TULIP_21041 && revinfo >= 0x20)
4103 sc->tulip_features |= TULIP_HAVE_SIA100;
4106 if (sc->tulip_features & TULIP_HAVE_POWERMGMT
4107 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) {
4108 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE);
4109 pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
4112 if_initname(&sc->tulip_if, device_get_name(dev), device_get_unit(dev));
4113 sc->tulip_revinfo = revinfo;
4114 sc->tulip_if.if_softc = sc;
4115 #if defined(TULIP_IOMAPPED)
4117 res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
4120 res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
4124 sc->tulip_csrs_bst = rman_get_bustag(res);
4125 sc->tulip_csrs_bsh = rman_get_bushandle(res);
4128 tulips[device_get_unit(dev)] = sc;
4130 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
4132 sc->tulip_rxdescs = kmalloc(sizeof(tulip_desc_t) * TULIP_RXDESCS,
4133 M_DEVBUF, M_INTWAIT);
4134 sc->tulip_txdescs = kmalloc(sizeof(tulip_desc_t) * TULIP_TXDESCS,
4135 M_DEVBUF, M_INTWAIT);
4137 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS);
4138 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS);
4141 * Make sure there won't be any interrupts or such...
4143 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4144 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
4145 33MHz that comes to two microseconds but wait a
4146 bit longer anyways) */
4148 if ((retval = tulip_read_macaddr(sc)) < 0) {
4149 device_printf(dev, "can't read ENET ROM (why=%d) (", retval);
4150 for (idx = 0; idx < 32; idx++)
4151 kprintf("%02x", sc->tulip_rombuf[idx]);
4153 device_printf(dev, "%s%s pass %d.%d\n",
4154 sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
4155 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
4156 device_printf(dev, "address unknown\n");
4158 void (*intr_rtn)(void *) = tulip_intr_normal;
4160 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
4161 intr_rtn = tulip_intr_shared;
4164 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) {
4168 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
4169 RF_SHAREABLE | RF_ACTIVE);
4170 if (res == 0 || bus_setup_intr(dev, res, INTR_MPSAFE,
4172 sc->tulip_if.if_serializer)) {
4173 device_printf(dev, "couldn't map interrupt\n");
4175 kfree((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
4176 kfree((caddr_t) sc->tulip_txdescs, M_DEVBUF);
4180 sc->tulip_if.if_cpuid = ithread_cpuid(rman_get_start(res));
4181 KKASSERT(sc->tulip_if.if_cpuid >= 0 &&
4182 sc->tulip_if.if_cpuid < ncpus);
4188 static device_method_t tulip_pci_methods[] = {
4189 /* Device interface */
4190 DEVMETHOD(device_probe, tulip_pci_probe),
4191 DEVMETHOD(device_attach, tulip_pci_attach),
4192 DEVMETHOD(device_shutdown, tulip_shutdown),
4195 static driver_t tulip_pci_driver = {
4198 sizeof(tulip_softc_t),
4200 static devclass_t tulip_devclass;
4202 DECLARE_DUMMY_MODULE(if_de);
4203 DRIVER_MODULE(if_de, pci, tulip_pci_driver, tulip_devclass, 0, 0);