aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/usb/URB.txt
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/usb/URB.txt')
-rw-r--r--Documentation/usb/URB.txt74
1 files changed, 31 insertions, 43 deletions
diff --git a/Documentation/usb/URB.txt b/Documentation/usb/URB.txt
index d59b95cc6f1b..a49e5f2c2b46 100644
--- a/Documentation/usb/URB.txt
+++ b/Documentation/usb/URB.txt
@@ -1,5 +1,6 @@
1Revised: 2000-Dec-05. 1Revised: 2000-Dec-05.
2Again: 2002-Jul-06 2Again: 2002-Jul-06
3Again: 2005-Sep-19
3 4
4 NOTE: 5 NOTE:
5 6
@@ -18,8 +19,8 @@ called USB Request Block, or URB for short.
18 and deliver the data and status back. 19 and deliver the data and status back.
19 20
20- Execution of an URB is inherently an asynchronous operation, i.e. the 21- Execution of an URB is inherently an asynchronous operation, i.e. the
21 usb_submit_urb(urb) call returns immediately after it has successfully queued 22 usb_submit_urb(urb) call returns immediately after it has successfully
22 the requested action. 23 queued the requested action.
23 24
24- Transfers for one URB can be canceled with usb_unlink_urb(urb) at any time. 25- Transfers for one URB can be canceled with usb_unlink_urb(urb) at any time.
25 26
@@ -94,8 +95,9 @@ To free an URB, use
94 95
95 void usb_free_urb(struct urb *urb) 96 void usb_free_urb(struct urb *urb)
96 97
97You may not free an urb that you've submitted, but which hasn't yet been 98You may free an urb that you've submitted, but which hasn't yet been
98returned to you in a completion callback. 99returned to you in a completion callback. It will automatically be
100deallocated when it is no longer in use.
99 101
100 102
1011.4. What has to be filled in? 1031.4. What has to be filled in?
@@ -145,30 +147,36 @@ to get seamless ISO streaming.
145 147
1461.6. How to cancel an already running URB? 1481.6. How to cancel an already running URB?
147 149
148For an URB which you've submitted, but which hasn't been returned to 150There are two ways to cancel an URB you've submitted but which hasn't
149your driver by the host controller, call 151been returned to your driver yet. For an asynchronous cancel, call
150 152
151 int usb_unlink_urb(struct urb *urb) 153 int usb_unlink_urb(struct urb *urb)
152 154
153It removes the urb from the internal list and frees all allocated 155It removes the urb from the internal list and frees all allocated
154HW descriptors. The status is changed to reflect unlinking. After 156HW descriptors. The status is changed to reflect unlinking. Note
155usb_unlink_urb() returns with that status code, you can free the URB 157that the URB will not normally have finished when usb_unlink_urb()
156with usb_free_urb(). 158returns; you must still wait for the completion handler to be called.
157 159
158There is also an asynchronous unlink mode. To use this, set the 160To cancel an URB synchronously, call
159the URB_ASYNC_UNLINK flag in urb->transfer flags before calling 161
160usb_unlink_urb(). When using async unlinking, the URB will not 162 void usb_kill_urb(struct urb *urb)
161normally be unlinked when usb_unlink_urb() returns. Instead, wait 163
162for the completion handler to be called. 164It does everything usb_unlink_urb does, and in addition it waits
165until after the URB has been returned and the completion handler
166has finished. It also marks the URB as temporarily unusable, so
167that if the completion handler or anyone else tries to resubmit it
168they will get a -EPERM error. Thus you can be sure that when
169usb_kill_urb() returns, the URB is totally idle.
163 170
164 171
1651.7. What about the completion handler? 1721.7. What about the completion handler?
166 173
167The handler is of the following type: 174The handler is of the following type:
168 175
169 typedef void (*usb_complete_t)(struct urb *); 176 typedef void (*usb_complete_t)(struct urb *, struct pt_regs *)
170 177
171i.e. it gets just the URB that caused the completion call. 178I.e., it gets the URB that caused the completion call, plus the
179register values at the time of the corresponding interrupt (if any).
172In the completion handler, you should have a look at urb->status to 180In the completion handler, you should have a look at urb->status to
173detect any USB errors. Since the context parameter is included in the URB, 181detect any USB errors. Since the context parameter is included in the URB,
174you can pass information to the completion handler. 182you can pass information to the completion handler.
@@ -176,17 +184,11 @@ you can pass information to the completion handler.
176Note that even when an error (or unlink) is reported, data may have been 184Note that even when an error (or unlink) is reported, data may have been
177transferred. That's because USB transfers are packetized; it might take 185transferred. That's because USB transfers are packetized; it might take
178sixteen packets to transfer your 1KByte buffer, and ten of them might 186sixteen packets to transfer your 1KByte buffer, and ten of them might
179have transferred succesfully before the completion is called. 187have transferred succesfully before the completion was called.
180 188
181 189
182NOTE: ***** WARNING ***** 190NOTE: ***** WARNING *****
183Don't use urb->dev field in your completion handler; it's cleared 191NEVER SLEEP IN A COMPLETION HANDLER. These are normally called
184as part of giving urbs back to drivers. (Addressing an issue with
185ownership of periodic URBs, which was otherwise ambiguous.) Instead,
186use urb->context to hold all the data your driver needs.
187
188NOTE: ***** WARNING *****
189Also, NEVER SLEEP IN A COMPLETION HANDLER. These are normally called
190during hardware interrupt processing. If you can, defer substantial 192during hardware interrupt processing. If you can, defer substantial
191work to a tasklet (bottom half) to keep system latencies low. You'll 193work to a tasklet (bottom half) to keep system latencies low. You'll
192probably need to use spinlocks to protect data structures you manipulate 194probably need to use spinlocks to protect data structures you manipulate
@@ -229,24 +231,10 @@ ISO data with some other event stream.
229Interrupt transfers, like isochronous transfers, are periodic, and happen 231Interrupt transfers, like isochronous transfers, are periodic, and happen
230in intervals that are powers of two (1, 2, 4 etc) units. Units are frames 232in intervals that are powers of two (1, 2, 4 etc) units. Units are frames
231for full and low speed devices, and microframes for high speed ones. 233for full and low speed devices, and microframes for high speed ones.
232
233Currently, after you submit one interrupt URB, that urb is owned by the
234host controller driver until you cancel it with usb_unlink_urb(). You
235may unlink interrupt urbs in their completion handlers, if you need to.
236
237After a transfer completion is called, the URB is automagically resubmitted.
238THIS BEHAVIOR IS EXPECTED TO BE REMOVED!!
239
240Interrupt transfers may only send (or receive) the "maxpacket" value for
241the given interrupt endpoint; if you need more data, you will need to
242copy that data out of (or into) another buffer. Similarly, you can't
243queue interrupt transfers.
244THESE RESTRICTIONS ARE EXPECTED TO BE REMOVED!!
245
246Note that this automagic resubmission model does make it awkward to use
247interrupt OUT transfers. The portable solution involves unlinking those
248OUT urbs after the data is transferred, and perhaps submitting a final
249URB for a short packet.
250
251The usb_submit_urb() call modifies urb->interval to the implemented interval 234The usb_submit_urb() call modifies urb->interval to the implemented interval
252value that is less than or equal to the requested interval value. 235value that is less than or equal to the requested interval value.
236
237In Linux 2.6, unlike earlier versions, interrupt URBs are not automagically
238restarted when they complete. They end when the completion handler is
239called, just like other URBs. If you want an interrupt URB to be restarted,
240your completion handler must resubmit it.