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 routine.
560 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
561 callout_handle_init(&sc->cue_stat_ch);
562 usb_register_netisr();
566 USB_ATTACH_SUCCESS_RETURN;
569 Static int cue_detach(dev)
572 struct cue_softc *sc;
578 sc = device_get_softc(dev);
579 ifp = &sc->arpcom.ac_if;
582 untimeout(cue_tick, sc, sc->cue_stat_ch);
583 ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
585 if (sc->cue_ep[CUE_ENDPT_TX] != NULL)
586 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
587 if (sc->cue_ep[CUE_ENDPT_RX] != NULL)
588 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
589 if (sc->cue_ep[CUE_ENDPT_INTR] != NULL)
590 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
598 * Initialize an RX descriptor and attach an MBUF cluster.
600 Static int cue_newbuf(sc, c, m)
601 struct cue_softc *sc;
605 struct mbuf *m_new = NULL;
608 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
610 printf("cue%d: no memory for rx list "
611 "-- packet dropped!\n", sc->cue_unit);
615 MCLGET(m_new, M_DONTWAIT);
616 if (!(m_new->m_flags & M_EXT)) {
617 printf("cue%d: no memory for rx list "
618 "-- packet dropped!\n", sc->cue_unit);
622 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
625 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
626 m_new->m_data = m_new->m_ext.ext_buf;
629 m_adj(m_new, ETHER_ALIGN);
635 Static int cue_rx_list_init(sc)
636 struct cue_softc *sc;
638 struct cue_cdata *cd;
643 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
644 c = &cd->cue_rx_chain[i];
647 if (cue_newbuf(sc, c, NULL) == ENOBUFS)
649 if (c->cue_xfer == NULL) {
650 c->cue_xfer = usbd_alloc_xfer(sc->cue_udev);
651 if (c->cue_xfer == NULL)
659 Static int cue_tx_list_init(sc)
660 struct cue_softc *sc;
662 struct cue_cdata *cd;
667 for (i = 0; i < CUE_TX_LIST_CNT; i++) {
668 c = &cd->cue_tx_chain[i];
672 if (c->cue_xfer == NULL) {
673 c->cue_xfer = usbd_alloc_xfer(sc->cue_udev);
674 if (c->cue_xfer == NULL)
677 c->cue_buf = malloc(CUE_BUFSZ, M_USBDEV, M_NOWAIT);
678 if (c->cue_buf == NULL)
685 Static void cue_rxstart(ifp)
688 struct cue_softc *sc;
692 c = &sc->cue_cdata.cue_rx_chain[sc->cue_cdata.cue_rx_prod];
694 if (cue_newbuf(sc, c, NULL) == ENOBUFS) {
699 /* Setup new transfer. */
700 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
701 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ, USBD_SHORT_XFER_OK,
702 USBD_NO_TIMEOUT, cue_rxeof);
703 usbd_transfer(c->cue_xfer);
709 * A frame has been uploaded: pass the resulting mbuf chain up to
710 * the higher level protocols.
712 Static void cue_rxeof(xfer, priv, status)
713 usbd_xfer_handle xfer;
714 usbd_private_handle priv;
717 struct cue_softc *sc;
726 ifp = &sc->arpcom.ac_if;
728 if (!(ifp->if_flags & IFF_RUNNING))
731 if (status != USBD_NORMAL_COMPLETION) {
732 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
734 printf("cue%d: usb error on rx: %s\n", sc->cue_unit,
735 usbd_errstr(status));
736 if (status == USBD_STALLED)
737 usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_RX]);
741 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
744 len = *mtod(m, u_int16_t *);
746 /* No errors; receive the packet. */
749 if (len < sizeof(struct ether_header)) {
755 m_adj(m, sizeof(u_int16_t));
756 m->m_pkthdr.rcvif = (struct ifnet *)&cue_qdat;
757 m->m_pkthdr.len = m->m_len = total_len;
759 /* Put the packet on the special USB input queue. */
764 /* Setup new transfer. */
765 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
766 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ, USBD_SHORT_XFER_OK,
767 USBD_NO_TIMEOUT, cue_rxeof);
768 usbd_transfer(c->cue_xfer);
774 * A frame was downloaded to the chip. It's safe for us to clean up
778 Static void cue_txeof(xfer, priv, status)
779 usbd_xfer_handle xfer;
780 usbd_private_handle priv;
783 struct cue_softc *sc;
793 ifp = &sc->arpcom.ac_if;
795 if (status != USBD_NORMAL_COMPLETION) {
796 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
800 printf("cue%d: usb error on tx: %s\n", sc->cue_unit,
801 usbd_errstr(status));
802 if (status == USBD_STALLED)
803 usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_TX]);
809 ifp->if_flags &= ~IFF_OACTIVE;
810 usbd_get_xfer_status(c->cue_xfer, NULL, NULL, NULL, &err);
812 if (c->cue_mbuf != NULL) {
813 c->cue_mbuf->m_pkthdr.rcvif = ifp;
814 usb_tx_done(c->cue_mbuf);
828 Static void cue_tick(xsc)
831 struct cue_softc *sc;
844 ifp = &sc->arpcom.ac_if;
846 ifp->if_collisions += csr_read_2(sc, CUE_TX_SINGLECOLL);
847 ifp->if_collisions += csr_read_2(sc, CUE_TX_MULTICOLL);
848 ifp->if_collisions += csr_read_2(sc, CUE_TX_EXCESSCOLL);
850 if (csr_read_2(sc, CUE_RX_FRAMEERR))
853 sc->cue_stat_ch = timeout(cue_tick, sc, hz);
860 Static int cue_encap(sc, m, idx)
861 struct cue_softc *sc;
869 c = &sc->cue_cdata.cue_tx_chain[idx];
872 * Copy the mbuf data into a contiguous buffer, leaving two
873 * bytes at the beginning to hold the frame length.
875 m_copydata(m, 0, m->m_pkthdr.len, c->cue_buf + 2);
878 total_len = m->m_pkthdr.len + 2;
880 /* The first two bytes are the frame length */
881 c->cue_buf[0] = (u_int8_t)m->m_pkthdr.len;
882 c->cue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
884 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_TX],
885 c, c->cue_buf, total_len, 0, 10000, cue_txeof);
888 err = usbd_transfer(c->cue_xfer);
889 if (err != USBD_IN_PROGRESS) {
894 sc->cue_cdata.cue_tx_cnt++;
899 Static void cue_start(ifp)
902 struct cue_softc *sc;
903 struct mbuf *m_head = NULL;
907 if (ifp->if_flags & IFF_OACTIVE)
910 IF_DEQUEUE(&ifp->if_snd, m_head);
914 if (cue_encap(sc, m_head, 0)) {
915 IF_PREPEND(&ifp->if_snd, m_head);
916 ifp->if_flags |= IFF_OACTIVE;
921 * If there's a BPF listener, bounce a copy of this frame
925 bpf_mtap(ifp, m_head);
927 ifp->if_flags |= IFF_OACTIVE;
930 * Set a timeout in case the chip goes out to lunch.
937 Static void cue_init(xsc)
940 struct cue_softc *sc = xsc;
941 struct ifnet *ifp = &sc->arpcom.ac_if;
946 if (ifp->if_flags & IFF_RUNNING)
952 * Cancel pending I/O and free all RX/TX buffers.
958 /* Set MAC address */
959 for (i = 0; i < ETHER_ADDR_LEN; i++)
960 csr_write_1(sc, CUE_PAR0 - i, sc->arpcom.ac_enaddr[i]);
962 /* Enable RX logic. */
963 csr_write_1(sc, CUE_ETHCTL, CUE_ETHCTL_RX_ON|CUE_ETHCTL_MCAST_ON);
965 /* If we want promiscuous mode, set the allframes bit. */
966 if (ifp->if_flags & IFF_PROMISC) {
967 CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
969 CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
973 if (cue_tx_list_init(sc) == ENOBUFS) {
974 printf("cue%d: tx list init failed\n", sc->cue_unit);
980 if (cue_rx_list_init(sc) == ENOBUFS) {
981 printf("cue%d: rx list init failed\n", sc->cue_unit);
986 /* Load the multicast filter. */
990 * Set the number of RX and TX buffers that we want
991 * to reserve inside the ASIC.
993 csr_write_1(sc, CUE_RX_BUFPKTS, CUE_RX_FRAMES);
994 csr_write_1(sc, CUE_TX_BUFPKTS, CUE_TX_FRAMES);
996 /* Set advanced operation modes. */
997 csr_write_1(sc, CUE_ADVANCED_OPMODES,
998 CUE_AOP_EMBED_RXLEN|0x01); /* 1 wait state */
1000 /* Program the LED operation. */
1001 csr_write_1(sc, CUE_LEDCTL, CUE_LEDCTL_FOLLOW_LINK);
1003 /* Open RX and TX pipes. */
1004 err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_RX],
1005 USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_RX]);
1007 printf("cue%d: open rx pipe failed: %s\n",
1008 sc->cue_unit, usbd_errstr(err));
1012 err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_TX],
1013 USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_TX]);
1015 printf("cue%d: open tx pipe failed: %s\n",
1016 sc->cue_unit, usbd_errstr(err));
1021 /* Start up the receive pipe. */
1022 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
1023 c = &sc->cue_cdata.cue_rx_chain[i];
1024 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
1025 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ,
1026 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, cue_rxeof);
1027 usbd_transfer(c->cue_xfer);
1030 ifp->if_flags |= IFF_RUNNING;
1031 ifp->if_flags &= ~IFF_OACTIVE;
1035 sc->cue_stat_ch = timeout(cue_tick, sc, hz);
1040 Static int cue_ioctl(ifp, command, data)
1045 struct cue_softc *sc = ifp->if_softc;
1054 error = ether_ioctl(ifp, command, data);
1057 if (ifp->if_flags & IFF_UP) {
1058 if (ifp->if_flags & IFF_RUNNING &&
1059 ifp->if_flags & IFF_PROMISC &&
1060 !(sc->cue_if_flags & IFF_PROMISC)) {
1061 CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
1063 } else if (ifp->if_flags & IFF_RUNNING &&
1064 !(ifp->if_flags & IFF_PROMISC) &&
1065 sc->cue_if_flags & IFF_PROMISC) {
1066 CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
1068 } else if (!(ifp->if_flags & IFF_RUNNING))
1071 if (ifp->if_flags & IFF_RUNNING)
1074 sc->cue_if_flags = ifp->if_flags;
1092 Static void cue_watchdog(ifp)
1095 struct cue_softc *sc;
1096 struct cue_chain *c;
1102 printf("cue%d: watchdog timeout\n", sc->cue_unit);
1104 c = &sc->cue_cdata.cue_tx_chain[0];
1105 usbd_get_xfer_status(c->cue_xfer, NULL, NULL, NULL, &stat);
1106 cue_txeof(c->cue_xfer, c, stat);
1108 if (ifp->if_snd.ifq_head != NULL)
1115 * Stop the adapter and free any mbufs allocated to the
1118 Static void cue_stop(sc)
1119 struct cue_softc *sc;
1125 ifp = &sc->arpcom.ac_if;
1128 csr_write_1(sc, CUE_ETHCTL, 0);
1130 untimeout(cue_tick, sc, sc->cue_stat_ch);
1132 /* Stop transfers. */
1133 if (sc->cue_ep[CUE_ENDPT_RX] != NULL) {
1134 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
1136 printf("cue%d: abort rx pipe failed: %s\n",
1137 sc->cue_unit, usbd_errstr(err));
1139 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_RX]);
1141 printf("cue%d: close rx pipe failed: %s\n",
1142 sc->cue_unit, usbd_errstr(err));
1144 sc->cue_ep[CUE_ENDPT_RX] = NULL;
1147 if (sc->cue_ep[CUE_ENDPT_TX] != NULL) {
1148 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
1150 printf("cue%d: abort tx pipe failed: %s\n",
1151 sc->cue_unit, usbd_errstr(err));
1153 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_TX]);
1155 printf("cue%d: close tx pipe failed: %s\n",
1156 sc->cue_unit, usbd_errstr(err));
1158 sc->cue_ep[CUE_ENDPT_TX] = NULL;
1161 if (sc->cue_ep[CUE_ENDPT_INTR] != NULL) {
1162 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
1164 printf("cue%d: abort intr pipe failed: %s\n",
1165 sc->cue_unit, usbd_errstr(err));
1167 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
1169 printf("cue%d: close intr pipe failed: %s\n",
1170 sc->cue_unit, usbd_errstr(err));
1172 sc->cue_ep[CUE_ENDPT_INTR] = NULL;
1175 /* Free RX resources. */
1176 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
1177 if (sc->cue_cdata.cue_rx_chain[i].cue_buf != NULL) {
1178 free(sc->cue_cdata.cue_rx_chain[i].cue_buf, M_USBDEV);
1179 sc->cue_cdata.cue_rx_chain[i].cue_buf = NULL;
1181 if (sc->cue_cdata.cue_rx_chain[i].cue_mbuf != NULL) {
1182 m_freem(sc->cue_cdata.cue_rx_chain[i].cue_mbuf);
1183 sc->cue_cdata.cue_rx_chain[i].cue_mbuf = NULL;
1185 if (sc->cue_cdata.cue_rx_chain[i].cue_xfer != NULL) {
1186 usbd_free_xfer(sc->cue_cdata.cue_rx_chain[i].cue_xfer);
1187 sc->cue_cdata.cue_rx_chain[i].cue_xfer = NULL;
1191 /* Free TX resources. */
1192 for (i = 0; i < CUE_TX_LIST_CNT; i++) {
1193 if (sc->cue_cdata.cue_tx_chain[i].cue_buf != NULL) {
1194 free(sc->cue_cdata.cue_tx_chain[i].cue_buf, M_USBDEV);
1195 sc->cue_cdata.cue_tx_chain[i].cue_buf = NULL;
1197 if (sc->cue_cdata.cue_tx_chain[i].cue_mbuf != NULL) {
1198 m_freem(sc->cue_cdata.cue_tx_chain[i].cue_mbuf);
1199 sc->cue_cdata.cue_tx_chain[i].cue_mbuf = NULL;
1201 if (sc->cue_cdata.cue_tx_chain[i].cue_xfer != NULL) {
1202 usbd_free_xfer(sc->cue_cdata.cue_tx_chain[i].cue_xfer);
1203 sc->cue_cdata.cue_tx_chain[i].cue_xfer = NULL;
1207 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1213 * Stop all chip I/O so that the kernel's probe routines don't
1214 * get confused by errant DMAs when rebooting.
1216 Static void cue_shutdown(dev)
1219 struct cue_softc *sc;
1221 sc = device_get_softc(dev);