1 /* $OpenBSD: if_sk.c,v 2.33 2003/08/12 05:23:06 nate Exp $ */
4 * Copyright (c) 1997, 1998, 1999, 2000
5 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Bill Paul.
18 * 4. Neither the name of the author nor the names of any co-contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
35 * Copyright (c) 2003 Nathan L. Binkert <binkertn@umich.edu>
37 * Permission to use, copy, modify, and distribute this software for any
38 * purpose with or without fee is hereby granted, provided that the above
39 * copyright notice and this permission notice appear in all copies.
41 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
42 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
43 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
44 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
45 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
46 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
47 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
50 #include <sys/cdefs.h>
51 __FBSDID("$FreeBSD$");
54 * SysKonnect SK-NET gigabit ethernet driver for FreeBSD. Supports
55 * the SK-984x series adapters, both single port and dual port.
57 * The XaQti XMAC II datasheet,
58 * http://www.freebsd.org/~wpaul/SysKonnect/xmacii_datasheet_rev_c_9-29.pdf
59 * The SysKonnect GEnesis manual, http://www.syskonnect.com
61 * Note: XaQti has been aquired by Vitesse, and Vitesse does not have the
62 * XMAC II datasheet online. I have put my copy at people.freebsd.org as a
63 * convenience to others until Vitesse corrects this problem:
65 * http://people.freebsd.org/~wpaul/SysKonnect/xmacii_datasheet_rev_c_9-29.pdf
67 * Written by Bill Paul <wpaul@ee.columbia.edu>
68 * Department of Electrical Engineering
69 * Columbia University, New York City
72 * The SysKonnect gigabit ethernet adapters consist of two main
73 * components: the SysKonnect GEnesis controller chip and the XaQti Corp.
74 * XMAC II gigabit ethernet MAC. The XMAC provides all of the MAC
75 * components and a PHY while the GEnesis controller provides a PCI
76 * interface with DMA support. Each card may have between 512K and
77 * 2MB of SRAM on board depending on the configuration.
79 * The SysKonnect GEnesis controller can have either one or two XMAC
80 * chips connected to it, allowing single or dual port NIC configurations.
81 * SysKonnect has the distinction of being the only vendor on the market
82 * with a dual port gigabit ethernet NIC. The GEnesis provides dual FIFOs,
83 * dual DMA queues, packet/MAC/transmit arbiters and direct access to the
84 * XMAC registers. This driver takes advantage of these features to allow
85 * both XMACs to operate as independent interfaces.
88 #include <sys/param.h>
89 #include <sys/systm.h>
90 #include <sys/sockio.h>
92 #include <sys/malloc.h>
93 #include <sys/kernel.h>
94 #include <sys/module.h>
95 #include <sys/socket.h>
96 #include <sys/queue.h>
97 #include <sys/sysctl.h>
100 #include <net/if_arp.h>
101 #include <net/ethernet.h>
102 #include <net/if_dl.h>
103 #include <net/if_media.h>
107 #include <vm/vm.h> /* for vtophys */
108 #include <vm/pmap.h> /* for vtophys */
109 #include <machine/bus_pio.h>
110 #include <machine/bus_memio.h>
111 #include <machine/bus.h>
112 #include <machine/resource.h>
114 #include <sys/rman.h>
116 #include <dev/mii/mii.h>
117 #include <dev/mii/miivar.h>
118 #include <dev/mii/brgphyreg.h>
120 #include <dev/pci/pcireg.h>
121 #include <dev/pci/pcivar.h>
124 #define SK_USEIOSPACE
127 #include <pci/if_skreg.h>
128 #include <pci/xmaciireg.h>
129 #include <pci/yukonreg.h>
131 MODULE_DEPEND(sk, pci, 1, 1, 1);
132 MODULE_DEPEND(sk, ether, 1, 1, 1);
133 MODULE_DEPEND(sk, miibus, 1, 1, 1);
135 /* "controller miibus0" required. See GENERIC if you get errors here. */
136 #include "miibus_if.h"
139 static const char rcsid[] =
143 static struct sk_type sk_devs[] = {
147 "SysKonnect Gigabit Ethernet (V1.0)"
152 "SysKonnect Gigabit Ethernet (V2.0)"
157 "Marvell Gigabit Ethernet"
161 DEVICEID_BELKIN_5005,
162 "Belkin F5D5005 Gigabit Ethernet"
167 "3Com 3C940 Gigabit Ethernet"
171 DEVICEID_LINKSYS_EG1032,
172 "Linksys EG1032 Gigabit Ethernet"
176 DEVICEID_DLINK_DGE530T,
177 "D-Link DGE-530T Gigabit Ethernet"
182 static int skc_probe(device_t);
183 static int skc_attach(device_t);
184 static int skc_detach(device_t);
185 static void skc_shutdown(device_t);
186 static int sk_detach(device_t);
187 static int sk_probe(device_t);
188 static int sk_attach(device_t);
189 static void sk_tick(void *);
190 static void sk_intr(void *);
191 static void sk_intr_xmac(struct sk_if_softc *);
192 static void sk_intr_bcom(struct sk_if_softc *);
193 static void sk_intr_yukon(struct sk_if_softc *);
194 static void sk_rxeof(struct sk_if_softc *);
195 static void sk_txeof(struct sk_if_softc *);
196 static int sk_encap(struct sk_if_softc *, struct mbuf *,
198 static void sk_start(struct ifnet *);
199 static int sk_ioctl(struct ifnet *, u_long, caddr_t);
200 static void sk_init(void *);
201 static void sk_init_xmac(struct sk_if_softc *);
202 static void sk_init_yukon(struct sk_if_softc *);
203 static void sk_stop(struct sk_if_softc *);
204 static void sk_watchdog(struct ifnet *);
205 static int sk_ifmedia_upd(struct ifnet *);
206 static void sk_ifmedia_sts(struct ifnet *, struct ifmediareq *);
207 static void sk_reset(struct sk_softc *);
208 static int sk_newbuf(struct sk_if_softc *,
209 struct sk_chain *, struct mbuf *);
210 static int sk_alloc_jumbo_mem(struct sk_if_softc *);
211 static void sk_free_jumbo_mem(struct sk_if_softc *);
212 static void *sk_jalloc(struct sk_if_softc *);
213 static void sk_jfree(void *, void *);
214 static int sk_init_rx_ring(struct sk_if_softc *);
215 static void sk_init_tx_ring(struct sk_if_softc *);
216 static u_int32_t sk_win_read_4(struct sk_softc *, int);
217 static u_int16_t sk_win_read_2(struct sk_softc *, int);
218 static u_int8_t sk_win_read_1(struct sk_softc *, int);
219 static void sk_win_write_4(struct sk_softc *, int, u_int32_t);
220 static void sk_win_write_2(struct sk_softc *, int, u_int32_t);
221 static void sk_win_write_1(struct sk_softc *, int, u_int32_t);
222 static u_int8_t sk_vpd_readbyte(struct sk_softc *, int);
223 static void sk_vpd_read_res(struct sk_softc *, struct vpd_res *, int);
224 static void sk_vpd_read(struct sk_softc *);
226 static int sk_miibus_readreg(device_t, int, int);
227 static int sk_miibus_writereg(device_t, int, int, int);
228 static void sk_miibus_statchg(device_t);
230 static int sk_xmac_miibus_readreg(struct sk_if_softc *, int, int);
231 static int sk_xmac_miibus_writereg(struct sk_if_softc *, int, int,
233 static void sk_xmac_miibus_statchg(struct sk_if_softc *);
235 static int sk_marv_miibus_readreg(struct sk_if_softc *, int, int);
236 static int sk_marv_miibus_writereg(struct sk_if_softc *, int, int,
238 static void sk_marv_miibus_statchg(struct sk_if_softc *);
240 static uint32_t sk_xmchash(const uint8_t *);
241 static uint32_t sk_gmchash(const uint8_t *);
242 static void sk_setfilt(struct sk_if_softc *, caddr_t, int);
243 static void sk_setmulti(struct sk_if_softc *);
244 static void sk_setpromisc(struct sk_if_softc *);
246 static int sysctl_int_range(SYSCTL_HANDLER_ARGS, int low, int high);
247 static int sysctl_hw_sk_int_mod(SYSCTL_HANDLER_ARGS);
250 #define SK_RES SYS_RES_IOPORT
251 #define SK_RID SK_PCI_LOIO
253 #define SK_RES SYS_RES_MEMORY
254 #define SK_RID SK_PCI_LOMEM
258 * Note that we have newbus methods for both the GEnesis controller
259 * itself and the XMAC(s). The XMACs are children of the GEnesis, and
260 * the miibus code is a child of the XMACs. We need to do it this way
261 * so that the miibus drivers can access the PHY registers on the
262 * right PHY. It's not quite what I had in mind, but it's the only
263 * design that achieves the desired effect.
265 static device_method_t skc_methods[] = {
266 /* Device interface */
267 DEVMETHOD(device_probe, skc_probe),
268 DEVMETHOD(device_attach, skc_attach),
269 DEVMETHOD(device_detach, skc_detach),
270 DEVMETHOD(device_shutdown, skc_shutdown),
273 DEVMETHOD(bus_print_child, bus_generic_print_child),
274 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
279 static driver_t skc_driver = {
282 sizeof(struct sk_softc)
285 static devclass_t skc_devclass;
287 static device_method_t sk_methods[] = {
288 /* Device interface */
289 DEVMETHOD(device_probe, sk_probe),
290 DEVMETHOD(device_attach, sk_attach),
291 DEVMETHOD(device_detach, sk_detach),
292 DEVMETHOD(device_shutdown, bus_generic_shutdown),
295 DEVMETHOD(bus_print_child, bus_generic_print_child),
296 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
299 DEVMETHOD(miibus_readreg, sk_miibus_readreg),
300 DEVMETHOD(miibus_writereg, sk_miibus_writereg),
301 DEVMETHOD(miibus_statchg, sk_miibus_statchg),
306 static driver_t sk_driver = {
309 sizeof(struct sk_if_softc)
312 static devclass_t sk_devclass;
314 DRIVER_MODULE(sk, pci, skc_driver, skc_devclass, 0, 0);
315 DRIVER_MODULE(sk, skc, sk_driver, sk_devclass, 0, 0);
316 DRIVER_MODULE(miibus, sk, miibus_driver, miibus_devclass, 0, 0);
318 #define SK_SETBIT(sc, reg, x) \
319 CSR_WRITE_4(sc, reg, CSR_READ_4(sc, reg) | x)
321 #define SK_CLRBIT(sc, reg, x) \
322 CSR_WRITE_4(sc, reg, CSR_READ_4(sc, reg) & ~x)
324 #define SK_WIN_SETBIT_4(sc, reg, x) \
325 sk_win_write_4(sc, reg, sk_win_read_4(sc, reg) | x)
327 #define SK_WIN_CLRBIT_4(sc, reg, x) \
328 sk_win_write_4(sc, reg, sk_win_read_4(sc, reg) & ~x)
330 #define SK_WIN_SETBIT_2(sc, reg, x) \
331 sk_win_write_2(sc, reg, sk_win_read_2(sc, reg) | x)
333 #define SK_WIN_CLRBIT_2(sc, reg, x) \
334 sk_win_write_2(sc, reg, sk_win_read_2(sc, reg) & ~x)
337 sk_win_read_4(sc, reg)
342 CSR_WRITE_4(sc, SK_RAP, SK_WIN(reg));
343 return(CSR_READ_4(sc, SK_WIN_BASE + SK_REG(reg)));
345 return(CSR_READ_4(sc, reg));
350 sk_win_read_2(sc, reg)
355 CSR_WRITE_4(sc, SK_RAP, SK_WIN(reg));
356 return(CSR_READ_2(sc, SK_WIN_BASE + SK_REG(reg)));
358 return(CSR_READ_2(sc, reg));
363 sk_win_read_1(sc, reg)
368 CSR_WRITE_4(sc, SK_RAP, SK_WIN(reg));
369 return(CSR_READ_1(sc, SK_WIN_BASE + SK_REG(reg)));
371 return(CSR_READ_1(sc, reg));
376 sk_win_write_4(sc, reg, val)
382 CSR_WRITE_4(sc, SK_RAP, SK_WIN(reg));
383 CSR_WRITE_4(sc, SK_WIN_BASE + SK_REG(reg), val);
385 CSR_WRITE_4(sc, reg, val);
391 sk_win_write_2(sc, reg, val)
397 CSR_WRITE_4(sc, SK_RAP, SK_WIN(reg));
398 CSR_WRITE_2(sc, SK_WIN_BASE + SK_REG(reg), val);
400 CSR_WRITE_2(sc, reg, val);
406 sk_win_write_1(sc, reg, val)
412 CSR_WRITE_4(sc, SK_RAP, SK_WIN(reg));
413 CSR_WRITE_1(sc, SK_WIN_BASE + SK_REG(reg), val);
415 CSR_WRITE_1(sc, reg, val);
421 * The VPD EEPROM contains Vital Product Data, as suggested in
422 * the PCI 2.1 specification. The VPD data is separared into areas
423 * denoted by resource IDs. The SysKonnect VPD contains an ID string
424 * resource (the name of the adapter), a read-only area resource
425 * containing various key/data fields and a read/write area which
426 * can be used to store asset management information or log messages.
427 * We read the ID string and read-only into buffers attached to
428 * the controller softc structure for later use. At the moment,
429 * we only use the ID string during skc_attach().
432 sk_vpd_readbyte(sc, addr)
438 sk_win_write_2(sc, SK_PCI_REG(SK_PCI_VPD_ADDR), addr);
439 for (i = 0; i < SK_TIMEOUT; i++) {
441 if (sk_win_read_2(sc,
442 SK_PCI_REG(SK_PCI_VPD_ADDR)) & SK_VPD_FLAG)
449 return(sk_win_read_1(sc, SK_PCI_REG(SK_PCI_VPD_DATA)));
453 sk_vpd_read_res(sc, res, addr)
461 ptr = (u_int8_t *)res;
462 for (i = 0; i < sizeof(struct vpd_res); i++)
463 ptr[i] = sk_vpd_readbyte(sc, i + addr);
475 if (sc->sk_vpd_prodname != NULL)
476 free(sc->sk_vpd_prodname, M_DEVBUF);
477 if (sc->sk_vpd_readonly != NULL)
478 free(sc->sk_vpd_readonly, M_DEVBUF);
479 sc->sk_vpd_prodname = NULL;
480 sc->sk_vpd_readonly = NULL;
481 sc->sk_vpd_readonly_len = 0;
483 sk_vpd_read_res(sc, &res, pos);
486 * Bail out quietly if the eeprom appears to be missing or empty.
488 if (res.vr_id == 0xff && res.vr_len == 0xff && res.vr_pad == 0xff)
491 if (res.vr_id != VPD_RES_ID) {
492 printf("skc%d: bad VPD resource id: expected %x got %x\n",
493 sc->sk_unit, VPD_RES_ID, res.vr_id);
498 sc->sk_vpd_prodname = malloc(res.vr_len + 1, M_DEVBUF, M_NOWAIT);
499 if (sc->sk_vpd_prodname != NULL) {
500 for (i = 0; i < res.vr_len; i++)
501 sc->sk_vpd_prodname[i] = sk_vpd_readbyte(sc, i + pos);
502 sc->sk_vpd_prodname[i] = '\0';
506 sk_vpd_read_res(sc, &res, pos);
508 if (res.vr_id != VPD_RES_READ) {
509 printf("skc%d: bad VPD resource id: expected %x got %x\n",
510 sc->sk_unit, VPD_RES_READ, res.vr_id);
515 sc->sk_vpd_readonly = malloc(res.vr_len, M_DEVBUF, M_NOWAIT);
516 for (i = 0; i < res.vr_len; i++)
517 sc->sk_vpd_readonly[i] = sk_vpd_readbyte(sc, i + pos);
518 sc->sk_vpd_readonly_len = res.vr_len;
524 sk_miibus_readreg(dev, phy, reg)
528 struct sk_if_softc *sc_if;
530 sc_if = device_get_softc(dev);
532 switch(sc_if->sk_softc->sk_type) {
534 return(sk_xmac_miibus_readreg(sc_if, phy, reg));
538 return(sk_marv_miibus_readreg(sc_if, phy, reg));
545 sk_miibus_writereg(dev, phy, reg, val)
549 struct sk_if_softc *sc_if;
551 sc_if = device_get_softc(dev);
553 switch(sc_if->sk_softc->sk_type) {
555 return(sk_xmac_miibus_writereg(sc_if, phy, reg, val));
559 return(sk_marv_miibus_writereg(sc_if, phy, reg, val));
566 sk_miibus_statchg(dev)
569 struct sk_if_softc *sc_if;
571 sc_if = device_get_softc(dev);
573 switch(sc_if->sk_softc->sk_type) {
575 sk_xmac_miibus_statchg(sc_if);
580 sk_marv_miibus_statchg(sc_if);
588 sk_xmac_miibus_readreg(sc_if, phy, reg)
589 struct sk_if_softc *sc_if;
594 if (sc_if->sk_phytype == SK_PHYTYPE_XMAC && phy != 0)
598 SK_XM_WRITE_2(sc_if, XM_PHY_ADDR, reg|(phy << 8));
599 SK_XM_READ_2(sc_if, XM_PHY_DATA);
600 if (sc_if->sk_phytype != SK_PHYTYPE_XMAC) {
601 for (i = 0; i < SK_TIMEOUT; i++) {
603 if (SK_XM_READ_2(sc_if, XM_MMUCMD) &
604 XM_MMUCMD_PHYDATARDY)
608 if (i == SK_TIMEOUT) {
609 printf("sk%d: phy failed to come ready\n",
616 i = SK_XM_READ_2(sc_if, XM_PHY_DATA);
622 sk_xmac_miibus_writereg(sc_if, phy, reg, val)
623 struct sk_if_softc *sc_if;
629 SK_XM_WRITE_2(sc_if, XM_PHY_ADDR, reg|(phy << 8));
630 for (i = 0; i < SK_TIMEOUT; i++) {
631 if (!(SK_XM_READ_2(sc_if, XM_MMUCMD) & XM_MMUCMD_PHYBUSY))
635 if (i == SK_TIMEOUT) {
636 printf("sk%d: phy failed to come ready\n", sc_if->sk_unit);
641 SK_XM_WRITE_2(sc_if, XM_PHY_DATA, val);
642 for (i = 0; i < SK_TIMEOUT; i++) {
644 if (!(SK_XM_READ_2(sc_if, XM_MMUCMD) & XM_MMUCMD_PHYBUSY))
649 printf("sk%d: phy write timed out\n", sc_if->sk_unit);
655 sk_xmac_miibus_statchg(sc_if)
656 struct sk_if_softc *sc_if;
658 struct mii_data *mii;
660 mii = device_get_softc(sc_if->sk_miibus);
664 * If this is a GMII PHY, manually set the XMAC's
665 * duplex mode accordingly.
667 if (sc_if->sk_phytype != SK_PHYTYPE_XMAC) {
668 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
669 SK_XM_SETBIT_2(sc_if, XM_MMUCMD, XM_MMUCMD_GMIIFDX);
671 SK_XM_CLRBIT_2(sc_if, XM_MMUCMD, XM_MMUCMD_GMIIFDX);
680 sk_marv_miibus_readreg(sc_if, phy, reg)
681 struct sk_if_softc *sc_if;
688 (sc_if->sk_phytype != SK_PHYTYPE_MARV_COPPER &&
689 sc_if->sk_phytype != SK_PHYTYPE_MARV_FIBER)) {
694 SK_YU_WRITE_2(sc_if, YUKON_SMICR, YU_SMICR_PHYAD(phy) |
695 YU_SMICR_REGAD(reg) | YU_SMICR_OP_READ);
697 for (i = 0; i < SK_TIMEOUT; i++) {
699 val = SK_YU_READ_2(sc_if, YUKON_SMICR);
700 if (val & YU_SMICR_READ_VALID)
704 if (i == SK_TIMEOUT) {
705 printf("sk%d: phy failed to come ready\n",
711 val = SK_YU_READ_2(sc_if, YUKON_SMIDR);
718 sk_marv_miibus_writereg(sc_if, phy, reg, val)
719 struct sk_if_softc *sc_if;
725 SK_YU_WRITE_2(sc_if, YUKON_SMIDR, val);
726 SK_YU_WRITE_2(sc_if, YUKON_SMICR, YU_SMICR_PHYAD(phy) |
727 YU_SMICR_REGAD(reg) | YU_SMICR_OP_WRITE);
729 for (i = 0; i < SK_TIMEOUT; i++) {
731 if (SK_YU_READ_2(sc_if, YUKON_SMICR) & YU_SMICR_BUSY)
740 sk_marv_miibus_statchg(sc_if)
741 struct sk_if_softc *sc_if;
754 /* Compute CRC for the address value. */
755 crc = ether_crc32_le(addr, ETHER_ADDR_LEN);
757 return (~crc & ((1 << HASH_BITS) - 1));
760 /* gmchash is just a big endian crc */
767 /* Compute CRC for the address value. */
768 crc = ether_crc32_be(addr, ETHER_ADDR_LEN);
770 return (crc & ((1 << HASH_BITS) - 1));
774 sk_setfilt(sc_if, addr, slot)
775 struct sk_if_softc *sc_if;
781 base = XM_RXFILT_ENTRY(slot);
783 SK_XM_WRITE_2(sc_if, base, *(u_int16_t *)(&addr[0]));
784 SK_XM_WRITE_2(sc_if, base + 2, *(u_int16_t *)(&addr[2]));
785 SK_XM_WRITE_2(sc_if, base + 4, *(u_int16_t *)(&addr[4]));
792 struct sk_if_softc *sc_if;
794 struct sk_softc *sc = sc_if->sk_softc;
795 struct ifnet *ifp = &sc_if->arpcom.ac_if;
796 u_int32_t hashes[2] = { 0, 0 };
798 struct ifmultiaddr *ifma;
799 u_int8_t dummy[] = { 0, 0, 0, 0, 0 ,0 };
802 /* First, zot all the existing filters. */
803 switch(sc->sk_type) {
805 for (i = 1; i < XM_RXFILT_MAX; i++)
806 sk_setfilt(sc_if, (caddr_t)&dummy, i);
808 SK_XM_WRITE_4(sc_if, XM_MAR0, 0);
809 SK_XM_WRITE_4(sc_if, XM_MAR2, 0);
814 SK_YU_WRITE_2(sc_if, YUKON_MCAH1, 0);
815 SK_YU_WRITE_2(sc_if, YUKON_MCAH2, 0);
816 SK_YU_WRITE_2(sc_if, YUKON_MCAH3, 0);
817 SK_YU_WRITE_2(sc_if, YUKON_MCAH4, 0);
821 /* Now program new ones. */
822 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
823 hashes[0] = 0xFFFFFFFF;
824 hashes[1] = 0xFFFFFFFF;
827 TAILQ_FOREACH_REVERSE(ifma, &ifp->if_multiaddrs, ifmultihead, ifma_link) {
828 if (ifma->ifma_addr->sa_family != AF_LINK)
831 * Program the first XM_RXFILT_MAX multicast groups
832 * into the perfect filter. For all others,
833 * use the hash table.
835 if (sc->sk_type == SK_GENESIS && i < XM_RXFILT_MAX) {
837 LLADDR((struct sockaddr_dl *)ifma->ifma_addr), i);
842 switch(sc->sk_type) {
845 LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
851 LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
855 hashes[0] |= (1 << h);
857 hashes[1] |= (1 << (h - 32));
861 switch(sc->sk_type) {
863 SK_XM_SETBIT_4(sc_if, XM_MODE, XM_MODE_RX_USE_HASH|
864 XM_MODE_RX_USE_PERFECT);
865 SK_XM_WRITE_4(sc_if, XM_MAR0, hashes[0]);
866 SK_XM_WRITE_4(sc_if, XM_MAR2, hashes[1]);
871 SK_YU_WRITE_2(sc_if, YUKON_MCAH1, hashes[0] & 0xffff);
872 SK_YU_WRITE_2(sc_if, YUKON_MCAH2, (hashes[0] >> 16) & 0xffff);
873 SK_YU_WRITE_2(sc_if, YUKON_MCAH3, hashes[1] & 0xffff);
874 SK_YU_WRITE_2(sc_if, YUKON_MCAH4, (hashes[1] >> 16) & 0xffff);
883 struct sk_if_softc *sc_if;
885 struct sk_softc *sc = sc_if->sk_softc;
886 struct ifnet *ifp = &sc_if->arpcom.ac_if;
888 switch(sc->sk_type) {
890 if (ifp->if_flags & IFF_PROMISC) {
891 SK_XM_SETBIT_4(sc_if, XM_MODE, XM_MODE_RX_PROMISC);
893 SK_XM_CLRBIT_4(sc_if, XM_MODE, XM_MODE_RX_PROMISC);
899 if (ifp->if_flags & IFF_PROMISC) {
900 SK_YU_CLRBIT_2(sc_if, YUKON_RCR,
901 YU_RCR_UFLEN | YU_RCR_MUFLEN);
903 SK_YU_SETBIT_2(sc_if, YUKON_RCR,
904 YU_RCR_UFLEN | YU_RCR_MUFLEN);
913 sk_init_rx_ring(sc_if)
914 struct sk_if_softc *sc_if;
916 struct sk_chain_data *cd = &sc_if->sk_cdata;
917 struct sk_ring_data *rd = sc_if->sk_rdata;
920 bzero((char *)rd->sk_rx_ring,
921 sizeof(struct sk_rx_desc) * SK_RX_RING_CNT);
923 for (i = 0; i < SK_RX_RING_CNT; i++) {
924 cd->sk_rx_chain[i].sk_desc = &rd->sk_rx_ring[i];
925 if (sk_newbuf(sc_if, &cd->sk_rx_chain[i], NULL) == ENOBUFS)
927 if (i == (SK_RX_RING_CNT - 1)) {
928 cd->sk_rx_chain[i].sk_next =
930 rd->sk_rx_ring[i].sk_next =
931 vtophys(&rd->sk_rx_ring[0]);
933 cd->sk_rx_chain[i].sk_next =
934 &cd->sk_rx_chain[i + 1];
935 rd->sk_rx_ring[i].sk_next =
936 vtophys(&rd->sk_rx_ring[i + 1]);
940 sc_if->sk_cdata.sk_rx_prod = 0;
941 sc_if->sk_cdata.sk_rx_cons = 0;
947 sk_init_tx_ring(sc_if)
948 struct sk_if_softc *sc_if;
950 struct sk_chain_data *cd = &sc_if->sk_cdata;
951 struct sk_ring_data *rd = sc_if->sk_rdata;
954 bzero((char *)sc_if->sk_rdata->sk_tx_ring,
955 sizeof(struct sk_tx_desc) * SK_TX_RING_CNT);
957 for (i = 0; i < SK_TX_RING_CNT; i++) {
958 cd->sk_tx_chain[i].sk_desc = &rd->sk_tx_ring[i];
959 if (i == (SK_TX_RING_CNT - 1)) {
960 cd->sk_tx_chain[i].sk_next =
962 rd->sk_tx_ring[i].sk_next =
963 vtophys(&rd->sk_tx_ring[0]);
965 cd->sk_tx_chain[i].sk_next =
966 &cd->sk_tx_chain[i + 1];
967 rd->sk_tx_ring[i].sk_next =
968 vtophys(&rd->sk_tx_ring[i + 1]);
972 sc_if->sk_cdata.sk_tx_prod = 0;
973 sc_if->sk_cdata.sk_tx_cons = 0;
974 sc_if->sk_cdata.sk_tx_cnt = 0;
980 sk_newbuf(sc_if, c, m)
981 struct sk_if_softc *sc_if;
985 struct mbuf *m_new = NULL;
986 struct sk_rx_desc *r;
991 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
995 /* Allocate the jumbo buffer */
996 buf = sk_jalloc(sc_if);
1000 printf("sk%d: jumbo allocation failed "
1001 "-- packet dropped!\n", sc_if->sk_unit);
1006 /* Attach the buffer to the mbuf */
1007 MEXTADD(m_new, buf, SK_JLEN, sk_jfree,
1008 (struct sk_if_softc *)sc_if, 0, EXT_NET_DRV);
1009 m_new->m_data = (void *)buf;
1010 m_new->m_pkthdr.len = m_new->m_len = SK_JLEN;
1013 * We're re-using a previously allocated mbuf;
1014 * be sure to re-init pointers and lengths to
1018 m_new->m_len = m_new->m_pkthdr.len = SK_JLEN;
1019 m_new->m_data = m_new->m_ext.ext_buf;
1023 * Adjust alignment so packet payload begins on a
1024 * longword boundary. Mandatory for Alpha, useful on
1027 m_adj(m_new, ETHER_ALIGN);
1031 r->sk_data_lo = vtophys(mtod(m_new, caddr_t));
1032 r->sk_ctl = m_new->m_len | SK_RXSTAT;
1038 * Allocate jumbo buffer storage. The SysKonnect adapters support
1039 * "jumbograms" (9K frames), although SysKonnect doesn't currently
1040 * use them in their drivers. In order for us to use them, we need
1041 * large 9K receive buffers, however standard mbuf clusters are only
1042 * 2048 bytes in size. Consequently, we need to allocate and manage
1043 * our own jumbo buffer pool. Fortunately, this does not require an
1044 * excessive amount of additional code.
1047 sk_alloc_jumbo_mem(sc_if)
1048 struct sk_if_softc *sc_if;
1052 struct sk_jpool_entry *entry;
1054 /* Grab a big chunk o' storage. */
1055 sc_if->sk_cdata.sk_jumbo_buf = contigmalloc(SK_JMEM, M_DEVBUF,
1056 M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
1058 if (sc_if->sk_cdata.sk_jumbo_buf == NULL) {
1059 printf("sk%d: no memory for jumbo buffers!\n", sc_if->sk_unit);
1063 mtx_init(&sc_if->sk_jlist_mtx, "sk_jlist_mtx", NULL, MTX_DEF);
1065 SLIST_INIT(&sc_if->sk_jfree_listhead);
1066 SLIST_INIT(&sc_if->sk_jinuse_listhead);
1069 * Now divide it up into 9K pieces and save the addresses
1072 ptr = sc_if->sk_cdata.sk_jumbo_buf;
1073 for (i = 0; i < SK_JSLOTS; i++) {
1074 sc_if->sk_cdata.sk_jslots[i] = ptr;
1076 entry = malloc(sizeof(struct sk_jpool_entry),
1077 M_DEVBUF, M_NOWAIT);
1078 if (entry == NULL) {
1079 sk_free_jumbo_mem(sc_if);
1080 sc_if->sk_cdata.sk_jumbo_buf = NULL;
1081 printf("sk%d: no memory for jumbo "
1082 "buffer queue!\n", sc_if->sk_unit);
1086 SLIST_INSERT_HEAD(&sc_if->sk_jfree_listhead,
1087 entry, jpool_entries);
1094 sk_free_jumbo_mem(sc_if)
1095 struct sk_if_softc *sc_if;
1097 struct sk_jpool_entry *entry;
1099 SK_JLIST_LOCK(sc_if);
1101 /* We cannot release external mbuf storage while in use. */
1102 if (!SLIST_EMPTY(&sc_if->sk_jinuse_listhead)) {
1103 printf("sk%d: will leak jumbo buffer memory!\n", sc_if->sk_unit);
1104 SK_JLIST_UNLOCK(sc_if);
1108 while (!SLIST_EMPTY(&sc_if->sk_jfree_listhead)) {
1109 entry = SLIST_FIRST(&sc_if->sk_jfree_listhead);
1110 SLIST_REMOVE_HEAD(&sc_if->sk_jfree_listhead, jpool_entries);
1111 free(entry, M_DEVBUF);
1114 SK_JLIST_UNLOCK(sc_if);
1116 mtx_destroy(&sc_if->sk_jlist_mtx);
1118 contigfree(sc_if->sk_cdata.sk_jumbo_buf, SK_JMEM, M_DEVBUF);
1124 * Allocate a jumbo buffer.
1128 struct sk_if_softc *sc_if;
1130 struct sk_jpool_entry *entry;
1132 SK_JLIST_LOCK(sc_if);
1134 entry = SLIST_FIRST(&sc_if->sk_jfree_listhead);
1136 if (entry == NULL) {
1138 printf("sk%d: no free jumbo buffers\n", sc_if->sk_unit);
1140 SK_JLIST_UNLOCK(sc_if);
1144 SLIST_REMOVE_HEAD(&sc_if->sk_jfree_listhead, jpool_entries);
1145 SLIST_INSERT_HEAD(&sc_if->sk_jinuse_listhead, entry, jpool_entries);
1147 SK_JLIST_UNLOCK(sc_if);
1149 return(sc_if->sk_cdata.sk_jslots[entry->slot]);
1153 * Release a jumbo buffer.
1160 struct sk_if_softc *sc_if;
1162 struct sk_jpool_entry *entry;
1164 /* Extract the softc struct pointer. */
1165 sc_if = (struct sk_if_softc *)args;
1167 panic("sk_jfree: didn't get softc pointer!");
1169 SK_JLIST_LOCK(sc_if);
1171 /* calculate the slot this buffer belongs to */
1172 i = ((vm_offset_t)buf
1173 - (vm_offset_t)sc_if->sk_cdata.sk_jumbo_buf) / SK_JLEN;
1175 if ((i < 0) || (i >= SK_JSLOTS))
1176 panic("sk_jfree: asked to free buffer that we don't manage!");
1178 entry = SLIST_FIRST(&sc_if->sk_jinuse_listhead);
1180 panic("sk_jfree: buffer not in use!");
1182 SLIST_REMOVE_HEAD(&sc_if->sk_jinuse_listhead, jpool_entries);
1183 SLIST_INSERT_HEAD(&sc_if->sk_jfree_listhead, entry, jpool_entries);
1184 if (SLIST_EMPTY(&sc_if->sk_jinuse_listhead))
1187 SK_JLIST_UNLOCK(sc_if);
1192 * Set media options.
1198 struct sk_if_softc *sc_if = ifp->if_softc;
1199 struct mii_data *mii;
1201 mii = device_get_softc(sc_if->sk_miibus);
1209 * Report current media status.
1212 sk_ifmedia_sts(ifp, ifmr)
1214 struct ifmediareq *ifmr;
1216 struct sk_if_softc *sc_if;
1217 struct mii_data *mii;
1219 sc_if = ifp->if_softc;
1220 mii = device_get_softc(sc_if->sk_miibus);
1223 ifmr->ifm_active = mii->mii_media_active;
1224 ifmr->ifm_status = mii->mii_media_status;
1230 sk_ioctl(ifp, command, data)
1235 struct sk_if_softc *sc_if = ifp->if_softc;
1236 struct ifreq *ifr = (struct ifreq *) data;
1238 struct mii_data *mii;
1242 if (ifr->ifr_mtu > SK_JUMBO_MTU)
1245 ifp->if_mtu = ifr->ifr_mtu;
1246 ifp->if_flags &= ~IFF_RUNNING;
1252 if (ifp->if_flags & IFF_UP) {
1253 if (ifp->if_flags & IFF_RUNNING) {
1254 if ((ifp->if_flags ^ sc_if->sk_if_flags)
1256 sk_setpromisc(sc_if);
1262 if (ifp->if_flags & IFF_RUNNING)
1265 sc_if->sk_if_flags = ifp->if_flags;
1266 SK_IF_UNLOCK(sc_if);
1271 if (ifp->if_flags & IFF_RUNNING) {
1274 SK_IF_UNLOCK(sc_if);
1280 mii = device_get_softc(sc_if->sk_miibus);
1281 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
1284 error = ether_ioctl(ifp, command, data);
1292 * Probe for a SysKonnect GEnesis chip. Check the PCI vendor and device
1293 * IDs against our list and return a device name if we find a match.
1299 struct sk_softc *sc;
1300 struct sk_type *t = sk_devs;
1302 sc = device_get_softc(dev);
1304 while(t->sk_name != NULL) {
1305 if ((pci_get_vendor(dev) == t->sk_vid) &&
1306 (pci_get_device(dev) == t->sk_did)) {
1307 device_set_desc(dev, t->sk_name);
1308 return (BUS_PROBE_DEFAULT);
1317 * Force the GEnesis into reset, then bring it out of reset.
1321 struct sk_softc *sc;
1323 CSR_WRITE_2(sc, SK_CSR, SK_CSR_SW_RESET);
1324 CSR_WRITE_2(sc, SK_CSR, SK_CSR_MASTER_RESET);
1325 if (SK_YUKON_FAMILY(sc->sk_type))
1326 CSR_WRITE_2(sc, SK_LINK_CTRL, SK_LINK_RESET_SET);
1329 CSR_WRITE_2(sc, SK_CSR, SK_CSR_SW_UNRESET);
1331 CSR_WRITE_2(sc, SK_CSR, SK_CSR_MASTER_UNRESET);
1332 if (SK_YUKON_FAMILY(sc->sk_type))
1333 CSR_WRITE_2(sc, SK_LINK_CTRL, SK_LINK_RESET_CLEAR);
1335 if (sc->sk_type == SK_GENESIS) {
1336 /* Configure packet arbiter */
1337 sk_win_write_2(sc, SK_PKTARB_CTL, SK_PKTARBCTL_UNRESET);
1338 sk_win_write_2(sc, SK_RXPA1_TINIT, SK_PKTARB_TIMEOUT);
1339 sk_win_write_2(sc, SK_TXPA1_TINIT, SK_PKTARB_TIMEOUT);
1340 sk_win_write_2(sc, SK_RXPA2_TINIT, SK_PKTARB_TIMEOUT);
1341 sk_win_write_2(sc, SK_TXPA2_TINIT, SK_PKTARB_TIMEOUT);
1344 /* Enable RAM interface */
1345 sk_win_write_4(sc, SK_RAMCTL, SK_RAMCTL_UNRESET);
1348 * Configure interrupt moderation. The moderation timer
1349 * defers interrupts specified in the interrupt moderation
1350 * timer mask based on the timeout specified in the interrupt
1351 * moderation timer init register. Each bit in the timer
1352 * register represents 18.825ns, so to specify a timeout in
1353 * microseconds, we have to multiply by 54.
1355 printf("skc%d: interrupt moderation is %d us\n",
1356 sc->sk_unit, sc->sk_int_mod);
1357 sk_win_write_4(sc, SK_IMTIMERINIT, SK_IM_USECS(sc->sk_int_mod));
1358 sk_win_write_4(sc, SK_IMMR, SK_ISR_TX1_S_EOF|SK_ISR_TX2_S_EOF|
1359 SK_ISR_RX1_EOF|SK_ISR_RX2_EOF);
1360 sk_win_write_1(sc, SK_IMTIMERCTL, SK_IMCTL_START);
1369 struct sk_softc *sc;
1371 sc = device_get_softc(device_get_parent(dev));
1374 * Not much to do here. We always know there will be
1375 * at least one XMAC present, and if there are two,
1376 * skc_attach() will create a second device instance
1379 switch (sc->sk_type) {
1381 device_set_desc(dev, "XaQti Corp. XMAC II");
1386 device_set_desc(dev, "Marvell Semiconductor, Inc. Yukon");
1390 return (BUS_PROBE_DEFAULT);
1394 * Each XMAC chip is attached as a separate logical IP interface.
1395 * Single port cards will have only one logical interface of course.
1401 struct sk_softc *sc;
1402 struct sk_if_softc *sc_if;
1410 sc_if = device_get_softc(dev);
1411 sc = device_get_softc(device_get_parent(dev));
1412 port = *(int *)device_get_ivars(dev);
1414 sc_if->sk_dev = dev;
1415 sc_if->sk_unit = device_get_unit(dev);
1416 sc_if->sk_port = port;
1417 sc_if->sk_softc = sc;
1418 sc->sk_if[port] = sc_if;
1419 if (port == SK_PORT_A)
1420 sc_if->sk_tx_bmu = SK_BMU_TXS_CSR0;
1421 if (port == SK_PORT_B)
1422 sc_if->sk_tx_bmu = SK_BMU_TXS_CSR1;
1424 /* Allocate the descriptor queues. */
1425 sc_if->sk_rdata = contigmalloc(sizeof(struct sk_ring_data), M_DEVBUF,
1426 M_NOWAIT, M_ZERO, 0xffffffff, PAGE_SIZE, 0);
1428 if (sc_if->sk_rdata == NULL) {
1429 printf("sk%d: no memory for list buffers!\n", sc_if->sk_unit);
1434 /* Try to allocate memory for jumbo buffers. */
1435 if (sk_alloc_jumbo_mem(sc_if)) {
1436 printf("sk%d: jumbo buffer allocation failed\n",
1442 ifp = &sc_if->arpcom.ac_if;
1443 ifp->if_softc = sc_if;
1444 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
1445 ifp->if_mtu = ETHERMTU;
1446 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
1447 ifp->if_ioctl = sk_ioctl;
1448 ifp->if_start = sk_start;
1449 ifp->if_watchdog = sk_watchdog;
1450 ifp->if_init = sk_init;
1451 ifp->if_baudrate = 1000000000;
1452 IFQ_SET_MAXLEN(&ifp->if_snd, SK_TX_RING_CNT - 1);
1453 ifp->if_snd.ifq_drv_maxlen = SK_TX_RING_CNT - 1;
1454 IFQ_SET_READY(&ifp->if_snd);
1456 callout_handle_init(&sc_if->sk_tick_ch);
1459 * Get station address for this interface. Note that
1460 * dual port cards actually come with three station
1461 * addresses: one for each port, plus an extra. The
1462 * extra one is used by the SysKonnect driver software
1463 * as a 'virtual' station address for when both ports
1464 * are operating in failover mode. Currently we don't
1465 * use this extra address.
1468 for (i = 0; i < ETHER_ADDR_LEN; i++)
1469 sc_if->arpcom.ac_enaddr[i] =
1470 sk_win_read_1(sc, SK_MAC0_0 + (port * 8) + i);
1473 * Set up RAM buffer addresses. The NIC will have a certain
1474 * amount of SRAM on it, somewhere between 512K and 2MB. We
1475 * need to divide this up a) between the transmitter and
1476 * receiver and b) between the two XMACs, if this is a
1477 * dual port NIC. Our algotithm is to divide up the memory
1478 * evenly so that everyone gets a fair share.
1480 if (sk_win_read_1(sc, SK_CONFIG) & SK_CONFIG_SINGLEMAC) {
1481 u_int32_t chunk, val;
1483 chunk = sc->sk_ramsize / 2;
1484 val = sc->sk_rboff / sizeof(u_int64_t);
1485 sc_if->sk_rx_ramstart = val;
1486 val += (chunk / sizeof(u_int64_t));
1487 sc_if->sk_rx_ramend = val - 1;
1488 sc_if->sk_tx_ramstart = val;
1489 val += (chunk / sizeof(u_int64_t));
1490 sc_if->sk_tx_ramend = val - 1;
1492 u_int32_t chunk, val;
1494 chunk = sc->sk_ramsize / 4;
1495 val = (sc->sk_rboff + (chunk * 2 * sc_if->sk_port)) /
1497 sc_if->sk_rx_ramstart = val;
1498 val += (chunk / sizeof(u_int64_t));
1499 sc_if->sk_rx_ramend = val - 1;
1500 sc_if->sk_tx_ramstart = val;
1501 val += (chunk / sizeof(u_int64_t));
1502 sc_if->sk_tx_ramend = val - 1;
1505 /* Read and save PHY type and set PHY address */
1506 sc_if->sk_phytype = sk_win_read_1(sc, SK_EPROM1) & 0xF;
1507 switch(sc_if->sk_phytype) {
1508 case SK_PHYTYPE_XMAC:
1509 sc_if->sk_phyaddr = SK_PHYADDR_XMAC;
1511 case SK_PHYTYPE_BCOM:
1512 sc_if->sk_phyaddr = SK_PHYADDR_BCOM;
1514 case SK_PHYTYPE_MARV_COPPER:
1515 sc_if->sk_phyaddr = SK_PHYADDR_MARV;
1518 printf("skc%d: unsupported PHY type: %d\n",
1519 sc->sk_unit, sc_if->sk_phytype);
1527 * Call MI attach routine. Can't hold locks when calling into ether_*.
1530 ether_ifattach(ifp, sc_if->arpcom.ac_enaddr);
1536 switch (sc->sk_type) {
1538 sk_init_xmac(sc_if);
1543 sk_init_yukon(sc_if);
1548 if (mii_phy_probe(dev, &sc_if->sk_miibus,
1549 sk_ifmedia_upd, sk_ifmedia_sts)) {
1550 printf("skc%d: no PHY found!\n", sc_if->sk_unit);
1551 ether_ifdetach(ifp);
1558 /* Access should be ok even though lock has been dropped */
1559 sc->sk_if[port] = NULL;
1567 * Attach the interface. Allocate softc structures, do ifmedia
1568 * setup and ethernet/BPF attach.
1574 struct sk_softc *sc;
1575 int unit, error = 0, rid, *port;
1577 char *pname, *revstr;
1579 sc = device_get_softc(dev);
1580 unit = device_get_unit(dev);
1582 mtx_init(&sc->sk_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
1583 MTX_DEF | MTX_RECURSE);
1585 * Map control/status registers.
1587 pci_enable_busmaster(dev);
1590 sc->sk_res = bus_alloc_resource_any(dev, SK_RES, &rid, RF_ACTIVE);
1592 if (sc->sk_res == NULL) {
1593 printf("sk%d: couldn't map ports/memory\n", unit);
1598 sc->sk_btag = rman_get_bustag(sc->sk_res);
1599 sc->sk_bhandle = rman_get_bushandle(sc->sk_res);
1601 sc->sk_type = sk_win_read_1(sc, SK_CHIPVER);
1602 sc->sk_rev = (sk_win_read_1(sc, SK_CONFIG) >> 4) & 0xf;
1604 /* Bail out if chip is not recognized. */
1605 if (sc->sk_type != SK_GENESIS && !SK_YUKON_FAMILY(sc->sk_type)) {
1606 printf("skc%d: unknown device: chipver=%02x, rev=%x\n",
1607 unit, sc->sk_type, sc->sk_rev);
1612 /* Allocate interrupt */
1614 sc->sk_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
1615 RF_SHAREABLE | RF_ACTIVE);
1617 if (sc->sk_irq == NULL) {
1618 printf("skc%d: couldn't map interrupt\n", unit);
1623 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1624 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
1625 OID_AUTO, "int_mod", CTLTYPE_INT|CTLFLAG_RW,
1626 &sc->sk_int_mod, 0, sysctl_hw_sk_int_mod, "I",
1627 "SK interrupt moderation");
1629 /* Pull in device tunables. */
1630 sc->sk_int_mod = SK_IM_DEFAULT;
1631 error = resource_int_value(device_get_name(dev), unit,
1632 "int_mod", &sc->sk_int_mod);
1634 if (sc->sk_int_mod < SK_IM_MIN ||
1635 sc->sk_int_mod > SK_IM_MAX) {
1636 printf("skc%d: int_mod value out of range; "
1637 "using default: %d\n", unit, SK_IM_DEFAULT);
1638 sc->sk_int_mod = SK_IM_DEFAULT;
1642 /* Reset the adapter. */
1647 /* Read and save vital product data from EEPROM. */
1650 skrs = sk_win_read_1(sc, SK_EPROM0);
1651 if (sc->sk_type == SK_GENESIS) {
1652 /* Read and save RAM size and RAMbuffer offset */
1654 case SK_RAMSIZE_512K_64:
1655 sc->sk_ramsize = 0x80000;
1656 sc->sk_rboff = SK_RBOFF_0;
1658 case SK_RAMSIZE_1024K_64:
1659 sc->sk_ramsize = 0x100000;
1660 sc->sk_rboff = SK_RBOFF_80000;
1662 case SK_RAMSIZE_1024K_128:
1663 sc->sk_ramsize = 0x100000;
1664 sc->sk_rboff = SK_RBOFF_0;
1666 case SK_RAMSIZE_2048K_128:
1667 sc->sk_ramsize = 0x200000;
1668 sc->sk_rboff = SK_RBOFF_0;
1671 printf("skc%d: unknown ram size: %d\n",
1672 sc->sk_unit, sk_win_read_1(sc, SK_EPROM0));
1676 } else { /* SK_YUKON_FAMILY */
1678 sc->sk_ramsize = 0x20000;
1680 sc->sk_ramsize = skrs * (1<<12);
1681 sc->sk_rboff = SK_RBOFF_0;
1684 /* Read and save physical media type */
1685 switch(sk_win_read_1(sc, SK_PMDTYPE)) {
1686 case SK_PMD_1000BASESX:
1687 sc->sk_pmd = IFM_1000_SX;
1689 case SK_PMD_1000BASELX:
1690 sc->sk_pmd = IFM_1000_LX;
1692 case SK_PMD_1000BASECX:
1693 sc->sk_pmd = IFM_1000_CX;
1695 case SK_PMD_1000BASETX:
1696 sc->sk_pmd = IFM_1000_T;
1699 printf("skc%d: unknown media type: 0x%x\n",
1700 sc->sk_unit, sk_win_read_1(sc, SK_PMDTYPE));
1705 /* Determine whether to name it with VPD PN or just make it up.
1706 * Marvell Yukon VPD PN seems to freqently be bogus. */
1707 switch (pci_get_device(dev)) {
1708 case DEVICEID_SK_V1:
1709 case DEVICEID_BELKIN_5005:
1710 case DEVICEID_3COM_3C940:
1711 case DEVICEID_LINKSYS_EG1032:
1712 case DEVICEID_DLINK_DGE530T:
1713 /* Stay with VPD PN. */
1714 pname = sc->sk_vpd_prodname;
1716 case DEVICEID_SK_V2:
1717 /* YUKON VPD PN might bear no resemblance to reality. */
1718 switch (sc->sk_type) {
1720 /* Stay with VPD PN. */
1721 pname = sc->sk_vpd_prodname;
1724 pname = "Marvell Yukon Gigabit Ethernet";
1727 pname = "Marvell Yukon Lite Gigabit Ethernet";
1730 pname = "Marvell Yukon LP Gigabit Ethernet";
1733 pname = "Marvell Yukon (Unknown) Gigabit Ethernet";
1737 /* Yukon Lite Rev. A0 needs special test. */
1738 if (sc->sk_type == SK_YUKON || sc->sk_type == SK_YUKON_LP) {
1742 /* Save flash address register before testing. */
1743 far = sk_win_read_4(sc, SK_EP_ADDR);
1745 sk_win_write_1(sc, SK_EP_ADDR+0x03, 0xff);
1746 testbyte = sk_win_read_1(sc, SK_EP_ADDR+0x03);
1748 if (testbyte != 0x00) {
1749 /* Yukon Lite Rev. A0 detected. */
1750 sc->sk_type = SK_YUKON_LITE;
1751 sc->sk_rev = SK_YUKON_LITE_REV_A0;
1752 /* Restore flash address register. */
1753 sk_win_write_4(sc, SK_EP_ADDR, far);
1758 device_printf(dev, "unknown device: vendor=%04x, device=%04x, "
1759 "chipver=%02x, rev=%x\n",
1760 pci_get_vendor(dev), pci_get_device(dev),
1761 sc->sk_type, sc->sk_rev);
1766 if (sc->sk_type == SK_YUKON_LITE) {
1767 switch (sc->sk_rev) {
1768 case SK_YUKON_LITE_REV_A0:
1771 case SK_YUKON_LITE_REV_A1:
1774 case SK_YUKON_LITE_REV_A3:
1785 /* Announce the product name and more VPD data if there. */
1786 device_printf(dev, "%s rev. %s(0x%x)\n",
1787 pname != NULL ? pname : "<unknown>", revstr, sc->sk_rev);
1790 if (sc->sk_vpd_readonly != NULL &&
1791 sc->sk_vpd_readonly_len != 0) {
1793 char *dp = sc->sk_vpd_readonly;
1794 uint16_t l, len = sc->sk_vpd_readonly_len;
1797 if ((*dp == 'P' && *(dp+1) == 'N') ||
1798 (*dp == 'E' && *(dp+1) == 'C') ||
1799 (*dp == 'M' && *(dp+1) == 'N') ||
1800 (*dp == 'S' && *(dp+1) == 'N')) {
1802 while (l < *(dp+2)) {
1807 device_printf(dev, "%c%c: %s\n",
1812 len -= (3 + *(dp+2));
1813 dp += (3 + *(dp+2));
1817 device_printf(dev, "chip ver = 0x%02x\n", sc->sk_type);
1818 device_printf(dev, "chip rev = 0x%02x\n", sc->sk_rev);
1819 device_printf(dev, "SK_EPROM0 = 0x%02x\n", skrs);
1820 device_printf(dev, "SRAM size = 0x%06x\n", sc->sk_ramsize);
1823 sc->sk_devs[SK_PORT_A] = device_add_child(dev, "sk", -1);
1824 if (sc->sk_devs[SK_PORT_A] == NULL) {
1825 device_printf(dev, "failed to add child for PORT_A\n");
1829 port = malloc(sizeof(int), M_DEVBUF, M_NOWAIT);
1831 device_printf(dev, "failed to allocate memory for "
1832 "ivars of PORT_A\n");
1837 device_set_ivars(sc->sk_devs[SK_PORT_A], port);
1839 if (!(sk_win_read_1(sc, SK_CONFIG) & SK_CONFIG_SINGLEMAC)) {
1840 sc->sk_devs[SK_PORT_B] = device_add_child(dev, "sk", -1);
1841 if (sc->sk_devs[SK_PORT_B] == NULL) {
1842 device_printf(dev, "failed to add child for PORT_B\n");
1846 port = malloc(sizeof(int), M_DEVBUF, M_NOWAIT);
1848 device_printf(dev, "failed to allocate memory for "
1849 "ivars of PORT_B\n");
1854 device_set_ivars(sc->sk_devs[SK_PORT_B], port);
1857 /* Turn on the 'driver is loaded' LED. */
1858 CSR_WRITE_2(sc, SK_LED, SK_LED_GREEN_ON);
1860 bus_generic_attach(dev);
1862 /* Hook interrupt last to avoid having to lock softc */
1863 error = bus_setup_intr(dev, sc->sk_irq, INTR_TYPE_NET|INTR_MPSAFE,
1864 sk_intr, sc, &sc->sk_intrhand);
1867 printf("skc%d: couldn't set up irq\n", unit);
1879 * Shutdown hardware and free up resources. This can be called any
1880 * time after the mutex has been initialized. It is called in both
1881 * the error case in attach and the normal detach case so it needs
1882 * to be careful about only freeing resources that have actually been
1889 struct sk_if_softc *sc_if;
1892 sc_if = device_get_softc(dev);
1893 KASSERT(mtx_initialized(&sc_if->sk_softc->sk_mtx),
1894 ("sk mutex not initialized in sk_detach"));
1897 ifp = &sc_if->arpcom.ac_if;
1898 /* These should only be active if attach_xmac succeeded */
1899 if (device_is_attached(dev)) {
1901 /* Can't hold locks while calling detach */
1902 SK_IF_UNLOCK(sc_if);
1903 ether_ifdetach(ifp);
1907 * We're generally called from skc_detach() which is using
1908 * device_delete_child() to get to here. It's already trashed
1909 * miibus for us, so don't do it here or we'll panic.
1912 if (sc_if->sk_miibus != NULL)
1913 device_delete_child(dev, sc_if->sk_miibus);
1915 bus_generic_detach(dev);
1916 if (sc_if->sk_cdata.sk_jumbo_buf != NULL)
1917 sk_free_jumbo_mem(sc_if);
1918 if (sc_if->sk_rdata != NULL) {
1919 contigfree(sc_if->sk_rdata, sizeof(struct sk_ring_data),
1922 SK_IF_UNLOCK(sc_if);
1931 struct sk_softc *sc;
1933 sc = device_get_softc(dev);
1934 KASSERT(mtx_initialized(&sc->sk_mtx), ("sk mutex not initialized"));
1936 if (device_is_alive(dev)) {
1937 if (sc->sk_devs[SK_PORT_A] != NULL) {
1938 free(device_get_ivars(sc->sk_devs[SK_PORT_A]), M_DEVBUF);
1939 device_delete_child(dev, sc->sk_devs[SK_PORT_A]);
1941 if (sc->sk_devs[SK_PORT_B] != NULL) {
1942 free(device_get_ivars(sc->sk_devs[SK_PORT_B]), M_DEVBUF);
1943 device_delete_child(dev, sc->sk_devs[SK_PORT_B]);
1945 bus_generic_detach(dev);
1948 if (sc->sk_vpd_prodname != NULL)
1949 free(sc->sk_vpd_prodname, M_DEVBUF);
1950 if (sc->sk_vpd_readonly != NULL)
1951 free(sc->sk_vpd_readonly, M_DEVBUF);
1953 if (sc->sk_intrhand)
1954 bus_teardown_intr(dev, sc->sk_irq, sc->sk_intrhand);
1956 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sk_irq);
1958 bus_release_resource(dev, SK_RES, SK_RID, sc->sk_res);
1960 mtx_destroy(&sc->sk_mtx);
1966 sk_encap(sc_if, m_head, txidx)
1967 struct sk_if_softc *sc_if;
1968 struct mbuf *m_head;
1971 struct sk_tx_desc *f = NULL;
1973 u_int32_t frag, cur, cnt = 0;
1975 SK_IF_LOCK_ASSERT(sc_if);
1978 cur = frag = *txidx;
1981 * Start packing the mbufs in this chain into
1982 * the fragment pointers. Stop when we run out
1983 * of fragments or hit the end of the mbuf chain.
1985 for (m = m_head; m != NULL; m = m->m_next) {
1986 if (m->m_len != 0) {
1987 if ((SK_TX_RING_CNT -
1988 (sc_if->sk_cdata.sk_tx_cnt + cnt)) < 2)
1990 f = &sc_if->sk_rdata->sk_tx_ring[frag];
1991 f->sk_data_lo = vtophys(mtod(m, vm_offset_t));
1992 f->sk_ctl = m->m_len | SK_OPCODE_DEFAULT;
1994 f->sk_ctl |= SK_TXCTL_FIRSTFRAG;
1996 f->sk_ctl |= SK_TXCTL_OWN;
1998 SK_INC(frag, SK_TX_RING_CNT);
2006 sc_if->sk_rdata->sk_tx_ring[cur].sk_ctl |=
2007 SK_TXCTL_LASTFRAG|SK_TXCTL_EOF_INTR;
2008 sc_if->sk_cdata.sk_tx_chain[cur].sk_mbuf = m_head;
2009 sc_if->sk_rdata->sk_tx_ring[*txidx].sk_ctl |= SK_TXCTL_OWN;
2010 sc_if->sk_cdata.sk_tx_cnt += cnt;
2021 struct sk_softc *sc;
2022 struct sk_if_softc *sc_if;
2023 struct mbuf *m_head = NULL;
2026 sc_if = ifp->if_softc;
2027 sc = sc_if->sk_softc;
2031 idx = sc_if->sk_cdata.sk_tx_prod;
2033 while(sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf == NULL) {
2034 IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
2039 * Pack the data into the transmit ring. If we
2040 * don't have room, set the OACTIVE flag and wait
2041 * for the NIC to drain the ring.
2043 if (sk_encap(sc_if, m_head, &idx)) {
2044 IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
2045 ifp->if_flags |= IFF_OACTIVE;
2050 * If there's a BPF listener, bounce a copy of this frame
2053 BPF_MTAP(ifp, m_head);
2057 if (idx != sc_if->sk_cdata.sk_tx_prod) {
2058 sc_if->sk_cdata.sk_tx_prod = idx;
2059 CSR_WRITE_4(sc, sc_if->sk_tx_bmu, SK_TXBMU_TX_START);
2061 /* Set a timeout in case the chip goes out to lunch. */
2064 SK_IF_UNLOCK(sc_if);
2074 struct sk_if_softc *sc_if;
2076 sc_if = ifp->if_softc;
2078 printf("sk%d: watchdog timeout\n", sc_if->sk_unit);
2079 ifp->if_flags &= ~IFF_RUNNING;
2089 struct sk_softc *sc;
2091 sc = device_get_softc(dev);
2094 /* Turn off the 'driver is loaded' LED. */
2095 CSR_WRITE_2(sc, SK_LED, SK_LED_GREEN_OFF);
2098 * Reset the GEnesis controller. Doing this should also
2099 * assert the resets on the attached XMAC(s).
2109 struct sk_if_softc *sc_if;
2111 struct sk_softc *sc;
2114 struct sk_chain *cur_rx;
2119 sc = sc_if->sk_softc;
2120 ifp = &sc_if->arpcom.ac_if;
2121 i = sc_if->sk_cdata.sk_rx_prod;
2122 cur_rx = &sc_if->sk_cdata.sk_rx_chain[i];
2126 while(!(sc_if->sk_rdata->sk_rx_ring[i].sk_ctl & SK_RXCTL_OWN)) {
2128 cur_rx = &sc_if->sk_cdata.sk_rx_chain[i];
2129 rxstat = sc_if->sk_rdata->sk_rx_ring[i].sk_xmac_rxstat;
2130 m = cur_rx->sk_mbuf;
2131 cur_rx->sk_mbuf = NULL;
2132 total_len = SK_RXBYTES(sc_if->sk_rdata->sk_rx_ring[i].sk_ctl);
2133 SK_INC(i, SK_RX_RING_CNT);
2135 if (rxstat & XM_RXSTAT_ERRFRAME) {
2137 sk_newbuf(sc_if, cur_rx, m);
2142 * Try to allocate a new jumbo buffer. If that
2143 * fails, copy the packet to mbufs and put the
2144 * jumbo buffer back in the ring so it can be
2145 * re-used. If allocating mbufs fails, then we
2146 * have to drop the packet.
2148 if (sk_newbuf(sc_if, cur_rx, NULL) == ENOBUFS) {
2150 m0 = m_devget(mtod(m, char *), total_len, ETHER_ALIGN,
2152 sk_newbuf(sc_if, cur_rx, m);
2154 printf("sk%d: no receive buffers "
2155 "available -- packet dropped!\n",
2162 m->m_pkthdr.rcvif = ifp;
2163 m->m_pkthdr.len = m->m_len = total_len;
2168 (*ifp->if_input)(ifp, m);
2172 sc_if->sk_cdata.sk_rx_prod = i;
2179 struct sk_if_softc *sc_if;
2181 struct sk_softc *sc;
2182 struct sk_tx_desc *cur_tx;
2186 sc = sc_if->sk_softc;
2187 ifp = &sc_if->arpcom.ac_if;
2190 * Go through our tx ring and free mbufs for those
2191 * frames that have been sent.
2193 idx = sc_if->sk_cdata.sk_tx_cons;
2194 while(idx != sc_if->sk_cdata.sk_tx_prod) {
2195 cur_tx = &sc_if->sk_rdata->sk_tx_ring[idx];
2196 if (cur_tx->sk_ctl & SK_TXCTL_OWN)
2198 if (cur_tx->sk_ctl & SK_TXCTL_LASTFRAG)
2200 if (sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf != NULL) {
2201 m_freem(sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf);
2202 sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf = NULL;
2204 sc_if->sk_cdata.sk_tx_cnt--;
2205 SK_INC(idx, SK_TX_RING_CNT);
2208 if (sc_if->sk_cdata.sk_tx_cnt == 0) {
2210 } else /* nudge chip to keep tx ring moving */
2211 CSR_WRITE_4(sc, sc_if->sk_tx_bmu, SK_TXBMU_TX_START);
2213 if (sc_if->sk_cdata.sk_tx_cnt < SK_TX_RING_CNT - 2)
2214 ifp->if_flags &= ~IFF_OACTIVE;
2216 sc_if->sk_cdata.sk_tx_cons = idx;
2223 struct sk_if_softc *sc_if;
2224 struct mii_data *mii;
2230 ifp = &sc_if->arpcom.ac_if;
2231 mii = device_get_softc(sc_if->sk_miibus);
2233 if (!(ifp->if_flags & IFF_UP)) {
2234 SK_IF_UNLOCK(sc_if);
2238 if (sc_if->sk_phytype == SK_PHYTYPE_BCOM) {
2239 sk_intr_bcom(sc_if);
2240 SK_IF_UNLOCK(sc_if);
2245 * According to SysKonnect, the correct way to verify that
2246 * the link has come back up is to poll bit 0 of the GPIO
2247 * register three times. This pin has the signal from the
2248 * link_sync pin connected to it; if we read the same link
2249 * state 3 times in a row, we know the link is up.
2251 for (i = 0; i < 3; i++) {
2252 if (SK_XM_READ_2(sc_if, XM_GPIO) & XM_GPIO_GP0_SET)
2257 sc_if->sk_tick_ch = timeout(sk_tick, sc_if, hz);
2258 SK_IF_UNLOCK(sc_if);
2262 /* Turn the GP0 interrupt back on. */
2263 SK_XM_CLRBIT_2(sc_if, XM_IMR, XM_IMR_GP0_SET);
2264 SK_XM_READ_2(sc_if, XM_ISR);
2266 untimeout(sk_tick, sc_if, sc_if->sk_tick_ch);
2268 SK_IF_UNLOCK(sc_if);
2274 struct sk_if_softc *sc_if;
2276 struct mii_data *mii;
2279 mii = device_get_softc(sc_if->sk_miibus);
2280 ifp = &sc_if->arpcom.ac_if;
2282 SK_XM_CLRBIT_2(sc_if, XM_MMUCMD, XM_MMUCMD_TX_ENB|XM_MMUCMD_RX_ENB);
2285 * Read the PHY interrupt register to make sure
2286 * we clear any pending interrupts.
2288 status = sk_xmac_miibus_readreg(sc_if, SK_PHYADDR_BCOM, BRGPHY_MII_ISR);
2290 if (!(ifp->if_flags & IFF_RUNNING)) {
2291 sk_init_xmac(sc_if);
2295 if (status & (BRGPHY_ISR_LNK_CHG|BRGPHY_ISR_AN_PR)) {
2297 lstat = sk_xmac_miibus_readreg(sc_if, SK_PHYADDR_BCOM,
2300 if (!(lstat & BRGPHY_AUXSTS_LINK) && sc_if->sk_link) {
2302 /* Turn off the link LED. */
2303 SK_IF_WRITE_1(sc_if, 0,
2304 SK_LINKLED1_CTL, SK_LINKLED_OFF);
2306 } else if (status & BRGPHY_ISR_LNK_CHG) {
2307 sk_xmac_miibus_writereg(sc_if, SK_PHYADDR_BCOM,
2308 BRGPHY_MII_IMR, 0xFF00);
2311 /* Turn on the link LED. */
2312 SK_IF_WRITE_1(sc_if, 0, SK_LINKLED1_CTL,
2313 SK_LINKLED_ON|SK_LINKLED_LINKSYNC_OFF|
2314 SK_LINKLED_BLINK_OFF);
2317 sc_if->sk_tick_ch = timeout(sk_tick, sc_if, hz);
2321 SK_XM_SETBIT_2(sc_if, XM_MMUCMD, XM_MMUCMD_TX_ENB|XM_MMUCMD_RX_ENB);
2328 struct sk_if_softc *sc_if;
2330 struct sk_softc *sc;
2333 sc = sc_if->sk_softc;
2334 status = SK_XM_READ_2(sc_if, XM_ISR);
2337 * Link has gone down. Start MII tick timeout to
2338 * watch for link resync.
2340 if (sc_if->sk_phytype == SK_PHYTYPE_XMAC) {
2341 if (status & XM_ISR_GP0_SET) {
2342 SK_XM_SETBIT_2(sc_if, XM_IMR, XM_IMR_GP0_SET);
2343 sc_if->sk_tick_ch = timeout(sk_tick, sc_if, hz);
2346 if (status & XM_ISR_AUTONEG_DONE) {
2347 sc_if->sk_tick_ch = timeout(sk_tick, sc_if, hz);
2351 if (status & XM_IMR_TX_UNDERRUN)
2352 SK_XM_SETBIT_4(sc_if, XM_MODE, XM_MODE_FLUSH_TXFIFO);
2354 if (status & XM_IMR_RX_OVERRUN)
2355 SK_XM_SETBIT_4(sc_if, XM_MODE, XM_MODE_FLUSH_RXFIFO);
2357 status = SK_XM_READ_2(sc_if, XM_ISR);
2363 sk_intr_yukon(sc_if)
2364 struct sk_if_softc *sc_if;
2368 status = SK_IF_READ_2(sc_if, 0, SK_GMAC_ISR);
2377 struct sk_softc *sc = xsc;
2378 struct sk_if_softc *sc_if0 = NULL, *sc_if1 = NULL;
2379 struct ifnet *ifp0 = NULL, *ifp1 = NULL;
2384 sc_if0 = sc->sk_if[SK_PORT_A];
2385 sc_if1 = sc->sk_if[SK_PORT_B];
2388 ifp0 = &sc_if0->arpcom.ac_if;
2390 ifp1 = &sc_if1->arpcom.ac_if;
2393 status = CSR_READ_4(sc, SK_ISSR);
2394 if (!(status & sc->sk_intrmask))
2397 /* Handle receive interrupts first. */
2398 if (status & SK_ISR_RX1_EOF) {
2400 CSR_WRITE_4(sc, SK_BMU_RX_CSR0,
2401 SK_RXBMU_CLR_IRQ_EOF|SK_RXBMU_RX_START);
2403 if (status & SK_ISR_RX2_EOF) {
2405 CSR_WRITE_4(sc, SK_BMU_RX_CSR1,
2406 SK_RXBMU_CLR_IRQ_EOF|SK_RXBMU_RX_START);
2409 /* Then transmit interrupts. */
2410 if (status & SK_ISR_TX1_S_EOF) {
2412 CSR_WRITE_4(sc, SK_BMU_TXS_CSR0,
2413 SK_TXBMU_CLR_IRQ_EOF);
2415 if (status & SK_ISR_TX2_S_EOF) {
2417 CSR_WRITE_4(sc, SK_BMU_TXS_CSR1,
2418 SK_TXBMU_CLR_IRQ_EOF);
2421 /* Then MAC interrupts. */
2422 if (status & SK_ISR_MAC1 && ifp0->if_flags & IFF_RUNNING) {
2423 if (sc->sk_type == SK_GENESIS)
2424 sk_intr_xmac(sc_if0);
2426 sk_intr_yukon(sc_if0);
2429 if (status & SK_ISR_MAC2 && ifp1->if_flags & IFF_RUNNING) {
2430 if (sc->sk_type == SK_GENESIS)
2431 sk_intr_xmac(sc_if1);
2433 sk_intr_yukon(sc_if1);
2436 if (status & SK_ISR_EXTERNAL_REG) {
2438 sc_if0->sk_phytype == SK_PHYTYPE_BCOM)
2439 sk_intr_bcom(sc_if0);
2441 sc_if1->sk_phytype == SK_PHYTYPE_BCOM)
2442 sk_intr_bcom(sc_if1);
2446 CSR_WRITE_4(sc, SK_IMR, sc->sk_intrmask);
2448 if (ifp0 != NULL && !IFQ_DRV_IS_EMPTY(&ifp0->if_snd))
2450 if (ifp1 != NULL && !IFQ_DRV_IS_EMPTY(&ifp1->if_snd))
2460 struct sk_if_softc *sc_if;
2462 struct sk_softc *sc;
2464 struct sk_bcom_hack bhack[] = {
2465 { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1104 }, { 0x17, 0x0013 },
2466 { 0x15, 0x0404 }, { 0x17, 0x8006 }, { 0x15, 0x0132 }, { 0x17, 0x8006 },
2467 { 0x15, 0x0232 }, { 0x17, 0x800D }, { 0x15, 0x000F }, { 0x18, 0x0420 },
2470 sc = sc_if->sk_softc;
2471 ifp = &sc_if->arpcom.ac_if;
2473 /* Unreset the XMAC. */
2474 SK_IF_WRITE_2(sc_if, 0, SK_TXF1_MACCTL, SK_TXMACCTL_XMAC_UNRESET);
2477 /* Reset the XMAC's internal state. */
2478 SK_XM_SETBIT_2(sc_if, XM_GPIO, XM_GPIO_RESETMAC);
2480 /* Save the XMAC II revision */
2481 sc_if->sk_xmac_rev = XM_XMAC_REV(SK_XM_READ_4(sc_if, XM_DEVID));
2484 * Perform additional initialization for external PHYs,
2485 * namely for the 1000baseTX cards that use the XMAC's
2488 if (sc_if->sk_phytype == SK_PHYTYPE_BCOM) {
2492 /* Take PHY out of reset. */
2493 val = sk_win_read_4(sc, SK_GPIO);
2494 if (sc_if->sk_port == SK_PORT_A)
2495 val |= SK_GPIO_DIR0|SK_GPIO_DAT0;
2497 val |= SK_GPIO_DIR2|SK_GPIO_DAT2;
2498 sk_win_write_4(sc, SK_GPIO, val);
2500 /* Enable GMII mode on the XMAC. */
2501 SK_XM_SETBIT_2(sc_if, XM_HWCFG, XM_HWCFG_GMIIMODE);
2503 sk_xmac_miibus_writereg(sc_if, SK_PHYADDR_BCOM,
2504 BRGPHY_MII_BMCR, BRGPHY_BMCR_RESET);
2506 sk_xmac_miibus_writereg(sc_if, SK_PHYADDR_BCOM,
2507 BRGPHY_MII_IMR, 0xFFF0);
2510 * Early versions of the BCM5400 apparently have
2511 * a bug that requires them to have their reserved
2512 * registers initialized to some magic values. I don't
2513 * know what the numbers do, I'm just the messenger.
2515 if (sk_xmac_miibus_readreg(sc_if, SK_PHYADDR_BCOM, 0x03)
2517 while(bhack[i].reg) {
2518 sk_xmac_miibus_writereg(sc_if, SK_PHYADDR_BCOM,
2519 bhack[i].reg, bhack[i].val);
2525 /* Set station address */
2526 SK_XM_WRITE_2(sc_if, XM_PAR0,
2527 *(u_int16_t *)(&sc_if->arpcom.ac_enaddr[0]));
2528 SK_XM_WRITE_2(sc_if, XM_PAR1,
2529 *(u_int16_t *)(&sc_if->arpcom.ac_enaddr[2]));
2530 SK_XM_WRITE_2(sc_if, XM_PAR2,
2531 *(u_int16_t *)(&sc_if->arpcom.ac_enaddr[4]));
2532 SK_XM_SETBIT_4(sc_if, XM_MODE, XM_MODE_RX_USE_STATION);
2534 if (ifp->if_flags & IFF_BROADCAST) {
2535 SK_XM_CLRBIT_4(sc_if, XM_MODE, XM_MODE_RX_NOBROAD);
2537 SK_XM_SETBIT_4(sc_if, XM_MODE, XM_MODE_RX_NOBROAD);
2540 /* We don't need the FCS appended to the packet. */
2541 SK_XM_SETBIT_2(sc_if, XM_RXCMD, XM_RXCMD_STRIPFCS);
2543 /* We want short frames padded to 60 bytes. */
2544 SK_XM_SETBIT_2(sc_if, XM_TXCMD, XM_TXCMD_AUTOPAD);
2547 * Enable the reception of all error frames. This is is
2548 * a necessary evil due to the design of the XMAC. The
2549 * XMAC's receive FIFO is only 8K in size, however jumbo
2550 * frames can be up to 9000 bytes in length. When bad
2551 * frame filtering is enabled, the XMAC's RX FIFO operates
2552 * in 'store and forward' mode. For this to work, the
2553 * entire frame has to fit into the FIFO, but that means
2554 * that jumbo frames larger than 8192 bytes will be
2555 * truncated. Disabling all bad frame filtering causes
2556 * the RX FIFO to operate in streaming mode, in which
2557 * case the XMAC will start transfering frames out of the
2558 * RX FIFO as soon as the FIFO threshold is reached.
2560 SK_XM_SETBIT_4(sc_if, XM_MODE, XM_MODE_RX_BADFRAMES|
2561 XM_MODE_RX_GIANTS|XM_MODE_RX_RUNTS|XM_MODE_RX_CRCERRS|
2562 XM_MODE_RX_INRANGELEN);
2564 if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN))
2565 SK_XM_SETBIT_2(sc_if, XM_RXCMD, XM_RXCMD_BIGPKTOK);
2567 SK_XM_CLRBIT_2(sc_if, XM_RXCMD, XM_RXCMD_BIGPKTOK);
2570 * Bump up the transmit threshold. This helps hold off transmit
2571 * underruns when we're blasting traffic from both ports at once.
2573 SK_XM_WRITE_2(sc_if, XM_TX_REQTHRESH, SK_XM_TX_FIFOTHRESH);
2575 /* Set promiscuous mode */
2576 sk_setpromisc(sc_if);
2578 /* Set multicast filter */
2581 /* Clear and enable interrupts */
2582 SK_XM_READ_2(sc_if, XM_ISR);
2583 if (sc_if->sk_phytype == SK_PHYTYPE_XMAC)
2584 SK_XM_WRITE_2(sc_if, XM_IMR, XM_INTRS);
2586 SK_XM_WRITE_2(sc_if, XM_IMR, 0xFFFF);
2588 /* Configure MAC arbiter */
2589 switch(sc_if->sk_xmac_rev) {
2590 case XM_XMAC_REV_B2:
2591 sk_win_write_1(sc, SK_RCINIT_RX1, SK_RCINIT_XMAC_B2);
2592 sk_win_write_1(sc, SK_RCINIT_TX1, SK_RCINIT_XMAC_B2);
2593 sk_win_write_1(sc, SK_RCINIT_RX2, SK_RCINIT_XMAC_B2);
2594 sk_win_write_1(sc, SK_RCINIT_TX2, SK_RCINIT_XMAC_B2);
2595 sk_win_write_1(sc, SK_MINIT_RX1, SK_MINIT_XMAC_B2);
2596 sk_win_write_1(sc, SK_MINIT_TX1, SK_MINIT_XMAC_B2);
2597 sk_win_write_1(sc, SK_MINIT_RX2, SK_MINIT_XMAC_B2);
2598 sk_win_write_1(sc, SK_MINIT_TX2, SK_MINIT_XMAC_B2);
2599 sk_win_write_1(sc, SK_RECOVERY_CTL, SK_RECOVERY_XMAC_B2);
2601 case XM_XMAC_REV_C1:
2602 sk_win_write_1(sc, SK_RCINIT_RX1, SK_RCINIT_XMAC_C1);
2603 sk_win_write_1(sc, SK_RCINIT_TX1, SK_RCINIT_XMAC_C1);
2604 sk_win_write_1(sc, SK_RCINIT_RX2, SK_RCINIT_XMAC_C1);
2605 sk_win_write_1(sc, SK_RCINIT_TX2, SK_RCINIT_XMAC_C1);
2606 sk_win_write_1(sc, SK_MINIT_RX1, SK_MINIT_XMAC_C1);
2607 sk_win_write_1(sc, SK_MINIT_TX1, SK_MINIT_XMAC_C1);
2608 sk_win_write_1(sc, SK_MINIT_RX2, SK_MINIT_XMAC_C1);
2609 sk_win_write_1(sc, SK_MINIT_TX2, SK_MINIT_XMAC_C1);
2610 sk_win_write_1(sc, SK_RECOVERY_CTL, SK_RECOVERY_XMAC_B2);
2615 sk_win_write_2(sc, SK_MACARB_CTL,
2616 SK_MACARBCTL_UNRESET|SK_MACARBCTL_FASTOE_OFF);
2624 sk_init_yukon(sc_if)
2625 struct sk_if_softc *sc_if;
2629 struct sk_softc *sc;
2633 sc = sc_if->sk_softc;
2634 ifp = &sc_if->arpcom.ac_if;
2636 if (sc->sk_type == SK_YUKON_LITE &&
2637 sc->sk_rev == SK_YUKON_LITE_REV_A3) {
2638 /* Take PHY out of reset. */
2639 sk_win_write_4(sc, SK_GPIO,
2640 (sk_win_read_4(sc, SK_GPIO) | SK_GPIO_DIR9) & ~SK_GPIO_DAT9);
2643 /* GMAC and GPHY Reset */
2644 SK_IF_WRITE_4(sc_if, 0, SK_GPHY_CTRL, SK_GPHY_RESET_SET);
2645 SK_IF_WRITE_4(sc_if, 0, SK_GMAC_CTRL, SK_GMAC_RESET_SET);
2647 SK_IF_WRITE_4(sc_if, 0, SK_GMAC_CTRL, SK_GMAC_RESET_CLEAR);
2648 SK_IF_WRITE_4(sc_if, 0, SK_GMAC_CTRL, SK_GMAC_RESET_SET);
2651 phy = SK_GPHY_INT_POL_HI | SK_GPHY_DIS_FC | SK_GPHY_DIS_SLEEP |
2652 SK_GPHY_ENA_XC | SK_GPHY_ANEG_ALL | SK_GPHY_ENA_PAUSE;
2654 switch(sc_if->sk_softc->sk_pmd) {
2657 phy |= SK_GPHY_FIBER;
2662 phy |= SK_GPHY_COPPER;
2666 SK_IF_WRITE_4(sc_if, 0, SK_GPHY_CTRL, phy | SK_GPHY_RESET_SET);
2668 SK_IF_WRITE_4(sc_if, 0, SK_GPHY_CTRL, phy | SK_GPHY_RESET_CLEAR);
2669 SK_IF_WRITE_4(sc_if, 0, SK_GMAC_CTRL, SK_GMAC_LOOP_OFF |
2670 SK_GMAC_PAUSE_ON | SK_GMAC_RESET_CLEAR);
2672 /* unused read of the interrupt source register */
2673 SK_IF_READ_2(sc_if, 0, SK_GMAC_ISR);
2675 reg = SK_YU_READ_2(sc_if, YUKON_PAR);
2677 /* MIB Counter Clear Mode set */
2678 reg |= YU_PAR_MIB_CLR;
2679 SK_YU_WRITE_2(sc_if, YUKON_PAR, reg);
2681 /* MIB Counter Clear Mode clear */
2682 reg &= ~YU_PAR_MIB_CLR;
2683 SK_YU_WRITE_2(sc_if, YUKON_PAR, reg);
2685 /* receive control reg */
2686 SK_YU_WRITE_2(sc_if, YUKON_RCR, YU_RCR_CRCR);
2688 /* transmit parameter register */
2689 SK_YU_WRITE_2(sc_if, YUKON_TPR, YU_TPR_JAM_LEN(0x3) |
2690 YU_TPR_JAM_IPG(0xb) | YU_TPR_JAM2DATA_IPG(0x1a) );
2692 /* serial mode register */
2693 reg = YU_SMR_DATA_BLIND(0x1c) | YU_SMR_MFL_VLAN | YU_SMR_IPG_DATA(0x1e);
2694 if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN))
2695 reg |= YU_SMR_MFL_JUMBO;
2696 SK_YU_WRITE_2(sc_if, YUKON_SMR, reg);
2698 /* Setup Yukon's address */
2699 for (i = 0; i < 3; i++) {
2700 /* Write Source Address 1 (unicast filter) */
2701 SK_YU_WRITE_2(sc_if, YUKON_SAL1 + i * 4,
2702 sc_if->arpcom.ac_enaddr[i * 2] |
2703 sc_if->arpcom.ac_enaddr[i * 2 + 1] << 8);
2706 for (i = 0; i < 3; i++) {
2707 reg = sk_win_read_2(sc_if->sk_softc,
2708 SK_MAC1_0 + i * 2 + sc_if->sk_port * 8);
2709 SK_YU_WRITE_2(sc_if, YUKON_SAL2 + i * 4, reg);
2712 /* Set promiscuous mode */
2713 sk_setpromisc(sc_if);
2715 /* Set multicast filter */
2718 /* enable interrupt mask for counter overflows */
2719 SK_YU_WRITE_2(sc_if, YUKON_TIMR, 0);
2720 SK_YU_WRITE_2(sc_if, YUKON_RIMR, 0);
2721 SK_YU_WRITE_2(sc_if, YUKON_TRIMR, 0);
2723 /* Configure RX MAC FIFO */
2724 SK_IF_WRITE_1(sc_if, 0, SK_RXMF1_CTRL_TEST, SK_RFCTL_RESET_CLEAR);
2725 SK_IF_WRITE_4(sc_if, 0, SK_RXMF1_CTRL_TEST, SK_RFCTL_OPERATION_ON);
2727 /* Configure TX MAC FIFO */
2728 SK_IF_WRITE_1(sc_if, 0, SK_TXMF1_CTRL_TEST, SK_TFCTL_RESET_CLEAR);
2729 SK_IF_WRITE_4(sc_if, 0, SK_TXMF1_CTRL_TEST, SK_TFCTL_OPERATION_ON);
2733 * Note that to properly initialize any part of the GEnesis chip,
2734 * you first have to take it out of reset mode.
2740 struct sk_if_softc *sc_if = xsc;
2741 struct sk_softc *sc;
2743 struct mii_data *mii;
2749 ifp = &sc_if->arpcom.ac_if;
2750 sc = sc_if->sk_softc;
2751 mii = device_get_softc(sc_if->sk_miibus);
2753 if (ifp->if_flags & IFF_RUNNING) {
2754 SK_IF_UNLOCK(sc_if);
2758 /* Cancel pending I/O and free all RX/TX buffers. */
2761 if (sc->sk_type == SK_GENESIS) {
2762 /* Configure LINK_SYNC LED */
2763 SK_IF_WRITE_1(sc_if, 0, SK_LINKLED1_CTL, SK_LINKLED_ON);
2764 SK_IF_WRITE_1(sc_if, 0, SK_LINKLED1_CTL,
2765 SK_LINKLED_LINKSYNC_ON);
2767 /* Configure RX LED */
2768 SK_IF_WRITE_1(sc_if, 0, SK_RXLED1_CTL,
2769 SK_RXLEDCTL_COUNTER_START);
2771 /* Configure TX LED */
2772 SK_IF_WRITE_1(sc_if, 0, SK_TXLED1_CTL,
2773 SK_TXLEDCTL_COUNTER_START);
2776 /* Configure I2C registers */
2778 /* Configure XMAC(s) */
2779 switch (sc->sk_type) {
2781 sk_init_xmac(sc_if);
2786 sk_init_yukon(sc_if);
2791 if (sc->sk_type == SK_GENESIS) {
2792 /* Configure MAC FIFOs */
2793 SK_IF_WRITE_4(sc_if, 0, SK_RXF1_CTL, SK_FIFO_UNRESET);
2794 SK_IF_WRITE_4(sc_if, 0, SK_RXF1_END, SK_FIFO_END);
2795 SK_IF_WRITE_4(sc_if, 0, SK_RXF1_CTL, SK_FIFO_ON);
2797 SK_IF_WRITE_4(sc_if, 0, SK_TXF1_CTL, SK_FIFO_UNRESET);
2798 SK_IF_WRITE_4(sc_if, 0, SK_TXF1_END, SK_FIFO_END);
2799 SK_IF_WRITE_4(sc_if, 0, SK_TXF1_CTL, SK_FIFO_ON);
2802 /* Configure transmit arbiter(s) */
2803 SK_IF_WRITE_1(sc_if, 0, SK_TXAR1_COUNTERCTL,
2804 SK_TXARCTL_ON|SK_TXARCTL_FSYNC_ON);
2806 /* Configure RAMbuffers */
2807 SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_CTLTST, SK_RBCTL_UNRESET);
2808 SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_START, sc_if->sk_rx_ramstart);
2809 SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_WR_PTR, sc_if->sk_rx_ramstart);
2810 SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_RD_PTR, sc_if->sk_rx_ramstart);
2811 SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_END, sc_if->sk_rx_ramend);
2812 SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_CTLTST, SK_RBCTL_ON);
2814 SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_CTLTST, SK_RBCTL_UNRESET);
2815 SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_CTLTST, SK_RBCTL_STORENFWD_ON);
2816 SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_START, sc_if->sk_tx_ramstart);
2817 SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_WR_PTR, sc_if->sk_tx_ramstart);
2818 SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_RD_PTR, sc_if->sk_tx_ramstart);
2819 SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_END, sc_if->sk_tx_ramend);
2820 SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_CTLTST, SK_RBCTL_ON);
2822 /* Configure BMUs */
2823 SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_BMU_CSR, SK_RXBMU_ONLINE);
2824 SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_CURADDR_LO,
2825 vtophys(&sc_if->sk_rdata->sk_rx_ring[0]));
2826 SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_CURADDR_HI, 0);
2828 SK_IF_WRITE_4(sc_if, 1, SK_TXQS1_BMU_CSR, SK_TXBMU_ONLINE);
2829 SK_IF_WRITE_4(sc_if, 1, SK_TXQS1_CURADDR_LO,
2830 vtophys(&sc_if->sk_rdata->sk_tx_ring[0]));
2831 SK_IF_WRITE_4(sc_if, 1, SK_TXQS1_CURADDR_HI, 0);
2833 /* Init descriptors */
2834 if (sk_init_rx_ring(sc_if) == ENOBUFS) {
2835 printf("sk%d: initialization failed: no "
2836 "memory for rx buffers\n", sc_if->sk_unit);
2838 SK_IF_UNLOCK(sc_if);
2841 sk_init_tx_ring(sc_if);
2843 /* Set interrupt moderation if changed via sysctl. */
2845 imr = sk_win_read_4(sc, SK_IMTIMERINIT);
2846 if (imr != SK_IM_USECS(sc->sk_int_mod)) {
2847 sk_win_write_4(sc, SK_IMTIMERINIT, SK_IM_USECS(sc->sk_int_mod));
2848 printf("skc%d: interrupt moderation is %d us\n",
2849 sc->sk_unit, sc->sk_int_mod);
2851 /* SK_UNLOCK(sc); */
2853 /* Configure interrupt handling */
2854 CSR_READ_4(sc, SK_ISSR);
2855 if (sc_if->sk_port == SK_PORT_A)
2856 sc->sk_intrmask |= SK_INTRS1;
2858 sc->sk_intrmask |= SK_INTRS2;
2860 sc->sk_intrmask |= SK_ISR_EXTERNAL_REG;
2862 CSR_WRITE_4(sc, SK_IMR, sc->sk_intrmask);
2865 SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_BMU_CSR, SK_RXBMU_RX_START);
2867 switch(sc->sk_type) {
2869 /* Enable XMACs TX and RX state machines */
2870 SK_XM_CLRBIT_2(sc_if, XM_MMUCMD, XM_MMUCMD_IGNPAUSE);
2871 SK_XM_SETBIT_2(sc_if, XM_MMUCMD, XM_MMUCMD_TX_ENB|XM_MMUCMD_RX_ENB);
2876 reg = SK_YU_READ_2(sc_if, YUKON_GPCR);
2877 reg |= YU_GPCR_TXEN | YU_GPCR_RXEN;
2878 reg &= ~(YU_GPCR_SPEED_EN | YU_GPCR_DPLX_EN);
2879 SK_YU_WRITE_2(sc_if, YUKON_GPCR, reg);
2882 ifp->if_flags |= IFF_RUNNING;
2883 ifp->if_flags &= ~IFF_OACTIVE;
2885 SK_IF_UNLOCK(sc_if);
2892 struct sk_if_softc *sc_if;
2895 struct sk_softc *sc;
2899 sc = sc_if->sk_softc;
2900 ifp = &sc_if->arpcom.ac_if;
2902 untimeout(sk_tick, sc_if, sc_if->sk_tick_ch);
2904 if (sc_if->sk_phytype == SK_PHYTYPE_BCOM) {
2907 /* Put PHY back into reset. */
2908 val = sk_win_read_4(sc, SK_GPIO);
2909 if (sc_if->sk_port == SK_PORT_A) {
2910 val |= SK_GPIO_DIR0;
2911 val &= ~SK_GPIO_DAT0;
2913 val |= SK_GPIO_DIR2;
2914 val &= ~SK_GPIO_DAT2;
2916 sk_win_write_4(sc, SK_GPIO, val);
2919 /* Turn off various components of this interface. */
2920 SK_XM_SETBIT_2(sc_if, XM_GPIO, XM_GPIO_RESETMAC);
2921 switch (sc->sk_type) {
2923 SK_IF_WRITE_2(sc_if, 0, SK_TXF1_MACCTL, SK_TXMACCTL_XMAC_RESET);
2924 SK_IF_WRITE_4(sc_if, 0, SK_RXF1_CTL, SK_FIFO_RESET);
2929 SK_IF_WRITE_1(sc_if,0, SK_RXMF1_CTRL_TEST, SK_RFCTL_RESET_SET);
2930 SK_IF_WRITE_1(sc_if,0, SK_TXMF1_CTRL_TEST, SK_TFCTL_RESET_SET);
2933 SK_IF_WRITE_4(sc_if, 0, SK_RXQ1_BMU_CSR, SK_RXBMU_OFFLINE);
2934 SK_IF_WRITE_4(sc_if, 0, SK_RXRB1_CTLTST, SK_RBCTL_RESET|SK_RBCTL_OFF);
2935 SK_IF_WRITE_4(sc_if, 1, SK_TXQS1_BMU_CSR, SK_TXBMU_OFFLINE);
2936 SK_IF_WRITE_4(sc_if, 1, SK_TXRBS1_CTLTST, SK_RBCTL_RESET|SK_RBCTL_OFF);
2937 SK_IF_WRITE_1(sc_if, 0, SK_TXAR1_COUNTERCTL, SK_TXARCTL_OFF);
2938 SK_IF_WRITE_1(sc_if, 0, SK_RXLED1_CTL, SK_RXLEDCTL_COUNTER_STOP);
2939 SK_IF_WRITE_1(sc_if, 0, SK_TXLED1_CTL, SK_RXLEDCTL_COUNTER_STOP);
2940 SK_IF_WRITE_1(sc_if, 0, SK_LINKLED1_CTL, SK_LINKLED_OFF);
2941 SK_IF_WRITE_1(sc_if, 0, SK_LINKLED1_CTL, SK_LINKLED_LINKSYNC_OFF);
2943 /* Disable interrupts */
2944 if (sc_if->sk_port == SK_PORT_A)
2945 sc->sk_intrmask &= ~SK_INTRS1;
2947 sc->sk_intrmask &= ~SK_INTRS2;
2948 CSR_WRITE_4(sc, SK_IMR, sc->sk_intrmask);
2950 SK_XM_READ_2(sc_if, XM_ISR);
2951 SK_XM_WRITE_2(sc_if, XM_IMR, 0xFFFF);
2953 /* Free RX and TX mbufs still in the queues. */
2954 for (i = 0; i < SK_RX_RING_CNT; i++) {
2955 if (sc_if->sk_cdata.sk_rx_chain[i].sk_mbuf != NULL) {
2956 m_freem(sc_if->sk_cdata.sk_rx_chain[i].sk_mbuf);
2957 sc_if->sk_cdata.sk_rx_chain[i].sk_mbuf = NULL;
2961 for (i = 0; i < SK_TX_RING_CNT; i++) {
2962 if (sc_if->sk_cdata.sk_tx_chain[i].sk_mbuf != NULL) {
2963 m_freem(sc_if->sk_cdata.sk_tx_chain[i].sk_mbuf);
2964 sc_if->sk_cdata.sk_tx_chain[i].sk_mbuf = NULL;
2968 ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
2969 SK_IF_UNLOCK(sc_if);
2974 sysctl_int_range(SYSCTL_HANDLER_ARGS, int low, int high)
2980 value = *(int *)arg1;
2981 error = sysctl_handle_int(oidp, &value, 0, req);
2982 if (error || !req->newptr)
2984 if (value < low || value > high)
2986 *(int *)arg1 = value;
2991 sysctl_hw_sk_int_mod(SYSCTL_HANDLER_ARGS)
2993 return (sysctl_int_range(oidp, arg1, arg2, req, SK_IM_MIN, SK_IM_MAX));