Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / alpha / a12 / if_ade.c
blob132d4c271bc7f39d4cfefc0b7fea3e75d80daa8f
1 /* $NetBSD: if_ade.c,v 1.35 2009/03/14 21:04:01 dsl Exp $ */
3 /*
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.
8 */
10 /* [Notice revision 2.0]
11 * Copyright (c) 1997 Avalon Computer Systems, Inc.
12 * All rights reserved.
14 * Author: Ross Harvey
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
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
30 * assignment date.
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.
44 /*-
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
50 * are met:
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
81 #define LCLDMA 1
83 #include <sys/cdefs.h>
84 __KERNEL_RCSID(0, "$NetBSD: if_ade.c,v 1.35 2009/03/14 21:04:01 dsl Exp $");
86 #include "opt_inet.h"
87 #include "opt_ns.h"
89 #include <sys/param.h>
90 #include <sys/systm.h>
91 #include <sys/mbuf.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>
103 #endif
105 #include <net/if.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>
115 #endif
117 #include "bpfilter.h"
118 #if NBPFILTER > 0
119 #include <net/bpf.h>
120 #include <net/bpfdesc.h>
121 #endif
123 #ifdef INET
124 #include <netinet/in.h>
125 #include <netinet/in_systm.h>
126 #include <netinet/in_var.h>
127 #include <netinet/ip.h>
128 #endif
130 #ifdef NS
131 #include <netns/ns.h>
132 #include <netns/ns_if.h>
133 #endif
135 #include <uvm/uvm_extern.h>
137 #if defined(__FreeBSD__)
138 #include <vm/pmap.h>
139 #include <pci.h>
140 #include <netinet/if_ether.h>
141 #if NPCI > 0
142 #include <pci/pcivar.h>
143 #include <pci/dc21040.h>
144 #define DEVAR_INCLUDE "pci/if_devar.h"
145 #endif
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
157 #include <eisa.h>
158 #else
159 #define NEISA 0
160 #endif
161 #if NEISA > 0 && _BSDI_VERSION >= 199401
162 #include <i386/eisa/eisa.h>
163 #define TULIP_EISA
164 #endif
165 #define DEVAR_INCLUDE "i386/pci/if_devar.h"
166 #endif /* __bsdi__ */
168 #if defined(__NetBSD__)
169 #include <net/if_ether.h>
170 #if defined(INET)
171 #include <netinet/if_inarp.h>
172 #endif
173 #include <machine/bus.h>
174 #if defined(__alpha__)
175 #include <machine/intr.h>
176 #endif
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
187 #endif
189 #if 0
191 * This turns on all sort of debugging stuff and make the
192 * driver much larger.
194 #define TULIP_DEBUG
195 #endif
197 #if 0
198 #define TULIP_USE_SOFTINTR
199 #endif
201 #define TULIP_HZ 10
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); */
228 #ifdef LCLDMA
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.
239 static void
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) {
249 long bounce[9];
250 int i,
251 offset, /* destination misalignment */
252 t, /* segment count */
253 llw; /* last longword index */
255 char *src = vsrc;
256 long *dst = vdst;
258 offset = (long)dst & 7;
259 dst = (long *)((long)dst & ~7L);
260 alpha_wmb();
261 while(len) {
262 t = 64;
263 if(t > len)
264 t = len;
265 llw = (t+offset) >> 3;
266 if(((t|offset) & 7) == 0 && llw)
267 --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
274 * mem.
276 if(offset)
277 bounce[0] = dst[0];
278 memcpy((int8_t *)bounce+offset,src,t);
279 for(i=llw; i>=0; --i) { /* reverse so d_status is last */
280 alpha_mb();
281 dst[i] = bounce[i];
282 alpha_mb();
284 #if 0
285 { static int printcount;
286 if(++printcount<=4) {
287 for(i=llw; i>=0; --i) {
288 alpha_mb();
289 printf("dst[%d]=%16lx@%16lx bounce[%d]=%16lx\n",
290 i, dst[i], &dst[i], i, bounce[i]);
291 alpha_mb();
295 #endif
296 dst += 8;
297 src += t;
298 len -= t;
300 alpha_wmb();
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));
310 #ifdef LCLDMA
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;
315 return p;
317 #endif
318 #endif
320 static void
321 tulip_timeout_callback(
322 void *arg)
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);
330 TULIP_RESTORESPL(s);
333 static void
334 tulip_timeout(
335 tulip_softc_t * const sc)
337 if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
338 return;
339 sc->tulip_flags |= TULIP_TIMEOUTPENDING;
340 timeout(tulip_timeout_callback, sc, (hz + TULIP_HZ / 2) / TULIP_HZ);
343 #if defined(TULIP_NEED_FASTTIMEOUT)
344 static void
345 tulip_fasttimeout_callback(
346 void *arg)
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);
353 TULIP_RESTORESPL(s);
356 static void
357 tulip_fasttimeout(
358 tulip_softc_t * const sc)
360 if (sc->tulip_flags & TULIP_FASTTIMEOUTPENDING)
361 return;
362 sc->tulip_flags |= TULIP_FASTTIMEOUTPENDING;
363 timeout(tulip_fasttimeout_callback, sc, 1);
365 #endif
367 static int
368 tulip_txprobe(
369 tulip_softc_t * const sc)
371 struct mbuf *m;
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);
380 if (m == NULL)
381 return 0;
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;
393 * send it!
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++;
401 return 1;
404 #ifdef BIG_PACKET
405 #define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0)
406 #else
407 #define TULIP_SIAGEN_WATCHDOG 0
408 #endif
410 static void
411 tulip_media_set(
412 tulip_softc_t * const sc,
413 tulip_media_t media)
415 const tulip_media_info_t *mi = sc->tulip_mediums[media];
417 if (mi == NULL)
418 return;
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);
431 } else {
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;
444 tulip_reset(sc);
446 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
447 DELAY(10);
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;
457 tulip_reset(sc);
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) {
463 int idx;
464 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
465 const u_int8_t *dp;
466 dp = &sc->tulip_rombuf[mi->mi_reset_offset];
467 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) {
468 DELAY(10);
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) {
474 DELAY(10);
475 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
477 } else {
478 for (idx = 0; idx < mi->mi_reset_length; idx++) {
479 DELAY(10);
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++) {
484 DELAY(10);
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);
503 static void
504 tulip_linkup(
505 tulip_softc_t * const sc,
506 tulip_media_t media)
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);
518 } else {
519 if (TULIP_IS_MEDIA_FD(media)
520 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL)
521 media = TULIP_HD_MEDIA_OF(media);
524 #endif
525 if (sc->tulip_media != media) {
526 #ifdef TULIP_DEBUG
527 sc->tulip_dbg.dbg_last_media = sc->tulip_media;
528 #endif
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);
548 } else {
549 tulip_reset(sc);
550 tulip_init(sc);
554 static void
555 tulip_media_print(
556 tulip_softc_t * const sc)
558 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
559 return;
560 if (sc->tulip_flags & TULIP_PRINTMEDIA) {
561 printf(TULIP_PRINTF_FMT ": enabling %s port\n",
562 TULIP_PRINTF_ARGS,
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)
572 static tulip_media_t
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;
578 tulip_media_t media;
581 * If one of the media blocks contained a default media flag,
582 * use that.
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))
590 continue;
591 if (mi->mi_type != TULIP_MEDIAINFO_GPR)
592 continue;
595 * Remember the media is this is the "default" media.
597 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
598 maybe_media = media;
601 * No activity mask? Can't see if it is active if there's no mask.
603 if (mi->mi_actmask == 0)
604 continue;
607 * Does the activity data match?
609 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
610 continue;
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);
617 #endif
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) {
625 last_media = media;
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;
641 if (mi == NULL) {
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__);
645 #endif
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) {
661 u_int32_t status;
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);
679 #endif
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++;
734 #endif
735 return TULIP_LINK_DOWN;
738 static void
739 tulip_media_poll(
740 tulip_softc_t * const sc,
741 tulip_mediapoll_event_t event)
743 #if defined(TULIP_DEBUG)
744 sc->tulip_dbg.dbg_events[event]++;
745 #endif
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;
754 break;
756 case TULIP_LINK_UP: {
758 * Check again soon.
760 tulip_timeout(sc);
761 return;
763 case TULIP_LINK_UNKNOWN: {
765 * We can't tell so don't bother.
767 return;
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++;
777 #endif
778 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
779 tulip_reset(sc); /* restart probe */
781 return;
783 #if defined(TULIP_DEBUG)
784 sc->tulip_dbg.dbg_link_pollintrs++;
785 #endif
788 if (event == TULIP_MEDIAPOLL_START) {
789 sc->tulip_if.if_flags |= IFF_OACTIVE;
790 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
791 return;
792 sc->tulip_probe_mediamask = 0;
793 sc->tulip_probe_passes = 0;
794 #if defined(TULIP_DEBUG)
795 sc->tulip_dbg.dbg_media_probes++;
796 #endif
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);
809 tulip_timeout(sc);
810 return;
813 if (sc->tulip_features & TULIP_HAVE_GPR) {
814 sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
815 sc->tulip_probe_timeout = 2000;
816 } else {
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;
829 return;
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)
839 else
840 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
841 #endif
842 tulip_linkup(sc, sc->tulip_probe_media);
843 tulip_timeout(sc);
844 return;
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]);
860 #endif
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);
865 } else {
866 sc->tulip_probe_count = 10;
869 sc->tulip_probe_media = new_probe_media;
870 tulip_timeout(sc);
871 return;
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;
881 tulip_timeout(sc);
882 return;
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;
897 #ifdef notyet
898 if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
899 break;
900 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
901 break;
902 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
903 #endif
904 break;
906 case TULIP_PROBE_PHYAUTONEG: {
907 return;
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;
916 break;
918 tulip_linkup(sc, sc->tulip_probe_media);
919 tulip_timeout(sc);
920 return;
922 default: {
923 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
924 panic("tulip_media_poll: botch at line %d", __LINE__);
925 #endif
926 break;
931 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
932 #if defined(TULIP_DEBUG)
933 sc->tulip_dbg.dbg_txprobes_failed[sc->tulip_probe_media]++;
934 #endif
935 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
936 return;
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",
946 TULIP_PRINTF_ARGS);
947 sc->tulip_probe_media = TULIP_MEDIA_MAX;
949 #endif
951 * Find the next media type to check for. Full Duplex
952 * types are not allowed.
954 do {
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",
959 TULIP_PRINTF_ARGS);
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;
963 return;
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]);
978 #endif
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;
982 tulip_reset(sc);
983 tulip_media_set(sc, sc->tulip_probe_media);
984 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
986 tulip_timeout(sc);
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))
996 return;
997 break;
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)
1002 return;
1003 tulip_linkup(sc, sc->tulip_probe_media);
1004 #ifdef notyet
1005 if (sc->tulip_features & TULIP_HAVE_MII)
1006 tulip_timeout(sc);
1007 #endif
1008 return;
1010 break;
1012 case TULIP_MEDIAINFO_RESET:
1013 case TULIP_MEDIAINFO_SYM:
1014 case TULIP_MEDIAINFO_GPR: {
1015 break;
1019 * Try to send a packet.
1021 tulip_txprobe(sc);
1024 static void
1025 tulip_media_select(
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);
1030 DELAY(10);
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)
1037 return;
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);
1041 } else {
1042 tulip_media_set(sc, sc->tulip_media);
1046 static void
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);
1069 static void
1070 tulip_21040_media_probe(
1071 tulip_softc_t * const sc)
1073 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
1074 return;
1077 static void
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;
1086 static void
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;
1094 } else {
1095 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1096 sc->tulip_flags |= TULIP_SQETEST;
1098 tulip_media_set(sc, sc->tulip_media);
1101 static void
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;
1111 static void
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,
1122 tulip_media_select,
1123 tulip_media_poll,
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,
1130 NULL,
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,
1137 NULL,
1140 static void
1141 tulip_21041_mediainfo_init(
1142 tulip_softc_t * const sc)
1144 tulip_media_info_t * const mi = sc->tulip_mediainfo;
1146 #ifdef notyet
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);
1152 return;
1154 #endif
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);
1161 static void
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);
1172 static void
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]++;
1181 #endif
1183 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
1184 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
1185 || !TULIP_DO_AUTOSENSE(sc))
1186 return;
1187 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
1188 tulip_reset(sc); /* start probe */
1189 return;
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);
1199 #ifdef notyet
1200 if (sc->tulip_revinfo >= 0x20) {
1201 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
1202 sc->tulip_flags |= TULIP_DIDNWAY;
1204 #endif
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);
1210 tulip_timeout(sc);
1211 return;
1214 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1215 return;
1217 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
1218 #if defined(TULIP_DEBUG)
1219 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
1220 #endif
1221 tulip_linkup(sc, sc->tulip_probe_media);
1222 return;
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);
1237 return;
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)
1247 return;
1248 if (sc->tulip_probe_timeout > 0
1249 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
1250 tulip_timeout(sc);
1251 return;
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;
1257 } else {
1258 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1260 tulip_media_set(sc, sc->tulip_probe_media);
1261 tulip_timeout(sc);
1262 return;
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);
1278 return;
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;
1287 tulip_txprobe(sc);
1288 tulip_timeout(sc);
1289 return;
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;
1300 } else {
1301 printf(TULIP_PRINTF_FMT ": autosense failed: cable problem?\n",
1302 TULIP_PRINTF_ARGS);
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;
1306 return;
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;
1318 } else {
1319 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1321 tulip_media_set(sc, sc->tulip_probe_media);
1322 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1323 tulip_timeout(sc);
1326 static const tulip_boardsw_t tulip_21041_boardsw = {
1327 TULIP_21041_GENERIC,
1328 tulip_21041_media_probe,
1329 tulip_media_select,
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)
1340 "NS DP83840",
1341 #endif
1343 { 0x0281F400, 0, /* 00-A0-7D */
1345 { 0x12, 0x0010, 0x0000 }, /* 10T */
1346 { }, /* 100TX */
1347 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1348 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1350 #if defined(TULIP_DEBUG)
1351 "Seeq 80C240"
1352 #endif
1354 #if 0
1355 { 0x0015F420, 0, /* 00-A0-7D */
1357 { 0x12, 0x0010, 0x0000 }, /* 10T */
1358 { }, /* 100TX */
1359 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1360 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1362 #if defined(TULIP_DEBUG)
1363 "Broadcom BCM5000"
1364 #endif
1366 #endif
1367 { 0x0281F400, 0, /* 00-A0-BE */
1369 { 0x11, 0x8000, 0x0000 }, /* 10T */
1370 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1371 { }, /* 100T4 */
1372 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1374 #if defined(TULIP_DEBUG)
1375 "ICS 1890"
1376 #endif
1378 { 0 }
1381 static tulip_media_t
1382 tulip_mii_phy_readspecific(
1383 tulip_softc_t * const sc)
1385 const tulip_phy_attr_t *attr;
1386 u_int16_t data;
1387 u_int32_t id;
1388 unsigned idx = 0;
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,
1397 TULIP_MEDIA_UNKNOWN
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)
1413 break;
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)
1420 idx = 2;
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)
1426 idx = 3;
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)
1432 idx = 1;
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);
1439 return table[idx];
1442 static unsigned
1443 tulip_mii_get_phyaddr(
1444 tulip_softc_t * const sc,
1445 unsigned offset)
1447 unsigned phyaddr;
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)
1452 continue;
1453 if (offset == 0)
1454 return phyaddr;
1455 offset--;
1457 if (offset == 0) {
1458 unsigned status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
1459 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1460 return TULIP_MII_NOPHY;
1461 return 0;
1463 return TULIP_MII_NOPHY;
1466 static int
1467 tulip_mii_map_abilities(
1468 tulip_softc_t * const sc,
1469 unsigned abilities)
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;
1482 } else {
1483 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1484 return 0;
1486 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1487 return 1;
1490 static void
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;
1503 /* FALL THROUGH */
1505 case TULIP_PROBE_PHYRESET: {
1506 u_int32_t status;
1507 u_int32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1508 if (data & PHYCTL_RESET) {
1509 if (sc->tulip_probe_timeout > 0) {
1510 tulip_timeout(sc);
1511 return;
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);
1518 return;
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);
1525 #endif
1526 sc->tulip_flags &= ~TULIP_DIDNWAY;
1527 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1528 return;
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);
1538 else
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++;
1542 #endif
1543 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
1544 sc->tulip_probe_timeout = 3000;
1545 /* FALL THROUGH */
1547 case TULIP_PROBE_PHYAUTONEG: {
1548 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1549 u_int32_t data;
1550 if ((status & PHYSTS_AUTONEG_DONE) == 0) {
1551 if (sc->tulip_probe_timeout > 0) {
1552 tulip_timeout(sc);
1553 return;
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));
1559 #endif
1560 sc->tulip_flags &= ~TULIP_DIDNWAY;
1561 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1562 return;
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);
1568 #endif
1569 data = (data << 6) & status;
1570 if (!tulip_mii_map_abilities(sc, data))
1571 sc->tulip_flags &= ~TULIP_DIDNWAY;
1572 return;
1574 default: {
1575 #if defined(DIAGNOSTIC)
1576 panic("tulip_media_poll: botch at line %d", __LINE__);
1577 #endif
1578 break;
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++;
1585 #endif
1588 static void
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;
1597 else
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) {
1606 #endif
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)
1618 } else {
1619 printf(TULIP_PRINTF_FMT ": preset: bad media %d!\n",
1620 TULIP_PRINTF_ARGS, media);
1622 #endif
1624 switch (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;
1632 break;
1634 case TULIP_MEDIA_10BASET_FD: {
1635 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
1636 sc->tulip_if.if_baudrate = 10000000;
1637 break;
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;
1645 break;
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;
1652 break;
1654 default: {
1655 break;
1658 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1662 ********************************************************************
1663 * Start of 21140/21140A support which does not use the MII interface
1666 static void
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]++;
1673 #endif
1674 #if defined(DIAGNOSTIC)
1675 printf(TULIP_PRINTF_FMT ": botch(media_poll) at line %d\n",
1676 TULIP_PRINTF_ARGS, __LINE__);
1677 #endif
1680 inline static void
1681 tulip_21140_mediainit(
1682 tulip_softc_t * const sc,
1683 tulip_media_info_t * const mip,
1684 tulip_media_t const media,
1685 unsigned gpdata,
1686 unsigned cmdmode)
1688 sc->tulip_mediums[media] = mip;
1689 mip->mi_type = TULIP_MEDIAINFO_GPR;
1690 mip->mi_cmdmode = cmdmode;
1691 mip->mi_gpdata = gpdata;
1694 static void
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);
1709 DELAY(1000000);
1710 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
1711 sc->tulip_media = TULIP_MEDIA_10BASET;
1712 } else {
1713 sc->tulip_media = TULIP_MEDIA_100BASETX;
1715 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1716 TULIP_GP_EB_INIT,
1717 TULIP_CMD_TXTHRSHLDCTL);
1718 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1719 TULIP_GP_EB_INIT,
1720 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1721 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1722 TULIP_GP_EB_INIT,
1723 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1724 |TULIP_CMD_SCRAMBLER);
1725 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1726 TULIP_GP_EB_INIT,
1727 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1728 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1731 static const tulip_boardsw_t tulip_21140_eb_boardsw = {
1732 TULIP_21140_DEC_EB,
1733 tulip_21140_evalboard_media_probe,
1734 tulip_media_select,
1735 tulip_null_media_poll,
1736 tulip_2114x_media_preset,
1739 static void
1740 tulip_21140_smc9332_media_probe(
1741 tulip_softc_t * const sc)
1743 tulip_media_info_t *mip = sc->tulip_mediainfo;
1744 int idx, cnt = 0;
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);
1757 DELAY(200000);
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)) {
1761 if (++cnt > 100)
1762 break;
1763 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
1764 break;
1765 } else {
1766 cnt = 0;
1768 DELAY(1000);
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,
1790 tulip_media_select,
1791 tulip_null_media_poll,
1792 tulip_2114x_media_preset,
1795 static void
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,
1825 tulip_media_select,
1826 tulip_null_media_poll,
1827 tulip_2114x_media_preset
1830 static void
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);
1847 DELAY(200000);
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)) {
1851 if (++cnt100 > 100)
1852 break;
1853 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
1854 if (++cnt10 > 100)
1855 break;
1856 } else {
1857 cnt10 = 0;
1858 cnt100 = 0;
1860 DELAY(1000);
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,
1882 tulip_media_select,
1883 tulip_null_media_poll,
1884 tulip_2114x_media_preset,
1887 static void
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 = {
1896 TULIP_21140_ISV,
1897 tulip_2114x_media_probe,
1898 tulip_media_select,
1899 tulip_media_poll,
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 = {
1911 TULIP_21140_AVALON,
1912 tulip_21140_evalboard_media_probe,
1913 tulip_media_select,
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)
1926 static void
1927 tulip_delay_300ns(
1928 tulip_softc_t * const sc)
1930 int idx;
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)
1937 static void
1938 tulip_srom_idle(
1939 tulip_softc_t * const sc)
1941 unsigned bit, csr;
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;
1957 csr = 0; EMIT;
1961 static void
1962 tulip_srom_read(
1963 tulip_softc_t * const sc)
1965 int idx;
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;
1980 lastbit = 0;
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 */
1986 } else {
1987 EMIT;
1989 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1990 lastbit = thisbit;
1992 csr ^= SROMCLKOFF; EMIT;
1994 for (data = 0, bits = 0; bits < 16; bits++) {
1995 data <<= 1;
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;
2003 csr = 0; 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)
2010 static void
2011 tulip_mii_writebits(
2012 tulip_softc_t * const sc,
2013 unsigned data,
2014 unsigned bits)
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 */
2028 lastbit = thisbit;
2029 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
2033 static void
2034 tulip_mii_turnaround(
2035 tulip_softc_t * const sc,
2036 unsigned cmd)
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 */
2045 } else {
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 */
2052 static unsigned
2053 tulip_mii_readbits(
2054 tulip_softc_t * const sc)
2056 unsigned data;
2057 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
2058 int idx;
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)
2064 data |= 1;
2065 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
2067 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
2069 return data;
2072 static unsigned
2073 tulip_mii_readreg(
2074 tulip_softc_t * const sc,
2075 unsigned devaddr,
2076 unsigned regno)
2078 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
2079 unsigned data;
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]++;
2092 #endif
2093 return data;
2096 static void
2097 tulip_mii_writereg(
2098 tulip_softc_t * const sc,
2099 unsigned devaddr,
2100 unsigned regno,
2101 unsigned data)
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]++;
2114 #endif
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)))
2122 static unsigned
2123 tulip_crc32(
2124 const unsigned char *databuf,
2125 size_t datalen)
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);
2132 return crc;
2135 static void
2136 tulip_identify_dec_nic(
2137 tulip_softc_t * const sc)
2139 strcpy(sc->tulip_boardid, "DEC ");
2140 #define D0 4
2141 if (sc->tulip_chipid <= TULIP_DE425)
2142 return;
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] = ' ';
2148 #undef D0
2151 static void
2152 tulip_identify_znyx_nic(
2153 tulip_softc_t * const sc)
2155 unsigned id = 0;
2156 strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
2157 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
2158 unsigned znyx_ptr;
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;
2163 return;
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';
2190 if (id == 0) {
2192 * Assume it's a ZX342...
2194 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2196 return;
2198 sc->tulip_boardid[8] = '1';
2199 if (sc->tulip_chipid == TULIP_21041) {
2200 sc->tulip_boardid[10] = '1';
2201 return;
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;
2224 } else {
2225 id = 0;
2228 if (id == 0) {
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;
2244 static void
2245 tulip_identify_smc_nic(
2246 tulip_softc_t * const sc)
2248 u_int32_t id1, id2, ei;
2249 int auibnc = 0, utp = 0;
2250 char *cp;
2252 strcpy(sc->tulip_boardid, "SMC ");
2253 if (sc->tulip_chipid == TULIP_21041)
2254 return;
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 ");
2261 } else {
2262 strcpy(&sc->tulip_boardid[4], "9334BDT ");
2264 return;
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];
2272 if ((id1 & 1) == 0)
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;
2278 if (id2 == 0x15) {
2279 sc->tulip_boardid[7] = '4';
2280 *cp++ = '-';
2281 *cp++ = 'C';
2282 *cp++ = 'H';
2283 *cp++ = (ei ? '2' : '1');
2285 *cp++ = ' ';
2286 *cp = '\0';
2287 if (utp && !auibnc)
2288 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2289 else if (!utp && auibnc)
2290 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
2293 static void
2294 tulip_identify_cogent_nic(
2295 tulip_softc_t * const sc)
2297 #ifdef HRH_RIP
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;
2305 #endif
2307 #if 0
2309 static void
2310 tulip_identify_avalon_nic(
2311 tulip_softc_t * const sc)
2313 strcpy(sc->tulip_boardid, "Avalon PMC2TTX");
2315 #endif
2317 static void
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);
2337 DELAY(100);
2338 TULIP_CSR_WRITE(sc, csr_gp, 0);
2339 DELAY(200000);
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)
2349 return;
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;
2365 static int
2366 tulip_srom_decode(
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;
2375 const u_int8_t *dp;
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)
2380 break;
2381 if (saip->sai_device == sc->tulip_pci_devno)
2382 break;
2385 * Didn't find the right media block for this card.
2387 if (idx1 == shp->sh_adapter_count)
2388 return 0;
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
2397 * won't hurt.
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)
2410 break;
2412 sc->tulip_connidx = idx2;
2414 if (sc->tulip_chipid == TULIP_21041) {
2415 blocks = *dp++;
2416 for (idx2 = 0; idx2 < blocks; idx2++) {
2417 tulip_media_t media;
2418 data = *dp++;
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)
2422 break;
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;
2432 mi++;
2433 } else {
2434 switch (media) {
2435 case TULIP_MEDIA_BNC: {
2436 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
2437 mi++;
2438 break;
2440 case TULIP_MEDIA_AUI: {
2441 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
2442 mi++;
2443 break;
2445 case TULIP_MEDIA_10BASET: {
2446 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
2447 mi++;
2448 break;
2450 case TULIP_MEDIA_10BASET_FD: {
2451 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
2452 mi++;
2453 break;
2455 default: {
2456 break;
2461 if (data & TULIP_SROM_21041_EXTENDED)
2462 dp += 6;
2464 #ifdef notdef
2465 if (blocks == 0) {
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++;
2471 #endif
2472 } else {
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++;
2477 blocks = *dp++;
2478 for (idx2 = 0; idx2 < blocks; idx2++) {
2479 const u_int8_t *ep;
2480 if ((*dp & 0x80) == 0) {
2481 length = 4;
2482 type = 0;
2483 } else {
2484 length = (*dp++ & 0x7f) - 1;
2485 type = *dp++ & 0x3f;
2487 ep = dp + length;
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)
2494 break;
2496 media = tulip_srom_mediums[idx3].sm_type;
2497 if (media == TULIP_MEDIA_UNKNOWN)
2498 break;
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;
2504 gp_media = media;
2506 data = dp[2] + dp[3] * 256;
2507 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2508 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2509 mi->mi_actmask = 0;
2510 } else {
2511 #if 0
2512 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2513 #endif
2514 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2515 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2517 mi++;
2518 break;
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++) {
2536 DELAY(10);
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++) {
2541 DELAY(10);
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)
2547 break;
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);
2558 mi++;
2559 break;
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)
2566 break;
2568 media = tulip_srom_mediums[idx3].sm_type;
2569 if (media == TULIP_MEDIA_UNKNOWN)
2570 break;
2571 mi->mi_type = TULIP_MEDIAINFO_SIA;
2572 sc->tulip_mediums[media] = mi;
2573 if (type & 0x40) {
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;
2577 dp += 6;
2578 } else {
2579 switch (media) {
2580 case TULIP_MEDIA_BNC: {
2581 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
2582 break;
2584 case TULIP_MEDIA_AUI: {
2585 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
2586 break;
2588 case TULIP_MEDIA_10BASET: {
2589 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
2590 break;
2592 case TULIP_MEDIA_10BASET_FD: {
2593 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
2594 break;
2596 default: {
2597 goto bad_media;
2601 mi->mi_sia_gp_control = (dp[0] + dp[1] * 256) << 16;
2602 mi->mi_sia_gp_data = (dp[2] + dp[3] * 256) << 16;
2603 mi++;
2604 bad_media:
2605 break;
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) {
2620 DELAY(10);
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) {
2626 DELAY(10);
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)
2631 break;
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);
2643 mi++;
2644 break;
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)
2651 break;
2653 media = tulip_srom_mediums[idx3].sm_type;
2654 if (media == TULIP_MEDIA_UNKNOWN)
2655 break;
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) {
2663 mi->mi_actmask = 0;
2664 } else {
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;
2669 mi++;
2670 break;
2672 #if 0
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;
2678 mi++;
2679 break;
2681 #endif
2682 default: {
2685 dp = ep;
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 } },
2702 #if 0
2703 { tulip_identify_avalon_nic, { 0x00, 0x80, 0xe0 } },
2704 { tulip_identify_avalon_nic, { 0x02, 0xbb, 0x01 } },
2705 #else
2706 { tulip_identify_dec_nic, { 0x00, 0x80, 0xe0 } },
2707 { tulip_identify_dec_nic, { 0x02, 0xbb, 0x01 } },
2708 #endif
2709 { NULL }
2713 * This deals with the vagaries of the address roms and the
2714 * brain-deadness that various vendors commit in using them.
2716 static int
2717 tulip_read_macaddr(
2718 tulip_softc_t * const sc)
2720 int cksum, rom_cksum, idx;
2721 u_int32_t csr;
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++) {
2730 int cnt = 0;
2731 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
2732 cnt++;
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) {
2738 int cnt;
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])
2742 ++idx;
2743 else
2744 idx = 0;
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 */
2750 } else {
2751 if (sc->tulip_chipid == TULIP_21041) {
2753 * Thankfully all 21041's act the same.
2755 sc->tulip_boardsw = &tulip_21041_boardsw;
2756 } else {
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
2770 * new format.
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)
2781 break;
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
2792 * BASE rom.
2794 if (sc->tulip_rombuf[19] > 1)
2795 sc->tulip_flags |= TULIP_BASEROM;
2796 if (sc->tulip_boardsw == NULL)
2797 return -6;
2798 goto check_oui;
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");
2811 #if 0
2812 printf("ade%d: Warning: reinit srom! Old Avalon format!",
2813 cf->cf_unit);
2814 memcpy(sc->tulip_enaddr, sc->tulip_rombuf + 4, 6);
2815 sc->tulip_flags |= TULIP_ROMOK;
2816 goto check_oui;
2817 #endif
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
2824 * start at 8).
2826 for (idx = 8; idx < 32; idx++) {
2827 if (sc->tulip_rombuf[idx] != 0xFF)
2828 return -4;
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)
2835 return -4;
2836 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
2837 && sc->tulip_rombuf[2] == 0)
2838 return -4;
2839 memcpy(sc->tulip_enaddr, sc->tulip_rombuf, 6);
2840 sc->tulip_flags |= TULIP_ROMOK;
2841 goto check_oui;
2842 } else {
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)
2855 break;
2857 if (idx == sizeof(sc->tulip_rombuf)) {
2858 int root_unit;
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)
2863 break;
2864 root_sc = NULL;
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))
2876 return -5;
2877 } else {
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;
2893 return 0;
2899 * This is the standard DEC address ROM test.
2902 if (memcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
2903 return -3;
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)
2910 return -2;
2912 memcpy(sc->tulip_enaddr, sc->tulip_rombuf, 6);
2914 cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
2915 cksum *= 2;
2916 if (cksum > 65535) cksum -= 65535;
2917 cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
2918 if (cksum > 65535) cksum -= 65535;
2919 cksum *= 2;
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)
2927 return -1;
2929 check_oui:
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);
2937 break;
2941 sc->tulip_flags |= TULIP_ROMOK;
2942 return 0;
2945 static void
2946 tulip_ifmedia_add(
2947 tulip_softc_t * const sc)
2949 tulip_media_t media;
2950 int medias = 0;
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],
2955 0, 0);
2956 medias++;
2959 if (medias == 0) {
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);
2965 } else {
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);
2972 static int
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);
2989 return 0;
2993 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
2994 tulip_reset(sc);
2995 tulip_init(sc);
2996 return 0;
3000 * Media status callback
3002 static void
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;
3014 return;
3016 #endif
3017 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN)
3018 return;
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];
3027 static void
3028 tulip_addr_filter(
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;
3040 #endif
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;
3049 } else {
3050 u_int32_t *sp = sc->tulip_setupdata;
3051 unsigned hash;
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);
3063 } else {
3064 sc->tulip_flags |= TULIP_ALLMULTI;
3065 break;
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;
3085 int idx = 0;
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];
3096 } else {
3097 sc->tulip_flags |= TULIP_ALLMULTI;
3098 break;
3100 ETHER_NEXT_MULTI(step, enm);
3103 * Add the broadcast address.
3105 idx++;
3106 *sp++ = 0xFFFF;
3107 *sp++ = 0xFFFF;
3108 *sp++ = 0xFFFF;
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;
3122 #endif
3125 static void
3126 tulip_reset(
3127 tulip_softc_t * const sc)
3129 tulip_ringinfo_t *ri;
3130 tulip_desc_t *di;
3131 u_int32_t inreset = (sc->tulip_flags & TULIP_INRESET);
3133 debug_sc = sc;
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.
3139 * Grrrr.
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) */
3149 if (!inreset) {
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);
3159 else {
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;
3168 #ifdef LCLDMA
3169 reset_lcl_dma(sc);
3170 #endif
3171 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
3173 * Free all the mbufs that were on the transmit ring.
3175 for (;;) {
3176 struct mbuf *m;
3177 IF_DEQUEUE(&sc->tulip_txq, m);
3178 if (m == NULL)
3179 break;
3180 m_freem(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++)
3187 setstatus(di,0);
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
3192 * more.
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++) {
3198 BEGIN(di);
3199 t.d_status = 0;
3200 t.d_length1= 0;
3201 t.d_length2= 0;
3202 #ifndef LCLDMA
3203 t.d_addr1 = 0;
3204 t.d_addr2 = 0;
3205 #endif
3206 END(di);
3208 for (;;) {
3209 struct mbuf *m;
3210 IF_DEQUEUE(&sc->tulip_rxq, m);
3211 if (m == NULL)
3212 break;
3213 m_freem(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
3219 * have happened.
3221 if (inreset)
3222 return;
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",
3233 TULIP_PRINTF_ARGS);
3234 #endif
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
3240 |TULIP_RXACT);
3241 tulip_addr_filter(sc);
3244 static void
3245 tulip_init(
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 */
3251 tulip_reset(sc);
3253 sc->tulip_if.if_flags |= IFF_RUNNING;
3254 if (sc->tulip_if.if_flags & IFF_PROMISC) {
3255 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
3256 } else {
3257 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
3258 if (sc->tulip_flags & TULIP_ALLMULTI) {
3259 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
3260 } else {
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) {
3266 tulip_rx_intr(sc);
3267 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3268 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3269 } else {
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);
3277 } else {
3278 sc->tulip_if.if_flags &= ~IFF_RUNNING;
3279 tulip_reset(sc);
3283 static void
3284 tulip_rx_intr(
3285 tulip_softc_t * const sc)
3287 tulip_ringinfo_t * const ri = &sc->tulip_rxinfo;
3288 struct ifnet * const ifp = &sc->tulip_if;
3289 int fillok = 1;
3290 #if defined(TULIP_DEBUG)
3291 int cnt = 0;
3292 #endif
3294 for (;;) {
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;
3299 int accept = 0;
3301 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
3302 goto queue_mbuf;
3304 #if defined(TULIP_DEBUG)
3305 if (cnt == ri->ri_max)
3306 break;
3307 #endif
3309 * If the TULIP has no descriptors, there can't be any receive
3310 * descriptors to process.
3312 if (eop == ri->ri_nextout)
3313 break;
3316 * 90% of the packets will fit in one descriptor. So we optimize
3317 * for that case.
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);
3321 me = ms;
3322 } else {
3324 * If still owned by the TULIP, don't touch it.
3326 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
3327 break;
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");
3337 #endif
3338 if (++eop == ri->ri_last)
3339 eop = ri->ri_first;
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]++;
3344 #endif
3345 return;
3347 total_len++;
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);
3364 me = me->m_next;
3369 * Now get the size of received packet (minus the CRC).
3371 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
3372 /* good packet ? */
3373 if ((eop->d_status & TULIP_DSTS_ERRSUM) == 0
3374 || (sc->tulip_flags & TULIP_RXBAD)
3375 #ifdef BIG_PACKET
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)
3380 #endif
3382 me->m_len = total_len - last_offset;
3383 eh = *mtod(ms, struct ether_header *);
3384 #if NBPFILTER > 0
3385 if (sc->tulip_bpf != NULL) {
3386 if (me == ms)
3387 TULIP_BPF_TAP(sc, mtod(ms, void *), total_len);
3388 else
3389 TULIP_BPF_MTAP(sc, ms);
3391 #endif
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))
3395 goto next;
3396 accept = 1;
3397 sc->tulip_flags |= TULIP_RXACT;
3398 } else {
3399 ifp->if_ierrors++;
3400 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3401 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3402 } else {
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";
3412 } else {
3413 sc->tulip_dot3stats.dot3StatsFCSErrors++;
3414 error = "bad crc";
3417 if (error != NULL && (sc->tulip_flags & TULIP_NOMESSAGES) == 0) {
3418 printf(TULIP_PRINTF_FMT ": receive: " TULIP_EADDR_FMT ": %s\n",
3419 TULIP_PRINTF_ARGS,
3420 TULIP_EADDR_ARGS(mtod(ms, u_char *) + 6),
3421 error);
3422 sc->tulip_flags |= TULIP_NOMESSAGES;
3426 next:
3427 #if defined(TULIP_DEBUG)
3428 cnt++;
3429 #endif
3430 ifp->if_ipackets++;
3431 if (++eop == ri->ri_last)
3432 eop = ri->ri_first;
3433 ri->ri_nextin = eop;
3434 queue_mbuf:
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) {
3449 struct mbuf *m0;
3450 MGETHDR(m0, M_DONTWAIT, MT_DATA);
3451 if (m0 != NULL) {
3452 #if defined(TULIP_COPY_RXDATA)
3453 if (!accept || total_len >= MHLEN - 2) {
3454 #endif
3455 #if defined(LCLDMA)
3456 MCLGET(m0, M_DONTWAIT);
3457 if ((m0->m_flags & M_EXT) == 0) {
3458 m_freem(m0);
3459 m0 = NULL;
3461 #endif /* defined(LCLDMA) */
3462 #if defined(TULIP_COPY_RXDATA)
3464 #endif
3466 if (accept
3467 #if defined(TULIP_COPY_RXDATA)
3468 && m0 != NULL
3469 #endif
3471 #if defined(__bsdi__)
3472 eh.ether_type = ntohs(eh.ether_type);
3473 #endif
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);
3479 #else
3480 m_adj(ms, sizeof(struct ether_header);
3481 ether_input(ifp, &eh, ms);
3482 #endif /* __NetBSD__ */
3483 #ifdef LCLDMA
3484 #error LCLDMA requires TULIP_COPY_RXDATA
3485 #endif
3486 #else
3487 #ifdef BIG_PACKET
3488 #error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
3489 #endif
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);
3496 #else
3497 m_adj(m0, sizeof(struct ether_header);
3498 ether_input(ifp, &eh, m0);
3499 #endif /* __NetBSD__ */
3500 m0 = ms;
3501 #endif /* ! TULIP_COPY_RXDATA */
3503 ms = m0;
3505 if (ms == NULL) {
3507 * Couldn't allocate a new buffer. Don't bother
3508 * trying to replenish the receive queue.
3510 fillok = 0;
3511 sc->tulip_flags |= TULIP_RXBUFSLOW;
3512 #if defined(TULIP_DEBUG)
3513 sc->tulip_dbg.dbg_rxlowbufs++;
3514 #endif
3515 continue;
3518 * Now give the buffer(s) to the TULIP and save in our
3519 * receive queue.
3521 #ifdef LCLDMA
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);
3534 #ifdef TULIP_DEBUG
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");
3540 #endif
3541 #endif
3542 do {
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;
3550 me = ms->m_next;
3551 ms->m_next = NULL;
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]++;
3562 #endif
3565 static int
3566 tulip_tx_intr(
3567 tulip_softc_t * const sc)
3569 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
3570 struct mbuf *m;
3571 int xmits = 0;
3572 int f;
3574 while (ri->ri_free < ri->ri_max) {
3575 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
3576 break;
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) {
3590 tulip_rx_intr(sc);
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);
3597 } else {
3598 tulip_desc_t * const nextin = ri->ri_nextin;
3599 IF_DEQUEUE(&sc->tulip_txq, m);
3600 m_freem(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++;
3609 #endif
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!
3616 break;
3617 } else {
3618 xmits++;
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++;
3629 } else {
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;
3656 ri->ri_free++;
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;
3666 else if (xmits > 0)
3667 sc->tulip_txtimer = TULIP_TXTIMER;
3668 sc->tulip_if.if_opackets += xmits;
3669 return xmits;
3672 static void
3673 tulip_print_abnormal_interrupt(
3674 tulip_softc_t * const sc,
3675 u_int32_t csr)
3677 const char * const *msgp = tulip_status_bits;
3678 const char *sep;
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);
3685 sep = ", ";
3688 printf("\n");
3691 static void
3692 tulip_intr_handler(
3693 tulip_softc_t * const sc,
3694 int *progress_p)
3696 u_int32_t csr;
3698 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3699 *progress_p = 1;
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;
3706 } else {
3707 printf(TULIP_PRINTF_FMT ": system error: %s\n",
3708 TULIP_PRINTF_ARGS,
3709 tulip_system_errors[sc->tulip_last_system_error]);
3711 sc->tulip_flags |= TULIP_NEEDRESET;
3712 sc->tulip_system_errors++;
3713 break;
3715 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL)) {
3716 #if defined(TULIP_DEBUG)
3717 sc->tulip_dbg.dbg_link_intrs++;
3718 #endif
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;
3746 tulip_rx_intr(sc);
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;
3760 } else {
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) {
3767 tulip_tx_intr(sc);
3768 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3769 tulip_ifstart(&sc->tulip_if);
3772 if (sc->tulip_flags & TULIP_NEEDRESET) {
3773 tulip_reset(sc);
3774 tulip_init(sc);
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.
3794 static void
3795 tulip_hardintr_handler(
3796 tulip_softc_t * const sc,
3797 int *progress_p)
3799 if (TULIP_CSR_READ(sc, csr_status) & (TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR) == 0)
3800 return;
3801 *progress_p = 1;
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);
3812 static void
3813 tulip_softintr(
3814 void)
3816 u_int32_t softintr_mask, mask;
3817 int progress = 0;
3818 int unit;
3819 tulip_spl_t s;
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
3838 softintr_mask = 0;
3839 tulip_intr_handler(sc, &progress);
3840 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3842 return;
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) {
3853 unit = 0; mask = 1;
3854 } else {
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
3876 tulip_intr_shared(
3877 void *arg)
3879 tulip_softc_t * sc;
3880 int progress = 0;
3882 for (sc = (tulip_softc_t *) arg; sc != NULL; sc = sc->tulip_slaves) {
3883 #if defined(TULIP_DEBUG)
3884 sc->tulip_dbg.dbg_intrs++;
3885 #endif
3886 #if defined(TULIP_USE_SOFTINTR)
3887 tulip_hardintr_handler(sc, &progress);
3888 #else
3889 tulip_intr_handler(sc, &progress);
3890 #endif
3892 #if defined(TULIP_USE_SOFTINTR)
3893 if (progress)
3894 schednetisr(NETISR_DE);
3895 #endif
3896 #if !defined(TULIP_VOID_INTRFUNC)
3897 return progress;
3898 #endif
3901 static tulip_intrfunc_t
3902 tulip_intr_normal(
3903 void *arg)
3905 tulip_softc_t * sc = (tulip_softc_t *) arg;
3906 int progress = 0;
3908 #if defined(TULIP_DEBUG)
3909 sc->tulip_dbg.dbg_intrs++;
3910 #endif
3911 #if defined(TULIP_USE_SOFTINTR)
3912 tulip_hardintr_handler(sc, &progress);
3913 if (progress)
3914 schednetisr(NETISR_DE);
3915 #else
3916 tulip_intr_handler(sc, &progress);
3917 #endif
3918 #if !defined(TULIP_VOID_INTRFUNC)
3919 return progress;
3920 #endif
3924 * This routine is entered at splnet() (splsoftnet() on NetBSD)
3925 * and thereby imposes no problems when TULIP_USE_SOFTINTR is
3926 * defined or not.
3928 static int
3929 tulip_ifioctl(
3930 struct ifnet * const ifp,
3931 ioctl_cmd_t cmd,
3932 void *data)
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;
3937 tulip_spl_t s;
3938 int error = 0;
3940 #if defined(TULIP_USE_SOFTINTR)
3941 s = TULIP_RAISESOFTSPL();
3942 #else
3943 s = TULIP_RAISESPL();
3944 #endif
3945 switch (cmd) {
3946 case SIOCINITIFADDR: {
3947 ifp->if_flags |= IFF_UP;
3948 switch(ifa->ifa_addr->sa_family) {
3949 #ifdef INET
3950 case AF_INET: {
3951 tulip_init(sc);
3952 TULIP_ARP_IFINIT(sc, ifa);
3953 break;
3955 #endif /* INET */
3957 #ifdef NS
3959 * This magic copied from if_is.c; I don't use XNS,
3960 * so I have no way of telling if this actually
3961 * works or not.
3963 case AF_NS: {
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);
3967 } else {
3968 ifp->if_flags &= ~IFF_RUNNING;
3969 memcpy((void *)sc->tulip_enaddr,
3970 (void *)ina->x_host.c_host,
3971 sizeof(sc->tulip_enaddr));
3973 tulip_init(sc);
3974 break;
3976 #endif /* NS */
3978 default: {
3979 tulip_init(sc);
3980 break;
3983 break;
3985 case SIOCSIFFLAGS: {
3986 if ((error = ifioctl_common(ifp, cmd, data)) != 0)
3987 break;
3988 tulip_init(sc);
3989 break;
3992 #if defined(SIOCSIFMEDIA)
3993 case SIOCSIFMEDIA:
3994 case SIOCGIFMEDIA: {
3995 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
3996 break;
3998 #endif
4000 case SIOCADDMULTI:
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 */
4008 tulip_init(sc);
4010 error = 0;
4012 break;
4014 #if defined(SIOCSIFMTU)
4015 #if !defined(ifr_mtu)
4016 #define ifr_mtu ifr_metric
4017 #endif
4018 case SIOCSIFMTU:
4020 * Set the interface MTU.
4022 if (ifr->ifr_mtu > ETHERMTU
4023 #ifdef BIG_PACKET
4024 && sc->tulip_chipid != TULIP_21140
4025 && sc->tulip_chipid != TULIP_21140A
4026 && sc->tulip_chipid != TULIP_21041
4027 #endif
4029 error = EINVAL;
4030 break;
4032 if ((error = ifioctl_common(ifp, cmd, data)) == ENETRESET) {
4033 #ifdef BIG_PACKET
4034 tulip_reset(sc);
4035 tulip_init(sc);
4036 #endif
4037 error = 0;
4039 break;
4040 #endif /* SIOCSIFMTU */
4042 #ifdef SIOCGADDRROM
4043 case SIOCGADDRROM: {
4044 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
4045 break;
4047 #endif
4048 #ifdef SIOCGCHIPID
4049 case SIOCGCHIPID: {
4050 ifr->ifr_metric = (int) sc->tulip_chipid;
4051 break;
4053 #endif
4054 default: {
4055 error = ether_ioctl(ifp, cmd, data);
4056 break;
4060 TULIP_RESTORESPL(s);
4061 return error;
4063 #if 0
4064 static void htnote(char * );
4065 static void htnote(char *s) {
4066 if(hrh_trace)
4067 hrh_check_status(s);
4069 #endif
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.
4076 static ifnet_ret_t
4077 tulip_ifstart(
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)
4087 return;
4089 for (;;) {
4090 tulip_desc_t *eop, *nextout;
4091 int segcnt, free, recopy;
4092 u_int32_t d_status;
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",
4098 TULIP_PRINTF_ARGS);
4099 ifp->if_flags |= IFF_OACTIVE;
4100 return;
4102 #endif
4103 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
4104 ifp->if_flags |= IFF_OACTIVE;
4105 return;
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;
4111 ri->ri_free--;
4112 nextout = ri->ri_nextout;
4113 BEGIN(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);
4120 #ifdef LCLDMA
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");
4128 #else
4129 t.d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
4130 #endif
4131 t.d_length2 = 0;
4132 t.d_addr2 = 0;
4133 END(nextout);
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
4142 * ring.
4144 setstatus(ri->ri_nextout,0);
4145 setstatus(nextout, TULIP_DSTS_OWNER);
4146 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4149 IF_DEQUEUE(ifq, m);
4150 if (m == NULL)
4151 break;
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",
4156 TULIP_PRINTF_ARGS,
4157 (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : "");
4158 ifp->if_flags |= IFF_OACTIVE;
4159 IF_PREPEND(ifq, m);
4160 return;
4162 #endif
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.
4181 d_status = 0;
4182 recopy = 0;
4183 eop = nextout = ri->ri_nextout;
4184 m0 = m;
4185 segcnt = 0;
4186 free = ri->ri_free;
4187 /* Create a chain of descriptors tracking the chain of mbufs */
4188 do {
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;
4194 while (len > 0) {
4195 unsigned slen = min(len, clsize);
4196 #ifdef BIG_PACKET
4197 int partial = 0;
4198 if (slen >= 2048)
4199 slen = 2040, partial = 1;
4200 #endif
4201 segcnt++;
4202 if (segcnt > TULIP_MAX_TXSEG) {
4203 recopy = 1;
4204 next_m0 = NULL; /* to break out of outside loop */
4205 break;
4207 if (segcnt & 1) {
4208 if (--free <= 0) {
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
4213 * mbuf and return.
4215 ifp->if_flags |= IFF_OACTIVE;
4216 IF_PREPEND(ifq, m);
4217 return;
4219 eop = nextout;
4220 if (++nextout == ri->ri_last)
4221 nextout = ri->ri_first;
4222 BEGIN(eop);
4223 t.d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4224 t.d_status = d_status;
4225 #ifdef LCLDMA
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");
4235 #endif
4236 t.d_length1 = slen;
4237 next_m0 = NULL;
4238 #else
4239 t.d_addr1 = TULIP_KVATOPHYS(sc, addr);
4240 t.d_length1 = slen;
4241 #endif
4242 END(eop);
4243 } else {
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;
4253 len -= slen;
4254 addr += slen;
4255 #ifdef BIG_PACKET
4256 if (partial)
4257 continue;
4258 #endif
4259 clsize = PAGE_SIZE;
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.
4268 if (recopy) {
4269 MGETHDR(m0, M_DONTWAIT, MT_DATA);
4270 if (m0 != NULL) {
4271 if (m->m_pkthdr.len > MHLEN) {
4272 MCLGET(m0, M_DONTWAIT);
4273 if ((m0->m_flags & M_EXT) == 0) {
4274 m_freem(m);
4275 m_freem(m0);
4276 continue;
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);
4283 m_freem(m);
4284 continue;
4288 * The descriptors have been filled in. Now get ready
4289 * to transmit.
4291 #if NBPFILTER > 0
4292 if (sc->tulip_bpf != NULL)
4293 TULIP_BPF_MTAP(sc, m);
4294 #endif
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.
4309 BEGIN(eop);
4310 if (segcnt & 1) {
4311 t.d_addr2 = 0;
4312 t.d_length2 = 0;
4316 * Mark the last and first segments, indicate we want a transmit
4317 * complete interrupt, give the descriptors to the TULIP, and tell
4318 * it to transmit!
4320 t.d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
4321 END(eop);
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;
4337 ri->ri_free = free;
4339 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4341 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
4342 ifp->if_flags |= IFF_OACTIVE;
4343 return;
4345 if (sc->tulip_txtimer == 0)
4346 sc->tulip_txtimer = TULIP_TXTIMER;
4348 if (m != NULL) {
4349 ifp->if_flags |= IFF_OACTIVE;
4350 IF_PREPEND(ifq, m);
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.
4361 static void
4362 tulip_ifwatchdog(
4363 struct ifnet *ifp)
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
4377 * them if needed.
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)
4384 tulip_rx_intr(sc);
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);
4406 tulip_reset(sc);
4407 tulip_init(sc);
4410 #if defined(__bsdi__) || (defined(__FreeBSD__) && BSD < 199506)
4411 static ifnet_ret_t
4412 tulip_ifwatchdog_wrapper(
4413 int unit)
4415 tulip_ifwatchdog(&TULIP_UNIT_TO_SOFTC(unit)->tulip_if);
4417 #define tulip_ifwatchdog tulip_ifwatchdog_wrapper
4418 #endif
4421 * All printf's are real as of now!
4423 #ifdef printf
4424 #undef printf
4425 #endif
4426 #if !defined(IFF_NOTRAILERS)
4427 #define IFF_NOTRAILERS 0
4428 #endif
4430 static void
4431 tulip_attach(
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;
4440 ifp->if_timer = 1;
4441 #if (!defined(__bsdi__) || _BSDI_VERSION < 199401) && !defined(__NetBSD__)
4442 ifp->if_output = ether_output;
4443 #endif
4444 #if defined(__bsdi__) && _BSDI_VERSION < 199401
4445 ifp->if_mtu = ETHERMTU;
4446 #endif
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);
4454 printf("\n");
4455 sc->tulip_pf = aprint_normal;
4456 aprint_normal(TULIP_PRINTF_FMT ": address " TULIP_EADDR_FMT "\n",
4457 TULIP_PRINTF_ARGS,
4458 TULIP_EADDR_ARGS(sc->tulip_enaddr));
4459 #else
4460 printf(
4461 #if defined(__bsdi__)
4462 "\n"
4463 #endif
4464 TULIP_PRINTF_FMT ": %s%s pass %d.%d\n",
4465 TULIP_PRINTF_ARGS,
4466 sc->tulip_boardid,
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",
4471 TULIP_PRINTF_ARGS,
4472 TULIP_EADDR_ARGS(sc->tulip_enaddr));
4473 #endif
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;
4483 #endif
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);
4492 tulip_reset(sc);
4494 #if defined(__bsdi__) && _BSDI_VERSION >= 199510
4495 sc->tulip_pf = printf;
4496 TULIP_ETHER_IFATTACH(sc);
4497 #else
4498 if_attach(ifp);
4499 #if defined(__NetBSD__) || (defined(__FreeBSD__) && BSD >= 199506)
4500 TULIP_ETHER_IFATTACH(sc);
4501 #endif
4502 #endif /* __bsdi__ */
4505 static void
4506 tulip_initcsrs(
4507 tulip_softc_t * const sc,
4508 tulip_csrptr_t csr_base,
4509 size_t csr_size)
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;
4529 #endif
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;
4546 void *
4547 lcl_dma_ram_next(int size)
4549 static void *first;
4550 void *t;
4552 if (first==0L /* || size==-1 */) {
4553 first = LCLDMAstart;
4555 t = first;
4556 first += size;
4557 if (first > LCLDMAstart + lclpcisize) {
4558 #ifdef TULIP_DEBUG
4559 printf("first=%p LCLDMAstart=%p lclpcisize=%p\n",
4560 first, LCLDMAstart, lclpcisize);
4561 #endif
4562 panic("tulip lcldma next");
4564 return t;
4567 static char *lcl_dma_retrace;
4569 void lcl_dma_start_check(void);
4570 void
4571 lcl_dma_start_check(void)
4573 lcl_dma_retrace = LCLDMAstart;
4576 void *lcl_dma_ram_next_check(int);
4577 void *
4578 lcl_dma_ram_next_check(int size)
4580 void *t = lcl_dma_retrace;
4581 lcl_dma_retrace += size;
4582 return t;
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
4588 * buffer addresses.
4590 #ifdef LCLDMA
4591 tulip_softc_t *debug_sc;
4592 #if 0
4593 static void a12pbs(tulip_softc_t * const sc, u_int32_t *base, void *kva) {
4594 u_int32_t p;
4596 p = a12map(TULIP_KVATOPHYS(sc,kva));
4597 a12r2pb(&p, base, sizeof(p));
4599 #endif
4601 static void
4602 tulip_initring(
4603 tulip_softc_t * const sc,
4604 tulip_ringinfo_t * const ri,
4605 tulip_desc_t *descs,
4606 void **kvalist,
4607 int ndescs)
4609 int i, dsize = sizeof descs[0] * ndescs;
4611 debug_sc = sc;
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;
4626 END(ri->ri_last-1);
4627 dumpring(kvalist);
4630 static void dumpring(void **kvalist) {
4631 #if 0
4632 long *d = (long *)0xfffffc8020000000L;
4633 int k;
4635 for(k=0; k<10; ++k)
4636 printf("kvalist[%d] = %16lx\n", k, kvalist[k]);
4637 for(k=0; k<20; ++k)
4638 printf("%03x: %16lx %16lx %16lx %16lx\n",
4639 k*4*8,
4640 d[k*4],
4641 d[k*4+1],
4642 d[k*4+2],
4643 d[k*4+3]);
4644 #endif
4649 * This doesn't do anything other than check that the ring hasn't been
4650 * changed since tulip_pci_attach()
4652 static void
4653 tulip_ring_reset(
4654 tulip_softc_t * const sc,
4655 tulip_ringinfo_t * const ri,
4656 tulip_desc_t *descs,
4657 void **kvalist,
4658 int ndescs)
4660 int i;
4661 int q;
4662 tulip_desc_t *t;
4664 t = 0; /* -Wall */
4665 for(i=q=0; i<ndescs; ++i) {
4666 if (q) {
4667 printf("d_flag %d = %x\n", i-1, t->d_flag);
4668 goto die;
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",
4673 &t->d_addr1,
4674 t->d_addr1,
4675 a12map(TULIP_KVATOPHYS(sc,kvalist[i])));
4676 dumpring(kvalist);
4677 goto die;
4679 if (t->d_addr2) {
4680 printf("t->d_addr2=%x\n",t->d_addr2);
4681 goto die;
4683 q = t->d_flag & TULIP_DFLAG_ENDRING;
4685 if (q)
4686 return;
4687 printf("final d_flag = %x\n", t->d_flag);
4688 die: panic("tulip ring corrupted");
4691 static void
4692 reset_lcl_dma(tulip_softc_t * const sc)
4694 tulip_ring_reset(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, sc->tulip_rx_kva,
4695 TULIP_RXDESCS);
4696 tulip_ring_reset(sc, &sc->tulip_txinfo, sc->tulip_txdescs, sc->tulip_tx_kva,
4697 TULIP_TXDESCS);
4699 #else
4700 static void
4701 tulip_initring( /* the usual case */
4702 tulip_softc_t * const sc,
4703 tulip_ringinfo_t * const ri,
4704 tulip_desc_t *descs,
4705 void **kvalist;
4706 int ndescs)
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;
4714 #endif
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 };
4733 #endif
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);
4743 static int
4744 tulip_pci_shutdown(
4745 struct kern_devconf * const kdc,
4746 int force)
4748 if (kdc->kdc_unit < TULIP_MAX_DEVICES) {
4749 tulip_softc_t * const sc = TULIP_UNIT_TO_SOFTC(kdc->kdc_unit);
4750 if (sc != NULL)
4751 tulip_shutdown(0, sc);
4753 (void) dev_detach(kdc);
4754 return 0;
4756 #endif
4758 static char*
4759 tulip_pci_probe(
4760 pcici_t config_id,
4761 pcidi_t device_id)
4763 if (cputype != ST_AVALON_A12) /* XXX */
4764 return NULL;
4765 if (PCI_VENDORID(device_id) != DEC_VENDORID)
4766 return NULL;
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";
4775 else
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";
4782 else
4783 return "Digital 21142 Fast Ethernet";
4785 return NULL;
4788 static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS);
4789 static u_long tulip_pci_count;
4791 struct pci_device adedevice = {
4792 "ade",
4793 tulip_pci_probe,
4794 tulip_pci_attach,
4795 &tulip_pci_count,
4796 #if defined(TULIP_DEVCONF)
4797 tulip_pci_shutdown,
4798 #endif
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
4808 static int
4809 tulip_pci_match(
4810 pci_devaddr_t *pa)
4812 int irq;
4813 unsigned id;
4815 id = pci_inl(pa, PCI_VENDOR_ID);
4816 if (PCI_VENDORID(id) != DEC_VENDORID)
4817 return 0;
4818 id = PCI_CHIPID(id);
4819 if (id != CHIPID_21040 && id != CHIPID_21041
4820 && id != CHIPID_21140 && id != CHIPID_21142)
4821 return 0;
4822 irq = pci_inl(pa, PCI_I_LINE) & 0xFF;
4823 if (irq == 0 || irq >= 16) {
4824 printf("ade?: invalid IRQ %d; skipping\n", irq);
4825 return 0;
4827 return 1;
4830 static int
4831 tulip_probe(
4832 struct device *parent,
4833 struct cfdata *cf,
4834 void *aux)
4836 struct isa_attach_args * const ia = (struct isa_attach_args *) aux;
4837 unsigned irq, slot;
4838 pci_devaddr_t *pa;
4840 #if _BSDI_VERSION >= 199401
4841 switch (ia->ia_bustype) {
4842 case BUS_PCI:
4843 #endif
4844 pa = pci_scan(tulip_pci_match);
4845 if (pa == NULL)
4846 return 0;
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;
4853 ia->ia_msize = 0;
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);
4861 #else
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);
4866 ia->ia_iobase = 0;
4867 ia->ia_iosize = 0;
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
4875 break;
4877 #if defined(TULIP_EISA)
4878 case BUS_EISA: {
4879 unsigned tmp;
4881 if ((slot = eisa_match(cf, ia)) == 0)
4882 return 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.
4892 if ((tmp & 1) == 0)
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));
4900 ia->ia_aux = NULL;
4901 break;
4903 #endif /* TULIP_EISA */
4904 default:
4905 return 0;
4907 #endif
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",
4915 cf->cf_unit,
4916 ffs(ia->ia_irq) - 1, ffs(irq) - 1);
4917 return 0;
4919 if (ia->ia_irq == IRQUNK)
4920 ia->ia_irq = irq;
4921 #ifdef IRQSHARE
4922 ia->ia_irq |= IRQSHARE;
4923 #endif
4924 return 1;
4927 static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS);
4929 #if defined(TULIP_EISA)
4930 static char *tulip_eisa_ids[] = {
4931 "DEC4250",
4932 NULL
4934 #endif
4936 struct cfdriver decd = {
4937 0, "ade", tulip_probe, tulip_pci_attach,
4938 #if _BSDI_VERSION >= 199401
4939 DV_IFNET,
4940 #endif
4941 sizeof(tulip_softc_t),
4942 #if defined(TULIP_EISA)
4943 tulip_eisa_ids
4944 #endif
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
4952 static int
4953 tulip_pci_probe(
4954 struct device *parent,
4955 struct cfdata *match,
4956 void *aux)
4958 struct pci_attach_args *pa = (struct pci_attach_args *) aux;
4960 if (PCI_VENDORID(pa->pa_id) != DEC_VENDORID)
4961 return 0;
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)
4966 return 1;
4968 return 0;
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__ */
4978 static void
4979 tulip_shutdown(
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) */
4989 static void
4990 tulip_pci_attach(
4991 TULIP_PCI_ATTACH_ARGS)
4993 #if defined(__FreeBSD__)
4994 tulip_softc_t *sc;
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 */
4999 #endif
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))
5009 #endif
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
5015 bus_addr_t regbase;
5016 bus_size_t regsize;
5017 int cacheable;
5018 #else
5019 #ifdef PCI_PREFER_IOSPACE
5020 error error error error
5021 #endif
5022 #endif
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; \
5030 } while (0)
5031 #endif /* __NetBSD__ */
5032 int retval, idx;
5033 u_int32_t revinfo, cfdainfo, id;
5034 #if !defined(TULIP_IOMAPPED) && defined(__FreeBSD__)
5035 paddr_t pa_csrs;
5036 #endif
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) {
5043 #ifdef __FreeBSD__
5044 printf("ade%d", unit);
5045 #endif
5046 printf(": not configured; limit of %d reached or exceeded\n",
5047 TULIP_MAX_DEVICES);
5048 return;
5051 #if defined(__bsdi__)
5052 if (pa != NULL) {
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)
5057 } else {
5058 revinfo = inl(ia->ia_iobase + DE425_CFRV) & 0xFF;
5059 csroffset = TULIP_EISA_CSROFFSET;
5060 csrsize = TULIP_EISA_CSRSIZE;
5061 chipid = TULIP_DE425;
5062 cfdainfo = 0;
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)
5082 return;
5084 if ((chipid == TULIP_21040 || chipid == TULIP_DE425) && revinfo < 0x20) {
5085 #ifdef __FreeBSD__
5086 printf("ade%d", unit);
5087 #endif
5088 printf(": not configured; 21040 pass 2.0 required (%d.%d found)\n",
5089 revinfo >> 4, revinfo & 0x0f);
5090 return;
5091 } else if (chipid == TULIP_21140 && revinfo < 0x11) {
5092 #ifndef __FreeBSD__
5093 printf("\n");
5094 #endif
5095 printf("ade%d: not configured; 21140 pass 1.1 required (%d.%d found)\n",
5096 unit, revinfo >> 4, revinfo & 0x0f);
5097 return;
5100 #if defined(__FreeBSD__)
5101 sc = (tulip_softc_t *) malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT);
5102 if (sc == NULL)
5103 return;
5104 memset(sc, 0, sizeof(*sc)); /* Zero out the softc*/
5105 #endif
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);
5130 DELAY(11*1000);
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
5137 * force a probe.
5139 switch ((cfdainfo >> 8) & 0xff) {
5140 case 1: sc->tulip_media = chipid > TULIP_DE425 ? TULIP_MEDIA_AUI : TULIP_MEDIA_AUIBNC;
5141 break;
5142 case 2: sc->tulip_media = chipid > TULIP_DE425 ? TULIP_MEDIA_BNC : TULIP_MEDIA_UNKNOWN;
5143 break;
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;
5149 #endif
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;
5156 #else
5157 sc->tulip_unit = unit;
5158 sc->tulip_name = "ade";
5159 #endif
5160 sc->tulip_revinfo = revinfo;
5161 #if defined(__FreeBSD__)
5162 #if BSD >= 199506
5163 sc->tulip_if.if_softc = sc;
5164 #endif
5165 #if defined(TULIP_IOMAPPED)
5166 retval = pci_map_port(config_id, PCI_CBIO, &csr_base);
5167 #else
5168 retval = pci_map_mem(config_id, PCI_CBMA, (vaddr_t *) &csr_base, &pa_csrs);
5169 #endif
5170 if (!retval) {
5171 free((void *) sc, M_DEVBUF);
5172 return;
5174 tulips[unit] = sc;
5175 #endif /* __FreeBSD__ */
5177 #if defined(__bsdi__)
5178 sc->tulip_pf = printf;
5179 #if defined(TULIP_IOMAPPED)
5180 csr_base = ia->ia_iobase;
5181 #else
5182 csr_base = (vaddr_t) mapphys((vaddr_t) ia->ia_maddr, ia->ia_msize);
5183 #endif
5184 #endif /* __bsdi__ */
5186 #if defined(__NetBSD__)
5187 csr_base = 0;
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;
5191 cacheable = 0;
5192 if (pci_io_find(pa->pa_pc, pa->pa_tag, PCI_CBIO, &regbase, &regsize))
5193 return;
5194 #else
5195 sc->tulip_bustag = pa->pa_memt;
5196 if (pci_mem_find(pa->pa_pc, pa->pa_tag, PCI_CBMA, &regbase, &regsize, &cacheable))
5197 return;
5198 #endif
5199 if (bus_space_map(sc->tulip_bustag, regbase, regsize, cacheable, &sc->tulip_bushandle))
5200 return;
5201 #else
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");
5219 return;
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;
5226 } else {
5227 sc->tulip_bustag = memt, sc->tulip_bushandle = memh;
5229 #else
5230 if (cfcs & PCI_COMMAND_MEM_ENABLE) {
5231 sc->tulip_bustag = memt, sc->tulip_bushandle = memh;
5232 } else {
5233 sc->tulip_bustag = iot, sc->tulip_bushandle = ioh;
5235 #endif /* PCI_PREFER_IOSPACE */
5237 #endif
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 */
5245 lcl_dma_restart();
5246 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, sc->tulip_rx_kva,
5247 TULIP_RXDESCS);
5248 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, sc->tulip_tx_kva,
5249 TULIP_TXDESCS);
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);
5262 #endif
5263 printf(": can't read ENET ROM (why=%d) (", retval);
5264 for (idx = 0; idx < 32; idx++)
5265 printf("%02x", sc->tulip_rombuf[idx]);
5266 printf("\n");
5267 printf(TULIP_PRINTF_FMT ": %s%s pass %d.%d\n",
5268 TULIP_PRINTF_ARGS,
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);
5272 } else {
5273 tulip_spl_t s;
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");
5286 return;
5288 intrstr = pci_intr_string(pa->pa_pc, intrhandle);
5289 sc->tulip_ih = pci_intr_establish(pa->pa_pc, intrhandle, IPL_NET,
5290 intr_rtn, sc);
5291 if (sc->tulip_ih == NULL)
5292 printf(": couldn't establish interrupt");
5293 if (intrstr != NULL)
5294 printf(" at %s", intrstr);
5295 printf("\n");
5296 if (sc->tulip_ih == NULL)
5297 return;
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",
5302 sc->tulip_xname);
5303 #endif
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",
5308 TULIP_PRINTF_ARGS);
5309 return;
5312 #if !defined(TULIP_DEVCONF)
5313 at_shutdown(tulip_shutdown, sc, SHUTDOWN_POST_SYNC);
5314 #endif
5315 #endif
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);
5328 #endif
5329 #if defined(TULIP_USE_SOFTINTR)
5330 if (sc->tulip_unit > tulip_softintr_max_unit)
5331 tulip_softintr_max_unit = sc->tulip_unit;
5332 #endif
5334 s = TULIP_RAISESPL();
5335 tulip_reset(sc);
5336 tulip_attach(sc);
5337 TULIP_RESTORESPL(s);
5341 static void
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);