3 Copyright (c) 2004 - 2008, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Header file for SCSI Disk Driver.
26 #include <IndustryStandard/Scsi.h>
28 #define IsDeviceFixed(a) (a)->FixedDevice ? 1 : 0
30 #define SCSI_DISK_DEV_SIGNATURE EFI_SIGNATURE_32 ('s', 'c', 'd', 'k')
37 EFI_BLOCK_IO_PROTOCOL BlkIo
;
38 EFI_BLOCK_IO_MEDIA BlkIoMedia
;
39 EFI_SCSI_IO_PROTOCOL
*ScsiIo
;
44 EFI_SCSI_SENSE_DATA
*SenseData
;
45 UINTN SenseDataNumber
;
46 EFI_SCSI_INQUIRY_DATA InquiryData
;
48 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
52 #define SCSI_DISK_DEV_FROM_THIS(a) CR (a, SCSI_DISK_DEV, BlkIo, SCSI_DISK_DEV_SIGNATURE)
57 extern EFI_DRIVER_BINDING_PROTOCOL gScsiDiskDriverBinding
;
58 extern EFI_COMPONENT_NAME_PROTOCOL gScsiDiskComponentName
;
59 extern EFI_COMPONENT_NAME2_PROTOCOL gScsiDiskComponentName2
;
61 // action code used in detect media process
63 #define ACTION_NO_ACTION 0x00
64 #define ACTION_READ_CAPACITY 0x01
65 #define ACTION_RETRY_COMMAND_LATER 0x02
69 ScsiDiskDriverBindingSupported (
70 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
71 IN EFI_HANDLE Controller
,
72 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
77 ScsiDiskDriverBindingStart (
78 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
79 IN EFI_HANDLE Controller
,
80 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
85 ScsiDiskDriverBindingStop (
86 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
87 IN EFI_HANDLE Controller
,
88 IN UINTN NumberOfChildren
,
89 IN EFI_HANDLE
*ChildHandleBuffer
93 // EFI Component Name Functions
96 Retrieves a Unicode string that is the user readable name of the driver.
98 This function retrieves the user readable name of a driver in the form of a
99 Unicode string. If the driver specified by This has a user readable name in
100 the language specified by Language, then a pointer to the driver name is
101 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
102 by This does not support the language specified by Language,
103 then EFI_UNSUPPORTED is returned.
105 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
106 EFI_COMPONENT_NAME_PROTOCOL instance.
108 @param Language[in] A pointer to a Null-terminated ASCII string
109 array indicating the language. This is the
110 language of the driver name that the caller is
111 requesting, and it must match one of the
112 languages specified in SupportedLanguages. The
113 number of languages supported by a driver is up
114 to the driver writer. Language is specified
115 in RFC 3066 or ISO 639-2 language code format.
117 @param DriverName[out] A pointer to the Unicode string to return.
118 This Unicode string is the name of the
119 driver specified by This in the language
120 specified by Language.
122 @retval EFI_SUCCESS The Unicode string for the Driver specified by
123 This and the language specified by Language was
124 returned in DriverName.
126 @retval EFI_INVALID_PARAMETER Language is NULL.
128 @retval EFI_INVALID_PARAMETER DriverName is NULL.
130 @retval EFI_UNSUPPORTED The driver specified by This does not support
131 the language specified by Language.
136 ScsiDiskComponentNameGetDriverName (
137 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
139 OUT CHAR16
**DriverName
144 Retrieves a Unicode string that is the user readable name of the controller
145 that is being managed by a driver.
147 This function retrieves the user readable name of the controller specified by
148 ControllerHandle and ChildHandle in the form of a Unicode string. If the
149 driver specified by This has a user readable name in the language specified by
150 Language, then a pointer to the controller name is returned in ControllerName,
151 and EFI_SUCCESS is returned. If the driver specified by This is not currently
152 managing the controller specified by ControllerHandle and ChildHandle,
153 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
154 support the language specified by Language, then EFI_UNSUPPORTED is returned.
156 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
157 EFI_COMPONENT_NAME_PROTOCOL instance.
159 @param ControllerHandle[in] The handle of a controller that the driver
160 specified by This is managing. This handle
161 specifies the controller whose name is to be
164 @param ChildHandle[in] The handle of the child controller to retrieve
165 the name of. This is an optional parameter that
166 may be NULL. It will be NULL for device
167 drivers. It will also be NULL for a bus drivers
168 that wish to retrieve the name of the bus
169 controller. It will not be NULL for a bus
170 driver that wishes to retrieve the name of a
173 @param Language[in] A pointer to a Null-terminated ASCII string
174 array indicating the language. This is the
175 language of the driver name that the caller is
176 requesting, and it must match one of the
177 languages specified in SupportedLanguages. The
178 number of languages supported by a driver is up
179 to the driver writer. Language is specified in
180 RFC 3066 or ISO 639-2 language code format.
182 @param ControllerName[out] A pointer to the Unicode string to return.
183 This Unicode string is the name of the
184 controller specified by ControllerHandle and
185 ChildHandle in the language specified by
186 Language from the point of view of the driver
189 @retval EFI_SUCCESS The Unicode string for the user readable name in
190 the language specified by Language for the
191 driver specified by This was returned in
194 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
196 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
199 @retval EFI_INVALID_PARAMETER Language is NULL.
201 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
203 @retval EFI_UNSUPPORTED The driver specified by This is not currently
204 managing the controller specified by
205 ControllerHandle and ChildHandle.
207 @retval EFI_UNSUPPORTED The driver specified by This does not support
208 the language specified by Language.
213 ScsiDiskComponentNameGetControllerName (
214 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
215 IN EFI_HANDLE ControllerHandle
,
216 IN EFI_HANDLE ChildHandle OPTIONAL
,
218 OUT CHAR16
**ControllerName
225 IN EFI_BLOCK_IO_PROTOCOL
*This
,
226 IN BOOLEAN ExtendedVerification
236 This - The pointer of EFI_BLOCK_IO_PROTOCOL
237 ExtendedVerification - The flag about if extend verificate
249 IN EFI_BLOCK_IO_PROTOCOL
*This
,
259 The function is to Read Block from SCSI Disk
263 This - The pointer of EFI_BLOCK_IO_PROTOCOL
264 MediaId - The Id of Media detected
265 LBA - The logic block address
266 BufferSize - The size of Buffer
267 Buffer - The buffer to fill the read out data
271 EFI_INVALID_PARAMETER - Invalid parameter passed in.
272 EFI_SUCCESS - Successfully to read out block.
273 EFI_DEVICE_ERROR - Fail to detect media.
274 EFI_NO_MEDIA - Media is not present.
275 EFI_MEDIA_CHANGED - Media has changed.
276 EFI_BAD_BUFFER_SIZE - The buffer size is not multiple of BlockSize.
283 ScsiDiskWriteBlocks (
284 IN EFI_BLOCK_IO_PROTOCOL
*This
,
294 The function is to Write Block to SCSI Disk
298 This - The pointer of EFI_BLOCK_IO_PROTOCOL
299 MediaId - The Id of Media detected
300 LBA - The logic block address
301 BufferSize - The size of Buffer
302 Buffer - The buffer to fill the read out data
306 EFI_INVALID_PARAMETER - Invalid parameter passed in.
307 EFI_SUCCESS - Successfully to read out block.
308 EFI_DEVICE_ERROR - Fail to detect media.
309 EFI_NO_MEDIA - Media is not present.
310 EFI_MEDIA_CHANGED - Media has changed.
311 EFI_BAD_BUFFER_SIZE - The buffer size is not multiple of BlockSize.
318 ScsiDiskFlushBlocks (
319 IN EFI_BLOCK_IO_PROTOCOL
*This
329 This - The pointer of EFI_BLOCK_IO_PROTOCOL
339 ScsiDiskDetectMedia (
340 SCSI_DISK_DEV
*ScsiDiskDevice
,
348 Dectect Device and read out capacity ,if error occurs, parse the sense key.
352 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
353 MustReadCapacity - The flag about reading device capacity
354 MediaChange - The pointer of flag indicates if media has changed
358 EFI_DEVICE_ERROR - Indicates that error occurs
359 EFI_SUCCESS - Successfully to detect media
365 ScsiDiskTestUnitReady (
366 SCSI_DISK_DEV
*ScsiDiskDevice
,
368 EFI_SCSI_SENSE_DATA
**SenseDataArray
,
369 UINTN
*NumberOfSenseKeys
375 When Test Unit Ready command succeeds, retrieve Sense Keys via Request Sense;
376 When Test Unit Ready command encounters any error caused by host adapter or
377 target, return error without retrieving Sense Keys.
381 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
382 NeedRetry - The pointer of flag indicates try again
383 SenseDataArray - The pointer of an array of sense data
384 NumberOfSenseKeys - The pointer of the number of sense data array
388 EFI_DEVICE_ERROR - Indicates that error occurs
389 EFI_SUCCESS - Successfully to test unit
395 DetectMediaParsingSenseKeys (
396 SCSI_DISK_DEV
*ScsiDiskDevice
,
397 EFI_SCSI_SENSE_DATA
*SenseData
,
398 UINTN NumberOfSenseKeys
,
405 Parsing Sense Keys which got from request sense command.
409 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
410 SenseData - The pointer of EFI_SCSI_SENSE_DATA
411 NumberOfSenseKeys - The number of sense key
412 Action - The pointer of action which indicates what is need to do next
416 EFI_DEVICE_ERROR - Indicates that error occurs
417 EFI_SUCCESS - Successfully to complete the parsing
423 ScsiDiskReadCapacity (
424 SCSI_DISK_DEV
*ScsiDiskDevice
,
426 EFI_SCSI_SENSE_DATA
**SenseDataArray
,
427 UINTN
*NumberOfSenseKeys
433 Send read capacity command to device and get the device parameter
437 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
438 NeedRetry - The pointer of flag indicates if need a retry
439 SenseDataArray - The pointer of an array of sense data
440 NumberOfSenseKeys - The number of sense key
444 EFI_DEVICE_ERROR - Indicates that error occurs
445 EFI_SUCCESS - Successfully to read capacity
451 CheckHostAdapterStatus (
452 UINT8 HostAdapterStatus
458 Check the HostAdapter status
462 HostAdapterStatus - Host Adapter status
482 Check the target status
486 TargetStatus - Target status
498 ScsiDiskRequestSenseKeys (
499 SCSI_DISK_DEV
*ScsiDiskDevice
,
501 EFI_SCSI_SENSE_DATA
**SenseDataArray
,
502 UINTN
*NumberOfSenseKeys
,
503 BOOLEAN AskResetIfError
509 Retrieve all sense keys from the device.
510 When encountering error during the process,
511 if retrieve sense keys before error encounterred,
512 return the sense keys with return status set to EFI_SUCCESS,
513 and NeedRetry set to FALSE; otherwize, return the proper return
518 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
519 NeedRetry - The pointer of flag indicates if need a retry
520 SenseDataArray - The pointer of an array of sense data
521 NumberOfSenseKeys - The number of sense key
522 AskResetIfError - The flag indicates if need reset when error occurs
526 EFI_DEVICE_ERROR - Indicates that error occurs
527 EFI_SUCCESS - Successfully to request sense key
533 ScsiDiskInquiryDevice (
534 SCSI_DISK_DEV
*ScsiDiskDevice
,
541 Send out Inquiry command to Device
545 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
546 NeedRetry - Indicates if needs try again when error happens
550 EFI_DEVICE_ERROR - Indicates that error occurs
551 EFI_SUCCESS - Successfully to detect media
558 SCSI_DISK_DEV
*ScsiDiskDevice
568 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
578 ScsiDiskReadSectors (
579 SCSI_DISK_DEV
*ScsiDiskDevice
,
588 Read sector from SCSI Disk
592 ScsiDiskDevice - The poiniter of SCSI_DISK_DEV
593 Buffer - The buffer to fill in the read out data
594 Lba - Logic block address
595 NumberOfBlocks - The number of blocks to read
606 ScsiDiskWriteSectors (
607 SCSI_DISK_DEV
*ScsiDiskDevice
,
616 Write SCSI Disk sectors
620 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
621 Buffer - The data buffer to write sector
622 Lba - Logic block address
623 NumberOfBlocks - The number of blocks to write
635 SCSI_DISK_DEV
*ScsiDiskDevice
,
637 EFI_SCSI_SENSE_DATA
**SenseDataArray
,
638 UINTN
*NumberOfSenseKeys
,
653 ScsiDiskDevice - The pointer of ScsiDiskDevice
654 NeedRetry - The pointer of flag indicates if needs retry if error happens
655 SenseDataArray - The pointer of an array of sense data
656 NumberOfSenseKeys - The number of sense key
657 Timeout - The time to complete the command
658 DataBuffer - The buffer to fill with the read out data
659 DataLength - The length of buffer
660 StartLba - The start logic block address
661 SectorSize - The size of sector
672 SCSI_DISK_DEV
*ScsiDiskDevice
,
674 EFI_SCSI_SENSE_DATA
**SenseDataArray
,
675 UINTN
*NumberOfSenseKeys
,
690 ScsiDiskDevice - The pointer of ScsiDiskDevice
691 NeedRetry - The pointer of flag indicates if needs retry if error happens
692 SenseDataArray - The pointer of an array of sense data
693 NumberOfSenseKeys - The number of sense key
694 Timeout - The time to complete the command
695 DataBuffer - The buffer to fill with the read out data
696 DataLength - The length of buffer
697 StartLba - The start logic block address
698 SectorSize - The size of sector
709 SCSI_DISK_DEV
*ScsiDiskDevice
,
710 EFI_SCSI_DISK_CAPACITY_DATA
*Capacity
716 Get information from media read capacity command
720 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
721 Capacity - The pointer of EFI_SCSI_DISK_CAPACITY_DATA
732 IN EFI_SCSI_SENSE_DATA
*SenseData
,
739 Check sense key to find if media presents
743 SenseData - The pointer of EFI_SCSI_SENSE_DATA
744 SenseCounts - The number of sense key
754 ScsiDiskIsMediaError (
755 IN EFI_SCSI_SENSE_DATA
*SenseData
,
766 SenseData - The pointer of EFI_SCSI_SENSE_DATA
767 SenseCounts - The number of sense key
777 ScsiDiskIsHardwareError (
778 IN EFI_SCSI_SENSE_DATA
*SenseData
,
785 Check sense key to find if hardware error happens
789 SenseData - The pointer of EFI_SCSI_SENSE_DATA
790 SenseCounts - The number of sense key
800 ScsiDiskIsMediaChange (
801 IN EFI_SCSI_SENSE_DATA
*SenseData
,
810 Check sense key to find if media has changed
814 SenseData - The pointer of EFI_SCSI_SENSE_DATA
815 SenseCounts - The number of sense key
825 ScsiDiskIsResetBefore (
826 IN EFI_SCSI_SENSE_DATA
*SenseData
,
833 Check sense key to find if reset happens
837 SenseData - The pointer of EFI_SCSI_SENSE_DATA
838 SenseCounts - The number of sense key
848 ScsiDiskIsDriveReady (
849 IN EFI_SCSI_SENSE_DATA
*SenseData
,
850 IN UINTN SenseCounts
,
851 OUT BOOLEAN
*NeedRetry
857 Check sense key to find if the drive is ready
861 SenseData - The pointer of EFI_SCSI_SENSE_DATA
862 SenseCounts - The number of sense key
863 RetryLater - The flag means if need a retry
873 ScsiDiskHaveSenseKey (
874 IN EFI_SCSI_SENSE_DATA
*SenseData
,
881 Check sense key to find if it has sense key
885 SenseData - The pointer of EFI_SCSI_SENSE_DATA
886 SenseCounts - The number of sense key
896 ReleaseScsiDiskDeviceResources (
897 IN SCSI_DISK_DEV
*ScsiDiskDevice
903 Release resource about disk device
907 ScsiDiskDevice - The pointer of SCSI_DISK_DEV