2 Header file for SCSI Disk Driver.
4 Copyright (c) 2004 - 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.
22 #include <Protocol/ScsiIo.h>
23 #include <Protocol/ComponentName.h>
24 #include <Protocol/BlockIo.h>
25 #include <Protocol/BlockIo2.h>
26 #include <Protocol/DriverBinding.h>
27 #include <Protocol/ScsiPassThruExt.h>
28 #include <Protocol/ScsiPassThru.h>
29 #include <Protocol/DiskInfo.h>
32 #include <Library/DebugLib.h>
33 #include <Library/UefiDriverEntryPoint.h>
34 #include <Library/UefiLib.h>
35 #include <Library/BaseMemoryLib.h>
36 #include <Library/MemoryAllocationLib.h>
37 #include <Library/UefiScsiLib.h>
38 #include <Library/UefiBootServicesTableLib.h>
39 #include <Library/DevicePathLib.h>
41 #include <IndustryStandard/Scsi.h>
42 #include <IndustryStandard/Atapi.h>
44 #define IS_DEVICE_FIXED(a) (a)->FixedDevice ? 1 : 0
46 #define SCSI_DISK_DEV_SIGNATURE SIGNATURE_32 ('s', 'c', 'd', 'k')
53 EFI_BLOCK_IO_PROTOCOL BlkIo
;
54 EFI_BLOCK_IO2_PROTOCOL BlkIo2
;
55 EFI_BLOCK_IO_MEDIA BlkIoMedia
;
56 EFI_SCSI_IO_PROTOCOL
*ScsiIo
;
61 EFI_SCSI_SENSE_DATA
*SenseData
;
62 UINTN SenseDataNumber
;
63 EFI_SCSI_INQUIRY_DATA InquiryData
;
65 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
67 EFI_DISK_INFO_PROTOCOL DiskInfo
;
70 // The following fields are only valid for ATAPI/SATA device
74 ATAPI_IDENTIFY_DATA IdentifyData
;
77 // The flag indicates if 16-byte command can be used
82 // The queue for BlockIo2 requests
84 LIST_ENTRY BlkIo2Queue
;
87 #define SCSI_DISK_DEV_FROM_BLKIO(a) CR (a, SCSI_DISK_DEV, BlkIo, SCSI_DISK_DEV_SIGNATURE)
88 #define SCSI_DISK_DEV_FROM_BLKIO2(a) CR (a, SCSI_DISK_DEV, BlkIo2, SCSI_DISK_DEV_SIGNATURE)
90 #define SCSI_DISK_DEV_FROM_DISKINFO(a) CR (a, SCSI_DISK_DEV, DiskInfo, SCSI_DISK_DEV_SIGNATURE)
93 // Asynchronous I/O request
96 // Private data structure for a BlockIo2 request
99 EFI_BLOCK_IO2_TOKEN
*Token
;
101 // The flag indicates if the last Scsi Read/Write sub-task for a BlockIo2
102 // request is sent to device
107 // The queue for Scsi Read/Write sub-tasks of a BlockIo2 request
109 LIST_ENTRY ScsiRWQueue
;
112 } SCSI_BLKIO2_REQUEST
;
115 // Private data structure for a SCSI Read/Write request
118 SCSI_DISK_DEV
*ScsiDiskDevice
;
120 EFI_SCSI_SENSE_DATA
*SenseData
;
121 UINT8 SenseDataLength
;
122 UINT8 HostAdapterStatus
;
132 // The BlockIo2 request this SCSI command belongs to
134 SCSI_BLKIO2_REQUEST
*BlkIo2Req
;
137 } SCSI_ASYNC_RW_REQUEST
;
142 extern EFI_DRIVER_BINDING_PROTOCOL gScsiDiskDriverBinding
;
143 extern EFI_COMPONENT_NAME_PROTOCOL gScsiDiskComponentName
;
144 extern EFI_COMPONENT_NAME2_PROTOCOL gScsiDiskComponentName2
;
146 // action code used in detect media process
148 #define ACTION_NO_ACTION 0x00
149 #define ACTION_READ_CAPACITY 0x01
150 #define ACTION_RETRY_COMMAND_LATER 0x02
151 #define ACTION_RETRY_WITH_BACKOFF_ALGO 0x03
153 #define SCSI_COMMAND_VERSION_1 0x01
154 #define SCSI_COMMAND_VERSION_2 0x02
155 #define SCSI_COMMAND_VERSION_3 0x03
158 // SCSI Disk Timeout Experience Value
160 #define SCSI_DISK_TIMEOUT EFI_TIMER_PERIOD_SECONDS (3)
163 Test to see if this driver supports ControllerHandle.
165 This service is called by the EFI boot service ConnectController(). In order
166 to make drivers as small as possible, there are a few calling restrictions for
167 this service. ConnectController() must follow these calling restrictions.
168 If any other agent wishes to call Supported() it must also follow these
169 calling restrictions.
171 @param This Protocol instance pointer.
172 @param ControllerHandle Handle of device to test
173 @param RemainingDevicePath Optional parameter use to pick a specific child
176 @retval EFI_SUCCESS This driver supports this device
177 @retval EFI_ALREADY_STARTED This driver is already running on this device
178 @retval other This driver does not support this device
183 ScsiDiskDriverBindingSupported (
184 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
185 IN EFI_HANDLE Controller
,
186 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
190 Start this driver on ControllerHandle.
192 This service is called by the EFI boot service ConnectController(). In order
193 to make drivers as small as possible, there are a few calling restrictions for
194 this service. ConnectController() must follow these calling restrictions. If
195 any other agent wishes to call Start() it must also follow these calling
198 @param This Protocol instance pointer.
199 @param ControllerHandle Handle of device to bind driver to
200 @param RemainingDevicePath Optional parameter use to pick a specific child
203 @retval EFI_SUCCESS This driver is added to ControllerHandle
204 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
205 @retval other This driver does not support this device
210 ScsiDiskDriverBindingStart (
211 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
212 IN EFI_HANDLE Controller
,
213 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
217 Stop this driver on ControllerHandle.
219 This service is called by the EFI boot service DisconnectController().
220 In order to make drivers as small as possible, there are a few calling
221 restrictions for this service. DisconnectController() must follow these
222 calling restrictions. If any other agent wishes to call Stop() it must
223 also follow these calling restrictions.
225 @param This Protocol instance pointer.
226 @param ControllerHandle Handle of device to stop driver on
227 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
228 children is zero stop the entire bus driver.
229 @param ChildHandleBuffer List of Child Handles to Stop.
231 @retval EFI_SUCCESS This driver is removed ControllerHandle
232 @retval other This driver was not removed from this device
237 ScsiDiskDriverBindingStop (
238 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
239 IN EFI_HANDLE Controller
,
240 IN UINTN NumberOfChildren
,
241 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
245 // EFI Component Name Functions
248 Retrieves a Unicode string that is the user readable name of the driver.
250 This function retrieves the user readable name of a driver in the form of a
251 Unicode string. If the driver specified by This has a user readable name in
252 the language specified by Language, then a pointer to the driver name is
253 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
254 by This does not support the language specified by Language,
255 then EFI_UNSUPPORTED is returned.
257 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
258 EFI_COMPONENT_NAME_PROTOCOL instance.
260 @param Language A pointer to a Null-terminated ASCII string
261 array indicating the language. This is the
262 language of the driver name that the caller is
263 requesting, and it must match one of the
264 languages specified in SupportedLanguages. The
265 number of languages supported by a driver is up
266 to the driver writer. Language is specified
267 in RFC 4646 or ISO 639-2 language code format.
269 @param DriverName A pointer to the Unicode string to return.
270 This Unicode string is the name of the
271 driver specified by This in the language
272 specified by Language.
274 @retval EFI_SUCCESS The Unicode string for the Driver specified by
275 This and the language specified by Language was
276 returned in DriverName.
278 @retval EFI_INVALID_PARAMETER Language is NULL.
280 @retval EFI_INVALID_PARAMETER DriverName is NULL.
282 @retval EFI_UNSUPPORTED The driver specified by This does not support
283 the language specified by Language.
288 ScsiDiskComponentNameGetDriverName (
289 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
291 OUT CHAR16
**DriverName
296 Retrieves a Unicode string that is the user readable name of the controller
297 that is being managed by a driver.
299 This function retrieves the user readable name of the controller specified by
300 ControllerHandle and ChildHandle in the form of a Unicode string. If the
301 driver specified by This has a user readable name in the language specified by
302 Language, then a pointer to the controller name is returned in ControllerName,
303 and EFI_SUCCESS is returned. If the driver specified by This is not currently
304 managing the controller specified by ControllerHandle and ChildHandle,
305 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
306 support the language specified by Language, then EFI_UNSUPPORTED is returned.
308 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
309 EFI_COMPONENT_NAME_PROTOCOL instance.
311 @param ControllerHandle The handle of a controller that the driver
312 specified by This is managing. This handle
313 specifies the controller whose name is to be
316 @param ChildHandle The handle of the child controller to retrieve
317 the name of. This is an optional parameter that
318 may be NULL. It will be NULL for device
319 drivers. It will also be NULL for a bus drivers
320 that wish to retrieve the name of the bus
321 controller. It will not be NULL for a bus
322 driver that wishes to retrieve the name of a
325 @param Language A pointer to a Null-terminated ASCII string
326 array indicating the language. This is the
327 language of the driver name that the caller is
328 requesting, and it must match one of the
329 languages specified in SupportedLanguages. The
330 number of languages supported by a driver is up
331 to the driver writer. Language is specified in
332 RFC 4646 or ISO 639-2 language code format.
334 @param ControllerName A pointer to the Unicode string to return.
335 This Unicode string is the name of the
336 controller specified by ControllerHandle and
337 ChildHandle in the language specified by
338 Language from the point of view of the driver
341 @retval EFI_SUCCESS The Unicode string for the user readable name in
342 the language specified by Language for the
343 driver specified by This was returned in
346 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
348 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
351 @retval EFI_INVALID_PARAMETER Language is NULL.
353 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
355 @retval EFI_UNSUPPORTED The driver specified by This is not currently
356 managing the controller specified by
357 ControllerHandle and ChildHandle.
359 @retval EFI_UNSUPPORTED The driver specified by This does not support
360 the language specified by Language.
365 ScsiDiskComponentNameGetControllerName (
366 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
367 IN EFI_HANDLE ControllerHandle
,
368 IN EFI_HANDLE ChildHandle OPTIONAL
,
370 OUT CHAR16
**ControllerName
377 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
378 @param ExtendedVerification The flag about if extend verificate
380 @retval EFI_SUCCESS The device was reset.
381 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
383 @return EFI_STATUS is retured from EFI_SCSI_IO_PROTOCOL.ResetDevice().
389 IN EFI_BLOCK_IO_PROTOCOL
*This
,
390 IN BOOLEAN ExtendedVerification
395 The function is to Read Block from SCSI Disk.
397 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
398 @param MediaId The Id of Media detected
399 @param Lba The logic block address
400 @param BufferSize The size of Buffer
401 @param Buffer The buffer to fill the read out data
403 @retval EFI_SUCCESS Successfully to read out block.
404 @retval EFI_DEVICE_ERROR Fail to detect media.
405 @retval EFI_NO_MEDIA Media is not present.
406 @retval EFI_MEDIA_CHANGED Media has changed.
407 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
408 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
414 IN EFI_BLOCK_IO_PROTOCOL
*This
,
423 The function is to Write Block to SCSI Disk.
425 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
426 @param MediaId The Id of Media detected
427 @param Lba The logic block address
428 @param BufferSize The size of Buffer
429 @param Buffer The buffer to fill the read out data
431 @retval EFI_SUCCESS Successfully to read out block.
432 @retval EFI_WRITE_PROTECTED The device can not be written to.
433 @retval EFI_DEVICE_ERROR Fail to detect media.
434 @retval EFI_NO_MEDIA Media is not present.
435 @retval EFI_MEDIA_CHNAGED Media has changed.
436 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
437 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
442 ScsiDiskWriteBlocks (
443 IN EFI_BLOCK_IO_PROTOCOL
*This
,
454 EFI_SUCCESS is returned directly.
456 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
458 @retval EFI_SUCCESS All outstanding data was written to the device
463 ScsiDiskFlushBlocks (
464 IN EFI_BLOCK_IO_PROTOCOL
*This
471 @param This The pointer of EFI_BLOCK_IO2_PROTOCOL.
472 @param ExtendedVerification The flag about if extend verificate.
474 @retval EFI_SUCCESS The device was reset.
475 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
477 @return EFI_STATUS is returned from EFI_SCSI_IO_PROTOCOL.ResetDevice().
483 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
484 IN BOOLEAN ExtendedVerification
488 The function is to Read Block from SCSI Disk.
490 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
491 @param MediaId The Id of Media detected.
492 @param Lba The logic block address.
493 @param Token A pointer to the token associated with the transaction.
494 @param BufferSize The size of Buffer.
495 @param Buffer The buffer to fill the read out data.
497 @retval EFI_SUCCESS The read request was queued if Token-> Event is
498 not NULL. The data was read correctly from the
499 device if theToken-> Event is NULL.
500 @retval EFI_DEVICE_ERROR The device reported an error while attempting
501 to perform the read operation.
502 @retval EFI_NO_MEDIA There is no media in the device.
503 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
504 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
505 the intrinsic block size of the device.
506 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
507 valid, or the buffer is not on proper
509 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
515 ScsiDiskReadBlocksEx (
516 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
519 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
525 The function is to Write Block to SCSI Disk.
527 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
528 @param MediaId The Id of Media detected.
529 @param Lba The logic block address.
530 @param Token A pointer to the token associated with the transaction.
531 @param BufferSize The size of Buffer.
532 @param Buffer The buffer to fill the read out data.
534 @retval EFI_SUCCESS The data were written correctly to the device.
535 @retval EFI_WRITE_PROTECTED The device cannot be written to.
536 @retval EFI_NO_MEDIA There is no media in the device.
537 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
538 @retval EFI_DEVICE_ERROR The device reported an error while attempting
539 to perform the write operation.
540 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
541 the intrinsic block size of the device.
542 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
543 valid, or the buffer is not on proper
549 ScsiDiskWriteBlocksEx (
550 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
553 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
559 Flush the Block Device.
561 @param This Indicates a pointer to the calling context.
562 @param Token A pointer to the token associated with the transaction.
564 @retval EFI_SUCCESS All outstanding data was written to the device.
565 @retval EFI_DEVICE_ERROR The device reported an error while attempting to
567 @retval EFI_WRITE_PROTECTED The device cannot be written to.
568 @retval EFI_NO_MEDIA There is no media in the device.
569 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
574 ScsiDiskFlushBlocksEx (
575 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
576 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
581 Provides inquiry information for the controller type.
583 This function is used by the IDE bus driver to get inquiry data. Data format
584 of Identify data is defined by the Interface GUID.
586 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
587 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
588 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
590 @retval EFI_SUCCESS The command was accepted without any errors.
591 @retval EFI_NOT_FOUND Device does not support this data class
592 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
593 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
598 ScsiDiskInfoInquiry (
599 IN EFI_DISK_INFO_PROTOCOL
*This
,
600 IN OUT VOID
*InquiryData
,
601 IN OUT UINT32
*InquiryDataSize
606 Provides identify information for the controller type.
608 This function is used by the IDE bus driver to get identify data. Data format
609 of Identify data is defined by the Interface GUID.
611 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
613 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
614 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
617 @retval EFI_SUCCESS The command was accepted without any errors.
618 @retval EFI_NOT_FOUND Device does not support this data class
619 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
620 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
625 ScsiDiskInfoIdentify (
626 IN EFI_DISK_INFO_PROTOCOL
*This
,
627 IN OUT VOID
*IdentifyData
,
628 IN OUT UINT32
*IdentifyDataSize
633 Provides sense data information for the controller type.
635 This function is used by the IDE bus driver to get sense data.
636 Data format of Sense data is defined by the Interface GUID.
638 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
639 @param[in, out] SenseData Pointer to the SenseData.
640 @param[in, out] SenseDataSize Size of SenseData in bytes.
641 @param[out] SenseDataNumber Pointer to the value for the sense data size.
643 @retval EFI_SUCCESS The command was accepted without any errors.
644 @retval EFI_NOT_FOUND Device does not support this data class.
645 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
646 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
651 ScsiDiskInfoSenseData (
652 IN EFI_DISK_INFO_PROTOCOL
*This
,
653 IN OUT VOID
*SenseData
,
654 IN OUT UINT32
*SenseDataSize
,
655 OUT UINT8
*SenseDataNumber
659 This function is used by the IDE bus driver to get controller information.
661 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
662 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
663 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
665 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
666 @retval EFI_UNSUPPORTED This is not an IDE device.
671 ScsiDiskInfoWhichIde (
672 IN EFI_DISK_INFO_PROTOCOL
*This
,
673 OUT UINT32
*IdeChannel
,
674 OUT UINT32
*IdeDevice
679 Detect Device and read out capacity ,if error occurs, parse the sense key.
681 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
682 @param MustReadCapacity The flag about reading device capacity
683 @param MediaChange The pointer of flag indicates if media has changed
685 @retval EFI_DEVICE_ERROR Indicates that error occurs
686 @retval EFI_SUCCESS Successfully to detect media
690 ScsiDiskDetectMedia (
691 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
692 IN BOOLEAN MustReadCapacity
,
693 OUT BOOLEAN
*MediaChange
699 When Test Unit Ready command succeeds, retrieve Sense Keys via Request Sense;
700 When Test Unit Ready command encounters any error caused by host adapter or
701 target, return error without retrieving Sense Keys.
703 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
704 @param NeedRetry The pointer of flag indicates try again
705 @param SenseDataArray The pointer of an array of sense data
706 @param NumberOfSenseKeys The pointer of the number of sense data array
708 @retval EFI_DEVICE_ERROR Indicates that error occurs
709 @retval EFI_SUCCESS Successfully to test unit
713 ScsiDiskTestUnitReady (
714 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
715 OUT BOOLEAN
*NeedRetry
,
716 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
717 OUT UINTN
*NumberOfSenseKeys
722 Parsing Sense Keys which got from request sense command.
724 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
725 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
726 @param NumberOfSenseKeys The number of sense key
727 @param Action The pointer of action which indicates what is need to do next
729 @retval EFI_DEVICE_ERROR Indicates that error occurs
730 @retval EFI_SUCCESS Successfully to complete the parsing
734 DetectMediaParsingSenseKeys (
735 OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
736 IN EFI_SCSI_SENSE_DATA
*SenseData
,
737 IN UINTN NumberOfSenseKeys
,
743 Send read capacity command to device and get the device parameter.
745 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
746 @param NeedRetry The pointer of flag indicates if need a retry
747 @param SenseDataArray The pointer of an array of sense data
748 @param NumberOfSenseKeys The number of sense key
750 @retval EFI_DEVICE_ERROR Indicates that error occurs
751 @retval EFI_SUCCESS Successfully to read capacity
755 ScsiDiskReadCapacity (
756 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
757 OUT BOOLEAN
*NeedRetry
,
758 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
759 OUT UINTN
*NumberOfSenseKeys
763 Check the HostAdapter status and re-interpret it in EFI_STATUS.
765 @param HostAdapterStatus Host Adapter status
767 @retval EFI_SUCCESS Host adapter is OK.
768 @retval EFI_TIMEOUT Timeout.
769 @retval EFI_NOT_READY Adapter NOT ready.
770 @retval EFI_DEVICE_ERROR Adapter device error.
774 CheckHostAdapterStatus (
775 IN UINT8 HostAdapterStatus
780 Check the target status and re-interpret it in EFI_STATUS.
782 @param TargetStatus Target status
784 @retval EFI_NOT_READY Device is NOT ready.
785 @retval EFI_DEVICE_ERROR
791 IN UINT8 TargetStatus
795 Retrieve all sense keys from the device.
797 When encountering error during the process, if retrieve sense keys before
798 error encountered, it returns the sense keys with return status set to EFI_SUCCESS,
799 and NeedRetry set to FALSE; otherwize, return the proper return status.
801 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
802 @param NeedRetry The pointer of flag indicates if need a retry
803 @param SenseDataArray The pointer of an array of sense data
804 @param NumberOfSenseKeys The number of sense key
805 @param AskResetIfError The flag indicates if need reset when error occurs
807 @retval EFI_DEVICE_ERROR Indicates that error occurs
808 @retval EFI_SUCCESS Successfully to request sense key
812 ScsiDiskRequestSenseKeys (
813 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
814 OUT BOOLEAN
*NeedRetry
,
815 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
816 OUT UINTN
*NumberOfSenseKeys
,
817 IN BOOLEAN AskResetIfError
821 Send out Inquiry command to Device.
823 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
824 @param NeedRetry Indicates if needs try again when error happens
826 @retval EFI_DEVICE_ERROR Indicates that error occurs
827 @retval EFI_SUCCESS Successfully to detect media
831 ScsiDiskInquiryDevice (
832 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
833 OUT BOOLEAN
*NeedRetry
839 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
844 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
848 Read sector from SCSI Disk.
850 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
851 @param Buffer The buffer to fill in the read out data
852 @param Lba Logic block address
853 @param NumberOfBlocks The number of blocks to read
855 @retval EFI_DEVICE_ERROR Indicates a device error.
856 @retval EFI_SUCCESS Operation is successful.
860 ScsiDiskReadSectors (
861 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
864 IN UINTN NumberOfBlocks
868 Write sector to SCSI Disk.
870 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
871 @param Buffer The buffer of data to be written into SCSI Disk
872 @param Lba Logic block address
873 @param NumberOfBlocks The number of blocks to read
875 @retval EFI_DEVICE_ERROR Indicates a device error.
876 @retval EFI_SUCCESS Operation is successful.
880 ScsiDiskWriteSectors (
881 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
884 IN UINTN NumberOfBlocks
888 Asynchronously read sector from SCSI Disk.
890 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
891 @param Buffer The buffer to fill in the read out data.
892 @param Lba Logic block address.
893 @param NumberOfBlocks The number of blocks to read.
894 @param Token A pointer to the token associated with the
895 non-blocking read request.
897 @retval EFI_INVALID_PARAMETER Token is NULL or Token->Event is NULL.
898 @retval EFI_DEVICE_ERROR Indicates a device error.
899 @retval EFI_SUCCESS Operation is successful.
903 ScsiDiskAsyncReadSectors (
904 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
907 IN UINTN NumberOfBlocks
,
908 IN EFI_BLOCK_IO2_TOKEN
*Token
912 Asynchronously write sector to SCSI Disk.
914 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
915 @param Buffer The buffer of data to be written into SCSI Disk.
916 @param Lba Logic block address.
917 @param NumberOfBlocks The number of blocks to read.
918 @param Token A pointer to the token associated with the
919 non-blocking read request.
921 @retval EFI_INVALID_PARAMETER Token is NULL or Token->Event is NULL
922 @retval EFI_DEVICE_ERROR Indicates a device error.
923 @retval EFI_SUCCESS Operation is successful.
927 ScsiDiskAsyncWriteSectors (
928 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
931 IN UINTN NumberOfBlocks
,
932 IN EFI_BLOCK_IO2_TOKEN
*Token
936 Submit Read(10) command.
938 @param ScsiDiskDevice The pointer of ScsiDiskDevice
939 @param NeedRetry The pointer of flag indicates if needs retry if error happens
940 @param Timeout The time to complete the command
941 @param DataBuffer The buffer to fill with the read out data
942 @param DataLength The length of buffer
943 @param StartLba The start logic block address
944 @param SectorCount The number of blocks to read
946 @return EFI_STATUS is returned by calling ScsiRead10Command().
950 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
951 OUT BOOLEAN
*NeedRetry
,
953 OUT UINT8
*DataBuffer
,
954 IN OUT UINT32
*DataLength
,
956 IN UINT32 SectorCount
960 Submit Write(10) Command.
962 @param ScsiDiskDevice The pointer of ScsiDiskDevice
963 @param NeedRetry The pointer of flag indicates if needs retry if error happens
964 @param Timeout The time to complete the command
965 @param DataBuffer The buffer to fill with the read out data
966 @param DataLength The length of buffer
967 @param StartLba The start logic block address
968 @param SectorCount The number of blocks to write
970 @return EFI_STATUS is returned by calling ScsiWrite10Command().
975 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
976 OUT BOOLEAN
*NeedRetry
,
978 IN UINT8
*DataBuffer
,
979 IN OUT UINT32
*DataLength
,
981 IN UINT32 SectorCount
985 Submit Read(16) command.
987 @param ScsiDiskDevice The pointer of ScsiDiskDevice
988 @param NeedRetry The pointer of flag indicates if needs retry if error happens
989 @param Timeout The time to complete the command
990 @param DataBuffer The buffer to fill with the read out data
991 @param DataLength The length of buffer
992 @param StartLba The start logic block address
993 @param SectorCount The number of blocks to read
995 @return EFI_STATUS is returned by calling ScsiRead16Command().
999 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1000 OUT BOOLEAN
*NeedRetry
,
1002 OUT UINT8
*DataBuffer
,
1003 IN OUT UINT32
*DataLength
,
1005 IN UINT32 SectorCount
1009 Submit Write(16) Command.
1011 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1012 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1013 @param Timeout The time to complete the command
1014 @param DataBuffer The buffer to fill with the read out data
1015 @param DataLength The length of buffer
1016 @param StartLba The start logic block address
1017 @param SectorCount The number of blocks to write
1019 @return EFI_STATUS is returned by calling ScsiWrite16Command().
1024 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1025 OUT BOOLEAN
*NeedRetry
,
1027 IN UINT8
*DataBuffer
,
1028 IN OUT UINT32
*DataLength
,
1030 IN UINT32 SectorCount
1034 Submit Async Read(10) command.
1036 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1037 @param Timeout The time to complete the command.
1038 @param TimesRetry The number of times the command has been retried.
1039 @param DataBuffer The buffer to fill with the read out data.
1040 @param DataLength The length of buffer.
1041 @param StartLba The start logic block address.
1042 @param SectorCount The number of blocks to read.
1043 @param BlkIo2Req The upstream BlockIo2 request.
1044 @param Token The pointer to the token associated with the
1045 non-blocking read request.
1047 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1049 @return others Status returned by calling
1050 ScsiRead10CommandEx().
1054 ScsiDiskAsyncRead10 (
1055 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1057 IN UINT8 TimesRetry
,
1058 OUT UINT8
*DataBuffer
,
1059 IN UINT32 DataLength
,
1061 IN UINT32 SectorCount
,
1062 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1063 IN EFI_BLOCK_IO2_TOKEN
*Token
1067 Submit Async Write(10) command.
1069 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1070 @param Timeout The time to complete the command.
1071 @param TimesRetry The number of times the command has been retried.
1072 @param DataBuffer The buffer contains the data to write.
1073 @param DataLength The length of buffer.
1074 @param StartLba The start logic block address.
1075 @param SectorCount The number of blocks to write.
1076 @param BlkIo2Req The upstream BlockIo2 request.
1077 @param Token The pointer to the token associated with the
1078 non-blocking read request.
1080 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1082 @return others Status returned by calling
1083 ScsiWrite10CommandEx().
1087 ScsiDiskAsyncWrite10 (
1088 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1090 IN UINT8 TimesRetry
,
1091 IN UINT8
*DataBuffer
,
1092 IN UINT32 DataLength
,
1094 IN UINT32 SectorCount
,
1095 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1096 IN EFI_BLOCK_IO2_TOKEN
*Token
1100 Submit Async Read(16) command.
1102 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1103 @param Timeout The time to complete the command.
1104 @param TimesRetry The number of times the command has been retried.
1105 @param DataBuffer The buffer to fill with the read out data.
1106 @param DataLength The length of buffer.
1107 @param StartLba The start logic block address.
1108 @param SectorCount The number of blocks to read.
1109 @param BlkIo2Req The upstream BlockIo2 request.
1110 @param Token The pointer to the token associated with the
1111 non-blocking read request.
1113 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1115 @return others Status returned by calling
1116 ScsiRead16CommandEx().
1120 ScsiDiskAsyncRead16 (
1121 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1123 IN UINT8 TimesRetry
,
1124 OUT UINT8
*DataBuffer
,
1125 IN UINT32 DataLength
,
1127 IN UINT32 SectorCount
,
1128 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1129 IN EFI_BLOCK_IO2_TOKEN
*Token
1133 Submit Async Write(16) command.
1135 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1136 @param Timeout The time to complete the command.
1137 @param TimesRetry The number of times the command has been retried.
1138 @param DataBuffer The buffer contains the data to write.
1139 @param DataLength The length of buffer.
1140 @param StartLba The start logic block address.
1141 @param SectorCount The number of blocks to write.
1142 @param BlkIo2Req The upstream BlockIo2 request.
1143 @param Token The pointer to the token associated with the
1144 non-blocking read request.
1146 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1148 @return others Status returned by calling
1149 ScsiWrite16CommandEx().
1153 ScsiDiskAsyncWrite16 (
1154 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1156 IN UINT8 TimesRetry
,
1157 IN UINT8
*DataBuffer
,
1158 IN UINT32 DataLength
,
1160 IN UINT32 SectorCount
,
1161 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1162 IN EFI_BLOCK_IO2_TOKEN
*Token
1166 Get information from media read capacity command.
1168 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1169 @param Capacity10 The pointer of EFI_SCSI_DISK_CAPACITY_DATA
1170 @param Capacity16 The pointer of EFI_SCSI_DISK_CAPACITY_DATA16
1174 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
1175 IN EFI_SCSI_DISK_CAPACITY_DATA
*Capacity10
,
1176 IN EFI_SCSI_DISK_CAPACITY_DATA16
*Capacity16
1180 Check sense key to find if media presents.
1182 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1183 @param SenseCounts The number of sense key
1185 @retval TRUE NOT any media
1186 @retval FALSE Media presents
1190 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1191 IN UINTN SenseCounts
1197 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1198 @param SenseCounts The number of sense key
1201 @retval FALSE NOT error
1205 ScsiDiskIsMediaError (
1206 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1207 IN UINTN SenseCounts
1211 Check sense key to find if hardware error happens.
1213 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1214 @param SenseCounts The number of sense key
1216 @retval TRUE Hardware error exits.
1217 @retval FALSE NO error.
1221 ScsiDiskIsHardwareError (
1222 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1223 IN UINTN SenseCounts
1227 Check sense key to find if media has changed.
1229 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1230 @param SenseCounts The number of sense key
1232 @retval TRUE Media is changed.
1233 @retval FALSE Medit is NOT changed.
1236 ScsiDiskIsMediaChange (
1237 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1238 IN UINTN SenseCounts
1242 Check sense key to find if reset happens.
1244 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1245 @param SenseCounts The number of sense key
1247 @retval TRUE It is reset before.
1248 @retval FALSE It is NOT reset before.
1252 ScsiDiskIsResetBefore (
1253 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1254 IN UINTN SenseCounts
1258 Check sense key to find if the drive is ready.
1260 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1261 @param SenseCounts The number of sense key
1262 @param RetryLater The flag means if need a retry
1264 @retval TRUE Drive is ready.
1265 @retval FALSE Drive is NOT ready.
1269 ScsiDiskIsDriveReady (
1270 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1271 IN UINTN SenseCounts
,
1272 OUT BOOLEAN
*RetryLater
1276 Check sense key to find if it has sense key.
1278 @param SenseData - The pointer of EFI_SCSI_SENSE_DATA
1279 @param SenseCounts - The number of sense key
1281 @retval TRUE It has sense key.
1282 @retval FALSE It has NOT any sense key.
1286 ScsiDiskHaveSenseKey (
1287 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1288 IN UINTN SenseCounts
1292 Release resource about disk device.
1294 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1298 ReleaseScsiDiskDeviceResources (
1299 IN SCSI_DISK_DEV
*ScsiDiskDevice
1303 Determine if Block Io should be produced.
1306 @param ChildHandle Child Handle to retrieve Parent information.
1308 @retval TRUE Should produce Block Io.
1309 @retval FALSE Should not produce Block Io.
1313 DetermineInstallBlockIo (
1314 IN EFI_HANDLE ChildHandle
1318 Initialize the installation of DiskInfo protocol.
1320 This function prepares for the installation of DiskInfo protocol on the child handle.
1321 By default, it installs DiskInfo protocol with SCSI interface GUID. If it further
1322 detects that the physical device is an ATAPI/AHCI device, it then updates interface GUID
1323 to be IDE/AHCI interface GUID.
1325 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1326 @param ChildHandle Child handle to install DiskInfo protocol.
1330 InitializeInstallDiskInfo (
1331 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1332 IN EFI_HANDLE ChildHandle
1336 Search protocol database and check to see if the protocol
1337 specified by ProtocolGuid is present on a ControllerHandle and opened by
1338 ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1339 If the ControllerHandle is found, then the protocol specified by ProtocolGuid
1340 will be opened on it.
1343 @param ProtocolGuid ProtocolGuid pointer.
1344 @param ChildHandle Child Handle to retrieve Parent information.
1350 IN EFI_GUID
*ProtocolGuid
,
1351 IN EFI_HANDLE ChildHandle