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>
88 #if __FreeBSD_version < 500000
89 #include <machine/clock.h>
92 #include <dev/usb/usb.h>
93 #include <dev/usb/usbdi.h>
94 #include <dev/usb/usbdi_util.h>
95 #include <dev/usb/usbdivar.h>
97 #include <dev/usb/usb_ethersubr.h>
99 #include <dev/usb/if_kuereg.h>
100 #include <dev/usb/kue_fw.h>
102 MODULE_DEPEND(kue, usb, 1, 1, 1);
103 MODULE_DEPEND(kue, ether, 1, 1, 1);
106 * Various supported device vendors/products.
108 static struct kue_type kue_devs[] = {
109 { USB_VENDOR_AOX, USB_PRODUCT_AOX_USB101 },
110 { USB_VENDOR_KLSI, USB_PRODUCT_AOX_USB101 },
111 { USB_VENDOR_ADS, USB_PRODUCT_ADS_UBS10BT },
112 { USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC10T },
113 { USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_EA101 },
114 { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET },
115 { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET2 },
116 { USB_VENDOR_ENTREGA, USB_PRODUCT_ENTREGA_E45 },
117 { USB_VENDOR_3COM, USB_PRODUCT_3COM_3C19250 },
118 { USB_VENDOR_COREGA, USB_PRODUCT_COREGA_ETHER_USB_T },
119 { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650C },
120 { USB_VENDOR_SMC, USB_PRODUCT_SMC_2102USB },
121 { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T },
122 { USB_VENDOR_KLSI, USB_PRODUCT_KLSI_DUH3E10BT },
123 { USB_VENDOR_KLSI, USB_PRODUCT_KLSI_DUH3E10BTN },
124 { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET3 },
125 { USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETT },
126 { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_URE450 },
127 { USB_VENDOR_SILICOM, USB_PRODUCT_SILICOM_GPE },
131 static int kue_match(device_t);
132 static int kue_attach(device_t);
133 static int kue_detach(device_t);
134 static void kue_shutdown(device_t);
135 static int kue_encap(struct kue_softc *, struct mbuf *, int);
136 static void kue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
137 static void kue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
138 static void kue_start(struct ifnet *);
139 static void kue_rxstart(struct ifnet *);
140 static int kue_ioctl(struct ifnet *, u_long, caddr_t);
141 static void kue_init(void *);
142 static void kue_stop(struct kue_softc *);
143 static void kue_watchdog(struct ifnet *);
145 static void kue_setmulti(struct kue_softc *);
146 static void kue_reset(struct kue_softc *);
148 static usbd_status kue_do_request(usbd_device_handle,
149 usb_device_request_t *, void *);
150 static usbd_status kue_ctl(struct kue_softc *, int, u_int8_t,
151 u_int16_t, char *, int);
152 static usbd_status kue_setword(struct kue_softc *, u_int8_t, u_int16_t);
153 static int kue_load_fw(struct kue_softc *);
155 static device_method_t kue_methods[] = {
156 /* Device interface */
157 DEVMETHOD(device_probe, kue_match),
158 DEVMETHOD(device_attach, kue_attach),
159 DEVMETHOD(device_detach, kue_detach),
160 DEVMETHOD(device_shutdown, kue_shutdown),
165 static driver_t kue_driver = {
168 sizeof(struct kue_softc)
171 static devclass_t kue_devclass;
173 DRIVER_MODULE(kue, uhub, kue_driver, kue_devclass, usbd_driver_load, 0);
176 * We have a custom do_request function which is almost like the
177 * regular do_request function, except it has a much longer timeout.
178 * Why? Because we need to make requests over the control endpoint
179 * to download the firmware to the device, which can take longer
180 * than the default timeout.
183 kue_do_request(usbd_device_handle dev, usb_device_request_t *req, void *data)
185 usbd_xfer_handle xfer;
188 xfer = usbd_alloc_xfer(dev);
189 usbd_setup_default_xfer(xfer, dev, 0, 500000, req,
190 data, UGETW(req->wLength), USBD_SHORT_XFER_OK, 0);
191 err = usbd_sync_transfer(xfer);
192 usbd_free_xfer(xfer);
197 kue_setword(struct kue_softc *sc, u_int8_t breq, u_int16_t word)
199 usbd_device_handle dev;
200 usb_device_request_t req;
204 return(USBD_NORMAL_COMPLETION);
210 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
213 USETW(req.wValue, word);
214 USETW(req.wIndex, 0);
215 USETW(req.wLength, 0);
217 err = kue_do_request(dev, &req, NULL);
225 kue_ctl(struct kue_softc *sc, int rw, u_int8_t breq, u_int16_t val,
228 usbd_device_handle dev;
229 usb_device_request_t req;
235 return(USBD_NORMAL_COMPLETION);
239 if (rw == KUE_CTL_WRITE)
240 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
242 req.bmRequestType = UT_READ_VENDOR_DEVICE;
245 USETW(req.wValue, val);
246 USETW(req.wIndex, 0);
247 USETW(req.wLength, len);
249 err = kue_do_request(dev, &req, data);
257 kue_load_fw(struct kue_softc *sc)
260 usb_device_descriptor_t *dd;
263 dd = &sc->kue_udev->ddesc;
264 hwrev = UGETW(dd->bcdDevice);
267 * First, check if we even need to load the firmware.
268 * If the device was still attached when the system was
269 * rebooted, it may already have firmware loaded in it.
270 * If this is the case, we don't need to do it again.
271 * And in fact, if we try to load it again, we'll hang,
272 * so we have to avoid this condition if we don't want
275 * We can test this quickly by checking the bcdRevision
276 * code. The NIC will return a different revision code if
277 * it's probed while the firmware is still loaded and
283 /* Load code segment */
284 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN,
285 0, kue_code_seg, sizeof(kue_code_seg));
287 printf("kue%d: failed to load code segment: %s\n",
288 sc->kue_unit, usbd_errstr(err));
292 /* Load fixup segment */
293 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN,
294 0, kue_fix_seg, sizeof(kue_fix_seg));
296 printf("kue%d: failed to load fixup segment: %s\n",
297 sc->kue_unit, usbd_errstr(err));
301 /* Send trigger command. */
302 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN,
303 0, kue_trig_seg, sizeof(kue_trig_seg));
305 printf("kue%d: failed to load trigger segment: %s\n",
306 sc->kue_unit, usbd_errstr(err));
314 kue_setmulti(struct kue_softc *sc)
317 struct ifmultiaddr *ifma;
322 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
323 sc->kue_rxfilt |= KUE_RXFILT_ALLMULTI;
324 sc->kue_rxfilt &= ~KUE_RXFILT_MULTICAST;
325 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt);
329 sc->kue_rxfilt &= ~KUE_RXFILT_ALLMULTI;
332 #if __FreeBSD_version >= 500000
333 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
335 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
338 if (ifma->ifma_addr->sa_family != AF_LINK)
341 * If there are too many addresses for the
342 * internal filter, switch over to allmulti mode.
344 if (i == KUE_MCFILTCNT(sc))
346 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
347 KUE_MCFILT(sc, i), ETHER_ADDR_LEN);
352 if (i == KUE_MCFILTCNT(sc))
353 sc->kue_rxfilt |= KUE_RXFILT_ALLMULTI;
355 sc->kue_rxfilt |= KUE_RXFILT_MULTICAST;
356 kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MCAST_FILTERS,
357 i, sc->kue_mcfilters, i * ETHER_ADDR_LEN);
360 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt);
366 * Issue a SET_CONFIGURATION command to reset the MAC. This should be
367 * done after the firmware is loaded into the adapter in order to
368 * bring it into proper operation.
371 kue_reset(struct kue_softc *sc)
373 if (usbd_set_config_no(sc->kue_udev, KUE_CONFIG_NO, 0) ||
374 usbd_device2interface_handle(sc->kue_udev, KUE_IFACE_IDX,
376 printf("kue%d: getting interface handle failed\n",
380 /* Wait a little while for the chip to get its brains in order. */
386 * Probe for a KLSI chip.
390 USB_MATCH_START(kue, uaa);
398 if (uaa->vendor == t->kue_vid &&
399 uaa->product == t->kue_did) {
400 return(UMATCH_VENDOR_PRODUCT);
409 * Attach the interface. Allocate softc structures, do
410 * setup and ethernet/BPF attach.
414 USB_ATTACH_START(kue, sc, uaa);
418 usb_interface_descriptor_t *id;
419 usb_endpoint_descriptor_t *ed;
422 bzero(sc, sizeof(struct kue_softc));
424 sc->kue_iface = uaa->iface;
425 sc->kue_udev = uaa->device;
426 sc->kue_unit = device_get_unit(self);
428 id = usbd_get_interface_descriptor(uaa->iface);
430 usbd_devinfo(uaa->device, 0, devinfo);
431 device_set_desc_copy(self, devinfo);
432 printf("%s: %s\n", device_get_nameunit(self), devinfo);
434 /* Find endpoints. */
435 for (i = 0; i < id->bNumEndpoints; i++) {
436 ed = usbd_interface2endpoint_descriptor(uaa->iface, i);
438 printf("kue%d: couldn't get ep %d\n",
440 USB_ATTACH_ERROR_RETURN;
442 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
443 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
444 sc->kue_ed[KUE_ENDPT_RX] = ed->bEndpointAddress;
445 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
446 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
447 sc->kue_ed[KUE_ENDPT_TX] = ed->bEndpointAddress;
448 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
449 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
450 sc->kue_ed[KUE_ENDPT_INTR] = ed->bEndpointAddress;
454 #if __FreeBSD_version >= 500000
455 mtx_init(&sc->kue_mtx, device_get_nameunit(self), MTX_NETWORK_LOCK,
456 MTX_DEF | MTX_RECURSE);
460 /* Load the firmware into the NIC. */
461 if (kue_load_fw(sc)) {
463 #if __FreeBSD_version >= 500000
464 mtx_destroy(&sc->kue_mtx);
466 USB_ATTACH_ERROR_RETURN;
469 /* Reset the adapter. */
472 /* Read ethernet descriptor */
473 err = kue_ctl(sc, KUE_CTL_READ, KUE_CMD_GET_ETHER_DESCRIPTOR,
474 0, (char *)&sc->kue_desc, sizeof(sc->kue_desc));
476 sc->kue_mcfilters = malloc(KUE_MCFILTCNT(sc) * ETHER_ADDR_LEN,
479 ifp = sc->kue_ifp = if_alloc(IFT_ETHER);
481 printf("kue%d: can not if_alloc()\n", sc->kue_unit);
483 #if __FreeBSD_version >= 500000
484 mtx_destroy(&sc->kue_mtx);
486 USB_ATTACH_ERROR_RETURN;
489 if_initname(ifp, "kue", sc->kue_unit);
490 ifp->if_mtu = ETHERMTU;
491 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
493 ifp->if_ioctl = kue_ioctl;
494 ifp->if_start = kue_start;
495 ifp->if_watchdog = kue_watchdog;
496 ifp->if_init = kue_init;
497 ifp->if_baudrate = 10000000;
498 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
500 sc->kue_qdat.ifp = ifp;
501 sc->kue_qdat.if_rxstart = kue_rxstart;
504 * Call MI attach routine.
506 #if __FreeBSD_version >= 500000
507 ether_ifattach(ifp, sc->kue_desc.kue_macaddr);
509 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
511 usb_register_netisr();
516 USB_ATTACH_SUCCESS_RETURN;
520 kue_detach(device_t dev)
522 struct kue_softc *sc;
525 sc = device_get_softc(dev);
532 #if __FreeBSD_version >= 500000
536 ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
539 if (sc->kue_ep[KUE_ENDPT_TX] != NULL)
540 usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_TX]);
541 if (sc->kue_ep[KUE_ENDPT_RX] != NULL)
542 usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_RX]);
543 if (sc->kue_ep[KUE_ENDPT_INTR] != NULL)
544 usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
546 if (sc->kue_mcfilters != NULL)
547 free(sc->kue_mcfilters, M_USBDEV);
550 #if __FreeBSD_version >= 500000
551 mtx_destroy(&sc->kue_mtx);
558 kue_rxstart(struct ifnet *ifp)
560 struct kue_softc *sc;
565 c = &sc->kue_cdata.ue_rx_chain[sc->kue_cdata.ue_rx_prod];
567 c->ue_mbuf = usb_ether_newbuf();
568 if (c->ue_mbuf == NULL) {
569 printf("%s: no memory for rx list "
570 "-- packet dropped!\n", device_get_nameunit(sc->kue_dev));
576 /* Setup new transfer. */
577 usbd_setup_xfer(c->ue_xfer, sc->kue_ep[KUE_ENDPT_RX],
578 c, mtod(c->ue_mbuf, char *), UE_BUFSZ, USBD_SHORT_XFER_OK,
579 USBD_NO_TIMEOUT, kue_rxeof);
580 usbd_transfer(c->ue_xfer);
588 * A frame has been uploaded: pass the resulting mbuf chain up to
589 * the higher level protocols.
591 static void kue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv,
594 struct kue_softc *sc;
606 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
611 if (status != USBD_NORMAL_COMPLETION) {
612 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
616 if (usbd_ratecheck(&sc->kue_rx_notice))
617 printf("kue%d: usb error on rx: %s\n", sc->kue_unit,
618 usbd_errstr(status));
619 if (status == USBD_STALLED)
620 usbd_clear_endpoint_stall(sc->kue_ep[KUE_ENDPT_RX]);
624 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
629 len = *mtod(m, u_int16_t *);
630 m_adj(m, sizeof(u_int16_t));
632 /* No errors; receive the packet. */
635 if (len < sizeof(struct ether_header)) {
641 m->m_pkthdr.rcvif = (void *)&sc->kue_qdat;
642 m->m_pkthdr.len = m->m_len = total_len;
644 /* Put the packet on the special USB input queue. */
651 /* Setup new transfer. */
652 usbd_setup_xfer(c->ue_xfer, sc->kue_ep[KUE_ENDPT_RX],
653 c, mtod(c->ue_mbuf, char *), UE_BUFSZ, USBD_SHORT_XFER_OK,
654 USBD_NO_TIMEOUT, kue_rxeof);
655 usbd_transfer(c->ue_xfer);
662 * A frame was downloaded to the chip. It's safe for us to clean up
667 kue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
669 struct kue_softc *sc;
680 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
682 if (status != USBD_NORMAL_COMPLETION) {
683 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
687 printf("kue%d: usb error on tx: %s\n", sc->kue_unit,
688 usbd_errstr(status));
689 if (status == USBD_STALLED)
690 usbd_clear_endpoint_stall(sc->kue_ep[KUE_ENDPT_TX]);
695 usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &err);
697 if (c->ue_mbuf != NULL) {
698 c->ue_mbuf->m_pkthdr.rcvif = ifp;
699 usb_tx_done(c->ue_mbuf);
714 kue_encap(struct kue_softc *sc, struct mbuf *m, int idx)
720 c = &sc->kue_cdata.ue_tx_chain[idx];
723 * Copy the mbuf data into a contiguous buffer, leaving two
724 * bytes at the beginning to hold the frame length.
726 m_copydata(m, 0, m->m_pkthdr.len, c->ue_buf + 2);
729 total_len = m->m_pkthdr.len + 2;
730 total_len += 64 - (total_len % 64);
732 /* Frame length is specified in the first 2 bytes of the buffer. */
733 c->ue_buf[0] = (u_int8_t)m->m_pkthdr.len;
734 c->ue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
736 usbd_setup_xfer(c->ue_xfer, sc->kue_ep[KUE_ENDPT_TX],
737 c, c->ue_buf, total_len, 0, 10000, kue_txeof);
740 err = usbd_transfer(c->ue_xfer);
741 if (err != USBD_IN_PROGRESS) {
746 sc->kue_cdata.ue_tx_cnt++;
752 kue_start(struct ifnet *ifp)
754 struct kue_softc *sc;
755 struct mbuf *m_head = NULL;
760 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
765 IF_DEQUEUE(&ifp->if_snd, m_head);
766 if (m_head == NULL) {
771 if (kue_encap(sc, m_head, 0)) {
772 IF_PREPEND(&ifp->if_snd, m_head);
773 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
779 * If there's a BPF listener, bounce a copy of this frame
782 BPF_MTAP(ifp, m_head);
784 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
787 * Set a timeout in case the chip goes out to lunch.
798 struct kue_softc *sc = xsc;
799 struct ifnet *ifp = sc->kue_ifp;
806 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
811 /* Set MAC address */
812 kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MAC,
813 0, IF_LLADDR(sc->kue_ifp), ETHER_ADDR_LEN);
815 sc->kue_rxfilt = KUE_RXFILT_UNICAST|KUE_RXFILT_BROADCAST;
817 /* If we want promiscuous mode, set the allframes bit. */
818 if (ifp->if_flags & IFF_PROMISC)
819 sc->kue_rxfilt |= KUE_RXFILT_PROMISC;
821 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt);
823 /* I'm not sure how to tune these. */
826 * Leave this one alone for now; setting it
827 * wrong causes lockups on some machines/controllers.
829 kue_setword(sc, KUE_CMD_SET_SOFS, 1);
831 kue_setword(sc, KUE_CMD_SET_URB_SIZE, 64);
834 if (usb_ether_tx_list_init(sc, &sc->kue_cdata,
835 sc->kue_udev) == ENOBUFS) {
836 printf("kue%d: tx list init failed\n", sc->kue_unit);
842 if (usb_ether_rx_list_init(sc, &sc->kue_cdata,
843 sc->kue_udev) == ENOBUFS) {
844 printf("kue%d: rx list init failed\n", sc->kue_unit);
849 /* Load the multicast filter. */
852 /* Open RX and TX pipes. */
853 err = usbd_open_pipe(sc->kue_iface, sc->kue_ed[KUE_ENDPT_RX],
854 USBD_EXCLUSIVE_USE, &sc->kue_ep[KUE_ENDPT_RX]);
856 printf("kue%d: open rx pipe failed: %s\n",
857 sc->kue_unit, usbd_errstr(err));
862 err = usbd_open_pipe(sc->kue_iface, sc->kue_ed[KUE_ENDPT_TX],
863 USBD_EXCLUSIVE_USE, &sc->kue_ep[KUE_ENDPT_TX]);
865 printf("kue%d: open tx pipe failed: %s\n",
866 sc->kue_unit, usbd_errstr(err));
871 /* Start up the receive pipe. */
872 for (i = 0; i < UE_RX_LIST_CNT; i++) {
873 c = &sc->kue_cdata.ue_rx_chain[i];
874 usbd_setup_xfer(c->ue_xfer, sc->kue_ep[KUE_ENDPT_RX],
875 c, mtod(c->ue_mbuf, char *), UE_BUFSZ,
876 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, kue_rxeof);
877 usbd_transfer(c->ue_xfer);
880 ifp->if_drv_flags |= IFF_DRV_RUNNING;
881 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
889 kue_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
891 struct kue_softc *sc = ifp->if_softc;
898 if (ifp->if_flags & IFF_UP) {
899 if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
900 ifp->if_flags & IFF_PROMISC &&
901 !(sc->kue_if_flags & IFF_PROMISC)) {
902 sc->kue_rxfilt |= KUE_RXFILT_PROMISC;
903 kue_setword(sc, KUE_CMD_SET_PKT_FILTER,
905 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING &&
906 !(ifp->if_flags & IFF_PROMISC) &&
907 sc->kue_if_flags & IFF_PROMISC) {
908 sc->kue_rxfilt &= ~KUE_RXFILT_PROMISC;
909 kue_setword(sc, KUE_CMD_SET_PKT_FILTER,
911 } else if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
914 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
917 sc->kue_if_flags = ifp->if_flags;
926 error = ether_ioctl(ifp, command, data);
936 kue_watchdog(struct ifnet *ifp)
938 struct kue_softc *sc;
945 printf("kue%d: watchdog timeout\n", sc->kue_unit);
947 c = &sc->kue_cdata.ue_tx_chain[0];
948 usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &stat);
949 kue_txeof(c->ue_xfer, c, stat);
951 if (ifp->if_snd.ifq_head != NULL)
959 * Stop the adapter and free any mbufs allocated to the
963 kue_stop(struct kue_softc *sc)
972 /* Stop transfers. */
973 if (sc->kue_ep[KUE_ENDPT_RX] != NULL) {
974 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_RX]);
976 printf("kue%d: abort rx pipe failed: %s\n",
977 sc->kue_unit, usbd_errstr(err));
979 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_RX]);
981 printf("kue%d: close rx pipe failed: %s\n",
982 sc->kue_unit, usbd_errstr(err));
984 sc->kue_ep[KUE_ENDPT_RX] = NULL;
987 if (sc->kue_ep[KUE_ENDPT_TX] != NULL) {
988 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_TX]);
990 printf("kue%d: abort tx pipe failed: %s\n",
991 sc->kue_unit, usbd_errstr(err));
993 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_TX]);
995 printf("kue%d: close tx pipe failed: %s\n",
996 sc->kue_unit, usbd_errstr(err));
998 sc->kue_ep[KUE_ENDPT_TX] = NULL;
1001 if (sc->kue_ep[KUE_ENDPT_INTR] != NULL) {
1002 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
1004 printf("kue%d: abort intr pipe failed: %s\n",
1005 sc->kue_unit, usbd_errstr(err));
1007 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
1009 printf("kue%d: close intr pipe failed: %s\n",
1010 sc->kue_unit, usbd_errstr(err));
1012 sc->kue_ep[KUE_ENDPT_INTR] = NULL;
1015 /* Free RX resources. */
1016 usb_ether_rx_list_free(&sc->kue_cdata);
1017 /* Free TX resources. */
1018 usb_ether_tx_list_free(&sc->kue_cdata);
1020 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
1027 * Stop all chip I/O so that the kernel's probe routines don't
1028 * get confused by errant DMAs when rebooting.
1031 kue_shutdown(device_t dev)
1033 struct kue_softc *sc;
1035 sc = device_get_softc(dev);