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.29 2005/02/21 20:48:13 joerg 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 withough 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>
51 #include <machine/clock.h>
52 #include <machine/bus.h>
53 #include <machine/resource.h>
61 #include <net/if_media.h>
62 #include <net/if_dl.h>
67 #include <netinet/in.h>
68 #include <netinet/if_ether.h>
72 #include <netproto/ipx/ipx.h>
73 #include <netproto/ipx/ipx_if.h>
77 #include <netproto/ns/ns.h>
78 #include <netproto/ns/ns_if.h>
83 #include <net/if_var.h>
85 #include <bus/pci/pcivar.h>
86 #include <bus/pci/pcireg.h>
87 #include <bus/pci/dc21040reg.h>
90 * Intel CPUs should use I/O mapped access.
93 #define TULIP_IOMAPPED
100 static tulip_softc_t *tulips[TULIP_MAX_DEVICES];
103 * This module supports
104 * the DEC 21040 PCI Ethernet Controller.
105 * the DEC 21041 PCI Ethernet Controller.
106 * the DEC 21140 PCI Fast Ethernet Controller.
108 static void tulip_mii_autonegotiate(tulip_softc_t *, u_int);
109 static void tulip_intr_shared(void *);
110 static void tulip_intr_normal(void *);
111 static void tulip_init(tulip_softc_t *);
112 static void tulip_reset(tulip_softc_t *);
113 static void tulip_ifstart(struct ifnet *);
114 static struct mbuf *tulip_txput(tulip_softc_t *, struct mbuf *);
115 static void tulip_txput_setup(tulip_softc_t *);
116 static void tulip_rx_intr(tulip_softc_t *);
117 static void tulip_addr_filter(tulip_softc_t *);
118 static u_int tulip_mii_readreg(tulip_softc_t *, u_int, u_int);
119 static void tulip_mii_writereg(tulip_softc_t *, u_int, u_int, u_int);
120 static int tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities);
121 static tulip_media_t tulip_mii_phy_readspecific(tulip_softc_t *);
122 static int tulip_srom_decode(tulip_softc_t *);
123 static int tulip_ifmedia_change(struct ifnet *);
124 static void tulip_ifmedia_status(struct ifnet *, struct ifmediareq *);
125 /* static void tulip_21140_map_media(tulip_softc_t *sc); */
128 tulip_timeout_callback(void *arg)
130 tulip_softc_t *sc = arg;
133 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING;
134 sc->tulip_probe_timeout -= 1000 / TULIP_HZ;
135 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER);
140 tulip_timeout(tulip_softc_t *sc)
142 if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
144 sc->tulip_flags |= TULIP_TIMEOUTPENDING;
145 callout_reset(&sc->tulip_timer, (hz + TULIP_HZ / 2) / TULIP_HZ,
146 tulip_timeout_callback, sc);
150 tulip_txprobe(tulip_softc_t *sc)
154 * Before we are sure this is the right media we need
155 * to send a small packet to make sure there's carrier.
156 * Strangely, BNC and AUI will "see" receive data if
157 * either is connected so the transmit is the only way
158 * to verify the connectivity.
160 MGETHDR(m, MB_DONTWAIT, MT_DATA);
164 * Construct a LLC TEST message which will point to ourselves.
166 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_dhost, 6);
167 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_shost, 6);
168 mtod(m, struct ether_header *)->ether_type = htons(3);
169 mtod(m, unsigned char *)[14] = 0;
170 mtod(m, unsigned char *)[15] = 0;
171 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
172 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
176 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
177 sc->tulip_intrmask |= TULIP_STS_TXINTR;
178 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
179 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
180 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
181 if ((m = tulip_txput(sc, m)) != NULL)
183 sc->tulip_probe.probe_txprobes++;
188 #define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0)
190 #define TULIP_SIAGEN_WATCHDOG 0
194 tulip_media_set(tulip_softc_t *sc, tulip_media_t media)
196 const tulip_media_info_t *mi = sc->tulip_mediums[media];
202 * If we are switching media, make sure we don't think there's
203 * any stale RX activity
205 sc->tulip_flags &= ~TULIP_RXACT;
206 if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
207 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
208 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx);
209 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
210 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
212 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
214 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
216 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity);
217 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
218 #define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL)
220 * If the cmdmode bits don't match the currently operating mode,
221 * set the cmdmode appropriately and reset the chip.
223 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
224 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
225 sc->tulip_cmdmode |= mi->mi_cmdmode;
228 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
230 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata);
231 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
233 * If the cmdmode bits don't match the currently operating mode,
234 * set the cmdmode appropriately and reset the chip.
236 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
237 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
238 sc->tulip_cmdmode |= mi->mi_cmdmode;
241 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol);
242 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata);
243 } else if (mi->mi_type == TULIP_MEDIAINFO_MII
244 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) {
246 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
248 dp = &sc->tulip_rombuf[mi->mi_reset_offset];
249 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) {
251 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
253 sc->tulip_phyaddr = mi->mi_phyaddr;
254 dp = &sc->tulip_rombuf[mi->mi_gpr_offset];
255 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) {
257 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
260 for (idx = 0; idx < mi->mi_reset_length; idx++) {
262 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]);
264 sc->tulip_phyaddr = mi->mi_phyaddr;
265 for (idx = 0; idx < mi->mi_gpr_length; idx++) {
267 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]);
270 if (sc->tulip_flags & TULIP_TRYNWAY) {
271 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
272 } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
273 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL);
274 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE);
275 sc->tulip_flags &= ~TULIP_DIDNWAY;
276 if (TULIP_IS_MEDIA_FD(media))
277 data |= PHYCTL_FULL_DUPLEX;
278 if (TULIP_IS_MEDIA_100MB(media))
279 data |= PHYCTL_SELECT_100MB;
280 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data);
286 tulip_linkup(tulip_softc_t *sc, tulip_media_t media)
288 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
289 sc->tulip_flags |= TULIP_PRINTLINKUP;
290 sc->tulip_flags |= TULIP_LINKUP;
291 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
292 #if 0 /* XXX how does with work with ifmedia? */
293 if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
294 if (sc->tulip_if.if_flags & IFF_FULLDUPLEX) {
295 if (TULIP_CAN_MEDIA_FD(media)
296 && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL)
297 media = TULIP_FD_MEDIA_OF(media);
299 if (TULIP_IS_MEDIA_FD(media)
300 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL)
301 media = TULIP_HD_MEDIA_OF(media);
305 if (sc->tulip_media != media) {
306 sc->tulip_media = media;
307 sc->tulip_flags |= TULIP_PRINTMEDIA;
308 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) {
309 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
310 } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) {
311 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
315 * We could set probe_timeout to 0 but setting to 3000 puts this
316 * in one central place and the only matters is tulip_link is
317 * followed by a tulip_timeout. Therefore setting it should not
318 * result in aberrant behavour.
320 sc->tulip_probe_timeout = 3000;
321 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
322 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY);
323 if (sc->tulip_flags & TULIP_INRESET) {
324 tulip_media_set(sc, sc->tulip_media);
325 } else if (sc->tulip_probe_media != sc->tulip_media) {
327 * No reason to change media if we have the right media.
335 tulip_media_print(tulip_softc_t *sc)
337 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
339 if (sc->tulip_flags & TULIP_PRINTMEDIA) {
340 printf("%s%d: enabling %s port\n",
341 sc->tulip_name, sc->tulip_unit,
342 tulip_mediums[sc->tulip_media]);
343 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
344 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
345 printf("%s%d: link up\n", sc->tulip_name, sc->tulip_unit);
346 sc->tulip_flags &= ~TULIP_PRINTLINKUP;
350 #if defined(TULIP_DO_GPR_SENSE)
352 tulip_21140_gpr_media_sense(tulip_softc_t *sc)
354 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
355 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
359 * If one of the media blocks contained a default media flag,
362 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
363 const tulip_media_info_t *mi;
365 * Media is not supported (or is full-duplex).
367 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media))
369 if (mi->mi_type != TULIP_MEDIAINFO_GPR)
373 * Remember the media is this is the "default" media.
375 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
379 * No activity mask? Can't see if it is active if there's no mask.
381 if (mi->mi_actmask == 0)
385 * Does the activity data match?
387 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
391 * It does! If this is the first media we detected, then
392 * remember this media. If isn't the first, then there were
393 * multiple matches which we equate to no match (since we don't
394 * which to select (if any).
396 if (last_media == TULIP_MEDIA_UNKNOWN) {
398 } else if (last_media != media) {
399 last_media = TULIP_MEDIA_UNKNOWN;
402 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
404 #endif /* TULIP_DO_GPR_SENSE */
406 static tulip_link_status_t
407 tulip_media_link_monitor(tulip_softc_t *sc)
409 const tulip_media_info_t *mi = sc->tulip_mediums[sc->tulip_media];
410 tulip_link_status_t linkup = TULIP_LINK_DOWN;
413 #if defined(DIAGNOSTIC)
414 panic("tulip_media_link_monitor: %s: botch at line %d\n",
415 tulip_mediums[sc->tulip_media],__LINE__);
417 return TULIP_LINK_UNKNOWN;
422 * Have we seen some packets? If so, the link must be good.
424 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) {
425 sc->tulip_flags &= ~TULIP_RXACT;
426 sc->tulip_probe_timeout = 3000;
427 return TULIP_LINK_UP;
430 sc->tulip_flags &= ~TULIP_RXACT;
431 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
434 * Read the PHY status register.
436 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
437 if (status & PHYSTS_AUTONEG_DONE) {
439 * If the PHY has completed autonegotiation, see the if the
440 * remote systems abilities have changed. If so, upgrade or
441 * downgrade as appropriate.
443 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
444 abilities = (abilities << 6) & status;
445 if (abilities != sc->tulip_abilities) {
446 if (tulip_mii_map_abilities(sc, abilities)) {
447 tulip_linkup(sc, sc->tulip_probe_media);
448 return TULIP_LINK_UP;
451 * if we had selected media because of autonegotiation,
452 * we need to probe for the new media.
454 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
455 if (sc->tulip_flags & TULIP_DIDNWAY)
456 return TULIP_LINK_DOWN;
460 * The link is now up. If was down, say its back up.
462 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP)
463 linkup = TULIP_LINK_UP;
464 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
466 * No activity sensor? Assume all's well.
468 if (mi->mi_actmask == 0)
469 return TULIP_LINK_UNKNOWN;
471 * Does the activity data match?
473 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata)
474 linkup = TULIP_LINK_UP;
475 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
477 * Assume non TP ok for now.
479 if (!TULIP_IS_MEDIA_TP(sc->tulip_media))
480 return TULIP_LINK_UNKNOWN;
481 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
482 linkup = TULIP_LINK_UP;
483 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
484 return TULIP_LINK_UNKNOWN;
487 * We will wait for 3 seconds until the link goes into suspect mode.
489 if (sc->tulip_flags & TULIP_LINKUP) {
490 if (linkup == TULIP_LINK_UP)
491 sc->tulip_probe_timeout = 3000;
492 if (sc->tulip_probe_timeout > 0)
493 return TULIP_LINK_UP;
495 sc->tulip_flags &= ~TULIP_LINKUP;
496 printf("%s%d: link down: cable problem?\n", sc->tulip_name, sc->tulip_unit);
498 return TULIP_LINK_DOWN;
502 tulip_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
504 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
505 && event == TULIP_MEDIAPOLL_TIMER) {
506 switch (tulip_media_link_monitor(sc)) {
507 case TULIP_LINK_DOWN: {
509 * Link Monitor failed. Probe for new media.
511 event = TULIP_MEDIAPOLL_LINKFAIL;
514 case TULIP_LINK_UP: {
521 case TULIP_LINK_UNKNOWN: {
523 * We can't tell so don't bother.
530 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
531 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
532 if (TULIP_DO_AUTOSENSE(sc)) {
533 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
534 if (sc->tulip_if.if_flags & IFF_UP)
535 tulip_reset(sc); /* restart probe */
541 if (event == TULIP_MEDIAPOLL_START) {
542 sc->tulip_if.if_flags |= IFF_OACTIVE;
543 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
545 sc->tulip_probe_mediamask = 0;
546 sc->tulip_probe_passes = 0;
548 * If the SROM contained an explicit media to use, use it.
550 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX);
551 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS;
552 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
554 * connidx is defaulted to a media_unknown type.
556 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media;
557 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) {
558 tulip_linkup(sc, sc->tulip_probe_media);
563 if (sc->tulip_features & TULIP_HAVE_GPR) {
564 sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
565 sc->tulip_probe_timeout = 2000;
567 sc->tulip_probe_media = TULIP_MEDIA_MAX;
568 sc->tulip_probe_timeout = 0;
569 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
574 * Ignore txprobe failures or spurious callbacks.
576 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED
577 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) {
578 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
583 * If we really transmitted a packet, then that's the media we'll use.
585 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) {
586 if (event == TULIP_MEDIAPOLL_LINKPASS) {
587 /* XXX Check media status just to be sure */
588 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
590 tulip_linkup(sc, sc->tulip_probe_media);
595 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) {
596 #if defined(TULIP_DO_GPR_SENSE)
598 * Check for media via the general purpose register.
600 * Try to sense the media via the GPR. If the same value
601 * occurs 3 times in a row then just use that.
603 if (sc->tulip_probe_timeout > 0) {
604 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
605 if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
606 if (new_probe_media == sc->tulip_probe_media) {
607 if (--sc->tulip_probe_count == 0)
608 tulip_linkup(sc, sc->tulip_probe_media);
610 sc->tulip_probe_count = 10;
613 sc->tulip_probe_media = new_probe_media;
617 #endif /* TULIP_DO_GPR_SENSE */
619 * Brute force. We cycle through each of the media types
620 * and try to transmit a packet.
622 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
623 sc->tulip_probe_media = TULIP_MEDIA_MAX;
624 sc->tulip_probe_timeout = 0;
629 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST
630 && (sc->tulip_features & TULIP_HAVE_MII)) {
631 tulip_media_t old_media = sc->tulip_probe_media;
632 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
633 switch (sc->tulip_probe_state) {
634 case TULIP_PROBE_FAILED:
635 case TULIP_PROBE_MEDIATEST: {
637 * Try the next media.
639 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask;
640 sc->tulip_probe_timeout = 0;
642 if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
644 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
646 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
650 case TULIP_PROBE_PHYAUTONEG: {
653 case TULIP_PROBE_INACTIVE: {
655 * Only probe if we autonegotiated a media that hasn't failed.
657 sc->tulip_probe_timeout = 0;
658 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) {
659 sc->tulip_probe_media = old_media;
662 tulip_linkup(sc, sc->tulip_probe_media);
667 #if defined(DIAGNOSTIC)
668 panic("tulip_media_poll: botch at line %d\n", __LINE__);
675 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
676 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
681 * switch to another media if we tried this one enough.
683 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
685 * Find the next media type to check for. Full Duplex
686 * types are not allowed.
689 sc->tulip_probe_media -= 1;
690 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
691 if (++sc->tulip_probe_passes == 3) {
692 printf("%s%d: autosense failed: cable problem?\n",
693 sc->tulip_name, sc->tulip_unit);
694 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
695 sc->tulip_if.if_flags &= ~IFF_RUNNING;
696 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
700 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */
701 sc->tulip_probe_mediamask = 0;
702 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1;
704 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL
705 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
706 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
708 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
709 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
710 sc->tulip_probe.probe_txprobes = 0;
712 tulip_media_set(sc, sc->tulip_probe_media);
713 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
718 * If this is hanging off a phy, we know are doing NWAY and we have
719 * forced the phy to a specific speed. Wait for link up before
720 * before sending a packet.
722 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) {
723 case TULIP_MEDIAINFO_MII: {
724 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
728 case TULIP_MEDIAINFO_SIA: {
729 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) {
730 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL)
732 tulip_linkup(sc, sc->tulip_probe_media);
734 if (sc->tulip_features & TULIP_HAVE_MII)
741 case TULIP_MEDIAINFO_RESET:
742 case TULIP_MEDIAINFO_SYM:
743 case TULIP_MEDIAINFO_NONE:
744 case TULIP_MEDIAINFO_GPR: {
749 * Try to send a packet.
755 tulip_media_select(tulip_softc_t *sc)
757 if (sc->tulip_features & TULIP_HAVE_GPR) {
758 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
760 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata);
763 * If this board has no media, just return
765 if (sc->tulip_features & TULIP_HAVE_NOMEDIA)
768 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
769 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
770 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START);
772 tulip_media_set(sc, sc->tulip_media);
777 tulip_21040_mediainfo_init(tulip_softc_t *sc, tulip_media_t media)
779 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
780 |TULIP_CMD_BACKOFFCTR;
781 sc->tulip_if.if_baudrate = 10000000;
783 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) {
784 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET);
785 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD);
786 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
789 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) {
790 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC);
793 if (media == TULIP_MEDIA_UNKNOWN) {
794 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA);
799 tulip_21040_media_probe(tulip_softc_t *sc)
801 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
805 tulip_21040_10baset_only_media_probe(tulip_softc_t *sc)
807 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
808 tulip_media_set(sc, TULIP_MEDIA_10BASET);
809 sc->tulip_media = TULIP_MEDIA_10BASET;
813 tulip_21040_10baset_only_media_select(tulip_softc_t *sc)
815 sc->tulip_flags |= TULIP_LINKUP;
816 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
817 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
818 sc->tulip_flags &= ~TULIP_SQETEST;
820 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
821 sc->tulip_flags |= TULIP_SQETEST;
823 tulip_media_set(sc, sc->tulip_media);
827 tulip_21040_auibnc_only_media_probe(tulip_softc_t *sc)
829 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
830 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
831 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
832 sc->tulip_media = TULIP_MEDIA_AUIBNC;
836 tulip_21040_auibnc_only_media_select(tulip_softc_t *sc)
838 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
839 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
842 static const tulip_boardsw_t tulip_21040_boardsw = {
844 tulip_21040_media_probe,
849 static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = {
851 tulip_21040_10baset_only_media_probe,
852 tulip_21040_10baset_only_media_select,
856 static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = {
858 tulip_21040_auibnc_only_media_probe,
859 tulip_21040_auibnc_only_media_select,
864 tulip_21041_mediainfo_init(tulip_softc_t *sc)
866 tulip_media_info_t *mi = sc->tulip_mediainfo;
869 if (sc->tulip_revinfo >= 0x20) {
870 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET);
871 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD);
872 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI);
873 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC);
877 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET);
878 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD);
879 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
880 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
884 tulip_21041_media_probe(tulip_softc_t *sc)
886 sc->tulip_if.if_baudrate = 10000000;
887 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
888 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
889 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
890 tulip_21041_mediainfo_init(sc);
894 tulip_21041_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
898 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
899 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
900 || !TULIP_DO_AUTOSENSE(sc))
902 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
903 tulip_reset(sc); /* start probe */
908 * If we've been been asked to start a poll or link change interrupt
909 * restart the probe (and reset the tulip to a known state).
911 if (event == TULIP_MEDIAPOLL_START) {
912 sc->tulip_if.if_flags |= IFF_OACTIVE;
913 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN);
915 if (sc->tulip_revinfo >= 0x20) {
916 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
917 sc->tulip_flags |= TULIP_DIDNWAY;
920 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
921 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
922 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
923 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT;
924 tulip_media_set(sc, TULIP_MEDIA_10BASET);
929 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
932 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
933 tulip_linkup(sc, sc->tulip_probe_media);
937 sia_status = TULIP_CSR_READ(sc, csr_sia_status);
938 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status);
939 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) {
940 if (sc->tulip_revinfo >= 0x20) {
941 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6)))
942 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
945 * If the link has passed LinkPass, 10baseT is the
946 * proper media to use.
948 tulip_linkup(sc, sc->tulip_probe_media);
953 * wait for up to 2.4 seconds for the link to reach pass state.
954 * Only then start scanning the other media for activity.
955 * choose media with receive activity over those without.
957 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) {
958 if (event != TULIP_MEDIAPOLL_TIMER)
960 if (sc->tulip_probe_timeout > 0
961 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
965 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
966 sc->tulip_flags |= TULIP_WANTRXACT;
967 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) {
968 sc->tulip_probe_media = TULIP_MEDIA_BNC;
970 sc->tulip_probe_media = TULIP_MEDIA_AUI;
972 tulip_media_set(sc, sc->tulip_probe_media);
978 * If we failed, clear the txprobe active flag.
980 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED)
981 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
984 if (event == TULIP_MEDIAPOLL_TIMER) {
986 * If we've received something, then that's our link!
988 if (sc->tulip_flags & TULIP_RXACT) {
989 tulip_linkup(sc, sc->tulip_probe_media);
993 * if no txprobe active
995 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0
996 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0
997 || (sia_status & TULIP_SIASTS_RXACTIVITY))) {
998 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1004 * Take 2 passes through before deciding to not
1005 * wait for receive activity. Then take another
1006 * two passes before spitting out a warning.
1008 if (sc->tulip_probe_timeout <= 0) {
1009 if (sc->tulip_flags & TULIP_WANTRXACT) {
1010 sc->tulip_flags &= ~TULIP_WANTRXACT;
1011 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1013 printf("%s%d: autosense failed: cable problem?\n",
1014 sc->tulip_name, sc->tulip_unit);
1015 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
1016 sc->tulip_if.if_flags &= ~IFF_RUNNING;
1017 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1025 * Since this media failed to probe, try the other one.
1027 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1028 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) {
1029 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1031 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1033 tulip_media_set(sc, sc->tulip_probe_media);
1034 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1038 static const tulip_boardsw_t tulip_21041_boardsw = {
1039 TULIP_21041_GENERIC,
1040 tulip_21041_media_probe,
1042 tulip_21041_media_poll
1045 static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
1046 { 0x20005c00, 0, /* 08-00-17 */
1048 { 0x19, 0x0040, 0x0040 }, /* 10TX */
1049 { 0x19, 0x0040, 0x0000 }, /* 100TX */
1052 { 0x0281F400, 0, /* 00-A0-7D */
1054 { 0x12, 0x0010, 0x0000 }, /* 10T */
1056 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1057 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1061 { 0x0015F420, 0, /* 00-A0-7D */
1063 { 0x12, 0x0010, 0x0000 }, /* 10T */
1065 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1066 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1070 { 0x0281F400, 0, /* 00-A0-BE */
1072 { 0x11, 0x8000, 0x0000 }, /* 10T */
1073 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1075 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1081 static tulip_media_t
1082 tulip_mii_phy_readspecific(tulip_softc_t *sc)
1084 const tulip_phy_attr_t *attr;
1088 static const tulip_media_t table[] = {
1089 TULIP_MEDIA_UNKNOWN,
1090 TULIP_MEDIA_10BASET,
1091 TULIP_MEDIA_100BASETX,
1092 TULIP_MEDIA_100BASET4,
1093 TULIP_MEDIA_UNKNOWN,
1094 TULIP_MEDIA_10BASET_FD,
1095 TULIP_MEDIA_100BASETX_FD,
1100 * Don't read phy specific registers if link is not up.
1102 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
1103 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS))
1104 return TULIP_MEDIA_UNKNOWN;
1106 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) |
1107 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH);
1108 for (attr = tulip_mii_phy_attrlist;; attr++) {
1109 if (attr->attr_id == 0)
1110 return TULIP_MEDIA_UNKNOWN;
1111 if ((id & ~0x0F) == attr->attr_id)
1115 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
1116 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_100TX];
1117 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1118 if ((data & pm->pm_mask) == pm->pm_value)
1121 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) {
1122 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_100T4];
1123 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1124 if ((data & pm->pm_mask) == pm->pm_value)
1127 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) {
1128 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_10T];
1129 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1130 if ((data & pm->pm_mask) == pm->pm_value)
1133 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) {
1134 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
1135 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1136 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
1142 tulip_mii_get_phyaddr(tulip_softc_t *sc, u_int offset)
1146 for (phyaddr = 1; phyaddr < 32; phyaddr++) {
1147 u_int status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1148 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1155 u_int status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
1156 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1157 return TULIP_MII_NOPHY;
1160 return TULIP_MII_NOPHY;
1164 tulip_mii_map_abilities(tulip_softc_t *sc, u_int abilities)
1166 sc->tulip_abilities = abilities;
1167 if (abilities & PHYSTS_100BASETX_FD) {
1168 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD;
1169 } else if (abilities & PHYSTS_100BASET4) {
1170 sc->tulip_probe_media = TULIP_MEDIA_100BASET4;
1171 } else if (abilities & PHYSTS_100BASETX) {
1172 sc->tulip_probe_media = TULIP_MEDIA_100BASETX;
1173 } else if (abilities & PHYSTS_10BASET_FD) {
1174 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1175 } else if (abilities & PHYSTS_10BASET) {
1176 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1178 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1181 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1186 tulip_mii_autonegotiate(tulip_softc_t *sc, u_int phyaddr)
1188 switch (sc->tulip_probe_state) {
1189 case TULIP_PROBE_MEDIATEST:
1190 case TULIP_PROBE_INACTIVE: {
1191 sc->tulip_flags |= TULIP_DIDNWAY;
1192 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET);
1193 sc->tulip_probe_timeout = 3000;
1194 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR;
1195 sc->tulip_probe_state = TULIP_PROBE_PHYRESET;
1198 case TULIP_PROBE_PHYRESET: {
1200 uint32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1201 if (data & PHYCTL_RESET) {
1202 if (sc->tulip_probe_timeout > 0) {
1206 printf("%s%d(phy%d): error: reset of PHY never completed!\n",
1207 sc->tulip_name, sc->tulip_unit, phyaddr);
1208 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1209 sc->tulip_probe_state = TULIP_PROBE_FAILED;
1210 sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
1213 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1214 if ((status & PHYSTS_CAN_AUTONEG) == 0) {
1215 sc->tulip_flags &= ~TULIP_DIDNWAY;
1216 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1219 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01))
1220 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
1221 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
1222 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1223 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
1224 sc->tulip_probe_timeout = 3000;
1227 case TULIP_PROBE_PHYAUTONEG: {
1228 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1230 if ((status & PHYSTS_AUTONEG_DONE) == 0) {
1231 if (sc->tulip_probe_timeout > 0) {
1235 sc->tulip_flags &= ~TULIP_DIDNWAY;
1236 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1239 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
1240 data = (data << 6) & status;
1241 if (!tulip_mii_map_abilities(sc, data))
1242 sc->tulip_flags &= ~TULIP_DIDNWAY;
1246 #if defined(DIAGNOSTIC)
1247 panic("tulip_media_poll: botch at line %d\n", __LINE__);
1255 tulip_2114x_media_preset(tulip_softc_t *sc)
1257 const tulip_media_info_t *mi = NULL;
1258 tulip_media_t media = sc->tulip_media;
1260 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1261 media = sc->tulip_media;
1263 media = sc->tulip_probe_media;
1265 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
1266 sc->tulip_flags &= ~TULIP_SQETEST;
1267 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
1268 mi = sc->tulip_mediums[media];
1269 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
1270 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1271 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR
1272 || mi->mi_type == TULIP_MEDIAINFO_SYM) {
1273 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
1274 sc->tulip_cmdmode |= mi->mi_cmdmode;
1275 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
1276 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
1280 case TULIP_MEDIA_BNC:
1281 case TULIP_MEDIA_AUI:
1282 case TULIP_MEDIA_10BASET: {
1283 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1284 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
1285 sc->tulip_if.if_baudrate = 10000000;
1286 sc->tulip_flags |= TULIP_SQETEST;
1289 case TULIP_MEDIA_10BASET_FD: {
1290 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
1291 sc->tulip_if.if_baudrate = 10000000;
1294 case TULIP_MEDIA_100BASEFX:
1295 case TULIP_MEDIA_100BASET4:
1296 case TULIP_MEDIA_100BASETX: {
1297 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL);
1298 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1299 sc->tulip_if.if_baudrate = 100000000;
1302 case TULIP_MEDIA_100BASEFX_FD:
1303 case TULIP_MEDIA_100BASETX_FD: {
1304 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT;
1305 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
1306 sc->tulip_if.if_baudrate = 100000000;
1313 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1317 ********************************************************************
1318 * Start of 21140/21140A support which does not use the MII interface
1322 tulip_null_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
1324 #if defined(DIAGNOSTIC)
1325 printf("%s%d: botch(media_poll) at line %d\n",
1326 sc->tulip_name, sc->tulip_unit, __LINE__);
1331 tulip_21140_mediainit(tulip_softc_t *sc, tulip_media_info_t *mip,
1332 tulip_media_t media, u_int gpdata, u_int cmdmode)
1334 sc->tulip_mediums[media] = mip;
1335 mip->mi_type = TULIP_MEDIAINFO_GPR;
1336 mip->mi_cmdmode = cmdmode;
1337 mip->mi_gpdata = gpdata;
1341 tulip_21140_evalboard_media_probe(tulip_softc_t *sc)
1343 tulip_media_info_t *mip = sc->tulip_mediainfo;
1345 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1346 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1347 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1348 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1349 TULIP_CSR_WRITE(sc, csr_command,
1350 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1351 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1352 TULIP_CSR_WRITE(sc, csr_command,
1353 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1355 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
1356 sc->tulip_media = TULIP_MEDIA_10BASET;
1358 sc->tulip_media = TULIP_MEDIA_100BASETX;
1360 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1362 TULIP_CMD_TXTHRSHLDCTL);
1363 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1365 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1366 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1368 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1369 |TULIP_CMD_SCRAMBLER);
1370 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1372 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1373 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1376 static const tulip_boardsw_t tulip_21140_eb_boardsw = {
1378 tulip_21140_evalboard_media_probe,
1380 tulip_null_media_poll,
1381 tulip_2114x_media_preset,
1385 tulip_21140_accton_media_probe(tulip_softc_t *sc)
1387 tulip_media_info_t *mip = sc->tulip_mediainfo;
1390 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1391 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1392 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1393 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1394 TULIP_CSR_WRITE(sc, csr_command,
1395 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1396 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1397 TULIP_CSR_WRITE(sc, csr_command,
1398 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1400 gpdata = TULIP_CSR_READ(sc, csr_gp);
1401 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) {
1402 sc->tulip_media = TULIP_MEDIA_10BASET;
1404 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) {
1405 sc->tulip_media = TULIP_MEDIA_BNC;
1407 sc->tulip_media = TULIP_MEDIA_100BASETX;
1410 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC,
1411 TULIP_GP_EN1207_BNC_INIT,
1412 TULIP_CMD_TXTHRSHLDCTL);
1413 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1414 TULIP_GP_EN1207_UTP_INIT,
1415 TULIP_CMD_TXTHRSHLDCTL);
1416 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1417 TULIP_GP_EN1207_UTP_INIT,
1418 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1419 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1420 TULIP_GP_EN1207_100_INIT,
1421 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1422 |TULIP_CMD_SCRAMBLER);
1423 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1424 TULIP_GP_EN1207_100_INIT,
1425 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1426 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1429 static const tulip_boardsw_t tulip_21140_accton_boardsw = {
1431 tulip_21140_accton_media_probe,
1433 tulip_null_media_poll,
1434 tulip_2114x_media_preset,
1438 tulip_21140_smc9332_media_probe(tulip_softc_t *sc)
1440 tulip_media_info_t *mip = sc->tulip_mediainfo;
1443 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE);
1444 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
1445 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
1446 33MHz that comes to two microseconds but wait a
1447 bit longer anyways) */
1448 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT |
1449 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1450 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS;
1451 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT;
1452 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET);
1453 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT);
1455 for (idx = 1000; idx > 0; idx--) {
1456 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1457 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) {
1460 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
1467 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1468 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1469 TULIP_GP_SMC_9332_INIT,
1470 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1471 |TULIP_CMD_SCRAMBLER);
1472 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1473 TULIP_GP_SMC_9332_INIT,
1474 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1475 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1476 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1477 TULIP_GP_SMC_9332_INIT,
1478 TULIP_CMD_TXTHRSHLDCTL);
1479 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1480 TULIP_GP_SMC_9332_INIT,
1481 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1484 static const tulip_boardsw_t tulip_21140_smc9332_boardsw = {
1485 TULIP_21140_SMC_9332,
1486 tulip_21140_smc9332_media_probe,
1488 tulip_null_media_poll,
1489 tulip_2114x_media_preset,
1493 tulip_21140_cogent_em100_media_probe(tulip_softc_t *sc)
1495 tulip_media_info_t *mip = sc->tulip_mediainfo;
1496 uint32_t cmdmode = TULIP_CSR_READ(sc, csr_command);
1498 sc->tulip_gpinit = TULIP_GP_EM100_PINS;
1499 sc->tulip_gpdata = TULIP_GP_EM100_INIT;
1500 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS);
1501 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT);
1503 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE;
1504 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER);
1505 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1506 TULIP_CSR_WRITE(sc, csr_command, cmdmode);
1507 sc->tulip_media = TULIP_MEDIA_100BASEFX;
1509 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX,
1510 TULIP_GP_EM100_INIT,
1511 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION);
1512 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD,
1513 TULIP_GP_EM100_INIT,
1514 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1515 |TULIP_CMD_FULLDUPLEX);
1517 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);
1518 sc->tulip_media = TULIP_MEDIA_100BASETX;
1519 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1520 TULIP_GP_EM100_INIT,
1521 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1522 |TULIP_CMD_SCRAMBLER);
1523 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1524 TULIP_GP_EM100_INIT,
1525 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1526 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1530 static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {
1531 TULIP_21140_COGENT_EM100,
1532 tulip_21140_cogent_em100_media_probe,
1534 tulip_null_media_poll,
1535 tulip_2114x_media_preset
1539 tulip_21140_znyx_zx34x_media_probe(tulip_softc_t *sc)
1541 tulip_media_info_t *mip = sc->tulip_mediainfo;
1542 int cnt10 = 0, cnt100 = 0, idx;
1544 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS;
1545 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT;
1546 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS);
1547 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT);
1548 TULIP_CSR_WRITE(sc, csr_command,
1549 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1550 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1551 TULIP_CSR_WRITE(sc, csr_command,
1552 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1555 for (idx = 1000; idx > 0; idx--) {
1556 uint32_t csr = TULIP_CSR_READ(sc, csr_gp);
1557 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)) {
1560 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
1569 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1570 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1571 TULIP_GP_ZX34X_INIT,
1572 TULIP_CMD_TXTHRSHLDCTL);
1573 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1574 TULIP_GP_ZX34X_INIT,
1575 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1576 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1577 TULIP_GP_ZX34X_INIT,
1578 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1579 |TULIP_CMD_SCRAMBLER);
1580 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1581 TULIP_GP_ZX34X_INIT,
1582 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1583 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1586 static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = {
1587 TULIP_21140_ZNYX_ZX34X,
1588 tulip_21140_znyx_zx34x_media_probe,
1590 tulip_null_media_poll,
1591 tulip_2114x_media_preset,
1595 tulip_2114x_media_probe(tulip_softc_t *sc)
1597 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE | TULIP_CMD_BACKOFFCTR |
1598 TULIP_CMD_THRSHLD72;
1601 static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
1603 tulip_2114x_media_probe,
1606 tulip_2114x_media_preset,
1610 * ******** END of chip-specific handlers. ***********
1614 * Code the read the SROM and MII bit streams (I2C)
1617 TULIP_CSR_WRITE(sc, csr_srom_mii, csr); \
1622 tulip_srom_idle(tulip_softc_t *sc)
1626 csr = SROMSEL ; EMIT;
1627 csr = SROMSEL | SROMRD; EMIT;
1628 csr ^= SROMCS; EMIT;
1629 csr ^= SROMCLKON; EMIT;
1632 * Write 25 cycles of 0 which will force the SROM to be idle.
1634 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1635 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1636 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1638 csr ^= SROMCLKOFF; EMIT;
1639 csr ^= SROMCS; EMIT;
1645 tulip_srom_read(tulip_softc_t *sc)
1647 const u_int bitwidth = SROM_BITWIDTH;
1648 const u_int cmdmask = (SROMCMD_RD << bitwidth);
1649 const u_int msb = 1 << (bitwidth + 3 - 1);
1650 u_int idx, lastidx = (1 << bitwidth) - 1;
1652 tulip_srom_idle(sc);
1654 for (idx = 0; idx <= lastidx; idx++) {
1655 u_int lastbit, data, bits, bit, csr;
1656 csr = SROMSEL ; EMIT;
1657 csr = SROMSEL | SROMRD; EMIT;
1658 csr ^= SROMCSON; EMIT;
1659 csr ^= SROMCLKON; EMIT;
1662 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
1663 u_int thisbit = bits & msb;
1664 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1665 if (thisbit != lastbit) {
1666 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1670 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1673 csr ^= SROMCLKOFF; EMIT;
1675 for (data = 0, bits = 0; bits < 16; bits++) {
1677 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1678 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1679 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1681 sc->tulip_rombuf[idx*2] = data & 0xFF;
1682 sc->tulip_rombuf[idx*2+1] = data >> 8;
1683 csr = SROMSEL | SROMRD; EMIT;
1686 tulip_srom_idle(sc);
1689 #define MII_EMIT do { \
1690 TULIP_CSR_WRITE(sc, csr_srom_mii, csr); \
1695 tulip_mii_writebits(tulip_softc_t *sc, u_int data, u_int bits)
1697 u_int csr, msb, lastbit;
1699 msb = 1 << (bits - 1);
1700 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1701 lastbit = (csr & MII_DOUT) ? msb : 0;
1702 csr |= MII_WR; MII_EMIT; /* clock low; assert write */
1704 for (; bits > 0; bits--, data <<= 1) {
1705 const unsigned thisbit = data & msb;
1706 if (thisbit != lastbit) {
1707 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */
1709 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1711 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1716 tulip_mii_turnaround(tulip_softc_t *sc, u_int cmd)
1720 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1722 if (cmd == MII_WRCMD) {
1723 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
1724 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1725 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1726 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */
1728 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */
1730 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1731 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1735 tulip_mii_readbits(tulip_softc_t *sc)
1737 u_int csr, data, idx;
1739 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1741 for (idx = 0, data = 0; idx < 16; idx++) {
1742 data <<= 1; /* this is NOOP on the first pass through */
1743 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1744 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)
1746 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1748 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
1754 tulip_mii_readreg(tulip_softc_t *sc, u_int devaddr, u_int regno)
1759 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1760 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1761 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1762 tulip_mii_writebits(sc, MII_RDCMD, 8);
1763 tulip_mii_writebits(sc, devaddr, 5);
1764 tulip_mii_writebits(sc, regno, 5);
1765 tulip_mii_turnaround(sc, MII_RDCMD);
1767 data = tulip_mii_readbits(sc);
1772 tulip_mii_writereg(tulip_softc_t *sc, u_int devaddr, u_int regno, u_int data)
1776 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1777 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1778 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1779 tulip_mii_writebits(sc, MII_WRCMD, 8);
1780 tulip_mii_writebits(sc, devaddr, 5);
1781 tulip_mii_writebits(sc, regno, 5);
1782 tulip_mii_turnaround(sc, MII_WRCMD);
1783 tulip_mii_writebits(sc, data, 16);
1786 #define tulip_mchash(mca) (ether_crc32_le(mca, 6) & 0x1FF)
1787 #define tulip_srom_crcok(databuf) ( \
1788 ((ether_crc32_le(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
1789 ((databuf)[126] | ((databuf)[127] << 8)))
1792 tulip_identify_dec_nic(tulip_softc_t *sc)
1794 strcpy(sc->tulip_boardid, "DEC ");
1796 if (sc->tulip_chipid <= TULIP_21040)
1798 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0
1799 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {
1800 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);
1801 sc->tulip_boardid[D0+8] = ' ';
1807 tulip_identify_znyx_nic(tulip_softc_t * const sc)
1810 strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
1811 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
1813 sc->tulip_boardid[8] = '4';
1814 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
1815 if (znyx_ptr < 26 || znyx_ptr > 116) {
1816 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1819 /* ZX344 = 0010 .. 0013FF
1821 if (sc->tulip_rombuf[znyx_ptr] == 0x4A
1822 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52
1823 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) {
1824 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4];
1825 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) {
1826 sc->tulip_boardid[9] = '2';
1827 if (id == TULIP_ZNYX_ID_ZX342B) {
1828 sc->tulip_boardid[10] = 'B';
1829 sc->tulip_boardid[11] = ' ';
1831 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1832 } else if (id == TULIP_ZNYX_ID_ZX344) {
1833 sc->tulip_boardid[10] = '4';
1834 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1835 } else if (id == TULIP_ZNYX_ID_ZX345) {
1836 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5';
1837 } else if (id == TULIP_ZNYX_ID_ZX346) {
1838 sc->tulip_boardid[9] = '6';
1839 } else if (id == TULIP_ZNYX_ID_ZX351) {
1840 sc->tulip_boardid[8] = '5';
1841 sc->tulip_boardid[9] = '1';
1846 * Assume it's a ZX342...
1848 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1852 sc->tulip_boardid[8] = '1';
1853 if (sc->tulip_chipid == TULIP_21041) {
1854 sc->tulip_boardid[10] = '1';
1857 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) {
1858 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36];
1859 if (id == TULIP_ZNYX_ID_ZX312T) {
1860 sc->tulip_boardid[9] = '2';
1861 sc->tulip_boardid[10] = 'T';
1862 sc->tulip_boardid[11] = ' ';
1863 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1864 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) {
1865 sc->tulip_boardid[9] = '4';
1866 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1867 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1868 } else if (id == TULIP_ZNYX_ID_ZX314) {
1869 sc->tulip_boardid[9] = '4';
1870 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1871 sc->tulip_features |= TULIP_HAVE_BASEROM;
1872 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) {
1873 sc->tulip_boardid[9] = '5';
1874 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1875 } else if (id == TULIP_ZNYX_ID_ZX315) {
1876 sc->tulip_boardid[9] = '5';
1877 sc->tulip_features |= TULIP_HAVE_BASEROM;
1883 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) {
1884 sc->tulip_boardid[9] = '4';
1885 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1886 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1887 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) {
1888 sc->tulip_boardid[9] = '5';
1889 sc->tulip_boardsw = &tulip_21040_boardsw;
1890 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1891 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) {
1892 sc->tulip_boardid[9] = '2';
1893 sc->tulip_boardsw = &tulip_21040_boardsw;
1899 tulip_identify_smc_nic(tulip_softc_t * const sc)
1901 uint32_t id1, id2, ei;
1902 int auibnc = 0, utp = 0;
1905 strcpy(sc->tulip_boardid, "SMC ");
1906 if (sc->tulip_chipid == TULIP_21041)
1908 if (sc->tulip_chipid != TULIP_21040) {
1909 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
1910 strcpy(&sc->tulip_boardid[4], "9332DST ");
1911 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;
1912 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {
1913 strcpy(&sc->tulip_boardid[4], "9334BDT ");
1915 strcpy(&sc->tulip_boardid[4], "9332BDT ");
1919 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);
1920 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);
1921 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);
1923 strcpy(&sc->tulip_boardid[4], "8432");
1924 cp = &sc->tulip_boardid[8];
1926 *cp++ = 'B', auibnc = 1;
1927 if ((id1 & 0xFF) > 0x32)
1928 *cp++ = 'T', utp = 1;
1929 if ((id1 & 0x4000) == 0)
1930 *cp++ = 'A', auibnc = 1;
1932 sc->tulip_boardid[7] = '4';
1936 *cp++ = (ei ? '2' : '1');
1941 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1942 else if (!utp && auibnc)
1943 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
1947 tulip_identify_cogent_nic(tulip_softc_t * const sc)
1949 strcpy(sc->tulip_boardid, "Cogent ");
1950 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
1951 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {
1952 strcat(sc->tulip_boardid, "EM100TX ");
1953 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1954 #if defined(TULIP_COGENT_EM110TX_ID)
1955 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {
1956 strcat(sc->tulip_boardid, "EM110TX ");
1957 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1959 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1960 strcat(sc->tulip_boardid, "EM100FX ");
1961 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1964 * Magic number (0x24001109U) is the SubVendor (0x2400) and
1965 * SubDevId (0x1109) for the ANA6944TX (EM440TX).
1967 if (*(uint32_t *) sc->tulip_rombuf == 0x24001109U
1968 && (sc->tulip_features & TULIP_HAVE_BASEROM)) {
1970 * Cogent (Adaptec) is still mapping all INTs to INTA of
1971 * first 21140. Dumb! Dumb!
1973 strcat(sc->tulip_boardid, "EM440TX ");
1974 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
1976 } else if (sc->tulip_chipid == TULIP_21040) {
1977 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1982 tulip_identify_accton_nic(tulip_softc_t * const sc)
1984 strcpy(sc->tulip_boardid, "ACCTON ");
1985 switch (sc->tulip_chipid) {
1987 strcat(sc->tulip_boardid, "EN1207 ");
1988 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
1989 sc->tulip_boardsw = &tulip_21140_accton_boardsw;
1992 strcat(sc->tulip_boardid, "EN1207TX ");
1993 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
1994 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
1997 strcat(sc->tulip_boardid, "EN1203 ");
1998 sc->tulip_boardsw = &tulip_21040_boardsw;
2001 strcat(sc->tulip_boardid, "EN1203 ");
2002 sc->tulip_boardsw = &tulip_21041_boardsw;
2005 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2011 tulip_identify_asante_nic(tulip_softc_t * const sc)
2013 strcpy(sc->tulip_boardid, "Asante ");
2014 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
2015 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2016 tulip_media_info_t *mi = sc->tulip_mediainfo;
2019 * The Asante Fast Ethernet doesn't always ship with a valid
2020 * new format SROM. So if isn't in the new format, we cheat
2021 * set it up as if we had.
2024 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;
2025 sc->tulip_gpdata = 0;
2027 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);
2028 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);
2030 TULIP_CSR_WRITE(sc, csr_gp, 0);
2032 mi->mi_type = TULIP_MEDIAINFO_MII;
2033 mi->mi_gpr_length = 0;
2034 mi->mi_gpr_offset = 0;
2035 mi->mi_reset_length = 0;
2036 mi->mi_reset_offset = 0;;
2038 mi->mi_phyaddr = TULIP_MII_NOPHY;
2039 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) {
2041 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
2043 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2044 printf("%s%d: can't find phy 0\n", sc->tulip_name, sc->tulip_unit);
2048 sc->tulip_features |= TULIP_HAVE_MII;
2049 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2050 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2051 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD;
2052 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD;
2053 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2054 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2055 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2056 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2057 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2058 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2059 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2061 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2066 tulip_identify_compex_nic(tulip_softc_t *sc)
2068 strcpy(sc->tulip_boardid, "COMPEX ");
2069 if (sc->tulip_chipid == TULIP_21140A) {
2071 tulip_softc_t *root_sc = NULL;
2073 strcat(sc->tulip_boardid, "400TX/PCI ");
2075 * All 4 chips on these boards share an interrupt. This code
2076 * copied from tulip_read_macaddr.
2078 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2079 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2080 root_sc = tulips[root_unit];
2082 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
2087 && root_sc->tulip_chipid == sc->tulip_chipid
2088 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2089 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2090 sc->tulip_slaves = root_sc->tulip_slaves;
2091 root_sc->tulip_slaves = sc;
2092 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
2093 printf("\nCannot find master device for de%d interrupts",
2097 strcat(sc->tulip_boardid, "unknown ");
2099 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */
2104 tulip_srom_decode(tulip_softc_t *sc)
2106 u_int idx1, idx2, idx3;
2108 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
2109 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
2110 tulip_srom_media_t srom_media;
2111 tulip_media_info_t *mi = sc->tulip_mediainfo;
2113 uint32_t leaf_offset, blocks, data;
2115 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
2116 if (shp->sh_adapter_count == 1)
2118 if (saip->sai_device == sc->tulip_pci_devno)
2122 * Didn't find the right media block for this card.
2124 if (idx1 == shp->sh_adapter_count)
2128 * Save the hardware address.
2130 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6);
2132 * If this is a multiple port card, add the adapter index to the last
2133 * byte of the hardware address. (if it isn't multiport, adding 0
2136 sc->tulip_enaddr[5] += idx1;
2138 leaf_offset = saip->sai_leaf_offset_lowbyte
2139 + saip->sai_leaf_offset_highbyte * 256;
2140 dp = sc->tulip_rombuf + leaf_offset;
2142 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2;
2144 for (idx2 = 0;; idx2++) {
2145 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype
2146 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED)
2149 sc->tulip_connidx = idx2;
2151 if (sc->tulip_chipid == TULIP_21041) {
2153 for (idx2 = 0; idx2 < blocks; idx2++) {
2154 tulip_media_t media;
2156 srom_media = (tulip_srom_media_t) (data & 0x3F);
2157 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2158 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2161 media = tulip_srom_mediums[idx3].sm_type;
2162 if (media != TULIP_MEDIA_UNKNOWN) {
2163 if (data & TULIP_SROM_21041_EXTENDED) {
2164 mi->mi_type = TULIP_MEDIAINFO_SIA;
2165 sc->tulip_mediums[media] = mi;
2166 mi->mi_sia_connectivity = dp[0] + dp[1] * 256;
2167 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256;
2168 mi->mi_sia_general = dp[4] + dp[5] * 256;
2172 case TULIP_MEDIA_BNC: {
2173 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
2177 case TULIP_MEDIA_AUI: {
2178 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
2182 case TULIP_MEDIA_10BASET: {
2183 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
2187 case TULIP_MEDIA_10BASET_FD: {
2188 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
2198 if (data & TULIP_SROM_21041_EXTENDED)
2203 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++;
2204 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++;
2205 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++;
2206 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++;
2210 unsigned length, type;
2211 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN;
2212 if (sc->tulip_features & TULIP_HAVE_GPR)
2213 sc->tulip_gpinit = *dp++;
2215 for (idx2 = 0; idx2 < blocks; idx2++) {
2217 if ((*dp & 0x80) == 0) {
2221 length = (*dp++ & 0x7f) - 1;
2222 type = *dp++ & 0x3f;
2225 switch (type & 0x3f) {
2226 case 0: { /* 21140[A] GPR block */
2227 tulip_media_t media;
2228 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2229 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2230 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2233 media = tulip_srom_mediums[idx3].sm_type;
2234 if (media == TULIP_MEDIA_UNKNOWN)
2236 mi->mi_type = TULIP_MEDIAINFO_GPR;
2237 sc->tulip_mediums[media] = mi;
2238 mi->mi_gpdata = dp[1];
2239 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) {
2240 sc->tulip_gpdata = mi->mi_gpdata;
2243 data = dp[2] + dp[3] * 256;
2244 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2245 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2249 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2251 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2252 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2257 case 1: { /* 21140[A] MII block */
2258 const u_int phyno = *dp++;
2259 mi->mi_type = TULIP_MEDIAINFO_MII;
2260 mi->mi_gpr_length = *dp++;
2261 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2262 dp += mi->mi_gpr_length;
2263 mi->mi_reset_length = *dp++;
2264 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2265 dp += mi->mi_reset_length;
2268 * Before we probe for a PHY, use the GPR information
2269 * to select it. If we don't, it may be inaccessible.
2271 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET);
2272 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) {
2274 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]);
2276 sc->tulip_phyaddr = mi->mi_phyaddr;
2277 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) {
2279 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]);
2283 * At least write something!
2285 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2286 TULIP_CSR_WRITE(sc, csr_gp, 0);
2288 mi->mi_phyaddr = TULIP_MII_NOPHY;
2289 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2291 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2293 if (mi->mi_phyaddr == TULIP_MII_NOPHY)
2295 sc->tulip_features |= TULIP_HAVE_MII;
2296 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2297 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2298 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2299 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2300 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2301 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2302 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2303 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2304 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2305 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2306 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2310 case 2: { /* 2114[23] SIA block */
2311 tulip_media_t media;
2312 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2313 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2314 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2317 media = tulip_srom_mediums[idx3].sm_type;
2318 if (media == TULIP_MEDIA_UNKNOWN)
2320 mi->mi_type = TULIP_MEDIAINFO_SIA;
2321 sc->tulip_mediums[media] = mi;
2323 mi->mi_sia_connectivity = dp[1] + dp[2] * 256;
2324 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256;
2325 mi->mi_sia_general = dp[5] + dp[6] * 256;
2329 case TULIP_MEDIA_BNC: {
2330 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
2333 case TULIP_MEDIA_AUI: {
2334 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
2337 case TULIP_MEDIA_10BASET: {
2338 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
2339 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2342 case TULIP_MEDIA_10BASET_FD: {
2343 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
2344 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2352 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16;
2353 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16;
2358 case 3: { /* 2114[23] MII PHY block */
2359 const u_int phyno = *dp++;
2361 mi->mi_type = TULIP_MEDIAINFO_MII;
2362 mi->mi_gpr_length = *dp++;
2363 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2364 dp += 2 * mi->mi_gpr_length;
2365 mi->mi_reset_length = *dp++;
2366 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2367 dp += 2 * mi->mi_reset_length;
2369 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset];
2370 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) {
2372 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2374 sc->tulip_phyaddr = mi->mi_phyaddr;
2375 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset];
2376 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) {
2378 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2381 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2382 TULIP_CSR_WRITE(sc, csr_sia_general, 0);
2384 mi->mi_phyaddr = TULIP_MII_NOPHY;
2385 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2387 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2389 if (mi->mi_phyaddr == TULIP_MII_NOPHY)
2391 sc->tulip_features |= TULIP_HAVE_MII;
2392 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2393 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2394 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2395 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2396 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2;
2397 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2398 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2399 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2400 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2401 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2402 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2403 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2407 case 4: { /* 21143 SYM block */
2408 tulip_media_t media;
2409 srom_media = (tulip_srom_media_t) dp[0];
2410 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2411 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2414 media = tulip_srom_mediums[idx3].sm_type;
2415 if (media == TULIP_MEDIA_UNKNOWN)
2417 mi->mi_type = TULIP_MEDIAINFO_SYM;
2418 sc->tulip_mediums[media] = mi;
2419 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16;
2420 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16;
2421 data = dp[5] + dp[6] * 256;
2422 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2423 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2426 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2427 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2428 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2430 if (TULIP_IS_MEDIA_TP(media))
2431 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2436 case 5: { /* 21143 Reset block */
2437 mi->mi_type = TULIP_MEDIAINFO_RESET;
2438 mi->mi_reset_length = *dp++;
2439 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2440 dp += 2 * mi->mi_reset_length;
2451 return mi - sc->tulip_mediainfo;
2454 static const struct {
2455 void (*vendor_identify_nic)(tulip_softc_t * const sc);
2456 unsigned char vendor_oui[3];
2457 } tulip_vendors[] = {
2458 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } },
2459 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } },
2460 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } },
2461 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } },
2462 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } },
2463 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } },
2464 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } },
2465 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } },
2466 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } },
2467 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } },
2472 * This deals with the vagaries of the address roms and the
2473 * brain-deadness that various vendors commit in using them.
2476 tulip_read_macaddr(tulip_softc_t *sc)
2478 u_int cksum, rom_cksum, idx;
2480 unsigned char tmpbuf[8];
2481 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
2483 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX;
2485 if (sc->tulip_chipid == TULIP_21040) {
2486 TULIP_CSR_WRITE(sc, csr_enetrom, 1);
2487 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2489 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
2491 sc->tulip_rombuf[idx] = csr & 0xFF;
2493 sc->tulip_boardsw = &tulip_21040_boardsw;
2495 if (sc->tulip_chipid == TULIP_21041) {
2497 * Thankfully all 21041's act the same.
2499 sc->tulip_boardsw = &tulip_21041_boardsw;
2502 * Assume all 21140 board are compatible with the
2503 * DEC 10/100 evaluation board. Not really valid but
2504 * it's the best we can do until every one switches to
2505 * the new SROM format.
2508 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2510 tulip_srom_read(sc);
2511 if (tulip_srom_crcok(sc->tulip_rombuf)) {
2513 * SROM CRC is valid therefore it must be in the
2516 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM;
2517 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
2519 * No checksum is present. See if the SROM id checks out;
2520 * the first 18 bytes should be 0 followed by a 1 followed
2521 * by the number of adapters (which we don't deal with yet).
2523 for (idx = 0; idx < 18; idx++) {
2524 if (sc->tulip_rombuf[idx] != 0)
2527 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
2528 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2529 } else if (sc->tulip_chipid >= TULIP_21142) {
2530 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2531 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2533 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) {
2534 if (sc->tulip_chipid != TULIP_21041)
2535 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2538 * If the SROM specifies more than one adapter, tag this as a
2541 if (sc->tulip_rombuf[19] > 1)
2542 sc->tulip_features |= TULIP_HAVE_BASEROM;
2543 if (sc->tulip_boardsw == NULL)
2550 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
2552 * Some folks don't use the standard ethernet rom format
2553 * but instead just put the address in the first 6 bytes
2554 * of the rom and let the rest be all 0xffs. (Can we say
2555 * ZNYX?) (well sometimes they put in a checksum so we'll
2558 for (idx = 8; idx < 32; idx++) {
2559 if (sc->tulip_rombuf[idx] != 0xFF)
2563 * Make sure the address is not multicast or locally assigned
2564 * that the OUI is not 00-00-00.
2566 if ((sc->tulip_rombuf[0] & 3) != 0)
2568 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
2569 && sc->tulip_rombuf[2] == 0)
2571 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2572 sc->tulip_features |= TULIP_HAVE_OKROM;
2576 * A number of makers of multiport boards (ZNYX and Cogent)
2577 * only put on one address ROM on their 21040 boards. So
2578 * if the ROM is all zeros (or all 0xFFs), look at the
2579 * previous configured boards (as long as they are on the same
2580 * PCI bus and the bus number is non-zero) until we find the
2581 * master board with address ROM. We then use its address ROM
2582 * as the base for this board. (we add our relative board
2583 * to the last byte of its address).
2585 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2586 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF)
2589 if (idx == sizeof(sc->tulip_rombuf)) {
2591 tulip_softc_t *root_sc = NULL;
2592 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2593 root_sc = tulips[root_unit];
2594 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
2598 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM)
2599 && root_sc->tulip_chipid == sc->tulip_chipid
2600 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2601 sc->tulip_features |= TULIP_HAVE_SLAVEDROM;
2602 sc->tulip_boardsw = root_sc->tulip_boardsw;
2603 strcpy(sc->tulip_boardid, root_sc->tulip_boardid);
2604 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) {
2605 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf,
2606 sizeof(sc->tulip_rombuf));
2607 if (!tulip_srom_decode(sc))
2610 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
2611 sc->tulip_enaddr[5] += sc->tulip_unit - root_sc->tulip_unit;
2614 * Now for a truly disgusting kludge: all 4 21040s on
2615 * the ZX314 share the same INTA line so the mapping
2616 * setup by the BIOS on the PCI bridge is worthless.
2617 * Rather than reprogramming the value in the config
2618 * register, we will handle this internally.
2620 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) {
2621 sc->tulip_slaves = root_sc->tulip_slaves;
2622 root_sc->tulip_slaves = sc;
2623 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2631 * This is the standard DEC address ROM test.
2634 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
2637 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
2638 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
2639 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
2640 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
2641 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
2644 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2646 cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
2648 if (cksum > 65535) cksum -= 65535;
2649 cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
2650 if (cksum > 65535) cksum -= 65535;
2652 if (cksum > 65535) cksum -= 65535;
2653 cksum += *(u_int16_t *) &sc->tulip_enaddr[4];
2654 if (cksum >= 65535) cksum -= 65535;
2656 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6];
2658 if (cksum != rom_cksum)
2663 * Check for various boards based on OUI. Did I say braindead?
2665 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) {
2666 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) {
2667 (*tulip_vendors[idx].vendor_identify_nic)(sc);
2672 sc->tulip_features |= TULIP_HAVE_OKROM;
2677 tulip_ifmedia_add(tulip_softc_t * const sc)
2679 tulip_media_t media;
2682 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2683 if (sc->tulip_mediums[media] != NULL) {
2684 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media],
2690 sc->tulip_features |= TULIP_HAVE_NOMEDIA;
2691 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0);
2692 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE);
2693 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
2694 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0);
2695 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO);
2697 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]);
2698 sc->tulip_flags |= TULIP_PRINTMEDIA;
2699 tulip_linkup(sc, sc->tulip_media);
2704 tulip_ifmedia_change(struct ifnet *ifp)
2706 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2708 sc->tulip_flags |= TULIP_NEEDRESET;
2709 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
2710 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
2711 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) {
2712 tulip_media_t media;
2713 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2714 if (sc->tulip_mediums[media] != NULL
2715 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) {
2716 sc->tulip_flags |= TULIP_PRINTMEDIA;
2717 sc->tulip_flags &= ~TULIP_DIDNWAY;
2718 tulip_linkup(sc, media);
2723 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
2730 * Media status callback
2733 tulip_ifmedia_status(struct ifnet *ifp, struct ifmediareq *req)
2735 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2737 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN)
2740 req->ifm_status = IFM_AVALID;
2741 if (sc->tulip_flags & TULIP_LINKUP)
2742 req->ifm_status |= IFM_ACTIVE;
2744 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
2748 tulip_addr_filter(tulip_softc_t *sc)
2750 struct ifmultiaddr *ifma;
2754 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI);
2755 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART;
2756 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
2757 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
2758 #if defined(IFF_ALLMULTI)
2759 if (sc->tulip_if.if_flags & IFF_ALLMULTI)
2760 sc->tulip_flags |= TULIP_ALLMULTI ;
2764 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
2765 ifma = ifma->ifma_link.le_next) {
2767 if (ifma->ifma_addr->sa_family == AF_LINK)
2771 sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */
2772 if (multicnt > 14) {
2773 uint32_t *sp = sc->tulip_setupdata;
2776 * Some early passes of the 21140 have broken implementations of
2777 * hash-perfect mode. When we get too many multicasts for perfect
2778 * filtering with these chips, we need to switch into hash-only
2779 * mode (this is better than all-multicast on network with lots
2780 * of multicast traffic).
2782 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
2783 sc->tulip_flags |= TULIP_WANTHASHONLY;
2785 sc->tulip_flags |= TULIP_WANTHASHPERFECT;
2787 * If we have more than 14 multicasts, we have
2788 * go into hash perfect mode (512 bit multicast
2789 * hash and one perfect hardware).
2791 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
2793 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
2794 ifma = ifma->ifma_link.le_next) {
2796 if (ifma->ifma_addr->sa_family != AF_LINK)
2799 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
2800 #if BYTE_ORDER == BIG_ENDIAN
2801 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2803 sp[hash >> 4] |= 1 << (hash & 0xF);
2807 * No reason to use a hash if we are going to be
2808 * receiving every multicast.
2810 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
2811 hash = tulip_mchash(sc->tulip_if.if_broadcastaddr);
2812 #if BYTE_ORDER == BIG_ENDIAN
2813 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2815 sp[hash >> 4] |= 1 << (hash & 0xF);
2817 if (sc->tulip_flags & TULIP_WANTHASHONLY) {
2818 hash = tulip_mchash(sc->tulip_enaddr);
2819 #if BYTE_ORDER == BIG_ENDIAN
2820 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2822 sp[hash >> 4] |= 1 << (hash & 0xF);
2825 #if BYTE_ORDER == BIG_ENDIAN
2826 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
2827 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
2828 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
2830 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0];
2831 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1];
2832 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2];
2837 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
2838 uint32_t *sp = sc->tulip_setupdata;
2840 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
2842 * Else can get perfect filtering for 16 addresses.
2844 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
2845 ifma = ifma->ifma_link.le_next) {
2846 if (ifma->ifma_addr->sa_family != AF_LINK)
2848 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
2849 #if BYTE_ORDER == BIG_ENDIAN
2850 *sp++ = ((u_int16_t *) addrp)[0] << 16;
2851 *sp++ = ((u_int16_t *) addrp)[1] << 16;
2852 *sp++ = ((u_int16_t *) addrp)[2] << 16;
2854 *sp++ = ((u_int16_t *) addrp)[0];
2855 *sp++ = ((u_int16_t *) addrp)[1];
2856 *sp++ = ((u_int16_t *) addrp)[2];
2861 * Add the broadcast address.
2864 #if BYTE_ORDER == BIG_ENDIAN
2865 *sp++ = 0xFFFF << 16;
2866 *sp++ = 0xFFFF << 16;
2867 *sp++ = 0xFFFF << 16;
2875 * Pad the rest with our hardware address
2877 for (; idx < 16; idx++) {
2878 #if BYTE_ORDER == BIG_ENDIAN
2879 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
2880 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
2881 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
2883 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0];
2884 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1];
2885 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2];
2889 #if defined(IFF_ALLMULTI)
2890 if (sc->tulip_flags & TULIP_ALLMULTI)
2891 sc->tulip_if.if_flags |= IFF_ALLMULTI;
2896 tulip_reset(tulip_softc_t *sc)
2898 tulip_ringinfo_t *ri;
2900 uint32_t inreset = (sc->tulip_flags & TULIP_INRESET);
2903 * Brilliant. Simply brilliant. When switching modes/speeds
2904 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
2905 * bits in CSR6 and then do a software reset to get the 21140
2906 * to properly reset its internal pathways to the right places.
2909 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
2910 && sc->tulip_boardsw->bd_media_preset != NULL)
2911 (*sc->tulip_boardsw->bd_media_preset)(sc);
2913 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2914 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
2915 33MHz that comes to two microseconds but wait a
2916 bit longer anyways) */
2919 sc->tulip_flags |= TULIP_INRESET;
2920 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
2921 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
2922 sc->tulip_if.if_start = tulip_ifstart;
2925 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
2926 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
2927 TULIP_CSR_WRITE(sc, csr_busmode,
2928 (1 << (3 /*pci_max_burst_len*/ + 8))
2929 |TULIP_BUSMODE_CACHE_ALIGN8
2930 |TULIP_BUSMODE_READMULTIPLE
2931 |(BYTE_ORDER != LITTLE_ENDIAN ?
2932 TULIP_BUSMODE_DESC_BIGENDIAN : 0));
2934 sc->tulip_txtimer = 0;
2935 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
2937 * Free all the mbufs that were on the transmit ring.
2941 IF_DEQUEUE(&sc->tulip_txq, m);
2947 ri = &sc->tulip_txinfo;
2948 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
2949 ri->ri_free = ri->ri_max;
2950 for (di = ri->ri_first; di < ri->ri_last; di++)
2954 * We need to collect all the mbufs were on the
2955 * receive ring before we reinit it either to put
2956 * them back on or to know if we have to allocate
2959 ri = &sc->tulip_rxinfo;
2960 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
2961 ri->ri_free = ri->ri_max;
2962 for (di = ri->ri_first; di < ri->ri_last; di++) {
2964 di->d_length1 = 0; di->d_addr1 = 0;
2965 di->d_length2 = 0; di->d_addr2 = 0;
2969 IF_DEQUEUE(&sc->tulip_rxq, m);
2976 * If tulip_reset is being called recurisvely, exit quickly knowing
2977 * that when the outer tulip_reset returns all the right stuff will
2983 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
2984 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
2985 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
2986 |TULIP_STS_RXSTOPPED;
2988 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
2989 (*sc->tulip_boardsw->bd_media_select)(sc);
2990 tulip_media_print(sc);
2991 if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
2992 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
2994 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
2996 tulip_addr_filter(sc);
3000 tulip_init(tulip_softc_t * const sc)
3002 if (sc->tulip_if.if_flags & IFF_UP) {
3003 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) {
3004 /* initialize the media */
3007 sc->tulip_if.if_flags |= IFF_RUNNING;
3008 if (sc->tulip_if.if_flags & IFF_PROMISC) {
3009 sc->tulip_flags |= TULIP_PROMISC;
3010 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
3011 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3013 sc->tulip_flags &= ~TULIP_PROMISC;
3014 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
3015 if (sc->tulip_flags & TULIP_ALLMULTI) {
3016 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
3018 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
3021 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
3022 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
3024 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3025 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3027 sc->tulip_if.if_flags |= IFF_OACTIVE;
3028 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3029 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3031 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3032 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3033 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3034 tulip_txput_setup(sc);
3036 sc->tulip_if.if_flags &= ~IFF_RUNNING;
3042 tulip_rx_intr(tulip_softc_t *sc)
3044 tulip_ringinfo_t *ri = &sc->tulip_rxinfo;
3045 struct ifnet *ifp = &sc->tulip_if;
3049 struct ether_header eh;
3050 tulip_desc_t *eop = ri->ri_nextin;
3051 int total_len = 0, last_offset = 0;
3052 struct mbuf *ms = NULL, *me = NULL;
3055 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
3059 * If the TULIP has no descriptors, there can't be any receive
3060 * descriptors to process.
3062 if (eop == ri->ri_nextout)
3066 * 90% of the packets will fit in one descriptor. So we optimize
3069 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3070 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
3071 IF_DEQUEUE(&sc->tulip_rxq, ms);
3075 * If still owned by the TULIP, don't touch it.
3077 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
3081 * It is possible (though improbable unless the BIG_PACKET support
3082 * is enabled or MCLBYTES < 1518) for a received packet to cross
3083 * more than one receive descriptor.
3085 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) {
3086 if (++eop == ri->ri_last)
3088 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3089 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
3096 * Dequeue the first buffer for the start of the packet. Hopefully
3097 * this will be the only one we need to dequeue. However, if the
3098 * packet consumed multiple descriptors, then we need to dequeue
3099 * those buffers and chain to the starting mbuf. All buffers but
3100 * the last buffer have the same length so we can set that now.
3101 * (we add to last_offset instead of multiplying since we normally
3102 * won't go into the loop and thereby saving a ourselves from
3103 * doing a multiplication by 0 in the normal case).
3105 IF_DEQUEUE(&sc->tulip_rxq, ms);
3106 for (me = ms; total_len > 0; total_len--) {
3107 me->m_len = TULIP_RX_BUFLEN;
3108 last_offset += TULIP_RX_BUFLEN;
3109 IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
3115 * Now get the size of received packet (minus the CRC).
3117 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
3118 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
3119 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0
3121 || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) &&
3122 (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT|
3123 TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC|
3124 TULIP_DSTS_RxOVERFLOW)) == 0)
3127 me->m_len = total_len - last_offset;
3129 eh = *mtod(ms, struct ether_header *);
3130 sc->tulip_flags |= TULIP_RXACT;
3134 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3135 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3137 if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
3138 sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
3140 if (eop->d_status & TULIP_DSTS_RxBADCRC) {
3141 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
3142 sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
3144 sc->tulip_dot3stats.dot3StatsFCSErrors++;
3150 if (++eop == ri->ri_last)
3152 ri->ri_nextin = eop;
3155 * Either we are priming the TULIP with mbufs (m == NULL)
3156 * or we are about to accept an mbuf for the upper layers
3157 * so we need to allocate an mbuf to replace it. If we
3158 * can't replace it, send up it anyways. This may cause
3159 * us to drop packets in the future but that's better than
3160 * being caught in livelock.
3162 * Note that if this packet crossed multiple descriptors
3163 * we don't even try to reallocate all the mbufs here.
3164 * Instead we rely on the test of the beginning of
3165 * the loop to refill for the extra consumed mbufs.
3167 if (accept || ms == NULL) {
3169 MGETHDR(m0, MB_DONTWAIT, MT_DATA);
3171 #if defined(TULIP_COPY_RXDATA)
3172 if (!accept || total_len >= (MHLEN - 2)) {
3174 MCLGET(m0, MB_DONTWAIT);
3175 if ((m0->m_flags & M_EXT) == 0) {
3179 #if defined(TULIP_COPY_RXDATA)
3184 #if defined(TULIP_COPY_RXDATA)
3188 #if !defined(TULIP_COPY_RXDATA)
3189 ms->m_pkthdr.len = total_len;
3190 ms->m_pkthdr.rcvif = ifp;
3191 m_adj(ms, sizeof(struct ether_header));
3192 ether_input(ifp, &eh, ms);
3195 #error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
3197 m0->m_data += 2; /* align data after header */
3198 m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
3199 m0->m_len = m0->m_pkthdr.len = total_len;
3200 m0->m_pkthdr.rcvif = ifp;
3201 m_adj(m0, sizeof(struct ether_header));
3202 ether_input(ifp, &eh, m0);
3204 #endif /* ! TULIP_COPY_RXDATA */
3210 * Couldn't allocate a new buffer. Don't bother
3211 * trying to replenish the receive queue.
3214 sc->tulip_flags |= TULIP_RXBUFSLOW;
3218 * Now give the buffer(s) to the TULIP and save in our
3222 tulip_desc_t * const nextout = ri->ri_nextout;
3223 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
3224 nextout->d_length1 = TULIP_RX_BUFLEN;
3225 nextout->d_status = TULIP_DSTS_OWNER;
3226 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
3227 if (++ri->ri_nextout == ri->ri_last)
3228 ri->ri_nextout = ri->ri_first;
3231 IF_ENQUEUE(&sc->tulip_rxq, ms);
3232 } while ((ms = me) != NULL);
3234 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
3235 sc->tulip_flags &= ~TULIP_RXBUFSLOW;
3240 tulip_tx_intr(tulip_softc_t *sc)
3242 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3247 while (ri->ri_free < ri->ri_max) {
3250 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
3251 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
3256 d_flag = ri->ri_nextin->d_flag;
3257 if (d_flag & TULIP_DFLAG_TxLASTSEG) {
3258 if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
3260 * We've just finished processing a setup packet.
3261 * Mark that we finished it. If there's not
3262 * another pending, startup the TULIP receiver.
3263 * Make sure we ack the RXSTOPPED so we won't get
3264 * an abormal interrupt indication.
3266 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap);
3267 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
3268 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT)
3269 sc->tulip_flags |= TULIP_HASHONLY;
3270 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
3272 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3273 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3274 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3275 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3276 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3279 const uint32_t d_status = ri->ri_nextin->d_status;
3280 IF_DEQUEUE(&sc->tulip_txq, m);
3284 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3285 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
3286 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
3287 event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
3289 (*sc->tulip_boardsw->bd_media_poll)(sc, event);
3291 * Escape from the loop before media poll has reset the TULIP!
3296 if (d_status & TULIP_DSTS_ERRSUM) {
3297 sc->tulip_if.if_oerrors++;
3298 if (d_status & TULIP_DSTS_TxEXCCOLL)
3299 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
3300 if (d_status & TULIP_DSTS_TxLATECOLL)
3301 sc->tulip_dot3stats.dot3StatsLateCollisions++;
3302 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
3303 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
3304 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
3305 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
3306 if (d_status & TULIP_DSTS_TxUNDERFLOW)
3307 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
3308 if (d_status & TULIP_DSTS_TxBABBLE)
3309 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
3311 u_int32_t collisions =
3312 (d_status & TULIP_DSTS_TxCOLLMASK)
3313 >> TULIP_DSTS_V_TxCOLLCNT;
3314 sc->tulip_if.if_collisions += collisions;
3315 if (collisions == 1)
3316 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
3317 else if (collisions > 1)
3318 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
3319 else if (d_status & TULIP_DSTS_TxDEFERRED)
3320 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
3322 * SQE is only valid for 10baseT/BNC/AUI when not
3323 * running in full-duplex. In order to speed up the
3324 * test, the corresponding bit in tulip_flags needs to
3325 * set as well to get us to count SQE Test Errors.
3327 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
3328 sc->tulip_dot3stats.dot3StatsSQETestErrors++;
3334 if (++ri->ri_nextin == ri->ri_last)
3335 ri->ri_nextin = ri->ri_first;
3337 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3338 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
3341 * If nothing left to transmit, disable the timer.
3342 * Else if progress, reset the timer back to 2 ticks.
3344 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
3345 sc->tulip_txtimer = 0;
3347 sc->tulip_txtimer = TULIP_TXTIMER;
3348 sc->tulip_if.if_opackets += xmits;
3353 tulip_print_abnormal_interrupt(tulip_softc_t *sc, uint32_t csr)
3355 const char * const *msgp = tulip_status_bits;
3358 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
3360 csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1;
3361 printf("%s%d: abnormal interrupt:", sc->tulip_name, sc->tulip_unit);
3362 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
3363 if ((csr & mask) && *msgp != NULL) {
3364 printf("%s%s", sep, *msgp);
3365 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
3366 sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
3367 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
3368 printf(" (switching to store-and-forward mode)");
3370 printf(" (raising TX threshold to %s)",
3371 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
3381 tulip_intr_handler(tulip_softc_t *sc, int *progress_p)
3385 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3387 TULIP_CSR_WRITE(sc, csr_status, csr);
3389 if (csr & TULIP_STS_SYSERROR) {
3390 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
3391 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3392 sc->tulip_flags |= TULIP_SYSTEMERROR;
3394 printf("%s%d: system error: %s\n",
3395 sc->tulip_name, sc->tulip_unit,
3396 tulip_system_errors[sc->tulip_last_system_error]);
3398 sc->tulip_flags |= TULIP_NEEDRESET;
3399 sc->tulip_system_errors++;
3402 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
3403 if (sc->tulip_boardsw->bd_media_poll != NULL) {
3404 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
3405 ? TULIP_MEDIAPOLL_LINKFAIL
3406 : TULIP_MEDIAPOLL_LINKPASS);
3407 csr &= ~TULIP_STS_ABNRMLINTR;
3409 tulip_media_print(sc);
3411 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
3412 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
3413 if (csr & TULIP_STS_RXNOBUF)
3414 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
3416 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3417 * on receive overflows.
3419 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
3420 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3422 * Stop the receiver process and spin until it's stopped.
3423 * Tell rx_intr to drop the packets it dequeues.
3425 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
3426 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
3428 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3429 sc->tulip_flags |= TULIP_RXIGNORE;
3432 if (sc->tulip_flags & TULIP_RXIGNORE) {
3434 * Restart the receiver.
3436 sc->tulip_flags &= ~TULIP_RXIGNORE;
3437 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3440 if (csr & TULIP_STS_ABNRMLINTR) {
3441 u_int32_t tmp = csr & sc->tulip_intrmask
3442 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
3443 if (csr & TULIP_STS_TXUNDERFLOW) {
3444 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
3445 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
3446 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3447 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
3448 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
3449 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3452 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3453 sc->tulip_statusbits |= tmp;
3455 tulip_print_abnormal_interrupt(sc, tmp);
3456 sc->tulip_flags |= TULIP_NOMESSAGES;
3458 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3460 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
3462 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3463 tulip_ifstart(&sc->tulip_if);
3466 if (sc->tulip_flags & TULIP_NEEDRESET) {
3473 tulip_intr_shared(void *arg)
3475 tulip_softc_t *sc = arg;
3478 for (; sc != NULL; sc = sc->tulip_slaves) {
3479 tulip_intr_handler(sc, &progress);
3484 tulip_intr_normal(void *arg)
3486 tulip_softc_t *sc = (tulip_softc_t *)arg;
3489 tulip_intr_handler(sc, &progress);
3492 static struct mbuf *
3493 tulip_mbuf_compress(struct mbuf *m)
3496 #if MCLBYTES >= ETHERMTU + 18 && !defined(BIG_PACKET)
3497 MGETHDR(m0, MB_DONTWAIT, MT_DATA);
3499 if (m->m_pkthdr.len > MHLEN) {
3500 MCLGET(m0, MB_DONTWAIT);
3501 if ((m0->m_flags & M_EXT) == 0) {
3507 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t));
3508 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len;
3512 int len = m->m_pkthdr.len;
3513 struct mbuf **mp = &m0;
3516 if (mlen == MHLEN) {
3517 MGETHDR(*mp, MB_DONTWAIT, MT_DATA);
3519 MGET(*mp, MB_DONTWAIT, MT_DATA);
3527 MCLGET(*mp, MB_DONTWAIT);
3528 if (((*mp)->m_flags & M_EXT) == 0) {
3533 (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES;
3535 (*mp)->m_len = len <= mlen ? len : mlen;
3537 m_copydata(m, m->m_pkthdr.len - len,
3538 (*mp)->m_len, mtod((*mp), caddr_t));
3539 len -= (*mp)->m_len;
3540 mp = &(*mp)->m_next;
3548 static struct mbuf *
3549 tulip_txput(tulip_softc_t *sc, struct mbuf *m)
3551 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3552 tulip_desc_t *eop, *nextout;
3558 * Now we try to fill in our transmit descriptors. This is
3559 * a bit reminiscent of going on the Ark two by two
3560 * since each descriptor for the TULIP can describe
3561 * two buffers. So we advance through packet filling
3562 * each of the two entries at a time to to fill each
3563 * descriptor. Clear the first and last segment bits
3564 * in each descriptor (actually just clear everything
3565 * but the end-of-ring or chain bits) to make sure
3566 * we don't get messed up by previously sent packets.
3568 * We may fail to put the entire packet on the ring if
3569 * there is either not enough ring entries free or if the
3570 * packet has more than MAX_TXSEG segments. In the former
3571 * case we will just wait for the ring to empty. In the
3572 * latter case we have to recopy.
3577 eop = nextout = ri->ri_nextout;
3582 int len = m0->m_len;
3583 caddr_t addr = mtod(m0, caddr_t);
3584 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1));
3587 unsigned slen = min(len, clsize);
3591 slen = 2040, partial = 1;
3594 if (segcnt > TULIP_MAX_TXSEG) {
3596 * The packet exceeds the number of transmit buffer
3597 * entries that we can use for one packet, so we have
3598 * recopy it into one mbuf and then try again.
3600 m = tulip_mbuf_compress(m);
3608 * See if there's any unclaimed space in the
3611 if ((free += tulip_tx_intr(sc)) == 0) {
3613 * There's no more room but since nothing
3614 * has been committed at this point, just
3615 * show output is active, put back the
3618 sc->tulip_flags |= TULIP_WANTTXSTART;
3623 if (++nextout == ri->ri_last)
3624 nextout = ri->ri_first;
3625 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
3626 eop->d_status = d_status;
3627 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr);
3628 eop->d_length1 = slen;
3631 * Fill in second half of descriptor
3633 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr);
3634 eop->d_length2 = slen;
3636 d_status = TULIP_DSTS_OWNER;
3645 } while ((m0 = m0->m_next) != NULL);
3647 BPF_MTAP(&sc->tulip_if, m);
3650 * The descriptors have been filled in. Now get ready
3653 IF_ENQUEUE(&sc->tulip_txq, m);
3657 * Make sure the next descriptor after this packet is owned
3658 * by us since it may have been set up above if we ran out
3659 * of room in the ring.
3661 nextout->d_status = 0;
3662 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
3665 * If we only used the first segment of the last descriptor,
3666 * make sure the second segment will not be used.
3674 * Mark the last and first segments, indicate we want a transmit
3675 * complete interrupt, and tell it to transmit!
3677 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
3680 * Note that ri->ri_nextout is still the start of the packet
3681 * and until we set the OWNER bit, we can still back out of
3682 * everything we have done.
3684 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
3685 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
3686 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
3689 * This advances the ring for us.
3691 ri->ri_nextout = nextout;
3694 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3695 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3696 sc->tulip_if.if_flags |= IFF_OACTIVE;
3697 sc->tulip_if.if_start = tulip_ifstart;
3702 * switch back to the single queueing ifstart.
3704 sc->tulip_flags &= ~TULIP_WANTTXSTART;
3705 if (sc->tulip_txtimer == 0)
3706 sc->tulip_txtimer = TULIP_TXTIMER;
3709 * If we want a txstart, there must be not enough space in the
3710 * transmit ring. So we want to enable transmit done interrupts
3711 * so we can immediately reclaim some space. When the transmit
3712 * interrupt is posted, the interrupt handler will call tx_intr
3713 * to reclaim space and then txstart (since WANTTXSTART is set).
3714 * txstart will move the packet into the transmit ring and clear
3715 * WANTTXSTART thereby causing TXINTR to be cleared.
3718 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
3719 sc->tulip_if.if_flags |= IFF_OACTIVE;
3720 sc->tulip_if.if_start = tulip_ifstart;
3721 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
3722 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3723 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3725 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) {
3726 if (sc->tulip_intrmask & TULIP_STS_TXINTR) {
3727 sc->tulip_intrmask &= ~TULIP_STS_TXINTR;
3728 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3731 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3736 tulip_txput_setup(tulip_softc_t *sc)
3738 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3739 tulip_desc_t *nextout;
3742 * We will transmit, at most, one setup packet per call to ifstart.
3746 * Try to reclaim some free descriptors..
3748 if (ri->ri_free < 2)
3750 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
3751 sc->tulip_flags |= TULIP_WANTTXSTART;
3752 sc->tulip_if.if_start = tulip_ifstart;
3755 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
3756 sizeof(sc->tulip_setupbuf));
3758 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is
3759 * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
3761 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP;
3763 nextout = ri->ri_nextout;
3764 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
3765 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
3766 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
3767 if (sc->tulip_flags & TULIP_WANTHASHPERFECT)
3768 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
3769 else if (sc->tulip_flags & TULIP_WANTHASHONLY)
3770 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT;
3772 nextout->d_length2 = 0;
3773 nextout->d_addr2 = 0;
3774 nextout->d_length1 = sizeof(sc->tulip_setupbuf);
3775 nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
3778 * Advance the ring for the next transmit packet.
3780 if (++ri->ri_nextout == ri->ri_last)
3781 ri->ri_nextout = ri->ri_first;
3784 * Make sure the next descriptor is owned by us since it
3785 * may have been set up above if we ran out of room in the
3788 ri->ri_nextout->d_status = 0;
3789 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
3790 nextout->d_status = TULIP_DSTS_OWNER;
3792 * Flush the ownwership of the current descriptor
3794 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
3795 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3796 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
3797 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3798 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3803 tulip_ifioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred * cr)
3805 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
3806 struct ifaddr *ifa = (struct ifaddr *)data;
3807 struct ifreq *ifr = (struct ifreq *)data;
3814 ifp->if_flags |= IFF_UP;
3815 switch(ifa->ifa_addr->sa_family) {
3819 arp_ifinit(&(sc)->tulip_ac.ac_if, ifa);
3826 struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr);
3827 if (ipx_nullhost(*ina)) {
3828 ina->x_host = *(union ipx_host *)(sc->tulip_enaddr);
3830 ifp->if_flags &= ~IFF_RUNNING;
3831 bcopy((caddr_t)ina->x_host.c_host,
3832 (caddr_t)sc->tulip_enaddr,
3833 sizeof(sc->tulip_enaddr));
3842 * This magic copied from if_is.c; I don't use XNS,
3843 * so I have no way of telling if this actually
3847 struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
3848 if (ns_nullhost(*ina)) {
3849 ina->x_host = *(union ns_host *)(sc->tulip_enaddr);
3851 ifp->if_flags &= ~IFF_RUNNING;
3852 bcopy((caddr_t)ina->x_host.c_host,
3853 (caddr_t)sc->tulip_enaddr,
3854 sizeof(sc->tulip_enaddr));
3869 bcopy((caddr_t) sc->tulip_enaddr,
3870 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
3875 case SIOCSIFFLAGS: {
3876 tulip_addr_filter(sc); /* reinit multicast filter */
3882 case SIOCGIFMEDIA: {
3883 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
3888 case SIOCDELMULTI: {
3890 * Update multicast listeners
3892 tulip_addr_filter(sc); /* reset multicast filtering */
3900 * Set the interface MTU.
3902 if (ifr->ifr_mtu > ETHERMTU
3904 && sc->tulip_chipid != TULIP_21140
3905 && sc->tulip_chipid != TULIP_21140A
3906 && sc->tulip_chipid != TULIP_21041
3912 ifp->if_mtu = ifr->ifr_mtu;
3920 case SIOCGADDRROM: {
3921 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
3927 ifr->ifr_metric = (int) sc->tulip_chipid;
3942 tulip_ifstart(struct ifnet *ifp)
3944 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
3946 if (sc->tulip_if.if_flags & IFF_RUNNING) {
3948 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3949 tulip_txput_setup(sc);
3951 while (sc->tulip_if.if_snd.ifq_head != NULL) {
3953 IF_DEQUEUE(&sc->tulip_if.if_snd, m);
3954 if ((m = tulip_txput(sc, m)) != NULL) {
3955 IF_PREPEND(&sc->tulip_if.if_snd, m);
3963 tulip_ifwatchdog(struct ifnet *ifp)
3965 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
3967 sc->tulip_if.if_timer = 1;
3969 * These should be rare so do a bulk test up front so we can just skip
3972 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) {
3974 * If the number of receive buffer is low, try to refill
3976 if (sc->tulip_flags & TULIP_RXBUFSLOW)
3979 if (sc->tulip_flags & TULIP_SYSTEMERROR) {
3980 printf("%s%d: %d system errors: last was %s\n",
3981 sc->tulip_name, sc->tulip_unit, sc->tulip_system_errors,
3982 tulip_system_errors[sc->tulip_last_system_error]);
3984 if (sc->tulip_statusbits) {
3985 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
3986 sc->tulip_statusbits = 0;
3989 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR);
3992 if (sc->tulip_txtimer)
3994 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
3995 printf("%s%d: transmission timeout\n", sc->tulip_name, sc->tulip_unit);
3996 if (TULIP_DO_AUTOSENSE(sc)) {
3997 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
3998 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
3999 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP);
4007 tulip_attach(tulip_softc_t *sc)
4009 struct ifnet *ifp = &sc->tulip_if;
4011 callout_init(&sc->tulip_timer);
4012 callout_init(&sc->tulip_fast_timer);
4014 if_initname(ifp, sc->tulip_name, sc->tulip_unit);
4015 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
4016 ifp->if_ioctl = tulip_ifioctl;
4017 ifp->if_start = tulip_ifstart;
4018 ifp->if_watchdog = tulip_ifwatchdog;
4021 printf("%s%d: %s%s pass %d.%d%s\n",
4022 sc->tulip_name, sc->tulip_unit,
4024 tulip_chipdescs[sc->tulip_chipid],
4025 (sc->tulip_revinfo & 0xF0) >> 4,
4026 sc->tulip_revinfo & 0x0F,
4027 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM))
4028 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "");
4030 (*sc->tulip_boardsw->bd_media_probe)(sc);
4031 ifmedia_init(&sc->tulip_ifmedia, 0,
4032 tulip_ifmedia_change,
4033 tulip_ifmedia_status);
4034 sc->tulip_flags &= ~TULIP_DEVICEPROBE;
4035 tulip_ifmedia_add(sc);
4039 ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr);
4040 ifp->if_snd.ifq_maxlen = ifqmaxlen;
4044 tulip_initcsrs(tulip_softc_t *sc, tulip_csrptr_t csr_base, size_t csr_size)
4046 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
4047 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
4048 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
4049 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
4050 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
4051 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
4052 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
4053 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
4054 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size;
4055 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size;
4056 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size;
4057 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size;
4058 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size;
4059 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size;
4060 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
4061 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
4065 tulip_initring(tulip_softc_t *sc, tulip_ringinfo_t *ri, tulip_desc_t *descs,
4068 ri->ri_max = ndescs;
4069 ri->ri_first = descs;
4070 ri->ri_last = ri->ri_first + ri->ri_max;
4071 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
4072 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
4076 * This is the PCI configuration support.
4079 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
4080 #define PCI_CBMA 0x14 /* Configuration Base Memory Address */
4081 #define PCI_CFDA 0x40 /* Configuration Driver Area */
4084 tulip_pci_probe(device_t dev)
4086 const char *name = NULL;
4088 if (pci_get_vendor(dev) != DEC_VENDORID)
4092 * Some LanMedia WAN cards use the Tulip chip, but they have
4093 * their own driver, and we should not recognize them
4095 if (pci_get_subvendor(dev) == 0x1376)
4098 switch (pci_get_device(dev)) {
4100 name = "Digital 21040 Ethernet";
4103 name = "Digital 21041 Ethernet";
4106 if (pci_get_revid(dev) >= 0x20)
4107 name = "Digital 21140A Fast Ethernet";
4109 name = "Digital 21140 Fast Ethernet";
4112 if (pci_get_revid(dev) >= 0x20)
4113 name = "Digital 21143 Fast Ethernet";
4115 name = "Digital 21142 Fast Ethernet";
4119 device_set_desc(dev, name);
4126 tulip_shutdown(device_t dev)
4128 tulip_softc_t *sc = device_get_softc(dev);
4129 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4130 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
4131 33MHz that comes to two microseconds but wait a
4132 bit longer anyways) */
4137 tulip_pci_attach(device_t dev)
4141 uint32_t revinfo, cfdainfo, cfcsinfo;
4142 u_int csroffset = TULIP_PCI_CSROFFSET;
4143 u_int csrsize = TULIP_PCI_CSRSIZE;
4144 tulip_csrptr_t csr_base;
4145 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
4146 struct resource *res;
4149 unit = device_get_unit(dev);
4151 if (unit >= TULIP_MAX_DEVICES) {
4152 printf("de%d", unit);
4153 printf(": not configured; limit of %d reached or exceeded\n",
4158 revinfo = pci_get_revid(dev);
4159 cfdainfo = pci_read_config(dev, PCI_CFDA, 4);
4160 cfcsinfo = pci_read_config(dev, PCIR_COMMAND, 4);
4162 /* turn busmaster on in case BIOS doesn't set it */
4163 pci_enable_busmaster(dev);
4165 if (pci_get_vendor(dev) == DEC_VENDORID) {
4166 if (pci_get_device(dev) == CHIPID_21040)
4167 chipid = TULIP_21040;
4168 else if (pci_get_device(dev) == CHIPID_21041)
4169 chipid = TULIP_21041;
4170 else if (pci_get_device(dev) == CHIPID_21140)
4171 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140;
4172 else if (pci_get_device(dev) == CHIPID_21142)
4173 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142;
4175 if (chipid == TULIP_CHIPID_UNKNOWN)
4178 if (chipid == TULIP_21040 && revinfo < 0x20) {
4179 printf("de%d", unit);
4180 printf(": not configured; 21040 pass 2.0 required (%d.%d found)\n",
4181 revinfo >> 4, revinfo & 0x0f);
4183 } else if (chipid == TULIP_21140 && revinfo < 0x11) {
4184 printf("de%d: not configured; 21140 pass 1.1 required (%d.%d found)\n",
4185 unit, revinfo >> 4, revinfo & 0x0f);
4189 sc = device_get_softc(dev);
4190 sc->tulip_pci_busno = pci_get_bus(dev);
4191 sc->tulip_pci_devno = pci_get_slot(dev);
4192 sc->tulip_chipid = chipid;
4193 sc->tulip_flags |= TULIP_DEVICEPROBE;
4194 if (chipid == TULIP_21140 || chipid == TULIP_21140A)
4195 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD;
4196 if (chipid == TULIP_21140A && revinfo <= 0x22)
4197 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW;
4198 if (chipid == TULIP_21140)
4199 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH;
4200 if (chipid != TULIP_21040 && chipid != TULIP_21140)
4201 sc->tulip_features |= TULIP_HAVE_POWERMGMT;
4202 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) {
4203 sc->tulip_features |= TULIP_HAVE_DUALSENSE;
4204 if (chipid != TULIP_21041 || revinfo >= 0x20)
4205 sc->tulip_features |= TULIP_HAVE_SIANWAY;
4206 if (chipid != TULIP_21041)
4207 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD;
4208 if (chipid != TULIP_21041 && revinfo >= 0x20)
4209 sc->tulip_features |= TULIP_HAVE_SIA100;
4212 if (sc->tulip_features & TULIP_HAVE_POWERMGMT
4213 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) {
4214 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE);
4215 pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
4218 sc->tulip_unit = unit;
4219 sc->tulip_name = "de";
4220 sc->tulip_revinfo = revinfo;
4221 sc->tulip_if.if_softc = sc;
4222 #if defined(TULIP_IOMAPPED)
4224 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
4225 0, ~0, 1, RF_ACTIVE);
4228 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
4229 0, ~0, 1, RF_ACTIVE);
4233 sc->tulip_csrs_bst = rman_get_bustag(res);
4234 sc->tulip_csrs_bsh = rman_get_bushandle(res);
4239 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
4241 sc->tulip_rxdescs = malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS,
4242 M_DEVBUF, M_INTWAIT);
4243 sc->tulip_txdescs = malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS,
4244 M_DEVBUF, M_INTWAIT);
4246 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS);
4247 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS);
4250 * Make sure there won't be any interrupts or such...
4252 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4253 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
4254 33MHz that comes to two microseconds but wait a
4255 bit longer anyways) */
4257 if ((retval = tulip_read_macaddr(sc)) < 0) {
4258 printf("%s%d", sc->tulip_name, sc->tulip_unit);
4259 printf(": can't read ENET ROM (why=%d) (", retval);
4260 for (idx = 0; idx < 32; idx++)
4261 printf("%02x", sc->tulip_rombuf[idx]);
4263 printf("%s%d: %s%s pass %d.%d\n",
4264 sc->tulip_name, sc->tulip_unit,
4265 sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
4266 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
4267 printf("%s%d: address unknown\n", sc->tulip_name, sc->tulip_unit);
4270 void (*intr_rtn)(void *) = tulip_intr_normal;
4272 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
4273 intr_rtn = tulip_intr_shared;
4275 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) {
4279 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
4280 0, ~0, 1, RF_SHAREABLE | RF_ACTIVE);
4281 if (res == 0 || bus_setup_intr(dev, res, INTR_TYPE_NET,
4282 intr_rtn, sc, &ih)) {
4283 printf("%s%d: couldn't map interrupt\n",
4284 sc->tulip_name, sc->tulip_unit);
4285 free((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
4286 free((caddr_t) sc->tulip_txdescs, M_DEVBUF);
4298 static device_method_t tulip_pci_methods[] = {
4299 /* Device interface */
4300 DEVMETHOD(device_probe, tulip_pci_probe),
4301 DEVMETHOD(device_attach, tulip_pci_attach),
4302 DEVMETHOD(device_shutdown, tulip_shutdown),
4305 static driver_t tulip_pci_driver = {
4308 sizeof(tulip_softc_t),
4310 static devclass_t tulip_devclass;
4312 DECLARE_DUMMY_MODULE(if_de);
4313 DRIVER_MODULE(if_de, pci, tulip_pci_driver, tulip_devclass, 0, 0);