2 * Copyright (c) 1997, 1998, 1999, 2000
3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
32 * $FreeBSD: src/sys/dev/usb/if_cue.c,v 1.45 2003/12/08 07:54:14 obrien Exp $
33 * $DragonFly: src/sys/dev/netif/cue/if_cue.c,v 1.20 2005/05/25 11:51:26 joerg Exp $
37 * CATC USB-EL1210A USB to ethernet driver. Used in the CATC Netmate
38 * adapters and others.
40 * Written by Bill Paul <wpaul@ee.columbia.edu>
41 * Electrical Engineering Department
42 * Columbia University, New York City
46 * The CATC USB-EL1210A provides USB ethernet support at 10Mbps. The
47 * RX filter uses a 512-bit multicast hash table, single perfect entry
48 * for the station address, and promiscuous mode. Unlike the ADMtek
49 * and KLSI chips, the CATC ASIC supports read and write combining
50 * mode where multiple packets can be transfered using a single bulk
51 * transaction, which helps performance a great deal.
54 #include <sys/param.h>
55 #include <sys/systm.h>
56 #include <sys/sockio.h>
58 #include <sys/malloc.h>
59 #include <sys/kernel.h>
60 #include <sys/socket.h>
63 #include <net/ifq_var.h>
64 #include <net/if_arp.h>
65 #include <net/ethernet.h>
66 #include <net/if_dl.h>
71 #include <machine/bus.h>
73 #include <bus/usb/usb.h>
74 #include <bus/usb/usbdi.h>
75 #include <bus/usb/usbdi_util.h>
76 #include <bus/usb/usbdivar.h>
77 #include <bus/usb/usbdevs.h>
78 #include <bus/usb/usb_ethersubr.h>
80 #include "if_cuereg.h"
83 * Various supported device vendors/products.
85 Static struct cue_type cue_devs[] = {
86 { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE },
87 { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE2 },
88 { USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTLINK },
92 Static int cue_match(device_ptr_t);
93 Static int cue_attach(device_ptr_t);
94 Static int cue_detach(device_ptr_t);
96 Static int cue_tx_list_init(struct cue_softc *);
97 Static int cue_rx_list_init(struct cue_softc *);
98 Static int cue_newbuf(struct cue_softc *, struct cue_chain *, struct mbuf *);
99 Static int cue_encap(struct cue_softc *, struct mbuf *, int);
100 Static void cue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
101 Static void cue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
102 Static void cue_tick(void *);
103 Static void cue_rxstart(struct ifnet *);
104 Static void cue_start(struct ifnet *);
105 Static int cue_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
106 Static void cue_init(void *);
107 Static void cue_stop(struct cue_softc *);
108 Static void cue_watchdog(struct ifnet *);
109 Static void cue_shutdown(device_ptr_t);
111 Static void cue_setmulti(struct cue_softc *);
112 Static void cue_reset(struct cue_softc *);
114 Static int cue_csr_read_1(struct cue_softc *, int);
115 Static int cue_csr_write_1(struct cue_softc *, int, int);
116 Static int cue_csr_read_2(struct cue_softc *, int);
118 Static int cue_csr_write_2(struct cue_softc *, int, int);
120 Static int cue_mem(struct cue_softc *, int, int, void *, int);
121 Static int cue_getmac(struct cue_softc *, void *);
123 Static device_method_t cue_methods[] = {
124 /* Device interface */
125 DEVMETHOD(device_probe, cue_match),
126 DEVMETHOD(device_attach, cue_attach),
127 DEVMETHOD(device_detach, cue_detach),
128 DEVMETHOD(device_shutdown, cue_shutdown),
133 Static driver_t cue_driver = {
136 sizeof(struct cue_softc)
139 Static devclass_t cue_devclass;
141 DECLARE_DUMMY_MODULE(if_cue);
142 DRIVER_MODULE(cue, uhub, cue_driver, cue_devclass, usbd_driver_load, 0);
143 MODULE_DEPEND(cue, usb, 1, 1, 1);
145 #define CUE_SETBIT(sc, reg, x) \
146 cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) | (x))
148 #define CUE_CLRBIT(sc, reg, x) \
149 cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) & ~(x))
152 cue_csr_read_1(struct cue_softc *sc, int reg)
154 usb_device_request_t req;
163 req.bmRequestType = UT_READ_VENDOR_DEVICE;
164 req.bRequest = CUE_CMD_READREG;
165 USETW(req.wValue, 0);
166 USETW(req.wIndex, reg);
167 USETW(req.wLength, 1);
169 err = usbd_do_request(sc->cue_udev, &req, &val);
180 cue_csr_read_2(struct cue_softc *sc, int reg)
182 usb_device_request_t req;
191 req.bmRequestType = UT_READ_VENDOR_DEVICE;
192 req.bRequest = CUE_CMD_READREG;
193 USETW(req.wValue, 0);
194 USETW(req.wIndex, reg);
195 USETW(req.wLength, 2);
197 err = usbd_do_request(sc->cue_udev, &req, &val);
208 cue_csr_write_1(struct cue_softc *sc, int reg, int val)
210 usb_device_request_t req;
218 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
219 req.bRequest = CUE_CMD_WRITEREG;
220 USETW(req.wValue, val);
221 USETW(req.wIndex, reg);
222 USETW(req.wLength, 0);
224 err = usbd_do_request(sc->cue_udev, &req, NULL);
236 cue_csr_write_2(struct cue_softc *sc, int reg, int val)
238 usb_device_request_t req;
246 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
247 req.bRequest = CUE_CMD_WRITEREG;
248 USETW(req.wValue, val);
249 USETW(req.wIndex, reg);
250 USETW(req.wLength, 0);
252 err = usbd_do_request(sc->cue_udev, &req, NULL);
264 cue_mem(struct cue_softc *sc, int cmd, int addr, void *buf, int len)
266 usb_device_request_t req;
274 if (cmd == CUE_CMD_READSRAM)
275 req.bmRequestType = UT_READ_VENDOR_DEVICE;
277 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
279 USETW(req.wValue, 0);
280 USETW(req.wIndex, addr);
281 USETW(req.wLength, len);
283 err = usbd_do_request(sc->cue_udev, &req, buf);
294 cue_getmac(struct cue_softc *sc, void *buf)
296 usb_device_request_t req;
304 req.bmRequestType = UT_READ_VENDOR_DEVICE;
305 req.bRequest = CUE_CMD_GET_MACADDR;
306 USETW(req.wValue, 0);
307 USETW(req.wIndex, 0);
308 USETW(req.wLength, ETHER_ADDR_LEN);
310 err = usbd_do_request(sc->cue_udev, &req, buf);
315 if_printf(&sc->arpcom.ac_if, "read MAC address failed\n");
325 cue_setmulti(struct cue_softc *sc)
328 struct ifmultiaddr *ifma;
331 ifp = &sc->arpcom.ac_if;
333 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
334 for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
335 sc->cue_mctab[i] = 0xFF;
336 cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
337 &sc->cue_mctab, CUE_MCAST_TABLE_LEN);
341 /* first, zot all the existing hash bits */
342 for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
343 sc->cue_mctab[i] = 0;
345 /* now program new ones */
346 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
347 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
349 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
352 if (ifma->ifma_addr->sa_family != AF_LINK)
355 LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
356 ETHER_ADDR_LEN) & ((1 << CUE_BITS) - 1);
357 sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
361 * Also include the broadcast address in the filter
362 * so we can receive broadcast frames.
364 if (ifp->if_flags & IFF_BROADCAST) {
365 h = ether_crc32_le(ifp->if_broadcastaddr, ETHER_ADDR_LEN) &
366 ((1 << CUE_BITS) - 1);
367 sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);
370 cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
371 &sc->cue_mctab, CUE_MCAST_TABLE_LEN);
377 cue_reset(struct cue_softc *sc)
379 usb_device_request_t req;
385 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
386 req.bRequest = CUE_CMD_RESET;
387 USETW(req.wValue, 0);
388 USETW(req.wIndex, 0);
389 USETW(req.wLength, 0);
390 err = usbd_do_request(sc->cue_udev, &req, NULL);
392 if_printf(&sc->arpcom.ac_if, "reset failed\n");
394 /* Wait a little while for the chip to get its brains in order. */
400 * Probe for a Pegasus chip.
404 USB_MATCH_START(cue, uaa);
412 if (uaa->vendor == t->cue_vid &&
413 uaa->product == t->cue_did) {
414 return(UMATCH_VENDOR_PRODUCT);
423 * Attach the interface. Allocate softc structures, do ifmedia
424 * setup and ethernet/BPF attach.
428 USB_ATTACH_START(cue, sc, uaa);
430 u_char eaddr[ETHER_ADDR_LEN];
432 usb_interface_descriptor_t *id;
433 usb_endpoint_descriptor_t *ed;
436 bzero(sc, sizeof(struct cue_softc));
437 sc->cue_iface = uaa->iface;
438 sc->cue_udev = uaa->device;
439 callout_init(&sc->cue_stat_timer);
441 if (usbd_set_config_no(sc->cue_udev, CUE_CONFIG_NO, 0)) {
442 device_printf(self, "setting config no %d failed\n",
444 USB_ATTACH_ERROR_RETURN;
447 id = usbd_get_interface_descriptor(uaa->iface);
449 usbd_devinfo(uaa->device, 0, devinfo);
450 device_set_desc_copy(self, devinfo);
451 device_printf(self, "%s\n", devinfo);
453 /* Find endpoints. */
454 for (i = 0; i < id->bNumEndpoints; i++) {
455 ed = usbd_interface2endpoint_descriptor(uaa->iface, i);
457 device_printf(self, "couldn't get ep %d\n", i);
458 USB_ATTACH_ERROR_RETURN;
460 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
461 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
462 sc->cue_ed[CUE_ENDPT_RX] = ed->bEndpointAddress;
463 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
464 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
465 sc->cue_ed[CUE_ENDPT_TX] = ed->bEndpointAddress;
466 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
467 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
468 sc->cue_ed[CUE_ENDPT_INTR] = ed->bEndpointAddress;
472 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
473 mtx_init(&sc->cue_mtx, device_get_nameunit(self), MTX_NETWORK_LOCK,
474 MTX_DEF | MTX_RECURSE);
478 ifp = &sc->arpcom.ac_if;
479 if_initname(ifp, device_get_name(self), device_get_unit(self));
482 /* Reset the adapter. */
486 * Get station address.
488 cue_getmac(sc, &eaddr);
491 ifp->if_mtu = ETHERMTU;
492 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
493 ifp->if_ioctl = cue_ioctl;
494 ifp->if_start = cue_start;
495 ifp->if_watchdog = cue_watchdog;
496 ifp->if_init = cue_init;
497 ifp->if_baudrate = 10000000;
498 ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
499 ifq_set_ready(&ifp->if_snd);
502 * Call MI attach routine.
504 ether_ifattach(ifp, eaddr);
505 usb_register_netisr();
509 USB_ATTACH_SUCCESS_RETURN;
513 cue_detach(device_ptr_t dev)
515 struct cue_softc *sc;
518 sc = device_get_softc(dev);
520 ifp = &sc->arpcom.ac_if;
523 callout_stop(&sc->cue_stat_timer);
526 if (sc->cue_ep[CUE_ENDPT_TX] != NULL)
527 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
528 if (sc->cue_ep[CUE_ENDPT_RX] != NULL)
529 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
530 if (sc->cue_ep[CUE_ENDPT_INTR] != NULL)
531 usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
534 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
535 mtx_destroy(&sc->cue_mtx);
542 * Initialize an RX descriptor and attach an MBUF cluster.
545 cue_newbuf(struct cue_softc *sc, struct cue_chain *c, struct mbuf *m)
547 struct mbuf *m_new = NULL;
550 MGETHDR(m_new, MB_DONTWAIT, MT_DATA);
552 if_printf(&sc->arpcom.ac_if, "no memory for rx list "
553 "-- packet dropped!\n");
557 MCLGET(m_new, MB_DONTWAIT);
558 if (!(m_new->m_flags & M_EXT)) {
559 if_printf(&sc->arpcom.ac_if, "no memory for rx list "
560 "-- packet dropped!\n");
564 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
567 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
568 m_new->m_data = m_new->m_ext.ext_buf;
571 m_adj(m_new, ETHER_ALIGN);
578 cue_rx_list_init(struct cue_softc *sc)
580 struct cue_cdata *cd;
585 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
586 c = &cd->cue_rx_chain[i];
589 if (cue_newbuf(sc, c, NULL) == ENOBUFS)
591 if (c->cue_xfer == NULL) {
592 c->cue_xfer = usbd_alloc_xfer(sc->cue_udev);
593 if (c->cue_xfer == NULL)
602 cue_tx_list_init(struct cue_softc *sc)
604 struct cue_cdata *cd;
609 for (i = 0; i < CUE_TX_LIST_CNT; i++) {
610 c = &cd->cue_tx_chain[i];
614 if (c->cue_xfer == NULL) {
615 c->cue_xfer = usbd_alloc_xfer(sc->cue_udev);
616 if (c->cue_xfer == NULL)
619 c->cue_buf = malloc(CUE_BUFSZ, M_USBDEV, M_WAITOK);
626 cue_rxstart(struct ifnet *ifp)
628 struct cue_softc *sc;
633 c = &sc->cue_cdata.cue_rx_chain[sc->cue_cdata.cue_rx_prod];
635 if (cue_newbuf(sc, c, NULL) == ENOBUFS) {
641 /* Setup new transfer. */
642 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
643 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ, USBD_SHORT_XFER_OK,
644 USBD_NO_TIMEOUT, cue_rxeof);
645 usbd_transfer(c->cue_xfer);
652 * A frame has been uploaded: pass the resulting mbuf chain up to
653 * the higher level protocols.
656 cue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
658 struct cue_softc *sc;
668 ifp = &sc->arpcom.ac_if;
670 if (!(ifp->if_flags & IFF_RUNNING)) {
675 if (status != USBD_NORMAL_COMPLETION) {
676 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
680 if (usbd_ratecheck(&sc->cue_rx_notice)) {
681 if_printf(ifp, "usb error on rx: %s\n",
682 usbd_errstr(status));
684 if (status == USBD_STALLED)
685 usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_RX]);
689 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
692 len = *mtod(m, u_int16_t *);
694 /* No errors; receive the packet. */
697 if (len < sizeof(struct ether_header)) {
703 m_adj(m, sizeof(u_int16_t));
704 m->m_pkthdr.rcvif = ifp;
705 m->m_pkthdr.len = m->m_len = total_len;
707 /* Put the packet on the special USB input queue. */
715 /* Setup new transfer. */
716 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
717 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ, USBD_SHORT_XFER_OK,
718 USBD_NO_TIMEOUT, cue_rxeof);
719 usbd_transfer(c->cue_xfer);
726 * A frame was downloaded to the chip. It's safe for us to clean up
731 cue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
733 struct cue_softc *sc;
741 ifp = &sc->arpcom.ac_if;
743 if (status != USBD_NORMAL_COMPLETION) {
744 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
748 if_printf(ifp, "usb error on tx: %s\n", usbd_errstr(status));
749 if (status == USBD_STALLED)
750 usbd_clear_endpoint_stall(sc->cue_ep[CUE_ENDPT_TX]);
756 ifp->if_flags &= ~IFF_OACTIVE;
757 usbd_get_xfer_status(c->cue_xfer, NULL, NULL, NULL, &err);
759 if (c->cue_mbuf != NULL) {
760 m_freem(c->cue_mbuf);
769 if (!ifq_is_empty(&ifp->if_snd))
770 (*ifp->if_start)(ifp);
780 struct cue_softc *sc;
790 ifp = &sc->arpcom.ac_if;
792 ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_SINGLECOLL);
793 ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_MULTICOLL);
794 ifp->if_collisions += cue_csr_read_2(sc, CUE_TX_EXCESSCOLL);
796 if (cue_csr_read_2(sc, CUE_RX_FRAMEERR))
799 callout_reset(&sc->cue_stat_timer, hz, cue_tick, sc);
807 cue_encap(struct cue_softc *sc, struct mbuf *m, int idx)
813 c = &sc->cue_cdata.cue_tx_chain[idx];
816 * Copy the mbuf data into a contiguous buffer, leaving two
817 * bytes at the beginning to hold the frame length.
819 m_copydata(m, 0, m->m_pkthdr.len, c->cue_buf + 2);
822 total_len = m->m_pkthdr.len + 2;
824 /* The first two bytes are the frame length */
825 c->cue_buf[0] = (u_int8_t)m->m_pkthdr.len;
826 c->cue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
828 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_TX],
829 c, c->cue_buf, total_len, 0, 10000, cue_txeof);
832 err = usbd_transfer(c->cue_xfer);
833 if (err != USBD_IN_PROGRESS) {
838 sc->cue_cdata.cue_tx_cnt++;
844 cue_start(struct ifnet *ifp)
846 struct cue_softc *sc;
847 struct mbuf *m_head = NULL;
852 if (ifp->if_flags & IFF_OACTIVE) {
857 m_head = ifq_poll(&ifp->if_snd);
858 if (m_head == NULL) {
863 if (cue_encap(sc, m_head, 0)) {
864 ifp->if_flags |= IFF_OACTIVE;
868 m_head = ifq_dequeue(&ifp->if_snd);
871 * If there's a BPF listener, bounce a copy of this frame
874 BPF_MTAP(ifp, m_head);
876 ifp->if_flags |= IFF_OACTIVE;
879 * Set a timeout in case the chip goes out to lunch.
890 struct cue_softc *sc = xsc;
891 struct ifnet *ifp = &sc->arpcom.ac_if;
896 if (ifp->if_flags & IFF_RUNNING)
902 * Cancel pending I/O and free all RX/TX buffers.
908 /* Set MAC address */
909 for (i = 0; i < ETHER_ADDR_LEN; i++)
910 cue_csr_write_1(sc, CUE_PAR0 - i, sc->arpcom.ac_enaddr[i]);
912 /* Enable RX logic. */
913 cue_csr_write_1(sc, CUE_ETHCTL, CUE_ETHCTL_RX_ON|CUE_ETHCTL_MCAST_ON);
915 /* If we want promiscuous mode, set the allframes bit. */
916 if (ifp->if_flags & IFF_PROMISC) {
917 CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
919 CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
923 if (cue_tx_list_init(sc) == ENOBUFS) {
924 if_printf(ifp, "tx list init failed\n");
930 if (cue_rx_list_init(sc) == ENOBUFS) {
931 if_printf(ifp, "rx list init failed\n");
936 /* Load the multicast filter. */
940 * Set the number of RX and TX buffers that we want
941 * to reserve inside the ASIC.
943 cue_csr_write_1(sc, CUE_RX_BUFPKTS, CUE_RX_FRAMES);
944 cue_csr_write_1(sc, CUE_TX_BUFPKTS, CUE_TX_FRAMES);
946 /* Set advanced operation modes. */
947 cue_csr_write_1(sc, CUE_ADVANCED_OPMODES,
948 CUE_AOP_EMBED_RXLEN|0x01); /* 1 wait state */
950 /* Program the LED operation. */
951 cue_csr_write_1(sc, CUE_LEDCTL, CUE_LEDCTL_FOLLOW_LINK);
953 /* Open RX and TX pipes. */
954 err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_RX],
955 USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_RX]);
957 if_printf(ifp, "open rx pipe failed: %s\n", usbd_errstr(err));
961 err = usbd_open_pipe(sc->cue_iface, sc->cue_ed[CUE_ENDPT_TX],
962 USBD_EXCLUSIVE_USE, &sc->cue_ep[CUE_ENDPT_TX]);
964 if_printf(ifp, "open tx pipe failed: %s\n", usbd_errstr(err));
969 /* Start up the receive pipe. */
970 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
971 c = &sc->cue_cdata.cue_rx_chain[i];
972 usbd_setup_xfer(c->cue_xfer, sc->cue_ep[CUE_ENDPT_RX],
973 c, mtod(c->cue_mbuf, char *), CUE_BUFSZ,
974 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, cue_rxeof);
975 usbd_transfer(c->cue_xfer);
978 ifp->if_flags |= IFF_RUNNING;
979 ifp->if_flags &= ~IFF_OACTIVE;
983 callout_reset(&sc->cue_stat_timer, hz, cue_tick, sc);
987 cue_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
989 struct cue_softc *sc = ifp->if_softc;
996 if (ifp->if_flags & IFF_UP) {
997 if (ifp->if_flags & IFF_RUNNING &&
998 ifp->if_flags & IFF_PROMISC &&
999 !(sc->cue_if_flags & IFF_PROMISC)) {
1000 CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
1002 } else if (ifp->if_flags & IFF_RUNNING &&
1003 !(ifp->if_flags & IFF_PROMISC) &&
1004 sc->cue_if_flags & IFF_PROMISC) {
1005 CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
1007 } else if (!(ifp->if_flags & IFF_RUNNING))
1010 if (ifp->if_flags & IFF_RUNNING)
1013 sc->cue_if_flags = ifp->if_flags;
1022 error = ether_ioctl(ifp, command, data);
1032 cue_watchdog(struct ifnet *ifp)
1034 struct cue_softc *sc;
1035 struct cue_chain *c;
1042 if_printf(ifp, "watchdog timeout\n");
1044 c = &sc->cue_cdata.cue_tx_chain[0];
1045 usbd_get_xfer_status(c->cue_xfer, NULL, NULL, NULL, &stat);
1046 cue_txeof(c->cue_xfer, c, stat);
1048 if (!ifq_is_empty(&ifp->if_snd))
1056 * Stop the adapter and free any mbufs allocated to the
1060 cue_stop(struct cue_softc *sc)
1068 ifp = &sc->arpcom.ac_if;
1071 cue_csr_write_1(sc, CUE_ETHCTL, 0);
1073 callout_stop(&sc->cue_stat_timer);
1075 /* Stop transfers. */
1076 if (sc->cue_ep[CUE_ENDPT_RX] != NULL) {
1077 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_RX]);
1079 if_printf(ifp, "abort rx pipe failed: %s\n",
1082 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_RX]);
1084 if_printf(ifp, "close rx pipe failed: %s\n",
1087 sc->cue_ep[CUE_ENDPT_RX] = NULL;
1090 if (sc->cue_ep[CUE_ENDPT_TX] != NULL) {
1091 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_TX]);
1093 if_printf(ifp, "abort tx pipe failed: %s\n",
1096 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_TX]);
1098 if_printf(ifp, "close tx pipe failed: %s\n",
1101 sc->cue_ep[CUE_ENDPT_TX] = NULL;
1104 if (sc->cue_ep[CUE_ENDPT_INTR] != NULL) {
1105 err = usbd_abort_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
1107 if_printf(ifp, "abort intr pipe failed: %s\n",
1110 err = usbd_close_pipe(sc->cue_ep[CUE_ENDPT_INTR]);
1112 if_printf(ifp, "close intr pipe failed: %s\n",
1115 sc->cue_ep[CUE_ENDPT_INTR] = NULL;
1118 /* Free RX resources. */
1119 for (i = 0; i < CUE_RX_LIST_CNT; i++) {
1120 if (sc->cue_cdata.cue_rx_chain[i].cue_buf != NULL) {
1121 free(sc->cue_cdata.cue_rx_chain[i].cue_buf, M_USBDEV);
1122 sc->cue_cdata.cue_rx_chain[i].cue_buf = NULL;
1124 if (sc->cue_cdata.cue_rx_chain[i].cue_mbuf != NULL) {
1125 m_freem(sc->cue_cdata.cue_rx_chain[i].cue_mbuf);
1126 sc->cue_cdata.cue_rx_chain[i].cue_mbuf = NULL;
1128 if (sc->cue_cdata.cue_rx_chain[i].cue_xfer != NULL) {
1129 usbd_free_xfer(sc->cue_cdata.cue_rx_chain[i].cue_xfer);
1130 sc->cue_cdata.cue_rx_chain[i].cue_xfer = NULL;
1134 /* Free TX resources. */
1135 for (i = 0; i < CUE_TX_LIST_CNT; i++) {
1136 if (sc->cue_cdata.cue_tx_chain[i].cue_buf != NULL) {
1137 free(sc->cue_cdata.cue_tx_chain[i].cue_buf, M_USBDEV);
1138 sc->cue_cdata.cue_tx_chain[i].cue_buf = NULL;
1140 if (sc->cue_cdata.cue_tx_chain[i].cue_mbuf != NULL) {
1141 m_freem(sc->cue_cdata.cue_tx_chain[i].cue_mbuf);
1142 sc->cue_cdata.cue_tx_chain[i].cue_mbuf = NULL;
1144 if (sc->cue_cdata.cue_tx_chain[i].cue_xfer != NULL) {
1145 usbd_free_xfer(sc->cue_cdata.cue_tx_chain[i].cue_xfer);
1146 sc->cue_cdata.cue_tx_chain[i].cue_xfer = NULL;
1150 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1157 * Stop all chip I/O so that the kernel's probe routines don't
1158 * get confused by errant DMAs when rebooting.
1161 cue_shutdown(device_ptr_t dev)
1163 struct cue_softc *sc;
1165 sc = device_get_softc(dev);