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 return ScsiIo
->ExecuteScsiCommand (ScsiIo
, CommandPacket
, SelfEvent
);
1500 if (Context
!= NULL
) {
1509 Execute blocking/non-blocking Write(10) SCSI command on a specific SCSI
1512 Executes the SCSI Write(10) command on the SCSI target specified by ScsiIo.
1513 When Event is NULL, blocking command will be executed. Otherwise non-blocking
1514 command will be executed.
1515 For blocking I/O, if Timeout is zero, this function will wait indefinitely
1516 for the command to complete. If Timeout is greater than zero, then the
1517 command is executed and will timeout after Timeout 100 ns units.
1518 For non-blocking I/O, if Timeout is zero, Event will be signaled only after
1519 the command to completes. If Timeout is greater than zero, Event will also be
1520 signaled after Timeout 100 ns units.
1521 The StartLba and SectorSize parameters are used to construct the CDB for this
1524 If ScsiIo is NULL, then ASSERT().
1525 If SenseDataLength is NULL, then ASSERT().
1526 If HostAdapterStatus is NULL, then ASSERT().
1527 If TargetStatus is NULL, then ASSERT().
1528 If DataLength is NULL, then ASSERT().
1530 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet
1531 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1532 EFI_INVALID_PARAMETER gets returned.
1534 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet
1535 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1536 EFI_INVALID_PARAMETER gets returned.
1538 @param[in] ScsiIo SCSI IO Protocol to use
1539 @param[in] Timeout The length of timeout period.
1540 @param[in, out] SenseData A pointer to output sense data.
1541 @param[in, out] SenseDataLength The length of output sense data.
1542 @param[out] HostAdapterStatus The status of Host Adapter.
1543 @param[out] TargetStatus The status of the target.
1544 @param[in, out] DataBuffer A pointer to a data buffer.
1545 @param[in, out] DataLength The length of data buffer.
1546 @param[in] StartLba The start address of LBA.
1547 @param[in] SectorSize The number of contiguous logical blocks
1548 of data that shall be transferred.
1549 @param[in] Event If the SCSI target does not support
1550 non-blocking I/O, then Event is ignored,
1551 and blocking I/O is performed. If Event
1552 is NULL, then blocking I/O is performed.
1553 If Event is not NULL and non-blocking
1554 I/O is supported, then non-blocking I/O
1555 is performed, and Event will be signaled
1556 when the SCSI Write(10) command
1559 @retval EFI_SUCCESS Command is executed successfully.
1560 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
1561 but the entire DataBuffer could not be
1562 transferred. The actual number of bytes
1563 transferred is returned in DataLength.
1564 @retval EFI_NOT_READY The SCSI Request Packet could not be
1565 sent because there are too many SCSI
1566 Command Packets already queued.
1567 @retval EFI_DEVICE_ERROR A device error occurred while attempting
1568 to send SCSI Request Packet.
1569 @retval EFI_UNSUPPORTED The command described by the SCSI
1570 Request Packet is not supported by the
1571 SCSI initiator(i.e., SCSI Host
1573 @retval EFI_TIMEOUT A timeout occurred while waiting for the
1574 SCSI Request Packet to execute.
1575 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet
1577 @retval EFI_OUT_OF_RESOURCES The request could not be completed due
1578 to a lack of resources.
1583 ScsiWrite10CommandEx (
1584 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1586 IN OUT VOID
*SenseData
, OPTIONAL
1587 IN OUT UINT8
*SenseDataLength
,
1588 OUT UINT8
*HostAdapterStatus
,
1589 OUT UINT8
*TargetStatus
,
1590 IN OUT VOID
*DataBuffer
, OPTIONAL
1591 IN OUT UINT32
*DataLength
,
1593 IN UINT32 SectorSize
,
1594 IN EFI_EVENT Event OPTIONAL
1597 EFI_SCSI_LIB_ASYNC_CONTEXT
*Context
;
1598 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
1601 EFI_EVENT SelfEvent
;
1603 if (Event
== NULL
) {
1604 return ScsiWrite10Command (
1618 ASSERT (SenseDataLength
!= NULL
);
1619 ASSERT (HostAdapterStatus
!= NULL
);
1620 ASSERT (TargetStatus
!= NULL
);
1621 ASSERT (DataLength
!= NULL
);
1622 ASSERT (ScsiIo
!= NULL
);
1624 Context
= AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT
));
1625 if (Context
== NULL
) {
1626 return EFI_OUT_OF_RESOURCES
;
1629 Cdb
= AllocateZeroPool (EFI_SCSI_OP_LENGTH_TEN
);
1631 Status
= EFI_OUT_OF_RESOURCES
;
1635 Context
->SenseDataLength
= SenseDataLength
;
1636 Context
->HostAdapterStatus
= HostAdapterStatus
;
1637 Context
->TargetStatus
= TargetStatus
;
1638 Context
->CallerEvent
= Event
;
1640 CommandPacket
= &Context
->CommandPacket
;
1641 CommandPacket
->Timeout
= Timeout
;
1642 CommandPacket
->OutDataBuffer
= DataBuffer
;
1643 CommandPacket
->SenseData
= SenseData
;
1644 CommandPacket
->OutTransferLength
= *DataLength
;
1645 CommandPacket
->Cdb
= Cdb
;
1647 // Fill Cdb for Write (10) Command
1649 Cdb
[0] = EFI_SCSI_OP_WRITE10
;
1650 WriteUnaligned32 ((UINT32
*)&Cdb
[2], SwapBytes32 (StartLba
));
1651 WriteUnaligned16 ((UINT16
*)&Cdb
[7], SwapBytes16 ((UINT16
) SectorSize
));
1653 CommandPacket
->CdbLength
= EFI_SCSI_OP_LENGTH_TEN
;
1654 CommandPacket
->DataDirection
= EFI_SCSI_DATA_OUT
;
1655 CommandPacket
->SenseDataLength
= *SenseDataLength
;
1660 Status
= gBS
->CreateEvent (
1667 if (EFI_ERROR(Status
)) {
1671 return ScsiIo
->ExecuteScsiCommand (ScsiIo
, CommandPacket
, Event
);
1674 if (Context
!= NULL
) {
1683 Execute blocking/non-blocking Read(16) SCSI command on a specific SCSI
1686 Executes the SCSI Read(16) command on the SCSI target specified by ScsiIo.
1687 When Event is NULL, blocking command will be executed. Otherwise non-blocking
1688 command will be executed.
1689 For blocking I/O, if Timeout is zero, this function will wait indefinitely
1690 for the command to complete. If Timeout is greater than zero, then the
1691 command is executed and will timeout after Timeout 100 ns units.
1692 For non-blocking I/O, if Timeout is zero, Event will be signaled only after
1693 the command to completes. If Timeout is greater than zero, Event will also be
1694 signaled after Timeout 100 ns units.
1695 The StartLba and SectorSize parameters are used to construct the CDB for this
1698 If ScsiIo is NULL, then ASSERT().
1699 If SenseDataLength is NULL, then ASSERT().
1700 If HostAdapterStatus is NULL, then ASSERT().
1701 If TargetStatus is NULL, then ASSERT().
1702 If DataLength is NULL, then ASSERT().
1704 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet
1705 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1706 EFI_INVALID_PARAMETER gets returned.
1708 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet
1709 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1710 EFI_INVALID_PARAMETER gets returned.
1712 @param[in] ScsiIo A pointer to SCSI IO protocol.
1713 @param[in] Timeout The length of timeout period.
1714 @param[in, out] SenseData A pointer to output sense data.
1715 @param[in, out] SenseDataLength The length of output sense data.
1716 @param[out] HostAdapterStatus The status of Host Adapter.
1717 @param[out] TargetStatus The status of the target.
1718 @param[in, out] DataBuffer Read 16 command data.
1719 @param[in, out] DataLength The length of data buffer.
1720 @param[in] StartLba The start address of LBA.
1721 @param[in] SectorSize The number of contiguous logical blocks
1722 of data that shall be transferred.
1723 @param[in] Event If the SCSI target does not support
1724 non-blocking I/O, then Event is ignored,
1725 and blocking I/O is performed. If Event
1726 is NULL, then blocking I/O is performed.
1727 If Event is not NULL and non-blocking
1728 I/O is supported, then non-blocking I/O
1729 is performed, and Event will be signaled
1730 when the SCSI Read(16) command
1733 @retval EFI_SUCCESS Command is executed successfully.
1734 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
1735 but the entire DataBuffer could not be
1736 transferred. The actual number of bytes
1737 transferred is returned in DataLength.
1738 @retval EFI_NOT_READY The SCSI Request Packet could not be
1739 sent because there are too many SCSI
1740 Command Packets already queued.
1741 @retval EFI_DEVICE_ERROR A device error occurred while attempting
1742 to send SCSI Request Packet.
1743 @retval EFI_UNSUPPORTED The command described by the SCSI
1744 Request Packet is not supported by the
1745 SCSI initiator(i.e., SCSI Host
1747 @retval EFI_TIMEOUT A timeout occurred while waiting for the
1748 SCSI Request Packet to execute.
1749 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet
1751 @retval EFI_OUT_OF_RESOURCES The request could not be completed due
1752 to a lack of resources.
1757 ScsiRead16CommandEx (
1758 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1760 IN OUT VOID
*SenseData
, OPTIONAL
1761 IN OUT UINT8
*SenseDataLength
,
1762 OUT UINT8
*HostAdapterStatus
,
1763 OUT UINT8
*TargetStatus
,
1764 IN OUT VOID
*DataBuffer
, OPTIONAL
1765 IN OUT UINT32
*DataLength
,
1767 IN UINT32 SectorSize
,
1768 IN EFI_EVENT Event OPTIONAL
1771 EFI_SCSI_LIB_ASYNC_CONTEXT
*Context
;
1772 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
1775 EFI_EVENT SelfEvent
;
1777 if (Event
== NULL
) {
1778 return ScsiRead16Command (
1792 ASSERT (SenseDataLength
!= NULL
);
1793 ASSERT (HostAdapterStatus
!= NULL
);
1794 ASSERT (TargetStatus
!= NULL
);
1795 ASSERT (DataLength
!= NULL
);
1796 ASSERT (ScsiIo
!= NULL
);
1798 Context
= AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT
));
1799 if (Context
== NULL
) {
1800 return EFI_OUT_OF_RESOURCES
;
1803 Cdb
= AllocateZeroPool (EFI_SCSI_OP_LENGTH_SIXTEEN
);
1805 Status
= EFI_OUT_OF_RESOURCES
;
1809 Context
->SenseDataLength
= SenseDataLength
;
1810 Context
->HostAdapterStatus
= HostAdapterStatus
;
1811 Context
->TargetStatus
= TargetStatus
;
1812 Context
->CallerEvent
= Event
;
1814 CommandPacket
= &Context
->CommandPacket
;
1815 CommandPacket
->Timeout
= Timeout
;
1816 CommandPacket
->InDataBuffer
= DataBuffer
;
1817 CommandPacket
->SenseData
= SenseData
;
1818 CommandPacket
->InTransferLength
= *DataLength
;
1819 CommandPacket
->Cdb
= Cdb
;
1821 // Fill Cdb for Read (16) Command
1823 Cdb
[0] = EFI_SCSI_OP_READ16
;
1824 WriteUnaligned64 ((UINT64
*)&Cdb
[2], SwapBytes64 (StartLba
));
1825 WriteUnaligned32 ((UINT32
*)&Cdb
[10], SwapBytes32 (SectorSize
));
1827 CommandPacket
->CdbLength
= EFI_SCSI_OP_LENGTH_SIXTEEN
;
1828 CommandPacket
->DataDirection
= EFI_SCSI_DATA_IN
;
1829 CommandPacket
->SenseDataLength
= *SenseDataLength
;
1834 Status
= gBS
->CreateEvent (
1841 if (EFI_ERROR(Status
)) {
1845 return ScsiIo
->ExecuteScsiCommand (ScsiIo
, CommandPacket
, Event
);
1848 if (Context
!= NULL
) {
1857 Execute blocking/non-blocking Write(16) SCSI command on a specific SCSI
1860 Executes the SCSI Write(16) command on the SCSI target specified by ScsiIo.
1861 When Event is NULL, blocking command will be executed. Otherwise non-blocking
1862 command will be executed.
1863 For blocking I/O, if Timeout is zero, this function will wait indefinitely
1864 for the command to complete. If Timeout is greater than zero, then the
1865 command is executed and will timeout after Timeout 100 ns units.
1866 For non-blocking I/O, if Timeout is zero, Event will be signaled only after
1867 the command to completes. If Timeout is greater than zero, Event will also be
1868 signaled after Timeout 100 ns units.
1869 The StartLba and SectorSize parameters are used to construct the CDB for this
1872 If ScsiIo is NULL, then ASSERT().
1873 If SenseDataLength is NULL, then ASSERT().
1874 If HostAdapterStatus is NULL, then ASSERT().
1875 If TargetStatus is NULL, then ASSERT().
1876 If DataLength is NULL, then ASSERT().
1878 If SenseDataLength is non-zero and SenseData is not NULL, SenseData must meet
1879 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1880 EFI_INVALID_PARAMETER gets returned.
1882 If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must meet
1883 buffer alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise
1884 EFI_INVALID_PARAMETER gets returned.
1886 @param[in] ScsiIo SCSI IO Protocol to use
1887 @param[in] Timeout The length of timeout period.
1888 @param[in, out] SenseData A pointer to output sense data.
1889 @param[in, out] SenseDataLength The length of output sense data.
1890 @param[out] HostAdapterStatus The status of Host Adapter.
1891 @param[out] TargetStatus The status of the target.
1892 @param[in, out] DataBuffer A pointer to a data buffer.
1893 @param[in, out] DataLength The length of data buffer.
1894 @param[in] StartLba The start address of LBA.
1895 @param[in] SectorSize The number of contiguous logical blocks
1896 of data that shall be transferred.
1897 @param[in] Event If the SCSI target does not support
1898 non-blocking I/O, then Event is ignored,
1899 and blocking I/O is performed. If Event
1900 is NULL, then blocking I/O is performed.
1901 If Event is not NULL and non-blocking
1902 I/O is supported, then non-blocking I/O
1903 is performed, and Event will be signaled
1904 when the SCSI Write(16) command
1907 @retval EFI_SUCCESS Command is executed successfully.
1908 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
1909 but the entire DataBuffer could not be
1910 transferred. The actual number of bytes
1911 transferred is returned in DataLength.
1912 @retval EFI_NOT_READY The SCSI Request Packet could not be
1913 sent because there are too many SCSI
1914 Command Packets already queued.
1915 @retval EFI_DEVICE_ERROR A device error occurred while attempting
1916 to send SCSI Request Packet.
1917 @retval EFI_UNSUPPORTED The command described by the SCSI
1918 Request Packet is not supported by the
1919 SCSI initiator(i.e., SCSI Host
1921 @retval EFI_TIMEOUT A timeout occurred while waiting for the
1922 SCSI Request Packet to execute.
1923 @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Packet
1925 @retval EFI_OUT_OF_RESOURCES The request could not be completed due
1926 to a lack of resources.
1931 ScsiWrite16CommandEx (
1932 IN EFI_SCSI_IO_PROTOCOL
*ScsiIo
,
1934 IN OUT VOID
*SenseData
, OPTIONAL
1935 IN OUT UINT8
*SenseDataLength
,
1936 OUT UINT8
*HostAdapterStatus
,
1937 OUT UINT8
*TargetStatus
,
1938 IN OUT VOID
*DataBuffer
, OPTIONAL
1939 IN OUT UINT32
*DataLength
,
1941 IN UINT32 SectorSize
,
1942 IN EFI_EVENT Event OPTIONAL
1945 EFI_SCSI_LIB_ASYNC_CONTEXT
*Context
;
1946 EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
;
1949 EFI_EVENT SelfEvent
;
1951 if (Event
== NULL
) {
1952 return ScsiWrite16Command (
1966 ASSERT (SenseDataLength
!= NULL
);
1967 ASSERT (HostAdapterStatus
!= NULL
);
1968 ASSERT (TargetStatus
!= NULL
);
1969 ASSERT (DataLength
!= NULL
);
1970 ASSERT (ScsiIo
!= NULL
);
1972 Context
= AllocateZeroPool (sizeof (EFI_SCSI_LIB_ASYNC_CONTEXT
));
1973 if (Context
== NULL
) {
1974 return EFI_OUT_OF_RESOURCES
;
1977 Cdb
= AllocateZeroPool (EFI_SCSI_OP_LENGTH_SIXTEEN
);
1979 Status
= EFI_OUT_OF_RESOURCES
;
1983 Context
->SenseDataLength
= SenseDataLength
;
1984 Context
->HostAdapterStatus
= HostAdapterStatus
;
1985 Context
->TargetStatus
= TargetStatus
;
1986 Context
->CallerEvent
= Event
;
1988 CommandPacket
= &Context
->CommandPacket
;
1989 CommandPacket
->Timeout
= Timeout
;
1990 CommandPacket
->OutDataBuffer
= DataBuffer
;
1991 CommandPacket
->SenseData
= SenseData
;
1992 CommandPacket
->OutTransferLength
= *DataLength
;
1993 CommandPacket
->Cdb
= Cdb
;
1995 // Fill Cdb for Write (16) Command
1997 Cdb
[0] = EFI_SCSI_OP_WRITE16
;
1998 WriteUnaligned64 ((UINT64
*)&Cdb
[2], SwapBytes64 (StartLba
));
1999 WriteUnaligned32 ((UINT32
*)&Cdb
[10], SwapBytes32 (SectorSize
));
2001 CommandPacket
->CdbLength
= EFI_SCSI_OP_LENGTH_SIXTEEN
;
2002 CommandPacket
->DataDirection
= EFI_SCSI_DATA_OUT
;
2003 CommandPacket
->SenseDataLength
= *SenseDataLength
;
2008 Status
= gBS
->CreateEvent (
2015 if (EFI_ERROR(Status
)) {
2019 return ScsiIo
->ExecuteScsiCommand (ScsiIo
, CommandPacket
, Event
);
2022 if (Context
!= NULL
) {