Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] USB: Update Documentation/usb/URB.txt

This patch (as564) updates Documentation/usb/URB.txt, bringing it roughly
up to the current level.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Alan Stern and committed by
Linus Torvalds
0fc084ea c6c88834

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