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>
76 #include <net/if_arp.h>
77 #include <net/ethernet.h>
78 #include <net/if_dl.h>
79 #include <net/if_media.h>
83 #include <machine/clock.h> /* for DELAY */
86 #include <dev/usb/usb.h>
87 #include <dev/usb/usbdi.h>
88 #include <dev/usb/usbdi_util.h>
89 #include <dev/usb/usbdivar.h>
90 #include <dev/usb/usbdevs.h>
91 #include <dev/usb/usb_ethersubr.h>
93 #include <dev/usb/if_kuereg.h>
94 #include <dev/usb/kue_fw.h>
97 static const char rcsid[] =
98 "$FreeBSD: src/sys/dev/usb/if_kue.c,v 1.17.2.9 2003/04/13 02:39:25 murray Exp $";
102 * Various supported device vendors/products.
104 Static struct kue_type kue_devs[] = {
105 { USB_VENDOR_AOX, USB_PRODUCT_AOX_USB101 },
106 { USB_VENDOR_KLSI, USB_PRODUCT_AOX_USB101 },
107 { USB_VENDOR_ADS, USB_PRODUCT_ADS_UBS10BT },
108 { USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC10T },
109 { USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_EA101 },
110 { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET },
111 { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET2 },
112 { USB_VENDOR_ENTREGA, USB_PRODUCT_ENTREGA_E45 },
113 { USB_VENDOR_3COM, USB_PRODUCT_3COM_3C19250 },
114 { USB_VENDOR_COREGA, USB_PRODUCT_COREGA_ETHER_USB_T },
115 { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650C },
116 { USB_VENDOR_SMC, USB_PRODUCT_SMC_2102USB },
117 { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T },
118 { USB_VENDOR_KLSI, USB_PRODUCT_KLSI_DUH3E10BT },
119 { USB_VENDOR_KLSI, USB_PRODUCT_KLSI_DUH3E10BTN },
120 { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET3 },
124 Static struct usb_qdat kue_qdat;
126 Static int kue_match(device_t);
127 Static int kue_attach(device_t);
128 Static int kue_detach(device_t);
129 Static void kue_shutdown(device_t);
130 Static int kue_tx_list_init(struct kue_softc *);
131 Static int kue_rx_list_init(struct kue_softc *);
132 Static int kue_newbuf(struct kue_softc *, struct kue_chain *, struct mbuf *);
133 Static int kue_encap(struct kue_softc *, struct mbuf *, int);
134 Static void kue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
135 Static void kue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
136 Static void kue_start(struct ifnet *);
137 Static void kue_rxstart(struct ifnet *);
138 Static int kue_ioctl(struct ifnet *, u_long, caddr_t);
139 Static void kue_init(void *);
140 Static void kue_stop(struct kue_softc *);
141 Static void kue_watchdog(struct ifnet *);
143 Static void kue_setmulti(struct kue_softc *);
144 Static void kue_reset(struct kue_softc *);
146 Static usbd_status kue_do_request(usbd_device_handle,
147 usb_device_request_t *, void *);
148 Static usbd_status kue_ctl(struct kue_softc *, int, u_int8_t,
149 u_int16_t, char *, int);
150 Static usbd_status kue_setword(struct kue_softc *, u_int8_t, u_int16_t);
151 Static int kue_load_fw(struct kue_softc *);
153 Static device_method_t kue_methods[] = {
154 /* Device interface */
155 DEVMETHOD(device_probe, kue_match),
156 DEVMETHOD(device_attach, kue_attach),
157 DEVMETHOD(device_detach, kue_detach),
158 DEVMETHOD(device_shutdown, kue_shutdown),
163 Static driver_t kue_driver = {
166 sizeof(struct kue_softc)
169 Static devclass_t kue_devclass;
171 DRIVER_MODULE(if_kue, uhub, kue_driver, kue_devclass, usbd_driver_load, 0);
174 * We have a custom do_request function which is almost like the
175 * regular do_request function, except it has a much longer timeout.
176 * Why? Because we need to make requests over the control endpoint
177 * to download the firmware to the device, which can take longer
178 * than the default timeout.
181 kue_do_request(usbd_device_handle dev, usb_device_request_t *req, void *data)
183 usbd_xfer_handle xfer;
186 xfer = usbd_alloc_xfer(dev);
187 usbd_setup_default_xfer(xfer, dev, 0, 500000, req,
188 data, UGETW(req->wLength), USBD_SHORT_XFER_OK|USBD_NO_TSLEEP, 0);
189 err = usbd_sync_transfer(xfer);
190 usbd_free_xfer(xfer);
195 kue_setword(struct kue_softc *sc, u_int8_t breq, u_int16_t word)
197 usbd_device_handle dev;
198 usb_device_request_t req;
203 return(USBD_NORMAL_COMPLETION);
209 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
212 USETW(req.wValue, word);
213 USETW(req.wIndex, 0);
214 USETW(req.wLength, 0);
216 err = kue_do_request(dev, &req, NULL);
224 kue_ctl(struct kue_softc *sc, int rw, u_int8_t breq, u_int16_t val,
227 usbd_device_handle dev;
228 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;
320 ifp = &sc->arpcom.ac_if;
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;
331 for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL;
332 ifma = ifma->ifma_link.le_next) {
333 if (ifma->ifma_addr->sa_family != AF_LINK)
336 * If there are too many addresses for the
337 * internal filter, switch over to allmulti mode.
339 if (i == KUE_MCFILTCNT(sc))
341 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
342 KUE_MCFILT(sc, i), ETHER_ADDR_LEN);
346 if (i == KUE_MCFILTCNT(sc))
347 sc->kue_rxfilt |= KUE_RXFILT_ALLMULTI;
349 sc->kue_rxfilt |= KUE_RXFILT_MULTICAST;
350 kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MCAST_FILTERS,
351 i, sc->kue_mcfilters, i * ETHER_ADDR_LEN);
354 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt);
360 * Issue a SET_CONFIGURATION command to reset the MAC. This should be
361 * done after the firmware is loaded into the adapter in order to
362 * bring it into proper operation.
365 kue_reset(struct kue_softc *sc)
367 if (usbd_set_config_no(sc->kue_udev, KUE_CONFIG_NO, 0)) {
368 printf("kue%d: 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.
382 USB_MATCH_START(kue, uaa);
390 if (uaa->vendor == t->kue_vid &&
391 uaa->product == t->kue_did) {
392 return(UMATCH_VENDOR_PRODUCT);
401 * Attach the interface. Allocate softc structures, do
402 * setup and ethernet/BPF attach.
406 USB_ATTACH_START(kue, sc, uaa);
411 usb_interface_descriptor_t *id;
412 usb_endpoint_descriptor_t *ed;
417 bzero(sc, sizeof(struct kue_softc));
418 sc->kue_iface = uaa->iface;
419 sc->kue_udev = uaa->device;
420 sc->kue_unit = device_get_unit(self);
422 id = usbd_get_interface_descriptor(uaa->iface);
424 usbd_devinfo(uaa->device, 0, devinfo);
425 device_set_desc_copy(self, devinfo);
426 printf("%s: %s\n", USBDEVNAME(self), devinfo);
428 /* Find endpoints. */
429 for (i = 0; i < id->bNumEndpoints; i++) {
430 ed = usbd_interface2endpoint_descriptor(uaa->iface, i);
432 printf("kue%d: couldn't get ep %d\n",
435 USB_ATTACH_ERROR_RETURN;
437 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
438 (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
439 sc->kue_ed[KUE_ENDPT_RX] = ed->bEndpointAddress;
440 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
441 (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
442 sc->kue_ed[KUE_ENDPT_TX] = ed->bEndpointAddress;
443 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
444 (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
445 sc->kue_ed[KUE_ENDPT_INTR] = ed->bEndpointAddress;
449 /* Load the firmware into the NIC. */
450 if (kue_load_fw(sc)) {
452 USB_ATTACH_ERROR_RETURN;
455 /* Reset the adapter. */
458 /* Read ethernet descriptor */
459 err = kue_ctl(sc, KUE_CTL_READ, KUE_CMD_GET_ETHER_DESCRIPTOR,
460 0, (char *)&sc->kue_desc, sizeof(sc->kue_desc));
462 sc->kue_mcfilters = malloc(KUE_MCFILTCNT(sc) * ETHER_ADDR_LEN,
466 * A KLSI chip was detected. Inform the world.
468 printf("kue%d: Ethernet address: %6D\n", sc->kue_unit,
469 sc->kue_desc.kue_macaddr, ":");
471 bcopy(sc->kue_desc.kue_macaddr,
472 (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
474 ifp = &sc->arpcom.ac_if;
476 ifp->if_unit = sc->kue_unit;
477 ifp->if_name = "kue";
478 ifp->if_mtu = ETHERMTU;
479 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
480 ifp->if_ioctl = kue_ioctl;
481 ifp->if_output = ether_output;
482 ifp->if_start = kue_start;
483 ifp->if_watchdog = kue_watchdog;
484 ifp->if_init = kue_init;
485 ifp->if_baudrate = 10000000;
486 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
489 kue_qdat.if_rxstart = kue_rxstart;
492 * Call MI attach routine.
494 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
495 usb_register_netisr();
499 USB_ATTACH_SUCCESS_RETURN;
503 kue_detach(device_ptr_t dev)
505 struct kue_softc *sc;
511 sc = device_get_softc(dev);
512 ifp = &sc->arpcom.ac_if;
517 ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
519 if (sc->kue_ep[KUE_ENDPT_TX] != NULL)
520 usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_TX]);
521 if (sc->kue_ep[KUE_ENDPT_RX] != NULL)
522 usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_RX]);
523 if (sc->kue_ep[KUE_ENDPT_INTR] != NULL)
524 usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
526 if (sc->kue_mcfilters != NULL)
527 free(sc->kue_mcfilters, M_USBDEV);
535 * Initialize an RX descriptor and attach an MBUF cluster.
538 kue_newbuf(struct kue_softc *sc, struct kue_chain *c, struct mbuf *m)
540 struct mbuf *m_new = NULL;
543 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
545 printf("kue%d: no memory for rx list "
546 "-- packet dropped!\n", sc->kue_unit);
550 MCLGET(m_new, M_DONTWAIT);
551 if (!(m_new->m_flags & M_EXT)) {
552 printf("kue%d: no memory for rx list "
553 "-- packet dropped!\n", sc->kue_unit);
557 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
560 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
561 m_new->m_data = m_new->m_ext.ext_buf;
570 kue_rx_list_init(struct kue_softc *sc)
572 struct kue_cdata *cd;
577 for (i = 0; i < KUE_RX_LIST_CNT; i++) {
578 c = &cd->kue_rx_chain[i];
581 if (kue_newbuf(sc, c, NULL) == ENOBUFS)
583 if (c->kue_xfer == NULL) {
584 c->kue_xfer = usbd_alloc_xfer(sc->kue_udev);
585 if (c->kue_xfer == NULL)
594 kue_tx_list_init(struct kue_softc *sc)
596 struct kue_cdata *cd;
601 for (i = 0; i < KUE_TX_LIST_CNT; i++) {
602 c = &cd->kue_tx_chain[i];
606 if (c->kue_xfer == NULL) {
607 c->kue_xfer = usbd_alloc_xfer(sc->kue_udev);
608 if (c->kue_xfer == NULL)
611 c->kue_buf = malloc(KUE_BUFSZ, M_USBDEV, M_NOWAIT);
612 if (c->kue_buf == NULL)
620 kue_rxstart(struct ifnet *ifp)
622 struct kue_softc *sc;
626 c = &sc->kue_cdata.kue_rx_chain[sc->kue_cdata.kue_rx_prod];
628 if (kue_newbuf(sc, c, NULL) == ENOBUFS) {
633 /* Setup new transfer. */
634 usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_RX],
635 c, mtod(c->kue_mbuf, char *), KUE_BUFSZ, USBD_SHORT_XFER_OK,
636 USBD_NO_TIMEOUT, kue_rxeof);
637 usbd_transfer(c->kue_xfer);
643 * A frame has been uploaded: pass the resulting mbuf chain up to
644 * the higher level protocols.
646 Static void kue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv,
649 struct kue_softc *sc;
658 ifp = &sc->arpcom.ac_if;
660 if (!(ifp->if_flags & IFF_RUNNING))
663 if (status != USBD_NORMAL_COMPLETION) {
664 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
666 printf("kue%d: usb error on rx: %s\n", sc->kue_unit,
667 usbd_errstr(status));
668 if (status == USBD_STALLED)
669 usbd_clear_endpoint_stall(sc->kue_ep[KUE_ENDPT_RX]);
673 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
678 len = *mtod(m, u_int16_t *);
679 m_adj(m, sizeof(u_int16_t));
681 /* No errors; receive the packet. */
684 if (len < sizeof(struct ether_header)) {
690 m->m_pkthdr.rcvif = (struct ifnet *)&kue_qdat;
691 m->m_pkthdr.len = m->m_len = total_len;
693 /* Put the packet on the special USB input queue. */
699 /* Setup new transfer. */
700 usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_RX],
701 c, mtod(c->kue_mbuf, char *), KUE_BUFSZ, USBD_SHORT_XFER_OK,
702 USBD_NO_TIMEOUT, kue_rxeof);
703 usbd_transfer(c->kue_xfer);
709 * A frame was downloaded to the chip. It's safe for us to clean up
714 kue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
716 struct kue_softc *sc;
726 ifp = &sc->arpcom.ac_if;
728 ifp->if_flags &= ~IFF_OACTIVE;
730 if (status != USBD_NORMAL_COMPLETION) {
731 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
735 printf("kue%d: usb error on tx: %s\n", sc->kue_unit,
736 usbd_errstr(status));
737 if (status == USBD_STALLED)
738 usbd_clear_endpoint_stall(sc->kue_ep[KUE_ENDPT_TX]);
743 usbd_get_xfer_status(c->kue_xfer, NULL, NULL, NULL, &err);
745 if (c->kue_mbuf != NULL) {
746 c->kue_mbuf->m_pkthdr.rcvif = ifp;
747 usb_tx_done(c->kue_mbuf);
762 kue_encap(struct kue_softc *sc, struct mbuf *m, int idx)
768 c = &sc->kue_cdata.kue_tx_chain[idx];
771 * Copy the mbuf data into a contiguous buffer, leaving two
772 * bytes at the beginning to hold the frame length.
774 m_copydata(m, 0, m->m_pkthdr.len, c->kue_buf + 2);
777 total_len = m->m_pkthdr.len + 2;
778 total_len += 64 - (total_len % 64);
780 /* Frame length is specified in the first 2 bytes of the buffer. */
781 c->kue_buf[0] = (u_int8_t)m->m_pkthdr.len;
782 c->kue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
784 usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_TX],
785 c, c->kue_buf, total_len, 0, 10000, kue_txeof);
788 err = usbd_transfer(c->kue_xfer);
789 if (err != USBD_IN_PROGRESS) {
794 sc->kue_cdata.kue_tx_cnt++;
800 kue_start(struct ifnet *ifp)
802 struct kue_softc *sc;
803 struct mbuf *m_head = NULL;
807 if (ifp->if_flags & IFF_OACTIVE)
810 IF_DEQUEUE(&ifp->if_snd, m_head);
814 if (kue_encap(sc, m_head, 0)) {
815 IF_PREPEND(&ifp->if_snd, m_head);
816 ifp->if_flags |= IFF_OACTIVE;
821 * If there's a BPF listener, bounce a copy of this frame
825 bpf_mtap(ifp, m_head);
827 ifp->if_flags |= IFF_OACTIVE;
830 * Set a timeout in case the chip goes out to lunch.
840 struct kue_softc *sc = xsc;
841 struct ifnet *ifp = &sc->arpcom.ac_if;
846 if (ifp->if_flags & IFF_RUNNING)
851 /* Set MAC address */
852 kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MAC,
853 0, sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
855 sc->kue_rxfilt = KUE_RXFILT_UNICAST|KUE_RXFILT_BROADCAST;
857 /* If we want promiscuous mode, set the allframes bit. */
858 if (ifp->if_flags & IFF_PROMISC)
859 sc->kue_rxfilt |= KUE_RXFILT_PROMISC;
861 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt);
863 /* I'm not sure how to tune these. */
866 * Leave this one alone for now; setting it
867 * wrong causes lockups on some machines/controllers.
869 kue_setword(sc, KUE_CMD_SET_SOFS, 1);
871 kue_setword(sc, KUE_CMD_SET_URB_SIZE, 64);
874 if (kue_tx_list_init(sc) == ENOBUFS) {
875 printf("kue%d: tx list init failed\n", sc->kue_unit);
881 if (kue_rx_list_init(sc) == ENOBUFS) {
882 printf("kue%d: rx list init failed\n", sc->kue_unit);
887 /* Load the multicast filter. */
890 /* Open RX and TX pipes. */
891 err = usbd_open_pipe(sc->kue_iface, sc->kue_ed[KUE_ENDPT_RX],
892 USBD_EXCLUSIVE_USE, &sc->kue_ep[KUE_ENDPT_RX]);
894 printf("kue%d: open rx pipe failed: %s\n",
895 sc->kue_unit, usbd_errstr(err));
900 err = usbd_open_pipe(sc->kue_iface, sc->kue_ed[KUE_ENDPT_TX],
901 USBD_EXCLUSIVE_USE, &sc->kue_ep[KUE_ENDPT_TX]);
903 printf("kue%d: open tx pipe failed: %s\n",
904 sc->kue_unit, usbd_errstr(err));
909 /* Start up the receive pipe. */
910 for (i = 0; i < KUE_RX_LIST_CNT; i++) {
911 c = &sc->kue_cdata.kue_rx_chain[i];
912 usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_RX],
913 c, mtod(c->kue_mbuf, char *), KUE_BUFSZ,
914 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, kue_rxeof);
915 usbd_transfer(c->kue_xfer);
918 ifp->if_flags |= IFF_RUNNING;
919 ifp->if_flags &= ~IFF_OACTIVE;
927 kue_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
929 struct kue_softc *sc = ifp->if_softc;
938 error = ether_ioctl(ifp, command, data);
941 if (ifp->if_flags & IFF_UP) {
942 if (ifp->if_flags & IFF_RUNNING &&
943 ifp->if_flags & IFF_PROMISC &&
944 !(sc->kue_if_flags & IFF_PROMISC)) {
945 sc->kue_rxfilt |= KUE_RXFILT_PROMISC;
946 kue_setword(sc, KUE_CMD_SET_PKT_FILTER,
948 } else if (ifp->if_flags & IFF_RUNNING &&
949 !(ifp->if_flags & IFF_PROMISC) &&
950 sc->kue_if_flags & IFF_PROMISC) {
951 sc->kue_rxfilt &= ~KUE_RXFILT_PROMISC;
952 kue_setword(sc, KUE_CMD_SET_PKT_FILTER,
954 } else if (!(ifp->if_flags & IFF_RUNNING))
957 if (ifp->if_flags & IFF_RUNNING)
960 sc->kue_if_flags = ifp->if_flags;
979 kue_watchdog(struct ifnet *ifp)
981 struct kue_softc *sc;
988 printf("kue%d: watchdog timeout\n", sc->kue_unit);
990 c = &sc->kue_cdata.kue_tx_chain[0];
991 usbd_get_xfer_status(c->kue_xfer, NULL, NULL, NULL, &stat);
992 kue_txeof(c->kue_xfer, c, stat);
994 if (ifp->if_snd.ifq_head != NULL)
1001 * Stop the adapter and free any mbufs allocated to the
1005 kue_stop(struct kue_softc *sc)
1011 ifp = &sc->arpcom.ac_if;
1014 /* Stop transfers. */
1015 if (sc->kue_ep[KUE_ENDPT_RX] != NULL) {
1016 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_RX]);
1018 printf("kue%d: abort rx pipe failed: %s\n",
1019 sc->kue_unit, usbd_errstr(err));
1021 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_RX]);
1023 printf("kue%d: close rx pipe failed: %s\n",
1024 sc->kue_unit, usbd_errstr(err));
1026 sc->kue_ep[KUE_ENDPT_RX] = NULL;
1029 if (sc->kue_ep[KUE_ENDPT_TX] != NULL) {
1030 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_TX]);
1032 printf("kue%d: abort tx pipe failed: %s\n",
1033 sc->kue_unit, usbd_errstr(err));
1035 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_TX]);
1037 printf("kue%d: close tx pipe failed: %s\n",
1038 sc->kue_unit, usbd_errstr(err));
1040 sc->kue_ep[KUE_ENDPT_TX] = NULL;
1043 if (sc->kue_ep[KUE_ENDPT_INTR] != NULL) {
1044 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
1046 printf("kue%d: abort intr pipe failed: %s\n",
1047 sc->kue_unit, usbd_errstr(err));
1049 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_INTR]);
1051 printf("kue%d: close intr pipe failed: %s\n",
1052 sc->kue_unit, usbd_errstr(err));
1054 sc->kue_ep[KUE_ENDPT_INTR] = NULL;
1057 /* Free RX resources. */
1058 for (i = 0; i < KUE_RX_LIST_CNT; i++) {
1059 if (sc->kue_cdata.kue_rx_chain[i].kue_buf != NULL) {
1060 free(sc->kue_cdata.kue_rx_chain[i].kue_buf, M_USBDEV);
1061 sc->kue_cdata.kue_rx_chain[i].kue_buf = NULL;
1063 if (sc->kue_cdata.kue_rx_chain[i].kue_mbuf != NULL) {
1064 m_freem(sc->kue_cdata.kue_rx_chain[i].kue_mbuf);
1065 sc->kue_cdata.kue_rx_chain[i].kue_mbuf = NULL;
1067 if (sc->kue_cdata.kue_rx_chain[i].kue_xfer != NULL) {
1068 usbd_free_xfer(sc->kue_cdata.kue_rx_chain[i].kue_xfer);
1069 sc->kue_cdata.kue_rx_chain[i].kue_xfer = NULL;
1073 /* Free TX resources. */
1074 for (i = 0; i < KUE_TX_LIST_CNT; i++) {
1075 if (sc->kue_cdata.kue_tx_chain[i].kue_buf != NULL) {
1076 free(sc->kue_cdata.kue_tx_chain[i].kue_buf, M_USBDEV);
1077 sc->kue_cdata.kue_tx_chain[i].kue_buf = NULL;
1079 if (sc->kue_cdata.kue_tx_chain[i].kue_mbuf != NULL) {
1080 m_freem(sc->kue_cdata.kue_tx_chain[i].kue_mbuf);
1081 sc->kue_cdata.kue_tx_chain[i].kue_mbuf = NULL;
1083 if (sc->kue_cdata.kue_tx_chain[i].kue_xfer != NULL) {
1084 usbd_free_xfer(sc->kue_cdata.kue_tx_chain[i].kue_xfer);
1085 sc->kue_cdata.kue_tx_chain[i].kue_xfer = NULL;
1089 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1095 * Stop all chip I/O so that the kernel's probe routines don't
1096 * get confused by errant DMAs when rebooting.
1099 kue_shutdown(device_ptr_t dev)
1101 struct kue_softc *sc;
1103 sc = device_get_softc(dev);