Deleted Added
full compact
udbp.c (193045) udbp.c (194228)
1/*-
2 * Copyright (c) 1996-2000 Whistle Communications, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

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.
28 *
29 */
30
31#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1996-2000 Whistle Communications, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

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.
28 *
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/dev/usb/misc/udbp.c 193045 2009-05-29 18:46:57Z thompsa $");
32__FBSDID("$FreeBSD: head/sys/dev/usb/misc/udbp.c 194228 2009-06-15 01:02:43Z thompsa $");
33
34/* Driver for arbitrary double bulk pipe devices.
35 * The driver assumes that there will be the same driver on the other side.
36 *
37 * XXX Some more information on what the framing of the IP packets looks like.
38 *
39 * To take full advantage of bulk transmission, packets should be chosen
40 * between 1k and 5k in size (1k to make sure the sending side starts

--- 271 unchanged lines hidden (view full) ---

312
313static int
314udbp_attach(device_t dev)
315{
316 struct usb_attach_arg *uaa = device_get_ivars(dev);
317 struct udbp_softc *sc = device_get_softc(dev);
318 int error;
319
33
34/* Driver for arbitrary double bulk pipe devices.
35 * The driver assumes that there will be the same driver on the other side.
36 *
37 * XXX Some more information on what the framing of the IP packets looks like.
38 *
39 * To take full advantage of bulk transmission, packets should be chosen
40 * between 1k and 5k in size (1k to make sure the sending side starts

--- 271 unchanged lines hidden (view full) ---

312
313static int
314udbp_attach(device_t dev)
315{
316 struct usb_attach_arg *uaa = device_get_ivars(dev);
317 struct udbp_softc *sc = device_get_softc(dev);
318 int error;
319
320 device_set_usb2_desc(dev);
320 device_set_usb_desc(dev);
321
322 snprintf(sc->sc_name, sizeof(sc->sc_name),
323 "%s", device_get_nameunit(dev));
324
325 mtx_init(&sc->sc_mtx, "udbp lock", NULL, MTX_DEF | MTX_RECURSE);
326
321
322 snprintf(sc->sc_name, sizeof(sc->sc_name),
323 "%s", device_get_nameunit(dev));
324
325 mtx_init(&sc->sc_mtx, "udbp lock", NULL, MTX_DEF | MTX_RECURSE);
326
327 error = usb2_transfer_setup(uaa->device, &uaa->info.bIfaceIndex,
327 error = usbd_transfer_setup(uaa->device, &uaa->info.bIfaceIndex,
328 sc->sc_xfer, udbp_config, UDBP_T_MAX, sc, &sc->sc_mtx);
329 if (error) {
328 sc->sc_xfer, udbp_config, UDBP_T_MAX, sc, &sc->sc_mtx);
329 if (error) {
330 DPRINTF("error=%s\n", usb2_errstr(error));
330 DPRINTF("error=%s\n", usbd_errstr(error));
331 goto detach;
332 }
333 NG_BT_MBUFQ_INIT(&sc->sc_xmitq, UDBP_Q_MAXLEN);
334
335 NG_BT_MBUFQ_INIT(&sc->sc_xmitq_hipri, UDBP_Q_MAXLEN);
336
337 /* create Netgraph node */
338

--- 32 unchanged lines hidden (view full) ---

371
372 if (sc->sc_node != NULL) {
373 NG_NODE_SET_PRIVATE(sc->sc_node, NULL);
374 ng_rmnode_self(sc->sc_node);
375 sc->sc_node = NULL;
376 }
377 /* free USB transfers, if any */
378
331 goto detach;
332 }
333 NG_BT_MBUFQ_INIT(&sc->sc_xmitq, UDBP_Q_MAXLEN);
334
335 NG_BT_MBUFQ_INIT(&sc->sc_xmitq_hipri, UDBP_Q_MAXLEN);
336
337 /* create Netgraph node */
338

--- 32 unchanged lines hidden (view full) ---

