xref: /dragonfly/sys/bus/u4b/net/if_cue.c (revision 2b3f93ea6d1f70880f3e87f3c2cbe0dc0bfc9332)
1 /*-
2  * Copyright (c) 1997, 1998, 1999, 2000
3  *        Bill Paul <wpaul@ee.columbia.edu>.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
19  *
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.
31  *
32  * $FreeBSD: head/sys/dev/usb/net/if_cue.c 271832 2014-09-18 21:09:22Z glebius $
33  */
34 
35 /*
36  * CATC USB-EL1210A USB to ethernet driver. Used in the CATC Netmate
37  * adapters and others.
38  *
39  * Written by Bill Paul <wpaul@ee.columbia.edu>
40  * Electrical Engineering Department
41  * Columbia University, New York City
42  */
43 
44 /*
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.
51  */
52 
53 #include <sys/stdint.h>
54 #include <sys/param.h>
55 #include <sys/queue.h>
56 #include <sys/types.h>
57 #include <sys/systm.h>
58 #include <sys/socket.h>
59 #include <sys/kernel.h>
60 #include <sys/bus.h>
61 #include <sys/module.h>
62 #include <sys/lock.h>
63 #include <sys/condvar.h>
64 #include <sys/sysctl.h>
65 #include <sys/unistd.h>
66 #include <sys/callout.h>
67 #include <sys/malloc.h>
68 #include <sys/caps.h>
69 
70 #include <net/if.h>
71 #include <net/if_var.h>
72 #include <net/ifq_var.h>
73 
74 #include <bus/u4b/usb.h>
75 #include <bus/u4b/usbdi.h>
76 #include <bus/u4b/usbdi_util.h>
77 #include "usbdevs.h"
78 
79 #define   USB_DEBUG_VAR cue_debug
80 #include <bus/u4b/usb_debug.h>
81 #include <bus/u4b/usb_process.h>
82 
83 #include <bus/u4b/net/usb_ethernet.h>
84 #include <bus/u4b/net/if_cuereg.h>
85 
86 /*
87  * Various supported device vendors/products.
88  */
89 
90 /* Belkin F5U111 adapter covered by NETMATE entry */
91 
92 static const STRUCT_USB_HOST_ID cue_devs[] = {
93 #define   CUE_DEV(v,p) { USB_VP(USB_VENDOR_##v, USB_PRODUCT_##v##_##p) }
94           CUE_DEV(CATC, NETMATE),
95           CUE_DEV(CATC, NETMATE2),
96           CUE_DEV(SMARTBRIDGES, SMARTLINK),
97 #undef CUE_DEV
98 };
99 
100 /* prototypes */
101 
102 static device_probe_t cue_probe;
103 static device_attach_t cue_attach;
104 static device_detach_t cue_detach;
105 
106 static usb_callback_t cue_bulk_read_callback;
107 static usb_callback_t cue_bulk_write_callback;
108 
109 static uether_fn_t cue_attach_post;
110 static uether_fn_t cue_init;
111 static uether_fn_t cue_stop;
112 static uether_fn_t cue_start;
113 static uether_fn_t cue_tick;
114 static uether_fn_t cue_setmulti;
115 static uether_fn_t cue_setpromisc;
116 
117 static uint8_t      cue_csr_read_1(struct cue_softc *, uint16_t);
118 static uint16_t     cue_csr_read_2(struct cue_softc *, uint8_t);
119 static int          cue_csr_write_1(struct cue_softc *, uint16_t, uint16_t);
120 static int          cue_mem(struct cue_softc *, uint8_t, uint16_t, void *, int);
121 static int          cue_getmac(struct cue_softc *, void *);
122 static uint32_t     cue_mchash(const uint8_t *);
123 static void         cue_reset(struct cue_softc *);
124 
125 #ifdef USB_DEBUG
126 static int cue_debug = 0;
127 
128 static SYSCTL_NODE(_hw_usb, OID_AUTO, cue, CTLFLAG_RW, 0, "USB cue");
129 SYSCTL_INT(_hw_usb_cue, OID_AUTO, debug, CTLFLAG_RW, &cue_debug, 0,
130     "Debug level");
131 #endif
132 
133 static const struct usb_config cue_config[CUE_N_TRANSFER] = {
134 
135           [CUE_BULK_DT_WR] = {
136                     .type = UE_BULK,
137                     .endpoint = UE_ADDR_ANY,
138                     .direction = UE_DIR_OUT,
139                     .bufsize = (MCLBYTES + 2),
140                     .flags = {.pipe_bof = 1,},
141                     .callback = cue_bulk_write_callback,
142                     .timeout = 10000,   /* 10 seconds */
143           },
144 
145           [CUE_BULK_DT_RD] = {
146                     .type = UE_BULK,
147                     .endpoint = UE_ADDR_ANY,
148                     .direction = UE_DIR_IN,
149                     .bufsize = (MCLBYTES + 2),
150                     .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
151                     .callback = cue_bulk_read_callback,
152           },
153 };
154 
155 static device_method_t cue_methods[] = {
156           /* Device interface */
157           DEVMETHOD(device_probe, cue_probe),
158           DEVMETHOD(device_attach, cue_attach),
159           DEVMETHOD(device_detach, cue_detach),
160 
161           DEVMETHOD_END
162 };
163 
164 static driver_t cue_driver = {
165           .name = "cue",
166           .methods = cue_methods,
167           .size = sizeof(struct cue_softc),
168 };
169 
170 static devclass_t cue_devclass;
171 
172 DRIVER_MODULE(cue, uhub, cue_driver, cue_devclass, NULL, NULL);
173 MODULE_DEPEND(cue, uether, 1, 1, 1);
174 MODULE_DEPEND(cue, usb, 1, 1, 1);
175 MODULE_DEPEND(cue, ether, 1, 1, 1);
176 MODULE_VERSION(cue, 1);
177 
178 static const struct usb_ether_methods cue_ue_methods = {
179           .ue_attach_post = cue_attach_post,
180           .ue_start = cue_start,
181           .ue_init = cue_init,
182           .ue_stop = cue_stop,
183           .ue_tick = cue_tick,
184           .ue_setmulti = cue_setmulti,
185           .ue_setpromisc = cue_setpromisc,
186 };
187 
188 #define   CUE_SETBIT(sc, reg, x)                                      \
189           cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) | (x))
190 
191 #define   CUE_CLRBIT(sc, reg, x)                                      \
192           cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) & ~(x))
193 
194 static uint8_t
cue_csr_read_1(struct cue_softc * sc,uint16_t reg)195 cue_csr_read_1(struct cue_softc *sc, uint16_t reg)
196 {
197           struct usb_device_request req;
198           uint8_t val;
199 
200           req.bmRequestType = UT_READ_VENDOR_DEVICE;
201           req.bRequest = CUE_CMD_READREG;
202           USETW(req.wValue, 0);
203           USETW(req.wIndex, reg);
204           USETW(req.wLength, 1);
205 
206           if (uether_do_request(&sc->sc_ue, &req, &val, 1000)) {
207                     /* ignore any errors */
208           }
209           return (val);
210 }
211 
212 static uint16_t
cue_csr_read_2(struct cue_softc * sc,uint8_t reg)213 cue_csr_read_2(struct cue_softc *sc, uint8_t reg)
214 {
215           struct usb_device_request req;
216           uint16_t val;
217 
218           req.bmRequestType = UT_READ_VENDOR_DEVICE;
219           req.bRequest = CUE_CMD_READREG;
220           USETW(req.wValue, 0);
221           USETW(req.wIndex, reg);
222           USETW(req.wLength, 2);
223 
224           (void)uether_do_request(&sc->sc_ue, &req, &val, 1000);
225           return (le16toh(val));
226 }
227 
228 static int
cue_csr_write_1(struct cue_softc * sc,uint16_t reg,uint16_t val)229 cue_csr_write_1(struct cue_softc *sc, uint16_t reg, uint16_t val)
230 {
231           struct usb_device_request req;
232 
233           req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
234           req.bRequest = CUE_CMD_WRITEREG;
235           USETW(req.wValue, val);
236           USETW(req.wIndex, reg);
237           USETW(req.wLength, 0);
238 
239           return (uether_do_request(&sc->sc_ue, &req, NULL, 1000));
240 }
241 
242 static int
cue_mem(struct cue_softc * sc,uint8_t cmd,uint16_t addr,void * buf,int len)243 cue_mem(struct cue_softc *sc, uint8_t cmd, uint16_t addr, void *buf, int len)
244 {
245           struct usb_device_request req;
246 
247           if (cmd == CUE_CMD_READSRAM)
248                     req.bmRequestType = UT_READ_VENDOR_DEVICE;
249           else
250                     req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
251           req.bRequest = cmd;
252           USETW(req.wValue, 0);
253           USETW(req.wIndex, addr);
254           USETW(req.wLength, len);
255 
256           return (uether_do_request(&sc->sc_ue, &req, buf, 1000));
257 }
258 
259 static int
cue_getmac(struct cue_softc * sc,void * buf)260 cue_getmac(struct cue_softc *sc, void *buf)
261 {
262           struct usb_device_request req;
263 
264           req.bmRequestType = UT_READ_VENDOR_DEVICE;
265           req.bRequest = CUE_CMD_GET_MACADDR;
266           USETW(req.wValue, 0);
267           USETW(req.wIndex, 0);
268           USETW(req.wLength, ETHER_ADDR_LEN);
269 
270           return (uether_do_request(&sc->sc_ue, &req, buf, 1000));
271 }
272 
273 #define   CUE_BITS 9
274 
275 static uint32_t
cue_mchash(const uint8_t * addr)276 cue_mchash(const uint8_t *addr)
277 {
278           uint32_t crc;
279 
280           /* Compute CRC for the address value. */
281           crc = ether_crc32_le(addr, ETHER_ADDR_LEN);
282 
283           return (crc & ((1 << CUE_BITS) - 1));
284 }
285 
286 static void
cue_setpromisc(struct usb_ether * ue)287 cue_setpromisc(struct usb_ether *ue)
288 {
289           struct cue_softc *sc = uether_getsc(ue);
290           struct ifnet *ifp = uether_getifp(ue);
291 
292           CUE_LOCK_ASSERT(sc);
293 
294           /* if we want promiscuous mode, set the allframes bit */
295           if (ifp->if_flags & IFF_PROMISC)
296                     CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
297           else
298                     CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
299 
300           /* write multicast hash-bits */
301           cue_setmulti(ue);
302 }
303 
304 static void
cue_setmulti(struct usb_ether * ue)305 cue_setmulti(struct usb_ether *ue)
306 {
307           struct cue_softc *sc = uether_getsc(ue);
308           struct ifnet *ifp = uether_getifp(ue);
309           struct ifmultiaddr *ifma;
310           uint32_t h = 0, i;
311           uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
312 
313           CUE_LOCK_ASSERT(sc);
314 
315           if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
316                     for (i = 0; i < 8; i++)
317                               hashtbl[i] = 0xff;
318                     cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
319                         &hashtbl, 8);
320                     return;
321           }
322 
323           /* now program new ones */
324           TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
325           {
326                     if (ifma->ifma_addr->sa_family != AF_LINK)
327                               continue;
328                     h = cue_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
329                     hashtbl[h >> 3] |= 1 << (h & 0x7);
330           }
331 
332           /*
333            * Also include the broadcast address in the filter
334            * so we can receive broadcast frames.
335            */
336           if (ifp->if_flags & IFF_BROADCAST) {
337                     h = cue_mchash(ifp->if_broadcastaddr);
338                     hashtbl[h >> 3] |= 1 << (h & 0x7);
339           }
340 
341           cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR, &hashtbl, 8);
342 }
343 
344 static void
cue_reset(struct cue_softc * sc)345 cue_reset(struct cue_softc *sc)
346 {
347           struct usb_device_request req;
348 
349           req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
350           req.bRequest = CUE_CMD_RESET;
351           USETW(req.wValue, 0);
352           USETW(req.wIndex, 0);
353           USETW(req.wLength, 0);
354 
355           if (uether_do_request(&sc->sc_ue, &req, NULL, 1000)) {
356                     /* ignore any errors */
357           }
358 
359           /*
360            * wait a little while for the chip to get its brains in order:
361            */
362           uether_pause(&sc->sc_ue, hz / 100);
363 }
364 
365 static void
cue_attach_post(struct usb_ether * ue)366 cue_attach_post(struct usb_ether *ue)
367 {
368           struct cue_softc *sc = uether_getsc(ue);
369 
370           cue_getmac(sc, ue->ue_eaddr);
371 }
372 
373 static int
cue_probe(device_t dev)374 cue_probe(device_t dev)
375 {
376           struct usb_attach_arg *uaa = device_get_ivars(dev);
377 
378           if (uaa->usb_mode != USB_MODE_HOST)
379                     return (ENXIO);
380           if (uaa->info.bConfigIndex != CUE_CONFIG_IDX)
381                     return (ENXIO);
382           if (uaa->info.bIfaceIndex != CUE_IFACE_IDX)
383                     return (ENXIO);
384 
385           return (usbd_lookup_id_by_uaa(cue_devs, sizeof(cue_devs), uaa));
386 }
387 
388 /*
389  * Attach the interface. Allocate softc structures, do ifmedia
390  * setup and ethernet/BPF attach.
391  */
392 static int
cue_attach(device_t dev)393 cue_attach(device_t dev)
394 {
395           struct usb_attach_arg *uaa = device_get_ivars(dev);
396           struct cue_softc *sc = device_get_softc(dev);
397           struct usb_ether *ue = &sc->sc_ue;
398           uint8_t iface_index;
399           int error;
400 
401           device_set_usb_desc(dev);
402           lockinit(&sc->sc_lock, device_get_nameunit(dev), 0, LK_CANRECURSE);
403 
404           iface_index = CUE_IFACE_IDX;
405           error = usbd_transfer_setup(uaa->device, &iface_index,
406               sc->sc_xfer, cue_config, CUE_N_TRANSFER, sc, &sc->sc_lock);
407           if (error) {
408                     device_printf(dev, "allocating USB transfers failed\n");
409                     goto detach;
410           }
411 
412           ue->ue_sc = sc;
413           ue->ue_dev = dev;
414           ue->ue_udev = uaa->device;
415           ue->ue_lock = &sc->sc_lock;
416           ue->ue_methods = &cue_ue_methods;
417 
418           error = uether_ifattach(ue);
419           if (error) {
420                     device_printf(dev, "could not attach interface\n");
421                     goto detach;
422           }
423           return (0);                             /* success */
424 
425 detach:
426           cue_detach(dev);
427           return (ENXIO);                         /* failure */
428 }
429 
430 static int
cue_detach(device_t dev)431 cue_detach(device_t dev)
432 {
433           struct cue_softc *sc = device_get_softc(dev);
434           struct usb_ether *ue = &sc->sc_ue;
435 
436           usbd_transfer_unsetup(sc->sc_xfer, CUE_N_TRANSFER);
437           uether_ifdetach(ue);
438           lockuninit(&sc->sc_lock);
439 
440           return (0);
441 }
442 
443 static void
cue_bulk_read_callback(struct usb_xfer * xfer,usb_error_t error)444 cue_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
445 {
446           struct cue_softc *sc = usbd_xfer_softc(xfer);
447           struct usb_ether *ue = &sc->sc_ue;
448           struct ifnet *ifp = uether_getifp(ue);
449           struct usb_page_cache *pc;
450           uint8_t buf[2];
451           int len;
452           int actlen;
453 
454           usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
455 
456           switch (USB_GET_STATE(xfer)) {
457           case USB_ST_TRANSFERRED:
458 
459                     if (actlen <= (int)(2 + sizeof(struct ether_header))) {
460                               IFNET_STAT_INC(ifp, ierrors, 1);
461                               goto tr_setup;
462                     }
463                     pc = usbd_xfer_get_frame(xfer, 0);
464                     usbd_copy_out(pc, 0, buf, 2);
465                     actlen -= 2;
466                     len = buf[0] | (buf[1] << 8);
467                     len = min(actlen, len);
468 
469                     uether_rxbuf(ue, pc, 2, len);
470                     /* FALLTHROUGH */
471           case USB_ST_SETUP:
472 tr_setup:
473                     usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
474                     usbd_transfer_submit(xfer);
475                     uether_rxflush(ue);
476                     return;
477 
478           default:                      /* Error */
479                     DPRINTF("bulk read error, %s\n",
480                         usbd_errstr(error));
481 
482                     if (error != USB_ERR_CANCELLED) {
483                               /* try to clear stall first */
484                               usbd_xfer_set_stall(xfer);
485                               goto tr_setup;
486                     }
487                     return;
488 
489           }
490 }
491 
492 static void
cue_bulk_write_callback(struct usb_xfer * xfer,usb_error_t error)493 cue_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
494 {
495           struct cue_softc *sc = usbd_xfer_softc(xfer);
496           struct ifnet *ifp = uether_getifp(&sc->sc_ue);
497           struct usb_page_cache *pc;
498           struct mbuf *m;
499           uint8_t buf[2];
500 
501           switch (USB_GET_STATE(xfer)) {
502           case USB_ST_TRANSFERRED:
503                     DPRINTFN(11, "transfer complete\n");
504                     IFNET_STAT_INC(ifp, opackets, 1);
505 
506                     /* FALLTHROUGH */
507           case USB_ST_SETUP:
508 tr_setup:
509                     m = ifq_dequeue(&ifp->if_snd);
510 
511                     if (m == NULL)
512                               return;
513                     if (m->m_pkthdr.len > MCLBYTES)
514                               m->m_pkthdr.len = MCLBYTES;
515                     usbd_xfer_set_frame_len(xfer, 0, (m->m_pkthdr.len + 2));
516 
517                     /* the first two bytes are the frame length */
518 
519                     buf[0] = (uint8_t)(m->m_pkthdr.len);
520                     buf[1] = (uint8_t)(m->m_pkthdr.len >> 8);
521 
522                     pc = usbd_xfer_get_frame(xfer, 0);
523                     usbd_copy_in(pc, 0, buf, 2);
524                     usbd_m_copy_in(pc, 2, m, 0, m->m_pkthdr.len);
525 
526                     /*
527                      * If there's a BPF listener, bounce a copy of this frame
528                      * to him.
529                      */
530                     BPF_MTAP(ifp, m);
531 
532                     m_freem(m);
533 
534                     usbd_transfer_submit(xfer);
535 
536                     return;
537 
538           default:                      /* Error */
539                     DPRINTFN(11, "transfer error, %s\n",
540                         usbd_errstr(error));
541 
542                     IFNET_STAT_INC(ifp, oerrors, 1);
543 
544                     if (error != USB_ERR_CANCELLED) {
545                               /* try to clear stall first */
546                               usbd_xfer_set_stall(xfer);
547                               goto tr_setup;
548                     }
549                     return;
550           }
551 }
552 
553 static void
cue_tick(struct usb_ether * ue)554 cue_tick(struct usb_ether *ue)
555 {
556           struct cue_softc *sc = uether_getsc(ue);
557           struct ifnet *ifp = uether_getifp(ue);
558 
559           CUE_LOCK_ASSERT(sc);
560 
561           IFNET_STAT_INC(ifp, collisions, cue_csr_read_2(sc, CUE_TX_SINGLECOLL));
562           IFNET_STAT_INC(ifp, collisions, cue_csr_read_2(sc, CUE_TX_MULTICOLL));
563           IFNET_STAT_INC(ifp, collisions, cue_csr_read_2(sc, CUE_TX_EXCESSCOLL));
564 
565           if (cue_csr_read_2(sc, CUE_RX_FRAMEERR))
566                     IFNET_STAT_INC(ifp, ierrors, 1);
567 }
568 
569 static void
cue_start(struct usb_ether * ue)570 cue_start(struct usb_ether *ue)
571 {
572           struct cue_softc *sc = uether_getsc(ue);
573 
574           /*
575            * start the USB transfers, if not already started:
576            */
577           usbd_transfer_start(sc->sc_xfer[CUE_BULK_DT_RD]);
578           usbd_transfer_start(sc->sc_xfer[CUE_BULK_DT_WR]);
579 }
580 
581 static void
cue_init(struct usb_ether * ue)582 cue_init(struct usb_ether *ue)
583 {
584           struct cue_softc *sc = uether_getsc(ue);
585           struct ifnet *ifp = uether_getifp(ue);
586           int i;
587 
588           CUE_LOCK_ASSERT(sc);
589 
590           /*
591            * Cancel pending I/O and free all RX/TX buffers.
592            */
593           cue_stop(ue);
594 #if 0
595           cue_reset(sc);
596 #endif
597           /* Set MAC address */
598           for (i = 0; i < ETHER_ADDR_LEN; i++)
599                     cue_csr_write_1(sc, CUE_PAR0 - i, IF_LLADDR(ifp)[i]);
600 
601           /* Enable RX logic. */
602           cue_csr_write_1(sc, CUE_ETHCTL, CUE_ETHCTL_RX_ON | CUE_ETHCTL_MCAST_ON);
603 
604           /* Load the multicast filter */
605           cue_setpromisc(ue);
606 
607           /*
608            * Set the number of RX and TX buffers that we want
609            * to reserve inside the ASIC.
610            */
611           cue_csr_write_1(sc, CUE_RX_BUFPKTS, CUE_RX_FRAMES);
612           cue_csr_write_1(sc, CUE_TX_BUFPKTS, CUE_TX_FRAMES);
613 
614           /* Set advanced operation modes. */
615           cue_csr_write_1(sc, CUE_ADVANCED_OPMODES,
616               CUE_AOP_EMBED_RXLEN | 0x01);/* 1 wait state */
617 
618           /* Program the LED operation. */
619           cue_csr_write_1(sc, CUE_LEDCTL, CUE_LEDCTL_FOLLOW_LINK);
620 
621           usbd_xfer_set_stall(sc->sc_xfer[CUE_BULK_DT_WR]);
622 
623           ifp->if_flags |= IFF_RUNNING;
624           cue_start(ue);
625 }
626 
627 /*
628  * Stop the adapter and free any mbufs allocated to the
629  * RX and TX lists.
630  */
631 static void
cue_stop(struct usb_ether * ue)632 cue_stop(struct usb_ether *ue)
633 {
634           struct cue_softc *sc = uether_getsc(ue);
635           struct ifnet *ifp = uether_getifp(ue);
636 
637           CUE_LOCK_ASSERT(sc);
638 
639           ifp->if_flags &= ~IFF_RUNNING;
640 
641           /*
642            * stop all the transfers, if not already stopped:
643            */
644           usbd_transfer_stop(sc->sc_xfer[CUE_BULK_DT_WR]);
645           usbd_transfer_stop(sc->sc_xfer[CUE_BULK_DT_RD]);
646 
647           cue_csr_write_1(sc, CUE_ETHCTL, 0);
648           cue_reset(sc);
649 }
650