2 UEFI SCSI Library implementation
4 Copyright (c) 2006 - 2019, 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 WriteUnaligned32 ((UINT32
*)&Cdb
[2], SwapBytes32 (StartLba
));
1068 WriteUnaligned16 ((UINT16
*)&Cdb
[7], SwapBytes16 ((UINT16
) SectorSize
));
1070 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
1071 CommandPacket
.DataDirection
= EFI_SCSI_DATA_OUT
;
1072 CommandPacket
.SenseDataLength
= *SenseDataLength
;
1074 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
1076 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
1077 *TargetStatus
= CommandPacket
.TargetStatus
;
1078 *SenseDataLength
= CommandPacket
.SenseDataLength
;
1079 *DataLength
= CommandPacket
.OutTransferLength
;
1085 Execute Read(16) SCSI command on a specific SCSI target.
1087 Executes the SCSI Read(16) command on the SCSI target specified by ScsiIo.
1088 If Timeout is zero, then this function waits indefinitely for the command to complete.
1089 If Timeout is greater than zero, then the command is executed and will timeout
1090 after Timeout 100 ns units. The StartLba and SectorSize parameters are used to
1091 construct the CDB for this SCSI command.
1092 If ScsiIo is NULL, then ASSERT().
1093 If SenseDataLength is NULL, then ASSERT().
1094 If HostAdapterStatus is NULL, then ASSERT().
1095 If TargetStatus is NULL, then ASSERT().
1096 If DataLength is NULL, then ASSERT().
1098 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
1099 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1102 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
1103 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1106 @param[in] ScsiIo A pointer to SCSI IO protocol.
1107 @param[in] Timeout The length of timeout period.
1108 @param[in, out] SenseData A pointer to output sense data.
1109 @param[in, out] SenseDataLength The length of output sense data.
1110 @param[out] HostAdapterStatus The status of Host Adapter.
1111 @param[out] TargetStatus The status of the target.
1112 @param[in, out] DataBuffer Read 16 command data.
1113 @param[in, out] DataLength The length of data buffer.
1114 @param[in] StartLba The start address of LBA.
1115 @param[in] SectorSize The number of contiguous logical blocks of data that shall be transferred.
1117 @retval EFI_SUCCESS Command is executed successfully.
1118 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could
1119 not be transferred. The actual number of bytes transferred is returned in DataLength.
1120 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
1121 SCSI Command Packets already queued.
1122 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
1123 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
1124 the SCSI initiator(i.e., SCSI Host Controller)
1125 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
1126 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
1132 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1134 IN OUT VOID
*SenseData
, OPTIONAL
1135 IN OUT UINT8
*SenseDataLength
,
1136 OUT UINT8
*HostAdapterStatus
,
1137 OUT UINT8
*TargetStatus
,
1138 IN OUT VOID
*DataBuffer
, OPTIONAL
1139 IN OUT UINT32
*DataLength
,
1141 IN UINT32 SectorSize
1144 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
1146 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIXTEEN
];
1148 ASSERT (SenseDataLength
!= NULL
);
1149 ASSERT (HostAdapterStatus
!= NULL
);
1150 ASSERT (TargetStatus
!= NULL
);
1151 ASSERT (DataLength
!= NULL
);
1152 ASSERT (ScsiIo
!= NULL
);
1154 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
1155 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIXTEEN
);
1157 CommandPacket
.Timeout
= Timeout
;
1158 CommandPacket
.InDataBuffer
= DataBuffer
;
1159 CommandPacket
.SenseData
= SenseData
;
1160 CommandPacket
.InTransferLength
= *DataLength
;
1161 CommandPacket
.Cdb
= Cdb
;
1163 // Fill Cdb for Read (16) Command
1165 Cdb
[0] = EFI_SCSI_OP_READ16
;
1166 WriteUnaligned64 ((UINT64
*)&Cdb
[2], SwapBytes64 (StartLba
));
1167 WriteUnaligned32 ((UINT32
*)&Cdb
[10], SwapBytes32 (SectorSize
));
1169 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_SIXTEEN
;
1170 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
1171 CommandPacket
.SenseDataLength
= *SenseDataLength
;
1173 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
1175 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
1176 *TargetStatus
= CommandPacket
.TargetStatus
;
1177 *SenseDataLength
= CommandPacket
.SenseDataLength
;
1178 *DataLength
= CommandPacket
.InTransferLength
;
1185 Execute Write(16) SCSI command on a specific SCSI target.
1187 Executes the SCSI Write(16) command on the SCSI target specified by ScsiIo.
1188 If Timeout is zero, then this function waits indefinitely for the command to complete.
1189 If Timeout is greater than zero, then the command is executed and will timeout after
1190 Timeout 100 ns units. The StartLba and SectorSize parameters are used to construct
1191 the CDB for this SCSI command.
1192 If ScsiIo is NULL, then ASSERT().
1193 If SenseDataLength is NULL, then ASSERT().
1194 If HostAdapterStatus is NULL, then ASSERT().
1195 If TargetStatus is NULL, then ASSERT().
1196 If DataLength is NULL, then ASSERT().
1198 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
1199 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1202 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
1203 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1206 @param[in] ScsiIo SCSI IO Protocol to use
1207 @param[in] Timeout The length of timeout period.
1208 @param[in, out] SenseData A pointer to output sense data.
1209 @param[in, out] SenseDataLength The length of output sense data.
1210 @param[out] HostAdapterStatus The status of Host Adapter.
1211 @param[out] TargetStatus The status of the target.
1212 @param[in, out] DataBuffer A pointer to a data buffer.
1213 @param[in, out] DataLength The length of data buffer.
1214 @param[in] StartLba The start address of LBA.
1215 @param[in] SectorSize The number of contiguous logical blocks of data that shall be transferred.
1217 @retval EFI_SUCCESS Command is executed successfully.
1218 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could
1219 not be transferred. The actual number of bytes transferred is returned in DataLength.
1220 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
1221 SCSI Command Packets already queued.
1222 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
1223 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
1224 the SCSI initiator(i.e., SCSI Host Controller)
1225 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
1226 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
1231 ScsiWrite16Command (
1232 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1234 IN OUT VOID
*SenseData
, OPTIONAL
1235 IN OUT UINT8
*SenseDataLength
,
1236 OUT UINT8
*HostAdapterStatus
,
1237 OUT UINT8
*TargetStatus
,
1238 IN OUT VOID
*DataBuffer
, OPTIONAL
1239 IN OUT UINT32
*DataLength
,
1241 IN UINT32 SectorSize
1244 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
1246 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIXTEEN
];
1248 ASSERT (SenseDataLength
!= NULL
);
1249 ASSERT (HostAdapterStatus
!= NULL
);
1250 ASSERT (TargetStatus
!= NULL
);
1251 ASSERT (DataLength
!= NULL
);
1252 ASSERT (ScsiIo
!= NULL
);
1254 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
1255 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIXTEEN
);
1257 CommandPacket
.Timeout
= Timeout
;
1258 CommandPacket
.OutDataBuffer
= DataBuffer
;
1259 CommandPacket
.SenseData
= SenseData
;
1260 CommandPacket
.OutTransferLength
= *DataLength
;
1261 CommandPacket
.Cdb
= Cdb
;
1263 // Fill Cdb for Write (16) Command
1265 Cdb
[0] = EFI_SCSI_OP_WRITE16
;
1266 WriteUnaligned64 ((UINT64
*)&Cdb
[2], SwapBytes64 (StartLba
));
1267 WriteUnaligned32 ((UINT32
*)&Cdb
[10], SwapBytes32 (SectorSize
));
1269 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_SIXTEEN
;
1270 CommandPacket
.DataDirection
= EFI_SCSI_DATA_OUT
;
1271 CommandPacket
.SenseDataLength
= *SenseDataLength
;
1273 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
1275 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
1276 *TargetStatus
= CommandPacket
.TargetStatus
;
1277 *SenseDataLength
= CommandPacket
.SenseDataLength
;
1278 *DataLength
= CommandPacket
.OutTransferLength
;
1285 Execute Security Protocol In SCSI command on a specific SCSI target.
1287 Executes the SCSI Security Protocol In command on the SCSI target specified by ScsiIo.
1288 If Timeout is zero, then this function waits indefinitely for the command to complete.
1289 If Timeout is greater than zero, then the command is executed and will timeout after
1290 Timeout 100 ns units.
1291 If ScsiIo is NULL, then ASSERT().
1292 If SenseDataLength is NULL, then ASSERT().
1293 If HostAdapterStatus is NULL, then ASSERT().
1294 If TargetStatus is NULL, then ASSERT().
1295 If TransferLength is NULL, then ASSERT().
1297 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
1298 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1301 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
1302 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1305 @param[in] ScsiIo SCSI IO Protocol to use.
1306 @param[in] Timeout The length of timeout period.
1307 @param[in, out] SenseData A pointer to output sense data.
1308 @param[in, out] SenseDataLength The length of output sense data.
1309 @param[out] HostAdapterStatus The status of Host Adapter.
1310 @param[out] TargetStatus The status of the target.
1311 @param[in] SecurityProtocol The Security Protocol to use.
1312 @param[in] SecurityProtocolSpecific The Security Protocol Specific data.
1313 @param[in] Inc512 If TRUE, 512 increment (INC_512) bit will be set for the
1314 SECURITY PROTOCOL IN command.
1315 @param[in] DataLength The size in bytes of the data buffer.
1316 @param[in, out] DataBuffer A pointer to a data buffer.
1317 @param[out] TransferLength A pointer to a buffer to store the size in
1318 bytes of the data written to the data buffer.
1320 @retval EFI_SUCCESS Command is executed successfully.
1321 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could
1322 not be transferred. The actual number of bytes transferred is returned in TransferLength.
1323 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
1324 SCSI Command Packets already queued.
1325 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
1326 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
1327 the SCSI initiator(i.e., SCSI Host Controller)
1328 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
1329 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
1334 ScsiSecurityProtocolInCommand (
1335 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1337 IN OUT VOID
*SenseData
, OPTIONAL
1338 IN OUT UINT8
*SenseDataLength
,
1339 OUT UINT8
*HostAdapterStatus
,
1340 OUT UINT8
*TargetStatus
,
1341 IN UINT8 SecurityProtocol
,
1342 IN UINT16 SecurityProtocolSpecific
,
1344 IN UINTN DataLength
,
1345 IN OUT VOID
*DataBuffer
, OPTIONAL
1346 OUT UINTN
*TransferLength
1349 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
1351 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TWELVE
];
1353 ASSERT (SenseDataLength
!= NULL
);
1354 ASSERT (HostAdapterStatus
!= NULL
);
1355 ASSERT (TargetStatus
!= NULL
);
1356 ASSERT (ScsiIo
!= NULL
);
1357 ASSERT (TransferLength
!= NULL
);
1358 ASSERT (DataLength
<= MAX_UINT32
);
1360 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
1361 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TWELVE
);
1363 CommandPacket
.Timeout
= Timeout
;
1364 CommandPacket
.InDataBuffer
= DataBuffer
;
1365 CommandPacket
.SenseData
= SenseData
;
1366 CommandPacket
.InTransferLength
= (UINT32
) DataLength
;
1367 CommandPacket
.Cdb
= Cdb
;
1369 // Fill Cdb for Security Protocol In Command
1371 Cdb
[0] = EFI_SCSI_OP_SECURITY_PROTOCOL_IN
;
1372 Cdb
[1] = SecurityProtocol
;
1373 WriteUnaligned16 ((UINT16
*)&Cdb
[2], SwapBytes16 (SecurityProtocolSpecific
));
1376 if (DataLength
% 512 != 0) {
1377 return EFI_INVALID_PARAMETER
;
1380 WriteUnaligned32 ((UINT32
*)&Cdb
[6], SwapBytes32 ((UINT32
) DataLength
/ 512));
1382 WriteUnaligned32 ((UINT32
*)&Cdb
[6], SwapBytes32 ((UINT32
) DataLength
));
1385 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TWELVE
;
1386 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
1387 CommandPacket
.SenseDataLength
= *SenseDataLength
;
1389 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
1391 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
1392 *TargetStatus
= CommandPacket
.TargetStatus
;
1393 *SenseDataLength
= CommandPacket
.SenseDataLength
;
1394 *TransferLength
= (UINTN
) CommandPacket
.InTransferLength
;
1401 Execute Security Protocol Out SCSI command on a specific SCSI target.
1403 Executes the SCSI Security Protocol Out command on the SCSI target specified by ScsiIo.
1404 If Timeout is zero, then this function waits indefinitely for the command to complete.
1405 If Timeout is greater than zero, then the command is executed and will timeout after
1406 Timeout 100 ns units.
1407 If ScsiIo is NULL, then ASSERT().
1408 If SenseDataLength is NULL, then ASSERT().
1409 If HostAdapterStatus is NULL, then ASSERT().
1410 If TargetStatus is NULL, then ASSERT().
1412 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
1413 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1416 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
1417 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1420 @param[in] ScsiIo SCSI IO Protocol to use.
1421 @param[in] Timeout The length of timeout period.
1422 @param[in, out] SenseData A pointer to output sense data.
1423 @param[in, out] SenseDataLength The length of output sense data.
1424 @param[out] HostAdapterStatus The status of Host Adapter.
1425 @param[out] TargetStatus The status of the target.
1426 @param[in] SecurityProtocol The Security Protocol to use.
1427 @param[in] SecurityProtocolSpecific The Security Protocol Specific data.
1428 @param[in] Inc512 If TRUE, 512 increment (INC_512) bit will be set for the
1429 SECURITY PROTOCOL OUT command.
1430 @param[in] DataLength The size in bytes of the transfer data.
1431 @param[in, out] DataBuffer A pointer to a data buffer.
1433 @retval EFI_SUCCESS Command is executed successfully.
1434 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could
1435 not be transferred. The actual number of bytes transferred is returned in DataLength.
1436 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
1437 SCSI Command Packets already queued.
1438 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
1439 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
1440 the SCSI initiator(i.e., SCSI Host Controller)
1441 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
1442 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
1447 ScsiSecurityProtocolOutCommand (
1448 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1450 IN OUT VOID
*SenseData
, OPTIONAL
1451 IN OUT UINT8
*SenseDataLength
,
1452 OUT UINT8
*HostAdapterStatus
,
1453 OUT UINT8
*TargetStatus
,
1454 IN UINT8 SecurityProtocol
,
1455 IN UINT16 SecurityProtocolSpecific
,
1457 IN UINTN DataLength
,
1458 IN OUT VOID
*DataBuffer OPTIONAL
1461 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
1463 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TWELVE
];
1465 ASSERT (SenseDataLength
!= NULL
);
1466 ASSERT (HostAdapterStatus
!= NULL
);
1467 ASSERT (TargetStatus
!= NULL
);
1468 ASSERT (ScsiIo
!= NULL
);
1469 ASSERT (DataLength
<= MAX_UINT32
);
1471 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
1472 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TWELVE
);
1474 CommandPacket
.Timeout
= Timeout
;
1475 CommandPacket
.OutDataBuffer
= DataBuffer
;
1476 CommandPacket
.SenseData
= SenseData
;
1477 CommandPacket
.OutTransferLength
= (UINT32
) DataLength
;
1478 CommandPacket
.Cdb
= Cdb
;
1480 // Fill Cdb for Security Protocol Out Command
1482 Cdb
[0] = EFI_SCSI_OP_SECURITY_PROTOCOL_OUT
;
1483 Cdb
[1] = SecurityProtocol
;
1484 WriteUnaligned16 ((UINT16
*)&Cdb
[2], SwapBytes16 (SecurityProtocolSpecific
));
1487 if (DataLength
% 512 != 0) {
1488 return EFI_INVALID_PARAMETER
;
1491 WriteUnaligned32 ((UINT32
*)&Cdb
[6], SwapBytes32 ((UINT32
) DataLength
/ 512));
1493 WriteUnaligned32 ((UINT32
*)&Cdb
[6], SwapBytes32 ((UINT32
) DataLength
));
1496 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TWELVE
;
1497 CommandPacket
.DataDirection
= EFI_SCSI_DATA_OUT
;
1498 CommandPacket
.SenseDataLength
= *SenseDataLength
;
1500 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
1502 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
1503 *TargetStatus
= CommandPacket
.TargetStatus
;
1504 *SenseDataLength
= CommandPacket
.SenseDataLength
;
1511 Internal helper notify function in which update the result of the
1512 non-blocking SCSI Read/Write commands and signal caller event.
1514 @param Event The instance of EFI_EVENT.
1515 @param Context The parameter passed in.
1525 EFI_SCSI_LIB_ASYNC_CONTEXT
*LibContext
;
1526 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
1527 EFI_EVENT CallerEvent
;
1529 LibContext
= (EFI_SCSI_LIB_ASYNC_CONTEXT
*) Context
;
1530 CommandPacket
= &LibContext
->CommandPacket
;
1531 CallerEvent
= LibContext
->CallerEvent
;
1534 // Update SCSI Read/Write operation results
1536 *LibContext
->SenseDataLength
= CommandPacket
->SenseDataLength
;
1537 *LibContext
->HostAdapterStatus
= CommandPacket
->HostAdapterStatus
;
1538 *LibContext
->TargetStatus
= CommandPacket
->TargetStatus
;
1539 if (CommandPacket
->InDataBuffer
!= NULL
) {
1540 *LibContext
->DataLength
= CommandPacket
->InTransferLength
;
1542 *LibContext
->DataLength
= CommandPacket
->OutTransferLength
;
1545 if (CommandPacket
->Cdb
!= NULL
) {
1546 FreePool (CommandPacket
->Cdb
);
1550 gBS
->CloseEvent (Event
);
1551 gBS
->SignalEvent (CallerEvent
);
1556 Execute blocking/non-blocking Read(10) SCSI command on a specific SCSI
1559 Executes the SCSI Read(10) command on the SCSI target specified by ScsiIo.
1560 When Event is NULL, blocking command will be executed. Otherwise non-blocking
1561 command will be executed.
1562 For blocking I/O, if Timeout is zero, this function will wait indefinitely
1563 for the command to complete. If Timeout is greater than zero, then the
1564 command is executed and will timeout after Timeout 100 ns units.
1565 For non-blocking I/O, if Timeout is zero, Event will be signaled only after
1566 the command to completes. If Timeout is greater than zero, Event will also be
1567 signaled after Timeout 100 ns units.
1568 The StartLba and SectorSize parameters are used to construct the CDB for this
1571 If ScsiIo is NULL, then ASSERT().
1572 If SenseDataLength is NULL, then ASSERT().
1573 If HostAdapterStatus is NULL, then ASSERT().
1574 If TargetStatus is NULL, then ASSERT().
1575 If DataLength is NULL, then ASSERT().
1577 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet
1578 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1579 EFI_INVALID_PARAMETER gets returned.
1581 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet
1582 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1583 EFI_INVALID_PARAMETER gets returned.
1585 @param[in] ScsiIo A pointer to SCSI IO protocol.
1586 @param[in] Timeout The length of timeout period.
1587 @param[in, out] SenseData A pointer to output sense data.
1588 @param[in, out] SenseDataLength The length of output sense data.
1589 @param[out] HostAdapterStatus The status of Host Adapter.
1590 @param[out] TargetStatus The status of the target.
1591 @param[in, out] DataBuffer Read 16 command data.
1592 @param[in, out] DataLength The length of data buffer.
1593 @param[in] StartLba The start address of LBA.
1594 @param[in] SectorSize The number of contiguous logical blocks
1595 of data that shall be transferred.
1596 @param[in] Event If the SCSI target does not support
1597 non-blocking I/O, then Event is ignored,
1598 and blocking I/O is performed. If Event
1599 is NULL, then blocking I/O is performed.
1600 If Event is not NULL and non-blocking
1601 I/O is supported, then non-blocking I/O
1602 is performed, and Event will be signaled
1603 when the SCSI Read(10) command
1606 @retval EFI_SUCCESS Command is executed successfully.
1607 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
1608 but the entire DataBuffer could not be
1609 transferred. The actual number of bytes
1610 transferred is returned in DataLength.
1611 @retval EFI_NOT_READY The SCSI Request Packet could not be
1612 sent because there are too many SCSI
1613 Command Packets already queued.
1614 @retval EFI_DEVICE_ERROR A device error occurred while attempting
1615 to send SCSI Request Packet.
1616 @retval EFI_UNSUPPORTED The command described by the SCSI
1617 Request Packet is not supported by the
1618 SCSI initiator(i.e., SCSI Host
1620 @retval EFI_TIMEOUT A timeout occurred while waiting for the
1621 SCSI Request Packet to execute.
1622 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet
1624 @retval EFI_OUT_OF_RESOURCES The request could not be completed due
1625 to a lack of resources.
1630 ScsiRead10CommandEx (
1631 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1633 IN OUT VOID
*SenseData
, OPTIONAL
1634 IN OUT UINT8
*SenseDataLength
,
1635 OUT UINT8
*HostAdapterStatus
,
1636 OUT UINT8
*TargetStatus
,
1637 IN OUT VOID
*DataBuffer
, OPTIONAL
1638 IN OUT UINT32
*DataLength
,
1640 IN UINT32 SectorSize
,
1641 IN EFI_EVENT Event OPTIONAL
1644 EFI_SCSI_LIB_ASYNC_CONTEXT
*Context
;
1645 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
1648 EFI_EVENT SelfEvent
;
1650 if (Event
== NULL
) {
1651 return ScsiRead10Command (
1665 ASSERT (SenseDataLength
!= NULL
);
1666 ASSERT (HostAdapterStatus
!= NULL
);
1667 ASSERT (TargetStatus
!= NULL
);
1668 ASSERT (DataLength
!= NULL
);
1669 ASSERT (ScsiIo
!= NULL
);
1671 Context
= AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT
));
1672 if (Context
== NULL
) {
1673 return EFI_OUT_OF_RESOURCES
;
1676 Cdb
= AllocateZeroPool (EFI_SCSI_OP_LENGTH_TEN
);
1678 Status
= EFI_OUT_OF_RESOURCES
;
1682 Context
->SenseDataLength
= SenseDataLength
;
1683 Context
->HostAdapterStatus
= HostAdapterStatus
;
1684 Context
->TargetStatus
= TargetStatus
;
1685 Context
->CallerEvent
= Event
;
1687 CommandPacket
= &Context
->CommandPacket
;
1688 CommandPacket
->Timeout
= Timeout
;
1689 CommandPacket
->InDataBuffer
= DataBuffer
;
1690 CommandPacket
->SenseData
= SenseData
;
1691 CommandPacket
->InTransferLength
= *DataLength
;
1692 CommandPacket
->Cdb
= Cdb
;
1694 // Fill Cdb for Read (10) Command
1696 Cdb
[0] = EFI_SCSI_OP_READ10
;
1697 WriteUnaligned32 ((UINT32
*)&Cdb
[2], SwapBytes32 (StartLba
));
1698 WriteUnaligned16 ((UINT16
*)&Cdb
[7], SwapBytes16 ((UINT16
) SectorSize
));
1700 CommandPacket
->CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
1701 CommandPacket
->DataDirection
= EFI_SCSI_DATA_IN
;
1702 CommandPacket
->SenseDataLength
= *SenseDataLength
;
1707 Status
= gBS
->CreateEvent (
1714 if (EFI_ERROR(Status
)) {
1718 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, CommandPacket
, SelfEvent
);
1719 if (EFI_ERROR(Status
)) {
1721 // Since ScsiLibNotify() will not be signaled if ExecuteScsiCommand()
1722 // returns with error, close the event here.
1724 gBS
->CloseEvent (SelfEvent
);
1731 if (Context
!= NULL
) {
1740 Execute blocking/non-blocking Write(10) SCSI command on a specific SCSI
1743 Executes the SCSI Write(10) command on the SCSI target specified by ScsiIo.
1744 When Event is NULL, blocking command will be executed. Otherwise non-blocking
1745 command will be executed.
1746 For blocking I/O, if Timeout is zero, this function will wait indefinitely
1747 for the command to complete. If Timeout is greater than zero, then the
1748 command is executed and will timeout after Timeout 100 ns units.
1749 For non-blocking I/O, if Timeout is zero, Event will be signaled only after
1750 the command to completes. If Timeout is greater than zero, Event will also be
1751 signaled after Timeout 100 ns units.
1752 The StartLba and SectorSize parameters are used to construct the CDB for this
1755 If ScsiIo is NULL, then ASSERT().
1756 If SenseDataLength is NULL, then ASSERT().
1757 If HostAdapterStatus is NULL, then ASSERT().
1758 If TargetStatus is NULL, then ASSERT().
1759 If DataLength is NULL, then ASSERT().
1761 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet
1762 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1763 EFI_INVALID_PARAMETER gets returned.
1765 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet
1766 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1767 EFI_INVALID_PARAMETER gets returned.
1769 @param[in] ScsiIo SCSI IO Protocol to use
1770 @param[in] Timeout The length of timeout period.
1771 @param[in, out] SenseData A pointer to output sense data.
1772 @param[in, out] SenseDataLength The length of output sense data.
1773 @param[out] HostAdapterStatus The status of Host Adapter.
1774 @param[out] TargetStatus The status of the target.
1775 @param[in, out] DataBuffer A pointer to a data buffer.
1776 @param[in, out] DataLength The length of data buffer.
1777 @param[in] StartLba The start address of LBA.
1778 @param[in] SectorSize The number of contiguous logical blocks
1779 of data that shall be transferred.
1780 @param[in] Event If the SCSI target does not support
1781 non-blocking I/O, then Event is ignored,
1782 and blocking I/O is performed. If Event
1783 is NULL, then blocking I/O is performed.
1784 If Event is not NULL and non-blocking
1785 I/O is supported, then non-blocking I/O
1786 is performed, and Event will be signaled
1787 when the SCSI Write(10) command
1790 @retval EFI_SUCCESS Command is executed successfully.
1791 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
1792 but the entire DataBuffer could not be
1793 transferred. The actual number of bytes
1794 transferred is returned in DataLength.
1795 @retval EFI_NOT_READY The SCSI Request Packet could not be
1796 sent because there are too many SCSI
1797 Command Packets already queued.
1798 @retval EFI_DEVICE_ERROR A device error occurred while attempting
1799 to send SCSI Request Packet.
1800 @retval EFI_UNSUPPORTED The command described by the SCSI
1801 Request Packet is not supported by the
1802 SCSI initiator(i.e., SCSI Host
1804 @retval EFI_TIMEOUT A timeout occurred while waiting for the
1805 SCSI Request Packet to execute.
1806 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet
1808 @retval EFI_OUT_OF_RESOURCES The request could not be completed due
1809 to a lack of resources.
1814 ScsiWrite10CommandEx (
1815 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1817 IN OUT VOID
*SenseData
, OPTIONAL
1818 IN OUT UINT8
*SenseDataLength
,
1819 OUT UINT8
*HostAdapterStatus
,
1820 OUT UINT8
*TargetStatus
,
1821 IN OUT VOID
*DataBuffer
, OPTIONAL
1822 IN OUT UINT32
*DataLength
,
1824 IN UINT32 SectorSize
,
1825 IN EFI_EVENT Event OPTIONAL
1828 EFI_SCSI_LIB_ASYNC_CONTEXT
*Context
;
1829 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
1832 EFI_EVENT SelfEvent
;
1834 if (Event
== NULL
) {
1835 return ScsiWrite10Command (
1849 ASSERT (SenseDataLength
!= NULL
);
1850 ASSERT (HostAdapterStatus
!= NULL
);
1851 ASSERT (TargetStatus
!= NULL
);
1852 ASSERT (DataLength
!= NULL
);
1853 ASSERT (ScsiIo
!= NULL
);
1855 Context
= AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT
));
1856 if (Context
== NULL
) {
1857 return EFI_OUT_OF_RESOURCES
;
1860 Cdb
= AllocateZeroPool (EFI_SCSI_OP_LENGTH_TEN
);
1862 Status
= EFI_OUT_OF_RESOURCES
;
1866 Context
->SenseDataLength
= SenseDataLength
;
1867 Context
->HostAdapterStatus
= HostAdapterStatus
;
1868 Context
->TargetStatus
= TargetStatus
;
1869 Context
->CallerEvent
= Event
;
1871 CommandPacket
= &Context
->CommandPacket
;
1872 CommandPacket
->Timeout
= Timeout
;
1873 CommandPacket
->OutDataBuffer
= DataBuffer
;
1874 CommandPacket
->SenseData
= SenseData
;
1875 CommandPacket
->OutTransferLength
= *DataLength
;
1876 CommandPacket
->Cdb
= Cdb
;
1878 // Fill Cdb for Write (10) Command
1880 Cdb
[0] = EFI_SCSI_OP_WRITE10
;
1881 WriteUnaligned32 ((UINT32
*)&Cdb
[2], SwapBytes32 (StartLba
));
1882 WriteUnaligned16 ((UINT16
*)&Cdb
[7], SwapBytes16 ((UINT16
) SectorSize
));
1884 CommandPacket
->CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
1885 CommandPacket
->DataDirection
= EFI_SCSI_DATA_OUT
;
1886 CommandPacket
->SenseDataLength
= *SenseDataLength
;
1891 Status
= gBS
->CreateEvent (
1898 if (EFI_ERROR(Status
)) {
1902 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, CommandPacket
, SelfEvent
);
1903 if (EFI_ERROR(Status
)) {
1905 // Since ScsiLibNotify() will not be signaled if ExecuteScsiCommand()
1906 // returns with error, close the event here.
1908 gBS
->CloseEvent (SelfEvent
);
1915 if (Context
!= NULL
) {
1924 Execute blocking/non-blocking Read(16) SCSI command on a specific SCSI
1927 Executes the SCSI Read(16) command on the SCSI target specified by ScsiIo.
1928 When Event is NULL, blocking command will be executed. Otherwise non-blocking
1929 command will be executed.
1930 For blocking I/O, if Timeout is zero, this function will wait indefinitely
1931 for the command to complete. If Timeout is greater than zero, then the
1932 command is executed and will timeout after Timeout 100 ns units.
1933 For non-blocking I/O, if Timeout is zero, Event will be signaled only after
1934 the command to completes. If Timeout is greater than zero, Event will also be
1935 signaled after Timeout 100 ns units.
1936 The StartLba and SectorSize parameters are used to construct the CDB for this
1939 If ScsiIo is NULL, then ASSERT().
1940 If SenseDataLength is NULL, then ASSERT().
1941 If HostAdapterStatus is NULL, then ASSERT().
1942 If TargetStatus is NULL, then ASSERT().
1943 If DataLength is NULL, then ASSERT().
1945 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet
1946 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1947 EFI_INVALID_PARAMETER gets returned.
1949 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet
1950 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1951 EFI_INVALID_PARAMETER gets returned.
1953 @param[in] ScsiIo A pointer to SCSI IO protocol.
1954 @param[in] Timeout The length of timeout period.
1955 @param[in, out] SenseData A pointer to output sense data.
1956 @param[in, out] SenseDataLength The length of output sense data.
1957 @param[out] HostAdapterStatus The status of Host Adapter.
1958 @param[out] TargetStatus The status of the target.
1959 @param[in, out] DataBuffer Read 16 command data.
1960 @param[in, out] DataLength The length of data buffer.
1961 @param[in] StartLba The start address of LBA.
1962 @param[in] SectorSize The number of contiguous logical blocks
1963 of data that shall be transferred.
1964 @param[in] Event If the SCSI target does not support
1965 non-blocking I/O, then Event is ignored,
1966 and blocking I/O is performed. If Event
1967 is NULL, then blocking I/O is performed.
1968 If Event is not NULL and non-blocking
1969 I/O is supported, then non-blocking I/O
1970 is performed, and Event will be signaled
1971 when the SCSI Read(16) command
1974 @retval EFI_SUCCESS Command is executed successfully.
1975 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
1976 but the entire DataBuffer could not be
1977 transferred. The actual number of bytes
1978 transferred is returned in DataLength.
1979 @retval EFI_NOT_READY The SCSI Request Packet could not be
1980 sent because there are too many SCSI
1981 Command Packets already queued.
1982 @retval EFI_DEVICE_ERROR A device error occurred while attempting
1983 to send SCSI Request Packet.
1984 @retval EFI_UNSUPPORTED The command described by the SCSI
1985 Request Packet is not supported by the
1986 SCSI initiator(i.e., SCSI Host
1988 @retval EFI_TIMEOUT A timeout occurred while waiting for the
1989 SCSI Request Packet to execute.
1990 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet
1992 @retval EFI_OUT_OF_RESOURCES The request could not be completed due
1993 to a lack of resources.
1998 ScsiRead16CommandEx (
1999 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
2001 IN OUT VOID
*SenseData
, OPTIONAL
2002 IN OUT UINT8
*SenseDataLength
,
2003 OUT UINT8
*HostAdapterStatus
,
2004 OUT UINT8
*TargetStatus
,
2005 IN OUT VOID
*DataBuffer
, OPTIONAL
2006 IN OUT UINT32
*DataLength
,
2008 IN UINT32 SectorSize
,
2009 IN EFI_EVENT Event OPTIONAL
2012 EFI_SCSI_LIB_ASYNC_CONTEXT
*Context
;
2013 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
2016 EFI_EVENT SelfEvent
;
2018 if (Event
== NULL
) {
2019 return ScsiRead16Command (
2033 ASSERT (SenseDataLength
!= NULL
);
2034 ASSERT (HostAdapterStatus
!= NULL
);
2035 ASSERT (TargetStatus
!= NULL
);
2036 ASSERT (DataLength
!= NULL
);
2037 ASSERT (ScsiIo
!= NULL
);
2039 Context
= AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT
));
2040 if (Context
== NULL
) {
2041 return EFI_OUT_OF_RESOURCES
;
2044 Cdb
= AllocateZeroPool (EFI_SCSI_OP_LENGTH_SIXTEEN
);
2046 Status
= EFI_OUT_OF_RESOURCES
;
2050 Context
->SenseDataLength
= SenseDataLength
;
2051 Context
->HostAdapterStatus
= HostAdapterStatus
;
2052 Context
->TargetStatus
= TargetStatus
;
2053 Context
->CallerEvent
= Event
;
2055 CommandPacket
= &Context
->CommandPacket
;
2056 CommandPacket
->Timeout
= Timeout
;
2057 CommandPacket
->InDataBuffer
= DataBuffer
;
2058 CommandPacket
->SenseData
= SenseData
;
2059 CommandPacket
->InTransferLength
= *DataLength
;
2060 CommandPacket
->Cdb
= Cdb
;
2062 // Fill Cdb for Read (16) Command
2064 Cdb
[0] = EFI_SCSI_OP_READ16
;
2065 WriteUnaligned64 ((UINT64
*)&Cdb
[2], SwapBytes64 (StartLba
));
2066 WriteUnaligned32 ((UINT32
*)&Cdb
[10], SwapBytes32 (SectorSize
));
2068 CommandPacket
->CdbLength
= EFI_SCSI_OP_LENGTH_SIXTEEN
;
2069 CommandPacket
->DataDirection
= EFI_SCSI_DATA_IN
;
2070 CommandPacket
->SenseDataLength
= *SenseDataLength
;
2075 Status
= gBS
->CreateEvent (
2082 if (EFI_ERROR(Status
)) {
2086 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, CommandPacket
, SelfEvent
);
2087 if (EFI_ERROR(Status
)) {
2089 // Since ScsiLibNotify() will not be signaled if ExecuteScsiCommand()
2090 // returns with error, close the event here.
2092 gBS
->CloseEvent (SelfEvent
);
2099 if (Context
!= NULL
) {
2108 Execute blocking/non-blocking Write(16) SCSI command on a specific SCSI
2111 Executes the SCSI Write(16) command on the SCSI target specified by ScsiIo.
2112 When Event is NULL, blocking command will be executed. Otherwise non-blocking
2113 command will be executed.
2114 For blocking I/O, if Timeout is zero, this function will wait indefinitely
2115 for the command to complete. If Timeout is greater than zero, then the
2116 command is executed and will timeout after Timeout 100 ns units.
2117 For non-blocking I/O, if Timeout is zero, Event will be signaled only after
2118 the command to completes. If Timeout is greater than zero, Event will also be
2119 signaled after Timeout 100 ns units.
2120 The StartLba and SectorSize parameters are used to construct the CDB for this
2123 If ScsiIo is NULL, then ASSERT().
2124 If SenseDataLength is NULL, then ASSERT().
2125 If HostAdapterStatus is NULL, then ASSERT().
2126 If TargetStatus is NULL, then ASSERT().
2127 If DataLength is NULL, then ASSERT().
2129 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet
2130 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
2131 EFI_INVALID_PARAMETER gets returned.
2133 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet
2134 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
2135 EFI_INVALID_PARAMETER gets returned.
2137 @param[in] ScsiIo SCSI IO Protocol to use
2138 @param[in] Timeout The length of timeout period.
2139 @param[in, out] SenseData A pointer to output sense data.
2140 @param[in, out] SenseDataLength The length of output sense data.
2141 @param[out] HostAdapterStatus The status of Host Adapter.
2142 @param[out] TargetStatus The status of the target.
2143 @param[in, out] DataBuffer A pointer to a data buffer.
2144 @param[in, out] DataLength The length of data buffer.
2145 @param[in] StartLba The start address of LBA.
2146 @param[in] SectorSize The number of contiguous logical blocks
2147 of data that shall be transferred.
2148 @param[in] Event If the SCSI target does not support
2149 non-blocking I/O, then Event is ignored,
2150 and blocking I/O is performed. If Event
2151 is NULL, then blocking I/O is performed.
2152 If Event is not NULL and non-blocking
2153 I/O is supported, then non-blocking I/O
2154 is performed, and Event will be signaled
2155 when the SCSI Write(16) command
2158 @retval EFI_SUCCESS Command is executed successfully.
2159 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
2160 but the entire DataBuffer could not be
2161 transferred. The actual number of bytes
2162 transferred is returned in DataLength.
2163 @retval EFI_NOT_READY The SCSI Request Packet could not be
2164 sent because there are too many SCSI
2165 Command Packets already queued.
2166 @retval EFI_DEVICE_ERROR A device error occurred while attempting
2167 to send SCSI Request Packet.
2168 @retval EFI_UNSUPPORTED The command described by the SCSI
2169 Request Packet is not supported by the
2170 SCSI initiator(i.e., SCSI Host
2172 @retval EFI_TIMEOUT A timeout occurred while waiting for the
2173 SCSI Request Packet to execute.
2174 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet
2176 @retval EFI_OUT_OF_RESOURCES The request could not be completed due
2177 to a lack of resources.
2182 ScsiWrite16CommandEx (
2183 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
2185 IN OUT VOID
*SenseData
, OPTIONAL
2186 IN OUT UINT8
*SenseDataLength
,
2187 OUT UINT8
*HostAdapterStatus
,
2188 OUT UINT8
*TargetStatus
,
2189 IN OUT VOID
*DataBuffer
, OPTIONAL
2190 IN OUT UINT32
*DataLength
,
2192 IN UINT32 SectorSize
,
2193 IN EFI_EVENT Event OPTIONAL
2196 EFI_SCSI_LIB_ASYNC_CONTEXT
*Context
;
2197 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
2200 EFI_EVENT SelfEvent
;
2202 if (Event
== NULL
) {
2203 return ScsiWrite16Command (
2217 ASSERT (SenseDataLength
!= NULL
);
2218 ASSERT (HostAdapterStatus
!= NULL
);
2219 ASSERT (TargetStatus
!= NULL
);
2220 ASSERT (DataLength
!= NULL
);
2221 ASSERT (ScsiIo
!= NULL
);
2223 Context
= AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT
));
2224 if (Context
== NULL
) {
2225 return EFI_OUT_OF_RESOURCES
;
2228 Cdb
= AllocateZeroPool (EFI_SCSI_OP_LENGTH_SIXTEEN
);
2230 Status
= EFI_OUT_OF_RESOURCES
;
2234 Context
->SenseDataLength
= SenseDataLength
;
2235 Context
->HostAdapterStatus
= HostAdapterStatus
;
2236 Context
->TargetStatus
= TargetStatus
;
2237 Context
->CallerEvent
= Event
;
2239 CommandPacket
= &Context
->CommandPacket
;
2240 CommandPacket
->Timeout
= Timeout
;
2241 CommandPacket
->OutDataBuffer
= DataBuffer
;
2242 CommandPacket
->SenseData
= SenseData
;
2243 CommandPacket
->OutTransferLength
= *DataLength
;
2244 CommandPacket
->Cdb
= Cdb
;
2246 // Fill Cdb for Write (16) Command
2248 Cdb
[0] = EFI_SCSI_OP_WRITE16
;
2249 WriteUnaligned64 ((UINT64
*)&Cdb
[2], SwapBytes64 (StartLba
));
2250 WriteUnaligned32 ((UINT32
*)&Cdb
[10], SwapBytes32 (SectorSize
));
2252 CommandPacket
->CdbLength
= EFI_SCSI_OP_LENGTH_SIXTEEN
;
2253 CommandPacket
->DataDirection
= EFI_SCSI_DATA_OUT
;
2254 CommandPacket
->SenseDataLength
= *SenseDataLength
;
2259 Status
= gBS
->CreateEvent (
2266 if (EFI_ERROR(Status
)) {
2270 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, CommandPacket
, SelfEvent
);
2271 if (EFI_ERROR(Status
)) {
2273 // Since ScsiLibNotify() will not be signaled if ExecuteScsiCommand()
2274 // returns with error, close the event here.
2276 gBS
->CloseEvent (SelfEvent
);
2283 if (Context
!= NULL
) {