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_cue.c,v 1.45 2003/12/08 07:54:14 obrien Exp $
33 * $DragonFly: src/sys/dev/netif/cue/if_cue.c,v 1.32 2008/05/14 11:59:19 sephe Exp $
37 * CATC USB-EL1210A USB to ethernet driver. Used in the CATC Netmate
38 * adapters and others.
40 * Written by Bill Paul <wpaul@ee.columbia.edu>
41 * Electrical Engineering Department
42 * Columbia University, New York City
46 * The CATC USB-EL1210A provides USB ethernet support at 10Mbps. The
47 * RX filter uses a 512-bit multicast hash table, single perfect entry
48 * for the station address, and promiscuous mode. Unlike the ADMtek
49 * and KLSI chips, the CATC ASIC supports read and write combining
50 * mode where multiple packets can be transfered using a single bulk
51 * transaction, which helps performance a great deal.
54 #include <sys/param.h>
55 #include <sys/systm.h>
56 #include <sys/sockio.h>
58 #include <sys/malloc.h>
59 #include <sys/kernel.h>
60 #include <sys/socket.h>
64 #include <net/ifq_var.h>
65 #include <net/if_arp.h>
66 #include <net/ethernet.h>
67 #include <net/if_dl.h>
70 #include <bus/usb/usb.h>
71 #include <bus/usb/usbdi.h>
72 #include <bus/usb/usbdi_util.h>
73 #include <bus/usb/usbdivar.h>
74 #include <bus/usb/usb_ethersubr.h>
76 #include "if_cuereg.h"
79 * Various supported device vendors/products.
81 static struct usb_devno cue_devs[] = {
82 { USB_DEVICE(0x0423, 0x000a) }, /* CATC Netmate */
83 { USB_DEVICE(0x0423, 0x000c) }, /* CATC Netmate2 */
84 { USB_DEVICE(0x08d1, 0x0001) }, /* SmartBridges SmartLink */
87 static int cue_match(device_t);
88 static int cue_attach(device_t);
89 static int cue_detach(device_t);
91 static int cue_tx_list_init(struct cue_softc *);
92 static int cue_rx_list_init(struct cue_softc *);
93 static int cue_newbuf(struct cue_softc *, struct cue_chain *, struct mbuf *);
94 static int cue_encap(struct cue_softc *, struct mbuf *, int);
95 static void cue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
96 static void cue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
97 static void cue_tick(void *);
98 static void cue_rxstart(struct ifnet *);
99 static void cue_start(struct ifnet *);
100 static int cue_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
101 static void cue_init(void *);
102 static void cue_stop(struct cue_softc *);
103 static void cue_watchdog(struct ifnet *);
104 static void cue_shutdown(device_t);
106 static void cue_setmulti(struct cue_softc *);
107 static void cue_reset(struct cue_softc *);
109 static int cue_csr_read_1(struct cue_softc *, int);
110 static int cue_csr_write_1(struct cue_softc *, int, int);
111 static int cue_csr_read_2(struct cue_softc *, int);
113 static int cue_csr_write_2(struct cue_softc *, int, int);
115 static int cue_mem(struct cue_softc *, int, int, void *, int);
116 static int cue_getmac(struct cue_softc *, void *);
118 static device_method_t cue_methods[] = {
119 /* Device interface */
120 DEVMETHOD(device_probe, cue_match),
121 DEVMETHOD(device_attach, cue_attach),
122 DEVMETHOD(device_detach, cue_detach),
123 DEVMETHOD(device_shutdown, cue_shutdown),
128 static driver_t cue_driver = {
131 sizeof(struct cue_softc)
134 static devclass_t cue_devclass;
136 DECLARE_DUMMY_MODULE(if_cue);
137 DRIVER_MODULE(cue, uhub, cue_driver, cue_devclass, usbd_driver_load, 0);
138 MODULE_DEPEND(cue, usb, 1, 1, 1);
140 #define CUE_SETBIT(sc, reg, x) \
141 cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) | (x))
143 #define CUE_CLRBIT(sc, reg, x) \
144 cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) & ~(x))
147 cue_csr_read_1(struct cue_softc *sc, int reg)
149 usb_device_request_t req;
158 req.bmRequestType = UT_READ_VENDOR_DEVICE;
159 req.bRequest = CUE_CMD_READREG;
160 USETW(req.wValue, 0);
161 USETW(req.wIndex, reg);
162 USETW(req.wLength, 1);
164 err = usbd_do_request(sc->cue_udev, &req, &val);
175 cue_csr_read_2(struct cue_softc *sc, int reg)
177 usb_device_request_t req;
186 req.bmRequestType = UT_READ_VENDOR_DEVICE;
187 req.bRequest = CUE_CMD_READREG;
188 USETW(req.wValue, 0);
189 USETW(req.wIndex, reg);
190 USETW(req.wLength, 2);
192 err = usbd_do_request(sc->cue_udev, &req, &val);
203 cue_csr_write_1(struct cue_softc *sc, int reg, int val)
205 usb_device_request_t req;
213 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
214 req.bRequest = CUE_CMD_WRITEREG;
215 USETW(req.wValue, val);
216 USETW(req.wIndex, reg);
217 USETW(req.wLength, 0);
219 err = usbd_do_request(sc->cue_udev, &req, NULL);
231 cue_csr_write_2(struct cue_softc *sc, int reg, int val)
233 usb_device_request_t req;
241 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
242 req.bRequest = CUE_CMD_WRITEREG;
243 USETW(req.wValue, val);
244 USETW(req.wIndex, reg);
245 USETW(req.wLength, 0);
247 err = usbd_do_request(sc->cue_udev, &req, NULL);
259 cue_mem(struct cue_softc *sc, int cmd, int addr, void *buf, int len)
261 usb_device_request_t req;
269 if (cmd == CUE_CMD_READSRAM)
270 req.bmRequestType = UT_READ_VENDOR_DEVICE;
272 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
274 USETW(req.wValue, 0);
275 USETW(req.wIndex, addr);
276 USETW(req.wLength, len);
278 err = usbd_do_request(sc->cue_udev, &req, buf);
289 cue_getmac(struct cue_softc *sc, void *buf)
291 usb_device_request_t req;
299 req.bmRequestType = UT_READ_VENDOR_DEVICE;
300 req.bRequest = CUE_CMD_GET_MACADDR;
301 USETW(req.wValue, 0);
302 USETW(req.wIndex, 0);
303 USETW(req.wLength, ETHER_ADDR_LEN);
305 err = usbd_do_request(sc->cue_udev, &req, buf);
310 if_printf(&sc->arpcom.ac_if, "read MAC address failed\n");
320 cue_setmulti(struct cue_softc *sc)
323 struct ifmultiaddr *ifma;
326 ifp = &sc->arpcom.ac_if;
328 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
329 for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
330 sc->cue_mctab[i] = 0xFF;
331 cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
332 &sc->cue_mctab, CUE_MCAST_TABLE_LEN);
336 /* first, zot all the existing hash bits */
337 for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
338 sc->cue_mctab[i] = 0;
340 /* now program new ones */
341 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
343 if (ifma->ifma_addr->sa_family != AF_LINK)
346 LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
347 ETHER_ADDR_LEN) & ((1 << CUE_BITS) - 1);
348 sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
352 * Also include the broadcast address in the filter
353 * so we can receive broadcast frames.
355 if (ifp->if_flags & IFF_BROADCAST) {
356 h = ether_crc32_le(ifp->if_broadcastaddr, ETHER_ADDR_LEN) &
357 ((1 << CUE_BITS) - 1);
358 sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
361 cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
362 &sc->cue_mctab, CUE_MCAST_TABLE_LEN);
368 cue_reset(struct cue_softc *sc)
370 usb_device_request_t req;
376 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
377 req.bRequest = CUE_CMD_RESET;
378 USETW(req.wValue, 0);
379 USETW(req.wIndex, 0);
380 USETW(req.wLength, 0);
381 err = usbd_do_request(sc->cue_udev, &req, NULL);
383 if_printf(&sc->arpcom.ac_if, "reset failed\n");
385 /* Wait a little while for the chip to get its brains in order. */
391 * Probe for a Pegasus chip.
394 cue_match(device_t self)
396 struct usb_attach_arg *uaa = device_get_ivars(self);
398 if (uaa->iface == NULL)
401 return (usb_lookup(cue_devs, uaa->vendor, uaa->product) != NULL) ?
402 UMATCH_VENDOR_PRODUCT : UMATCH_NONE;
406 * Attach the interface. Allocate softc structures, do ifmedia
407 * setup and ethernet/BPF attach.
410 cue_attach(device_t self)
412 struct cue_softc *sc = device_get_softc(self);
413 struct usb_attach_arg *uaa = device_get_ivars(self);
414 u_char eaddr[ETHER_ADDR_LEN];
416 usb_interface_descriptor_t *id;
417 usb_endpoint_descriptor_t *ed;
420 sc->cue_iface = uaa->iface;
421 sc->cue_udev = uaa->device;
422 callout_init(&sc->cue_stat_timer);
424 if (usbd_set_config_no(sc->cue_udev, CUE_CONFIG_NO, 0)) {
425 device_printf(self, "setting config no %d failed\n",
430 id = usbd_get_interface_descriptor(uaa->iface);
432 /* Find endpoints. */
433 for (i = 0; i < id->bNumEndpoints; i++) {
434 ed = usbd_interface2endpoint_descriptor(uaa->iface, i);
436 device_printf(self, "couldn't get ep %d\n", i);
439 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
440 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
441 sc->cue_ed[CUE_ENDPT_RX] = ed->bEndpointAddress;
442 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
443 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
444 sc->cue_ed[CUE_ENDPT_TX] = ed->bEndpointAddress;
445 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
446 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
447 sc->cue_ed[CUE_ENDPT_INTR] = ed->bEndpointAddress;
453 ifp = &sc->arpcom.ac_if;
454 if_initname(ifp, device_get_name(self), device_get_unit(self));
457 /* Reset the adapter. */
461 * Get station address.
463 cue_getmac(sc, &eaddr);
466 ifp->if_mtu = ETHERMTU;
467 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
468 ifp->if_ioctl = cue_ioctl;
469 ifp->if_start = cue_start;
470 ifp->if_watchdog = cue_watchdog;
471 ifp->if_init = cue_init;
472 ifp->if_baudrate = 10000000;
473 ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
474 ifq_set_ready(&ifp->if_snd);
477 * Call MI attach routine.
479 ether_ifattach(ifp, eaddr, NULL);
480 usb_register_netisr();
488 cue_detach(device_t dev)
490 struct cue_softc *sc;
493 sc = device_get_softc(dev);
495 ifp = &sc->arpcom.ac_if;
498 callout_stop(&sc->cue_stat_timer);
501 if (sc->cue_ep[CUE_ENDPT_TX] != NULL)
502 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
503 if (sc->cue_ep[CUE_ENDPT_RX] != NULL)
504 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
505 if (sc->cue_ep[CUE_ENDPT_INTR] != NULL)
506 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
514 * Initialize an RX descriptor and attach an MBUF cluster.
517 cue_newbuf(struct cue_softc *sc, struct cue_chain *c, struct mbuf *m)
519 struct mbuf *m_new = NULL;
522 MGETHDR(m_new, MB_DONTWAIT, MT_DATA);
524 if_printf(&sc->arpcom.ac_if, "no memory for rx list "
525 "-- packet dropped!\n");
529 MCLGET(m_new, MB_DONTWAIT);
530 if (!(m_new->m_flags & M_EXT)) {
531 if_printf(&sc->arpcom.ac_if, "no memory for rx list "
532 "-- packet dropped!\n");
536 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
539 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
540 m_new->m_data = m_new->m_ext.ext_buf;
543 m_adj(m_new, ETHER_ALIGN);
550 cue_rx_list_init(struct cue_softc *sc)
552 struct cue_cdata *cd;
557 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
558 c = &cd->cue_rx_chain[i];
561 if (cue_newbuf(sc, c, NULL) == ENOBUFS)
563 if (c->cue_xfer == NULL) {
564 c->cue_xfer = usbd_alloc_xfer(sc->cue_udev);
565 if (c->cue_xfer == NULL)
574 cue_tx_list_init(struct cue_softc *sc)
576 struct cue_cdata *cd;
581 for (i = 0; i < CUE_TX_LIST_CNT; i++) {
582 c = &cd->cue_tx_chain[i];
586 if (c->cue_xfer == NULL) {
587 c->cue_xfer = usbd_alloc_xfer(sc->cue_udev);
588 if (c->cue_xfer == NULL)
591 c->cue_buf = kmalloc(CUE_BUFSZ, M_USBDEV, M_WAITOK);
598 cue_rxstart(struct ifnet *ifp)
600 struct cue_softc *sc;
605 c = &sc->cue_cdata.cue_rx_chain[sc->cue_cdata.cue_rx_prod];
607 if (cue_newbuf(sc, c, NULL) == ENOBUFS) {
613 /* Setup new transfer. */
614 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
615 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ, USBD_SHORT_XFER_OK,
616 USBD_NO_TIMEOUT, cue_rxeof);
617 usbd_transfer(c->cue_xfer);
624 * A frame has been uploaded: pass the resulting mbuf chain up to
625 * the higher level protocols.
628 cue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
630 struct cue_softc *sc;
640 ifp = &sc->arpcom.ac_if;
642 if (!(ifp->if_flags & IFF_RUNNING)) {
647 if (status != USBD_NORMAL_COMPLETION) {
648 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
652 if (usbd_ratecheck(&sc->cue_rx_notice)) {
653 if_printf(ifp, "usb error on rx: %s\n",
654 usbd_errstr(status));
656 if (status == USBD_STALLED)
657 usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_RX]);
661 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
664 len = *mtod(m, u_int16_t *);
666 /* No errors; receive the packet. */
669 if (len < sizeof(struct ether_header)) {
675 m_adj(m, sizeof(u_int16_t));
676 m->m_pkthdr.rcvif = ifp;
677 m->m_pkthdr.len = m->m_len = total_len;
679 /* Put the packet on the special USB input queue. */
687 /* Setup new transfer. */
688 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
689 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ, USBD_SHORT_XFER_OK,
690 USBD_NO_TIMEOUT, cue_rxeof);
691 usbd_transfer(c->cue_xfer);
698 * A frame was downloaded to the chip. It's safe for us to clean up
703 cue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
705 struct cue_softc *sc;
713 ifp = &sc->arpcom.ac_if;
715 if (status != USBD_NORMAL_COMPLETION) {
716 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
720 if_printf(ifp, "usb error on tx: %s\n", usbd_errstr(status));
721 if (status == USBD_STALLED)
722 usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_TX]);
728 ifp->if_flags &= ~IFF_OACTIVE;
729 usbd_get_xfer_status(c->cue_xfer, NULL, NULL, NULL, &err);
731 if (c->cue_mbuf != NULL) {
732 m_freem(c->cue_mbuf);
741 if (!ifq_is_empty(&ifp->if_snd))
752 struct cue_softc *sc;
762 ifp = &sc->arpcom.ac_if;
764 ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_SINGLECOLL);
765 ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_MULTICOLL);
766 ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_EXCESSCOLL);
768 if (cue_csr_read_2(sc, CUE_RX_FRAMEERR))
771 callout_reset(&sc->cue_stat_timer, hz, cue_tick, sc);
779 cue_encap(struct cue_softc *sc, struct mbuf *m, int idx)
785 c = &sc->cue_cdata.cue_tx_chain[idx];
788 * Copy the mbuf data into a contiguous buffer, leaving two
789 * bytes at the beginning to hold the frame length.
791 m_copydata(m, 0, m->m_pkthdr.len, c->cue_buf + 2);
794 total_len = m->m_pkthdr.len + 2;
796 /* The first two bytes are the frame length */
797 c->cue_buf[0] = (u_int8_t)m->m_pkthdr.len;
798 c->cue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
800 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_TX],
801 c, c->cue_buf, total_len, 0, 10000, cue_txeof);
804 err = usbd_transfer(c->cue_xfer);
805 if (err != USBD_IN_PROGRESS) {
810 sc->cue_cdata.cue_tx_cnt++;
816 cue_start(struct ifnet *ifp)
818 struct cue_softc *sc;
819 struct mbuf *m_head = NULL;
824 if (ifp->if_flags & IFF_OACTIVE) {
829 m_head = ifq_dequeue(&ifp->if_snd, NULL);
830 if (m_head == NULL) {
835 if (cue_encap(sc, m_head, 0)) {
836 /* cue_encap() will free m_head, if we reach here */
837 ifp->if_flags |= IFF_OACTIVE;
843 * If there's a BPF listener, bounce a copy of this frame
846 BPF_MTAP(ifp, m_head);
848 ifp->if_flags |= IFF_OACTIVE;
851 * Set a timeout in case the chip goes out to lunch.
862 struct cue_softc *sc = xsc;
863 struct ifnet *ifp = &sc->arpcom.ac_if;
868 if (ifp->if_flags & IFF_RUNNING)
874 * Cancel pending I/O and free all RX/TX buffers.
880 /* Set MAC address */
881 for (i = 0; i < ETHER_ADDR_LEN; i++)
882 cue_csr_write_1(sc, CUE_PAR0 - i, sc->arpcom.ac_enaddr[i]);
884 /* Enable RX logic. */
885 cue_csr_write_1(sc, CUE_ETHCTL, CUE_ETHCTL_RX_ON|CUE_ETHCTL_MCAST_ON);
887 /* If we want promiscuous mode, set the allframes bit. */
888 if (ifp->if_flags & IFF_PROMISC) {
889 CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
891 CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
895 if (cue_tx_list_init(sc) == ENOBUFS) {
896 if_printf(ifp, "tx list init failed\n");
902 if (cue_rx_list_init(sc) == ENOBUFS) {
903 if_printf(ifp, "rx list init failed\n");
908 /* Load the multicast filter. */
912 * Set the number of RX and TX buffers that we want
913 * to reserve inside the ASIC.
915 cue_csr_write_1(sc, CUE_RX_BUFPKTS, CUE_RX_FRAMES);
916 cue_csr_write_1(sc, CUE_TX_BUFPKTS, CUE_TX_FRAMES);
918 /* Set advanced operation modes. */
919 cue_csr_write_1(sc, CUE_ADVANCED_OPMODES,
920 CUE_AOP_EMBED_RXLEN|0x01); /* 1 wait state */
922 /* Program the LED operation. */
923 cue_csr_write_1(sc, CUE_LEDCTL, CUE_LEDCTL_FOLLOW_LINK);
925 /* Open RX and TX pipes. */
926 err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_RX],
927 USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_RX]);
929 if_printf(ifp, "open rx pipe failed: %s\n", usbd_errstr(err));
933 err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_TX],
934 USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_TX]);
936 if_printf(ifp, "open tx pipe failed: %s\n", usbd_errstr(err));
941 /* Start up the receive pipe. */
942 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
943 c = &sc->cue_cdata.cue_rx_chain[i];
944 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
945 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ,
946 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, cue_rxeof);
947 usbd_transfer(c->cue_xfer);
950 ifp->if_flags |= IFF_RUNNING;
951 ifp->if_flags &= ~IFF_OACTIVE;
955 callout_reset(&sc->cue_stat_timer, hz, cue_tick, sc);
959 cue_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
961 struct cue_softc *sc = ifp->if_softc;
968 if (ifp->if_flags & IFF_UP) {
969 if (ifp->if_flags & IFF_RUNNING &&
970 ifp->if_flags & IFF_PROMISC &&
971 !(sc->cue_if_flags & IFF_PROMISC)) {
972 CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
974 } else if (ifp->if_flags & IFF_RUNNING &&
975 !(ifp->if_flags & IFF_PROMISC) &&
976 sc->cue_if_flags & IFF_PROMISC) {
977 CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
979 } else if (!(ifp->if_flags & IFF_RUNNING))
982 if (ifp->if_flags & IFF_RUNNING)
985 sc->cue_if_flags = ifp->if_flags;
994 error = ether_ioctl(ifp, command, data);
1004 cue_watchdog(struct ifnet *ifp)
1006 struct cue_softc *sc;
1007 struct cue_chain *c;
1014 if_printf(ifp, "watchdog timeout\n");
1016 c = &sc->cue_cdata.cue_tx_chain[0];
1017 usbd_get_xfer_status(c->cue_xfer, NULL, NULL, NULL, &stat);
1018 cue_txeof(c->cue_xfer, c, stat);
1020 if (!ifq_is_empty(&ifp->if_snd))
1028 * Stop the adapter and free any mbufs allocated to the
1032 cue_stop(struct cue_softc *sc)
1040 ifp = &sc->arpcom.ac_if;
1043 cue_csr_write_1(sc, CUE_ETHCTL, 0);
1045 callout_stop(&sc->cue_stat_timer);
1047 /* Stop transfers. */
1048 if (sc->cue_ep[CUE_ENDPT_RX] != NULL) {
1049 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
1051 if_printf(ifp, "abort rx pipe failed: %s\n",
1054 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_RX]);
1056 if_printf(ifp, "close rx pipe failed: %s\n",
1059 sc->cue_ep[CUE_ENDPT_RX] = NULL;
1062 if (sc->cue_ep[CUE_ENDPT_TX] != NULL) {
1063 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
1065 if_printf(ifp, "abort tx pipe failed: %s\n",
1068 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_TX]);
1070 if_printf(ifp, "close tx pipe failed: %s\n",
1073 sc->cue_ep[CUE_ENDPT_TX] = NULL;
1076 if (sc->cue_ep[CUE_ENDPT_INTR] != NULL) {
1077 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
1079 if_printf(ifp, "abort intr pipe failed: %s\n",
1082 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
1084 if_printf(ifp, "close intr pipe failed: %s\n",
1087 sc->cue_ep[CUE_ENDPT_INTR] = NULL;
1090 /* Free RX resources. */
1091 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
1092 if (sc->cue_cdata.cue_rx_chain[i].cue_buf != NULL) {
1093 kfree(sc->cue_cdata.cue_rx_chain[i].cue_buf, M_USBDEV);
1094 sc->cue_cdata.cue_rx_chain[i].cue_buf = NULL;
1096 if (sc->cue_cdata.cue_rx_chain[i].cue_mbuf != NULL) {
1097 m_freem(sc->cue_cdata.cue_rx_chain[i].cue_mbuf);
1098 sc->cue_cdata.cue_rx_chain[i].cue_mbuf = NULL;
1100 if (sc->cue_cdata.cue_rx_chain[i].cue_xfer != NULL) {
1101 usbd_free_xfer(sc->cue_cdata.cue_rx_chain[i].cue_xfer);
1102 sc->cue_cdata.cue_rx_chain[i].cue_xfer = NULL;
1106 /* Free TX resources. */
1107 for (i = 0; i < CUE_TX_LIST_CNT; i++) {
1108 if (sc->cue_cdata.cue_tx_chain[i].cue_buf != NULL) {
1109 kfree(sc->cue_cdata.cue_tx_chain[i].cue_buf, M_USBDEV);
1110 sc->cue_cdata.cue_tx_chain[i].cue_buf = NULL;
1112 if (sc->cue_cdata.cue_tx_chain[i].cue_mbuf != NULL) {
1113 m_freem(sc->cue_cdata.cue_tx_chain[i].cue_mbuf);
1114 sc->cue_cdata.cue_tx_chain[i].cue_mbuf = NULL;
1116 if (sc->cue_cdata.cue_tx_chain[i].cue_xfer != NULL) {
1117 usbd_free_xfer(sc->cue_cdata.cue_tx_chain[i].cue_xfer);
1118 sc->cue_cdata.cue_tx_chain[i].cue_xfer = NULL;
1122 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1129 * Stop all chip I/O so that the kernel's probe routines don't
1130 * get confused by errant DMAs when rebooting.
1133 cue_shutdown(device_t dev)
1135 struct cue_softc *sc;
1137 sc = device_get_softc(dev);