1 /* $NetBSD: if_de.c,v 1.86 1999/06/01 19:17:59 thorpej Exp $ */
3 /* $FreeBSD: src/sys/pci/if_de.c,v 1.123.2.4 2000/08/04 23:25:09 peter Exp $ */
4 /* $DragonFly: src/sys/dev/netif/de/if_de.c,v 1.49 2008/08/17 04:32:33 sephe Exp $ */
7 * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com)
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software 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>
53 #include <sys/thread2.h>
54 #include <sys/interrupt.h>
60 #include <net/if_media.h>
61 #include <net/if_dl.h>
62 #include <net/ifq_var.h>
66 #include <netinet/in.h>
67 #include <netinet/if_ether.h>
71 #include <netproto/ipx/ipx.h>
72 #include <netproto/ipx/ipx_if.h>
76 #include <netproto/ns/ns.h>
77 #include <netproto/ns/ns_if.h>
82 #include <net/if_var.h>
84 #include <bus/pci/pcivar.h>
85 #include <bus/pci/pcireg.h>
86 #include <bus/pci/dc21040reg.h>
89 * Intel CPUs should use I/O mapped access.
92 #define TULIP_IOMAPPED
99 static tulip_softc_t *tulips[TULIP_MAX_DEVICES];
102 * This module supports
103 * the DEC 21040 PCI Ethernet Controller.
104 * the DEC 21041 PCI Ethernet Controller.
105 * the DEC 21140 PCI Fast Ethernet Controller.
107 static void tulip_mii_autonegotiate(tulip_softc_t *, u_int);
108 static void tulip_intr_shared(void *);
109 static void tulip_intr_normal(void *);
110 static void tulip_init(tulip_softc_t *);
111 static void tulip_reset(tulip_softc_t *);
112 static void tulip_ifstart(struct ifnet *);
113 static struct mbuf *tulip_txput(tulip_softc_t *, struct mbuf *);
114 static void tulip_txput_setup(tulip_softc_t *);
115 static void tulip_rx_intr(tulip_softc_t *);
116 static void tulip_addr_filter(tulip_softc_t *);
117 static u_int tulip_mii_readreg(tulip_softc_t *, u_int, u_int);
118 static void tulip_mii_writereg(tulip_softc_t *, u_int, u_int, u_int);
119 static int tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities);
120 static tulip_media_t tulip_mii_phy_readspecific(tulip_softc_t *);
121 static int tulip_srom_decode(tulip_softc_t *);
122 static int tulip_ifmedia_change(struct ifnet *);
123 static void tulip_ifmedia_status(struct ifnet *, struct ifmediareq *);
124 /* static void tulip_21140_map_media(tulip_softc_t *sc); */
127 tulip_timeout_callback(void *arg)
129 tulip_softc_t *sc = arg;
131 lwkt_serialize_enter(sc->tulip_if.if_serializer);
132 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING;
133 sc->tulip_probe_timeout -= 1000 / TULIP_HZ;
134 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER);
135 lwkt_serialize_exit(sc->tulip_if.if_serializer);
139 tulip_timeout(tulip_softc_t *sc)
141 if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
143 sc->tulip_flags |= TULIP_TIMEOUTPENDING;
144 callout_reset(&sc->tulip_timer, (hz + TULIP_HZ / 2) / TULIP_HZ,
145 tulip_timeout_callback, sc);
149 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;
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;
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 LIST_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
2760 if (ifma->ifma_addr->sa_family == AF_LINK)
2764 sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */
2765 if (multicnt > 14) {
2766 uint32_t *sp = sc->tulip_setupdata;
2769 * Some early passes of the 21140 have broken implementations of
2770 * hash-perfect mode. When we get too many multicasts for perfect
2771 * filtering with these chips, we need to switch into hash-only
2772 * mode (this is better than all-multicast on network with lots
2773 * of multicast traffic).
2775 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
2776 sc->tulip_flags |= TULIP_WANTHASHONLY;
2778 sc->tulip_flags |= TULIP_WANTHASHPERFECT;
2780 * If we have more than 14 multicasts, we have
2781 * go into hash perfect mode (512 bit multicast
2782 * hash and one perfect hardware).
2784 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
2786 LIST_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
2787 if (ifma->ifma_addr->sa_family != AF_LINK)
2790 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
2791 #if BYTE_ORDER == BIG_ENDIAN
2792 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2794 sp[hash >> 4] |= 1 << (hash & 0xF);
2798 * No reason to use a hash if we are going to be
2799 * receiving every multicast.
2801 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
2802 hash = tulip_mchash(sc->tulip_if.if_broadcastaddr);
2803 #if BYTE_ORDER == BIG_ENDIAN
2804 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2806 sp[hash >> 4] |= 1 << (hash & 0xF);
2808 if (sc->tulip_flags & TULIP_WANTHASHONLY) {
2809 hash = tulip_mchash(sc->tulip_enaddr);
2810 #if BYTE_ORDER == BIG_ENDIAN
2811 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2813 sp[hash >> 4] |= 1 << (hash & 0xF);
2816 #if BYTE_ORDER == BIG_ENDIAN
2817 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
2818 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
2819 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
2821 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0];
2822 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1];
2823 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2];
2828 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
2829 uint32_t *sp = sc->tulip_setupdata;
2831 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
2833 * Else can get perfect filtering for 16 addresses.
2835 LIST_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
2836 if (ifma->ifma_addr->sa_family != AF_LINK)
2838 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
2839 #if BYTE_ORDER == BIG_ENDIAN
2840 *sp++ = ((u_int16_t *) addrp)[0] << 16;
2841 *sp++ = ((u_int16_t *) addrp)[1] << 16;
2842 *sp++ = ((u_int16_t *) addrp)[2] << 16;
2844 *sp++ = ((u_int16_t *) addrp)[0];
2845 *sp++ = ((u_int16_t *) addrp)[1];
2846 *sp++ = ((u_int16_t *) addrp)[2];
2851 * Add the broadcast address.
2854 #if BYTE_ORDER == BIG_ENDIAN
2855 *sp++ = 0xFFFF << 16;
2856 *sp++ = 0xFFFF << 16;
2857 *sp++ = 0xFFFF << 16;
2865 * Pad the rest with our hardware address
2867 for (; idx < 16; idx++) {
2868 #if BYTE_ORDER == BIG_ENDIAN
2869 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
2870 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
2871 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
2873 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0];
2874 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1];
2875 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2];
2879 #if defined(IFF_ALLMULTI)
2880 if (sc->tulip_flags & TULIP_ALLMULTI)
2881 sc->tulip_if.if_flags |= IFF_ALLMULTI;
2886 tulip_reset(tulip_softc_t *sc)
2888 tulip_ringinfo_t *ri;
2890 uint32_t inreset = (sc->tulip_flags & TULIP_INRESET);
2893 * Brilliant. Simply brilliant. When switching modes/speeds
2894 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
2895 * bits in CSR6 and then do a software reset to get the 21140
2896 * to properly reset its internal pathways to the right places.
2899 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
2900 && sc->tulip_boardsw->bd_media_preset != NULL)
2901 (*sc->tulip_boardsw->bd_media_preset)(sc);
2903 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2904 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
2905 33MHz that comes to two microseconds but wait a
2906 bit longer anyways) */
2909 sc->tulip_flags |= TULIP_INRESET;
2910 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
2911 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
2912 sc->tulip_if.if_start = tulip_ifstart;
2915 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
2916 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
2917 TULIP_CSR_WRITE(sc, csr_busmode,
2918 (1 << (3 /*pci_max_burst_len*/ + 8))
2919 |TULIP_BUSMODE_CACHE_ALIGN8
2920 |TULIP_BUSMODE_READMULTIPLE
2921 |(BYTE_ORDER != LITTLE_ENDIAN ?
2922 TULIP_BUSMODE_DESC_BIGENDIAN : 0));
2924 sc->tulip_txtimer = 0;
2925 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
2927 * Free all the mbufs that were on the transmit ring.
2929 IF_DRAIN(&sc->tulip_txq);
2931 ri = &sc->tulip_txinfo;
2932 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
2933 ri->ri_free = ri->ri_max;
2934 for (di = ri->ri_first; di < ri->ri_last; di++)
2938 * We need to collect all the mbufs were on the
2939 * receive ring before we reinit it either to put
2940 * them back on or to know if we have to allocate
2943 ri = &sc->tulip_rxinfo;
2944 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
2945 ri->ri_free = ri->ri_max;
2946 for (di = ri->ri_first; di < ri->ri_last; di++) {
2948 di->d_length1 = 0; di->d_addr1 = 0;
2949 di->d_length2 = 0; di->d_addr2 = 0;
2951 IF_DRAIN(&sc->tulip_rxq);
2954 * If tulip_reset is being called recurisvely, exit quickly knowing
2955 * that when the outer tulip_reset returns all the right stuff will
2961 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
2962 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
2963 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
2964 |TULIP_STS_RXSTOPPED;
2966 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
2967 (*sc->tulip_boardsw->bd_media_select)(sc);
2968 tulip_media_print(sc);
2969 if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
2970 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
2972 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
2974 tulip_addr_filter(sc);
2978 tulip_init(tulip_softc_t * const sc)
2980 if (sc->tulip_if.if_flags & IFF_UP) {
2981 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) {
2982 /* initialize the media */
2985 sc->tulip_if.if_flags |= IFF_RUNNING;
2986 if (sc->tulip_if.if_flags & IFF_PROMISC) {
2987 sc->tulip_flags |= TULIP_PROMISC;
2988 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
2989 sc->tulip_intrmask |= TULIP_STS_TXINTR;
2991 sc->tulip_flags &= ~TULIP_PROMISC;
2992 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
2993 if (sc->tulip_flags & TULIP_ALLMULTI) {
2994 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
2996 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
2999 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
3000 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
3002 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3003 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3005 sc->tulip_if.if_flags |= IFF_OACTIVE;
3006 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3007 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3009 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3010 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3011 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3012 tulip_txput_setup(sc);
3014 sc->tulip_if.if_flags &= ~IFF_RUNNING;
3020 tulip_rx_intr(tulip_softc_t *sc)
3022 tulip_ringinfo_t *ri = &sc->tulip_rxinfo;
3023 struct ifnet *ifp = &sc->tulip_if;
3027 tulip_desc_t *eop = ri->ri_nextin;
3028 int total_len = 0, last_offset = 0;
3029 struct mbuf *ms = NULL, *me = NULL;
3032 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
3036 * If the TULIP has no descriptors, there can't be any receive
3037 * descriptors to process.
3039 if (eop == ri->ri_nextout)
3043 * 90% of the packets will fit in one descriptor. So we optimize
3046 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3047 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
3048 IF_DEQUEUE(&sc->tulip_rxq, ms);
3052 * If still owned by the TULIP, don't touch it.
3054 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
3058 * It is possible (though improbable unless the BIG_PACKET support
3059 * is enabled or MCLBYTES < 1518) for a received packet to cross
3060 * more than one receive descriptor.
3062 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) {
3063 if (++eop == ri->ri_last)
3065 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3066 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
3073 * Dequeue the first buffer for the start of the packet. Hopefully
3074 * this will be the only one we need to dequeue. However, if the
3075 * packet consumed multiple descriptors, then we need to dequeue
3076 * those buffers and chain to the starting mbuf. All buffers but
3077 * the last buffer have the same length so we can set that now.
3078 * (we add to last_offset instead of multiplying since we normally
3079 * won't go into the loop and thereby saving a ourselves from
3080 * doing a multiplication by 0 in the normal case).
3082 IF_DEQUEUE(&sc->tulip_rxq, ms);
3083 for (me = ms; total_len > 0; total_len--) {
3084 me->m_len = TULIP_RX_BUFLEN;
3085 last_offset += TULIP_RX_BUFLEN;
3086 IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
3092 * Now get the size of received packet (minus the CRC).
3094 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
3095 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
3096 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0
3098 || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) &&
3099 (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT|
3100 TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC|
3101 TULIP_DSTS_RxOVERFLOW)) == 0)
3104 me->m_len = total_len - last_offset;
3106 sc->tulip_flags |= TULIP_RXACT;
3110 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3111 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3113 if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
3114 sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
3116 if (eop->d_status & TULIP_DSTS_RxBADCRC) {
3117 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
3118 sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
3120 sc->tulip_dot3stats.dot3StatsFCSErrors++;
3126 if (++eop == ri->ri_last)
3128 ri->ri_nextin = eop;
3131 * Either we are priming the TULIP with mbufs (m == NULL)
3132 * or we are about to accept an mbuf for the upper layers
3133 * so we need to allocate an mbuf to replace it. If we
3134 * can't replace it, send up it anyways. This may cause
3135 * us to drop packets in the future but that's better than
3136 * being caught in livelock.
3138 * Note that if this packet crossed multiple descriptors
3139 * we don't even try to reallocate all the mbufs here.
3140 * Instead we rely on the test of the beginning of
3141 * the loop to refill for the extra consumed mbufs.
3143 if (accept || ms == NULL) {
3146 #if defined(TULIP_COPY_RXDATA)
3147 if (!accept || total_len >= (MHLEN - 2))
3148 m0 = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
3150 m0 = m_gethdr(MB_DONTWAIT, MT_DATA);
3152 m0 = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
3156 #if defined(TULIP_COPY_RXDATA)
3160 #if !defined(TULIP_COPY_RXDATA)
3161 ms->m_pkthdr.len = total_len;
3162 ifp->if_input(ifp, ms);
3165 #error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
3167 m0->m_data += 2; /* align data after header */
3168 m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
3169 m0->m_len = m0->m_pkthdr.len = total_len;
3170 m0->m_pkthdr.rcvif = ifp;
3171 ifp->if_input(ifp, m0);
3173 #endif /* ! TULIP_COPY_RXDATA */
3179 * Couldn't allocate a new buffer. Don't bother
3180 * trying to replenish the receive queue.
3183 sc->tulip_flags |= TULIP_RXBUFSLOW;
3187 * Now give the buffer(s) to the TULIP and save in our
3191 tulip_desc_t * const nextout = ri->ri_nextout;
3192 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
3193 nextout->d_length1 = TULIP_RX_BUFLEN;
3194 nextout->d_status = TULIP_DSTS_OWNER;
3195 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
3196 if (++ri->ri_nextout == ri->ri_last)
3197 ri->ri_nextout = ri->ri_first;
3200 IF_ENQUEUE(&sc->tulip_rxq, ms);
3201 } while ((ms = me) != NULL);
3203 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
3204 sc->tulip_flags &= ~TULIP_RXBUFSLOW;
3209 tulip_tx_intr(tulip_softc_t *sc)
3211 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3216 while (ri->ri_free < ri->ri_max) {
3219 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
3220 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
3225 d_flag = ri->ri_nextin->d_flag;
3226 if (d_flag & TULIP_DFLAG_TxLASTSEG) {
3227 if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
3229 * We've just finished processing a setup packet.
3230 * Mark that we finished it. If there's not
3231 * another pending, startup the TULIP receiver.
3232 * Make sure we ack the RXSTOPPED so we won't get
3233 * an abormal interrupt indication.
3235 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap);
3236 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
3237 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT)
3238 sc->tulip_flags |= TULIP_HASHONLY;
3239 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
3241 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3242 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3243 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3244 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3245 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3248 const uint32_t d_status = ri->ri_nextin->d_status;
3249 IF_DEQUEUE(&sc->tulip_txq, m);
3253 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3254 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
3255 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
3256 event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
3258 (*sc->tulip_boardsw->bd_media_poll)(sc, event);
3260 * Escape from the loop before media poll has reset the TULIP!
3265 if (d_status & TULIP_DSTS_ERRSUM) {
3266 sc->tulip_if.if_oerrors++;
3267 if (d_status & TULIP_DSTS_TxEXCCOLL)
3268 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
3269 if (d_status & TULIP_DSTS_TxLATECOLL)
3270 sc->tulip_dot3stats.dot3StatsLateCollisions++;
3271 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
3272 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
3273 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
3274 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
3275 if (d_status & TULIP_DSTS_TxUNDERFLOW)
3276 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
3277 if (d_status & TULIP_DSTS_TxBABBLE)
3278 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
3280 u_int32_t collisions =
3281 (d_status & TULIP_DSTS_TxCOLLMASK)
3282 >> TULIP_DSTS_V_TxCOLLCNT;
3283 sc->tulip_if.if_collisions += collisions;
3284 if (collisions == 1)
3285 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
3286 else if (collisions > 1)
3287 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
3288 else if (d_status & TULIP_DSTS_TxDEFERRED)
3289 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
3291 * SQE is only valid for 10baseT/BNC/AUI when not
3292 * running in full-duplex. In order to speed up the
3293 * test, the corresponding bit in tulip_flags needs to
3294 * set as well to get us to count SQE Test Errors.
3296 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
3297 sc->tulip_dot3stats.dot3StatsSQETestErrors++;
3303 if (++ri->ri_nextin == ri->ri_last)
3304 ri->ri_nextin = ri->ri_first;
3306 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3307 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
3310 * If nothing left to transmit, disable the timer.
3311 * Else if progress, reset the timer back to 2 ticks.
3313 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
3314 sc->tulip_txtimer = 0;
3316 sc->tulip_txtimer = TULIP_TXTIMER;
3317 sc->tulip_if.if_opackets += xmits;
3322 tulip_print_abnormal_interrupt(tulip_softc_t *sc, uint32_t csr)
3324 const char * const *msgp = tulip_status_bits;
3327 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
3329 csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1;
3330 if_printf(&sc->tulip_if, "abnormal interrupt:");
3331 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
3332 if ((csr & mask) && *msgp != NULL) {
3333 kprintf("%s%s", sep, *msgp);
3334 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
3335 sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
3336 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
3337 kprintf(" (switching to store-and-forward mode)");
3339 kprintf(" (raising TX threshold to %s)",
3340 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
3350 tulip_intr_handler(tulip_softc_t *sc)
3354 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3355 TULIP_CSR_WRITE(sc, csr_status, csr);
3357 if (csr & TULIP_STS_SYSERROR) {
3358 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
3359 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3360 sc->tulip_flags |= TULIP_SYSTEMERROR;
3362 if_printf(&sc->tulip_if, "system error: %s\n",
3363 tulip_system_errors[sc->tulip_last_system_error]);
3365 sc->tulip_flags |= TULIP_NEEDRESET;
3366 sc->tulip_system_errors++;
3369 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
3370 if (sc->tulip_boardsw->bd_media_poll != NULL) {
3371 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
3372 ? TULIP_MEDIAPOLL_LINKFAIL
3373 : TULIP_MEDIAPOLL_LINKPASS);
3374 csr &= ~TULIP_STS_ABNRMLINTR;
3376 tulip_media_print(sc);
3378 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
3379 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
3380 if (csr & TULIP_STS_RXNOBUF)
3381 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
3383 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3384 * on receive overflows.
3386 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
3387 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3389 * Stop the receiver process and spin until it's stopped.
3390 * Tell rx_intr to drop the packets it dequeues.
3392 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
3393 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
3395 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3396 sc->tulip_flags |= TULIP_RXIGNORE;
3399 if (sc->tulip_flags & TULIP_RXIGNORE) {
3401 * Restart the receiver.
3403 sc->tulip_flags &= ~TULIP_RXIGNORE;
3404 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3407 if (csr & TULIP_STS_ABNRMLINTR) {
3408 u_int32_t tmp = csr & sc->tulip_intrmask
3409 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
3410 if (csr & TULIP_STS_TXUNDERFLOW) {
3411 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
3412 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
3413 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3414 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
3415 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
3416 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3419 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3420 sc->tulip_statusbits |= tmp;
3422 tulip_print_abnormal_interrupt(sc, tmp);
3423 sc->tulip_flags |= TULIP_NOMESSAGES;
3425 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3427 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
3429 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3430 if_devstart(&sc->tulip_if);
3433 if (sc->tulip_flags & TULIP_NEEDRESET) {
3440 tulip_intr_shared(void *arg)
3444 for (sc = arg; sc != NULL; sc = sc->tulip_slaves)
3445 tulip_intr_handler(sc);
3449 tulip_intr_normal(void *arg)
3451 tulip_softc_t *sc = (tulip_softc_t *)arg;
3453 tulip_intr_handler(sc);
3456 static struct mbuf *
3457 tulip_txput(tulip_softc_t *sc, struct mbuf *m)
3459 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3460 tulip_desc_t *eop, *nextout;
3466 * Now we try to fill in our transmit descriptors. This is
3467 * a bit reminiscent of going on the Ark two by two
3468 * since each descriptor for the TULIP can describe
3469 * two buffers. So we advance through packet filling
3470 * each of the two entries at a time to to fill each
3471 * descriptor. Clear the first and last segment bits
3472 * in each descriptor (actually just clear everything
3473 * but the end-of-ring or chain bits) to make sure
3474 * we don't get messed up by previously sent packets.
3476 * We may fail to put the entire packet on the ring if
3477 * there is either not enough ring entries free or if the
3478 * packet has more than MAX_TXSEG segments. In the former
3479 * case we will just wait for the ring to empty. In the
3480 * latter case we have to recopy.
3485 eop = nextout = ri->ri_nextout;
3490 int len = m0->m_len;
3491 caddr_t addr = mtod(m0, caddr_t);
3492 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1));
3495 unsigned slen = min(len, clsize);
3499 slen = 2040, partial = 1;
3502 if (segcnt > TULIP_MAX_TXSEG) {
3504 * The packet exceeds the number of transmit buffer
3505 * entries that we can use for one packet, so we have
3506 * recopy it into one mbuf and then try again.
3508 m0 = m_defrag(m, MB_DONTWAIT);
3517 * See if there's any unclaimed space in the
3520 if ((free += tulip_tx_intr(sc)) == 0) {
3522 * There's no more room but since nothing
3523 * has been committed at this point, just
3524 * show output is active, put back the
3527 sc->tulip_flags |= TULIP_WANTTXSTART;
3532 if (++nextout == ri->ri_last)
3533 nextout = ri->ri_first;
3534 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
3535 eop->d_status = d_status;
3536 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr);
3537 eop->d_length1 = slen;
3540 * Fill in second half of descriptor
3542 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr);
3543 eop->d_length2 = slen;
3545 d_status = TULIP_DSTS_OWNER;
3554 } while ((m0 = m0->m_next) != NULL);
3556 BPF_MTAP(&sc->tulip_if, m);
3559 * The descriptors have been filled in. Now get ready
3562 IF_ENQUEUE(&sc->tulip_txq, m);
3566 * Make sure the next descriptor after this packet is owned
3567 * by us since it may have been set up above if we ran out
3568 * of room in the ring.
3570 nextout->d_status = 0;
3571 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
3574 * If we only used the first segment of the last descriptor,
3575 * make sure the second segment will not be used.
3583 * Mark the last and first segments, indicate we want a transmit
3584 * complete interrupt, and tell it to transmit!
3586 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
3589 * Note that ri->ri_nextout is still the start of the packet
3590 * and until we set the OWNER bit, we can still back out of
3591 * everything we have done.
3593 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
3594 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
3595 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
3598 * This advances the ring for us.
3600 ri->ri_nextout = nextout;
3603 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3604 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3605 sc->tulip_if.if_flags |= IFF_OACTIVE;
3606 sc->tulip_if.if_start = tulip_ifstart;
3611 * switch back to the single queueing ifstart.
3613 sc->tulip_flags &= ~TULIP_WANTTXSTART;
3614 if (sc->tulip_txtimer == 0)
3615 sc->tulip_txtimer = TULIP_TXTIMER;
3618 * If we want a txstart, there must be not enough space in the
3619 * transmit ring. So we want to enable transmit done interrupts
3620 * so we can immediately reclaim some space. When the transmit
3621 * interrupt is posted, the interrupt handler will call tx_intr
3622 * to reclaim space and then txstart (since WANTTXSTART is set).
3623 * txstart will move the packet into the transmit ring and clear
3624 * WANTTXSTART thereby causing TXINTR to be cleared.
3627 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
3628 sc->tulip_if.if_flags |= IFF_OACTIVE;
3629 sc->tulip_if.if_start = tulip_ifstart;
3630 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
3631 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3632 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3634 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) {
3635 if (sc->tulip_intrmask & TULIP_STS_TXINTR) {
3636 sc->tulip_intrmask &= ~TULIP_STS_TXINTR;
3637 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3640 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3645 tulip_txput_setup(tulip_softc_t *sc)
3647 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3648 tulip_desc_t *nextout;
3651 * We will transmit, at most, one setup packet per call to ifstart.
3655 * Try to reclaim some free descriptors..
3657 if (ri->ri_free < 2)
3659 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
3660 sc->tulip_flags |= TULIP_WANTTXSTART;
3661 sc->tulip_if.if_start = tulip_ifstart;
3664 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
3665 sizeof(sc->tulip_setupbuf));
3667 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is
3668 * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
3670 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP;
3672 nextout = ri->ri_nextout;
3673 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
3674 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
3675 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
3676 if (sc->tulip_flags & TULIP_WANTHASHPERFECT)
3677 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
3678 else if (sc->tulip_flags & TULIP_WANTHASHONLY)
3679 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT;
3681 nextout->d_length2 = 0;
3682 nextout->d_addr2 = 0;
3683 nextout->d_length1 = sizeof(sc->tulip_setupbuf);
3684 nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
3687 * Advance the ring for the next transmit packet.
3689 if (++ri->ri_nextout == ri->ri_last)
3690 ri->ri_nextout = ri->ri_first;
3693 * Make sure the next descriptor is owned by us since it
3694 * may have been set up above if we ran out of room in the
3697 ri->ri_nextout->d_status = 0;
3698 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
3699 nextout->d_status = TULIP_DSTS_OWNER;
3701 * Flush the ownwership of the current descriptor
3703 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
3704 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3705 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
3706 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3707 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3712 tulip_ifioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred * cr)
3714 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
3715 struct ifaddr *ifa = (struct ifaddr *)data;
3716 struct ifreq *ifr = (struct ifreq *)data;
3721 ifp->if_flags |= IFF_UP;
3722 switch(ifa->ifa_addr->sa_family) {
3726 arp_ifinit(&(sc)->tulip_ac.ac_if, ifa);
3733 struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr);
3734 if (ipx_nullhost(*ina)) {
3735 ina->x_host = *(union ipx_host *)(sc->tulip_enaddr);
3737 ifp->if_flags &= ~IFF_RUNNING;
3738 bcopy((caddr_t)ina->x_host.c_host,
3739 (caddr_t)sc->tulip_enaddr,
3740 sizeof(sc->tulip_enaddr));
3749 * This magic copied from if_is.c; I don't use XNS,
3750 * so I have no way of telling if this actually
3754 struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
3755 if (ns_nullhost(*ina)) {
3756 ina->x_host = *(union ns_host *)(sc->tulip_enaddr);
3758 ifp->if_flags &= ~IFF_RUNNING;
3759 bcopy((caddr_t)ina->x_host.c_host,
3760 (caddr_t)sc->tulip_enaddr,
3761 sizeof(sc->tulip_enaddr));
3776 bcopy((caddr_t) sc->tulip_enaddr,
3777 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
3782 case SIOCSIFFLAGS: {
3783 tulip_addr_filter(sc); /* reinit multicast filter */
3789 case SIOCGIFMEDIA: {
3790 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
3795 case SIOCDELMULTI: {
3797 * Update multicast listeners
3799 tulip_addr_filter(sc); /* reset multicast filtering */
3807 * Set the interface MTU.
3809 if (ifr->ifr_mtu > ETHERMTU
3811 && sc->tulip_chipid != TULIP_21140
3812 && sc->tulip_chipid != TULIP_21140A
3813 && sc->tulip_chipid != TULIP_21041
3819 ifp->if_mtu = ifr->ifr_mtu;
3827 case SIOCGADDRROM: {
3828 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
3834 ifr->ifr_metric = (int) sc->tulip_chipid;
3847 tulip_ifstart(struct ifnet *ifp)
3849 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
3851 if (sc->tulip_if.if_flags & IFF_RUNNING) {
3853 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3854 tulip_txput_setup(sc);
3856 while (sc->tulip_if.if_snd.ifq_head != NULL) {
3859 ALTQ_LOCK(&sc->tulip_if.if_snd);
3860 IF_DEQUEUE(&sc->tulip_if.if_snd, m);
3861 ALTQ_UNLOCK(&sc->tulip_if.if_snd);
3863 if ((m = tulip_txput(sc, m)) != NULL) {
3864 ALTQ_LOCK(&sc->tulip_if.if_snd);
3865 IF_PREPEND(&sc->tulip_if.if_snd, m);
3866 ALTQ_UNLOCK(&sc->tulip_if.if_snd);
3874 tulip_ifwatchdog(struct ifnet *ifp)
3876 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
3878 sc->tulip_if.if_timer = 1;
3880 * These should be rare so do a bulk test up front so we can just skip
3883 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) {
3885 * If the number of receive buffer is low, try to refill
3887 if (sc->tulip_flags & TULIP_RXBUFSLOW)
3890 if (sc->tulip_flags & TULIP_SYSTEMERROR) {
3891 if_printf(ifp, "%d system errors: last was %s\n",
3892 sc->tulip_system_errors,
3893 tulip_system_errors[sc->tulip_last_system_error]);
3895 if (sc->tulip_statusbits) {
3896 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
3897 sc->tulip_statusbits = 0;
3900 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR);
3903 if (sc->tulip_txtimer)
3905 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
3906 if_printf(ifp, "transmission timeout\n");
3907 if (TULIP_DO_AUTOSENSE(sc)) {
3908 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
3909 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
3910 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP);
3918 tulip_attach(tulip_softc_t *sc)
3920 struct ifnet *ifp = &sc->tulip_if;
3922 callout_init(&sc->tulip_timer);
3923 callout_init(&sc->tulip_fast_timer);
3925 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
3926 ifp->if_ioctl = tulip_ifioctl;
3927 ifp->if_start = tulip_ifstart;
3928 ifp->if_watchdog = tulip_ifwatchdog;
3931 if_printf(ifp, "%s%s pass %d.%d%s\n",
3933 tulip_chipdescs[sc->tulip_chipid],
3934 (sc->tulip_revinfo & 0xF0) >> 4,
3935 sc->tulip_revinfo & 0x0F,
3936 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM))
3937 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "");
3939 (*sc->tulip_boardsw->bd_media_probe)(sc);
3940 ifmedia_init(&sc->tulip_ifmedia, 0,
3941 tulip_ifmedia_change,
3942 tulip_ifmedia_status);
3943 sc->tulip_flags &= ~TULIP_DEVICEPROBE;
3944 tulip_ifmedia_add(sc);
3948 ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr, NULL);
3949 ifp->if_snd.ifq_maxlen = ifqmaxlen;
3953 tulip_detach(tulip_softc_t *sc)
3955 ifmedia_removeall(&sc->tulip_ifmedia);
3956 ether_ifdetach(&sc->tulip_if);
3960 tulip_initcsrs(tulip_softc_t *sc, tulip_csrptr_t csr_base, size_t csr_size)
3962 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
3963 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
3964 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
3965 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
3966 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
3967 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
3968 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
3969 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
3970 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size;
3971 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size;
3972 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size;
3973 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size;
3974 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size;
3975 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size;
3976 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
3977 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
3981 tulip_initring(tulip_softc_t *sc, tulip_ringinfo_t *ri, tulip_desc_t *descs,
3984 ri->ri_max = ndescs;
3985 ri->ri_first = descs;
3986 ri->ri_last = ri->ri_first + ri->ri_max;
3987 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
3988 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
3992 * This is the PCI configuration support.
3995 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
3996 #define PCI_CBMA 0x14 /* Configuration Base Memory Address */
3997 #define PCI_CFDA 0x40 /* Configuration Driver Area */
4000 tulip_pci_probe(device_t dev)
4002 const char *name = NULL;
4004 if (pci_get_vendor(dev) != DEC_VENDORID)
4008 * Some LanMedia WAN cards use the Tulip chip, but they have
4009 * their own driver, and we should not recognize them
4011 if (pci_get_subvendor(dev) == 0x1376)
4014 switch (pci_get_device(dev)) {
4016 name = "Digital 21040 Ethernet";
4019 name = "Digital 21041 Ethernet";
4022 if (pci_get_revid(dev) >= 0x20)
4023 name = "Digital 21140A Fast Ethernet";
4025 name = "Digital 21140 Fast Ethernet";
4028 if (pci_get_revid(dev) >= 0x20)
4029 name = "Digital 21143 Fast Ethernet";
4031 name = "Digital 21142 Fast Ethernet";
4035 device_set_desc(dev, name);
4042 tulip_shutdown(device_t dev)
4044 tulip_softc_t *sc = device_get_softc(dev);
4046 lwkt_serialize_enter(sc->tulip_if.if_serializer);
4047 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4048 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
4049 33MHz that comes to two microseconds but wait a
4050 bit longer anyways) */
4051 lwkt_serialize_exit(sc->tulip_if.if_serializer);
4056 tulip_pci_attach(device_t dev)
4060 uint32_t revinfo, cfdainfo, cfcsinfo;
4061 u_int csroffset = TULIP_PCI_CSROFFSET;
4062 u_int csrsize = TULIP_PCI_CSRSIZE;
4063 tulip_csrptr_t csr_base;
4064 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
4065 struct resource *res;
4068 if (device_get_unit(dev) >= TULIP_MAX_DEVICES) {
4069 device_printf(dev, "not configured; limit of %d reached or exceeded\n",
4074 revinfo = pci_get_revid(dev);
4075 cfdainfo = pci_read_config(dev, PCI_CFDA, 4);
4076 cfcsinfo = pci_read_config(dev, PCIR_COMMAND, 4);
4078 /* turn busmaster on in case BIOS doesn't set it */
4079 pci_enable_busmaster(dev);
4081 if (pci_get_vendor(dev) == DEC_VENDORID) {
4082 if (pci_get_device(dev) == CHIPID_21040)
4083 chipid = TULIP_21040;
4084 else if (pci_get_device(dev) == CHIPID_21041)
4085 chipid = TULIP_21041;
4086 else if (pci_get_device(dev) == CHIPID_21140)
4087 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140;
4088 else if (pci_get_device(dev) == CHIPID_21142)
4089 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142;
4091 if (chipid == TULIP_CHIPID_UNKNOWN)
4094 if (chipid == TULIP_21040 && revinfo < 0x20) {
4095 device_printf(dev, "not configured; 21040 pass 2.0 required (%d.%d found)\n",
4096 revinfo >> 4, revinfo & 0x0f);
4098 } else if (chipid == TULIP_21140 && revinfo < 0x11) {
4099 device_printf(dev, "not configured; 21140 pass 1.1 required (%d.%d found)\n",
4100 revinfo >> 4, revinfo & 0x0f);
4104 sc = device_get_softc(dev);
4105 sc->tulip_dev = dev;
4106 sc->tulip_pci_busno = pci_get_bus(dev);
4107 sc->tulip_pci_devno = pci_get_slot(dev);
4108 sc->tulip_chipid = chipid;
4109 sc->tulip_flags |= TULIP_DEVICEPROBE;
4110 if (chipid == TULIP_21140 || chipid == TULIP_21140A)
4111 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD;
4112 if (chipid == TULIP_21140A && revinfo <= 0x22)
4113 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW;
4114 if (chipid == TULIP_21140)
4115 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH;
4116 if (chipid != TULIP_21040 && chipid != TULIP_21140)
4117 sc->tulip_features |= TULIP_HAVE_POWERMGMT;
4118 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) {
4119 sc->tulip_features |= TULIP_HAVE_DUALSENSE;
4120 if (chipid != TULIP_21041 || revinfo >= 0x20)
4121 sc->tulip_features |= TULIP_HAVE_SIANWAY;
4122 if (chipid != TULIP_21041)
4123 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD;
4124 if (chipid != TULIP_21041 && revinfo >= 0x20)
4125 sc->tulip_features |= TULIP_HAVE_SIA100;
4128 if (sc->tulip_features & TULIP_HAVE_POWERMGMT
4129 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) {
4130 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE);
4131 pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
4134 if_initname(&sc->tulip_if, device_get_name(dev), device_get_unit(dev));
4135 sc->tulip_revinfo = revinfo;
4136 sc->tulip_if.if_softc = sc;
4137 #if defined(TULIP_IOMAPPED)
4139 res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
4142 res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
4146 sc->tulip_csrs_bst = rman_get_bustag(res);
4147 sc->tulip_csrs_bsh = rman_get_bushandle(res);
4150 tulips[device_get_unit(dev)] = sc;
4152 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
4154 sc->tulip_rxdescs = kmalloc(sizeof(tulip_desc_t) * TULIP_RXDESCS,
4155 M_DEVBUF, M_INTWAIT);
4156 sc->tulip_txdescs = kmalloc(sizeof(tulip_desc_t) * TULIP_TXDESCS,
4157 M_DEVBUF, M_INTWAIT);
4159 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS);
4160 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS);
4163 * Make sure there won't be any interrupts or such...
4165 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4166 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
4167 33MHz that comes to two microseconds but wait a
4168 bit longer anyways) */
4170 if ((retval = tulip_read_macaddr(sc)) < 0) {
4171 device_printf(dev, "can't read ENET ROM (why=%d) (", retval);
4172 for (idx = 0; idx < 32; idx++)
4173 kprintf("%02x", sc->tulip_rombuf[idx]);
4175 device_printf(dev, "%s%s pass %d.%d\n",
4176 sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
4177 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
4178 device_printf(dev, "address unknown\n");
4180 void (*intr_rtn)(void *) = tulip_intr_normal;
4182 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
4183 intr_rtn = tulip_intr_shared;
4186 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) {
4190 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
4191 RF_SHAREABLE | RF_ACTIVE);
4192 if (res == 0 || bus_setup_intr(dev, res, INTR_MPSAFE,
4194 sc->tulip_if.if_serializer)) {
4195 device_printf(dev, "couldn't map interrupt\n");
4197 kfree((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
4198 kfree((caddr_t) sc->tulip_txdescs, M_DEVBUF);
4202 sc->tulip_if.if_cpuid = ithread_cpuid(rman_get_start(res));
4203 KKASSERT(sc->tulip_if.if_cpuid >= 0 &&
4204 sc->tulip_if.if_cpuid < ncpus);
4210 static device_method_t tulip_pci_methods[] = {
4211 /* Device interface */
4212 DEVMETHOD(device_probe, tulip_pci_probe),
4213 DEVMETHOD(device_attach, tulip_pci_attach),
4214 DEVMETHOD(device_shutdown, tulip_shutdown),
4217 static driver_t tulip_pci_driver = {
4220 sizeof(tulip_softc_t),
4222 static devclass_t tulip_devclass;
4224 DECLARE_DUMMY_MODULE(if_de);
4225 DRIVER_MODULE(if_de, pci, tulip_pci_driver, tulip_devclass, 0, 0);