FreeBSD kernel usb device Code
if_cdce.c
Go to the documentation of this file.
1/* $NetBSD: if_cdce.c,v 1.4 2004/10/24 12:50:54 augustss Exp $ */
2
3/*-
4 * SPDX-License-Identifier: BSD-4-Clause
5 *
6 * Copyright (c) 1997, 1998, 1999, 2000-2003 Bill Paul <wpaul@windriver.com>
7 * Copyright (c) 2003-2005 Craig Boston
8 * Copyright (c) 2004 Daniel Hartmeier
9 * Copyright (c) 2009 Hans Petter Selasky
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by Bill Paul.
23 * 4. Neither the name of the author nor the names of any co-contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul, THE VOICES IN HIS HEAD OR
31 * THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
34 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
36 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 */
39
40/*
41 * USB Communication Device Class (Ethernet Networking Control Model)
42 * http://www.usb.org/developers/devclass_docs/usbcdc11.pdf
43 */
44
45/*
46 * USB Network Control Model (NCM)
47 * http://www.usb.org/developers/devclass_docs/NCM10.zip
48 */
49
50#include <sys/cdefs.h>
51__FBSDID("$FreeBSD$");
52
53#include <sys/gsb_crc32.h>
54#include <sys/eventhandler.h>
55#include <sys/stdint.h>
56#include <sys/stddef.h>
57#include <sys/queue.h>
58#include <sys/systm.h>
59#include <sys/socket.h>
60#include <sys/kernel.h>
61#include <sys/bus.h>
62#include <sys/module.h>
63#include <sys/lock.h>
64#include <sys/mutex.h>
65#include <sys/condvar.h>
66#include <sys/sysctl.h>
67#include <sys/sx.h>
68#include <sys/unistd.h>
69#include <sys/callout.h>
70#include <sys/malloc.h>
71#include <sys/priv.h>
72
73#include <net/if.h>
74#include <net/if_var.h>
75
76#include <dev/usb/usb.h>
77#include <dev/usb/usbdi.h>
78#include <dev/usb/usbdi_util.h>
79#include <dev/usb/usb_cdc.h>
80#include "usbdevs.h"
81
82#define USB_DEBUG_VAR cdce_debug
83#include <dev/usb/usb_debug.h>
84#include <dev/usb/usb_process.h>
85#include <dev/usb/usb_msctest.h>
86#include "usb_if.h"
87
90
91static device_probe_t cdce_probe;
92static device_attach_t cdce_attach;
93static device_detach_t cdce_detach;
94static device_suspend_t cdce_suspend;
95static device_resume_t cdce_resume;
96static usb_handle_request_t cdce_handle_request;
97
102
103#if CDCE_HAVE_NCM
104static usb_callback_t cdce_ncm_bulk_write_callback;
105static usb_callback_t cdce_ncm_bulk_read_callback;
106#endif
107
114static int cdce_attach_post_sub(struct usb_ether *);
115static int cdce_ioctl(struct ifnet *, u_long, caddr_t);
116static int cdce_media_change_cb(struct ifnet *);
117static void cdce_media_status_cb(struct ifnet *, struct ifmediareq *);
118
119static uint32_t cdce_m_crc32(struct mbuf *, uint32_t, uint32_t);
120static void cdce_set_filter(struct usb_ether *);
121
122#ifdef USB_DEBUG
123static int cdce_debug = 0;
124static int cdce_tx_interval = 0;
125
126static SYSCTL_NODE(_hw_usb, OID_AUTO, cdce, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
127 "USB CDC-Ethernet");
128SYSCTL_INT(_hw_usb_cdce, OID_AUTO, debug, CTLFLAG_RWTUN, &cdce_debug, 0,
129 "Debug level");
130SYSCTL_INT(_hw_usb_cdce, OID_AUTO, interval, CTLFLAG_RWTUN, &cdce_tx_interval, 0,
131 "NCM transmit interval in ms");
132#else
133#define cdce_debug 0
134#endif
135
136static const struct usb_config cdce_config[CDCE_N_TRANSFER] = {
137 [CDCE_BULK_RX] = {
138 .type = UE_BULK,
139 .endpoint = UE_ADDR_ANY,
140 .direction = UE_DIR_RX,
141 .if_index = 0,
142 .frames = CDCE_FRAMES_MAX,
143 .bufsize = (CDCE_FRAMES_MAX * MCLBYTES),
144 .flags = {.pipe_bof = 1,.short_frames_ok = 1,.short_xfer_ok = 1,.ext_buffer = 1,},
145 .callback = cdce_bulk_read_callback,
146 .timeout = 0, /* no timeout */
147 .usb_mode = USB_MODE_DUAL, /* both modes */
148 },
149
150 [CDCE_BULK_TX] = {
151 .type = UE_BULK,
152 .endpoint = UE_ADDR_ANY,
153 .direction = UE_DIR_TX,
154 .if_index = 0,
155 .frames = CDCE_FRAMES_MAX,
156 .bufsize = (CDCE_FRAMES_MAX * MCLBYTES),
157 .flags = {.pipe_bof = 1,.force_short_xfer = 1,.ext_buffer = 1,},
158 .callback = cdce_bulk_write_callback,
159 .timeout = 10000, /* 10 seconds */
160 .usb_mode = USB_MODE_DUAL, /* both modes */
161 },
162
163 [CDCE_INTR_RX] = {
164 .type = UE_INTERRUPT,
165 .endpoint = UE_ADDR_ANY,
166 .direction = UE_DIR_RX,
167 .if_index = 1,
168 .bufsize = CDCE_IND_SIZE_MAX,
169 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,.no_pipe_ok = 1,},
170 .callback = cdce_intr_read_callback,
171 .timeout = 0,
172 .usb_mode = USB_MODE_HOST,
173 },
174
175 [CDCE_INTR_TX] = {
176 .type = UE_INTERRUPT,
177 .endpoint = UE_ADDR_ANY,
178 .direction = UE_DIR_TX,
179 .if_index = 1,
180 .bufsize = CDCE_IND_SIZE_MAX,
181 .flags = {.pipe_bof = 1,.force_short_xfer = 1,.no_pipe_ok = 1,},
182 .callback = cdce_intr_write_callback,
183 .timeout = 10000, /* 10 seconds */
184 .usb_mode = USB_MODE_DEVICE,
185 },
186};
187
188#if CDCE_HAVE_NCM
189static const struct usb_config cdce_ncm_config[CDCE_N_TRANSFER] = {
190 [CDCE_BULK_RX] = {
191 .type = UE_BULK,
192 .endpoint = UE_ADDR_ANY,
193 .direction = UE_DIR_RX,
194 .if_index = 0,
195 .frames = CDCE_NCM_RX_FRAMES_MAX,
197 .flags = {.pipe_bof = 1,.short_frames_ok = 1,.short_xfer_ok = 1,},
198 .callback = cdce_ncm_bulk_read_callback,
199 .timeout = 0, /* no timeout */
200 .usb_mode = USB_MODE_DUAL, /* both modes */
201 },
202
203 [CDCE_BULK_TX] = {
204 .type = UE_BULK,
205 .endpoint = UE_ADDR_ANY,
206 .direction = UE_DIR_TX,
207 .if_index = 0,
208 .frames = CDCE_NCM_TX_FRAMES_MAX,
210 .flags = {.pipe_bof = 1,},
211 .callback = cdce_ncm_bulk_write_callback,
212 .timeout = 10000, /* 10 seconds */
213 .usb_mode = USB_MODE_DUAL, /* both modes */
214 },
215
216 [CDCE_INTR_RX] = {
217 .type = UE_INTERRUPT,
218 .endpoint = UE_ADDR_ANY,
219 .direction = UE_DIR_RX,
220 .if_index = 1,
221 .bufsize = CDCE_IND_SIZE_MAX,
222 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,.no_pipe_ok = 1,},
223 .callback = cdce_intr_read_callback,
224 .timeout = 0,
225 .usb_mode = USB_MODE_HOST,
226 },
227
228 [CDCE_INTR_TX] = {
229 .type = UE_INTERRUPT,
230 .endpoint = UE_ADDR_ANY,
231 .direction = UE_DIR_TX,
232 .if_index = 1,
233 .bufsize = CDCE_IND_SIZE_MAX,
234 .flags = {.pipe_bof = 1,.force_short_xfer = 1,.no_pipe_ok = 1,},
235 .callback = cdce_intr_write_callback,
236 .timeout = 10000, /* 10 seconds */
237 .usb_mode = USB_MODE_DEVICE,
238 },
239};
240#endif
241
242static device_method_t cdce_methods[] = {
243 /* USB interface */
245
246 /* Device interface */
247 DEVMETHOD(device_probe, cdce_probe),
248 DEVMETHOD(device_attach, cdce_attach),
249 DEVMETHOD(device_detach, cdce_detach),
250 DEVMETHOD(device_suspend, cdce_suspend),
251 DEVMETHOD(device_resume, cdce_resume),
252
253 DEVMETHOD_END
254};
255
256static driver_t cdce_driver = {
257 .name = "cdce",
258 .methods = cdce_methods,
259 .size = sizeof(struct cdce_softc),
260};
261
262static devclass_t cdce_devclass;
263static eventhandler_tag cdce_etag;
264
265static int cdce_driver_loaded(struct module *, int, void *);
266
268 {USB_VPI(USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E3272_INIT, MSC_EJECT_HUAWEI2)},
269};
270
272 {USB_VPI(USB_VENDOR_ACERLABS, USB_PRODUCT_ACERLABS_M5632, CDCE_FLAG_NO_UNION)},
273 {USB_VPI(USB_VENDOR_AMBIT, USB_PRODUCT_AMBIT_NTL_250, CDCE_FLAG_NO_UNION)},
274 {USB_VPI(USB_VENDOR_COMPAQ, USB_PRODUCT_COMPAQ_IPAQLINUX, CDCE_FLAG_NO_UNION)},
275 {USB_VPI(USB_VENDOR_GMATE, USB_PRODUCT_GMATE_YP3X00, CDCE_FLAG_NO_UNION)},
276 {USB_VPI(USB_VENDOR_MOTOROLA2, USB_PRODUCT_MOTOROLA2_USBLAN, CDCE_FLAG_ZAURUS | CDCE_FLAG_NO_UNION)},
277 {USB_VPI(USB_VENDOR_MOTOROLA2, USB_PRODUCT_MOTOROLA2_USBLAN2, CDCE_FLAG_ZAURUS | CDCE_FLAG_NO_UNION)},
278 {USB_VPI(USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2501, CDCE_FLAG_NO_UNION)},
279 {USB_VPI(USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SL5500, CDCE_FLAG_ZAURUS)},
280 {USB_VPI(USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SL5600, CDCE_FLAG_ZAURUS | CDCE_FLAG_NO_UNION)},
281 {USB_VPI(USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SLA300, CDCE_FLAG_ZAURUS | CDCE_FLAG_NO_UNION)},
282 {USB_VPI(USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SLC700, CDCE_FLAG_ZAURUS | CDCE_FLAG_NO_UNION)},
283 {USB_VPI(USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SLC750, CDCE_FLAG_ZAURUS | CDCE_FLAG_NO_UNION)},
284 {USB_VPI(USB_VENDOR_REALTEK, USB_PRODUCT_REALTEK_RTL8156, 0)},
285
286 {USB_VENDOR(USB_VENDOR_HUAWEI), USB_IFACE_CLASS(UICLASS_VENDOR),
288 USB_DRIVER_INFO(0)},
289 {USB_VENDOR(USB_VENDOR_HUAWEI), USB_IFACE_CLASS(UICLASS_VENDOR),
291 USB_DRIVER_INFO(0)},
292 {USB_VENDOR(USB_VENDOR_HUAWEI), USB_IFACE_CLASS(UICLASS_VENDOR),
294 USB_DRIVER_INFO(0)},
295 {USB_VENDOR(USB_VENDOR_HUAWEI), USB_IFACE_CLASS(UICLASS_VENDOR),
297 USB_DRIVER_INFO(0)},
298};
299
304};
305
308MODULE_DEPEND(cdce, uether, 1, 1, 1);
309MODULE_DEPEND(cdce, usb, 1, 1, 1);
310MODULE_DEPEND(cdce, ether, 1, 1, 1);
314
315static const struct usb_ether_methods cdce_ue_methods = {
317 .ue_attach_post_sub = cdce_attach_post_sub,
318 .ue_start = cdce_start,
319 .ue_init = cdce_init,
320 .ue_stop = cdce_stop,
321 .ue_setmulti = cdce_setmulti,
322 .ue_setpromisc = cdce_setpromisc,
323};
324
325#if CDCE_HAVE_NCM
326/*------------------------------------------------------------------------*
327 * cdce_ncm_init
328 *
329 * Return values:
330 * 0: Success
331 * Else: Failure
332 *------------------------------------------------------------------------*/
333static uint8_t
334cdce_ncm_init(struct cdce_softc *sc)
335{
336 struct usb_ncm_parameters temp;
337 struct usb_device_request req;
338 struct usb_ncm_func_descriptor *ufd;
339 uint8_t value[8];
340 int err;
341
342 ufd = usbd_find_descriptor(sc->sc_ue.ue_udev, NULL,
345
346 /* verify length of NCM functional descriptor */
347 if (ufd != NULL) {
348 if (ufd->bLength < sizeof(*ufd))
349 ufd = NULL;
350 else
351 DPRINTFN(1, "Found NCM functional descriptor.\n");
352 }
353
354 req.bmRequestType = UT_READ_CLASS_INTERFACE;
356 USETW(req.wValue, 0);
357 req.wIndex[0] = sc->sc_ifaces_index[1];
358 req.wIndex[1] = 0;
359 USETW(req.wLength, sizeof(temp));
360
361 err = usbd_do_request_flags(sc->sc_ue.ue_udev, NULL, &req,
362 &temp, 0, NULL, 1000 /* ms */);
363 if (err)
364 return (1);
365
366 /* Read correct set of parameters according to device mode */
367
369 sc->sc_ncm.rx_max = UGETDW(temp.dwNtbInMaxSize);
370 sc->sc_ncm.tx_max = UGETDW(temp.dwNtbOutMaxSize);
371 sc->sc_ncm.tx_remainder = UGETW(temp.wNdpOutPayloadRemainder);
372 sc->sc_ncm.tx_modulus = UGETW(temp.wNdpOutDivisor);
373 sc->sc_ncm.tx_struct_align = UGETW(temp.wNdpOutAlignment);
374 sc->sc_ncm.tx_nframe = UGETW(temp.wNtbOutMaxDatagrams);
375 } else {
376 sc->sc_ncm.rx_max = UGETDW(temp.dwNtbOutMaxSize);
377 sc->sc_ncm.tx_max = UGETDW(temp.dwNtbInMaxSize);
378 sc->sc_ncm.tx_remainder = UGETW(temp.wNdpInPayloadRemainder);
379 sc->sc_ncm.tx_modulus = UGETW(temp.wNdpInDivisor);
380 sc->sc_ncm.tx_struct_align = UGETW(temp.wNdpInAlignment);
381 sc->sc_ncm.tx_nframe = UGETW(temp.wNtbOutMaxDatagrams);
382 }
383
384 /* Verify maximum receive length */
385
386 if ((sc->sc_ncm.rx_max < 32) ||
388 DPRINTFN(1, "Using default maximum receive length\n");
390 }
391
392 /* Verify maximum transmit length */
393
394 if ((sc->sc_ncm.tx_max < 32) ||
396 DPRINTFN(1, "Using default maximum transmit length\n");
398 }
399
400 /*
401 * Verify that the structure alignment is:
402 * - power of two
403 * - not greater than the maximum transmit length
404 * - not less than four bytes
405 */
406 if ((sc->sc_ncm.tx_struct_align < 4) ||
407 (sc->sc_ncm.tx_struct_align !=
409 (sc->sc_ncm.tx_struct_align >= sc->sc_ncm.tx_max)) {
410 DPRINTFN(1, "Using default other alignment: 4 bytes\n");
411 sc->sc_ncm.tx_struct_align = 4;
412 }
413
414 /*
415 * Verify that the payload alignment is:
416 * - power of two
417 * - not greater than the maximum transmit length
418 * - not less than four bytes
419 */
420 if ((sc->sc_ncm.tx_modulus < 4) ||
421 (sc->sc_ncm.tx_modulus !=
422 ((-sc->sc_ncm.tx_modulus) & sc->sc_ncm.tx_modulus)) ||
423 (sc->sc_ncm.tx_modulus >= sc->sc_ncm.tx_max)) {
424 DPRINTFN(1, "Using default transmit modulus: 4 bytes\n");
425 sc->sc_ncm.tx_modulus = 4;
426 }
427
428 /* Verify that the payload remainder */
429
430 if ((sc->sc_ncm.tx_remainder >= sc->sc_ncm.tx_modulus)) {
431 DPRINTFN(1, "Using default transmit remainder: 0 bytes\n");
432 sc->sc_ncm.tx_remainder = 0;
433 }
434
435 /*
436 * Offset the TX remainder so that IP packet payload starts at
437 * the tx_modulus. This is not too clear in the specification.
438 */
439
440 sc->sc_ncm.tx_remainder =
441 (sc->sc_ncm.tx_remainder - ETHER_HDR_LEN) &
442 (sc->sc_ncm.tx_modulus - 1);
443
444 /* Verify max datagrams */
445
446 if (sc->sc_ncm.tx_nframe == 0 ||
448 DPRINTFN(1, "Using default max "
449 "subframes: %u units\n", CDCE_NCM_SUBFRAMES_MAX - 1);
450 /* need to reserve one entry for zero padding */
452 }
453
454 /* Additional configuration, will fail in device side mode, which is OK. */
455
456 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
458 USETW(req.wValue, 0);
459 req.wIndex[0] = sc->sc_ifaces_index[1];
460 req.wIndex[1] = 0;
461
462 if (ufd != NULL &&
464 USETW(req.wLength, 8);
465 USETDW(value, sc->sc_ncm.rx_max);
466 USETW(value + 4, (CDCE_NCM_SUBFRAMES_MAX - 1));
467 USETW(value + 6, 0);
468 } else {
469 USETW(req.wLength, 4);
470 USETDW(value, sc->sc_ncm.rx_max);
471 }
472
473 err = usbd_do_request_flags(sc->sc_ue.ue_udev, NULL, &req,
474 &value, 0, NULL, 1000 /* ms */);
475 if (err) {
476 DPRINTFN(1, "Setting input size "
477 "to %u failed.\n", sc->sc_ncm.rx_max);
478 }
479
480 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
481 req.bRequest = UCDC_NCM_SET_CRC_MODE;
482 USETW(req.wValue, 0); /* no CRC */
483 req.wIndex[0] = sc->sc_ifaces_index[1];
484 req.wIndex[1] = 0;
485 USETW(req.wLength, 0);
486
487 err = usbd_do_request_flags(sc->sc_ue.ue_udev, NULL, &req,
488 NULL, 0, NULL, 1000 /* ms */);
489 if (err) {
490 DPRINTFN(1, "Setting CRC mode to off failed.\n");
491 }
492
493 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
494 req.bRequest = UCDC_NCM_SET_NTB_FORMAT;
495 USETW(req.wValue, 0); /* NTB-16 */
496 req.wIndex[0] = sc->sc_ifaces_index[1];
497 req.wIndex[1] = 0;
498 USETW(req.wLength, 0);
499
500 err = usbd_do_request_flags(sc->sc_ue.ue_udev, NULL, &req,
501 NULL, 0, NULL, 1000 /* ms */);
502 if (err) {
503 DPRINTFN(1, "Setting NTB format to 16-bit failed.\n");
504 }
505
506 return (0); /* success */
507}
508#endif
509
510static void
511cdce_test_autoinst(void *arg, struct usb_device *udev,
512 struct usb_attach_arg *uaa)
513{
514 struct usb_interface *iface;
516
517 if (uaa->dev_state != UAA_DEV_READY)
518 return;
519
520 iface = usbd_get_iface(udev, 0);
521 if (iface == NULL)
522 return;
523 id = iface->idesc;
524 if (id == NULL || id->bInterfaceClass != UICLASS_MASS)
525 return;
527 return; /* no device match */
528
529 if (usb_msc_eject(udev, 0, USB_GET_DRIVER_INFO(uaa)) == 0) {
530 /* success, mark the udev as disappearing */
532 }
533}
534
535static int
536cdce_driver_loaded(struct module *mod, int what, void *arg)
537{
538 switch (what) {
539 case MOD_LOAD:
540 /* register our autoinstall handler */
541 cdce_etag = EVENTHANDLER_REGISTER(usb_dev_configured,
542 cdce_test_autoinst, NULL, EVENTHANDLER_PRI_ANY);
543 return (0);
544 case MOD_UNLOAD:
545 EVENTHANDLER_DEREGISTER(usb_dev_configured, cdce_etag);
546 return (0);
547 default:
548 return (EOPNOTSUPP);
549 }
550}
551
552static int
553cdce_probe(device_t dev)
554{
555 struct usb_attach_arg *uaa = device_get_ivars(dev);
556 int error;
557
559 if (error)
561 return (error);
562}
563
564static void
566{
567 /* no-op */
568 return;
569}
570
571static int
573{
574 struct cdce_softc *sc = uether_getsc(ue);
575 struct ifnet *ifp = uether_getifp(ue);
576
577 /* mostly copied from usb_ethernet.c */
578 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
579 ifp->if_start = uether_start;
580 ifp->if_ioctl = cdce_ioctl;
581 ifp->if_init = uether_init;
582 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
583 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
584 IFQ_SET_READY(&ifp->if_snd);
585
587 if_setcapabilitiesbit(ifp, IFCAP_VLAN_MTU, 0);
588
589 if_setcapabilitiesbit(ifp, IFCAP_LINKSTATE, 0);
590 if_setcapenable(ifp, if_getcapabilities(ifp));
591
592 ifmedia_init(&sc->sc_media, IFM_IMASK, cdce_media_change_cb,
594 ifmedia_add(&sc->sc_media, IFM_ETHER | IFM_AUTO, 0, NULL);
595 ifmedia_set(&sc->sc_media, IFM_ETHER | IFM_AUTO);
596 sc->sc_media.ifm_media = sc->sc_media.ifm_cur->ifm_media;
597 CDCE_LOCK(sc);
598 cdce_set_filter(ue);
599 CDCE_UNLOCK(sc);
600
601 return 0;
602}
603
604static int
605cdce_attach(device_t dev)
606{
607 struct cdce_softc *sc = device_get_softc(dev);
608 struct usb_ether *ue = &sc->sc_ue;
609 struct usb_attach_arg *uaa = device_get_ivars(dev);
610 struct usb_interface *iface;
611 const struct usb_cdc_union_descriptor *ud;
612 const struct usb_interface_descriptor *id;
613 const struct usb_cdc_ethernet_descriptor *ued;
614 const struct usb_config *pcfg;
615 uint32_t seed;
616 int error;
617 uint8_t i;
618 uint8_t data_iface_no;
619 char eaddr_str[5 * ETHER_ADDR_LEN]; /* approx */
620
621 sc->sc_flags = USB_GET_DRIVER_INFO(uaa);
622 sc->sc_ue.ue_udev = uaa->device;
623
625
626 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF);
627
629 (uaa->device, NULL, uaa->info.bIfaceIndex,
631
632 if ((ud == NULL) || (ud->bLength < sizeof(*ud)) ||
634 DPRINTFN(1, "No union descriptor!\n");
635 sc->sc_ifaces_index[0] = uaa->info.bIfaceIndex;
636 sc->sc_ifaces_index[1] = uaa->info.bIfaceIndex;
637 goto alloc_transfers;
638 }
639 data_iface_no = ud->bSlaveInterface[0];
640
641 for (i = 0;; i++) {
642 iface = usbd_get_iface(uaa->device, i);
643
644 if (iface) {
646
647 if (id && (id->bInterfaceNumber == data_iface_no)) {
648 sc->sc_ifaces_index[0] = i;
649 sc->sc_ifaces_index[1] = uaa->info.bIfaceIndex;
651 break;
652 }
653 } else {
654 device_printf(dev, "no data interface found\n");
655 goto detach;
656 }
657 }
658
659 /*
660 * <quote>
661 *
662 * The Data Class interface of a networking device shall have
663 * a minimum of two interface settings. The first setting
664 * (the default interface setting) includes no endpoints and
665 * therefore no networking traffic is exchanged whenever the
666 * default interface setting is selected. One or more
667 * additional interface settings are used for normal
668 * operation, and therefore each includes a pair of endpoints
669 * (one IN, and one OUT) to exchange network traffic. Select
670 * an alternate interface setting to initialize the network
671 * aspects of the device and to enable the exchange of
672 * network traffic.
673 *
674 * </quote>
675 *
676 * Some devices, most notably cable modems, include interface
677 * settings that have no IN or OUT endpoint, therefore loop
678 * through the list of all available interface settings
679 * looking for one with both IN and OUT endpoints.
680 */
681
682alloc_transfers:
683
684 pcfg = cdce_config; /* Default Configuration */
685
686 for (i = 0; i != 32; i++) {
688 sc->sc_ifaces_index[0], i);
689 if (error)
690 break;
691#if CDCE_HAVE_NCM
692 if ((i == 0) && (cdce_ncm_init(sc) == 0))
693 pcfg = cdce_ncm_config;
694#endif
696 sc->sc_ifaces_index, sc->sc_xfer,
697 pcfg, CDCE_N_TRANSFER, sc, &sc->sc_mtx);
698
699 if (error == 0)
700 break;
701 }
702
703 if (error || (i == 32)) {
704 device_printf(dev, "No valid alternate "
705 "setting found\n");
706 goto detach;
707 }
708
710 (uaa->device, NULL, uaa->info.bIfaceIndex,
712
713 if ((ued == NULL) || (ued->bLength < sizeof(*ued))) {
715 } else {
716 /*
717 * ECM 1.2 doesn't say it excludes the CRC, but states that it's
718 * normally 1514, which excludes the CRC.
719 */
720 DPRINTF("max segsize: %d\n", UGETW(ued->wMaxSegmentSize));
721 if (UGETW(ued->wMaxSegmentSize) >= (ETHER_MAX_LEN - ETHER_CRC_LEN + ETHER_VLAN_ENCAP_LEN))
723
725 eaddr_str, sizeof(eaddr_str), ued->iMacAddress);
726 }
727
728 if (error) {
729 /* fake MAC address */
730
731 device_printf(dev, "faking MAC address\n");
732 seed = ticks;
733 sc->sc_ue.ue_eaddr[0] = 0x2a;
734 memcpy(&sc->sc_ue.ue_eaddr[1], &seed, sizeof(uint32_t));
735 sc->sc_ue.ue_eaddr[5] = device_get_unit(dev);
736
737 } else {
738 memset(sc->sc_ue.ue_eaddr, 0, sizeof(sc->sc_ue.ue_eaddr));
739
740 for (i = 0; i != (ETHER_ADDR_LEN * 2); i++) {
741 char c = eaddr_str[i];
742
743 if ('0' <= c && c <= '9')
744 c -= '0';
745 else if (c != 0)
746 c -= 'A' - 10;
747 else
748 break;
749
750 c &= 0xf;
751
752 if ((i & 1) == 0)
753 c <<= 4;
754 sc->sc_ue.ue_eaddr[i / 2] |= c;
755 }
756
757 if (uaa->usb_mode == USB_MODE_DEVICE) {
758 /*
759 * Do not use the same MAC address like the peer !
760 */
761 sc->sc_ue.ue_eaddr[5] ^= 0xFF;
762 }
763 }
764
765 ue->ue_sc = sc;
766 ue->ue_dev = dev;
767 ue->ue_udev = uaa->device;
768 ue->ue_mtx = &sc->sc_mtx;
770
772 if (error) {
773 device_printf(dev, "could not attach interface\n");
774 goto detach;
775 }
776 return (0); /* success */
777
778detach:
780 return (ENXIO); /* failure */
781}
782
783static int
784cdce_detach(device_t dev)
785{
786 struct cdce_softc *sc = device_get_softc(dev);
787 struct usb_ether *ue = &sc->sc_ue;
788
789 /* stop all USB transfers first */
791 uether_ifdetach(ue);
792 mtx_destroy(&sc->sc_mtx);
793
794 ifmedia_removeall(&sc->sc_media);
795
796 return (0);
797}
798
799static void
801{
802 struct cdce_softc *sc = uether_getsc(ue);
803
804 /*
805 * Start the USB transfers, if not already started:
806 */
809}
810
811static int
812cdce_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
813{
814 struct usb_ether *ue = ifp->if_softc;
815 struct cdce_softc *sc = uether_getsc(ue);
816 struct ifreq *ifr = (struct ifreq *)data;
817 int error;
818
819 error = 0;
820
821 switch(command) {
822 case SIOCGIFMEDIA:
823 case SIOCSIFMEDIA:
824 error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, command);
825 break;
826 default:
827 error = uether_ioctl(ifp, command, data);
828 break;
829 }
830
831 return (error);
832}
833
834static void
835cdce_free_queue(struct mbuf **ppm, uint8_t n)
836{
837 uint8_t x;
838 for (x = 0; x != n; x++) {
839 if (ppm[x] != NULL) {
840 m_freem(ppm[x]);
841 ppm[x] = NULL;
842 }
843 }
844}
845
846static int
847cdce_media_change_cb(struct ifnet *ifp)
848{
849
850 return (EOPNOTSUPP);
851}
852
853static void
854cdce_media_status_cb(struct ifnet *ifp, struct ifmediareq *ifmr)
855{
856
857 if ((if_getflags(ifp) & IFF_UP) == 0)
858 return;
859
860 ifmr->ifm_active = IFM_ETHER;
861 ifmr->ifm_status = IFM_AVALID;
862 ifmr->ifm_status |=
863 ifp->if_link_state == LINK_STATE_UP ? IFM_ACTIVE : 0;
864}
865
866static void
868{
869 struct cdce_softc *sc = usbd_xfer_softc(xfer);
870 struct ifnet *ifp = uether_getifp(&sc->sc_ue);
871 struct mbuf *m;
872 struct mbuf *mt;
873 uint32_t crc;
874 uint8_t x;
875 int actlen, aframes;
876
877 usbd_xfer_status(xfer, &actlen, NULL, &aframes, NULL);
878
879 DPRINTFN(1, "\n");
880
881 switch (USB_GET_STATE(xfer)) {
883 DPRINTFN(11, "transfer complete: %u bytes in %u frames\n",
884 actlen, aframes);
885
886 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
887
888 /* free all previous TX buffers */
890
891 /* FALLTHROUGH */
892 case USB_ST_SETUP:
893tr_setup:
894 for (x = 0; x != CDCE_FRAMES_MAX; x++) {
895 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
896
897 if (m == NULL)
898 break;
899
900 if (sc->sc_flags & CDCE_FLAG_ZAURUS) {
901 /*
902 * Zaurus wants a 32-bit CRC appended
903 * to every frame
904 */
905
906 crc = cdce_m_crc32(m, 0, m->m_pkthdr.len);
907 crc = htole32(crc);
908
909 if (!m_append(m, 4, (void *)&crc)) {
910 m_freem(m);
911 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
912 continue;
913 }
914 }
915 if (m->m_len != m->m_pkthdr.len) {
916 mt = m_defrag(m, M_NOWAIT);
917 if (mt == NULL) {
918 m_freem(m);
919 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
920 continue;
921 }
922 m = mt;
923 }
924 if (m->m_pkthdr.len > MCLBYTES) {
925 m->m_pkthdr.len = MCLBYTES;
926 }
927 sc->sc_tx_buf[x] = m;
928 usbd_xfer_set_frame_data(xfer, x, m->m_data, m->m_len);
929
930 /*
931 * If there's a BPF listener, bounce a copy of
932 * this frame to him:
933 */
934 BPF_MTAP(ifp, m);
935 }
936 if (x != 0) {
937 usbd_xfer_set_frames(xfer, x);
938
940 }
941 break;
942
943 default: /* Error */
944 DPRINTFN(11, "transfer error, %s\n",
946
947 /* free all previous TX buffers */
949
950 /* count output errors */
951 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
952
953 if (error != USB_ERR_CANCELLED) {
955 /* try to clear stall first */
957 }
958 goto tr_setup;
959 }
960 break;
961 }
962}
963
964static int32_t
965cdce_m_crc32_cb(void *arg, void *src, uint32_t count)
966{
967 uint32_t *p_crc = arg;
968
969 *p_crc = crc32_raw(src, count, *p_crc);
970 return (0);
971}
972
973static uint32_t
974cdce_m_crc32(struct mbuf *m, uint32_t src_offset, uint32_t src_len)
975{
976 uint32_t crc = 0xFFFFFFFF;
977
978 (void)m_apply(m, src_offset, src_len, cdce_m_crc32_cb, &crc);
979 return (crc ^ 0xFFFFFFFF);
980}
981
982static void
984{
985 struct cdce_softc *sc = uether_getsc(ue);
986 struct ifnet *ifp = uether_getifp(ue);
987
988 CDCE_LOCK_ASSERT(sc, MA_OWNED);
989
990 ifp->if_drv_flags |= IFF_DRV_RUNNING;
991
992 /* start interrupt transfer */
995
996 /*
997 * Stall data write direction, which depends on USB mode.
998 *
999 * Some USB host stacks (e.g. Mac OS X) don't clears stall
1000 * bit as it should, so set it in our host mode only.
1001 */
1004
1005 /* start data transfers */
1006 cdce_start(ue);
1007}
1008
1009static void
1011{
1012 struct cdce_softc *sc = uether_getsc(ue);
1013 struct ifnet *ifp = uether_getifp(ue);
1014
1015 CDCE_LOCK_ASSERT(sc, MA_OWNED);
1016
1017 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
1018
1019 /*
1020 * stop all the transfers, if not already stopped:
1021 */
1026}
1027
1028static void
1030{
1031
1032 cdce_set_filter(ue);
1033}
1034
1035static void
1037{
1038
1039 cdce_set_filter(ue);
1040}
1041
1042static void
1044{
1045 struct cdce_softc *sc = uether_getsc(ue);
1046 struct ifnet *ifp = uether_getifp(ue);
1047 struct usb_device_request req;
1048 uint16_t value;
1049
1051 if (if_getflags(ifp) & IFF_PROMISC)
1053 if (if_getflags(ifp) & IFF_ALLMULTI)
1055
1056 req.bmRequestType = UT_CLASS | UT_INTERFACE;
1058 USETW(req.wValue, value);
1059 req.wIndex[0] = sc->sc_ifaces_index[1];
1060 req.wIndex[1] = 0;
1061 USETW(req.wLength, 0);
1062
1063 /*
1064 * Function below will drop the sc mutex.
1065 * We can do that since we're called from a separate task,
1066 * that simply wraps the setpromisc/setmulti methods.
1067 */
1068 usbd_do_request(sc->sc_ue.ue_udev, &sc->sc_mtx, &req, NULL);
1069}
1070
1071static int
1072cdce_suspend(device_t dev)
1073{
1074 device_printf(dev, "Suspending\n");
1075 return (0);
1076}
1077
1078static int
1079cdce_resume(device_t dev)
1080{
1081 device_printf(dev, "Resuming\n");
1082 return (0);
1083}
1084
1085static void
1087{
1088 struct cdce_softc *sc = usbd_xfer_softc(xfer);
1089 struct mbuf *m;
1090 uint8_t x;
1091 int actlen;
1092 int aframes;
1093 int len;
1094
1095 usbd_xfer_status(xfer, &actlen, NULL, &aframes, NULL);
1096
1097 switch (USB_GET_STATE(xfer)) {
1098 case USB_ST_TRANSFERRED:
1099
1100 DPRINTF("received %u bytes in %u frames\n", actlen, aframes);
1101
1102 for (x = 0; x != aframes; x++) {
1103 m = sc->sc_rx_buf[x];
1104 sc->sc_rx_buf[x] = NULL;
1105 len = usbd_xfer_frame_len(xfer, x);
1106
1107 /* Strip off CRC added by Zaurus, if any */
1108 if ((sc->sc_flags & CDCE_FLAG_ZAURUS) && len >= 14)
1109 len -= 4;
1110
1111 if (len < (int)sizeof(struct ether_header)) {
1112 m_freem(m);
1113 continue;
1114 }
1115 /* queue up mbuf */
1116 uether_rxmbuf(&sc->sc_ue, m, len);
1117 }
1118
1119 /* FALLTHROUGH */
1120 case USB_ST_SETUP:
1121 /*
1122 * TODO: Implement support for multi frame transfers,
1123 * when the USB hardware supports it.
1124 */
1125 for (x = 0; x != 1; x++) {
1126 if (sc->sc_rx_buf[x] == NULL) {
1127 m = uether_newbuf();
1128 if (m == NULL)
1129 goto tr_stall;
1130 sc->sc_rx_buf[x] = m;
1131 } else {
1132 m = sc->sc_rx_buf[x];
1133 }
1134
1135 usbd_xfer_set_frame_data(xfer, x, m->m_data, m->m_len);
1136 }
1137 /* set number of frames and start hardware */
1138 usbd_xfer_set_frames(xfer, x);
1140 /* flush any received frames */
1141 uether_rxflush(&sc->sc_ue);
1142 break;
1143
1144 default: /* Error */
1145 DPRINTF("error = %s\n",
1147
1148 if (error != USB_ERR_CANCELLED) {
1149tr_stall:
1151 /* try to clear stall first */
1152 usbd_xfer_set_stall(xfer);
1153 usbd_xfer_set_frames(xfer, 0);
1155 }
1156 break;
1157 }
1158
1159 /* need to free the RX-mbufs when we are cancelled */
1161 break;
1162 }
1163}
1164
1165static void
1167{
1168 u_char buf[CDCE_IND_SIZE_MAX];
1169 struct usb_cdc_notification ucn;
1170 struct cdce_softc *sc;
1171 struct ifnet *ifp;
1172 struct usb_page_cache *pc;
1173 int off, actlen;
1174 uint32_t downrate, uprate;
1175
1176 sc = usbd_xfer_softc(xfer);
1177 ifp = uether_getifp(&sc->sc_ue);
1178 pc = usbd_xfer_get_frame(xfer, 0);
1179
1180 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
1181
1182 switch (USB_GET_STATE(xfer)) {
1183 case USB_ST_TRANSFERRED:
1184 if (USB_DEBUG_VAR)
1185 usbd_copy_out(pc, 0, buf, MIN(actlen, sizeof buf));
1186 DPRINTF("Received %d bytes: %*D\n", actlen,
1187 (int)MIN(actlen, sizeof buf), buf, "");
1188
1189 off = 0;
1190 while (actlen - off >= UCDC_NOTIFICATION_LENGTH) {
1192
1193 do {
1194 if (ucn.bmRequestType != 0xa1)
1195 break;
1196
1197 switch (ucn.bNotification) {
1199 DPRINTF("changing link state: %d\n",
1200 UGETW(ucn.wValue));
1201 if_link_state_change(ifp,
1202 UGETW(ucn.wValue) ? LINK_STATE_UP :
1203 LINK_STATE_DOWN);
1204 break;
1205
1207 if (UGETW(ucn.wLength) != 8)
1208 break;
1209
1210 usbd_copy_out(pc, off +
1212 &ucn.data, UGETW(ucn.wLength));
1213 downrate = UGETDW(ucn.data);
1214 uprate = UGETDW(ucn.data);
1215 if (downrate != uprate)
1216 break;
1217
1218 /* set rate */
1219 DPRINTF("changing baudrate: %u\n",
1220 downrate);
1221 if_setbaudrate(ifp, downrate);
1222 break;
1223
1224 default:
1225 break;
1226 }
1227 } while (0);
1228
1230 }
1231
1232 /* FALLTHROUGH */
1233 case USB_ST_SETUP:
1234tr_setup:
1237 break;
1238
1239 default: /* Error */
1240 if (error != USB_ERR_CANCELLED) {
1241 /* start clear stall */
1243 usbd_xfer_set_stall(xfer);
1244 goto tr_setup;
1245 }
1246 break;
1247 }
1248}
1249
1250static void
1252{
1253 struct cdce_softc *sc = usbd_xfer_softc(xfer);
1255 struct usb_page_cache *pc;
1256 uint32_t speed;
1257 int actlen;
1258
1259 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
1260
1261 switch (USB_GET_STATE(xfer)) {
1262 case USB_ST_TRANSFERRED:
1263
1264 DPRINTF("Transferred %d bytes\n", actlen);
1265
1266 switch (sc->sc_notify_state) {
1269 break;
1272 break;
1273 default:
1274 break;
1275 }
1276
1277 /* FALLTHROUGH */
1278 case USB_ST_SETUP:
1279tr_setup:
1280 /*
1281 * Inform host about connection. Required according to USB CDC
1282 * specification and communicating to Mac OS X USB host stack.
1283 * Some of the values seems ignored by Mac OS X though.
1284 */
1286 req.bmRequestType = UCDC_NOTIFICATION;
1287 req.bNotification = UCDC_N_NETWORK_CONNECTION;
1288 req.wIndex[0] = sc->sc_ifaces_index[1];
1289 req.wIndex[1] = 0;
1290 USETW(req.wValue, 1); /* Connected */
1291 USETW(req.wLength, 0);
1292
1293 pc = usbd_xfer_get_frame(xfer, 0);
1294 usbd_copy_in(pc, 0, &req, sizeof(req));
1295 usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
1296 usbd_xfer_set_frames(xfer, 1);
1297 usbd_transfer_submit(xfer);
1298
1299 } else if (sc->sc_notify_state == CDCE_NOTIFY_SPEED_CHANGE) {
1300 req.bmRequestType = UCDC_NOTIFICATION;
1301 req.bNotification = UCDC_N_CONNECTION_SPEED_CHANGE;
1302 req.wIndex[0] = sc->sc_ifaces_index[1];
1303 req.wIndex[1] = 0;
1304 USETW(req.wValue, 0);
1305 USETW(req.wLength, 8);
1306
1307 /* Peak theoretical bulk trasfer rate in bits/s */
1309 speed = (13 * 512 * 8 * 1000 * 8);
1310 else
1311 speed = (19 * 64 * 1 * 1000 * 8);
1312
1313 USETDW(req.data + 0, speed); /* Upstream bit rate */
1314 USETDW(req.data + 4, speed); /* Downstream bit rate */
1315
1316 pc = usbd_xfer_get_frame(xfer, 0);
1317 usbd_copy_in(pc, 0, &req, sizeof(req));
1318 usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
1319 usbd_xfer_set_frames(xfer, 1);
1320 usbd_transfer_submit(xfer);
1321 }
1322 break;
1323
1324 default: /* Error */
1325 if (error != USB_ERR_CANCELLED) {
1327 /* start clear stall */
1328 usbd_xfer_set_stall(xfer);
1329 }
1330 goto tr_setup;
1331 }
1332 break;
1333 }
1334}
1335
1336static int
1338 const void *preq, void **pptr, uint16_t *plen,
1339 uint16_t offset, uint8_t *pstate)
1340{
1341 struct cdce_softc *sc = device_get_softc(dev);
1342 const struct usb_device_request *req = preq;
1343 uint8_t is_complete = *pstate;
1344
1345 /*
1346 * When Mac OS X resumes after suspending it expects
1347 * to be notified again after this request.
1348 */
1349 if (req->bmRequestType == UT_WRITE_CLASS_INTERFACE && \
1351 if (is_complete == 1) {
1352 mtx_lock(&sc->sc_mtx);
1355 mtx_unlock(&sc->sc_mtx);
1356 }
1357
1358 return (0);
1359 }
1360
1361 return (ENXIO); /* use builtin handler */
1362}
1363
1364#if CDCE_HAVE_NCM
1365static void
1366cdce_ncm_tx_zero(struct usb_page_cache *pc,
1367 uint32_t start, uint32_t end)
1368{
1369 if (start >= CDCE_NCM_TX_MAXLEN)
1370 return;
1371 if (end > CDCE_NCM_TX_MAXLEN)
1372 end = CDCE_NCM_TX_MAXLEN;
1373
1374 usbd_frame_zero(pc, start, end - start);
1375}
1376
1377static uint8_t
1378cdce_ncm_fill_tx_frames(struct usb_xfer *xfer, uint8_t index)
1379{
1380 struct cdce_softc *sc = usbd_xfer_softc(xfer);
1381 struct ifnet *ifp = uether_getifp(&sc->sc_ue);
1382 struct usb_page_cache *pc = usbd_xfer_get_frame(xfer, index);
1383 struct mbuf *m;
1384 uint32_t rem;
1385 uint32_t offset;
1386 uint32_t last_offset;
1387 uint16_t n;
1388 uint8_t retval;
1389
1390 usbd_xfer_set_frame_offset(xfer, index * CDCE_NCM_TX_MAXLEN, index);
1391
1392 offset = sizeof(sc->sc_ncm.hdr) +
1393 sizeof(sc->sc_ncm.dpt) + sizeof(sc->sc_ncm.dp);
1394
1395 /* Store last valid offset before alignment */
1396 last_offset = offset;
1397
1398 /* Align offset */
1400 offset, sc->sc_ncm.tx_modulus);
1401
1402 /* Zero pad */
1403 cdce_ncm_tx_zero(pc, last_offset, offset);
1404
1405 /* buffer full */
1406 retval = 2;
1407
1408 for (n = 0; n != sc->sc_ncm.tx_nframe; n++) {
1409 /* check if end of transmit buffer is reached */
1410
1411 if (offset >= sc->sc_ncm.tx_max)
1412 break;
1413
1414 /* compute maximum buffer size */
1415
1416 rem = sc->sc_ncm.tx_max - offset;
1417
1418 IFQ_DRV_DEQUEUE(&(ifp->if_snd), m);
1419
1420 if (m == NULL) {
1421 /* buffer not full */
1422 retval = 1;
1423 break;
1424 }
1425
1426 if (m->m_pkthdr.len > (int)rem) {
1427 if (n == 0) {
1428 /* The frame won't fit in our buffer */
1429 DPRINTFN(1, "Frame too big to be transmitted!\n");
1430 m_freem(m);
1431 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1432 n--;
1433 continue;
1434 }
1435 /* Wait till next buffer becomes ready */
1436 IFQ_DRV_PREPEND(&(ifp->if_snd), m);
1437 break;
1438 }
1439 usbd_m_copy_in(pc, offset, m, 0, m->m_pkthdr.len);
1440
1441 USETW(sc->sc_ncm.dp[n].wFrameLength, m->m_pkthdr.len);
1443
1444 /* Update offset */
1445 offset += m->m_pkthdr.len;
1446
1447 /* Store last valid offset before alignment */
1448 last_offset = offset;
1449
1450 /* Align offset */
1452 offset, sc->sc_ncm.tx_modulus);
1453
1454 /* Zero pad */
1455 cdce_ncm_tx_zero(pc, last_offset, offset);
1456
1457 /*
1458 * If there's a BPF listener, bounce a copy
1459 * of this frame to him:
1460 */
1461 BPF_MTAP(ifp, m);
1462
1463 /* Free mbuf */
1464
1465 m_freem(m);
1466
1467 /* Pre-increment interface counter */
1468
1469 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
1470 }
1471
1472 if (n == 0)
1473 return (0);
1474
1475 rem = (sizeof(sc->sc_ncm.dpt) + (4 * n) + 4);
1476
1477 USETW(sc->sc_ncm.dpt.wLength, rem);
1478
1479 /* zero the rest of the data pointer entries */
1480 for (; n != CDCE_NCM_SUBFRAMES_MAX; n++) {
1481 USETW(sc->sc_ncm.dp[n].wFrameLength, 0);
1482 USETW(sc->sc_ncm.dp[n].wFrameIndex, 0);
1483 }
1484
1485 offset = last_offset;
1486
1487 /* Align offset */
1489
1490 /* Optimise, save bandwidth and force short termination */
1491 if (offset >= sc->sc_ncm.tx_max)
1492 offset = sc->sc_ncm.tx_max;
1493 else
1494 offset ++;
1495
1496 /* Zero pad */
1497 cdce_ncm_tx_zero(pc, last_offset, offset);
1498
1499 /* set frame length */
1500 usbd_xfer_set_frame_len(xfer, index, offset);
1501
1502 /* Fill out 16-bit header */
1503 sc->sc_ncm.hdr.dwSignature[0] = 'N';
1504 sc->sc_ncm.hdr.dwSignature[1] = 'C';
1505 sc->sc_ncm.hdr.dwSignature[2] = 'M';
1506 sc->sc_ncm.hdr.dwSignature[3] = 'H';
1507 USETW(sc->sc_ncm.hdr.wHeaderLength, sizeof(sc->sc_ncm.hdr));
1510 USETW(sc->sc_ncm.hdr.wDptIndex, sizeof(sc->sc_ncm.hdr));
1511
1512 sc->sc_ncm.tx_seq++;
1513
1514 /* Fill out 16-bit frame table header */
1515 sc->sc_ncm.dpt.dwSignature[0] = 'N';
1516 sc->sc_ncm.dpt.dwSignature[1] = 'C';
1517 sc->sc_ncm.dpt.dwSignature[2] = 'M';
1518 sc->sc_ncm.dpt.dwSignature[3] = '0';
1519 USETW(sc->sc_ncm.dpt.wNextNdpIndex, 0); /* reserved */
1520
1521 usbd_copy_in(pc, 0, &(sc->sc_ncm.hdr), sizeof(sc->sc_ncm.hdr));
1522 usbd_copy_in(pc, sizeof(sc->sc_ncm.hdr), &(sc->sc_ncm.dpt),
1523 sizeof(sc->sc_ncm.dpt));
1524 usbd_copy_in(pc, sizeof(sc->sc_ncm.hdr) + sizeof(sc->sc_ncm.dpt),
1525 &(sc->sc_ncm.dp), sizeof(sc->sc_ncm.dp));
1526 return (retval);
1527}
1528
1529static void
1530cdce_ncm_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
1531{
1532 struct cdce_softc *sc = usbd_xfer_softc(xfer);
1533 struct ifnet *ifp = uether_getifp(&sc->sc_ue);
1534 uint16_t x;
1535 uint8_t temp;
1536 int actlen;
1537 int aframes;
1538
1539 switch (USB_GET_STATE(xfer)) {
1540 case USB_ST_TRANSFERRED:
1541
1542 usbd_xfer_status(xfer, &actlen, NULL, &aframes, NULL);
1543
1544 DPRINTFN(10, "transfer complete: "
1545 "%u bytes in %u frames\n", actlen, aframes);
1546
1547 case USB_ST_SETUP:
1548 for (x = 0; x != CDCE_NCM_TX_FRAMES_MAX; x++) {
1549 temp = cdce_ncm_fill_tx_frames(xfer, x);
1550 if (temp == 0)
1551 break;
1552 if (temp == 1) {
1553 x++;
1554 break;
1555 }
1556 }
1557
1558 if (x != 0) {
1559#ifdef USB_DEBUG
1560 usbd_xfer_set_interval(xfer, cdce_tx_interval);
1561#endif
1562 usbd_xfer_set_frames(xfer, x);
1564 }
1565 break;
1566
1567 default: /* Error */
1568 DPRINTFN(10, "Transfer error: %s\n",
1570
1571 /* update error counter */
1572 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1573
1574 if (error != USB_ERR_CANCELLED) {
1576 /* try to clear stall first */
1577 usbd_xfer_set_stall(xfer);
1578 usbd_xfer_set_frames(xfer, 0);
1580 }
1581 }
1582 break;
1583 }
1584}
1585
1586static void
1587cdce_ncm_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
1588{
1589 struct cdce_softc *sc = usbd_xfer_softc(xfer);
1590 struct usb_page_cache *pc = usbd_xfer_get_frame(xfer, 0);
1591 struct ifnet *ifp = uether_getifp(&sc->sc_ue);
1592 struct mbuf *m;
1593 int sumdata;
1594 int sumlen;
1595 int actlen;
1596 int aframes;
1597 int temp;
1598 int nframes;
1599 int x;
1600 int offset;
1601
1602 switch (USB_GET_STATE(xfer)) {
1603 case USB_ST_TRANSFERRED:
1604
1605 usbd_xfer_status(xfer, &actlen, &sumlen, &aframes, NULL);
1606
1607 DPRINTFN(1, "received %u bytes in %u frames\n",
1608 actlen, aframes);
1609
1610 if (actlen < (int)(sizeof(sc->sc_ncm.hdr) +
1611 sizeof(sc->sc_ncm.dpt))) {
1612 DPRINTFN(1, "frame too short\n");
1613 goto tr_setup;
1614 }
1615 usbd_copy_out(pc, 0, &(sc->sc_ncm.hdr),
1616 sizeof(sc->sc_ncm.hdr));
1617
1618 if ((sc->sc_ncm.hdr.dwSignature[0] != 'N') ||
1619 (sc->sc_ncm.hdr.dwSignature[1] != 'C') ||
1620 (sc->sc_ncm.hdr.dwSignature[2] != 'M') ||
1621 (sc->sc_ncm.hdr.dwSignature[3] != 'H')) {
1622 DPRINTFN(1, "invalid HDR signature: "
1623 "0x%02x:0x%02x:0x%02x:0x%02x\n",
1624 sc->sc_ncm.hdr.dwSignature[0],
1625 sc->sc_ncm.hdr.dwSignature[1],
1626 sc->sc_ncm.hdr.dwSignature[2],
1627 sc->sc_ncm.hdr.dwSignature[3]);
1628 goto tr_stall;
1629 }
1630 temp = UGETW(sc->sc_ncm.hdr.wBlockLength);
1631 if (temp > sumlen) {
1632 DPRINTFN(1, "unsupported block length %u/%u\n",
1633 temp, sumlen);
1634 goto tr_stall;
1635 }
1636 temp = UGETW(sc->sc_ncm.hdr.wDptIndex);
1637 if ((int)(temp + sizeof(sc->sc_ncm.dpt)) > actlen) {
1638 DPRINTFN(1, "invalid DPT index: 0x%04x\n", temp);
1639 goto tr_stall;
1640 }
1641 usbd_copy_out(pc, temp, &(sc->sc_ncm.dpt),
1642 sizeof(sc->sc_ncm.dpt));
1643
1644 if ((sc->sc_ncm.dpt.dwSignature[0] != 'N') ||
1645 (sc->sc_ncm.dpt.dwSignature[1] != 'C') ||
1646 (sc->sc_ncm.dpt.dwSignature[2] != 'M') ||
1647 (sc->sc_ncm.dpt.dwSignature[3] != '0')) {
1648 DPRINTFN(1, "invalid DPT signature"
1649 "0x%02x:0x%02x:0x%02x:0x%02x\n",
1650 sc->sc_ncm.dpt.dwSignature[0],
1651 sc->sc_ncm.dpt.dwSignature[1],
1652 sc->sc_ncm.dpt.dwSignature[2],
1653 sc->sc_ncm.dpt.dwSignature[3]);
1654 goto tr_stall;
1655 }
1656 nframes = UGETW(sc->sc_ncm.dpt.wLength) / 4;
1657
1658 /* Subtract size of header and last zero padded entry */
1659 if (nframes >= (2 + 1))
1660 nframes -= (2 + 1);
1661 else
1662 nframes = 0;
1663
1664 DPRINTFN(1, "nframes = %u\n", nframes);
1665
1666 temp += sizeof(sc->sc_ncm.dpt);
1667
1668 if ((temp + (4 * nframes)) > actlen)
1669 goto tr_stall;
1670
1671 if (nframes > CDCE_NCM_SUBFRAMES_MAX) {
1672 DPRINTFN(1, "Truncating number of frames from %u to %u\n",
1673 nframes, CDCE_NCM_SUBFRAMES_MAX);
1674 nframes = CDCE_NCM_SUBFRAMES_MAX;
1675 }
1676 usbd_copy_out(pc, temp, &(sc->sc_ncm.dp), (4 * nframes));
1677
1678 sumdata = 0;
1679
1680 for (x = 0; x != nframes; x++) {
1681 offset = UGETW(sc->sc_ncm.dp[x].wFrameIndex);
1682 temp = UGETW(sc->sc_ncm.dp[x].wFrameLength);
1683
1684 if ((offset == 0) ||
1685 (temp < (int)sizeof(struct ether_header)) ||
1686 (temp > (MCLBYTES - ETHER_ALIGN))) {
1687 DPRINTFN(1, "NULL frame detected at %d\n", x);
1688 m = NULL;
1689 /* silently ignore this frame */
1690 continue;
1691 } else if ((offset + temp) > actlen) {
1692 DPRINTFN(1, "invalid frame "
1693 "detected at %d\n", x);
1694 m = NULL;
1695 /* silently ignore this frame */
1696 continue;
1697 } else if (temp > (int)(MHLEN - ETHER_ALIGN)) {
1698 m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
1699 } else {
1700 m = m_gethdr(M_NOWAIT, MT_DATA);
1701 }
1702
1703 DPRINTFN(16, "frame %u, offset = %u, length = %u \n",
1704 x, offset, temp);
1705
1706 /* check if we have a buffer */
1707 if (m) {
1708 m->m_len = m->m_pkthdr.len = temp + ETHER_ALIGN;
1709 m_adj(m, ETHER_ALIGN);
1710
1711 usbd_copy_out(pc, offset, m->m_data, temp);
1712
1713 /* enqueue */
1714 uether_rxmbuf(&sc->sc_ue, m, temp);
1715
1716 sumdata += temp;
1717 } else {
1718 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
1719 }
1720 }
1721
1722 DPRINTFN(1, "Efficiency: %u/%u bytes\n", sumdata, actlen);
1723
1724 case USB_ST_SETUP:
1725tr_setup:
1727 usbd_xfer_set_frames(xfer, 1);
1729 uether_rxflush(&sc->sc_ue); /* must be last */
1730 break;
1731
1732 default: /* Error */
1733 DPRINTFN(1, "error = %s\n",
1735
1736 if (error != USB_ERR_CANCELLED) {
1737tr_stall:
1739 /* try to clear stall first */
1740 usbd_xfer_set_stall(xfer);
1741 usbd_xfer_set_frames(xfer, 0);
1743 }
1744 }
1745 break;
1746 }
1747}
1748#endif
static int debug
Definition: cfumass.c:73
static SYSCTL_NODE(_hw_usb, OID_AUTO, dwc_otg, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "USB DWC OTG")
SYSCTL_INT(_hw_usb_dwc_otg, OID_AUTO, phy_type, CTLFLAG_RDTUN, &dwc_otg_phy_type, 0, "DWC OTG PHY TYPE - 0/1/2/3 - ULPI/HSIC/INTERNAL/UTMI+")
uint16_t len
Definition: ehci.h:41
static device_method_t cdce_methods[]
Definition: if_cdce.c:242
static eventhandler_tag cdce_etag
Definition: if_cdce.c:263
static uether_fn_t cdce_setmulti
Definition: if_cdce.c:112
static int cdce_ioctl(struct ifnet *, u_long, caddr_t)
Definition: if_cdce.c:812
static const STRUCT_USB_DUAL_ID cdce_dual_devs[]
Definition: if_cdce.c:300
static usb_callback_t cdce_intr_write_callback
Definition: if_cdce.c:101
static uether_fn_t cdce_setpromisc
Definition: if_cdce.c:113
USB_PNP_DUAL_INFO(cdce_dual_devs)
USB_PNP_DEVICE_INFO(cdce_switch_devs)
static uether_fn_t cdce_start
Definition: if_cdce.c:111
static void cdce_test_autoinst(void *arg, struct usb_device *udev, struct usb_attach_arg *uaa)
Definition: if_cdce.c:511
static device_suspend_t cdce_suspend
Definition: if_cdce.c:94
static int cdce_media_change_cb(struct ifnet *)
Definition: if_cdce.c:847
static device_probe_t cdce_probe
Definition: if_cdce.c:91
static int cdce_driver_loaded(struct module *, int, void *)
Definition: if_cdce.c:536
MODULE_VERSION(cdce, 1)
MODULE_DEPEND(cdce, uether, 1, 1, 1)
static uether_fn_t cdce_stop
Definition: if_cdce.c:110
static device_resume_t cdce_resume
Definition: if_cdce.c:95
static devclass_t cdce_devclass
Definition: if_cdce.c:262
static usb_callback_t cdce_intr_read_callback
Definition: if_cdce.c:100
__FBSDID("$FreeBSD$")
#define USB_DEBUG_VAR
Definition: if_cdce.c:82
static driver_t cdce_driver
Definition: if_cdce.c:256
DRIVER_MODULE(cdce, uhub, cdce_driver, cdce_devclass, cdce_driver_loaded, 0)
static usb_handle_request_t cdce_handle_request
Definition: if_cdce.c:96
static uether_fn_t cdce_attach_post
Definition: if_cdce.c:108
static int cdce_attach_post_sub(struct usb_ether *)
Definition: if_cdce.c:572
static const struct usb_ether_methods cdce_ue_methods
Definition: if_cdce.c:315
static const STRUCT_USB_HOST_ID cdce_host_devs[]
Definition: if_cdce.c:271
static usb_callback_t cdce_bulk_read_callback
Definition: if_cdce.c:99
static uint32_t cdce_m_crc32(struct mbuf *, uint32_t, uint32_t)
Definition: if_cdce.c:974
static void cdce_set_filter(struct usb_ether *)
Definition: if_cdce.c:1043
static uether_fn_t cdce_init
Definition: if_cdce.c:109
static usb_callback_t cdce_bulk_write_callback
Definition: if_cdce.c:98
static device_attach_t cdce_attach
Definition: if_cdce.c:92
static int32_t cdce_m_crc32_cb(void *arg, void *src, uint32_t count)
Definition: if_cdce.c:965
static device_detach_t cdce_detach
Definition: if_cdce.c:93
static void cdce_media_status_cb(struct ifnet *, struct ifmediareq *)
Definition: if_cdce.c:854
static const struct usb_config cdce_config[CDCE_N_TRANSFER]
Definition: if_cdce.c:136
USB_PNP_HOST_INFO(cdce_host_devs)
static void cdce_free_queue(struct mbuf **ppm, uint8_t n)
Definition: if_cdce.c:835
static const STRUCT_USB_HOST_ID cdce_switch_devs[]
Definition: if_cdce.c:267
#define cdce_debug
Definition: if_cdce.c:133
#define CDCE_LOCK(_sc)
Definition: if_cdcereg.h:122
#define CDCE_NCM_TX_MINLEN
Definition: if_cdcereg.h:45
@ CDCE_INTR_RX
Definition: if_cdcereg.h:65
@ CDCE_BULK_RX
Definition: if_cdcereg.h:63
@ CDCE_INTR_TX
Definition: if_cdcereg.h:66
@ CDCE_BULK_TX
Definition: if_cdcereg.h:64
@ CDCE_N_TRANSFER
Definition: if_cdcereg.h:67
#define CDCE_NCM_RX_MAXLEN
Definition: if_cdcereg.h:49
#define CDCE_FLAG_ZAURUS
Definition: if_cdcereg.h:96
#define CDCE_NOTIFY_DONE
Definition: if_cdcereg.h:106
#define CDC_PACKET_TYPE_ALL_MULTICAST
Definition: if_cdcereg.h:117
#define CDCE_NOTIFY_SPEED_CHANGE
Definition: if_cdcereg.h:105
#define CDC_SET_ETHERNET_PACKET_FILTER
Definition: if_cdcereg.h:114
#define CDCE_NCM_RX_FRAMES_MAX
Definition: if_cdcereg.h:50
#define CDCE_LOCK_ASSERT(_sc, t)
Definition: if_cdcereg.h:124
#define CDCE_FLAG_NO_UNION
Definition: if_cdcereg.h:97
#define CDC_PACKET_TYPE_BROADCAST
Definition: if_cdcereg.h:119
#define CDCE_NCM_ALIGN(rem, off, mod)
Definition: if_cdcereg.h:54
#define CDCE_NCM_TX_FRAMES_MAX
Definition: if_cdcereg.h:47
#define CDCE_UNLOCK(_sc)
Definition: if_cdcereg.h:123
#define CDC_PACKET_TYPE_DIRECTED
Definition: if_cdcereg.h:118
#define CDCE_NCM_TX_MAXLEN
Definition: if_cdcereg.h:46
#define CDCE_NCM_SUBFRAMES_MAX
Definition: if_cdcereg.h:52
#define CDCE_FLAG_VLAN
Definition: if_cdcereg.h:99
#define CDCE_IND_SIZE_MAX
Definition: if_cdcereg.h:43
#define CDCE_NOTIFY_NETWORK_CONNECTION
Definition: if_cdcereg.h:104
#define CDC_PACKET_TYPE_PROMISC
Definition: if_cdcereg.h:116
#define CDCE_FRAMES_MAX
Definition: if_cdcereg.h:42
uint8_t n
Definition: if_run.c:612
struct @109 error
uint8_t id
Definition: if_usievar.h:4
uint32_t value
uint16_t data
int * count
device_t dev
uint16_t tx_remainder
Definition: if_cdcereg.h:76
uint32_t rx_max
Definition: if_cdcereg.h:74
uint16_t tx_struct_align
Definition: if_cdcereg.h:78
struct usb_ncm16_hdr hdr
Definition: if_cdcereg.h:71
uint32_t tx_max
Definition: if_cdcereg.h:75
struct usb_ncm16_dpt dpt
Definition: if_cdcereg.h:72
uint16_t tx_modulus
Definition: if_cdcereg.h:77
uint16_t tx_seq
Definition: if_cdcereg.h:79
uint16_t tx_nframe
Definition: if_cdcereg.h:80
struct usb_ncm16_dp dp[CDCE_NCM_SUBFRAMES_MAX]
Definition: if_cdcereg.h:73
struct cdce_ncm sc_ncm
Definition: if_cdcereg.h:87
struct ifmedia sc_media
Definition: if_cdcereg.h:93
struct usb_ether sc_ue
Definition: if_cdcereg.h:84
struct mbuf * sc_tx_buf[CDCE_FRAMES_MAX]
Definition: if_cdcereg.h:91
int sc_flags
Definition: if_cdcereg.h:95
struct mbuf * sc_rx_buf[CDCE_FRAMES_MAX]
Definition: if_cdcereg.h:90
uint8_t sc_notify_state
Definition: if_cdcereg.h:103
uint8_t sc_ifaces_index[2]
Definition: if_cdcereg.h:102
struct mtx sc_mtx
Definition: if_cdcereg.h:85
struct usb_xfer * sc_xfer[CDCE_N_TRANSFER]
Definition: if_cdcereg.h:89
enum usb_hc_mode usb_mode
Definition: usbdi.h:432
uint8_t dev_state
Definition: usbdi.h:434
struct usbd_lookup_info info
Definition: usbdi.h:426
struct usb_device * device
Definition: usbdi.h:430
uByte data[16]
Definition: usb_cdc.h:160
uByte bSlaveInterface[1]
Definition: usb_cdc.h:90
struct usb_xfer_flags flags
Definition: usbdi.h:235
uint8_t type
Definition: usbdi.h:238
uether_fn_t * ue_attach_post
Definition: usb_ethernet.h:58
const struct usb_ether_methods * ue_methods
Definition: usb_ethernet.h:81
struct usb_device * ue_udev
Definition: usb_ethernet.h:84
uint8_t ue_eaddr[ETHER_ADDR_LEN]
Definition: usb_ethernet.h:101
device_t ue_dev
Definition: usb_ethernet.h:85
struct mtx * ue_mtx
Definition: usb_ethernet.h:80
void * ue_sc
Definition: usb_ethernet.h:83
struct usb_interface_descriptor * idesc
Definition: usbdi.h:175
uWord wFrameIndex
Definition: usb_cdc.h:198
uWord wFrameLength
Definition: usb_cdc.h:199
uDWord dwSignature
Definition: usb_cdc.h:203
uWord wLength
Definition: usb_cdc.h:204
uWord wNextNdpIndex
Definition: usb_cdc.h:205
uWord wHeaderLength
Definition: usb_cdc.h:191
uWord wSequence
Definition: usb_cdc.h:192
uWord wBlockLength
Definition: usb_cdc.h:193
uWord wDptIndex
Definition: usb_cdc.h:194
uDWord dwSignature
Definition: usb_cdc.h:190
uint8_t pipe_bof
Definition: usbdi.h:200
uint8_t bIfaceIndex
Definition: usbdi.h:417
#define DPRINTF(...)
Definition: umass.c:179
#define UE_INTERRUPT
Definition: usb.h:544
#define UE_ADDR_ANY
Definition: usb.h:537
#define UE_BULK
Definition: usb.h:543
#define UT_READ_CLASS_INTERFACE
Definition: usb.h:173
#define UICLASS_VENDOR
Definition: usb.h:520
#define UT_INTERFACE
Definition: usb.h:162
#define UISUBCLASS_NETWORK_CONTROL_MODEL
Definition: usb.h:447
#define UE_DIR_RX
Definition: usb.h:533
#define UICLASS_CDC
Definition: usb.h:434
@ USB_SPEED_FULL
Definition: usb.h:754
@ USB_MODE_DUAL
Definition: usb.h:780
@ USB_MODE_HOST
Definition: usb.h:778
@ USB_MODE_DEVICE
Definition: usb.h:779
#define UE_DIR_TX
Definition: usb.h:534
#define UT_WRITE_CLASS_INTERFACE
Definition: usb.h:177
#define UISUBCLASS_MOBILE_DIRECT_LINE_MODEL
Definition: usb.h:444
#define UT_CLASS
Definition: usb.h:159
#define UICLASS_MASS
Definition: usb.h:467
#define UDESC_CS_INTERFACE
Definition: usb.h:212
#define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL
Definition: usb.h:440
void usbd_frame_zero(struct usb_page_cache *cache, usb_frlength_t offset, usb_frlength_t len)
Definition: usb_busdma.c:339
void usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset, const void *ptr, usb_frlength_t len)
Definition: usb_busdma.c:166
void usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset, void *ptr, usb_frlength_t len)
Definition: usb_busdma.c:283
#define UCDC_N_CONNECTION_SPEED_CHANGE
Definition: usb_cdc.h:156
#define UCDC_NOTIFICATION_LENGTH
Definition: usb_cdc.h:163
#define UCDC_NCM_SET_ETHERNET_PACKET_FILTER
Definition: usb_cdc.h:254
#define UDESCSUB_CDC_UNION
Definition: usb_cdc.h:45
#define UCDC_N_NETWORK_CONNECTION
Definition: usb_cdc.h:149
#define UDESCSUB_CDC_ENF
Definition: usb_cdc.h:54
#define UCDC_NCM_SET_NTB_INPUT_SIZE
Definition: usb_cdc.h:262
#define UCDC_NCM_FUNC_DESC_SUBTYPE
Definition: usb_cdc.h:233
#define UCDC_NCM_GET_NTB_PARAMETERS
Definition: usb_cdc.h:256
#define UCDC_NCM_CAP_MAX_DGRAM
Definition: usb_cdc.h:246
#define UCDC_NCM_SET_CRC_MODE
Definition: usb_cdc.h:266
#define UCDC_NOTIFICATION
Definition: usb_cdc.h:147
#define UCDC_NCM_SET_NTB_FORMAT
Definition: usb_cdc.h:260
usb_error_t usbd_set_alt_interface_index(struct usb_device *udev, uint8_t iface_index, uint8_t alt_index)
Definition: usb_device.c:1034
struct usb_interface_descriptor * usbd_get_interface_descriptor(struct usb_interface *iface)
Definition: usb_device.c:2654
void usbd_set_parent_iface(struct usb_device *udev, uint8_t iface_index, uint8_t parent_index)
Definition: usb_device.c:1395
void * usbd_find_descriptor(struct usb_device *udev, void *id, uint8_t iface_index, uint8_t type, uint8_t type_mask, uint8_t subtype, uint8_t subtype_mask)
Definition: usb_device.c:2395
enum usb_dev_speed usbd_get_speed(struct usb_device *udev)
Definition: usb_device.c:2589
enum usb_hc_mode usbd_get_mode(struct usb_device *udev)
Definition: usb_device.c:2579
struct usb_interface * usbd_get_iface(struct usb_device *udev, uint8_t iface_index)
Definition: usb_device.c:2370
#define USETW(w, v)
Definition: usb_endian.h:77
#define USETDW(w, v)
Definition: usb_endian.h:82
#define UGETW(w)
Definition: usb_endian.h:53
#define UGETDW(w)
Definition: usb_endian.h:57
const char * usbd_errstr(usb_error_t err)
Definition: usb_error.c:93
void uether_rxflush(struct usb_ether *ue)
Definition: usb_ethernet.c:646
struct mbuf * uether_newbuf(void)
Definition: usb_ethernet.c:584
void uether_ifdetach(struct usb_ether *ue)
Definition: usb_ethernet.c:302
void * uether_getsc(struct usb_ether *ue)
Definition: usb_ethernet.c:148
struct ifnet * uether_getifp(struct usb_ether *ue)
Definition: usb_ethernet.c:136
int uether_rxmbuf(struct usb_ether *ue, struct mbuf *m, unsigned int len)
Definition: usb_ethernet.c:598
void uether_init(void *arg)
Definition: usb_ethernet.c:358
int uether_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
Definition: usb_ethernet.c:513
int uether_ifattach(struct usb_ether *ue)
Definition: usb_ethernet.c:164
void uether_start(struct ifnet *ifp)
Definition: usb_ethernet.c:410
void() uether_fn_t(struct usb_ether *)
Definition: usb_ethernet.h:55
static usb_error_t usb_handle_request(struct usb_xfer *)
void ** pptr
Definition: usb_if.m:52
uint8_t * pstate
Definition: usb_if.m:55
uint16_t * plen
Definition: usb_if.m:53
uint16_t offset
Definition: usb_if.m:54
const void * req
Definition: usb_if.m:51
INTERFACE usb
Definition: usb_if.m:35
int usbd_lookup_id_by_uaa(const struct usb_device_id *id, usb_size_t sizeof_id, struct usb_attach_arg *uaa)
Definition: usb_lookup.c:143
usb_error_t usb_msc_eject(struct usb_device *udev, uint8_t iface_index, int method)
Definition: usb_msctest.c:964
@ MSC_EJECT_HUAWEI2
Definition: usb_msctest.h:38
usb_error_t usbd_req_get_string_any(struct usb_device *udev, struct mtx *mtx, char *buf, uint16_t len, uint8_t string_index)
Definition: usb_request.c:1100
usb_error_t usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx, struct usb_device_request *req, void *data, uint16_t flags, uint16_t *actlen, usb_timeout_t timeout)
Definition: usb_request.c:405
void usbd_transfer_submit(struct usb_xfer *xfer)
void usbd_xfer_set_frames(struct usb_xfer *xfer, usb_frcount_t n)
void usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup)
void usbd_xfer_set_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex, void *ptr, usb_frlength_t len)
void usbd_xfer_set_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex, usb_frlength_t len)
usb_frlength_t usbd_xfer_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex)
struct usb_page_cache * usbd_xfer_get_frame(struct usb_xfer *xfer, usb_frcount_t frindex)
usb_error_t usbd_transfer_setup(struct usb_device *udev, const uint8_t *ifaces, struct usb_xfer **ppxfer, const struct usb_config *setup_start, uint16_t n_setup, void *priv_sc, struct mtx *xfer_mtx)
Definition: usb_transfer.c:987
void usbd_transfer_start(struct usb_xfer *xfer)
void usbd_xfer_set_frame_offset(struct usb_xfer *xfer, usb_frlength_t offset, usb_frcount_t frindex)
void * usbd_xfer_softc(struct usb_xfer *xfer)
void usbd_xfer_set_stall(struct usb_xfer *xfer)
void usbd_xfer_set_interval(struct usb_xfer *xfer, int i)
void usbd_transfer_stop(struct usb_xfer *xfer)
void usbd_xfer_status(struct usb_xfer *xfer, int *actlen, int *sumlen, int *aframes, int *nframes)
usb_frlength_t usbd_xfer_max_len(struct usb_xfer *xfer)
void device_set_usb_desc(device_t dev)
Definition: usb_util.c:73
#define USB_IF_CSI(class, subclass, info)
Definition: usbdi.h:394
#define USB_IFACE_SUBCLASS(isc)
Definition: usbdi.h:388
#define USB_ST_SETUP
Definition: usbdi.h:502
usb_error_t
Definition: usbdi.h:45
@ USB_ERR_CANCELLED
Definition: usbdi.h:51
@ USB_ERR_INVAL
Definition: usbdi.h:49
#define UAA_DEV_READY
Definition: usbdi.h:435
#define USB_IFACE_CLASS(ic)
Definition: usbdi.h:385
#define USB_ST_TRANSFERRED
Definition: usbdi.h:503
void usbd_m_copy_in(struct usb_page_cache *cache, usb_frlength_t dst_offset, struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len)
#define USB_IFACE_PROTOCOL(ip)
Definition: usbdi.h:391
void() usb_callback_t(struct usb_xfer *, usb_error_t)
Definition: usbdi.h:94
#define USB_VENDOR(vend)
Definition: usbdi.h:358
#define USB_VPI(vend, prod, info)
Definition: usbdi.h:367
#define STRUCT_USB_HOST_ID
Definition: usbdi.h:258
#define USB_GET_DRIVER_INFO(did)
Definition: usbdi.h:400
#define USB_GET_STATE(xfer)
Definition: usbdi.h:515
#define usbd_do_request(u, m, r, d)
Definition: usbdi.h:596
#define UAA_DEV_EJECTING
Definition: usbdi.h:437
#define STRUCT_USB_DUAL_ID
Definition: usbdi.h:262
#define USB_DRIVER_INFO(n)
Definition: usbdi.h:397