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 $
36 * Kawasaki LSI KL5KUSB101B USB to ethernet adapter driver.
38 * Written by Bill Paul <wpaul@ee.columbia.edu>
39 * Electrical Engineering Department
40 * Columbia University, New York City
44 * The KLSI USB to ethernet adapter chip contains an USB serial interface,
45 * ethernet MAC and embedded microcontroller (called the QT Engine).
46 * The chip must have firmware loaded into it before it will operate.
47 * Packets are passed between the chip and host via bulk transfers.
48 * There is an interrupt endpoint mentioned in the software spec, however
49 * it's currently unused. This device is 10Mbps half-duplex only, hence
50 * there is no media selection logic. The MAC supports a 128 entry
51 * multicast filter, though the exact size of the filter can depend
52 * on the firmware. Curiously, while the software spec describes various
53 * ethernet statistics counters, my sample adapter and firmware combination
54 * claims not to support any statistics counters at all.
56 * Note that once we load the firmware in the device, we have to be
57 * careful not to load it again: if you restart your computer but
58 * leave the adapter attached to the USB controller, it may remain
59 * powered on and retain its firmware. In this case, we don't need
60 * to load the firmware a second time.
62 * Special thanks to Rob Furr for providing an ADS Technologies
63 * adapter for development and testing. No monkeys were harmed during
64 * the development of this driver.
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/sockio.h>
71 #include <sys/malloc.h>
72 #include <sys/kernel.h>
73 #include <sys/socket.h>
77 #include <net/ifq_var.h>
78 #include <net/if_arp.h>
79 #include <net/ethernet.h>
80 #include <net/if_dl.h>
81 #include <net/if_media.h>
84 #include <machine/clock.h>
86 #include <bus/usb/usb.h>
87 #include <bus/usb/usbdi.h>
88 #include <bus/usb/usbdi_util.h>
89 #include <bus/usb/usbdivar.h>
90 #include <bus/usb/usb_ethersubr.h>
92 #include "if_kuereg.h"
93 #include <bus/usb/kue_fw.h>
95 MODULE_DEPEND(kue, usb, 1, 1, 1);
98 * Various supported device vendors/products.
100 static const struct usb_devno kue_devs[] = {
101 { USB_DEVICE(0x03e8, 0x0008) }, /* AOX USB101 */
102 { USB_DEVICE(0x04bb, 0x0901) }, /* I-O DATA USBETT */
103 { USB_DEVICE(0x0506, 0x03e8) }, /* 3Com 3C19250 */
104 { USB_DEVICE(0x0557, 0x2002) }, /* ATen UC10T */
105 { USB_DEVICE(0x0565, 0x0002) }, /* Peracom Ethernet adapter */
106 { USB_DEVICE(0x0565, 0x0003) }, /* Peracom Ethernet adapter*/
107 { USB_DEVICE(0x0565, 0x0005) }, /* Peracom Ethernet adapter */
108 { USB_DEVICE(0x05e9, 0x0008) }, /* AOX (rebranded Kawasaki?) USB101*/
109 { USB_DEVICE(0x05e9, 0x0008) }, /* Kawasaki LSI DUH3E10BT */
110 { USB_DEVICE(0x05e9, 0x0009) }, /* Kawasaki LSI DUH3E10BTN */
111 { USB_DEVICE(0x066b, 0x2202) }, /* Linksys USB10T */
112 { USB_DEVICE(0x06e1, 0x0008) }, /* ADS UBS-10BT */
113 { USB_DEVICE(0x0707, 0x0100) }, /* SMC 2102USB */
114 { USB_DEVICE(0x07aa, 0x0001) }, /* Corega USB-T*/
115 { USB_DEVICE(0x07b8, 0x4000) }, /* AboCom URE450 */
116 { USB_DEVICE(0x0846, 0x1001) }, /* Netgear EA101 */
117 { USB_DEVICE(0x1645, 0x0005) }, /* Entrega E45*/
118 { USB_DEVICE(0x2001, 0x4000) }, /* D-Link DSB650C */
121 static int kue_match(device_t);
122 static int kue_attach(device_t);
123 static int kue_detach(device_t);
124 static void kue_shutdown(device_t);
125 static int kue_tx_list_init(struct kue_softc *);
126 static int kue_rx_list_init(struct kue_softc *);
127 static int kue_newbuf(struct kue_softc *, struct kue_chain *, struct mbuf *);
128 static int kue_encap(struct kue_softc *, struct mbuf *, int);
129 static void kue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
130 static void kue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
131 static void kue_start(struct ifnet *);
132 static void kue_rxstart(struct ifnet *);
133 static int kue_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
134 static void kue_init(void *);
135 static void kue_stop(struct kue_softc *);
136 static void kue_watchdog(struct ifnet *);
138 static void kue_setmulti(struct kue_softc *);
139 static void kue_reset(struct kue_softc *);
141 static usbd_status kue_do_request(usbd_device_handle,
142 usb_device_request_t *, void *);
143 static usbd_status kue_ctl(struct kue_softc *, int, u_int8_t,
144 u_int16_t, char *, int);
145 static usbd_status kue_setword(struct kue_softc *, u_int8_t, u_int16_t);
146 static int kue_load_fw(struct kue_softc *);
148 static device_method_t kue_methods[] = {
149 /* Device interface */
150 DEVMETHOD(device_probe, kue_match),
151 DEVMETHOD(device_attach, kue_attach),
152 DEVMETHOD(device_detach, kue_detach),
153 DEVMETHOD(device_shutdown, kue_shutdown),
158 static driver_t kue_driver = {
161 sizeof(struct kue_softc)
164 static devclass_t kue_devclass;
166 DECLARE_DUMMY_MODULE(if_kue);
167 DRIVER_MODULE(kue, uhub, kue_driver, kue_devclass, usbd_driver_load, NULL);
170 * We have a custom do_request function which is almost like the
171 * regular do_request function, except it has a much longer timeout.
172 * Why? Because we need to make requests over the control endpoint
173 * to download the firmware to the device, which can take longer
174 * than the default timeout.
177 kue_do_request(usbd_device_handle dev, usb_device_request_t *req, void *data)
179 usbd_xfer_handle xfer;
182 xfer = usbd_alloc_xfer(dev);
183 usbd_setup_default_xfer(xfer, dev, 0, 500000, req,
184 data, UGETW(req->wLength), USBD_SHORT_XFER_OK, 0);
185 err = usbd_sync_transfer(xfer);
186 usbd_free_xfer(xfer);
191 kue_setword(struct kue_softc *sc, u_int8_t breq, u_int16_t word)
193 usbd_device_handle dev;
194 usb_device_request_t req;
198 return(USBD_NORMAL_COMPLETION);
204 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
207 USETW(req.wValue, word);
208 USETW(req.wIndex, 0);
209 USETW(req.wLength, 0);
211 err = kue_do_request(dev, &req, NULL);
219 kue_ctl(struct kue_softc *sc, int rw, u_int8_t breq, u_int16_t val,
222 usbd_device_handle dev;
223 usb_device_request_t req;
229 return(USBD_NORMAL_COMPLETION);
233 if (rw == KUE_CTL_WRITE)
234 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
236 req.bmRequestType = UT_READ_VENDOR_DEVICE;
239 USETW(req.wValue, val);
240 USETW(req.wIndex, 0);
241 USETW(req.wLength, len);
243 err = kue_do_request(dev, &req, data);
251 kue_load_fw(struct kue_softc *sc)
254 usb_device_descriptor_t *dd;
257 dd = &sc->kue_udev->ddesc;
258 hwrev = UGETW(dd->bcdDevice);
261 * First, check if we even need to load the firmware.
262 * If the device was still attached when the system was
263 * rebooted, it may already have firmware loaded in it.
264 * If this is the case, we don't need to do it again.
265 * And in fact, if we try to load it again, we'll hang,
266 * so we have to avoid this condition if we don't want
269 * We can test this quickly by checking the bcdRevision
270 * code. The NIC will return a different revision code if
271 * it's probed while the firmware is still loaded and
277 /* Load code segment */
278 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN,
279 0, kue_code_seg, sizeof(kue_code_seg));
281 kprintf("kue%d: failed to load code segment: %s\n",
282 sc->kue_unit, usbd_errstr(err));
286 /* Load fixup segment */
287 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN,
288 0, kue_fix_seg, sizeof(kue_fix_seg));
290 kprintf("kue%d: failed to load fixup segment: %s\n",
291 sc->kue_unit, usbd_errstr(err));
295 /* Send trigger command. */
296 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN,
297 0, kue_trig_seg, sizeof(kue_trig_seg));
299 kprintf("kue%d: failed to load trigger segment: %s\n",
300 sc->kue_unit, usbd_errstr(err));
308 kue_setmulti(struct kue_softc *sc)
311 struct ifmultiaddr *ifma;
314 ifp = &sc->arpcom.ac_if;
316 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
317 sc->kue_rxfilt |= KUE_RXFILT_ALLMULTI;
318 sc->kue_rxfilt &= ~KUE_RXFILT_MULTICAST;
319 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt);
323 sc->kue_rxfilt &= ~KUE_RXFILT_ALLMULTI;
325 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
326 if (ifma->ifma_addr->sa_family != AF_LINK)
329 * If there are too many addresses for the
330 * internal filter, switch over to allmulti mode.
332 if (i == KUE_MCFILTCNT(sc))
334 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
335 KUE_MCFILT(sc, i), ETHER_ADDR_LEN);
339 if (i == KUE_MCFILTCNT(sc))
340 sc->kue_rxfilt |= KUE_RXFILT_ALLMULTI;
342 sc->kue_rxfilt |= KUE_RXFILT_MULTICAST;
343 kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MCAST_FILTERS,
344 i, sc->kue_mcfilters, i * ETHER_ADDR_LEN);
347 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt);
353 * Issue a SET_CONFIGURATION command to reset the MAC. This should be
354 * done after the firmware is loaded into the adapter in order to
355 * bring it into proper operation.
358 kue_reset(struct kue_softc *sc)
360 if (usbd_set_config_no(sc->kue_udev, KUE_CONFIG_NO, 0) ||
361 usbd_device2interface_handle(sc->kue_udev, KUE_IFACE_IDX,
363 kprintf("kue%d: getting interface handle failed\n",
367 /* Wait a little while for the chip to get its brains in order. */
373 * Probe for a KLSI chip.
376 kue_match(device_t self)
378 struct usb_attach_arg *uaa = device_get_ivars(self);
380 if (uaa->iface == NULL)
383 return (usb_lookup(kue_devs, uaa->vendor, uaa->product) != NULL ?
384 UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
388 * Attach the interface. Allocate softc structures, do
389 * setup and ethernet/BPF attach.
392 kue_attach(device_t self)
394 struct kue_softc *sc = device_get_softc(self);
395 struct usb_attach_arg *uaa = device_get_ivars(self);
398 usb_interface_descriptor_t *id;
399 usb_endpoint_descriptor_t *ed;
402 sc->kue_iface = uaa->iface;
403 sc->kue_udev = uaa->device;
404 sc->kue_unit = device_get_unit(self);
406 id = usbd_get_interface_descriptor(uaa->iface);
408 /* Find endpoints. */
409 for (i = 0; i < id->bNumEndpoints; i++) {
410 ed = usbd_interface2endpoint_descriptor(uaa->iface, i);
412 kprintf("kue%d: couldn't get ep %d\n",
416 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
417 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
418 sc->kue_ed[KUE_ENDPT_RX] = ed->bEndpointAddress;
419 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
420 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
421 sc->kue_ed[KUE_ENDPT_TX] = ed->bEndpointAddress;
422 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
423 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
424 sc->kue_ed[KUE_ENDPT_INTR] = ed->bEndpointAddress;
428 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
429 mtx_init(&sc->kue_mtx, device_get_nameunit(self), MTX_NETWORK_LOCK,
430 MTX_DEF | MTX_RECURSE);
434 /* Load the firmware into the NIC. */
435 if (kue_load_fw(sc)) {
437 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
438 mtx_destroy(&sc->kue_mtx);
443 /* Reset the adapter. */
446 /* Read ethernet descriptor */
447 err = kue_ctl(sc, KUE_CTL_READ, KUE_CMD_GET_ETHER_DESCRIPTOR,
448 0, (char *)&sc->kue_desc, sizeof(sc->kue_desc));
450 sc->kue_mcfilters = kmalloc(KUE_MCFILTCNT(sc) * ETHER_ADDR_LEN,
453 ifp = &sc->arpcom.ac_if;
455 if_initname(ifp, "kue", sc->kue_unit);
456 ifp->if_mtu = ETHERMTU;
457 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
458 ifp->if_ioctl = kue_ioctl;
459 ifp->if_start = kue_start;
460 ifp->if_watchdog = kue_watchdog;
461 ifp->if_init = kue_init;
462 ifp->if_baudrate = 10000000;
463 ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
464 ifq_set_ready(&ifp->if_snd);
467 * Call MI attach routine.
469 ether_ifattach(ifp, sc->kue_desc.kue_macaddr, NULL);
470 usb_register_netisr();
479 kue_detach(device_t dev)
481 struct kue_softc *sc;
484 sc = device_get_softc(dev);
486 ifp = &sc->arpcom.ac_if;
493 if (sc->kue_ep[KUE_ENDPT_TX] != NULL)
494 usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_TX]);
495 if (sc->kue_ep[KUE_ENDPT_RX] != NULL)
496 usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_RX]);
497 if (sc->kue_ep[KUE_ENDPT_INTR] != NULL)
498 usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
500 if (sc->kue_mcfilters != NULL)
501 kfree(sc->kue_mcfilters, M_USBDEV);
504 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
505 mtx_destroy(&sc->kue_mtx);
512 * Initialize an RX descriptor and attach an MBUF cluster.
515 kue_newbuf(struct kue_softc *sc, struct kue_chain *c, struct mbuf *m)
517 struct mbuf *m_new = NULL;
520 MGETHDR(m_new, MB_DONTWAIT, MT_DATA);
522 kprintf("kue%d: no memory for rx list "
523 "-- packet dropped!\n", sc->kue_unit);
527 MCLGET(m_new, MB_DONTWAIT);
528 if (!(m_new->m_flags & M_EXT)) {
529 kprintf("kue%d: no memory for rx list "
530 "-- packet dropped!\n", sc->kue_unit);
534 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
537 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
538 m_new->m_data = m_new->m_ext.ext_buf;
547 kue_rx_list_init(struct kue_softc *sc)
549 struct kue_cdata *cd;
554 for (i = 0; i < KUE_RX_LIST_CNT; i++) {
555 c = &cd->kue_rx_chain[i];
558 if (kue_newbuf(sc, c, NULL) == ENOBUFS)
560 if (c->kue_xfer == NULL) {
561 c->kue_xfer = usbd_alloc_xfer(sc->kue_udev);
562 if (c->kue_xfer == NULL)
571 kue_tx_list_init(struct kue_softc *sc)
573 struct kue_cdata *cd;
578 for (i = 0; i < KUE_TX_LIST_CNT; i++) {
579 c = &cd->kue_tx_chain[i];
583 if (c->kue_xfer == NULL) {
584 c->kue_xfer = usbd_alloc_xfer(sc->kue_udev);
585 if (c->kue_xfer == NULL)
588 c->kue_buf = kmalloc(KUE_BUFSZ, M_USBDEV, M_WAITOK);
595 kue_rxstart(struct ifnet *ifp)
597 struct kue_softc *sc;
602 c = &sc->kue_cdata.kue_rx_chain[sc->kue_cdata.kue_rx_prod];
604 if (kue_newbuf(sc, c, NULL) == ENOBUFS) {
609 /* Setup new transfer. */
610 usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_RX],
611 c, mtod(c->kue_mbuf, char *), KUE_BUFSZ, USBD_SHORT_XFER_OK,
612 USBD_NO_TIMEOUT, kue_rxeof);
613 usbd_transfer(c->kue_xfer);
621 * A frame has been uploaded: pass the resulting mbuf chain up to
622 * the higher level protocols.
625 kue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
627 struct kue_softc *sc;
637 ifp = &sc->arpcom.ac_if;
639 if (!(ifp->if_flags & IFF_RUNNING)) {
644 if (status != USBD_NORMAL_COMPLETION) {
645 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
649 if (usbd_ratecheck(&sc->kue_rx_notice))
650 kprintf("kue%d: usb error on rx: %s\n", sc->kue_unit,
651 usbd_errstr(status));
652 if (status == USBD_STALLED)
653 usbd_clear_endpoint_stall(sc->kue_ep[KUE_ENDPT_RX]);
657 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
662 len = *mtod(m, u_int16_t *);
663 m_adj(m, sizeof(u_int16_t));
665 /* No errors; receive the packet. */
668 if (len < sizeof(struct ether_header)) {
674 m->m_pkthdr.rcvif = ifp;
675 m->m_pkthdr.len = m->m_len = total_len;
677 /* Put the packet on the special USB input queue. */
686 /* Setup new transfer. */
687 usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_RX],
688 c, mtod(c->kue_mbuf, char *), KUE_BUFSZ, USBD_SHORT_XFER_OK,
689 USBD_NO_TIMEOUT, kue_rxeof);
690 usbd_transfer(c->kue_xfer);
697 * A frame was downloaded to the chip. It's safe for us to clean up
702 kue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
704 struct kue_softc *sc;
713 ifp = &sc->arpcom.ac_if;
715 ifp->if_flags &= ~IFF_OACTIVE;
717 if (status != USBD_NORMAL_COMPLETION) {
718 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
722 kprintf("kue%d: usb error on tx: %s\n", sc->kue_unit,
723 usbd_errstr(status));
724 if (status == USBD_STALLED)
725 usbd_clear_endpoint_stall(sc->kue_ep[KUE_ENDPT_TX]);
730 usbd_get_xfer_status(c->kue_xfer, NULL, NULL, NULL, &err);
732 if (c->kue_mbuf != NULL) {
733 m_freem(c->kue_mbuf);
742 if (!ifq_is_empty(&ifp->if_snd))
751 kue_encap(struct kue_softc *sc, struct mbuf *m, int idx)
757 c = &sc->kue_cdata.kue_tx_chain[idx];
760 * Copy the mbuf data into a contiguous buffer, leaving two
761 * bytes at the beginning to hold the frame length.
763 m_copydata(m, 0, m->m_pkthdr.len, c->kue_buf + 2);
766 total_len = m->m_pkthdr.len + 2;
767 total_len += 64 - (total_len % 64);
769 /* Frame length is specified in the first 2 bytes of the buffer. */
770 c->kue_buf[0] = (u_int8_t)m->m_pkthdr.len;
771 c->kue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
773 usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_TX],
774 c, c->kue_buf, total_len, 0, 10000, kue_txeof);
777 err = usbd_transfer(c->kue_xfer);
778 if (err != USBD_IN_PROGRESS) {
783 sc->kue_cdata.kue_tx_cnt++;
789 kue_start(struct ifnet *ifp)
791 struct kue_softc *sc;
792 struct mbuf *m_head = NULL;
797 if (ifp->if_flags & IFF_OACTIVE) {
802 m_head = ifq_dequeue(&ifp->if_snd, NULL);
803 if (m_head == NULL) {
808 if (kue_encap(sc, m_head, 0)) {
809 /* kue_encap() will free m_head, if we reach here */
810 ifp->if_flags |= IFF_OACTIVE;
816 * If there's a BPF listener, bounce a copy of this frame
819 BPF_MTAP(ifp, m_head);
821 ifp->if_flags |= IFF_OACTIVE;
824 * Set a timeout in case the chip goes out to lunch.
835 struct kue_softc *sc = xsc;
836 struct ifnet *ifp = &sc->arpcom.ac_if;
843 if (ifp->if_flags & IFF_RUNNING) {
848 /* Set MAC address */
849 kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MAC,
850 0, sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
852 sc->kue_rxfilt = KUE_RXFILT_UNICAST|KUE_RXFILT_BROADCAST;
854 /* If we want promiscuous mode, set the allframes bit. */
855 if (ifp->if_flags & IFF_PROMISC)
856 sc->kue_rxfilt |= KUE_RXFILT_PROMISC;
858 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt);
860 /* I'm not sure how to tune these. */
863 * Leave this one alone for now; setting it
864 * wrong causes lockups on some machines/controllers.
866 kue_setword(sc, KUE_CMD_SET_SOFS, 1);
868 kue_setword(sc, KUE_CMD_SET_URB_SIZE, 64);
871 if (kue_tx_list_init(sc) == ENOBUFS) {
872 kprintf("kue%d: tx list init failed\n", sc->kue_unit);
878 if (kue_rx_list_init(sc) == ENOBUFS) {
879 kprintf("kue%d: rx list init failed\n", sc->kue_unit);
884 /* Load the multicast filter. */
887 /* Open RX and TX pipes. */
888 err = usbd_open_pipe(sc->kue_iface, sc->kue_ed[KUE_ENDPT_RX],
889 USBD_EXCLUSIVE_USE, &sc->kue_ep[KUE_ENDPT_RX]);
891 kprintf("kue%d: open rx pipe failed: %s\n",
892 sc->kue_unit, usbd_errstr(err));
897 err = usbd_open_pipe(sc->kue_iface, sc->kue_ed[KUE_ENDPT_TX],
898 USBD_EXCLUSIVE_USE, &sc->kue_ep[KUE_ENDPT_TX]);
900 kprintf("kue%d: open tx pipe failed: %s\n",
901 sc->kue_unit, usbd_errstr(err));
906 /* Start up the receive pipe. */
907 for (i = 0; i < KUE_RX_LIST_CNT; i++) {
908 c = &sc->kue_cdata.kue_rx_chain[i];
909 usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_RX],
910 c, mtod(c->kue_mbuf, char *), KUE_BUFSZ,
911 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, kue_rxeof);
912 usbd_transfer(c->kue_xfer);
915 ifp->if_flags |= IFF_RUNNING;
916 ifp->if_flags &= ~IFF_OACTIVE;
924 kue_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
926 struct kue_softc *sc = ifp->if_softc;
933 if (ifp->if_flags & IFF_UP) {
934 if (ifp->if_flags & IFF_RUNNING &&
935 ifp->if_flags & IFF_PROMISC &&
936 !(sc->kue_if_flags & IFF_PROMISC)) {
937 sc->kue_rxfilt |= KUE_RXFILT_PROMISC;
938 kue_setword(sc, KUE_CMD_SET_PKT_FILTER,
940 } else if (ifp->if_flags & IFF_RUNNING &&
941 !(ifp->if_flags & IFF_PROMISC) &&
942 sc->kue_if_flags & IFF_PROMISC) {
943 sc->kue_rxfilt &= ~KUE_RXFILT_PROMISC;
944 kue_setword(sc, KUE_CMD_SET_PKT_FILTER,
946 } else if (!(ifp->if_flags & IFF_RUNNING))
949 if (ifp->if_flags & IFF_RUNNING)
952 sc->kue_if_flags = ifp->if_flags;
961 error = ether_ioctl(ifp, command, data);
971 kue_watchdog(struct ifnet *ifp)
973 struct kue_softc *sc;
980 kprintf("kue%d: watchdog timeout\n", sc->kue_unit);
982 c = &sc->kue_cdata.kue_tx_chain[0];
983 usbd_get_xfer_status(c->kue_xfer, NULL, NULL, NULL, &stat);
984 kue_txeof(c->kue_xfer, c, stat);
986 if (!ifq_is_empty(&ifp->if_snd))
994 * Stop the adapter and free any mbufs allocated to the
998 kue_stop(struct kue_softc *sc)
1005 ifp = &sc->arpcom.ac_if;
1008 /* Stop transfers. */
1009 if (sc->kue_ep[KUE_ENDPT_RX] != NULL) {
1010 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_RX]);
1012 kprintf("kue%d: abort rx pipe failed: %s\n",
1013 sc->kue_unit, usbd_errstr(err));
1015 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_RX]);
1017 kprintf("kue%d: close rx pipe failed: %s\n",
1018 sc->kue_unit, usbd_errstr(err));
1020 sc->kue_ep[KUE_ENDPT_RX] = NULL;
1023 if (sc->kue_ep[KUE_ENDPT_TX] != NULL) {
1024 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_TX]);
1026 kprintf("kue%d: abort tx pipe failed: %s\n",
1027 sc->kue_unit, usbd_errstr(err));
1029 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_TX]);
1031 kprintf("kue%d: close tx pipe failed: %s\n",
1032 sc->kue_unit, usbd_errstr(err));
1034 sc->kue_ep[KUE_ENDPT_TX] = NULL;
1037 if (sc->kue_ep[KUE_ENDPT_INTR] != NULL) {
1038 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
1040 kprintf("kue%d: abort intr pipe failed: %s\n",
1041 sc->kue_unit, usbd_errstr(err));
1043 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
1045 kprintf("kue%d: close intr pipe failed: %s\n",
1046 sc->kue_unit, usbd_errstr(err));
1048 sc->kue_ep[KUE_ENDPT_INTR] = NULL;
1051 /* Free RX resources. */
1052 for (i = 0; i < KUE_RX_LIST_CNT; i++) {
1053 if (sc->kue_cdata.kue_rx_chain[i].kue_buf != NULL) {
1054 kfree(sc->kue_cdata.kue_rx_chain[i].kue_buf, M_USBDEV);
1055 sc->kue_cdata.kue_rx_chain[i].kue_buf = NULL;
1057 if (sc->kue_cdata.kue_rx_chain[i].kue_mbuf != NULL) {
1058 m_freem(sc->kue_cdata.kue_rx_chain[i].kue_mbuf);
1059 sc->kue_cdata.kue_rx_chain[i].kue_mbuf = NULL;
1061 if (sc->kue_cdata.kue_rx_chain[i].kue_xfer != NULL) {
1062 usbd_free_xfer(sc->kue_cdata.kue_rx_chain[i].kue_xfer);
1063 sc->kue_cdata.kue_rx_chain[i].kue_xfer = NULL;
1067 /* Free TX resources. */
1068 for (i = 0; i < KUE_TX_LIST_CNT; i++) {
1069 if (sc->kue_cdata.kue_tx_chain[i].kue_buf != NULL) {
1070 kfree(sc->kue_cdata.kue_tx_chain[i].kue_buf, M_USBDEV);
1071 sc->kue_cdata.kue_tx_chain[i].kue_buf = NULL;
1073 if (sc->kue_cdata.kue_tx_chain[i].kue_mbuf != NULL) {
1074 m_freem(sc->kue_cdata.kue_tx_chain[i].kue_mbuf);
1075 sc->kue_cdata.kue_tx_chain[i].kue_mbuf = NULL;
1077 if (sc->kue_cdata.kue_tx_chain[i].kue_xfer != NULL) {
1078 usbd_free_xfer(sc->kue_cdata.kue_tx_chain[i].kue_xfer);
1079 sc->kue_cdata.kue_tx_chain[i].kue_xfer = NULL;
1083 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1090 * Stop all chip I/O so that the kernel's probe routines don't
1091 * get confused by errant DMAs when rebooting.
1094 kue_shutdown(device_t dev)
1096 struct kue_softc *sc;
1098 sc = device_get_softc(dev);