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 * Copyright (c) 1997, 1998, 1999, 2000
29 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by Bill Paul.
42 * 4. Neither the name of the author nor the names of any co-contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
50 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
51 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
52 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
56 * THE POSSIBILITY OF SUCH DAMAGE.
59 #include <sys/cdefs.h>
60 __FBSDID("$FreeBSD$");
63 * RealTek RTL8150 USB to fast ethernet controller driver.
64 * Datasheet is available from
65 * ftp://ftp.realtek.com.tw/lancard/data_sheet/8150/.
68 #include <sys/stdint.h>
69 #include <sys/stddef.h>
70 #include <sys/param.h>
71 #include <sys/queue.h>
72 #include <sys/types.h>
73 #include <sys/systm.h>
74 #include <sys/kernel.h>
76 #include <sys/linker_set.h>
77 #include <sys/module.h>
79 #include <sys/mutex.h>
80 #include <sys/condvar.h>
81 #include <sys/sysctl.h>
83 #include <sys/unistd.h>
84 #include <sys/callout.h>
85 #include <sys/malloc.h>
88 #include <dev/usb/usb.h>
89 #include <dev/usb/usbdi.h>
90 #include <dev/usb/usbdi_util.h>
93 #define USB_DEBUG_VAR rue_debug
94 #include <dev/usb/usb_debug.h>
95 #include <dev/usb/usb_process.h>
97 #include <dev/usb/net/usb_ethernet.h>
98 #include <dev/usb/net/if_ruereg.h>
101 static int rue_debug = 0;
103 SYSCTL_NODE(_hw_usb, OID_AUTO, rue, CTLFLAG_RW, 0, "USB rue");
104 SYSCTL_INT(_hw_usb_rue, OID_AUTO, debug, CTLFLAG_RW,
105 &rue_debug, 0, "Debug level");
109 * Various supported device vendors/products.
112 static const struct usb_device_id rue_devs[] = {
113 {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUAKTX, 0)},
114 {USB_VPI(USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_USBKR100, 0)},
119 static device_probe_t rue_probe;
120 static device_attach_t rue_attach;
121 static device_detach_t rue_detach;
123 static miibus_readreg_t rue_miibus_readreg;
124 static miibus_writereg_t rue_miibus_writereg;
125 static miibus_statchg_t rue_miibus_statchg;
127 static usb_callback_t rue_intr_callback;
128 static usb_callback_t rue_bulk_read_callback;
129 static usb_callback_t rue_bulk_write_callback;
131 static uether_fn_t rue_attach_post;
132 static uether_fn_t rue_init;
133 static uether_fn_t rue_stop;
134 static uether_fn_t rue_start;
135 static uether_fn_t rue_tick;
136 static uether_fn_t rue_setmulti;
137 static uether_fn_t rue_setpromisc;
139 static int rue_read_mem(struct rue_softc *, uint16_t, void *, int);
140 static int rue_write_mem(struct rue_softc *, uint16_t, void *, int);
141 static uint8_t rue_csr_read_1(struct rue_softc *, uint16_t);
142 static uint16_t rue_csr_read_2(struct rue_softc *, uint16_t);
143 static int rue_csr_write_1(struct rue_softc *, uint16_t, uint8_t);
144 static int rue_csr_write_2(struct rue_softc *, uint16_t, uint16_t);
145 static int rue_csr_write_4(struct rue_softc *, int, uint32_t);
147 static void rue_reset(struct rue_softc *);
148 static int rue_ifmedia_upd(struct ifnet *);
149 static void rue_ifmedia_sts(struct ifnet *, struct ifmediareq *);
151 static const struct usb_config rue_config[RUE_N_TRANSFER] = {
155 .endpoint = UE_ADDR_ANY,
156 .direction = UE_DIR_OUT,
158 .flags = {.pipe_bof = 1,.force_short_xfer = 1,},
159 .callback = rue_bulk_write_callback,
160 .timeout = 10000, /* 10 seconds */
165 .endpoint = UE_ADDR_ANY,
166 .direction = UE_DIR_IN,
167 .bufsize = (MCLBYTES + 4),
168 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
169 .callback = rue_bulk_read_callback,
170 .timeout = 0, /* no timeout */
174 .type = UE_INTERRUPT,
175 .endpoint = UE_ADDR_ANY,
176 .direction = UE_DIR_IN,
177 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
178 .bufsize = 0, /* use wMaxPacketSize */
179 .callback = rue_intr_callback,
183 static device_method_t rue_methods[] = {
184 /* Device interface */
185 DEVMETHOD(device_probe, rue_probe),
186 DEVMETHOD(device_attach, rue_attach),
187 DEVMETHOD(device_detach, rue_detach),
190 DEVMETHOD(bus_print_child, bus_generic_print_child),
191 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
194 DEVMETHOD(miibus_readreg, rue_miibus_readreg),
195 DEVMETHOD(miibus_writereg, rue_miibus_writereg),
196 DEVMETHOD(miibus_statchg, rue_miibus_statchg),
201 static driver_t rue_driver = {
203 .methods = rue_methods,
204 .size = sizeof(struct rue_softc),
207 static devclass_t rue_devclass;
209 DRIVER_MODULE(rue, uhub, rue_driver, rue_devclass, NULL, 0);
210 DRIVER_MODULE(miibus, rue, miibus_driver, miibus_devclass, 0, 0);
211 MODULE_DEPEND(rue, uether, 1, 1, 1);
212 MODULE_DEPEND(rue, usb, 1, 1, 1);
213 MODULE_DEPEND(rue, ether, 1, 1, 1);
214 MODULE_DEPEND(rue, miibus, 1, 1, 1);
216 static const struct usb_ether_methods rue_ue_methods = {
217 .ue_attach_post = rue_attach_post,
218 .ue_start = rue_start,
222 .ue_setmulti = rue_setmulti,
223 .ue_setpromisc = rue_setpromisc,
224 .ue_mii_upd = rue_ifmedia_upd,
225 .ue_mii_sts = rue_ifmedia_sts,
228 #define RUE_SETBIT(sc, reg, x) \
229 rue_csr_write_1(sc, reg, rue_csr_read_1(sc, reg) | (x))
231 #define RUE_CLRBIT(sc, reg, x) \
232 rue_csr_write_1(sc, reg, rue_csr_read_1(sc, reg) & ~(x))
235 rue_read_mem(struct rue_softc *sc, uint16_t addr, void *buf, int len)
237 struct usb_device_request req;
239 req.bmRequestType = UT_READ_VENDOR_DEVICE;
240 req.bRequest = UR_SET_ADDRESS;
241 USETW(req.wValue, addr);
242 USETW(req.wIndex, 0);
243 USETW(req.wLength, len);
245 return (uether_do_request(&sc->sc_ue, &req, buf, 1000));
249 rue_write_mem(struct rue_softc *sc, uint16_t addr, void *buf, int len)
251 struct usb_device_request req;
253 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
254 req.bRequest = UR_SET_ADDRESS;
255 USETW(req.wValue, addr);
256 USETW(req.wIndex, 0);
257 USETW(req.wLength, len);
259 return (uether_do_request(&sc->sc_ue, &req, buf, 1000));
263 rue_csr_read_1(struct rue_softc *sc, uint16_t reg)
267 rue_read_mem(sc, reg, &val, 1);
272 rue_csr_read_2(struct rue_softc *sc, uint16_t reg)
276 rue_read_mem(sc, reg, &val, 2);
281 rue_csr_write_1(struct rue_softc *sc, uint16_t reg, uint8_t val)
283 return (rue_write_mem(sc, reg, &val, 1));
287 rue_csr_write_2(struct rue_softc *sc, uint16_t reg, uint16_t val)
292 return (rue_write_mem(sc, reg, &temp, 2));
296 rue_csr_write_4(struct rue_softc *sc, int reg, uint32_t val)
301 return (rue_write_mem(sc, reg, &temp, 4));
305 rue_miibus_readreg(device_t dev, int phy, int reg)
307 struct rue_softc *sc = device_get_softc(dev);
312 if (phy != 0) /* RTL8150 supports PHY == 0, only */
315 locked = mtx_owned(&sc->sc_mtx);
340 if (RUE_REG_MIN <= reg && reg <= RUE_REG_MAX) {
341 rval = rue_csr_read_1(sc, reg);
344 device_printf(sc->sc_ue.ue_dev, "bad phy register\n");
349 rval = rue_csr_read_2(sc, ruereg);
357 rue_miibus_writereg(device_t dev, int phy, int reg, int data)
359 struct rue_softc *sc = device_get_softc(dev);
363 if (phy != 0) /* RTL8150 supports PHY == 0, only */
366 locked = mtx_owned(&sc->sc_mtx);
390 if (RUE_REG_MIN <= reg && reg <= RUE_REG_MAX) {
391 rue_csr_write_1(sc, reg, data);
394 device_printf(sc->sc_ue.ue_dev, " bad phy register\n");
397 rue_csr_write_2(sc, ruereg, data);
405 rue_miibus_statchg(device_t dev)
408 * When the code below is enabled the card starts doing weird
409 * things after link going from UP to DOWN and back UP.
411 * Looks like some of register writes below messes up PHY
414 * No visible regressions were found after commenting this code
415 * out, so that disable it for good.
418 struct rue_softc *sc = device_get_softc(dev);
419 struct mii_data *mii = GET_MII(sc);
423 locked = mtx_owned(&sc->sc_mtx);
427 RUE_CLRBIT(sc, RUE_CR, (RUE_CR_RE | RUE_CR_TE));
429 bmcr = rue_csr_read_2(sc, RUE_BMCR);
431 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX)
432 bmcr |= RUE_BMCR_SPD_SET;
434 bmcr &= ~RUE_BMCR_SPD_SET;
436 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX)
437 bmcr |= RUE_BMCR_DUPLEX;
439 bmcr &= ~RUE_BMCR_DUPLEX;
441 rue_csr_write_2(sc, RUE_BMCR, bmcr);
443 RUE_SETBIT(sc, RUE_CR, (RUE_CR_RE | RUE_CR_TE));
451 rue_setpromisc(struct usb_ether *ue)
453 struct rue_softc *sc = uether_getsc(ue);
454 struct ifnet *ifp = uether_getifp(ue);
456 RUE_LOCK_ASSERT(sc, MA_OWNED);
458 /* If we want promiscuous mode, set the allframes bit. */
459 if (ifp->if_flags & IFF_PROMISC)
460 RUE_SETBIT(sc, RUE_RCR, RUE_RCR_AAP);
462 RUE_CLRBIT(sc, RUE_RCR, RUE_RCR_AAP);
466 * Program the 64-bit multicast hash filter.
469 rue_setmulti(struct usb_ether *ue)
471 struct rue_softc *sc = uether_getsc(ue);
472 struct ifnet *ifp = uether_getifp(ue);
475 uint32_t hashes[2] = { 0, 0 };
476 struct ifmultiaddr *ifma;
479 RUE_LOCK_ASSERT(sc, MA_OWNED);
481 rxcfg = rue_csr_read_2(sc, RUE_RCR);
483 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
484 rxcfg |= (RUE_RCR_AAM | RUE_RCR_AAP);
485 rxcfg &= ~RUE_RCR_AM;
486 rue_csr_write_2(sc, RUE_RCR, rxcfg);
487 rue_csr_write_4(sc, RUE_MAR0, 0xFFFFFFFF);
488 rue_csr_write_4(sc, RUE_MAR4, 0xFFFFFFFF);
492 /* first, zot all the existing hash bits */
493 rue_csr_write_4(sc, RUE_MAR0, 0);
494 rue_csr_write_4(sc, RUE_MAR4, 0);
496 /* now program new ones */
498 TAILQ_FOREACH (ifma, &ifp->if_multiaddrs, ifma_link)
500 if (ifma->ifma_addr->sa_family != AF_LINK)
502 h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
503 ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
505 hashes[0] |= (1 << h);
507 hashes[1] |= (1 << (h - 32));
510 if_maddr_runlock(ifp);
515 rxcfg &= ~RUE_RCR_AM;
517 rxcfg &= ~(RUE_RCR_AAM | RUE_RCR_AAP);
519 rue_csr_write_2(sc, RUE_RCR, rxcfg);
520 rue_csr_write_4(sc, RUE_MAR0, hashes[0]);
521 rue_csr_write_4(sc, RUE_MAR4, hashes[1]);
525 rue_reset(struct rue_softc *sc)
529 rue_csr_write_1(sc, RUE_CR, RUE_CR_SOFT_RST);
531 for (i = 0; i != RUE_TIMEOUT; i++) {
532 if (uether_pause(&sc->sc_ue, hz / 1000))
534 if (!(rue_csr_read_1(sc, RUE_CR) & RUE_CR_SOFT_RST))
537 if (i == RUE_TIMEOUT)
538 device_printf(sc->sc_ue.ue_dev, "reset never completed\n");
540 uether_pause(&sc->sc_ue, hz / 100);
544 rue_attach_post(struct usb_ether *ue)
546 struct rue_softc *sc = uether_getsc(ue);
548 /* reset the adapter */
551 /* get station address from the EEPROM */
552 rue_read_mem(sc, RUE_EEPROM_IDR0, ue->ue_eaddr, ETHER_ADDR_LEN);
556 * Probe for a RTL8150 chip.
559 rue_probe(device_t dev)
561 struct usb_attach_arg *uaa = device_get_ivars(dev);
563 if (uaa->usb_mode != USB_MODE_HOST)
565 if (uaa->info.bConfigIndex != RUE_CONFIG_IDX)
567 if (uaa->info.bIfaceIndex != RUE_IFACE_IDX)
570 return (usbd_lookup_id_by_uaa(rue_devs, sizeof(rue_devs), uaa));
574 * Attach the interface. Allocate softc structures, do ifmedia
575 * setup and ethernet/BPF attach.
578 rue_attach(device_t dev)
580 struct usb_attach_arg *uaa = device_get_ivars(dev);
581 struct rue_softc *sc = device_get_softc(dev);
582 struct usb_ether *ue = &sc->sc_ue;
586 device_set_usb_desc(dev);
587 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF);
589 iface_index = RUE_IFACE_IDX;
590 error = usbd_transfer_setup(uaa->device, &iface_index,
591 sc->sc_xfer, rue_config, RUE_N_TRANSFER,
594 device_printf(dev, "allocating USB transfers failed\n");
600 ue->ue_udev = uaa->device;
601 ue->ue_mtx = &sc->sc_mtx;
602 ue->ue_methods = &rue_ue_methods;
604 error = uether_ifattach(ue);
606 device_printf(dev, "could not attach interface\n");
609 return (0); /* success */
613 return (ENXIO); /* failure */
617 rue_detach(device_t dev)
619 struct rue_softc *sc = device_get_softc(dev);
620 struct usb_ether *ue = &sc->sc_ue;
622 usbd_transfer_unsetup(sc->sc_xfer, RUE_N_TRANSFER);
624 mtx_destroy(&sc->sc_mtx);
630 rue_intr_callback(struct usb_xfer *xfer, usb_error_t error)
632 struct rue_softc *sc = usbd_xfer_softc(xfer);
633 struct ifnet *ifp = uether_getifp(&sc->sc_ue);
634 struct rue_intrpkt pkt;
635 struct usb_page_cache *pc;
638 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
640 switch (USB_GET_STATE(xfer)) {
641 case USB_ST_TRANSFERRED:
643 if (ifp && (ifp->if_drv_flags & IFF_DRV_RUNNING) &&
644 actlen >= sizeof(pkt)) {
646 pc = usbd_xfer_get_frame(xfer, 0);
647 usbd_copy_out(pc, 0, &pkt, sizeof(pkt));
649 ifp->if_ierrors += pkt.rue_rxlost_cnt;
650 ifp->if_ierrors += pkt.rue_crcerr_cnt;
651 ifp->if_collisions += pkt.rue_col_cnt;
656 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
657 usbd_transfer_submit(xfer);
661 if (error != USB_ERR_CANCELLED) {
662 /* try to clear stall first */
663 usbd_xfer_set_stall(xfer);
671 rue_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
673 struct rue_softc *sc = usbd_xfer_softc(xfer);
674 struct usb_ether *ue = &sc->sc_ue;
675 struct ifnet *ifp = uether_getifp(ue);
676 struct usb_page_cache *pc;
680 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
682 switch (USB_GET_STATE(xfer)) {
683 case USB_ST_TRANSFERRED:
689 pc = usbd_xfer_get_frame(xfer, 0);
690 usbd_copy_out(pc, actlen - 4, &status, sizeof(status));
693 /* check recieve packet was valid or not */
694 status = le16toh(status);
695 if ((status & RUE_RXSTAT_VALID) == 0) {
699 uether_rxbuf(ue, pc, 0, actlen);
703 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
704 usbd_transfer_submit(xfer);
709 DPRINTF("bulk read error, %s\n",
712 if (error != USB_ERR_CANCELLED) {
713 /* try to clear stall first */
714 usbd_xfer_set_stall(xfer);
722 rue_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
724 struct rue_softc *sc = usbd_xfer_softc(xfer);
725 struct ifnet *ifp = uether_getifp(&sc->sc_ue);
726 struct usb_page_cache *pc;
730 switch (USB_GET_STATE(xfer)) {
731 case USB_ST_TRANSFERRED:
732 DPRINTFN(11, "transfer complete\n");
738 if ((sc->sc_flags & RUE_FLAG_LINK) == 0) {
740 * don't send anything if there is no link !
744 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
748 if (m->m_pkthdr.len > MCLBYTES)
749 m->m_pkthdr.len = MCLBYTES;
750 temp_len = m->m_pkthdr.len;
752 pc = usbd_xfer_get_frame(xfer, 0);
753 usbd_m_copy_in(pc, 0, m, 0, m->m_pkthdr.len);
756 * This is an undocumented behavior.
757 * RTL8150 chip doesn't send frame length smaller than
758 * RUE_MIN_FRAMELEN (60) byte packet.
760 if (temp_len < RUE_MIN_FRAMELEN) {
761 usbd_frame_zero(pc, temp_len,
762 RUE_MIN_FRAMELEN - temp_len);
763 temp_len = RUE_MIN_FRAMELEN;
765 usbd_xfer_set_frame_len(xfer, 0, temp_len);
768 * if there's a BPF listener, bounce a copy
769 * of this frame to him:
775 usbd_transfer_submit(xfer);
780 DPRINTFN(11, "transfer error, %s\n",
785 if (error != USB_ERR_CANCELLED) {
786 /* try to clear stall first */
787 usbd_xfer_set_stall(xfer);
795 rue_tick(struct usb_ether *ue)
797 struct rue_softc *sc = uether_getsc(ue);
798 struct mii_data *mii = GET_MII(sc);
800 RUE_LOCK_ASSERT(sc, MA_OWNED);
803 if ((sc->sc_flags & RUE_FLAG_LINK) == 0
804 && mii->mii_media_status & IFM_ACTIVE &&
805 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
806 sc->sc_flags |= RUE_FLAG_LINK;
812 rue_start(struct usb_ether *ue)
814 struct rue_softc *sc = uether_getsc(ue);
817 * start the USB transfers, if not already started:
819 usbd_transfer_start(sc->sc_xfer[RUE_INTR_DT_RD]);
820 usbd_transfer_start(sc->sc_xfer[RUE_BULK_DT_RD]);
821 usbd_transfer_start(sc->sc_xfer[RUE_BULK_DT_WR]);
825 rue_init(struct usb_ether *ue)
827 struct rue_softc *sc = uether_getsc(ue);
828 struct ifnet *ifp = uether_getifp(ue);
830 RUE_LOCK_ASSERT(sc, MA_OWNED);
837 /* Set MAC address */
838 rue_write_mem(sc, RUE_IDR0, IF_LLADDR(ifp), ETHER_ADDR_LEN);
843 * Set the initial TX and RX configuration.
845 rue_csr_write_1(sc, RUE_TCR, RUE_TCR_CONFIG);
846 rue_csr_write_2(sc, RUE_RCR, RUE_RCR_CONFIG|RUE_RCR_AB);
848 /* Load the multicast filter */
850 /* Load the multicast filter. */
853 /* Enable RX and TX */
854 rue_csr_write_1(sc, RUE_CR, (RUE_CR_TE | RUE_CR_RE | RUE_CR_EP3CLREN));
856 usbd_xfer_set_stall(sc->sc_xfer[RUE_BULK_DT_WR]);
858 ifp->if_drv_flags |= IFF_DRV_RUNNING;
866 rue_ifmedia_upd(struct ifnet *ifp)
868 struct rue_softc *sc = ifp->if_softc;
869 struct mii_data *mii = GET_MII(sc);
871 RUE_LOCK_ASSERT(sc, MA_OWNED);
873 sc->sc_flags &= ~RUE_FLAG_LINK;
874 if (mii->mii_instance) {
875 struct mii_softc *miisc;
877 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
878 mii_phy_reset(miisc);
885 * Report current media status.
888 rue_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
890 struct rue_softc *sc = ifp->if_softc;
891 struct mii_data *mii = GET_MII(sc);
896 ifmr->ifm_active = mii->mii_media_active;
897 ifmr->ifm_status = mii->mii_media_status;
901 rue_stop(struct usb_ether *ue)
903 struct rue_softc *sc = uether_getsc(ue);
904 struct ifnet *ifp = uether_getifp(ue);
906 RUE_LOCK_ASSERT(sc, MA_OWNED);
908 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
909 sc->sc_flags &= ~RUE_FLAG_LINK;
912 * stop all the transfers, if not already stopped:
914 usbd_transfer_stop(sc->sc_xfer[RUE_BULK_DT_WR]);
915 usbd_transfer_stop(sc->sc_xfer[RUE_BULK_DT_RD]);
916 usbd_transfer_stop(sc->sc_xfer[RUE_INTR_DT_RD]);
918 rue_csr_write_1(sc, RUE_CR, 0x00);