Mauro Carvalho Chehab | 79e0c2e | 2017-04-05 10:23:02 -0300 | [diff] [blame] | 1 | USB Anchors |
| 2 | ~~~~~~~~~~~ |
| 3 | |
Oliver Neukum | e6a79f1 | 2008-04-09 15:37:34 +0200 | [diff] [blame] | 4 | What is anchor? |
| 5 | =============== |
| 6 | |
| 7 | A USB driver needs to support some callbacks requiring |
| 8 | a driver to cease all IO to an interface. To do so, a |
| 9 | driver has to keep track of the URBs it has submitted |
| 10 | to know they've all completed or to call usb_kill_urb |
| 11 | for them. The anchor is a data structure takes care of |
| 12 | keeping track of URBs and provides methods to deal with |
| 13 | multiple URBs. |
| 14 | |
| 15 | Allocation and Initialisation |
| 16 | ============================= |
| 17 | |
| 18 | There's no API to allocate an anchor. It is simply declared |
Mauro Carvalho Chehab | 79e0c2e | 2017-04-05 10:23:02 -0300 | [diff] [blame] | 19 | as struct usb_anchor. :c:func:`init_usb_anchor` must be called to |
Oliver Neukum | e6a79f1 | 2008-04-09 15:37:34 +0200 | [diff] [blame] | 20 | initialise the data structure. |
| 21 | |
| 22 | Deallocation |
| 23 | ============ |
| 24 | |
| 25 | Once it has no more URBs associated with it, the anchor can be |
| 26 | freed with normal memory management operations. |
| 27 | |
| 28 | Association and disassociation of URBs with anchors |
| 29 | =================================================== |
| 30 | |
| 31 | An association of URBs to an anchor is made by an explicit |
Mauro Carvalho Chehab | 79e0c2e | 2017-04-05 10:23:02 -0300 | [diff] [blame] | 32 | call to :c:func:`usb_anchor_urb`. The association is maintained until |
Matt LaPlante | 19f5946 | 2009-04-27 15:06:31 +0200 | [diff] [blame] | 33 | an URB is finished by (successful) completion. Thus disassociation |
Oliver Neukum | e6a79f1 | 2008-04-09 15:37:34 +0200 | [diff] [blame] | 34 | is automatic. A function is provided to forcibly finish (kill) |
| 35 | all URBs associated with an anchor. |
Mauro Carvalho Chehab | 79e0c2e | 2017-04-05 10:23:02 -0300 | [diff] [blame] | 36 | Furthermore, disassociation can be made with :c:func:`usb_unanchor_urb` |
Oliver Neukum | e6a79f1 | 2008-04-09 15:37:34 +0200 | [diff] [blame] | 37 | |
| 38 | Operations on multitudes of URBs |
| 39 | ================================ |
| 40 | |
Mauro Carvalho Chehab | 79e0c2e | 2017-04-05 10:23:02 -0300 | [diff] [blame] | 41 | :c:func:`usb_kill_anchored_urbs` |
| 42 | -------------------------------- |
Oliver Neukum | e6a79f1 | 2008-04-09 15:37:34 +0200 | [diff] [blame] | 43 | |
| 44 | This function kills all URBs associated with an anchor. The URBs |
| 45 | are called in the reverse temporal order they were submitted. |
| 46 | This way no data can be reordered. |
| 47 | |
Mauro Carvalho Chehab | 79e0c2e | 2017-04-05 10:23:02 -0300 | [diff] [blame] | 48 | :c:func:`usb_unlink_anchored_urbs` |
| 49 | ---------------------------------- |
| 50 | |
Oliver Neukum | 697e04d | 2008-09-02 10:52:08 +0200 | [diff] [blame] | 51 | |
| 52 | This function unlinks all URBs associated with an anchor. The URBs |
| 53 | are processed in the reverse temporal order they were submitted. |
Mauro Carvalho Chehab | 79e0c2e | 2017-04-05 10:23:02 -0300 | [diff] [blame] | 54 | This is similar to :c:func:`usb_kill_anchored_urbs`, but it will not sleep. |
Oliver Neukum | 697e04d | 2008-09-02 10:52:08 +0200 | [diff] [blame] | 55 | Therefore no guarantee is made that the URBs have been unlinked when |
| 56 | the call returns. They may be unlinked later but will be unlinked in |
| 57 | finite time. |
| 58 | |
Mauro Carvalho Chehab | 79e0c2e | 2017-04-05 10:23:02 -0300 | [diff] [blame] | 59 | :c:func:`usb_scuttle_anchored_urbs` |
| 60 | ----------------------------------- |
Oliver Neukum | d1b1944 | 2008-09-02 14:16:11 +0200 | [diff] [blame] | 61 | |
| 62 | All URBs of an anchor are unanchored en masse. |
| 63 | |
Mauro Carvalho Chehab | 79e0c2e | 2017-04-05 10:23:02 -0300 | [diff] [blame] | 64 | :c:func:`usb_wait_anchor_empty_timeout` |
| 65 | --------------------------------------- |
Oliver Neukum | e6a79f1 | 2008-04-09 15:37:34 +0200 | [diff] [blame] | 66 | |
| 67 | This function waits for all URBs associated with an anchor to finish |
| 68 | or a timeout, whichever comes first. Its return value will tell you |
| 69 | whether the timeout was reached. |
Oliver Neukum | 697e04d | 2008-09-02 10:52:08 +0200 | [diff] [blame] | 70 | |
Mauro Carvalho Chehab | 79e0c2e | 2017-04-05 10:23:02 -0300 | [diff] [blame] | 71 | :c:func:`usb_anchor_empty` |
| 72 | -------------------------- |
Oliver Neukum | 697e04d | 2008-09-02 10:52:08 +0200 | [diff] [blame] | 73 | |
Oliver Neukum | d1b1944 | 2008-09-02 14:16:11 +0200 | [diff] [blame] | 74 | Returns true if no URBs are associated with an anchor. Locking |
| 75 | is the caller's responsibility. |
| 76 | |
Mauro Carvalho Chehab | 79e0c2e | 2017-04-05 10:23:02 -0300 | [diff] [blame] | 77 | :c:func:`usb_get_from_anchor` |
| 78 | ----------------------------- |
Oliver Neukum | d1b1944 | 2008-09-02 14:16:11 +0200 | [diff] [blame] | 79 | |
| 80 | Returns the oldest anchored URB of an anchor. The URB is unanchored |
| 81 | and returned with a reference. As you may mix URBs to several |
| 82 | destinations in one anchor you have no guarantee the chronologically |
Matt LaPlante | 19f5946 | 2009-04-27 15:06:31 +0200 | [diff] [blame] | 83 | first submitted URB is returned. |