2 Header file for SCSI Disk Driver.
4 Copyright (c) 2004 - 2018, 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/EraseBlock.h>
27 #include <Protocol/DriverBinding.h>
28 #include <Protocol/ScsiPassThruExt.h>
29 #include <Protocol/ScsiPassThru.h>
30 #include <Protocol/DiskInfo.h>
33 #include <Library/DebugLib.h>
34 #include <Library/UefiDriverEntryPoint.h>
35 #include <Library/UefiLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/MemoryAllocationLib.h>
38 #include <Library/UefiScsiLib.h>
39 #include <Library/UefiBootServicesTableLib.h>
40 #include <Library/DevicePathLib.h>
42 #include <IndustryStandard/Scsi.h>
43 #include <IndustryStandard/Atapi.h>
45 #define IS_DEVICE_FIXED(a) (a)->FixedDevice ? 1 : 0
50 UINT32 GranularityAlignment
;
51 } SCSI_UNMAP_PARAM_INFO
;
53 #define SCSI_DISK_DEV_SIGNATURE SIGNATURE_32 ('s', 'c', 'd', 'k')
60 EFI_BLOCK_IO_PROTOCOL BlkIo
;
61 EFI_BLOCK_IO2_PROTOCOL BlkIo2
;
62 EFI_BLOCK_IO_MEDIA BlkIoMedia
;
63 EFI_ERASE_BLOCK_PROTOCOL EraseBlock
;
64 EFI_SCSI_IO_PROTOCOL
*ScsiIo
;
69 EFI_SCSI_SENSE_DATA
*SenseData
;
70 UINTN SenseDataNumber
;
71 EFI_SCSI_INQUIRY_DATA InquiryData
;
73 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
75 EFI_DISK_INFO_PROTOCOL DiskInfo
;
78 // The following fields are only valid for ATAPI/SATA device
82 ATAPI_IDENTIFY_DATA IdentifyData
;
85 // Scsi UNMAP command parameters information
87 SCSI_UNMAP_PARAM_INFO UnmapInfo
;
88 BOOLEAN BlockLimitsVpdSupported
;
91 // The flag indicates if 16-byte command can be used
96 // The queue for asynchronous task requests
98 LIST_ENTRY AsyncTaskQueue
;
101 #define SCSI_DISK_DEV_FROM_BLKIO(a) CR (a, SCSI_DISK_DEV, BlkIo, SCSI_DISK_DEV_SIGNATURE)
102 #define SCSI_DISK_DEV_FROM_BLKIO2(a) CR (a, SCSI_DISK_DEV, BlkIo2, SCSI_DISK_DEV_SIGNATURE)
103 #define SCSI_DISK_DEV_FROM_ERASEBLK(a) CR (a, SCSI_DISK_DEV, EraseBlock, SCSI_DISK_DEV_SIGNATURE)
105 #define SCSI_DISK_DEV_FROM_DISKINFO(a) CR (a, SCSI_DISK_DEV, DiskInfo, SCSI_DISK_DEV_SIGNATURE)
108 // Asynchronous I/O request
111 // Private data structure for a BlockIo2 request
114 EFI_BLOCK_IO2_TOKEN
*Token
;
116 // The flag indicates if the last Scsi Read/Write sub-task for a BlockIo2
117 // request is sent to device
122 // The queue for Scsi Read/Write sub-tasks of a BlockIo2 request
124 LIST_ENTRY ScsiRWQueue
;
127 } SCSI_BLKIO2_REQUEST
;
130 // Private data structure for a SCSI Read/Write request
133 SCSI_DISK_DEV
*ScsiDiskDevice
;
135 EFI_SCSI_SENSE_DATA
*SenseData
;
136 UINT8 SenseDataLength
;
137 UINT8 HostAdapterStatus
;
147 // The BlockIo2 request this SCSI command belongs to
149 SCSI_BLKIO2_REQUEST
*BlkIo2Req
;
152 } SCSI_ASYNC_RW_REQUEST
;
155 // Private data structure for an EraseBlock request
158 EFI_ERASE_BLOCK_TOKEN
*Token
;
160 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket
;
163 } SCSI_ERASEBLK_REQUEST
;
168 extern EFI_DRIVER_BINDING_PROTOCOL gScsiDiskDriverBinding
;
169 extern EFI_COMPONENT_NAME_PROTOCOL gScsiDiskComponentName
;
170 extern EFI_COMPONENT_NAME2_PROTOCOL gScsiDiskComponentName2
;
172 // action code used in detect media process
174 #define ACTION_NO_ACTION 0x00
175 #define ACTION_READ_CAPACITY 0x01
176 #define ACTION_RETRY_COMMAND_LATER 0x02
177 #define ACTION_RETRY_WITH_BACKOFF_ALGO 0x03
179 #define SCSI_COMMAND_VERSION_1 0x01
180 #define SCSI_COMMAND_VERSION_2 0x02
181 #define SCSI_COMMAND_VERSION_3 0x03
184 // SCSI Disk Timeout Experience Value
186 // As ScsiDisk and ScsiBus driver are used to manage SCSI or ATAPI devices, the timout
187 // value is updated to 30s to follow ATA/ATAPI spec in which the device may take up to 30s
188 // to respond command.
190 #define SCSI_DISK_TIMEOUT EFI_TIMER_PERIOD_SECONDS (30)
193 Test to see if this driver supports ControllerHandle.
195 This service is called by the EFI boot service ConnectController(). In order
196 to make drivers as small as possible, there are a few calling restrictions for
197 this service. ConnectController() must follow these calling restrictions.
198 If any other agent wishes to call Supported() it must also follow these
199 calling restrictions.
201 @param This Protocol instance pointer.
202 @param ControllerHandle Handle of device to test
203 @param RemainingDevicePath Optional parameter use to pick a specific child
206 @retval EFI_SUCCESS This driver supports this device
207 @retval EFI_ALREADY_STARTED This driver is already running on this device
208 @retval other This driver does not support this device
213 ScsiDiskDriverBindingSupported (
214 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
215 IN EFI_HANDLE Controller
,
216 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
220 Start this driver on ControllerHandle.
222 This service is called by the EFI boot service ConnectController(). In order
223 to make drivers as small as possible, there are a few calling restrictions for
224 this service. ConnectController() must follow these calling restrictions. If
225 any other agent wishes to call Start() it must also follow these calling
228 @param This Protocol instance pointer.
229 @param ControllerHandle Handle of device to bind driver to
230 @param RemainingDevicePath Optional parameter use to pick a specific child
233 @retval EFI_SUCCESS This driver is added to ControllerHandle
234 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
235 @retval other This driver does not support this device
240 ScsiDiskDriverBindingStart (
241 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
242 IN EFI_HANDLE Controller
,
243 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
247 Stop this driver on ControllerHandle.
249 This service is called by the EFI boot service DisconnectController().
250 In order to make drivers as small as possible, there are a few calling
251 restrictions for this service. DisconnectController() must follow these
252 calling restrictions. If any other agent wishes to call Stop() it must
253 also follow these calling restrictions.
255 @param This Protocol instance pointer.
256 @param ControllerHandle Handle of device to stop driver on
257 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
258 children is zero stop the entire bus driver.
259 @param ChildHandleBuffer List of Child Handles to Stop.
261 @retval EFI_SUCCESS This driver is removed ControllerHandle
262 @retval other This driver was not removed from this device
267 ScsiDiskDriverBindingStop (
268 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
269 IN EFI_HANDLE Controller
,
270 IN UINTN NumberOfChildren
,
271 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
275 // EFI Component Name Functions
278 Retrieves a Unicode string that is the user readable name of the driver.
280 This function retrieves the user readable name of a driver in the form of a
281 Unicode string. If the driver specified by This has a user readable name in
282 the language specified by Language, then a pointer to the driver name is
283 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
284 by This does not support the language specified by Language,
285 then EFI_UNSUPPORTED is returned.
287 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
288 EFI_COMPONENT_NAME_PROTOCOL instance.
290 @param Language A pointer to a Null-terminated ASCII string
291 array indicating the language. This is the
292 language of the driver name that the caller is
293 requesting, and it must match one of the
294 languages specified in SupportedLanguages. The
295 number of languages supported by a driver is up
296 to the driver writer. Language is specified
297 in RFC 4646 or ISO 639-2 language code format.
299 @param DriverName A pointer to the Unicode string to return.
300 This Unicode string is the name of the
301 driver specified by This in the language
302 specified by Language.
304 @retval EFI_SUCCESS The Unicode string for the Driver specified by
305 This and the language specified by Language was
306 returned in DriverName.
308 @retval EFI_INVALID_PARAMETER Language is NULL.
310 @retval EFI_INVALID_PARAMETER DriverName is NULL.
312 @retval EFI_UNSUPPORTED The driver specified by This does not support
313 the language specified by Language.
318 ScsiDiskComponentNameGetDriverName (
319 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
321 OUT CHAR16
**DriverName
326 Retrieves a Unicode string that is the user readable name of the controller
327 that is being managed by a driver.
329 This function retrieves the user readable name of the controller specified by
330 ControllerHandle and ChildHandle in the form of a Unicode string. If the
331 driver specified by This has a user readable name in the language specified by
332 Language, then a pointer to the controller name is returned in ControllerName,
333 and EFI_SUCCESS is returned. If the driver specified by This is not currently
334 managing the controller specified by ControllerHandle and ChildHandle,
335 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
336 support the language specified by Language, then EFI_UNSUPPORTED is returned.
338 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
339 EFI_COMPONENT_NAME_PROTOCOL instance.
341 @param ControllerHandle The handle of a controller that the driver
342 specified by This is managing. This handle
343 specifies the controller whose name is to be
346 @param ChildHandle The handle of the child controller to retrieve
347 the name of. This is an optional parameter that
348 may be NULL. It will be NULL for device
349 drivers. It will also be NULL for a bus drivers
350 that wish to retrieve the name of the bus
351 controller. It will not be NULL for a bus
352 driver that wishes to retrieve the name of a
355 @param Language A pointer to a Null-terminated ASCII string
356 array indicating the language. This is the
357 language of the driver name that the caller is
358 requesting, and it must match one of the
359 languages specified in SupportedLanguages. The
360 number of languages supported by a driver is up
361 to the driver writer. Language is specified in
362 RFC 4646 or ISO 639-2 language code format.
364 @param ControllerName A pointer to the Unicode string to return.
365 This Unicode string is the name of the
366 controller specified by ControllerHandle and
367 ChildHandle in the language specified by
368 Language from the point of view of the driver
371 @retval EFI_SUCCESS The Unicode string for the user readable name in
372 the language specified by Language for the
373 driver specified by This was returned in
376 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
378 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
381 @retval EFI_INVALID_PARAMETER Language is NULL.
383 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
385 @retval EFI_UNSUPPORTED The driver specified by This is not currently
386 managing the controller specified by
387 ControllerHandle and ChildHandle.
389 @retval EFI_UNSUPPORTED The driver specified by This does not support
390 the language specified by Language.
395 ScsiDiskComponentNameGetControllerName (
396 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
397 IN EFI_HANDLE ControllerHandle
,
398 IN EFI_HANDLE ChildHandle OPTIONAL
,
400 OUT CHAR16
**ControllerName
407 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
408 @param ExtendedVerification The flag about if extend verificate
410 @retval EFI_SUCCESS The device was reset.
411 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
413 @return EFI_STATUS is retured from EFI_SCSI_IO_PROTOCOL.ResetDevice().
419 IN EFI_BLOCK_IO_PROTOCOL
*This
,
420 IN BOOLEAN ExtendedVerification
425 The function is to Read Block from SCSI Disk.
427 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
428 @param MediaId The Id of Media detected
429 @param Lba The logic block address
430 @param BufferSize The size of Buffer
431 @param Buffer The buffer to fill the read out data
433 @retval EFI_SUCCESS Successfully to read out block.
434 @retval EFI_DEVICE_ERROR Fail to detect media.
435 @retval EFI_NO_MEDIA Media is not present.
436 @retval EFI_MEDIA_CHANGED Media has changed.
437 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
438 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
444 IN EFI_BLOCK_IO_PROTOCOL
*This
,
453 The function is to Write Block to SCSI Disk.
455 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
456 @param MediaId The Id of Media detected
457 @param Lba The logic block address
458 @param BufferSize The size of Buffer
459 @param Buffer The buffer to fill the read out data
461 @retval EFI_SUCCESS Successfully to read out block.
462 @retval EFI_WRITE_PROTECTED The device can not be written to.
463 @retval EFI_DEVICE_ERROR Fail to detect media.
464 @retval EFI_NO_MEDIA Media is not present.
465 @retval EFI_MEDIA_CHNAGED Media has changed.
466 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
467 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
472 ScsiDiskWriteBlocks (
473 IN EFI_BLOCK_IO_PROTOCOL
*This
,
484 EFI_SUCCESS is returned directly.
486 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
488 @retval EFI_SUCCESS All outstanding data was written to the device
493 ScsiDiskFlushBlocks (
494 IN EFI_BLOCK_IO_PROTOCOL
*This
501 @param This The pointer of EFI_BLOCK_IO2_PROTOCOL.
502 @param ExtendedVerification The flag about if extend verificate.
504 @retval EFI_SUCCESS The device was reset.
505 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
507 @return EFI_STATUS is returned from EFI_SCSI_IO_PROTOCOL.ResetDevice().
513 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
514 IN BOOLEAN ExtendedVerification
518 The function is to Read Block from SCSI Disk.
520 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
521 @param MediaId The Id of Media detected.
522 @param Lba The logic block address.
523 @param Token A pointer to the token associated with the transaction.
524 @param BufferSize The size of Buffer.
525 @param Buffer The buffer to fill the read out data.
527 @retval EFI_SUCCESS The read request was queued if Token-> Event is
528 not NULL. The data was read correctly from the
529 device if theToken-> Event is NULL.
530 @retval EFI_DEVICE_ERROR The device reported an error while attempting
531 to perform the read operation.
532 @retval EFI_NO_MEDIA There is no media in the device.
533 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
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 read request contains LBAs that are not
537 valid, or the buffer is not on proper
539 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
545 ScsiDiskReadBlocksEx (
546 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
549 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
555 The function is to Write Block to SCSI Disk.
557 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
558 @param MediaId The Id of Media detected.
559 @param Lba The logic block address.
560 @param Token A pointer to the token associated with the transaction.
561 @param BufferSize The size of Buffer.
562 @param Buffer The buffer to fill the read out data.
564 @retval EFI_SUCCESS The data were written correctly to the device.
565 @retval EFI_WRITE_PROTECTED The device cannot be written to.
566 @retval EFI_NO_MEDIA There is no media in the device.
567 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
568 @retval EFI_DEVICE_ERROR The device reported an error while attempting
569 to perform the write operation.
570 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
571 the intrinsic block size of the device.
572 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
573 valid, or the buffer is not on proper
579 ScsiDiskWriteBlocksEx (
580 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
583 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
,
589 Flush the Block Device.
591 @param This Indicates a pointer to the calling context.
592 @param Token A pointer to the token associated with the transaction.
594 @retval EFI_SUCCESS All outstanding data was written to the device.
595 @retval EFI_DEVICE_ERROR The device reported an error while attempting to
597 @retval EFI_WRITE_PROTECTED The device cannot be written to.
598 @retval EFI_NO_MEDIA There is no media in the device.
599 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
604 ScsiDiskFlushBlocksEx (
605 IN EFI_BLOCK_IO2_PROTOCOL
*This
,
606 IN OUT EFI_BLOCK_IO2_TOKEN
*Token
610 Erase a specified number of device blocks.
612 @param[in] This Indicates a pointer to the calling context.
613 @param[in] MediaId The media ID that the erase request is for.
614 @param[in] Lba The starting logical block address to be
615 erased. The caller is responsible for erasing
616 only legitimate locations.
617 @param[in, out] Token A pointer to the token associated with the
619 @param[in] Size The size in bytes to be erased. This must be
620 a multiple of the physical block size of the
623 @retval EFI_SUCCESS The erase request was queued if Event is not
624 NULL. The data was erased correctly to the
625 device if the Event is NULL.to the device.
626 @retval EFI_WRITE_PROTECTED The device cannot be erased due to write
628 @retval EFI_DEVICE_ERROR The device reported an error while attempting
629 to perform the erase operation.
630 @retval EFI_INVALID_PARAMETER The erase request contains LBAs that are not
632 @retval EFI_NO_MEDIA There is no media in the device.
633 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
638 ScsiDiskEraseBlocks (
639 IN EFI_ERASE_BLOCK_PROTOCOL
*This
,
642 IN OUT EFI_ERASE_BLOCK_TOKEN
*Token
,
648 Provides inquiry information for the controller type.
650 This function is used by the IDE bus driver to get inquiry data. Data format
651 of Identify data is defined by the Interface GUID.
653 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
654 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
655 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
657 @retval EFI_SUCCESS The command was accepted without any errors.
658 @retval EFI_NOT_FOUND Device does not support this data class
659 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
660 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
665 ScsiDiskInfoInquiry (
666 IN EFI_DISK_INFO_PROTOCOL
*This
,
667 IN OUT VOID
*InquiryData
,
668 IN OUT UINT32
*InquiryDataSize
673 Provides identify information for the controller type.
675 This function is used by the IDE bus driver to get identify data. Data format
676 of Identify data is defined by the Interface GUID.
678 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
680 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
681 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
684 @retval EFI_SUCCESS The command was accepted without any errors.
685 @retval EFI_NOT_FOUND Device does not support this data class
686 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
687 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
692 ScsiDiskInfoIdentify (
693 IN EFI_DISK_INFO_PROTOCOL
*This
,
694 IN OUT VOID
*IdentifyData
,
695 IN OUT UINT32
*IdentifyDataSize
700 Provides sense data information for the controller type.
702 This function is used by the IDE bus driver to get sense data.
703 Data format of Sense data is defined by the Interface GUID.
705 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
706 @param[in, out] SenseData Pointer to the SenseData.
707 @param[in, out] SenseDataSize Size of SenseData in bytes.
708 @param[out] SenseDataNumber Pointer to the value for the sense data size.
710 @retval EFI_SUCCESS The command was accepted without any errors.
711 @retval EFI_NOT_FOUND Device does not support this data class.
712 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
713 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
718 ScsiDiskInfoSenseData (
719 IN EFI_DISK_INFO_PROTOCOL
*This
,
720 IN OUT VOID
*SenseData
,
721 IN OUT UINT32
*SenseDataSize
,
722 OUT UINT8
*SenseDataNumber
726 This function is used by the IDE bus driver to get controller information.
728 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
729 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
730 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
732 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
733 @retval EFI_UNSUPPORTED This is not an IDE device.
738 ScsiDiskInfoWhichIde (
739 IN EFI_DISK_INFO_PROTOCOL
*This
,
740 OUT UINT32
*IdeChannel
,
741 OUT UINT32
*IdeDevice
746 Detect Device and read out capacity ,if error occurs, parse the sense key.
748 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
749 @param MustReadCapacity The flag about reading device capacity
750 @param MediaChange The pointer of flag indicates if media has changed
752 @retval EFI_DEVICE_ERROR Indicates that error occurs
753 @retval EFI_SUCCESS Successfully to detect media
757 ScsiDiskDetectMedia (
758 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
759 IN BOOLEAN MustReadCapacity
,
760 OUT BOOLEAN
*MediaChange
766 When Test Unit Ready command succeeds, retrieve Sense Keys via Request Sense;
767 When Test Unit Ready command encounters any error caused by host adapter or
768 target, return error without retrieving Sense Keys.
770 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
771 @param NeedRetry The pointer of flag indicates try again
772 @param SenseDataArray The pointer of an array of sense data
773 @param NumberOfSenseKeys The pointer of the number of sense data array
775 @retval EFI_DEVICE_ERROR Indicates that error occurs
776 @retval EFI_SUCCESS Successfully to test unit
780 ScsiDiskTestUnitReady (
781 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
782 OUT BOOLEAN
*NeedRetry
,
783 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
784 OUT UINTN
*NumberOfSenseKeys
789 Parsing Sense Keys which got from request sense command.
791 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
792 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
793 @param NumberOfSenseKeys The number of sense key
794 @param Action The pointer of action which indicates what is need to do next
796 @retval EFI_DEVICE_ERROR Indicates that error occurs
797 @retval EFI_SUCCESS Successfully to complete the parsing
801 DetectMediaParsingSenseKeys (
802 OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
803 IN EFI_SCSI_SENSE_DATA
*SenseData
,
804 IN UINTN NumberOfSenseKeys
,
810 Send read capacity command to device and get the device parameter.
812 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
813 @param NeedRetry The pointer of flag indicates if need a retry
814 @param SenseDataArray The pointer of an array of sense data
815 @param NumberOfSenseKeys The number of sense key
817 @retval EFI_DEVICE_ERROR Indicates that error occurs
818 @retval EFI_SUCCESS Successfully to read capacity
822 ScsiDiskReadCapacity (
823 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
824 OUT BOOLEAN
*NeedRetry
,
825 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
826 OUT UINTN
*NumberOfSenseKeys
830 Check the HostAdapter status and re-interpret it in EFI_STATUS.
832 @param HostAdapterStatus Host Adapter status
834 @retval EFI_SUCCESS Host adapter is OK.
835 @retval EFI_TIMEOUT Timeout.
836 @retval EFI_NOT_READY Adapter NOT ready.
837 @retval EFI_DEVICE_ERROR Adapter device error.
841 CheckHostAdapterStatus (
842 IN UINT8 HostAdapterStatus
847 Check the target status and re-interpret it in EFI_STATUS.
849 @param TargetStatus Target status
851 @retval EFI_NOT_READY Device is NOT ready.
852 @retval EFI_DEVICE_ERROR
858 IN UINT8 TargetStatus
862 Retrieve all sense keys from the device.
864 When encountering error during the process, if retrieve sense keys before
865 error encountered, it returns the sense keys with return status set to EFI_SUCCESS,
866 and NeedRetry set to FALSE; otherwize, return the proper return status.
868 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
869 @param NeedRetry The pointer of flag indicates if need a retry
870 @param SenseDataArray The pointer of an array of sense data
871 @param NumberOfSenseKeys The number of sense key
872 @param AskResetIfError The flag indicates if need reset when error occurs
874 @retval EFI_DEVICE_ERROR Indicates that error occurs
875 @retval EFI_SUCCESS Successfully to request sense key
879 ScsiDiskRequestSenseKeys (
880 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
881 OUT BOOLEAN
*NeedRetry
,
882 OUT EFI_SCSI_SENSE_DATA
**SenseDataArray
,
883 OUT UINTN
*NumberOfSenseKeys
,
884 IN BOOLEAN AskResetIfError
888 Send out Inquiry command to Device.
890 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
891 @param NeedRetry Indicates if needs try again when error happens
893 @retval EFI_DEVICE_ERROR Indicates that error occurs
894 @retval EFI_SUCCESS Successfully to detect media
898 ScsiDiskInquiryDevice (
899 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
900 OUT BOOLEAN
*NeedRetry
906 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
911 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
915 Read sector from SCSI Disk.
917 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
918 @param Buffer The buffer to fill in the read out data
919 @param Lba Logic block address
920 @param NumberOfBlocks The number of blocks to read
922 @retval EFI_DEVICE_ERROR Indicates a device error.
923 @retval EFI_SUCCESS Operation is successful.
927 ScsiDiskReadSectors (
928 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
931 IN UINTN NumberOfBlocks
935 Write sector to SCSI Disk.
937 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
938 @param Buffer The buffer of data to be written into SCSI Disk
939 @param Lba Logic block address
940 @param NumberOfBlocks The number of blocks to read
942 @retval EFI_DEVICE_ERROR Indicates a device error.
943 @retval EFI_SUCCESS Operation is successful.
947 ScsiDiskWriteSectors (
948 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
951 IN UINTN NumberOfBlocks
955 Asynchronously read sector from SCSI Disk.
957 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
958 @param Buffer The buffer to fill in the read out data.
959 @param Lba Logic block address.
960 @param NumberOfBlocks The number of blocks to read.
961 @param Token A pointer to the token associated with the
962 non-blocking read request.
964 @retval EFI_INVALID_PARAMETER Token is NULL or Token->Event is NULL.
965 @retval EFI_DEVICE_ERROR Indicates a device error.
966 @retval EFI_SUCCESS Operation is successful.
970 ScsiDiskAsyncReadSectors (
971 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
974 IN UINTN NumberOfBlocks
,
975 IN EFI_BLOCK_IO2_TOKEN
*Token
979 Asynchronously write sector to SCSI Disk.
981 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
982 @param Buffer The buffer of data to be written into SCSI Disk.
983 @param Lba Logic block address.
984 @param NumberOfBlocks The number of blocks to read.
985 @param Token A pointer to the token associated with the
986 non-blocking read request.
988 @retval EFI_INVALID_PARAMETER Token is NULL or Token->Event is NULL
989 @retval EFI_DEVICE_ERROR Indicates a device error.
990 @retval EFI_SUCCESS Operation is successful.
994 ScsiDiskAsyncWriteSectors (
995 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
998 IN UINTN NumberOfBlocks
,
999 IN EFI_BLOCK_IO2_TOKEN
*Token
1003 Submit Read(10) command.
1005 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1006 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1007 @param Timeout The time to complete the command
1008 @param DataBuffer The buffer to fill with the read out data
1009 @param DataLength The length of buffer
1010 @param StartLba The start logic block address
1011 @param SectorCount The number of blocks to read
1013 @return EFI_STATUS is returned by calling ScsiRead10Command().
1017 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1018 OUT BOOLEAN
*NeedRetry
,
1020 OUT UINT8
*DataBuffer
,
1021 IN OUT UINT32
*DataLength
,
1023 IN UINT32 SectorCount
1027 Submit Write(10) Command.
1029 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1030 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1031 @param Timeout The time to complete the command
1032 @param DataBuffer The buffer to fill with the read out data
1033 @param DataLength The length of buffer
1034 @param StartLba The start logic block address
1035 @param SectorCount The number of blocks to write
1037 @return EFI_STATUS is returned by calling ScsiWrite10Command().
1042 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1043 OUT BOOLEAN
*NeedRetry
,
1045 IN UINT8
*DataBuffer
,
1046 IN OUT UINT32
*DataLength
,
1048 IN UINT32 SectorCount
1052 Submit Read(16) command.
1054 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1055 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1056 @param Timeout The time to complete the command
1057 @param DataBuffer The buffer to fill with the read out data
1058 @param DataLength The length of buffer
1059 @param StartLba The start logic block address
1060 @param SectorCount The number of blocks to read
1062 @return EFI_STATUS is returned by calling ScsiRead16Command().
1066 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1067 OUT BOOLEAN
*NeedRetry
,
1069 OUT UINT8
*DataBuffer
,
1070 IN OUT UINT32
*DataLength
,
1072 IN UINT32 SectorCount
1076 Submit Write(16) Command.
1078 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1079 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1080 @param Timeout The time to complete the command
1081 @param DataBuffer The buffer to fill with the read out data
1082 @param DataLength The length of buffer
1083 @param StartLba The start logic block address
1084 @param SectorCount The number of blocks to write
1086 @return EFI_STATUS is returned by calling ScsiWrite16Command().
1091 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1092 OUT BOOLEAN
*NeedRetry
,
1094 IN UINT8
*DataBuffer
,
1095 IN OUT UINT32
*DataLength
,
1097 IN UINT32 SectorCount
1101 Submit Async Read(10) command.
1103 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1104 @param Timeout The time to complete the command.
1105 @param TimesRetry The number of times the command has been retried.
1106 @param DataBuffer The buffer to fill with the read out data.
1107 @param DataLength The length of buffer.
1108 @param StartLba The start logic block address.
1109 @param SectorCount The number of blocks to read.
1110 @param BlkIo2Req The upstream BlockIo2 request.
1111 @param Token The pointer to the token associated with the
1112 non-blocking read request.
1114 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1116 @return others Status returned by calling
1117 ScsiRead10CommandEx().
1121 ScsiDiskAsyncRead10 (
1122 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1124 IN UINT8 TimesRetry
,
1125 OUT UINT8
*DataBuffer
,
1126 IN UINT32 DataLength
,
1128 IN UINT32 SectorCount
,
1129 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1130 IN EFI_BLOCK_IO2_TOKEN
*Token
1134 Submit Async Write(10) command.
1136 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1137 @param Timeout The time to complete the command.
1138 @param TimesRetry The number of times the command has been retried.
1139 @param DataBuffer The buffer contains the data to write.
1140 @param DataLength The length of buffer.
1141 @param StartLba The start logic block address.
1142 @param SectorCount The number of blocks to write.
1143 @param BlkIo2Req The upstream BlockIo2 request.
1144 @param Token The pointer to the token associated with the
1145 non-blocking read request.
1147 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1149 @return others Status returned by calling
1150 ScsiWrite10CommandEx().
1154 ScsiDiskAsyncWrite10 (
1155 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1157 IN UINT8 TimesRetry
,
1158 IN UINT8
*DataBuffer
,
1159 IN UINT32 DataLength
,
1161 IN UINT32 SectorCount
,
1162 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1163 IN EFI_BLOCK_IO2_TOKEN
*Token
1167 Submit Async Read(16) command.
1169 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1170 @param Timeout The time to complete the command.
1171 @param TimesRetry The number of times the command has been retried.
1172 @param DataBuffer The buffer to fill with the read out data.
1173 @param DataLength The length of buffer.
1174 @param StartLba The start logic block address.
1175 @param SectorCount The number of blocks to read.
1176 @param BlkIo2Req The upstream BlockIo2 request.
1177 @param Token The pointer to the token associated with the
1178 non-blocking read request.
1180 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1182 @return others Status returned by calling
1183 ScsiRead16CommandEx().
1187 ScsiDiskAsyncRead16 (
1188 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1190 IN UINT8 TimesRetry
,
1191 OUT UINT8
*DataBuffer
,
1192 IN UINT32 DataLength
,
1194 IN UINT32 SectorCount
,
1195 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1196 IN EFI_BLOCK_IO2_TOKEN
*Token
1200 Submit Async Write(16) command.
1202 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1203 @param Timeout The time to complete the command.
1204 @param TimesRetry The number of times the command has been retried.
1205 @param DataBuffer The buffer contains the data to write.
1206 @param DataLength The length of buffer.
1207 @param StartLba The start logic block address.
1208 @param SectorCount The number of blocks to write.
1209 @param BlkIo2Req The upstream BlockIo2 request.
1210 @param Token The pointer to the token associated with the
1211 non-blocking read request.
1213 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1215 @return others Status returned by calling
1216 ScsiWrite16CommandEx().
1220 ScsiDiskAsyncWrite16 (
1221 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1223 IN UINT8 TimesRetry
,
1224 IN UINT8
*DataBuffer
,
1225 IN UINT32 DataLength
,
1227 IN UINT32 SectorCount
,
1228 IN OUT SCSI_BLKIO2_REQUEST
*BlkIo2Req
,
1229 IN EFI_BLOCK_IO2_TOKEN
*Token
1233 Get information from media read capacity command.
1235 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1236 @param Capacity10 The pointer of EFI_SCSI_DISK_CAPACITY_DATA
1237 @param Capacity16 The pointer of EFI_SCSI_DISK_CAPACITY_DATA16
1241 IN OUT SCSI_DISK_DEV
*ScsiDiskDevice
,
1242 IN EFI_SCSI_DISK_CAPACITY_DATA
*Capacity10
,
1243 IN EFI_SCSI_DISK_CAPACITY_DATA16
*Capacity16
1247 Check sense key to find if media presents.
1249 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1250 @param SenseCounts The number of sense key
1252 @retval TRUE NOT any media
1253 @retval FALSE Media presents
1257 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1258 IN UINTN SenseCounts
1264 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1265 @param SenseCounts The number of sense key
1268 @retval FALSE NOT error
1272 ScsiDiskIsMediaError (
1273 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1274 IN UINTN SenseCounts
1278 Check sense key to find if hardware error happens.
1280 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1281 @param SenseCounts The number of sense key
1283 @retval TRUE Hardware error exits.
1284 @retval FALSE NO error.
1288 ScsiDiskIsHardwareError (
1289 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1290 IN UINTN SenseCounts
1294 Check sense key to find if media has changed.
1296 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1297 @param SenseCounts The number of sense key
1299 @retval TRUE Media is changed.
1300 @retval FALSE Medit is NOT changed.
1303 ScsiDiskIsMediaChange (
1304 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1305 IN UINTN SenseCounts
1309 Check sense key to find if reset happens.
1311 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1312 @param SenseCounts The number of sense key
1314 @retval TRUE It is reset before.
1315 @retval FALSE It is NOT reset before.
1319 ScsiDiskIsResetBefore (
1320 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1321 IN UINTN SenseCounts
1325 Check sense key to find if the drive is ready.
1327 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1328 @param SenseCounts The number of sense key
1329 @param RetryLater The flag means if need a retry
1331 @retval TRUE Drive is ready.
1332 @retval FALSE Drive is NOT ready.
1336 ScsiDiskIsDriveReady (
1337 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1338 IN UINTN SenseCounts
,
1339 OUT BOOLEAN
*RetryLater
1343 Check sense key to find if it has sense key.
1345 @param SenseData - The pointer of EFI_SCSI_SENSE_DATA
1346 @param SenseCounts - The number of sense key
1348 @retval TRUE It has sense key.
1349 @retval FALSE It has NOT any sense key.
1353 ScsiDiskHaveSenseKey (
1354 IN EFI_SCSI_SENSE_DATA
*SenseData
,
1355 IN UINTN SenseCounts
1359 Release resource about disk device.
1361 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1365 ReleaseScsiDiskDeviceResources (
1366 IN SCSI_DISK_DEV
*ScsiDiskDevice
1370 Determine if Block Io should be produced.
1373 @param ChildHandle Child Handle to retrieve Parent information.
1375 @retval TRUE Should produce Block Io.
1376 @retval FALSE Should not produce Block Io.
1380 DetermineInstallBlockIo (
1381 IN EFI_HANDLE ChildHandle
1385 Initialize the installation of DiskInfo protocol.
1387 This function prepares for the installation of DiskInfo protocol on the child handle.
1388 By default, it installs DiskInfo protocol with SCSI interface GUID. If it further
1389 detects that the physical device is an ATAPI/AHCI device, it then updates interface GUID
1390 to be IDE/AHCI interface GUID.
1392 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1393 @param ChildHandle Child handle to install DiskInfo protocol.
1397 InitializeInstallDiskInfo (
1398 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1399 IN EFI_HANDLE ChildHandle
1403 Search protocol database and check to see if the protocol
1404 specified by ProtocolGuid is present on a ControllerHandle and opened by
1405 ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1406 If the ControllerHandle is found, then the protocol specified by ProtocolGuid
1407 will be opened on it.
1410 @param ProtocolGuid ProtocolGuid pointer.
1411 @param ChildHandle Child Handle to retrieve Parent information.
1417 IN EFI_GUID
*ProtocolGuid
,
1418 IN EFI_HANDLE ChildHandle
1422 Determine if EFI Erase Block Protocol should be produced.
1424 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1425 @param ChildHandle Handle of device.
1427 @retval TRUE Should produce EFI Erase Block Protocol.
1428 @retval FALSE Should not produce EFI Erase Block Protocol.
1432 DetermineInstallEraseBlock (
1433 IN SCSI_DISK_DEV
*ScsiDiskDevice
,
1434 IN EFI_HANDLE ChildHandle