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.34 2005/05/12 01:41:07 drhodus 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 if_printf(&sc->tulip_if, "enabling %s port\n",
341 tulip_mediums[sc->tulip_media]);
342 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
343 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
344 if_printf(&sc->tulip_if, "link up\n");
345 sc->tulip_flags &= ~TULIP_PRINTLINKUP;
349 #if defined(TULIP_DO_GPR_SENSE)
351 tulip_21140_gpr_media_sense(tulip_softc_t *sc)
353 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
354 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
358 * If one of the media blocks contained a default media flag,
361 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
362 const tulip_media_info_t *mi;
364 * Media is not supported (or is full-duplex).
366 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media))
368 if (mi->mi_type != TULIP_MEDIAINFO_GPR)
372 * Remember the media is this is the "default" media.
374 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
378 * No activity mask? Can't see if it is active if there's no mask.
380 if (mi->mi_actmask == 0)
384 * Does the activity data match?
386 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
390 * It does! If this is the first media we detected, then
391 * remember this media. If isn't the first, then there were
392 * multiple matches which we equate to no match (since we don't
393 * which to select (if any).
395 if (last_media == TULIP_MEDIA_UNKNOWN) {
397 } else if (last_media != media) {
398 last_media = TULIP_MEDIA_UNKNOWN;
401 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
403 #endif /* TULIP_DO_GPR_SENSE */
405 static tulip_link_status_t
406 tulip_media_link_monitor(tulip_softc_t *sc)
408 const tulip_media_info_t *mi = sc->tulip_mediums[sc->tulip_media];
409 tulip_link_status_t linkup = TULIP_LINK_DOWN;
412 #if defined(DIAGNOSTIC)
413 panic("tulip_media_link_monitor: %s: botch at line %d\n",
414 tulip_mediums[sc->tulip_media],__LINE__);
416 return TULIP_LINK_UNKNOWN;
421 * Have we seen some packets? If so, the link must be good.
423 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) {
424 sc->tulip_flags &= ~TULIP_RXACT;
425 sc->tulip_probe_timeout = 3000;
426 return TULIP_LINK_UP;
429 sc->tulip_flags &= ~TULIP_RXACT;
430 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
433 * Read the PHY status register.
435 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
436 if (status & PHYSTS_AUTONEG_DONE) {
438 * If the PHY has completed autonegotiation, see the if the
439 * remote systems abilities have changed. If so, upgrade or
440 * downgrade as appropriate.
442 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
443 abilities = (abilities << 6) & status;
444 if (abilities != sc->tulip_abilities) {
445 if (tulip_mii_map_abilities(sc, abilities)) {
446 tulip_linkup(sc, sc->tulip_probe_media);
447 return TULIP_LINK_UP;
450 * if we had selected media because of autonegotiation,
451 * we need to probe for the new media.
453 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
454 if (sc->tulip_flags & TULIP_DIDNWAY)
455 return TULIP_LINK_DOWN;
459 * The link is now up. If was down, say its back up.
461 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP)
462 linkup = TULIP_LINK_UP;
463 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
465 * No activity sensor? Assume all's well.
467 if (mi->mi_actmask == 0)
468 return TULIP_LINK_UNKNOWN;
470 * Does the activity data match?
472 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata)
473 linkup = TULIP_LINK_UP;
474 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
476 * Assume non TP ok for now.
478 if (!TULIP_IS_MEDIA_TP(sc->tulip_media))
479 return TULIP_LINK_UNKNOWN;
480 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
481 linkup = TULIP_LINK_UP;
482 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
483 return TULIP_LINK_UNKNOWN;
486 * We will wait for 3 seconds until the link goes into suspect mode.
488 if (sc->tulip_flags & TULIP_LINKUP) {
489 if (linkup == TULIP_LINK_UP)
490 sc->tulip_probe_timeout = 3000;
491 if (sc->tulip_probe_timeout > 0)
492 return TULIP_LINK_UP;
494 sc->tulip_flags &= ~TULIP_LINKUP;
495 if_printf(&sc->tulip_if, "link down: cable problem?\n");
497 return TULIP_LINK_DOWN;
501 tulip_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
503 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
504 && event == TULIP_MEDIAPOLL_TIMER) {
505 switch (tulip_media_link_monitor(sc)) {
506 case TULIP_LINK_DOWN: {
508 * Link Monitor failed. Probe for new media.
510 event = TULIP_MEDIAPOLL_LINKFAIL;
513 case TULIP_LINK_UP: {
520 case TULIP_LINK_UNKNOWN: {
522 * We can't tell so don't bother.
529 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
530 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
531 if (TULIP_DO_AUTOSENSE(sc)) {
532 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
533 if (sc->tulip_if.if_flags & IFF_UP)
534 tulip_reset(sc); /* restart probe */
540 if (event == TULIP_MEDIAPOLL_START) {
541 sc->tulip_if.if_flags |= IFF_OACTIVE;
542 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
544 sc->tulip_probe_mediamask = 0;
545 sc->tulip_probe_passes = 0;
547 * If the SROM contained an explicit media to use, use it.
549 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX);
550 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS;
551 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
553 * connidx is defaulted to a media_unknown type.
555 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media;
556 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) {
557 tulip_linkup(sc, sc->tulip_probe_media);
562 if (sc->tulip_features & TULIP_HAVE_GPR) {
563 sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
564 sc->tulip_probe_timeout = 2000;
566 sc->tulip_probe_media = TULIP_MEDIA_MAX;
567 sc->tulip_probe_timeout = 0;
568 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
573 * Ignore txprobe failures or spurious callbacks.
575 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED
576 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) {
577 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
582 * If we really transmitted a packet, then that's the media we'll use.
584 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) {
585 if (event == TULIP_MEDIAPOLL_LINKPASS) {
586 /* XXX Check media status just to be sure */
587 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
589 tulip_linkup(sc, sc->tulip_probe_media);
594 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) {
595 #if defined(TULIP_DO_GPR_SENSE)
597 * Check for media via the general purpose register.
599 * Try to sense the media via the GPR. If the same value
600 * occurs 3 times in a row then just use that.
602 if (sc->tulip_probe_timeout > 0) {
603 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
604 if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
605 if (new_probe_media == sc->tulip_probe_media) {
606 if (--sc->tulip_probe_count == 0)
607 tulip_linkup(sc, sc->tulip_probe_media);
609 sc->tulip_probe_count = 10;
612 sc->tulip_probe_media = new_probe_media;
616 #endif /* TULIP_DO_GPR_SENSE */
618 * Brute force. We cycle through each of the media types
619 * and try to transmit a packet.
621 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
622 sc->tulip_probe_media = TULIP_MEDIA_MAX;
623 sc->tulip_probe_timeout = 0;
628 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST
629 && (sc->tulip_features & TULIP_HAVE_MII)) {
630 tulip_media_t old_media = sc->tulip_probe_media;
631 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
632 switch (sc->tulip_probe_state) {
633 case TULIP_PROBE_FAILED:
634 case TULIP_PROBE_MEDIATEST: {
636 * Try the next media.
638 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask;
639 sc->tulip_probe_timeout = 0;
641 if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
643 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
645 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
649 case TULIP_PROBE_PHYAUTONEG: {
652 case TULIP_PROBE_INACTIVE: {
654 * Only probe if we autonegotiated a media that hasn't failed.
656 sc->tulip_probe_timeout = 0;
657 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) {
658 sc->tulip_probe_media = old_media;
661 tulip_linkup(sc, sc->tulip_probe_media);
666 #if defined(DIAGNOSTIC)
667 panic("tulip_media_poll: botch at line %d\n", __LINE__);
674 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
675 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
680 * switch to another media if we tried this one enough.
682 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
684 * Find the next media type to check for. Full Duplex
685 * types are not allowed.
688 sc->tulip_probe_media -= 1;
689 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
690 if (++sc->tulip_probe_passes == 3) {
691 if_printf(&sc->tulip_if, "autosense failed: cable problem?\n");
692 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
693 sc->tulip_if.if_flags &= ~IFF_RUNNING;
694 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
698 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */
699 sc->tulip_probe_mediamask = 0;
700 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1;
702 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL
703 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
704 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
706 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
707 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
708 sc->tulip_probe.probe_txprobes = 0;
710 tulip_media_set(sc, sc->tulip_probe_media);
711 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
716 * If this is hanging off a phy, we know are doing NWAY and we have
717 * forced the phy to a specific speed. Wait for link up before
718 * before sending a packet.
720 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) {
721 case TULIP_MEDIAINFO_MII: {
722 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
726 case TULIP_MEDIAINFO_SIA: {
727 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) {
728 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL)
730 tulip_linkup(sc, sc->tulip_probe_media);
732 if (sc->tulip_features & TULIP_HAVE_MII)
739 case TULIP_MEDIAINFO_RESET:
740 case TULIP_MEDIAINFO_SYM:
741 case TULIP_MEDIAINFO_NONE:
742 case TULIP_MEDIAINFO_GPR: {
747 * Try to send a packet.
753 tulip_media_select(tulip_softc_t *sc)
755 if (sc->tulip_features & TULIP_HAVE_GPR) {
756 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
758 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata);
761 * If this board has no media, just return
763 if (sc->tulip_features & TULIP_HAVE_NOMEDIA)
766 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
767 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
768 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START);
770 tulip_media_set(sc, sc->tulip_media);
775 tulip_21040_mediainfo_init(tulip_softc_t *sc, tulip_media_t media)
777 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
778 |TULIP_CMD_BACKOFFCTR;
779 sc->tulip_if.if_baudrate = 10000000;
781 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) {
782 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET);
783 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD);
784 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
787 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) {
788 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC);
791 if (media == TULIP_MEDIA_UNKNOWN) {
792 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA);
797 tulip_21040_media_probe(tulip_softc_t *sc)
799 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
803 tulip_21040_10baset_only_media_probe(tulip_softc_t *sc)
805 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
806 tulip_media_set(sc, TULIP_MEDIA_10BASET);
807 sc->tulip_media = TULIP_MEDIA_10BASET;
811 tulip_21040_10baset_only_media_select(tulip_softc_t *sc)
813 sc->tulip_flags |= TULIP_LINKUP;
814 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
815 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
816 sc->tulip_flags &= ~TULIP_SQETEST;
818 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
819 sc->tulip_flags |= TULIP_SQETEST;
821 tulip_media_set(sc, sc->tulip_media);
825 tulip_21040_auibnc_only_media_probe(tulip_softc_t *sc)
827 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
828 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
829 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
830 sc->tulip_media = TULIP_MEDIA_AUIBNC;
834 tulip_21040_auibnc_only_media_select(tulip_softc_t *sc)
836 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
837 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
840 static const tulip_boardsw_t tulip_21040_boardsw = {
842 tulip_21040_media_probe,
847 static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = {
849 tulip_21040_10baset_only_media_probe,
850 tulip_21040_10baset_only_media_select,
854 static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = {
856 tulip_21040_auibnc_only_media_probe,
857 tulip_21040_auibnc_only_media_select,
862 tulip_21041_mediainfo_init(tulip_softc_t *sc)
864 tulip_media_info_t *mi = sc->tulip_mediainfo;
867 if (sc->tulip_revinfo >= 0x20) {
868 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET);
869 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD);
870 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI);
871 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC);
875 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET);
876 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD);
877 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
878 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
882 tulip_21041_media_probe(tulip_softc_t *sc)
884 sc->tulip_if.if_baudrate = 10000000;
885 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
886 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
887 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
888 tulip_21041_mediainfo_init(sc);
892 tulip_21041_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
896 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
897 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
898 || !TULIP_DO_AUTOSENSE(sc))
900 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
901 tulip_reset(sc); /* start probe */
906 * If we've been been asked to start a poll or link change interrupt
907 * restart the probe (and reset the tulip to a known state).
909 if (event == TULIP_MEDIAPOLL_START) {
910 sc->tulip_if.if_flags |= IFF_OACTIVE;
911 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN);
913 if (sc->tulip_revinfo >= 0x20) {
914 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
915 sc->tulip_flags |= TULIP_DIDNWAY;
918 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
919 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
920 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
921 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT;
922 tulip_media_set(sc, TULIP_MEDIA_10BASET);
927 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
930 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
931 tulip_linkup(sc, sc->tulip_probe_media);
935 sia_status = TULIP_CSR_READ(sc, csr_sia_status);
936 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status);
937 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) {
938 if (sc->tulip_revinfo >= 0x20) {
939 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6)))
940 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
943 * If the link has passed LinkPass, 10baseT is the
944 * proper media to use.
946 tulip_linkup(sc, sc->tulip_probe_media);
951 * wait for up to 2.4 seconds for the link to reach pass state.
952 * Only then start scanning the other media for activity.
953 * choose media with receive activity over those without.
955 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) {
956 if (event != TULIP_MEDIAPOLL_TIMER)
958 if (sc->tulip_probe_timeout > 0
959 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
963 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
964 sc->tulip_flags |= TULIP_WANTRXACT;
965 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) {
966 sc->tulip_probe_media = TULIP_MEDIA_BNC;
968 sc->tulip_probe_media = TULIP_MEDIA_AUI;
970 tulip_media_set(sc, sc->tulip_probe_media);
976 * If we failed, clear the txprobe active flag.
978 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED)
979 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
982 if (event == TULIP_MEDIAPOLL_TIMER) {
984 * If we've received something, then that's our link!
986 if (sc->tulip_flags & TULIP_RXACT) {
987 tulip_linkup(sc, sc->tulip_probe_media);
991 * if no txprobe active
993 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0
994 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0
995 || (sia_status & TULIP_SIASTS_RXACTIVITY))) {
996 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1002 * Take 2 passes through before deciding to not
1003 * wait for receive activity. Then take another
1004 * two passes before spitting out a warning.
1006 if (sc->tulip_probe_timeout <= 0) {
1007 if (sc->tulip_flags & TULIP_WANTRXACT) {
1008 sc->tulip_flags &= ~TULIP_WANTRXACT;
1009 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1011 if_printf(&sc->tulip_if, "autosense failed: cable problem?\n");
1012 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
1013 sc->tulip_if.if_flags &= ~IFF_RUNNING;
1014 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1022 * Since this media failed to probe, try the other one.
1024 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1025 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) {
1026 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1028 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1030 tulip_media_set(sc, sc->tulip_probe_media);
1031 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1035 static const tulip_boardsw_t tulip_21041_boardsw = {
1036 TULIP_21041_GENERIC,
1037 tulip_21041_media_probe,
1039 tulip_21041_media_poll
1042 static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
1043 { 0x20005c00, 0, /* 08-00-17 */
1045 { 0x19, 0x0040, 0x0040 }, /* 10TX */
1046 { 0x19, 0x0040, 0x0000 }, /* 100TX */
1049 { 0x0281F400, 0, /* 00-A0-7D */
1051 { 0x12, 0x0010, 0x0000 }, /* 10T */
1053 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1054 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1058 { 0x0015F420, 0, /* 00-A0-7D */
1060 { 0x12, 0x0010, 0x0000 }, /* 10T */
1062 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1063 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1067 { 0x0281F400, 0, /* 00-A0-BE */
1069 { 0x11, 0x8000, 0x0000 }, /* 10T */
1070 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1072 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1078 static tulip_media_t
1079 tulip_mii_phy_readspecific(tulip_softc_t *sc)
1081 const tulip_phy_attr_t *attr;
1085 static const tulip_media_t table[] = {
1086 TULIP_MEDIA_UNKNOWN,
1087 TULIP_MEDIA_10BASET,
1088 TULIP_MEDIA_100BASETX,
1089 TULIP_MEDIA_100BASET4,
1090 TULIP_MEDIA_UNKNOWN,
1091 TULIP_MEDIA_10BASET_FD,
1092 TULIP_MEDIA_100BASETX_FD,
1097 * Don't read phy specific registers if link is not up.
1099 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
1100 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS))
1101 return TULIP_MEDIA_UNKNOWN;
1103 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) |
1104 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH);
1105 for (attr = tulip_mii_phy_attrlist;; attr++) {
1106 if (attr->attr_id == 0)
1107 return TULIP_MEDIA_UNKNOWN;
1108 if ((id & ~0x0F) == attr->attr_id)
1112 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
1113 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_100TX];
1114 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1115 if ((data & pm->pm_mask) == pm->pm_value)
1118 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) {
1119 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_100T4];
1120 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1121 if ((data & pm->pm_mask) == pm->pm_value)
1124 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) {
1125 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_10T];
1126 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1127 if ((data & pm->pm_mask) == pm->pm_value)
1130 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) {
1131 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
1132 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1133 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
1139 tulip_mii_get_phyaddr(tulip_softc_t *sc, u_int offset)
1143 for (phyaddr = 1; phyaddr < 32; phyaddr++) {
1144 u_int status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1145 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1152 u_int status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
1153 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1154 return TULIP_MII_NOPHY;
1157 return TULIP_MII_NOPHY;
1161 tulip_mii_map_abilities(tulip_softc_t *sc, u_int abilities)
1163 sc->tulip_abilities = abilities;
1164 if (abilities & PHYSTS_100BASETX_FD) {
1165 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD;
1166 } else if (abilities & PHYSTS_100BASET4) {
1167 sc->tulip_probe_media = TULIP_MEDIA_100BASET4;
1168 } else if (abilities & PHYSTS_100BASETX) {
1169 sc->tulip_probe_media = TULIP_MEDIA_100BASETX;
1170 } else if (abilities & PHYSTS_10BASET_FD) {
1171 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1172 } else if (abilities & PHYSTS_10BASET) {
1173 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1175 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1178 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1183 tulip_mii_autonegotiate(tulip_softc_t *sc, u_int phyaddr)
1185 switch (sc->tulip_probe_state) {
1186 case TULIP_PROBE_MEDIATEST:
1187 case TULIP_PROBE_INACTIVE: {
1188 sc->tulip_flags |= TULIP_DIDNWAY;
1189 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET);
1190 sc->tulip_probe_timeout = 3000;
1191 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR;
1192 sc->tulip_probe_state = TULIP_PROBE_PHYRESET;
1195 case TULIP_PROBE_PHYRESET: {
1197 uint32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1198 if (data & PHYCTL_RESET) {
1199 if (sc->tulip_probe_timeout > 0) {
1203 if_printf(&sc->tulip_if,
1204 "(phy%d): error: reset of PHY never completed!\n", phyaddr);
1205 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1206 sc->tulip_probe_state = TULIP_PROBE_FAILED;
1207 sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
1210 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1211 if ((status & PHYSTS_CAN_AUTONEG) == 0) {
1212 sc->tulip_flags &= ~TULIP_DIDNWAY;
1213 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1216 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01))
1217 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
1218 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
1219 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1220 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
1221 sc->tulip_probe_timeout = 3000;
1224 case TULIP_PROBE_PHYAUTONEG: {
1225 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1227 if ((status & PHYSTS_AUTONEG_DONE) == 0) {
1228 if (sc->tulip_probe_timeout > 0) {
1232 sc->tulip_flags &= ~TULIP_DIDNWAY;
1233 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1236 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
1237 data = (data << 6) & status;
1238 if (!tulip_mii_map_abilities(sc, data))
1239 sc->tulip_flags &= ~TULIP_DIDNWAY;
1243 #if defined(DIAGNOSTIC)
1244 panic("tulip_media_poll: botch at line %d\n", __LINE__);
1252 tulip_2114x_media_preset(tulip_softc_t *sc)
1254 const tulip_media_info_t *mi = NULL;
1255 tulip_media_t media = sc->tulip_media;
1257 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1258 media = sc->tulip_media;
1260 media = sc->tulip_probe_media;
1262 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
1263 sc->tulip_flags &= ~TULIP_SQETEST;
1264 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
1265 mi = sc->tulip_mediums[media];
1266 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
1267 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1268 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR
1269 || mi->mi_type == TULIP_MEDIAINFO_SYM) {
1270 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
1271 sc->tulip_cmdmode |= mi->mi_cmdmode;
1272 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
1273 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
1277 case TULIP_MEDIA_BNC:
1278 case TULIP_MEDIA_AUI:
1279 case TULIP_MEDIA_10BASET: {
1280 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1281 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
1282 sc->tulip_if.if_baudrate = 10000000;
1283 sc->tulip_flags |= TULIP_SQETEST;
1286 case TULIP_MEDIA_10BASET_FD: {
1287 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
1288 sc->tulip_if.if_baudrate = 10000000;
1291 case TULIP_MEDIA_100BASEFX:
1292 case TULIP_MEDIA_100BASET4:
1293 case TULIP_MEDIA_100BASETX: {
1294 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL);
1295 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1296 sc->tulip_if.if_baudrate = 100000000;
1299 case TULIP_MEDIA_100BASEFX_FD:
1300 case TULIP_MEDIA_100BASETX_FD: {
1301 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT;
1302 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
1303 sc->tulip_if.if_baudrate = 100000000;
1310 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1314 ********************************************************************
1315 * Start of 21140/21140A support which does not use the MII interface
1319 tulip_null_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
1321 #if defined(DIAGNOSTIC)
1322 if_printf(&sc->tulip_if, "botch(media_poll) at line %d\n", __LINE__);
1327 tulip_21140_mediainit(tulip_softc_t *sc, tulip_media_info_t *mip,
1328 tulip_media_t media, u_int gpdata, u_int cmdmode)
1330 sc->tulip_mediums[media] = mip;
1331 mip->mi_type = TULIP_MEDIAINFO_GPR;
1332 mip->mi_cmdmode = cmdmode;
1333 mip->mi_gpdata = gpdata;
1337 tulip_21140_evalboard_media_probe(tulip_softc_t *sc)
1339 tulip_media_info_t *mip = sc->tulip_mediainfo;
1341 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1342 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1343 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1344 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1345 TULIP_CSR_WRITE(sc, csr_command,
1346 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1347 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1348 TULIP_CSR_WRITE(sc, csr_command,
1349 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1351 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
1352 sc->tulip_media = TULIP_MEDIA_10BASET;
1354 sc->tulip_media = TULIP_MEDIA_100BASETX;
1356 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1358 TULIP_CMD_TXTHRSHLDCTL);
1359 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1361 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1362 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1364 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1365 |TULIP_CMD_SCRAMBLER);
1366 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1368 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1369 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1372 static const tulip_boardsw_t tulip_21140_eb_boardsw = {
1374 tulip_21140_evalboard_media_probe,
1376 tulip_null_media_poll,
1377 tulip_2114x_media_preset,
1381 tulip_21140_accton_media_probe(tulip_softc_t *sc)
1383 tulip_media_info_t *mip = sc->tulip_mediainfo;
1386 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1387 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1388 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1389 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1390 TULIP_CSR_WRITE(sc, csr_command,
1391 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1392 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1393 TULIP_CSR_WRITE(sc, csr_command,
1394 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1396 gpdata = TULIP_CSR_READ(sc, csr_gp);
1397 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) {
1398 sc->tulip_media = TULIP_MEDIA_10BASET;
1400 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) {
1401 sc->tulip_media = TULIP_MEDIA_BNC;
1403 sc->tulip_media = TULIP_MEDIA_100BASETX;
1406 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC,
1407 TULIP_GP_EN1207_BNC_INIT,
1408 TULIP_CMD_TXTHRSHLDCTL);
1409 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1410 TULIP_GP_EN1207_UTP_INIT,
1411 TULIP_CMD_TXTHRSHLDCTL);
1412 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1413 TULIP_GP_EN1207_UTP_INIT,
1414 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1415 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1416 TULIP_GP_EN1207_100_INIT,
1417 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1418 |TULIP_CMD_SCRAMBLER);
1419 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1420 TULIP_GP_EN1207_100_INIT,
1421 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1422 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1425 static const tulip_boardsw_t tulip_21140_accton_boardsw = {
1427 tulip_21140_accton_media_probe,
1429 tulip_null_media_poll,
1430 tulip_2114x_media_preset,
1434 tulip_21140_smc9332_media_probe(tulip_softc_t *sc)
1436 tulip_media_info_t *mip = sc->tulip_mediainfo;
1439 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE);
1440 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
1441 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
1442 33MHz that comes to two microseconds but wait a
1443 bit longer anyways) */
1444 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT |
1445 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1446 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS;
1447 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT;
1448 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET);
1449 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT);
1451 for (idx = 1000; idx > 0; idx--) {
1452 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1453 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) {
1456 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
1463 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1464 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1465 TULIP_GP_SMC_9332_INIT,
1466 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1467 |TULIP_CMD_SCRAMBLER);
1468 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1469 TULIP_GP_SMC_9332_INIT,
1470 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1471 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1472 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1473 TULIP_GP_SMC_9332_INIT,
1474 TULIP_CMD_TXTHRSHLDCTL);
1475 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1476 TULIP_GP_SMC_9332_INIT,
1477 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1480 static const tulip_boardsw_t tulip_21140_smc9332_boardsw = {
1481 TULIP_21140_SMC_9332,
1482 tulip_21140_smc9332_media_probe,
1484 tulip_null_media_poll,
1485 tulip_2114x_media_preset,
1489 tulip_21140_cogent_em100_media_probe(tulip_softc_t *sc)
1491 tulip_media_info_t *mip = sc->tulip_mediainfo;
1492 uint32_t cmdmode = TULIP_CSR_READ(sc, csr_command);
1494 sc->tulip_gpinit = TULIP_GP_EM100_PINS;
1495 sc->tulip_gpdata = TULIP_GP_EM100_INIT;
1496 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS);
1497 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT);
1499 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE;
1500 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER);
1501 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1502 TULIP_CSR_WRITE(sc, csr_command, cmdmode);
1503 sc->tulip_media = TULIP_MEDIA_100BASEFX;
1505 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX,
1506 TULIP_GP_EM100_INIT,
1507 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION);
1508 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD,
1509 TULIP_GP_EM100_INIT,
1510 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1511 |TULIP_CMD_FULLDUPLEX);
1513 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);
1514 sc->tulip_media = TULIP_MEDIA_100BASETX;
1515 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1516 TULIP_GP_EM100_INIT,
1517 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1518 |TULIP_CMD_SCRAMBLER);
1519 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1520 TULIP_GP_EM100_INIT,
1521 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1522 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1526 static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {
1527 TULIP_21140_COGENT_EM100,
1528 tulip_21140_cogent_em100_media_probe,
1530 tulip_null_media_poll,
1531 tulip_2114x_media_preset
1535 tulip_21140_znyx_zx34x_media_probe(tulip_softc_t *sc)
1537 tulip_media_info_t *mip = sc->tulip_mediainfo;
1538 int cnt10 = 0, cnt100 = 0, idx;
1540 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS;
1541 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT;
1542 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS);
1543 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT);
1544 TULIP_CSR_WRITE(sc, csr_command,
1545 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1546 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1547 TULIP_CSR_WRITE(sc, csr_command,
1548 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1551 for (idx = 1000; idx > 0; idx--) {
1552 uint32_t csr = TULIP_CSR_READ(sc, csr_gp);
1553 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)) {
1556 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
1565 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1566 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1567 TULIP_GP_ZX34X_INIT,
1568 TULIP_CMD_TXTHRSHLDCTL);
1569 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1570 TULIP_GP_ZX34X_INIT,
1571 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1572 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1573 TULIP_GP_ZX34X_INIT,
1574 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1575 |TULIP_CMD_SCRAMBLER);
1576 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1577 TULIP_GP_ZX34X_INIT,
1578 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1579 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1582 static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = {
1583 TULIP_21140_ZNYX_ZX34X,
1584 tulip_21140_znyx_zx34x_media_probe,
1586 tulip_null_media_poll,
1587 tulip_2114x_media_preset,
1591 tulip_2114x_media_probe(tulip_softc_t *sc)
1593 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE | TULIP_CMD_BACKOFFCTR |
1594 TULIP_CMD_THRSHLD72;
1597 static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
1599 tulip_2114x_media_probe,
1602 tulip_2114x_media_preset,
1606 * ******** END of chip-specific handlers. ***********
1610 * Code the read the SROM and MII bit streams (I2C)
1613 TULIP_CSR_WRITE(sc, csr_srom_mii, csr); \
1618 tulip_srom_idle(tulip_softc_t *sc)
1622 csr = SROMSEL ; EMIT;
1623 csr = SROMSEL | SROMRD; EMIT;
1624 csr ^= SROMCS; EMIT;
1625 csr ^= SROMCLKON; EMIT;
1628 * Write 25 cycles of 0 which will force the SROM to be idle.
1630 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1631 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1632 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1634 csr ^= SROMCLKOFF; EMIT;
1635 csr ^= SROMCS; EMIT;
1641 tulip_srom_read(tulip_softc_t *sc)
1643 const u_int bitwidth = SROM_BITWIDTH;
1644 const u_int cmdmask = (SROMCMD_RD << bitwidth);
1645 const u_int msb = 1 << (bitwidth + 3 - 1);
1646 u_int idx, lastidx = (1 << bitwidth) - 1;
1648 tulip_srom_idle(sc);
1650 for (idx = 0; idx <= lastidx; idx++) {
1651 u_int lastbit, data, bits, bit, csr;
1652 csr = SROMSEL ; EMIT;
1653 csr = SROMSEL | SROMRD; EMIT;
1654 csr ^= SROMCSON; EMIT;
1655 csr ^= SROMCLKON; EMIT;
1658 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
1659 u_int thisbit = bits & msb;
1660 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1661 if (thisbit != lastbit) {
1662 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1666 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1669 csr ^= SROMCLKOFF; EMIT;
1671 for (data = 0, bits = 0; bits < 16; bits++) {
1673 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1674 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1675 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1677 sc->tulip_rombuf[idx*2] = data & 0xFF;
1678 sc->tulip_rombuf[idx*2+1] = data >> 8;
1679 csr = SROMSEL | SROMRD; EMIT;
1682 tulip_srom_idle(sc);
1685 #define MII_EMIT do { \
1686 TULIP_CSR_WRITE(sc, csr_srom_mii, csr); \
1691 tulip_mii_writebits(tulip_softc_t *sc, u_int data, u_int bits)
1693 u_int csr, msb, lastbit;
1695 msb = 1 << (bits - 1);
1696 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1697 lastbit = (csr & MII_DOUT) ? msb : 0;
1698 csr |= MII_WR; MII_EMIT; /* clock low; assert write */
1700 for (; bits > 0; bits--, data <<= 1) {
1701 const unsigned thisbit = data & msb;
1702 if (thisbit != lastbit) {
1703 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */
1705 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1707 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1712 tulip_mii_turnaround(tulip_softc_t *sc, u_int cmd)
1716 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1718 if (cmd == MII_WRCMD) {
1719 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
1720 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1721 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1722 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */
1724 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */
1726 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1727 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1731 tulip_mii_readbits(tulip_softc_t *sc)
1733 u_int csr, data, idx;
1735 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1737 for (idx = 0, data = 0; idx < 16; idx++) {
1738 data <<= 1; /* this is NOOP on the first pass through */
1739 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1740 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)
1742 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1744 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
1750 tulip_mii_readreg(tulip_softc_t *sc, u_int devaddr, u_int regno)
1755 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1756 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1757 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1758 tulip_mii_writebits(sc, MII_RDCMD, 8);
1759 tulip_mii_writebits(sc, devaddr, 5);
1760 tulip_mii_writebits(sc, regno, 5);
1761 tulip_mii_turnaround(sc, MII_RDCMD);
1763 data = tulip_mii_readbits(sc);
1768 tulip_mii_writereg(tulip_softc_t *sc, u_int devaddr, u_int regno, u_int data)
1772 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1773 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1774 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1775 tulip_mii_writebits(sc, MII_WRCMD, 8);
1776 tulip_mii_writebits(sc, devaddr, 5);
1777 tulip_mii_writebits(sc, regno, 5);
1778 tulip_mii_turnaround(sc, MII_WRCMD);
1779 tulip_mii_writebits(sc, data, 16);
1782 #define tulip_mchash(mca) (ether_crc32_le(mca, 6) & 0x1FF)
1783 #define tulip_srom_crcok(databuf) ( \
1784 ((ether_crc32_le(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
1785 ((databuf)[126] | ((databuf)[127] << 8)))
1788 tulip_identify_dec_nic(tulip_softc_t *sc)
1790 strcpy(sc->tulip_boardid, "DEC ");
1792 if (sc->tulip_chipid <= TULIP_21040)
1794 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0
1795 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {
1796 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);
1797 sc->tulip_boardid[D0+8] = ' ';
1803 tulip_identify_znyx_nic(tulip_softc_t * const sc)
1806 strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
1807 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
1809 sc->tulip_boardid[8] = '4';
1810 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
1811 if (znyx_ptr < 26 || znyx_ptr > 116) {
1812 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1815 /* ZX344 = 0010 .. 0013FF
1817 if (sc->tulip_rombuf[znyx_ptr] == 0x4A
1818 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52
1819 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) {
1820 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4];
1821 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) {
1822 sc->tulip_boardid[9] = '2';
1823 if (id == TULIP_ZNYX_ID_ZX342B) {
1824 sc->tulip_boardid[10] = 'B';
1825 sc->tulip_boardid[11] = ' ';
1827 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1828 } else if (id == TULIP_ZNYX_ID_ZX344) {
1829 sc->tulip_boardid[10] = '4';
1830 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1831 } else if (id == TULIP_ZNYX_ID_ZX345) {
1832 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5';
1833 } else if (id == TULIP_ZNYX_ID_ZX346) {
1834 sc->tulip_boardid[9] = '6';
1835 } else if (id == TULIP_ZNYX_ID_ZX351) {
1836 sc->tulip_boardid[8] = '5';
1837 sc->tulip_boardid[9] = '1';
1842 * Assume it's a ZX342...
1844 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1848 sc->tulip_boardid[8] = '1';
1849 if (sc->tulip_chipid == TULIP_21041) {
1850 sc->tulip_boardid[10] = '1';
1853 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) {
1854 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36];
1855 if (id == TULIP_ZNYX_ID_ZX312T) {
1856 sc->tulip_boardid[9] = '2';
1857 sc->tulip_boardid[10] = 'T';
1858 sc->tulip_boardid[11] = ' ';
1859 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1860 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) {
1861 sc->tulip_boardid[9] = '4';
1862 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1863 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1864 } else if (id == TULIP_ZNYX_ID_ZX314) {
1865 sc->tulip_boardid[9] = '4';
1866 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1867 sc->tulip_features |= TULIP_HAVE_BASEROM;
1868 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) {
1869 sc->tulip_boardid[9] = '5';
1870 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1871 } else if (id == TULIP_ZNYX_ID_ZX315) {
1872 sc->tulip_boardid[9] = '5';
1873 sc->tulip_features |= TULIP_HAVE_BASEROM;
1879 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) {
1880 sc->tulip_boardid[9] = '4';
1881 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1882 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1883 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) {
1884 sc->tulip_boardid[9] = '5';
1885 sc->tulip_boardsw = &tulip_21040_boardsw;
1886 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1887 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) {
1888 sc->tulip_boardid[9] = '2';
1889 sc->tulip_boardsw = &tulip_21040_boardsw;
1895 tulip_identify_smc_nic(tulip_softc_t * const sc)
1897 uint32_t id1, id2, ei;
1898 int auibnc = 0, utp = 0;
1901 strcpy(sc->tulip_boardid, "SMC ");
1902 if (sc->tulip_chipid == TULIP_21041)
1904 if (sc->tulip_chipid != TULIP_21040) {
1905 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
1906 strcpy(&sc->tulip_boardid[4], "9332DST ");
1907 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;
1908 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {
1909 strcpy(&sc->tulip_boardid[4], "9334BDT ");
1911 strcpy(&sc->tulip_boardid[4], "9332BDT ");
1915 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);
1916 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);
1917 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);
1919 strcpy(&sc->tulip_boardid[4], "8432");
1920 cp = &sc->tulip_boardid[8];
1922 *cp++ = 'B', auibnc = 1;
1923 if ((id1 & 0xFF) > 0x32)
1924 *cp++ = 'T', utp = 1;
1925 if ((id1 & 0x4000) == 0)
1926 *cp++ = 'A', auibnc = 1;
1928 sc->tulip_boardid[7] = '4';
1932 *cp++ = (ei ? '2' : '1');
1937 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1938 else if (!utp && auibnc)
1939 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
1943 tulip_identify_cogent_nic(tulip_softc_t * const sc)
1945 strcpy(sc->tulip_boardid, "Cogent ");
1946 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
1947 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {
1948 strcat(sc->tulip_boardid, "EM100TX ");
1949 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1950 #if defined(TULIP_COGENT_EM110TX_ID)
1951 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {
1952 strcat(sc->tulip_boardid, "EM110TX ");
1953 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1955 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1956 strcat(sc->tulip_boardid, "EM100FX ");
1957 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1960 * Magic number (0x24001109U) is the SubVendor (0x2400) and
1961 * SubDevId (0x1109) for the ANA6944TX (EM440TX).
1963 if (*(uint32_t *) sc->tulip_rombuf == 0x24001109U
1964 && (sc->tulip_features & TULIP_HAVE_BASEROM)) {
1966 * Cogent (Adaptec) is still mapping all INTs to INTA of
1967 * first 21140. Dumb! Dumb!
1969 strcat(sc->tulip_boardid, "EM440TX ");
1970 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
1972 } else if (sc->tulip_chipid == TULIP_21040) {
1973 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1978 tulip_identify_accton_nic(tulip_softc_t * const sc)
1980 strcpy(sc->tulip_boardid, "ACCTON ");
1981 switch (sc->tulip_chipid) {
1983 strcat(sc->tulip_boardid, "EN1207 ");
1984 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
1985 sc->tulip_boardsw = &tulip_21140_accton_boardsw;
1988 strcat(sc->tulip_boardid, "EN1207TX ");
1989 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
1990 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
1993 strcat(sc->tulip_boardid, "EN1203 ");
1994 sc->tulip_boardsw = &tulip_21040_boardsw;
1997 strcat(sc->tulip_boardid, "EN1203 ");
1998 sc->tulip_boardsw = &tulip_21041_boardsw;
2001 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2007 tulip_identify_asante_nic(tulip_softc_t * const sc)
2009 strcpy(sc->tulip_boardid, "Asante ");
2010 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
2011 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2012 tulip_media_info_t *mi = sc->tulip_mediainfo;
2015 * The Asante Fast Ethernet doesn't always ship with a valid
2016 * new format SROM. So if isn't in the new format, we cheat
2017 * set it up as if we had.
2020 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;
2021 sc->tulip_gpdata = 0;
2023 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);
2024 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);
2026 TULIP_CSR_WRITE(sc, csr_gp, 0);
2028 mi->mi_type = TULIP_MEDIAINFO_MII;
2029 mi->mi_gpr_length = 0;
2030 mi->mi_gpr_offset = 0;
2031 mi->mi_reset_length = 0;
2032 mi->mi_reset_offset = 0;;
2034 mi->mi_phyaddr = TULIP_MII_NOPHY;
2035 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) {
2037 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
2039 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2040 if_printf(&sc->tulip_if, "can't find phy 0\n");
2044 sc->tulip_features |= TULIP_HAVE_MII;
2045 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2046 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2047 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD;
2048 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD;
2049 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2050 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2051 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2052 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2053 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2054 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2055 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2057 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2062 tulip_identify_compex_nic(tulip_softc_t *sc)
2064 strcpy(sc->tulip_boardid, "COMPEX ");
2065 if (sc->tulip_chipid == TULIP_21140A) {
2067 tulip_softc_t *root_sc = NULL;
2069 strcat(sc->tulip_boardid, "400TX/PCI ");
2071 * All 4 chips on these boards share an interrupt. This code
2072 * copied from tulip_read_macaddr.
2074 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2075 for (root_unit = device_get_unit(sc->tulip_dev) - 1; root_unit >= 0; root_unit--) {
2076 root_sc = tulips[root_unit];
2078 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
2083 && root_sc->tulip_chipid == sc->tulip_chipid
2084 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2085 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2086 sc->tulip_slaves = root_sc->tulip_slaves;
2087 root_sc->tulip_slaves = sc;
2088 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
2089 if_printf(&sc->tulip_if, "can't find master device for interrupts");
2092 strcat(sc->tulip_boardid, "unknown ");
2094 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */
2099 tulip_srom_decode(tulip_softc_t *sc)
2101 u_int idx1, idx2, idx3;
2103 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
2104 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
2105 tulip_srom_media_t srom_media;
2106 tulip_media_info_t *mi = sc->tulip_mediainfo;
2108 uint32_t leaf_offset, blocks, data;
2110 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
2111 if (shp->sh_adapter_count == 1)
2113 if (saip->sai_device == sc->tulip_pci_devno)
2117 * Didn't find the right media block for this card.
2119 if (idx1 == shp->sh_adapter_count)
2123 * Save the hardware address.
2125 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6);
2127 * If this is a multiple port card, add the adapter index to the last
2128 * byte of the hardware address. (if it isn't multiport, adding 0
2131 sc->tulip_enaddr[5] += idx1;
2133 leaf_offset = saip->sai_leaf_offset_lowbyte
2134 + saip->sai_leaf_offset_highbyte * 256;
2135 dp = sc->tulip_rombuf + leaf_offset;
2137 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2;
2139 for (idx2 = 0;; idx2++) {
2140 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype
2141 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED)
2144 sc->tulip_connidx = idx2;
2146 if (sc->tulip_chipid == TULIP_21041) {
2148 for (idx2 = 0; idx2 < blocks; idx2++) {
2149 tulip_media_t media;
2151 srom_media = (tulip_srom_media_t) (data & 0x3F);
2152 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2153 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2156 media = tulip_srom_mediums[idx3].sm_type;
2157 if (media != TULIP_MEDIA_UNKNOWN) {
2158 if (data & TULIP_SROM_21041_EXTENDED) {
2159 mi->mi_type = TULIP_MEDIAINFO_SIA;
2160 sc->tulip_mediums[media] = mi;
2161 mi->mi_sia_connectivity = dp[0] + dp[1] * 256;
2162 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256;
2163 mi->mi_sia_general = dp[4] + dp[5] * 256;
2167 case TULIP_MEDIA_BNC: {
2168 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
2172 case TULIP_MEDIA_AUI: {
2173 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
2177 case TULIP_MEDIA_10BASET: {
2178 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
2182 case TULIP_MEDIA_10BASET_FD: {
2183 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
2193 if (data & TULIP_SROM_21041_EXTENDED)
2198 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++;
2199 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++;
2200 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++;
2201 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++;
2205 unsigned length, type;
2206 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN;
2207 if (sc->tulip_features & TULIP_HAVE_GPR)
2208 sc->tulip_gpinit = *dp++;
2210 for (idx2 = 0; idx2 < blocks; idx2++) {
2212 if ((*dp & 0x80) == 0) {
2216 length = (*dp++ & 0x7f) - 1;
2217 type = *dp++ & 0x3f;
2220 switch (type & 0x3f) {
2221 case 0: { /* 21140[A] GPR block */
2222 tulip_media_t media;
2223 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2224 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2225 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2228 media = tulip_srom_mediums[idx3].sm_type;
2229 if (media == TULIP_MEDIA_UNKNOWN)
2231 mi->mi_type = TULIP_MEDIAINFO_GPR;
2232 sc->tulip_mediums[media] = mi;
2233 mi->mi_gpdata = dp[1];
2234 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) {
2235 sc->tulip_gpdata = mi->mi_gpdata;
2238 data = dp[2] + dp[3] * 256;
2239 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2240 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2244 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2246 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2247 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2252 case 1: { /* 21140[A] MII block */
2253 const u_int phyno = *dp++;
2254 mi->mi_type = TULIP_MEDIAINFO_MII;
2255 mi->mi_gpr_length = *dp++;
2256 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2257 dp += mi->mi_gpr_length;
2258 mi->mi_reset_length = *dp++;
2259 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2260 dp += mi->mi_reset_length;
2263 * Before we probe for a PHY, use the GPR information
2264 * to select it. If we don't, it may be inaccessible.
2266 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET);
2267 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) {
2269 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]);
2271 sc->tulip_phyaddr = mi->mi_phyaddr;
2272 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) {
2274 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]);
2278 * At least write something!
2280 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2281 TULIP_CSR_WRITE(sc, csr_gp, 0);
2283 mi->mi_phyaddr = TULIP_MII_NOPHY;
2284 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2286 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2288 if (mi->mi_phyaddr == TULIP_MII_NOPHY)
2290 sc->tulip_features |= TULIP_HAVE_MII;
2291 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2292 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2293 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2294 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2295 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2296 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2297 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2298 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2299 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2300 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2301 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2305 case 2: { /* 2114[23] SIA block */
2306 tulip_media_t media;
2307 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2308 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2309 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2312 media = tulip_srom_mediums[idx3].sm_type;
2313 if (media == TULIP_MEDIA_UNKNOWN)
2315 mi->mi_type = TULIP_MEDIAINFO_SIA;
2316 sc->tulip_mediums[media] = mi;
2318 mi->mi_sia_connectivity = dp[1] + dp[2] * 256;
2319 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256;
2320 mi->mi_sia_general = dp[5] + dp[6] * 256;
2324 case TULIP_MEDIA_BNC: {
2325 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
2328 case TULIP_MEDIA_AUI: {
2329 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
2332 case TULIP_MEDIA_10BASET: {
2333 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
2334 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2337 case TULIP_MEDIA_10BASET_FD: {
2338 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
2339 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2347 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16;
2348 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16;
2353 case 3: { /* 2114[23] MII PHY block */
2354 const u_int phyno = *dp++;
2356 mi->mi_type = TULIP_MEDIAINFO_MII;
2357 mi->mi_gpr_length = *dp++;
2358 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2359 dp += 2 * mi->mi_gpr_length;
2360 mi->mi_reset_length = *dp++;
2361 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2362 dp += 2 * mi->mi_reset_length;
2364 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset];
2365 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) {
2367 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2369 sc->tulip_phyaddr = mi->mi_phyaddr;
2370 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset];
2371 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) {
2373 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2376 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2377 TULIP_CSR_WRITE(sc, csr_sia_general, 0);
2379 mi->mi_phyaddr = TULIP_MII_NOPHY;
2380 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2382 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2384 if (mi->mi_phyaddr == TULIP_MII_NOPHY)
2386 sc->tulip_features |= TULIP_HAVE_MII;
2387 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2388 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2389 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2390 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2391 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2;
2392 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2393 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2394 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2395 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2396 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2397 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2398 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2402 case 4: { /* 21143 SYM block */
2403 tulip_media_t media;
2404 srom_media = (tulip_srom_media_t) dp[0];
2405 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2406 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2409 media = tulip_srom_mediums[idx3].sm_type;
2410 if (media == TULIP_MEDIA_UNKNOWN)
2412 mi->mi_type = TULIP_MEDIAINFO_SYM;
2413 sc->tulip_mediums[media] = mi;
2414 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16;
2415 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16;
2416 data = dp[5] + dp[6] * 256;
2417 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2418 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2421 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2422 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2423 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2425 if (TULIP_IS_MEDIA_TP(media))
2426 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2431 case 5: { /* 21143 Reset block */
2432 mi->mi_type = TULIP_MEDIAINFO_RESET;
2433 mi->mi_reset_length = *dp++;
2434 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2435 dp += 2 * mi->mi_reset_length;
2446 return mi - sc->tulip_mediainfo;
2449 static const struct {
2450 void (*vendor_identify_nic)(tulip_softc_t * const sc);
2451 unsigned char vendor_oui[3];
2452 } tulip_vendors[] = {
2453 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } },
2454 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } },
2455 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } },
2456 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } },
2457 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } },
2458 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } },
2459 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } },
2460 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } },
2461 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } },
2462 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } },
2467 * This deals with the vagaries of the address roms and the
2468 * brain-deadness that various vendors commit in using them.
2471 tulip_read_macaddr(tulip_softc_t *sc)
2473 u_int cksum, rom_cksum, idx;
2475 unsigned char tmpbuf[8];
2476 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
2478 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX;
2480 if (sc->tulip_chipid == TULIP_21040) {
2481 TULIP_CSR_WRITE(sc, csr_enetrom, 1);
2482 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2484 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
2486 sc->tulip_rombuf[idx] = csr & 0xFF;
2488 sc->tulip_boardsw = &tulip_21040_boardsw;
2490 if (sc->tulip_chipid == TULIP_21041) {
2492 * Thankfully all 21041's act the same.
2494 sc->tulip_boardsw = &tulip_21041_boardsw;
2497 * Assume all 21140 board are compatible with the
2498 * DEC 10/100 evaluation board. Not really valid but
2499 * it's the best we can do until every one switches to
2500 * the new SROM format.
2503 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2505 tulip_srom_read(sc);
2506 if (tulip_srom_crcok(sc->tulip_rombuf)) {
2508 * SROM CRC is valid therefore it must be in the
2511 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM;
2512 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
2514 * No checksum is present. See if the SROM id checks out;
2515 * the first 18 bytes should be 0 followed by a 1 followed
2516 * by the number of adapters (which we don't deal with yet).
2518 for (idx = 0; idx < 18; idx++) {
2519 if (sc->tulip_rombuf[idx] != 0)
2522 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
2523 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2524 } else if (sc->tulip_chipid >= TULIP_21142) {
2525 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2526 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2528 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) {
2529 if (sc->tulip_chipid != TULIP_21041)
2530 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2533 * If the SROM specifies more than one adapter, tag this as a
2536 if (sc->tulip_rombuf[19] > 1)
2537 sc->tulip_features |= TULIP_HAVE_BASEROM;
2538 if (sc->tulip_boardsw == NULL)
2545 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
2547 * Some folks don't use the standard ethernet rom format
2548 * but instead just put the address in the first 6 bytes
2549 * of the rom and let the rest be all 0xffs. (Can we say
2550 * ZNYX?) (well sometimes they put in a checksum so we'll
2553 for (idx = 8; idx < 32; idx++) {
2554 if (sc->tulip_rombuf[idx] != 0xFF)
2558 * Make sure the address is not multicast or locally assigned
2559 * that the OUI is not 00-00-00.
2561 if ((sc->tulip_rombuf[0] & 3) != 0)
2563 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
2564 && sc->tulip_rombuf[2] == 0)
2566 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2567 sc->tulip_features |= TULIP_HAVE_OKROM;
2571 * A number of makers of multiport boards (ZNYX and Cogent)
2572 * only put on one address ROM on their 21040 boards. So
2573 * if the ROM is all zeros (or all 0xFFs), look at the
2574 * previous configured boards (as long as they are on the same
2575 * PCI bus and the bus number is non-zero) until we find the
2576 * master board with address ROM. We then use its address ROM
2577 * as the base for this board. (we add our relative board
2578 * to the last byte of its address).
2580 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2581 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF)
2584 if (idx == sizeof(sc->tulip_rombuf)) {
2586 tulip_softc_t *root_sc = NULL;
2587 for (root_unit = device_get_unit(sc->tulip_dev) - 1; root_unit >= 0; root_unit--) {
2588 root_sc = tulips[root_unit];
2589 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
2593 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM)
2594 && root_sc->tulip_chipid == sc->tulip_chipid
2595 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2596 sc->tulip_features |= TULIP_HAVE_SLAVEDROM;
2597 sc->tulip_boardsw = root_sc->tulip_boardsw;
2598 strcpy(sc->tulip_boardid, root_sc->tulip_boardid);
2599 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) {
2600 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf,
2601 sizeof(sc->tulip_rombuf));
2602 if (!tulip_srom_decode(sc))
2605 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
2606 sc->tulip_enaddr[5] += device_get_unit(sc->tulip_dev) - device_get_unit(root_sc->tulip_dev);
2609 * Now for a truly disgusting kludge: all 4 21040s on
2610 * the ZX314 share the same INTA line so the mapping
2611 * setup by the BIOS on the PCI bridge is worthless.
2612 * Rather than reprogramming the value in the config
2613 * register, we will handle this internally.
2615 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) {
2616 sc->tulip_slaves = root_sc->tulip_slaves;
2617 root_sc->tulip_slaves = sc;
2618 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2626 * This is the standard DEC address ROM test.
2629 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
2632 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
2633 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
2634 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
2635 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
2636 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
2639 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2641 cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
2643 if (cksum > 65535) cksum -= 65535;
2644 cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
2645 if (cksum > 65535) cksum -= 65535;
2647 if (cksum > 65535) cksum -= 65535;
2648 cksum += *(u_int16_t *) &sc->tulip_enaddr[4];
2649 if (cksum >= 65535) cksum -= 65535;
2651 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6];
2653 if (cksum != rom_cksum)
2658 * Check for various boards based on OUI. Did I say braindead?
2660 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) {
2661 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) {
2662 (*tulip_vendors[idx].vendor_identify_nic)(sc);
2667 sc->tulip_features |= TULIP_HAVE_OKROM;
2672 tulip_ifmedia_add(tulip_softc_t * const sc)
2674 tulip_media_t media;
2677 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2678 if (sc->tulip_mediums[media] != NULL) {
2679 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media],
2685 sc->tulip_features |= TULIP_HAVE_NOMEDIA;
2686 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0);
2687 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE);
2688 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
2689 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0);
2690 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO);
2692 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]);
2693 sc->tulip_flags |= TULIP_PRINTMEDIA;
2694 tulip_linkup(sc, sc->tulip_media);
2699 tulip_ifmedia_change(struct ifnet *ifp)
2701 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2703 sc->tulip_flags |= TULIP_NEEDRESET;
2704 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
2705 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
2706 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) {
2707 tulip_media_t media;
2708 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2709 if (sc->tulip_mediums[media] != NULL
2710 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) {
2711 sc->tulip_flags |= TULIP_PRINTMEDIA;
2712 sc->tulip_flags &= ~TULIP_DIDNWAY;
2713 tulip_linkup(sc, media);
2718 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
2725 * Media status callback
2728 tulip_ifmedia_status(struct ifnet *ifp, struct ifmediareq *req)
2730 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2732 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN)
2735 req->ifm_status = IFM_AVALID;
2736 if (sc->tulip_flags & TULIP_LINKUP)
2737 req->ifm_status |= IFM_ACTIVE;
2739 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
2743 tulip_addr_filter(tulip_softc_t *sc)
2745 struct ifmultiaddr *ifma;
2749 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI);
2750 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART;
2751 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
2752 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
2753 #if defined(IFF_ALLMULTI)
2754 if (sc->tulip_if.if_flags & IFF_ALLMULTI)
2755 sc->tulip_flags |= TULIP_ALLMULTI ;
2759 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
2760 ifma = ifma->ifma_link.le_next) {
2762 if (ifma->ifma_addr->sa_family == AF_LINK)
2766 sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */
2767 if (multicnt > 14) {
2768 uint32_t *sp = sc->tulip_setupdata;
2771 * Some early passes of the 21140 have broken implementations of
2772 * hash-perfect mode. When we get too many multicasts for perfect
2773 * filtering with these chips, we need to switch into hash-only
2774 * mode (this is better than all-multicast on network with lots
2775 * of multicast traffic).
2777 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
2778 sc->tulip_flags |= TULIP_WANTHASHONLY;
2780 sc->tulip_flags |= TULIP_WANTHASHPERFECT;
2782 * If we have more than 14 multicasts, we have
2783 * go into hash perfect mode (512 bit multicast
2784 * hash and one perfect hardware).
2786 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
2788 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
2789 ifma = ifma->ifma_link.le_next) {
2791 if (ifma->ifma_addr->sa_family != AF_LINK)
2794 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
2795 #if BYTE_ORDER == BIG_ENDIAN
2796 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2798 sp[hash >> 4] |= 1 << (hash & 0xF);
2802 * No reason to use a hash if we are going to be
2803 * receiving every multicast.
2805 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
2806 hash = tulip_mchash(sc->tulip_if.if_broadcastaddr);
2807 #if BYTE_ORDER == BIG_ENDIAN
2808 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2810 sp[hash >> 4] |= 1 << (hash & 0xF);
2812 if (sc->tulip_flags & TULIP_WANTHASHONLY) {
2813 hash = tulip_mchash(sc->tulip_enaddr);
2814 #if BYTE_ORDER == BIG_ENDIAN
2815 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2817 sp[hash >> 4] |= 1 << (hash & 0xF);
2820 #if BYTE_ORDER == BIG_ENDIAN
2821 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
2822 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
2823 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
2825 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0];
2826 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1];
2827 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2];
2832 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
2833 uint32_t *sp = sc->tulip_setupdata;
2835 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
2837 * Else can get perfect filtering for 16 addresses.
2839 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
2840 ifma = ifma->ifma_link.le_next) {
2841 if (ifma->ifma_addr->sa_family != AF_LINK)
2843 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
2844 #if BYTE_ORDER == BIG_ENDIAN
2845 *sp++ = ((u_int16_t *) addrp)[0] << 16;
2846 *sp++ = ((u_int16_t *) addrp)[1] << 16;
2847 *sp++ = ((u_int16_t *) addrp)[2] << 16;
2849 *sp++ = ((u_int16_t *) addrp)[0];
2850 *sp++ = ((u_int16_t *) addrp)[1];
2851 *sp++ = ((u_int16_t *) addrp)[2];
2856 * Add the broadcast address.
2859 #if BYTE_ORDER == BIG_ENDIAN
2860 *sp++ = 0xFFFF << 16;
2861 *sp++ = 0xFFFF << 16;
2862 *sp++ = 0xFFFF << 16;
2870 * Pad the rest with our hardware address
2872 for (; idx < 16; idx++) {
2873 #if BYTE_ORDER == BIG_ENDIAN
2874 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
2875 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
2876 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
2878 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0];
2879 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1];
2880 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2];
2884 #if defined(IFF_ALLMULTI)
2885 if (sc->tulip_flags & TULIP_ALLMULTI)
2886 sc->tulip_if.if_flags |= IFF_ALLMULTI;
2891 tulip_reset(tulip_softc_t *sc)
2893 tulip_ringinfo_t *ri;
2895 uint32_t inreset = (sc->tulip_flags & TULIP_INRESET);
2898 * Brilliant. Simply brilliant. When switching modes/speeds
2899 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
2900 * bits in CSR6 and then do a software reset to get the 21140
2901 * to properly reset its internal pathways to the right places.
2904 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
2905 && sc->tulip_boardsw->bd_media_preset != NULL)
2906 (*sc->tulip_boardsw->bd_media_preset)(sc);
2908 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2909 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
2910 33MHz that comes to two microseconds but wait a
2911 bit longer anyways) */
2914 sc->tulip_flags |= TULIP_INRESET;
2915 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
2916 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
2917 sc->tulip_if.if_start = tulip_ifstart;
2920 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
2921 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
2922 TULIP_CSR_WRITE(sc, csr_busmode,
2923 (1 << (3 /*pci_max_burst_len*/ + 8))
2924 |TULIP_BUSMODE_CACHE_ALIGN8
2925 |TULIP_BUSMODE_READMULTIPLE
2926 |(BYTE_ORDER != LITTLE_ENDIAN ?
2927 TULIP_BUSMODE_DESC_BIGENDIAN : 0));
2929 sc->tulip_txtimer = 0;
2930 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
2932 * Free all the mbufs that were on the transmit ring.
2934 IF_DRAIN(&sc->tulip_txq);
2936 ri = &sc->tulip_txinfo;
2937 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
2938 ri->ri_free = ri->ri_max;
2939 for (di = ri->ri_first; di < ri->ri_last; di++)
2943 * We need to collect all the mbufs were on the
2944 * receive ring before we reinit it either to put
2945 * them back on or to know if we have to allocate
2948 ri = &sc->tulip_rxinfo;
2949 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
2950 ri->ri_free = ri->ri_max;
2951 for (di = ri->ri_first; di < ri->ri_last; di++) {
2953 di->d_length1 = 0; di->d_addr1 = 0;
2954 di->d_length2 = 0; di->d_addr2 = 0;
2956 IF_DRAIN(&sc->tulip_rxq);
2959 * If tulip_reset is being called recurisvely, exit quickly knowing
2960 * that when the outer tulip_reset returns all the right stuff will
2966 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
2967 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
2968 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
2969 |TULIP_STS_RXSTOPPED;
2971 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
2972 (*sc->tulip_boardsw->bd_media_select)(sc);
2973 tulip_media_print(sc);
2974 if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
2975 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
2977 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
2979 tulip_addr_filter(sc);
2983 tulip_init(tulip_softc_t * const sc)
2985 if (sc->tulip_if.if_flags & IFF_UP) {
2986 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) {
2987 /* initialize the media */
2990 sc->tulip_if.if_flags |= IFF_RUNNING;
2991 if (sc->tulip_if.if_flags & IFF_PROMISC) {
2992 sc->tulip_flags |= TULIP_PROMISC;
2993 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
2994 sc->tulip_intrmask |= TULIP_STS_TXINTR;
2996 sc->tulip_flags &= ~TULIP_PROMISC;
2997 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
2998 if (sc->tulip_flags & TULIP_ALLMULTI) {
2999 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
3001 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
3004 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
3005 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
3007 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3008 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3010 sc->tulip_if.if_flags |= IFF_OACTIVE;
3011 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3012 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3014 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3015 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3016 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3017 tulip_txput_setup(sc);
3019 sc->tulip_if.if_flags &= ~IFF_RUNNING;
3025 tulip_rx_intr(tulip_softc_t *sc)
3027 tulip_ringinfo_t *ri = &sc->tulip_rxinfo;
3028 struct ifnet *ifp = &sc->tulip_if;
3032 struct ether_header eh;
3033 tulip_desc_t *eop = ri->ri_nextin;
3034 int total_len = 0, last_offset = 0;
3035 struct mbuf *ms = NULL, *me = NULL;
3038 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
3042 * If the TULIP has no descriptors, there can't be any receive
3043 * descriptors to process.
3045 if (eop == ri->ri_nextout)
3049 * 90% of the packets will fit in one descriptor. So we optimize
3052 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3053 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
3054 IF_DEQUEUE(&sc->tulip_rxq, ms);
3058 * If still owned by the TULIP, don't touch it.
3060 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
3064 * It is possible (though improbable unless the BIG_PACKET support
3065 * is enabled or MCLBYTES < 1518) for a received packet to cross
3066 * more than one receive descriptor.
3068 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) {
3069 if (++eop == ri->ri_last)
3071 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3072 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
3079 * Dequeue the first buffer for the start of the packet. Hopefully
3080 * this will be the only one we need to dequeue. However, if the
3081 * packet consumed multiple descriptors, then we need to dequeue
3082 * those buffers and chain to the starting mbuf. All buffers but
3083 * the last buffer have the same length so we can set that now.
3084 * (we add to last_offset instead of multiplying since we normally
3085 * won't go into the loop and thereby saving a ourselves from
3086 * doing a multiplication by 0 in the normal case).
3088 IF_DEQUEUE(&sc->tulip_rxq, ms);
3089 for (me = ms; total_len > 0; total_len--) {
3090 me->m_len = TULIP_RX_BUFLEN;
3091 last_offset += TULIP_RX_BUFLEN;
3092 IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
3098 * Now get the size of received packet (minus the CRC).
3100 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
3101 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
3102 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0
3104 || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) &&
3105 (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT|
3106 TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC|
3107 TULIP_DSTS_RxOVERFLOW)) == 0)
3110 me->m_len = total_len - last_offset;
3112 eh = *mtod(ms, struct ether_header *);
3113 sc->tulip_flags |= TULIP_RXACT;
3117 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3118 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3120 if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
3121 sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
3123 if (eop->d_status & TULIP_DSTS_RxBADCRC) {
3124 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
3125 sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
3127 sc->tulip_dot3stats.dot3StatsFCSErrors++;
3133 if (++eop == ri->ri_last)
3135 ri->ri_nextin = eop;
3138 * Either we are priming the TULIP with mbufs (m == NULL)
3139 * or we are about to accept an mbuf for the upper layers
3140 * so we need to allocate an mbuf to replace it. If we
3141 * can't replace it, send up it anyways. This may cause
3142 * us to drop packets in the future but that's better than
3143 * being caught in livelock.
3145 * Note that if this packet crossed multiple descriptors
3146 * we don't even try to reallocate all the mbufs here.
3147 * Instead we rely on the test of the beginning of
3148 * the loop to refill for the extra consumed mbufs.
3150 if (accept || ms == NULL) {
3152 MGETHDR(m0, MB_DONTWAIT, MT_DATA);
3154 #if defined(TULIP_COPY_RXDATA)
3155 if (!accept || total_len >= (MHLEN - 2)) {
3157 MCLGET(m0, MB_DONTWAIT);
3158 if ((m0->m_flags & M_EXT) == 0) {
3162 #if defined(TULIP_COPY_RXDATA)
3167 #if defined(TULIP_COPY_RXDATA)
3171 #if !defined(TULIP_COPY_RXDATA)
3172 ms->m_pkthdr.len = total_len;
3173 ms->m_pkthdr.rcvif = ifp;
3174 m_adj(ms, sizeof(struct ether_header));
3175 ether_input(ifp, &eh, ms);
3178 #error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
3180 m0->m_data += 2; /* align data after header */
3181 m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
3182 m0->m_len = m0->m_pkthdr.len = total_len;
3183 m0->m_pkthdr.rcvif = ifp;
3184 m_adj(m0, sizeof(struct ether_header));
3185 ether_input(ifp, &eh, m0);
3187 #endif /* ! TULIP_COPY_RXDATA */
3193 * Couldn't allocate a new buffer. Don't bother
3194 * trying to replenish the receive queue.
3197 sc->tulip_flags |= TULIP_RXBUFSLOW;
3201 * Now give the buffer(s) to the TULIP and save in our
3205 tulip_desc_t * const nextout = ri->ri_nextout;
3206 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
3207 nextout->d_length1 = TULIP_RX_BUFLEN;
3208 nextout->d_status = TULIP_DSTS_OWNER;
3209 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
3210 if (++ri->ri_nextout == ri->ri_last)
3211 ri->ri_nextout = ri->ri_first;
3214 IF_ENQUEUE(&sc->tulip_rxq, ms);
3215 } while ((ms = me) != NULL);
3217 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
3218 sc->tulip_flags &= ~TULIP_RXBUFSLOW;
3223 tulip_tx_intr(tulip_softc_t *sc)
3225 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3230 while (ri->ri_free < ri->ri_max) {
3233 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
3234 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
3239 d_flag = ri->ri_nextin->d_flag;
3240 if (d_flag & TULIP_DFLAG_TxLASTSEG) {
3241 if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
3243 * We've just finished processing a setup packet.
3244 * Mark that we finished it. If there's not
3245 * another pending, startup the TULIP receiver.
3246 * Make sure we ack the RXSTOPPED so we won't get
3247 * an abormal interrupt indication.
3249 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap);
3250 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
3251 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT)
3252 sc->tulip_flags |= TULIP_HASHONLY;
3253 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
3255 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3256 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3257 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3258 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3259 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3262 const uint32_t d_status = ri->ri_nextin->d_status;
3263 IF_DEQUEUE(&sc->tulip_txq, m);
3267 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3268 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
3269 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
3270 event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
3272 (*sc->tulip_boardsw->bd_media_poll)(sc, event);
3274 * Escape from the loop before media poll has reset the TULIP!
3279 if (d_status & TULIP_DSTS_ERRSUM) {
3280 sc->tulip_if.if_oerrors++;
3281 if (d_status & TULIP_DSTS_TxEXCCOLL)
3282 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
3283 if (d_status & TULIP_DSTS_TxLATECOLL)
3284 sc->tulip_dot3stats.dot3StatsLateCollisions++;
3285 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
3286 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
3287 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
3288 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
3289 if (d_status & TULIP_DSTS_TxUNDERFLOW)
3290 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
3291 if (d_status & TULIP_DSTS_TxBABBLE)
3292 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
3294 u_int32_t collisions =
3295 (d_status & TULIP_DSTS_TxCOLLMASK)
3296 >> TULIP_DSTS_V_TxCOLLCNT;
3297 sc->tulip_if.if_collisions += collisions;
3298 if (collisions == 1)
3299 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
3300 else if (collisions > 1)
3301 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
3302 else if (d_status & TULIP_DSTS_TxDEFERRED)
3303 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
3305 * SQE is only valid for 10baseT/BNC/AUI when not
3306 * running in full-duplex. In order to speed up the
3307 * test, the corresponding bit in tulip_flags needs to
3308 * set as well to get us to count SQE Test Errors.
3310 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
3311 sc->tulip_dot3stats.dot3StatsSQETestErrors++;
3317 if (++ri->ri_nextin == ri->ri_last)
3318 ri->ri_nextin = ri->ri_first;
3320 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3321 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
3324 * If nothing left to transmit, disable the timer.
3325 * Else if progress, reset the timer back to 2 ticks.
3327 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
3328 sc->tulip_txtimer = 0;
3330 sc->tulip_txtimer = TULIP_TXTIMER;
3331 sc->tulip_if.if_opackets += xmits;
3336 tulip_print_abnormal_interrupt(tulip_softc_t *sc, uint32_t csr)
3338 const char * const *msgp = tulip_status_bits;
3341 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
3343 csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1;
3344 if_printf(&sc->tulip_if, "abnormal interrupt:");
3345 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
3346 if ((csr & mask) && *msgp != NULL) {
3347 printf("%s%s", sep, *msgp);
3348 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
3349 sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
3350 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
3351 printf(" (switching to store-and-forward mode)");
3353 printf(" (raising TX threshold to %s)",
3354 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
3364 tulip_intr_handler(tulip_softc_t *sc)
3368 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3369 TULIP_CSR_WRITE(sc, csr_status, csr);
3371 if (csr & TULIP_STS_SYSERROR) {
3372 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
3373 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3374 sc->tulip_flags |= TULIP_SYSTEMERROR;
3376 if_printf(&sc->tulip_if, "system error: %s\n",
3377 tulip_system_errors[sc->tulip_last_system_error]);
3379 sc->tulip_flags |= TULIP_NEEDRESET;
3380 sc->tulip_system_errors++;
3383 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
3384 if (sc->tulip_boardsw->bd_media_poll != NULL) {
3385 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
3386 ? TULIP_MEDIAPOLL_LINKFAIL
3387 : TULIP_MEDIAPOLL_LINKPASS);
3388 csr &= ~TULIP_STS_ABNRMLINTR;
3390 tulip_media_print(sc);
3392 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
3393 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
3394 if (csr & TULIP_STS_RXNOBUF)
3395 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
3397 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3398 * on receive overflows.
3400 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
3401 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3403 * Stop the receiver process and spin until it's stopped.
3404 * Tell rx_intr to drop the packets it dequeues.
3406 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
3407 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
3409 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3410 sc->tulip_flags |= TULIP_RXIGNORE;
3413 if (sc->tulip_flags & TULIP_RXIGNORE) {
3415 * Restart the receiver.
3417 sc->tulip_flags &= ~TULIP_RXIGNORE;
3418 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3421 if (csr & TULIP_STS_ABNRMLINTR) {
3422 u_int32_t tmp = csr & sc->tulip_intrmask
3423 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
3424 if (csr & TULIP_STS_TXUNDERFLOW) {
3425 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
3426 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
3427 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3428 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
3429 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
3430 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3433 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3434 sc->tulip_statusbits |= tmp;
3436 tulip_print_abnormal_interrupt(sc, tmp);
3437 sc->tulip_flags |= TULIP_NOMESSAGES;
3439 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3441 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
3443 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3444 tulip_ifstart(&sc->tulip_if);
3447 if (sc->tulip_flags & TULIP_NEEDRESET) {
3454 tulip_intr_shared(void *arg)
3458 for (sc = arg; sc != NULL; sc = sc->tulip_slaves)
3459 tulip_intr_handler(sc);
3463 tulip_intr_normal(void *arg)
3465 tulip_softc_t *sc = (tulip_softc_t *)arg;
3467 tulip_intr_handler(sc);
3470 static struct mbuf *
3471 tulip_txput(tulip_softc_t *sc, struct mbuf *m)
3473 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3474 tulip_desc_t *eop, *nextout;
3480 * Now we try to fill in our transmit descriptors. This is
3481 * a bit reminiscent of going on the Ark two by two
3482 * since each descriptor for the TULIP can describe
3483 * two buffers. So we advance through packet filling
3484 * each of the two entries at a time to to fill each
3485 * descriptor. Clear the first and last segment bits
3486 * in each descriptor (actually just clear everything
3487 * but the end-of-ring or chain bits) to make sure
3488 * we don't get messed up by previously sent packets.
3490 * We may fail to put the entire packet on the ring if
3491 * there is either not enough ring entries free or if the
3492 * packet has more than MAX_TXSEG segments. In the former
3493 * case we will just wait for the ring to empty. In the
3494 * latter case we have to recopy.
3499 eop = nextout = ri->ri_nextout;
3504 int len = m0->m_len;
3505 caddr_t addr = mtod(m0, caddr_t);
3506 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1));
3509 unsigned slen = min(len, clsize);
3513 slen = 2040, partial = 1;
3516 if (segcnt > TULIP_MAX_TXSEG) {
3518 * The packet exceeds the number of transmit buffer
3519 * entries that we can use for one packet, so we have
3520 * recopy it into one mbuf and then try again.
3522 m0 = m_defrag(m, MB_DONTWAIT);
3531 * See if there's any unclaimed space in the
3534 if ((free += tulip_tx_intr(sc)) == 0) {
3536 * There's no more room but since nothing
3537 * has been committed at this point, just
3538 * show output is active, put back the
3541 sc->tulip_flags |= TULIP_WANTTXSTART;
3546 if (++nextout == ri->ri_last)
3547 nextout = ri->ri_first;
3548 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
3549 eop->d_status = d_status;
3550 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr);
3551 eop->d_length1 = slen;
3554 * Fill in second half of descriptor
3556 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr);
3557 eop->d_length2 = slen;
3559 d_status = TULIP_DSTS_OWNER;
3568 } while ((m0 = m0->m_next) != NULL);
3570 BPF_MTAP(&sc->tulip_if, m);
3573 * The descriptors have been filled in. Now get ready
3576 IF_ENQUEUE(&sc->tulip_txq, m);
3580 * Make sure the next descriptor after this packet is owned
3581 * by us since it may have been set up above if we ran out
3582 * of room in the ring.
3584 nextout->d_status = 0;
3585 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
3588 * If we only used the first segment of the last descriptor,
3589 * make sure the second segment will not be used.
3597 * Mark the last and first segments, indicate we want a transmit
3598 * complete interrupt, and tell it to transmit!
3600 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
3603 * Note that ri->ri_nextout is still the start of the packet
3604 * and until we set the OWNER bit, we can still back out of
3605 * everything we have done.
3607 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
3608 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
3609 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
3612 * This advances the ring for us.
3614 ri->ri_nextout = nextout;
3617 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3618 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3619 sc->tulip_if.if_flags |= IFF_OACTIVE;
3620 sc->tulip_if.if_start = tulip_ifstart;
3625 * switch back to the single queueing ifstart.
3627 sc->tulip_flags &= ~TULIP_WANTTXSTART;
3628 if (sc->tulip_txtimer == 0)
3629 sc->tulip_txtimer = TULIP_TXTIMER;
3632 * If we want a txstart, there must be not enough space in the
3633 * transmit ring. So we want to enable transmit done interrupts
3634 * so we can immediately reclaim some space. When the transmit
3635 * interrupt is posted, the interrupt handler will call tx_intr
3636 * to reclaim space and then txstart (since WANTTXSTART is set).
3637 * txstart will move the packet into the transmit ring and clear
3638 * WANTTXSTART thereby causing TXINTR to be cleared.
3641 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
3642 sc->tulip_if.if_flags |= IFF_OACTIVE;
3643 sc->tulip_if.if_start = tulip_ifstart;
3644 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
3645 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3646 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3648 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) {
3649 if (sc->tulip_intrmask & TULIP_STS_TXINTR) {
3650 sc->tulip_intrmask &= ~TULIP_STS_TXINTR;
3651 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3654 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3659 tulip_txput_setup(tulip_softc_t *sc)
3661 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3662 tulip_desc_t *nextout;
3665 * We will transmit, at most, one setup packet per call to ifstart.
3669 * Try to reclaim some free descriptors..
3671 if (ri->ri_free < 2)
3673 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
3674 sc->tulip_flags |= TULIP_WANTTXSTART;
3675 sc->tulip_if.if_start = tulip_ifstart;
3678 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
3679 sizeof(sc->tulip_setupbuf));
3681 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is
3682 * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
3684 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP;
3686 nextout = ri->ri_nextout;
3687 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
3688 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
3689 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
3690 if (sc->tulip_flags & TULIP_WANTHASHPERFECT)
3691 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
3692 else if (sc->tulip_flags & TULIP_WANTHASHONLY)
3693 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT;
3695 nextout->d_length2 = 0;
3696 nextout->d_addr2 = 0;
3697 nextout->d_length1 = sizeof(sc->tulip_setupbuf);
3698 nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
3701 * Advance the ring for the next transmit packet.
3703 if (++ri->ri_nextout == ri->ri_last)
3704 ri->ri_nextout = ri->ri_first;
3707 * Make sure the next descriptor is owned by us since it
3708 * may have been set up above if we ran out of room in the
3711 ri->ri_nextout->d_status = 0;
3712 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
3713 nextout->d_status = TULIP_DSTS_OWNER;
3715 * Flush the ownwership of the current descriptor
3717 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
3718 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3719 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
3720 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3721 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3726 tulip_ifioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred * cr)
3728 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
3729 struct ifaddr *ifa = (struct ifaddr *)data;
3730 struct ifreq *ifr = (struct ifreq *)data;
3737 ifp->if_flags |= IFF_UP;
3738 switch(ifa->ifa_addr->sa_family) {
3742 arp_ifinit(&(sc)->tulip_ac.ac_if, ifa);
3749 struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr);
3750 if (ipx_nullhost(*ina)) {
3751 ina->x_host = *(union ipx_host *)(sc->tulip_enaddr);
3753 ifp->if_flags &= ~IFF_RUNNING;
3754 bcopy((caddr_t)ina->x_host.c_host,
3755 (caddr_t)sc->tulip_enaddr,
3756 sizeof(sc->tulip_enaddr));
3765 * This magic copied from if_is.c; I don't use XNS,
3766 * so I have no way of telling if this actually
3770 struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
3771 if (ns_nullhost(*ina)) {
3772 ina->x_host = *(union ns_host *)(sc->tulip_enaddr);
3774 ifp->if_flags &= ~IFF_RUNNING;
3775 bcopy((caddr_t)ina->x_host.c_host,
3776 (caddr_t)sc->tulip_enaddr,
3777 sizeof(sc->tulip_enaddr));
3792 bcopy((caddr_t) sc->tulip_enaddr,
3793 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
3798 case SIOCSIFFLAGS: {
3799 tulip_addr_filter(sc); /* reinit multicast filter */
3805 case SIOCGIFMEDIA: {
3806 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
3811 case SIOCDELMULTI: {
3813 * Update multicast listeners
3815 tulip_addr_filter(sc); /* reset multicast filtering */
3823 * Set the interface MTU.
3825 if (ifr->ifr_mtu > ETHERMTU
3827 && sc->tulip_chipid != TULIP_21140
3828 && sc->tulip_chipid != TULIP_21140A
3829 && sc->tulip_chipid != TULIP_21041
3835 ifp->if_mtu = ifr->ifr_mtu;
3843 case SIOCGADDRROM: {
3844 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
3850 ifr->ifr_metric = (int) sc->tulip_chipid;
3865 tulip_ifstart(struct ifnet *ifp)
3867 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
3869 if (sc->tulip_if.if_flags & IFF_RUNNING) {
3871 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3872 tulip_txput_setup(sc);
3874 while (sc->tulip_if.if_snd.ifq_head != NULL) {
3876 IF_DEQUEUE(&sc->tulip_if.if_snd, m);
3877 if ((m = tulip_txput(sc, m)) != NULL) {
3878 IF_PREPEND(&sc->tulip_if.if_snd, m);
3886 tulip_ifwatchdog(struct ifnet *ifp)
3888 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
3890 sc->tulip_if.if_timer = 1;
3892 * These should be rare so do a bulk test up front so we can just skip
3895 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) {
3897 * If the number of receive buffer is low, try to refill
3899 if (sc->tulip_flags & TULIP_RXBUFSLOW)
3902 if (sc->tulip_flags & TULIP_SYSTEMERROR) {
3903 if_printf(ifp, "%d system errors: last was %s\n",
3904 sc->tulip_system_errors,
3905 tulip_system_errors[sc->tulip_last_system_error]);
3907 if (sc->tulip_statusbits) {
3908 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
3909 sc->tulip_statusbits = 0;
3912 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR);
3915 if (sc->tulip_txtimer)
3917 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
3918 if_printf(ifp, "transmission timeout\n");
3919 if (TULIP_DO_AUTOSENSE(sc)) {
3920 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
3921 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
3922 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP);
3930 tulip_attach(tulip_softc_t *sc)
3932 struct ifnet *ifp = &sc->tulip_if;
3934 callout_init(&sc->tulip_timer);
3935 callout_init(&sc->tulip_fast_timer);
3937 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
3938 ifp->if_ioctl = tulip_ifioctl;
3939 ifp->if_start = tulip_ifstart;
3940 ifp->if_watchdog = tulip_ifwatchdog;
3943 if_printf(ifp, "%s%s pass %d.%d%s\n",
3945 tulip_chipdescs[sc->tulip_chipid],
3946 (sc->tulip_revinfo & 0xF0) >> 4,
3947 sc->tulip_revinfo & 0x0F,
3948 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM))
3949 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "");
3951 (*sc->tulip_boardsw->bd_media_probe)(sc);
3952 ifmedia_init(&sc->tulip_ifmedia, 0,
3953 tulip_ifmedia_change,
3954 tulip_ifmedia_status);
3955 sc->tulip_flags &= ~TULIP_DEVICEPROBE;
3956 tulip_ifmedia_add(sc);
3960 ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr);
3961 ifp->if_snd.ifq_maxlen = ifqmaxlen;
3965 tulip_initcsrs(tulip_softc_t *sc, tulip_csrptr_t csr_base, size_t csr_size)
3967 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
3968 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
3969 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
3970 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
3971 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
3972 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
3973 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
3974 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
3975 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size;
3976 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size;
3977 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size;
3978 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size;
3979 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size;
3980 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size;
3981 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
3982 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
3986 tulip_initring(tulip_softc_t *sc, tulip_ringinfo_t *ri, tulip_desc_t *descs,
3989 ri->ri_max = ndescs;
3990 ri->ri_first = descs;
3991 ri->ri_last = ri->ri_first + ri->ri_max;
3992 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
3993 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
3997 * This is the PCI configuration support.
4000 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
4001 #define PCI_CBMA 0x14 /* Configuration Base Memory Address */
4002 #define PCI_CFDA 0x40 /* Configuration Driver Area */
4005 tulip_pci_probe(device_t dev)
4007 const char *name = NULL;
4009 if (pci_get_vendor(dev) != DEC_VENDORID)
4013 * Some LanMedia WAN cards use the Tulip chip, but they have
4014 * their own driver, and we should not recognize them
4016 if (pci_get_subvendor(dev) == 0x1376)
4019 switch (pci_get_device(dev)) {
4021 name = "Digital 21040 Ethernet";
4024 name = "Digital 21041 Ethernet";
4027 if (pci_get_revid(dev) >= 0x20)
4028 name = "Digital 21140A Fast Ethernet";
4030 name = "Digital 21140 Fast Ethernet";
4033 if (pci_get_revid(dev) >= 0x20)
4034 name = "Digital 21143 Fast Ethernet";
4036 name = "Digital 21142 Fast Ethernet";
4040 device_set_desc(dev, name);
4047 tulip_shutdown(device_t dev)
4049 tulip_softc_t *sc = device_get_softc(dev);
4050 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4051 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
4052 33MHz that comes to two microseconds but wait a
4053 bit longer anyways) */
4058 tulip_pci_attach(device_t dev)
4062 uint32_t revinfo, cfdainfo, cfcsinfo;
4063 u_int csroffset = TULIP_PCI_CSROFFSET;
4064 u_int csrsize = TULIP_PCI_CSRSIZE;
4065 tulip_csrptr_t csr_base;
4066 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
4067 struct resource *res;
4070 if (device_get_unit(dev) >= TULIP_MAX_DEVICES) {
4071 device_printf(dev, "not configured; limit of %d reached or exceeded\n",
4076 revinfo = pci_get_revid(dev);
4077 cfdainfo = pci_read_config(dev, PCI_CFDA, 4);
4078 cfcsinfo = pci_read_config(dev, PCIR_COMMAND, 4);
4080 /* turn busmaster on in case BIOS doesn't set it */
4081 pci_enable_busmaster(dev);
4083 if (pci_get_vendor(dev) == DEC_VENDORID) {
4084 if (pci_get_device(dev) == CHIPID_21040)
4085 chipid = TULIP_21040;
4086 else if (pci_get_device(dev) == CHIPID_21041)
4087 chipid = TULIP_21041;
4088 else if (pci_get_device(dev) == CHIPID_21140)
4089 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140;
4090 else if (pci_get_device(dev) == CHIPID_21142)
4091 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142;
4093 if (chipid == TULIP_CHIPID_UNKNOWN)
4096 if (chipid == TULIP_21040 && revinfo < 0x20) {
4097 device_printf(dev, "not configured; 21040 pass 2.0 required (%d.%d found)\n",
4098 revinfo >> 4, revinfo & 0x0f);
4100 } else if (chipid == TULIP_21140 && revinfo < 0x11) {
4101 device_printf(dev, "not configured; 21140 pass 1.1 required (%d.%d found)\n",
4102 revinfo >> 4, revinfo & 0x0f);
4106 sc = device_get_softc(dev);
4107 sc->tulip_dev = dev;
4108 sc->tulip_pci_busno = pci_get_bus(dev);
4109 sc->tulip_pci_devno = pci_get_slot(dev);
4110 sc->tulip_chipid = chipid;
4111 sc->tulip_flags |= TULIP_DEVICEPROBE;
4112 if (chipid == TULIP_21140 || chipid == TULIP_21140A)
4113 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD;
4114 if (chipid == TULIP_21140A && revinfo <= 0x22)
4115 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW;
4116 if (chipid == TULIP_21140)
4117 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH;
4118 if (chipid != TULIP_21040 && chipid != TULIP_21140)
4119 sc->tulip_features |= TULIP_HAVE_POWERMGMT;
4120 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) {
4121 sc->tulip_features |= TULIP_HAVE_DUALSENSE;
4122 if (chipid != TULIP_21041 || revinfo >= 0x20)
4123 sc->tulip_features |= TULIP_HAVE_SIANWAY;
4124 if (chipid != TULIP_21041)
4125 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD;
4126 if (chipid != TULIP_21041 && revinfo >= 0x20)
4127 sc->tulip_features |= TULIP_HAVE_SIA100;
4130 if (sc->tulip_features & TULIP_HAVE_POWERMGMT
4131 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) {
4132 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE);
4133 pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
4136 if_initname(&sc->tulip_if, device_get_name(dev), device_get_unit(dev));
4137 sc->tulip_revinfo = revinfo;
4138 sc->tulip_if.if_softc = sc;
4139 #if defined(TULIP_IOMAPPED)
4141 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
4142 0, ~0, 1, RF_ACTIVE);
4145 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
4146 0, ~0, 1, RF_ACTIVE);
4150 sc->tulip_csrs_bst = rman_get_bustag(res);
4151 sc->tulip_csrs_bsh = rman_get_bushandle(res);
4154 tulips[device_get_unit(dev)] = sc;
4156 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
4158 sc->tulip_rxdescs = malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS,
4159 M_DEVBUF, M_INTWAIT);
4160 sc->tulip_txdescs = malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS,
4161 M_DEVBUF, M_INTWAIT);
4163 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS);
4164 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS);
4167 * Make sure there won't be any interrupts or such...
4169 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4170 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
4171 33MHz that comes to two microseconds but wait a
4172 bit longer anyways) */
4174 if ((retval = tulip_read_macaddr(sc)) < 0) {
4175 device_printf(dev, "can't read ENET ROM (why=%d) (", retval);
4176 for (idx = 0; idx < 32; idx++)
4177 printf("%02x", sc->tulip_rombuf[idx]);
4179 device_printf(dev, "%s%s pass %d.%d\n",
4180 sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
4181 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
4182 device_printf(dev, "address unknown\n");
4185 void (*intr_rtn)(void *) = tulip_intr_normal;
4187 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
4188 intr_rtn = tulip_intr_shared;
4190 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) {
4194 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
4195 0, ~0, 1, RF_SHAREABLE | RF_ACTIVE);
4196 if (res == 0 || bus_setup_intr(dev, res, INTR_TYPE_NET,
4197 intr_rtn, sc, &ih)) {
4198 device_printf(dev, "couldn't map interrupt\n");
4199 free((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
4200 free((caddr_t) sc->tulip_txdescs, M_DEVBUF);
4212 static device_method_t tulip_pci_methods[] = {
4213 /* Device interface */
4214 DEVMETHOD(device_probe, tulip_pci_probe),
4215 DEVMETHOD(device_attach, tulip_pci_attach),
4216 DEVMETHOD(device_shutdown, tulip_shutdown),
4219 static driver_t tulip_pci_driver = {
4222 sizeof(tulip_softc_t),
4224 static devclass_t tulip_devclass;
4226 DECLARE_DUMMY_MODULE(if_de);
4227 DRIVER_MODULE(if_de, pci, tulip_pci_driver, tulip_devclass, 0, 0);