2 UEFI SCSI Library implementation
4 Copyright (c) 2006 - 2008, Intel Corporation.<BR>
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.
17 #include <Library/DebugLib.h>
18 #include <Library/UefiScsiLib.h>
19 #include <Library/BaseMemoryLib.h>
21 #include <IndustryStandard/Scsi.h>
25 // Max bytes needed to represent ID of a SCSI device
27 #define EFI_SCSI_TARGET_MAX_BYTES (0x10)
30 // bit5..7 are for Logical unit number
33 #define EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK 0xe0
36 // Scsi Command Length six or ten
38 #define EFI_SCSI_OP_LENGTH_SIX 0x6
39 #define EFI_SCSI_OP_LENGTH_TEN 0xa
44 Execute Test Unit Ready SCSI command on a specific SCSI target.
46 Executes the Test Unit Ready command on the SCSI target specified by ScsiIo.
47 If Timeout is zero, then this function waits indefinitely for the command to complete.
48 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
49 If ScsiIo is NULL, then ASSERT().
50 If SenseDataLength is NULL, then ASSERT().
51 If HostAdapterStatus is NULL, then ASSERT().
52 If TargetStatus is NULL, then ASSERT().
55 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
56 for the specific SCSI target.
57 @param[in] Timeout The timeout in 100 ns units to use for the execution
58 of this SCSI Request Packet. A Timeout value of
59 zero means that this function will wait indefinitely
60 for the SCSI Request Packet to execute. If Timeout
61 is greater than zero, then this function will return
62 EFI_TIMEOUT if the time required to execute the SCSI
63 Request Packet is greater than Timeout.
64 @param[in, out] SenseData A pointer to sense data that was generated by
65 the execution of the SCSI Request Packet. This
66 buffer must be allocated by the caller.
67 If SenseDataLength is 0, then this parameter is
68 optional and may be NULL.
69 @param[in, out] SenseDataLength On input, a pointer to the length in bytes of
70 the SenseData buffer. On output, a poiinter to
71 the number of bytes written to the SenseData buffer.
72 @param[out] HostAdapterStatus The status of the SCSI Host Controller that produces
73 the SCSI bus containing the SCSI target specified by
74 ScsiIo when the SCSI Request Packet was executed.
75 See the EFI SCSI I/O Protocol in the UEFI Specification
76 for details on the possible return values.
77 @param[out] TargetStatus The status returned by the SCSI target specified
78 by ScsiIo when the SCSI Request Packat was executed
79 on the SCSI Host Controller. See the EFI SCSI I/O
80 Protocol in the UEFI Specification for details on
81 the possible return values.
83 @retval EFI_SUCCESS The command was executed successfully.
84 See HostAdapterStatus, TargetStatus, SenseDataLength,
85 and SenseData in that order for additional status
87 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
88 there are too many SCSI Command Packets already
89 queued. The SCSI Request Packet was not sent, so
90 no additional status information is available.
91 The caller may retry again later.
92 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
93 SCSI Request Packet. See HostAdapterStatus,
94 TargetStatus, SenseDataLength, and SenseData in that
95 order for additional status information.
96 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
97 is not supported by the SCSI initiator(i.e., SCSI
98 Host Controller). The SCSI Request Packet was not
99 sent, so no additional status information is available.
100 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request
101 Packet to execute. See HostAdapterStatus, TargetStatus,
102 SenseDataLength, and SenseData in that order for
103 additional status information.
104 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
105 but the entire DataBuffer could not be transferred.
106 The actual number of bytes transferred is returned
112 ScsiTestUnitReadyCommand (
113 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
115 IN OUT VOID
*SenseData
, OPTIONAL
116 IN OUT UINT8
*SenseDataLength
,
117 OUT UINT8
*HostAdapterStatus
,
118 OUT UINT8
*TargetStatus
121 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
124 UINT8 TargetArray
[EFI_SCSI_TARGET_MAX_BYTES
];
126 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIX
];
128 ASSERT (SenseDataLength
!= NULL
);
129 ASSERT (HostAdapterStatus
!= NULL
);
130 ASSERT (TargetStatus
!= NULL
);
131 ASSERT (ScsiIo
!= NULL
);
133 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
134 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIX
);
136 CommandPacket
.Timeout
= Timeout
;
137 CommandPacket
.InDataBuffer
= NULL
;
138 CommandPacket
.InTransferLength
= 0;
139 CommandPacket
.OutDataBuffer
= NULL
;
140 CommandPacket
.OutTransferLength
= 0;
141 CommandPacket
.SenseData
= SenseData
;
142 CommandPacket
.Cdb
= Cdb
;
144 // Fill Cdb for Test Unit Ready Command
146 Target
= &TargetArray
[0];
147 ScsiIo
->GetDeviceLocation (ScsiIo
, &Target
, &Lun
);
149 Cdb
[0] = EFI_SCSI_OP_TEST_UNIT_READY
;
150 Cdb
[1] = (UINT8
) (Lun
& EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK
);
151 CommandPacket
.CdbLength
= (UINT8
) EFI_SCSI_OP_LENGTH_SIX
;
152 CommandPacket
.SenseDataLength
= *SenseDataLength
;
154 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
156 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
157 *TargetStatus
= CommandPacket
.TargetStatus
;
158 *SenseDataLength
= CommandPacket
.SenseDataLength
;
165 Execute Inquiry SCSI command on a specific SCSI target.
167 Executes the Inquiry command on the SCSI target specified by ScsiIo.
168 If Timeout is zero, then this function waits indefinitely for the command to complete.
169 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
170 If ScsiIo is NULL, then ASSERT().
171 If SenseDataLength is NULL, then ASSERT().
172 If HostAdapterStatus is NULL, then ASSERT().
173 If TargetStatus is NULL, then ASSERT().
174 If InquiryDataLength is NULL, then ASSERT().
176 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
177 for the specific SCSI target.
178 @param[in] Timeout The timeout in 100 ns units to use for the
179 execution of this SCSI Request Packet. A Timeout
180 value of zero means that this function will wait
181 indefinitely for the SCSI Request Packet to execute.
182 If Timeout is greater than zero, then this function
183 will return EFI_TIMEOUT if the time required to
184 execute the SCSI Request Packet is greater than Timeout.
185 @param[in, out] SenseData A pointer to sense data that was generated
186 by the execution of the SCSI Request Packet.
187 This buffer must be allocated by the caller.
188 If SenseDataLength is 0, then this parameter
189 is optional and may be NULL.
190 @param[in, out] SenseDataLength On input, the length in bytes of the SenseData buffer.
191 On output, the number of bytes written to the SenseData buffer.
192 @param[out] HostAdapterStatus The status of the SCSI Host Controller that
193 produces the SCSI bus containing the SCSI
194 target specified by ScsiIo when the SCSI
195 Request Packet was executed. See the EFI
196 SCSI I/O Protocol in the UEFI Specification
197 for details on the possible return values.
198 @param[out] TargetStatus The status returned by the SCSI target specified
199 by ScsiIo when the SCSI Request Packat was
200 executed on the SCSI Host Controller.
201 See the EFI SCSI I/O Protocol in the UEFI
202 Specification for details on the possible
204 @param[in, out] InquiryDataBuffer A pointer to inquiry data that was generated
205 by the execution of the SCSI Request Packet.
206 This buffer must be allocated by the caller.
207 If InquiryDataLength is 0, then this parameter
208 is optional and may be NULL.
209 @param[in, out] InquiryDataLength On input, a pointer to the length in bytes
210 of the InquiryDataBuffer buffer.
211 On output, a pointer to the number of bytes
212 written to the InquiryDataBuffer buffer.
213 @param[in] EnableVitalProductData If TRUE, then the supported vital product
214 data is returned in InquiryDataBuffer.
215 If FALSE, then the standard inquiry data is
216 returned in InquiryDataBuffer.
218 @retval EFI_SUCCESS The command was executed successfully. See HostAdapterStatus,
219 TargetStatus, SenseDataLength, and SenseData in that order
220 for additional status information.
221 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire
222 InquiryDataBuffer could not be transferred. The actual
223 number of bytes transferred is returned in InquiryDataLength.
224 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there
225 are too many SCSI Command Packets already queued.
226 The SCSI Request Packet was not sent, so no additional
227 status information is available. The caller may retry again later.
228 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI
229 Request Packet. See HostAdapterStatus, TargetStatus,
230 SenseDataLength, and SenseData in that order for additional
232 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not
233 supported by the SCSI initiator(i.e., SCSI Host Controller).
234 The SCSI Request Packet was not sent, so no additional
235 status information is available.
236 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request
237 Packet to execute. See HostAdapterStatus, TargetStatus,
238 SenseDataLength, and SenseData in that order for
239 additional status information.
245 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
247 IN OUT VOID
*SenseData
, OPTIONAL
248 IN OUT UINT8
*SenseDataLength
,
249 OUT UINT8
*HostAdapterStatus
,
250 OUT UINT8
*TargetStatus
,
251 IN OUT VOID
*InquiryDataBuffer
, OPTIONAL
252 IN OUT UINT32
*InquiryDataLength
,
253 IN BOOLEAN EnableVitalProductData
256 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
259 UINT8 TargetArray
[EFI_SCSI_TARGET_MAX_BYTES
];
261 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIX
];
263 ASSERT (SenseDataLength
!= NULL
);
264 ASSERT (HostAdapterStatus
!= NULL
);
265 ASSERT (TargetStatus
!= NULL
);
266 ASSERT (InquiryDataLength
!= NULL
);
267 ASSERT (ScsiIo
!= NULL
);
269 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
270 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIX
);
272 CommandPacket
.Timeout
= Timeout
;
273 CommandPacket
.InDataBuffer
= InquiryDataBuffer
;
274 CommandPacket
.InTransferLength
= *InquiryDataLength
;
275 CommandPacket
.SenseData
= SenseData
;
276 CommandPacket
.SenseDataLength
= *SenseDataLength
;
277 CommandPacket
.Cdb
= Cdb
;
279 Target
= &TargetArray
[0];
280 ScsiIo
->GetDeviceLocation (ScsiIo
, &Target
, &Lun
);
282 Cdb
[0] = EFI_SCSI_OP_INQUIRY
;
283 Cdb
[1] = (UINT8
) (Lun
& EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK
);
284 if (EnableVitalProductData
) {
288 if (*InquiryDataLength
> 0xff) {
289 *InquiryDataLength
= 0xff;
292 Cdb
[4] = (UINT8
) (*InquiryDataLength
);
293 CommandPacket
.CdbLength
= (UINT8
) EFI_SCSI_OP_LENGTH_SIX
;
294 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
296 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
298 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
299 *TargetStatus
= CommandPacket
.TargetStatus
;
300 *SenseDataLength
= CommandPacket
.SenseDataLength
;
301 *InquiryDataLength
= CommandPacket
.InTransferLength
;
308 Execute Mode Sense(10) SCSI command on a specific SCSI target.
310 Executes the SCSI Mode Sense(10) command on the SCSI target specified by ScsiIo.
311 If Timeout is zero, then this function waits indefinitely for the command to complete.
312 If Timeout is greater than zero, then the command is executed and will timeout
313 after Timeout 100 ns units. The DBDField, PageControl, and PageCode parameters
314 are used to construct the CDB for this SCSI command.
315 If ScsiIo is NULL, then ASSERT().
316 If SenseDataLength is NULL, then ASSERT().
317 If HostAdapterStatus is NULL, then ASSERT().
318 If TargetStatus is NULL, then ASSERT().
319 If DataLength is NULL, then ASSERT().
322 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
323 for the specific SCSI target.
324 @param[in] Timeout The timeout in 100 ns units to use for the
325 execution of this SCSI Request Packet. A Timeout
326 value of zero means that this function will wait
327 indefinitely for the SCSI Request Packet to execute.
328 If Timeout is greater than zero, then this function
329 will return EFI_TIMEOUT if the time required to
330 execute the SCSI Request Packet is greater than Timeout.
331 @param[in, out] SenseData A pointer to sense data that was generated
332 by the execution of the SCSI Request Packet.
333 This buffer must be allocated by the caller.
334 If SenseDataLength is 0, then this parameter
335 is optional and may be NULL.
336 @param[in, out] SenseDataLength On input, the length in bytes of the SenseData buffer.
337 On output, the number of bytes written to the SenseData buffer.
338 @param[out] HostAdapterStatus The status of the SCSI Host Controller that
339 produces the SCSI bus containing the SCSI target
340 specified by ScsiIo when the SCSI Request Packet
341 was executed. See the EFI SCSI I/O Protocol in the
342 UEFI Specification for details on the possible
344 @param[out] TargetStatus The status returned by the SCSI target specified
345 by ScsiIo when the SCSI Request Packat was executed
346 on the SCSI Host Controller. See the EFI SCSI
347 I/O Protocol in the UEFI Specification for details
348 on the possible return values.
349 @param[in, out] DataBuffer A pointer to data that was generated by the
350 execution of the SCSI Request Packet. This
351 buffer must be allocated by the caller. If
352 DataLength is 0, then this parameter is optional
354 @param[in, out] DataLength On input, a pointer to the length in bytes of
355 the DataBuffer buffer. On output, a pointer
356 to the number of bytes written to the DataBuffer
358 @param[in] DBDField Specifies the DBD field of the CDB for this SCSI Command.
359 @param[in] PageControl Specifies the PC field of the CDB for this SCSI Command.
360 @param[in] PageCode Specifies the Page Control field of the CDB for this SCSI Command.
362 @retval EFI_SUCCESS The command was executed successfully.
363 See HostAdapterStatus, TargetStatus, SenseDataLength,
364 and SenseData in that order for additional status information.
365 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the
366 entire DataBuffer could not be transferred.
367 The actual number of bytes transferred is returned
369 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
370 there are too many SCSI Command Packets already queued.
371 The SCSI Request Packet was not sent, so no additional
372 status information is available. The caller may retry
374 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
375 SCSI Request Packet. See HostAdapterStatus, TargetStatus,
376 SenseDataLength, and SenseData in that order for
377 additional status information.
378 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
379 is not supported by the SCSI initiator(i.e., SCSI
380 Host Controller). The SCSI Request Packet was not
381 sent, so no additional status information is available.
382 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
383 Request Packet to execute. See HostAdapterStatus,
384 TargetStatus, SenseDataLength, and SenseData in that
385 order for additional status information.
390 ScsiModeSense10Command (
391 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
393 IN OUT VOID
*SenseData
, OPTIONAL
394 IN OUT UINT8
*SenseDataLength
,
395 OUT UINT8
*HostAdapterStatus
,
396 OUT UINT8
*TargetStatus
,
397 IN OUT VOID
*DataBuffer
, OPTIONAL
398 IN OUT UINT32
*DataLength
,
399 IN UINT8 DBDField
, OPTIONAL
400 IN UINT8 PageControl
,
404 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
407 UINT8 TargetArray
[EFI_SCSI_TARGET_MAX_BYTES
];
409 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TEN
];
411 ASSERT (SenseDataLength
!= NULL
);
412 ASSERT (HostAdapterStatus
!= NULL
);
413 ASSERT (TargetStatus
!= NULL
);
414 ASSERT (DataLength
!= NULL
);
415 ASSERT (ScsiIo
!= NULL
);
417 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
418 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TEN
);
420 CommandPacket
.Timeout
= Timeout
;
421 CommandPacket
.InDataBuffer
= DataBuffer
;
422 CommandPacket
.SenseData
= SenseData
;
423 CommandPacket
.InTransferLength
= *DataLength
;
424 CommandPacket
.Cdb
= Cdb
;
426 // Fill Cdb for Mode Sense (10) Command
428 Target
= &TargetArray
[0];
429 ScsiIo
->GetDeviceLocation (ScsiIo
, &Target
, &Lun
);
431 Cdb
[0] = EFI_SCSI_OP_MODE_SEN10
;
433 // DBDField is in Cdb[1] bit3 of (bit7..0)
435 Cdb
[1] = (UINT8
) ((Lun
& EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK
) + ((DBDField
<< 3) & 0x08));
437 // PageControl is in Cdb[2] bit7..6, PageCode is in Cdb[2] bit5..0
439 Cdb
[2] = (UINT8
) ((PageControl
& 0xc0) | (PageCode
& 0x3f));
440 Cdb
[7] = (UINT8
) (*DataLength
>> 8);
441 Cdb
[8] = (UINT8
) (*DataLength
);
443 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
444 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
445 CommandPacket
.SenseDataLength
= *SenseDataLength
;
447 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
449 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
450 *TargetStatus
= CommandPacket
.TargetStatus
;
451 *SenseDataLength
= CommandPacket
.SenseDataLength
;
452 *DataLength
= CommandPacket
.InTransferLength
;
459 Execute Request Sense SCSI command on a specific SCSI target.
461 Executes the Request Sense command on the SCSI target specified by ScsiIo.
462 If Timeout is zero, then this function waits indefinitely for the command to complete.
463 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
464 If ScsiIo is NULL, then ASSERT().
465 If SenseDataLength is NULL, then ASSERT().
466 If HostAdapterStatus is NULL, then ASSERT().
467 If TargetStatus is NULL, then ASSERT().
469 @param[in] ScsiIo A pointer to SCSI IO protocol.
470 @param[in] Timeout The length of timeout period.
471 @param[in, out] SenseData A pointer to output sense data.
472 @param[in, out] SenseDataLength The length of output sense data.
473 @param[out] HostAdapterStatus The status of Host Adapter.
474 @param[out] TargetStatus The status of the target.
476 @retval EFI_SUCCESS Command is executed successfully.
477 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are
478 too many SCSI Command Packets already queued.
479 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
480 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
481 the SCSI initiator(i.e., SCSI Host Controller)
482 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
487 ScsiRequestSenseCommand (
488 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
490 IN OUT VOID
*SenseData
, OPTIONAL
491 IN OUT UINT8
*SenseDataLength
,
492 OUT UINT8
*HostAdapterStatus
,
493 OUT UINT8
*TargetStatus
496 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
499 UINT8 TargetArray
[EFI_SCSI_TARGET_MAX_BYTES
];
501 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIX
];
503 ASSERT (SenseDataLength
!= NULL
);
504 ASSERT (HostAdapterStatus
!= NULL
);
505 ASSERT (TargetStatus
!= NULL
);
506 ASSERT (ScsiIo
!= NULL
);
508 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
509 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIX
);
511 CommandPacket
.Timeout
= Timeout
;
512 CommandPacket
.InDataBuffer
= SenseData
;
513 CommandPacket
.SenseData
= NULL
;
514 CommandPacket
.InTransferLength
= *SenseDataLength
;
515 CommandPacket
.Cdb
= Cdb
;
517 // Fill Cdb for Request Sense Command
519 Target
= &TargetArray
[0];
520 ScsiIo
->GetDeviceLocation (ScsiIo
, &Target
, &Lun
);
522 Cdb
[0] = EFI_SCSI_OP_REQUEST_SENSE
;
523 Cdb
[1] = (UINT8
) (Lun
& EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK
);
524 Cdb
[4] = (UINT8
) (*SenseDataLength
);
526 CommandPacket
.CdbLength
= (UINT8
) EFI_SCSI_OP_LENGTH_SIX
;
527 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
528 CommandPacket
.SenseDataLength
= 0;
530 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
532 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
533 *TargetStatus
= CommandPacket
.TargetStatus
;
534 *SenseDataLength
= (UINT8
) CommandPacket
.InTransferLength
;
541 Execute Read Capacity SCSI command on a specific SCSI target.
543 Executes the SCSI Read Capacity command on the SCSI target specified by ScsiIo.
544 If Timeout is zero, then this function waits indefinitely for the command to complete.
545 If Timeout is greater than zero, then the command is executed and will timeout after
546 Timeout 100 ns units. The PMI parameter is used to construct the CDB for this SCSI command.
547 If ScsiIo is NULL, then ASSERT().
548 If SenseDataLength is NULL, then ASSERT().
549 If HostAdapterStatus is NULL, then ASSERT().
550 If TargetStatus is NULL, then ASSERT().
551 If DataLength is NULL, then ASSERT().
553 @param[in] ScsiIo A pointer to SCSI IO protocol.
554 @param[in] Timeout The length of timeout period.
555 @param[in, out] SenseData A pointer to output sense data.
556 @param[in, out] SenseDataLength The length of output sense data.
557 @param[out] HostAdapterStatus The status of Host Adapter.
558 @param[out] TargetStatus The status of the target.
559 @param[in, out] DataBuffer A pointer to a data buffer.
560 @param[in, out] DataLength The length of data buffer.
561 @param[in] PMI Partial medium indicator.
563 @retval EFI_SUCCESS Command is executed successfully.
564 @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, but the entire DataBuffer could
565 not be transferred. The actual number of bytes transferred is returned in DataLength.
566 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
567 SCSI Command Packets already queued.
568 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
569 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
570 the SCSI initiator(i.e., SCSI Host Controller)
571 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
576 ScsiReadCapacityCommand (
577 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
579 IN OUT VOID
*SenseData
, OPTIONAL
580 IN OUT UINT8
*SenseDataLength
,
581 OUT UINT8
*HostAdapterStatus
,
582 OUT UINT8
*TargetStatus
,
583 IN OUT VOID
*DataBuffer
, OPTIONAL
584 IN OUT UINT32
*DataLength
,
588 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
591 UINT8 TargetArray
[EFI_SCSI_TARGET_MAX_BYTES
];
593 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TEN
];
595 ASSERT (SenseDataLength
!= NULL
);
596 ASSERT (HostAdapterStatus
!= NULL
);
597 ASSERT (TargetStatus
!= NULL
);
598 ASSERT (DataLength
!= NULL
);
599 ASSERT (ScsiIo
!= NULL
);
601 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
602 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TEN
);
604 CommandPacket
.Timeout
= Timeout
;
605 CommandPacket
.InDataBuffer
= DataBuffer
;
606 CommandPacket
.SenseData
= SenseData
;
607 CommandPacket
.InTransferLength
= *DataLength
;
608 CommandPacket
.Cdb
= Cdb
;
610 // Fill Cdb for Read Capacity Command
612 Target
= &TargetArray
[0];
613 ScsiIo
->GetDeviceLocation (ScsiIo
, &Target
, &Lun
);
615 Cdb
[0] = EFI_SCSI_OP_READ_CAPACITY
;
616 Cdb
[1] = (UINT8
) (Lun
& EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK
);
619 // Partial medium indicator,if PMI is FALSE, the Cdb.2 ~ Cdb.5 MUST BE ZERO.
621 ZeroMem ((Cdb
+ 2), 4);
626 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
627 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
628 CommandPacket
.SenseDataLength
= *SenseDataLength
;
630 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
632 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
633 *TargetStatus
= CommandPacket
.TargetStatus
;
634 *SenseDataLength
= CommandPacket
.SenseDataLength
;
635 *DataLength
= CommandPacket
.InTransferLength
;
642 Execute Read(10) SCSI command on a specific SCSI target.
644 Executes the SCSI Read(10) command on the SCSI target specified by ScsiIo.
645 If Timeout is zero, then this function waits indefinitely for the command to complete.
646 If Timeout is greater than zero, then the command is executed and will timeout
647 after Timeout 100 ns units. The StartLba and SectorSize parameters are used to
648 construct the CDB for this SCSI command.
649 If ScsiIo is NULL, then ASSERT().
650 If SenseDataLength is NULL, then ASSERT().
651 If HostAdapterStatus is NULL, then ASSERT().
652 If TargetStatus is NULL, then ASSERT().
653 If DataLength is NULL, then ASSERT().
656 @param[in] ScsiIo A pointer to SCSI IO protocol.
657 @param[in] Timeout The length of timeout period.
658 @param[in, out] SenseData A pointer to output sense data.
659 @param[in, out] SenseDataLength The length of output sense data.
660 @param[out] HostAdapterStatus The status of Host Adapter.
661 @param[out] TargetStatus The status of the target.
662 @param[in, out] DataBuffer Read 10 command data.
663 @param[in, out] DataLength The length of data buffer.
664 @param[in] StartLba The start address of LBA.
665 @param[in] SectorSize The sector size.
667 @retval EFI_SUCCESS Command is executed successfully.
668 @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, but the entire DataBuffer could
669 not be transferred. The actual number of bytes transferred is returned in DataLength.
670 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
671 SCSI Command Packets already queued.
672 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
673 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
674 the SCSI initiator(i.e., SCSI Host Controller)
675 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
681 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
683 IN OUT VOID
*SenseData
, OPTIONAL
684 IN OUT UINT8
*SenseDataLength
,
685 OUT UINT8
*HostAdapterStatus
,
686 OUT UINT8
*TargetStatus
,
687 IN OUT VOID
*DataBuffer
, OPTIONAL
688 IN OUT UINT32
*DataLength
,
693 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
696 UINT8 TargetArray
[EFI_SCSI_TARGET_MAX_BYTES
];
698 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TEN
];
700 ASSERT (SenseDataLength
!= NULL
);
701 ASSERT (HostAdapterStatus
!= NULL
);
702 ASSERT (TargetStatus
!= NULL
);
703 ASSERT (DataLength
!= NULL
);
704 ASSERT (ScsiIo
!= NULL
);
706 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
707 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TEN
);
709 CommandPacket
.Timeout
= Timeout
;
710 CommandPacket
.InDataBuffer
= DataBuffer
;
711 CommandPacket
.SenseData
= SenseData
;
712 CommandPacket
.InTransferLength
= *DataLength
;
713 CommandPacket
.Cdb
= Cdb
;
715 // Fill Cdb for Read (10) Command
717 Target
= &TargetArray
[0];
718 ScsiIo
->GetDeviceLocation (ScsiIo
, &Target
, &Lun
);
720 Cdb
[0] = EFI_SCSI_OP_READ10
;
721 Cdb
[1] = (UINT8
) (Lun
& EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK
);
722 Cdb
[2] = (UINT8
) (StartLba
>> 24);
723 Cdb
[3] = (UINT8
) (StartLba
>> 16);
724 Cdb
[4] = (UINT8
) (StartLba
>> 8);
725 Cdb
[5] = (UINT8
) (StartLba
& 0xff);
726 Cdb
[7] = (UINT8
) (SectorSize
>> 8);
727 Cdb
[8] = (UINT8
) (SectorSize
& 0xff);
729 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
730 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
731 CommandPacket
.SenseDataLength
= *SenseDataLength
;
733 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
735 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
736 *TargetStatus
= CommandPacket
.TargetStatus
;
737 *SenseDataLength
= CommandPacket
.SenseDataLength
;
738 *DataLength
= CommandPacket
.InTransferLength
;
745 Execute Write(10) SCSI command on a specific SCSI target.
747 Executes the SCSI Write(10) command on the SCSI target specified by ScsiIo.
748 If Timeout is zero, then this function waits indefinitely for the command to complete.
749 If Timeout is greater than zero, then the command is executed and will timeout after
750 Timeout 100 ns units. The StartLba and SectorSize parameters are used to construct
751 the CDB for this SCSI command.
752 If ScsiIo is NULL, then ASSERT().
753 If SenseDataLength is NULL, then ASSERT().
754 If HostAdapterStatus is NULL, then ASSERT().
755 If TargetStatus is NULL, then ASSERT().
756 If DataLength is NULL, then ASSERT().
758 @param[in] ScsiIo SCSI IO Protocol to use
759 @param[in] Timeout The length of timeout period.
760 @param[in, out] SenseData A pointer to output sense data.
761 @param[in, out] SenseDataLength The length of output sense data.
762 @param[out] HostAdapterStatus The status of Host Adapter.
763 @param[out] TargetStatus The status of the target.
764 @param[in, out] DataBuffer A pointer to a data buffer.
765 @param[in, out] DataLength The length of data buffer.
766 @param[in] StartLba The start address of LBA.
767 @param[in] SectorSize The sector size.
769 @retval EFI_SUCCESS Command is executed successfully.
770 @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, but the entire DataBuffer could
771 not be transferred. The actual number of bytes transferred is returned in DataLength.
772 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
773 SCSI Command Packets already queued.
774 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
775 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
776 the SCSI initiator(i.e., SCSI Host Controller)
777 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
783 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
785 IN OUT VOID
*SenseData
, OPTIONAL
786 IN OUT UINT8
*SenseDataLength
,
787 OUT UINT8
*HostAdapterStatus
,
788 OUT UINT8
*TargetStatus
,
789 IN OUT VOID
*DataBuffer
, OPTIONAL
790 IN OUT UINT32
*DataLength
,
795 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
798 UINT8 TargetArray
[EFI_SCSI_TARGET_MAX_BYTES
];
800 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TEN
];
802 ASSERT (SenseDataLength
!= NULL
);
803 ASSERT (HostAdapterStatus
!= NULL
);
804 ASSERT (TargetStatus
!= NULL
);
805 ASSERT (DataLength
!= NULL
);
806 ASSERT (ScsiIo
!= NULL
);
808 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
809 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TEN
);
811 CommandPacket
.Timeout
= Timeout
;
812 CommandPacket
.OutDataBuffer
= DataBuffer
;
813 CommandPacket
.SenseData
= SenseData
;
814 CommandPacket
.OutTransferLength
= *DataLength
;
815 CommandPacket
.Cdb
= Cdb
;
817 // Fill Cdb for Write (10) Command
819 Target
= &TargetArray
[0];
820 ScsiIo
->GetDeviceLocation (ScsiIo
, &Target
, &Lun
);
822 Cdb
[0] = EFI_SCSI_OP_WRITE10
;
823 Cdb
[1] = (UINT8
) (Lun
& EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK
);
824 Cdb
[2] = (UINT8
) (StartLba
>> 24);
825 Cdb
[3] = (UINT8
) (StartLba
>> 16);
826 Cdb
[4] = (UINT8
) (StartLba
>> 8);
827 Cdb
[5] = (UINT8
) StartLba
;
828 Cdb
[7] = (UINT8
) (SectorSize
>> 8);
829 Cdb
[8] = (UINT8
) SectorSize
;
831 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
832 CommandPacket
.DataDirection
= EFI_SCSI_DATA_OUT
;
833 CommandPacket
.SenseDataLength
= *SenseDataLength
;
835 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
837 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
838 *TargetStatus
= CommandPacket
.TargetStatus
;
839 *SenseDataLength
= CommandPacket
.SenseDataLength
;
840 *DataLength
= CommandPacket
.OutTransferLength
;