tulip.c revision 1.146 1 /* $NetBSD: tulip.c,v 1.146 2006/08/30 23:31:08 rumble Exp $ */
2
3 /*-
4 * Copyright (c) 1998, 1999, 2000, 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center; and by Charles M. Hannum.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * Device driver for the Digital Semiconductor ``Tulip'' (21x4x)
42 * Ethernet controller family, and a variety of clone chips.
43 */
44
45 #include <sys/cdefs.h>
46 __KERNEL_RCSID(0, "$NetBSD: tulip.c,v 1.146 2006/08/30 23:31:08 rumble Exp $");
47
48 #include "bpfilter.h"
49
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/callout.h>
53 #include <sys/mbuf.h>
54 #include <sys/malloc.h>
55 #include <sys/kernel.h>
56 #include <sys/socket.h>
57 #include <sys/ioctl.h>
58 #include <sys/errno.h>
59 #include <sys/device.h>
60
61 #include <machine/endian.h>
62
63 #include <uvm/uvm_extern.h>
64
65 #include <net/if.h>
66 #include <net/if_dl.h>
67 #include <net/if_media.h>
68 #include <net/if_ether.h>
69
70 #if NBPFILTER > 0
71 #include <net/bpf.h>
72 #endif
73
74 #include <machine/bus.h>
75 #include <machine/intr.h>
76
77 #include <dev/mii/mii.h>
78 #include <dev/mii/miivar.h>
79 #include <dev/mii/mii_bitbang.h>
80
81 #include <dev/ic/tulipreg.h>
82 #include <dev/ic/tulipvar.h>
83
84 const char * const tlp_chip_names[] = TULIP_CHIP_NAMES;
85
86 static const struct tulip_txthresh_tab tlp_10_txthresh_tab[] =
87 TLP_TXTHRESH_TAB_10;
88
89 static const struct tulip_txthresh_tab tlp_10_100_txthresh_tab[] =
90 TLP_TXTHRESH_TAB_10_100;
91
92 static const struct tulip_txthresh_tab tlp_winb_txthresh_tab[] =
93 TLP_TXTHRESH_TAB_WINB;
94
95 static const struct tulip_txthresh_tab tlp_dm9102_txthresh_tab[] =
96 TLP_TXTHRESH_TAB_DM9102;
97
98 static void tlp_start(struct ifnet *);
99 static void tlp_watchdog(struct ifnet *);
100 static int tlp_ioctl(struct ifnet *, u_long, caddr_t);
101 static int tlp_init(struct ifnet *);
102 static void tlp_stop(struct ifnet *, int);
103
104 static void tlp_shutdown(void *);
105
106 static void tlp_rxdrain(struct tulip_softc *);
107 static int tlp_add_rxbuf(struct tulip_softc *, int);
108 static void tlp_srom_idle(struct tulip_softc *);
109 static int tlp_srom_size(struct tulip_softc *);
110
111 static int tlp_enable(struct tulip_softc *);
112 static void tlp_disable(struct tulip_softc *);
113 static void tlp_power(int, void *);
114
115 static void tlp_filter_setup(struct tulip_softc *);
116 static void tlp_winb_filter_setup(struct tulip_softc *);
117 static void tlp_al981_filter_setup(struct tulip_softc *);
118 static void tlp_asix_filter_setup(struct tulip_softc *);
119
120 static void tlp_rxintr(struct tulip_softc *);
121 static void tlp_txintr(struct tulip_softc *);
122
123 static void tlp_mii_tick(void *);
124 static void tlp_mii_statchg(struct device *);
125 static void tlp_winb_mii_statchg(struct device *);
126 static void tlp_dm9102_mii_statchg(struct device *);
127
128 static void tlp_mii_getmedia(struct tulip_softc *, struct ifmediareq *);
129 static int tlp_mii_setmedia(struct tulip_softc *);
130
131 static int tlp_bitbang_mii_readreg(struct device *, int, int);
132 static void tlp_bitbang_mii_writereg(struct device *, int, int, int);
133
134 static int tlp_pnic_mii_readreg(struct device *, int, int);
135 static void tlp_pnic_mii_writereg(struct device *, int, int, int);
136
137 static int tlp_al981_mii_readreg(struct device *, int, int);
138 static void tlp_al981_mii_writereg(struct device *, int, int, int);
139
140 static void tlp_2114x_preinit(struct tulip_softc *);
141 static void tlp_2114x_mii_preinit(struct tulip_softc *);
142 static void tlp_pnic_preinit(struct tulip_softc *);
143 static void tlp_dm9102_preinit(struct tulip_softc *);
144 static void tlp_asix_preinit(struct tulip_softc *);
145
146 static void tlp_21140_reset(struct tulip_softc *);
147 static void tlp_21142_reset(struct tulip_softc *);
148 static void tlp_pmac_reset(struct tulip_softc *);
149 #if 0
150 static void tlp_dm9102_reset(struct tulip_softc *);
151 #endif
152
153 static void tlp_2114x_nway_tick(void *);
154
155 #define tlp_mchash(addr, sz) \
156 (ether_crc32_le((addr), ETHER_ADDR_LEN) & ((sz) - 1))
157
158 /*
159 * MII bit-bang glue.
160 */
161 static u_int32_t tlp_sio_mii_bitbang_read(struct device *);
162 static void tlp_sio_mii_bitbang_write(struct device *, u_int32_t);
163
164 static const struct mii_bitbang_ops tlp_sio_mii_bitbang_ops = {
165 tlp_sio_mii_bitbang_read,
166 tlp_sio_mii_bitbang_write,
167 {
168 MIIROM_MDO, /* MII_BIT_MDO */
169 MIIROM_MDI, /* MII_BIT_MDI */
170 MIIROM_MDC, /* MII_BIT_MDC */
171 0, /* MII_BIT_DIR_HOST_PHY */
172 MIIROM_MIIDIR, /* MII_BIT_DIR_PHY_HOST */
173 }
174 };
175
176 #ifdef TLP_DEBUG
177 #define DPRINTF(sc, x) if ((sc)->sc_ethercom.ec_if.if_flags & IFF_DEBUG) \
178 printf x
179 #else
180 #define DPRINTF(sc, x) /* nothing */
181 #endif
182
183 #ifdef TLP_STATS
184 static void tlp_print_stats(struct tulip_softc *);
185 #endif
186
187 /*
188 * Can be used to debug the SROM-related things, including contents.
189 * Initialized so that it's patchable.
190 */
191 int tlp_srom_debug = 0;
192
193 /*
194 * tlp_attach:
195 *
196 * Attach a Tulip interface to the system.
197 */
198 void
199 tlp_attach(struct tulip_softc *sc, const u_int8_t *enaddr)
200 {
201 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
202 int i, error;
203
204 callout_init(&sc->sc_nway_callout);
205 callout_init(&sc->sc_tick_callout);
206
207 /*
208 * NOTE: WE EXPECT THE FRONT-END TO INITIALIZE sc_regshift!
209 */
210
211 /*
212 * Setup the transmit threshold table.
213 */
214 switch (sc->sc_chip) {
215 case TULIP_CHIP_DE425:
216 case TULIP_CHIP_21040:
217 case TULIP_CHIP_21041:
218 sc->sc_txth = tlp_10_txthresh_tab;
219 break;
220
221 case TULIP_CHIP_DM9102:
222 case TULIP_CHIP_DM9102A:
223 sc->sc_txth = tlp_dm9102_txthresh_tab;
224 break;
225
226 default:
227 sc->sc_txth = tlp_10_100_txthresh_tab;
228 break;
229 }
230
231 /*
232 * Setup the filter setup function.
233 */
234 switch (sc->sc_chip) {
235 case TULIP_CHIP_WB89C840F:
236 sc->sc_filter_setup = tlp_winb_filter_setup;
237 break;
238
239 case TULIP_CHIP_AL981:
240 case TULIP_CHIP_AN983:
241 case TULIP_CHIP_AN985:
242 sc->sc_filter_setup = tlp_al981_filter_setup;
243 break;
244
245 case TULIP_CHIP_AX88140:
246 case TULIP_CHIP_AX88141:
247 sc->sc_filter_setup = tlp_asix_filter_setup;
248 break;
249
250 default:
251 sc->sc_filter_setup = tlp_filter_setup;
252 break;
253 }
254
255 /*
256 * Set up the media status change function.
257 */
258 switch (sc->sc_chip) {
259 case TULIP_CHIP_WB89C840F:
260 sc->sc_statchg = tlp_winb_mii_statchg;
261 break;
262
263 case TULIP_CHIP_DM9102:
264 case TULIP_CHIP_DM9102A:
265 sc->sc_statchg = tlp_dm9102_mii_statchg;
266 break;
267
268 default:
269 /*
270 * We may override this if we have special media
271 * handling requirements (e.g. flipping GPIO pins).
272 *
273 * The pure-MII statchg function covers the basics.
274 */
275 sc->sc_statchg = tlp_mii_statchg;
276 break;
277 }
278
279 /*
280 * Default to no FS|LS in setup packet descriptors. They're
281 * supposed to be zero according to the 21040 and 21143
282 * manuals, and some chips fall over badly if they're
283 * included. Yet, other chips seem to require them. Sigh.
284 */
285 switch (sc->sc_chip) {
286 case TULIP_CHIP_X3201_3:
287 sc->sc_setup_fsls = TDCTL_Tx_FS|TDCTL_Tx_LS;
288 break;
289
290 default:
291 sc->sc_setup_fsls = 0;
292 }
293
294 /*
295 * Set up various chip-specific quirks.
296 *
297 * Note that wherever we can, we use the "ring" option for
298 * transmit and receive descriptors. This is because some
299 * clone chips apparently have problems when using chaining,
300 * although some *only* support chaining.
301 *
302 * What we do is always program the "next" pointer, and then
303 * conditionally set the TDCTL_CH and TDCTL_ER bits in the
304 * appropriate places.
305 */
306 switch (sc->sc_chip) {
307 case TULIP_CHIP_21140:
308 case TULIP_CHIP_21140A:
309 case TULIP_CHIP_21142:
310 case TULIP_CHIP_21143:
311 case TULIP_CHIP_82C115: /* 21143-like */
312 case TULIP_CHIP_MX98713: /* 21140-like */
313 case TULIP_CHIP_MX98713A: /* 21143-like */
314 case TULIP_CHIP_MX98715: /* 21143-like */
315 case TULIP_CHIP_MX98715A: /* 21143-like */
316 case TULIP_CHIP_MX98715AEC_X: /* 21143-like */
317 case TULIP_CHIP_MX98725: /* 21143-like */
318 case TULIP_CHIP_RS7112: /* 21143-like */
319 /*
320 * Run these chips in ring mode.
321 */
322 sc->sc_tdctl_ch = 0;
323 sc->sc_tdctl_er = TDCTL_ER;
324 sc->sc_preinit = tlp_2114x_preinit;
325 break;
326
327 case TULIP_CHIP_82C168:
328 case TULIP_CHIP_82C169:
329 /*
330 * Run these chips in ring mode.
331 */
332 sc->sc_tdctl_ch = 0;
333 sc->sc_tdctl_er = TDCTL_ER;
334 sc->sc_preinit = tlp_pnic_preinit;
335
336 /*
337 * These chips seem to have busted DMA engines; just put them
338 * in Store-and-Forward mode from the get-go.
339 */
340 sc->sc_txthresh = TXTH_SF;
341 break;
342
343 case TULIP_CHIP_WB89C840F:
344 /*
345 * Run this chip in chained mode.
346 */
347 sc->sc_tdctl_ch = TDCTL_CH;
348 sc->sc_tdctl_er = 0;
349 sc->sc_flags |= TULIPF_IC_FS;
350 break;
351
352 case TULIP_CHIP_DM9102:
353 case TULIP_CHIP_DM9102A:
354 /*
355 * Run these chips in chained mode.
356 */
357 sc->sc_tdctl_ch = TDCTL_CH;
358 sc->sc_tdctl_er = 0;
359 sc->sc_preinit = tlp_dm9102_preinit;
360
361 /*
362 * These chips have a broken bus interface, so we
363 * can't use any optimized bus commands. For this
364 * reason, we tend to underrun pretty quickly, so
365 * just to Store-and-Forward mode from the get-go.
366 */
367 sc->sc_txthresh = TXTH_DM9102_SF;
368 break;
369
370 case TULIP_CHIP_AX88140:
371 case TULIP_CHIP_AX88141:
372 /*
373 * Run these chips in ring mode.
374 */
375 sc->sc_tdctl_ch = 0;
376 sc->sc_tdctl_er = TDCTL_ER;
377 sc->sc_preinit = tlp_asix_preinit;
378 break;
379
380 default:
381 /*
382 * Default to running in ring mode.
383 */
384 sc->sc_tdctl_ch = 0;
385 sc->sc_tdctl_er = TDCTL_ER;
386 }
387
388 /*
389 * Set up the MII bit-bang operations.
390 */
391 switch (sc->sc_chip) {
392 case TULIP_CHIP_WB89C840F: /* XXX direction bit different? */
393 sc->sc_bitbang_ops = &tlp_sio_mii_bitbang_ops;
394 break;
395
396 default:
397 sc->sc_bitbang_ops = &tlp_sio_mii_bitbang_ops;
398 }
399
400 SIMPLEQ_INIT(&sc->sc_txfreeq);
401 SIMPLEQ_INIT(&sc->sc_txdirtyq);
402
403 /*
404 * Allocate the control data structures, and create and load the
405 * DMA map for it.
406 */
407 if ((error = bus_dmamem_alloc(sc->sc_dmat,
408 sizeof(struct tulip_control_data), PAGE_SIZE, 0, &sc->sc_cdseg,
409 1, &sc->sc_cdnseg, 0)) != 0) {
410 printf("%s: unable to allocate control data, error = %d\n",
411 sc->sc_dev.dv_xname, error);
412 goto fail_0;
413 }
414
415 if ((error = bus_dmamem_map(sc->sc_dmat, &sc->sc_cdseg, sc->sc_cdnseg,
416 sizeof(struct tulip_control_data), (caddr_t *)&sc->sc_control_data,
417 BUS_DMA_COHERENT)) != 0) {
418 printf("%s: unable to map control data, error = %d\n",
419 sc->sc_dev.dv_xname, error);
420 goto fail_1;
421 }
422
423 if ((error = bus_dmamap_create(sc->sc_dmat,
424 sizeof(struct tulip_control_data), 1,
425 sizeof(struct tulip_control_data), 0, 0, &sc->sc_cddmamap)) != 0) {
426 printf("%s: unable to create control data DMA map, "
427 "error = %d\n", sc->sc_dev.dv_xname, error);
428 goto fail_2;
429 }
430
431 if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_cddmamap,
432 sc->sc_control_data, sizeof(struct tulip_control_data), NULL,
433 0)) != 0) {
434 printf("%s: unable to load control data DMA map, error = %d\n",
435 sc->sc_dev.dv_xname, error);
436 goto fail_3;
437 }
438
439 /*
440 * Create the transmit buffer DMA maps.
441 *
442 * Note that on the Xircom clone, transmit buffers must be
443 * 4-byte aligned. We're almost guaranteed to have to copy
444 * the packet in that case, so we just limit ourselves to
445 * one segment.
446 *
447 * On the DM9102, the transmit logic can only handle one
448 * DMA segment.
449 */
450 switch (sc->sc_chip) {
451 case TULIP_CHIP_X3201_3:
452 case TULIP_CHIP_DM9102:
453 case TULIP_CHIP_DM9102A:
454 case TULIP_CHIP_AX88140:
455 case TULIP_CHIP_AX88141:
456 sc->sc_ntxsegs = 1;
457 break;
458
459 default:
460 sc->sc_ntxsegs = TULIP_NTXSEGS;
461 }
462 for (i = 0; i < TULIP_TXQUEUELEN; i++) {
463 if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES,
464 sc->sc_ntxsegs, MCLBYTES, 0, 0,
465 &sc->sc_txsoft[i].txs_dmamap)) != 0) {
466 printf("%s: unable to create tx DMA map %d, "
467 "error = %d\n", sc->sc_dev.dv_xname, i, error);
468 goto fail_4;
469 }
470 }
471
472 /*
473 * Create the receive buffer DMA maps.
474 */
475 for (i = 0; i < TULIP_NRXDESC; i++) {
476 if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1,
477 MCLBYTES, 0, 0, &sc->sc_rxsoft[i].rxs_dmamap)) != 0) {
478 printf("%s: unable to create rx DMA map %d, "
479 "error = %d\n", sc->sc_dev.dv_xname, i, error);
480 goto fail_5;
481 }
482 sc->sc_rxsoft[i].rxs_mbuf = NULL;
483 }
484
485 /*
486 * From this point forward, the attachment cannot fail. A failure
487 * before this point releases all resources that may have been
488 * allocated.
489 */
490 sc->sc_flags |= TULIPF_ATTACHED;
491
492 /*
493 * Reset the chip to a known state.
494 */
495 tlp_reset(sc);
496
497 /* Announce ourselves. */
498 printf("%s: %s%sEthernet address %s\n", sc->sc_dev.dv_xname,
499 sc->sc_name[0] != '\0' ? sc->sc_name : "",
500 sc->sc_name[0] != '\0' ? ", " : "",
501 ether_sprintf(enaddr));
502
503 /*
504 * Check to see if we're the simulated Ethernet on Connectix
505 * Virtual PC.
506 */
507 if (enaddr[0] == 0x00 && enaddr[1] == 0x03 && enaddr[2] == 0xff)
508 sc->sc_flags |= TULIPF_VPC;
509
510 /*
511 * Initialize our media structures. This may probe the MII, if
512 * present.
513 */
514 (*sc->sc_mediasw->tmsw_init)(sc);
515
516 strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
517 ifp->if_softc = sc;
518 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
519 sc->sc_if_flags = ifp->if_flags;
520 ifp->if_ioctl = tlp_ioctl;
521 ifp->if_start = tlp_start;
522 ifp->if_watchdog = tlp_watchdog;
523 ifp->if_init = tlp_init;
524 ifp->if_stop = tlp_stop;
525 IFQ_SET_READY(&ifp->if_snd);
526
527 /*
528 * We can support 802.1Q VLAN-sized frames.
529 */
530 sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU;
531
532 /*
533 * Attach the interface.
534 */
535 if_attach(ifp);
536 ether_ifattach(ifp, enaddr);
537 #if NRND > 0
538 rnd_attach_source(&sc->sc_rnd_source, sc->sc_dev.dv_xname,
539 RND_TYPE_NET, 0);
540 #endif
541
542 /*
543 * Make sure the interface is shutdown during reboot.
544 */
545 sc->sc_sdhook = shutdownhook_establish(tlp_shutdown, sc);
546 if (sc->sc_sdhook == NULL)
547 printf("%s: WARNING: unable to establish shutdown hook\n",
548 sc->sc_dev.dv_xname);
549
550 /*
551 * Add a suspend hook to make sure we come back up after a
552 * resume.
553 */
554 sc->sc_powerhook = powerhook_establish(tlp_power, sc);
555 if (sc->sc_powerhook == NULL)
556 printf("%s: WARNING: unable to establish power hook\n",
557 sc->sc_dev.dv_xname);
558 return;
559
560 /*
561 * Free any resources we've allocated during the failed attach
562 * attempt. Do this in reverse order and fall through.
563 */
564 fail_5:
565 for (i = 0; i < TULIP_NRXDESC; i++) {
566 if (sc->sc_rxsoft[i].rxs_dmamap != NULL)
567 bus_dmamap_destroy(sc->sc_dmat,
568 sc->sc_rxsoft[i].rxs_dmamap);
569 }
570 fail_4:
571 for (i = 0; i < TULIP_TXQUEUELEN; i++) {
572 if (sc->sc_txsoft[i].txs_dmamap != NULL)
573 bus_dmamap_destroy(sc->sc_dmat,
574 sc->sc_txsoft[i].txs_dmamap);
575 }
576 bus_dmamap_unload(sc->sc_dmat, sc->sc_cddmamap);
577 fail_3:
578 bus_dmamap_destroy(sc->sc_dmat, sc->sc_cddmamap);
579 fail_2:
580 bus_dmamem_unmap(sc->sc_dmat, (caddr_t)sc->sc_control_data,
581 sizeof(struct tulip_control_data));
582 fail_1:
583 bus_dmamem_free(sc->sc_dmat, &sc->sc_cdseg, sc->sc_cdnseg);
584 fail_0:
585 return;
586 }
587
588 /*
589 * tlp_activate:
590 *
591 * Handle device activation/deactivation requests.
592 */
593 int
594 tlp_activate(struct device *self, enum devact act)
595 {
596 struct tulip_softc *sc = (void *) self;
597 int s, error = 0;
598
599 s = splnet();
600 switch (act) {
601 case DVACT_ACTIVATE:
602 error = EOPNOTSUPP;
603 break;
604
605 case DVACT_DEACTIVATE:
606 if (sc->sc_flags & TULIPF_HAS_MII)
607 mii_activate(&sc->sc_mii, act, MII_PHY_ANY,
608 MII_OFFSET_ANY);
609 if_deactivate(&sc->sc_ethercom.ec_if);
610 break;
611 }
612 splx(s);
613
614 return (error);
615 }
616
617 /*
618 * tlp_detach:
619 *
620 * Detach a Tulip interface.
621 */
622 int
623 tlp_detach(struct tulip_softc *sc)
624 {
625 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
626 struct tulip_rxsoft *rxs;
627 struct tulip_txsoft *txs;
628 int i;
629
630 /*
631 * Succeed now if there isn't any work to do.
632 */
633 if ((sc->sc_flags & TULIPF_ATTACHED) == 0)
634 return (0);
635
636 /* Unhook our tick handler. */
637 if (sc->sc_tick)
638 callout_stop(&sc->sc_tick_callout);
639
640 if (sc->sc_flags & TULIPF_HAS_MII) {
641 /* Detach all PHYs */
642 mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
643 }
644
645 /* Delete all remaining media. */
646 ifmedia_delete_instance(&sc->sc_mii.mii_media, IFM_INST_ANY);
647
648 #if NRND > 0
649 rnd_detach_source(&sc->sc_rnd_source);
650 #endif
651 ether_ifdetach(ifp);
652 if_detach(ifp);
653
654 for (i = 0; i < TULIP_NRXDESC; i++) {
655 rxs = &sc->sc_rxsoft[i];
656 if (rxs->rxs_mbuf != NULL) {
657 bus_dmamap_unload(sc->sc_dmat, rxs->rxs_dmamap);
658 m_freem(rxs->rxs_mbuf);
659 rxs->rxs_mbuf = NULL;
660 }
661 bus_dmamap_destroy(sc->sc_dmat, rxs->rxs_dmamap);
662 }
663 for (i = 0; i < TULIP_TXQUEUELEN; i++) {
664 txs = &sc->sc_txsoft[i];
665 if (txs->txs_mbuf != NULL) {
666 bus_dmamap_unload(sc->sc_dmat, txs->txs_dmamap);
667 m_freem(txs->txs_mbuf);
668 txs->txs_mbuf = NULL;
669 }
670 bus_dmamap_destroy(sc->sc_dmat, txs->txs_dmamap);
671 }
672 bus_dmamap_unload(sc->sc_dmat, sc->sc_cddmamap);
673 bus_dmamap_destroy(sc->sc_dmat, sc->sc_cddmamap);
674 bus_dmamem_unmap(sc->sc_dmat, (caddr_t)sc->sc_control_data,
675 sizeof(struct tulip_control_data));
676 bus_dmamem_free(sc->sc_dmat, &sc->sc_cdseg, sc->sc_cdnseg);
677
678 shutdownhook_disestablish(sc->sc_sdhook);
679 powerhook_disestablish(sc->sc_powerhook);
680
681 if (sc->sc_srom)
682 free(sc->sc_srom, M_DEVBUF);
683
684 return (0);
685 }
686
687 /*
688 * tlp_shutdown:
689 *
690 * Make sure the interface is stopped at reboot time.
691 */
692 static void
693 tlp_shutdown(void *arg)
694 {
695 struct tulip_softc *sc = arg;
696
697 tlp_stop(&sc->sc_ethercom.ec_if, 1);
698 }
699
700 /*
701 * tlp_start: [ifnet interface function]
702 *
703 * Start packet transmission on the interface.
704 */
705 static void
706 tlp_start(struct ifnet *ifp)
707 {
708 struct tulip_softc *sc = ifp->if_softc;
709 struct mbuf *m0, *m;
710 struct tulip_txsoft *txs, *last_txs = NULL;
711 bus_dmamap_t dmamap;
712 int error, firsttx, nexttx, lasttx = 1, ofree, seg;
713
714 DPRINTF(sc, ("%s: tlp_start: sc_flags 0x%08x, if_flags 0x%08x\n",
715 sc->sc_dev.dv_xname, sc->sc_flags, ifp->if_flags));
716
717 /*
718 * If we want a filter setup, it means no more descriptors were
719 * available for the setup routine. Let it get a chance to wedge
720 * itself into the ring.
721 */
722 if (sc->sc_flags & TULIPF_WANT_SETUP)
723 ifp->if_flags |= IFF_OACTIVE;
724
725 if ((ifp->if_flags & (IFF_RUNNING|IFF_OACTIVE)) != IFF_RUNNING)
726 return;
727
728 if (sc->sc_tick == tlp_2114x_nway_tick &&
729 (sc->sc_flags & TULIPF_LINK_UP) == 0 && ifp->if_snd.ifq_len < 10)
730 return;
731
732 /*
733 * Remember the previous number of free descriptors and
734 * the first descriptor we'll use.
735 */
736 ofree = sc->sc_txfree;
737 firsttx = sc->sc_txnext;
738
739 DPRINTF(sc, ("%s: tlp_start: txfree %d, txnext %d\n",
740 sc->sc_dev.dv_xname, ofree, firsttx));
741
742 /*
743 * Loop through the send queue, setting up transmit descriptors
744 * until we drain the queue, or use up all available transmit
745 * descriptors.
746 */
747 while ((txs = SIMPLEQ_FIRST(&sc->sc_txfreeq)) != NULL &&
748 sc->sc_txfree != 0) {
749 /*
750 * Grab a packet off the queue.
751 */
752 IFQ_POLL(&ifp->if_snd, m0);
753 if (m0 == NULL)
754 break;
755 m = NULL;
756
757 dmamap = txs->txs_dmamap;
758
759 /*
760 * Load the DMA map. If this fails, the packet either
761 * didn't fit in the alloted number of segments, or we were
762 * short on resources. In this case, we'll copy and try
763 * again.
764 *
765 * Note that if we're only allowed 1 Tx segment, we
766 * have an alignment restriction. Do this test before
767 * attempting to load the DMA map, because it's more
768 * likely we'll trip the alignment test than the
769 * more-than-one-segment test.
770 */
771 if ((sc->sc_ntxsegs == 1 && (mtod(m0, uintptr_t) & 3) != 0) ||
772 bus_dmamap_load_mbuf(sc->sc_dmat, dmamap, m0,
773 BUS_DMA_WRITE|BUS_DMA_NOWAIT) != 0) {
774 MGETHDR(m, M_DONTWAIT, MT_DATA);
775 if (m == NULL) {
776 printf("%s: unable to allocate Tx mbuf\n",
777 sc->sc_dev.dv_xname);
778 break;
779 }
780 MCLAIM(m, &sc->sc_ethercom.ec_tx_mowner);
781 if (m0->m_pkthdr.len > MHLEN) {
782 MCLGET(m, M_DONTWAIT);
783 if ((m->m_flags & M_EXT) == 0) {
784 printf("%s: unable to allocate Tx "
785 "cluster\n", sc->sc_dev.dv_xname);
786 m_freem(m);
787 break;
788 }
789 }
790 m_copydata(m0, 0, m0->m_pkthdr.len, mtod(m, caddr_t));
791 m->m_pkthdr.len = m->m_len = m0->m_pkthdr.len;
792 error = bus_dmamap_load_mbuf(sc->sc_dmat, dmamap,
793 m, BUS_DMA_WRITE|BUS_DMA_NOWAIT);
794 if (error) {
795 printf("%s: unable to load Tx buffer, "
796 "error = %d\n", sc->sc_dev.dv_xname, error);
797 break;
798 }
799 }
800
801 /*
802 * Ensure we have enough descriptors free to describe
803 * the packet.
804 */
805 if (dmamap->dm_nsegs > sc->sc_txfree) {
806 /*
807 * Not enough free descriptors to transmit this
808 * packet. We haven't committed to anything yet,
809 * so just unload the DMA map, put the packet
810 * back on the queue, and punt. Notify the upper
811 * layer that there are no more slots left.
812 *
813 * XXX We could allocate an mbuf and copy, but
814 * XXX it is worth it?
815 */
816 ifp->if_flags |= IFF_OACTIVE;
817 bus_dmamap_unload(sc->sc_dmat, dmamap);
818 if (m != NULL)
819 m_freem(m);
820 break;
821 }
822
823 IFQ_DEQUEUE(&ifp->if_snd, m0);
824 if (m != NULL) {
825 m_freem(m0);
826 m0 = m;
827 }
828
829 /*
830 * WE ARE NOW COMMITTED TO TRANSMITTING THE PACKET.
831 */
832
833 /* Sync the DMA map. */
834 bus_dmamap_sync(sc->sc_dmat, dmamap, 0, dmamap->dm_mapsize,
835 BUS_DMASYNC_PREWRITE);
836
837 /*
838 * Initialize the transmit descriptors.
839 */
840 for (nexttx = sc->sc_txnext, seg = 0;
841 seg < dmamap->dm_nsegs;
842 seg++, nexttx = TULIP_NEXTTX(nexttx)) {
843 /*
844 * If this is the first descriptor we're
845 * enqueueing, don't set the OWN bit just
846 * yet. That could cause a race condition.
847 * We'll do it below.
848 */
849 sc->sc_txdescs[nexttx].td_status =
850 (nexttx == firsttx) ? 0 : htole32(TDSTAT_OWN);
851 sc->sc_txdescs[nexttx].td_bufaddr1 =
852 htole32(dmamap->dm_segs[seg].ds_addr);
853 sc->sc_txdescs[nexttx].td_ctl =
854 htole32((dmamap->dm_segs[seg].ds_len <<
855 TDCTL_SIZE1_SHIFT) | sc->sc_tdctl_ch |
856 (nexttx == (TULIP_NTXDESC - 1) ?
857 sc->sc_tdctl_er : 0));
858 lasttx = nexttx;
859 }
860
861 KASSERT(lasttx != -1);
862
863 /* Set `first segment' and `last segment' appropriately. */
864 sc->sc_txdescs[sc->sc_txnext].td_ctl |= htole32(TDCTL_Tx_FS);
865 sc->sc_txdescs[lasttx].td_ctl |= htole32(TDCTL_Tx_LS);
866
867 #ifdef TLP_DEBUG
868 if (ifp->if_flags & IFF_DEBUG) {
869 printf(" txsoft %p transmit chain:\n", txs);
870 for (seg = sc->sc_txnext;; seg = TULIP_NEXTTX(seg)) {
871 printf(" descriptor %d:\n", seg);
872 printf(" td_status: 0x%08x\n",
873 le32toh(sc->sc_txdescs[seg].td_status));
874 printf(" td_ctl: 0x%08x\n",
875 le32toh(sc->sc_txdescs[seg].td_ctl));
876 printf(" td_bufaddr1: 0x%08x\n",
877 le32toh(sc->sc_txdescs[seg].td_bufaddr1));
878 printf(" td_bufaddr2: 0x%08x\n",
879 le32toh(sc->sc_txdescs[seg].td_bufaddr2));
880 if (seg == lasttx)
881 break;
882 }
883 }
884 #endif
885
886 /* Sync the descriptors we're using. */
887 TULIP_CDTXSYNC(sc, sc->sc_txnext, dmamap->dm_nsegs,
888 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
889
890 /*
891 * Store a pointer to the packet so we can free it later,
892 * and remember what txdirty will be once the packet is
893 * done.
894 */
895 txs->txs_mbuf = m0;
896 txs->txs_firstdesc = sc->sc_txnext;
897 txs->txs_lastdesc = lasttx;
898 txs->txs_ndescs = dmamap->dm_nsegs;
899
900 /* Advance the tx pointer. */
901 sc->sc_txfree -= dmamap->dm_nsegs;
902 sc->sc_txnext = nexttx;
903
904 SIMPLEQ_REMOVE_HEAD(&sc->sc_txfreeq, txs_q);
905 SIMPLEQ_INSERT_TAIL(&sc->sc_txdirtyq, txs, txs_q);
906
907 last_txs = txs;
908
909 #if NBPFILTER > 0
910 /*
911 * Pass the packet to any BPF listeners.
912 */
913 if (ifp->if_bpf)
914 bpf_mtap(ifp->if_bpf, m0);
915 #endif /* NBPFILTER > 0 */
916 }
917
918 if (txs == NULL || sc->sc_txfree == 0) {
919 /* No more slots left; notify upper layer. */
920 ifp->if_flags |= IFF_OACTIVE;
921 }
922
923 if (sc->sc_txfree != ofree) {
924 DPRINTF(sc, ("%s: packets enqueued, IC on %d, OWN on %d\n",
925 sc->sc_dev.dv_xname, lasttx, firsttx));
926 /*
927 * Cause a transmit interrupt to happen on the
928 * last packet we enqueued.
929 */
930 sc->sc_txdescs[lasttx].td_ctl |= htole32(TDCTL_Tx_IC);
931 TULIP_CDTXSYNC(sc, lasttx, 1,
932 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
933
934 /*
935 * Some clone chips want IC on the *first* segment in
936 * the packet. Appease them.
937 */
938 KASSERT(last_txs != NULL);
939 if ((sc->sc_flags & TULIPF_IC_FS) != 0 &&
940 last_txs->txs_firstdesc != lasttx) {
941 sc->sc_txdescs[last_txs->txs_firstdesc].td_ctl |=
942 htole32(TDCTL_Tx_IC);
943 TULIP_CDTXSYNC(sc, last_txs->txs_firstdesc, 1,
944 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
945 }
946
947 /*
948 * The entire packet chain is set up. Give the
949 * first descriptor to the chip now.
950 */
951 sc->sc_txdescs[firsttx].td_status |= htole32(TDSTAT_OWN);
952 TULIP_CDTXSYNC(sc, firsttx, 1,
953 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
954
955 /* Wake up the transmitter. */
956 /* XXX USE AUTOPOLLING? */
957 TULIP_WRITE(sc, CSR_TXPOLL, TXPOLL_TPD);
958
959 /* Set a watchdog timer in case the chip flakes out. */
960 ifp->if_timer = 5;
961 }
962 }
963
964 /*
965 * tlp_watchdog: [ifnet interface function]
966 *
967 * Watchdog timer handler.
968 */
969 static void
970 tlp_watchdog(struct ifnet *ifp)
971 {
972 struct tulip_softc *sc = ifp->if_softc;
973 int doing_setup, doing_transmit;
974
975 doing_setup = (sc->sc_flags & TULIPF_DOING_SETUP);
976 doing_transmit = (! SIMPLEQ_EMPTY(&sc->sc_txdirtyq));
977
978 if (doing_setup && doing_transmit) {
979 printf("%s: filter setup and transmit timeout\n",
980 sc->sc_dev.dv_xname);
981 ifp->if_oerrors++;
982 } else if (doing_transmit) {
983 printf("%s: transmit timeout\n", sc->sc_dev.dv_xname);
984 ifp->if_oerrors++;
985 } else if (doing_setup)
986 printf("%s: filter setup timeout\n", sc->sc_dev.dv_xname);
987 else
988 printf("%s: spurious watchdog timeout\n", sc->sc_dev.dv_xname);
989
990 (void) tlp_init(ifp);
991
992 /* Try to get more packets going. */
993 tlp_start(ifp);
994 }
995
996 /*
997 * tlp_ioctl: [ifnet interface function]
998 *
999 * Handle control requests from the operator.
1000 */
1001 static int
1002 tlp_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
1003 {
1004 struct tulip_softc *sc = ifp->if_softc;
1005 struct ifreq *ifr = (struct ifreq *)data;
1006 int s, error;
1007
1008 s = splnet();
1009
1010 switch (cmd) {
1011 case SIOCSIFMEDIA:
1012 case SIOCGIFMEDIA:
1013 error = ifmedia_ioctl(ifp, ifr, &sc->sc_mii.mii_media, cmd);
1014 break;
1015 case SIOCSIFFLAGS:
1016 /* If the interface is up and running, only modify the receive
1017 * filter when setting promiscuous or debug mode. Otherwise
1018 * fall through to ether_ioctl, which will reset the chip.
1019 */
1020 #define RESETIGN (IFF_CANTCHANGE|IFF_DEBUG)
1021 if (((ifp->if_flags & (IFF_UP|IFF_RUNNING))
1022 == (IFF_UP|IFF_RUNNING))
1023 && ((ifp->if_flags & (~RESETIGN))
1024 == (sc->sc_if_flags & (~RESETIGN)))) {
1025 /* Set up the receive filter. */
1026 (*sc->sc_filter_setup)(sc);
1027 error = 0;
1028 break;
1029 #undef RESETIGN
1030 }
1031 /* FALLTHROUGH */
1032 default:
1033 error = ether_ioctl(ifp, cmd, data);
1034 if (error == ENETRESET) {
1035 if (ifp->if_flags & IFF_RUNNING) {
1036 /*
1037 * Multicast list has changed. Set the
1038 * hardware filter accordingly.
1039 */
1040 (*sc->sc_filter_setup)(sc);
1041 }
1042 error = 0;
1043 }
1044 break;
1045 }
1046
1047 /* Try to get more packets going. */
1048 if (TULIP_IS_ENABLED(sc))
1049 tlp_start(ifp);
1050
1051 sc->sc_if_flags = ifp->if_flags;
1052 splx(s);
1053 return (error);
1054 }
1055
1056 /*
1057 * tlp_intr:
1058 *
1059 * Interrupt service routine.
1060 */
1061 int
1062 tlp_intr(void *arg)
1063 {
1064 struct tulip_softc *sc = arg;
1065 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
1066 u_int32_t status, rxstatus, txstatus;
1067 int handled = 0, txthresh;
1068
1069 DPRINTF(sc, ("%s: tlp_intr\n", sc->sc_dev.dv_xname));
1070
1071 #ifdef DEBUG
1072 if (TULIP_IS_ENABLED(sc) == 0)
1073 panic("%s: tlp_intr: not enabled", sc->sc_dev.dv_xname);
1074 #endif
1075
1076 /*
1077 * If the interface isn't running, the interrupt couldn't
1078 * possibly have come from us.
1079 */
1080 if ((ifp->if_flags & IFF_RUNNING) == 0 ||
1081 !device_is_active(&sc->sc_dev))
1082 return (0);
1083
1084 /* Disable interrupts on the DM9102 (interrupt edge bug). */
1085 switch (sc->sc_chip) {
1086 case TULIP_CHIP_DM9102:
1087 case TULIP_CHIP_DM9102A:
1088 TULIP_WRITE(sc, CSR_INTEN, 0);
1089 break;
1090
1091 default:
1092 /* Nothing. */
1093 break;
1094 }
1095
1096 for (;;) {
1097 status = TULIP_READ(sc, CSR_STATUS);
1098 if (status)
1099 TULIP_WRITE(sc, CSR_STATUS, status);
1100
1101 if ((status & sc->sc_inten) == 0)
1102 break;
1103
1104 handled = 1;
1105
1106 rxstatus = status & sc->sc_rxint_mask;
1107 txstatus = status & sc->sc_txint_mask;
1108
1109 if (rxstatus) {
1110 /* Grab new any new packets. */
1111 tlp_rxintr(sc);
1112
1113 if (rxstatus & STATUS_RWT)
1114 printf("%s: receive watchdog timeout\n",
1115 sc->sc_dev.dv_xname);
1116
1117 if (rxstatus & STATUS_RU) {
1118 printf("%s: receive ring overrun\n",
1119 sc->sc_dev.dv_xname);
1120 /* Get the receive process going again. */
1121 if (sc->sc_tdctl_er != TDCTL_ER) {
1122 tlp_idle(sc, OPMODE_SR);
1123 TULIP_WRITE(sc, CSR_RXLIST,
1124 TULIP_CDRXADDR(sc, sc->sc_rxptr));
1125 TULIP_WRITE(sc, CSR_OPMODE,
1126 sc->sc_opmode);
1127 }
1128 TULIP_WRITE(sc, CSR_RXPOLL, RXPOLL_RPD);
1129 break;
1130 }
1131 }
1132
1133 if (txstatus) {
1134 /* Sweep up transmit descriptors. */
1135 tlp_txintr(sc);
1136
1137 if (txstatus & STATUS_TJT)
1138 printf("%s: transmit jabber timeout\n",
1139 sc->sc_dev.dv_xname);
1140
1141 if (txstatus & STATUS_UNF) {
1142 /*
1143 * Increase our transmit threshold if
1144 * another is available.
1145 */
1146 txthresh = sc->sc_txthresh + 1;
1147 if (sc->sc_txth[txthresh].txth_name != NULL) {
1148 /* Idle the transmit process. */
1149 tlp_idle(sc, OPMODE_ST);
1150
1151 sc->sc_txthresh = txthresh;
1152 sc->sc_opmode &= ~(OPMODE_TR|OPMODE_SF);
1153 sc->sc_opmode |=
1154 sc->sc_txth[txthresh].txth_opmode;
1155 printf("%s: transmit underrun; new "
1156 "threshold: %s\n",
1157 sc->sc_dev.dv_xname,
1158 sc->sc_txth[txthresh].txth_name);
1159
1160 /*
1161 * Set the new threshold and restart
1162 * the transmit process.
1163 */
1164 TULIP_WRITE(sc, CSR_OPMODE,
1165 sc->sc_opmode);
1166 }
1167 /*
1168 * XXX Log every Nth underrun from
1169 * XXX now on?
1170 */
1171 }
1172 }
1173
1174 if (status & (STATUS_TPS|STATUS_RPS)) {
1175 if (status & STATUS_TPS)
1176 printf("%s: transmit process stopped\n",
1177 sc->sc_dev.dv_xname);
1178 if (status & STATUS_RPS)
1179 printf("%s: receive process stopped\n",
1180 sc->sc_dev.dv_xname);
1181 (void) tlp_init(ifp);
1182 break;
1183 }
1184
1185 if (status & STATUS_SE) {
1186 const char *str;
1187 switch (status & STATUS_EB) {
1188 case STATUS_EB_PARITY:
1189 str = "parity error";
1190 break;
1191
1192 case STATUS_EB_MABT:
1193 str = "master abort";
1194 break;
1195
1196 case STATUS_EB_TABT:
1197 str = "target abort";
1198 break;
1199
1200 default:
1201 str = "unknown error";
1202 break;
1203 }
1204 printf("%s: fatal system error: %s\n",
1205 sc->sc_dev.dv_xname, str);
1206 (void) tlp_init(ifp);
1207 break;
1208 }
1209
1210 /*
1211 * Not handled:
1212 *
1213 * Transmit buffer unavailable -- normal
1214 * condition, nothing to do, really.
1215 *
1216 * General purpose timer experied -- we don't
1217 * use the general purpose timer.
1218 *
1219 * Early receive interrupt -- not available on
1220 * all chips, we just use RI. We also only
1221 * use single-segment receive DMA, so this
1222 * is mostly useless.
1223 */
1224 }
1225
1226 /* Bring interrupts back up on the DM9102. */
1227 switch (sc->sc_chip) {
1228 case TULIP_CHIP_DM9102:
1229 case TULIP_CHIP_DM9102A:
1230 TULIP_WRITE(sc, CSR_INTEN, sc->sc_inten);
1231 break;
1232
1233 default:
1234 /* Nothing. */
1235 break;
1236 }
1237
1238 /* Try to get more packets going. */
1239 tlp_start(ifp);
1240
1241 #if NRND > 0
1242 if (handled)
1243 rnd_add_uint32(&sc->sc_rnd_source, status);
1244 #endif
1245 return (handled);
1246 }
1247
1248 /*
1249 * tlp_rxintr:
1250 *
1251 * Helper; handle receive interrupts.
1252 */
1253 static void
1254 tlp_rxintr(struct tulip_softc *sc)
1255 {
1256 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
1257 struct ether_header *eh;
1258 struct tulip_rxsoft *rxs;
1259 struct mbuf *m;
1260 u_int32_t rxstat;
1261 int i, len;
1262
1263 for (i = sc->sc_rxptr;; i = TULIP_NEXTRX(i)) {
1264 rxs = &sc->sc_rxsoft[i];
1265
1266 TULIP_CDRXSYNC(sc, i,
1267 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
1268
1269 rxstat = le32toh(sc->sc_rxdescs[i].td_status);
1270
1271 if (rxstat & TDSTAT_OWN) {
1272 /*
1273 * We have processed all of the receive buffers.
1274 */
1275 break;
1276 }
1277
1278 /*
1279 * Make sure the packet fit in one buffer. This should
1280 * always be the case. But the Lite-On PNIC, rev 33
1281 * has an awful receive engine bug, which may require
1282 * a very icky work-around.
1283 */
1284 if ((rxstat & (TDSTAT_Rx_FS|TDSTAT_Rx_LS)) !=
1285 (TDSTAT_Rx_FS|TDSTAT_Rx_LS)) {
1286 printf("%s: incoming packet spilled, resetting\n",
1287 sc->sc_dev.dv_xname);
1288 (void) tlp_init(ifp);
1289 return;
1290 }
1291
1292 /*
1293 * If any collisions were seen on the wire, count one.
1294 */
1295 if (rxstat & TDSTAT_Rx_CS)
1296 ifp->if_collisions++;
1297
1298 /*
1299 * If an error occurred, update stats, clear the status
1300 * word, and leave the packet buffer in place. It will
1301 * simply be reused the next time the ring comes around.
1302 * If 802.1Q VLAN MTU is enabled, ignore the Frame Too Long
1303 * error.
1304 */
1305 if (rxstat & TDSTAT_ES &&
1306 ((sc->sc_ethercom.ec_capenable & ETHERCAP_VLAN_MTU) == 0 ||
1307 (rxstat & (TDSTAT_Rx_DE | TDSTAT_Rx_RF |
1308 TDSTAT_Rx_DB | TDSTAT_Rx_CE)) != 0)) {
1309 #define PRINTERR(bit, str) \
1310 if (rxstat & (bit)) \
1311 printf("%s: receive error: %s\n", \
1312 sc->sc_dev.dv_xname, str)
1313 ifp->if_ierrors++;
1314 PRINTERR(TDSTAT_Rx_DE, "descriptor error");
1315 PRINTERR(TDSTAT_Rx_RF, "runt frame");
1316 PRINTERR(TDSTAT_Rx_TL, "frame too long");
1317 PRINTERR(TDSTAT_Rx_RE, "MII error");
1318 PRINTERR(TDSTAT_Rx_DB, "dribbling bit");
1319 PRINTERR(TDSTAT_Rx_CE, "CRC error");
1320 #undef PRINTERR
1321 TULIP_INIT_RXDESC(sc, i);
1322 continue;
1323 }
1324
1325 bus_dmamap_sync(sc->sc_dmat, rxs->rxs_dmamap, 0,
1326 rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_POSTREAD);
1327
1328 /*
1329 * No errors; receive the packet. Note the Tulip
1330 * includes the CRC with every packet.
1331 */
1332 len = TDSTAT_Rx_LENGTH(rxstat) - ETHER_CRC_LEN;
1333
1334 #ifdef __NO_STRICT_ALIGNMENT
1335 /*
1336 * Allocate a new mbuf cluster. If that fails, we are
1337 * out of memory, and must drop the packet and recycle
1338 * the buffer that's already attached to this descriptor.
1339 */
1340 m = rxs->rxs_mbuf;
1341 if (tlp_add_rxbuf(sc, i) != 0) {
1342 ifp->if_ierrors++;
1343 TULIP_INIT_RXDESC(sc, i);
1344 bus_dmamap_sync(sc->sc_dmat, rxs->rxs_dmamap, 0,
1345 rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_PREREAD);
1346 continue;
1347 }
1348 #else
1349 /*
1350 * The Tulip's receive buffers must be 4-byte aligned.
1351 * But this means that the data after the Ethernet header
1352 * is misaligned. We must allocate a new buffer and
1353 * copy the data, shifted forward 2 bytes.
1354 */
1355 MGETHDR(m, M_DONTWAIT, MT_DATA);
1356 if (m == NULL) {
1357 dropit:
1358 ifp->if_ierrors++;
1359 TULIP_INIT_RXDESC(sc, i);
1360 bus_dmamap_sync(sc->sc_dmat, rxs->rxs_dmamap, 0,
1361 rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_PREREAD);
1362 continue;
1363 }
1364 MCLAIM(m, &sc->sc_ethercom.ec_rx_mowner);
1365 if (len > (MHLEN - 2)) {
1366 MCLGET(m, M_DONTWAIT);
1367 if ((m->m_flags & M_EXT) == 0) {
1368 m_freem(m);
1369 goto dropit;
1370 }
1371 }
1372 m->m_data += 2;
1373
1374 /*
1375 * Note that we use clusters for incoming frames, so the
1376 * buffer is virtually contiguous.
1377 */
1378 memcpy(mtod(m, caddr_t), mtod(rxs->rxs_mbuf, caddr_t), len);
1379
1380 /* Allow the receive descriptor to continue using its mbuf. */
1381 TULIP_INIT_RXDESC(sc, i);
1382 bus_dmamap_sync(sc->sc_dmat, rxs->rxs_dmamap, 0,
1383 rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_PREREAD);
1384 #endif /* __NO_STRICT_ALIGNMENT */
1385
1386 ifp->if_ipackets++;
1387 eh = mtod(m, struct ether_header *);
1388 m->m_pkthdr.rcvif = ifp;
1389 m->m_pkthdr.len = m->m_len = len;
1390
1391 /*
1392 * XXX Work-around for a weird problem with the emulated
1393 * 21041 on Connectix Virtual PC:
1394 *
1395 * When we receive a full-size TCP segment, we seem to get
1396 * a packet there the Rx status says 1522 bytes, yet we do
1397 * not get a frame-too-long error from the chip. The extra
1398 * bytes seem to always be zeros. Perhaps Virtual PC is
1399 * inserting 4 bytes of zeros after every packet. In any
1400 * case, let's try and detect this condition and truncate
1401 * the length so that it will pass up the stack.
1402 */
1403 if (__predict_false((sc->sc_flags & TULIPF_VPC) != 0)) {
1404 uint16_t etype = ntohs(eh->ether_type);
1405
1406 if (len > ETHER_MAX_FRAME(ifp, etype, 0))
1407 m->m_pkthdr.len = m->m_len = len =
1408 ETHER_MAX_FRAME(ifp, etype, 0);
1409 }
1410
1411 #if NBPFILTER > 0
1412 /*
1413 * Pass this up to any BPF listeners, but only
1414 * pass it up the stack if its for us.
1415 */
1416 if (ifp->if_bpf)
1417 bpf_mtap(ifp->if_bpf, m);
1418 #endif /* NPBFILTER > 0 */
1419
1420 /*
1421 * We sometimes have to run the 21140 in Hash-Only
1422 * mode. If we're in that mode, and not in promiscuous
1423 * mode, and we have a unicast packet that isn't for
1424 * us, then drop it.
1425 */
1426 if (sc->sc_filtmode == TDCTL_Tx_FT_HASHONLY &&
1427 (ifp->if_flags & IFF_PROMISC) == 0 &&
1428 ETHER_IS_MULTICAST(eh->ether_dhost) == 0 &&
1429 memcmp(LLADDR(ifp->if_sadl), eh->ether_dhost,
1430 ETHER_ADDR_LEN) != 0) {
1431 m_freem(m);
1432 continue;
1433 }
1434
1435 /* Pass it on. */
1436 (*ifp->if_input)(ifp, m);
1437 }
1438
1439 /* Update the receive pointer. */
1440 sc->sc_rxptr = i;
1441 }
1442
1443 /*
1444 * tlp_txintr:
1445 *
1446 * Helper; handle transmit interrupts.
1447 */
1448 static void
1449 tlp_txintr(struct tulip_softc *sc)
1450 {
1451 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
1452 struct tulip_txsoft *txs;
1453 u_int32_t txstat;
1454
1455 DPRINTF(sc, ("%s: tlp_txintr: sc_flags 0x%08x\n",
1456 sc->sc_dev.dv_xname, sc->sc_flags));
1457
1458 ifp->if_flags &= ~IFF_OACTIVE;
1459
1460 /*
1461 * Go through our Tx list and free mbufs for those
1462 * frames that have been transmitted.
1463 */
1464 while ((txs = SIMPLEQ_FIRST(&sc->sc_txdirtyq)) != NULL) {
1465 TULIP_CDTXSYNC(sc, txs->txs_lastdesc,
1466 txs->txs_ndescs,
1467 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
1468
1469 #ifdef TLP_DEBUG
1470 if (ifp->if_flags & IFF_DEBUG) {
1471 int i;
1472 printf(" txsoft %p transmit chain:\n", txs);
1473 for (i = txs->txs_firstdesc;; i = TULIP_NEXTTX(i)) {
1474 printf(" descriptor %d:\n", i);
1475 printf(" td_status: 0x%08x\n",
1476 le32toh(sc->sc_txdescs[i].td_status));
1477 printf(" td_ctl: 0x%08x\n",
1478 le32toh(sc->sc_txdescs[i].td_ctl));
1479 printf(" td_bufaddr1: 0x%08x\n",
1480 le32toh(sc->sc_txdescs[i].td_bufaddr1));
1481 printf(" td_bufaddr2: 0x%08x\n",
1482 le32toh(sc->sc_txdescs[i].td_bufaddr2));
1483 if (i == txs->txs_lastdesc)
1484 break;
1485 }
1486 }
1487 #endif
1488
1489 txstat = le32toh(sc->sc_txdescs[txs->txs_lastdesc].td_status);
1490 if (txstat & TDSTAT_OWN)
1491 break;
1492
1493 SIMPLEQ_REMOVE_HEAD(&sc->sc_txdirtyq, txs_q);
1494
1495 sc->sc_txfree += txs->txs_ndescs;
1496
1497 if (txs->txs_mbuf == NULL) {
1498 /*
1499 * If we didn't have an mbuf, it was the setup
1500 * packet.
1501 */
1502 #ifdef DIAGNOSTIC
1503 if ((sc->sc_flags & TULIPF_DOING_SETUP) == 0)
1504 panic("tlp_txintr: null mbuf, not doing setup");
1505 #endif
1506 TULIP_CDSPSYNC(sc, BUS_DMASYNC_POSTWRITE);
1507 sc->sc_flags &= ~TULIPF_DOING_SETUP;
1508 SIMPLEQ_INSERT_TAIL(&sc->sc_txfreeq, txs, txs_q);
1509 continue;
1510 }
1511
1512 bus_dmamap_sync(sc->sc_dmat, txs->txs_dmamap,
1513 0, txs->txs_dmamap->dm_mapsize,
1514 BUS_DMASYNC_POSTWRITE);
1515 bus_dmamap_unload(sc->sc_dmat, txs->txs_dmamap);
1516 m_freem(txs->txs_mbuf);
1517 txs->txs_mbuf = NULL;
1518
1519 SIMPLEQ_INSERT_TAIL(&sc->sc_txfreeq, txs, txs_q);
1520
1521 /*
1522 * Check for errors and collisions.
1523 */
1524 #ifdef TLP_STATS
1525 if (txstat & TDSTAT_Tx_UF)
1526 sc->sc_stats.ts_tx_uf++;
1527 if (txstat & TDSTAT_Tx_TO)
1528 sc->sc_stats.ts_tx_to++;
1529 if (txstat & TDSTAT_Tx_EC)
1530 sc->sc_stats.ts_tx_ec++;
1531 if (txstat & TDSTAT_Tx_LC)
1532 sc->sc_stats.ts_tx_lc++;
1533 #endif
1534
1535 if (txstat & (TDSTAT_Tx_UF|TDSTAT_Tx_TO))
1536 ifp->if_oerrors++;
1537
1538 if (txstat & TDSTAT_Tx_EC)
1539 ifp->if_collisions += 16;
1540 else
1541 ifp->if_collisions += TDSTAT_Tx_COLLISIONS(txstat);
1542 if (txstat & TDSTAT_Tx_LC)
1543 ifp->if_collisions++;
1544
1545 ifp->if_opackets++;
1546 }
1547
1548 /*
1549 * If there are no more pending transmissions, cancel the watchdog
1550 * timer.
1551 */
1552 if (txs == NULL && (sc->sc_flags & TULIPF_DOING_SETUP) == 0)
1553 ifp->if_timer = 0;
1554
1555 /*
1556 * If we have a receive filter setup pending, do it now.
1557 */
1558 if (sc->sc_flags & TULIPF_WANT_SETUP)
1559 (*sc->sc_filter_setup)(sc);
1560 }
1561
1562 #ifdef TLP_STATS
1563 void
1564 tlp_print_stats(struct tulip_softc *sc)
1565 {
1566
1567 printf("%s: tx_uf %lu, tx_to %lu, tx_ec %lu, tx_lc %lu\n",
1568 sc->sc_dev.dv_xname,
1569 sc->sc_stats.ts_tx_uf, sc->sc_stats.ts_tx_to,
1570 sc->sc_stats.ts_tx_ec, sc->sc_stats.ts_tx_lc);
1571 }
1572 #endif
1573
1574 /*
1575 * tlp_reset:
1576 *
1577 * Perform a soft reset on the Tulip.
1578 */
1579 void
1580 tlp_reset(struct tulip_softc *sc)
1581 {
1582 int i;
1583
1584 TULIP_WRITE(sc, CSR_BUSMODE, BUSMODE_SWR);
1585
1586 /*
1587 * Xircom, ASIX and Conexant clones don't bring themselves
1588 * out of reset automatically.
1589 * Instead, we have to wait at least 50 PCI cycles, and then
1590 * clear SWR.
1591 */
1592 switch (sc->sc_chip) {
1593 case TULIP_CHIP_X3201_3:
1594 case TULIP_CHIP_AX88140:
1595 case TULIP_CHIP_AX88141:
1596 case TULIP_CHIP_RS7112:
1597 delay(10);
1598 TULIP_WRITE(sc, CSR_BUSMODE, 0);
1599 break;
1600 default:
1601 break;
1602 }
1603
1604 for (i = 0; i < 1000; i++) {
1605 /*
1606 * Wait at least 50 PCI cycles for the reset to
1607 * complete before peeking at the Tulip again.
1608 * 10 uSec is a bit longer than 50 PCI cycles
1609 * (at 33MHz), but it doesn't hurt have the extra
1610 * wait.
1611 */
1612 delay(10);
1613 if (TULIP_ISSET(sc, CSR_BUSMODE, BUSMODE_SWR) == 0)
1614 break;
1615 }
1616
1617 if (TULIP_ISSET(sc, CSR_BUSMODE, BUSMODE_SWR))
1618 printf("%s: reset failed to complete\n", sc->sc_dev.dv_xname);
1619
1620 delay(1000);
1621
1622 /*
1623 * If the board has any GPIO reset sequences to issue, do them now.
1624 */
1625 if (sc->sc_reset != NULL)
1626 (*sc->sc_reset)(sc);
1627 }
1628
1629 /*
1630 * tlp_init: [ ifnet interface function ]
1631 *
1632 * Initialize the interface. Must be called at splnet().
1633 */
1634 static int
1635 tlp_init(struct ifnet *ifp)
1636 {
1637 struct tulip_softc *sc = ifp->if_softc;
1638 struct tulip_txsoft *txs;
1639 struct tulip_rxsoft *rxs;
1640 int i, error = 0;
1641
1642 if ((error = tlp_enable(sc)) != 0)
1643 goto out;
1644
1645 /*
1646 * Cancel any pending I/O.
1647 */
1648 tlp_stop(ifp, 0);
1649
1650 /*
1651 * Initialize `opmode' to 0, and call the pre-init routine, if
1652 * any. This is required because the 2114x and some of the
1653 * clones require that the media-related bits in `opmode' be
1654 * set before performing a soft-reset in order to get internal
1655 * chip pathways are correct. Yay!
1656 */
1657 sc->sc_opmode = 0;
1658 if (sc->sc_preinit != NULL)
1659 (*sc->sc_preinit)(sc);
1660
1661 /*
1662 * Reset the Tulip to a known state.
1663 */
1664 tlp_reset(sc);
1665
1666 /*
1667 * Initialize the BUSMODE register.
1668 */
1669 sc->sc_busmode = BUSMODE_BAR;
1670 switch (sc->sc_chip) {
1671 case TULIP_CHIP_21140:
1672 case TULIP_CHIP_21140A:
1673 case TULIP_CHIP_21142:
1674 case TULIP_CHIP_21143:
1675 case TULIP_CHIP_82C115:
1676 case TULIP_CHIP_MX98725:
1677 /*
1678 * If we're allowed to do so, use Memory Read Line
1679 * and Memory Read Multiple.
1680 *
1681 * XXX Should we use Memory Write and Invalidate?
1682 */
1683 if (sc->sc_flags & TULIPF_MRL)
1684 sc->sc_busmode |= BUSMODE_RLE;
1685 if (sc->sc_flags & TULIPF_MRM)
1686 sc->sc_busmode |= BUSMODE_RME;
1687 #if 0
1688 if (sc->sc_flags & TULIPF_MWI)
1689 sc->sc_busmode |= BUSMODE_WLE;
1690 #endif
1691 break;
1692
1693 case TULIP_CHIP_82C168:
1694 case TULIP_CHIP_82C169:
1695 sc->sc_busmode |= BUSMODE_PNIC_MBO;
1696 if (sc->sc_maxburst == 0)
1697 sc->sc_maxburst = 16;
1698 break;
1699
1700 case TULIP_CHIP_AX88140:
1701 case TULIP_CHIP_AX88141:
1702 if (sc->sc_maxburst == 0)
1703 sc->sc_maxburst = 16;
1704 break;
1705
1706 default:
1707 /* Nothing. */
1708 break;
1709 }
1710 switch (sc->sc_cacheline) {
1711 default:
1712 /*
1713 * Note: We must *always* set these bits; a cache
1714 * alignment of 0 is RESERVED.
1715 */
1716 case 8:
1717 sc->sc_busmode |= BUSMODE_CAL_8LW;
1718 break;
1719 case 16:
1720 sc->sc_busmode |= BUSMODE_CAL_16LW;
1721 break;
1722 case 32:
1723 sc->sc_busmode |= BUSMODE_CAL_32LW;
1724 break;
1725 }
1726 switch (sc->sc_maxburst) {
1727 case 1:
1728 sc->sc_busmode |= BUSMODE_PBL_1LW;
1729 break;
1730 case 2:
1731 sc->sc_busmode |= BUSMODE_PBL_2LW;
1732 break;
1733 case 4:
1734 sc->sc_busmode |= BUSMODE_PBL_4LW;
1735 break;
1736 case 8:
1737 sc->sc_busmode |= BUSMODE_PBL_8LW;
1738 break;
1739 case 16:
1740 sc->sc_busmode |= BUSMODE_PBL_16LW;
1741 break;
1742 case 32:
1743 sc->sc_busmode |= BUSMODE_PBL_32LW;
1744 break;
1745 default:
1746 sc->sc_busmode |= BUSMODE_PBL_DEFAULT;
1747 break;
1748 }
1749 #if BYTE_ORDER == BIG_ENDIAN
1750 /*
1751 * Can't use BUSMODE_BLE or BUSMODE_DBO; not all chips
1752 * support them, and even on ones that do, it doesn't
1753 * always work. So we always access descriptors with
1754 * little endian via htole32/le32toh.
1755 */
1756 #endif
1757 /*
1758 * Big-endian bus requires BUSMODE_BLE anyway.
1759 * Also, BUSMODE_DBO is needed because we assume
1760 * descriptors are little endian.
1761 */
1762 if (sc->sc_flags & TULIPF_BLE)
1763 sc->sc_busmode |= BUSMODE_BLE;
1764 if (sc->sc_flags & TULIPF_DBO)
1765 sc->sc_busmode |= BUSMODE_DBO;
1766
1767 /*
1768 * Some chips have a broken bus interface.
1769 */
1770 switch (sc->sc_chip) {
1771 case TULIP_CHIP_DM9102:
1772 case TULIP_CHIP_DM9102A:
1773 sc->sc_busmode = 0;
1774 break;
1775
1776 default:
1777 /* Nothing. */
1778 break;
1779 }
1780
1781 TULIP_WRITE(sc, CSR_BUSMODE, sc->sc_busmode);
1782
1783 /*
1784 * Initialize the OPMODE register. We don't write it until
1785 * we're ready to begin the transmit and receive processes.
1786 *
1787 * Media-related OPMODE bits are set in the media callbacks
1788 * for each specific chip/board.
1789 */
1790 sc->sc_opmode |= OPMODE_SR | OPMODE_ST |
1791 sc->sc_txth[sc->sc_txthresh].txth_opmode;
1792
1793 /*
1794 * Magical mystery initialization on the Macronix chips.
1795 * The MX98713 uses its own magic value, the rest share
1796 * a common one.
1797 */
1798 switch (sc->sc_chip) {
1799 case TULIP_CHIP_MX98713:
1800 TULIP_WRITE(sc, CSR_PMAC_TOR, PMAC_TOR_98713);
1801 break;
1802
1803 case TULIP_CHIP_MX98713A:
1804 case TULIP_CHIP_MX98715:
1805 case TULIP_CHIP_MX98715A:
1806 case TULIP_CHIP_MX98715AEC_X:
1807 case TULIP_CHIP_MX98725:
1808 TULIP_WRITE(sc, CSR_PMAC_TOR, PMAC_TOR_98715);
1809 break;
1810
1811 default:
1812 /* Nothing. */
1813 break;
1814 }
1815
1816 /*
1817 * Initialize the transmit descriptor ring.
1818 */
1819 memset(sc->sc_txdescs, 0, sizeof(sc->sc_txdescs));
1820 for (i = 0; i < TULIP_NTXDESC; i++) {
1821 sc->sc_txdescs[i].td_ctl = htole32(sc->sc_tdctl_ch);
1822 sc->sc_txdescs[i].td_bufaddr2 =
1823 htole32(TULIP_CDTXADDR(sc, TULIP_NEXTTX(i)));
1824 }
1825 sc->sc_txdescs[TULIP_NTXDESC - 1].td_ctl |= htole32(sc->sc_tdctl_er);
1826 TULIP_CDTXSYNC(sc, 0, TULIP_NTXDESC,
1827 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
1828 sc->sc_txfree = TULIP_NTXDESC;
1829 sc->sc_txnext = 0;
1830
1831 /*
1832 * Initialize the transmit job descriptors.
1833 */
1834 SIMPLEQ_INIT(&sc->sc_txfreeq);
1835 SIMPLEQ_INIT(&sc->sc_txdirtyq);
1836 for (i = 0; i < TULIP_TXQUEUELEN; i++) {
1837 txs = &sc->sc_txsoft[i];
1838 txs->txs_mbuf = NULL;
1839 SIMPLEQ_INSERT_TAIL(&sc->sc_txfreeq, txs, txs_q);
1840 }
1841
1842 /*
1843 * Initialize the receive descriptor and receive job
1844 * descriptor rings.
1845 */
1846 for (i = 0; i < TULIP_NRXDESC; i++) {
1847 rxs = &sc->sc_rxsoft[i];
1848 if (rxs->rxs_mbuf == NULL) {
1849 if ((error = tlp_add_rxbuf(sc, i)) != 0) {
1850 printf("%s: unable to allocate or map rx "
1851 "buffer %d, error = %d\n",
1852 sc->sc_dev.dv_xname, i, error);
1853 /*
1854 * XXX Should attempt to run with fewer receive
1855 * XXX buffers instead of just failing.
1856 */
1857 tlp_rxdrain(sc);
1858 goto out;
1859 }
1860 } else
1861 TULIP_INIT_RXDESC(sc, i);
1862 }
1863 sc->sc_rxptr = 0;
1864
1865 /*
1866 * Initialize the interrupt mask and enable interrupts.
1867 */
1868 /* normal interrupts */
1869 sc->sc_inten = STATUS_TI | STATUS_TU | STATUS_RI | STATUS_NIS;
1870
1871 /* abnormal interrupts */
1872 sc->sc_inten |= STATUS_TPS | STATUS_TJT | STATUS_UNF |
1873 STATUS_RU | STATUS_RPS | STATUS_RWT | STATUS_SE | STATUS_AIS;
1874
1875 sc->sc_rxint_mask = STATUS_RI|STATUS_RU|STATUS_RWT;
1876 sc->sc_txint_mask = STATUS_TI|STATUS_UNF|STATUS_TJT;
1877
1878 switch (sc->sc_chip) {
1879 case TULIP_CHIP_WB89C840F:
1880 /*
1881 * Clear bits that we don't want that happen to
1882 * overlap or don't exist.
1883 */
1884 sc->sc_inten &= ~(STATUS_WINB_REI|STATUS_RWT);
1885 break;
1886
1887 default:
1888 /* Nothing. */
1889 break;
1890 }
1891
1892 sc->sc_rxint_mask &= sc->sc_inten;
1893 sc->sc_txint_mask &= sc->sc_inten;
1894
1895 TULIP_WRITE(sc, CSR_INTEN, sc->sc_inten);
1896 TULIP_WRITE(sc, CSR_STATUS, 0xffffffff);
1897
1898 /*
1899 * Give the transmit and receive rings to the Tulip.
1900 */
1901 TULIP_WRITE(sc, CSR_TXLIST, TULIP_CDTXADDR(sc, sc->sc_txnext));
1902 TULIP_WRITE(sc, CSR_RXLIST, TULIP_CDRXADDR(sc, sc->sc_rxptr));
1903
1904 /*
1905 * On chips that do this differently, set the station address.
1906 */
1907 switch (sc->sc_chip) {
1908 case TULIP_CHIP_WB89C840F:
1909 {
1910 /* XXX Do this with stream writes? */
1911 bus_addr_t cpa = TULIP_CSR_OFFSET(sc, CSR_WINB_CPA0);
1912
1913 for (i = 0; i < ETHER_ADDR_LEN; i++) {
1914 bus_space_write_1(sc->sc_st, sc->sc_sh,
1915 cpa + i, LLADDR(ifp->if_sadl)[i]);
1916 }
1917 break;
1918 }
1919
1920 case TULIP_CHIP_AL981:
1921 case TULIP_CHIP_AN983:
1922 case TULIP_CHIP_AN985:
1923 {
1924 u_int32_t reg;
1925 u_int8_t *enaddr = LLADDR(ifp->if_sadl);
1926
1927 reg = enaddr[0] |
1928 (enaddr[1] << 8) |
1929 (enaddr[2] << 16) |
1930 (enaddr[3] << 24);
1931 bus_space_write_4(sc->sc_st, sc->sc_sh, CSR_ADM_PAR0, reg);
1932
1933 reg = enaddr[4] |
1934 (enaddr[5] << 8);
1935 bus_space_write_4(sc->sc_st, sc->sc_sh, CSR_ADM_PAR1, reg);
1936 break;
1937 }
1938
1939 case TULIP_CHIP_AX88140:
1940 case TULIP_CHIP_AX88141:
1941 {
1942 u_int32_t reg;
1943 u_int8_t *enaddr = LLADDR(ifp->if_sadl);
1944
1945 reg = enaddr[0] |
1946 (enaddr[1] << 8) |
1947 (enaddr[2] << 16) |
1948 (enaddr[3] << 24);
1949 TULIP_WRITE(sc, CSR_AX_FILTIDX, AX_FILTIDX_PAR0);
1950 TULIP_WRITE(sc, CSR_AX_FILTDATA, reg);
1951
1952 reg = enaddr[4] | (enaddr[5] << 8);
1953 TULIP_WRITE(sc, CSR_AX_FILTIDX, AX_FILTIDX_PAR1);
1954 TULIP_WRITE(sc, CSR_AX_FILTDATA, reg);
1955 break;
1956 }
1957
1958 default:
1959 /* Nothing. */
1960 break;
1961 }
1962
1963 /*
1964 * Set the receive filter. This will start the transmit and
1965 * receive processes.
1966 */
1967 (*sc->sc_filter_setup)(sc);
1968
1969 /*
1970 * Set the current media.
1971 */
1972 (void) (*sc->sc_mediasw->tmsw_set)(sc);
1973
1974 /*
1975 * Start the receive process.
1976 */
1977 TULIP_WRITE(sc, CSR_RXPOLL, RXPOLL_RPD);
1978
1979 if (sc->sc_tick != NULL) {
1980 /* Start the one second clock. */
1981 callout_reset(&sc->sc_tick_callout, hz >> 3, sc->sc_tick, sc);
1982 }
1983
1984 /*
1985 * Note that the interface is now running.
1986 */
1987 ifp->if_flags |= IFF_RUNNING;
1988 ifp->if_flags &= ~IFF_OACTIVE;
1989 sc->sc_if_flags = ifp->if_flags;
1990
1991 out:
1992 if (error) {
1993 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1994 ifp->if_timer = 0;
1995 printf("%s: interface not running\n", sc->sc_dev.dv_xname);
1996 }
1997 return (error);
1998 }
1999
2000 /*
2001 * tlp_enable:
2002 *
2003 * Enable the Tulip chip.
2004 */
2005 static int
2006 tlp_enable(struct tulip_softc *sc)
2007 {
2008
2009 if (TULIP_IS_ENABLED(sc) == 0 && sc->sc_enable != NULL) {
2010 if ((*sc->sc_enable)(sc) != 0) {
2011 printf("%s: device enable failed\n",
2012 sc->sc_dev.dv_xname);
2013 return (EIO);
2014 }
2015 sc->sc_flags |= TULIPF_ENABLED;
2016 }
2017 return (0);
2018 }
2019
2020 /*
2021 * tlp_disable:
2022 *
2023 * Disable the Tulip chip.
2024 */
2025 static void
2026 tlp_disable(struct tulip_softc *sc)
2027 {
2028
2029 if (TULIP_IS_ENABLED(sc) && sc->sc_disable != NULL) {
2030 (*sc->sc_disable)(sc);
2031 sc->sc_flags &= ~TULIPF_ENABLED;
2032 }
2033 }
2034
2035 /*
2036 * tlp_power:
2037 *
2038 * Power management (suspend/resume) hook.
2039 */
2040 static void
2041 tlp_power(int why, void *arg)
2042 {
2043 struct tulip_softc *sc = arg;
2044 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
2045 int s;
2046
2047 s = splnet();
2048 switch (why) {
2049 case PWR_STANDBY:
2050 /* do nothing! */
2051 break;
2052 case PWR_SUSPEND:
2053 tlp_stop(ifp, 0);
2054 if (sc->sc_power != NULL)
2055 (*sc->sc_power)(sc, why);
2056 break;
2057 case PWR_RESUME:
2058 if (ifp->if_flags & IFF_UP) {
2059 if (sc->sc_power != NULL)
2060 (*sc->sc_power)(sc, why);
2061 tlp_init(ifp);
2062 }
2063 break;
2064 case PWR_SOFTSUSPEND:
2065 case PWR_SOFTSTANDBY:
2066 case PWR_SOFTRESUME:
2067 break;
2068 }
2069 splx(s);
2070 }
2071
2072 /*
2073 * tlp_rxdrain:
2074 *
2075 * Drain the receive queue.
2076 */
2077 static void
2078 tlp_rxdrain(struct tulip_softc *sc)
2079 {
2080 struct tulip_rxsoft *rxs;
2081 int i;
2082
2083 for (i = 0; i < TULIP_NRXDESC; i++) {
2084 rxs = &sc->sc_rxsoft[i];
2085 if (rxs->rxs_mbuf != NULL) {
2086 bus_dmamap_unload(sc->sc_dmat, rxs->rxs_dmamap);
2087 m_freem(rxs->rxs_mbuf);
2088 rxs->rxs_mbuf = NULL;
2089 }
2090 }
2091 }
2092
2093 /*
2094 * tlp_stop: [ ifnet interface function ]
2095 *
2096 * Stop transmission on the interface.
2097 */
2098 static void
2099 tlp_stop(struct ifnet *ifp, int disable)
2100 {
2101 struct tulip_softc *sc = ifp->if_softc;
2102 struct tulip_txsoft *txs;
2103
2104 if (sc->sc_tick != NULL) {
2105 /* Stop the one second clock. */
2106 callout_stop(&sc->sc_tick_callout);
2107 }
2108
2109 if (sc->sc_flags & TULIPF_HAS_MII) {
2110 /* Down the MII. */
2111 mii_down(&sc->sc_mii);
2112 }
2113
2114 /* Disable interrupts. */
2115 TULIP_WRITE(sc, CSR_INTEN, 0);
2116
2117 /* Stop the transmit and receive processes. */
2118 sc->sc_opmode = 0;
2119 TULIP_WRITE(sc, CSR_OPMODE, 0);
2120 TULIP_WRITE(sc, CSR_RXLIST, 0);
2121 TULIP_WRITE(sc, CSR_TXLIST, 0);
2122
2123 /*
2124 * Release any queued transmit buffers.
2125 */
2126 while ((txs = SIMPLEQ_FIRST(&sc->sc_txdirtyq)) != NULL) {
2127 SIMPLEQ_REMOVE_HEAD(&sc->sc_txdirtyq, txs_q);
2128 if (txs->txs_mbuf != NULL) {
2129 bus_dmamap_unload(sc->sc_dmat, txs->txs_dmamap);
2130 m_freem(txs->txs_mbuf);
2131 txs->txs_mbuf = NULL;
2132 }
2133 SIMPLEQ_INSERT_TAIL(&sc->sc_txfreeq, txs, txs_q);
2134 }
2135
2136 if (disable) {
2137 tlp_rxdrain(sc);
2138 tlp_disable(sc);
2139 }
2140
2141 sc->sc_flags &= ~(TULIPF_WANT_SETUP|TULIPF_DOING_SETUP);
2142
2143 /*
2144 * Mark the interface down and cancel the watchdog timer.
2145 */
2146 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
2147 sc->sc_if_flags = ifp->if_flags;
2148 ifp->if_timer = 0;
2149
2150 /*
2151 * Reset the chip (needed on some flavors to actually disable it).
2152 */
2153 tlp_reset(sc);
2154 }
2155
2156 #define SROM_EMIT(sc, x) \
2157 do { \
2158 TULIP_WRITE((sc), CSR_MIIROM, (x)); \
2159 delay(2); \
2160 } while (0)
2161
2162 /*
2163 * tlp_srom_idle:
2164 *
2165 * Put the SROM in idle state.
2166 */
2167 static void
2168 tlp_srom_idle(struct tulip_softc *sc)
2169 {
2170 u_int32_t miirom;
2171 int i;
2172
2173 miirom = MIIROM_SR;
2174 SROM_EMIT(sc, miirom);
2175
2176 miirom |= MIIROM_RD;
2177 SROM_EMIT(sc, miirom);
2178
2179 miirom |= MIIROM_SROMCS;
2180 SROM_EMIT(sc, miirom);
2181
2182 SROM_EMIT(sc, miirom|MIIROM_SROMSK);
2183
2184 /* Strobe the clock 32 times. */
2185 for (i = 0; i < 32; i++) {
2186 SROM_EMIT(sc, miirom);
2187 SROM_EMIT(sc, miirom|MIIROM_SROMSK);
2188 }
2189
2190 SROM_EMIT(sc, miirom);
2191
2192 miirom &= ~MIIROM_SROMCS;
2193 SROM_EMIT(sc, miirom);
2194
2195 SROM_EMIT(sc, 0);
2196 }
2197
2198 /*
2199 * tlp_srom_size:
2200 *
2201 * Determine the number of address bits in the SROM.
2202 */
2203 static int
2204 tlp_srom_size(struct tulip_softc *sc)
2205 {
2206 u_int32_t miirom;
2207 int x;
2208
2209 /* Select the SROM. */
2210 miirom = MIIROM_SR;
2211 SROM_EMIT(sc, miirom);
2212
2213 miirom |= MIIROM_RD;
2214 SROM_EMIT(sc, miirom);
2215
2216 /* Send CHIP SELECT for one clock tick. */
2217 miirom |= MIIROM_SROMCS;
2218 SROM_EMIT(sc, miirom);
2219
2220 /* Shift in the READ opcode. */
2221 for (x = 3; x > 0; x--) {
2222 if (TULIP_SROM_OPC_READ & (1 << (x - 1)))
2223 miirom |= MIIROM_SROMDI;
2224 else
2225 miirom &= ~MIIROM_SROMDI;
2226 SROM_EMIT(sc, miirom);
2227 SROM_EMIT(sc, miirom|MIIROM_SROMSK);
2228 SROM_EMIT(sc, miirom);
2229 }
2230
2231 /* Shift in address and look for dummy 0 bit. */
2232 for (x = 1; x <= 12; x++) {
2233 miirom &= ~MIIROM_SROMDI;
2234 SROM_EMIT(sc, miirom);
2235 SROM_EMIT(sc, miirom|MIIROM_SROMSK);
2236 if (!TULIP_ISSET(sc, CSR_MIIROM, MIIROM_SROMDO))
2237 break;
2238 SROM_EMIT(sc, miirom);
2239 }
2240
2241 /* Clear CHIP SELECT. */
2242 miirom &= ~MIIROM_SROMCS;
2243 SROM_EMIT(sc, miirom);
2244
2245 /* Deselect the SROM. */
2246 SROM_EMIT(sc, 0);
2247
2248 if (x < 4 || x > 12) {
2249 printf("%s: broken MicroWire interface detected; "
2250 "setting SROM size to 1Kb\n", sc->sc_dev.dv_xname);
2251 return (6);
2252 } else {
2253 if (tlp_srom_debug)
2254 printf("%s: SROM size is 2^%d*16 bits (%d bytes)\n",
2255 sc->sc_dev.dv_xname, x, (1 << (x + 4)) >> 3);
2256 return (x);
2257 }
2258 }
2259
2260 /*
2261 * tlp_read_srom:
2262 *
2263 * Read the Tulip SROM.
2264 */
2265 int
2266 tlp_read_srom(struct tulip_softc *sc)
2267 {
2268 int size;
2269 u_int32_t miirom;
2270 u_int16_t datain;
2271 int i, x;
2272
2273 tlp_srom_idle(sc);
2274
2275 sc->sc_srom_addrbits = tlp_srom_size(sc);
2276 if (sc->sc_srom_addrbits == 0)
2277 return (0);
2278 size = TULIP_ROM_SIZE(sc->sc_srom_addrbits);
2279 sc->sc_srom = malloc(size, M_DEVBUF, M_NOWAIT);
2280
2281 /* Select the SROM. */
2282 miirom = MIIROM_SR;
2283 SROM_EMIT(sc, miirom);
2284
2285 miirom |= MIIROM_RD;
2286 SROM_EMIT(sc, miirom);
2287
2288 for (i = 0; i < size; i += 2) {
2289 /* Send CHIP SELECT for one clock tick. */
2290 miirom |= MIIROM_SROMCS;
2291 SROM_EMIT(sc, miirom);
2292
2293 /* Shift in the READ opcode. */
2294 for (x = 3; x > 0; x--) {
2295 if (TULIP_SROM_OPC_READ & (1 << (x - 1)))
2296 miirom |= MIIROM_SROMDI;
2297 else
2298 miirom &= ~MIIROM_SROMDI;
2299 SROM_EMIT(sc, miirom);
2300 SROM_EMIT(sc, miirom|MIIROM_SROMSK);
2301 SROM_EMIT(sc, miirom);
2302 }
2303
2304 /* Shift in address. */
2305 for (x = sc->sc_srom_addrbits; x > 0; x--) {
2306 if (i & (1 << x))
2307 miirom |= MIIROM_SROMDI;
2308 else
2309 miirom &= ~MIIROM_SROMDI;
2310 SROM_EMIT(sc, miirom);
2311 SROM_EMIT(sc, miirom|MIIROM_SROMSK);
2312 SROM_EMIT(sc, miirom);
2313 }
2314
2315 /* Shift out data. */
2316 miirom &= ~MIIROM_SROMDI;
2317 datain = 0;
2318 for (x = 16; x > 0; x--) {
2319 SROM_EMIT(sc, miirom|MIIROM_SROMSK);
2320 if (TULIP_ISSET(sc, CSR_MIIROM, MIIROM_SROMDO))
2321 datain |= (1 << (x - 1));
2322 SROM_EMIT(sc, miirom);
2323 }
2324 sc->sc_srom[i] = datain & 0xff;
2325 sc->sc_srom[i + 1] = datain >> 8;
2326
2327 /* Clear CHIP SELECT. */
2328 miirom &= ~MIIROM_SROMCS;
2329 SROM_EMIT(sc, miirom);
2330 }
2331
2332 /* Deselect the SROM. */
2333 SROM_EMIT(sc, 0);
2334
2335 /* ...and idle it. */
2336 tlp_srom_idle(sc);
2337
2338 if (tlp_srom_debug) {
2339 printf("SROM CONTENTS:");
2340 for (i = 0; i < size; i++) {
2341 if ((i % 8) == 0)
2342 printf("\n\t");
2343 printf("0x%02x ", sc->sc_srom[i]);
2344 }
2345 printf("\n");
2346 }
2347
2348 return (1);
2349 }
2350
2351 #undef SROM_EMIT
2352
2353 /*
2354 * tlp_add_rxbuf:
2355 *
2356 * Add a receive buffer to the indicated descriptor.
2357 */
2358 static int
2359 tlp_add_rxbuf(struct tulip_softc *sc, int idx)
2360 {
2361 struct tulip_rxsoft *rxs = &sc->sc_rxsoft[idx];
2362 struct mbuf *m;
2363 int error;
2364
2365 MGETHDR(m, M_DONTWAIT, MT_DATA);
2366 if (m == NULL)
2367 return (ENOBUFS);
2368
2369 MCLAIM(m, &sc->sc_ethercom.ec_rx_mowner);
2370 MCLGET(m, M_DONTWAIT);
2371 if ((m->m_flags & M_EXT) == 0) {
2372 m_freem(m);
2373 return (ENOBUFS);
2374 }
2375
2376 if (rxs->rxs_mbuf != NULL)
2377 bus_dmamap_unload(sc->sc_dmat, rxs->rxs_dmamap);
2378
2379 rxs->rxs_mbuf = m;
2380
2381 error = bus_dmamap_load(sc->sc_dmat, rxs->rxs_dmamap,
2382 m->m_ext.ext_buf, m->m_ext.ext_size, NULL,
2383 BUS_DMA_READ|BUS_DMA_NOWAIT);
2384 if (error) {
2385 printf("%s: can't load rx DMA map %d, error = %d\n",
2386 sc->sc_dev.dv_xname, idx, error);
2387 panic("tlp_add_rxbuf"); /* XXX */
2388 }
2389
2390 bus_dmamap_sync(sc->sc_dmat, rxs->rxs_dmamap, 0,
2391 rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_PREREAD);
2392
2393 TULIP_INIT_RXDESC(sc, idx);
2394
2395 return (0);
2396 }
2397
2398 /*
2399 * tlp_srom_crcok:
2400 *
2401 * Check the CRC of the Tulip SROM.
2402 */
2403 int
2404 tlp_srom_crcok(const u_int8_t *romdata)
2405 {
2406 u_int32_t crc;
2407
2408 crc = ether_crc32_le(romdata, TULIP_ROM_CRC32_CHECKSUM);
2409 crc = (crc & 0xffff) ^ 0xffff;
2410 if (crc == TULIP_ROM_GETW(romdata, TULIP_ROM_CRC32_CHECKSUM))
2411 return (1);
2412
2413 /*
2414 * Try an alternate checksum.
2415 */
2416 crc = ether_crc32_le(romdata, TULIP_ROM_CRC32_CHECKSUM1);
2417 crc = (crc & 0xffff) ^ 0xffff;
2418 if (crc == TULIP_ROM_GETW(romdata, TULIP_ROM_CRC32_CHECKSUM1))
2419 return (1);
2420
2421 return (0);
2422 }
2423
2424 /*
2425 * tlp_isv_srom:
2426 *
2427 * Check to see if the SROM is in the new standardized format.
2428 */
2429 int
2430 tlp_isv_srom(const u_int8_t *romdata)
2431 {
2432 int i;
2433 u_int16_t cksum;
2434
2435 if (tlp_srom_crcok(romdata)) {
2436 /*
2437 * SROM CRC checks out; must be in the new format.
2438 */
2439 return (1);
2440 }
2441
2442 cksum = TULIP_ROM_GETW(romdata, TULIP_ROM_CRC32_CHECKSUM);
2443 if (cksum == 0xffff || cksum == 0) {
2444 /*
2445 * No checksum present. Check the SROM ID; 18 bytes of 0
2446 * followed by 1 (version) followed by the number of
2447 * adapters which use this SROM (should be non-zero).
2448 */
2449 for (i = 0; i < TULIP_ROM_SROM_FORMAT_VERION; i++) {
2450 if (romdata[i] != 0)
2451 return (0);
2452 }
2453 if (romdata[TULIP_ROM_SROM_FORMAT_VERION] != 1)
2454 return (0);
2455 if (romdata[TULIP_ROM_CHIP_COUNT] == 0)
2456 return (0);
2457 return (1);
2458 }
2459
2460 return (0);
2461 }
2462
2463 /*
2464 * tlp_isv_srom_enaddr:
2465 *
2466 * Get the Ethernet address from an ISV SROM.
2467 */
2468 int
2469 tlp_isv_srom_enaddr(struct tulip_softc *sc, u_int8_t *enaddr)
2470 {
2471 int i, devcnt;
2472
2473 if (tlp_isv_srom(sc->sc_srom) == 0)
2474 return (0);
2475
2476 devcnt = sc->sc_srom[TULIP_ROM_CHIP_COUNT];
2477 for (i = 0; i < devcnt; i++) {
2478 if (sc->sc_srom[TULIP_ROM_CHIP_COUNT] == 1)
2479 break;
2480 if (sc->sc_srom[TULIP_ROM_CHIPn_DEVICE_NUMBER(i)] ==
2481 sc->sc_devno)
2482 break;
2483 }
2484
2485 if (i == devcnt)
2486 return (0);
2487
2488 memcpy(enaddr, &sc->sc_srom[TULIP_ROM_IEEE_NETWORK_ADDRESS],
2489 ETHER_ADDR_LEN);
2490 enaddr[5] += i;
2491
2492 return (1);
2493 }
2494
2495 /*
2496 * tlp_parse_old_srom:
2497 *
2498 * Parse old-format SROMs.
2499 *
2500 * This routine is largely lifted from Matt Thomas's `de' driver.
2501 */
2502 int
2503 tlp_parse_old_srom(struct tulip_softc *sc, u_int8_t *enaddr)
2504 {
2505 static const u_int8_t testpat[] =
2506 { 0xff, 0, 0x55, 0xaa, 0xff, 0, 0x55, 0xaa };
2507 int i;
2508 u_int32_t cksum;
2509
2510 if (memcmp(&sc->sc_srom[0], &sc->sc_srom[16], 8) != 0) {
2511 /*
2512 * Phobos interfaces have the address at offsets 20
2513 * and 84, but each pair of bytes is swapped. The
2514 * first and last two bytes appear to contain
2515 * checksums. Everything else is 0.
2516 */
2517 if (sc->sc_srom_addrbits == 6 &&
2518 sc->sc_srom[21] == 0x00 &&
2519 sc->sc_srom[20] == 0x60 &&
2520 sc->sc_srom[23] == 0xf5 &&
2521 memcmp(&sc->sc_srom[20], &sc->sc_srom[84], 6) == 0) {
2522 for (i = 0; i < 6; i += 2) {
2523 enaddr[i] = sc->sc_srom[20 + i + 1];
2524 enaddr[i + 1] = sc->sc_srom[20 + i];
2525 }
2526 return (1);
2527 }
2528
2529 /*
2530 * Cobalt Networks interfaces simply have the address
2531 * in the first six bytes. The rest is zeroed out
2532 * on some models, but others contain unknown data.
2533 */
2534 if (sc->sc_srom[0] == 0x00 &&
2535 sc->sc_srom[1] == 0x10 &&
2536 sc->sc_srom[2] == 0xe0) {
2537 memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
2538 return (1);
2539 }
2540
2541 /*
2542 * Some vendors (e.g. ZNYX) don't use the standard
2543 * DEC Address ROM format, but rather just have an
2544 * Ethernet address in the first 6 bytes, maybe a
2545 * 2 byte checksum, and then all 0xff's.
2546 */
2547 for (i = 8; i < 32; i++) {
2548 if (sc->sc_srom[i] != 0xff &&
2549 sc->sc_srom[i] != 0)
2550 return (0);
2551 }
2552
2553 /*
2554 * Sanity check the Ethernet address:
2555 *
2556 * - Make sure it's not multicast or locally
2557 * assigned
2558 * - Make sure it has a non-0 OUI
2559 */
2560 if (sc->sc_srom[0] & 3)
2561 return (0);
2562 if (sc->sc_srom[0] == 0 && sc->sc_srom[1] == 0 &&
2563 sc->sc_srom[2] == 0)
2564 return (0);
2565
2566 memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
2567 return (1);
2568 }
2569
2570 /*
2571 * Standard DEC Address ROM test.
2572 */
2573
2574 if (memcmp(&sc->sc_srom[24], testpat, 8) != 0)
2575 return (0);
2576
2577 for (i = 0; i < 8; i++) {
2578 if (sc->sc_srom[i] != sc->sc_srom[15 - i])
2579 return (0);
2580 }
2581
2582 memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
2583
2584 cksum = *(u_int16_t *) &enaddr[0];
2585
2586 cksum <<= 1;
2587 if (cksum > 0xffff)
2588 cksum -= 0xffff;
2589
2590 cksum += *(u_int16_t *) &enaddr[2];
2591 if (cksum > 0xffff)
2592 cksum -= 0xffff;
2593
2594 cksum <<= 1;
2595 if (cksum > 0xffff)
2596 cksum -= 0xffff;
2597
2598 cksum += *(u_int16_t *) &enaddr[4];
2599 if (cksum >= 0xffff)
2600 cksum -= 0xffff;
2601
2602 if (cksum != *(u_int16_t *) &sc->sc_srom[6])
2603 return (0);
2604
2605 return (1);
2606 }
2607
2608 /*
2609 * tlp_filter_setup:
2610 *
2611 * Set the Tulip's receive filter.
2612 */
2613 static void
2614 tlp_filter_setup(struct tulip_softc *sc)
2615 {
2616 struct ethercom *ec = &sc->sc_ethercom;
2617 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
2618 struct ether_multi *enm;
2619 struct ether_multistep step;
2620 volatile u_int32_t *sp;
2621 struct tulip_txsoft *txs;
2622 u_int8_t enaddr[ETHER_ADDR_LEN];
2623 u_int32_t hash, hashsize;
2624 int cnt, nexttx;
2625
2626 DPRINTF(sc, ("%s: tlp_filter_setup: sc_flags 0x%08x\n",
2627 sc->sc_dev.dv_xname, sc->sc_flags));
2628
2629 memcpy(enaddr, LLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
2630
2631 /*
2632 * If there are transmissions pending, wait until they have
2633 * completed.
2634 */
2635 if (! SIMPLEQ_EMPTY(&sc->sc_txdirtyq) ||
2636 (sc->sc_flags & TULIPF_DOING_SETUP) != 0) {
2637 sc->sc_flags |= TULIPF_WANT_SETUP;
2638 DPRINTF(sc, ("%s: tlp_filter_setup: deferring\n",
2639 sc->sc_dev.dv_xname));
2640 return;
2641 }
2642 sc->sc_flags &= ~TULIPF_WANT_SETUP;
2643
2644 switch (sc->sc_chip) {
2645 case TULIP_CHIP_82C115:
2646 hashsize = TULIP_PNICII_HASHSIZE;
2647 break;
2648
2649 default:
2650 hashsize = TULIP_MCHASHSIZE;
2651 }
2652
2653 /*
2654 * If we're running, idle the transmit and receive engines. If
2655 * we're NOT running, we're being called from tlp_init(), and our
2656 * writing OPMODE will start the transmit and receive processes
2657 * in motion.
2658 */
2659 if (ifp->if_flags & IFF_RUNNING)
2660 tlp_idle(sc, OPMODE_ST|OPMODE_SR);
2661
2662 sc->sc_opmode &= ~(OPMODE_PR|OPMODE_PM);
2663
2664 if (ifp->if_flags & IFF_PROMISC) {
2665 sc->sc_opmode |= OPMODE_PR;
2666 goto allmulti;
2667 }
2668
2669 /*
2670 * Try Perfect filtering first.
2671 */
2672
2673 sc->sc_filtmode = TDCTL_Tx_FT_PERFECT;
2674 sp = TULIP_CDSP(sc);
2675 memset(TULIP_CDSP(sc), 0, TULIP_SETUP_PACKET_LEN);
2676 cnt = 0;
2677 ETHER_FIRST_MULTI(step, ec, enm);
2678 while (enm != NULL) {
2679 if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
2680 /*
2681 * We must listen to a range of multicast addresses.
2682 * For now, just accept all multicasts, rather than
2683 * trying to set only those filter bits needed to match
2684 * the range. (At this time, the only use of address
2685 * ranges is for IP multicast routing, for which the
2686 * range is big enough to require all bits set.)
2687 */
2688 goto allmulti;
2689 }
2690 if (cnt == (TULIP_MAXADDRS - 2)) {
2691 /*
2692 * We already have our multicast limit (still need
2693 * our station address and broadcast). Go to
2694 * Hash-Perfect mode.
2695 */
2696 goto hashperfect;
2697 }
2698 cnt++;
2699 *sp++ = TULIP_SP_FIELD(enm->enm_addrlo, 0);
2700 *sp++ = TULIP_SP_FIELD(enm->enm_addrlo, 1);
2701 *sp++ = TULIP_SP_FIELD(enm->enm_addrlo, 2);
2702 ETHER_NEXT_MULTI(step, enm);
2703 }
2704
2705 if (ifp->if_flags & IFF_BROADCAST) {
2706 /* ...and the broadcast address. */
2707 cnt++;
2708 *sp++ = TULIP_SP_FIELD_C(0xffff);
2709 *sp++ = TULIP_SP_FIELD_C(0xffff);
2710 *sp++ = TULIP_SP_FIELD_C(0xffff);
2711 }
2712
2713 /* Pad the rest with our station address. */
2714 for (; cnt < TULIP_MAXADDRS; cnt++) {
2715 *sp++ = TULIP_SP_FIELD(enaddr, 0);
2716 *sp++ = TULIP_SP_FIELD(enaddr, 1);
2717 *sp++ = TULIP_SP_FIELD(enaddr, 2);
2718 }
2719 ifp->if_flags &= ~IFF_ALLMULTI;
2720 goto setit;
2721
2722 hashperfect:
2723 /*
2724 * Try Hash-Perfect mode.
2725 */
2726
2727 /*
2728 * Some 21140 chips have broken Hash-Perfect modes. On these
2729 * chips, we simply use Hash-Only mode, and put our station
2730 * address into the filter.
2731 */
2732 if (sc->sc_chip == TULIP_CHIP_21140)
2733 sc->sc_filtmode = TDCTL_Tx_FT_HASHONLY;
2734 else
2735 sc->sc_filtmode = TDCTL_Tx_FT_HASH;
2736 sp = TULIP_CDSP(sc);
2737 memset(TULIP_CDSP(sc), 0, TULIP_SETUP_PACKET_LEN);
2738 ETHER_FIRST_MULTI(step, ec, enm);
2739 while (enm != NULL) {
2740 if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
2741 /*
2742 * We must listen to a range of multicast addresses.
2743 * For now, just accept all multicasts, rather than
2744 * trying to set only those filter bits needed to match
2745 * the range. (At this time, the only use of address
2746 * ranges is for IP multicast routing, for which the
2747 * range is big enough to require all bits set.)
2748 */
2749 goto allmulti;
2750 }
2751 hash = tlp_mchash(enm->enm_addrlo, hashsize);
2752 sp[hash >> 4] |= htole32(1 << (hash & 0xf));
2753 ETHER_NEXT_MULTI(step, enm);
2754 }
2755
2756 if (ifp->if_flags & IFF_BROADCAST) {
2757 /* ...and the broadcast address. */
2758 hash = tlp_mchash(etherbroadcastaddr, hashsize);
2759 sp[hash >> 4] |= htole32(1 << (hash & 0xf));
2760 }
2761
2762 if (sc->sc_filtmode == TDCTL_Tx_FT_HASHONLY) {
2763 /* ...and our station address. */
2764 hash = tlp_mchash(enaddr, hashsize);
2765 sp[hash >> 4] |= htole32(1 << (hash & 0xf));
2766 } else {
2767 /*
2768 * Hash-Perfect mode; put our station address after
2769 * the hash table.
2770 */
2771 sp[39] = TULIP_SP_FIELD(enaddr, 0);
2772 sp[40] = TULIP_SP_FIELD(enaddr, 1);
2773 sp[41] = TULIP_SP_FIELD(enaddr, 2);
2774 }
2775 ifp->if_flags &= ~IFF_ALLMULTI;
2776 goto setit;
2777
2778 allmulti:
2779 /*
2780 * Use Perfect filter mode. First address is the broadcast address,
2781 * and pad the rest with our station address. We'll set Pass-all-
2782 * multicast in OPMODE below.
2783 */
2784 sc->sc_filtmode = TDCTL_Tx_FT_PERFECT;
2785 sp = TULIP_CDSP(sc);
2786 memset(TULIP_CDSP(sc), 0, TULIP_SETUP_PACKET_LEN);
2787 cnt = 0;
2788 if (ifp->if_flags & IFF_BROADCAST) {
2789 cnt++;
2790 *sp++ = TULIP_SP_FIELD_C(0xffff);
2791 *sp++ = TULIP_SP_FIELD_C(0xffff);
2792 *sp++ = TULIP_SP_FIELD_C(0xffff);
2793 }
2794 for (; cnt < TULIP_MAXADDRS; cnt++) {
2795 *sp++ = TULIP_SP_FIELD(enaddr, 0);
2796 *sp++ = TULIP_SP_FIELD(enaddr, 1);
2797 *sp++ = TULIP_SP_FIELD(enaddr, 2);
2798 }
2799 ifp->if_flags |= IFF_ALLMULTI;
2800
2801 setit:
2802 if (ifp->if_flags & IFF_ALLMULTI)
2803 sc->sc_opmode |= OPMODE_PM;
2804
2805 /* Sync the setup packet buffer. */
2806 TULIP_CDSPSYNC(sc, BUS_DMASYNC_PREWRITE);
2807
2808 /*
2809 * Fill in the setup packet descriptor.
2810 */
2811 txs = SIMPLEQ_FIRST(&sc->sc_txfreeq);
2812
2813 txs->txs_firstdesc = sc->sc_txnext;
2814 txs->txs_lastdesc = sc->sc_txnext;
2815 txs->txs_ndescs = 1;
2816 txs->txs_mbuf = NULL;
2817
2818 nexttx = sc->sc_txnext;
2819 sc->sc_txdescs[nexttx].td_status = 0;
2820 sc->sc_txdescs[nexttx].td_bufaddr1 = htole32(TULIP_CDSPADDR(sc));
2821 sc->sc_txdescs[nexttx].td_ctl =
2822 htole32((TULIP_SETUP_PACKET_LEN << TDCTL_SIZE1_SHIFT) |
2823 sc->sc_filtmode | TDCTL_Tx_SET | sc->sc_setup_fsls |
2824 TDCTL_Tx_IC | sc->sc_tdctl_ch |
2825 (nexttx == (TULIP_NTXDESC - 1) ? sc->sc_tdctl_er : 0));
2826 TULIP_CDTXSYNC(sc, nexttx, 1,
2827 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
2828
2829 #ifdef TLP_DEBUG
2830 if (ifp->if_flags & IFF_DEBUG) {
2831 printf(" filter_setup %p transmit chain:\n", txs);
2832 printf(" descriptor %d:\n", nexttx);
2833 printf(" td_status: 0x%08x\n",
2834 le32toh(sc->sc_txdescs[nexttx].td_status));
2835 printf(" td_ctl: 0x%08x\n",
2836 le32toh(sc->sc_txdescs[nexttx].td_ctl));
2837 printf(" td_bufaddr1: 0x%08x\n",
2838 le32toh(sc->sc_txdescs[nexttx].td_bufaddr1));
2839 printf(" td_bufaddr2: 0x%08x\n",
2840 le32toh(sc->sc_txdescs[nexttx].td_bufaddr2));
2841 }
2842 #endif
2843
2844 sc->sc_txdescs[nexttx].td_status = htole32(TDSTAT_OWN);
2845 TULIP_CDTXSYNC(sc, nexttx, 1,
2846 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
2847
2848 /* Advance the tx pointer. */
2849 sc->sc_txfree -= 1;
2850 sc->sc_txnext = TULIP_NEXTTX(nexttx);
2851
2852 SIMPLEQ_REMOVE_HEAD(&sc->sc_txfreeq, txs_q);
2853 SIMPLEQ_INSERT_TAIL(&sc->sc_txdirtyq, txs, txs_q);
2854
2855 /*
2856 * Set the OPMODE register. This will also resume the
2857 * transmit process we idled above.
2858 */
2859 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
2860
2861 sc->sc_flags |= TULIPF_DOING_SETUP;
2862
2863 /*
2864 * Kick the transmitter; this will cause the Tulip to
2865 * read the setup descriptor.
2866 */
2867 /* XXX USE AUTOPOLLING? */
2868 TULIP_WRITE(sc, CSR_TXPOLL, TXPOLL_TPD);
2869
2870 /* Set up a watchdog timer in case the chip flakes out. */
2871 ifp->if_timer = 5;
2872
2873 DPRINTF(sc, ("%s: tlp_filter_setup: returning\n", sc->sc_dev.dv_xname));
2874 }
2875
2876 /*
2877 * tlp_winb_filter_setup:
2878 *
2879 * Set the Winbond 89C840F's receive filter.
2880 */
2881 static void
2882 tlp_winb_filter_setup(struct tulip_softc *sc)
2883 {
2884 struct ethercom *ec = &sc->sc_ethercom;
2885 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
2886 struct ether_multi *enm;
2887 struct ether_multistep step;
2888 u_int32_t hash, mchash[2];
2889
2890 DPRINTF(sc, ("%s: tlp_winb_filter_setup: sc_flags 0x%08x\n",
2891 sc->sc_dev.dv_xname, sc->sc_flags));
2892
2893 sc->sc_opmode &= ~(OPMODE_WINB_APP|OPMODE_WINB_AMP|OPMODE_WINB_ABP);
2894
2895 if (ifp->if_flags & IFF_MULTICAST)
2896 sc->sc_opmode |= OPMODE_WINB_AMP;
2897
2898 if (ifp->if_flags & IFF_BROADCAST)
2899 sc->sc_opmode |= OPMODE_WINB_ABP;
2900
2901 if (ifp->if_flags & IFF_PROMISC) {
2902 sc->sc_opmode |= OPMODE_WINB_APP;
2903 goto allmulti;
2904 }
2905
2906 mchash[0] = mchash[1] = 0;
2907
2908 ETHER_FIRST_MULTI(step, ec, enm);
2909 while (enm != NULL) {
2910 if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
2911 /*
2912 * We must listen to a range of multicast addresses.
2913 * For now, just accept all multicasts, rather than
2914 * trying to set only those filter bits needed to match
2915 * the range. (At this time, the only use of address
2916 * ranges is for IP multicast routing, for which the
2917 * range is big enough to require all bits set.)
2918 */
2919 goto allmulti;
2920 }
2921
2922 /*
2923 * According to the FreeBSD `wb' driver, yes, you
2924 * really do invert the hash.
2925 */
2926 hash =
2927 (~(ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26))
2928 & 0x3f;
2929 mchash[hash >> 5] |= 1 << (hash & 0x1f);
2930 ETHER_NEXT_MULTI(step, enm);
2931 }
2932 ifp->if_flags &= ~IFF_ALLMULTI;
2933 goto setit;
2934
2935 allmulti:
2936 ifp->if_flags |= IFF_ALLMULTI;
2937 mchash[0] = mchash[1] = 0xffffffff;
2938
2939 setit:
2940 TULIP_WRITE(sc, CSR_WINB_CMA0, mchash[0]);
2941 TULIP_WRITE(sc, CSR_WINB_CMA1, mchash[1]);
2942 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
2943 DPRINTF(sc, ("%s: tlp_winb_filter_setup: returning\n",
2944 sc->sc_dev.dv_xname));
2945 }
2946
2947 /*
2948 * tlp_al981_filter_setup:
2949 *
2950 * Set the ADMtek AL981's receive filter.
2951 */
2952 static void
2953 tlp_al981_filter_setup(struct tulip_softc *sc)
2954 {
2955 struct ethercom *ec = &sc->sc_ethercom;
2956 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
2957 struct ether_multi *enm;
2958 struct ether_multistep step;
2959 u_int32_t hash, mchash[2];
2960
2961 /*
2962 * If the chip is running, we need to reset the interface,
2963 * and will revisit here (with IFF_RUNNING) clear. The
2964 * chip seems to really not like to have its multicast
2965 * filter programmed without a reset.
2966 */
2967 if (ifp->if_flags & IFF_RUNNING) {
2968 (void) tlp_init(ifp);
2969 return;
2970 }
2971
2972 DPRINTF(sc, ("%s: tlp_al981_filter_setup: sc_flags 0x%08x\n",
2973 sc->sc_dev.dv_xname, sc->sc_flags));
2974
2975 sc->sc_opmode &= ~(OPMODE_PR|OPMODE_PM);
2976
2977 if (ifp->if_flags & IFF_PROMISC) {
2978 sc->sc_opmode |= OPMODE_PR;
2979 goto allmulti;
2980 }
2981
2982 mchash[0] = mchash[1] = 0;
2983
2984 ETHER_FIRST_MULTI(step, ec, enm);
2985 while (enm != NULL) {
2986 if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
2987 /*
2988 * We must listen to a range of multicast addresses.
2989 * For now, just accept all multicasts, rather than
2990 * trying to set only those filter bits needed to match
2991 * the range. (At this time, the only use of address
2992 * ranges is for IP multicast routing, for which the
2993 * range is big enough to require all bits set.)
2994 */
2995 goto allmulti;
2996 }
2997
2998 hash = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN) & 0x3f;
2999 mchash[hash >> 5] |= 1 << (hash & 0x1f);
3000 ETHER_NEXT_MULTI(step, enm);
3001 }
3002 ifp->if_flags &= ~IFF_ALLMULTI;
3003 goto setit;
3004
3005 allmulti:
3006 ifp->if_flags |= IFF_ALLMULTI;
3007 mchash[0] = mchash[1] = 0xffffffff;
3008
3009 setit:
3010 bus_space_write_4(sc->sc_st, sc->sc_sh, CSR_ADM_MAR0, mchash[0]);
3011 bus_space_write_4(sc->sc_st, sc->sc_sh, CSR_ADM_MAR1, mchash[1]);
3012 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
3013 DPRINTF(sc, ("%s: tlp_al981_filter_setup: returning\n",
3014 sc->sc_dev.dv_xname));
3015 }
3016
3017 /*
3018 * tlp_asix_filter_setup:
3019 *
3020 * Set the ASIX AX8814x recieve filter.
3021 */
3022 static void
3023 tlp_asix_filter_setup(struct tulip_softc *sc)
3024 {
3025 struct ethercom *ec = &sc->sc_ethercom;
3026 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
3027 struct ether_multi *enm;
3028 struct ether_multistep step;
3029 u_int32_t hash, mchash[2];
3030
3031 DPRINTF(sc, ("%s: tlp_asix_filter_setup: sc_flags 0x%08x\n",
3032 sc->sc_dev.dv_xname, sc->sc_flags));
3033
3034 sc->sc_opmode &= ~(OPMODE_PM|OPMODE_AX_RB|OPMODE_PR);
3035
3036 if (ifp->if_flags & IFF_MULTICAST)
3037 sc->sc_opmode |= OPMODE_PM;
3038
3039 if (ifp->if_flags & IFF_BROADCAST)
3040 sc->sc_opmode |= OPMODE_AX_RB;
3041
3042 if (ifp->if_flags & IFF_PROMISC) {
3043 sc->sc_opmode |= OPMODE_PR;
3044 goto allmulti;
3045 }
3046
3047 mchash[0] = mchash[1] = 0;
3048
3049 ETHER_FIRST_MULTI(step, ec, enm);
3050 while (enm != NULL) {
3051 if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
3052 /*
3053 * We must listen to a range of multicast addresses.
3054 * For now, just accept all multicasts, rather than
3055 * trying to set only those filter bits needed to match
3056 * the range. (At this time, the only use of address
3057 * ranges is for IP multicast routing, for which the
3058 * range is big enough to require all bits set.)
3059 */
3060 goto allmulti;
3061 }
3062 hash = (ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26)
3063 & 0x3f;
3064 if (hash < 32)
3065 mchash[0] |= (1 << hash);
3066 else
3067 mchash[1] |= (1 << (hash - 32));
3068 ETHER_NEXT_MULTI(step, enm);
3069 }
3070 ifp->if_flags &= ~IFF_ALLMULTI;
3071 goto setit;
3072
3073 allmulti:
3074 ifp->if_flags |= IFF_ALLMULTI;
3075 mchash[0] = mchash[1] = 0xffffffff;
3076
3077 setit:
3078 TULIP_WRITE(sc, CSR_AX_FILTIDX, AX_FILTIDX_MAR0);
3079 TULIP_WRITE(sc, CSR_AX_FILTDATA, mchash[0]);
3080 TULIP_WRITE(sc, CSR_AX_FILTIDX, AX_FILTIDX_MAR1);
3081 TULIP_WRITE(sc, CSR_AX_FILTDATA, mchash[1]);
3082 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
3083 DPRINTF(sc, ("%s: tlp_asix_filter_setup: returning\n",
3084 sc->sc_dev.dv_xname));
3085 }
3086
3087
3088 /*
3089 * tlp_idle:
3090 *
3091 * Cause the transmit and/or receive processes to go idle.
3092 */
3093 void
3094 tlp_idle(struct tulip_softc *sc, u_int32_t bits)
3095 {
3096 static const char * const tlp_tx_state_names[] = {
3097 "STOPPED",
3098 "RUNNING - FETCH",
3099 "RUNNING - WAIT",
3100 "RUNNING - READING",
3101 "-- RESERVED --",
3102 "RUNNING - SETUP",
3103 "SUSPENDED",
3104 "RUNNING - CLOSE",
3105 };
3106 static const char * const tlp_rx_state_names[] = {
3107 "STOPPED",
3108 "RUNNING - FETCH",
3109 "RUNNING - CHECK",
3110 "RUNNING - WAIT",
3111 "SUSPENDED",
3112 "RUNNING - CLOSE",
3113 "RUNNING - FLUSH",
3114 "RUNNING - QUEUE",
3115 };
3116 static const char * const dm9102_tx_state_names[] = {
3117 "STOPPED",
3118 "RUNNING - FETCH",
3119 "RUNNING - SETUP",
3120 "RUNNING - READING",
3121 "RUNNING - CLOSE - CLEAR OWNER",
3122 "RUNNING - WAIT",
3123 "RUNNING - CLOSE - WRITE STATUS",
3124 "SUSPENDED",
3125 };
3126 static const char * const dm9102_rx_state_names[] = {
3127 "STOPPED",
3128 "RUNNING - FETCH",
3129 "RUNNING - WAIT",
3130 "RUNNING - QUEUE",
3131 "RUNNING - CLOSE - CLEAR OWNER",
3132 "RUNNING - CLOSE - WRITE STATUS",
3133 "SUSPENDED",
3134 "RUNNING - FLUSH",
3135 };
3136
3137 const char * const *tx_state_names, * const *rx_state_names;
3138 u_int32_t csr, ackmask = 0;
3139 int i;
3140
3141 switch (sc->sc_chip) {
3142 case TULIP_CHIP_DM9102:
3143 case TULIP_CHIP_DM9102A:
3144 tx_state_names = dm9102_tx_state_names;
3145 rx_state_names = dm9102_rx_state_names;
3146 break;
3147
3148 default:
3149 tx_state_names = tlp_tx_state_names;
3150 rx_state_names = tlp_rx_state_names;
3151 break;
3152 }
3153
3154 if (bits & OPMODE_ST)
3155 ackmask |= STATUS_TPS;
3156
3157 if (bits & OPMODE_SR)
3158 ackmask |= STATUS_RPS;
3159
3160 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode & ~bits);
3161
3162 for (i = 0; i < 1000; i++) {
3163 if (TULIP_ISSET(sc, CSR_STATUS, ackmask) == ackmask)
3164 break;
3165 delay(10);
3166 }
3167
3168 csr = TULIP_READ(sc, CSR_STATUS);
3169 if ((csr & ackmask) != ackmask) {
3170 if ((bits & OPMODE_ST) != 0 && (csr & STATUS_TPS) == 0 &&
3171 (csr & STATUS_TS) != STATUS_TS_STOPPED) {
3172 switch (sc->sc_chip) {
3173 case TULIP_CHIP_AX88140:
3174 case TULIP_CHIP_AX88141:
3175 /*
3176 * Filter the message out on noisy chips.
3177 */
3178 break;
3179 default:
3180 printf("%s: transmit process failed to idle: "
3181 "state %s\n", sc->sc_dev.dv_xname,
3182 tx_state_names[(csr & STATUS_TS) >> 20]);
3183 }
3184 }
3185 if ((bits & OPMODE_SR) != 0 && (csr & STATUS_RPS) == 0 &&
3186 (csr & STATUS_RS) != STATUS_RS_STOPPED) {
3187 switch (sc->sc_chip) {
3188 case TULIP_CHIP_AN983:
3189 case TULIP_CHIP_AN985:
3190 case TULIP_CHIP_DM9102A:
3191 case TULIP_CHIP_RS7112:
3192 /*
3193 * Filter the message out on noisy chips.
3194 */
3195 break;
3196 default:
3197 printf("%s: receive process failed to idle: "
3198 "state %s\n", sc->sc_dev.dv_xname,
3199 rx_state_names[(csr & STATUS_RS) >> 17]);
3200 }
3201 }
3202 }
3203 TULIP_WRITE(sc, CSR_STATUS, ackmask);
3204 }
3205
3206 /*****************************************************************************
3207 * Generic media support functions.
3208 *****************************************************************************/
3209
3210 /*
3211 * tlp_mediastatus: [ifmedia interface function]
3212 *
3213 * Query the current media.
3214 */
3215 void
3216 tlp_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
3217 {
3218 struct tulip_softc *sc = ifp->if_softc;
3219
3220 if (TULIP_IS_ENABLED(sc) == 0) {
3221 ifmr->ifm_active = IFM_ETHER | IFM_NONE;
3222 ifmr->ifm_status = 0;
3223 return;
3224 }
3225
3226 (*sc->sc_mediasw->tmsw_get)(sc, ifmr);
3227 }
3228
3229 /*
3230 * tlp_mediachange: [ifmedia interface function]
3231 *
3232 * Update the current media.
3233 */
3234 int
3235 tlp_mediachange(struct ifnet *ifp)
3236 {
3237 struct tulip_softc *sc = ifp->if_softc;
3238
3239 if ((ifp->if_flags & IFF_UP) == 0)
3240 return (0);
3241 return ((*sc->sc_mediasw->tmsw_set)(sc));
3242 }
3243
3244 /*****************************************************************************
3245 * Support functions for MII-attached media.
3246 *****************************************************************************/
3247
3248 /*
3249 * tlp_mii_tick:
3250 *
3251 * One second timer, used to tick the MII.
3252 */
3253 static void
3254 tlp_mii_tick(void *arg)
3255 {
3256 struct tulip_softc *sc = arg;
3257 int s;
3258
3259 if (!device_is_active(&sc->sc_dev))
3260 return;
3261
3262 s = splnet();
3263 mii_tick(&sc->sc_mii);
3264 splx(s);
3265
3266 callout_reset(&sc->sc_tick_callout, hz, sc->sc_tick, sc);
3267 }
3268
3269 /*
3270 * tlp_mii_statchg: [mii interface function]
3271 *
3272 * Callback from PHY when media changes.
3273 */
3274 static void
3275 tlp_mii_statchg(struct device *self)
3276 {
3277 struct tulip_softc *sc = (struct tulip_softc *)self;
3278
3279 /* Idle the transmit and receive processes. */
3280 tlp_idle(sc, OPMODE_ST|OPMODE_SR);
3281
3282 sc->sc_opmode &= ~(OPMODE_TTM|OPMODE_FD|OPMODE_HBD);
3283
3284 if (IFM_SUBTYPE(sc->sc_mii.mii_media_active) == IFM_10_T)
3285 sc->sc_opmode |= OPMODE_TTM;
3286 else
3287 sc->sc_opmode |= OPMODE_HBD;
3288
3289 if (sc->sc_mii.mii_media_active & IFM_FDX)
3290 sc->sc_opmode |= OPMODE_FD|OPMODE_HBD;
3291
3292 /*
3293 * Write new OPMODE bits. This also restarts the transmit
3294 * and receive processes.
3295 */
3296 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
3297 }
3298
3299 /*
3300 * tlp_winb_mii_statchg: [mii interface function]
3301 *
3302 * Callback from PHY when media changes. This version is
3303 * for the Winbond 89C840F, which has different OPMODE bits.
3304 */
3305 static void
3306 tlp_winb_mii_statchg(struct device *self)
3307 {
3308 struct tulip_softc *sc = (struct tulip_softc *)self;
3309
3310 /* Idle the transmit and receive processes. */
3311 tlp_idle(sc, OPMODE_ST|OPMODE_SR);
3312
3313 sc->sc_opmode &= ~(OPMODE_WINB_FES|OPMODE_FD);
3314
3315 if (IFM_SUBTYPE(sc->sc_mii.mii_media_active) == IFM_100_TX)
3316 sc->sc_opmode |= OPMODE_WINB_FES;
3317
3318 if (sc->sc_mii.mii_media_active & IFM_FDX)
3319 sc->sc_opmode |= OPMODE_FD;
3320
3321 /*
3322 * Write new OPMODE bits. This also restarts the transmit
3323 * and receive processes.
3324 */
3325 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
3326 }
3327
3328 /*
3329 * tlp_dm9102_mii_statchg: [mii interface function]
3330 *
3331 * Callback from PHY when media changes. This version is
3332 * for the DM9102.
3333 */
3334 static void
3335 tlp_dm9102_mii_statchg(struct device *self)
3336 {
3337 struct tulip_softc *sc = (struct tulip_softc *)self;
3338
3339 /*
3340 * Don't idle the transmit and receive processes, here. It
3341 * seems to fail, and just causes excess noise.
3342 */
3343 sc->sc_opmode &= ~(OPMODE_TTM|OPMODE_FD);
3344
3345 if (IFM_SUBTYPE(sc->sc_mii.mii_media_active) != IFM_100_TX)
3346 sc->sc_opmode |= OPMODE_TTM;
3347
3348 if (sc->sc_mii.mii_media_active & IFM_FDX)
3349 sc->sc_opmode |= OPMODE_FD;
3350
3351 /*
3352 * Write new OPMODE bits.
3353 */
3354 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
3355 }
3356
3357 /*
3358 * tlp_mii_getmedia:
3359 *
3360 * Callback from ifmedia to request current media status.
3361 */
3362 static void
3363 tlp_mii_getmedia(struct tulip_softc *sc, struct ifmediareq *ifmr)
3364 {
3365
3366 mii_pollstat(&sc->sc_mii);
3367 ifmr->ifm_status = sc->sc_mii.mii_media_status;
3368 ifmr->ifm_active = sc->sc_mii.mii_media_active;
3369 }
3370
3371 /*
3372 * tlp_mii_setmedia:
3373 *
3374 * Callback from ifmedia to request new media setting.
3375 */
3376 static int
3377 tlp_mii_setmedia(struct tulip_softc *sc)
3378 {
3379 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
3380
3381 if (ifp->if_flags & IFF_UP) {
3382 switch (sc->sc_chip) {
3383 case TULIP_CHIP_21142:
3384 case TULIP_CHIP_21143:
3385 /* Disable the internal Nway engine. */
3386 TULIP_WRITE(sc, CSR_SIATXRX, 0);
3387 break;
3388
3389 default:
3390 /* Nothing. */
3391 break;
3392 }
3393 mii_mediachg(&sc->sc_mii);
3394 }
3395 return (0);
3396 }
3397
3398 /*
3399 * tlp_bitbang_mii_readreg:
3400 *
3401 * Read a PHY register via bit-bang'ing the MII.
3402 */
3403 static int
3404 tlp_bitbang_mii_readreg(struct device *self, int phy, int reg)
3405 {
3406 struct tulip_softc *sc = (void *) self;
3407
3408 return (mii_bitbang_readreg(self, sc->sc_bitbang_ops, phy, reg));
3409 }
3410
3411 /*
3412 * tlp_bitbang_mii_writereg:
3413 *
3414 * Write a PHY register via bit-bang'ing the MII.
3415 */
3416 static void
3417 tlp_bitbang_mii_writereg(struct device *self, int phy, int reg, int val)
3418 {
3419 struct tulip_softc *sc = (void *) self;
3420
3421 mii_bitbang_writereg(self, sc->sc_bitbang_ops, phy, reg, val);
3422 }
3423
3424 /*
3425 * tlp_sio_mii_bitbang_read:
3426 *
3427 * Read the MII serial port for the MII bit-bang module.
3428 */
3429 static u_int32_t
3430 tlp_sio_mii_bitbang_read(struct device *self)
3431 {
3432 struct tulip_softc *sc = (void *) self;
3433
3434 return (TULIP_READ(sc, CSR_MIIROM));
3435 }
3436
3437 /*
3438 * tlp_sio_mii_bitbang_write:
3439 *
3440 * Write the MII serial port for the MII bit-bang module.
3441 */
3442 static void
3443 tlp_sio_mii_bitbang_write(struct device *self, u_int32_t val)
3444 {
3445 struct tulip_softc *sc = (void *) self;
3446
3447 TULIP_WRITE(sc, CSR_MIIROM, val);
3448 }
3449
3450 /*
3451 * tlp_pnic_mii_readreg:
3452 *
3453 * Read a PHY register on the Lite-On PNIC.
3454 */
3455 static int
3456 tlp_pnic_mii_readreg(struct device *self, int phy, int reg)
3457 {
3458 struct tulip_softc *sc = (void *) self;
3459 u_int32_t val;
3460 int i;
3461
3462 TULIP_WRITE(sc, CSR_PNIC_MII,
3463 PNIC_MII_MBO | PNIC_MII_RESERVED |
3464 PNIC_MII_READ | (phy << PNIC_MII_PHYSHIFT) |
3465 (reg << PNIC_MII_REGSHIFT));
3466
3467 for (i = 0; i < 1000; i++) {
3468 delay(10);
3469 val = TULIP_READ(sc, CSR_PNIC_MII);
3470 if ((val & PNIC_MII_BUSY) == 0) {
3471 if ((val & PNIC_MII_DATA) == PNIC_MII_DATA)
3472 return (0);
3473 else
3474 return (val & PNIC_MII_DATA);
3475 }
3476 }
3477 printf("%s: MII read timed out\n", sc->sc_dev.dv_xname);
3478 return (0);
3479 }
3480
3481 /*
3482 * tlp_pnic_mii_writereg:
3483 *
3484 * Write a PHY register on the Lite-On PNIC.
3485 */
3486 static void
3487 tlp_pnic_mii_writereg(struct device *self, int phy, int reg, int val)
3488 {
3489 struct tulip_softc *sc = (void *) self;
3490 int i;
3491
3492 TULIP_WRITE(sc, CSR_PNIC_MII,
3493 PNIC_MII_MBO | PNIC_MII_RESERVED |
3494 PNIC_MII_WRITE | (phy << PNIC_MII_PHYSHIFT) |
3495 (reg << PNIC_MII_REGSHIFT) | val);
3496
3497 for (i = 0; i < 1000; i++) {
3498 delay(10);
3499 if (TULIP_ISSET(sc, CSR_PNIC_MII, PNIC_MII_BUSY) == 0)
3500 return;
3501 }
3502 printf("%s: MII write timed out\n", sc->sc_dev.dv_xname);
3503 }
3504
3505 static const bus_addr_t tlp_al981_phy_regmap[] = {
3506 CSR_ADM_BMCR,
3507 CSR_ADM_BMSR,
3508 CSR_ADM_PHYIDR1,
3509 CSR_ADM_PHYIDR2,
3510 CSR_ADM_ANAR,
3511 CSR_ADM_ANLPAR,
3512 CSR_ADM_ANER,
3513
3514 CSR_ADM_XMC,
3515 CSR_ADM_XCIIS,
3516 CSR_ADM_XIE,
3517 CSR_ADM_100CTR,
3518 };
3519 static const int tlp_al981_phy_regmap_size = sizeof(tlp_al981_phy_regmap) /
3520 sizeof(tlp_al981_phy_regmap[0]);
3521
3522 /*
3523 * tlp_al981_mii_readreg:
3524 *
3525 * Read a PHY register on the ADMtek AL981.
3526 */
3527 static int
3528 tlp_al981_mii_readreg(struct device *self, int phy, int reg)
3529 {
3530 struct tulip_softc *sc = (struct tulip_softc *)self;
3531
3532 /* AL981 only has an internal PHY. */
3533 if (phy != 0)
3534 return (0);
3535
3536 if (reg >= tlp_al981_phy_regmap_size)
3537 return (0);
3538
3539 return (bus_space_read_4(sc->sc_st, sc->sc_sh,
3540 tlp_al981_phy_regmap[reg]) & 0xffff);
3541 }
3542
3543 /*
3544 * tlp_al981_mii_writereg:
3545 *
3546 * Write a PHY register on the ADMtek AL981.
3547 */
3548 static void
3549 tlp_al981_mii_writereg(struct device *self, int phy, int reg, int val)
3550 {
3551 struct tulip_softc *sc = (struct tulip_softc *)self;
3552
3553 /* AL981 only has an internal PHY. */
3554 if (phy != 0)
3555 return;
3556
3557 if (reg >= tlp_al981_phy_regmap_size)
3558 return;
3559
3560 bus_space_write_4(sc->sc_st, sc->sc_sh,
3561 tlp_al981_phy_regmap[reg], val);
3562 }
3563
3564 /*****************************************************************************
3565 * Chip-specific pre-init and reset functions.
3566 *****************************************************************************/
3567
3568 /*
3569 * tlp_2114x_preinit:
3570 *
3571 * Pre-init function shared by DECchip 21140, 21140A, 21142, and 21143.
3572 */
3573 static void
3574 tlp_2114x_preinit(struct tulip_softc *sc)
3575 {
3576 struct ifmedia_entry *ife = sc->sc_mii.mii_media.ifm_cur;
3577 struct tulip_21x4x_media *tm = ife->ifm_aux;
3578
3579 /*
3580 * Whether or not we're in MII or SIA/SYM mode, the media info
3581 * contains the appropriate OPMODE bits.
3582 *
3583 * Also, we always set the Must-Be-One bit.
3584 */
3585 sc->sc_opmode |= OPMODE_MBO | tm->tm_opmode;
3586
3587 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
3588 }
3589
3590 /*
3591 * tlp_2114x_mii_preinit:
3592 *
3593 * Pre-init function shared by DECchip 21140, 21140A, 21142, and 21143.
3594 * This version is used by boards which only have MII and don't have
3595 * an ISV SROM.
3596 */
3597 static void
3598 tlp_2114x_mii_preinit(struct tulip_softc *sc)
3599 {
3600
3601 /*
3602 * Always set the Must-Be-One bit, and Port Select (to select MII).
3603 * We'll never be called during a media change.
3604 */
3605 sc->sc_opmode |= OPMODE_MBO|OPMODE_PS;
3606 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
3607 }
3608
3609 /*
3610 * tlp_pnic_preinit:
3611 *
3612 * Pre-init function for the Lite-On 82c168 and 82c169.
3613 */
3614 static void
3615 tlp_pnic_preinit(struct tulip_softc *sc)
3616 {
3617
3618 if (sc->sc_flags & TULIPF_HAS_MII) {
3619 /*
3620 * MII case: just set the port-select bit; we will never
3621 * be called during a media change.
3622 */
3623 sc->sc_opmode |= OPMODE_PS;
3624 } else {
3625 /*
3626 * ENDEC/PCS/Nway mode; enable the Tx backoff counter.
3627 */
3628 sc->sc_opmode |= OPMODE_PNIC_TBEN;
3629 }
3630 }
3631
3632 /*
3633 * tlp_asix_preinit:
3634 *
3635 * Pre-init function for the ASIX chipsets.
3636 */
3637 static void
3638 tlp_asix_preinit(struct tulip_softc *sc)
3639 {
3640
3641 switch (sc->sc_chip) {
3642 case TULIP_CHIP_AX88140:
3643 case TULIP_CHIP_AX88141:
3644 /* XXX Handle PHY. */
3645 sc->sc_opmode |= OPMODE_HBD|OPMODE_PS;
3646 break;
3647 default:
3648 /* Nothing */
3649 break;
3650 }
3651
3652 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
3653 }
3654
3655 /*
3656 * tlp_dm9102_preinit:
3657 *
3658 * Pre-init function for the Davicom DM9102.
3659 */
3660 static void
3661 tlp_dm9102_preinit(struct tulip_softc *sc)
3662 {
3663
3664 switch (sc->sc_chip) {
3665 case TULIP_CHIP_DM9102:
3666 sc->sc_opmode |= OPMODE_MBO|OPMODE_HBD|OPMODE_PS;
3667 break;
3668
3669 case TULIP_CHIP_DM9102A:
3670 /*
3671 * XXX Figure out how to actually deal with the HomePNA
3672 * XXX portion of the DM9102A.
3673 */
3674 sc->sc_opmode |= OPMODE_MBO|OPMODE_HBD;
3675 break;
3676
3677 default:
3678 /* Nothing. */
3679 break;
3680 }
3681
3682 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
3683 }
3684
3685 /*
3686 * tlp_21140_reset:
3687 *
3688 * Issue a reset sequence on the 21140 via the GPIO facility.
3689 */
3690 static void
3691 tlp_21140_reset(struct tulip_softc *sc)
3692 {
3693 struct ifmedia_entry *ife = sc->sc_mii.mii_media.ifm_cur;
3694 struct tulip_21x4x_media *tm = ife->ifm_aux;
3695 int i;
3696
3697 /* First, set the direction on the GPIO pins. */
3698 TULIP_WRITE(sc, CSR_GPP, GPP_GPC|sc->sc_gp_dir);
3699
3700 /* Now, issue the reset sequence. */
3701 for (i = 0; i < tm->tm_reset_length; i++) {
3702 delay(10);
3703 TULIP_WRITE(sc, CSR_GPP, sc->sc_srom[tm->tm_reset_offset + i]);
3704 }
3705
3706 /* Now, issue the selection sequence. */
3707 for (i = 0; i < tm->tm_gp_length; i++) {
3708 delay(10);
3709 TULIP_WRITE(sc, CSR_GPP, sc->sc_srom[tm->tm_gp_offset + i]);
3710 }
3711
3712 /* If there were no sequences, just lower the pins. */
3713 if (tm->tm_reset_length == 0 && tm->tm_gp_length == 0) {
3714 delay(10);
3715 TULIP_WRITE(sc, CSR_GPP, 0);
3716 }
3717 }
3718
3719 /*
3720 * tlp_21142_reset:
3721 *
3722 * Issue a reset sequence on the 21142 via the GPIO facility.
3723 */
3724 static void
3725 tlp_21142_reset(struct tulip_softc *sc)
3726 {
3727 struct ifmedia_entry *ife = sc->sc_mii.mii_media.ifm_cur;
3728 struct tulip_21x4x_media *tm = ife->ifm_aux;
3729 const u_int8_t *cp;
3730 int i;
3731
3732 cp = &sc->sc_srom[tm->tm_reset_offset];
3733 for (i = 0; i < tm->tm_reset_length; i++, cp += 2) {
3734 delay(10);
3735 TULIP_WRITE(sc, CSR_SIAGEN, TULIP_ROM_GETW(cp, 0) << 16);
3736 }
3737
3738 cp = &sc->sc_srom[tm->tm_gp_offset];
3739 for (i = 0; i < tm->tm_gp_length; i++, cp += 2) {
3740 delay(10);
3741 TULIP_WRITE(sc, CSR_SIAGEN, TULIP_ROM_GETW(cp, 0) << 16);
3742 }
3743
3744 /* If there were no sequences, just lower the pins. */
3745 if (tm->tm_reset_length == 0 && tm->tm_gp_length == 0) {
3746 delay(10);
3747 TULIP_WRITE(sc, CSR_SIAGEN, 0);
3748 }
3749 }
3750
3751 /*
3752 * tlp_pmac_reset:
3753 *
3754 * Reset routine for Macronix chips.
3755 */
3756 static void
3757 tlp_pmac_reset(struct tulip_softc *sc)
3758 {
3759
3760 switch (sc->sc_chip) {
3761 case TULIP_CHIP_82C115:
3762 case TULIP_CHIP_MX98715:
3763 case TULIP_CHIP_MX98715A:
3764 case TULIP_CHIP_MX98725:
3765 /*
3766 * Set the LED operating mode. This information is located
3767 * in the EEPROM at byte offset 0x77, per the MX98715A and
3768 * MX98725 application notes.
3769 */
3770 TULIP_WRITE(sc, CSR_MIIROM, sc->sc_srom[0x77] << 24);
3771 break;
3772 case TULIP_CHIP_MX98715AEC_X:
3773 /*
3774 * Set the LED operating mode. This information is located
3775 * in the EEPROM at byte offset 0x76, per the MX98715AEC
3776 * application note.
3777 */
3778 TULIP_WRITE(sc, CSR_MIIROM, ((0xf & sc->sc_srom[0x76]) << 28)
3779 | ((0xf0 & sc->sc_srom[0x76]) << 20));
3780 break;
3781
3782 default:
3783 /* Nothing. */
3784 break;
3785 }
3786 }
3787
3788 #if 0
3789 /*
3790 * tlp_dm9102_reset:
3791 *
3792 * Reset routine for the Davicom DM9102.
3793 */
3794 static void
3795 tlp_dm9102_reset(struct tulip_softc *sc)
3796 {
3797
3798 TULIP_WRITE(sc, CSR_DM_PHYSTAT, DM_PHYSTAT_GEPC|DM_PHYSTAT_GPED);
3799 delay(100);
3800 TULIP_WRITE(sc, CSR_DM_PHYSTAT, 0);
3801 }
3802 #endif
3803
3804 /*****************************************************************************
3805 * Chip/board-specific media switches. The ones here are ones that
3806 * are potentially common to multiple front-ends.
3807 *****************************************************************************/
3808
3809 /*
3810 * This table is a common place for all sorts of media information,
3811 * keyed off of the SROM media code for that media.
3812 *
3813 * Note that we explicitly configure the 21142/21143 to always advertise
3814 * NWay capabilities when using the UTP port.
3815 * XXX Actually, we don't yet.
3816 */
3817 static const struct tulip_srom_to_ifmedia tulip_srom_to_ifmedia_table[] = {
3818 { TULIP_ROM_MB_MEDIA_TP, IFM_10_T, 0,
3819 "10baseT",
3820 OPMODE_TTM,
3821 BMSR_10THDX,
3822 { SIACONN_21040_10BASET,
3823 SIATXRX_21040_10BASET,
3824 SIAGEN_21040_10BASET },
3825
3826 { SIACONN_21041_10BASET,
3827 SIATXRX_21041_10BASET,
3828 SIAGEN_21041_10BASET },
3829
3830 { SIACONN_21142_10BASET,
3831 SIATXRX_21142_10BASET,
3832 SIAGEN_21142_10BASET } },
3833
3834 { TULIP_ROM_MB_MEDIA_BNC, IFM_10_2, 0,
3835 "10base2",
3836 0,
3837 0,
3838 { 0,
3839 0,
3840 0 },
3841
3842 { SIACONN_21041_BNC,
3843 SIATXRX_21041_BNC,
3844 SIAGEN_21041_BNC },
3845
3846 { SIACONN_21142_BNC,
3847 SIATXRX_21142_BNC,
3848 SIAGEN_21142_BNC } },
3849
3850 { TULIP_ROM_MB_MEDIA_AUI, IFM_10_5, 0,
3851 "10base5",
3852 0,
3853 0,
3854 { SIACONN_21040_AUI,
3855 SIATXRX_21040_AUI,
3856 SIAGEN_21040_AUI },
3857
3858 { SIACONN_21041_AUI,
3859 SIATXRX_21041_AUI,
3860 SIAGEN_21041_AUI },
3861
3862 { SIACONN_21142_AUI,
3863 SIATXRX_21142_AUI,
3864 SIAGEN_21142_AUI } },
3865
3866 { TULIP_ROM_MB_MEDIA_100TX, IFM_100_TX, 0,
3867 "100baseTX",
3868 OPMODE_PS|OPMODE_PCS|OPMODE_SCR|OPMODE_HBD,
3869 BMSR_100TXHDX,
3870 { 0,
3871 0,
3872 0 },
3873
3874 { 0,
3875 0,
3876 0 },
3877
3878 { 0,
3879 0,
3880 SIAGEN_ABM } },
3881
3882 { TULIP_ROM_MB_MEDIA_TP_FDX, IFM_10_T, IFM_FDX,
3883 "10baseT-FDX",
3884 OPMODE_TTM|OPMODE_FD|OPMODE_HBD,
3885 BMSR_10TFDX,
3886 { SIACONN_21040_10BASET_FDX,
3887 SIATXRX_21040_10BASET_FDX,
3888 SIAGEN_21040_10BASET_FDX },
3889
3890 { SIACONN_21041_10BASET_FDX,
3891 SIATXRX_21041_10BASET_FDX,
3892 SIAGEN_21041_10BASET_FDX },
3893
3894 { SIACONN_21142_10BASET_FDX,
3895 SIATXRX_21142_10BASET_FDX,
3896 SIAGEN_21142_10BASET_FDX } },
3897
3898 { TULIP_ROM_MB_MEDIA_100TX_FDX, IFM_100_TX, IFM_FDX,
3899 "100baseTX-FDX",
3900 OPMODE_PS|OPMODE_PCS|OPMODE_SCR|OPMODE_FD|OPMODE_HBD,
3901 BMSR_100TXFDX,
3902 { 0,
3903 0,
3904 0 },
3905
3906 { 0,
3907 0,
3908 0 },
3909
3910 { 0,
3911 0,
3912 SIAGEN_ABM } },
3913
3914 { TULIP_ROM_MB_MEDIA_100T4, IFM_100_T4, 0,
3915 "100baseT4",
3916 OPMODE_PS|OPMODE_PCS|OPMODE_SCR|OPMODE_HBD,
3917 BMSR_100T4,
3918 { 0,
3919 0,
3920 0 },
3921
3922 { 0,
3923 0,
3924 0 },
3925
3926 { 0,
3927 0,
3928 SIAGEN_ABM } },
3929
3930 { TULIP_ROM_MB_MEDIA_100FX, IFM_100_FX, 0,
3931 "100baseFX",
3932 OPMODE_PS|OPMODE_PCS|OPMODE_HBD,
3933 0,
3934 { 0,
3935 0,
3936 0 },
3937
3938 { 0,
3939 0,
3940 0 },
3941
3942 { 0,
3943 0,
3944 SIAGEN_ABM } },
3945
3946 { TULIP_ROM_MB_MEDIA_100FX_FDX, IFM_100_FX, IFM_FDX,
3947 "100baseFX-FDX",
3948 OPMODE_PS|OPMODE_PCS|OPMODE_FD|OPMODE_HBD,
3949 0,
3950 { 0,
3951 0,
3952 0 },
3953
3954 { 0,
3955 0,
3956 0 },
3957
3958 { 0,
3959 0,
3960 SIAGEN_ABM } },
3961
3962 { 0, 0, 0,
3963 NULL,
3964 0,
3965 0,
3966 { 0,
3967 0,
3968 0 },
3969
3970 { 0,
3971 0,
3972 0 },
3973
3974 { 0,
3975 0,
3976 0 } },
3977 };
3978
3979 static const struct tulip_srom_to_ifmedia *tlp_srom_to_ifmedia(u_int8_t);
3980 static void tlp_srom_media_info(struct tulip_softc *,
3981 const struct tulip_srom_to_ifmedia *,
3982 struct tulip_21x4x_media *);
3983 static void tlp_add_srom_media(struct tulip_softc *, int,
3984 void (*)(struct tulip_softc *, struct ifmediareq *),
3985 int (*)(struct tulip_softc *), const u_int8_t *, int);
3986 static void tlp_print_media(struct tulip_softc *);
3987 static void tlp_nway_activate(struct tulip_softc *, int);
3988 static void tlp_get_minst(struct tulip_softc *);
3989
3990 static const struct tulip_srom_to_ifmedia *
3991 tlp_srom_to_ifmedia(u_int8_t sm)
3992 {
3993 const struct tulip_srom_to_ifmedia *tsti;
3994
3995 for (tsti = tulip_srom_to_ifmedia_table;
3996 tsti->tsti_name != NULL; tsti++) {
3997 if (tsti->tsti_srom == sm)
3998 return (tsti);
3999 }
4000
4001 return (NULL);
4002 }
4003
4004 static void
4005 tlp_srom_media_info(struct tulip_softc *sc,
4006 const struct tulip_srom_to_ifmedia *tsti, struct tulip_21x4x_media *tm)
4007 {
4008
4009 tm->tm_name = tsti->tsti_name;
4010 tm->tm_opmode = tsti->tsti_opmode;
4011
4012 sc->sc_sia_cap |= tsti->tsti_sia_cap;
4013
4014 switch (sc->sc_chip) {
4015 case TULIP_CHIP_DE425:
4016 case TULIP_CHIP_21040:
4017 tm->tm_sia = tsti->tsti_21040; /* struct assignment */
4018 break;
4019
4020 case TULIP_CHIP_21041:
4021 tm->tm_sia = tsti->tsti_21041; /* struct assignment */
4022 break;
4023
4024 case TULIP_CHIP_21142:
4025 case TULIP_CHIP_21143:
4026 case TULIP_CHIP_82C115:
4027 case TULIP_CHIP_MX98715:
4028 case TULIP_CHIP_MX98715A:
4029 case TULIP_CHIP_MX98715AEC_X:
4030 case TULIP_CHIP_MX98725:
4031 tm->tm_sia = tsti->tsti_21142; /* struct assignment */
4032 break;
4033
4034 default:
4035 /* Nothing. */
4036 break;
4037 }
4038 }
4039
4040 static void
4041 tlp_add_srom_media(struct tulip_softc *sc, int type,
4042 void (*get)(struct tulip_softc *, struct ifmediareq *),
4043 int (*set)(struct tulip_softc *), const u_int8_t *list,
4044 int cnt)
4045 {
4046 struct tulip_21x4x_media *tm;
4047 const struct tulip_srom_to_ifmedia *tsti;
4048 int i;
4049
4050 for (i = 0; i < cnt; i++) {
4051 tsti = tlp_srom_to_ifmedia(list[i]);
4052 tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
4053 tlp_srom_media_info(sc, tsti, tm);
4054 tm->tm_type = type;
4055 tm->tm_get = get;
4056 tm->tm_set = set;
4057
4058 ifmedia_add(&sc->sc_mii.mii_media,
4059 IFM_MAKEWORD(IFM_ETHER, tsti->tsti_subtype,
4060 tsti->tsti_options, sc->sc_tlp_minst), 0, tm);
4061 }
4062 }
4063
4064 static void
4065 tlp_print_media(struct tulip_softc *sc)
4066 {
4067 struct ifmedia_entry *ife;
4068 struct tulip_21x4x_media *tm;
4069 const char *sep = "";
4070
4071 #define PRINT(str) printf("%s%s", sep, str); sep = ", "
4072
4073 printf("%s: ", sc->sc_dev.dv_xname);
4074 for (ife = TAILQ_FIRST(&sc->sc_mii.mii_media.ifm_list);
4075 ife != NULL; ife = TAILQ_NEXT(ife, ifm_list)) {
4076 tm = ife->ifm_aux;
4077 if (tm == NULL) {
4078 #ifdef DIAGNOSTIC
4079 if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
4080 panic("tlp_print_media");
4081 #endif
4082 PRINT("auto");
4083 } else if (tm->tm_type != TULIP_ROM_MB_21140_MII &&
4084 tm->tm_type != TULIP_ROM_MB_21142_MII) {
4085 PRINT(tm->tm_name);
4086 }
4087 }
4088 printf("\n");
4089
4090 #undef PRINT
4091 }
4092
4093 static void
4094 tlp_nway_activate(struct tulip_softc *sc, int media)
4095 {
4096 struct ifmedia_entry *ife;
4097
4098 ife = ifmedia_match(&sc->sc_mii.mii_media, media, 0);
4099 #ifdef DIAGNOSTIC
4100 if (ife == NULL)
4101 panic("tlp_nway_activate");
4102 #endif
4103 sc->sc_nway_active = ife;
4104 }
4105
4106 static void
4107 tlp_get_minst(struct tulip_softc *sc)
4108 {
4109
4110 if ((sc->sc_media_seen &
4111 ~((1 << TULIP_ROM_MB_21140_MII) |
4112 (1 << TULIP_ROM_MB_21142_MII))) == 0) {
4113 /*
4114 * We have not yet seen any SIA/SYM media (but are
4115 * about to; that's why we're called!), so assign
4116 * the current media instance to be the `internal media'
4117 * instance, and advance it so any MII media gets a
4118 * fresh one (used to selecting/isolating a PHY).
4119 */
4120 sc->sc_tlp_minst = sc->sc_mii.mii_instance++;
4121 }
4122 }
4123
4124 /*
4125 * SIA Utility functions.
4126 */
4127 static void tlp_sia_update_link(struct tulip_softc *);
4128 static void tlp_sia_get(struct tulip_softc *, struct ifmediareq *);
4129 static int tlp_sia_set(struct tulip_softc *);
4130 static int tlp_sia_media(struct tulip_softc *, struct ifmedia_entry *);
4131 static void tlp_sia_fixup(struct tulip_softc *);
4132
4133 static void
4134 tlp_sia_update_link(struct tulip_softc *sc)
4135 {
4136 struct ifmedia_entry *ife;
4137 struct tulip_21x4x_media *tm;
4138 u_int32_t siastat;
4139
4140 ife = TULIP_CURRENT_MEDIA(sc);
4141 tm = ife->ifm_aux;
4142
4143 sc->sc_flags &= ~(TULIPF_LINK_UP|TULIPF_LINK_VALID);
4144
4145 siastat = TULIP_READ(sc, CSR_SIASTAT);
4146
4147 /*
4148 * Note that when we do SIA link tests, we are assuming that
4149 * the chip is really in the mode that the current media setting
4150 * reflects. If we're not, then the link tests will not be
4151 * accurate!
4152 */
4153 switch (IFM_SUBTYPE(ife->ifm_media)) {
4154 case IFM_10_T:
4155 sc->sc_flags |= TULIPF_LINK_VALID;
4156 if ((siastat & SIASTAT_LS10) == 0)
4157 sc->sc_flags |= TULIPF_LINK_UP;
4158 break;
4159
4160 case IFM_100_TX:
4161 case IFM_100_T4:
4162 sc->sc_flags |= TULIPF_LINK_VALID;
4163 if ((siastat & SIASTAT_LS100) == 0)
4164 sc->sc_flags |= TULIPF_LINK_UP;
4165 break;
4166 }
4167
4168 switch (sc->sc_chip) {
4169 case TULIP_CHIP_21142:
4170 case TULIP_CHIP_21143:
4171 /*
4172 * On these chips, we can tell more information about
4173 * AUI/BNC. Note that the AUI/BNC selection is made
4174 * in a different register; for our purpose, it's all
4175 * AUI.
4176 */
4177 switch (IFM_SUBTYPE(ife->ifm_media)) {
4178 case IFM_10_2:
4179 case IFM_10_5:
4180 sc->sc_flags |= TULIPF_LINK_VALID;
4181 if (siastat & SIASTAT_ARA) {
4182 TULIP_WRITE(sc, CSR_SIASTAT, SIASTAT_ARA);
4183 sc->sc_flags |= TULIPF_LINK_UP;
4184 }
4185 break;
4186
4187 default:
4188 /*
4189 * If we're SYM media and can detect the link
4190 * via the GPIO facility, prefer that status
4191 * over LS100.
4192 */
4193 if (tm->tm_type == TULIP_ROM_MB_21143_SYM &&
4194 tm->tm_actmask != 0) {
4195 sc->sc_flags = (sc->sc_flags &
4196 ~TULIPF_LINK_UP) | TULIPF_LINK_VALID;
4197 if (TULIP_ISSET(sc, CSR_SIAGEN,
4198 tm->tm_actmask) == tm->tm_actdata)
4199 sc->sc_flags |= TULIPF_LINK_UP;
4200 }
4201 }
4202 break;
4203
4204 default:
4205 /* Nothing. */
4206 break;
4207 }
4208 }
4209
4210 static void
4211 tlp_sia_get(struct tulip_softc *sc, struct ifmediareq *ifmr)
4212 {
4213 struct ifmedia_entry *ife;
4214
4215 ifmr->ifm_status = 0;
4216
4217 tlp_sia_update_link(sc);
4218
4219 ife = TULIP_CURRENT_MEDIA(sc);
4220
4221 if (sc->sc_flags & TULIPF_LINK_VALID)
4222 ifmr->ifm_status |= IFM_AVALID;
4223 if (sc->sc_flags & TULIPF_LINK_UP)
4224 ifmr->ifm_status |= IFM_ACTIVE;
4225 ifmr->ifm_active = ife->ifm_media;
4226 }
4227
4228 static void
4229 tlp_sia_fixup(struct tulip_softc *sc)
4230 {
4231 struct ifmedia_entry *ife;
4232 struct tulip_21x4x_media *tm;
4233 u_int32_t siaconn, siatxrx, siagen;
4234
4235 switch (sc->sc_chip) {
4236 case TULIP_CHIP_82C115:
4237 case TULIP_CHIP_MX98713A:
4238 case TULIP_CHIP_MX98715:
4239 case TULIP_CHIP_MX98715A:
4240 case TULIP_CHIP_MX98715AEC_X:
4241 case TULIP_CHIP_MX98725:
4242 siaconn = PMAC_SIACONN_MASK;
4243 siatxrx = PMAC_SIATXRX_MASK;
4244 siagen = PMAC_SIAGEN_MASK;
4245 break;
4246
4247 default:
4248 /* No fixups required on any other chips. */
4249 return;
4250 }
4251
4252 for (ife = TAILQ_FIRST(&sc->sc_mii.mii_media.ifm_list);
4253 ife != NULL; ife = TAILQ_NEXT(ife, ifm_list)) {
4254 tm = ife->ifm_aux;
4255 if (tm == NULL)
4256 continue;
4257
4258 tm->tm_siaconn &= siaconn;
4259 tm->tm_siatxrx &= siatxrx;
4260 tm->tm_siagen &= siagen;
4261 }
4262 }
4263
4264 static int
4265 tlp_sia_set(struct tulip_softc *sc)
4266 {
4267
4268 return (tlp_sia_media(sc, TULIP_CURRENT_MEDIA(sc)));
4269 }
4270
4271 static int
4272 tlp_sia_media(struct tulip_softc *sc, struct ifmedia_entry *ife)
4273 {
4274 struct tulip_21x4x_media *tm;
4275
4276 tm = ife->ifm_aux;
4277
4278 /*
4279 * XXX This appears to be necessary on a bunch of the clone chips.
4280 */
4281 delay(20000);
4282
4283 /*
4284 * Idle the chip.
4285 */
4286 tlp_idle(sc, OPMODE_ST|OPMODE_SR);
4287
4288 /*
4289 * Program the SIA. It's important to write in this order,
4290 * resetting the SIA first.
4291 */
4292 TULIP_WRITE(sc, CSR_SIACONN, 0); /* SRL bit clear */
4293 delay(1000);
4294
4295 TULIP_WRITE(sc, CSR_SIATXRX, tm->tm_siatxrx);
4296
4297 switch (sc->sc_chip) {
4298 case TULIP_CHIP_21142:
4299 case TULIP_CHIP_21143:
4300 TULIP_WRITE(sc, CSR_SIAGEN, tm->tm_siagen | tm->tm_gpctl);
4301 TULIP_WRITE(sc, CSR_SIAGEN, tm->tm_siagen | tm->tm_gpdata);
4302 break;
4303 default:
4304 TULIP_WRITE(sc, CSR_SIAGEN, tm->tm_siagen);
4305 }
4306
4307 TULIP_WRITE(sc, CSR_SIACONN, tm->tm_siaconn);
4308
4309 /*
4310 * Set the OPMODE bits for this media and write OPMODE.
4311 * This will resume the transmit and receive processes.
4312 */
4313 sc->sc_opmode = (sc->sc_opmode & ~OPMODE_MEDIA_BITS) | tm->tm_opmode;
4314 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
4315
4316 return (0);
4317 }
4318
4319 /*
4320 * 21140 GPIO utility functions.
4321 */
4322 static void tlp_21140_gpio_update_link(struct tulip_softc *);
4323
4324 static void
4325 tlp_21140_gpio_update_link(struct tulip_softc *sc)
4326 {
4327 struct ifmedia_entry *ife;
4328 struct tulip_21x4x_media *tm;
4329
4330 ife = TULIP_CURRENT_MEDIA(sc);
4331 tm = ife->ifm_aux;
4332
4333 sc->sc_flags &= ~(TULIPF_LINK_UP|TULIPF_LINK_VALID);
4334
4335 if (tm->tm_actmask != 0) {
4336 sc->sc_flags |= TULIPF_LINK_VALID;
4337 if (TULIP_ISSET(sc, CSR_GPP, tm->tm_actmask) ==
4338 tm->tm_actdata)
4339 sc->sc_flags |= TULIPF_LINK_UP;
4340 }
4341 }
4342
4343 void
4344 tlp_21140_gpio_get(struct tulip_softc *sc, struct ifmediareq *ifmr)
4345 {
4346 struct ifmedia_entry *ife;
4347
4348 ifmr->ifm_status = 0;
4349
4350 tlp_21140_gpio_update_link(sc);
4351
4352 ife = TULIP_CURRENT_MEDIA(sc);
4353
4354 if (sc->sc_flags & TULIPF_LINK_VALID)
4355 ifmr->ifm_status |= IFM_AVALID;
4356 if (sc->sc_flags & TULIPF_LINK_UP)
4357 ifmr->ifm_status |= IFM_ACTIVE;
4358 ifmr->ifm_active = ife->ifm_media;
4359 }
4360
4361 int
4362 tlp_21140_gpio_set(struct tulip_softc *sc)
4363 {
4364 struct ifmedia_entry *ife;
4365 struct tulip_21x4x_media *tm;
4366
4367 ife = TULIP_CURRENT_MEDIA(sc);
4368 tm = ife->ifm_aux;
4369
4370 /*
4371 * Idle the chip.
4372 */
4373 tlp_idle(sc, OPMODE_ST|OPMODE_SR);
4374
4375 /*
4376 * Set the GPIO pins for this media, to flip any
4377 * relays, etc.
4378 */
4379 TULIP_WRITE(sc, CSR_GPP, GPP_GPC|sc->sc_gp_dir);
4380 delay(10);
4381 TULIP_WRITE(sc, CSR_GPP, tm->tm_gpdata);
4382
4383 /*
4384 * Set the OPMODE bits for this media and write OPMODE.
4385 * This will resume the transmit and receive processes.
4386 */
4387 sc->sc_opmode = (sc->sc_opmode & ~OPMODE_MEDIA_BITS) | tm->tm_opmode;
4388 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
4389
4390 return (0);
4391 }
4392
4393 /*
4394 * 21040 and 21041 media switches.
4395 */
4396 static void tlp_21040_tmsw_init(struct tulip_softc *);
4397 static void tlp_21040_tp_tmsw_init(struct tulip_softc *);
4398 static void tlp_21040_auibnc_tmsw_init(struct tulip_softc *);
4399 static void tlp_21041_tmsw_init(struct tulip_softc *);
4400
4401 const struct tulip_mediasw tlp_21040_mediasw = {
4402 tlp_21040_tmsw_init, tlp_sia_get, tlp_sia_set
4403 };
4404
4405 const struct tulip_mediasw tlp_21040_tp_mediasw = {
4406 tlp_21040_tp_tmsw_init, tlp_sia_get, tlp_sia_set
4407 };
4408
4409 const struct tulip_mediasw tlp_21040_auibnc_mediasw = {
4410 tlp_21040_auibnc_tmsw_init, tlp_sia_get, tlp_sia_set
4411 };
4412
4413 const struct tulip_mediasw tlp_21041_mediasw = {
4414 tlp_21041_tmsw_init, tlp_sia_get, tlp_sia_set
4415 };
4416
4417 static void
4418 tlp_21040_tmsw_init(struct tulip_softc *sc)
4419 {
4420 static const u_int8_t media[] = {
4421 TULIP_ROM_MB_MEDIA_TP,
4422 TULIP_ROM_MB_MEDIA_TP_FDX,
4423 TULIP_ROM_MB_MEDIA_AUI,
4424 };
4425 struct tulip_21x4x_media *tm;
4426
4427 ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
4428 tlp_mediastatus);
4429
4430 tlp_add_srom_media(sc, 0, NULL, NULL, media, 3);
4431
4432 /*
4433 * No SROM type for External SIA.
4434 */
4435 tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
4436 tm->tm_name = "manual";
4437 tm->tm_opmode = 0;
4438 tm->tm_siaconn = SIACONN_21040_EXTSIA;
4439 tm->tm_siatxrx = SIATXRX_21040_EXTSIA;
4440 tm->tm_siagen = SIAGEN_21040_EXTSIA;
4441 ifmedia_add(&sc->sc_mii.mii_media,
4442 IFM_MAKEWORD(IFM_ETHER, IFM_MANUAL, 0, sc->sc_tlp_minst), 0, tm);
4443
4444 /*
4445 * XXX Autosense not yet supported.
4446 */
4447
4448 /* XXX This should be auto-sense. */
4449 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_10_T);
4450
4451 tlp_print_media(sc);
4452 }
4453
4454 static void
4455 tlp_21040_tp_tmsw_init(struct tulip_softc *sc)
4456 {
4457 static const u_int8_t media[] = {
4458 TULIP_ROM_MB_MEDIA_TP,
4459 TULIP_ROM_MB_MEDIA_TP_FDX,
4460 };
4461
4462 ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
4463 tlp_mediastatus);
4464
4465 tlp_add_srom_media(sc, 0, NULL, NULL, media, 2);
4466
4467 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_10_T);
4468
4469 tlp_print_media(sc);
4470 }
4471
4472 static void
4473 tlp_21040_auibnc_tmsw_init(struct tulip_softc *sc)
4474 {
4475 static const u_int8_t media[] = {
4476 TULIP_ROM_MB_MEDIA_AUI,
4477 };
4478
4479 ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
4480 tlp_mediastatus);
4481
4482 tlp_add_srom_media(sc, 0, NULL, NULL, media, 1);
4483
4484 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_10_5);
4485
4486 tlp_print_media(sc);
4487 }
4488
4489 static void
4490 tlp_21041_tmsw_init(struct tulip_softc *sc)
4491 {
4492 static const u_int8_t media[] = {
4493 TULIP_ROM_MB_MEDIA_TP,
4494 TULIP_ROM_MB_MEDIA_TP_FDX,
4495 TULIP_ROM_MB_MEDIA_BNC,
4496 TULIP_ROM_MB_MEDIA_AUI,
4497 };
4498 int i, defmedia, devcnt, leaf_offset, mb_offset, m_cnt;
4499 const struct tulip_srom_to_ifmedia *tsti;
4500 struct tulip_21x4x_media *tm;
4501 u_int16_t romdef;
4502 u_int8_t mb;
4503
4504 ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
4505 tlp_mediastatus);
4506
4507 if (tlp_isv_srom(sc->sc_srom) == 0) {
4508 not_isv_srom:
4509 /*
4510 * If we have a board without the standard 21041 SROM format,
4511 * we just assume all media are present and try and pick a
4512 * reasonable default.
4513 */
4514 tlp_add_srom_media(sc, 0, NULL, NULL, media, 4);
4515
4516 /*
4517 * XXX Autosense not yet supported.
4518 */
4519
4520 /* XXX This should be auto-sense. */
4521 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_10_T);
4522
4523 tlp_print_media(sc);
4524 return;
4525 }
4526
4527 devcnt = sc->sc_srom[TULIP_ROM_CHIP_COUNT];
4528 for (i = 0; i < devcnt; i++) {
4529 if (sc->sc_srom[TULIP_ROM_CHIP_COUNT] == 1)
4530 break;
4531 if (sc->sc_srom[TULIP_ROM_CHIPn_DEVICE_NUMBER(i)] ==
4532 sc->sc_devno)
4533 break;
4534 }
4535
4536 if (i == devcnt)
4537 goto not_isv_srom;
4538
4539 leaf_offset = TULIP_ROM_GETW(sc->sc_srom,
4540 TULIP_ROM_CHIPn_INFO_LEAF_OFFSET(i));
4541 mb_offset = leaf_offset + TULIP_ROM_IL_MEDIAn_BLOCK_BASE;
4542 m_cnt = sc->sc_srom[leaf_offset + TULIP_ROM_IL_MEDIA_COUNT];
4543
4544 for (; m_cnt != 0;
4545 m_cnt--, mb_offset += TULIP_ROM_MB_SIZE(mb)) {
4546 mb = sc->sc_srom[mb_offset];
4547 tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
4548 switch (mb & TULIP_ROM_MB_MEDIA_CODE) {
4549 case TULIP_ROM_MB_MEDIA_TP_FDX:
4550 case TULIP_ROM_MB_MEDIA_TP:
4551 case TULIP_ROM_MB_MEDIA_BNC:
4552 case TULIP_ROM_MB_MEDIA_AUI:
4553 tsti = tlp_srom_to_ifmedia(mb &
4554 TULIP_ROM_MB_MEDIA_CODE);
4555
4556 tlp_srom_media_info(sc, tsti, tm);
4557
4558 /*
4559 * Override our default SIA settings if the
4560 * SROM contains its own.
4561 */
4562 if (mb & TULIP_ROM_MB_EXT) {
4563 tm->tm_siaconn = TULIP_ROM_GETW(sc->sc_srom,
4564 mb_offset + TULIP_ROM_MB_CSR13);
4565 tm->tm_siatxrx = TULIP_ROM_GETW(sc->sc_srom,
4566 mb_offset + TULIP_ROM_MB_CSR14);
4567 tm->tm_siagen = TULIP_ROM_GETW(sc->sc_srom,
4568 mb_offset + TULIP_ROM_MB_CSR15);
4569 }
4570
4571 ifmedia_add(&sc->sc_mii.mii_media,
4572 IFM_MAKEWORD(IFM_ETHER, tsti->tsti_subtype,
4573 tsti->tsti_options, sc->sc_tlp_minst), 0, tm);
4574 break;
4575
4576 default:
4577 printf("%s: unknown media code 0x%02x\n",
4578 sc->sc_dev.dv_xname,
4579 mb & TULIP_ROM_MB_MEDIA_CODE);
4580 free(tm, M_DEVBUF);
4581 }
4582 }
4583
4584 /*
4585 * XXX Autosense not yet supported.
4586 */
4587
4588 romdef = TULIP_ROM_GETW(sc->sc_srom, leaf_offset +
4589 TULIP_ROM_IL_SELECT_CONN_TYPE);
4590 switch (romdef) {
4591 case SELECT_CONN_TYPE_TP:
4592 case SELECT_CONN_TYPE_TP_AUTONEG:
4593 case SELECT_CONN_TYPE_TP_NOLINKPASS:
4594 defmedia = IFM_ETHER|IFM_10_T;
4595 break;
4596
4597 case SELECT_CONN_TYPE_TP_FDX:
4598 defmedia = IFM_ETHER|IFM_10_T|IFM_FDX;
4599 break;
4600
4601 case SELECT_CONN_TYPE_BNC:
4602 defmedia = IFM_ETHER|IFM_10_2;
4603 break;
4604
4605 case SELECT_CONN_TYPE_AUI:
4606 defmedia = IFM_ETHER|IFM_10_5;
4607 break;
4608 #if 0 /* XXX */
4609 case SELECT_CONN_TYPE_ASENSE:
4610 case SELECT_CONN_TYPE_ASENSE_AUTONEG:
4611 defmedia = IFM_ETHER|IFM_AUTO;
4612 break;
4613 #endif
4614 default:
4615 defmedia = 0;
4616 }
4617
4618 if (defmedia == 0) {
4619 /*
4620 * XXX We should default to auto-sense.
4621 */
4622 defmedia = IFM_ETHER|IFM_10_T;
4623 }
4624
4625 ifmedia_set(&sc->sc_mii.mii_media, defmedia);
4626
4627 tlp_print_media(sc);
4628 }
4629
4630 /*
4631 * DECchip 2114x ISV media switch.
4632 */
4633 static void tlp_2114x_isv_tmsw_init(struct tulip_softc *);
4634 static void tlp_2114x_isv_tmsw_get(struct tulip_softc *,
4635 struct ifmediareq *);
4636 static int tlp_2114x_isv_tmsw_set(struct tulip_softc *);
4637
4638 const struct tulip_mediasw tlp_2114x_isv_mediasw = {
4639 tlp_2114x_isv_tmsw_init, tlp_2114x_isv_tmsw_get, tlp_2114x_isv_tmsw_set
4640 };
4641
4642 static void tlp_2114x_nway_get(struct tulip_softc *, struct ifmediareq *);
4643 static int tlp_2114x_nway_set(struct tulip_softc *);
4644
4645 static void tlp_2114x_nway_statchg(struct device *);
4646 static int tlp_2114x_nway_service(struct tulip_softc *, int);
4647 static void tlp_2114x_nway_auto(struct tulip_softc *);
4648 static void tlp_2114x_nway_status(struct tulip_softc *);
4649
4650 static void
4651 tlp_2114x_isv_tmsw_init(struct tulip_softc *sc)
4652 {
4653 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
4654 struct ifmedia_entry *ife;
4655 struct mii_softc *phy;
4656 struct tulip_21x4x_media *tm;
4657 const struct tulip_srom_to_ifmedia *tsti;
4658 int i, devcnt, leaf_offset, m_cnt, type, length;
4659 int defmedia, miidef;
4660 u_int16_t word;
4661 u_int8_t *cp, *ncp;
4662
4663 defmedia = miidef = 0;
4664
4665 sc->sc_mii.mii_ifp = ifp;
4666 sc->sc_mii.mii_readreg = tlp_bitbang_mii_readreg;
4667 sc->sc_mii.mii_writereg = tlp_bitbang_mii_writereg;
4668 sc->sc_mii.mii_statchg = sc->sc_statchg;
4669
4670 /*
4671 * Ignore `instance'; we may get a mixture of SIA and MII
4672 * media, and `instance' is used to isolate or select the
4673 * PHY on the MII as appropriate. Note that duplicate media
4674 * are disallowed, so ignoring `instance' is safe.
4675 */
4676 ifmedia_init(&sc->sc_mii.mii_media, IFM_IMASK, tlp_mediachange,
4677 tlp_mediastatus);
4678
4679 devcnt = sc->sc_srom[TULIP_ROM_CHIP_COUNT];
4680 for (i = 0; i < devcnt; i++) {
4681 if (sc->sc_srom[TULIP_ROM_CHIP_COUNT] == 1)
4682 break;
4683 if (sc->sc_srom[TULIP_ROM_CHIPn_DEVICE_NUMBER(i)] ==
4684 sc->sc_devno)
4685 break;
4686 }
4687
4688 if (i == devcnt) {
4689 printf("%s: unable to locate info leaf in SROM\n",
4690 sc->sc_dev.dv_xname);
4691 return;
4692 }
4693
4694 leaf_offset = TULIP_ROM_GETW(sc->sc_srom,
4695 TULIP_ROM_CHIPn_INFO_LEAF_OFFSET(i));
4696
4697 /* XXX SELECT CONN TYPE */
4698
4699 cp = &sc->sc_srom[leaf_offset + TULIP_ROM_IL_MEDIA_COUNT];
4700
4701 /*
4702 * On some chips, the first thing in the Info Leaf is the
4703 * GPIO pin direction data.
4704 */
4705 switch (sc->sc_chip) {
4706 case TULIP_CHIP_21140:
4707 case TULIP_CHIP_21140A:
4708 case TULIP_CHIP_MX98713:
4709 case TULIP_CHIP_AX88140:
4710 case TULIP_CHIP_AX88141:
4711 sc->sc_gp_dir = *cp++;
4712 break;
4713
4714 default:
4715 /* Nothing. */
4716 break;
4717 }
4718
4719 /* Get the media count. */
4720 m_cnt = *cp++;
4721
4722 if (m_cnt == 0) {
4723 sc->sc_mediasw = &tlp_sio_mii_mediasw;
4724 (*sc->sc_mediasw->tmsw_init)(sc);
4725 return;
4726 }
4727
4728 for (; m_cnt != 0; cp = ncp, m_cnt--) {
4729 /*
4730 * Determine the type and length of this media block.
4731 * The 21143 is spec'd to always use extended format blocks,
4732 * but some cards don't set the bit to indicate this.
4733 * Hopefully there are no cards which really don't use
4734 * extended format blocks.
4735 */
4736 if ((*cp & 0x80) == 0 && sc->sc_chip != TULIP_CHIP_21143) {
4737 length = 4;
4738 type = TULIP_ROM_MB_21140_GPR;
4739 } else {
4740 length = (*cp++ & 0x7f) - 1;
4741 type = *cp++ & 0x3f;
4742 }
4743
4744 /* Compute the start of the next block. */
4745 ncp = cp + length;
4746
4747 /* Now, parse the block. */
4748 switch (type) {
4749 case TULIP_ROM_MB_21140_GPR:
4750 tlp_get_minst(sc);
4751 sc->sc_media_seen |= 1 << TULIP_ROM_MB_21140_GPR;
4752
4753 tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
4754
4755 tm->tm_type = TULIP_ROM_MB_21140_GPR;
4756 tm->tm_get = tlp_21140_gpio_get;
4757 tm->tm_set = tlp_21140_gpio_set;
4758
4759 /* First is the media type code. */
4760 tsti = tlp_srom_to_ifmedia(cp[0] &
4761 TULIP_ROM_MB_MEDIA_CODE);
4762 if (tsti == NULL) {
4763 /* Invalid media code. */
4764 free(tm, M_DEVBUF);
4765 break;
4766 }
4767
4768 /* Get defaults. */
4769 tlp_srom_media_info(sc, tsti, tm);
4770
4771 /* Next is any GPIO info for this media. */
4772 tm->tm_gpdata = cp[1];
4773
4774 /*
4775 * Next is a word containing OPMODE information
4776 * and info on how to detect if this media is
4777 * active.
4778 */
4779 word = TULIP_ROM_GETW(cp, 2);
4780 tm->tm_opmode &= OPMODE_FD;
4781 tm->tm_opmode |= TULIP_ROM_MB_OPMODE(word);
4782 if ((word & TULIP_ROM_MB_NOINDICATOR) == 0) {
4783 tm->tm_actmask =
4784 TULIP_ROM_MB_BITPOS(word);
4785 tm->tm_actdata =
4786 (word & TULIP_ROM_MB_POLARITY) ?
4787 0 : tm->tm_actmask;
4788 }
4789
4790 ifmedia_add(&sc->sc_mii.mii_media,
4791 IFM_MAKEWORD(IFM_ETHER, tsti->tsti_subtype,
4792 tsti->tsti_options, sc->sc_tlp_minst), 0, tm);
4793 break;
4794
4795 case TULIP_ROM_MB_21140_MII:
4796 sc->sc_media_seen |= 1 << TULIP_ROM_MB_21140_MII;
4797
4798 tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
4799
4800 tm->tm_type = TULIP_ROM_MB_21140_MII;
4801 tm->tm_get = tlp_mii_getmedia;
4802 tm->tm_set = tlp_mii_setmedia;
4803 tm->tm_opmode = OPMODE_PS;
4804
4805 if (sc->sc_reset == NULL)
4806 sc->sc_reset = tlp_21140_reset;
4807
4808 /* First is the PHY number. */
4809 tm->tm_phyno = *cp++;
4810
4811 /* Next is the MII select sequence length and offset. */
4812 tm->tm_gp_length = *cp++;
4813 tm->tm_gp_offset = cp - &sc->sc_srom[0];
4814 cp += tm->tm_gp_length;
4815
4816 /* Next is the MII reset sequence length and offset. */
4817 tm->tm_reset_length = *cp++;
4818 tm->tm_reset_offset = cp - &sc->sc_srom[0];
4819 cp += tm->tm_reset_length;
4820
4821 /*
4822 * The following items are left in the media block
4823 * that we don't particularly care about:
4824 *
4825 * capabilities W
4826 * advertisement W
4827 * full duplex W
4828 * tx threshold W
4829 *
4830 * These appear to be bits in the PHY registers,
4831 * which our MII code handles on its own.
4832 */
4833
4834 /*
4835 * Before we probe the MII bus, we need to reset
4836 * it and issue the selection sequence.
4837 */
4838
4839 /* Set the direction of the pins... */
4840 TULIP_WRITE(sc, CSR_GPP, GPP_GPC|sc->sc_gp_dir);
4841
4842 for (i = 0; i < tm->tm_reset_length; i++) {
4843 delay(10);
4844 TULIP_WRITE(sc, CSR_GPP,
4845 sc->sc_srom[tm->tm_reset_offset + i]);
4846 }
4847
4848 for (i = 0; i < tm->tm_gp_length; i++) {
4849 delay(10);
4850 TULIP_WRITE(sc, CSR_GPP,
4851 sc->sc_srom[tm->tm_gp_offset + i]);
4852 }
4853
4854 /* If there were no sequences, just lower the pins. */
4855 if (tm->tm_reset_length == 0 && tm->tm_gp_length == 0) {
4856 delay(10);
4857 TULIP_WRITE(sc, CSR_GPP, 0);
4858 }
4859
4860 /*
4861 * Now, probe the MII for the PHY. Note, we know
4862 * the location of the PHY on the bus, but we don't
4863 * particularly care; the MII code just likes to
4864 * search the whole thing anyhow.
4865 */
4866 mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff,
4867 MII_PHY_ANY, tm->tm_phyno, 0);
4868
4869 /*
4870 * Now, search for the PHY we hopefully just
4871 * configured. If it's not configured into the
4872 * kernel, we lose. The PHY's default media always
4873 * takes priority.
4874 */
4875 for (phy = LIST_FIRST(&sc->sc_mii.mii_phys);
4876 phy != NULL;
4877 phy = LIST_NEXT(phy, mii_list))
4878 if (phy->mii_offset == tm->tm_phyno)
4879 break;
4880 if (phy == NULL) {
4881 printf("%s: unable to configure MII\n",
4882 sc->sc_dev.dv_xname);
4883 break;
4884 }
4885
4886 sc->sc_flags |= TULIPF_HAS_MII;
4887 sc->sc_tick = tlp_mii_tick;
4888 miidef = IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0,
4889 phy->mii_inst);
4890
4891 /*
4892 * Okay, now that we've found the PHY and the MII
4893 * layer has added all of the media associated
4894 * with that PHY, we need to traverse the media
4895 * list, and add our `tm' to each entry's `aux'
4896 * pointer.
4897 *
4898 * We do this by looking for media with our
4899 * PHY's `instance'.
4900 */
4901 for (ife = TAILQ_FIRST(&sc->sc_mii.mii_media.ifm_list);
4902 ife != NULL;
4903 ife = TAILQ_NEXT(ife, ifm_list)) {
4904 if (IFM_INST(ife->ifm_media) != phy->mii_inst)
4905 continue;
4906 ife->ifm_aux = tm;
4907 }
4908 break;
4909
4910 case TULIP_ROM_MB_21142_SIA:
4911 tlp_get_minst(sc);
4912 sc->sc_media_seen |= 1 << TULIP_ROM_MB_21142_SIA;
4913
4914 tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
4915
4916 tm->tm_type = TULIP_ROM_MB_21142_SIA;
4917 tm->tm_get = tlp_sia_get;
4918 tm->tm_set = tlp_sia_set;
4919
4920 /* First is the media type code. */
4921 tsti = tlp_srom_to_ifmedia(cp[0] &
4922 TULIP_ROM_MB_MEDIA_CODE);
4923 if (tsti == NULL) {
4924 /* Invalid media code. */
4925 free(tm, M_DEVBUF);
4926 break;
4927 }
4928
4929 /* Get defaults. */
4930 tlp_srom_media_info(sc, tsti, tm);
4931
4932 /*
4933 * Override our default SIA settings if the
4934 * SROM contains its own.
4935 */
4936 if (cp[0] & 0x40) {
4937 tm->tm_siaconn = TULIP_ROM_GETW(cp, 1);
4938 tm->tm_siatxrx = TULIP_ROM_GETW(cp, 3);
4939 tm->tm_siagen = TULIP_ROM_GETW(cp, 5);
4940 cp += 7;
4941 } else
4942 cp++;
4943
4944 /* Next is GPIO control/data. */
4945 tm->tm_gpctl = TULIP_ROM_GETW(cp, 0) << 16;
4946 tm->tm_gpdata = TULIP_ROM_GETW(cp, 2) << 16;
4947
4948 ifmedia_add(&sc->sc_mii.mii_media,
4949 IFM_MAKEWORD(IFM_ETHER, tsti->tsti_subtype,
4950 tsti->tsti_options, sc->sc_tlp_minst), 0, tm);
4951 break;
4952
4953 case TULIP_ROM_MB_21142_MII:
4954 sc->sc_media_seen |= 1 << TULIP_ROM_MB_21142_MII;
4955
4956 tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
4957
4958 tm->tm_type = TULIP_ROM_MB_21142_MII;
4959 tm->tm_get = tlp_mii_getmedia;
4960 tm->tm_set = tlp_mii_setmedia;
4961 tm->tm_opmode = OPMODE_PS;
4962
4963 if (sc->sc_reset == NULL)
4964 sc->sc_reset = tlp_21142_reset;
4965
4966 /* First is the PHY number. */
4967 tm->tm_phyno = *cp++;
4968
4969 /* Next is the MII select sequence length and offset. */
4970 tm->tm_gp_length = *cp++;
4971 tm->tm_gp_offset = cp - &sc->sc_srom[0];
4972 cp += tm->tm_gp_length * 2;
4973
4974 /* Next is the MII reset sequence length and offset. */
4975 tm->tm_reset_length = *cp++;
4976 tm->tm_reset_offset = cp - &sc->sc_srom[0];
4977 cp += tm->tm_reset_length * 2;
4978
4979 /*
4980 * The following items are left in the media block
4981 * that we don't particularly care about:
4982 *
4983 * capabilities W
4984 * advertisement W
4985 * full duplex W
4986 * tx threshold W
4987 * MII interrupt W
4988 *
4989 * These appear to be bits in the PHY registers,
4990 * which our MII code handles on its own.
4991 */
4992
4993 /*
4994 * Before we probe the MII bus, we need to reset
4995 * it and issue the selection sequence.
4996 */
4997
4998 cp = &sc->sc_srom[tm->tm_reset_offset];
4999 for (i = 0; i < tm->tm_reset_length; i++, cp += 2) {
5000 delay(10);
5001 TULIP_WRITE(sc, CSR_SIAGEN,
5002 TULIP_ROM_GETW(cp, 0) << 16);
5003 }
5004
5005 cp = &sc->sc_srom[tm->tm_gp_offset];
5006 for (i = 0; i < tm->tm_gp_length; i++, cp += 2) {
5007 delay(10);
5008 TULIP_WRITE(sc, CSR_SIAGEN,
5009 TULIP_ROM_GETW(cp, 0) << 16);
5010 }
5011
5012 /* If there were no sequences, just lower the pins. */
5013 if (tm->tm_reset_length == 0 && tm->tm_gp_length == 0) {
5014 delay(10);
5015 TULIP_WRITE(sc, CSR_SIAGEN, 0);
5016 }
5017
5018 /*
5019 * Now, probe the MII for the PHY. Note, we know
5020 * the location of the PHY on the bus, but we don't
5021 * particularly care; the MII code just likes to
5022 * search the whole thing anyhow.
5023 */
5024 mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff,
5025 MII_PHY_ANY, tm->tm_phyno, 0);
5026
5027 /*
5028 * Now, search for the PHY we hopefully just
5029 * configured. If it's not configured into the
5030 * kernel, we lose. The PHY's default media always
5031 * takes priority.
5032 */
5033 for (phy = LIST_FIRST(&sc->sc_mii.mii_phys);
5034 phy != NULL;
5035 phy = LIST_NEXT(phy, mii_list))
5036 if (phy->mii_offset == tm->tm_phyno)
5037 break;
5038 if (phy == NULL) {
5039 printf("%s: unable to configure MII\n",
5040 sc->sc_dev.dv_xname);
5041 break;
5042 }
5043
5044 sc->sc_flags |= TULIPF_HAS_MII;
5045 sc->sc_tick = tlp_mii_tick;
5046 miidef = IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0,
5047 phy->mii_inst);
5048
5049 /*
5050 * Okay, now that we've found the PHY and the MII
5051 * layer has added all of the media associated
5052 * with that PHY, we need to traverse the media
5053 * list, and add our `tm' to each entry's `aux'
5054 * pointer.
5055 *
5056 * We do this by looking for media with our
5057 * PHY's `instance'.
5058 */
5059 for (ife = TAILQ_FIRST(&sc->sc_mii.mii_media.ifm_list);
5060 ife != NULL;
5061 ife = TAILQ_NEXT(ife, ifm_list)) {
5062 if (IFM_INST(ife->ifm_media) != phy->mii_inst)
5063 continue;
5064 ife->ifm_aux = tm;
5065 }
5066 break;
5067
5068 case TULIP_ROM_MB_21143_SYM:
5069 tlp_get_minst(sc);
5070 sc->sc_media_seen |= 1 << TULIP_ROM_MB_21143_SYM;
5071
5072 tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
5073
5074 tm->tm_type = TULIP_ROM_MB_21143_SYM;
5075 tm->tm_get = tlp_sia_get;
5076 tm->tm_set = tlp_sia_set;
5077
5078 /* First is the media type code. */
5079 tsti = tlp_srom_to_ifmedia(cp[0] &
5080 TULIP_ROM_MB_MEDIA_CODE);
5081 if (tsti == NULL) {
5082 /* Invalid media code. */
5083 free(tm, M_DEVBUF);
5084 break;
5085 }
5086
5087 /* Get defaults. */
5088 tlp_srom_media_info(sc, tsti, tm);
5089
5090 /* Next is GPIO control/data. */
5091 tm->tm_gpctl = TULIP_ROM_GETW(cp, 1) << 16;
5092 tm->tm_gpdata = TULIP_ROM_GETW(cp, 3) << 16;
5093
5094 /*
5095 * Next is a word containing OPMODE information
5096 * and info on how to detect if this media is
5097 * active.
5098 */
5099 word = TULIP_ROM_GETW(cp, 5);
5100 tm->tm_opmode &= OPMODE_FD;
5101 tm->tm_opmode |= TULIP_ROM_MB_OPMODE(word);
5102 if ((word & TULIP_ROM_MB_NOINDICATOR) == 0) {
5103 tm->tm_actmask =
5104 TULIP_ROM_MB_BITPOS(word);
5105 tm->tm_actdata =
5106 (word & TULIP_ROM_MB_POLARITY) ?
5107 0 : tm->tm_actmask;
5108 }
5109
5110 ifmedia_add(&sc->sc_mii.mii_media,
5111 IFM_MAKEWORD(IFM_ETHER, tsti->tsti_subtype,
5112 tsti->tsti_options, sc->sc_tlp_minst), 0, tm);
5113 break;
5114
5115 case TULIP_ROM_MB_21143_RESET:
5116 printf("%s: 21143 reset block\n", sc->sc_dev.dv_xname);
5117 break;
5118
5119 default:
5120 printf("%s: unknown ISV media block type 0x%02x\n",
5121 sc->sc_dev.dv_xname, type);
5122 }
5123 }
5124
5125 /*
5126 * Deal with the case where no media is configured.
5127 */
5128 if (TAILQ_FIRST(&sc->sc_mii.mii_media.ifm_list) == NULL) {
5129 printf("%s: no media found!\n", sc->sc_dev.dv_xname);
5130 ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
5131 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
5132 return;
5133 }
5134
5135 /*
5136 * Pick the default media.
5137 */
5138 if (miidef != 0)
5139 defmedia = miidef;
5140 else {
5141 switch (sc->sc_chip) {
5142 case TULIP_CHIP_21140:
5143 case TULIP_CHIP_21140A:
5144 /* XXX should come from SROM */
5145 defmedia = IFM_MAKEWORD(IFM_ETHER, IFM_10_T, 0, 0);
5146 if (ifmedia_match(&sc->sc_mii.mii_media, defmedia,
5147 sc->sc_mii.mii_media.ifm_mask) == NULL) {
5148 /*
5149 * There is not a 10baseT media.
5150 * Fall back to the first found one.
5151 */
5152 ife = TAILQ_FIRST(&sc->sc_mii.mii_media.ifm_list);
5153 defmedia = ife->ifm_media;
5154 }
5155 break;
5156
5157 case TULIP_CHIP_21142:
5158 case TULIP_CHIP_21143:
5159 case TULIP_CHIP_MX98713A:
5160 case TULIP_CHIP_MX98715:
5161 case TULIP_CHIP_MX98715A:
5162 case TULIP_CHIP_MX98715AEC_X:
5163 case TULIP_CHIP_MX98725:
5164 tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
5165 tm->tm_name = "auto";
5166 tm->tm_get = tlp_2114x_nway_get;
5167 tm->tm_set = tlp_2114x_nway_set;
5168
5169 defmedia = IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, 0);
5170 ifmedia_add(&sc->sc_mii.mii_media, defmedia, 0, tm);
5171
5172 sc->sc_statchg = tlp_2114x_nway_statchg;
5173 sc->sc_tick = tlp_2114x_nway_tick;
5174 break;
5175
5176 default:
5177 defmedia = IFM_MAKEWORD(IFM_ETHER, IFM_10_T, 0, 0);
5178 break;
5179 }
5180 }
5181
5182 ifmedia_set(&sc->sc_mii.mii_media, defmedia);
5183
5184 /*
5185 * Display any non-MII media we've located.
5186 */
5187 if (sc->sc_media_seen &
5188 ~((1 << TULIP_ROM_MB_21140_MII) | (1 << TULIP_ROM_MB_21142_MII)))
5189 tlp_print_media(sc);
5190
5191 tlp_sia_fixup(sc);
5192 }
5193
5194 static void
5195 tlp_2114x_nway_get(struct tulip_softc *sc, struct ifmediareq *ifmr)
5196 {
5197
5198 (void) tlp_2114x_nway_service(sc, MII_POLLSTAT);
5199 ifmr->ifm_status = sc->sc_mii.mii_media_status;
5200 ifmr->ifm_active = sc->sc_mii.mii_media_active;
5201 }
5202
5203 static int
5204 tlp_2114x_nway_set(struct tulip_softc *sc)
5205 {
5206
5207 return (tlp_2114x_nway_service(sc, MII_MEDIACHG));
5208 }
5209
5210 static void
5211 tlp_2114x_nway_statchg(struct device *self)
5212 {
5213 struct tulip_softc *sc = (struct tulip_softc *)self;
5214 struct mii_data *mii = &sc->sc_mii;
5215 struct ifmedia_entry *ife;
5216
5217 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_NONE)
5218 return;
5219
5220 if ((ife = ifmedia_match(&mii->mii_media, mii->mii_media_active,
5221 mii->mii_media.ifm_mask)) == NULL) {
5222 printf("tlp_2114x_nway_statchg: no match for media 0x%x/0x%x\n",
5223 mii->mii_media_active, ~mii->mii_media.ifm_mask);
5224 panic("tlp_2114x_nway_statchg");
5225 }
5226
5227 tlp_sia_media(sc, ife);
5228 }
5229
5230 static void
5231 tlp_2114x_nway_tick(void *arg)
5232 {
5233 struct tulip_softc *sc = arg;
5234 struct mii_data *mii = &sc->sc_mii;
5235 int s, ticks;
5236
5237 if (!device_is_active(&sc->sc_dev))
5238 return;
5239
5240 s = splnet();
5241 tlp_2114x_nway_service(sc, MII_TICK);
5242 if ((sc->sc_flags & TULIPF_LINK_UP) == 0 &&
5243 (mii->mii_media_status & IFM_ACTIVE) != 0 &&
5244 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
5245 sc->sc_flags |= TULIPF_LINK_UP;
5246 tlp_start(&sc->sc_ethercom.ec_if);
5247 } else if ((sc->sc_flags & TULIPF_LINK_UP) != 0 &&
5248 (mii->mii_media_status & IFM_ACTIVE) == 0) {
5249 sc->sc_flags &= ~TULIPF_LINK_UP;
5250 }
5251 splx(s);
5252
5253 if ((sc->sc_flags & TULIPF_LINK_UP) == 0)
5254 ticks = hz >> 3;
5255 else
5256 ticks = hz;
5257 callout_reset(&sc->sc_tick_callout, ticks, tlp_2114x_nway_tick, sc);
5258 }
5259
5260 /*
5261 * Support for the 2114X internal NWay block. This is constructed
5262 * somewhat like a PHY driver for simplicity.
5263 */
5264
5265 static int
5266 tlp_2114x_nway_service(struct tulip_softc *sc, int cmd)
5267 {
5268 struct mii_data *mii = &sc->sc_mii;
5269 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
5270
5271 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
5272 return (0);
5273
5274 switch (cmd) {
5275 case MII_POLLSTAT:
5276 /* Nothing special to do here. */
5277 break;
5278
5279 case MII_MEDIACHG:
5280 switch (IFM_SUBTYPE(ife->ifm_media)) {
5281 case IFM_AUTO:
5282 goto restart;
5283 default:
5284 /* Manual setting doesn't go through here. */
5285 printf("tlp_2114x_nway_service: oops!\n");
5286 return (EINVAL);
5287 }
5288 break;
5289
5290 case MII_TICK:
5291 /*
5292 * Only used for autonegotiation.
5293 */
5294 if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
5295 break;
5296
5297 /*
5298 * Check to see if we have link. If we do, we don't
5299 * need to restart the autonegotiation process.
5300 */
5301 #if 0
5302 if (mii->mii_media_status & IFM_ACTIVE)
5303 #else
5304 if (sc->sc_flags & TULIPF_LINK_UP)
5305 #endif
5306 break;
5307
5308 /*
5309 * Only retry autonegotiation every 5 seconds.
5310 */
5311 if (++sc->sc_nway_ticks != (5 << 3))
5312 break;
5313
5314 restart:
5315 sc->sc_nway_ticks = 0;
5316 ife->ifm_data = IFM_NONE;
5317 tlp_2114x_nway_auto(sc);
5318 break;
5319 }
5320
5321 /* Update the media status. */
5322 tlp_2114x_nway_status(sc);
5323
5324 /*
5325 * Callback if something changed. Manually configuration goes through
5326 * tlp_sia_set() anyway, so ignore that here.
5327 */
5328 if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO &&
5329 ife->ifm_data != mii->mii_media_active) {
5330 (*sc->sc_statchg)(&sc->sc_dev);
5331 ife->ifm_data = mii->mii_media_active;
5332 }
5333 return (0);
5334 }
5335
5336 static void
5337 tlp_2114x_nway_auto(struct tulip_softc *sc)
5338 {
5339 uint32_t siastat, siatxrx;
5340
5341 tlp_idle(sc, OPMODE_ST|OPMODE_SR);
5342
5343 sc->sc_opmode &= ~(OPMODE_PS|OPMODE_PCS|OPMODE_SCR|OPMODE_FD);
5344 sc->sc_opmode |= OPMODE_TTM|OPMODE_HBD;
5345 siatxrx = 0xffbf; /* XXX magic number */
5346
5347 /* Compute the link code word to advertise. */
5348 if (sc->sc_sia_cap & BMSR_100T4)
5349 siatxrx |= SIATXRX_T4;
5350 if (sc->sc_sia_cap & BMSR_100TXFDX)
5351 siatxrx |= SIATXRX_TXF;
5352 if (sc->sc_sia_cap & BMSR_100TXHDX)
5353 siatxrx |= SIATXRX_THX;
5354 if (sc->sc_sia_cap & BMSR_10TFDX)
5355 sc->sc_opmode |= OPMODE_FD;
5356 if (sc->sc_sia_cap & BMSR_10THDX)
5357 siatxrx |= SIATXRX_TH;
5358
5359 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
5360
5361 TULIP_WRITE(sc, CSR_SIACONN, 0);
5362 delay(1000);
5363 TULIP_WRITE(sc, CSR_SIATXRX, siatxrx);
5364 TULIP_WRITE(sc, CSR_SIACONN, SIACONN_SRL);
5365
5366 siastat = TULIP_READ(sc, CSR_SIASTAT);
5367 siastat &= ~(SIASTAT_ANS|SIASTAT_LPC|SIASTAT_TRA|SIASTAT_ARA|
5368 SIASTAT_LS100|SIASTAT_LS10|SIASTAT_MRA);
5369 siastat |= SIASTAT_ANS_TXDIS;
5370 TULIP_WRITE(sc, CSR_SIASTAT, siastat);
5371 }
5372
5373 static void
5374 tlp_2114x_nway_status(struct tulip_softc *sc)
5375 {
5376 struct mii_data *mii = &sc->sc_mii;
5377 uint32_t siatxrx, siastat, anlpar;
5378
5379 mii->mii_media_status = IFM_AVALID;
5380 mii->mii_media_active = IFM_ETHER;
5381
5382 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
5383 return;
5384
5385 siastat = TULIP_READ(sc, CSR_SIASTAT);
5386 siatxrx = TULIP_READ(sc, CSR_SIATXRX);
5387
5388 if (siatxrx & SIATXRX_ANE) {
5389 if ((siastat & SIASTAT_ANS) != SIASTAT_ANS_FLPGOOD) {
5390 /* Erg, still trying, I guess... */
5391 mii->mii_media_active |= IFM_NONE;
5392 return;
5393 }
5394
5395 if (~siastat & (SIASTAT_LS10 | SIASTAT_LS100))
5396 mii->mii_media_status |= IFM_ACTIVE;
5397
5398 if (siastat & SIASTAT_LPN) {
5399 anlpar = SIASTAT_GETLPC(siastat);
5400 if (anlpar & ANLPAR_T4 &&
5401 sc->sc_sia_cap & BMSR_100T4)
5402 mii->mii_media_active |= IFM_100_T4;
5403 else if (anlpar & ANLPAR_TX_FD &&
5404 sc->sc_sia_cap & BMSR_100TXFDX)
5405 mii->mii_media_active |= IFM_100_TX|IFM_FDX;
5406 else if (anlpar & ANLPAR_TX &&
5407 sc->sc_sia_cap & BMSR_100TXHDX)
5408 mii->mii_media_active |= IFM_100_TX;
5409 else if (anlpar & ANLPAR_10_FD &&
5410 sc->sc_sia_cap & BMSR_10TFDX)
5411 mii->mii_media_active |= IFM_10_T|IFM_FDX;
5412 else if (anlpar & ANLPAR_10 &&
5413 sc->sc_sia_cap & BMSR_10THDX)
5414 mii->mii_media_active |= IFM_10_T;
5415 else
5416 mii->mii_media_active |= IFM_NONE;
5417 } else {
5418 /*
5419 * If the other side doesn't support NWAY, then the
5420 * best we can do is determine if we have a 10Mbps or
5421 * 100Mbps link. There's no way to know if the link
5422 * is full or half duplex, so we default to half duplex
5423 * and hope that the user is clever enough to manually
5424 * change the media settings if we're wrong.
5425 */
5426 if ((siastat & SIASTAT_LS100) == 0)
5427 mii->mii_media_active |= IFM_100_TX;
5428 else if ((siastat & SIASTAT_LS10) == 0)
5429 mii->mii_media_active |= IFM_10_T;
5430 else
5431 mii->mii_media_active |= IFM_NONE;
5432 }
5433 } else {
5434 if (~siastat & (SIASTAT_LS10 | SIASTAT_LS100))
5435 mii->mii_media_status |= IFM_ACTIVE;
5436
5437 if (sc->sc_opmode & OPMODE_TTM)
5438 mii->mii_media_active |= IFM_10_T;
5439 else
5440 mii->mii_media_active |= IFM_100_TX;
5441 if (sc->sc_opmode & OPMODE_FD)
5442 mii->mii_media_active |= IFM_FDX;
5443 }
5444 }
5445
5446 static void
5447 tlp_2114x_isv_tmsw_get(struct tulip_softc *sc, struct ifmediareq *ifmr)
5448 {
5449 struct ifmedia_entry *ife = sc->sc_mii.mii_media.ifm_cur;
5450 struct tulip_21x4x_media *tm = ife->ifm_aux;
5451
5452 (*tm->tm_get)(sc, ifmr);
5453 }
5454
5455 static int
5456 tlp_2114x_isv_tmsw_set(struct tulip_softc *sc)
5457 {
5458 struct ifmedia_entry *ife = sc->sc_mii.mii_media.ifm_cur;
5459 struct tulip_21x4x_media *tm = ife->ifm_aux;
5460
5461 /*
5462 * Check to see if we need to reset the chip, and do it. The
5463 * reset path will get the OPMODE register right the next
5464 * time through.
5465 */
5466 if (TULIP_MEDIA_NEEDSRESET(sc, tm->tm_opmode))
5467 return (tlp_init(&sc->sc_ethercom.ec_if));
5468
5469 return ((*tm->tm_set)(sc));
5470 }
5471
5472 /*
5473 * MII-on-SIO media switch. Handles only MII attached to the SIO.
5474 */
5475 static void tlp_sio_mii_tmsw_init(struct tulip_softc *);
5476
5477 const struct tulip_mediasw tlp_sio_mii_mediasw = {
5478 tlp_sio_mii_tmsw_init, tlp_mii_getmedia, tlp_mii_setmedia
5479 };
5480
5481 static void
5482 tlp_sio_mii_tmsw_init(struct tulip_softc *sc)
5483 {
5484 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
5485
5486 /*
5487 * We don't attach any media info structures to the ifmedia
5488 * entries, so if we're using a pre-init function that needs
5489 * that info, override it to one that doesn't.
5490 */
5491 if (sc->sc_preinit == tlp_2114x_preinit)
5492 sc->sc_preinit = tlp_2114x_mii_preinit;
5493
5494 sc->sc_mii.mii_ifp = ifp;
5495 sc->sc_mii.mii_readreg = tlp_bitbang_mii_readreg;
5496 sc->sc_mii.mii_writereg = tlp_bitbang_mii_writereg;
5497 sc->sc_mii.mii_statchg = sc->sc_statchg;
5498 ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
5499 tlp_mediastatus);
5500 mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
5501 MII_OFFSET_ANY, 0);
5502 if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
5503 ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
5504 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
5505 } else {
5506 sc->sc_flags |= TULIPF_HAS_MII;
5507 sc->sc_tick = tlp_mii_tick;
5508 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
5509 }
5510 }
5511
5512 /*
5513 * Lite-On PNIC media switch. Must handle MII or internal NWAY.
5514 */
5515 static void tlp_pnic_tmsw_init(struct tulip_softc *);
5516 static void tlp_pnic_tmsw_get(struct tulip_softc *, struct ifmediareq *);
5517 static int tlp_pnic_tmsw_set(struct tulip_softc *);
5518
5519 const struct tulip_mediasw tlp_pnic_mediasw = {
5520 tlp_pnic_tmsw_init, tlp_pnic_tmsw_get, tlp_pnic_tmsw_set
5521 };
5522
5523 static void tlp_pnic_nway_statchg(struct device *);
5524 static void tlp_pnic_nway_tick(void *);
5525 static int tlp_pnic_nway_service(struct tulip_softc *, int);
5526 static void tlp_pnic_nway_reset(struct tulip_softc *);
5527 static int tlp_pnic_nway_auto(struct tulip_softc *, int);
5528 static void tlp_pnic_nway_auto_timeout(void *);
5529 static void tlp_pnic_nway_status(struct tulip_softc *);
5530 static void tlp_pnic_nway_acomp(struct tulip_softc *);
5531
5532 static void
5533 tlp_pnic_tmsw_init(struct tulip_softc *sc)
5534 {
5535 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
5536 const char *sep = "";
5537
5538 #define ADD(m, c) ifmedia_add(&sc->sc_mii.mii_media, (m), (c), NULL)
5539 #define PRINT(str) printf("%s%s", sep, str); sep = ", "
5540
5541 sc->sc_mii.mii_ifp = ifp;
5542 sc->sc_mii.mii_readreg = tlp_pnic_mii_readreg;
5543 sc->sc_mii.mii_writereg = tlp_pnic_mii_writereg;
5544 sc->sc_mii.mii_statchg = sc->sc_statchg;
5545 ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
5546 tlp_mediastatus);
5547 mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
5548 MII_OFFSET_ANY, 0);
5549 if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
5550 /* XXX What about AUI/BNC support? */
5551 printf("%s: ", sc->sc_dev.dv_xname);
5552
5553 tlp_pnic_nway_reset(sc);
5554
5555 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_T, 0, 0),
5556 PNIC_NWAY_TW|PNIC_NWAY_CAP10T);
5557 PRINT("10baseT");
5558
5559 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_T, IFM_FDX, 0),
5560 PNIC_NWAY_TW|PNIC_NWAY_FD|PNIC_NWAY_CAP10TFDX);
5561 PRINT("10baseT-FDX");
5562
5563 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, 0, 0),
5564 PNIC_NWAY_TW|PNIC_NWAY_100|PNIC_NWAY_CAP100TX);
5565 PRINT("100baseTX");
5566
5567 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_FDX, 0),
5568 PNIC_NWAY_TW|PNIC_NWAY_100|PNIC_NWAY_FD|
5569 PNIC_NWAY_CAP100TXFDX);
5570 PRINT("100baseTX-FDX");
5571
5572 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, 0),
5573 PNIC_NWAY_TW|PNIC_NWAY_RN|PNIC_NWAY_NW|
5574 PNIC_NWAY_CAP10T|PNIC_NWAY_CAP10TFDX|
5575 PNIC_NWAY_CAP100TXFDX|PNIC_NWAY_CAP100TX);
5576 PRINT("auto");
5577
5578 printf("\n");
5579
5580 sc->sc_statchg = tlp_pnic_nway_statchg;
5581 sc->sc_tick = tlp_pnic_nway_tick;
5582 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
5583 } else {
5584 sc->sc_flags |= TULIPF_HAS_MII;
5585 sc->sc_tick = tlp_mii_tick;
5586 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
5587 }
5588
5589 #undef ADD
5590 #undef PRINT
5591 }
5592
5593 static void
5594 tlp_pnic_tmsw_get(struct tulip_softc *sc, struct ifmediareq *ifmr)
5595 {
5596 struct mii_data *mii = &sc->sc_mii;
5597
5598 if (sc->sc_flags & TULIPF_HAS_MII)
5599 tlp_mii_getmedia(sc, ifmr);
5600 else {
5601 mii->mii_media_status = 0;
5602 mii->mii_media_active = IFM_NONE;
5603 tlp_pnic_nway_service(sc, MII_POLLSTAT);
5604 ifmr->ifm_status = sc->sc_mii.mii_media_status;
5605 ifmr->ifm_active = sc->sc_mii.mii_media_active;
5606 }
5607 }
5608
5609 static int
5610 tlp_pnic_tmsw_set(struct tulip_softc *sc)
5611 {
5612 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
5613 struct mii_data *mii = &sc->sc_mii;
5614
5615 if (sc->sc_flags & TULIPF_HAS_MII) {
5616 /*
5617 * Make sure the built-in Tx jabber timer is disabled.
5618 */
5619 TULIP_WRITE(sc, CSR_PNIC_ENDEC, PNIC_ENDEC_JDIS);
5620
5621 return (tlp_mii_setmedia(sc));
5622 }
5623
5624 if (ifp->if_flags & IFF_UP) {
5625 mii->mii_media_status = 0;
5626 mii->mii_media_active = IFM_NONE;
5627 return (tlp_pnic_nway_service(sc, MII_MEDIACHG));
5628 }
5629
5630 return (0);
5631 }
5632
5633 static void
5634 tlp_pnic_nway_statchg(struct device *self)
5635 {
5636 struct tulip_softc *sc = (struct tulip_softc *)self;
5637
5638 /* Idle the transmit and receive processes. */
5639 tlp_idle(sc, OPMODE_ST|OPMODE_SR);
5640
5641 sc->sc_opmode &= ~(OPMODE_TTM|OPMODE_FD|OPMODE_PS|OPMODE_PCS|
5642 OPMODE_SCR|OPMODE_HBD);
5643
5644 if (IFM_SUBTYPE(sc->sc_mii.mii_media_active) == IFM_10_T) {
5645 sc->sc_opmode |= OPMODE_TTM;
5646 TULIP_WRITE(sc, CSR_GPP,
5647 GPP_PNIC_OUT(GPP_PNIC_PIN_SPEED_RLY, 0) |
5648 GPP_PNIC_OUT(GPP_PNIC_PIN_100M_LPKB, 1));
5649 } else {
5650 sc->sc_opmode |= OPMODE_PS|OPMODE_PCS|OPMODE_SCR|OPMODE_HBD;
5651 TULIP_WRITE(sc, CSR_GPP,
5652 GPP_PNIC_OUT(GPP_PNIC_PIN_SPEED_RLY, 1) |
5653 GPP_PNIC_OUT(GPP_PNIC_PIN_100M_LPKB, 1));
5654 }
5655
5656 if (sc->sc_mii.mii_media_active & IFM_FDX)
5657 sc->sc_opmode |= OPMODE_FD|OPMODE_HBD;
5658
5659 /*
5660 * Write new OPMODE bits. This also restarts the transmit
5661 * and receive processes.
5662 */
5663 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
5664 }
5665
5666 static void
5667 tlp_pnic_nway_tick(void *arg)
5668 {
5669 struct tulip_softc *sc = arg;
5670 int s;
5671
5672 if (!device_is_active(&sc->sc_dev))
5673 return;
5674
5675 s = splnet();
5676 tlp_pnic_nway_service(sc, MII_TICK);
5677 splx(s);
5678
5679 callout_reset(&sc->sc_tick_callout, hz, tlp_pnic_nway_tick, sc);
5680 }
5681
5682 /*
5683 * Support for the Lite-On PNIC internal NWay block. This is constructed
5684 * somewhat like a PHY driver for simplicity.
5685 */
5686
5687 static int
5688 tlp_pnic_nway_service(struct tulip_softc *sc, int cmd)
5689 {
5690 struct mii_data *mii = &sc->sc_mii;
5691 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
5692
5693 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
5694 return (0);
5695
5696 switch (cmd) {
5697 case MII_POLLSTAT:
5698 /* Nothing special to do here. */
5699 break;
5700
5701 case MII_MEDIACHG:
5702 switch (IFM_SUBTYPE(ife->ifm_media)) {
5703 case IFM_AUTO:
5704 (void) tlp_pnic_nway_auto(sc, 1);
5705 break;
5706 case IFM_100_T4:
5707 /*
5708 * XXX Not supported as a manual setting right now.
5709 */
5710 return (EINVAL);
5711 default:
5712 /*
5713 * NWAY register data is stored in the ifmedia entry.
5714 */
5715 TULIP_WRITE(sc, CSR_PNIC_NWAY, ife->ifm_data);
5716 }
5717 break;
5718
5719 case MII_TICK:
5720 /*
5721 * Only used for autonegotiation.
5722 */
5723 if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
5724 return (0);
5725
5726 /*
5727 * Check to see if we have link. If we do, we don't
5728 * need to restart the autonegotiation process.
5729 */
5730 if (sc->sc_flags & TULIPF_LINK_UP)
5731 return (0);
5732
5733 /*
5734 * Only retry autonegotiation every 5 seconds.
5735 */
5736 if (++sc->sc_nway_ticks != 5)
5737 return (0);
5738
5739 sc->sc_nway_ticks = 0;
5740 tlp_pnic_nway_reset(sc);
5741 if (tlp_pnic_nway_auto(sc, 0) == EJUSTRETURN)
5742 return (0);
5743 break;
5744 }
5745
5746 /* Update the media status. */
5747 tlp_pnic_nway_status(sc);
5748
5749 /* Callback if something changed. */
5750 if ((sc->sc_nway_active == NULL ||
5751 sc->sc_nway_active->ifm_media != mii->mii_media_active) ||
5752 cmd == MII_MEDIACHG) {
5753 (*sc->sc_statchg)(&sc->sc_dev);
5754 tlp_nway_activate(sc, mii->mii_media_active);
5755 }
5756 return (0);
5757 }
5758
5759 static void
5760 tlp_pnic_nway_reset(struct tulip_softc *sc)
5761 {
5762
5763 TULIP_WRITE(sc, CSR_PNIC_NWAY, PNIC_NWAY_RS);
5764 delay(100);
5765 TULIP_WRITE(sc, CSR_PNIC_NWAY, 0);
5766 }
5767
5768 static int
5769 tlp_pnic_nway_auto(struct tulip_softc *sc, int waitfor)
5770 {
5771 struct mii_data *mii = &sc->sc_mii;
5772 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
5773 u_int32_t reg;
5774 int i;
5775
5776 if ((sc->sc_flags & TULIPF_DOINGAUTO) == 0)
5777 TULIP_WRITE(sc, CSR_PNIC_NWAY, ife->ifm_data);
5778
5779 if (waitfor) {
5780 /* Wait 500ms for it to complete. */
5781 for (i = 0; i < 500; i++) {
5782 reg = TULIP_READ(sc, CSR_PNIC_NWAY);
5783 if (reg & PNIC_NWAY_LPAR_MASK) {
5784 tlp_pnic_nway_acomp(sc);
5785 return (0);
5786 }
5787 delay(1000);
5788 }
5789 #if 0
5790 if ((reg & PNIC_NWAY_LPAR_MASK) == 0)
5791 printf("%s: autonegotiation failed to complete\n",
5792 sc->sc_dev.dv_xname);
5793 #endif
5794
5795 /*
5796 * Don't need to worry about clearing DOINGAUTO.
5797 * If that's set, a timeout is pending, and it will
5798 * clear the flag.
5799 */
5800 return (EIO);
5801 }
5802
5803 /*
5804 * Just let it finish asynchronously. This is for the benefit of
5805 * the tick handler driving autonegotiation. Don't want 500ms
5806 * delays all the time while the system is running!
5807 */
5808 if ((sc->sc_flags & TULIPF_DOINGAUTO) == 0) {
5809 sc->sc_flags |= TULIPF_DOINGAUTO;
5810 callout_reset(&sc->sc_nway_callout, hz >> 1,
5811 tlp_pnic_nway_auto_timeout, sc);
5812 }
5813 return (EJUSTRETURN);
5814 }
5815
5816 static void
5817 tlp_pnic_nway_auto_timeout(void *arg)
5818 {
5819 struct tulip_softc *sc = arg;
5820 u_int32_t reg;
5821 int s;
5822
5823 s = splnet();
5824 sc->sc_flags &= ~TULIPF_DOINGAUTO;
5825 reg = TULIP_READ(sc, CSR_PNIC_NWAY);
5826 #if 0
5827 if ((reg & PNIC_NWAY_LPAR_MASK) == 0)
5828 printf("%s: autonegotiation failed to complete\n",
5829 sc->sc_dev.dv_xname);
5830 #endif
5831
5832 tlp_pnic_nway_acomp(sc);
5833
5834 /* Update the media status. */
5835 (void) tlp_pnic_nway_service(sc, MII_POLLSTAT);
5836 splx(s);
5837 }
5838
5839 static void
5840 tlp_pnic_nway_status(struct tulip_softc *sc)
5841 {
5842 struct mii_data *mii = &sc->sc_mii;
5843 u_int32_t reg;
5844
5845 mii->mii_media_status = IFM_AVALID;
5846 mii->mii_media_active = IFM_ETHER;
5847
5848 reg = TULIP_READ(sc, CSR_PNIC_NWAY);
5849
5850 if (sc->sc_flags & TULIPF_LINK_UP)
5851 mii->mii_media_status |= IFM_ACTIVE;
5852
5853 if (reg & PNIC_NWAY_NW) {
5854 if ((reg & PNIC_NWAY_LPAR_MASK) == 0) {
5855 /* Erg, still trying, I guess... */
5856 mii->mii_media_active |= IFM_NONE;
5857 return;
5858 }
5859
5860 #if 0
5861 if (reg & PNIC_NWAY_LPAR100T4)
5862 mii->mii_media_active |= IFM_100_T4;
5863 else
5864 #endif
5865 if (reg & PNIC_NWAY_LPAR100TXFDX)
5866 mii->mii_media_active |= IFM_100_TX|IFM_FDX;
5867 else if (reg & PNIC_NWAY_LPAR100TX)
5868 mii->mii_media_active |= IFM_100_TX;
5869 else if (reg & PNIC_NWAY_LPAR10TFDX)
5870 mii->mii_media_active |= IFM_10_T|IFM_FDX;
5871 else if (reg & PNIC_NWAY_LPAR10T)
5872 mii->mii_media_active |= IFM_10_T;
5873 else
5874 mii->mii_media_active |= IFM_NONE;
5875 } else {
5876 if (reg & PNIC_NWAY_100)
5877 mii->mii_media_active |= IFM_100_TX;
5878 else
5879 mii->mii_media_active |= IFM_10_T;
5880 if (reg & PNIC_NWAY_FD)
5881 mii->mii_media_active |= IFM_FDX;
5882 }
5883 }
5884
5885 static void
5886 tlp_pnic_nway_acomp(struct tulip_softc *sc)
5887 {
5888 u_int32_t reg;
5889
5890 reg = TULIP_READ(sc, CSR_PNIC_NWAY);
5891 reg &= ~(PNIC_NWAY_FD|PNIC_NWAY_100|PNIC_NWAY_RN);
5892
5893 if (reg & (PNIC_NWAY_LPAR100TXFDX|PNIC_NWAY_LPAR100TX))
5894 reg |= PNIC_NWAY_100;
5895 if (reg & (PNIC_NWAY_LPAR10TFDX|PNIC_NWAY_LPAR100TXFDX))
5896 reg |= PNIC_NWAY_FD;
5897
5898 TULIP_WRITE(sc, CSR_PNIC_NWAY, reg);
5899 }
5900
5901 /*
5902 * Macronix PMAC and Lite-On PNIC-II media switch:
5903 *
5904 * MX98713 and MX98713A 21140-like MII or GPIO media.
5905 *
5906 * MX98713A 21143-like MII or SIA/SYM media.
5907 *
5908 * MX98715, MX98715A, MX98725, 21143-like SIA/SYM media.
5909 * 82C115, MX98715AEC-C, -E
5910 *
5911 * So, what we do here is fake MII-on-SIO or ISV media info, and
5912 * use the ISV media switch get/set functions to handle the rest.
5913 */
5914
5915 static void tlp_pmac_tmsw_init(struct tulip_softc *);
5916
5917 const struct tulip_mediasw tlp_pmac_mediasw = {
5918 tlp_pmac_tmsw_init, tlp_2114x_isv_tmsw_get, tlp_2114x_isv_tmsw_set
5919 };
5920
5921 const struct tulip_mediasw tlp_pmac_mii_mediasw = {
5922 tlp_pmac_tmsw_init, tlp_mii_getmedia, tlp_mii_setmedia
5923 };
5924
5925 static void
5926 tlp_pmac_tmsw_init(struct tulip_softc *sc)
5927 {
5928 static const u_int8_t media[] = {
5929 TULIP_ROM_MB_MEDIA_TP,
5930 TULIP_ROM_MB_MEDIA_TP_FDX,
5931 TULIP_ROM_MB_MEDIA_100TX,
5932 TULIP_ROM_MB_MEDIA_100TX_FDX,
5933 };
5934 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
5935 struct tulip_21x4x_media *tm;
5936
5937 sc->sc_mii.mii_ifp = ifp;
5938 sc->sc_mii.mii_readreg = tlp_bitbang_mii_readreg;
5939 sc->sc_mii.mii_writereg = tlp_bitbang_mii_writereg;
5940 sc->sc_mii.mii_statchg = sc->sc_statchg;
5941 ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
5942 tlp_mediastatus);
5943 if (sc->sc_chip == TULIP_CHIP_MX98713 ||
5944 sc->sc_chip == TULIP_CHIP_MX98713A) {
5945 mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff,
5946 MII_PHY_ANY, MII_OFFSET_ANY, 0);
5947 if (LIST_FIRST(&sc->sc_mii.mii_phys) != NULL) {
5948 sc->sc_flags |= TULIPF_HAS_MII;
5949 sc->sc_tick = tlp_mii_tick;
5950 sc->sc_preinit = tlp_2114x_mii_preinit;
5951 sc->sc_mediasw = &tlp_pmac_mii_mediasw;
5952 ifmedia_set(&sc->sc_mii.mii_media,
5953 IFM_ETHER|IFM_AUTO);
5954 return;
5955 }
5956 }
5957
5958 switch (sc->sc_chip) {
5959 case TULIP_CHIP_MX98713:
5960 tlp_add_srom_media(sc, TULIP_ROM_MB_21140_GPR,
5961 tlp_21140_gpio_get, tlp_21140_gpio_set, media, 4);
5962
5963 /*
5964 * XXX Should implement auto-sense for this someday,
5965 * XXX when we do the same for the 21140.
5966 */
5967 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_10_T);
5968 break;
5969
5970 default:
5971 tlp_add_srom_media(sc, TULIP_ROM_MB_21142_SIA,
5972 tlp_sia_get, tlp_sia_set, media, 2);
5973 tlp_add_srom_media(sc, TULIP_ROM_MB_21143_SYM,
5974 tlp_sia_get, tlp_sia_set, media + 2, 2);
5975
5976 tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
5977 tm->tm_name = "auto";
5978 tm->tm_get = tlp_2114x_nway_get;
5979 tm->tm_set = tlp_2114x_nway_set;
5980 ifmedia_add(&sc->sc_mii.mii_media,
5981 IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, 0), 0, tm);
5982
5983 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
5984 sc->sc_statchg = tlp_2114x_nway_statchg;
5985 sc->sc_tick = tlp_2114x_nway_tick;
5986 break;
5987 }
5988
5989 tlp_print_media(sc);
5990 tlp_sia_fixup(sc);
5991
5992 /* Set the LED modes. */
5993 tlp_pmac_reset(sc);
5994
5995 sc->sc_reset = tlp_pmac_reset;
5996 }
5997
5998 /*
5999 * ADMtek AL981 media switch. Only has internal PHY.
6000 */
6001 static void tlp_al981_tmsw_init(struct tulip_softc *);
6002
6003 const struct tulip_mediasw tlp_al981_mediasw = {
6004 tlp_al981_tmsw_init, tlp_mii_getmedia, tlp_mii_setmedia
6005 };
6006
6007 static void
6008 tlp_al981_tmsw_init(struct tulip_softc *sc)
6009 {
6010 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
6011
6012 sc->sc_mii.mii_ifp = ifp;
6013 sc->sc_mii.mii_readreg = tlp_al981_mii_readreg;
6014 sc->sc_mii.mii_writereg = tlp_al981_mii_writereg;
6015 sc->sc_mii.mii_statchg = sc->sc_statchg;
6016 ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
6017 tlp_mediastatus);
6018 mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
6019 MII_OFFSET_ANY, 0);
6020 if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
6021 ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
6022 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
6023 } else {
6024 sc->sc_flags |= TULIPF_HAS_MII;
6025 sc->sc_tick = tlp_mii_tick;
6026 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
6027 }
6028 }
6029
6030 /*
6031 * ADMtek AN983/985 media switch. Only has internal PHY, but
6032 * on an SIO-like interface. Unfortunately, we can't use the
6033 * standard SIO media switch, because the AN985 "ghosts" the
6034 * singly PHY at every address.
6035 */
6036 static void tlp_an985_tmsw_init(struct tulip_softc *);
6037
6038 const struct tulip_mediasw tlp_an985_mediasw = {
6039 tlp_an985_tmsw_init, tlp_mii_getmedia, tlp_mii_setmedia
6040 };
6041
6042 static void
6043 tlp_an985_tmsw_init(struct tulip_softc *sc)
6044 {
6045 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
6046
6047 sc->sc_mii.mii_ifp = ifp;
6048 sc->sc_mii.mii_readreg = tlp_bitbang_mii_readreg;
6049 sc->sc_mii.mii_writereg = tlp_bitbang_mii_writereg;
6050 sc->sc_mii.mii_statchg = sc->sc_statchg;
6051 ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
6052 tlp_mediastatus);
6053 mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff, 1,
6054 MII_OFFSET_ANY, 0);
6055 if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
6056 ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
6057 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
6058 } else {
6059 sc->sc_flags |= TULIPF_HAS_MII;
6060 sc->sc_tick = tlp_mii_tick;
6061 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
6062 }
6063 }
6064
6065 /*
6066 * Davicom DM9102 media switch. Internal PHY and possibly HomePNA.
6067 */
6068 static void tlp_dm9102_tmsw_init(struct tulip_softc *);
6069 static void tlp_dm9102_tmsw_getmedia(struct tulip_softc *,
6070 struct ifmediareq *);
6071 static int tlp_dm9102_tmsw_setmedia(struct tulip_softc *);
6072
6073 const struct tulip_mediasw tlp_dm9102_mediasw = {
6074 tlp_dm9102_tmsw_init, tlp_dm9102_tmsw_getmedia,
6075 tlp_dm9102_tmsw_setmedia
6076 };
6077
6078 static void
6079 tlp_dm9102_tmsw_init(struct tulip_softc *sc)
6080 {
6081 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
6082 u_int32_t opmode;
6083
6084 sc->sc_mii.mii_ifp = ifp;
6085 sc->sc_mii.mii_readreg = tlp_bitbang_mii_readreg;
6086 sc->sc_mii.mii_writereg = tlp_bitbang_mii_writereg;
6087 sc->sc_mii.mii_statchg = sc->sc_statchg;
6088 ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
6089 tlp_mediastatus);
6090
6091 /* PHY block already reset via tlp_reset(). */
6092
6093 /*
6094 * Configure OPMODE properly for the internal MII interface.
6095 */
6096 switch (sc->sc_chip) {
6097 case TULIP_CHIP_DM9102:
6098 opmode = OPMODE_MBO|OPMODE_HBD|OPMODE_PS;
6099 break;
6100
6101 case TULIP_CHIP_DM9102A:
6102 opmode = OPMODE_MBO|OPMODE_HBD;
6103 break;
6104
6105 default:
6106 opmode = 0;
6107 break;
6108 }
6109
6110 TULIP_WRITE(sc, CSR_OPMODE, opmode);
6111
6112 /* Now, probe the internal MII for the internal PHY. */
6113 mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
6114 MII_OFFSET_ANY, 0);
6115
6116 /*
6117 * XXX Figure out what to do about the HomePNA portion
6118 * XXX of the DM9102A.
6119 */
6120
6121 if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
6122 ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
6123 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
6124 } else {
6125 sc->sc_flags |= TULIPF_HAS_MII;
6126 sc->sc_tick = tlp_mii_tick;
6127 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
6128 }
6129 }
6130
6131 static void
6132 tlp_dm9102_tmsw_getmedia(struct tulip_softc *sc, struct ifmediareq *ifmr)
6133 {
6134
6135 /* XXX HomePNA on DM9102A. */
6136 tlp_mii_getmedia(sc, ifmr);
6137 }
6138
6139 static int
6140 tlp_dm9102_tmsw_setmedia(struct tulip_softc *sc)
6141 {
6142
6143 /* XXX HomePNA on DM9102A. */
6144 return (tlp_mii_setmedia(sc));
6145 }
6146
6147 /*
6148 * ASIX AX88140A/AX88141 media switch. Internal PHY or MII.
6149 */
6150
6151 static void tlp_asix_tmsw_init(struct tulip_softc *);
6152 static void tlp_asix_tmsw_getmedia(struct tulip_softc *,
6153 struct ifmediareq *);
6154 static int tlp_asix_tmsw_setmedia(struct tulip_softc *);
6155
6156 const struct tulip_mediasw tlp_asix_mediasw = {
6157 tlp_asix_tmsw_init, tlp_asix_tmsw_getmedia,
6158 tlp_asix_tmsw_setmedia
6159 };
6160
6161 static void
6162 tlp_asix_tmsw_init(struct tulip_softc *sc)
6163 {
6164 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
6165 u_int32_t opmode;
6166
6167 sc->sc_mii.mii_ifp = ifp;
6168 sc->sc_mii.mii_readreg = tlp_bitbang_mii_readreg;
6169 sc->sc_mii.mii_writereg = tlp_bitbang_mii_writereg;
6170 sc->sc_mii.mii_statchg = sc->sc_statchg;
6171 ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
6172 tlp_mediastatus);
6173
6174 /*
6175 * Configure OPMODE properly for the internal MII interface.
6176 */
6177 switch (sc->sc_chip) {
6178 case TULIP_CHIP_AX88140:
6179 case TULIP_CHIP_AX88141:
6180 opmode = OPMODE_HBD|OPMODE_PS;
6181 break;
6182 default:
6183 opmode = 0;
6184 break;
6185 }
6186
6187 TULIP_WRITE(sc, CSR_OPMODE, opmode);
6188
6189 /* Now, probe the internal MII for the internal PHY. */
6190 mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
6191 MII_OFFSET_ANY, 0);
6192
6193 /* XXX Figure how to handle the PHY. */
6194
6195 if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
6196 ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
6197 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
6198 } else {
6199 sc->sc_flags |= TULIPF_HAS_MII;
6200 sc->sc_tick = tlp_mii_tick;
6201 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
6202 }
6203
6204
6205 }
6206
6207 static void
6208 tlp_asix_tmsw_getmedia(struct tulip_softc *sc, struct ifmediareq *ifmr)
6209 {
6210
6211 /* XXX PHY handling. */
6212 tlp_mii_getmedia(sc, ifmr);
6213 }
6214
6215 static int
6216 tlp_asix_tmsw_setmedia(struct tulip_softc *sc)
6217 {
6218
6219 /* XXX PHY handling. */
6220 return (tlp_mii_setmedia(sc));
6221 }
6222
6223 /*
6224 * RS7112 media switch. Handles only MII attached to the SIO.
6225 * We only have a PHY at 1.
6226 */
6227 void tlp_rs7112_tmsw_init(struct tulip_softc *);
6228
6229 const struct tulip_mediasw tlp_rs7112_mediasw = {
6230 tlp_rs7112_tmsw_init, tlp_mii_getmedia, tlp_mii_setmedia
6231 };
6232
6233 void
6234 tlp_rs7112_tmsw_init(struct tulip_softc *sc)
6235 {
6236 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
6237
6238 /*
6239 * We don't attach any media info structures to the ifmedia
6240 * entries, so if we're using a pre-init function that needs
6241 * that info, override it to one that doesn't.
6242 */
6243 if (sc->sc_preinit == tlp_2114x_preinit)
6244 sc->sc_preinit = tlp_2114x_mii_preinit;
6245
6246 sc->sc_mii.mii_ifp = ifp;
6247 sc->sc_mii.mii_readreg = tlp_bitbang_mii_readreg;
6248 sc->sc_mii.mii_writereg = tlp_bitbang_mii_writereg;
6249 sc->sc_mii.mii_statchg = sc->sc_statchg;
6250 ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
6251 tlp_mediastatus);
6252
6253 /*
6254 * The RS7112 reports a PHY at 0 (possibly HomePNA?)
6255 * and 1 (ethernet). We attach ethernet only.
6256 */
6257 mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff, 1,
6258 MII_OFFSET_ANY, 0);
6259
6260 if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
6261 ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
6262 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
6263 } else {
6264 sc->sc_flags |= TULIPF_HAS_MII;
6265 sc->sc_tick = tlp_mii_tick;
6266 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
6267 }
6268 }
6269