2 * Copyright (c) 1997, 1998, 1999
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
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
30 * THE POSSIBILITY OF SUCH DAMAGE.
32 * $FreeBSD: src/sys/pci/if_xl.c,v 1.72.2.28 2003/10/08 06:01:57 murray Exp $
33 * $DragonFly: src/sys/dev/netif/xl/if_xl.c,v 1.10 2004/03/19 06:30:08 dillon Exp $
37 * 3Com 3c90x Etherlink XL PCI NIC driver
39 * Supports the 3Com "boomerang", "cyclone" and "hurricane" PCI
40 * bus-master chips (3c90x cards and embedded controllers) including
43 * 3Com 3c900-TPO 10Mbps/RJ-45
44 * 3Com 3c900-COMBO 10Mbps/RJ-45,AUI,BNC
45 * 3Com 3c905-TX 10/100Mbps/RJ-45
46 * 3Com 3c905-T4 10/100Mbps/RJ-45
47 * 3Com 3c900B-TPO 10Mbps/RJ-45
48 * 3Com 3c900B-COMBO 10Mbps/RJ-45,AUI,BNC
49 * 3Com 3c900B-TPC 10Mbps/RJ-45,BNC
50 * 3Com 3c900B-FL 10Mbps/Fiber-optic
51 * 3Com 3c905B-COMBO 10/100Mbps/RJ-45,AUI,BNC
52 * 3Com 3c905B-TX 10/100Mbps/RJ-45
53 * 3Com 3c905B-FL/FX 10/100Mbps/Fiber-optic
54 * 3Com 3c905C-TX 10/100Mbps/RJ-45 (Tornado ASIC)
55 * 3Com 3c980-TX 10/100Mbps server adapter (Hurricane ASIC)
56 * 3Com 3c980C-TX 10/100Mbps server adapter (Tornado ASIC)
57 * 3Com 3cSOHO100-TX 10/100Mbps/RJ-45 (Hurricane ASIC)
58 * 3Com 3c450-TX 10/100Mbps/RJ-45 (Tornado ASIC)
59 * 3Com 3c555 10/100Mbps/RJ-45 (MiniPCI, Laptop Hurricane)
60 * 3Com 3c556 10/100Mbps/RJ-45 (MiniPCI, Hurricane ASIC)
61 * 3Com 3c556B 10/100Mbps/RJ-45 (MiniPCI, Hurricane ASIC)
62 * 3Com 3c575TX 10/100Mbps/RJ-45 (Cardbus, Hurricane ASIC)
63 * 3Com 3c575B 10/100Mbps/RJ-45 (Cardbus, Hurricane ASIC)
64 * 3Com 3c575C 10/100Mbps/RJ-45 (Cardbus, Hurricane ASIC)
65 * 3Com 3cxfem656 10/100Mbps/RJ-45 (Cardbus, Hurricane ASIC)
66 * 3Com 3cxfem656b 10/100Mbps/RJ-45 (Cardbus, Hurricane ASIC)
67 * 3Com 3cxfem656c 10/100Mbps/RJ-45 (Cardbus, Tornado ASIC)
68 * Dell Optiplex GX1 on-board 3c918 10/100Mbps/RJ-45
69 * Dell on-board 3c920 10/100Mbps/RJ-45
70 * Dell Precision on-board 3c905B 10/100Mbps/RJ-45
71 * Dell Latitude laptop docking station embedded 3c905-TX
73 * Written by Bill Paul <wpaul@ctr.columbia.edu>
74 * Electrical Engineering Department
75 * Columbia University, New York City
79 * The 3c90x series chips use a bus-master DMA interface for transfering
80 * packets to and from the controller chip. Some of the "vortex" cards
81 * (3c59x) also supported a bus master mode, however for those chips
82 * you could only DMA packets to/from a contiguous memory buffer. For
83 * transmission this would mean copying the contents of the queued mbuf
84 * chain into an mbuf cluster and then DMAing the cluster. This extra
85 * copy would sort of defeat the purpose of the bus master support for
86 * any packet that doesn't fit into a single mbuf.
88 * By contrast, the 3c90x cards support a fragment-based bus master
89 * mode where mbuf chains can be encapsulated using TX descriptors.
90 * This is similar to other PCI chips such as the Texas Instruments
91 * ThunderLAN and the Intel 82557/82558.
93 * The "vortex" driver (if_vx.c) happens to work for the "boomerang"
94 * bus master chips because they maintain the old PIO interface for
95 * backwards compatibility, but starting with the 3c905B and the
96 * "cyclone" chips, the compatibility interface has been dropped.
97 * Since using bus master DMA is a big win, we use this driver to
98 * support the PCI "boomerang" chips even though they work with the
99 * "vortex" driver in order to obtain better performance.
101 * This driver is in the /sys/pci directory because it only supports
105 #include <sys/param.h>
106 #include <sys/systm.h>
107 #include <sys/sockio.h>
108 #include <sys/endian.h>
109 #include <sys/mbuf.h>
110 #include <sys/kernel.h>
111 #include <sys/socket.h>
114 #include <net/if_arp.h>
115 #include <net/ethernet.h>
116 #include <net/if_dl.h>
117 #include <net/if_media.h>
118 #include <net/vlan/if_vlan_var.h>
122 #include <machine/bus_memio.h>
123 #include <machine/bus_pio.h>
124 #include <machine/bus.h>
125 #include <machine/clock.h> /* for DELAY */
126 #include <machine/resource.h>
128 #include <sys/rman.h>
130 #include "../mii_layer/mii.h"
131 #include "../mii_layer/miivar.h"
133 #include <bus/pci/pcireg.h>
134 #include <bus/pci/pcivar.h>
136 /* "controller miibus0" required. See GENERIC if you get errors here. */
137 #include "miibus_if.h"
139 #include "if_xlreg.h"
141 #define XL905B_CSUM_FEATURES (CSUM_IP | CSUM_TCP | CSUM_UDP)
144 * Various supported device vendors/types and their names.
146 static struct xl_type xl_devs[] = {
147 { TC_VENDORID, TC_DEVICEID_BOOMERANG_10BT,
148 "3Com 3c900-TPO Etherlink XL" },
149 { TC_VENDORID, TC_DEVICEID_BOOMERANG_10BT_COMBO,
150 "3Com 3c900-COMBO Etherlink XL" },
151 { TC_VENDORID, TC_DEVICEID_BOOMERANG_10_100BT,
152 "3Com 3c905-TX Fast Etherlink XL" },
153 { TC_VENDORID, TC_DEVICEID_BOOMERANG_100BT4,
154 "3Com 3c905-T4 Fast Etherlink XL" },
155 { TC_VENDORID, TC_DEVICEID_KRAKATOA_10BT,
156 "3Com 3c900B-TPO Etherlink XL" },
157 { TC_VENDORID, TC_DEVICEID_KRAKATOA_10BT_COMBO,
158 "3Com 3c900B-COMBO Etherlink XL" },
159 { TC_VENDORID, TC_DEVICEID_KRAKATOA_10BT_TPC,
160 "3Com 3c900B-TPC Etherlink XL" },
161 { TC_VENDORID, TC_DEVICEID_CYCLONE_10FL,
162 "3Com 3c900B-FL Etherlink XL" },
163 { TC_VENDORID, TC_DEVICEID_HURRICANE_10_100BT,
164 "3Com 3c905B-TX Fast Etherlink XL" },
165 { TC_VENDORID, TC_DEVICEID_CYCLONE_10_100BT4,
166 "3Com 3c905B-T4 Fast Etherlink XL" },
167 { TC_VENDORID, TC_DEVICEID_CYCLONE_10_100FX,
168 "3Com 3c905B-FX/SC Fast Etherlink XL" },
169 { TC_VENDORID, TC_DEVICEID_CYCLONE_10_100_COMBO,
170 "3Com 3c905B-COMBO Fast Etherlink XL" },
171 { TC_VENDORID, TC_DEVICEID_TORNADO_10_100BT,
172 "3Com 3c905C-TX Fast Etherlink XL" },
173 { TC_VENDORID, TC_DEVICEID_TORNADO_10_100BT_920B,
174 "3Com 3c920B-EMB Integrated Fast Etherlink XL" },
175 { TC_VENDORID, TC_DEVICEID_HURRICANE_10_100BT_SERV,
176 "3Com 3c980 Fast Etherlink XL" },
177 { TC_VENDORID, TC_DEVICEID_TORNADO_10_100BT_SERV,
178 "3Com 3c980C Fast Etherlink XL" },
179 { TC_VENDORID, TC_DEVICEID_HURRICANE_SOHO100TX,
180 "3Com 3cSOHO100-TX OfficeConnect" },
181 { TC_VENDORID, TC_DEVICEID_TORNADO_HOMECONNECT,
182 "3Com 3c450-TX HomeConnect" },
183 { TC_VENDORID, TC_DEVICEID_HURRICANE_555,
184 "3Com 3c555 Fast Etherlink XL" },
185 { TC_VENDORID, TC_DEVICEID_HURRICANE_556,
186 "3Com 3c556 Fast Etherlink XL" },
187 { TC_VENDORID, TC_DEVICEID_HURRICANE_556B,
188 "3Com 3c556B Fast Etherlink XL" },
189 { TC_VENDORID, TC_DEVICEID_HURRICANE_575A,
190 "3Com 3c575TX Fast Etherlink XL" },
191 { TC_VENDORID, TC_DEVICEID_HURRICANE_575B,
192 "3Com 3c575B Fast Etherlink XL" },
193 { TC_VENDORID, TC_DEVICEID_HURRICANE_575C,
194 "3Com 3c575C Fast Etherlink XL" },
195 { TC_VENDORID, TC_DEVICEID_HURRICANE_656,
196 "3Com 3c656 Fast Etherlink XL" },
197 { TC_VENDORID, TC_DEVICEID_HURRICANE_656B,
198 "3Com 3c656B Fast Etherlink XL" },
199 { TC_VENDORID, TC_DEVICEID_TORNADO_656C,
200 "3Com 3c656C Fast Etherlink XL" },
204 static int xl_probe (device_t);
205 static int xl_attach (device_t);
206 static int xl_detach (device_t);
208 static int xl_newbuf (struct xl_softc *, struct xl_chain_onefrag *);
209 static void xl_stats_update (void *);
210 static int xl_encap (struct xl_softc *, struct xl_chain *,
212 static void xl_rxeof (struct xl_softc *);
213 static int xl_rx_resync (struct xl_softc *);
214 static void xl_txeof (struct xl_softc *);
215 static void xl_txeof_90xB (struct xl_softc *);
216 static void xl_txeoc (struct xl_softc *);
217 static void xl_intr (void *);
218 static void xl_start (struct ifnet *);
219 static void xl_start_90xB (struct ifnet *);
220 static int xl_ioctl (struct ifnet *, u_long, caddr_t);
221 static void xl_init (void *);
222 static void xl_stop (struct xl_softc *);
223 static void xl_watchdog (struct ifnet *);
224 static void xl_shutdown (device_t);
225 static int xl_suspend (device_t);
226 static int xl_resume (device_t);
228 static int xl_ifmedia_upd (struct ifnet *);
229 static void xl_ifmedia_sts (struct ifnet *, struct ifmediareq *);
231 static int xl_eeprom_wait (struct xl_softc *);
232 static int xl_read_eeprom (struct xl_softc *, caddr_t, int, int, int);
233 static void xl_mii_sync (struct xl_softc *);
234 static void xl_mii_send (struct xl_softc *, u_int32_t, int);
235 static int xl_mii_readreg (struct xl_softc *, struct xl_mii_frame *);
236 static int xl_mii_writereg (struct xl_softc *, struct xl_mii_frame *);
238 static void xl_setcfg (struct xl_softc *);
239 static void xl_setmode (struct xl_softc *, int);
240 static u_int8_t xl_calchash (caddr_t);
241 static void xl_setmulti (struct xl_softc *);
242 static void xl_setmulti_hash (struct xl_softc *);
243 static void xl_reset (struct xl_softc *);
244 static int xl_list_rx_init (struct xl_softc *);
245 static int xl_list_tx_init (struct xl_softc *);
246 static int xl_list_tx_init_90xB (struct xl_softc *);
247 static void xl_wait (struct xl_softc *);
248 static void xl_mediacheck (struct xl_softc *);
249 static void xl_choose_xcvr (struct xl_softc *, int);
250 static void xl_dma_map_addr (void *, bus_dma_segment_t *, int, int);
251 static void xl_dma_map_rxbuf (void *, bus_dma_segment_t *, int, bus_size_t,
253 static void xl_dma_map_txbuf (void *, bus_dma_segment_t *, int, bus_size_t,
256 static void xl_testpacket (struct xl_softc *);
259 static int xl_miibus_readreg (device_t, int, int);
260 static int xl_miibus_writereg (device_t, int, int, int);
261 static void xl_miibus_statchg (device_t);
262 static void xl_miibus_mediainit (device_t);
264 static device_method_t xl_methods[] = {
265 /* Device interface */
266 DEVMETHOD(device_probe, xl_probe),
267 DEVMETHOD(device_attach, xl_attach),
268 DEVMETHOD(device_detach, xl_detach),
269 DEVMETHOD(device_shutdown, xl_shutdown),
270 DEVMETHOD(device_suspend, xl_suspend),
271 DEVMETHOD(device_resume, xl_resume),
274 DEVMETHOD(bus_print_child, bus_generic_print_child),
275 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
278 DEVMETHOD(miibus_readreg, xl_miibus_readreg),
279 DEVMETHOD(miibus_writereg, xl_miibus_writereg),
280 DEVMETHOD(miibus_statchg, xl_miibus_statchg),
281 DEVMETHOD(miibus_mediainit, xl_miibus_mediainit),
286 static driver_t xl_driver = {
289 sizeof(struct xl_softc)
292 static devclass_t xl_devclass;
294 DECLARE_DUMMY_MODULE(if_xl);
295 MODULE_DEPEND(if_xl, miibus, 1, 1, 1);
296 DRIVER_MODULE(if_xl, pci, xl_driver, xl_devclass, 0, 0);
297 DRIVER_MODULE(miibus, xl, miibus_driver, miibus_devclass, 0, 0);
300 xl_dma_map_addr(arg, segs, nseg, error)
302 bus_dma_segment_t *segs;
308 *paddr = segs->ds_addr;
312 xl_dma_map_rxbuf(arg, segs, nseg, mapsize, error)
314 bus_dma_segment_t *segs;
323 KASSERT(nseg == 1, ("xl_dma_map_rxbuf: too many DMA segments"));
325 *paddr = segs->ds_addr;
329 xl_dma_map_txbuf(arg, segs, nseg, mapsize, error)
331 bus_dma_segment_t *segs;
342 KASSERT(nseg <= XL_MAXFRAGS, ("too many DMA segments"));
346 for (i = 0; i < nseg; i++) {
347 KASSERT(segs[i].ds_len <= MCLBYTES, ("segment size too large"));
348 l->xl_frag[i].xl_addr = htole32(segs[i].ds_addr);
349 l->xl_frag[i].xl_len = htole32(segs[i].ds_len);
350 total_len += segs[i].ds_len;
352 l->xl_frag[nseg - 1].xl_len = htole32(segs[nseg - 1].ds_len |
354 l->xl_status = htole32(total_len);
359 * Murphy's law says that it's possible the chip can wedge and
360 * the 'command in progress' bit may never clear. Hence, we wait
361 * only a finite amount of time to avoid getting caught in an
362 * infinite loop. Normally this delay routine would be a macro,
363 * but it isn't called during normal operation so we can afford
364 * to make it a function.
372 for (i = 0; i < XL_TIMEOUT; i++) {
373 if (!(CSR_READ_2(sc, XL_STATUS) & XL_STAT_CMDBUSY))
378 printf("xl%d: command never completed!\n", sc->xl_unit);
384 * MII access routines are provided for adapters with external
385 * PHYs (3c905-TX, 3c905-T4, 3c905B-T4) and those with built-in
386 * autoneg logic that's faked up to look like a PHY (3c905B-TX).
387 * Note: if you don't perform the MDIO operations just right,
388 * it's possible to end up with code that works correctly with
389 * some chips/CPUs/processor speeds/bus speeds/etc but not
393 CSR_WRITE_2(sc, XL_W4_PHY_MGMT, \
394 CSR_READ_2(sc, XL_W4_PHY_MGMT) | (x))
397 CSR_WRITE_2(sc, XL_W4_PHY_MGMT, \
398 CSR_READ_2(sc, XL_W4_PHY_MGMT) & ~(x))
401 * Sync the PHYs by setting data bit and strobing the clock 32 times.
410 MII_SET(XL_MII_DIR|XL_MII_DATA);
412 for (i = 0; i < 32; i++) {
414 MII_SET(XL_MII_DATA);
415 MII_SET(XL_MII_DATA);
417 MII_SET(XL_MII_DATA);
418 MII_SET(XL_MII_DATA);
425 * Clock a series of bits through the MII.
428 xl_mii_send(sc, bits, cnt)
438 for (i = (0x1 << (cnt - 1)); i; i >>= 1) {
440 MII_SET(XL_MII_DATA);
442 MII_CLR(XL_MII_DATA);
450 * Read an PHY register through the MII.
453 xl_mii_readreg(sc, frame)
455 struct xl_mii_frame *frame;
463 * Set up frame for RX.
465 frame->mii_stdelim = XL_MII_STARTDELIM;
466 frame->mii_opcode = XL_MII_READOP;
467 frame->mii_turnaround = 0;
471 * Select register window 4.
476 CSR_WRITE_2(sc, XL_W4_PHY_MGMT, 0);
485 * Send command/address info.
487 xl_mii_send(sc, frame->mii_stdelim, 2);
488 xl_mii_send(sc, frame->mii_opcode, 2);
489 xl_mii_send(sc, frame->mii_phyaddr, 5);
490 xl_mii_send(sc, frame->mii_regaddr, 5);
493 MII_CLR((XL_MII_CLK|XL_MII_DATA));
501 ack = CSR_READ_2(sc, XL_W4_PHY_MGMT) & XL_MII_DATA;
505 * Now try reading data bits. If the ack failed, we still
506 * need to clock through 16 cycles to keep the PHY(s) in sync.
509 for(i = 0; i < 16; i++) {
516 for (i = 0x8000; i; i >>= 1) {
519 if (CSR_READ_2(sc, XL_W4_PHY_MGMT) & XL_MII_DATA)
520 frame->mii_data |= i;
538 * Write to a PHY register through the MII.
541 xl_mii_writereg(sc, frame)
543 struct xl_mii_frame *frame;
551 * Set up frame for TX.
554 frame->mii_stdelim = XL_MII_STARTDELIM;
555 frame->mii_opcode = XL_MII_WRITEOP;
556 frame->mii_turnaround = XL_MII_TURNAROUND;
559 * Select the window 4.
564 * Turn on data output.
570 xl_mii_send(sc, frame->mii_stdelim, 2);
571 xl_mii_send(sc, frame->mii_opcode, 2);
572 xl_mii_send(sc, frame->mii_phyaddr, 5);
573 xl_mii_send(sc, frame->mii_regaddr, 5);
574 xl_mii_send(sc, frame->mii_turnaround, 2);
575 xl_mii_send(sc, frame->mii_data, 16);
592 xl_miibus_readreg(dev, phy, reg)
597 struct xl_mii_frame frame;
599 sc = device_get_softc(dev);
602 * Pretend that PHYs are only available at MII address 24.
603 * This is to guard against problems with certain 3Com ASIC
604 * revisions that incorrectly map the internal transceiver
605 * control registers at all MII addresses. This can cause
606 * the miibus code to attach the same PHY several times over.
608 if ((!(sc->xl_flags & XL_FLAG_PHYOK)) && phy != 24)
611 bzero((char *)&frame, sizeof(frame));
613 frame.mii_phyaddr = phy;
614 frame.mii_regaddr = reg;
615 xl_mii_readreg(sc, &frame);
617 return(frame.mii_data);
621 xl_miibus_writereg(dev, phy, reg, data)
626 struct xl_mii_frame frame;
628 sc = device_get_softc(dev);
630 if ((!(sc->xl_flags & XL_FLAG_PHYOK)) && phy != 24)
633 bzero((char *)&frame, sizeof(frame));
635 frame.mii_phyaddr = phy;
636 frame.mii_regaddr = reg;
637 frame.mii_data = data;
639 xl_mii_writereg(sc, &frame);
645 xl_miibus_statchg(dev)
649 struct mii_data *mii;
652 sc = device_get_softc(dev);
653 mii = device_get_softc(sc->xl_miibus);
657 /* Set ASIC's duplex mode to match the PHY. */
659 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX)
660 CSR_WRITE_1(sc, XL_W3_MAC_CTRL, XL_MACCTRL_DUPLEX);
662 CSR_WRITE_1(sc, XL_W3_MAC_CTRL,
663 (CSR_READ_1(sc, XL_W3_MAC_CTRL) & ~XL_MACCTRL_DUPLEX));
669 * Special support for the 3c905B-COMBO. This card has 10/100 support
670 * plus BNC and AUI ports. This means we will have both an miibus attached
671 * plus some non-MII media settings. In order to allow this, we have to
672 * add the extra media to the miibus's ifmedia struct, but we can't do
673 * that during xl_attach() because the miibus hasn't been attached yet.
674 * So instead, we wait until the miibus probe/attach is done, at which
675 * point we will get a callback telling is that it's safe to add our
679 xl_miibus_mediainit(dev)
683 struct mii_data *mii;
686 sc = device_get_softc(dev);
687 mii = device_get_softc(sc->xl_miibus);
688 ifm = &mii->mii_media;
690 if (sc->xl_media & (XL_MEDIAOPT_AUI|XL_MEDIAOPT_10FL)) {
692 * Check for a 10baseFL board in disguise.
694 if (sc->xl_type == XL_TYPE_905B &&
695 sc->xl_media == XL_MEDIAOPT_10FL) {
697 printf("xl%d: found 10baseFL\n", sc->xl_unit);
698 ifmedia_add(ifm, IFM_ETHER|IFM_10_FL, 0, NULL);
699 ifmedia_add(ifm, IFM_ETHER|IFM_10_FL|IFM_HDX, 0, NULL);
700 if (sc->xl_caps & XL_CAPS_FULL_DUPLEX)
702 IFM_ETHER|IFM_10_FL|IFM_FDX, 0, NULL);
705 printf("xl%d: found AUI\n", sc->xl_unit);
706 ifmedia_add(ifm, IFM_ETHER|IFM_10_5, 0, NULL);
710 if (sc->xl_media & XL_MEDIAOPT_BNC) {
712 printf("xl%d: found BNC\n", sc->xl_unit);
713 ifmedia_add(ifm, IFM_ETHER|IFM_10_2, 0, NULL);
720 * The EEPROM is slow: give it time to come ready after issuing
729 for (i = 0; i < 100; i++) {
730 if (CSR_READ_2(sc, XL_W0_EE_CMD) & XL_EE_BUSY)
737 printf("xl%d: eeprom failed to come ready\n", sc->xl_unit);
745 * Read a sequence of words from the EEPROM. Note that ethernet address
746 * data is stored in the EEPROM in network byte order.
749 xl_read_eeprom(sc, dest, off, cnt, swap)
757 u_int16_t word = 0, *ptr;
758 #define EEPROM_5BIT_OFFSET(A) ((((A) << 2) & 0x7F00) | ((A) & 0x003F))
759 #define EEPROM_8BIT_OFFSET(A) ((A) & 0x003F)
761 * It's easy to accidentally overwrite the rom content!
762 * Note: the 3c575 uses 8bit EEPROM offsets.
766 if (xl_eeprom_wait(sc))
769 if (sc->xl_flags & XL_FLAG_EEPROM_OFFSET_30)
772 for (i = 0; i < cnt; i++) {
773 if (sc->xl_flags & XL_FLAG_8BITROM)
774 CSR_WRITE_2(sc, XL_W0_EE_CMD,
775 XL_EE_8BIT_READ | EEPROM_8BIT_OFFSET(off + i));
777 CSR_WRITE_2(sc, XL_W0_EE_CMD,
778 XL_EE_READ | EEPROM_5BIT_OFFSET(off + i));
779 err = xl_eeprom_wait(sc);
782 word = CSR_READ_2(sc, XL_W0_EE_DATA);
783 ptr = (u_int16_t *)(dest + (i * 2));
794 * This routine is taken from the 3Com Etherlink XL manual,
795 * page 10-7. It calculates a CRC of the supplied multicast
796 * group address and returns the lower 8 bits, which are used
797 * as the multicast filter position.
798 * Note: the 3c905B currently only supports a 64-bit hash table,
799 * which means we really only need 6 bits, but the manual indicates
800 * that future chip revisions will have a 256-bit hash table,
801 * hence the routine is set up to calculate 8 bits of position
802 * info in case we need it some day.
803 * Note II, The Sequel: _CURRENT_ versions of the 3c905B have a
804 * 256 bit hash table. This means we have to use all 8 bits regardless.
805 * On older cards, the upper 2 bits will be ignored. Grrrr....
807 static u_int8_t xl_calchash(addr)
810 u_int32_t crc, carry;
814 /* Compute CRC for the address value. */
815 crc = 0xFFFFFFFF; /* initial value */
817 for (i = 0; i < 6; i++) {
819 for (j = 0; j < 8; j++) {
820 carry = ((crc & 0x80000000) ? 1 : 0) ^ (c & 0x01);
824 crc = (crc ^ 0x04c11db6) | carry;
828 /* return the filter bit position */
829 return(crc & 0x000000FF);
833 * NICs older than the 3c905B have only one multicast option, which
834 * is to enable reception of all multicast frames.
841 struct ifmultiaddr *ifma;
845 ifp = &sc->arpcom.ac_if;
848 rxfilt = CSR_READ_1(sc, XL_W5_RX_FILTER);
850 if (ifp->if_flags & IFF_ALLMULTI) {
851 rxfilt |= XL_RXFILTER_ALLMULTI;
852 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_SET_FILT|rxfilt);
856 for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL;
857 ifma = ifma->ifma_link.le_next)
861 rxfilt |= XL_RXFILTER_ALLMULTI;
863 rxfilt &= ~XL_RXFILTER_ALLMULTI;
865 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_SET_FILT|rxfilt);
871 * 3c905B adapters have a hash filter that we can program.
879 struct ifmultiaddr *ifma;
883 ifp = &sc->arpcom.ac_if;
886 rxfilt = CSR_READ_1(sc, XL_W5_RX_FILTER);
888 if (ifp->if_flags & IFF_ALLMULTI) {
889 rxfilt |= XL_RXFILTER_ALLMULTI;
890 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_SET_FILT|rxfilt);
893 rxfilt &= ~XL_RXFILTER_ALLMULTI;
896 /* first, zot all the existing hash bits */
897 for (i = 0; i < XL_HASHFILT_SIZE; i++)
898 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_SET_HASH|i);
900 /* now program new ones */
901 for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL;
902 ifma = ifma->ifma_link.le_next) {
903 if (ifma->ifma_addr->sa_family != AF_LINK)
905 h = xl_calchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
906 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_SET_HASH|XL_HASH_SET|h);
911 rxfilt |= XL_RXFILTER_MULTIHASH;
913 rxfilt &= ~XL_RXFILTER_MULTIHASH;
915 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_SET_FILT|rxfilt);
928 ifp = &sc->arpcom.ac_if;
930 MGETHDR(m, M_DONTWAIT, MT_DATA);
935 bcopy(&sc->arpcom.ac_enaddr,
936 mtod(m, struct ether_header *)->ether_dhost, ETHER_ADDR_LEN);
937 bcopy(&sc->arpcom.ac_enaddr,
938 mtod(m, struct ether_header *)->ether_shost, ETHER_ADDR_LEN);
939 mtod(m, struct ether_header *)->ether_type = htons(3);
940 mtod(m, unsigned char *)[14] = 0;
941 mtod(m, unsigned char *)[15] = 0;
942 mtod(m, unsigned char *)[16] = 0xE3;
943 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
944 IF_ENQUEUE(&ifp->if_snd, m);
958 icfg = CSR_READ_4(sc, XL_W3_INTERNAL_CFG);
959 icfg &= ~XL_ICFG_CONNECTOR_MASK;
960 if (sc->xl_media & XL_MEDIAOPT_MII ||
961 sc->xl_media & XL_MEDIAOPT_BT4)
962 icfg |= (XL_XCVR_MII << XL_ICFG_CONNECTOR_BITS);
963 if (sc->xl_media & XL_MEDIAOPT_BTX)
964 icfg |= (XL_XCVR_AUTO << XL_ICFG_CONNECTOR_BITS);
966 CSR_WRITE_4(sc, XL_W3_INTERNAL_CFG, icfg);
967 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_COAX_STOP);
973 xl_setmode(sc, media)
980 printf("xl%d: selecting ", sc->xl_unit);
983 mediastat = CSR_READ_2(sc, XL_W4_MEDIA_STATUS);
985 icfg = CSR_READ_4(sc, XL_W3_INTERNAL_CFG);
987 if (sc->xl_media & XL_MEDIAOPT_BT) {
988 if (IFM_SUBTYPE(media) == IFM_10_T) {
989 printf("10baseT transceiver, ");
990 sc->xl_xcvr = XL_XCVR_10BT;
991 icfg &= ~XL_ICFG_CONNECTOR_MASK;
992 icfg |= (XL_XCVR_10BT << XL_ICFG_CONNECTOR_BITS);
993 mediastat |= XL_MEDIASTAT_LINKBEAT|
994 XL_MEDIASTAT_JABGUARD;
995 mediastat &= ~XL_MEDIASTAT_SQEENB;
999 if (sc->xl_media & XL_MEDIAOPT_BFX) {
1000 if (IFM_SUBTYPE(media) == IFM_100_FX) {
1001 printf("100baseFX port, ");
1002 sc->xl_xcvr = XL_XCVR_100BFX;
1003 icfg &= ~XL_ICFG_CONNECTOR_MASK;
1004 icfg |= (XL_XCVR_100BFX << XL_ICFG_CONNECTOR_BITS);
1005 mediastat |= XL_MEDIASTAT_LINKBEAT;
1006 mediastat &= ~XL_MEDIASTAT_SQEENB;
1010 if (sc->xl_media & (XL_MEDIAOPT_AUI|XL_MEDIAOPT_10FL)) {
1011 if (IFM_SUBTYPE(media) == IFM_10_5) {
1012 printf("AUI port, ");
1013 sc->xl_xcvr = XL_XCVR_AUI;
1014 icfg &= ~XL_ICFG_CONNECTOR_MASK;
1015 icfg |= (XL_XCVR_AUI << XL_ICFG_CONNECTOR_BITS);
1016 mediastat &= ~(XL_MEDIASTAT_LINKBEAT|
1017 XL_MEDIASTAT_JABGUARD);
1018 mediastat |= ~XL_MEDIASTAT_SQEENB;
1020 if (IFM_SUBTYPE(media) == IFM_10_FL) {
1021 printf("10baseFL transceiver, ");
1022 sc->xl_xcvr = XL_XCVR_AUI;
1023 icfg &= ~XL_ICFG_CONNECTOR_MASK;
1024 icfg |= (XL_XCVR_AUI << XL_ICFG_CONNECTOR_BITS);
1025 mediastat &= ~(XL_MEDIASTAT_LINKBEAT|
1026 XL_MEDIASTAT_JABGUARD);
1027 mediastat |= ~XL_MEDIASTAT_SQEENB;
1031 if (sc->xl_media & XL_MEDIAOPT_BNC) {
1032 if (IFM_SUBTYPE(media) == IFM_10_2) {
1033 printf("BNC port, ");
1034 sc->xl_xcvr = XL_XCVR_COAX;
1035 icfg &= ~XL_ICFG_CONNECTOR_MASK;
1036 icfg |= (XL_XCVR_COAX << XL_ICFG_CONNECTOR_BITS);
1037 mediastat &= ~(XL_MEDIASTAT_LINKBEAT|
1038 XL_MEDIASTAT_JABGUARD|
1039 XL_MEDIASTAT_SQEENB);
1043 if ((media & IFM_GMASK) == IFM_FDX ||
1044 IFM_SUBTYPE(media) == IFM_100_FX) {
1045 printf("full duplex\n");
1047 CSR_WRITE_1(sc, XL_W3_MAC_CTRL, XL_MACCTRL_DUPLEX);
1049 printf("half duplex\n");
1051 CSR_WRITE_1(sc, XL_W3_MAC_CTRL,
1052 (CSR_READ_1(sc, XL_W3_MAC_CTRL) & ~XL_MACCTRL_DUPLEX));
1055 if (IFM_SUBTYPE(media) == IFM_10_2)
1056 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_COAX_START);
1058 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_COAX_STOP);
1059 CSR_WRITE_4(sc, XL_W3_INTERNAL_CFG, icfg);
1061 CSR_WRITE_2(sc, XL_W4_MEDIA_STATUS, mediastat);
1070 struct xl_softc *sc;
1075 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RESET |
1076 ((sc->xl_flags & XL_FLAG_WEIRDRESET) ?
1077 XL_RESETOPT_DISADVFD:0));
1080 * If we're using memory mapped register mode, pause briefly
1081 * after issuing the reset command before trying to access any
1082 * other registers. With my 3c575C cardbus card, failing to do
1083 * this results in the system locking up while trying to poll
1084 * the command busy bit in the status register.
1086 if (sc->xl_flags & XL_FLAG_USE_MMIO)
1089 for (i = 0; i < XL_TIMEOUT; i++) {
1091 if (!(CSR_READ_2(sc, XL_STATUS) & XL_STAT_CMDBUSY))
1095 if (i == XL_TIMEOUT)
1096 printf("xl%d: reset didn't complete\n", sc->xl_unit);
1098 /* Reset TX and RX. */
1099 /* Note: the RX reset takes an absurd amount of time
1100 * on newer versions of the Tornado chips such as those
1101 * on the 3c905CX and newer 3c908C cards. We wait an
1102 * extra amount of time so that xl_wait() doesn't complain
1103 * and annoy the users.
1105 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_RESET);
1108 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_TX_RESET);
1111 if (sc->xl_flags & XL_FLAG_INVERT_LED_PWR ||
1112 sc->xl_flags & XL_FLAG_INVERT_MII_PWR) {
1114 CSR_WRITE_2(sc, XL_W2_RESET_OPTIONS, CSR_READ_2(sc,
1115 XL_W2_RESET_OPTIONS)
1116 | ((sc->xl_flags & XL_FLAG_INVERT_LED_PWR)?XL_RESETOPT_INVERT_LED:0)
1117 | ((sc->xl_flags & XL_FLAG_INVERT_MII_PWR)?XL_RESETOPT_INVERT_MII:0)
1121 /* Wait a little while for the chip to get its brains in order. */
1127 * Probe for a 3Com Etherlink XL chip. Check the PCI vendor and device
1128 * IDs against our list and return a device name if we find a match.
1138 while(t->xl_name != NULL) {
1139 if ((pci_get_vendor(dev) == t->xl_vid) &&
1140 (pci_get_device(dev) == t->xl_did)) {
1141 device_set_desc(dev, t->xl_name);
1151 * This routine is a kludge to work around possible hardware faults
1152 * or manufacturing defects that can cause the media options register
1153 * (or reset options register, as it's called for the first generation
1154 * 3c90x adapters) to return an incorrect result. I have encountered
1155 * one Dell Latitude laptop docking station with an integrated 3c905-TX
1156 * which doesn't have any of the 'mediaopt' bits set. This screws up
1157 * the attach routine pretty badly because it doesn't know what media
1158 * to look for. If we find ourselves in this predicament, this routine
1159 * will try to guess the media options values and warn the user of a
1160 * possible manufacturing defect with his adapter/system/whatever.
1164 struct xl_softc *sc;
1168 * If some of the media options bits are set, assume they are
1169 * correct. If not, try to figure it out down below.
1170 * XXX I should check for 10baseFL, but I don't have an adapter
1173 if (sc->xl_media & (XL_MEDIAOPT_MASK & ~XL_MEDIAOPT_VCO)) {
1175 * Check the XCVR value. If it's not in the normal range
1176 * of values, we need to fake it up here.
1178 if (sc->xl_xcvr <= XL_XCVR_AUTO)
1181 printf("xl%d: bogus xcvr value "
1182 "in EEPROM (%x)\n", sc->xl_unit, sc->xl_xcvr);
1183 printf("xl%d: choosing new default based "
1184 "on card type\n", sc->xl_unit);
1187 if (sc->xl_type == XL_TYPE_905B &&
1188 sc->xl_media & XL_MEDIAOPT_10FL)
1190 printf("xl%d: WARNING: no media options bits set in "
1191 "the media options register!!\n", sc->xl_unit);
1192 printf("xl%d: this could be a manufacturing defect in "
1193 "your adapter or system\n", sc->xl_unit);
1194 printf("xl%d: attempting to guess media type; you "
1195 "should probably consult your vendor\n", sc->xl_unit);
1198 xl_choose_xcvr(sc, 1);
1204 xl_choose_xcvr(sc, verbose)
1205 struct xl_softc *sc;
1211 * Read the device ID from the EEPROM.
1212 * This is what's loaded into the PCI device ID register, so it has
1213 * to be correct otherwise we wouldn't have gotten this far.
1215 xl_read_eeprom(sc, (caddr_t)&devid, XL_EE_PRODID, 1, 0);
1218 case TC_DEVICEID_BOOMERANG_10BT: /* 3c900-TPO */
1219 case TC_DEVICEID_KRAKATOA_10BT: /* 3c900B-TPO */
1220 sc->xl_media = XL_MEDIAOPT_BT;
1221 sc->xl_xcvr = XL_XCVR_10BT;
1223 printf("xl%d: guessing 10BaseT "
1224 "transceiver\n", sc->xl_unit);
1226 case TC_DEVICEID_BOOMERANG_10BT_COMBO: /* 3c900-COMBO */
1227 case TC_DEVICEID_KRAKATOA_10BT_COMBO: /* 3c900B-COMBO */
1228 sc->xl_media = XL_MEDIAOPT_BT|XL_MEDIAOPT_BNC|XL_MEDIAOPT_AUI;
1229 sc->xl_xcvr = XL_XCVR_10BT;
1231 printf("xl%d: guessing COMBO "
1232 "(AUI/BNC/TP)\n", sc->xl_unit);
1234 case TC_DEVICEID_KRAKATOA_10BT_TPC: /* 3c900B-TPC */
1235 sc->xl_media = XL_MEDIAOPT_BT|XL_MEDIAOPT_BNC;
1236 sc->xl_xcvr = XL_XCVR_10BT;
1238 printf("xl%d: guessing TPC (BNC/TP)\n", sc->xl_unit);
1240 case TC_DEVICEID_CYCLONE_10FL: /* 3c900B-FL */
1241 sc->xl_media = XL_MEDIAOPT_10FL;
1242 sc->xl_xcvr = XL_XCVR_AUI;
1244 printf("xl%d: guessing 10baseFL\n", sc->xl_unit);
1246 case TC_DEVICEID_BOOMERANG_10_100BT: /* 3c905-TX */
1247 case TC_DEVICEID_HURRICANE_555: /* 3c555 */
1248 case TC_DEVICEID_HURRICANE_556: /* 3c556 */
1249 case TC_DEVICEID_HURRICANE_556B: /* 3c556B */
1250 case TC_DEVICEID_HURRICANE_575A: /* 3c575TX */
1251 case TC_DEVICEID_HURRICANE_575B: /* 3c575B */
1252 case TC_DEVICEID_HURRICANE_575C: /* 3c575C */
1253 case TC_DEVICEID_HURRICANE_656: /* 3c656 */
1254 case TC_DEVICEID_HURRICANE_656B: /* 3c656B */
1255 case TC_DEVICEID_TORNADO_656C: /* 3c656C */
1256 case TC_DEVICEID_TORNADO_10_100BT_920B: /* 3c920B-EMB */
1257 sc->xl_media = XL_MEDIAOPT_MII;
1258 sc->xl_xcvr = XL_XCVR_MII;
1260 printf("xl%d: guessing MII\n", sc->xl_unit);
1262 case TC_DEVICEID_BOOMERANG_100BT4: /* 3c905-T4 */
1263 case TC_DEVICEID_CYCLONE_10_100BT4: /* 3c905B-T4 */
1264 sc->xl_media = XL_MEDIAOPT_BT4;
1265 sc->xl_xcvr = XL_XCVR_MII;
1267 printf("xl%d: guessing 100BaseT4/MII\n", sc->xl_unit);
1269 case TC_DEVICEID_HURRICANE_10_100BT: /* 3c905B-TX */
1270 case TC_DEVICEID_HURRICANE_10_100BT_SERV:/*3c980-TX */
1271 case TC_DEVICEID_TORNADO_10_100BT_SERV: /* 3c980C-TX */
1272 case TC_DEVICEID_HURRICANE_SOHO100TX: /* 3cSOHO100-TX */
1273 case TC_DEVICEID_TORNADO_10_100BT: /* 3c905C-TX */
1274 case TC_DEVICEID_TORNADO_HOMECONNECT: /* 3c450-TX */
1275 sc->xl_media = XL_MEDIAOPT_BTX;
1276 sc->xl_xcvr = XL_XCVR_AUTO;
1278 printf("xl%d: guessing 10/100 internal\n", sc->xl_unit);
1280 case TC_DEVICEID_CYCLONE_10_100_COMBO: /* 3c905B-COMBO */
1281 sc->xl_media = XL_MEDIAOPT_BTX|XL_MEDIAOPT_BNC|XL_MEDIAOPT_AUI;
1282 sc->xl_xcvr = XL_XCVR_AUTO;
1284 printf("xl%d: guessing 10/100 "
1285 "plus BNC/AUI\n", sc->xl_unit);
1288 printf("xl%d: unknown device ID: %x -- "
1289 "defaulting to 10baseT\n", sc->xl_unit, devid);
1290 sc->xl_media = XL_MEDIAOPT_BT;
1298 * Attach the interface. Allocate softc structures, do ifmedia
1299 * setup and ethernet/BPF attach.
1306 u_char eaddr[ETHER_ADDR_LEN];
1309 struct xl_softc *sc;
1311 int media = IFM_ETHER|IFM_100_TX|IFM_FDX;
1312 int unit, error = 0, rid, res;
1316 sc = device_get_softc(dev);
1317 unit = device_get_unit(dev);
1319 ifmedia_init(&sc->ifmedia, 0, xl_ifmedia_upd, xl_ifmedia_sts);
1322 if (pci_get_device(dev) == TC_DEVICEID_HURRICANE_555)
1323 sc->xl_flags |= XL_FLAG_EEPROM_OFFSET_30 | XL_FLAG_PHYOK;
1324 if (pci_get_device(dev) == TC_DEVICEID_HURRICANE_556 ||
1325 pci_get_device(dev) == TC_DEVICEID_HURRICANE_556B)
1326 sc->xl_flags |= XL_FLAG_FUNCREG | XL_FLAG_PHYOK |
1327 XL_FLAG_EEPROM_OFFSET_30 | XL_FLAG_WEIRDRESET |
1328 XL_FLAG_INVERT_LED_PWR | XL_FLAG_INVERT_MII_PWR;
1329 if (pci_get_device(dev) == TC_DEVICEID_HURRICANE_555 ||
1330 pci_get_device(dev) == TC_DEVICEID_HURRICANE_556)
1331 sc->xl_flags |= XL_FLAG_8BITROM;
1332 if (pci_get_device(dev) == TC_DEVICEID_HURRICANE_556B)
1333 sc->xl_flags |= XL_FLAG_NO_XCVR_PWR;
1335 if (pci_get_device(dev) == TC_DEVICEID_HURRICANE_575A ||
1336 pci_get_device(dev) == TC_DEVICEID_HURRICANE_575B ||
1337 pci_get_device(dev) == TC_DEVICEID_HURRICANE_575C ||
1338 pci_get_device(dev) == TC_DEVICEID_HURRICANE_656B ||
1339 pci_get_device(dev) == TC_DEVICEID_TORNADO_656C)
1340 sc->xl_flags |= XL_FLAG_FUNCREG | XL_FLAG_PHYOK |
1341 XL_FLAG_EEPROM_OFFSET_30 | XL_FLAG_8BITROM;
1342 if (pci_get_device(dev) == TC_DEVICEID_HURRICANE_656)
1343 sc->xl_flags |= XL_FLAG_FUNCREG | XL_FLAG_PHYOK;
1344 if (pci_get_device(dev) == TC_DEVICEID_HURRICANE_575B)
1345 sc->xl_flags |= XL_FLAG_INVERT_LED_PWR;
1346 if (pci_get_device(dev) == TC_DEVICEID_HURRICANE_575C)
1347 sc->xl_flags |= XL_FLAG_INVERT_MII_PWR;
1348 if (pci_get_device(dev) == TC_DEVICEID_TORNADO_656C)
1349 sc->xl_flags |= XL_FLAG_INVERT_MII_PWR;
1350 if (pci_get_device(dev) == TC_DEVICEID_HURRICANE_656 ||
1351 pci_get_device(dev) == TC_DEVICEID_HURRICANE_656B)
1352 sc->xl_flags |= XL_FLAG_INVERT_MII_PWR |
1353 XL_FLAG_INVERT_LED_PWR;
1354 if (pci_get_device(dev) == TC_DEVICEID_TORNADO_10_100BT_920B)
1355 sc->xl_flags |= XL_FLAG_PHYOK;
1356 #ifndef BURN_BRIDGES
1358 * If this is a 3c905B, we have to check one extra thing.
1359 * The 905B supports power management and may be placed in
1360 * a low-power mode (D3 mode), typically by certain operating
1361 * systems which shall not be named. The PCI BIOS is supposed
1362 * to reset the NIC and bring it out of low-power mode, but
1363 * some do not. Consequently, we have to see if this chip
1364 * supports power management, and if so, make sure it's not
1365 * in low-power mode. If power management is available, the
1366 * capid byte will be 0x01.
1368 * I _think_ that what actually happens is that the chip
1369 * loses its PCI configuration during the transition from
1370 * D3 back to D0; this means that it should be possible for
1371 * us to save the PCI iobase, membase and IRQ, put the chip
1372 * back in the D0 state, then restore the PCI config ourselves.
1375 if (pci_get_powerstate(dev) != PCI_POWERSTATE_D0) {
1376 u_int32_t iobase, membase, irq;
1378 /* Save important PCI config data. */
1379 iobase = pci_read_config(dev, XL_PCI_LOIO, 4);
1380 membase = pci_read_config(dev, XL_PCI_LOMEM, 4);
1381 irq = pci_read_config(dev, XL_PCI_INTLINE, 4);
1383 /* Reset the power state. */
1384 printf("xl%d: chip is in D%d power mode "
1385 "-- setting to D0\n", unit,
1386 pci_get_powerstate(dev));
1388 pci_set_powerstate(dev, PCI_POWERSTATE_D0);
1390 /* Restore PCI config data. */
1391 pci_write_config(dev, XL_PCI_LOIO, iobase, 4);
1392 pci_write_config(dev, XL_PCI_LOMEM, membase, 4);
1393 pci_write_config(dev, XL_PCI_INTLINE, irq, 4);
1397 * Map control/status registers.
1399 pci_enable_busmaster(dev);
1400 pci_enable_io(dev, SYS_RES_IOPORT);
1401 pci_enable_io(dev, SYS_RES_MEMORY);
1402 command = pci_read_config(dev, PCIR_COMMAND, 4);
1404 if (!(command & PCIM_CMD_PORTEN) && !(command & PCIM_CMD_MEMEN)) {
1405 printf("xl%d: failed to enable I/O ports and memory mappings!\n", unit);
1411 res = SYS_RES_MEMORY;
1414 sc->xl_res = bus_alloc_resource(dev, res, &rid,
1415 0, ~0, 1, RF_ACTIVE);
1418 if (sc->xl_res != NULL) {
1419 sc->xl_flags |= XL_FLAG_USE_MMIO;
1421 printf("xl%d: using memory mapped I/O\n", unit);
1424 res = SYS_RES_IOPORT;
1425 sc->xl_res = bus_alloc_resource(dev, res, &rid,
1426 0, ~0, 1, RF_ACTIVE);
1427 if (sc->xl_res == NULL) {
1428 printf ("xl%d: couldn't map ports/memory\n", unit);
1433 printf("xl%d: using port I/O\n", unit);
1436 sc->xl_btag = rman_get_bustag(sc->xl_res);
1437 sc->xl_bhandle = rman_get_bushandle(sc->xl_res);
1439 if (sc->xl_flags & XL_FLAG_FUNCREG) {
1440 rid = XL_PCI_FUNCMEM;
1441 sc->xl_fres = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
1442 0, ~0, 1, RF_ACTIVE);
1444 if (sc->xl_fres == NULL) {
1445 printf ("xl%d: couldn't map ports/memory\n", unit);
1450 sc->xl_ftag = rman_get_bustag(sc->xl_fres);
1451 sc->xl_fhandle = rman_get_bushandle(sc->xl_fres);
1454 /* Allocate interrupt */
1456 sc->xl_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
1457 RF_SHAREABLE | RF_ACTIVE);
1458 if (sc->xl_irq == NULL) {
1459 printf("xl%d: couldn't map interrupt\n", unit);
1464 sc->xl_flags |= XL_FLAG_ATTACH_MAPPED;
1466 /* Reset the adapter. */
1470 * Get station address from the EEPROM.
1472 if (xl_read_eeprom(sc, (caddr_t)&eaddr, XL_EE_OEM_ADR0, 3, 1)) {
1473 printf("xl%d: failed to read station address\n", sc->xl_unit);
1479 * A 3Com chip was detected. Inform the world.
1481 printf("xl%d: Ethernet address: %6D\n", unit, eaddr, ":");
1484 callout_handle_init(&sc->xl_stat_ch);
1487 * Now allocate a tag for the DMA descriptor lists and a chunk
1488 * of DMA-able memory based on the tag. Also obtain the DMA
1489 * addresses of the RX and TX ring, which we'll need later.
1490 * All of our lists are allocated as a contiguous block
1493 error = bus_dma_tag_create(NULL, 8, 0,
1494 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1495 XL_RX_LIST_SZ, 1, XL_RX_LIST_SZ, 0,
1496 &sc->xl_ldata.xl_rx_tag);
1498 printf("xl%d: failed to allocate rx dma tag\n", unit);
1502 error = bus_dmamem_alloc(sc->xl_ldata.xl_rx_tag,
1503 (void **)&sc->xl_ldata.xl_rx_list, BUS_DMA_NOWAIT,
1504 &sc->xl_ldata.xl_rx_dmamap);
1506 printf("xl%d: no memory for rx list buffers!\n", unit);
1507 bus_dma_tag_destroy(sc->xl_ldata.xl_rx_tag);
1508 sc->xl_ldata.xl_rx_tag = NULL;
1512 error = bus_dmamap_load(sc->xl_ldata.xl_rx_tag,
1513 sc->xl_ldata.xl_rx_dmamap, sc->xl_ldata.xl_rx_list,
1514 XL_RX_LIST_SZ, xl_dma_map_addr,
1515 &sc->xl_ldata.xl_rx_dmaaddr, BUS_DMA_NOWAIT);
1517 printf("xl%d: cannot get dma address of the rx ring!\n", unit);
1518 bus_dmamem_free(sc->xl_ldata.xl_rx_tag, sc->xl_ldata.xl_rx_list,
1519 sc->xl_ldata.xl_rx_dmamap);
1520 bus_dma_tag_destroy(sc->xl_ldata.xl_rx_tag);
1521 sc->xl_ldata.xl_rx_tag = NULL;
1525 error = bus_dma_tag_create(NULL, 8, 0,
1526 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1527 XL_TX_LIST_SZ, 1, XL_TX_LIST_SZ, 0,
1528 &sc->xl_ldata.xl_tx_tag);
1530 printf("xl%d: failed to allocate tx dma tag\n", unit);
1534 error = bus_dmamem_alloc(sc->xl_ldata.xl_tx_tag,
1535 (void **)&sc->xl_ldata.xl_tx_list, BUS_DMA_NOWAIT,
1536 &sc->xl_ldata.xl_tx_dmamap);
1538 printf("xl%d: no memory for list buffers!\n", unit);
1539 bus_dma_tag_destroy(sc->xl_ldata.xl_tx_tag);
1540 sc->xl_ldata.xl_tx_tag = NULL;
1544 error = bus_dmamap_load(sc->xl_ldata.xl_tx_tag,
1545 sc->xl_ldata.xl_tx_dmamap, sc->xl_ldata.xl_tx_list,
1546 XL_TX_LIST_SZ, xl_dma_map_addr,
1547 &sc->xl_ldata.xl_tx_dmaaddr, BUS_DMA_NOWAIT);
1549 printf("xl%d: cannot get dma address of the tx ring!\n", unit);
1550 bus_dmamem_free(sc->xl_ldata.xl_tx_tag, sc->xl_ldata.xl_tx_list,
1551 sc->xl_ldata.xl_tx_dmamap);
1552 bus_dma_tag_destroy(sc->xl_ldata.xl_tx_tag);
1553 sc->xl_ldata.xl_tx_tag = NULL;
1558 * Allocate a DMA tag for the mapping of mbufs.
1560 error = bus_dma_tag_create(NULL, 1, 0,
1561 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1562 MCLBYTES * XL_MAXFRAGS, XL_MAXFRAGS, MCLBYTES, 0,
1565 printf("xl%d: failed to allocate mbuf dma tag\n", unit);
1569 bzero(sc->xl_ldata.xl_tx_list, XL_TX_LIST_SZ);
1570 bzero(sc->xl_ldata.xl_rx_list, XL_RX_LIST_SZ);
1572 /* We need a spare DMA map for the RX ring. */
1573 error = bus_dmamap_create(sc->xl_mtag, 0, &sc->xl_tmpmap);
1578 * Figure out the card type. 3c905B adapters have the
1579 * 'supportsNoTxLength' bit set in the capabilities
1580 * word in the EEPROM.
1581 * Note: my 3c575C cardbus card lies. It returns a value
1582 * of 0x1578 for its capabilities word, which is somewhat
1583 * nonsensical. Another way to distinguish a 3c90x chip
1584 * from a 3c90xB/C chip is to check for the 'supportsLargePackets'
1585 * bit. This will only be set for 3c90x boomerage chips.
1587 xl_read_eeprom(sc, (caddr_t)&sc->xl_caps, XL_EE_CAPS, 1, 0);
1588 if (sc->xl_caps & XL_CAPS_NO_TXLENGTH ||
1589 !(sc->xl_caps & XL_CAPS_LARGE_PKTS))
1590 sc->xl_type = XL_TYPE_905B;
1592 sc->xl_type = XL_TYPE_90X;
1594 ifp = &sc->arpcom.ac_if;
1596 if_initname(ifp, "xl", unit);
1597 ifp->if_mtu = ETHERMTU;
1598 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1599 ifp->if_ioctl = xl_ioctl;
1600 ifp->if_output = ether_output;
1601 ifp->if_capabilities = 0;
1602 if (sc->xl_type == XL_TYPE_905B) {
1603 ifp->if_start = xl_start_90xB;
1604 ifp->if_capabilities |= IFCAP_HWCSUM;
1606 ifp->if_start = xl_start;
1608 ifp->if_watchdog = xl_watchdog;
1609 ifp->if_init = xl_init;
1610 ifp->if_baudrate = 10000000;
1611 ifp->if_snd.ifq_maxlen = XL_TX_LIST_CNT - 1;
1613 * NOTE: features disabled by default. This seems to corrupt
1614 * tx packet data one out of a million packets or so and then
1615 * generates a good checksum so the receiver doesn't
1616 * know the packet is bad
1618 ifp->if_capenable = 0; /*ifp->if_capabilities;*/
1619 if (ifp->if_capenable & IFCAP_TXCSUM)
1620 ifp->if_hwassist = XL905B_CSUM_FEATURES;
1623 * Now we have to see what sort of media we have.
1624 * This includes probing for an MII interace and a
1628 sc->xl_media = CSR_READ_2(sc, XL_W3_MEDIA_OPT);
1630 printf("xl%d: media options word: %x\n", sc->xl_unit,
1633 xl_read_eeprom(sc, (char *)&xcvr, XL_EE_ICFG_0, 2, 0);
1634 sc->xl_xcvr = xcvr[0] | xcvr[1] << 16;
1635 sc->xl_xcvr &= XL_ICFG_CONNECTOR_MASK;
1636 sc->xl_xcvr >>= XL_ICFG_CONNECTOR_BITS;
1640 if (sc->xl_media & XL_MEDIAOPT_MII || sc->xl_media & XL_MEDIAOPT_BTX
1641 || sc->xl_media & XL_MEDIAOPT_BT4) {
1643 printf("xl%d: found MII/AUTO\n", sc->xl_unit);
1645 if (mii_phy_probe(dev, &sc->xl_miibus,
1646 xl_ifmedia_upd, xl_ifmedia_sts)) {
1647 printf("xl%d: no PHY found!\n", sc->xl_unit);
1656 * Sanity check. If the user has selected "auto" and this isn't
1657 * a 10/100 card of some kind, we need to force the transceiver
1658 * type to something sane.
1660 if (sc->xl_xcvr == XL_XCVR_AUTO)
1661 xl_choose_xcvr(sc, bootverbose);
1666 if (sc->xl_media & XL_MEDIAOPT_BT) {
1668 printf("xl%d: found 10baseT\n", sc->xl_unit);
1669 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_T, 0, NULL);
1670 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_T|IFM_HDX, 0, NULL);
1671 if (sc->xl_caps & XL_CAPS_FULL_DUPLEX)
1672 ifmedia_add(&sc->ifmedia,
1673 IFM_ETHER|IFM_10_T|IFM_FDX, 0, NULL);
1676 if (sc->xl_media & (XL_MEDIAOPT_AUI|XL_MEDIAOPT_10FL)) {
1678 * Check for a 10baseFL board in disguise.
1680 if (sc->xl_type == XL_TYPE_905B &&
1681 sc->xl_media == XL_MEDIAOPT_10FL) {
1683 printf("xl%d: found 10baseFL\n", sc->xl_unit);
1684 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_FL, 0, NULL);
1685 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_FL|IFM_HDX,
1687 if (sc->xl_caps & XL_CAPS_FULL_DUPLEX)
1688 ifmedia_add(&sc->ifmedia,
1689 IFM_ETHER|IFM_10_FL|IFM_FDX, 0, NULL);
1692 printf("xl%d: found AUI\n", sc->xl_unit);
1693 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_5, 0, NULL);
1697 if (sc->xl_media & XL_MEDIAOPT_BNC) {
1699 printf("xl%d: found BNC\n", sc->xl_unit);
1700 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_2, 0, NULL);
1703 if (sc->xl_media & XL_MEDIAOPT_BFX) {
1705 printf("xl%d: found 100baseFX\n", sc->xl_unit);
1706 ifp->if_baudrate = 100000000;
1707 ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_100_FX, 0, NULL);
1710 /* Choose a default media. */
1711 switch(sc->xl_xcvr) {
1713 media = IFM_ETHER|IFM_10_T;
1714 xl_setmode(sc, media);
1717 if (sc->xl_type == XL_TYPE_905B &&
1718 sc->xl_media == XL_MEDIAOPT_10FL) {
1719 media = IFM_ETHER|IFM_10_FL;
1720 xl_setmode(sc, media);
1722 media = IFM_ETHER|IFM_10_5;
1723 xl_setmode(sc, media);
1727 media = IFM_ETHER|IFM_10_2;
1728 xl_setmode(sc, media);
1731 case XL_XCVR_100BTX:
1733 /* Chosen by miibus */
1735 case XL_XCVR_100BFX:
1736 media = IFM_ETHER|IFM_100_FX;
1739 printf("xl%d: unknown XCVR type: %d\n", sc->xl_unit,
1742 * This will probably be wrong, but it prevents
1743 * the ifmedia code from panicking.
1745 media = IFM_ETHER|IFM_10_T;
1749 if (sc->xl_miibus == NULL)
1750 ifmedia_set(&sc->ifmedia, media);
1754 if (sc->xl_flags & XL_FLAG_NO_XCVR_PWR) {
1756 CSR_WRITE_2(sc, XL_W0_MFG_ID, XL_NO_XCVR_PWR_MAGICBITS);
1760 * Call MI attach routine.
1762 ether_ifattach(ifp, eaddr);
1765 * Tell the upper layer(s) we support long frames.
1767 ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
1769 /* Hook interrupt last to avoid having to lock softc */
1770 error = bus_setup_intr(dev, sc->xl_irq, INTR_TYPE_NET,
1771 xl_intr, sc, &sc->xl_intrhand);
1773 printf("xl%d: couldn't set up irq\n", unit);
1774 ether_ifdetach(ifp);
1788 * Shutdown hardware and free up resources. This can be called any
1789 * time after the mutex has been initialized. It is called in both
1790 * the error case in attach and the normal detach case so it needs
1791 * to be careful about only freeing resources that have actually been
1798 struct xl_softc *sc;
1805 sc = device_get_softc(dev);
1806 ifp = &sc->arpcom.ac_if;
1808 if (sc->xl_flags & XL_FLAG_USE_MMIO) {
1810 res = SYS_RES_MEMORY;
1813 res = SYS_RES_IOPORT;
1817 * Only try to communicate with the device if we were able to map
1818 * the ports. This flag is set before ether_ifattach() so it also
1819 * governs our call to ether_ifdetach().
1821 if (sc->xl_flags & XL_FLAG_ATTACH_MAPPED) {
1824 ether_ifdetach(ifp);
1828 device_delete_child(dev, sc->xl_miibus);
1829 bus_generic_detach(dev);
1830 ifmedia_removeall(&sc->ifmedia);
1832 if (sc->xl_intrhand)
1833 bus_teardown_intr(dev, sc->xl_irq, sc->xl_intrhand);
1835 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->xl_irq);
1836 if (sc->xl_fres != NULL)
1837 bus_release_resource(dev, SYS_RES_MEMORY,
1838 XL_PCI_FUNCMEM, sc->xl_fres);
1840 bus_release_resource(dev, res, rid, sc->xl_res);
1843 bus_dmamap_destroy(sc->xl_mtag, sc->xl_tmpmap);
1844 bus_dma_tag_destroy(sc->xl_mtag);
1846 if (sc->xl_ldata.xl_rx_tag) {
1847 bus_dmamap_unload(sc->xl_ldata.xl_rx_tag,
1848 sc->xl_ldata.xl_rx_dmamap);
1849 bus_dmamem_free(sc->xl_ldata.xl_rx_tag, sc->xl_ldata.xl_rx_list,
1850 sc->xl_ldata.xl_rx_dmamap);
1851 bus_dma_tag_destroy(sc->xl_ldata.xl_rx_tag);
1853 if (sc->xl_ldata.xl_tx_tag) {
1854 bus_dmamap_unload(sc->xl_ldata.xl_tx_tag,
1855 sc->xl_ldata.xl_tx_dmamap);
1856 bus_dmamem_free(sc->xl_ldata.xl_tx_tag, sc->xl_ldata.xl_tx_list,
1857 sc->xl_ldata.xl_tx_dmamap);
1858 bus_dma_tag_destroy(sc->xl_ldata.xl_tx_tag);
1867 * Initialize the transmit descriptors.
1871 struct xl_softc *sc;
1873 struct xl_chain_data *cd;
1874 struct xl_list_data *ld;
1879 for (i = 0; i < XL_TX_LIST_CNT; i++) {
1880 cd->xl_tx_chain[i].xl_ptr = &ld->xl_tx_list[i];
1881 error = bus_dmamap_create(sc->xl_mtag, 0,
1882 &cd->xl_tx_chain[i].xl_map);
1885 cd->xl_tx_chain[i].xl_phys = ld->xl_tx_dmaaddr +
1886 i * sizeof(struct xl_list);
1887 if (i == (XL_TX_LIST_CNT - 1))
1888 cd->xl_tx_chain[i].xl_next = NULL;
1890 cd->xl_tx_chain[i].xl_next = &cd->xl_tx_chain[i + 1];
1893 cd->xl_tx_free = &cd->xl_tx_chain[0];
1894 cd->xl_tx_tail = cd->xl_tx_head = NULL;
1896 bus_dmamap_sync(ld->xl_tx_tag, ld->xl_tx_dmamap, BUS_DMASYNC_PREWRITE);
1901 * Initialize the transmit descriptors.
1904 xl_list_tx_init_90xB(sc)
1905 struct xl_softc *sc;
1907 struct xl_chain_data *cd;
1908 struct xl_list_data *ld;
1913 for (i = 0; i < XL_TX_LIST_CNT; i++) {
1914 cd->xl_tx_chain[i].xl_ptr = &ld->xl_tx_list[i];
1915 error = bus_dmamap_create(sc->xl_mtag, 0,
1916 &cd->xl_tx_chain[i].xl_map);
1919 cd->xl_tx_chain[i].xl_phys = ld->xl_tx_dmaaddr +
1920 i * sizeof(struct xl_list);
1921 if (i == (XL_TX_LIST_CNT - 1))
1922 cd->xl_tx_chain[i].xl_next = &cd->xl_tx_chain[0];
1924 cd->xl_tx_chain[i].xl_next = &cd->xl_tx_chain[i + 1];
1926 cd->xl_tx_chain[i].xl_prev =
1927 &cd->xl_tx_chain[XL_TX_LIST_CNT - 1];
1929 cd->xl_tx_chain[i].xl_prev =
1930 &cd->xl_tx_chain[i - 1];
1933 bzero(ld->xl_tx_list, XL_TX_LIST_SZ);
1934 ld->xl_tx_list[0].xl_status = htole32(XL_TXSTAT_EMPTY);
1940 bus_dmamap_sync(ld->xl_tx_tag, ld->xl_tx_dmamap, BUS_DMASYNC_PREWRITE);
1945 * Initialize the RX descriptors and allocate mbufs for them. Note that
1946 * we arrange the descriptors in a closed ring, so that the last descriptor
1947 * points back to the first.
1951 struct xl_softc *sc;
1953 struct xl_chain_data *cd;
1954 struct xl_list_data *ld;
1961 for (i = 0; i < XL_RX_LIST_CNT; i++) {
1962 cd->xl_rx_chain[i].xl_ptr = &ld->xl_rx_list[i];
1963 error = bus_dmamap_create(sc->xl_mtag, 0,
1964 &cd->xl_rx_chain[i].xl_map);
1967 error = xl_newbuf(sc, &cd->xl_rx_chain[i]);
1970 if (i == (XL_RX_LIST_CNT - 1))
1974 nextptr = ld->xl_rx_dmaaddr +
1975 next * sizeof(struct xl_list_onefrag);
1976 cd->xl_rx_chain[i].xl_next = &cd->xl_rx_chain[next];
1977 ld->xl_rx_list[i].xl_next = htole32(nextptr);
1980 bus_dmamap_sync(ld->xl_rx_tag, ld->xl_rx_dmamap, BUS_DMASYNC_PREWRITE);
1981 cd->xl_rx_head = &cd->xl_rx_chain[0];
1987 * Initialize an RX descriptor and attach an MBUF cluster.
1988 * If we fail to do so, we need to leave the old mbuf and
1989 * the old DMA map untouched so that it can be reused.
1993 struct xl_softc *sc;
1994 struct xl_chain_onefrag *c;
1996 struct mbuf *m_new = NULL;
2001 m_new = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
2005 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
2007 /* Force longword alignment for packet payload. */
2008 m_adj(m_new, ETHER_ALIGN);
2010 error = bus_dmamap_load_mbuf(sc->xl_mtag, sc->xl_tmpmap, m_new,
2011 xl_dma_map_rxbuf, &baddr, BUS_DMA_NOWAIT);
2014 printf("xl%d: can't map mbuf (error %d)\n", sc->xl_unit, error);
2018 bus_dmamap_unload(sc->xl_mtag, c->xl_map);
2020 c->xl_map = sc->xl_tmpmap;
2021 sc->xl_tmpmap = map;
2023 c->xl_ptr->xl_frag.xl_len = htole32(m_new->m_len | XL_LAST_FRAG);
2024 c->xl_ptr->xl_status = 0;
2025 c->xl_ptr->xl_frag.xl_addr = htole32(baddr);
2026 bus_dmamap_sync(sc->xl_mtag, c->xl_map, BUS_DMASYNC_PREREAD);
2032 struct xl_softc *sc;
2034 struct xl_chain_onefrag *pos;
2037 pos = sc->xl_cdata.xl_rx_head;
2039 for (i = 0; i < XL_RX_LIST_CNT; i++) {
2040 if (pos->xl_ptr->xl_status)
2045 if (i == XL_RX_LIST_CNT)
2048 sc->xl_cdata.xl_rx_head = pos;
2054 * A frame has been uploaded: pass the resulting mbuf chain up to
2055 * the higher level protocols.
2059 struct xl_softc *sc;
2061 struct ether_header *eh;
2064 struct xl_chain_onefrag *cur_rx;
2068 ifp = &sc->arpcom.ac_if;
2072 bus_dmamap_sync(sc->xl_ldata.xl_rx_tag, sc->xl_ldata.xl_rx_dmamap,
2073 BUS_DMASYNC_POSTREAD);
2074 while((rxstat = le32toh(sc->xl_cdata.xl_rx_head->xl_ptr->xl_status))) {
2075 cur_rx = sc->xl_cdata.xl_rx_head;
2076 sc->xl_cdata.xl_rx_head = cur_rx->xl_next;
2077 total_len = rxstat & XL_RXSTAT_LENMASK;
2080 * Since we have told the chip to allow large frames,
2081 * we need to trap giant frame errors in software. We allow
2082 * a little more than the normal frame size to account for
2083 * frames with VLAN tags.
2085 if (total_len > XL_MAX_FRAMELEN)
2086 rxstat |= (XL_RXSTAT_UP_ERROR|XL_RXSTAT_OVERSIZE);
2089 * If an error occurs, update stats, clear the
2090 * status word and leave the mbuf cluster in place:
2091 * it should simply get re-used next time this descriptor
2092 * comes up in the ring.
2094 if (rxstat & XL_RXSTAT_UP_ERROR) {
2096 cur_rx->xl_ptr->xl_status = 0;
2097 bus_dmamap_sync(sc->xl_ldata.xl_rx_tag,
2098 sc->xl_ldata.xl_rx_dmamap, BUS_DMASYNC_PREWRITE);
2103 * If the error bit was not set, the upload complete
2104 * bit should be set which means we have a valid packet.
2105 * If not, something truly strange has happened.
2107 if (!(rxstat & XL_RXSTAT_UP_CMPLT)) {
2108 printf("xl%d: bad receive status -- "
2109 "packet dropped\n", sc->xl_unit);
2111 cur_rx->xl_ptr->xl_status = 0;
2112 bus_dmamap_sync(sc->xl_ldata.xl_rx_tag,
2113 sc->xl_ldata.xl_rx_dmamap, BUS_DMASYNC_PREWRITE);
2117 /* No errors; receive the packet. */
2118 bus_dmamap_sync(sc->xl_mtag, cur_rx->xl_map,
2119 BUS_DMASYNC_POSTREAD);
2120 m = cur_rx->xl_mbuf;
2123 * Try to conjure up a new mbuf cluster. If that
2124 * fails, it means we have an out of memory condition and
2125 * should leave the buffer in place and continue. This will
2126 * result in a lost packet, but there's little else we
2127 * can do in this situation.
2129 if (xl_newbuf(sc, cur_rx)) {
2131 cur_rx->xl_ptr->xl_status = 0;
2132 bus_dmamap_sync(sc->xl_ldata.xl_rx_tag,
2133 sc->xl_ldata.xl_rx_dmamap, BUS_DMASYNC_PREWRITE);
2136 bus_dmamap_sync(sc->xl_ldata.xl_rx_tag,
2137 sc->xl_ldata.xl_rx_dmamap, BUS_DMASYNC_PREWRITE);
2140 eh = mtod(m, struct ether_header *);
2141 m->m_pkthdr.rcvif = ifp;
2142 m->m_pkthdr.len = m->m_len = total_len;
2144 /* Remove header from mbuf and pass it on. */
2145 m_adj(m, sizeof(struct ether_header));
2147 if (ifp->if_capenable & IFCAP_RXCSUM) {
2148 /* Do IP checksum checking. */
2149 if (rxstat & XL_RXSTAT_IPCKOK)
2150 m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED;
2151 if (!(rxstat & XL_RXSTAT_IPCKERR))
2152 m->m_pkthdr.csum_flags |= CSUM_IP_VALID;
2153 if ((rxstat & XL_RXSTAT_TCPCOK &&
2154 !(rxstat & XL_RXSTAT_TCPCKERR)) ||
2155 (rxstat & XL_RXSTAT_UDPCKOK &&
2156 !(rxstat & XL_RXSTAT_UDPCKERR))) {
2157 m->m_pkthdr.csum_flags |=
2158 CSUM_DATA_VALID|CSUM_PSEUDO_HDR;
2159 m->m_pkthdr.csum_data = 0xffff;
2163 ether_input(ifp, eh, m);
2167 * Handle the 'end of channel' condition. When the upload
2168 * engine hits the end of the RX ring, it will stall. This
2169 * is our cue to flush the RX ring, reload the uplist pointer
2170 * register and unstall the engine.
2171 * XXX This is actually a little goofy. With the ThunderLAN
2172 * chip, you get an interrupt when the receiver hits the end
2173 * of the receive ring, which tells you exactly when you
2174 * you need to reload the ring pointer. Here we have to
2175 * fake it. I'm mad at myself for not being clever enough
2176 * to avoid the use of a goto here.
2178 if (CSR_READ_4(sc, XL_UPLIST_PTR) == 0 ||
2179 CSR_READ_4(sc, XL_UPLIST_STATUS) & XL_PKTSTAT_UP_STALLED) {
2180 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_UP_STALL);
2182 CSR_WRITE_4(sc, XL_UPLIST_PTR, sc->xl_ldata.xl_rx_dmaaddr);
2183 sc->xl_cdata.xl_rx_head = &sc->xl_cdata.xl_rx_chain[0];
2184 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_UP_UNSTALL);
2192 * A frame was downloaded to the chip. It's safe for us to clean up
2197 struct xl_softc *sc;
2199 struct xl_chain *cur_tx;
2202 ifp = &sc->arpcom.ac_if;
2204 /* Clear the timeout timer. */
2208 * Go through our tx list and free mbufs for those
2209 * frames that have been uploaded. Note: the 3c905B
2210 * sets a special bit in the status word to let us
2211 * know that a frame has been downloaded, but the
2212 * original 3c900/3c905 adapters don't do that.
2213 * Consequently, we have to use a different test if
2214 * xl_type != XL_TYPE_905B.
2216 while(sc->xl_cdata.xl_tx_head != NULL) {
2217 cur_tx = sc->xl_cdata.xl_tx_head;
2219 if (CSR_READ_4(sc, XL_DOWNLIST_PTR))
2222 sc->xl_cdata.xl_tx_head = cur_tx->xl_next;
2223 bus_dmamap_sync(sc->xl_mtag, cur_tx->xl_map,
2224 BUS_DMASYNC_POSTWRITE);
2225 bus_dmamap_unload(sc->xl_mtag, cur_tx->xl_map);
2226 m_freem(cur_tx->xl_mbuf);
2227 cur_tx->xl_mbuf = NULL;
2230 cur_tx->xl_next = sc->xl_cdata.xl_tx_free;
2231 sc->xl_cdata.xl_tx_free = cur_tx;
2234 if (sc->xl_cdata.xl_tx_head == NULL) {
2235 ifp->if_flags &= ~IFF_OACTIVE;
2236 sc->xl_cdata.xl_tx_tail = NULL;
2238 if (CSR_READ_4(sc, XL_DMACTL) & XL_DMACTL_DOWN_STALLED ||
2239 !CSR_READ_4(sc, XL_DOWNLIST_PTR)) {
2240 CSR_WRITE_4(sc, XL_DOWNLIST_PTR,
2241 sc->xl_cdata.xl_tx_head->xl_phys);
2242 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_DOWN_UNSTALL);
2251 struct xl_softc *sc;
2253 struct xl_chain *cur_tx = NULL;
2257 ifp = &sc->arpcom.ac_if;
2259 bus_dmamap_sync(sc->xl_ldata.xl_tx_tag, sc->xl_ldata.xl_tx_dmamap,
2260 BUS_DMASYNC_POSTREAD);
2261 idx = sc->xl_cdata.xl_tx_cons;
2262 while(idx != sc->xl_cdata.xl_tx_prod) {
2264 cur_tx = &sc->xl_cdata.xl_tx_chain[idx];
2266 if (!(le32toh(cur_tx->xl_ptr->xl_status) &
2267 XL_TXSTAT_DL_COMPLETE))
2270 if (cur_tx->xl_mbuf != NULL) {
2271 bus_dmamap_sync(sc->xl_mtag, cur_tx->xl_map,
2272 BUS_DMASYNC_POSTWRITE);
2273 bus_dmamap_unload(sc->xl_mtag, cur_tx->xl_map);
2274 m_freem(cur_tx->xl_mbuf);
2275 cur_tx->xl_mbuf = NULL;
2280 sc->xl_cdata.xl_tx_cnt--;
2281 XL_INC(idx, XL_TX_LIST_CNT);
2285 sc->xl_cdata.xl_tx_cons = idx;
2288 ifp->if_flags &= ~IFF_OACTIVE;
2294 * TX 'end of channel' interrupt handler. Actually, we should
2295 * only get a 'TX complete' interrupt if there's a transmit error,
2296 * so this is really TX error handler.
2300 struct xl_softc *sc;
2304 while((txstat = CSR_READ_1(sc, XL_TX_STATUS))) {
2305 if (txstat & XL_TXSTATUS_UNDERRUN ||
2306 txstat & XL_TXSTATUS_JABBER ||
2307 txstat & XL_TXSTATUS_RECLAIM) {
2308 printf("xl%d: transmission error: %x\n",
2309 sc->xl_unit, txstat);
2310 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_TX_RESET);
2312 if (sc->xl_type == XL_TYPE_905B) {
2313 if (sc->xl_cdata.xl_tx_cnt) {
2316 i = sc->xl_cdata.xl_tx_cons;
2317 c = &sc->xl_cdata.xl_tx_chain[i];
2318 CSR_WRITE_4(sc, XL_DOWNLIST_PTR,
2320 CSR_WRITE_1(sc, XL_DOWN_POLL, 64);
2323 if (sc->xl_cdata.xl_tx_head != NULL)
2324 CSR_WRITE_4(sc, XL_DOWNLIST_PTR,
2325 sc->xl_cdata.xl_tx_head->xl_phys);
2328 * Remember to set this for the
2329 * first generation 3c90X chips.
2331 CSR_WRITE_1(sc, XL_TX_FREETHRESH, XL_PACKET_SIZE >> 8);
2332 if (txstat & XL_TXSTATUS_UNDERRUN &&
2333 sc->xl_tx_thresh < XL_PACKET_SIZE) {
2334 sc->xl_tx_thresh += XL_MIN_FRAMELEN;
2335 printf("xl%d: tx underrun, increasing tx start"
2336 " threshold to %d bytes\n", sc->xl_unit,
2339 CSR_WRITE_2(sc, XL_COMMAND,
2340 XL_CMD_TX_SET_START|sc->xl_tx_thresh);
2341 if (sc->xl_type == XL_TYPE_905B) {
2342 CSR_WRITE_2(sc, XL_COMMAND,
2343 XL_CMD_SET_TX_RECLAIM|(XL_PACKET_SIZE >> 4));
2345 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_TX_ENABLE);
2346 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_DOWN_UNSTALL);
2348 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_TX_ENABLE);
2349 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_DOWN_UNSTALL);
2352 * Write an arbitrary byte to the TX_STATUS register
2353 * to clear this interrupt/error and advance to the next.
2355 CSR_WRITE_1(sc, XL_TX_STATUS, 0x01);
2365 struct xl_softc *sc;
2370 ifp = &sc->arpcom.ac_if;
2372 while((status = CSR_READ_2(sc, XL_STATUS)) & XL_INTRS && status != 0xFFFF) {
2374 CSR_WRITE_2(sc, XL_COMMAND,
2375 XL_CMD_INTR_ACK|(status & XL_INTRS));
2377 if (status & XL_STAT_UP_COMPLETE) {
2380 curpkts = ifp->if_ipackets;
2382 if (curpkts == ifp->if_ipackets) {
2383 while (xl_rx_resync(sc))
2388 if (status & XL_STAT_DOWN_COMPLETE) {
2389 if (sc->xl_type == XL_TYPE_905B)
2395 if (status & XL_STAT_TX_COMPLETE) {
2400 if (status & XL_STAT_ADFAIL) {
2405 if (status & XL_STAT_STATSOFLOW) {
2406 sc->xl_stats_no_timeout = 1;
2407 xl_stats_update(sc);
2408 sc->xl_stats_no_timeout = 0;
2412 if (ifp->if_snd.ifq_head != NULL)
2413 (*ifp->if_start)(ifp);
2419 xl_stats_update(xsc)
2422 struct xl_softc *sc;
2424 struct xl_stats xl_stats;
2427 struct mii_data *mii = NULL;
2429 bzero((char *)&xl_stats, sizeof(struct xl_stats));
2432 ifp = &sc->arpcom.ac_if;
2433 if (sc->xl_miibus != NULL)
2434 mii = device_get_softc(sc->xl_miibus);
2436 p = (u_int8_t *)&xl_stats;
2438 /* Read all the stats registers. */
2441 for (i = 0; i < 16; i++)
2442 *p++ = CSR_READ_1(sc, XL_W6_CARRIER_LOST + i);
2444 ifp->if_ierrors += xl_stats.xl_rx_overrun;
2446 ifp->if_collisions += xl_stats.xl_tx_multi_collision +
2447 xl_stats.xl_tx_single_collision +
2448 xl_stats.xl_tx_late_collision;
2451 * Boomerang and cyclone chips have an extra stats counter
2452 * in window 4 (BadSSD). We have to read this too in order
2453 * to clear out all the stats registers and avoid a statsoflow
2457 CSR_READ_1(sc, XL_W4_BADSSD);
2459 if ((mii != NULL) && (!sc->xl_stats_no_timeout))
2464 if (!sc->xl_stats_no_timeout)
2465 sc->xl_stat_ch = timeout(xl_stats_update, sc, hz);
2471 * Encapsulate an mbuf chain in a descriptor by coupling the mbuf data
2472 * pointers to the fragment pointers.
2475 xl_encap(sc, c, m_head)
2476 struct xl_softc *sc;
2478 struct mbuf *m_head;
2484 ifp = &sc->arpcom.ac_if;
2487 * Start packing the mbufs in this chain into
2488 * the fragment pointers. Stop when we run out
2489 * of fragments or hit the end of the mbuf chain.
2491 error = bus_dmamap_load_mbuf(sc->xl_mtag, c->xl_map, m_head,
2492 xl_dma_map_txbuf, c->xl_ptr, BUS_DMA_NOWAIT);
2494 if (error && error != EFBIG) {
2496 printf("xl%d: can't map mbuf (error %d)\n", sc->xl_unit, error);
2501 * Handle special case: we used up all 63 fragments,
2502 * but we have more mbufs left in the chain. Copy the
2503 * data into an mbuf cluster. Note that we don't
2504 * bother clearing the values in the other fragment
2505 * pointers/counters; it wouldn't gain us anything,
2506 * and would waste cycles.
2511 m_new = m_defrag(m_head, M_DONTWAIT);
2512 if (m_new == NULL) {
2519 error = bus_dmamap_load_mbuf(sc->xl_mtag, c->xl_map,
2520 m_head, xl_dma_map_txbuf, c->xl_ptr, BUS_DMA_NOWAIT);
2523 printf("xl%d: can't map mbuf (error %d)\n",
2524 sc->xl_unit, error);
2529 if (sc->xl_type == XL_TYPE_905B) {
2530 status = XL_TXSTAT_RND_DEFEAT;
2532 if (m_head->m_pkthdr.csum_flags) {
2533 if (m_head->m_pkthdr.csum_flags & CSUM_IP)
2534 status |= XL_TXSTAT_IPCKSUM;
2535 if (m_head->m_pkthdr.csum_flags & CSUM_TCP)
2536 status |= XL_TXSTAT_TCPCKSUM;
2537 if (m_head->m_pkthdr.csum_flags & CSUM_UDP)
2538 status |= XL_TXSTAT_UDPCKSUM;
2540 c->xl_ptr->xl_status = htole32(status);
2543 c->xl_mbuf = m_head;
2544 bus_dmamap_sync(sc->xl_mtag, c->xl_map, BUS_DMASYNC_PREWRITE);
2549 * Main transmit routine. To avoid having to do mbuf copies, we put pointers
2550 * to the mbuf data regions directly in the transmit lists. We also save a
2551 * copy of the pointers since the transmit list fragment pointers are
2552 * physical addresses.
2558 struct xl_softc *sc;
2559 struct mbuf *m_head = NULL;
2560 struct xl_chain *prev = NULL, *cur_tx = NULL, *start_tx;
2561 struct xl_chain *prev_tx;
2567 * Check for an available queue slot. If there are none,
2570 if (sc->xl_cdata.xl_tx_free == NULL) {
2573 if (sc->xl_cdata.xl_tx_free == NULL) {
2574 ifp->if_flags |= IFF_OACTIVE;
2579 start_tx = sc->xl_cdata.xl_tx_free;
2581 while(sc->xl_cdata.xl_tx_free != NULL) {
2582 IF_DEQUEUE(&ifp->if_snd, m_head);
2586 /* Pick a descriptor off the free list. */
2588 cur_tx = sc->xl_cdata.xl_tx_free;
2590 /* Pack the data into the descriptor. */
2591 error = xl_encap(sc, cur_tx, m_head);
2597 sc->xl_cdata.xl_tx_free = cur_tx->xl_next;
2598 cur_tx->xl_next = NULL;
2600 /* Chain it together. */
2602 prev->xl_next = cur_tx;
2603 prev->xl_ptr->xl_next = htole32(cur_tx->xl_phys);
2608 * If there's a BPF listener, bounce a copy of this frame
2612 bpf_mtap(ifp, cur_tx->xl_mbuf);
2616 * If there are no packets queued, bail.
2618 if (cur_tx == NULL) {
2623 * Place the request for the upload interrupt
2624 * in the last descriptor in the chain. This way, if
2625 * we're chaining several packets at once, we'll only
2626 * get an interupt once for the whole chain rather than
2627 * once for each packet.
2629 cur_tx->xl_ptr->xl_status = htole32(le32toh(cur_tx->xl_ptr->xl_status) |
2631 bus_dmamap_sync(sc->xl_ldata.xl_tx_tag, sc->xl_ldata.xl_tx_dmamap,
2632 BUS_DMASYNC_PREWRITE);
2635 * Queue the packets. If the TX channel is clear, update
2636 * the downlist pointer register.
2638 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_DOWN_STALL);
2641 if (sc->xl_cdata.xl_tx_head != NULL) {
2642 sc->xl_cdata.xl_tx_tail->xl_next = start_tx;
2643 sc->xl_cdata.xl_tx_tail->xl_ptr->xl_next =
2644 htole32(start_tx->xl_phys);
2645 status = sc->xl_cdata.xl_tx_tail->xl_ptr->xl_status;
2646 sc->xl_cdata.xl_tx_tail->xl_ptr->xl_status =
2647 htole32(le32toh(status) & ~XL_TXSTAT_DL_INTR);
2648 sc->xl_cdata.xl_tx_tail = cur_tx;
2650 sc->xl_cdata.xl_tx_head = start_tx;
2651 sc->xl_cdata.xl_tx_tail = cur_tx;
2653 if (!CSR_READ_4(sc, XL_DOWNLIST_PTR))
2654 CSR_WRITE_4(sc, XL_DOWNLIST_PTR, start_tx->xl_phys);
2656 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_DOWN_UNSTALL);
2661 * Set a timeout in case the chip goes out to lunch.
2666 * XXX Under certain conditions, usually on slower machines
2667 * where interrupts may be dropped, it's possible for the
2668 * adapter to chew up all the buffers in the receive ring
2669 * and stall, without us being able to do anything about it.
2670 * To guard against this, we need to make a pass over the
2671 * RX queue to make sure there aren't any packets pending.
2672 * Doing it here means we can flush the receive ring at the
2673 * same time the chip is DMAing the transmit descriptors we
2676 * 3Com goes to some lengths to emphasize the Parallel Tasking (tm)
2677 * nature of their chips in all their marketing literature;
2678 * we may as well take advantage of it. :)
2689 struct xl_softc *sc;
2690 struct mbuf *m_head = NULL;
2691 struct xl_chain *prev = NULL, *cur_tx = NULL, *start_tx;
2692 struct xl_chain *prev_tx;
2697 if (ifp->if_flags & IFF_OACTIVE) {
2701 idx = sc->xl_cdata.xl_tx_prod;
2702 start_tx = &sc->xl_cdata.xl_tx_chain[idx];
2704 while (sc->xl_cdata.xl_tx_chain[idx].xl_mbuf == NULL) {
2706 if ((XL_TX_LIST_CNT - sc->xl_cdata.xl_tx_cnt) < 3) {
2707 ifp->if_flags |= IFF_OACTIVE;
2711 IF_DEQUEUE(&ifp->if_snd, m_head);
2716 cur_tx = &sc->xl_cdata.xl_tx_chain[idx];
2718 /* Pack the data into the descriptor. */
2719 error = xl_encap(sc, cur_tx, m_head);
2725 /* Chain it together. */
2727 prev->xl_ptr->xl_next = htole32(cur_tx->xl_phys);
2731 * If there's a BPF listener, bounce a copy of this frame
2735 bpf_mtap(ifp, cur_tx->xl_mbuf);
2737 XL_INC(idx, XL_TX_LIST_CNT);
2738 sc->xl_cdata.xl_tx_cnt++;
2742 * If there are no packets queued, bail.
2744 if (cur_tx == NULL) {
2749 * Place the request for the upload interrupt
2750 * in the last descriptor in the chain. This way, if
2751 * we're chaining several packets at once, we'll only
2752 * get an interupt once for the whole chain rather than
2753 * once for each packet.
2755 cur_tx->xl_ptr->xl_status = htole32(le32toh(cur_tx->xl_ptr->xl_status) |
2757 bus_dmamap_sync(sc->xl_ldata.xl_tx_tag, sc->xl_ldata.xl_tx_dmamap,
2758 BUS_DMASYNC_PREWRITE);
2760 /* Start transmission */
2761 sc->xl_cdata.xl_tx_prod = idx;
2762 start_tx->xl_prev->xl_ptr->xl_next = htole32(start_tx->xl_phys);
2765 * Set a timeout in case the chip goes out to lunch.
2776 struct xl_softc *sc = xsc;
2777 struct ifnet *ifp = &sc->arpcom.ac_if;
2779 u_int16_t rxfilt = 0;
2780 struct mii_data *mii = NULL;
2786 * Cancel pending I/O and free all RX/TX buffers.
2790 if (sc->xl_miibus == NULL) {
2791 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_RESET);
2794 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_TX_RESET);
2798 if (sc->xl_miibus != NULL)
2799 mii = device_get_softc(sc->xl_miibus);
2801 /* Init our MAC address */
2803 for (i = 0; i < ETHER_ADDR_LEN; i++) {
2804 CSR_WRITE_1(sc, XL_W2_STATION_ADDR_LO + i,
2805 sc->arpcom.ac_enaddr[i]);
2808 /* Clear the station mask. */
2809 for (i = 0; i < 3; i++)
2810 CSR_WRITE_2(sc, XL_W2_STATION_MASK_LO + (i * 2), 0);
2812 /* Reset TX and RX. */
2813 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_RESET);
2815 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_TX_RESET);
2818 /* Init circular RX list. */
2819 error = xl_list_rx_init(sc);
2821 printf("xl%d: initialization of the rx ring failed (%d)\n",
2822 sc->xl_unit, error);
2828 /* Init TX descriptors. */
2829 if (sc->xl_type == XL_TYPE_905B)
2830 error = xl_list_tx_init_90xB(sc);
2832 error = xl_list_tx_init(sc);
2834 printf("xl%d: initialization of the tx ring failed (%d)\n",
2835 sc->xl_unit, error);
2841 * Set the TX freethresh value.
2842 * Note that this has no effect on 3c905B "cyclone"
2843 * cards but is required for 3c900/3c905 "boomerang"
2844 * cards in order to enable the download engine.
2846 CSR_WRITE_1(sc, XL_TX_FREETHRESH, XL_PACKET_SIZE >> 8);
2848 /* Set the TX start threshold for best performance. */
2849 sc->xl_tx_thresh = XL_MIN_FRAMELEN;
2850 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_TX_SET_START|sc->xl_tx_thresh);
2853 * If this is a 3c905B, also set the tx reclaim threshold.
2854 * This helps cut down on the number of tx reclaim errors
2855 * that could happen on a busy network. The chip multiplies
2856 * the register value by 16 to obtain the actual threshold
2857 * in bytes, so we divide by 16 when setting the value here.
2858 * The existing threshold value can be examined by reading
2859 * the register at offset 9 in window 5.
2861 if (sc->xl_type == XL_TYPE_905B) {
2862 CSR_WRITE_2(sc, XL_COMMAND,
2863 XL_CMD_SET_TX_RECLAIM|(XL_PACKET_SIZE >> 4));
2866 /* Set RX filter bits. */
2868 rxfilt = CSR_READ_1(sc, XL_W5_RX_FILTER);
2870 /* Set the individual bit to receive frames for this host only. */
2871 rxfilt |= XL_RXFILTER_INDIVIDUAL;
2873 /* If we want promiscuous mode, set the allframes bit. */
2874 if (ifp->if_flags & IFF_PROMISC) {
2875 rxfilt |= XL_RXFILTER_ALLFRAMES;
2876 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_SET_FILT|rxfilt);
2878 rxfilt &= ~XL_RXFILTER_ALLFRAMES;
2879 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_SET_FILT|rxfilt);
2883 * Set capture broadcast bit to capture broadcast frames.
2885 if (ifp->if_flags & IFF_BROADCAST) {
2886 rxfilt |= XL_RXFILTER_BROADCAST;
2887 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_SET_FILT|rxfilt);
2889 rxfilt &= ~XL_RXFILTER_BROADCAST;
2890 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_SET_FILT|rxfilt);
2894 * Program the multicast filter, if necessary.
2896 if (sc->xl_type == XL_TYPE_905B)
2897 xl_setmulti_hash(sc);
2902 * Load the address of the RX list. We have to
2903 * stall the upload engine before we can manipulate
2904 * the uplist pointer register, then unstall it when
2905 * we're finished. We also have to wait for the
2906 * stall command to complete before proceeding.
2907 * Note that we have to do this after any RX resets
2908 * have completed since the uplist register is cleared
2911 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_UP_STALL);
2913 CSR_WRITE_4(sc, XL_UPLIST_PTR, sc->xl_ldata.xl_rx_dmaaddr);
2914 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_UP_UNSTALL);
2918 if (sc->xl_type == XL_TYPE_905B) {
2919 /* Set polling interval */
2920 CSR_WRITE_1(sc, XL_DOWN_POLL, 64);
2921 /* Load the address of the TX list */
2922 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_DOWN_STALL);
2924 CSR_WRITE_4(sc, XL_DOWNLIST_PTR,
2925 sc->xl_cdata.xl_tx_chain[0].xl_phys);
2926 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_DOWN_UNSTALL);
2931 * If the coax transceiver is on, make sure to enable
2932 * the DC-DC converter.
2935 if (sc->xl_xcvr == XL_XCVR_COAX)
2936 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_COAX_START);
2938 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_COAX_STOP);
2941 * increase packet size to allow reception of 802.1q or ISL packets.
2942 * For the 3c90x chip, set the 'allow large packets' bit in the MAC
2943 * control register. For 3c90xB/C chips, use the RX packet size
2947 if (sc->xl_type == XL_TYPE_905B)
2948 CSR_WRITE_2(sc, XL_W3_MAXPKTSIZE, XL_PACKET_SIZE);
2951 macctl = CSR_READ_1(sc, XL_W3_MAC_CTRL);
2952 macctl |= XL_MACCTRL_ALLOW_LARGE_PACK;
2953 CSR_WRITE_1(sc, XL_W3_MAC_CTRL, macctl);
2956 /* Clear out the stats counters. */
2957 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_STATS_DISABLE);
2958 sc->xl_stats_no_timeout = 1;
2959 xl_stats_update(sc);
2960 sc->xl_stats_no_timeout = 0;
2962 CSR_WRITE_2(sc, XL_W4_NET_DIAG, XL_NETDIAG_UPPER_BYTES_ENABLE);
2963 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_STATS_ENABLE);
2966 * Enable interrupts.
2968 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_INTR_ACK|0xFF);
2969 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_STAT_ENB|XL_INTRS);
2970 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_INTR_ENB|XL_INTRS);
2971 if (sc->xl_flags & XL_FLAG_FUNCREG)
2972 bus_space_write_4(sc->xl_ftag, sc->xl_fhandle, 4, 0x8000);
2974 /* Set the RX early threshold */
2975 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_SET_THRESH|(XL_PACKET_SIZE >>2));
2976 CSR_WRITE_2(sc, XL_DMACTL, XL_DMACTL_UP_RX_EARLY);
2978 /* Enable receiver and transmitter. */
2979 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_TX_ENABLE);
2981 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_ENABLE);
2987 /* Select window 7 for normal operations. */
2990 ifp->if_flags |= IFF_RUNNING;
2991 ifp->if_flags &= ~IFF_OACTIVE;
2993 sc->xl_stat_ch = timeout(xl_stats_update, sc, hz);
3001 * Set media options.
3007 struct xl_softc *sc;
3008 struct ifmedia *ifm = NULL;
3009 struct mii_data *mii = NULL;
3012 if (sc->xl_miibus != NULL)
3013 mii = device_get_softc(sc->xl_miibus);
3017 ifm = &mii->mii_media;
3019 switch(IFM_SUBTYPE(ifm->ifm_media)) {
3024 xl_setmode(sc, ifm->ifm_media);
3031 if (sc->xl_media & XL_MEDIAOPT_MII || sc->xl_media & XL_MEDIAOPT_BTX
3032 || sc->xl_media & XL_MEDIAOPT_BT4) {
3035 xl_setmode(sc, ifm->ifm_media);
3042 * Report current media status.
3045 xl_ifmedia_sts(ifp, ifmr)
3047 struct ifmediareq *ifmr;
3049 struct xl_softc *sc;
3051 struct mii_data *mii = NULL;
3054 if (sc->xl_miibus != NULL)
3055 mii = device_get_softc(sc->xl_miibus);
3058 icfg = CSR_READ_4(sc, XL_W3_INTERNAL_CFG) & XL_ICFG_CONNECTOR_MASK;
3059 icfg >>= XL_ICFG_CONNECTOR_BITS;
3061 ifmr->ifm_active = IFM_ETHER;
3065 ifmr->ifm_active = IFM_ETHER|IFM_10_T;
3066 if (CSR_READ_1(sc, XL_W3_MAC_CTRL) & XL_MACCTRL_DUPLEX)
3067 ifmr->ifm_active |= IFM_FDX;
3069 ifmr->ifm_active |= IFM_HDX;
3072 if (sc->xl_type == XL_TYPE_905B &&
3073 sc->xl_media == XL_MEDIAOPT_10FL) {
3074 ifmr->ifm_active = IFM_ETHER|IFM_10_FL;
3075 if (CSR_READ_1(sc, XL_W3_MAC_CTRL) & XL_MACCTRL_DUPLEX)
3076 ifmr->ifm_active |= IFM_FDX;
3078 ifmr->ifm_active |= IFM_HDX;
3080 ifmr->ifm_active = IFM_ETHER|IFM_10_5;
3083 ifmr->ifm_active = IFM_ETHER|IFM_10_2;
3086 * XXX MII and BTX/AUTO should be separate cases.
3089 case XL_XCVR_100BTX:
3094 ifmr->ifm_active = mii->mii_media_active;
3095 ifmr->ifm_status = mii->mii_media_status;
3098 case XL_XCVR_100BFX:
3099 ifmr->ifm_active = IFM_ETHER|IFM_100_FX;
3102 printf("xl%d: unknown XCVR type: %d\n", sc->xl_unit, icfg);
3110 xl_ioctl(ifp, command, data)
3115 struct xl_softc *sc = ifp->if_softc;
3116 struct ifreq *ifr = (struct ifreq *) data;
3118 struct mii_data *mii = NULL;
3128 error = ether_ioctl(ifp, command, data);
3132 rxfilt = CSR_READ_1(sc, XL_W5_RX_FILTER);
3133 if (ifp->if_flags & IFF_UP) {
3134 if (ifp->if_flags & IFF_RUNNING &&
3135 ifp->if_flags & IFF_PROMISC &&
3136 !(sc->xl_if_flags & IFF_PROMISC)) {
3137 rxfilt |= XL_RXFILTER_ALLFRAMES;
3138 CSR_WRITE_2(sc, XL_COMMAND,
3139 XL_CMD_RX_SET_FILT|rxfilt);
3141 } else if (ifp->if_flags & IFF_RUNNING &&
3142 !(ifp->if_flags & IFF_PROMISC) &&
3143 sc->xl_if_flags & IFF_PROMISC) {
3144 rxfilt &= ~XL_RXFILTER_ALLFRAMES;
3145 CSR_WRITE_2(sc, XL_COMMAND,
3146 XL_CMD_RX_SET_FILT|rxfilt);
3151 if (ifp->if_flags & IFF_RUNNING)
3154 sc->xl_if_flags = ifp->if_flags;
3159 if (sc->xl_type == XL_TYPE_905B)
3160 xl_setmulti_hash(sc);
3167 if (sc->xl_miibus != NULL)
3168 mii = device_get_softc(sc->xl_miibus);
3170 error = ifmedia_ioctl(ifp, ifr,
3171 &sc->ifmedia, command);
3173 error = ifmedia_ioctl(ifp, ifr,
3174 &mii->mii_media, command);
3177 ifp->if_capenable = ifr->ifr_reqcap;
3178 if (ifp->if_capenable & IFCAP_TXCSUM)
3179 ifp->if_hwassist = XL905B_CSUM_FEATURES;
3181 ifp->if_hwassist = 0;
3196 struct xl_softc *sc;
3197 u_int16_t status = 0;
3203 status = CSR_READ_2(sc, XL_W4_MEDIA_STATUS);
3204 printf("xl%d: watchdog timeout\n", sc->xl_unit);
3206 if (status & XL_MEDIASTAT_CARRIER)
3207 printf("xl%d: no carrier - transceiver cable problem?\n",
3215 if (ifp->if_snd.ifq_head != NULL)
3216 (*ifp->if_start)(ifp);
3222 * Stop the adapter and free any mbufs allocated to the
3227 struct xl_softc *sc;
3232 ifp = &sc->arpcom.ac_if;
3235 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_DISABLE);
3236 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_STATS_DISABLE);
3237 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_INTR_ENB);
3238 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_DISCARD);
3240 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_TX_DISABLE);
3241 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_COAX_STOP);
3245 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_RX_RESET);
3247 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_TX_RESET);
3251 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_INTR_ACK|XL_STAT_INTLATCH);
3252 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_STAT_ENB|0);
3253 CSR_WRITE_2(sc, XL_COMMAND, XL_CMD_INTR_ENB|0);
3254 if (sc->xl_flags & XL_FLAG_FUNCREG) bus_space_write_4 (sc->xl_ftag, sc->xl_fhandle, 4, 0x8000);
3256 /* Stop the stats updater. */
3257 untimeout(xl_stats_update, sc, sc->xl_stat_ch);
3260 * Free data in the RX lists.
3262 for (i = 0; i < XL_RX_LIST_CNT; i++) {
3263 if (sc->xl_cdata.xl_rx_chain[i].xl_mbuf != NULL) {
3264 bus_dmamap_unload(sc->xl_mtag,
3265 sc->xl_cdata.xl_rx_chain[i].xl_map);
3266 bus_dmamap_destroy(sc->xl_mtag,
3267 sc->xl_cdata.xl_rx_chain[i].xl_map);
3268 m_freem(sc->xl_cdata.xl_rx_chain[i].xl_mbuf);
3269 sc->xl_cdata.xl_rx_chain[i].xl_mbuf = NULL;
3272 bzero(sc->xl_ldata.xl_rx_list, XL_RX_LIST_SZ);
3274 * Free the TX list buffers.
3276 for (i = 0; i < XL_TX_LIST_CNT; i++) {
3277 if (sc->xl_cdata.xl_tx_chain[i].xl_mbuf != NULL) {
3278 bus_dmamap_unload(sc->xl_mtag,
3279 sc->xl_cdata.xl_tx_chain[i].xl_map);
3280 bus_dmamap_destroy(sc->xl_mtag,
3281 sc->xl_cdata.xl_tx_chain[i].xl_map);
3282 m_freem(sc->xl_cdata.xl_tx_chain[i].xl_mbuf);
3283 sc->xl_cdata.xl_tx_chain[i].xl_mbuf = NULL;
3286 bzero(sc->xl_ldata.xl_tx_list, XL_TX_LIST_SZ);
3288 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
3294 * Stop all chip I/O so that the kernel's probe routines don't
3295 * get confused by errant DMAs when rebooting.
3301 struct xl_softc *sc;
3303 sc = device_get_softc(dev);
3315 struct xl_softc *sc;
3320 sc = device_get_softc(dev);
3333 struct xl_softc *sc;
3339 sc = device_get_softc(dev);
3340 ifp = &sc->arpcom.ac_if;
3343 if (ifp->if_flags & IFF_UP)