371
372 if (sc->sc_node != NULL) {
373 NG_NODE_SET_PRIVATE(sc->sc_node, NULL);
374 ng_rmnode_self(sc->sc_node);
375 sc->sc_node = NULL;
376 }
377 /* free USB transfers, if any */
378
379 usb2_transfer_unsetup(sc->sc_xfer, UDBP_T_MAX);
379 usbd_transfer_unsetup(sc->sc_xfer, UDBP_T_MAX);
380
381 mtx_destroy(&sc->sc_mtx);
382
383 /* destroy queues */
384
385 NG_BT_MBUFQ_DESTROY(&sc->sc_xmitq);
386 NG_BT_MBUFQ_DESTROY(&sc->sc_xmitq_hipri);
387

--- 25 unchanged lines hidden (view full) ---

413 MCLGET(m, M_DONTWAIT);
414
415 if (!(m->m_flags & M_EXT)) {
416 m_freem(m);
417 goto tr_setup;
418 }
419 m->m_pkthdr.len = m->m_len = xfer->actlen;
420
380
381 mtx_destroy(&sc->sc_mtx);
382
383 /* destroy queues */
384
385 NG_BT_MBUFQ_DESTROY(&sc->sc_xmitq);
386 NG_BT_MBUFQ_DESTROY(&sc->sc_xmitq_hipri);
387

--- 25 unchanged lines hidden (view full) ---

