xref: /titanic_50/usr/src/man/man9f/usb_pipe_drain_reqs.9f (revision 81a990d5435fe81e68c90bcd35697365a7f718db)
te
Copyright (c) 2004, Sun Microsystems, Inc., All Rights Reserved
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
USB_PIPE_DRAIN_REQS 9F "Jan 5, 2004"
NAME
usb_pipe_drain_reqs - Allow completion of pending pipe requests
SYNOPSIS

#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);
INTERFACE LEVEL

Solaris DDI specific (Solaris DDI)

PARAMETERS
dip

Pointer to the device's dev_info structure.

pipe_handle

Handle of the pipe containing pending requests.

timeout

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

flags

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

callback

Callback handler to notify of asynchronous completion.

callback_arg

Second argument passed to callback function.

DESCRIPTION

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: USB_CB_NO_INFO

Callback was uneventful.

USB_CB_ASYNC_REQ_FAILED

Error starting asynchronous request.

RETURN VALUES
USB_SUCCESS

Request is successful.

USB_INVALID_ARGS

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

USB_INVALID_CONTEXT

Called from callback context with the USB_FLAGS_SLEEP flag set.

USB_INVALID_PIPE

Pipe is not open, is closing or is closed.

CONTEXT

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.

EXAMPLES
 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.
 */
 qprocsoff(q);
 ...
 ...
 ddi_remove_minor_node(dip, NULL);
 ...
 ...
 }

NOTES

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.

ATTRIBUTES

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

ATTRIBUTE TYPE ATTRIBUTE VALUE
Architecture PCI-based systems
Interface stability Committed
SEE ALSO

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