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.
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[] =
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 __P((device_t));
98 Static int cue_attach __P((device_t));
99 Static int cue_detach __P((device_t));
101 Static int cue_tx_list_init __P((struct cue_softc *));
102 Static int cue_rx_list_init __P((struct cue_softc *));
103 Static int cue_newbuf __P((struct cue_softc *, struct cue_chain *,
105 Static int cue_encap __P((struct cue_softc *, struct mbuf *, int));
106 Static void cue_rxeof __P((usbd_xfer_handle,
107 usbd_private_handle, usbd_status));
108 Static void cue_txeof __P((usbd_xfer_handle,
109 usbd_private_handle, usbd_status));
110 Static void cue_tick __P((void *));
111 Static void cue_rxstart __P((struct ifnet *));
112 Static void cue_start __P((struct ifnet *));
113 Static int cue_ioctl __P((struct ifnet *, u_long, caddr_t));
114 Static void cue_init __P((void *));
115 Static void cue_stop __P((struct cue_softc *));
116 Static void cue_watchdog __P((struct ifnet *));
117 Static void cue_shutdown __P((device_t));
119 Static void cue_setmulti __P((struct cue_softc *));
120 Static u_int32_t cue_crc __P((caddr_t));
121 Static void cue_reset __P((struct cue_softc *));
123 Static int csr_read_1 __P((struct cue_softc *, int));
124 Static int csr_write_1 __P((struct cue_softc *, int, int));
125 Static int csr_read_2 __P((struct cue_softc *, int));
127 Static int csr_write_2 __P((struct cue_softc *, int, int));
129 Static int cue_mem __P((struct cue_softc *, int,
131 Static int cue_getmac __P((struct cue_softc *, void *));
133 Static device_method_t cue_methods[] = {
134 /* Device interface */
135 DEVMETHOD(device_probe, cue_match),
136 DEVMETHOD(device_attach, cue_attach),
137 DEVMETHOD(device_detach, cue_detach),
138 DEVMETHOD(device_shutdown, cue_shutdown),
143 Static driver_t cue_driver = {
146 sizeof(struct cue_softc)
149 Static devclass_t cue_devclass;
151 DRIVER_MODULE(if_cue, uhub, cue_driver, cue_devclass, usbd_driver_load, 0);
153 #define CUE_SETBIT(sc, reg, x) \
154 csr_write_1(sc, reg, csr_read_1(sc, reg) | (x))
156 #define CUE_CLRBIT(sc, reg, x) \
157 csr_write_1(sc, reg, csr_read_1(sc, reg) & ~(x))
159 Static int csr_read_1(sc, reg)
160 struct cue_softc *sc;
163 usb_device_request_t req;
173 req.bmRequestType = UT_READ_VENDOR_DEVICE;
174 req.bRequest = CUE_CMD_READREG;
175 USETW(req.wValue, 0);
176 USETW(req.wIndex, reg);
177 USETW(req.wLength, 1);
179 err = usbd_do_request_flags(sc->cue_udev,
180 &req, &val, USBD_NO_TSLEEP, NULL);
190 Static int csr_read_2(sc, reg)
191 struct cue_softc *sc;
194 usb_device_request_t req;
204 req.bmRequestType = UT_READ_VENDOR_DEVICE;
205 req.bRequest = CUE_CMD_READREG;
206 USETW(req.wValue, 0);
207 USETW(req.wIndex, reg);
208 USETW(req.wLength, 2);
210 err = usbd_do_request_flags(sc->cue_udev,
211 &req, &val, USBD_NO_TSLEEP, NULL);
221 Static int csr_write_1(sc, reg, val)
222 struct cue_softc *sc;
225 usb_device_request_t req;
234 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
235 req.bRequest = CUE_CMD_WRITEREG;
236 USETW(req.wValue, val);
237 USETW(req.wIndex, reg);
238 USETW(req.wLength, 0);
240 err = usbd_do_request_flags(sc->cue_udev,
241 &req, &val, USBD_NO_TSLEEP, NULL);
252 Static int csr_write_2(sc, reg, val)
253 struct cue_softc *sc;
256 usb_device_request_t req;
265 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
266 req.bRequest = CUE_CMD_WRITEREG;
267 USETW(req.wValue, val);
268 USETW(req.wIndex, reg);
269 USETW(req.wLength, 0);
271 err = usbd_do_request_flags(sc->cue_udev,
272 &req, &val, USBD_NO_TSLEEP, NULL);
283 Static int cue_mem(sc, cmd, addr, buf, len)
284 struct cue_softc *sc;
290 usb_device_request_t req;
299 if (cmd == CUE_CMD_READSRAM)
300 req.bmRequestType = UT_READ_VENDOR_DEVICE;
302 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
304 USETW(req.wValue, 0);
305 USETW(req.wIndex, addr);
306 USETW(req.wLength, len);
308 err = usbd_do_request_flags(sc->cue_udev,
309 &req, &buf, USBD_NO_TSLEEP, NULL);
319 Static int cue_getmac(sc, buf)
320 struct cue_softc *sc;
323 usb_device_request_t req;
332 req.bmRequestType = UT_READ_VENDOR_DEVICE;
333 req.bRequest = CUE_CMD_GET_MACADDR;
334 USETW(req.wValue, 0);
335 USETW(req.wIndex, 0);
336 USETW(req.wLength, ETHER_ADDR_LEN);
338 err = usbd_do_request_flags(sc->cue_udev,
339 &req, buf, USBD_NO_TSLEEP, NULL);
344 printf("cue%d: read MAC address failed\n", sc->cue_unit);
351 #define CUE_POLY 0xEDB88320
354 Static u_int32_t cue_crc(addr)
357 u_int32_t idx, bit, data, crc;
359 /* Compute CRC for the address value. */
360 crc = 0xFFFFFFFF; /* initial value */
362 for (idx = 0; idx < 6; idx++) {
363 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
364 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? CUE_POLY : 0);
367 return (crc & ((1 << CUE_BITS) - 1));
370 Static void cue_setmulti(sc)
371 struct cue_softc *sc;
374 struct ifmultiaddr *ifma;
377 ifp = &sc->arpcom.ac_if;
379 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
380 for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
381 sc->cue_mctab[i] = 0xFF;
382 cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
383 &sc->cue_mctab, CUE_MCAST_TABLE_LEN);
387 /* first, zot all the existing hash bits */
388 for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
389 sc->cue_mctab[i] = 0;
391 /* now program new ones */
392 for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL;
393 ifma = ifma->ifma_link.le_next) {
394 if (ifma->ifma_addr->sa_family != AF_LINK)
396 h = cue_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
397 sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
401 * Also include the broadcast address in the filter
402 * so we can receive broadcast frames.
404 if (ifp->if_flags & IFF_BROADCAST) {
405 h = cue_crc(etherbroadcastaddr);
406 sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
409 cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
410 &sc->cue_mctab, CUE_MCAST_TABLE_LEN);
415 Static void cue_reset(sc)
416 struct cue_softc *sc;
418 usb_device_request_t req;
427 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
428 req.bRequest = CUE_CMD_RESET;
429 USETW(req.wValue, 0);
430 USETW(req.wIndex, 0);
431 USETW(req.wLength, 0);
432 err = usbd_do_request_flags(sc->cue_udev,
433 &req, NULL, USBD_NO_TSLEEP, NULL);
438 printf("cue%d: reset failed\n", sc->cue_unit);
440 /* Wait a little while for the chip to get its brains in order. */
446 * Probe for a Pegasus chip.
450 USB_MATCH_START(cue, uaa);
458 if (uaa->vendor == t->cue_vid &&
459 uaa->product == t->cue_did) {
460 return(UMATCH_VENDOR_PRODUCT);
469 * Attach the interface. Allocate softc structures, do ifmedia
470 * setup and ethernet/BPF attach.
474 USB_ATTACH_START(cue, sc, uaa);
477 u_char eaddr[ETHER_ADDR_LEN];
479 usb_interface_descriptor_t *id;
480 usb_endpoint_descriptor_t *ed;
485 bzero(sc, sizeof(struct cue_softc));
486 sc->cue_iface = uaa->iface;
487 sc->cue_udev = uaa->device;
488 sc->cue_unit = device_get_unit(self);
490 if (usbd_set_config_no(sc->cue_udev, CUE_CONFIG_NO, 0)) {
491 printf("cue%d: getting interface handle failed\n",
494 USB_ATTACH_ERROR_RETURN;
497 id = usbd_get_interface_descriptor(uaa->iface);
499 usbd_devinfo(uaa->device, 0, devinfo);
500 device_set_desc_copy(self, devinfo);
501 printf("%s: %s\n", USBDEVNAME(self), devinfo);
503 /* Find endpoints. */
504 for (i = 0; i < id->bNumEndpoints; i++) {
505 ed = usbd_interface2endpoint_descriptor(uaa->iface, i);
507 printf("cue%d: couldn't get ep %d\n",
510 USB_ATTACH_ERROR_RETURN;
512 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
513 (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
514 sc->cue_ed[CUE_ENDPT_RX] = ed->bEndpointAddress;
515 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
516 (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
517 sc->cue_ed[CUE_ENDPT_TX] = ed->bEndpointAddress;
518 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
519 (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
520 sc->cue_ed[CUE_ENDPT_INTR] = ed->bEndpointAddress;
525 /* Reset the adapter. */
529 * Get station address.
531 cue_getmac(sc, &eaddr);
534 * A CATC chip was detected. Inform the world.
536 printf("cue%d: Ethernet address: %6D\n", sc->cue_unit, eaddr, ":");
538 bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
540 ifp = &sc->arpcom.ac_if;
542 ifp->if_unit = sc->cue_unit;
543 ifp->if_name = "cue";
544 ifp->if_mtu = ETHERMTU;
545 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
546 ifp->if_ioctl = cue_ioctl;
547 ifp->if_output = ether_output;
548 ifp->if_start = cue_start;
549 ifp->if_watchdog = cue_watchdog;
550 ifp->if_init = cue_init;
551 ifp->if_baudrate = 10000000;
552 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
555 cue_qdat.if_rxstart = cue_rxstart;
558 * Call MI attach routines.
562 callout_handle_init(&sc->cue_stat_ch);
563 bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header));
564 usb_register_netisr();
568 USB_ATTACH_SUCCESS_RETURN;
571 Static int cue_detach(dev)
574 struct cue_softc *sc;
580 sc = device_get_softc(dev);
581 ifp = &sc->arpcom.ac_if;
584 untimeout(cue_tick, sc, sc->cue_stat_ch);
588 if (sc->cue_ep[CUE_ENDPT_TX] != NULL)
589 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
590 if (sc->cue_ep[CUE_ENDPT_RX] != NULL)
591 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
592 if (sc->cue_ep[CUE_ENDPT_INTR] != NULL)
593 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
601 * Initialize an RX descriptor and attach an MBUF cluster.
603 Static int cue_newbuf(sc, c, m)
604 struct cue_softc *sc;
608 struct mbuf *m_new = NULL;
611 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
613 printf("cue%d: no memory for rx list "
614 "-- packet dropped!\n", sc->cue_unit);
618 MCLGET(m_new, M_DONTWAIT);
619 if (!(m_new->m_flags & M_EXT)) {
620 printf("cue%d: no memory for rx list "
621 "-- packet dropped!\n", sc->cue_unit);
625 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
628 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
629 m_new->m_data = m_new->m_ext.ext_buf;
632 m_adj(m_new, ETHER_ALIGN);
638 Static int cue_rx_list_init(sc)
639 struct cue_softc *sc;
641 struct cue_cdata *cd;
646 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
647 c = &cd->cue_rx_chain[i];
650 if (cue_newbuf(sc, c, NULL) == ENOBUFS)
652 if (c->cue_xfer == NULL) {
653 c->cue_xfer = usbd_alloc_xfer(sc->cue_udev);
654 if (c->cue_xfer == NULL)
662 Static int cue_tx_list_init(sc)
663 struct cue_softc *sc;
665 struct cue_cdata *cd;
670 for (i = 0; i < CUE_TX_LIST_CNT; i++) {
671 c = &cd->cue_tx_chain[i];
675 if (c->cue_xfer == NULL) {
676 c->cue_xfer = usbd_alloc_xfer(sc->cue_udev);
677 if (c->cue_xfer == NULL)
680 c->cue_buf = malloc(CUE_BUFSZ, M_USBDEV, M_NOWAIT);
681 if (c->cue_buf == NULL)
688 Static void cue_rxstart(ifp)
691 struct cue_softc *sc;
695 c = &sc->cue_cdata.cue_rx_chain[sc->cue_cdata.cue_rx_prod];
697 if (cue_newbuf(sc, c, NULL) == ENOBUFS) {
702 /* Setup new transfer. */
703 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
704 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ, USBD_SHORT_XFER_OK,
705 USBD_NO_TIMEOUT, cue_rxeof);
706 usbd_transfer(c->cue_xfer);
712 * A frame has been uploaded: pass the resulting mbuf chain up to
713 * the higher level protocols.
715 Static void cue_rxeof(xfer, priv, status)
716 usbd_xfer_handle xfer;
717 usbd_private_handle priv;
720 struct cue_softc *sc;
729 ifp = &sc->arpcom.ac_if;
731 if (!(ifp->if_flags & IFF_RUNNING))
734 if (status != USBD_NORMAL_COMPLETION) {
735 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
737 printf("cue%d: usb error on rx: %s\n", sc->cue_unit,
738 usbd_errstr(status));
739 if (status == USBD_STALLED)
740 usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_RX]);
744 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
747 len = *mtod(m, u_int16_t *);
749 /* No errors; receive the packet. */
752 if (len < sizeof(struct ether_header)) {
758 m_adj(m, sizeof(u_int16_t));
759 m->m_pkthdr.rcvif = (struct ifnet *)&cue_qdat;
760 m->m_pkthdr.len = m->m_len = total_len;
762 /* Put the packet on the special USB input queue. */
767 /* Setup new transfer. */
768 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
769 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ, USBD_SHORT_XFER_OK,
770 USBD_NO_TIMEOUT, cue_rxeof);
771 usbd_transfer(c->cue_xfer);
777 * A frame was downloaded to the chip. It's safe for us to clean up
781 Static void cue_txeof(xfer, priv, status)
782 usbd_xfer_handle xfer;
783 usbd_private_handle priv;
786 struct cue_softc *sc;
796 ifp = &sc->arpcom.ac_if;
798 if (status != USBD_NORMAL_COMPLETION) {
799 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
803 printf("cue%d: usb error on tx: %s\n", sc->cue_unit,
804 usbd_errstr(status));
805 if (status == USBD_STALLED)
806 usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_TX]);
812 ifp->if_flags &= ~IFF_OACTIVE;
813 usbd_get_xfer_status(c->cue_xfer, NULL, NULL, NULL, &err);
815 c->cue_mbuf->m_pkthdr.rcvif = ifp;
816 usb_tx_done(c->cue_mbuf);
829 Static void cue_tick(xsc)
832 struct cue_softc *sc;
845 ifp = &sc->arpcom.ac_if;
847 ifp->if_collisions += csr_read_2(sc, CUE_TX_SINGLECOLL);
848 ifp->if_collisions += csr_read_2(sc, CUE_TX_MULTICOLL);
849 ifp->if_collisions += csr_read_2(sc, CUE_TX_EXCESSCOLL);
851 if (csr_read_2(sc, CUE_RX_FRAMEERR))
854 sc->cue_stat_ch = timeout(cue_tick, sc, hz);
861 Static int cue_encap(sc, m, idx)
862 struct cue_softc *sc;
870 c = &sc->cue_cdata.cue_tx_chain[idx];
873 * Copy the mbuf data into a contiguous buffer, leaving two
874 * bytes at the beginning to hold the frame length.
876 m_copydata(m, 0, m->m_pkthdr.len, c->cue_buf + 2);
879 total_len = m->m_pkthdr.len + 2;
881 /* The first two bytes are the frame length */
882 c->cue_buf[0] = (u_int8_t)m->m_pkthdr.len;
883 c->cue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
885 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_TX],
886 c, c->cue_buf, total_len, 0, 10000, cue_txeof);
889 err = usbd_transfer(c->cue_xfer);
890 if (err != USBD_IN_PROGRESS) {
895 sc->cue_cdata.cue_tx_cnt++;
900 Static void cue_start(ifp)
903 struct cue_softc *sc;
904 struct mbuf *m_head = NULL;
908 if (ifp->if_flags & IFF_OACTIVE)
911 IF_DEQUEUE(&ifp->if_snd, m_head);
915 if (cue_encap(sc, m_head, 0)) {
916 IF_PREPEND(&ifp->if_snd, m_head);
917 ifp->if_flags |= IFF_OACTIVE;
922 * If there's a BPF listener, bounce a copy of this frame
926 bpf_mtap(ifp, m_head);
928 ifp->if_flags |= IFF_OACTIVE;
931 * Set a timeout in case the chip goes out to lunch.
938 Static void cue_init(xsc)
941 struct cue_softc *sc = xsc;
942 struct ifnet *ifp = &sc->arpcom.ac_if;
947 if (ifp->if_flags & IFF_RUNNING)
953 * Cancel pending I/O and free all RX/TX buffers.
959 /* Set MAC address */
960 for (i = 0; i < ETHER_ADDR_LEN; i++)
961 csr_write_1(sc, CUE_PAR0 - i, sc->arpcom.ac_enaddr[i]);
963 /* Enable RX logic. */
964 csr_write_1(sc, CUE_ETHCTL, CUE_ETHCTL_RX_ON|CUE_ETHCTL_MCAST_ON);
966 /* If we want promiscuous mode, set the allframes bit. */
967 if (ifp->if_flags & IFF_PROMISC) {
968 CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
970 CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
974 if (cue_tx_list_init(sc) == ENOBUFS) {
975 printf("cue%d: tx list init failed\n", sc->cue_unit);
981 if (cue_rx_list_init(sc) == ENOBUFS) {
982 printf("cue%d: rx list init failed\n", sc->cue_unit);
987 /* Load the multicast filter. */
991 * Set the number of RX and TX buffers that we want
992 * to reserve inside the ASIC.
994 csr_write_1(sc, CUE_RX_BUFPKTS, CUE_RX_FRAMES);
995 csr_write_1(sc, CUE_TX_BUFPKTS, CUE_TX_FRAMES);
997 /* Set advanced operation modes. */
998 csr_write_1(sc, CUE_ADVANCED_OPMODES,
999 CUE_AOP_EMBED_RXLEN|0x01); /* 1 wait state */
1001 /* Program the LED operation. */
1002 csr_write_1(sc, CUE_LEDCTL, CUE_LEDCTL_FOLLOW_LINK);
1004 /* Open RX and TX pipes. */
1005 err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_RX],
1006 USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_RX]);
1008 printf("cue%d: open rx pipe failed: %s\n",
1009 sc->cue_unit, usbd_errstr(err));
1013 err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_TX],
1014 USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_TX]);
1016 printf("cue%d: open tx pipe failed: %s\n",
1017 sc->cue_unit, usbd_errstr(err));
1022 /* Start up the receive pipe. */
1023 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
1024 c = &sc->cue_cdata.cue_rx_chain[i];
1025 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
1026 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ,
1027 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, cue_rxeof);
1028 usbd_transfer(c->cue_xfer);
1031 ifp->if_flags |= IFF_RUNNING;
1032 ifp->if_flags &= ~IFF_OACTIVE;
1036 sc->cue_stat_ch = timeout(cue_tick, sc, hz);
1041 Static int cue_ioctl(ifp, command, data)
1046 struct cue_softc *sc = ifp->if_softc;
1055 error = ether_ioctl(ifp, command, data);
1058 if (ifp->if_flags & IFF_UP) {
1059 if (ifp->if_flags & IFF_RUNNING &&
1060 ifp->if_flags & IFF_PROMISC &&
1061 !(sc->cue_if_flags & IFF_PROMISC)) {
1062 CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
1064 } else if (ifp->if_flags & IFF_RUNNING &&
1065 !(ifp->if_flags & IFF_PROMISC) &&
1066 sc->cue_if_flags & IFF_PROMISC) {
1067 CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
1069 } else if (!(ifp->if_flags & IFF_RUNNING))
1072 if (ifp->if_flags & IFF_RUNNING)
1075 sc->cue_if_flags = ifp->if_flags;
1093 Static void cue_watchdog(ifp)
1096 struct cue_softc *sc;
1101 printf("cue%d: watchdog timeout\n", sc->cue_unit);
1105 if (ifp->if_snd.ifq_head != NULL)
1112 * Stop the adapter and free any mbufs allocated to the
1115 Static void cue_stop(sc)
1116 struct cue_softc *sc;
1122 ifp = &sc->arpcom.ac_if;
1125 csr_write_1(sc, CUE_ETHCTL, 0);
1127 untimeout(cue_tick, sc, sc->cue_stat_ch);
1129 /* Stop transfers. */
1130 if (sc->cue_ep[CUE_ENDPT_RX] != NULL) {
1131 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
1133 printf("cue%d: abort rx pipe failed: %s\n",
1134 sc->cue_unit, usbd_errstr(err));
1136 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_RX]);
1138 printf("cue%d: close rx pipe failed: %s\n",
1139 sc->cue_unit, usbd_errstr(err));
1141 sc->cue_ep[CUE_ENDPT_RX] = NULL;
1144 if (sc->cue_ep[CUE_ENDPT_TX] != NULL) {
1145 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
1147 printf("cue%d: abort tx pipe failed: %s\n",
1148 sc->cue_unit, usbd_errstr(err));
1150 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_TX]);
1152 printf("cue%d: close tx pipe failed: %s\n",
1153 sc->cue_unit, usbd_errstr(err));
1155 sc->cue_ep[CUE_ENDPT_TX] = NULL;
1158 if (sc->cue_ep[CUE_ENDPT_INTR] != NULL) {
1159 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
1161 printf("cue%d: abort intr pipe failed: %s\n",
1162 sc->cue_unit, usbd_errstr(err));
1164 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
1166 printf("cue%d: close intr pipe failed: %s\n",
1167 sc->cue_unit, usbd_errstr(err));
1169 sc->cue_ep[CUE_ENDPT_INTR] = NULL;
1172 /* Free RX resources. */
1173 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
1174 if (sc->cue_cdata.cue_rx_chain[i].cue_buf != NULL) {
1175 free(sc->cue_cdata.cue_rx_chain[i].cue_buf, M_USBDEV);
1176 sc->cue_cdata.cue_rx_chain[i].cue_buf = NULL;
1178 if (sc->cue_cdata.cue_rx_chain[i].cue_mbuf != NULL) {
1179 m_freem(sc->cue_cdata.cue_rx_chain[i].cue_mbuf);
1180 sc->cue_cdata.cue_rx_chain[i].cue_mbuf = NULL;
1182 if (sc->cue_cdata.cue_rx_chain[i].cue_xfer != NULL) {
1183 usbd_free_xfer(sc->cue_cdata.cue_rx_chain[i].cue_xfer);
1184 sc->cue_cdata.cue_rx_chain[i].cue_xfer = NULL;
1188 /* Free TX resources. */
1189 for (i = 0; i < CUE_TX_LIST_CNT; i++) {
1190 if (sc->cue_cdata.cue_tx_chain[i].cue_buf != NULL) {
1191 free(sc->cue_cdata.cue_tx_chain[i].cue_buf, M_USBDEV);
1192 sc->cue_cdata.cue_tx_chain[i].cue_buf = NULL;
1194 if (sc->cue_cdata.cue_tx_chain[i].cue_mbuf != NULL) {
1195 m_freem(sc->cue_cdata.cue_tx_chain[i].cue_mbuf);
1196 sc->cue_cdata.cue_tx_chain[i].cue_mbuf = NULL;
1198 if (sc->cue_cdata.cue_tx_chain[i].cue_xfer != NULL) {
1199 usbd_free_xfer(sc->cue_cdata.cue_tx_chain[i].cue_xfer);
1200 sc->cue_cdata.cue_tx_chain[i].cue_xfer = NULL;
1204 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1210 * Stop all chip I/O so that the kernel's probe routines don't
1211 * get confused by errant DMAs when rebooting.
1213 Static void cue_shutdown(dev)
1216 struct cue_softc *sc;
1218 sc = device_get_softc(dev);