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 // As ScsiDisk and ScsiBus driver are used to manage SCSI or ATAPI devices, the timout
161 // value is updated to 30s to follow ATA/ATAPI spec in which the device may take up to 30s
162 // to respond command.
164 #define SCSI_DISK_TIMEOUT EFI_TIMER_PERIOD_SECONDS (30)
167 Test to see if this driver supports ControllerHandle.
169 This service is called by the EFI boot service ConnectController(). In order
170 to make drivers as small as possible, there are a few calling restrictions for
171 this service. ConnectController() must follow these calling restrictions.
172 If any other agent wishes to call Supported() it must also follow these
173 calling restrictions.
175 @param This Protocol instance pointer.
176 @param ControllerHandle Handle of device to test
177 @param RemainingDevicePath Optional parameter use to pick a specific child
180 @retval EFI_SUCCESS This driver supports this device
181 @retval EFI_ALREADY_STARTED This driver is already running on this device
182 @retval other This driver does not support this device
187 ScsiDiskDriverBindingSupported (
188 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
189 IN EFI_HANDLE Controller
,
190 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
194 Start this driver on ControllerHandle.
196 This service is called by the EFI boot service ConnectController(). In order
197 to make drivers as small as possible, there are a few calling restrictions for
198 this service. ConnectController() must follow these calling restrictions. If
199 any other agent wishes to call Start() it must also follow these calling
202 @param This Protocol instance pointer.
203 @param ControllerHandle Handle of device to bind driver to
204 @param RemainingDevicePath Optional parameter use to pick a specific child
207 @retval EFI_SUCCESS This driver is added to ControllerHandle
208 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
209 @retval other This driver does not support this device
214 ScsiDiskDriverBindingStart (
215 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
216 IN EFI_HANDLE Controller
,
217 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
221 Stop this driver on ControllerHandle.
223 This service is called by the EFI boot service DisconnectController().
224 In order to make drivers as small as possible, there are a few calling
225 restrictions for this service. DisconnectController() must follow these
226 calling restrictions. If any other agent wishes to call Stop() it must
227 also follow these calling restrictions.
229 @param This Protocol instance pointer.
230 @param ControllerHandle Handle of device to stop driver on
231 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
232 children is zero stop the entire bus driver.
233 @param ChildHandleBuffer List of Child Handles to Stop.
235 @retval EFI_SUCCESS This driver is removed ControllerHandle
236 @retval other This driver was not removed from this device
241 ScsiDiskDriverBindingStop (
242 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
243 IN EFI_HANDLE Controller
,
244 IN UINTN NumberOfChildren
,
245 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
249 // EFI Component Name Functions
252 Retrieves a Unicode string that is the user readable name of the driver.
254 This function retrieves the user readable name of a driver in the form of a
255 Unicode string. If the driver specified by This has a user readable name in
256 the language specified by Language, then a pointer to the driver name is
257 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
258 by This does not support the language specified by Language,
259 then EFI_UNSUPPORTED is returned.
261 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
262 EFI_COMPONENT_NAME_PROTOCOL instance.
264 @param Language A pointer to a Null-terminated ASCII string
265 array indicating the language. This is the
266 language of the driver name that the caller is
267 requesting, and it must match one of the
268 languages specified in SupportedLanguages. The
269 number of languages supported by a driver is up
270 to the driver writer. Language is specified
271 in RFC 4646 or ISO 639-2 language code format.
273 @param DriverName A pointer to the Unicode string to return.
274 This Unicode string is the name of the
275 driver specified by This in the language
276 specified by Language.
278 @retval EFI_SUCCESS The Unicode string for the Driver specified by
279 This and the language specified by Language was
280 returned in DriverName.
282 @retval EFI_INVALID_PARAMETER Language is NULL.
284 @retval EFI_INVALID_PARAMETER DriverName is NULL.
286 @retval EFI_UNSUPPORTED The driver specified by This does not support
287 the language specified by Language.
292 ScsiDiskComponentNameGetDriverName (
293 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
295 OUT CHAR16
**DriverName
300 Retrieves a Unicode string that is the user readable name of the controller
301 that is being managed by a driver.
303 This function retrieves the user readable name of the controller specified by
304 ControllerHandle and ChildHandle in the form of a Unicode string. If the
305 driver specified by This has a user readable name in the language specified by
306 Language, then a pointer to the controller name is returned in ControllerName,
307 and EFI_SUCCESS is returned. If the driver specified by This is not currently
308 managing the controller specified by ControllerHandle and ChildHandle,
309 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
310 support the language specified by Language, then EFI_UNSUPPORTED is returned.
312 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
313 EFI_COMPONENT_NAME_PROTOCOL instance.
315 @param ControllerHandle The handle of a controller that the driver
316 specified by This is managing. This handle
317 specifies the controller whose name is to be
320 @param ChildHandle The handle of the child controller to retrieve
321 the name of. This is an optional parameter that
322 may be NULL. It will be NULL for device
323 drivers. It will also be NULL for a bus drivers
324 that wish to retrieve the name of the bus
325 controller. It will not be NULL for a bus
326 driver that wishes to retrieve the name of a
329 @param Language A pointer to a Null-terminated ASCII string
330 array indicating the language. This is the
331 language of the driver name that the caller is
332 requesting, and it must match one of the
333 languages specified in SupportedLanguages. The
334 number of languages supported by a driver is up
335 to the driver writer. Language is specified in
336 RFC 4646 or ISO 639-2 language code format.
338 @param ControllerName A pointer to the Unicode string to return.
339 This Unicode string is the name of the
340 controller specified by ControllerHandle and
341 ChildHandle in the language specified by
342 Language from the point of view of the driver
345 @retval EFI_SUCCESS The Unicode string for the user readable name in
346 the language specified by Language for the
347 driver specified by This was returned in
350 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
352 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
355 @retval EFI_INVALID_PARAMETER Language is NULL.
357 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
359 @retval EFI_UNSUPPORTED The driver specified by This is not currently
360 managing the controller specified by
361 ControllerHandle and ChildHandle.
363 @retval EFI_UNSUPPORTED The driver specified by This does not support
364 the language specified by Language.
369 ScsiDiskComponentNameGetControllerName (
370 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
371 IN EFI_HANDLE ControllerHandle
,
372 IN EFI_HANDLE ChildHandle OPTIONAL
,
374 OUT CHAR16
**ControllerName
381 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
382 @param ExtendedVerification The flag about if extend verificate
384 @retval EFI_SUCCESS The device was reset.
385 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
387 @return EFI_STATUS is retured from EFI_SCSI_IO_PROTOCOL.ResetDevice().
393 IN EFI_BLOCK_IO_PROTOCOL
*This
,
394 IN BOOLEAN ExtendedVerification
399 The function is to Read Block from SCSI Disk.
401 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
402 @param MediaId The Id of Media detected
403 @param Lba The logic block address
404 @param BufferSize The size of Buffer
405 @param Buffer The buffer to fill the read out data
407 @retval EFI_SUCCESS Successfully to read out block.
408 @retval EFI_DEVICE_ERROR Fail to detect media.
409 @retval EFI_NO_MEDIA Media is not present.
410 @retval EFI_MEDIA_CHANGED Media has changed.
411 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
412 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
418 IN EFI_BLOCK_IO_PROTOCOL
*This
,
427 The function is to Write Block to SCSI Disk.
429 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
430 @param MediaId The Id of Media detected
431 @param Lba The logic block address
432 @param BufferSize The size of Buffer
433 @param Buffer The buffer to fill the read out data
435 @retval EFI_SUCCESS Successfully to read out block.
436 @retval EFI_WRITE_PROTECTED The device can not be written to.
437 @retval EFI_DEVICE_ERROR Fail to detect media.
438 @retval EFI_NO_MEDIA Media is not present.
439 @retval EFI_MEDIA_CHNAGED Media has changed.
440 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
441 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
446 ScsiDiskWriteBlocks (
447 IN EFI_BLOCK_IO_PROTOCOL
*This
,
458 EFI_SUCCESS is returned directly.
460 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
462 @retval EFI_SUCCESS All outstanding data was written to the device
467 ScsiDiskFlushBlocks (
468 IN EFI_BLOCK_IO_PROTOCOL
*This
475 @param This The pointer of EFI_BLOCK_IO2_PROTOCOL.
476 @param ExtendedVerification The flag about if extend verificate.
478 @retval EFI_SUCCESS The device was reset.
479 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
481 @return EFI_STATUS is returned from EFI_SCSI_IO_PROTOCOL.ResetDevice().
487 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
488 IN BOOLEAN ExtendedVerification
492 The function is to Read Block from SCSI Disk.
494 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
495 @param MediaId The Id of Media detected.
496 @param Lba The logic block address.
497 @param Token A pointer to the token associated with the transaction.
498 @param BufferSize The size of Buffer.
499 @param Buffer The buffer to fill the read out data.
501 @retval EFI_SUCCESS The read request was queued if Token-> Event is
502 not NULL. The data was read correctly from the
503 device if theToken-> Event is NULL.
504 @retval EFI_DEVICE_ERROR The device reported an error while attempting
505 to perform the read operation.
506 @retval EFI_NO_MEDIA There is no media in the device.
507 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
508 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
509 the intrinsic block size of the device.
510 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
511 valid, or the buffer is not on proper
513 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
519 ScsiDiskReadBlocksEx (
520 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
523 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
529 The function is to Write Block to SCSI Disk.
531 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
532 @param MediaId The Id of Media detected.
533 @param Lba The logic block address.
534 @param Token A pointer to the token associated with the transaction.
535 @param BufferSize The size of Buffer.
536 @param Buffer The buffer to fill the read out data.
538 @retval EFI_SUCCESS The data were written correctly to the device.
539 @retval EFI_WRITE_PROTECTED The device cannot be written to.
540 @retval EFI_NO_MEDIA There is no media in the device.
541 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
542 @retval EFI_DEVICE_ERROR The device reported an error while attempting
543 to perform the write operation.
544 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
545 the intrinsic block size of the device.
546 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
547 valid, or the buffer is not on proper
553 ScsiDiskWriteBlocksEx (
554 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
557 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
563 Flush the Block Device.
565 @param This Indicates a pointer to the calling context.
566 @param Token A pointer to the token associated with the transaction.
568 @retval EFI_SUCCESS All outstanding data was written to the device.
569 @retval EFI_DEVICE_ERROR The device reported an error while attempting to
571 @retval EFI_WRITE_PROTECTED The device cannot be written to.
572 @retval EFI_NO_MEDIA There is no media in the device.
573 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
578 ScsiDiskFlushBlocksEx (
579 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
580 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
585 Provides inquiry information for the controller type.
587 This function is used by the IDE bus driver to get inquiry data. Data format
588 of Identify data is defined by the Interface GUID.
590 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
591 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
592 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
594 @retval EFI_SUCCESS The command was accepted without any errors.
595 @retval EFI_NOT_FOUND Device does not support this data class
596 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
597 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
602 ScsiDiskInfoInquiry (
603 IN EFI_DISK_INFO_PROTOCOL
*This
,
604 IN OUT VOID
*InquiryData
,
605 IN OUT UINT32
*InquiryDataSize
610 Provides identify information for the controller type.
612 This function is used by the IDE bus driver to get identify data. Data format
613 of Identify data is defined by the Interface GUID.
615 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
617 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
618 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
621 @retval EFI_SUCCESS The command was accepted without any errors.
622 @retval EFI_NOT_FOUND Device does not support this data class
623 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
624 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
629 ScsiDiskInfoIdentify (
630 IN EFI_DISK_INFO_PROTOCOL
*This
,
631 IN OUT VOID
*IdentifyData
,
632 IN OUT UINT32
*IdentifyDataSize
637 Provides sense data information for the controller type.
639 This function is used by the IDE bus driver to get sense data.
640 Data format of Sense data is defined by the Interface GUID.
642 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
643 @param[in, out] SenseData Pointer to the SenseData.
644 @param[in, out] SenseDataSize Size of SenseData in bytes.
645 @param[out] SenseDataNumber Pointer to the value for the sense data size.
647 @retval EFI_SUCCESS The command was accepted without any errors.
648 @retval EFI_NOT_FOUND Device does not support this data class.
649 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
650 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
655 ScsiDiskInfoSenseData (
656 IN EFI_DISK_INFO_PROTOCOL
*This
,
657 IN OUT VOID
*SenseData
,
658 IN OUT UINT32
*SenseDataSize
,
659 OUT UINT8
*SenseDataNumber
663 This function is used by the IDE bus driver to get controller information.
665 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
666 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
667 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
669 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
670 @retval EFI_UNSUPPORTED This is not an IDE device.
675 ScsiDiskInfoWhichIde (
676 IN EFI_DISK_INFO_PROTOCOL
*This
,
677 OUT UINT32
*IdeChannel
,
678 OUT UINT32
*IdeDevice
683 Detect Device and read out capacity ,if error occurs, parse the sense key.
685 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
686 @param MustReadCapacity The flag about reading device capacity
687 @param MediaChange The pointer of flag indicates if media has changed
689 @retval EFI_DEVICE_ERROR Indicates that error occurs
690 @retval EFI_SUCCESS Successfully to detect media
694 ScsiDiskDetectMedia (
695 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
696 IN BOOLEAN MustReadCapacity
,
697 OUT BOOLEAN
*MediaChange
703 When Test Unit Ready command succeeds, retrieve Sense Keys via Request Sense;
704 When Test Unit Ready command encounters any error caused by host adapter or
705 target, return error without retrieving Sense Keys.
707 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
708 @param NeedRetry The pointer of flag indicates try again
709 @param SenseDataArray The pointer of an array of sense data
710 @param NumberOfSenseKeys The pointer of the number of sense data array
712 @retval EFI_DEVICE_ERROR Indicates that error occurs
713 @retval EFI_SUCCESS Successfully to test unit
717 ScsiDiskTestUnitReady (
718 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
719 OUT BOOLEAN
*NeedRetry
,
720 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
721 OUT UINTN
*NumberOfSenseKeys
726 Parsing Sense Keys which got from request sense command.
728 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
729 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
730 @param NumberOfSenseKeys The number of sense key
731 @param Action The pointer of action which indicates what is need to do next
733 @retval EFI_DEVICE_ERROR Indicates that error occurs
734 @retval EFI_SUCCESS Successfully to complete the parsing
738 DetectMediaParsingSenseKeys (
739 OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
740 IN EFI_SCSI_SENSE_DATA
*SenseData
,
741 IN UINTN NumberOfSenseKeys
,
747 Send read capacity command to device and get the device parameter.
749 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
750 @param NeedRetry The pointer of flag indicates if need a retry
751 @param SenseDataArray The pointer of an array of sense data
752 @param NumberOfSenseKeys The number of sense key
754 @retval EFI_DEVICE_ERROR Indicates that error occurs
755 @retval EFI_SUCCESS Successfully to read capacity
759 ScsiDiskReadCapacity (
760 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
761 OUT BOOLEAN
*NeedRetry
,
762 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
763 OUT UINTN
*NumberOfSenseKeys
767 Check the HostAdapter status and re-interpret it in EFI_STATUS.
769 @param HostAdapterStatus Host Adapter status
771 @retval EFI_SUCCESS Host adapter is OK.
772 @retval EFI_TIMEOUT Timeout.
773 @retval EFI_NOT_READY Adapter NOT ready.
774 @retval EFI_DEVICE_ERROR Adapter device error.
778 CheckHostAdapterStatus (
779 IN UINT8 HostAdapterStatus
784 Check the target status and re-interpret it in EFI_STATUS.
786 @param TargetStatus Target status
788 @retval EFI_NOT_READY Device is NOT ready.
789 @retval EFI_DEVICE_ERROR
795 IN UINT8 TargetStatus
799 Retrieve all sense keys from the device.
801 When encountering error during the process, if retrieve sense keys before
802 error encountered, it returns the sense keys with return status set to EFI_SUCCESS,
803 and NeedRetry set to FALSE; otherwize, return the proper return status.
805 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
806 @param NeedRetry The pointer of flag indicates if need a retry
807 @param SenseDataArray The pointer of an array of sense data
808 @param NumberOfSenseKeys The number of sense key
809 @param AskResetIfError The flag indicates if need reset when error occurs
811 @retval EFI_DEVICE_ERROR Indicates that error occurs
812 @retval EFI_SUCCESS Successfully to request sense key
816 ScsiDiskRequestSenseKeys (
817 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
818 OUT BOOLEAN
*NeedRetry
,
819 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
820 OUT UINTN
*NumberOfSenseKeys
,
821 IN BOOLEAN AskResetIfError
825 Send out Inquiry command to Device.
827 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
828 @param NeedRetry Indicates if needs try again when error happens
830 @retval EFI_DEVICE_ERROR Indicates that error occurs
831 @retval EFI_SUCCESS Successfully to detect media
835 ScsiDiskInquiryDevice (
836 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
837 OUT BOOLEAN
*NeedRetry
843 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
848 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
852 Read sector from SCSI Disk.
854 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
855 @param Buffer The buffer to fill in the read out data
856 @param Lba Logic block address
857 @param NumberOfBlocks The number of blocks to read
859 @retval EFI_DEVICE_ERROR Indicates a device error.
860 @retval EFI_SUCCESS Operation is successful.
864 ScsiDiskReadSectors (
865 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
868 IN UINTN NumberOfBlocks
872 Write sector to SCSI Disk.
874 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
875 @param Buffer The buffer of data to be written into SCSI Disk
876 @param Lba Logic block address
877 @param NumberOfBlocks The number of blocks to read
879 @retval EFI_DEVICE_ERROR Indicates a device error.
880 @retval EFI_SUCCESS Operation is successful.
884 ScsiDiskWriteSectors (
885 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
888 IN UINTN NumberOfBlocks
892 Asynchronously read sector from SCSI Disk.
894 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
895 @param Buffer The buffer to fill in the read out data.
896 @param Lba Logic block address.
897 @param NumberOfBlocks The number of blocks to read.
898 @param Token A pointer to the token associated with the
899 non-blocking read request.
901 @retval EFI_INVALID_PARAMETER Token is NULL or Token->Event is NULL.
902 @retval EFI_DEVICE_ERROR Indicates a device error.
903 @retval EFI_SUCCESS Operation is successful.
907 ScsiDiskAsyncReadSectors (
908 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
911 IN UINTN NumberOfBlocks
,
912 IN EFI_BLOCK_IO2_TOKEN
*Token
916 Asynchronously write sector to SCSI Disk.
918 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
919 @param Buffer The buffer of data to be written into SCSI Disk.
920 @param Lba Logic block address.
921 @param NumberOfBlocks The number of blocks to read.
922 @param Token A pointer to the token associated with the
923 non-blocking read request.
925 @retval EFI_INVALID_PARAMETER Token is NULL or Token->Event is NULL
926 @retval EFI_DEVICE_ERROR Indicates a device error.
927 @retval EFI_SUCCESS Operation is successful.
931 ScsiDiskAsyncWriteSectors (
932 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
935 IN UINTN NumberOfBlocks
,
936 IN EFI_BLOCK_IO2_TOKEN
*Token
940 Submit Read(10) command.
942 @param ScsiDiskDevice The pointer of ScsiDiskDevice
943 @param NeedRetry The pointer of flag indicates if needs retry if error happens
944 @param Timeout The time to complete the command
945 @param DataBuffer The buffer to fill with the read out data
946 @param DataLength The length of buffer
947 @param StartLba The start logic block address
948 @param SectorCount The number of blocks to read
950 @return EFI_STATUS is returned by calling ScsiRead10Command().
954 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
955 OUT BOOLEAN
*NeedRetry
,
957 OUT UINT8
*DataBuffer
,
958 IN OUT UINT32
*DataLength
,
960 IN UINT32 SectorCount
964 Submit Write(10) Command.
966 @param ScsiDiskDevice The pointer of ScsiDiskDevice
967 @param NeedRetry The pointer of flag indicates if needs retry if error happens
968 @param Timeout The time to complete the command
969 @param DataBuffer The buffer to fill with the read out data
970 @param DataLength The length of buffer
971 @param StartLba The start logic block address
972 @param SectorCount The number of blocks to write
974 @return EFI_STATUS is returned by calling ScsiWrite10Command().
979 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
980 OUT BOOLEAN
*NeedRetry
,
982 IN UINT8
*DataBuffer
,
983 IN OUT UINT32
*DataLength
,
985 IN UINT32 SectorCount
989 Submit Read(16) command.
991 @param ScsiDiskDevice The pointer of ScsiDiskDevice
992 @param NeedRetry The pointer of flag indicates if needs retry if error happens
993 @param Timeout The time to complete the command
994 @param DataBuffer The buffer to fill with the read out data
995 @param DataLength The length of buffer
996 @param StartLba The start logic block address
997 @param SectorCount The number of blocks to read
999 @return EFI_STATUS is returned by calling ScsiRead16Command().
1003 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1004 OUT BOOLEAN
*NeedRetry
,
1006 OUT UINT8
*DataBuffer
,
1007 IN OUT UINT32
*DataLength
,
1009 IN UINT32 SectorCount
1013 Submit Write(16) Command.
1015 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1016 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1017 @param Timeout The time to complete the command
1018 @param DataBuffer The buffer to fill with the read out data
1019 @param DataLength The length of buffer
1020 @param StartLba The start logic block address
1021 @param SectorCount The number of blocks to write
1023 @return EFI_STATUS is returned by calling ScsiWrite16Command().
1028 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1029 OUT BOOLEAN
*NeedRetry
,
1031 IN UINT8
*DataBuffer
,
1032 IN OUT UINT32
*DataLength
,
1034 IN UINT32 SectorCount
1038 Submit Async Read(10) command.
1040 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1041 @param Timeout The time to complete the command.
1042 @param TimesRetry The number of times the command has been retried.
1043 @param DataBuffer The buffer to fill with the read out data.
1044 @param DataLength The length of buffer.
1045 @param StartLba The start logic block address.
1046 @param SectorCount The number of blocks to read.
1047 @param BlkIo2Req The upstream BlockIo2 request.
1048 @param Token The pointer to the token associated with the
1049 non-blocking read request.
1051 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1053 @return others Status returned by calling
1054 ScsiRead10CommandEx().
1058 ScsiDiskAsyncRead10 (
1059 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1061 IN UINT8 TimesRetry
,
1062 OUT UINT8
*DataBuffer
,
1063 IN UINT32 DataLength
,
1065 IN UINT32 SectorCount
,
1066 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1067 IN EFI_BLOCK_IO2_TOKEN
*Token
1071 Submit Async Write(10) command.
1073 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1074 @param Timeout The time to complete the command.
1075 @param TimesRetry The number of times the command has been retried.
1076 @param DataBuffer The buffer contains the data to write.
1077 @param DataLength The length of buffer.
1078 @param StartLba The start logic block address.
1079 @param SectorCount The number of blocks to write.
1080 @param BlkIo2Req The upstream BlockIo2 request.
1081 @param Token The pointer to the token associated with the
1082 non-blocking read request.
1084 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1086 @return others Status returned by calling
1087 ScsiWrite10CommandEx().
1091 ScsiDiskAsyncWrite10 (
1092 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1094 IN UINT8 TimesRetry
,
1095 IN UINT8
*DataBuffer
,
1096 IN UINT32 DataLength
,
1098 IN UINT32 SectorCount
,
1099 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1100 IN EFI_BLOCK_IO2_TOKEN
*Token
1104 Submit Async Read(16) command.
1106 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1107 @param Timeout The time to complete the command.
1108 @param TimesRetry The number of times the command has been retried.
1109 @param DataBuffer The buffer to fill with the read out data.
1110 @param DataLength The length of buffer.
1111 @param StartLba The start logic block address.
1112 @param SectorCount The number of blocks to read.
1113 @param BlkIo2Req The upstream BlockIo2 request.
1114 @param Token The pointer to the token associated with the
1115 non-blocking read request.
1117 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1119 @return others Status returned by calling
1120 ScsiRead16CommandEx().
1124 ScsiDiskAsyncRead16 (
1125 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1127 IN UINT8 TimesRetry
,
1128 OUT UINT8
*DataBuffer
,
1129 IN UINT32 DataLength
,
1131 IN UINT32 SectorCount
,
1132 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1133 IN EFI_BLOCK_IO2_TOKEN
*Token
1137 Submit Async Write(16) command.
1139 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1140 @param Timeout The time to complete the command.
1141 @param TimesRetry The number of times the command has been retried.
1142 @param DataBuffer The buffer contains the data to write.
1143 @param DataLength The length of buffer.
1144 @param StartLba The start logic block address.
1145 @param SectorCount The number of blocks to write.
1146 @param BlkIo2Req The upstream BlockIo2 request.
1147 @param Token The pointer to the token associated with the
1148 non-blocking read request.
1150 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1152 @return others Status returned by calling
1153 ScsiWrite16CommandEx().
1157 ScsiDiskAsyncWrite16 (
1158 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1160 IN UINT8 TimesRetry
,
1161 IN UINT8
*DataBuffer
,
1162 IN UINT32 DataLength
,
1164 IN UINT32 SectorCount
,
1165 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1166 IN EFI_BLOCK_IO2_TOKEN
*Token
1170 Get information from media read capacity command.
1172 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1173 @param Capacity10 The pointer of EFI_SCSI_DISK_CAPACITY_DATA
1174 @param Capacity16 The pointer of EFI_SCSI_DISK_CAPACITY_DATA16
1178 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
1179 IN EFI_SCSI_DISK_CAPACITY_DATA
*Capacity10
,
1180 IN EFI_SCSI_DISK_CAPACITY_DATA16
*Capacity16
1184 Check sense key to find if media presents.
1186 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1187 @param SenseCounts The number of sense key
1189 @retval TRUE NOT any media
1190 @retval FALSE Media presents
1194 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1195 IN UINTN SenseCounts
1201 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1202 @param SenseCounts The number of sense key
1205 @retval FALSE NOT error
1209 ScsiDiskIsMediaError (
1210 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1211 IN UINTN SenseCounts
1215 Check sense key to find if hardware error happens.
1217 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1218 @param SenseCounts The number of sense key
1220 @retval TRUE Hardware error exits.
1221 @retval FALSE NO error.
1225 ScsiDiskIsHardwareError (
1226 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1227 IN UINTN SenseCounts
1231 Check sense key to find if media has changed.
1233 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1234 @param SenseCounts The number of sense key
1236 @retval TRUE Media is changed.
1237 @retval FALSE Medit is NOT changed.
1240 ScsiDiskIsMediaChange (
1241 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1242 IN UINTN SenseCounts
1246 Check sense key to find if reset happens.
1248 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1249 @param SenseCounts The number of sense key
1251 @retval TRUE It is reset before.
1252 @retval FALSE It is NOT reset before.
1256 ScsiDiskIsResetBefore (
1257 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1258 IN UINTN SenseCounts
1262 Check sense key to find if the drive is ready.
1264 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1265 @param SenseCounts The number of sense key
1266 @param RetryLater The flag means if need a retry
1268 @retval TRUE Drive is ready.
1269 @retval FALSE Drive is NOT ready.
1273 ScsiDiskIsDriveReady (
1274 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1275 IN UINTN SenseCounts
,
1276 OUT BOOLEAN
*RetryLater
1280 Check sense key to find if it has sense key.
1282 @param SenseData - The pointer of EFI_SCSI_SENSE_DATA
1283 @param SenseCounts - The number of sense key
1285 @retval TRUE It has sense key.
1286 @retval FALSE It has NOT any sense key.
1290 ScsiDiskHaveSenseKey (
1291 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1292 IN UINTN SenseCounts
1296 Release resource about disk device.
1298 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1302 ReleaseScsiDiskDeviceResources (
1303 IN SCSI_DISK_DEV
*ScsiDiskDevice
1307 Determine if Block Io should be produced.
1310 @param ChildHandle Child Handle to retrieve Parent information.
1312 @retval TRUE Should produce Block Io.
1313 @retval FALSE Should not produce Block Io.
1317 DetermineInstallBlockIo (
1318 IN EFI_HANDLE ChildHandle
1322 Initialize the installation of DiskInfo protocol.
1324 This function prepares for the installation of DiskInfo protocol on the child handle.
1325 By default, it installs DiskInfo protocol with SCSI interface GUID. If it further
1326 detects that the physical device is an ATAPI/AHCI device, it then updates interface GUID
1327 to be IDE/AHCI interface GUID.
1329 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1330 @param ChildHandle Child handle to install DiskInfo protocol.
1334 InitializeInstallDiskInfo (
1335 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1336 IN EFI_HANDLE ChildHandle
1340 Search protocol database and check to see if the protocol
1341 specified by ProtocolGuid is present on a ControllerHandle and opened by
1342 ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1343 If the ControllerHandle is found, then the protocol specified by ProtocolGuid
1344 will be opened on it.
1347 @param ProtocolGuid ProtocolGuid pointer.
1348 @param ChildHandle Child Handle to retrieve Parent information.
1354 IN EFI_GUID
*ProtocolGuid
,
1355 IN EFI_HANDLE ChildHandle