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.
32 * $FreeBSD: src/sys/dev/usb/if_kue.c,v 1.17.2.9 2003/04/13 02:39:25 murray Exp $
33 * $DragonFly: src/sys/dev/netif/kue/if_kue.c,v 1.4 2003/11/20 22:07:29 dillon Exp $
35 * $FreeBSD: src/sys/dev/usb/if_kue.c,v 1.17.2.9 2003/04/13 02:39:25 murray Exp $
39 * Kawasaki LSI KL5KUSB101B USB to ethernet adapter driver.
41 * Written by Bill Paul <wpaul@ee.columbia.edu>
42 * Electrical Engineering Department
43 * Columbia University, New York City
47 * The KLSI USB to ethernet adapter chip contains an USB serial interface,
48 * ethernet MAC and embedded microcontroller (called the QT Engine).
49 * The chip must have firmware loaded into it before it will operate.
50 * Packets are passed between the chip and host via bulk transfers.
51 * There is an interrupt endpoint mentioned in the software spec, however
52 * it's currently unused. This device is 10Mbps half-duplex only, hence
53 * there is no media selection logic. The MAC supports a 128 entry
54 * multicast filter, though the exact size of the filter can depend
55 * on the firmware. Curiously, while the software spec describes various
56 * ethernet statistics counters, my sample adapter and firmware combination
57 * claims not to support any statistics counters at all.
59 * Note that once we load the firmware in the device, we have to be
60 * careful not to load it again: if you restart your computer but
61 * leave the adapter attached to the USB controller, it may remain
62 * powered on and retain its firmware. In this case, we don't need
63 * to load the firmware a second time.
65 * Special thanks to Rob Furr for providing an ADS Technologies
66 * adapter for development and testing. No monkeys were harmed during
67 * the development of this driver.
70 #include <sys/param.h>
71 #include <sys/systm.h>
72 #include <sys/sockio.h>
74 #include <sys/malloc.h>
75 #include <sys/kernel.h>
76 #include <sys/socket.h>
79 #include <net/if_arp.h>
80 #include <net/ethernet.h>
81 #include <net/if_dl.h>
82 #include <net/if_media.h>
86 #include <machine/clock.h> /* for DELAY */
89 #include <bus/usb/usb.h>
90 #include <bus/usb/usbdi.h>
91 #include <bus/usb/usbdi_util.h>
92 #include <bus/usb/usbdivar.h>
93 #include <bus/usb/usbdevs.h>
94 #include <bus/usb/usb_ethersubr.h>
96 #include "if_kuereg.h"
97 #include <bus/usb/kue_fw.h>
100 * Various supported device vendors/products.
102 Static struct kue_type kue_devs[] = {
103 { USB_VENDOR_AOX, USB_PRODUCT_AOX_USB101 },
104 { USB_VENDOR_KLSI, USB_PRODUCT_AOX_USB101 },
105 { USB_VENDOR_ADS, USB_PRODUCT_ADS_UBS10BT },
106 { USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC10T },
107 { USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_EA101 },
108 { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET },
109 { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET2 },
110 { USB_VENDOR_ENTREGA, USB_PRODUCT_ENTREGA_E45 },
111 { USB_VENDOR_3COM, USB_PRODUCT_3COM_3C19250 },
112 { USB_VENDOR_COREGA, USB_PRODUCT_COREGA_ETHER_USB_T },
113 { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650C },
114 { USB_VENDOR_SMC, USB_PRODUCT_SMC_2102USB },
115 { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T },
116 { USB_VENDOR_KLSI, USB_PRODUCT_KLSI_DUH3E10BT },
117 { USB_VENDOR_KLSI, USB_PRODUCT_KLSI_DUH3E10BTN },
118 { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET3 },
122 Static struct usb_qdat kue_qdat;
124 Static int kue_match(device_t);
125 Static int kue_attach(device_t);
126 Static int kue_detach(device_t);
127 Static void kue_shutdown(device_t);
128 Static int kue_tx_list_init(struct kue_softc *);
129 Static int kue_rx_list_init(struct kue_softc *);
130 Static int kue_newbuf(struct kue_softc *, struct kue_chain *, struct mbuf *);
131 Static int kue_encap(struct kue_softc *, struct mbuf *, int);
132 Static void kue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
133 Static void kue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
134 Static void kue_start(struct ifnet *);
135 Static void kue_rxstart(struct ifnet *);
136 Static int kue_ioctl(struct ifnet *, u_long, caddr_t);
137 Static void kue_init(void *);
138 Static void kue_stop(struct kue_softc *);
139 Static void kue_watchdog(struct ifnet *);
141 Static void kue_setmulti(struct kue_softc *);
142 Static void kue_reset(struct kue_softc *);
144 Static usbd_status kue_do_request(usbd_device_handle,
145 usb_device_request_t *, void *);
146 Static usbd_status kue_ctl(struct kue_softc *, int, u_int8_t,
147 u_int16_t, char *, int);
148 Static usbd_status kue_setword(struct kue_softc *, u_int8_t, u_int16_t);
149 Static int kue_load_fw(struct kue_softc *);
151 Static device_method_t kue_methods[] = {
152 /* Device interface */
153 DEVMETHOD(device_probe, kue_match),
154 DEVMETHOD(device_attach, kue_attach),
155 DEVMETHOD(device_detach, kue_detach),
156 DEVMETHOD(device_shutdown, kue_shutdown),
161 Static driver_t kue_driver = {
164 sizeof(struct kue_softc)
167 Static devclass_t kue_devclass;
169 DECLARE_DUMMY_MODULE(if_kue);
170 DRIVER_MODULE(if_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|USBD_NO_TSLEEP, 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;
202 return(USBD_NORMAL_COMPLETION);
208 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
211 USETW(req.wValue, word);
212 USETW(req.wIndex, 0);
213 USETW(req.wLength, 0);
215 err = kue_do_request(dev, &req, NULL);
223 kue_ctl(struct kue_softc *sc, int rw, u_int8_t breq, u_int16_t val,
226 usbd_device_handle dev;
227 usb_device_request_t req;
234 return(USBD_NORMAL_COMPLETION);
238 if (rw == KUE_CTL_WRITE)
239 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
241 req.bmRequestType = UT_READ_VENDOR_DEVICE;
244 USETW(req.wValue, val);
245 USETW(req.wIndex, 0);
246 USETW(req.wLength, len);
248 err = kue_do_request(dev, &req, data);
256 kue_load_fw(struct kue_softc *sc)
259 usb_device_descriptor_t *dd;
262 dd = &sc->kue_udev->ddesc;
263 hwrev = UGETW(dd->bcdDevice);
266 * First, check if we even need to load the firmware.
267 * If the device was still attached when the system was
268 * rebooted, it may already have firmware loaded in it.
269 * If this is the case, we don't need to do it again.
270 * And in fact, if we try to load it again, we'll hang,
271 * so we have to avoid this condition if we don't want
274 * We can test this quickly by checking the bcdRevision
275 * code. The NIC will return a different revision code if
276 * it's probed while the firmware is still loaded and
282 /* Load code segment */
283 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN,
284 0, kue_code_seg, sizeof(kue_code_seg));
286 printf("kue%d: failed to load code segment: %s\n",
287 sc->kue_unit, usbd_errstr(err));
291 /* Load fixup segment */
292 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN,
293 0, kue_fix_seg, sizeof(kue_fix_seg));
295 printf("kue%d: failed to load fixup segment: %s\n",
296 sc->kue_unit, usbd_errstr(err));
300 /* Send trigger command. */
301 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN,
302 0, kue_trig_seg, sizeof(kue_trig_seg));
304 printf("kue%d: failed to load trigger segment: %s\n",
305 sc->kue_unit, usbd_errstr(err));
313 kue_setmulti(struct kue_softc *sc)
316 struct ifmultiaddr *ifma;
319 ifp = &sc->arpcom.ac_if;
321 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
322 sc->kue_rxfilt |= KUE_RXFILT_ALLMULTI;
323 sc->kue_rxfilt &= ~KUE_RXFILT_MULTICAST;
324 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt);
328 sc->kue_rxfilt &= ~KUE_RXFILT_ALLMULTI;
330 for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL;
331 ifma = ifma->ifma_link.le_next) {
332 if (ifma->ifma_addr->sa_family != AF_LINK)
335 * If there are too many addresses for the
336 * internal filter, switch over to allmulti mode.
338 if (i == KUE_MCFILTCNT(sc))
340 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
341 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 printf("kue%d: getting interface handle failed\n",
371 /* Wait a little while for the chip to get its brains in order. */
377 * Probe for a KLSI chip.
381 USB_MATCH_START(kue, uaa);
389 if (uaa->vendor == t->kue_vid &&
390 uaa->product == t->kue_did) {
391 return(UMATCH_VENDOR_PRODUCT);
400 * Attach the interface. Allocate softc structures, do
401 * setup and ethernet/BPF attach.
405 USB_ATTACH_START(kue, sc, uaa);
410 usb_interface_descriptor_t *id;
411 usb_endpoint_descriptor_t *ed;
416 bzero(sc, sizeof(struct kue_softc));
417 sc->kue_iface = uaa->iface;
418 sc->kue_udev = uaa->device;
419 sc->kue_unit = device_get_unit(self);
421 id = usbd_get_interface_descriptor(uaa->iface);
423 usbd_devinfo(uaa->device, 0, devinfo);
424 device_set_desc_copy(self, devinfo);
425 printf("%s: %s\n", USBDEVNAME(self), devinfo);
427 /* Find endpoints. */
428 for (i = 0; i < id->bNumEndpoints; i++) {
429 ed = usbd_interface2endpoint_descriptor(uaa->iface, i);
431 printf("kue%d: couldn't get ep %d\n",
434 USB_ATTACH_ERROR_RETURN;
436 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
437 (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
438 sc->kue_ed[KUE_ENDPT_RX] = ed->bEndpointAddress;
439 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
440 (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
441 sc->kue_ed[KUE_ENDPT_TX] = ed->bEndpointAddress;
442 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
443 (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
444 sc->kue_ed[KUE_ENDPT_INTR] = ed->bEndpointAddress;
448 /* Load the firmware into the NIC. */
449 if (kue_load_fw(sc)) {
451 USB_ATTACH_ERROR_RETURN;
454 /* Reset the adapter. */
457 /* Read ethernet descriptor */
458 err = kue_ctl(sc, KUE_CTL_READ, KUE_CMD_GET_ETHER_DESCRIPTOR,
459 0, (char *)&sc->kue_desc, sizeof(sc->kue_desc));
461 sc->kue_mcfilters = malloc(KUE_MCFILTCNT(sc) * ETHER_ADDR_LEN,
465 * A KLSI chip was detected. Inform the world.
467 printf("kue%d: Ethernet address: %6D\n", sc->kue_unit,
468 sc->kue_desc.kue_macaddr, ":");
470 bcopy(sc->kue_desc.kue_macaddr,
471 (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
473 ifp = &sc->arpcom.ac_if;
475 ifp->if_unit = sc->kue_unit;
476 ifp->if_name = "kue";
477 ifp->if_mtu = ETHERMTU;
478 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
479 ifp->if_ioctl = kue_ioctl;
480 ifp->if_output = ether_output;
481 ifp->if_start = kue_start;
482 ifp->if_watchdog = kue_watchdog;
483 ifp->if_init = kue_init;
484 ifp->if_baudrate = 10000000;
485 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
488 kue_qdat.if_rxstart = kue_rxstart;
491 * Call MI attach routine.
493 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
494 usb_register_netisr();
498 USB_ATTACH_SUCCESS_RETURN;
502 kue_detach(device_ptr_t dev)
504 struct kue_softc *sc;
510 sc = device_get_softc(dev);
511 ifp = &sc->arpcom.ac_if;
516 ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
518 if (sc->kue_ep[KUE_ENDPT_TX] != NULL)
519 usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_TX]);
520 if (sc->kue_ep[KUE_ENDPT_RX] != NULL)
521 usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_RX]);
522 if (sc->kue_ep[KUE_ENDPT_INTR] != NULL)
523 usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
525 if (sc->kue_mcfilters != NULL)
526 free(sc->kue_mcfilters, M_USBDEV);
534 * Initialize an RX descriptor and attach an MBUF cluster.
537 kue_newbuf(struct kue_softc *sc, struct kue_chain *c, struct mbuf *m)
539 struct mbuf *m_new = NULL;
542 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
544 printf("kue%d: no memory for rx list "
545 "-- packet dropped!\n", sc->kue_unit);
549 MCLGET(m_new, M_DONTWAIT);
550 if (!(m_new->m_flags & M_EXT)) {
551 printf("kue%d: no memory for rx list "
552 "-- packet dropped!\n", sc->kue_unit);
556 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
559 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
560 m_new->m_data = m_new->m_ext.ext_buf;
569 kue_rx_list_init(struct kue_softc *sc)
571 struct kue_cdata *cd;
576 for (i = 0; i < KUE_RX_LIST_CNT; i++) {
577 c = &cd->kue_rx_chain[i];
580 if (kue_newbuf(sc, c, NULL) == ENOBUFS)
582 if (c->kue_xfer == NULL) {
583 c->kue_xfer = usbd_alloc_xfer(sc->kue_udev);
584 if (c->kue_xfer == NULL)
593 kue_tx_list_init(struct kue_softc *sc)
595 struct kue_cdata *cd;
600 for (i = 0; i < KUE_TX_LIST_CNT; i++) {
601 c = &cd->kue_tx_chain[i];
605 if (c->kue_xfer == NULL) {
606 c->kue_xfer = usbd_alloc_xfer(sc->kue_udev);
607 if (c->kue_xfer == NULL)
610 c->kue_buf = malloc(KUE_BUFSZ, M_USBDEV, M_NOWAIT);
611 if (c->kue_buf == NULL)
619 kue_rxstart(struct ifnet *ifp)
621 struct kue_softc *sc;
625 c = &sc->kue_cdata.kue_rx_chain[sc->kue_cdata.kue_rx_prod];
627 if (kue_newbuf(sc, c, NULL) == ENOBUFS) {
632 /* Setup new transfer. */
633 usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_RX],
634 c, mtod(c->kue_mbuf, char *), KUE_BUFSZ, USBD_SHORT_XFER_OK,
635 USBD_NO_TIMEOUT, kue_rxeof);
636 usbd_transfer(c->kue_xfer);
642 * A frame has been uploaded: pass the resulting mbuf chain up to
643 * the higher level protocols.
645 Static void kue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv,
648 struct kue_softc *sc;
657 ifp = &sc->arpcom.ac_if;
659 if (!(ifp->if_flags & IFF_RUNNING))
662 if (status != USBD_NORMAL_COMPLETION) {
663 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
665 printf("kue%d: usb error on rx: %s\n", sc->kue_unit,
666 usbd_errstr(status));
667 if (status == USBD_STALLED)
668 usbd_clear_endpoint_stall(sc->kue_ep[KUE_ENDPT_RX]);
672 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
677 len = *mtod(m, u_int16_t *);
678 m_adj(m, sizeof(u_int16_t));
680 /* No errors; receive the packet. */
683 if (len < sizeof(struct ether_header)) {
689 m->m_pkthdr.rcvif = (struct ifnet *)&kue_qdat;
690 m->m_pkthdr.len = m->m_len = total_len;
692 /* Put the packet on the special USB input queue. */
698 /* Setup new transfer. */
699 usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_RX],
700 c, mtod(c->kue_mbuf, char *), KUE_BUFSZ, USBD_SHORT_XFER_OK,
701 USBD_NO_TIMEOUT, kue_rxeof);
702 usbd_transfer(c->kue_xfer);
708 * A frame was downloaded to the chip. It's safe for us to clean up
713 kue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
715 struct kue_softc *sc;
725 ifp = &sc->arpcom.ac_if;
727 ifp->if_flags &= ~IFF_OACTIVE;
729 if (status != USBD_NORMAL_COMPLETION) {
730 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
734 printf("kue%d: usb error on tx: %s\n", sc->kue_unit,
735 usbd_errstr(status));
736 if (status == USBD_STALLED)
737 usbd_clear_endpoint_stall(sc->kue_ep[KUE_ENDPT_TX]);
742 usbd_get_xfer_status(c->kue_xfer, NULL, NULL, NULL, &err);
744 if (c->kue_mbuf != NULL) {
745 c->kue_mbuf->m_pkthdr.rcvif = ifp;
746 usb_tx_done(c->kue_mbuf);
761 kue_encap(struct kue_softc *sc, struct mbuf *m, int idx)
767 c = &sc->kue_cdata.kue_tx_chain[idx];
770 * Copy the mbuf data into a contiguous buffer, leaving two
771 * bytes at the beginning to hold the frame length.
773 m_copydata(m, 0, m->m_pkthdr.len, c->kue_buf + 2);
776 total_len = m->m_pkthdr.len + 2;
777 total_len += 64 - (total_len % 64);
779 /* Frame length is specified in the first 2 bytes of the buffer. */
780 c->kue_buf[0] = (u_int8_t)m->m_pkthdr.len;
781 c->kue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
783 usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_TX],
784 c, c->kue_buf, total_len, 0, 10000, kue_txeof);
787 err = usbd_transfer(c->kue_xfer);
788 if (err != USBD_IN_PROGRESS) {
793 sc->kue_cdata.kue_tx_cnt++;
799 kue_start(struct ifnet *ifp)
801 struct kue_softc *sc;
802 struct mbuf *m_head = NULL;
806 if (ifp->if_flags & IFF_OACTIVE)
809 IF_DEQUEUE(&ifp->if_snd, m_head);
813 if (kue_encap(sc, m_head, 0)) {
814 IF_PREPEND(&ifp->if_snd, m_head);
815 ifp->if_flags |= IFF_OACTIVE;
820 * If there's a BPF listener, bounce a copy of this frame
824 bpf_mtap(ifp, m_head);
826 ifp->if_flags |= IFF_OACTIVE;
829 * Set a timeout in case the chip goes out to lunch.
839 struct kue_softc *sc = xsc;
840 struct ifnet *ifp = &sc->arpcom.ac_if;
845 if (ifp->if_flags & IFF_RUNNING)
850 /* Set MAC address */
851 kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MAC,
852 0, sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
854 sc->kue_rxfilt = KUE_RXFILT_UNICAST|KUE_RXFILT_BROADCAST;
856 /* If we want promiscuous mode, set the allframes bit. */
857 if (ifp->if_flags & IFF_PROMISC)
858 sc->kue_rxfilt |= KUE_RXFILT_PROMISC;
860 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt);
862 /* I'm not sure how to tune these. */
865 * Leave this one alone for now; setting it
866 * wrong causes lockups on some machines/controllers.
868 kue_setword(sc, KUE_CMD_SET_SOFS, 1);
870 kue_setword(sc, KUE_CMD_SET_URB_SIZE, 64);
873 if (kue_tx_list_init(sc) == ENOBUFS) {
874 printf("kue%d: tx list init failed\n", sc->kue_unit);
880 if (kue_rx_list_init(sc) == ENOBUFS) {
881 printf("kue%d: rx list init failed\n", sc->kue_unit);
886 /* Load the multicast filter. */
889 /* Open RX and TX pipes. */
890 err = usbd_open_pipe(sc->kue_iface, sc->kue_ed[KUE_ENDPT_RX],
891 USBD_EXCLUSIVE_USE, &sc->kue_ep[KUE_ENDPT_RX]);
893 printf("kue%d: open rx pipe failed: %s\n",
894 sc->kue_unit, usbd_errstr(err));
899 err = usbd_open_pipe(sc->kue_iface, sc->kue_ed[KUE_ENDPT_TX],
900 USBD_EXCLUSIVE_USE, &sc->kue_ep[KUE_ENDPT_TX]);
902 printf("kue%d: open tx pipe failed: %s\n",
903 sc->kue_unit, usbd_errstr(err));
908 /* Start up the receive pipe. */
909 for (i = 0; i < KUE_RX_LIST_CNT; i++) {
910 c = &sc->kue_cdata.kue_rx_chain[i];
911 usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_RX],
912 c, mtod(c->kue_mbuf, char *), KUE_BUFSZ,
913 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, kue_rxeof);
914 usbd_transfer(c->kue_xfer);
917 ifp->if_flags |= IFF_RUNNING;
918 ifp->if_flags &= ~IFF_OACTIVE;
926 kue_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
928 struct kue_softc *sc = ifp->if_softc;
937 error = ether_ioctl(ifp, command, data);
940 if (ifp->if_flags & IFF_UP) {
941 if (ifp->if_flags & IFF_RUNNING &&
942 ifp->if_flags & IFF_PROMISC &&
943 !(sc->kue_if_flags & IFF_PROMISC)) {
944 sc->kue_rxfilt |= KUE_RXFILT_PROMISC;
945 kue_setword(sc, KUE_CMD_SET_PKT_FILTER,
947 } else if (ifp->if_flags & IFF_RUNNING &&
948 !(ifp->if_flags & IFF_PROMISC) &&
949 sc->kue_if_flags & IFF_PROMISC) {
950 sc->kue_rxfilt &= ~KUE_RXFILT_PROMISC;
951 kue_setword(sc, KUE_CMD_SET_PKT_FILTER,
953 } else if (!(ifp->if_flags & IFF_RUNNING))
956 if (ifp->if_flags & IFF_RUNNING)
959 sc->kue_if_flags = ifp->if_flags;
978 kue_watchdog(struct ifnet *ifp)
980 struct kue_softc *sc;
987 printf("kue%d: watchdog timeout\n", sc->kue_unit);
989 c = &sc->kue_cdata.kue_tx_chain[0];
990 usbd_get_xfer_status(c->kue_xfer, NULL, NULL, NULL, &stat);
991 kue_txeof(c->kue_xfer, c, stat);
993 if (ifp->if_snd.ifq_head != NULL)
1000 * Stop the adapter and free any mbufs allocated to the
1004 kue_stop(struct kue_softc *sc)
1010 ifp = &sc->arpcom.ac_if;
1013 /* Stop transfers. */
1014 if (sc->kue_ep[KUE_ENDPT_RX] != NULL) {
1015 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_RX]);
1017 printf("kue%d: abort rx pipe failed: %s\n",
1018 sc->kue_unit, usbd_errstr(err));
1020 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_RX]);
1022 printf("kue%d: close rx pipe failed: %s\n",
1023 sc->kue_unit, usbd_errstr(err));
1025 sc->kue_ep[KUE_ENDPT_RX] = NULL;
1028 if (sc->kue_ep[KUE_ENDPT_TX] != NULL) {
1029 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_TX]);
1031 printf("kue%d: abort tx pipe failed: %s\n",
1032 sc->kue_unit, usbd_errstr(err));
1034 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_TX]);
1036 printf("kue%d: close tx pipe failed: %s\n",
1037 sc->kue_unit, usbd_errstr(err));
1039 sc->kue_ep[KUE_ENDPT_TX] = NULL;
1042 if (sc->kue_ep[KUE_ENDPT_INTR] != NULL) {
1043 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
1045 printf("kue%d: abort intr pipe failed: %s\n",
1046 sc->kue_unit, usbd_errstr(err));
1048 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
1050 printf("kue%d: close intr pipe failed: %s\n",
1051 sc->kue_unit, usbd_errstr(err));
1053 sc->kue_ep[KUE_ENDPT_INTR] = NULL;
1056 /* Free RX resources. */
1057 for (i = 0; i < KUE_RX_LIST_CNT; i++) {
1058 if (sc->kue_cdata.kue_rx_chain[i].kue_buf != NULL) {
1059 free(sc->kue_cdata.kue_rx_chain[i].kue_buf, M_USBDEV);
1060 sc->kue_cdata.kue_rx_chain[i].kue_buf = NULL;
1062 if (sc->kue_cdata.kue_rx_chain[i].kue_mbuf != NULL) {
1063 m_freem(sc->kue_cdata.kue_rx_chain[i].kue_mbuf);
1064 sc->kue_cdata.kue_rx_chain[i].kue_mbuf = NULL;
1066 if (sc->kue_cdata.kue_rx_chain[i].kue_xfer != NULL) {
1067 usbd_free_xfer(sc->kue_cdata.kue_rx_chain[i].kue_xfer);
1068 sc->kue_cdata.kue_rx_chain[i].kue_xfer = NULL;
1072 /* Free TX resources. */
1073 for (i = 0; i < KUE_TX_LIST_CNT; i++) {
1074 if (sc->kue_cdata.kue_tx_chain[i].kue_buf != NULL) {
1075 free(sc->kue_cdata.kue_tx_chain[i].kue_buf, M_USBDEV);
1076 sc->kue_cdata.kue_tx_chain[i].kue_buf = NULL;
1078 if (sc->kue_cdata.kue_tx_chain[i].kue_mbuf != NULL) {
1079 m_freem(sc->kue_cdata.kue_tx_chain[i].kue_mbuf);
1080 sc->kue_cdata.kue_tx_chain[i].kue_mbuf = NULL;
1082 if (sc->kue_cdata.kue_tx_chain[i].kue_xfer != NULL) {
1083 usbd_free_xfer(sc->kue_cdata.kue_tx_chain[i].kue_xfer);
1084 sc->kue_cdata.kue_tx_chain[i].kue_xfer = NULL;
1088 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1094 * Stop all chip I/O so that the kernel's probe routines don't
1095 * get confused by errant DMAs when rebooting.
1098 kue_shutdown(device_ptr_t dev)
1100 struct kue_softc *sc;
1102 sc = device_get_softc(dev);