413 MCLGET(m, M_DONTWAIT);
414
415 if (!(m->m_flags & M_EXT)) {
416 m_freem(m);
417 goto tr_setup;
418 }
419 m->m_pkthdr.len = m->m_len = xfer->actlen;
420
421 usb2_copy_out(xfer->frbuffers, 0, m->m_data, xfer->actlen);
421 usbd_copy_out(xfer->frbuffers, 0, m->m_data, xfer->actlen);
422
423 sc->sc_bulk_in_buffer = m;
424
425 DPRINTF("received package %d "
426 "bytes\n", xfer->actlen);
427
428 case USB_ST_SETUP:
429tr_setup:
430 if (sc->sc_bulk_in_buffer) {
431 ng_send_fn(sc->sc_node, NULL, &udbp_bulk_read_complete, NULL, 0);
432 return;
433 }
434 if (sc->sc_flags & UDBP_FLAG_READ_STALL) {
422
423 sc->sc_bulk_in_buffer = m;
424
425 DPRINTF("received package %d "
426 "bytes\n", xfer->actlen);
427
428 case USB_ST_SETUP:
429tr_setup:
430 if (sc->sc_bulk_in_buffer) {
431 ng_send_fn(sc->sc_node, NULL, &udbp_bulk_read_complete, NULL, 0);
432 return;
433 }
434 if (sc->sc_flags & UDBP_FLAG_READ_STALL) {
435 usb2_transfer_start(sc->sc_xfer[UDBP_T_RD_CS]);
435 usbd_transfer_start(sc->sc_xfer[UDBP_T_RD_CS]);
436 return;
437 }
438 xfer->frlengths[0] = xfer->max_data_length;
436 return;
437 }
438 xfer->frlengths[0] = xfer->max_data_length;
439 usb2_start_hardware(xfer);
439 usbd_transfer_submit(xfer);
440 return;
441
442 default: /* Error */
443 if (xfer->error != USB_ERR_CANCELLED) {
444 /* try to clear stall first */
445 sc->sc_flags |= UDBP_FLAG_READ_STALL;
440 return;
441
442 default: /* Error */
443 if (xfer->error != USB_ERR_CANCELLED) {
444 /* try to clear stall first */
445 sc->sc_flags |= UDBP_FLAG_READ_STALL;
446 usb2_transfer_start(sc->sc_xfer[UDBP_T_RD_CS]);
446 usbd_transfer_start(sc->sc_xfer[UDBP_T_RD_CS]);
447 }
448 return;
449
450 }
451}
452
453static void
454udbp_bulk_read_clear_stall_callback(struct usb_xfer *xfer)
455{
456 struct udbp_softc *sc = xfer->priv_sc;
457 struct usb_xfer *xfer_other = sc->sc_xfer[UDBP_T_RD];
458
447 }
448 return;
449
450 }
451}
452
453static void
454udbp_bulk_read_clear_stall_callback(struct usb_xfer *xfer)
455{
456 struct udbp_softc *sc = xfer->priv_sc;
457 struct usb_xfer *xfer_other = sc->sc_xfer[UDBP_T_RD];
458
459 if (usb2_clear_stall_callback(xfer, xfer_other)) {
459 if (usbd_clear_stall_callback(xfer, xfer_other)) {
460 DPRINTF("stall cleared\n");
461 sc->sc_flags &= ~UDBP_FLAG_READ_STALL;
460 DPRINTF("stall cleared\n");
461 sc->sc_flags &= ~UDBP_FLAG_READ_STALL;
462 usb2_transfer_start(xfer_other);
462 usbd_transfer_start(xfer_other);
463 }
464}
465
466static void
467udbp_bulk_read_complete(node_p node, hook_p hook, void *arg1, int arg2)
468{
469 struct udbp_softc *sc = NG_NODE_PRIVATE(node);
470 struct mbuf *m;

--- 22 unchanged lines hidden (view full) ---

493 m = NULL;
494 }
495done:
496 if (m) {
497 m_freem(m);
498 }
499 /* start USB bulk-in transfer, if not already started */
500
463 }
464}
465
466static void
467udbp_bulk_read_complete(node_p node, hook_p hook, void *arg1, int arg2)
468{
469 struct udbp_softc *sc = NG_NODE_PRIVATE(node);
470 struct mbuf *m;

--- 22 unchanged lines hidden (view full) ---

493 m = NULL;
494 }
495done:
496 if (m) {
497 m_freem(m);
498 }
499 /* start USB bulk-in transfer, if not already started */
500
501 usb2_transfer_start(sc->sc_xfer[UDBP_T_RD]);
501 usbd_transfer_start(sc->sc_xfer[UDBP_T_RD]);
502
503 mtx_unlock(&sc->sc_mtx);
504}
505
506static void
507udbp_bulk_write_callback(struct usb_xfer *xfer)
508{
509 struct udbp_softc *sc = xfer->priv_sc;
510 struct mbuf *m;
511
512 switch (USB_GET_STATE(xfer)) {
513 case USB_ST_TRANSFERRED:
514
515 sc->sc_packets_out++;
516
517 case USB_ST_SETUP:
518 if (sc->sc_flags & UDBP_FLAG_WRITE_STALL) {
502
503 mtx_unlock(&sc->sc_mtx);
504}
505
506static void
507udbp_bulk_write_callback(struct usb_xfer *xfer)
508{
509 struct udbp_softc *sc = xfer->priv_sc;
510 struct mbuf *m;
511
512 switch (USB_GET_STATE(xfer)) {
513 case USB_ST_TRANSFERRED:
514
515 sc->sc_packets_out++;
516
517 case USB_ST_SETUP:
518 if (sc->sc_flags & UDBP_FLAG_WRITE_STALL) {
519 usb2_transfer_start(sc->sc_xfer[UDBP_T_WR_CS]);
519 usbd_transfer_start(sc->sc_xfer[UDBP_T_WR_CS]);
520 return;
521 }
522 /* get next mbuf, if any */
523
524 NG_BT_MBUFQ_DEQUEUE(&sc->sc_xmitq_hipri, m);
525 if (m == NULL) {
526 NG_BT_MBUFQ_DEQUEUE(&sc->sc_xmitq, m);
527 if (m == NULL) {
528 DPRINTF("Data queue is empty\n");
529 return;
530 }
531 }
532 if (m->m_pkthdr.len > MCLBYTES) {
533 DPRINTF("truncating large packet "
534 "from %d to %d bytes\n", m->m_pkthdr.len,
535 MCLBYTES);
536 m->m_pkthdr.len = MCLBYTES;
537 }
520 return;
521 }
522 /* get next mbuf, if any */
523
524 NG_BT_MBUFQ_DEQUEUE(&sc->sc_xmitq_hipri, m);
525 if (m == NULL) {
526 NG_BT_MBUFQ_DEQUEUE(&sc->sc_xmitq, m);
527 if (m == NULL) {
528 DPRINTF("Data queue is empty\n");
529 return;
530 }
531 }
532 if (m->m_pkthdr.len > MCLBYTES) {
533 DPRINTF("truncating large packet "
534 "from %d to %d bytes\n", m->m_pkthdr.len,
535 MCLBYTES);
536 m->m_pkthdr.len = MCLBYTES;
537 }
538 usb2_m_copy_in(xfer->frbuffers, 0, m, 0, m->m_pkthdr.len);
538 usbd_m_copy_in(xfer->frbuffers, 0, m, 0, m->m_pkthdr.len);
539
540 xfer->frlengths[0] = m->m_pkthdr.len;
541
542 m_freem(m);
543
544 DPRINTF("packet out: %d bytes\n",
545 xfer->frlengths[0]);
546
539
540 xfer->frlengths[0] = m->m_pkthdr.len;
541
542 m_freem(m);
543
544 DPRINTF("packet out: %d bytes\n",
545 xfer->frlengths[0]);
546
547 usb2_start_hardware(xfer);
547 usbd_transfer_submit(xfer);
548 return;
549
550 default: /* Error */
551 if (xfer->error != USB_ERR_CANCELLED) {
552 /* try to clear stall first */
553 sc->sc_flags |= UDBP_FLAG_WRITE_STALL;
548 return;
549
550 default: /* Error */
551 if (xfer->error != USB_ERR_CANCELLED) {
552 /* try to clear stall first */
553 sc->sc_flags |= UDBP_FLAG_WRITE_STALL;
554 usb2_transfer_start(sc->sc_xfer[UDBP_T_WR_CS]);
554 usbd_transfer_start(sc->sc_xfer[UDBP_T_WR_CS]);
555 }
556 return;
557
558 }
559}
560
561static void
562udbp_bulk_write_clear_stall_callback(struct usb_xfer *xfer)
563{
564 struct udbp_softc *sc = xfer->priv_sc;
565 struct usb_xfer *xfer_other = sc->sc_xfer[UDBP_T_WR];
566
555 }
556 return;
557
558 }
559}
560
561static void
562udbp_bulk_write_clear_stall_callback(struct usb_xfer *xfer)
563{
564 struct udbp_softc *sc = xfer->priv_sc;
565 struct usb_xfer *xfer_other = sc->sc_xfer[UDBP_T_WR];
566
567 if (usb2_clear_stall_callback(xfer, xfer_other)) {
567 if (usbd_clear_stall_callback(xfer, xfer_other)) {
568 DPRINTF("stall cleared\n");
569 sc->sc_flags &= ~UDBP_FLAG_WRITE_STALL;
568 DPRINTF("stall cleared\n");
569 sc->sc_flags &= ~UDBP_FLAG_WRITE_STALL;
570 usb2_transfer_start(xfer_other);
570 usbd_transfer_start(xfer_other);
571 }
572}
573
574/***********************************************************************
575 * Start of Netgraph methods
576 **********************************************************************/
577
578/*

--- 141 unchanged lines hidden (view full) ---

720 NG_BT_MBUFQ_DROP(queue_ptr);
721 NG_FREE_M(m);
722 error = ENOBUFS;
723 } else {
724 NG_BT_MBUFQ_ENQUEUE(queue_ptr, m);
725 /*
726 * start bulk-out transfer, if not already started:
727 */
571 }
572}
573
574/***********************************************************************
575 * Start of Netgraph methods
576 **********************************************************************/
577
578/*

--- 141 unchanged lines hidden (view full) ---

720 NG_BT_MBUFQ_DROP(queue_ptr);
721 NG_FREE_M(m);
722 error = ENOBUFS;
723 } else {
724 NG_BT_MBUFQ_ENQUEUE(queue_ptr, m);
725 /*
726 * start bulk-out transfer, if not already started:
727 */
728 usb2_transfer_start(sc->sc_xfer[UDBP_T_WR]);
728 usbd_transfer_start(sc->sc_xfer[UDBP_T_WR]);
729 error = 0;
730 }
731
732 mtx_unlock(&sc->sc_mtx);
733
734 return (error);
735}
736

