xref: /illumos-gate/usr/src/man/man9f/usb_pipe_xopen.9f (revision 3184921aa9155f2314caa4909eba31a0be558b3d)
1993e3fafSRobert Mustacchi.\" Copyright (c) 2004, Sun Microsystems, Inc., All Rights Reserved
2993e3fafSRobert Mustacchi.\" Copyright 2016 Joyent, Inc.
3993e3fafSRobert Mustacchi.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
4993e3fafSRobert Mustacchi.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
5993e3fafSRobert Mustacchi.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6993e3fafSRobert Mustacchi.Dd Sep 16, 2016
7993e3fafSRobert Mustacchi.Dt USB_PIPE_XOPEN 9F
8993e3fafSRobert Mustacchi.Os
9993e3fafSRobert Mustacchi.Sh NAME
10993e3fafSRobert Mustacchi.Nm usb_pipe_open ,
11993e3fafSRobert Mustacchi.Nm usb_pipe_xopen
12993e3fafSRobert Mustacchi.Nd Open a USB pipe to a device
13993e3fafSRobert Mustacchi.Sh SYNOPSIS
14993e3fafSRobert Mustacchi.In sys/usb/usba.h
15993e3fafSRobert Mustacchi.Ft int
16993e3fafSRobert Mustacchi.Fo usb_pipe_open
17993e3fafSRobert Mustacchi.Fa "dev_info_t *dip"
18993e3fafSRobert Mustacchi.Fa "usb_ep_descr_t *endpoint"
19993e3fafSRobert Mustacchi.Fa "usb_pipe_policy_t *pipe_policy"
20993e3fafSRobert Mustacchi.Fa "usb_flags_t flags"
21993e3fafSRobert Mustacchi.Fa "usb_pipe_handle_t *pipe_handle"
22993e3fafSRobert Mustacchi.Fc
23993e3fafSRobert Mustacchi.Ft int
24993e3fafSRobert Mustacchi.Fo usb_pipe_xopen
25993e3fafSRobert Mustacchi.Fa "dev_info_t *dip"
26993e3fafSRobert Mustacchi.Fa "usb_ep_xdescr_t *extended_endpoint"
27993e3fafSRobert Mustacchi.Fa "usb_pipe_policy_t *pipe_policy"
28993e3fafSRobert Mustacchi.Fa "usb_flags_t flags"
29993e3fafSRobert Mustacchi.Fa "usb_pipe_handle_t *pipe_handle"
30993e3fafSRobert Mustacchi.Fc
31993e3fafSRobert Mustacchi.Sh INTERFACE LEVEL
32*3184921aSRichard Loweillumos DDI specific (illumos DDI)
33993e3fafSRobert Mustacchi.Sh PARAMETERS
34993e3fafSRobert Mustacchi.Bl -tag -width Fa
35993e3fafSRobert Mustacchi.It Fa dip
36993e3fafSRobert MustacchiPointer to the device's
37993e3fafSRobert Mustacchi.Sy dev_info
38993e3fafSRobert Mustacchistructure.
39993e3fafSRobert Mustacchi.It Fa endpoint
40993e3fafSRobert MustacchiPointer to endpoint descriptor.
41993e3fafSRobert Mustacchi.It Fa extended_endpoint
42993e3fafSRobert MustacchiPointer to an extended endpoint descriptor retrieved from calling
43993e3fafSRobert Mustacchi.Xr usb_ep_xdescr_fill 9F .
44993e3fafSRobert Mustacchi.It Fa pipe_policy
45993e3fafSRobert MustacchiPointer to
46993e3fafSRobert Mustacchi.Em pipe_policy.
47993e3fafSRobert Mustacchi.Em pipe_policy
48993e3fafSRobert Mustacchiprovides hints on pipe usage.
49993e3fafSRobert Mustacchi.It Fa flags
50993e3fafSRobert Mustacchi.Sy USB_FLAGS_SLEEP
5172d3dbb9SYuri Pankovis only flag that is recognized.
5272d3dbb9SYuri PankovWait for memory resources if not immediately available.
53993e3fafSRobert Mustacchi.It Fa pipe_handle
5472d3dbb9SYuri PankovAddress to where new pipe handle is returned.
5572d3dbb9SYuri Pankov(The handle is opaque.)
56993e3fafSRobert Mustacchi.El
57993e3fafSRobert Mustacchi.Sh DESCRIPTION
5872d3dbb9SYuri PankovA pipe is a logical connection to an endpoint on a USB device.
5972d3dbb9SYuri PankovThe
60993e3fafSRobert Mustacchi.Fn usb_pipe_xopen
61993e3fafSRobert Mustacchifunction creates such a logical connection and returns an
62993e3fafSRobert Mustacchiinitialized handle which refers to that connection.
63993e3fafSRobert Mustacchi.Pp
64993e3fafSRobert MustacchiThe
65993e3fafSRobert Mustacchi.Em USB 3.0
66993e3fafSRobert Mustacchispecification defines four endpoint types, each with a
6772d3dbb9SYuri Pankovcorresponding type of pipe.
6872d3dbb9SYuri PankovEach of the four types of pipes uses its physical connection resource
6972d3dbb9SYuri Pankovdifferently.
7072d3dbb9SYuri PankovThey are:
71993e3fafSRobert Mustacchi.Bl -tag -width Sy
72993e3fafSRobert Mustacchi.It Sy Control Pipe
73993e3fafSRobert MustacchiUsed for bursty, non-periodic, reliable, host-initiated request/response
7472d3dbb9SYuri Pankovcommunication, such as for command/status operations.
7572d3dbb9SYuri PankovThese are guaranteed to get approximately 10% of frame time and will get more if
7672d3dbb9SYuri Pankovneeded and if available, but there is no guarantee on transfer promptness.
7772d3dbb9SYuri PankovBidirectional.
78993e3fafSRobert Mustacchi.It Sy Bulk Pipe
7972d3dbb9SYuri PankovUsed for large, reliable, non-time-critical data transfers.
8072d3dbb9SYuri PankovThese get the bus on a bandwidth-available basis.
8172d3dbb9SYuri PankovUnidirectional.
8272d3dbb9SYuri PankovSample uses include printer data.
83993e3fafSRobert Mustacchi.It Sy Interrupt Pipe
84993e3fafSRobert MustacchiUsed for sending or receiving small amounts of reliable data infrequently but
8572d3dbb9SYuri Pankovwith bounded service periods, as for interrupt handling.
8672d3dbb9SYuri PankovUnidirectional.
87993e3fafSRobert Mustacchi.It Sy Isochronous Pipe
8872d3dbb9SYuri PankovUsed for large, unreliable, time-critical data transfers.
8972d3dbb9SYuri PankovBoasts a guaranteed constant data rate as long as there is data, but there are
9072d3dbb9SYuri Pankovno retries of failed transfers.
9172d3dbb9SYuri PankovInterrupt and isochronous data are together guaranteed 90% of frame time as
9272d3dbb9SYuri Pankovneeded.
9372d3dbb9SYuri PankovUnidirectional.
9472d3dbb9SYuri PankovSample uses include audio.
95993e3fafSRobert Mustacchi.El
96993e3fafSRobert Mustacchi.Pp
97993e3fafSRobert MustacchiThe type of endpoint to which a pipe connects (and therefore the pipe type) is
98993e3fafSRobert Mustacchidefined by the
99993e3fafSRobert Mustacchi.Sy bmAttributes
100993e3fafSRobert Mustacchifield of that pipe's endpoint descriptor.
101993e3fafSRobert Mustacchi.Po
102993e3fafSRobert MustacchiSee
103993e3fafSRobert Mustacchi.Xr usb_ep_descr 9S
104993e3fafSRobert Mustacchi.Pc .
105993e3fafSRobert Mustacchi.Pp
106993e3fafSRobert MustacchiPrior to the
107993e3fafSRobert Mustacchi.Em USB 3.0
108993e3fafSRobert Mustacchispecification, only the
109993e3fafSRobert Mustacchi.Xr usb_ep_descr 9S
11072d3dbb9SYuri Pankovwas required to identify all of the attributes of a given pipe.
11172d3dbb9SYuri PankovStarting with
112993e3fafSRobert Mustacchi.Em USB 3.0
113993e3fafSRobert Mustacchithere are additional endpoint companion descriptors required to open a
11472d3dbb9SYuri Pankovpipe.
11572d3dbb9SYuri PankovTo support SuperSpeed devices, the new
116993e3fafSRobert Mustacchi.Fn usb_pipe_xopen
117993e3fafSRobert Mustacchifunction must be used rather than the older
118993e3fafSRobert Mustacchi.Fn usb_pipe_open
11972d3dbb9SYuri Pankovfunction.
12072d3dbb9SYuri PankovThe
121993e3fafSRobert Mustacchi.Xr usb_ep_xdescr 9S
122993e3fafSRobert Mustacchistructure can be automatically filled out and obtained by calling the
123993e3fafSRobert Mustacchi.Xr usb_ep_xdescr_fill 9F
124993e3fafSRobert Mustacchifunction.
125993e3fafSRobert Mustacchi.Pp
12672d3dbb9SYuri PankovOpens to interrupt and isochronous pipes can fail if the required bandwidth
12772d3dbb9SYuri Pankovcannot be guaranteed.
128993e3fafSRobert Mustacchi.Pp
129993e3fafSRobert MustacchiThe polling interval for periodic (interrupt or isochronous) pipes, carried by
13072d3dbb9SYuri Pankovthe endpoint argument's bInterval field, must be within range.
13172d3dbb9SYuri PankovValid ranges are:
132993e3fafSRobert Mustacchi.Pp
133993e3fafSRobert MustacchiFull speed: range of 1-255 maps to 1-255 ms.
134993e3fafSRobert Mustacchi.Pp
135993e3fafSRobert MustacchiLow speed: range of 10-255 maps to 10-255 ms.
136993e3fafSRobert Mustacchi.Pp
137993e3fafSRobert MustacchiHigh speed: range of 1-16 maps to (2**(bInterval-1)) * 125us.
138993e3fafSRobert Mustacchi.Pp
139993e3fafSRobert MustacchiSuper speed: range of 1-16 maps to (2**(bInterval-1)) * 125us.
140993e3fafSRobert Mustacchi.Pp
141993e3fafSRobert MustacchiAdequate bandwidth during transfers is guaranteed for all periodic pipes which
14272d3dbb9SYuri Pankovare opened successfully.
14372d3dbb9SYuri PankovInterrupt and isochronous pipes have guaranteed latency times, so bandwidth for
14472d3dbb9SYuri Pankovthem is allocated when they are opened.
145993e3fafSRobert Mustacchi.Po
14672d3dbb9SYuri PankovPlease refer to Sections
147993e3fafSRobert Mustacchi.Em 4.4.7
148993e3fafSRobert Mustacchiand
149993e3fafSRobert Mustacchi.Em 4.4.8
150993e3fafSRobert Mustacchiof the
151993e3fafSRobert Mustacchi.Em USB 3.1
152993e3fafSRobert Mustacchispecification
153993e3fafSRobert Mustacchiwhich address isochronous and interrupt transfers.
154993e3fafSRobert Mustacchi.Pc
155993e3fafSRobert MustacchiOpens of interrupt and isochronous pipes fail if inadequate bandwidth is
15672d3dbb9SYuri Pankovavailable to support their guaranteed latency time.
15772d3dbb9SYuri PankovBecause periodic pipe bandwidth is allocated on pipe open, open periodic pipes
15872d3dbb9SYuri Pankovonly when needed.
159993e3fafSRobert Mustacchi.Pp
160993e3fafSRobert MustacchiThe bandwidth required by a device varies based on polling interval, the
161993e3fafSRobert Mustacchimaximum packet size
162993e3fafSRobert Mustacchi.Pq Sy wMaxPacketSize
16372d3dbb9SYuri Pankovand the device speed.
16472d3dbb9SYuri PankovUnallocated bandwidth remaining for new devices depends on the bandwidth already
16572d3dbb9SYuri Pankovallocated for previously opened periodic pipes.
166993e3fafSRobert Mustacchi.Pp
167993e3fafSRobert MustacchiThe
168993e3fafSRobert Mustacchi.Em pipe_policy
16972d3dbb9SYuri Pankovparameter provides a hint as to pipe usage and must be specified.
17072d3dbb9SYuri PankovIt is a
171993e3fafSRobert Mustacchi.Em usb_pipe_policy_t
172993e3fafSRobert Mustacchiwhich contains the following fields:
173993e3fafSRobert Mustacchi.Bd -literal -offset indent
174993e3fafSRobert Mustacchiuchar_t         pp_max_async_reqs:
175993e3fafSRobert Mustacchi.Ed
176993e3fafSRobert Mustacchi.Pp
177993e3fafSRobert MustacchiThe
178993e3fafSRobert Mustacchi.Sy pp_max_async_reqs
179993e3fafSRobert Mustacchimember is a hint indicating how many asynchronous operations requiring
180993e3fafSRobert Mustacchitheir own kernel thread will be concurrently in progress, the highest
18172d3dbb9SYuri Pankovnumber of threads ever needed at one time.
18272d3dbb9SYuri PankovAllow at least one for synchronous callback handling and as many as are needed
18372d3dbb9SYuri Pankovto accommodate the anticipated parallelism of asynchronous* calls to the
18472d3dbb9SYuri Pankovfollowing functions:
185993e3fafSRobert Mustacchi.Xr usb_pipe_close 9F ,
186993e3fafSRobert Mustacchi.Xr usb_set_cfg 9F ,
187993e3fafSRobert Mustacchi.Xr usb_set_alt_if 9F ,
188993e3fafSRobert Mustacchi.Xr usb_clr_feature 9F ,
189993e3fafSRobert Mustacchi.Xr usb_pipe_reset 9F ,
190993e3fafSRobert Mustacchi.Xr usb_pipe_drain_reqs 9F ,
191993e3fafSRobert Mustacchi.Xr usb_pipe_stop_intr_polling 9F ,
192993e3fafSRobert Mustacchiand
193993e3fafSRobert Mustacchi.Xr usb_pipe_stop_isoc_polling 9F .
194993e3fafSRobert Mustacchi.Pp
19572d3dbb9SYuri PankovSetting to too small a value can deadlock the pipe.
19672d3dbb9SYuri PankovAsynchronous calls are calls made without the
197993e3fafSRobert Mustacchi.Sy USB_FLAGS_SLEEP
19872d3dbb9SYuri Pankovflag being passed.
19972d3dbb9SYuri PankovNote that a large number of callbacks becomes an issue mainly when blocking
200993e3fafSRobert Mustacchifunctions are called from callback handlers.
201993e3fafSRobert Mustacchi.Pp
202993e3fafSRobert MustacchiThe control pipe to the default endpoints (endpoints for both directions with
203993e3fafSRobert Mustacchiaddr 0, sometimes called the default control pipe or default pipe) comes
20472d3dbb9SYuri Pankovpre-opened by the hub.
20572d3dbb9SYuri PankovA client driver receives the default control pipe handle through
206993e3fafSRobert Mustacchi.Xr usb_get_dev_data 9F .
207993e3fafSRobert MustacchiA client driver cannot open the default
20872d3dbb9SYuri Pankovcontrol pipe manually.
20972d3dbb9SYuri PankovNote that the same control pipe may be shared among several drivers when a
21072d3dbb9SYuri Pankovdevice has multiple interfaces and each interface is operated by its own driver.
211993e3fafSRobert Mustacchi.Pp
212993e3fafSRobert MustacchiAll explicit pipe opens are exclusive; attempts to open an opened pipe fail.
213993e3fafSRobert Mustacchi.Pp
214993e3fafSRobert MustacchiOn success, the pipe_handle argument points to an opaque handle of the opened
21572d3dbb9SYuri Pankovpipe.
21672d3dbb9SYuri PankovOn failure, it is set to NULL.
217993e3fafSRobert Mustacchi.Sh CONTEXT
21872d3dbb9SYuri PankovMay be called from user or kernel context regardless of arguments.
21972d3dbb9SYuri PankovMay also be called from interrupt context if the
220993e3fafSRobert Mustacchi.Sy USB_FLAGS_SLEEP
221993e3fafSRobert Mustacchioption is not set.
222993e3fafSRobert Mustacchi.Sh RETURN VALUES
223993e3fafSRobert Mustacchi.Bl -tag -width Sy
224993e3fafSRobert Mustacchi.It Sy USB_SUCCESS
225993e3fafSRobert MustacchiOpen succeeded.
226993e3fafSRobert Mustacchi.It Sy USB_NO_RESOURCES
227993e3fafSRobert MustacchiInsufficient resources were available.
228993e3fafSRobert Mustacchi.It Sy USB_NO_BANDWIDTH
22972d3dbb9SYuri PankovInsufficient bandwidth available.
23072d3dbb9SYuri Pankov(isochronous and interrupt pipes).
231993e3fafSRobert Mustacchi.It Sy USB_INVALID_CONTEXT
232993e3fafSRobert MustacchiCalled from interrupt handler with USB_FLAGS_SLEEP set.
233993e3fafSRobert Mustacchi.It Sy USB_INVALID_ARGS
23472d3dbb9SYuri Pankovdip and/or pipe_handle is NULL.
23572d3dbb9SYuri PankovPipe_policy is NULL.
236993e3fafSRobert Mustacchi.It Sy USB_INVALID_PERM
23772d3dbb9SYuri PankovEndpoint is NULL, signifying the default control pipe.
23872d3dbb9SYuri PankovA client driver cannot open the default control pipe.
239993e3fafSRobert Mustacchi.It Sy USB_NOT_SUPPORTED
240993e3fafSRobert MustacchiIsochronous or interrupt endpoint with maximum packet size of zero is not
241993e3fafSRobert Mustacchisupported.
242993e3fafSRobert Mustacchi.It Sy USB_HC_HARDWARE_ERROR
243993e3fafSRobert MustacchiHost controller is in an error state.
244993e3fafSRobert Mustacchi.It Sy USB_FAILURE
24572d3dbb9SYuri PankovPipe is already open.
24672d3dbb9SYuri PankovHost controller not in an operational state.
24772d3dbb9SYuri PankovPolling interval
248993e3fafSRobert Mustacchi.Pq Sy Bep_descr bInterval No field
249993e3fafSRobert Mustacchiis out of range (intr or isoc pipes).
250993e3fafSRobert Mustacchi.Pp
251993e3fafSRobert MustacchiThe device referred to by
252993e3fafSRobert Mustacchi.Fa dip
253993e3fafSRobert Mustacchiis at least a SuperSpeed device and the older
254993e3fafSRobert Mustacchi.Fn usb_pipe_open
255993e3fafSRobert Mustacchifunction was used.
256993e3fafSRobert Mustacchi.El
257993e3fafSRobert Mustacchi.Sh EXAMPLES
258993e3fafSRobert Mustacchi.Bd -literal -offset indent
259993e3fafSRobert Mustacchiusb_ep_data_t *ep_data;
260993e3fafSRobert Mustacchiusb_ep_xdescr_t ep_xdescr;
261993e3fafSRobert Mustacchiusb_pipe_policy_t policy;
262993e3fafSRobert Mustacchiusb_pipe_handle_t pipe;
263993e3fafSRobert Mustacchiusb_client_dev_data_t *reg_data;
264993e3fafSRobert Mustacchiuint8_t interface = 1;
265993e3fafSRobert Mustacchiuint8_t alternate = 1;
266993e3fafSRobert Mustacchiuint8_t first_ep_number = 0;
267993e3fafSRobert Mustacchi
268993e3fafSRobert Mustacchi/* Initialize pipe policy. */
269993e3fafSRobert Mustacchibzero(policy, sizeof(usb_pipe_policy_t));
270993e3fafSRobert Mustacchipolicy.pp_max_async_requests = 2;
271993e3fafSRobert Mustacchi
272993e3fafSRobert Mustacchi/* Get tree of descriptors for device. */
273993e3fafSRobert Mustacchiif (usb_get_dev_data(dip, USBDRV_VERSION, &reg_data,
274993e3fafSRobert Mustacchi    USB_FLAGS_ALL_DESCR, 0) != USB_SUCCESS) {
275993e3fafSRobert Mustacchi        ...
276993e3fafSRobert Mustacchi}
277993e3fafSRobert Mustacchi
278993e3fafSRobert Mustacchi/* Get first interrupt-IN endpoint. */
279993e3fafSRobert Mustacchiep_data = usb_lookup_ep_data(dip, reg_data, interface, alternate,
280993e3fafSRobert Mustacchi    first_ep_number, USB_EP_ATTR_INTR, USB_EP_DIR_IN);
281993e3fafSRobert Mustacchiif (ep_data == NULL) {
282993e3fafSRobert Mustacchi        ...
283993e3fafSRobert Mustacchi}
284993e3fafSRobert Mustacchi
285993e3fafSRobert Mustacchi/* Translate the ep_data into the filled in usb_ep_xdescr_t */
286993e3fafSRobert Mustacchiif (usb_ep_xdescr_fill(USB_EP_XDESCR_CURRENT_VERSION, dip,
287993e3fafSRobert Mustacchi    ep_data, &ep_xdescr) != USB_SUCCESS) {
288993e3fafSRobert Mustacchi       ...
289993e3fafSRobert Mustacchi}
290993e3fafSRobert Mustacchi
291993e3fafSRobert Mustacchi/* Open the pipe.  Get handle to pipe back in 5th argument. */
292993e3fafSRobert Mustacchiif (usb_pipe_open(dip, &ep_data.ep_descr
293993e3fafSRobert Mustacchi    &policy, USB_FLAGS_SLEEP, &pipe) != USB_SUCCESS) {
294993e3fafSRobert Mustacchi        ...
295993e3fafSRobert Mustacchi}
296993e3fafSRobert Mustacchi.Ed
297993e3fafSRobert Mustacchi.Sh SEE ALSO
298993e3fafSRobert Mustacchi.Xr usb_get_alt_if 9F ,
299993e3fafSRobert Mustacchi.Xr usb_get_cfg 9F ,
300993e3fafSRobert Mustacchi.Xr usb_get_dev_data 9F ,
301993e3fafSRobert Mustacchi.Xr usb_get_status 9F ,
302993e3fafSRobert Mustacchi.Xr usb_pipe_bulk_xfer 9F ,
303993e3fafSRobert Mustacchi.Xr usb_pipe_close 9F ,
304993e3fafSRobert Mustacchi.Xr usb_pipe_ctrl_xfer 9F ,
305993e3fafSRobert Mustacchi.Xr usb_pipe_get_state 9F ,
306993e3fafSRobert Mustacchi.Xr usb_pipe_intr_xfer 9F ,
307993e3fafSRobert Mustacchi.Xr usb_pipe_isoc_xfer 9F ,
308993e3fafSRobert Mustacchi.Xr usb_pipe_reset 9F ,
309993e3fafSRobert Mustacchi.Xr usb_pipe_set_private 9F ,
310993e3fafSRobert Mustacchi.Xr usb_callback_flags 9S ,
311993e3fafSRobert Mustacchi.Xr usb_ep_descr 9S
312993e3fafSRobert Mustacchi.Rs
313993e3fafSRobert Mustacchi.%T Universal Serial Bus 3.1 Specification
314993e3fafSRobert Mustacchi.%U http://www.usb.org
315993e3fafSRobert Mustacchi.Re
316