1 /* $NetBSD: if_de.c,v 1.86 1999/06/01 19:17:59 thorpej Exp $ */
3 * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. The name of the author may not be used to endorse or promote products
12 * derived from this software without specific prior written permission
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 * Id: if_de.c,v 1.94 1997/07/03 16:55:07 thomas Exp
29 * DEC 21040 PCI Ethernet Controller
31 * Written by Matt Thomas
32 * BPF support code stolen directly from if_ec.c
34 * This driver supports the DEC DE435 or any other PCI
35 * board which support 21040, 21041, or 21140 (mostly).
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
41 #define TULIP_HDR_DATA
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/endian.h>
50 #include <sys/socket.h>
51 #include <sys/sockio.h>
52 #include <sys/malloc.h>
53 #include <sys/kernel.h>
54 #include <sys/module.h>
55 #include <sys/eventhandler.h>
56 #include <machine/bus.h>
57 #include <machine/bus_dma.h>
58 #include <machine/resource.h>
63 #include <net/if_arp.h>
64 #include <net/ethernet.h>
65 #include <net/if_media.h>
66 #include <net/if_types.h>
67 #include <net/if_dl.h>
72 #include <netinet/in.h>
73 #include <netinet/if_ether.h>
78 #include <net/if_var.h>
80 #include <dev/pci/pcivar.h>
81 #include <dev/pci/pcireg.h>
82 #include <dev/de/dc21040reg.h>
89 * Intel CPUs should use I/O mapped access.
92 #define TULIP_IOMAPPED
96 /* This enables KTR traces at KTR_DEV. */
97 #define KTR_TULIP KTR_DEV
104 * This turns on all sort of debugging stuff and make the
105 * driver much larger.
111 #define TULIP_PERFSTATS
116 #include <dev/de/if_devar.h>
123 * This module supports
124 * the DEC 21040 PCI Ethernet Controller.
125 * the DEC 21041 PCI Ethernet Controller.
126 * the DEC 21140 PCI Fast Ethernet Controller.
128 static void tulip_addr_filter(tulip_softc_t * const sc);
129 static int tulip_ifmedia_change(struct ifnet * const ifp);
130 static void tulip_ifmedia_status(struct ifnet * const ifp,
131 struct ifmediareq *req);
132 static void tulip_init(void *);
133 static void tulip_init_locked(tulip_softc_t * const sc);
134 static void tulip_intr_shared(void *arg);
135 static void tulip_intr_normal(void *arg);
136 static void tulip_mii_autonegotiate(tulip_softc_t * const sc,
137 const unsigned phyaddr);
138 static int tulip_mii_map_abilities(tulip_softc_t * const sc,
141 tulip_mii_phy_readspecific(tulip_softc_t * const sc);
142 static unsigned tulip_mii_readreg(tulip_softc_t * const sc, unsigned devaddr,
144 static void tulip_mii_writereg(tulip_softc_t * const sc, unsigned devaddr,
145 unsigned regno, unsigned data);
146 static void tulip_reset(tulip_softc_t * const sc);
147 static void tulip_rx_intr(tulip_softc_t * const sc);
148 static int tulip_srom_decode(tulip_softc_t * const sc);
149 static void tulip_start(struct ifnet *ifp);
150 static void tulip_start_locked(tulip_softc_t * const sc);
152 tulip_txput(tulip_softc_t * const sc, struct mbuf *m);
153 static void tulip_txput_setup(tulip_softc_t * const sc);
154 struct mbuf * tulip_dequeue_mbuf(tulip_ringinfo_t *ri, tulip_descinfo_t *di,
156 static void tulip_dma_map_addr(void *, bus_dma_segment_t *, int, int);
157 static void tulip_dma_map_rxbuf(void *, bus_dma_segment_t *, int,
161 tulip_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
169 *paddr = segs->ds_addr;
173 tulip_dma_map_rxbuf(void *arg, bus_dma_segment_t *segs, int nseg,
174 bus_size_t mapsize, int error)
182 KASSERT(nseg == 1, ("too many DMA segments"));
183 KASSERT(segs[0].ds_len >= TULIP_RX_BUFLEN, ("receive buffer too small"));
185 desc->d_addr1 = segs[0].ds_addr;
186 desc->d_length1 = TULIP_RX_BUFLEN;
188 /* These should already always be zero. */
195 tulip_dequeue_mbuf(tulip_ringinfo_t *ri, tulip_descinfo_t *di, int sync)
205 TULIP_RXMAP_POSTSYNC(ri, di);
208 TULIP_TXMAP_POSTSYNC(ri, di);
211 panic("bad sync flag: %d", sync);
213 bus_dmamap_unload(ri->ri_data_tag, *di->di_map);
220 tulip_timeout_callback(void *arg)
222 tulip_softc_t * const sc = arg;
224 TULIP_PERFSTART(timeout)
225 TULIP_LOCK_ASSERT(sc);
227 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING;
228 sc->tulip_probe_timeout -= 1000 / TULIP_HZ;
229 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER);
231 TULIP_PERFEND(timeout);
235 tulip_timeout(tulip_softc_t * const sc)
237 TULIP_LOCK_ASSERT(sc);
238 if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
240 sc->tulip_flags |= TULIP_TIMEOUTPENDING;
241 callout_reset(&sc->tulip_callout, (hz + TULIP_HZ / 2) / TULIP_HZ,
242 tulip_timeout_callback, sc);
246 tulip_txprobe(tulip_softc_t * const sc)
252 * Before we are sure this is the right media we need
253 * to send a small packet to make sure there's carrier.
254 * Strangely, BNC and AUI will "see" receive data if
255 * either is connected so the transmit is the only way
256 * to verify the connectivity.
258 TULIP_LOCK_ASSERT(sc);
259 MGETHDR(m, M_DONTWAIT, MT_DATA);
263 * Construct a LLC TEST message which will point to ourselves.
265 if (sc->tulip_ifp->if_input != NULL)
266 enaddr = IF_LLADDR(sc->tulip_ifp);
268 enaddr = sc->tulip_enaddr;
269 bcopy(enaddr, mtod(m, struct ether_header *)->ether_dhost, ETHER_ADDR_LEN);
270 bcopy(enaddr, mtod(m, struct ether_header *)->ether_shost, ETHER_ADDR_LEN);
271 mtod(m, struct ether_header *)->ether_type = htons(3);
272 mtod(m, unsigned char *)[14] = 0;
273 mtod(m, unsigned char *)[15] = 0;
274 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
275 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
279 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
280 sc->tulip_intrmask |= TULIP_STS_TXINTR;
281 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
282 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
283 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
284 if ((m = tulip_txput(sc, m)) != NULL)
286 sc->tulip_probe.probe_txprobes++;
291 tulip_media_set(tulip_softc_t * const sc, tulip_media_t media)
293 const tulip_media_info_t *mi = sc->tulip_mediums[media];
295 TULIP_LOCK_ASSERT(sc);
300 * If we are switching media, make sure we don't think there's
301 * any stale RX activity
303 sc->tulip_flags &= ~TULIP_RXACT;
304 if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
305 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
306 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx);
307 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
308 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general);
310 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general);
312 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general);
314 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity);
315 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
316 #define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL)
318 * If the cmdmode bits don't match the currently operating mode,
319 * set the cmdmode appropriately and reset the chip.
321 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
322 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
323 sc->tulip_cmdmode |= mi->mi_cmdmode;
326 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
328 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata);
329 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
331 * If the cmdmode bits don't match the currently operating mode,
332 * set the cmdmode appropriately and reset the chip.
334 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
335 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
336 sc->tulip_cmdmode |= mi->mi_cmdmode;
339 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol);
340 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata);
341 } else if (mi->mi_type == TULIP_MEDIAINFO_MII
342 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) {
344 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
346 dp = &sc->tulip_rombuf[mi->mi_reset_offset];
347 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) {
349 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
351 sc->tulip_phyaddr = mi->mi_phyaddr;
352 dp = &sc->tulip_rombuf[mi->mi_gpr_offset];
353 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) {
355 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
358 for (idx = 0; idx < mi->mi_reset_length; idx++) {
360 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]);
362 sc->tulip_phyaddr = mi->mi_phyaddr;
363 for (idx = 0; idx < mi->mi_gpr_length; idx++) {
365 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]);
368 if (sc->tulip_flags & TULIP_TRYNWAY) {
369 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
370 } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
371 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL);
372 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE);
373 sc->tulip_flags &= ~TULIP_DIDNWAY;
374 if (TULIP_IS_MEDIA_FD(media))
375 data |= PHYCTL_FULL_DUPLEX;
376 if (TULIP_IS_MEDIA_100MB(media))
377 data |= PHYCTL_SELECT_100MB;
378 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data);
384 tulip_linkup(tulip_softc_t * const sc, tulip_media_t media)
386 TULIP_LOCK_ASSERT(sc);
387 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
388 sc->tulip_flags |= TULIP_PRINTLINKUP;
389 sc->tulip_flags |= TULIP_LINKUP;
390 sc->tulip_ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
391 #if 0 /* XXX how does with work with ifmedia? */
392 if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
393 if (sc->tulip_ifp->if_flags & IFF_FULLDUPLEX) {
394 if (TULIP_CAN_MEDIA_FD(media)
395 && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL)
396 media = TULIP_FD_MEDIA_OF(media);
398 if (TULIP_IS_MEDIA_FD(media)
399 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL)
400 media = TULIP_HD_MEDIA_OF(media);
404 if (sc->tulip_media != media) {
406 sc->tulip_dbg.dbg_last_media = sc->tulip_media;
408 sc->tulip_media = media;
409 sc->tulip_flags |= TULIP_PRINTMEDIA;
410 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) {
411 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
412 } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) {
413 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
417 * We could set probe_timeout to 0 but setting to 3000 puts this
418 * in one central place and the only matters is tulip_link is
419 * followed by a tulip_timeout. Therefore setting it should not
420 * result in aberrant behavour.
422 sc->tulip_probe_timeout = 3000;
423 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
424 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY);
425 if (sc->tulip_flags & TULIP_INRESET) {
426 tulip_media_set(sc, sc->tulip_media);
427 } else if (sc->tulip_probe_media != sc->tulip_media) {
429 * No reason to change media if we have the right media.
433 tulip_init_locked(sc);
437 tulip_media_print(tulip_softc_t * const sc)
440 TULIP_LOCK_ASSERT(sc);
441 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
443 if (sc->tulip_flags & TULIP_PRINTMEDIA) {
444 device_printf(sc->tulip_dev, "enabling %s port\n",
445 tulip_mediums[sc->tulip_media]);
446 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
447 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
448 device_printf(sc->tulip_dev, "link up\n");
449 sc->tulip_flags &= ~TULIP_PRINTLINKUP;
453 #if defined(TULIP_DO_GPR_SENSE)
455 tulip_21140_gpr_media_sense(tulip_softc_t * const sc)
457 struct ifnet *ifp sc->tulip_ifp;
458 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
459 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
462 TULIP_LOCK_ASSERT(sc);
465 * If one of the media blocks contained a default media flag,
468 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
469 const tulip_media_info_t *mi;
471 * Media is not supported (or is full-duplex).
473 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media))
475 if (mi->mi_type != TULIP_MEDIAINFO_GPR)
479 * Remember the media is this is the "default" media.
481 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
485 * No activity mask? Can't see if it is active if there's no mask.
487 if (mi->mi_actmask == 0)
491 * Does the activity data match?
493 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
496 #if defined(TULIP_DEBUG)
497 device_printf(sc->tulip_dev, "%s: %s: 0x%02x & 0x%02x == 0x%02x\n",
498 __func__, tulip_mediums[media], TULIP_CSR_READ(sc, csr_gp) & 0xFF,
499 mi->mi_actmask, mi->mi_actdata);
502 * It does! If this is the first media we detected, then
503 * remember this media. If isn't the first, then there were
504 * multiple matches which we equate to no match (since we don't
505 * which to select (if any).
507 if (last_media == TULIP_MEDIA_UNKNOWN) {
509 } else if (last_media != media) {
510 last_media = TULIP_MEDIA_UNKNOWN;
513 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
515 #endif /* TULIP_DO_GPR_SENSE */
517 static tulip_link_status_t
518 tulip_media_link_monitor(tulip_softc_t * const sc)
520 const tulip_media_info_t * const mi = sc->tulip_mediums[sc->tulip_media];
521 tulip_link_status_t linkup = TULIP_LINK_DOWN;
523 TULIP_LOCK_ASSERT(sc);
525 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
526 panic("tulip_media_link_monitor: %s: botch at line %d\n",
527 tulip_mediums[sc->tulip_media],__LINE__);
529 return TULIP_LINK_UNKNOWN;
535 * Have we seen some packets? If so, the link must be good.
537 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) {
538 sc->tulip_flags &= ~TULIP_RXACT;
539 sc->tulip_probe_timeout = 3000;
540 return TULIP_LINK_UP;
543 sc->tulip_flags &= ~TULIP_RXACT;
544 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
547 * Read the PHY status register.
549 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
550 if (status & PHYSTS_AUTONEG_DONE) {
552 * If the PHY has completed autonegotiation, see the if the
553 * remote systems abilities have changed. If so, upgrade or
554 * downgrade as appropriate.
556 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
557 abilities = (abilities << 6) & status;
558 if (abilities != sc->tulip_abilities) {
559 #if defined(TULIP_DEBUG)
560 loudprintf("%s(phy%d): autonegotiation changed: 0x%04x -> 0x%04x\n",
561 ifp->if_xname, sc->tulip_phyaddr,
562 sc->tulip_abilities, abilities);
564 if (tulip_mii_map_abilities(sc, abilities)) {
565 tulip_linkup(sc, sc->tulip_probe_media);
566 return TULIP_LINK_UP;
569 * if we had selected media because of autonegotiation,
570 * we need to probe for the new media.
572 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
573 if (sc->tulip_flags & TULIP_DIDNWAY)
574 return TULIP_LINK_DOWN;
578 * The link is now up. If was down, say its back up.
580 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP)
581 linkup = TULIP_LINK_UP;
582 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
584 * No activity sensor? Assume all's well.
586 if (mi->mi_actmask == 0)
587 return TULIP_LINK_UNKNOWN;
589 * Does the activity data match?
591 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata)
592 linkup = TULIP_LINK_UP;
593 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
595 * Assume non TP ok for now.
597 if (!TULIP_IS_MEDIA_TP(sc->tulip_media))
598 return TULIP_LINK_UNKNOWN;
599 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
600 linkup = TULIP_LINK_UP;
601 #if defined(TULIP_DEBUG)
602 if (sc->tulip_probe_timeout <= 0)
603 device_printf(sc->tulip_dev, "sia status = 0x%08x\n",
604 TULIP_CSR_READ(sc, csr_sia_status));
606 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
607 return TULIP_LINK_UNKNOWN;
610 * We will wait for 3 seconds until the link goes into suspect mode.
612 if (sc->tulip_flags & TULIP_LINKUP) {
613 if (linkup == TULIP_LINK_UP)
614 sc->tulip_probe_timeout = 3000;
615 if (sc->tulip_probe_timeout > 0)
616 return TULIP_LINK_UP;
618 sc->tulip_flags &= ~TULIP_LINKUP;
619 device_printf(sc->tulip_dev, "link down: cable problem?\n");
621 #if defined(TULIP_DEBUG)
622 sc->tulip_dbg.dbg_link_downed++;
624 return TULIP_LINK_DOWN;
628 tulip_media_poll(tulip_softc_t * const sc, tulip_mediapoll_event_t event)
631 TULIP_LOCK_ASSERT(sc);
632 #if defined(TULIP_DEBUG)
633 sc->tulip_dbg.dbg_events[event]++;
635 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
636 && event == TULIP_MEDIAPOLL_TIMER) {
637 switch (tulip_media_link_monitor(sc)) {
638 case TULIP_LINK_DOWN: {
640 * Link Monitor failed. Probe for new media.
642 event = TULIP_MEDIAPOLL_LINKFAIL;
645 case TULIP_LINK_UP: {
652 case TULIP_LINK_UNKNOWN: {
654 * We can't tell so don't bother.
661 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
662 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
663 if (TULIP_DO_AUTOSENSE(sc)) {
664 #if defined(TULIP_DEBUG)
665 sc->tulip_dbg.dbg_link_failures++;
667 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
668 if (sc->tulip_ifp->if_flags & IFF_UP)
669 tulip_reset(sc); /* restart probe */
673 #if defined(TULIP_DEBUG)
674 sc->tulip_dbg.dbg_link_pollintrs++;
678 if (event == TULIP_MEDIAPOLL_START) {
679 sc->tulip_ifp->if_drv_flags |= IFF_DRV_OACTIVE;
680 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
682 sc->tulip_probe_mediamask = 0;
683 sc->tulip_probe_passes = 0;
684 #if defined(TULIP_DEBUG)
685 sc->tulip_dbg.dbg_media_probes++;
688 * If the SROM contained an explicit media to use, use it.
690 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX);
691 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS;
692 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
694 * connidx is defaulted to a media_unknown type.
696 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media;
697 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) {
698 tulip_linkup(sc, sc->tulip_probe_media);
703 if (sc->tulip_features & TULIP_HAVE_GPR) {
704 sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
705 sc->tulip_probe_timeout = 2000;
707 sc->tulip_probe_media = TULIP_MEDIA_MAX;
708 sc->tulip_probe_timeout = 0;
709 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
714 * Ignore txprobe failures or spurious callbacks.
716 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED
717 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) {
718 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
723 * If we really transmitted a packet, then that's the media we'll use.
725 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) {
726 if (event == TULIP_MEDIAPOLL_LINKPASS) {
727 /* XXX Check media status just to be sure */
728 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
729 #if defined(TULIP_DEBUG)
731 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
734 tulip_linkup(sc, sc->tulip_probe_media);
739 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) {
740 #if defined(TULIP_DO_GPR_SENSE)
742 * Check for media via the general purpose register.
744 * Try to sense the media via the GPR. If the same value
745 * occurs 3 times in a row then just use that.
747 if (sc->tulip_probe_timeout > 0) {
748 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
749 #if defined(TULIP_DEBUG)
750 device_printf(sc->tulip_dev, "%s: gpr sensing = %s\n", __func__,
751 tulip_mediums[new_probe_media]);
753 if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
754 if (new_probe_media == sc->tulip_probe_media) {
755 if (--sc->tulip_probe_count == 0)
756 tulip_linkup(sc, sc->tulip_probe_media);
758 sc->tulip_probe_count = 10;
761 sc->tulip_probe_media = new_probe_media;
765 #endif /* TULIP_DO_GPR_SENSE */
767 * Brute force. We cycle through each of the media types
768 * and try to transmit a packet.
770 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
771 sc->tulip_probe_media = TULIP_MEDIA_MAX;
772 sc->tulip_probe_timeout = 0;
777 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST
778 && (sc->tulip_features & TULIP_HAVE_MII)) {
779 tulip_media_t old_media = sc->tulip_probe_media;
780 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
781 switch (sc->tulip_probe_state) {
782 case TULIP_PROBE_FAILED:
783 case TULIP_PROBE_MEDIATEST: {
785 * Try the next media.
787 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask;
788 sc->tulip_probe_timeout = 0;
790 if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
792 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
794 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
798 case TULIP_PROBE_PHYAUTONEG: {
801 case TULIP_PROBE_INACTIVE: {
803 * Only probe if we autonegotiated a media that hasn't failed.
805 sc->tulip_probe_timeout = 0;
806 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) {
807 sc->tulip_probe_media = old_media;
810 tulip_linkup(sc, sc->tulip_probe_media);
815 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
816 panic("tulip_media_poll: botch at line %d\n", __LINE__);
823 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
824 #if defined(TULIP_DEBUG)
825 sc->tulip_dbg.dbg_txprobes_failed[sc->tulip_probe_media]++;
827 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
832 * switch to another media if we tried this one enough.
834 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
835 #if defined(TULIP_DEBUG)
836 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
837 device_printf(sc->tulip_dev, "poll media unknown!\n");
838 sc->tulip_probe_media = TULIP_MEDIA_MAX;
842 * Find the next media type to check for. Full Duplex
843 * types are not allowed.
846 sc->tulip_probe_media -= 1;
847 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
848 if (++sc->tulip_probe_passes == 3) {
849 device_printf(sc->tulip_dev,
850 "autosense failed: cable problem?\n");
851 if ((sc->tulip_ifp->if_flags & IFF_UP) == 0) {
852 sc->tulip_ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
853 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
857 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */
858 sc->tulip_probe_mediamask = 0;
859 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1;
861 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL
862 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
863 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
865 #if defined(TULIP_DEBUG)
866 device_printf(sc->tulip_dev, "%s: probing %s\n",
867 event == TULIP_MEDIAPOLL_TXPROBE_FAILED ? "txprobe failed" : "timeout",
868 tulip_mediums[sc->tulip_probe_media]);
870 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
871 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
872 sc->tulip_probe.probe_txprobes = 0;
874 tulip_media_set(sc, sc->tulip_probe_media);
875 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
880 * If this is hanging off a phy, we know are doing NWAY and we have
881 * forced the phy to a specific speed. Wait for link up before
882 * before sending a packet.
884 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) {
885 case TULIP_MEDIAINFO_MII: {
886 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
890 case TULIP_MEDIAINFO_SIA: {
891 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) {
892 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL)
894 tulip_linkup(sc, sc->tulip_probe_media);
896 if (sc->tulip_features & TULIP_HAVE_MII)
903 case TULIP_MEDIAINFO_RESET:
904 case TULIP_MEDIAINFO_SYM:
905 case TULIP_MEDIAINFO_NONE:
906 case TULIP_MEDIAINFO_GPR: {
911 * Try to send a packet.
917 tulip_media_select(tulip_softc_t * const sc)
919 TULIP_LOCK_ASSERT(sc);
920 if (sc->tulip_features & TULIP_HAVE_GPR) {
921 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
923 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata);
926 * If this board has no media, just return
928 if (sc->tulip_features & TULIP_HAVE_NOMEDIA)
931 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
932 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
933 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START);
935 tulip_media_set(sc, sc->tulip_media);
940 tulip_21040_mediainfo_init(tulip_softc_t * const sc, tulip_media_t media)
942 TULIP_LOCK_ASSERT(sc);
943 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
944 |TULIP_CMD_BACKOFFCTR;
945 sc->tulip_ifp->if_baudrate = 10000000;
947 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) {
948 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET);
949 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD);
950 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
953 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) {
954 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC);
957 if (media == TULIP_MEDIA_UNKNOWN) {
958 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA);
963 tulip_21040_media_probe(tulip_softc_t * const sc)
965 TULIP_LOCK_ASSERT(sc);
966 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
971 tulip_21040_10baset_only_media_probe(tulip_softc_t * const sc)
973 TULIP_LOCK_ASSERT(sc);
974 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
975 tulip_media_set(sc, TULIP_MEDIA_10BASET);
976 sc->tulip_media = TULIP_MEDIA_10BASET;
980 tulip_21040_10baset_only_media_select(tulip_softc_t * const sc)
982 TULIP_LOCK_ASSERT(sc);
983 sc->tulip_flags |= TULIP_LINKUP;
984 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
985 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
986 sc->tulip_flags &= ~TULIP_SQETEST;
988 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
989 sc->tulip_flags |= TULIP_SQETEST;
991 tulip_media_set(sc, sc->tulip_media);
995 tulip_21040_auibnc_only_media_probe(tulip_softc_t * const sc)
997 TULIP_LOCK_ASSERT(sc);
998 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
999 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
1000 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
1001 sc->tulip_media = TULIP_MEDIA_AUIBNC;
1005 tulip_21040_auibnc_only_media_select(tulip_softc_t * const sc)
1007 TULIP_LOCK_ASSERT(sc);
1008 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
1009 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1012 static const tulip_boardsw_t tulip_21040_boardsw = {
1013 TULIP_21040_GENERIC,
1014 tulip_21040_media_probe,
1019 static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = {
1020 TULIP_21040_GENERIC,
1021 tulip_21040_10baset_only_media_probe,
1022 tulip_21040_10baset_only_media_select,
1026 static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = {
1027 TULIP_21040_GENERIC,
1028 tulip_21040_auibnc_only_media_probe,
1029 tulip_21040_auibnc_only_media_select,
1034 tulip_21041_mediainfo_init(tulip_softc_t * const sc)
1036 tulip_media_info_t * const mi = sc->tulip_mediainfo;
1038 TULIP_LOCK_ASSERT(sc);
1040 if (sc->tulip_revinfo >= 0x20) {
1041 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET);
1042 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD);
1043 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI);
1044 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC);
1048 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET);
1049 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD);
1050 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
1051 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
1055 tulip_21041_media_probe(tulip_softc_t * const sc)
1057 TULIP_LOCK_ASSERT(sc);
1058 sc->tulip_ifp->if_baudrate = 10000000;
1059 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
1060 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
1061 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
1062 tulip_21041_mediainfo_init(sc);
1066 tulip_21041_media_poll(tulip_softc_t * const sc,
1067 const tulip_mediapoll_event_t event)
1069 u_int32_t sia_status;
1071 TULIP_LOCK_ASSERT(sc);
1072 #if defined(TULIP_DEBUG)
1073 sc->tulip_dbg.dbg_events[event]++;
1076 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
1077 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
1078 || !TULIP_DO_AUTOSENSE(sc))
1080 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
1081 tulip_reset(sc); /* start probe */
1086 * If we've been been asked to start a poll or link change interrupt
1087 * restart the probe (and reset the tulip to a known state).
1089 if (event == TULIP_MEDIAPOLL_START) {
1090 sc->tulip_ifp->if_drv_flags |= IFF_DRV_OACTIVE;
1091 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN);
1093 if (sc->tulip_revinfo >= 0x20) {
1094 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
1095 sc->tulip_flags |= TULIP_DIDNWAY;
1098 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1099 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1100 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1101 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT;
1102 tulip_media_set(sc, TULIP_MEDIA_10BASET);
1107 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1110 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
1111 #if defined(TULIP_DEBUG)
1112 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
1114 tulip_linkup(sc, sc->tulip_probe_media);
1118 sia_status = TULIP_CSR_READ(sc, csr_sia_status);
1119 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status);
1120 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) {
1121 if (sc->tulip_revinfo >= 0x20) {
1122 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6)))
1123 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1126 * If the link has passed LinkPass, 10baseT is the
1127 * proper media to use.
1129 tulip_linkup(sc, sc->tulip_probe_media);
1134 * wait for up to 2.4 seconds for the link to reach pass state.
1135 * Only then start scanning the other media for activity.
1136 * choose media with receive activity over those without.
1138 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) {
1139 if (event != TULIP_MEDIAPOLL_TIMER)
1141 if (sc->tulip_probe_timeout > 0
1142 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
1146 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1147 sc->tulip_flags |= TULIP_WANTRXACT;
1148 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) {
1149 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1151 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1153 tulip_media_set(sc, sc->tulip_probe_media);
1159 * If we failed, clear the txprobe active flag.
1161 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED)
1162 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1165 if (event == TULIP_MEDIAPOLL_TIMER) {
1167 * If we've received something, then that's our link!
1169 if (sc->tulip_flags & TULIP_RXACT) {
1170 tulip_linkup(sc, sc->tulip_probe_media);
1174 * if no txprobe active
1176 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0
1177 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0
1178 || (sia_status & TULIP_SIASTS_RXACTIVITY))) {
1179 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1185 * Take 2 passes through before deciding to not
1186 * wait for receive activity. Then take another
1187 * two passes before spitting out a warning.
1189 if (sc->tulip_probe_timeout <= 0) {
1190 if (sc->tulip_flags & TULIP_WANTRXACT) {
1191 sc->tulip_flags &= ~TULIP_WANTRXACT;
1192 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1194 device_printf(sc->tulip_dev,
1195 "autosense failed: cable problem?\n");
1196 if ((sc->tulip_ifp->if_flags & IFF_UP) == 0) {
1197 sc->tulip_ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
1198 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1206 * Since this media failed to probe, try the other one.
1208 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1209 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) {
1210 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1212 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1214 tulip_media_set(sc, sc->tulip_probe_media);
1215 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1219 static const tulip_boardsw_t tulip_21041_boardsw = {
1220 TULIP_21041_GENERIC,
1221 tulip_21041_media_probe,
1223 tulip_21041_media_poll
1226 static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
1227 { 0x20005c00, 0, /* 08-00-17 */
1229 { 0x19, 0x0040, 0x0040 }, /* 10TX */
1230 { 0x19, 0x0040, 0x0000 }, /* 100TX */
1232 #if defined(TULIP_DEBUG)
1236 { 0x0281F400, 0, /* 00-A0-7D */
1238 { 0x12, 0x0010, 0x0000 }, /* 10T */
1240 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1241 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1243 #if defined(TULIP_DEBUG)
1248 { 0x0015F420, 0, /* 00-A0-7D */
1250 { 0x12, 0x0010, 0x0000 }, /* 10T */
1252 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1253 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1255 #if defined(TULIP_DEBUG)
1260 { 0x0281F400, 0, /* 00-A0-BE */
1262 { 0x11, 0x8000, 0x0000 }, /* 10T */
1263 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1265 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1267 #if defined(TULIP_DEBUG)
1274 static tulip_media_t
1275 tulip_mii_phy_readspecific(tulip_softc_t * const sc)
1277 const tulip_phy_attr_t *attr;
1281 static const tulip_media_t table[] = {
1282 TULIP_MEDIA_UNKNOWN,
1283 TULIP_MEDIA_10BASET,
1284 TULIP_MEDIA_100BASETX,
1285 TULIP_MEDIA_100BASET4,
1286 TULIP_MEDIA_UNKNOWN,
1287 TULIP_MEDIA_10BASET_FD,
1288 TULIP_MEDIA_100BASETX_FD,
1292 TULIP_LOCK_ASSERT(sc);
1295 * Don't read phy specific registers if link is not up.
1297 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
1298 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS))
1299 return TULIP_MEDIA_UNKNOWN;
1301 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) |
1302 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH);
1303 for (attr = tulip_mii_phy_attrlist;; attr++) {
1304 if (attr->attr_id == 0)
1305 return TULIP_MEDIA_UNKNOWN;
1306 if ((id & ~0x0F) == attr->attr_id)
1310 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
1311 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100TX];
1312 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1313 if ((data & pm->pm_mask) == pm->pm_value)
1316 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) {
1317 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100T4];
1318 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1319 if ((data & pm->pm_mask) == pm->pm_value)
1322 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) {
1323 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_10T];
1324 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1325 if ((data & pm->pm_mask) == pm->pm_value)
1328 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) {
1329 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
1330 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1331 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
1337 tulip_mii_get_phyaddr(tulip_softc_t * const sc, unsigned offset)
1341 TULIP_LOCK_ASSERT(sc);
1342 for (phyaddr = 1; phyaddr < 32; phyaddr++) {
1343 unsigned status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1344 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1351 unsigned status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
1352 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1353 return TULIP_MII_NOPHY;
1356 return TULIP_MII_NOPHY;
1360 tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities)
1362 TULIP_LOCK_ASSERT(sc);
1363 sc->tulip_abilities = abilities;
1364 if (abilities & PHYSTS_100BASETX_FD) {
1365 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD;
1366 } else if (abilities & PHYSTS_100BASET4) {
1367 sc->tulip_probe_media = TULIP_MEDIA_100BASET4;
1368 } else if (abilities & PHYSTS_100BASETX) {
1369 sc->tulip_probe_media = TULIP_MEDIA_100BASETX;
1370 } else if (abilities & PHYSTS_10BASET_FD) {
1371 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1372 } else if (abilities & PHYSTS_10BASET) {
1373 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1375 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1378 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1383 tulip_mii_autonegotiate(tulip_softc_t * const sc, const unsigned phyaddr)
1385 struct ifnet *ifp = sc->tulip_ifp;
1387 TULIP_LOCK_ASSERT(sc);
1388 switch (sc->tulip_probe_state) {
1389 case TULIP_PROBE_MEDIATEST:
1390 case TULIP_PROBE_INACTIVE: {
1391 sc->tulip_flags |= TULIP_DIDNWAY;
1392 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET);
1393 sc->tulip_probe_timeout = 3000;
1394 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR;
1395 sc->tulip_probe_state = TULIP_PROBE_PHYRESET;
1398 case TULIP_PROBE_PHYRESET: {
1400 u_int32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1401 if (data & PHYCTL_RESET) {
1402 if (sc->tulip_probe_timeout > 0) {
1406 printf("%s(phy%d): error: reset of PHY never completed!\n",
1407 ifp->if_xname, phyaddr);
1408 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1409 sc->tulip_probe_state = TULIP_PROBE_FAILED;
1410 sc->tulip_ifp->if_flags &= ~IFF_UP;
1411 sc->tulip_ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
1414 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1415 if ((status & PHYSTS_CAN_AUTONEG) == 0) {
1416 #if defined(TULIP_DEBUG)
1417 loudprintf("%s(phy%d): autonegotiation disabled\n",
1418 ifp->if_xname, phyaddr);
1420 sc->tulip_flags &= ~TULIP_DIDNWAY;
1421 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1424 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01))
1425 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
1426 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
1427 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1428 #if defined(TULIP_DEBUG)
1429 if ((data & PHYCTL_AUTONEG_ENABLE) == 0)
1430 loudprintf("%s(phy%d): oops: enable autonegotiation failed: 0x%04x\n",
1431 ifp->if_xname, phyaddr, data);
1433 loudprintf("%s(phy%d): autonegotiation restarted: 0x%04x\n",
1434 ifp->if_xname, phyaddr, data);
1435 sc->tulip_dbg.dbg_nway_starts++;
1437 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
1438 sc->tulip_probe_timeout = 3000;
1441 case TULIP_PROBE_PHYAUTONEG: {
1442 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1444 if ((status & PHYSTS_AUTONEG_DONE) == 0) {
1445 if (sc->tulip_probe_timeout > 0) {
1449 #if defined(TULIP_DEBUG)
1450 loudprintf("%s(phy%d): autonegotiation timeout: sts=0x%04x, ctl=0x%04x\n",
1451 ifp->if_xname, phyaddr, status,
1452 tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL));
1454 sc->tulip_flags &= ~TULIP_DIDNWAY;
1455 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1458 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
1459 #if defined(TULIP_DEBUG)
1460 loudprintf("%s(phy%d): autonegotiation complete: 0x%04x\n",
1461 ifp->if_xname, phyaddr, data);
1463 data = (data << 6) & status;
1464 if (!tulip_mii_map_abilities(sc, data))
1465 sc->tulip_flags &= ~TULIP_DIDNWAY;
1469 #if defined(DIAGNOSTIC)
1470 panic("tulip_media_poll: botch at line %d\n", __LINE__);
1475 #if defined(TULIP_DEBUG)
1476 loudprintf("%s(phy%d): autonegotiation failure: state = %d\n",
1477 ifp->if_xname, phyaddr, sc->tulip_probe_state);
1478 sc->tulip_dbg.dbg_nway_failures++;
1483 tulip_2114x_media_preset(tulip_softc_t * const sc)
1485 const tulip_media_info_t *mi = NULL;
1486 tulip_media_t media = sc->tulip_media;
1488 TULIP_LOCK_ASSERT(sc);
1489 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1490 media = sc->tulip_media;
1492 media = sc->tulip_probe_media;
1494 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
1495 sc->tulip_flags &= ~TULIP_SQETEST;
1496 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
1497 #if defined(TULIP_DEBUG)
1498 if (media < TULIP_MEDIA_MAX && sc->tulip_mediums[media] != NULL) {
1500 mi = sc->tulip_mediums[media];
1501 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
1502 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1503 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR
1504 || mi->mi_type == TULIP_MEDIAINFO_SYM) {
1505 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
1506 sc->tulip_cmdmode |= mi->mi_cmdmode;
1507 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
1508 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
1510 #if defined(TULIP_DEBUG)
1512 device_printf(sc->tulip_dev, "preset: bad media %d!\n", media);
1517 case TULIP_MEDIA_BNC:
1518 case TULIP_MEDIA_AUI:
1519 case TULIP_MEDIA_10BASET: {
1520 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1521 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
1522 sc->tulip_ifp->if_baudrate = 10000000;
1523 sc->tulip_flags |= TULIP_SQETEST;
1526 case TULIP_MEDIA_10BASET_FD: {
1527 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
1528 sc->tulip_ifp->if_baudrate = 10000000;
1531 case TULIP_MEDIA_100BASEFX:
1532 case TULIP_MEDIA_100BASET4:
1533 case TULIP_MEDIA_100BASETX: {
1534 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL);
1535 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1536 sc->tulip_ifp->if_baudrate = 100000000;
1539 case TULIP_MEDIA_100BASEFX_FD:
1540 case TULIP_MEDIA_100BASETX_FD: {
1541 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT;
1542 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
1543 sc->tulip_ifp->if_baudrate = 100000000;
1550 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1554 ********************************************************************
1555 * Start of 21140/21140A support which does not use the MII interface
1559 tulip_null_media_poll(tulip_softc_t * const sc, tulip_mediapoll_event_t event)
1561 #if defined(TULIP_DEBUG)
1562 sc->tulip_dbg.dbg_events[event]++;
1564 #if defined(DIAGNOSTIC)
1565 device_printf(sc->tulip_dev, "botch(media_poll) at line %d\n", __LINE__);
1569 __inline static void
1570 tulip_21140_mediainit(tulip_softc_t * const sc, tulip_media_info_t * const mip,
1571 tulip_media_t const media, unsigned gpdata, unsigned cmdmode)
1573 TULIP_LOCK_ASSERT(sc);
1574 sc->tulip_mediums[media] = mip;
1575 mip->mi_type = TULIP_MEDIAINFO_GPR;
1576 mip->mi_cmdmode = cmdmode;
1577 mip->mi_gpdata = gpdata;
1581 tulip_21140_evalboard_media_probe(tulip_softc_t * const sc)
1583 tulip_media_info_t *mip = sc->tulip_mediainfo;
1585 TULIP_LOCK_ASSERT(sc);
1586 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1587 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1588 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1589 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1590 TULIP_CSR_WRITE(sc, csr_command,
1591 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1592 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1593 TULIP_CSR_WRITE(sc, csr_command,
1594 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1596 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
1597 sc->tulip_media = TULIP_MEDIA_10BASET;
1599 sc->tulip_media = TULIP_MEDIA_100BASETX;
1601 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1603 TULIP_CMD_TXTHRSHLDCTL);
1604 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1606 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1607 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1609 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1610 |TULIP_CMD_SCRAMBLER);
1611 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1613 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1614 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1617 static const tulip_boardsw_t tulip_21140_eb_boardsw = {
1619 tulip_21140_evalboard_media_probe,
1621 tulip_null_media_poll,
1622 tulip_2114x_media_preset,
1626 tulip_21140_accton_media_probe(tulip_softc_t * const sc)
1628 tulip_media_info_t *mip = sc->tulip_mediainfo;
1631 TULIP_LOCK_ASSERT(sc);
1632 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1633 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1634 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1635 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1636 TULIP_CSR_WRITE(sc, csr_command,
1637 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1638 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1639 TULIP_CSR_WRITE(sc, csr_command,
1640 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1642 gpdata = TULIP_CSR_READ(sc, csr_gp);
1643 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) {
1644 sc->tulip_media = TULIP_MEDIA_10BASET;
1646 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) {
1647 sc->tulip_media = TULIP_MEDIA_BNC;
1649 sc->tulip_media = TULIP_MEDIA_100BASETX;
1652 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC,
1653 TULIP_GP_EN1207_BNC_INIT,
1654 TULIP_CMD_TXTHRSHLDCTL);
1655 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1656 TULIP_GP_EN1207_UTP_INIT,
1657 TULIP_CMD_TXTHRSHLDCTL);
1658 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1659 TULIP_GP_EN1207_UTP_INIT,
1660 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1661 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1662 TULIP_GP_EN1207_100_INIT,
1663 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1664 |TULIP_CMD_SCRAMBLER);
1665 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1666 TULIP_GP_EN1207_100_INIT,
1667 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1668 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1671 static const tulip_boardsw_t tulip_21140_accton_boardsw = {
1673 tulip_21140_accton_media_probe,
1675 tulip_null_media_poll,
1676 tulip_2114x_media_preset,
1680 tulip_21140_smc9332_media_probe(tulip_softc_t * const sc)
1682 tulip_media_info_t *mip = sc->tulip_mediainfo;
1685 TULIP_LOCK_ASSERT(sc);
1686 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE);
1687 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
1688 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
1689 33MHz that comes to two microseconds but wait a
1690 bit longer anyways) */
1691 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT |
1692 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1693 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS;
1694 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT;
1695 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET);
1696 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT);
1698 for (idx = 1000; idx > 0; idx--) {
1699 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1700 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) {
1703 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
1710 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1711 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1712 TULIP_GP_SMC_9332_INIT,
1713 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1714 |TULIP_CMD_SCRAMBLER);
1715 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1716 TULIP_GP_SMC_9332_INIT,
1717 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1718 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1719 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1720 TULIP_GP_SMC_9332_INIT,
1721 TULIP_CMD_TXTHRSHLDCTL);
1722 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1723 TULIP_GP_SMC_9332_INIT,
1724 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1727 static const tulip_boardsw_t tulip_21140_smc9332_boardsw = {
1728 TULIP_21140_SMC_9332,
1729 tulip_21140_smc9332_media_probe,
1731 tulip_null_media_poll,
1732 tulip_2114x_media_preset,
1736 tulip_21140_cogent_em100_media_probe(tulip_softc_t * const sc)
1738 tulip_media_info_t *mip = sc->tulip_mediainfo;
1739 u_int32_t cmdmode = TULIP_CSR_READ(sc, csr_command);
1741 TULIP_LOCK_ASSERT(sc);
1742 sc->tulip_gpinit = TULIP_GP_EM100_PINS;
1743 sc->tulip_gpdata = TULIP_GP_EM100_INIT;
1744 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS);
1745 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT);
1747 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE;
1748 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER);
1749 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1750 TULIP_CSR_WRITE(sc, csr_command, cmdmode);
1751 sc->tulip_media = TULIP_MEDIA_100BASEFX;
1753 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX,
1754 TULIP_GP_EM100_INIT,
1755 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION);
1756 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD,
1757 TULIP_GP_EM100_INIT,
1758 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1759 |TULIP_CMD_FULLDUPLEX);
1761 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);
1762 sc->tulip_media = TULIP_MEDIA_100BASETX;
1763 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1764 TULIP_GP_EM100_INIT,
1765 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1766 |TULIP_CMD_SCRAMBLER);
1767 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1768 TULIP_GP_EM100_INIT,
1769 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1770 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1774 static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {
1775 TULIP_21140_COGENT_EM100,
1776 tulip_21140_cogent_em100_media_probe,
1778 tulip_null_media_poll,
1779 tulip_2114x_media_preset
1783 tulip_21140_znyx_zx34x_media_probe(tulip_softc_t * const sc)
1785 tulip_media_info_t *mip = sc->tulip_mediainfo;
1786 int cnt10 = 0, cnt100 = 0, idx;
1788 TULIP_LOCK_ASSERT(sc);
1789 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS;
1790 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT;
1791 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS);
1792 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT);
1793 TULIP_CSR_WRITE(sc, csr_command,
1794 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1795 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1796 TULIP_CSR_WRITE(sc, csr_command,
1797 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1800 for (idx = 1000; idx > 0; idx--) {
1801 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1802 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)) {
1805 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
1814 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1815 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1816 TULIP_GP_ZX34X_INIT,
1817 TULIP_CMD_TXTHRSHLDCTL);
1818 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1819 TULIP_GP_ZX34X_INIT,
1820 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1821 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1822 TULIP_GP_ZX34X_INIT,
1823 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1824 |TULIP_CMD_SCRAMBLER);
1825 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1826 TULIP_GP_ZX34X_INIT,
1827 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1828 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1831 static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = {
1832 TULIP_21140_ZNYX_ZX34X,
1833 tulip_21140_znyx_zx34x_media_probe,
1835 tulip_null_media_poll,
1836 tulip_2114x_media_preset,
1840 tulip_2114x_media_probe(tulip_softc_t * const sc)
1842 TULIP_LOCK_ASSERT(sc);
1843 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE
1844 |TULIP_CMD_BACKOFFCTR|TULIP_CMD_THRSHLD72;
1847 static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
1849 tulip_2114x_media_probe,
1852 tulip_2114x_media_preset,
1856 * ******** END of chip-specific handlers. ***********
1860 * Code the read the SROM and MII bit streams (I2C)
1862 #define EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
1865 tulip_srom_idle(tulip_softc_t * const sc)
1869 csr = SROMSEL ; EMIT;
1870 csr = SROMSEL | SROMRD; EMIT;
1871 csr ^= SROMCS; EMIT;
1872 csr ^= SROMCLKON; EMIT;
1875 * Write 25 cycles of 0 which will force the SROM to be idle.
1877 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1878 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1879 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1881 csr ^= SROMCLKOFF; EMIT;
1882 csr ^= SROMCS; EMIT;
1887 tulip_srom_read(tulip_softc_t * const sc)
1890 const unsigned bitwidth = SROM_BITWIDTH;
1891 const unsigned cmdmask = (SROMCMD_RD << bitwidth);
1892 const unsigned msb = 1 << (bitwidth + 3 - 1);
1893 unsigned lastidx = (1 << bitwidth) - 1;
1895 tulip_srom_idle(sc);
1897 for (idx = 0; idx <= lastidx; idx++) {
1898 unsigned lastbit, data, bits, bit, csr;
1899 csr = SROMSEL ; EMIT;
1900 csr = SROMSEL | SROMRD; EMIT;
1901 csr ^= SROMCSON; EMIT;
1902 csr ^= SROMCLKON; EMIT;
1905 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
1906 const unsigned thisbit = bits & msb;
1907 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1908 if (thisbit != lastbit) {
1909 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1913 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1916 csr ^= SROMCLKOFF; EMIT;
1918 for (data = 0, bits = 0; bits < 16; bits++) {
1920 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1921 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1922 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1924 sc->tulip_rombuf[idx*2] = data & 0xFF;
1925 sc->tulip_rombuf[idx*2+1] = data >> 8;
1926 csr = SROMSEL | SROMRD; EMIT;
1929 tulip_srom_idle(sc);
1932 #define MII_EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
1935 tulip_mii_writebits(tulip_softc_t * const sc, unsigned data, unsigned bits)
1937 unsigned msb = 1 << (bits - 1);
1938 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1939 unsigned lastbit = (csr & MII_DOUT) ? msb : 0;
1941 TULIP_LOCK_ASSERT(sc);
1942 csr |= MII_WR; MII_EMIT; /* clock low; assert write */
1944 for (; bits > 0; bits--, data <<= 1) {
1945 const unsigned thisbit = data & msb;
1946 if (thisbit != lastbit) {
1947 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */
1949 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1951 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1956 tulip_mii_turnaround(tulip_softc_t * const sc, unsigned cmd)
1958 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1960 TULIP_LOCK_ASSERT(sc);
1961 if (cmd == MII_WRCMD) {
1962 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
1963 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1964 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1965 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */
1967 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */
1969 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1970 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1974 tulip_mii_readbits(tulip_softc_t * const sc)
1977 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1980 TULIP_LOCK_ASSERT(sc);
1981 for (idx = 0, data = 0; idx < 16; idx++) {
1982 data <<= 1; /* this is NOOP on the first pass through */
1983 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1984 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)
1986 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1988 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
1994 tulip_mii_readreg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno)
1996 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1999 TULIP_LOCK_ASSERT(sc);
2000 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
2001 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
2002 tulip_mii_writebits(sc, MII_RDCMD, 8);
2003 tulip_mii_writebits(sc, devaddr, 5);
2004 tulip_mii_writebits(sc, regno, 5);
2005 tulip_mii_turnaround(sc, MII_RDCMD);
2007 data = tulip_mii_readbits(sc);
2008 #if defined(TULIP_DEBUG)
2009 sc->tulip_dbg.dbg_phyregs[regno][0] = data;
2010 sc->tulip_dbg.dbg_phyregs[regno][1]++;
2016 tulip_mii_writereg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno,
2019 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
2021 TULIP_LOCK_ASSERT(sc);
2022 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
2023 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
2024 tulip_mii_writebits(sc, MII_WRCMD, 8);
2025 tulip_mii_writebits(sc, devaddr, 5);
2026 tulip_mii_writebits(sc, regno, 5);
2027 tulip_mii_turnaround(sc, MII_WRCMD);
2028 tulip_mii_writebits(sc, data, 16);
2029 #if defined(TULIP_DEBUG)
2030 sc->tulip_dbg.dbg_phyregs[regno][2] = data;
2031 sc->tulip_dbg.dbg_phyregs[regno][3]++;
2035 #define tulip_mchash(mca) (ether_crc32_le(mca, 6) & 0x1FF)
2036 #define tulip_srom_crcok(databuf) ( \
2037 ((ether_crc32_le(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
2038 ((databuf)[126] | ((databuf)[127] << 8)))
2041 tulip_identify_dec_nic(tulip_softc_t * const sc)
2043 TULIP_LOCK_ASSERT(sc);
2044 strcpy(sc->tulip_boardid, "DEC ");
2046 if (sc->tulip_chipid <= TULIP_21040)
2048 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0
2049 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {
2050 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);
2051 sc->tulip_boardid[D0+8] = ' ';
2057 tulip_identify_znyx_nic(tulip_softc_t * const sc)
2061 TULIP_LOCK_ASSERT(sc);
2062 strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
2063 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
2065 sc->tulip_boardid[8] = '4';
2066 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
2067 if (znyx_ptr < 26 || znyx_ptr > 116) {
2068 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2071 /* ZX344 = 0010 .. 0013FF
2073 if (sc->tulip_rombuf[znyx_ptr] == 0x4A
2074 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52
2075 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) {
2076 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4];
2077 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) {
2078 sc->tulip_boardid[9] = '2';
2079 if (id == TULIP_ZNYX_ID_ZX342B) {
2080 sc->tulip_boardid[10] = 'B';
2081 sc->tulip_boardid[11] = ' ';
2083 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2084 } else if (id == TULIP_ZNYX_ID_ZX344) {
2085 sc->tulip_boardid[10] = '4';
2086 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2087 } else if (id == TULIP_ZNYX_ID_ZX345) {
2088 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5';
2089 } else if (id == TULIP_ZNYX_ID_ZX346) {
2090 sc->tulip_boardid[9] = '6';
2091 } else if (id == TULIP_ZNYX_ID_ZX351) {
2092 sc->tulip_boardid[8] = '5';
2093 sc->tulip_boardid[9] = '1';
2098 * Assume it's a ZX342...
2100 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2104 sc->tulip_boardid[8] = '1';
2105 if (sc->tulip_chipid == TULIP_21041) {
2106 sc->tulip_boardid[10] = '1';
2109 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) {
2110 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36];
2111 if (id == TULIP_ZNYX_ID_ZX312T) {
2112 sc->tulip_boardid[9] = '2';
2113 sc->tulip_boardid[10] = 'T';
2114 sc->tulip_boardid[11] = ' ';
2115 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2116 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) {
2117 sc->tulip_boardid[9] = '4';
2118 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2119 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2120 } else if (id == TULIP_ZNYX_ID_ZX314) {
2121 sc->tulip_boardid[9] = '4';
2122 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2123 sc->tulip_features |= TULIP_HAVE_BASEROM;
2124 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) {
2125 sc->tulip_boardid[9] = '5';
2126 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2127 } else if (id == TULIP_ZNYX_ID_ZX315) {
2128 sc->tulip_boardid[9] = '5';
2129 sc->tulip_features |= TULIP_HAVE_BASEROM;
2135 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) {
2136 sc->tulip_boardid[9] = '4';
2137 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2138 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2139 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) {
2140 sc->tulip_boardid[9] = '5';
2141 sc->tulip_boardsw = &tulip_21040_boardsw;
2142 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2143 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) {
2144 sc->tulip_boardid[9] = '2';
2145 sc->tulip_boardsw = &tulip_21040_boardsw;
2151 tulip_identify_smc_nic(tulip_softc_t * const sc)
2153 u_int32_t id1, id2, ei;
2154 int auibnc = 0, utp = 0;
2157 TULIP_LOCK_ASSERT(sc);
2158 strcpy(sc->tulip_boardid, "SMC ");
2159 if (sc->tulip_chipid == TULIP_21041)
2161 if (sc->tulip_chipid != TULIP_21040) {
2162 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2163 strcpy(&sc->tulip_boardid[4], "9332DST ");
2164 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;
2165 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {
2166 strcpy(&sc->tulip_boardid[4], "9334BDT ");
2168 strcpy(&sc->tulip_boardid[4], "9332BDT ");
2172 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);
2173 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);
2174 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);
2176 strcpy(&sc->tulip_boardid[4], "8432");
2177 cp = &sc->tulip_boardid[8];
2179 *cp++ = 'B', auibnc = 1;
2180 if ((id1 & 0xFF) > 0x32)
2181 *cp++ = 'T', utp = 1;
2182 if ((id1 & 0x4000) == 0)
2183 *cp++ = 'A', auibnc = 1;
2185 sc->tulip_boardid[7] = '4';
2189 *cp++ = (ei ? '2' : '1');
2194 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2195 else if (!utp && auibnc)
2196 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
2200 tulip_identify_cogent_nic(tulip_softc_t * const sc)
2202 TULIP_LOCK_ASSERT(sc);
2203 strcpy(sc->tulip_boardid, "Cogent ");
2204 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
2205 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {
2206 strcat(sc->tulip_boardid, "EM100TX ");
2207 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2208 #if defined(TULIP_COGENT_EM110TX_ID)
2209 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {
2210 strcat(sc->tulip_boardid, "EM110TX ");
2211 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2213 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
2214 strcat(sc->tulip_boardid, "EM100FX ");
2215 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2218 * Magic number (0x24001109U) is the SubVendor (0x2400) and
2219 * SubDevId (0x1109) for the ANA6944TX (EM440TX).
2221 if (*(u_int32_t *) sc->tulip_rombuf == 0x24001109U
2222 && (sc->tulip_features & TULIP_HAVE_BASEROM)) {
2224 * Cogent (Adaptec) is still mapping all INTs to INTA of
2225 * first 21140. Dumb! Dumb!
2227 strcat(sc->tulip_boardid, "EM440TX ");
2228 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2230 } else if (sc->tulip_chipid == TULIP_21040) {
2231 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2236 tulip_identify_accton_nic(tulip_softc_t * const sc)
2238 TULIP_LOCK_ASSERT(sc);
2239 strcpy(sc->tulip_boardid, "ACCTON ");
2240 switch (sc->tulip_chipid) {
2242 strcat(sc->tulip_boardid, "EN1207 ");
2243 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
2244 sc->tulip_boardsw = &tulip_21140_accton_boardsw;
2247 strcat(sc->tulip_boardid, "EN1207TX ");
2248 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
2249 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2252 strcat(sc->tulip_boardid, "EN1203 ");
2253 sc->tulip_boardsw = &tulip_21040_boardsw;
2256 strcat(sc->tulip_boardid, "EN1203 ");
2257 sc->tulip_boardsw = &tulip_21041_boardsw;
2260 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2266 tulip_identify_asante_nic(tulip_softc_t * const sc)
2268 TULIP_LOCK_ASSERT(sc);
2269 strcpy(sc->tulip_boardid, "Asante ");
2270 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
2271 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2272 tulip_media_info_t *mi = sc->tulip_mediainfo;
2275 * The Asante Fast Ethernet doesn't always ship with a valid
2276 * new format SROM. So if isn't in the new format, we cheat
2277 * set it up as if we had.
2280 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;
2281 sc->tulip_gpdata = 0;
2283 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);
2284 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);
2286 TULIP_CSR_WRITE(sc, csr_gp, 0);
2288 mi->mi_type = TULIP_MEDIAINFO_MII;
2289 mi->mi_gpr_length = 0;
2290 mi->mi_gpr_offset = 0;
2291 mi->mi_reset_length = 0;
2292 mi->mi_reset_offset = 0;;
2294 mi->mi_phyaddr = TULIP_MII_NOPHY;
2295 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) {
2297 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
2299 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2300 device_printf(sc->tulip_dev, "can't find phy 0\n");
2304 sc->tulip_features |= TULIP_HAVE_MII;
2305 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2306 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2307 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD;
2308 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD;
2309 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2310 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2311 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2312 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2313 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2314 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2315 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2317 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2322 tulip_identify_compex_nic(tulip_softc_t * const sc)
2324 TULIP_LOCK_ASSERT(sc);
2325 strcpy(sc->tulip_boardid, "COMPEX ");
2326 if (sc->tulip_chipid == TULIP_21140A) {
2328 tulip_softc_t *root_sc = NULL;
2330 strcat(sc->tulip_boardid, "400TX/PCI ");
2332 * All 4 chips on these boards share an interrupt. This code
2333 * copied from tulip_read_macaddr.
2335 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2336 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2337 root_sc = tulips[root_unit];
2339 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
2344 && root_sc->tulip_chipid == sc->tulip_chipid
2345 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2346 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2347 sc->tulip_slaves = root_sc->tulip_slaves;
2348 root_sc->tulip_slaves = sc;
2349 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
2350 printf("\nCannot find master device for %s interrupts",
2351 sc->tulip_ifp->if_xname);
2354 strcat(sc->tulip_boardid, "unknown ");
2356 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */
2361 tulip_srom_decode(tulip_softc_t * const sc)
2363 unsigned idx1, idx2, idx3;
2365 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
2366 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
2367 tulip_srom_media_t srom_media;
2368 tulip_media_info_t *mi = sc->tulip_mediainfo;
2370 u_int32_t leaf_offset, blocks, data;
2372 TULIP_LOCK_ASSERT(sc);
2373 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
2374 if (shp->sh_adapter_count == 1)
2376 if (saip->sai_device == sc->tulip_pci_devno)
2380 * Didn't find the right media block for this card.
2382 if (idx1 == shp->sh_adapter_count)
2386 * Save the hardware address.
2388 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6);
2390 * If this is a multiple port card, add the adapter index to the last
2391 * byte of the hardware address. (if it isn't multiport, adding 0
2394 sc->tulip_enaddr[5] += idx1;
2396 leaf_offset = saip->sai_leaf_offset_lowbyte
2397 + saip->sai_leaf_offset_highbyte * 256;
2398 dp = sc->tulip_rombuf + leaf_offset;
2400 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2;
2402 for (idx2 = 0;; idx2++) {
2403 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype
2404 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED)
2407 sc->tulip_connidx = idx2;
2409 if (sc->tulip_chipid == TULIP_21041) {
2411 for (idx2 = 0; idx2 < blocks; idx2++) {
2412 tulip_media_t media;
2414 srom_media = (tulip_srom_media_t) (data & 0x3F);
2415 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2416 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2419 media = tulip_srom_mediums[idx3].sm_type;
2420 if (media != TULIP_MEDIA_UNKNOWN) {
2421 if (data & TULIP_SROM_21041_EXTENDED) {
2422 mi->mi_type = TULIP_MEDIAINFO_SIA;
2423 sc->tulip_mediums[media] = mi;
2424 mi->mi_sia_connectivity = dp[0] + dp[1] * 256;
2425 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256;
2426 mi->mi_sia_general = dp[4] + dp[5] * 256;
2430 case TULIP_MEDIA_BNC: {
2431 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
2435 case TULIP_MEDIA_AUI: {
2436 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
2440 case TULIP_MEDIA_10BASET: {
2441 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
2445 case TULIP_MEDIA_10BASET_FD: {
2446 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
2456 if (data & TULIP_SROM_21041_EXTENDED)
2461 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++;
2462 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++;
2463 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++;
2464 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++;
2468 unsigned length, type;
2469 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN;
2470 if (sc->tulip_features & TULIP_HAVE_GPR)
2471 sc->tulip_gpinit = *dp++;
2473 for (idx2 = 0; idx2 < blocks; idx2++) {
2475 if ((*dp & 0x80) == 0) {
2479 length = (*dp++ & 0x7f) - 1;
2480 type = *dp++ & 0x3f;
2483 switch (type & 0x3f) {
2484 case 0: { /* 21140[A] GPR block */
2485 tulip_media_t media;
2486 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2487 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2488 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2491 media = tulip_srom_mediums[idx3].sm_type;
2492 if (media == TULIP_MEDIA_UNKNOWN)
2494 mi->mi_type = TULIP_MEDIAINFO_GPR;
2495 sc->tulip_mediums[media] = mi;
2496 mi->mi_gpdata = dp[1];
2497 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) {
2498 sc->tulip_gpdata = mi->mi_gpdata;
2501 data = dp[2] + dp[3] * 256;
2502 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2503 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2507 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2509 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2510 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2515 case 1: { /* 21140[A] MII block */
2516 const unsigned phyno = *dp++;
2517 mi->mi_type = TULIP_MEDIAINFO_MII;
2518 mi->mi_gpr_length = *dp++;
2519 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2520 dp += mi->mi_gpr_length;
2521 mi->mi_reset_length = *dp++;
2522 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2523 dp += mi->mi_reset_length;
2526 * Before we probe for a PHY, use the GPR information
2527 * to select it. If we don't, it may be inaccessible.
2529 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET);
2530 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) {
2532 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]);
2534 sc->tulip_phyaddr = mi->mi_phyaddr;
2535 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) {
2537 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]);
2541 * At least write something!
2543 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2544 TULIP_CSR_WRITE(sc, csr_gp, 0);
2546 mi->mi_phyaddr = TULIP_MII_NOPHY;
2547 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2549 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2551 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2552 #if defined(TULIP_DEBUG)
2553 device_printf(sc->tulip_dev, "can't find phy %d\n",
2558 sc->tulip_features |= TULIP_HAVE_MII;
2559 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2560 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2561 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2562 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2563 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2564 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2565 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2566 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2567 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2568 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2569 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2573 case 2: { /* 2114[23] SIA block */
2574 tulip_media_t media;
2575 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2576 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2577 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2580 media = tulip_srom_mediums[idx3].sm_type;
2581 if (media == TULIP_MEDIA_UNKNOWN)
2583 mi->mi_type = TULIP_MEDIAINFO_SIA;
2584 sc->tulip_mediums[media] = mi;
2586 mi->mi_sia_connectivity = dp[1] + dp[2] * 256;
2587 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256;
2588 mi->mi_sia_general = dp[5] + dp[6] * 256;
2592 case TULIP_MEDIA_BNC: {
2593 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
2596 case TULIP_MEDIA_AUI: {
2597 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
2600 case TULIP_MEDIA_10BASET: {
2601 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
2602 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2605 case TULIP_MEDIA_10BASET_FD: {
2606 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
2607 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2615 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16;
2616 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16;
2621 case 3: { /* 2114[23] MII PHY block */
2622 const unsigned phyno = *dp++;
2623 const u_int8_t *dp0;
2624 mi->mi_type = TULIP_MEDIAINFO_MII;
2625 mi->mi_gpr_length = *dp++;
2626 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2627 dp += 2 * mi->mi_gpr_length;
2628 mi->mi_reset_length = *dp++;
2629 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2630 dp += 2 * mi->mi_reset_length;
2632 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset];
2633 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) {
2635 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2637 sc->tulip_phyaddr = mi->mi_phyaddr;
2638 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset];
2639 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) {
2641 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2644 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2645 TULIP_CSR_WRITE(sc, csr_sia_general, 0);
2647 mi->mi_phyaddr = TULIP_MII_NOPHY;
2648 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2650 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2652 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2653 #if defined(TULIP_DEBUG)
2654 device_printf(sc->tulip_dev, "can't find phy %d\n",
2659 sc->tulip_features |= TULIP_HAVE_MII;
2660 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2661 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2662 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2663 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2664 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2;
2665 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2666 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2667 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2668 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2669 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2670 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2671 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2675 case 4: { /* 21143 SYM block */
2676 tulip_media_t media;
2677 srom_media = (tulip_srom_media_t) dp[0];
2678 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2679 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2682 media = tulip_srom_mediums[idx3].sm_type;
2683 if (media == TULIP_MEDIA_UNKNOWN)
2685 mi->mi_type = TULIP_MEDIAINFO_SYM;
2686 sc->tulip_mediums[media] = mi;
2687 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16;
2688 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16;
2689 data = dp[5] + dp[6] * 256;
2690 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2691 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2694 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2695 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2696 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2698 if (TULIP_IS_MEDIA_TP(media))
2699 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2704 case 5: { /* 21143 Reset block */
2705 mi->mi_type = TULIP_MEDIAINFO_RESET;
2706 mi->mi_reset_length = *dp++;
2707 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2708 dp += 2 * mi->mi_reset_length;
2719 return mi - sc->tulip_mediainfo;
2722 static const struct {
2723 void (*vendor_identify_nic)(tulip_softc_t * const sc);
2724 unsigned char vendor_oui[3];
2725 } tulip_vendors[] = {
2726 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } },
2727 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } },
2728 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } },
2729 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } },
2730 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } },
2731 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } },
2732 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } },
2733 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } },
2734 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } },
2735 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } },
2740 * This deals with the vagaries of the address roms and the
2741 * brain-deadness that various vendors commit in using them.
2744 tulip_read_macaddr(tulip_softc_t * const sc)
2746 unsigned cksum, rom_cksum, idx;
2748 unsigned char tmpbuf[8];
2749 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
2751 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX;
2753 if (sc->tulip_chipid == TULIP_21040) {
2754 TULIP_CSR_WRITE(sc, csr_enetrom, 1);
2755 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2757 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
2759 sc->tulip_rombuf[idx] = csr & 0xFF;
2761 sc->tulip_boardsw = &tulip_21040_boardsw;
2763 if (sc->tulip_chipid == TULIP_21041) {
2765 * Thankfully all 21041's act the same.
2767 sc->tulip_boardsw = &tulip_21041_boardsw;
2770 * Assume all 21140 board are compatible with the
2771 * DEC 10/100 evaluation board. Not really valid but
2772 * it's the best we can do until every one switches to
2773 * the new SROM format.
2776 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2778 tulip_srom_read(sc);
2779 if (tulip_srom_crcok(sc->tulip_rombuf)) {
2781 * SROM CRC is valid therefore it must be in the
2784 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM;
2785 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
2787 * No checksum is present. See if the SROM id checks out;
2788 * the first 18 bytes should be 0 followed by a 1 followed
2789 * by the number of adapters (which we don't deal with yet).
2791 for (idx = 0; idx < 18; idx++) {
2792 if (sc->tulip_rombuf[idx] != 0)
2795 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
2796 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2797 } else if (sc->tulip_chipid >= TULIP_21142) {
2798 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2799 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2801 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) {
2802 if (sc->tulip_chipid != TULIP_21041)
2803 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2806 * If the SROM specifies more than one adapter, tag this as a
2809 if (sc->tulip_rombuf[19] > 1)
2810 sc->tulip_features |= TULIP_HAVE_BASEROM;
2811 if (sc->tulip_boardsw == NULL)
2818 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
2820 * Some folks don't use the standard ethernet rom format
2821 * but instead just put the address in the first 6 bytes
2822 * of the rom and let the rest be all 0xffs. (Can we say
2823 * ZNYX?) (well sometimes they put in a checksum so we'll
2826 for (idx = 8; idx < 32; idx++) {
2827 if (sc->tulip_rombuf[idx] != 0xFF)
2831 * Make sure the address is not multicast or locally assigned
2832 * that the OUI is not 00-00-00.
2834 if ((sc->tulip_rombuf[0] & 3) != 0)
2836 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
2837 && sc->tulip_rombuf[2] == 0)
2839 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2840 sc->tulip_features |= TULIP_HAVE_OKROM;
2844 * A number of makers of multiport boards (ZNYX and Cogent)
2845 * only put on one address ROM on their 21040 boards. So
2846 * if the ROM is all zeros (or all 0xFFs), look at the
2847 * previous configured boards (as long as they are on the same
2848 * PCI bus and the bus number is non-zero) until we find the
2849 * master board with address ROM. We then use its address ROM
2850 * as the base for this board. (we add our relative board
2851 * to the last byte of its address).
2853 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2854 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF)
2857 if (idx == sizeof(sc->tulip_rombuf)) {
2859 tulip_softc_t *root_sc = NULL;
2860 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2861 root_sc = tulips[root_unit];
2862 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
2866 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM)
2867 && root_sc->tulip_chipid == sc->tulip_chipid
2868 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2869 sc->tulip_features |= TULIP_HAVE_SLAVEDROM;
2870 sc->tulip_boardsw = root_sc->tulip_boardsw;
2871 strcpy(sc->tulip_boardid, root_sc->tulip_boardid);
2872 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) {
2873 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf,
2874 sizeof(sc->tulip_rombuf));
2875 if (!tulip_srom_decode(sc))
2878 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
2879 sc->tulip_enaddr[5] += sc->tulip_unit - root_sc->tulip_unit;
2882 * Now for a truly disgusting kludge: all 4 21040s on
2883 * the ZX314 share the same INTA line so the mapping
2884 * setup by the BIOS on the PCI bridge is worthless.
2885 * Rather than reprogramming the value in the config
2886 * register, we will handle this internally.
2888 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) {
2889 sc->tulip_slaves = root_sc->tulip_slaves;
2890 root_sc->tulip_slaves = sc;
2891 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2899 * This is the standard DEC address ROM test.
2902 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
2905 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
2906 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
2907 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
2908 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
2909 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
2912 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2914 cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
2916 if (cksum > 65535) cksum -= 65535;
2917 cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
2918 if (cksum > 65535) cksum -= 65535;
2920 if (cksum > 65535) cksum -= 65535;
2921 cksum += *(u_int16_t *) &sc->tulip_enaddr[4];
2922 if (cksum >= 65535) cksum -= 65535;
2924 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6];
2926 if (cksum != rom_cksum)
2931 * Check for various boards based on OUI. Did I say braindead?
2933 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) {
2934 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) {
2935 (*tulip_vendors[idx].vendor_identify_nic)(sc);
2940 sc->tulip_features |= TULIP_HAVE_OKROM;
2945 tulip_ifmedia_add(tulip_softc_t * const sc)
2947 tulip_media_t media;
2950 TULIP_LOCK_ASSERT(sc);
2951 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2952 if (sc->tulip_mediums[media] != NULL) {
2953 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media],
2959 sc->tulip_features |= TULIP_HAVE_NOMEDIA;
2960 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0);
2961 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE);
2962 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
2963 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0);
2964 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO);
2966 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]);
2967 sc->tulip_flags |= TULIP_PRINTMEDIA;
2968 tulip_linkup(sc, sc->tulip_media);
2973 tulip_ifmedia_change(struct ifnet * const ifp)
2975 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
2978 sc->tulip_flags |= TULIP_NEEDRESET;
2979 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
2980 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
2981 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) {
2982 tulip_media_t media;
2983 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2984 if (sc->tulip_mediums[media] != NULL
2985 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) {
2986 sc->tulip_flags |= TULIP_PRINTMEDIA;
2987 sc->tulip_flags &= ~TULIP_DIDNWAY;
2988 tulip_linkup(sc, media);
2994 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
2996 tulip_init_locked(sc);
3002 * Media status callback
3005 tulip_ifmedia_status(struct ifnet * const ifp, struct ifmediareq *req)
3007 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
3010 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
3015 req->ifm_status = IFM_AVALID;
3016 if (sc->tulip_flags & TULIP_LINKUP)
3017 req->ifm_status |= IFM_ACTIVE;
3019 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
3024 tulip_addr_filter(tulip_softc_t * const sc)
3026 struct ifmultiaddr *ifma;
3029 u_int16_t eaddr[ETHER_ADDR_LEN/2];
3032 TULIP_LOCK_ASSERT(sc);
3033 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI);
3034 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART;
3035 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3036 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3037 #if defined(IFF_ALLMULTI)
3038 if (sc->tulip_ifp->if_flags & IFF_ALLMULTI)
3039 sc->tulip_flags |= TULIP_ALLMULTI ;
3043 ifp = sc->tulip_ifp;
3044 if_maddr_rlock(ifp);
3046 /* Copy MAC address on stack to align. */
3047 if (ifp->if_input != NULL)
3048 bcopy(IF_LLADDR(ifp), eaddr, ETHER_ADDR_LEN);
3050 bcopy(sc->tulip_enaddr, eaddr, ETHER_ADDR_LEN);
3052 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
3054 if (ifma->ifma_addr->sa_family == AF_LINK)
3058 if (multicnt > 14) {
3059 u_int32_t *sp = sc->tulip_setupdata;
3062 * Some early passes of the 21140 have broken implementations of
3063 * hash-perfect mode. When we get too many multicasts for perfect
3064 * filtering with these chips, we need to switch into hash-only
3065 * mode (this is better than all-multicast on network with lots
3066 * of multicast traffic).
3068 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
3069 sc->tulip_flags |= TULIP_WANTHASHONLY;
3071 sc->tulip_flags |= TULIP_WANTHASHPERFECT;
3073 * If we have more than 14 multicasts, we have
3074 * go into hash perfect mode (512 bit multicast
3075 * hash and one perfect hardware).
3077 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
3079 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
3081 if (ifma->ifma_addr->sa_family != AF_LINK)
3084 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
3085 sp[hash >> 4] |= htole32(1 << (hash & 0xF));
3088 * No reason to use a hash if we are going to be
3089 * receiving every multicast.
3091 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
3092 hash = tulip_mchash(ifp->if_broadcastaddr);
3093 sp[hash >> 4] |= htole32(1 << (hash & 0xF));
3094 if (sc->tulip_flags & TULIP_WANTHASHONLY) {
3095 hash = tulip_mchash((caddr_t)eaddr);
3096 sp[hash >> 4] |= htole32(1 << (hash & 0xF));
3098 sp[39] = TULIP_SP_MAC(eaddr[0]);
3099 sp[40] = TULIP_SP_MAC(eaddr[1]);
3100 sp[41] = TULIP_SP_MAC(eaddr[2]);
3104 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
3105 u_int32_t *sp = sc->tulip_setupdata;
3107 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
3109 * Else can get perfect filtering for 16 addresses.
3111 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
3112 if (ifma->ifma_addr->sa_family != AF_LINK)
3114 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
3115 *sp++ = TULIP_SP_MAC(((u_int16_t *)addrp)[0]);
3116 *sp++ = TULIP_SP_MAC(((u_int16_t *)addrp)[1]);
3117 *sp++ = TULIP_SP_MAC(((u_int16_t *)addrp)[2]);
3121 * Add the broadcast address.
3124 *sp++ = TULIP_SP_MAC(0xFFFF);
3125 *sp++ = TULIP_SP_MAC(0xFFFF);
3126 *sp++ = TULIP_SP_MAC(0xFFFF);
3129 * Pad the rest with our hardware address
3131 for (; idx < 16; idx++) {
3132 *sp++ = TULIP_SP_MAC(eaddr[0]);
3133 *sp++ = TULIP_SP_MAC(eaddr[1]);
3134 *sp++ = TULIP_SP_MAC(eaddr[2]);
3137 if_maddr_runlock(ifp);
3141 tulip_reset(tulip_softc_t * const sc)
3143 tulip_ringinfo_t *ri;
3144 tulip_descinfo_t *di;
3146 u_int32_t inreset = (sc->tulip_flags & TULIP_INRESET);
3148 TULIP_LOCK_ASSERT(sc);
3150 CTR1(KTR_TULIP, "tulip_reset: inreset %d", inreset);
3153 * Brilliant. Simply brilliant. When switching modes/speeds
3154 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
3155 * bits in CSR6 and then do a software reset to get the 21140
3156 * to properly reset its internal pathways to the right places.
3159 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
3160 && sc->tulip_boardsw->bd_media_preset != NULL)
3161 (*sc->tulip_boardsw->bd_media_preset)(sc);
3163 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
3164 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
3165 33MHz that comes to two microseconds but wait a
3166 bit longer anyways) */
3169 sc->tulip_flags |= TULIP_INRESET;
3170 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
3171 sc->tulip_ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
3174 TULIP_CSR_WRITE(sc, csr_txlist, sc->tulip_txinfo.ri_dma_addr);
3175 TULIP_CSR_WRITE(sc, csr_rxlist, sc->tulip_rxinfo.ri_dma_addr);
3176 TULIP_CSR_WRITE(sc, csr_busmode,
3177 (1 << (3 /*pci_max_burst_len*/ + 8))
3178 |TULIP_BUSMODE_CACHE_ALIGN8
3179 |TULIP_BUSMODE_READMULTIPLE
3180 |(BYTE_ORDER != LITTLE_ENDIAN ?
3181 TULIP_BUSMODE_DESC_BIGENDIAN : 0));
3183 sc->tulip_txtimer = 0;
3185 * Free all the mbufs that were on the transmit ring.
3187 CTR0(KTR_TULIP, "tulip_reset: drain transmit ring");
3188 ri = &sc->tulip_txinfo;
3189 for (di = ri->ri_first; di < ri->ri_last; di++) {
3190 m = tulip_dequeue_mbuf(ri, di, SYNC_NONE);
3193 di->di_desc->d_status = 0;
3196 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
3197 ri->ri_free = ri->ri_max;
3198 TULIP_TXDESC_PRESYNC(ri);
3201 * We need to collect all the mbufs that were on the
3202 * receive ring before we reinit it either to put
3203 * them back on or to know if we have to allocate
3206 CTR0(KTR_TULIP, "tulip_reset: drain receive ring");
3207 ri = &sc->tulip_rxinfo;
3208 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
3209 ri->ri_free = ri->ri_max;
3210 for (di = ri->ri_first; di < ri->ri_last; di++) {
3211 di->di_desc->d_status = 0;
3212 di->di_desc->d_length1 = 0; di->di_desc->d_addr1 = 0;
3213 di->di_desc->d_length2 = 0; di->di_desc->d_addr2 = 0;
3215 TULIP_RXDESC_PRESYNC(ri);
3216 for (di = ri->ri_first; di < ri->ri_last; di++) {
3217 m = tulip_dequeue_mbuf(ri, di, SYNC_NONE);
3223 * If tulip_reset is being called recursively, exit quickly knowing
3224 * that when the outer tulip_reset returns all the right stuff will
3230 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
3231 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
3232 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
3233 |TULIP_STS_RXSTOPPED;
3235 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
3236 (*sc->tulip_boardsw->bd_media_select)(sc);
3237 #if defined(TULIP_DEBUG)
3238 if ((sc->tulip_flags & TULIP_NEEDRESET) == TULIP_NEEDRESET)
3239 device_printf(sc->tulip_dev,
3240 "tulip_reset: additional reset needed?!?\n");
3243 tulip_media_print(sc);
3244 if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
3245 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
3247 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
3253 tulip_init(void *arg)
3255 tulip_softc_t *sc = (tulip_softc_t *)arg;
3258 tulip_init_locked(sc);
3263 tulip_init_locked(tulip_softc_t * const sc)
3265 CTR0(KTR_TULIP, "tulip_init_locked");
3266 if (sc->tulip_ifp->if_flags & IFF_UP) {
3267 if ((sc->tulip_ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
3268 /* initialize the media */
3269 CTR0(KTR_TULIP, "tulip_init_locked: up but not running, reset chip");
3272 tulip_addr_filter(sc);
3273 sc->tulip_ifp->if_drv_flags |= IFF_DRV_RUNNING;
3274 if (sc->tulip_ifp->if_flags & IFF_PROMISC) {
3275 sc->tulip_flags |= TULIP_PROMISC;
3276 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
3277 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3279 sc->tulip_flags &= ~TULIP_PROMISC;
3280 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
3281 if (sc->tulip_flags & TULIP_ALLMULTI) {
3282 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
3284 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
3287 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
3288 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
3290 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3291 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3293 sc->tulip_ifp->if_drv_flags |= IFF_DRV_OACTIVE;
3294 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3295 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3297 CTR2(KTR_TULIP, "tulip_init_locked: intr mask %08x cmdmode %08x",
3298 sc->tulip_intrmask, sc->tulip_cmdmode);
3299 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3300 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3301 CTR1(KTR_TULIP, "tulip_init_locked: status %08x\n",
3302 TULIP_CSR_READ(sc, csr_status));
3303 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3304 tulip_txput_setup(sc);
3306 CTR0(KTR_TULIP, "tulip_init_locked: not up, reset chip");
3307 sc->tulip_ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
3309 tulip_addr_filter(sc);
3313 #define DESC_STATUS(di) (((volatile tulip_desc_t *)((di)->di_desc))->d_status)
3314 #define DESC_FLAG(di) ((di)->di_desc->d_flag)
3317 tulip_rx_intr(tulip_softc_t * const sc)
3319 TULIP_PERFSTART(rxintr)
3320 tulip_ringinfo_t * const ri = &sc->tulip_rxinfo;
3321 struct ifnet * const ifp = sc->tulip_ifp;
3323 #if defined(TULIP_DEBUG)
3327 TULIP_LOCK_ASSERT(sc);
3328 CTR0(KTR_TULIP, "tulip_rx_intr: start");
3330 TULIP_PERFSTART(rxget)
3331 tulip_descinfo_t *eop = ri->ri_nextin, *dip;
3332 int total_len = 0, last_offset = 0;
3333 struct mbuf *ms = NULL, *me = NULL;
3337 if (fillok && (ri->ri_max - ri->ri_free) < TULIP_RXQ_TARGET)
3340 #if defined(TULIP_DEBUG)
3341 if (cnt == ri->ri_max)
3345 * If the TULIP has no descriptors, there can't be any receive
3346 * descriptors to process.
3348 if (eop == ri->ri_nextout)
3352 * 90% of the packets will fit in one descriptor. So we optimize
3355 TULIP_RXDESC_POSTSYNC(ri);
3356 if ((DESC_STATUS(eop) & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
3357 ms = tulip_dequeue_mbuf(ri, eop, SYNC_RX);
3359 "tulip_rx_intr: single packet mbuf %p from descriptor %td", ms,
3360 eop - ri->ri_first);
3365 * If still owned by the TULIP, don't touch it.
3367 if (DESC_STATUS(eop) & TULIP_DSTS_OWNER)
3371 * It is possible (though improbable unless MCLBYTES < 1518) for
3372 * a received packet to cross more than one receive descriptor.
3373 * We first loop through the descriptor ring making sure we have
3374 * received a complete packet. If not, we bail until the next
3378 while ((DESC_STATUS(eop) & TULIP_DSTS_RxLASTDESC) == 0) {
3379 if (++eop == ri->ri_last)
3381 TULIP_RXDESC_POSTSYNC(ri);
3382 if (eop == ri->ri_nextout || DESC_STATUS(eop) & TULIP_DSTS_OWNER) {
3383 #if defined(TULIP_DEBUG)
3384 sc->tulip_dbg.dbg_rxintrs++;
3385 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
3387 TULIP_PERFEND(rxget);
3388 TULIP_PERFEND(rxintr);
3395 * Dequeue the first buffer for the start of the packet. Hopefully
3396 * this will be the only one we need to dequeue. However, if the
3397 * packet consumed multiple descriptors, then we need to dequeue
3398 * those buffers and chain to the starting mbuf. All buffers but
3399 * the last buffer have the same length so we can set that now.
3400 * (we add to last_offset instead of multiplying since we normally
3401 * won't go into the loop and thereby saving ourselves from
3402 * doing a multiplication by 0 in the normal case).
3404 ms = tulip_dequeue_mbuf(ri, dip, SYNC_RX);
3406 "tulip_rx_intr: start packet mbuf %p from descriptor %td", ms,
3407 dip - ri->ri_first);
3409 for (me = ms; total_len > 0; total_len--) {
3410 me->m_len = TULIP_RX_BUFLEN;
3411 last_offset += TULIP_RX_BUFLEN;
3412 if (++dip == ri->ri_last)
3414 me->m_next = tulip_dequeue_mbuf(ri, dip, SYNC_RX);
3418 "tulip_rx_intr: cont packet mbuf %p from descriptor %td",
3419 me, dip - ri->ri_first);
3421 KASSERT(dip == eop, ("mismatched descinfo structs"));
3425 * Now get the size of received packet (minus the CRC).
3427 total_len = ((DESC_STATUS(eop) >> 16) & 0x7FFF) - ETHER_CRC_LEN;
3428 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
3429 && ((DESC_STATUS(eop) & TULIP_DSTS_ERRSUM) == 0)) {
3430 me->m_len = total_len - last_offset;
3431 sc->tulip_flags |= TULIP_RXACT;
3433 CTR1(KTR_TULIP, "tulip_rx_intr: good packet; length %d",
3436 CTR1(KTR_TULIP, "tulip_rx_intr: bad packet; status %08x",
3439 if (DESC_STATUS(eop) & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3440 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3442 #if defined(TULIP_VERBOSE)
3443 const char *error = NULL;
3445 if (DESC_STATUS(eop) & TULIP_DSTS_RxTOOLONG) {
3446 sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
3447 #if defined(TULIP_VERBOSE)
3448 error = "frame too long";
3451 if (DESC_STATUS(eop) & TULIP_DSTS_RxBADCRC) {
3452 if (DESC_STATUS(eop) & TULIP_DSTS_RxDRBBLBIT) {
3453 sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
3454 #if defined(TULIP_VERBOSE)
3455 error = "alignment error";
3458 sc->tulip_dot3stats.dot3StatsFCSErrors++;
3459 #if defined(TULIP_VERBOSE)
3464 #if defined(TULIP_VERBOSE)
3465 if (error != NULL && (sc->tulip_flags & TULIP_NOMESSAGES) == 0) {
3466 device_printf(sc->tulip_dev, "receive: %6D: %s\n",
3467 mtod(ms, u_char *) + 6, ":",
3469 sc->tulip_flags |= TULIP_NOMESSAGES;
3475 #if defined(TULIP_DEBUG)
3479 if (++eop == ri->ri_last)
3481 ri->ri_nextin = eop;
3484 * We have received a good packet that needs to be passed up the
3490 KASSERT(ms != NULL, ("no packet to accept"));
3491 #if defined(TULIP_COPY_RXDATA)
3493 * Copy the data into a new mbuf that is properly aligned. If
3494 * we fail to allocate a new mbuf, then drop the packet. We will
3495 * reuse the same rx buffer ('ms') below for another packet
3498 m0 = m_devget(mtod(ms, caddr_t), total_len, ETHER_ALIGN, ifp, NULL);
3505 * Update the header for the mbuf referencing this receive
3506 * buffer and pass it up the stack. Allocate a new mbuf cluster
3507 * to replace the one we just passed up the stack.
3509 * Note that if this packet crossed multiple descriptors
3510 * we don't even try to reallocate all the mbufs here.
3511 * Instead we rely on the test at the beginning of
3512 * the loop to refill for the extra consumed mbufs.
3514 ms->m_pkthdr.len = total_len;
3515 ms->m_pkthdr.rcvif = ifp;
3517 ms = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
3520 CTR1(KTR_TULIP, "tulip_rx_intr: passing %p to upper layer", m0);
3521 (*ifp->if_input)(ifp, m0);
3523 } else if (ms == NULL)
3525 * If we are priming the TULIP with mbufs, then allocate
3526 * a new cluster for the next descriptor.
3528 ms = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
3530 #if defined(TULIP_COPY_RXDATA)
3535 * Couldn't allocate a new buffer. Don't bother
3536 * trying to replenish the receive queue.
3539 sc->tulip_flags |= TULIP_RXBUFSLOW;
3540 #if defined(TULIP_DEBUG)
3541 sc->tulip_dbg.dbg_rxlowbufs++;
3543 TULIP_PERFEND(rxget);
3547 * Now give the buffer(s) to the TULIP and save in our
3551 tulip_descinfo_t * const nextout = ri->ri_nextout;
3554 KASSERT(ms->m_data == ms->m_ext.ext_buf,
3555 ("rx mbuf data doesn't point to cluster"));
3556 ms->m_len = ms->m_pkthdr.len = TULIP_RX_BUFLEN;
3557 error = bus_dmamap_load_mbuf(ri->ri_data_tag, *nextout->di_map, ms,
3558 tulip_dma_map_rxbuf, nextout->di_desc, BUS_DMA_NOWAIT);
3560 device_printf(sc->tulip_dev,
3561 "unable to load rx map, error = %d\n", error);
3562 panic("tulip_rx_intr"); /* XXX */
3564 nextout->di_desc->d_status = TULIP_DSTS_OWNER;
3565 KASSERT(nextout->di_mbuf == NULL, ("clobbering earlier rx mbuf"));
3566 nextout->di_mbuf = ms;
3567 CTR2(KTR_TULIP, "tulip_rx_intr: enqueued mbuf %p to descriptor %td",
3568 ms, nextout - ri->ri_first);
3569 TULIP_RXDESC_POSTSYNC(ri);
3570 if (++ri->ri_nextout == ri->ri_last)
3571 ri->ri_nextout = ri->ri_first;
3575 } while ((ms = me) != NULL);
3577 if ((ri->ri_max - ri->ri_free) >= TULIP_RXQ_TARGET)
3578 sc->tulip_flags &= ~TULIP_RXBUFSLOW;
3579 TULIP_PERFEND(rxget);
3582 #if defined(TULIP_DEBUG)
3583 sc->tulip_dbg.dbg_rxintrs++;
3584 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
3586 TULIP_PERFEND(rxintr);
3590 tulip_tx_intr(tulip_softc_t * const sc)
3592 TULIP_PERFSTART(txintr)
3593 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
3598 CTR0(KTR_TULIP, "tulip_tx_intr: start");
3599 TULIP_LOCK_ASSERT(sc);
3600 while (ri->ri_free < ri->ri_max) {
3603 TULIP_TXDESC_POSTSYNC(ri);
3604 if (DESC_STATUS(ri->ri_nextin) & TULIP_DSTS_OWNER)
3609 d_flag = DESC_FLAG(ri->ri_nextin);
3610 if (d_flag & TULIP_DFLAG_TxLASTSEG) {
3611 if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
3613 "tulip_tx_intr: setup packet from descriptor %td: %08x",
3614 ri->ri_nextin - ri->ri_first, DESC_STATUS(ri->ri_nextin));
3616 * We've just finished processing a setup packet.
3617 * Mark that we finished it. If there's not
3618 * another pending, startup the TULIP receiver.
3619 * Make sure we ack the RXSTOPPED so we won't get
3620 * an abormal interrupt indication.
3622 bus_dmamap_sync(sc->tulip_setup_tag, sc->tulip_setup_map,
3623 BUS_DMASYNC_POSTWRITE);
3624 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
3625 if (DESC_FLAG(ri->ri_nextin) & TULIP_DFLAG_TxINVRSFILT)
3626 sc->tulip_flags |= TULIP_HASHONLY;
3627 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
3629 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3630 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3632 "tulip_tx_intr: intr mask %08x cmdmode %08x",
3633 sc->tulip_intrmask, sc->tulip_cmdmode);
3634 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3635 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3636 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3639 const u_int32_t d_status = DESC_STATUS(ri->ri_nextin);
3641 m = tulip_dequeue_mbuf(ri, ri->ri_nextin, SYNC_TX);
3643 "tulip_tx_intr: data packet %p from descriptor %td", m,
3644 ri->ri_nextin - ri->ri_first);
3647 #if defined(TULIP_DEBUG)
3649 device_printf(sc->tulip_dev,
3650 "tx_intr: failed to dequeue mbuf?!?\n");
3653 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3654 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
3655 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
3656 #if defined(TULIP_DEBUG)
3657 if (d_status & TULIP_DSTS_TxNOCARR)
3658 sc->tulip_dbg.dbg_txprobe_nocarr++;
3659 if (d_status & TULIP_DSTS_TxEXCCOLL)
3660 sc->tulip_dbg.dbg_txprobe_exccoll++;
3662 event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
3664 (*sc->tulip_boardsw->bd_media_poll)(sc, event);
3666 * Escape from the loop before media poll has reset the TULIP!
3671 if (d_status & TULIP_DSTS_ERRSUM) {
3672 CTR1(KTR_TULIP, "tulip_tx_intr: output error: %08x",
3674 sc->tulip_ifp->if_oerrors++;
3675 if (d_status & TULIP_DSTS_TxEXCCOLL)
3676 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
3677 if (d_status & TULIP_DSTS_TxLATECOLL)
3678 sc->tulip_dot3stats.dot3StatsLateCollisions++;
3679 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
3680 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
3681 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
3682 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
3683 if (d_status & TULIP_DSTS_TxUNDERFLOW)
3684 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
3685 if (d_status & TULIP_DSTS_TxBABBLE)
3686 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
3688 u_int32_t collisions =
3689 (d_status & TULIP_DSTS_TxCOLLMASK)
3690 >> TULIP_DSTS_V_TxCOLLCNT;
3693 "tulip_tx_intr: output ok, collisions %d, status %08x",
3694 collisions, d_status);
3695 sc->tulip_ifp->if_collisions += collisions;
3696 if (collisions == 1)
3697 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
3698 else if (collisions > 1)
3699 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
3700 else if (d_status & TULIP_DSTS_TxDEFERRED)
3701 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
3703 * SQE is only valid for 10baseT/BNC/AUI when not
3704 * running in full-duplex. In order to speed up the
3705 * test, the corresponding bit in tulip_flags needs to
3706 * set as well to get us to count SQE Test Errors.
3708 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
3709 sc->tulip_dot3stats.dot3StatsSQETestErrors++;
3715 if (++ri->ri_nextin == ri->ri_last)
3716 ri->ri_nextin = ri->ri_first;
3718 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3719 sc->tulip_ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
3722 * If nothing left to transmit, disable the timer.
3723 * Else if progress, reset the timer back to 2 ticks.
3725 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
3726 sc->tulip_txtimer = 0;
3728 sc->tulip_txtimer = TULIP_TXTIMER;
3729 sc->tulip_ifp->if_opackets += xmits;
3730 TULIP_PERFEND(txintr);
3735 tulip_print_abnormal_interrupt(tulip_softc_t * const sc, u_int32_t csr)
3737 const char * const *msgp = tulip_status_bits;
3740 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
3742 TULIP_LOCK_ASSERT(sc);
3743 csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1;
3744 device_printf(sc->tulip_dev, "abnormal interrupt:");
3745 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
3746 if ((csr & mask) && *msgp != NULL) {
3747 printf("%s%s", sep, *msgp);
3748 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
3749 sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
3750 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
3751 printf(" (switching to store-and-forward mode)");
3753 printf(" (raising TX threshold to %s)",
3754 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
3764 tulip_intr_handler(tulip_softc_t * const sc)
3766 TULIP_PERFSTART(intr)
3769 CTR0(KTR_TULIP, "tulip_intr_handler invoked");
3770 TULIP_LOCK_ASSERT(sc);
3771 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3772 TULIP_CSR_WRITE(sc, csr_status, csr);
3774 if (csr & TULIP_STS_SYSERROR) {
3775 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
3776 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3777 sc->tulip_flags |= TULIP_SYSTEMERROR;
3779 device_printf(sc->tulip_dev, "system error: %s\n",
3780 tulip_system_errors[sc->tulip_last_system_error]);
3782 sc->tulip_flags |= TULIP_NEEDRESET;
3783 sc->tulip_system_errors++;
3786 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
3787 #if defined(TULIP_DEBUG)
3788 sc->tulip_dbg.dbg_link_intrs++;
3790 if (sc->tulip_boardsw->bd_media_poll != NULL) {
3791 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
3792 ? TULIP_MEDIAPOLL_LINKFAIL
3793 : TULIP_MEDIAPOLL_LINKPASS);
3794 csr &= ~TULIP_STS_ABNRMLINTR;
3796 tulip_media_print(sc);
3798 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
3799 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
3800 if (csr & TULIP_STS_RXNOBUF)
3801 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
3803 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3804 * on receive overflows.
3806 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
3807 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3809 * Stop the receiver process and spin until it's stopped.
3810 * Tell rx_intr to drop the packets it dequeues.
3812 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
3813 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
3815 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3816 sc->tulip_flags |= TULIP_RXIGNORE;
3819 if (sc->tulip_flags & TULIP_RXIGNORE) {
3821 * Restart the receiver.
3823 sc->tulip_flags &= ~TULIP_RXIGNORE;
3824 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3827 if (csr & TULIP_STS_ABNRMLINTR) {
3828 u_int32_t tmp = csr & sc->tulip_intrmask
3829 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
3830 if (csr & TULIP_STS_TXUNDERFLOW) {
3831 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
3832 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
3833 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3834 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
3835 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
3836 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3839 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3840 sc->tulip_statusbits |= tmp;
3842 tulip_print_abnormal_interrupt(sc, tmp);
3843 sc->tulip_flags |= TULIP_NOMESSAGES;
3845 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3847 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
3849 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3850 tulip_start_locked(sc);
3853 if (sc->tulip_flags & TULIP_NEEDRESET) {
3855 tulip_init_locked(sc);
3857 TULIP_PERFEND(intr);
3861 tulip_intr_shared(void *arg)
3863 tulip_softc_t * sc = arg;
3865 for (; sc != NULL; sc = sc->tulip_slaves) {
3867 #if defined(TULIP_DEBUG)
3868 sc->tulip_dbg.dbg_intrs++;
3870 tulip_intr_handler(sc);
3876 tulip_intr_normal(void *arg)
3878 tulip_softc_t * sc = (tulip_softc_t *) arg;
3881 #if defined(TULIP_DEBUG)
3882 sc->tulip_dbg.dbg_intrs++;
3884 tulip_intr_handler(sc);
3888 static struct mbuf *
3889 tulip_txput(tulip_softc_t * const sc, struct mbuf *m)
3891 TULIP_PERFSTART(txput)
3892 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
3893 tulip_descinfo_t *eop, *nextout;
3896 bus_dma_segment_t segs[TULIP_MAX_TXSEG];
3901 TULIP_LOCK_ASSERT(sc);
3902 #if defined(TULIP_DEBUG)
3903 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
3904 device_printf(sc->tulip_dev, "txput%s: tx not running\n",
3905 (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : "");
3906 sc->tulip_flags |= TULIP_WANTTXSTART;
3907 sc->tulip_dbg.dbg_txput_finishes[0]++;
3913 * Now we try to fill in our transmit descriptors. This is
3914 * a bit reminiscent of going on the Ark two by two
3915 * since each descriptor for the TULIP can describe
3916 * two buffers. So we advance through packet filling
3917 * each of the two entries at a time to to fill each
3918 * descriptor. Clear the first and last segment bits
3919 * in each descriptor (actually just clear everything
3920 * but the end-of-ring or chain bits) to make sure
3921 * we don't get messed up by previously sent packets.
3923 * We may fail to put the entire packet on the ring if
3924 * there is either not enough ring entries free or if the
3925 * packet has more than MAX_TXSEG segments. In the former
3926 * case we will just wait for the ring to empty. In the
3927 * latter case we have to recopy.
3929 #if defined(KTR) && KTR_TULIP
3932 while (m0->m_next != NULL) {
3937 CTR2(KTR_TULIP, "tulip_txput: sending packet %p (%d chunks)", m, segcnt);
3939 eop = nextout = ri->ri_nextout;
3944 * Reclaim some tx descriptors if we are out since we need at least one
3945 * free descriptor so that we have a dma_map to load the mbuf.
3948 #if defined(TULIP_DEBUG)
3949 sc->tulip_dbg.dbg_no_txmaps++;
3951 free += tulip_tx_intr(sc);
3954 sc->tulip_flags |= TULIP_WANTTXSTART;
3955 #if defined(TULIP_DEBUG)
3956 sc->tulip_dbg.dbg_txput_finishes[1]++;
3960 error = bus_dmamap_load_mbuf_sg(ri->ri_data_tag, *eop->di_map, m, segs,
3961 &nsegs, BUS_DMA_NOWAIT);
3963 if (error == EFBIG) {
3965 * The packet exceeds the number of transmit buffer
3966 * entries that we can use for one packet, so we have
3967 * to recopy it into one mbuf and then try again. If
3968 * we can't recopy it, try again later.
3970 m0 = m_defrag(m, M_DONTWAIT);
3972 sc->tulip_flags |= TULIP_WANTTXSTART;
3973 #if defined(TULIP_DEBUG)
3974 sc->tulip_dbg.dbg_txput_finishes[2]++;
3979 error = bus_dmamap_load_mbuf_sg(ri->ri_data_tag, *eop->di_map, m,
3980 segs, &nsegs, BUS_DMA_NOWAIT);
3983 device_printf(sc->tulip_dev,
3984 "unable to load tx map, error = %d\n", error);
3985 #if defined(TULIP_DEBUG)
3986 sc->tulip_dbg.dbg_txput_finishes[3]++;
3991 CTR1(KTR_TULIP, "tulip_txput: nsegs %d", nsegs);
3994 * Each descriptor allows for up to 2 fragments since we don't use
3995 * the descriptor chaining mode in this driver.
3997 if ((free -= (nsegs + 1) / 2) <= 0
3999 * See if there's any unclaimed space in the transmit ring.
4001 && (free += tulip_tx_intr(sc)) <= 0) {
4003 * There's no more room but since nothing
4004 * has been committed at this point, just
4005 * show output is active, put back the
4008 sc->tulip_flags |= TULIP_WANTTXSTART;
4009 #if defined(TULIP_DEBUG)
4010 sc->tulip_dbg.dbg_txput_finishes[4]++;
4012 bus_dmamap_unload(ri->ri_data_tag, *eop->di_map);
4015 for (; nsegs - segcnt > 1; segcnt += 2) {
4017 eop->di_desc->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4018 eop->di_desc->d_status = d_status;
4019 eop->di_desc->d_addr1 = segs[segcnt].ds_addr;
4020 eop->di_desc->d_length1 = segs[segcnt].ds_len;
4021 eop->di_desc->d_addr2 = segs[segcnt+1].ds_addr;
4022 eop->di_desc->d_length2 = segs[segcnt+1].ds_len;
4023 d_status = TULIP_DSTS_OWNER;
4024 if (++nextout == ri->ri_last)
4025 nextout = ri->ri_first;
4027 if (segcnt < nsegs) {
4029 eop->di_desc->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4030 eop->di_desc->d_status = d_status;
4031 eop->di_desc->d_addr1 = segs[segcnt].ds_addr;
4032 eop->di_desc->d_length1 = segs[segcnt].ds_len;
4033 eop->di_desc->d_addr2 = 0;
4034 eop->di_desc->d_length2 = 0;
4035 if (++nextout == ri->ri_last)
4036 nextout = ri->ri_first;
4040 * tulip_tx_intr() harvests the mbuf from the last descriptor in the
4041 * frame. We just used the dmamap in the first descriptor for the
4042 * load operation however. Thus, to let the tulip_dequeue_mbuf() call
4043 * in tulip_tx_intr() unload the correct dmamap, we swap the dmamap
4044 * pointers in the two descriptors if this is a multiple-descriptor
4047 if (eop != ri->ri_nextout) {
4049 eop->di_map = ri->ri_nextout->di_map;
4050 ri->ri_nextout->di_map = map;
4054 * bounce a copy to the bpf listener, if any.
4056 if (!(sc->tulip_flags & TULIP_DEVICEPROBE))
4057 BPF_MTAP(sc->tulip_ifp, m);
4060 * The descriptors have been filled in. Now get ready
4063 CTR3(KTR_TULIP, "tulip_txput: enqueued mbuf %p to descriptors %td - %td",
4064 m, ri->ri_nextout - ri->ri_first, eop - ri->ri_first);
4065 KASSERT(eop->di_mbuf == NULL, ("clobbering earlier tx mbuf"));
4067 TULIP_TXMAP_PRESYNC(ri, ri->ri_nextout);
4071 * Make sure the next descriptor after this packet is owned
4072 * by us since it may have been set up above if we ran out
4073 * of room in the ring.
4075 nextout->di_desc->d_status = 0;
4076 TULIP_TXDESC_PRESYNC(ri);
4079 * Mark the last and first segments, indicate we want a transmit
4080 * complete interrupt, and tell it to transmit!
4082 eop->di_desc->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
4085 * Note that ri->ri_nextout is still the start of the packet
4086 * and until we set the OWNER bit, we can still back out of
4087 * everything we have done.
4089 ri->ri_nextout->di_desc->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
4090 TULIP_TXDESC_PRESYNC(ri);
4091 ri->ri_nextout->di_desc->d_status = TULIP_DSTS_OWNER;
4092 TULIP_TXDESC_PRESYNC(ri);
4095 * This advances the ring for us.
4097 ri->ri_nextout = nextout;
4100 TULIP_PERFEND(txput);
4102 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
4103 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4104 sc->tulip_ifp->if_drv_flags |= IFF_DRV_OACTIVE;
4105 TULIP_PERFEND(txput);
4110 * switch back to the single queueing ifstart.
4112 sc->tulip_flags &= ~TULIP_WANTTXSTART;
4113 if (sc->tulip_txtimer == 0)
4114 sc->tulip_txtimer = TULIP_TXTIMER;
4115 #if defined(TULIP_DEBUG)
4116 sc->tulip_dbg.dbg_txput_finishes[5]++;
4120 * If we want a txstart, there must be not enough space in the
4121 * transmit ring. So we want to enable transmit done interrupts
4122 * so we can immediately reclaim some space. When the transmit
4123 * interrupt is posted, the interrupt handler will call tx_intr
4124 * to reclaim space and then txstart (since WANTTXSTART is set).
4125 * txstart will move the packet into the transmit ring and clear
4126 * WANTTXSTART thereby causing TXINTR to be cleared.
4129 #if defined(TULIP_DEBUG)
4130 sc->tulip_dbg.dbg_txput_finishes[6]++;
4132 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
4133 sc->tulip_ifp->if_drv_flags |= IFF_DRV_OACTIVE;
4134 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
4135 sc->tulip_intrmask |= TULIP_STS_TXINTR;
4136 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4138 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) {
4139 if (sc->tulip_intrmask & TULIP_STS_TXINTR) {
4140 sc->tulip_intrmask &= ~TULIP_STS_TXINTR;
4141 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4144 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4145 TULIP_PERFEND(txput);
4150 tulip_txput_setup(tulip_softc_t * const sc)
4152 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
4153 tulip_desc_t *nextout;
4155 TULIP_LOCK_ASSERT(sc);
4158 * We will transmit, at most, one setup packet per call to ifstart.
4161 #if defined(TULIP_DEBUG)
4162 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
4163 device_printf(sc->tulip_dev, "txput_setup: tx not running\n");
4164 sc->tulip_flags |= TULIP_WANTTXSTART;
4169 * Try to reclaim some free descriptors..
4171 if (ri->ri_free < 2)
4173 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
4174 sc->tulip_flags |= TULIP_WANTTXSTART;
4177 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
4178 sizeof(sc->tulip_setupdata));
4180 * Clear WANTSETUP and set DOINGSETUP. Since we know that WANTSETUP is
4181 * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
4183 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP;
4185 nextout = ri->ri_nextout->di_desc;
4186 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4187 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
4188 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
4189 if (sc->tulip_flags & TULIP_WANTHASHPERFECT)
4190 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
4191 else if (sc->tulip_flags & TULIP_WANTHASHONLY)
4192 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT;
4194 nextout->d_length2 = 0;
4195 nextout->d_addr2 = 0;
4196 nextout->d_length1 = sizeof(sc->tulip_setupdata);
4197 nextout->d_addr1 = sc->tulip_setup_dma_addr;
4198 bus_dmamap_sync(sc->tulip_setup_tag, sc->tulip_setup_map,
4199 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
4200 TULIP_TXDESC_PRESYNC(ri);
4201 CTR1(KTR_TULIP, "tulip_txput_setup: using descriptor %td",
4202 ri->ri_nextout - ri->ri_first);
4205 * Advance the ring for the next transmit packet.
4207 if (++ri->ri_nextout == ri->ri_last)
4208 ri->ri_nextout = ri->ri_first;
4211 * Make sure the next descriptor is owned by us since it
4212 * may have been set up above if we ran out of room in the
4215 ri->ri_nextout->di_desc->d_status = 0;
4216 TULIP_TXDESC_PRESYNC(ri);
4217 nextout->d_status = TULIP_DSTS_OWNER;
4219 * Flush the ownwership of the current descriptor
4221 TULIP_TXDESC_PRESYNC(ri);
4222 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4223 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
4224 sc->tulip_intrmask |= TULIP_STS_TXINTR;
4225 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4230 tulip_ifioctl(struct ifnet * ifp, u_long cmd, caddr_t data)
4232 TULIP_PERFSTART(ifioctl)
4233 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4234 struct ifreq *ifr = (struct ifreq *) data;
4238 case SIOCSIFFLAGS: {
4240 tulip_init_locked(sc);
4246 case SIOCGIFMEDIA: {
4247 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
4252 case SIOCDELMULTI: {
4254 * Update multicast listeners
4257 tulip_init_locked(sc);
4264 case SIOCGADDRROM: {
4265 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
4271 ifr->ifr_metric = (int) sc->tulip_chipid;
4276 error = ether_ioctl(ifp, cmd, data);
4281 TULIP_PERFEND(ifioctl);
4286 tulip_start(struct ifnet * const ifp)
4288 TULIP_PERFSTART(ifstart)
4289 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4292 tulip_start_locked(sc);
4295 TULIP_PERFEND(ifstart);
4299 tulip_start_locked(tulip_softc_t * const sc)
4303 TULIP_LOCK_ASSERT(sc);
4305 CTR0(KTR_TULIP, "tulip_start_locked invoked");
4306 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
4307 tulip_txput_setup(sc);
4309 CTR1(KTR_TULIP, "tulip_start_locked: %d tx packets pending",
4310 sc->tulip_ifp->if_snd.ifq_len);
4311 while (!IFQ_DRV_IS_EMPTY(&sc->tulip_ifp->if_snd)) {
4312 IFQ_DRV_DEQUEUE(&sc->tulip_ifp->if_snd, m);
4315 if ((m = tulip_txput(sc, m)) != NULL) {
4316 IFQ_DRV_PREPEND(&sc->tulip_ifp->if_snd, m);
4323 * Even though this routine runs at device spl, it does not break
4324 * our use of splnet (splsoftnet under NetBSD) for the majority
4325 * of this driver since
4326 * if_watcbog is called from if_watchdog which is called from
4327 * splsoftclock which is below spl[soft]net.
4330 tulip_ifwatchdog(struct ifnet *ifp)
4332 TULIP_PERFSTART(ifwatchdog)
4333 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4334 #if defined(TULIP_DEBUG)
4339 #if defined(TULIP_DEBUG)
4340 rxintrs = sc->tulip_dbg.dbg_rxintrs - sc->tulip_dbg.dbg_last_rxintrs;
4341 if (rxintrs > sc->tulip_dbg.dbg_high_rxintrs_hz)
4342 sc->tulip_dbg.dbg_high_rxintrs_hz = rxintrs;
4343 sc->tulip_dbg.dbg_last_rxintrs = sc->tulip_dbg.dbg_rxintrs;
4344 #endif /* TULIP_DEBUG */
4346 sc->tulip_ifp->if_timer = 1;
4348 * These should be rare so do a bulk test up front so we can just skip
4351 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) {
4353 * If the number of receive buffer is low, try to refill
4355 if (sc->tulip_flags & TULIP_RXBUFSLOW)
4358 if (sc->tulip_flags & TULIP_SYSTEMERROR) {
4359 if_printf(sc->tulip_ifp, "%d system errors: last was %s\n",
4360 sc->tulip_system_errors,
4361 tulip_system_errors[sc->tulip_last_system_error]);
4363 if (sc->tulip_statusbits) {
4364 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
4365 sc->tulip_statusbits = 0;
4368 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR);
4371 if (sc->tulip_txtimer)
4373 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
4374 if_printf(sc->tulip_ifp, "transmission timeout\n");
4375 if (TULIP_DO_AUTOSENSE(sc)) {
4376 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
4377 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
4378 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP);
4381 tulip_init_locked(sc);
4384 TULIP_PERFEND(ifwatchdog);
4385 TULIP_PERFMERGE(sc, perf_intr_cycles);
4386 TULIP_PERFMERGE(sc, perf_ifstart_cycles);
4387 TULIP_PERFMERGE(sc, perf_ifioctl_cycles);
4388 TULIP_PERFMERGE(sc, perf_ifwatchdog_cycles);
4389 TULIP_PERFMERGE(sc, perf_timeout_cycles);
4390 TULIP_PERFMERGE(sc, perf_ifstart_one_cycles);
4391 TULIP_PERFMERGE(sc, perf_txput_cycles);
4392 TULIP_PERFMERGE(sc, perf_txintr_cycles);
4393 TULIP_PERFMERGE(sc, perf_rxintr_cycles);
4394 TULIP_PERFMERGE(sc, perf_rxget_cycles);
4395 TULIP_PERFMERGE(sc, perf_intr);
4396 TULIP_PERFMERGE(sc, perf_ifstart);
4397 TULIP_PERFMERGE(sc, perf_ifioctl);
4398 TULIP_PERFMERGE(sc, perf_ifwatchdog);
4399 TULIP_PERFMERGE(sc, perf_timeout);
4400 TULIP_PERFMERGE(sc, perf_ifstart_one);
4401 TULIP_PERFMERGE(sc, perf_txput);
4402 TULIP_PERFMERGE(sc, perf_txintr);
4403 TULIP_PERFMERGE(sc, perf_rxintr);
4404 TULIP_PERFMERGE(sc, perf_rxget);
4409 tulip_attach(tulip_softc_t * const sc)
4413 ifp = sc->tulip_ifp = if_alloc(IFT_ETHER);
4415 /* XXX: driver name/unit should be set some other way */
4416 if_initname(ifp, "de", sc->tulip_unit);
4418 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
4419 ifp->if_ioctl = tulip_ifioctl;
4420 ifp->if_start = tulip_start;
4421 ifp->if_watchdog = tulip_ifwatchdog;
4423 ifp->if_init = tulip_init;
4424 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
4425 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
4426 IFQ_SET_READY(&ifp->if_snd);
4428 device_printf(sc->tulip_dev, "%s%s pass %d.%d%s\n",
4430 tulip_chipdescs[sc->tulip_chipid],
4431 (sc->tulip_revinfo & 0xF0) >> 4,
4432 sc->tulip_revinfo & 0x0F,
4433 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM))
4434 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "");
4437 (*sc->tulip_boardsw->bd_media_probe)(sc);
4438 ifmedia_init(&sc->tulip_ifmedia, 0,
4439 tulip_ifmedia_change,
4440 tulip_ifmedia_status);
4441 tulip_ifmedia_add(sc);
4446 ether_ifattach(sc->tulip_ifp, sc->tulip_enaddr);
4449 sc->tulip_flags &= ~TULIP_DEVICEPROBE;
4453 /* Release memory for a single descriptor ring. */
4455 tulip_busdma_freering(tulip_ringinfo_t *ri)
4459 /* Release the DMA maps and tag for data buffers. */
4460 if (ri->ri_data_maps != NULL) {
4461 for (i = 0; i < ri->ri_max; i++) {
4462 if (ri->ri_data_maps[i] != NULL) {
4463 bus_dmamap_destroy(ri->ri_data_tag, ri->ri_data_maps[i]);
4464 ri->ri_data_maps[i] = NULL;
4467 free(ri->ri_data_maps, M_DEVBUF);
4468 ri->ri_data_maps = NULL;
4470 if (ri->ri_data_tag != NULL) {
4471 bus_dma_tag_destroy(ri->ri_data_tag);
4472 ri->ri_data_tag = NULL;
4475 /* Release the DMA memory and tag for the ring descriptors. */
4476 if (ri->ri_dma_addr != 0) {
4477 bus_dmamap_unload(ri->ri_ring_tag, ri->ri_ring_map);
4478 ri->ri_dma_addr = 0;
4480 if (ri->ri_descs != NULL) {
4481 bus_dmamem_free(ri->ri_ring_tag, ri->ri_descs, ri->ri_ring_map);
4482 ri->ri_ring_map = NULL;
4483 ri->ri_descs = NULL;
4485 if (ri->ri_ring_tag != NULL) {
4486 bus_dma_tag_destroy(ri->ri_ring_tag);
4487 ri->ri_ring_tag = NULL;
4491 /* Allocate memory for a single descriptor ring. */
4493 tulip_busdma_allocring(device_t dev, tulip_softc_t * const sc, size_t count,
4494 bus_size_t maxsize, int nsegs, tulip_ringinfo_t *ri, const char *name)
4499 /* First, setup a tag. */
4501 size = count * sizeof(tulip_desc_t);
4502 error = bus_dma_tag_create(NULL, PAGE_SIZE, 0, BUS_SPACE_MAXADDR_32BIT,
4503 BUS_SPACE_MAXADDR, NULL, NULL, size, 1, size, 0, NULL, NULL,
4506 device_printf(dev, "failed to allocate %s descriptor ring dma tag\n",
4511 /* Next, allocate memory for the descriptors. */
4512 error = bus_dmamem_alloc(ri->ri_ring_tag, (void **)&ri->ri_descs,
4513 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &ri->ri_ring_map);
4515 device_printf(dev, "failed to allocate memory for %s descriptor ring\n",
4520 /* Map the descriptors. */
4521 error = bus_dmamap_load(ri->ri_ring_tag, ri->ri_ring_map, ri->ri_descs,
4522 size, tulip_dma_map_addr, &ri->ri_dma_addr, BUS_DMA_NOWAIT);
4524 device_printf(dev, "failed to get dma address for %s descriptor ring\n",
4529 /* Allocate a tag for the data buffers. */
4530 error = bus_dma_tag_create(NULL, 4, 0,
4531 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
4532 maxsize, nsegs, TULIP_DATA_PER_DESC, 0, NULL, NULL, &ri->ri_data_tag);
4534 device_printf(dev, "failed to allocate %s buffer dma tag\n", name);
4538 /* Allocate maps for the data buffers. */
4539 ri->ri_data_maps = malloc(sizeof(bus_dmamap_t) * count, M_DEVBUF,
4541 for (i = 0; i < count; i++) {
4542 error = bus_dmamap_create(ri->ri_data_tag, 0, &ri->ri_data_maps[i]);
4544 device_printf(dev, "failed to create map for %s buffer %d\n",
4553 /* Release busdma maps, tags, and memory. */
4555 tulip_busdma_cleanup(tulip_softc_t * const sc)
4558 /* Release resources for the setup descriptor. */
4559 if (sc->tulip_setup_dma_addr != 0) {
4560 bus_dmamap_unload(sc->tulip_setup_tag, sc->tulip_setup_map);
4561 sc->tulip_setup_dma_addr = 0;
4563 if (sc->tulip_setupbuf != NULL) {
4564 bus_dmamem_free(sc->tulip_setup_tag, sc->tulip_setupbuf,
4565 sc->tulip_setup_map);
4566 sc->tulip_setup_map = NULL;
4567 sc->tulip_setupbuf = NULL;
4569 if (sc->tulip_setup_tag != NULL) {
4570 bus_dma_tag_destroy(sc->tulip_setup_tag);
4571 sc->tulip_setup_tag = NULL;
4574 /* Release the transmit ring. */
4575 tulip_busdma_freering(&sc->tulip_txinfo);
4577 /* Release the receive ring. */
4578 tulip_busdma_freering(&sc->tulip_rxinfo);
4582 tulip_busdma_init(device_t dev, tulip_softc_t * const sc)
4587 * Allocate space and dmamap for transmit ring.
4589 error = tulip_busdma_allocring(dev, sc, TULIP_TXDESCS, TULIP_DATA_PER_DESC,
4590 TULIP_MAX_TXSEG, &sc->tulip_txinfo, "transmit");
4595 * Allocate space and dmamap for receive ring. We tell bus_dma that
4596 * we can map MCLBYTES so that it will accept a full MCLBYTES cluster,
4597 * but we will only map the first TULIP_RX_BUFLEN bytes. This is not
4598 * a waste in practice though as an ethernet frame can easily fit
4599 * in TULIP_RX_BUFLEN bytes.
4601 error = tulip_busdma_allocring(dev, sc, TULIP_RXDESCS, MCLBYTES, 1,
4602 &sc->tulip_rxinfo, "receive");
4607 * Allocate a DMA tag, memory, and map for setup descriptor
4609 error = bus_dma_tag_create(NULL, 4, 0,
4610 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
4611 sizeof(sc->tulip_setupdata), 1, sizeof(sc->tulip_setupdata), 0,
4612 NULL, NULL, &sc->tulip_setup_tag);
4614 device_printf(dev, "failed to allocate setup descriptor dma tag\n");
4617 error = bus_dmamem_alloc(sc->tulip_setup_tag, (void **)&sc->tulip_setupbuf,
4618 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sc->tulip_setup_map);
4620 device_printf(dev, "failed to allocate memory for setup descriptor\n");
4623 error = bus_dmamap_load(sc->tulip_setup_tag, sc->tulip_setup_map,
4624 sc->tulip_setupbuf, sizeof(sc->tulip_setupdata),
4625 tulip_dma_map_addr, &sc->tulip_setup_dma_addr, BUS_DMA_NOWAIT);
4627 device_printf(dev, "failed to get dma address for setup descriptor\n");
4635 tulip_initcsrs(tulip_softc_t * const sc, tulip_csrptr_t csr_base,
4638 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
4639 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
4640 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
4641 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
4642 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
4643 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
4644 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
4645 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
4646 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size;
4647 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size;
4648 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size;
4649 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size;
4650 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size;
4651 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size;
4652 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
4653 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
4659 tulip_softc_t * const sc,
4660 tulip_ringinfo_t * const ri,
4665 ri->ri_descinfo = malloc(sizeof(tulip_descinfo_t) * ndescs, M_DEVBUF,
4667 for (i = 0; i < ndescs; i++) {
4668 ri->ri_descinfo[i].di_desc = &ri->ri_descs[i];
4669 ri->ri_descinfo[i].di_map = &ri->ri_data_maps[i];
4671 ri->ri_first = ri->ri_descinfo;
4672 ri->ri_max = ndescs;
4673 ri->ri_last = ri->ri_first + ri->ri_max;
4674 bzero(ri->ri_descs, sizeof(tulip_desc_t) * ri->ri_max);
4675 ri->ri_last[-1].di_desc->d_flag = TULIP_DFLAG_ENDRING;
4680 * This is the PCI configuration support.
4683 #define PCI_CBIO PCIR_BAR(0) /* Configuration Base IO Address */
4684 #define PCI_CBMA PCIR_BAR(1) /* Configuration Base Memory Address */
4685 #define PCI_CFDA 0x40 /* Configuration Driver Area */
4688 tulip_pci_probe(device_t dev)
4690 const char *name = NULL;
4692 if (pci_get_vendor(dev) != DEC_VENDORID)
4696 * Some LanMedia WAN cards use the Tulip chip, but they have
4697 * their own driver, and we should not recognize them
4699 if (pci_get_subvendor(dev) == 0x1376)
4702 switch (pci_get_device(dev)) {
4704 name = "Digital 21040 Ethernet";
4707 name = "Digital 21041 Ethernet";
4710 if (pci_get_revid(dev) >= 0x20)
4711 name = "Digital 21140A Fast Ethernet";
4713 name = "Digital 21140 Fast Ethernet";
4716 if (pci_get_revid(dev) >= 0x20)
4717 name = "Digital 21143 Fast Ethernet";
4719 name = "Digital 21142 Fast Ethernet";
4723 device_set_desc(dev, name);
4724 return BUS_PROBE_LOW_PRIORITY;
4730 tulip_shutdown(device_t dev)
4732 tulip_softc_t * const sc = device_get_softc(dev);
4733 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4734 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
4735 33MHz that comes to two microseconds but wait a
4736 bit longer anyways) */
4741 tulip_pci_attach(device_t dev)
4745 u_int32_t revinfo, cfdainfo;
4746 unsigned csroffset = TULIP_PCI_CSROFFSET;
4747 unsigned csrsize = TULIP_PCI_CSRSIZE;
4748 tulip_csrptr_t csr_base;
4749 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
4750 struct resource *res;
4753 unit = device_get_unit(dev);
4755 if (unit >= TULIP_MAX_DEVICES) {
4756 device_printf(dev, "not configured; limit of %d reached or exceeded\n",
4761 revinfo = pci_get_revid(dev);
4762 cfdainfo = pci_read_config(dev, PCI_CFDA, 4);
4764 /* turn busmaster on in case BIOS doesn't set it */
4765 pci_enable_busmaster(dev);
4767 if (pci_get_vendor(dev) == DEC_VENDORID) {
4768 if (pci_get_device(dev) == CHIPID_21040)
4769 chipid = TULIP_21040;
4770 else if (pci_get_device(dev) == CHIPID_21041)
4771 chipid = TULIP_21041;
4772 else if (pci_get_device(dev) == CHIPID_21140)
4773 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140;
4774 else if (pci_get_device(dev) == CHIPID_21142)
4775 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142;
4777 if (chipid == TULIP_CHIPID_UNKNOWN)
4780 if (chipid == TULIP_21040 && revinfo < 0x20) {
4782 "not configured; 21040 pass 2.0 required (%d.%d found)\n",
4783 revinfo >> 4, revinfo & 0x0f);
4785 } else if (chipid == TULIP_21140 && revinfo < 0x11) {
4787 "not configured; 21140 pass 1.1 required (%d.%d found)\n",
4788 revinfo >> 4, revinfo & 0x0f);
4792 sc = device_get_softc(dev);
4793 sc->tulip_dev = dev;
4794 sc->tulip_pci_busno = pci_get_bus(dev);
4795 sc->tulip_pci_devno = pci_get_slot(dev);
4796 sc->tulip_chipid = chipid;
4797 sc->tulip_flags |= TULIP_DEVICEPROBE;
4798 if (chipid == TULIP_21140 || chipid == TULIP_21140A)
4799 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD;
4800 if (chipid == TULIP_21140A && revinfo <= 0x22)
4801 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW;
4802 if (chipid == TULIP_21140)
4803 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH;
4804 if (chipid != TULIP_21040 && chipid != TULIP_21140)
4805 sc->tulip_features |= TULIP_HAVE_POWERMGMT;
4806 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) {
4807 sc->tulip_features |= TULIP_HAVE_DUALSENSE;
4808 if (chipid != TULIP_21041 || revinfo >= 0x20)
4809 sc->tulip_features |= TULIP_HAVE_SIANWAY;
4810 if (chipid != TULIP_21041)
4811 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD;
4812 if (chipid != TULIP_21041 && revinfo >= 0x20)
4813 sc->tulip_features |= TULIP_HAVE_SIA100;
4816 if (sc->tulip_features & TULIP_HAVE_POWERMGMT
4817 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) {
4818 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE);
4819 pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
4823 sc->tulip_unit = unit;
4824 sc->tulip_revinfo = revinfo;
4825 #if defined(TULIP_IOMAPPED)
4827 res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
4830 res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
4834 sc->tulip_csrs_bst = rman_get_bustag(res);
4835 sc->tulip_csrs_bsh = rman_get_bushandle(res);
4838 mtx_init(TULIP_MUTEX(sc), MTX_NETWORK_LOCK, device_get_nameunit(dev),
4840 callout_init_mtx(&sc->tulip_callout, TULIP_MUTEX(sc), 0);
4843 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
4845 if ((retval = tulip_busdma_init(dev, sc)) != 0) {
4846 device_printf(dev, "error initing bus_dma: %d\n", retval);
4847 tulip_busdma_cleanup(sc);
4848 mtx_destroy(TULIP_MUTEX(sc));
4852 retval = tulip_initring(dev, sc, &sc->tulip_rxinfo, TULIP_RXDESCS);
4854 retval = tulip_initring(dev, sc, &sc->tulip_txinfo, TULIP_TXDESCS);
4856 tulip_busdma_cleanup(sc);
4857 mtx_destroy(TULIP_MUTEX(sc));
4862 * Make sure there won't be any interrupts or such...
4864 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4865 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
4866 33MHz that comes to two microseconds but wait a
4867 bit longer anyways) */
4870 retval = tulip_read_macaddr(sc);
4873 device_printf(dev, "can't read ENET ROM (why=%d) (", retval);
4874 for (idx = 0; idx < 32; idx++)
4875 printf("%02x", sc->tulip_rombuf[idx]);
4877 device_printf(dev, "%s%s pass %d.%d\n",
4878 sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
4879 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
4880 device_printf(dev, "address unknown\n");
4882 void (*intr_rtn)(void *) = tulip_intr_normal;
4884 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
4885 intr_rtn = tulip_intr_shared;
4889 /* Setup interrupt last. */
4890 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) {
4894 res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
4895 RF_SHAREABLE | RF_ACTIVE);
4896 if (res == 0 || bus_setup_intr(dev, res, INTR_TYPE_NET |
4897 INTR_MPSAFE, NULL, intr_rtn, sc, &ih)) {
4898 device_printf(dev, "couldn't map interrupt\n");
4899 tulip_busdma_cleanup(sc);
4900 ether_ifdetach(sc->tulip_ifp);
4901 if_free(sc->tulip_ifp);
4902 mtx_destroy(TULIP_MUTEX(sc));
4910 static device_method_t tulip_pci_methods[] = {
4911 /* Device interface */
4912 DEVMETHOD(device_probe, tulip_pci_probe),
4913 DEVMETHOD(device_attach, tulip_pci_attach),
4914 DEVMETHOD(device_shutdown, tulip_shutdown),
4918 static driver_t tulip_pci_driver = {
4921 sizeof(tulip_softc_t),
4924 static devclass_t tulip_devclass;
4926 DRIVER_MODULE(de, pci, tulip_pci_driver, tulip_devclass, 0, 0);
4929 void tulip_dumpring(int unit, int ring);
4930 void tulip_dumpdesc(int unit, int ring, int desc);
4931 void tulip_status(int unit);
4934 tulip_dumpring(int unit, int ring)
4937 tulip_ringinfo_t *ri;
4938 tulip_descinfo_t *di;
4940 if (unit < 0 || unit >= TULIP_MAX_DEVICES) {
4941 db_printf("invalid unit %d\n", unit);
4946 db_printf("unit %d not present\n", unit);
4952 db_printf("receive ring:\n");
4953 ri = &sc->tulip_rxinfo;
4956 db_printf("transmit ring:\n");
4957 ri = &sc->tulip_txinfo;
4960 db_printf("invalid ring %d\n", ring);
4964 db_printf(" nextin: %td, nextout: %td, max: %d, free: %d\n",
4965 ri->ri_nextin - ri->ri_first, ri->ri_nextout - ri->ri_first,
4966 ri->ri_max, ri->ri_free);
4967 for (di = ri->ri_first; di != ri->ri_last; di++) {
4968 if (di->di_mbuf != NULL)
4969 db_printf(" descriptor %td: mbuf %p\n", di - ri->ri_first,
4971 else if (di->di_desc->d_flag & TULIP_DFLAG_TxSETUPPKT)
4972 db_printf(" descriptor %td: setup packet\n", di - ri->ri_first);
4977 tulip_dumpdesc(int unit, int ring, int desc)
4980 tulip_ringinfo_t *ri;
4981 tulip_descinfo_t *di;
4984 if (unit < 0 || unit >= TULIP_MAX_DEVICES) {
4985 db_printf("invalid unit %d\n", unit);
4990 db_printf("unit %d not present\n", unit);
4997 ri = &sc->tulip_rxinfo;
5001 ri = &sc->tulip_txinfo;
5004 db_printf("invalid ring %d\n", ring);
5008 if (desc < 0 || desc >= ri->ri_max) {
5009 db_printf("invalid descriptor %d\n", desc);
5013 db_printf("%s descriptor %d:\n", s, desc);
5014 di = &ri->ri_first[desc];
5015 db_printf(" mbuf: %p\n", di->di_mbuf);
5016 db_printf(" status: %08x flag: %03x\n", di->di_desc->d_status,
5017 di->di_desc->d_flag);
5018 db_printf(" addr1: %08x len1: %03x\n", di->di_desc->d_addr1,
5019 di->di_desc->d_length1);
5020 db_printf(" addr2: %08x len2: %03x\n", di->di_desc->d_addr2,
5021 di->di_desc->d_length2);