--- 51 unchanged lines hidden (view full) ---

788 NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook));
789
790 mtx_lock(&sc->sc_mtx);
791
792 sc->sc_flags |= (UDBP_FLAG_READ_STALL |
793 UDBP_FLAG_WRITE_STALL);
794
795 /* start bulk-in transfer */
729 error = 0;
730 }
731
732 mtx_unlock(&sc->sc_mtx);
733
734 return (error);
735}
736

--- 51 unchanged lines hidden (view full) ---

788 NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook));
789
790 mtx_lock(&sc->sc_mtx);
791
792 sc->sc_flags |= (UDBP_FLAG_READ_STALL |
793 UDBP_FLAG_WRITE_STALL);
794
795 /* start bulk-in transfer */
796 usb2_transfer_start(sc->sc_xfer[UDBP_T_RD]);
796 usbd_transfer_start(sc->sc_xfer[UDBP_T_RD]);
797
798 /* start bulk-out transfer */
797
798 /* start bulk-out transfer */
799 usb2_transfer_start(sc->sc_xfer[UDBP_T_WR]);
799 usbd_transfer_start(sc->sc_xfer[UDBP_T_WR]);
800
801 mtx_unlock(&sc->sc_mtx);
802
803 return (0);
804}
805
806/*
807 * Dook disconnection

--- 10 unchanged lines hidden (view full) ---

818
819 mtx_lock(&sc->sc_mtx);
820
821 if (hook != sc->sc_hook) {
822 error = EINVAL;
823 } else {
824
825 /* stop bulk-in transfer */
800
801 mtx_unlock(&sc->sc_mtx);
802
803 return (0);
804}
805
806/*
807 * Dook disconnection

--- 10 unchanged lines hidden (view full) ---

818
819 mtx_lock(&sc->sc_mtx);
820
821 if (hook != sc->sc_hook) {
822 error = EINVAL;
823 } else {
824
825 /* stop bulk-in transfer */
826 usb2_transfer_stop(sc->sc_xfer[UDBP_T_RD_CS]);
827 usb2_transfer_stop(sc->sc_xfer[UDBP_T_RD]);
826 usbd_transfer_stop(sc->sc_xfer[UDBP_T_RD_CS]);
827 usbd_transfer_stop(sc->sc_xfer[UDBP_T_RD]);
828
829 /* stop bulk-out transfer */
828
829 /* stop bulk-out transfer */
830 usb2_transfer_stop(sc->sc_xfer[UDBP_T_WR_CS]);
831 usb2_transfer_stop(sc->sc_xfer[UDBP_T_WR]);
830 usbd_transfer_stop(sc->sc_xfer[UDBP_T_WR_CS]);
831 usbd_transfer_stop(sc->sc_xfer[UDBP_T_WR]);
832
833 /* cleanup queues */
834 NG_BT_MBUFQ_DRAIN(&sc->sc_xmitq);
835 NG_BT_MBUFQ_DRAIN(&sc->sc_xmitq_hipri);
836
837 if (sc->sc_bulk_in_buffer) {
838 m_freem(sc->sc_bulk_in_buffer);
839 sc->sc_bulk_in_buffer = NULL;

--- 12 unchanged lines hidden ---
832
833 /* cleanup queues */
834 NG_BT_MBUFQ_DRAIN(&sc->sc_xmitq);
835 NG_BT_MBUFQ_DRAIN(&sc->sc_xmitq_hipri);
836
837 if (sc->sc_bulk_in_buffer) {
838 m_freem(sc->sc_bulk_in_buffer);
839 sc->sc_bulk_in_buffer = NULL;

--- 12 unchanged lines hidden ---