2 * Copyright (c) 2001-2003, Shunsuke Akiyama <akiyama@FreeBSD.org>.
3 * Copyright (c) 1997, 1998, 1999, 2000 Bill Paul <wpaul@ee.columbia.edu>.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SPDX-License-Identifier: BSD-4-Clause AND BSD-2-Clause-FreeBSD
30 * Copyright (c) 1997, 1998, 1999, 2000
31 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by Bill Paul.
44 * 4. Neither the name of the author nor the names of any co-contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
52 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
53 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
54 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
55 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
56 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
57 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
58 * THE POSSIBILITY OF SUCH DAMAGE.
61 #include <sys/cdefs.h>
62 __FBSDID("$FreeBSD$");
65 * RealTek RTL8150 USB to fast ethernet controller driver.
66 * Datasheet is available from
67 * ftp://ftp.realtek.com.tw/lancard/data_sheet/8150/.
70 #include <sys/stdint.h>
71 #include <sys/stddef.h>
72 #include <sys/param.h>
73 #include <sys/queue.h>
74 #include <sys/types.h>
75 #include <sys/systm.h>
76 #include <sys/socket.h>
77 #include <sys/kernel.h>
79 #include <sys/module.h>
81 #include <sys/mutex.h>
82 #include <sys/condvar.h>
83 #include <sys/sysctl.h>
85 #include <sys/unistd.h>
86 #include <sys/callout.h>
87 #include <sys/malloc.h>
91 #include <net/if_var.h>
92 #include <net/if_media.h>
94 #include <dev/mii/mii.h>
95 #include <dev/mii/miivar.h>
97 #include <dev/usb/usb.h>
98 #include <dev/usb/usbdi.h>
99 #include <dev/usb/usbdi_util.h>
102 #define USB_DEBUG_VAR rue_debug
103 #include <dev/usb/usb_debug.h>
104 #include <dev/usb/usb_process.h>
106 #include <dev/usb/net/usb_ethernet.h>
107 #include <dev/usb/net/if_ruereg.h>
109 #include "miibus_if.h"
112 static int rue_debug = 0;
114 static SYSCTL_NODE(_hw_usb, OID_AUTO, rue, CTLFLAG_RW, 0, "USB rue");
115 SYSCTL_INT(_hw_usb_rue, OID_AUTO, debug, CTLFLAG_RWTUN,
116 &rue_debug, 0, "Debug level");
120 * Various supported device vendors/products.
123 static const STRUCT_USB_HOST_ID rue_devs[] = {
124 {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUAKTX, 0)},
125 {USB_VPI(USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_USBKR100, 0)},
126 {USB_VPI(USB_VENDOR_OQO, USB_PRODUCT_OQO_ETHER01, 0)},
131 static device_probe_t rue_probe;
132 static device_attach_t rue_attach;
133 static device_detach_t rue_detach;
135 static miibus_readreg_t rue_miibus_readreg;
136 static miibus_writereg_t rue_miibus_writereg;
137 static miibus_statchg_t rue_miibus_statchg;
139 static usb_callback_t rue_intr_callback;
140 static usb_callback_t rue_bulk_read_callback;
141 static usb_callback_t rue_bulk_write_callback;
143 static uether_fn_t rue_attach_post;
144 static uether_fn_t rue_init;
145 static uether_fn_t rue_stop;
146 static uether_fn_t rue_start;
147 static uether_fn_t rue_tick;
148 static uether_fn_t rue_setmulti;
149 static uether_fn_t rue_setpromisc;
151 static int rue_read_mem(struct rue_softc *, uint16_t, void *, int);
152 static int rue_write_mem(struct rue_softc *, uint16_t, void *, int);
153 static uint8_t rue_csr_read_1(struct rue_softc *, uint16_t);
154 static uint16_t rue_csr_read_2(struct rue_softc *, uint16_t);
155 static int rue_csr_write_1(struct rue_softc *, uint16_t, uint8_t);
156 static int rue_csr_write_2(struct rue_softc *, uint16_t, uint16_t);
157 static int rue_csr_write_4(struct rue_softc *, int, uint32_t);
159 static void rue_reset(struct rue_softc *);
160 static int rue_ifmedia_upd(struct ifnet *);
161 static void rue_ifmedia_sts(struct ifnet *, struct ifmediareq *);
163 static const struct usb_config rue_config[RUE_N_TRANSFER] = {
167 .endpoint = UE_ADDR_ANY,
168 .direction = UE_DIR_OUT,
170 .flags = {.pipe_bof = 1,.force_short_xfer = 1,},
171 .callback = rue_bulk_write_callback,
172 .timeout = 10000, /* 10 seconds */
177 .endpoint = UE_ADDR_ANY,
178 .direction = UE_DIR_IN,
179 .bufsize = (MCLBYTES + 4),
180 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
181 .callback = rue_bulk_read_callback,
182 .timeout = 0, /* no timeout */
186 .type = UE_INTERRUPT,
187 .endpoint = UE_ADDR_ANY,
188 .direction = UE_DIR_IN,
189 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
190 .bufsize = 0, /* use wMaxPacketSize */
191 .callback = rue_intr_callback,
195 static device_method_t rue_methods[] = {
196 /* Device interface */
197 DEVMETHOD(device_probe, rue_probe),
198 DEVMETHOD(device_attach, rue_attach),
199 DEVMETHOD(device_detach, rue_detach),
202 DEVMETHOD(miibus_readreg, rue_miibus_readreg),
203 DEVMETHOD(miibus_writereg, rue_miibus_writereg),
204 DEVMETHOD(miibus_statchg, rue_miibus_statchg),
209 static driver_t rue_driver = {
211 .methods = rue_methods,
212 .size = sizeof(struct rue_softc),
215 static devclass_t rue_devclass;
217 DRIVER_MODULE_ORDERED(rue, uhub, rue_driver, rue_devclass, NULL, NULL,
219 DRIVER_MODULE(miibus, rue, miibus_driver, miibus_devclass, NULL, NULL);
220 MODULE_DEPEND(rue, uether, 1, 1, 1);
221 MODULE_DEPEND(rue, usb, 1, 1, 1);
222 MODULE_DEPEND(rue, ether, 1, 1, 1);
223 MODULE_DEPEND(rue, miibus, 1, 1, 1);
224 MODULE_VERSION(rue, 1);
225 USB_PNP_HOST_INFO(rue_devs);
227 static const struct usb_ether_methods rue_ue_methods = {
228 .ue_attach_post = rue_attach_post,
229 .ue_start = rue_start,
233 .ue_setmulti = rue_setmulti,
234 .ue_setpromisc = rue_setpromisc,
235 .ue_mii_upd = rue_ifmedia_upd,
236 .ue_mii_sts = rue_ifmedia_sts,
239 #define RUE_SETBIT(sc, reg, x) \
240 rue_csr_write_1(sc, reg, rue_csr_read_1(sc, reg) | (x))
242 #define RUE_CLRBIT(sc, reg, x) \
243 rue_csr_write_1(sc, reg, rue_csr_read_1(sc, reg) & ~(x))
246 rue_read_mem(struct rue_softc *sc, uint16_t addr, void *buf, int len)
248 struct usb_device_request req;
250 req.bmRequestType = UT_READ_VENDOR_DEVICE;
251 req.bRequest = UR_SET_ADDRESS;
252 USETW(req.wValue, addr);
253 USETW(req.wIndex, 0);
254 USETW(req.wLength, len);
256 return (uether_do_request(&sc->sc_ue, &req, buf, 1000));
260 rue_write_mem(struct rue_softc *sc, uint16_t addr, void *buf, int len)
262 struct usb_device_request req;
264 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
265 req.bRequest = UR_SET_ADDRESS;
266 USETW(req.wValue, addr);
267 USETW(req.wIndex, 0);
268 USETW(req.wLength, len);
270 return (uether_do_request(&sc->sc_ue, &req, buf, 1000));
274 rue_csr_read_1(struct rue_softc *sc, uint16_t reg)
278 rue_read_mem(sc, reg, &val, 1);
283 rue_csr_read_2(struct rue_softc *sc, uint16_t reg)
287 rue_read_mem(sc, reg, &val, 2);
292 rue_csr_write_1(struct rue_softc *sc, uint16_t reg, uint8_t val)
294 return (rue_write_mem(sc, reg, &val, 1));
298 rue_csr_write_2(struct rue_softc *sc, uint16_t reg, uint16_t val)
303 return (rue_write_mem(sc, reg, &temp, 2));
307 rue_csr_write_4(struct rue_softc *sc, int reg, uint32_t val)
312 return (rue_write_mem(sc, reg, &temp, 4));
316 rue_miibus_readreg(device_t dev, int phy, int reg)
318 struct rue_softc *sc = device_get_softc(dev);
323 if (phy != 0) /* RTL8150 supports PHY == 0, only */
326 locked = mtx_owned(&sc->sc_mtx);
351 if (RUE_REG_MIN <= reg && reg <= RUE_REG_MAX) {
352 rval = rue_csr_read_1(sc, reg);
355 device_printf(sc->sc_ue.ue_dev, "bad phy register\n");
360 rval = rue_csr_read_2(sc, ruereg);
368 rue_miibus_writereg(device_t dev, int phy, int reg, int data)
370 struct rue_softc *sc = device_get_softc(dev);
374 if (phy != 0) /* RTL8150 supports PHY == 0, only */
377 locked = mtx_owned(&sc->sc_mtx);
401 if (RUE_REG_MIN <= reg && reg <= RUE_REG_MAX) {
402 rue_csr_write_1(sc, reg, data);
405 device_printf(sc->sc_ue.ue_dev, " bad phy register\n");
408 rue_csr_write_2(sc, ruereg, data);
416 rue_miibus_statchg(device_t dev)
419 * When the code below is enabled the card starts doing weird
420 * things after link going from UP to DOWN and back UP.
422 * Looks like some of register writes below messes up PHY
425 * No visible regressions were found after commenting this code
426 * out, so that disable it for good.
429 struct rue_softc *sc = device_get_softc(dev);
430 struct mii_data *mii = GET_MII(sc);
434 locked = mtx_owned(&sc->sc_mtx);
438 RUE_CLRBIT(sc, RUE_CR, (RUE_CR_RE | RUE_CR_TE));
440 bmcr = rue_csr_read_2(sc, RUE_BMCR);
442 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX)
443 bmcr |= RUE_BMCR_SPD_SET;
445 bmcr &= ~RUE_BMCR_SPD_SET;
447 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX)
448 bmcr |= RUE_BMCR_DUPLEX;
450 bmcr &= ~RUE_BMCR_DUPLEX;
452 rue_csr_write_2(sc, RUE_BMCR, bmcr);
454 RUE_SETBIT(sc, RUE_CR, (RUE_CR_RE | RUE_CR_TE));
462 rue_setpromisc(struct usb_ether *ue)
464 struct rue_softc *sc = uether_getsc(ue);
465 struct ifnet *ifp = uether_getifp(ue);
467 RUE_LOCK_ASSERT(sc, MA_OWNED);
469 /* If we want promiscuous mode, set the allframes bit. */
470 if (ifp->if_flags & IFF_PROMISC)
471 RUE_SETBIT(sc, RUE_RCR, RUE_RCR_AAP);
473 RUE_CLRBIT(sc, RUE_RCR, RUE_RCR_AAP);
477 * Program the 64-bit multicast hash filter.
480 rue_setmulti(struct usb_ether *ue)
482 struct rue_softc *sc = uether_getsc(ue);
483 struct ifnet *ifp = uether_getifp(ue);
486 uint32_t hashes[2] = { 0, 0 };
487 struct ifmultiaddr *ifma;
490 RUE_LOCK_ASSERT(sc, MA_OWNED);
492 rxcfg = rue_csr_read_2(sc, RUE_RCR);
494 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
495 rxcfg |= (RUE_RCR_AAM | RUE_RCR_AAP);
496 rxcfg &= ~RUE_RCR_AM;
497 rue_csr_write_2(sc, RUE_RCR, rxcfg);
498 rue_csr_write_4(sc, RUE_MAR0, 0xFFFFFFFF);
499 rue_csr_write_4(sc, RUE_MAR4, 0xFFFFFFFF);
503 /* first, zot all the existing hash bits */
504 rue_csr_write_4(sc, RUE_MAR0, 0);
505 rue_csr_write_4(sc, RUE_MAR4, 0);
507 /* now program new ones */
509 CK_STAILQ_FOREACH (ifma, &ifp->if_multiaddrs, ifma_link)
511 if (ifma->ifma_addr->sa_family != AF_LINK)
513 h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
514 ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
516 hashes[0] |= (1 << h);
518 hashes[1] |= (1 << (h - 32));
521 if_maddr_runlock(ifp);
526 rxcfg &= ~RUE_RCR_AM;
528 rxcfg &= ~(RUE_RCR_AAM | RUE_RCR_AAP);
530 rue_csr_write_2(sc, RUE_RCR, rxcfg);
531 rue_csr_write_4(sc, RUE_MAR0, hashes[0]);
532 rue_csr_write_4(sc, RUE_MAR4, hashes[1]);
536 rue_reset(struct rue_softc *sc)
540 rue_csr_write_1(sc, RUE_CR, RUE_CR_SOFT_RST);
542 for (i = 0; i != RUE_TIMEOUT; i++) {
543 if (uether_pause(&sc->sc_ue, hz / 1000))
545 if (!(rue_csr_read_1(sc, RUE_CR) & RUE_CR_SOFT_RST))
548 if (i == RUE_TIMEOUT)
549 device_printf(sc->sc_ue.ue_dev, "reset never completed\n");
551 uether_pause(&sc->sc_ue, hz / 100);
555 rue_attach_post(struct usb_ether *ue)
557 struct rue_softc *sc = uether_getsc(ue);
559 /* reset the adapter */
562 /* get station address from the EEPROM */
563 rue_read_mem(sc, RUE_EEPROM_IDR0, ue->ue_eaddr, ETHER_ADDR_LEN);
567 * Probe for a RTL8150 chip.
570 rue_probe(device_t dev)
572 struct usb_attach_arg *uaa = device_get_ivars(dev);
574 if (uaa->usb_mode != USB_MODE_HOST)
576 if (uaa->info.bConfigIndex != RUE_CONFIG_IDX)
578 if (uaa->info.bIfaceIndex != RUE_IFACE_IDX)
581 return (usbd_lookup_id_by_uaa(rue_devs, sizeof(rue_devs), uaa));
585 * Attach the interface. Allocate softc structures, do ifmedia
586 * setup and ethernet/BPF attach.
589 rue_attach(device_t dev)
591 struct usb_attach_arg *uaa = device_get_ivars(dev);
592 struct rue_softc *sc = device_get_softc(dev);
593 struct usb_ether *ue = &sc->sc_ue;
597 device_set_usb_desc(dev);
598 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF);
600 iface_index = RUE_IFACE_IDX;
601 error = usbd_transfer_setup(uaa->device, &iface_index,
602 sc->sc_xfer, rue_config, RUE_N_TRANSFER,
605 device_printf(dev, "allocating USB transfers failed\n");
611 ue->ue_udev = uaa->device;
612 ue->ue_mtx = &sc->sc_mtx;
613 ue->ue_methods = &rue_ue_methods;
615 error = uether_ifattach(ue);
617 device_printf(dev, "could not attach interface\n");
620 return (0); /* success */
624 return (ENXIO); /* failure */
628 rue_detach(device_t dev)
630 struct rue_softc *sc = device_get_softc(dev);
631 struct usb_ether *ue = &sc->sc_ue;
633 usbd_transfer_unsetup(sc->sc_xfer, RUE_N_TRANSFER);
635 mtx_destroy(&sc->sc_mtx);
641 rue_intr_callback(struct usb_xfer *xfer, usb_error_t error)
643 struct rue_softc *sc = usbd_xfer_softc(xfer);
644 struct ifnet *ifp = uether_getifp(&sc->sc_ue);
645 struct rue_intrpkt pkt;
646 struct usb_page_cache *pc;
649 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
651 switch (USB_GET_STATE(xfer)) {
652 case USB_ST_TRANSFERRED:
654 if (ifp && (ifp->if_drv_flags & IFF_DRV_RUNNING) &&
655 actlen >= (int)sizeof(pkt)) {
657 pc = usbd_xfer_get_frame(xfer, 0);
658 usbd_copy_out(pc, 0, &pkt, sizeof(pkt));
660 if_inc_counter(ifp, IFCOUNTER_IERRORS, pkt.rue_rxlost_cnt);
661 if_inc_counter(ifp, IFCOUNTER_IERRORS, pkt.rue_crcerr_cnt);
662 if_inc_counter(ifp, IFCOUNTER_COLLISIONS, pkt.rue_col_cnt);
667 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
668 usbd_transfer_submit(xfer);
672 if (error != USB_ERR_CANCELLED) {
673 /* try to clear stall first */
674 usbd_xfer_set_stall(xfer);
682 rue_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
684 struct rue_softc *sc = usbd_xfer_softc(xfer);
685 struct usb_ether *ue = &sc->sc_ue;
686 struct ifnet *ifp = uether_getifp(ue);
687 struct usb_page_cache *pc;
691 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
693 switch (USB_GET_STATE(xfer)) {
694 case USB_ST_TRANSFERRED:
697 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
700 pc = usbd_xfer_get_frame(xfer, 0);
701 usbd_copy_out(pc, actlen - 4, &status, sizeof(status));
704 /* check receive packet was valid or not */
705 status = le16toh(status);
706 if ((status & RUE_RXSTAT_VALID) == 0) {
707 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
710 uether_rxbuf(ue, pc, 0, actlen);
714 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
715 usbd_transfer_submit(xfer);
720 DPRINTF("bulk read error, %s\n",
723 if (error != USB_ERR_CANCELLED) {
724 /* try to clear stall first */
725 usbd_xfer_set_stall(xfer);
733 rue_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
735 struct rue_softc *sc = usbd_xfer_softc(xfer);
736 struct ifnet *ifp = uether_getifp(&sc->sc_ue);
737 struct usb_page_cache *pc;
741 switch (USB_GET_STATE(xfer)) {
742 case USB_ST_TRANSFERRED:
743 DPRINTFN(11, "transfer complete\n");
744 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
749 if ((sc->sc_flags & RUE_FLAG_LINK) == 0) {
751 * don't send anything if there is no link !
755 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
759 if (m->m_pkthdr.len > MCLBYTES)
760 m->m_pkthdr.len = MCLBYTES;
761 temp_len = m->m_pkthdr.len;
763 pc = usbd_xfer_get_frame(xfer, 0);
764 usbd_m_copy_in(pc, 0, m, 0, m->m_pkthdr.len);
767 * This is an undocumented behavior.
768 * RTL8150 chip doesn't send frame length smaller than
769 * RUE_MIN_FRAMELEN (60) byte packet.
771 if (temp_len < RUE_MIN_FRAMELEN) {
772 usbd_frame_zero(pc, temp_len,
773 RUE_MIN_FRAMELEN - temp_len);
774 temp_len = RUE_MIN_FRAMELEN;
776 usbd_xfer_set_frame_len(xfer, 0, temp_len);
779 * if there's a BPF listener, bounce a copy
780 * of this frame to him:
786 usbd_transfer_submit(xfer);
791 DPRINTFN(11, "transfer error, %s\n",
794 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
796 if (error != USB_ERR_CANCELLED) {
797 /* try to clear stall first */
798 usbd_xfer_set_stall(xfer);
806 rue_tick(struct usb_ether *ue)
808 struct rue_softc *sc = uether_getsc(ue);
809 struct mii_data *mii = GET_MII(sc);
811 RUE_LOCK_ASSERT(sc, MA_OWNED);
814 if ((sc->sc_flags & RUE_FLAG_LINK) == 0
815 && mii->mii_media_status & IFM_ACTIVE &&
816 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
817 sc->sc_flags |= RUE_FLAG_LINK;
823 rue_start(struct usb_ether *ue)
825 struct rue_softc *sc = uether_getsc(ue);
828 * start the USB transfers, if not already started:
830 usbd_transfer_start(sc->sc_xfer[RUE_INTR_DT_RD]);
831 usbd_transfer_start(sc->sc_xfer[RUE_BULK_DT_RD]);
832 usbd_transfer_start(sc->sc_xfer[RUE_BULK_DT_WR]);
836 rue_init(struct usb_ether *ue)
838 struct rue_softc *sc = uether_getsc(ue);
839 struct ifnet *ifp = uether_getifp(ue);
841 RUE_LOCK_ASSERT(sc, MA_OWNED);
848 /* Set MAC address */
849 rue_write_mem(sc, RUE_IDR0, IF_LLADDR(ifp), ETHER_ADDR_LEN);
854 * Set the initial TX and RX configuration.
856 rue_csr_write_1(sc, RUE_TCR, RUE_TCR_CONFIG);
857 rue_csr_write_2(sc, RUE_RCR, RUE_RCR_CONFIG|RUE_RCR_AB);
859 /* Load the multicast filter */
861 /* Load the multicast filter. */
864 /* Enable RX and TX */
865 rue_csr_write_1(sc, RUE_CR, (RUE_CR_TE | RUE_CR_RE | RUE_CR_EP3CLREN));
867 usbd_xfer_set_stall(sc->sc_xfer[RUE_BULK_DT_WR]);
869 ifp->if_drv_flags |= IFF_DRV_RUNNING;
877 rue_ifmedia_upd(struct ifnet *ifp)
879 struct rue_softc *sc = ifp->if_softc;
880 struct mii_data *mii = GET_MII(sc);
881 struct mii_softc *miisc;
884 RUE_LOCK_ASSERT(sc, MA_OWNED);
886 sc->sc_flags &= ~RUE_FLAG_LINK;
887 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
889 error = mii_mediachg(mii);
894 * Report current media status.
897 rue_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
899 struct rue_softc *sc = ifp->if_softc;
900 struct mii_data *mii = GET_MII(sc);
904 ifmr->ifm_active = mii->mii_media_active;
905 ifmr->ifm_status = mii->mii_media_status;
910 rue_stop(struct usb_ether *ue)
912 struct rue_softc *sc = uether_getsc(ue);
913 struct ifnet *ifp = uether_getifp(ue);
915 RUE_LOCK_ASSERT(sc, MA_OWNED);
917 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
918 sc->sc_flags &= ~RUE_FLAG_LINK;
921 * stop all the transfers, if not already stopped:
923 usbd_transfer_stop(sc->sc_xfer[RUE_BULK_DT_WR]);
924 usbd_transfer_stop(sc->sc_xfer[RUE_BULK_DT_RD]);
925 usbd_transfer_stop(sc->sc_xfer[RUE_INTR_DT_RD]);
927 rue_csr_write_1(sc, RUE_CR, 0x00);