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