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