1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
.\"
.\" This file and its contents are supplied under the terms of the
.\" Common Development and Distribution License ("CDDL"), version 1.0.
.\" You may only use this file in accordance with the terms of version
.\" 1.0 of the CDDL.
.\"
.\" A full copy of the text of the CDDL should have accompanied this
.\" source. A copy of the CDDL is also available via the Internet at
.\" http://www.illumos.org/license/CDDL.
.\"
.\"
.\" Copyright 2016 Joyent, Inc.
.\"
.Dd Dec 22, 2016
.Dt USBA_HCDI_PIPE_INTR_XFER 9E
.Os
.Sh NAME
.Nm usba_hcdi_pipe_intr_xfer
.Nd perform a USB interrupt transfer
.Sh SYNOPSIS
.In sys/usb/usba/hcdi.h
.Ft int
.Fo prefix_hcdi_pipe_intr_xfer
.Fa "usba_pipe_handle_data_t *ph"
.Fa "usb_intr_req_t *uirp"
.Fa "usb_flags_t usb_flags"
.Fc
.Sh INTERFACE LEVEL
.Sy Volatile -
illumos USB HCD private function
.Pp
This is a private function that is not part of the stable DDI.
It may be removed or changed at any time.
.Sh PARAMETERS
.Bl -tag -width Fa
.It Fa ph
A pointer to a USB pipe handle as defined in
.Xr usba_pipe_handle_data 9S .
.It Fa uirp
A pointer to a USB interrupt transfer request.
The structure's members are documented in
.Xr usb_intr_req 9S .
.It Fa usb_flags
Flags which describe how allocations should be performed.
Valid flags are:
.Bl -tag -width Sy
.It Sy USB_FLAGS_NOSLEEP
Do not block waiting for memory.
If memory is not available the allocation will fail.
.It Sy USB_FLAGS_SLEEP
Perform a blocking allocation.
If memory is not available, the function will wait until memory is made
available.
.Pp
Note, the request may still fail even if
.Sy USB_FLAGS_SLEEP
is specified.
.El
.El
.Sh DESCRIPTION
The
.Fn usba_hcdi_pipe_intr_xfer
entry point is used to initiate an
.Em asynchronous
USB interrupt transfer on the pipe
.Fa ph .
The specific USB interrupt transfer is provided in
.Fa uirp .
For more background on transfer types, see
.Xr usba_hcdi 9E .
.Pp
The host controller driver should first check the USB address of the
pipe handle.
It may correspond to the root hub.
If it does, rather than initiating an I/O transfer, the driver may need to
emulate it.
.Pp
Unlike other transfers, interrupt transfers may be periodic.
If the transfer is meant to be a one-shot, then the
.Sy USB_ATTRS_ONE_XFER
flag will be set in the
.Sy intr_attributes
member of the
.Fa uirp
structure.
If the
.Sy USB_ATTRS_ONE_XFER
flag is not set, then the transfer begins a periodic transfer.
Periodic transfers have different handling and behavior.
.Pp
Interrupt transfers may send data to the device or receive data from the device.
A given interrupt endpoint is uni-directional.
The direction can be determined from the endpoint address based on the
.Sy p_ep
member of
.Fa ubrp .
See
.Xr usb_ep_descr 9S
for more information on how to determine the direction of the endpoint.
.Pp
The device driver should allocate memory, whether memory suitable for a
DMA transfer or otherwise, to perform the transfer.
For all memory allocated, it should honor the values in
.Fa usb_flags
to determine whether or not it should block for allocations.
.Pp
The length of the interrupt transfer and its data can be found in the
.Sy intr_len
and
.Sy intr_data
members of
.Fa uirp
respectively.
The
.Xr mblk 9S
structure that should not be used directly and data should be copied to
or from the data buffer that will go the controller.
.Pp
Unlike bulk and control transfers, the
.Fa intr_data
member may not be allocated for interrupt-IN transfers.
In such cases, the device driver is required to allocate the message block
through something like
.Xr allocb 9F
and assign it to the
.Sy intr_data
member.
.Pp
If the driver successfully schedules the I/O, then it should return
.Sy USB_SUCCESS .
When the I/O completes, it must call
.Xr usba_hcdi_cb 9F
with
.Fa uirp .
If the transfer fails, but the driver returned
.Sy USB_SUCCESS ,
it still must call
.Xr usba_hcdi_cb 9F
and should specify an error there.
.Pp
It is the driver's responsibility to time out one-shot interrupt transfer
requests.
If the timeout in the request as indicated in the
.Sy intr_timeout
member of
.Fa uirp
is set to zero, then the driver should use the USBA default timeout of
.Sy HCDI_DEFAULT_TIMEOUT .
All timeout values are in
.Em seconds .
.Ss Periodic Transfers
When the
.Sy USB_ATTRS_ONE_XFER
flag is not present, it indicates that a periodic interrupt transfer is
being initiated.
Once a periodic interrupt transfer is initiated, every time data is received the
driver should call
.Xr usba_hcdi_cb 9F
with the updated data.
.Pp
When a periodic transfer is initiated, many controller drivers will
allocate multiple transfers up front and schedule them all.
Many drivers do this to ensure that data isn't lost between servicing the first
transfer and scheduling the next.
The number of such transfers used depends on the polling frequency specified in
the endpoint descriptor.
.Pp
Unless an error occurs, the driver must not use the original interrupt
request,
.Fa uirp .
Instead, it should duplicate the request through the
.Xr usba_hcdi_dup_intr_req 9F
function before calling
.Xr usba_hcdi_cb 9F .
.Pp
The driver should return the original transfer in one of the following
conditions:
.Bl -bullet
.It
A pipe reset request came in from the
.Xr usba_hcdi_pipe_reset 9E
entry point.
.It
A request to stop polling came in from the
.Xr usba_hcdi_pipe_stop_intr_polling 9E
entry point.
.It
A request to close the pipe came in from the
.Xr usba_hcdi_pipe_close 9E
entry point.
.It
An out of memory condition occurred.
The caller should call
.Xr usba_hcdi_cb 9F
with the code
.Sy USB_CR_NO_RESOURCES .
.It
Some other transfer error occurred.
.El
.Pp
If the periodic interrupt transfer is for the root hub, the driver will
need to emulate the behavior of a hub as specified in the USB
specification.
For more information, see the
.Sx Root Hub Management
section in
.Xr usba_hcdi 9E .
.Ss Callback Handling
When the interrupt transfer completes, the driver should consider the
following items to determine what actions it should take on the
callback:
.Sy USB_SUCCESS .
Otherwise, it should return the appropriate USB error.
If uncertain, use
.Sy USB_FAILURE .
.Bl -bullet
.It
If the transfer timed out, it should remove the transfer from the
outstanding list, queue the next transfer, and return the transfer back
to the OS with the error code
.Sy USB_CR_TIMEOUT
with
.Xr usba_hcdi_cb 9F .
.It
If the transfer failed, it should find the appropriate error and call
.Xr usba_hcdi_cb 9F
with that error.
.It
If the transfer succeeded, but less data was transferred than expected,
consult the
.Sy intr_attributes
member of the
.Fa uirp .
If the
.Sy USB_ATTRS_SHORT_XFER_OK
flag is not present, then the driver should call
.Xr usba_hcdi_cb 9F
with the error
.Sy USB_CR_DATA_UNDERRUN .
.It
If the transfer was going to the host, then the driver should copy the
data into the transfer's message block and update the
.Sy b_wptr
member of the
.Xr mblk 9S .
.It
If everything was successful, call
.Xr usba_hcdi_cb 9F
with the code
.Sy USB_CR_OK .
.It
If this was a periodic transfer, it should reschedule the transfer.
.El
.Sh RETURN VALUES
Upon successful completion, the
.Fn usba_hcdi_pipe_intr_xfer
function should return
function should return
.Sy USB_SUCCESS .
Otherwise, it should return the appropriate USB error.
If uncertain, use
.Sy USB_FAILURE .
.Sh SEE ALSO
.Xr usba_hcdi 9E ,
.Xr usba_hcdi_pipe_close 9E ,
.Xr usba_hcdi_pipe_reset 9E ,
.Xr usba_hcdi_pipe_stop_intr_polling 9E ,
.Xr allocb 9F ,
.Xr usba_hcdi_cb 9F ,
.Xr usba_hcdi_dup_intr_req 9F ,
.Xr mblk 9S ,
.Xr usb_ep_descr 9S ,
.Xr usb_intr_req 9S ,
.Xr usba_pipe_handle_data 9S
|