Deleted Added
sdiff udiff text old ( 72012 ) new ( 72084 )
full compact
1/* $NetBSD: if_de.c,v 1.86 1999/06/01 19:17:59 thorpej Exp $ */
2
3/* $FreeBSD: head/sys/dev/de/if_de.c 72084 2001-02-06 10:12:15Z phk $ */
4
5/*-
6 * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com)
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software withough specific prior written permission
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Id: if_de.c,v 1.94 1997/07/03 16:55:07 thomas Exp
29 *
30 */
31
32/*
33 * DEC 21040 PCI Ethernet Controller
34 *
35 * Written by Matt Thomas
36 * BPF support code stolen directly from if_ec.c
37 *
38 * This driver supports the DEC DE435 or any other PCI
39 * board which support 21040, 21041, or 21140 (mostly).
40 */
41#define TULIP_HDR_DATA
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/mbuf.h>
46#include <sys/socket.h>
47#include <sys/sockio.h>
48#include <sys/malloc.h>
49#include <sys/kernel.h>
50#include <sys/eventhandler.h>
51#include <machine/bus.h>
52#include <machine/resource.h>
53#include <sys/bus.h>
54#include <sys/rman.h>
55
56#include <net/if.h>
57#include <net/if_arp.h>
58#include <net/ethernet.h>
59#include <net/if_media.h>
60#include <net/if_dl.h>
61#ifdef TULIP_USE_SOFTINTR
62#include <net/netisr.h>
63#endif
64
65#include <net/bpf.h>
66
67#ifdef INET
68#include <netinet/in.h>
69#include <netinet/if_ether.h>
70#endif
71
72#include <vm/vm.h>
73
74#include <net/if_var.h>
75#include <vm/pmap.h>
76#include <pci/pcivar.h>
77#include <pci/pcireg.h>
78#include <pci/dc21040reg.h>
79
80/*
81 * Intel CPUs should use I/O mapped access.
82 */
83#if defined(__i386__)
84#define TULIP_IOMAPPED
85#endif
86
87#if 0
88/*
89 * This turns on all sort of debugging stuff and make the
90 * driver much larger.
91 */
92#define TULIP_DEBUG
93#endif
94
95#if 0
96#define TULIP_PERFSTATS
97#endif
98
99#if 0
100#define TULIP_USE_SOFTINTR
101#endif
102
103#define TULIP_HZ 10
104
105#include <pci/if_devar.h>
106
107/*
108 * This module supports
109 * the DEC 21040 PCI Ethernet Controller.
110 * the DEC 21041 PCI Ethernet Controller.
111 * the DEC 21140 PCI Fast Ethernet Controller.
112 */
113static void tulip_mii_autonegotiate(tulip_softc_t * const sc, const unsigned phyaddr);
114static void tulip_intr_shared(void *arg);
115static void tulip_intr_normal(void *arg);
116static void tulip_init(tulip_softc_t * const sc);
117static void tulip_ifinit(void *);
118static void tulip_reset(tulip_softc_t * const sc);
119static void tulip_ifstart_one(struct ifnet *ifp);
120static void tulip_ifstart(struct ifnet *ifp);
121static struct mbuf *tulip_txput(tulip_softc_t * const sc, struct mbuf *m);
122static void tulip_txput_setup(tulip_softc_t * const sc);
123static void tulip_rx_intr(tulip_softc_t * const sc);
124static void tulip_addr_filter(tulip_softc_t * const sc);
125static unsigned tulip_mii_readreg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno);
126static void tulip_mii_writereg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno, unsigned data);
127static int tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities);
128static tulip_media_t tulip_mii_phy_readspecific(tulip_softc_t * const sc);
129static int tulip_srom_decode(tulip_softc_t * const sc);
130static int tulip_ifmedia_change(struct ifnet * const ifp);
131static void tulip_ifmedia_status(struct ifnet * const ifp, struct ifmediareq *req);
132/* static void tulip_21140_map_media(tulip_softc_t *sc); */
133
134static void
135tulip_timeout_callback(
136 void *arg)
137{
138 tulip_softc_t * const sc = arg;
139 int s = splimp();
140
141 TULIP_PERFSTART(timeout)
142
143 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING;
144 sc->tulip_probe_timeout -= 1000 / TULIP_HZ;
145 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER);
146
147 TULIP_PERFEND(timeout);
148 splx(s);
149}
150
151static void
152tulip_timeout(
153 tulip_softc_t * const sc)
154{
155 if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
156 return;
157 sc->tulip_flags |= TULIP_TIMEOUTPENDING;
158 timeout(tulip_timeout_callback, sc, (hz + TULIP_HZ / 2) / TULIP_HZ);
159}
160
161#if defined(TULIP_NEED_FASTTIMEOUT)
162static void
163tulip_fasttimeout_callback(
164 void *arg)
165{
166 tulip_softc_t * const sc = arg;
167 int s = splimp();
168
169 sc->tulip_flags &= ~TULIP_FASTTIMEOUTPENDING;
170 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_FASTTIMER);
171 splx(s);
172}
173
174static void
175tulip_fasttimeout(
176 tulip_softc_t * const sc)
177{
178 if (sc->tulip_flags & TULIP_FASTTIMEOUTPENDING)
179 return;
180 sc->tulip_flags |= TULIP_FASTTIMEOUTPENDING;
181 timeout(tulip_fasttimeout_callback, sc, 1);
182}
183#endif
184
185static int
186tulip_txprobe(
187 tulip_softc_t * const sc)
188{
189 struct mbuf *m;
190 /*
191 * Before we are sure this is the right media we need
192 * to send a small packet to make sure there's carrier.
193 * Strangely, BNC and AUI will "see" receive data if
194 * either is connected so the transmit is the only way
195 * to verify the connectivity.
196 */
197 MGETHDR(m, M_DONTWAIT, MT_DATA);
198 if (m == NULL)
199 return 0;
200 /*
201 * Construct a LLC TEST message which will point to ourselves.
202 */
203 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_dhost, 6);
204 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_shost, 6);
205 mtod(m, struct ether_header *)->ether_type = htons(3);
206 mtod(m, unsigned char *)[14] = 0;
207 mtod(m, unsigned char *)[15] = 0;
208 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
209 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
210 /*
211 * send it!
212 */
213 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
214 sc->tulip_intrmask |= TULIP_STS_TXINTR;
215 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
216 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
217 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
218 if ((m = tulip_txput(sc, m)) != NULL)
219 m_freem(m);
220 sc->tulip_probe.probe_txprobes++;
221 return 1;
222}
223
224#ifdef BIG_PACKET
225#define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0)
226#else
227#define TULIP_SIAGEN_WATCHDOG 0
228#endif
229
230static void
231tulip_media_set(
232 tulip_softc_t * const sc,
233 tulip_media_t media)
234{
235 const tulip_media_info_t *mi = sc->tulip_mediums[media];
236
237 if (mi == NULL)
238 return;
239
240 /*
241 * If we are switching media, make sure we don't think there's
242 * any stale RX activity
243 */
244 sc->tulip_flags &= ~TULIP_RXACT;
245 if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
246 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
247 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx);
248 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
249 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
250 DELAY(50);
251 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
252 } else {
253 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
254 }
255 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity);
256 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
257#define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL)
258 /*
259 * If the cmdmode bits don't match the currently operating mode,
260 * set the cmdmode appropriately and reset the chip.
261 */
262 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
263 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
264 sc->tulip_cmdmode |= mi->mi_cmdmode;
265 tulip_reset(sc);
266 }
267 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
268 DELAY(10);
269 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata);
270 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
271 /*
272 * If the cmdmode bits don't match the currently operating mode,
273 * set the cmdmode appropriately and reset the chip.
274 */
275 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
276 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
277 sc->tulip_cmdmode |= mi->mi_cmdmode;
278 tulip_reset(sc);
279 }
280 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol);
281 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata);
282 } else if (mi->mi_type == TULIP_MEDIAINFO_MII
283 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) {
284 int idx;
285 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
286 const u_int8_t *dp;
287 dp = &sc->tulip_rombuf[mi->mi_reset_offset];
288 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) {
289 DELAY(10);
290 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
291 }
292 sc->tulip_phyaddr = mi->mi_phyaddr;
293 dp = &sc->tulip_rombuf[mi->mi_gpr_offset];
294 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) {
295 DELAY(10);
296 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
297 }
298 } else {
299 for (idx = 0; idx < mi->mi_reset_length; idx++) {
300 DELAY(10);
301 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]);
302 }
303 sc->tulip_phyaddr = mi->mi_phyaddr;
304 for (idx = 0; idx < mi->mi_gpr_length; idx++) {
305 DELAY(10);
306 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]);
307 }
308 }
309 if (sc->tulip_flags & TULIP_TRYNWAY) {
310 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
311 } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
312 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL);
313 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE);
314 sc->tulip_flags &= ~TULIP_DIDNWAY;
315 if (TULIP_IS_MEDIA_FD(media))
316 data |= PHYCTL_FULL_DUPLEX;
317 if (TULIP_IS_MEDIA_100MB(media))
318 data |= PHYCTL_SELECT_100MB;
319 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data);
320 }
321 }
322}
323
324static void
325tulip_linkup(
326 tulip_softc_t * const sc,
327 tulip_media_t media)
328{
329 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
330 sc->tulip_flags |= TULIP_PRINTLINKUP;
331 sc->tulip_flags |= TULIP_LINKUP;
332 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
333#if 0 /* XXX how does with work with ifmedia? */
334 if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
335 if (sc->tulip_if.if_flags & IFF_FULLDUPLEX) {
336 if (TULIP_CAN_MEDIA_FD(media)
337 && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL)
338 media = TULIP_FD_MEDIA_OF(media);
339 } else {
340 if (TULIP_IS_MEDIA_FD(media)
341 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL)
342 media = TULIP_HD_MEDIA_OF(media);
343 }
344 }
345#endif
346 if (sc->tulip_media != media) {
347#ifdef TULIP_DEBUG
348 sc->tulip_dbg.dbg_last_media = sc->tulip_media;
349#endif
350 sc->tulip_media = media;
351 sc->tulip_flags |= TULIP_PRINTMEDIA;
352 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) {
353 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
354 } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) {
355 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
356 }
357 }
358 /*
359 * We could set probe_timeout to 0 but setting to 3000 puts this
360 * in one central place and the only matters is tulip_link is
361 * followed by a tulip_timeout. Therefore setting it should not
362 * result in aberrant behavour.
363 */
364 sc->tulip_probe_timeout = 3000;
365 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
366 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY);
367 if (sc->tulip_flags & TULIP_INRESET) {
368 tulip_media_set(sc, sc->tulip_media);
369 } else if (sc->tulip_probe_media != sc->tulip_media) {
370 /*
371 * No reason to change media if we have the right media.
372 */
373 tulip_reset(sc);
374 }
375 tulip_init(sc);
376}
377
378static void
379tulip_media_print(
380 tulip_softc_t * const sc)
381{
382 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
383 return;
384 if (sc->tulip_flags & TULIP_PRINTMEDIA) {
385 printf("%s%d: enabling %s port\n",
386 sc->tulip_name, sc->tulip_unit,
387 tulip_mediums[sc->tulip_media]);
388 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
389 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
390 printf("%s%d: link up\n", sc->tulip_name, sc->tulip_unit);
391 sc->tulip_flags &= ~TULIP_PRINTLINKUP;
392 }
393}
394
395#if defined(TULIP_DO_GPR_SENSE)
396static tulip_media_t
397tulip_21140_gpr_media_sense(
398 tulip_softc_t * const sc)
399{
400 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
401 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
402 tulip_media_t media;
403
404 /*
405 * If one of the media blocks contained a default media flag,
406 * use that.
407 */
408 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
409 const tulip_media_info_t *mi;
410 /*
411 * Media is not supported (or is full-duplex).
412 */
413 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media))
414 continue;
415 if (mi->mi_type != TULIP_MEDIAINFO_GPR)
416 continue;
417
418 /*
419 * Remember the media is this is the "default" media.
420 */
421 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
422 maybe_media = media;
423
424 /*
425 * No activity mask? Can't see if it is active if there's no mask.
426 */
427 if (mi->mi_actmask == 0)
428 continue;
429
430 /*
431 * Does the activity data match?
432 */
433 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
434 continue;
435
436#if defined(TULIP_DEBUG)
437 printf("%s%d: gpr_media_sense: %s: 0x%02x & 0x%02x == 0x%02x\n",
438 sc->tulip_name, sc->tulip_unit, tulip_mediums[media],
439 TULIP_CSR_READ(sc, csr_gp) & 0xFF,
440 mi->mi_actmask, mi->mi_actdata);
441#endif
442 /*
443 * It does! If this is the first media we detected, then
444 * remember this media. If isn't the first, then there were
445 * multiple matches which we equate to no match (since we don't
446 * which to select (if any).
447 */
448 if (last_media == TULIP_MEDIA_UNKNOWN) {
449 last_media = media;
450 } else if (last_media != media) {
451 last_media = TULIP_MEDIA_UNKNOWN;
452 }
453 }
454 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
455}
456#endif /* TULIP_DO_GPR_SENSE */
457
458static tulip_link_status_t
459tulip_media_link_monitor(
460 tulip_softc_t * const sc)
461{
462 const tulip_media_info_t * const mi = sc->tulip_mediums[sc->tulip_media];
463 tulip_link_status_t linkup = TULIP_LINK_DOWN;
464
465 if (mi == NULL) {
466#if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
467 panic("tulip_media_link_monitor: %s: botch at line %d\n",
468 tulip_mediums[sc->tulip_media],__LINE__);
469#endif
470 return TULIP_LINK_UNKNOWN;
471 }
472
473
474 /*
475 * Have we seen some packets? If so, the link must be good.
476 */
477 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) {
478 sc->tulip_flags &= ~TULIP_RXACT;
479 sc->tulip_probe_timeout = 3000;
480 return TULIP_LINK_UP;
481 }
482
483 sc->tulip_flags &= ~TULIP_RXACT;
484 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
485 u_int32_t status;
486 /*
487 * Read the PHY status register.
488 */
489 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
490 if (status & PHYSTS_AUTONEG_DONE) {
491 /*
492 * If the PHY has completed autonegotiation, see the if the
493 * remote systems abilities have changed. If so, upgrade or
494 * downgrade as appropriate.
495 */
496 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
497 abilities = (abilities << 6) & status;
498 if (abilities != sc->tulip_abilities) {
499#if defined(TULIP_DEBUG)
500 loudprintf("%s%d(phy%d): autonegotiation changed: 0x%04x -> 0x%04x\n",
501 sc->tulip_name, sc->tulip_unit, sc->tulip_phyaddr,
502 sc->tulip_abilities, abilities);
503#endif
504 if (tulip_mii_map_abilities(sc, abilities)) {
505 tulip_linkup(sc, sc->tulip_probe_media);
506 return TULIP_LINK_UP;
507 }
508 /*
509 * if we had selected media because of autonegotiation,
510 * we need to probe for the new media.
511 */
512 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
513 if (sc->tulip_flags & TULIP_DIDNWAY)
514 return TULIP_LINK_DOWN;
515 }
516 }
517 /*
518 * The link is now up. If was down, say its back up.
519 */
520 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP)
521 linkup = TULIP_LINK_UP;
522 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
523 /*
524 * No activity sensor? Assume all's well.
525 */
526 if (mi->mi_actmask == 0)
527 return TULIP_LINK_UNKNOWN;
528 /*
529 * Does the activity data match?
530 */
531 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata)
532 linkup = TULIP_LINK_UP;
533 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
534 /*
535 * Assume non TP ok for now.
536 */
537 if (!TULIP_IS_MEDIA_TP(sc->tulip_media))
538 return TULIP_LINK_UNKNOWN;
539 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
540 linkup = TULIP_LINK_UP;
541#if defined(TULIP_DEBUG)
542 if (sc->tulip_probe_timeout <= 0)
543 printf("%s%d: sia status = 0x%08x\n", sc->tulip_name,
544 sc->tulip_unit, TULIP_CSR_READ(sc, csr_sia_status));
545#endif
546 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
547 return TULIP_LINK_UNKNOWN;
548 }
549 /*
550 * We will wait for 3 seconds until the link goes into suspect mode.
551 */
552 if (sc->tulip_flags & TULIP_LINKUP) {
553 if (linkup == TULIP_LINK_UP)
554 sc->tulip_probe_timeout = 3000;
555 if (sc->tulip_probe_timeout > 0)
556 return TULIP_LINK_UP;
557
558 sc->tulip_flags &= ~TULIP_LINKUP;
559 printf("%s%d: link down: cable problem?\n", sc->tulip_name, sc->tulip_unit);
560 }
561#if defined(TULIP_DEBUG)
562 sc->tulip_dbg.dbg_link_downed++;
563#endif
564 return TULIP_LINK_DOWN;
565}
566
567static void
568tulip_media_poll(
569 tulip_softc_t * const sc,
570 tulip_mediapoll_event_t event)
571{
572#if defined(TULIP_DEBUG)
573 sc->tulip_dbg.dbg_events[event]++;
574#endif
575 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
576 && event == TULIP_MEDIAPOLL_TIMER) {
577 switch (tulip_media_link_monitor(sc)) {
578 case TULIP_LINK_DOWN: {
579 /*
580 * Link Monitor failed. Probe for new media.
581 */
582 event = TULIP_MEDIAPOLL_LINKFAIL;
583 break;
584 }
585 case TULIP_LINK_UP: {
586 /*
587 * Check again soon.
588 */
589 tulip_timeout(sc);
590 return;
591 }
592 case TULIP_LINK_UNKNOWN: {
593 /*
594 * We can't tell so don't bother.
595 */
596 return;
597 }
598 }
599 }
600
601 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
602 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
603 if (TULIP_DO_AUTOSENSE(sc)) {
604#if defined(TULIP_DEBUG)
605 sc->tulip_dbg.dbg_link_failures++;
606#endif
607 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
608 if (sc->tulip_if.if_flags & IFF_UP)
609 tulip_reset(sc); /* restart probe */
610 }
611 return;
612 }
613#if defined(TULIP_DEBUG)
614 sc->tulip_dbg.dbg_link_pollintrs++;
615#endif
616 }
617
618 if (event == TULIP_MEDIAPOLL_START) {
619 sc->tulip_if.if_flags |= IFF_OACTIVE;
620 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
621 return;
622 sc->tulip_probe_mediamask = 0;
623 sc->tulip_probe_passes = 0;
624#if defined(TULIP_DEBUG)
625 sc->tulip_dbg.dbg_media_probes++;
626#endif
627 /*
628 * If the SROM contained an explicit media to use, use it.
629 */
630 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX);
631 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS;
632 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
633 /*
634 * connidx is defaulted to a media_unknown type.
635 */
636 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media;
637 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) {
638 tulip_linkup(sc, sc->tulip_probe_media);
639 tulip_timeout(sc);
640 return;
641 }
642
643 if (sc->tulip_features & TULIP_HAVE_GPR) {
644 sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
645 sc->tulip_probe_timeout = 2000;
646 } else {
647 sc->tulip_probe_media = TULIP_MEDIA_MAX;
648 sc->tulip_probe_timeout = 0;
649 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
650 }
651 }
652
653 /*
654 * Ignore txprobe failures or spurious callbacks.
655 */
656 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED
657 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) {
658 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
659 return;
660 }
661
662 /*
663 * If we really transmitted a packet, then that's the media we'll use.
664 */
665 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) {
666 if (event == TULIP_MEDIAPOLL_LINKPASS) {
667 /* XXX Check media status just to be sure */
668 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
669#if defined(TULIP_DEBUG)
670 } else {
671 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
672#endif
673 }
674 tulip_linkup(sc, sc->tulip_probe_media);
675 tulip_timeout(sc);
676 return;
677 }
678
679 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) {
680#if defined(TULIP_DO_GPR_SENSE)
681 /*
682 * Check for media via the general purpose register.
683 *
684 * Try to sense the media via the GPR. If the same value
685 * occurs 3 times in a row then just use that.
686 */
687 if (sc->tulip_probe_timeout > 0) {
688 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
689#if defined(TULIP_DEBUG)
690 printf("%s%d: media_poll: gpr sensing = %s\n",
691 sc->tulip_name, sc->tulip_unit, tulip_mediums[new_probe_media]);
692#endif
693 if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
694 if (new_probe_media == sc->tulip_probe_media) {
695 if (--sc->tulip_probe_count == 0)
696 tulip_linkup(sc, sc->tulip_probe_media);
697 } else {
698 sc->tulip_probe_count = 10;
699 }
700 }
701 sc->tulip_probe_media = new_probe_media;
702 tulip_timeout(sc);
703 return;
704 }
705#endif /* TULIP_DO_GPR_SENSE */
706 /*
707 * Brute force. We cycle through each of the media types
708 * and try to transmit a packet.
709 */
710 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
711 sc->tulip_probe_media = TULIP_MEDIA_MAX;
712 sc->tulip_probe_timeout = 0;
713 tulip_timeout(sc);
714 return;
715 }
716
717 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST
718 && (sc->tulip_features & TULIP_HAVE_MII)) {
719 tulip_media_t old_media = sc->tulip_probe_media;
720 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
721 switch (sc->tulip_probe_state) {
722 case TULIP_PROBE_FAILED:
723 case TULIP_PROBE_MEDIATEST: {
724 /*
725 * Try the next media.
726 */
727 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask;
728 sc->tulip_probe_timeout = 0;
729#ifdef notyet
730 if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
731 break;
732 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
733 break;
734 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
735#endif
736 break;
737 }
738 case TULIP_PROBE_PHYAUTONEG: {
739 return;
740 }
741 case TULIP_PROBE_INACTIVE: {
742 /*
743 * Only probe if we autonegotiated a media that hasn't failed.
744 */
745 sc->tulip_probe_timeout = 0;
746 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) {
747 sc->tulip_probe_media = old_media;
748 break;
749 }
750 tulip_linkup(sc, sc->tulip_probe_media);
751 tulip_timeout(sc);
752 return;
753 }
754 default: {
755#if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
756 panic("tulip_media_poll: botch at line %d\n", __LINE__);
757#endif
758 break;
759 }
760 }
761 }
762
763 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
764#if defined(TULIP_DEBUG)
765 sc->tulip_dbg.dbg_txprobes_failed[sc->tulip_probe_media]++;
766#endif
767 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
768 return;
769 }
770
771 /*
772 * switch to another media if we tried this one enough.
773 */
774 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
775#if defined(TULIP_DEBUG)
776 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
777 printf("%s%d: poll media unknown!\n",
778 sc->tulip_name, sc->tulip_unit);
779 sc->tulip_probe_media = TULIP_MEDIA_MAX;
780 }
781#endif
782 /*
783 * Find the next media type to check for. Full Duplex
784 * types are not allowed.
785 */
786 do {
787 sc->tulip_probe_media -= 1;
788 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
789 if (++sc->tulip_probe_passes == 3) {
790 printf("%s%d: autosense failed: cable problem?\n",
791 sc->tulip_name, sc->tulip_unit);
792 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
793 sc->tulip_if.if_flags &= ~IFF_RUNNING;
794 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
795 return;
796 }
797 }
798 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */
799 sc->tulip_probe_mediamask = 0;
800 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1;
801 }
802 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL
803 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
804 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
805
806#if defined(TULIP_DEBUG)
807 printf("%s%d: %s: probing %s\n", sc->tulip_name, sc->tulip_unit,
808 event == TULIP_MEDIAPOLL_TXPROBE_FAILED ? "txprobe failed" : "timeout",
809 tulip_mediums[sc->tulip_probe_media]);
810#endif
811 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
812 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
813 sc->tulip_probe.probe_txprobes = 0;
814 tulip_reset(sc);
815 tulip_media_set(sc, sc->tulip_probe_media);
816 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
817 }
818 tulip_timeout(sc);
819
820 /*
821 * If this is hanging off a phy, we know are doing NWAY and we have
822 * forced the phy to a specific speed. Wait for link up before
823 * before sending a packet.
824 */
825 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) {
826 case TULIP_MEDIAINFO_MII: {
827 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
828 return;
829 break;
830 }
831 case TULIP_MEDIAINFO_SIA: {
832 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) {
833 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL)
834 return;
835 tulip_linkup(sc, sc->tulip_probe_media);
836#ifdef notyet
837 if (sc->tulip_features & TULIP_HAVE_MII)
838 tulip_timeout(sc);
839#endif
840 return;
841 }
842 break;
843 }
844 case TULIP_MEDIAINFO_RESET:
845 case TULIP_MEDIAINFO_SYM:
846 case TULIP_MEDIAINFO_NONE:
847 case TULIP_MEDIAINFO_GPR: {
848 break;
849 }
850 }
851 /*
852 * Try to send a packet.
853 */
854 tulip_txprobe(sc);
855}
856
857static void
858tulip_media_select(
859 tulip_softc_t * const sc)
860{
861 if (sc->tulip_features & TULIP_HAVE_GPR) {
862 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
863 DELAY(10);
864 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata);
865 }
866 /*
867 * If this board has no media, just return
868 */
869 if (sc->tulip_features & TULIP_HAVE_NOMEDIA)
870 return;
871
872 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
873 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
874 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START);
875 } else {
876 tulip_media_set(sc, sc->tulip_media);
877 }
878}
879
880static void
881tulip_21040_mediainfo_init(
882 tulip_softc_t * const sc,
883 tulip_media_t media)
884{
885 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
886 |TULIP_CMD_BACKOFFCTR;
887 sc->tulip_if.if_baudrate = 10000000;
888
889 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) {
890 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET);
891 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD);
892 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
893 }
894
895 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) {
896 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC);
897 }
898
899 if (media == TULIP_MEDIA_UNKNOWN) {
900 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA);
901 }
902}
903
904static void
905tulip_21040_media_probe(
906 tulip_softc_t * const sc)
907{
908 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
909 return;
910}
911
912static void
913tulip_21040_10baset_only_media_probe(
914 tulip_softc_t * const sc)
915{
916 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
917 tulip_media_set(sc, TULIP_MEDIA_10BASET);
918 sc->tulip_media = TULIP_MEDIA_10BASET;
919}
920
921static void
922tulip_21040_10baset_only_media_select(
923 tulip_softc_t * const sc)
924{
925 sc->tulip_flags |= TULIP_LINKUP;
926 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
927 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
928 sc->tulip_flags &= ~TULIP_SQETEST;
929 } else {
930 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
931 sc->tulip_flags |= TULIP_SQETEST;
932 }
933 tulip_media_set(sc, sc->tulip_media);
934}
935
936static void
937tulip_21040_auibnc_only_media_probe(
938 tulip_softc_t * const sc)
939{
940 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
941 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
942 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
943 sc->tulip_media = TULIP_MEDIA_AUIBNC;
944}
945
946static void
947tulip_21040_auibnc_only_media_select(
948 tulip_softc_t * const sc)
949{
950 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
951 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
952}
953
954static const tulip_boardsw_t tulip_21040_boardsw = {
955 TULIP_21040_GENERIC,
956 tulip_21040_media_probe,
957 tulip_media_select,
958 tulip_media_poll,
959};
960
961static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = {
962 TULIP_21040_GENERIC,
963 tulip_21040_10baset_only_media_probe,
964 tulip_21040_10baset_only_media_select,
965 NULL,
966};
967
968static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = {
969 TULIP_21040_GENERIC,
970 tulip_21040_auibnc_only_media_probe,
971 tulip_21040_auibnc_only_media_select,
972 NULL,
973};
974
975static void
976tulip_21041_mediainfo_init(
977 tulip_softc_t * const sc)
978{
979 tulip_media_info_t * const mi = sc->tulip_mediainfo;
980
981#ifdef notyet
982 if (sc->tulip_revinfo >= 0x20) {
983 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET);
984 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD);
985 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI);
986 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC);
987 return;
988 }
989#endif
990 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET);
991 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD);
992 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
993 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
994}
995
996static void
997tulip_21041_media_probe(
998 tulip_softc_t * const sc)
999{
1000 sc->tulip_if.if_baudrate = 10000000;
1001 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
1002 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
1003 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
1004 tulip_21041_mediainfo_init(sc);
1005}
1006
1007static void
1008tulip_21041_media_poll(
1009 tulip_softc_t * const sc,
1010 const tulip_mediapoll_event_t event)
1011{
1012 u_int32_t sia_status;
1013
1014#if defined(TULIP_DEBUG)
1015 sc->tulip_dbg.dbg_events[event]++;
1016#endif
1017
1018 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
1019 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
1020 || !TULIP_DO_AUTOSENSE(sc))
1021 return;
1022 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
1023 tulip_reset(sc); /* start probe */
1024 return;
1025 }
1026
1027 /*
1028 * If we've been been asked to start a poll or link change interrupt
1029 * restart the probe (and reset the tulip to a known state).
1030 */
1031 if (event == TULIP_MEDIAPOLL_START) {
1032 sc->tulip_if.if_flags |= IFF_OACTIVE;
1033 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN);
1034#ifdef notyet
1035 if (sc->tulip_revinfo >= 0x20) {
1036 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
1037 sc->tulip_flags |= TULIP_DIDNWAY;
1038 }
1039#endif
1040 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1041 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1042 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1043 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT;
1044 tulip_media_set(sc, TULIP_MEDIA_10BASET);
1045 tulip_timeout(sc);
1046 return;
1047 }
1048
1049 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1050 return;
1051
1052 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
1053#if defined(TULIP_DEBUG)
1054 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
1055#endif
1056 tulip_linkup(sc, sc->tulip_probe_media);
1057 return;
1058 }
1059
1060 sia_status = TULIP_CSR_READ(sc, csr_sia_status);
1061 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status);
1062 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) {
1063 if (sc->tulip_revinfo >= 0x20) {
1064 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6)))
1065 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1066 }
1067 /*
1068 * If the link has passed LinkPass, 10baseT is the
1069 * proper media to use.
1070 */
1071 tulip_linkup(sc, sc->tulip_probe_media);
1072 return;
1073 }
1074
1075 /*
1076 * wait for up to 2.4 seconds for the link to reach pass state.
1077 * Only then start scanning the other media for activity.
1078 * choose media with receive activity over those without.
1079 */
1080 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) {
1081 if (event != TULIP_MEDIAPOLL_TIMER)
1082 return;
1083 if (sc->tulip_probe_timeout > 0
1084 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
1085 tulip_timeout(sc);
1086 return;
1087 }
1088 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1089 sc->tulip_flags |= TULIP_WANTRXACT;
1090 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) {
1091 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1092 } else {
1093 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1094 }
1095 tulip_media_set(sc, sc->tulip_probe_media);
1096 tulip_timeout(sc);
1097 return;
1098 }
1099
1100 /*
1101 * If we failed, clear the txprobe active flag.
1102 */
1103 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED)
1104 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1105
1106
1107 if (event == TULIP_MEDIAPOLL_TIMER) {
1108 /*
1109 * If we've received something, then that's our link!
1110 */
1111 if (sc->tulip_flags & TULIP_RXACT) {
1112 tulip_linkup(sc, sc->tulip_probe_media);
1113 return;
1114 }
1115 /*
1116 * if no txprobe active
1117 */
1118 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0
1119 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0
1120 || (sia_status & TULIP_SIASTS_RXACTIVITY))) {
1121 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1122 tulip_txprobe(sc);
1123 tulip_timeout(sc);
1124 return;
1125 }
1126 /*
1127 * Take 2 passes through before deciding to not
1128 * wait for receive activity. Then take another
1129 * two passes before spitting out a warning.
1130 */
1131 if (sc->tulip_probe_timeout <= 0) {
1132 if (sc->tulip_flags & TULIP_WANTRXACT) {
1133 sc->tulip_flags &= ~TULIP_WANTRXACT;
1134 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1135 } else {
1136 printf("%s%d: autosense failed: cable problem?\n",
1137 sc->tulip_name, sc->tulip_unit);
1138 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
1139 sc->tulip_if.if_flags &= ~IFF_RUNNING;
1140 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1141 return;
1142 }
1143 }
1144 }
1145 }
1146
1147 /*
1148 * Since this media failed to probe, try the other one.
1149 */
1150 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1151 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) {
1152 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1153 } else {
1154 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1155 }
1156 tulip_media_set(sc, sc->tulip_probe_media);
1157 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1158 tulip_timeout(sc);
1159}
1160
1161static const tulip_boardsw_t tulip_21041_boardsw = {
1162 TULIP_21041_GENERIC,
1163 tulip_21041_media_probe,
1164 tulip_media_select,
1165 tulip_21041_media_poll
1166};
1167
1168static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
1169 { 0x20005c00, 0, /* 08-00-17 */
1170 {
1171 { 0x19, 0x0040, 0x0040 }, /* 10TX */
1172 { 0x19, 0x0040, 0x0000 }, /* 100TX */
1173 },
1174#if defined(TULIP_DEBUG)
1175 "NS DP83840",
1176#endif
1177 },
1178 { 0x0281F400, 0, /* 00-A0-7D */
1179 {
1180 { 0x12, 0x0010, 0x0000 }, /* 10T */
1181 { }, /* 100TX */
1182 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1183 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1184 },
1185#if defined(TULIP_DEBUG)
1186 "Seeq 80C240"
1187#endif
1188 },
1189#if 0
1190 { 0x0015F420, 0, /* 00-A0-7D */
1191 {
1192 { 0x12, 0x0010, 0x0000 }, /* 10T */
1193 { }, /* 100TX */
1194 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1195 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1196 },
1197#if defined(TULIP_DEBUG)
1198 "Broadcom BCM5000"
1199#endif
1200 },
1201#endif
1202 { 0x0281F400, 0, /* 00-A0-BE */
1203 {
1204 { 0x11, 0x8000, 0x0000 }, /* 10T */
1205 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1206 { }, /* 100T4 */
1207 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1208 },
1209#if defined(TULIP_DEBUG)
1210 "ICS 1890"
1211#endif
1212 },
1213 { 0 }
1214};
1215
1216static tulip_media_t
1217tulip_mii_phy_readspecific(
1218 tulip_softc_t * const sc)
1219{
1220 const tulip_phy_attr_t *attr;
1221 u_int16_t data;
1222 u_int32_t id;
1223 unsigned idx = 0;
1224 static const tulip_media_t table[] = {
1225 TULIP_MEDIA_UNKNOWN,
1226 TULIP_MEDIA_10BASET,
1227 TULIP_MEDIA_100BASETX,
1228 TULIP_MEDIA_100BASET4,
1229 TULIP_MEDIA_UNKNOWN,
1230 TULIP_MEDIA_10BASET_FD,
1231 TULIP_MEDIA_100BASETX_FD,
1232 TULIP_MEDIA_UNKNOWN
1233 };
1234
1235 /*
1236 * Don't read phy specific registers if link is not up.
1237 */
1238 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
1239 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS))
1240 return TULIP_MEDIA_UNKNOWN;
1241
1242 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) |
1243 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH);
1244 for (attr = tulip_mii_phy_attrlist;; attr++) {
1245 if (attr->attr_id == 0)
1246 return TULIP_MEDIA_UNKNOWN;
1247 if ((id & ~0x0F) == attr->attr_id)
1248 break;
1249 }
1250
1251 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
1252 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100TX];
1253 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1254 if ((data & pm->pm_mask) == pm->pm_value)
1255 idx = 2;
1256 }
1257 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) {
1258 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100T4];
1259 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1260 if ((data & pm->pm_mask) == pm->pm_value)
1261 idx = 3;
1262 }
1263 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) {
1264 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_10T];
1265 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1266 if ((data & pm->pm_mask) == pm->pm_value)
1267 idx = 1;
1268 }
1269 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) {
1270 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
1271 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1272 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
1273 }
1274 return table[idx];
1275}
1276
1277static unsigned
1278tulip_mii_get_phyaddr(
1279 tulip_softc_t * const sc,
1280 unsigned offset)
1281{
1282 unsigned phyaddr;
1283
1284 for (phyaddr = 1; phyaddr < 32; phyaddr++) {
1285 unsigned status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1286 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1287 continue;
1288 if (offset == 0)
1289 return phyaddr;
1290 offset--;
1291 }
1292 if (offset == 0) {
1293 unsigned status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
1294 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1295 return TULIP_MII_NOPHY;
1296 return 0;
1297 }
1298 return TULIP_MII_NOPHY;
1299}
1300
1301static int
1302tulip_mii_map_abilities(
1303 tulip_softc_t * const sc,
1304 unsigned abilities)
1305{
1306 sc->tulip_abilities = abilities;
1307 if (abilities & PHYSTS_100BASETX_FD) {
1308 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD;
1309 } else if (abilities & PHYSTS_100BASET4) {
1310 sc->tulip_probe_media = TULIP_MEDIA_100BASET4;
1311 } else if (abilities & PHYSTS_100BASETX) {
1312 sc->tulip_probe_media = TULIP_MEDIA_100BASETX;
1313 } else if (abilities & PHYSTS_10BASET_FD) {
1314 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1315 } else if (abilities & PHYSTS_10BASET) {
1316 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1317 } else {
1318 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1319 return 0;
1320 }
1321 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1322 return 1;
1323}
1324
1325static void
1326tulip_mii_autonegotiate(
1327 tulip_softc_t * const sc,
1328 const unsigned phyaddr)
1329{
1330 switch (sc->tulip_probe_state) {
1331 case TULIP_PROBE_MEDIATEST:
1332 case TULIP_PROBE_INACTIVE: {
1333 sc->tulip_flags |= TULIP_DIDNWAY;
1334 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET);
1335 sc->tulip_probe_timeout = 3000;
1336 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR;
1337 sc->tulip_probe_state = TULIP_PROBE_PHYRESET;
1338 /* FALL THROUGH */
1339 }
1340 case TULIP_PROBE_PHYRESET: {
1341 u_int32_t status;
1342 u_int32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1343 if (data & PHYCTL_RESET) {
1344 if (sc->tulip_probe_timeout > 0) {
1345 tulip_timeout(sc);
1346 return;
1347 }
1348 printf("%s%d(phy%d): error: reset of PHY never completed!\n",
1349 sc->tulip_name, sc->tulip_unit, phyaddr);
1350 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1351 sc->tulip_probe_state = TULIP_PROBE_FAILED;
1352 sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
1353 return;
1354 }
1355 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1356 if ((status & PHYSTS_CAN_AUTONEG) == 0) {
1357#if defined(TULIP_DEBUG)
1358 loudprintf("%s%d(phy%d): autonegotiation disabled\n",
1359 sc->tulip_name, sc->tulip_unit, phyaddr);
1360#endif
1361 sc->tulip_flags &= ~TULIP_DIDNWAY;
1362 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1363 return;
1364 }
1365 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01))
1366 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
1367 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
1368 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1369#if defined(TULIP_DEBUG)
1370 if ((data & PHYCTL_AUTONEG_ENABLE) == 0)
1371 loudprintf("%s%d(phy%d): oops: enable autonegotiation failed: 0x%04x\n",
1372 sc->tulip_name, sc->tulip_unit, phyaddr, data);
1373 else
1374 loudprintf("%s%d(phy%d): autonegotiation restarted: 0x%04x\n",
1375 sc->tulip_name, sc->tulip_unit, phyaddr, data);
1376 sc->tulip_dbg.dbg_nway_starts++;
1377#endif
1378 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
1379 sc->tulip_probe_timeout = 3000;
1380 /* FALL THROUGH */
1381 }
1382 case TULIP_PROBE_PHYAUTONEG: {
1383 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1384 u_int32_t data;
1385 if ((status & PHYSTS_AUTONEG_DONE) == 0) {
1386 if (sc->tulip_probe_timeout > 0) {
1387 tulip_timeout(sc);
1388 return;
1389 }
1390#if defined(TULIP_DEBUG)
1391 loudprintf("%s%d(phy%d): autonegotiation timeout: sts=0x%04x, ctl=0x%04x\n",
1392 sc->tulip_name, sc->tulip_unit, phyaddr, status,
1393 tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL));
1394#endif
1395 sc->tulip_flags &= ~TULIP_DIDNWAY;
1396 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1397 return;
1398 }
1399 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
1400#if defined(TULIP_DEBUG)
1401 loudprintf("%s%d(phy%d): autonegotiation complete: 0x%04x\n",
1402 sc->tulip_name, sc->tulip_unit, phyaddr, data);
1403#endif
1404 data = (data << 6) & status;
1405 if (!tulip_mii_map_abilities(sc, data))
1406 sc->tulip_flags &= ~TULIP_DIDNWAY;
1407 return;
1408 }
1409 default: {
1410#if defined(DIAGNOSTIC)
1411 panic("tulip_media_poll: botch at line %d\n", __LINE__);
1412#endif
1413 break;
1414 }
1415 }
1416#if defined(TULIP_DEBUG)
1417 loudprintf("%s%d(phy%d): autonegotiation failure: state = %d\n",
1418 sc->tulip_name, sc->tulip_unit, phyaddr, sc->tulip_probe_state);
1419 sc->tulip_dbg.dbg_nway_failures++;
1420#endif
1421}
1422
1423static void
1424tulip_2114x_media_preset(
1425 tulip_softc_t * const sc)
1426{
1427 const tulip_media_info_t *mi = NULL;
1428 tulip_media_t media = sc->tulip_media;
1429
1430 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1431 media = sc->tulip_media;
1432 else
1433 media = sc->tulip_probe_media;
1434
1435 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
1436 sc->tulip_flags &= ~TULIP_SQETEST;
1437 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
1438#if defined(TULIP_DEBUG)
1439 if (media < TULIP_MEDIA_MAX && sc->tulip_mediums[media] != NULL) {
1440#endif
1441 mi = sc->tulip_mediums[media];
1442 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
1443 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1444 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR
1445 || mi->mi_type == TULIP_MEDIAINFO_SYM) {
1446 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
1447 sc->tulip_cmdmode |= mi->mi_cmdmode;
1448 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
1449 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
1450 }
1451#if defined(TULIP_DEBUG)
1452 } else {
1453 printf("%s%d: preset: bad media %d!\n",
1454 sc->tulip_name, sc->tulip_unit, media);
1455 }
1456#endif
1457 }
1458 switch (media) {
1459 case TULIP_MEDIA_BNC:
1460 case TULIP_MEDIA_AUI:
1461 case TULIP_MEDIA_10BASET: {
1462 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1463 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
1464 sc->tulip_if.if_baudrate = 10000000;
1465 sc->tulip_flags |= TULIP_SQETEST;
1466 break;
1467 }
1468 case TULIP_MEDIA_10BASET_FD: {
1469 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
1470 sc->tulip_if.if_baudrate = 10000000;
1471 break;
1472 }
1473 case TULIP_MEDIA_100BASEFX:
1474 case TULIP_MEDIA_100BASET4:
1475 case TULIP_MEDIA_100BASETX: {
1476 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL);
1477 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1478 sc->tulip_if.if_baudrate = 100000000;
1479 break;
1480 }
1481 case TULIP_MEDIA_100BASEFX_FD:
1482 case TULIP_MEDIA_100BASETX_FD: {
1483 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT;
1484 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
1485 sc->tulip_if.if_baudrate = 100000000;
1486 break;
1487 }
1488 default: {
1489 break;
1490 }
1491 }
1492 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1493}
1494
1495/*
1496 ********************************************************************
1497 * Start of 21140/21140A support which does not use the MII interface
1498 */
1499
1500static void
1501tulip_null_media_poll(
1502 tulip_softc_t * const sc,
1503 tulip_mediapoll_event_t event)
1504{
1505#if defined(TULIP_DEBUG)
1506 sc->tulip_dbg.dbg_events[event]++;
1507#endif
1508#if defined(DIAGNOSTIC)
1509 printf("%s%d: botch(media_poll) at line %d\n",
1510 sc->tulip_name, sc->tulip_unit, __LINE__);
1511#endif
1512}
1513
1514__inline__ static void
1515tulip_21140_mediainit(
1516 tulip_softc_t * const sc,
1517 tulip_media_info_t * const mip,
1518 tulip_media_t const media,
1519 unsigned gpdata,
1520 unsigned cmdmode)
1521{
1522 sc->tulip_mediums[media] = mip;
1523 mip->mi_type = TULIP_MEDIAINFO_GPR;
1524 mip->mi_cmdmode = cmdmode;
1525 mip->mi_gpdata = gpdata;
1526}
1527
1528static void
1529tulip_21140_evalboard_media_probe(
1530 tulip_softc_t * const sc)
1531{
1532 tulip_media_info_t *mip = sc->tulip_mediainfo;
1533
1534 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1535 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1536 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1537 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1538 TULIP_CSR_WRITE(sc, csr_command,
1539 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1540 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1541 TULIP_CSR_WRITE(sc, csr_command,
1542 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1543 DELAY(1000000);
1544 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
1545 sc->tulip_media = TULIP_MEDIA_10BASET;
1546 } else {
1547 sc->tulip_media = TULIP_MEDIA_100BASETX;
1548 }
1549 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1550 TULIP_GP_EB_INIT,
1551 TULIP_CMD_TXTHRSHLDCTL);
1552 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1553 TULIP_GP_EB_INIT,
1554 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1555 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1556 TULIP_GP_EB_INIT,
1557 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1558 |TULIP_CMD_SCRAMBLER);
1559 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1560 TULIP_GP_EB_INIT,
1561 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1562 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1563}
1564
1565static const tulip_boardsw_t tulip_21140_eb_boardsw = {
1566 TULIP_21140_DEC_EB,
1567 tulip_21140_evalboard_media_probe,
1568 tulip_media_select,
1569 tulip_null_media_poll,
1570 tulip_2114x_media_preset,
1571};
1572
1573static void
1574tulip_21140_accton_media_probe(
1575 tulip_softc_t * const sc)
1576{
1577 tulip_media_info_t *mip = sc->tulip_mediainfo;
1578 unsigned gpdata;
1579
1580 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1581 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1582 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1583 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1584 TULIP_CSR_WRITE(sc, csr_command,
1585 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1586 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1587 TULIP_CSR_WRITE(sc, csr_command,
1588 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1589 DELAY(1000000);
1590 gpdata = TULIP_CSR_READ(sc, csr_gp);
1591 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) {
1592 sc->tulip_media = TULIP_MEDIA_10BASET;
1593 } else {
1594 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) {
1595 sc->tulip_media = TULIP_MEDIA_BNC;
1596 } else {
1597 sc->tulip_media = TULIP_MEDIA_100BASETX;
1598 }
1599 }
1600 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC,
1601 TULIP_GP_EN1207_BNC_INIT,
1602 TULIP_CMD_TXTHRSHLDCTL);
1603 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1604 TULIP_GP_EN1207_UTP_INIT,
1605 TULIP_CMD_TXTHRSHLDCTL);
1606 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1607 TULIP_GP_EN1207_UTP_INIT,
1608 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1609 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1610 TULIP_GP_EN1207_100_INIT,
1611 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1612 |TULIP_CMD_SCRAMBLER);
1613 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1614 TULIP_GP_EN1207_100_INIT,
1615 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1616 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1617}
1618
1619static const tulip_boardsw_t tulip_21140_accton_boardsw = {
1620 TULIP_21140_EN1207,
1621 tulip_21140_accton_media_probe,
1622 tulip_media_select,
1623 tulip_null_media_poll,
1624 tulip_2114x_media_preset,
1625};
1626
1627static void
1628tulip_21140_smc9332_media_probe(
1629 tulip_softc_t * const sc)
1630{
1631 tulip_media_info_t *mip = sc->tulip_mediainfo;
1632 int idx, cnt = 0;
1633
1634 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE);
1635 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
1636 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
1637 33MHz that comes to two microseconds but wait a
1638 bit longer anyways) */
1639 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT |
1640 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1641 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS;
1642 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT;
1643 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET);
1644 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT);
1645 DELAY(200000);
1646 for (idx = 1000; idx > 0; idx--) {
1647 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1648 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) {
1649 if (++cnt > 100)
1650 break;
1651 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
1652 break;
1653 } else {
1654 cnt = 0;
1655 }
1656 DELAY(1000);
1657 }
1658 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1659 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1660 TULIP_GP_SMC_9332_INIT,
1661 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1662 |TULIP_CMD_SCRAMBLER);
1663 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1664 TULIP_GP_SMC_9332_INIT,
1665 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1666 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1667 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1668 TULIP_GP_SMC_9332_INIT,
1669 TULIP_CMD_TXTHRSHLDCTL);
1670 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1671 TULIP_GP_SMC_9332_INIT,
1672 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1673}
1674
1675static const tulip_boardsw_t tulip_21140_smc9332_boardsw = {
1676 TULIP_21140_SMC_9332,
1677 tulip_21140_smc9332_media_probe,
1678 tulip_media_select,
1679 tulip_null_media_poll,
1680 tulip_2114x_media_preset,
1681};
1682
1683static void
1684tulip_21140_cogent_em100_media_probe(
1685 tulip_softc_t * const sc)
1686{
1687 tulip_media_info_t *mip = sc->tulip_mediainfo;
1688 u_int32_t cmdmode = TULIP_CSR_READ(sc, csr_command);
1689
1690 sc->tulip_gpinit = TULIP_GP_EM100_PINS;
1691 sc->tulip_gpdata = TULIP_GP_EM100_INIT;
1692 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS);
1693 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT);
1694
1695 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE;
1696 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER);
1697 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1698 TULIP_CSR_WRITE(sc, csr_command, cmdmode);
1699 sc->tulip_media = TULIP_MEDIA_100BASEFX;
1700
1701 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX,
1702 TULIP_GP_EM100_INIT,
1703 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION);
1704 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD,
1705 TULIP_GP_EM100_INIT,
1706 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1707 |TULIP_CMD_FULLDUPLEX);
1708 } else {
1709 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);
1710 sc->tulip_media = TULIP_MEDIA_100BASETX;
1711 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1712 TULIP_GP_EM100_INIT,
1713 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1714 |TULIP_CMD_SCRAMBLER);
1715 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1716 TULIP_GP_EM100_INIT,
1717 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1718 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1719 }
1720}
1721
1722static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {
1723 TULIP_21140_COGENT_EM100,
1724 tulip_21140_cogent_em100_media_probe,
1725 tulip_media_select,
1726 tulip_null_media_poll,
1727 tulip_2114x_media_preset
1728};
1729
1730static void
1731tulip_21140_znyx_zx34x_media_probe(
1732 tulip_softc_t * const sc)
1733{
1734 tulip_media_info_t *mip = sc->tulip_mediainfo;
1735 int cnt10 = 0, cnt100 = 0, idx;
1736
1737 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS;
1738 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT;
1739 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS);
1740 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT);
1741 TULIP_CSR_WRITE(sc, csr_command,
1742 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1743 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1744 TULIP_CSR_WRITE(sc, csr_command,
1745 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1746
1747 DELAY(200000);
1748 for (idx = 1000; idx > 0; idx--) {
1749 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1750 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)) {
1751 if (++cnt100 > 100)
1752 break;
1753 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
1754 if (++cnt10 > 100)
1755 break;
1756 } else {
1757 cnt10 = 0;
1758 cnt100 = 0;
1759 }
1760 DELAY(1000);
1761 }
1762 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1763 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1764 TULIP_GP_ZX34X_INIT,
1765 TULIP_CMD_TXTHRSHLDCTL);
1766 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1767 TULIP_GP_ZX34X_INIT,
1768 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1769 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1770 TULIP_GP_ZX34X_INIT,
1771 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1772 |TULIP_CMD_SCRAMBLER);
1773 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1774 TULIP_GP_ZX34X_INIT,
1775 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1776 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1777}
1778
1779static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = {
1780 TULIP_21140_ZNYX_ZX34X,
1781 tulip_21140_znyx_zx34x_media_probe,
1782 tulip_media_select,
1783 tulip_null_media_poll,
1784 tulip_2114x_media_preset,
1785};
1786
1787static void
1788tulip_2114x_media_probe(
1789 tulip_softc_t * const sc)
1790{
1791 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE
1792 |TULIP_CMD_BACKOFFCTR|TULIP_CMD_THRSHLD72;
1793}
1794
1795static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
1796 TULIP_21140_ISV,
1797 tulip_2114x_media_probe,
1798 tulip_media_select,
1799 tulip_media_poll,
1800 tulip_2114x_media_preset,
1801};
1802
1803/*
1804 * ******** END of chip-specific handlers. ***********
1805 */
1806
1807/*
1808 * Code the read the SROM and MII bit streams (I2C)
1809 */
1810#define EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
1811
1812static void
1813tulip_srom_idle(
1814 tulip_softc_t * const sc)
1815{
1816 unsigned bit, csr;
1817
1818 csr = SROMSEL ; EMIT;
1819 csr = SROMSEL | SROMRD; EMIT;
1820 csr ^= SROMCS; EMIT;
1821 csr ^= SROMCLKON; EMIT;
1822
1823 /*
1824 * Write 25 cycles of 0 which will force the SROM to be idle.
1825 */
1826 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1827 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1828 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1829 }
1830 csr ^= SROMCLKOFF; EMIT;
1831 csr ^= SROMCS; EMIT;
1832 csr = 0; EMIT;
1833}
1834
1835
1836static void
1837tulip_srom_read(
1838 tulip_softc_t * const sc)
1839{
1840 unsigned idx;
1841 const unsigned bitwidth = SROM_BITWIDTH;
1842 const unsigned cmdmask = (SROMCMD_RD << bitwidth);
1843 const unsigned msb = 1 << (bitwidth + 3 - 1);
1844 unsigned lastidx = (1 << bitwidth) - 1;
1845
1846 tulip_srom_idle(sc);
1847
1848 for (idx = 0; idx <= lastidx; idx++) {
1849 unsigned lastbit, data, bits, bit, csr;
1850 csr = SROMSEL ; EMIT;
1851 csr = SROMSEL | SROMRD; EMIT;
1852 csr ^= SROMCSON; EMIT;
1853 csr ^= SROMCLKON; EMIT;
1854
1855 lastbit = 0;
1856 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
1857 const unsigned thisbit = bits & msb;
1858 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1859 if (thisbit != lastbit) {
1860 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1861 } else {
1862 EMIT;
1863 }
1864 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1865 lastbit = thisbit;
1866 }
1867 csr ^= SROMCLKOFF; EMIT;
1868
1869 for (data = 0, bits = 0; bits < 16; bits++) {
1870 data <<= 1;
1871 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1872 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1873 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1874 }
1875 sc->tulip_rombuf[idx*2] = data & 0xFF;
1876 sc->tulip_rombuf[idx*2+1] = data >> 8;
1877 csr = SROMSEL | SROMRD; EMIT;
1878 csr = 0; EMIT;
1879 }
1880 tulip_srom_idle(sc);
1881}
1882
1883#define MII_EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
1884
1885static void
1886tulip_mii_writebits(
1887 tulip_softc_t * const sc,
1888 unsigned data,
1889 unsigned bits)
1890{
1891 unsigned msb = 1 << (bits - 1);
1892 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1893 unsigned lastbit = (csr & MII_DOUT) ? msb : 0;
1894
1895 csr |= MII_WR; MII_EMIT; /* clock low; assert write */
1896
1897 for (; bits > 0; bits--, data <<= 1) {
1898 const unsigned thisbit = data & msb;
1899 if (thisbit != lastbit) {
1900 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */
1901 }
1902 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1903 lastbit = thisbit;
1904 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1905 }
1906}
1907
1908static void
1909tulip_mii_turnaround(
1910 tulip_softc_t * const sc,
1911 unsigned cmd)
1912{
1913 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1914
1915 if (cmd == MII_WRCMD) {
1916 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
1917 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1918 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1919 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */
1920 } else {
1921 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */
1922 }
1923 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1924 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1925}
1926
1927static unsigned
1928tulip_mii_readbits(
1929 tulip_softc_t * const sc)
1930{
1931 unsigned data;
1932 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1933 int idx;
1934
1935 for (idx = 0, data = 0; idx < 16; idx++) {
1936 data <<= 1; /* this is NOOP on the first pass through */
1937 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1938 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)
1939 data |= 1;
1940 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1941 }
1942 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
1943
1944 return data;
1945}
1946
1947static unsigned
1948tulip_mii_readreg(
1949 tulip_softc_t * const sc,
1950 unsigned devaddr,
1951 unsigned regno)
1952{
1953 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1954 unsigned data;
1955
1956 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1957 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1958 tulip_mii_writebits(sc, MII_RDCMD, 8);
1959 tulip_mii_writebits(sc, devaddr, 5);
1960 tulip_mii_writebits(sc, regno, 5);
1961 tulip_mii_turnaround(sc, MII_RDCMD);
1962
1963 data = tulip_mii_readbits(sc);
1964#if defined(TULIP_DEBUG)
1965 sc->tulip_dbg.dbg_phyregs[regno][0] = data;
1966 sc->tulip_dbg.dbg_phyregs[regno][1]++;
1967#endif
1968 return data;
1969}
1970
1971static void
1972tulip_mii_writereg(
1973 tulip_softc_t * const sc,
1974 unsigned devaddr,
1975 unsigned regno,
1976 unsigned data)
1977{
1978 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1979 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1980 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1981 tulip_mii_writebits(sc, MII_WRCMD, 8);
1982 tulip_mii_writebits(sc, devaddr, 5);
1983 tulip_mii_writebits(sc, regno, 5);
1984 tulip_mii_turnaround(sc, MII_WRCMD);
1985 tulip_mii_writebits(sc, data, 16);
1986#if defined(TULIP_DEBUG)
1987 sc->tulip_dbg.dbg_phyregs[regno][2] = data;
1988 sc->tulip_dbg.dbg_phyregs[regno][3]++;
1989#endif
1990}
1991
1992#define tulip_mchash(mca) (tulip_crc32(mca, 6) & 0x1FF)
1993#define tulip_srom_crcok(databuf) ( \
1994 ((tulip_crc32(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
1995 ((databuf)[126] | ((databuf)[127] << 8)))
1996
1997static unsigned
1998tulip_crc32(
1999 const unsigned char *databuf,
2000 size_t datalen)
2001{
2002 u_int idx, crc = 0xFFFFFFFFUL;
2003 static const u_int crctab[] = {
2004 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
2005 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
2006 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
2007 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
2008 };
2009
2010 for (idx = 0; idx < datalen; idx++) {
2011 crc ^= *databuf++;
2012 crc = (crc >> 4) ^ crctab[crc & 0xf];
2013 crc = (crc >> 4) ^ crctab[crc & 0xf];
2014 }
2015 return crc;
2016}
2017
2018static void
2019tulip_identify_dec_nic(
2020 tulip_softc_t * const sc)
2021{
2022 strcpy(sc->tulip_boardid, "DEC ");
2023#define D0 4
2024 if (sc->tulip_chipid <= TULIP_21040)
2025 return;
2026 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0
2027 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {
2028 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);
2029 sc->tulip_boardid[D0+8] = ' ';
2030 }
2031#undef D0
2032}
2033
2034static void
2035tulip_identify_znyx_nic(
2036 tulip_softc_t * const sc)
2037{
2038 unsigned id = 0;
2039 strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
2040 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
2041 unsigned znyx_ptr;
2042 sc->tulip_boardid[8] = '4';
2043 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
2044 if (znyx_ptr < 26 || znyx_ptr > 116) {
2045 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2046 return;
2047 }
2048 /* ZX344 = 0010 .. 0013FF
2049 */
2050 if (sc->tulip_rombuf[znyx_ptr] == 0x4A
2051 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52
2052 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) {
2053 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4];
2054 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) {
2055 sc->tulip_boardid[9] = '2';
2056 if (id == TULIP_ZNYX_ID_ZX342B) {
2057 sc->tulip_boardid[10] = 'B';
2058 sc->tulip_boardid[11] = ' ';
2059 }
2060 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2061 } else if (id == TULIP_ZNYX_ID_ZX344) {
2062 sc->tulip_boardid[10] = '4';
2063 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2064 } else if (id == TULIP_ZNYX_ID_ZX345) {
2065 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5';
2066 } else if (id == TULIP_ZNYX_ID_ZX346) {
2067 sc->tulip_boardid[9] = '6';
2068 } else if (id == TULIP_ZNYX_ID_ZX351) {
2069 sc->tulip_boardid[8] = '5';
2070 sc->tulip_boardid[9] = '1';
2071 }
2072 }
2073 if (id == 0) {
2074 /*
2075 * Assume it's a ZX342...
2076 */
2077 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2078 }
2079 return;
2080 }
2081 sc->tulip_boardid[8] = '1';
2082 if (sc->tulip_chipid == TULIP_21041) {
2083 sc->tulip_boardid[10] = '1';
2084 return;
2085 }
2086 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) {
2087 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36];
2088 if (id == TULIP_ZNYX_ID_ZX312T) {
2089 sc->tulip_boardid[9] = '2';
2090 sc->tulip_boardid[10] = 'T';
2091 sc->tulip_boardid[11] = ' ';
2092 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2093 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) {
2094 sc->tulip_boardid[9] = '4';
2095 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2096 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2097 } else if (id == TULIP_ZNYX_ID_ZX314) {
2098 sc->tulip_boardid[9] = '4';
2099 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2100 sc->tulip_features |= TULIP_HAVE_BASEROM;
2101 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) {
2102 sc->tulip_boardid[9] = '5';
2103 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2104 } else if (id == TULIP_ZNYX_ID_ZX315) {
2105 sc->tulip_boardid[9] = '5';
2106 sc->tulip_features |= TULIP_HAVE_BASEROM;
2107 } else {
2108 id = 0;
2109 }
2110 }
2111 if (id == 0) {
2112 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) {
2113 sc->tulip_boardid[9] = '4';
2114 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2115 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2116 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) {
2117 sc->tulip_boardid[9] = '5';
2118 sc->tulip_boardsw = &tulip_21040_boardsw;
2119 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2120 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) {
2121 sc->tulip_boardid[9] = '2';
2122 sc->tulip_boardsw = &tulip_21040_boardsw;
2123 }
2124 }
2125}
2126
2127static void
2128tulip_identify_smc_nic(
2129 tulip_softc_t * const sc)
2130{
2131 u_int32_t id1, id2, ei;
2132 int auibnc = 0, utp = 0;
2133 char *cp;
2134
2135 strcpy(sc->tulip_boardid, "SMC ");
2136 if (sc->tulip_chipid == TULIP_21041)
2137 return;
2138 if (sc->tulip_chipid != TULIP_21040) {
2139 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2140 strcpy(&sc->tulip_boardid[4], "9332DST ");
2141 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;
2142 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {
2143 strcpy(&sc->tulip_boardid[4], "9334BDT ");
2144 } else {
2145 strcpy(&sc->tulip_boardid[4], "9332BDT ");
2146 }
2147 return;
2148 }
2149 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);
2150 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);
2151 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);
2152
2153 strcpy(&sc->tulip_boardid[4], "8432");
2154 cp = &sc->tulip_boardid[8];
2155 if ((id1 & 1) == 0)
2156 *cp++ = 'B', auibnc = 1;
2157 if ((id1 & 0xFF) > 0x32)
2158 *cp++ = 'T', utp = 1;
2159 if ((id1 & 0x4000) == 0)
2160 *cp++ = 'A', auibnc = 1;
2161 if (id2 == 0x15) {
2162 sc->tulip_boardid[7] = '4';
2163 *cp++ = '-';
2164 *cp++ = 'C';
2165 *cp++ = 'H';
2166 *cp++ = (ei ? '2' : '1');
2167 }
2168 *cp++ = ' ';
2169 *cp = '\0';
2170 if (utp && !auibnc)
2171 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2172 else if (!utp && auibnc)
2173 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
2174}
2175
2176static void
2177tulip_identify_cogent_nic(
2178 tulip_softc_t * const sc)
2179{
2180 strcpy(sc->tulip_boardid, "Cogent ");
2181 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
2182 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {
2183 strcat(sc->tulip_boardid, "EM100TX ");
2184 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2185#if defined(TULIP_COGENT_EM110TX_ID)
2186 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {
2187 strcat(sc->tulip_boardid, "EM110TX ");
2188 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2189#endif
2190 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
2191 strcat(sc->tulip_boardid, "EM100FX ");
2192 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2193 }
2194 /*
2195 * Magic number (0x24001109U) is the SubVendor (0x2400) and
2196 * SubDevId (0x1109) for the ANA6944TX (EM440TX).
2197 */
2198 if (*(u_int32_t *) sc->tulip_rombuf == 0x24001109U
2199 && (sc->tulip_features & TULIP_HAVE_BASEROM)) {
2200 /*
2201 * Cogent (Adaptec) is still mapping all INTs to INTA of
2202 * first 21140. Dumb! Dumb!
2203 */
2204 strcat(sc->tulip_boardid, "EM440TX ");
2205 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2206 }
2207 } else if (sc->tulip_chipid == TULIP_21040) {
2208 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2209 }
2210}
2211
2212static void
2213tulip_identify_accton_nic(
2214 tulip_softc_t * const sc)
2215{
2216 strcpy(sc->tulip_boardid, "ACCTON ");
2217 switch (sc->tulip_chipid) {
2218 case TULIP_21140A:
2219 strcat(sc->tulip_boardid, "EN1207 ");
2220 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
2221 sc->tulip_boardsw = &tulip_21140_accton_boardsw;
2222 break;
2223 case TULIP_21140:
2224 strcat(sc->tulip_boardid, "EN1207TX ");
2225 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
2226 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2227 break;
2228 case TULIP_21040:
2229 strcat(sc->tulip_boardid, "EN1203 ");
2230 sc->tulip_boardsw = &tulip_21040_boardsw;
2231 break;
2232 case TULIP_21041:
2233 strcat(sc->tulip_boardid, "EN1203 ");
2234 sc->tulip_boardsw = &tulip_21041_boardsw;
2235 break;
2236 default:
2237 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2238 break;
2239 }
2240}
2241
2242static void
2243tulip_identify_asante_nic(
2244 tulip_softc_t * const sc)
2245{
2246 strcpy(sc->tulip_boardid, "Asante ");
2247 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
2248 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2249 tulip_media_info_t *mi = sc->tulip_mediainfo;
2250 int idx;
2251 /*
2252 * The Asante Fast Ethernet doesn't always ship with a valid
2253 * new format SROM. So if isn't in the new format, we cheat
2254 * set it up as if we had.
2255 */
2256
2257 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;
2258 sc->tulip_gpdata = 0;
2259
2260 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);
2261 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);
2262 DELAY(100);
2263 TULIP_CSR_WRITE(sc, csr_gp, 0);
2264
2265 mi->mi_type = TULIP_MEDIAINFO_MII;
2266 mi->mi_gpr_length = 0;
2267 mi->mi_gpr_offset = 0;
2268 mi->mi_reset_length = 0;
2269 mi->mi_reset_offset = 0;;
2270
2271 mi->mi_phyaddr = TULIP_MII_NOPHY;
2272 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) {
2273 DELAY(10000);
2274 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
2275 }
2276 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2277 printf("%s%d: can't find phy 0\n", sc->tulip_name, sc->tulip_unit);
2278 return;
2279 }
2280
2281 sc->tulip_features |= TULIP_HAVE_MII;
2282 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2283 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2284 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD;
2285 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD;
2286 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2287 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2288 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2289 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2290 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2291 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2292 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2293
2294 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2295 }
2296}
2297
2298static void
2299tulip_identify_compex_nic(
2300 tulip_softc_t * const sc)
2301{
2302 strcpy(sc->tulip_boardid, "COMPEX ");
2303 if (sc->tulip_chipid == TULIP_21140A) {
2304 int root_unit;
2305 tulip_softc_t *root_sc = NULL;
2306
2307 strcat(sc->tulip_boardid, "400TX/PCI ");
2308 /*
2309 * All 4 chips on these boards share an interrupt. This code
2310 * copied from tulip_read_macaddr.
2311 */
2312 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2313 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2314 root_sc = tulips[root_unit];
2315 if (root_sc == NULL
2316 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
2317 break;
2318 root_sc = NULL;
2319 }
2320 if (root_sc != NULL
2321 && root_sc->tulip_chipid == sc->tulip_chipid
2322 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2323 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2324 sc->tulip_slaves = root_sc->tulip_slaves;
2325 root_sc->tulip_slaves = sc;
2326 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
2327 printf("\nCannot find master device for de%d interrupts",
2328 sc->tulip_unit);
2329 }
2330 } else {
2331 strcat(sc->tulip_boardid, "unknown ");
2332 }
2333 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */
2334 return;
2335}
2336
2337static int
2338tulip_srom_decode(
2339 tulip_softc_t * const sc)
2340{
2341 unsigned idx1, idx2, idx3;
2342
2343 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
2344 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
2345 tulip_srom_media_t srom_media;
2346 tulip_media_info_t *mi = sc->tulip_mediainfo;
2347 const u_int8_t *dp;
2348 u_int32_t leaf_offset, blocks, data;
2349
2350 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
2351 if (shp->sh_adapter_count == 1)
2352 break;
2353 if (saip->sai_device == sc->tulip_pci_devno)
2354 break;
2355 }
2356 /*
2357 * Didn't find the right media block for this card.
2358 */
2359 if (idx1 == shp->sh_adapter_count)
2360 return 0;
2361
2362 /*
2363 * Save the hardware address.
2364 */
2365 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6);
2366 /*
2367 * If this is a multiple port card, add the adapter index to the last
2368 * byte of the hardware address. (if it isn't multiport, adding 0
2369 * won't hurt.
2370 */
2371 sc->tulip_enaddr[5] += idx1;
2372
2373 leaf_offset = saip->sai_leaf_offset_lowbyte
2374 + saip->sai_leaf_offset_highbyte * 256;
2375 dp = sc->tulip_rombuf + leaf_offset;
2376
2377 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2;
2378
2379 for (idx2 = 0;; idx2++) {
2380 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype
2381 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED)
2382 break;
2383 }
2384 sc->tulip_connidx = idx2;
2385
2386 if (sc->tulip_chipid == TULIP_21041) {
2387 blocks = *dp++;
2388 for (idx2 = 0; idx2 < blocks; idx2++) {
2389 tulip_media_t media;
2390 data = *dp++;
2391 srom_media = (tulip_srom_media_t) (data & 0x3F);
2392 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2393 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2394 break;
2395 }
2396 media = tulip_srom_mediums[idx3].sm_type;
2397 if (media != TULIP_MEDIA_UNKNOWN) {
2398 if (data & TULIP_SROM_21041_EXTENDED) {
2399 mi->mi_type = TULIP_MEDIAINFO_SIA;
2400 sc->tulip_mediums[media] = mi;
2401 mi->mi_sia_connectivity = dp[0] + dp[1] * 256;
2402 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256;
2403 mi->mi_sia_general = dp[4] + dp[5] * 256;
2404 mi++;
2405 } else {
2406 switch (media) {
2407 case TULIP_MEDIA_BNC: {
2408 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
2409 mi++;
2410 break;
2411 }
2412 case TULIP_MEDIA_AUI: {
2413 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
2414 mi++;
2415 break;
2416 }
2417 case TULIP_MEDIA_10BASET: {
2418 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
2419 mi++;
2420 break;
2421 }
2422 case TULIP_MEDIA_10BASET_FD: {
2423 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
2424 mi++;
2425 break;
2426 }
2427 default: {
2428 break;
2429 }
2430 }
2431 }
2432 }
2433 if (data & TULIP_SROM_21041_EXTENDED)
2434 dp += 6;
2435 }
2436#ifdef notdef
2437 if (blocks == 0) {
2438 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++;
2439 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++;
2440 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++;
2441 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++;
2442 }
2443#endif
2444 } else {
2445 unsigned length, type;
2446 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN;
2447 if (sc->tulip_features & TULIP_HAVE_GPR)
2448 sc->tulip_gpinit = *dp++;
2449 blocks = *dp++;
2450 for (idx2 = 0; idx2 < blocks; idx2++) {
2451 const u_int8_t *ep;
2452 if ((*dp & 0x80) == 0) {
2453 length = 4;
2454 type = 0;
2455 } else {
2456 length = (*dp++ & 0x7f) - 1;
2457 type = *dp++ & 0x3f;
2458 }
2459 ep = dp + length;
2460 switch (type & 0x3f) {
2461 case 0: { /* 21140[A] GPR block */
2462 tulip_media_t media;
2463 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2464 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2465 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2466 break;
2467 }
2468 media = tulip_srom_mediums[idx3].sm_type;
2469 if (media == TULIP_MEDIA_UNKNOWN)
2470 break;
2471 mi->mi_type = TULIP_MEDIAINFO_GPR;
2472 sc->tulip_mediums[media] = mi;
2473 mi->mi_gpdata = dp[1];
2474 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) {
2475 sc->tulip_gpdata = mi->mi_gpdata;
2476 gp_media = media;
2477 }
2478 data = dp[2] + dp[3] * 256;
2479 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2480 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2481 mi->mi_actmask = 0;
2482 } else {
2483#if 0
2484 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2485#endif
2486 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2487 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2488 }
2489 mi++;
2490 break;
2491 }
2492 case 1: { /* 21140[A] MII block */
2493 const unsigned phyno = *dp++;
2494 mi->mi_type = TULIP_MEDIAINFO_MII;
2495 mi->mi_gpr_length = *dp++;
2496 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2497 dp += mi->mi_gpr_length;
2498 mi->mi_reset_length = *dp++;
2499 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2500 dp += mi->mi_reset_length;
2501
2502 /*
2503 * Before we probe for a PHY, use the GPR information
2504 * to select it. If we don't, it may be inaccessible.
2505 */
2506 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET);
2507 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) {
2508 DELAY(10);
2509 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]);
2510 }
2511 sc->tulip_phyaddr = mi->mi_phyaddr;
2512 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) {
2513 DELAY(10);
2514 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]);
2515 }
2516
2517 /*
2518 * At least write something!
2519 */
2520 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2521 TULIP_CSR_WRITE(sc, csr_gp, 0);
2522
2523 mi->mi_phyaddr = TULIP_MII_NOPHY;
2524 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2525 DELAY(10000);
2526 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2527 }
2528 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2529#if defined(TULIP_DEBUG)
2530 printf("%s%d: can't find phy %d\n",
2531 sc->tulip_name, sc->tulip_unit, phyno);
2532#endif
2533 break;
2534 }
2535 sc->tulip_features |= TULIP_HAVE_MII;
2536 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2537 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2538 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2539 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2540 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2541 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2542 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2543 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2544 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2545 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2546 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2547 mi++;
2548 break;
2549 }
2550 case 2: { /* 2114[23] SIA block */
2551 tulip_media_t media;
2552 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2553 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2554 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2555 break;
2556 }
2557 media = tulip_srom_mediums[idx3].sm_type;
2558 if (media == TULIP_MEDIA_UNKNOWN)
2559 break;
2560 mi->mi_type = TULIP_MEDIAINFO_SIA;
2561 sc->tulip_mediums[media] = mi;
2562 if (dp[0] & 0x40) {
2563 mi->mi_sia_connectivity = dp[1] + dp[2] * 256;
2564 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256;
2565 mi->mi_sia_general = dp[5] + dp[6] * 256;
2566 dp += 6;
2567 } else {
2568 switch (media) {
2569 case TULIP_MEDIA_BNC: {
2570 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
2571 break;
2572 }
2573 case TULIP_MEDIA_AUI: {
2574 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
2575 break;
2576 }
2577 case TULIP_MEDIA_10BASET: {
2578 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
2579 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2580 break;
2581 }
2582 case TULIP_MEDIA_10BASET_FD: {
2583 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
2584 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2585 break;
2586 }
2587 default: {
2588 goto bad_media;
2589 }
2590 }
2591 }
2592 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16;
2593 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16;
2594 mi++;
2595 bad_media:
2596 break;
2597 }
2598 case 3: { /* 2114[23] MII PHY block */
2599 const unsigned phyno = *dp++;
2600 const u_int8_t *dp0;
2601 mi->mi_type = TULIP_MEDIAINFO_MII;
2602 mi->mi_gpr_length = *dp++;
2603 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2604 dp += 2 * mi->mi_gpr_length;
2605 mi->mi_reset_length = *dp++;
2606 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2607 dp += 2 * mi->mi_reset_length;
2608
2609 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset];
2610 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) {
2611 DELAY(10);
2612 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2613 }
2614 sc->tulip_phyaddr = mi->mi_phyaddr;
2615 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset];
2616 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) {
2617 DELAY(10);
2618 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2619 }
2620
2621 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2622 TULIP_CSR_WRITE(sc, csr_sia_general, 0);
2623
2624 mi->mi_phyaddr = TULIP_MII_NOPHY;
2625 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2626 DELAY(10000);
2627 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2628 }
2629 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2630#if defined(TULIP_DEBUG)
2631 printf("%s%d: can't find phy %d\n",
2632 sc->tulip_name, sc->tulip_unit, phyno);
2633#endif
2634 break;
2635 }
2636 sc->tulip_features |= TULIP_HAVE_MII;
2637 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2638 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2639 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2640 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2641 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2;
2642 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2643 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2644 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2645 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2646 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2647 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2648 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2649 mi++;
2650 break;
2651 }
2652 case 4: { /* 21143 SYM block */
2653 tulip_media_t media;
2654 srom_media = (tulip_srom_media_t) dp[0];
2655 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2656 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2657 break;
2658 }
2659 media = tulip_srom_mediums[idx3].sm_type;
2660 if (media == TULIP_MEDIA_UNKNOWN)
2661 break;
2662 mi->mi_type = TULIP_MEDIAINFO_SYM;
2663 sc->tulip_mediums[media] = mi;
2664 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16;
2665 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16;
2666 data = dp[5] + dp[6] * 256;
2667 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2668 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2669 mi->mi_actmask = 0;
2670 } else {
2671 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2672 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2673 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2674 }
2675 if (TULIP_IS_MEDIA_TP(media))
2676 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2677 mi++;
2678 break;
2679 }
2680#if 0
2681 case 5: { /* 21143 Reset block */
2682 mi->mi_type = TULIP_MEDIAINFO_RESET;
2683 mi->mi_reset_length = *dp++;
2684 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2685 dp += 2 * mi->mi_reset_length;
2686 mi++;
2687 break;
2688 }
2689#endif
2690 default: {
2691 }
2692 }
2693 dp = ep;
2694 }
2695 }
2696 return mi - sc->tulip_mediainfo;
2697}
2698
2699static const struct {
2700 void (*vendor_identify_nic)(tulip_softc_t * const sc);
2701 unsigned char vendor_oui[3];
2702} tulip_vendors[] = {
2703 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } },
2704 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } },
2705 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } },
2706 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } },
2707 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } },
2708 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } },
2709 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } },
2710 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } },
2711 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } },
2712 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } },
2713 { NULL }
2714};
2715
2716/*
2717 * This deals with the vagaries of the address roms and the
2718 * brain-deadness that various vendors commit in using them.
2719 */
2720static int
2721tulip_read_macaddr(
2722 tulip_softc_t * const sc)
2723{
2724 unsigned cksum, rom_cksum, idx;
2725 u_int32_t csr;
2726 unsigned char tmpbuf[8];
2727 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
2728
2729 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX;
2730
2731 if (sc->tulip_chipid == TULIP_21040) {
2732 TULIP_CSR_WRITE(sc, csr_enetrom, 1);
2733 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2734 int cnt = 0;
2735 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
2736 cnt++;
2737 sc->tulip_rombuf[idx] = csr & 0xFF;
2738 }
2739 sc->tulip_boardsw = &tulip_21040_boardsw;
2740 } else {
2741 if (sc->tulip_chipid == TULIP_21041) {
2742 /*
2743 * Thankfully all 21041's act the same.
2744 */
2745 sc->tulip_boardsw = &tulip_21041_boardsw;
2746 } else {
2747 /*
2748 * Assume all 21140 board are compatible with the
2749 * DEC 10/100 evaluation board. Not really valid but
2750 * it's the best we can do until every one switches to
2751 * the new SROM format.
2752 */
2753
2754 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2755 }
2756 tulip_srom_read(sc);
2757 if (tulip_srom_crcok(sc->tulip_rombuf)) {
2758 /*
2759 * SROM CRC is valid therefore it must be in the
2760 * new format.
2761 */
2762 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM;
2763 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
2764 /*
2765 * No checksum is present. See if the SROM id checks out;
2766 * the first 18 bytes should be 0 followed by a 1 followed
2767 * by the number of adapters (which we don't deal with yet).
2768 */
2769 for (idx = 0; idx < 18; idx++) {
2770 if (sc->tulip_rombuf[idx] != 0)
2771 break;
2772 }
2773 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
2774 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2775 } else if (sc->tulip_chipid >= TULIP_21142) {
2776 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2777 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2778 }
2779 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) {
2780 if (sc->tulip_chipid != TULIP_21041)
2781 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2782
2783 /*
2784 * If the SROM specifies more than one adapter, tag this as a
2785 * BASE rom.
2786 */
2787 if (sc->tulip_rombuf[19] > 1)
2788 sc->tulip_features |= TULIP_HAVE_BASEROM;
2789 if (sc->tulip_boardsw == NULL)
2790 return -6;
2791 goto check_oui;
2792 }
2793 }
2794
2795
2796 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
2797 /*
2798 * Some folks don't use the standard ethernet rom format
2799 * but instead just put the address in the first 6 bytes
2800 * of the rom and let the rest be all 0xffs. (Can we say
2801 * ZNYX?) (well sometimes they put in a checksum so we'll
2802 * start at 8).
2803 */
2804 for (idx = 8; idx < 32; idx++) {
2805 if (sc->tulip_rombuf[idx] != 0xFF)
2806 return -4;
2807 }
2808 /*
2809 * Make sure the address is not multicast or locally assigned
2810 * that the OUI is not 00-00-00.
2811 */
2812 if ((sc->tulip_rombuf[0] & 3) != 0)
2813 return -4;
2814 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
2815 && sc->tulip_rombuf[2] == 0)
2816 return -4;
2817 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2818 sc->tulip_features |= TULIP_HAVE_OKROM;
2819 goto check_oui;
2820 } else {
2821 /*
2822 * A number of makers of multiport boards (ZNYX and Cogent)
2823 * only put on one address ROM on their 21040 boards. So
2824 * if the ROM is all zeros (or all 0xFFs), look at the
2825 * previous configured boards (as long as they are on the same
2826 * PCI bus and the bus number is non-zero) until we find the
2827 * master board with address ROM. We then use its address ROM
2828 * as the base for this board. (we add our relative board
2829 * to the last byte of its address).
2830 */
2831 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2832 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF)
2833 break;
2834 }
2835 if (idx == sizeof(sc->tulip_rombuf)) {
2836 int root_unit;
2837 tulip_softc_t *root_sc = NULL;
2838 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2839 root_sc = tulips[root_unit];
2840 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
2841 break;
2842 root_sc = NULL;
2843 }
2844 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM)
2845 && root_sc->tulip_chipid == sc->tulip_chipid
2846 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2847 sc->tulip_features |= TULIP_HAVE_SLAVEDROM;
2848 sc->tulip_boardsw = root_sc->tulip_boardsw;
2849 strcpy(sc->tulip_boardid, root_sc->tulip_boardid);
2850 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) {
2851 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf,
2852 sizeof(sc->tulip_rombuf));
2853 if (!tulip_srom_decode(sc))
2854 return -5;
2855 } else {
2856 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
2857 sc->tulip_enaddr[5] += sc->tulip_unit - root_sc->tulip_unit;
2858 }
2859 /*
2860 * Now for a truly disgusting kludge: all 4 21040s on
2861 * the ZX314 share the same INTA line so the mapping
2862 * setup by the BIOS on the PCI bridge is worthless.
2863 * Rather than reprogramming the value in the config
2864 * register, we will handle this internally.
2865 */
2866 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) {
2867 sc->tulip_slaves = root_sc->tulip_slaves;
2868 root_sc->tulip_slaves = sc;
2869 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2870 }
2871 return 0;
2872 }
2873 }
2874 }
2875
2876 /*
2877 * This is the standard DEC address ROM test.
2878 */
2879
2880 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
2881 return -3;
2882
2883 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
2884 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
2885 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
2886 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
2887 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
2888 return -2;
2889
2890 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2891
2892 cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
2893 cksum *= 2;
2894 if (cksum > 65535) cksum -= 65535;
2895 cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
2896 if (cksum > 65535) cksum -= 65535;
2897 cksum *= 2;
2898 if (cksum > 65535) cksum -= 65535;
2899 cksum += *(u_int16_t *) &sc->tulip_enaddr[4];
2900 if (cksum >= 65535) cksum -= 65535;
2901
2902 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6];
2903
2904 if (cksum != rom_cksum)
2905 return -1;
2906
2907 check_oui:
2908 /*
2909 * Check for various boards based on OUI. Did I say braindead?
2910 */
2911 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) {
2912 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) {
2913 (*tulip_vendors[idx].vendor_identify_nic)(sc);
2914 break;
2915 }
2916 }
2917
2918 sc->tulip_features |= TULIP_HAVE_OKROM;
2919 return 0;
2920}
2921
2922static void
2923tulip_ifmedia_add(
2924 tulip_softc_t * const sc)
2925{
2926 tulip_media_t media;
2927 int medias = 0;
2928
2929 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2930 if (sc->tulip_mediums[media] != NULL) {
2931 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media],
2932 0, 0);
2933 medias++;
2934 }
2935 }
2936 if (medias == 0) {
2937 sc->tulip_features |= TULIP_HAVE_NOMEDIA;
2938 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0);
2939 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE);
2940 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
2941 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0);
2942 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO);
2943 } else {
2944 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]);
2945 sc->tulip_flags |= TULIP_PRINTMEDIA;
2946 tulip_linkup(sc, sc->tulip_media);
2947 }
2948}
2949
2950static int
2951tulip_ifmedia_change(
2952 struct ifnet * const ifp)
2953{
2954 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
2955
2956 sc->tulip_flags |= TULIP_NEEDRESET;
2957 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
2958 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
2959 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) {
2960 tulip_media_t media;
2961 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2962 if (sc->tulip_mediums[media] != NULL
2963 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) {
2964 sc->tulip_flags |= TULIP_PRINTMEDIA;
2965 sc->tulip_flags &= ~TULIP_DIDNWAY;
2966 tulip_linkup(sc, media);
2967 return 0;
2968 }
2969 }
2970 }
2971 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
2972 tulip_reset(sc);
2973 tulip_init(sc);
2974 return 0;
2975}
2976
2977/*
2978 * Media status callback
2979 */
2980static void
2981tulip_ifmedia_status(
2982 struct ifnet * const ifp,
2983 struct ifmediareq *req)
2984{
2985 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2986
2987 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN)
2988 return;
2989
2990 req->ifm_status = IFM_AVALID;
2991 if (sc->tulip_flags & TULIP_LINKUP)
2992 req->ifm_status |= IFM_ACTIVE;
2993
2994 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
2995}
2996
2997static void
2998tulip_addr_filter(
2999 tulip_softc_t * const sc)
3000{
3001 struct ifmultiaddr *ifma;
3002 u_char *addrp;
3003 int multicnt;
3004
3005 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI);
3006 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART;
3007 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3008 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3009#if defined(IFF_ALLMULTI)
3010 if (sc->tulip_if.if_flags & IFF_ALLMULTI)
3011 sc->tulip_flags |= TULIP_ALLMULTI ;
3012#endif
3013
3014 multicnt = 0;
3015 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
3016
3017 if (ifma->ifma_addr->sa_family == AF_LINK)
3018 multicnt++;
3019 }
3020
3021 sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */
3022 if (multicnt > 14) {
3023 u_int32_t *sp = sc->tulip_setupdata;
3024 unsigned hash;
3025 /*
3026 * Some early passes of the 21140 have broken implementations of
3027 * hash-perfect mode. When we get too many multicasts for perfect
3028 * filtering with these chips, we need to switch into hash-only
3029 * mode (this is better than all-multicast on network with lots
3030 * of multicast traffic).
3031 */
3032 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
3033 sc->tulip_flags |= TULIP_WANTHASHONLY;
3034 else
3035 sc->tulip_flags |= TULIP_WANTHASHPERFECT;
3036 /*
3037 * If we have more than 14 multicasts, we have
3038 * go into hash perfect mode (512 bit multicast
3039 * hash and one perfect hardware).
3040 */
3041 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
3042
3043 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
3044
3045 if (ifma->ifma_addr->sa_family != AF_LINK)
3046 continue;
3047
3048 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
3049#if BYTE_ORDER == BIG_ENDIAN
3050 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3051#else
3052 sp[hash >> 4] |= 1 << (hash & 0xF);
3053#endif
3054 }
3055 /*
3056 * No reason to use a hash if we are going to be
3057 * receiving every multicast.
3058 */
3059 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
3060 hash = tulip_mchash(etherbroadcastaddr);
3061#if BYTE_ORDER == BIG_ENDIAN
3062 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3063#else
3064 sp[hash >> 4] |= 1 << (hash & 0xF);
3065#endif
3066 if (sc->tulip_flags & TULIP_WANTHASHONLY) {
3067 hash = tulip_mchash(sc->tulip_enaddr);
3068#if BYTE_ORDER == BIG_ENDIAN
3069 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3070#else
3071 sp[hash >> 4] |= 1 << (hash & 0xF);
3072#endif
3073 } else {
3074#if BYTE_ORDER == BIG_ENDIAN
3075 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
3076 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
3077 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
3078#else
3079 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0];
3080 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1];
3081 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2];
3082#endif
3083 }
3084 }
3085 }
3086 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
3087 u_int32_t *sp = sc->tulip_setupdata;
3088 int idx = 0;
3089 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
3090 /*
3091 * Else can get perfect filtering for 16 addresses.
3092 */
3093 TAILQ_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
3094 if (ifma->ifma_addr->sa_family != AF_LINK)
3095 continue;
3096 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
3097#if BYTE_ORDER == BIG_ENDIAN
3098 *sp++ = ((u_int16_t *) addrp)[0] << 16;
3099 *sp++ = ((u_int16_t *) addrp)[1] << 16;
3100 *sp++ = ((u_int16_t *) addrp)[2] << 16;
3101#else
3102 *sp++ = ((u_int16_t *) addrp)[0];
3103 *sp++ = ((u_int16_t *) addrp)[1];
3104 *sp++ = ((u_int16_t *) addrp)[2];
3105#endif
3106 idx++;
3107 }
3108 /*
3109 * Add the broadcast address.
3110 */
3111 idx++;
3112#if BYTE_ORDER == BIG_ENDIAN
3113 *sp++ = 0xFFFF << 16;
3114 *sp++ = 0xFFFF << 16;
3115 *sp++ = 0xFFFF << 16;
3116#else
3117 *sp++ = 0xFFFF;
3118 *sp++ = 0xFFFF;
3119 *sp++ = 0xFFFF;
3120#endif
3121 }
3122 /*
3123 * Pad the rest with our hardware address
3124 */
3125 for (; idx < 16; idx++) {
3126#if BYTE_ORDER == BIG_ENDIAN
3127 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
3128 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
3129 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
3130#else
3131 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0];
3132 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1];
3133 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2];
3134#endif
3135 }
3136 }
3137#if defined(IFF_ALLMULTI)
3138 if (sc->tulip_flags & TULIP_ALLMULTI)
3139 sc->tulip_if.if_flags |= IFF_ALLMULTI;
3140#endif
3141}
3142
3143static void
3144tulip_reset(
3145 tulip_softc_t * const sc)
3146{
3147 tulip_ringinfo_t *ri;
3148 tulip_desc_t *di;
3149 u_int32_t inreset = (sc->tulip_flags & TULIP_INRESET);
3150
3151 /*
3152 * Brilliant. Simply brilliant. When switching modes/speeds
3153 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
3154 * bits in CSR6 and then do a software reset to get the 21140
3155 * to properly reset its internal pathways to the right places.
3156 * Grrrr.
3157 */
3158 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
3159 && sc->tulip_boardsw->bd_media_preset != NULL)
3160 (*sc->tulip_boardsw->bd_media_preset)(sc);
3161
3162 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
3163 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
3164 33MHz that comes to two microseconds but wait a
3165 bit longer anyways) */
3166
3167 if (!inreset) {
3168 sc->tulip_flags |= TULIP_INRESET;
3169 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
3170 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
3171 sc->tulip_if.if_start = tulip_ifstart;
3172 }
3173
3174#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3175 TULIP_CSR_WRITE(sc, csr_txlist, sc->tulip_txdescmap->dm_segs[0].ds_addr);
3176#else
3177 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
3178#endif
3179#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3180 TULIP_CSR_WRITE(sc, csr_rxlist, sc->tulip_rxdescmap->dm_segs[0].ds_addr);
3181#else
3182 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
3183#endif
3184 TULIP_CSR_WRITE(sc, csr_busmode,
3185 (1 << (3 /*pci_max_burst_len*/ + 8))
3186 |TULIP_BUSMODE_CACHE_ALIGN8
3187 |TULIP_BUSMODE_READMULTIPLE
3188 |(BYTE_ORDER != LITTLE_ENDIAN ?
3189 TULIP_BUSMODE_DESC_BIGENDIAN : 0));
3190
3191 sc->tulip_txtimer = 0;
3192 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
3193 /*
3194 * Free all the mbufs that were on the transmit ring.
3195 */
3196 for (;;) {
3197#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3198 bus_dmamap_t map;
3199#endif
3200 struct mbuf *m;
3201 _IF_DEQUEUE(&sc->tulip_txq, m);
3202 if (m == NULL)
3203 break;
3204#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3205 map = M_GETCTX(m, bus_dmamap_t);
3206 bus_dmamap_unload(sc->tulip_dmatag, map);
3207 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
3208#endif
3209 m_freem(m);
3210 }
3211
3212 ri = &sc->tulip_txinfo;
3213 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
3214 ri->ri_free = ri->ri_max;
3215 for (di = ri->ri_first; di < ri->ri_last; di++)
3216 di->d_status = 0;
3217#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3218 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_txdescmap,
3219 0, sc->tulip_txdescmap->dm_mapsize,
3220 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
3221#endif
3222
3223 /*
3224 * We need to collect all the mbufs were on the
3225 * receive ring before we reinit it either to put
3226 * them back on or to know if we have to allocate
3227 * more.
3228 */
3229 ri = &sc->tulip_rxinfo;
3230 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
3231 ri->ri_free = ri->ri_max;
3232 for (di = ri->ri_first; di < ri->ri_last; di++) {
3233 di->d_status = 0;
3234 di->d_length1 = 0; di->d_addr1 = 0;
3235 di->d_length2 = 0; di->d_addr2 = 0;
3236 }
3237#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3238 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_rxdescmap,
3239 0, sc->tulip_rxdescmap->dm_mapsize,
3240 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
3241#endif
3242 for (;;) {
3243#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3244 bus_dmamap_t map;
3245#endif
3246 struct mbuf *m;
3247 _IF_DEQUEUE(&sc->tulip_rxq, m);
3248 if (m == NULL)
3249 break;
3250#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3251 map = M_GETCTX(m, bus_dmamap_t);
3252 bus_dmamap_unload(sc->tulip_dmatag, map);
3253 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3254#endif
3255 m_freem(m);
3256 }
3257
3258 /*
3259 * If tulip_reset is being called recurisvely, exit quickly knowing
3260 * that when the outer tulip_reset returns all the right stuff will
3261 * have happened.
3262 */
3263 if (inreset)
3264 return;
3265
3266 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
3267 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
3268 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
3269 |TULIP_STS_RXSTOPPED;
3270
3271 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
3272 (*sc->tulip_boardsw->bd_media_select)(sc);
3273#if defined(TULIP_DEBUG)
3274 if ((sc->tulip_flags & TULIP_NEEDRESET) == TULIP_NEEDRESET)
3275 printf("%s%d: tulip_reset: additional reset needed?!?\n",
3276 sc->tulip_name, sc->tulip_unit);
3277#endif
3278 tulip_media_print(sc);
3279 if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
3280 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
3281
3282 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
3283 |TULIP_RXACT);
3284 tulip_addr_filter(sc);
3285}
3286
3287
3288static void
3289tulip_ifinit(
3290 void * sc)
3291{
3292 tulip_init((tulip_softc_t *)sc);
3293}
3294
3295static void
3296tulip_init(
3297 tulip_softc_t * const sc)
3298{
3299 if (sc->tulip_if.if_flags & IFF_UP) {
3300 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) {
3301 /* initialize the media */
3302 tulip_reset(sc);
3303 }
3304 sc->tulip_if.if_flags |= IFF_RUNNING;
3305 if (sc->tulip_if.if_flags & IFF_PROMISC) {
3306 sc->tulip_flags |= TULIP_PROMISC;
3307 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
3308 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3309 } else {
3310 sc->tulip_flags &= ~TULIP_PROMISC;
3311 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
3312 if (sc->tulip_flags & TULIP_ALLMULTI) {
3313 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
3314 } else {
3315 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
3316 }
3317 }
3318 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
3319 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
3320 tulip_rx_intr(sc);
3321 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3322 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3323 } else {
3324 sc->tulip_if.if_flags |= IFF_OACTIVE;
3325 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3326 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3327 }
3328 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3329 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3330 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3331 tulip_txput_setup(sc);
3332 } else {
3333 sc->tulip_if.if_flags &= ~IFF_RUNNING;
3334 tulip_reset(sc);
3335 }
3336}
3337
3338static void
3339tulip_rx_intr(
3340 tulip_softc_t * const sc)
3341{
3342 TULIP_PERFSTART(rxintr)
3343 tulip_ringinfo_t * const ri = &sc->tulip_rxinfo;
3344 struct ifnet * const ifp = &sc->tulip_if;
3345 int fillok = 1;
3346#if defined(TULIP_DEBUG)
3347 int cnt = 0;
3348#endif
3349
3350 for (;;) {
3351 TULIP_PERFSTART(rxget)
3352 struct ether_header eh;
3353 tulip_desc_t *eop = ri->ri_nextin;
3354 int total_len = 0, last_offset = 0;
3355 struct mbuf *ms = NULL, *me = NULL;
3356 int accept = 0;
3357#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3358 bus_dmamap_t map;
3359 int error;
3360#endif
3361
3362 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
3363 goto queue_mbuf;
3364
3365#if defined(TULIP_DEBUG)
3366 if (cnt == ri->ri_max)
3367 break;
3368#endif
3369 /*
3370 * If the TULIP has no descriptors, there can't be any receive
3371 * descriptors to process.
3372 */
3373 if (eop == ri->ri_nextout)
3374 break;
3375
3376 /*
3377 * 90% of the packets will fit in one descriptor. So we optimize
3378 * for that case.
3379 */
3380 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3381 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
3382 _IF_DEQUEUE(&sc->tulip_rxq, ms);
3383 me = ms;
3384 } else {
3385 /*
3386 * If still owned by the TULIP, don't touch it.
3387 */
3388 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
3389 break;
3390
3391 /*
3392 * It is possible (though improbable unless the BIG_PACKET support
3393 * is enabled or MCLBYTES < 1518) for a received packet to cross
3394 * more than one receive descriptor.
3395 */
3396 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) {
3397 if (++eop == ri->ri_last)
3398 eop = ri->ri_first;
3399 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3400 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
3401#if defined(TULIP_DEBUG)
3402 sc->tulip_dbg.dbg_rxintrs++;
3403 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
3404#endif
3405 TULIP_PERFEND(rxget);
3406 TULIP_PERFEND(rxintr);
3407 return;
3408 }
3409 total_len++;
3410 }
3411
3412 /*
3413 * Dequeue the first buffer for the start of the packet. Hopefully
3414 * this will be the only one we need to dequeue. However, if the
3415 * packet consumed multiple descriptors, then we need to dequeue
3416 * those buffers and chain to the starting mbuf. All buffers but
3417 * the last buffer have the same length so we can set that now.
3418 * (we add to last_offset instead of multiplying since we normally
3419 * won't go into the loop and thereby saving a ourselves from
3420 * doing a multiplication by 0 in the normal case).
3421 */
3422 _IF_DEQUEUE(&sc->tulip_rxq, ms);
3423 for (me = ms; total_len > 0; total_len--) {
3424#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3425 map = M_GETCTX(me, bus_dmamap_t);
3426 TULIP_RXMAP_POSTSYNC(sc, map);
3427 bus_dmamap_unload(sc->tulip_dmatag, map);
3428 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3429#if defined(DIAGNOSTIC)
3430 M_SETCTX(me, NULL);
3431#endif
3432#endif /* TULIP_BUS_DMA */
3433 me->m_len = TULIP_RX_BUFLEN;
3434 last_offset += TULIP_RX_BUFLEN;
3435 _IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
3436 me = me->m_next;
3437 }
3438 }
3439
3440 /*
3441 * Now get the size of received packet (minus the CRC).
3442 */
3443 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
3444 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
3445 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0
3446#ifdef BIG_PACKET
3447 || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) &&
3448 (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT|
3449 TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC|
3450 TULIP_DSTS_RxOVERFLOW)) == 0)
3451#endif
3452 )) {
3453 me->m_len = total_len - last_offset;
3454
3455#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3456 map = M_GETCTX(me, bus_dmamap_t);
3457 bus_dmamap_sync(sc->tulip_dmatag, map, 0, me->m_len,
3458 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
3459 bus_dmamap_unload(sc->tulip_dmatag, map);
3460 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3461#if defined(DIAGNOSTIC)
3462 M_SETCTX(me, NULL);
3463#endif
3464#endif /* TULIP_BUS_DMA */
3465
3466 eh = *mtod(ms, struct ether_header *);
3467#ifndef __FreeBSD__
3468 if (sc->tulip_if.if_bpf != NULL) {
3469 if (me == ms)
3470 bpf_tap(&sc->tulip_if, mtod(ms, caddr_t), total_len);
3471 else
3472 bpf_mtap(&sc->tulip_if, ms);
3473 }
3474#endif
3475 sc->tulip_flags |= TULIP_RXACT;
3476 accept = 1;
3477 } else {
3478 ifp->if_ierrors++;
3479 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3480 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3481 } else {
3482#if defined(TULIP_VERBOSE)
3483 const char *error = NULL;
3484#endif
3485 if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
3486 sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
3487#if defined(TULIP_VERBOSE)
3488 error = "frame too long";
3489#endif
3490 }
3491 if (eop->d_status & TULIP_DSTS_RxBADCRC) {
3492 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
3493 sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
3494#if defined(TULIP_VERBOSE)
3495 error = "alignment error";
3496#endif
3497 } else {
3498 sc->tulip_dot3stats.dot3StatsFCSErrors++;
3499#if defined(TULIP_VERBOSE)
3500 error = "bad crc";
3501#endif
3502 }
3503 }
3504#if defined(TULIP_VERBOSE)
3505 if (error != NULL && (sc->tulip_flags & TULIP_NOMESSAGES) == 0) {
3506 printf("%s%d: receive: %6D: %s\n",
3507 sc->tulip_name, sc->tulip_unit,
3508 mtod(ms, u_char *) + 6, ":",
3509 error);
3510 sc->tulip_flags |= TULIP_NOMESSAGES;
3511 }
3512#endif
3513 }
3514
3515#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3516 map = M_GETCTX(me, bus_dmamap_t);
3517 bus_dmamap_unload(sc->tulip_dmatag, map);
3518 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3519#if defined(DIAGNOSTIC)
3520 M_SETCTX(me, NULL);
3521#endif
3522#endif /* TULIP_BUS_DMA */
3523 }
3524#if defined(TULIP_DEBUG)
3525 cnt++;
3526#endif
3527 ifp->if_ipackets++;
3528 if (++eop == ri->ri_last)
3529 eop = ri->ri_first;
3530 ri->ri_nextin = eop;
3531 queue_mbuf:
3532 /*
3533 * Either we are priming the TULIP with mbufs (m == NULL)
3534 * or we are about to accept an mbuf for the upper layers
3535 * so we need to allocate an mbuf to replace it. If we
3536 * can't replace it, send up it anyways. This may cause
3537 * us to drop packets in the future but that's better than
3538 * being caught in livelock.
3539 *
3540 * Note that if this packet crossed multiple descriptors
3541 * we don't even try to reallocate all the mbufs here.
3542 * Instead we rely on the test of the beginning of
3543 * the loop to refill for the extra consumed mbufs.
3544 */
3545 if (accept || ms == NULL) {
3546 struct mbuf *m0;
3547 MGETHDR(m0, M_DONTWAIT, MT_DATA);
3548 if (m0 != NULL) {
3549#if defined(TULIP_COPY_RXDATA)
3550 if (!accept || total_len >= (MHLEN - 2)) {
3551#endif
3552 MCLGET(m0, M_DONTWAIT);
3553 if ((m0->m_flags & M_EXT) == 0) {
3554 m_freem(m0);
3555 m0 = NULL;
3556 }
3557#if defined(TULIP_COPY_RXDATA)
3558 }
3559#endif
3560 }
3561 if (accept
3562#if defined(TULIP_COPY_RXDATA)
3563 && m0 != NULL
3564#endif
3565 ) {
3566#if !defined(TULIP_COPY_RXDATA)
3567 ms->m_pkthdr.len = total_len;
3568 ms->m_pkthdr.rcvif = ifp;
3569 m_adj(ms, sizeof(struct ether_header));
3570 ether_input(ifp, &eh, ms);
3571#else
3572#ifdef BIG_PACKET
3573#error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
3574#endif
3575 m0->m_data += 2; /* align data after header */
3576 m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
3577 m0->m_len = m0->m_pkthdr.len = total_len;
3578 m0->m_pkthdr.rcvif = ifp;
3579 m_adj(m0, sizeof(struct ether_header));
3580 ether_input(ifp, &eh, m0);
3581 m0 = ms;
3582#endif /* ! TULIP_COPY_RXDATA */
3583 }
3584 ms = m0;
3585 }
3586 if (ms == NULL) {
3587 /*
3588 * Couldn't allocate a new buffer. Don't bother
3589 * trying to replenish the receive queue.
3590 */
3591 fillok = 0;
3592 sc->tulip_flags |= TULIP_RXBUFSLOW;
3593#if defined(TULIP_DEBUG)
3594 sc->tulip_dbg.dbg_rxlowbufs++;
3595#endif
3596 TULIP_PERFEND(rxget);
3597 continue;
3598 }
3599 /*
3600 * Now give the buffer(s) to the TULIP and save in our
3601 * receive queue.
3602 */
3603 do {
3604 tulip_desc_t * const nextout = ri->ri_nextout;
3605#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3606 if (sc->tulip_rxmaps_free > 0) {
3607 map = sc->tulip_rxmaps[--sc->tulip_rxmaps_free];
3608 } else {
3609 m_freem(ms);
3610 sc->tulip_flags |= TULIP_RXBUFSLOW;
3611#if defined(TULIP_DEBUG)
3612 sc->tulip_dbg.dbg_rxlowbufs++;
3613#endif
3614 break;
3615 }
3616 M_SETCTX(ms, map);
3617 error = bus_dmamap_load(sc->tulip_dmatag, map, mtod(ms, void *),
3618 TULIP_RX_BUFLEN, NULL, BUS_DMA_NOWAIT);
3619 if (error) {
3620 printf("%s%d: unable to load rx map, "
3621 "error = %d\n", sc->tulip_name, sc->tulip_unit, error);
3622 panic("tulip_rx_intr"); /* XXX */
3623 }
3624 nextout->d_addr1 = map->dm_segs[0].ds_addr;
3625 nextout->d_length1 = map->dm_segs[0].ds_len;
3626 if (map->dm_nsegs == 2) {
3627 nextout->d_addr2 = map->dm_segs[1].ds_addr;
3628 nextout->d_length2 = map->dm_segs[1].ds_len;
3629 } else {
3630 nextout->d_addr2 = 0;
3631 nextout->d_length2 = 0;
3632 }
3633 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(*nextout));
3634#else /* TULIP_BUS_DMA */
3635 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
3636 nextout->d_length1 = TULIP_RX_BUFLEN;
3637#endif /* TULIP_BUS_DMA */
3638 nextout->d_status = TULIP_DSTS_OWNER;
3639 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
3640 if (++ri->ri_nextout == ri->ri_last)
3641 ri->ri_nextout = ri->ri_first;
3642 me = ms->m_next;
3643 ms->m_next = NULL;
3644 _IF_ENQUEUE(&sc->tulip_rxq, ms);
3645 } while ((ms = me) != NULL);
3646
3647 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
3648 sc->tulip_flags &= ~TULIP_RXBUFSLOW;
3649 TULIP_PERFEND(rxget);
3650 }
3651
3652#if defined(TULIP_DEBUG)
3653 sc->tulip_dbg.dbg_rxintrs++;
3654 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
3655#endif
3656 TULIP_PERFEND(rxintr);
3657}
3658
3659static int
3660tulip_tx_intr(
3661 tulip_softc_t * const sc)
3662{
3663 TULIP_PERFSTART(txintr)
3664 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
3665 struct mbuf *m;
3666 int xmits = 0;
3667 int descs = 0;
3668
3669 while (ri->ri_free < ri->ri_max) {
3670 u_int32_t d_flag;
3671
3672 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
3673 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
3674 break;
3675
3676 ri->ri_free++;
3677 descs++;
3678 d_flag = ri->ri_nextin->d_flag;
3679 if (d_flag & TULIP_DFLAG_TxLASTSEG) {
3680 if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
3681 /*
3682 * We've just finished processing a setup packet.
3683 * Mark that we finished it. If there's not
3684 * another pending, startup the TULIP receiver.
3685 * Make sure we ack the RXSTOPPED so we won't get
3686 * an abormal interrupt indication.
3687 */
3688 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap);
3689 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
3690 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT)
3691 sc->tulip_flags |= TULIP_HASHONLY;
3692 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
3693 tulip_rx_intr(sc);
3694 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3695 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3696 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3697 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3698 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3699 }
3700 } else {
3701 const u_int32_t d_status = ri->ri_nextin->d_status;
3702 _IF_DEQUEUE(&sc->tulip_txq, m);
3703 if (m != NULL) {
3704#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3705 bus_dmamap_t map = M_GETCTX(m, bus_dmamap_t);
3706 TULIP_TXMAP_POSTSYNC(sc, map);
3707 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
3708#endif /* TULIP_BUS_DMA */
3709 m_freem(m);
3710#if defined(TULIP_DEBUG)
3711 } else {
3712 printf("%s%d: tx_intr: failed to dequeue mbuf?!?\n",
3713 sc->tulip_name, sc->tulip_unit);
3714#endif
3715 }
3716 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3717 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
3718 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
3719#if defined(TULIP_DEBUG)
3720 if (d_status & TULIP_DSTS_TxNOCARR)
3721 sc->tulip_dbg.dbg_txprobe_nocarr++;
3722 if (d_status & TULIP_DSTS_TxEXCCOLL)
3723 sc->tulip_dbg.dbg_txprobe_exccoll++;
3724#endif
3725 event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
3726 }
3727 (*sc->tulip_boardsw->bd_media_poll)(sc, event);
3728 /*
3729 * Escape from the loop before media poll has reset the TULIP!
3730 */
3731 break;
3732 } else {
3733 xmits++;
3734 if (d_status & TULIP_DSTS_ERRSUM) {
3735 sc->tulip_if.if_oerrors++;
3736 if (d_status & TULIP_DSTS_TxEXCCOLL)
3737 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
3738 if (d_status & TULIP_DSTS_TxLATECOLL)
3739 sc->tulip_dot3stats.dot3StatsLateCollisions++;
3740 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
3741 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
3742 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
3743 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
3744 if (d_status & TULIP_DSTS_TxUNDERFLOW)
3745 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
3746 if (d_status & TULIP_DSTS_TxBABBLE)
3747 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
3748 } else {
3749 u_int32_t collisions =
3750 (d_status & TULIP_DSTS_TxCOLLMASK)
3751 >> TULIP_DSTS_V_TxCOLLCNT;
3752 sc->tulip_if.if_collisions += collisions;
3753 if (collisions == 1)
3754 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
3755 else if (collisions > 1)
3756 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
3757 else if (d_status & TULIP_DSTS_TxDEFERRED)
3758 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
3759 /*
3760 * SQE is only valid for 10baseT/BNC/AUI when not
3761 * running in full-duplex. In order to speed up the
3762 * test, the corresponding bit in tulip_flags needs to
3763 * set as well to get us to count SQE Test Errors.
3764 */
3765 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
3766 sc->tulip_dot3stats.dot3StatsSQETestErrors++;
3767 }
3768 }
3769 }
3770 }
3771
3772 if (++ri->ri_nextin == ri->ri_last)
3773 ri->ri_nextin = ri->ri_first;
3774
3775 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3776 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
3777 }
3778 /*
3779 * If nothing left to transmit, disable the timer.
3780 * Else if progress, reset the timer back to 2 ticks.
3781 */
3782 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
3783 sc->tulip_txtimer = 0;
3784 else if (xmits > 0)
3785 sc->tulip_txtimer = TULIP_TXTIMER;
3786 sc->tulip_if.if_opackets += xmits;
3787 TULIP_PERFEND(txintr);
3788 return descs;
3789}
3790
3791static void
3792tulip_print_abnormal_interrupt(
3793 tulip_softc_t * const sc,
3794 u_int32_t csr)
3795{
3796 const char * const *msgp = tulip_status_bits;
3797 const char *sep;
3798 u_int32_t mask;
3799 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
3800
3801 csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1;
3802 printf("%s%d: abnormal interrupt:", sc->tulip_name, sc->tulip_unit);
3803 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
3804 if ((csr & mask) && *msgp != NULL) {
3805 printf("%s%s", sep, *msgp);
3806 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
3807 sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
3808 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
3809 printf(" (switching to store-and-forward mode)");
3810 } else {
3811 printf(" (raising TX threshold to %s)",
3812 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
3813 }
3814 }
3815 sep = ", ";
3816 }
3817 }
3818 printf("\n");
3819}
3820
3821static void
3822tulip_intr_handler(
3823 tulip_softc_t * const sc,
3824 int *progress_p)
3825{
3826 TULIP_PERFSTART(intr)
3827 u_int32_t csr;
3828
3829 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3830 *progress_p = 1;
3831 TULIP_CSR_WRITE(sc, csr_status, csr);
3832
3833 if (csr & TULIP_STS_SYSERROR) {
3834 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
3835 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3836 sc->tulip_flags |= TULIP_SYSTEMERROR;
3837 } else {
3838 printf("%s%d: system error: %s\n",
3839 sc->tulip_name, sc->tulip_unit,
3840 tulip_system_errors[sc->tulip_last_system_error]);
3841 }
3842 sc->tulip_flags |= TULIP_NEEDRESET;
3843 sc->tulip_system_errors++;
3844 break;
3845 }
3846 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
3847#if defined(TULIP_DEBUG)
3848 sc->tulip_dbg.dbg_link_intrs++;
3849#endif
3850 if (sc->tulip_boardsw->bd_media_poll != NULL) {
3851 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
3852 ? TULIP_MEDIAPOLL_LINKFAIL
3853 : TULIP_MEDIAPOLL_LINKPASS);
3854 csr &= ~TULIP_STS_ABNRMLINTR;
3855 }
3856 tulip_media_print(sc);
3857 }
3858 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
3859 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
3860 if (csr & TULIP_STS_RXNOBUF)
3861 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
3862 /*
3863 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3864 * on receive overflows.
3865 */
3866 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
3867 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3868 /*
3869 * Stop the receiver process and spin until it's stopped.
3870 * Tell rx_intr to drop the packets it dequeues.
3871 */
3872 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
3873 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
3874 ;
3875 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3876 sc->tulip_flags |= TULIP_RXIGNORE;
3877 }
3878 tulip_rx_intr(sc);
3879 if (sc->tulip_flags & TULIP_RXIGNORE) {
3880 /*
3881 * Restart the receiver.
3882 */
3883 sc->tulip_flags &= ~TULIP_RXIGNORE;
3884 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3885 }
3886 }
3887 if (csr & TULIP_STS_ABNRMLINTR) {
3888 u_int32_t tmp = csr & sc->tulip_intrmask
3889 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
3890 if (csr & TULIP_STS_TXUNDERFLOW) {
3891 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
3892 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
3893 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3894 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
3895 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
3896 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3897 }
3898 }
3899 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3900 sc->tulip_statusbits |= tmp;
3901 } else {
3902 tulip_print_abnormal_interrupt(sc, tmp);
3903 sc->tulip_flags |= TULIP_NOMESSAGES;
3904 }
3905 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3906 }
3907 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
3908 tulip_tx_intr(sc);
3909 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3910 tulip_ifstart(&sc->tulip_if);
3911 }
3912 }
3913 if (sc->tulip_flags & TULIP_NEEDRESET) {
3914 tulip_reset(sc);
3915 tulip_init(sc);
3916 }
3917 TULIP_PERFEND(intr);
3918}
3919
3920#if defined(TULIP_USE_SOFTINTR)
3921/*
3922 * This is a experimental idea to alleviate problems due to interrupt
3923 * livelock. What is interrupt livelock? It's when you spend all your
3924 * time servicing device interrupts and never drop below device ipl
3925 * to do "useful" work.
3926 *
3927 * So what we do here is see if the device needs service and if so,
3928 * disable interrupts (dismiss the interrupt), place it in a list of devices
3929 * needing service, and issue a network software interrupt.
3930 *
3931 * When our network software interrupt routine gets called, we simply
3932 * walk done the list of devices that we have created and deal with them
3933 * at splnet/splsoftnet.
3934 *
3935 */
3936static void
3937tulip_hardintr_handler(
3938 tulip_softc_t * const sc,
3939 int *progress_p)
3940{
3941 if (TULIP_CSR_READ(sc, csr_status) & (TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR) == 0)
3942 return;
3943 *progress_p = 1;
3944 /*
3945 * disable interrupts
3946 */
3947 TULIP_CSR_WRITE(sc, csr_intr, 0);
3948 /*
3949 * mark it as needing a software interrupt
3950 */
3951 tulip_softintr_mask |= (1U << sc->tulip_unit);
3952}
3953
3954static void
3955tulip_softintr(
3956 void)
3957{
3958 u_int32_t softintr_mask, mask;
3959 int progress = 0;
3960 int unit;
3961 int s;
3962
3963 /*
3964 * Copy mask to local copy and reset global one to 0.
3965 */
3966 s = splimp();
3967 softintr_mask = tulip_softintr_mask;
3968 tulip_softintr_mask = 0;
3969 splx(s);
3970
3971 /*
3972 * Optimize for the single unit case.
3973 */
3974 if (tulip_softintr_max_unit == 0) {
3975 if (softintr_mask & 1) {
3976 tulip_softc_t * const sc = tulips[0];
3977 /*
3978 * Handle the "interrupt" and then reenable interrupts
3979 */
3980 softintr_mask = 0;
3981 tulip_intr_handler(sc, &progress);
3982 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3983 }
3984 return;
3985 }
3986
3987 /*
3988 * Handle all "queued" interrupts in a round robin fashion.
3989 * This is done so as not to favor a particular interface.
3990 */
3991 unit = tulip_softintr_last_unit;
3992 mask = (1U << unit);
3993 while (softintr_mask != 0) {
3994 if (tulip_softintr_max_unit == unit) {
3995 unit = 0; mask = 1;
3996 } else {
3997 unit += 1; mask <<= 1;
3998 }
3999 if (softintr_mask & mask) {
4000 tulip_softc_t * const sc = tulips[unit];
4001 /*
4002 * Handle the "interrupt" and then reenable interrupts
4003 */
4004 softintr_mask ^= mask;
4005 tulip_intr_handler(sc, &progress);
4006 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4007 }
4008 }
4009
4010 /*
4011 * Save where we ending up.
4012 */
4013 tulip_softintr_last_unit = unit;
4014}
4015#endif /* TULIP_USE_SOFTINTR */
4016
4017static void
4018tulip_intr_shared(
4019 void *arg)
4020{
4021 tulip_softc_t * sc = arg;
4022 int progress = 0;
4023
4024 for (; sc != NULL; sc = sc->tulip_slaves) {
4025#if defined(TULIP_DEBUG)
4026 sc->tulip_dbg.dbg_intrs++;
4027#endif
4028#if defined(TULIP_USE_SOFTINTR)
4029 tulip_hardintr_handler(sc, &progress);
4030#else
4031 tulip_intr_handler(sc, &progress);
4032#endif
4033 }
4034#if defined(TULIP_USE_SOFTINTR)
4035 if (progress)
4036 schednetisr(NETISR_DE);
4037#endif
4038}
4039
4040static void
4041tulip_intr_normal(
4042 void *arg)
4043{
4044 tulip_softc_t * sc = (tulip_softc_t *) arg;
4045 int progress = 0;
4046
4047#if defined(TULIP_DEBUG)
4048 sc->tulip_dbg.dbg_intrs++;
4049#endif
4050#if defined(TULIP_USE_SOFTINTR)
4051 tulip_hardintr_handler(sc, &progress);
4052 if (progress)
4053 schednetisr(NETISR_DE);
4054#else
4055 tulip_intr_handler(sc, &progress);
4056#endif
4057}
4058
4059static struct mbuf *
4060tulip_mbuf_compress(
4061 struct mbuf *m)
4062{
4063 struct mbuf *m0;
4064#if MCLBYTES >= ETHERMTU + 18 && !defined(BIG_PACKET)
4065 MGETHDR(m0, M_DONTWAIT, MT_DATA);
4066 if (m0 != NULL) {
4067 if (m->m_pkthdr.len > MHLEN) {
4068 MCLGET(m0, M_DONTWAIT);
4069 if ((m0->m_flags & M_EXT) == 0) {
4070 m_freem(m);
4071 m_freem(m0);
4072 return NULL;
4073 }
4074 }
4075 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t));
4076 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len;
4077 }
4078#else
4079 int mlen = MHLEN;
4080 int len = m->m_pkthdr.len;
4081 struct mbuf **mp = &m0;
4082
4083 while (len > 0) {
4084 if (mlen == MHLEN) {
4085 MGETHDR(*mp, M_DONTWAIT, MT_DATA);
4086 } else {
4087 MGET(*mp, M_DONTWAIT, MT_DATA);
4088 }
4089 if (*mp == NULL) {
4090 m_freem(m0);
4091 m0 = NULL;
4092 break;
4093 }
4094 if (len > MLEN) {
4095 MCLGET(*mp, M_DONTWAIT);
4096 if (((*mp)->m_flags & M_EXT) == 0) {
4097 m_freem(m0);
4098 m0 = NULL;
4099 break;
4100 }
4101 (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES;
4102 } else {
4103 (*mp)->m_len = len <= mlen ? len : mlen;
4104 }
4105 m_copydata(m, m->m_pkthdr.len - len,
4106 (*mp)->m_len, mtod((*mp), caddr_t));
4107 len -= (*mp)->m_len;
4108 mp = &(*mp)->m_next;
4109 mlen = MLEN;
4110 }
4111#endif
4112 m_freem(m);
4113 return m0;
4114}
4115
4116static struct mbuf *
4117tulip_txput(
4118 tulip_softc_t * const sc,
4119 struct mbuf *m)
4120{
4121 TULIP_PERFSTART(txput)
4122 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
4123 tulip_desc_t *eop, *nextout;
4124 int segcnt, free;
4125 u_int32_t d_status;
4126#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
4127 bus_dmamap_t map;
4128 int error;
4129#else
4130 struct mbuf *m0;
4131#endif
4132
4133#if defined(TULIP_DEBUG)
4134 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
4135 printf("%s%d: txput%s: tx not running\n",
4136 sc->tulip_name, sc->tulip_unit,
4137 (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : "");
4138 sc->tulip_flags |= TULIP_WANTTXSTART;
4139 sc->tulip_dbg.dbg_txput_finishes[0]++;
4140 goto finish;
4141 }
4142#endif
4143
4144 /*
4145 * Now we try to fill in our transmit descriptors. This is
4146 * a bit reminiscent of going on the Ark two by two
4147 * since each descriptor for the TULIP can describe
4148 * two buffers. So we advance through packet filling
4149 * each of the two entries at a time to to fill each
4150 * descriptor. Clear the first and last segment bits
4151 * in each descriptor (actually just clear everything
4152 * but the end-of-ring or chain bits) to make sure
4153 * we don't get messed up by previously sent packets.
4154 *
4155 * We may fail to put the entire packet on the ring if
4156 * there is either not enough ring entries free or if the
4157 * packet has more than MAX_TXSEG segments. In the former
4158 * case we will just wait for the ring to empty. In the
4159 * latter case we have to recopy.
4160 */
4161#if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX)
4162 again:
4163 m0 = m;
4164#endif
4165 d_status = 0;
4166 eop = nextout = ri->ri_nextout;
4167 segcnt = 0;
4168 free = ri->ri_free;
4169
4170#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
4171 /*
4172 * Reclaim some dma maps from if we are out.
4173 */
4174 if (sc->tulip_txmaps_free == 0) {
4175#if defined(TULIP_DEBUG)
4176 sc->tulip_dbg.dbg_no_txmaps++;
4177#endif
4178 free += tulip_tx_intr(sc);
4179 }
4180 if (sc->tulip_txmaps_free > 0) {
4181 map = sc->tulip_txmaps[sc->tulip_txmaps_free-1];
4182 } else {
4183 sc->tulip_flags |= TULIP_WANTTXSTART;
4184#if defined(TULIP_DEBUG)
4185 sc->tulip_dbg.dbg_txput_finishes[1]++;
4186#endif
4187 goto finish;
4188 }
4189 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT);
4190 if (error != 0) {
4191 if (error == EFBIG) {
4192 /*
4193 * The packet exceeds the number of transmit buffer
4194 * entries that we can use for one packet, so we have
4195 * to recopy it into one mbuf and then try again.
4196 */
4197 m = tulip_mbuf_compress(m);
4198 if (m == NULL) {
4199#if defined(TULIP_DEBUG)
4200 sc->tulip_dbg.dbg_txput_finishes[2]++;
4201#endif
4202 goto finish;
4203 }
4204 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT);
4205 }
4206 if (error != 0) {
4207 printf("%s%d: unable to load tx map, "
4208 "error = %d\n", sc->tulip_name, sc->tulip_unit, error);
4209#if defined(TULIP_DEBUG)
4210 sc->tulip_dbg.dbg_txput_finishes[3]++;
4211#endif
4212 goto finish;
4213 }
4214 }
4215 if ((free -= (map->dm_nsegs + 1) / 2) <= 0
4216 /*
4217 * See if there's any unclaimed space in the transmit ring.
4218 */
4219 && (free += tulip_tx_intr(sc)) <= 0) {
4220 /*
4221 * There's no more room but since nothing
4222 * has been committed at this point, just
4223 * show output is active, put back the
4224 * mbuf and return.
4225 */
4226 sc->tulip_flags |= TULIP_WANTTXSTART;
4227#if defined(TULIP_DEBUG)
4228 sc->tulip_dbg.dbg_txput_finishes[4]++;
4229#endif
4230 bus_dmamap_unload(sc->tulip_dmatag, map);
4231 goto finish;
4232 }
4233 for (; map->dm_nsegs - segcnt > 1; segcnt += 2) {
4234 eop = nextout;
4235 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4236 eop->d_status = d_status;
4237 eop->d_addr1 = map->dm_segs[segcnt].ds_addr;
4238 eop->d_length1 = map->dm_segs[segcnt].ds_len;
4239 eop->d_addr2 = map->dm_segs[segcnt+1].ds_addr;
4240 eop->d_length2 = map->dm_segs[segcnt+1].ds_len;
4241 d_status = TULIP_DSTS_OWNER;
4242 if (++nextout == ri->ri_last)
4243 nextout = ri->ri_first;
4244 }
4245 if (segcnt < map->dm_nsegs) {
4246 eop = nextout;
4247 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4248 eop->d_status = d_status;
4249 eop->d_addr1 = map->dm_segs[segcnt].ds_addr;
4250 eop->d_length1 = map->dm_segs[segcnt].ds_len;
4251 eop->d_addr2 = 0;
4252 eop->d_length2 = 0;
4253 if (++nextout == ri->ri_last)
4254 nextout = ri->ri_first;
4255 }
4256 TULIP_TXMAP_PRESYNC(sc, map);
4257 M_SETCTX(m, map);
4258 map = NULL;
4259 --sc->tulip_txmaps_free; /* commit to using the dmamap */
4260
4261#else /* !TULIP_BUS_DMA */
4262
4263 do {
4264 int len = m0->m_len;
4265 caddr_t addr = mtod(m0, caddr_t);
4266 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1));
4267
4268 while (len > 0) {
4269 unsigned slen = min(len, clsize);
4270#ifdef BIG_PACKET
4271 int partial = 0;
4272 if (slen >= 2048)
4273 slen = 2040, partial = 1;
4274#endif
4275 segcnt++;
4276 if (segcnt > TULIP_MAX_TXSEG) {
4277 /*
4278 * The packet exceeds the number of transmit buffer
4279 * entries that we can use for one packet, so we have
4280 * recopy it into one mbuf and then try again.
4281 */
4282 m = tulip_mbuf_compress(m);
4283 if (m == NULL)
4284 goto finish;
4285 goto again;
4286 }
4287 if (segcnt & 1) {
4288 if (--free == 0) {
4289 /*
4290 * See if there's any unclaimed space in the
4291 * transmit ring.
4292 */
4293 if ((free += tulip_tx_intr(sc)) == 0) {
4294 /*
4295 * There's no more room but since nothing
4296 * has been committed at this point, just
4297 * show output is active, put back the
4298 * mbuf and return.
4299 */
4300 sc->tulip_flags |= TULIP_WANTTXSTART;
4301#if defined(TULIP_DEBUG)
4302 sc->tulip_dbg.dbg_txput_finishes[1]++;
4303#endif
4304 goto finish;
4305 }
4306 }
4307 eop = nextout;
4308 if (++nextout == ri->ri_last)
4309 nextout = ri->ri_first;
4310 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4311 eop->d_status = d_status;
4312 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr);
4313 eop->d_length1 = slen;
4314 } else {
4315 /*
4316 * Fill in second half of descriptor
4317 */
4318 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr);
4319 eop->d_length2 = slen;
4320 }
4321 d_status = TULIP_DSTS_OWNER;
4322 len -= slen;
4323 addr += slen;
4324#ifdef BIG_PACKET
4325 if (partial)
4326 continue;
4327#endif
4328 clsize = PAGE_SIZE;
4329 }
4330 } while ((m0 = m0->m_next) != NULL);
4331#endif /* TULIP_BUS_DMA */
4332
4333 /*
4334 * bounce a copy to the bpf listener, if any.
4335 */
4336 if (sc->tulip_if.if_bpf != NULL)
4337 bpf_mtap(&sc->tulip_if, m);
4338
4339 /*
4340 * The descriptors have been filled in. Now get ready
4341 * to transmit.
4342 */
4343 _IF_ENQUEUE(&sc->tulip_txq, m);
4344 m = NULL;
4345
4346 /*
4347 * Make sure the next descriptor after this packet is owned
4348 * by us since it may have been set up above if we ran out
4349 * of room in the ring.
4350 */
4351 nextout->d_status = 0;
4352 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
4353
4354#if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX)
4355 /*
4356 * If we only used the first segment of the last descriptor,
4357 * make sure the second segment will not be used.
4358 */
4359 if (segcnt & 1) {
4360 eop->d_addr2 = 0;
4361 eop->d_length2 = 0;
4362 }
4363#endif /* TULIP_BUS_DMA */
4364
4365 /*
4366 * Mark the last and first segments, indicate we want a transmit
4367 * complete interrupt, and tell it to transmit!
4368 */
4369 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
4370
4371 /*
4372 * Note that ri->ri_nextout is still the start of the packet
4373 * and until we set the OWNER bit, we can still back out of
4374 * everything we have done.
4375 */
4376 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
4377#if defined(TULIP_BUS_MAP) && !defined(TULIP_BUS_DMA_NOTX)
4378 if (eop < ri->ri_nextout) {
4379 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout,
4380 (caddr_t) ri->ri_last - (caddr_t) ri->ri_nextout);
4381 TULIP_TXDESC_PRESYNC(sc, ri->ri_first,
4382 (caddr_t) (eop + 1) - (caddr_t) ri->ri_first);
4383 } else {
4384 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout,
4385 (caddr_t) (eop + 1) - (caddr_t) ri->ri_nextout);
4386 }
4387#endif
4388 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
4389 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
4390
4391 /*
4392 * This advances the ring for us.
4393 */
4394 ri->ri_nextout = nextout;
4395 ri->ri_free = free;
4396
4397 TULIP_PERFEND(txput);
4398
4399 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
4400 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4401 sc->tulip_if.if_flags |= IFF_OACTIVE;
4402 sc->tulip_if.if_start = tulip_ifstart;
4403 TULIP_PERFEND(txput);
4404 return NULL;
4405 }
4406
4407 /*
4408 * switch back to the single queueing ifstart.
4409 */
4410 sc->tulip_flags &= ~TULIP_WANTTXSTART;
4411 if (sc->tulip_txtimer == 0)
4412 sc->tulip_txtimer = TULIP_TXTIMER;
4413#if defined(TULIP_DEBUG)
4414 sc->tulip_dbg.dbg_txput_finishes[5]++;
4415#endif
4416
4417 /*
4418 * If we want a txstart, there must be not enough space in the
4419 * transmit ring. So we want to enable transmit done interrupts
4420 * so we can immediately reclaim some space. When the transmit
4421 * interrupt is posted, the interrupt handler will call tx_intr
4422 * to reclaim space and then txstart (since WANTTXSTART is set).
4423 * txstart will move the packet into the transmit ring and clear
4424 * WANTTXSTART thereby causing TXINTR to be cleared.
4425 */
4426 finish:
4427#if defined(TULIP_DEBUG)
4428 sc->tulip_dbg.dbg_txput_finishes[6]++;
4429#endif
4430 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
4431 sc->tulip_if.if_flags |= IFF_OACTIVE;
4432 sc->tulip_if.if_start = tulip_ifstart;
4433 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
4434 sc->tulip_intrmask |= TULIP_STS_TXINTR;
4435 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4436 }
4437 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) {
4438 if (sc->tulip_intrmask & TULIP_STS_TXINTR) {
4439 sc->tulip_intrmask &= ~TULIP_STS_TXINTR;
4440 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4441 }
4442 }
4443 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4444 TULIP_PERFEND(txput);
4445 return m;
4446}
4447
4448static void
4449tulip_txput_setup(
4450 tulip_softc_t * const sc)
4451{
4452 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
4453 tulip_desc_t *nextout;
4454
4455 /*
4456 * We will transmit, at most, one setup packet per call to ifstart.
4457 */
4458
4459#if defined(TULIP_DEBUG)
4460 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
4461 printf("%s%d: txput_setup: tx not running\n",
4462 sc->tulip_name, sc->tulip_unit);
4463 sc->tulip_flags |= TULIP_WANTTXSTART;
4464 sc->tulip_if.if_start = tulip_ifstart;
4465 return;
4466 }
4467#endif
4468 /*
4469 * Try to reclaim some free descriptors..
4470 */
4471 if (ri->ri_free < 2)
4472 tulip_tx_intr(sc);
4473 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
4474 sc->tulip_flags |= TULIP_WANTTXSTART;
4475 sc->tulip_if.if_start = tulip_ifstart;
4476 return;
4477 }
4478 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
4479 sizeof(sc->tulip_setupbuf));
4480 /*
4481 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is
4482 * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
4483 */
4484 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP;
4485 ri->ri_free--;
4486 nextout = ri->ri_nextout;
4487 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4488 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
4489 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
4490 if (sc->tulip_flags & TULIP_WANTHASHPERFECT)
4491 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
4492 else if (sc->tulip_flags & TULIP_WANTHASHONLY)
4493 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT;
4494
4495 nextout->d_length2 = 0;
4496 nextout->d_addr2 = 0;
4497#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
4498 nextout->d_length1 = sc->tulip_setupmap->dm_segs[0].ds_len;
4499 nextout->d_addr1 = sc->tulip_setupmap->dm_segs[0].ds_addr;
4500 if (sc->tulip_setupmap->dm_nsegs == 2) {
4501 nextout->d_length2 = sc->tulip_setupmap->dm_segs[1].ds_len;
4502 nextout->d_addr2 = sc->tulip_setupmap->dm_segs[1].ds_addr;
4503 }
4504 TULIP_TXMAP_PRESYNC(sc, sc->tulip_setupmap);
4505 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(*nextout));
4506#else
4507 nextout->d_length1 = sizeof(sc->tulip_setupbuf);
4508 nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
4509#endif
4510
4511 /*
4512 * Advance the ring for the next transmit packet.
4513 */
4514 if (++ri->ri_nextout == ri->ri_last)
4515 ri->ri_nextout = ri->ri_first;
4516
4517 /*
4518 * Make sure the next descriptor is owned by us since it
4519 * may have been set up above if we ran out of room in the
4520 * ring.
4521 */
4522 ri->ri_nextout->d_status = 0;
4523 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
4524 nextout->d_status = TULIP_DSTS_OWNER;
4525 /*
4526 * Flush the ownwership of the current descriptor
4527 */
4528 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
4529 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4530 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
4531 sc->tulip_intrmask |= TULIP_STS_TXINTR;
4532 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4533 }
4534}
4535
4536
4537/*
4538 * This routine is entered at splnet() (splsoftnet() on NetBSD)
4539 * and thereby imposes no problems when TULIP_USE_SOFTINTR is
4540 * defined or not.
4541 */
4542static int
4543tulip_ifioctl(
4544 struct ifnet * ifp,
4545 u_long cmd,
4546 caddr_t data)
4547{
4548 TULIP_PERFSTART(ifioctl)
4549 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4550 struct ifreq *ifr = (struct ifreq *) data;
4551 int s;
4552 int error = 0;
4553
4554#if defined(TULIP_USE_SOFTINTR)
4555 s = splnet();
4556#else
4557 s = splimp();
4558#endif
4559 switch (cmd) {
4560 case SIOCSIFADDR:
4561 case SIOCGIFADDR: {
4562 error = ether_ioctl(ifp, cmd, data);
4563 break;
4564 }
4565
4566 case SIOCSIFFLAGS: {
4567 tulip_addr_filter(sc); /* reinit multicast filter */
4568 tulip_init(sc);
4569 break;
4570 }
4571
4572 case SIOCSIFMEDIA:
4573 case SIOCGIFMEDIA: {
4574 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
4575 break;
4576 }
4577
4578 case SIOCADDMULTI:
4579 case SIOCDELMULTI: {
4580 /*
4581 * Update multicast listeners
4582 */
4583 tulip_addr_filter(sc); /* reset multicast filtering */
4584 tulip_init(sc);
4585 error = 0;
4586 break;
4587 }
4588
4589 case SIOCSIFMTU:
4590 /*
4591 * Set the interface MTU.
4592 */
4593 if (ifr->ifr_mtu > ETHERMTU
4594#ifdef BIG_PACKET
4595 && sc->tulip_chipid != TULIP_21140
4596 && sc->tulip_chipid != TULIP_21140A
4597 && sc->tulip_chipid != TULIP_21041
4598#endif
4599 ) {
4600 error = EINVAL;
4601 break;
4602 }
4603 ifp->if_mtu = ifr->ifr_mtu;
4604#ifdef BIG_PACKET
4605 tulip_reset(sc);
4606 tulip_init(sc);
4607#endif
4608 break;
4609
4610#ifdef SIOCGADDRROM
4611 case SIOCGADDRROM: {
4612 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
4613 break;
4614 }
4615#endif
4616#ifdef SIOCGCHIPID
4617 case SIOCGCHIPID: {
4618 ifr->ifr_metric = (int) sc->tulip_chipid;
4619 break;
4620 }
4621#endif
4622 default: {
4623 error = EINVAL;
4624 break;
4625 }
4626 }
4627
4628 splx(s);
4629 TULIP_PERFEND(ifioctl);
4630 return error;
4631}
4632
4633/*
4634 * These routines gets called at device spl (from ether_output). This might
4635 * pose a problem for TULIP_USE_SOFTINTR if ether_output is called at
4636 * device spl from another driver.
4637 */
4638
4639static void
4640tulip_ifstart(
4641 struct ifnet * const ifp)
4642{
4643 TULIP_PERFSTART(ifstart)
4644 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4645
4646 if (sc->tulip_if.if_flags & IFF_RUNNING) {
4647
4648 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
4649 tulip_txput_setup(sc);
4650
4651 while (sc->tulip_if.if_snd.ifq_head != NULL) {
4652 struct mbuf *m;
4653 IF_DEQUEUE(&sc->tulip_if.if_snd, m);
4654 if ((m = tulip_txput(sc, m)) != NULL) {
4655 IF_PREPEND(&sc->tulip_if.if_snd, m);
4656 break;
4657 }
4658 }
4659 if (sc->tulip_if.if_snd.ifq_head == NULL)
4660 sc->tulip_if.if_start = tulip_ifstart_one;
4661 }
4662
4663 TULIP_PERFEND(ifstart);
4664}
4665
4666static void
4667tulip_ifstart_one(
4668 struct ifnet * const ifp)
4669{
4670 TULIP_PERFSTART(ifstart_one)
4671 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4672
4673 if ((sc->tulip_if.if_flags & IFF_RUNNING)
4674 && sc->tulip_if.if_snd.ifq_head != NULL) {
4675 struct mbuf *m;
4676 IF_DEQUEUE(&sc->tulip_if.if_snd, m);
4677 if ((m = tulip_txput(sc, m)) != NULL)
4678 IF_PREPEND(&sc->tulip_if.if_snd, m);
4679 }
4680 TULIP_PERFEND(ifstart_one);
4681}
4682
4683/*
4684 * Even though this routine runs at device spl, it does not break
4685 * our use of splnet (splsoftnet under NetBSD) for the majority
4686 * of this driver (if TULIP_USE_SOFTINTR defined) since
4687 * if_watcbog is called from if_watchdog which is called from
4688 * splsoftclock which is below spl[soft]net.
4689 */
4690static void
4691tulip_ifwatchdog(
4692 struct ifnet *ifp)
4693{
4694 TULIP_PERFSTART(ifwatchdog)
4695 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4696
4697#if defined(TULIP_DEBUG)
4698 u_int32_t rxintrs = sc->tulip_dbg.dbg_rxintrs - sc->tulip_dbg.dbg_last_rxintrs;
4699 if (rxintrs > sc->tulip_dbg.dbg_high_rxintrs_hz)
4700 sc->tulip_dbg.dbg_high_rxintrs_hz = rxintrs;
4701 sc->tulip_dbg.dbg_last_rxintrs = sc->tulip_dbg.dbg_rxintrs;
4702#endif /* TULIP_DEBUG */
4703
4704 sc->tulip_if.if_timer = 1;
4705 /*
4706 * These should be rare so do a bulk test up front so we can just skip
4707 * them if needed.
4708 */
4709 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) {
4710 /*
4711 * If the number of receive buffer is low, try to refill
4712 */
4713 if (sc->tulip_flags & TULIP_RXBUFSLOW)
4714 tulip_rx_intr(sc);
4715
4716 if (sc->tulip_flags & TULIP_SYSTEMERROR) {
4717 printf("%s%d: %d system errors: last was %s\n",
4718 sc->tulip_name, sc->tulip_unit, sc->tulip_system_errors,
4719 tulip_system_errors[sc->tulip_last_system_error]);
4720 }
4721 if (sc->tulip_statusbits) {
4722 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
4723 sc->tulip_statusbits = 0;
4724 }
4725
4726 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR);
4727 }
4728
4729 if (sc->tulip_txtimer)
4730 tulip_tx_intr(sc);
4731 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
4732 printf("%s%d: transmission timeout\n", sc->tulip_name, sc->tulip_unit);
4733 if (TULIP_DO_AUTOSENSE(sc)) {
4734 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
4735 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
4736 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP);
4737 }
4738 tulip_reset(sc);
4739 tulip_init(sc);
4740 }
4741
4742 TULIP_PERFEND(ifwatchdog);
4743 TULIP_PERFMERGE(sc, perf_intr_cycles);
4744 TULIP_PERFMERGE(sc, perf_ifstart_cycles);
4745 TULIP_PERFMERGE(sc, perf_ifioctl_cycles);
4746 TULIP_PERFMERGE(sc, perf_ifwatchdog_cycles);
4747 TULIP_PERFMERGE(sc, perf_timeout_cycles);
4748 TULIP_PERFMERGE(sc, perf_ifstart_one_cycles);
4749 TULIP_PERFMERGE(sc, perf_txput_cycles);
4750 TULIP_PERFMERGE(sc, perf_txintr_cycles);
4751 TULIP_PERFMERGE(sc, perf_rxintr_cycles);
4752 TULIP_PERFMERGE(sc, perf_rxget_cycles);
4753 TULIP_PERFMERGE(sc, perf_intr);
4754 TULIP_PERFMERGE(sc, perf_ifstart);
4755 TULIP_PERFMERGE(sc, perf_ifioctl);
4756 TULIP_PERFMERGE(sc, perf_ifwatchdog);
4757 TULIP_PERFMERGE(sc, perf_timeout);
4758 TULIP_PERFMERGE(sc, perf_ifstart_one);
4759 TULIP_PERFMERGE(sc, perf_txput);
4760 TULIP_PERFMERGE(sc, perf_txintr);
4761 TULIP_PERFMERGE(sc, perf_rxintr);
4762 TULIP_PERFMERGE(sc, perf_rxget);
4763}
4764
4765/*
4766 * All printf's are real as of now!
4767 */
4768#ifdef printf
4769#undef printf
4770#endif
4771
4772static void
4773tulip_attach(
4774 tulip_softc_t * const sc)
4775{
4776 struct ifnet * const ifp = &sc->tulip_if;
4777
4778 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
4779 ifp->if_ioctl = tulip_ifioctl;
4780 ifp->if_start = tulip_ifstart;
4781 ifp->if_watchdog = tulip_ifwatchdog;
4782 ifp->if_timer = 1;
4783 ifp->if_output = ether_output;
4784 ifp->if_init = tulip_ifinit;
4785
4786 printf("%s%d: %s%s pass %d.%d%s\n",
4787 sc->tulip_name, sc->tulip_unit,
4788 sc->tulip_boardid,
4789 tulip_chipdescs[sc->tulip_chipid],
4790 (sc->tulip_revinfo & 0xF0) >> 4,
4791 sc->tulip_revinfo & 0x0F,
4792 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM))
4793 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "");
4794 printf("%s%d: address %6D\n",
4795 sc->tulip_name, sc->tulip_unit, sc->tulip_enaddr, ":");
4796
4797#if defined(__alpha__)
4798 /*
4799 * In case the SRM console told us about a bogus media,
4800 * we need to check to be safe.
4801 */
4802 if (sc->tulip_mediums[sc->tulip_media] == NULL)
4803 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
4804#endif
4805
4806 (*sc->tulip_boardsw->bd_media_probe)(sc);
4807 ifmedia_init(&sc->tulip_ifmedia, 0,
4808 tulip_ifmedia_change,
4809 tulip_ifmedia_status);
4810 sc->tulip_flags &= ~TULIP_DEVICEPROBE;
4811 tulip_ifmedia_add(sc);
4812
4813 tulip_reset(sc);
4814
4815 ether_ifattach(&(sc)->tulip_if, ETHER_BPF_SUPPORTED);
4816 ifp->if_snd.ifq_maxlen = ifqmaxlen;
4817}
4818
4819#if defined(TULIP_BUS_DMA)
4820#if !defined(TULIP_BUS_DMA_NOTX) || !defined(TULIP_BUS_DMA_NORX)
4821static int
4822tulip_busdma_allocmem(
4823 tulip_softc_t * const sc,
4824 size_t size,
4825 bus_dmamap_t *map_p,
4826 tulip_desc_t **desc_p)
4827{
4828 bus_dma_segment_t segs[1];
4829 int nsegs, error;
4830 error = bus_dmamem_alloc(sc->tulip_dmatag, size, 1, PAGE_SIZE,
4831 segs, sizeof(segs)/sizeof(segs[0]),
4832 &nsegs, BUS_DMA_NOWAIT);
4833 if (error == 0) {
4834 void *desc;
4835 error = bus_dmamem_map(sc->tulip_dmatag, segs, nsegs, size,
4836 (void *) &desc, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
4837 if (error == 0) {
4838 bus_dmamap_t map;
4839 error = bus_dmamap_create(sc->tulip_dmatag, size, 1, size, 0,
4840 BUS_DMA_NOWAIT, &map);
4841 if (error == 0) {
4842 error = bus_dmamap_load(sc->tulip_dmatag, map, desc,
4843 size, NULL, BUS_DMA_NOWAIT);
4844 if (error)
4845 bus_dmamap_destroy(sc->tulip_dmatag, map);
4846 else
4847 *map_p = map;
4848 }
4849 if (error)
4850 bus_dmamem_unmap(sc->tulip_dmatag, desc, size);
4851 }
4852 if (error)
4853 bus_dmamem_free(sc->tulip_dmatag, segs, nsegs);
4854 else
4855 *desc_p = desc;
4856 }
4857 return error;
4858}
4859#endif
4860
4861static int
4862tulip_busdma_init(
4863 tulip_softc_t * const sc)
4864{
4865 int error = 0;
4866
4867#if !defined(TULIP_BUS_DMA_NOTX)
4868 /*
4869 * Allocate dmamap for setup descriptor
4870 */
4871 error = bus_dmamap_create(sc->tulip_dmatag, sizeof(sc->tulip_setupbuf), 2,
4872 sizeof(sc->tulip_setupbuf), 0, BUS_DMA_NOWAIT,
4873 &sc->tulip_setupmap);
4874 if (error == 0) {
4875 error = bus_dmamap_load(sc->tulip_dmatag, sc->tulip_setupmap,
4876 sc->tulip_setupbuf, sizeof(sc->tulip_setupbuf),
4877 NULL, BUS_DMA_NOWAIT);
4878 if (error)
4879 bus_dmamap_destroy(sc->tulip_dmatag, sc->tulip_setupmap);
4880 }
4881 /*
4882 * Allocate space and dmamap for transmit ring
4883 */
4884 if (error == 0) {
4885 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_TXDESCS,
4886 &sc->tulip_txdescmap,
4887 &sc->tulip_txdescs);
4888 }
4889
4890 /*
4891 * Allocate dmamaps for each transmit descriptors
4892 */
4893 if (error == 0) {
4894 while (error == 0 && sc->tulip_txmaps_free < TULIP_TXDESCS) {
4895 bus_dmamap_t map;
4896 if ((error = TULIP_TXMAP_CREATE(sc, &map)) == 0)
4897 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
4898 }
4899 if (error) {
4900 while (sc->tulip_txmaps_free > 0)
4901 bus_dmamap_destroy(sc->tulip_dmatag,
4902 sc->tulip_txmaps[--sc->tulip_txmaps_free]);
4903 }
4904 }
4905#else
4906 if (error == 0) {
4907 sc->tulip_txdescs = (tulip_desc_t *) malloc(TULIP_TXDESCS * sizeof(tulip_desc_t), M_DEVBUF, M_NOWAIT);
4908 if (sc->tulip_txdescs == NULL)
4909 error = ENOMEM;
4910 }
4911#endif
4912#if !defined(TULIP_BUS_DMA_NORX)
4913 /*
4914 * Allocate space and dmamap for receive ring
4915 */
4916 if (error == 0) {
4917 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_RXDESCS,
4918 &sc->tulip_rxdescmap,
4919 &sc->tulip_rxdescs);
4920 }
4921
4922 /*
4923 * Allocate dmamaps for each receive descriptors
4924 */
4925 if (error == 0) {
4926 while (error == 0 && sc->tulip_rxmaps_free < TULIP_RXDESCS) {
4927 bus_dmamap_t map;
4928 if ((error = TULIP_RXMAP_CREATE(sc, &map)) == 0)
4929 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
4930 }
4931 if (error) {
4932 while (sc->tulip_rxmaps_free > 0)
4933 bus_dmamap_destroy(sc->tulip_dmatag,
4934 sc->tulip_rxmaps[--sc->tulip_rxmaps_free]);
4935 }
4936 }
4937#else
4938 if (error == 0) {
4939 sc->tulip_rxdescs = (tulip_desc_t *) malloc(TULIP_RXDESCS * sizeof(tulip_desc_t), M_DEVBUF, M_NOWAIT);
4940 if (sc->tulip_rxdescs == NULL)
4941 error = ENOMEM;
4942 }
4943#endif
4944 return error;
4945}
4946#endif /* TULIP_BUS_DMA */
4947
4948static void
4949tulip_initcsrs(
4950 tulip_softc_t * const sc,
4951 tulip_csrptr_t csr_base,
4952 size_t csr_size)
4953{
4954 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
4955 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
4956 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
4957 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
4958 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
4959 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
4960 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
4961 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
4962 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size;
4963 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size;
4964 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size;
4965 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size;
4966 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size;
4967 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size;
4968 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
4969 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
4970}
4971
4972static void
4973tulip_initring(
4974 tulip_softc_t * const sc,
4975 tulip_ringinfo_t * const ri,
4976 tulip_desc_t *descs,
4977 int ndescs)
4978{
4979 ri->ri_max = ndescs;
4980 ri->ri_first = descs;
4981 ri->ri_last = ri->ri_first + ri->ri_max;
4982 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
4983 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
4984}
4985
4986/*
4987 * This is the PCI configuration support.
4988 */
4989
4990#define PCI_CBIO 0x10 /* Configuration Base IO Address */
4991#define PCI_CBMA 0x14 /* Configuration Base Memory Address */
4992#define PCI_CFDA 0x40 /* Configuration Driver Area */
4993
4994static int
4995tulip_pci_probe(device_t dev)
4996{
4997 const char *name = NULL;
4998
4999 if (pci_get_vendor(dev) != DEC_VENDORID)
5000 return ENXIO;
5001
5002 /*
5003 * Some LanMedia WAN cards use the Tulip chip, but they have
5004 * their own driver, and we should not recognize them
5005 */
5006 if (pci_get_subvendor(dev) == 0x1376)
5007 return ENXIO;
5008
5009 switch (pci_get_device(dev)) {
5010 case CHIPID_21040:
5011 name = "Digital 21040 Ethernet";
5012 break;
5013 case CHIPID_21041:
5014 name = "Digital 21041 Ethernet";
5015 break;
5016 case CHIPID_21140:
5017 if (pci_get_revid(dev) >= 0x20)
5018 name = "Digital 21140A Fast Ethernet";
5019 else
5020 name = "Digital 21140 Fast Ethernet";
5021 break;
5022 case CHIPID_21142:
5023 if (pci_get_revid(dev) >= 0x20)
5024 name = "Digital 21143 Fast Ethernet";
5025 else
5026 name = "Digital 21142 Fast Ethernet";
5027 break;
5028 }
5029 if (name) {
5030 device_set_desc(dev, name);
5031 return -200;
5032 }
5033 return ENXIO;
5034}
5035
5036static int
5037tulip_shutdown(device_t dev)
5038{
5039 tulip_softc_t * const sc = device_get_softc(dev);
5040 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
5041 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
5042 33MHz that comes to two microseconds but wait a
5043 bit longer anyways) */
5044 return 0;
5045}
5046
5047static int
5048tulip_pci_attach(device_t dev)
5049{
5050 tulip_softc_t *sc;
5051#if defined(__alpha__)
5052 tulip_media_t media = TULIP_MEDIA_UNKNOWN;
5053#endif
5054 int retval, idx;
5055 u_int32_t revinfo, cfdainfo, cfcsinfo;
5056 unsigned csroffset = TULIP_PCI_CSROFFSET;
5057 unsigned csrsize = TULIP_PCI_CSRSIZE;
5058 tulip_csrptr_t csr_base;
5059 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
5060 struct resource *res;
5061 int rid, unit;
5062
5063 unit = device_get_unit(dev);
5064
5065 if (unit >= TULIP_MAX_DEVICES) {
5066 printf("de%d", unit);
5067 printf(": not configured; limit of %d reached or exceeded\n",
5068 TULIP_MAX_DEVICES);
5069 return ENXIO;
5070 }
5071
5072 revinfo = pci_get_revid(dev);
5073 cfdainfo = pci_read_config(dev, PCI_CFDA, 4);
5074 cfcsinfo = pci_read_config(dev, PCIR_COMMAND, 4);
5075
5076 /* turn busmaster on in case BIOS doesn't set it */
5077 if(!(cfcsinfo & PCIM_CMD_BUSMASTEREN)) {
5078 cfcsinfo |= PCIM_CMD_BUSMASTEREN;
5079 pci_write_config(dev, PCIR_COMMAND, cfcsinfo, 4);
5080 }
5081
5082 if (pci_get_vendor(dev) == DEC_VENDORID) {
5083 if (pci_get_device(dev) == CHIPID_21040)
5084 chipid = TULIP_21040;
5085 else if (pci_get_device(dev) == CHIPID_21041)
5086 chipid = TULIP_21041;
5087 else if (pci_get_device(dev) == CHIPID_21140)
5088 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140;
5089 else if (pci_get_device(dev) == CHIPID_21142)
5090 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142;
5091 }
5092 if (chipid == TULIP_CHIPID_UNKNOWN)
5093 return ENXIO;
5094
5095 if (chipid == TULIP_21040 && revinfo < 0x20) {
5096 printf("de%d", unit);
5097 printf(": not configured; 21040 pass 2.0 required (%d.%d found)\n",
5098 revinfo >> 4, revinfo & 0x0f);
5099 return ENXIO;
5100 } else if (chipid == TULIP_21140 && revinfo < 0x11) {
5101 printf("de%d: not configured; 21140 pass 1.1 required (%d.%d found)\n",
5102 unit, revinfo >> 4, revinfo & 0x0f);
5103 return ENXIO;
5104 }
5105
5106 sc = device_get_softc(dev);
5107 sc->tulip_pci_busno = pci_get_bus(dev);
5108 sc->tulip_pci_devno = pci_get_slot(dev);
5109 sc->tulip_chipid = chipid;
5110 sc->tulip_flags |= TULIP_DEVICEPROBE;
5111 if (chipid == TULIP_21140 || chipid == TULIP_21140A)
5112 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD;
5113 if (chipid == TULIP_21140A && revinfo <= 0x22)
5114 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW;
5115 if (chipid == TULIP_21140)
5116 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH;
5117 if (chipid != TULIP_21040 && chipid != TULIP_21140)
5118 sc->tulip_features |= TULIP_HAVE_POWERMGMT;
5119 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) {
5120 sc->tulip_features |= TULIP_HAVE_DUALSENSE;
5121 if (chipid != TULIP_21041 || revinfo >= 0x20)
5122 sc->tulip_features |= TULIP_HAVE_SIANWAY;
5123 if (chipid != TULIP_21041)
5124 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD;
5125 if (chipid != TULIP_21041 && revinfo >= 0x20)
5126 sc->tulip_features |= TULIP_HAVE_SIA100;
5127 }
5128
5129 if (sc->tulip_features & TULIP_HAVE_POWERMGMT
5130 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) {
5131 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE);
5132 pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
5133 DELAY(11*1000);
5134 }
5135#if defined(__alpha__)
5136 /*
5137 * The Alpha SRM console encodes a console set media in the driver
5138 * part of the CFDA register. Note that the Multia presents a
5139 * problem in that its BNC mode is really EXTSIA. So in that case
5140 * force a probe.
5141 */
5142 switch ((cfdainfo >> 8) & 0xff) {
5143 case 1: media = chipid > TULIP_21040 ? TULIP_MEDIA_AUI : TULIP_MEDIA_AUIBNC; break;
5144 case 2: media = chipid > TULIP_21040 ? TULIP_MEDIA_BNC : TULIP_MEDIA_UNKNOWN; break;
5145 case 3: media = TULIP_MEDIA_10BASET; break;
5146 case 4: media = TULIP_MEDIA_10BASET_FD; break;
5147 case 5: media = TULIP_MEDIA_100BASETX; break;
5148 case 6: media = TULIP_MEDIA_100BASETX_FD; break;
5149 default: media = TULIP_MEDIA_UNKNOWN; break;
5150 }
5151#endif
5152
5153 sc->tulip_unit = unit;
5154 sc->tulip_name = "de";
5155 sc->tulip_revinfo = revinfo;
5156 sc->tulip_if.if_softc = sc;
5157#if defined(TULIP_IOMAPPED)
5158 rid = PCI_CBIO;
5159 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
5160 0, ~0, 1, RF_ACTIVE);
5161#else
5162 rid = PCI_CBMA;
5163 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
5164 0, ~0, 1, RF_ACTIVE);
5165#endif
5166 if (!res)
5167 return ENXIO;
5168 sc->tulip_csrs_bst = rman_get_bustag(res);
5169 sc->tulip_csrs_bsh = rman_get_bushandle(res);
5170 csr_base = 0;
5171
5172 tulips[unit] = sc;
5173
5174 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
5175
5176#if defined(TULIP_BUS_DMA)
5177 if ((retval = tulip_busdma_init(sc)) != 0) {
5178 printf("error initing bus_dma: %d\n", retval);
5179 return ENXIO;
5180 }
5181#else
5182 sc->tulip_rxdescs = (tulip_desc_t *) malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS, M_DEVBUF, M_NOWAIT);
5183 sc->tulip_txdescs = (tulip_desc_t *) malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS, M_DEVBUF, M_NOWAIT);
5184 if (sc->tulip_rxdescs == NULL || sc->tulip_txdescs == NULL) {
5185 printf("malloc failed\n");
5186 if (sc->tulip_rxdescs)
5187 free((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
5188 if (sc->tulip_txdescs)
5189 free((caddr_t) sc->tulip_txdescs, M_DEVBUF);
5190 return ENXIO;
5191 }
5192#endif
5193
5194 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS);
5195 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS);
5196
5197 /*
5198 * Make sure there won't be any interrupts or such...
5199 */
5200 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
5201 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
5202 33MHz that comes to two microseconds but wait a
5203 bit longer anyways) */
5204
5205 if ((retval = tulip_read_macaddr(sc)) < 0) {
5206 printf("%s%d", sc->tulip_name, sc->tulip_unit);
5207 printf(": can't read ENET ROM (why=%d) (", retval);
5208 for (idx = 0; idx < 32; idx++)
5209 printf("%02x", sc->tulip_rombuf[idx]);
5210 printf("\n");
5211 printf("%s%d: %s%s pass %d.%d\n",
5212 sc->tulip_name, sc->tulip_unit,
5213 sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
5214 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
5215 printf("%s%d: address unknown\n", sc->tulip_name, sc->tulip_unit);
5216 } else {
5217 int s;
5218 void (*intr_rtn)(void *) = tulip_intr_normal;
5219
5220 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
5221 intr_rtn = tulip_intr_shared;
5222
5223 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) {
5224 void *ih;
5225
5226 rid = 0;
5227 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
5228 0, ~0, 1, RF_SHAREABLE | RF_ACTIVE);
5229 if (res == 0 || bus_setup_intr(dev, res, INTR_TYPE_NET,
5230 intr_rtn, sc, &ih)) {
5231 printf("%s%d: couldn't map interrupt\n",
5232 sc->tulip_name, sc->tulip_unit);
5233 free((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
5234 free((caddr_t) sc->tulip_txdescs, M_DEVBUF);
5235 return ENXIO;
5236 }
5237 }
5238#if defined(TULIP_USE_SOFTINTR)
5239 if (sc->tulip_unit > tulip_softintr_max_unit)
5240 tulip_softintr_max_unit = sc->tulip_unit;
5241#endif
5242
5243 s = splimp();
5244#if defined(__alpha__)
5245 sc->tulip_media = media;
5246#endif
5247 tulip_attach(sc);
5248#if defined(__alpha__)
5249 if (sc->tulip_media != TULIP_MEDIA_UNKNOWN)
5250 tulip_linkup(sc, media);
5251#endif
5252 splx(s);
5253 }
5254 return 0;
5255}
5256
5257static device_method_t tulip_pci_methods[] = {
5258 /* Device interface */
5259 DEVMETHOD(device_probe, tulip_pci_probe),
5260 DEVMETHOD(device_attach, tulip_pci_attach),
5261 DEVMETHOD(device_shutdown, tulip_shutdown),
5262 { 0, 0 }
5263};
5264static driver_t tulip_pci_driver = {
5265 "de",
5266 tulip_pci_methods,
5267 sizeof(tulip_softc_t),
5268};
5269static devclass_t tulip_devclass;
5270DRIVER_MODULE(if_de, pci, tulip_pci_driver, tulip_devclass, 0, 0);