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>
70 #include <dev/usb/usb.h>
71 #include <dev/usb/usbdi.h>
72 #include <dev/usb/usbdi_util.h>
73 #include <dev/usb/usbdivar.h>
74 #include <dev/usb/usbdevs.h>
75 #include <dev/usb/usb_ethersubr.h>
77 #include <dev/usb/if_cuereg.h>
80 static const char rcsid[] =
85 * Various supported device vendors/products.
87 Static struct cue_type cue_devs[] = {
88 { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE },
89 { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE2 },
90 { USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTLINK },
94 Static struct usb_qdat cue_qdat;
96 Static int cue_match __P((device_t));
97 Static int cue_attach __P((device_t));
98 Static int cue_detach __P((device_t));
100 Static int cue_tx_list_init __P((struct cue_softc *));
101 Static int cue_rx_list_init __P((struct cue_softc *));
102 Static int cue_newbuf __P((struct cue_softc *, struct cue_chain *,
104 Static int cue_encap __P((struct cue_softc *, struct mbuf *, int));
105 Static void cue_rxeof __P((usbd_xfer_handle,
106 usbd_private_handle, usbd_status));
107 Static void cue_txeof __P((usbd_xfer_handle,
108 usbd_private_handle, usbd_status));
109 Static void cue_tick __P((void *));
110 Static void cue_rxstart __P((struct ifnet *));
111 Static void cue_start __P((struct ifnet *));
112 Static int cue_ioctl __P((struct ifnet *, u_long, caddr_t));
113 Static void cue_init __P((void *));
114 Static void cue_stop __P((struct cue_softc *));
115 Static void cue_watchdog __P((struct ifnet *));
116 Static void cue_shutdown __P((device_t));
118 Static void cue_setmulti __P((struct cue_softc *));
119 Static u_int32_t cue_crc __P((caddr_t));
120 Static void cue_reset __P((struct cue_softc *));
122 Static int csr_read_1 __P((struct cue_softc *, int));
123 Static int csr_write_1 __P((struct cue_softc *, int, int));
124 Static int csr_read_2 __P((struct cue_softc *, int));
126 Static int csr_write_2 __P((struct cue_softc *, int, int));
128 Static int cue_mem __P((struct cue_softc *, int,
130 Static int cue_getmac __P((struct cue_softc *, void *));
132 Static device_method_t cue_methods[] = {
133 /* Device interface */
134 DEVMETHOD(device_probe, cue_match),
135 DEVMETHOD(device_attach, cue_attach),
136 DEVMETHOD(device_detach, cue_detach),
137 DEVMETHOD(device_shutdown, cue_shutdown),
142 Static driver_t cue_driver = {
145 sizeof(struct cue_softc)
148 Static devclass_t cue_devclass;
150 DRIVER_MODULE(if_cue, uhub, cue_driver, cue_devclass, usbd_driver_load, 0);
152 #define CUE_SETBIT(sc, reg, x) \
153 csr_write_1(sc, reg, csr_read_1(sc, reg) | (x))
155 #define CUE_CLRBIT(sc, reg, x) \
156 csr_write_1(sc, reg, csr_read_1(sc, reg) & ~(x))
158 Static int csr_read_1(sc, reg)
159 struct cue_softc *sc;
162 usb_device_request_t req;
171 req.bmRequestType = UT_READ_VENDOR_DEVICE;
172 req.bRequest = CUE_CMD_READREG;
173 USETW(req.wValue, 0);
174 USETW(req.wIndex, reg);
175 USETW(req.wLength, 1);
177 err = usbd_do_request_flags(sc->cue_udev,
178 &req, &val, USBD_NO_TSLEEP, NULL);
188 Static int csr_read_2(sc, reg)
189 struct cue_softc *sc;
192 usb_device_request_t req;
201 req.bmRequestType = UT_READ_VENDOR_DEVICE;
202 req.bRequest = CUE_CMD_READREG;
203 USETW(req.wValue, 0);
204 USETW(req.wIndex, reg);
205 USETW(req.wLength, 2);
207 err = usbd_do_request_flags(sc->cue_udev,
208 &req, &val, USBD_NO_TSLEEP, NULL);
218 Static int csr_write_1(sc, reg, val)
219 struct cue_softc *sc;
222 usb_device_request_t req;
230 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
231 req.bRequest = CUE_CMD_WRITEREG;
232 USETW(req.wValue, val);
233 USETW(req.wIndex, reg);
234 USETW(req.wLength, 0);
236 err = usbd_do_request_flags(sc->cue_udev,
237 &req, &val, USBD_NO_TSLEEP, NULL);
248 Static int csr_write_2(sc, reg, val)
249 struct cue_softc *sc;
252 usb_device_request_t req;
260 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
261 req.bRequest = CUE_CMD_WRITEREG;
262 USETW(req.wValue, val);
263 USETW(req.wIndex, reg);
264 USETW(req.wLength, 0);
266 err = usbd_do_request_flags(sc->cue_udev,
267 &req, &val, USBD_NO_TSLEEP, NULL);
278 Static int cue_mem(sc, cmd, addr, buf, len)
279 struct cue_softc *sc;
285 usb_device_request_t req;
293 if (cmd == CUE_CMD_READSRAM)
294 req.bmRequestType = UT_READ_VENDOR_DEVICE;
296 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
298 USETW(req.wValue, 0);
299 USETW(req.wIndex, addr);
300 USETW(req.wLength, len);
302 err = usbd_do_request_flags(sc->cue_udev,
303 &req, &buf, USBD_NO_TSLEEP, NULL);
313 Static int cue_getmac(sc, buf)
314 struct cue_softc *sc;
317 usb_device_request_t req;
325 req.bmRequestType = UT_READ_VENDOR_DEVICE;
326 req.bRequest = CUE_CMD_GET_MACADDR;
327 USETW(req.wValue, 0);
328 USETW(req.wIndex, 0);
329 USETW(req.wLength, ETHER_ADDR_LEN);
331 err = usbd_do_request_flags(sc->cue_udev,
332 &req, buf, USBD_NO_TSLEEP, NULL);
337 printf("cue%d: read MAC address failed\n", sc->cue_unit);
344 #define CUE_POLY 0xEDB88320
347 Static u_int32_t cue_crc(addr)
350 u_int32_t idx, bit, data, crc;
352 /* Compute CRC for the address value. */
353 crc = 0xFFFFFFFF; /* initial value */
355 for (idx = 0; idx < 6; idx++) {
356 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
357 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? CUE_POLY : 0);
360 return (crc & ((1 << CUE_BITS) - 1));
363 Static void cue_setmulti(sc)
364 struct cue_softc *sc;
367 struct ifmultiaddr *ifma;
370 ifp = &sc->arpcom.ac_if;
372 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
373 for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
374 sc->cue_mctab[i] = 0xFF;
375 cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
376 &sc->cue_mctab, CUE_MCAST_TABLE_LEN);
380 /* first, zot all the existing hash bits */
381 for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
382 sc->cue_mctab[i] = 0;
384 /* now program new ones */
385 for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL;
386 ifma = ifma->ifma_link.le_next) {
387 if (ifma->ifma_addr->sa_family != AF_LINK)
389 h = cue_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
390 sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
394 * Also include the broadcast address in the filter
395 * so we can receive broadcast frames.
397 if (ifp->if_flags & IFF_BROADCAST) {
398 h = cue_crc(etherbroadcastaddr);
399 sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
402 cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
403 &sc->cue_mctab, CUE_MCAST_TABLE_LEN);
408 Static void cue_reset(sc)
409 struct cue_softc *sc;
411 usb_device_request_t req;
417 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
418 req.bRequest = CUE_CMD_RESET;
419 USETW(req.wValue, 0);
420 USETW(req.wIndex, 0);
421 USETW(req.wLength, 0);
422 err = usbd_do_request_flags(sc->cue_udev,
423 &req, NULL, USBD_NO_TSLEEP, NULL);
426 printf("cue%d: reset failed\n", sc->cue_unit);
428 /* Wait a little while for the chip to get its brains in order. */
434 * Probe for a Pegasus chip.
438 USB_MATCH_START(cue, uaa);
446 if (uaa->vendor == t->cue_vid &&
447 uaa->product == t->cue_did) {
448 return(UMATCH_VENDOR_PRODUCT);
457 * Attach the interface. Allocate softc structures, do ifmedia
458 * setup and ethernet/BPF attach.
462 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;
470 bzero(sc, sizeof(struct cue_softc));
471 sc->cue_iface = uaa->iface;
472 sc->cue_udev = uaa->device;
473 sc->cue_unit = device_get_unit(self);
475 if (usbd_set_config_no(sc->cue_udev, CUE_CONFIG_NO, 0)) {
476 printf("cue%d: getting interface handle failed\n",
478 USB_ATTACH_ERROR_RETURN;
481 id = usbd_get_interface_descriptor(uaa->iface);
483 usbd_devinfo(uaa->device, 0, devinfo);
484 device_set_desc_copy(self, devinfo);
485 printf("%s: %s\n", USBDEVNAME(self), devinfo);
487 /* Find endpoints. */
488 for (i = 0; i < id->bNumEndpoints; i++) {
489 ed = usbd_interface2endpoint_descriptor(uaa->iface, i);
491 printf("cue%d: couldn't get ep %d\n",
493 USB_ATTACH_ERROR_RETURN;
495 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
496 (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
497 sc->cue_ed[CUE_ENDPT_RX] = ed->bEndpointAddress;
498 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
499 (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
500 sc->cue_ed[CUE_ENDPT_TX] = ed->bEndpointAddress;
501 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
502 (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
503 sc->cue_ed[CUE_ENDPT_INTR] = ed->bEndpointAddress;
507 mtx_init(&sc->cue_mtx, device_get_nameunit(self), MTX_DEF);
511 /* Reset the adapter. */
515 * Get station address.
517 cue_getmac(sc, &eaddr);
520 * A CATC chip was detected. Inform the world.
522 printf("cue%d: Ethernet address: %6D\n", sc->cue_unit, eaddr, ":");
524 bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
526 ifp = &sc->arpcom.ac_if;
528 ifp->if_unit = sc->cue_unit;
529 ifp->if_name = "cue";
530 ifp->if_mtu = ETHERMTU;
531 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
532 ifp->if_ioctl = cue_ioctl;
533 ifp->if_output = ether_output;
534 ifp->if_start = cue_start;
535 ifp->if_watchdog = cue_watchdog;
536 ifp->if_init = cue_init;
537 ifp->if_baudrate = 10000000;
538 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
541 cue_qdat.if_rxstart = cue_rxstart;
544 * Call MI attach routine.
546 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
547 callout_handle_init(&sc->cue_stat_ch);
548 usb_register_netisr();
552 USB_ATTACH_SUCCESS_RETURN;
555 Static int cue_detach(dev)
558 struct cue_softc *sc;
561 sc = device_get_softc(dev);
563 ifp = &sc->arpcom.ac_if;
566 untimeout(cue_tick, sc, sc->cue_stat_ch);
567 ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
569 if (sc->cue_ep[CUE_ENDPT_TX] != NULL)
570 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
571 if (sc->cue_ep[CUE_ENDPT_RX] != NULL)
572 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
573 if (sc->cue_ep[CUE_ENDPT_INTR] != NULL)
574 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
577 mtx_destroy(&sc->cue_mtx);
583 * Initialize an RX descriptor and attach an MBUF cluster.
585 Static int cue_newbuf(sc, c, m)
586 struct cue_softc *sc;
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);
620 Static int cue_rx_list_init(sc)
621 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)
644 Static int cue_tx_list_init(sc)
645 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)
670 Static void cue_rxstart(ifp)
673 struct cue_softc *sc;
678 c = &sc->cue_cdata.cue_rx_chain[sc->cue_cdata.cue_rx_prod];
680 if (cue_newbuf(sc, c, NULL) == ENOBUFS) {
686 /* Setup new transfer. */
687 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
688 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ, USBD_SHORT_XFER_OK,
689 USBD_NO_TIMEOUT, cue_rxeof);
690 usbd_transfer(c->cue_xfer);
697 * A frame has been uploaded: pass the resulting mbuf chain up to
698 * the higher level protocols.
700 Static void cue_rxeof(xfer, priv, status)
701 usbd_xfer_handle xfer;
702 usbd_private_handle priv;
705 struct cue_softc *sc;
715 ifp = &sc->arpcom.ac_if;
717 if (!(ifp->if_flags & IFF_RUNNING)) {
722 if (status != USBD_NORMAL_COMPLETION) {
723 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
727 printf("cue%d: usb error on rx: %s\n", sc->cue_unit,
728 usbd_errstr(status));
729 if (status == USBD_STALLED)
730 usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_RX]);
734 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
737 len = *mtod(m, u_int16_t *);
739 /* No errors; receive the packet. */
742 if (len < sizeof(struct ether_header)) {
748 m_adj(m, sizeof(u_int16_t));
749 m->m_pkthdr.rcvif = (struct ifnet *)&cue_qdat;
750 m->m_pkthdr.len = m->m_len = total_len;
752 /* Put the packet on the special USB input queue. */
758 /* Setup new transfer. */
759 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
760 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ, USBD_SHORT_XFER_OK,
761 USBD_NO_TIMEOUT, cue_rxeof);
762 usbd_transfer(c->cue_xfer);
769 * A frame was downloaded to the chip. It's safe for us to clean up
773 Static void cue_txeof(xfer, priv, status)
774 usbd_xfer_handle xfer;
775 usbd_private_handle priv;
778 struct cue_softc *sc;
786 ifp = &sc->arpcom.ac_if;
788 if (status != USBD_NORMAL_COMPLETION) {
789 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
793 printf("cue%d: usb error on tx: %s\n", sc->cue_unit,
794 usbd_errstr(status));
795 if (status == USBD_STALLED)
796 usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_TX]);
802 ifp->if_flags &= ~IFF_OACTIVE;
803 usbd_get_xfer_status(c->cue_xfer, NULL, NULL, NULL, &err);
805 if (c->cue_mbuf != NULL) {
806 c->cue_mbuf->m_pkthdr.rcvif = ifp;
807 usb_tx_done(c->cue_mbuf);
821 Static void cue_tick(xsc)
824 struct cue_softc *sc;
834 ifp = &sc->arpcom.ac_if;
836 ifp->if_collisions += csr_read_2(sc, CUE_TX_SINGLECOLL);
837 ifp->if_collisions += csr_read_2(sc, CUE_TX_MULTICOLL);
838 ifp->if_collisions += csr_read_2(sc, CUE_TX_EXCESSCOLL);
840 if (csr_read_2(sc, CUE_RX_FRAMEERR))
843 sc->cue_stat_ch = timeout(cue_tick, sc, hz);
850 Static int cue_encap(sc, m, idx)
851 struct cue_softc *sc;
859 c = &sc->cue_cdata.cue_tx_chain[idx];
862 * Copy the mbuf data into a contiguous buffer, leaving two
863 * bytes at the beginning to hold the frame length.
865 m_copydata(m, 0, m->m_pkthdr.len, c->cue_buf + 2);
868 total_len = m->m_pkthdr.len + 2;
870 /* The first two bytes are the frame length */
871 c->cue_buf[0] = (u_int8_t)m->m_pkthdr.len;
872 c->cue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
874 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_TX],
875 c, c->cue_buf, total_len, 0, 10000, cue_txeof);
878 err = usbd_transfer(c->cue_xfer);
879 if (err != USBD_IN_PROGRESS) {
884 sc->cue_cdata.cue_tx_cnt++;
889 Static void cue_start(ifp)
892 struct cue_softc *sc;
893 struct mbuf *m_head = NULL;
898 if (ifp->if_flags & IFF_OACTIVE) {
903 IF_DEQUEUE(&ifp->if_snd, m_head);
904 if (m_head == NULL) {
909 if (cue_encap(sc, m_head, 0)) {
910 IF_PREPEND(&ifp->if_snd, m_head);
911 ifp->if_flags |= IFF_OACTIVE;
917 * If there's a BPF listener, bounce a copy of this frame
921 bpf_mtap(ifp, m_head);
923 ifp->if_flags |= IFF_OACTIVE;
926 * Set a timeout in case the chip goes out to lunch.
934 Static void cue_init(xsc)
937 struct cue_softc *sc = xsc;
938 struct ifnet *ifp = &sc->arpcom.ac_if;
943 if (ifp->if_flags & IFF_RUNNING)
949 * Cancel pending I/O and free all RX/TX buffers.
955 /* Set MAC address */
956 for (i = 0; i < ETHER_ADDR_LEN; i++)
957 csr_write_1(sc, CUE_PAR0 - i, sc->arpcom.ac_enaddr[i]);
959 /* Enable RX logic. */
960 csr_write_1(sc, CUE_ETHCTL, CUE_ETHCTL_RX_ON|CUE_ETHCTL_MCAST_ON);
962 /* If we want promiscuous mode, set the allframes bit. */
963 if (ifp->if_flags & IFF_PROMISC) {
964 CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
966 CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
970 if (cue_tx_list_init(sc) == ENOBUFS) {
971 printf("cue%d: tx list init failed\n", sc->cue_unit);
977 if (cue_rx_list_init(sc) == ENOBUFS) {
978 printf("cue%d: rx list init failed\n", sc->cue_unit);
983 /* Load the multicast filter. */
987 * Set the number of RX and TX buffers that we want
988 * to reserve inside the ASIC.
990 csr_write_1(sc, CUE_RX_BUFPKTS, CUE_RX_FRAMES);
991 csr_write_1(sc, CUE_TX_BUFPKTS, CUE_TX_FRAMES);
993 /* Set advanced operation modes. */
994 csr_write_1(sc, CUE_ADVANCED_OPMODES,
995 CUE_AOP_EMBED_RXLEN|0x01); /* 1 wait state */
997 /* Program the LED operation. */
998 csr_write_1(sc, CUE_LEDCTL, CUE_LEDCTL_FOLLOW_LINK);
1000 /* Open RX and TX pipes. */
1001 err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_RX],
1002 USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_RX]);
1004 printf("cue%d: open rx pipe failed: %s\n",
1005 sc->cue_unit, usbd_errstr(err));
1009 err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_TX],
1010 USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_TX]);
1012 printf("cue%d: open tx pipe failed: %s\n",
1013 sc->cue_unit, usbd_errstr(err));
1018 /* Start up the receive pipe. */
1019 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
1020 c = &sc->cue_cdata.cue_rx_chain[i];
1021 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
1022 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ,
1023 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, cue_rxeof);
1024 usbd_transfer(c->cue_xfer);
1027 ifp->if_flags |= IFF_RUNNING;
1028 ifp->if_flags &= ~IFF_OACTIVE;
1032 sc->cue_stat_ch = timeout(cue_tick, sc, hz);
1037 Static int cue_ioctl(ifp, command, data)
1042 struct cue_softc *sc = ifp->if_softc;
1051 error = ether_ioctl(ifp, command, data);
1054 if (ifp->if_flags & IFF_UP) {
1055 if (ifp->if_flags & IFF_RUNNING &&
1056 ifp->if_flags & IFF_PROMISC &&
1057 !(sc->cue_if_flags & IFF_PROMISC)) {
1058 CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
1060 } else if (ifp->if_flags & IFF_RUNNING &&
1061 !(ifp->if_flags & IFF_PROMISC) &&
1062 sc->cue_if_flags & IFF_PROMISC) {
1063 CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
1065 } else if (!(ifp->if_flags & IFF_RUNNING))
1068 if (ifp->if_flags & IFF_RUNNING)
1071 sc->cue_if_flags = ifp->if_flags;
1089 Static void cue_watchdog(ifp)
1092 struct cue_softc *sc;
1093 struct cue_chain *c;
1100 printf("cue%d: watchdog timeout\n", sc->cue_unit);
1102 c = &sc->cue_cdata.cue_tx_chain[0];
1103 usbd_get_xfer_status(c->cue_xfer, NULL, NULL, NULL, &stat);
1104 cue_txeof(c->cue_xfer, c, stat);
1106 if (ifp->if_snd.ifq_head != NULL)
1114 * Stop the adapter and free any mbufs allocated to the
1117 Static void cue_stop(sc)
1118 struct cue_softc *sc;
1126 ifp = &sc->arpcom.ac_if;
1129 csr_write_1(sc, CUE_ETHCTL, 0);
1131 untimeout(cue_tick, sc, sc->cue_stat_ch);
1133 /* Stop transfers. */
1134 if (sc->cue_ep[CUE_ENDPT_RX] != NULL) {
1135 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
1137 printf("cue%d: abort rx pipe failed: %s\n",
1138 sc->cue_unit, usbd_errstr(err));
1140 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_RX]);
1142 printf("cue%d: close rx pipe failed: %s\n",
1143 sc->cue_unit, usbd_errstr(err));
1145 sc->cue_ep[CUE_ENDPT_RX] = NULL;
1148 if (sc->cue_ep[CUE_ENDPT_TX] != NULL) {
1149 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
1151 printf("cue%d: abort tx pipe failed: %s\n",
1152 sc->cue_unit, usbd_errstr(err));
1154 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_TX]);
1156 printf("cue%d: close tx pipe failed: %s\n",
1157 sc->cue_unit, usbd_errstr(err));
1159 sc->cue_ep[CUE_ENDPT_TX] = NULL;
1162 if (sc->cue_ep[CUE_ENDPT_INTR] != NULL) {
1163 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
1165 printf("cue%d: abort intr pipe failed: %s\n",
1166 sc->cue_unit, usbd_errstr(err));
1168 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
1170 printf("cue%d: close intr pipe failed: %s\n",
1171 sc->cue_unit, usbd_errstr(err));
1173 sc->cue_ep[CUE_ENDPT_INTR] = NULL;
1176 /* Free RX resources. */
1177 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
1178 if (sc->cue_cdata.cue_rx_chain[i].cue_buf != NULL) {
1179 free(sc->cue_cdata.cue_rx_chain[i].cue_buf, M_USBDEV);
1180 sc->cue_cdata.cue_rx_chain[i].cue_buf = NULL;
1182 if (sc->cue_cdata.cue_rx_chain[i].cue_mbuf != NULL) {
1183 m_freem(sc->cue_cdata.cue_rx_chain[i].cue_mbuf);
1184 sc->cue_cdata.cue_rx_chain[i].cue_mbuf = NULL;
1186 if (sc->cue_cdata.cue_rx_chain[i].cue_xfer != NULL) {
1187 usbd_free_xfer(sc->cue_cdata.cue_rx_chain[i].cue_xfer);
1188 sc->cue_cdata.cue_rx_chain[i].cue_xfer = NULL;
1192 /* Free TX resources. */
1193 for (i = 0; i < CUE_TX_LIST_CNT; i++) {
1194 if (sc->cue_cdata.cue_tx_chain[i].cue_buf != NULL) {
1195 free(sc->cue_cdata.cue_tx_chain[i].cue_buf, M_USBDEV);
1196 sc->cue_cdata.cue_tx_chain[i].cue_buf = NULL;
1198 if (sc->cue_cdata.cue_tx_chain[i].cue_mbuf != NULL) {
1199 m_freem(sc->cue_cdata.cue_tx_chain[i].cue_mbuf);
1200 sc->cue_cdata.cue_tx_chain[i].cue_mbuf = NULL;
1202 if (sc->cue_cdata.cue_tx_chain[i].cue_xfer != NULL) {
1203 usbd_free_xfer(sc->cue_cdata.cue_tx_chain[i].cue_xfer);
1204 sc->cue_cdata.cue_tx_chain[i].cue_xfer = NULL;
1208 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1215 * Stop all chip I/O so that the kernel's probe routines don't
1216 * get confused by errant DMAs when rebooting.
1218 Static void cue_shutdown(dev)
1221 struct cue_softc *sc;
1223 sc = device_get_softc(dev);