Merge commit '9276b3991ba20d5a5660887ba81b0bc7bed25a0c'
[unleashed.git] / share / man / man9f / usb_pipe_xopen.9f
blob4d403a786eb065fa70791cc2d6693a5649016b25
1 .\" Copyright (c) 2004, Sun Microsystems, Inc., All Rights Reserved
2 .\" Copyright 2016 Joyent, Inc.
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .Dd Sep 16, 2016
7 .Dt USB_PIPE_XOPEN 9F
8 .Os
9 .Sh NAME
10 .Nm usb_pipe_open ,
11 .Nm usb_pipe_xopen
12 .Nd Open a USB pipe to a device
13 .Sh SYNOPSIS
14 .In sys/usb/usba.h
15 .Ft int
16 .Fo usb_pipe_open
17 .Fa "dev_info_t *dip"
18 .Fa "usb_ep_descr_t *endpoint"
19 .Fa "usb_pipe_policy_t *pipe_policy"
20 .Fa "usb_flags_t flags"
21 .Fa "usb_pipe_handle_t *pipe_handle"
22 .Fc
23 .Ft int
24 .Fo usb_pipe_xopen
25 .Fa "dev_info_t *dip"
26 .Fa "usb_ep_xdescr_t *extended_endpoint"
27 .Fa "usb_pipe_policy_t *pipe_policy"
28 .Fa "usb_flags_t flags"
29 .Fa "usb_pipe_handle_t *pipe_handle"
30 .Fc
31 .Sh INTERFACE LEVEL
32 Solaris DDI specific (Solaris DDI)
33 .Sh PARAMETERS
34 .Bl -tag -width Fa
35 .It Fa dip
36 Pointer to the device's
37 .Sy dev_info
38 structure.
39 .It Fa endpoint
40 Pointer to endpoint descriptor.
41 .It Fa extended_endpoint
42 Pointer to an extended endpoint descriptor retrieved from calling
43 .Xr usb_ep_xdescr_fill 9F .
44 .It Fa pipe_policy
45 Pointer to
46 .Em pipe_policy.
47 .Em pipe_policy
48 provides hints on pipe usage.
49 .It Fa flags
50 .Sy USB_FLAGS_SLEEP
51 is only flag that is recognized.
52 Wait for memory resources if not immediately available.
53 .It Fa pipe_handle
54 Address to where new pipe handle is returned.
55 (The handle is opaque.)
56 .El
57 .Sh DESCRIPTION
58 A pipe is a logical connection to an endpoint on a USB device.
59 The
60 .Fn usb_pipe_xopen
61 function creates such a logical connection and returns an
62 initialized handle which refers to that connection.
63 .Pp
64 The
65 .Em USB 3.0
66 specification defines four endpoint types, each with a
67 corresponding type of pipe.
68 Each of the four types of pipes uses its physical connection resource
69 differently.
70 They are:
71 .Bl -tag -width Sy
72 .It Sy Control Pipe
73 Used for bursty, non-periodic, reliable, host-initiated request/response
74 communication, such as for command/status operations.
75 These are guaranteed to get approximately 10% of frame time and will get more if
76 needed and if available, but there is no guarantee on transfer promptness.
77 Bidirectional.
78 .It Sy Bulk Pipe
79 Used for large, reliable, non-time-critical data transfers.
80 These get the bus on a bandwidth-available basis.
81 Unidirectional.
82 Sample uses include printer data.
83 .It Sy Interrupt Pipe
84 Used for sending or receiving small amounts of reliable data infrequently but
85 with bounded service periods, as for interrupt handling.
86 Unidirectional.
87 .It Sy Isochronous Pipe
88 Used for large, unreliable, time-critical data transfers.
89 Boasts a guaranteed constant data rate as long as there is data, but there are
90 no retries of failed transfers.
91 Interrupt and isochronous data are together guaranteed 90% of frame time as
92 needed.
93 Unidirectional.
94 Sample uses include audio.
95 .El
96 .Pp
97 The type of endpoint to which a pipe connects (and therefore the pipe type) is
98 defined by the
99 .Sy bmAttributes
100 field of that pipe's endpoint descriptor.
103 .Xr usb_ep_descr 9S
104 .Pc .
106 Prior to the
107 .Em USB 3.0
108 specification, only the
109 .Xr usb_ep_descr 9S
110 was required to identify all of the attributes of a given pipe.
111 Starting with
112 .Em USB 3.0
113 there are additional endpoint companion descriptors required to open a
114 pipe.
115 To support SuperSpeed devices, the new
116 .Fn usb_pipe_xopen
117 function must be used rather than the older
118 .Fn usb_pipe_open
119 function.
121 .Xr usb_ep_xdescr 9S
122 structure can be automatically filled out and obtained by calling the
123 .Xr usb_ep_xdescr_fill 9F
124 function.
126 Opens to interrupt and isochronous pipes can fail if the required bandwidth
127 cannot be guaranteed.
129 The polling interval for periodic (interrupt or isochronous) pipes, carried by
130 the endpoint argument's bInterval field, must be within range.
131 Valid ranges are:
133 Full speed: range of 1-255 maps to 1-255 ms.
135 Low speed: range of 10-255 maps to 10-255 ms.
137 High speed: range of 1-16 maps to (2**(bInterval-1)) * 125us.
139 Super speed: range of 1-16 maps to (2**(bInterval-1)) * 125us.
141 Adequate bandwidth during transfers is guaranteed for all periodic pipes which
142 are opened successfully.
143 Interrupt and isochronous pipes have guaranteed latency times, so bandwidth for
144 them is allocated when they are opened.
146 Please refer to Sections
147 .Em 4.4.7
149 .Em 4.4.8
150 of the
151 .Em USB 3.1
152 specification
153 which address isochronous and interrupt transfers.
155 Opens of interrupt and isochronous pipes fail if inadequate bandwidth is
156 available to support their guaranteed latency time.
157 Because periodic pipe bandwidth is allocated on pipe open, open periodic pipes
158 only when needed.
160 The bandwidth required by a device varies based on polling interval, the
161 maximum packet size
162 .Pq Sy wMaxPacketSize
163 and the device speed.
164 Unallocated bandwidth remaining for new devices depends on the bandwidth already
165 allocated for previously opened periodic pipes.
168 .Em pipe_policy
169 parameter provides a hint as to pipe usage and must be specified.
170 It is a
171 .Em usb_pipe_policy_t
172 which contains the following fields:
173 .Bd -literal -offset indent
174 uchar_t         pp_max_async_reqs:
178 .Sy pp_max_async_reqs
179 member is a hint indicating how many asynchronous operations requiring
180 their own kernel thread will be concurrently in progress, the highest
181 number of threads ever needed at one time.
182 Allow at least one for synchronous callback handling and as many as are needed
183 to accommodate the anticipated parallelism of asynchronous* calls to the
184 following functions:
185 .Xr usb_pipe_close 9F ,
186 .Xr usb_set_cfg 9F ,
187 .Xr usb_set_alt_if 9F ,
188 .Xr usb_clr_feature 9F ,
189 .Xr usb_pipe_reset 9F ,
190 .Xr usb_pipe_drain_reqs 9F ,
191 .Xr usb_pipe_stop_intr_polling 9F ,
193 .Xr usb_pipe_stop_isoc_polling 9F .
195 Setting to too small a value can deadlock the pipe.
196 Asynchronous calls are calls made without the
197 .Sy USB_FLAGS_SLEEP
198 flag being passed.
199 Note that a large number of callbacks becomes an issue mainly when blocking
200 functions are called from callback handlers.
202 The control pipe to the default endpoints (endpoints for both directions with
203 addr 0, sometimes called the default control pipe or default pipe) comes
204 pre-opened by the hub.
205 A client driver receives the default control pipe handle through
206 .Xr usb_get_dev_data 9F .
207 A client driver cannot open the default
208 control pipe manually.
209 Note that the same control pipe may be shared among several drivers when a
210 device has multiple interfaces and each interface is operated by its own driver.
212 All explicit pipe opens are exclusive; attempts to open an opened pipe fail.
214 On success, the pipe_handle argument points to an opaque handle of the opened
215 pipe.
216 On failure, it is set to NULL.
217 .Sh CONTEXT
218 May be called from user or kernel context regardless of arguments.
219 May also be called from interrupt context if the
220 .Sy USB_FLAGS_SLEEP
221 option is not set.
222 .Sh RETURN VALUES
223 .Bl -tag -width Sy
224 .It Sy USB_SUCCESS
225 Open succeeded.
226 .It Sy USB_NO_RESOURCES
227 Insufficient resources were available.
228 .It Sy USB_NO_BANDWIDTH
229 Insufficient bandwidth available.
230 (isochronous and interrupt pipes).
231 .It Sy USB_INVALID_CONTEXT
232 Called from interrupt handler with USB_FLAGS_SLEEP set.
233 .It Sy USB_INVALID_ARGS
234 dip and/or pipe_handle is NULL.
235 Pipe_policy is NULL.
236 .It Sy USB_INVALID_PERM
237 Endpoint is NULL, signifying the default control pipe.
238 A client driver cannot open the default control pipe.
239 .It Sy USB_NOT_SUPPORTED
240 Isochronous or interrupt endpoint with maximum packet size of zero is not
241 supported.
242 .It Sy USB_HC_HARDWARE_ERROR
243 Host controller is in an error state.
244 .It Sy USB_FAILURE
245 Pipe is already open.
246 Host controller not in an operational state.
247 Polling interval
248 .Pq Sy Bep_descr bInterval No field
249 is out of range (intr or isoc pipes).
251 The device referred to by
252 .Fa dip
253 is at least a SuperSpeed device and the older
254 .Fn usb_pipe_open
255 function was used.
257 .Sh EXAMPLES
258 .Bd -literal -offset indent
259 usb_ep_data_t *ep_data;
260 usb_ep_xdescr_t ep_xdescr;
261 usb_pipe_policy_t policy;
262 usb_pipe_handle_t pipe;
263 usb_client_dev_data_t *reg_data;
264 uint8_t interface = 1;
265 uint8_t alternate = 1;
266 uint8_t first_ep_number = 0;
268 /* Initialize pipe policy. */
269 bzero(policy, sizeof(usb_pipe_policy_t));
270 policy.pp_max_async_requests = 2;
272 /* Get tree of descriptors for device. */
273 if (usb_get_dev_data(dip, USBDRV_VERSION, &reg_data,
274     USB_FLAGS_ALL_DESCR, 0) != USB_SUCCESS) {
275         ...
278 /* Get first interrupt-IN endpoint. */
279 ep_data = usb_lookup_ep_data(dip, reg_data, interface, alternate,
280     first_ep_number, USB_EP_ATTR_INTR, USB_EP_DIR_IN);
281 if (ep_data == NULL) {
282         ...
285 /* Translate the ep_data into the filled in usb_ep_xdescr_t */
286 if (usb_ep_xdescr_fill(USB_EP_XDESCR_CURRENT_VERSION, dip,
287     ep_data, &ep_xdescr) != USB_SUCCESS) {
288        ...
291 /* Open the pipe.  Get handle to pipe back in 5th argument. */
292 if (usb_pipe_open(dip, &ep_data.ep_descr
293     &policy, USB_FLAGS_SLEEP, &pipe) != USB_SUCCESS) {
294         ...
297 .Sh SEE ALSO
298 .Xr usb_get_alt_if 9F ,
299 .Xr usb_get_cfg 9F ,
300 .Xr usb_get_dev_data 9F ,
301 .Xr usb_get_status 9F ,
302 .Xr usb_pipe_bulk_xfer 9F ,
303 .Xr usb_pipe_close 9F ,
304 .Xr usb_pipe_ctrl_xfer 9F ,
305 .Xr usb_pipe_get_state 9F ,
306 .Xr usb_pipe_intr_xfer 9F ,
307 .Xr usb_pipe_isoc_xfer 9F ,
308 .Xr usb_pipe_reset 9F ,
309 .Xr usb_pipe_set_private 9F ,
310 .Xr usb_callback_flags 9S ,
311 .Xr usb_ep_descr 9S
313 .%T Universal Serial Bus 3.1 Specification
314 .%U http://www.usb.org