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.17 2005/02/16 22:50:28 joerg Exp $
38 * CATC USB-EL1210A USB to ethernet driver. Used in the CATC Netmate
39 * adapters and others.
41 * Written by Bill Paul <wpaul@ee.columbia.edu>
42 * Electrical Engineering Department
43 * Columbia University, New York City
47 * The CATC USB-EL1210A provides USB ethernet support at 10Mbps. The
48 * RX filter uses a 512-bit multicast hash table, single perfect entry
49 * for the station address, and promiscuous mode. Unlike the ADMtek
50 * and KLSI chips, the CATC ASIC supports read and write combining
51 * mode where multiple packets can be transfered using a single bulk
52 * transaction, which helps performance a great deal.
55 #include <sys/param.h>
56 #include <sys/systm.h>
57 #include <sys/sockio.h>
59 #include <sys/malloc.h>
60 #include <sys/kernel.h>
61 #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>
72 #include <machine/bus.h>
73 #if defined(__DragonFly__) || __FreeBSD_version < 500000
74 #include <machine/clock.h>
77 #include <bus/usb/usb.h>
78 #include <bus/usb/usbdi.h>
79 #include <bus/usb/usbdi_util.h>
80 #include <bus/usb/usbdivar.h>
81 #include <bus/usb/usbdevs.h>
82 #include <bus/usb/usb_ethersubr.h>
84 #include "if_cuereg.h"
87 * Various supported device vendors/products.
89 Static struct cue_type cue_devs[] = {
90 { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE },
91 { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE2 },
92 { USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTLINK },
96 Static int cue_match(device_ptr_t);
97 Static int cue_attach(device_ptr_t);
98 Static int cue_detach(device_ptr_t);
100 Static int cue_tx_list_init(struct cue_softc *);
101 Static int cue_rx_list_init(struct cue_softc *);
102 Static int cue_newbuf(struct cue_softc *, struct cue_chain *, struct mbuf *);
103 Static int cue_encap(struct cue_softc *, struct mbuf *, int);
104 Static void cue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
105 Static void cue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
106 Static void cue_tick(void *);
107 Static void cue_rxstart(struct ifnet *);
108 Static void cue_start(struct ifnet *);
109 Static int cue_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
110 Static void cue_init(void *);
111 Static void cue_stop(struct cue_softc *);
112 Static void cue_watchdog(struct ifnet *);
113 Static void cue_shutdown(device_ptr_t);
115 Static void cue_setmulti(struct cue_softc *);
116 Static uint32_t cue_mchash(const uint8_t *);
117 Static void cue_reset(struct cue_softc *);
119 Static int cue_csr_read_1(struct cue_softc *, int);
120 Static int cue_csr_write_1(struct cue_softc *, int, int);
121 Static int cue_csr_read_2(struct cue_softc *, int);
123 Static int cue_csr_write_2(struct cue_softc *, int, int);
125 Static int cue_mem(struct cue_softc *, int, int, void *, int);
126 Static int cue_getmac(struct cue_softc *, void *);
128 Static device_method_t cue_methods[] = {
129 /* Device interface */
130 DEVMETHOD(device_probe, cue_match),
131 DEVMETHOD(device_attach, cue_attach),
132 DEVMETHOD(device_detach, cue_detach),
133 DEVMETHOD(device_shutdown, cue_shutdown),
138 Static driver_t cue_driver = {
141 sizeof(struct cue_softc)
144 Static devclass_t cue_devclass;
146 DECLARE_DUMMY_MODULE(if_cue);
147 DRIVER_MODULE(cue, uhub, cue_driver, cue_devclass, usbd_driver_load, 0);
148 MODULE_DEPEND(cue, usb, 1, 1, 1);
150 #define CUE_SETBIT(sc, reg, x) \
151 cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) | (x))
153 #define CUE_CLRBIT(sc, reg, x) \
154 cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) & ~(x))
157 cue_csr_read_1(struct cue_softc *sc, int reg)
159 usb_device_request_t req;
168 req.bmRequestType = UT_READ_VENDOR_DEVICE;
169 req.bRequest = CUE_CMD_READREG;
170 USETW(req.wValue, 0);
171 USETW(req.wIndex, reg);
172 USETW(req.wLength, 1);
174 err = usbd_do_request(sc->cue_udev, &req, &val);
185 cue_csr_read_2(struct cue_softc *sc, int reg)
187 usb_device_request_t req;
196 req.bmRequestType = UT_READ_VENDOR_DEVICE;
197 req.bRequest = CUE_CMD_READREG;
198 USETW(req.wValue, 0);
199 USETW(req.wIndex, reg);
200 USETW(req.wLength, 2);
202 err = usbd_do_request(sc->cue_udev, &req, &val);
213 cue_csr_write_1(struct cue_softc *sc, int reg, int val)
215 usb_device_request_t req;
223 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
224 req.bRequest = CUE_CMD_WRITEREG;
225 USETW(req.wValue, val);
226 USETW(req.wIndex, reg);
227 USETW(req.wLength, 0);
229 err = usbd_do_request(sc->cue_udev, &req, NULL);
241 cue_csr_write_2(struct cue_softc *sc, int reg, int val)
243 usb_device_request_t req;
251 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
252 req.bRequest = CUE_CMD_WRITEREG;
253 USETW(req.wValue, val);
254 USETW(req.wIndex, reg);
255 USETW(req.wLength, 0);
257 err = usbd_do_request(sc->cue_udev, &req, NULL);
269 cue_mem(struct cue_softc *sc, int cmd, int addr, void *buf, int len)
271 usb_device_request_t req;
279 if (cmd == CUE_CMD_READSRAM)
280 req.bmRequestType = UT_READ_VENDOR_DEVICE;
282 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
284 USETW(req.wValue, 0);
285 USETW(req.wIndex, addr);
286 USETW(req.wLength, len);
288 err = usbd_do_request(sc->cue_udev, &req, buf);
299 cue_getmac(struct cue_softc *sc, void *buf)
301 usb_device_request_t req;
309 req.bmRequestType = UT_READ_VENDOR_DEVICE;
310 req.bRequest = CUE_CMD_GET_MACADDR;
311 USETW(req.wValue, 0);
312 USETW(req.wIndex, 0);
313 USETW(req.wLength, ETHER_ADDR_LEN);
315 err = usbd_do_request(sc->cue_udev, &req, buf);
320 printf("cue%d: read MAC address failed\n", sc->cue_unit);
327 #define CUE_POLY 0xEDB88320
331 cue_mchash(const uint8_t *addr)
337 /* Compute CRC for the address value. */
338 crc = 0xFFFFFFFF; /* initial value */
340 for (idx = 0; idx < 6; idx++) {
341 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
342 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? CUE_POLY : 0);
345 return (crc & ((1 << CUE_BITS) - 1));
349 cue_setmulti(struct cue_softc *sc)
352 struct ifmultiaddr *ifma;
355 ifp = &sc->arpcom.ac_if;
357 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
358 for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
359 sc->cue_mctab[i] = 0xFF;
360 cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
361 &sc->cue_mctab, CUE_MCAST_TABLE_LEN);
365 /* first, zot all the existing hash bits */
366 for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
367 sc->cue_mctab[i] = 0;
369 /* now program new ones */
370 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
371 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
373 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
376 if (ifma->ifma_addr->sa_family != AF_LINK)
378 h = cue_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
379 sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
383 * Also include the broadcast address in the filter
384 * so we can receive broadcast frames.
386 if (ifp->if_flags & IFF_BROADCAST) {
387 h = cue_mchash(ifp->if_broadcastaddr);
388 sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
391 cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
392 &sc->cue_mctab, CUE_MCAST_TABLE_LEN);
398 cue_reset(struct cue_softc *sc)
400 usb_device_request_t req;
406 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
407 req.bRequest = CUE_CMD_RESET;
408 USETW(req.wValue, 0);
409 USETW(req.wIndex, 0);
410 USETW(req.wLength, 0);
411 err = usbd_do_request(sc->cue_udev, &req, NULL);
413 printf("cue%d: reset failed\n", sc->cue_unit);
415 /* Wait a little while for the chip to get its brains in order. */
421 * Probe for a Pegasus chip.
425 USB_MATCH_START(cue, uaa);
433 if (uaa->vendor == t->cue_vid &&
434 uaa->product == t->cue_did) {
435 return(UMATCH_VENDOR_PRODUCT);
444 * Attach the interface. Allocate softc structures, do ifmedia
445 * setup and ethernet/BPF attach.
449 USB_ATTACH_START(cue, sc, uaa);
451 u_char eaddr[ETHER_ADDR_LEN];
453 usb_interface_descriptor_t *id;
454 usb_endpoint_descriptor_t *ed;
457 bzero(sc, sizeof(struct cue_softc));
458 sc->cue_iface = uaa->iface;
459 sc->cue_udev = uaa->device;
460 sc->cue_unit = device_get_unit(self);
461 callout_init(&sc->cue_stat_timer);
463 if (usbd_set_config_no(sc->cue_udev, CUE_CONFIG_NO, 0)) {
464 printf("cue%d: getting interface handle failed\n",
466 USB_ATTACH_ERROR_RETURN;
469 id = usbd_get_interface_descriptor(uaa->iface);
471 usbd_devinfo(uaa->device, 0, devinfo);
472 device_set_desc_copy(self, devinfo);
473 printf("%s: %s\n", USBDEVNAME(self), devinfo);
475 /* Find endpoints. */
476 for (i = 0; i < id->bNumEndpoints; i++) {
477 ed = usbd_interface2endpoint_descriptor(uaa->iface, i);
479 printf("cue%d: couldn't get ep %d\n",
481 USB_ATTACH_ERROR_RETURN;
483 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
484 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
485 sc->cue_ed[CUE_ENDPT_RX] = ed->bEndpointAddress;
486 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
487 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
488 sc->cue_ed[CUE_ENDPT_TX] = ed->bEndpointAddress;
489 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
490 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
491 sc->cue_ed[CUE_ENDPT_INTR] = ed->bEndpointAddress;
495 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
496 mtx_init(&sc->cue_mtx, device_get_nameunit(self), MTX_NETWORK_LOCK,
497 MTX_DEF | MTX_RECURSE);
502 /* Reset the adapter. */
506 * Get station address.
508 cue_getmac(sc, &eaddr);
510 ifp = &sc->arpcom.ac_if;
512 if_initname(ifp, "cue", sc->cue_unit);
513 ifp->if_mtu = ETHERMTU;
514 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
515 ifp->if_ioctl = cue_ioctl;
516 ifp->if_start = cue_start;
517 ifp->if_watchdog = cue_watchdog;
518 ifp->if_init = cue_init;
519 ifp->if_baudrate = 10000000;
520 ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
521 ifq_set_ready(&ifp->if_snd);
524 * Call MI attach routine.
526 ether_ifattach(ifp, eaddr);
527 usb_register_netisr();
531 USB_ATTACH_SUCCESS_RETURN;
535 cue_detach(device_ptr_t dev)
537 struct cue_softc *sc;
540 sc = device_get_softc(dev);
542 ifp = &sc->arpcom.ac_if;
545 callout_stop(&sc->cue_stat_timer);
548 if (sc->cue_ep[CUE_ENDPT_TX] != NULL)
549 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
550 if (sc->cue_ep[CUE_ENDPT_RX] != NULL)
551 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
552 if (sc->cue_ep[CUE_ENDPT_INTR] != NULL)
553 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
556 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
557 mtx_destroy(&sc->cue_mtx);
564 * Initialize an RX descriptor and attach an MBUF cluster.
567 cue_newbuf(struct cue_softc *sc, struct cue_chain *c, struct mbuf *m)
569 struct mbuf *m_new = NULL;
572 MGETHDR(m_new, MB_DONTWAIT, MT_DATA);
574 printf("cue%d: no memory for rx list "
575 "-- packet dropped!\n", sc->cue_unit);
579 MCLGET(m_new, MB_DONTWAIT);
580 if (!(m_new->m_flags & M_EXT)) {
581 printf("cue%d: no memory for rx list "
582 "-- packet dropped!\n", sc->cue_unit);
586 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
589 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
590 m_new->m_data = m_new->m_ext.ext_buf;
593 m_adj(m_new, ETHER_ALIGN);
600 cue_rx_list_init(struct cue_softc *sc)
602 struct cue_cdata *cd;
607 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
608 c = &cd->cue_rx_chain[i];
611 if (cue_newbuf(sc, c, NULL) == ENOBUFS)
613 if (c->cue_xfer == NULL) {
614 c->cue_xfer = usbd_alloc_xfer(sc->cue_udev);
615 if (c->cue_xfer == NULL)
624 cue_tx_list_init(struct cue_softc *sc)
626 struct cue_cdata *cd;
631 for (i = 0; i < CUE_TX_LIST_CNT; i++) {
632 c = &cd->cue_tx_chain[i];
636 if (c->cue_xfer == NULL) {
637 c->cue_xfer = usbd_alloc_xfer(sc->cue_udev);
638 if (c->cue_xfer == NULL)
641 c->cue_buf = malloc(CUE_BUFSZ, M_USBDEV, M_WAITOK);
648 cue_rxstart(struct ifnet *ifp)
650 struct cue_softc *sc;
655 c = &sc->cue_cdata.cue_rx_chain[sc->cue_cdata.cue_rx_prod];
657 if (cue_newbuf(sc, c, NULL) == ENOBUFS) {
663 /* Setup new transfer. */
664 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
665 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ, USBD_SHORT_XFER_OK,
666 USBD_NO_TIMEOUT, cue_rxeof);
667 usbd_transfer(c->cue_xfer);
674 * A frame has been uploaded: pass the resulting mbuf chain up to
675 * the higher level protocols.
678 cue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
680 struct cue_softc *sc;
690 ifp = &sc->arpcom.ac_if;
692 if (!(ifp->if_flags & IFF_RUNNING)) {
697 if (status != USBD_NORMAL_COMPLETION) {
698 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
702 if (usbd_ratecheck(&sc->cue_rx_notice))
703 printf("cue%d: usb error on rx: %s\n", sc->cue_unit,
704 usbd_errstr(status));
705 if (status == USBD_STALLED)
706 usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_RX]);
710 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
713 len = *mtod(m, u_int16_t *);
715 /* No errors; receive the packet. */
718 if (len < sizeof(struct ether_header)) {
724 m_adj(m, sizeof(u_int16_t));
725 m->m_pkthdr.rcvif = ifp;
726 m->m_pkthdr.len = m->m_len = total_len;
728 /* Put the packet on the special USB input queue. */
736 /* Setup new transfer. */
737 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
738 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ, USBD_SHORT_XFER_OK,
739 USBD_NO_TIMEOUT, cue_rxeof);
740 usbd_transfer(c->cue_xfer);
747 * A frame was downloaded to the chip. It's safe for us to clean up
752 cue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
754 struct cue_softc *sc;
762 ifp = &sc->arpcom.ac_if;
764 if (status != USBD_NORMAL_COMPLETION) {
765 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
769 printf("cue%d: usb error on tx: %s\n", sc->cue_unit,
770 usbd_errstr(status));
771 if (status == USBD_STALLED)
772 usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_TX]);
778 ifp->if_flags &= ~IFF_OACTIVE;
779 usbd_get_xfer_status(c->cue_xfer, NULL, NULL, NULL, &err);
781 if (c->cue_mbuf != NULL) {
782 m_freem(c->cue_mbuf);
791 if (!ifq_is_empty(&ifp->if_snd))
792 (*ifp->if_start)(ifp);
802 struct cue_softc *sc;
812 ifp = &sc->arpcom.ac_if;
814 ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_SINGLECOLL);
815 ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_MULTICOLL);
816 ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_EXCESSCOLL);
818 if (cue_csr_read_2(sc, CUE_RX_FRAMEERR))
821 callout_reset(&sc->cue_stat_timer, hz, cue_tick, sc);
829 cue_encap(struct cue_softc *sc, struct mbuf *m, int idx)
835 c = &sc->cue_cdata.cue_tx_chain[idx];
838 * Copy the mbuf data into a contiguous buffer, leaving two
839 * bytes at the beginning to hold the frame length.
841 m_copydata(m, 0, m->m_pkthdr.len, c->cue_buf + 2);
844 total_len = m->m_pkthdr.len + 2;
846 /* The first two bytes are the frame length */
847 c->cue_buf[0] = (u_int8_t)m->m_pkthdr.len;
848 c->cue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
850 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_TX],
851 c, c->cue_buf, total_len, 0, 10000, cue_txeof);
854 err = usbd_transfer(c->cue_xfer);
855 if (err != USBD_IN_PROGRESS) {
860 sc->cue_cdata.cue_tx_cnt++;
866 cue_start(struct ifnet *ifp)
868 struct cue_softc *sc;
869 struct mbuf *m_head = NULL;
874 if (ifp->if_flags & IFF_OACTIVE) {
879 m_head = ifq_poll(&ifp->if_snd);
880 if (m_head == NULL) {
885 if (cue_encap(sc, m_head, 0)) {
886 ifp->if_flags |= IFF_OACTIVE;
890 m_head = ifq_dequeue(&ifp->if_snd);
893 * If there's a BPF listener, bounce a copy of this frame
896 BPF_MTAP(ifp, m_head);
898 ifp->if_flags |= IFF_OACTIVE;
901 * Set a timeout in case the chip goes out to lunch.
912 struct cue_softc *sc = xsc;
913 struct ifnet *ifp = &sc->arpcom.ac_if;
918 if (ifp->if_flags & IFF_RUNNING)
924 * Cancel pending I/O and free all RX/TX buffers.
930 /* Set MAC address */
931 for (i = 0; i < ETHER_ADDR_LEN; i++)
932 cue_csr_write_1(sc, CUE_PAR0 - i, sc->arpcom.ac_enaddr[i]);
934 /* Enable RX logic. */
935 cue_csr_write_1(sc, CUE_ETHCTL, CUE_ETHCTL_RX_ON|CUE_ETHCTL_MCAST_ON);
937 /* If we want promiscuous mode, set the allframes bit. */
938 if (ifp->if_flags & IFF_PROMISC) {
939 CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
941 CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
945 if (cue_tx_list_init(sc) == ENOBUFS) {
946 printf("cue%d: tx list init failed\n", sc->cue_unit);
952 if (cue_rx_list_init(sc) == ENOBUFS) {
953 printf("cue%d: rx list init failed\n", sc->cue_unit);
958 /* Load the multicast filter. */
962 * Set the number of RX and TX buffers that we want
963 * to reserve inside the ASIC.
965 cue_csr_write_1(sc, CUE_RX_BUFPKTS, CUE_RX_FRAMES);
966 cue_csr_write_1(sc, CUE_TX_BUFPKTS, CUE_TX_FRAMES);
968 /* Set advanced operation modes. */
969 cue_csr_write_1(sc, CUE_ADVANCED_OPMODES,
970 CUE_AOP_EMBED_RXLEN|0x01); /* 1 wait state */
972 /* Program the LED operation. */
973 cue_csr_write_1(sc, CUE_LEDCTL, CUE_LEDCTL_FOLLOW_LINK);
975 /* Open RX and TX pipes. */
976 err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_RX],
977 USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_RX]);
979 printf("cue%d: open rx pipe failed: %s\n",
980 sc->cue_unit, usbd_errstr(err));
984 err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_TX],
985 USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_TX]);
987 printf("cue%d: open tx pipe failed: %s\n",
988 sc->cue_unit, usbd_errstr(err));
993 /* Start up the receive pipe. */
994 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
995 c = &sc->cue_cdata.cue_rx_chain[i];
996 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
997 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ,
998 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, cue_rxeof);
999 usbd_transfer(c->cue_xfer);
1002 ifp->if_flags |= IFF_RUNNING;
1003 ifp->if_flags &= ~IFF_OACTIVE;
1007 callout_reset(&sc->cue_stat_timer, hz, cue_tick, sc);
1011 cue_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
1013 struct cue_softc *sc = ifp->if_softc;
1020 if (ifp->if_flags & IFF_UP) {
1021 if (ifp->if_flags & IFF_RUNNING &&
1022 ifp->if_flags & IFF_PROMISC &&
1023 !(sc->cue_if_flags & IFF_PROMISC)) {
1024 CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
1026 } else if (ifp->if_flags & IFF_RUNNING &&
1027 !(ifp->if_flags & IFF_PROMISC) &&
1028 sc->cue_if_flags & IFF_PROMISC) {
1029 CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
1031 } else if (!(ifp->if_flags & IFF_RUNNING))
1034 if (ifp->if_flags & IFF_RUNNING)
1037 sc->cue_if_flags = ifp->if_flags;
1046 error = ether_ioctl(ifp, command, data);
1056 cue_watchdog(struct ifnet *ifp)
1058 struct cue_softc *sc;
1059 struct cue_chain *c;
1066 printf("cue%d: watchdog timeout\n", sc->cue_unit);
1068 c = &sc->cue_cdata.cue_tx_chain[0];
1069 usbd_get_xfer_status(c->cue_xfer, NULL, NULL, NULL, &stat);
1070 cue_txeof(c->cue_xfer, c, stat);
1072 if (!ifq_is_empty(&ifp->if_snd))
1080 * Stop the adapter and free any mbufs allocated to the
1084 cue_stop(struct cue_softc *sc)
1092 ifp = &sc->arpcom.ac_if;
1095 cue_csr_write_1(sc, CUE_ETHCTL, 0);
1097 callout_stop(&sc->cue_stat_timer);
1099 /* Stop transfers. */
1100 if (sc->cue_ep[CUE_ENDPT_RX] != NULL) {
1101 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
1103 printf("cue%d: abort rx pipe failed: %s\n",
1104 sc->cue_unit, usbd_errstr(err));
1106 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_RX]);
1108 printf("cue%d: close rx pipe failed: %s\n",
1109 sc->cue_unit, usbd_errstr(err));
1111 sc->cue_ep[CUE_ENDPT_RX] = NULL;
1114 if (sc->cue_ep[CUE_ENDPT_TX] != NULL) {
1115 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
1117 printf("cue%d: abort tx pipe failed: %s\n",
1118 sc->cue_unit, usbd_errstr(err));
1120 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_TX]);
1122 printf("cue%d: close tx pipe failed: %s\n",
1123 sc->cue_unit, usbd_errstr(err));
1125 sc->cue_ep[CUE_ENDPT_TX] = NULL;
1128 if (sc->cue_ep[CUE_ENDPT_INTR] != NULL) {
1129 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
1131 printf("cue%d: abort intr pipe failed: %s\n",
1132 sc->cue_unit, usbd_errstr(err));
1134 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
1136 printf("cue%d: close intr pipe failed: %s\n",
1137 sc->cue_unit, usbd_errstr(err));
1139 sc->cue_ep[CUE_ENDPT_INTR] = NULL;
1142 /* Free RX resources. */
1143 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
1144 if (sc->cue_cdata.cue_rx_chain[i].cue_buf != NULL) {
1145 free(sc->cue_cdata.cue_rx_chain[i].cue_buf, M_USBDEV);
1146 sc->cue_cdata.cue_rx_chain[i].cue_buf = NULL;
1148 if (sc->cue_cdata.cue_rx_chain[i].cue_mbuf != NULL) {
1149 m_freem(sc->cue_cdata.cue_rx_chain[i].cue_mbuf);
1150 sc->cue_cdata.cue_rx_chain[i].cue_mbuf = NULL;
1152 if (sc->cue_cdata.cue_rx_chain[i].cue_xfer != NULL) {
1153 usbd_free_xfer(sc->cue_cdata.cue_rx_chain[i].cue_xfer);
1154 sc->cue_cdata.cue_rx_chain[i].cue_xfer = NULL;
1158 /* Free TX resources. */
1159 for (i = 0; i < CUE_TX_LIST_CNT; i++) {
1160 if (sc->cue_cdata.cue_tx_chain[i].cue_buf != NULL) {
1161 free(sc->cue_cdata.cue_tx_chain[i].cue_buf, M_USBDEV);
1162 sc->cue_cdata.cue_tx_chain[i].cue_buf = NULL;
1164 if (sc->cue_cdata.cue_tx_chain[i].cue_mbuf != NULL) {
1165 m_freem(sc->cue_cdata.cue_tx_chain[i].cue_mbuf);
1166 sc->cue_cdata.cue_tx_chain[i].cue_mbuf = NULL;
1168 if (sc->cue_cdata.cue_tx_chain[i].cue_xfer != NULL) {
1169 usbd_free_xfer(sc->cue_cdata.cue_tx_chain[i].cue_xfer);
1170 sc->cue_cdata.cue_tx_chain[i].cue_xfer = NULL;
1174 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1181 * Stop all chip I/O so that the kernel's probe routines don't
1182 * get confused by errant DMAs when rebooting.
1185 cue_shutdown(device_ptr_t dev)
1187 struct cue_softc *sc;
1189 sc = device_get_softc(dev);