'\" 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] .TH usb_pipe_drain_reqs 9F "5 Jan 2004" "SunOS 5.11" "Kernel Functions for Drivers" .SH NAME usb_pipe_drain_reqs \- Allow completion of pending pipe requests .SH SYNOPSIS .LP .nf #include \fBint\fR \fBusb_pipe_drain_reqs\fR(\fBdev_info_t *\fR\fIdip\fR, \fBusb_pipe_handle_t\fR \fIpipe_handle\fR, \fBuint_t\fR \fItimeout\fR, \fBusb_flags_t\fR \fIusb_flags\fR, \fBvoid (*\fR\fIcallback\fR)(usb_pipe_handle_t \fIpipe_handle\fR, \fBusb_opaque_t\fR \fIcallback_arg\fR, \fBint\fR \fIrval\fR, \fBusb_cb_flags_t\fR \fIflags)\fR, \fBusb_opaque_t\fR \fIcallback_arg\fR); .fi .SH INTERFACE LEVEL .sp .LP Solaris DDI specific (Solaris DDI) .SH PARAMETERS .sp .ne 2 .mk .na \fB\fIdip\fR\fR .ad .RS 16n .rt Pointer to the device's \fBdev_info\fR structure. .RE .sp .ne 2 .mk .na \fB\fIpipe_handle\fR\fR .ad .RS 16n .rt Handle of the pipe containing pending requests. .RE .sp .ne 2 .mk .na \fB\fItimeout\fR\fR .ad .RS 16n .rt Maximum wait time for requests to drain. Must be a non-negative value in seconds. Zero specifies no timeout. .RE .sp .ne 2 .mk .na \fB\fIflags\fR\fR .ad .RS 16n .rt USB_FLAGS_SLEEP is the only flag recognized. Wait for completion and do not call callback. .RE .sp .ne 2 .mk .na \fB\fIcallback\fR\fR .ad .RS 16n .rt Callback handler to notify of asynchronous completion. .RE .sp .ne 2 .mk .na \fB\fIcallback_arg\fR\fR .ad .RS 16n .rt Second argument passed to callback function. .RE .SH DESCRIPTION .sp .LP The \fBusb_pipe_drain_reqs()\fR 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. .sp .LP The \fBusb_pipe_drain_reqs()\fR 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 \fBusb_pipe_close\fR(9F) allows all requests in a pipe to finish before returning. However, a client driver cannot close the default control pipe. .sp .LP 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. .sp .LP The \fIcallback\fR parameter accepts the asynchronous callback handler, which takes the following arguments: .sp .ne 2 .mk .na \fBusb_pipe_handle_t default_pipe_handle\fR .ad .sp .6 .RS 4n Handle of the pipe to drain. .RE .sp .ne 2 .mk .na \fBusb_opaque_t callback_arg\fR .ad .sp .6 .RS 4n callback_arg specified to \fBusb_pipe_drain_reqs()\fR. .RE .sp .ne 2 .mk .na \fBint rval\fR .ad .sp .6 .RS 4n Request status. .RE .sp .ne 2 .mk .na \fBusb_cb_flags_t callback_flags\fR .ad .sp .6 .RS 4n Status of the queueing operation. Can be: .sp .ne 2 .mk .na \fBUSB_CB_NO_INFO\fR .ad .RS 27n .rt Callback was uneventful. .RE .sp .ne 2 .mk .na \fBUSB_CB_ASYNC_REQ_FAILED\fR .ad .RS 27n .rt Error starting asynchronous request. .RE .RE .SH RETURN VALUES .sp .ne 2 .mk .na \fBUSB_SUCCESS\fR .ad .RS 23n .rt Request is successful. .RE .sp .ne 2 .mk .na \fBUSB_INVALID_ARGS\fR .ad .RS 23n .rt \fIdip\fR argument is \fBNULL\fR. USB_FLAGS_SLEEP is clear and callback is \fBNULL\fR. .RE .sp .ne 2 .mk .na \fBUSB_INVALID_CONTEXT\fR .ad .RS 23n .rt Called from callback context with the USB_FLAGS_SLEEP flag set. .RE .sp .ne 2 .mk .na \fBUSB_INVALID_PIPE\fR .ad .RS 23n .rt Pipe is not open, is closing or is closed. .RE .SH CONTEXT .sp .LP May be called from user or kernel context. .sp .LP 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 \fBusb_callback_flags\fR(9S) for more information on callbacks. .SH EXAMPLES .sp .in +2 .nf 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); ... ... } .fi .in -2 .SH NOTES .sp .LP For pipes other than the default control pipe, it is recommended to close the pipe using a synchronous \fBusb_pipe_close()\fR. \fBusb_pipe_close()\fR with the USB_FLAGS_SLEEP flag allows any pending requests in that pipe to complete before returning. .sp .LP Do not call \fBusb_pipe_drain_reqs()\fR while additional requests are being submitted by a different thread. This action can stall the calling thread of \fBusb_pipe_drain_reqs()\fR unnecessarily. .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ ArchitecturePCI-based systems _ Interface stabilityCommitted .TE .SH SEE ALSO .sp .LP \fBattributes\fR(5), \fBusb_pipe_close\fR(9F), \fBusb_pipe_reset\fR(9F), \fBusb_callback_flags\fR(9S)