2017-04-05 16:23:02 +03:00
USB Anchors
~~~~~~~~~~~
2008-04-09 17:37:34 +04:00
What is anchor?
===============
A USB driver needs to support some callbacks requiring
a driver to cease all IO to an interface. To do so, a
driver has to keep track of the URBs it has submitted
to know they've all completed or to call usb_kill_urb
for them. The anchor is a data structure takes care of
keeping track of URBs and provides methods to deal with
multiple URBs.
Allocation and Initialisation
=============================
There's no API to allocate an anchor. It is simply declared
2017-04-05 16:23:02 +03:00
as struct usb_anchor. :c:func: `init_usb_anchor` must be called to
2008-04-09 17:37:34 +04:00
initialise the data structure.
Deallocation
============
Once it has no more URBs associated with it, the anchor can be
freed with normal memory management operations.
Association and disassociation of URBs with anchors
===================================================
An association of URBs to an anchor is made by an explicit
2017-04-05 16:23:02 +03:00
call to :c:func: `usb_anchor_urb` . The association is maintained until
2009-04-27 17:06:31 +04:00
an URB is finished by (successful) completion. Thus disassociation
2008-04-09 17:37:34 +04:00
is automatic. A function is provided to forcibly finish (kill)
all URBs associated with an anchor.
2017-04-05 16:23:02 +03:00
Furthermore, disassociation can be made with :c:func: `usb_unanchor_urb`
2008-04-09 17:37:34 +04:00
Operations on multitudes of URBs
================================
2017-04-05 16:23:02 +03:00
:c:func: `usb_kill_anchored_urbs`
--------------------------------
2008-04-09 17:37:34 +04:00
This function kills all URBs associated with an anchor. The URBs
are called in the reverse temporal order they were submitted.
This way no data can be reordered.
2017-04-05 16:23:02 +03:00
:c:func: `usb_unlink_anchored_urbs`
----------------------------------
2008-09-02 12:52:08 +04:00
This function unlinks all URBs associated with an anchor. The URBs
are processed in the reverse temporal order they were submitted.
2017-04-05 16:23:02 +03:00
This is similar to :c:func: `usb_kill_anchored_urbs` , but it will not sleep.
2008-09-02 12:52:08 +04:00
Therefore no guarantee is made that the URBs have been unlinked when
the call returns. They may be unlinked later but will be unlinked in
finite time.
2017-04-05 16:23:02 +03:00
:c:func: `usb_scuttle_anchored_urbs`
-----------------------------------
2008-09-02 16:16:11 +04:00
All URBs of an anchor are unanchored en masse.
2017-04-05 16:23:02 +03:00
:c:func: `usb_wait_anchor_empty_timeout`
---------------------------------------
2008-04-09 17:37:34 +04:00
This function waits for all URBs associated with an anchor to finish
or a timeout, whichever comes first. Its return value will tell you
whether the timeout was reached.
2008-09-02 12:52:08 +04:00
2017-04-05 16:23:02 +03:00
:c:func: `usb_anchor_empty`
--------------------------
2008-09-02 16:16:11 +04:00
Returns true if no URBs are associated with an anchor. Locking
is the caller's responsibility.
2017-04-05 16:23:02 +03:00
:c:func: `usb_get_from_anchor`
-----------------------------
2008-09-02 12:52:08 +04:00
2008-09-02 16:16:11 +04:00
Returns the oldest anchored URB of an anchor. The URB is unanchored
and returned with a reference. As you may mix URBs to several
destinations in one anchor you have no guarantee the chronologically
2009-04-27 17:06:31 +04:00
first submitted URB is returned.