xref: /illumos-gate/usr/src/man/man9s/scsi_pkt.9s (revision 16b76d3cb933ff92018a2a75594449010192eacb)
1.\" Copyright (c) 2009, Sun Microsystems, Inc.  All Rights Reserved.
2.\" Copyright 2022 Garrett D'Amore
3.\" The contents of this file are subject to the terms of the
4.\" Common Development and Distribution License (the "License").
5.\" You may not use this file except in compliance with the License.
6.\"
7.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
8.\" or http://www.opensolaris.org/os/licensing.
9.\" See the License for the specific language governing permissions
10.\" and limitations under the License.
11.\"
12.\" When distributing Covered Code, include this CDDL HEADER in each
13.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14.\" If applicable, add the following below this CDDL HEADER, with the
15.\" fields enclosed by brackets "[]" replaced with your own identifying
16.\" information: Portions Copyright [yyyy] [name of copyright owner]
17.Dd June 21, 2022
18.Dt SCSI_PKT 9S
19.Os
20.Sh NAME
21.Nm scsi_pkt
22.Nd SCSI packet structure
23.Sh SYNOPSIS
24.In sys/scsi/scsi.h
25.Sh INTERFACE LEVEL
26illumos DDI specific (illumos DDI).
27.Sh DESCRIPTION
28A
29.Nm
30structure defines the packet that is allocated by
31.Xr scsi_init_pkt 9F .
32The target driver fills in some information and passes it to
33.Xr scsi_transport 9F
34for execution on the target.
35The host bus adapter
36.Pq HBA
37fills in other information as the command is processed.
38When the command completes or can be taken no further, the completion function
39specified in the packet is called with a pointer to the packet as its argument.
40From fields within the packet, the target driver can determine the success or
41failure of the command.
42.Sh STRUCTURE MEMBERS
43.Bd -literal -offset indent
44opaque_t             pkt_ha_private;
45struct scsi_address  pkt_address;
46opaque_t             pkt_private;
47void                 (*pkt_comp)(struct scsi_pkt *);
48uint_t               pkt_flags;
49int                  pkt_time;
50uchar_t              *pkt_scbp;
51uchar_t              *pkt_cdbp;
52ssize_t              pkt_resid;
53uint_t               pkt_state;
54uint_t               pkt_statistics;
55uchar_t              pkt_reason;
56uint_t               pkt_cdblen;
57uint_t               pkt_scblen;
58uint_t               pkt_tgtlen;
59uint_t               pkt_numcookies;
60ddi_dma_cookie_t     *pkt_cookies;
61uint_t               pkt_dma_flags;
62.Ed
63.Pp
64These members are described here:
65.Bl -tag -width indent
66.It Fa pkt_ha_private
67Opaque pointer that the HBA uses to reference a private data structure that
68transfers
69.Nm
70requests.
71.It Fa pkt_address
72Initialized by
73.Xr scsi_init_pkt 9F ,
74.Fa pkt_address
75records the intended route and the recipient of a request.
76.It Fa pkt_private
77Reserved for the use of the target driver,
78.Fa pkt_private
79is not changed by the HBA driver.
80.It Fa pkt_comp
81Specifies the command completion callback routine.
82When the host adapter driver has gone as far as it can in transporting a
83command to a SCSI target, and the command has either run to completion or
84can go no further for some other reason, the host adapter driver calls the
85function pointed to by this field and passes a pointer to the packet as
86argument.
87The callback routine itself is called from interrupt context and must not
88sleep or call any function that might sleep.
89.It Fa pkt_flags
90Provides additional information about how the target driver expects the command
91to be executed.
92See
93.Sx pkt_flags Definitions .
94.It Fa pkt_time
95Set by the target driver to represent the maximum time allowed in seconds for
96this command to complete.
97Timeout starts when the command is transmitted on the SCSI bus.
98The
99.Fa pkt_time
100may be zero if no timeout is required.
101.It Fa pkt_scbp
102Points to either a struct
103.Xr scsi_status 9S
104or, if
105.Fa auto-rqsense
106is enabled and
107.Fa pkt_state
108includes
109.Dv STATE_ARQ_DONE ,
110a struct
111.Xr scsi_arq_status 9S .
112If
113.Xr scsi_status 9S
114is returned, the SCSI status byte resulting from the requested command is
115available.
116If
117.Xr scsi_arq_status 9S
118is returned, the sense information is also available.
119.It Fa pkt_cdbp
120Points to a kernel-addressable buffer with a length specified by a call to the
121proper resource allocation routine,
122.Xr scsi_init_pkt 9F .
123.It Fa pkt_resid
124Contains a residual count, either the number of data bytes that have not been
125transferred by
126.Xr scsi_transport 9F
127or the number of data bytes for which
128DMA resources could not be allocated by
129.Xr scsi_init_pkt 9F .
130In the latter case, partial DMA resources can be allocated only if
131.Xr scsi_init_pkt 9F
132is called with the
133.Dv PKT_DMA_PARTIAL
134flag.
135.It Fa pkt_state
136Has bit positions that represent the six most important states that a
137SCSI command can go through.
138See
139.Sx pkt_state Definitions .
140.It Fa pkt_statistics
141Maintains some transport-related statistics.
142See
143.Sx pkt_statistics Definitions .
144.It Fa pkt_reason
145Contains a completion code that indicates why the
146.Fa pkt_comp
147function was called.
148See
149.Sx pkt_reason Definitions .
150.It Fa pkt_cdblen
151Length of buffer pointed to by
152.Fa pkt_cdbp .
153Se
154.Xr  tran_setup_pkt 9E .
155.It Fa pkt_scblen
156Length of buffer pointed to by
157.Fa pkt_scbp .
158See
159.Xr tran_setup_pkt 9E .
160.It Fa pkt_tgtlen
161Length of buffer pointed to by
162.Fa pkt_private .
163See
164.Xr tran_setup_pkt 9E .
165.It Fa pkt_numcookies
166Length of
167.Fa pkt_cookies
168array.
169See
170.Xr tran_setup_pkt 9E .
171.It Fa pkt_cookies
172Array of DMA cookies.
173See
174.Xr tran_setup_pkt 9E .
175.It Fa pkt_dma_flags
176DMA flags used, such as
177.Dv DDI_DMA_READ
178and
179.Dv DDI_DMA_WRITE .
180See
181.Xr tran_setup_pkt 9E .
182.El
183.Pp
184The host adapter driver will update the
185.Fa pkt_resid ,
186.Fa pkt_reason ,
187.Fa pkt_state ,
188and
189.Fa pkt_statistics
190fields.
191.Ss "pkt_flags Definitions"
192The appropriate definitions for the structure member
193.Fa pkt_flags
194are:
195.Bl -tag -width indent
196.It Dv FLAG_NOINTR
197Run command with no command completion callback.
198Command is complete upon return from
199.Xr scsi_transport 9F .
200.It Dv FLAG_NODISCON
201Run command without disconnects.
202.It Dv FLAG_NOPARITY
203Run command without parity checking.
204.It Dv FLAG_HTAG
205Run command as the head-of-queue-tagged command.
206.It Dv FLAG_OTAG
207Run command as an ordered-queue-tagged command.
208.It Dv FLAG_STAG
209Run command as a simple-queue-tagged command.
210.It Dv FLAG_SENSING
211Indicates a request sense command.
212.It Dv FLAG_HEAD
213Place command at the head of the queue.
214.It Dv FLAG_RENEGOTIATE_WIDE_SYNC
215Before transporting this command, the host adapter should initiate the
216renegotiation of wide mode and synchronous transfer speed.
217Normally, the HBA driver manages negotiations but under certain conditions
218forcing a renegotiation is appropriate.
219Renegotiation is recommended before
220.Ql "Request Sense"
221and
222.Ql Inquiry
223commands.
224Refer to the SCSI 2 standard, sections 6.6.21 and 6.6.23.
225.Pp
226This flag should not be set for every packet as this will severely impact
227performance.
228.El
229.Ss "pkt_reason Definitions"
230The appropriate definitions for the structure member
231.Fa pkt_reason
232are:
233.Bl -tag -width indent
234.It Dv CMD_CMPLT
235No transport errors; normal completion.
236.It Dv CMD_INCOMPLETE
237Transport stopped with abnormal state.
238.It Dv CMD_DMA_DERR
239DMA direction error.
240.It Dv CMD_TRAN_ERR
241Unspecified transport error.
242.It Dv CMD_RESET
243SCSI bus reset destroyed command.
244.It Dv CMD_ABORTED
245Command transport aborted on request.
246.It Dv CMD_TIMEOUT
247Command timed out.
248.It Dv CMD_DATA_OVR
249Data overrun.
250.It Dv CMD_CMD_OVR
251Command overrun.
252.It Dv CMD_STS_OVR
253Status overrun.
254.It Dv CMD_BADMSG
255Message not command complete.
256.It Dv CMD_NOMSGOUT
257Target refused to go to message out phase.
258.It Dv CMD_XID_FAIL
259Extended identify message rejected.
260.It Dv CMD_IDE_FAIL
261"Initiator Detected Error" message rejected.
262.It Dv CMD_ABORT_FAIL
263Abort message rejected.
264.It Dv CMD_REJECT_FAIL
265Reject message rejected.
266.It Dv CMD_NOP_FAIL
267"No Operation" message rejected.
268.It Dv CMD_PER_FAIL
269"Message Parity Error" message rejected.
270.It Dv CMD_BDR_FAIL
271"Bus Device Reset" message rejected.
272.It Dv CMD_ID_FAIL
273Identify message rejected.
274.It Dv CMD_UNX_BUS_FREE
275Unexpected bus free phase.
276.It Dv CMD_TAG_REJECT
277Target rejected the tag message.
278.It Dv CMD_DEV_GONE
279The device has been removed.
280.El
281.Ss "pkt_state Definitions"
282The appropriate definitions for the structure member
283.Fa pkt_state
284are:
285.Bl -tag -width indent
286.It Dv STATE_GOT_BUS
287Bus arbitration succeeded.
288.It Dv STATE_GOT_TARGET
289Target successfully selected.
290.It Dv STATE_SENT_CMD
291Command successfully sent.
292.It Dv STATE_XFERRED_DATA
293Data transfer took place.
294.It Dv STATE_GOT_STATUS
295Status received.
296.It Dv STATE_ARQ_DONE
297The command resulted in a check condition and the host adapter driver executed
298an automatic request sense command.
299.It Dv STATE_XARQ_DONE
300The command requested in extra sense data using a
301.Dv PKT_XARQ
302flag got a check condition.
303The host adapter driver was able to successfully request and return this.
304The
305.Sy scsi_pkt.pkt_scbp->sts_rqpkt_resid
306returns the sense data residual based on the
307.Fa statuslen
308parameter of the
309.Xr scsi_init_pkt 9F
310call.
311The sense data begins at
312.Sy scsi_pkt.pkt_scbp->sts_sensedata .
313.El
314.Ss "pkt_statistics Definitions"
315The definitions that are appropriate for the structure member
316.Fa pkt_statistics
317are:
318.Bl -tag -width indent
319.It Dv STAT_DISCON
320Device disconnect.
321.It Dv STAT_SYNC
322Command did a synchronous data transfer.
323.It Dv STAT_PERR
324SCSI parity error.
325.It Dv STAT_BUS_RESET
326Bus reset.
327.It Dv STAT_DEV_RESET
328Device reset.
329.It Dv STAT_ABORTED
330Command was aborted.
331.It Dv STAT_TIMEOUT
332Command timed out.
333.El
334.Sh SEE ALSO
335.Xr tran_init_pkt 9E ,
336.Xr tran_setup_pkt 9E ,
337.Xr scsi_hba_pkt_comp 9F ,
338.Xr scsi_init_pkt 9F ,
339.Xr scsi_transport 9F ,
340.Xr scsi_arq_status 9S ,
341.Xr scsi_status 9S
342.Pp
343.Rs
344.%T "Writing Device Drivers"
345.Re
346.Sh NOTES
347HBA drivers should signal
348.Nm
349completion by calling
350.Xr scsi_hba_pkt_comp 9F .
351This is mandatory for HBA drivers that implement
352.Xr tran_setup_pkt 9E .
353Failure to comply results in undefined behavior.
354.Pp
355Drivers must not make assumptions about the size of the
356.Nm
357structure.
358In particular, this structure must not be directly
359inlined into other driver structures nor allocated
360except by one of the specialized allocation functions
361such as
362.Xr scsi_init_pkt 9F .
363