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