2 Common Libarary for SCSI
4 Copyright (c) 2006 - 2007, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Protocol/ScsiIo.h>
21 // the time unit is 100ns, since the SCSI I/O defines timeout in 100ns unit.
23 #define EFI_SCSI_STALL_1_MICROSECOND 10
24 #define EFI_SCSI_STALL_1_MILLISECOND 10000
25 #define EFI_SCSI_STALL_1_SECOND 10000000
28 /// this macro cannot be directly used by the gBS->Stall(),
29 /// since the value output by this macro is in 100ns unit,
30 /// not 1us unit (1us = 1000ns)
32 #define EfiScsiStallSeconds(a) ((a) * EFI_SCSI_STALL_1_SECOND)
36 Function test the ready status of the SCSI unit.
38 Submit SCSI test unit ready command with SCSI request packet specified by this scsi command, TimeOut
39 and SenseData, then get the status of the target Scsi unit.
41 If SenseDataLength is NULL, then ASSERT().
43 If HostAdapterStatus is NULL, then ASSERT().
45 If TargetStatus is NULL, then ASSERT().
47 @param[in] ScsiIo A pointer to SCSI IO protocol.
48 @param[in] Timeout The length of timeout period.
49 @param[in] SenseData A pointer to output sense data.
50 @param[out] SenseDataLength The length of output sense data.
51 @param[out] HostAdapterStatus The status of Host Adapter.
52 @param[out] TargetStatus The status of the target.
54 @retval EFI_SUCCESS The status of the unit is tested successfully.
55 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
56 but the entire DataBuffer could not be transferred.
57 The actual number of bytes transferred is returned
59 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
60 there are too many SCSI Command Packets already
62 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
63 the SCSI Request Packet.
64 @retval EFI_INVALID_PARAMETER ScsiIo is NULL.
65 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
66 is not supported by the SCSI initiator(i.e., SCSI
68 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
69 Request Packet to execute.
74 ScsiTestUnitReadyCommand (
75 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
78 OUT UINT8
*SenseDataLength
,
79 OUT UINT8
*HostAdapterStatus
,
80 OUT UINT8
*TargetStatus
85 Function to submit SCSI inquiry command.
87 Submit SCSI inquiry command with the SCSI request packet specified by this SCSI command and input
88 parameters, then return the status of Scsi unit execution.
90 If SenseDataLength is NULL, then ASSERT().
92 If HostAdapterStatus is NULL, then ASSERT().
94 If TargetStatus is NULL, then ASSERT().
96 If InquiryDataLength is NULL, then ASSERT().
98 @param[in] ScsiIo SCSI IO Protocol to use
99 @param[in] Timeout The length of timeout period.
100 @param[in] SenseData A pointer to output sense data.
101 @param[in, out] SenseDataLength The length of output sense data.
102 @param[out] HostAdapterStatus The status of Host Adapter.
103 @param[out] TargetStatus The status of the target.
104 @param[in, out] InquiryDataBuffer A pointer to inquiry data buffer.
105 @param[in, out] InquiryDataLength The length of inquiry data buffer.
106 @param[in] EnableVitalProductData Boolean to enable Vital Product Data.
108 @retval EFI_SUCCESS Command is executed successfully.
109 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
110 but the entire DataBuffer could not be transferred.
111 The actual number of bytes transferred is returned
113 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
114 there are too many SCSI Command Packets already
116 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
117 the SCSI Request Packet.
118 @retval EFI_INVALID_PARAMETER ScsiIo is NULL.
119 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
120 is not supported by the SCSI initiator(i.e., SCSI
122 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
123 Request Packet to execute.
129 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
132 IN OUT UINT8
*SenseDataLength
,
133 OUT UINT8
*HostAdapterStatus
,
134 OUT UINT8
*TargetStatus
,
135 IN OUT VOID
*InquiryDataBuffer
,
136 IN OUT UINT32
*InquiryDataLength
,
137 IN BOOLEAN EnableVitalProductData
142 Function to submit SCSI mode sense 10 command.
144 Submit SCSI Mode Sense (10) command with the SCSI request packet specified by this SCSI command and
145 the input parameters, then return the status of Scsi unit execution.
147 If SenseDataLength is NULL, then ASSERT().
149 If HostAdapterStatus is NULL, then ASSERT().
151 If TargetStatus is NULL, then ASSERT().
153 If DataLength is NULL, then ASSERT().
155 @param[in] ScsiIo A pointer to SCSI IO protocol.
156 @param[in] Timeout The length of timeout period.
157 @param[in] SenseData A pointer to output sense data.
158 @param[in, out] SenseDataLength The length of output sense data.
159 @param[out] HostAdapterStatus The status of Host Adapter.
160 @param[out] TargetStatus The status of the target.
161 @param[in] DataBuffer A pointer to input data buffer.
162 @param[in, out] DataLength The length of input data buffer.
163 @param[in] DBDField The DBD Field (Optional).
164 @param[in] PageControl Page Control.
165 @param[in] PageCode Page code.
167 @retval EFI_SUCCESS The status of the unit is tested successfully.
168 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
169 but the entire DataBuffer could not be transferred.
170 The actual number of bytes transferred is returned
172 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
173 there are too many SCSI Command Packets already
175 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
176 the SCSI Request Packet.
177 @retval EFI_INVALID_PARAMETER ScsiIo is NULL.
178 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
179 is not supported by the SCSI initiator(i.e., SCSI
181 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
182 Request Packet to execute.
187 ScsiModeSense10Command (
188 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
191 IN OUT UINT8
*SenseDataLength
,
192 OUT UINT8
*HostAdapterStatus
,
193 OUT UINT8
*TargetStatus
,
195 IN OUT UINT32
*DataLength
,
196 IN UINT8 DBDField
, OPTIONAL
197 IN UINT8 PageControl
,
204 Function to submit SCSI request sense command.
206 Submit SCSI request sense command with the SCSI requested packet specified by this
207 SCSI command, TimeOut and SenseData, and then return the status of scsi unit execution.
209 If SenseDataLength is NULL, then ASSERT().
211 If HostAdapterStatus is NULL, then ASSERT().
213 If TargetStatus is NULL, then ASSERT().
215 @param[in] ScsiIo A pointer to SCSI IO protocol.
216 @param[in] Timeout The length of timeout period.
217 @param[in] SenseData A pointer to output sense data.
218 @param[in, out] SenseDataLength The length of output sense data.
219 @param[out] HostAdapterStatus The status of Host Adapter.
220 @param[out] TargetStatus The status of the target.
222 @retval EFI_SUCCESS Command is executed successfully.
223 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are
224 too many SCSI Command Packets already queued.
225 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
226 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
227 the SCSI initiator(i.e., SCSI Host Controller)
228 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
229 @retval EFI_INVALID_PARAMETER ScsiIo is NULL.
234 ScsiRequestSenseCommand (
235 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
238 IN OUT UINT8
*SenseDataLength
,
239 OUT UINT8
*HostAdapterStatus
,
240 OUT UINT8
*TargetStatus
245 Function to submit read capacity command.
247 Submit SCSI read capacity command with the SCSI request packet specified by this SCSI
248 command and the input parameters, and then return the status of Scsi unit execution.
250 If SenseDataLength is NULL, then ASSERT().
252 If HostAdapterStatus is NULL, then ASSERT().
254 If TargetStatus is NULL, then ASSERT().
256 If DataLength is NULL, then ASSERT().
258 @param[in] ScsiIo A pointer to SCSI IO protocol.
259 @param[in] Timeout The length of timeout period.
260 @param[in] SenseData A pointer to output sense data.
261 @param[in, out] SenseDataLength The length of output sense data.
262 @param[out] HostAdapterStatus The status of Host Adapter.
263 @param[out] TargetStatus The status of the target.
264 @param[out] DataBuffer A pointer to a data buffer.
265 @param[in, out] DataLength The length of data buffer.
266 @param[in] PMI Partial medium indicator.
268 @retval EFI_SUCCESS Command is executed successfully.
269 @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, but the entire DataBuffer could
270 not be transferred. The actual number of bytes transferred is returned in DataLength.
271 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
272 SCSI Command Packets already queued.
273 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
274 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
275 the SCSI initiator(i.e., SCSI Host Controller)
276 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
277 @retval EFI_INVALID_PARAMETER ScsiIo is NULL.
282 ScsiReadCapacityCommand (
283 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
286 IN OUT UINT8
*SenseDataLength
,
287 OUT UINT8
*HostAdapterStatus
,
288 OUT UINT8
*TargetStatus
,
289 OUT VOID
*DataBuffer
,
290 IN OUT UINT32
*DataLength
,
296 Function to submit read 10 command.
298 Submit SCSI read (10) command with the SCSI request packet specified by this SCSI command
299 and the input parameters, and then return the status of Scsi unit execution.
301 If SenseDataLength is NULL, then ASSERT().
303 If HostAdapterStatus is NULL, then ASSERT().
305 If TargetStatus is NULL, then ASSERT().
307 If DataLength is NULL, then ASSERT().
309 @param[in] ScsiIo A pointer to SCSI IO protocol.
310 @param[in] Timeout The length of timeout period.
311 @param[in] SenseData A pointer to output sense data.
312 @param[in, out] SenseDataLength The length of output sense data.
313 @param[out] HostAdapterStatus The status of Host Adapter.
314 @param[out] TargetStatus The status of the target.
315 @param[out] DataBuffer Read 10 command data.
316 @param[in, out] DataLength The length of data buffer.
317 @param[in] StartLba The start address of LBA.
318 @param[in] SectorSize The sector size.
320 @retval EFI_SUCCESS Command is executed successfully.
321 @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, but the entire DataBuffer could
322 not be transferred. The actual number of bytes transferred is returned in DataLength.
323 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
324 SCSI Command Packets already queued.
325 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
326 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
327 the SCSI initiator(i.e., SCSI Host Controller)
328 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
329 @retval EFI_INVALID_PARAMETER ScsiIo is NULL.
335 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
338 IN OUT UINT8
*SenseDataLength
,
339 OUT UINT8
*HostAdapterStatus
,
340 OUT UINT8
*TargetStatus
,
341 OUT VOID
*DataBuffer
,
342 IN OUT UINT32
*DataLength
,
349 Function to submit SCSI write 10 command.
351 Submit SCSI write (10) command with the SCSI request packet specified by this SCSI command and the
352 input parameters, and then return the status of Scsi unit execution.
354 If SenseDataLength is NULL, then ASSERT().
356 If HostAdapterStatus is NULL, then ASSERT().
358 If TargetStatus is NULL, then ASSERT().
360 If DataLength is NULL, then ASSERT().
362 @param[in] ScsiIo SCSI IO Protocol to use
363 @param[in] Timeout The length of timeout period.
364 @param[in] SenseData A pointer to output sense data.
365 @param[in, out] SenseDataLength The length of output sense data.
366 @param[out] HostAdapterStatus The status of Host Adapter.
367 @param[out] TargetStatus The status of the target.
368 @param[out] DataBuffer A pointer to a data buffer.
369 @param[in, out] DataLength The length of data buffer.
370 @param[in] StartLba The start address of LBA.
371 @param[in] SectorSize The sector size.
373 @retval EFI_SUCCESS Command is executed successfully.
374 @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, but the entire DataBuffer could
375 not be transferred. The actual number of bytes transferred is returned in DataLength.
376 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
377 SCSI Command Packets already queued.
378 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
379 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
380 the SCSI initiator(i.e., SCSI Host Controller)
381 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
382 @retval EFI_INVALID_PARAMETER ScsiIo is NULL.
388 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
391 IN OUT UINT8
*SenseDataLength
,
392 OUT UINT8
*HostAdapterStatus
,
393 OUT UINT8
*TargetStatus
,
394 OUT VOID
*DataBuffer
,
395 IN OUT UINT32
*DataLength
,