xref: /freebsd/sys/dev/usb/net/if_cue.c (revision 911f0260390e18cf85f3dbf2c719b593efdc1e3c)
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 	[CUE_BULK_DT_WR] = {
141 		.type = UE_BULK,
142 		.endpoint = UE_ADDR_ANY,
143 		.direction = UE_DIR_OUT,
144 		.bufsize = (MCLBYTES + 2),
145 		.flags = {.pipe_bof = 1,},
146 		.callback = cue_bulk_write_callback,
147 		.timeout = 10000,	/* 10 seconds */
148 	},
149 
150 	[CUE_BULK_DT_RD] = {
151 		.type = UE_BULK,
152 		.endpoint = UE_ADDR_ANY,
153 		.direction = UE_DIR_IN,
154 		.bufsize = (MCLBYTES + 2),
155 		.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
156 		.callback = cue_bulk_read_callback,
157 	},
158 };
159 
160 static device_method_t cue_methods[] = {
161 	/* Device interface */
162 	DEVMETHOD(device_probe, cue_probe),
163 	DEVMETHOD(device_attach, cue_attach),
164 	DEVMETHOD(device_detach, cue_detach),
165 
166 	DEVMETHOD_END
167 };
168 
169 static driver_t cue_driver = {
170 	.name = "cue",
171 	.methods = cue_methods,
172 	.size = sizeof(struct cue_softc),
173 };
174 
175 DRIVER_MODULE(cue, uhub, cue_driver, NULL, NULL);
176 MODULE_DEPEND(cue, uether, 1, 1, 1);
177 MODULE_DEPEND(cue, usb, 1, 1, 1);
178 MODULE_DEPEND(cue, ether, 1, 1, 1);
179 MODULE_VERSION(cue, 1);
180 USB_PNP_HOST_INFO(cue_devs);
181 
182 static const struct usb_ether_methods cue_ue_methods = {
183 	.ue_attach_post = cue_attach_post,
184 	.ue_start = cue_start,
185 	.ue_init = cue_init,
186 	.ue_stop = cue_stop,
187 	.ue_tick = cue_tick,
188 	.ue_setmulti = cue_setmulti,
189 	.ue_setpromisc = cue_setpromisc,
190 };
191 
192 #define	CUE_SETBIT(sc, reg, x)				\
193 	cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) | (x))
194 
195 #define	CUE_CLRBIT(sc, reg, x)				\
196 	cue_csr_write_1(sc, reg, cue_csr_read_1(sc, reg) & ~(x))
197 
198 static uint8_t
199 cue_csr_read_1(struct cue_softc *sc, uint16_t reg)
200 {
201 	struct usb_device_request req;
202 	uint8_t val;
203 
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, 1);
209 
210 	if (uether_do_request(&sc->sc_ue, &req, &val, 1000)) {
211 		/* ignore any errors */
212 	}
213 	return (val);
214 }
215 
216 static uint16_t
217 cue_csr_read_2(struct cue_softc *sc, uint8_t reg)
218 {
219 	struct usb_device_request req;
220 	uint16_t val;
221 
222 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
223 	req.bRequest = CUE_CMD_READREG;
224 	USETW(req.wValue, 0);
225 	USETW(req.wIndex, reg);
226 	USETW(req.wLength, 2);
227 
228 	(void)uether_do_request(&sc->sc_ue, &req, &val, 1000);
229 	return (le16toh(val));
230 }
231 
232 static int
233 cue_csr_write_1(struct cue_softc *sc, uint16_t reg, uint16_t val)
234 {
235 	struct usb_device_request req;
236 
237 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
238 	req.bRequest = CUE_CMD_WRITEREG;
239 	USETW(req.wValue, val);
240 	USETW(req.wIndex, reg);
241 	USETW(req.wLength, 0);
242 
243 	return (uether_do_request(&sc->sc_ue, &req, NULL, 1000));
244 }
245 
246 static int
247 cue_mem(struct cue_softc *sc, uint8_t cmd, uint16_t addr, void *buf, int len)
248 {
249 	struct usb_device_request req;
250 
251 	if (cmd == CUE_CMD_READSRAM)
252 		req.bmRequestType = UT_READ_VENDOR_DEVICE;
253 	else
254 		req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
255 	req.bRequest = cmd;
256 	USETW(req.wValue, 0);
257 	USETW(req.wIndex, addr);
258 	USETW(req.wLength, len);
259 
260 	return (uether_do_request(&sc->sc_ue, &req, buf, 1000));
261 }
262 
263 static int
264 cue_getmac(struct cue_softc *sc, void *buf)
265 {
266 	struct usb_device_request req;
267 
268 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
269 	req.bRequest = CUE_CMD_GET_MACADDR;
270 	USETW(req.wValue, 0);
271 	USETW(req.wIndex, 0);
272 	USETW(req.wLength, ETHER_ADDR_LEN);
273 
274 	return (uether_do_request(&sc->sc_ue, &req, buf, 1000));
275 }
276 
277 #define	CUE_BITS 9
278 
279 static uint32_t
280 cue_mchash(const uint8_t *addr)
281 {
282 	uint32_t crc;
283 
284 	/* Compute CRC for the address value. */
285 	crc = ether_crc32_le(addr, ETHER_ADDR_LEN);
286 
287 	return (crc & ((1 << CUE_BITS) - 1));
288 }
289 
290 static void
291 cue_setpromisc(struct usb_ether *ue)
292 {
293 	struct cue_softc *sc = uether_getsc(ue);
294 	if_t ifp = uether_getifp(ue);
295 
296 	CUE_LOCK_ASSERT(sc, MA_OWNED);
297 
298 	/* if we want promiscuous mode, set the allframes bit */
299 	if (if_getflags(ifp) & IFF_PROMISC)
300 		CUE_SETBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
301 	else
302 		CUE_CLRBIT(sc, CUE_ETHCTL, CUE_ETHCTL_PROMISC);
303 
304 	/* write multicast hash-bits */
305 	cue_setmulti(ue);
306 }
307 
308 static u_int
309 cue_hash_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt)
310 {
311 	uint8_t *hashtbl = arg;
312 	uint32_t h;
313 
314 	h = cue_mchash(LLADDR(sdl));
315 	hashtbl[h >> 3] |= 1 << (h & 0x7);
316 
317 	return (1);
318 }
319 
320 static void
321 cue_setmulti(struct usb_ether *ue)
322 {
323 	struct cue_softc *sc = uether_getsc(ue);
324 	if_t ifp = uether_getifp(ue);
325 	uint32_t h, i;
326 	uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
327 
328 	CUE_LOCK_ASSERT(sc, MA_OWNED);
329 
330 	if (if_getflags(ifp) & IFF_ALLMULTI || if_getflags(ifp) & IFF_PROMISC) {
331 		for (i = 0; i < 8; i++)
332 			hashtbl[i] = 0xff;
333 		cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
334 		    &hashtbl, 8);
335 		return;
336 	}
337 
338 	/* now program new ones */
339 	if_foreach_llmaddr(ifp, cue_hash_maddr, hashtbl);
340 
341 	/*
342 	 * Also include the broadcast address in the filter
343 	 * so we can receive broadcast frames.
344  	 */
345 	if (if_getflags(ifp) & IFF_BROADCAST) {
346 		h = cue_mchash(if_getbroadcastaddr(ifp));
347 		hashtbl[h >> 3] |= 1 << (h & 0x7);
348 	}
349 
350 	cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR, &hashtbl, 8);
351 }
352 
353 static void
354 cue_reset(struct cue_softc *sc)
355 {
356 	struct usb_device_request req;
357 
358 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
359 	req.bRequest = CUE_CMD_RESET;
360 	USETW(req.wValue, 0);
361 	USETW(req.wIndex, 0);
362 	USETW(req.wLength, 0);
363 
364 	if (uether_do_request(&sc->sc_ue, &req, NULL, 1000)) {
365 		/* ignore any errors */
366 	}
367 
368 	/*
369 	 * wait a little while for the chip to get its brains in order:
370 	 */
371 	uether_pause(&sc->sc_ue, hz / 100);
372 }
373 
374 static void
375 cue_attach_post(struct usb_ether *ue)
376 {
377 	struct cue_softc *sc = uether_getsc(ue);
378 
379 	cue_getmac(sc, ue->ue_eaddr);
380 }
381 
382 static int
383 cue_probe(device_t dev)
384 {
385 	struct usb_attach_arg *uaa = device_get_ivars(dev);
386 
387 	if (uaa->usb_mode != USB_MODE_HOST)
388 		return (ENXIO);
389 	if (uaa->info.bConfigIndex != CUE_CONFIG_IDX)
390 		return (ENXIO);
391 	if (uaa->info.bIfaceIndex != CUE_IFACE_IDX)
392 		return (ENXIO);
393 
394 	return (usbd_lookup_id_by_uaa(cue_devs, sizeof(cue_devs), uaa));
395 }
396 
397 /*
398  * Attach the interface. Allocate softc structures, do ifmedia
399  * setup and ethernet/BPF attach.
400  */
401 static int
402 cue_attach(device_t dev)
403 {
404 	struct usb_attach_arg *uaa = device_get_ivars(dev);
405 	struct cue_softc *sc = device_get_softc(dev);
406 	struct usb_ether *ue = &sc->sc_ue;
407 	uint8_t iface_index;
408 	int error;
409 
410 	device_set_usb_desc(dev);
411 	mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF);
412 
413 	iface_index = CUE_IFACE_IDX;
414 	error = usbd_transfer_setup(uaa->device, &iface_index,
415 	    sc->sc_xfer, cue_config, CUE_N_TRANSFER, sc, &sc->sc_mtx);
416 	if (error) {
417 		device_printf(dev, "allocating USB transfers failed\n");
418 		goto detach;
419 	}
420 
421 	ue->ue_sc = sc;
422 	ue->ue_dev = dev;
423 	ue->ue_udev = uaa->device;
424 	ue->ue_mtx = &sc->sc_mtx;
425 	ue->ue_methods = &cue_ue_methods;
426 
427 	error = uether_ifattach(ue);
428 	if (error) {
429 		device_printf(dev, "could not attach interface\n");
430 		goto detach;
431 	}
432 	return (0);			/* success */
433 
434 detach:
435 	cue_detach(dev);
436 	return (ENXIO);			/* failure */
437 }
438 
439 static int
440 cue_detach(device_t dev)
441 {
442 	struct cue_softc *sc = device_get_softc(dev);
443 	struct usb_ether *ue = &sc->sc_ue;
444 
445 	usbd_transfer_unsetup(sc->sc_xfer, CUE_N_TRANSFER);
446 	uether_ifdetach(ue);
447 	mtx_destroy(&sc->sc_mtx);
448 
449 	return (0);
450 }
451 
452 static void
453 cue_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
454 {
455 	struct cue_softc *sc = usbd_xfer_softc(xfer);
456 	struct usb_ether *ue = &sc->sc_ue;
457 	if_t ifp = uether_getifp(ue);
458 	struct usb_page_cache *pc;
459 	uint8_t buf[2];
460 	int len;
461 	int actlen;
462 
463 	usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
464 
465 	switch (USB_GET_STATE(xfer)) {
466 	case USB_ST_TRANSFERRED:
467 
468 		if (actlen <= (int)(2 + sizeof(struct ether_header))) {
469 			if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
470 			goto tr_setup;
471 		}
472 		pc = usbd_xfer_get_frame(xfer, 0);
473 		usbd_copy_out(pc, 0, buf, 2);
474 		actlen -= 2;
475 		len = buf[0] | (buf[1] << 8);
476 		len = min(actlen, len);
477 
478 		uether_rxbuf(ue, pc, 2, len);
479 		/* FALLTHROUGH */
480 	case USB_ST_SETUP:
481 tr_setup:
482 		usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
483 		usbd_transfer_submit(xfer);
484 		uether_rxflush(ue);
485 		return;
486 
487 	default:			/* Error */
488 		DPRINTF("bulk read error, %s\n",
489 		    usbd_errstr(error));
490 
491 		if (error != USB_ERR_CANCELLED) {
492 			/* try to clear stall first */
493 			usbd_xfer_set_stall(xfer);
494 			goto tr_setup;
495 		}
496 		return;
497 	}
498 }
499 
500 static void
501 cue_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
502 {
503 	struct cue_softc *sc = usbd_xfer_softc(xfer);
504 	if_t ifp = uether_getifp(&sc->sc_ue);
505 	struct usb_page_cache *pc;
506 	struct mbuf *m;
507 	uint8_t buf[2];
508 
509 	switch (USB_GET_STATE(xfer)) {
510 	case USB_ST_TRANSFERRED:
511 		DPRINTFN(11, "transfer complete\n");
512 		if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
513 
514 		/* FALLTHROUGH */
515 	case USB_ST_SETUP:
516 tr_setup:
517 		m = if_dequeue(ifp);
518 
519 		if (m == NULL)
520 			return;
521 		if (m->m_pkthdr.len > MCLBYTES)
522 			m->m_pkthdr.len = MCLBYTES;
523 		usbd_xfer_set_frame_len(xfer, 0, (m->m_pkthdr.len + 2));
524 
525 		/* the first two bytes are the frame length */
526 
527 		buf[0] = (uint8_t)(m->m_pkthdr.len);
528 		buf[1] = (uint8_t)(m->m_pkthdr.len >> 8);
529 
530 		pc = usbd_xfer_get_frame(xfer, 0);
531 		usbd_copy_in(pc, 0, buf, 2);
532 		usbd_m_copy_in(pc, 2, m, 0, m->m_pkthdr.len);
533 
534 		/*
535 		 * If there's a BPF listener, bounce a copy of this frame
536 		 * to him.
537 		 */
538 		BPF_MTAP(ifp, m);
539 
540 		m_freem(m);
541 
542 		usbd_transfer_submit(xfer);
543 
544 		return;
545 
546 	default:			/* Error */
547 		DPRINTFN(11, "transfer error, %s\n",
548 		    usbd_errstr(error));
549 
550 		if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
551 
552 		if (error != USB_ERR_CANCELLED) {
553 			/* try to clear stall first */
554 			usbd_xfer_set_stall(xfer);
555 			goto tr_setup;
556 		}
557 		return;
558 	}
559 }
560 
561 static void
562 cue_tick(struct usb_ether *ue)
563 {
564 	struct cue_softc *sc = uether_getsc(ue);
565 	if_t ifp = uether_getifp(ue);
566 
567 	CUE_LOCK_ASSERT(sc, MA_OWNED);
568 
569 	if_inc_counter(ifp, IFCOUNTER_COLLISIONS, cue_csr_read_2(sc, CUE_TX_SINGLECOLL));
570 	if_inc_counter(ifp, IFCOUNTER_COLLISIONS, cue_csr_read_2(sc, CUE_TX_MULTICOLL));
571 	if_inc_counter(ifp, IFCOUNTER_COLLISIONS, cue_csr_read_2(sc, CUE_TX_EXCESSCOLL));
572 
573 	if (cue_csr_read_2(sc, CUE_RX_FRAMEERR))
574 		if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
575 }
576 
577 static void
578 cue_start(struct usb_ether *ue)
579 {
580 	struct cue_softc *sc = uether_getsc(ue);
581 
582 	/*
583 	 * start the USB transfers, if not already started:
584 	 */
585 	usbd_transfer_start(sc->sc_xfer[CUE_BULK_DT_RD]);
586 	usbd_transfer_start(sc->sc_xfer[CUE_BULK_DT_WR]);
587 }
588 
589 static void
590 cue_init(struct usb_ether *ue)
591 {
592 	struct cue_softc *sc = uether_getsc(ue);
593 	if_t ifp = uether_getifp(ue);
594 	int i;
595 
596 	CUE_LOCK_ASSERT(sc, MA_OWNED);
597 
598 	/*
599 	 * Cancel pending I/O and free all RX/TX buffers.
600 	 */
601 	cue_stop(ue);
602 #if 0
603 	cue_reset(sc);
604 #endif
605 	/* Set MAC address */
606 	for (i = 0; i < ETHER_ADDR_LEN; i++)
607 		cue_csr_write_1(sc, CUE_PAR0 - i, if_getlladdr(ifp)[i]);
608 
609 	/* Enable RX logic. */
610 	cue_csr_write_1(sc, CUE_ETHCTL, CUE_ETHCTL_RX_ON | CUE_ETHCTL_MCAST_ON);
611 
612 	/* Load the multicast filter */
613 	cue_setpromisc(ue);
614 
615 	/*
616 	 * Set the number of RX and TX buffers that we want
617 	 * to reserve inside the ASIC.
618 	 */
619 	cue_csr_write_1(sc, CUE_RX_BUFPKTS, CUE_RX_FRAMES);
620 	cue_csr_write_1(sc, CUE_TX_BUFPKTS, CUE_TX_FRAMES);
621 
622 	/* Set advanced operation modes. */
623 	cue_csr_write_1(sc, CUE_ADVANCED_OPMODES,
624 	    CUE_AOP_EMBED_RXLEN | 0x01);/* 1 wait state */
625 
626 	/* Program the LED operation. */
627 	cue_csr_write_1(sc, CUE_LEDCTL, CUE_LEDCTL_FOLLOW_LINK);
628 
629 	usbd_xfer_set_stall(sc->sc_xfer[CUE_BULK_DT_WR]);
630 
631 	if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0);
632 	cue_start(ue);
633 }
634 
635 /*
636  * Stop the adapter and free any mbufs allocated to the
637  * RX and TX lists.
638  */
639 static void
640 cue_stop(struct usb_ether *ue)
641 {
642 	struct cue_softc *sc = uether_getsc(ue);
643 	if_t ifp = uether_getifp(ue);
644 
645 	CUE_LOCK_ASSERT(sc, MA_OWNED);
646 
647 	if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING);
648 
649 	/*
650 	 * stop all the transfers, if not already stopped:
651 	 */
652 	usbd_transfer_stop(sc->sc_xfer[CUE_BULK_DT_WR]);
653 	usbd_transfer_stop(sc->sc_xfer[CUE_BULK_DT_RD]);
654 
655 	cue_csr_write_1(sc, CUE_ETHCTL, 0);
656 	cue_reset(sc);
657 }
658