blob: 4b248e691bd6e76c838d84e3c778f6e06415c15e [file] [log] [blame]
Mauro Carvalho Chehab79e0c2e2017-04-05 10:23:02 -03001USB Anchors
2~~~~~~~~~~~
3
Oliver Neukume6a79f12008-04-09 15:37:34 +02004What is anchor?
5===============
6
7A USB driver needs to support some callbacks requiring
8a driver to cease all IO to an interface. To do so, a
9driver has to keep track of the URBs it has submitted
10to know they've all completed or to call usb_kill_urb
11for them. The anchor is a data structure takes care of
12keeping track of URBs and provides methods to deal with
13multiple URBs.
14
15Allocation and Initialisation
16=============================
17
18There's no API to allocate an anchor. It is simply declared
Mauro Carvalho Chehab79e0c2e2017-04-05 10:23:02 -030019as struct usb_anchor. :c:func:`init_usb_anchor` must be called to
Oliver Neukume6a79f12008-04-09 15:37:34 +020020initialise the data structure.
21
22Deallocation
23============
24
25Once it has no more URBs associated with it, the anchor can be
26freed with normal memory management operations.
27
28Association and disassociation of URBs with anchors
29===================================================
30
31An association of URBs to an anchor is made by an explicit
Mauro Carvalho Chehab79e0c2e2017-04-05 10:23:02 -030032call to :c:func:`usb_anchor_urb`. The association is maintained until
Matt LaPlante19f59462009-04-27 15:06:31 +020033an URB is finished by (successful) completion. Thus disassociation
Oliver Neukume6a79f12008-04-09 15:37:34 +020034is automatic. A function is provided to forcibly finish (kill)
35all URBs associated with an anchor.
Mauro Carvalho Chehab79e0c2e2017-04-05 10:23:02 -030036Furthermore, disassociation can be made with :c:func:`usb_unanchor_urb`
Oliver Neukume6a79f12008-04-09 15:37:34 +020037
38Operations on multitudes of URBs
39================================
40
Mauro Carvalho Chehab79e0c2e2017-04-05 10:23:02 -030041:c:func:`usb_kill_anchored_urbs`
42--------------------------------
Oliver Neukume6a79f12008-04-09 15:37:34 +020043
44This function kills all URBs associated with an anchor. The URBs
45are called in the reverse temporal order they were submitted.
46This way no data can be reordered.
47
Mauro Carvalho Chehab79e0c2e2017-04-05 10:23:02 -030048:c:func:`usb_unlink_anchored_urbs`
49----------------------------------
50
Oliver Neukum697e04d2008-09-02 10:52:08 +020051
52This function unlinks all URBs associated with an anchor. The URBs
53are processed in the reverse temporal order they were submitted.
Mauro Carvalho Chehab79e0c2e2017-04-05 10:23:02 -030054This is similar to :c:func:`usb_kill_anchored_urbs`, but it will not sleep.
Oliver Neukum697e04d2008-09-02 10:52:08 +020055Therefore no guarantee is made that the URBs have been unlinked when
56the call returns. They may be unlinked later but will be unlinked in
57finite time.
58
Mauro Carvalho Chehab79e0c2e2017-04-05 10:23:02 -030059:c:func:`usb_scuttle_anchored_urbs`
60-----------------------------------
Oliver Neukumd1b19442008-09-02 14:16:11 +020061
62All URBs of an anchor are unanchored en masse.
63
Mauro Carvalho Chehab79e0c2e2017-04-05 10:23:02 -030064:c:func:`usb_wait_anchor_empty_timeout`
65---------------------------------------
Oliver Neukume6a79f12008-04-09 15:37:34 +020066
67This function waits for all URBs associated with an anchor to finish
68or a timeout, whichever comes first. Its return value will tell you
69whether the timeout was reached.
Oliver Neukum697e04d2008-09-02 10:52:08 +020070
Mauro Carvalho Chehab79e0c2e2017-04-05 10:23:02 -030071:c:func:`usb_anchor_empty`
72--------------------------
Oliver Neukum697e04d2008-09-02 10:52:08 +020073
Oliver Neukumd1b19442008-09-02 14:16:11 +020074Returns true if no URBs are associated with an anchor. Locking
75is the caller's responsibility.
76
Mauro Carvalho Chehab79e0c2e2017-04-05 10:23:02 -030077:c:func:`usb_get_from_anchor`
78-----------------------------
Oliver Neukumd1b19442008-09-02 14:16:11 +020079
80Returns the oldest anchored URB of an anchor. The URB is unanchored
81and returned with a reference. As you may mix URBs to several
82destinations in one anchor you have no guarantee the chronologically
Matt LaPlante19f59462009-04-27 15:06:31 +020083first submitted URB is returned.