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.47 2006/12/22 23:26:19 swildner 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>
59 #include <net/if_media.h>
60 #include <net/if_dl.h>
65 #include <netinet/in.h>
66 #include <netinet/if_ether.h>
70 #include <netproto/ipx/ipx.h>
71 #include <netproto/ipx/ipx_if.h>
75 #include <netproto/ns/ns.h>
76 #include <netproto/ns/ns_if.h>
81 #include <net/if_var.h>
83 #include <bus/pci/pcivar.h>
84 #include <bus/pci/pcireg.h>
85 #include <bus/pci/dc21040reg.h>
88 * Intel CPUs should use I/O mapped access.
91 #define TULIP_IOMAPPED
98 static tulip_softc_t *tulips[TULIP_MAX_DEVICES];
101 * This module supports
102 * the DEC 21040 PCI Ethernet Controller.
103 * the DEC 21041 PCI Ethernet Controller.
104 * the DEC 21140 PCI Fast Ethernet Controller.
106 static void tulip_mii_autonegotiate(tulip_softc_t *, u_int);
107 static void tulip_intr_shared(void *);
108 static void tulip_intr_normal(void *);
109 static void tulip_init(tulip_softc_t *);
110 static void tulip_reset(tulip_softc_t *);
111 static void tulip_ifstart(struct ifnet *);
112 static struct mbuf *tulip_txput(tulip_softc_t *, struct mbuf *);
113 static void tulip_txput_setup(tulip_softc_t *);
114 static void tulip_rx_intr(tulip_softc_t *);
115 static void tulip_addr_filter(tulip_softc_t *);
116 static u_int tulip_mii_readreg(tulip_softc_t *, u_int, u_int);
117 static void tulip_mii_writereg(tulip_softc_t *, u_int, u_int, u_int);
118 static int tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities);
119 static tulip_media_t tulip_mii_phy_readspecific(tulip_softc_t *);
120 static int tulip_srom_decode(tulip_softc_t *);
121 static int tulip_ifmedia_change(struct ifnet *);
122 static void tulip_ifmedia_status(struct ifnet *, struct ifmediareq *);
123 /* static void tulip_21140_map_media(tulip_softc_t *sc); */
126 tulip_timeout_callback(void *arg)
128 tulip_softc_t *sc = arg;
130 lwkt_serialize_enter(sc->tulip_if.if_serializer);
131 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING;
132 sc->tulip_probe_timeout -= 1000 / TULIP_HZ;
133 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER);
134 lwkt_serialize_exit(sc->tulip_if.if_serializer);
138 tulip_timeout(tulip_softc_t *sc)
140 if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
142 sc->tulip_flags |= TULIP_TIMEOUTPENDING;
143 callout_reset(&sc->tulip_timer, (hz + TULIP_HZ / 2) / TULIP_HZ,
144 tulip_timeout_callback, sc);
148 tulip_txprobe(tulip_softc_t *sc)
153 * Before we are sure this is the right media we need
154 * to send a small packet to make sure there's carrier.
155 * Strangely, BNC and AUI will "see" receive data if
156 * either is connected so the transmit is the only way
157 * to verify the connectivity.
159 MGETHDR(m, MB_DONTWAIT, MT_DATA);
163 * Construct a LLC TEST message which will point to ourselves.
165 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_dhost, 6);
166 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_shost, 6);
167 mtod(m, struct ether_header *)->ether_type = htons(3);
168 mtod(m, unsigned char *)[14] = 0;
169 mtod(m, unsigned char *)[15] = 0;
170 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
171 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
175 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
176 sc->tulip_intrmask |= TULIP_STS_TXINTR;
177 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
178 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
179 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
180 if ((m = tulip_txput(sc, m)) != NULL)
182 sc->tulip_probe.probe_txprobes++;
187 #define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0)
189 #define TULIP_SIAGEN_WATCHDOG 0
193 tulip_media_set(tulip_softc_t *sc, tulip_media_t media)
195 const tulip_media_info_t *mi = sc->tulip_mediums[media];
201 * If we are switching media, make sure we don't think there's
202 * any stale RX activity
204 sc->tulip_flags &= ~TULIP_RXACT;
205 if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
206 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
207 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx);
208 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
209 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
211 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
213 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
215 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity);
216 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
217 #define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL)
219 * If the cmdmode bits don't match the currently operating mode,
220 * set the cmdmode appropriately and reset the chip.
222 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
223 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
224 sc->tulip_cmdmode |= mi->mi_cmdmode;
227 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
229 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata);
230 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
232 * If the cmdmode bits don't match the currently operating mode,
233 * set the cmdmode appropriately and reset the chip.
235 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
236 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
237 sc->tulip_cmdmode |= mi->mi_cmdmode;
240 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol);
241 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata);
242 } else if (mi->mi_type == TULIP_MEDIAINFO_MII
243 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) {
245 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
247 dp = &sc->tulip_rombuf[mi->mi_reset_offset];
248 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) {
250 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
252 sc->tulip_phyaddr = mi->mi_phyaddr;
253 dp = &sc->tulip_rombuf[mi->mi_gpr_offset];
254 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) {
256 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
259 for (idx = 0; idx < mi->mi_reset_length; idx++) {
261 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]);
263 sc->tulip_phyaddr = mi->mi_phyaddr;
264 for (idx = 0; idx < mi->mi_gpr_length; idx++) {
266 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]);
269 if (sc->tulip_flags & TULIP_TRYNWAY) {
270 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
271 } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
272 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL);
273 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE);
274 sc->tulip_flags &= ~TULIP_DIDNWAY;
275 if (TULIP_IS_MEDIA_FD(media))
276 data |= PHYCTL_FULL_DUPLEX;
277 if (TULIP_IS_MEDIA_100MB(media))
278 data |= PHYCTL_SELECT_100MB;
279 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data);
285 tulip_linkup(tulip_softc_t *sc, tulip_media_t media)
287 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
288 sc->tulip_flags |= TULIP_PRINTLINKUP;
289 sc->tulip_flags |= TULIP_LINKUP;
290 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
291 #if 0 /* XXX how does with work with ifmedia? */
292 if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
293 if (sc->tulip_if.if_flags & IFF_FULLDUPLEX) {
294 if (TULIP_CAN_MEDIA_FD(media)
295 && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL)
296 media = TULIP_FD_MEDIA_OF(media);
298 if (TULIP_IS_MEDIA_FD(media)
299 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL)
300 media = TULIP_HD_MEDIA_OF(media);
304 if (sc->tulip_media != media) {
305 sc->tulip_media = media;
306 sc->tulip_flags |= TULIP_PRINTMEDIA;
307 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) {
308 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
309 } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) {
310 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
314 * We could set probe_timeout to 0 but setting to 3000 puts this
315 * in one central place and the only matters is tulip_link is
316 * followed by a tulip_timeout. Therefore setting it should not
317 * result in aberrant behavour.
319 sc->tulip_probe_timeout = 3000;
320 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
321 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY);
322 if (sc->tulip_flags & TULIP_INRESET) {
323 tulip_media_set(sc, sc->tulip_media);
324 } else if (sc->tulip_probe_media != sc->tulip_media) {
326 * No reason to change media if we have the right media.
334 tulip_media_print(tulip_softc_t *sc)
336 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
338 if (sc->tulip_flags & TULIP_PRINTMEDIA) {
339 if_printf(&sc->tulip_if, "enabling %s port\n",
340 tulip_mediums[sc->tulip_media]);
341 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
342 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
343 if_printf(&sc->tulip_if, "link up\n");
344 sc->tulip_flags &= ~TULIP_PRINTLINKUP;
348 #if defined(TULIP_DO_GPR_SENSE)
350 tulip_21140_gpr_media_sense(tulip_softc_t *sc)
352 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
353 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
357 * If one of the media blocks contained a default media flag,
360 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
361 const tulip_media_info_t *mi;
363 * Media is not supported (or is full-duplex).
365 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media))
367 if (mi->mi_type != TULIP_MEDIAINFO_GPR)
371 * Remember the media is this is the "default" media.
373 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
377 * No activity mask? Can't see if it is active if there's no mask.
379 if (mi->mi_actmask == 0)
383 * Does the activity data match?
385 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
389 * It does! If this is the first media we detected, then
390 * remember this media. If isn't the first, then there were
391 * multiple matches which we equate to no match (since we don't
392 * which to select (if any).
394 if (last_media == TULIP_MEDIA_UNKNOWN) {
396 } else if (last_media != media) {
397 last_media = TULIP_MEDIA_UNKNOWN;
400 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
402 #endif /* TULIP_DO_GPR_SENSE */
404 static tulip_link_status_t
405 tulip_media_link_monitor(tulip_softc_t *sc)
407 const tulip_media_info_t *mi = sc->tulip_mediums[sc->tulip_media];
408 tulip_link_status_t linkup = TULIP_LINK_DOWN;
411 #if defined(DIAGNOSTIC)
412 panic("tulip_media_link_monitor: %s: botch at line %d\n",
413 tulip_mediums[sc->tulip_media],__LINE__);
415 return TULIP_LINK_UNKNOWN;
420 * Have we seen some packets? If so, the link must be good.
422 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) {
423 sc->tulip_flags &= ~TULIP_RXACT;
424 sc->tulip_probe_timeout = 3000;
425 return TULIP_LINK_UP;
428 sc->tulip_flags &= ~TULIP_RXACT;
429 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
432 * Read the PHY status register.
434 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
435 if (status & PHYSTS_AUTONEG_DONE) {
437 * If the PHY has completed autonegotiation, see the if the
438 * remote systems abilities have changed. If so, upgrade or
439 * downgrade as appropriate.
441 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
442 abilities = (abilities << 6) & status;
443 if (abilities != sc->tulip_abilities) {
444 if (tulip_mii_map_abilities(sc, abilities)) {
445 tulip_linkup(sc, sc->tulip_probe_media);
446 return TULIP_LINK_UP;
449 * if we had selected media because of autonegotiation,
450 * we need to probe for the new media.
452 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
453 if (sc->tulip_flags & TULIP_DIDNWAY)
454 return TULIP_LINK_DOWN;
458 * The link is now up. If was down, say its back up.
460 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP)
461 linkup = TULIP_LINK_UP;
462 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
464 * No activity sensor? Assume all's well.
466 if (mi->mi_actmask == 0)
467 return TULIP_LINK_UNKNOWN;
469 * Does the activity data match?
471 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata)
472 linkup = TULIP_LINK_UP;
473 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
475 * Assume non TP ok for now.
477 if (!TULIP_IS_MEDIA_TP(sc->tulip_media))
478 return TULIP_LINK_UNKNOWN;
479 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
480 linkup = TULIP_LINK_UP;
481 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
482 return TULIP_LINK_UNKNOWN;
485 * We will wait for 3 seconds until the link goes into suspect mode.
487 if (sc->tulip_flags & TULIP_LINKUP) {
488 if (linkup == TULIP_LINK_UP)
489 sc->tulip_probe_timeout = 3000;
490 if (sc->tulip_probe_timeout > 0)
491 return TULIP_LINK_UP;
493 sc->tulip_flags &= ~TULIP_LINKUP;
494 if_printf(&sc->tulip_if, "link down: cable problem?\n");
496 return TULIP_LINK_DOWN;
500 tulip_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
502 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
503 && event == TULIP_MEDIAPOLL_TIMER) {
504 switch (tulip_media_link_monitor(sc)) {
505 case TULIP_LINK_DOWN: {
507 * Link Monitor failed. Probe for new media.
509 event = TULIP_MEDIAPOLL_LINKFAIL;
512 case TULIP_LINK_UP: {
519 case TULIP_LINK_UNKNOWN: {
521 * We can't tell so don't bother.
528 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
529 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
530 if (TULIP_DO_AUTOSENSE(sc)) {
531 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
532 if (sc->tulip_if.if_flags & IFF_UP)
533 tulip_reset(sc); /* restart probe */
539 if (event == TULIP_MEDIAPOLL_START) {
540 sc->tulip_if.if_flags |= IFF_OACTIVE;
541 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
543 sc->tulip_probe_mediamask = 0;
544 sc->tulip_probe_passes = 0;
546 * If the SROM contained an explicit media to use, use it.
548 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX);
549 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS;
550 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
552 * connidx is defaulted to a media_unknown type.
554 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media;
555 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) {
556 tulip_linkup(sc, sc->tulip_probe_media);
561 if (sc->tulip_features & TULIP_HAVE_GPR) {
562 sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
563 sc->tulip_probe_timeout = 2000;
565 sc->tulip_probe_media = TULIP_MEDIA_MAX;
566 sc->tulip_probe_timeout = 0;
567 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
572 * Ignore txprobe failures or spurious callbacks.
574 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED
575 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) {
576 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
581 * If we really transmitted a packet, then that's the media we'll use.
583 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) {
584 if (event == TULIP_MEDIAPOLL_LINKPASS) {
585 /* XXX Check media status just to be sure */
586 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
588 tulip_linkup(sc, sc->tulip_probe_media);
593 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) {
594 #if defined(TULIP_DO_GPR_SENSE)
596 * Check for media via the general purpose register.
598 * Try to sense the media via the GPR. If the same value
599 * occurs 3 times in a row then just use that.
601 if (sc->tulip_probe_timeout > 0) {
602 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
603 if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
604 if (new_probe_media == sc->tulip_probe_media) {
605 if (--sc->tulip_probe_count == 0)
606 tulip_linkup(sc, sc->tulip_probe_media);
608 sc->tulip_probe_count = 10;
611 sc->tulip_probe_media = new_probe_media;
615 #endif /* TULIP_DO_GPR_SENSE */
617 * Brute force. We cycle through each of the media types
618 * and try to transmit a packet.
620 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
621 sc->tulip_probe_media = TULIP_MEDIA_MAX;
622 sc->tulip_probe_timeout = 0;
627 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST
628 && (sc->tulip_features & TULIP_HAVE_MII)) {
629 tulip_media_t old_media = sc->tulip_probe_media;
630 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
631 switch (sc->tulip_probe_state) {
632 case TULIP_PROBE_FAILED:
633 case TULIP_PROBE_MEDIATEST: {
635 * Try the next media.
637 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask;
638 sc->tulip_probe_timeout = 0;
640 if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
642 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
644 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
648 case TULIP_PROBE_PHYAUTONEG: {
651 case TULIP_PROBE_INACTIVE: {
653 * Only probe if we autonegotiated a media that hasn't failed.
655 sc->tulip_probe_timeout = 0;
656 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) {
657 sc->tulip_probe_media = old_media;
660 tulip_linkup(sc, sc->tulip_probe_media);
665 #if defined(DIAGNOSTIC)
666 panic("tulip_media_poll: botch at line %d\n", __LINE__);
673 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
674 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
679 * switch to another media if we tried this one enough.
681 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
683 * Find the next media type to check for. Full Duplex
684 * types are not allowed.
687 sc->tulip_probe_media -= 1;
688 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
689 if (++sc->tulip_probe_passes == 3) {
690 if_printf(&sc->tulip_if, "autosense failed: cable problem?\n");
691 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
692 sc->tulip_if.if_flags &= ~IFF_RUNNING;
693 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
697 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */
698 sc->tulip_probe_mediamask = 0;
699 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1;
701 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL
702 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
703 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
705 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
706 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
707 sc->tulip_probe.probe_txprobes = 0;
709 tulip_media_set(sc, sc->tulip_probe_media);
710 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
715 * If this is hanging off a phy, we know are doing NWAY and we have
716 * forced the phy to a specific speed. Wait for link up before
717 * before sending a packet.
719 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) {
720 case TULIP_MEDIAINFO_MII: {
721 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
725 case TULIP_MEDIAINFO_SIA: {
726 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) {
727 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL)
729 tulip_linkup(sc, sc->tulip_probe_media);
731 if (sc->tulip_features & TULIP_HAVE_MII)
738 case TULIP_MEDIAINFO_RESET:
739 case TULIP_MEDIAINFO_SYM:
740 case TULIP_MEDIAINFO_NONE:
741 case TULIP_MEDIAINFO_GPR: {
746 * Try to send a packet.
752 tulip_media_select(tulip_softc_t *sc)
754 if (sc->tulip_features & TULIP_HAVE_GPR) {
755 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
757 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata);
760 * If this board has no media, just return
762 if (sc->tulip_features & TULIP_HAVE_NOMEDIA)
765 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
766 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
767 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START);
769 tulip_media_set(sc, sc->tulip_media);
774 tulip_21040_mediainfo_init(tulip_softc_t *sc, tulip_media_t media)
776 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
777 |TULIP_CMD_BACKOFFCTR;
778 sc->tulip_if.if_baudrate = 10000000;
780 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) {
781 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET);
782 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD);
783 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
786 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) {
787 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC);
790 if (media == TULIP_MEDIA_UNKNOWN) {
791 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA);
796 tulip_21040_media_probe(tulip_softc_t *sc)
798 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
802 tulip_21040_10baset_only_media_probe(tulip_softc_t *sc)
804 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
805 tulip_media_set(sc, TULIP_MEDIA_10BASET);
806 sc->tulip_media = TULIP_MEDIA_10BASET;
810 tulip_21040_10baset_only_media_select(tulip_softc_t *sc)
812 sc->tulip_flags |= TULIP_LINKUP;
813 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
814 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
815 sc->tulip_flags &= ~TULIP_SQETEST;
817 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
818 sc->tulip_flags |= TULIP_SQETEST;
820 tulip_media_set(sc, sc->tulip_media);
824 tulip_21040_auibnc_only_media_probe(tulip_softc_t *sc)
826 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
827 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
828 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
829 sc->tulip_media = TULIP_MEDIA_AUIBNC;
833 tulip_21040_auibnc_only_media_select(tulip_softc_t *sc)
835 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
836 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
839 static const tulip_boardsw_t tulip_21040_boardsw = {
841 tulip_21040_media_probe,
846 static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = {
848 tulip_21040_10baset_only_media_probe,
849 tulip_21040_10baset_only_media_select,
853 static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = {
855 tulip_21040_auibnc_only_media_probe,
856 tulip_21040_auibnc_only_media_select,
861 tulip_21041_mediainfo_init(tulip_softc_t *sc)
863 tulip_media_info_t *mi = sc->tulip_mediainfo;
866 if (sc->tulip_revinfo >= 0x20) {
867 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET);
868 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD);
869 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI);
870 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC);
874 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET);
875 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD);
876 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
877 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
881 tulip_21041_media_probe(tulip_softc_t *sc)
883 sc->tulip_if.if_baudrate = 10000000;
884 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
885 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
886 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
887 tulip_21041_mediainfo_init(sc);
891 tulip_21041_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
895 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
896 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
897 || !TULIP_DO_AUTOSENSE(sc))
899 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
900 tulip_reset(sc); /* start probe */
905 * If we've been been asked to start a poll or link change interrupt
906 * restart the probe (and reset the tulip to a known state).
908 if (event == TULIP_MEDIAPOLL_START) {
909 sc->tulip_if.if_flags |= IFF_OACTIVE;
910 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN);
912 if (sc->tulip_revinfo >= 0x20) {
913 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
914 sc->tulip_flags |= TULIP_DIDNWAY;
917 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
918 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
919 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
920 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT;
921 tulip_media_set(sc, TULIP_MEDIA_10BASET);
926 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
929 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
930 tulip_linkup(sc, sc->tulip_probe_media);
934 sia_status = TULIP_CSR_READ(sc, csr_sia_status);
935 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status);
936 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) {
937 if (sc->tulip_revinfo >= 0x20) {
938 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6)))
939 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
942 * If the link has passed LinkPass, 10baseT is the
943 * proper media to use.
945 tulip_linkup(sc, sc->tulip_probe_media);
950 * wait for up to 2.4 seconds for the link to reach pass state.
951 * Only then start scanning the other media for activity.
952 * choose media with receive activity over those without.
954 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) {
955 if (event != TULIP_MEDIAPOLL_TIMER)
957 if (sc->tulip_probe_timeout > 0
958 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
962 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
963 sc->tulip_flags |= TULIP_WANTRXACT;
964 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) {
965 sc->tulip_probe_media = TULIP_MEDIA_BNC;
967 sc->tulip_probe_media = TULIP_MEDIA_AUI;
969 tulip_media_set(sc, sc->tulip_probe_media);
975 * If we failed, clear the txprobe active flag.
977 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED)
978 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
981 if (event == TULIP_MEDIAPOLL_TIMER) {
983 * If we've received something, then that's our link!
985 if (sc->tulip_flags & TULIP_RXACT) {
986 tulip_linkup(sc, sc->tulip_probe_media);
990 * if no txprobe active
992 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0
993 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0
994 || (sia_status & TULIP_SIASTS_RXACTIVITY))) {
995 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1001 * Take 2 passes through before deciding to not
1002 * wait for receive activity. Then take another
1003 * two passes before spitting out a warning.
1005 if (sc->tulip_probe_timeout <= 0) {
1006 if (sc->tulip_flags & TULIP_WANTRXACT) {
1007 sc->tulip_flags &= ~TULIP_WANTRXACT;
1008 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1010 if_printf(&sc->tulip_if, "autosense failed: cable problem?\n");
1011 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
1012 sc->tulip_if.if_flags &= ~IFF_RUNNING;
1013 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1021 * Since this media failed to probe, try the other one.
1023 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1024 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) {
1025 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1027 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1029 tulip_media_set(sc, sc->tulip_probe_media);
1030 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1034 static const tulip_boardsw_t tulip_21041_boardsw = {
1035 TULIP_21041_GENERIC,
1036 tulip_21041_media_probe,
1038 tulip_21041_media_poll
1041 static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
1042 { 0x20005c00, 0, /* 08-00-17 */
1044 { 0x19, 0x0040, 0x0040 }, /* 10TX */
1045 { 0x19, 0x0040, 0x0000 }, /* 100TX */
1048 { 0x0281F400, 0, /* 00-A0-7D */
1050 { 0x12, 0x0010, 0x0000 }, /* 10T */
1052 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1053 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1057 { 0x0015F420, 0, /* 00-A0-7D */
1059 { 0x12, 0x0010, 0x0000 }, /* 10T */
1061 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1062 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1066 { 0x0281F400, 0, /* 00-A0-BE */
1068 { 0x11, 0x8000, 0x0000 }, /* 10T */
1069 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1071 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1077 static tulip_media_t
1078 tulip_mii_phy_readspecific(tulip_softc_t *sc)
1080 const tulip_phy_attr_t *attr;
1084 static const tulip_media_t table[] = {
1085 TULIP_MEDIA_UNKNOWN,
1086 TULIP_MEDIA_10BASET,
1087 TULIP_MEDIA_100BASETX,
1088 TULIP_MEDIA_100BASET4,
1089 TULIP_MEDIA_UNKNOWN,
1090 TULIP_MEDIA_10BASET_FD,
1091 TULIP_MEDIA_100BASETX_FD,
1096 * Don't read phy specific registers if link is not up.
1098 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
1099 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS))
1100 return TULIP_MEDIA_UNKNOWN;
1102 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) |
1103 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH);
1104 for (attr = tulip_mii_phy_attrlist;; attr++) {
1105 if (attr->attr_id == 0)
1106 return TULIP_MEDIA_UNKNOWN;
1107 if ((id & ~0x0F) == attr->attr_id)
1111 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
1112 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_100TX];
1113 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1114 if ((data & pm->pm_mask) == pm->pm_value)
1117 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) {
1118 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_100T4];
1119 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1120 if ((data & pm->pm_mask) == pm->pm_value)
1123 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) {
1124 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_10T];
1125 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1126 if ((data & pm->pm_mask) == pm->pm_value)
1129 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) {
1130 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
1131 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1132 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
1138 tulip_mii_get_phyaddr(tulip_softc_t *sc, u_int offset)
1142 for (phyaddr = 1; phyaddr < 32; phyaddr++) {
1143 u_int status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1144 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1151 u_int status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
1152 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1153 return TULIP_MII_NOPHY;
1156 return TULIP_MII_NOPHY;
1160 tulip_mii_map_abilities(tulip_softc_t *sc, u_int abilities)
1162 sc->tulip_abilities = abilities;
1163 if (abilities & PHYSTS_100BASETX_FD) {
1164 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD;
1165 } else if (abilities & PHYSTS_100BASET4) {
1166 sc->tulip_probe_media = TULIP_MEDIA_100BASET4;
1167 } else if (abilities & PHYSTS_100BASETX) {
1168 sc->tulip_probe_media = TULIP_MEDIA_100BASETX;
1169 } else if (abilities & PHYSTS_10BASET_FD) {
1170 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1171 } else if (abilities & PHYSTS_10BASET) {
1172 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1174 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1177 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1182 tulip_mii_autonegotiate(tulip_softc_t *sc, u_int phyaddr)
1184 switch (sc->tulip_probe_state) {
1185 case TULIP_PROBE_MEDIATEST:
1186 case TULIP_PROBE_INACTIVE: {
1187 sc->tulip_flags |= TULIP_DIDNWAY;
1188 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET);
1189 sc->tulip_probe_timeout = 3000;
1190 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR;
1191 sc->tulip_probe_state = TULIP_PROBE_PHYRESET;
1194 case TULIP_PROBE_PHYRESET: {
1196 uint32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1197 if (data & PHYCTL_RESET) {
1198 if (sc->tulip_probe_timeout > 0) {
1202 if_printf(&sc->tulip_if,
1203 "(phy%d): error: reset of PHY never completed!\n", phyaddr);
1204 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1205 sc->tulip_probe_state = TULIP_PROBE_FAILED;
1206 sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
1209 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1210 if ((status & PHYSTS_CAN_AUTONEG) == 0) {
1211 sc->tulip_flags &= ~TULIP_DIDNWAY;
1212 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1215 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01))
1216 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
1217 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
1218 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1219 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
1220 sc->tulip_probe_timeout = 3000;
1223 case TULIP_PROBE_PHYAUTONEG: {
1224 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1226 if ((status & PHYSTS_AUTONEG_DONE) == 0) {
1227 if (sc->tulip_probe_timeout > 0) {
1231 sc->tulip_flags &= ~TULIP_DIDNWAY;
1232 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1235 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
1236 data = (data << 6) & status;
1237 if (!tulip_mii_map_abilities(sc, data))
1238 sc->tulip_flags &= ~TULIP_DIDNWAY;
1242 #if defined(DIAGNOSTIC)
1243 panic("tulip_media_poll: botch at line %d\n", __LINE__);
1251 tulip_2114x_media_preset(tulip_softc_t *sc)
1253 const tulip_media_info_t *mi = NULL;
1254 tulip_media_t media = sc->tulip_media;
1256 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1257 media = sc->tulip_media;
1259 media = sc->tulip_probe_media;
1261 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
1262 sc->tulip_flags &= ~TULIP_SQETEST;
1263 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
1264 mi = sc->tulip_mediums[media];
1265 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
1266 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1267 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR
1268 || mi->mi_type == TULIP_MEDIAINFO_SYM) {
1269 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
1270 sc->tulip_cmdmode |= mi->mi_cmdmode;
1271 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
1272 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
1276 case TULIP_MEDIA_BNC:
1277 case TULIP_MEDIA_AUI:
1278 case TULIP_MEDIA_10BASET: {
1279 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1280 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
1281 sc->tulip_if.if_baudrate = 10000000;
1282 sc->tulip_flags |= TULIP_SQETEST;
1285 case TULIP_MEDIA_10BASET_FD: {
1286 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
1287 sc->tulip_if.if_baudrate = 10000000;
1290 case TULIP_MEDIA_100BASEFX:
1291 case TULIP_MEDIA_100BASET4:
1292 case TULIP_MEDIA_100BASETX: {
1293 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL);
1294 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1295 sc->tulip_if.if_baudrate = 100000000;
1298 case TULIP_MEDIA_100BASEFX_FD:
1299 case TULIP_MEDIA_100BASETX_FD: {
1300 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT;
1301 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
1302 sc->tulip_if.if_baudrate = 100000000;
1309 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1313 ********************************************************************
1314 * Start of 21140/21140A support which does not use the MII interface
1318 tulip_null_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
1320 #if defined(DIAGNOSTIC)
1321 if_printf(&sc->tulip_if, "botch(media_poll) at line %d\n", __LINE__);
1326 tulip_21140_mediainit(tulip_softc_t *sc, tulip_media_info_t *mip,
1327 tulip_media_t media, u_int gpdata, u_int cmdmode)
1329 sc->tulip_mediums[media] = mip;
1330 mip->mi_type = TULIP_MEDIAINFO_GPR;
1331 mip->mi_cmdmode = cmdmode;
1332 mip->mi_gpdata = gpdata;
1336 tulip_21140_evalboard_media_probe(tulip_softc_t *sc)
1338 tulip_media_info_t *mip = sc->tulip_mediainfo;
1340 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1341 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1342 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1343 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1344 TULIP_CSR_WRITE(sc, csr_command,
1345 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1346 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1347 TULIP_CSR_WRITE(sc, csr_command,
1348 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1350 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
1351 sc->tulip_media = TULIP_MEDIA_10BASET;
1353 sc->tulip_media = TULIP_MEDIA_100BASETX;
1355 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1357 TULIP_CMD_TXTHRSHLDCTL);
1358 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1360 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1361 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1363 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1364 |TULIP_CMD_SCRAMBLER);
1365 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1367 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1368 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1371 static const tulip_boardsw_t tulip_21140_eb_boardsw = {
1373 tulip_21140_evalboard_media_probe,
1375 tulip_null_media_poll,
1376 tulip_2114x_media_preset,
1380 tulip_21140_accton_media_probe(tulip_softc_t *sc)
1382 tulip_media_info_t *mip = sc->tulip_mediainfo;
1385 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1386 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1387 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1388 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1389 TULIP_CSR_WRITE(sc, csr_command,
1390 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1391 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1392 TULIP_CSR_WRITE(sc, csr_command,
1393 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1395 gpdata = TULIP_CSR_READ(sc, csr_gp);
1396 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) {
1397 sc->tulip_media = TULIP_MEDIA_10BASET;
1399 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) {
1400 sc->tulip_media = TULIP_MEDIA_BNC;
1402 sc->tulip_media = TULIP_MEDIA_100BASETX;
1405 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC,
1406 TULIP_GP_EN1207_BNC_INIT,
1407 TULIP_CMD_TXTHRSHLDCTL);
1408 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1409 TULIP_GP_EN1207_UTP_INIT,
1410 TULIP_CMD_TXTHRSHLDCTL);
1411 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1412 TULIP_GP_EN1207_UTP_INIT,
1413 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1414 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1415 TULIP_GP_EN1207_100_INIT,
1416 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1417 |TULIP_CMD_SCRAMBLER);
1418 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1419 TULIP_GP_EN1207_100_INIT,
1420 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1421 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1424 static const tulip_boardsw_t tulip_21140_accton_boardsw = {
1426 tulip_21140_accton_media_probe,
1428 tulip_null_media_poll,
1429 tulip_2114x_media_preset,
1433 tulip_21140_smc9332_media_probe(tulip_softc_t *sc)
1435 tulip_media_info_t *mip = sc->tulip_mediainfo;
1438 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE);
1439 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
1440 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
1441 33MHz that comes to two microseconds but wait a
1442 bit longer anyways) */
1443 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT |
1444 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1445 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS;
1446 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT;
1447 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET);
1448 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT);
1450 for (idx = 1000; idx > 0; idx--) {
1451 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1452 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) {
1455 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
1462 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1463 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1464 TULIP_GP_SMC_9332_INIT,
1465 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1466 |TULIP_CMD_SCRAMBLER);
1467 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1468 TULIP_GP_SMC_9332_INIT,
1469 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1470 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1471 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1472 TULIP_GP_SMC_9332_INIT,
1473 TULIP_CMD_TXTHRSHLDCTL);
1474 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1475 TULIP_GP_SMC_9332_INIT,
1476 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1479 static const tulip_boardsw_t tulip_21140_smc9332_boardsw = {
1480 TULIP_21140_SMC_9332,
1481 tulip_21140_smc9332_media_probe,
1483 tulip_null_media_poll,
1484 tulip_2114x_media_preset,
1488 tulip_21140_cogent_em100_media_probe(tulip_softc_t *sc)
1490 tulip_media_info_t *mip = sc->tulip_mediainfo;
1491 uint32_t cmdmode = TULIP_CSR_READ(sc, csr_command);
1493 sc->tulip_gpinit = TULIP_GP_EM100_PINS;
1494 sc->tulip_gpdata = TULIP_GP_EM100_INIT;
1495 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS);
1496 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT);
1498 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE;
1499 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER);
1500 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1501 TULIP_CSR_WRITE(sc, csr_command, cmdmode);
1502 sc->tulip_media = TULIP_MEDIA_100BASEFX;
1504 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX,
1505 TULIP_GP_EM100_INIT,
1506 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION);
1507 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD,
1508 TULIP_GP_EM100_INIT,
1509 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1510 |TULIP_CMD_FULLDUPLEX);
1512 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);
1513 sc->tulip_media = TULIP_MEDIA_100BASETX;
1514 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1515 TULIP_GP_EM100_INIT,
1516 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1517 |TULIP_CMD_SCRAMBLER);
1518 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1519 TULIP_GP_EM100_INIT,
1520 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1521 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1525 static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {
1526 TULIP_21140_COGENT_EM100,
1527 tulip_21140_cogent_em100_media_probe,
1529 tulip_null_media_poll,
1530 tulip_2114x_media_preset
1534 tulip_21140_znyx_zx34x_media_probe(tulip_softc_t *sc)
1536 tulip_media_info_t *mip = sc->tulip_mediainfo;
1537 int cnt10 = 0, cnt100 = 0, idx;
1539 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS;
1540 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT;
1541 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS);
1542 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT);
1543 TULIP_CSR_WRITE(sc, csr_command,
1544 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1545 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1546 TULIP_CSR_WRITE(sc, csr_command,
1547 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1550 for (idx = 1000; idx > 0; idx--) {
1551 uint32_t csr = TULIP_CSR_READ(sc, csr_gp);
1552 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)) {
1555 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
1564 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1565 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1566 TULIP_GP_ZX34X_INIT,
1567 TULIP_CMD_TXTHRSHLDCTL);
1568 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1569 TULIP_GP_ZX34X_INIT,
1570 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1571 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1572 TULIP_GP_ZX34X_INIT,
1573 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1574 |TULIP_CMD_SCRAMBLER);
1575 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1576 TULIP_GP_ZX34X_INIT,
1577 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1578 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1581 static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = {
1582 TULIP_21140_ZNYX_ZX34X,
1583 tulip_21140_znyx_zx34x_media_probe,
1585 tulip_null_media_poll,
1586 tulip_2114x_media_preset,
1590 tulip_2114x_media_probe(tulip_softc_t *sc)
1592 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE | TULIP_CMD_BACKOFFCTR |
1593 TULIP_CMD_THRSHLD72;
1596 static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
1598 tulip_2114x_media_probe,
1601 tulip_2114x_media_preset,
1605 * ******** END of chip-specific handlers. ***********
1609 * Code the read the SROM and MII bit streams (I2C)
1612 TULIP_CSR_WRITE(sc, csr_srom_mii, csr); \
1617 tulip_srom_idle(tulip_softc_t *sc)
1621 csr = SROMSEL ; EMIT;
1622 csr = SROMSEL | SROMRD; EMIT;
1623 csr ^= SROMCS; EMIT;
1624 csr ^= SROMCLKON; EMIT;
1627 * Write 25 cycles of 0 which will force the SROM to be idle.
1629 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1630 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1631 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1633 csr ^= SROMCLKOFF; EMIT;
1634 csr ^= SROMCS; EMIT;
1640 tulip_srom_read(tulip_softc_t *sc)
1642 const u_int bitwidth = SROM_BITWIDTH;
1643 const u_int cmdmask = (SROMCMD_RD << bitwidth);
1644 const u_int msb = 1 << (bitwidth + 3 - 1);
1645 u_int idx, lastidx = (1 << bitwidth) - 1;
1647 tulip_srom_idle(sc);
1649 for (idx = 0; idx <= lastidx; idx++) {
1650 u_int lastbit, data, bits, bit, csr;
1651 csr = SROMSEL ; EMIT;
1652 csr = SROMSEL | SROMRD; EMIT;
1653 csr ^= SROMCSON; EMIT;
1654 csr ^= SROMCLKON; EMIT;
1657 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
1658 u_int thisbit = bits & msb;
1659 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1660 if (thisbit != lastbit) {
1661 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1665 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1668 csr ^= SROMCLKOFF; EMIT;
1670 for (data = 0, bits = 0; bits < 16; bits++) {
1672 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1673 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1674 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1676 sc->tulip_rombuf[idx*2] = data & 0xFF;
1677 sc->tulip_rombuf[idx*2+1] = data >> 8;
1678 csr = SROMSEL | SROMRD; EMIT;
1681 tulip_srom_idle(sc);
1684 #define MII_EMIT do { \
1685 TULIP_CSR_WRITE(sc, csr_srom_mii, csr); \
1690 tulip_mii_writebits(tulip_softc_t *sc, u_int data, u_int bits)
1692 u_int csr, msb, lastbit;
1694 msb = 1 << (bits - 1);
1695 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1696 lastbit = (csr & MII_DOUT) ? msb : 0;
1697 csr |= MII_WR; MII_EMIT; /* clock low; assert write */
1699 for (; bits > 0; bits--, data <<= 1) {
1700 const unsigned thisbit = data & msb;
1701 if (thisbit != lastbit) {
1702 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */
1704 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1706 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1711 tulip_mii_turnaround(tulip_softc_t *sc, u_int cmd)
1715 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1717 if (cmd == MII_WRCMD) {
1718 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
1719 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1720 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1721 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */
1723 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */
1725 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1726 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1730 tulip_mii_readbits(tulip_softc_t *sc)
1732 u_int csr, data, idx;
1734 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1736 for (idx = 0, data = 0; idx < 16; idx++) {
1737 data <<= 1; /* this is NOOP on the first pass through */
1738 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1739 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)
1741 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1743 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
1749 tulip_mii_readreg(tulip_softc_t *sc, u_int devaddr, u_int regno)
1754 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1755 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1756 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1757 tulip_mii_writebits(sc, MII_RDCMD, 8);
1758 tulip_mii_writebits(sc, devaddr, 5);
1759 tulip_mii_writebits(sc, regno, 5);
1760 tulip_mii_turnaround(sc, MII_RDCMD);
1762 data = tulip_mii_readbits(sc);
1767 tulip_mii_writereg(tulip_softc_t *sc, u_int devaddr, u_int regno, u_int data)
1771 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1772 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1773 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1774 tulip_mii_writebits(sc, MII_WRCMD, 8);
1775 tulip_mii_writebits(sc, devaddr, 5);
1776 tulip_mii_writebits(sc, regno, 5);
1777 tulip_mii_turnaround(sc, MII_WRCMD);
1778 tulip_mii_writebits(sc, data, 16);
1781 #define tulip_mchash(mca) (ether_crc32_le(mca, 6) & 0x1FF)
1782 #define tulip_srom_crcok(databuf) ( \
1783 ((ether_crc32_le(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
1784 ((databuf)[126] | ((databuf)[127] << 8)))
1787 tulip_identify_dec_nic(tulip_softc_t *sc)
1789 strcpy(sc->tulip_boardid, "DEC ");
1791 if (sc->tulip_chipid <= TULIP_21040)
1793 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0
1794 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {
1795 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);
1796 sc->tulip_boardid[D0+8] = ' ';
1802 tulip_identify_znyx_nic(tulip_softc_t * const sc)
1805 strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
1806 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
1808 sc->tulip_boardid[8] = '4';
1809 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
1810 if (znyx_ptr < 26 || znyx_ptr > 116) {
1811 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1814 /* ZX344 = 0010 .. 0013FF
1816 if (sc->tulip_rombuf[znyx_ptr] == 0x4A
1817 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52
1818 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) {
1819 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4];
1820 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) {
1821 sc->tulip_boardid[9] = '2';
1822 if (id == TULIP_ZNYX_ID_ZX342B) {
1823 sc->tulip_boardid[10] = 'B';
1824 sc->tulip_boardid[11] = ' ';
1826 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1827 } else if (id == TULIP_ZNYX_ID_ZX344) {
1828 sc->tulip_boardid[10] = '4';
1829 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1830 } else if (id == TULIP_ZNYX_ID_ZX345) {
1831 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5';
1832 } else if (id == TULIP_ZNYX_ID_ZX346) {
1833 sc->tulip_boardid[9] = '6';
1834 } else if (id == TULIP_ZNYX_ID_ZX351) {
1835 sc->tulip_boardid[8] = '5';
1836 sc->tulip_boardid[9] = '1';
1841 * Assume it's a ZX342...
1843 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1847 sc->tulip_boardid[8] = '1';
1848 if (sc->tulip_chipid == TULIP_21041) {
1849 sc->tulip_boardid[10] = '1';
1852 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) {
1853 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36];
1854 if (id == TULIP_ZNYX_ID_ZX312T) {
1855 sc->tulip_boardid[9] = '2';
1856 sc->tulip_boardid[10] = 'T';
1857 sc->tulip_boardid[11] = ' ';
1858 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1859 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) {
1860 sc->tulip_boardid[9] = '4';
1861 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1862 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1863 } else if (id == TULIP_ZNYX_ID_ZX314) {
1864 sc->tulip_boardid[9] = '4';
1865 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1866 sc->tulip_features |= TULIP_HAVE_BASEROM;
1867 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) {
1868 sc->tulip_boardid[9] = '5';
1869 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1870 } else if (id == TULIP_ZNYX_ID_ZX315) {
1871 sc->tulip_boardid[9] = '5';
1872 sc->tulip_features |= TULIP_HAVE_BASEROM;
1878 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) {
1879 sc->tulip_boardid[9] = '4';
1880 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1881 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1882 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) {
1883 sc->tulip_boardid[9] = '5';
1884 sc->tulip_boardsw = &tulip_21040_boardsw;
1885 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1886 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) {
1887 sc->tulip_boardid[9] = '2';
1888 sc->tulip_boardsw = &tulip_21040_boardsw;
1894 tulip_identify_smc_nic(tulip_softc_t * const sc)
1896 uint32_t id1, id2, ei;
1897 int auibnc = 0, utp = 0;
1900 strcpy(sc->tulip_boardid, "SMC ");
1901 if (sc->tulip_chipid == TULIP_21041)
1903 if (sc->tulip_chipid != TULIP_21040) {
1904 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
1905 strcpy(&sc->tulip_boardid[4], "9332DST ");
1906 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;
1907 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {
1908 strcpy(&sc->tulip_boardid[4], "9334BDT ");
1910 strcpy(&sc->tulip_boardid[4], "9332BDT ");
1914 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);
1915 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);
1916 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);
1918 strcpy(&sc->tulip_boardid[4], "8432");
1919 cp = &sc->tulip_boardid[8];
1921 *cp++ = 'B', auibnc = 1;
1922 if ((id1 & 0xFF) > 0x32)
1923 *cp++ = 'T', utp = 1;
1924 if ((id1 & 0x4000) == 0)
1925 *cp++ = 'A', auibnc = 1;
1927 sc->tulip_boardid[7] = '4';
1931 *cp++ = (ei ? '2' : '1');
1936 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1937 else if (!utp && auibnc)
1938 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
1942 tulip_identify_cogent_nic(tulip_softc_t * const sc)
1944 strcpy(sc->tulip_boardid, "Cogent ");
1945 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
1946 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {
1947 strcat(sc->tulip_boardid, "EM100TX ");
1948 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1949 #if defined(TULIP_COGENT_EM110TX_ID)
1950 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {
1951 strcat(sc->tulip_boardid, "EM110TX ");
1952 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1954 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1955 strcat(sc->tulip_boardid, "EM100FX ");
1956 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1959 * Magic number (0x24001109U) is the SubVendor (0x2400) and
1960 * SubDevId (0x1109) for the ANA6944TX (EM440TX).
1962 if (*(uint32_t *) sc->tulip_rombuf == 0x24001109U
1963 && (sc->tulip_features & TULIP_HAVE_BASEROM)) {
1965 * Cogent (Adaptec) is still mapping all INTs to INTA of
1966 * first 21140. Dumb! Dumb!
1968 strcat(sc->tulip_boardid, "EM440TX ");
1969 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
1971 } else if (sc->tulip_chipid == TULIP_21040) {
1972 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1977 tulip_identify_accton_nic(tulip_softc_t * const sc)
1979 strcpy(sc->tulip_boardid, "ACCTON ");
1980 switch (sc->tulip_chipid) {
1982 strcat(sc->tulip_boardid, "EN1207 ");
1983 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
1984 sc->tulip_boardsw = &tulip_21140_accton_boardsw;
1987 strcat(sc->tulip_boardid, "EN1207TX ");
1988 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
1989 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
1992 strcat(sc->tulip_boardid, "EN1203 ");
1993 sc->tulip_boardsw = &tulip_21040_boardsw;
1996 strcat(sc->tulip_boardid, "EN1203 ");
1997 sc->tulip_boardsw = &tulip_21041_boardsw;
2000 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2006 tulip_identify_asante_nic(tulip_softc_t * const sc)
2008 strcpy(sc->tulip_boardid, "Asante ");
2009 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
2010 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2011 tulip_media_info_t *mi = sc->tulip_mediainfo;
2014 * The Asante Fast Ethernet doesn't always ship with a valid
2015 * new format SROM. So if isn't in the new format, we cheat
2016 * set it up as if we had.
2019 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;
2020 sc->tulip_gpdata = 0;
2022 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);
2023 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);
2025 TULIP_CSR_WRITE(sc, csr_gp, 0);
2027 mi->mi_type = TULIP_MEDIAINFO_MII;
2028 mi->mi_gpr_length = 0;
2029 mi->mi_gpr_offset = 0;
2030 mi->mi_reset_length = 0;
2031 mi->mi_reset_offset = 0;
2033 mi->mi_phyaddr = TULIP_MII_NOPHY;
2034 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) {
2036 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
2038 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2039 if_printf(&sc->tulip_if, "can't find phy 0\n");
2043 sc->tulip_features |= TULIP_HAVE_MII;
2044 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2045 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2046 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD;
2047 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD;
2048 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2049 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2050 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2051 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2052 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2053 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2054 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2056 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2061 tulip_identify_compex_nic(tulip_softc_t *sc)
2063 strcpy(sc->tulip_boardid, "COMPEX ");
2064 if (sc->tulip_chipid == TULIP_21140A) {
2066 tulip_softc_t *root_sc = NULL;
2068 strcat(sc->tulip_boardid, "400TX/PCI ");
2070 * All 4 chips on these boards share an interrupt. This code
2071 * copied from tulip_read_macaddr.
2073 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2074 for (root_unit = device_get_unit(sc->tulip_dev) - 1; root_unit >= 0; root_unit--) {
2075 root_sc = tulips[root_unit];
2077 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
2082 && root_sc->tulip_chipid == sc->tulip_chipid
2083 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2084 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2085 sc->tulip_slaves = root_sc->tulip_slaves;
2086 root_sc->tulip_slaves = sc;
2087 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
2088 if_printf(&sc->tulip_if, "can't find master device for interrupts");
2091 strcat(sc->tulip_boardid, "unknown ");
2093 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */
2098 tulip_srom_decode(tulip_softc_t *sc)
2100 u_int idx1, idx2, idx3;
2102 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
2103 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
2104 tulip_srom_media_t srom_media;
2105 tulip_media_info_t *mi = sc->tulip_mediainfo;
2107 uint32_t leaf_offset, blocks, data;
2109 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
2110 if (shp->sh_adapter_count == 1)
2112 if (saip->sai_device == sc->tulip_pci_devno)
2116 * Didn't find the right media block for this card.
2118 if (idx1 == shp->sh_adapter_count)
2122 * Save the hardware address.
2124 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6);
2126 * If this is a multiple port card, add the adapter index to the last
2127 * byte of the hardware address. (if it isn't multiport, adding 0
2130 sc->tulip_enaddr[5] += idx1;
2132 leaf_offset = saip->sai_leaf_offset_lowbyte
2133 + saip->sai_leaf_offset_highbyte * 256;
2134 dp = sc->tulip_rombuf + leaf_offset;
2136 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2;
2138 for (idx2 = 0;; idx2++) {
2139 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype
2140 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED)
2143 sc->tulip_connidx = idx2;
2145 if (sc->tulip_chipid == TULIP_21041) {
2147 for (idx2 = 0; idx2 < blocks; idx2++) {
2148 tulip_media_t media;
2150 srom_media = (tulip_srom_media_t) (data & 0x3F);
2151 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2152 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2155 media = tulip_srom_mediums[idx3].sm_type;
2156 if (media != TULIP_MEDIA_UNKNOWN) {
2157 if (data & TULIP_SROM_21041_EXTENDED) {
2158 mi->mi_type = TULIP_MEDIAINFO_SIA;
2159 sc->tulip_mediums[media] = mi;
2160 mi->mi_sia_connectivity = dp[0] + dp[1] * 256;
2161 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256;
2162 mi->mi_sia_general = dp[4] + dp[5] * 256;
2166 case TULIP_MEDIA_BNC: {
2167 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
2171 case TULIP_MEDIA_AUI: {
2172 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
2176 case TULIP_MEDIA_10BASET: {
2177 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
2181 case TULIP_MEDIA_10BASET_FD: {
2182 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
2192 if (data & TULIP_SROM_21041_EXTENDED)
2197 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++;
2198 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++;
2199 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++;
2200 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++;
2204 unsigned length, type;
2205 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN;
2206 if (sc->tulip_features & TULIP_HAVE_GPR)
2207 sc->tulip_gpinit = *dp++;
2209 for (idx2 = 0; idx2 < blocks; idx2++) {
2211 if ((*dp & 0x80) == 0) {
2215 length = (*dp++ & 0x7f) - 1;
2216 type = *dp++ & 0x3f;
2219 switch (type & 0x3f) {
2220 case 0: { /* 21140[A] GPR block */
2221 tulip_media_t media;
2222 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2223 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2224 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2227 media = tulip_srom_mediums[idx3].sm_type;
2228 if (media == TULIP_MEDIA_UNKNOWN)
2230 mi->mi_type = TULIP_MEDIAINFO_GPR;
2231 sc->tulip_mediums[media] = mi;
2232 mi->mi_gpdata = dp[1];
2233 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) {
2234 sc->tulip_gpdata = mi->mi_gpdata;
2237 data = dp[2] + dp[3] * 256;
2238 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2239 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2243 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2245 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2246 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2251 case 1: { /* 21140[A] MII block */
2252 const u_int phyno = *dp++;
2253 mi->mi_type = TULIP_MEDIAINFO_MII;
2254 mi->mi_gpr_length = *dp++;
2255 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2256 dp += mi->mi_gpr_length;
2257 mi->mi_reset_length = *dp++;
2258 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2259 dp += mi->mi_reset_length;
2262 * Before we probe for a PHY, use the GPR information
2263 * to select it. If we don't, it may be inaccessible.
2265 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET);
2266 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) {
2268 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]);
2270 sc->tulip_phyaddr = mi->mi_phyaddr;
2271 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) {
2273 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]);
2277 * At least write something!
2279 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2280 TULIP_CSR_WRITE(sc, csr_gp, 0);
2282 mi->mi_phyaddr = TULIP_MII_NOPHY;
2283 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2285 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2287 if (mi->mi_phyaddr == TULIP_MII_NOPHY)
2289 sc->tulip_features |= TULIP_HAVE_MII;
2290 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2291 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2292 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2293 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2294 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2295 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2296 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2297 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2298 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2299 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2300 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2304 case 2: { /* 2114[23] SIA block */
2305 tulip_media_t media;
2306 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2307 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2308 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2311 media = tulip_srom_mediums[idx3].sm_type;
2312 if (media == TULIP_MEDIA_UNKNOWN)
2314 mi->mi_type = TULIP_MEDIAINFO_SIA;
2315 sc->tulip_mediums[media] = mi;
2317 mi->mi_sia_connectivity = dp[1] + dp[2] * 256;
2318 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256;
2319 mi->mi_sia_general = dp[5] + dp[6] * 256;
2323 case TULIP_MEDIA_BNC: {
2324 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
2327 case TULIP_MEDIA_AUI: {
2328 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
2331 case TULIP_MEDIA_10BASET: {
2332 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
2333 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2336 case TULIP_MEDIA_10BASET_FD: {
2337 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
2338 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2346 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16;
2347 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16;
2352 case 3: { /* 2114[23] MII PHY block */
2353 const u_int phyno = *dp++;
2355 mi->mi_type = TULIP_MEDIAINFO_MII;
2356 mi->mi_gpr_length = *dp++;
2357 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2358 dp += 2 * mi->mi_gpr_length;
2359 mi->mi_reset_length = *dp++;
2360 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2361 dp += 2 * mi->mi_reset_length;
2363 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset];
2364 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) {
2366 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2368 sc->tulip_phyaddr = mi->mi_phyaddr;
2369 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset];
2370 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) {
2372 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2375 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2376 TULIP_CSR_WRITE(sc, csr_sia_general, 0);
2378 mi->mi_phyaddr = TULIP_MII_NOPHY;
2379 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2381 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2383 if (mi->mi_phyaddr == TULIP_MII_NOPHY)
2385 sc->tulip_features |= TULIP_HAVE_MII;
2386 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2387 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2388 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2389 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2390 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2;
2391 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2392 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2393 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2394 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2395 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2396 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2397 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2401 case 4: { /* 21143 SYM block */
2402 tulip_media_t media;
2403 srom_media = (tulip_srom_media_t) dp[0];
2404 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2405 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2408 media = tulip_srom_mediums[idx3].sm_type;
2409 if (media == TULIP_MEDIA_UNKNOWN)
2411 mi->mi_type = TULIP_MEDIAINFO_SYM;
2412 sc->tulip_mediums[media] = mi;
2413 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16;
2414 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16;
2415 data = dp[5] + dp[6] * 256;
2416 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2417 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2420 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2421 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2422 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2424 if (TULIP_IS_MEDIA_TP(media))
2425 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2430 case 5: { /* 21143 Reset block */
2431 mi->mi_type = TULIP_MEDIAINFO_RESET;
2432 mi->mi_reset_length = *dp++;
2433 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2434 dp += 2 * mi->mi_reset_length;
2445 return mi - sc->tulip_mediainfo;
2448 static const struct {
2449 void (*vendor_identify_nic)(tulip_softc_t * const sc);
2450 unsigned char vendor_oui[3];
2451 } tulip_vendors[] = {
2452 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } },
2453 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } },
2454 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } },
2455 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } },
2456 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } },
2457 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } },
2458 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } },
2459 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } },
2460 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } },
2461 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } },
2466 * This deals with the vagaries of the address roms and the
2467 * brain-deadness that various vendors commit in using them.
2470 tulip_read_macaddr(tulip_softc_t *sc)
2472 u_int cksum, rom_cksum, idx;
2474 unsigned char tmpbuf[8];
2475 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
2477 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX;
2479 if (sc->tulip_chipid == TULIP_21040) {
2480 TULIP_CSR_WRITE(sc, csr_enetrom, 1);
2481 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2483 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
2485 sc->tulip_rombuf[idx] = csr & 0xFF;
2487 sc->tulip_boardsw = &tulip_21040_boardsw;
2489 if (sc->tulip_chipid == TULIP_21041) {
2491 * Thankfully all 21041's act the same.
2493 sc->tulip_boardsw = &tulip_21041_boardsw;
2496 * Assume all 21140 board are compatible with the
2497 * DEC 10/100 evaluation board. Not really valid but
2498 * it's the best we can do until every one switches to
2499 * the new SROM format.
2502 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2504 tulip_srom_read(sc);
2505 if (tulip_srom_crcok(sc->tulip_rombuf)) {
2507 * SROM CRC is valid therefore it must be in the
2510 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM;
2511 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
2513 * No checksum is present. See if the SROM id checks out;
2514 * the first 18 bytes should be 0 followed by a 1 followed
2515 * by the number of adapters (which we don't deal with yet).
2517 for (idx = 0; idx < 18; idx++) {
2518 if (sc->tulip_rombuf[idx] != 0)
2521 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
2522 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2523 } else if (sc->tulip_chipid >= TULIP_21142) {
2524 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2525 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2527 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) {
2528 if (sc->tulip_chipid != TULIP_21041)
2529 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2532 * If the SROM specifies more than one adapter, tag this as a
2535 if (sc->tulip_rombuf[19] > 1)
2536 sc->tulip_features |= TULIP_HAVE_BASEROM;
2537 if (sc->tulip_boardsw == NULL)
2544 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
2546 * Some folks don't use the standard ethernet rom format
2547 * but instead just put the address in the first 6 bytes
2548 * of the rom and let the rest be all 0xffs. (Can we say
2549 * ZNYX?) (well sometimes they put in a checksum so we'll
2552 for (idx = 8; idx < 32; idx++) {
2553 if (sc->tulip_rombuf[idx] != 0xFF)
2557 * Make sure the address is not multicast or locally assigned
2558 * that the OUI is not 00-00-00.
2560 if ((sc->tulip_rombuf[0] & 3) != 0)
2562 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
2563 && sc->tulip_rombuf[2] == 0)
2565 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2566 sc->tulip_features |= TULIP_HAVE_OKROM;
2570 * A number of makers of multiport boards (ZNYX and Cogent)
2571 * only put on one address ROM on their 21040 boards. So
2572 * if the ROM is all zeros (or all 0xFFs), look at the
2573 * previous configured boards (as long as they are on the same
2574 * PCI bus and the bus number is non-zero) until we find the
2575 * master board with address ROM. We then use its address ROM
2576 * as the base for this board. (we add our relative board
2577 * to the last byte of its address).
2579 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2580 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF)
2583 if (idx == sizeof(sc->tulip_rombuf)) {
2585 tulip_softc_t *root_sc = NULL;
2586 for (root_unit = device_get_unit(sc->tulip_dev) - 1; root_unit >= 0; root_unit--) {
2587 root_sc = tulips[root_unit];
2588 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
2592 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM)
2593 && root_sc->tulip_chipid == sc->tulip_chipid
2594 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2595 sc->tulip_features |= TULIP_HAVE_SLAVEDROM;
2596 sc->tulip_boardsw = root_sc->tulip_boardsw;
2597 strcpy(sc->tulip_boardid, root_sc->tulip_boardid);
2598 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) {
2599 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf,
2600 sizeof(sc->tulip_rombuf));
2601 if (!tulip_srom_decode(sc))
2604 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
2605 sc->tulip_enaddr[5] += device_get_unit(sc->tulip_dev) - device_get_unit(root_sc->tulip_dev);
2608 * Now for a truly disgusting kludge: all 4 21040s on
2609 * the ZX314 share the same INTA line so the mapping
2610 * setup by the BIOS on the PCI bridge is worthless.
2611 * Rather than reprogramming the value in the config
2612 * register, we will handle this internally.
2614 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) {
2615 sc->tulip_slaves = root_sc->tulip_slaves;
2616 root_sc->tulip_slaves = sc;
2617 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2625 * This is the standard DEC address ROM test.
2628 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
2631 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
2632 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
2633 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
2634 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
2635 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
2638 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2640 cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
2642 if (cksum > 65535) cksum -= 65535;
2643 cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
2644 if (cksum > 65535) cksum -= 65535;
2646 if (cksum > 65535) cksum -= 65535;
2647 cksum += *(u_int16_t *) &sc->tulip_enaddr[4];
2648 if (cksum >= 65535) cksum -= 65535;
2650 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6];
2652 if (cksum != rom_cksum)
2657 * Check for various boards based on OUI. Did I say braindead?
2659 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) {
2660 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) {
2661 (*tulip_vendors[idx].vendor_identify_nic)(sc);
2666 sc->tulip_features |= TULIP_HAVE_OKROM;
2671 tulip_ifmedia_add(tulip_softc_t * const sc)
2673 tulip_media_t media;
2676 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2677 if (sc->tulip_mediums[media] != NULL) {
2678 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media],
2684 sc->tulip_features |= TULIP_HAVE_NOMEDIA;
2685 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0);
2686 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE);
2687 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
2688 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0);
2689 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO);
2691 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]);
2692 sc->tulip_flags |= TULIP_PRINTMEDIA;
2693 tulip_linkup(sc, sc->tulip_media);
2698 tulip_ifmedia_change(struct ifnet *ifp)
2700 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2702 sc->tulip_flags |= TULIP_NEEDRESET;
2703 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
2704 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
2705 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) {
2706 tulip_media_t media;
2707 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2708 if (sc->tulip_mediums[media] != NULL
2709 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) {
2710 sc->tulip_flags |= TULIP_PRINTMEDIA;
2711 sc->tulip_flags &= ~TULIP_DIDNWAY;
2712 tulip_linkup(sc, media);
2717 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
2724 * Media status callback
2727 tulip_ifmedia_status(struct ifnet *ifp, struct ifmediareq *req)
2729 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2731 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN)
2734 req->ifm_status = IFM_AVALID;
2735 if (sc->tulip_flags & TULIP_LINKUP)
2736 req->ifm_status |= IFM_ACTIVE;
2738 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
2742 tulip_addr_filter(tulip_softc_t *sc)
2744 struct ifmultiaddr *ifma;
2748 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI);
2749 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART;
2750 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
2751 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
2752 #if defined(IFF_ALLMULTI)
2753 if (sc->tulip_if.if_flags & IFF_ALLMULTI)
2754 sc->tulip_flags |= TULIP_ALLMULTI ;
2758 LIST_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
2759 if (ifma->ifma_addr->sa_family == AF_LINK)
2763 sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */
2764 if (multicnt > 14) {
2765 uint32_t *sp = sc->tulip_setupdata;
2768 * Some early passes of the 21140 have broken implementations of
2769 * hash-perfect mode. When we get too many multicasts for perfect
2770 * filtering with these chips, we need to switch into hash-only
2771 * mode (this is better than all-multicast on network with lots
2772 * of multicast traffic).
2774 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
2775 sc->tulip_flags |= TULIP_WANTHASHONLY;
2777 sc->tulip_flags |= TULIP_WANTHASHPERFECT;
2779 * If we have more than 14 multicasts, we have
2780 * go into hash perfect mode (512 bit multicast
2781 * hash and one perfect hardware).
2783 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
2785 LIST_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
2786 if (ifma->ifma_addr->sa_family != AF_LINK)
2789 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
2790 #if BYTE_ORDER == BIG_ENDIAN
2791 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2793 sp[hash >> 4] |= 1 << (hash & 0xF);
2797 * No reason to use a hash if we are going to be
2798 * receiving every multicast.
2800 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
2801 hash = tulip_mchash(sc->tulip_if.if_broadcastaddr);
2802 #if BYTE_ORDER == BIG_ENDIAN
2803 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2805 sp[hash >> 4] |= 1 << (hash & 0xF);
2807 if (sc->tulip_flags & TULIP_WANTHASHONLY) {
2808 hash = tulip_mchash(sc->tulip_enaddr);
2809 #if BYTE_ORDER == BIG_ENDIAN
2810 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2812 sp[hash >> 4] |= 1 << (hash & 0xF);
2815 #if BYTE_ORDER == BIG_ENDIAN
2816 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
2817 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
2818 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
2820 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0];
2821 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1];
2822 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2];
2827 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
2828 uint32_t *sp = sc->tulip_setupdata;
2830 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
2832 * Else can get perfect filtering for 16 addresses.
2834 LIST_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
2835 if (ifma->ifma_addr->sa_family != AF_LINK)
2837 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
2838 #if BYTE_ORDER == BIG_ENDIAN
2839 *sp++ = ((u_int16_t *) addrp)[0] << 16;
2840 *sp++ = ((u_int16_t *) addrp)[1] << 16;
2841 *sp++ = ((u_int16_t *) addrp)[2] << 16;
2843 *sp++ = ((u_int16_t *) addrp)[0];
2844 *sp++ = ((u_int16_t *) addrp)[1];
2845 *sp++ = ((u_int16_t *) addrp)[2];
2850 * Add the broadcast address.
2853 #if BYTE_ORDER == BIG_ENDIAN
2854 *sp++ = 0xFFFF << 16;
2855 *sp++ = 0xFFFF << 16;
2856 *sp++ = 0xFFFF << 16;
2864 * Pad the rest with our hardware address
2866 for (; idx < 16; idx++) {
2867 #if BYTE_ORDER == BIG_ENDIAN
2868 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
2869 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
2870 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
2872 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0];
2873 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1];
2874 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2];
2878 #if defined(IFF_ALLMULTI)
2879 if (sc->tulip_flags & TULIP_ALLMULTI)
2880 sc->tulip_if.if_flags |= IFF_ALLMULTI;
2885 tulip_reset(tulip_softc_t *sc)
2887 tulip_ringinfo_t *ri;
2889 uint32_t inreset = (sc->tulip_flags & TULIP_INRESET);
2892 * Brilliant. Simply brilliant. When switching modes/speeds
2893 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
2894 * bits in CSR6 and then do a software reset to get the 21140
2895 * to properly reset its internal pathways to the right places.
2898 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
2899 && sc->tulip_boardsw->bd_media_preset != NULL)
2900 (*sc->tulip_boardsw->bd_media_preset)(sc);
2902 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2903 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
2904 33MHz that comes to two microseconds but wait a
2905 bit longer anyways) */
2908 sc->tulip_flags |= TULIP_INRESET;
2909 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
2910 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
2911 sc->tulip_if.if_start = tulip_ifstart;
2914 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
2915 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
2916 TULIP_CSR_WRITE(sc, csr_busmode,
2917 (1 << (3 /*pci_max_burst_len*/ + 8))
2918 |TULIP_BUSMODE_CACHE_ALIGN8
2919 |TULIP_BUSMODE_READMULTIPLE
2920 |(BYTE_ORDER != LITTLE_ENDIAN ?
2921 TULIP_BUSMODE_DESC_BIGENDIAN : 0));
2923 sc->tulip_txtimer = 0;
2924 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
2926 * Free all the mbufs that were on the transmit ring.
2928 IF_DRAIN(&sc->tulip_txq);
2930 ri = &sc->tulip_txinfo;
2931 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
2932 ri->ri_free = ri->ri_max;
2933 for (di = ri->ri_first; di < ri->ri_last; di++)
2937 * We need to collect all the mbufs were on the
2938 * receive ring before we reinit it either to put
2939 * them back on or to know if we have to allocate
2942 ri = &sc->tulip_rxinfo;
2943 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
2944 ri->ri_free = ri->ri_max;
2945 for (di = ri->ri_first; di < ri->ri_last; di++) {
2947 di->d_length1 = 0; di->d_addr1 = 0;
2948 di->d_length2 = 0; di->d_addr2 = 0;
2950 IF_DRAIN(&sc->tulip_rxq);
2953 * If tulip_reset is being called recurisvely, exit quickly knowing
2954 * that when the outer tulip_reset returns all the right stuff will
2960 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
2961 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
2962 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
2963 |TULIP_STS_RXSTOPPED;
2965 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
2966 (*sc->tulip_boardsw->bd_media_select)(sc);
2967 tulip_media_print(sc);
2968 if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
2969 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
2971 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
2973 tulip_addr_filter(sc);
2977 tulip_init(tulip_softc_t * const sc)
2979 if (sc->tulip_if.if_flags & IFF_UP) {
2980 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) {
2981 /* initialize the media */
2984 sc->tulip_if.if_flags |= IFF_RUNNING;
2985 if (sc->tulip_if.if_flags & IFF_PROMISC) {
2986 sc->tulip_flags |= TULIP_PROMISC;
2987 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
2988 sc->tulip_intrmask |= TULIP_STS_TXINTR;
2990 sc->tulip_flags &= ~TULIP_PROMISC;
2991 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
2992 if (sc->tulip_flags & TULIP_ALLMULTI) {
2993 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
2995 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
2998 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
2999 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
3001 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3002 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3004 sc->tulip_if.if_flags |= IFF_OACTIVE;
3005 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3006 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3008 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3009 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3010 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3011 tulip_txput_setup(sc);
3013 sc->tulip_if.if_flags &= ~IFF_RUNNING;
3019 tulip_rx_intr(tulip_softc_t *sc)
3021 tulip_ringinfo_t *ri = &sc->tulip_rxinfo;
3022 struct ifnet *ifp = &sc->tulip_if;
3026 tulip_desc_t *eop = ri->ri_nextin;
3027 int total_len = 0, last_offset = 0;
3028 struct mbuf *ms = NULL, *me = NULL;
3031 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
3035 * If the TULIP has no descriptors, there can't be any receive
3036 * descriptors to process.
3038 if (eop == ri->ri_nextout)
3042 * 90% of the packets will fit in one descriptor. So we optimize
3045 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3046 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
3047 IF_DEQUEUE(&sc->tulip_rxq, ms);
3051 * If still owned by the TULIP, don't touch it.
3053 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
3057 * It is possible (though improbable unless the BIG_PACKET support
3058 * is enabled or MCLBYTES < 1518) for a received packet to cross
3059 * more than one receive descriptor.
3061 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) {
3062 if (++eop == ri->ri_last)
3064 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3065 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
3072 * Dequeue the first buffer for the start of the packet. Hopefully
3073 * this will be the only one we need to dequeue. However, if the
3074 * packet consumed multiple descriptors, then we need to dequeue
3075 * those buffers and chain to the starting mbuf. All buffers but
3076 * the last buffer have the same length so we can set that now.
3077 * (we add to last_offset instead of multiplying since we normally
3078 * won't go into the loop and thereby saving a ourselves from
3079 * doing a multiplication by 0 in the normal case).
3081 IF_DEQUEUE(&sc->tulip_rxq, ms);
3082 for (me = ms; total_len > 0; total_len--) {
3083 me->m_len = TULIP_RX_BUFLEN;
3084 last_offset += TULIP_RX_BUFLEN;
3085 IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
3091 * Now get the size of received packet (minus the CRC).
3093 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
3094 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
3095 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0
3097 || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) &&
3098 (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT|
3099 TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC|
3100 TULIP_DSTS_RxOVERFLOW)) == 0)
3103 me->m_len = total_len - last_offset;
3105 sc->tulip_flags |= TULIP_RXACT;
3109 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3110 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3112 if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
3113 sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
3115 if (eop->d_status & TULIP_DSTS_RxBADCRC) {
3116 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
3117 sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
3119 sc->tulip_dot3stats.dot3StatsFCSErrors++;
3125 if (++eop == ri->ri_last)
3127 ri->ri_nextin = eop;
3130 * Either we are priming the TULIP with mbufs (m == NULL)
3131 * or we are about to accept an mbuf for the upper layers
3132 * so we need to allocate an mbuf to replace it. If we
3133 * can't replace it, send up it anyways. This may cause
3134 * us to drop packets in the future but that's better than
3135 * being caught in livelock.
3137 * Note that if this packet crossed multiple descriptors
3138 * we don't even try to reallocate all the mbufs here.
3139 * Instead we rely on the test of the beginning of
3140 * the loop to refill for the extra consumed mbufs.
3142 if (accept || ms == NULL) {
3145 #if defined(TULIP_COPY_RXDATA)
3146 if (!accept || total_len >= (MHLEN - 2))
3147 m0 = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
3149 m0 = m_gethdr(MB_DONTWAIT, MT_DATA);
3151 m0 = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
3155 #if defined(TULIP_COPY_RXDATA)
3159 #if !defined(TULIP_COPY_RXDATA)
3160 ms->m_pkthdr.len = total_len;
3161 ifp->if_input(ifp, ms);
3164 #error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
3166 m0->m_data += 2; /* align data after header */
3167 m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
3168 m0->m_len = m0->m_pkthdr.len = total_len;
3169 m0->m_pkthdr.rcvif = ifp;
3170 ifp->if_input(ifp, m0);
3172 #endif /* ! TULIP_COPY_RXDATA */
3178 * Couldn't allocate a new buffer. Don't bother
3179 * trying to replenish the receive queue.
3182 sc->tulip_flags |= TULIP_RXBUFSLOW;
3186 * Now give the buffer(s) to the TULIP and save in our
3190 tulip_desc_t * const nextout = ri->ri_nextout;
3191 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
3192 nextout->d_length1 = TULIP_RX_BUFLEN;
3193 nextout->d_status = TULIP_DSTS_OWNER;
3194 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
3195 if (++ri->ri_nextout == ri->ri_last)
3196 ri->ri_nextout = ri->ri_first;
3199 IF_ENQUEUE(&sc->tulip_rxq, ms);
3200 } while ((ms = me) != NULL);
3202 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
3203 sc->tulip_flags &= ~TULIP_RXBUFSLOW;
3208 tulip_tx_intr(tulip_softc_t *sc)
3210 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3215 while (ri->ri_free < ri->ri_max) {
3218 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
3219 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
3224 d_flag = ri->ri_nextin->d_flag;
3225 if (d_flag & TULIP_DFLAG_TxLASTSEG) {
3226 if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
3228 * We've just finished processing a setup packet.
3229 * Mark that we finished it. If there's not
3230 * another pending, startup the TULIP receiver.
3231 * Make sure we ack the RXSTOPPED so we won't get
3232 * an abormal interrupt indication.
3234 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap);
3235 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
3236 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT)
3237 sc->tulip_flags |= TULIP_HASHONLY;
3238 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
3240 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3241 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3242 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3243 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3244 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3247 const uint32_t d_status = ri->ri_nextin->d_status;
3248 IF_DEQUEUE(&sc->tulip_txq, m);
3252 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3253 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
3254 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
3255 event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
3257 (*sc->tulip_boardsw->bd_media_poll)(sc, event);
3259 * Escape from the loop before media poll has reset the TULIP!
3264 if (d_status & TULIP_DSTS_ERRSUM) {
3265 sc->tulip_if.if_oerrors++;
3266 if (d_status & TULIP_DSTS_TxEXCCOLL)
3267 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
3268 if (d_status & TULIP_DSTS_TxLATECOLL)
3269 sc->tulip_dot3stats.dot3StatsLateCollisions++;
3270 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
3271 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
3272 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
3273 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
3274 if (d_status & TULIP_DSTS_TxUNDERFLOW)
3275 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
3276 if (d_status & TULIP_DSTS_TxBABBLE)
3277 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
3279 u_int32_t collisions =
3280 (d_status & TULIP_DSTS_TxCOLLMASK)
3281 >> TULIP_DSTS_V_TxCOLLCNT;
3282 sc->tulip_if.if_collisions += collisions;
3283 if (collisions == 1)
3284 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
3285 else if (collisions > 1)
3286 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
3287 else if (d_status & TULIP_DSTS_TxDEFERRED)
3288 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
3290 * SQE is only valid for 10baseT/BNC/AUI when not
3291 * running in full-duplex. In order to speed up the
3292 * test, the corresponding bit in tulip_flags needs to
3293 * set as well to get us to count SQE Test Errors.
3295 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
3296 sc->tulip_dot3stats.dot3StatsSQETestErrors++;
3302 if (++ri->ri_nextin == ri->ri_last)
3303 ri->ri_nextin = ri->ri_first;
3305 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3306 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
3309 * If nothing left to transmit, disable the timer.
3310 * Else if progress, reset the timer back to 2 ticks.
3312 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
3313 sc->tulip_txtimer = 0;
3315 sc->tulip_txtimer = TULIP_TXTIMER;
3316 sc->tulip_if.if_opackets += xmits;
3321 tulip_print_abnormal_interrupt(tulip_softc_t *sc, uint32_t csr)
3323 const char * const *msgp = tulip_status_bits;
3326 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
3328 csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1;
3329 if_printf(&sc->tulip_if, "abnormal interrupt:");
3330 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
3331 if ((csr & mask) && *msgp != NULL) {
3332 kprintf("%s%s", sep, *msgp);
3333 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
3334 sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
3335 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
3336 kprintf(" (switching to store-and-forward mode)");
3338 kprintf(" (raising TX threshold to %s)",
3339 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
3349 tulip_intr_handler(tulip_softc_t *sc)
3353 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3354 TULIP_CSR_WRITE(sc, csr_status, csr);
3356 if (csr & TULIP_STS_SYSERROR) {
3357 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
3358 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3359 sc->tulip_flags |= TULIP_SYSTEMERROR;
3361 if_printf(&sc->tulip_if, "system error: %s\n",
3362 tulip_system_errors[sc->tulip_last_system_error]);
3364 sc->tulip_flags |= TULIP_NEEDRESET;
3365 sc->tulip_system_errors++;
3368 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
3369 if (sc->tulip_boardsw->bd_media_poll != NULL) {
3370 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
3371 ? TULIP_MEDIAPOLL_LINKFAIL
3372 : TULIP_MEDIAPOLL_LINKPASS);
3373 csr &= ~TULIP_STS_ABNRMLINTR;
3375 tulip_media_print(sc);
3377 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
3378 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
3379 if (csr & TULIP_STS_RXNOBUF)
3380 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
3382 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3383 * on receive overflows.
3385 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
3386 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3388 * Stop the receiver process and spin until it's stopped.
3389 * Tell rx_intr to drop the packets it dequeues.
3391 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
3392 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
3394 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3395 sc->tulip_flags |= TULIP_RXIGNORE;
3398 if (sc->tulip_flags & TULIP_RXIGNORE) {
3400 * Restart the receiver.
3402 sc->tulip_flags &= ~TULIP_RXIGNORE;
3403 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3406 if (csr & TULIP_STS_ABNRMLINTR) {
3407 u_int32_t tmp = csr & sc->tulip_intrmask
3408 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
3409 if (csr & TULIP_STS_TXUNDERFLOW) {
3410 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
3411 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
3412 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3413 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
3414 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
3415 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3418 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3419 sc->tulip_statusbits |= tmp;
3421 tulip_print_abnormal_interrupt(sc, tmp);
3422 sc->tulip_flags |= TULIP_NOMESSAGES;
3424 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3426 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
3428 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3429 tulip_ifstart(&sc->tulip_if);
3432 if (sc->tulip_flags & TULIP_NEEDRESET) {
3439 tulip_intr_shared(void *arg)
3443 for (sc = arg; sc != NULL; sc = sc->tulip_slaves)
3444 tulip_intr_handler(sc);
3448 tulip_intr_normal(void *arg)
3450 tulip_softc_t *sc = (tulip_softc_t *)arg;
3452 tulip_intr_handler(sc);
3455 static struct mbuf *
3456 tulip_txput(tulip_softc_t *sc, struct mbuf *m)
3458 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3459 tulip_desc_t *eop, *nextout;
3465 * Now we try to fill in our transmit descriptors. This is
3466 * a bit reminiscent of going on the Ark two by two
3467 * since each descriptor for the TULIP can describe
3468 * two buffers. So we advance through packet filling
3469 * each of the two entries at a time to to fill each
3470 * descriptor. Clear the first and last segment bits
3471 * in each descriptor (actually just clear everything
3472 * but the end-of-ring or chain bits) to make sure
3473 * we don't get messed up by previously sent packets.
3475 * We may fail to put the entire packet on the ring if
3476 * there is either not enough ring entries free or if the
3477 * packet has more than MAX_TXSEG segments. In the former
3478 * case we will just wait for the ring to empty. In the
3479 * latter case we have to recopy.
3484 eop = nextout = ri->ri_nextout;
3489 int len = m0->m_len;
3490 caddr_t addr = mtod(m0, caddr_t);
3491 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1));
3494 unsigned slen = min(len, clsize);
3498 slen = 2040, partial = 1;
3501 if (segcnt > TULIP_MAX_TXSEG) {
3503 * The packet exceeds the number of transmit buffer
3504 * entries that we can use for one packet, so we have
3505 * recopy it into one mbuf and then try again.
3507 m0 = m_defrag(m, MB_DONTWAIT);
3516 * See if there's any unclaimed space in the
3519 if ((free += tulip_tx_intr(sc)) == 0) {
3521 * There's no more room but since nothing
3522 * has been committed at this point, just
3523 * show output is active, put back the
3526 sc->tulip_flags |= TULIP_WANTTXSTART;
3531 if (++nextout == ri->ri_last)
3532 nextout = ri->ri_first;
3533 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
3534 eop->d_status = d_status;
3535 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr);
3536 eop->d_length1 = slen;
3539 * Fill in second half of descriptor
3541 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr);
3542 eop->d_length2 = slen;
3544 d_status = TULIP_DSTS_OWNER;
3553 } while ((m0 = m0->m_next) != NULL);
3555 BPF_MTAP(&sc->tulip_if, m);
3558 * The descriptors have been filled in. Now get ready
3561 IF_ENQUEUE(&sc->tulip_txq, m);
3565 * Make sure the next descriptor after this packet is owned
3566 * by us since it may have been set up above if we ran out
3567 * of room in the ring.
3569 nextout->d_status = 0;
3570 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
3573 * If we only used the first segment of the last descriptor,
3574 * make sure the second segment will not be used.
3582 * Mark the last and first segments, indicate we want a transmit
3583 * complete interrupt, and tell it to transmit!
3585 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
3588 * Note that ri->ri_nextout is still the start of the packet
3589 * and until we set the OWNER bit, we can still back out of
3590 * everything we have done.
3592 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
3593 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
3594 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
3597 * This advances the ring for us.
3599 ri->ri_nextout = nextout;
3602 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3603 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3604 sc->tulip_if.if_flags |= IFF_OACTIVE;
3605 sc->tulip_if.if_start = tulip_ifstart;
3610 * switch back to the single queueing ifstart.
3612 sc->tulip_flags &= ~TULIP_WANTTXSTART;
3613 if (sc->tulip_txtimer == 0)
3614 sc->tulip_txtimer = TULIP_TXTIMER;
3617 * If we want a txstart, there must be not enough space in the
3618 * transmit ring. So we want to enable transmit done interrupts
3619 * so we can immediately reclaim some space. When the transmit
3620 * interrupt is posted, the interrupt handler will call tx_intr
3621 * to reclaim space and then txstart (since WANTTXSTART is set).
3622 * txstart will move the packet into the transmit ring and clear
3623 * WANTTXSTART thereby causing TXINTR to be cleared.
3626 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
3627 sc->tulip_if.if_flags |= IFF_OACTIVE;
3628 sc->tulip_if.if_start = tulip_ifstart;
3629 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
3630 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3631 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3633 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) {
3634 if (sc->tulip_intrmask & TULIP_STS_TXINTR) {
3635 sc->tulip_intrmask &= ~TULIP_STS_TXINTR;
3636 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3639 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3644 tulip_txput_setup(tulip_softc_t *sc)
3646 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
3647 tulip_desc_t *nextout;
3650 * We will transmit, at most, one setup packet per call to ifstart.
3654 * Try to reclaim some free descriptors..
3656 if (ri->ri_free < 2)
3658 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
3659 sc->tulip_flags |= TULIP_WANTTXSTART;
3660 sc->tulip_if.if_start = tulip_ifstart;
3663 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
3664 sizeof(sc->tulip_setupbuf));
3666 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is
3667 * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
3669 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP;
3671 nextout = ri->ri_nextout;
3672 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
3673 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
3674 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
3675 if (sc->tulip_flags & TULIP_WANTHASHPERFECT)
3676 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
3677 else if (sc->tulip_flags & TULIP_WANTHASHONLY)
3678 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT;
3680 nextout->d_length2 = 0;
3681 nextout->d_addr2 = 0;
3682 nextout->d_length1 = sizeof(sc->tulip_setupbuf);
3683 nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
3686 * Advance the ring for the next transmit packet.
3688 if (++ri->ri_nextout == ri->ri_last)
3689 ri->ri_nextout = ri->ri_first;
3692 * Make sure the next descriptor is owned by us since it
3693 * may have been set up above if we ran out of room in the
3696 ri->ri_nextout->d_status = 0;
3697 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
3698 nextout->d_status = TULIP_DSTS_OWNER;
3700 * Flush the ownwership of the current descriptor
3702 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
3703 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
3704 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
3705 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3706 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3711 tulip_ifioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred * cr)
3713 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
3714 struct ifaddr *ifa = (struct ifaddr *)data;
3715 struct ifreq *ifr = (struct ifreq *)data;
3720 ifp->if_flags |= IFF_UP;
3721 switch(ifa->ifa_addr->sa_family) {
3725 arp_ifinit(&(sc)->tulip_ac.ac_if, ifa);
3732 struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr);
3733 if (ipx_nullhost(*ina)) {
3734 ina->x_host = *(union ipx_host *)(sc->tulip_enaddr);
3736 ifp->if_flags &= ~IFF_RUNNING;
3737 bcopy((caddr_t)ina->x_host.c_host,
3738 (caddr_t)sc->tulip_enaddr,
3739 sizeof(sc->tulip_enaddr));
3748 * This magic copied from if_is.c; I don't use XNS,
3749 * so I have no way of telling if this actually
3753 struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
3754 if (ns_nullhost(*ina)) {
3755 ina->x_host = *(union ns_host *)(sc->tulip_enaddr);
3757 ifp->if_flags &= ~IFF_RUNNING;
3758 bcopy((caddr_t)ina->x_host.c_host,
3759 (caddr_t)sc->tulip_enaddr,
3760 sizeof(sc->tulip_enaddr));
3775 bcopy((caddr_t) sc->tulip_enaddr,
3776 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
3781 case SIOCSIFFLAGS: {
3782 tulip_addr_filter(sc); /* reinit multicast filter */
3788 case SIOCGIFMEDIA: {
3789 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
3794 case SIOCDELMULTI: {
3796 * Update multicast listeners
3798 tulip_addr_filter(sc); /* reset multicast filtering */
3806 * Set the interface MTU.
3808 if (ifr->ifr_mtu > ETHERMTU
3810 && sc->tulip_chipid != TULIP_21140
3811 && sc->tulip_chipid != TULIP_21140A
3812 && sc->tulip_chipid != TULIP_21041
3818 ifp->if_mtu = ifr->ifr_mtu;
3826 case SIOCGADDRROM: {
3827 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
3833 ifr->ifr_metric = (int) sc->tulip_chipid;
3846 tulip_ifstart(struct ifnet *ifp)
3848 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
3850 if (sc->tulip_if.if_flags & IFF_RUNNING) {
3852 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3853 tulip_txput_setup(sc);
3855 while (sc->tulip_if.if_snd.ifq_head != NULL) {
3857 IF_DEQUEUE(&sc->tulip_if.if_snd, m);
3858 if ((m = tulip_txput(sc, m)) != NULL) {
3859 IF_PREPEND(&sc->tulip_if.if_snd, m);
3867 tulip_ifwatchdog(struct ifnet *ifp)
3869 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
3871 sc->tulip_if.if_timer = 1;
3873 * These should be rare so do a bulk test up front so we can just skip
3876 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) {
3878 * If the number of receive buffer is low, try to refill
3880 if (sc->tulip_flags & TULIP_RXBUFSLOW)
3883 if (sc->tulip_flags & TULIP_SYSTEMERROR) {
3884 if_printf(ifp, "%d system errors: last was %s\n",
3885 sc->tulip_system_errors,
3886 tulip_system_errors[sc->tulip_last_system_error]);
3888 if (sc->tulip_statusbits) {
3889 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
3890 sc->tulip_statusbits = 0;
3893 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR);
3896 if (sc->tulip_txtimer)
3898 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
3899 if_printf(ifp, "transmission timeout\n");
3900 if (TULIP_DO_AUTOSENSE(sc)) {
3901 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
3902 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
3903 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP);
3911 tulip_attach(tulip_softc_t *sc)
3913 struct ifnet *ifp = &sc->tulip_if;
3915 callout_init(&sc->tulip_timer);
3916 callout_init(&sc->tulip_fast_timer);
3918 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
3919 ifp->if_ioctl = tulip_ifioctl;
3920 ifp->if_start = tulip_ifstart;
3921 ifp->if_watchdog = tulip_ifwatchdog;
3924 if_printf(ifp, "%s%s pass %d.%d%s\n",
3926 tulip_chipdescs[sc->tulip_chipid],
3927 (sc->tulip_revinfo & 0xF0) >> 4,
3928 sc->tulip_revinfo & 0x0F,
3929 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM))
3930 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "");
3932 (*sc->tulip_boardsw->bd_media_probe)(sc);
3933 ifmedia_init(&sc->tulip_ifmedia, 0,
3934 tulip_ifmedia_change,
3935 tulip_ifmedia_status);
3936 sc->tulip_flags &= ~TULIP_DEVICEPROBE;
3937 tulip_ifmedia_add(sc);
3941 ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr, NULL);
3942 ifp->if_snd.ifq_maxlen = ifqmaxlen;
3946 tulip_detach(tulip_softc_t *sc)
3948 ifmedia_removeall(&sc->tulip_ifmedia);
3949 ether_ifdetach(&sc->tulip_if);
3953 tulip_initcsrs(tulip_softc_t *sc, tulip_csrptr_t csr_base, size_t csr_size)
3955 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
3956 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
3957 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
3958 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
3959 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
3960 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
3961 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
3962 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
3963 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size;
3964 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size;
3965 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size;
3966 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size;
3967 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size;
3968 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size;
3969 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
3970 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
3974 tulip_initring(tulip_softc_t *sc, tulip_ringinfo_t *ri, tulip_desc_t *descs,
3977 ri->ri_max = ndescs;
3978 ri->ri_first = descs;
3979 ri->ri_last = ri->ri_first + ri->ri_max;
3980 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
3981 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
3985 * This is the PCI configuration support.
3988 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
3989 #define PCI_CBMA 0x14 /* Configuration Base Memory Address */
3990 #define PCI_CFDA 0x40 /* Configuration Driver Area */
3993 tulip_pci_probe(device_t dev)
3995 const char *name = NULL;
3997 if (pci_get_vendor(dev) != DEC_VENDORID)
4001 * Some LanMedia WAN cards use the Tulip chip, but they have
4002 * their own driver, and we should not recognize them
4004 if (pci_get_subvendor(dev) == 0x1376)
4007 switch (pci_get_device(dev)) {
4009 name = "Digital 21040 Ethernet";
4012 name = "Digital 21041 Ethernet";
4015 if (pci_get_revid(dev) >= 0x20)
4016 name = "Digital 21140A Fast Ethernet";
4018 name = "Digital 21140 Fast Ethernet";
4021 if (pci_get_revid(dev) >= 0x20)
4022 name = "Digital 21143 Fast Ethernet";
4024 name = "Digital 21142 Fast Ethernet";
4028 device_set_desc(dev, name);
4035 tulip_shutdown(device_t dev)
4037 tulip_softc_t *sc = device_get_softc(dev);
4039 lwkt_serialize_enter(sc->tulip_if.if_serializer);
4040 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4041 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
4042 33MHz that comes to two microseconds but wait a
4043 bit longer anyways) */
4044 lwkt_serialize_exit(sc->tulip_if.if_serializer);
4049 tulip_pci_attach(device_t dev)
4053 uint32_t revinfo, cfdainfo, cfcsinfo;
4054 u_int csroffset = TULIP_PCI_CSROFFSET;
4055 u_int csrsize = TULIP_PCI_CSRSIZE;
4056 tulip_csrptr_t csr_base;
4057 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
4058 struct resource *res;
4061 if (device_get_unit(dev) >= TULIP_MAX_DEVICES) {
4062 device_printf(dev, "not configured; limit of %d reached or exceeded\n",
4067 revinfo = pci_get_revid(dev);
4068 cfdainfo = pci_read_config(dev, PCI_CFDA, 4);
4069 cfcsinfo = pci_read_config(dev, PCIR_COMMAND, 4);
4071 /* turn busmaster on in case BIOS doesn't set it */
4072 pci_enable_busmaster(dev);
4074 if (pci_get_vendor(dev) == DEC_VENDORID) {
4075 if (pci_get_device(dev) == CHIPID_21040)
4076 chipid = TULIP_21040;
4077 else if (pci_get_device(dev) == CHIPID_21041)
4078 chipid = TULIP_21041;
4079 else if (pci_get_device(dev) == CHIPID_21140)
4080 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140;
4081 else if (pci_get_device(dev) == CHIPID_21142)
4082 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142;
4084 if (chipid == TULIP_CHIPID_UNKNOWN)
4087 if (chipid == TULIP_21040 && revinfo < 0x20) {
4088 device_printf(dev, "not configured; 21040 pass 2.0 required (%d.%d found)\n",
4089 revinfo >> 4, revinfo & 0x0f);
4091 } else if (chipid == TULIP_21140 && revinfo < 0x11) {
4092 device_printf(dev, "not configured; 21140 pass 1.1 required (%d.%d found)\n",
4093 revinfo >> 4, revinfo & 0x0f);
4097 sc = device_get_softc(dev);
4098 sc->tulip_dev = dev;
4099 sc->tulip_pci_busno = pci_get_bus(dev);
4100 sc->tulip_pci_devno = pci_get_slot(dev);
4101 sc->tulip_chipid = chipid;
4102 sc->tulip_flags |= TULIP_DEVICEPROBE;
4103 if (chipid == TULIP_21140 || chipid == TULIP_21140A)
4104 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD;
4105 if (chipid == TULIP_21140A && revinfo <= 0x22)
4106 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW;
4107 if (chipid == TULIP_21140)
4108 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH;
4109 if (chipid != TULIP_21040 && chipid != TULIP_21140)
4110 sc->tulip_features |= TULIP_HAVE_POWERMGMT;
4111 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) {
4112 sc->tulip_features |= TULIP_HAVE_DUALSENSE;
4113 if (chipid != TULIP_21041 || revinfo >= 0x20)
4114 sc->tulip_features |= TULIP_HAVE_SIANWAY;
4115 if (chipid != TULIP_21041)
4116 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD;
4117 if (chipid != TULIP_21041 && revinfo >= 0x20)
4118 sc->tulip_features |= TULIP_HAVE_SIA100;
4121 if (sc->tulip_features & TULIP_HAVE_POWERMGMT
4122 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) {
4123 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE);
4124 pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
4127 if_initname(&sc->tulip_if, device_get_name(dev), device_get_unit(dev));
4128 sc->tulip_revinfo = revinfo;
4129 sc->tulip_if.if_softc = sc;
4130 #if defined(TULIP_IOMAPPED)
4132 res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
4135 res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
4139 sc->tulip_csrs_bst = rman_get_bustag(res);
4140 sc->tulip_csrs_bsh = rman_get_bushandle(res);
4143 tulips[device_get_unit(dev)] = sc;
4145 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
4147 sc->tulip_rxdescs = kmalloc(sizeof(tulip_desc_t) * TULIP_RXDESCS,
4148 M_DEVBUF, M_INTWAIT);
4149 sc->tulip_txdescs = kmalloc(sizeof(tulip_desc_t) * TULIP_TXDESCS,
4150 M_DEVBUF, M_INTWAIT);
4152 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS);
4153 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS);
4156 * Make sure there won't be any interrupts or such...
4158 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4159 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
4160 33MHz that comes to two microseconds but wait a
4161 bit longer anyways) */
4163 if ((retval = tulip_read_macaddr(sc)) < 0) {
4164 device_printf(dev, "can't read ENET ROM (why=%d) (", retval);
4165 for (idx = 0; idx < 32; idx++)
4166 kprintf("%02x", sc->tulip_rombuf[idx]);
4168 device_printf(dev, "%s%s pass %d.%d\n",
4169 sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
4170 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
4171 device_printf(dev, "address unknown\n");
4173 void (*intr_rtn)(void *) = tulip_intr_normal;
4175 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
4176 intr_rtn = tulip_intr_shared;
4179 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) {
4183 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
4184 RF_SHAREABLE | RF_ACTIVE);
4185 if (res == 0 || bus_setup_intr(dev, res, INTR_NETSAFE,
4187 sc->tulip_if.if_serializer)) {
4188 device_printf(dev, "couldn't map interrupt\n");
4190 kfree((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
4191 kfree((caddr_t) sc->tulip_txdescs, M_DEVBUF);
4199 static device_method_t tulip_pci_methods[] = {
4200 /* Device interface */
4201 DEVMETHOD(device_probe, tulip_pci_probe),
4202 DEVMETHOD(device_attach, tulip_pci_attach),
4203 DEVMETHOD(device_shutdown, tulip_shutdown),
4206 static driver_t tulip_pci_driver = {
4209 sizeof(tulip_softc_t),
4211 static devclass_t tulip_devclass;
4213 DECLARE_DUMMY_MODULE(if_de);
4214 DRIVER_MODULE(if_de, pci, tulip_pci_driver, tulip_devclass, 0, 0);