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.7.2.6 2002/11/06 14:23:20 joe Exp $
36 * CATC USB-EL1210A USB to ethernet driver. Used in the CATC Netmate
37 * adapters and others.
39 * Written by Bill Paul <wpaul@ee.columbia.edu>
40 * Electrical Engineering Department
41 * Columbia University, New York City
45 * The CATC USB-EL1210A provides USB ethernet support at 10Mbps. The
46 * RX filter uses a 512-bit multicast hash table, single perfect entry
47 * for the station address, and promiscuous mode. Unlike the ADMtek
48 * and KLSI chips, the CATC ASIC supports read and write combining
49 * mode where multiple packets can be transfered using a single bulk
50 * transaction, which helps performance a great deal.
53 #include <sys/param.h>
54 #include <sys/systm.h>
55 #include <sys/sockio.h>
57 #include <sys/malloc.h>
58 #include <sys/kernel.h>
59 #include <sys/socket.h>
62 #include <net/if_arp.h>
63 #include <net/ethernet.h>
64 #include <net/if_dl.h>
68 #include <machine/clock.h> /* for DELAY */
71 #include <dev/usb/usb.h>
72 #include <dev/usb/usbdi.h>
73 #include <dev/usb/usbdi_util.h>
74 #include <dev/usb/usbdivar.h>
75 #include <dev/usb/usbdevs.h>
76 #include <dev/usb/usb_ethersubr.h>
78 #include <dev/usb/if_cuereg.h>
81 static const char rcsid[] =
82 "$FreeBSD: src/sys/dev/usb/if_cue.c,v 1.7.2.6 2002/11/06 14:23:20 joe Exp $";
86 * Various supported device vendors/products.
88 Static struct cue_type cue_devs[] = {
89 { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE },
90 { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE2 },
91 { USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTLINK },
95 Static struct usb_qdat cue_qdat;
97 Static int cue_match(device_t);
98 Static int cue_attach(device_t);
99 Static int cue_detach(device_t);
101 Static int cue_tx_list_init(struct cue_softc *);
102 Static int cue_rx_list_init(struct cue_softc *);
103 Static int cue_newbuf(struct cue_softc *, struct cue_chain *, struct mbuf *);
104 Static int cue_encap(struct cue_softc *, struct mbuf *, int);
105 Static void cue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
106 Static void cue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
107 Static void cue_tick(void *);
108 Static void cue_rxstart(struct ifnet *);
109 Static void cue_start(struct ifnet *);
110 Static int cue_ioctl(struct ifnet *, u_long, caddr_t);
111 Static void cue_init(void *);
112 Static void cue_stop(struct cue_softc *);
113 Static void cue_watchdog(struct ifnet *);
114 Static void cue_shutdown(device_t);
116 Static void cue_setmulti(struct cue_softc *);
117 Static u_int32_t cue_crc(caddr_t);
118 Static void cue_reset(struct cue_softc *);
120 Static int csr_read_1(struct cue_softc *, int);
121 Static int csr_write_1(struct cue_softc *, int, int);
122 Static int csr_read_2(struct cue_softc *, int);
124 Static int csr_write_2(struct cue_softc *, int, int);
126 Static int cue_mem(struct cue_softc *, int, int, void *, int);
127 Static int cue_getmac(struct cue_softc *, void *);
129 Static device_method_t cue_methods[] = {
130 /* Device interface */
131 DEVMETHOD(device_probe, cue_match),
132 DEVMETHOD(device_attach, cue_attach),
133 DEVMETHOD(device_detach, cue_detach),
134 DEVMETHOD(device_shutdown, cue_shutdown),
139 Static driver_t cue_driver = {
142 sizeof(struct cue_softc)
145 Static devclass_t cue_devclass;
147 DRIVER_MODULE(if_cue, uhub, cue_driver, cue_devclass, usbd_driver_load, 0);
149 #define CUE_SETBIT(sc, reg, x) \
150 csr_write_1(sc, reg, csr_read_1(sc, reg) | (x))
152 #define CUE_CLRBIT(sc, reg, x) \
153 csr_write_1(sc, reg, csr_read_1(sc, reg) & ~(x))
156 csr_read_1(struct cue_softc *sc, int reg)
158 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_flags(sc->cue_udev,
175 &req, &val, USBD_NO_TSLEEP, NULL);
186 csr_read_2(struct cue_softc *sc, int reg)
188 usb_device_request_t req;
198 req.bmRequestType = UT_READ_VENDOR_DEVICE;
199 req.bRequest = CUE_CMD_READREG;
200 USETW(req.wValue, 0);
201 USETW(req.wIndex, reg);
202 USETW(req.wLength, 2);
204 err = usbd_do_request_flags(sc->cue_udev,
205 &req, &val, USBD_NO_TSLEEP, NULL);
216 csr_write_1(struct cue_softc *sc, int reg, int val)
218 usb_device_request_t req;
227 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
228 req.bRequest = CUE_CMD_WRITEREG;
229 USETW(req.wValue, val);
230 USETW(req.wIndex, reg);
231 USETW(req.wLength, 0);
233 err = usbd_do_request_flags(sc->cue_udev,
234 &req, &val, USBD_NO_TSLEEP, NULL);
246 csr_write_2(struct cue_softc *sc, int reg, int val)
248 usb_device_request_t req;
257 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
258 req.bRequest = CUE_CMD_WRITEREG;
259 USETW(req.wValue, val);
260 USETW(req.wIndex, reg);
261 USETW(req.wLength, 0);
263 err = usbd_do_request_flags(sc->cue_udev,
264 &req, &val, USBD_NO_TSLEEP, NULL);
276 cue_mem(struct cue_softc *sc, int cmd, int addr, void *buf, int len)
278 usb_device_request_t req;
287 if (cmd == CUE_CMD_READSRAM)
288 req.bmRequestType = UT_READ_VENDOR_DEVICE;
290 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
292 USETW(req.wValue, 0);
293 USETW(req.wIndex, addr);
294 USETW(req.wLength, len);
296 err = usbd_do_request_flags(sc->cue_udev,
297 &req, &buf, USBD_NO_TSLEEP, NULL);
308 cue_getmac(struct cue_softc *sc, void *buf)
310 usb_device_request_t req;
319 req.bmRequestType = UT_READ_VENDOR_DEVICE;
320 req.bRequest = CUE_CMD_GET_MACADDR;
321 USETW(req.wValue, 0);
322 USETW(req.wIndex, 0);
323 USETW(req.wLength, ETHER_ADDR_LEN);
325 err = usbd_do_request_flags(sc->cue_udev,
326 &req, buf, USBD_NO_TSLEEP, NULL);
331 printf("cue%d: read MAC address failed\n", sc->cue_unit);
338 #define CUE_POLY 0xEDB88320
342 cue_crc(caddr_t addr)
344 u_int32_t idx, bit, data, crc;
346 /* Compute CRC for the address value. */
347 crc = 0xFFFFFFFF; /* initial value */
349 for (idx = 0; idx < 6; idx++) {
350 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
351 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? CUE_POLY : 0);
354 return (crc & ((1 << CUE_BITS) - 1));
358 cue_setmulti(struct cue_softc *sc)
361 struct ifmultiaddr *ifma;
364 ifp = &sc->arpcom.ac_if;
366 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
367 for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
368 sc->cue_mctab[i] = 0xFF;
369 cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
370 &sc->cue_mctab, CUE_MCAST_TABLE_LEN);
374 /* first, zot all the existing hash bits */
375 for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
376 sc->cue_mctab[i] = 0;
378 /* now program new ones */
379 for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL;
380 ifma = ifma->ifma_link.le_next) {
381 if (ifma->ifma_addr->sa_family != AF_LINK)
383 h = cue_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
384 sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
388 * Also include the broadcast address in the filter
389 * so we can receive broadcast frames.
391 if (ifp->if_flags & IFF_BROADCAST) {
392 h = cue_crc(etherbroadcastaddr);
393 sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
396 cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
397 &sc->cue_mctab, CUE_MCAST_TABLE_LEN);
403 cue_reset(struct cue_softc *sc)
405 usb_device_request_t req;
414 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
415 req.bRequest = CUE_CMD_RESET;
416 USETW(req.wValue, 0);
417 USETW(req.wIndex, 0);
418 USETW(req.wLength, 0);
419 err = usbd_do_request_flags(sc->cue_udev,
420 &req, NULL, USBD_NO_TSLEEP, NULL);
425 printf("cue%d: reset failed\n", sc->cue_unit);
427 /* Wait a little while for the chip to get its brains in order. */
433 * Probe for a Pegasus chip.
437 USB_MATCH_START(cue, uaa);
445 if (uaa->vendor == t->cue_vid &&
446 uaa->product == t->cue_did) {
447 return(UMATCH_VENDOR_PRODUCT);
456 * Attach the interface. Allocate softc structures, do ifmedia
457 * setup and ethernet/BPF attach.
461 USB_ATTACH_START(cue, sc, uaa);
464 u_char eaddr[ETHER_ADDR_LEN];
466 usb_interface_descriptor_t *id;
467 usb_endpoint_descriptor_t *ed;
472 bzero(sc, sizeof(struct cue_softc));
473 sc->cue_iface = uaa->iface;
474 sc->cue_udev = uaa->device;
475 sc->cue_unit = device_get_unit(self);
477 if (usbd_set_config_no(sc->cue_udev, CUE_CONFIG_NO, 0)) {
478 printf("cue%d: getting interface handle failed\n",
481 USB_ATTACH_ERROR_RETURN;
484 id = usbd_get_interface_descriptor(uaa->iface);
486 usbd_devinfo(uaa->device, 0, devinfo);
487 device_set_desc_copy(self, devinfo);
488 printf("%s: %s\n", USBDEVNAME(self), devinfo);
490 /* Find endpoints. */
491 for (i = 0; i < id->bNumEndpoints; i++) {
492 ed = usbd_interface2endpoint_descriptor(uaa->iface, i);
494 printf("cue%d: couldn't get ep %d\n",
497 USB_ATTACH_ERROR_RETURN;
499 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
500 (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
501 sc->cue_ed[CUE_ENDPT_RX] = ed->bEndpointAddress;
502 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
503 (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
504 sc->cue_ed[CUE_ENDPT_TX] = ed->bEndpointAddress;
505 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
506 (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
507 sc->cue_ed[CUE_ENDPT_INTR] = ed->bEndpointAddress;
512 /* Reset the adapter. */
516 * Get station address.
518 cue_getmac(sc, &eaddr);
521 * A CATC chip was detected. Inform the world.
523 printf("cue%d: Ethernet address: %6D\n", sc->cue_unit, eaddr, ":");
525 bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
527 ifp = &sc->arpcom.ac_if;
529 ifp->if_unit = sc->cue_unit;
530 ifp->if_name = "cue";
531 ifp->if_mtu = ETHERMTU;
532 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
533 ifp->if_ioctl = cue_ioctl;
534 ifp->if_output = ether_output;
535 ifp->if_start = cue_start;
536 ifp->if_watchdog = cue_watchdog;
537 ifp->if_init = cue_init;
538 ifp->if_baudrate = 10000000;
539 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
542 cue_qdat.if_rxstart = cue_rxstart;
545 * Call MI attach routine.
547 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
548 callout_handle_init(&sc->cue_stat_ch);
549 usb_register_netisr();
553 USB_ATTACH_SUCCESS_RETURN;
557 cue_detach(device_ptr_t dev)
559 struct cue_softc *sc;
565 sc = device_get_softc(dev);
566 ifp = &sc->arpcom.ac_if;
569 untimeout(cue_tick, sc, sc->cue_stat_ch);
570 ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
572 if (sc->cue_ep[CUE_ENDPT_TX] != NULL)
573 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
574 if (sc->cue_ep[CUE_ENDPT_RX] != NULL)
575 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
576 if (sc->cue_ep[CUE_ENDPT_INTR] != NULL)
577 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
585 * Initialize an RX descriptor and attach an MBUF cluster.
588 cue_newbuf(struct cue_softc *sc, struct cue_chain *c, struct mbuf *m)
590 struct mbuf *m_new = NULL;
593 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
595 printf("cue%d: no memory for rx list "
596 "-- packet dropped!\n", sc->cue_unit);
600 MCLGET(m_new, M_DONTWAIT);
601 if (!(m_new->m_flags & M_EXT)) {
602 printf("cue%d: no memory for rx list "
603 "-- packet dropped!\n", sc->cue_unit);
607 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
610 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
611 m_new->m_data = m_new->m_ext.ext_buf;
614 m_adj(m_new, ETHER_ALIGN);
621 cue_rx_list_init(struct cue_softc *sc)
623 struct cue_cdata *cd;
628 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
629 c = &cd->cue_rx_chain[i];
632 if (cue_newbuf(sc, c, NULL) == ENOBUFS)
634 if (c->cue_xfer == NULL) {
635 c->cue_xfer = usbd_alloc_xfer(sc->cue_udev);
636 if (c->cue_xfer == NULL)
645 cue_tx_list_init(struct cue_softc *sc)
647 struct cue_cdata *cd;
652 for (i = 0; i < CUE_TX_LIST_CNT; i++) {
653 c = &cd->cue_tx_chain[i];
657 if (c->cue_xfer == NULL) {
658 c->cue_xfer = usbd_alloc_xfer(sc->cue_udev);
659 if (c->cue_xfer == NULL)
662 c->cue_buf = malloc(CUE_BUFSZ, M_USBDEV, M_NOWAIT);
663 if (c->cue_buf == NULL)
671 cue_rxstart(struct ifnet *ifp)
673 struct cue_softc *sc;
677 c = &sc->cue_cdata.cue_rx_chain[sc->cue_cdata.cue_rx_prod];
679 if (cue_newbuf(sc, c, NULL) == ENOBUFS) {
684 /* Setup new transfer. */
685 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
686 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ, USBD_SHORT_XFER_OK,
687 USBD_NO_TIMEOUT, cue_rxeof);
688 usbd_transfer(c->cue_xfer);
694 * A frame has been uploaded: pass the resulting mbuf chain up to
695 * the higher level protocols.
698 cue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
700 struct cue_softc *sc;
709 ifp = &sc->arpcom.ac_if;
711 if (!(ifp->if_flags & IFF_RUNNING))
714 if (status != USBD_NORMAL_COMPLETION) {
715 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
717 printf("cue%d: usb error on rx: %s\n", sc->cue_unit,
718 usbd_errstr(status));
719 if (status == USBD_STALLED)
720 usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_RX]);
724 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
727 len = *mtod(m, u_int16_t *);
729 /* No errors; receive the packet. */
732 if (len < sizeof(struct ether_header)) {
738 m_adj(m, sizeof(u_int16_t));
739 m->m_pkthdr.rcvif = (struct ifnet *)&cue_qdat;
740 m->m_pkthdr.len = m->m_len = total_len;
742 /* Put the packet on the special USB input queue. */
747 /* Setup new transfer. */
748 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
749 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ, USBD_SHORT_XFER_OK,
750 USBD_NO_TIMEOUT, cue_rxeof);
751 usbd_transfer(c->cue_xfer);
757 * A frame was downloaded to the chip. It's safe for us to clean up
762 cue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
764 struct cue_softc *sc;
774 ifp = &sc->arpcom.ac_if;
776 if (status != USBD_NORMAL_COMPLETION) {
777 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
781 printf("cue%d: usb error on tx: %s\n", sc->cue_unit,
782 usbd_errstr(status));
783 if (status == USBD_STALLED)
784 usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_TX]);
790 ifp->if_flags &= ~IFF_OACTIVE;
791 usbd_get_xfer_status(c->cue_xfer, NULL, NULL, NULL, &err);
793 if (c->cue_mbuf != NULL) {
794 c->cue_mbuf->m_pkthdr.rcvif = ifp;
795 usb_tx_done(c->cue_mbuf);
812 struct cue_softc *sc;
825 ifp = &sc->arpcom.ac_if;
827 ifp->if_collisions += csr_read_2(sc, CUE_TX_SINGLECOLL);
828 ifp->if_collisions += csr_read_2(sc, CUE_TX_MULTICOLL);
829 ifp->if_collisions += csr_read_2(sc, CUE_TX_EXCESSCOLL);
831 if (csr_read_2(sc, CUE_RX_FRAMEERR))
834 sc->cue_stat_ch = timeout(cue_tick, sc, hz);
842 cue_encap(struct cue_softc *sc, struct mbuf *m, int idx)
848 c = &sc->cue_cdata.cue_tx_chain[idx];
851 * Copy the mbuf data into a contiguous buffer, leaving two
852 * bytes at the beginning to hold the frame length.
854 m_copydata(m, 0, m->m_pkthdr.len, c->cue_buf + 2);
857 total_len = m->m_pkthdr.len + 2;
859 /* The first two bytes are the frame length */
860 c->cue_buf[0] = (u_int8_t)m->m_pkthdr.len;
861 c->cue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
863 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_TX],
864 c, c->cue_buf, total_len, 0, 10000, cue_txeof);
867 err = usbd_transfer(c->cue_xfer);
868 if (err != USBD_IN_PROGRESS) {
873 sc->cue_cdata.cue_tx_cnt++;
879 cue_start(struct ifnet *ifp)
881 struct cue_softc *sc;
882 struct mbuf *m_head = NULL;
886 if (ifp->if_flags & IFF_OACTIVE)
889 IF_DEQUEUE(&ifp->if_snd, m_head);
893 if (cue_encap(sc, m_head, 0)) {
894 IF_PREPEND(&ifp->if_snd, m_head);
895 ifp->if_flags |= IFF_OACTIVE;
900 * If there's a BPF listener, bounce a copy of this frame
904 bpf_mtap(ifp, m_head);
906 ifp->if_flags |= IFF_OACTIVE;
909 * Set a timeout in case the chip goes out to lunch.
919 struct cue_softc *sc = xsc;
920 struct ifnet *ifp = &sc->arpcom.ac_if;
925 if (ifp->if_flags & IFF_RUNNING)
931 * Cancel pending I/O and free all RX/TX buffers.
937 /* Set MAC address */
938 for (i = 0; i < ETHER_ADDR_LEN; i++)
939 csr_write_1(sc, CUE_PAR0 - i, sc->arpcom.ac_enaddr[i]);
941 /* Enable RX logic. */
942 csr_write_1(sc, CUE_ETHCTL, CUE_ETHCTL_RX_ON|CUE_ETHCTL_MCAST_ON);
944 /* If we want promiscuous mode, set the allframes bit. */
945 if (ifp->if_flags & IFF_PROMISC) {
946 CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
948 CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
952 if (cue_tx_list_init(sc) == ENOBUFS) {
953 printf("cue%d: tx list init failed\n", sc->cue_unit);
959 if (cue_rx_list_init(sc) == ENOBUFS) {
960 printf("cue%d: rx list init failed\n", sc->cue_unit);
965 /* Load the multicast filter. */
969 * Set the number of RX and TX buffers that we want
970 * to reserve inside the ASIC.
972 csr_write_1(sc, CUE_RX_BUFPKTS, CUE_RX_FRAMES);
973 csr_write_1(sc, CUE_TX_BUFPKTS, CUE_TX_FRAMES);
975 /* Set advanced operation modes. */
976 csr_write_1(sc, CUE_ADVANCED_OPMODES,
977 CUE_AOP_EMBED_RXLEN|0x01); /* 1 wait state */
979 /* Program the LED operation. */
980 csr_write_1(sc, CUE_LEDCTL, CUE_LEDCTL_FOLLOW_LINK);
982 /* Open RX and TX pipes. */
983 err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_RX],
984 USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_RX]);
986 printf("cue%d: open rx pipe failed: %s\n",
987 sc->cue_unit, usbd_errstr(err));
991 err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_TX],
992 USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_TX]);
994 printf("cue%d: open tx pipe failed: %s\n",
995 sc->cue_unit, usbd_errstr(err));
1000 /* Start up the receive pipe. */
1001 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
1002 c = &sc->cue_cdata.cue_rx_chain[i];
1003 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
1004 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ,
1005 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, cue_rxeof);
1006 usbd_transfer(c->cue_xfer);
1009 ifp->if_flags |= IFF_RUNNING;
1010 ifp->if_flags &= ~IFF_OACTIVE;
1014 sc->cue_stat_ch = timeout(cue_tick, sc, hz);
1020 cue_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
1022 struct cue_softc *sc = ifp->if_softc;
1031 error = ether_ioctl(ifp, command, data);
1034 if (ifp->if_flags & IFF_UP) {
1035 if (ifp->if_flags & IFF_RUNNING &&
1036 ifp->if_flags & IFF_PROMISC &&
1037 !(sc->cue_if_flags & IFF_PROMISC)) {
1038 CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
1040 } else if (ifp->if_flags & IFF_RUNNING &&
1041 !(ifp->if_flags & IFF_PROMISC) &&
1042 sc->cue_if_flags & IFF_PROMISC) {
1043 CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
1045 } else if (!(ifp->if_flags & IFF_RUNNING))
1048 if (ifp->if_flags & IFF_RUNNING)
1051 sc->cue_if_flags = ifp->if_flags;
1070 cue_watchdog(struct ifnet *ifp)
1072 struct cue_softc *sc;
1073 struct cue_chain *c;
1079 printf("cue%d: watchdog timeout\n", sc->cue_unit);
1081 c = &sc->cue_cdata.cue_tx_chain[0];
1082 usbd_get_xfer_status(c->cue_xfer, NULL, NULL, NULL, &stat);
1083 cue_txeof(c->cue_xfer, c, stat);
1085 if (ifp->if_snd.ifq_head != NULL)
1092 * Stop the adapter and free any mbufs allocated to the
1096 cue_stop(struct cue_softc *sc)
1102 ifp = &sc->arpcom.ac_if;
1105 csr_write_1(sc, CUE_ETHCTL, 0);
1107 untimeout(cue_tick, sc, sc->cue_stat_ch);
1109 /* Stop transfers. */
1110 if (sc->cue_ep[CUE_ENDPT_RX] != NULL) {
1111 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
1113 printf("cue%d: abort rx pipe failed: %s\n",
1114 sc->cue_unit, usbd_errstr(err));
1116 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_RX]);
1118 printf("cue%d: close rx pipe failed: %s\n",
1119 sc->cue_unit, usbd_errstr(err));
1121 sc->cue_ep[CUE_ENDPT_RX] = NULL;
1124 if (sc->cue_ep[CUE_ENDPT_TX] != NULL) {
1125 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
1127 printf("cue%d: abort tx pipe failed: %s\n",
1128 sc->cue_unit, usbd_errstr(err));
1130 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_TX]);
1132 printf("cue%d: close tx pipe failed: %s\n",
1133 sc->cue_unit, usbd_errstr(err));
1135 sc->cue_ep[CUE_ENDPT_TX] = NULL;
1138 if (sc->cue_ep[CUE_ENDPT_INTR] != NULL) {
1139 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
1141 printf("cue%d: abort intr pipe failed: %s\n",
1142 sc->cue_unit, usbd_errstr(err));
1144 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
1146 printf("cue%d: close intr pipe failed: %s\n",
1147 sc->cue_unit, usbd_errstr(err));
1149 sc->cue_ep[CUE_ENDPT_INTR] = NULL;
1152 /* Free RX resources. */
1153 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
1154 if (sc->cue_cdata.cue_rx_chain[i].cue_buf != NULL) {
1155 free(sc->cue_cdata.cue_rx_chain[i].cue_buf, M_USBDEV);
1156 sc->cue_cdata.cue_rx_chain[i].cue_buf = NULL;
1158 if (sc->cue_cdata.cue_rx_chain[i].cue_mbuf != NULL) {
1159 m_freem(sc->cue_cdata.cue_rx_chain[i].cue_mbuf);
1160 sc->cue_cdata.cue_rx_chain[i].cue_mbuf = NULL;
1162 if (sc->cue_cdata.cue_rx_chain[i].cue_xfer != NULL) {
1163 usbd_free_xfer(sc->cue_cdata.cue_rx_chain[i].cue_xfer);
1164 sc->cue_cdata.cue_rx_chain[i].cue_xfer = NULL;
1168 /* Free TX resources. */
1169 for (i = 0; i < CUE_TX_LIST_CNT; i++) {
1170 if (sc->cue_cdata.cue_tx_chain[i].cue_buf != NULL) {
1171 free(sc->cue_cdata.cue_tx_chain[i].cue_buf, M_USBDEV);
1172 sc->cue_cdata.cue_tx_chain[i].cue_buf = NULL;
1174 if (sc->cue_cdata.cue_tx_chain[i].cue_mbuf != NULL) {
1175 m_freem(sc->cue_cdata.cue_tx_chain[i].cue_mbuf);
1176 sc->cue_cdata.cue_tx_chain[i].cue_mbuf = NULL;
1178 if (sc->cue_cdata.cue_tx_chain[i].cue_xfer != NULL) {
1179 usbd_free_xfer(sc->cue_cdata.cue_tx_chain[i].cue_xfer);
1180 sc->cue_cdata.cue_tx_chain[i].cue_xfer = NULL;
1184 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1190 * Stop all chip I/O so that the kernel's probe routines don't
1191 * get confused by errant DMAs when rebooting.
1194 cue_shutdown(device_ptr_t dev)
1196 struct cue_softc *sc;
1198 sc = device_get_softc(dev);