2 UEFI SCSI Library implementation
4 Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/BaseLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/UefiScsiLib.h>
14 #include <Library/BaseMemoryLib.h>
15 #include <Library/MemoryAllocationLib.h>
16 #include <Library/UefiBootServicesTableLib.h>
18 #include <IndustryStandard/Scsi.h>
22 // Scsi Command Length
24 #define EFI_SCSI_OP_LENGTH_SIX 0x6
25 #define EFI_SCSI_OP_LENGTH_TEN 0xa
26 #define EFI_SCSI_OP_LENGTH_TWELVE 0xc
27 #define EFI_SCSI_OP_LENGTH_SIXTEEN 0x10
30 // The context structure used when non-blocking SCSI read/write operation
35 /// The SCSI request packet to send to the SCSI controller specified by
36 /// the device handle.
38 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
40 /// The length of the output sense data.
42 UINT8
*SenseDataLength
;
44 /// The status of the SCSI host adapter.
46 UINT8
*HostAdapterStatus
;
48 /// The status of the target SCSI device.
52 /// The length of the data buffer for the SCSI read/write command.
56 /// The caller event to be signaled when the SCSI read/write command
59 EFI_EVENT CallerEvent
;
60 } EFI_SCSI_LIB_ASYNC_CONTEXT
;
65 Execute Test Unit Ready SCSI command on a specific SCSI target.
67 Executes the Test Unit Ready command on the SCSI target specified by ScsiIo.
68 If Timeout is zero, then this function waits indefinitely for the command to complete.
69 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
70 If ScsiIo is NULL, then ASSERT().
71 If SenseDataLength is NULL, then ASSERT().
72 If HostAdapterStatus is NULL, then ASSERT().
73 If TargetStatus is NULL, then ASSERT().
75 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
76 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
79 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
80 for the specific SCSI target.
81 @param[in] Timeout The timeout in 100 ns units to use for the execution
82 of this SCSI Request Packet. A Timeout value of
83 zero means that this function will wait indefinitely
84 for the SCSI Request Packet to execute. If Timeout
85 is greater than zero, then this function will return
86 EFI_TIMEOUT if the time required to execute the SCSI
87 Request Packet is greater than Timeout.
88 @param[in, out] SenseData A pointer to sense data that was generated by
89 the execution of the SCSI Request Packet. This
90 buffer must be allocated by the caller.
91 If SenseDataLength is 0, then this parameter is
92 optional and may be NULL.
93 @param[in, out] SenseDataLength On input, a pointer to the length in bytes of
94 the SenseData buffer. On output, a pointer to
95 the number of bytes written to the SenseData buffer.
96 @param[out] HostAdapterStatus The status of the SCSI Host Controller that produces
97 the SCSI bus containing the SCSI target specified by
98 ScsiIo when the SCSI Request Packet was executed.
99 See the EFI SCSI I/O Protocol in the UEFI Specification
100 for details on the possible return values.
101 @param[out] TargetStatus The status returned by the SCSI target specified
102 by ScsiIo when the SCSI Request Packet was executed
103 on the SCSI Host Controller. See the EFI SCSI I/O
104 Protocol in the UEFI Specification for details on
105 the possible return values.
107 @retval EFI_SUCCESS The command was executed successfully.
108 See HostAdapterStatus, TargetStatus, SenseDataLength,
109 and SenseData in that order for additional status
111 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
112 there are too many SCSI Command Packets already
113 queued. The SCSI Request Packet was not sent, so
114 no additional status information is available.
115 The caller may retry again later.
116 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
117 SCSI Request Packet. See HostAdapterStatus,
118 TargetStatus, SenseDataLength, and SenseData in that
119 order for additional status information.
120 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
121 is not supported by the SCSI initiator(i.e., SCSI
122 Host Controller). The SCSI Request Packet was not
123 sent, so no additional status information is available.
124 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request
125 Packet to execute. See HostAdapterStatus, TargetStatus,
126 SenseDataLength, and SenseData in that order for
127 additional status information.
128 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
133 ScsiTestUnitReadyCommand (
134 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
136 IN OUT VOID
*SenseData
, OPTIONAL
137 IN OUT UINT8
*SenseDataLength
,
138 OUT UINT8
*HostAdapterStatus
,
139 OUT UINT8
*TargetStatus
142 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
144 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIX
];
146 ASSERT (SenseDataLength
!= NULL
);
147 ASSERT (HostAdapterStatus
!= NULL
);
148 ASSERT (TargetStatus
!= NULL
);
149 ASSERT (ScsiIo
!= NULL
);
151 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
152 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIX
);
154 CommandPacket
.Timeout
= Timeout
;
155 CommandPacket
.InDataBuffer
= NULL
;
156 CommandPacket
.InTransferLength
= 0;
157 CommandPacket
.OutDataBuffer
= NULL
;
158 CommandPacket
.OutTransferLength
= 0;
159 CommandPacket
.SenseData
= SenseData
;
160 CommandPacket
.Cdb
= Cdb
;
162 // Fill Cdb for Test Unit Ready Command
164 Cdb
[0] = EFI_SCSI_OP_TEST_UNIT_READY
;
165 CommandPacket
.CdbLength
= (UINT8
) EFI_SCSI_OP_LENGTH_SIX
;
166 CommandPacket
.SenseDataLength
= *SenseDataLength
;
168 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
170 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
171 *TargetStatus
= CommandPacket
.TargetStatus
;
172 *SenseDataLength
= CommandPacket
.SenseDataLength
;
179 Execute Inquiry SCSI command on a specific SCSI target.
181 Executes the Inquiry command on the SCSI target specified by ScsiIo.
182 If Timeout is zero, then this function waits indefinitely for the command to complete.
183 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
184 If ScsiIo is NULL, then ASSERT().
185 If SenseDataLength is NULL, then ASSERT().
186 If HostAdapterStatus is NULL, then ASSERT().
187 If TargetStatus is NULL, then ASSERT().
188 If InquiryDataLength is NULL, then ASSERT().
190 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
191 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
194 If InquiryDataLength is non-zero and InquiryDataBuffer is not NULL, InquiryDataBuffer
195 must meet buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
196 EFI_INVALID_PARAMETER gets returned.
198 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
199 for the specific SCSI target.
200 @param[in] Timeout The timeout in 100 ns units to use for the
201 execution of this SCSI Request Packet. A Timeout
202 value of zero means that this function will wait
203 indefinitely for the SCSI Request Packet to execute.
204 If Timeout is greater than zero, then this function
205 will return EFI_TIMEOUT if the time required to
206 execute the SCSI Request Packet is greater than Timeout.
207 @param[in, out] SenseData A pointer to sense data that was generated
208 by the execution of the SCSI Request Packet.
209 This buffer must be allocated by the caller.
210 If SenseDataLength is 0, then this parameter
211 is optional and may be NULL.
212 @param[in, out] SenseDataLength On input, the length in bytes of the SenseData buffer.
213 On output, the number of bytes written to the SenseData buffer.
214 @param[out] HostAdapterStatus The status of the SCSI Host Controller that
215 produces the SCSI bus containing the SCSI
216 target specified by ScsiIo when the SCSI
217 Request Packet was executed. See the EFI
218 SCSI I/O Protocol in the UEFI Specification
219 for details on the possible return values.
220 @param[out] TargetStatus The status returned by the SCSI target specified
221 by ScsiIo when the SCSI Request Packet was
222 executed on the SCSI Host Controller.
223 See the EFI SCSI I/O Protocol in the UEFI
224 Specification for details on the possible
226 @param[in, out] InquiryDataBuffer A pointer to inquiry data that was generated
227 by the execution of the SCSI Request Packet.
228 This buffer must be allocated by the caller.
229 If InquiryDataLength is 0, then this parameter
230 is optional and may be NULL.
231 @param[in, out] InquiryDataLength On input, a pointer to the length in bytes
232 of the InquiryDataBuffer buffer.
233 On output, a pointer to the number of bytes
234 written to the InquiryDataBuffer buffer.
235 @param[in] EnableVitalProductData If TRUE, then the supported vital product
236 data for the PageCode is returned in InquiryDataBuffer.
237 If FALSE, then the standard inquiry data is
238 returned in InquiryDataBuffer and PageCode is ignored.
239 @param[in] PageCode The page code of the vital product data.
240 It's ignored if EnableVitalProductData is FALSE.
242 @retval EFI_SUCCESS The command executed successfully. See HostAdapterStatus,
243 TargetStatus, SenseDataLength, and SenseData in that order
244 for additional status information.
245 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire
246 InquiryDataBuffer could not be transferred. The actual
247 number of bytes transferred is returned in InquiryDataLength.
248 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there
249 are too many SCSI Command Packets already queued.
250 The SCSI Request Packet was not sent, so no additional
251 status information is available. The caller may retry again later.
252 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI
253 Request Packet. See HostAdapterStatus, TargetStatus,
254 SenseDataLength, and SenseData in that order for additional
256 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not
257 supported by the SCSI initiator(i.e., SCSI Host Controller).
258 The SCSI Request Packet was not sent, so no additional
259 status information is available.
260 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request
261 Packet to execute. See HostAdapterStatus, TargetStatus,
262 SenseDataLength, and SenseData in that order for
263 additional status information.
264 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
269 ScsiInquiryCommandEx (
270 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
272 IN OUT VOID
*SenseData
, OPTIONAL
273 IN OUT UINT8
*SenseDataLength
,
274 OUT UINT8
*HostAdapterStatus
,
275 OUT UINT8
*TargetStatus
,
276 IN OUT VOID
*InquiryDataBuffer
, OPTIONAL
277 IN OUT UINT32
*InquiryDataLength
,
278 IN BOOLEAN EnableVitalProductData
,
282 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
284 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIX
];
286 ASSERT (SenseDataLength
!= NULL
);
287 ASSERT (HostAdapterStatus
!= NULL
);
288 ASSERT (TargetStatus
!= NULL
);
289 ASSERT (InquiryDataLength
!= NULL
);
290 ASSERT (ScsiIo
!= NULL
);
292 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
293 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIX
);
295 CommandPacket
.Timeout
= Timeout
;
296 CommandPacket
.InDataBuffer
= InquiryDataBuffer
;
297 CommandPacket
.InTransferLength
= *InquiryDataLength
;
298 CommandPacket
.SenseData
= SenseData
;
299 CommandPacket
.SenseDataLength
= *SenseDataLength
;
300 CommandPacket
.Cdb
= Cdb
;
302 Cdb
[0] = EFI_SCSI_OP_INQUIRY
;
303 if (EnableVitalProductData
) {
308 if (*InquiryDataLength
> 0xff) {
309 *InquiryDataLength
= 0xff;
312 Cdb
[4] = (UINT8
) (*InquiryDataLength
);
313 CommandPacket
.CdbLength
= (UINT8
) EFI_SCSI_OP_LENGTH_SIX
;
314 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
316 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
318 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
319 *TargetStatus
= CommandPacket
.TargetStatus
;
320 *SenseDataLength
= CommandPacket
.SenseDataLength
;
321 *InquiryDataLength
= CommandPacket
.InTransferLength
;
328 Execute Inquiry SCSI command on a specific SCSI target.
330 Executes the Inquiry command on the SCSI target specified by ScsiIo.
331 If Timeout is zero, then this function waits indefinitely for the command to complete.
332 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
333 If ScsiIo is NULL, then ASSERT().
334 If SenseDataLength is NULL, then ASSERT().
335 If HostAdapterStatus is NULL, then ASSERT().
336 If TargetStatus is NULL, then ASSERT().
337 If InquiryDataLength is NULL, then ASSERT().
339 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
340 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
343 If InquiryDataLength is non-zero and InquiryDataBuffer is not NULL, InquiryDataBuffer
344 must meet buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
345 EFI_INVALID_PARAMETER gets returned.
347 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
348 for the specific SCSI target.
349 @param[in] Timeout The timeout in 100 ns units to use for the
350 execution of this SCSI Request Packet. A Timeout
351 value of zero means that this function will wait
352 indefinitely for the SCSI Request Packet to execute.
353 If Timeout is greater than zero, then this function
354 will return EFI_TIMEOUT if the time required to
355 execute the SCSI Request Packet is greater than Timeout.
356 @param[in, out] SenseData A pointer to sense data that was generated
357 by the execution of the SCSI Request Packet.
358 This buffer must be allocated by the caller.
359 If SenseDataLength is 0, then this parameter
360 is optional and may be NULL.
361 @param[in, out] SenseDataLength On input, the length in bytes of the SenseData buffer.
362 On output, the number of bytes written to the SenseData buffer.
363 @param[out] HostAdapterStatus The status of the SCSI Host Controller that
364 produces the SCSI bus containing the SCSI
365 target specified by ScsiIo when the SCSI
366 Request Packet was executed. See the EFI
367 SCSI I/O Protocol in the UEFI Specification
368 for details on the possible return values.
369 @param[out] TargetStatus The status returned by the SCSI target specified
370 by ScsiIo when the SCSI Request Packet was
371 executed on the SCSI Host Controller.
372 See the EFI SCSI I/O Protocol in the UEFI
373 Specification for details on the possible
375 @param[in, out] InquiryDataBuffer A pointer to inquiry data that was generated
376 by the execution of the SCSI Request Packet.
377 This buffer must be allocated by the caller.
378 If InquiryDataLength is 0, then this parameter
379 is optional and may be NULL.
380 @param[in, out] InquiryDataLength On input, a pointer to the length in bytes
381 of the InquiryDataBuffer buffer.
382 On output, a pointer to the number of bytes
383 written to the InquiryDataBuffer buffer.
384 @param[in] EnableVitalProductData If TRUE, then the supported vital product
385 data is returned in InquiryDataBuffer.
386 If FALSE, then the standard inquiry data is
387 returned in InquiryDataBuffer.
389 @retval EFI_SUCCESS The command was executed successfully. See HostAdapterStatus,
390 TargetStatus, SenseDataLength, and SenseData in that order
391 for additional status information.
392 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire
393 InquiryDataBuffer could not be transferred. The actual
394 number of bytes transferred is returned in InquiryDataLength.
395 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there
396 are too many SCSI Command Packets already queued.
397 The SCSI Request Packet was not sent, so no additional
398 status information is available. The caller may retry again later.
399 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI
400 Request Packet. See HostAdapterStatus, TargetStatus,
401 SenseDataLength, and SenseData in that order for additional
403 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not
404 supported by the SCSI initiator(i.e., SCSI Host Controller).
405 The SCSI Request Packet was not sent, so no additional
406 status information is available.
407 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request
408 Packet to execute. See HostAdapterStatus, TargetStatus,
409 SenseDataLength, and SenseData in that order for
410 additional status information.
411 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
417 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
419 IN OUT VOID
*SenseData
, OPTIONAL
420 IN OUT UINT8
*SenseDataLength
,
421 OUT UINT8
*HostAdapterStatus
,
422 OUT UINT8
*TargetStatus
,
423 IN OUT VOID
*InquiryDataBuffer
, OPTIONAL
424 IN OUT UINT32
*InquiryDataLength
,
425 IN BOOLEAN EnableVitalProductData
428 return ScsiInquiryCommandEx (
437 EnableVitalProductData
,
443 Execute Mode Sense(10) SCSI command on a specific SCSI target.
445 Executes the SCSI Mode Sense(10) command on the SCSI target specified by ScsiIo.
446 If Timeout is zero, then this function waits indefinitely for the command to complete.
447 If Timeout is greater than zero, then the command is executed and will timeout
448 after Timeout 100 ns units. The DBDField, PageControl, and PageCode parameters
449 are used to construct the CDB for this SCSI command.
450 If ScsiIo is NULL, then ASSERT().
451 If SenseDataLength is NULL, then ASSERT().
452 If HostAdapterStatus is NULL, then ASSERT().
453 If TargetStatus is NULL, then ASSERT().
454 If DataLength is NULL, then ASSERT().
456 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
457 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
460 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
461 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
464 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
465 for the specific SCSI target.
466 @param[in] Timeout The timeout in 100 ns units to use for the
467 execution of this SCSI Request Packet. A Timeout
468 value of zero means that this function will wait
469 indefinitely for the SCSI Request Packet to execute.
470 If Timeout is greater than zero, then this function
471 will return EFI_TIMEOUT if the time required to
472 execute the SCSI Request Packet is greater than Timeout.
473 @param[in, out] SenseData A pointer to sense data that was generated
474 by the execution of the SCSI Request Packet.
475 This buffer must be allocated by the caller.
476 If SenseDataLength is 0, then this parameter
477 is optional and may be NULL.
478 @param[in, out] SenseDataLength On input, the length in bytes of the SenseData buffer.
479 On output, the number of bytes written to the SenseData buffer.
480 @param[out] HostAdapterStatus The status of the SCSI Host Controller that
481 produces the SCSI bus containing the SCSI target
482 specified by ScsiIo when the SCSI Request Packet
483 was executed. See the EFI SCSI I/O Protocol in the
484 UEFI Specification for details on the possible
486 @param[out] TargetStatus The status returned by the SCSI target specified
487 by ScsiIo when the SCSI Request Packet was executed
488 on the SCSI Host Controller. See the EFI SCSI
489 I/O Protocol in the UEFI Specification for details
490 on the possible return values.
491 @param[in, out] DataBuffer A pointer to data that was generated by the
492 execution of the SCSI Request Packet. This
493 buffer must be allocated by the caller. If
494 DataLength is 0, then this parameter is optional
496 @param[in, out] DataLength On input, a pointer to the length in bytes of
497 the DataBuffer buffer. On output, a pointer
498 to the number of bytes written to the DataBuffer
500 @param[in] DBDField Specifies the DBD field of the CDB for this SCSI Command.
501 @param[in] PageControl Specifies the PC field of the CDB for this SCSI Command.
502 @param[in] PageCode Specifies the Page Control field of the CDB for this SCSI Command.
504 @retval EFI_SUCCESS The command was executed successfully.
505 See HostAdapterStatus, TargetStatus, SenseDataLength,
506 and SenseData in that order for additional status information.
507 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the
508 entire DataBuffer could not be transferred.
509 The actual number of bytes transferred is returned
511 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
512 there are too many SCSI Command Packets already queued.
513 The SCSI Request Packet was not sent, so no additional
514 status information is available. The caller may retry
516 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
517 SCSI Request Packet. See HostAdapterStatus, TargetStatus,
518 SenseDataLength, and SenseData in that order for
519 additional status information.
520 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
521 is not supported by the SCSI initiator(i.e., SCSI
522 Host Controller). The SCSI Request Packet was not
523 sent, so no additional status information is available.
524 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
525 Request Packet to execute. See HostAdapterStatus,
526 TargetStatus, SenseDataLength, and SenseData in that
527 order for additional status information.
528 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
533 ScsiModeSense10Command (
534 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
536 IN OUT VOID
*SenseData
, OPTIONAL
537 IN OUT UINT8
*SenseDataLength
,
538 OUT UINT8
*HostAdapterStatus
,
539 OUT UINT8
*TargetStatus
,
540 IN OUT VOID
*DataBuffer
, OPTIONAL
541 IN OUT UINT32
*DataLength
,
542 IN UINT8 DBDField
, OPTIONAL
543 IN UINT8 PageControl
,
547 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
549 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TEN
];
551 ASSERT (SenseDataLength
!= NULL
);
552 ASSERT (HostAdapterStatus
!= NULL
);
553 ASSERT (TargetStatus
!= NULL
);
554 ASSERT (DataLength
!= NULL
);
555 ASSERT (ScsiIo
!= NULL
);
557 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
558 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TEN
);
560 CommandPacket
.Timeout
= Timeout
;
561 CommandPacket
.InDataBuffer
= DataBuffer
;
562 CommandPacket
.SenseData
= SenseData
;
563 CommandPacket
.InTransferLength
= *DataLength
;
564 CommandPacket
.Cdb
= Cdb
;
566 // Fill Cdb for Mode Sense (10) Command
568 Cdb
[0] = EFI_SCSI_OP_MODE_SEN10
;
570 // DBDField is in Cdb[1] bit3 of (bit7..0)
572 Cdb
[1] = (UINT8
) ((DBDField
<< 3) & 0x08);
574 // PageControl is in Cdb[2] bit7..6, PageCode is in Cdb[2] bit5..0
576 Cdb
[2] = (UINT8
) (((PageControl
<< 6) & 0xc0) | (PageCode
& 0x3f));
577 Cdb
[7] = (UINT8
) (*DataLength
>> 8);
578 Cdb
[8] = (UINT8
) (*DataLength
);
580 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
581 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
582 CommandPacket
.SenseDataLength
= *SenseDataLength
;
584 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
586 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
587 *TargetStatus
= CommandPacket
.TargetStatus
;
588 *SenseDataLength
= CommandPacket
.SenseDataLength
;
589 *DataLength
= CommandPacket
.InTransferLength
;
596 Execute Request Sense SCSI command on a specific SCSI target.
598 Executes the Request Sense command on the SCSI target specified by ScsiIo.
599 If Timeout is zero, then this function waits indefinitely for the command to complete.
600 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
601 If ScsiIo is NULL, then ASSERT().
602 If SenseDataLength is NULL, then ASSERT().
603 If HostAdapterStatus is NULL, then ASSERT().
604 If TargetStatus is NULL, then ASSERT().
606 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
607 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
610 @param[in] ScsiIo A pointer to SCSI IO protocol.
611 @param[in] Timeout The length of timeout period.
612 @param[in, out] SenseData A pointer to output sense data.
613 @param[in, out] SenseDataLength The length of output sense data.
614 @param[out] HostAdapterStatus The status of Host Adapter.
615 @param[out] TargetStatus The status of the target.
617 @retval EFI_SUCCESS Command is executed successfully.
618 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are
619 too many SCSI Command Packets already queued.
620 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
621 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
622 the SCSI initiator(i.e., SCSI Host Controller)
623 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
624 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
629 ScsiRequestSenseCommand (
630 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
632 IN OUT VOID
*SenseData
, OPTIONAL
633 IN OUT UINT8
*SenseDataLength
,
634 OUT UINT8
*HostAdapterStatus
,
635 OUT UINT8
*TargetStatus
638 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
640 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIX
];
642 ASSERT (SenseDataLength
!= NULL
);
643 ASSERT (HostAdapterStatus
!= NULL
);
644 ASSERT (TargetStatus
!= NULL
);
645 ASSERT (ScsiIo
!= NULL
);
647 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
648 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIX
);
650 CommandPacket
.Timeout
= Timeout
;
651 CommandPacket
.InDataBuffer
= SenseData
;
652 CommandPacket
.SenseData
= NULL
;
653 CommandPacket
.InTransferLength
= *SenseDataLength
;
654 CommandPacket
.Cdb
= Cdb
;
656 // Fill Cdb for Request Sense Command
658 Cdb
[0] = EFI_SCSI_OP_REQUEST_SENSE
;
659 Cdb
[4] = (UINT8
) (*SenseDataLength
);
661 CommandPacket
.CdbLength
= (UINT8
) EFI_SCSI_OP_LENGTH_SIX
;
662 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
663 CommandPacket
.SenseDataLength
= 0;
665 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
667 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
668 *TargetStatus
= CommandPacket
.TargetStatus
;
669 *SenseDataLength
= (UINT8
) CommandPacket
.InTransferLength
;
676 Execute Read Capacity SCSI command on a specific SCSI target.
678 Executes the SCSI Read Capacity command on the SCSI target specified by ScsiIo.
679 If Timeout is zero, then this function waits indefinitely for the command to complete.
680 If Timeout is greater than zero, then the command is executed and will timeout after
681 Timeout 100 ns units. The Pmi parameter is used to construct the CDB for this SCSI command.
682 If ScsiIo is NULL, then ASSERT().
683 If SenseDataLength is NULL, then ASSERT().
684 If HostAdapterStatus is NULL, then ASSERT().
685 If TargetStatus is NULL, then ASSERT().
686 If DataLength is NULL, then ASSERT().
688 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
689 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
692 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
693 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
696 @param[in] ScsiIo A pointer to SCSI IO protocol.
697 @param[in] Timeout The length of timeout period.
698 @param[in, out] SenseData A pointer to output sense data.
699 @param[in, out] SenseDataLength The length of output sense data.
700 @param[out] HostAdapterStatus The status of Host Adapter.
701 @param[out] TargetStatus The status of the target.
702 @param[in, out] DataBuffer A pointer to a data buffer.
703 @param[in, out] DataLength The length of data buffer.
704 @param[in] Pmi Partial medium indicator.
706 @retval EFI_SUCCESS Command is executed successfully.
707 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire
708 DataBuffer could not be transferred. The actual
709 number of bytes transferred is returned in DataLength.
710 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
711 there are too many SCSI Command Packets already queued.
712 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
713 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
714 is not supported by the SCSI initiator(i.e., SCSI Host Controller)
715 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
716 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
721 ScsiReadCapacityCommand (
722 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
724 IN OUT VOID
*SenseData
, OPTIONAL
725 IN OUT UINT8
*SenseDataLength
,
726 OUT UINT8
*HostAdapterStatus
,
727 OUT UINT8
*TargetStatus
,
728 IN OUT VOID
*DataBuffer
, OPTIONAL
729 IN OUT UINT32
*DataLength
,
733 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
735 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TEN
];
737 ASSERT (SenseDataLength
!= NULL
);
738 ASSERT (HostAdapterStatus
!= NULL
);
739 ASSERT (TargetStatus
!= NULL
);
740 ASSERT (DataLength
!= NULL
);
741 ASSERT (ScsiIo
!= NULL
);
743 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
744 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TEN
);
746 CommandPacket
.Timeout
= Timeout
;
747 CommandPacket
.InDataBuffer
= DataBuffer
;
748 CommandPacket
.SenseData
= SenseData
;
749 CommandPacket
.InTransferLength
= *DataLength
;
750 CommandPacket
.Cdb
= Cdb
;
752 // Fill Cdb for Read Capacity Command
754 Cdb
[0] = EFI_SCSI_OP_READ_CAPACITY
;
757 // Partial medium indicator,if Pmi is FALSE, the Cdb.2 ~ Cdb.5 MUST BE ZERO.
759 ZeroMem ((Cdb
+ 2), 4);
764 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
765 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
766 CommandPacket
.SenseDataLength
= *SenseDataLength
;
768 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
770 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
771 *TargetStatus
= CommandPacket
.TargetStatus
;
772 *SenseDataLength
= CommandPacket
.SenseDataLength
;
773 *DataLength
= CommandPacket
.InTransferLength
;
780 Execute Read Capacity SCSI 16 command on a specific SCSI target.
782 Executes the SCSI Read Capacity 16 command on the SCSI target specified by ScsiIo.
783 If Timeout is zero, then this function waits indefinitely for the command to complete.
784 If Timeout is greater than zero, then the command is executed and will timeout after
785 Timeout 100 ns units. The Pmi parameter is used to construct the CDB for this SCSI command.
786 If ScsiIo is NULL, then ASSERT().
787 If SenseDataLength is NULL, then ASSERT().
788 If HostAdapterStatus is NULL, then ASSERT().
789 If TargetStatus is NULL, then ASSERT().
790 If DataLength is NULL, then ASSERT().
792 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
793 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
796 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
797 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
800 @param[in] ScsiIo A pointer to SCSI IO protocol.
801 @param[in] Timeout The length of timeout period.
802 @param[in, out] SenseData A pointer to output sense data.
803 @param[in, out] SenseDataLength The length of output sense data.
804 @param[out] HostAdapterStatus The status of Host Adapter.
805 @param[out] TargetStatus The status of the target.
806 @param[in, out] DataBuffer A pointer to a data buffer.
807 @param[in, out] DataLength The length of data buffer.
808 @param[in] Pmi Partial medium indicator.
810 @retval EFI_SUCCESS Command is executed successfully.
811 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire
812 DataBuffer could not be transferred. The actual
813 number of bytes transferred is returned in DataLength.
814 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
815 there are too many SCSI Command Packets already queued.
816 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
817 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
818 is not supported by the SCSI initiator(i.e., SCSI Host Controller)
819 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
820 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
825 ScsiReadCapacity16Command (
826 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
828 IN OUT VOID
*SenseData
, OPTIONAL
829 IN OUT UINT8
*SenseDataLength
,
830 OUT UINT8
*HostAdapterStatus
,
831 OUT UINT8
*TargetStatus
,
832 IN OUT VOID
*DataBuffer
, OPTIONAL
833 IN OUT UINT32
*DataLength
,
837 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
841 ASSERT (SenseDataLength
!= NULL
);
842 ASSERT (HostAdapterStatus
!= NULL
);
843 ASSERT (TargetStatus
!= NULL
);
844 ASSERT (DataLength
!= NULL
);
845 ASSERT (ScsiIo
!= NULL
);
847 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
850 CommandPacket
.Timeout
= Timeout
;
851 CommandPacket
.InDataBuffer
= DataBuffer
;
852 CommandPacket
.SenseData
= SenseData
;
853 CommandPacket
.InTransferLength
= *DataLength
;
854 CommandPacket
.Cdb
= Cdb
;
856 // Fill Cdb for Read Capacity Command
858 Cdb
[0] = EFI_SCSI_OP_READ_CAPACITY16
;
862 // Partial medium indicator,if Pmi is FALSE, the Cdb.2 ~ Cdb.9 MUST BE ZERO.
864 ZeroMem ((Cdb
+ 2), 8);
870 CommandPacket
.CdbLength
= 16;
871 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
872 CommandPacket
.SenseDataLength
= *SenseDataLength
;
874 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
876 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
877 *TargetStatus
= CommandPacket
.TargetStatus
;
878 *SenseDataLength
= CommandPacket
.SenseDataLength
;
879 *DataLength
= CommandPacket
.InTransferLength
;
886 Execute Read(10) SCSI command on a specific SCSI target.
888 Executes the SCSI Read(10) command on the SCSI target specified by ScsiIo.
889 If Timeout is zero, then this function waits indefinitely for the command to complete.
890 If Timeout is greater than zero, then the command is executed and will timeout
891 after Timeout 100 ns units. The StartLba and SectorSize parameters are used to
892 construct the CDB for this SCSI command.
893 If ScsiIo is NULL, then ASSERT().
894 If SenseDataLength is NULL, then ASSERT().
895 If HostAdapterStatus is NULL, then ASSERT().
896 If TargetStatus is NULL, then ASSERT().
897 If DataLength is NULL, then ASSERT().
899 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
900 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
903 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
904 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
907 @param[in] ScsiIo A pointer to SCSI IO protocol.
908 @param[in] Timeout The length of timeout period.
909 @param[in, out] SenseData A pointer to output sense data.
910 @param[in, out] SenseDataLength The length of output sense data.
911 @param[out] HostAdapterStatus The status of Host Adapter.
912 @param[out] TargetStatus The status of the target.
913 @param[in, out] DataBuffer Read 10 command data.
914 @param[in, out] DataLength The length of data buffer.
915 @param[in] StartLba The start address of LBA.
916 @param[in] SectorSize The number of contiguous logical blocks of data that shall be transferred.
918 @retval EFI_SUCCESS Command is executed successfully.
919 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could
920 not be transferred. The actual number of bytes transferred is returned in DataLength.
921 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
922 SCSI Command Packets already queued.
923 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
924 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
925 the SCSI initiator(i.e., SCSI Host Controller)
926 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
927 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
933 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
935 IN OUT VOID
*SenseData
, OPTIONAL
936 IN OUT UINT8
*SenseDataLength
,
937 OUT UINT8
*HostAdapterStatus
,
938 OUT UINT8
*TargetStatus
,
939 IN OUT VOID
*DataBuffer
, OPTIONAL
940 IN OUT UINT32
*DataLength
,
945 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
947 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TEN
];
949 ASSERT (SenseDataLength
!= NULL
);
950 ASSERT (HostAdapterStatus
!= NULL
);
951 ASSERT (TargetStatus
!= NULL
);
952 ASSERT (DataLength
!= NULL
);
953 ASSERT (ScsiIo
!= NULL
);
955 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
956 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TEN
);
958 CommandPacket
.Timeout
= Timeout
;
959 CommandPacket
.InDataBuffer
= DataBuffer
;
960 CommandPacket
.SenseData
= SenseData
;
961 CommandPacket
.InTransferLength
= *DataLength
;
962 CommandPacket
.Cdb
= Cdb
;
964 // Fill Cdb for Read (10) Command
966 Cdb
[0] = EFI_SCSI_OP_READ10
;
967 WriteUnaligned32 ((UINT32
*)&Cdb
[2], SwapBytes32 (StartLba
));
968 WriteUnaligned16 ((UINT16
*)&Cdb
[7], SwapBytes16 ((UINT16
) SectorSize
));
970 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
971 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
972 CommandPacket
.SenseDataLength
= *SenseDataLength
;
974 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
976 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
977 *TargetStatus
= CommandPacket
.TargetStatus
;
978 *SenseDataLength
= CommandPacket
.SenseDataLength
;
979 *DataLength
= CommandPacket
.InTransferLength
;
986 Execute Write(10) SCSI command on a specific SCSI target.
988 Executes the SCSI Write(10) command on the SCSI target specified by ScsiIo.
989 If Timeout is zero, then this function waits indefinitely for the command to complete.
990 If Timeout is greater than zero, then the command is executed and will timeout after
991 Timeout 100 ns units. The StartLba and SectorSize parameters are used to construct
992 the CDB for this SCSI command.
993 If ScsiIo is NULL, then ASSERT().
994 If SenseDataLength is NULL, then ASSERT().
995 If HostAdapterStatus is NULL, then ASSERT().
996 If TargetStatus is NULL, then ASSERT().
997 If DataLength is NULL, then ASSERT().
999 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
1000 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1003 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
1004 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1007 @param[in] ScsiIo SCSI IO Protocol to use
1008 @param[in] Timeout The length of timeout period.
1009 @param[in, out] SenseData A pointer to output sense data.
1010 @param[in, out] SenseDataLength The length of output sense data.
1011 @param[out] HostAdapterStatus The status of Host Adapter.
1012 @param[out] TargetStatus The status of the target.
1013 @param[in, out] DataBuffer A pointer to a data buffer.
1014 @param[in, out] DataLength The length of data buffer.
1015 @param[in] StartLba The start address of LBA.
1016 @param[in] SectorSize The number of contiguous logical blocks of data that shall be transferred.
1018 @retval EFI_SUCCESS Command is executed successfully.
1019 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could
1020 not be transferred. The actual number of bytes transferred is returned in DataLength.
1021 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
1022 SCSI Command Packets already queued.
1023 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
1024 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
1025 the SCSI initiator(i.e., SCSI Host Controller)
1026 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
1027 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
1032 ScsiWrite10Command (
1033 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1035 IN OUT VOID
*SenseData
, OPTIONAL
1036 IN OUT UINT8
*SenseDataLength
,
1037 OUT UINT8
*HostAdapterStatus
,
1038 OUT UINT8
*TargetStatus
,
1039 IN OUT VOID
*DataBuffer
, OPTIONAL
1040 IN OUT UINT32
*DataLength
,
1042 IN UINT32 SectorSize
1045 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
1047 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TEN
];
1049 ASSERT (SenseDataLength
!= NULL
);
1050 ASSERT (HostAdapterStatus
!= NULL
);
1051 ASSERT (TargetStatus
!= NULL
);
1052 ASSERT (DataLength
!= NULL
);
1053 ASSERT (ScsiIo
!= NULL
);
1055 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
1056 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TEN
);
1058 CommandPacket
.Timeout
= Timeout
;
1059 CommandPacket
.OutDataBuffer
= DataBuffer
;
1060 CommandPacket
.SenseData
= SenseData
;
1061 CommandPacket
.OutTransferLength
= *DataLength
;
1062 CommandPacket
.Cdb
= Cdb
;
1064 // Fill Cdb for Write (10) Command
1066 Cdb
[0] = EFI_SCSI_OP_WRITE10
;
1067 Cdb
[1] = EFI_SCSI_BLOCK_FUA
;
1068 WriteUnaligned32 ((UINT32
*)&Cdb
[2], SwapBytes32 (StartLba
));
1069 WriteUnaligned16 ((UINT16
*)&Cdb
[7], SwapBytes16 ((UINT16
) SectorSize
));
1071 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
1072 CommandPacket
.DataDirection
= EFI_SCSI_DATA_OUT
;
1073 CommandPacket
.SenseDataLength
= *SenseDataLength
;
1075 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
1077 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
1078 *TargetStatus
= CommandPacket
.TargetStatus
;
1079 *SenseDataLength
= CommandPacket
.SenseDataLength
;
1080 *DataLength
= CommandPacket
.OutTransferLength
;
1086 Execute Read(16) SCSI command on a specific SCSI target.
1088 Executes the SCSI Read(16) command on the SCSI target specified by ScsiIo.
1089 If Timeout is zero, then this function waits indefinitely for the command to complete.
1090 If Timeout is greater than zero, then the command is executed and will timeout
1091 after Timeout 100 ns units. The StartLba and SectorSize parameters are used to
1092 construct the CDB for this SCSI command.
1093 If ScsiIo is NULL, then ASSERT().
1094 If SenseDataLength is NULL, then ASSERT().
1095 If HostAdapterStatus is NULL, then ASSERT().
1096 If TargetStatus is NULL, then ASSERT().
1097 If DataLength is NULL, then ASSERT().
1099 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
1100 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1103 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
1104 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1107 @param[in] ScsiIo A pointer to SCSI IO protocol.
1108 @param[in] Timeout The length of timeout period.
1109 @param[in, out] SenseData A pointer to output sense data.
1110 @param[in, out] SenseDataLength The length of output sense data.
1111 @param[out] HostAdapterStatus The status of Host Adapter.
1112 @param[out] TargetStatus The status of the target.
1113 @param[in, out] DataBuffer Read 16 command data.
1114 @param[in, out] DataLength The length of data buffer.
1115 @param[in] StartLba The start address of LBA.
1116 @param[in] SectorSize The number of contiguous logical blocks of data that shall be transferred.
1118 @retval EFI_SUCCESS Command is executed successfully.
1119 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could
1120 not be transferred. The actual number of bytes transferred is returned in DataLength.
1121 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
1122 SCSI Command Packets already queued.
1123 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
1124 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
1125 the SCSI initiator(i.e., SCSI Host Controller)
1126 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
1127 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
1133 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1135 IN OUT VOID
*SenseData
, OPTIONAL
1136 IN OUT UINT8
*SenseDataLength
,
1137 OUT UINT8
*HostAdapterStatus
,
1138 OUT UINT8
*TargetStatus
,
1139 IN OUT VOID
*DataBuffer
, OPTIONAL
1140 IN OUT UINT32
*DataLength
,
1142 IN UINT32 SectorSize
1145 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
1147 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIXTEEN
];
1149 ASSERT (SenseDataLength
!= NULL
);
1150 ASSERT (HostAdapterStatus
!= NULL
);
1151 ASSERT (TargetStatus
!= NULL
);
1152 ASSERT (DataLength
!= NULL
);
1153 ASSERT (ScsiIo
!= NULL
);
1155 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
1156 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIXTEEN
);
1158 CommandPacket
.Timeout
= Timeout
;
1159 CommandPacket
.InDataBuffer
= DataBuffer
;
1160 CommandPacket
.SenseData
= SenseData
;
1161 CommandPacket
.InTransferLength
= *DataLength
;
1162 CommandPacket
.Cdb
= Cdb
;
1164 // Fill Cdb for Read (16) Command
1166 Cdb
[0] = EFI_SCSI_OP_READ16
;
1167 WriteUnaligned64 ((UINT64
*)&Cdb
[2], SwapBytes64 (StartLba
));
1168 WriteUnaligned32 ((UINT32
*)&Cdb
[10], SwapBytes32 (SectorSize
));
1170 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_SIXTEEN
;
1171 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
1172 CommandPacket
.SenseDataLength
= *SenseDataLength
;
1174 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
1176 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
1177 *TargetStatus
= CommandPacket
.TargetStatus
;
1178 *SenseDataLength
= CommandPacket
.SenseDataLength
;
1179 *DataLength
= CommandPacket
.InTransferLength
;
1186 Execute Write(16) SCSI command on a specific SCSI target.
1188 Executes the SCSI Write(16) command on the SCSI target specified by ScsiIo.
1189 If Timeout is zero, then this function waits indefinitely for the command to complete.
1190 If Timeout is greater than zero, then the command is executed and will timeout after
1191 Timeout 100 ns units. The StartLba and SectorSize parameters are used to construct
1192 the CDB for this SCSI command.
1193 If ScsiIo is NULL, then ASSERT().
1194 If SenseDataLength is NULL, then ASSERT().
1195 If HostAdapterStatus is NULL, then ASSERT().
1196 If TargetStatus is NULL, then ASSERT().
1197 If DataLength is NULL, then ASSERT().
1199 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
1200 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1203 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
1204 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1207 @param[in] ScsiIo SCSI IO Protocol to use
1208 @param[in] Timeout The length of timeout period.
1209 @param[in, out] SenseData A pointer to output sense data.
1210 @param[in, out] SenseDataLength The length of output sense data.
1211 @param[out] HostAdapterStatus The status of Host Adapter.
1212 @param[out] TargetStatus The status of the target.
1213 @param[in, out] DataBuffer A pointer to a data buffer.
1214 @param[in, out] DataLength The length of data buffer.
1215 @param[in] StartLba The start address of LBA.
1216 @param[in] SectorSize The number of contiguous logical blocks of data that shall be transferred.
1218 @retval EFI_SUCCESS Command is executed successfully.
1219 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could
1220 not be transferred. The actual number of bytes transferred is returned in DataLength.
1221 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
1222 SCSI Command Packets already queued.
1223 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
1224 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
1225 the SCSI initiator(i.e., SCSI Host Controller)
1226 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
1227 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
1232 ScsiWrite16Command (
1233 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1235 IN OUT VOID
*SenseData
, OPTIONAL
1236 IN OUT UINT8
*SenseDataLength
,
1237 OUT UINT8
*HostAdapterStatus
,
1238 OUT UINT8
*TargetStatus
,
1239 IN OUT VOID
*DataBuffer
, OPTIONAL
1240 IN OUT UINT32
*DataLength
,
1242 IN UINT32 SectorSize
1245 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
1247 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIXTEEN
];
1249 ASSERT (SenseDataLength
!= NULL
);
1250 ASSERT (HostAdapterStatus
!= NULL
);
1251 ASSERT (TargetStatus
!= NULL
);
1252 ASSERT (DataLength
!= NULL
);
1253 ASSERT (ScsiIo
!= NULL
);
1255 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
1256 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIXTEEN
);
1258 CommandPacket
.Timeout
= Timeout
;
1259 CommandPacket
.OutDataBuffer
= DataBuffer
;
1260 CommandPacket
.SenseData
= SenseData
;
1261 CommandPacket
.OutTransferLength
= *DataLength
;
1262 CommandPacket
.Cdb
= Cdb
;
1264 // Fill Cdb for Write (16) Command
1266 Cdb
[0] = EFI_SCSI_OP_WRITE16
;
1267 Cdb
[1] = EFI_SCSI_BLOCK_FUA
;
1268 WriteUnaligned64 ((UINT64
*)&Cdb
[2], SwapBytes64 (StartLba
));
1269 WriteUnaligned32 ((UINT32
*)&Cdb
[10], SwapBytes32 (SectorSize
));
1271 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_SIXTEEN
;
1272 CommandPacket
.DataDirection
= EFI_SCSI_DATA_OUT
;
1273 CommandPacket
.SenseDataLength
= *SenseDataLength
;
1275 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
1277 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
1278 *TargetStatus
= CommandPacket
.TargetStatus
;
1279 *SenseDataLength
= CommandPacket
.SenseDataLength
;
1280 *DataLength
= CommandPacket
.OutTransferLength
;
1287 Execute Security Protocol In SCSI command on a specific SCSI target.
1289 Executes the SCSI Security Protocol In command on the SCSI target specified by ScsiIo.
1290 If Timeout is zero, then this function waits indefinitely for the command to complete.
1291 If Timeout is greater than zero, then the command is executed and will timeout after
1292 Timeout 100 ns units.
1293 If ScsiIo is NULL, then ASSERT().
1294 If SenseDataLength is NULL, then ASSERT().
1295 If HostAdapterStatus is NULL, then ASSERT().
1296 If TargetStatus is NULL, then ASSERT().
1297 If TransferLength is NULL, then ASSERT().
1299 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
1300 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1303 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
1304 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1307 @param[in] ScsiIo SCSI IO Protocol to use.
1308 @param[in] Timeout The length of timeout period.
1309 @param[in, out] SenseData A pointer to output sense data.
1310 @param[in, out] SenseDataLength The length of output sense data.
1311 @param[out] HostAdapterStatus The status of Host Adapter.
1312 @param[out] TargetStatus The status of the target.
1313 @param[in] SecurityProtocol The Security Protocol to use.
1314 @param[in] SecurityProtocolSpecific The Security Protocol Specific data.
1315 @param[in] Inc512 If TRUE, 512 increment (INC_512) bit will be set for the
1316 SECURITY PROTOCOL IN command.
1317 @param[in] DataLength The size in bytes of the data buffer.
1318 @param[in, out] DataBuffer A pointer to a data buffer.
1319 @param[out] TransferLength A pointer to a buffer to store the size in
1320 bytes of the data written to the data buffer.
1322 @retval EFI_SUCCESS Command is executed successfully.
1323 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could
1324 not be transferred. The actual number of bytes transferred is returned in TransferLength.
1325 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
1326 SCSI Command Packets already queued.
1327 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
1328 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
1329 the SCSI initiator(i.e., SCSI Host Controller)
1330 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
1331 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
1336 ScsiSecurityProtocolInCommand (
1337 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1339 IN OUT VOID
*SenseData
, OPTIONAL
1340 IN OUT UINT8
*SenseDataLength
,
1341 OUT UINT8
*HostAdapterStatus
,
1342 OUT UINT8
*TargetStatus
,
1343 IN UINT8 SecurityProtocol
,
1344 IN UINT16 SecurityProtocolSpecific
,
1346 IN UINTN DataLength
,
1347 IN OUT VOID
*DataBuffer
, OPTIONAL
1348 OUT UINTN
*TransferLength
1351 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
1353 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TWELVE
];
1355 ASSERT (SenseDataLength
!= NULL
);
1356 ASSERT (HostAdapterStatus
!= NULL
);
1357 ASSERT (TargetStatus
!= NULL
);
1358 ASSERT (ScsiIo
!= NULL
);
1359 ASSERT (TransferLength
!= NULL
);
1360 ASSERT (DataLength
<= MAX_UINT32
);
1362 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
1363 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TWELVE
);
1365 CommandPacket
.Timeout
= Timeout
;
1366 CommandPacket
.InDataBuffer
= DataBuffer
;
1367 CommandPacket
.SenseData
= SenseData
;
1368 CommandPacket
.InTransferLength
= (UINT32
) DataLength
;
1369 CommandPacket
.Cdb
= Cdb
;
1371 // Fill Cdb for Security Protocol In Command
1373 Cdb
[0] = EFI_SCSI_OP_SECURITY_PROTOCOL_IN
;
1374 Cdb
[1] = SecurityProtocol
;
1375 WriteUnaligned16 ((UINT16
*)&Cdb
[2], SwapBytes16 (SecurityProtocolSpecific
));
1378 if (DataLength
% 512 != 0) {
1379 return EFI_INVALID_PARAMETER
;
1382 WriteUnaligned32 ((UINT32
*)&Cdb
[6], SwapBytes32 ((UINT32
) DataLength
/ 512));
1384 WriteUnaligned32 ((UINT32
*)&Cdb
[6], SwapBytes32 ((UINT32
) DataLength
));
1387 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TWELVE
;
1388 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
1389 CommandPacket
.SenseDataLength
= *SenseDataLength
;
1391 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
1393 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
1394 *TargetStatus
= CommandPacket
.TargetStatus
;
1395 *SenseDataLength
= CommandPacket
.SenseDataLength
;
1396 *TransferLength
= (UINTN
) CommandPacket
.InTransferLength
;
1403 Execute Security Protocol Out SCSI command on a specific SCSI target.
1405 Executes the SCSI Security Protocol Out command on the SCSI target specified by ScsiIo.
1406 If Timeout is zero, then this function waits indefinitely for the command to complete.
1407 If Timeout is greater than zero, then the command is executed and will timeout after
1408 Timeout 100 ns units.
1409 If ScsiIo is NULL, then ASSERT().
1410 If SenseDataLength is NULL, then ASSERT().
1411 If HostAdapterStatus is NULL, then ASSERT().
1412 If TargetStatus is NULL, then ASSERT().
1414 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
1415 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1418 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
1419 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1422 @param[in] ScsiIo SCSI IO Protocol to use.
1423 @param[in] Timeout The length of timeout period.
1424 @param[in, out] SenseData A pointer to output sense data.
1425 @param[in, out] SenseDataLength The length of output sense data.
1426 @param[out] HostAdapterStatus The status of Host Adapter.
1427 @param[out] TargetStatus The status of the target.
1428 @param[in] SecurityProtocol The Security Protocol to use.
1429 @param[in] SecurityProtocolSpecific The Security Protocol Specific data.
1430 @param[in] Inc512 If TRUE, 512 increment (INC_512) bit will be set for the
1431 SECURITY PROTOCOL OUT command.
1432 @param[in] DataLength The size in bytes of the transfer data.
1433 @param[in, out] DataBuffer A pointer to a data buffer.
1435 @retval EFI_SUCCESS Command is executed successfully.
1436 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could
1437 not be transferred. The actual number of bytes transferred is returned in DataLength.
1438 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
1439 SCSI Command Packets already queued.
1440 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
1441 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
1442 the SCSI initiator(i.e., SCSI Host Controller)
1443 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
1444 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
1449 ScsiSecurityProtocolOutCommand (
1450 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1452 IN OUT VOID
*SenseData
, OPTIONAL
1453 IN OUT UINT8
*SenseDataLength
,
1454 OUT UINT8
*HostAdapterStatus
,
1455 OUT UINT8
*TargetStatus
,
1456 IN UINT8 SecurityProtocol
,
1457 IN UINT16 SecurityProtocolSpecific
,
1459 IN UINTN DataLength
,
1460 IN OUT VOID
*DataBuffer OPTIONAL
1463 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
1465 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TWELVE
];
1467 ASSERT (SenseDataLength
!= NULL
);
1468 ASSERT (HostAdapterStatus
!= NULL
);
1469 ASSERT (TargetStatus
!= NULL
);
1470 ASSERT (ScsiIo
!= NULL
);
1471 ASSERT (DataLength
<= MAX_UINT32
);
1473 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
1474 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TWELVE
);
1476 CommandPacket
.Timeout
= Timeout
;
1477 CommandPacket
.OutDataBuffer
= DataBuffer
;
1478 CommandPacket
.SenseData
= SenseData
;
1479 CommandPacket
.OutTransferLength
= (UINT32
) DataLength
;
1480 CommandPacket
.Cdb
= Cdb
;
1482 // Fill Cdb for Security Protocol Out Command
1484 Cdb
[0] = EFI_SCSI_OP_SECURITY_PROTOCOL_OUT
;
1485 Cdb
[1] = SecurityProtocol
;
1486 WriteUnaligned16 ((UINT16
*)&Cdb
[2], SwapBytes16 (SecurityProtocolSpecific
));
1489 if (DataLength
% 512 != 0) {
1490 return EFI_INVALID_PARAMETER
;
1493 WriteUnaligned32 ((UINT32
*)&Cdb
[6], SwapBytes32 ((UINT32
) DataLength
/ 512));
1495 WriteUnaligned32 ((UINT32
*)&Cdb
[6], SwapBytes32 ((UINT32
) DataLength
));
1498 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TWELVE
;
1499 CommandPacket
.DataDirection
= EFI_SCSI_DATA_OUT
;
1500 CommandPacket
.SenseDataLength
= *SenseDataLength
;
1502 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
1504 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
1505 *TargetStatus
= CommandPacket
.TargetStatus
;
1506 *SenseDataLength
= CommandPacket
.SenseDataLength
;
1513 Internal helper notify function in which update the result of the
1514 non-blocking SCSI Read/Write commands and signal caller event.
1516 @param Event The instance of EFI_EVENT.
1517 @param Context The parameter passed in.
1527 EFI_SCSI_LIB_ASYNC_CONTEXT
*LibContext
;
1528 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
1529 EFI_EVENT CallerEvent
;
1531 LibContext
= (EFI_SCSI_LIB_ASYNC_CONTEXT
*) Context
;
1532 CommandPacket
= &LibContext
->CommandPacket
;
1533 CallerEvent
= LibContext
->CallerEvent
;
1536 // Update SCSI Read/Write operation results
1538 *LibContext
->SenseDataLength
= CommandPacket
->SenseDataLength
;
1539 *LibContext
->HostAdapterStatus
= CommandPacket
->HostAdapterStatus
;
1540 *LibContext
->TargetStatus
= CommandPacket
->TargetStatus
;
1541 if (CommandPacket
->InDataBuffer
!= NULL
) {
1542 *LibContext
->DataLength
= CommandPacket
->InTransferLength
;
1544 *LibContext
->DataLength
= CommandPacket
->OutTransferLength
;
1547 if (CommandPacket
->Cdb
!= NULL
) {
1548 FreePool (CommandPacket
->Cdb
);
1552 gBS
->CloseEvent (Event
);
1553 gBS
->SignalEvent (CallerEvent
);
1558 Execute blocking/non-blocking Read(10) SCSI command on a specific SCSI
1561 Executes the SCSI Read(10) command on the SCSI target specified by ScsiIo.
1562 When Event is NULL, blocking command will be executed. Otherwise non-blocking
1563 command will be executed.
1564 For blocking I/O, if Timeout is zero, this function will wait indefinitely
1565 for the command to complete. If Timeout is greater than zero, then the
1566 command is executed and will timeout after Timeout 100 ns units.
1567 For non-blocking I/O, if Timeout is zero, Event will be signaled only after
1568 the command to completes. If Timeout is greater than zero, Event will also be
1569 signaled after Timeout 100 ns units.
1570 The StartLba and SectorSize parameters are used to construct the CDB for this
1573 If ScsiIo is NULL, then ASSERT().
1574 If SenseDataLength is NULL, then ASSERT().
1575 If HostAdapterStatus is NULL, then ASSERT().
1576 If TargetStatus is NULL, then ASSERT().
1577 If DataLength is NULL, then ASSERT().
1579 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet
1580 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1581 EFI_INVALID_PARAMETER gets returned.
1583 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet
1584 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1585 EFI_INVALID_PARAMETER gets returned.
1587 @param[in] ScsiIo A pointer to SCSI IO protocol.
1588 @param[in] Timeout The length of timeout period.
1589 @param[in, out] SenseData A pointer to output sense data.
1590 @param[in, out] SenseDataLength The length of output sense data.
1591 @param[out] HostAdapterStatus The status of Host Adapter.
1592 @param[out] TargetStatus The status of the target.
1593 @param[in, out] DataBuffer Read 16 command data.
1594 @param[in, out] DataLength The length of data buffer.
1595 @param[in] StartLba The start address of LBA.
1596 @param[in] SectorSize The number of contiguous logical blocks
1597 of data that shall be transferred.
1598 @param[in] Event If the SCSI target does not support
1599 non-blocking I/O, then Event is ignored,
1600 and blocking I/O is performed. If Event
1601 is NULL, then blocking I/O is performed.
1602 If Event is not NULL and non-blocking
1603 I/O is supported, then non-blocking I/O
1604 is performed, and Event will be signaled
1605 when the SCSI Read(10) command
1608 @retval EFI_SUCCESS Command is executed successfully.
1609 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
1610 but the entire DataBuffer could not be
1611 transferred. The actual number of bytes
1612 transferred is returned in DataLength.
1613 @retval EFI_NOT_READY The SCSI Request Packet could not be
1614 sent because there are too many SCSI
1615 Command Packets already queued.
1616 @retval EFI_DEVICE_ERROR A device error occurred while attempting
1617 to send SCSI Request Packet.
1618 @retval EFI_UNSUPPORTED The command described by the SCSI
1619 Request Packet is not supported by the
1620 SCSI initiator(i.e., SCSI Host
1622 @retval EFI_TIMEOUT A timeout occurred while waiting for the
1623 SCSI Request Packet to execute.
1624 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet
1626 @retval EFI_OUT_OF_RESOURCES The request could not be completed due
1627 to a lack of resources.
1632 ScsiRead10CommandEx (
1633 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1635 IN OUT VOID
*SenseData
, OPTIONAL
1636 IN OUT UINT8
*SenseDataLength
,
1637 OUT UINT8
*HostAdapterStatus
,
1638 OUT UINT8
*TargetStatus
,
1639 IN OUT VOID
*DataBuffer
, OPTIONAL
1640 IN OUT UINT32
*DataLength
,
1642 IN UINT32 SectorSize
,
1643 IN EFI_EVENT Event OPTIONAL
1646 EFI_SCSI_LIB_ASYNC_CONTEXT
*Context
;
1647 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
1650 EFI_EVENT SelfEvent
;
1652 if (Event
== NULL
) {
1653 return ScsiRead10Command (
1667 ASSERT (SenseDataLength
!= NULL
);
1668 ASSERT (HostAdapterStatus
!= NULL
);
1669 ASSERT (TargetStatus
!= NULL
);
1670 ASSERT (DataLength
!= NULL
);
1671 ASSERT (ScsiIo
!= NULL
);
1673 Context
= AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT
));
1674 if (Context
== NULL
) {
1675 return EFI_OUT_OF_RESOURCES
;
1678 Cdb
= AllocateZeroPool (EFI_SCSI_OP_LENGTH_TEN
);
1680 Status
= EFI_OUT_OF_RESOURCES
;
1684 Context
->SenseDataLength
= SenseDataLength
;
1685 Context
->HostAdapterStatus
= HostAdapterStatus
;
1686 Context
->TargetStatus
= TargetStatus
;
1687 Context
->CallerEvent
= Event
;
1689 CommandPacket
= &Context
->CommandPacket
;
1690 CommandPacket
->Timeout
= Timeout
;
1691 CommandPacket
->InDataBuffer
= DataBuffer
;
1692 CommandPacket
->SenseData
= SenseData
;
1693 CommandPacket
->InTransferLength
= *DataLength
;
1694 CommandPacket
->Cdb
= Cdb
;
1696 // Fill Cdb for Read (10) Command
1698 Cdb
[0] = EFI_SCSI_OP_READ10
;
1699 WriteUnaligned32 ((UINT32
*)&Cdb
[2], SwapBytes32 (StartLba
));
1700 WriteUnaligned16 ((UINT16
*)&Cdb
[7], SwapBytes16 ((UINT16
) SectorSize
));
1702 CommandPacket
->CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
1703 CommandPacket
->DataDirection
= EFI_SCSI_DATA_IN
;
1704 CommandPacket
->SenseDataLength
= *SenseDataLength
;
1709 Status
= gBS
->CreateEvent (
1716 if (EFI_ERROR(Status
)) {
1720 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, CommandPacket
, SelfEvent
);
1721 if (EFI_ERROR(Status
)) {
1723 // Since ScsiLibNotify() will not be signaled if ExecuteScsiCommand()
1724 // returns with error, close the event here.
1726 gBS
->CloseEvent (SelfEvent
);
1733 if (Context
!= NULL
) {
1742 Execute blocking/non-blocking Write(10) SCSI command on a specific SCSI
1745 Executes the SCSI Write(10) command on the SCSI target specified by ScsiIo.
1746 When Event is NULL, blocking command will be executed. Otherwise non-blocking
1747 command will be executed.
1748 For blocking I/O, if Timeout is zero, this function will wait indefinitely
1749 for the command to complete. If Timeout is greater than zero, then the
1750 command is executed and will timeout after Timeout 100 ns units.
1751 For non-blocking I/O, if Timeout is zero, Event will be signaled only after
1752 the command to completes. If Timeout is greater than zero, Event will also be
1753 signaled after Timeout 100 ns units.
1754 The StartLba and SectorSize parameters are used to construct the CDB for this
1757 If ScsiIo is NULL, then ASSERT().
1758 If SenseDataLength is NULL, then ASSERT().
1759 If HostAdapterStatus is NULL, then ASSERT().
1760 If TargetStatus is NULL, then ASSERT().
1761 If DataLength is NULL, then ASSERT().
1763 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet
1764 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1765 EFI_INVALID_PARAMETER gets returned.
1767 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet
1768 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1769 EFI_INVALID_PARAMETER gets returned.
1771 @param[in] ScsiIo SCSI IO Protocol to use
1772 @param[in] Timeout The length of timeout period.
1773 @param[in, out] SenseData A pointer to output sense data.
1774 @param[in, out] SenseDataLength The length of output sense data.
1775 @param[out] HostAdapterStatus The status of Host Adapter.
1776 @param[out] TargetStatus The status of the target.
1777 @param[in, out] DataBuffer A pointer to a data buffer.
1778 @param[in, out] DataLength The length of data buffer.
1779 @param[in] StartLba The start address of LBA.
1780 @param[in] SectorSize The number of contiguous logical blocks
1781 of data that shall be transferred.
1782 @param[in] Event If the SCSI target does not support
1783 non-blocking I/O, then Event is ignored,
1784 and blocking I/O is performed. If Event
1785 is NULL, then blocking I/O is performed.
1786 If Event is not NULL and non-blocking
1787 I/O is supported, then non-blocking I/O
1788 is performed, and Event will be signaled
1789 when the SCSI Write(10) command
1792 @retval EFI_SUCCESS Command is executed successfully.
1793 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
1794 but the entire DataBuffer could not be
1795 transferred. The actual number of bytes
1796 transferred is returned in DataLength.
1797 @retval EFI_NOT_READY The SCSI Request Packet could not be
1798 sent because there are too many SCSI
1799 Command Packets already queued.
1800 @retval EFI_DEVICE_ERROR A device error occurred while attempting
1801 to send SCSI Request Packet.
1802 @retval EFI_UNSUPPORTED The command described by the SCSI
1803 Request Packet is not supported by the
1804 SCSI initiator(i.e., SCSI Host
1806 @retval EFI_TIMEOUT A timeout occurred while waiting for the
1807 SCSI Request Packet to execute.
1808 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet
1810 @retval EFI_OUT_OF_RESOURCES The request could not be completed due
1811 to a lack of resources.
1816 ScsiWrite10CommandEx (
1817 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1819 IN OUT VOID
*SenseData
, OPTIONAL
1820 IN OUT UINT8
*SenseDataLength
,
1821 OUT UINT8
*HostAdapterStatus
,
1822 OUT UINT8
*TargetStatus
,
1823 IN OUT VOID
*DataBuffer
, OPTIONAL
1824 IN OUT UINT32
*DataLength
,
1826 IN UINT32 SectorSize
,
1827 IN EFI_EVENT Event OPTIONAL
1830 EFI_SCSI_LIB_ASYNC_CONTEXT
*Context
;
1831 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
1834 EFI_EVENT SelfEvent
;
1836 if (Event
== NULL
) {
1837 return ScsiWrite10Command (
1851 ASSERT (SenseDataLength
!= NULL
);
1852 ASSERT (HostAdapterStatus
!= NULL
);
1853 ASSERT (TargetStatus
!= NULL
);
1854 ASSERT (DataLength
!= NULL
);
1855 ASSERT (ScsiIo
!= NULL
);
1857 Context
= AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT
));
1858 if (Context
== NULL
) {
1859 return EFI_OUT_OF_RESOURCES
;
1862 Cdb
= AllocateZeroPool (EFI_SCSI_OP_LENGTH_TEN
);
1864 Status
= EFI_OUT_OF_RESOURCES
;
1868 Context
->SenseDataLength
= SenseDataLength
;
1869 Context
->HostAdapterStatus
= HostAdapterStatus
;
1870 Context
->TargetStatus
= TargetStatus
;
1871 Context
->CallerEvent
= Event
;
1873 CommandPacket
= &Context
->CommandPacket
;
1874 CommandPacket
->Timeout
= Timeout
;
1875 CommandPacket
->OutDataBuffer
= DataBuffer
;
1876 CommandPacket
->SenseData
= SenseData
;
1877 CommandPacket
->OutTransferLength
= *DataLength
;
1878 CommandPacket
->Cdb
= Cdb
;
1880 // Fill Cdb for Write (10) Command
1882 Cdb
[0] = EFI_SCSI_OP_WRITE10
;
1883 WriteUnaligned32 ((UINT32
*)&Cdb
[2], SwapBytes32 (StartLba
));
1884 WriteUnaligned16 ((UINT16
*)&Cdb
[7], SwapBytes16 ((UINT16
) SectorSize
));
1886 CommandPacket
->CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
1887 CommandPacket
->DataDirection
= EFI_SCSI_DATA_OUT
;
1888 CommandPacket
->SenseDataLength
= *SenseDataLength
;
1893 Status
= gBS
->CreateEvent (
1900 if (EFI_ERROR(Status
)) {
1904 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, CommandPacket
, SelfEvent
);
1905 if (EFI_ERROR(Status
)) {
1907 // Since ScsiLibNotify() will not be signaled if ExecuteScsiCommand()
1908 // returns with error, close the event here.
1910 gBS
->CloseEvent (SelfEvent
);
1917 if (Context
!= NULL
) {
1926 Execute blocking/non-blocking Read(16) SCSI command on a specific SCSI
1929 Executes the SCSI Read(16) command on the SCSI target specified by ScsiIo.
1930 When Event is NULL, blocking command will be executed. Otherwise non-blocking
1931 command will be executed.
1932 For blocking I/O, if Timeout is zero, this function will wait indefinitely
1933 for the command to complete. If Timeout is greater than zero, then the
1934 command is executed and will timeout after Timeout 100 ns units.
1935 For non-blocking I/O, if Timeout is zero, Event will be signaled only after
1936 the command to completes. If Timeout is greater than zero, Event will also be
1937 signaled after Timeout 100 ns units.
1938 The StartLba and SectorSize parameters are used to construct the CDB for this
1941 If ScsiIo is NULL, then ASSERT().
1942 If SenseDataLength is NULL, then ASSERT().
1943 If HostAdapterStatus is NULL, then ASSERT().
1944 If TargetStatus is NULL, then ASSERT().
1945 If DataLength is NULL, then ASSERT().
1947 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet
1948 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1949 EFI_INVALID_PARAMETER gets returned.
1951 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet
1952 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1953 EFI_INVALID_PARAMETER gets returned.
1955 @param[in] ScsiIo A pointer to SCSI IO protocol.
1956 @param[in] Timeout The length of timeout period.
1957 @param[in, out] SenseData A pointer to output sense data.
1958 @param[in, out] SenseDataLength The length of output sense data.
1959 @param[out] HostAdapterStatus The status of Host Adapter.
1960 @param[out] TargetStatus The status of the target.
1961 @param[in, out] DataBuffer Read 16 command data.
1962 @param[in, out] DataLength The length of data buffer.
1963 @param[in] StartLba The start address of LBA.
1964 @param[in] SectorSize The number of contiguous logical blocks
1965 of data that shall be transferred.
1966 @param[in] Event If the SCSI target does not support
1967 non-blocking I/O, then Event is ignored,
1968 and blocking I/O is performed. If Event
1969 is NULL, then blocking I/O is performed.
1970 If Event is not NULL and non-blocking
1971 I/O is supported, then non-blocking I/O
1972 is performed, and Event will be signaled
1973 when the SCSI Read(16) command
1976 @retval EFI_SUCCESS Command is executed successfully.
1977 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
1978 but the entire DataBuffer could not be
1979 transferred. The actual number of bytes
1980 transferred is returned in DataLength.
1981 @retval EFI_NOT_READY The SCSI Request Packet could not be
1982 sent because there are too many SCSI
1983 Command Packets already queued.
1984 @retval EFI_DEVICE_ERROR A device error occurred while attempting
1985 to send SCSI Request Packet.
1986 @retval EFI_UNSUPPORTED The command described by the SCSI
1987 Request Packet is not supported by the
1988 SCSI initiator(i.e., SCSI Host
1990 @retval EFI_TIMEOUT A timeout occurred while waiting for the
1991 SCSI Request Packet to execute.
1992 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet
1994 @retval EFI_OUT_OF_RESOURCES The request could not be completed due
1995 to a lack of resources.
2000 ScsiRead16CommandEx (
2001 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
2003 IN OUT VOID
*SenseData
, OPTIONAL
2004 IN OUT UINT8
*SenseDataLength
,
2005 OUT UINT8
*HostAdapterStatus
,
2006 OUT UINT8
*TargetStatus
,
2007 IN OUT VOID
*DataBuffer
, OPTIONAL
2008 IN OUT UINT32
*DataLength
,
2010 IN UINT32 SectorSize
,
2011 IN EFI_EVENT Event OPTIONAL
2014 EFI_SCSI_LIB_ASYNC_CONTEXT
*Context
;
2015 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
2018 EFI_EVENT SelfEvent
;
2020 if (Event
== NULL
) {
2021 return ScsiRead16Command (
2035 ASSERT (SenseDataLength
!= NULL
);
2036 ASSERT (HostAdapterStatus
!= NULL
);
2037 ASSERT (TargetStatus
!= NULL
);
2038 ASSERT (DataLength
!= NULL
);
2039 ASSERT (ScsiIo
!= NULL
);
2041 Context
= AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT
));
2042 if (Context
== NULL
) {
2043 return EFI_OUT_OF_RESOURCES
;
2046 Cdb
= AllocateZeroPool (EFI_SCSI_OP_LENGTH_SIXTEEN
);
2048 Status
= EFI_OUT_OF_RESOURCES
;
2052 Context
->SenseDataLength
= SenseDataLength
;
2053 Context
->HostAdapterStatus
= HostAdapterStatus
;
2054 Context
->TargetStatus
= TargetStatus
;
2055 Context
->CallerEvent
= Event
;
2057 CommandPacket
= &Context
->CommandPacket
;
2058 CommandPacket
->Timeout
= Timeout
;
2059 CommandPacket
->InDataBuffer
= DataBuffer
;
2060 CommandPacket
->SenseData
= SenseData
;
2061 CommandPacket
->InTransferLength
= *DataLength
;
2062 CommandPacket
->Cdb
= Cdb
;
2064 // Fill Cdb for Read (16) Command
2066 Cdb
[0] = EFI_SCSI_OP_READ16
;
2067 WriteUnaligned64 ((UINT64
*)&Cdb
[2], SwapBytes64 (StartLba
));
2068 WriteUnaligned32 ((UINT32
*)&Cdb
[10], SwapBytes32 (SectorSize
));
2070 CommandPacket
->CdbLength
= EFI_SCSI_OP_LENGTH_SIXTEEN
;
2071 CommandPacket
->DataDirection
= EFI_SCSI_DATA_IN
;
2072 CommandPacket
->SenseDataLength
= *SenseDataLength
;
2077 Status
= gBS
->CreateEvent (
2084 if (EFI_ERROR(Status
)) {
2088 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, CommandPacket
, SelfEvent
);
2089 if (EFI_ERROR(Status
)) {
2091 // Since ScsiLibNotify() will not be signaled if ExecuteScsiCommand()
2092 // returns with error, close the event here.
2094 gBS
->CloseEvent (SelfEvent
);
2101 if (Context
!= NULL
) {
2110 Execute blocking/non-blocking Write(16) SCSI command on a specific SCSI
2113 Executes the SCSI Write(16) command on the SCSI target specified by ScsiIo.
2114 When Event is NULL, blocking command will be executed. Otherwise non-blocking
2115 command will be executed.
2116 For blocking I/O, if Timeout is zero, this function will wait indefinitely
2117 for the command to complete. If Timeout is greater than zero, then the
2118 command is executed and will timeout after Timeout 100 ns units.
2119 For non-blocking I/O, if Timeout is zero, Event will be signaled only after
2120 the command to completes. If Timeout is greater than zero, Event will also be
2121 signaled after Timeout 100 ns units.
2122 The StartLba and SectorSize parameters are used to construct the CDB for this
2125 If ScsiIo is NULL, then ASSERT().
2126 If SenseDataLength is NULL, then ASSERT().
2127 If HostAdapterStatus is NULL, then ASSERT().
2128 If TargetStatus is NULL, then ASSERT().
2129 If DataLength is NULL, then ASSERT().
2131 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet
2132 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
2133 EFI_INVALID_PARAMETER gets returned.
2135 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet
2136 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
2137 EFI_INVALID_PARAMETER gets returned.
2139 @param[in] ScsiIo SCSI IO Protocol to use
2140 @param[in] Timeout The length of timeout period.
2141 @param[in, out] SenseData A pointer to output sense data.
2142 @param[in, out] SenseDataLength The length of output sense data.
2143 @param[out] HostAdapterStatus The status of Host Adapter.
2144 @param[out] TargetStatus The status of the target.
2145 @param[in, out] DataBuffer A pointer to a data buffer.
2146 @param[in, out] DataLength The length of data buffer.
2147 @param[in] StartLba The start address of LBA.
2148 @param[in] SectorSize The number of contiguous logical blocks
2149 of data that shall be transferred.
2150 @param[in] Event If the SCSI target does not support
2151 non-blocking I/O, then Event is ignored,
2152 and blocking I/O is performed. If Event
2153 is NULL, then blocking I/O is performed.
2154 If Event is not NULL and non-blocking
2155 I/O is supported, then non-blocking I/O
2156 is performed, and Event will be signaled
2157 when the SCSI Write(16) command
2160 @retval EFI_SUCCESS Command is executed successfully.
2161 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
2162 but the entire DataBuffer could not be
2163 transferred. The actual number of bytes
2164 transferred is returned in DataLength.
2165 @retval EFI_NOT_READY The SCSI Request Packet could not be
2166 sent because there are too many SCSI
2167 Command Packets already queued.
2168 @retval EFI_DEVICE_ERROR A device error occurred while attempting
2169 to send SCSI Request Packet.
2170 @retval EFI_UNSUPPORTED The command described by the SCSI
2171 Request Packet is not supported by the
2172 SCSI initiator(i.e., SCSI Host
2174 @retval EFI_TIMEOUT A timeout occurred while waiting for the
2175 SCSI Request Packet to execute.
2176 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet
2178 @retval EFI_OUT_OF_RESOURCES The request could not be completed due
2179 to a lack of resources.
2184 ScsiWrite16CommandEx (
2185 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
2187 IN OUT VOID
*SenseData
, OPTIONAL
2188 IN OUT UINT8
*SenseDataLength
,
2189 OUT UINT8
*HostAdapterStatus
,
2190 OUT UINT8
*TargetStatus
,
2191 IN OUT VOID
*DataBuffer
, OPTIONAL
2192 IN OUT UINT32
*DataLength
,
2194 IN UINT32 SectorSize
,
2195 IN EFI_EVENT Event OPTIONAL
2198 EFI_SCSI_LIB_ASYNC_CONTEXT
*Context
;
2199 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
2202 EFI_EVENT SelfEvent
;
2204 if (Event
== NULL
) {
2205 return ScsiWrite16Command (
2219 ASSERT (SenseDataLength
!= NULL
);
2220 ASSERT (HostAdapterStatus
!= NULL
);
2221 ASSERT (TargetStatus
!= NULL
);
2222 ASSERT (DataLength
!= NULL
);
2223 ASSERT (ScsiIo
!= NULL
);
2225 Context
= AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT
));
2226 if (Context
== NULL
) {
2227 return EFI_OUT_OF_RESOURCES
;
2230 Cdb
= AllocateZeroPool (EFI_SCSI_OP_LENGTH_SIXTEEN
);
2232 Status
= EFI_OUT_OF_RESOURCES
;
2236 Context
->SenseDataLength
= SenseDataLength
;
2237 Context
->HostAdapterStatus
= HostAdapterStatus
;
2238 Context
->TargetStatus
= TargetStatus
;
2239 Context
->CallerEvent
= Event
;
2241 CommandPacket
= &Context
->CommandPacket
;
2242 CommandPacket
->Timeout
= Timeout
;
2243 CommandPacket
->OutDataBuffer
= DataBuffer
;
2244 CommandPacket
->SenseData
= SenseData
;
2245 CommandPacket
->OutTransferLength
= *DataLength
;
2246 CommandPacket
->Cdb
= Cdb
;
2248 // Fill Cdb for Write (16) Command
2250 Cdb
[0] = EFI_SCSI_OP_WRITE16
;
2251 WriteUnaligned64 ((UINT64
*)&Cdb
[2], SwapBytes64 (StartLba
));
2252 WriteUnaligned32 ((UINT32
*)&Cdb
[10], SwapBytes32 (SectorSize
));
2254 CommandPacket
->CdbLength
= EFI_SCSI_OP_LENGTH_SIXTEEN
;
2255 CommandPacket
->DataDirection
= EFI_SCSI_DATA_OUT
;
2256 CommandPacket
->SenseDataLength
= *SenseDataLength
;
2261 Status
= gBS
->CreateEvent (
2268 if (EFI_ERROR(Status
)) {
2272 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, CommandPacket
, SelfEvent
);
2273 if (EFI_ERROR(Status
)) {
2275 // Since ScsiLibNotify() will not be signaled if ExecuteScsiCommand()
2276 // returns with error, close the event here.
2278 gBS
->CloseEvent (SelfEvent
);
2285 if (Context
!= NULL
) {