Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Jun 2016 07:12:22 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r302125 - head/lib/libusb
Message-ID:  <201606230712.u5N7CMXj021657@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Thu Jun 23 07:12:22 2016
New Revision: 302125
URL: https://svnweb.freebsd.org/changeset/base/302125

Log:
  Add support for USB streams to the LibUSB v1.0 API and update the
  libusb(3) manual page.
  
  Approved by:	re (gjb)
  Requested by:	swills
  MFC after:	1 week

Modified:
  head/lib/libusb/Makefile
  head/lib/libusb/libusb.3
  head/lib/libusb/libusb.h
  head/lib/libusb/libusb10.c
  head/lib/libusb/libusb10.h
  head/lib/libusb/libusb10_io.c

Modified: head/lib/libusb/Makefile
==============================================================================
--- head/lib/libusb/Makefile	Thu Jun 23 07:09:44 2016	(r302124)
+++ head/lib/libusb/Makefile	Thu Jun 23 07:12:22 2016	(r302125)
@@ -120,8 +120,12 @@ MLINKS += libusb.3 libusb_get_ss_usb_dev
 MLINKS += libusb.3 libusb_free_ss_usb_device_capability_descriptor.3
 MLINKS += libusb.3 libusb_get_container_id_descriptor.3
 MLINKS += libusb.3 libusb_free_container_id_descriptor.3
+MLINKS += libusb.3 libusb_alloc_streams.3
+MLINKS += libusb.3 libusb_free_streams.3
 MLINKS += libusb.3 libusb_alloc_transfer.3
 MLINKS += libusb.3 libusb_free_transfer.3
+MLINKS += libusb.3 libusb_transfer_set_stream_id.3
+MLINKS += libusb.3 libusb_transfer_get_stream_id.3
 MLINKS += libusb.3 libusb_submit_transfer.3
 MLINKS += libusb.3 libusb_cancel_transfer.3
 MLINKS += libusb.3 libusb_control_transfer.3

Modified: head/lib/libusb/libusb.3
==============================================================================
--- head/lib/libusb/libusb.3	Thu Jun 23 07:09:44 2016	(r302124)
+++ head/lib/libusb/libusb.3	Thu Jun 23 07:12:22 2016	(r302125)
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd June 22, 2016
+.Dd June 23, 2016
 .Dt LIBUSB 3
 .Os
 .Sh NAME
@@ -521,6 +521,29 @@ if the transfer timed out, LIBUSB_ERROR_
 supported, LIBUSB_ERROR_OVERFLOW if the device offered more data,
 LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and
 a LIBUSB_ERROR code on other failure.
+.Sh USB STREAMS SUPPORT
+.Ft int
+.Fn libusb_alloc_streams "libusb_device_handle *dev" "uint32_t num_streams" "unsigned char *endpoints" "int num_endpoints"
+This function verifies that the given number of streams using the
+given number of endpoints is allowed and allocates the resources
+needed to use so-called USB streams.
+Currently only a single stream per endpoint is supported to simplify
+the internals of LibUSB.
+This function returns 0 on success or a LIBUSB_ERROR code on failure.
+.Pp
+.Ft int
+.Fn libusb_free_streams "libusb_device_handle *dev" "unsigned char *endpoints" "int num_endpoints"
+This function release resources needed for streams usage.
+Returns 0 on success or a LIBUSB_ERROR code on failure.
+.Pp
+.Ft void
+.Fn libusb_transfer_set_stream_id "struct libusb_transfer *transfer" "uint32_t stream_id"
+This function sets the stream ID for the given USB transfer.
+.Pp
+.Ft uint32_t
+.Fn libusb_transfer_get_stream_id "struct libusb_transfer *transfer"
+This function returns the stream ID for the given USB transfer.
+If no stream ID is used a value of zero is returned.
 .Sh USB EVENTS
 .Ft int
 .Fn libusb_try_lock_events "libusb_context *ctx"

