1 /* $NetBSD: if_ade.c,v 1.35 2009/03/14 21:04:01 dsl Exp $ */
4 * NOTE: this version of if_de was modified for bounce buffers prior
5 * to the introduction of bus_dma to netbsd. When a busified if_de
6 * is available and the a12 platform bus_dma is complete, then this
7 * module will be taken for a long walk on a short pier.
10 /* [Notice revision 2.0]
11 * Copyright (c) 1997 Avalon Computer Systems, Inc.
12 * All rights reserved.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright and
20 * author notice, this list of conditions, and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. Neither the name of Avalon Computer Systems, Inc. nor the names of
25 * its contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 * 4. This copyright will be assigned to The NetBSD Foundation on
28 * 1/1/2000 unless these terms (including possibly the assignment
29 * date) are updated in writing by Avalon prior to the latest specified
32 * THIS SOFTWARE IS PROVIDED BY AVALON COMPUTER SYSTEMS, INC. AND CONTRIBUTORS
33 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
34 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
35 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
36 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGE.
45 * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com)
46 * All rights reserved.
48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions
51 * 1. Redistributions of source code must retain the above copyright
52 * notice, this list of conditions and the following disclaimer.
53 * 2. The name of the author may not be used to endorse or promote products
54 * derived from this software without specific prior written permission
56 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
57 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
58 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
59 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
60 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
62 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
63 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
64 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
65 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 * Id: if_de.c,v 1.83 1997/03/25 21:12:17 thomas Exp
72 * DEC 21040 PCI Ethernet Controller
74 * Written by Matt Thomas
75 * BPF support code stolen directly from if_ec.c
77 * This driver supports the DEC DE435 or any other PCI
78 * board which support 21040, 21041, or 21140 (mostly).
80 #define TULIP_HDR_DATA
83 #include <sys/cdefs.h>
84 __KERNEL_RCSID(0, "$NetBSD: if_ade.c,v 1.35 2009/03/14 21:04:01 dsl Exp $");
89 #include <sys/param.h>
90 #include <sys/systm.h>
92 #include <sys/protosw.h>
93 #include <sys/socket.h>
94 #include <sys/ioctl.h>
95 #include <sys/errno.h>
96 #include <sys/malloc.h>
97 #include <sys/kernel.h>
98 #include <sys/proc.h> /* only for declaration of wakeup() used by vm.h */
99 #if defined(__FreeBSD__)
100 #include <machine/clock.h>
101 #elif defined(__bsdi__) || defined(__NetBSD__)
102 #include <sys/device.h>
106 #include <net/if_media.h>
107 #include <net/if_types.h>
108 #include <net/if_dl.h>
109 #include <net/route.h>
110 #include <net/netisr.h>
112 #if defined(__bsdi__) && _BSDI_VERSION >= 199701
113 #include <dev/mii/mii.h>
114 #include <dev/mii/miivar.h>
117 #include "bpfilter.h"
120 #include <net/bpfdesc.h>
124 #include <netinet/in.h>
125 #include <netinet/in_systm.h>
126 #include <netinet/in_var.h>
127 #include <netinet/ip.h>
131 #include <netns/ns.h>
132 #include <netns/ns_if.h>
135 #include <uvm/uvm_extern.h>
137 #if defined(__FreeBSD__)
140 #include <netinet/if_ether.h>
142 #include <pci/pcivar.h>
143 #include <pci/dc21040.h>
144 #define DEVAR_INCLUDE "pci/if_devar.h"
146 #endif /* __FreeBSD__ */
148 #if defined(__bsdi__)
149 #include <netinet/if_ether.h>
150 #include <i386/pci/ic/dc21040.h>
151 #include <i386/isa/isa.h>
152 #include <i386/isa/icu.h>
153 #include <i386/isa/dma.h>
154 #include <i386/isa/isavar.h>
155 #include <i386/pci/pci.h>
156 #if _BSDI_VERSION < 199510
161 #if NEISA > 0 && _BSDI_VERSION >= 199401
162 #include <i386/eisa/eisa.h>
165 #define DEVAR_INCLUDE "i386/pci/if_devar.h"
166 #endif /* __bsdi__ */
168 #if defined(__NetBSD__)
169 #include <net/if_ether.h>
171 #include <netinet/if_inarp.h>
173 #include <machine/bus.h>
174 #if defined(__alpha__)
175 #include <machine/intr.h>
177 #include <dev/pci/pcireg.h>
178 #include <dev/pci/pcivar.h>
179 #include <dev/ic/dc21040reg.h>
180 #endif /* __NetBSD__ */
183 * Intel CPUs should use I/O mapped access.
185 #if defined(__i386__) || defined(TULIP_EISA)
186 #define TULIP_IOMAPPED
191 * This turns on all sort of debugging stuff and make the
192 * driver much larger.
198 #define TULIP_USE_SOFTINTR
203 #include <alpha/a12/if_adevar.h>
204 tulip_softc_t
* debug_sc
; /* XXX */
206 * This module supports
207 * the DEC 21040 PCI Ethernet Controller.
208 * the DEC 21041 PCI Ethernet Controller.
209 * the DEC 21140 PCI Fast Ethernet Controller.
212 static void tulip_mii_autonegotiate(tulip_softc_t
* const sc
, const unsigned phyaddr
);
213 static tulip_intrfunc_t
tulip_intr_shared(void *arg
);
214 static tulip_intrfunc_t
tulip_intr_normal(void *arg
);
215 static void tulip_init(tulip_softc_t
* const sc
);
216 static void tulip_reset(tulip_softc_t
* const sc
);
217 static ifnet_ret_t
tulip_ifstart(struct ifnet
*ifp
);
218 static void tulip_rx_intr(tulip_softc_t
* const sc
);
219 static void tulip_addr_filter(tulip_softc_t
* const sc
);
220 static unsigned tulip_mii_readreg(tulip_softc_t
* const sc
, unsigned devaddr
, unsigned regno
);
221 static void tulip_mii_writereg(tulip_softc_t
* const sc
, unsigned devaddr
, unsigned regno
, unsigned data
);
222 static int tulip_mii_map_abilities(tulip_softc_t
* const sc
, unsigned abilities
);
223 static tulip_media_t
tulip_mii_phy_readspecific(tulip_softc_t
* const sc
);
224 static int tulip_srom_decode(tulip_softc_t
* const sc
);
225 static int tulip_ifmedia_change(struct ifnet
* const ifp
);
226 static void tulip_ifmedia_status(struct ifnet
* const ifp
, struct ifmediareq
*req
);
227 /* static void tulip_21140_map_media(tulip_softc_t *sc); */
229 static void reset_lcl_dma(tulip_softc_t
* const sc
);
230 static void a12_m_copydata(struct mbuf
*m
, int off
, int len
, void *cp
);
231 static void dumpring(void **);
233 * Note for LCLDMA mods. These are for systems such as the Avalon
234 * A12 that can't DMA to main memory, but instead have an essentially
235 * dual-ported local buffer memory. Other systems with this kind
236 * of bus architecture include many of the VAXstation models. Of
237 * course, they won't be needing de(4) drivers.
240 donothing(struct mbuf
*m
, void *buf
, size_t size
, void *arg
)
243 if (__predict_true(m
!= NULL
)) {
244 pool_cache_put(mb_cache
, m
);
248 static void a12r2pb(void *vsrc
, void *vdst
, int len
) {
251 offset
, /* destination misalignment */
252 t
, /* segment count */
253 llw
; /* last longword index */
258 offset
= (long)dst
& 7;
259 dst
= (long *)((long)dst
& ~7L);
265 llw
= (t
+offset
) >> 3;
266 if(((t
|offset
) & 7) == 0 && llw
)
268 else bounce
[llw
] = dst
[llw
];
270 * The whole idea is that llw indexes the first long
271 * that contains at least 1 byte NOT to be overwritten.
272 * If we are an even, aligned transfer, then bump down
273 * llw to avoid an extra load/store to the slow buffer
278 memcpy((int8_t *)bounce
+offset
,src
,t
);
279 for(i
=llw
; i
>=0; --i
) { /* reverse so d_status is last */
285 { static int printcount
;
286 if(++printcount
<=4) {
287 for(i
=llw
; i
>=0; --i
) {
289 printf("dst[%d]=%16lx@%16lx bounce[%d]=%16lx\n",
290 i
, dst
[i
], &dst
[i
], i
, bounce
[i
]);
303 #define BEGIN(p) do { tulip_desc_t t; memcpy(&t,(p),sizeof(t))
304 #define END(p) a12r2pb(&t,(p),sizeof(t)); } while(0)
306 static void setstatus(tulip_desc_t
*t
, u_int32_t val
) {
307 a12r2pb(&val
, &t
->d_status
, sizeof(t
->d_status
));
311 #include <machine/rpb.h>
312 static u_int32_t
a12map(u_int32_t p
) {
313 if(cputype
==ST_AVALON_A12
)
314 p
= (p
& 0xfffffff) | 0x80000000;
321 tulip_timeout_callback(
324 tulip_softc_t
* const sc
= arg
;
325 tulip_spl_t s
= TULIP_RAISESPL();
327 sc
->tulip_flags
&= ~TULIP_TIMEOUTPENDING
;
328 sc
->tulip_probe_timeout
-= 1000 / TULIP_HZ
;
329 (sc
->tulip_boardsw
->bd_media_poll
)(sc
, TULIP_MEDIAPOLL_TIMER
);
335 tulip_softc_t
* const sc
)
337 if (sc
->tulip_flags
& TULIP_TIMEOUTPENDING
)
339 sc
->tulip_flags
|= TULIP_TIMEOUTPENDING
;
340 timeout(tulip_timeout_callback
, sc
, (hz
+ TULIP_HZ
/ 2) / TULIP_HZ
);
343 #if defined(TULIP_NEED_FASTTIMEOUT)
345 tulip_fasttimeout_callback(
348 tulip_softc_t
* const sc
= arg
;
349 tulip_spl_t s
= TULIP_RAISESPL();
351 sc
->tulip_flags
&= ~TULIP_FASTTIMEOUTPENDING
;
352 (sc
->tulip_boardsw
->bd_media_poll
)(sc
, TULIP_MEDIAPOLL_FASTTIMER
);
358 tulip_softc_t
* const sc
)
360 if (sc
->tulip_flags
& TULIP_FASTTIMEOUTPENDING
)
362 sc
->tulip_flags
|= TULIP_FASTTIMEOUTPENDING
;
363 timeout(tulip_fasttimeout_callback
, sc
, 1);
369 tulip_softc_t
* const sc
)
373 * Before we are sure this is the right media we need
374 * to send a small packet to make sure there's carrier.
375 * Strangely, BNC and AUI will 'see" receive data if
376 * either is connected so the transmit is the only way
377 * to verify the connectivity.
379 m
= m_gethdr(M_DONTWAIT
, MT_DATA
);
383 * Construct a LLC TEST message which will point to ourselves.
385 memcpy(mtod(m
, struct ether_header
*)->ether_dhost
, sc
->tulip_enaddr
, 6);
386 memcpy(mtod(m
, struct ether_header
*)->ether_shost
, sc
->tulip_enaddr
, 6);
387 mtod(m
, struct ether_header
*)->ether_type
= htons(3);
388 mtod(m
, unsigned char *)[14] = 0;
389 mtod(m
, unsigned char *)[15] = 0;
390 mtod(m
, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
391 m
->m_len
= m
->m_pkthdr
.len
= sizeof(struct ether_header
) + 3;
395 sc
->tulip_cmdmode
|= TULIP_CMD_TXRUN
;
396 sc
->tulip_flags
|= TULIP_TXPROBE_ACTIVE
;
397 TULIP_CSR_WRITE(sc
, csr_command
, sc
->tulip_cmdmode
);
398 IF_PREPEND(&sc
->tulip_if
.if_snd
, m
);
399 tulip_ifstart(&sc
->tulip_if
);
400 sc
->tulip_probe
.probe_txprobes
++;
405 #define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0)
407 #define TULIP_SIAGEN_WATCHDOG 0
412 tulip_softc_t
* const sc
,
415 const tulip_media_info_t
*mi
= sc
->tulip_mediums
[media
];
421 * If we are switching media, make sure we don't think there's
422 * any stale RX activity
424 sc
->tulip_flags
&= ~TULIP_RXACT
;
425 if (mi
->mi_type
== TULIP_MEDIAINFO_SIA
) {
426 TULIP_CSR_WRITE(sc
, csr_sia_connectivity
, TULIP_SIACONN_RESET
);
427 TULIP_CSR_WRITE(sc
, csr_sia_tx_rx
, mi
->mi_sia_tx_rx
);
428 if (sc
->tulip_features
& TULIP_HAVE_SIAGP
) {
429 TULIP_CSR_WRITE(sc
, csr_sia_general
, mi
->mi_sia_gp_control
|mi
->mi_sia_general
|TULIP_SIAGEN_WATCHDOG
);
430 TULIP_CSR_WRITE(sc
, csr_sia_general
, mi
->mi_sia_gp_data
|mi
->mi_sia_general
|TULIP_SIAGEN_WATCHDOG
);
432 TULIP_CSR_WRITE(sc
, csr_sia_general
, mi
->mi_sia_general
|TULIP_SIAGEN_WATCHDOG
);
434 TULIP_CSR_WRITE(sc
, csr_sia_connectivity
, mi
->mi_sia_connectivity
);
435 } else if (mi
->mi_type
== TULIP_MEDIAINFO_GPR
) {
436 #define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL)
438 * If the cmdmode bits don't match the currently operating mode,
439 * set the cmdmode appropriately and reset the chip.
441 if (((mi
->mi_cmdmode
^ TULIP_CSR_READ(sc
, csr_command
)) & TULIP_GPR_CMDBITS
) != 0) {
442 sc
->tulip_cmdmode
&= ~TULIP_GPR_CMDBITS
;
443 sc
->tulip_cmdmode
|= mi
->mi_cmdmode
;
446 TULIP_CSR_WRITE(sc
, csr_gp
, TULIP_GP_PINSET
|sc
->tulip_gpinit
);
448 TULIP_CSR_WRITE(sc
, csr_gp
, (u_int8_t
) mi
->mi_gpdata
);
449 } else if (mi
->mi_type
== TULIP_MEDIAINFO_SYM
) {
451 * If the cmdmode bits don't match the currently operating mode,
452 * set the cmdmode appropriately and reset the chip.
454 if (((mi
->mi_cmdmode
^ TULIP_CSR_READ(sc
, csr_command
)) & TULIP_GPR_CMDBITS
) != 0) {
455 sc
->tulip_cmdmode
&= ~TULIP_GPR_CMDBITS
;
456 sc
->tulip_cmdmode
|= mi
->mi_cmdmode
;
459 TULIP_CSR_WRITE(sc
, csr_sia_general
, mi
->mi_gpcontrol
);
460 TULIP_CSR_WRITE(sc
, csr_sia_general
, mi
->mi_gpdata
);
461 } else if (mi
->mi_type
== TULIP_MEDIAINFO_MII
462 && sc
->tulip_probe_state
!= TULIP_PROBE_INACTIVE
) {
464 if (sc
->tulip_features
& TULIP_HAVE_SIAGP
) {
466 dp
= &sc
->tulip_rombuf
[mi
->mi_reset_offset
];
467 for (idx
= 0; idx
< mi
->mi_reset_length
; idx
++, dp
+= 2) {
469 TULIP_CSR_WRITE(sc
, csr_sia_general
, (dp
[0] + 256 * dp
[1]) << 16);
471 sc
->tulip_phyaddr
= mi
->mi_phyaddr
;
472 dp
= &sc
->tulip_rombuf
[mi
->mi_gpr_offset
];
473 for (idx
= 0; idx
< mi
->mi_gpr_length
; idx
++, dp
+= 2) {
475 TULIP_CSR_WRITE(sc
, csr_sia_general
, (dp
[0] + 256 * dp
[1]) << 16);
478 for (idx
= 0; idx
< mi
->mi_reset_length
; idx
++) {
480 TULIP_CSR_WRITE(sc
, csr_gp
, sc
->tulip_rombuf
[mi
->mi_reset_offset
+ idx
]);
482 sc
->tulip_phyaddr
= mi
->mi_phyaddr
;
483 for (idx
= 0; idx
< mi
->mi_gpr_length
; idx
++) {
485 TULIP_CSR_WRITE(sc
, csr_gp
, sc
->tulip_rombuf
[mi
->mi_gpr_offset
+ idx
]);
488 if (sc
->tulip_flags
& TULIP_TRYNWAY
) {
489 tulip_mii_autonegotiate(sc
, sc
->tulip_phyaddr
);
490 } else if ((sc
->tulip_flags
& TULIP_DIDNWAY
) == 0) {
491 u_int32_t data
= tulip_mii_readreg(sc
, sc
->tulip_phyaddr
, PHYREG_CONTROL
);
492 data
&= ~(PHYCTL_SELECT_100MB
|PHYCTL_FULL_DUPLEX
|PHYCTL_AUTONEG_ENABLE
);
493 sc
->tulip_flags
&= ~TULIP_DIDNWAY
;
494 if (TULIP_IS_MEDIA_FD(media
))
495 data
|= PHYCTL_FULL_DUPLEX
;
496 if (TULIP_IS_MEDIA_100MB(media
))
497 data
|= PHYCTL_SELECT_100MB
;
498 tulip_mii_writereg(sc
, sc
->tulip_phyaddr
, PHYREG_CONTROL
, data
);
505 tulip_softc_t
* const sc
,
508 if ((sc
->tulip_flags
& TULIP_LINKUP
) == 0)
509 sc
->tulip_flags
|= TULIP_PRINTLINKUP
;
510 sc
->tulip_flags
|= TULIP_LINKUP
;
511 sc
->tulip_if
.if_flags
&= ~IFF_OACTIVE
;
512 #if 0 /* XXX how does with work with ifmedia? */
513 if ((sc
->tulip_flags
& TULIP_DIDNWAY
) == 0) {
514 if (sc
->tulip_if
.if_flags
& IFF_FULLDUPLEX
) {
515 if (TULIP_CAN_MEDIA_FD(media
)
516 && sc
->tulip_mediums
[TULIP_FD_MEDIA_OF(media
)] != NULL
)
517 media
= TULIP_FD_MEDIA_OF(media
);
519 if (TULIP_IS_MEDIA_FD(media
)
520 && sc
->tulip_mediums
[TULIP_HD_MEDIA_OF(media
)] != NULL
)
521 media
= TULIP_HD_MEDIA_OF(media
);
525 if (sc
->tulip_media
!= media
) {
527 sc
->tulip_dbg
.dbg_last_media
= sc
->tulip_media
;
529 sc
->tulip_media
= media
;
530 sc
->tulip_flags
|= TULIP_PRINTMEDIA
;
531 if (TULIP_IS_MEDIA_FD(sc
->tulip_media
)) {
532 sc
->tulip_cmdmode
|= TULIP_CMD_FULLDUPLEX
;
533 } else if (sc
->tulip_chipid
!= TULIP_21041
|| (sc
->tulip_flags
& TULIP_DIDNWAY
) == 0) {
534 sc
->tulip_cmdmode
&= ~TULIP_CMD_FULLDUPLEX
;
538 * We could set probe_timeout to 0 but setting to 3000 puts this
539 * in one central place and the only matters is tulip_link is
540 * followed by a tulip_timeout. Therefore setting it should not
541 * result in aberrant behavour.
543 sc
->tulip_probe_timeout
= 3000;
544 sc
->tulip_probe_state
= TULIP_PROBE_INACTIVE
;
545 sc
->tulip_flags
&= ~(TULIP_TXPROBE_ACTIVE
|TULIP_TRYNWAY
);
546 if (sc
->tulip_flags
& TULIP_INRESET
) {
547 tulip_media_set(sc
, sc
->tulip_media
);
556 tulip_softc_t
* const sc
)
558 if ((sc
->tulip_flags
& TULIP_LINKUP
) == 0)
560 if (sc
->tulip_flags
& TULIP_PRINTMEDIA
) {
561 printf(TULIP_PRINTF_FMT
": enabling %s port\n",
563 tulip_mediums
[sc
->tulip_media
]);
564 sc
->tulip_flags
&= ~(TULIP_PRINTMEDIA
|TULIP_PRINTLINKUP
);
565 } else if (sc
->tulip_flags
& TULIP_PRINTLINKUP
) {
566 printf(TULIP_PRINTF_FMT
": link up\n", TULIP_PRINTF_ARGS
);
567 sc
->tulip_flags
&= ~TULIP_PRINTLINKUP
;
571 #if defined(TULIP_DO_GPR_SENSE)
573 tulip_21140_gpr_media_sense(
574 tulip_softc_t
* const sc
)
576 tulip_media_t maybe_media
= TULIP_MEDIA_UNKNOWN
;
577 tulip_media_t last_media
= TULIP_MEDIA_UNKNOWN
;
581 * If one of the media blocks contained a default media flag,
584 for (media
= TULIP_MEDIA_UNKNOWN
; media
< TULIP_MEDIA_MAX
; media
++) {
585 const tulip_media_info_t
*mi
;
587 * Media is not supported (or is full-duplex).
589 if ((mi
= sc
->tulip_mediums
[media
]) == NULL
|| TULIP_IS_MEDIA_FD(media
))
591 if (mi
->mi_type
!= TULIP_MEDIAINFO_GPR
)
595 * Remember the media is this is the "default" media.
597 if (mi
->mi_default
&& maybe_media
== TULIP_MEDIA_UNKNOWN
)
601 * No activity mask? Can't see if it is active if there's no mask.
603 if (mi
->mi_actmask
== 0)
607 * Does the activity data match?
609 if ((TULIP_CSR_READ(sc
, csr_gp
) & mi
->mi_actmask
) != mi
->mi_actdata
)
612 #if defined(TULIP_DEBUG)
613 printf(TULIP_PRINTF_FMT
": gpr_media_sense: %s: 0x%02x & 0x%02x == 0x%02x\n",
614 TULIP_PRINTF_ARGS
, tulip_mediums
[media
],
615 TULIP_CSR_READ(sc
, csr_gp
) & 0xFF,
616 mi
->mi_actmask
, mi
->mi_actdata
);
619 * It does! If this is the first media we detected, then
620 * remember this media. If isn't the first, then there were
621 * multiple matches which we equate to no match (since we don't
622 * which to select (if any).
624 if (last_media
== TULIP_MEDIA_UNKNOWN
) {
626 } else if (last_media
!= media
) {
627 last_media
= TULIP_MEDIA_UNKNOWN
;
630 return (last_media
!= TULIP_MEDIA_UNKNOWN
) ? last_media
: maybe_media
;
632 #endif /* TULIP_DO_GPR_SENSE */
634 static tulip_link_status_t
635 tulip_media_link_monitor(
636 tulip_softc_t
* const sc
)
638 const tulip_media_info_t
* const mi
= sc
->tulip_mediums
[sc
->tulip_media
];
639 tulip_link_status_t linkup
= TULIP_LINK_DOWN
;
642 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
643 panic("tulip_media_link_monitor: %s: botch at line %d",
644 tulip_mediums
[sc
->tulip_media
],__LINE__
);
646 return TULIP_LINK_UNKNOWN
;
651 * Have we seen some packets? If so, the link must be good.
653 if ((sc
->tulip_flags
& (TULIP_RXACT
|TULIP_LINKUP
)) == (TULIP_RXACT
|TULIP_LINKUP
)) {
654 sc
->tulip_flags
&= ~TULIP_RXACT
;
655 sc
->tulip_probe_timeout
= 3000;
656 return TULIP_LINK_UP
;
659 sc
->tulip_flags
&= ~TULIP_RXACT
;
660 if (mi
->mi_type
== TULIP_MEDIAINFO_MII
) {
663 * Read the PHY status register.
665 status
= tulip_mii_readreg(sc
, sc
->tulip_phyaddr
, PHYREG_STATUS
);
666 if (status
& PHYSTS_AUTONEG_DONE
) {
668 * If the PHY has completed autonegotiation, see the if the
669 * remote systems abilities have changed. If so, upgrade or
670 * downgrade as appropriate.
672 u_int32_t abilities
= tulip_mii_readreg(sc
, sc
->tulip_phyaddr
, PHYREG_AUTONEG_ABILITIES
);
673 abilities
= (abilities
<< 6) & status
;
674 if (abilities
!= sc
->tulip_abilities
) {
675 #if defined(TULIP_DEBUG)
676 loudprintf(TULIP_PRINTF_FMT
"(phy%d): autonegotiation changed: 0x%04x -> 0x%04x\n",
677 TULIP_PRINTF_ARGS
, sc
->tulip_phyaddr
,
678 sc
->tulip_abilities
, abilities
);
680 if (tulip_mii_map_abilities(sc
, abilities
)) {
681 tulip_linkup(sc
, sc
->tulip_probe_media
);
682 return TULIP_LINK_UP
;
685 * if we had selected media because of autonegotiation,
686 * we need to probe for the new media.
688 sc
->tulip_probe_state
= TULIP_PROBE_INACTIVE
;
689 if (sc
->tulip_flags
& TULIP_DIDNWAY
)
690 return TULIP_LINK_DOWN
;
694 * The link is now up. If was down, say its back up.
696 if ((status
& (PHYSTS_LINK_UP
|PHYSTS_REMOTE_FAULT
)) == PHYSTS_LINK_UP
)
697 linkup
= TULIP_LINK_UP
;
698 } else if (mi
->mi_type
== TULIP_MEDIAINFO_GPR
) {
700 * No activity sensor? Assume all's well.
702 if (mi
->mi_actmask
== 0)
703 return TULIP_LINK_UNKNOWN
;
705 * Does the activity data match?
707 if ((TULIP_CSR_READ(sc
, csr_gp
) & mi
->mi_actmask
) == mi
->mi_actdata
)
708 linkup
= TULIP_LINK_UP
;
709 } else if (mi
->mi_type
== TULIP_MEDIAINFO_SIA
) {
711 * Assume non TP ok for now.
713 if (!TULIP_IS_MEDIA_TP(sc
->tulip_media
))
714 return TULIP_LINK_UNKNOWN
;
715 if ((TULIP_CSR_READ(sc
, csr_sia_status
) & TULIP_SIASTS_LINKFAIL
) == 0)
716 linkup
= TULIP_LINK_UP
;
717 } else if (mi
->mi_type
== TULIP_MEDIAINFO_SYM
) {
718 return TULIP_LINK_UNKNOWN
;
721 * We will wait for 3 seconds until the link goes into suspect mode.
723 if (sc
->tulip_flags
& TULIP_LINKUP
) {
724 if (linkup
== TULIP_LINK_UP
)
725 sc
->tulip_probe_timeout
= 3000;
726 if (sc
->tulip_probe_timeout
> 0)
727 return TULIP_LINK_UP
;
729 sc
->tulip_flags
&= ~TULIP_LINKUP
;
730 printf(TULIP_PRINTF_FMT
": link down: cable problem?\n", TULIP_PRINTF_ARGS
);
732 #if defined(TULIP_DEBUG)
733 sc
->tulip_dbg
.dbg_link_downed
++;
735 return TULIP_LINK_DOWN
;
740 tulip_softc_t
* const sc
,
741 tulip_mediapoll_event_t event
)
743 #if defined(TULIP_DEBUG)
744 sc
->tulip_dbg
.dbg_events
[event
]++;
746 if (sc
->tulip_probe_state
== TULIP_PROBE_INACTIVE
747 && event
== TULIP_MEDIAPOLL_TIMER
) {
748 switch (tulip_media_link_monitor(sc
)) {
749 case TULIP_LINK_DOWN
: {
751 * Link Monitor failed. Probe for new media.
753 event
= TULIP_MEDIAPOLL_LINKFAIL
;
756 case TULIP_LINK_UP
: {
763 case TULIP_LINK_UNKNOWN
: {
765 * We can't tell so don't bother.
772 if (event
== TULIP_MEDIAPOLL_LINKFAIL
) {
773 if (sc
->tulip_probe_state
== TULIP_PROBE_INACTIVE
) {
774 if (TULIP_DO_AUTOSENSE(sc
)) {
775 #if defined(TULIP_DEBUG)
776 sc
->tulip_dbg
.dbg_link_failures
++;
778 sc
->tulip_media
= TULIP_MEDIA_UNKNOWN
;
779 tulip_reset(sc
); /* restart probe */
783 #if defined(TULIP_DEBUG)
784 sc
->tulip_dbg
.dbg_link_pollintrs
++;
788 if (event
== TULIP_MEDIAPOLL_START
) {
789 sc
->tulip_if
.if_flags
|= IFF_OACTIVE
;
790 if (sc
->tulip_probe_state
!= TULIP_PROBE_INACTIVE
)
792 sc
->tulip_probe_mediamask
= 0;
793 sc
->tulip_probe_passes
= 0;
794 #if defined(TULIP_DEBUG)
795 sc
->tulip_dbg
.dbg_media_probes
++;
798 * If the SROM contained an explicit media to use, use it.
800 sc
->tulip_cmdmode
&= ~(TULIP_CMD_RXRUN
|TULIP_CMD_FULLDUPLEX
);
801 sc
->tulip_flags
|= TULIP_TRYNWAY
|TULIP_PROBE1STPASS
;
802 sc
->tulip_flags
&= ~(TULIP_DIDNWAY
|TULIP_PRINTMEDIA
|TULIP_PRINTLINKUP
);
804 * connidx is defaulted to a media_unknown type.
806 sc
->tulip_probe_media
= tulip_srom_conninfo
[sc
->tulip_connidx
].sc_media
;
807 if (sc
->tulip_probe_media
!= TULIP_MEDIA_UNKNOWN
) {
808 tulip_linkup(sc
, sc
->tulip_probe_media
);
813 if (sc
->tulip_features
& TULIP_HAVE_GPR
) {
814 sc
->tulip_probe_state
= TULIP_PROBE_GPRTEST
;
815 sc
->tulip_probe_timeout
= 2000;
817 sc
->tulip_probe_media
= TULIP_MEDIA_MAX
;
818 sc
->tulip_probe_timeout
= 0;
819 sc
->tulip_probe_state
= TULIP_PROBE_MEDIATEST
;
824 * Ignore txprobe failures or spurious callbacks.
826 if (event
== TULIP_MEDIAPOLL_TXPROBE_FAILED
827 && sc
->tulip_probe_state
!= TULIP_PROBE_MEDIATEST
) {
828 sc
->tulip_flags
&= ~TULIP_TXPROBE_ACTIVE
;
833 * If we really transmitted a packet, then that's the media we'll use.
835 if (event
== TULIP_MEDIAPOLL_TXPROBE_OK
|| event
== TULIP_MEDIAPOLL_LINKPASS
) {
836 if (event
== TULIP_MEDIAPOLL_LINKPASS
)
837 sc
->tulip_probe_media
= TULIP_MEDIA_10BASET
;
838 #if defined(TULIP_DEBUG)
840 sc
->tulip_dbg
.dbg_txprobes_ok
[sc
->tulip_probe_media
]++;
842 tulip_linkup(sc
, sc
->tulip_probe_media
);
847 if (sc
->tulip_probe_state
== TULIP_PROBE_GPRTEST
) {
848 #if defined(TULIP_DO_GPR_SENSE)
850 * Check for media via the general purpose register.
852 * Try to sense the media via the GPR. If the same value
853 * occurs 3 times in a row then just use that.
855 if (sc
->tulip_probe_timeout
> 0) {
856 tulip_media_t new_probe_media
= tulip_21140_gpr_media_sense(sc
);
857 #if defined(TULIP_DEBUG)
858 printf(TULIP_PRINTF_FMT
": media_poll: gpr sensing = %s\n",
859 TULIP_PRINTF_ARGS
, tulip_mediums
[new_probe_media
]);
861 if (new_probe_media
!= TULIP_MEDIA_UNKNOWN
) {
862 if (new_probe_media
== sc
->tulip_probe_media
) {
863 if (--sc
->tulip_probe_count
== 0)
864 tulip_linkup(sc
, sc
->tulip_probe_media
);
866 sc
->tulip_probe_count
= 10;
869 sc
->tulip_probe_media
= new_probe_media
;
873 #endif /* TULIP_DO_GPR_SENSE */
875 * Brute force. We cycle through each of the media types
876 * and try to transmit a packet.
878 sc
->tulip_probe_state
= TULIP_PROBE_MEDIATEST
;
879 sc
->tulip_probe_media
= TULIP_MEDIA_MAX
;
880 sc
->tulip_probe_timeout
= 0;
885 if (sc
->tulip_probe_state
!= TULIP_PROBE_MEDIATEST
886 && (sc
->tulip_features
& TULIP_HAVE_MII
)) {
887 tulip_media_t old_media
= sc
->tulip_probe_media
;
888 tulip_mii_autonegotiate(sc
, sc
->tulip_phyaddr
);
889 switch (sc
->tulip_probe_state
) {
890 case TULIP_PROBE_FAILED
:
891 case TULIP_PROBE_MEDIATEST
: {
893 * Try the next media.
895 sc
->tulip_probe_mediamask
|= sc
->tulip_mediums
[sc
->tulip_probe_media
]->mi_mediamask
;
896 sc
->tulip_probe_timeout
= 0;
898 if (sc
->tulip_probe_state
== TULIP_PROBE_FAILED
)
900 if (sc
->tulip_probe_media
!= tulip_mii_phy_readspecific(sc
))
902 sc
->tulip_probe_timeout
= TULIP_IS_MEDIA_TP(sc
->tulip_probe_media
) ? 2500 : 300;
906 case TULIP_PROBE_PHYAUTONEG
: {
909 case TULIP_PROBE_INACTIVE
: {
911 * Only probe if we autonegotiated a media that hasn't failed.
913 sc
->tulip_probe_timeout
= 0;
914 if (sc
->tulip_probe_mediamask
& TULIP_BIT(sc
->tulip_probe_media
)) {
915 sc
->tulip_probe_media
= old_media
;
918 tulip_linkup(sc
, sc
->tulip_probe_media
);
923 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
924 panic("tulip_media_poll: botch at line %d", __LINE__
);
931 if (event
== TULIP_MEDIAPOLL_TXPROBE_FAILED
) {
932 #if defined(TULIP_DEBUG)
933 sc
->tulip_dbg
.dbg_txprobes_failed
[sc
->tulip_probe_media
]++;
935 sc
->tulip_flags
&= ~TULIP_TXPROBE_ACTIVE
;
940 * switch to another media if we tried this one enough.
942 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc
->tulip_probe_timeout
<= 0) {
943 #if defined(TULIP_DEBUG)
944 if (sc
->tulip_probe_media
== TULIP_MEDIA_UNKNOWN
) {
945 printf(TULIP_PRINTF_FMT
": poll media unknown!\n",
947 sc
->tulip_probe_media
= TULIP_MEDIA_MAX
;
951 * Find the next media type to check for. Full Duplex
952 * types are not allowed.
955 sc
->tulip_probe_media
-= 1;
956 if (sc
->tulip_probe_media
== TULIP_MEDIA_UNKNOWN
) {
957 if (++sc
->tulip_probe_passes
== 3) {
958 printf(TULIP_PRINTF_FMT
": autosense failed: cable problem?\n",
960 if ((sc
->tulip_if
.if_flags
& IFF_UP
) == 0) {
961 sc
->tulip_if
.if_flags
&= ~IFF_RUNNING
;
962 sc
->tulip_probe_state
= TULIP_PROBE_INACTIVE
;
966 sc
->tulip_flags
^= TULIP_TRYNWAY
; /* XXX */
967 sc
->tulip_probe_mediamask
= 0;
968 sc
->tulip_probe_media
= TULIP_MEDIA_MAX
- 1;
970 } while (sc
->tulip_mediums
[sc
->tulip_probe_media
] == NULL
971 || (sc
->tulip_probe_mediamask
& TULIP_BIT(sc
->tulip_probe_media
))
972 || TULIP_IS_MEDIA_FD(sc
->tulip_probe_media
));
974 #if defined(TULIP_DEBUG)
975 printf(TULIP_PRINTF_FMT
": %s: probing %s\n", TULIP_PRINTF_ARGS
,
976 event
== TULIP_MEDIAPOLL_TXPROBE_FAILED
? "txprobe failed" : "timeout",
977 tulip_mediums
[sc
->tulip_probe_media
]);
979 sc
->tulip_probe_timeout
= TULIP_IS_MEDIA_TP(sc
->tulip_probe_media
) ? 2500 : 1000;
980 sc
->tulip_probe_state
= TULIP_PROBE_MEDIATEST
;
981 sc
->tulip_probe
.probe_txprobes
= 0;
983 tulip_media_set(sc
, sc
->tulip_probe_media
);
984 sc
->tulip_flags
&= ~TULIP_TXPROBE_ACTIVE
;
989 * If this is hanging off a phy, we know are doing NWAY and we have
990 * forced the phy to a specific speed. Wait for link up before
991 * before sending a packet.
993 switch (sc
->tulip_mediums
[sc
->tulip_probe_media
]->mi_type
) {
994 case TULIP_MEDIAINFO_MII
: {
995 if (sc
->tulip_probe_media
!= tulip_mii_phy_readspecific(sc
))
999 case TULIP_MEDIAINFO_SIA
: {
1000 if (TULIP_IS_MEDIA_TP(sc
->tulip_probe_media
)) {
1001 if (TULIP_CSR_READ(sc
, csr_sia_status
) & TULIP_SIASTS_LINKFAIL
)
1003 tulip_linkup(sc
, sc
->tulip_probe_media
);
1005 if (sc
->tulip_features
& TULIP_HAVE_MII
)
1012 case TULIP_MEDIAINFO_RESET
:
1013 case TULIP_MEDIAINFO_SYM
:
1014 case TULIP_MEDIAINFO_GPR
: {
1019 * Try to send a packet.
1026 tulip_softc_t
* const sc
)
1028 if (sc
->tulip_features
& TULIP_HAVE_GPR
) {
1029 TULIP_CSR_WRITE(sc
, csr_gp
, TULIP_GP_PINSET
|sc
->tulip_gpinit
);
1031 TULIP_CSR_WRITE(sc
, csr_gp
, sc
->tulip_gpdata
);
1034 * If this board has no media, just return
1036 if (IFM_SUBTYPE(sc
->tulip_ifmedia
.ifm_media
) == IFM_NONE
)
1038 if (sc
->tulip_media
== TULIP_MEDIA_UNKNOWN
) {
1039 TULIP_CSR_WRITE(sc
, csr_intr
, sc
->tulip_intrmask
);
1040 (*sc
->tulip_boardsw
->bd_media_poll
)(sc
, TULIP_MEDIAPOLL_START
);
1042 tulip_media_set(sc
, sc
->tulip_media
);
1047 tulip_21040_mediainfo_init(
1048 tulip_softc_t
* const sc
,
1049 tulip_media_t media
)
1051 sc
->tulip_cmdmode
|= TULIP_CMD_CAPTREFFCT
|TULIP_CMD_THRSHLD160
1052 |TULIP_CMD_BACKOFFCTR
;
1053 sc
->tulip_if
.if_baudrate
= 10000000;
1055 if (media
== TULIP_MEDIA_10BASET
|| media
== TULIP_MEDIA_UNKNOWN
) {
1056 TULIP_MEDIAINFO_SIA_INIT(sc
, &sc
->tulip_mediainfo
[0], 21040, 10BASET
);
1057 TULIP_MEDIAINFO_SIA_INIT(sc
, &sc
->tulip_mediainfo
[1], 21040, 10BASET_FD
);
1060 if (media
== TULIP_MEDIA_AUIBNC
|| media
== TULIP_MEDIA_UNKNOWN
) {
1061 TULIP_MEDIAINFO_SIA_INIT(sc
, &sc
->tulip_mediainfo
[2], 21040, AUIBNC
);
1064 if (media
== TULIP_MEDIA_UNKNOWN
) {
1065 TULIP_MEDIAINFO_SIA_INIT(sc
, &sc
->tulip_mediainfo
[3], 21040, EXTSIA
);
1070 tulip_21040_media_probe(
1071 tulip_softc_t
* const sc
)
1073 tulip_21040_mediainfo_init(sc
, TULIP_MEDIA_UNKNOWN
);
1078 tulip_21040_10baset_only_media_probe(
1079 tulip_softc_t
* const sc
)
1081 tulip_21040_mediainfo_init(sc
, TULIP_MEDIA_10BASET
);
1082 tulip_media_set(sc
, TULIP_MEDIA_10BASET
);
1083 sc
->tulip_media
= TULIP_MEDIA_10BASET
;
1087 tulip_21040_10baset_only_media_select(
1088 tulip_softc_t
* const sc
)
1090 sc
->tulip_flags
|= TULIP_LINKUP
;
1091 if (sc
->tulip_media
== TULIP_MEDIA_10BASET_FD
) {
1092 sc
->tulip_cmdmode
|= TULIP_CMD_FULLDUPLEX
;
1093 sc
->tulip_flags
&= ~TULIP_SQETEST
;
1095 sc
->tulip_cmdmode
&= ~TULIP_CMD_FULLDUPLEX
;
1096 sc
->tulip_flags
|= TULIP_SQETEST
;
1098 tulip_media_set(sc
, sc
->tulip_media
);
1102 tulip_21040_auibnc_only_media_probe(
1103 tulip_softc_t
* const sc
)
1105 tulip_21040_mediainfo_init(sc
, TULIP_MEDIA_AUIBNC
);
1106 sc
->tulip_flags
|= TULIP_SQETEST
|TULIP_LINKUP
;
1107 tulip_media_set(sc
, TULIP_MEDIA_AUIBNC
);
1108 sc
->tulip_media
= TULIP_MEDIA_AUIBNC
;
1112 tulip_21040_auibnc_only_media_select(
1113 tulip_softc_t
* const sc
)
1115 tulip_media_set(sc
, TULIP_MEDIA_AUIBNC
);
1116 sc
->tulip_cmdmode
&= ~TULIP_CMD_FULLDUPLEX
;
1119 static const tulip_boardsw_t tulip_21040_boardsw
= {
1120 TULIP_21040_GENERIC
,
1121 tulip_21040_media_probe
,
1126 static const tulip_boardsw_t tulip_21040_10baset_only_boardsw
= {
1127 TULIP_21040_GENERIC
,
1128 tulip_21040_10baset_only_media_probe
,
1129 tulip_21040_10baset_only_media_select
,
1133 static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw
= {
1134 TULIP_21040_GENERIC
,
1135 tulip_21040_auibnc_only_media_probe
,
1136 tulip_21040_auibnc_only_media_select
,
1141 tulip_21041_mediainfo_init(
1142 tulip_softc_t
* const sc
)
1144 tulip_media_info_t
* const mi
= sc
->tulip_mediainfo
;
1147 if (sc
->tulip_revinfo
>= 0x20) {
1148 TULIP_MEDIAINFO_SIA_INIT(sc
, &mi
[0], 21041P2
, 10BASET
);
1149 TULIP_MEDIAINFO_SIA_INIT(sc
, &mi
[1], 21041P2
, 10BASET_FD
);
1150 TULIP_MEDIAINFO_SIA_INIT(sc
, &mi
[0], 21041P2
, AUI
);
1151 TULIP_MEDIAINFO_SIA_INIT(sc
, &mi
[1], 21041P2
, BNC
);
1155 TULIP_MEDIAINFO_SIA_INIT(sc
, &mi
[0], 21041, 10BASET
);
1156 TULIP_MEDIAINFO_SIA_INIT(sc
, &mi
[1], 21041, 10BASET_FD
);
1157 TULIP_MEDIAINFO_SIA_INIT(sc
, &mi
[2], 21041, AUI
);
1158 TULIP_MEDIAINFO_SIA_INIT(sc
, &mi
[3], 21041, BNC
);
1162 tulip_21041_media_probe(
1163 tulip_softc_t
* const sc
)
1165 sc
->tulip_if
.if_baudrate
= 10000000;
1166 sc
->tulip_cmdmode
|= TULIP_CMD_CAPTREFFCT
|TULIP_CMD_ENHCAPTEFFCT
1167 |TULIP_CMD_THRSHLD160
|TULIP_CMD_BACKOFFCTR
;
1168 sc
->tulip_intrmask
|= TULIP_STS_LINKPASS
;
1169 tulip_21041_mediainfo_init(sc
);
1173 tulip_21041_media_poll(
1174 tulip_softc_t
* const sc
,
1175 const tulip_mediapoll_event_t event
)
1177 u_int32_t sia_status
;
1179 #if defined(TULIP_DEBUG)
1180 sc
->tulip_dbg
.dbg_events
[event
]++;
1183 if (event
== TULIP_MEDIAPOLL_LINKFAIL
) {
1184 if (sc
->tulip_probe_state
!= TULIP_PROBE_INACTIVE
1185 || !TULIP_DO_AUTOSENSE(sc
))
1187 sc
->tulip_media
= TULIP_MEDIA_UNKNOWN
;
1188 tulip_reset(sc
); /* start probe */
1193 * If we've been been asked to start a poll or link change interrupt
1194 * restart the probe (and reset the tulip to a known state).
1196 if (event
== TULIP_MEDIAPOLL_START
) {
1197 sc
->tulip_if
.if_flags
|= IFF_OACTIVE
;
1198 sc
->tulip_cmdmode
&= ~(TULIP_CMD_FULLDUPLEX
|TULIP_CMD_RXRUN
);
1200 if (sc
->tulip_revinfo
>= 0x20) {
1201 sc
->tulip_cmdmode
|= TULIP_CMD_FULLDUPLEX
;
1202 sc
->tulip_flags
|= TULIP_DIDNWAY
;
1205 TULIP_CSR_WRITE(sc
, csr_command
, sc
->tulip_cmdmode
);
1206 sc
->tulip_probe_state
= TULIP_PROBE_MEDIATEST
;
1207 sc
->tulip_probe_media
= TULIP_MEDIA_10BASET
;
1208 sc
->tulip_probe_timeout
= TULIP_21041_PROBE_10BASET_TIMEOUT
;
1209 tulip_media_set(sc
, TULIP_MEDIA_10BASET
);
1214 if (sc
->tulip_probe_state
== TULIP_PROBE_INACTIVE
)
1217 if (event
== TULIP_MEDIAPOLL_TXPROBE_OK
) {
1218 #if defined(TULIP_DEBUG)
1219 sc
->tulip_dbg
.dbg_txprobes_ok
[sc
->tulip_probe_media
]++;
1221 tulip_linkup(sc
, sc
->tulip_probe_media
);
1225 sia_status
= TULIP_CSR_READ(sc
, csr_sia_status
);
1226 TULIP_CSR_WRITE(sc
, csr_sia_status
, sia_status
);
1227 if ((sia_status
& TULIP_SIASTS_LINKFAIL
) == 0) {
1228 if (sc
->tulip_revinfo
>= 0x20) {
1229 if (sia_status
& (PHYSTS_10BASET_FD
<< (16 - 6)))
1230 sc
->tulip_probe_media
= TULIP_MEDIA_10BASET_FD
;
1233 * If the link has passed LinkPass, 10baseT is the
1234 * proper media to use.
1236 tulip_linkup(sc
, sc
->tulip_probe_media
);
1241 * wait for up to 2.4 seconds for the link to reach pass state.
1242 * Only then start scanning the other media for activity.
1243 * choose media with receive activity over those without.
1245 if (sc
->tulip_probe_media
== TULIP_MEDIA_10BASET
) {
1246 if (event
!= TULIP_MEDIAPOLL_TIMER
)
1248 if (sc
->tulip_probe_timeout
> 0
1249 && (sia_status
& TULIP_SIASTS_OTHERRXACTIVITY
) == 0) {
1253 sc
->tulip_probe_timeout
= TULIP_21041_PROBE_AUIBNC_TIMEOUT
;
1254 sc
->tulip_flags
|= TULIP_WANTRXACT
;
1255 if (sia_status
& TULIP_SIASTS_OTHERRXACTIVITY
) {
1256 sc
->tulip_probe_media
= TULIP_MEDIA_BNC
;
1258 sc
->tulip_probe_media
= TULIP_MEDIA_AUI
;
1260 tulip_media_set(sc
, sc
->tulip_probe_media
);
1266 * If we failed, clear the txprobe active flag.
1268 if (event
== TULIP_MEDIAPOLL_TXPROBE_FAILED
)
1269 sc
->tulip_flags
&= ~TULIP_TXPROBE_ACTIVE
;
1272 if (event
== TULIP_MEDIAPOLL_TIMER
) {
1274 * If we've received something, then that's our link!
1276 if (sc
->tulip_flags
& TULIP_RXACT
) {
1277 tulip_linkup(sc
, sc
->tulip_probe_media
);
1281 * if no txprobe active
1283 if ((sc
->tulip_flags
& TULIP_TXPROBE_ACTIVE
) == 0
1284 && ((sc
->tulip_flags
& TULIP_WANTRXACT
) == 0
1285 || (sia_status
& TULIP_SIASTS_RXACTIVITY
))) {
1286 sc
->tulip_probe_timeout
= TULIP_21041_PROBE_AUIBNC_TIMEOUT
;
1292 * Take 2 passes through before deciding to not
1293 * wait for receive activity. Then take another
1294 * two passes before spitting out a warning.
1296 if (sc
->tulip_probe_timeout
<= 0) {
1297 if (sc
->tulip_flags
& TULIP_WANTRXACT
) {
1298 sc
->tulip_flags
&= ~TULIP_WANTRXACT
;
1299 sc
->tulip_probe_timeout
= TULIP_21041_PROBE_AUIBNC_TIMEOUT
;
1301 printf(TULIP_PRINTF_FMT
": autosense failed: cable problem?\n",
1303 if ((sc
->tulip_if
.if_flags
& IFF_UP
) == 0) {
1304 sc
->tulip_if
.if_flags
&= ~IFF_RUNNING
;
1305 sc
->tulip_probe_state
= TULIP_PROBE_INACTIVE
;
1313 * Since this media failed to probe, try the other one.
1315 sc
->tulip_probe_timeout
= TULIP_21041_PROBE_AUIBNC_TIMEOUT
;
1316 if (sc
->tulip_probe_media
== TULIP_MEDIA_AUI
) {
1317 sc
->tulip_probe_media
= TULIP_MEDIA_BNC
;
1319 sc
->tulip_probe_media
= TULIP_MEDIA_AUI
;
1321 tulip_media_set(sc
, sc
->tulip_probe_media
);
1322 sc
->tulip_flags
&= ~TULIP_TXPROBE_ACTIVE
;
1326 static const tulip_boardsw_t tulip_21041_boardsw
= {
1327 TULIP_21041_GENERIC
,
1328 tulip_21041_media_probe
,
1330 tulip_21041_media_poll
1333 static const tulip_phy_attr_t tulip_mii_phy_attrlist
[] = {
1334 { 0x20005c00, 0, /* 08-00-17 */
1336 { 0x19, 0x0040, 0x0040 }, /* 10TX */
1337 { 0x19, 0x0040, 0x0000 }, /* 100TX */
1339 #if defined(TULIP_DEBUG)
1343 { 0x0281F400, 0, /* 00-A0-7D */
1345 { 0x12, 0x0010, 0x0000 }, /* 10T */
1347 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1348 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1350 #if defined(TULIP_DEBUG)
1355 { 0x0015F420, 0, /* 00-A0-7D */
1357 { 0x12, 0x0010, 0x0000 }, /* 10T */
1359 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1360 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1362 #if defined(TULIP_DEBUG)
1367 { 0x0281F400, 0, /* 00-A0-BE */
1369 { 0x11, 0x8000, 0x0000 }, /* 10T */
1370 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1372 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1374 #if defined(TULIP_DEBUG)
1381 static tulip_media_t
1382 tulip_mii_phy_readspecific(
1383 tulip_softc_t
* const sc
)
1385 const tulip_phy_attr_t
*attr
;
1389 static const tulip_media_t table
[] = {
1390 TULIP_MEDIA_UNKNOWN
,
1391 TULIP_MEDIA_10BASET
,
1392 TULIP_MEDIA_100BASETX
,
1393 TULIP_MEDIA_100BASET4
,
1394 TULIP_MEDIA_UNKNOWN
,
1395 TULIP_MEDIA_10BASET_FD
,
1396 TULIP_MEDIA_100BASETX_FD
,
1401 * Don't read phy specific registers if link is not up.
1403 data
= tulip_mii_readreg(sc
, sc
->tulip_phyaddr
, PHYREG_STATUS
);
1404 if ((data
& (PHYSTS_LINK_UP
|PHYSTS_EXTENDED_REGS
)) != (PHYSTS_LINK_UP
|PHYSTS_EXTENDED_REGS
))
1405 return TULIP_MEDIA_UNKNOWN
;
1407 id
= (tulip_mii_readreg(sc
, sc
->tulip_phyaddr
, PHYREG_IDLOW
) << 16) |
1408 tulip_mii_readreg(sc
, sc
->tulip_phyaddr
, PHYREG_IDHIGH
);
1409 for (attr
= tulip_mii_phy_attrlist
;; attr
++) {
1410 if (attr
->attr_id
== 0)
1411 return TULIP_MEDIA_UNKNOWN
;
1412 if ((id
& ~0x0F) == attr
->attr_id
)
1416 if (attr
->attr_modes
[PHY_MODE_100TX
].pm_regno
) {
1417 const tulip_phy_modedata_t
* const pm
= &attr
->attr_modes
[PHY_MODE_100TX
];
1418 data
= tulip_mii_readreg(sc
, sc
->tulip_phyaddr
, pm
->pm_regno
);
1419 if ((data
& pm
->pm_mask
) == pm
->pm_value
)
1422 if (idx
== 0 && attr
->attr_modes
[PHY_MODE_100T4
].pm_regno
) {
1423 const tulip_phy_modedata_t
* const pm
= &attr
->attr_modes
[PHY_MODE_100T4
];
1424 data
= tulip_mii_readreg(sc
, sc
->tulip_phyaddr
, pm
->pm_regno
);
1425 if ((data
& pm
->pm_mask
) == pm
->pm_value
)
1428 if (idx
== 0 && attr
->attr_modes
[PHY_MODE_10T
].pm_regno
) {
1429 const tulip_phy_modedata_t
* const pm
= &attr
->attr_modes
[PHY_MODE_10T
];
1430 data
= tulip_mii_readreg(sc
, sc
->tulip_phyaddr
, pm
->pm_regno
);
1431 if ((data
& pm
->pm_mask
) == pm
->pm_value
)
1434 if (idx
!= 0 && attr
->attr_modes
[PHY_MODE_FULLDUPLEX
].pm_regno
) {
1435 const tulip_phy_modedata_t
* const pm
= &attr
->attr_modes
[PHY_MODE_FULLDUPLEX
];
1436 data
= tulip_mii_readreg(sc
, sc
->tulip_phyaddr
, pm
->pm_regno
);
1437 idx
+= ((data
& pm
->pm_mask
) == pm
->pm_value
? 4 : 0);
1443 tulip_mii_get_phyaddr(
1444 tulip_softc_t
* const sc
,
1449 for (phyaddr
= 1; phyaddr
< 32; phyaddr
++) {
1450 unsigned status
= tulip_mii_readreg(sc
, phyaddr
, PHYREG_STATUS
);
1451 if (status
== 0 || status
== 0xFFFF || status
< PHYSTS_10BASET
)
1458 unsigned status
= tulip_mii_readreg(sc
, 0, PHYREG_STATUS
);
1459 if (status
== 0 || status
== 0xFFFF || status
< PHYSTS_10BASET
)
1460 return TULIP_MII_NOPHY
;
1463 return TULIP_MII_NOPHY
;
1467 tulip_mii_map_abilities(
1468 tulip_softc_t
* const sc
,
1471 sc
->tulip_abilities
= abilities
;
1472 if (abilities
& PHYSTS_100BASETX_FD
) {
1473 sc
->tulip_probe_media
= TULIP_MEDIA_100BASETX_FD
;
1474 } else if (abilities
& PHYSTS_100BASET4
) {
1475 sc
->tulip_probe_media
= TULIP_MEDIA_100BASET4
;
1476 } else if (abilities
& PHYSTS_100BASETX
) {
1477 sc
->tulip_probe_media
= TULIP_MEDIA_100BASETX
;
1478 } else if (abilities
& PHYSTS_10BASET_FD
) {
1479 sc
->tulip_probe_media
= TULIP_MEDIA_10BASET_FD
;
1480 } else if (abilities
& PHYSTS_10BASET
) {
1481 sc
->tulip_probe_media
= TULIP_MEDIA_10BASET
;
1483 sc
->tulip_probe_state
= TULIP_PROBE_MEDIATEST
;
1486 sc
->tulip_probe_state
= TULIP_PROBE_INACTIVE
;
1491 tulip_mii_autonegotiate(
1492 tulip_softc_t
* const sc
,
1493 const unsigned phyaddr
)
1495 switch (sc
->tulip_probe_state
) {
1496 case TULIP_PROBE_MEDIATEST
:
1497 case TULIP_PROBE_INACTIVE
: {
1498 sc
->tulip_flags
|= TULIP_DIDNWAY
;
1499 tulip_mii_writereg(sc
, phyaddr
, PHYREG_CONTROL
, PHYCTL_RESET
);
1500 sc
->tulip_probe_timeout
= 3000;
1501 sc
->tulip_intrmask
|= TULIP_STS_ABNRMLINTR
|TULIP_STS_NORMALINTR
;
1502 sc
->tulip_probe_state
= TULIP_PROBE_PHYRESET
;
1505 case TULIP_PROBE_PHYRESET
: {
1507 u_int32_t data
= tulip_mii_readreg(sc
, phyaddr
, PHYREG_CONTROL
);
1508 if (data
& PHYCTL_RESET
) {
1509 if (sc
->tulip_probe_timeout
> 0) {
1513 printf(TULIP_PRINTF_FMT
"(phy%d): error: reset of PHY never completed!\n",
1514 TULIP_PRINTF_ARGS
, phyaddr
);
1515 sc
->tulip_flags
&= ~TULIP_TXPROBE_ACTIVE
;
1516 sc
->tulip_probe_state
= TULIP_PROBE_FAILED
;
1517 sc
->tulip_if
.if_flags
&= ~(IFF_UP
|IFF_RUNNING
);
1520 status
= tulip_mii_readreg(sc
, phyaddr
, PHYREG_STATUS
);
1521 if ((status
& PHYSTS_CAN_AUTONEG
) == 0) {
1522 #if defined(TULIP_DEBUG)
1523 loudprintf(TULIP_PRINTF_FMT
"(phy%d): autonegotiation disabled\n",
1524 TULIP_PRINTF_ARGS
, phyaddr
);
1526 sc
->tulip_flags
&= ~TULIP_DIDNWAY
;
1527 sc
->tulip_probe_state
= TULIP_PROBE_MEDIATEST
;
1530 if (tulip_mii_readreg(sc
, phyaddr
, PHYREG_AUTONEG_ADVERTISEMENT
) != ((status
>> 6) | 0x01))
1531 tulip_mii_writereg(sc
, phyaddr
, PHYREG_AUTONEG_ADVERTISEMENT
, (status
>> 6) | 0x01);
1532 tulip_mii_writereg(sc
, phyaddr
, PHYREG_CONTROL
, data
|PHYCTL_AUTONEG_RESTART
|PHYCTL_AUTONEG_ENABLE
);
1533 data
= tulip_mii_readreg(sc
, phyaddr
, PHYREG_CONTROL
);
1534 #if defined(TULIP_DEBUG)
1535 if ((data
& PHYCTL_AUTONEG_ENABLE
) == 0)
1536 loudprintf(TULIP_PRINTF_FMT
"(phy%d): oops: enable autonegotiation failed: 0x%04x\n",
1537 TULIP_PRINTF_ARGS
, phyaddr
, data
);
1539 loudprintf(TULIP_PRINTF_FMT
"(phy%d): autonegotiation restarted: 0x%04x\n",
1540 TULIP_PRINTF_ARGS
, phyaddr
, data
);
1541 sc
->tulip_dbg
.dbg_nway_starts
++;
1543 sc
->tulip_probe_state
= TULIP_PROBE_PHYAUTONEG
;
1544 sc
->tulip_probe_timeout
= 3000;
1547 case TULIP_PROBE_PHYAUTONEG
: {
1548 u_int32_t status
= tulip_mii_readreg(sc
, phyaddr
, PHYREG_STATUS
);
1550 if ((status
& PHYSTS_AUTONEG_DONE
) == 0) {
1551 if (sc
->tulip_probe_timeout
> 0) {
1555 #if defined(TULIP_DEBUG)
1556 loudprintf(TULIP_PRINTF_FMT
"(phy%d): autonegotiation timeout: sts=0x%04x, ctl=0x%04x\n",
1557 TULIP_PRINTF_ARGS
, phyaddr
, status
,
1558 tulip_mii_readreg(sc
, phyaddr
, PHYREG_CONTROL
));
1560 sc
->tulip_flags
&= ~TULIP_DIDNWAY
;
1561 sc
->tulip_probe_state
= TULIP_PROBE_MEDIATEST
;
1564 data
= tulip_mii_readreg(sc
, phyaddr
, PHYREG_AUTONEG_ABILITIES
);
1565 #if defined(TULIP_DEBUG)
1566 loudprintf(TULIP_PRINTF_FMT
"(phy%d): autonegotiation complete: 0x%04x\n",
1567 TULIP_PRINTF_ARGS
, phyaddr
, data
);
1569 data
= (data
<< 6) & status
;
1570 if (!tulip_mii_map_abilities(sc
, data
))
1571 sc
->tulip_flags
&= ~TULIP_DIDNWAY
;
1575 #if defined(DIAGNOSTIC)
1576 panic("tulip_media_poll: botch at line %d", __LINE__
);
1581 #if defined(TULIP_DEBUG)
1582 loudprintf(TULIP_PRINTF_FMT
"(phy%d): autonegotiation failure: state = %d\n",
1583 TULIP_PRINTF_ARGS
, phyaddr
, sc
->tulip_probe_state
);
1584 sc
->tulip_dbg
.dbg_nway_failures
++;
1589 tulip_2114x_media_preset(
1590 tulip_softc_t
* const sc
)
1592 const tulip_media_info_t
*mi
= NULL
;
1593 tulip_media_t media
= sc
->tulip_media
;
1595 if (sc
->tulip_probe_state
== TULIP_PROBE_INACTIVE
)
1596 media
= sc
->tulip_media
;
1598 media
= sc
->tulip_probe_media
;
1600 sc
->tulip_cmdmode
&= ~TULIP_CMD_PORTSELECT
;
1601 sc
->tulip_flags
&= ~TULIP_SQETEST
;
1602 /* here is the srom media problem */
1603 if (media
!= TULIP_MEDIA_UNKNOWN
) {
1604 #if 1 || defined(TULIP_DEBUG)
1605 if (media
< TULIP_MEDIA_MAX
&& sc
->tulip_mediums
[media
] != NULL
) {
1607 mi
= sc
->tulip_mediums
[media
];
1608 if (mi
->mi_type
== TULIP_MEDIAINFO_MII
) {
1609 sc
->tulip_cmdmode
|= TULIP_CMD_PORTSELECT
;
1610 } else if (mi
->mi_type
== TULIP_MEDIAINFO_GPR
1611 || mi
->mi_type
== TULIP_MEDIAINFO_SYM
) {
1612 sc
->tulip_cmdmode
&= ~TULIP_GPR_CMDBITS
;
1613 sc
->tulip_cmdmode
|= mi
->mi_cmdmode
;
1614 } else if (mi
->mi_type
== TULIP_MEDIAINFO_SIA
) {
1615 TULIP_CSR_WRITE(sc
, csr_sia_connectivity
, TULIP_SIACONN_RESET
);
1617 #if 1 || defined(TULIP_DEBUG)
1619 printf(TULIP_PRINTF_FMT
": preset: bad media %d!\n",
1620 TULIP_PRINTF_ARGS
, media
);
1625 case TULIP_MEDIA_BNC
:
1626 case TULIP_MEDIA_AUI
:
1627 case TULIP_MEDIA_10BASET
: {
1628 sc
->tulip_cmdmode
&= ~TULIP_CMD_FULLDUPLEX
;
1629 sc
->tulip_cmdmode
|= TULIP_CMD_TXTHRSHLDCTL
;
1630 sc
->tulip_if
.if_baudrate
= 10000000;
1631 sc
->tulip_flags
|= TULIP_SQETEST
;
1634 case TULIP_MEDIA_10BASET_FD
: {
1635 sc
->tulip_cmdmode
|= TULIP_CMD_FULLDUPLEX
|TULIP_CMD_TXTHRSHLDCTL
;
1636 sc
->tulip_if
.if_baudrate
= 10000000;
1639 case TULIP_MEDIA_100BASEFX
:
1640 case TULIP_MEDIA_100BASET4
:
1641 case TULIP_MEDIA_100BASETX
: {
1642 sc
->tulip_cmdmode
&= ~(TULIP_CMD_FULLDUPLEX
|TULIP_CMD_TXTHRSHLDCTL
);
1643 sc
->tulip_cmdmode
|= TULIP_CMD_PORTSELECT
;
1644 sc
->tulip_if
.if_baudrate
= 100000000;
1647 case TULIP_MEDIA_100BASEFX_FD
:
1648 case TULIP_MEDIA_100BASETX_FD
: {
1649 sc
->tulip_cmdmode
|= TULIP_CMD_FULLDUPLEX
|TULIP_CMD_PORTSELECT
;
1650 sc
->tulip_cmdmode
&= ~TULIP_CMD_TXTHRSHLDCTL
;
1651 sc
->tulip_if
.if_baudrate
= 100000000;
1658 TULIP_CSR_WRITE(sc
, csr_command
, sc
->tulip_cmdmode
);
1662 ********************************************************************
1663 * Start of 21140/21140A support which does not use the MII interface
1667 tulip_null_media_poll(
1668 tulip_softc_t
* const sc
,
1669 tulip_mediapoll_event_t event
)
1671 #if defined(TULIP_DEBUG)
1672 sc
->tulip_dbg
.dbg_events
[event
]++;
1674 #if defined(DIAGNOSTIC)
1675 printf(TULIP_PRINTF_FMT
": botch(media_poll) at line %d\n",
1676 TULIP_PRINTF_ARGS
, __LINE__
);
1681 tulip_21140_mediainit(
1682 tulip_softc_t
* const sc
,
1683 tulip_media_info_t
* const mip
,
1684 tulip_media_t
const media
,
1688 sc
->tulip_mediums
[media
] = mip
;
1689 mip
->mi_type
= TULIP_MEDIAINFO_GPR
;
1690 mip
->mi_cmdmode
= cmdmode
;
1691 mip
->mi_gpdata
= gpdata
;
1695 tulip_21140_evalboard_media_probe(
1696 tulip_softc_t
* const sc
)
1698 tulip_media_info_t
*mip
= sc
->tulip_mediainfo
;
1700 sc
->tulip_gpinit
= TULIP_GP_EB_PINS
;
1701 sc
->tulip_gpdata
= TULIP_GP_EB_INIT
;
1702 TULIP_CSR_WRITE(sc
, csr_gp
, TULIP_GP_EB_PINS
);
1703 TULIP_CSR_WRITE(sc
, csr_gp
, TULIP_GP_EB_INIT
);
1704 TULIP_CSR_WRITE(sc
, csr_command
,
1705 TULIP_CSR_READ(sc
, csr_command
) | TULIP_CMD_PORTSELECT
|
1706 TULIP_CMD_PCSFUNCTION
| TULIP_CMD_SCRAMBLER
| TULIP_CMD_MUSTBEONE
);
1707 TULIP_CSR_WRITE(sc
, csr_command
,
1708 TULIP_CSR_READ(sc
, csr_command
) & ~TULIP_CMD_TXTHRSHLDCTL
);
1710 if ((TULIP_CSR_READ(sc
, csr_gp
) & TULIP_GP_EB_OK100
) != 0) {
1711 sc
->tulip_media
= TULIP_MEDIA_10BASET
;
1713 sc
->tulip_media
= TULIP_MEDIA_100BASETX
;
1715 tulip_21140_mediainit(sc
, mip
++, TULIP_MEDIA_10BASET
,
1717 TULIP_CMD_TXTHRSHLDCTL
);
1718 tulip_21140_mediainit(sc
, mip
++, TULIP_MEDIA_10BASET_FD
,
1720 TULIP_CMD_TXTHRSHLDCTL
|TULIP_CMD_FULLDUPLEX
);
1721 tulip_21140_mediainit(sc
, mip
++, TULIP_MEDIA_100BASETX
,
1723 TULIP_CMD_PORTSELECT
|TULIP_CMD_PCSFUNCTION
1724 |TULIP_CMD_SCRAMBLER
);
1725 tulip_21140_mediainit(sc
, mip
++, TULIP_MEDIA_100BASETX_FD
,
1727 TULIP_CMD_PORTSELECT
|TULIP_CMD_PCSFUNCTION
1728 |TULIP_CMD_SCRAMBLER
|TULIP_CMD_FULLDUPLEX
);
1731 static const tulip_boardsw_t tulip_21140_eb_boardsw
= {
1733 tulip_21140_evalboard_media_probe
,
1735 tulip_null_media_poll
,
1736 tulip_2114x_media_preset
,
1740 tulip_21140_smc9332_media_probe(
1741 tulip_softc_t
* const sc
)
1743 tulip_media_info_t
*mip
= sc
->tulip_mediainfo
;
1746 TULIP_CSR_WRITE(sc
, csr_command
, TULIP_CMD_PORTSELECT
|TULIP_CMD_MUSTBEONE
);
1747 TULIP_CSR_WRITE(sc
, csr_busmode
, TULIP_BUSMODE_SWRESET
);
1748 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
1749 33MHz that comes to two microseconds but wait a
1750 bit longer anyways) */
1751 TULIP_CSR_WRITE(sc
, csr_command
, TULIP_CMD_PORTSELECT
|
1752 TULIP_CMD_PCSFUNCTION
| TULIP_CMD_SCRAMBLER
| TULIP_CMD_MUSTBEONE
);
1753 sc
->tulip_gpinit
= TULIP_GP_SMC_9332_PINS
;
1754 sc
->tulip_gpdata
= TULIP_GP_SMC_9332_INIT
;
1755 TULIP_CSR_WRITE(sc
, csr_gp
, TULIP_GP_SMC_9332_PINS
|TULIP_GP_PINSET
);
1756 TULIP_CSR_WRITE(sc
, csr_gp
, TULIP_GP_SMC_9332_INIT
);
1758 for (idx
= 1000; idx
> 0; idx
--) {
1759 u_int32_t csr
= TULIP_CSR_READ(sc
, csr_gp
);
1760 if ((csr
& (TULIP_GP_SMC_9332_OK10
|TULIP_GP_SMC_9332_OK100
)) == (TULIP_GP_SMC_9332_OK10
|TULIP_GP_SMC_9332_OK100
)) {
1763 } else if ((csr
& TULIP_GP_SMC_9332_OK10
) == 0) {
1770 sc
->tulip_media
= cnt
> 100 ? TULIP_MEDIA_100BASETX
: TULIP_MEDIA_10BASET
;
1771 tulip_21140_mediainit(sc
, mip
++, TULIP_MEDIA_100BASETX
,
1772 TULIP_GP_SMC_9332_INIT
,
1773 TULIP_CMD_PORTSELECT
|TULIP_CMD_PCSFUNCTION
1774 |TULIP_CMD_SCRAMBLER
);
1775 tulip_21140_mediainit(sc
, mip
++, TULIP_MEDIA_100BASETX_FD
,
1776 TULIP_GP_SMC_9332_INIT
,
1777 TULIP_CMD_PORTSELECT
|TULIP_CMD_PCSFUNCTION
1778 |TULIP_CMD_SCRAMBLER
|TULIP_CMD_FULLDUPLEX
);
1779 tulip_21140_mediainit(sc
, mip
++, TULIP_MEDIA_10BASET
,
1780 TULIP_GP_SMC_9332_INIT
,
1781 TULIP_CMD_TXTHRSHLDCTL
);
1782 tulip_21140_mediainit(sc
, mip
++, TULIP_MEDIA_10BASET_FD
,
1783 TULIP_GP_SMC_9332_INIT
,
1784 TULIP_CMD_TXTHRSHLDCTL
|TULIP_CMD_FULLDUPLEX
);
1787 static const tulip_boardsw_t tulip_21140_smc9332_boardsw
= {
1788 TULIP_21140_SMC_9332
,
1789 tulip_21140_smc9332_media_probe
,
1791 tulip_null_media_poll
,
1792 tulip_2114x_media_preset
,
1796 tulip_21140_cogent_em100_media_probe(
1797 tulip_softc_t
* const sc
)
1799 tulip_media_info_t
*mip
= sc
->tulip_mediainfo
;
1801 sc
->tulip_gpinit
= TULIP_GP_EM100_PINS
;
1802 sc
->tulip_gpdata
= TULIP_GP_EM100_INIT
;
1803 TULIP_CSR_WRITE(sc
, csr_gp
, TULIP_GP_EM100_PINS
);
1804 TULIP_CSR_WRITE(sc
, csr_gp
, TULIP_GP_EM100_INIT
);
1805 TULIP_CSR_WRITE(sc
, csr_command
,
1806 TULIP_CSR_READ(sc
, csr_command
) | TULIP_CMD_PORTSELECT
|
1807 TULIP_CMD_PCSFUNCTION
| TULIP_CMD_SCRAMBLER
| TULIP_CMD_MUSTBEONE
);
1808 TULIP_CSR_WRITE(sc
, csr_command
,
1809 TULIP_CSR_READ(sc
, csr_command
) & ~TULIP_CMD_TXTHRSHLDCTL
);
1810 sc
->tulip_media
= TULIP_MEDIA_100BASETX
;
1812 tulip_21140_mediainit(sc
, mip
++, TULIP_MEDIA_100BASETX
,
1813 TULIP_GP_EM100_INIT
,
1814 TULIP_CMD_PORTSELECT
|TULIP_CMD_PCSFUNCTION
1815 |TULIP_CMD_SCRAMBLER
);
1816 tulip_21140_mediainit(sc
, mip
++, TULIP_MEDIA_100BASETX_FD
,
1817 TULIP_GP_EM100_INIT
,
1818 TULIP_CMD_PORTSELECT
|TULIP_CMD_PCSFUNCTION
1819 |TULIP_CMD_SCRAMBLER
|TULIP_CMD_FULLDUPLEX
);
1822 static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw
= {
1823 TULIP_21140_COGENT_EM100
,
1824 tulip_21140_cogent_em100_media_probe
,
1826 tulip_null_media_poll
,
1827 tulip_2114x_media_preset
1831 tulip_21140_znyx_zx34x_media_probe(
1832 tulip_softc_t
* const sc
)
1834 tulip_media_info_t
*mip
= sc
->tulip_mediainfo
;
1835 int cnt10
= 0, cnt100
= 0, idx
;
1837 sc
->tulip_gpinit
= TULIP_GP_ZX34X_PINS
;
1838 sc
->tulip_gpdata
= TULIP_GP_ZX34X_INIT
;
1839 TULIP_CSR_WRITE(sc
, csr_gp
, TULIP_GP_ZX34X_PINS
);
1840 TULIP_CSR_WRITE(sc
, csr_gp
, TULIP_GP_ZX34X_INIT
);
1841 TULIP_CSR_WRITE(sc
, csr_command
,
1842 TULIP_CSR_READ(sc
, csr_command
) | TULIP_CMD_PORTSELECT
|
1843 TULIP_CMD_PCSFUNCTION
| TULIP_CMD_SCRAMBLER
| TULIP_CMD_MUSTBEONE
);
1844 TULIP_CSR_WRITE(sc
, csr_command
,
1845 TULIP_CSR_READ(sc
, csr_command
) & ~TULIP_CMD_TXTHRSHLDCTL
);
1848 for (idx
= 1000; idx
> 0; idx
--) {
1849 u_int32_t csr
= TULIP_CSR_READ(sc
, csr_gp
);
1850 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
)) {
1853 } else if ((csr
& TULIP_GP_ZX34X_LNKFAIL
) == 0) {
1862 sc
->tulip_media
= cnt100
> 100 ? TULIP_MEDIA_100BASETX
: TULIP_MEDIA_10BASET
;
1863 tulip_21140_mediainit(sc
, mip
++, TULIP_MEDIA_10BASET
,
1864 TULIP_GP_ZX34X_INIT
,
1865 TULIP_CMD_TXTHRSHLDCTL
);
1866 tulip_21140_mediainit(sc
, mip
++, TULIP_MEDIA_10BASET_FD
,
1867 TULIP_GP_ZX34X_INIT
,
1868 TULIP_CMD_TXTHRSHLDCTL
|TULIP_CMD_FULLDUPLEX
);
1869 tulip_21140_mediainit(sc
, mip
++, TULIP_MEDIA_100BASETX
,
1870 TULIP_GP_ZX34X_INIT
,
1871 TULIP_CMD_PORTSELECT
|TULIP_CMD_PCSFUNCTION
1872 |TULIP_CMD_SCRAMBLER
);
1873 tulip_21140_mediainit(sc
, mip
++, TULIP_MEDIA_100BASETX_FD
,
1874 TULIP_GP_ZX34X_INIT
,
1875 TULIP_CMD_PORTSELECT
|TULIP_CMD_PCSFUNCTION
1876 |TULIP_CMD_SCRAMBLER
|TULIP_CMD_FULLDUPLEX
);
1879 static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw
= {
1880 TULIP_21140_ZNYX_ZX34X
,
1881 tulip_21140_znyx_zx34x_media_probe
,
1883 tulip_null_media_poll
,
1884 tulip_2114x_media_preset
,
1888 tulip_2114x_media_probe(
1889 tulip_softc_t
* const sc
)
1891 sc
->tulip_cmdmode
|= TULIP_CMD_STOREFWD
|TULIP_CMD_MUSTBEONE
1892 |TULIP_CMD_BACKOFFCTR
;
1895 static const tulip_boardsw_t tulip_2114x_isv_boardsw
= {
1897 tulip_2114x_media_probe
,
1900 tulip_2114x_media_preset
,
1903 * At least in some versions of the driver, all 2114x are mapped to
1904 * tulip_21140_eb_boardsw, so this isn't necessarily going to be
1905 * used. But for possible later use, provide this as a clone of
1906 * the dec evalboard configuration. The Avalon card should look the
1907 * same to the software as the eval card, with the exception of the
1908 * srom format in the early production units.
1910 static const tulip_boardsw_t tulip_2114x_avalon_boardsw
= {
1912 tulip_21140_evalboard_media_probe
,
1914 tulip_null_media_poll
,
1915 tulip_2114x_media_preset
,
1920 * ******** END of chip-specific handlers. ***********
1924 * Code the read the SROM and MII bit streams (I2C)
1928 tulip_softc_t
* const sc
)
1931 for (idx
= (300 / 33) + 1; idx
> 0; idx
--)
1932 (void) TULIP_CSR_READ(sc
, csr_busmode
);
1935 #define EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); tulip_delay_300ns(sc); } while (0)
1939 tulip_softc_t
* const sc
)
1943 csr
= SROMSEL
; EMIT
;
1944 csr
= SROMSEL
| SROMRD
; EMIT
;
1945 csr
^= SROMCS
; EMIT
;
1946 csr
^= SROMCLKON
; EMIT
;
1949 * Write 25 cycles of 0 which will force the SROM to be idle.
1951 for (bit
= 3 + SROM_BITWIDTH
+ 16; bit
> 0; bit
--) {
1952 csr
^= SROMCLKOFF
; EMIT
; /* clock low; data not valid */
1953 csr
^= SROMCLKON
; EMIT
; /* clock high; data valid */
1955 csr
^= SROMCLKOFF
; EMIT
;
1956 csr
^= SROMCS
; EMIT
;
1963 tulip_softc_t
* const sc
)
1966 const unsigned bitwidth
= SROM_BITWIDTH
;
1967 const unsigned cmdmask
= (SROMCMD_RD
<< bitwidth
);
1968 const unsigned msb
= 1 << (bitwidth
+ 3 - 1);
1969 unsigned lastidx
= (1 << bitwidth
) - 1;
1971 tulip_srom_idle(sc
);
1973 for (idx
= 0; idx
<= lastidx
; idx
++) {
1974 unsigned lastbit
, data
, bits
, bit
, csr
;
1975 csr
= SROMSEL
; EMIT
;
1976 csr
= SROMSEL
| SROMRD
; EMIT
;
1977 csr
^= SROMCSON
; EMIT
;
1978 csr
^= SROMCLKON
; EMIT
;
1981 for (bits
= idx
|cmdmask
, bit
= bitwidth
+ 3; bit
> 0; bit
--, bits
<<= 1) {
1982 const unsigned thisbit
= bits
& msb
;
1983 csr
^= SROMCLKOFF
; EMIT
; /* clock low; data not valid */
1984 if (thisbit
!= lastbit
) {
1985 csr
^= SROMDOUT
; EMIT
; /* clock low; invert data */
1989 csr
^= SROMCLKON
; EMIT
; /* clock high; data valid */
1992 csr
^= SROMCLKOFF
; EMIT
;
1994 for (data
= 0, bits
= 0; bits
< 16; bits
++) {
1996 csr
^= SROMCLKON
; EMIT
; /* clock high; data valid */
1997 data
|= TULIP_CSR_READ(sc
, csr_srom_mii
) & SROMDIN
? 1 : 0;
1998 csr
^= SROMCLKOFF
; EMIT
; /* clock low; data not valid */
2000 sc
->tulip_rombuf
[idx
*2] = data
& 0xFF;
2001 sc
->tulip_rombuf
[idx
*2+1] = data
>> 8;
2002 csr
= SROMSEL
| SROMRD
; EMIT
;
2005 tulip_srom_idle(sc
);
2008 #define MII_EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); tulip_delay_300ns(sc); } while (0)
2011 tulip_mii_writebits(
2012 tulip_softc_t
* const sc
,
2016 unsigned msb
= 1 << (bits
- 1);
2017 unsigned csr
= TULIP_CSR_READ(sc
, csr_srom_mii
) & (MII_RD
|MII_DOUT
|MII_CLK
);
2018 unsigned lastbit
= (csr
& MII_DOUT
) ? msb
: 0;
2020 csr
|= MII_WR
; MII_EMIT
; /* clock low; assert write */
2022 for (; bits
> 0; bits
--, data
<<= 1) {
2023 const unsigned thisbit
= data
& msb
;
2024 if (thisbit
!= lastbit
) {
2025 csr
^= MII_DOUT
; MII_EMIT
; /* clock low; invert data */
2027 csr
^= MII_CLKON
; MII_EMIT
; /* clock high; data valid */
2029 csr
^= MII_CLKOFF
; MII_EMIT
; /* clock low; data not valid */
2034 tulip_mii_turnaround(
2035 tulip_softc_t
* const sc
,
2038 unsigned csr
= TULIP_CSR_READ(sc
, csr_srom_mii
) & (MII_RD
|MII_DOUT
|MII_CLK
);
2040 if (cmd
== MII_WRCMD
) {
2041 csr
|= MII_DOUT
; MII_EMIT
; /* clock low; change data */
2042 csr
^= MII_CLKON
; MII_EMIT
; /* clock high; data valid */
2043 csr
^= MII_CLKOFF
; MII_EMIT
; /* clock low; data not valid */
2044 csr
^= MII_DOUT
; MII_EMIT
; /* clock low; change data */
2046 csr
|= MII_RD
; MII_EMIT
; /* clock low; switch to read */
2048 csr
^= MII_CLKON
; MII_EMIT
; /* clock high; data valid */
2049 csr
^= MII_CLKOFF
; MII_EMIT
; /* clock low; data not valid */
2054 tulip_softc_t
* const sc
)
2057 unsigned csr
= TULIP_CSR_READ(sc
, csr_srom_mii
) & (MII_RD
|MII_DOUT
|MII_CLK
);
2060 for (idx
= 0, data
= 0; idx
< 16; idx
++) {
2061 data
<<= 1; /* this is NOOP on the first pass through */
2062 csr
^= MII_CLKON
; MII_EMIT
; /* clock high; data valid */
2063 if (TULIP_CSR_READ(sc
, csr_srom_mii
) & MII_DIN
)
2065 csr
^= MII_CLKOFF
; MII_EMIT
; /* clock low; data not valid */
2067 csr
^= MII_RD
; MII_EMIT
; /* clock low; turn off read */
2074 tulip_softc_t
* const sc
,
2078 unsigned csr
= TULIP_CSR_READ(sc
, csr_srom_mii
) & (MII_RD
|MII_DOUT
|MII_CLK
);
2081 csr
&= ~(MII_RD
|MII_CLK
); MII_EMIT
;
2082 tulip_mii_writebits(sc
, MII_PREAMBLE
, 32);
2083 tulip_mii_writebits(sc
, MII_RDCMD
, 8);
2084 tulip_mii_writebits(sc
, devaddr
, 5);
2085 tulip_mii_writebits(sc
, regno
, 5);
2086 tulip_mii_turnaround(sc
, MII_RDCMD
);
2088 data
= tulip_mii_readbits(sc
);
2089 #if defined(TULIP_DEBUG)
2090 sc
->tulip_dbg
.dbg_phyregs
[regno
][0] = data
;
2091 sc
->tulip_dbg
.dbg_phyregs
[regno
][1]++;
2098 tulip_softc_t
* const sc
,
2103 unsigned csr
= TULIP_CSR_READ(sc
, csr_srom_mii
) & (MII_RD
|MII_DOUT
|MII_CLK
);
2104 csr
&= ~(MII_RD
|MII_CLK
); MII_EMIT
;
2105 tulip_mii_writebits(sc
, MII_PREAMBLE
, 32);
2106 tulip_mii_writebits(sc
, MII_WRCMD
, 8);
2107 tulip_mii_writebits(sc
, devaddr
, 5);
2108 tulip_mii_writebits(sc
, regno
, 5);
2109 tulip_mii_turnaround(sc
, MII_WRCMD
);
2110 tulip_mii_writebits(sc
, data
, 16);
2111 #if defined(TULIP_DEBUG)
2112 sc
->tulip_dbg
.dbg_phyregs
[regno
][2] = data
;
2113 sc
->tulip_dbg
.dbg_phyregs
[regno
][3]++;
2117 #define tulip_mchash(mca) (tulip_crc32(mca, 6) & 0x1FF)
2118 #define tulip_srom_crcok(databuf) ( \
2119 ((tulip_crc32(databuf, 126) & 0xFFFF) ^ 0xFFFF)== \
2120 ((databuf)[126] | ((databuf)[127] << 8)))
2124 const unsigned char *databuf
,
2127 u_int idx
, bit
, data
, crc
= 0xFFFFFFFFUL
;
2129 for (idx
= 0; idx
< datalen
; idx
++)
2130 for (data
= *databuf
++, bit
= 0; bit
< 8; bit
++, data
>>= 1)
2131 crc
= (crc
>> 1) ^ (((crc
^ data
) & 1) ? TULIP_CRC32_POLY
: 0);
2136 tulip_identify_dec_nic(
2137 tulip_softc_t
* const sc
)
2139 strcpy(sc
->tulip_boardid
, "DEC ");
2141 if (sc
->tulip_chipid
<= TULIP_DE425
)
2143 if (memcmp(sc
->tulip_rombuf
+ 29, "DE500", 5) == 0
2144 || memcmp(sc
->tulip_rombuf
+ 29, "DE450", 5) == 0) {
2145 memcpy(&sc
->tulip_boardid
[D0
], sc
->tulip_rombuf
+ 29, 8);
2146 sc
->tulip_boardid
[D0
+8] = ' ';
2152 tulip_identify_znyx_nic(
2153 tulip_softc_t
* const sc
)
2156 strcpy(sc
->tulip_boardid
, "ZNYX ZX3XX ");
2157 if (sc
->tulip_chipid
== TULIP_21140
|| sc
->tulip_chipid
== TULIP_21140A
) {
2159 sc
->tulip_boardid
[8] = '4';
2160 znyx_ptr
= sc
->tulip_rombuf
[124] + 256 * sc
->tulip_rombuf
[125];
2161 if (znyx_ptr
< 26 || znyx_ptr
> 116) {
2162 sc
->tulip_boardsw
= &tulip_21140_znyx_zx34x_boardsw
;
2165 /* ZX344 = 0010 .. 0013FF
2167 if (sc
->tulip_rombuf
[znyx_ptr
] == 0x4A
2168 && sc
->tulip_rombuf
[znyx_ptr
+ 1] == 0x52
2169 && sc
->tulip_rombuf
[znyx_ptr
+ 2] == 0x01) {
2170 id
= sc
->tulip_rombuf
[znyx_ptr
+ 5] + 256 * sc
->tulip_rombuf
[znyx_ptr
+ 4];
2171 if ((id
>> 8) == (TULIP_ZNYX_ID_ZX342
>> 8)) {
2172 sc
->tulip_boardid
[9] = '2';
2173 if (id
== TULIP_ZNYX_ID_ZX342B
) {
2174 sc
->tulip_boardid
[10] = 'B';
2175 sc
->tulip_boardid
[11] = ' ';
2177 sc
->tulip_boardsw
= &tulip_21140_znyx_zx34x_boardsw
;
2178 } else if (id
== TULIP_ZNYX_ID_ZX344
) {
2179 sc
->tulip_boardid
[10] = '4';
2180 sc
->tulip_boardsw
= &tulip_21140_znyx_zx34x_boardsw
;
2181 } else if (id
== TULIP_ZNYX_ID_ZX345
) {
2182 sc
->tulip_boardid
[9] = (sc
->tulip_rombuf
[19] > 1) ? '8' : '5';
2183 } else if (id
== TULIP_ZNYX_ID_ZX346
) {
2184 sc
->tulip_boardid
[9] = '6';
2185 } else if (id
== TULIP_ZNYX_ID_ZX351
) {
2186 sc
->tulip_boardid
[8] = '5';
2187 sc
->tulip_boardid
[9] = '1';
2192 * Assume it's a ZX342...
2194 sc
->tulip_boardsw
= &tulip_21140_znyx_zx34x_boardsw
;
2198 sc
->tulip_boardid
[8] = '1';
2199 if (sc
->tulip_chipid
== TULIP_21041
) {
2200 sc
->tulip_boardid
[10] = '1';
2203 if (sc
->tulip_rombuf
[32] == 0x4A && sc
->tulip_rombuf
[33] == 0x52) {
2204 id
= sc
->tulip_rombuf
[37] + 256 * sc
->tulip_rombuf
[36];
2205 if (id
== TULIP_ZNYX_ID_ZX312T
) {
2206 sc
->tulip_boardid
[9] = '2';
2207 sc
->tulip_boardid
[10] = 'T';
2208 sc
->tulip_boardid
[11] = ' ';
2209 sc
->tulip_boardsw
= &tulip_21040_10baset_only_boardsw
;
2210 } else if (id
== TULIP_ZNYX_ID_ZX314_INTA
) {
2211 sc
->tulip_boardid
[9] = '4';
2212 sc
->tulip_boardsw
= &tulip_21040_10baset_only_boardsw
;
2213 sc
->tulip_flags
|= TULIP_SHAREDINTR
|TULIP_BASEROM
;
2214 } else if (id
== TULIP_ZNYX_ID_ZX314
) {
2215 sc
->tulip_boardid
[9] = '4';
2216 sc
->tulip_boardsw
= &tulip_21040_10baset_only_boardsw
;
2217 sc
->tulip_flags
|= TULIP_BASEROM
;
2218 } else if (id
== TULIP_ZNYX_ID_ZX315_INTA
) {
2219 sc
->tulip_boardid
[9] = '5';
2220 sc
->tulip_flags
|= TULIP_SHAREDINTR
|TULIP_BASEROM
;
2221 } else if (id
== TULIP_ZNYX_ID_ZX315
) {
2222 sc
->tulip_boardid
[9] = '5';
2223 sc
->tulip_flags
|= TULIP_BASEROM
;
2229 if ((sc
->tulip_enaddr
[3] & ~3) == 0xF0 && (sc
->tulip_enaddr
[5] & 3) == 0) {
2230 sc
->tulip_boardid
[9] = '4';
2231 sc
->tulip_boardsw
= &tulip_21040_10baset_only_boardsw
;
2232 sc
->tulip_flags
|= TULIP_SHAREDINTR
|TULIP_BASEROM
;
2233 } else if ((sc
->tulip_enaddr
[3] & ~3) == 0xF4 && (sc
->tulip_enaddr
[5] & 1) == 0) {
2234 sc
->tulip_boardid
[9] = '5';
2235 sc
->tulip_boardsw
= &tulip_21040_boardsw
;
2236 sc
->tulip_flags
|= TULIP_SHAREDINTR
|TULIP_BASEROM
;
2237 } else if ((sc
->tulip_enaddr
[3] & ~3) == 0xEC) {
2238 sc
->tulip_boardid
[9] = '2';
2239 sc
->tulip_boardsw
= &tulip_21040_boardsw
;
2245 tulip_identify_smc_nic(
2246 tulip_softc_t
* const sc
)
2248 u_int32_t id1
, id2
, ei
;
2249 int auibnc
= 0, utp
= 0;
2252 strcpy(sc
->tulip_boardid
, "SMC ");
2253 if (sc
->tulip_chipid
== TULIP_21041
)
2255 if (sc
->tulip_chipid
!= TULIP_21040
) {
2256 if (sc
->tulip_boardsw
!= &tulip_2114x_isv_boardsw
) {
2257 strcpy(&sc
->tulip_boardid
[4], "9332DST ");
2258 sc
->tulip_boardsw
= &tulip_21140_smc9332_boardsw
;
2259 } else if (sc
->tulip_flags
& (TULIP_BASEROM
|TULIP_SLAVEDROM
)) {
2260 strcpy(&sc
->tulip_boardid
[4], "9332BDT ");
2262 strcpy(&sc
->tulip_boardid
[4], "9334BDT ");
2266 id1
= sc
->tulip_rombuf
[0x60] | (sc
->tulip_rombuf
[0x61] << 8);
2267 id2
= sc
->tulip_rombuf
[0x62] | (sc
->tulip_rombuf
[0x63] << 8);
2268 ei
= sc
->tulip_rombuf
[0x66] | (sc
->tulip_rombuf
[0x67] << 8);
2270 strcpy(&sc
->tulip_boardid
[4], "8432");
2271 cp
= &sc
->tulip_boardid
[8];
2273 *cp
++ = 'B', auibnc
= 1;
2274 if ((id1
& 0xFF) > 0x32)
2275 *cp
++ = 'T', utp
= 1;
2276 if ((id1
& 0x4000) == 0)
2277 *cp
++ = 'A', auibnc
= 1;
2279 sc
->tulip_boardid
[7] = '4';
2283 *cp
++ = (ei
? '2' : '1');
2288 sc
->tulip_boardsw
= &tulip_21040_10baset_only_boardsw
;
2289 else if (!utp
&& auibnc
)
2290 sc
->tulip_boardsw
= &tulip_21040_auibnc_only_boardsw
;
2294 tulip_identify_cogent_nic(
2295 tulip_softc_t
* const sc
)
2298 strcpy(sc
->tulip_boardid
, "Cogent ");
2299 if (sc
->tulip_chipid
== TULIP_21140
|| sc
->tulip_chipid
== TULIP_21140A
) {
2300 if (sc
->tulip_rombuf
[32] == TULIP_COGENT_EM100_ID
)
2301 sc
->tulip_boardsw
= &tulip_21140_cogent_em100_boardsw
;
2302 } else if (sc
->tulip_chipid
== TULIP_21040
) {
2303 sc
->tulip_flags
|= TULIP_SHAREDINTR
|TULIP_BASEROM
;
2310 tulip_identify_avalon_nic(
2311 tulip_softc_t
* const sc
)
2313 strcpy(sc
->tulip_boardid
, "Avalon PMC2TTX");
2318 tulip_identify_asante_nic(
2319 tulip_softc_t
* const sc
)
2321 strcpy(sc
->tulip_boardid
, "Asante ");
2322 if ((sc
->tulip_chipid
== TULIP_21140
|| sc
->tulip_chipid
== TULIP_21140A
)
2323 && sc
->tulip_boardsw
!= &tulip_2114x_isv_boardsw
) {
2324 tulip_media_info_t
*mi
= sc
->tulip_mediainfo
;
2327 * The Asante Fast Ethernet doesn't always ship with a valid
2328 * new format SROM. So if isn't in the new format, we cheat
2329 * set it up as if we had.
2332 sc
->tulip_gpinit
= TULIP_GP_ASANTE_PINS
;
2333 sc
->tulip_gpdata
= 0;
2335 TULIP_CSR_WRITE(sc
, csr_gp
, TULIP_GP_ASANTE_PINS
|TULIP_GP_PINSET
);
2336 TULIP_CSR_WRITE(sc
, csr_gp
, TULIP_GP_ASANTE_PHYRESET
);
2338 TULIP_CSR_WRITE(sc
, csr_gp
, 0);
2341 mi
->mi_type
= TULIP_MEDIAINFO_MII
;
2342 mi
->mi_gpr_length
= 0;
2343 mi
->mi_gpr_offset
= 0;
2344 mi
->mi_reset_length
= 0;
2345 mi
->mi_reset_offset
= 0;
2347 mi
->mi_phyaddr
= tulip_mii_get_phyaddr(sc
, 0);
2348 if (mi
->mi_phyaddr
== TULIP_MII_NOPHY
)
2350 sc
->tulip_features
|= TULIP_HAVE_MII
;
2351 mi
->mi_capabilities
= PHYSTS_10BASET
|PHYSTS_10BASET_FD
|PHYSTS_100BASETX
|PHYSTS_100BASETX_FD
;
2352 mi
->mi_advertisement
= PHYSTS_10BASET
|PHYSTS_10BASET_FD
|PHYSTS_100BASETX
|PHYSTS_100BASETX_FD
;
2353 mi
->mi_full_duplex
= PHYSTS_10BASET_FD
|PHYSTS_100BASETX_FD
;
2354 mi
->mi_tx_threshold
= PHYSTS_10BASET
|PHYSTS_10BASET_FD
;
2355 TULIP_MEDIAINFO_ADD_CAPABILITY(sc
, mi
, 100BASETX_FD
);
2356 TULIP_MEDIAINFO_ADD_CAPABILITY(sc
, mi
, 100BASETX
);
2357 TULIP_MEDIAINFO_ADD_CAPABILITY(sc
, mi
, 100BASET4
);
2358 TULIP_MEDIAINFO_ADD_CAPABILITY(sc
, mi
, 10BASET_FD
);
2359 TULIP_MEDIAINFO_ADD_CAPABILITY(sc
, mi
, 10BASET
);
2361 sc
->tulip_boardsw
= &tulip_2114x_isv_boardsw
;
2367 tulip_softc_t
* const sc
)
2369 int idx1
, idx2
, idx3
;
2371 const tulip_srom_header_t
*shp
= (tulip_srom_header_t
*) &sc
->tulip_rombuf
[0];
2372 const tulip_srom_adapter_info_t
*saip
= (tulip_srom_adapter_info_t
*) (shp
+ 1);
2373 tulip_srom_media_t srom_media
;
2374 tulip_media_info_t
*mi
= sc
->tulip_mediainfo
;
2376 u_int32_t leaf_offset
, blocks
, data
;
2378 for (idx1
= 0; idx1
< shp
->sh_adapter_count
; idx1
++, saip
++) {
2379 if (shp
->sh_adapter_count
== 1)
2381 if (saip
->sai_device
== sc
->tulip_pci_devno
)
2385 * Didn't find the right media block for this card.
2387 if (idx1
== shp
->sh_adapter_count
)
2391 * Save the hardware address.
2393 memcpy((void *) sc
->tulip_enaddr
, (void *) shp
->sh_ieee802_address
, 6);
2395 * If this is a multiple port card, add the adapter index to the last
2396 * byte of the hardware address. (if it isn't multiport, adding 0
2399 sc
->tulip_enaddr
[5] += idx1
;
2401 leaf_offset
= saip
->sai_leaf_offset_lowbyte
2402 + saip
->sai_leaf_offset_highbyte
* 256;
2403 dp
= sc
->tulip_rombuf
+ leaf_offset
;
2405 sc
->tulip_conntype
= (tulip_srom_connection_t
) (dp
[0] + dp
[1] * 256); dp
+= 2;
2407 for (idx2
= 0;; idx2
++) {
2408 if (tulip_srom_conninfo
[idx2
].sc_type
== sc
->tulip_conntype
2409 || tulip_srom_conninfo
[idx2
].sc_type
== TULIP_SROM_CONNTYPE_NOT_USED
)
2412 sc
->tulip_connidx
= idx2
;
2414 if (sc
->tulip_chipid
== TULIP_21041
) {
2416 for (idx2
= 0; idx2
< blocks
; idx2
++) {
2417 tulip_media_t media
;
2419 srom_media
= (tulip_srom_media_t
) (data
& 0x3F);
2420 for (idx3
= 0; tulip_srom_mediums
[idx3
].sm_type
!= TULIP_MEDIA_UNKNOWN
; idx3
++) {
2421 if (tulip_srom_mediums
[idx3
].sm_srom_type
== srom_media
)
2424 media
= tulip_srom_mediums
[idx3
].sm_type
;
2425 if (media
!= TULIP_MEDIA_UNKNOWN
) {
2426 if (data
& TULIP_SROM_21041_EXTENDED
) {
2427 mi
->mi_type
= TULIP_MEDIAINFO_SIA
;
2428 sc
->tulip_mediums
[media
] = mi
;
2429 mi
->mi_sia_connectivity
= dp
[0] + dp
[1] * 256;
2430 mi
->mi_sia_tx_rx
= dp
[2] + dp
[3] * 256;
2431 mi
->mi_sia_general
= dp
[4] + dp
[5] * 256;
2435 case TULIP_MEDIA_BNC
: {
2436 TULIP_MEDIAINFO_SIA_INIT(sc
, mi
, 21041, BNC
);
2440 case TULIP_MEDIA_AUI
: {
2441 TULIP_MEDIAINFO_SIA_INIT(sc
, mi
, 21041, AUI
);
2445 case TULIP_MEDIA_10BASET
: {
2446 TULIP_MEDIAINFO_SIA_INIT(sc
, mi
, 21041, 10BASET
);
2450 case TULIP_MEDIA_10BASET_FD
: {
2451 TULIP_MEDIAINFO_SIA_INIT(sc
, mi
, 21041, 10BASET_FD
);
2461 if (data
& TULIP_SROM_21041_EXTENDED
)
2466 TULIP_MEDIAINFO_SIA_INIT(sc
, mi
, 21041, BNC
); mi
++;
2467 TULIP_MEDIAINFO_SIA_INIT(sc
, mi
, 21041, AUI
); mi
++;
2468 TULIP_MEDIAINFO_SIA_INIT(sc
, mi
, 21041, 10BASET
); mi
++;
2469 TULIP_MEDIAINFO_SIA_INIT(sc
, mi
, 21041, 10BASET_FD
); mi
++;
2473 unsigned length
, type
;
2474 tulip_media_t gp_media
= TULIP_MEDIA_UNKNOWN
;
2475 if (sc
->tulip_features
& TULIP_HAVE_GPR
)
2476 sc
->tulip_gpinit
= *dp
++;
2478 for (idx2
= 0; idx2
< blocks
; idx2
++) {
2480 if ((*dp
& 0x80) == 0) {
2484 length
= (*dp
++ & 0x7f) - 1;
2485 type
= *dp
++ & 0x3f;
2488 switch (type
& 0x3f) {
2489 case 0: { /* 21140[A] GPR block */
2490 tulip_media_t media
;
2491 srom_media
= (tulip_srom_media_t
) dp
[0];
2492 for (idx3
= 0; tulip_srom_mediums
[idx3
].sm_type
!= TULIP_MEDIA_UNKNOWN
; idx3
++) {
2493 if (tulip_srom_mediums
[idx3
].sm_srom_type
== srom_media
)
2496 media
= tulip_srom_mediums
[idx3
].sm_type
;
2497 if (media
== TULIP_MEDIA_UNKNOWN
)
2499 mi
->mi_type
= TULIP_MEDIAINFO_GPR
;
2500 sc
->tulip_mediums
[media
] = mi
;
2501 mi
->mi_gpdata
= dp
[1];
2502 if (media
> gp_media
&& !TULIP_IS_MEDIA_FD(media
)) {
2503 sc
->tulip_gpdata
= mi
->mi_gpdata
;
2506 data
= dp
[2] + dp
[3] * 256;
2507 mi
->mi_cmdmode
= TULIP_SROM_2114X_CMDBITS(data
);
2508 if (data
& TULIP_SROM_2114X_NOINDICATOR
) {
2512 mi
->mi_default
= (data
& TULIP_SROM_2114X_DEFAULT
) != 0;
2514 mi
->mi_actmask
= TULIP_SROM_2114X_BITPOS(data
);
2515 mi
->mi_actdata
= (data
& TULIP_SROM_2114X_POLARITY
) ? 0 : mi
->mi_actmask
;
2520 case 1: { /* 21140[A] MII block */
2521 const unsigned phyno
= *dp
++;
2522 mi
->mi_type
= TULIP_MEDIAINFO_MII
;
2523 mi
->mi_gpr_length
= *dp
++;
2524 mi
->mi_gpr_offset
= dp
- sc
->tulip_rombuf
;
2525 dp
+= mi
->mi_gpr_length
;
2526 mi
->mi_reset_length
= *dp
++;
2527 mi
->mi_reset_offset
= dp
- sc
->tulip_rombuf
;
2528 dp
+= mi
->mi_reset_length
;
2531 * Before we probe for a PHY, use the GPR information
2532 * to select it. If we don't, it may be inaccessible.
2534 TULIP_CSR_WRITE(sc
, csr_gp
, sc
->tulip_gpinit
|TULIP_GP_PINSET
);
2535 for (idx3
= 0; idx3
< mi
->mi_reset_length
; idx3
++) {
2537 TULIP_CSR_WRITE(sc
, csr_gp
, sc
->tulip_rombuf
[mi
->mi_reset_offset
+ idx3
]);
2539 sc
->tulip_phyaddr
= mi
->mi_phyaddr
;
2540 for (idx3
= 0; idx3
< mi
->mi_gpr_length
; idx3
++) {
2542 TULIP_CSR_WRITE(sc
, csr_gp
, sc
->tulip_rombuf
[mi
->mi_gpr_offset
+ idx3
]);
2545 mi
->mi_phyaddr
= tulip_mii_get_phyaddr(sc
, phyno
);
2546 if (mi
->mi_phyaddr
== TULIP_MII_NOPHY
)
2548 sc
->tulip_features
|= TULIP_HAVE_MII
;
2549 mi
->mi_capabilities
= dp
[0] + dp
[1] * 256; dp
+= 2;
2550 mi
->mi_advertisement
= dp
[0] + dp
[1] * 256; dp
+= 2;
2551 mi
->mi_full_duplex
= dp
[0] + dp
[1] * 256; dp
+= 2;
2552 mi
->mi_tx_threshold
= dp
[0] + dp
[1] * 256; dp
+= 2;
2553 TULIP_MEDIAINFO_ADD_CAPABILITY(sc
, mi
, 100BASETX_FD
);
2554 TULIP_MEDIAINFO_ADD_CAPABILITY(sc
, mi
, 100BASETX
);
2555 TULIP_MEDIAINFO_ADD_CAPABILITY(sc
, mi
, 100BASET4
);
2556 TULIP_MEDIAINFO_ADD_CAPABILITY(sc
, mi
, 10BASET_FD
);
2557 TULIP_MEDIAINFO_ADD_CAPABILITY(sc
, mi
, 10BASET
);
2561 case 2: { /* 2114[23] SIA block */
2562 tulip_media_t media
;
2563 srom_media
= (tulip_srom_media_t
) dp
[0];
2564 for (idx3
= 0; tulip_srom_mediums
[idx3
].sm_type
!= TULIP_MEDIA_UNKNOWN
; idx3
++) {
2565 if (tulip_srom_mediums
[idx3
].sm_srom_type
== srom_media
)
2568 media
= tulip_srom_mediums
[idx3
].sm_type
;
2569 if (media
== TULIP_MEDIA_UNKNOWN
)
2571 mi
->mi_type
= TULIP_MEDIAINFO_SIA
;
2572 sc
->tulip_mediums
[media
] = mi
;
2574 mi
->mi_sia_connectivity
= dp
[0] + dp
[1] * 256;
2575 mi
->mi_sia_tx_rx
= dp
[2] + dp
[3] * 256;
2576 mi
->mi_sia_general
= dp
[4] + dp
[5] * 256;
2580 case TULIP_MEDIA_BNC
: {
2581 TULIP_MEDIAINFO_SIA_INIT(sc
, mi
, 21142, BNC
);
2584 case TULIP_MEDIA_AUI
: {
2585 TULIP_MEDIAINFO_SIA_INIT(sc
, mi
, 21142, AUI
);
2588 case TULIP_MEDIA_10BASET
: {
2589 TULIP_MEDIAINFO_SIA_INIT(sc
, mi
, 21142, 10BASET
);
2592 case TULIP_MEDIA_10BASET_FD
: {
2593 TULIP_MEDIAINFO_SIA_INIT(sc
, mi
, 21142, 10BASET_FD
);
2601 mi
->mi_sia_gp_control
= (dp
[0] + dp
[1] * 256) << 16;
2602 mi
->mi_sia_gp_data
= (dp
[2] + dp
[3] * 256) << 16;
2607 case 3: { /* 2114[23] MII PHY block */
2608 const unsigned phyno
= *dp
++;
2609 const u_int8_t
*dp0
;
2610 mi
->mi_type
= TULIP_MEDIAINFO_MII
;
2611 mi
->mi_gpr_length
= *dp
++;
2612 mi
->mi_gpr_offset
= dp
- sc
->tulip_rombuf
;
2613 dp
+= 2 * mi
->mi_gpr_length
;
2614 mi
->mi_reset_length
= *dp
++;
2615 mi
->mi_reset_offset
= dp
- sc
->tulip_rombuf
;
2616 dp
+= 2 * mi
->mi_reset_length
;
2618 dp0
= &sc
->tulip_rombuf
[mi
->mi_reset_offset
];
2619 for (idx3
= 0; idx3
< mi
->mi_reset_length
; idx3
++, dp0
+= 2) {
2621 TULIP_CSR_WRITE(sc
, csr_sia_general
, (dp0
[0] + 256 * dp0
[1]) << 16);
2623 sc
->tulip_phyaddr
= mi
->mi_phyaddr
;
2624 dp0
= &sc
->tulip_rombuf
[mi
->mi_gpr_offset
];
2625 for (idx3
= 0; idx3
< mi
->mi_gpr_length
; idx3
++, dp0
+= 2) {
2627 TULIP_CSR_WRITE(sc
, csr_sia_general
, (dp0
[0] + 256 * dp0
[1]) << 16);
2629 mi
->mi_phyaddr
= tulip_mii_get_phyaddr(sc
, phyno
);
2630 if (mi
->mi_phyaddr
== TULIP_MII_NOPHY
)
2632 sc
->tulip_features
|= TULIP_HAVE_MII
;
2633 mi
->mi_capabilities
= dp
[0] + dp
[1] * 256; dp
+= 2;
2634 mi
->mi_advertisement
= dp
[0] + dp
[1] * 256; dp
+= 2;
2635 mi
->mi_full_duplex
= dp
[0] + dp
[1] * 256; dp
+= 2;
2636 mi
->mi_tx_threshold
= dp
[0] + dp
[1] * 256; dp
+= 2;
2637 mi
->mi_mii_interrupt
= dp
[0] + dp
[1] * 256; dp
+= 2;
2638 TULIP_MEDIAINFO_ADD_CAPABILITY(sc
, mi
, 100BASETX_FD
);
2639 TULIP_MEDIAINFO_ADD_CAPABILITY(sc
, mi
, 100BASETX
);
2640 TULIP_MEDIAINFO_ADD_CAPABILITY(sc
, mi
, 100BASET4
);
2641 TULIP_MEDIAINFO_ADD_CAPABILITY(sc
, mi
, 10BASET_FD
);
2642 TULIP_MEDIAINFO_ADD_CAPABILITY(sc
, mi
, 10BASET
);
2646 case 4: { /* 21143 SYM block */
2647 tulip_media_t media
;
2648 srom_media
= (tulip_srom_media_t
) dp
[0];
2649 for (idx3
= 0; tulip_srom_mediums
[idx3
].sm_type
!= TULIP_MEDIA_UNKNOWN
; idx3
++) {
2650 if (tulip_srom_mediums
[idx3
].sm_srom_type
== srom_media
)
2653 media
= tulip_srom_mediums
[idx3
].sm_type
;
2654 if (media
== TULIP_MEDIA_UNKNOWN
)
2656 mi
->mi_type
= TULIP_MEDIAINFO_SYM
;
2657 sc
->tulip_mediums
[media
] = mi
;
2658 mi
->mi_gpcontrol
= (dp
[1] + dp
[2] * 256) << 16;
2659 mi
->mi_gpdata
= (dp
[3] + dp
[4] * 256) << 16;
2660 data
= dp
[5] + dp
[6] * 256;
2661 mi
->mi_cmdmode
= TULIP_SROM_2114X_CMDBITS(data
);
2662 if (data
& TULIP_SROM_2114X_NOINDICATOR
) {
2665 mi
->mi_default
= (data
& TULIP_SROM_2114X_DEFAULT
) != 0;
2666 mi
->mi_actmask
= TULIP_SROM_2114X_BITPOS(data
);
2667 mi
->mi_actdata
= (data
& TULIP_SROM_2114X_POLARITY
) ? 0 : mi
->mi_actmask
;
2673 case 5: { /* 21143 Reset block */
2674 mi
->mi_type
= TULIP_MEDIAINFO_RESET
;
2675 mi
->mi_reset_length
= *dp
++;
2676 mi
->mi_reset_offset
= dp
- sc
->tulip_rombuf
;
2677 dp
+= 2 * mi
->mi_reset_length
;
2688 return mi
- sc
->tulip_mediainfo
;
2691 static const struct {
2692 void (*vendor_identify_nic
)(tulip_softc_t
* const sc
);
2693 unsigned char vendor_oui
[3];
2694 } tulip_vendors
[] = {
2695 { tulip_identify_dec_nic
, { 0x08, 0x00, 0x2B } },
2696 { tulip_identify_dec_nic
, { 0x00, 0x00, 0xF8 } },
2697 { tulip_identify_smc_nic
, { 0x00, 0x00, 0xC0 } },
2698 { tulip_identify_smc_nic
, { 0x00, 0xE0, 0x29 } },
2699 { tulip_identify_znyx_nic
, { 0x00, 0xC0, 0x95 } },
2700 { tulip_identify_cogent_nic
, { 0x00, 0x00, 0x92 } },
2701 { tulip_identify_asante_nic
, { 0x00, 0x00, 0x94 } },
2703 { tulip_identify_avalon_nic
, { 0x00, 0x80, 0xe0 } },
2704 { tulip_identify_avalon_nic
, { 0x02, 0xbb, 0x01 } },
2706 { tulip_identify_dec_nic
, { 0x00, 0x80, 0xe0 } },
2707 { tulip_identify_dec_nic
, { 0x02, 0xbb, 0x01 } },
2713 * This deals with the vagaries of the address roms and the
2714 * brain-deadness that various vendors commit in using them.
2718 tulip_softc_t
* const sc
)
2720 int cksum
, rom_cksum
, idx
;
2722 unsigned char tmpbuf
[8];
2723 static const u_char testpat
[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
2725 sc
->tulip_connidx
= TULIP_SROM_LASTCONNIDX
;
2727 if (sc
->tulip_chipid
== TULIP_21040
) {
2728 TULIP_CSR_WRITE(sc
, csr_enetrom
, 1);
2729 for (idx
= 0; idx
< sizeof(sc
->tulip_rombuf
); idx
++) {
2731 while (((csr
= TULIP_CSR_READ(sc
, csr_enetrom
)) & 0x80000000L
) && cnt
< 10000)
2733 sc
->tulip_rombuf
[idx
] = csr
& 0xFF;
2735 sc
->tulip_boardsw
= &tulip_21040_boardsw
;
2736 #if defined(TULIP_EISA)
2737 } else if (sc
->tulip_chipid
== TULIP_DE425
) {
2739 for (idx
= 0, cnt
= 0; idx
< sizeof(testpat
) && cnt
< 32; cnt
++) {
2740 tmpbuf
[idx
] = TULIP_CSR_READBYTE(sc
, csr_enetrom
);
2741 if (tmpbuf
[idx
] == testpat
[idx
])
2746 for (idx
= 0; idx
< 32; idx
++)
2747 sc
->tulip_rombuf
[idx
] = TULIP_CSR_READBYTE(sc
, csr_enetrom
);
2748 sc
->tulip_boardsw
= &tulip_21040_boardsw
;
2749 #endif /* TULIP_EISA */
2751 if (sc
->tulip_chipid
== TULIP_21041
) {
2753 * Thankfully all 21041's act the same.
2755 sc
->tulip_boardsw
= &tulip_21041_boardsw
;
2758 * Assume all 21140 board are compatible with the
2759 * DEC 10/100 evaluation board. Not really valid but
2760 * it's the best we can do until every one switches to
2761 * the new SROM format.
2764 sc
->tulip_boardsw
= &tulip_21140_eb_boardsw
;
2766 tulip_srom_read(sc
);
2767 if (tulip_srom_crcok(sc
->tulip_rombuf
)) {
2769 * SROM CRC is valid therefore it must be in the
2772 sc
->tulip_features
|= TULIP_HAVE_ISVSROM
;
2773 } else if (sc
->tulip_rombuf
[126] == 0xff && sc
->tulip_rombuf
[127] == 0xFF) {
2775 * No checksum is present. See if the SROM id checks out;
2776 * the first 18 bytes should be 0 followed by a 1 followed
2777 * by the number of adapters (which we don't deal with yet).
2779 for (idx
= 0; idx
< 18; idx
++) {
2780 if (sc
->tulip_rombuf
[idx
] != 0)
2783 if (idx
== 18 && sc
->tulip_rombuf
[18] == 1 && sc
->tulip_rombuf
[19] != 0)
2784 sc
->tulip_features
|= TULIP_HAVE_ISVSROM
;
2786 if ((sc
->tulip_features
& TULIP_HAVE_ISVSROM
) && tulip_srom_decode(sc
)) {
2787 if (sc
->tulip_chipid
!= TULIP_21041
)
2788 sc
->tulip_boardsw
= &tulip_2114x_isv_boardsw
;
2791 * If the SROM specifies more than one adapter, tag this as a
2794 if (sc
->tulip_rombuf
[19] > 1)
2795 sc
->tulip_flags
|= TULIP_BASEROM
;
2796 if (sc
->tulip_boardsw
== NULL
)
2803 if (memcmp(&sc
->tulip_rombuf
[0], &sc
->tulip_rombuf
[16], 8) != 0) {
2805 * Detect early Avalon 100-TX PMC cards with magic number followed
2806 * by hw addr. These should all have been upgraded by now. It's an
2807 * electronic eeprom write-in-place, so there's no excuse not to...
2809 if (memcmp("AC5E", sc
->tulip_rombuf
, 4) == 0) {
2810 panic("PMC2TTX: old format Avalon srom, reprogram hw addr");
2812 printf("ade%d: Warning: reinit srom! Old Avalon format!",
2814 memcpy(sc
->tulip_enaddr
, sc
->tulip_rombuf
+ 4, 6);
2815 sc
->tulip_flags
|= TULIP_ROMOK
;
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 memcpy(sc
->tulip_enaddr
, sc
->tulip_rombuf
, 6);
2840 sc
->tulip_flags
|= TULIP_ROMOK
;
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
= TULIP_UNIT_TO_SOFTC(root_unit
);
2862 if (root_sc
== NULL
|| (root_sc
->tulip_flags
& (TULIP_ROMOK
|TULIP_SLAVEDROM
)) == TULIP_ROMOK
)
2866 if (root_sc
!= NULL
&& (root_sc
->tulip_flags
& TULIP_BASEROM
)
2867 && root_sc
->tulip_chipid
== sc
->tulip_chipid
2868 && root_sc
->tulip_pci_busno
== sc
->tulip_pci_busno
) {
2869 sc
->tulip_flags
|= TULIP_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 memcpy(sc
->tulip_rombuf
, root_sc
->tulip_rombuf
,
2874 sizeof(sc
->tulip_rombuf
));
2875 if (!tulip_srom_decode(sc
))
2878 memcpy(sc
->tulip_enaddr
, root_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_flags
& TULIP_SHAREDINTR
) {
2889 sc
->tulip_slaves
= root_sc
->tulip_slaves
;
2890 root_sc
->tulip_slaves
= sc
;
2891 sc
->tulip_flags
|= TULIP_SLAVEDINTR
;
2899 * This is the standard DEC address ROM test.
2902 if (memcmp(&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 (memcmp(&sc
->tulip_rombuf
[0], tmpbuf
, 8) != 0)
2912 memcpy(sc
->tulip_enaddr
, sc
->tulip_rombuf
, 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 (memcmp((void *) sc
->tulip_enaddr
,
2935 (void *) tulip_vendors
[idx
].vendor_oui
, 3) == 0) {
2936 (*tulip_vendors
[idx
].vendor_identify_nic
)(sc
);
2941 sc
->tulip_flags
|= TULIP_ROMOK
;
2947 tulip_softc_t
* const sc
)
2949 tulip_media_t media
;
2952 for (media
= TULIP_MEDIA_UNKNOWN
; media
< TULIP_MEDIA_MAX
; media
++) {
2953 if (sc
->tulip_mediums
[media
] != NULL
) {
2954 ifmedia_add(&sc
->tulip_ifmedia
, tulip_media_to_ifmedia
[media
],
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(
2974 struct ifnet
* const ifp
)
2976 tulip_softc_t
* const sc
= TULIP_IFP_TO_SOFTC(ifp
);
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
);
2993 sc
->tulip_flags
&= ~(TULIP_TXPROBE_ACTIVE
|TULIP_WANTRXACT
);
3000 * Media status callback
3003 tulip_ifmedia_status(
3004 struct ifnet
* const ifp
,
3005 struct ifmediareq
*req
)
3007 tulip_softc_t
*sc
= TULIP_IFP_TO_SOFTC(ifp
);
3009 #if defined(__bsdi__)
3010 if (sc
->tulip_mii
.mii_instance
!= 0) {
3011 mii_pollstat(&sc
->tulip_mii
);
3012 req
->ifm_active
= sc
->tulip_mii
.mii_media_active
;
3013 req
->ifm_status
= sc
->tulip_mii
.mii_media_status
;
3017 if (sc
->tulip_media
== TULIP_MEDIA_UNKNOWN
)
3020 req
->ifm_status
= IFM_AVALID
;
3021 if (sc
->tulip_flags
& TULIP_LINKUP
)
3022 req
->ifm_status
|= IFM_ACTIVE
;
3024 req
->ifm_active
= tulip_media_to_ifmedia
[sc
->tulip_media
];
3029 tulip_softc_t
* const sc
)
3031 struct ether_multistep step
;
3032 struct ether_multi
*enm
;
3034 sc
->tulip_flags
&= ~(TULIP_WANTHASH
|TULIP_ALLMULTI
);
3035 sc
->tulip_flags
|= TULIP_WANTSETUP
;
3036 sc
->tulip_cmdmode
&= ~TULIP_CMD_RXRUN
;
3037 sc
->tulip_intrmask
&= ~TULIP_STS_RXSTOPPED
;
3038 #if defined(IFF_ALLMULTI)
3039 sc
->tulip_if
.if_flags
&= ~IFF_ALLMULTI
;
3041 if (sc
->tulip_multicnt
> 14) {
3043 * Some early passes of the 21140 have broken multicast hashes.
3044 * When we get too many multicasts with these chips, we have to
3045 * switch into all-multicast mode.
3047 if (sc
->tulip_features
& TULIP_HAVE_BROKEN_HASH
) {
3048 sc
->tulip_flags
|= TULIP_ALLMULTI
;
3050 u_int32_t
*sp
= sc
->tulip_setupdata
;
3053 * If we have more than 14 multicasts, we have
3054 * go into hash perfect mode (512 bit multicast
3055 * hash and one perfect hardware).
3057 memset(sc
->tulip_setupdata
, 0, sizeof(sc
->tulip_setupdata
));
3058 ETHER_FIRST_MULTI(step
, TULIP_ETHERCOM(sc
), enm
);
3059 while (enm
!= NULL
) {
3060 if (memcmp(enm
->enm_addrlo
, enm
->enm_addrhi
, 6) == 0) {
3061 hash
= tulip_mchash(enm
->enm_addrlo
);
3062 sp
[hash
>> 4] |= 1 << (hash
& 0xF);
3064 sc
->tulip_flags
|= TULIP_ALLMULTI
;
3067 ETHER_NEXT_MULTI(step
, enm
);
3070 * No reason to use a hash if we are going to be
3071 * receiving every multicast.
3073 if ((sc
->tulip_flags
& TULIP_ALLMULTI
) == 0) {
3074 hash
= tulip_mchash(etherbroadcastaddr
);
3075 sp
[hash
>> 4] |= 1 << (hash
& 0xF);
3076 sc
->tulip_flags
|= TULIP_WANTHASH
;
3077 sp
[39] = ((u_int16_t
*) sc
->tulip_enaddr
)[0];
3078 sp
[40] = ((u_int16_t
*) sc
->tulip_enaddr
)[1];
3079 sp
[41] = ((u_int16_t
*) sc
->tulip_enaddr
)[2];
3083 if ((sc
->tulip_flags
& TULIP_WANTHASH
) == 0) {
3084 u_int32_t
*sp
= sc
->tulip_setupdata
;
3086 if ((sc
->tulip_flags
& TULIP_ALLMULTI
) == 0) {
3088 * Else can get perfect filtering for 16 addresses.
3090 ETHER_FIRST_MULTI(step
, TULIP_ETHERCOM(sc
), enm
);
3091 for (; enm
!= NULL
; idx
++) {
3092 if (memcmp(enm
->enm_addrlo
, enm
->enm_addrhi
, 6) == 0) {
3093 *sp
++ = ((u_int16_t
*) enm
->enm_addrlo
)[0];
3094 *sp
++ = ((u_int16_t
*) enm
->enm_addrlo
)[1];
3095 *sp
++ = ((u_int16_t
*) enm
->enm_addrlo
)[2];
3097 sc
->tulip_flags
|= TULIP_ALLMULTI
;
3100 ETHER_NEXT_MULTI(step
, enm
);
3103 * Add the broadcast address.
3111 * Pad the rest with our hardware address
3113 for (; idx
< 16; idx
++) {
3114 *sp
++ = ((u_int16_t
*) sc
->tulip_enaddr
)[0];
3115 *sp
++ = ((u_int16_t
*) sc
->tulip_enaddr
)[1];
3116 *sp
++ = ((u_int16_t
*) sc
->tulip_enaddr
)[2];
3119 #if defined(IFF_ALLMULTI)
3120 if (sc
->tulip_flags
& TULIP_ALLMULTI
)
3121 sc
->tulip_if
.if_flags
|= IFF_ALLMULTI
;
3127 tulip_softc_t
* const sc
)
3129 tulip_ringinfo_t
*ri
;
3131 u_int32_t inreset
= (sc
->tulip_flags
& TULIP_INRESET
);
3135 * Brilliant. Simply brilliant. When switching modes/speeds
3136 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
3137 * bits in CSR6 and then do a software reset to get the 21140
3138 * to properly reset its internal pathways to the right places.
3141 if (sc
->tulip_boardsw
->bd_media_preset
!= NULL
)
3142 (*sc
->tulip_boardsw
->bd_media_preset
)(sc
);
3144 TULIP_CSR_WRITE(sc
, csr_busmode
, TULIP_BUSMODE_SWRESET
);
3145 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
3146 33MHz that comes to two microseconds but wait a
3147 bit longer anyways) */
3150 sc
->tulip_flags
|= TULIP_INRESET
;
3151 sc
->tulip_flags
&= ~(TULIP_NEEDRESET
|TULIP_RXBUFSLOW
);
3152 sc
->tulip_if
.if_flags
&= ~IFF_OACTIVE
;
3155 TULIP_CSR_WRITE(sc
, csr_txlist
, a12map(TULIP_KVATOPHYS(sc
, &sc
->tulip_txinfo
.ri_first
[0])));
3156 TULIP_CSR_WRITE(sc
, csr_rxlist
, a12map(TULIP_KVATOPHYS(sc
, &sc
->tulip_rxinfo
.ri_first
[0])));
3157 if(cputype
==ST_AVALON_A12
)
3158 TULIP_CSR_WRITE(sc
, csr_busmode
, 0x00008100);
3160 TULIP_CSR_WRITE(sc
, csr_busmode
,
3161 (1 << (TULIP_BURSTSIZE(sc
->tulip_unit
) + 8))
3162 |TULIP_BUSMODE_CACHE_ALIGN8
3163 |TULIP_BUSMODE_READMULTIPLE
3164 |(BYTE_ORDER
!= LITTLE_ENDIAN
? TULIP_BUSMODE_BIGENDIAN
: 0));
3167 sc
->tulip_txtimer
= 0;
3171 sc
->tulip_txq
.ifq_maxlen
= TULIP_TXDESCS
;
3173 * Free all the mbufs that were on the transmit ring.
3177 IF_DEQUEUE(&sc
->tulip_txq
, m
);
3183 ri
= &sc
->tulip_txinfo
;
3184 ri
->ri_nextin
= ri
->ri_nextout
= ri
->ri_first
;
3185 ri
->ri_free
= ri
->ri_max
;
3186 for (di
= ri
->ri_first
; di
< ri
->ri_last
; di
++)
3189 * We need to collect all the mbufs on the
3190 * receive ring before we reinit it either to put
3191 * them back on or to know if we have to allocate
3194 ri
= &sc
->tulip_rxinfo
;
3195 ri
->ri_nextin
= ri
->ri_nextout
= ri
->ri_first
;
3196 ri
->ri_free
= ri
->ri_max
;
3197 for (di
= ri
->ri_first
; di
< ri
->ri_last
; di
++) {
3210 IF_DEQUEUE(&sc
->tulip_rxq
, m
);
3217 * If tulip_reset is being called recurisvely, exit quickly knowing
3218 * that when the outer tulip_reset returns all the right stuff will
3224 sc
->tulip_intrmask
|= TULIP_STS_NORMALINTR
|TULIP_STS_RXINTR
|TULIP_STS_TXINTR
3225 |TULIP_STS_ABNRMLINTR
|TULIP_STS_SYSERROR
|TULIP_STS_TXSTOPPED
3226 |TULIP_STS_TXBABBLE
|TULIP_STS_LINKFAIL
|TULIP_STS_RXSTOPPED
;
3228 if ((sc
->tulip_flags
& TULIP_DEVICEPROBE
) == 0)
3229 (*sc
->tulip_boardsw
->bd_media_select
)(sc
);
3230 #if defined(TULIP_DEBUG)
3231 if ((sc
->tulip_flags
& TULIP_NEEDRESET
) == TULIP_NEEDRESET
)
3232 printf(TULIP_PRINTF_FMT
": tulip_reset: additional reset needed?!?\n",
3235 tulip_media_print(sc
);
3236 if (sc
->tulip_features
& TULIP_HAVE_DUALSENSE
)
3237 TULIP_CSR_WRITE(sc
, csr_sia_status
, TULIP_CSR_READ(sc
, csr_sia_status
));
3239 sc
->tulip_flags
&= ~(TULIP_DOINGSETUP
|TULIP_WANTSETUP
|TULIP_INRESET
3241 tulip_addr_filter(sc
);
3246 tulip_softc_t
* const sc
)
3248 if (sc
->tulip_if
.if_flags
& IFF_UP
) {
3249 if ((sc
->tulip_if
.if_flags
& IFF_RUNNING
) == 0) {
3250 /* initialize the media */
3253 sc
->tulip_if
.if_flags
|= IFF_RUNNING
;
3254 if (sc
->tulip_if
.if_flags
& IFF_PROMISC
) {
3255 sc
->tulip_cmdmode
|= TULIP_CMD_PROMISCUOUS
;
3257 sc
->tulip_cmdmode
&= ~TULIP_CMD_PROMISCUOUS
;
3258 if (sc
->tulip_flags
& TULIP_ALLMULTI
) {
3259 sc
->tulip_cmdmode
|= TULIP_CMD_ALLMULTI
;
3261 sc
->tulip_cmdmode
&= ~TULIP_CMD_ALLMULTI
;
3264 sc
->tulip_cmdmode
|= TULIP_CMD_TXRUN
;
3265 if ((sc
->tulip_flags
& (TULIP_TXPROBE_ACTIVE
|TULIP_WANTSETUP
)) == 0) {
3267 sc
->tulip_cmdmode
|= TULIP_CMD_RXRUN
;
3268 sc
->tulip_intrmask
|= TULIP_STS_RXSTOPPED
;
3270 sc
->tulip_if
.if_flags
|= IFF_OACTIVE
;
3271 sc
->tulip_cmdmode
&= ~TULIP_CMD_RXRUN
;
3272 sc
->tulip_intrmask
&= ~TULIP_STS_RXSTOPPED
;
3274 TULIP_CSR_WRITE(sc
, csr_intr
, sc
->tulip_intrmask
);
3275 TULIP_CSR_WRITE(sc
, csr_command
, sc
->tulip_cmdmode
);
3276 tulip_ifstart(&sc
->tulip_if
);
3278 sc
->tulip_if
.if_flags
&= ~IFF_RUNNING
;
3285 tulip_softc_t
* const sc
)
3287 tulip_ringinfo_t
* const ri
= &sc
->tulip_rxinfo
;
3288 struct ifnet
* const ifp
= &sc
->tulip_if
;
3290 #if defined(TULIP_DEBUG)
3295 struct ether_header eh
;
3296 tulip_desc_t
*eop
= ri
->ri_nextin
;
3297 int total_len
= 0, last_offset
= 0;
3298 struct mbuf
*ms
= NULL
, *me
= NULL
;
3301 if (fillok
&& sc
->tulip_rxq
.ifq_len
< TULIP_RXQ_TARGET
)
3304 #if defined(TULIP_DEBUG)
3305 if (cnt
== ri
->ri_max
)
3309 * If the TULIP has no descriptors, there can't be any receive
3310 * descriptors to process.
3312 if (eop
== ri
->ri_nextout
)
3316 * 90% of the packets will fit in one descriptor. So we optimize
3319 if ((((volatile tulip_desc_t
*) eop
)->d_status
& (TULIP_DSTS_OWNER
|TULIP_DSTS_RxFIRSTDESC
|TULIP_DSTS_RxLASTDESC
)) == (TULIP_DSTS_RxFIRSTDESC
|TULIP_DSTS_RxLASTDESC
)) {
3320 IF_DEQUEUE(&sc
->tulip_rxq
, ms
);
3324 * If still owned by the TULIP, don't touch it.
3326 if (((volatile tulip_desc_t
*) eop
)->d_status
& TULIP_DSTS_OWNER
)
3330 * It is possible (though improbable unless the BIG_PACKET support
3331 * is enabled or MCLBYTES < 1518) for a received packet to cross
3332 * more than one receive descriptor.
3334 while ((((volatile tulip_desc_t
*) eop
)->d_status
& TULIP_DSTS_RxLASTDESC
) == 0) {
3335 #if defined(LCLDMA) && defined(DIAGNOSTIC)
3336 panic("tulip descriptor count > 1");
3338 if (++eop
== ri
->ri_last
)
3340 if (eop
== ri
->ri_nextout
|| ((((volatile tulip_desc_t
*) eop
)->d_status
& TULIP_DSTS_OWNER
))) {
3341 #if defined(TULIP_DEBUG)
3342 sc
->tulip_dbg
.dbg_rxintrs
++;
3343 sc
->tulip_dbg
.dbg_rxpktsperintr
[cnt
]++;
3350 * Dequeue the first buffer for the start of the packet. Hopefully
3351 * this will be the only one we need to dequeue. However, if the
3352 * packet consumed multiple descriptors, then we need to dequeue
3353 * those buffers and chain to the starting mbuf. All buffers but
3354 * the last buffer have the same length so we can set that now.
3355 * (we add to last_offset instead of multiplying since we normally
3356 * won't go into the loop and thereby saving a ourselves from
3357 * doing a multiplication by 0 in the normal case).
3359 IF_DEQUEUE(&sc
->tulip_rxq
, ms
);
3360 for (me
= ms
; total_len
> 0; total_len
--) {
3361 me
->m_len
= TULIP_RX_BUFLEN
;
3362 last_offset
+= TULIP_RX_BUFLEN
;
3363 IF_DEQUEUE(&sc
->tulip_rxq
, me
->m_next
);
3369 * Now get the size of received packet (minus the CRC).
3371 total_len
= ((eop
->d_status
>> 16) & 0x7FFF) - 4;
3373 if ((eop
->d_status
& TULIP_DSTS_ERRSUM
) == 0
3374 || (sc
->tulip_flags
& TULIP_RXBAD
)
3376 || (total_len
<= sc
->tulip_if
.if_mtu
+ sizeof(struct ether_header
) &&
3377 (eop
->d_status
& (TULIP_DSTS_RxBADLENGTH
|TULIP_DSTS_RxRUNT
|
3378 TULIP_DSTS_RxCOLLSEEN
|TULIP_DSTS_RxBADCRC
|
3379 TULIP_DSTS_RxOVERFLOW
)) == 0)
3382 me
->m_len
= total_len
- last_offset
;
3383 eh
= *mtod(ms
, struct ether_header
*);
3385 if (sc
->tulip_bpf
!= NULL
) {
3387 TULIP_BPF_TAP(sc
, mtod(ms
, void *), total_len
);
3389 TULIP_BPF_MTAP(sc
, ms
);
3392 if ((sc
->tulip_if
.if_flags
& IFF_PROMISC
)
3393 && (eh
.ether_dhost
[0] & 1) == 0
3394 && !TULIP_ADDREQUAL(eh
.ether_dhost
, sc
->tulip_enaddr
))
3397 sc
->tulip_flags
|= TULIP_RXACT
;
3400 if (eop
->d_status
& (TULIP_DSTS_RxBADLENGTH
|TULIP_DSTS_RxOVERFLOW
|TULIP_DSTS_RxWATCHDOG
)) {
3401 sc
->tulip_dot3stats
.dot3StatsInternalMacReceiveErrors
++;
3403 const char *error
= NULL
;
3404 if (eop
->d_status
& TULIP_DSTS_RxTOOLONG
) {
3405 sc
->tulip_dot3stats
.dot3StatsFrameTooLongs
++;
3406 error
= "frame too long";
3408 if (eop
->d_status
& TULIP_DSTS_RxBADCRC
) {
3409 if (eop
->d_status
& TULIP_DSTS_RxDRBBLBIT
) {
3410 sc
->tulip_dot3stats
.dot3StatsAlignmentErrors
++;
3411 error
= "alignment error";
3413 sc
->tulip_dot3stats
.dot3StatsFCSErrors
++;
3417 if (error
!= NULL
&& (sc
->tulip_flags
& TULIP_NOMESSAGES
) == 0) {
3418 printf(TULIP_PRINTF_FMT
": receive: " TULIP_EADDR_FMT
": %s\n",
3420 TULIP_EADDR_ARGS(mtod(ms
, u_char
*) + 6),
3422 sc
->tulip_flags
|= TULIP_NOMESSAGES
;
3427 #if defined(TULIP_DEBUG)
3431 if (++eop
== ri
->ri_last
)
3433 ri
->ri_nextin
= eop
;
3436 * Either we are priming the TULIP with mbufs (m == NULL)
3437 * or we are about to accept an mbuf for the upper layers
3438 * so we need to allocate an mbuf to replace it. If we
3439 * can't replace it, send up it anyways. This may cause
3440 * us to drop packets in the future but that's better than
3441 * being caught in livelock.
3443 * Note that if this packet crossed multiple descriptors
3444 * we don't even try to reallocate all the mbufs here.
3445 * Instead we rely on the test of the beginning of
3446 * the loop to refill for the extra consumed mbufs.
3448 if (accept
|| ms
== NULL
) {
3450 MGETHDR(m0
, M_DONTWAIT
, MT_DATA
);
3452 #if defined(TULIP_COPY_RXDATA)
3453 if (!accept
|| total_len
>= MHLEN
- 2) {
3456 MCLGET(m0
, M_DONTWAIT
);
3457 if ((m0
->m_flags
& M_EXT
) == 0) {
3461 #endif /* defined(LCLDMA) */
3462 #if defined(TULIP_COPY_RXDATA)
3467 #if defined(TULIP_COPY_RXDATA)
3471 #if defined(__bsdi__)
3472 eh
.ether_type
= ntohs(eh
.ether_type
);
3474 #if !defined(TULIP_COPY_RXDATA)
3475 ms
->m_pkthdr
.len
= total_len
;
3476 ms
->m_pkthdr
.rcvif
= ifp
;
3477 #if defined(__NetBSD__)
3478 (*ifp
->if_input
)(ifp
, ms
);
3480 m_adj(ms
, sizeof(struct ether_header
);
3481 ether_input(ifp
, &eh
, ms
);
3482 #endif /* __NetBSD__ */
3484 #error LCLDMA requires TULIP_COPY_RXDATA
3488 #error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
3490 m0
->m_data
+= 2; /* align data after header */
3491 m_copydata(ms
, 0, total_len
, mtod(m0
, void *));
3492 m0
->m_len
= m0
->m_pkthdr
.len
= total_len
;
3493 m0
->m_pkthdr
.rcvif
= ifp
;
3494 #if defined(__NetBSD__)
3495 (*ifp
->if_input
)(ifp
, m0
);
3497 m_adj(m0
, sizeof(struct ether_header
);
3498 ether_input(ifp
, &eh
, m0
);
3499 #endif /* __NetBSD__ */
3501 #endif /* ! TULIP_COPY_RXDATA */
3507 * Couldn't allocate a new buffer. Don't bother
3508 * trying to replenish the receive queue.
3511 sc
->tulip_flags
|= TULIP_RXBUFSLOW
;
3512 #if defined(TULIP_DEBUG)
3513 sc
->tulip_dbg
.dbg_rxlowbufs
++;
3518 * Now give the buffer(s) to the TULIP and save in our
3523 * Made it almost to the end without any separate LCLDMA
3524 * code. (Other than debugging.) That took some planning.
3525 * If we are priming the rx ring, we have a main-memory
3526 * mbuf cluster that we really can't use. Otherwise, we
3527 * recycle them efficiently.
3529 if ((ms
->m_flags
& M_EXT
) == 0) { /* not one of ours */
3530 int ring_entry_number
= ri
->ri_nextout
- ri
->ri_first
;
3531 MEXTADD(ms
, sc
->tulip_rx_kva
[ring_entry_number
],
3532 TULIP_RX_BUFLEN
, MT_DATA
, donothing
, 0);
3535 if (ms
->m_next
!= NULL
)
3536 panic("tulip lcldma rx unexpected chain");
3537 if (ri
->ri_nextout
->d_addr1
3538 != a12map(TULIP_KVATOPHYS(sc
, mtod(ms
, void *))))
3539 panic("tulip LCLDMA rx d_addr1");
3543 BEGIN(ri
->ri_nextout
);
3544 t
.d_length1
= TULIP_RX_BUFLEN
;
3545 t
.d_addr1
= a12map(TULIP_KVATOPHYS(sc
, mtod(ms
, void *)));
3546 END(ri
->ri_nextout
);
3547 setstatus(ri
->ri_nextout
,TULIP_DSTS_OWNER
);
3548 if (++ri
->ri_nextout
== ri
->ri_last
)
3549 ri
->ri_nextout
= ri
->ri_first
;
3552 IF_ENQUEUE(&sc
->tulip_rxq
, ms
);
3553 } while ((ms
= me
) != NULL
);
3555 if (sc
->tulip_rxq
.ifq_len
>= TULIP_RXQ_TARGET
)
3556 sc
->tulip_flags
&= ~TULIP_RXBUFSLOW
;
3559 #if defined(TULIP_DEBUG)
3560 sc
->tulip_dbg
.dbg_rxintrs
++;
3561 sc
->tulip_dbg
.dbg_rxpktsperintr
[cnt
]++;
3567 tulip_softc_t
* const sc
)
3569 tulip_ringinfo_t
* const ri
= &sc
->tulip_txinfo
;
3574 while (ri
->ri_free
< ri
->ri_max
) {
3575 if (((volatile tulip_desc_t
*) ri
->ri_nextin
)->d_status
& TULIP_DSTS_OWNER
)
3578 f
= ri
->ri_nextin
->d_flag
; /* potentially non-cached RAM */
3579 if (f
& TULIP_DFLAG_TxLASTSEG
) {
3580 if (f
& TULIP_DFLAG_TxSETUPPKT
) {
3582 * We've just finished processing a setup packet.
3583 * Mark that we finished it. If there's not
3584 * another pending, startup the TULIP receiver.
3585 * Make sure we ack the RXSTOPPED so we won't get
3586 * an abormal interrupt indication.
3588 sc
->tulip_flags
&= ~TULIP_DOINGSETUP
;
3589 if ((sc
->tulip_flags
& (TULIP_WANTSETUP
|TULIP_TXPROBE_ACTIVE
)) == 0) {
3591 sc
->tulip_cmdmode
|= TULIP_CMD_RXRUN
;
3592 sc
->tulip_intrmask
|= TULIP_STS_RXSTOPPED
;
3593 TULIP_CSR_WRITE(sc
, csr_status
, TULIP_STS_RXSTOPPED
);
3594 TULIP_CSR_WRITE(sc
, csr_intr
, sc
->tulip_intrmask
);
3595 TULIP_CSR_WRITE(sc
, csr_command
, sc
->tulip_cmdmode
);
3598 tulip_desc_t
* const nextin
= ri
->ri_nextin
;
3599 IF_DEQUEUE(&sc
->tulip_txq
, m
);
3601 if (sc
->tulip_flags
& TULIP_TXPROBE_ACTIVE
) {
3602 tulip_mediapoll_event_t event
= TULIP_MEDIAPOLL_TXPROBE_OK
;
3603 if (nextin
->d_status
& (TULIP_DSTS_TxNOCARR
|TULIP_DSTS_TxEXCCOLL
)) {
3604 #if defined(TULIP_DEBUG)
3605 if (nextin
->d_status
& TULIP_DSTS_TxNOCARR
)
3606 sc
->tulip_dbg
.dbg_txprobe_nocarr
++;
3607 if (nextin
->d_status
& TULIP_DSTS_TxEXCCOLL
)
3608 sc
->tulip_dbg
.dbg_txprobe_exccoll
++;
3610 event
= TULIP_MEDIAPOLL_TXPROBE_FAILED
;
3612 (*sc
->tulip_boardsw
->bd_media_poll
)(sc
, event
);
3614 * Escape from the loop before media poll has reset the TULIP!
3619 if (nextin
->d_status
& TULIP_DSTS_ERRSUM
) {
3620 sc
->tulip_if
.if_oerrors
++;
3621 if (nextin
->d_status
& TULIP_DSTS_TxEXCCOLL
)
3622 sc
->tulip_dot3stats
.dot3StatsExcessiveCollisions
++;
3623 if (nextin
->d_status
& TULIP_DSTS_TxLATECOLL
)
3624 sc
->tulip_dot3stats
.dot3StatsLateCollisions
++;
3625 if (nextin
->d_status
& (TULIP_DSTS_TxNOCARR
|TULIP_DSTS_TxCARRLOSS
))
3626 sc
->tulip_dot3stats
.dot3StatsCarrierSenseErrors
++;
3627 if (nextin
->d_status
& (TULIP_DSTS_TxUNDERFLOW
|TULIP_DSTS_TxBABBLE
))
3628 sc
->tulip_dot3stats
.dot3StatsInternalMacTransmitErrors
++;
3630 u_int32_t collisions
=
3631 (nextin
->d_status
& TULIP_DSTS_TxCOLLMASK
)
3632 >> TULIP_DSTS_V_TxCOLLCNT
;
3633 sc
->tulip_if
.if_collisions
+= collisions
;
3634 if (collisions
== 1)
3635 sc
->tulip_dot3stats
.dot3StatsSingleCollisionFrames
++;
3636 else if (collisions
> 1)
3637 sc
->tulip_dot3stats
.dot3StatsMultipleCollisionFrames
++;
3638 else if (nextin
->d_status
& TULIP_DSTS_TxDEFERRED
)
3639 sc
->tulip_dot3stats
.dot3StatsDeferredTransmissions
++;
3641 * SQE is only valid for 10baseT/BNC/AUI when not
3642 * running in full-duplex. In order to speed up the
3643 * test, the corresponding bit in tulip_flags needs to
3644 * set as well to get us to count SQE Test Errors.
3646 if (nextin
->d_status
& TULIP_DSTS_TxNOHRTBT
& sc
->tulip_flags
)
3647 sc
->tulip_dot3stats
.dot3StatsSQETestErrors
++;
3653 if (++ri
->ri_nextin
== ri
->ri_last
)
3654 ri
->ri_nextin
= ri
->ri_first
;
3657 if ((sc
->tulip_flags
& TULIP_TXPROBE_ACTIVE
) == 0)
3658 sc
->tulip_if
.if_flags
&= ~IFF_OACTIVE
;
3661 * If nothing left to transmit, disable the timer.
3662 * Else if progress, reset the timer back to 2 ticks.
3664 if (ri
->ri_free
== ri
->ri_max
|| (sc
->tulip_flags
& TULIP_TXPROBE_ACTIVE
))
3665 sc
->tulip_txtimer
= 0;
3667 sc
->tulip_txtimer
= TULIP_TXTIMER
;
3668 sc
->tulip_if
.if_opackets
+= xmits
;
3673 tulip_print_abnormal_interrupt(
3674 tulip_softc_t
* const sc
,
3677 const char * const *msgp
= tulip_status_bits
;
3680 csr
&= (1 << (sizeof(tulip_status_bits
)/sizeof(tulip_status_bits
[0]))) - 1;
3681 printf(TULIP_PRINTF_FMT
": abnormal interrupt:", TULIP_PRINTF_ARGS
);
3682 for (sep
= " "; csr
!= 0; csr
>>= 1, msgp
++) {
3683 if ((csr
& 1) && *msgp
!= NULL
) {
3684 printf("%s%s", sep
, *msgp
);
3693 tulip_softc_t
* const sc
,
3698 while ((csr
= TULIP_CSR_READ(sc
, csr_status
)) & sc
->tulip_intrmask
) {
3700 TULIP_CSR_WRITE(sc
, csr_status
, csr
);
3702 if (csr
& TULIP_STS_SYSERROR
) {
3703 sc
->tulip_last_system_error
= (csr
& TULIP_STS_ERRORMASK
) >> TULIP_STS_ERR_SHIFT
;
3704 if (sc
->tulip_flags
& TULIP_NOMESSAGES
) {
3705 sc
->tulip_flags
|= TULIP_SYSTEMERROR
;
3707 printf(TULIP_PRINTF_FMT
": system error: %s\n",
3709 tulip_system_errors
[sc
->tulip_last_system_error
]);
3711 sc
->tulip_flags
|= TULIP_NEEDRESET
;
3712 sc
->tulip_system_errors
++;
3715 if (csr
& (TULIP_STS_LINKPASS
|TULIP_STS_LINKFAIL
)) {
3716 #if defined(TULIP_DEBUG)
3717 sc
->tulip_dbg
.dbg_link_intrs
++;
3719 if (sc
->tulip_boardsw
->bd_media_poll
!= NULL
) {
3720 (*sc
->tulip_boardsw
->bd_media_poll
)(sc
, csr
& TULIP_STS_LINKFAIL
3721 ? TULIP_MEDIAPOLL_LINKFAIL
3722 : TULIP_MEDIAPOLL_LINKPASS
);
3723 csr
&= ~TULIP_STS_ABNRMLINTR
;
3725 tulip_media_print(sc
);
3727 if (csr
& (TULIP_STS_RXINTR
|TULIP_STS_RXNOBUF
)) {
3728 u_int32_t misses
= TULIP_CSR_READ(sc
, csr_missed_frames
);
3729 if (csr
& TULIP_STS_RXNOBUF
)
3730 sc
->tulip_dot3stats
.dot3StatsMissedFrames
+= misses
& 0xFFFF;
3732 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3733 * on receive overflows.
3735 if ((misses
& 0x0FFE0000) && (sc
->tulip_features
& TULIP_HAVE_RXBUGGY
)) {
3737 * Stop the receiver process and spin until it's stopped.
3738 * Tell rx_intr to drop the packets it dequeues.
3740 TULIP_CSR_WRITE(sc
, csr_command
, sc
->tulip_cmdmode
& ~TULIP_CMD_RXRUN
);
3741 while ((TULIP_CSR_READ(sc
, csr_status
) & TULIP_STS_RXSTOPPED
) == 0)
3743 TULIP_CSR_WRITE(sc
, csr_status
, TULIP_STS_RXSTOPPED
);
3744 sc
->tulip_flags
|= TULIP_RXBAD
;
3747 if (sc
->tulip_flags
& TULIP_RXBAD
) {
3749 * Restart the receiver.
3751 sc
->tulip_flags
&= ~TULIP_RXBAD
;
3752 TULIP_CSR_WRITE(sc
, csr_command
, sc
->tulip_cmdmode
);
3755 if (csr
& TULIP_STS_ABNRMLINTR
) {
3756 u_int32_t tmp
= csr
& sc
->tulip_intrmask
3757 & ~(TULIP_STS_NORMALINTR
|TULIP_STS_ABNRMLINTR
);
3758 if (sc
->tulip_flags
& TULIP_NOMESSAGES
) {
3759 sc
->tulip_statusbits
|= tmp
;
3761 tulip_print_abnormal_interrupt(sc
, tmp
);
3762 sc
->tulip_flags
|= TULIP_NOMESSAGES
;
3764 TULIP_CSR_WRITE(sc
, csr_command
, sc
->tulip_cmdmode
);
3766 if (sc
->tulip_txinfo
.ri_free
< sc
->tulip_txinfo
.ri_max
) {
3768 if ((sc
->tulip_flags
& TULIP_TXPROBE_ACTIVE
) == 0)
3769 tulip_ifstart(&sc
->tulip_if
);
3772 if (sc
->tulip_flags
& TULIP_NEEDRESET
) {
3778 #if defined(TULIP_USE_SOFTINTR)
3780 * This is a experimental idea to alleviate problems due to interrupt
3781 * livelock. What is interrupt livelock? It's when you spend all your
3782 * time servicing device interrupts and never drop below device ipl
3783 * to do "useful" work.
3785 * So what we do here is see if the device needs service and if so,
3786 * disable interrupts (dismiss the interrupt), place it in a list of devices
3787 * needing service, and issue a network software interrupt.
3789 * When our network software interrupt routine gets called, we simply
3790 * walk done the list of devices that we have created and deal with them
3791 * at splnet/splsoftnet.
3795 tulip_hardintr_handler(
3796 tulip_softc_t
* const sc
,
3799 if (TULIP_CSR_READ(sc
, csr_status
) & (TULIP_STS_NORMALINTR
|TULIP_STS_ABNRMLINTR
) == 0)
3803 * disable interrupts
3805 TULIP_CSR_WRITE(sc
, csr_intr
, 0);
3807 * mark it as needing a software interrupt
3809 tulip_softintr_mask
|= (1U << sc
->tulip_unit
);
3816 u_int32_t softintr_mask
, mask
;
3822 * Copy mask to local copy and reset global one to 0.
3824 s
= TULIP_RAISESPL();
3825 softintr_mask
= tulip_softintr_mask
;
3826 tulip_softintr_mask
= 0;
3827 TULIP_RESTORESPL(s
);
3830 * Optimize for the single unit case.
3832 if (tulip_softintr_max_unit
== 0) {
3833 if (softintr_mask
& 1) {
3834 tulip_softc_t
* const sc
= TULIP_UNIT_TO_SOFTC(0);
3836 * Handle the "interrupt" and then reenable interrupts
3839 tulip_intr_handler(sc
, &progress
);
3840 TULIP_CSR_WRITE(sc
, csr_intr
, sc
->tulip_intrmask
);
3846 * Handle all "queued" interrupts in a round robin fashion.
3847 * This is done so as not to favor a particular interface.
3849 unit
= tulip_softintr_last_unit
;
3850 mask
= (1U << unit
);
3851 while (softintr_mask
!= 0) {
3852 if (tulip_softintr_max_unit
== unit
) {
3855 unit
+= 1; mask
<<= 1;
3857 if (softintr_mask
& mask
) {
3858 tulip_softc_t
* const sc
= TULIP_UNIT_TO_SOFTC(unit
);
3860 * Handle the "interrupt" and then reenable interrupts
3862 softintr_mask
^= mask
;
3863 tulip_intr_handler(sc
, &progress
);
3864 TULIP_CSR_WRITE(sc
, csr_intr
, sc
->tulip_intrmask
);
3869 * Save where we ending up.
3871 tulip_softintr_last_unit
= unit
;
3873 #endif /* TULIP_USE_SOFTINTR */
3875 static tulip_intrfunc_t
3882 for (sc
= (tulip_softc_t
*) arg
; sc
!= NULL
; sc
= sc
->tulip_slaves
) {
3883 #if defined(TULIP_DEBUG)
3884 sc
->tulip_dbg
.dbg_intrs
++;
3886 #if defined(TULIP_USE_SOFTINTR)
3887 tulip_hardintr_handler(sc
, &progress
);
3889 tulip_intr_handler(sc
, &progress
);
3892 #if defined(TULIP_USE_SOFTINTR)
3894 schednetisr(NETISR_DE
);
3896 #if !defined(TULIP_VOID_INTRFUNC)
3901 static tulip_intrfunc_t
3905 tulip_softc_t
* sc
= (tulip_softc_t
*) arg
;
3908 #if defined(TULIP_DEBUG)
3909 sc
->tulip_dbg
.dbg_intrs
++;
3911 #if defined(TULIP_USE_SOFTINTR)
3912 tulip_hardintr_handler(sc
, &progress
);
3914 schednetisr(NETISR_DE
);
3916 tulip_intr_handler(sc
, &progress
);
3918 #if !defined(TULIP_VOID_INTRFUNC)
3924 * This routine is entered at splnet() (splsoftnet() on NetBSD)
3925 * and thereby imposes no problems when TULIP_USE_SOFTINTR is
3930 struct ifnet
* const ifp
,
3934 tulip_softc_t
* const sc
= TULIP_IFP_TO_SOFTC(ifp
);
3935 struct ifaddr
*ifa
= (struct ifaddr
*)data
;
3936 struct ifreq
*ifr
= (struct ifreq
*) data
;
3940 #if defined(TULIP_USE_SOFTINTR)
3941 s
= TULIP_RAISESOFTSPL();
3943 s
= TULIP_RAISESPL();
3946 case SIOCINITIFADDR
: {
3947 ifp
->if_flags
|= IFF_UP
;
3948 switch(ifa
->ifa_addr
->sa_family
) {
3952 TULIP_ARP_IFINIT(sc
, ifa
);
3959 * This magic copied from if_is.c; I don't use XNS,
3960 * so I have no way of telling if this actually
3964 struct ns_addr
*ina
= &(IA_SNS(ifa
)->sns_addr
);
3965 if (ns_nullhost(*ina
)) {
3966 ina
->x_host
= *(union ns_host
*)(sc
->tulip_enaddr
);
3968 ifp
->if_flags
&= ~IFF_RUNNING
;
3969 memcpy((void *)sc
->tulip_enaddr
,
3970 (void *)ina
->x_host
.c_host
,
3971 sizeof(sc
->tulip_enaddr
));
3985 case SIOCSIFFLAGS
: {
3986 if ((error
= ifioctl_common(ifp
, cmd
, data
)) != 0)
3992 #if defined(SIOCSIFMEDIA)
3994 case SIOCGIFMEDIA
: {
3995 error
= ifmedia_ioctl(ifp
, ifr
, &sc
->tulip_ifmedia
, cmd
);
4001 case SIOCDELMULTI
: {
4003 * Update multicast listeners
4005 if ((error
= ether_ioctl(ifp
, cmd
, data
)) == ENETRESET
) {
4006 if (ifp
->if_flags
& IFF_RUNNING
) {
4007 tulip_addr_filter(sc
); /* reset multicast filtering */
4014 #if defined(SIOCSIFMTU)
4015 #if !defined(ifr_mtu)
4016 #define ifr_mtu ifr_metric
4020 * Set the interface MTU.
4022 if (ifr
->ifr_mtu
> ETHERMTU
4024 && sc
->tulip_chipid
!= TULIP_21140
4025 && sc
->tulip_chipid
!= TULIP_21140A
4026 && sc
->tulip_chipid
!= TULIP_21041
4032 if ((error
= ifioctl_common(ifp
, cmd
, data
)) == ENETRESET
) {
4040 #endif /* SIOCSIFMTU */
4043 case SIOCGADDRROM
: {
4044 error
= copyout(sc
->tulip_rombuf
, ifr
->ifr_data
, sizeof(sc
->tulip_rombuf
));
4050 ifr
->ifr_metric
= (int) sc
->tulip_chipid
;
4055 error
= ether_ioctl(ifp
, cmd
, data
);
4060 TULIP_RESTORESPL(s
);
4064 static void htnote(char * );
4065 static void htnote(char *s
) {
4067 hrh_check_status(s
);
4072 * This routine gets called at device spl (from ether_output). This might
4073 * pose a problem for TULIP_USE_SOFTINTR if ether_output is called at
4074 * device spl from another driver.
4078 struct ifnet
* const ifp
)
4080 tulip_softc_t
* const sc
= TULIP_IFP_TO_SOFTC(ifp
);
4081 struct ifqueue
* const ifq
= &ifp
->if_snd
;
4082 tulip_ringinfo_t
* const ri
= &sc
->tulip_txinfo
;
4083 struct mbuf
*m
, *m0
, *next_m0
;
4085 if ((ifp
->if_flags
& IFF_RUNNING
) == 0
4086 && (sc
->tulip_flags
& TULIP_TXPROBE_ACTIVE
) == 0)
4090 tulip_desc_t
*eop
, *nextout
;
4091 int segcnt
, free
, recopy
;
4094 if ((sc
->tulip_flags
& (TULIP_WANTSETUP
|TULIP_TXPROBE_ACTIVE
)) == TULIP_WANTSETUP
) {
4095 #if defined(TULIP_DEBUG)
4096 if ((sc
->tulip_cmdmode
& TULIP_CMD_TXRUN
) == 0) {
4097 printf(TULIP_PRINTF_FMT
": ifstart: tx not running\n",
4099 ifp
->if_flags
|= IFF_OACTIVE
;
4103 if ((sc
->tulip_flags
& TULIP_DOINGSETUP
) || ri
->ri_free
== 1) {
4104 ifp
->if_flags
|= IFF_OACTIVE
;
4107 memcpy(sc
->tulip_setupbuf
, sc
->tulip_setupdata
,
4108 sizeof(sc
->tulip_setupdata
));
4109 sc
->tulip_flags
&= ~TULIP_WANTSETUP
;
4110 sc
->tulip_flags
|= TULIP_DOINGSETUP
;
4112 nextout
= ri
->ri_nextout
;
4114 t
.d_flag
&= TULIP_DFLAG_ENDRING
|TULIP_DFLAG_CHAIN
;
4115 t
.d_flag
|= TULIP_DFLAG_TxFIRSTSEG
|TULIP_DFLAG_TxLASTSEG
4116 |TULIP_DFLAG_TxSETUPPKT
|TULIP_DFLAG_TxWANTINTR
;
4117 if (sc
->tulip_flags
& TULIP_WANTHASH
)
4118 t
.d_flag
|= TULIP_DFLAG_TxHASHFILT
;
4119 t
.d_length1
= sizeof(sc
->tulip_setupdata
);
4121 a12r2pb(sc
->tulip_setupbuf
,
4122 sc
->tulip_tx_kva
[nextout
-ri
->ri_first
],
4123 sizeof(sc
->tulip_setupbuf
));
4124 if (a12map(TULIP_KVATOPHYS(
4125 sc
, sc
->tulip_tx_kva
[nextout
-ri
->ri_first
]))
4126 != nextout
->d_addr1
)
4127 panic("tulip tx 1");
4129 t
.d_addr1
= TULIP_KVATOPHYS(sc
, sc
->tulip_setupbuf
);
4135 * Advance the ring for the next transmit packet.
4137 if (++ri
->ri_nextout
== ri
->ri_last
)
4138 ri
->ri_nextout
= ri
->ri_first
;
4140 * Make sure the next descriptor is owned by us since it
4141 * may have been set up above if we ran out of room in the
4144 setstatus(ri
->ri_nextout
,0);
4145 setstatus(nextout
, TULIP_DSTS_OWNER
);
4146 TULIP_CSR_WRITE(sc
, csr_txpoll
, 1);
4153 #if defined(TULIP_DEBUG)
4154 if ((sc
->tulip_cmdmode
& TULIP_CMD_TXRUN
) == 0) {
4155 printf(TULIP_PRINTF_FMT
": ifstart%s: tx not running\n",
4157 (sc
->tulip_flags
& TULIP_TXPROBE_ACTIVE
) ? "(probe)" : "");
4158 ifp
->if_flags
|= IFF_OACTIVE
;
4165 * Now we try to fill in our transmit descriptors. This is
4166 * a bit reminiscent of going on the Ark two by two
4167 * since each descriptor for the TULIP can describe
4168 * two buffers. So we advance through packet filling
4169 * each of the two entries at a time to to fill each
4170 * descriptor. Clear the first and last segment bits
4171 * in each descriptor (actually just clear everything
4172 * but the end-of-ring or chain bits) to make sure
4173 * we don't get messed up by previously sent packets.
4175 * We may fail to put the entire packet on the ring if
4176 * there is either not enough ring entries free or if the
4177 * packet has more than MAX_TXSEG segments. In the former
4178 * case we will just wait for the ring to empty. In the
4179 * latter case we have to recopy.
4183 eop
= nextout
= ri
->ri_nextout
;
4187 /* Create a chain of descriptors tracking the chain of mbufs */
4189 int len
= m0
->m_len
;
4190 void *addr
= mtod(m0
, void *);
4191 unsigned clsize
= PAGE_SIZE
- (((u_long
) addr
) & PGOFSET
);
4193 next_m0
= m0
->m_next
;
4195 unsigned slen
= min(len
, clsize
);
4199 slen
= 2040, partial
= 1;
4202 if (segcnt
> TULIP_MAX_TXSEG
) {
4204 next_m0
= NULL
; /* to break out of outside loop */
4210 * There's no more room but since nothing
4211 * has been committed at this point, just
4212 * show output is active, put back the
4215 ifp
->if_flags
|= IFF_OACTIVE
;
4220 if (++nextout
== ri
->ri_last
)
4221 nextout
= ri
->ri_first
;
4223 t
.d_flag
&= TULIP_DFLAG_ENDRING
|TULIP_DFLAG_CHAIN
;
4224 t
.d_status
= d_status
;
4226 slen
= m
->m_pkthdr
.len
;
4227 if (slen
> TULIP_TX_BUFLEN
)
4228 panic("tulip lcldma tx 2");
4229 a12_m_copydata(m
,0,slen
,
4230 sc
->tulip_tx_kva
[eop
- ri
->ri_first
]);
4231 #if defined(TULIP_DEBUG)
4232 if (sc
->tulip_tx_kva
[eop
- ri
->ri_first
]
4233 != a12map(TULIP_KVATOPHYS(sc
,eop
->d_addr1
)))
4234 panic("tulip lcldma tx 3");
4239 t
.d_addr1
= TULIP_KVATOPHYS(sc
, addr
);
4245 * Fill in second half of descriptor
4247 if(cputype
==ST_AVALON_A12
)
4248 panic("tulip lcldma tx 3.5");
4249 eop
->d_addr2
= TULIP_KVATOPHYS(sc
, addr
);
4250 eop
->d_length2
= slen
;
4252 d_status
= TULIP_DSTS_OWNER
;
4261 } while ((m0
= next_m0
) != NULL
);
4264 * The packet exceeds the number of transmit buffer
4265 * entries that we can use for one packet, so we have
4266 * recopy it into one mbuf and then try again.
4269 MGETHDR(m0
, M_DONTWAIT
, MT_DATA
);
4271 if (m
->m_pkthdr
.len
> MHLEN
) {
4272 MCLGET(m0
, M_DONTWAIT
);
4273 if ((m0
->m_flags
& M_EXT
) == 0) {
4279 m_copydata(m
, 0, m
->m_pkthdr
.len
, mtod(m0
, void *));
4280 m0
->m_pkthdr
.len
= m0
->m_len
= m
->m_pkthdr
.len
;
4281 IF_PREPEND(ifq
, m0
);
4288 * The descriptors have been filled in. Now get ready
4292 if (sc
->tulip_bpf
!= NULL
)
4293 TULIP_BPF_MTAP(sc
, m
);
4295 IF_ENQUEUE(&sc
->tulip_txq
, m
);
4298 * Make sure the next descriptor after this packet is owned
4299 * by us since it may have been set up above if we ran out
4300 * of room in the ring.
4303 setstatus(nextout
,0);
4306 * If we only used the first segment of the last descriptor,
4307 * make sure the second segment will not be used.
4316 * Mark the last and first segments, indicate we want a transmit
4317 * complete interrupt, give the descriptors to the TULIP, and tell
4320 t
.d_flag
|= TULIP_DFLAG_TxLASTSEG
|TULIP_DFLAG_TxWANTINTR
;
4324 * Note that ri->ri_nextout is still the start of the packet
4325 * and until we set the OWNER bit, we can still back out of
4326 * everything we have done.
4328 BEGIN(ri
->ri_nextout
);
4329 t
.d_flag
|= TULIP_DFLAG_TxFIRSTSEG
;
4330 t
.d_status
= TULIP_DSTS_OWNER
;
4331 END(ri
->ri_nextout
);
4334 * This advances the ring for us.
4336 ri
->ri_nextout
= nextout
;
4339 TULIP_CSR_WRITE(sc
, csr_txpoll
, 1);
4341 if (sc
->tulip_flags
& TULIP_TXPROBE_ACTIVE
) {
4342 ifp
->if_flags
|= IFF_OACTIVE
;
4345 if (sc
->tulip_txtimer
== 0)
4346 sc
->tulip_txtimer
= TULIP_TXTIMER
;
4349 ifp
->if_flags
|= IFF_OACTIVE
;
4355 * Even though this routine runs at device spl, it does not break
4356 * our use of splnet (splsoftnet under NetBSD) for the majority
4357 * of this driver (if TULIP_USE_SOFTINTR defined) since
4358 * if_watcbog is called from if_watchdog which is called from
4359 * splsoftclock which is below spl[soft]net.
4365 tulip_softc_t
* const sc
= TULIP_IFP_TO_SOFTC(ifp
);
4367 #if defined(TULIP_DEBUG)
4368 u_int32_t rxintrs
= sc
->tulip_dbg
.dbg_rxintrs
- sc
->tulip_dbg
.dbg_last_rxintrs
;
4369 if (rxintrs
> sc
->tulip_dbg
.dbg_high_rxintrs_hz
)
4370 sc
->tulip_dbg
.dbg_high_rxintrs_hz
= rxintrs
;
4371 sc
->tulip_dbg
.dbg_last_rxintrs
= sc
->tulip_dbg
.dbg_rxintrs
;
4372 #endif /* TULIP_DEBUG */
4374 sc
->tulip_if
.if_timer
= 1;
4376 * These should be rare so do a bulk test up front so we can just skip
4379 if (sc
->tulip_flags
& (TULIP_SYSTEMERROR
|TULIP_RXBUFSLOW
|TULIP_NOMESSAGES
)) {
4381 * If the number of receive buffer is low, try to refill
4383 if (sc
->tulip_flags
& TULIP_RXBUFSLOW
)
4386 if (sc
->tulip_flags
& TULIP_SYSTEMERROR
) {
4387 printf(TULIP_PRINTF_FMT
": %d system errors: last was %s\n",
4388 TULIP_PRINTF_ARGS
, sc
->tulip_system_errors
,
4389 tulip_system_errors
[sc
->tulip_last_system_error
]);
4391 if (sc
->tulip_statusbits
) {
4392 tulip_print_abnormal_interrupt(sc
, sc
->tulip_statusbits
);
4393 sc
->tulip_statusbits
= 0;
4396 sc
->tulip_flags
&= ~(TULIP_NOMESSAGES
|TULIP_SYSTEMERROR
);
4399 if (sc
->tulip_txtimer
&& --sc
->tulip_txtimer
== 0) {
4400 printf(TULIP_PRINTF_FMT
": transmission timeout\n", TULIP_PRINTF_ARGS
);
4401 if (TULIP_DO_AUTOSENSE(sc
)) {
4402 sc
->tulip_media
= TULIP_MEDIA_UNKNOWN
;
4403 sc
->tulip_probe_state
= TULIP_PROBE_INACTIVE
;
4404 sc
->tulip_flags
&= ~(TULIP_WANTRXACT
|TULIP_LINKUP
);
4410 #if defined(__bsdi__) || (defined(__FreeBSD__) && BSD < 199506)
4412 tulip_ifwatchdog_wrapper(
4415 tulip_ifwatchdog(&TULIP_UNIT_TO_SOFTC(unit
)->tulip_if
);
4417 #define tulip_ifwatchdog tulip_ifwatchdog_wrapper
4421 * All printf's are real as of now!
4426 #if !defined(IFF_NOTRAILERS)
4427 #define IFF_NOTRAILERS 0
4432 tulip_softc_t
* const sc
)
4434 struct ifnet
* const ifp
= &sc
->tulip_if
;
4436 ifp
->if_flags
= IFF_BROADCAST
|IFF_SIMPLEX
|IFF_NOTRAILERS
|IFF_MULTICAST
;
4437 ifp
->if_ioctl
= tulip_ifioctl
;
4438 ifp
->if_start
= tulip_ifstart
;
4439 ifp
->if_watchdog
= tulip_ifwatchdog
;
4441 #if (!defined(__bsdi__) || _BSDI_VERSION < 199401) && !defined(__NetBSD__)
4442 ifp
->if_output
= ether_output
;
4444 #if defined(__bsdi__) && _BSDI_VERSION < 199401
4445 ifp
->if_mtu
= ETHERMTU
;
4448 #if defined(__bsdi__) && _BSDI_VERSION >= 199510
4449 aprint_naive(": DEC Ethernet");
4450 aprint_normal(": %s%s", sc
->tulip_boardid
,
4451 tulip_chipdescs
[sc
->tulip_chipid
]);
4452 aprint_verbose(" pass %d.%d", (sc
->tulip_revinfo
& 0xF0) >> 4,
4453 sc
->tulip_revinfo
& 0x0F);
4455 sc
->tulip_pf
= aprint_normal
;
4456 aprint_normal(TULIP_PRINTF_FMT
": address " TULIP_EADDR_FMT
"\n",
4458 TULIP_EADDR_ARGS(sc
->tulip_enaddr
));
4461 #if defined(__bsdi__)
4464 TULIP_PRINTF_FMT
": %s%s pass %d.%d\n",
4467 tulip_chipdescs
[sc
->tulip_chipid
],
4468 (sc
->tulip_revinfo
& 0xF0) >> 4,
4469 sc
->tulip_revinfo
& 0x0F);
4470 printf(TULIP_PRINTF_FMT
": address " TULIP_EADDR_FMT
"\n",
4472 TULIP_EADDR_ARGS(sc
->tulip_enaddr
));
4475 #if defined(__alpha__)
4477 * In case the SRM console told us about a bogus media,
4478 * we need to check to be safe.
4480 if (sc
->tulip_mediums
[sc
->tulip_media
] == NULL
) {
4481 sc
->tulip_media
= TULIP_MEDIA_UNKNOWN
;
4485 ifmedia_init(&sc
->tulip_ifmedia
, 0,
4486 tulip_ifmedia_change
,
4487 tulip_ifmedia_status
);
4488 (*sc
->tulip_boardsw
->bd_media_probe
)(sc
);
4489 sc
->tulip_flags
&= ~TULIP_DEVICEPROBE
;
4490 tulip_ifmedia_add(sc
);
4494 #if defined(__bsdi__) && _BSDI_VERSION >= 199510
4495 sc
->tulip_pf
= printf
;
4496 TULIP_ETHER_IFATTACH(sc
);
4499 #if defined(__NetBSD__) || (defined(__FreeBSD__) && BSD >= 199506)
4500 TULIP_ETHER_IFATTACH(sc
);
4502 #endif /* __bsdi__ */
4507 tulip_softc_t
* const sc
,
4508 tulip_csrptr_t csr_base
,
4511 sc
->tulip_csrs
.csr_busmode
= csr_base
+ 0 * csr_size
;
4512 sc
->tulip_csrs
.csr_txpoll
= csr_base
+ 1 * csr_size
;
4513 sc
->tulip_csrs
.csr_rxpoll
= csr_base
+ 2 * csr_size
;
4514 sc
->tulip_csrs
.csr_rxlist
= csr_base
+ 3 * csr_size
;
4515 sc
->tulip_csrs
.csr_txlist
= csr_base
+ 4 * csr_size
;
4516 sc
->tulip_csrs
.csr_status
= csr_base
+ 5 * csr_size
;
4517 sc
->tulip_csrs
.csr_command
= csr_base
+ 6 * csr_size
;
4518 sc
->tulip_csrs
.csr_intr
= csr_base
+ 7 * csr_size
;
4519 sc
->tulip_csrs
.csr_missed_frames
= csr_base
+ 8 * csr_size
;
4520 sc
->tulip_csrs
.csr_9
= csr_base
+ 9 * csr_size
;
4521 sc
->tulip_csrs
.csr_10
= csr_base
+ 10 * csr_size
;
4522 sc
->tulip_csrs
.csr_11
= csr_base
+ 11 * csr_size
;
4523 sc
->tulip_csrs
.csr_12
= csr_base
+ 12 * csr_size
;
4524 sc
->tulip_csrs
.csr_13
= csr_base
+ 13 * csr_size
;
4525 sc
->tulip_csrs
.csr_14
= csr_base
+ 14 * csr_size
;
4526 sc
->tulip_csrs
.csr_15
= csr_base
+ 15 * csr_size
;
4527 #if defined(TULIP_EISA)
4528 sc
->tulip_csrs
.csr_enetrom
= csr_base
+ DE425_ENETROM_OFFSET
;
4532 /* XXX. In the long run, these don't belong here in a driver */
4534 void *lcl_dma_ram_next(int);
4535 void lcl_dma_restart(void);
4537 void lcl_dma_restart(void) {
4538 /* lcl_dma_ram_next(-1); */
4541 #include <alpha/pci/a12creg.h>
4543 static void * LCLDMAstart
= (void *)ALPHA_PHYS_TO_K0SEG(A12_PCIBuffer
);
4544 static int lclpcisize
= 128*1024;
4547 lcl_dma_ram_next(int size
)
4552 if (first
==0L /* || size==-1 */) {
4553 first
= LCLDMAstart
;
4557 if (first
> LCLDMAstart
+ lclpcisize
) {
4559 printf("first=%p LCLDMAstart=%p lclpcisize=%p\n",
4560 first
, LCLDMAstart
, lclpcisize
);
4562 panic("tulip lcldma next");
4567 static char *lcl_dma_retrace
;
4569 void lcl_dma_start_check(void);
4571 lcl_dma_start_check(void)
4573 lcl_dma_retrace
= LCLDMAstart
;
4576 void *lcl_dma_ram_next_check(int);
4578 lcl_dma_ram_next_check(int size
)
4580 void *t
= lcl_dma_retrace
;
4581 lcl_dma_retrace
+= size
;
4586 * For LCLDMA, we need to use local memory for both the descriptors
4587 * and for the buffers, and we need to easily be able to recall the
4591 tulip_softc_t
*debug_sc
;
4593 static void a12pbs(tulip_softc_t
* const sc
, u_int32_t
*base
, void *kva
) {
4596 p
= a12map(TULIP_KVATOPHYS(sc
,kva
));
4597 a12r2pb(&p
, base
, sizeof(p
));
4603 tulip_softc_t
* const sc
,
4604 tulip_ringinfo_t
* const ri
,
4605 tulip_desc_t
*descs
,
4609 int i
, dsize
= sizeof descs
[0] * ndescs
;
4612 ri
->ri_max
= ndescs
;
4613 (void)lcl_dma_ram_next(16); /* superstitiously avoid the origin */
4614 ri
->ri_first
= (tulip_desc_t
*)lcl_dma_ram_next(dsize
);
4615 memset(ri
->ri_first
, 0, dsize
);
4616 for(i
=0; i
<ndescs
; ++i
) {
4617 kvalist
[i
] = lcl_dma_ram_next(TULIP_XX_BUFLEN
);
4618 BEGIN(ri
->ri_first
+i
);
4619 memset(&t
, 0, sizeof(t
));
4620 t
.d_addr1
= a12map(TULIP_KVATOPHYS(sc
,kvalist
[i
]));
4621 END(ri
->ri_first
+i
);
4623 ri
->ri_last
= ri
->ri_first
+ ri
->ri_max
;
4624 BEGIN(ri
->ri_last
-1);
4625 t
.d_flag
= TULIP_DFLAG_ENDRING
;
4630 static void dumpring(void **kvalist
) {
4632 long *d
= (long *)0xfffffc8020000000L
;
4636 printf("kvalist[%d] = %16lx\n", k
, kvalist
[k
]);
4638 printf("%03x: %16lx %16lx %16lx %16lx\n",
4649 * This doesn't do anything other than check that the ring hasn't been
4650 * changed since tulip_pci_attach()
4654 tulip_softc_t
* const sc
,
4655 tulip_ringinfo_t
* const ri
,
4656 tulip_desc_t
*descs
,
4665 for(i
=q
=0; i
<ndescs
; ++i
) {
4667 printf("d_flag %d = %x\n", i
-1, t
->d_flag
);
4670 t
= ri
->ri_first
+ i
;
4671 if (t
->d_addr1
!= a12map(TULIP_KVATOPHYS(sc
,kvalist
[i
]))) {
4672 printf("&a1=%lx t->d_addr1=%x a12map(...)=%x\n",
4675 a12map(TULIP_KVATOPHYS(sc
,kvalist
[i
])));
4680 printf("t->d_addr2=%x\n",t
->d_addr2
);
4683 q
= t
->d_flag
& TULIP_DFLAG_ENDRING
;
4687 printf("final d_flag = %x\n", t
->d_flag
);
4688 die
: panic("tulip ring corrupted");
4692 reset_lcl_dma(tulip_softc_t
* const sc
)
4694 tulip_ring_reset(sc
, &sc
->tulip_rxinfo
, sc
->tulip_rxdescs
, sc
->tulip_rx_kva
,
4696 tulip_ring_reset(sc
, &sc
->tulip_txinfo
, sc
->tulip_txdescs
, sc
->tulip_tx_kva
,
4701 tulip_initring( /* the usual case */
4702 tulip_softc_t
* const sc
,
4703 tulip_ringinfo_t
* const ri
,
4704 tulip_desc_t
*descs
,
4708 ri
->ri_max
= ndescs
;
4709 ri
->ri_first
= descs
;
4710 ri
->ri_last
= ri
->ri_first
+ ri
->ri_max
;
4711 memset((void *) ri
->ri_first
, 0, sizeof(ri
->ri_first
[0]) * ri
->ri_max
);
4712 ri
->ri_last
[-1].d_flag
= TULIP_DFLAG_ENDRING
;
4717 * This is the PCI configuration support. Since the 21040 is available
4718 * on both EISA and PCI boards, one must be careful in how defines the
4719 * 21040 in the config file.
4722 #define PCI_CFID 0x00 /* Configuration ID */
4723 #define PCI_CFCS 0x04 /* Configurtion Command/Status */
4724 #define PCI_CFRV 0x08 /* Configuration Revision */
4725 #define PCI_CFLT 0x0c /* Configuration Latency Timer */
4726 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
4727 #define PCI_CBMA 0x14 /* Configuration Base Memory Address */
4728 #define PCI_CFIT 0x3c /* Configuration Interrupt */
4729 #define PCI_CFDA 0x40 /* Configuration Driver Area */
4731 #if defined(TULIP_EISA)
4732 static const int tulip_eisa_irqs
[4] = { IRQ5
, IRQ9
, IRQ10
, IRQ11
};
4735 #if defined(__FreeBSD__)
4737 #define TULIP_PCI_ATTACH_ARGS pcici_t config_id, int unit
4738 #define TULIP_SHUTDOWN_ARGS int howto, void *arg
4740 #if defined(TULIP_DEVCONF)
4741 static void tulip_shutdown(TULIP_SHUTDOWN_ARGS
);
4745 struct kern_devconf
* const kdc
,
4748 if (kdc
->kdc_unit
< TULIP_MAX_DEVICES
) {
4749 tulip_softc_t
* const sc
= TULIP_UNIT_TO_SOFTC(kdc
->kdc_unit
);
4751 tulip_shutdown(0, sc
);
4753 (void) dev_detach(kdc
);
4763 if (cputype
!= ST_AVALON_A12
) /* XXX */
4765 if (PCI_VENDORID(device_id
) != DEC_VENDORID
)
4767 if (PCI_CHIPID(device_id
) == CHIPID_21040
)
4768 return "Digital 21040 Ethernet";
4769 if (PCI_CHIPID(device_id
) == CHIPID_21041
)
4770 return "Digital 21041 Ethernet";
4771 if (PCI_CHIPID(device_id
) == CHIPID_21140
) {
4772 u_int32_t revinfo
= pci_conf_read(config_id
, PCI_CFRV
) & 0xFF;
4773 if (revinfo
>= 0x20)
4774 return "Digital 21140A Fast Ethernet";
4776 return "Digital 21140 Fast Ethernet";
4778 if (PCI_CHIPID(device_id
) == CHIPID_21142
) {
4779 u_int32_t revinfo
= pci_conf_read(config_id
, PCI_CFRV
) & 0xFF;
4780 if (revinfo
>= 0x20)
4781 return "Digital 21143 Fast Ethernet";
4783 return "Digital 21142 Fast Ethernet";
4788 static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS
);
4789 static u_long tulip_pci_count
;
4791 struct pci_device adedevice
= {
4796 #if defined(TULIP_DEVCONF)
4801 DATA_SET (pcidevice_set
, adedevice
);
4802 #endif /* __FreeBSD__ */
4804 #if defined(__bsdi__)
4805 #define TULIP_PCI_ATTACH_ARGS struct device * const parent, struct device * const self, void *const aux
4806 #define TULIP_SHUTDOWN_ARGS void *arg
4815 id
= pci_inl(pa
, PCI_VENDOR_ID
);
4816 if (PCI_VENDORID(id
) != DEC_VENDORID
)
4818 id
= PCI_CHIPID(id
);
4819 if (id
!= CHIPID_21040
&& id
!= CHIPID_21041
4820 && id
!= CHIPID_21140
&& id
!= CHIPID_21142
)
4822 irq
= pci_inl(pa
, PCI_I_LINE
) & 0xFF;
4823 if (irq
== 0 || irq
>= 16) {
4824 printf("ade?: invalid IRQ %d; skipping\n", irq
);
4832 struct device
*parent
,
4836 struct isa_attach_args
* const ia
= (struct isa_attach_args
*) aux
;
4840 #if _BSDI_VERSION >= 199401
4841 switch (ia
->ia_bustype
) {
4844 pa
= pci_scan(tulip_pci_match
);
4848 irq
= (1 << (pci_inl(pa
, PCI_I_LINE
) & 0xFF));
4850 /* Get the base address; assume the BIOS set it up correctly */
4851 #if defined(TULIP_IOMAPPED)
4852 ia
->ia_maddr
= NULL
;
4854 ia
->ia_iobase
= pci_inl(pa
, PCI_CBIO
) & ~7;
4855 pci_outl(pa
, PCI_CBIO
, 0xFFFFFFFF);
4856 ia
->ia_iosize
= ((~pci_inl(pa
, PCI_CBIO
)) | 7) + 1;
4857 pci_outl(pa
, PCI_CBIO
, (int) ia
->ia_iobase
);
4859 /* Disable memory space access */
4860 pci_outl(pa
, PCI_COMMAND
, pci_inl(pa
, PCI_COMMAND
) & ~2);
4862 ia
->ia_maddr
= (void *) (pci_inl(pa
, PCI_CBMA
) & ~7);
4863 pci_outl(pa
, PCI_CBMA
, 0xFFFFFFFF);
4864 ia
->ia_msize
= ((~pci_inl(pa
, PCI_CBMA
)) | 7) + 1;
4865 pci_outl(pa
, PCI_CBMA
, (int) ia
->ia_maddr
);
4869 /* Disable I/O space access */
4870 pci_outl(pa
, PCI_COMMAND
, pci_inl(pa
, PCI_COMMAND
) & ~1);
4871 #endif /* TULIP_IOMAPPED */
4873 ia
->ia_aux
= (void *) pa
;
4874 #if _BSDI_VERSION >= 199401
4877 #if defined(TULIP_EISA)
4881 if ((slot
= eisa_match(cf
, ia
)) == 0)
4883 ia
->ia_iobase
= slot
<< 12;
4884 ia
->ia_iosize
= EISA_NPORT
;
4885 eisa_slotalloc(slot
);
4886 tmp
= inb(ia
->ia_iobase
+ DE425_CFG0
);
4887 irq
= tulip_eisa_irqs
[(tmp
>> 1) & 0x03];
4889 * Until BSD/OS likes level interrupts, force
4890 * the DE425 into edge-triggered mode.
4893 outb(ia
->ia_iobase
+ DE425_CFG0
, tmp
| 1);
4895 * CBIO needs to map to the EISA slot
4896 * enable I/O access and Master
4898 outl(ia
->ia_iobase
+ DE425_CBIO
, ia
->ia_iobase
);
4899 outl(ia
->ia_iobase
+ DE425_CFCS
, 5 | inl(ia
->ia_iobase
+ DE425_CFCS
));
4903 #endif /* TULIP_EISA */
4909 /* PCI bus masters don't use host DMA channels */
4910 ia
->ia_drq
= DRQNONE
;
4912 if (ia
->ia_irq
!= IRQUNK
&& irq
!= ia
->ia_irq
) {
4913 printf("ade%d: error: desired IRQ of %d does not match device's "
4914 "actual IRQ of %d,\n",
4916 ffs(ia
->ia_irq
) - 1, ffs(irq
) - 1);
4919 if (ia
->ia_irq
== IRQUNK
)
4922 ia
->ia_irq
|= IRQSHARE
;
4927 static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS
);
4929 #if defined(TULIP_EISA)
4930 static char *tulip_eisa_ids
[] = {
4936 struct cfdriver decd
= {
4937 0, "ade", tulip_probe
, tulip_pci_attach
,
4938 #if _BSDI_VERSION >= 199401
4941 sizeof(tulip_softc_t
),
4942 #if defined(TULIP_EISA)
4947 #endif /* __bsdi__ */
4949 #if defined(__NetBSD__)
4950 #define TULIP_PCI_ATTACH_ARGS struct device * const parent, struct device * const self, void *const aux
4951 #define TULIP_SHUTDOWN_ARGS void *arg
4954 struct device
*parent
,
4955 struct cfdata
*match
,
4958 struct pci_attach_args
*pa
= (struct pci_attach_args
*) aux
;
4960 if (PCI_VENDORID(pa
->pa_id
) != DEC_VENDORID
)
4962 if (PCI_CHIPID(pa
->pa_id
) == CHIPID_21040
4963 || PCI_CHIPID(pa
->pa_id
) == CHIPID_21041
4964 || PCI_CHIPID(pa
->pa_id
) == CHIPID_21140
4965 || PCI_CHIPID(pa
->pa_id
) == CHIPID_21142
)
4971 static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS
);
4973 CFATTACH_DECL(ade
, sizeof(tulip_softc_t
),
4974 tulip_pci_probe
, tulip_pci_attach
, NULL
, NULL
);
4976 #endif /* __NetBSD__ */
4980 TULIP_SHUTDOWN_ARGS
)
4982 tulip_softc_t
* const sc
= arg
;
4983 TULIP_CSR_WRITE(sc
, csr_busmode
, TULIP_BUSMODE_SWRESET
);
4984 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
4985 33MHz that comes to two microseconds but wait a
4986 bit longer anyways) */
4991 TULIP_PCI_ATTACH_ARGS
)
4993 #if defined(__FreeBSD__)
4995 #define PCI_CONF_WRITE(r, v) pci_conf_write(config_id, (r), (v))
4996 #define PCI_CONF_READ(r) pci_conf_read(config_id, (r))
4997 #define PCI_GETBUSDEVINFO(sc) ((void)((sc)->tulip_pci_busno = ((config_id.cfg1 >> 16) & 0xFF), /* XXX */ \
4998 (sc)->tulip_pci_devno = ((config_id.cfg1 >> 11) & 0x1F))) /* XXX */
5000 #if defined(__bsdi__)
5001 tulip_softc_t
* const sc
= (tulip_softc_t
*) self
;
5002 struct isa_attach_args
* const ia
= (struct isa_attach_args
*) aux
;
5003 pci_devaddr_t
*pa
= (pci_devaddr_t
*) ia
->ia_aux
;
5004 const int unit
= sc
->tulip_dev
.dv_unit
;
5005 #define PCI_CONF_WRITE(r, v) pci_outl(pa, (r), (v))
5006 #define PCI_CONF_READ(r) pci_inl(pa, (r))
5007 #define PCI_GETBUSDEVINFO(sc) ((void)((sc)->tulip_pci_busno = pa->d_bus, \
5008 (sc)->tulip_pci_devno = pa->d_agent))
5010 #if defined(__NetBSD__)
5011 tulip_softc_t
* const sc
= (tulip_softc_t
*) self
;
5012 struct pci_attach_args
* const pa
= (struct pci_attach_args
*) aux
;
5013 const int unit
= device_unit(&sc
->tulip_dev
);
5014 #ifdef THIS_IS_THE_ORIGINAL_HRH_DRIVER_USING_THE_NOW_DEFUNCT_PCI_MEM_FIND
5019 #ifdef PCI_PREFER_IOSPACE
5020 error error error error
5023 #define PCI_CONF_WRITE(r, v) pci_conf_write(pa->pa_pc, pa->pa_tag, (r), (v))
5024 #define PCI_CONF_READ(r) pci_conf_read(pa->pa_pc, pa->pa_tag, (r))
5025 #define PCI_GETBUSDEVINFO(sc) do { \
5026 int busno, devno, funcno; \
5027 pci_decompose_tag(pa->pa_pc, pa->pa_tag, &busno, &devno, &funcno); \
5028 (sc)->tulip_pci_busno = busno; \
5029 (sc)->tulip_pci_devno = devno; \
5031 #endif /* __NetBSD__ */
5033 u_int32_t revinfo
, cfdainfo
, id
;
5034 #if !defined(TULIP_IOMAPPED) && defined(__FreeBSD__)
5037 unsigned csroffset
= TULIP_PCI_CSROFFSET
;
5038 unsigned csrsize
= TULIP_PCI_CSRSIZE
;
5039 tulip_csrptr_t csr_base
;
5040 tulip_chipid_t chipid
= TULIP_CHIPID_UNKNOWN
;
5042 if (unit
>= TULIP_MAX_DEVICES
) {
5044 printf("ade%d", unit
);
5046 printf(": not configured; limit of %d reached or exceeded\n",
5051 #if defined(__bsdi__)
5053 revinfo
= pci_inl(pa
, PCI_CFRV
) & 0xFF;
5054 id
= pci_inl(pa
, PCI_CFID
);
5055 cfdainfo
= pci_inl(pa
, PCI_CFDA
);
5056 #if defined(TULIP_EISA)
5058 revinfo
= inl(ia
->ia_iobase
+ DE425_CFRV
) & 0xFF;
5059 csroffset
= TULIP_EISA_CSROFFSET
;
5060 csrsize
= TULIP_EISA_CSRSIZE
;
5061 chipid
= TULIP_DE425
;
5063 #endif /* TULIP_EISA */
5065 #else /* __bsdi__ */
5066 revinfo
= PCI_CONF_READ(PCI_CFRV
) & 0xFF;
5067 id
= PCI_CONF_READ(PCI_CFID
);
5068 cfdainfo
= PCI_CONF_READ(PCI_CFDA
);
5069 #endif /* __bsdi__ */
5071 if (PCI_VENDORID(id
) == DEC_VENDORID
) {
5072 if (PCI_CHIPID(id
) == CHIPID_21040
) chipid
= TULIP_21040
;
5073 else if (PCI_CHIPID(id
) == CHIPID_21140
) {
5074 chipid
= (revinfo
>= 0x20) ? TULIP_21140A
: TULIP_21140
;
5075 } else if (PCI_CHIPID(id
) == CHIPID_21142
) {
5076 chipid
= (revinfo
>= 0x20) ? TULIP_21143
: TULIP_21142
;
5078 else if (PCI_CHIPID(id
) == CHIPID_21041
) chipid
= TULIP_21041
;
5079 else if (PCI_CHIPID(id
) == CHIPID_21142
) chipid
= TULIP_21142
;
5081 if (chipid
== TULIP_CHIPID_UNKNOWN
)
5084 if ((chipid
== TULIP_21040
|| chipid
== TULIP_DE425
) && revinfo
< 0x20) {
5086 printf("ade%d", unit
);
5088 printf(": not configured; 21040 pass 2.0 required (%d.%d found)\n",
5089 revinfo
>> 4, revinfo
& 0x0f);
5091 } else if (chipid
== TULIP_21140
&& revinfo
< 0x11) {
5095 printf("ade%d: not configured; 21140 pass 1.1 required (%d.%d found)\n",
5096 unit
, revinfo
>> 4, revinfo
& 0x0f);
5100 #if defined(__FreeBSD__)
5101 sc
= (tulip_softc_t
*) malloc(sizeof(*sc
), M_DEVBUF
, M_NOWAIT
);
5104 memset(sc
, 0, sizeof(*sc
)); /* Zero out the softc*/
5107 PCI_GETBUSDEVINFO(sc
);
5108 sc
->tulip_chipid
= chipid
;
5109 sc
->tulip_flags
|= TULIP_DEVICEPROBE
;
5110 if (chipid
== TULIP_21140
|| chipid
== TULIP_21140A
)
5111 sc
->tulip_features
|= TULIP_HAVE_GPR
;
5112 if (chipid
== TULIP_21140A
&& revinfo
<= 0x22)
5113 sc
->tulip_features
|= TULIP_HAVE_RXBUGGY
;
5114 if (chipid
== TULIP_21140
)
5115 sc
->tulip_features
|= TULIP_HAVE_BROKEN_HASH
;
5116 if (chipid
!= TULIP_21040
&& chipid
!= TULIP_DE425
&& chipid
!= TULIP_21140
)
5117 sc
->tulip_features
|= TULIP_HAVE_POWERMGMT
;
5118 if (chipid
== TULIP_21041
|| chipid
== TULIP_21142
|| chipid
== TULIP_21143
) {
5119 sc
->tulip_features
|= TULIP_HAVE_DUALSENSE
;
5120 if (chipid
!= TULIP_21041
|| sc
->tulip_revinfo
>= 0x20)
5121 sc
->tulip_features
|= TULIP_HAVE_SIANWAY
;
5122 if (chipid
!= TULIP_21041
)
5123 sc
->tulip_features
|= TULIP_HAVE_SIAGP
;
5126 if (sc
->tulip_features
& TULIP_HAVE_POWERMGMT
5127 && (cfdainfo
& (TULIP_CFDA_SLEEP
|TULIP_CFDA_SNOOZE
))) {
5128 cfdainfo
&= ~(TULIP_CFDA_SLEEP
|TULIP_CFDA_SNOOZE
);
5129 PCI_CONF_WRITE(PCI_CFDA
, cfdainfo
);
5132 #if defined(__alpha__)
5134 * The Alpha SRM console encodes a console set media in the driver
5135 * part of the CFDA register. Note that the Multia presents a
5136 * problem in that its BNC mode is really EXTSIA. So in that case
5139 switch ((cfdainfo
>> 8) & 0xff) {
5140 case 1: sc
->tulip_media
= chipid
> TULIP_DE425
? TULIP_MEDIA_AUI
: TULIP_MEDIA_AUIBNC
;
5142 case 2: sc
->tulip_media
= chipid
> TULIP_DE425
? TULIP_MEDIA_BNC
: TULIP_MEDIA_UNKNOWN
;
5144 case 3: sc
->tulip_media
= TULIP_MEDIA_10BASET
; break;
5145 case 4: sc
->tulip_media
= TULIP_MEDIA_10BASET_FD
; break;
5146 case 5: sc
->tulip_media
= TULIP_MEDIA_100BASETX
; break;
5147 case 6: sc
->tulip_media
= TULIP_MEDIA_100BASETX_FD
; break;
5152 #if defined(__NetBSD__)
5153 strcpy(sc
->tulip_if
.if_xname
, self
->dv_xname
);
5154 sc
->tulip_if
.if_softc
= sc
;
5155 sc
->tulip_pc
= pa
->pa_pc
;
5157 sc
->tulip_unit
= unit
;
5158 sc
->tulip_name
= "ade";
5160 sc
->tulip_revinfo
= revinfo
;
5161 #if defined(__FreeBSD__)
5163 sc
->tulip_if
.if_softc
= sc
;
5165 #if defined(TULIP_IOMAPPED)
5166 retval
= pci_map_port(config_id
, PCI_CBIO
, &csr_base
);
5168 retval
= pci_map_mem(config_id
, PCI_CBMA
, (vaddr_t
*) &csr_base
, &pa_csrs
);
5171 free((void *) sc
, M_DEVBUF
);
5175 #endif /* __FreeBSD__ */
5177 #if defined(__bsdi__)
5178 sc
->tulip_pf
= printf
;
5179 #if defined(TULIP_IOMAPPED)
5180 csr_base
= ia
->ia_iobase
;
5182 csr_base
= (vaddr_t
) mapphys((vaddr_t
) ia
->ia_maddr
, ia
->ia_msize
);
5184 #endif /* __bsdi__ */
5186 #if defined(__NetBSD__)
5188 #ifdef THIS_IS_THE_ORIGINAL_HRH_DRIVER_USING_THE_NOW_DEFUNCT_PCI_MEM_FIND
5189 #if defined(TULIP_IOMAPPED)
5190 sc
->tulip_bustag
= pa
->pa_iot
;
5192 if (pci_io_find(pa
->pa_pc
, pa
->pa_tag
, PCI_CBIO
, ®base
, ®size
))
5195 sc
->tulip_bustag
= pa
->pa_memt
;
5196 if (pci_mem_find(pa
->pa_pc
, pa
->pa_tag
, PCI_CBMA
, ®base
, ®size
, &cacheable
))
5199 if (bus_space_map(sc
->tulip_bustag
, regbase
, regsize
, cacheable
, &sc
->tulip_bushandle
))
5203 bus_space_tag_t iot
, memt
;
5204 bus_space_handle_t ioh
, memh
;
5205 u_int32_t cfcs
= PCI_CONF_READ(PCI_CFCS
);
5207 cfcs
&= ~(PCI_COMMAND_IO_ENABLE
| PCI_COMMAND_MEM_ENABLE
);
5208 if (!pci_mapreg_map(pa
, PCI_CBIO
, PCI_MAPREG_TYPE_IO
, 0,
5209 &iot
, &ioh
, NULL
, NULL
)) {
5210 cfcs
|= PCI_COMMAND_IO_ENABLE
;
5212 if (!pci_mapreg_map(pa
, PCI_CBMA
,
5213 PCI_MAPREG_TYPE_MEM
| PCI_MAPREG_MEM_TYPE_32BIT
,
5214 0, &memt
, &memh
, NULL
, NULL
)) {
5215 cfcs
|= PCI_COMMAND_MEM_ENABLE
;
5217 if ((cfcs
& (PCI_COMMAND_IO_ENABLE
| PCI_COMMAND_MEM_ENABLE
)) == 0) {
5218 printf(": unable to map device registers\n");
5221 cfcs
|= PCI_COMMAND_MASTER_ENABLE
;
5222 PCI_CONF_WRITE(PCI_CFCS
, cfcs
);
5223 #if defined(PCI_PREFER_IOSPACE)
5224 if (cfcs
& PCI_COMMAND_IO_ENABLE
) {
5225 sc
->tulip_bustag
= iot
, sc
->tulip_bushandle
= ioh
;
5227 sc
->tulip_bustag
= memt
, sc
->tulip_bushandle
= memh
;
5230 if (cfcs
& PCI_COMMAND_MEM_ENABLE
) {
5231 sc
->tulip_bustag
= memt
, sc
->tulip_bushandle
= memh
;
5233 sc
->tulip_bustag
= iot
, sc
->tulip_bushandle
= ioh
;
5235 #endif /* PCI_PREFER_IOSPACE */
5238 #endif /* __NetBSD__ */
5240 tulip_initcsrs(sc
, csr_base
+ csroffset
, csrsize
);
5242 TULIP_CSR_WRITE(sc
, csr_busmode
, TULIP_BUSMODE_SWRESET
); /* hrh */
5243 DELAY(100); /* hrh */
5246 tulip_initring(sc
, &sc
->tulip_rxinfo
, sc
->tulip_rxdescs
, sc
->tulip_rx_kva
,
5248 tulip_initring(sc
, &sc
->tulip_txinfo
, sc
->tulip_txdescs
, sc
->tulip_tx_kva
,
5252 * Make sure there won't be any interrupts or such...
5254 TULIP_CSR_WRITE(sc
, csr_busmode
, TULIP_BUSMODE_SWRESET
);
5255 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
5256 33MHz that comes to two microseconds but wait a
5257 bit longer anyways) */
5259 if ((retval
= tulip_read_macaddr(sc
)) < 0) {
5260 #if defined(__FreeBSD__)
5261 printf(TULIP_PRINTF_FMT
, TULIP_PRINTF_ARGS
);
5263 printf(": can't read ENET ROM (why=%d) (", retval
);
5264 for (idx
= 0; idx
< 32; idx
++)
5265 printf("%02x", sc
->tulip_rombuf
[idx
]);
5267 printf(TULIP_PRINTF_FMT
": %s%s pass %d.%d\n",
5269 sc
->tulip_boardid
, tulip_chipdescs
[sc
->tulip_chipid
],
5270 (sc
->tulip_revinfo
& 0xF0) >> 4, sc
->tulip_revinfo
& 0x0F);
5271 printf(TULIP_PRINTF_FMT
": address unknown\n", TULIP_PRINTF_ARGS
);
5274 tulip_intrfunc_t (*intr_rtn
)(void *) = tulip_intr_normal
;
5276 if (sc
->tulip_flags
& TULIP_SHAREDINTR
)
5277 intr_rtn
= tulip_intr_shared
;
5279 #if defined(__NetBSD__)
5280 if ((sc
->tulip_flags
& TULIP_SLAVEDINTR
) == 0) {
5281 pci_intr_handle_t intrhandle
;
5282 const char *intrstr
;
5284 if (pci_intr_map(pa
, &intrhandle
)) {
5285 printf(": couldn't map interrupt\n");
5288 intrstr
= pci_intr_string(pa
->pa_pc
, intrhandle
);
5289 sc
->tulip_ih
= pci_intr_establish(pa
->pa_pc
, intrhandle
, IPL_NET
,
5291 if (sc
->tulip_ih
== NULL
)
5292 printf(": couldn't establish interrupt");
5293 if (intrstr
!= NULL
)
5294 printf(" at %s", intrstr
);
5296 if (sc
->tulip_ih
== NULL
)
5299 sc
->tulip_ats
= shutdownhook_establish(tulip_shutdown
, sc
);
5300 if (sc
->tulip_ats
== NULL
)
5301 printf("\n%s: warning: couldn't establish shutdown hook\n",
5304 #if defined(__FreeBSD__)
5305 if ((sc
->tulip_flags
& TULIP_SLAVEDINTR
) == 0) {
5306 if (!pci_map_int (config_id
, intr_rtn
, (void*) sc
, &net_imask
)) {
5307 printf(TULIP_PRINTF_FMT
": couldn't map interrupt\n",
5312 #if !defined(TULIP_DEVCONF)
5313 at_shutdown(tulip_shutdown
, sc
, SHUTDOWN_POST_SYNC
);
5316 #if defined(__bsdi__)
5317 if ((sc
->tulip_flags
& TULIP_SLAVEDINTR
) == 0) {
5318 isa_establish(&sc
->tulip_id
, &sc
->tulip_dev
);
5320 sc
->tulip_ih
.ih_fun
= intr_rtn
;
5321 sc
->tulip_ih
.ih_arg
= (void *) sc
;
5322 intr_establish(ia
->ia_irq
, &sc
->tulip_ih
, DV_NET
);
5325 sc
->tulip_ats
.func
= tulip_shutdown
;
5326 sc
->tulip_ats
.arg
= (void *) sc
;
5327 atshutdown(&sc
->tulip_ats
, ATSH_ADD
);
5329 #if defined(TULIP_USE_SOFTINTR)
5330 if (sc
->tulip_unit
> tulip_softintr_max_unit
)
5331 tulip_softintr_max_unit
= sc
->tulip_unit
;
5334 s
= TULIP_RAISESPL();
5337 TULIP_RESTORESPL(s
);
5342 a12_m_copydata(register struct mbuf
*m
, register int off
, register int len
, void *cp
)
5344 static long packet
[200]; /* may seem unwise, but typ a12 ram is 512 MB */
5346 if(len
> sizeof(packet
))
5347 panic("a12_m_copydata");
5348 m_copydata(m
, off
, len
, (void *)packet
);
5349 a12r2pb(packet
,cp
,len
);