2 * Copyright (c) 1996-2000 Whistle Communications, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of author nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY NICK HIBMA AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
29 * $FreeBSD: src/sys/dev/usb/udbp.c,v 1.24 2003/08/24 17:55:55 obrien Exp $
30 * $DragonFly: src/sys/dev/usbmisc/udbp/Attic/udbp.c,v 1.16 2007/11/05 13:32:28 hasso Exp $
33 /* Driver for arbitrary double bulk pipe devices.
34 * The driver assumes that there will be the same driver on the other side.
36 * XXX Some more information on what the framing of the IP packets looks like.
38 * To take full advantage of bulk transmission, packets should be chosen
39 * between 1k and 5k in size (1k to make sure the sending side starts
40 * straming, and <5k to avoid overflowing the system with small TDs).
44 /* probe/attach/detach:
45 * Connect the driver to the hardware and netgraph
47 * udbp_setup_out_transfer(sc);
48 * Setup an outbound transfer. Only one transmit can be active at the same
50 * XXX If it is required that the driver is able to queue multiple requests
51 * let me know. That is slightly difficult, due to the fact that we
52 * cannot call usbd_alloc_xfer in int context.
54 * udbp_setup_in_transfer(sc)
55 * Prepare an in transfer that will be waiting for data to come in. It
56 * is submitted and sits there until data is available.
57 * The callback resubmits a new transfer on completion.
59 * The reason we submit a bulk in transfer is that USB does not know about
60 * interrupts. The bulk transfer continuously polls the device for data.
61 * While the device has no data available, the device NAKs the TDs. As soon
62 * as there is data, the transfer happens and the data comes flowing in.
64 * In case you were wondering, interrupt transfers happen exactly that way.
65 * It therefore doesn't make sense to use the interrupt pipe to signal
66 * 'data ready' and then schedule a bulk transfer to fetch it. That would
67 * incur a 2ms delay at least, without reducing bandwidth requirements.
73 #include <sys/param.h>
74 #include <sys/systm.h>
75 #include <sys/kernel.h>
76 #include <sys/malloc.h>
77 #include <sys/module.h>
81 #include <sys/select.h>
84 #include <sys/socket.h>
85 #include <sys/ctype.h>
86 #include <sys/errno.h>
87 #include <sys/sysctl.h>
88 #include <sys/thread2.h>
92 #include <dev/usb/usb.h>
93 #include <dev/usb/usbdi.h>
94 #include <dev/usb/usbdi_util.h>
95 #include <dev/usb/usbdivar.h>
96 #include <dev/usb/usbhid.h>
98 #include <dev/usb/usbdevs.h>
101 #include <netgraph/ng_message.h>
102 #include <netgraph/ng_parse.h>
103 #include <dev/usb/udbp.h>
104 #include <netgraph/netgraph.h>
107 #define DPRINTF(x) if (udbpdebug) kprintf x
108 #define DPRINTFN(n,x) if (udbpdebug>(n)) kprintf x
110 SYSCTL_NODE(_hw_usb, OID_AUTO, udbp, CTLFLAG_RW, 0, "USB udbp");
111 SYSCTL_INT(_hw_usb_udbp, OID_AUTO, debug, CTLFLAG_RW,
112 &udbpdebug, 0, "udbp debug level");
115 #define DPRINTFN(n,x)
118 #define MS_TO_TICKS(ms) ((ms) * hz / 1000)
120 #define UDBP_TIMEOUT 2000 /* timeout on outbound transfers, in msecs */
121 #define UDBP_BUFFERSIZE 2048 /* maximum number of bytes in one transfer */
125 device_t sc_dev; /* base device */
126 usbd_interface_handle sc_iface;
128 usbd_pipe_handle sc_bulkin_pipe;
130 usbd_xfer_handle sc_bulkin_xfer;
131 void *sc_bulkin_buffer;
132 int sc_bulkin_bufferlen;
133 int sc_bulkin_datalen;
135 usbd_pipe_handle sc_bulkout_pipe;
137 usbd_xfer_handle sc_bulkout_xfer;
138 void *sc_bulkout_buffer;
139 int sc_bulkout_bufferlen;
140 int sc_bulkout_datalen;
143 # define DISCONNECTED 0x01
144 # define OUT_BUSY 0x02
145 # define NETGRAPH_INITIALISED 0x04
146 node_p node; /* back pointer to node */
147 hook_p hook; /* pointer to the hook */
148 u_int packets_in; /* packets in from downstream */
149 u_int packets_out; /* packets out towards downstream */
150 struct ifqueue xmitq_hipri; /* hi-priority transmit queue */
151 struct ifqueue xmitq; /* low-priority transmit queue */
154 typedef struct udbp_softc *udbp_p;
158 static ng_constructor_t ng_udbp_constructor;
159 static ng_rcvmsg_t ng_udbp_rcvmsg;
160 static ng_shutdown_t ng_udbp_rmnode;
161 static ng_newhook_t ng_udbp_newhook;
162 static ng_connect_t ng_udbp_connect;
163 static ng_rcvdata_t ng_udbp_rcvdata;
164 static ng_disconnect_t ng_udbp_disconnect;
166 /* Parse type for struct ngudbpstat */
167 static const struct ng_parse_struct_field
168 ng_udbp_stat_type_fields[] = NG_UDBP_STATS_TYPE_INFO;
169 static const struct ng_parse_type ng_udbp_stat_type = {
170 &ng_parse_struct_type,
171 &ng_udbp_stat_type_fields
174 /* List of commands and how to convert arguments to/from ASCII */
175 static const struct ng_cmdlist ng_udbp_cmdlist[] = {
187 &ng_parse_int32_type,
193 /* Netgraph node type descriptor */
194 static struct ng_type ng_udbp_typestruct = {
209 static int udbp_setup_in_transfer (udbp_p sc);
210 static void udbp_in_transfer_cb (usbd_xfer_handle xfer,
211 usbd_private_handle priv,
214 static int udbp_setup_out_transfer (udbp_p sc);
215 static void udbp_out_transfer_cb (usbd_xfer_handle xfer,
216 usbd_private_handle priv,
219 static const struct usb_devno udbp_devs[] = {
220 { USB_DEVICE(0x0525, 0x1080) }, /* NetChip Turbo-Connect */
221 { USB_DEVICE(0x0547, 0x2720) }, /* Anchor EZLINK */
222 { USB_DEVICE(0x067b, 0x0000) }, /* Prolific PL2301 */
223 { USB_DEVICE(0x067b, 0x0001) }, /* Prolofic PL2302 */
226 static device_probe_t udbp_match;
227 static device_attach_t udbp_attach;
228 static device_detach_t udbp_detach;
230 static devclass_t udbp_devclass;
232 static kobj_method_t udbp_methods[] = {
233 DEVMETHOD(device_probe, udbp_match),
234 DEVMETHOD(device_attach, udbp_attach),
235 DEVMETHOD(device_detach, udbp_detach),
239 static driver_t udbp_driver = {
242 sizeof(struct udbp_softc)
245 MODULE_DEPEND(udbp, usb, 1, 1, 1);
248 udbp_match(device_t self)
250 struct usb_attach_arg *uaa = device_get_ivars(self);
252 if (uaa->iface == NULL)
253 return (UMATCH_NONE);
255 return (usb_lookup(udbp_devs, uaa->vendor, uaa->product) != NULL) ?
256 UMATCH_VENDOR_PRODUCT : UMATCH_NONE;
260 udbp_attach(device_t self)
262 struct udbp_softc *sc = device_get_softc(self);
263 struct usb_attach_arg *uaa = device_get_ivars(self);
264 usbd_interface_handle iface = uaa->iface;
265 usb_interface_descriptor_t *id;
266 usb_endpoint_descriptor_t *ed, *ed_bulkin = NULL, *ed_bulkout = NULL;
270 static int ngudbp_done_init=0;
272 sc->flags |= DISCONNECTED;
273 /* fetch the interface handle for the first interface */
274 (void) usbd_device2interface_handle(uaa->device, 0, &iface);
275 id = usbd_get_interface_descriptor(iface);
276 usbd_devinfo(uaa->device, 0, devinfo);
278 device_set_desc_copy(self, devinfo);
279 kprintf("%s: %s, iclass %d/%d\n", device_get_nameunit(sc->sc_dev),
280 devinfo, id->bInterfaceClass, id->bInterfaceSubClass);
282 /* Find the two first bulk endpoints */
283 for (i = 0 ; i < id->bNumEndpoints; i++) {
284 ed = usbd_interface2endpoint_descriptor(iface, i);
286 kprintf("%s: could not read endpoint descriptor\n",
287 device_get_nameunit(sc->sc_dev));
291 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN
292 && (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
294 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT
295 && (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
299 if (ed_bulkin && ed_bulkout) /* found all we need */
303 /* Verify that we goething sensible */
304 if (ed_bulkin == NULL || ed_bulkout == NULL) {
305 kprintf("%s: bulk-in and/or bulk-out endpoint not found\n",
306 device_get_nameunit(sc->sc_dev));
310 if (ed_bulkin->wMaxPacketSize[0] != ed_bulkout->wMaxPacketSize[0] ||
311 ed_bulkin->wMaxPacketSize[1] != ed_bulkout->wMaxPacketSize[1]) {
312 kprintf("%s: bulk-in and bulk-out have different packet sizes %d %d %d %d\n",
313 device_get_nameunit(sc->sc_dev),
314 ed_bulkin->wMaxPacketSize[0],
315 ed_bulkout->wMaxPacketSize[0],
316 ed_bulkin->wMaxPacketSize[1],
317 ed_bulkout->wMaxPacketSize[1]);
321 sc->sc_bulkin = ed_bulkin->bEndpointAddress;
322 sc->sc_bulkout = ed_bulkout->bEndpointAddress;
324 DPRINTF(("%s: Bulk-in: 0x%02x, bulk-out 0x%02x, packet size = %d\n",
325 device_get_nameunit(sc->sc_dev), sc->sc_bulkin, sc->sc_bulkout,
326 ed_bulkin->wMaxPacketSize[0]));
328 /* Allocate the in transfer struct */
329 sc->sc_bulkin_xfer = usbd_alloc_xfer(uaa->device);
330 if (!sc->sc_bulkin_xfer) {
333 sc->sc_bulkout_xfer = usbd_alloc_xfer(uaa->device);
334 if (!sc->sc_bulkout_xfer) {
337 sc->sc_bulkin_buffer = kmalloc(UDBP_BUFFERSIZE, M_USBDEV, M_INTWAIT);
338 if (!sc->sc_bulkin_buffer) {
341 sc->sc_bulkout_buffer = kmalloc(UDBP_BUFFERSIZE, M_USBDEV, M_INTWAIT);
342 if (!sc->sc_bulkout_xfer || !sc->sc_bulkout_buffer) {
345 sc->sc_bulkin_bufferlen = UDBP_BUFFERSIZE;
346 sc->sc_bulkout_bufferlen = UDBP_BUFFERSIZE;
348 /* We have decided on which endpoints to use, now open the pipes */
349 err = usbd_open_pipe(iface, sc->sc_bulkin,
350 USBD_EXCLUSIVE_USE, &sc->sc_bulkin_pipe);
352 kprintf("%s: cannot open bulk-in pipe (addr %d)\n",
353 device_get_nameunit(sc->sc_dev), sc->sc_bulkin);
356 err = usbd_open_pipe(iface, sc->sc_bulkout,
357 USBD_EXCLUSIVE_USE, &sc->sc_bulkout_pipe);
359 kprintf("%s: cannot open bulk-out pipe (addr %d)\n",
360 device_get_nameunit(sc->sc_dev), sc->sc_bulkout);
364 if (!ngudbp_done_init){
366 if (ng_newtype(&ng_udbp_typestruct)) {
367 kprintf("ngudbp install failed\n");
372 if ((err = ng_make_node_common(&ng_udbp_typestruct, &sc->node)) == 0) {
374 ksprintf(nodename, "%s", device_get_nameunit(sc->sc_dev));
375 if ((err = ng_name_node(sc->node, nodename))) {
376 NG_NODE_UNREF(sc->node);
380 NG_NODE_SET_PRIVATE(sc->node, sc);
381 sc->xmitq.ifq_maxlen = IFQ_MAXLEN;
382 sc->xmitq_hipri.ifq_maxlen = IFQ_MAXLEN;
383 mtx_init(&sc->xmitq.ifq_mtx, "usb_xmitq", NULL,
385 mtx_init(&sc->xmitq_hipri.ifq_mtx,
386 "usb_xmitq_hipri", NULL, MTX_DEF);
389 sc->flags = NETGRAPH_INITIALISED;
390 /* sc->flags &= ~DISCONNECTED; */ /* XXX */
393 /* the device is now operational */
396 /* schedule the first incoming xfer */
397 err = udbp_setup_in_transfer(sc);
403 #if 0 /* probably done in udbp_detach() */
404 if (sc->sc_bulkout_buffer) {
405 FREE(sc->sc_bulkout_buffer, M_USBDEV);
407 if (sc->sc_bulkin_buffer) {
408 FREE(sc->sc_bulkin_buffer, M_USBDEV);
410 if (sc->sc_bulkout_xfer) {
411 usbd_free_xfer(sc->sc_bulkout_xfer);
413 if (sc->sc_bulkin_xfer) {
414 usbd_free_xfer(sc->sc_bulkin_xfer);
423 udbp_detach(device_t self)
425 struct udbp_softc *sc = device_get_softc(self);
427 sc->flags |= DISCONNECTED;
429 DPRINTF(("%s: disconnected\n", device_get_nameunit(self)));
431 if (sc->sc_bulkin_pipe) {
432 usbd_abort_pipe(sc->sc_bulkin_pipe);
433 usbd_close_pipe(sc->sc_bulkin_pipe);
435 if (sc->sc_bulkout_pipe) {
436 usbd_abort_pipe(sc->sc_bulkout_pipe);
437 usbd_close_pipe(sc->sc_bulkout_pipe);
440 if (sc->flags & NETGRAPH_INITIALISED) {
441 ng_rmnode_self(sc->node);
442 NG_NODE_SET_PRIVATE(sc->node, NULL);
443 NG_NODE_UNREF(sc->node);
444 sc->node = NULL; /* Paranoid */
447 if (sc->sc_bulkin_xfer)
448 usbd_free_xfer(sc->sc_bulkin_xfer);
449 if (sc->sc_bulkout_xfer)
450 usbd_free_xfer(sc->sc_bulkout_xfer);
452 if (sc->sc_bulkin_buffer)
453 kfree(sc->sc_bulkin_buffer, M_USBDEV);
454 if (sc->sc_bulkout_buffer)
455 kfree(sc->sc_bulkout_buffer, M_USBDEV);
461 udbp_setup_in_transfer(udbp_p sc)
463 void *priv = sc; /* XXX this should probably be some pointer to
464 * struct describing the transfer (mbuf?)
470 * How should we arrange for 2 extra bytes at the start of the
474 /* Initialise a USB transfer and then schedule it */
476 (void) usbd_setup_xfer( sc->sc_bulkin_xfer,
479 sc->sc_bulkin_buffer,
480 sc->sc_bulkin_bufferlen,
483 udbp_in_transfer_cb);
485 err = usbd_transfer(sc->sc_bulkin_xfer);
486 if (err && err != USBD_IN_PROGRESS) {
487 DPRINTF(("%s: failed to setup in-transfer, %s\n",
488 device_get_nameunit(sc->sc_dev), usbd_errstr(err)));
492 return (USBD_NORMAL_COMPLETION);
496 udbp_in_transfer_cb(usbd_xfer_handle xfer, usbd_private_handle priv,
499 udbp_p sc = priv; /* XXX see priv above */
505 if (err != USBD_CANCELLED) {
506 DPRINTF(("%s: bulk-out transfer failed: %s\n",
507 device_get_nameunit(sc->sc_dev), usbd_errstr(err)));
509 /* USBD_CANCELLED happens at unload of the driver */
513 /* Transfer has failed, packet is not received */
520 /* get packet from device and send on */
521 m = m_devget(sc->sc_bulkin_buffer, len, 0, NULL, NULL);
522 NG_SEND_DATA_ONLY(err, sc->hook, m);
527 /* schedule the next in transfer */
528 udbp_setup_in_transfer(sc);
533 udbp_setup_out_transfer(udbp_p sc)
535 void *priv = sc; /* XXX this should probably be some pointer to
536 * struct describing the transfer (mbuf?)
544 if (sc->flags & OUT_BUSY)
545 panic("out transfer already in use, we should add queuing");
546 sc->flags |= OUT_BUSY;
549 IF_DEQUEUE(&sc->xmitq_hipri, m);
551 IF_DEQUEUE(&sc->xmitq, m);
556 sc->flags &= ~OUT_BUSY;
557 return (USBD_NORMAL_COMPLETION);
560 pktlen = m->m_pkthdr.len;
561 if (pktlen > sc->sc_bulkout_bufferlen) {
562 kprintf("%s: Packet too large, %d > %d\n",
563 device_get_nameunit(sc->sc_dev), pktlen,
564 sc->sc_bulkout_bufferlen);
565 return (USBD_IOERROR);
568 m_copydata(m, 0, pktlen, sc->sc_bulkout_buffer);
571 /* Initialise a USB transfer and then schedule it */
573 (void) usbd_setup_xfer( sc->sc_bulkout_xfer,
576 sc->sc_bulkout_buffer,
580 udbp_out_transfer_cb);
582 err = usbd_transfer(sc->sc_bulkout_xfer);
583 if (err && err != USBD_IN_PROGRESS) {
584 DPRINTF(("%s: failed to setup out-transfer, %s\n",
585 device_get_nameunit(sc->sc_dev), usbd_errstr(err)));
589 return (USBD_NORMAL_COMPLETION);
593 udbp_out_transfer_cb(usbd_xfer_handle xfer, usbd_private_handle priv,
596 udbp_p sc = priv; /* XXX see priv above */
599 DPRINTF(("%s: bulk-out transfer failed: %s\n",
600 device_get_nameunit(sc->sc_dev), usbd_errstr(err)));
601 /* Transfer has failed, packet is not transmitted */
602 /* XXX Invalidate packet */
606 /* packet has been transmitted */
609 sc->flags &= ~OUT_BUSY;
610 udbp_setup_out_transfer(sc);
614 DRIVER_MODULE(udbp, uhub, udbp_driver, udbp_devclass, usbd_driver_load, 0);
615 MODULE_DEPEND(udbp, netgraph, NG_ABI_VERSION, NG_ABI_VERSION, NG_ABI_VERSION);
618 /***********************************************************************
619 * Start of Netgraph methods
620 **********************************************************************/
623 * If this is a device node so this work is done in the attach()
624 * routine and the constructor will return EINVAL as you should not be able
625 * to create nodes that depend on hardware (unless you can add the hardware :)
628 ng_udbp_constructor(node_p node)
634 * Give our ok for a hook to be added...
635 * If we are not running this might kick a device into life.
636 * Possibly decode information out of the hook name.
637 * Add the hook's private info to the hook structure.
638 * (if we had some). In this example, we assume that there is a
639 * an array of structs, called 'channel' in the private info,
640 * one for each active channel. The private
641 * pointer of each hook points to the appropriate UDBP_hookinfo struct
642 * so that the source of an input packet is easily identified.
645 ng_udbp_newhook(node_p node, hook_p hook, const char *name)
647 const udbp_p sc = NG_NODE_PRIVATE(node);
650 /* Possibly start up the device if it's not already going */
651 if ((sc->flags & SCF_RUNNING) == 0) {
652 ng_udbp_start_hardware(sc);
656 if (strcmp(name, NG_UDBP_HOOK_NAME) == 0) {
658 NG_HOOK_SET_PRIVATE(hook, NULL);
660 return (EINVAL); /* not a hook we know about */
666 * Get a netgraph control message.
667 * Check it is one we understand. If needed, send a response.
668 * We could save the address for an async action later, but don't here.
669 * Always free the message.
670 * The response should be in a malloc'd region that the caller can 'free'.
671 * A response is not required.
672 * Theoretically you could respond defferently to old message types if
673 * the cookie in the header didn't match what we consider to be current
674 * (so that old userland programs could continue to work).
677 ng_udbp_rcvmsg(node_p node, item_p item, hook_p lasthook)
679 const udbp_p sc = NG_NODE_PRIVATE(node);
680 struct ng_mesg *resp = NULL;
684 NGI_GET_MSG(item, msg);
685 /* Deal with message according to cookie and command */
686 switch (msg->header.typecookie) {
687 case NGM_UDBP_COOKIE:
688 switch (msg->header.cmd) {
689 case NGM_UDBP_GET_STATUS:
691 struct ngudbpstat *stats;
693 NG_MKRESPONSE(resp, msg, sizeof(*stats), M_NOWAIT);
698 stats = (struct ngudbpstat *) resp->data;
699 stats->packets_in = sc->packets_in;
700 stats->packets_out = sc->packets_out;
703 case NGM_UDBP_SET_FLAG:
704 if (msg->header.arglen != sizeof(u_int32_t)) {
708 sc->flags = *((u_int32_t *) msg->data);
711 error = EINVAL; /* unknown command */
716 error = EINVAL; /* unknown cookie type */
720 /* Take care of synchronous response, if any */
721 NG_RESPOND_MSG(error, node, item, resp);
727 * Accept data from the hook and queue it for output.
730 ng_udbp_rcvdata(hook_p hook, item_p item)
732 const udbp_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
734 struct ifqueue *xmitq_p;
739 NGI_GET_META(item, meta);
742 * Now queue the data for when it can be sent
744 if (meta && meta->priority > 0) {
745 xmitq_p = (&sc->xmitq_hipri);
747 xmitq_p = (&sc->xmitq);
750 if (IF_QFULL(xmitq_p)) {
756 IF_ENQUEUE(xmitq_p, m);
757 if (!(sc->flags & OUT_BUSY))
758 udbp_setup_out_transfer(sc);
763 * It was an error case.
764 * check if we need to free the mbuf, and then return the error
772 * Do local shutdown processing..
773 * We are a persistant device, we refuse to go away, and
774 * only remove our links and reset ourself.
777 ng_udbp_rmnode(node_p node)
779 const udbp_p sc = NG_NODE_PRIVATE(node);
782 if (sc->flags & DISCONNECTED) {
784 * WE are really going away.. hardware must have gone.
785 * Assume that the hardware drive part will clear up the
786 * sc, in fact it may already have done so..
787 * In which case we may have just segfaulted..XXX
792 /* stolen from attach routine */
793 /* Drain the queues */
794 IF_DRAIN(&sc->xmitq_hipri);
795 IF_DRAIN(&sc->xmitq);
797 sc->packets_in = 0; /* reset stats */
799 NG_NODE_UNREF(node); /* forget it ever existed */
801 if ((err = ng_make_node_common(&ng_udbp_typestruct, &sc->node)) == 0) {
803 ksprintf(nodename, "%s", device_get_nameunit(sc->sc_dev));
804 if ((err = ng_name_node(sc->node, nodename))) {
805 NG_NODE_UNREF(sc->node); /* out damned spot! */
806 sc->flags &= ~NETGRAPH_INITIALISED;
809 NG_NODE_SET_PRIVATE(sc->node, sc);
816 * This is called once we've already connected a new hook to the other node.
817 * It gives us a chance to balk at the last minute.
820 ng_udbp_connect(hook_p hook)
822 /* probably not at splnet, force outward queueing */
823 NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook));
824 /* be really amiable and just say "YUP that's OK by me! " */
831 * For this type, removal of the last link destroys the node
834 ng_udbp_disconnect(hook_p hook)
836 const udbp_p sc = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
839 if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
840 && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook))))
841 ng_rmnode_self(NG_HOOK_NODE(hook));