2 * Copyright (c) 1997, 1998, 1999, 2000
3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
37 * Kawasaki LSI KL5KUSB101B USB to ethernet adapter driver.
39 * Written by Bill Paul <wpaul@ee.columbia.edu>
40 * Electrical Engineering Department
41 * Columbia University, New York City
45 * The KLSI USB to ethernet adapter chip contains an USB serial interface,
46 * ethernet MAC and embedded microcontroller (called the QT Engine).
47 * The chip must have firmware loaded into it before it will operate.
48 * Packets are passed between the chip and host via bulk transfers.
49 * There is an interrupt endpoint mentioned in the software spec, however
50 * it's currently unused. This device is 10Mbps half-duplex only, hence
51 * there is no media selection logic. The MAC supports a 128 entry
52 * multicast filter, though the exact size of the filter can depend
53 * on the firmware. Curiously, while the software spec describes various
54 * ethernet statistics counters, my sample adapter and firmware combination
55 * claims not to support any statistics counters at all.
57 * Note that once we load the firmware in the device, we have to be
58 * careful not to load it again: if you restart your computer but
59 * leave the adapter attached to the USB controller, it may remain
60 * powered on and retain its firmware. In this case, we don't need
61 * to load the firmware a second time.
63 * Special thanks to Rob Furr for providing an ADS Technologies
64 * adapter for development and testing. No monkeys were harmed during
65 * the development of this driver.
68 #include <sys/param.h>
69 #include <sys/systm.h>
70 #include <sys/sockio.h>
72 #include <sys/malloc.h>
73 #include <sys/kernel.h>
74 #include <sys/module.h>
75 #include <sys/socket.h>
78 #include <net/if_arp.h>
79 #include <net/ethernet.h>
80 #include <net/if_dl.h>
81 #include <net/if_media.h>
82 #include <net/if_types.h>
87 #include <machine/bus.h>
89 #include <dev/usb/usb.h>
90 #include <dev/usb/usbdi.h>
91 #include <dev/usb/usbdi_util.h>
92 #include <dev/usb/usbdivar.h>
94 #include <dev/usb/usb_ethersubr.h>
96 #include <dev/usb/if_kuereg.h>
97 #include <dev/usb/kue_fw.h>
99 MODULE_DEPEND(kue, usb, 1, 1, 1);
100 MODULE_DEPEND(kue, ether, 1, 1, 1);
103 * Various supported device vendors/products.
105 static struct kue_type kue_devs[] = {
106 { USB_VENDOR_AOX, USB_PRODUCT_AOX_USB101 },
107 { USB_VENDOR_KLSI, USB_PRODUCT_AOX_USB101 },
108 { USB_VENDOR_ADS, USB_PRODUCT_ADS_UBS10BT },
109 { USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC10T },
110 { USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_EA101 },
111 { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET },
112 { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET2 },
113 { USB_VENDOR_ENTREGA, USB_PRODUCT_ENTREGA_E45 },
114 { USB_VENDOR_3COM, USB_PRODUCT_3COM_3C19250 },
115 { USB_VENDOR_COREGA, USB_PRODUCT_COREGA_ETHER_USB_T },
116 { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650C },
117 { USB_VENDOR_SMC, USB_PRODUCT_SMC_2102USB },
118 { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T },
119 { USB_VENDOR_KLSI, USB_PRODUCT_KLSI_DUH3E10BT },
120 { USB_VENDOR_KLSI, USB_PRODUCT_KLSI_DUH3E10BTN },
121 { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET3 },
122 { USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETT },
123 { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_URE450 },
124 { USB_VENDOR_SILICOM, USB_PRODUCT_SILICOM_GPE },
128 static int kue_match(device_t);
129 static int kue_attach(device_t);
130 static int kue_detach(device_t);
131 static void kue_shutdown(device_t);
132 static int kue_encap(struct kue_softc *, struct mbuf *, int);
133 static void kue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
134 static void kue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
135 static void kue_start(struct ifnet *);
136 static void kue_rxstart(struct ifnet *);
137 static int kue_ioctl(struct ifnet *, u_long, caddr_t);
138 static void kue_init(void *);
139 static void kue_stop(struct kue_softc *);
140 static void kue_watchdog(struct ifnet *);
142 static void kue_setmulti(struct kue_softc *);
143 static void kue_reset(struct kue_softc *);
145 static usbd_status kue_do_request(usbd_device_handle,
146 usb_device_request_t *, void *);
147 static usbd_status kue_ctl(struct kue_softc *, int, u_int8_t,
148 u_int16_t, char *, int);
149 static usbd_status kue_setword(struct kue_softc *, u_int8_t, u_int16_t);
150 static int kue_load_fw(struct kue_softc *);
152 static device_method_t kue_methods[] = {
153 /* Device interface */
154 DEVMETHOD(device_probe, kue_match),
155 DEVMETHOD(device_attach, kue_attach),
156 DEVMETHOD(device_detach, kue_detach),
157 DEVMETHOD(device_shutdown, kue_shutdown),
162 static driver_t kue_driver = {
165 sizeof(struct kue_softc)
168 static devclass_t kue_devclass;
170 DRIVER_MODULE(kue, uhub, kue_driver, kue_devclass, usbd_driver_load, 0);
173 * We have a custom do_request function which is almost like the
174 * regular do_request function, except it has a much longer timeout.
175 * Why? Because we need to make requests over the control endpoint
176 * to download the firmware to the device, which can take longer
177 * than the default timeout.
180 kue_do_request(usbd_device_handle dev, usb_device_request_t *req, void *data)
182 usbd_xfer_handle xfer;
185 xfer = usbd_alloc_xfer(dev);
186 usbd_setup_default_xfer(xfer, dev, 0, 500000, req,
187 data, UGETW(req->wLength), USBD_SHORT_XFER_OK, 0);
188 err = usbd_sync_transfer(xfer);
189 usbd_free_xfer(xfer);
194 kue_setword(struct kue_softc *sc, u_int8_t breq, u_int16_t word)
196 usbd_device_handle dev;
197 usb_device_request_t req;
201 return(USBD_NORMAL_COMPLETION);
207 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
210 USETW(req.wValue, word);
211 USETW(req.wIndex, 0);
212 USETW(req.wLength, 0);
214 err = kue_do_request(dev, &req, NULL);
222 kue_ctl(struct kue_softc *sc, int rw, u_int8_t breq, u_int16_t val,
225 usbd_device_handle dev;
226 usb_device_request_t req;
232 return(USBD_NORMAL_COMPLETION);
236 if (rw == KUE_CTL_WRITE)
237 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
239 req.bmRequestType = UT_READ_VENDOR_DEVICE;
242 USETW(req.wValue, val);
243 USETW(req.wIndex, 0);
244 USETW(req.wLength, len);
246 err = kue_do_request(dev, &req, data);
254 kue_load_fw(struct kue_softc *sc)
257 usb_device_descriptor_t *dd;
260 dd = &sc->kue_udev->ddesc;
261 hwrev = UGETW(dd->bcdDevice);
264 * First, check if we even need to load the firmware.
265 * If the device was still attached when the system was
266 * rebooted, it may already have firmware loaded in it.
267 * If this is the case, we don't need to do it again.
268 * And in fact, if we try to load it again, we'll hang,
269 * so we have to avoid this condition if we don't want
272 * We can test this quickly by checking the bcdRevision
273 * code. The NIC will return a different revision code if
274 * it's probed while the firmware is still loaded and
280 /* Load code segment */
281 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN,
282 0, kue_code_seg, sizeof(kue_code_seg));
284 device_printf(sc->kue_dev, "failed to load code segment: %s\n",
289 /* Load fixup segment */
290 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN,
291 0, kue_fix_seg, sizeof(kue_fix_seg));
293 device_printf(sc->kue_dev, "failed to load fixup segment: %s\n",
298 /* Send trigger command. */
299 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN,
300 0, kue_trig_seg, sizeof(kue_trig_seg));
302 device_printf(sc->kue_dev, "failed to load trigger segment: %s\n",
311 kue_setmulti(struct kue_softc *sc)
314 struct ifmultiaddr *ifma;
319 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
320 sc->kue_rxfilt |= KUE_RXFILT_ALLMULTI;
321 sc->kue_rxfilt &= ~KUE_RXFILT_MULTICAST;
322 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt);
326 sc->kue_rxfilt &= ~KUE_RXFILT_ALLMULTI;
329 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
331 if (ifma->ifma_addr->sa_family != AF_LINK)
334 * If there are too many addresses for the
335 * internal filter, switch over to allmulti mode.
337 if (i == KUE_MCFILTCNT(sc))
339 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
340 KUE_MCFILT(sc, i), ETHER_ADDR_LEN);
345 if (i == KUE_MCFILTCNT(sc))
346 sc->kue_rxfilt |= KUE_RXFILT_ALLMULTI;
348 sc->kue_rxfilt |= KUE_RXFILT_MULTICAST;
349 kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MCAST_FILTERS,
350 i, sc->kue_mcfilters, i * ETHER_ADDR_LEN);
353 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt);
359 * Issue a SET_CONFIGURATION command to reset the MAC. This should be
360 * done after the firmware is loaded into the adapter in order to
361 * bring it into proper operation.
364 kue_reset(struct kue_softc *sc)
366 if (usbd_set_config_no(sc->kue_udev, KUE_CONFIG_NO, 0) ||
367 usbd_device2interface_handle(sc->kue_udev, KUE_IFACE_IDX,
369 device_printf(sc->kue_dev, "getting interface handle failed\n");
372 /* Wait a little while for the chip to get its brains in order. */
378 * Probe for a KLSI chip.
381 kue_match(device_t self)
383 struct usb_attach_arg *uaa = device_get_ivars(self);
391 if (uaa->vendor == t->kue_vid && uaa->product == t->kue_did)
392 return (UMATCH_VENDOR_PRODUCT);
395 return (UMATCH_NONE);
399 * Attach the interface. Allocate softc structures, do
400 * setup and ethernet/BPF attach.
403 kue_attach(device_t self)
405 struct kue_softc *sc = device_get_softc(self);
406 struct usb_attach_arg *uaa = device_get_ivars(self);
409 usb_interface_descriptor_t *id;
410 usb_endpoint_descriptor_t *ed;
414 sc->kue_iface = uaa->iface;
415 sc->kue_udev = uaa->device;
417 id = usbd_get_interface_descriptor(uaa->iface);
419 /* Find endpoints. */
420 for (i = 0; i < id->bNumEndpoints; i++) {
421 ed = usbd_interface2endpoint_descriptor(uaa->iface, i);
423 device_printf(sc->kue_dev, "couldn't get ep %d\n", i);
426 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
427 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
428 sc->kue_ed[KUE_ENDPT_RX] = ed->bEndpointAddress;
429 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
430 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
431 sc->kue_ed[KUE_ENDPT_TX] = ed->bEndpointAddress;
432 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
433 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
434 sc->kue_ed[KUE_ENDPT_INTR] = ed->bEndpointAddress;
438 mtx_init(&sc->kue_mtx, device_get_nameunit(self), MTX_NETWORK_LOCK,
439 MTX_DEF | MTX_RECURSE);
442 /* Load the firmware into the NIC. */
443 if (kue_load_fw(sc)) {
445 mtx_destroy(&sc->kue_mtx);
449 /* Reset the adapter. */
452 /* Read ethernet descriptor */
453 err = kue_ctl(sc, KUE_CTL_READ, KUE_CMD_GET_ETHER_DESCRIPTOR,
454 0, (char *)&sc->kue_desc, sizeof(sc->kue_desc));
456 sc->kue_mcfilters = malloc(KUE_MCFILTCNT(sc) * ETHER_ADDR_LEN,
459 ifp = sc->kue_ifp = if_alloc(IFT_ETHER);
461 device_printf(sc->kue_dev, "can not if_alloc()\n");
463 mtx_destroy(&sc->kue_mtx);
467 if_initname(ifp, "kue", device_get_unit(sc->kue_dev));
468 ifp->if_mtu = ETHERMTU;
469 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
471 ifp->if_ioctl = kue_ioctl;
472 ifp->if_start = kue_start;
473 ifp->if_watchdog = kue_watchdog;
474 ifp->if_init = kue_init;
475 ifp->if_baudrate = 10000000;
476 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
478 sc->kue_qdat.ifp = ifp;
479 sc->kue_qdat.if_rxstart = kue_rxstart;
482 * Call MI attach routine.
484 ether_ifattach(ifp, sc->kue_desc.kue_macaddr);
485 usb_register_netisr();
494 kue_detach(device_t dev)
496 struct kue_softc *sc;
499 sc = device_get_softc(dev);
510 if (sc->kue_ep[KUE_ENDPT_TX] != NULL)
511 usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_TX]);
512 if (sc->kue_ep[KUE_ENDPT_RX] != NULL)
513 usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_RX]);
514 if (sc->kue_ep[KUE_ENDPT_INTR] != NULL)
515 usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
517 if (sc->kue_mcfilters != NULL)
518 free(sc->kue_mcfilters, M_USBDEV);
521 mtx_destroy(&sc->kue_mtx);
527 kue_rxstart(struct ifnet *ifp)
529 struct kue_softc *sc;
534 c = &sc->kue_cdata.ue_rx_chain[sc->kue_cdata.ue_rx_prod];
536 c->ue_mbuf = usb_ether_newbuf();
537 if (c->ue_mbuf == NULL) {
538 device_printf(sc->kue_dev, "no memory for rx list "
539 "-- packet dropped!\n");
545 /* Setup new transfer. */
546 usbd_setup_xfer(c->ue_xfer, sc->kue_ep[KUE_ENDPT_RX],
547 c, mtod(c->ue_mbuf, char *), UE_BUFSZ, USBD_SHORT_XFER_OK,
548 USBD_NO_TIMEOUT, kue_rxeof);
549 usbd_transfer(c->ue_xfer);
557 * A frame has been uploaded: pass the resulting mbuf chain up to
558 * the higher level protocols.
560 static void kue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv,
563 struct kue_softc *sc;
575 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
580 if (status != USBD_NORMAL_COMPLETION) {
581 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
585 if (usbd_ratecheck(&sc->kue_rx_notice))
586 device_printf(sc->kue_dev, "usb error on rx: %s\n",
587 usbd_errstr(status));
588 if (status == USBD_STALLED)
589 usbd_clear_endpoint_stall(sc->kue_ep[KUE_ENDPT_RX]);
593 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
598 len = *mtod(m, u_int16_t *);
599 m_adj(m, sizeof(u_int16_t));
601 /* No errors; receive the packet. */
604 if (len < sizeof(struct ether_header)) {
610 m->m_pkthdr.rcvif = (void *)&sc->kue_qdat;
611 m->m_pkthdr.len = m->m_len = total_len;
613 /* Put the packet on the special USB input queue. */
620 /* Setup new transfer. */
621 usbd_setup_xfer(c->ue_xfer, sc->kue_ep[KUE_ENDPT_RX],
622 c, mtod(c->ue_mbuf, char *), UE_BUFSZ, USBD_SHORT_XFER_OK,
623 USBD_NO_TIMEOUT, kue_rxeof);
624 usbd_transfer(c->ue_xfer);
631 * A frame was downloaded to the chip. It's safe for us to clean up
636 kue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
638 struct kue_softc *sc;
649 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
651 if (status != USBD_NORMAL_COMPLETION) {
652 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
656 device_printf(sc->kue_dev, "usb error on tx: %s\n",
657 usbd_errstr(status));
658 if (status == USBD_STALLED)
659 usbd_clear_endpoint_stall(sc->kue_ep[KUE_ENDPT_TX]);
664 usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &err);
666 if (c->ue_mbuf != NULL) {
667 c->ue_mbuf->m_pkthdr.rcvif = ifp;
668 usb_tx_done(c->ue_mbuf);
683 kue_encap(struct kue_softc *sc, struct mbuf *m, int idx)
689 c = &sc->kue_cdata.ue_tx_chain[idx];
692 * Copy the mbuf data into a contiguous buffer, leaving two
693 * bytes at the beginning to hold the frame length.
695 m_copydata(m, 0, m->m_pkthdr.len, c->ue_buf + 2);
698 total_len = m->m_pkthdr.len + 2;
699 total_len += 64 - (total_len % 64);
701 /* Frame length is specified in the first 2 bytes of the buffer. */
702 c->ue_buf[0] = (u_int8_t)m->m_pkthdr.len;
703 c->ue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
705 usbd_setup_xfer(c->ue_xfer, sc->kue_ep[KUE_ENDPT_TX],
706 c, c->ue_buf, total_len, 0, 10000, kue_txeof);
709 err = usbd_transfer(c->ue_xfer);
710 if (err != USBD_IN_PROGRESS) {
715 sc->kue_cdata.ue_tx_cnt++;
721 kue_start(struct ifnet *ifp)
723 struct kue_softc *sc;
724 struct mbuf *m_head = NULL;
729 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
734 IF_DEQUEUE(&ifp->if_snd, m_head);
735 if (m_head == NULL) {
740 if (kue_encap(sc, m_head, 0)) {
741 IF_PREPEND(&ifp->if_snd, m_head);
742 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
748 * If there's a BPF listener, bounce a copy of this frame
751 BPF_MTAP(ifp, m_head);
753 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
756 * Set a timeout in case the chip goes out to lunch.
767 struct kue_softc *sc = xsc;
768 struct ifnet *ifp = sc->kue_ifp;
775 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
780 /* Set MAC address */
781 kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MAC,
782 0, IF_LLADDR(sc->kue_ifp), ETHER_ADDR_LEN);
784 sc->kue_rxfilt = KUE_RXFILT_UNICAST|KUE_RXFILT_BROADCAST;
786 /* If we want promiscuous mode, set the allframes bit. */
787 if (ifp->if_flags & IFF_PROMISC)
788 sc->kue_rxfilt |= KUE_RXFILT_PROMISC;
790 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt);
792 /* I'm not sure how to tune these. */
795 * Leave this one alone for now; setting it
796 * wrong causes lockups on some machines/controllers.
798 kue_setword(sc, KUE_CMD_SET_SOFS, 1);
800 kue_setword(sc, KUE_CMD_SET_URB_SIZE, 64);
803 if (usb_ether_tx_list_init(sc, &sc->kue_cdata,
804 sc->kue_udev) == ENOBUFS) {
805 device_printf(sc->kue_dev, "tx list init failed\n");
811 if (usb_ether_rx_list_init(sc, &sc->kue_cdata,
812 sc->kue_udev) == ENOBUFS) {
813 device_printf(sc->kue_dev, "rx list init failed\n");
818 /* Load the multicast filter. */
821 /* Open RX and TX pipes. */
822 err = usbd_open_pipe(sc->kue_iface, sc->kue_ed[KUE_ENDPT_RX],
823 USBD_EXCLUSIVE_USE, &sc->kue_ep[KUE_ENDPT_RX]);
825 device_printf(sc->kue_dev, "open rx pipe failed: %s\n",
831 err = usbd_open_pipe(sc->kue_iface, sc->kue_ed[KUE_ENDPT_TX],
832 USBD_EXCLUSIVE_USE, &sc->kue_ep[KUE_ENDPT_TX]);
834 device_printf(sc->kue_dev, "open tx pipe failed: %s\n",
840 /* Start up the receive pipe. */
841 for (i = 0; i < UE_RX_LIST_CNT; i++) {
842 c = &sc->kue_cdata.ue_rx_chain[i];
843 usbd_setup_xfer(c->ue_xfer, sc->kue_ep[KUE_ENDPT_RX],
844 c, mtod(c->ue_mbuf, char *), UE_BUFSZ,
845 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, kue_rxeof);
846 usbd_transfer(c->ue_xfer);
849 ifp->if_drv_flags |= IFF_DRV_RUNNING;
850 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
858 kue_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
860 struct kue_softc *sc = ifp->if_softc;
867 if (ifp->if_flags & IFF_UP) {
868 if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
869 ifp->if_flags & IFF_PROMISC &&
870 !(sc->kue_if_flags & IFF_PROMISC)) {
871 sc->kue_rxfilt |= KUE_RXFILT_PROMISC;
872 kue_setword(sc, KUE_CMD_SET_PKT_FILTER,
874 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
875 !(ifp->if_flags & IFF_PROMISC) &&
876 sc->kue_if_flags & IFF_PROMISC) {
877 sc->kue_rxfilt &= ~KUE_RXFILT_PROMISC;
878 kue_setword(sc, KUE_CMD_SET_PKT_FILTER,
880 } else if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
883 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
886 sc->kue_if_flags = ifp->if_flags;
895 error = ether_ioctl(ifp, command, data);
905 kue_watchdog(struct ifnet *ifp)
907 struct kue_softc *sc;
914 device_printf(sc->kue_dev, "watchdog timeout\n");
916 c = &sc->kue_cdata.ue_tx_chain[0];
917 usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &stat);
918 kue_txeof(c->ue_xfer, c, stat);
920 if (ifp->if_snd.ifq_head != NULL)
928 * Stop the adapter and free any mbufs allocated to the
932 kue_stop(struct kue_softc *sc)
941 /* Stop transfers. */
942 if (sc->kue_ep[KUE_ENDPT_RX] != NULL) {
943 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_RX]);
945 device_printf(sc->kue_dev, "abort rx pipe failed: %s\n",
948 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_RX]);
950 device_printf(sc->kue_dev, "close rx pipe failed: %s\n",
953 sc->kue_ep[KUE_ENDPT_RX] = NULL;
956 if (sc->kue_ep[KUE_ENDPT_TX] != NULL) {
957 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_TX]);
959 device_printf(sc->kue_dev, "abort tx pipe failed: %s\n",
962 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_TX]);
964 device_printf(sc->kue_dev, "close tx pipe failed: %s\n",
967 sc->kue_ep[KUE_ENDPT_TX] = NULL;
970 if (sc->kue_ep[KUE_ENDPT_INTR] != NULL) {
971 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
973 device_printf(sc->kue_dev, "abort intr pipe failed: %s\n",
976 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
978 device_printf(sc->kue_dev, "close intr pipe failed: %s\n",
981 sc->kue_ep[KUE_ENDPT_INTR] = NULL;
984 /* Free RX resources. */
985 usb_ether_rx_list_free(&sc->kue_cdata);
986 /* Free TX resources. */
987 usb_ether_tx_list_free(&sc->kue_cdata);
989 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
996 * Stop all chip I/O so that the kernel's probe routines don't
997 * get confused by errant DMAs when rebooting.
1000 kue_shutdown(device_t dev)
1002 struct kue_softc *sc;
1004 sc = device_get_softc(dev);