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 queue for Scsi Read/Write requests of a BlockIo2
103 LIST_ENTRY ScsiRWQueue
;
106 } SCSI_BLKIO2_REQUEST
;
109 // Private data structure for a SCSI Read/Write request
112 SCSI_DISK_DEV
*ScsiDiskDevice
;
114 EFI_SCSI_SENSE_DATA
*SenseData
;
115 UINT8 SenseDataLength
;
116 UINT8 HostAdapterStatus
;
126 // The BlockIo2 request this SCSI command belongs to
128 SCSI_BLKIO2_REQUEST
*BlkIo2Req
;
131 } SCSI_ASYNC_RW_REQUEST
;
136 extern EFI_DRIVER_BINDING_PROTOCOL gScsiDiskDriverBinding
;
137 extern EFI_COMPONENT_NAME_PROTOCOL gScsiDiskComponentName
;
138 extern EFI_COMPONENT_NAME2_PROTOCOL gScsiDiskComponentName2
;
140 // action code used in detect media process
142 #define ACTION_NO_ACTION 0x00
143 #define ACTION_READ_CAPACITY 0x01
144 #define ACTION_RETRY_COMMAND_LATER 0x02
145 #define ACTION_RETRY_WITH_BACKOFF_ALGO 0x03
147 #define SCSI_COMMAND_VERSION_1 0x01
148 #define SCSI_COMMAND_VERSION_2 0x02
149 #define SCSI_COMMAND_VERSION_3 0x03
152 // SCSI Disk Timeout Experience Value
154 #define SCSI_DISK_TIMEOUT EFI_TIMER_PERIOD_SECONDS (3)
157 Test to see if this driver supports ControllerHandle.
159 This service is called by the EFI boot service ConnectController(). In order
160 to make drivers as small as possible, there are a few calling restrictions for
161 this service. ConnectController() must follow these calling restrictions.
162 If any other agent wishes to call Supported() it must also follow these
163 calling restrictions.
165 @param This Protocol instance pointer.
166 @param ControllerHandle Handle of device to test
167 @param RemainingDevicePath Optional parameter use to pick a specific child
170 @retval EFI_SUCCESS This driver supports this device
171 @retval EFI_ALREADY_STARTED This driver is already running on this device
172 @retval other This driver does not support this device
177 ScsiDiskDriverBindingSupported (
178 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
179 IN EFI_HANDLE Controller
,
180 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
184 Start this driver on ControllerHandle.
186 This service is called by the EFI boot service ConnectController(). In order
187 to make drivers as small as possible, there are a few calling restrictions for
188 this service. ConnectController() must follow these calling restrictions. If
189 any other agent wishes to call Start() it must also follow these calling
192 @param This Protocol instance pointer.
193 @param ControllerHandle Handle of device to bind driver to
194 @param RemainingDevicePath Optional parameter use to pick a specific child
197 @retval EFI_SUCCESS This driver is added to ControllerHandle
198 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
199 @retval other This driver does not support this device
204 ScsiDiskDriverBindingStart (
205 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
206 IN EFI_HANDLE Controller
,
207 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
211 Stop this driver on ControllerHandle.
213 This service is called by the EFI boot service DisconnectController().
214 In order to make drivers as small as possible, there are a few calling
215 restrictions for this service. DisconnectController() must follow these
216 calling restrictions. If any other agent wishes to call Stop() it must
217 also follow these calling restrictions.
219 @param This Protocol instance pointer.
220 @param ControllerHandle Handle of device to stop driver on
221 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
222 children is zero stop the entire bus driver.
223 @param ChildHandleBuffer List of Child Handles to Stop.
225 @retval EFI_SUCCESS This driver is removed ControllerHandle
226 @retval other This driver was not removed from this device
231 ScsiDiskDriverBindingStop (
232 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
233 IN EFI_HANDLE Controller
,
234 IN UINTN NumberOfChildren
,
235 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
239 // EFI Component Name Functions
242 Retrieves a Unicode string that is the user readable name of the driver.
244 This function retrieves the user readable name of a driver in the form of a
245 Unicode string. If the driver specified by This has a user readable name in
246 the language specified by Language, then a pointer to the driver name is
247 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
248 by This does not support the language specified by Language,
249 then EFI_UNSUPPORTED is returned.
251 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
252 EFI_COMPONENT_NAME_PROTOCOL instance.
254 @param Language A pointer to a Null-terminated ASCII string
255 array indicating the language. This is the
256 language of the driver name that the caller is
257 requesting, and it must match one of the
258 languages specified in SupportedLanguages. The
259 number of languages supported by a driver is up
260 to the driver writer. Language is specified
261 in RFC 4646 or ISO 639-2 language code format.
263 @param DriverName A pointer to the Unicode string to return.
264 This Unicode string is the name of the
265 driver specified by This in the language
266 specified by Language.
268 @retval EFI_SUCCESS The Unicode string for the Driver specified by
269 This and the language specified by Language was
270 returned in DriverName.
272 @retval EFI_INVALID_PARAMETER Language is NULL.
274 @retval EFI_INVALID_PARAMETER DriverName is NULL.
276 @retval EFI_UNSUPPORTED The driver specified by This does not support
277 the language specified by Language.
282 ScsiDiskComponentNameGetDriverName (
283 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
285 OUT CHAR16
**DriverName
290 Retrieves a Unicode string that is the user readable name of the controller
291 that is being managed by a driver.
293 This function retrieves the user readable name of the controller specified by
294 ControllerHandle and ChildHandle in the form of a Unicode string. If the
295 driver specified by This has a user readable name in the language specified by
296 Language, then a pointer to the controller name is returned in ControllerName,
297 and EFI_SUCCESS is returned. If the driver specified by This is not currently
298 managing the controller specified by ControllerHandle and ChildHandle,
299 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
300 support the language specified by Language, then EFI_UNSUPPORTED is returned.
302 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
303 EFI_COMPONENT_NAME_PROTOCOL instance.
305 @param ControllerHandle The handle of a controller that the driver
306 specified by This is managing. This handle
307 specifies the controller whose name is to be
310 @param ChildHandle The handle of the child controller to retrieve
311 the name of. This is an optional parameter that
312 may be NULL. It will be NULL for device
313 drivers. It will also be NULL for a bus drivers
314 that wish to retrieve the name of the bus
315 controller. It will not be NULL for a bus
316 driver that wishes to retrieve the name of a
319 @param Language A pointer to a Null-terminated ASCII string
320 array indicating the language. This is the
321 language of the driver name that the caller is
322 requesting, and it must match one of the
323 languages specified in SupportedLanguages. The
324 number of languages supported by a driver is up
325 to the driver writer. Language is specified in
326 RFC 4646 or ISO 639-2 language code format.
328 @param ControllerName A pointer to the Unicode string to return.
329 This Unicode string is the name of the
330 controller specified by ControllerHandle and
331 ChildHandle in the language specified by
332 Language from the point of view of the driver
335 @retval EFI_SUCCESS The Unicode string for the user readable name in
336 the language specified by Language for the
337 driver specified by This was returned in
340 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
342 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
345 @retval EFI_INVALID_PARAMETER Language is NULL.
347 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
349 @retval EFI_UNSUPPORTED The driver specified by This is not currently
350 managing the controller specified by
351 ControllerHandle and ChildHandle.
353 @retval EFI_UNSUPPORTED The driver specified by This does not support
354 the language specified by Language.
359 ScsiDiskComponentNameGetControllerName (
360 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
361 IN EFI_HANDLE ControllerHandle
,
362 IN EFI_HANDLE ChildHandle OPTIONAL
,
364 OUT CHAR16
**ControllerName
371 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
372 @param ExtendedVerification The flag about if extend verificate
374 @retval EFI_SUCCESS The device was reset.
375 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
377 @return EFI_STATUS is retured from EFI_SCSI_IO_PROTOCOL.ResetDevice().
383 IN EFI_BLOCK_IO_PROTOCOL
*This
,
384 IN BOOLEAN ExtendedVerification
389 The function is to Read Block from SCSI Disk.
391 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
392 @param MediaId The Id of Media detected
393 @param Lba The logic block address
394 @param BufferSize The size of Buffer
395 @param Buffer The buffer to fill the read out data
397 @retval EFI_SUCCESS Successfully to read out block.
398 @retval EFI_DEVICE_ERROR Fail to detect media.
399 @retval EFI_NO_MEDIA Media is not present.
400 @retval EFI_MEDIA_CHANGED Media has changed.
401 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
402 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
408 IN EFI_BLOCK_IO_PROTOCOL
*This
,
417 The function is to Write Block to SCSI Disk.
419 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
420 @param MediaId The Id of Media detected
421 @param Lba The logic block address
422 @param BufferSize The size of Buffer
423 @param Buffer The buffer to fill the read out data
425 @retval EFI_SUCCESS Successfully to read out block.
426 @retval EFI_WRITE_PROTECTED The device can not be written to.
427 @retval EFI_DEVICE_ERROR Fail to detect media.
428 @retval EFI_NO_MEDIA Media is not present.
429 @retval EFI_MEDIA_CHNAGED Media has changed.
430 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
431 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
436 ScsiDiskWriteBlocks (
437 IN EFI_BLOCK_IO_PROTOCOL
*This
,
448 EFI_SUCCESS is returned directly.
450 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
452 @retval EFI_SUCCESS All outstanding data was written to the device
457 ScsiDiskFlushBlocks (
458 IN EFI_BLOCK_IO_PROTOCOL
*This
465 @param This The pointer of EFI_BLOCK_IO2_PROTOCOL.
466 @param ExtendedVerification The flag about if extend verificate.
468 @retval EFI_SUCCESS The device was reset.
469 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
471 @return EFI_STATUS is returned from EFI_SCSI_IO_PROTOCOL.ResetDevice().
477 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
478 IN BOOLEAN ExtendedVerification
482 The function is to Read Block from SCSI Disk.
484 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
485 @param MediaId The Id of Media detected.
486 @param Lba The logic block address.
487 @param Token A pointer to the token associated with the transaction.
488 @param BufferSize The size of Buffer.
489 @param Buffer The buffer to fill the read out data.
491 @retval EFI_SUCCESS The read request was queued if Token-> Event is
492 not NULL. The data was read correctly from the
493 device if theToken-> Event is NULL.
494 @retval EFI_DEVICE_ERROR The device reported an error while attempting
495 to perform the read operation.
496 @retval EFI_NO_MEDIA There is no media in the device.
497 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
498 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
499 the intrinsic block size of the device.
500 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
501 valid, or the buffer is not on proper
503 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
509 ScsiDiskReadBlocksEx (
510 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
513 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
519 The function is to Write Block to SCSI Disk.
521 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
522 @param MediaId The Id of Media detected.
523 @param Lba The logic block address.
524 @param Token A pointer to the token associated with the transaction.
525 @param BufferSize The size of Buffer.
526 @param Buffer The buffer to fill the read out data.
528 @retval EFI_SUCCESS The data were written correctly to the device.
529 @retval EFI_WRITE_PROTECTED The device cannot be written to.
530 @retval EFI_NO_MEDIA There is no media in the device.
531 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
532 @retval EFI_DEVICE_ERROR The device reported an error while attempting
533 to perform the write operation.
534 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
535 the intrinsic block size of the device.
536 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
537 valid, or the buffer is not on proper
543 ScsiDiskWriteBlocksEx (
544 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
547 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
553 Flush the Block Device.
555 @param This Indicates a pointer to the calling context.
556 @param Token A pointer to the token associated with the transaction.
558 @retval EFI_SUCCESS All outstanding data was written to the device.
559 @retval EFI_DEVICE_ERROR The device reported an error while attempting to
561 @retval EFI_WRITE_PROTECTED The device cannot be written to.
562 @retval EFI_NO_MEDIA There is no media in the device.
563 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
568 ScsiDiskFlushBlocksEx (
569 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
570 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
575 Provides inquiry information for the controller type.
577 This function is used by the IDE bus driver to get inquiry data. Data format
578 of Identify data is defined by the Interface GUID.
580 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
581 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
582 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
584 @retval EFI_SUCCESS The command was accepted without any errors.
585 @retval EFI_NOT_FOUND Device does not support this data class
586 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
587 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
592 ScsiDiskInfoInquiry (
593 IN EFI_DISK_INFO_PROTOCOL
*This
,
594 IN OUT VOID
*InquiryData
,
595 IN OUT UINT32
*InquiryDataSize
600 Provides identify information for the controller type.
602 This function is used by the IDE bus driver to get identify data. Data format
603 of Identify data is defined by the Interface GUID.
605 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
607 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
608 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
611 @retval EFI_SUCCESS The command was accepted without any errors.
612 @retval EFI_NOT_FOUND Device does not support this data class
613 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
614 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
619 ScsiDiskInfoIdentify (
620 IN EFI_DISK_INFO_PROTOCOL
*This
,
621 IN OUT VOID
*IdentifyData
,
622 IN OUT UINT32
*IdentifyDataSize
627 Provides sense data information for the controller type.
629 This function is used by the IDE bus driver to get sense data.
630 Data format of Sense data is defined by the Interface GUID.
632 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
633 @param[in, out] SenseData Pointer to the SenseData.
634 @param[in, out] SenseDataSize Size of SenseData in bytes.
635 @param[out] SenseDataNumber Pointer to the value for the sense data size.
637 @retval EFI_SUCCESS The command was accepted without any errors.
638 @retval EFI_NOT_FOUND Device does not support this data class.
639 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
640 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
645 ScsiDiskInfoSenseData (
646 IN EFI_DISK_INFO_PROTOCOL
*This
,
647 IN OUT VOID
*SenseData
,
648 IN OUT UINT32
*SenseDataSize
,
649 OUT UINT8
*SenseDataNumber
653 This function is used by the IDE bus driver to get controller information.
655 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
656 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
657 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
659 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
660 @retval EFI_UNSUPPORTED This is not an IDE device.
665 ScsiDiskInfoWhichIde (
666 IN EFI_DISK_INFO_PROTOCOL
*This
,
667 OUT UINT32
*IdeChannel
,
668 OUT UINT32
*IdeDevice
673 Detect Device and read out capacity ,if error occurs, parse the sense key.
675 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
676 @param MustReadCapacity The flag about reading device capacity
677 @param MediaChange The pointer of flag indicates if media has changed
679 @retval EFI_DEVICE_ERROR Indicates that error occurs
680 @retval EFI_SUCCESS Successfully to detect media
684 ScsiDiskDetectMedia (
685 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
686 IN BOOLEAN MustReadCapacity
,
687 OUT BOOLEAN
*MediaChange
693 When Test Unit Ready command succeeds, retrieve Sense Keys via Request Sense;
694 When Test Unit Ready command encounters any error caused by host adapter or
695 target, return error without retrieving Sense Keys.
697 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
698 @param NeedRetry The pointer of flag indicates try again
699 @param SenseDataArray The pointer of an array of sense data
700 @param NumberOfSenseKeys The pointer of the number of sense data array
702 @retval EFI_DEVICE_ERROR Indicates that error occurs
703 @retval EFI_SUCCESS Successfully to test unit
707 ScsiDiskTestUnitReady (
708 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
709 OUT BOOLEAN
*NeedRetry
,
710 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
711 OUT UINTN
*NumberOfSenseKeys
716 Parsing Sense Keys which got from request sense command.
718 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
719 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
720 @param NumberOfSenseKeys The number of sense key
721 @param Action The pointer of action which indicates what is need to do next
723 @retval EFI_DEVICE_ERROR Indicates that error occurs
724 @retval EFI_SUCCESS Successfully to complete the parsing
728 DetectMediaParsingSenseKeys (
729 OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
730 IN EFI_SCSI_SENSE_DATA
*SenseData
,
731 IN UINTN NumberOfSenseKeys
,
737 Send read capacity command to device and get the device parameter.
739 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
740 @param NeedRetry The pointer of flag indicates if need a retry
741 @param SenseDataArray The pointer of an array of sense data
742 @param NumberOfSenseKeys The number of sense key
744 @retval EFI_DEVICE_ERROR Indicates that error occurs
745 @retval EFI_SUCCESS Successfully to read capacity
749 ScsiDiskReadCapacity (
750 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
751 OUT BOOLEAN
*NeedRetry
,
752 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
753 OUT UINTN
*NumberOfSenseKeys
757 Check the HostAdapter status and re-interpret it in EFI_STATUS.
759 @param HostAdapterStatus Host Adapter status
761 @retval EFI_SUCCESS Host adapter is OK.
762 @retval EFI_TIMEOUT Timeout.
763 @retval EFI_NOT_READY Adapter NOT ready.
764 @retval EFI_DEVICE_ERROR Adapter device error.
768 CheckHostAdapterStatus (
769 IN UINT8 HostAdapterStatus
774 Check the target status and re-interpret it in EFI_STATUS.
776 @param TargetStatus Target status
778 @retval EFI_NOT_READY Device is NOT ready.
779 @retval EFI_DEVICE_ERROR
785 IN UINT8 TargetStatus
789 Retrieve all sense keys from the device.
791 When encountering error during the process, if retrieve sense keys before
792 error encountered, it returns the sense keys with return status set to EFI_SUCCESS,
793 and NeedRetry set to FALSE; otherwize, return the proper return status.
795 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
796 @param NeedRetry The pointer of flag indicates if need a retry
797 @param SenseDataArray The pointer of an array of sense data
798 @param NumberOfSenseKeys The number of sense key
799 @param AskResetIfError The flag indicates if need reset when error occurs
801 @retval EFI_DEVICE_ERROR Indicates that error occurs
802 @retval EFI_SUCCESS Successfully to request sense key
806 ScsiDiskRequestSenseKeys (
807 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
808 OUT BOOLEAN
*NeedRetry
,
809 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
810 OUT UINTN
*NumberOfSenseKeys
,
811 IN BOOLEAN AskResetIfError
815 Send out Inquiry command to Device.
817 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
818 @param NeedRetry Indicates if needs try again when error happens
820 @retval EFI_DEVICE_ERROR Indicates that error occurs
821 @retval EFI_SUCCESS Successfully to detect media
825 ScsiDiskInquiryDevice (
826 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
827 OUT BOOLEAN
*NeedRetry
833 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
838 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
842 Read sector from SCSI Disk.
844 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
845 @param Buffer The buffer to fill in the read out data
846 @param Lba Logic block address
847 @param NumberOfBlocks The number of blocks to read
849 @retval EFI_DEVICE_ERROR Indicates a device error.
850 @retval EFI_SUCCESS Operation is successful.
854 ScsiDiskReadSectors (
855 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
858 IN UINTN NumberOfBlocks
862 Write sector to SCSI Disk.
864 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
865 @param Buffer The buffer of data to be written into SCSI Disk
866 @param Lba Logic block address
867 @param NumberOfBlocks The number of blocks to read
869 @retval EFI_DEVICE_ERROR Indicates a device error.
870 @retval EFI_SUCCESS Operation is successful.
874 ScsiDiskWriteSectors (
875 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
878 IN UINTN NumberOfBlocks
882 Asynchronously read sector from SCSI Disk.
884 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
885 @param Buffer The buffer to fill in the read out data.
886 @param Lba Logic block address.
887 @param NumberOfBlocks The number of blocks to read.
888 @param Token A pointer to the token associated with the
889 non-blocking read request.
891 @retval EFI_INVALID_PARAMETER Token is NULL or Token->Event is NULL.
892 @retval EFI_DEVICE_ERROR Indicates a device error.
893 @retval EFI_SUCCESS Operation is successful.
897 ScsiDiskAsyncReadSectors (
898 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
901 IN UINTN NumberOfBlocks
,
902 IN EFI_BLOCK_IO2_TOKEN
*Token
906 Asynchronously write sector to SCSI Disk.
908 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
909 @param Buffer The buffer of data to be written into SCSI Disk.
910 @param Lba Logic block address.
911 @param NumberOfBlocks The number of blocks to read.
912 @param Token A pointer to the token associated with the
913 non-blocking read request.
915 @retval EFI_INVALID_PARAMETER Token is NULL or Token->Event is NULL
916 @retval EFI_DEVICE_ERROR Indicates a device error.
917 @retval EFI_SUCCESS Operation is successful.
921 ScsiDiskAsyncWriteSectors (
922 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
925 IN UINTN NumberOfBlocks
,
926 IN EFI_BLOCK_IO2_TOKEN
*Token
930 Submit Read(10) command.
932 @param ScsiDiskDevice The pointer of ScsiDiskDevice
933 @param NeedRetry The pointer of flag indicates if needs retry if error happens
934 @param Timeout The time to complete the command
935 @param DataBuffer The buffer to fill with the read out data
936 @param DataLength The length of buffer
937 @param StartLba The start logic block address
938 @param SectorCount The number of blocks to read
940 @return EFI_STATUS is returned by calling ScsiRead10Command().
944 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
945 OUT BOOLEAN
*NeedRetry
,
947 OUT UINT8
*DataBuffer
,
948 IN OUT UINT32
*DataLength
,
950 IN UINT32 SectorCount
954 Submit Write(10) Command.
956 @param ScsiDiskDevice The pointer of ScsiDiskDevice
957 @param NeedRetry The pointer of flag indicates if needs retry if error happens
958 @param Timeout The time to complete the command
959 @param DataBuffer The buffer to fill with the read out data
960 @param DataLength The length of buffer
961 @param StartLba The start logic block address
962 @param SectorCount The number of blocks to write
964 @return EFI_STATUS is returned by calling ScsiWrite10Command().
969 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
970 OUT BOOLEAN
*NeedRetry
,
972 IN UINT8
*DataBuffer
,
973 IN OUT UINT32
*DataLength
,
975 IN UINT32 SectorCount
979 Submit Read(16) command.
981 @param ScsiDiskDevice The pointer of ScsiDiskDevice
982 @param NeedRetry The pointer of flag indicates if needs retry if error happens
983 @param Timeout The time to complete the command
984 @param DataBuffer The buffer to fill with the read out data
985 @param DataLength The length of buffer
986 @param StartLba The start logic block address
987 @param SectorCount The number of blocks to read
989 @return EFI_STATUS is returned by calling ScsiRead16Command().
993 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
994 OUT BOOLEAN
*NeedRetry
,
996 OUT UINT8
*DataBuffer
,
997 IN OUT UINT32
*DataLength
,
999 IN UINT32 SectorCount
1003 Submit Write(16) Command.
1005 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1006 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1007 @param Timeout The time to complete the command
1008 @param DataBuffer The buffer to fill with the read out data
1009 @param DataLength The length of buffer
1010 @param StartLba The start logic block address
1011 @param SectorCount The number of blocks to write
1013 @return EFI_STATUS is returned by calling ScsiWrite16Command().
1018 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1019 OUT BOOLEAN
*NeedRetry
,
1021 IN UINT8
*DataBuffer
,
1022 IN OUT UINT32
*DataLength
,
1024 IN UINT32 SectorCount
1028 Submit Async Read(10) command.
1030 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1031 @param Timeout The time to complete the command.
1032 @param DataBuffer The buffer to fill with the read out data.
1033 @param DataLength The length of buffer.
1034 @param StartLba The start logic block address.
1035 @param SectorCount The number of blocks to read.
1036 @param BlkIo2Req The upstream BlockIo2 request.
1037 @param Token The pointer to the token associated with the
1038 non-blocking read request.
1040 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1042 @return others Status returned by calling
1043 ScsiRead10CommandEx().
1047 ScsiDiskAsyncRead10 (
1048 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1050 OUT UINT8
*DataBuffer
,
1051 IN UINT32 DataLength
,
1053 IN UINT32 SectorCount
,
1054 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1055 IN EFI_BLOCK_IO2_TOKEN
*Token
1059 Submit Async Write(10) command.
1061 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1062 @param Timeout The time to complete the command.
1063 @param DataBuffer The buffer contains the data to write.
1064 @param DataLength The length of buffer.
1065 @param StartLba The start logic block address.
1066 @param SectorCount The number of blocks to write.
1067 @param BlkIo2Req The upstream BlockIo2 request.
1068 @param Token The pointer to the token associated with the
1069 non-blocking read request.
1071 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1073 @return others Status returned by calling
1074 ScsiWrite10CommandEx().
1078 ScsiDiskAsyncWrite10 (
1079 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1081 IN UINT8
*DataBuffer
,
1082 IN UINT32 DataLength
,
1084 IN UINT32 SectorCount
,
1085 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1086 IN EFI_BLOCK_IO2_TOKEN
*Token
1090 Submit Async Read(16) command.
1092 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1093 @param Timeout The time to complete the command.
1094 @param DataBuffer The buffer to fill with the read out data.
1095 @param DataLength The length of buffer.
1096 @param StartLba The start logic block address.
1097 @param SectorCount The number of blocks to read.
1098 @param BlkIo2Req The upstream BlockIo2 request.
1099 @param Token The pointer to the token associated with the
1100 non-blocking read request.
1102 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1104 @return others Status returned by calling
1105 ScsiRead16CommandEx().
1109 ScsiDiskAsyncRead16 (
1110 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1112 OUT UINT8
*DataBuffer
,
1113 IN UINT32 DataLength
,
1115 IN UINT32 SectorCount
,
1116 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1117 IN EFI_BLOCK_IO2_TOKEN
*Token
1121 Submit Async Write(16) command.
1123 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1124 @param Timeout The time to complete the command.
1125 @param DataBuffer The buffer contains the data to write.
1126 @param DataLength The length of buffer.
1127 @param StartLba The start logic block address.
1128 @param SectorCount The number of blocks to write.
1129 @param BlkIo2Req The upstream BlockIo2 request.
1130 @param Token The pointer to the token associated with the
1131 non-blocking read request.
1133 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1135 @return others Status returned by calling
1136 ScsiWrite16CommandEx().
1140 ScsiDiskAsyncWrite16 (
1141 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1143 IN UINT8
*DataBuffer
,
1144 IN UINT32 DataLength
,
1146 IN UINT32 SectorCount
,
1147 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1148 IN EFI_BLOCK_IO2_TOKEN
*Token
1152 Get information from media read capacity command.
1154 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1155 @param Capacity10 The pointer of EFI_SCSI_DISK_CAPACITY_DATA
1156 @param Capacity16 The pointer of EFI_SCSI_DISK_CAPACITY_DATA16
1160 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
1161 IN EFI_SCSI_DISK_CAPACITY_DATA
*Capacity10
,
1162 IN EFI_SCSI_DISK_CAPACITY_DATA16
*Capacity16
1166 Check sense key to find if media presents.
1168 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1169 @param SenseCounts The number of sense key
1171 @retval TRUE NOT any media
1172 @retval FALSE Media presents
1176 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1177 IN UINTN SenseCounts
1183 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1184 @param SenseCounts The number of sense key
1187 @retval FALSE NOT error
1191 ScsiDiskIsMediaError (
1192 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1193 IN UINTN SenseCounts
1197 Check sense key to find if hardware error happens.
1199 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1200 @param SenseCounts The number of sense key
1202 @retval TRUE Hardware error exits.
1203 @retval FALSE NO error.
1207 ScsiDiskIsHardwareError (
1208 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1209 IN UINTN SenseCounts
1213 Check sense key to find if media has changed.
1215 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1216 @param SenseCounts The number of sense key
1218 @retval TRUE Media is changed.
1219 @retval FALSE Medit is NOT changed.
1222 ScsiDiskIsMediaChange (
1223 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1224 IN UINTN SenseCounts
1228 Check sense key to find if reset happens.
1230 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1231 @param SenseCounts The number of sense key
1233 @retval TRUE It is reset before.
1234 @retval FALSE It is NOT reset before.
1238 ScsiDiskIsResetBefore (
1239 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1240 IN UINTN SenseCounts
1244 Check sense key to find if the drive is ready.
1246 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1247 @param SenseCounts The number of sense key
1248 @param RetryLater The flag means if need a retry
1250 @retval TRUE Drive is ready.
1251 @retval FALSE Drive is NOT ready.
1255 ScsiDiskIsDriveReady (
1256 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1257 IN UINTN SenseCounts
,
1258 OUT BOOLEAN
*RetryLater
1262 Check sense key to find if it has sense key.
1264 @param SenseData - The pointer of EFI_SCSI_SENSE_DATA
1265 @param SenseCounts - The number of sense key
1267 @retval TRUE It has sense key.
1268 @retval FALSE It has NOT any sense key.
1272 ScsiDiskHaveSenseKey (
1273 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1274 IN UINTN SenseCounts
1278 Release resource about disk device.
1280 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1284 ReleaseScsiDiskDeviceResources (
1285 IN SCSI_DISK_DEV
*ScsiDiskDevice
1289 Determine if Block Io should be produced.
1292 @param ChildHandle Child Handle to retrieve Parent information.
1294 @retval TRUE Should produce Block Io.
1295 @retval FALSE Should not produce Block Io.
1299 DetermineInstallBlockIo (
1300 IN EFI_HANDLE ChildHandle
1304 Initialize the installation of DiskInfo protocol.
1306 This function prepares for the installation of DiskInfo protocol on the child handle.
1307 By default, it installs DiskInfo protocol with SCSI interface GUID. If it further
1308 detects that the physical device is an ATAPI/AHCI device, it then updates interface GUID
1309 to be IDE/AHCI interface GUID.
1311 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1312 @param ChildHandle Child handle to install DiskInfo protocol.
1316 InitializeInstallDiskInfo (
1317 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1318 IN EFI_HANDLE ChildHandle
1322 Search protocol database and check to see if the protocol
1323 specified by ProtocolGuid is present on a ControllerHandle and opened by
1324 ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1325 If the ControllerHandle is found, then the protocol specified by ProtocolGuid
1326 will be opened on it.
1329 @param ProtocolGuid ProtocolGuid pointer.
1330 @param ChildHandle Child Handle to retrieve Parent information.
1336 IN EFI_GUID
*ProtocolGuid
,
1337 IN EFI_HANDLE ChildHandle