USB_PIPE_DRAIN_REQS(9F) Kernel Functions for Drivers USB_PIPE_DRAIN_REQS(9F)

usb_pipe_drain_reqs - Allow completion of pending pipe requests

#include <sys/usb/usba.h>
int usb_pipe_drain_reqs(dev_info_t *dip, usb_pipe_handle_t pipe_handle,

uint_t timeout, usb_flags_t usb_flags,
void (*callback)(usb_pipe_handle_t pipe_handle,
usb_opaque_t callback_arg, int rval, usb_cb_flags_t flags),
usb_opaque_t callback_arg);

illumos DDI specific (illumos DDI)


Pointer to the device's dev_info structure.


Handle of the pipe containing pending requests.


Maximum wait time for requests to drain. Must be a non-negative value in seconds. Zero specifies no timeout.


USB_FLAGS_SLEEP is the only flag recognized. Wait for completion and do not call callback.


Callback handler to notify of asynchronous completion.


Second argument passed to callback function.

The usb_pipe_drain_reqs() function provides waits for pending requests to complete and then provides synchronous or asynchronous notification that all pending requests on a non-shared pipe indicated by pipe_handle have completed. For a shared pipe (such as the default control pipe used by multiple drivers each managing one interface of a device), this function provides notification that all pending requests on that pipe that are associated with a given dip are completed.

The usb_pipe_drain_reqs() function can be used to notify a close procedure when the default control pipe is clear during device closure, thereby allowing the close procedure to continue safely. Normally, a synchronous call to usb_pipe_close(9F) allows all requests in a pipe to finish before returning. However, a client driver cannot close the default control pipe.

If USB_FLAGS_SLEEP is set in flags, block until all pending requests are completed. Otherwise, return immediately and call the callback handler when all pending requests are completed.

The callback parameter accepts the asynchronous callback handler, which takes the following arguments:

usb_pipe_handle_t default_pipe_handle

Handle of the pipe to drain.

usb_opaque_t callback_arg

callback_arg specified to usb_pipe_drain_reqs().

int rval

Request status.

usb_cb_flags_t callback_flags

Status of the queueing operation. Can be:


Callback was uneventful.


Error starting asynchronous request.


Request is successful.


dip argument is NULL. USB_FLAGS_SLEEP is clear and callback is NULL.


Called from callback context with the USB_FLAGS_SLEEP flag set.


Pipe is not open, is closing or is closed.

May be called from user or kernel context.

If the USB_CB_ASYNC_REQ_FAILED bit is clear in usb_cb_flags_t, the callback, if supplied, can block because it is executing in kernel context. Otherwise the callback cannot block. Please see usb_callback_flags(9S) for more information on callbacks.

mydev_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
mydev_state->pipe_state = CLOSED;
/* Wait for pending requests of a pipe to finish. Don't timeout. */
(void) usb_pipe_drain_reqs(
dip, pipe_handle, 0, USB_FLAGS_SLEEP, NULL, 0);
* Dismantle streams and tear down this instance,
* now that all requests have been sent.
ddi_remove_minor_node(dip, NULL);

For pipes other than the default control pipe, it is recommended to close the pipe using a synchronous usb_pipe_close(). usb_pipe_close() with the USB_FLAGS_SLEEP flag allows any pending requests in that pipe to complete before returning.

Do not call usb_pipe_drain_reqs() while additional requests are being submitted by a different thread. This action can stall the calling thread of usb_pipe_drain_reqs() unnecessarily.

See attributes(7) for descriptions of the following attributes:

Architecture PCI-based systems
Interface stability Committed

attributes(7), usb_pipe_close(9F), usb_pipe_reset(9F), usb_callback_flags(9S)

January 5, 2004 OmniOS