2 UEFI SCSI Library implementation
4 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
5 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.
17 #include <Library/BaseLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/UefiScsiLib.h>
20 #include <Library/BaseMemoryLib.h>
22 #include <IndustryStandard/Scsi.h>
26 // Max bytes needed to represent ID of a SCSI device
28 #define EFI_SCSI_TARGET_MAX_BYTES (0x10)
31 // bit5..7 are for Logical unit number
34 #define EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK 0xe0
37 // Scsi Command Length six or ten
39 #define EFI_SCSI_OP_LENGTH_SIX 0x6
40 #define EFI_SCSI_OP_LENGTH_TEN 0xa
45 Execute Test Unit Ready SCSI command on a specific SCSI target.
47 Executes the Test Unit Ready command on the SCSI target specified by ScsiIo.
48 If Timeout is zero, then this function waits indefinitely for the command to complete.
49 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
50 If ScsiIo is NULL, then ASSERT().
51 If SenseDataLength is NULL, then ASSERT().
52 If HostAdapterStatus is NULL, then ASSERT().
53 If TargetStatus is NULL, then ASSERT().
56 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
57 for the specific SCSI target.
58 @param[in] Timeout The timeout in 100 ns units to use for the execution
59 of this SCSI Request Packet. A Timeout value of
60 zero means that this function will wait indefinitely
61 for the SCSI Request Packet to execute. If Timeout
62 is greater than zero, then this function will return
63 EFI_TIMEOUT if the time required to execute the SCSI
64 Request Packet is greater than Timeout.
65 @param[in, out] SenseData A pointer to sense data that was generated by
66 the execution of the SCSI Request Packet. This
67 buffer must be allocated by the caller.
68 If SenseDataLength is 0, then this parameter is
69 optional and may be NULL.
70 @param[in, out] SenseDataLength On input, a pointer to the length in bytes of
71 the SenseData buffer. On output, a pointer to
72 the number of bytes written to the SenseData buffer.
73 @param[out] HostAdapterStatus The status of the SCSI Host Controller that produces
74 the SCSI bus containing the SCSI target specified by
75 ScsiIo when the SCSI Request Packet was executed.
76 See the EFI SCSI I/O Protocol in the UEFI Specification
77 for details on the possible return values.
78 @param[out] TargetStatus The status returned by the SCSI target specified
79 by ScsiIo when the SCSI Request Packet was executed
80 on the SCSI Host Controller. See the EFI SCSI I/O
81 Protocol in the UEFI Specification for details on
82 the possible return values.
84 @retval EFI_SUCCESS The command was executed successfully.
85 See HostAdapterStatus, TargetStatus, SenseDataLength,
86 and SenseData in that order for additional status
88 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
89 there are too many SCSI Command Packets already
90 queued. The SCSI Request Packet was not sent, so
91 no additional status information is available.
92 The caller may retry again later.
93 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
94 SCSI Request Packet. See HostAdapterStatus,
95 TargetStatus, SenseDataLength, and SenseData in that
96 order for additional status information.
97 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
98 is not supported by the SCSI initiator(i.e., SCSI
99 Host Controller). The SCSI Request Packet was not
100 sent, so no additional status information is available.
101 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request
102 Packet to execute. See HostAdapterStatus, TargetStatus,
103 SenseDataLength, and SenseData in that order for
104 additional status information.
109 ScsiTestUnitReadyCommand (
110 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
112 IN OUT VOID
*SenseData
, OPTIONAL
113 IN OUT UINT8
*SenseDataLength
,
114 OUT UINT8
*HostAdapterStatus
,
115 OUT UINT8
*TargetStatus
118 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
121 UINT8 TargetArray
[EFI_SCSI_TARGET_MAX_BYTES
];
123 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIX
];
125 ASSERT (SenseDataLength
!= NULL
);
126 ASSERT (HostAdapterStatus
!= NULL
);
127 ASSERT (TargetStatus
!= NULL
);
128 ASSERT (ScsiIo
!= NULL
);
130 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
131 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIX
);
133 CommandPacket
.Timeout
= Timeout
;
134 CommandPacket
.InDataBuffer
= NULL
;
135 CommandPacket
.InTransferLength
= 0;
136 CommandPacket
.OutDataBuffer
= NULL
;
137 CommandPacket
.OutTransferLength
= 0;
138 CommandPacket
.SenseData
= SenseData
;
139 CommandPacket
.Cdb
= Cdb
;
141 // Fill Cdb for Test Unit Ready Command
143 Target
= &TargetArray
[0];
144 ScsiIo
->GetDeviceLocation (ScsiIo
, &Target
, &Lun
);
146 Cdb
[0] = EFI_SCSI_OP_TEST_UNIT_READY
;
147 Cdb
[1] = (UINT8
) (LShiftU64 (Lun
, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK
);
148 CommandPacket
.CdbLength
= (UINT8
) EFI_SCSI_OP_LENGTH_SIX
;
149 CommandPacket
.SenseDataLength
= *SenseDataLength
;
151 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
153 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
154 *TargetStatus
= CommandPacket
.TargetStatus
;
155 *SenseDataLength
= CommandPacket
.SenseDataLength
;
162 Execute Inquiry SCSI command on a specific SCSI target.
164 Executes the Inquiry command on the SCSI target specified by ScsiIo.
165 If Timeout is zero, then this function waits indefinitely for the command to complete.
166 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
167 If ScsiIo is NULL, then ASSERT().
168 If SenseDataLength is NULL, then ASSERT().
169 If HostAdapterStatus is NULL, then ASSERT().
170 If TargetStatus is NULL, then ASSERT().
171 If InquiryDataLength is NULL, then ASSERT().
173 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
174 for the specific SCSI target.
175 @param[in] Timeout The timeout in 100 ns units to use for the
176 execution of this SCSI Request Packet. A Timeout
177 value of zero means that this function will wait
178 indefinitely for the SCSI Request Packet to execute.
179 If Timeout is greater than zero, then this function
180 will return EFI_TIMEOUT if the time required to
181 execute the SCSI Request Packet is greater than Timeout.
182 @param[in, out] SenseData A pointer to sense data that was generated
183 by the execution of the SCSI Request Packet.
184 This buffer must be allocated by the caller.
185 If SenseDataLength is 0, then this parameter
186 is optional and may be NULL.
187 @param[in, out] SenseDataLength On input, the length in bytes of the SenseData buffer.
188 On output, the number of bytes written to the SenseData buffer.
189 @param[out] HostAdapterStatus The status of the SCSI Host Controller that
190 produces the SCSI bus containing the SCSI
191 target specified by ScsiIo when the SCSI
192 Request Packet was executed. See the EFI
193 SCSI I/O Protocol in the UEFI Specification
194 for details on the possible return values.
195 @param[out] TargetStatus The status returned by the SCSI target specified
196 by ScsiIo when the SCSI Request Packet was
197 executed on the SCSI Host Controller.
198 See the EFI SCSI I/O Protocol in the UEFI
199 Specification for details on the possible
201 @param[in, out] InquiryDataBuffer A pointer to inquiry data that was generated
202 by the execution of the SCSI Request Packet.
203 This buffer must be allocated by the caller.
204 If InquiryDataLength is 0, then this parameter
205 is optional and may be NULL.
206 @param[in, out] InquiryDataLength On input, a pointer to the length in bytes
207 of the InquiryDataBuffer buffer.
208 On output, a pointer to the number of bytes
209 written to the InquiryDataBuffer buffer.
210 @param[in] EnableVitalProductData If TRUE, then the supported vital product
211 data is returned in InquiryDataBuffer.
212 If FALSE, then the standard inquiry data is
213 returned in InquiryDataBuffer.
215 @retval EFI_SUCCESS The command was executed successfully. See HostAdapterStatus,
216 TargetStatus, SenseDataLength, and SenseData in that order
217 for additional status information.
218 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire
219 InquiryDataBuffer could not be transferred. The actual
220 number of bytes transferred is returned in InquiryDataLength.
221 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there
222 are too many SCSI Command Packets already queued.
223 The SCSI Request Packet was not sent, so no additional
224 status information is available. The caller may retry again later.
225 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI
226 Request Packet. See HostAdapterStatus, TargetStatus,
227 SenseDataLength, and SenseData in that order for additional
229 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not
230 supported by the SCSI initiator(i.e., SCSI Host Controller).
231 The SCSI Request Packet was not sent, so no additional
232 status information is available.
233 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request
234 Packet to execute. See HostAdapterStatus, TargetStatus,
235 SenseDataLength, and SenseData in that order for
236 additional status information.
242 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
244 IN OUT VOID
*SenseData
, OPTIONAL
245 IN OUT UINT8
*SenseDataLength
,
246 OUT UINT8
*HostAdapterStatus
,
247 OUT UINT8
*TargetStatus
,
248 IN OUT VOID
*InquiryDataBuffer
, OPTIONAL
249 IN OUT UINT32
*InquiryDataLength
,
250 IN BOOLEAN EnableVitalProductData
253 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
256 UINT8 TargetArray
[EFI_SCSI_TARGET_MAX_BYTES
];
258 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIX
];
260 ASSERT (SenseDataLength
!= NULL
);
261 ASSERT (HostAdapterStatus
!= NULL
);
262 ASSERT (TargetStatus
!= NULL
);
263 ASSERT (InquiryDataLength
!= NULL
);
264 ASSERT (ScsiIo
!= NULL
);
266 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
267 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIX
);
269 CommandPacket
.Timeout
= Timeout
;
270 CommandPacket
.InDataBuffer
= InquiryDataBuffer
;
271 CommandPacket
.InTransferLength
= *InquiryDataLength
;
272 CommandPacket
.SenseData
= SenseData
;
273 CommandPacket
.SenseDataLength
= *SenseDataLength
;
274 CommandPacket
.Cdb
= Cdb
;
276 Target
= &TargetArray
[0];
277 ScsiIo
->GetDeviceLocation (ScsiIo
, &Target
, &Lun
);
279 Cdb
[0] = EFI_SCSI_OP_INQUIRY
;
280 Cdb
[1] = (UINT8
) (LShiftU64 (Lun
, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK
);
281 if (EnableVitalProductData
) {
285 if (*InquiryDataLength
> 0xff) {
286 *InquiryDataLength
= 0xff;
289 Cdb
[4] = (UINT8
) (*InquiryDataLength
);
290 CommandPacket
.CdbLength
= (UINT8
) EFI_SCSI_OP_LENGTH_SIX
;
291 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
293 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
295 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
296 *TargetStatus
= CommandPacket
.TargetStatus
;
297 *SenseDataLength
= CommandPacket
.SenseDataLength
;
298 *InquiryDataLength
= CommandPacket
.InTransferLength
;
305 Execute Mode Sense(10) SCSI command on a specific SCSI target.
307 Executes the SCSI Mode Sense(10) command on the SCSI target specified by ScsiIo.
308 If Timeout is zero, then this function waits indefinitely for the command to complete.
309 If Timeout is greater than zero, then the command is executed and will timeout
310 after Timeout 100 ns units. The DBDField, PageControl, and PageCode parameters
311 are used to construct the CDB for this SCSI command.
312 If ScsiIo is NULL, then ASSERT().
313 If SenseDataLength is NULL, then ASSERT().
314 If HostAdapterStatus is NULL, then ASSERT().
315 If TargetStatus is NULL, then ASSERT().
316 If DataLength is NULL, then ASSERT().
319 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
320 for the specific SCSI target.
321 @param[in] Timeout The timeout in 100 ns units to use for the
322 execution of this SCSI Request Packet. A Timeout
323 value of zero means that this function will wait
324 indefinitely for the SCSI Request Packet to execute.
325 If Timeout is greater than zero, then this function
326 will return EFI_TIMEOUT if the time required to
327 execute the SCSI Request Packet is greater than Timeout.
328 @param[in, out] SenseData A pointer to sense data that was generated
329 by the execution of the SCSI Request Packet.
330 This buffer must be allocated by the caller.
331 If SenseDataLength is 0, then this parameter
332 is optional and may be NULL.
333 @param[in, out] SenseDataLength On input, the length in bytes of the SenseData buffer.
334 On output, the number of bytes written to the SenseData buffer.
335 @param[out] HostAdapterStatus The status of the SCSI Host Controller that
336 produces the SCSI bus containing the SCSI target
337 specified by ScsiIo when the SCSI Request Packet
338 was executed. See the EFI SCSI I/O Protocol in the
339 UEFI Specification for details on the possible
341 @param[out] TargetStatus The status returned by the SCSI target specified
342 by ScsiIo when the SCSI Request Packet was executed
343 on the SCSI Host Controller. See the EFI SCSI
344 I/O Protocol in the UEFI Specification for details
345 on the possible return values.
346 @param[in, out] DataBuffer A pointer to data that was generated by the
347 execution of the SCSI Request Packet. This
348 buffer must be allocated by the caller. If
349 DataLength is 0, then this parameter is optional
351 @param[in, out] DataLength On input, a pointer to the length in bytes of
352 the DataBuffer buffer. On output, a pointer
353 to the number of bytes written to the DataBuffer
355 @param[in] DBDField Specifies the DBD field of the CDB for this SCSI Command.
356 @param[in] PageControl Specifies the PC field of the CDB for this SCSI Command.
357 @param[in] PageCode Specifies the Page Control field of the CDB for this SCSI Command.
359 @retval EFI_SUCCESS The command was executed successfully.
360 See HostAdapterStatus, TargetStatus, SenseDataLength,
361 and SenseData in that order for additional status information.
362 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the
363 entire DataBuffer could not be transferred.
364 The actual number of bytes transferred is returned
366 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
367 there are too many SCSI Command Packets already queued.
368 The SCSI Request Packet was not sent, so no additional
369 status information is available. The caller may retry
371 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
372 SCSI Request Packet. See HostAdapterStatus, TargetStatus,
373 SenseDataLength, and SenseData in that order for
374 additional status information.
375 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
376 is not supported by the SCSI initiator(i.e., SCSI
377 Host Controller). The SCSI Request Packet was not
378 sent, so no additional status information is available.
379 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
380 Request Packet to execute. See HostAdapterStatus,
381 TargetStatus, SenseDataLength, and SenseData in that
382 order for additional status information.
387 ScsiModeSense10Command (
388 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
390 IN OUT VOID
*SenseData
, OPTIONAL
391 IN OUT UINT8
*SenseDataLength
,
392 OUT UINT8
*HostAdapterStatus
,
393 OUT UINT8
*TargetStatus
,
394 IN OUT VOID
*DataBuffer
, OPTIONAL
395 IN OUT UINT32
*DataLength
,
396 IN UINT8 DBDField
, OPTIONAL
397 IN UINT8 PageControl
,
401 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
404 UINT8 TargetArray
[EFI_SCSI_TARGET_MAX_BYTES
];
406 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TEN
];
408 ASSERT (SenseDataLength
!= NULL
);
409 ASSERT (HostAdapterStatus
!= NULL
);
410 ASSERT (TargetStatus
!= NULL
);
411 ASSERT (DataLength
!= NULL
);
412 ASSERT (ScsiIo
!= NULL
);
414 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
415 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TEN
);
417 CommandPacket
.Timeout
= Timeout
;
418 CommandPacket
.InDataBuffer
= DataBuffer
;
419 CommandPacket
.SenseData
= SenseData
;
420 CommandPacket
.InTransferLength
= *DataLength
;
421 CommandPacket
.Cdb
= Cdb
;
423 // Fill Cdb for Mode Sense (10) Command
425 Target
= &TargetArray
[0];
426 ScsiIo
->GetDeviceLocation (ScsiIo
, &Target
, &Lun
);
428 Cdb
[0] = EFI_SCSI_OP_MODE_SEN10
;
430 // DBDField is in Cdb[1] bit3 of (bit7..0)
432 Cdb
[1] = (UINT8
) ((LShiftU64 (Lun
, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK
) + ((DBDField
<< 3) & 0x08));
434 // PageControl is in Cdb[2] bit7..6, PageCode is in Cdb[2] bit5..0
436 Cdb
[2] = (UINT8
) (((PageControl
<< 6) & 0xc0) | (PageCode
& 0x3f));
437 Cdb
[7] = (UINT8
) (*DataLength
>> 8);
438 Cdb
[8] = (UINT8
) (*DataLength
);
440 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
441 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
442 CommandPacket
.SenseDataLength
= *SenseDataLength
;
444 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
446 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
447 *TargetStatus
= CommandPacket
.TargetStatus
;
448 *SenseDataLength
= CommandPacket
.SenseDataLength
;
449 *DataLength
= CommandPacket
.InTransferLength
;
456 Execute Request Sense SCSI command on a specific SCSI target.
458 Executes the Request Sense command on the SCSI target specified by ScsiIo.
459 If Timeout is zero, then this function waits indefinitely for the command to complete.
460 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
461 If ScsiIo is NULL, then ASSERT().
462 If SenseDataLength is NULL, then ASSERT().
463 If HostAdapterStatus is NULL, then ASSERT().
464 If TargetStatus is NULL, then ASSERT().
466 @param[in] ScsiIo A pointer to SCSI IO protocol.
467 @param[in] Timeout The length of timeout period.
468 @param[in, out] SenseData A pointer to output sense data.
469 @param[in, out] SenseDataLength The length of output sense data.
470 @param[out] HostAdapterStatus The status of Host Adapter.
471 @param[out] TargetStatus The status of the target.
473 @retval EFI_SUCCESS Command is executed successfully.
474 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are
475 too many SCSI Command Packets already queued.
476 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
477 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
478 the SCSI initiator(i.e., SCSI Host Controller)
479 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
484 ScsiRequestSenseCommand (
485 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
487 IN OUT VOID
*SenseData
, OPTIONAL
488 IN OUT UINT8
*SenseDataLength
,
489 OUT UINT8
*HostAdapterStatus
,
490 OUT UINT8
*TargetStatus
493 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
496 UINT8 TargetArray
[EFI_SCSI_TARGET_MAX_BYTES
];
498 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIX
];
500 ASSERT (SenseDataLength
!= NULL
);
501 ASSERT (HostAdapterStatus
!= NULL
);
502 ASSERT (TargetStatus
!= NULL
);
503 ASSERT (ScsiIo
!= NULL
);
505 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
506 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIX
);
508 CommandPacket
.Timeout
= Timeout
;
509 CommandPacket
.InDataBuffer
= SenseData
;
510 CommandPacket
.SenseData
= NULL
;
511 CommandPacket
.InTransferLength
= *SenseDataLength
;
512 CommandPacket
.Cdb
= Cdb
;
514 // Fill Cdb for Request Sense Command
516 Target
= &TargetArray
[0];
517 ScsiIo
->GetDeviceLocation (ScsiIo
, &Target
, &Lun
);
519 Cdb
[0] = EFI_SCSI_OP_REQUEST_SENSE
;
520 Cdb
[1] = (UINT8
) (LShiftU64 (Lun
, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK
);
521 Cdb
[4] = (UINT8
) (*SenseDataLength
);
523 CommandPacket
.CdbLength
= (UINT8
) EFI_SCSI_OP_LENGTH_SIX
;
524 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
525 CommandPacket
.SenseDataLength
= 0;
527 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
529 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
530 *TargetStatus
= CommandPacket
.TargetStatus
;
531 *SenseDataLength
= (UINT8
) CommandPacket
.InTransferLength
;
538 Execute Read Capacity SCSI command on a specific SCSI target.
540 Executes the SCSI Read Capacity command on the SCSI target specified by ScsiIo.
541 If Timeout is zero, then this function waits indefinitely for the command to complete.
542 If Timeout is greater than zero, then the command is executed and will timeout after
543 Timeout 100 ns units. The Pmi parameter is used to construct the CDB for this SCSI command.
544 If ScsiIo is NULL, then ASSERT().
545 If SenseDataLength is NULL, then ASSERT().
546 If HostAdapterStatus is NULL, then ASSERT().
547 If TargetStatus is NULL, then ASSERT().
548 If DataLength is NULL, then ASSERT().
550 @param[in] ScsiIo A pointer to SCSI IO protocol.
551 @param[in] Timeout The length of timeout period.
552 @param[in, out] SenseData A pointer to output sense data.
553 @param[in, out] SenseDataLength The length of output sense data.
554 @param[out] HostAdapterStatus The status of Host Adapter.
555 @param[out] TargetStatus The status of the target.
556 @param[in, out] DataBuffer A pointer to a data buffer.
557 @param[in, out] DataLength The length of data buffer.
558 @param[in] Pmi Partial medium indicator.
560 @retval EFI_SUCCESS Command is executed successfully.
561 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire
562 DataBuffer could not be transferred. The actual
563 number of bytes transferred is returned in DataLength.
564 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
565 there are too many SCSI Command Packets already queued.
566 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
567 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
568 is not supported by the SCSI initiator(i.e., SCSI Host Controller)
569 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
574 ScsiReadCapacityCommand (
575 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
577 IN OUT VOID
*SenseData
, OPTIONAL
578 IN OUT UINT8
*SenseDataLength
,
579 OUT UINT8
*HostAdapterStatus
,
580 OUT UINT8
*TargetStatus
,
581 IN OUT VOID
*DataBuffer
, OPTIONAL
582 IN OUT UINT32
*DataLength
,
586 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
589 UINT8 TargetArray
[EFI_SCSI_TARGET_MAX_BYTES
];
591 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TEN
];
593 ASSERT (SenseDataLength
!= NULL
);
594 ASSERT (HostAdapterStatus
!= NULL
);
595 ASSERT (TargetStatus
!= NULL
);
596 ASSERT (DataLength
!= NULL
);
597 ASSERT (ScsiIo
!= NULL
);
599 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
600 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TEN
);
602 CommandPacket
.Timeout
= Timeout
;
603 CommandPacket
.InDataBuffer
= DataBuffer
;
604 CommandPacket
.SenseData
= SenseData
;
605 CommandPacket
.InTransferLength
= *DataLength
;
606 CommandPacket
.Cdb
= Cdb
;
608 // Fill Cdb for Read Capacity Command
610 Target
= &TargetArray
[0];
611 ScsiIo
->GetDeviceLocation (ScsiIo
, &Target
, &Lun
);
613 Cdb
[0] = EFI_SCSI_OP_READ_CAPACITY
;
614 Cdb
[1] = (UINT8
) (LShiftU64 (Lun
, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK
);
617 // Partial medium indicator,if Pmi is FALSE, the Cdb.2 ~ Cdb.5 MUST BE ZERO.
619 ZeroMem ((Cdb
+ 2), 4);
624 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
625 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
626 CommandPacket
.SenseDataLength
= *SenseDataLength
;
628 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
630 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
631 *TargetStatus
= CommandPacket
.TargetStatus
;
632 *SenseDataLength
= CommandPacket
.SenseDataLength
;
633 *DataLength
= CommandPacket
.InTransferLength
;
640 Execute Read Capacity SCSI 16 command on a specific SCSI target.
642 Executes the SCSI Read Capacity 16 command on the SCSI target specified by ScsiIo.
643 If Timeout is zero, then this function waits indefinitely for the command to complete.
644 If Timeout is greater than zero, then the command is executed and will timeout after
645 Timeout 100 ns units. The Pmi parameter is used to construct the CDB for this SCSI command.
646 If ScsiIo is NULL, then ASSERT().
647 If SenseDataLength is NULL, then ASSERT().
648 If HostAdapterStatus is NULL, then ASSERT().
649 If TargetStatus is NULL, then ASSERT().
650 If DataLength is NULL, then ASSERT().
652 @param[in] ScsiIo A pointer to SCSI IO protocol.
653 @param[in] Timeout The length of timeout period.
654 @param[in, out] SenseData A pointer to output sense data.
655 @param[in, out] SenseDataLength The length of output sense data.
656 @param[out] HostAdapterStatus The status of Host Adapter.
657 @param[out] TargetStatus The status of the target.
658 @param[in, out] DataBuffer A pointer to a data buffer.
659 @param[in, out] DataLength The length of data buffer.
660 @param[in] Pmi Partial medium indicator.
662 @retval EFI_SUCCESS Command is executed successfully.
663 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire
664 DataBuffer could not be transferred. The actual
665 number of bytes transferred is returned in DataLength.
666 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
667 there are too many SCSI Command Packets already queued.
668 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
669 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
670 is not supported by the SCSI initiator(i.e., SCSI Host Controller)
671 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
676 ScsiReadCapacity16Command (
677 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
679 IN OUT VOID
*SenseData
, OPTIONAL
680 IN OUT UINT8
*SenseDataLength
,
681 OUT UINT8
*HostAdapterStatus
,
682 OUT UINT8
*TargetStatus
,
683 IN OUT VOID
*DataBuffer
, OPTIONAL
684 IN OUT UINT32
*DataLength
,
688 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
691 UINT8 TargetArray
[EFI_SCSI_TARGET_MAX_BYTES
];
695 ASSERT (SenseDataLength
!= NULL
);
696 ASSERT (HostAdapterStatus
!= NULL
);
697 ASSERT (TargetStatus
!= NULL
);
698 ASSERT (DataLength
!= NULL
);
699 ASSERT (ScsiIo
!= NULL
);
701 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
704 CommandPacket
.Timeout
= Timeout
;
705 CommandPacket
.InDataBuffer
= DataBuffer
;
706 CommandPacket
.SenseData
= SenseData
;
707 CommandPacket
.InTransferLength
= *DataLength
;
708 CommandPacket
.Cdb
= Cdb
;
710 // Fill Cdb for Read Capacity Command
712 Target
= &TargetArray
[0];
713 ScsiIo
->GetDeviceLocation (ScsiIo
, &Target
, &Lun
);
715 Cdb
[0] = EFI_SCSI_OP_READ_CAPACITY16
;
719 // Partial medium indicator,if Pmi is FALSE, the Cdb.2 ~ Cdb.9 MUST BE ZERO.
721 ZeroMem ((Cdb
+ 2), 8);
727 CommandPacket
.CdbLength
= 16;
728 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
729 CommandPacket
.SenseDataLength
= *SenseDataLength
;
731 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
733 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
734 *TargetStatus
= CommandPacket
.TargetStatus
;
735 *SenseDataLength
= CommandPacket
.SenseDataLength
;
736 *DataLength
= CommandPacket
.InTransferLength
;
743 Execute Read(10) SCSI command on a specific SCSI target.
745 Executes the SCSI Read(10) command on the SCSI target specified by ScsiIo.
746 If Timeout is zero, then this function waits indefinitely for the command to complete.
747 If Timeout is greater than zero, then the command is executed and will timeout
748 after Timeout 100 ns units. The StartLba and SectorSize parameters are used to
749 construct the CDB for this SCSI command.
750 If ScsiIo is NULL, then ASSERT().
751 If SenseDataLength is NULL, then ASSERT().
752 If HostAdapterStatus is NULL, then ASSERT().
753 If TargetStatus is NULL, then ASSERT().
754 If DataLength is NULL, then ASSERT().
757 @param[in] ScsiIo A pointer to SCSI IO protocol.
758 @param[in] Timeout The length of timeout period.
759 @param[in, out] SenseData A pointer to output sense data.
760 @param[in, out] SenseDataLength The length of output sense data.
761 @param[out] HostAdapterStatus The status of Host Adapter.
762 @param[out] TargetStatus The status of the target.
763 @param[in, out] DataBuffer Read 10 command data.
764 @param[in, out] DataLength The length of data buffer.
765 @param[in] StartLba The start address of LBA.
766 @param[in] SectorSize The sector size.
768 @retval EFI_SUCCESS Command is executed successfully.
769 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could
770 not be transferred. The actual number of bytes transferred is returned in DataLength.
771 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
772 SCSI Command Packets already queued.
773 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
774 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
775 the SCSI initiator(i.e., SCSI Host Controller)
776 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
782 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
784 IN OUT VOID
*SenseData
, OPTIONAL
785 IN OUT UINT8
*SenseDataLength
,
786 OUT UINT8
*HostAdapterStatus
,
787 OUT UINT8
*TargetStatus
,
788 IN OUT VOID
*DataBuffer
, OPTIONAL
789 IN OUT UINT32
*DataLength
,
794 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
797 UINT8 TargetArray
[EFI_SCSI_TARGET_MAX_BYTES
];
799 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TEN
];
801 ASSERT (SenseDataLength
!= NULL
);
802 ASSERT (HostAdapterStatus
!= NULL
);
803 ASSERT (TargetStatus
!= NULL
);
804 ASSERT (DataLength
!= NULL
);
805 ASSERT (ScsiIo
!= NULL
);
807 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
808 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TEN
);
810 CommandPacket
.Timeout
= Timeout
;
811 CommandPacket
.InDataBuffer
= DataBuffer
;
812 CommandPacket
.SenseData
= SenseData
;
813 CommandPacket
.InTransferLength
= *DataLength
;
814 CommandPacket
.Cdb
= Cdb
;
816 // Fill Cdb for Read (10) Command
818 Target
= &TargetArray
[0];
819 ScsiIo
->GetDeviceLocation (ScsiIo
, &Target
, &Lun
);
821 Cdb
[0] = EFI_SCSI_OP_READ10
;
822 Cdb
[1] = (UINT8
) (LShiftU64 (Lun
, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK
);
823 Cdb
[2] = (UINT8
) (StartLba
>> 24);
824 Cdb
[3] = (UINT8
) (StartLba
>> 16);
825 Cdb
[4] = (UINT8
) (StartLba
>> 8);
826 Cdb
[5] = (UINT8
) (StartLba
& 0xff);
827 Cdb
[7] = (UINT8
) (SectorSize
>> 8);
828 Cdb
[8] = (UINT8
) (SectorSize
& 0xff);
830 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
831 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
832 CommandPacket
.SenseDataLength
= *SenseDataLength
;
834 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
836 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
837 *TargetStatus
= CommandPacket
.TargetStatus
;
838 *SenseDataLength
= CommandPacket
.SenseDataLength
;
839 *DataLength
= CommandPacket
.InTransferLength
;
846 Execute Write(10) SCSI command on a specific SCSI target.
848 Executes the SCSI Write(10) command on the SCSI target specified by ScsiIo.
849 If Timeout is zero, then this function waits indefinitely for the command to complete.
850 If Timeout is greater than zero, then the command is executed and will timeout after
851 Timeout 100 ns units. The StartLba and SectorSize parameters are used to construct
852 the CDB for this SCSI command.
853 If ScsiIo is NULL, then ASSERT().
854 If SenseDataLength is NULL, then ASSERT().
855 If HostAdapterStatus is NULL, then ASSERT().
856 If TargetStatus is NULL, then ASSERT().
857 If DataLength is NULL, then ASSERT().
859 @param[in] ScsiIo SCSI IO Protocol to use
860 @param[in] Timeout The length of timeout period.
861 @param[in, out] SenseData A pointer to output sense data.
862 @param[in, out] SenseDataLength The length of output sense data.
863 @param[out] HostAdapterStatus The status of Host Adapter.
864 @param[out] TargetStatus The status of the target.
865 @param[in, out] DataBuffer A pointer to a data buffer.
866 @param[in, out] DataLength The length of data buffer.
867 @param[in] StartLba The start address of LBA.
868 @param[in] SectorSize The sector size.
870 @retval EFI_SUCCESS Command is executed successfully.
871 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could
872 not be transferred. The actual number of bytes transferred is returned in DataLength.
873 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
874 SCSI Command Packets already queued.
875 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
876 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
877 the SCSI initiator(i.e., SCSI Host Controller)
878 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
884 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
886 IN OUT VOID
*SenseData
, OPTIONAL
887 IN OUT UINT8
*SenseDataLength
,
888 OUT UINT8
*HostAdapterStatus
,
889 OUT UINT8
*TargetStatus
,
890 IN OUT VOID
*DataBuffer
, OPTIONAL
891 IN OUT UINT32
*DataLength
,
896 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
899 UINT8 TargetArray
[EFI_SCSI_TARGET_MAX_BYTES
];
901 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TEN
];
903 ASSERT (SenseDataLength
!= NULL
);
904 ASSERT (HostAdapterStatus
!= NULL
);
905 ASSERT (TargetStatus
!= NULL
);
906 ASSERT (DataLength
!= NULL
);
907 ASSERT (ScsiIo
!= NULL
);
909 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
910 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TEN
);
912 CommandPacket
.Timeout
= Timeout
;
913 CommandPacket
.OutDataBuffer
= DataBuffer
;
914 CommandPacket
.SenseData
= SenseData
;
915 CommandPacket
.OutTransferLength
= *DataLength
;
916 CommandPacket
.Cdb
= Cdb
;
918 // Fill Cdb for Write (10) Command
920 Target
= &TargetArray
[0];
921 ScsiIo
->GetDeviceLocation (ScsiIo
, &Target
, &Lun
);
923 Cdb
[0] = EFI_SCSI_OP_WRITE10
;
924 Cdb
[1] = (UINT8
) (LShiftU64 (Lun
, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK
);
925 Cdb
[2] = (UINT8
) (StartLba
>> 24);
926 Cdb
[3] = (UINT8
) (StartLba
>> 16);
927 Cdb
[4] = (UINT8
) (StartLba
>> 8);
928 Cdb
[5] = (UINT8
) StartLba
;
929 Cdb
[7] = (UINT8
) (SectorSize
>> 8);
930 Cdb
[8] = (UINT8
) SectorSize
;
932 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
933 CommandPacket
.DataDirection
= EFI_SCSI_DATA_OUT
;
934 CommandPacket
.SenseDataLength
= *SenseDataLength
;
936 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
938 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
939 *TargetStatus
= CommandPacket
.TargetStatus
;
940 *SenseDataLength
= CommandPacket
.SenseDataLength
;
941 *DataLength
= CommandPacket
.OutTransferLength
;