2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1996-2000 Whistle Communications, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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. Neither the name of author nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY NICK HIBMA AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 /* Driver for arbitrary double bulk pipe devices.
37 * The driver assumes that there will be the same driver on the other side.
39 * XXX Some more information on what the framing of the IP packets looks like.
41 * To take full advantage of bulk transmission, packets should be chosen
42 * between 1k and 5k in size (1k to make sure the sending side starts
43 * streaming, and <5k to avoid overflowing the system with small TDs).
47 /* probe/attach/detach:
48 * Connect the driver to the hardware and netgraph
50 * The reason we submit a bulk in transfer is that USB does not know about
51 * interrupts. The bulk transfer continuously polls the device for data.
52 * While the device has no data available, the device NAKs the TDs. As soon
53 * as there is data, the transfer happens and the data comes flowing in.
55 * In case you were wondering, interrupt transfers happen exactly that way.
56 * It therefore doesn't make sense to use the interrupt pipe to signal
57 * 'data ready' and then schedule a bulk transfer to fetch it. That would
58 * incur a 2ms delay at least, without reducing bandwidth requirements.
62 #include <sys/stdint.h>
63 #include <sys/stddef.h>
64 #include <sys/param.h>
65 #include <sys/queue.h>
66 #include <sys/types.h>
67 #include <sys/systm.h>
68 #include <sys/kernel.h>
70 #include <sys/module.h>
72 #include <sys/mutex.h>
73 #include <sys/condvar.h>
74 #include <sys/sysctl.h>
76 #include <sys/unistd.h>
77 #include <sys/callout.h>
78 #include <sys/malloc.h>
81 #include <dev/usb/usb.h>
82 #include <dev/usb/usbdi.h>
83 #include <dev/usb/usbdi_util.h>
86 #define USB_DEBUG_VAR udbp_debug
87 #include <dev/usb/usb_debug.h>
91 #include <netgraph/ng_message.h>
92 #include <netgraph/netgraph.h>
93 #include <netgraph/ng_parse.h>
94 #include <netgraph/bluetooth/include/ng_bluetooth.h>
96 #include <dev/usb/misc/udbp.h>
99 static int udbp_debug = 0;
101 static SYSCTL_NODE(_hw_usb, OID_AUTO, udbp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
103 SYSCTL_INT(_hw_usb_udbp, OID_AUTO, debug, CTLFLAG_RWTUN,
104 &udbp_debug, 0, "udbp debug level");
107 #define UDBP_TIMEOUT 2000 /* timeout on outbound transfers, in
109 #define UDBP_BUFFERSIZE MCLBYTES /* maximum number of bytes in one
113 #define UDBP_T_WR_CS 2
114 #define UDBP_T_RD_CS 3
116 #define UDBP_Q_MAXLEN 50
121 struct ng_bt_mbufq sc_xmitq_hipri; /* hi-priority transmit queue */
122 struct ng_bt_mbufq sc_xmitq; /* low-priority transmit queue */
124 struct usb_xfer *sc_xfer[UDBP_T_MAX];
125 node_p sc_node; /* back pointer to node */
126 hook_p sc_hook; /* pointer to the hook */
127 struct mbuf *sc_bulk_in_buffer;
129 uint32_t sc_packets_in; /* packets in from downstream */
130 uint32_t sc_packets_out; /* packets out towards downstream */
133 #define UDBP_FLAG_READ_STALL 0x01 /* read transfer stalled */
134 #define UDBP_FLAG_WRITE_STALL 0x02 /* write transfer stalled */
141 static int udbp_modload(module_t mod, int event, void *data);
143 static device_probe_t udbp_probe;
144 static device_attach_t udbp_attach;
145 static device_detach_t udbp_detach;
147 static usb_callback_t udbp_bulk_read_callback;
148 static usb_callback_t udbp_bulk_read_clear_stall_callback;
149 static usb_callback_t udbp_bulk_write_callback;
150 static usb_callback_t udbp_bulk_write_clear_stall_callback;
152 static void udbp_bulk_read_complete(node_p, hook_p, void *, int);
154 static ng_constructor_t ng_udbp_constructor;
155 static ng_rcvmsg_t ng_udbp_rcvmsg;
156 static ng_shutdown_t ng_udbp_rmnode;
157 static ng_newhook_t ng_udbp_newhook;
158 static ng_connect_t ng_udbp_connect;
159 static ng_rcvdata_t ng_udbp_rcvdata;
160 static ng_disconnect_t ng_udbp_disconnect;
162 /* Parse type for struct ngudbpstat */
163 static const struct ng_parse_struct_field
164 ng_udbp_stat_type_fields[] = NG_UDBP_STATS_TYPE_INFO;
166 static const struct ng_parse_type ng_udbp_stat_type = {
167 &ng_parse_struct_type,
168 &ng_udbp_stat_type_fields
171 /* List of commands and how to convert arguments to/from ASCII */
172 static const struct ng_cmdlist ng_udbp_cmdlist[] = {
184 &ng_parse_int32_type,
190 /* Netgraph node type descriptor */
191 static struct ng_type ng_udbp_typestruct = {
192 .version = NG_ABI_VERSION,
193 .name = NG_UDBP_NODE_TYPE,
194 .constructor = ng_udbp_constructor,
195 .rcvmsg = ng_udbp_rcvmsg,
196 .shutdown = ng_udbp_rmnode,
197 .newhook = ng_udbp_newhook,
198 .connect = ng_udbp_connect,
199 .rcvdata = ng_udbp_rcvdata,
200 .disconnect = ng_udbp_disconnect,
201 .cmdlist = ng_udbp_cmdlist,
205 static const struct usb_config udbp_config[UDBP_T_MAX] = {
209 .endpoint = UE_ADDR_ANY,
210 .direction = UE_DIR_OUT,
211 .bufsize = UDBP_BUFFERSIZE,
212 .flags = {.pipe_bof = 1,.force_short_xfer = 1,},
213 .callback = &udbp_bulk_write_callback,
214 .timeout = UDBP_TIMEOUT,
219 .endpoint = UE_ADDR_ANY,
220 .direction = UE_DIR_IN,
221 .bufsize = UDBP_BUFFERSIZE,
222 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
223 .callback = &udbp_bulk_read_callback,
228 .endpoint = 0x00, /* Control pipe */
229 .direction = UE_DIR_ANY,
230 .bufsize = sizeof(struct usb_device_request),
231 .callback = &udbp_bulk_write_clear_stall_callback,
232 .timeout = 1000, /* 1 second */
233 .interval = 50, /* 50ms */
238 .endpoint = 0x00, /* Control pipe */
239 .direction = UE_DIR_ANY,
240 .bufsize = sizeof(struct usb_device_request),
241 .callback = &udbp_bulk_read_clear_stall_callback,
242 .timeout = 1000, /* 1 second */
243 .interval = 50, /* 50ms */
247 static devclass_t udbp_devclass;
249 static device_method_t udbp_methods[] = {
250 /* Device interface */
251 DEVMETHOD(device_probe, udbp_probe),
252 DEVMETHOD(device_attach, udbp_attach),
253 DEVMETHOD(device_detach, udbp_detach),
258 static driver_t udbp_driver = {
260 .methods = udbp_methods,
261 .size = sizeof(struct udbp_softc),
264 static const STRUCT_USB_HOST_ID udbp_devs[] = {
265 {USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U258, 0)},
266 {USB_VPI(USB_VENDOR_NETCHIP, USB_PRODUCT_NETCHIP_TURBOCONNECT, 0)},
267 {USB_VPI(USB_VENDOR_NETCHIP, USB_PRODUCT_NETCHIP_GADGETZERO, 0)},
268 {USB_VPI(USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2301, 0)},
269 {USB_VPI(USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2302, 0)},
270 {USB_VPI(USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL27A1, 0)},
271 {USB_VPI(USB_VENDOR_ANCHOR, USB_PRODUCT_ANCHOR_EZLINK, 0)},
272 {USB_VPI(USB_VENDOR_GENESYS, USB_PRODUCT_GENESYS_GL620USB, 0)},
275 DRIVER_MODULE(udbp, uhub, udbp_driver, udbp_devclass, udbp_modload, 0);
276 MODULE_DEPEND(udbp, netgraph, NG_ABI_VERSION, NG_ABI_VERSION, NG_ABI_VERSION);
277 MODULE_DEPEND(udbp, usb, 1, 1, 1);
278 MODULE_VERSION(udbp, 1);
279 USB_PNP_HOST_INFO(udbp_devs);
282 udbp_modload(module_t mod, int event, void *data)
288 error = ng_newtype(&ng_udbp_typestruct);
290 printf("%s: Could not register "
291 "Netgraph node type, error=%d\n",
292 NG_UDBP_NODE_TYPE, error);
297 error = ng_rmtype(&ng_udbp_typestruct);
308 udbp_probe(device_t dev)
310 struct usb_attach_arg *uaa = device_get_ivars(dev);
312 if (uaa->usb_mode != USB_MODE_HOST)
314 if (uaa->info.bConfigIndex != 0)
316 if (uaa->info.bIfaceIndex != 0)
319 return (usbd_lookup_id_by_uaa(udbp_devs, sizeof(udbp_devs), uaa));
323 udbp_attach(device_t dev)
325 struct usb_attach_arg *uaa = device_get_ivars(dev);
326 struct udbp_softc *sc = device_get_softc(dev);
329 device_set_usb_desc(dev);
331 snprintf(sc->sc_name, sizeof(sc->sc_name),
332 "%s", device_get_nameunit(dev));
334 mtx_init(&sc->sc_mtx, "udbp lock", NULL, MTX_DEF | MTX_RECURSE);
336 error = usbd_transfer_setup(uaa->device, &uaa->info.bIfaceIndex,
337 sc->sc_xfer, udbp_config, UDBP_T_MAX, sc, &sc->sc_mtx);
339 DPRINTF("error=%s\n", usbd_errstr(error));
342 NG_BT_MBUFQ_INIT(&sc->sc_xmitq, UDBP_Q_MAXLEN);
344 NG_BT_MBUFQ_INIT(&sc->sc_xmitq_hipri, UDBP_Q_MAXLEN);
346 /* create Netgraph node */
348 if (ng_make_node_common(&ng_udbp_typestruct, &sc->sc_node) != 0) {
349 printf("%s: Could not create Netgraph node\n",
356 if (ng_name_node(sc->sc_node, sc->sc_name) != 0) {
357 printf("%s: Could not name node\n",
359 NG_NODE_UNREF(sc->sc_node);
363 NG_NODE_SET_PRIVATE(sc->sc_node, sc);
365 /* the device is now operational */
367 return (0); /* success */
371 return (ENOMEM); /* failure */
375 udbp_detach(device_t dev)
377 struct udbp_softc *sc = device_get_softc(dev);
379 /* destroy Netgraph node */
381 if (sc->sc_node != NULL) {
382 NG_NODE_SET_PRIVATE(sc->sc_node, NULL);
383 ng_rmnode_self(sc->sc_node);
386 /* free USB transfers, if any */
388 usbd_transfer_unsetup(sc->sc_xfer, UDBP_T_MAX);
390 mtx_destroy(&sc->sc_mtx);
394 NG_BT_MBUFQ_DESTROY(&sc->sc_xmitq);
395 NG_BT_MBUFQ_DESTROY(&sc->sc_xmitq_hipri);
399 if (sc->sc_bulk_in_buffer) {
400 m_freem(sc->sc_bulk_in_buffer);
401 sc->sc_bulk_in_buffer = NULL;
403 return (0); /* success */
407 udbp_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
409 struct udbp_softc *sc = usbd_xfer_softc(xfer);
410 struct usb_page_cache *pc;
414 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
416 switch (USB_GET_STATE(xfer)) {
417 case USB_ST_TRANSFERRED:
419 /* allocate new mbuf */
421 MGETHDR(m, M_NOWAIT, MT_DATA);
427 if (!(MCLGET(m, M_NOWAIT))) {
431 m->m_pkthdr.len = m->m_len = actlen;
433 pc = usbd_xfer_get_frame(xfer, 0);
434 usbd_copy_out(pc, 0, m->m_data, actlen);
436 sc->sc_bulk_in_buffer = m;
438 DPRINTF("received package %d bytes\n", actlen);
442 if (sc->sc_bulk_in_buffer) {
443 ng_send_fn(sc->sc_node, NULL, &udbp_bulk_read_complete, NULL, 0);
446 if (sc->sc_flags & UDBP_FLAG_READ_STALL) {
447 usbd_transfer_start(sc->sc_xfer[UDBP_T_RD_CS]);
450 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
451 usbd_transfer_submit(xfer);
455 if (error != USB_ERR_CANCELLED) {
456 /* try to clear stall first */
457 sc->sc_flags |= UDBP_FLAG_READ_STALL;
458 usbd_transfer_start(sc->sc_xfer[UDBP_T_RD_CS]);
466 udbp_bulk_read_clear_stall_callback(struct usb_xfer *xfer, usb_error_t error)
468 struct udbp_softc *sc = usbd_xfer_softc(xfer);
469 struct usb_xfer *xfer_other = sc->sc_xfer[UDBP_T_RD];
471 if (usbd_clear_stall_callback(xfer, xfer_other)) {
472 DPRINTF("stall cleared\n");
473 sc->sc_flags &= ~UDBP_FLAG_READ_STALL;
474 usbd_transfer_start(xfer_other);
479 udbp_bulk_read_complete(node_p node, hook_p hook, void *arg1, int arg2)
481 struct udbp_softc *sc = NG_NODE_PRIVATE(node);
488 mtx_lock(&sc->sc_mtx);
490 m = sc->sc_bulk_in_buffer;
494 sc->sc_bulk_in_buffer = NULL;
496 if ((sc->sc_hook == NULL) ||
497 NG_HOOK_NOT_VALID(sc->sc_hook)) {
498 DPRINTF("No upstream hook\n");
503 NG_SEND_DATA_ONLY(error, sc->sc_hook, m);
511 /* start USB bulk-in transfer, if not already started */
513 usbd_transfer_start(sc->sc_xfer[UDBP_T_RD]);
515 mtx_unlock(&sc->sc_mtx);
519 udbp_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
521 struct udbp_softc *sc = usbd_xfer_softc(xfer);
522 struct usb_page_cache *pc;
525 switch (USB_GET_STATE(xfer)) {
526 case USB_ST_TRANSFERRED:
528 sc->sc_packets_out++;
531 if (sc->sc_flags & UDBP_FLAG_WRITE_STALL) {
532 usbd_transfer_start(sc->sc_xfer[UDBP_T_WR_CS]);
535 /* get next mbuf, if any */
537 NG_BT_MBUFQ_DEQUEUE(&sc->sc_xmitq_hipri, m);
539 NG_BT_MBUFQ_DEQUEUE(&sc->sc_xmitq, m);
541 DPRINTF("Data queue is empty\n");
545 if (m->m_pkthdr.len > MCLBYTES) {
546 DPRINTF("truncating large packet "
547 "from %d to %d bytes\n", m->m_pkthdr.len,
549 m->m_pkthdr.len = MCLBYTES;
551 pc = usbd_xfer_get_frame(xfer, 0);
552 usbd_m_copy_in(pc, 0, m, 0, m->m_pkthdr.len);
554 usbd_xfer_set_frame_len(xfer, 0, m->m_pkthdr.len);
556 DPRINTF("packet out: %d bytes\n", m->m_pkthdr.len);
560 usbd_transfer_submit(xfer);
564 if (error != USB_ERR_CANCELLED) {
565 /* try to clear stall first */
566 sc->sc_flags |= UDBP_FLAG_WRITE_STALL;
567 usbd_transfer_start(sc->sc_xfer[UDBP_T_WR_CS]);
575 udbp_bulk_write_clear_stall_callback(struct usb_xfer *xfer, usb_error_t error)
577 struct udbp_softc *sc = usbd_xfer_softc(xfer);
578 struct usb_xfer *xfer_other = sc->sc_xfer[UDBP_T_WR];
580 if (usbd_clear_stall_callback(xfer, xfer_other)) {
581 DPRINTF("stall cleared\n");
582 sc->sc_flags &= ~UDBP_FLAG_WRITE_STALL;
583 usbd_transfer_start(xfer_other);
587 /***********************************************************************
588 * Start of Netgraph methods
589 **********************************************************************/
592 * If this is a device node so this work is done in the attach()
593 * routine and the constructor will return EINVAL as you should not be able
594 * to create nodes that depend on hardware (unless you can add the hardware :)
597 ng_udbp_constructor(node_p node)
603 * Give our ok for a hook to be added...
604 * If we are not running this might kick a device into life.
605 * Possibly decode information out of the hook name.
606 * Add the hook's private info to the hook structure.
607 * (if we had some). In this example, we assume that there is a
608 * an array of structs, called 'channel' in the private info,
609 * one for each active channel. The private
610 * pointer of each hook points to the appropriate UDBP_hookinfo struct
611 * so that the source of an input packet is easily identified.
614 ng_udbp_newhook(node_p node, hook_p hook, const char *name)
616 struct udbp_softc *sc = NG_NODE_PRIVATE(node);
619 if (strcmp(name, NG_UDBP_HOOK_NAME)) {
622 mtx_lock(&sc->sc_mtx);
624 if (sc->sc_hook != NULL) {
628 NG_HOOK_SET_PRIVATE(hook, NULL);
631 mtx_unlock(&sc->sc_mtx);
637 * Get a netgraph control message.
638 * Check it is one we understand. If needed, send a response.
639 * We could save the address for an async action later, but don't here.
640 * Always free the message.
641 * The response should be in a malloc'd region that the caller can 'free'.
642 * A response is not required.
643 * Theoretically you could respond defferently to old message types if
644 * the cookie in the header didn't match what we consider to be current
645 * (so that old userland programs could continue to work).
648 ng_udbp_rcvmsg(node_p node, item_p item, hook_p lasthook)
650 struct udbp_softc *sc = NG_NODE_PRIVATE(node);
651 struct ng_mesg *resp = NULL;
655 NGI_GET_MSG(item, msg);
656 /* Deal with message according to cookie and command */
657 switch (msg->header.typecookie) {
658 case NGM_UDBP_COOKIE:
659 switch (msg->header.cmd) {
660 case NGM_UDBP_GET_STATUS:
662 struct ngudbpstat *stats;
664 NG_MKRESPONSE(resp, msg, sizeof(*stats), M_NOWAIT);
669 stats = (struct ngudbpstat *)resp->data;
670 mtx_lock(&sc->sc_mtx);
671 stats->packets_in = sc->sc_packets_in;
672 stats->packets_out = sc->sc_packets_out;
673 mtx_unlock(&sc->sc_mtx);
676 case NGM_UDBP_SET_FLAG:
677 if (msg->header.arglen != sizeof(uint32_t)) {
681 DPRINTF("flags = 0x%08x\n",
682 *((uint32_t *)msg->data));
685 error = EINVAL; /* unknown command */
690 error = EINVAL; /* unknown cookie type */
694 /* Take care of synchronous response, if any */
695 NG_RESPOND_MSG(error, node, item, resp);
701 * Accept data from the hook and queue it for output.
704 ng_udbp_rcvdata(hook_p hook, item_p item)
706 struct udbp_softc *sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
707 struct ng_bt_mbufq *queue_ptr;
709 struct ng_tag_prio *ptag;
720 * Now queue the data for when it can be sent
722 ptag = (void *)m_tag_locate(m, NGM_GENERIC_COOKIE,
725 if (ptag && (ptag->priority > NG_PRIO_CUTOFF))
726 queue_ptr = &sc->sc_xmitq_hipri;
728 queue_ptr = &sc->sc_xmitq;
730 mtx_lock(&sc->sc_mtx);
732 if (NG_BT_MBUFQ_FULL(queue_ptr)) {
733 NG_BT_MBUFQ_DROP(queue_ptr);
737 NG_BT_MBUFQ_ENQUEUE(queue_ptr, m);
739 * start bulk-out transfer, if not already started:
741 usbd_transfer_start(sc->sc_xfer[UDBP_T_WR]);
745 mtx_unlock(&sc->sc_mtx);
751 * Do local shutdown processing..
752 * We are a persistent device, we refuse to go away, and
753 * only remove our links and reset ourself.
756 ng_udbp_rmnode(node_p node)
758 struct udbp_softc *sc = NG_NODE_PRIVATE(node);
760 /* Let old node go */
761 NG_NODE_SET_PRIVATE(node, NULL);
762 NG_NODE_UNREF(node); /* forget it ever existed */
767 /* Create Netgraph node */
768 if (ng_make_node_common(&ng_udbp_typestruct, &sc->sc_node) != 0) {
769 printf("%s: Could not create Netgraph node\n",
775 if (ng_name_node(sc->sc_node, sc->sc_name) != 0) {
776 printf("%s: Could not name Netgraph node\n",
778 NG_NODE_UNREF(sc->sc_node);
782 NG_NODE_SET_PRIVATE(sc->sc_node, sc);
786 mtx_unlock(&sc->sc_mtx);
792 * This is called once we've already connected a new hook to the other node.
793 * It gives us a chance to balk at the last minute.
796 ng_udbp_connect(hook_p hook)
798 struct udbp_softc *sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
800 /* probably not at splnet, force outward queueing */
801 NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook));
803 mtx_lock(&sc->sc_mtx);
805 sc->sc_flags |= (UDBP_FLAG_READ_STALL |
806 UDBP_FLAG_WRITE_STALL);
808 /* start bulk-in transfer */
809 usbd_transfer_start(sc->sc_xfer[UDBP_T_RD]);
811 /* start bulk-out transfer */
812 usbd_transfer_start(sc->sc_xfer[UDBP_T_WR]);
814 mtx_unlock(&sc->sc_mtx);
822 * For this type, removal of the last link destroys the node
825 ng_udbp_disconnect(hook_p hook)
827 struct udbp_softc *sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
832 mtx_lock(&sc->sc_mtx);
834 if (hook != sc->sc_hook) {
838 /* stop bulk-in transfer */
839 usbd_transfer_stop(sc->sc_xfer[UDBP_T_RD_CS]);
840 usbd_transfer_stop(sc->sc_xfer[UDBP_T_RD]);
842 /* stop bulk-out transfer */
843 usbd_transfer_stop(sc->sc_xfer[UDBP_T_WR_CS]);
844 usbd_transfer_stop(sc->sc_xfer[UDBP_T_WR]);
847 NG_BT_MBUFQ_DRAIN(&sc->sc_xmitq);
848 NG_BT_MBUFQ_DRAIN(&sc->sc_xmitq_hipri);
850 if (sc->sc_bulk_in_buffer) {
851 m_freem(sc->sc_bulk_in_buffer);
852 sc->sc_bulk_in_buffer = NULL;
857 mtx_unlock(&sc->sc_mtx);
859 if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
860 && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook))))
861 ng_rmnode_self(NG_HOOK_NODE(hook));