2 .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH SCSI_ALLOC_CONSISTENT_BUF 9F "Jan 16, 2006"
8 scsi_alloc_consistent_buf \- allocate an I/O buffer for SCSI DMA
12 #include <sys/scsi/scsi.h>
16 \fBstruct buf *\fR\fBscsi_alloc_consistent_buf\fR(\fBstructscsi_address*\fR\fIap\fR,
17 \fBstruct buf *\fR\fIbp\fR, \fBsize_t\fR \fIdatalen\fR, \fBuint_t\fR \fIbflags\fR,
18 \fBint (*\fR\fIcallback\fR)(caddr_t), \fBcaddr_t\fR \fIarg\fR);
24 Solaris DDI specific (Solaris DDI).
32 Pointer to the \fBscsi_address\fR(9S) structure.
41 Pointer to the \fBbuf\fR(9S) structure.
50 Number of bytes for the data buffer.
59 Flags setting for the allocated buffer header. This should either be
60 \fBB_READ\fR or \fBB_WRITE\fR.
69 A pointer to a callback function, \fBNULL_FUNC\fR or \fBSLEEP_FUNC\fR.
78 The callback function argument.
84 The \fBscsi_alloc_consistent_buf()\fR function returns allocates a buffer
85 header and the associated data buffer for direct memory access (DMA) transfer.
86 This buffer is allocated from the \fBiobp\fR space, which is considered
87 consistent memory. For more details, see \fBddi_dma_mem_alloc\fR(9F) and
88 \fBddi_dma_sync\fR(9F).
91 For buffers allocated via \fBscsi_alloc_consistent_buf()\fR, and marked with
92 the \fBPKT_CONSISTENT\fR flag via \fBscsi_init_pkt\fR(9F), the HBA driver must
93 ensure that the data transfer for the command is correctly synchronized before
94 the target driver's command completion callback is performed.
97 If \fIbp\fR is \fINULL\fR, a new buffer header will be allocated using
98 \fBgetrbuf\fR(9F). In addition, if \fIdatalen\fR is non-zero, a new buffer will
99 be allocated using \fBddi_dma_mem_alloc\fR(9F).
102 \fIcallback\fR indicates what the allocator routines should do when direct
103 memory access \fB(DMA)\fR resources are not available; the valid values are:
107 \fB\fBNULL_FUNC\fR\fR
110 Do not wait for resources. Return a \fINULL\fR pointer.
116 \fB\fBSLEEP_FUNC\fR\fR
119 Wait indefinitely for resources.
128 \fIcallback\fR points to a function that is called when resources may become
129 available. \fIcallback\fR must return either \fB0\fR (indicating that it
130 attempted to allocate resources but failed to do so), in which case it is put
131 back on a list to be called again later, or \fB1\fR indicating either success
132 in allocating resources or indicating that it no longer cares for a retry. The
133 last argument \fIarg\fR is supplied to the \fIcallback\fR function when it is
140 The \fBscsi_alloc_consistent_buf()\fR function returns a pointer to a
141 \fBbuf\fR(9S) structure on success. It returns \fBNULL\fR if resources are not
142 available even if \fIwaitfunc\fR was not \fBSLEEP_FUNC\fR.
146 If \fIcallback\fR is \fBSLEEP_FUNC\fR, then this routine may be called only
147 from user-level code. Otherwise, it may be called fromuser, interrupt, or
148 kernel context. The \fIcallback\fR function may not block or call routines that
152 \fBExample 1 \fRAllocate a request sense packet with consistent DMA resources
157 bp = scsi_alloc_consistent_buf(&devp->sd_address, NULL,
158 SENSE_LENGTH, B_READ, SLEEP_FUNC, NULL);
159 rqpkt = scsi_init_pkt(&devp->sd_address,
160 NULL, bp, CDB_GROUP0, 1, 0,
161 PKT_CONSISTENT, SLEEP_FUNC, NULL);
166 \fBExample 2 \fRAllocate an inquiry packet with consistent DMA resources
171 bp = scsi_alloc_consistent_buf(&devp->sd_address, NULL,
172 SUN_INQSIZE, B_READ, canwait, NULL);
174 pkt = scsi_init_pkt(&devp->sd_address, NULL, bp,
175 CDB_GROUP0, 1, PP_LEN, PKT_CONSISTENT,
184 \fBddi_dma_mem_alloc\fR(9F), \fBddi_dma_sync\fR(9F), \fBgetrbuf\fR(9F),
185 \fBscsi_destroy_pkt\fR(9F), \fBscsi_init_pkt\fR(9F),
186 \fBscsi_free_consistent_buf\fR(9F), \fBbuf\fR(9S), \fBscsi_address\fR(9S)
189 \fIWriting Device Drivers\fR