3 Provides the functions to submit Scsi commands defined in SCSI-2 specification for scsi device.
5 Copyright (c) 2006 - 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include <Protocol/ScsiIo.h>
22 // the time unit is 100ns, since the SCSI I/O defines timeout in 100ns unit.
24 #define EFI_SCSI_STALL_1_MICROSECOND 10
25 #define EFI_SCSI_STALL_1_MILLISECOND 10000
26 #define EFI_SCSI_STALL_1_SECOND 10000000
29 /// this macro cannot be directly used by the gBS->Stall(),
30 /// since the value output by this macro is in 100ns unit,
31 /// not 1us unit (1us = 1000ns)
33 #define EFI_SCSI_STALL_SECONDS(a) ((a) * EFI_SCSI_STALL_1_SECOND)
37 Function test the ready status of the SCSI unit.
39 Submit SCSI test unit ready command with SCSI request packet specified by this scsi command, TimeOut
40 and SenseData, then get the status of the target Scsi unit.
42 If SenseDataLength is NULL, then ASSERT().
44 If HostAdapterStatus is NULL, then ASSERT().
46 If TargetStatus is NULL, then ASSERT().
48 @param[in] ScsiIo A pointer to SCSI IO protocol.
49 @param[in] Timeout The length of timeout period.
50 @param[in] SenseData A pointer to output sense data.
51 @param[out] SenseDataLength The length of output sense data.
52 @param[out] HostAdapterStatus The status of Host Adapter.
53 @param[out] TargetStatus The status of the target.
55 @retval EFI_SUCCESS The status of the unit is tested successfully.
56 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
57 but the entire DataBuffer could not be transferred.
58 The actual number of bytes transferred is returned
60 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
61 there are too many SCSI Command Packets already
63 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
64 the SCSI Request Packet.
65 @retval EFI_INVALID_PARAMETER ScsiIo is NULL.
66 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
67 is not supported by the SCSI initiator(i.e., SCSI
69 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
70 Request Packet to execute.
75 ScsiTestUnitReadyCommand (
76 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
79 OUT UINT8
*SenseDataLength
,
80 OUT UINT8
*HostAdapterStatus
,
81 OUT UINT8
*TargetStatus
86 Function to submit SCSI inquiry command.
88 Submit SCSI inquiry command with the SCSI request packet specified by this SCSI command and input
89 parameters, then return the status of Scsi unit execution.
91 If SenseDataLength is NULL, then ASSERT().
93 If HostAdapterStatus is NULL, then ASSERT().
95 If TargetStatus is NULL, then ASSERT().
97 If InquiryDataLength is NULL, then ASSERT().
99 @param[in] ScsiIo SCSI IO Protocol to use
100 @param[in] Timeout The length of timeout period.
101 @param[in] SenseData A pointer to output sense data.
102 @param[in, out] SenseDataLength The length of output sense data.
103 @param[out] HostAdapterStatus The status of Host Adapter.
104 @param[out] TargetStatus The status of the target.
105 @param[in, out] InquiryDataBuffer A pointer to inquiry data buffer.
106 @param[in, out] InquiryDataLength The length of inquiry data buffer.
107 @param[in] EnableVitalProductData Boolean to enable Vital Product Data.
109 @retval EFI_SUCCESS Command is executed successfully.
110 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
111 but the entire DataBuffer could not be transferred.
112 The actual number of bytes transferred is returned
114 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
115 there are too many SCSI Command Packets already
117 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
118 the SCSI Request Packet.
119 @retval EFI_INVALID_PARAMETER ScsiIo is NULL.
120 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
121 is not supported by the SCSI initiator(i.e., SCSI
123 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
124 Request Packet to execute.
130 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
133 IN OUT UINT8
*SenseDataLength
,
134 OUT UINT8
*HostAdapterStatus
,
135 OUT UINT8
*TargetStatus
,
136 IN OUT VOID
*InquiryDataBuffer
,
137 IN OUT UINT32
*InquiryDataLength
,
138 IN BOOLEAN EnableVitalProductData
143 Function to submit SCSI mode sense 10 command.
145 Submit SCSI Mode Sense (10) command with the SCSI request packet specified by this SCSI command and
146 the input parameters, then return the status of Scsi unit execution.
148 If SenseDataLength is NULL, then ASSERT().
150 If HostAdapterStatus is NULL, then ASSERT().
152 If TargetStatus is NULL, then ASSERT().
154 If DataLength is NULL, then ASSERT().
156 @param[in] ScsiIo A pointer to SCSI IO protocol.
157 @param[in] Timeout The length of timeout period.
158 @param[in] SenseData A pointer to output sense data.
159 @param[in, out] SenseDataLength The length of output sense data.
160 @param[out] HostAdapterStatus The status of Host Adapter.
161 @param[out] TargetStatus The status of the target.
162 @param[in] DataBuffer A pointer to input data buffer.
163 @param[in, out] DataLength The length of input data buffer.
164 @param[in] DBDField The DBD Field (Optional).
165 @param[in] PageControl Page Control.
166 @param[in] PageCode Page code.
168 @retval EFI_SUCCESS The status of the unit is tested successfully.
169 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
170 but the entire DataBuffer could not be transferred.
171 The actual number of bytes transferred is returned
173 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
174 there are too many SCSI Command Packets already
176 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
177 the SCSI Request Packet.
178 @retval EFI_INVALID_PARAMETER ScsiIo is NULL.
179 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
180 is not supported by the SCSI initiator(i.e., SCSI
182 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
183 Request Packet to execute.
188 ScsiModeSense10Command (
189 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
192 IN OUT UINT8
*SenseDataLength
,
193 OUT UINT8
*HostAdapterStatus
,
194 OUT UINT8
*TargetStatus
,
196 IN OUT UINT32
*DataLength
,
197 IN UINT8 DBDField
, OPTIONAL
198 IN UINT8 PageControl
,
205 Function to submit SCSI request sense command.
207 Submit SCSI request sense command with the SCSI requested packet specified by this
208 SCSI command, TimeOut and SenseData, and then return the status of scsi unit execution.
210 If SenseDataLength is NULL, then ASSERT().
212 If HostAdapterStatus is NULL, then ASSERT().
214 If TargetStatus is NULL, then ASSERT().
216 @param[in] ScsiIo A pointer to SCSI IO protocol.
217 @param[in] Timeout The length of timeout period.
218 @param[in] SenseData A pointer to output sense data.
219 @param[in, out] SenseDataLength The length of output sense data.
220 @param[out] HostAdapterStatus The status of Host Adapter.
221 @param[out] TargetStatus The status of the target.
223 @retval EFI_SUCCESS Command is executed successfully.
224 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are
225 too many SCSI Command Packets already queued.
226 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
227 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
228 the SCSI initiator(i.e., SCSI Host Controller)
229 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
230 @retval EFI_INVALID_PARAMETER ScsiIo is NULL.
235 ScsiRequestSenseCommand (
236 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
239 IN OUT UINT8
*SenseDataLength
,
240 OUT UINT8
*HostAdapterStatus
,
241 OUT UINT8
*TargetStatus
246 Function to submit read capacity command.
248 Submit SCSI read capacity command with the SCSI request packet specified by this SCSI
249 command and the input parameters, and then return the status of Scsi unit execution.
251 If SenseDataLength is NULL, then ASSERT().
253 If HostAdapterStatus is NULL, then ASSERT().
255 If TargetStatus is NULL, then ASSERT().
257 If DataLength is NULL, then ASSERT().
259 @param[in] ScsiIo A pointer to SCSI IO protocol.
260 @param[in] Timeout The length of timeout period.
261 @param[in] SenseData A pointer to output sense data.
262 @param[in, out] SenseDataLength The length of output sense data.
263 @param[out] HostAdapterStatus The status of Host Adapter.
264 @param[out] TargetStatus The status of the target.
265 @param[out] DataBuffer A pointer to a data buffer.
266 @param[in, out] DataLength The length of data buffer.
267 @param[in] PMI Partial medium indicator.
269 @retval EFI_SUCCESS Command is executed successfully.
270 @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, but the entire DataBuffer could
271 not be transferred. The actual number of bytes transferred is returned in DataLength.
272 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
273 SCSI Command Packets already queued.
274 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
275 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
276 the SCSI initiator(i.e., SCSI Host Controller)
277 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
278 @retval EFI_INVALID_PARAMETER ScsiIo is NULL.
283 ScsiReadCapacityCommand (
284 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
287 IN OUT UINT8
*SenseDataLength
,
288 OUT UINT8
*HostAdapterStatus
,
289 OUT UINT8
*TargetStatus
,
290 OUT VOID
*DataBuffer
,
291 IN OUT UINT32
*DataLength
,
297 Function to submit read 10 command.
299 Submit SCSI read (10) command with the SCSI request packet specified by this SCSI command
300 and the input parameters, and then return the status of Scsi unit execution.
302 If SenseDataLength is NULL, then ASSERT().
304 If HostAdapterStatus is NULL, then ASSERT().
306 If TargetStatus is NULL, then ASSERT().
308 If DataLength is NULL, then ASSERT().
310 @param[in] ScsiIo A pointer to SCSI IO protocol.
311 @param[in] Timeout The length of timeout period.
312 @param[in] SenseData A pointer to output sense data.
313 @param[in, out] SenseDataLength The length of output sense data.
314 @param[out] HostAdapterStatus The status of Host Adapter.
315 @param[out] TargetStatus The status of the target.
316 @param[out] DataBuffer Read 10 command data.
317 @param[in, out] DataLength The length of data buffer.
318 @param[in] StartLba The start address of LBA.
319 @param[in] SectorSize The sector size.
321 @retval EFI_SUCCESS Command is executed successfully.
322 @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, but the entire DataBuffer could
323 not be transferred. The actual number of bytes transferred is returned in DataLength.
324 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
325 SCSI Command Packets already queued.
326 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
327 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
328 the SCSI initiator(i.e., SCSI Host Controller)
329 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
330 @retval EFI_INVALID_PARAMETER ScsiIo is NULL.
336 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
339 IN OUT UINT8
*SenseDataLength
,
340 OUT UINT8
*HostAdapterStatus
,
341 OUT UINT8
*TargetStatus
,
342 OUT VOID
*DataBuffer
,
343 IN OUT UINT32
*DataLength
,
350 Function to submit SCSI write 10 command.
352 Submit SCSI write (10) command with the SCSI request packet specified by this SCSI command and the
353 input parameters, and then return the status of Scsi unit execution.
355 If SenseDataLength is NULL, then ASSERT().
357 If HostAdapterStatus is NULL, then ASSERT().
359 If TargetStatus is NULL, then ASSERT().
361 If DataLength is NULL, then ASSERT().
363 @param[in] ScsiIo SCSI IO Protocol to use
364 @param[in] Timeout The length of timeout period.
365 @param[in] SenseData A pointer to output sense data.
366 @param[in, out] SenseDataLength The length of output sense data.
367 @param[out] HostAdapterStatus The status of Host Adapter.
368 @param[out] TargetStatus The status of the target.
369 @param[out] DataBuffer A pointer to a data buffer.
370 @param[in, out] DataLength The length of data buffer.
371 @param[in] StartLba The start address of LBA.
372 @param[in] SectorSize The sector size.
374 @retval EFI_SUCCESS Command is executed successfully.
375 @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, but the entire DataBuffer could
376 not be transferred. The actual number of bytes transferred is returned in DataLength.
377 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
378 SCSI Command Packets already queued.
379 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
380 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
381 the SCSI initiator(i.e., SCSI Host Controller)
382 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
383 @retval EFI_INVALID_PARAMETER ScsiIo is NULL.
389 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
392 IN OUT UINT8
*SenseDataLength
,
393 OUT UINT8
*HostAdapterStatus
,
394 OUT UINT8
*TargetStatus
,
395 OUT VOID
*DataBuffer
,
396 IN OUT UINT32
*DataLength
,