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, 0, "USB udbp");
102 SYSCTL_INT(_hw_usb_udbp, OID_AUTO, debug, CTLFLAG_RWTUN,
103 &udbp_debug, 0, "udbp debug level");
106 #define UDBP_TIMEOUT 2000 /* timeout on outbound transfers, in
108 #define UDBP_BUFFERSIZE MCLBYTES /* maximum number of bytes in one
112 #define UDBP_T_WR_CS 2
113 #define UDBP_T_RD_CS 3
115 #define UDBP_Q_MAXLEN 50
120 struct ng_bt_mbufq sc_xmitq_hipri; /* hi-priority transmit queue */
121 struct ng_bt_mbufq sc_xmitq; /* low-priority transmit queue */
123 struct usb_xfer *sc_xfer[UDBP_T_MAX];
124 node_p sc_node; /* back pointer to node */
125 hook_p sc_hook; /* pointer to the hook */
126 struct mbuf *sc_bulk_in_buffer;
128 uint32_t sc_packets_in; /* packets in from downstream */
129 uint32_t sc_packets_out; /* packets out towards downstream */
132 #define UDBP_FLAG_READ_STALL 0x01 /* read transfer stalled */
133 #define UDBP_FLAG_WRITE_STALL 0x02 /* write transfer stalled */
140 static int udbp_modload(module_t mod, int event, void *data);
142 static device_probe_t udbp_probe;
143 static device_attach_t udbp_attach;
144 static device_detach_t udbp_detach;
146 static usb_callback_t udbp_bulk_read_callback;
147 static usb_callback_t udbp_bulk_read_clear_stall_callback;
148 static usb_callback_t udbp_bulk_write_callback;
149 static usb_callback_t udbp_bulk_write_clear_stall_callback;
151 static void udbp_bulk_read_complete(node_p, hook_p, void *, int);
153 static ng_constructor_t ng_udbp_constructor;
154 static ng_rcvmsg_t ng_udbp_rcvmsg;
155 static ng_shutdown_t ng_udbp_rmnode;
156 static ng_newhook_t ng_udbp_newhook;
157 static ng_connect_t ng_udbp_connect;
158 static ng_rcvdata_t ng_udbp_rcvdata;
159 static ng_disconnect_t ng_udbp_disconnect;
161 /* Parse type for struct ngudbpstat */
162 static const struct ng_parse_struct_field
163 ng_udbp_stat_type_fields[] = NG_UDBP_STATS_TYPE_INFO;
165 static const struct ng_parse_type ng_udbp_stat_type = {
166 &ng_parse_struct_type,
167 &ng_udbp_stat_type_fields
170 /* List of commands and how to convert arguments to/from ASCII */
171 static const struct ng_cmdlist ng_udbp_cmdlist[] = {
183 &ng_parse_int32_type,
189 /* Netgraph node type descriptor */
190 static struct ng_type ng_udbp_typestruct = {
191 .version = NG_ABI_VERSION,
192 .name = NG_UDBP_NODE_TYPE,
193 .constructor = ng_udbp_constructor,
194 .rcvmsg = ng_udbp_rcvmsg,
195 .shutdown = ng_udbp_rmnode,
196 .newhook = ng_udbp_newhook,
197 .connect = ng_udbp_connect,
198 .rcvdata = ng_udbp_rcvdata,
199 .disconnect = ng_udbp_disconnect,
200 .cmdlist = ng_udbp_cmdlist,
204 static const struct usb_config udbp_config[UDBP_T_MAX] = {
208 .endpoint = UE_ADDR_ANY,
209 .direction = UE_DIR_OUT,
210 .bufsize = UDBP_BUFFERSIZE,
211 .flags = {.pipe_bof = 1,.force_short_xfer = 1,},
212 .callback = &udbp_bulk_write_callback,
213 .timeout = UDBP_TIMEOUT,
218 .endpoint = UE_ADDR_ANY,
219 .direction = UE_DIR_IN,
220 .bufsize = UDBP_BUFFERSIZE,
221 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
222 .callback = &udbp_bulk_read_callback,
227 .endpoint = 0x00, /* Control pipe */
228 .direction = UE_DIR_ANY,
229 .bufsize = sizeof(struct usb_device_request),
230 .callback = &udbp_bulk_write_clear_stall_callback,
231 .timeout = 1000, /* 1 second */
232 .interval = 50, /* 50ms */
237 .endpoint = 0x00, /* Control pipe */
238 .direction = UE_DIR_ANY,
239 .bufsize = sizeof(struct usb_device_request),
240 .callback = &udbp_bulk_read_clear_stall_callback,
241 .timeout = 1000, /* 1 second */
242 .interval = 50, /* 50ms */
246 static devclass_t udbp_devclass;
248 static device_method_t udbp_methods[] = {
249 /* Device interface */
250 DEVMETHOD(device_probe, udbp_probe),
251 DEVMETHOD(device_attach, udbp_attach),
252 DEVMETHOD(device_detach, udbp_detach),
257 static driver_t udbp_driver = {
259 .methods = udbp_methods,
260 .size = sizeof(struct udbp_softc),
263 static const STRUCT_USB_HOST_ID udbp_devs[] = {
264 {USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U258, 0)},
265 {USB_VPI(USB_VENDOR_NETCHIP, USB_PRODUCT_NETCHIP_TURBOCONNECT, 0)},
266 {USB_VPI(USB_VENDOR_NETCHIP, USB_PRODUCT_NETCHIP_GADGETZERO, 0)},
267 {USB_VPI(USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2301, 0)},
268 {USB_VPI(USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2302, 0)},
269 {USB_VPI(USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL27A1, 0)},
270 {USB_VPI(USB_VENDOR_ANCHOR, USB_PRODUCT_ANCHOR_EZLINK, 0)},
271 {USB_VPI(USB_VENDOR_GENESYS, USB_PRODUCT_GENESYS_GL620USB, 0)},
274 DRIVER_MODULE(udbp, uhub, udbp_driver, udbp_devclass, udbp_modload, 0);
275 MODULE_DEPEND(udbp, netgraph, NG_ABI_VERSION, NG_ABI_VERSION, NG_ABI_VERSION);
276 MODULE_DEPEND(udbp, usb, 1, 1, 1);
277 MODULE_VERSION(udbp, 1);
278 USB_PNP_HOST_INFO(udbp_devs);
281 udbp_modload(module_t mod, int event, void *data)
287 error = ng_newtype(&ng_udbp_typestruct);
289 printf("%s: Could not register "
290 "Netgraph node type, error=%d\n",
291 NG_UDBP_NODE_TYPE, error);
296 error = ng_rmtype(&ng_udbp_typestruct);
307 udbp_probe(device_t dev)
309 struct usb_attach_arg *uaa = device_get_ivars(dev);
311 if (uaa->usb_mode != USB_MODE_HOST)
313 if (uaa->info.bConfigIndex != 0)
315 if (uaa->info.bIfaceIndex != 0)
318 return (usbd_lookup_id_by_uaa(udbp_devs, sizeof(udbp_devs), uaa));
322 udbp_attach(device_t dev)
324 struct usb_attach_arg *uaa = device_get_ivars(dev);
325 struct udbp_softc *sc = device_get_softc(dev);
328 device_set_usb_desc(dev);
330 snprintf(sc->sc_name, sizeof(sc->sc_name),
331 "%s", device_get_nameunit(dev));
333 mtx_init(&sc->sc_mtx, "udbp lock", NULL, MTX_DEF | MTX_RECURSE);
335 error = usbd_transfer_setup(uaa->device, &uaa->info.bIfaceIndex,
336 sc->sc_xfer, udbp_config, UDBP_T_MAX, sc, &sc->sc_mtx);
338 DPRINTF("error=%s\n", usbd_errstr(error));
341 NG_BT_MBUFQ_INIT(&sc->sc_xmitq, UDBP_Q_MAXLEN);
343 NG_BT_MBUFQ_INIT(&sc->sc_xmitq_hipri, UDBP_Q_MAXLEN);
345 /* create Netgraph node */
347 if (ng_make_node_common(&ng_udbp_typestruct, &sc->sc_node) != 0) {
348 printf("%s: Could not create Netgraph node\n",
355 if (ng_name_node(sc->sc_node, sc->sc_name) != 0) {
356 printf("%s: Could not name node\n",
358 NG_NODE_UNREF(sc->sc_node);
362 NG_NODE_SET_PRIVATE(sc->sc_node, sc);
364 /* the device is now operational */
366 return (0); /* success */
370 return (ENOMEM); /* failure */
374 udbp_detach(device_t dev)
376 struct udbp_softc *sc = device_get_softc(dev);
378 /* destroy Netgraph node */
380 if (sc->sc_node != NULL) {
381 NG_NODE_SET_PRIVATE(sc->sc_node, NULL);
382 ng_rmnode_self(sc->sc_node);
385 /* free USB transfers, if any */
387 usbd_transfer_unsetup(sc->sc_xfer, UDBP_T_MAX);
389 mtx_destroy(&sc->sc_mtx);
393 NG_BT_MBUFQ_DESTROY(&sc->sc_xmitq);
394 NG_BT_MBUFQ_DESTROY(&sc->sc_xmitq_hipri);
398 if (sc->sc_bulk_in_buffer) {
399 m_freem(sc->sc_bulk_in_buffer);
400 sc->sc_bulk_in_buffer = NULL;
402 return (0); /* success */
406 udbp_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
408 struct udbp_softc *sc = usbd_xfer_softc(xfer);
409 struct usb_page_cache *pc;
413 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
415 switch (USB_GET_STATE(xfer)) {
416 case USB_ST_TRANSFERRED:
418 /* allocate new mbuf */
420 MGETHDR(m, M_NOWAIT, MT_DATA);
426 if (!(MCLGET(m, M_NOWAIT))) {
430 m->m_pkthdr.len = m->m_len = actlen;
432 pc = usbd_xfer_get_frame(xfer, 0);
433 usbd_copy_out(pc, 0, m->m_data, actlen);
435 sc->sc_bulk_in_buffer = m;
437 DPRINTF("received package %d bytes\n", actlen);
441 if (sc->sc_bulk_in_buffer) {
442 ng_send_fn(sc->sc_node, NULL, &udbp_bulk_read_complete, NULL, 0);
445 if (sc->sc_flags & UDBP_FLAG_READ_STALL) {
446 usbd_transfer_start(sc->sc_xfer[UDBP_T_RD_CS]);
449 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
450 usbd_transfer_submit(xfer);
454 if (error != USB_ERR_CANCELLED) {
455 /* try to clear stall first */
456 sc->sc_flags |= UDBP_FLAG_READ_STALL;
457 usbd_transfer_start(sc->sc_xfer[UDBP_T_RD_CS]);
465 udbp_bulk_read_clear_stall_callback(struct usb_xfer *xfer, usb_error_t error)
467 struct udbp_softc *sc = usbd_xfer_softc(xfer);
468 struct usb_xfer *xfer_other = sc->sc_xfer[UDBP_T_RD];
470 if (usbd_clear_stall_callback(xfer, xfer_other)) {
471 DPRINTF("stall cleared\n");
472 sc->sc_flags &= ~UDBP_FLAG_READ_STALL;
473 usbd_transfer_start(xfer_other);
478 udbp_bulk_read_complete(node_p node, hook_p hook, void *arg1, int arg2)
480 struct udbp_softc *sc = NG_NODE_PRIVATE(node);
487 mtx_lock(&sc->sc_mtx);
489 m = sc->sc_bulk_in_buffer;
493 sc->sc_bulk_in_buffer = NULL;
495 if ((sc->sc_hook == NULL) ||
496 NG_HOOK_NOT_VALID(sc->sc_hook)) {
497 DPRINTF("No upstream hook\n");
502 NG_SEND_DATA_ONLY(error, sc->sc_hook, m);
510 /* start USB bulk-in transfer, if not already started */
512 usbd_transfer_start(sc->sc_xfer[UDBP_T_RD]);
514 mtx_unlock(&sc->sc_mtx);
518 udbp_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
520 struct udbp_softc *sc = usbd_xfer_softc(xfer);
521 struct usb_page_cache *pc;
524 switch (USB_GET_STATE(xfer)) {
525 case USB_ST_TRANSFERRED:
527 sc->sc_packets_out++;
530 if (sc->sc_flags & UDBP_FLAG_WRITE_STALL) {
531 usbd_transfer_start(sc->sc_xfer[UDBP_T_WR_CS]);
534 /* get next mbuf, if any */
536 NG_BT_MBUFQ_DEQUEUE(&sc->sc_xmitq_hipri, m);
538 NG_BT_MBUFQ_DEQUEUE(&sc->sc_xmitq, m);
540 DPRINTF("Data queue is empty\n");
544 if (m->m_pkthdr.len > MCLBYTES) {
545 DPRINTF("truncating large packet "
546 "from %d to %d bytes\n", m->m_pkthdr.len,
548 m->m_pkthdr.len = MCLBYTES;
550 pc = usbd_xfer_get_frame(xfer, 0);
551 usbd_m_copy_in(pc, 0, m, 0, m->m_pkthdr.len);
553 usbd_xfer_set_frame_len(xfer, 0, m->m_pkthdr.len);
555 DPRINTF("packet out: %d bytes\n", m->m_pkthdr.len);
559 usbd_transfer_submit(xfer);
563 if (error != USB_ERR_CANCELLED) {
564 /* try to clear stall first */
565 sc->sc_flags |= UDBP_FLAG_WRITE_STALL;
566 usbd_transfer_start(sc->sc_xfer[UDBP_T_WR_CS]);
574 udbp_bulk_write_clear_stall_callback(struct usb_xfer *xfer, usb_error_t error)
576 struct udbp_softc *sc = usbd_xfer_softc(xfer);
577 struct usb_xfer *xfer_other = sc->sc_xfer[UDBP_T_WR];
579 if (usbd_clear_stall_callback(xfer, xfer_other)) {
580 DPRINTF("stall cleared\n");
581 sc->sc_flags &= ~UDBP_FLAG_WRITE_STALL;
582 usbd_transfer_start(xfer_other);
586 /***********************************************************************
587 * Start of Netgraph methods
588 **********************************************************************/
591 * If this is a device node so this work is done in the attach()
592 * routine and the constructor will return EINVAL as you should not be able
593 * to create nodes that depend on hardware (unless you can add the hardware :)
596 ng_udbp_constructor(node_p node)
602 * Give our ok for a hook to be added...
603 * If we are not running this might kick a device into life.
604 * Possibly decode information out of the hook name.
605 * Add the hook's private info to the hook structure.
606 * (if we had some). In this example, we assume that there is a
607 * an array of structs, called 'channel' in the private info,
608 * one for each active channel. The private
609 * pointer of each hook points to the appropriate UDBP_hookinfo struct
610 * so that the source of an input packet is easily identified.
613 ng_udbp_newhook(node_p node, hook_p hook, const char *name)
615 struct udbp_softc *sc = NG_NODE_PRIVATE(node);
618 if (strcmp(name, NG_UDBP_HOOK_NAME)) {
621 mtx_lock(&sc->sc_mtx);
623 if (sc->sc_hook != NULL) {
627 NG_HOOK_SET_PRIVATE(hook, NULL);
630 mtx_unlock(&sc->sc_mtx);
636 * Get a netgraph control message.
637 * Check it is one we understand. If needed, send a response.
638 * We could save the address for an async action later, but don't here.
639 * Always free the message.
640 * The response should be in a malloc'd region that the caller can 'free'.
641 * A response is not required.
642 * Theoretically you could respond defferently to old message types if
643 * the cookie in the header didn't match what we consider to be current
644 * (so that old userland programs could continue to work).
647 ng_udbp_rcvmsg(node_p node, item_p item, hook_p lasthook)
649 struct udbp_softc *sc = NG_NODE_PRIVATE(node);
650 struct ng_mesg *resp = NULL;
654 NGI_GET_MSG(item, msg);
655 /* Deal with message according to cookie and command */
656 switch (msg->header.typecookie) {
657 case NGM_UDBP_COOKIE:
658 switch (msg->header.cmd) {
659 case NGM_UDBP_GET_STATUS:
661 struct ngudbpstat *stats;
663 NG_MKRESPONSE(resp, msg, sizeof(*stats), M_NOWAIT);
668 stats = (struct ngudbpstat *)resp->data;
669 mtx_lock(&sc->sc_mtx);
670 stats->packets_in = sc->sc_packets_in;
671 stats->packets_out = sc->sc_packets_out;
672 mtx_unlock(&sc->sc_mtx);
675 case NGM_UDBP_SET_FLAG:
676 if (msg->header.arglen != sizeof(uint32_t)) {
680 DPRINTF("flags = 0x%08x\n",
681 *((uint32_t *)msg->data));
684 error = EINVAL; /* unknown command */
689 error = EINVAL; /* unknown cookie type */
693 /* Take care of synchronous response, if any */
694 NG_RESPOND_MSG(error, node, item, resp);
700 * Accept data from the hook and queue it for output.
703 ng_udbp_rcvdata(hook_p hook, item_p item)
705 struct udbp_softc *sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
706 struct ng_bt_mbufq *queue_ptr;
708 struct ng_tag_prio *ptag;
719 * Now queue the data for when it can be sent
721 ptag = (void *)m_tag_locate(m, NGM_GENERIC_COOKIE,
724 if (ptag && (ptag->priority > NG_PRIO_CUTOFF))
725 queue_ptr = &sc->sc_xmitq_hipri;
727 queue_ptr = &sc->sc_xmitq;
729 mtx_lock(&sc->sc_mtx);
731 if (NG_BT_MBUFQ_FULL(queue_ptr)) {
732 NG_BT_MBUFQ_DROP(queue_ptr);
736 NG_BT_MBUFQ_ENQUEUE(queue_ptr, m);
738 * start bulk-out transfer, if not already started:
740 usbd_transfer_start(sc->sc_xfer[UDBP_T_WR]);
744 mtx_unlock(&sc->sc_mtx);
750 * Do local shutdown processing..
751 * We are a persistent device, we refuse to go away, and
752 * only remove our links and reset ourself.
755 ng_udbp_rmnode(node_p node)
757 struct udbp_softc *sc = NG_NODE_PRIVATE(node);
759 /* Let old node go */
760 NG_NODE_SET_PRIVATE(node, NULL);
761 NG_NODE_UNREF(node); /* forget it ever existed */
766 /* Create Netgraph node */
767 if (ng_make_node_common(&ng_udbp_typestruct, &sc->sc_node) != 0) {
768 printf("%s: Could not create Netgraph node\n",
774 if (ng_name_node(sc->sc_node, sc->sc_name) != 0) {
775 printf("%s: Could not name Netgraph node\n",
777 NG_NODE_UNREF(sc->sc_node);
781 NG_NODE_SET_PRIVATE(sc->sc_node, sc);
785 mtx_unlock(&sc->sc_mtx);
791 * This is called once we've already connected a new hook to the other node.
792 * It gives us a chance to balk at the last minute.
795 ng_udbp_connect(hook_p hook)
797 struct udbp_softc *sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
799 /* probably not at splnet, force outward queueing */
800 NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook));
802 mtx_lock(&sc->sc_mtx);
804 sc->sc_flags |= (UDBP_FLAG_READ_STALL |
805 UDBP_FLAG_WRITE_STALL);
807 /* start bulk-in transfer */
808 usbd_transfer_start(sc->sc_xfer[UDBP_T_RD]);
810 /* start bulk-out transfer */
811 usbd_transfer_start(sc->sc_xfer[UDBP_T_WR]);
813 mtx_unlock(&sc->sc_mtx);
821 * For this type, removal of the last link destroys the node
824 ng_udbp_disconnect(hook_p hook)
826 struct udbp_softc *sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
831 mtx_lock(&sc->sc_mtx);
833 if (hook != sc->sc_hook) {
837 /* stop bulk-in transfer */
838 usbd_transfer_stop(sc->sc_xfer[UDBP_T_RD_CS]);
839 usbd_transfer_stop(sc->sc_xfer[UDBP_T_RD]);
841 /* stop bulk-out transfer */
842 usbd_transfer_stop(sc->sc_xfer[UDBP_T_WR_CS]);
843 usbd_transfer_stop(sc->sc_xfer[UDBP_T_WR]);
846 NG_BT_MBUFQ_DRAIN(&sc->sc_xmitq);
847 NG_BT_MBUFQ_DRAIN(&sc->sc_xmitq_hipri);
849 if (sc->sc_bulk_in_buffer) {
850 m_freem(sc->sc_bulk_in_buffer);
851 sc->sc_bulk_in_buffer = NULL;
856 mtx_unlock(&sc->sc_mtx);
858 if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
859 && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook))))
860 ng_rmnode_self(NG_HOOK_NODE(hook));