1 /* $NetBSD: tulip.c,v 1.172 2009/09/05 14:19:30 tsutsui Exp $ */
4 * Copyright (c) 1998, 1999, 2000, 2002 The NetBSD Foundation, Inc.
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.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * Device driver for the Digital Semiconductor ``Tulip'' (21x4x)
35 * Ethernet controller family, and a variety of clone chips.
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: tulip.c,v 1.172 2009/09/05 14:19:30 tsutsui Exp $");
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/callout.h>
47 #include <sys/malloc.h>
48 #include <sys/kernel.h>
49 #include <sys/socket.h>
50 #include <sys/ioctl.h>
51 #include <sys/errno.h>
52 #include <sys/device.h>
54 #include <machine/endian.h>
56 #include <uvm/uvm_extern.h>
59 #include <net/if_dl.h>
60 #include <net/if_media.h>
61 #include <net/if_ether.h>
70 #include <dev/mii/mii.h>
71 #include <dev/mii/miivar.h>
72 #include <dev/mii/mii_bitbang.h>
74 #include <dev/ic/tulipreg.h>
75 #include <dev/ic/tulipvar.h>
77 const char * const tlp_chip_names
[] = TULIP_CHIP_NAMES
;
79 static const struct tulip_txthresh_tab tlp_10_txthresh_tab
[] =
82 static const struct tulip_txthresh_tab tlp_10_100_txthresh_tab
[] =
83 TLP_TXTHRESH_TAB_10_100
;
85 static const struct tulip_txthresh_tab tlp_winb_txthresh_tab
[] =
86 TLP_TXTHRESH_TAB_WINB
;
88 static const struct tulip_txthresh_tab tlp_dm9102_txthresh_tab
[] =
89 TLP_TXTHRESH_TAB_DM9102
;
91 static void tlp_start(struct ifnet
*);
92 static void tlp_watchdog(struct ifnet
*);
93 static int tlp_ioctl(struct ifnet
*, u_long
, void *);
94 static int tlp_init(struct ifnet
*);
95 static void tlp_stop(struct ifnet
*, int);
96 static int tlp_ifflags_cb(struct ethercom
*);
98 static void tlp_rxdrain(struct tulip_softc
*);
99 static int tlp_add_rxbuf(struct tulip_softc
*, int);
100 static void tlp_srom_idle(struct tulip_softc
*);
101 static int tlp_srom_size(struct tulip_softc
*);
103 static int tlp_enable(struct tulip_softc
*);
104 static void tlp_disable(struct tulip_softc
*);
106 static void tlp_filter_setup(struct tulip_softc
*);
107 static void tlp_winb_filter_setup(struct tulip_softc
*);
108 static void tlp_al981_filter_setup(struct tulip_softc
*);
109 static void tlp_asix_filter_setup(struct tulip_softc
*);
111 static void tlp_rxintr(struct tulip_softc
*);
112 static void tlp_txintr(struct tulip_softc
*);
114 static void tlp_mii_tick(void *);
115 static void tlp_mii_statchg(device_t
);
116 static void tlp_winb_mii_statchg(device_t
);
117 static void tlp_dm9102_mii_statchg(device_t
);
119 static void tlp_mii_getmedia(struct tulip_softc
*, struct ifmediareq
*);
120 static int tlp_mii_setmedia(struct tulip_softc
*);
122 static int tlp_bitbang_mii_readreg(device_t
, int, int);
123 static void tlp_bitbang_mii_writereg(device_t
, int, int, int);
125 static int tlp_pnic_mii_readreg(device_t
, int, int);
126 static void tlp_pnic_mii_writereg(device_t
, int, int, int);
128 static int tlp_al981_mii_readreg(device_t
, int, int);
129 static void tlp_al981_mii_writereg(device_t
, int, int, int);
131 static void tlp_2114x_preinit(struct tulip_softc
*);
132 static void tlp_2114x_mii_preinit(struct tulip_softc
*);
133 static void tlp_pnic_preinit(struct tulip_softc
*);
134 static void tlp_dm9102_preinit(struct tulip_softc
*);
135 static void tlp_asix_preinit(struct tulip_softc
*);
137 static void tlp_21140_reset(struct tulip_softc
*);
138 static void tlp_21142_reset(struct tulip_softc
*);
139 static void tlp_pmac_reset(struct tulip_softc
*);
141 static void tlp_dm9102_reset(struct tulip_softc
*);
144 static void tlp_2114x_nway_tick(void *);
146 #define tlp_mchash(addr, sz) \
147 (ether_crc32_le((addr), ETHER_ADDR_LEN) & ((sz) - 1))
152 static uint32_t tlp_sio_mii_bitbang_read(device_t
);
153 static void tlp_sio_mii_bitbang_write(device_t
, uint32_t);
155 static const struct mii_bitbang_ops tlp_sio_mii_bitbang_ops
= {
156 tlp_sio_mii_bitbang_read
,
157 tlp_sio_mii_bitbang_write
,
159 MIIROM_MDO
, /* MII_BIT_MDO */
160 MIIROM_MDI
, /* MII_BIT_MDI */
161 MIIROM_MDC
, /* MII_BIT_MDC */
162 0, /* MII_BIT_DIR_HOST_PHY */
163 MIIROM_MIIDIR
, /* MII_BIT_DIR_PHY_HOST */
168 #define DPRINTF(sc, x) if ((sc)->sc_ethercom.ec_if.if_flags & IFF_DEBUG) \
171 #define DPRINTF(sc, x) /* nothing */
175 static void tlp_print_stats(struct tulip_softc
*);
179 * Can be used to debug the SROM-related things, including contents.
180 * Initialized so that it's patchable.
182 int tlp_srom_debug
= 0;
187 * Attach a Tulip interface to the system.
190 tlp_attach(struct tulip_softc
*sc
, const uint8_t *enaddr
)
192 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
193 device_t self
= sc
->sc_dev
;
196 callout_init(&sc
->sc_nway_callout
, 0);
197 callout_init(&sc
->sc_tick_callout
, 0);
200 * NOTE: WE EXPECT THE FRONT-END TO INITIALIZE sc_regshift!
204 * Setup the transmit threshold table.
206 switch (sc
->sc_chip
) {
207 case TULIP_CHIP_DE425
:
208 case TULIP_CHIP_21040
:
209 case TULIP_CHIP_21041
:
210 sc
->sc_txth
= tlp_10_txthresh_tab
;
213 case TULIP_CHIP_DM9102
:
214 case TULIP_CHIP_DM9102A
:
215 sc
->sc_txth
= tlp_dm9102_txthresh_tab
;
219 sc
->sc_txth
= tlp_10_100_txthresh_tab
;
224 * Setup the filter setup function.
226 switch (sc
->sc_chip
) {
227 case TULIP_CHIP_WB89C840F
:
228 sc
->sc_filter_setup
= tlp_winb_filter_setup
;
231 case TULIP_CHIP_AL981
:
232 case TULIP_CHIP_AN983
:
233 case TULIP_CHIP_AN985
:
234 sc
->sc_filter_setup
= tlp_al981_filter_setup
;
237 case TULIP_CHIP_AX88140
:
238 case TULIP_CHIP_AX88141
:
239 sc
->sc_filter_setup
= tlp_asix_filter_setup
;
243 sc
->sc_filter_setup
= tlp_filter_setup
;
248 * Set up the media status change function.
250 switch (sc
->sc_chip
) {
251 case TULIP_CHIP_WB89C840F
:
252 sc
->sc_statchg
= tlp_winb_mii_statchg
;
255 case TULIP_CHIP_DM9102
:
256 case TULIP_CHIP_DM9102A
:
257 sc
->sc_statchg
= tlp_dm9102_mii_statchg
;
262 * We may override this if we have special media
263 * handling requirements (e.g. flipping GPIO pins).
265 * The pure-MII statchg function covers the basics.
267 sc
->sc_statchg
= tlp_mii_statchg
;
272 * Default to no FS|LS in setup packet descriptors. They're
273 * supposed to be zero according to the 21040 and 21143
274 * manuals, and some chips fall over badly if they're
275 * included. Yet, other chips seem to require them. Sigh.
277 switch (sc
->sc_chip
) {
278 case TULIP_CHIP_X3201_3
:
279 sc
->sc_setup_fsls
= TDCTL_Tx_FS
|TDCTL_Tx_LS
;
283 sc
->sc_setup_fsls
= 0;
287 * Set up various chip-specific quirks.
289 * Note that wherever we can, we use the "ring" option for
290 * transmit and receive descriptors. This is because some
291 * clone chips apparently have problems when using chaining,
292 * although some *only* support chaining.
294 * What we do is always program the "next" pointer, and then
295 * conditionally set the TDCTL_CH and TDCTL_ER bits in the
296 * appropriate places.
298 switch (sc
->sc_chip
) {
299 case TULIP_CHIP_21140
:
300 case TULIP_CHIP_21140A
:
301 case TULIP_CHIP_21142
:
302 case TULIP_CHIP_21143
:
303 case TULIP_CHIP_82C115
: /* 21143-like */
304 case TULIP_CHIP_MX98713
: /* 21140-like */
305 case TULIP_CHIP_MX98713A
: /* 21143-like */
306 case TULIP_CHIP_MX98715
: /* 21143-like */
307 case TULIP_CHIP_MX98715A
: /* 21143-like */
308 case TULIP_CHIP_MX98715AEC_X
: /* 21143-like */
309 case TULIP_CHIP_MX98725
: /* 21143-like */
310 case TULIP_CHIP_RS7112
: /* 21143-like */
312 * Run these chips in ring mode.
315 sc
->sc_tdctl_er
= TDCTL_ER
;
316 sc
->sc_preinit
= tlp_2114x_preinit
;
319 case TULIP_CHIP_82C168
:
320 case TULIP_CHIP_82C169
:
322 * Run these chips in ring mode.
325 sc
->sc_tdctl_er
= TDCTL_ER
;
326 sc
->sc_preinit
= tlp_pnic_preinit
;
329 * These chips seem to have busted DMA engines; just put them
330 * in Store-and-Forward mode from the get-go.
332 sc
->sc_txthresh
= TXTH_SF
;
335 case TULIP_CHIP_WB89C840F
:
337 * Run this chip in chained mode.
339 sc
->sc_tdctl_ch
= TDCTL_CH
;
341 sc
->sc_flags
|= TULIPF_IC_FS
;
344 case TULIP_CHIP_DM9102
:
345 case TULIP_CHIP_DM9102A
:
347 * Run these chips in chained mode.
349 sc
->sc_tdctl_ch
= TDCTL_CH
;
351 sc
->sc_preinit
= tlp_dm9102_preinit
;
354 * These chips have a broken bus interface, so we
355 * can't use any optimized bus commands. For this
356 * reason, we tend to underrun pretty quickly, so
357 * just to Store-and-Forward mode from the get-go.
359 sc
->sc_txthresh
= TXTH_DM9102_SF
;
362 case TULIP_CHIP_AX88140
:
363 case TULIP_CHIP_AX88141
:
365 * Run these chips in ring mode.
368 sc
->sc_tdctl_er
= TDCTL_ER
;
369 sc
->sc_preinit
= tlp_asix_preinit
;
374 * Default to running in ring mode.
377 sc
->sc_tdctl_er
= TDCTL_ER
;
381 * Set up the MII bit-bang operations.
383 switch (sc
->sc_chip
) {
384 case TULIP_CHIP_WB89C840F
: /* XXX direction bit different? */
385 sc
->sc_bitbang_ops
= &tlp_sio_mii_bitbang_ops
;
389 sc
->sc_bitbang_ops
= &tlp_sio_mii_bitbang_ops
;
392 SIMPLEQ_INIT(&sc
->sc_txfreeq
);
393 SIMPLEQ_INIT(&sc
->sc_txdirtyq
);
396 * Allocate the control data structures, and create and load the
399 if ((error
= bus_dmamem_alloc(sc
->sc_dmat
,
400 sizeof(struct tulip_control_data
), PAGE_SIZE
, 0, &sc
->sc_cdseg
,
401 1, &sc
->sc_cdnseg
, 0)) != 0) {
402 aprint_error_dev(self
, "unable to allocate control data, error = %d\n",
407 if ((error
= bus_dmamem_map(sc
->sc_dmat
, &sc
->sc_cdseg
, sc
->sc_cdnseg
,
408 sizeof(struct tulip_control_data
), (void **)&sc
->sc_control_data
,
409 BUS_DMA_COHERENT
)) != 0) {
410 aprint_error_dev(self
, "unable to map control data, error = %d\n",
415 if ((error
= bus_dmamap_create(sc
->sc_dmat
,
416 sizeof(struct tulip_control_data
), 1,
417 sizeof(struct tulip_control_data
), 0, 0, &sc
->sc_cddmamap
)) != 0) {
418 sc
->sc_cddmamap
= NULL
;
419 aprint_error_dev(self
, "unable to create control data DMA map, "
420 "error = %d\n", error
);
424 if ((error
= bus_dmamap_load(sc
->sc_dmat
, sc
->sc_cddmamap
,
425 sc
->sc_control_data
, sizeof(struct tulip_control_data
), NULL
,
427 aprint_error_dev(self
, "unable to load control data DMA map, error = %d\n",
433 * Create the transmit buffer DMA maps.
435 * Note that on the Xircom clone, transmit buffers must be
436 * 4-byte aligned. We're almost guaranteed to have to copy
437 * the packet in that case, so we just limit ourselves to
440 * On the DM9102, the transmit logic can only handle one
443 switch (sc
->sc_chip
) {
444 case TULIP_CHIP_X3201_3
:
445 case TULIP_CHIP_DM9102
:
446 case TULIP_CHIP_DM9102A
:
447 case TULIP_CHIP_AX88140
:
448 case TULIP_CHIP_AX88141
:
453 sc
->sc_ntxsegs
= TULIP_NTXSEGS
;
455 for (i
= 0; i
< TULIP_TXQUEUELEN
; i
++) {
456 if ((error
= bus_dmamap_create(sc
->sc_dmat
, MCLBYTES
,
457 sc
->sc_ntxsegs
, MCLBYTES
, 0, 0,
458 &sc
->sc_txsoft
[i
].txs_dmamap
)) != 0) {
459 sc
->sc_txsoft
[i
].txs_dmamap
= NULL
;
460 aprint_error_dev(self
, "unable to create tx DMA map %d, "
461 "error = %d\n", i
, error
);
467 * Create the receive buffer DMA maps.
469 for (i
= 0; i
< TULIP_NRXDESC
; i
++) {
470 if ((error
= bus_dmamap_create(sc
->sc_dmat
, MCLBYTES
, 1,
471 MCLBYTES
, 0, 0, &sc
->sc_rxsoft
[i
].rxs_dmamap
)) != 0) {
472 sc
->sc_rxsoft
[i
].rxs_dmamap
= NULL
;
473 aprint_error_dev(self
, "unable to create rx DMA map %d, "
474 "error = %d\n", i
, error
);
477 sc
->sc_rxsoft
[i
].rxs_mbuf
= NULL
;
481 * From this point forward, the attachment cannot fail. A failure
482 * before this point releases all resources that may have been
485 sc
->sc_flags
|= TULIPF_ATTACHED
;
488 * Reset the chip to a known state.
492 /* Announce ourselves. */
493 aprint_normal_dev(self
, "%s%sEthernet address %s\n",
494 sc
->sc_name
[0] != '\0' ? sc
->sc_name
: "",
495 sc
->sc_name
[0] != '\0' ? ", " : "",
496 ether_sprintf(enaddr
));
499 * Check to see if we're the simulated Ethernet on Connectix
502 if (enaddr
[0] == 0x00 && enaddr
[1] == 0x03 && enaddr
[2] == 0xff)
503 sc
->sc_flags
|= TULIPF_VPC
;
506 * Initialize our media structures. This may probe the MII, if
509 (*sc
->sc_mediasw
->tmsw_init
)(sc
);
511 strlcpy(ifp
->if_xname
, device_xname(self
), IFNAMSIZ
);
513 ifp
->if_flags
= IFF_BROADCAST
| IFF_SIMPLEX
| IFF_MULTICAST
;
514 sc
->sc_if_flags
= ifp
->if_flags
;
515 ifp
->if_ioctl
= tlp_ioctl
;
516 ifp
->if_start
= tlp_start
;
517 ifp
->if_watchdog
= tlp_watchdog
;
518 ifp
->if_init
= tlp_init
;
519 ifp
->if_stop
= tlp_stop
;
520 IFQ_SET_READY(&ifp
->if_snd
);
523 * We can support 802.1Q VLAN-sized frames.
525 sc
->sc_ethercom
.ec_capabilities
|= ETHERCAP_VLAN_MTU
;
528 * Attach the interface.
531 ether_ifattach(ifp
, enaddr
);
532 ether_set_ifflags_cb(&sc
->sc_ethercom
, tlp_ifflags_cb
);
534 rnd_attach_source(&sc
->sc_rnd_source
, device_xname(self
),
538 if (pmf_device_register(self
, NULL
, NULL
))
539 pmf_class_network_register(self
, ifp
);
541 aprint_error_dev(self
, "couldn't establish power handler\n");
546 * Free any resources we've allocated during the failed attach
547 * attempt. Do this in reverse order and fall through.
550 for (i
= 0; i
< TULIP_NRXDESC
; i
++) {
551 if (sc
->sc_rxsoft
[i
].rxs_dmamap
!= NULL
)
552 bus_dmamap_destroy(sc
->sc_dmat
,
553 sc
->sc_rxsoft
[i
].rxs_dmamap
);
556 for (i
= 0; i
< TULIP_TXQUEUELEN
; i
++) {
557 if (sc
->sc_txsoft
[i
].txs_dmamap
!= NULL
)
558 bus_dmamap_destroy(sc
->sc_dmat
,
559 sc
->sc_txsoft
[i
].txs_dmamap
);
561 bus_dmamap_unload(sc
->sc_dmat
, sc
->sc_cddmamap
);
563 bus_dmamap_destroy(sc
->sc_dmat
, sc
->sc_cddmamap
);
565 bus_dmamem_unmap(sc
->sc_dmat
, (void *)sc
->sc_control_data
,
566 sizeof(struct tulip_control_data
));
568 bus_dmamem_free(sc
->sc_dmat
, &sc
->sc_cdseg
, sc
->sc_cdnseg
);
576 * Handle device activation/deactivation requests.
579 tlp_activate(device_t self
, enum devact act
)
581 struct tulip_softc
*sc
= device_private(self
);
584 case DVACT_DEACTIVATE
:
585 if_deactivate(&sc
->sc_ethercom
.ec_if
);
595 * Detach a Tulip interface.
598 tlp_detach(struct tulip_softc
*sc
)
600 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
601 struct tulip_rxsoft
*rxs
;
602 struct tulip_txsoft
*txs
;
603 device_t self
= sc
->sc_dev
;
607 * Succeed now if there isn't any work to do.
609 if ((sc
->sc_flags
& TULIPF_ATTACHED
) == 0)
612 /* Unhook our tick handler. */
614 callout_stop(&sc
->sc_tick_callout
);
616 if (sc
->sc_flags
& TULIPF_HAS_MII
) {
617 /* Detach all PHYs */
618 mii_detach(&sc
->sc_mii
, MII_PHY_ANY
, MII_OFFSET_ANY
);
621 /* Delete all remaining media. */
622 ifmedia_delete_instance(&sc
->sc_mii
.mii_media
, IFM_INST_ANY
);
625 rnd_detach_source(&sc
->sc_rnd_source
);
630 for (i
= 0; i
< TULIP_NRXDESC
; i
++) {
631 rxs
= &sc
->sc_rxsoft
[i
];
632 if (rxs
->rxs_mbuf
!= NULL
) {
633 bus_dmamap_unload(sc
->sc_dmat
, rxs
->rxs_dmamap
);
634 m_freem(rxs
->rxs_mbuf
);
635 rxs
->rxs_mbuf
= NULL
;
637 bus_dmamap_destroy(sc
->sc_dmat
, rxs
->rxs_dmamap
);
639 for (i
= 0; i
< TULIP_TXQUEUELEN
; i
++) {
640 txs
= &sc
->sc_txsoft
[i
];
641 if (txs
->txs_mbuf
!= NULL
) {
642 bus_dmamap_unload(sc
->sc_dmat
, txs
->txs_dmamap
);
643 m_freem(txs
->txs_mbuf
);
644 txs
->txs_mbuf
= NULL
;
646 bus_dmamap_destroy(sc
->sc_dmat
, txs
->txs_dmamap
);
648 bus_dmamap_unload(sc
->sc_dmat
, sc
->sc_cddmamap
);
649 bus_dmamap_destroy(sc
->sc_dmat
, sc
->sc_cddmamap
);
650 bus_dmamem_unmap(sc
->sc_dmat
, (void *)sc
->sc_control_data
,
651 sizeof(struct tulip_control_data
));
652 bus_dmamem_free(sc
->sc_dmat
, &sc
->sc_cdseg
, sc
->sc_cdnseg
);
654 pmf_device_deregister(self
);
657 free(sc
->sc_srom
, M_DEVBUF
);
663 * tlp_start: [ifnet interface function]
665 * Start packet transmission on the interface.
668 tlp_start(struct ifnet
*ifp
)
670 struct tulip_softc
*sc
= ifp
->if_softc
;
672 struct tulip_txsoft
*txs
, *last_txs
= NULL
;
674 int error
, firsttx
, nexttx
, lasttx
= 1, ofree
, seg
;
676 DPRINTF(sc
, ("%s: tlp_start: sc_flags 0x%08x, if_flags 0x%08x\n",
677 device_xname(sc
->sc_dev
), sc
->sc_flags
, ifp
->if_flags
));
680 * If we want a filter setup, it means no more descriptors were
681 * available for the setup routine. Let it get a chance to wedge
682 * itself into the ring.
684 if (sc
->sc_flags
& TULIPF_WANT_SETUP
)
685 ifp
->if_flags
|= IFF_OACTIVE
;
687 if ((ifp
->if_flags
& (IFF_RUNNING
|IFF_OACTIVE
)) != IFF_RUNNING
)
690 if (sc
->sc_tick
== tlp_2114x_nway_tick
&&
691 (sc
->sc_flags
& TULIPF_LINK_UP
) == 0 && ifp
->if_snd
.ifq_len
< 10)
695 * Remember the previous number of free descriptors and
696 * the first descriptor we'll use.
698 ofree
= sc
->sc_txfree
;
699 firsttx
= sc
->sc_txnext
;
701 DPRINTF(sc
, ("%s: tlp_start: txfree %d, txnext %d\n",
702 device_xname(sc
->sc_dev
), ofree
, firsttx
));
705 * Loop through the send queue, setting up transmit descriptors
706 * until we drain the queue, or use up all available transmit
709 while ((txs
= SIMPLEQ_FIRST(&sc
->sc_txfreeq
)) != NULL
&&
710 sc
->sc_txfree
!= 0) {
712 * Grab a packet off the queue.
714 IFQ_POLL(&ifp
->if_snd
, m0
);
719 dmamap
= txs
->txs_dmamap
;
722 * Load the DMA map. If this fails, the packet either
723 * didn't fit in the alloted number of segments, or we were
724 * short on resources. In this case, we'll copy and try
727 * Note that if we're only allowed 1 Tx segment, we
728 * have an alignment restriction. Do this test before
729 * attempting to load the DMA map, because it's more
730 * likely we'll trip the alignment test than the
731 * more-than-one-segment test.
733 if ((sc
->sc_ntxsegs
== 1 && (mtod(m0
, uintptr_t) & 3) != 0) ||
734 bus_dmamap_load_mbuf(sc
->sc_dmat
, dmamap
, m0
,
735 BUS_DMA_WRITE
|BUS_DMA_NOWAIT
) != 0) {
736 MGETHDR(m
, M_DONTWAIT
, MT_DATA
);
738 aprint_error_dev(sc
->sc_dev
, "unable to allocate Tx mbuf\n");
741 MCLAIM(m
, &sc
->sc_ethercom
.ec_tx_mowner
);
742 if (m0
->m_pkthdr
.len
> MHLEN
) {
743 MCLGET(m
, M_DONTWAIT
);
744 if ((m
->m_flags
& M_EXT
) == 0) {
745 aprint_error_dev(sc
->sc_dev
,
746 "unable to allocate Tx cluster\n");
751 m_copydata(m0
, 0, m0
->m_pkthdr
.len
, mtod(m
, void *));
752 m
->m_pkthdr
.len
= m
->m_len
= m0
->m_pkthdr
.len
;
753 error
= bus_dmamap_load_mbuf(sc
->sc_dmat
, dmamap
,
754 m
, BUS_DMA_WRITE
|BUS_DMA_NOWAIT
);
756 aprint_error_dev(sc
->sc_dev
,
757 "unable to load Tx buffer, error = %d",
764 * Ensure we have enough descriptors free to describe
767 if (dmamap
->dm_nsegs
> sc
->sc_txfree
) {
769 * Not enough free descriptors to transmit this
770 * packet. We haven't committed to anything yet,
771 * so just unload the DMA map, put the packet
772 * back on the queue, and punt. Notify the upper
773 * layer that there are no more slots left.
775 * XXX We could allocate an mbuf and copy, but
776 * XXX it is worth it?
778 ifp
->if_flags
|= IFF_OACTIVE
;
779 bus_dmamap_unload(sc
->sc_dmat
, dmamap
);
785 IFQ_DEQUEUE(&ifp
->if_snd
, m0
);
792 * WE ARE NOW COMMITTED TO TRANSMITTING THE PACKET.
795 /* Sync the DMA map. */
796 bus_dmamap_sync(sc
->sc_dmat
, dmamap
, 0, dmamap
->dm_mapsize
,
797 BUS_DMASYNC_PREWRITE
);
800 * Initialize the transmit descriptors.
802 for (nexttx
= sc
->sc_txnext
, seg
= 0;
803 seg
< dmamap
->dm_nsegs
;
804 seg
++, nexttx
= TULIP_NEXTTX(nexttx
)) {
806 * If this is the first descriptor we're
807 * enqueueing, don't set the OWN bit just
808 * yet. That could cause a race condition.
811 sc
->sc_txdescs
[nexttx
].td_status
=
812 (nexttx
== firsttx
) ? 0 : htole32(TDSTAT_OWN
);
813 sc
->sc_txdescs
[nexttx
].td_bufaddr1
=
814 htole32(dmamap
->dm_segs
[seg
].ds_addr
);
815 sc
->sc_txdescs
[nexttx
].td_ctl
=
816 htole32((dmamap
->dm_segs
[seg
].ds_len
<<
817 TDCTL_SIZE1_SHIFT
) | sc
->sc_tdctl_ch
|
818 (nexttx
== (TULIP_NTXDESC
- 1) ?
819 sc
->sc_tdctl_er
: 0));
823 KASSERT(lasttx
!= -1);
825 /* Set `first segment' and `last segment' appropriately. */
826 sc
->sc_txdescs
[sc
->sc_txnext
].td_ctl
|= htole32(TDCTL_Tx_FS
);
827 sc
->sc_txdescs
[lasttx
].td_ctl
|= htole32(TDCTL_Tx_LS
);
830 if (ifp
->if_flags
& IFF_DEBUG
) {
831 printf(" txsoft %p transmit chain:\n", txs
);
832 for (seg
= sc
->sc_txnext
;; seg
= TULIP_NEXTTX(seg
)) {
833 printf(" descriptor %d:\n", seg
);
834 printf(" td_status: 0x%08x\n",
835 le32toh(sc
->sc_txdescs
[seg
].td_status
));
836 printf(" td_ctl: 0x%08x\n",
837 le32toh(sc
->sc_txdescs
[seg
].td_ctl
));
838 printf(" td_bufaddr1: 0x%08x\n",
839 le32toh(sc
->sc_txdescs
[seg
].td_bufaddr1
));
840 printf(" td_bufaddr2: 0x%08x\n",
841 le32toh(sc
->sc_txdescs
[seg
].td_bufaddr2
));
848 /* Sync the descriptors we're using. */
849 TULIP_CDTXSYNC(sc
, sc
->sc_txnext
, dmamap
->dm_nsegs
,
850 BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
853 * Store a pointer to the packet so we can free it later,
854 * and remember what txdirty will be once the packet is
858 txs
->txs_firstdesc
= sc
->sc_txnext
;
859 txs
->txs_lastdesc
= lasttx
;
860 txs
->txs_ndescs
= dmamap
->dm_nsegs
;
862 /* Advance the tx pointer. */
863 sc
->sc_txfree
-= dmamap
->dm_nsegs
;
864 sc
->sc_txnext
= nexttx
;
866 SIMPLEQ_REMOVE_HEAD(&sc
->sc_txfreeq
, txs_q
);
867 SIMPLEQ_INSERT_TAIL(&sc
->sc_txdirtyq
, txs
, txs_q
);
873 * Pass the packet to any BPF listeners.
876 bpf_mtap(ifp
->if_bpf
, m0
);
877 #endif /* NBPFILTER > 0 */
880 if (txs
== NULL
|| sc
->sc_txfree
== 0) {
881 /* No more slots left; notify upper layer. */
882 ifp
->if_flags
|= IFF_OACTIVE
;
885 if (sc
->sc_txfree
!= ofree
) {
886 DPRINTF(sc
, ("%s: packets enqueued, IC on %d, OWN on %d\n",
887 device_xname(sc
->sc_dev
), lasttx
, firsttx
));
889 * Cause a transmit interrupt to happen on the
890 * last packet we enqueued.
892 sc
->sc_txdescs
[lasttx
].td_ctl
|= htole32(TDCTL_Tx_IC
);
893 TULIP_CDTXSYNC(sc
, lasttx
, 1,
894 BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
897 * Some clone chips want IC on the *first* segment in
898 * the packet. Appease them.
900 KASSERT(last_txs
!= NULL
);
901 if ((sc
->sc_flags
& TULIPF_IC_FS
) != 0 &&
902 last_txs
->txs_firstdesc
!= lasttx
) {
903 sc
->sc_txdescs
[last_txs
->txs_firstdesc
].td_ctl
|=
904 htole32(TDCTL_Tx_IC
);
905 TULIP_CDTXSYNC(sc
, last_txs
->txs_firstdesc
, 1,
906 BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
910 * The entire packet chain is set up. Give the
911 * first descriptor to the chip now.
913 sc
->sc_txdescs
[firsttx
].td_status
|= htole32(TDSTAT_OWN
);
914 TULIP_CDTXSYNC(sc
, firsttx
, 1,
915 BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
917 /* Wake up the transmitter. */
918 /* XXX USE AUTOPOLLING? */
919 TULIP_WRITE(sc
, CSR_TXPOLL
, TXPOLL_TPD
);
921 /* Set a watchdog timer in case the chip flakes out. */
927 * tlp_watchdog: [ifnet interface function]
929 * Watchdog timer handler.
932 tlp_watchdog(struct ifnet
*ifp
)
934 struct tulip_softc
*sc
= ifp
->if_softc
;
935 int doing_setup
, doing_transmit
;
937 doing_setup
= (sc
->sc_flags
& TULIPF_DOING_SETUP
);
938 doing_transmit
= (! SIMPLEQ_EMPTY(&sc
->sc_txdirtyq
));
940 if (doing_setup
&& doing_transmit
) {
941 printf("%s: filter setup and transmit timeout\n", device_xname(sc
->sc_dev
));
943 } else if (doing_transmit
) {
944 printf("%s: transmit timeout\n", device_xname(sc
->sc_dev
));
946 } else if (doing_setup
)
947 printf("%s: filter setup timeout\n", device_xname(sc
->sc_dev
));
949 printf("%s: spurious watchdog timeout\n", device_xname(sc
->sc_dev
));
951 (void) tlp_init(ifp
);
953 /* Try to get more packets going. */
957 /* If the interface is up and running, only modify the receive
958 * filter when setting promiscuous or debug mode. Otherwise fall
959 * through to ether_ioctl, which will reset the chip.
962 tlp_ifflags_cb(struct ethercom
*ec
)
964 struct ifnet
*ifp
= &ec
->ec_if
;
965 struct tulip_softc
*sc
= ifp
->if_softc
;
966 int change
= ifp
->if_flags
^ sc
->sc_if_flags
;
968 if ((change
& ~(IFF_CANTCHANGE
|IFF_DEBUG
)) != 0)
970 if ((change
& IFF_PROMISC
) != 0)
971 (*sc
->sc_filter_setup
)(sc
);
976 * tlp_ioctl: [ifnet interface function]
978 * Handle control requests from the operator.
981 tlp_ioctl(struct ifnet
*ifp
, u_long cmd
, void *data
)
983 struct tulip_softc
*sc
= ifp
->if_softc
;
984 struct ifreq
*ifr
= (struct ifreq
*)data
;
992 error
= ifmedia_ioctl(ifp
, ifr
, &sc
->sc_mii
.mii_media
, cmd
);
995 error
= ether_ioctl(ifp
, cmd
, data
);
996 if (error
== ENETRESET
) {
997 if (ifp
->if_flags
& IFF_RUNNING
) {
999 * Multicast list has changed. Set the
1000 * hardware filter accordingly.
1002 (*sc
->sc_filter_setup
)(sc
);
1009 /* Try to get more packets going. */
1010 if (TULIP_IS_ENABLED(sc
))
1013 sc
->sc_if_flags
= ifp
->if_flags
;
1021 * Interrupt service routine.
1026 struct tulip_softc
*sc
= arg
;
1027 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
1028 uint32_t status
, rxstatus
, txstatus
;
1029 int handled
= 0, txthresh
;
1031 DPRINTF(sc
, ("%s: tlp_intr\n", device_xname(sc
->sc_dev
)));
1034 if (TULIP_IS_ENABLED(sc
) == 0)
1035 panic("%s: tlp_intr: not enabled", device_xname(sc
->sc_dev
));
1039 * If the interface isn't running, the interrupt couldn't
1040 * possibly have come from us.
1042 if ((ifp
->if_flags
& IFF_RUNNING
) == 0 ||
1043 !device_is_active(sc
->sc_dev
))
1046 /* Disable interrupts on the DM9102 (interrupt edge bug). */
1047 switch (sc
->sc_chip
) {
1048 case TULIP_CHIP_DM9102
:
1049 case TULIP_CHIP_DM9102A
:
1050 TULIP_WRITE(sc
, CSR_INTEN
, 0);
1059 status
= TULIP_READ(sc
, CSR_STATUS
);
1061 TULIP_WRITE(sc
, CSR_STATUS
, status
);
1063 if ((status
& sc
->sc_inten
) == 0)
1068 rxstatus
= status
& sc
->sc_rxint_mask
;
1069 txstatus
= status
& sc
->sc_txint_mask
;
1072 /* Grab new any new packets. */
1075 if (rxstatus
& STATUS_RWT
)
1076 printf("%s: receive watchdog timeout\n",
1077 device_xname(sc
->sc_dev
));
1079 if (rxstatus
& STATUS_RU
) {
1080 printf("%s: receive ring overrun\n",
1081 device_xname(sc
->sc_dev
));
1082 /* Get the receive process going again. */
1083 if (sc
->sc_tdctl_er
!= TDCTL_ER
) {
1084 tlp_idle(sc
, OPMODE_SR
);
1085 TULIP_WRITE(sc
, CSR_RXLIST
,
1086 TULIP_CDRXADDR(sc
, sc
->sc_rxptr
));
1087 TULIP_WRITE(sc
, CSR_OPMODE
,
1090 TULIP_WRITE(sc
, CSR_RXPOLL
, RXPOLL_RPD
);
1096 /* Sweep up transmit descriptors. */
1099 if (txstatus
& STATUS_TJT
)
1100 printf("%s: transmit jabber timeout\n",
1101 device_xname(sc
->sc_dev
));
1103 if (txstatus
& STATUS_UNF
) {
1105 * Increase our transmit threshold if
1106 * another is available.
1108 txthresh
= sc
->sc_txthresh
+ 1;
1109 if (sc
->sc_txth
[txthresh
].txth_name
!= NULL
) {
1110 /* Idle the transmit process. */
1111 tlp_idle(sc
, OPMODE_ST
);
1113 sc
->sc_txthresh
= txthresh
;
1114 sc
->sc_opmode
&= ~(OPMODE_TR
|OPMODE_SF
);
1116 sc
->sc_txth
[txthresh
].txth_opmode
;
1117 printf("%s: transmit underrun; new "
1119 device_xname(sc
->sc_dev
),
1120 sc
->sc_txth
[txthresh
].txth_name
);
1123 * Set the new threshold and restart
1124 * the transmit process.
1126 TULIP_WRITE(sc
, CSR_OPMODE
,
1130 * XXX Log every Nth underrun from
1136 if (status
& (STATUS_TPS
|STATUS_RPS
)) {
1137 if (status
& STATUS_TPS
)
1138 printf("%s: transmit process stopped\n",
1139 device_xname(sc
->sc_dev
));
1140 if (status
& STATUS_RPS
)
1141 printf("%s: receive process stopped\n",
1142 device_xname(sc
->sc_dev
));
1143 (void) tlp_init(ifp
);
1147 if (status
& STATUS_SE
) {
1149 switch (status
& STATUS_EB
) {
1150 case STATUS_EB_PARITY
:
1151 str
= "parity error";
1154 case STATUS_EB_MABT
:
1155 str
= "master abort";
1158 case STATUS_EB_TABT
:
1159 str
= "target abort";
1163 str
= "unknown error";
1166 aprint_error_dev(sc
->sc_dev
, "fatal system error: %s\n",
1168 (void) tlp_init(ifp
);
1175 * Transmit buffer unavailable -- normal
1176 * condition, nothing to do, really.
1178 * General purpose timer experied -- we don't
1179 * use the general purpose timer.
1181 * Early receive interrupt -- not available on
1182 * all chips, we just use RI. We also only
1183 * use single-segment receive DMA, so this
1184 * is mostly useless.
1188 /* Bring interrupts back up on the DM9102. */
1189 switch (sc
->sc_chip
) {
1190 case TULIP_CHIP_DM9102
:
1191 case TULIP_CHIP_DM9102A
:
1192 TULIP_WRITE(sc
, CSR_INTEN
, sc
->sc_inten
);
1200 /* Try to get more packets going. */
1205 rnd_add_uint32(&sc
->sc_rnd_source
, status
);
1213 * Helper; handle receive interrupts.
1216 tlp_rxintr(struct tulip_softc
*sc
)
1218 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
1219 struct ether_header
*eh
;
1220 struct tulip_rxsoft
*rxs
;
1222 uint32_t rxstat
, errors
;
1225 for (i
= sc
->sc_rxptr
;; i
= TULIP_NEXTRX(i
)) {
1226 rxs
= &sc
->sc_rxsoft
[i
];
1228 TULIP_CDRXSYNC(sc
, i
,
1229 BUS_DMASYNC_POSTREAD
|BUS_DMASYNC_POSTWRITE
);
1231 rxstat
= le32toh(sc
->sc_rxdescs
[i
].td_status
);
1233 if (rxstat
& TDSTAT_OWN
) {
1235 * We have processed all of the receive buffers.
1241 * Make sure the packet fit in one buffer. This should
1242 * always be the case. But the Lite-On PNIC, rev 33
1243 * has an awful receive engine bug, which may require
1244 * a very icky work-around.
1246 if ((rxstat
& (TDSTAT_Rx_FS
|TDSTAT_Rx_LS
)) !=
1247 (TDSTAT_Rx_FS
|TDSTAT_Rx_LS
)) {
1248 printf("%s: incoming packet spilled, resetting\n",
1249 device_xname(sc
->sc_dev
));
1250 (void) tlp_init(ifp
);
1255 * If any collisions were seen on the wire, count one.
1257 if (rxstat
& TDSTAT_Rx_CS
)
1258 ifp
->if_collisions
++;
1261 * If an error occurred, update stats, clear the status
1262 * word, and leave the packet buffer in place. It will
1263 * simply be reused the next time the ring comes around.
1265 errors
= TDSTAT_Rx_DE
| TDSTAT_Rx_RF
| TDSTAT_Rx_TL
|
1266 TDSTAT_Rx_CS
| TDSTAT_Rx_RE
| TDSTAT_Rx_DB
| TDSTAT_Rx_CE
;
1268 * If 802.1Q VLAN MTU is enabled, ignore the Frame Too Long
1271 if ((sc
->sc_ethercom
.ec_capenable
& ETHERCAP_VLAN_MTU
) != 0)
1272 errors
&= ~TDSTAT_Rx_TL
;
1274 * If chip doesn't have MII, ignore the MII error bit.
1276 if ((sc
->sc_flags
& TULIPF_HAS_MII
) == 0)
1277 errors
&= ~TDSTAT_Rx_RE
;
1279 if ((rxstat
& TDSTAT_ES
) != 0 &&
1280 (rxstat
& errors
) != 0) {
1282 #define PRINTERR(bit, str) \
1283 if (rxstat & (bit)) \
1284 aprint_error_dev(sc->sc_dev, "receive error: %s\n", \
1287 PRINTERR(TDSTAT_Rx_DE
, "descriptor error");
1288 PRINTERR(TDSTAT_Rx_RF
, "runt frame");
1289 PRINTERR(TDSTAT_Rx_TL
, "frame too long");
1290 PRINTERR(TDSTAT_Rx_RE
, "MII error");
1291 PRINTERR(TDSTAT_Rx_DB
, "dribbling bit");
1292 PRINTERR(TDSTAT_Rx_CE
, "CRC error");
1294 TULIP_INIT_RXDESC(sc
, i
);
1298 bus_dmamap_sync(sc
->sc_dmat
, rxs
->rxs_dmamap
, 0,
1299 rxs
->rxs_dmamap
->dm_mapsize
, BUS_DMASYNC_POSTREAD
);
1302 * No errors; receive the packet. Note the Tulip
1303 * includes the CRC with every packet.
1305 len
= TDSTAT_Rx_LENGTH(rxstat
) - ETHER_CRC_LEN
;
1307 #ifdef __NO_STRICT_ALIGNMENT
1309 * Allocate a new mbuf cluster. If that fails, we are
1310 * out of memory, and must drop the packet and recycle
1311 * the buffer that's already attached to this descriptor.
1314 if (tlp_add_rxbuf(sc
, i
) != 0) {
1316 TULIP_INIT_RXDESC(sc
, i
);
1317 bus_dmamap_sync(sc
->sc_dmat
, rxs
->rxs_dmamap
, 0,
1318 rxs
->rxs_dmamap
->dm_mapsize
, BUS_DMASYNC_PREREAD
);
1323 * The Tulip's receive buffers must be 4-byte aligned.
1324 * But this means that the data after the Ethernet header
1325 * is misaligned. We must allocate a new buffer and
1326 * copy the data, shifted forward 2 bytes.
1328 MGETHDR(m
, M_DONTWAIT
, MT_DATA
);
1332 TULIP_INIT_RXDESC(sc
, i
);
1333 bus_dmamap_sync(sc
->sc_dmat
, rxs
->rxs_dmamap
, 0,
1334 rxs
->rxs_dmamap
->dm_mapsize
, BUS_DMASYNC_PREREAD
);
1337 MCLAIM(m
, &sc
->sc_ethercom
.ec_rx_mowner
);
1338 if (len
> (MHLEN
- 2)) {
1339 MCLGET(m
, M_DONTWAIT
);
1340 if ((m
->m_flags
& M_EXT
) == 0) {
1348 * Note that we use clusters for incoming frames, so the
1349 * buffer is virtually contiguous.
1351 memcpy(mtod(m
, void *), mtod(rxs
->rxs_mbuf
, void *), len
);
1353 /* Allow the receive descriptor to continue using its mbuf. */
1354 TULIP_INIT_RXDESC(sc
, i
);
1355 bus_dmamap_sync(sc
->sc_dmat
, rxs
->rxs_dmamap
, 0,
1356 rxs
->rxs_dmamap
->dm_mapsize
, BUS_DMASYNC_PREREAD
);
1357 #endif /* __NO_STRICT_ALIGNMENT */
1360 eh
= mtod(m
, struct ether_header
*);
1361 m
->m_pkthdr
.rcvif
= ifp
;
1362 m
->m_pkthdr
.len
= m
->m_len
= len
;
1365 * XXX Work-around for a weird problem with the emulated
1366 * 21041 on Connectix Virtual PC:
1368 * When we receive a full-size TCP segment, we seem to get
1369 * a packet there the Rx status says 1522 bytes, yet we do
1370 * not get a frame-too-long error from the chip. The extra
1371 * bytes seem to always be zeros. Perhaps Virtual PC is
1372 * inserting 4 bytes of zeros after every packet. In any
1373 * case, let's try and detect this condition and truncate
1374 * the length so that it will pass up the stack.
1376 if (__predict_false((sc
->sc_flags
& TULIPF_VPC
) != 0)) {
1377 uint16_t etype
= ntohs(eh
->ether_type
);
1379 if (len
> ETHER_MAX_FRAME(ifp
, etype
, 0))
1380 m
->m_pkthdr
.len
= m
->m_len
= len
=
1381 ETHER_MAX_FRAME(ifp
, etype
, 0);
1386 * Pass this up to any BPF listeners, but only
1387 * pass it up the stack if it's for us.
1390 bpf_mtap(ifp
->if_bpf
, m
);
1391 #endif /* NBPFILTER > 0 */
1394 * We sometimes have to run the 21140 in Hash-Only
1395 * mode. If we're in that mode, and not in promiscuous
1396 * mode, and we have a unicast packet that isn't for
1399 if (sc
->sc_filtmode
== TDCTL_Tx_FT_HASHONLY
&&
1400 (ifp
->if_flags
& IFF_PROMISC
) == 0 &&
1401 ETHER_IS_MULTICAST(eh
->ether_dhost
) == 0 &&
1402 memcmp(CLLADDR(ifp
->if_sadl
), eh
->ether_dhost
,
1403 ETHER_ADDR_LEN
) != 0) {
1409 (*ifp
->if_input
)(ifp
, m
);
1412 /* Update the receive pointer. */
1419 * Helper; handle transmit interrupts.
1422 tlp_txintr(struct tulip_softc
*sc
)
1424 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
1425 struct tulip_txsoft
*txs
;
1428 DPRINTF(sc
, ("%s: tlp_txintr: sc_flags 0x%08x\n",
1429 device_xname(sc
->sc_dev
), sc
->sc_flags
));
1431 ifp
->if_flags
&= ~IFF_OACTIVE
;
1434 * Go through our Tx list and free mbufs for those
1435 * frames that have been transmitted.
1437 while ((txs
= SIMPLEQ_FIRST(&sc
->sc_txdirtyq
)) != NULL
) {
1438 TULIP_CDTXSYNC(sc
, txs
->txs_lastdesc
,
1440 BUS_DMASYNC_POSTREAD
|BUS_DMASYNC_POSTWRITE
);
1443 if (ifp
->if_flags
& IFF_DEBUG
) {
1445 printf(" txsoft %p transmit chain:\n", txs
);
1446 for (i
= txs
->txs_firstdesc
;; i
= TULIP_NEXTTX(i
)) {
1447 printf(" descriptor %d:\n", i
);
1448 printf(" td_status: 0x%08x\n",
1449 le32toh(sc
->sc_txdescs
[i
].td_status
));
1450 printf(" td_ctl: 0x%08x\n",
1451 le32toh(sc
->sc_txdescs
[i
].td_ctl
));
1452 printf(" td_bufaddr1: 0x%08x\n",
1453 le32toh(sc
->sc_txdescs
[i
].td_bufaddr1
));
1454 printf(" td_bufaddr2: 0x%08x\n",
1455 le32toh(sc
->sc_txdescs
[i
].td_bufaddr2
));
1456 if (i
== txs
->txs_lastdesc
)
1462 txstat
= le32toh(sc
->sc_txdescs
[txs
->txs_lastdesc
].td_status
);
1463 if (txstat
& TDSTAT_OWN
)
1466 SIMPLEQ_REMOVE_HEAD(&sc
->sc_txdirtyq
, txs_q
);
1468 sc
->sc_txfree
+= txs
->txs_ndescs
;
1470 if (txs
->txs_mbuf
== NULL
) {
1472 * If we didn't have an mbuf, it was the setup
1476 if ((sc
->sc_flags
& TULIPF_DOING_SETUP
) == 0)
1477 panic("tlp_txintr: null mbuf, not doing setup");
1479 TULIP_CDSPSYNC(sc
, BUS_DMASYNC_POSTWRITE
);
1480 sc
->sc_flags
&= ~TULIPF_DOING_SETUP
;
1481 SIMPLEQ_INSERT_TAIL(&sc
->sc_txfreeq
, txs
, txs_q
);
1485 bus_dmamap_sync(sc
->sc_dmat
, txs
->txs_dmamap
,
1486 0, txs
->txs_dmamap
->dm_mapsize
,
1487 BUS_DMASYNC_POSTWRITE
);
1488 bus_dmamap_unload(sc
->sc_dmat
, txs
->txs_dmamap
);
1489 m_freem(txs
->txs_mbuf
);
1490 txs
->txs_mbuf
= NULL
;
1492 SIMPLEQ_INSERT_TAIL(&sc
->sc_txfreeq
, txs
, txs_q
);
1495 * Check for errors and collisions.
1498 if (txstat
& TDSTAT_Tx_UF
)
1499 sc
->sc_stats
.ts_tx_uf
++;
1500 if (txstat
& TDSTAT_Tx_TO
)
1501 sc
->sc_stats
.ts_tx_to
++;
1502 if (txstat
& TDSTAT_Tx_EC
)
1503 sc
->sc_stats
.ts_tx_ec
++;
1504 if (txstat
& TDSTAT_Tx_LC
)
1505 sc
->sc_stats
.ts_tx_lc
++;
1508 if (txstat
& (TDSTAT_Tx_UF
|TDSTAT_Tx_TO
))
1511 if (txstat
& TDSTAT_Tx_EC
)
1512 ifp
->if_collisions
+= 16;
1514 ifp
->if_collisions
+= TDSTAT_Tx_COLLISIONS(txstat
);
1515 if (txstat
& TDSTAT_Tx_LC
)
1516 ifp
->if_collisions
++;
1522 * If there are no more pending transmissions, cancel the watchdog
1525 if (txs
== NULL
&& (sc
->sc_flags
& TULIPF_DOING_SETUP
) == 0)
1529 * If we have a receive filter setup pending, do it now.
1531 if (sc
->sc_flags
& TULIPF_WANT_SETUP
)
1532 (*sc
->sc_filter_setup
)(sc
);
1537 tlp_print_stats(struct tulip_softc
*sc
)
1540 printf("%s: tx_uf %lu, tx_to %lu, tx_ec %lu, tx_lc %lu\n",
1541 device_xname(sc
->sc_dev
),
1542 sc
->sc_stats
.ts_tx_uf
, sc
->sc_stats
.ts_tx_to
,
1543 sc
->sc_stats
.ts_tx_ec
, sc
->sc_stats
.ts_tx_lc
);
1550 * Perform a soft reset on the Tulip.
1553 tlp_reset(struct tulip_softc
*sc
)
1557 TULIP_WRITE(sc
, CSR_BUSMODE
, BUSMODE_SWR
);
1560 * Xircom, ASIX and Conexant clones don't bring themselves
1561 * out of reset automatically.
1562 * Instead, we have to wait at least 50 PCI cycles, and then
1565 switch (sc
->sc_chip
) {
1566 case TULIP_CHIP_X3201_3
:
1567 case TULIP_CHIP_AX88140
:
1568 case TULIP_CHIP_AX88141
:
1569 case TULIP_CHIP_RS7112
:
1571 TULIP_WRITE(sc
, CSR_BUSMODE
, 0);
1577 for (i
= 0; i
< 1000; i
++) {
1579 * Wait at least 50 PCI cycles for the reset to
1580 * complete before peeking at the Tulip again.
1581 * 10 uSec is a bit longer than 50 PCI cycles
1582 * (at 33MHz), but it doesn't hurt have the extra
1586 if (TULIP_ISSET(sc
, CSR_BUSMODE
, BUSMODE_SWR
) == 0)
1590 if (TULIP_ISSET(sc
, CSR_BUSMODE
, BUSMODE_SWR
))
1591 aprint_error_dev(sc
->sc_dev
, "reset failed to complete\n");
1596 * If the board has any GPIO reset sequences to issue, do them now.
1598 if (sc
->sc_reset
!= NULL
)
1599 (*sc
->sc_reset
)(sc
);
1603 * tlp_init: [ ifnet interface function ]
1605 * Initialize the interface. Must be called at splnet().
1608 tlp_init(struct ifnet
*ifp
)
1610 struct tulip_softc
*sc
= ifp
->if_softc
;
1611 struct tulip_txsoft
*txs
;
1612 struct tulip_rxsoft
*rxs
;
1615 if ((error
= tlp_enable(sc
)) != 0)
1619 * Cancel any pending I/O.
1624 * Initialize `opmode' to 0, and call the pre-init routine, if
1625 * any. This is required because the 2114x and some of the
1626 * clones require that the media-related bits in `opmode' be
1627 * set before performing a soft-reset in order to get internal
1628 * chip pathways are correct. Yay!
1631 if (sc
->sc_preinit
!= NULL
)
1632 (*sc
->sc_preinit
)(sc
);
1635 * Reset the Tulip to a known state.
1640 * Initialize the BUSMODE register.
1642 sc
->sc_busmode
= BUSMODE_BAR
;
1643 switch (sc
->sc_chip
) {
1644 case TULIP_CHIP_21140
:
1645 case TULIP_CHIP_21140A
:
1646 case TULIP_CHIP_21142
:
1647 case TULIP_CHIP_21143
:
1648 case TULIP_CHIP_82C115
:
1649 case TULIP_CHIP_MX98725
:
1651 * If we're allowed to do so, use Memory Read Line
1652 * and Memory Read Multiple.
1654 * XXX Should we use Memory Write and Invalidate?
1656 if (sc
->sc_flags
& TULIPF_MRL
)
1657 sc
->sc_busmode
|= BUSMODE_RLE
;
1658 if (sc
->sc_flags
& TULIPF_MRM
)
1659 sc
->sc_busmode
|= BUSMODE_RME
;
1661 if (sc
->sc_flags
& TULIPF_MWI
)
1662 sc
->sc_busmode
|= BUSMODE_WLE
;
1666 case TULIP_CHIP_82C168
:
1667 case TULIP_CHIP_82C169
:
1668 sc
->sc_busmode
|= BUSMODE_PNIC_MBO
;
1669 if (sc
->sc_maxburst
== 0)
1670 sc
->sc_maxburst
= 16;
1673 case TULIP_CHIP_AX88140
:
1674 case TULIP_CHIP_AX88141
:
1675 if (sc
->sc_maxburst
== 0)
1676 sc
->sc_maxburst
= 16;
1683 switch (sc
->sc_cacheline
) {
1686 * Note: We must *always* set these bits; a cache
1687 * alignment of 0 is RESERVED.
1690 sc
->sc_busmode
|= BUSMODE_CAL_8LW
;
1693 sc
->sc_busmode
|= BUSMODE_CAL_16LW
;
1696 sc
->sc_busmode
|= BUSMODE_CAL_32LW
;
1699 switch (sc
->sc_maxburst
) {
1701 sc
->sc_busmode
|= BUSMODE_PBL_1LW
;
1704 sc
->sc_busmode
|= BUSMODE_PBL_2LW
;
1707 sc
->sc_busmode
|= BUSMODE_PBL_4LW
;
1710 sc
->sc_busmode
|= BUSMODE_PBL_8LW
;
1713 sc
->sc_busmode
|= BUSMODE_PBL_16LW
;
1716 sc
->sc_busmode
|= BUSMODE_PBL_32LW
;
1719 sc
->sc_busmode
|= BUSMODE_PBL_DEFAULT
;
1722 #if BYTE_ORDER == BIG_ENDIAN
1724 * Can't use BUSMODE_BLE or BUSMODE_DBO; not all chips
1725 * support them, and even on ones that do, it doesn't
1726 * always work. So we always access descriptors with
1727 * little endian via htole32/le32toh.
1731 * Big-endian bus requires BUSMODE_BLE anyway.
1732 * Also, BUSMODE_DBO is needed because we assume
1733 * descriptors are little endian.
1735 if (sc
->sc_flags
& TULIPF_BLE
)
1736 sc
->sc_busmode
|= BUSMODE_BLE
;
1737 if (sc
->sc_flags
& TULIPF_DBO
)
1738 sc
->sc_busmode
|= BUSMODE_DBO
;
1741 * Some chips have a broken bus interface.
1743 switch (sc
->sc_chip
) {
1744 case TULIP_CHIP_DM9102
:
1745 case TULIP_CHIP_DM9102A
:
1754 TULIP_WRITE(sc
, CSR_BUSMODE
, sc
->sc_busmode
);
1757 * Initialize the OPMODE register. We don't write it until
1758 * we're ready to begin the transmit and receive processes.
1760 * Media-related OPMODE bits are set in the media callbacks
1761 * for each specific chip/board.
1763 sc
->sc_opmode
|= OPMODE_SR
| OPMODE_ST
|
1764 sc
->sc_txth
[sc
->sc_txthresh
].txth_opmode
;
1767 * Magical mystery initialization on the Macronix chips.
1768 * The MX98713 uses its own magic value, the rest share
1771 switch (sc
->sc_chip
) {
1772 case TULIP_CHIP_MX98713
:
1773 TULIP_WRITE(sc
, CSR_PMAC_TOR
, PMAC_TOR_98713
);
1776 case TULIP_CHIP_MX98713A
:
1777 case TULIP_CHIP_MX98715
:
1778 case TULIP_CHIP_MX98715A
:
1779 case TULIP_CHIP_MX98715AEC_X
:
1780 case TULIP_CHIP_MX98725
:
1781 TULIP_WRITE(sc
, CSR_PMAC_TOR
, PMAC_TOR_98715
);
1790 * Initialize the transmit descriptor ring.
1792 memset(sc
->sc_txdescs
, 0, sizeof(sc
->sc_txdescs
));
1793 for (i
= 0; i
< TULIP_NTXDESC
; i
++) {
1794 sc
->sc_txdescs
[i
].td_ctl
= htole32(sc
->sc_tdctl_ch
);
1795 sc
->sc_txdescs
[i
].td_bufaddr2
=
1796 htole32(TULIP_CDTXADDR(sc
, TULIP_NEXTTX(i
)));
1798 sc
->sc_txdescs
[TULIP_NTXDESC
- 1].td_ctl
|= htole32(sc
->sc_tdctl_er
);
1799 TULIP_CDTXSYNC(sc
, 0, TULIP_NTXDESC
,
1800 BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
1801 sc
->sc_txfree
= TULIP_NTXDESC
;
1805 * Initialize the transmit job descriptors.
1807 SIMPLEQ_INIT(&sc
->sc_txfreeq
);
1808 SIMPLEQ_INIT(&sc
->sc_txdirtyq
);
1809 for (i
= 0; i
< TULIP_TXQUEUELEN
; i
++) {
1810 txs
= &sc
->sc_txsoft
[i
];
1811 txs
->txs_mbuf
= NULL
;
1812 SIMPLEQ_INSERT_TAIL(&sc
->sc_txfreeq
, txs
, txs_q
);
1816 * Initialize the receive descriptor and receive job
1819 for (i
= 0; i
< TULIP_NRXDESC
; i
++) {
1820 rxs
= &sc
->sc_rxsoft
[i
];
1821 if (rxs
->rxs_mbuf
== NULL
) {
1822 if ((error
= tlp_add_rxbuf(sc
, i
)) != 0) {
1823 aprint_error_dev(sc
->sc_dev
, "unable to allocate or map rx "
1824 "buffer %d, error = %d\n",
1827 * XXX Should attempt to run with fewer receive
1828 * XXX buffers instead of just failing.
1834 TULIP_INIT_RXDESC(sc
, i
);
1839 * Initialize the interrupt mask and enable interrupts.
1841 /* normal interrupts */
1842 sc
->sc_inten
= STATUS_TI
| STATUS_TU
| STATUS_RI
| STATUS_NIS
;
1844 /* abnormal interrupts */
1845 sc
->sc_inten
|= STATUS_TPS
| STATUS_TJT
| STATUS_UNF
|
1846 STATUS_RU
| STATUS_RPS
| STATUS_RWT
| STATUS_SE
| STATUS_AIS
;
1848 sc
->sc_rxint_mask
= STATUS_RI
|STATUS_RU
|STATUS_RWT
;
1849 sc
->sc_txint_mask
= STATUS_TI
|STATUS_UNF
|STATUS_TJT
;
1851 switch (sc
->sc_chip
) {
1852 case TULIP_CHIP_WB89C840F
:
1854 * Clear bits that we don't want that happen to
1855 * overlap or don't exist.
1857 sc
->sc_inten
&= ~(STATUS_WINB_REI
|STATUS_RWT
);
1865 sc
->sc_rxint_mask
&= sc
->sc_inten
;
1866 sc
->sc_txint_mask
&= sc
->sc_inten
;
1868 TULIP_WRITE(sc
, CSR_INTEN
, sc
->sc_inten
);
1869 TULIP_WRITE(sc
, CSR_STATUS
, 0xffffffff);
1872 * Give the transmit and receive rings to the Tulip.
1874 TULIP_WRITE(sc
, CSR_TXLIST
, TULIP_CDTXADDR(sc
, sc
->sc_txnext
));
1875 TULIP_WRITE(sc
, CSR_RXLIST
, TULIP_CDRXADDR(sc
, sc
->sc_rxptr
));
1878 * On chips that do this differently, set the station address.
1880 switch (sc
->sc_chip
) {
1881 case TULIP_CHIP_WB89C840F
:
1883 /* XXX Do this with stream writes? */
1884 bus_addr_t cpa
= TULIP_CSR_OFFSET(sc
, CSR_WINB_CPA0
);
1886 for (i
= 0; i
< ETHER_ADDR_LEN
; i
++) {
1887 bus_space_write_1(sc
->sc_st
, sc
->sc_sh
,
1888 cpa
+ i
, CLLADDR(ifp
->if_sadl
)[i
]);
1893 case TULIP_CHIP_AL981
:
1894 case TULIP_CHIP_AN983
:
1895 case TULIP_CHIP_AN985
:
1898 const uint8_t *enaddr
= CLLADDR(ifp
->if_sadl
);
1904 bus_space_write_4(sc
->sc_st
, sc
->sc_sh
, CSR_ADM_PAR0
, reg
);
1908 bus_space_write_4(sc
->sc_st
, sc
->sc_sh
, CSR_ADM_PAR1
, reg
);
1912 case TULIP_CHIP_AX88140
:
1913 case TULIP_CHIP_AX88141
:
1916 const uint8_t *enaddr
= CLLADDR(ifp
->if_sadl
);
1922 TULIP_WRITE(sc
, CSR_AX_FILTIDX
, AX_FILTIDX_PAR0
);
1923 TULIP_WRITE(sc
, CSR_AX_FILTDATA
, reg
);
1925 reg
= enaddr
[4] | (enaddr
[5] << 8);
1926 TULIP_WRITE(sc
, CSR_AX_FILTIDX
, AX_FILTIDX_PAR1
);
1927 TULIP_WRITE(sc
, CSR_AX_FILTDATA
, reg
);
1937 * Set the receive filter. This will start the transmit and
1938 * receive processes.
1940 (*sc
->sc_filter_setup
)(sc
);
1943 * Set the current media.
1945 (void) (*sc
->sc_mediasw
->tmsw_set
)(sc
);
1948 * Start the receive process.
1950 TULIP_WRITE(sc
, CSR_RXPOLL
, RXPOLL_RPD
);
1952 if (sc
->sc_tick
!= NULL
) {
1953 /* Start the one second clock. */
1954 callout_reset(&sc
->sc_tick_callout
, hz
>> 3, sc
->sc_tick
, sc
);
1958 * Note that the interface is now running.
1960 ifp
->if_flags
|= IFF_RUNNING
;
1961 ifp
->if_flags
&= ~IFF_OACTIVE
;
1962 sc
->sc_if_flags
= ifp
->if_flags
;
1966 ifp
->if_flags
&= ~(IFF_RUNNING
| IFF_OACTIVE
);
1968 printf("%s: interface not running\n", device_xname(sc
->sc_dev
));
1976 * Enable the Tulip chip.
1979 tlp_enable(struct tulip_softc
*sc
)
1982 if (TULIP_IS_ENABLED(sc
) == 0 && sc
->sc_enable
!= NULL
) {
1983 if ((*sc
->sc_enable
)(sc
) != 0) {
1984 aprint_error_dev(sc
->sc_dev
, "device enable failed\n");
1987 sc
->sc_flags
|= TULIPF_ENABLED
;
1995 * Disable the Tulip chip.
1998 tlp_disable(struct tulip_softc
*sc
)
2001 if (TULIP_IS_ENABLED(sc
) && sc
->sc_disable
!= NULL
) {
2002 (*sc
->sc_disable
)(sc
);
2003 sc
->sc_flags
&= ~TULIPF_ENABLED
;
2010 * Drain the receive queue.
2013 tlp_rxdrain(struct tulip_softc
*sc
)
2015 struct tulip_rxsoft
*rxs
;
2018 for (i
= 0; i
< TULIP_NRXDESC
; i
++) {
2019 rxs
= &sc
->sc_rxsoft
[i
];
2020 if (rxs
->rxs_mbuf
!= NULL
) {
2021 bus_dmamap_unload(sc
->sc_dmat
, rxs
->rxs_dmamap
);
2022 m_freem(rxs
->rxs_mbuf
);
2023 rxs
->rxs_mbuf
= NULL
;
2029 * tlp_stop: [ ifnet interface function ]
2031 * Stop transmission on the interface.
2034 tlp_stop(struct ifnet
*ifp
, int disable
)
2036 struct tulip_softc
*sc
= ifp
->if_softc
;
2037 struct tulip_txsoft
*txs
;
2039 if (sc
->sc_tick
!= NULL
) {
2040 /* Stop the one second clock. */
2041 callout_stop(&sc
->sc_tick_callout
);
2044 if (sc
->sc_flags
& TULIPF_HAS_MII
) {
2046 mii_down(&sc
->sc_mii
);
2049 /* Disable interrupts. */
2050 TULIP_WRITE(sc
, CSR_INTEN
, 0);
2052 /* Stop the transmit and receive processes. */
2054 TULIP_WRITE(sc
, CSR_OPMODE
, 0);
2055 TULIP_WRITE(sc
, CSR_RXLIST
, 0);
2056 TULIP_WRITE(sc
, CSR_TXLIST
, 0);
2059 * Release any queued transmit buffers.
2061 while ((txs
= SIMPLEQ_FIRST(&sc
->sc_txdirtyq
)) != NULL
) {
2062 SIMPLEQ_REMOVE_HEAD(&sc
->sc_txdirtyq
, txs_q
);
2063 if (txs
->txs_mbuf
!= NULL
) {
2064 bus_dmamap_unload(sc
->sc_dmat
, txs
->txs_dmamap
);
2065 m_freem(txs
->txs_mbuf
);
2066 txs
->txs_mbuf
= NULL
;
2068 SIMPLEQ_INSERT_TAIL(&sc
->sc_txfreeq
, txs
, txs_q
);
2071 sc
->sc_flags
&= ~(TULIPF_WANT_SETUP
|TULIPF_DOING_SETUP
);
2074 * Mark the interface down and cancel the watchdog timer.
2076 ifp
->if_flags
&= ~(IFF_RUNNING
| IFF_OACTIVE
);
2077 sc
->sc_if_flags
= ifp
->if_flags
;
2081 * Reset the chip (needed on some flavors to actually disable it).
2091 #define SROM_EMIT(sc, x) \
2093 TULIP_WRITE((sc), CSR_MIIROM, (x)); \
2100 * Put the SROM in idle state.
2103 tlp_srom_idle(struct tulip_softc
*sc
)
2109 SROM_EMIT(sc
, miirom
);
2111 miirom
|= MIIROM_RD
;
2112 SROM_EMIT(sc
, miirom
);
2114 miirom
|= MIIROM_SROMCS
;
2115 SROM_EMIT(sc
, miirom
);
2117 SROM_EMIT(sc
, miirom
|MIIROM_SROMSK
);
2119 /* Strobe the clock 32 times. */
2120 for (i
= 0; i
< 32; i
++) {
2121 SROM_EMIT(sc
, miirom
);
2122 SROM_EMIT(sc
, miirom
|MIIROM_SROMSK
);
2125 SROM_EMIT(sc
, miirom
);
2127 miirom
&= ~MIIROM_SROMCS
;
2128 SROM_EMIT(sc
, miirom
);
2136 * Determine the number of address bits in the SROM.
2139 tlp_srom_size(struct tulip_softc
*sc
)
2144 /* Select the SROM. */
2146 SROM_EMIT(sc
, miirom
);
2148 miirom
|= MIIROM_RD
;
2149 SROM_EMIT(sc
, miirom
);
2151 /* Send CHIP SELECT for one clock tick. */
2152 miirom
|= MIIROM_SROMCS
;
2153 SROM_EMIT(sc
, miirom
);
2155 /* Shift in the READ opcode. */
2156 for (x
= 3; x
> 0; x
--) {
2157 if (TULIP_SROM_OPC_READ
& (1 << (x
- 1)))
2158 miirom
|= MIIROM_SROMDI
;
2160 miirom
&= ~MIIROM_SROMDI
;
2161 SROM_EMIT(sc
, miirom
);
2162 SROM_EMIT(sc
, miirom
|MIIROM_SROMSK
);
2163 SROM_EMIT(sc
, miirom
);
2166 /* Shift in address and look for dummy 0 bit. */
2167 for (x
= 1; x
<= 12; x
++) {
2168 miirom
&= ~MIIROM_SROMDI
;
2169 SROM_EMIT(sc
, miirom
);
2170 SROM_EMIT(sc
, miirom
|MIIROM_SROMSK
);
2171 if (!TULIP_ISSET(sc
, CSR_MIIROM
, MIIROM_SROMDO
))
2173 SROM_EMIT(sc
, miirom
);
2176 /* Clear CHIP SELECT. */
2177 miirom
&= ~MIIROM_SROMCS
;
2178 SROM_EMIT(sc
, miirom
);
2180 /* Deselect the SROM. */
2183 if (x
< 4 || x
> 12) {
2184 aprint_debug_dev(sc
->sc_dev
, "broken MicroWire interface detected; "
2185 "setting SROM size to 1Kb\n");
2189 printf("%s: SROM size is 2^%d*16 bits (%d bytes)\n",
2190 device_xname(sc
->sc_dev
), x
, (1 << (x
+ 4)) >> 3);
2198 * Read the Tulip SROM.
2201 tlp_read_srom(struct tulip_softc
*sc
)
2210 sc
->sc_srom_addrbits
= tlp_srom_size(sc
);
2211 if (sc
->sc_srom_addrbits
== 0)
2213 size
= TULIP_ROM_SIZE(sc
->sc_srom_addrbits
);
2214 sc
->sc_srom
= malloc(size
, M_DEVBUF
, M_NOWAIT
);
2216 /* Select the SROM. */
2218 SROM_EMIT(sc
, miirom
);
2220 miirom
|= MIIROM_RD
;
2221 SROM_EMIT(sc
, miirom
);
2223 for (i
= 0; i
< size
; i
+= 2) {
2224 /* Send CHIP SELECT for one clock tick. */
2225 miirom
|= MIIROM_SROMCS
;
2226 SROM_EMIT(sc
, miirom
);
2228 /* Shift in the READ opcode. */
2229 for (x
= 3; x
> 0; x
--) {
2230 if (TULIP_SROM_OPC_READ
& (1 << (x
- 1)))
2231 miirom
|= MIIROM_SROMDI
;
2233 miirom
&= ~MIIROM_SROMDI
;
2234 SROM_EMIT(sc
, miirom
);
2235 SROM_EMIT(sc
, miirom
|MIIROM_SROMSK
);
2236 SROM_EMIT(sc
, miirom
);
2239 /* Shift in address. */
2240 for (x
= sc
->sc_srom_addrbits
; x
> 0; x
--) {
2242 miirom
|= MIIROM_SROMDI
;
2244 miirom
&= ~MIIROM_SROMDI
;
2245 SROM_EMIT(sc
, miirom
);
2246 SROM_EMIT(sc
, miirom
|MIIROM_SROMSK
);
2247 SROM_EMIT(sc
, miirom
);
2250 /* Shift out data. */
2251 miirom
&= ~MIIROM_SROMDI
;
2253 for (x
= 16; x
> 0; x
--) {
2254 SROM_EMIT(sc
, miirom
|MIIROM_SROMSK
);
2255 if (TULIP_ISSET(sc
, CSR_MIIROM
, MIIROM_SROMDO
))
2256 datain
|= (1 << (x
- 1));
2257 SROM_EMIT(sc
, miirom
);
2259 sc
->sc_srom
[i
] = datain
& 0xff;
2260 sc
->sc_srom
[i
+ 1] = datain
>> 8;
2262 /* Clear CHIP SELECT. */
2263 miirom
&= ~MIIROM_SROMCS
;
2264 SROM_EMIT(sc
, miirom
);
2267 /* Deselect the SROM. */
2270 /* ...and idle it. */
2273 if (tlp_srom_debug
) {
2274 printf("SROM CONTENTS:");
2275 for (i
= 0; i
< size
; i
++) {
2278 printf("0x%02x ", sc
->sc_srom
[i
]);
2291 * Add a receive buffer to the indicated descriptor.
2294 tlp_add_rxbuf(struct tulip_softc
*sc
, int idx
)
2296 struct tulip_rxsoft
*rxs
= &sc
->sc_rxsoft
[idx
];
2300 MGETHDR(m
, M_DONTWAIT
, MT_DATA
);
2304 MCLAIM(m
, &sc
->sc_ethercom
.ec_rx_mowner
);
2305 MCLGET(m
, M_DONTWAIT
);
2306 if ((m
->m_flags
& M_EXT
) == 0) {
2311 if (rxs
->rxs_mbuf
!= NULL
)
2312 bus_dmamap_unload(sc
->sc_dmat
, rxs
->rxs_dmamap
);
2316 error
= bus_dmamap_load(sc
->sc_dmat
, rxs
->rxs_dmamap
,
2317 m
->m_ext
.ext_buf
, m
->m_ext
.ext_size
, NULL
,
2318 BUS_DMA_READ
|BUS_DMA_NOWAIT
);
2320 aprint_error_dev(sc
->sc_dev
, "can't load rx DMA map %d, error = %d\n",
2322 panic("tlp_add_rxbuf"); /* XXX */
2325 bus_dmamap_sync(sc
->sc_dmat
, rxs
->rxs_dmamap
, 0,
2326 rxs
->rxs_dmamap
->dm_mapsize
, BUS_DMASYNC_PREREAD
);
2328 TULIP_INIT_RXDESC(sc
, idx
);
2336 * Check the CRC of the Tulip SROM.
2339 tlp_srom_crcok(const uint8_t *romdata
)
2343 crc
= ether_crc32_le(romdata
, TULIP_ROM_CRC32_CHECKSUM
);
2344 crc
= (crc
& 0xffff) ^ 0xffff;
2345 if (crc
== TULIP_ROM_GETW(romdata
, TULIP_ROM_CRC32_CHECKSUM
))
2349 * Try an alternate checksum.
2351 crc
= ether_crc32_le(romdata
, TULIP_ROM_CRC32_CHECKSUM1
);
2352 crc
= (crc
& 0xffff) ^ 0xffff;
2353 if (crc
== TULIP_ROM_GETW(romdata
, TULIP_ROM_CRC32_CHECKSUM1
))
2362 * Check to see if the SROM is in the new standardized format.
2365 tlp_isv_srom(const uint8_t *romdata
)
2370 if (tlp_srom_crcok(romdata
)) {
2372 * SROM CRC checks out; must be in the new format.
2377 cksum
= TULIP_ROM_GETW(romdata
, TULIP_ROM_CRC32_CHECKSUM
);
2378 if (cksum
== 0xffff || cksum
== 0) {
2380 * No checksum present. Check the SROM ID; 18 bytes of 0
2381 * followed by 1 (version) followed by the number of
2382 * adapters which use this SROM (should be non-zero).
2384 for (i
= 0; i
< TULIP_ROM_SROM_FORMAT_VERION
; i
++) {
2385 if (romdata
[i
] != 0)
2388 if (romdata
[TULIP_ROM_SROM_FORMAT_VERION
] != 1)
2390 if (romdata
[TULIP_ROM_CHIP_COUNT
] == 0)
2399 * tlp_isv_srom_enaddr:
2401 * Get the Ethernet address from an ISV SROM.
2404 tlp_isv_srom_enaddr(struct tulip_softc
*sc
, uint8_t *enaddr
)
2408 if (tlp_isv_srom(sc
->sc_srom
) == 0)
2411 devcnt
= sc
->sc_srom
[TULIP_ROM_CHIP_COUNT
];
2412 for (i
= 0; i
< devcnt
; i
++) {
2413 if (sc
->sc_srom
[TULIP_ROM_CHIP_COUNT
] == 1)
2415 if (sc
->sc_srom
[TULIP_ROM_CHIPn_DEVICE_NUMBER(i
)] ==
2423 memcpy(enaddr
, &sc
->sc_srom
[TULIP_ROM_IEEE_NETWORK_ADDRESS
],
2431 * tlp_parse_old_srom:
2433 * Parse old-format SROMs.
2435 * This routine is largely lifted from Matt Thomas's `de' driver.
2438 tlp_parse_old_srom(struct tulip_softc
*sc
, uint8_t *enaddr
)
2440 static const uint8_t testpat
[] =
2441 { 0xff, 0, 0x55, 0xaa, 0xff, 0, 0x55, 0xaa };
2445 if (memcmp(&sc
->sc_srom
[0], &sc
->sc_srom
[16], 8) != 0) {
2447 * Phobos G100 interfaces have the address at
2448 * offsets 0 and 20, but each pair of bytes is
2451 if (sc
->sc_srom_addrbits
== 6 &&
2452 sc
->sc_srom
[1] == 0x00 &&
2453 sc
->sc_srom
[0] == 0x60 &&
2454 sc
->sc_srom
[3] == 0xf5 &&
2455 memcmp(&sc
->sc_srom
[0], &sc
->sc_srom
[20], 6) == 0) {
2456 for (i
= 0; i
< 6; i
+= 2) {
2457 enaddr
[i
] = sc
->sc_srom
[i
+ 1];
2458 enaddr
[i
+ 1] = sc
->sc_srom
[i
];
2464 * Phobos G130/G160 interfaces have the address at
2465 * offsets 20 and 84, but each pair of bytes is
2468 if (sc
->sc_srom_addrbits
== 6 &&
2469 sc
->sc_srom
[21] == 0x00 &&
2470 sc
->sc_srom
[20] == 0x60 &&
2471 sc
->sc_srom
[23] == 0xf5 &&
2472 memcmp(&sc
->sc_srom
[20], &sc
->sc_srom
[84], 6) == 0) {
2473 for (i
= 0; i
< 6; i
+= 2) {
2474 enaddr
[i
] = sc
->sc_srom
[20 + i
+ 1];
2475 enaddr
[i
+ 1] = sc
->sc_srom
[20 + i
];
2481 * Cobalt Networks interfaces simply have the address
2482 * in the first six bytes. The rest is zeroed out
2483 * on some models, but others contain unknown data.
2485 if (sc
->sc_srom
[0] == 0x00 &&
2486 sc
->sc_srom
[1] == 0x10 &&
2487 sc
->sc_srom
[2] == 0xe0) {
2488 memcpy(enaddr
, sc
->sc_srom
, ETHER_ADDR_LEN
);
2493 * Some vendors (e.g. ZNYX) don't use the standard
2494 * DEC Address ROM format, but rather just have an
2495 * Ethernet address in the first 6 bytes, maybe a
2496 * 2 byte checksum, and then all 0xff's.
2498 for (i
= 8; i
< 32; i
++) {
2499 if (sc
->sc_srom
[i
] != 0xff &&
2500 sc
->sc_srom
[i
] != 0)
2505 * Sanity check the Ethernet address:
2507 * - Make sure it's not multicast or locally
2509 * - Make sure it has a non-0 OUI
2511 if (sc
->sc_srom
[0] & 3)
2513 if (sc
->sc_srom
[0] == 0 && sc
->sc_srom
[1] == 0 &&
2514 sc
->sc_srom
[2] == 0)
2517 memcpy(enaddr
, sc
->sc_srom
, ETHER_ADDR_LEN
);
2522 * Standard DEC Address ROM test.
2525 if (memcmp(&sc
->sc_srom
[24], testpat
, 8) != 0)
2528 for (i
= 0; i
< 8; i
++) {
2529 if (sc
->sc_srom
[i
] != sc
->sc_srom
[15 - i
])
2533 memcpy(enaddr
, sc
->sc_srom
, ETHER_ADDR_LEN
);
2535 cksum
= *(uint16_t *) &enaddr
[0];
2541 cksum
+= *(uint16_t *) &enaddr
[2];
2549 cksum
+= *(uint16_t *) &enaddr
[4];
2550 if (cksum
>= 0xffff)
2553 if (cksum
!= *(uint16_t *) &sc
->sc_srom
[6])
2562 * Set the Tulip's receive filter.
2565 tlp_filter_setup(struct tulip_softc
*sc
)
2567 struct ethercom
*ec
= &sc
->sc_ethercom
;
2568 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
2569 struct ether_multi
*enm
;
2570 struct ether_multistep step
;
2571 volatile uint32_t *sp
;
2572 struct tulip_txsoft
*txs
;
2573 uint8_t enaddr
[ETHER_ADDR_LEN
];
2574 uint32_t hash
, hashsize
;
2577 DPRINTF(sc
, ("%s: tlp_filter_setup: sc_flags 0x%08x\n",
2578 device_xname(sc
->sc_dev
), sc
->sc_flags
));
2580 memcpy(enaddr
, CLLADDR(ifp
->if_sadl
), ETHER_ADDR_LEN
);
2583 * If there are transmissions pending, wait until they have
2586 if (! SIMPLEQ_EMPTY(&sc
->sc_txdirtyq
) ||
2587 (sc
->sc_flags
& TULIPF_DOING_SETUP
) != 0) {
2588 sc
->sc_flags
|= TULIPF_WANT_SETUP
;
2589 DPRINTF(sc
, ("%s: tlp_filter_setup: deferring\n",
2590 device_xname(sc
->sc_dev
)));
2593 sc
->sc_flags
&= ~TULIPF_WANT_SETUP
;
2595 switch (sc
->sc_chip
) {
2596 case TULIP_CHIP_82C115
:
2597 hashsize
= TULIP_PNICII_HASHSIZE
;
2601 hashsize
= TULIP_MCHASHSIZE
;
2605 * If we're running, idle the transmit and receive engines. If
2606 * we're NOT running, we're being called from tlp_init(), and our
2607 * writing OPMODE will start the transmit and receive processes
2610 if (ifp
->if_flags
& IFF_RUNNING
)
2611 tlp_idle(sc
, OPMODE_ST
|OPMODE_SR
);
2613 sc
->sc_opmode
&= ~(OPMODE_PR
|OPMODE_PM
);
2615 if (ifp
->if_flags
& IFF_PROMISC
) {
2616 sc
->sc_opmode
|= OPMODE_PR
;
2621 * Try Perfect filtering first.
2624 sc
->sc_filtmode
= TDCTL_Tx_FT_PERFECT
;
2625 sp
= TULIP_CDSP(sc
);
2626 memset(TULIP_CDSP(sc
), 0, TULIP_SETUP_PACKET_LEN
);
2628 ETHER_FIRST_MULTI(step
, ec
, enm
);
2629 while (enm
!= NULL
) {
2630 if (memcmp(enm
->enm_addrlo
, enm
->enm_addrhi
, ETHER_ADDR_LEN
)) {
2632 * We must listen to a range of multicast addresses.
2633 * For now, just accept all multicasts, rather than
2634 * trying to set only those filter bits needed to match
2635 * the range. (At this time, the only use of address
2636 * ranges is for IP multicast routing, for which the
2637 * range is big enough to require all bits set.)
2641 if (cnt
== (TULIP_MAXADDRS
- 2)) {
2643 * We already have our multicast limit (still need
2644 * our station address and broadcast). Go to
2645 * Hash-Perfect mode.
2650 *sp
++ = htole32(TULIP_SP_FIELD(enm
->enm_addrlo
, 0));
2651 *sp
++ = htole32(TULIP_SP_FIELD(enm
->enm_addrlo
, 1));
2652 *sp
++ = htole32(TULIP_SP_FIELD(enm
->enm_addrlo
, 2));
2653 ETHER_NEXT_MULTI(step
, enm
);
2656 if (ifp
->if_flags
& IFF_BROADCAST
) {
2657 /* ...and the broadcast address. */
2659 *sp
++ = htole32(TULIP_SP_FIELD_C(0xff, 0xff));
2660 *sp
++ = htole32(TULIP_SP_FIELD_C(0xff, 0xff));
2661 *sp
++ = htole32(TULIP_SP_FIELD_C(0xff, 0xff));
2664 /* Pad the rest with our station address. */
2665 for (; cnt
< TULIP_MAXADDRS
; cnt
++) {
2666 *sp
++ = htole32(TULIP_SP_FIELD(enaddr
, 0));
2667 *sp
++ = htole32(TULIP_SP_FIELD(enaddr
, 1));
2668 *sp
++ = htole32(TULIP_SP_FIELD(enaddr
, 2));
2670 ifp
->if_flags
&= ~IFF_ALLMULTI
;
2675 * Try Hash-Perfect mode.
2679 * Some 21140 chips have broken Hash-Perfect modes. On these
2680 * chips, we simply use Hash-Only mode, and put our station
2681 * address into the filter.
2683 if (sc
->sc_chip
== TULIP_CHIP_21140
)
2684 sc
->sc_filtmode
= TDCTL_Tx_FT_HASHONLY
;
2686 sc
->sc_filtmode
= TDCTL_Tx_FT_HASH
;
2687 sp
= TULIP_CDSP(sc
);
2688 memset(TULIP_CDSP(sc
), 0, TULIP_SETUP_PACKET_LEN
);
2689 ETHER_FIRST_MULTI(step
, ec
, enm
);
2690 while (enm
!= NULL
) {
2691 if (memcmp(enm
->enm_addrlo
, enm
->enm_addrhi
, ETHER_ADDR_LEN
)) {
2693 * We must listen to a range of multicast addresses.
2694 * For now, just accept all multicasts, rather than
2695 * trying to set only those filter bits needed to match
2696 * the range. (At this time, the only use of address
2697 * ranges is for IP multicast routing, for which the
2698 * range is big enough to require all bits set.)
2702 hash
= tlp_mchash(enm
->enm_addrlo
, hashsize
);
2703 sp
[hash
>> 4] |= htole32(1 << (hash
& 0xf));
2704 ETHER_NEXT_MULTI(step
, enm
);
2707 if (ifp
->if_flags
& IFF_BROADCAST
) {
2708 /* ...and the broadcast address. */
2709 hash
= tlp_mchash(etherbroadcastaddr
, hashsize
);
2710 sp
[hash
>> 4] |= htole32(1 << (hash
& 0xf));
2713 if (sc
->sc_filtmode
== TDCTL_Tx_FT_HASHONLY
) {
2714 /* ...and our station address. */
2715 hash
= tlp_mchash(enaddr
, hashsize
);
2716 sp
[hash
>> 4] |= htole32(1 << (hash
& 0xf));
2719 * Hash-Perfect mode; put our station address after
2722 sp
[39] = htole32(TULIP_SP_FIELD(enaddr
, 0));
2723 sp
[40] = htole32(TULIP_SP_FIELD(enaddr
, 1));
2724 sp
[41] = htole32(TULIP_SP_FIELD(enaddr
, 2));
2726 ifp
->if_flags
&= ~IFF_ALLMULTI
;
2731 * Use Perfect filter mode. First address is the broadcast address,
2732 * and pad the rest with our station address. We'll set Pass-all-
2733 * multicast in OPMODE below.
2735 sc
->sc_filtmode
= TDCTL_Tx_FT_PERFECT
;
2736 sp
= TULIP_CDSP(sc
);
2737 memset(TULIP_CDSP(sc
), 0, TULIP_SETUP_PACKET_LEN
);
2739 if (ifp
->if_flags
& IFF_BROADCAST
) {
2741 *sp
++ = htole32(TULIP_SP_FIELD_C(0xff, 0xff));
2742 *sp
++ = htole32(TULIP_SP_FIELD_C(0xff, 0xff));
2743 *sp
++ = htole32(TULIP_SP_FIELD_C(0xff, 0xff));
2745 for (; cnt
< TULIP_MAXADDRS
; cnt
++) {
2746 *sp
++ = htole32(TULIP_SP_FIELD(enaddr
, 0));
2747 *sp
++ = htole32(TULIP_SP_FIELD(enaddr
, 1));
2748 *sp
++ = htole32(TULIP_SP_FIELD(enaddr
, 2));
2750 ifp
->if_flags
|= IFF_ALLMULTI
;
2753 if (ifp
->if_flags
& IFF_ALLMULTI
)
2754 sc
->sc_opmode
|= OPMODE_PM
;
2756 /* Sync the setup packet buffer. */
2757 TULIP_CDSPSYNC(sc
, BUS_DMASYNC_PREWRITE
);
2760 * Fill in the setup packet descriptor.
2762 txs
= SIMPLEQ_FIRST(&sc
->sc_txfreeq
);
2764 txs
->txs_firstdesc
= sc
->sc_txnext
;
2765 txs
->txs_lastdesc
= sc
->sc_txnext
;
2766 txs
->txs_ndescs
= 1;
2767 txs
->txs_mbuf
= NULL
;
2769 nexttx
= sc
->sc_txnext
;
2770 sc
->sc_txdescs
[nexttx
].td_status
= 0;
2771 sc
->sc_txdescs
[nexttx
].td_bufaddr1
= htole32(TULIP_CDSPADDR(sc
));
2772 sc
->sc_txdescs
[nexttx
].td_ctl
=
2773 htole32((TULIP_SETUP_PACKET_LEN
<< TDCTL_SIZE1_SHIFT
) |
2774 sc
->sc_filtmode
| TDCTL_Tx_SET
| sc
->sc_setup_fsls
|
2775 TDCTL_Tx_IC
| sc
->sc_tdctl_ch
|
2776 (nexttx
== (TULIP_NTXDESC
- 1) ? sc
->sc_tdctl_er
: 0));
2777 TULIP_CDTXSYNC(sc
, nexttx
, 1,
2778 BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
2781 if (ifp
->if_flags
& IFF_DEBUG
) {
2782 printf(" filter_setup %p transmit chain:\n", txs
);
2783 printf(" descriptor %d:\n", nexttx
);
2784 printf(" td_status: 0x%08x\n",
2785 le32toh(sc
->sc_txdescs
[nexttx
].td_status
));
2786 printf(" td_ctl: 0x%08x\n",
2787 le32toh(sc
->sc_txdescs
[nexttx
].td_ctl
));
2788 printf(" td_bufaddr1: 0x%08x\n",
2789 le32toh(sc
->sc_txdescs
[nexttx
].td_bufaddr1
));
2790 printf(" td_bufaddr2: 0x%08x\n",
2791 le32toh(sc
->sc_txdescs
[nexttx
].td_bufaddr2
));
2795 sc
->sc_txdescs
[nexttx
].td_status
= htole32(TDSTAT_OWN
);
2796 TULIP_CDTXSYNC(sc
, nexttx
, 1,
2797 BUS_DMASYNC_PREREAD
|BUS_DMASYNC_PREWRITE
);
2799 /* Advance the tx pointer. */
2801 sc
->sc_txnext
= TULIP_NEXTTX(nexttx
);
2803 SIMPLEQ_REMOVE_HEAD(&sc
->sc_txfreeq
, txs_q
);
2804 SIMPLEQ_INSERT_TAIL(&sc
->sc_txdirtyq
, txs
, txs_q
);
2807 * Set the OPMODE register. This will also resume the
2808 * transmit process we idled above.
2810 TULIP_WRITE(sc
, CSR_OPMODE
, sc
->sc_opmode
);
2812 sc
->sc_flags
|= TULIPF_DOING_SETUP
;
2815 * Kick the transmitter; this will cause the Tulip to
2816 * read the setup descriptor.
2818 /* XXX USE AUTOPOLLING? */
2819 TULIP_WRITE(sc
, CSR_TXPOLL
, TXPOLL_TPD
);
2821 /* Set up a watchdog timer in case the chip flakes out. */
2824 DPRINTF(sc
, ("%s: tlp_filter_setup: returning\n", device_xname(sc
->sc_dev
)));
2828 * tlp_winb_filter_setup:
2830 * Set the Winbond 89C840F's receive filter.
2833 tlp_winb_filter_setup(struct tulip_softc
*sc
)
2835 struct ethercom
*ec
= &sc
->sc_ethercom
;
2836 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
2837 struct ether_multi
*enm
;
2838 struct ether_multistep step
;
2839 uint32_t hash
, mchash
[2];
2841 DPRINTF(sc
, ("%s: tlp_winb_filter_setup: sc_flags 0x%08x\n",
2842 device_xname(sc
->sc_dev
), sc
->sc_flags
));
2844 sc
->sc_opmode
&= ~(OPMODE_WINB_APP
|OPMODE_WINB_AMP
|OPMODE_WINB_ABP
);
2846 if (ifp
->if_flags
& IFF_MULTICAST
)
2847 sc
->sc_opmode
|= OPMODE_WINB_AMP
;
2849 if (ifp
->if_flags
& IFF_BROADCAST
)
2850 sc
->sc_opmode
|= OPMODE_WINB_ABP
;
2852 if (ifp
->if_flags
& IFF_PROMISC
) {
2853 sc
->sc_opmode
|= OPMODE_WINB_APP
;
2857 mchash
[0] = mchash
[1] = 0;
2859 ETHER_FIRST_MULTI(step
, ec
, enm
);
2860 while (enm
!= NULL
) {
2861 if (memcmp(enm
->enm_addrlo
, enm
->enm_addrhi
, ETHER_ADDR_LEN
)) {
2863 * We must listen to a range of multicast addresses.
2864 * For now, just accept all multicasts, rather than
2865 * trying to set only those filter bits needed to match
2866 * the range. (At this time, the only use of address
2867 * ranges is for IP multicast routing, for which the
2868 * range is big enough to require all bits set.)
2874 * According to the FreeBSD `wb' driver, yes, you
2875 * really do invert the hash.
2878 (~(ether_crc32_le(enm
->enm_addrlo
, ETHER_ADDR_LEN
) >> 26))
2880 mchash
[hash
>> 5] |= 1 << (hash
& 0x1f);
2881 ETHER_NEXT_MULTI(step
, enm
);
2883 ifp
->if_flags
&= ~IFF_ALLMULTI
;
2887 ifp
->if_flags
|= IFF_ALLMULTI
;
2888 mchash
[0] = mchash
[1] = 0xffffffff;
2891 TULIP_WRITE(sc
, CSR_WINB_CMA0
, mchash
[0]);
2892 TULIP_WRITE(sc
, CSR_WINB_CMA1
, mchash
[1]);
2893 TULIP_WRITE(sc
, CSR_OPMODE
, sc
->sc_opmode
);
2894 DPRINTF(sc
, ("%s: tlp_winb_filter_setup: returning\n",
2895 device_xname(sc
->sc_dev
)));
2899 * tlp_al981_filter_setup:
2901 * Set the ADMtek AL981's receive filter.
2904 tlp_al981_filter_setup(struct tulip_softc
*sc
)
2906 struct ethercom
*ec
= &sc
->sc_ethercom
;
2907 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
2908 struct ether_multi
*enm
;
2909 struct ether_multistep step
;
2910 uint32_t hash
, mchash
[2];
2913 * If the chip is running, we need to reset the interface,
2914 * and will revisit here (with IFF_RUNNING) clear. The
2915 * chip seems to really not like to have its multicast
2916 * filter programmed without a reset.
2918 if (ifp
->if_flags
& IFF_RUNNING
) {
2919 (void) tlp_init(ifp
);
2923 DPRINTF(sc
, ("%s: tlp_al981_filter_setup: sc_flags 0x%08x\n",
2924 device_xname(sc
->sc_dev
), sc
->sc_flags
));
2926 sc
->sc_opmode
&= ~(OPMODE_PR
|OPMODE_PM
);
2928 if (ifp
->if_flags
& IFF_PROMISC
) {
2929 sc
->sc_opmode
|= OPMODE_PR
;
2933 mchash
[0] = mchash
[1] = 0;
2935 ETHER_FIRST_MULTI(step
, ec
, enm
);
2936 while (enm
!= NULL
) {
2937 if (memcmp(enm
->enm_addrlo
, enm
->enm_addrhi
, ETHER_ADDR_LEN
)) {
2939 * We must listen to a range of multicast addresses.
2940 * For now, just accept all multicasts, rather than
2941 * trying to set only those filter bits needed to match
2942 * the range. (At this time, the only use of address
2943 * ranges is for IP multicast routing, for which the
2944 * range is big enough to require all bits set.)
2949 hash
= ether_crc32_le(enm
->enm_addrlo
, ETHER_ADDR_LEN
) & 0x3f;
2950 mchash
[hash
>> 5] |= 1 << (hash
& 0x1f);
2951 ETHER_NEXT_MULTI(step
, enm
);
2953 ifp
->if_flags
&= ~IFF_ALLMULTI
;
2957 ifp
->if_flags
|= IFF_ALLMULTI
;
2958 mchash
[0] = mchash
[1] = 0xffffffff;
2961 bus_space_write_4(sc
->sc_st
, sc
->sc_sh
, CSR_ADM_MAR0
, mchash
[0]);
2962 bus_space_write_4(sc
->sc_st
, sc
->sc_sh
, CSR_ADM_MAR1
, mchash
[1]);
2963 TULIP_WRITE(sc
, CSR_OPMODE
, sc
->sc_opmode
);
2964 DPRINTF(sc
, ("%s: tlp_al981_filter_setup: returning\n",
2965 device_xname(sc
->sc_dev
)));
2969 * tlp_asix_filter_setup:
2971 * Set the ASIX AX8814x recieve filter.
2974 tlp_asix_filter_setup(struct tulip_softc
*sc
)
2976 struct ethercom
*ec
= &sc
->sc_ethercom
;
2977 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
2978 struct ether_multi
*enm
;
2979 struct ether_multistep step
;
2980 uint32_t hash
, mchash
[2];
2982 DPRINTF(sc
, ("%s: tlp_asix_filter_setup: sc_flags 0x%08x\n",
2983 device_xname(sc
->sc_dev
), sc
->sc_flags
));
2985 sc
->sc_opmode
&= ~(OPMODE_PM
|OPMODE_AX_RB
|OPMODE_PR
);
2987 if (ifp
->if_flags
& IFF_MULTICAST
)
2988 sc
->sc_opmode
|= OPMODE_PM
;
2990 if (ifp
->if_flags
& IFF_BROADCAST
)
2991 sc
->sc_opmode
|= OPMODE_AX_RB
;
2993 if (ifp
->if_flags
& IFF_PROMISC
) {
2994 sc
->sc_opmode
|= OPMODE_PR
;
2998 mchash
[0] = mchash
[1] = 0;
3000 ETHER_FIRST_MULTI(step
, ec
, enm
);
3001 while (enm
!= NULL
) {
3002 if (memcmp(enm
->enm_addrlo
, enm
->enm_addrhi
, ETHER_ADDR_LEN
)) {
3004 * We must listen to a range of multicast addresses.
3005 * For now, just accept all multicasts, rather than
3006 * trying to set only those filter bits needed to match
3007 * the range. (At this time, the only use of address
3008 * ranges is for IP multicast routing, for which the
3009 * range is big enough to require all bits set.)
3013 hash
= (ether_crc32_be(enm
->enm_addrlo
, ETHER_ADDR_LEN
) >> 26)
3016 mchash
[0] |= (1 << hash
);
3018 mchash
[1] |= (1 << (hash
- 32));
3019 ETHER_NEXT_MULTI(step
, enm
);
3021 ifp
->if_flags
&= ~IFF_ALLMULTI
;
3025 ifp
->if_flags
|= IFF_ALLMULTI
;
3026 mchash
[0] = mchash
[1] = 0xffffffff;
3029 TULIP_WRITE(sc
, CSR_AX_FILTIDX
, AX_FILTIDX_MAR0
);
3030 TULIP_WRITE(sc
, CSR_AX_FILTDATA
, mchash
[0]);
3031 TULIP_WRITE(sc
, CSR_AX_FILTIDX
, AX_FILTIDX_MAR1
);
3032 TULIP_WRITE(sc
, CSR_AX_FILTDATA
, mchash
[1]);
3033 TULIP_WRITE(sc
, CSR_OPMODE
, sc
->sc_opmode
);
3034 DPRINTF(sc
, ("%s: tlp_asix_filter_setup: returning\n",
3035 device_xname(sc
->sc_dev
)));
3042 * Cause the transmit and/or receive processes to go idle.
3045 tlp_idle(struct tulip_softc
*sc
, uint32_t bits
)
3047 static const char * const tlp_tx_state_names
[] = {
3051 "RUNNING - READING",
3057 static const char * const tlp_rx_state_names
[] = {
3067 static const char * const dm9102_tx_state_names
[] = {
3071 "RUNNING - READING",
3072 "RUNNING - CLOSE - CLEAR OWNER",
3074 "RUNNING - CLOSE - WRITE STATUS",
3077 static const char * const dm9102_rx_state_names
[] = {
3082 "RUNNING - CLOSE - CLEAR OWNER",
3083 "RUNNING - CLOSE - WRITE STATUS",
3088 const char * const *tx_state_names
, * const *rx_state_names
;
3089 uint32_t csr
, ackmask
= 0;
3092 switch (sc
->sc_chip
) {
3093 case TULIP_CHIP_DM9102
:
3094 case TULIP_CHIP_DM9102A
:
3095 tx_state_names
= dm9102_tx_state_names
;
3096 rx_state_names
= dm9102_rx_state_names
;
3100 tx_state_names
= tlp_tx_state_names
;
3101 rx_state_names
= tlp_rx_state_names
;
3105 if (bits
& OPMODE_ST
)
3106 ackmask
|= STATUS_TPS
;
3108 if (bits
& OPMODE_SR
)
3109 ackmask
|= STATUS_RPS
;
3111 TULIP_WRITE(sc
, CSR_OPMODE
, sc
->sc_opmode
& ~bits
);
3113 for (i
= 0; i
< 1000; i
++) {
3114 if (TULIP_ISSET(sc
, CSR_STATUS
, ackmask
) == ackmask
)
3119 csr
= TULIP_READ(sc
, CSR_STATUS
);
3120 if ((csr
& ackmask
) != ackmask
) {
3121 if ((bits
& OPMODE_ST
) != 0 && (csr
& STATUS_TPS
) == 0 &&
3122 (csr
& STATUS_TS
) != STATUS_TS_STOPPED
) {
3123 switch (sc
->sc_chip
) {
3124 case TULIP_CHIP_AX88140
:
3125 case TULIP_CHIP_AX88141
:
3127 * Filter the message out on noisy chips.
3131 printf("%s: transmit process failed to idle: "
3132 "state %s\n", device_xname(sc
->sc_dev
),
3133 tx_state_names
[(csr
& STATUS_TS
) >> 20]);
3136 if ((bits
& OPMODE_SR
) != 0 && (csr
& STATUS_RPS
) == 0 &&
3137 (csr
& STATUS_RS
) != STATUS_RS_STOPPED
) {
3138 switch (sc
->sc_chip
) {
3139 case TULIP_CHIP_AN983
:
3140 case TULIP_CHIP_AN985
:
3141 case TULIP_CHIP_DM9102A
:
3142 case TULIP_CHIP_RS7112
:
3144 * Filter the message out on noisy chips.
3148 printf("%s: receive process failed to idle: "
3149 "state %s\n", device_xname(sc
->sc_dev
),
3150 rx_state_names
[(csr
& STATUS_RS
) >> 17]);
3154 TULIP_WRITE(sc
, CSR_STATUS
, ackmask
);
3157 /*****************************************************************************
3158 * Generic media support functions.
3159 *****************************************************************************/
3162 * tlp_mediastatus: [ifmedia interface function]
3164 * Query the current media.
3167 tlp_mediastatus(struct ifnet
*ifp
, struct ifmediareq
*ifmr
)
3169 struct tulip_softc
*sc
= ifp
->if_softc
;
3171 if (TULIP_IS_ENABLED(sc
) == 0) {
3172 ifmr
->ifm_active
= IFM_ETHER
| IFM_NONE
;
3173 ifmr
->ifm_status
= 0;
3177 (*sc
->sc_mediasw
->tmsw_get
)(sc
, ifmr
);
3181 * tlp_mediachange: [ifmedia interface function]
3183 * Update the current media.
3186 tlp_mediachange(struct ifnet
*ifp
)
3188 struct tulip_softc
*sc
= ifp
->if_softc
;
3190 if ((ifp
->if_flags
& IFF_UP
) == 0)
3192 return ((*sc
->sc_mediasw
->tmsw_set
)(sc
));
3195 /*****************************************************************************
3196 * Support functions for MII-attached media.
3197 *****************************************************************************/
3202 * One second timer, used to tick the MII.
3205 tlp_mii_tick(void *arg
)
3207 struct tulip_softc
*sc
= arg
;
3210 if (!device_is_active(sc
->sc_dev
))
3214 mii_tick(&sc
->sc_mii
);
3217 callout_reset(&sc
->sc_tick_callout
, hz
, sc
->sc_tick
, sc
);
3221 * tlp_mii_statchg: [mii interface function]
3223 * Callback from PHY when media changes.
3226 tlp_mii_statchg(device_t self
)
3228 struct tulip_softc
*sc
= device_private(self
);
3230 /* Idle the transmit and receive processes. */
3231 tlp_idle(sc
, OPMODE_ST
|OPMODE_SR
);
3233 sc
->sc_opmode
&= ~(OPMODE_TTM
|OPMODE_FD
|OPMODE_HBD
);
3235 if (IFM_SUBTYPE(sc
->sc_mii
.mii_media_active
) == IFM_10_T
)
3236 sc
->sc_opmode
|= OPMODE_TTM
;
3238 sc
->sc_opmode
|= OPMODE_HBD
;
3240 if (sc
->sc_mii
.mii_media_active
& IFM_FDX
)
3241 sc
->sc_opmode
|= OPMODE_FD
|OPMODE_HBD
;
3244 * Write new OPMODE bits. This also restarts the transmit
3245 * and receive processes.
3247 TULIP_WRITE(sc
, CSR_OPMODE
, sc
->sc_opmode
);
3251 * tlp_winb_mii_statchg: [mii interface function]
3253 * Callback from PHY when media changes. This version is
3254 * for the Winbond 89C840F, which has different OPMODE bits.
3257 tlp_winb_mii_statchg(device_t self
)
3259 struct tulip_softc
*sc
= device_private(self
);
3261 /* Idle the transmit and receive processes. */
3262 tlp_idle(sc
, OPMODE_ST
|OPMODE_SR
);
3264 sc
->sc_opmode
&= ~(OPMODE_WINB_FES
|OPMODE_FD
);
3266 if (IFM_SUBTYPE(sc
->sc_mii
.mii_media_active
) == IFM_100_TX
)
3267 sc
->sc_opmode
|= OPMODE_WINB_FES
;
3269 if (sc
->sc_mii
.mii_media_active
& IFM_FDX
)
3270 sc
->sc_opmode
|= OPMODE_FD
;
3273 * Write new OPMODE bits. This also restarts the transmit
3274 * and receive processes.
3276 TULIP_WRITE(sc
, CSR_OPMODE
, sc
->sc_opmode
);
3280 * tlp_dm9102_mii_statchg: [mii interface function]
3282 * Callback from PHY when media changes. This version is
3286 tlp_dm9102_mii_statchg(device_t self
)
3288 struct tulip_softc
*sc
= device_private(self
);
3291 * Don't idle the transmit and receive processes, here. It
3292 * seems to fail, and just causes excess noise.
3294 sc
->sc_opmode
&= ~(OPMODE_TTM
|OPMODE_FD
);
3296 if (IFM_SUBTYPE(sc
->sc_mii
.mii_media_active
) != IFM_100_TX
)
3297 sc
->sc_opmode
|= OPMODE_TTM
;
3299 if (sc
->sc_mii
.mii_media_active
& IFM_FDX
)
3300 sc
->sc_opmode
|= OPMODE_FD
;
3303 * Write new OPMODE bits.
3305 TULIP_WRITE(sc
, CSR_OPMODE
, sc
->sc_opmode
);
3311 * Callback from ifmedia to request current media status.
3314 tlp_mii_getmedia(struct tulip_softc
*sc
, struct ifmediareq
*ifmr
)
3317 mii_pollstat(&sc
->sc_mii
);
3318 ifmr
->ifm_status
= sc
->sc_mii
.mii_media_status
;
3319 ifmr
->ifm_active
= sc
->sc_mii
.mii_media_active
;
3325 * Callback from ifmedia to request new media setting.
3328 tlp_mii_setmedia(struct tulip_softc
*sc
)
3330 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
3333 if ((ifp
->if_flags
& IFF_UP
) == 0)
3335 switch (sc
->sc_chip
) {
3336 case TULIP_CHIP_21142
:
3337 case TULIP_CHIP_21143
:
3338 /* Disable the internal Nway engine. */
3339 TULIP_WRITE(sc
, CSR_SIATXRX
, 0);
3346 if ((rc
= mii_mediachg(&sc
->sc_mii
)) == ENXIO
)
3352 * tlp_bitbang_mii_readreg:
3354 * Read a PHY register via bit-bang'ing the MII.
3357 tlp_bitbang_mii_readreg(device_t self
, int phy
, int reg
)
3359 struct tulip_softc
*sc
= device_private(self
);
3361 return (mii_bitbang_readreg(self
, sc
->sc_bitbang_ops
, phy
, reg
));
3365 * tlp_bitbang_mii_writereg:
3367 * Write a PHY register via bit-bang'ing the MII.
3370 tlp_bitbang_mii_writereg(device_t self
, int phy
, int reg
, int val
)
3372 struct tulip_softc
*sc
= device_private(self
);
3374 mii_bitbang_writereg(self
, sc
->sc_bitbang_ops
, phy
, reg
, val
);
3378 * tlp_sio_mii_bitbang_read:
3380 * Read the MII serial port for the MII bit-bang module.
3383 tlp_sio_mii_bitbang_read(device_t self
)
3385 struct tulip_softc
*sc
= device_private(self
);
3387 return (TULIP_READ(sc
, CSR_MIIROM
));
3391 * tlp_sio_mii_bitbang_write:
3393 * Write the MII serial port for the MII bit-bang module.
3396 tlp_sio_mii_bitbang_write(device_t self
, uint32_t val
)
3398 struct tulip_softc
*sc
= device_private(self
);
3400 TULIP_WRITE(sc
, CSR_MIIROM
, val
);
3404 * tlp_pnic_mii_readreg:
3406 * Read a PHY register on the Lite-On PNIC.
3409 tlp_pnic_mii_readreg(device_t self
, int phy
, int reg
)
3411 struct tulip_softc
*sc
= device_private(self
);
3415 TULIP_WRITE(sc
, CSR_PNIC_MII
,
3416 PNIC_MII_MBO
| PNIC_MII_RESERVED
|
3417 PNIC_MII_READ
| (phy
<< PNIC_MII_PHYSHIFT
) |
3418 (reg
<< PNIC_MII_REGSHIFT
));
3420 for (i
= 0; i
< 1000; i
++) {
3422 val
= TULIP_READ(sc
, CSR_PNIC_MII
);
3423 if ((val
& PNIC_MII_BUSY
) == 0) {
3424 if ((val
& PNIC_MII_DATA
) == PNIC_MII_DATA
)
3427 return (val
& PNIC_MII_DATA
);
3430 printf("%s: MII read timed out\n", device_xname(sc
->sc_dev
));
3435 * tlp_pnic_mii_writereg:
3437 * Write a PHY register on the Lite-On PNIC.
3440 tlp_pnic_mii_writereg(device_t self
, int phy
, int reg
, int val
)
3442 struct tulip_softc
*sc
= device_private(self
);
3445 TULIP_WRITE(sc
, CSR_PNIC_MII
,
3446 PNIC_MII_MBO
| PNIC_MII_RESERVED
|
3447 PNIC_MII_WRITE
| (phy
<< PNIC_MII_PHYSHIFT
) |
3448 (reg
<< PNIC_MII_REGSHIFT
) | val
);
3450 for (i
= 0; i
< 1000; i
++) {
3452 if (TULIP_ISSET(sc
, CSR_PNIC_MII
, PNIC_MII_BUSY
) == 0)
3455 printf("%s: MII write timed out\n", device_xname(sc
->sc_dev
));
3458 static const bus_addr_t tlp_al981_phy_regmap
[] = {
3472 static const int tlp_al981_phy_regmap_size
= sizeof(tlp_al981_phy_regmap
) /
3473 sizeof(tlp_al981_phy_regmap
[0]);
3476 * tlp_al981_mii_readreg:
3478 * Read a PHY register on the ADMtek AL981.
3481 tlp_al981_mii_readreg(device_t self
, int phy
, int reg
)
3483 struct tulip_softc
*sc
= device_private(self
);
3485 /* AL981 only has an internal PHY. */
3489 if (reg
>= tlp_al981_phy_regmap_size
)
3492 return (bus_space_read_4(sc
->sc_st
, sc
->sc_sh
,
3493 tlp_al981_phy_regmap
[reg
]) & 0xffff);
3497 * tlp_al981_mii_writereg:
3499 * Write a PHY register on the ADMtek AL981.
3502 tlp_al981_mii_writereg(device_t self
, int phy
, int reg
, int val
)
3504 struct tulip_softc
*sc
= device_private(self
);
3506 /* AL981 only has an internal PHY. */
3510 if (reg
>= tlp_al981_phy_regmap_size
)
3513 bus_space_write_4(sc
->sc_st
, sc
->sc_sh
,
3514 tlp_al981_phy_regmap
[reg
], val
);
3517 /*****************************************************************************
3518 * Chip-specific pre-init and reset functions.
3519 *****************************************************************************/
3522 * tlp_2114x_preinit:
3524 * Pre-init function shared by DECchip 21140, 21140A, 21142, and 21143.
3527 tlp_2114x_preinit(struct tulip_softc
*sc
)
3529 struct ifmedia_entry
*ife
= sc
->sc_mii
.mii_media
.ifm_cur
;
3530 struct tulip_21x4x_media
*tm
= ife
->ifm_aux
;
3533 * Whether or not we're in MII or SIA/SYM mode, the media info
3534 * contains the appropriate OPMODE bits.
3536 * Also, we always set the Must-Be-One bit.
3538 sc
->sc_opmode
|= OPMODE_MBO
| tm
->tm_opmode
;
3540 TULIP_WRITE(sc
, CSR_OPMODE
, sc
->sc_opmode
);
3544 * tlp_2114x_mii_preinit:
3546 * Pre-init function shared by DECchip 21140, 21140A, 21142, and 21143.
3547 * This version is used by boards which only have MII and don't have
3551 tlp_2114x_mii_preinit(struct tulip_softc
*sc
)
3555 * Always set the Must-Be-One bit, and Port Select (to select MII).
3556 * We'll never be called during a media change.
3558 sc
->sc_opmode
|= OPMODE_MBO
|OPMODE_PS
;
3559 TULIP_WRITE(sc
, CSR_OPMODE
, sc
->sc_opmode
);
3565 * Pre-init function for the Lite-On 82c168 and 82c169.
3568 tlp_pnic_preinit(struct tulip_softc
*sc
)
3571 if (sc
->sc_flags
& TULIPF_HAS_MII
) {
3573 * MII case: just set the port-select bit; we will never
3574 * be called during a media change.
3576 sc
->sc_opmode
|= OPMODE_PS
;
3579 * ENDEC/PCS/Nway mode; enable the Tx backoff counter.
3581 sc
->sc_opmode
|= OPMODE_PNIC_TBEN
;
3588 * Pre-init function for the ASIX chipsets.
3591 tlp_asix_preinit(struct tulip_softc
*sc
)
3594 switch (sc
->sc_chip
) {
3595 case TULIP_CHIP_AX88140
:
3596 case TULIP_CHIP_AX88141
:
3597 /* XXX Handle PHY. */
3598 sc
->sc_opmode
|= OPMODE_HBD
|OPMODE_PS
;
3605 TULIP_WRITE(sc
, CSR_OPMODE
, sc
->sc_opmode
);
3609 * tlp_dm9102_preinit:
3611 * Pre-init function for the Davicom DM9102.
3614 tlp_dm9102_preinit(struct tulip_softc
*sc
)
3617 switch (sc
->sc_chip
) {
3618 case TULIP_CHIP_DM9102
:
3619 sc
->sc_opmode
|= OPMODE_MBO
|OPMODE_HBD
|OPMODE_PS
;
3622 case TULIP_CHIP_DM9102A
:
3624 * XXX Figure out how to actually deal with the HomePNA
3625 * XXX portion of the DM9102A.
3627 sc
->sc_opmode
|= OPMODE_MBO
|OPMODE_HBD
;
3635 TULIP_WRITE(sc
, CSR_OPMODE
, sc
->sc_opmode
);
3641 * Issue a reset sequence on the 21140 via the GPIO facility.
3644 tlp_21140_reset(struct tulip_softc
*sc
)
3646 struct ifmedia_entry
*ife
= sc
->sc_mii
.mii_media
.ifm_cur
;
3647 struct tulip_21x4x_media
*tm
= ife
->ifm_aux
;
3650 /* First, set the direction on the GPIO pins. */
3651 TULIP_WRITE(sc
, CSR_GPP
, GPP_GPC
|sc
->sc_gp_dir
);
3653 /* Now, issue the reset sequence. */
3654 for (i
= 0; i
< tm
->tm_reset_length
; i
++) {
3656 TULIP_WRITE(sc
, CSR_GPP
, sc
->sc_srom
[tm
->tm_reset_offset
+ i
]);
3659 /* Now, issue the selection sequence. */
3660 for (i
= 0; i
< tm
->tm_gp_length
; i
++) {
3662 TULIP_WRITE(sc
, CSR_GPP
, sc
->sc_srom
[tm
->tm_gp_offset
+ i
]);
3665 /* If there were no sequences, just lower the pins. */
3666 if (tm
->tm_reset_length
== 0 && tm
->tm_gp_length
== 0) {
3668 TULIP_WRITE(sc
, CSR_GPP
, 0);
3675 * Issue a reset sequence on the 21142 via the GPIO facility.
3678 tlp_21142_reset(struct tulip_softc
*sc
)
3680 struct ifmedia_entry
*ife
= sc
->sc_mii
.mii_media
.ifm_cur
;
3681 struct tulip_21x4x_media
*tm
= ife
->ifm_aux
;
3685 cp
= &sc
->sc_srom
[tm
->tm_reset_offset
];
3686 for (i
= 0; i
< tm
->tm_reset_length
; i
++, cp
+= 2) {
3688 TULIP_WRITE(sc
, CSR_SIAGEN
, TULIP_ROM_GETW(cp
, 0) << 16);
3691 cp
= &sc
->sc_srom
[tm
->tm_gp_offset
];
3692 for (i
= 0; i
< tm
->tm_gp_length
; i
++, cp
+= 2) {
3694 TULIP_WRITE(sc
, CSR_SIAGEN
, TULIP_ROM_GETW(cp
, 0) << 16);
3697 /* If there were no sequences, just lower the pins. */
3698 if (tm
->tm_reset_length
== 0 && tm
->tm_gp_length
== 0) {
3700 TULIP_WRITE(sc
, CSR_SIAGEN
, 0);
3707 * Reset routine for Macronix chips.
3710 tlp_pmac_reset(struct tulip_softc
*sc
)
3713 switch (sc
->sc_chip
) {
3714 case TULIP_CHIP_82C115
:
3715 case TULIP_CHIP_MX98715
:
3716 case TULIP_CHIP_MX98715A
:
3717 case TULIP_CHIP_MX98725
:
3719 * Set the LED operating mode. This information is located
3720 * in the EEPROM at byte offset 0x77, per the MX98715A and
3721 * MX98725 application notes.
3723 TULIP_WRITE(sc
, CSR_MIIROM
, sc
->sc_srom
[0x77] << 24);
3725 case TULIP_CHIP_MX98715AEC_X
:
3727 * Set the LED operating mode. This information is located
3728 * in the EEPROM at byte offset 0x76, per the MX98715AEC
3731 TULIP_WRITE(sc
, CSR_MIIROM
, ((0xf & sc
->sc_srom
[0x76]) << 28)
3732 | ((0xf0 & sc
->sc_srom
[0x76]) << 20));
3745 * Reset routine for the Davicom DM9102.
3748 tlp_dm9102_reset(struct tulip_softc
*sc
)
3751 TULIP_WRITE(sc
, CSR_DM_PHYSTAT
, DM_PHYSTAT_GEPC
|DM_PHYSTAT_GPED
);
3753 TULIP_WRITE(sc
, CSR_DM_PHYSTAT
, 0);
3757 /*****************************************************************************
3758 * Chip/board-specific media switches. The ones here are ones that
3759 * are potentially common to multiple front-ends.
3760 *****************************************************************************/
3763 * This table is a common place for all sorts of media information,
3764 * keyed off of the SROM media code for that media.
3766 * Note that we explicitly configure the 21142/21143 to always advertise
3767 * NWay capabilities when using the UTP port.
3768 * XXX Actually, we don't yet.
3770 static const struct tulip_srom_to_ifmedia tulip_srom_to_ifmedia_table
[] = {
3771 { TULIP_ROM_MB_MEDIA_TP
, IFM_10_T
, 0,
3775 { SIACONN_21040_10BASET
,
3776 SIATXRX_21040_10BASET
,
3777 SIAGEN_21040_10BASET
},
3779 { SIACONN_21041_10BASET
,
3780 SIATXRX_21041_10BASET
,
3781 SIAGEN_21041_10BASET
},
3783 { SIACONN_21142_10BASET
,
3784 SIATXRX_21142_10BASET
,
3785 SIAGEN_21142_10BASET
} },
3787 { TULIP_ROM_MB_MEDIA_BNC
, IFM_10_2
, 0,
3795 { SIACONN_21041_BNC
,
3799 { SIACONN_21142_BNC
,
3801 SIAGEN_21142_BNC
} },
3803 { TULIP_ROM_MB_MEDIA_AUI
, IFM_10_5
, 0,
3807 { SIACONN_21040_AUI
,
3811 { SIACONN_21041_AUI
,
3815 { SIACONN_21142_AUI
,
3817 SIAGEN_21142_AUI
} },
3819 { TULIP_ROM_MB_MEDIA_100TX
, IFM_100_TX
, 0,
3821 OPMODE_PS
|OPMODE_PCS
|OPMODE_SCR
|OPMODE_HBD
,
3835 { TULIP_ROM_MB_MEDIA_TP_FDX
, IFM_10_T
, IFM_FDX
,
3837 OPMODE_TTM
|OPMODE_FD
|OPMODE_HBD
,
3839 { SIACONN_21040_10BASET_FDX
,
3840 SIATXRX_21040_10BASET_FDX
,
3841 SIAGEN_21040_10BASET_FDX
},
3843 { SIACONN_21041_10BASET_FDX
,
3844 SIATXRX_21041_10BASET_FDX
,
3845 SIAGEN_21041_10BASET_FDX
},
3847 { SIACONN_21142_10BASET_FDX
,
3848 SIATXRX_21142_10BASET_FDX
,
3849 SIAGEN_21142_10BASET_FDX
} },
3851 { TULIP_ROM_MB_MEDIA_100TX_FDX
, IFM_100_TX
, IFM_FDX
,
3853 OPMODE_PS
|OPMODE_PCS
|OPMODE_SCR
|OPMODE_FD
|OPMODE_HBD
,
3867 { TULIP_ROM_MB_MEDIA_100T4
, IFM_100_T4
, 0,
3869 OPMODE_PS
|OPMODE_PCS
|OPMODE_SCR
|OPMODE_HBD
,
3883 { TULIP_ROM_MB_MEDIA_100FX
, IFM_100_FX
, 0,
3885 OPMODE_PS
|OPMODE_PCS
|OPMODE_HBD
,
3899 { TULIP_ROM_MB_MEDIA_100FX_FDX
, IFM_100_FX
, IFM_FDX
,
3901 OPMODE_PS
|OPMODE_PCS
|OPMODE_FD
|OPMODE_HBD
,
3932 static const struct tulip_srom_to_ifmedia
*tlp_srom_to_ifmedia(uint8_t);
3933 static void tlp_srom_media_info(struct tulip_softc
*,
3934 const struct tulip_srom_to_ifmedia
*,
3935 struct tulip_21x4x_media
*);
3936 static void tlp_add_srom_media(struct tulip_softc
*, int,
3937 void (*)(struct tulip_softc
*, struct ifmediareq
*),
3938 int (*)(struct tulip_softc
*), const uint8_t *, int);
3939 static void tlp_print_media(struct tulip_softc
*);
3940 static void tlp_nway_activate(struct tulip_softc
*, int);
3941 static void tlp_get_minst(struct tulip_softc
*);
3943 static const struct tulip_srom_to_ifmedia
*
3944 tlp_srom_to_ifmedia(uint8_t sm
)
3946 const struct tulip_srom_to_ifmedia
*tsti
;
3948 for (tsti
= tulip_srom_to_ifmedia_table
;
3949 tsti
->tsti_name
!= NULL
; tsti
++) {
3950 if (tsti
->tsti_srom
== sm
)
3958 tlp_srom_media_info(struct tulip_softc
*sc
,
3959 const struct tulip_srom_to_ifmedia
*tsti
, struct tulip_21x4x_media
*tm
)
3962 tm
->tm_name
= tsti
->tsti_name
;
3963 tm
->tm_opmode
= tsti
->tsti_opmode
;
3965 sc
->sc_sia_cap
|= tsti
->tsti_sia_cap
;
3967 switch (sc
->sc_chip
) {
3968 case TULIP_CHIP_DE425
:
3969 case TULIP_CHIP_21040
:
3970 tm
->tm_sia
= tsti
->tsti_21040
; /* struct assignment */
3973 case TULIP_CHIP_21041
:
3974 tm
->tm_sia
= tsti
->tsti_21041
; /* struct assignment */
3977 case TULIP_CHIP_21142
:
3978 case TULIP_CHIP_21143
:
3979 case TULIP_CHIP_82C115
:
3980 case TULIP_CHIP_MX98715
:
3981 case TULIP_CHIP_MX98715A
:
3982 case TULIP_CHIP_MX98715AEC_X
:
3983 case TULIP_CHIP_MX98725
:
3984 tm
->tm_sia
= tsti
->tsti_21142
; /* struct assignment */
3994 tlp_add_srom_media(struct tulip_softc
*sc
, int type
,
3995 void (*get
)(struct tulip_softc
*, struct ifmediareq
*),
3996 int (*set
)(struct tulip_softc
*), const uint8_t *list
,
3999 struct tulip_21x4x_media
*tm
;
4000 const struct tulip_srom_to_ifmedia
*tsti
;
4003 for (i
= 0; i
< cnt
; i
++) {
4004 tsti
= tlp_srom_to_ifmedia(list
[i
]);
4005 tm
= malloc(sizeof(*tm
), M_DEVBUF
, M_WAITOK
|M_ZERO
);
4006 tlp_srom_media_info(sc
, tsti
, tm
);
4011 ifmedia_add(&sc
->sc_mii
.mii_media
,
4012 IFM_MAKEWORD(IFM_ETHER
, tsti
->tsti_subtype
,
4013 tsti
->tsti_options
, sc
->sc_tlp_minst
), 0, tm
);
4018 tlp_print_media(struct tulip_softc
*sc
)
4020 struct ifmedia_entry
*ife
;
4021 struct tulip_21x4x_media
*tm
;
4022 const char *sep
= "";
4024 #define PRINT(str) aprint_normal("%s%s", sep, str); sep = ", "
4026 aprint_normal_dev(sc
->sc_dev
, "");
4027 TAILQ_FOREACH(ife
, &sc
->sc_mii
.mii_media
.ifm_list
, ifm_list
) {
4031 if (IFM_SUBTYPE(ife
->ifm_media
) != IFM_AUTO
)
4032 panic("tlp_print_media");
4035 } else if (tm
->tm_type
!= TULIP_ROM_MB_21140_MII
&&
4036 tm
->tm_type
!= TULIP_ROM_MB_21142_MII
) {
4040 aprint_normal("\n");
4046 tlp_nway_activate(struct tulip_softc
*sc
, int media
)
4048 struct ifmedia_entry
*ife
;
4050 ife
= ifmedia_match(&sc
->sc_mii
.mii_media
, media
, 0);
4053 panic("tlp_nway_activate");
4055 sc
->sc_nway_active
= ife
;
4059 tlp_get_minst(struct tulip_softc
*sc
)
4062 if ((sc
->sc_media_seen
&
4063 ~((1 << TULIP_ROM_MB_21140_MII
) |
4064 (1 << TULIP_ROM_MB_21142_MII
))) == 0) {
4066 * We have not yet seen any SIA/SYM media (but are
4067 * about to; that's why we're called!), so assign
4068 * the current media instance to be the `internal media'
4069 * instance, and advance it so any MII media gets a
4070 * fresh one (used to selecting/isolating a PHY).
4072 sc
->sc_tlp_minst
= sc
->sc_mii
.mii_instance
++;
4077 * SIA Utility functions.
4079 static void tlp_sia_update_link(struct tulip_softc
*);
4080 static void tlp_sia_get(struct tulip_softc
*, struct ifmediareq
*);
4081 static int tlp_sia_set(struct tulip_softc
*);
4082 static int tlp_sia_media(struct tulip_softc
*, struct ifmedia_entry
*);
4083 static void tlp_sia_fixup(struct tulip_softc
*);
4086 tlp_sia_update_link(struct tulip_softc
*sc
)
4088 struct ifmedia_entry
*ife
;
4089 struct tulip_21x4x_media
*tm
;
4092 ife
= TULIP_CURRENT_MEDIA(sc
);
4095 sc
->sc_flags
&= ~(TULIPF_LINK_UP
|TULIPF_LINK_VALID
);
4097 siastat
= TULIP_READ(sc
, CSR_SIASTAT
);
4100 * Note that when we do SIA link tests, we are assuming that
4101 * the chip is really in the mode that the current media setting
4102 * reflects. If we're not, then the link tests will not be
4105 switch (IFM_SUBTYPE(ife
->ifm_media
)) {
4107 sc
->sc_flags
|= TULIPF_LINK_VALID
;
4108 if ((siastat
& SIASTAT_LS10
) == 0)
4109 sc
->sc_flags
|= TULIPF_LINK_UP
;
4114 sc
->sc_flags
|= TULIPF_LINK_VALID
;
4115 if ((siastat
& SIASTAT_LS100
) == 0)
4116 sc
->sc_flags
|= TULIPF_LINK_UP
;
4120 switch (sc
->sc_chip
) {
4121 case TULIP_CHIP_21142
:
4122 case TULIP_CHIP_21143
:
4124 * On these chips, we can tell more information about
4125 * AUI/BNC. Note that the AUI/BNC selection is made
4126 * in a different register; for our purpose, it's all
4129 switch (IFM_SUBTYPE(ife
->ifm_media
)) {
4132 sc
->sc_flags
|= TULIPF_LINK_VALID
;
4133 if (siastat
& SIASTAT_ARA
) {
4134 TULIP_WRITE(sc
, CSR_SIASTAT
, SIASTAT_ARA
);
4135 sc
->sc_flags
|= TULIPF_LINK_UP
;
4141 * If we're SYM media and can detect the link
4142 * via the GPIO facility, prefer that status
4145 if (tm
->tm_type
== TULIP_ROM_MB_21143_SYM
&&
4146 tm
->tm_actmask
!= 0) {
4147 sc
->sc_flags
= (sc
->sc_flags
&
4148 ~TULIPF_LINK_UP
) | TULIPF_LINK_VALID
;
4149 if (TULIP_ISSET(sc
, CSR_SIAGEN
,
4150 tm
->tm_actmask
) == tm
->tm_actdata
)
4151 sc
->sc_flags
|= TULIPF_LINK_UP
;
4163 tlp_sia_get(struct tulip_softc
*sc
, struct ifmediareq
*ifmr
)
4165 struct ifmedia_entry
*ife
;
4167 ifmr
->ifm_status
= 0;
4169 tlp_sia_update_link(sc
);
4171 ife
= TULIP_CURRENT_MEDIA(sc
);
4173 if (sc
->sc_flags
& TULIPF_LINK_VALID
)
4174 ifmr
->ifm_status
|= IFM_AVALID
;
4175 if (sc
->sc_flags
& TULIPF_LINK_UP
)
4176 ifmr
->ifm_status
|= IFM_ACTIVE
;
4177 ifmr
->ifm_active
= ife
->ifm_media
;
4181 tlp_sia_fixup(struct tulip_softc
*sc
)
4183 struct ifmedia_entry
*ife
;
4184 struct tulip_21x4x_media
*tm
;
4185 uint32_t siaconn
, siatxrx
, siagen
;
4187 switch (sc
->sc_chip
) {
4188 case TULIP_CHIP_82C115
:
4189 case TULIP_CHIP_MX98713A
:
4190 case TULIP_CHIP_MX98715
:
4191 case TULIP_CHIP_MX98715A
:
4192 case TULIP_CHIP_MX98715AEC_X
:
4193 case TULIP_CHIP_MX98725
:
4194 siaconn
= PMAC_SIACONN_MASK
;
4195 siatxrx
= PMAC_SIATXRX_MASK
;
4196 siagen
= PMAC_SIAGEN_MASK
;
4200 /* No fixups required on any other chips. */
4204 TAILQ_FOREACH(ife
, &sc
->sc_mii
.mii_media
.ifm_list
, ifm_list
) {
4209 tm
->tm_siaconn
&= siaconn
;
4210 tm
->tm_siatxrx
&= siatxrx
;
4211 tm
->tm_siagen
&= siagen
;
4216 tlp_sia_set(struct tulip_softc
*sc
)
4219 return (tlp_sia_media(sc
, TULIP_CURRENT_MEDIA(sc
)));
4223 tlp_sia_media(struct tulip_softc
*sc
, struct ifmedia_entry
*ife
)
4225 struct tulip_21x4x_media
*tm
;
4230 * XXX This appears to be necessary on a bunch of the clone chips.
4237 tlp_idle(sc
, OPMODE_ST
|OPMODE_SR
);
4240 * Program the SIA. It's important to write in this order,
4241 * resetting the SIA first.
4243 TULIP_WRITE(sc
, CSR_SIACONN
, 0); /* SRL bit clear */
4246 TULIP_WRITE(sc
, CSR_SIATXRX
, tm
->tm_siatxrx
);
4248 switch (sc
->sc_chip
) {
4249 case TULIP_CHIP_21142
:
4250 case TULIP_CHIP_21143
:
4251 TULIP_WRITE(sc
, CSR_SIAGEN
, tm
->tm_siagen
| tm
->tm_gpctl
);
4252 TULIP_WRITE(sc
, CSR_SIAGEN
, tm
->tm_siagen
| tm
->tm_gpdata
);
4255 TULIP_WRITE(sc
, CSR_SIAGEN
, tm
->tm_siagen
);
4258 TULIP_WRITE(sc
, CSR_SIACONN
, tm
->tm_siaconn
);
4261 * Set the OPMODE bits for this media and write OPMODE.
4262 * This will resume the transmit and receive processes.
4264 sc
->sc_opmode
= (sc
->sc_opmode
& ~OPMODE_MEDIA_BITS
) | tm
->tm_opmode
;
4265 TULIP_WRITE(sc
, CSR_OPMODE
, sc
->sc_opmode
);
4271 * 21140 GPIO utility functions.
4273 static void tlp_21140_gpio_update_link(struct tulip_softc
*);
4276 tlp_21140_gpio_update_link(struct tulip_softc
*sc
)
4278 struct ifmedia_entry
*ife
;
4279 struct tulip_21x4x_media
*tm
;
4281 ife
= TULIP_CURRENT_MEDIA(sc
);
4284 sc
->sc_flags
&= ~(TULIPF_LINK_UP
|TULIPF_LINK_VALID
);
4286 if (tm
->tm_actmask
!= 0) {
4287 sc
->sc_flags
|= TULIPF_LINK_VALID
;
4288 if (TULIP_ISSET(sc
, CSR_GPP
, tm
->tm_actmask
) ==
4290 sc
->sc_flags
|= TULIPF_LINK_UP
;
4295 tlp_21140_gpio_get(struct tulip_softc
*sc
, struct ifmediareq
*ifmr
)
4297 struct ifmedia_entry
*ife
;
4299 ifmr
->ifm_status
= 0;
4301 tlp_21140_gpio_update_link(sc
);
4303 ife
= TULIP_CURRENT_MEDIA(sc
);
4305 if (sc
->sc_flags
& TULIPF_LINK_VALID
)
4306 ifmr
->ifm_status
|= IFM_AVALID
;
4307 if (sc
->sc_flags
& TULIPF_LINK_UP
)
4308 ifmr
->ifm_status
|= IFM_ACTIVE
;
4309 ifmr
->ifm_active
= ife
->ifm_media
;
4313 tlp_21140_gpio_set(struct tulip_softc
*sc
)
4315 struct ifmedia_entry
*ife
;
4316 struct tulip_21x4x_media
*tm
;
4318 ife
= TULIP_CURRENT_MEDIA(sc
);
4324 tlp_idle(sc
, OPMODE_ST
|OPMODE_SR
);
4327 * Set the GPIO pins for this media, to flip any
4330 TULIP_WRITE(sc
, CSR_GPP
, GPP_GPC
|sc
->sc_gp_dir
);
4332 TULIP_WRITE(sc
, CSR_GPP
, tm
->tm_gpdata
);
4335 * Set the OPMODE bits for this media and write OPMODE.
4336 * This will resume the transmit and receive processes.
4338 sc
->sc_opmode
= (sc
->sc_opmode
& ~OPMODE_MEDIA_BITS
) | tm
->tm_opmode
;
4339 TULIP_WRITE(sc
, CSR_OPMODE
, sc
->sc_opmode
);
4345 * 21040 and 21041 media switches.
4347 static void tlp_21040_tmsw_init(struct tulip_softc
*);
4348 static void tlp_21040_tp_tmsw_init(struct tulip_softc
*);
4349 static void tlp_21040_auibnc_tmsw_init(struct tulip_softc
*);
4350 static void tlp_21041_tmsw_init(struct tulip_softc
*);
4352 const struct tulip_mediasw tlp_21040_mediasw
= {
4353 tlp_21040_tmsw_init
, tlp_sia_get
, tlp_sia_set
4356 const struct tulip_mediasw tlp_21040_tp_mediasw
= {
4357 tlp_21040_tp_tmsw_init
, tlp_sia_get
, tlp_sia_set
4360 const struct tulip_mediasw tlp_21040_auibnc_mediasw
= {
4361 tlp_21040_auibnc_tmsw_init
, tlp_sia_get
, tlp_sia_set
4364 const struct tulip_mediasw tlp_21041_mediasw
= {
4365 tlp_21041_tmsw_init
, tlp_sia_get
, tlp_sia_set
4369 tlp_21040_tmsw_init(struct tulip_softc
*sc
)
4371 static const uint8_t media
[] = {
4372 TULIP_ROM_MB_MEDIA_TP
,
4373 TULIP_ROM_MB_MEDIA_TP_FDX
,
4374 TULIP_ROM_MB_MEDIA_AUI
,
4376 struct tulip_21x4x_media
*tm
;
4378 ifmedia_init(&sc
->sc_mii
.mii_media
, 0, tlp_mediachange
,
4381 tlp_add_srom_media(sc
, 0, NULL
, NULL
, media
, 3);
4384 * No SROM type for External SIA.
4386 tm
= malloc(sizeof(*tm
), M_DEVBUF
, M_WAITOK
|M_ZERO
);
4387 tm
->tm_name
= "manual";
4389 tm
->tm_siaconn
= SIACONN_21040_EXTSIA
;
4390 tm
->tm_siatxrx
= SIATXRX_21040_EXTSIA
;
4391 tm
->tm_siagen
= SIAGEN_21040_EXTSIA
;
4392 ifmedia_add(&sc
->sc_mii
.mii_media
,
4393 IFM_MAKEWORD(IFM_ETHER
, IFM_MANUAL
, 0, sc
->sc_tlp_minst
), 0, tm
);
4396 * XXX Autosense not yet supported.
4399 /* XXX This should be auto-sense. */
4400 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_10_T
);
4402 tlp_print_media(sc
);
4406 tlp_21040_tp_tmsw_init(struct tulip_softc
*sc
)
4408 static const uint8_t media
[] = {
4409 TULIP_ROM_MB_MEDIA_TP
,
4410 TULIP_ROM_MB_MEDIA_TP_FDX
,
4413 ifmedia_init(&sc
->sc_mii
.mii_media
, 0, tlp_mediachange
,
4416 tlp_add_srom_media(sc
, 0, NULL
, NULL
, media
, 2);
4418 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_10_T
);
4420 tlp_print_media(sc
);
4424 tlp_21040_auibnc_tmsw_init(struct tulip_softc
*sc
)
4426 static const uint8_t media
[] = {
4427 TULIP_ROM_MB_MEDIA_AUI
,
4430 ifmedia_init(&sc
->sc_mii
.mii_media
, 0, tlp_mediachange
,
4433 tlp_add_srom_media(sc
, 0, NULL
, NULL
, media
, 1);
4435 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_10_5
);
4437 tlp_print_media(sc
);
4441 tlp_21041_tmsw_init(struct tulip_softc
*sc
)
4443 static const uint8_t media
[] = {
4444 TULIP_ROM_MB_MEDIA_TP
,
4445 TULIP_ROM_MB_MEDIA_TP_FDX
,
4446 TULIP_ROM_MB_MEDIA_BNC
,
4447 TULIP_ROM_MB_MEDIA_AUI
,
4449 int i
, defmedia
, devcnt
, leaf_offset
, mb_offset
, m_cnt
;
4450 const struct tulip_srom_to_ifmedia
*tsti
;
4451 struct tulip_21x4x_media
*tm
;
4455 ifmedia_init(&sc
->sc_mii
.mii_media
, 0, tlp_mediachange
,
4458 if (tlp_isv_srom(sc
->sc_srom
) == 0) {
4461 * If we have a board without the standard 21041 SROM format,
4462 * we just assume all media are present and try and pick a
4463 * reasonable default.
4465 tlp_add_srom_media(sc
, 0, NULL
, NULL
, media
, 4);
4468 * XXX Autosense not yet supported.
4471 /* XXX This should be auto-sense. */
4472 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_10_T
);
4474 tlp_print_media(sc
);
4478 devcnt
= sc
->sc_srom
[TULIP_ROM_CHIP_COUNT
];
4479 for (i
= 0; i
< devcnt
; i
++) {
4480 if (sc
->sc_srom
[TULIP_ROM_CHIP_COUNT
] == 1)
4482 if (sc
->sc_srom
[TULIP_ROM_CHIPn_DEVICE_NUMBER(i
)] ==
4490 leaf_offset
= TULIP_ROM_GETW(sc
->sc_srom
,
4491 TULIP_ROM_CHIPn_INFO_LEAF_OFFSET(i
));
4492 mb_offset
= leaf_offset
+ TULIP_ROM_IL_MEDIAn_BLOCK_BASE
;
4493 m_cnt
= sc
->sc_srom
[leaf_offset
+ TULIP_ROM_IL_MEDIA_COUNT
];
4496 m_cnt
--, mb_offset
+= TULIP_ROM_MB_SIZE(mb
)) {
4497 mb
= sc
->sc_srom
[mb_offset
];
4498 tm
= malloc(sizeof(*tm
), M_DEVBUF
, M_WAITOK
|M_ZERO
);
4499 switch (mb
& TULIP_ROM_MB_MEDIA_CODE
) {
4500 case TULIP_ROM_MB_MEDIA_TP_FDX
:
4501 case TULIP_ROM_MB_MEDIA_TP
:
4502 case TULIP_ROM_MB_MEDIA_BNC
:
4503 case TULIP_ROM_MB_MEDIA_AUI
:
4504 tsti
= tlp_srom_to_ifmedia(mb
&
4505 TULIP_ROM_MB_MEDIA_CODE
);
4507 tlp_srom_media_info(sc
, tsti
, tm
);
4510 * Override our default SIA settings if the
4511 * SROM contains its own.
4513 if (mb
& TULIP_ROM_MB_EXT
) {
4514 tm
->tm_siaconn
= TULIP_ROM_GETW(sc
->sc_srom
,
4515 mb_offset
+ TULIP_ROM_MB_CSR13
);
4516 tm
->tm_siatxrx
= TULIP_ROM_GETW(sc
->sc_srom
,
4517 mb_offset
+ TULIP_ROM_MB_CSR14
);
4518 tm
->tm_siagen
= TULIP_ROM_GETW(sc
->sc_srom
,
4519 mb_offset
+ TULIP_ROM_MB_CSR15
);
4522 ifmedia_add(&sc
->sc_mii
.mii_media
,
4523 IFM_MAKEWORD(IFM_ETHER
, tsti
->tsti_subtype
,
4524 tsti
->tsti_options
, sc
->sc_tlp_minst
), 0, tm
);
4528 aprint_error_dev(sc
->sc_dev
,
4529 "unknown media code 0x%02x\n",
4530 mb
& TULIP_ROM_MB_MEDIA_CODE
);
4536 * XXX Autosense not yet supported.
4539 romdef
= TULIP_ROM_GETW(sc
->sc_srom
, leaf_offset
+
4540 TULIP_ROM_IL_SELECT_CONN_TYPE
);
4542 case SELECT_CONN_TYPE_TP
:
4543 case SELECT_CONN_TYPE_TP_AUTONEG
:
4544 case SELECT_CONN_TYPE_TP_NOLINKPASS
:
4545 defmedia
= IFM_ETHER
|IFM_10_T
;
4548 case SELECT_CONN_TYPE_TP_FDX
:
4549 defmedia
= IFM_ETHER
|IFM_10_T
|IFM_FDX
;
4552 case SELECT_CONN_TYPE_BNC
:
4553 defmedia
= IFM_ETHER
|IFM_10_2
;
4556 case SELECT_CONN_TYPE_AUI
:
4557 defmedia
= IFM_ETHER
|IFM_10_5
;
4560 case SELECT_CONN_TYPE_ASENSE
:
4561 case SELECT_CONN_TYPE_ASENSE_AUTONEG
:
4562 defmedia
= IFM_ETHER
|IFM_AUTO
;
4569 if (defmedia
== 0) {
4571 * XXX We should default to auto-sense.
4573 defmedia
= IFM_ETHER
|IFM_10_T
;
4576 ifmedia_set(&sc
->sc_mii
.mii_media
, defmedia
);
4578 tlp_print_media(sc
);
4582 * DECchip 2114x ISV media switch.
4584 static void tlp_2114x_isv_tmsw_init(struct tulip_softc
*);
4585 static void tlp_2114x_isv_tmsw_get(struct tulip_softc
*,
4586 struct ifmediareq
*);
4587 static int tlp_2114x_isv_tmsw_set(struct tulip_softc
*);
4589 const struct tulip_mediasw tlp_2114x_isv_mediasw
= {
4590 tlp_2114x_isv_tmsw_init
, tlp_2114x_isv_tmsw_get
, tlp_2114x_isv_tmsw_set
4593 static void tlp_2114x_nway_get(struct tulip_softc
*, struct ifmediareq
*);
4594 static int tlp_2114x_nway_set(struct tulip_softc
*);
4596 static void tlp_2114x_nway_statchg(device_t
);
4597 static int tlp_2114x_nway_service(struct tulip_softc
*, int);
4598 static void tlp_2114x_nway_auto(struct tulip_softc
*);
4599 static void tlp_2114x_nway_status(struct tulip_softc
*);
4602 tlp_2114x_isv_tmsw_init(struct tulip_softc
*sc
)
4604 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
4605 struct ifmedia_entry
*ife
;
4606 struct mii_softc
*phy
;
4607 struct tulip_21x4x_media
*tm
;
4608 const struct tulip_srom_to_ifmedia
*tsti
;
4609 int i
, devcnt
, leaf_offset
, m_cnt
, type
, length
;
4610 int defmedia
, miidef
;
4614 defmedia
= miidef
= 0;
4616 sc
->sc_mii
.mii_ifp
= ifp
;
4617 sc
->sc_mii
.mii_readreg
= tlp_bitbang_mii_readreg
;
4618 sc
->sc_mii
.mii_writereg
= tlp_bitbang_mii_writereg
;
4619 sc
->sc_mii
.mii_statchg
= sc
->sc_statchg
;
4622 * Ignore `instance'; we may get a mixture of SIA and MII
4623 * media, and `instance' is used to isolate or select the
4624 * PHY on the MII as appropriate. Note that duplicate media
4625 * are disallowed, so ignoring `instance' is safe.
4627 ifmedia_init(&sc
->sc_mii
.mii_media
, IFM_IMASK
, tlp_mediachange
,
4630 devcnt
= sc
->sc_srom
[TULIP_ROM_CHIP_COUNT
];
4631 for (i
= 0; i
< devcnt
; i
++) {
4632 if (sc
->sc_srom
[TULIP_ROM_CHIP_COUNT
] == 1)
4634 if (sc
->sc_srom
[TULIP_ROM_CHIPn_DEVICE_NUMBER(i
)] ==
4640 aprint_error_dev(sc
->sc_dev
, "unable to locate info leaf in SROM\n");
4644 leaf_offset
= TULIP_ROM_GETW(sc
->sc_srom
,
4645 TULIP_ROM_CHIPn_INFO_LEAF_OFFSET(i
));
4647 /* XXX SELECT CONN TYPE */
4649 cp
= &sc
->sc_srom
[leaf_offset
+ TULIP_ROM_IL_MEDIA_COUNT
];
4652 * On some chips, the first thing in the Info Leaf is the
4653 * GPIO pin direction data.
4655 switch (sc
->sc_chip
) {
4656 case TULIP_CHIP_21140
:
4657 case TULIP_CHIP_21140A
:
4658 case TULIP_CHIP_MX98713
:
4659 case TULIP_CHIP_AX88140
:
4660 case TULIP_CHIP_AX88141
:
4661 sc
->sc_gp_dir
= *cp
++;
4669 /* Get the media count. */
4673 sc
->sc_mediasw
= &tlp_sio_mii_mediasw
;
4674 (*sc
->sc_mediasw
->tmsw_init
)(sc
);
4678 for (; m_cnt
!= 0; cp
= ncp
, m_cnt
--) {
4680 * Determine the type and length of this media block.
4681 * The 21143 is spec'd to always use extended format blocks,
4682 * but some cards don't set the bit to indicate this.
4683 * Hopefully there are no cards which really don't use
4684 * extended format blocks.
4686 if ((*cp
& 0x80) == 0 && sc
->sc_chip
!= TULIP_CHIP_21143
) {
4688 type
= TULIP_ROM_MB_21140_GPR
;
4690 length
= (*cp
++ & 0x7f) - 1;
4691 type
= *cp
++ & 0x3f;
4694 /* Compute the start of the next block. */
4697 /* Now, parse the block. */
4699 case TULIP_ROM_MB_21140_GPR
:
4701 sc
->sc_media_seen
|= 1 << TULIP_ROM_MB_21140_GPR
;
4703 tm
= malloc(sizeof(*tm
), M_DEVBUF
, M_WAITOK
|M_ZERO
);
4705 tm
->tm_type
= TULIP_ROM_MB_21140_GPR
;
4706 tm
->tm_get
= tlp_21140_gpio_get
;
4707 tm
->tm_set
= tlp_21140_gpio_set
;
4709 /* First is the media type code. */
4710 tsti
= tlp_srom_to_ifmedia(cp
[0] &
4711 TULIP_ROM_MB_MEDIA_CODE
);
4713 /* Invalid media code. */
4719 tlp_srom_media_info(sc
, tsti
, tm
);
4721 /* Next is any GPIO info for this media. */
4722 tm
->tm_gpdata
= cp
[1];
4725 * Next is a word containing OPMODE information
4726 * and info on how to detect if this media is
4729 word
= TULIP_ROM_GETW(cp
, 2);
4730 tm
->tm_opmode
&= OPMODE_FD
;
4731 tm
->tm_opmode
|= TULIP_ROM_MB_OPMODE(word
);
4732 if ((word
& TULIP_ROM_MB_NOINDICATOR
) == 0) {
4734 TULIP_ROM_MB_BITPOS(word
);
4736 (word
& TULIP_ROM_MB_POLARITY
) ?
4740 ifmedia_add(&sc
->sc_mii
.mii_media
,
4741 IFM_MAKEWORD(IFM_ETHER
, tsti
->tsti_subtype
,
4742 tsti
->tsti_options
, sc
->sc_tlp_minst
), 0, tm
);
4745 case TULIP_ROM_MB_21140_MII
:
4746 sc
->sc_media_seen
|= 1 << TULIP_ROM_MB_21140_MII
;
4748 tm
= malloc(sizeof(*tm
), M_DEVBUF
, M_WAITOK
|M_ZERO
);
4750 tm
->tm_type
= TULIP_ROM_MB_21140_MII
;
4751 tm
->tm_get
= tlp_mii_getmedia
;
4752 tm
->tm_set
= tlp_mii_setmedia
;
4753 tm
->tm_opmode
= OPMODE_PS
;
4755 if (sc
->sc_reset
== NULL
)
4756 sc
->sc_reset
= tlp_21140_reset
;
4758 /* First is the PHY number. */
4759 tm
->tm_phyno
= *cp
++;
4761 /* Next is the MII select sequence length and offset. */
4762 tm
->tm_gp_length
= *cp
++;
4763 tm
->tm_gp_offset
= cp
- &sc
->sc_srom
[0];
4764 cp
+= tm
->tm_gp_length
;
4766 /* Next is the MII reset sequence length and offset. */
4767 tm
->tm_reset_length
= *cp
++;
4768 tm
->tm_reset_offset
= cp
- &sc
->sc_srom
[0];
4769 cp
+= tm
->tm_reset_length
;
4772 * The following items are left in the media block
4773 * that we don't particularly care about:
4780 * These appear to be bits in the PHY registers,
4781 * which our MII code handles on its own.
4785 * Before we probe the MII bus, we need to reset
4786 * it and issue the selection sequence.
4789 /* Set the direction of the pins... */
4790 TULIP_WRITE(sc
, CSR_GPP
, GPP_GPC
|sc
->sc_gp_dir
);
4792 for (i
= 0; i
< tm
->tm_reset_length
; i
++) {
4794 TULIP_WRITE(sc
, CSR_GPP
,
4795 sc
->sc_srom
[tm
->tm_reset_offset
+ i
]);
4798 for (i
= 0; i
< tm
->tm_gp_length
; i
++) {
4800 TULIP_WRITE(sc
, CSR_GPP
,
4801 sc
->sc_srom
[tm
->tm_gp_offset
+ i
]);
4804 /* If there were no sequences, just lower the pins. */
4805 if (tm
->tm_reset_length
== 0 && tm
->tm_gp_length
== 0) {
4807 TULIP_WRITE(sc
, CSR_GPP
, 0);
4811 * Now, probe the MII for the PHY. Note, we know
4812 * the location of the PHY on the bus, but we don't
4813 * particularly care; the MII code just likes to
4814 * search the whole thing anyhow.
4816 mii_attach(sc
->sc_dev
, &sc
->sc_mii
, 0xffffffff,
4817 MII_PHY_ANY
, tm
->tm_phyno
, 0);
4820 * Now, search for the PHY we hopefully just
4821 * configured. If it's not configured into the
4822 * kernel, we lose. The PHY's default media always
4825 LIST_FOREACH(phy
, &sc
->sc_mii
.mii_phys
, mii_list
) {
4826 if (phy
->mii_offset
== tm
->tm_phyno
)
4830 aprint_error_dev(sc
->sc_dev
, "unable to configure MII\n");
4834 sc
->sc_flags
|= TULIPF_HAS_MII
;
4835 sc
->sc_tick
= tlp_mii_tick
;
4836 miidef
= IFM_MAKEWORD(IFM_ETHER
, IFM_AUTO
, 0,
4840 * Okay, now that we've found the PHY and the MII
4841 * layer has added all of the media associated
4842 * with that PHY, we need to traverse the media
4843 * list, and add our `tm' to each entry's `aux'
4846 * We do this by looking for media with our
4849 TAILQ_FOREACH(ife
, &sc
->sc_mii
.mii_media
.ifm_list
,
4851 if (IFM_INST(ife
->ifm_media
) != phy
->mii_inst
)
4857 case TULIP_ROM_MB_21142_SIA
:
4859 sc
->sc_media_seen
|= 1 << TULIP_ROM_MB_21142_SIA
;
4861 tm
= malloc(sizeof(*tm
), M_DEVBUF
, M_WAITOK
|M_ZERO
);
4863 tm
->tm_type
= TULIP_ROM_MB_21142_SIA
;
4864 tm
->tm_get
= tlp_sia_get
;
4865 tm
->tm_set
= tlp_sia_set
;
4867 /* First is the media type code. */
4868 tsti
= tlp_srom_to_ifmedia(cp
[0] &
4869 TULIP_ROM_MB_MEDIA_CODE
);
4871 /* Invalid media code. */
4877 tlp_srom_media_info(sc
, tsti
, tm
);
4880 * Override our default SIA settings if the
4881 * SROM contains its own.
4884 tm
->tm_siaconn
= TULIP_ROM_GETW(cp
, 1);
4885 tm
->tm_siatxrx
= TULIP_ROM_GETW(cp
, 3);
4886 tm
->tm_siagen
= TULIP_ROM_GETW(cp
, 5);
4891 /* Next is GPIO control/data. */
4892 tm
->tm_gpctl
= TULIP_ROM_GETW(cp
, 0) << 16;
4893 tm
->tm_gpdata
= TULIP_ROM_GETW(cp
, 2) << 16;
4895 ifmedia_add(&sc
->sc_mii
.mii_media
,
4896 IFM_MAKEWORD(IFM_ETHER
, tsti
->tsti_subtype
,
4897 tsti
->tsti_options
, sc
->sc_tlp_minst
), 0, tm
);
4900 case TULIP_ROM_MB_21142_MII
:
4901 sc
->sc_media_seen
|= 1 << TULIP_ROM_MB_21142_MII
;
4903 tm
= malloc(sizeof(*tm
), M_DEVBUF
, M_WAITOK
|M_ZERO
);
4905 tm
->tm_type
= TULIP_ROM_MB_21142_MII
;
4906 tm
->tm_get
= tlp_mii_getmedia
;
4907 tm
->tm_set
= tlp_mii_setmedia
;
4908 tm
->tm_opmode
= OPMODE_PS
;
4910 if (sc
->sc_reset
== NULL
)
4911 sc
->sc_reset
= tlp_21142_reset
;
4913 /* First is the PHY number. */
4914 tm
->tm_phyno
= *cp
++;
4916 /* Next is the MII select sequence length and offset. */
4917 tm
->tm_gp_length
= *cp
++;
4918 tm
->tm_gp_offset
= cp
- &sc
->sc_srom
[0];
4919 cp
+= tm
->tm_gp_length
* 2;
4921 /* Next is the MII reset sequence length and offset. */
4922 tm
->tm_reset_length
= *cp
++;
4923 tm
->tm_reset_offset
= cp
- &sc
->sc_srom
[0];
4924 cp
+= tm
->tm_reset_length
* 2;
4927 * The following items are left in the media block
4928 * that we don't particularly care about:
4936 * These appear to be bits in the PHY registers,
4937 * which our MII code handles on its own.
4941 * Before we probe the MII bus, we need to reset
4942 * it and issue the selection sequence.
4945 cp
= &sc
->sc_srom
[tm
->tm_reset_offset
];
4946 for (i
= 0; i
< tm
->tm_reset_length
; i
++, cp
+= 2) {
4948 TULIP_WRITE(sc
, CSR_SIAGEN
,
4949 TULIP_ROM_GETW(cp
, 0) << 16);
4952 cp
= &sc
->sc_srom
[tm
->tm_gp_offset
];
4953 for (i
= 0; i
< tm
->tm_gp_length
; i
++, cp
+= 2) {
4955 TULIP_WRITE(sc
, CSR_SIAGEN
,
4956 TULIP_ROM_GETW(cp
, 0) << 16);
4959 /* If there were no sequences, just lower the pins. */
4960 if (tm
->tm_reset_length
== 0 && tm
->tm_gp_length
== 0) {
4962 TULIP_WRITE(sc
, CSR_SIAGEN
, 0);
4966 * Now, probe the MII for the PHY. Note, we know
4967 * the location of the PHY on the bus, but we don't
4968 * particularly care; the MII code just likes to
4969 * search the whole thing anyhow.
4971 mii_attach(sc
->sc_dev
, &sc
->sc_mii
, 0xffffffff,
4972 MII_PHY_ANY
, tm
->tm_phyno
, 0);
4975 * Now, search for the PHY we hopefully just
4976 * configured. If it's not configured into the
4977 * kernel, we lose. The PHY's default media always
4980 LIST_FOREACH(phy
, &sc
->sc_mii
.mii_phys
, mii_list
) {
4981 if (phy
->mii_offset
== tm
->tm_phyno
)
4985 aprint_error_dev(sc
->sc_dev
, "unable to configure MII\n");
4989 sc
->sc_flags
|= TULIPF_HAS_MII
;
4990 sc
->sc_tick
= tlp_mii_tick
;
4991 miidef
= IFM_MAKEWORD(IFM_ETHER
, IFM_AUTO
, 0,
4995 * Okay, now that we've found the PHY and the MII
4996 * layer has added all of the media associated
4997 * with that PHY, we need to traverse the media
4998 * list, and add our `tm' to each entry's `aux'
5001 * We do this by looking for media with our
5004 TAILQ_FOREACH(ife
, &sc
->sc_mii
.mii_media
.ifm_list
,
5006 if (IFM_INST(ife
->ifm_media
) != phy
->mii_inst
)
5012 case TULIP_ROM_MB_21143_SYM
:
5014 sc
->sc_media_seen
|= 1 << TULIP_ROM_MB_21143_SYM
;
5016 tm
= malloc(sizeof(*tm
), M_DEVBUF
, M_WAITOK
|M_ZERO
);
5018 tm
->tm_type
= TULIP_ROM_MB_21143_SYM
;
5019 tm
->tm_get
= tlp_sia_get
;
5020 tm
->tm_set
= tlp_sia_set
;
5022 /* First is the media type code. */
5023 tsti
= tlp_srom_to_ifmedia(cp
[0] &
5024 TULIP_ROM_MB_MEDIA_CODE
);
5026 /* Invalid media code. */
5032 tlp_srom_media_info(sc
, tsti
, tm
);
5034 /* Next is GPIO control/data. */
5035 tm
->tm_gpctl
= TULIP_ROM_GETW(cp
, 1) << 16;
5036 tm
->tm_gpdata
= TULIP_ROM_GETW(cp
, 3) << 16;
5039 * Next is a word containing OPMODE information
5040 * and info on how to detect if this media is
5043 word
= TULIP_ROM_GETW(cp
, 5);
5044 tm
->tm_opmode
&= OPMODE_FD
;
5045 tm
->tm_opmode
|= TULIP_ROM_MB_OPMODE(word
);
5046 if ((word
& TULIP_ROM_MB_NOINDICATOR
) == 0) {
5048 TULIP_ROM_MB_BITPOS(word
);
5050 (word
& TULIP_ROM_MB_POLARITY
) ?
5054 ifmedia_add(&sc
->sc_mii
.mii_media
,
5055 IFM_MAKEWORD(IFM_ETHER
, tsti
->tsti_subtype
,
5056 tsti
->tsti_options
, sc
->sc_tlp_minst
), 0, tm
);
5059 case TULIP_ROM_MB_21143_RESET
:
5060 aprint_normal_dev(sc
->sc_dev
, "21143 reset block\n");
5064 aprint_error_dev(sc
->sc_dev
,
5065 "unknown ISV media block type 0x%02x\n", type
);
5070 * Deal with the case where no media is configured.
5072 if (TAILQ_FIRST(&sc
->sc_mii
.mii_media
.ifm_list
) == NULL
) {
5073 aprint_error_dev(sc
->sc_dev
, "no media found!\n");
5074 ifmedia_add(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_NONE
, 0, NULL
);
5075 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_NONE
);
5080 * Pick the default media.
5085 switch (sc
->sc_chip
) {
5086 case TULIP_CHIP_21140
:
5087 case TULIP_CHIP_21140A
:
5088 /* XXX should come from SROM */
5089 defmedia
= IFM_MAKEWORD(IFM_ETHER
, IFM_10_T
, 0, 0);
5090 if (ifmedia_match(&sc
->sc_mii
.mii_media
, defmedia
,
5091 sc
->sc_mii
.mii_media
.ifm_mask
) == NULL
) {
5093 * There is not a 10baseT media.
5094 * Fall back to the first found one.
5096 ife
= TAILQ_FIRST(&sc
->sc_mii
.mii_media
.ifm_list
);
5097 defmedia
= ife
->ifm_media
;
5101 case TULIP_CHIP_21142
:
5102 case TULIP_CHIP_21143
:
5103 case TULIP_CHIP_MX98713A
:
5104 case TULIP_CHIP_MX98715
:
5105 case TULIP_CHIP_MX98715A
:
5106 case TULIP_CHIP_MX98715AEC_X
:
5107 case TULIP_CHIP_MX98725
:
5108 tm
= malloc(sizeof(*tm
), M_DEVBUF
, M_WAITOK
|M_ZERO
);
5109 tm
->tm_name
= "auto";
5110 tm
->tm_get
= tlp_2114x_nway_get
;
5111 tm
->tm_set
= tlp_2114x_nway_set
;
5113 defmedia
= IFM_MAKEWORD(IFM_ETHER
, IFM_AUTO
, 0, 0);
5114 ifmedia_add(&sc
->sc_mii
.mii_media
, defmedia
, 0, tm
);
5116 sc
->sc_statchg
= tlp_2114x_nway_statchg
;
5117 sc
->sc_tick
= tlp_2114x_nway_tick
;
5121 defmedia
= IFM_MAKEWORD(IFM_ETHER
, IFM_10_T
, 0, 0);
5126 ifmedia_set(&sc
->sc_mii
.mii_media
, defmedia
);
5129 * Display any non-MII media we've located.
5131 if (sc
->sc_media_seen
&
5132 ~((1 << TULIP_ROM_MB_21140_MII
) | (1 << TULIP_ROM_MB_21142_MII
)))
5133 tlp_print_media(sc
);
5139 tlp_2114x_nway_get(struct tulip_softc
*sc
, struct ifmediareq
*ifmr
)
5142 (void) tlp_2114x_nway_service(sc
, MII_POLLSTAT
);
5143 ifmr
->ifm_status
= sc
->sc_mii
.mii_media_status
;
5144 ifmr
->ifm_active
= sc
->sc_mii
.mii_media_active
;
5148 tlp_2114x_nway_set(struct tulip_softc
*sc
)
5151 return (tlp_2114x_nway_service(sc
, MII_MEDIACHG
));
5155 tlp_2114x_nway_statchg(device_t self
)
5157 struct tulip_softc
*sc
= device_private(self
);
5158 struct mii_data
*mii
= &sc
->sc_mii
;
5159 struct ifmedia_entry
*ife
;
5161 if (IFM_SUBTYPE(mii
->mii_media_active
) == IFM_NONE
)
5164 if ((ife
= ifmedia_match(&mii
->mii_media
, mii
->mii_media_active
,
5165 mii
->mii_media
.ifm_mask
)) == NULL
) {
5166 printf("tlp_2114x_nway_statchg: no match for media 0x%x/0x%x\n",
5167 mii
->mii_media_active
, ~mii
->mii_media
.ifm_mask
);
5168 panic("tlp_2114x_nway_statchg");
5171 tlp_sia_media(sc
, ife
);
5175 tlp_2114x_nway_tick(void *arg
)
5177 struct tulip_softc
*sc
= arg
;
5178 struct mii_data
*mii
= &sc
->sc_mii
;
5181 if (!device_is_active(sc
->sc_dev
))
5185 tlp_2114x_nway_service(sc
, MII_TICK
);
5186 if ((sc
->sc_flags
& TULIPF_LINK_UP
) == 0 &&
5187 (mii
->mii_media_status
& IFM_ACTIVE
) != 0 &&
5188 IFM_SUBTYPE(mii
->mii_media_active
) != IFM_NONE
) {
5189 sc
->sc_flags
|= TULIPF_LINK_UP
;
5190 tlp_start(&sc
->sc_ethercom
.ec_if
);
5191 } else if ((sc
->sc_flags
& TULIPF_LINK_UP
) != 0 &&
5192 (mii
->mii_media_status
& IFM_ACTIVE
) == 0) {
5193 sc
->sc_flags
&= ~TULIPF_LINK_UP
;
5197 if ((sc
->sc_flags
& TULIPF_LINK_UP
) == 0)
5201 callout_reset(&sc
->sc_tick_callout
, ticks
, tlp_2114x_nway_tick
, sc
);
5205 * Support for the 2114X internal NWay block. This is constructed
5206 * somewhat like a PHY driver for simplicity.
5210 tlp_2114x_nway_service(struct tulip_softc
*sc
, int cmd
)
5212 struct mii_data
*mii
= &sc
->sc_mii
;
5213 struct ifmedia_entry
*ife
= mii
->mii_media
.ifm_cur
;
5215 if ((mii
->mii_ifp
->if_flags
& IFF_UP
) == 0)
5220 /* Nothing special to do here. */
5224 switch (IFM_SUBTYPE(ife
->ifm_media
)) {
5228 /* Manual setting doesn't go through here. */
5229 printf("tlp_2114x_nway_service: oops!\n");
5236 * Only used for autonegotiation.
5238 if (IFM_SUBTYPE(ife
->ifm_media
) != IFM_AUTO
)
5242 * Check to see if we have link. If we do, we don't
5243 * need to restart the autonegotiation process.
5246 if (mii
->mii_media_status
& IFM_ACTIVE
)
5248 if (sc
->sc_flags
& TULIPF_LINK_UP
)
5253 * Only retry autonegotiation every 5 seconds.
5255 if (++sc
->sc_nway_ticks
!= (5 << 3))
5259 sc
->sc_nway_ticks
= 0;
5260 ife
->ifm_data
= IFM_NONE
;
5261 tlp_2114x_nway_auto(sc
);
5265 /* Update the media status. */
5266 tlp_2114x_nway_status(sc
);
5269 * Callback if something changed. Manually configuration goes through
5270 * tlp_sia_set() anyway, so ignore that here.
5272 if (IFM_SUBTYPE(ife
->ifm_media
) == IFM_AUTO
&&
5273 ife
->ifm_data
!= mii
->mii_media_active
) {
5274 (*sc
->sc_statchg
)(sc
->sc_dev
);
5275 ife
->ifm_data
= mii
->mii_media_active
;
5281 tlp_2114x_nway_auto(struct tulip_softc
*sc
)
5283 uint32_t siastat
, siatxrx
;
5285 tlp_idle(sc
, OPMODE_ST
|OPMODE_SR
);
5287 sc
->sc_opmode
&= ~(OPMODE_PS
|OPMODE_PCS
|OPMODE_SCR
|OPMODE_FD
);
5288 sc
->sc_opmode
|= OPMODE_TTM
|OPMODE_HBD
;
5289 siatxrx
= 0xffbf; /* XXX magic number */
5291 /* Compute the link code word to advertise. */
5292 if (sc
->sc_sia_cap
& BMSR_100T4
)
5293 siatxrx
|= SIATXRX_T4
;
5294 if (sc
->sc_sia_cap
& BMSR_100TXFDX
)
5295 siatxrx
|= SIATXRX_TXF
;
5296 if (sc
->sc_sia_cap
& BMSR_100TXHDX
)
5297 siatxrx
|= SIATXRX_THX
;
5298 if (sc
->sc_sia_cap
& BMSR_10TFDX
)
5299 sc
->sc_opmode
|= OPMODE_FD
;
5300 if (sc
->sc_sia_cap
& BMSR_10THDX
)
5301 siatxrx
|= SIATXRX_TH
;
5303 TULIP_WRITE(sc
, CSR_OPMODE
, sc
->sc_opmode
);
5305 TULIP_WRITE(sc
, CSR_SIACONN
, 0);
5307 TULIP_WRITE(sc
, CSR_SIATXRX
, siatxrx
);
5308 TULIP_WRITE(sc
, CSR_SIACONN
, SIACONN_SRL
);
5310 siastat
= TULIP_READ(sc
, CSR_SIASTAT
);
5311 siastat
&= ~(SIASTAT_ANS
|SIASTAT_LPC
|SIASTAT_TRA
|SIASTAT_ARA
|
5312 SIASTAT_LS100
|SIASTAT_LS10
|SIASTAT_MRA
);
5313 siastat
|= SIASTAT_ANS_TXDIS
;
5314 TULIP_WRITE(sc
, CSR_SIASTAT
, siastat
);
5318 tlp_2114x_nway_status(struct tulip_softc
*sc
)
5320 struct mii_data
*mii
= &sc
->sc_mii
;
5321 uint32_t siatxrx
, siastat
, anlpar
;
5323 mii
->mii_media_status
= IFM_AVALID
;
5324 mii
->mii_media_active
= IFM_ETHER
;
5326 if ((mii
->mii_ifp
->if_flags
& IFF_UP
) == 0)
5329 siastat
= TULIP_READ(sc
, CSR_SIASTAT
);
5330 siatxrx
= TULIP_READ(sc
, CSR_SIATXRX
);
5332 if (siatxrx
& SIATXRX_ANE
) {
5333 if ((siastat
& SIASTAT_ANS
) != SIASTAT_ANS_FLPGOOD
) {
5334 /* Erg, still trying, I guess... */
5335 mii
->mii_media_active
|= IFM_NONE
;
5339 if (~siastat
& (SIASTAT_LS10
| SIASTAT_LS100
))
5340 mii
->mii_media_status
|= IFM_ACTIVE
;
5342 if (siastat
& SIASTAT_LPN
) {
5343 anlpar
= SIASTAT_GETLPC(siastat
);
5344 if (anlpar
& ANLPAR_T4
&&
5345 sc
->sc_sia_cap
& BMSR_100T4
)
5346 mii
->mii_media_active
|= IFM_100_T4
;
5347 else if (anlpar
& ANLPAR_TX_FD
&&
5348 sc
->sc_sia_cap
& BMSR_100TXFDX
)
5349 mii
->mii_media_active
|= IFM_100_TX
|IFM_FDX
;
5350 else if (anlpar
& ANLPAR_TX
&&
5351 sc
->sc_sia_cap
& BMSR_100TXHDX
)
5352 mii
->mii_media_active
|= IFM_100_TX
;
5353 else if (anlpar
& ANLPAR_10_FD
&&
5354 sc
->sc_sia_cap
& BMSR_10TFDX
)
5355 mii
->mii_media_active
|= IFM_10_T
|IFM_FDX
;
5356 else if (anlpar
& ANLPAR_10
&&
5357 sc
->sc_sia_cap
& BMSR_10THDX
)
5358 mii
->mii_media_active
|= IFM_10_T
;
5360 mii
->mii_media_active
|= IFM_NONE
;
5363 * If the other side doesn't support NWAY, then the
5364 * best we can do is determine if we have a 10Mbps or
5365 * 100Mbps link. There's no way to know if the link
5366 * is full or half duplex, so we default to half duplex
5367 * and hope that the user is clever enough to manually
5368 * change the media settings if we're wrong.
5370 if ((siastat
& SIASTAT_LS100
) == 0)
5371 mii
->mii_media_active
|= IFM_100_TX
;
5372 else if ((siastat
& SIASTAT_LS10
) == 0)
5373 mii
->mii_media_active
|= IFM_10_T
;
5375 mii
->mii_media_active
|= IFM_NONE
;
5378 if (~siastat
& (SIASTAT_LS10
| SIASTAT_LS100
))
5379 mii
->mii_media_status
|= IFM_ACTIVE
;
5381 if (sc
->sc_opmode
& OPMODE_TTM
)
5382 mii
->mii_media_active
|= IFM_10_T
;
5384 mii
->mii_media_active
|= IFM_100_TX
;
5385 if (sc
->sc_opmode
& OPMODE_FD
)
5386 mii
->mii_media_active
|= IFM_FDX
;
5391 tlp_2114x_isv_tmsw_get(struct tulip_softc
*sc
, struct ifmediareq
*ifmr
)
5393 struct ifmedia_entry
*ife
= sc
->sc_mii
.mii_media
.ifm_cur
;
5394 struct tulip_21x4x_media
*tm
= ife
->ifm_aux
;
5396 (*tm
->tm_get
)(sc
, ifmr
);
5400 tlp_2114x_isv_tmsw_set(struct tulip_softc
*sc
)
5402 struct ifmedia_entry
*ife
= sc
->sc_mii
.mii_media
.ifm_cur
;
5403 struct tulip_21x4x_media
*tm
= ife
->ifm_aux
;
5406 * Check to see if we need to reset the chip, and do it. The
5407 * reset path will get the OPMODE register right the next
5410 if (TULIP_MEDIA_NEEDSRESET(sc
, tm
->tm_opmode
))
5411 return (tlp_init(&sc
->sc_ethercom
.ec_if
));
5413 return ((*tm
->tm_set
)(sc
));
5417 * MII-on-SIO media switch. Handles only MII attached to the SIO.
5419 static void tlp_sio_mii_tmsw_init(struct tulip_softc
*);
5421 const struct tulip_mediasw tlp_sio_mii_mediasw
= {
5422 tlp_sio_mii_tmsw_init
, tlp_mii_getmedia
, tlp_mii_setmedia
5426 tlp_sio_mii_tmsw_init(struct tulip_softc
*sc
)
5428 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
5431 * We don't attach any media info structures to the ifmedia
5432 * entries, so if we're using a pre-init function that needs
5433 * that info, override it to one that doesn't.
5435 if (sc
->sc_preinit
== tlp_2114x_preinit
)
5436 sc
->sc_preinit
= tlp_2114x_mii_preinit
;
5438 sc
->sc_mii
.mii_ifp
= ifp
;
5439 sc
->sc_mii
.mii_readreg
= tlp_bitbang_mii_readreg
;
5440 sc
->sc_mii
.mii_writereg
= tlp_bitbang_mii_writereg
;
5441 sc
->sc_mii
.mii_statchg
= sc
->sc_statchg
;
5442 ifmedia_init(&sc
->sc_mii
.mii_media
, 0, tlp_mediachange
,
5444 mii_attach(sc
->sc_dev
, &sc
->sc_mii
, 0xffffffff, MII_PHY_ANY
,
5446 if (LIST_FIRST(&sc
->sc_mii
.mii_phys
) == NULL
) {
5447 ifmedia_add(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_NONE
, 0, NULL
);
5448 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_NONE
);
5450 sc
->sc_flags
|= TULIPF_HAS_MII
;
5451 sc
->sc_tick
= tlp_mii_tick
;
5452 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_AUTO
);
5457 * Lite-On PNIC media switch. Must handle MII or internal NWAY.
5459 static void tlp_pnic_tmsw_init(struct tulip_softc
*);
5460 static void tlp_pnic_tmsw_get(struct tulip_softc
*, struct ifmediareq
*);
5461 static int tlp_pnic_tmsw_set(struct tulip_softc
*);
5463 const struct tulip_mediasw tlp_pnic_mediasw
= {
5464 tlp_pnic_tmsw_init
, tlp_pnic_tmsw_get
, tlp_pnic_tmsw_set
5467 static void tlp_pnic_nway_statchg(device_t
);
5468 static void tlp_pnic_nway_tick(void *);
5469 static int tlp_pnic_nway_service(struct tulip_softc
*, int);
5470 static void tlp_pnic_nway_reset(struct tulip_softc
*);
5471 static int tlp_pnic_nway_auto(struct tulip_softc
*, int);
5472 static void tlp_pnic_nway_auto_timeout(void *);
5473 static void tlp_pnic_nway_status(struct tulip_softc
*);
5474 static void tlp_pnic_nway_acomp(struct tulip_softc
*);
5477 tlp_pnic_tmsw_init(struct tulip_softc
*sc
)
5479 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
5480 const char *sep
= "";
5482 #define ADD(m, c) ifmedia_add(&sc->sc_mii.mii_media, (m), (c), NULL)
5483 #define PRINT(str) aprint_normal("%s%s", sep, str); sep = ", "
5485 sc
->sc_mii
.mii_ifp
= ifp
;
5486 sc
->sc_mii
.mii_readreg
= tlp_pnic_mii_readreg
;
5487 sc
->sc_mii
.mii_writereg
= tlp_pnic_mii_writereg
;
5488 sc
->sc_mii
.mii_statchg
= sc
->sc_statchg
;
5489 ifmedia_init(&sc
->sc_mii
.mii_media
, 0, tlp_mediachange
,
5491 mii_attach(sc
->sc_dev
, &sc
->sc_mii
, 0xffffffff, MII_PHY_ANY
,
5493 if (LIST_FIRST(&sc
->sc_mii
.mii_phys
) == NULL
) {
5494 /* XXX What about AUI/BNC support? */
5495 aprint_normal_dev(sc
->sc_dev
, "");
5497 tlp_pnic_nway_reset(sc
);
5499 ADD(IFM_MAKEWORD(IFM_ETHER
, IFM_10_T
, 0, 0),
5500 PNIC_NWAY_TW
|PNIC_NWAY_CAP10T
);
5503 ADD(IFM_MAKEWORD(IFM_ETHER
, IFM_10_T
, IFM_FDX
, 0),
5504 PNIC_NWAY_TW
|PNIC_NWAY_FD
|PNIC_NWAY_CAP10TFDX
);
5505 PRINT("10baseT-FDX");
5507 ADD(IFM_MAKEWORD(IFM_ETHER
, IFM_100_TX
, 0, 0),
5508 PNIC_NWAY_TW
|PNIC_NWAY_100
|PNIC_NWAY_CAP100TX
);
5511 ADD(IFM_MAKEWORD(IFM_ETHER
, IFM_100_TX
, IFM_FDX
, 0),
5512 PNIC_NWAY_TW
|PNIC_NWAY_100
|PNIC_NWAY_FD
|
5513 PNIC_NWAY_CAP100TXFDX
);
5514 PRINT("100baseTX-FDX");
5516 ADD(IFM_MAKEWORD(IFM_ETHER
, IFM_AUTO
, 0, 0),
5517 PNIC_NWAY_TW
|PNIC_NWAY_RN
|PNIC_NWAY_NW
|
5518 PNIC_NWAY_CAP10T
|PNIC_NWAY_CAP10TFDX
|
5519 PNIC_NWAY_CAP100TXFDX
|PNIC_NWAY_CAP100TX
);
5522 aprint_normal("\n");
5524 sc
->sc_statchg
= tlp_pnic_nway_statchg
;
5525 sc
->sc_tick
= tlp_pnic_nway_tick
;
5526 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_AUTO
);
5528 sc
->sc_flags
|= TULIPF_HAS_MII
;
5529 sc
->sc_tick
= tlp_mii_tick
;
5530 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_AUTO
);
5538 tlp_pnic_tmsw_get(struct tulip_softc
*sc
, struct ifmediareq
*ifmr
)
5540 struct mii_data
*mii
= &sc
->sc_mii
;
5542 if (sc
->sc_flags
& TULIPF_HAS_MII
)
5543 tlp_mii_getmedia(sc
, ifmr
);
5545 mii
->mii_media_status
= 0;
5546 mii
->mii_media_active
= IFM_NONE
;
5547 tlp_pnic_nway_service(sc
, MII_POLLSTAT
);
5548 ifmr
->ifm_status
= sc
->sc_mii
.mii_media_status
;
5549 ifmr
->ifm_active
= sc
->sc_mii
.mii_media_active
;
5554 tlp_pnic_tmsw_set(struct tulip_softc
*sc
)
5556 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
5557 struct mii_data
*mii
= &sc
->sc_mii
;
5559 if (sc
->sc_flags
& TULIPF_HAS_MII
) {
5561 * Make sure the built-in Tx jabber timer is disabled.
5563 TULIP_WRITE(sc
, CSR_PNIC_ENDEC
, PNIC_ENDEC_JDIS
);
5565 return (tlp_mii_setmedia(sc
));
5568 if (ifp
->if_flags
& IFF_UP
) {
5569 mii
->mii_media_status
= 0;
5570 mii
->mii_media_active
= IFM_NONE
;
5571 return (tlp_pnic_nway_service(sc
, MII_MEDIACHG
));
5578 tlp_pnic_nway_statchg(device_t self
)
5580 struct tulip_softc
*sc
= device_private(self
);
5582 /* Idle the transmit and receive processes. */
5583 tlp_idle(sc
, OPMODE_ST
|OPMODE_SR
);
5585 sc
->sc_opmode
&= ~(OPMODE_TTM
|OPMODE_FD
|OPMODE_PS
|OPMODE_PCS
|
5586 OPMODE_SCR
|OPMODE_HBD
);
5588 if (IFM_SUBTYPE(sc
->sc_mii
.mii_media_active
) == IFM_10_T
) {
5589 sc
->sc_opmode
|= OPMODE_TTM
;
5590 TULIP_WRITE(sc
, CSR_GPP
,
5591 GPP_PNIC_OUT(GPP_PNIC_PIN_SPEED_RLY
, 0) |
5592 GPP_PNIC_OUT(GPP_PNIC_PIN_100M_LPKB
, 1));
5594 sc
->sc_opmode
|= OPMODE_PS
|OPMODE_PCS
|OPMODE_SCR
|OPMODE_HBD
;
5595 TULIP_WRITE(sc
, CSR_GPP
,
5596 GPP_PNIC_OUT(GPP_PNIC_PIN_SPEED_RLY
, 1) |
5597 GPP_PNIC_OUT(GPP_PNIC_PIN_100M_LPKB
, 1));
5600 if (sc
->sc_mii
.mii_media_active
& IFM_FDX
)
5601 sc
->sc_opmode
|= OPMODE_FD
|OPMODE_HBD
;
5604 * Write new OPMODE bits. This also restarts the transmit
5605 * and receive processes.
5607 TULIP_WRITE(sc
, CSR_OPMODE
, sc
->sc_opmode
);
5611 tlp_pnic_nway_tick(void *arg
)
5613 struct tulip_softc
*sc
= arg
;
5616 if (!device_is_active(sc
->sc_dev
))
5620 tlp_pnic_nway_service(sc
, MII_TICK
);
5623 callout_reset(&sc
->sc_tick_callout
, hz
, tlp_pnic_nway_tick
, sc
);
5627 * Support for the Lite-On PNIC internal NWay block. This is constructed
5628 * somewhat like a PHY driver for simplicity.
5632 tlp_pnic_nway_service(struct tulip_softc
*sc
, int cmd
)
5634 struct mii_data
*mii
= &sc
->sc_mii
;
5635 struct ifmedia_entry
*ife
= mii
->mii_media
.ifm_cur
;
5637 if ((mii
->mii_ifp
->if_flags
& IFF_UP
) == 0)
5642 /* Nothing special to do here. */
5646 switch (IFM_SUBTYPE(ife
->ifm_media
)) {
5648 (void) tlp_pnic_nway_auto(sc
, 1);
5652 * XXX Not supported as a manual setting right now.
5657 * NWAY register data is stored in the ifmedia entry.
5659 TULIP_WRITE(sc
, CSR_PNIC_NWAY
, ife
->ifm_data
);
5665 * Only used for autonegotiation.
5667 if (IFM_SUBTYPE(ife
->ifm_media
) != IFM_AUTO
)
5671 * Check to see if we have link. If we do, we don't
5672 * need to restart the autonegotiation process.
5674 if (sc
->sc_flags
& TULIPF_LINK_UP
)
5678 * Only retry autonegotiation every 5 seconds.
5680 if (++sc
->sc_nway_ticks
!= 5)
5683 sc
->sc_nway_ticks
= 0;
5684 tlp_pnic_nway_reset(sc
);
5685 if (tlp_pnic_nway_auto(sc
, 0) == EJUSTRETURN
)
5690 /* Update the media status. */
5691 tlp_pnic_nway_status(sc
);
5693 /* Callback if something changed. */
5694 if ((sc
->sc_nway_active
== NULL
||
5695 sc
->sc_nway_active
->ifm_media
!= mii
->mii_media_active
) ||
5696 cmd
== MII_MEDIACHG
) {
5697 (*sc
->sc_statchg
)(sc
->sc_dev
);
5698 tlp_nway_activate(sc
, mii
->mii_media_active
);
5704 tlp_pnic_nway_reset(struct tulip_softc
*sc
)
5707 TULIP_WRITE(sc
, CSR_PNIC_NWAY
, PNIC_NWAY_RS
);
5709 TULIP_WRITE(sc
, CSR_PNIC_NWAY
, 0);
5713 tlp_pnic_nway_auto(struct tulip_softc
*sc
, int waitfor
)
5715 struct mii_data
*mii
= &sc
->sc_mii
;
5716 struct ifmedia_entry
*ife
= mii
->mii_media
.ifm_cur
;
5720 if ((sc
->sc_flags
& TULIPF_DOINGAUTO
) == 0)
5721 TULIP_WRITE(sc
, CSR_PNIC_NWAY
, ife
->ifm_data
);
5724 /* Wait 500ms for it to complete. */
5725 for (i
= 0; i
< 500; i
++) {
5726 reg
= TULIP_READ(sc
, CSR_PNIC_NWAY
);
5727 if (reg
& PNIC_NWAY_LPAR_MASK
) {
5728 tlp_pnic_nway_acomp(sc
);
5734 if ((reg
& PNIC_NWAY_LPAR_MASK
) == 0)
5735 aprint_error_dev(sc
->sc_dev
, "autonegotiation failed to complete\n");
5739 * Don't need to worry about clearing DOINGAUTO.
5740 * If that's set, a timeout is pending, and it will
5747 * Just let it finish asynchronously. This is for the benefit of
5748 * the tick handler driving autonegotiation. Don't want 500ms
5749 * delays all the time while the system is running!
5751 if ((sc
->sc_flags
& TULIPF_DOINGAUTO
) == 0) {
5752 sc
->sc_flags
|= TULIPF_DOINGAUTO
;
5753 callout_reset(&sc
->sc_nway_callout
, hz
>> 1,
5754 tlp_pnic_nway_auto_timeout
, sc
);
5756 return (EJUSTRETURN
);
5760 tlp_pnic_nway_auto_timeout(void *arg
)
5762 struct tulip_softc
*sc
= arg
;
5767 sc
->sc_flags
&= ~TULIPF_DOINGAUTO
;
5768 reg
= TULIP_READ(sc
, CSR_PNIC_NWAY
);
5770 if ((reg
& PNIC_NWAY_LPAR_MASK
) == 0)
5771 aprint_error_dev(sc
->sc_dev
, "autonegotiation failed to complete\n");
5774 tlp_pnic_nway_acomp(sc
);
5776 /* Update the media status. */
5777 (void) tlp_pnic_nway_service(sc
, MII_POLLSTAT
);
5782 tlp_pnic_nway_status(struct tulip_softc
*sc
)
5784 struct mii_data
*mii
= &sc
->sc_mii
;
5787 mii
->mii_media_status
= IFM_AVALID
;
5788 mii
->mii_media_active
= IFM_ETHER
;
5790 reg
= TULIP_READ(sc
, CSR_PNIC_NWAY
);
5792 if (sc
->sc_flags
& TULIPF_LINK_UP
)
5793 mii
->mii_media_status
|= IFM_ACTIVE
;
5795 if (reg
& PNIC_NWAY_NW
) {
5796 if ((reg
& PNIC_NWAY_LPAR_MASK
) == 0) {
5797 /* Erg, still trying, I guess... */
5798 mii
->mii_media_active
|= IFM_NONE
;
5803 if (reg
& PNIC_NWAY_LPAR100T4
)
5804 mii
->mii_media_active
|= IFM_100_T4
;
5807 if (reg
& PNIC_NWAY_LPAR100TXFDX
)
5808 mii
->mii_media_active
|= IFM_100_TX
|IFM_FDX
;
5809 else if (reg
& PNIC_NWAY_LPAR100TX
)
5810 mii
->mii_media_active
|= IFM_100_TX
;
5811 else if (reg
& PNIC_NWAY_LPAR10TFDX
)
5812 mii
->mii_media_active
|= IFM_10_T
|IFM_FDX
;
5813 else if (reg
& PNIC_NWAY_LPAR10T
)
5814 mii
->mii_media_active
|= IFM_10_T
;
5816 mii
->mii_media_active
|= IFM_NONE
;
5818 if (reg
& PNIC_NWAY_100
)
5819 mii
->mii_media_active
|= IFM_100_TX
;
5821 mii
->mii_media_active
|= IFM_10_T
;
5822 if (reg
& PNIC_NWAY_FD
)
5823 mii
->mii_media_active
|= IFM_FDX
;
5828 tlp_pnic_nway_acomp(struct tulip_softc
*sc
)
5832 reg
= TULIP_READ(sc
, CSR_PNIC_NWAY
);
5833 reg
&= ~(PNIC_NWAY_FD
|PNIC_NWAY_100
|PNIC_NWAY_RN
);
5835 if (reg
& (PNIC_NWAY_LPAR100TXFDX
|PNIC_NWAY_LPAR100TX
))
5836 reg
|= PNIC_NWAY_100
;
5837 if (reg
& (PNIC_NWAY_LPAR10TFDX
|PNIC_NWAY_LPAR100TXFDX
))
5838 reg
|= PNIC_NWAY_FD
;
5840 TULIP_WRITE(sc
, CSR_PNIC_NWAY
, reg
);
5844 * Macronix PMAC and Lite-On PNIC-II media switch:
5846 * MX98713 and MX98713A 21140-like MII or GPIO media.
5848 * MX98713A 21143-like MII or SIA/SYM media.
5850 * MX98715, MX98715A, MX98725, 21143-like SIA/SYM media.
5851 * 82C115, MX98715AEC-C, -E
5853 * So, what we do here is fake MII-on-SIO or ISV media info, and
5854 * use the ISV media switch get/set functions to handle the rest.
5857 static void tlp_pmac_tmsw_init(struct tulip_softc
*);
5859 const struct tulip_mediasw tlp_pmac_mediasw
= {
5860 tlp_pmac_tmsw_init
, tlp_2114x_isv_tmsw_get
, tlp_2114x_isv_tmsw_set
5863 const struct tulip_mediasw tlp_pmac_mii_mediasw
= {
5864 tlp_pmac_tmsw_init
, tlp_mii_getmedia
, tlp_mii_setmedia
5868 tlp_pmac_tmsw_init(struct tulip_softc
*sc
)
5870 static const uint8_t media
[] = {
5871 TULIP_ROM_MB_MEDIA_TP
,
5872 TULIP_ROM_MB_MEDIA_TP_FDX
,
5873 TULIP_ROM_MB_MEDIA_100TX
,
5874 TULIP_ROM_MB_MEDIA_100TX_FDX
,
5876 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
5877 struct tulip_21x4x_media
*tm
;
5879 sc
->sc_mii
.mii_ifp
= ifp
;
5880 sc
->sc_mii
.mii_readreg
= tlp_bitbang_mii_readreg
;
5881 sc
->sc_mii
.mii_writereg
= tlp_bitbang_mii_writereg
;
5882 sc
->sc_mii
.mii_statchg
= sc
->sc_statchg
;
5883 ifmedia_init(&sc
->sc_mii
.mii_media
, 0, tlp_mediachange
,
5885 if (sc
->sc_chip
== TULIP_CHIP_MX98713
||
5886 sc
->sc_chip
== TULIP_CHIP_MX98713A
) {
5887 mii_attach(sc
->sc_dev
, &sc
->sc_mii
, 0xffffffff,
5888 MII_PHY_ANY
, MII_OFFSET_ANY
, 0);
5889 if (LIST_FIRST(&sc
->sc_mii
.mii_phys
) != NULL
) {
5890 sc
->sc_flags
|= TULIPF_HAS_MII
;
5891 sc
->sc_tick
= tlp_mii_tick
;
5892 sc
->sc_preinit
= tlp_2114x_mii_preinit
;
5893 sc
->sc_mediasw
= &tlp_pmac_mii_mediasw
;
5894 ifmedia_set(&sc
->sc_mii
.mii_media
,
5895 IFM_ETHER
|IFM_AUTO
);
5900 switch (sc
->sc_chip
) {
5901 case TULIP_CHIP_MX98713
:
5902 tlp_add_srom_media(sc
, TULIP_ROM_MB_21140_GPR
,
5903 tlp_21140_gpio_get
, tlp_21140_gpio_set
, media
, 4);
5906 * XXX Should implement auto-sense for this someday,
5907 * XXX when we do the same for the 21140.
5909 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_10_T
);
5913 tlp_add_srom_media(sc
, TULIP_ROM_MB_21142_SIA
,
5914 tlp_sia_get
, tlp_sia_set
, media
, 2);
5915 tlp_add_srom_media(sc
, TULIP_ROM_MB_21143_SYM
,
5916 tlp_sia_get
, tlp_sia_set
, media
+ 2, 2);
5918 tm
= malloc(sizeof(*tm
), M_DEVBUF
, M_WAITOK
|M_ZERO
);
5919 tm
->tm_name
= "auto";
5920 tm
->tm_get
= tlp_2114x_nway_get
;
5921 tm
->tm_set
= tlp_2114x_nway_set
;
5922 ifmedia_add(&sc
->sc_mii
.mii_media
,
5923 IFM_MAKEWORD(IFM_ETHER
, IFM_AUTO
, 0, 0), 0, tm
);
5925 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_AUTO
);
5926 sc
->sc_statchg
= tlp_2114x_nway_statchg
;
5927 sc
->sc_tick
= tlp_2114x_nway_tick
;
5931 tlp_print_media(sc
);
5934 /* Set the LED modes. */
5937 sc
->sc_reset
= tlp_pmac_reset
;
5941 * ADMtek AL981 media switch. Only has internal PHY.
5943 static void tlp_al981_tmsw_init(struct tulip_softc
*);
5945 const struct tulip_mediasw tlp_al981_mediasw
= {
5946 tlp_al981_tmsw_init
, tlp_mii_getmedia
, tlp_mii_setmedia
5950 tlp_al981_tmsw_init(struct tulip_softc
*sc
)
5952 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
5954 sc
->sc_mii
.mii_ifp
= ifp
;
5955 sc
->sc_mii
.mii_readreg
= tlp_al981_mii_readreg
;
5956 sc
->sc_mii
.mii_writereg
= tlp_al981_mii_writereg
;
5957 sc
->sc_mii
.mii_statchg
= sc
->sc_statchg
;
5958 ifmedia_init(&sc
->sc_mii
.mii_media
, 0, tlp_mediachange
,
5960 mii_attach(sc
->sc_dev
, &sc
->sc_mii
, 0xffffffff, MII_PHY_ANY
,
5962 if (LIST_FIRST(&sc
->sc_mii
.mii_phys
) == NULL
) {
5963 ifmedia_add(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_NONE
, 0, NULL
);
5964 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_NONE
);
5966 sc
->sc_flags
|= TULIPF_HAS_MII
;
5967 sc
->sc_tick
= tlp_mii_tick
;
5968 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_AUTO
);
5973 * ADMtek AN983/985 media switch. Only has internal PHY, but
5974 * on an SIO-like interface. Unfortunately, we can't use the
5975 * standard SIO media switch, because the AN985 "ghosts" the
5976 * singly PHY at every address.
5978 static void tlp_an985_tmsw_init(struct tulip_softc
*);
5980 const struct tulip_mediasw tlp_an985_mediasw
= {
5981 tlp_an985_tmsw_init
, tlp_mii_getmedia
, tlp_mii_setmedia
5985 tlp_an985_tmsw_init(struct tulip_softc
*sc
)
5987 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
5989 sc
->sc_mii
.mii_ifp
= ifp
;
5990 sc
->sc_mii
.mii_readreg
= tlp_bitbang_mii_readreg
;
5991 sc
->sc_mii
.mii_writereg
= tlp_bitbang_mii_writereg
;
5992 sc
->sc_mii
.mii_statchg
= sc
->sc_statchg
;
5993 ifmedia_init(&sc
->sc_mii
.mii_media
, 0, tlp_mediachange
,
5995 mii_attach(sc
->sc_dev
, &sc
->sc_mii
, 0xffffffff, 1,
5997 if (LIST_FIRST(&sc
->sc_mii
.mii_phys
) == NULL
) {
5998 ifmedia_add(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_NONE
, 0, NULL
);
5999 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_NONE
);
6001 sc
->sc_flags
|= TULIPF_HAS_MII
;
6002 sc
->sc_tick
= tlp_mii_tick
;
6003 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_AUTO
);
6008 * Davicom DM9102 media switch. Internal PHY and possibly HomePNA.
6010 static void tlp_dm9102_tmsw_init(struct tulip_softc
*);
6011 static void tlp_dm9102_tmsw_getmedia(struct tulip_softc
*,
6012 struct ifmediareq
*);
6013 static int tlp_dm9102_tmsw_setmedia(struct tulip_softc
*);
6015 const struct tulip_mediasw tlp_dm9102_mediasw
= {
6016 tlp_dm9102_tmsw_init
, tlp_dm9102_tmsw_getmedia
,
6017 tlp_dm9102_tmsw_setmedia
6021 tlp_dm9102_tmsw_init(struct tulip_softc
*sc
)
6023 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
6026 sc
->sc_mii
.mii_ifp
= ifp
;
6027 sc
->sc_mii
.mii_readreg
= tlp_bitbang_mii_readreg
;
6028 sc
->sc_mii
.mii_writereg
= tlp_bitbang_mii_writereg
;
6029 sc
->sc_mii
.mii_statchg
= sc
->sc_statchg
;
6030 ifmedia_init(&sc
->sc_mii
.mii_media
, 0, tlp_mediachange
,
6033 /* PHY block already reset via tlp_reset(). */
6036 * Configure OPMODE properly for the internal MII interface.
6038 switch (sc
->sc_chip
) {
6039 case TULIP_CHIP_DM9102
:
6040 opmode
= OPMODE_MBO
|OPMODE_HBD
|OPMODE_PS
;
6043 case TULIP_CHIP_DM9102A
:
6044 opmode
= OPMODE_MBO
|OPMODE_HBD
;
6052 TULIP_WRITE(sc
, CSR_OPMODE
, opmode
);
6054 /* Now, probe the internal MII for the internal PHY. */
6055 mii_attach(sc
->sc_dev
, &sc
->sc_mii
, 0xffffffff, MII_PHY_ANY
,
6059 * XXX Figure out what to do about the HomePNA portion
6060 * XXX of the DM9102A.
6063 if (LIST_FIRST(&sc
->sc_mii
.mii_phys
) == NULL
) {
6064 ifmedia_add(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_NONE
, 0, NULL
);
6065 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_NONE
);
6067 sc
->sc_flags
|= TULIPF_HAS_MII
;
6068 sc
->sc_tick
= tlp_mii_tick
;
6069 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_AUTO
);
6074 tlp_dm9102_tmsw_getmedia(struct tulip_softc
*sc
, struct ifmediareq
*ifmr
)
6077 /* XXX HomePNA on DM9102A. */
6078 tlp_mii_getmedia(sc
, ifmr
);
6082 tlp_dm9102_tmsw_setmedia(struct tulip_softc
*sc
)
6085 /* XXX HomePNA on DM9102A. */
6086 return (tlp_mii_setmedia(sc
));
6090 * ASIX AX88140A/AX88141 media switch. Internal PHY or MII.
6093 static void tlp_asix_tmsw_init(struct tulip_softc
*);
6094 static void tlp_asix_tmsw_getmedia(struct tulip_softc
*,
6095 struct ifmediareq
*);
6096 static int tlp_asix_tmsw_setmedia(struct tulip_softc
*);
6098 const struct tulip_mediasw tlp_asix_mediasw
= {
6099 tlp_asix_tmsw_init
, tlp_asix_tmsw_getmedia
,
6100 tlp_asix_tmsw_setmedia
6104 tlp_asix_tmsw_init(struct tulip_softc
*sc
)
6106 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
6109 sc
->sc_mii
.mii_ifp
= ifp
;
6110 sc
->sc_mii
.mii_readreg
= tlp_bitbang_mii_readreg
;
6111 sc
->sc_mii
.mii_writereg
= tlp_bitbang_mii_writereg
;
6112 sc
->sc_mii
.mii_statchg
= sc
->sc_statchg
;
6113 ifmedia_init(&sc
->sc_mii
.mii_media
, 0, tlp_mediachange
,
6117 * Configure OPMODE properly for the internal MII interface.
6119 switch (sc
->sc_chip
) {
6120 case TULIP_CHIP_AX88140
:
6121 case TULIP_CHIP_AX88141
:
6122 opmode
= OPMODE_HBD
|OPMODE_PS
;
6129 TULIP_WRITE(sc
, CSR_OPMODE
, opmode
);
6131 /* Now, probe the internal MII for the internal PHY. */
6132 mii_attach(sc
->sc_dev
, &sc
->sc_mii
, 0xffffffff, MII_PHY_ANY
,
6135 /* XXX Figure how to handle the PHY. */
6137 if (LIST_FIRST(&sc
->sc_mii
.mii_phys
) == NULL
) {
6138 ifmedia_add(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_NONE
, 0, NULL
);
6139 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_NONE
);
6141 sc
->sc_flags
|= TULIPF_HAS_MII
;
6142 sc
->sc_tick
= tlp_mii_tick
;
6143 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_AUTO
);
6150 tlp_asix_tmsw_getmedia(struct tulip_softc
*sc
, struct ifmediareq
*ifmr
)
6153 /* XXX PHY handling. */
6154 tlp_mii_getmedia(sc
, ifmr
);
6158 tlp_asix_tmsw_setmedia(struct tulip_softc
*sc
)
6161 /* XXX PHY handling. */
6162 return (tlp_mii_setmedia(sc
));
6166 * RS7112 media switch. Handles only MII attached to the SIO.
6167 * We only have a PHY at 1.
6169 void tlp_rs7112_tmsw_init(struct tulip_softc
*);
6171 const struct tulip_mediasw tlp_rs7112_mediasw
= {
6172 tlp_rs7112_tmsw_init
, tlp_mii_getmedia
, tlp_mii_setmedia
6176 tlp_rs7112_tmsw_init(struct tulip_softc
*sc
)
6178 struct ifnet
*ifp
= &sc
->sc_ethercom
.ec_if
;
6181 * We don't attach any media info structures to the ifmedia
6182 * entries, so if we're using a pre-init function that needs
6183 * that info, override it to one that doesn't.
6185 if (sc
->sc_preinit
== tlp_2114x_preinit
)
6186 sc
->sc_preinit
= tlp_2114x_mii_preinit
;
6188 sc
->sc_mii
.mii_ifp
= ifp
;
6189 sc
->sc_mii
.mii_readreg
= tlp_bitbang_mii_readreg
;
6190 sc
->sc_mii
.mii_writereg
= tlp_bitbang_mii_writereg
;
6191 sc
->sc_mii
.mii_statchg
= sc
->sc_statchg
;
6192 ifmedia_init(&sc
->sc_mii
.mii_media
, 0, tlp_mediachange
,
6196 * The RS7112 reports a PHY at 0 (possibly HomePNA?)
6197 * and 1 (ethernet). We attach ethernet only.
6199 mii_attach(sc
->sc_dev
, &sc
->sc_mii
, 0xffffffff, 1,
6202 if (LIST_FIRST(&sc
->sc_mii
.mii_phys
) == NULL
) {
6203 ifmedia_add(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_NONE
, 0, NULL
);
6204 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_NONE
);
6206 sc
->sc_flags
|= TULIPF_HAS_MII
;
6207 sc
->sc_tick
= tlp_mii_tick
;
6208 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_AUTO
);