2 UEFI SCSI Library implementation
4 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/BaseLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/UefiScsiLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/UefiBootServicesTableLib.h>
24 #include <IndustryStandard/Scsi.h>
28 // Scsi Command Length
30 #define EFI_SCSI_OP_LENGTH_SIX 0x6
31 #define EFI_SCSI_OP_LENGTH_TEN 0xa
32 #define EFI_SCSI_OP_LENGTH_SIXTEEN 0x10
35 // The context structure used when non-blocking SCSI read/write operation
40 /// The SCSI request packet to send to the SCSI controller specified by
41 /// the device handle.
43 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
45 /// The length of the output sense data.
47 UINT8
*SenseDataLength
;
49 /// The status of the SCSI host adapter.
51 UINT8
*HostAdapterStatus
;
53 /// The status of the target SCSI device.
57 /// The length of the data buffer for the SCSI read/write command.
61 /// The caller event to be signaled when the SCSI read/write command
64 EFI_EVENT CallerEvent
;
65 } EFI_SCSI_LIB_ASYNC_CONTEXT
;
70 Execute Test Unit Ready SCSI command on a specific SCSI target.
72 Executes the Test Unit Ready command on the SCSI target specified by ScsiIo.
73 If Timeout is zero, then this function waits indefinitely for the command to complete.
74 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
75 If ScsiIo is NULL, then ASSERT().
76 If SenseDataLength is NULL, then ASSERT().
77 If HostAdapterStatus is NULL, then ASSERT().
78 If TargetStatus is NULL, then ASSERT().
80 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
81 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
84 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
85 for the specific SCSI target.
86 @param[in] Timeout The timeout in 100 ns units to use for the execution
87 of this SCSI Request Packet. A Timeout value of
88 zero means that this function will wait indefinitely
89 for the SCSI Request Packet to execute. If Timeout
90 is greater than zero, then this function will return
91 EFI_TIMEOUT if the time required to execute the SCSI
92 Request Packet is greater than Timeout.
93 @param[in, out] SenseData A pointer to sense data that was generated by
94 the execution of the SCSI Request Packet. This
95 buffer must be allocated by the caller.
96 If SenseDataLength is 0, then this parameter is
97 optional and may be NULL.
98 @param[in, out] SenseDataLength On input, a pointer to the length in bytes of
99 the SenseData buffer. On output, a pointer to
100 the number of bytes written to the SenseData buffer.
101 @param[out] HostAdapterStatus The status of the SCSI Host Controller that produces
102 the SCSI bus containing the SCSI target specified by
103 ScsiIo when the SCSI Request Packet was executed.
104 See the EFI SCSI I/O Protocol in the UEFI Specification
105 for details on the possible return values.
106 @param[out] TargetStatus The status returned by the SCSI target specified
107 by ScsiIo when the SCSI Request Packet was executed
108 on the SCSI Host Controller. See the EFI SCSI I/O
109 Protocol in the UEFI Specification for details on
110 the possible return values.
112 @retval EFI_SUCCESS The command was executed successfully.
113 See HostAdapterStatus, TargetStatus, SenseDataLength,
114 and SenseData in that order for additional status
116 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
117 there are too many SCSI Command Packets already
118 queued. The SCSI Request Packet was not sent, so
119 no additional status information is available.
120 The caller may retry again later.
121 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
122 SCSI Request Packet. See HostAdapterStatus,
123 TargetStatus, SenseDataLength, and SenseData in that
124 order for additional status information.
125 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
126 is not supported by the SCSI initiator(i.e., SCSI
127 Host Controller). The SCSI Request Packet was not
128 sent, so no additional status information is available.
129 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request
130 Packet to execute. See HostAdapterStatus, TargetStatus,
131 SenseDataLength, and SenseData in that order for
132 additional status information.
133 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
138 ScsiTestUnitReadyCommand (
139 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
141 IN OUT VOID
*SenseData
, OPTIONAL
142 IN OUT UINT8
*SenseDataLength
,
143 OUT UINT8
*HostAdapterStatus
,
144 OUT UINT8
*TargetStatus
147 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
149 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIX
];
151 ASSERT (SenseDataLength
!= NULL
);
152 ASSERT (HostAdapterStatus
!= NULL
);
153 ASSERT (TargetStatus
!= NULL
);
154 ASSERT (ScsiIo
!= NULL
);
156 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
157 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIX
);
159 CommandPacket
.Timeout
= Timeout
;
160 CommandPacket
.InDataBuffer
= NULL
;
161 CommandPacket
.InTransferLength
= 0;
162 CommandPacket
.OutDataBuffer
= NULL
;
163 CommandPacket
.OutTransferLength
= 0;
164 CommandPacket
.SenseData
= SenseData
;
165 CommandPacket
.Cdb
= Cdb
;
167 // Fill Cdb for Test Unit Ready Command
169 Cdb
[0] = EFI_SCSI_OP_TEST_UNIT_READY
;
170 CommandPacket
.CdbLength
= (UINT8
) EFI_SCSI_OP_LENGTH_SIX
;
171 CommandPacket
.SenseDataLength
= *SenseDataLength
;
173 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
175 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
176 *TargetStatus
= CommandPacket
.TargetStatus
;
177 *SenseDataLength
= CommandPacket
.SenseDataLength
;
184 Execute Inquiry SCSI command on a specific SCSI target.
186 Executes the Inquiry command on the SCSI target specified by ScsiIo.
187 If Timeout is zero, then this function waits indefinitely for the command to complete.
188 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
189 If ScsiIo is NULL, then ASSERT().
190 If SenseDataLength is NULL, then ASSERT().
191 If HostAdapterStatus is NULL, then ASSERT().
192 If TargetStatus is NULL, then ASSERT().
193 If InquiryDataLength is NULL, then ASSERT().
195 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
196 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
199 If InquiryDataLength is non-zero and InquiryDataBuffer is not NULL, InquiryDataBuffer
200 must meet buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
201 EFI_INVALID_PARAMETER gets returned.
203 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
204 for the specific SCSI target.
205 @param[in] Timeout The timeout in 100 ns units to use for the
206 execution of this SCSI Request Packet. A Timeout
207 value of zero means that this function will wait
208 indefinitely for the SCSI Request Packet to execute.
209 If Timeout is greater than zero, then this function
210 will return EFI_TIMEOUT if the time required to
211 execute the SCSI Request Packet is greater than Timeout.
212 @param[in, out] SenseData A pointer to sense data that was generated
213 by the execution of the SCSI Request Packet.
214 This buffer must be allocated by the caller.
215 If SenseDataLength is 0, then this parameter
216 is optional and may be NULL.
217 @param[in, out] SenseDataLength On input, the length in bytes of the SenseData buffer.
218 On output, the number of bytes written to the SenseData buffer.
219 @param[out] HostAdapterStatus The status of the SCSI Host Controller that
220 produces the SCSI bus containing the SCSI
221 target specified by ScsiIo when the SCSI
222 Request Packet was executed. See the EFI
223 SCSI I/O Protocol in the UEFI Specification
224 for details on the possible return values.
225 @param[out] TargetStatus The status returned by the SCSI target specified
226 by ScsiIo when the SCSI Request Packet was
227 executed on the SCSI Host Controller.
228 See the EFI SCSI I/O Protocol in the UEFI
229 Specification for details on the possible
231 @param[in, out] InquiryDataBuffer A pointer to inquiry data that was generated
232 by the execution of the SCSI Request Packet.
233 This buffer must be allocated by the caller.
234 If InquiryDataLength is 0, then this parameter
235 is optional and may be NULL.
236 @param[in, out] InquiryDataLength On input, a pointer to the length in bytes
237 of the InquiryDataBuffer buffer.
238 On output, a pointer to the number of bytes
239 written to the InquiryDataBuffer buffer.
240 @param[in] EnableVitalProductData If TRUE, then the supported vital product
241 data for the PageCode is returned in InquiryDataBuffer.
242 If FALSE, then the standard inquiry data is
243 returned in InquiryDataBuffer and PageCode is ignored.
244 @param[in] PageCode The page code of the vital product data.
245 It's ignored if EnableVitalProductData is FALSE.
247 @retval EFI_SUCCESS The command executed successfully. See HostAdapterStatus,
248 TargetStatus, SenseDataLength, and SenseData in that order
249 for additional status information.
250 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire
251 InquiryDataBuffer could not be transferred. The actual
252 number of bytes transferred is returned in InquiryDataLength.
253 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there
254 are too many SCSI Command Packets already queued.
255 The SCSI Request Packet was not sent, so no additional
256 status information is available. The caller may retry again later.
257 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI
258 Request Packet. See HostAdapterStatus, TargetStatus,
259 SenseDataLength, and SenseData in that order for additional
261 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not
262 supported by the SCSI initiator(i.e., SCSI Host Controller).
263 The SCSI Request Packet was not sent, so no additional
264 status information is available.
265 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request
266 Packet to execute. See HostAdapterStatus, TargetStatus,
267 SenseDataLength, and SenseData in that order for
268 additional status information.
269 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
274 ScsiInquiryCommandEx (
275 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
277 IN OUT VOID
*SenseData
, OPTIONAL
278 IN OUT UINT8
*SenseDataLength
,
279 OUT UINT8
*HostAdapterStatus
,
280 OUT UINT8
*TargetStatus
,
281 IN OUT VOID
*InquiryDataBuffer
, OPTIONAL
282 IN OUT UINT32
*InquiryDataLength
,
283 IN BOOLEAN EnableVitalProductData
,
287 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
289 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIX
];
291 ASSERT (SenseDataLength
!= NULL
);
292 ASSERT (HostAdapterStatus
!= NULL
);
293 ASSERT (TargetStatus
!= NULL
);
294 ASSERT (InquiryDataLength
!= NULL
);
295 ASSERT (ScsiIo
!= NULL
);
297 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
298 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIX
);
300 CommandPacket
.Timeout
= Timeout
;
301 CommandPacket
.InDataBuffer
= InquiryDataBuffer
;
302 CommandPacket
.InTransferLength
= *InquiryDataLength
;
303 CommandPacket
.SenseData
= SenseData
;
304 CommandPacket
.SenseDataLength
= *SenseDataLength
;
305 CommandPacket
.Cdb
= Cdb
;
307 Cdb
[0] = EFI_SCSI_OP_INQUIRY
;
308 if (EnableVitalProductData
) {
313 if (*InquiryDataLength
> 0xff) {
314 *InquiryDataLength
= 0xff;
317 Cdb
[4] = (UINT8
) (*InquiryDataLength
);
318 CommandPacket
.CdbLength
= (UINT8
) EFI_SCSI_OP_LENGTH_SIX
;
319 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
321 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
323 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
324 *TargetStatus
= CommandPacket
.TargetStatus
;
325 *SenseDataLength
= CommandPacket
.SenseDataLength
;
326 *InquiryDataLength
= CommandPacket
.InTransferLength
;
333 Execute Inquiry SCSI command on a specific SCSI target.
335 Executes the Inquiry command on the SCSI target specified by ScsiIo.
336 If Timeout is zero, then this function waits indefinitely for the command to complete.
337 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
338 If ScsiIo is NULL, then ASSERT().
339 If SenseDataLength is NULL, then ASSERT().
340 If HostAdapterStatus is NULL, then ASSERT().
341 If TargetStatus is NULL, then ASSERT().
342 If InquiryDataLength is NULL, then ASSERT().
344 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
345 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
348 If InquiryDataLength is non-zero and InquiryDataBuffer is not NULL, InquiryDataBuffer
349 must meet buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
350 EFI_INVALID_PARAMETER gets returned.
352 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
353 for the specific SCSI target.
354 @param[in] Timeout The timeout in 100 ns units to use for the
355 execution of this SCSI Request Packet. A Timeout
356 value of zero means that this function will wait
357 indefinitely for the SCSI Request Packet to execute.
358 If Timeout is greater than zero, then this function
359 will return EFI_TIMEOUT if the time required to
360 execute the SCSI Request Packet is greater than Timeout.
361 @param[in, out] SenseData A pointer to sense data that was generated
362 by the execution of the SCSI Request Packet.
363 This buffer must be allocated by the caller.
364 If SenseDataLength is 0, then this parameter
365 is optional and may be NULL.
366 @param[in, out] SenseDataLength On input, the length in bytes of the SenseData buffer.
367 On output, the number of bytes written to the SenseData buffer.
368 @param[out] HostAdapterStatus The status of the SCSI Host Controller that
369 produces the SCSI bus containing the SCSI
370 target specified by ScsiIo when the SCSI
371 Request Packet was executed. See the EFI
372 SCSI I/O Protocol in the UEFI Specification
373 for details on the possible return values.
374 @param[out] TargetStatus The status returned by the SCSI target specified
375 by ScsiIo when the SCSI Request Packet was
376 executed on the SCSI Host Controller.
377 See the EFI SCSI I/O Protocol in the UEFI
378 Specification for details on the possible
380 @param[in, out] InquiryDataBuffer A pointer to inquiry data that was generated
381 by the execution of the SCSI Request Packet.
382 This buffer must be allocated by the caller.
383 If InquiryDataLength is 0, then this parameter
384 is optional and may be NULL.
385 @param[in, out] InquiryDataLength On input, a pointer to the length in bytes
386 of the InquiryDataBuffer buffer.
387 On output, a pointer to the number of bytes
388 written to the InquiryDataBuffer buffer.
389 @param[in] EnableVitalProductData If TRUE, then the supported vital product
390 data is returned in InquiryDataBuffer.
391 If FALSE, then the standard inquiry data is
392 returned in InquiryDataBuffer.
394 @retval EFI_SUCCESS The command was executed successfully. See HostAdapterStatus,
395 TargetStatus, SenseDataLength, and SenseData in that order
396 for additional status information.
397 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire
398 InquiryDataBuffer could not be transferred. The actual
399 number of bytes transferred is returned in InquiryDataLength.
400 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there
401 are too many SCSI Command Packets already queued.
402 The SCSI Request Packet was not sent, so no additional
403 status information is available. The caller may retry again later.
404 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI
405 Request Packet. See HostAdapterStatus, TargetStatus,
406 SenseDataLength, and SenseData in that order for additional
408 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not
409 supported by the SCSI initiator(i.e., SCSI Host Controller).
410 The SCSI Request Packet was not sent, so no additional
411 status information is available.
412 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request
413 Packet to execute. See HostAdapterStatus, TargetStatus,
414 SenseDataLength, and SenseData in that order for
415 additional status information.
416 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
422 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
424 IN OUT VOID
*SenseData
, OPTIONAL
425 IN OUT UINT8
*SenseDataLength
,
426 OUT UINT8
*HostAdapterStatus
,
427 OUT UINT8
*TargetStatus
,
428 IN OUT VOID
*InquiryDataBuffer
, OPTIONAL
429 IN OUT UINT32
*InquiryDataLength
,
430 IN BOOLEAN EnableVitalProductData
433 return ScsiInquiryCommandEx (
442 EnableVitalProductData
,
448 Execute Mode Sense(10) SCSI command on a specific SCSI target.
450 Executes the SCSI Mode Sense(10) command on the SCSI target specified by ScsiIo.
451 If Timeout is zero, then this function waits indefinitely for the command to complete.
452 If Timeout is greater than zero, then the command is executed and will timeout
453 after Timeout 100 ns units. The DBDField, PageControl, and PageCode parameters
454 are used to construct the CDB for this SCSI command.
455 If ScsiIo is NULL, then ASSERT().
456 If SenseDataLength is NULL, then ASSERT().
457 If HostAdapterStatus is NULL, then ASSERT().
458 If TargetStatus is NULL, then ASSERT().
459 If DataLength is NULL, then ASSERT().
461 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
462 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
465 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
466 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
469 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
470 for the specific SCSI target.
471 @param[in] Timeout The timeout in 100 ns units to use for the
472 execution of this SCSI Request Packet. A Timeout
473 value of zero means that this function will wait
474 indefinitely for the SCSI Request Packet to execute.
475 If Timeout is greater than zero, then this function
476 will return EFI_TIMEOUT if the time required to
477 execute the SCSI Request Packet is greater than Timeout.
478 @param[in, out] SenseData A pointer to sense data that was generated
479 by the execution of the SCSI Request Packet.
480 This buffer must be allocated by the caller.
481 If SenseDataLength is 0, then this parameter
482 is optional and may be NULL.
483 @param[in, out] SenseDataLength On input, the length in bytes of the SenseData buffer.
484 On output, the number of bytes written to the SenseData buffer.
485 @param[out] HostAdapterStatus The status of the SCSI Host Controller that
486 produces the SCSI bus containing the SCSI target
487 specified by ScsiIo when the SCSI Request Packet
488 was executed. See the EFI SCSI I/O Protocol in the
489 UEFI Specification for details on the possible
491 @param[out] TargetStatus The status returned by the SCSI target specified
492 by ScsiIo when the SCSI Request Packet was executed
493 on the SCSI Host Controller. See the EFI SCSI
494 I/O Protocol in the UEFI Specification for details
495 on the possible return values.
496 @param[in, out] DataBuffer A pointer to data that was generated by the
497 execution of the SCSI Request Packet. This
498 buffer must be allocated by the caller. If
499 DataLength is 0, then this parameter is optional
501 @param[in, out] DataLength On input, a pointer to the length in bytes of
502 the DataBuffer buffer. On output, a pointer
503 to the number of bytes written to the DataBuffer
505 @param[in] DBDField Specifies the DBD field of the CDB for this SCSI Command.
506 @param[in] PageControl Specifies the PC field of the CDB for this SCSI Command.
507 @param[in] PageCode Specifies the Page Control field of the CDB for this SCSI Command.
509 @retval EFI_SUCCESS The command was executed successfully.
510 See HostAdapterStatus, TargetStatus, SenseDataLength,
511 and SenseData in that order for additional status information.
512 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the
513 entire DataBuffer could not be transferred.
514 The actual number of bytes transferred is returned
516 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
517 there are too many SCSI Command Packets already queued.
518 The SCSI Request Packet was not sent, so no additional
519 status information is available. The caller may retry
521 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
522 SCSI Request Packet. See HostAdapterStatus, TargetStatus,
523 SenseDataLength, and SenseData in that order for
524 additional status information.
525 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
526 is not supported by the SCSI initiator(i.e., SCSI
527 Host Controller). The SCSI Request Packet was not
528 sent, so no additional status information is available.
529 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
530 Request Packet to execute. See HostAdapterStatus,
531 TargetStatus, SenseDataLength, and SenseData in that
532 order for additional status information.
533 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
538 ScsiModeSense10Command (
539 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
541 IN OUT VOID
*SenseData
, OPTIONAL
542 IN OUT UINT8
*SenseDataLength
,
543 OUT UINT8
*HostAdapterStatus
,
544 OUT UINT8
*TargetStatus
,
545 IN OUT VOID
*DataBuffer
, OPTIONAL
546 IN OUT UINT32
*DataLength
,
547 IN UINT8 DBDField
, OPTIONAL
548 IN UINT8 PageControl
,
552 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
554 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TEN
];
556 ASSERT (SenseDataLength
!= NULL
);
557 ASSERT (HostAdapterStatus
!= NULL
);
558 ASSERT (TargetStatus
!= NULL
);
559 ASSERT (DataLength
!= NULL
);
560 ASSERT (ScsiIo
!= NULL
);
562 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
563 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TEN
);
565 CommandPacket
.Timeout
= Timeout
;
566 CommandPacket
.InDataBuffer
= DataBuffer
;
567 CommandPacket
.SenseData
= SenseData
;
568 CommandPacket
.InTransferLength
= *DataLength
;
569 CommandPacket
.Cdb
= Cdb
;
571 // Fill Cdb for Mode Sense (10) Command
573 Cdb
[0] = EFI_SCSI_OP_MODE_SEN10
;
575 // DBDField is in Cdb[1] bit3 of (bit7..0)
577 Cdb
[1] = (UINT8
) ((DBDField
<< 3) & 0x08);
579 // PageControl is in Cdb[2] bit7..6, PageCode is in Cdb[2] bit5..0
581 Cdb
[2] = (UINT8
) (((PageControl
<< 6) & 0xc0) | (PageCode
& 0x3f));
582 Cdb
[7] = (UINT8
) (*DataLength
>> 8);
583 Cdb
[8] = (UINT8
) (*DataLength
);
585 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
586 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
587 CommandPacket
.SenseDataLength
= *SenseDataLength
;
589 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
591 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
592 *TargetStatus
= CommandPacket
.TargetStatus
;
593 *SenseDataLength
= CommandPacket
.SenseDataLength
;
594 *DataLength
= CommandPacket
.InTransferLength
;
601 Execute Request Sense SCSI command on a specific SCSI target.
603 Executes the Request Sense command on the SCSI target specified by ScsiIo.
604 If Timeout is zero, then this function waits indefinitely for the command to complete.
605 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
606 If ScsiIo is NULL, then ASSERT().
607 If SenseDataLength is NULL, then ASSERT().
608 If HostAdapterStatus is NULL, then ASSERT().
609 If TargetStatus is NULL, then ASSERT().
611 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
612 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
615 @param[in] ScsiIo A pointer to SCSI IO protocol.
616 @param[in] Timeout The length of timeout period.
617 @param[in, out] SenseData A pointer to output sense data.
618 @param[in, out] SenseDataLength The length of output sense data.
619 @param[out] HostAdapterStatus The status of Host Adapter.
620 @param[out] TargetStatus The status of the target.
622 @retval EFI_SUCCESS Command is executed successfully.
623 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are
624 too many SCSI Command Packets already queued.
625 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
626 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
627 the SCSI initiator(i.e., SCSI Host Controller)
628 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
629 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
634 ScsiRequestSenseCommand (
635 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
637 IN OUT VOID
*SenseData
, OPTIONAL
638 IN OUT UINT8
*SenseDataLength
,
639 OUT UINT8
*HostAdapterStatus
,
640 OUT UINT8
*TargetStatus
643 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
645 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIX
];
647 ASSERT (SenseDataLength
!= NULL
);
648 ASSERT (HostAdapterStatus
!= NULL
);
649 ASSERT (TargetStatus
!= NULL
);
650 ASSERT (ScsiIo
!= NULL
);
652 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
653 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIX
);
655 CommandPacket
.Timeout
= Timeout
;
656 CommandPacket
.InDataBuffer
= SenseData
;
657 CommandPacket
.SenseData
= NULL
;
658 CommandPacket
.InTransferLength
= *SenseDataLength
;
659 CommandPacket
.Cdb
= Cdb
;
661 // Fill Cdb for Request Sense Command
663 Cdb
[0] = EFI_SCSI_OP_REQUEST_SENSE
;
664 Cdb
[4] = (UINT8
) (*SenseDataLength
);
666 CommandPacket
.CdbLength
= (UINT8
) EFI_SCSI_OP_LENGTH_SIX
;
667 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
668 CommandPacket
.SenseDataLength
= 0;
670 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
672 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
673 *TargetStatus
= CommandPacket
.TargetStatus
;
674 *SenseDataLength
= (UINT8
) CommandPacket
.InTransferLength
;
681 Execute Read Capacity SCSI command on a specific SCSI target.
683 Executes the SCSI Read Capacity command on the SCSI target specified by ScsiIo.
684 If Timeout is zero, then this function waits indefinitely for the command to complete.
685 If Timeout is greater than zero, then the command is executed and will timeout after
686 Timeout 100 ns units. The Pmi parameter is used to construct the CDB for this SCSI command.
687 If ScsiIo is NULL, then ASSERT().
688 If SenseDataLength is NULL, then ASSERT().
689 If HostAdapterStatus is NULL, then ASSERT().
690 If TargetStatus is NULL, then ASSERT().
691 If DataLength is NULL, then ASSERT().
693 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
694 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
697 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
698 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
701 @param[in] ScsiIo A pointer to SCSI IO protocol.
702 @param[in] Timeout The length of timeout period.
703 @param[in, out] SenseData A pointer to output sense data.
704 @param[in, out] SenseDataLength The length of output sense data.
705 @param[out] HostAdapterStatus The status of Host Adapter.
706 @param[out] TargetStatus The status of the target.
707 @param[in, out] DataBuffer A pointer to a data buffer.
708 @param[in, out] DataLength The length of data buffer.
709 @param[in] Pmi Partial medium indicator.
711 @retval EFI_SUCCESS Command is executed successfully.
712 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire
713 DataBuffer could not be transferred. The actual
714 number of bytes transferred is returned in DataLength.
715 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
716 there are too many SCSI Command Packets already queued.
717 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
718 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
719 is not supported by the SCSI initiator(i.e., SCSI Host Controller)
720 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
721 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
726 ScsiReadCapacityCommand (
727 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
729 IN OUT VOID
*SenseData
, OPTIONAL
730 IN OUT UINT8
*SenseDataLength
,
731 OUT UINT8
*HostAdapterStatus
,
732 OUT UINT8
*TargetStatus
,
733 IN OUT VOID
*DataBuffer
, OPTIONAL
734 IN OUT UINT32
*DataLength
,
738 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
740 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TEN
];
742 ASSERT (SenseDataLength
!= NULL
);
743 ASSERT (HostAdapterStatus
!= NULL
);
744 ASSERT (TargetStatus
!= NULL
);
745 ASSERT (DataLength
!= NULL
);
746 ASSERT (ScsiIo
!= NULL
);
748 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
749 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TEN
);
751 CommandPacket
.Timeout
= Timeout
;
752 CommandPacket
.InDataBuffer
= DataBuffer
;
753 CommandPacket
.SenseData
= SenseData
;
754 CommandPacket
.InTransferLength
= *DataLength
;
755 CommandPacket
.Cdb
= Cdb
;
757 // Fill Cdb for Read Capacity Command
759 Cdb
[0] = EFI_SCSI_OP_READ_CAPACITY
;
762 // Partial medium indicator,if Pmi is FALSE, the Cdb.2 ~ Cdb.5 MUST BE ZERO.
764 ZeroMem ((Cdb
+ 2), 4);
769 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
770 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
771 CommandPacket
.SenseDataLength
= *SenseDataLength
;
773 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
775 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
776 *TargetStatus
= CommandPacket
.TargetStatus
;
777 *SenseDataLength
= CommandPacket
.SenseDataLength
;
778 *DataLength
= CommandPacket
.InTransferLength
;
785 Execute Read Capacity SCSI 16 command on a specific SCSI target.
787 Executes the SCSI Read Capacity 16 command on the SCSI target specified by ScsiIo.
788 If Timeout is zero, then this function waits indefinitely for the command to complete.
789 If Timeout is greater than zero, then the command is executed and will timeout after
790 Timeout 100 ns units. The Pmi parameter is used to construct the CDB for this SCSI command.
791 If ScsiIo is NULL, then ASSERT().
792 If SenseDataLength is NULL, then ASSERT().
793 If HostAdapterStatus is NULL, then ASSERT().
794 If TargetStatus is NULL, then ASSERT().
795 If DataLength is NULL, then ASSERT().
797 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
798 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
801 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
802 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
805 @param[in] ScsiIo A pointer to SCSI IO protocol.
806 @param[in] Timeout The length of timeout period.
807 @param[in, out] SenseData A pointer to output sense data.
808 @param[in, out] SenseDataLength The length of output sense data.
809 @param[out] HostAdapterStatus The status of Host Adapter.
810 @param[out] TargetStatus The status of the target.
811 @param[in, out] DataBuffer A pointer to a data buffer.
812 @param[in, out] DataLength The length of data buffer.
813 @param[in] Pmi Partial medium indicator.
815 @retval EFI_SUCCESS Command is executed successfully.
816 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire
817 DataBuffer could not be transferred. The actual
818 number of bytes transferred is returned in DataLength.
819 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
820 there are too many SCSI Command Packets already queued.
821 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
822 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
823 is not supported by the SCSI initiator(i.e., SCSI Host Controller)
824 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
825 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
830 ScsiReadCapacity16Command (
831 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
833 IN OUT VOID
*SenseData
, OPTIONAL
834 IN OUT UINT8
*SenseDataLength
,
835 OUT UINT8
*HostAdapterStatus
,
836 OUT UINT8
*TargetStatus
,
837 IN OUT VOID
*DataBuffer
, OPTIONAL
838 IN OUT UINT32
*DataLength
,
842 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
846 ASSERT (SenseDataLength
!= NULL
);
847 ASSERT (HostAdapterStatus
!= NULL
);
848 ASSERT (TargetStatus
!= NULL
);
849 ASSERT (DataLength
!= NULL
);
850 ASSERT (ScsiIo
!= NULL
);
852 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
855 CommandPacket
.Timeout
= Timeout
;
856 CommandPacket
.InDataBuffer
= DataBuffer
;
857 CommandPacket
.SenseData
= SenseData
;
858 CommandPacket
.InTransferLength
= *DataLength
;
859 CommandPacket
.Cdb
= Cdb
;
861 // Fill Cdb for Read Capacity Command
863 Cdb
[0] = EFI_SCSI_OP_READ_CAPACITY16
;
867 // Partial medium indicator,if Pmi is FALSE, the Cdb.2 ~ Cdb.9 MUST BE ZERO.
869 ZeroMem ((Cdb
+ 2), 8);
875 CommandPacket
.CdbLength
= 16;
876 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
877 CommandPacket
.SenseDataLength
= *SenseDataLength
;
879 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
881 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
882 *TargetStatus
= CommandPacket
.TargetStatus
;
883 *SenseDataLength
= CommandPacket
.SenseDataLength
;
884 *DataLength
= CommandPacket
.InTransferLength
;
891 Execute Read(10) SCSI command on a specific SCSI target.
893 Executes the SCSI Read(10) command on the SCSI target specified by ScsiIo.
894 If Timeout is zero, then this function waits indefinitely for the command to complete.
895 If Timeout is greater than zero, then the command is executed and will timeout
896 after Timeout 100 ns units. The StartLba and SectorSize parameters are used to
897 construct the CDB for this SCSI command.
898 If ScsiIo is NULL, then ASSERT().
899 If SenseDataLength is NULL, then ASSERT().
900 If HostAdapterStatus is NULL, then ASSERT().
901 If TargetStatus is NULL, then ASSERT().
902 If DataLength is NULL, then ASSERT().
904 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
905 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
908 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
909 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
912 @param[in] ScsiIo A pointer to SCSI IO protocol.
913 @param[in] Timeout The length of timeout period.
914 @param[in, out] SenseData A pointer to output sense data.
915 @param[in, out] SenseDataLength The length of output sense data.
916 @param[out] HostAdapterStatus The status of Host Adapter.
917 @param[out] TargetStatus The status of the target.
918 @param[in, out] DataBuffer Read 10 command data.
919 @param[in, out] DataLength The length of data buffer.
920 @param[in] StartLba The start address of LBA.
921 @param[in] SectorSize The number of contiguous logical blocks of data that shall be transferred.
923 @retval EFI_SUCCESS Command is executed successfully.
924 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could
925 not be transferred. The actual number of bytes transferred is returned in DataLength.
926 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
927 SCSI Command Packets already queued.
928 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
929 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
930 the SCSI initiator(i.e., SCSI Host Controller)
931 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
932 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
938 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
940 IN OUT VOID
*SenseData
, OPTIONAL
941 IN OUT UINT8
*SenseDataLength
,
942 OUT UINT8
*HostAdapterStatus
,
943 OUT UINT8
*TargetStatus
,
944 IN OUT VOID
*DataBuffer
, OPTIONAL
945 IN OUT UINT32
*DataLength
,
950 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
952 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TEN
];
954 ASSERT (SenseDataLength
!= NULL
);
955 ASSERT (HostAdapterStatus
!= NULL
);
956 ASSERT (TargetStatus
!= NULL
);
957 ASSERT (DataLength
!= NULL
);
958 ASSERT (ScsiIo
!= NULL
);
960 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
961 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TEN
);
963 CommandPacket
.Timeout
= Timeout
;
964 CommandPacket
.InDataBuffer
= DataBuffer
;
965 CommandPacket
.SenseData
= SenseData
;
966 CommandPacket
.InTransferLength
= *DataLength
;
967 CommandPacket
.Cdb
= Cdb
;
969 // Fill Cdb for Read (10) Command
971 Cdb
[0] = EFI_SCSI_OP_READ10
;
972 WriteUnaligned32 ((UINT32
*)&Cdb
[2], SwapBytes32 (StartLba
));
973 WriteUnaligned16 ((UINT16
*)&Cdb
[7], SwapBytes16 ((UINT16
) SectorSize
));
975 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
976 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
977 CommandPacket
.SenseDataLength
= *SenseDataLength
;
979 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
981 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
982 *TargetStatus
= CommandPacket
.TargetStatus
;
983 *SenseDataLength
= CommandPacket
.SenseDataLength
;
984 *DataLength
= CommandPacket
.InTransferLength
;
991 Execute Write(10) SCSI command on a specific SCSI target.
993 Executes the SCSI Write(10) command on the SCSI target specified by ScsiIo.
994 If Timeout is zero, then this function waits indefinitely for the command to complete.
995 If Timeout is greater than zero, then the command is executed and will timeout after
996 Timeout 100 ns units. The StartLba and SectorSize parameters are used to construct
997 the CDB for this SCSI command.
998 If ScsiIo is NULL, then ASSERT().
999 If SenseDataLength is NULL, then ASSERT().
1000 If HostAdapterStatus is NULL, then ASSERT().
1001 If TargetStatus is NULL, then ASSERT().
1002 If DataLength is NULL, then ASSERT().
1004 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
1005 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1008 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
1009 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1012 @param[in] ScsiIo SCSI IO Protocol to use
1013 @param[in] Timeout The length of timeout period.
1014 @param[in, out] SenseData A pointer to output sense data.
1015 @param[in, out] SenseDataLength The length of output sense data.
1016 @param[out] HostAdapterStatus The status of Host Adapter.
1017 @param[out] TargetStatus The status of the target.
1018 @param[in, out] DataBuffer A pointer to a data buffer.
1019 @param[in, out] DataLength The length of data buffer.
1020 @param[in] StartLba The start address of LBA.
1021 @param[in] SectorSize The number of contiguous logical blocks of data that shall be transferred.
1023 @retval EFI_SUCCESS Command is executed successfully.
1024 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could
1025 not be transferred. The actual number of bytes transferred is returned in DataLength.
1026 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
1027 SCSI Command Packets already queued.
1028 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
1029 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
1030 the SCSI initiator(i.e., SCSI Host Controller)
1031 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
1032 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
1037 ScsiWrite10Command (
1038 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1040 IN OUT VOID
*SenseData
, OPTIONAL
1041 IN OUT UINT8
*SenseDataLength
,
1042 OUT UINT8
*HostAdapterStatus
,
1043 OUT UINT8
*TargetStatus
,
1044 IN OUT VOID
*DataBuffer
, OPTIONAL
1045 IN OUT UINT32
*DataLength
,
1047 IN UINT32 SectorSize
1050 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
1052 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_TEN
];
1054 ASSERT (SenseDataLength
!= NULL
);
1055 ASSERT (HostAdapterStatus
!= NULL
);
1056 ASSERT (TargetStatus
!= NULL
);
1057 ASSERT (DataLength
!= NULL
);
1058 ASSERT (ScsiIo
!= NULL
);
1060 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
1061 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_TEN
);
1063 CommandPacket
.Timeout
= Timeout
;
1064 CommandPacket
.OutDataBuffer
= DataBuffer
;
1065 CommandPacket
.SenseData
= SenseData
;
1066 CommandPacket
.OutTransferLength
= *DataLength
;
1067 CommandPacket
.Cdb
= Cdb
;
1069 // Fill Cdb for Write (10) Command
1071 Cdb
[0] = EFI_SCSI_OP_WRITE10
;
1072 WriteUnaligned32 ((UINT32
*)&Cdb
[2], SwapBytes32 (StartLba
));
1073 WriteUnaligned16 ((UINT16
*)&Cdb
[7], SwapBytes16 ((UINT16
) SectorSize
));
1075 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
1076 CommandPacket
.DataDirection
= EFI_SCSI_DATA_OUT
;
1077 CommandPacket
.SenseDataLength
= *SenseDataLength
;
1079 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
1081 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
1082 *TargetStatus
= CommandPacket
.TargetStatus
;
1083 *SenseDataLength
= CommandPacket
.SenseDataLength
;
1084 *DataLength
= CommandPacket
.OutTransferLength
;
1090 Execute Read(16) SCSI command on a specific SCSI target.
1092 Executes the SCSI Read(16) command on the SCSI target specified by ScsiIo.
1093 If Timeout is zero, then this function waits indefinitely for the command to complete.
1094 If Timeout is greater than zero, then the command is executed and will timeout
1095 after Timeout 100 ns units. The StartLba and SectorSize parameters are used to
1096 construct the CDB for this SCSI command.
1097 If ScsiIo is NULL, then ASSERT().
1098 If SenseDataLength is NULL, then ASSERT().
1099 If HostAdapterStatus is NULL, then ASSERT().
1100 If TargetStatus is NULL, then ASSERT().
1101 If DataLength is NULL, then ASSERT().
1103 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
1104 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1107 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
1108 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1111 @param[in] ScsiIo A pointer to SCSI IO protocol.
1112 @param[in] Timeout The length of timeout period.
1113 @param[in, out] SenseData A pointer to output sense data.
1114 @param[in, out] SenseDataLength The length of output sense data.
1115 @param[out] HostAdapterStatus The status of Host Adapter.
1116 @param[out] TargetStatus The status of the target.
1117 @param[in, out] DataBuffer Read 16 command data.
1118 @param[in, out] DataLength The length of data buffer.
1119 @param[in] StartLba The start address of LBA.
1120 @param[in] SectorSize The number of contiguous logical blocks of data that shall be transferred.
1122 @retval EFI_SUCCESS Command is executed successfully.
1123 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could
1124 not be transferred. The actual number of bytes transferred is returned in DataLength.
1125 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
1126 SCSI Command Packets already queued.
1127 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
1128 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
1129 the SCSI initiator(i.e., SCSI Host Controller)
1130 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
1131 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
1137 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1139 IN OUT VOID
*SenseData
, OPTIONAL
1140 IN OUT UINT8
*SenseDataLength
,
1141 OUT UINT8
*HostAdapterStatus
,
1142 OUT UINT8
*TargetStatus
,
1143 IN OUT VOID
*DataBuffer
, OPTIONAL
1144 IN OUT UINT32
*DataLength
,
1146 IN UINT32 SectorSize
1149 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
1151 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIXTEEN
];
1153 ASSERT (SenseDataLength
!= NULL
);
1154 ASSERT (HostAdapterStatus
!= NULL
);
1155 ASSERT (TargetStatus
!= NULL
);
1156 ASSERT (DataLength
!= NULL
);
1157 ASSERT (ScsiIo
!= NULL
);
1159 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
1160 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIXTEEN
);
1162 CommandPacket
.Timeout
= Timeout
;
1163 CommandPacket
.InDataBuffer
= DataBuffer
;
1164 CommandPacket
.SenseData
= SenseData
;
1165 CommandPacket
.InTransferLength
= *DataLength
;
1166 CommandPacket
.Cdb
= Cdb
;
1168 // Fill Cdb for Read (16) Command
1170 Cdb
[0] = EFI_SCSI_OP_READ16
;
1171 WriteUnaligned64 ((UINT64
*)&Cdb
[2], SwapBytes64 (StartLba
));
1172 WriteUnaligned32 ((UINT32
*)&Cdb
[10], SwapBytes32 (SectorSize
));
1174 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_SIXTEEN
;
1175 CommandPacket
.DataDirection
= EFI_SCSI_DATA_IN
;
1176 CommandPacket
.SenseDataLength
= *SenseDataLength
;
1178 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
1180 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
1181 *TargetStatus
= CommandPacket
.TargetStatus
;
1182 *SenseDataLength
= CommandPacket
.SenseDataLength
;
1183 *DataLength
= CommandPacket
.InTransferLength
;
1190 Execute Write(16) SCSI command on a specific SCSI target.
1192 Executes the SCSI Write(16) command on the SCSI target specified by ScsiIo.
1193 If Timeout is zero, then this function waits indefinitely for the command to complete.
1194 If Timeout is greater than zero, then the command is executed and will timeout after
1195 Timeout 100 ns units. The StartLba and SectorSize parameters are used to construct
1196 the CDB for this SCSI command.
1197 If ScsiIo is NULL, then ASSERT().
1198 If SenseDataLength is NULL, then ASSERT().
1199 If HostAdapterStatus is NULL, then ASSERT().
1200 If TargetStatus is NULL, then ASSERT().
1201 If DataLength is NULL, then ASSERT().
1203 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet buffer
1204 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1207 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet buffer
1208 alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INVALID_PARAMETER
1211 @param[in] ScsiIo SCSI IO Protocol to use
1212 @param[in] Timeout The length of timeout period.
1213 @param[in, out] SenseData A pointer to output sense data.
1214 @param[in, out] SenseDataLength The length of output sense data.
1215 @param[out] HostAdapterStatus The status of Host Adapter.
1216 @param[out] TargetStatus The status of the target.
1217 @param[in, out] DataBuffer A pointer to a data buffer.
1218 @param[in, out] DataLength The length of data buffer.
1219 @param[in] StartLba The start address of LBA.
1220 @param[in] SectorSize The number of contiguous logical blocks of data that shall be transferred.
1222 @retval EFI_SUCCESS Command is executed successfully.
1223 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could
1224 not be transferred. The actual number of bytes transferred is returned in DataLength.
1225 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
1226 SCSI Command Packets already queued.
1227 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
1228 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
1229 the SCSI initiator(i.e., SCSI Host Controller)
1230 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
1231 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet are invalid.
1236 ScsiWrite16Command (
1237 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1239 IN OUT VOID
*SenseData
, OPTIONAL
1240 IN OUT UINT8
*SenseDataLength
,
1241 OUT UINT8
*HostAdapterStatus
,
1242 OUT UINT8
*TargetStatus
,
1243 IN OUT VOID
*DataBuffer
, OPTIONAL
1244 IN OUT UINT32
*DataLength
,
1246 IN UINT32 SectorSize
1249 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
1251 UINT8 Cdb
[EFI_SCSI_OP_LENGTH_SIXTEEN
];
1253 ASSERT (SenseDataLength
!= NULL
);
1254 ASSERT (HostAdapterStatus
!= NULL
);
1255 ASSERT (TargetStatus
!= NULL
);
1256 ASSERT (DataLength
!= NULL
);
1257 ASSERT (ScsiIo
!= NULL
);
1259 ZeroMem (&CommandPacket
, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET
));
1260 ZeroMem (Cdb
, EFI_SCSI_OP_LENGTH_SIXTEEN
);
1262 CommandPacket
.Timeout
= Timeout
;
1263 CommandPacket
.OutDataBuffer
= DataBuffer
;
1264 CommandPacket
.SenseData
= SenseData
;
1265 CommandPacket
.OutTransferLength
= *DataLength
;
1266 CommandPacket
.Cdb
= Cdb
;
1268 // Fill Cdb for Write (16) Command
1270 Cdb
[0] = EFI_SCSI_OP_WRITE16
;
1271 WriteUnaligned64 ((UINT64
*)&Cdb
[2], SwapBytes64 (StartLba
));
1272 WriteUnaligned32 ((UINT32
*)&Cdb
[10], SwapBytes32 (SectorSize
));
1274 CommandPacket
.CdbLength
= EFI_SCSI_OP_LENGTH_SIXTEEN
;
1275 CommandPacket
.DataDirection
= EFI_SCSI_DATA_OUT
;
1276 CommandPacket
.SenseDataLength
= *SenseDataLength
;
1278 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, &CommandPacket
, NULL
);
1280 *HostAdapterStatus
= CommandPacket
.HostAdapterStatus
;
1281 *TargetStatus
= CommandPacket
.TargetStatus
;
1282 *SenseDataLength
= CommandPacket
.SenseDataLength
;
1283 *DataLength
= CommandPacket
.OutTransferLength
;
1290 Internal helper notify function in which update the result of the
1291 non-blocking SCSI Read/Write commands and signal caller event.
1293 @param Event The instance of EFI_EVENT.
1294 @param Context The parameter passed in.
1304 EFI_SCSI_LIB_ASYNC_CONTEXT
*LibContext
;
1305 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
1306 EFI_EVENT CallerEvent
;
1308 LibContext
= (EFI_SCSI_LIB_ASYNC_CONTEXT
*) Context
;
1309 CommandPacket
= &LibContext
->CommandPacket
;
1310 CallerEvent
= LibContext
->CallerEvent
;
1313 // Update SCSI Read/Write operation results
1315 *LibContext
->SenseDataLength
= CommandPacket
->SenseDataLength
;
1316 *LibContext
->HostAdapterStatus
= CommandPacket
->HostAdapterStatus
;
1317 *LibContext
->TargetStatus
= CommandPacket
->TargetStatus
;
1318 if (CommandPacket
->InDataBuffer
!= NULL
) {
1319 *LibContext
->DataLength
= CommandPacket
->InTransferLength
;
1321 *LibContext
->DataLength
= CommandPacket
->OutTransferLength
;
1324 if (CommandPacket
->Cdb
!= NULL
) {
1325 FreePool (CommandPacket
->Cdb
);
1329 gBS
->CloseEvent (Event
);
1330 gBS
->SignalEvent (CallerEvent
);
1335 Execute blocking/non-blocking Read(10) SCSI command on a specific SCSI
1338 Executes the SCSI Read(10) command on the SCSI target specified by ScsiIo.
1339 When Event is NULL, blocking command will be executed. Otherwise non-blocking
1340 command will be executed.
1341 For blocking I/O, if Timeout is zero, this function will wait indefinitely
1342 for the command to complete. If Timeout is greater than zero, then the
1343 command is executed and will timeout after Timeout 100 ns units.
1344 For non-blocking I/O, if Timeout is zero, Event will be signaled only after
1345 the command to completes. If Timeout is greater than zero, Event will also be
1346 signaled after Timeout 100 ns units.
1347 The StartLba and SectorSize parameters are used to construct the CDB for this
1350 If ScsiIo is NULL, then ASSERT().
1351 If SenseDataLength is NULL, then ASSERT().
1352 If HostAdapterStatus is NULL, then ASSERT().
1353 If TargetStatus is NULL, then ASSERT().
1354 If DataLength is NULL, then ASSERT().
1356 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet
1357 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1358 EFI_INVALID_PARAMETER gets returned.
1360 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet
1361 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1362 EFI_INVALID_PARAMETER gets returned.
1364 @param[in] ScsiIo A pointer to SCSI IO protocol.
1365 @param[in] Timeout The length of timeout period.
1366 @param[in, out] SenseData A pointer to output sense data.
1367 @param[in, out] SenseDataLength The length of output sense data.
1368 @param[out] HostAdapterStatus The status of Host Adapter.
1369 @param[out] TargetStatus The status of the target.
1370 @param[in, out] DataBuffer Read 16 command data.
1371 @param[in, out] DataLength The length of data buffer.
1372 @param[in] StartLba The start address of LBA.
1373 @param[in] SectorSize The number of contiguous logical blocks
1374 of data that shall be transferred.
1375 @param[in] Event If the SCSI target does not support
1376 non-blocking I/O, then Event is ignored,
1377 and blocking I/O is performed. If Event
1378 is NULL, then blocking I/O is performed.
1379 If Event is not NULL and non-blocking
1380 I/O is supported, then non-blocking I/O
1381 is performed, and Event will be signaled
1382 when the SCSI Read(10) command
1385 @retval EFI_SUCCESS Command is executed successfully.
1386 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
1387 but the entire DataBuffer could not be
1388 transferred. The actual number of bytes
1389 transferred is returned in DataLength.
1390 @retval EFI_NOT_READY The SCSI Request Packet could not be
1391 sent because there are too many SCSI
1392 Command Packets already queued.
1393 @retval EFI_DEVICE_ERROR A device error occurred while attempting
1394 to send SCSI Request Packet.
1395 @retval EFI_UNSUPPORTED The command described by the SCSI
1396 Request Packet is not supported by the
1397 SCSI initiator(i.e., SCSI Host
1399 @retval EFI_TIMEOUT A timeout occurred while waiting for the
1400 SCSI Request Packet to execute.
1401 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet
1403 @retval EFI_OUT_OF_RESOURCES The request could not be completed due
1404 to a lack of resources.
1409 ScsiRead10CommandEx (
1410 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1412 IN OUT VOID
*SenseData
, OPTIONAL
1413 IN OUT UINT8
*SenseDataLength
,
1414 OUT UINT8
*HostAdapterStatus
,
1415 OUT UINT8
*TargetStatus
,
1416 IN OUT VOID
*DataBuffer
, OPTIONAL
1417 IN OUT UINT32
*DataLength
,
1419 IN UINT32 SectorSize
,
1420 IN EFI_EVENT Event OPTIONAL
1423 EFI_SCSI_LIB_ASYNC_CONTEXT
*Context
;
1424 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
1427 EFI_EVENT SelfEvent
;
1429 if (Event
== NULL
) {
1430 return ScsiRead10Command (
1444 ASSERT (SenseDataLength
!= NULL
);
1445 ASSERT (HostAdapterStatus
!= NULL
);
1446 ASSERT (TargetStatus
!= NULL
);
1447 ASSERT (DataLength
!= NULL
);
1448 ASSERT (ScsiIo
!= NULL
);
1450 Context
= AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT
));
1451 if (Context
== NULL
) {
1452 return EFI_OUT_OF_RESOURCES
;
1455 Cdb
= AllocateZeroPool (EFI_SCSI_OP_LENGTH_TEN
);
1457 Status
= EFI_OUT_OF_RESOURCES
;
1461 Context
->SenseDataLength
= SenseDataLength
;
1462 Context
->HostAdapterStatus
= HostAdapterStatus
;
1463 Context
->TargetStatus
= TargetStatus
;
1464 Context
->CallerEvent
= Event
;
1466 CommandPacket
= &Context
->CommandPacket
;
1467 CommandPacket
->Timeout
= Timeout
;
1468 CommandPacket
->InDataBuffer
= DataBuffer
;
1469 CommandPacket
->SenseData
= SenseData
;
1470 CommandPacket
->InTransferLength
= *DataLength
;
1471 CommandPacket
->Cdb
= Cdb
;
1473 // Fill Cdb for Read (10) Command
1475 Cdb
[0] = EFI_SCSI_OP_READ10
;
1476 WriteUnaligned32 ((UINT32
*)&Cdb
[2], SwapBytes32 (StartLba
));
1477 WriteUnaligned16 ((UINT16
*)&Cdb
[7], SwapBytes16 ((UINT16
) SectorSize
));
1479 CommandPacket
->CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
1480 CommandPacket
->DataDirection
= EFI_SCSI_DATA_IN
;
1481 CommandPacket
->SenseDataLength
= *SenseDataLength
;
1486 Status
= gBS
->CreateEvent (
1493 if (EFI_ERROR(Status
)) {
1497 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, CommandPacket
, SelfEvent
);
1498 if (EFI_ERROR(Status
)) {
1500 // Since ScsiLibNotify() will not be signaled if ExecuteScsiCommand()
1501 // returns with error, close the event here.
1503 gBS
->CloseEvent (SelfEvent
);
1510 if (Context
!= NULL
) {
1519 Execute blocking/non-blocking Write(10) SCSI command on a specific SCSI
1522 Executes the SCSI Write(10) command on the SCSI target specified by ScsiIo.
1523 When Event is NULL, blocking command will be executed. Otherwise non-blocking
1524 command will be executed.
1525 For blocking I/O, if Timeout is zero, this function will wait indefinitely
1526 for the command to complete. If Timeout is greater than zero, then the
1527 command is executed and will timeout after Timeout 100 ns units.
1528 For non-blocking I/O, if Timeout is zero, Event will be signaled only after
1529 the command to completes. If Timeout is greater than zero, Event will also be
1530 signaled after Timeout 100 ns units.
1531 The StartLba and SectorSize parameters are used to construct the CDB for this
1534 If ScsiIo is NULL, then ASSERT().
1535 If SenseDataLength is NULL, then ASSERT().
1536 If HostAdapterStatus is NULL, then ASSERT().
1537 If TargetStatus is NULL, then ASSERT().
1538 If DataLength is NULL, then ASSERT().
1540 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet
1541 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1542 EFI_INVALID_PARAMETER gets returned.
1544 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet
1545 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1546 EFI_INVALID_PARAMETER gets returned.
1548 @param[in] ScsiIo SCSI IO Protocol to use
1549 @param[in] Timeout The length of timeout period.
1550 @param[in, out] SenseData A pointer to output sense data.
1551 @param[in, out] SenseDataLength The length of output sense data.
1552 @param[out] HostAdapterStatus The status of Host Adapter.
1553 @param[out] TargetStatus The status of the target.
1554 @param[in, out] DataBuffer A pointer to a data buffer.
1555 @param[in, out] DataLength The length of data buffer.
1556 @param[in] StartLba The start address of LBA.
1557 @param[in] SectorSize The number of contiguous logical blocks
1558 of data that shall be transferred.
1559 @param[in] Event If the SCSI target does not support
1560 non-blocking I/O, then Event is ignored,
1561 and blocking I/O is performed. If Event
1562 is NULL, then blocking I/O is performed.
1563 If Event is not NULL and non-blocking
1564 I/O is supported, then non-blocking I/O
1565 is performed, and Event will be signaled
1566 when the SCSI Write(10) command
1569 @retval EFI_SUCCESS Command is executed successfully.
1570 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
1571 but the entire DataBuffer could not be
1572 transferred. The actual number of bytes
1573 transferred is returned in DataLength.
1574 @retval EFI_NOT_READY The SCSI Request Packet could not be
1575 sent because there are too many SCSI
1576 Command Packets already queued.
1577 @retval EFI_DEVICE_ERROR A device error occurred while attempting
1578 to send SCSI Request Packet.
1579 @retval EFI_UNSUPPORTED The command described by the SCSI
1580 Request Packet is not supported by the
1581 SCSI initiator(i.e., SCSI Host
1583 @retval EFI_TIMEOUT A timeout occurred while waiting for the
1584 SCSI Request Packet to execute.
1585 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet
1587 @retval EFI_OUT_OF_RESOURCES The request could not be completed due
1588 to a lack of resources.
1593 ScsiWrite10CommandEx (
1594 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1596 IN OUT VOID
*SenseData
, OPTIONAL
1597 IN OUT UINT8
*SenseDataLength
,
1598 OUT UINT8
*HostAdapterStatus
,
1599 OUT UINT8
*TargetStatus
,
1600 IN OUT VOID
*DataBuffer
, OPTIONAL
1601 IN OUT UINT32
*DataLength
,
1603 IN UINT32 SectorSize
,
1604 IN EFI_EVENT Event OPTIONAL
1607 EFI_SCSI_LIB_ASYNC_CONTEXT
*Context
;
1608 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
1611 EFI_EVENT SelfEvent
;
1613 if (Event
== NULL
) {
1614 return ScsiWrite10Command (
1628 ASSERT (SenseDataLength
!= NULL
);
1629 ASSERT (HostAdapterStatus
!= NULL
);
1630 ASSERT (TargetStatus
!= NULL
);
1631 ASSERT (DataLength
!= NULL
);
1632 ASSERT (ScsiIo
!= NULL
);
1634 Context
= AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT
));
1635 if (Context
== NULL
) {
1636 return EFI_OUT_OF_RESOURCES
;
1639 Cdb
= AllocateZeroPool (EFI_SCSI_OP_LENGTH_TEN
);
1641 Status
= EFI_OUT_OF_RESOURCES
;
1645 Context
->SenseDataLength
= SenseDataLength
;
1646 Context
->HostAdapterStatus
= HostAdapterStatus
;
1647 Context
->TargetStatus
= TargetStatus
;
1648 Context
->CallerEvent
= Event
;
1650 CommandPacket
= &Context
->CommandPacket
;
1651 CommandPacket
->Timeout
= Timeout
;
1652 CommandPacket
->OutDataBuffer
= DataBuffer
;
1653 CommandPacket
->SenseData
= SenseData
;
1654 CommandPacket
->OutTransferLength
= *DataLength
;
1655 CommandPacket
->Cdb
= Cdb
;
1657 // Fill Cdb for Write (10) Command
1659 Cdb
[0] = EFI_SCSI_OP_WRITE10
;
1660 WriteUnaligned32 ((UINT32
*)&Cdb
[2], SwapBytes32 (StartLba
));
1661 WriteUnaligned16 ((UINT16
*)&Cdb
[7], SwapBytes16 ((UINT16
) SectorSize
));
1663 CommandPacket
->CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
1664 CommandPacket
->DataDirection
= EFI_SCSI_DATA_OUT
;
1665 CommandPacket
->SenseDataLength
= *SenseDataLength
;
1670 Status
= gBS
->CreateEvent (
1677 if (EFI_ERROR(Status
)) {
1681 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, CommandPacket
, SelfEvent
);
1682 if (EFI_ERROR(Status
)) {
1684 // Since ScsiLibNotify() will not be signaled if ExecuteScsiCommand()
1685 // returns with error, close the event here.
1687 gBS
->CloseEvent (SelfEvent
);
1694 if (Context
!= NULL
) {
1703 Execute blocking/non-blocking Read(16) SCSI command on a specific SCSI
1706 Executes the SCSI Read(16) command on the SCSI target specified by ScsiIo.
1707 When Event is NULL, blocking command will be executed. Otherwise non-blocking
1708 command will be executed.
1709 For blocking I/O, if Timeout is zero, this function will wait indefinitely
1710 for the command to complete. If Timeout is greater than zero, then the
1711 command is executed and will timeout after Timeout 100 ns units.
1712 For non-blocking I/O, if Timeout is zero, Event will be signaled only after
1713 the command to completes. If Timeout is greater than zero, Event will also be
1714 signaled after Timeout 100 ns units.
1715 The StartLba and SectorSize parameters are used to construct the CDB for this
1718 If ScsiIo is NULL, then ASSERT().
1719 If SenseDataLength is NULL, then ASSERT().
1720 If HostAdapterStatus is NULL, then ASSERT().
1721 If TargetStatus is NULL, then ASSERT().
1722 If DataLength is NULL, then ASSERT().
1724 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet
1725 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1726 EFI_INVALID_PARAMETER gets returned.
1728 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet
1729 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1730 EFI_INVALID_PARAMETER gets returned.
1732 @param[in] ScsiIo A pointer to SCSI IO protocol.
1733 @param[in] Timeout The length of timeout period.
1734 @param[in, out] SenseData A pointer to output sense data.
1735 @param[in, out] SenseDataLength The length of output sense data.
1736 @param[out] HostAdapterStatus The status of Host Adapter.
1737 @param[out] TargetStatus The status of the target.
1738 @param[in, out] DataBuffer Read 16 command data.
1739 @param[in, out] DataLength The length of data buffer.
1740 @param[in] StartLba The start address of LBA.
1741 @param[in] SectorSize The number of contiguous logical blocks
1742 of data that shall be transferred.
1743 @param[in] Event If the SCSI target does not support
1744 non-blocking I/O, then Event is ignored,
1745 and blocking I/O is performed. If Event
1746 is NULL, then blocking I/O is performed.
1747 If Event is not NULL and non-blocking
1748 I/O is supported, then non-blocking I/O
1749 is performed, and Event will be signaled
1750 when the SCSI Read(16) command
1753 @retval EFI_SUCCESS Command is executed successfully.
1754 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
1755 but the entire DataBuffer could not be
1756 transferred. The actual number of bytes
1757 transferred is returned in DataLength.
1758 @retval EFI_NOT_READY The SCSI Request Packet could not be
1759 sent because there are too many SCSI
1760 Command Packets already queued.
1761 @retval EFI_DEVICE_ERROR A device error occurred while attempting
1762 to send SCSI Request Packet.
1763 @retval EFI_UNSUPPORTED The command described by the SCSI
1764 Request Packet is not supported by the
1765 SCSI initiator(i.e., SCSI Host
1767 @retval EFI_TIMEOUT A timeout occurred while waiting for the
1768 SCSI Request Packet to execute.
1769 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet
1771 @retval EFI_OUT_OF_RESOURCES The request could not be completed due
1772 to a lack of resources.
1777 ScsiRead16CommandEx (
1778 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1780 IN OUT VOID
*SenseData
, OPTIONAL
1781 IN OUT UINT8
*SenseDataLength
,
1782 OUT UINT8
*HostAdapterStatus
,
1783 OUT UINT8
*TargetStatus
,
1784 IN OUT VOID
*DataBuffer
, OPTIONAL
1785 IN OUT UINT32
*DataLength
,
1787 IN UINT32 SectorSize
,
1788 IN EFI_EVENT Event OPTIONAL
1791 EFI_SCSI_LIB_ASYNC_CONTEXT
*Context
;
1792 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
1795 EFI_EVENT SelfEvent
;
1797 if (Event
== NULL
) {
1798 return ScsiRead16Command (
1812 ASSERT (SenseDataLength
!= NULL
);
1813 ASSERT (HostAdapterStatus
!= NULL
);
1814 ASSERT (TargetStatus
!= NULL
);
1815 ASSERT (DataLength
!= NULL
);
1816 ASSERT (ScsiIo
!= NULL
);
1818 Context
= AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT
));
1819 if (Context
== NULL
) {
1820 return EFI_OUT_OF_RESOURCES
;
1823 Cdb
= AllocateZeroPool (EFI_SCSI_OP_LENGTH_SIXTEEN
);
1825 Status
= EFI_OUT_OF_RESOURCES
;
1829 Context
->SenseDataLength
= SenseDataLength
;
1830 Context
->HostAdapterStatus
= HostAdapterStatus
;
1831 Context
->TargetStatus
= TargetStatus
;
1832 Context
->CallerEvent
= Event
;
1834 CommandPacket
= &Context
->CommandPacket
;
1835 CommandPacket
->Timeout
= Timeout
;
1836 CommandPacket
->InDataBuffer
= DataBuffer
;
1837 CommandPacket
->SenseData
= SenseData
;
1838 CommandPacket
->InTransferLength
= *DataLength
;
1839 CommandPacket
->Cdb
= Cdb
;
1841 // Fill Cdb for Read (16) Command
1843 Cdb
[0] = EFI_SCSI_OP_READ16
;
1844 WriteUnaligned64 ((UINT64
*)&Cdb
[2], SwapBytes64 (StartLba
));
1845 WriteUnaligned32 ((UINT32
*)&Cdb
[10], SwapBytes32 (SectorSize
));
1847 CommandPacket
->CdbLength
= EFI_SCSI_OP_LENGTH_SIXTEEN
;
1848 CommandPacket
->DataDirection
= EFI_SCSI_DATA_IN
;
1849 CommandPacket
->SenseDataLength
= *SenseDataLength
;
1854 Status
= gBS
->CreateEvent (
1861 if (EFI_ERROR(Status
)) {
1865 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, CommandPacket
, SelfEvent
);
1866 if (EFI_ERROR(Status
)) {
1868 // Since ScsiLibNotify() will not be signaled if ExecuteScsiCommand()
1869 // returns with error, close the event here.
1871 gBS
->CloseEvent (SelfEvent
);
1878 if (Context
!= NULL
) {
1887 Execute blocking/non-blocking Write(16) SCSI command on a specific SCSI
1890 Executes the SCSI Write(16) command on the SCSI target specified by ScsiIo.
1891 When Event is NULL, blocking command will be executed. Otherwise non-blocking
1892 command will be executed.
1893 For blocking I/O, if Timeout is zero, this function will wait indefinitely
1894 for the command to complete. If Timeout is greater than zero, then the
1895 command is executed and will timeout after Timeout 100 ns units.
1896 For non-blocking I/O, if Timeout is zero, Event will be signaled only after
1897 the command to completes. If Timeout is greater than zero, Event will also be
1898 signaled after Timeout 100 ns units.
1899 The StartLba and SectorSize parameters are used to construct the CDB for this
1902 If ScsiIo is NULL, then ASSERT().
1903 If SenseDataLength is NULL, then ASSERT().
1904 If HostAdapterStatus is NULL, then ASSERT().
1905 If TargetStatus is NULL, then ASSERT().
1906 If DataLength is NULL, then ASSERT().
1908 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet
1909 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1910 EFI_INVALID_PARAMETER gets returned.
1912 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet
1913 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1914 EFI_INVALID_PARAMETER gets returned.
1916 @param[in] ScsiIo SCSI IO Protocol to use
1917 @param[in] Timeout The length of timeout period.
1918 @param[in, out] SenseData A pointer to output sense data.
1919 @param[in, out] SenseDataLength The length of output sense data.
1920 @param[out] HostAdapterStatus The status of Host Adapter.
1921 @param[out] TargetStatus The status of the target.
1922 @param[in, out] DataBuffer A pointer to a data buffer.
1923 @param[in, out] DataLength The length of data buffer.
1924 @param[in] StartLba The start address of LBA.
1925 @param[in] SectorSize The number of contiguous logical blocks
1926 of data that shall be transferred.
1927 @param[in] Event If the SCSI target does not support
1928 non-blocking I/O, then Event is ignored,
1929 and blocking I/O is performed. If Event
1930 is NULL, then blocking I/O is performed.
1931 If Event is not NULL and non-blocking
1932 I/O is supported, then non-blocking I/O
1933 is performed, and Event will be signaled
1934 when the SCSI Write(16) command
1937 @retval EFI_SUCCESS Command is executed successfully.
1938 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
1939 but the entire DataBuffer could not be
1940 transferred. The actual number of bytes
1941 transferred is returned in DataLength.
1942 @retval EFI_NOT_READY The SCSI Request Packet could not be
1943 sent because there are too many SCSI
1944 Command Packets already queued.
1945 @retval EFI_DEVICE_ERROR A device error occurred while attempting
1946 to send SCSI Request Packet.
1947 @retval EFI_UNSUPPORTED The command described by the SCSI
1948 Request Packet is not supported by the
1949 SCSI initiator(i.e., SCSI Host
1951 @retval EFI_TIMEOUT A timeout occurred while waiting for the
1952 SCSI Request Packet to execute.
1953 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet
1955 @retval EFI_OUT_OF_RESOURCES The request could not be completed due
1956 to a lack of resources.
1961 ScsiWrite16CommandEx (
1962 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1964 IN OUT VOID
*SenseData
, OPTIONAL
1965 IN OUT UINT8
*SenseDataLength
,
1966 OUT UINT8
*HostAdapterStatus
,
1967 OUT UINT8
*TargetStatus
,
1968 IN OUT VOID
*DataBuffer
, OPTIONAL
1969 IN OUT UINT32
*DataLength
,
1971 IN UINT32 SectorSize
,
1972 IN EFI_EVENT Event OPTIONAL
1975 EFI_SCSI_LIB_ASYNC_CONTEXT
*Context
;
1976 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
1979 EFI_EVENT SelfEvent
;
1981 if (Event
== NULL
) {
1982 return ScsiWrite16Command (
1996 ASSERT (SenseDataLength
!= NULL
);
1997 ASSERT (HostAdapterStatus
!= NULL
);
1998 ASSERT (TargetStatus
!= NULL
);
1999 ASSERT (DataLength
!= NULL
);
2000 ASSERT (ScsiIo
!= NULL
);
2002 Context
= AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT
));
2003 if (Context
== NULL
) {
2004 return EFI_OUT_OF_RESOURCES
;
2007 Cdb
= AllocateZeroPool (EFI_SCSI_OP_LENGTH_SIXTEEN
);
2009 Status
= EFI_OUT_OF_RESOURCES
;
2013 Context
->SenseDataLength
= SenseDataLength
;
2014 Context
->HostAdapterStatus
= HostAdapterStatus
;
2015 Context
->TargetStatus
= TargetStatus
;
2016 Context
->CallerEvent
= Event
;
2018 CommandPacket
= &Context
->CommandPacket
;
2019 CommandPacket
->Timeout
= Timeout
;
2020 CommandPacket
->OutDataBuffer
= DataBuffer
;
2021 CommandPacket
->SenseData
= SenseData
;
2022 CommandPacket
->OutTransferLength
= *DataLength
;
2023 CommandPacket
->Cdb
= Cdb
;
2025 // Fill Cdb for Write (16) Command
2027 Cdb
[0] = EFI_SCSI_OP_WRITE16
;
2028 WriteUnaligned64 ((UINT64
*)&Cdb
[2], SwapBytes64 (StartLba
));
2029 WriteUnaligned32 ((UINT32
*)&Cdb
[10], SwapBytes32 (SectorSize
));
2031 CommandPacket
->CdbLength
= EFI_SCSI_OP_LENGTH_SIXTEEN
;
2032 CommandPacket
->DataDirection
= EFI_SCSI_DATA_OUT
;
2033 CommandPacket
->SenseDataLength
= *SenseDataLength
;
2038 Status
= gBS
->CreateEvent (
2045 if (EFI_ERROR(Status
)) {
2049 Status
= ScsiIo
->ExecuteScsiCommand (ScsiIo
, CommandPacket
, SelfEvent
);
2050 if (EFI_ERROR(Status
)) {
2052 // Since ScsiLibNotify() will not be signaled if ExecuteScsiCommand()
2053 // returns with error, close the event here.
2055 gBS
->CloseEvent (SelfEvent
);
2062 if (Context
!= NULL
) {