Document additional work in last commit. Bumped library to ld-elf.so.2
[dragonfly.git] / sys / dev / netif / de / if_de.c
CommitLineData
984263bc
MD
1/* $NetBSD: if_de.c,v 1.86 1999/06/01 19:17:59 thorpej Exp $ */
2
3/* $FreeBSD: src/sys/pci/if_de.c,v 1.123.2.4 2000/08/04 23:25:09 peter Exp $ */
9bf3a1b2 4/* $DragonFly: src/sys/dev/netif/de/if_de.c,v 1.30 2005/05/11 19:40:00 joerg Exp $ */
984263bc
MD
5
6/*-
7 * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com)
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software withough specific prior written permission
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Id: if_de.c,v 1.94 1997/07/03 16:55:07 thomas Exp
30 *
31 */
32
33/*
34 * DEC 21040 PCI Ethernet Controller
35 *
36 * Written by Matt Thomas
37 * BPF support code stolen directly from if_ec.c
38 *
39 * This driver supports the DEC DE435 or any other PCI
40 * board which support 21040, 21041, or 21140 (mostly).
41 */
984263bc
MD
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/mbuf.h>
46#include <sys/socket.h>
47#include <sys/sockio.h>
48#include <sys/malloc.h>
49#include <sys/kernel.h>
50#include <sys/eventhandler.h>
51#include <machine/clock.h>
52#include <machine/bus.h>
53#include <machine/resource.h>
54#include <sys/bus.h>
55#include <sys/rman.h>
56
57#include "opt_inet.h"
58#include "opt_ipx.h"
59
60#include <net/if.h>
61#include <net/if_media.h>
62#include <net/if_dl.h>
984263bc
MD
63
64#include <net/bpf.h>
65
66#ifdef INET
67#include <netinet/in.h>
68#include <netinet/if_ether.h>
69#endif
70
71#ifdef IPX
d2438d69
MD
72#include <netproto/ipx/ipx.h>
73#include <netproto/ipx/ipx_if.h>
984263bc
MD
74#endif
75
76#ifdef NS
d2438d69
MD
77#include <netproto/ns/ns.h>
78#include <netproto/ns/ns_if.h>
984263bc
MD
79#endif
80
81#include <vm/vm.h>
82
83#include <net/if_var.h>
84#include <vm/pmap.h>
1f2de5d4
MD
85#include <bus/pci/pcivar.h>
86#include <bus/pci/pcireg.h>
87#include <bus/pci/dc21040reg.h>
984263bc
MD
88
89/*
90 * Intel CPUs should use I/O mapped access.
91 */
92#if defined(__i386__)
93#define TULIP_IOMAPPED
94#endif
95
984263bc
MD
96#define TULIP_HZ 10
97
1f2de5d4 98#include "if_devar.h"
984263bc 99
cdfcdfb0
JS
100static tulip_softc_t *tulips[TULIP_MAX_DEVICES];
101
984263bc
MD
102/*
103 * This module supports
104 * the DEC 21040 PCI Ethernet Controller.
105 * the DEC 21041 PCI Ethernet Controller.
106 * the DEC 21140 PCI Fast Ethernet Controller.
107 */
79fe23de
JS
108static void tulip_mii_autonegotiate(tulip_softc_t *, u_int);
109static void tulip_intr_shared(void *);
110static void tulip_intr_normal(void *);
111static void tulip_init(tulip_softc_t *);
112static void tulip_reset(tulip_softc_t *);
113static void tulip_ifstart(struct ifnet *);
114static struct mbuf *tulip_txput(tulip_softc_t *, struct mbuf *);
115static void tulip_txput_setup(tulip_softc_t *);
116static void tulip_rx_intr(tulip_softc_t *);
117static void tulip_addr_filter(tulip_softc_t *);
118static u_int tulip_mii_readreg(tulip_softc_t *, u_int, u_int);
119static void tulip_mii_writereg(tulip_softc_t *, u_int, u_int, u_int);
120static int tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities);
121static tulip_media_t tulip_mii_phy_readspecific(tulip_softc_t *);
122static int tulip_srom_decode(tulip_softc_t *);
123static int tulip_ifmedia_change(struct ifnet *);
124static void tulip_ifmedia_status(struct ifnet *, struct ifmediareq *);
984263bc 125/* static void tulip_21140_map_media(tulip_softc_t *sc); */
79fe23de 126
984263bc 127static void
79fe23de 128tulip_timeout_callback(void *arg)
984263bc 129{
79fe23de 130 tulip_softc_t *sc = arg;
984263bc
MD
131 int s = splimp();
132
984263bc
MD
133 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING;
134 sc->tulip_probe_timeout -= 1000 / TULIP_HZ;
135 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER);
984263bc
MD
136 splx(s);
137}
138
139static void
79fe23de 140tulip_timeout(tulip_softc_t *sc)
984263bc
MD
141{
142 if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
143 return;
144 sc->tulip_flags |= TULIP_TIMEOUTPENDING;
88fcae56
JS
145 callout_reset(&sc->tulip_timer, (hz + TULIP_HZ / 2) / TULIP_HZ,
146 tulip_timeout_callback, sc);
984263bc
MD
147}
148
984263bc 149static int
79fe23de 150tulip_txprobe(tulip_softc_t *sc)
984263bc
MD
151{
152 struct mbuf *m;
153 /*
154 * Before we are sure this is the right media we need
155 * to send a small packet to make sure there's carrier.
156 * Strangely, BNC and AUI will "see" receive data if
157 * either is connected so the transmit is the only way
158 * to verify the connectivity.
159 */
74f1caca 160 MGETHDR(m, MB_DONTWAIT, MT_DATA);
984263bc
MD
161 if (m == NULL)
162 return 0;
163 /*
164 * Construct a LLC TEST message which will point to ourselves.
165 */
166 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_dhost, 6);
167 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_shost, 6);
168 mtod(m, struct ether_header *)->ether_type = htons(3);
169 mtod(m, unsigned char *)[14] = 0;
170 mtod(m, unsigned char *)[15] = 0;
171 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
172 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
173 /*
174 * send it!
175 */
176 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
177 sc->tulip_intrmask |= TULIP_STS_TXINTR;
178 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
179 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
180 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
181 if ((m = tulip_txput(sc, m)) != NULL)
182 m_freem(m);
183 sc->tulip_probe.probe_txprobes++;
184 return 1;
185}
79fe23de 186
984263bc
MD
187#ifdef BIG_PACKET
188#define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0)
189#else
190#define TULIP_SIAGEN_WATCHDOG 0
191#endif
192
193static void
79fe23de 194tulip_media_set(tulip_softc_t *sc, tulip_media_t media)
984263bc
MD
195{
196 const tulip_media_info_t *mi = sc->tulip_mediums[media];
197
198 if (mi == NULL)
199 return;
200
201 /*
202 * If we are switching media, make sure we don't think there's
203 * any stale RX activity
204 */
205 sc->tulip_flags &= ~TULIP_RXACT;
206 if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
207 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
208 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx);
209 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
210 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
211 DELAY(50);
212 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
213 } else {
214 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
215 }
216 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity);
217 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
218#define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL)
219 /*
220 * If the cmdmode bits don't match the currently operating mode,
221 * set the cmdmode appropriately and reset the chip.
222 */
223 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
224 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
225 sc->tulip_cmdmode |= mi->mi_cmdmode;
226 tulip_reset(sc);
227 }
228 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
229 DELAY(10);
230 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata);
231 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
232 /*
233 * If the cmdmode bits don't match the currently operating mode,
234 * set the cmdmode appropriately and reset the chip.
235 */
236 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
237 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
238 sc->tulip_cmdmode |= mi->mi_cmdmode;
239 tulip_reset(sc);
240 }
241 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol);
242 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata);
243 } else if (mi->mi_type == TULIP_MEDIAINFO_MII
244 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) {
245 int idx;
246 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
247 const u_int8_t *dp;
248 dp = &sc->tulip_rombuf[mi->mi_reset_offset];
249 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) {
250 DELAY(10);
251 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
252 }
253 sc->tulip_phyaddr = mi->mi_phyaddr;
254 dp = &sc->tulip_rombuf[mi->mi_gpr_offset];
255 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) {
256 DELAY(10);
257 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
258 }
259 } else {
260 for (idx = 0; idx < mi->mi_reset_length; idx++) {
261 DELAY(10);
262 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]);
263 }
264 sc->tulip_phyaddr = mi->mi_phyaddr;
265 for (idx = 0; idx < mi->mi_gpr_length; idx++) {
266 DELAY(10);
267 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]);
268 }
269 }
270 if (sc->tulip_flags & TULIP_TRYNWAY) {
271 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
272 } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
273 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL);
274 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE);
275 sc->tulip_flags &= ~TULIP_DIDNWAY;
276 if (TULIP_IS_MEDIA_FD(media))
277 data |= PHYCTL_FULL_DUPLEX;
278 if (TULIP_IS_MEDIA_100MB(media))
279 data |= PHYCTL_SELECT_100MB;
280 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data);
281 }
282 }
283}
79fe23de 284
984263bc 285static void
79fe23de 286tulip_linkup(tulip_softc_t *sc, tulip_media_t media)
984263bc
MD
287{
288 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
289 sc->tulip_flags |= TULIP_PRINTLINKUP;
290 sc->tulip_flags |= TULIP_LINKUP;
291 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
292#if 0 /* XXX how does with work with ifmedia? */
293 if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
294 if (sc->tulip_if.if_flags & IFF_FULLDUPLEX) {
295 if (TULIP_CAN_MEDIA_FD(media)
296 && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL)
297 media = TULIP_FD_MEDIA_OF(media);
298 } else {
299 if (TULIP_IS_MEDIA_FD(media)
300 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL)
301 media = TULIP_HD_MEDIA_OF(media);
302 }
303 }
304#endif
305 if (sc->tulip_media != media) {
984263bc
MD
306 sc->tulip_media = media;
307 sc->tulip_flags |= TULIP_PRINTMEDIA;
308 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) {
309 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
310 } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) {
311 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
312 }
313 }
314 /*
315 * We could set probe_timeout to 0 but setting to 3000 puts this
316 * in one central place and the only matters is tulip_link is
317 * followed by a tulip_timeout. Therefore setting it should not
318 * result in aberrant behavour.
319 */
320 sc->tulip_probe_timeout = 3000;
321 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
322 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY);
323 if (sc->tulip_flags & TULIP_INRESET) {
324 tulip_media_set(sc, sc->tulip_media);
325 } else if (sc->tulip_probe_media != sc->tulip_media) {
326 /*
327 * No reason to change media if we have the right media.
328 */
329 tulip_reset(sc);
330 }
331 tulip_init(sc);
332}
79fe23de 333
984263bc 334static void
79fe23de 335tulip_media_print(tulip_softc_t *sc)
984263bc
MD
336{
337 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
338 return;
339 if (sc->tulip_flags & TULIP_PRINTMEDIA) {
340 printf("%s%d: enabling %s port\n",
341 sc->tulip_name, sc->tulip_unit,
342 tulip_mediums[sc->tulip_media]);
343 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
344 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
345 printf("%s%d: link up\n", sc->tulip_name, sc->tulip_unit);
346 sc->tulip_flags &= ~TULIP_PRINTLINKUP;
347 }
348}
79fe23de 349
984263bc
MD
350#if defined(TULIP_DO_GPR_SENSE)
351static tulip_media_t
79fe23de 352tulip_21140_gpr_media_sense(tulip_softc_t *sc)
984263bc
MD
353{
354 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
355 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
356 tulip_media_t media;
357
358 /*
359 * If one of the media blocks contained a default media flag,
360 * use that.
361 */
362 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
363 const tulip_media_info_t *mi;
364 /*
365 * Media is not supported (or is full-duplex).
366 */
367 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media))
368 continue;
369 if (mi->mi_type != TULIP_MEDIAINFO_GPR)
370 continue;
371
372 /*
373 * Remember the media is this is the "default" media.
374 */
375 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
376 maybe_media = media;
377
378 /*
379 * No activity mask? Can't see if it is active if there's no mask.
380 */
381 if (mi->mi_actmask == 0)
382 continue;
383
384 /*
385 * Does the activity data match?
386 */
387 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
388 continue;
389
984263bc
MD
390 /*
391 * It does! If this is the first media we detected, then
392 * remember this media. If isn't the first, then there were
393 * multiple matches which we equate to no match (since we don't
394 * which to select (if any).
395 */
396 if (last_media == TULIP_MEDIA_UNKNOWN) {
397 last_media = media;
398 } else if (last_media != media) {
399 last_media = TULIP_MEDIA_UNKNOWN;
400 }
401 }
402 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
403}
404#endif /* TULIP_DO_GPR_SENSE */
79fe23de 405
984263bc 406static tulip_link_status_t
79fe23de 407tulip_media_link_monitor(tulip_softc_t *sc)
984263bc 408{
79fe23de 409 const tulip_media_info_t *mi = sc->tulip_mediums[sc->tulip_media];
984263bc
MD
410 tulip_link_status_t linkup = TULIP_LINK_DOWN;
411
412 if (mi == NULL) {
46a77a85 413#if defined(DIAGNOSTIC)
984263bc
MD
414 panic("tulip_media_link_monitor: %s: botch at line %d\n",
415 tulip_mediums[sc->tulip_media],__LINE__);
416#endif
417 return TULIP_LINK_UNKNOWN;
418 }
419
420
421 /*
422 * Have we seen some packets? If so, the link must be good.
423 */
424 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) {
425 sc->tulip_flags &= ~TULIP_RXACT;
426 sc->tulip_probe_timeout = 3000;
427 return TULIP_LINK_UP;
428 }
429
430 sc->tulip_flags &= ~TULIP_RXACT;
431 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
432 u_int32_t status;
433 /*
434 * Read the PHY status register.
435 */
436 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
437 if (status & PHYSTS_AUTONEG_DONE) {
438 /*
439 * If the PHY has completed autonegotiation, see the if the
440 * remote systems abilities have changed. If so, upgrade or
441 * downgrade as appropriate.
442 */
443 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
444 abilities = (abilities << 6) & status;
445 if (abilities != sc->tulip_abilities) {
984263bc
MD
446 if (tulip_mii_map_abilities(sc, abilities)) {
447 tulip_linkup(sc, sc->tulip_probe_media);
448 return TULIP_LINK_UP;
449 }
450 /*
451 * if we had selected media because of autonegotiation,
452 * we need to probe for the new media.
453 */
454 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
455 if (sc->tulip_flags & TULIP_DIDNWAY)
456 return TULIP_LINK_DOWN;
457 }
458 }
459 /*
460 * The link is now up. If was down, say its back up.
461 */
462 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP)
463 linkup = TULIP_LINK_UP;
464 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
465 /*
466 * No activity sensor? Assume all's well.
467 */
468 if (mi->mi_actmask == 0)
469 return TULIP_LINK_UNKNOWN;
470 /*
471 * Does the activity data match?
472 */
473 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata)
474 linkup = TULIP_LINK_UP;
475 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
476 /*
477 * Assume non TP ok for now.
478 */
479 if (!TULIP_IS_MEDIA_TP(sc->tulip_media))
480 return TULIP_LINK_UNKNOWN;
481 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
482 linkup = TULIP_LINK_UP;
984263bc
MD
483 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
484 return TULIP_LINK_UNKNOWN;
485 }
486 /*
487 * We will wait for 3 seconds until the link goes into suspect mode.
488 */
489 if (sc->tulip_flags & TULIP_LINKUP) {
490 if (linkup == TULIP_LINK_UP)
491 sc->tulip_probe_timeout = 3000;
492 if (sc->tulip_probe_timeout > 0)
493 return TULIP_LINK_UP;
494
495 sc->tulip_flags &= ~TULIP_LINKUP;
496 printf("%s%d: link down: cable problem?\n", sc->tulip_name, sc->tulip_unit);
497 }
984263bc
MD
498 return TULIP_LINK_DOWN;
499}
79fe23de 500
984263bc 501static void
79fe23de 502tulip_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
984263bc 503{
984263bc
MD
504 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
505 && event == TULIP_MEDIAPOLL_TIMER) {
506 switch (tulip_media_link_monitor(sc)) {
507 case TULIP_LINK_DOWN: {
508 /*
509 * Link Monitor failed. Probe for new media.
510 */
511 event = TULIP_MEDIAPOLL_LINKFAIL;
512 break;
513 }
514 case TULIP_LINK_UP: {
515 /*
516 * Check again soon.
517 */
518 tulip_timeout(sc);
519 return;
520 }
521 case TULIP_LINK_UNKNOWN: {
522 /*
523 * We can't tell so don't bother.
524 */
525 return;
526 }
527 }
528 }
529
530 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
531 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
532 if (TULIP_DO_AUTOSENSE(sc)) {
984263bc
MD
533 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
534 if (sc->tulip_if.if_flags & IFF_UP)
535 tulip_reset(sc); /* restart probe */
536 }
537 return;
538 }
984263bc
MD
539 }
540
541 if (event == TULIP_MEDIAPOLL_START) {
542 sc->tulip_if.if_flags |= IFF_OACTIVE;
543 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
544 return;
545 sc->tulip_probe_mediamask = 0;
546 sc->tulip_probe_passes = 0;
984263bc
MD
547 /*
548 * If the SROM contained an explicit media to use, use it.
549 */
550 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX);
551 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS;
552 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
553 /*
554 * connidx is defaulted to a media_unknown type.
555 */
556 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media;
557 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) {
558 tulip_linkup(sc, sc->tulip_probe_media);
559 tulip_timeout(sc);
560 return;
561 }
562
563 if (sc->tulip_features & TULIP_HAVE_GPR) {
564 sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
565 sc->tulip_probe_timeout = 2000;
566 } else {
567 sc->tulip_probe_media = TULIP_MEDIA_MAX;
568 sc->tulip_probe_timeout = 0;
569 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
570 }
571 }
572
573 /*
574 * Ignore txprobe failures or spurious callbacks.
575 */
576 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED
577 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) {
578 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
579 return;
580 }
581
582 /*
583 * If we really transmitted a packet, then that's the media we'll use.
584 */
585 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) {
586 if (event == TULIP_MEDIAPOLL_LINKPASS) {
587 /* XXX Check media status just to be sure */
588 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
984263bc
MD
589 }
590 tulip_linkup(sc, sc->tulip_probe_media);
591 tulip_timeout(sc);
592 return;
593 }
594
595 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) {
596#if defined(TULIP_DO_GPR_SENSE)
597 /*
598 * Check for media via the general purpose register.
599 *
600 * Try to sense the media via the GPR. If the same value
601 * occurs 3 times in a row then just use that.
602 */
603 if (sc->tulip_probe_timeout > 0) {
604 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
984263bc
MD
605 if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
606 if (new_probe_media == sc->tulip_probe_media) {
607 if (--sc->tulip_probe_count == 0)
608 tulip_linkup(sc, sc->tulip_probe_media);
609 } else {
610 sc->tulip_probe_count = 10;
611 }
612 }
613 sc->tulip_probe_media = new_probe_media;
614 tulip_timeout(sc);
615 return;
616 }
617#endif /* TULIP_DO_GPR_SENSE */
618 /*
619 * Brute force. We cycle through each of the media types
620 * and try to transmit a packet.
621 */
622 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
623 sc->tulip_probe_media = TULIP_MEDIA_MAX;
624 sc->tulip_probe_timeout = 0;
625 tulip_timeout(sc);
626 return;
627 }
628
629 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST
630 && (sc->tulip_features & TULIP_HAVE_MII)) {
631 tulip_media_t old_media = sc->tulip_probe_media;
632 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
633 switch (sc->tulip_probe_state) {
634 case TULIP_PROBE_FAILED:
635 case TULIP_PROBE_MEDIATEST: {
636 /*
637 * Try the next media.
638 */
639 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask;
640 sc->tulip_probe_timeout = 0;
641#ifdef notyet
642 if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
643 break;
644 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
645 break;
646 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
647#endif
648 break;
649 }
650 case TULIP_PROBE_PHYAUTONEG: {
651 return;
652 }
653 case TULIP_PROBE_INACTIVE: {
654 /*
655 * Only probe if we autonegotiated a media that hasn't failed.
656 */
657 sc->tulip_probe_timeout = 0;
658 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) {
659 sc->tulip_probe_media = old_media;
660 break;
661 }
662 tulip_linkup(sc, sc->tulip_probe_media);
663 tulip_timeout(sc);
664 return;
665 }
666 default: {
46a77a85 667#if defined(DIAGNOSTIC)
984263bc
MD
668 panic("tulip_media_poll: botch at line %d\n", __LINE__);
669#endif
670 break;
671 }
672 }
673 }
674
675 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
984263bc
MD
676 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
677 return;
678 }
679
680 /*
681 * switch to another media if we tried this one enough.
682 */
683 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
984263bc
MD
684 /*
685 * Find the next media type to check for. Full Duplex
686 * types are not allowed.
687 */
688 do {
689 sc->tulip_probe_media -= 1;
690 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
691 if (++sc->tulip_probe_passes == 3) {
692 printf("%s%d: autosense failed: cable problem?\n",
693 sc->tulip_name, sc->tulip_unit);
694 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
695 sc->tulip_if.if_flags &= ~IFF_RUNNING;
696 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
697 return;
698 }
699 }
700 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */
701 sc->tulip_probe_mediamask = 0;
702 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1;
703 }
704 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL
705 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
706 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
707
984263bc
MD
708 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
709 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
710 sc->tulip_probe.probe_txprobes = 0;
711 tulip_reset(sc);
712 tulip_media_set(sc, sc->tulip_probe_media);
713 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
714 }
715 tulip_timeout(sc);
716
717 /*
718 * If this is hanging off a phy, we know are doing NWAY and we have
719 * forced the phy to a specific speed. Wait for link up before
720 * before sending a packet.
721 */
722 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) {
723 case TULIP_MEDIAINFO_MII: {
724 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
725 return;
726 break;
727 }
728 case TULIP_MEDIAINFO_SIA: {
729 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) {
730 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL)
731 return;
732 tulip_linkup(sc, sc->tulip_probe_media);
733#ifdef notyet
734 if (sc->tulip_features & TULIP_HAVE_MII)
735 tulip_timeout(sc);
736#endif
737 return;
738 }
739 break;
740 }
741 case TULIP_MEDIAINFO_RESET:
742 case TULIP_MEDIAINFO_SYM:
743 case TULIP_MEDIAINFO_NONE:
744 case TULIP_MEDIAINFO_GPR: {
745 break;
746 }
747 }
748 /*
749 * Try to send a packet.
750 */
751 tulip_txprobe(sc);
752}
79fe23de 753
984263bc 754static void
79fe23de 755tulip_media_select(tulip_softc_t *sc)
984263bc
MD
756{
757 if (sc->tulip_features & TULIP_HAVE_GPR) {
758 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
759 DELAY(10);
760 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata);
761 }
762 /*
763 * If this board has no media, just return
764 */
765 if (sc->tulip_features & TULIP_HAVE_NOMEDIA)
766 return;
767
768 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
769 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
770 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START);
771 } else {
772 tulip_media_set(sc, sc->tulip_media);
773 }
774}
79fe23de 775
984263bc 776static void
79fe23de 777tulip_21040_mediainfo_init(tulip_softc_t *sc, tulip_media_t media)
984263bc
MD
778{
779 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
780 |TULIP_CMD_BACKOFFCTR;
781 sc->tulip_if.if_baudrate = 10000000;
782
783 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) {
784 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET);
785 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD);
786 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
787 }
788
789 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) {
790 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC);
791 }
792
793 if (media == TULIP_MEDIA_UNKNOWN) {
794 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA);
795 }
796}
797
798static void
79fe23de 799tulip_21040_media_probe(tulip_softc_t *sc)
984263bc
MD
800{
801 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
984263bc
MD
802}
803
804static void
79fe23de 805tulip_21040_10baset_only_media_probe(tulip_softc_t *sc)
984263bc
MD
806{
807 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
808 tulip_media_set(sc, TULIP_MEDIA_10BASET);
809 sc->tulip_media = TULIP_MEDIA_10BASET;
810}
811
812static void
79fe23de 813tulip_21040_10baset_only_media_select(tulip_softc_t *sc)
984263bc
MD
814{
815 sc->tulip_flags |= TULIP_LINKUP;
816 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
817 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
818 sc->tulip_flags &= ~TULIP_SQETEST;
819 } else {
820 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
821 sc->tulip_flags |= TULIP_SQETEST;
822 }
823 tulip_media_set(sc, sc->tulip_media);
824}
825
826static void
79fe23de 827tulip_21040_auibnc_only_media_probe(tulip_softc_t *sc)
984263bc
MD
828{
829 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
830 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
831 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
832 sc->tulip_media = TULIP_MEDIA_AUIBNC;
833}
834
835static void
79fe23de 836tulip_21040_auibnc_only_media_select(tulip_softc_t *sc)
984263bc
MD
837{
838 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
839 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
840}
841
842static const tulip_boardsw_t tulip_21040_boardsw = {
843 TULIP_21040_GENERIC,
844 tulip_21040_media_probe,
845 tulip_media_select,
846 tulip_media_poll,
847};
848
849static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = {
850 TULIP_21040_GENERIC,
851 tulip_21040_10baset_only_media_probe,
852 tulip_21040_10baset_only_media_select,
853 NULL,
854};
855
856static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = {
857 TULIP_21040_GENERIC,
858 tulip_21040_auibnc_only_media_probe,
859 tulip_21040_auibnc_only_media_select,
860 NULL,
861};
79fe23de 862
984263bc 863static void
79fe23de 864tulip_21041_mediainfo_init(tulip_softc_t *sc)
984263bc 865{
79fe23de 866 tulip_media_info_t *mi = sc->tulip_mediainfo;
984263bc
MD
867
868#ifdef notyet
869 if (sc->tulip_revinfo >= 0x20) {
870 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET);
871 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD);
872 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI);
873 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC);
874 return;
875 }
876#endif
877 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET);
878 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD);
879 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
880 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
881}
79fe23de 882
984263bc 883static void
79fe23de 884tulip_21041_media_probe(tulip_softc_t *sc)
984263bc
MD
885{
886 sc->tulip_if.if_baudrate = 10000000;
887 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
888 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
889 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
890 tulip_21041_mediainfo_init(sc);
891}
892
893static void
79fe23de 894tulip_21041_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
984263bc 895{
79fe23de 896 uint32_t sia_status;
984263bc 897
984263bc
MD
898 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
899 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
900 || !TULIP_DO_AUTOSENSE(sc))
901 return;
902 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
903 tulip_reset(sc); /* start probe */
904 return;
905 }
906
907 /*
908 * If we've been been asked to start a poll or link change interrupt
909 * restart the probe (and reset the tulip to a known state).
910 */
911 if (event == TULIP_MEDIAPOLL_START) {
912 sc->tulip_if.if_flags |= IFF_OACTIVE;
913 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN);
914#ifdef notyet
915 if (sc->tulip_revinfo >= 0x20) {
916 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
917 sc->tulip_flags |= TULIP_DIDNWAY;
918 }
919#endif
920 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
921 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
922 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
923 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT;
924 tulip_media_set(sc, TULIP_MEDIA_10BASET);
925 tulip_timeout(sc);
926 return;
927 }
928
929 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
930 return;
931
932 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
984263bc
MD
933 tulip_linkup(sc, sc->tulip_probe_media);
934 return;
935 }
936
937 sia_status = TULIP_CSR_READ(sc, csr_sia_status);
938 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status);
939 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) {
940 if (sc->tulip_revinfo >= 0x20) {
941 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6)))
942 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
943 }
944 /*
945 * If the link has passed LinkPass, 10baseT is the
946 * proper media to use.
947 */
948 tulip_linkup(sc, sc->tulip_probe_media);
949 return;
950 }
951
952 /*
953 * wait for up to 2.4 seconds for the link to reach pass state.
954 * Only then start scanning the other media for activity.
955 * choose media with receive activity over those without.
956 */
957 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) {
958 if (event != TULIP_MEDIAPOLL_TIMER)
959 return;
960 if (sc->tulip_probe_timeout > 0
961 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
962 tulip_timeout(sc);
963 return;
964 }
965 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
966 sc->tulip_flags |= TULIP_WANTRXACT;
967 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) {
968 sc->tulip_probe_media = TULIP_MEDIA_BNC;
969 } else {
970 sc->tulip_probe_media = TULIP_MEDIA_AUI;
971 }
972 tulip_media_set(sc, sc->tulip_probe_media);
973 tulip_timeout(sc);
974 return;
975 }
976
977 /*
978 * If we failed, clear the txprobe active flag.
979 */
980 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED)
981 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
982
983
984 if (event == TULIP_MEDIAPOLL_TIMER) {
985 /*
986 * If we've received something, then that's our link!
987 */
988 if (sc->tulip_flags & TULIP_RXACT) {
989 tulip_linkup(sc, sc->tulip_probe_media);
990 return;
991 }
992 /*
993 * if no txprobe active
994 */
995 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0
996 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0
997 || (sia_status & TULIP_SIASTS_RXACTIVITY))) {
998 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
999 tulip_txprobe(sc);
1000 tulip_timeout(sc);
1001 return;
1002 }
1003 /*
1004 * Take 2 passes through before deciding to not
1005 * wait for receive activity. Then take another
1006 * two passes before spitting out a warning.
1007 */
1008 if (sc->tulip_probe_timeout <= 0) {
1009 if (sc->tulip_flags & TULIP_WANTRXACT) {
1010 sc->tulip_flags &= ~TULIP_WANTRXACT;
1011 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1012 } else {
1013 printf("%s%d: autosense failed: cable problem?\n",
1014 sc->tulip_name, sc->tulip_unit);
1015 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
1016 sc->tulip_if.if_flags &= ~IFF_RUNNING;
1017 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1018 return;
1019 }
1020 }
1021 }
1022 }
1023
1024 /*
1025 * Since this media failed to probe, try the other one.
1026 */
1027 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1028 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) {
1029 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1030 } else {
1031 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1032 }
1033 tulip_media_set(sc, sc->tulip_probe_media);
1034 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1035 tulip_timeout(sc);
1036}
1037
1038static const tulip_boardsw_t tulip_21041_boardsw = {
1039 TULIP_21041_GENERIC,
1040 tulip_21041_media_probe,
1041 tulip_media_select,
1042 tulip_21041_media_poll
1043};
79fe23de 1044
984263bc
MD
1045static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
1046 { 0x20005c00, 0, /* 08-00-17 */
1047 {
1048 { 0x19, 0x0040, 0x0040 }, /* 10TX */
1049 { 0x19, 0x0040, 0x0000 }, /* 100TX */
1050 },
984263bc
MD
1051 },
1052 { 0x0281F400, 0, /* 00-A0-7D */
1053 {
1054 { 0x12, 0x0010, 0x0000 }, /* 10T */
1055 { }, /* 100TX */
1056 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1057 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1058 },
984263bc
MD
1059 },
1060#if 0
1061 { 0x0015F420, 0, /* 00-A0-7D */
1062 {
1063 { 0x12, 0x0010, 0x0000 }, /* 10T */
1064 { }, /* 100TX */
1065 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1066 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1067 },
984263bc
MD
1068 },
1069#endif
1070 { 0x0281F400, 0, /* 00-A0-BE */
1071 {
1072 { 0x11, 0x8000, 0x0000 }, /* 10T */
1073 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1074 { }, /* 100T4 */
1075 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1076 },
984263bc
MD
1077 },
1078 { 0 }
1079};
79fe23de 1080
984263bc 1081static tulip_media_t
79fe23de 1082tulip_mii_phy_readspecific(tulip_softc_t *sc)
984263bc
MD
1083{
1084 const tulip_phy_attr_t *attr;
1085 u_int16_t data;
1086 u_int32_t id;
1087 unsigned idx = 0;
1088 static const tulip_media_t table[] = {
1089 TULIP_MEDIA_UNKNOWN,
1090 TULIP_MEDIA_10BASET,
1091 TULIP_MEDIA_100BASETX,
1092 TULIP_MEDIA_100BASET4,
1093 TULIP_MEDIA_UNKNOWN,
1094 TULIP_MEDIA_10BASET_FD,
1095 TULIP_MEDIA_100BASETX_FD,
1096 TULIP_MEDIA_UNKNOWN
1097 };
1098
1099 /*
1100 * Don't read phy specific registers if link is not up.
1101 */
1102 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
1103 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS))
1104 return TULIP_MEDIA_UNKNOWN;
1105
1106 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) |
1107 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH);
1108 for (attr = tulip_mii_phy_attrlist;; attr++) {
1109 if (attr->attr_id == 0)
1110 return TULIP_MEDIA_UNKNOWN;
1111 if ((id & ~0x0F) == attr->attr_id)
1112 break;
1113 }
1114
1115 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
79fe23de 1116 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_100TX];
984263bc
MD
1117 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1118 if ((data & pm->pm_mask) == pm->pm_value)
1119 idx = 2;
1120 }
1121 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) {
79fe23de 1122 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_100T4];
984263bc
MD
1123 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1124 if ((data & pm->pm_mask) == pm->pm_value)
1125 idx = 3;
1126 }
1127 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) {
79fe23de 1128 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_10T];
984263bc
MD
1129 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1130 if ((data & pm->pm_mask) == pm->pm_value)
1131 idx = 1;
1132 }
1133 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) {
79fe23de 1134 const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
984263bc
MD
1135 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1136 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
1137 }
1138 return table[idx];
1139}
79fe23de
JS
1140
1141static u_int
1142tulip_mii_get_phyaddr(tulip_softc_t *sc, u_int offset)
984263bc 1143{
79fe23de 1144 u_int phyaddr;
984263bc
MD
1145
1146 for (phyaddr = 1; phyaddr < 32; phyaddr++) {
79fe23de 1147 u_int status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
984263bc
MD
1148 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1149 continue;
1150 if (offset == 0)
1151 return phyaddr;
1152 offset--;
1153 }
1154 if (offset == 0) {
79fe23de 1155 u_int status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
984263bc
MD
1156 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1157 return TULIP_MII_NOPHY;
1158 return 0;
1159 }
1160 return TULIP_MII_NOPHY;
1161}
79fe23de 1162
984263bc 1163static int
79fe23de 1164tulip_mii_map_abilities(tulip_softc_t *sc, u_int abilities)
984263bc
MD
1165{
1166 sc->tulip_abilities = abilities;
1167 if (abilities & PHYSTS_100BASETX_FD) {
1168 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD;
1169 } else if (abilities & PHYSTS_100BASET4) {
1170 sc->tulip_probe_media = TULIP_MEDIA_100BASET4;
1171 } else if (abilities & PHYSTS_100BASETX) {
1172 sc->tulip_probe_media = TULIP_MEDIA_100BASETX;
1173 } else if (abilities & PHYSTS_10BASET_FD) {
1174 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1175 } else if (abilities & PHYSTS_10BASET) {
1176 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1177 } else {
1178 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1179 return 0;
1180 }
1181 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1182 return 1;
1183}
1184
1185static void
79fe23de 1186tulip_mii_autonegotiate(tulip_softc_t *sc, u_int phyaddr)
984263bc
MD
1187{
1188 switch (sc->tulip_probe_state) {
1189 case TULIP_PROBE_MEDIATEST:
1190 case TULIP_PROBE_INACTIVE: {
1191 sc->tulip_flags |= TULIP_DIDNWAY;
1192 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET);
1193 sc->tulip_probe_timeout = 3000;
1194 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR;
1195 sc->tulip_probe_state = TULIP_PROBE_PHYRESET;
1196 /* FALL THROUGH */
1197 }
1198 case TULIP_PROBE_PHYRESET: {
79fe23de
JS
1199 uint32_t status;
1200 uint32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
984263bc
MD
1201 if (data & PHYCTL_RESET) {
1202 if (sc->tulip_probe_timeout > 0) {
1203 tulip_timeout(sc);
1204 return;
1205 }
1206 printf("%s%d(phy%d): error: reset of PHY never completed!\n",
1207 sc->tulip_name, sc->tulip_unit, phyaddr);
1208 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1209 sc->tulip_probe_state = TULIP_PROBE_FAILED;
1210 sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
1211 return;
1212 }
1213 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1214 if ((status & PHYSTS_CAN_AUTONEG) == 0) {
984263bc
MD
1215 sc->tulip_flags &= ~TULIP_DIDNWAY;
1216 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1217 return;
1218 }
1219 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01))
1220 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
1221 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
1222 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
984263bc
MD
1223 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
1224 sc->tulip_probe_timeout = 3000;
1225 /* FALL THROUGH */
1226 }
1227 case TULIP_PROBE_PHYAUTONEG: {
1228 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1229 u_int32_t data;
1230 if ((status & PHYSTS_AUTONEG_DONE) == 0) {
1231 if (sc->tulip_probe_timeout > 0) {
1232 tulip_timeout(sc);
1233 return;
1234 }
984263bc
MD
1235 sc->tulip_flags &= ~TULIP_DIDNWAY;
1236 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1237 return;
1238 }
1239 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
984263bc
MD
1240 data = (data << 6) & status;
1241 if (!tulip_mii_map_abilities(sc, data))
1242 sc->tulip_flags &= ~TULIP_DIDNWAY;
1243 return;
1244 }
1245 default: {
1246#if defined(DIAGNOSTIC)
1247 panic("tulip_media_poll: botch at line %d\n", __LINE__);
1248#endif
1249 break;
1250 }
1251 }
984263bc 1252}
79fe23de 1253
984263bc 1254static void
79fe23de 1255tulip_2114x_media_preset(tulip_softc_t *sc)
984263bc
MD
1256{
1257 const tulip_media_info_t *mi = NULL;
1258 tulip_media_t media = sc->tulip_media;
1259
1260 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1261 media = sc->tulip_media;
1262 else
1263 media = sc->tulip_probe_media;
1264
1265 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
1266 sc->tulip_flags &= ~TULIP_SQETEST;
1267 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
984263bc
MD
1268 mi = sc->tulip_mediums[media];
1269 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
1270 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1271 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR
1272 || mi->mi_type == TULIP_MEDIAINFO_SYM) {
1273 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
1274 sc->tulip_cmdmode |= mi->mi_cmdmode;
1275 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
1276 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
1277 }
984263bc
MD
1278 }
1279 switch (media) {
1280 case TULIP_MEDIA_BNC:
1281 case TULIP_MEDIA_AUI:
1282 case TULIP_MEDIA_10BASET: {
1283 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1284 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
1285 sc->tulip_if.if_baudrate = 10000000;
1286 sc->tulip_flags |= TULIP_SQETEST;
1287 break;
1288 }
1289 case TULIP_MEDIA_10BASET_FD: {
1290 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
1291 sc->tulip_if.if_baudrate = 10000000;
1292 break;
1293 }
1294 case TULIP_MEDIA_100BASEFX:
1295 case TULIP_MEDIA_100BASET4:
1296 case TULIP_MEDIA_100BASETX: {
1297 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL);
1298 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1299 sc->tulip_if.if_baudrate = 100000000;
1300 break;
1301 }
1302 case TULIP_MEDIA_100BASEFX_FD:
1303 case TULIP_MEDIA_100BASETX_FD: {
1304 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT;
1305 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
1306 sc->tulip_if.if_baudrate = 100000000;
1307 break;
1308 }
1309 default: {
1310 break;
1311 }
1312 }
1313 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1314}
79fe23de 1315
984263bc
MD
1316/*
1317 ********************************************************************
1318 * Start of 21140/21140A support which does not use the MII interface
1319 */
79fe23de 1320
984263bc 1321static void
79fe23de 1322tulip_null_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
984263bc 1323{
984263bc
MD
1324#if defined(DIAGNOSTIC)
1325 printf("%s%d: botch(media_poll) at line %d\n",
1326 sc->tulip_name, sc->tulip_unit, __LINE__);
1327#endif
1328}
1329
79fe23de
JS
1330static void
1331tulip_21140_mediainit(tulip_softc_t *sc, tulip_media_info_t *mip,
1332 tulip_media_t media, u_int gpdata, u_int cmdmode)
984263bc
MD
1333{
1334 sc->tulip_mediums[media] = mip;
1335 mip->mi_type = TULIP_MEDIAINFO_GPR;
1336 mip->mi_cmdmode = cmdmode;
1337 mip->mi_gpdata = gpdata;
1338}
79fe23de 1339
984263bc 1340static void
79fe23de 1341tulip_21140_evalboard_media_probe(tulip_softc_t *sc)
984263bc
MD
1342{
1343 tulip_media_info_t *mip = sc->tulip_mediainfo;
1344
1345 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1346 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1347 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1348 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1349 TULIP_CSR_WRITE(sc, csr_command,
1350 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1351 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1352 TULIP_CSR_WRITE(sc, csr_command,
1353 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1354 DELAY(1000000);
1355 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
1356 sc->tulip_media = TULIP_MEDIA_10BASET;
1357 } else {
1358 sc->tulip_media = TULIP_MEDIA_100BASETX;
1359 }
1360 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1361 TULIP_GP_EB_INIT,
1362 TULIP_CMD_TXTHRSHLDCTL);
1363 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1364 TULIP_GP_EB_INIT,
1365 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1366 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1367 TULIP_GP_EB_INIT,
1368 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1369 |TULIP_CMD_SCRAMBLER);
1370 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1371 TULIP_GP_EB_INIT,
1372 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1373 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1374}
1375
1376static const tulip_boardsw_t tulip_21140_eb_boardsw = {
1377 TULIP_21140_DEC_EB,
1378 tulip_21140_evalboard_media_probe,
1379 tulip_media_select,
1380 tulip_null_media_poll,
1381 tulip_2114x_media_preset,
1382};
79fe23de 1383
984263bc 1384static void
79fe23de 1385tulip_21140_accton_media_probe(tulip_softc_t *sc)
984263bc
MD
1386{
1387 tulip_media_info_t *mip = sc->tulip_mediainfo;
79fe23de 1388 u_int gpdata;
984263bc
MD
1389
1390 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1391 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1392 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1393 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1394 TULIP_CSR_WRITE(sc, csr_command,
1395 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1396 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1397 TULIP_CSR_WRITE(sc, csr_command,
1398 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1399 DELAY(1000000);
1400 gpdata = TULIP_CSR_READ(sc, csr_gp);
1401 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) {
1402 sc->tulip_media = TULIP_MEDIA_10BASET;
1403 } else {
1404 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) {
1405 sc->tulip_media = TULIP_MEDIA_BNC;
1406 } else {
1407 sc->tulip_media = TULIP_MEDIA_100BASETX;
1408 }
1409 }
1410 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC,
1411 TULIP_GP_EN1207_BNC_INIT,
1412 TULIP_CMD_TXTHRSHLDCTL);
1413 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1414 TULIP_GP_EN1207_UTP_INIT,
1415 TULIP_CMD_TXTHRSHLDCTL);
1416 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1417 TULIP_GP_EN1207_UTP_INIT,
1418 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1419 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1420 TULIP_GP_EN1207_100_INIT,
1421 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1422 |TULIP_CMD_SCRAMBLER);
1423 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1424 TULIP_GP_EN1207_100_INIT,
1425 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1426 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1427}
1428
1429static const tulip_boardsw_t tulip_21140_accton_boardsw = {
1430 TULIP_21140_EN1207,
1431 tulip_21140_accton_media_probe,
1432 tulip_media_select,
1433 tulip_null_media_poll,
1434 tulip_2114x_media_preset,
1435};
79fe23de 1436
984263bc 1437static void
79fe23de 1438tulip_21140_smc9332_media_probe(tulip_softc_t *sc)
984263bc
MD
1439{
1440 tulip_media_info_t *mip = sc->tulip_mediainfo;
1441 int idx, cnt = 0;
1442
1443 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE);
1444 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
1445 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
1446 33MHz that comes to two microseconds but wait a
1447 bit longer anyways) */
1448 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT |
1449 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1450 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS;
1451 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT;
1452 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET);
1453 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT);
1454 DELAY(200000);
1455 for (idx = 1000; idx > 0; idx--) {
1456 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1457 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) {
1458 if (++cnt > 100)
1459 break;
1460 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
1461 break;
1462 } else {
1463 cnt = 0;
1464 }
1465 DELAY(1000);
1466 }
1467 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1468 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1469 TULIP_GP_SMC_9332_INIT,
1470 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1471 |TULIP_CMD_SCRAMBLER);
1472 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1473 TULIP_GP_SMC_9332_INIT,
1474 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1475 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1476 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1477 TULIP_GP_SMC_9332_INIT,
1478 TULIP_CMD_TXTHRSHLDCTL);
1479 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1480 TULIP_GP_SMC_9332_INIT,
1481 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1482}
1483
1484static const tulip_boardsw_t tulip_21140_smc9332_boardsw = {
1485 TULIP_21140_SMC_9332,
1486 tulip_21140_smc9332_media_probe,
1487 tulip_media_select,
1488 tulip_null_media_poll,
1489 tulip_2114x_media_preset,
1490};
79fe23de 1491
984263bc 1492static void
79fe23de 1493tulip_21140_cogent_em100_media_probe(tulip_softc_t *sc)
984263bc
MD
1494{
1495 tulip_media_info_t *mip = sc->tulip_mediainfo;
79fe23de 1496 uint32_t cmdmode = TULIP_CSR_READ(sc, csr_command);
984263bc
MD
1497
1498 sc->tulip_gpinit = TULIP_GP_EM100_PINS;
1499 sc->tulip_gpdata = TULIP_GP_EM100_INIT;
1500 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS);
1501 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT);
1502
1503 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE;
1504 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER);
1505 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1506 TULIP_CSR_WRITE(sc, csr_command, cmdmode);
1507 sc->tulip_media = TULIP_MEDIA_100BASEFX;
1508
1509 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX,
1510 TULIP_GP_EM100_INIT,
1511 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION);
1512 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD,
1513 TULIP_GP_EM100_INIT,
1514 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1515 |TULIP_CMD_FULLDUPLEX);
1516 } else {
1517 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);
1518 sc->tulip_media = TULIP_MEDIA_100BASETX;
1519 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1520 TULIP_GP_EM100_INIT,
1521 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1522 |TULIP_CMD_SCRAMBLER);
1523 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1524 TULIP_GP_EM100_INIT,
1525 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1526 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1527 }
1528}
1529
1530static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {
1531 TULIP_21140_COGENT_EM100,
1532 tulip_21140_cogent_em100_media_probe,
1533 tulip_media_select,
1534 tulip_null_media_poll,
1535 tulip_2114x_media_preset
1536};
79fe23de 1537
984263bc 1538static void
79fe23de 1539tulip_21140_znyx_zx34x_media_probe(tulip_softc_t *sc)
984263bc
MD
1540{
1541 tulip_media_info_t *mip = sc->tulip_mediainfo;
1542 int cnt10 = 0, cnt100 = 0, idx;
1543
1544 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS;
1545 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT;
1546 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS);
1547 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT);
1548 TULIP_CSR_WRITE(sc, csr_command,
1549 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1550 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1551 TULIP_CSR_WRITE(sc, csr_command,
1552 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1553
1554 DELAY(200000);
1555 for (idx = 1000; idx > 0; idx--) {
79fe23de 1556 uint32_t csr = TULIP_CSR_READ(sc, csr_gp);
984263bc
MD
1557 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)) {
1558 if (++cnt100 > 100)
1559 break;
1560 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
1561 if (++cnt10 > 100)
1562 break;
1563 } else {
1564 cnt10 = 0;
1565 cnt100 = 0;
1566 }
1567 DELAY(1000);
1568 }
1569 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1570 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1571 TULIP_GP_ZX34X_INIT,
1572 TULIP_CMD_TXTHRSHLDCTL);
1573 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1574 TULIP_GP_ZX34X_INIT,
1575 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1576 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1577 TULIP_GP_ZX34X_INIT,
1578 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1579 |TULIP_CMD_SCRAMBLER);
1580 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1581 TULIP_GP_ZX34X_INIT,
1582 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1583 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1584}
1585
1586static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = {
1587 TULIP_21140_ZNYX_ZX34X,
1588 tulip_21140_znyx_zx34x_media_probe,
1589 tulip_media_select,
1590 tulip_null_media_poll,
1591 tulip_2114x_media_preset,
1592};
79fe23de 1593
984263bc 1594static void
79fe23de 1595tulip_2114x_media_probe(tulip_softc_t *sc)
984263bc 1596{
79fe23de
JS
1597 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE | TULIP_CMD_BACKOFFCTR |
1598 TULIP_CMD_THRSHLD72;
984263bc
MD
1599}
1600
1601static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
1602 TULIP_21140_ISV,
1603 tulip_2114x_media_probe,
1604 tulip_media_select,
1605 tulip_media_poll,
1606 tulip_2114x_media_preset,
1607};
79fe23de 1608
984263bc
MD
1609/*
1610 * ******** END of chip-specific handlers. ***********
1611 */
79fe23de 1612
984263bc
MD
1613/*
1614 * Code the read the SROM and MII bit streams (I2C)
1615 */
79fe23de
JS
1616#define EMIT do { \
1617 TULIP_CSR_WRITE(sc, csr_srom_mii, csr); \
1618 DELAY(1); \
1619} while (0)
984263bc
MD
1620
1621static void
79fe23de 1622tulip_srom_idle(tulip_softc_t *sc)
984263bc 1623{
79fe23de 1624 u_int bit, csr;
984263bc
MD
1625
1626 csr = SROMSEL ; EMIT;
1627 csr = SROMSEL | SROMRD; EMIT;
1628 csr ^= SROMCS; EMIT;
1629 csr ^= SROMCLKON; EMIT;
1630
1631 /*
1632 * Write 25 cycles of 0 which will force the SROM to be idle.
1633 */
1634 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1635 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1636 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1637 }
1638 csr ^= SROMCLKOFF; EMIT;
1639 csr ^= SROMCS; EMIT;
1640 csr = 0; EMIT;
1641}
1642
1643
1644static void
79fe23de 1645tulip_srom_read(tulip_softc_t *sc)
984263bc 1646{
79fe23de
JS
1647 const u_int bitwidth = SROM_BITWIDTH;
1648 const u_int cmdmask = (SROMCMD_RD << bitwidth);
1649 const u_int msb = 1 << (bitwidth + 3 - 1);
1650 u_int idx, lastidx = (1 << bitwidth) - 1;
984263bc
MD
1651
1652 tulip_srom_idle(sc);
1653
1654 for (idx = 0; idx <= lastidx; idx++) {
79fe23de 1655 u_int lastbit, data, bits, bit, csr;
984263bc
MD
1656 csr = SROMSEL ; EMIT;
1657 csr = SROMSEL | SROMRD; EMIT;
1658 csr ^= SROMCSON; EMIT;
1659 csr ^= SROMCLKON; EMIT;
1660
1661 lastbit = 0;
1662 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
79fe23de 1663 u_int thisbit = bits & msb;
984263bc
MD
1664 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1665 if (thisbit != lastbit) {
1666 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1667 } else {
1668 EMIT;
1669 }
1670 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1671 lastbit = thisbit;
1672 }
1673 csr ^= SROMCLKOFF; EMIT;
1674
1675 for (data = 0, bits = 0; bits < 16; bits++) {
1676 data <<= 1;
1677 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1678 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1679 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1680 }
1681 sc->tulip_rombuf[idx*2] = data & 0xFF;
1682 sc->tulip_rombuf[idx*2+1] = data >> 8;
1683 csr = SROMSEL | SROMRD; EMIT;
1684 csr = 0; EMIT;
1685 }
1686 tulip_srom_idle(sc);
1687}
79fe23de
JS
1688
1689#define MII_EMIT do { \
1690 TULIP_CSR_WRITE(sc, csr_srom_mii, csr); \
1691 DELAY(1); \
1692} while (0)
984263bc
MD
1693
1694static void
79fe23de 1695tulip_mii_writebits(tulip_softc_t *sc, u_int data, u_int bits)
984263bc 1696{
79fe23de 1697 u_int csr, msb, lastbit;
984263bc 1698
79fe23de
JS
1699 msb = 1 << (bits - 1);
1700 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1701 lastbit = (csr & MII_DOUT) ? msb : 0;
984263bc
MD
1702 csr |= MII_WR; MII_EMIT; /* clock low; assert write */
1703
1704 for (; bits > 0; bits--, data <<= 1) {
1705 const unsigned thisbit = data & msb;
1706 if (thisbit != lastbit) {
1707 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */
1708 }
1709 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1710 lastbit = thisbit;
1711 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1712 }
1713}
1714
1715static void
79fe23de 1716tulip_mii_turnaround(tulip_softc_t *sc, u_int cmd)
984263bc 1717{
79fe23de
JS
1718 u_int csr;
1719
1720 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
984263bc
MD
1721
1722 if (cmd == MII_WRCMD) {
1723 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
1724 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1725 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1726 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */
1727 } else {
1728 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */
1729 }
1730 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1731 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1732}
1733
79fe23de
JS
1734static u_int
1735tulip_mii_readbits(tulip_softc_t *sc)
984263bc 1736{
79fe23de
JS
1737 u_int csr, data, idx;
1738
1739 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
984263bc
MD
1740
1741 for (idx = 0, data = 0; idx < 16; idx++) {
1742 data <<= 1; /* this is NOOP on the first pass through */
1743 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1744 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)
1745 data |= 1;
1746 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1747 }
1748 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
1749
1750 return data;
1751}
1752
79fe23de
JS
1753static u_int
1754tulip_mii_readreg(tulip_softc_t *sc, u_int devaddr, u_int regno)
984263bc 1755{
79fe23de
JS
1756 u_int csr;
1757 u_int data;
984263bc 1758
79fe23de 1759 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
984263bc
MD
1760 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1761 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1762 tulip_mii_writebits(sc, MII_RDCMD, 8);
1763 tulip_mii_writebits(sc, devaddr, 5);
1764 tulip_mii_writebits(sc, regno, 5);
1765 tulip_mii_turnaround(sc, MII_RDCMD);
1766
1767 data = tulip_mii_readbits(sc);
984263bc
MD
1768 return data;
1769}
1770
1771static void
79fe23de 1772tulip_mii_writereg(tulip_softc_t *sc, u_int devaddr, u_int regno, u_int data)
984263bc 1773{
79fe23de
JS
1774 u_int csr;
1775
1776 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
984263bc
MD
1777 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1778 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1779 tulip_mii_writebits(sc, MII_WRCMD, 8);
1780 tulip_mii_writebits(sc, devaddr, 5);
1781 tulip_mii_writebits(sc, regno, 5);
1782 tulip_mii_turnaround(sc, MII_WRCMD);
1783 tulip_mii_writebits(sc, data, 16);
984263bc 1784}
79fe23de 1785
18261b0d 1786#define tulip_mchash(mca) (ether_crc32_le(mca, 6) & 0x1FF)
984263bc 1787#define tulip_srom_crcok(databuf) ( \
18261b0d 1788 ((ether_crc32_le(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
984263bc 1789 ((databuf)[126] | ((databuf)[127] << 8)))
984263bc
MD
1790\f
1791static void
79fe23de 1792tulip_identify_dec_nic(tulip_softc_t *sc)
984263bc
MD
1793{
1794 strcpy(sc->tulip_boardid, "DEC ");
1795#define D0 4
1796 if (sc->tulip_chipid <= TULIP_21040)
1797 return;
1798 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0
1799 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {
1800 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);
1801 sc->tulip_boardid[D0+8] = ' ';
1802 }
1803#undef D0
1804}
79fe23de 1805
984263bc 1806static void
79fe23de 1807tulip_identify_znyx_nic(tulip_softc_t * const sc)
984263bc 1808{
79fe23de 1809 u_int id = 0;
984263bc
MD
1810 strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
1811 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
79fe23de 1812 u_int znyx_ptr;
984263bc
MD
1813 sc->tulip_boardid[8] = '4';
1814 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
1815 if (znyx_ptr < 26 || znyx_ptr > 116) {
1816 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1817 return;
1818 }
1819 /* ZX344 = 0010 .. 0013FF
1820 */
1821 if (sc->tulip_rombuf[znyx_ptr] == 0x4A
1822 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52
1823 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) {
1824 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4];
1825 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) {
1826 sc->tulip_boardid[9] = '2';
1827 if (id == TULIP_ZNYX_ID_ZX342B) {
1828 sc->tulip_boardid[10] = 'B';
1829 sc->tulip_boardid[11] = ' ';
1830 }
1831 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1832 } else if (id == TULIP_ZNYX_ID_ZX344) {
1833 sc->tulip_boardid[10] = '4';
1834 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1835 } else if (id == TULIP_ZNYX_ID_ZX345) {
1836 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5';
1837 } else if (id == TULIP_ZNYX_ID_ZX346) {
1838 sc->tulip_boardid[9] = '6';
1839 } else if (id == TULIP_ZNYX_ID_ZX351) {
1840 sc->tulip_boardid[8] = '5';
1841 sc->tulip_boardid[9] = '1';
1842 }
1843 }
1844 if (id == 0) {
1845 /*
1846 * Assume it's a ZX342...
1847 */
1848 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
1849 }
1850 return;
1851 }
1852 sc->tulip_boardid[8] = '1';
1853 if (sc->tulip_chipid == TULIP_21041) {
1854 sc->tulip_boardid[10] = '1';
1855 return;
1856 }
1857 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) {
1858 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36];
1859 if (id == TULIP_ZNYX_ID_ZX312T) {
1860 sc->tulip_boardid[9] = '2';
1861 sc->tulip_boardid[10] = 'T';
1862 sc->tulip_boardid[11] = ' ';
1863 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1864 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) {
1865 sc->tulip_boardid[9] = '4';
1866 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1867 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1868 } else if (id == TULIP_ZNYX_ID_ZX314) {
1869 sc->tulip_boardid[9] = '4';
1870 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1871 sc->tulip_features |= TULIP_HAVE_BASEROM;
1872 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) {
1873 sc->tulip_boardid[9] = '5';
1874 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1875 } else if (id == TULIP_ZNYX_ID_ZX315) {
1876 sc->tulip_boardid[9] = '5';
1877 sc->tulip_features |= TULIP_HAVE_BASEROM;
1878 } else {
1879 id = 0;
1880 }
1881 }
1882 if (id == 0) {
1883 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) {
1884 sc->tulip_boardid[9] = '4';
1885 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1886 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1887 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) {
1888 sc->tulip_boardid[9] = '5';
1889 sc->tulip_boardsw = &tulip_21040_boardsw;
1890 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1891 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) {
1892 sc->tulip_boardid[9] = '2';
1893 sc->tulip_boardsw = &tulip_21040_boardsw;
1894 }
1895 }
1896}
79fe23de 1897
984263bc 1898static void
79fe23de 1899tulip_identify_smc_nic(tulip_softc_t * const sc)
984263bc 1900{
79fe23de 1901 uint32_t id1, id2, ei;
984263bc
MD
1902 int auibnc = 0, utp = 0;
1903 char *cp;
1904
1905 strcpy(sc->tulip_boardid, "SMC ");
1906 if (sc->tulip_chipid == TULIP_21041)
1907 return;
1908 if (sc->tulip_chipid != TULIP_21040) {
1909 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
1910 strcpy(&sc->tulip_boardid[4], "9332DST ");
1911 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;
1912 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {
1913 strcpy(&sc->tulip_boardid[4], "9334BDT ");
1914 } else {
1915 strcpy(&sc->tulip_boardid[4], "9332BDT ");
1916 }
1917 return;
1918 }
1919 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);
1920 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);
1921 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);
1922
1923 strcpy(&sc->tulip_boardid[4], "8432");
1924 cp = &sc->tulip_boardid[8];
1925 if ((id1 & 1) == 0)
1926 *cp++ = 'B', auibnc = 1;
1927 if ((id1 & 0xFF) > 0x32)
1928 *cp++ = 'T', utp = 1;
1929 if ((id1 & 0x4000) == 0)
1930 *cp++ = 'A', auibnc = 1;
1931 if (id2 == 0x15) {
1932 sc->tulip_boardid[7] = '4';
1933 *cp++ = '-';
1934 *cp++ = 'C';
1935 *cp++ = 'H';
1936 *cp++ = (ei ? '2' : '1');
1937 }
1938 *cp++ = ' ';
1939 *cp = '\0';
1940 if (utp && !auibnc)
1941 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
1942 else if (!utp && auibnc)
1943 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
1944}
79fe23de 1945
984263bc 1946static void
79fe23de 1947tulip_identify_cogent_nic(tulip_softc_t * const sc)
984263bc
MD
1948{
1949 strcpy(sc->tulip_boardid, "Cogent ");
1950 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
1951 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {
1952 strcat(sc->tulip_boardid, "EM100TX ");
1953 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1954#if defined(TULIP_COGENT_EM110TX_ID)
1955 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {
1956 strcat(sc->tulip_boardid, "EM110TX ");
1957 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1958#endif
1959 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1960 strcat(sc->tulip_boardid, "EM100FX ");
1961 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
1962 }
1963 /*
1964 * Magic number (0x24001109U) is the SubVendor (0x2400) and
1965 * SubDevId (0x1109) for the ANA6944TX (EM440TX).
1966 */
79fe23de 1967 if (*(uint32_t *) sc->tulip_rombuf == 0x24001109U
984263bc
MD
1968 && (sc->tulip_features & TULIP_HAVE_BASEROM)) {
1969 /*
1970 * Cogent (Adaptec) is still mapping all INTs to INTA of
1971 * first 21140. Dumb! Dumb!
1972 */
1973 strcat(sc->tulip_boardid, "EM440TX ");
1974 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
1975 }
1976 } else if (sc->tulip_chipid == TULIP_21040) {
1977 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
1978 }
1979}
79fe23de 1980
984263bc 1981static void
79fe23de 1982tulip_identify_accton_nic(tulip_softc_t * const sc)
984263bc
MD
1983{
1984 strcpy(sc->tulip_boardid, "ACCTON ");
1985 switch (sc->tulip_chipid) {
1986 case TULIP_21140A:
1987 strcat(sc->tulip_boardid, "EN1207 ");
1988 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
1989 sc->tulip_boardsw = &tulip_21140_accton_boardsw;
1990 break;
1991 case TULIP_21140:
1992 strcat(sc->tulip_boardid, "EN1207TX ");
1993 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
1994 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
1995 break;
1996 case TULIP_21040:
1997 strcat(sc->tulip_boardid, "EN1203 ");
1998 sc->tulip_boardsw = &tulip_21040_boardsw;
1999 break;
2000 case TULIP_21041:
2001 strcat(sc->tulip_boardid, "EN1203 ");
2002 sc->tulip_boardsw = &tulip_21041_boardsw;
2003 break;
2004 default:
2005 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2006 break;
2007 }
2008}
79fe23de 2009
984263bc 2010static void
79fe23de 2011tulip_identify_asante_nic(tulip_softc_t * const sc)
984263bc
MD
2012{
2013 strcpy(sc->tulip_boardid, "Asante ");
2014 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
2015 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2016 tulip_media_info_t *mi = sc->tulip_mediainfo;
2017 int idx;
2018 /*
2019 * The Asante Fast Ethernet doesn't always ship with a valid
2020 * new format SROM. So if isn't in the new format, we cheat
2021 * set it up as if we had.
2022 */
2023
2024 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;
2025 sc->tulip_gpdata = 0;
2026
2027 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);
2028 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);
2029 DELAY(100);
2030 TULIP_CSR_WRITE(sc, csr_gp, 0);
2031
2032 mi->mi_type = TULIP_MEDIAINFO_MII;
2033 mi->mi_gpr_length = 0;
2034 mi->mi_gpr_offset = 0;
2035 mi->mi_reset_length = 0;
2036 mi->mi_reset_offset = 0;;
2037
2038 mi->mi_phyaddr = TULIP_MII_NOPHY;
2039 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) {
2040 DELAY(10000);
2041 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
2042 }
2043 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2044 printf("%s%d: can't find phy 0\n", sc->tulip_name, sc->tulip_unit);
2045 return;
2046 }
2047
2048 sc->tulip_features |= TULIP_HAVE_MII;
2049 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2050 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2051 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD;
2052 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD;
2053 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2054 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2055 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2056 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2057 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2058 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2059 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2060
2061 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2062 }
2063}
79fe23de 2064
984263bc 2065static void
79fe23de 2066tulip_identify_compex_nic(tulip_softc_t *sc)
984263bc
MD
2067{
2068 strcpy(sc->tulip_boardid, "COMPEX ");
2069 if (sc->tulip_chipid == TULIP_21140A) {
2070 int root_unit;
2071 tulip_softc_t *root_sc = NULL;
2072
2073 strcat(sc->tulip_boardid, "400TX/PCI ");
2074 /*
2075 * All 4 chips on these boards share an interrupt. This code
2076 * copied from tulip_read_macaddr.
2077 */
2078 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2079 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2080 root_sc = tulips[root_unit];
2081 if (root_sc == NULL
2082 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
2083 break;
2084 root_sc = NULL;
2085 }
2086 if (root_sc != NULL
2087 && root_sc->tulip_chipid == sc->tulip_chipid
2088 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2089 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2090 sc->tulip_slaves = root_sc->tulip_slaves;
2091 root_sc->tulip_slaves = sc;
2092 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
2093 printf("\nCannot find master device for de%d interrupts",
2094 sc->tulip_unit);
2095 }
2096 } else {
2097 strcat(sc->tulip_boardid, "unknown ");
2098 }
2099 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */
2100 return;
2101}
2102\f
2103static int
79fe23de 2104tulip_srom_decode(tulip_softc_t *sc)
984263bc 2105{
79fe23de 2106 u_int idx1, idx2, idx3;
984263bc
MD
2107
2108 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
2109 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
2110 tulip_srom_media_t srom_media;
2111 tulip_media_info_t *mi = sc->tulip_mediainfo;
79fe23de
JS
2112 const uint8_t *dp;
2113 uint32_t leaf_offset, blocks, data;
984263bc
MD
2114
2115 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
2116 if (shp->sh_adapter_count == 1)
2117 break;
2118 if (saip->sai_device == sc->tulip_pci_devno)
2119 break;
2120 }
2121 /*
2122 * Didn't find the right media block for this card.
2123 */
2124 if (idx1 == shp->sh_adapter_count)
2125 return 0;
2126
2127 /*
2128 * Save the hardware address.
2129 */
2130 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6);
2131 /*
2132 * If this is a multiple port card, add the adapter index to the last
2133 * byte of the hardware address. (if it isn't multiport, adding 0
2134 * won't hurt.
2135 */
2136 sc->tulip_enaddr[5] += idx1;
2137
2138 leaf_offset = saip->sai_leaf_offset_lowbyte
2139 + saip->sai_leaf_offset_highbyte * 256;
2140 dp = sc->tulip_rombuf + leaf_offset;
2141
2142 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2;
2143
2144 for (idx2 = 0;; idx2++) {
2145 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype
2146 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED)
2147 break;
2148 }
2149 sc->tulip_connidx = idx2;
2150
2151 if (sc->tulip_chipid == TULIP_21041) {
2152 blocks = *dp++;
2153 for (idx2 = 0; idx2 < blocks; idx2++) {
2154 tulip_media_t media;
2155 data = *dp++;
2156 srom_media = (tulip_srom_media_t) (data & 0x3F);
2157 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2158 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2159 break;
2160 }
2161 media = tulip_srom_mediums[idx3].sm_type;
2162 if (media != TULIP_MEDIA_UNKNOWN) {
2163 if (data & TULIP_SROM_21041_EXTENDED) {
2164 mi->mi_type = TULIP_MEDIAINFO_SIA;
2165 sc->tulip_mediums[media] = mi;
2166 mi->mi_sia_connectivity = dp[0] + dp[1] * 256;
2167 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256;
2168 mi->mi_sia_general = dp[4] + dp[5] * 256;
2169 mi++;
2170 } else {
2171 switch (media) {
2172 case TULIP_MEDIA_BNC: {
2173 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
2174 mi++;
2175 break;
2176 }
2177 case TULIP_MEDIA_AUI: {
2178 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
2179 mi++;
2180 break;
2181 }
2182 case TULIP_MEDIA_10BASET: {
2183 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
2184 mi++;
2185 break;
2186 }
2187 case TULIP_MEDIA_10BASET_FD: {
2188 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
2189 mi++;
2190 break;
2191 }
2192 default: {
2193 break;
2194 }
2195 }
2196 }
2197 }
2198 if (data & TULIP_SROM_21041_EXTENDED)
2199 dp += 6;
2200 }
2201#ifdef notdef
2202 if (blocks == 0) {
2203 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++;
2204 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++;
2205 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++;
2206 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++;
2207 }
2208#endif
2209 } else {
2210 unsigned length, type;
2211 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN;
2212 if (sc->tulip_features & TULIP_HAVE_GPR)
2213 sc->tulip_gpinit = *dp++;
2214 blocks = *dp++;
2215 for (idx2 = 0; idx2 < blocks; idx2++) {
79fe23de 2216 const uint8_t *ep;
984263bc
MD
2217 if ((*dp & 0x80) == 0) {
2218 length = 4;
2219 type = 0;
2220 } else {
2221 length = (*dp++ & 0x7f) - 1;
2222 type = *dp++ & 0x3f;
2223 }
2224 ep = dp + length;
2225 switch (type & 0x3f) {
2226 case 0: { /* 21140[A] GPR block */
2227 tulip_media_t media;
2228 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2229 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2230 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2231 break;
2232 }
2233 media = tulip_srom_mediums[idx3].sm_type;
2234 if (media == TULIP_MEDIA_UNKNOWN)
2235 break;
2236 mi->mi_type = TULIP_MEDIAINFO_GPR;
2237 sc->tulip_mediums[media] = mi;
2238 mi->mi_gpdata = dp[1];
2239 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) {
2240 sc->tulip_gpdata = mi->mi_gpdata;
2241 gp_media = media;
2242 }
2243 data = dp[2] + dp[3] * 256;
2244 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2245 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2246 mi->mi_actmask = 0;
2247 } else {
2248#if 0
2249 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2250#endif
2251 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2252 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2253 }
2254 mi++;
2255 break;
2256 }
2257 case 1: { /* 21140[A] MII block */
79fe23de 2258 const u_int phyno = *dp++;
984263bc
MD
2259 mi->mi_type = TULIP_MEDIAINFO_MII;
2260 mi->mi_gpr_length = *dp++;
2261 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2262 dp += mi->mi_gpr_length;
2263 mi->mi_reset_length = *dp++;
2264 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2265 dp += mi->mi_reset_length;
2266
2267 /*
2268 * Before we probe for a PHY, use the GPR information
2269 * to select it. If we don't, it may be inaccessible.
2270 */
2271 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET);
2272 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) {
2273 DELAY(10);
2274 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]);
2275 }
2276 sc->tulip_phyaddr = mi->mi_phyaddr;
2277 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) {
2278 DELAY(10);
2279 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]);
2280 }
2281
2282 /*
2283 * At least write something!
2284 */
2285 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2286 TULIP_CSR_WRITE(sc, csr_gp, 0);
2287
2288 mi->mi_phyaddr = TULIP_MII_NOPHY;
2289 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2290 DELAY(10000);
2291 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2292 }
46a77a85 2293 if (mi->mi_phyaddr == TULIP_MII_NOPHY)
984263bc 2294 break;
984263bc
MD
2295 sc->tulip_features |= TULIP_HAVE_MII;
2296 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2297 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2298 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2299 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2300 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2301 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2302 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2303 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2304 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2305 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2306 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2307 mi++;
2308 break;
2309 }
2310 case 2: { /* 2114[23] SIA block */
2311 tulip_media_t media;
2312 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2313 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2314 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2315 break;
2316 }
2317 media = tulip_srom_mediums[idx3].sm_type;
2318 if (media == TULIP_MEDIA_UNKNOWN)
2319 break;
2320 mi->mi_type = TULIP_MEDIAINFO_SIA;
2321 sc->tulip_mediums[media] = mi;
2322 if (dp[0] & 0x40) {
2323 mi->mi_sia_connectivity = dp[1] + dp[2] * 256;
2324 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256;
2325 mi->mi_sia_general = dp[5] + dp[6] * 256;
2326 dp += 6;
2327 } else {
2328 switch (media) {
2329 case TULIP_MEDIA_BNC: {
2330 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
2331 break;
2332 }
2333 case TULIP_MEDIA_AUI: {
2334 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
2335 break;
2336 }
2337 case TULIP_MEDIA_10BASET: {
2338 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
2339 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2340 break;
2341 }
2342 case TULIP_MEDIA_10BASET_FD: {
2343 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
2344 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2345 break;
2346 }
2347 default: {
2348 goto bad_media;
2349 }
2350 }
2351 }
2352 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16;
2353 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16;
2354 mi++;
2355 bad_media:
2356 break;
2357 }
2358 case 3: { /* 2114[23] MII PHY block */
79fe23de
JS
2359 const u_int phyno = *dp++;
2360 const uint8_t *dp0;
984263bc
MD
2361 mi->mi_type = TULIP_MEDIAINFO_MII;
2362 mi->mi_gpr_length = *dp++;
2363 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2364 dp += 2 * mi->mi_gpr_length;
2365 mi->mi_reset_length = *dp++;
2366 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2367 dp += 2 * mi->mi_reset_length;
2368
2369 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset];
2370 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) {
2371 DELAY(10);
2372 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2373 }
2374 sc->tulip_phyaddr = mi->mi_phyaddr;
2375 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset];
2376 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) {
2377 DELAY(10);
2378 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2379 }
2380
2381 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2382 TULIP_CSR_WRITE(sc, csr_sia_general, 0);
2383
2384 mi->mi_phyaddr = TULIP_MII_NOPHY;
2385 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2386 DELAY(10000);
2387 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2388 }
46a77a85 2389 if (mi->mi_phyaddr == TULIP_MII_NOPHY)
984263bc 2390 break;
984263bc
MD
2391 sc->tulip_features |= TULIP_HAVE_MII;
2392 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2393 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2394 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2395 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2396 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2;
2397 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2398 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2399 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2400 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2401 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2402 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2403 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2404 mi++;
2405 break;
2406 }
2407 case 4: { /* 21143 SYM block */
2408 tulip_media_t media;
2409 srom_media = (tulip_srom_media_t) dp[0];
2410 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2411 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2412 break;
2413 }
2414 media = tulip_srom_mediums[idx3].sm_type;
2415 if (media == TULIP_MEDIA_UNKNOWN)
2416 break;
2417 mi->mi_type = TULIP_MEDIAINFO_SYM;
2418 sc->tulip_mediums[media] = mi;
2419 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16;
2420 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16;
2421 data = dp[5] + dp[6] * 256;
2422 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2423 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2424 mi->mi_actmask = 0;
2425 } else {
2426 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2427 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2428 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2429 }
2430 if (TULIP_IS_MEDIA_TP(media))
2431 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2432 mi++;
2433 break;
2434 }
2435#if 0
2436 case 5: { /* 21143 Reset block */
2437 mi->mi_type = TULIP_MEDIAINFO_RESET;
2438 mi->mi_reset_length = *dp++;
2439 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2440 dp += 2 * mi->mi_reset_length;
2441 mi++;
2442 break;
2443 }
2444#endif
2445 default: {
2446 }
2447 }
2448 dp = ep;
2449 }
2450 }
2451 return mi - sc->tulip_mediainfo;
2452}
2453\f
2454static const struct {
2455 void (*vendor_identify_nic)(tulip_softc_t * const sc);
2456 unsigned char vendor_oui[3];
2457} tulip_vendors[] = {
2458 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } },
2459 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } },
2460 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } },
2461 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } },
2462 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } },
2463 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } },
2464 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } },
2465 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } },
2466 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } },
2467 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } },
2468 { NULL }
2469};
2470
2471/*
2472 * This deals with the vagaries of the address roms and the
2473 * brain-deadness that various vendors commit in using them.
2474 */
2475static int
79fe23de 2476tulip_read_macaddr(tulip_softc_t *sc)
984263bc 2477{
79fe23de
JS
2478 u_int cksum, rom_cksum, idx;
2479 uint32_t csr;
984263bc
MD
2480 unsigned char tmpbuf[8];
2481 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
2482
2483 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX;
2484
2485 if (sc->tulip_chipid == TULIP_21040) {
2486 TULIP_CSR_WRITE(sc, csr_enetrom, 1);
2487 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2488 int cnt = 0;
2489 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
2490 cnt++;
2491 sc->tulip_rombuf[idx] = csr & 0xFF;
2492 }
2493 sc->tulip_boardsw = &tulip_21040_boardsw;
2494 } else {
2495 if (sc->tulip_chipid == TULIP_21041) {
2496 /*
2497 * Thankfully all 21041's act the same.
2498 */
2499 sc->tulip_boardsw = &tulip_21041_boardsw;
2500 } else {
2501 /*
2502 * Assume all 21140 board are compatible with the
2503 * DEC 10/100 evaluation board. Not really valid but
2504 * it's the best we can do until every one switches to
2505 * the new SROM format.
2506 */
2507
2508 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2509 }
2510 tulip_srom_read(sc);
2511 if (tulip_srom_crcok(sc->tulip_rombuf)) {
2512 /*
2513 * SROM CRC is valid therefore it must be in the
2514 * new format.
2515 */
2516 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM;
2517 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
2518 /*
2519 * No checksum is present. See if the SROM id checks out;
2520 * the first 18 bytes should be 0 followed by a 1 followed
2521 * by the number of adapters (which we don't deal with yet).
2522 */
2523 for (idx = 0; idx < 18; idx++) {
2524 if (sc->tulip_rombuf[idx] != 0)
2525 break;
2526 }
2527 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
2528 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2529 } else if (sc->tulip_chipid >= TULIP_21142) {
2530 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2531 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2532 }
2533 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) {
2534 if (sc->tulip_chipid != TULIP_21041)
2535 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2536
2537 /*
2538 * If the SROM specifies more than one adapter, tag this as a
2539 * BASE rom.
2540 */
2541 if (sc->tulip_rombuf[19] > 1)
2542 sc->tulip_features |= TULIP_HAVE_BASEROM;
2543 if (sc->tulip_boardsw == NULL)
2544 return -6;
2545 goto check_oui;
2546 }
2547 }
2548
2549
2550 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
2551 /*
2552 * Some folks don't use the standard ethernet rom format
2553 * but instead just put the address in the first 6 bytes
2554 * of the rom and let the rest be all 0xffs. (Can we say
2555 * ZNYX?) (well sometimes they put in a checksum so we'll
2556 * start at 8).
2557 */
2558 for (idx = 8; idx < 32; idx++) {
2559 if (sc->tulip_rombuf[idx] != 0xFF)
2560 return -4;
2561 }
2562 /*
2563 * Make sure the address is not multicast or locally assigned
2564 * that the OUI is not 00-00-00.
2565 */
2566 if ((sc->tulip_rombuf[0] & 3) != 0)
2567 return -4;
2568 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
2569 && sc->tulip_rombuf[2] == 0)
2570 return -4;
2571 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2572 sc->tulip_features |= TULIP_HAVE_OKROM;
2573 goto check_oui;
2574 } else {
2575 /*
2576 * A number of makers of multiport boards (ZNYX and Cogent)
2577 * only put on one address ROM on their 21040 boards. So
2578 * if the ROM is all zeros (or all 0xFFs), look at the
2579 * previous configured boards (as long as they are on the same
2580 * PCI bus and the bus number is non-zero) until we find the
2581 * master board with address ROM. We then use its address ROM
2582 * as the base for this board. (we add our relative board
2583 * to the last byte of its address).
2584 */
2585 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2586 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF)
2587 break;
2588 }
2589 if (idx == sizeof(sc->tulip_rombuf)) {
2590 int root_unit;
2591 tulip_softc_t *root_sc = NULL;
2592 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2593 root_sc = tulips[root_unit];
2594 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
2595 break;
2596 root_sc = NULL;
2597 }
2598 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM)
2599 && root_sc->tulip_chipid == sc->tulip_chipid
2600 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2601 sc->tulip_features |= TULIP_HAVE_SLAVEDROM;
2602 sc->tulip_boardsw = root_sc->tulip_boardsw;
2603 strcpy(sc->tulip_boardid, root_sc->tulip_boardid);
2604 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) {
2605 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf,
2606 sizeof(sc->tulip_rombuf));
2607 if (!tulip_srom_decode(sc))
2608 return -5;
2609 } else {
2610 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
2611 sc->tulip_enaddr[5] += sc->tulip_unit - root_sc->tulip_unit;
2612 }
2613 /*
2614 * Now for a truly disgusting kludge: all 4 21040s on
2615 * the ZX314 share the same INTA line so the mapping
2616 * setup by the BIOS on the PCI bridge is worthless.
2617 * Rather than reprogramming the value in the config
2618 * register, we will handle this internally.
2619 */
2620 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) {
2621 sc->tulip_slaves = root_sc->tulip_slaves;
2622 root_sc->tulip_slaves = sc;
2623 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2624 }
2625 return 0;
2626 }
2627 }
2628 }
2629
2630 /*
2631 * This is the standard DEC address ROM test.
2632 */
2633
2634 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
2635 return -3;
2636
2637 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
2638 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
2639 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
2640 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
2641 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
2642 return -2;
2643
2644 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2645
2646 cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
2647 cksum *= 2;
2648 if (cksum > 65535) cksum -= 65535;
2649 cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
2650 if (cksum > 65535) cksum -= 65535;
2651 cksum *= 2;
2652 if (cksum > 65535) cksum -= 65535;
2653 cksum += *(u_int16_t *) &sc->tulip_enaddr[4];
2654 if (cksum >= 65535) cksum -= 65535;
2655
2656 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6];
2657
2658 if (cksum != rom_cksum)
2659 return -1;
2660
2661 check_oui:
2662 /*
2663 * Check for various boards based on OUI. Did I say braindead?
2664 */
2665 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) {
2666 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) {
2667 (*tulip_vendors[idx].vendor_identify_nic)(sc);
2668 break;
2669 }
2670 }
2671
2672 sc->tulip_features |= TULIP_HAVE_OKROM;
2673 return 0;
2674}
79fe23de 2675
984263bc 2676static void
79fe23de 2677tulip_ifmedia_add(tulip_softc_t * const sc)
984263bc
MD
2678{
2679 tulip_media_t media;
2680 int medias = 0;
2681
2682 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2683 if (sc->tulip_mediums[media] != NULL) {
2684 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media],
2685 0, 0);
2686 medias++;
2687 }
2688 }
2689 if (medias == 0) {
2690 sc->tulip_features |= TULIP_HAVE_NOMEDIA;
2691 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0);
2692 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE);
2693 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
2694 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0);
2695 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO);
2696 } else {
2697 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]);
2698 sc->tulip_flags |= TULIP_PRINTMEDIA;
2699 tulip_linkup(sc, sc->tulip_media);
2700 }
2701}
2702
2703static int
79fe23de 2704tulip_ifmedia_change(struct ifnet *ifp)
984263bc 2705{
79fe23de 2706 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
984263bc
MD
2707
2708 sc->tulip_flags |= TULIP_NEEDRESET;
2709 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
2710 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
2711 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) {
2712 tulip_media_t media;
2713 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2714 if (sc->tulip_mediums[media] != NULL
2715 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) {
2716 sc->tulip_flags |= TULIP_PRINTMEDIA;
2717 sc->tulip_flags &= ~TULIP_DIDNWAY;
2718 tulip_linkup(sc, media);
2719 return 0;
2720 }
2721 }
2722 }
2723 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
2724 tulip_reset(sc);
2725 tulip_init(sc);
2726 return 0;
2727}
79fe23de 2728
984263bc
MD
2729/*
2730 * Media status callback
2731 */
2732static void
79fe23de 2733tulip_ifmedia_status(struct ifnet *ifp, struct ifmediareq *req)
984263bc
MD
2734{
2735 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2736
2737 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN)
2738 return;
2739
2740 req->ifm_status = IFM_AVALID;
2741 if (sc->tulip_flags & TULIP_LINKUP)
2742 req->ifm_status |= IFM_ACTIVE;
2743
2744 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
2745}
79fe23de 2746
984263bc 2747static void
79fe23de 2748tulip_addr_filter(tulip_softc_t *sc)
984263bc
MD
2749{
2750 struct ifmultiaddr *ifma;
2751 u_char *addrp;
2752 int multicnt;
2753
2754 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI);
2755 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART;
2756 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
2757 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
2758#if defined(IFF_ALLMULTI)
2759 if (sc->tulip_if.if_flags & IFF_ALLMULTI)
2760 sc->tulip_flags |= TULIP_ALLMULTI ;
2761#endif
2762
2763 multicnt = 0;
2764 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
2765 ifma = ifma->ifma_link.le_next) {
2766
2767 if (ifma->ifma_addr->sa_family == AF_LINK)
2768 multicnt++;
2769 }
2770
2771 sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */
2772 if (multicnt > 14) {
79fe23de
JS
2773 uint32_t *sp = sc->tulip_setupdata;
2774 u_int hash;
984263bc
MD
2775 /*
2776 * Some early passes of the 21140 have broken implementations of
2777 * hash-perfect mode. When we get too many multicasts for perfect
2778 * filtering with these chips, we need to switch into hash-only
2779 * mode (this is better than all-multicast on network with lots
2780 * of multicast traffic).
2781 */
2782 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
2783 sc->tulip_flags |= TULIP_WANTHASHONLY;
2784 else
2785 sc->tulip_flags |= TULIP_WANTHASHPERFECT;
2786 /*
2787 * If we have more than 14 multicasts, we have
2788 * go into hash perfect mode (512 bit multicast
2789 * hash and one perfect hardware).
2790 */
2791 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
2792
2793 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
2794 ifma = ifma->ifma_link.le_next) {
2795
2796 if (ifma->ifma_addr->sa_family != AF_LINK)
2797 continue;
2798
2799 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
2800#if BYTE_ORDER == BIG_ENDIAN
2801 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2802#else
2803 sp[hash >> 4] |= 1 << (hash & 0xF);
2804#endif
2805 }
2806 /*
2807 * No reason to use a hash if we are going to be
2808 * receiving every multicast.
2809 */
2810 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
c401f0fd 2811 hash = tulip_mchash(sc->tulip_if.if_broadcastaddr);
984263bc
MD
2812#if BYTE_ORDER == BIG_ENDIAN
2813 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2814#else
2815 sp[hash >> 4] |= 1 << (hash & 0xF);
2816#endif
2817 if (sc->tulip_flags & TULIP_WANTHASHONLY) {
2818 hash = tulip_mchash(sc->tulip_enaddr);
2819#if BYTE_ORDER == BIG_ENDIAN
2820 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
2821#else
2822 sp[hash >> 4] |= 1 << (hash & 0xF);
2823#endif
2824 } else {
2825#if BYTE_ORDER == BIG_ENDIAN
2826 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
2827 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
2828 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
2829#else
2830 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0];
2831 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1];
2832 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2];
2833#endif
2834 }
2835 }
2836 }
2837 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
79fe23de 2838 uint32_t *sp = sc->tulip_setupdata;
984263bc
MD
2839 int idx = 0;
2840 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
2841 /*
2842 * Else can get perfect filtering for 16 addresses.
2843 */
2844 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
2845 ifma = ifma->ifma_link.le_next) {
2846 if (ifma->ifma_addr->sa_family != AF_LINK)
2847 continue;
2848 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
2849#if BYTE_ORDER == BIG_ENDIAN
2850 *sp++ = ((u_int16_t *) addrp)[0] << 16;
2851 *sp++ = ((u_int16_t *) addrp)[1] << 16;
2852 *sp++ = ((u_int16_t *) addrp)[2] << 16;
2853#else
2854 *sp++ = ((u_int16_t *) addrp)[0];
2855 *sp++ = ((u_int16_t *) addrp)[1];
2856 *sp++ = ((u_int16_t *) addrp)[2];
2857#endif
2858 idx++;
2859 }
2860 /*
2861 * Add the broadcast address.
2862 */
2863 idx++;
2864#if BYTE_ORDER == BIG_ENDIAN
2865 *sp++ = 0xFFFF << 16;
2866 *sp++ = 0xFFFF << 16;
2867 *sp++ = 0xFFFF << 16;
2868#else
2869 *sp++ = 0xFFFF;
2870 *sp++ = 0xFFFF;
2871 *sp++ = 0xFFFF;
2872#endif
2873 }
2874 /*
2875 * Pad the rest with our hardware address
2876 */
2877 for (; idx < 16; idx++) {
2878#if BYTE_ORDER == BIG_ENDIAN
2879 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
2880 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
2881 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
2882#else
2883 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0];
2884 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1];
2885 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2];
2886#endif
2887 }
2888 }
2889#if defined(IFF_ALLMULTI)
2890 if (sc->tulip_flags & TULIP_ALLMULTI)
2891 sc->tulip_if.if_flags |= IFF_ALLMULTI;
2892#endif
2893}
2894\f
2895static void
79fe23de 2896tulip_reset(tulip_softc_t *sc)
984263bc
MD
2897{
2898 tulip_ringinfo_t *ri;
2899 tulip_desc_t *di;
79fe23de 2900 uint32_t inreset = (sc->tulip_flags & TULIP_INRESET);
984263bc
MD
2901
2902 /*
2903 * Brilliant. Simply brilliant. When switching modes/speeds
2904 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
2905 * bits in CSR6 and then do a software reset to get the 21140
2906 * to properly reset its internal pathways to the right places.
2907 * Grrrr.
2908 */
2909 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
2910 && sc->tulip_boardsw->bd_media_preset != NULL)
2911 (*sc->tulip_boardsw->bd_media_preset)(sc);
2912
2913 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
2914 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
2915 33MHz that comes to two microseconds but wait a
2916 bit longer anyways) */
2917
2918 if (!inreset) {
2919 sc->tulip_flags |= TULIP_INRESET;
2920 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
2921 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
2922 sc->tulip_if.if_start = tulip_ifstart;
2923 }
2924
984263bc 2925 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
984263bc 2926 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
984263bc
MD
2927 TULIP_CSR_WRITE(sc, csr_busmode,
2928 (1 << (3 /*pci_max_burst_len*/ + 8))
2929 |TULIP_BUSMODE_CACHE_ALIGN8
2930 |TULIP_BUSMODE_READMULTIPLE
2931 |(BYTE_ORDER != LITTLE_ENDIAN ?
2932 TULIP_BUSMODE_DESC_BIGENDIAN : 0));
2933
2934 sc->tulip_txtimer = 0;
2935 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
2936 /*
2937 * Free all the mbufs that were on the transmit ring.
2938 */
9bf3a1b2 2939 IF_DRAIN(&sc->tulip_txq);
984263bc
MD
2940
2941 ri = &sc->tulip_txinfo;
2942 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
2943 ri->ri_free = ri->ri_max;
2944 for (di = ri->ri_first; di < ri->ri_last; di++)
2945 di->d_status = 0;
984263bc
MD
2946
2947 /*
2948 * We need to collect all the mbufs were on the
2949 * receive ring before we reinit it either to put
2950 * them back on or to know if we have to allocate
2951 * more.
2952 */
2953 ri = &sc->tulip_rxinfo;
2954 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
2955 ri->ri_free = ri->ri_max;
2956 for (di = ri->ri_first; di < ri->ri_last; di++) {
2957 di->d_status = 0;
2958 di->d_length1 = 0; di->d_addr1 = 0;
2959 di->d_length2 = 0; di->d_addr2 = 0;
2960 }
9bf3a1b2 2961 IF_DRAIN(&sc->tulip_rxq);
984263bc
MD
2962
2963 /*
2964 * If tulip_reset is being called recurisvely, exit quickly knowing
2965 * that when the outer tulip_reset returns all the right stuff will
2966 * have happened.
2967 */
2968 if (inreset)
2969 return;
2970
2971 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
2972 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
2973 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
2974 |TULIP_STS_RXSTOPPED;
2975
2976 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
2977 (*sc->tulip_boardsw->bd_media_select)(sc);
984263bc
MD
2978 tulip_media_print(sc);
2979 if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
2980 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
2981
2982 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
2983 |TULIP_RXACT);
2984 tulip_addr_filter(sc);
2985}
79fe23de 2986
984263bc 2987static void
79fe23de 2988tulip_init(tulip_softc_t * const sc)
984263bc
MD
2989{
2990 if (sc->tulip_if.if_flags & IFF_UP) {
2991 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) {
2992 /* initialize the media */
2993 tulip_reset(sc);
2994 }
2995 sc->tulip_if.if_flags |= IFF_RUNNING;
2996 if (sc->tulip_if.if_flags & IFF_PROMISC) {
2997 sc->tulip_flags |= TULIP_PROMISC;
2998 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
2999 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3000 } else {
3001 sc->tulip_flags &= ~TULIP_PROMISC;
3002 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
3003 if (sc->tulip_flags & TULIP_ALLMULTI) {
3004 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
3005 } else {
3006 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
3007 }
3008 }
3009 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
3010 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
3011 tulip_rx_intr(sc);
3012 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3013 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3014 } else {
3015 sc->tulip_if.if_flags |= IFF_OACTIVE;
3016 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3017 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3018 }
3019 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3020 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3021 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3022 tulip_txput_setup(sc);
3023 } else {
3024 sc->tulip_if.if_flags &= ~IFF_RUNNING;
3025 tulip_reset(sc);
3026 }
3027}
79fe23de 3028
984263bc 3029static void
79fe23de 3030tulip_rx_intr(tulip_softc_t *sc)
984263bc 3031{
79fe23de
JS
3032 tulip_ringinfo_t *ri = &sc->tulip_rxinfo;
3033 struct ifnet *ifp = &sc->tulip_if;
984263bc 3034 int fillok = 1;
984263bc
MD
3035
3036 for (;;) {
984263bc
MD
3037 struct ether_header eh;
3038 tulip_desc_t *eop = ri->ri_nextin;
3039 int total_len = 0, last_offset = 0;
3040 struct mbuf *ms = NULL, *me = NULL;
3041 int accept = 0;
984263bc
MD
3042
3043 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
3044 goto queue_mbuf;
3045
984263bc
MD
3046 /*
3047 * If the TULIP has no descriptors, there can't be any receive
3048 * descriptors to process.
3049 */
3050 if (eop == ri->ri_nextout)
3051 break;
3052
3053 /*
3054 * 90% of the packets will fit in one descriptor. So we optimize
3055 * for that case.
3056 */
3057 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3058 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
3059 IF_DEQUEUE(&sc->tulip_rxq, ms);
3060 me = ms;
3061 } else {
3062 /*
3063 * If still owned by the TULIP, don't touch it.
3064 */
3065 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
3066 break;
3067
3068 /*
3069 * It is possible (though improbable unless the BIG_PACKET support
3070 * is enabled or MCLBYTES < 1518) for a received packet to cross
3071 * more than one receive descriptor.
3072 */
3073 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) {
3074 if (++eop == ri->ri_last)
3075 eop = ri->ri_first;
3076 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3077 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
984263bc
MD
3078 return;
3079 }
3080 total_len++;
3081 }
3082
3083 /*
3084 * Dequeue the first buffer for the start of the packet. Hopefully
3085 * this will be the only one we need to dequeue. However, if the
3086 * packet consumed multiple descriptors, then we need to dequeue
3087 * those buffers and chain to the starting mbuf. All buffers but
3088 * the last buffer have the same length so we can set that now.
3089 * (we add to last_offset instead of multiplying since we normally
3090 * won't go into the loop and thereby saving a ourselves from
3091 * doing a multiplication by 0 in the normal case).
3092 */
3093 IF_DEQUEUE(&sc->tulip_rxq, ms);
3094 for (me = ms; total_len > 0; total_len--) {
984263bc
MD
3095 me->m_len = TULIP_RX_BUFLEN;
3096 last_offset += TULIP_RX_BUFLEN;
3097 IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
3098 me = me->m_next;
3099 }
3100 }
3101
3102 /*
3103 * Now get the size of received packet (minus the CRC).
3104 */
3105 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
3106 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
3107 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0
3108#ifdef BIG_PACKET
3109 || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) &&
3110 (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT|
3111 TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC|
3112 TULIP_DSTS_RxOVERFLOW)) == 0)
3113#endif
3114 )) {
3115 me->m_len = total_len - last_offset;
3116
984263bc 3117 eh = *mtod(ms, struct ether_header *);
984263bc
MD
3118 sc->tulip_flags |= TULIP_RXACT;
3119 accept = 1;
3120 } else {
3121 ifp->if_ierrors++;
3122 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3123 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3124 } else {
984263bc
MD
3125 if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
3126 sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
984263bc
MD
3127 }
3128 if (eop->d_status & TULIP_DSTS_RxBADCRC) {
3129 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
3130 sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
984263bc
MD
3131 } else {
3132 sc->tulip_dot3stats.dot3StatsFCSErrors++;
984263bc
MD
3133 }
3134 }
984263bc 3135 }
984263bc 3136 }
984263bc
MD
3137 ifp->if_ipackets++;
3138 if (++eop == ri->ri_last)
3139 eop = ri->ri_first;
3140 ri->ri_nextin = eop;
3141 queue_mbuf:
3142 /*
3143 * Either we are priming the TULIP with mbufs (m == NULL)
3144 * or we are about to accept an mbuf for the upper layers
3145 * so we need to allocate an mbuf to replace it. If we
3146 * can't replace it, send up it anyways. This may cause
3147 * us to drop packets in the future but that's better than
3148 * being caught in livelock.
3149 *
3150 * Note that if this packet crossed multiple descriptors
3151 * we don't even try to reallocate all the mbufs here.
3152 * Instead we rely on the test of the beginning of
3153 * the loop to refill for the extra consumed mbufs.
3154 */
3155 if (accept || ms == NULL) {
3156 struct mbuf *m0;
74f1caca 3157 MGETHDR(m0, MB_DONTWAIT, MT_DATA);
984263bc
MD
3158 if (m0 != NULL) {
3159#if defined(TULIP_COPY_RXDATA)
3160 if (!accept || total_len >= (MHLEN - 2)) {
3161#endif
74f1caca 3162 MCLGET(m0, MB_DONTWAIT);
984263bc
MD
3163 if ((m0->m_flags & M_EXT) == 0) {
3164 m_freem(m0);
3165 m0 = NULL;
3166 }
3167#if defined(TULIP_COPY_RXDATA)
3168 }
3169#endif
3170 }
3171 if (accept
3172#if defined(TULIP_COPY_RXDATA)
3173 && m0 != NULL
3174#endif
3175 ) {
3176#if !defined(TULIP_COPY_RXDATA)
3177 ms->m_pkthdr.len = total_len;
3178 ms->m_pkthdr.rcvif = ifp;
3179 m_adj(ms, sizeof(struct ether_header));
3180 ether_input(ifp, &eh, ms);
3181#else
3182#ifdef BIG_PACKET
3183#error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
3184#endif
3185 m0->m_data += 2; /* align data after header */
3186 m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
3187 m0->m_len = m0->m_pkthdr.len = total_len;
3188 m0->m_pkthdr.rcvif = ifp;
3189 m_adj(m0, sizeof(struct ether_header));
3190 ether_input(ifp, &eh, m0);
3191 m0 = ms;
3192#endif /* ! TULIP_COPY_RXDATA */
3193 }
3194 ms = m0;
3195 }
3196 if (ms == NULL) {
3197 /*
3198 * Couldn't allocate a new buffer. Don't bother
3199 * trying to replenish the receive queue.
3200 */
3201 fillok = 0;
3202 sc->tulip_flags |= TULIP_RXBUFSLOW;
984263bc
MD
3203 continue;
3204 }
3205 /*
3206 * Now give the buffer(s) to the TULIP and save in our
3207 * receive queue.
3208 */
3209 do {
3210 tulip_desc_t * const nextout = ri->ri_nextout;
984263bc
MD
3211 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
3212 nextout->d_length1 = TULIP_RX_BUFLEN;
984263bc
MD
3213 nextout->d_status = TULIP_DSTS_OWNER;
3214 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
3215 if (++ri->ri_nextout == ri->ri_last)
3216 ri->ri_nextout = ri->ri_first;
3217 me = ms->m_next;
3218 ms->m_next = NULL;
3219 IF_ENQUEUE(&sc->tulip_rxq, ms);
3220 } while ((ms = me) != NULL);
3221
3222 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
3223 sc->tulip_flags &= ~TULIP_RXBUFSLOW;
984263bc 3224 }
984263bc 3225}
79fe23de 3226
984263bc 3227static int
79fe23de 3228tulip_tx_intr(tulip_softc_t *sc)
984263bc 3229{
79fe23de 3230 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
984263bc
MD
3231 struct mbuf *m;
3232 int xmits = 0;
3233 int descs = 0;
3234
3235 while (ri->ri_free < ri->ri_max) {
79fe23de 3236 uint32_t d_flag;
984263bc
MD
3237
3238 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
3239 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
3240 break;
3241
3242 ri->ri_free++;
3243 descs++;
3244 d_flag = ri->ri_nextin->d_flag;
3245 if (d_flag & TULIP_DFLAG_TxLASTSEG) {
3246 if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
3247 /*
3248 * We've just finished processing a setup packet.
3249 * Mark that we finished it. If there's not
3250 * another pending, startup the TULIP receiver.
3251 * Make sure we ack the RXSTOPPED so we won't get
3252 * an abormal interrupt indication.
3253 */
3254 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap);
3255 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
3256 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT)
3257 sc->tulip_flags |= TULIP_HASHONLY;
3258 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
3259 tulip_rx_intr(sc);
3260 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3261 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3262 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3263 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3264 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3265 }
3266 } else {
79fe23de 3267 const uint32_t d_status = ri->ri_nextin->d_status;
984263bc
MD
3268 IF_DEQUEUE(&sc->tulip_txq, m);
3269 if (m != NULL) {
984263bc 3270 m_freem(m);
984263bc
MD
3271 }
3272 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3273 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
3274 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
984263bc
MD
3275 event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
3276 }
3277 (*sc->tulip_boardsw->bd_media_poll)(sc, event);
3278 /*
3279 * Escape from the loop before media poll has reset the TULIP!
3280 */
3281 break;
3282 } else {
3283 xmits++;
3284 if (d_status & TULIP_DSTS_ERRSUM) {
3285 sc->tulip_if.if_oerrors++;
3286 if (d_status & TULIP_DSTS_TxEXCCOLL)
3287 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
3288 if (d_status & TULIP_DSTS_TxLATECOLL)
3289 sc->tulip_dot3stats.dot3StatsLateCollisions++;
3290 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
3291 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
3292 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
3293 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
3294 if (d_status & TULIP_DSTS_TxUNDERFLOW)
3295 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
3296 if (d_status & TULIP_DSTS_TxBABBLE)
3297 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
3298 } else {
3299 u_int32_t collisions =
3300 (d_status & TULIP_DSTS_TxCOLLMASK)
3301 >> TULIP_DSTS_V_TxCOLLCNT;
3302 sc->tulip_if.if_collisions += collisions;
3303 if (collisions == 1)
3304 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
3305 else if (collisions > 1)
3306 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
3307 else if (d_status & TULIP_DSTS_TxDEFERRED)
3308 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
3309 /*
3310 * SQE is only valid for 10baseT/BNC/AUI when not
3311 * running in full-duplex. In order to speed up the
3312 * test, the corresponding bit in tulip_flags needs to
3313 * set as well to get us to count SQE Test Errors.
3314 */
3315 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
3316 sc->tulip_dot3stats.dot3StatsSQETestErrors++;
3317 }
3318 }
3319 }
3320 }
3321
3322 if (++ri->ri_nextin == ri->ri_last)
3323 ri->ri_nextin = ri->ri_first;
3324
3325 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3326 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
3327 }
3328 /*
3329 * If nothing left to transmit, disable the timer.
3330 * Else if progress, reset the timer back to 2 ticks.
3331 */
3332 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
3333 sc->tulip_txtimer = 0;
3334 else if (xmits > 0)
3335 sc->tulip_txtimer = TULIP_TXTIMER;
3336 sc->tulip_if.if_opackets += xmits;
984263bc
MD
3337 return descs;
3338}
79fe23de 3339
984263bc 3340static void
79fe23de 3341tulip_print_abnormal_interrupt(tulip_softc_t *sc, uint32_t csr)
984263bc
MD
3342{
3343 const char * const *msgp = tulip_status_bits;
3344 const char *sep;
79fe23de 3345 uint32_t mask;
984263bc
MD
3346 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
3347
3348 csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1;
3349 printf("%s%d: abnormal interrupt:", sc->tulip_name, sc->tulip_unit);
3350 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
3351 if ((csr & mask) && *msgp != NULL) {
3352 printf("%s%s", sep, *msgp);
3353 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
3354 sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
3355 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
3356 printf(" (switching to store-and-forward mode)");
3357 } else {
3358 printf(" (raising TX threshold to %s)",
3359 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
3360 }
3361 }
3362 sep = ", ";
3363 }
3364 }
3365 printf("\n");
3366}
3367
3368static void
79fe23de 3369tulip_intr_handler(tulip_softc_t *sc, int *progress_p)
984263bc 3370{
79fe23de 3371 uint32_t csr;
984263bc
MD
3372
3373 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3374 *progress_p = 1;
3375 TULIP_CSR_WRITE(sc, csr_status, csr);
3376
3377 if (csr & TULIP_STS_SYSERROR) {
3378 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
3379 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3380 sc->tulip_flags |= TULIP_SYSTEMERROR;
3381 } else {
3382 printf("%s%d: system error: %s\n",
3383 sc->tulip_name, sc->tulip_unit,
3384 tulip_system_errors[sc->tulip_last_system_error]);
3385 }
3386 sc->tulip_flags |= TULIP_NEEDRESET;
3387 sc->tulip_system_errors++;
3388 break;
3389 }
3390 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
984263bc
MD
3391 if (sc->tulip_boardsw->bd_media_poll != NULL) {
3392 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
3393 ? TULIP_MEDIAPOLL_LINKFAIL
3394 : TULIP_MEDIAPOLL_LINKPASS);
3395 csr &= ~TULIP_STS_ABNRMLINTR;
3396 }
3397 tulip_media_print(sc);
3398 }
3399 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
3400 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
3401 if (csr & TULIP_STS_RXNOBUF)
3402 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
3403 /*
3404 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3405 * on receive overflows.
3406 */
3407 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
3408 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3409 /*
3410 * Stop the receiver process and spin until it's stopped.
3411 * Tell rx_intr to drop the packets it dequeues.
3412 */
3413 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
3414 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
3415 ;
3416 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3417 sc->tulip_flags |= TULIP_RXIGNORE;
3418 }
3419 tulip_rx_intr(sc);
3420 if (sc->tulip_flags & TULIP_RXIGNORE) {
3421 /*
3422 * Restart the receiver.
3423 */
3424 sc->tulip_flags &= ~TULIP_RXIGNORE;
3425 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3426 }
3427 }
3428 if (csr & TULIP_STS_ABNRMLINTR) {
3429 u_int32_t tmp = csr & sc->tulip_intrmask
3430 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
3431 if (csr & TULIP_STS_TXUNDERFLOW) {
3432 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
3433 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
3434 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3435 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
3436 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
3437 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3438 }
3439 }
3440 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3441 sc->tulip_statusbits |= tmp;
3442 } else {
3443 tulip_print_abnormal_interrupt(sc, tmp);
3444 sc->tulip_flags |= TULIP_NOMESSAGES;
3445 }
3446 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3447 }
3448 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
3449 tulip_tx_intr(sc);
3450 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3451 tulip_ifstart(&sc->tulip_if);
3452 }
3453 }
3454 if (sc->tulip_flags & TULIP_NEEDRESET) {
3455 tulip_reset(sc);
3456 tulip_init(sc);
3457 }
984263bc
MD
3458}
3459
984263bc 3460static void
79fe23de 3461tulip_intr_shared(void *arg)
984263bc 3462{
79fe23de 3463 tulip_softc_t *sc = arg;
984263bc
MD
3464 int progress = 0;
3465
3466 for (; sc != NULL; sc = sc->tulip_slaves) {
984263bc 3467 tulip_intr_handler(sc, &progress);
984263bc 3468 }
984263bc
MD
3469}
3470
3471static void
79fe23de 3472tulip_intr_normal(void *arg)
984263bc 3473{
79fe23de 3474 tulip_softc_t *sc = (tulip_softc_t *)arg;
984263bc
MD
3475 int progress = 0;
3476
984263bc 3477 tulip_intr_handler(sc, &progress);
984263bc 3478}
79fe23de 3479
984263bc 3480static struct mbuf *
79fe23de 3481tulip_mbuf_compress(struct mbuf *m)
984263bc
MD
3482{
3483 struct mbuf *m0;
3484#if MCLBYTES >= ETHERMTU + 18 && !defined(BIG_PACKET)
74f1caca 3485 MGETHDR(m0, MB_DONTWAIT, MT_DATA);
984263bc
MD
3486 if (m0 != NULL) {
3487 if (m->m_pkthdr.len > MHLEN) {
74f1caca 3488 MCLGET(m0, MB_DONTWAIT);
984263bc
MD
3489 if ((m0->m_flags & M_EXT) == 0) {
3490 m_freem(m);
3491 m_freem(m0);
3492 return NULL;
3493 }
3494 }
3495 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t));
3496 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len;
3497 }
3498#else
3499 int mlen = MHLEN;
3500 int len = m->m_pkthdr.len;
3501 struct mbuf **mp = &m0;
3502
3503 while (len > 0) {
3504 if (mlen == MHLEN) {
74f1caca 3505 MGETHDR(*mp, MB_DONTWAIT, MT_DATA);
984263bc 3506 } else {
74f1caca 3507 MGET(*mp, MB_DONTWAIT, MT_DATA);
984263bc
MD
3508 }
3509 if (*mp == NULL) {
3510 m_freem(m0);
3511 m0 = NULL;
3512 break;
3513 }
3514 if (len > MLEN) {
74f1caca 3515 MCLGET(*mp, MB_DONTWAIT);
984263bc
MD
3516 if (((*mp)->m_flags & M_EXT) == 0) {
3517 m_freem(m0);
3518 m0 = NULL;
3519 break;
3520 }
3521 (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES;
3522 } else {
3523 (*mp)->m_len = len <= mlen ? len : mlen;
3524 }
3525 m_copydata(m, m->m_pkthdr.len - len,
3526 (*mp)->m_len, mtod((*mp), caddr_t));
3527 len -= (*mp)->m_len;
3528 mp = &(*mp)->m_next;
3529 mlen = MLEN;
3530 }
3531#endif
3532 m_freem(m);
3533 return m0;
3534}
79fe23de 3535
984263bc 3536static struct mbuf *
79fe23de 3537tulip_txput(tulip_softc_t *sc, struct mbuf *m)
984263bc 3538{
79fe23de 3539 tulip_ringinfo_t *ri = &sc->tulip_txinfo;
984263bc
MD
3540 tulip_desc_t *eop, *nextout;
3541 int segcnt, free;
79fe23de 3542 uint32_t d_status;
984263bc 3543 struct mbuf *m0;
984263bc 3544
984263bc
MD
3545 /*
3546 * Now we try to fill in our transmit descriptors. This is
3547 * a bit reminiscent of going on the Ark two by two
3548 * since each descriptor for the TULIP can describe
3549 * two buffers. So we advance through packet filling
3550 * each of the two entries at a time to to fill each
3551 * descriptor. Clear the first and last segment bits
3552 * in each descriptor (actually just clear everything
3553 * but the end-of-ring or chain bits) to make sure
3554 * we don't get messed up by previously sent packets.
3555 *
3556 * We may fail to put the entire packet on the ring if
3557 * there is either not enough ring entries free or if the
3558 * packet has more than MAX_TXSEG segments. In the former
3559 * case we will just wait for the ring to empty. In the
3560 * latter case we have to recopy.
3561 */
984263bc
MD
3562 again:
3563 m0 = m;
984263bc
MD
3564 d_status = 0;
3565 eop = nextout = ri->ri_nextout;
3566 segcnt = 0;
3567 free = ri->ri_free;
3568
984263bc
MD
3569 do {
3570 int len = m0->m_len;
3571 caddr_t addr = mtod(m0, caddr_t);
3572 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1));
3573
3574 while (len > 0) {
3575 unsigned slen = min(len, clsize);
3576#ifdef BIG_PACKET
3577 int partial = 0;
3578 if (slen >= 2048)
3579 slen = 2040, partial = 1;
3580#endif
3581 segcnt++;
3582 if (segcnt > TULIP_MAX_TXSEG) {
3583 /*
3584 * The packet exceeds the number of transmit buffer
3585 * entries that we can use for one packet, so we have
3586 * recopy it into one mbuf and then try again.
3587 */
3588 m = tulip_mbuf_compress(m);
3589 if (m == NULL)
3590 goto finish;
3591 goto again;
3592 }
3593 if (segcnt & 1) {
3594 if (--free == 0) {
3595 /*
3596 * See if there's any unclaimed space in the
3597 * transmit ring.
3598 */
3599 if ((free += tulip_tx_intr(sc)) == 0) {
3600 /*
3601 * There's no more room but since nothing
3602 * has been committed at this point, just
3603 * show output is active, put back the
3604 * mbuf and return.
3605 */
3606 sc->tulip_flags |= TULIP_WANTTXSTART;
984263bc
MD
3607 goto finish;
3608 }
3609 }
3610 eop = nextout;
3611 if (++nextout == ri->ri_last)
3612 nextout = ri->ri_first;
3613 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
3614 eop->d_status = d_status;
3615 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr);
3616 eop->d_length1 = slen;
3617 } else {
3618 /*
3619 * Fill in second half of descriptor
3620 */
3621 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr);
3622 eop->d_length2 = slen;
3623 }
3624 d_status = TULIP_DSTS_OWNER;
3625 len -= slen;
3626 addr += slen;
3627#ifdef BIG_PACKET
3628 if (partial)
3629 continue;
3630#endif
3631 clsize = PAGE_SIZE;
3632 }
3633 } while ((m0 = m0->m_next) != NULL);
984263bc 3634
7600679e 3635 BPF_MTAP(&sc->tulip_if, m);
984263bc
MD
3636
3637 /*
3638 * The descriptors have been filled in. Now get ready
3639 * to transmit.
3640 */
3641 IF_ENQUEUE(&sc->tulip_txq, m);
3642 m = NULL;
3643
3644 /*
3645 * Make sure the next descriptor after this packet is owned
3646 * by us since it may have been set up above if we ran out
3647 * of room in the ring.
3648 */
3649 nextout->d_status = 0;
3650 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
3651
984263bc
MD
3652 /*
3653 * If we only used the first segment of the last descriptor,
3654 * make sure the second segment will not be used.
3655 */
3656 if (segcnt & 1) {
3657 eop->d_addr2 = 0;
3658 eop->d_length2 = 0;
3659 }
984263bc
MD
3660
3661 /*
3662 * Mark the last and first segments, indicate we want a transmit
3663 * complete interrupt, and tell it to transmit!
3664 */
3665 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
3666
3667 /*
3668 * Note that ri->ri_nextout is still the start of the packet
3669 * and until we set the OWNER bit, we can still back out of
3670 * everything we have done.
3671 */
3672 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
984263bc
MD
3673 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
3674 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
3675
3676 /*
3677 * This advances the ring for us.
3678 */
3679 ri->ri_nextout = nextout;
3680 ri->ri_free = free;