1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
'\" te
.\" Copyright (c) 2009, 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 TRAN_INIT_PKT 9E "Jan 11, 2009"
.SH NAME
tran_init_pkt, tran_destroy_pkt \- SCSI HBA packet preparation and deallocation
.SH SYNOPSIS
.LP
.nf
#include <sys/scsi/scsi.h>
\fBstruct scsi_pkt *prefix\fR\fBtran_init_pkt\fR(\fBstruct scsi_address *\fR\fIap\fR,
\fBstruct scsi_pkt *\fR\fIpkt\fR, \fBstruct buf *\fR\fIbp\fR, \fBint\fR \fIcmdlen\fR,
\fBint\fR \fIstatuslen\fR, \fBint\fR \fItgtlen\fR, \fBint\fR\fIflags\fR, \fBint (*\fR\fIcallback\fR,
\fBcaddr_t),caddr_t\fR \fIarg\fR);
.fi
.LP
.nf
\fBvoid prefix\fR\fBtran_destroy_pkt\fR(\fBstruct scsi_address *\fR\fIap\fR,
\fBstruct scsi_pkt *\fR\fIpkt\fR);
.fi
.SH INTERFACE LEVEL
.sp
.LP
Solaris architecture specific (Solaris DDI).
.SH PARAMETERS
.sp
.ne 2
.na
\fB\fIap\fR\fR
.ad
.RS 13n
Pointer to a \fBscsi_address\fR(9S) structure.
.RE
.sp
.ne 2
.na
\fB\fIpkt\fR\fR
.ad
.RS 13n
Pointer to a \fBscsi_pkt\fR(9S) structure allocated in an earlier call, or
\fINULL\fR.
.RE
.sp
.ne 2
.na
\fB\fIbp\fR\fR
.ad
.RS 13n
Pointer to a \fBbuf\fR(9S) structure if \fBDMA \fRresources are to be allocated
for the \fIpkt\fR, or \fINULL\fR.
.RE
.sp
.ne 2
.na
\fB\fIcmdlen\fR\fR
.ad
.RS 13n
The required length for the \fBSCSI \fRcommand descriptor block (\fBCDB\fR) in
bytes.
.RE
.sp
.ne 2
.na
\fB\fIstatuslen\fR\fR
.ad
.RS 13n
The required length for the \fBSCSI \fRstatus completion block (\fBSCB\fR) in
bytes.
.RE
.sp
.ne 2
.na
\fB\fItgtlen\fR\fR
.ad
.RS 13n
The length of the packet private area within the \fBscsi_pkt\fR to be allocated
on behalf of the \fBSCSI \fRtarget driver.
.RE
.sp
.ne 2
.na
\fB\fIflags\fR\fR
.ad
.RS 13n
Flags for creating the packet.
.RE
.sp
.ne 2
.na
\fB\fIcallback\fR\fR
.ad
.RS 13n
Pointer to either \fBNULL_FUNC\fR or \fBSLEEP_FUNC\fR.
.RE
.sp
.ne 2
.na
\fB\fIarg\fR\fR
.ad
.RS 13n
Always \fINULL\fR.
.RE
.SH DESCRIPTION
.sp
.LP
The \fBtran_init_pkt()\fR and \fBtran_destroy_pkt()\fR vectors in the
\fBscsi_hba_tran\fR structure must be initialized during the \fBHBA \fRdriver's
\fBattach\fR(9E) to point to \fBHBA \fRentry points to be called when a target
driver calls \fBscsi_init_pkt\fR(9F) and \fBscsi_destroy_pkt\fR(9F).
.SS "\fBtran_init_pkt()\fR"
.sp
.LP
\fBtran_init_pkt()\fR is the entry point into the \fBHBA \fRwhich is used to
allocate and initialize a \fBscsi_pkt\fR structure on behalf of a \fBSCSI
\fRtarget driver. If \fIpkt\fR is \fINULL,\fR the \fBHBA \fRdriver must use
\fBscsi_hba_pkt_alloc\fR(9F) to allocate a new \fBscsi_pkt\fR structure.
.sp
.LP
If \fIbp\fR is non-\fINULL\fR, the \fBHBA \fRdriver must allocate appropriate
\fBDMA \fRresources for the \fIpkt\fR, for example,
through \fBddi_dma_buf_setup\fR(9F) or \fBddi_dma_buf_bind_handle\fR(9F).
.sp
.LP
If the \fBPKT_CONSISTENT\fR bit is set in \fIflags\fR, the buffer was allocated
by \fBscsi_alloc_consistent_buf\fR(9F). For packets marked with
\fBPKT_CONSISTENT,\fR the \fBHBA \fRdriver must synchronize any cached data
transfers before calling the target driver's command completion callback.
.sp
.LP
If the \fBPKT_DMA_PARTIAL\fR bit is set in \fIflags\fR, the \fBHBA \fRdriver
should set up partial data transfers, such as setting the \fBDDI_DMA_PARTIAL\fR
bit in the \fIflags\fR argument if interfaces such as
\fBddi_dma_buf_setup\fR(9F) or \fBddi_dma_buf_bind_handle\fR(9F) are used.
.sp
.LP
If only partial \fBDMA \fRresources are available, \fBtran_init_pkt()\fR must
return in the \fBpkt_resid\fR field of \fIpkt\fR the number of bytes of \fBDMA
\fRresources not allocated.
.sp
.LP
If both \fIpkt\fR and \fIbp\fR are non-\fINULL\fR, if the
\fBPKT_DMA_PARTIAL\fR bit is set in \fIflags\fR, and if \fBDMA \fRresources
have already been allocated for the pkt with a previous call to
\fBtran_init_pkt()\fR that returned a non-zero \fBpkt_resid\fR field, this
request is to move the \fBDMA \fRresources for the subsequent piece of the
transfer.
.sp
.LP
The contents of \fBscsi_address\fR(9S) pointed to by \fIap\fR are copied into
the \fBpkt_address\fR field of the \fBscsi_pkt\fR(9S) by
\fBscsi_hba_pkt_alloc\fR(9F).
.sp
.LP
\fItgtlen\fR is the length of the packet private area in the \fBscsi_pkt\fR
structure to be allocated on behalf of the \fBSCSI \fRtarget driver.
.sp
.LP
\fIstatuslen\fR is the required length for the \fBSCSI \fRstatus completion
block. If the requested status length is greater than or equal to
\fBsizeof(struct scsi_arq_status)\fR and the \fBauto_rqsense\fR capability
has been set, automatic request sense (\fBARS\fR) is enabled for this packet.
If the status length is less than \fBsizeof(struct scsi_arq_status)\fR,
automatic request sense must be disabled for this \fIpkt\fR.
.sp
.LP
If the \fBHBA\fR driver is not capable of disabling \fBARQ\fR on a per-packet
basis and \fBtran_init_pkt()\fR is called with a \fIstatuslen\fR that is less
than \fBsizeof(struct scsi_arq_status)\fR, the driver's \fBtran_init_pkt\fR
routine should allocate at least \fBsizeof(struct scsi_arq_status)\fR. If an
\fBARS\fR is needed, upon successful \fBARS\fR done by the \fBHBA\fR driver,
the driver must copy the sense data over and set \fBSTAT_ARQ_DONE\fR in
\fBpkt_state\fR.
.sp
.LP
\fIcmdlen\fR is the required length for the \fBSCSI \fRcommand descriptor
block.
.sp
.LP
Note: \fItgtlen\fR, \fIstatuslen\fR, and \fIcmdlen\fR are used only when the
\fBHBA \fRdriver allocates the \fBscsi_pkt\fR(9S), in other words, when
\fIpkt\fR is \fINULL\fR.
.sp
.LP
\fIcallback\fR indicates what the allocator routines should do when resources
are not available:
.sp
.ne 2
.na
\fB\fBNULL_FUNC\fR\fR
.ad
.RS 14n
Do not wait for resources. Return a \fINULL\fR pointer.
.RE
.sp
.ne 2
.na
\fB\fBSLEEP_FUNC\fR\fR
.ad
.RS 14n
Wait indefinitely for resources.
.RE
.SS "tran_destroy_pkt()"
.sp
.LP
\fBtran_destroy_pkt()\fR is the entry point into the \fBHBA \fRthat must free
all of the resources that were allocated to the \fBscsi_pkt\fR(9S) structure
during \fBtran_init_pkt()\fR.
.SH RETURN VALUES
.sp
.LP
\fBtran_init_pkt()\fR must return a pointer to a \fBscsi_pkt\fR(9S) structure
on success, or \fINULL\fR on failure.
.sp
.LP
If \fIpkt\fR is \fINULL\fR on entry, and \fBtran_init_pkt()\fR allocated a
packet through \fBscsi_hba_pkt_alloc\fR(9F) but was unable to allocate \fBDMA
\fRresources, \fBtran_init_pkt()\fR must free the packet through
\fBscsi_hba_pkt_free\fR(9F) before returning \fINULL\fR.
.SH SEE ALSO
.sp
.LP
\fBattach\fR(9E), \fBtran_setup_pkt\fR(9E), \fBtran_sync_pkt\fR(9E),
\fBbiodone\fR(9F), \fBbioerror\fR(9F), \fBddi_dma_buf_bind_handle\fR(9F),
\fBddi_dma_buf_setup\fR(9F), \fBkmem_cache_create\fR(9F),
\fBscsi_alloc_consistent_buf\fR(9F), \fBscsi_destroy_pkt\fR(9F),
\fBscsi_hba_attach\fR(9F), \fBscsi_hba_pkt_alloc\fR(9F),
\fBscsi_hba_pkt_free\fR(9F), \fBscsi_init_pkt\fR(9F), \fBbuf\fR(9S),
\fBscsi_address\fR(9S), \fBscsi_hba_tran\fR(9S), \fBscsi_pkt\fR(9S)
.sp
.LP
\fIWriting Device Drivers\fR
.SH NOTES
.sp
.LP
If a \fBDMA\fR allocation request fails with \fBDDI_DMA_NOMAPPING\fR, indicate
the error by calling \fBbioerror\fR(9F) with \fIbp\fR and an error code of
\fBEFAULT\fR.
.sp
.LP
If a \fBDMA \fRallocation request fails with \fBDDI_DMA_TOOBIG,\fR indicate the
error by calling \fBbioerror\fR(9F) with \fIbp\fR and an error code of
\fBEINVAL\fR.
.sp
.LP
For increased performance, an HBA driver may want to provide a cache for
\fBscsi_pkt\fR(9S) allocation. This cache should be implemented by the HBA
driver providing a \fBtran_setup_pkt\fR(9E) implementation. Implementing this
cache by direct use of \fBkmem_cache_create\fR(9F) adds a compile-time
dependency on \fBscsi_pkt()\fR size, which is illegal.
|