Modified: head/lib/libusb/libusb.h
==============================================================================
--- head/lib/libusb/libusb.h	Thu Jun 23 07:09:44 2016	(r302124)
+++ head/lib/libusb/libusb.h	Thu Jun 23 07:12:22 2016	(r302125)
@@ -561,6 +561,13 @@ typedef int (*libusb_hotplug_callback_fn
 int	libusb_hotplug_register_callback(libusb_context *ctx, libusb_hotplug_event events, libusb_hotplug_flag flags, int vendor_id, int product_id, int dev_class, libusb_hotplug_callback_fn cb_fn, void *user_data, libusb_hotplug_callback_handle *handle);
 void	libusb_hotplug_deregister_callback(libusb_context *ctx, libusb_hotplug_callback_handle handle);
 
+/* Streams support */
+
+int	libusb_alloc_streams(libusb_device_handle *dev, uint32_t num_streams, unsigned char *endpoints, int num_endpoints);
+int	libusb_free_streams(libusb_device_handle *dev, unsigned char *endpoints, int num_endpoints);
+void	libusb_transfer_set_stream_id(struct libusb_transfer *transfer, uint32_t stream_id);
+uint32_t libusb_transfer_get_stream_id(struct libusb_transfer *transfer);
+
 #if 0
 {					/* indent fix */
 #endif

Modified: head/lib/libusb/libusb10.c
==============================================================================
--- head/lib/libusb/libusb10.c	Thu Jun 23 07:09:44 2016	(r302124)
+++ head/lib/libusb/libusb10.c	Thu Jun 23 07:12:22 2016	(r302125)
@@ -1403,7 +1403,8 @@ found:
 	maxframe = libusb10_get_maxframe(pdev, uxfer);
 
 	/* make sure the transfer is opened */
-	err = libusb20_tr_open(pxfer0, buffsize, maxframe, endpoint);
+	err = libusb20_tr_open_stream(pxfer0, buffsize, maxframe,
+	    endpoint, sxfer->stream_id);
 	if (err && (err != LIBUSB20_ERROR_BUSY)) {
 		goto failure;
 	}

Modified: head/lib/libusb/libusb10.h
==============================================================================
--- head/lib/libusb/libusb10.h	Thu Jun 23 07:09:44 2016	(r302124)
+++ head/lib/libusb/libusb10.h	Thu Jun 23 07:12:22 2016	(r302125)
@@ -69,6 +69,7 @@ struct libusb_super_transfer {
 	uint8_t *curr_data;
 	uint32_t rem_len;
 	uint32_t last_len;
+	uint32_t stream_id;
 	uint8_t	state;
 #define	LIBUSB_SUPER_XFER_ST_NONE 0
 #define	LIBUSB_SUPER_XFER_ST_PEND 1

Modified: head/lib/libusb/libusb10_io.c
==============================================================================
--- head/lib/libusb/libusb10_io.c	Thu Jun 23 07:09:44 2016	(r302124)
+++ head/lib/libusb/libusb10_io.c	Thu Jun 23 07:12:22 2016	(r302125)
@@ -767,3 +767,48 @@ libusb_fill_iso_transfer(struct libusb_t
 	transfer->callback = callback;
 }
 
+int
+libusb_alloc_streams(libusb_device_handle *dev, uint32_t num_streams,
+    unsigned char *endpoints, int num_endpoints)
+{
+	if (num_streams > 1)
+		return (LIBUSB_ERROR_INVALID_PARAM);
+	return (0);
+}
+
+int
+libusb_free_streams(libusb_device_handle *dev, unsigned char *endpoints, int num_endpoints)
+{
+
+	return (0);
+}
+
+void
+libusb_transfer_set_stream_id(struct libusb_transfer *transfer, uint32_t stream_id)
+{
+	struct libusb_super_transfer *sxfer;
+
+	if (transfer == NULL)
+		return;
+
+	sxfer = (struct libusb_super_transfer *)(
+	    ((uint8_t *)transfer) - sizeof(*sxfer));
+
+	/* set stream ID */
+	sxfer->stream_id = stream_id;
+}
+
+uint32_t
+libusb_transfer_get_stream_id(struct libusb_transfer *transfer)
+{
+	struct libusb_super_transfer *sxfer;
+
+	if (transfer == NULL)
+		return (0);
+
+	sxfer = (struct libusb_super_transfer *)(
+	    ((uint8_t *)transfer) - sizeof(*sxfer));
+
+	/* get stream ID */
+	return (sxfer->stream_id);
+}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201606230712.u5N7CMXj021657>