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 writing back the
561 @retval EFI_NO_MEDIA There is no media in the device.
566 ScsiDiskFlushBlocksEx (
567 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
568 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
573 Provides inquiry information for the controller type.
575 This function is used by the IDE bus driver to get inquiry data. Data format
576 of Identify data is defined by the Interface GUID.
578 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
579 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
580 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
582 @retval EFI_SUCCESS The command was accepted without any errors.
583 @retval EFI_NOT_FOUND Device does not support this data class
584 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
585 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
590 ScsiDiskInfoInquiry (
591 IN EFI_DISK_INFO_PROTOCOL
*This
,
592 IN OUT VOID
*InquiryData
,
593 IN OUT UINT32
*InquiryDataSize
598 Provides identify information for the controller type.
600 This function is used by the IDE bus driver to get identify data. Data format
601 of Identify data is defined by the Interface GUID.
603 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
605 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
606 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
609 @retval EFI_SUCCESS The command was accepted without any errors.
610 @retval EFI_NOT_FOUND Device does not support this data class
611 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
612 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
617 ScsiDiskInfoIdentify (
618 IN EFI_DISK_INFO_PROTOCOL
*This
,
619 IN OUT VOID
*IdentifyData
,
620 IN OUT UINT32
*IdentifyDataSize
625 Provides sense data information for the controller type.
627 This function is used by the IDE bus driver to get sense data.
628 Data format of Sense data is defined by the Interface GUID.
630 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
631 @param[in, out] SenseData Pointer to the SenseData.
632 @param[in, out] SenseDataSize Size of SenseData in bytes.
633 @param[out] SenseDataNumber Pointer to the value for the sense data size.
635 @retval EFI_SUCCESS The command was accepted without any errors.
636 @retval EFI_NOT_FOUND Device does not support this data class.
637 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
638 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
643 ScsiDiskInfoSenseData (
644 IN EFI_DISK_INFO_PROTOCOL
*This
,
645 IN OUT VOID
*SenseData
,
646 IN OUT UINT32
*SenseDataSize
,
647 OUT UINT8
*SenseDataNumber
651 This function is used by the IDE bus driver to get controller information.
653 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
654 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
655 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
657 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
658 @retval EFI_UNSUPPORTED This is not an IDE device.
663 ScsiDiskInfoWhichIde (
664 IN EFI_DISK_INFO_PROTOCOL
*This
,
665 OUT UINT32
*IdeChannel
,
666 OUT UINT32
*IdeDevice
671 Detect Device and read out capacity ,if error occurs, parse the sense key.
673 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
674 @param MustReadCapacity The flag about reading device capacity
675 @param MediaChange The pointer of flag indicates if media has changed
677 @retval EFI_DEVICE_ERROR Indicates that error occurs
678 @retval EFI_SUCCESS Successfully to detect media
682 ScsiDiskDetectMedia (
683 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
684 IN BOOLEAN MustReadCapacity
,
685 OUT BOOLEAN
*MediaChange
691 When Test Unit Ready command succeeds, retrieve Sense Keys via Request Sense;
692 When Test Unit Ready command encounters any error caused by host adapter or
693 target, return error without retrieving Sense Keys.
695 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
696 @param NeedRetry The pointer of flag indicates try again
697 @param SenseDataArray The pointer of an array of sense data
698 @param NumberOfSenseKeys The pointer of the number of sense data array
700 @retval EFI_DEVICE_ERROR Indicates that error occurs
701 @retval EFI_SUCCESS Successfully to test unit
705 ScsiDiskTestUnitReady (
706 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
707 OUT BOOLEAN
*NeedRetry
,
708 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
709 OUT UINTN
*NumberOfSenseKeys
714 Parsing Sense Keys which got from request sense command.
716 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
717 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
718 @param NumberOfSenseKeys The number of sense key
719 @param Action The pointer of action which indicates what is need to do next
721 @retval EFI_DEVICE_ERROR Indicates that error occurs
722 @retval EFI_SUCCESS Successfully to complete the parsing
726 DetectMediaParsingSenseKeys (
727 OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
728 IN EFI_SCSI_SENSE_DATA
*SenseData
,
729 IN UINTN NumberOfSenseKeys
,
735 Send read capacity command to device and get the device parameter.
737 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
738 @param NeedRetry The pointer of flag indicates if need a retry
739 @param SenseDataArray The pointer of an array of sense data
740 @param NumberOfSenseKeys The number of sense key
742 @retval EFI_DEVICE_ERROR Indicates that error occurs
743 @retval EFI_SUCCESS Successfully to read capacity
747 ScsiDiskReadCapacity (
748 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
749 OUT BOOLEAN
*NeedRetry
,
750 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
751 OUT UINTN
*NumberOfSenseKeys
755 Check the HostAdapter status and re-interpret it in EFI_STATUS.
757 @param HostAdapterStatus Host Adapter status
759 @retval EFI_SUCCESS Host adapter is OK.
760 @retval EFI_TIMEOUT Timeout.
761 @retval EFI_NOT_READY Adapter NOT ready.
762 @retval EFI_DEVICE_ERROR Adapter device error.
766 CheckHostAdapterStatus (
767 IN UINT8 HostAdapterStatus
772 Check the target status and re-interpret it in EFI_STATUS.
774 @param TargetStatus Target status
776 @retval EFI_NOT_READY Device is NOT ready.
777 @retval EFI_DEVICE_ERROR
783 IN UINT8 TargetStatus
787 Retrieve all sense keys from the device.
789 When encountering error during the process, if retrieve sense keys before
790 error encountered, it returns the sense keys with return status set to EFI_SUCCESS,
791 and NeedRetry set to FALSE; otherwize, return the proper return status.
793 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
794 @param NeedRetry The pointer of flag indicates if need a retry
795 @param SenseDataArray The pointer of an array of sense data
796 @param NumberOfSenseKeys The number of sense key
797 @param AskResetIfError The flag indicates if need reset when error occurs
799 @retval EFI_DEVICE_ERROR Indicates that error occurs
800 @retval EFI_SUCCESS Successfully to request sense key
804 ScsiDiskRequestSenseKeys (
805 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
806 OUT BOOLEAN
*NeedRetry
,
807 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
808 OUT UINTN
*NumberOfSenseKeys
,
809 IN BOOLEAN AskResetIfError
813 Send out Inquiry command to Device.
815 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
816 @param NeedRetry Indicates if needs try again when error happens
818 @retval EFI_DEVICE_ERROR Indicates that error occurs
819 @retval EFI_SUCCESS Successfully to detect media
823 ScsiDiskInquiryDevice (
824 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
825 OUT BOOLEAN
*NeedRetry
831 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
836 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
840 Read sector from SCSI Disk.
842 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
843 @param Buffer The buffer to fill in the read out data
844 @param Lba Logic block address
845 @param NumberOfBlocks The number of blocks to read
847 @retval EFI_DEVICE_ERROR Indicates a device error.
848 @retval EFI_SUCCESS Operation is successful.
852 ScsiDiskReadSectors (
853 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
856 IN UINTN NumberOfBlocks
860 Write sector to SCSI Disk.
862 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
863 @param Buffer The buffer of data to be written into SCSI Disk
864 @param Lba Logic block address
865 @param NumberOfBlocks The number of blocks to read
867 @retval EFI_DEVICE_ERROR Indicates a device error.
868 @retval EFI_SUCCESS Operation is successful.
872 ScsiDiskWriteSectors (
873 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
876 IN UINTN NumberOfBlocks
880 Asynchronously read sector from SCSI Disk.
882 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
883 @param Buffer The buffer to fill in the read out data.
884 @param Lba Logic block address.
885 @param NumberOfBlocks The number of blocks to read.
886 @param Token A pointer to the token associated with the
887 non-blocking read request.
889 @retval EFI_INVALID_PARAMETER Token is NULL or Token->Event is NULL.
890 @retval EFI_DEVICE_ERROR Indicates a device error.
891 @retval EFI_SUCCESS Operation is successful.
895 ScsiDiskAsyncReadSectors (
896 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
899 IN UINTN NumberOfBlocks
,
900 IN EFI_BLOCK_IO2_TOKEN
*Token
904 Asynchronously write sector to SCSI Disk.
906 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
907 @param Buffer The buffer of data to be written into SCSI Disk.
908 @param Lba Logic block address.
909 @param NumberOfBlocks The number of blocks to read.
910 @param Token A pointer to the token associated with the
911 non-blocking read request.
913 @retval EFI_INVALID_PARAMETER Token is NULL or Token->Event is NULL
914 @retval EFI_DEVICE_ERROR Indicates a device error.
915 @retval EFI_SUCCESS Operation is successful.
919 ScsiDiskAsyncWriteSectors (
920 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
923 IN UINTN NumberOfBlocks
,
924 IN EFI_BLOCK_IO2_TOKEN
*Token
928 Submit Read(10) command.
930 @param ScsiDiskDevice The pointer of ScsiDiskDevice
931 @param NeedRetry The pointer of flag indicates if needs retry if error happens
932 @param Timeout The time to complete the command
933 @param DataBuffer The buffer to fill with the read out data
934 @param DataLength The length of buffer
935 @param StartLba The start logic block address
936 @param SectorCount The number of blocks to read
938 @return EFI_STATUS is returned by calling ScsiRead10Command().
942 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
943 OUT BOOLEAN
*NeedRetry
,
945 OUT UINT8
*DataBuffer
,
946 IN OUT UINT32
*DataLength
,
948 IN UINT32 SectorCount
952 Submit Write(10) Command.
954 @param ScsiDiskDevice The pointer of ScsiDiskDevice
955 @param NeedRetry The pointer of flag indicates if needs retry if error happens
956 @param Timeout The time to complete the command
957 @param DataBuffer The buffer to fill with the read out data
958 @param DataLength The length of buffer
959 @param StartLba The start logic block address
960 @param SectorCount The number of blocks to write
962 @return EFI_STATUS is returned by calling ScsiWrite10Command().
967 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
968 OUT BOOLEAN
*NeedRetry
,
970 IN UINT8
*DataBuffer
,
971 IN OUT UINT32
*DataLength
,
973 IN UINT32 SectorCount
977 Submit Read(16) command.
979 @param ScsiDiskDevice The pointer of ScsiDiskDevice
980 @param NeedRetry The pointer of flag indicates if needs retry if error happens
981 @param Timeout The time to complete the command
982 @param DataBuffer The buffer to fill with the read out data
983 @param DataLength The length of buffer
984 @param StartLba The start logic block address
985 @param SectorCount The number of blocks to read
987 @return EFI_STATUS is returned by calling ScsiRead16Command().
991 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
992 OUT BOOLEAN
*NeedRetry
,
994 OUT UINT8
*DataBuffer
,
995 IN OUT UINT32
*DataLength
,
997 IN UINT32 SectorCount
1001 Submit Write(16) Command.
1003 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1004 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1005 @param Timeout The time to complete the command
1006 @param DataBuffer The buffer to fill with the read out data
1007 @param DataLength The length of buffer
1008 @param StartLba The start logic block address
1009 @param SectorCount The number of blocks to write
1011 @return EFI_STATUS is returned by calling ScsiWrite16Command().
1016 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1017 OUT BOOLEAN
*NeedRetry
,
1019 IN UINT8
*DataBuffer
,
1020 IN OUT UINT32
*DataLength
,
1022 IN UINT32 SectorCount
1026 Submit Async Read(10) command.
1028 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1029 @param Timeout The time to complete the command.
1030 @param DataBuffer The buffer to fill with the read out data.
1031 @param DataLength The length of buffer.
1032 @param StartLba The start logic block address.
1033 @param SectorCount The number of blocks to read.
1034 @param BlkIo2Req The upstream BlockIo2 request.
1035 @param Token The pointer to the token associated with the
1036 non-blocking read request.
1038 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1040 @return others Status returned by calling
1041 ScsiRead10CommandEx().
1045 ScsiDiskAsyncRead10 (
1046 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1048 OUT UINT8
*DataBuffer
,
1049 IN UINT32 DataLength
,
1051 IN UINT32 SectorCount
,
1052 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1053 IN EFI_BLOCK_IO2_TOKEN
*Token
1057 Submit Async Write(10) command.
1059 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1060 @param Timeout The time to complete the command.
1061 @param DataBuffer The buffer contains the data to write.
1062 @param DataLength The length of buffer.
1063 @param StartLba The start logic block address.
1064 @param SectorCount The number of blocks to write.
1065 @param BlkIo2Req The upstream BlockIo2 request.
1066 @param Token The pointer to the token associated with the
1067 non-blocking read request.
1069 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1071 @return others Status returned by calling
1072 ScsiWrite10CommandEx().
1076 ScsiDiskAsyncWrite10 (
1077 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1079 IN UINT8
*DataBuffer
,
1080 IN UINT32 DataLength
,
1082 IN UINT32 SectorCount
,
1083 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1084 IN EFI_BLOCK_IO2_TOKEN
*Token
1088 Submit Async Read(16) command.
1090 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1091 @param Timeout The time to complete the command.
1092 @param DataBuffer The buffer to fill with the read out data.
1093 @param DataLength The length of buffer.
1094 @param StartLba The start logic block address.
1095 @param SectorCount The number of blocks to read.
1096 @param BlkIo2Req The upstream BlockIo2 request.
1097 @param Token The pointer to the token associated with the
1098 non-blocking read request.
1100 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1102 @return others Status returned by calling
1103 ScsiRead16CommandEx().
1107 ScsiDiskAsyncRead16 (
1108 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1110 OUT UINT8
*DataBuffer
,
1111 IN UINT32 DataLength
,
1113 IN UINT32 SectorCount
,
1114 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1115 IN EFI_BLOCK_IO2_TOKEN
*Token
1119 Submit Async Write(16) command.
1121 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1122 @param Timeout The time to complete the command.
1123 @param DataBuffer The buffer contains the data to write.
1124 @param DataLength The length of buffer.
1125 @param StartLba The start logic block address.
1126 @param SectorCount The number of blocks to write.
1127 @param BlkIo2Req The upstream BlockIo2 request.
1128 @param Token The pointer to the token associated with the
1129 non-blocking read request.
1131 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1133 @return others Status returned by calling
1134 ScsiWrite16CommandEx().
1138 ScsiDiskAsyncWrite16 (
1139 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1141 IN UINT8
*DataBuffer
,
1142 IN UINT32 DataLength
,
1144 IN UINT32 SectorCount
,
1145 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1146 IN EFI_BLOCK_IO2_TOKEN
*Token
1150 Get information from media read capacity command.
1152 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1153 @param Capacity10 The pointer of EFI_SCSI_DISK_CAPACITY_DATA
1154 @param Capacity16 The pointer of EFI_SCSI_DISK_CAPACITY_DATA16
1158 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
1159 IN EFI_SCSI_DISK_CAPACITY_DATA
*Capacity10
,
1160 IN EFI_SCSI_DISK_CAPACITY_DATA16
*Capacity16
1164 Check sense key to find if media presents.
1166 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1167 @param SenseCounts The number of sense key
1169 @retval TRUE NOT any media
1170 @retval FALSE Media presents
1174 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1175 IN UINTN SenseCounts
1181 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1182 @param SenseCounts The number of sense key
1185 @retval FALSE NOT error
1189 ScsiDiskIsMediaError (
1190 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1191 IN UINTN SenseCounts
1195 Check sense key to find if hardware error happens.
1197 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1198 @param SenseCounts The number of sense key
1200 @retval TRUE Hardware error exits.
1201 @retval FALSE NO error.
1205 ScsiDiskIsHardwareError (
1206 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1207 IN UINTN SenseCounts
1211 Check sense key to find if media has changed.
1213 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1214 @param SenseCounts The number of sense key
1216 @retval TRUE Media is changed.
1217 @retval FALSE Medit is NOT changed.
1220 ScsiDiskIsMediaChange (
1221 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1222 IN UINTN SenseCounts
1226 Check sense key to find if reset happens.
1228 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1229 @param SenseCounts The number of sense key
1231 @retval TRUE It is reset before.
1232 @retval FALSE It is NOT reset before.
1236 ScsiDiskIsResetBefore (
1237 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1238 IN UINTN SenseCounts
1242 Check sense key to find if the drive is ready.
1244 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1245 @param SenseCounts The number of sense key
1246 @param RetryLater The flag means if need a retry
1248 @retval TRUE Drive is ready.
1249 @retval FALSE Drive is NOT ready.
1253 ScsiDiskIsDriveReady (
1254 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1255 IN UINTN SenseCounts
,
1256 OUT BOOLEAN
*RetryLater
1260 Check sense key to find if it has sense key.
1262 @param SenseData - The pointer of EFI_SCSI_SENSE_DATA
1263 @param SenseCounts - The number of sense key
1265 @retval TRUE It has sense key.
1266 @retval FALSE It has NOT any sense key.
1270 ScsiDiskHaveSenseKey (
1271 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1272 IN UINTN SenseCounts
1276 Release resource about disk device.
1278 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1282 ReleaseScsiDiskDeviceResources (
1283 IN SCSI_DISK_DEV
*ScsiDiskDevice
1287 Determine if Block Io should be produced.
1290 @param ChildHandle Child Handle to retrieve Parent information.
1292 @retval TRUE Should produce Block Io.
1293 @retval FALSE Should not produce Block Io.
1297 DetermineInstallBlockIo (
1298 IN EFI_HANDLE ChildHandle
1302 Initialize the installation of DiskInfo protocol.
1304 This function prepares for the installation of DiskInfo protocol on the child handle.
1305 By default, it installs DiskInfo protocol with SCSI interface GUID. If it further
1306 detects that the physical device is an ATAPI/AHCI device, it then updates interface GUID
1307 to be IDE/AHCI interface GUID.
1309 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1310 @param ChildHandle Child handle to install DiskInfo protocol.
1314 InitializeInstallDiskInfo (
1315 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1316 IN EFI_HANDLE ChildHandle
1320 Search protocol database and check to see if the protocol
1321 specified by ProtocolGuid is present on a ControllerHandle and opened by
1322 ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1323 If the ControllerHandle is found, then the protocol specified by ProtocolGuid
1324 will be opened on it.
1327 @param ProtocolGuid ProtocolGuid pointer.
1328 @param ChildHandle Child Handle to retrieve Parent information.
1334 IN EFI_GUID
*ProtocolGuid
,
1335 IN EFI_HANDLE ChildHandle