2 Header file for SCSI Disk Driver.
4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
16 #include <Protocol/ScsiIo.h>
17 #include <Protocol/ComponentName.h>
18 #include <Protocol/BlockIo.h>
19 #include <Protocol/BlockIo2.h>
20 #include <Protocol/EraseBlock.h>
21 #include <Protocol/DriverBinding.h>
22 #include <Protocol/ScsiPassThruExt.h>
23 #include <Protocol/ScsiPassThru.h>
24 #include <Protocol/DiskInfo.h>
27 #include <Library/DebugLib.h>
28 #include <Library/UefiDriverEntryPoint.h>
29 #include <Library/UefiLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/MemoryAllocationLib.h>
32 #include <Library/UefiScsiLib.h>
33 #include <Library/UefiBootServicesTableLib.h>
34 #include <Library/DevicePathLib.h>
36 #include <IndustryStandard/Scsi.h>
37 #include <IndustryStandard/Atapi.h>
39 #define IS_DEVICE_FIXED(a) (a)->FixedDevice ? 1 : 0
44 UINT32 GranularityAlignment
;
45 } SCSI_UNMAP_PARAM_INFO
;
47 #define SCSI_DISK_DEV_SIGNATURE SIGNATURE_32 ('s', 'c', 'd', 'k')
54 EFI_BLOCK_IO_PROTOCOL BlkIo
;
55 EFI_BLOCK_IO2_PROTOCOL BlkIo2
;
56 EFI_BLOCK_IO_MEDIA BlkIoMedia
;
57 EFI_ERASE_BLOCK_PROTOCOL EraseBlock
;
58 EFI_SCSI_IO_PROTOCOL
*ScsiIo
;
63 EFI_SCSI_SENSE_DATA
*SenseData
;
64 UINTN SenseDataNumber
;
65 EFI_SCSI_INQUIRY_DATA InquiryData
;
67 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
69 EFI_DISK_INFO_PROTOCOL DiskInfo
;
72 // The following fields are only valid for ATAPI/SATA device
76 ATAPI_IDENTIFY_DATA IdentifyData
;
79 // Scsi UNMAP command parameters information
81 SCSI_UNMAP_PARAM_INFO UnmapInfo
;
82 BOOLEAN BlockLimitsVpdSupported
;
85 // The flag indicates if 16-byte command can be used
90 // The queue for asynchronous task requests
92 LIST_ENTRY AsyncTaskQueue
;
95 #define SCSI_DISK_DEV_FROM_BLKIO(a) CR (a, SCSI_DISK_DEV, BlkIo, SCSI_DISK_DEV_SIGNATURE)
96 #define SCSI_DISK_DEV_FROM_BLKIO2(a) CR (a, SCSI_DISK_DEV, BlkIo2, SCSI_DISK_DEV_SIGNATURE)
97 #define SCSI_DISK_DEV_FROM_ERASEBLK(a) CR (a, SCSI_DISK_DEV, EraseBlock, SCSI_DISK_DEV_SIGNATURE)
99 #define SCSI_DISK_DEV_FROM_DISKINFO(a) CR (a, SCSI_DISK_DEV, DiskInfo, SCSI_DISK_DEV_SIGNATURE)
102 // Asynchronous I/O request
105 // Private data structure for a BlockIo2 request
108 EFI_BLOCK_IO2_TOKEN
*Token
;
110 // The flag indicates if the last Scsi Read/Write sub-task for a BlockIo2
111 // request is sent to device
116 // The queue for Scsi Read/Write sub-tasks of a BlockIo2 request
118 LIST_ENTRY ScsiRWQueue
;
121 } SCSI_BLKIO2_REQUEST
;
124 // Private data structure for a SCSI Read/Write request
127 SCSI_DISK_DEV
*ScsiDiskDevice
;
129 EFI_SCSI_SENSE_DATA
*SenseData
;
130 UINT8 SenseDataLength
;
131 UINT8 HostAdapterStatus
;
141 // The BlockIo2 request this SCSI command belongs to
143 SCSI_BLKIO2_REQUEST
*BlkIo2Req
;
146 } SCSI_ASYNC_RW_REQUEST
;
149 // Private data structure for an EraseBlock request
152 EFI_ERASE_BLOCK_TOKEN
*Token
;
154 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
157 } SCSI_ERASEBLK_REQUEST
;
162 extern EFI_DRIVER_BINDING_PROTOCOL gScsiDiskDriverBinding
;
163 extern EFI_COMPONENT_NAME_PROTOCOL gScsiDiskComponentName
;
164 extern EFI_COMPONENT_NAME2_PROTOCOL gScsiDiskComponentName2
;
166 // action code used in detect media process
168 #define ACTION_NO_ACTION 0x00
169 #define ACTION_READ_CAPACITY 0x01
170 #define ACTION_RETRY_COMMAND_LATER 0x02
171 #define ACTION_RETRY_WITH_BACKOFF_ALGO 0x03
173 #define SCSI_COMMAND_VERSION_1 0x01
174 #define SCSI_COMMAND_VERSION_2 0x02
175 #define SCSI_COMMAND_VERSION_3 0x03
178 // SCSI Disk Timeout Experience Value
180 // As ScsiDisk and ScsiBus driver are used to manage SCSI or ATAPI devices, the timout
181 // value is updated to 30s to follow ATA/ATAPI spec in which the device may take up to 30s
182 // to respond command.
184 #define SCSI_DISK_TIMEOUT EFI_TIMER_PERIOD_SECONDS (30)
187 Test to see if this driver supports ControllerHandle.
189 This service is called by the EFI boot service ConnectController(). In order
190 to make drivers as small as possible, there are a few calling restrictions for
191 this service. ConnectController() must follow these calling restrictions.
192 If any other agent wishes to call Supported() it must also follow these
193 calling restrictions.
195 @param This Protocol instance pointer.
196 @param ControllerHandle Handle of device to test
197 @param RemainingDevicePath Optional parameter use to pick a specific child
200 @retval EFI_SUCCESS This driver supports this device
201 @retval EFI_ALREADY_STARTED This driver is already running on this device
202 @retval other This driver does not support this device
207 ScsiDiskDriverBindingSupported (
208 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
209 IN EFI_HANDLE Controller
,
210 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
214 Start this driver on ControllerHandle.
216 This service is called by the EFI boot service ConnectController(). In order
217 to make drivers as small as possible, there are a few calling restrictions for
218 this service. ConnectController() must follow these calling restrictions. If
219 any other agent wishes to call Start() it must also follow these calling
222 @param This Protocol instance pointer.
223 @param ControllerHandle Handle of device to bind driver to
224 @param RemainingDevicePath Optional parameter use to pick a specific child
227 @retval EFI_SUCCESS This driver is added to ControllerHandle
228 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
229 @retval other This driver does not support this device
234 ScsiDiskDriverBindingStart (
235 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
236 IN EFI_HANDLE Controller
,
237 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
241 Stop this driver on ControllerHandle.
243 This service is called by the EFI boot service DisconnectController().
244 In order to make drivers as small as possible, there are a few calling
245 restrictions for this service. DisconnectController() must follow these
246 calling restrictions. If any other agent wishes to call Stop() it must
247 also follow these calling restrictions.
249 @param This Protocol instance pointer.
250 @param ControllerHandle Handle of device to stop driver on
251 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
252 children is zero stop the entire bus driver.
253 @param ChildHandleBuffer List of Child Handles to Stop.
255 @retval EFI_SUCCESS This driver is removed ControllerHandle
256 @retval other This driver was not removed from this device
261 ScsiDiskDriverBindingStop (
262 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
263 IN EFI_HANDLE Controller
,
264 IN UINTN NumberOfChildren
,
265 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
269 // EFI Component Name Functions
272 Retrieves a Unicode string that is the user readable name of the driver.
274 This function retrieves the user readable name of a driver in the form of a
275 Unicode string. If the driver specified by This has a user readable name in
276 the language specified by Language, then a pointer to the driver name is
277 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
278 by This does not support the language specified by Language,
279 then EFI_UNSUPPORTED is returned.
281 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
282 EFI_COMPONENT_NAME_PROTOCOL instance.
284 @param Language A pointer to a Null-terminated ASCII string
285 array indicating the language. This is the
286 language of the driver name that the caller is
287 requesting, and it must match one of the
288 languages specified in SupportedLanguages. The
289 number of languages supported by a driver is up
290 to the driver writer. Language is specified
291 in RFC 4646 or ISO 639-2 language code format.
293 @param DriverName A pointer to the Unicode string to return.
294 This Unicode string is the name of the
295 driver specified by This in the language
296 specified by Language.
298 @retval EFI_SUCCESS The Unicode string for the Driver specified by
299 This and the language specified by Language was
300 returned in DriverName.
302 @retval EFI_INVALID_PARAMETER Language is NULL.
304 @retval EFI_INVALID_PARAMETER DriverName is NULL.
306 @retval EFI_UNSUPPORTED The driver specified by This does not support
307 the language specified by Language.
312 ScsiDiskComponentNameGetDriverName (
313 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
315 OUT CHAR16
**DriverName
320 Retrieves a Unicode string that is the user readable name of the controller
321 that is being managed by a driver.
323 This function retrieves the user readable name of the controller specified by
324 ControllerHandle and ChildHandle in the form of a Unicode string. If the
325 driver specified by This has a user readable name in the language specified by
326 Language, then a pointer to the controller name is returned in ControllerName,
327 and EFI_SUCCESS is returned. If the driver specified by This is not currently
328 managing the controller specified by ControllerHandle and ChildHandle,
329 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
330 support the language specified by Language, then EFI_UNSUPPORTED is returned.
332 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
333 EFI_COMPONENT_NAME_PROTOCOL instance.
335 @param ControllerHandle The handle of a controller that the driver
336 specified by This is managing. This handle
337 specifies the controller whose name is to be
340 @param ChildHandle The handle of the child controller to retrieve
341 the name of. This is an optional parameter that
342 may be NULL. It will be NULL for device
343 drivers. It will also be NULL for a bus drivers
344 that wish to retrieve the name of the bus
345 controller. It will not be NULL for a bus
346 driver that wishes to retrieve the name of a
349 @param Language A pointer to a Null-terminated ASCII string
350 array indicating the language. This is the
351 language of the driver name that the caller is
352 requesting, and it must match one of the
353 languages specified in SupportedLanguages. The
354 number of languages supported by a driver is up
355 to the driver writer. Language is specified in
356 RFC 4646 or ISO 639-2 language code format.
358 @param ControllerName A pointer to the Unicode string to return.
359 This Unicode string is the name of the
360 controller specified by ControllerHandle and
361 ChildHandle in the language specified by
362 Language from the point of view of the driver
365 @retval EFI_SUCCESS The Unicode string for the user readable name in
366 the language specified by Language for the
367 driver specified by This was returned in
370 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
372 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
375 @retval EFI_INVALID_PARAMETER Language is NULL.
377 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
379 @retval EFI_UNSUPPORTED The driver specified by This is not currently
380 managing the controller specified by
381 ControllerHandle and ChildHandle.
383 @retval EFI_UNSUPPORTED The driver specified by This does not support
384 the language specified by Language.
389 ScsiDiskComponentNameGetControllerName (
390 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
391 IN EFI_HANDLE ControllerHandle
,
392 IN EFI_HANDLE ChildHandle OPTIONAL
,
394 OUT CHAR16
**ControllerName
401 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
402 @param ExtendedVerification The flag about if extend verificate
404 @retval EFI_SUCCESS The device was reset.
405 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
407 @return EFI_STATUS is retured from EFI_SCSI_IO_PROTOCOL.ResetDevice().
413 IN EFI_BLOCK_IO_PROTOCOL
*This
,
414 IN BOOLEAN ExtendedVerification
419 The function is to Read Block from SCSI Disk.
421 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
422 @param MediaId The Id of Media detected
423 @param Lba The logic block address
424 @param BufferSize The size of Buffer
425 @param Buffer The buffer to fill the read out data
427 @retval EFI_SUCCESS Successfully to read out block.
428 @retval EFI_DEVICE_ERROR Fail to detect media.
429 @retval EFI_NO_MEDIA Media is not present.
430 @retval EFI_MEDIA_CHANGED Media has changed.
431 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
432 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
438 IN EFI_BLOCK_IO_PROTOCOL
*This
,
447 The function is to Write Block to SCSI Disk.
449 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
450 @param MediaId The Id of Media detected
451 @param Lba The logic block address
452 @param BufferSize The size of Buffer
453 @param Buffer The buffer to fill the read out data
455 @retval EFI_SUCCESS Successfully to read out block.
456 @retval EFI_WRITE_PROTECTED The device can not be written to.
457 @retval EFI_DEVICE_ERROR Fail to detect media.
458 @retval EFI_NO_MEDIA Media is not present.
459 @retval EFI_MEDIA_CHNAGED Media has changed.
460 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
461 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
466 ScsiDiskWriteBlocks (
467 IN EFI_BLOCK_IO_PROTOCOL
*This
,
478 EFI_SUCCESS is returned directly.
480 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
482 @retval EFI_SUCCESS All outstanding data was written to the device
487 ScsiDiskFlushBlocks (
488 IN EFI_BLOCK_IO_PROTOCOL
*This
495 @param This The pointer of EFI_BLOCK_IO2_PROTOCOL.
496 @param ExtendedVerification The flag about if extend verificate.
498 @retval EFI_SUCCESS The device was reset.
499 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
501 @return EFI_STATUS is returned from EFI_SCSI_IO_PROTOCOL.ResetDevice().
507 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
508 IN BOOLEAN ExtendedVerification
512 The function is to Read Block from SCSI Disk.
514 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
515 @param MediaId The Id of Media detected.
516 @param Lba The logic block address.
517 @param Token A pointer to the token associated with the transaction.
518 @param BufferSize The size of Buffer.
519 @param Buffer The buffer to fill the read out data.
521 @retval EFI_SUCCESS The read request was queued if Token-> Event is
522 not NULL. The data was read correctly from the
523 device if theToken-> Event is NULL.
524 @retval EFI_DEVICE_ERROR The device reported an error while attempting
525 to perform the read operation.
526 @retval EFI_NO_MEDIA There is no media in the device.
527 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
528 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
529 the intrinsic block size of the device.
530 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
531 valid, or the buffer is not on proper
533 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
539 ScsiDiskReadBlocksEx (
540 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
543 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
549 The function is to Write Block to SCSI Disk.
551 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
552 @param MediaId The Id of Media detected.
553 @param Lba The logic block address.
554 @param Token A pointer to the token associated with the transaction.
555 @param BufferSize The size of Buffer.
556 @param Buffer The buffer to fill the read out data.
558 @retval EFI_SUCCESS The data were written correctly to the device.
559 @retval EFI_WRITE_PROTECTED The device cannot be written to.
560 @retval EFI_NO_MEDIA There is no media in the device.
561 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
562 @retval EFI_DEVICE_ERROR The device reported an error while attempting
563 to perform the write operation.
564 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
565 the intrinsic block size of the device.
566 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
567 valid, or the buffer is not on proper
573 ScsiDiskWriteBlocksEx (
574 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
577 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
583 Flush the Block Device.
585 @param This Indicates a pointer to the calling context.
586 @param Token A pointer to the token associated with the transaction.
588 @retval EFI_SUCCESS All outstanding data was written to the device.
589 @retval EFI_DEVICE_ERROR The device reported an error while attempting to
591 @retval EFI_WRITE_PROTECTED The device cannot be written to.
592 @retval EFI_NO_MEDIA There is no media in the device.
593 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
598 ScsiDiskFlushBlocksEx (
599 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
600 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
604 Erase a specified number of device blocks.
606 @param[in] This Indicates a pointer to the calling context.
607 @param[in] MediaId The media ID that the erase request is for.
608 @param[in] Lba The starting logical block address to be
609 erased. The caller is responsible for erasing
610 only legitimate locations.
611 @param[in, out] Token A pointer to the token associated with the
613 @param[in] Size The size in bytes to be erased. This must be
614 a multiple of the physical block size of the
617 @retval EFI_SUCCESS The erase request was queued if Event is not
618 NULL. The data was erased correctly to the
619 device if the Event is NULL.to the device.
620 @retval EFI_WRITE_PROTECTED The device cannot be erased due to write
622 @retval EFI_DEVICE_ERROR The device reported an error while attempting
623 to perform the erase operation.
624 @retval EFI_INVALID_PARAMETER The erase request contains LBAs that are not
626 @retval EFI_NO_MEDIA There is no media in the device.
627 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
632 ScsiDiskEraseBlocks (
633 IN EFI_ERASE_BLOCK_PROTOCOL
*This
,
636 IN OUT EFI_ERASE_BLOCK_TOKEN
*Token
,
642 Provides inquiry information for the controller type.
644 This function is used by the IDE bus driver to get inquiry data. Data format
645 of Identify data is defined by the Interface GUID.
647 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
648 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
649 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
651 @retval EFI_SUCCESS The command was accepted without any errors.
652 @retval EFI_NOT_FOUND Device does not support this data class
653 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
654 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
659 ScsiDiskInfoInquiry (
660 IN EFI_DISK_INFO_PROTOCOL
*This
,
661 IN OUT VOID
*InquiryData
,
662 IN OUT UINT32
*InquiryDataSize
667 Provides identify information for the controller type.
669 This function is used by the IDE bus driver to get identify data. Data format
670 of Identify data is defined by the Interface GUID.
672 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
674 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
675 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
678 @retval EFI_SUCCESS The command was accepted without any errors.
679 @retval EFI_NOT_FOUND Device does not support this data class
680 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
681 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
686 ScsiDiskInfoIdentify (
687 IN EFI_DISK_INFO_PROTOCOL
*This
,
688 IN OUT VOID
*IdentifyData
,
689 IN OUT UINT32
*IdentifyDataSize
694 Provides sense data information for the controller type.
696 This function is used by the IDE bus driver to get sense data.
697 Data format of Sense data is defined by the Interface GUID.
699 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
700 @param[in, out] SenseData Pointer to the SenseData.
701 @param[in, out] SenseDataSize Size of SenseData in bytes.
702 @param[out] SenseDataNumber Pointer to the value for the sense data size.
704 @retval EFI_SUCCESS The command was accepted without any errors.
705 @retval EFI_NOT_FOUND Device does not support this data class.
706 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
707 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
712 ScsiDiskInfoSenseData (
713 IN EFI_DISK_INFO_PROTOCOL
*This
,
714 IN OUT VOID
*SenseData
,
715 IN OUT UINT32
*SenseDataSize
,
716 OUT UINT8
*SenseDataNumber
720 This function is used by the IDE bus driver to get controller information.
722 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
723 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
724 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
726 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
727 @retval EFI_UNSUPPORTED This is not an IDE device.
732 ScsiDiskInfoWhichIde (
733 IN EFI_DISK_INFO_PROTOCOL
*This
,
734 OUT UINT32
*IdeChannel
,
735 OUT UINT32
*IdeDevice
740 Detect Device and read out capacity ,if error occurs, parse the sense key.
742 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
743 @param MustReadCapacity The flag about reading device capacity
744 @param MediaChange The pointer of flag indicates if media has changed
746 @retval EFI_DEVICE_ERROR Indicates that error occurs
747 @retval EFI_SUCCESS Successfully to detect media
751 ScsiDiskDetectMedia (
752 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
753 IN BOOLEAN MustReadCapacity
,
754 OUT BOOLEAN
*MediaChange
760 When Test Unit Ready command succeeds, retrieve Sense Keys via Request Sense;
761 When Test Unit Ready command encounters any error caused by host adapter or
762 target, return error without retrieving Sense Keys.
764 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
765 @param NeedRetry The pointer of flag indicates try again
766 @param SenseDataArray The pointer of an array of sense data
767 @param NumberOfSenseKeys The pointer of the number of sense data array
769 @retval EFI_DEVICE_ERROR Indicates that error occurs
770 @retval EFI_SUCCESS Successfully to test unit
774 ScsiDiskTestUnitReady (
775 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
776 OUT BOOLEAN
*NeedRetry
,
777 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
778 OUT UINTN
*NumberOfSenseKeys
783 Parsing Sense Keys which got from request sense command.
785 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
786 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
787 @param NumberOfSenseKeys The number of sense key
788 @param Action The pointer of action which indicates what is need to do next
790 @retval EFI_DEVICE_ERROR Indicates that error occurs
791 @retval EFI_SUCCESS Successfully to complete the parsing
795 DetectMediaParsingSenseKeys (
796 OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
797 IN EFI_SCSI_SENSE_DATA
*SenseData
,
798 IN UINTN NumberOfSenseKeys
,
804 Send read capacity command to device and get the device parameter.
806 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
807 @param NeedRetry The pointer of flag indicates if need a retry
808 @param SenseDataArray The pointer of an array of sense data
809 @param NumberOfSenseKeys The number of sense key
811 @retval EFI_DEVICE_ERROR Indicates that error occurs
812 @retval EFI_SUCCESS Successfully to read capacity
816 ScsiDiskReadCapacity (
817 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
818 OUT BOOLEAN
*NeedRetry
,
819 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
820 OUT UINTN
*NumberOfSenseKeys
824 Check the HostAdapter status and re-interpret it in EFI_STATUS.
826 @param HostAdapterStatus Host Adapter status
828 @retval EFI_SUCCESS Host adapter is OK.
829 @retval EFI_TIMEOUT Timeout.
830 @retval EFI_NOT_READY Adapter NOT ready.
831 @retval EFI_DEVICE_ERROR Adapter device error.
835 CheckHostAdapterStatus (
836 IN UINT8 HostAdapterStatus
841 Check the target status and re-interpret it in EFI_STATUS.
843 @param TargetStatus Target status
845 @retval EFI_NOT_READY Device is NOT ready.
846 @retval EFI_DEVICE_ERROR
852 IN UINT8 TargetStatus
856 Retrieve all sense keys from the device.
858 When encountering error during the process, if retrieve sense keys before
859 error encountered, it returns the sense keys with return status set to EFI_SUCCESS,
860 and NeedRetry set to FALSE; otherwize, return the proper return status.
862 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
863 @param NeedRetry The pointer of flag indicates if need a retry
864 @param SenseDataArray The pointer of an array of sense data
865 @param NumberOfSenseKeys The number of sense key
866 @param AskResetIfError The flag indicates if need reset when error occurs
868 @retval EFI_DEVICE_ERROR Indicates that error occurs
869 @retval EFI_SUCCESS Successfully to request sense key
873 ScsiDiskRequestSenseKeys (
874 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
875 OUT BOOLEAN
*NeedRetry
,
876 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
877 OUT UINTN
*NumberOfSenseKeys
,
878 IN BOOLEAN AskResetIfError
882 Send out Inquiry command to Device.
884 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
885 @param NeedRetry Indicates if needs try again when error happens
887 @retval EFI_DEVICE_ERROR Indicates that error occurs
888 @retval EFI_SUCCESS Successfully to detect media
892 ScsiDiskInquiryDevice (
893 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
894 OUT BOOLEAN
*NeedRetry
900 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
905 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
909 Read sector from SCSI Disk.
911 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
912 @param Buffer The buffer to fill in the read out data
913 @param Lba Logic block address
914 @param NumberOfBlocks The number of blocks to read
916 @retval EFI_DEVICE_ERROR Indicates a device error.
917 @retval EFI_SUCCESS Operation is successful.
921 ScsiDiskReadSectors (
922 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
925 IN UINTN NumberOfBlocks
929 Write sector to SCSI Disk.
931 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
932 @param Buffer The buffer of data to be written into SCSI Disk
933 @param Lba Logic block address
934 @param NumberOfBlocks The number of blocks to read
936 @retval EFI_DEVICE_ERROR Indicates a device error.
937 @retval EFI_SUCCESS Operation is successful.
941 ScsiDiskWriteSectors (
942 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
945 IN UINTN NumberOfBlocks
949 Asynchronously read sector from SCSI Disk.
951 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
952 @param Buffer The buffer to fill in the read out data.
953 @param Lba Logic block address.
954 @param NumberOfBlocks The number of blocks to read.
955 @param Token A pointer to the token associated with the
956 non-blocking read request.
958 @retval EFI_INVALID_PARAMETER Token is NULL or Token->Event is NULL.
959 @retval EFI_DEVICE_ERROR Indicates a device error.
960 @retval EFI_SUCCESS Operation is successful.
964 ScsiDiskAsyncReadSectors (
965 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
968 IN UINTN NumberOfBlocks
,
969 IN EFI_BLOCK_IO2_TOKEN
*Token
973 Asynchronously write sector to SCSI Disk.
975 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
976 @param Buffer The buffer of data to be written into SCSI Disk.
977 @param Lba Logic block address.
978 @param NumberOfBlocks The number of blocks to read.
979 @param Token A pointer to the token associated with the
980 non-blocking read request.
982 @retval EFI_INVALID_PARAMETER Token is NULL or Token->Event is NULL
983 @retval EFI_DEVICE_ERROR Indicates a device error.
984 @retval EFI_SUCCESS Operation is successful.
988 ScsiDiskAsyncWriteSectors (
989 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
992 IN UINTN NumberOfBlocks
,
993 IN EFI_BLOCK_IO2_TOKEN
*Token
997 Submit Read(10) command.
999 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1000 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1001 @param Timeout The time to complete the command
1002 @param DataBuffer The buffer to fill with the read out data
1003 @param DataLength The length of buffer
1004 @param StartLba The start logic block address
1005 @param SectorCount The number of blocks to read
1007 @return EFI_STATUS is returned by calling ScsiRead10Command().
1011 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1012 OUT BOOLEAN
*NeedRetry
,
1014 OUT UINT8
*DataBuffer
,
1015 IN OUT UINT32
*DataLength
,
1017 IN UINT32 SectorCount
1021 Submit Write(10) Command.
1023 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1024 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1025 @param Timeout The time to complete the command
1026 @param DataBuffer The buffer to fill with the read out data
1027 @param DataLength The length of buffer
1028 @param StartLba The start logic block address
1029 @param SectorCount The number of blocks to write
1031 @return EFI_STATUS is returned by calling ScsiWrite10Command().
1036 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1037 OUT BOOLEAN
*NeedRetry
,
1039 IN UINT8
*DataBuffer
,
1040 IN OUT UINT32
*DataLength
,
1042 IN UINT32 SectorCount
1046 Submit Read(16) command.
1048 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1049 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1050 @param Timeout The time to complete the command
1051 @param DataBuffer The buffer to fill with the read out data
1052 @param DataLength The length of buffer
1053 @param StartLba The start logic block address
1054 @param SectorCount The number of blocks to read
1056 @return EFI_STATUS is returned by calling ScsiRead16Command().
1060 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1061 OUT BOOLEAN
*NeedRetry
,
1063 OUT UINT8
*DataBuffer
,
1064 IN OUT UINT32
*DataLength
,
1066 IN UINT32 SectorCount
1070 Submit Write(16) Command.
1072 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1073 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1074 @param Timeout The time to complete the command
1075 @param DataBuffer The buffer to fill with the read out data
1076 @param DataLength The length of buffer
1077 @param StartLba The start logic block address
1078 @param SectorCount The number of blocks to write
1080 @return EFI_STATUS is returned by calling ScsiWrite16Command().
1085 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1086 OUT BOOLEAN
*NeedRetry
,
1088 IN UINT8
*DataBuffer
,
1089 IN OUT UINT32
*DataLength
,
1091 IN UINT32 SectorCount
1095 Submit Async Read(10) command.
1097 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1098 @param Timeout The time to complete the command.
1099 @param TimesRetry The number of times the command has been retried.
1100 @param DataBuffer The buffer to fill with the read out data.
1101 @param DataLength The length of buffer.
1102 @param StartLba The start logic block address.
1103 @param SectorCount The number of blocks to read.
1104 @param BlkIo2Req The upstream BlockIo2 request.
1105 @param Token The pointer to the token associated with the
1106 non-blocking read request.
1108 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1110 @return others Status returned by calling
1111 ScsiRead10CommandEx().
1115 ScsiDiskAsyncRead10 (
1116 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1118 IN UINT8 TimesRetry
,
1119 OUT UINT8
*DataBuffer
,
1120 IN UINT32 DataLength
,
1122 IN UINT32 SectorCount
,
1123 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1124 IN EFI_BLOCK_IO2_TOKEN
*Token
1128 Submit Async Write(10) command.
1130 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1131 @param Timeout The time to complete the command.
1132 @param TimesRetry The number of times the command has been retried.
1133 @param DataBuffer The buffer contains the data to write.
1134 @param DataLength The length of buffer.
1135 @param StartLba The start logic block address.
1136 @param SectorCount The number of blocks to write.
1137 @param BlkIo2Req The upstream BlockIo2 request.
1138 @param Token The pointer to the token associated with the
1139 non-blocking read request.
1141 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1143 @return others Status returned by calling
1144 ScsiWrite10CommandEx().
1148 ScsiDiskAsyncWrite10 (
1149 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1151 IN UINT8 TimesRetry
,
1152 IN UINT8
*DataBuffer
,
1153 IN UINT32 DataLength
,
1155 IN UINT32 SectorCount
,
1156 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1157 IN EFI_BLOCK_IO2_TOKEN
*Token
1161 Submit Async Read(16) command.
1163 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1164 @param Timeout The time to complete the command.
1165 @param TimesRetry The number of times the command has been retried.
1166 @param DataBuffer The buffer to fill with the read out data.
1167 @param DataLength The length of buffer.
1168 @param StartLba The start logic block address.
1169 @param SectorCount The number of blocks to read.
1170 @param BlkIo2Req The upstream BlockIo2 request.
1171 @param Token The pointer to the token associated with the
1172 non-blocking read request.
1174 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1176 @return others Status returned by calling
1177 ScsiRead16CommandEx().
1181 ScsiDiskAsyncRead16 (
1182 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1184 IN UINT8 TimesRetry
,
1185 OUT UINT8
*DataBuffer
,
1186 IN UINT32 DataLength
,
1188 IN UINT32 SectorCount
,
1189 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1190 IN EFI_BLOCK_IO2_TOKEN
*Token
1194 Submit Async Write(16) command.
1196 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1197 @param Timeout The time to complete the command.
1198 @param TimesRetry The number of times the command has been retried.
1199 @param DataBuffer The buffer contains the data to write.
1200 @param DataLength The length of buffer.
1201 @param StartLba The start logic block address.
1202 @param SectorCount The number of blocks to write.
1203 @param BlkIo2Req The upstream BlockIo2 request.
1204 @param Token The pointer to the token associated with the
1205 non-blocking read request.
1207 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1209 @return others Status returned by calling
1210 ScsiWrite16CommandEx().
1214 ScsiDiskAsyncWrite16 (
1215 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1217 IN UINT8 TimesRetry
,
1218 IN UINT8
*DataBuffer
,
1219 IN UINT32 DataLength
,
1221 IN UINT32 SectorCount
,
1222 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1223 IN EFI_BLOCK_IO2_TOKEN
*Token
1227 Get information from media read capacity command.
1229 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1230 @param Capacity10 The pointer of EFI_SCSI_DISK_CAPACITY_DATA
1231 @param Capacity16 The pointer of EFI_SCSI_DISK_CAPACITY_DATA16
1235 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
1236 IN EFI_SCSI_DISK_CAPACITY_DATA
*Capacity10
,
1237 IN EFI_SCSI_DISK_CAPACITY_DATA16
*Capacity16
1241 Check sense key to find if media presents.
1243 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1244 @param SenseCounts The number of sense key
1246 @retval TRUE NOT any media
1247 @retval FALSE Media presents
1251 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1252 IN UINTN SenseCounts
1258 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1259 @param SenseCounts The number of sense key
1262 @retval FALSE NOT error
1266 ScsiDiskIsMediaError (
1267 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1268 IN UINTN SenseCounts
1272 Check sense key to find if hardware error happens.
1274 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1275 @param SenseCounts The number of sense key
1277 @retval TRUE Hardware error exits.
1278 @retval FALSE NO error.
1282 ScsiDiskIsHardwareError (
1283 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1284 IN UINTN SenseCounts
1288 Check sense key to find if media has changed.
1290 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1291 @param SenseCounts The number of sense key
1293 @retval TRUE Media is changed.
1294 @retval FALSE Medit is NOT changed.
1297 ScsiDiskIsMediaChange (
1298 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1299 IN UINTN SenseCounts
1303 Check sense key to find if reset happens.
1305 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1306 @param SenseCounts The number of sense key
1308 @retval TRUE It is reset before.
1309 @retval FALSE It is NOT reset before.
1313 ScsiDiskIsResetBefore (
1314 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1315 IN UINTN SenseCounts
1319 Check sense key to find if the drive is ready.
1321 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1322 @param SenseCounts The number of sense key
1323 @param RetryLater The flag means if need a retry
1325 @retval TRUE Drive is ready.
1326 @retval FALSE Drive is NOT ready.
1330 ScsiDiskIsDriveReady (
1331 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1332 IN UINTN SenseCounts
,
1333 OUT BOOLEAN
*RetryLater
1337 Check sense key to find if it has sense key.
1339 @param SenseData - The pointer of EFI_SCSI_SENSE_DATA
1340 @param SenseCounts - The number of sense key
1342 @retval TRUE It has sense key.
1343 @retval FALSE It has NOT any sense key.
1347 ScsiDiskHaveSenseKey (
1348 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1349 IN UINTN SenseCounts
1353 Release resource about disk device.
1355 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1359 ReleaseScsiDiskDeviceResources (
1360 IN SCSI_DISK_DEV
*ScsiDiskDevice
1364 Determine if Block Io should be produced.
1367 @param ChildHandle Child Handle to retrieve Parent information.
1369 @retval TRUE Should produce Block Io.
1370 @retval FALSE Should not produce Block Io.
1374 DetermineInstallBlockIo (
1375 IN EFI_HANDLE ChildHandle
1379 Initialize the installation of DiskInfo protocol.
1381 This function prepares for the installation of DiskInfo protocol on the child handle.
1382 By default, it installs DiskInfo protocol with SCSI interface GUID. If it further
1383 detects that the physical device is an ATAPI/AHCI device, it then updates interface GUID
1384 to be IDE/AHCI interface GUID.
1386 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1387 @param ChildHandle Child handle to install DiskInfo protocol.
1391 InitializeInstallDiskInfo (
1392 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1393 IN EFI_HANDLE ChildHandle
1397 Search protocol database and check to see if the protocol
1398 specified by ProtocolGuid is present on a ControllerHandle and opened by
1399 ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1400 If the ControllerHandle is found, then the protocol specified by ProtocolGuid
1401 will be opened on it.
1404 @param ProtocolGuid ProtocolGuid pointer.
1405 @param ChildHandle Child Handle to retrieve Parent information.
1411 IN EFI_GUID
*ProtocolGuid
,
1412 IN EFI_HANDLE ChildHandle
1416 Determine if EFI Erase Block Protocol should be produced.
1418 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1419 @param ChildHandle Handle of device.
1421 @retval TRUE Should produce EFI Erase Block Protocol.
1422 @retval FALSE Should not produce EFI Erase Block Protocol.
1426 DetermineInstallEraseBlock (
1427 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1428 IN EFI_HANDLE ChildHandle