2 Header file for SCSI Disk Driver.
4 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
5 All rights reserved. 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.
19 #include <IndustryStandard/Scsi.h>
21 #define IsDeviceFixed(a) (a)->FixedDevice ? 1 : 0
23 #define SCSI_DISK_DEV_SIGNATURE EFI_SIGNATURE_32 ('s', 'c', 'd', 'k')
30 EFI_BLOCK_IO_PROTOCOL BlkIo
;
31 EFI_BLOCK_IO_MEDIA BlkIoMedia
;
32 EFI_SCSI_IO_PROTOCOL
*ScsiIo
;
37 EFI_SCSI_SENSE_DATA
*SenseData
;
38 UINTN SenseDataNumber
;
39 EFI_SCSI_INQUIRY_DATA InquiryData
;
41 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
45 #define SCSI_DISK_DEV_FROM_THIS(a) CR (a, SCSI_DISK_DEV, BlkIo, SCSI_DISK_DEV_SIGNATURE)
50 extern EFI_DRIVER_BINDING_PROTOCOL gScsiDiskDriverBinding
;
51 extern EFI_COMPONENT_NAME_PROTOCOL gScsiDiskComponentName
;
52 extern EFI_COMPONENT_NAME2_PROTOCOL gScsiDiskComponentName2
;
54 // action code used in detect media process
56 #define ACTION_NO_ACTION 0x00
57 #define ACTION_READ_CAPACITY 0x01
58 #define ACTION_RETRY_COMMAND_LATER 0x02
62 ScsiDiskDriverBindingSupported (
63 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
64 IN EFI_HANDLE Controller
,
65 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
70 ScsiDiskDriverBindingStart (
71 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
72 IN EFI_HANDLE Controller
,
73 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
78 ScsiDiskDriverBindingStop (
79 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
80 IN EFI_HANDLE Controller
,
81 IN UINTN NumberOfChildren
,
82 IN EFI_HANDLE
*ChildHandleBuffer
86 // EFI Component Name Functions
89 Retrieves a Unicode string that is the user readable name of the driver.
91 This function retrieves the user readable name of a driver in the form of a
92 Unicode string. If the driver specified by This has a user readable name in
93 the language specified by Language, then a pointer to the driver name is
94 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
95 by This does not support the language specified by Language,
96 then EFI_UNSUPPORTED is returned.
98 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
99 EFI_COMPONENT_NAME_PROTOCOL instance.
101 @param Language[in] A pointer to a Null-terminated ASCII string
102 array indicating the language. This is the
103 language of the driver name that the caller is
104 requesting, and it must match one of the
105 languages specified in SupportedLanguages. The
106 number of languages supported by a driver is up
107 to the driver writer. Language is specified
108 in RFC 3066 or ISO 639-2 language code format.
110 @param DriverName[out] A pointer to the Unicode string to return.
111 This Unicode string is the name of the
112 driver specified by This in the language
113 specified by Language.
115 @retval EFI_SUCCESS The Unicode string for the Driver specified by
116 This and the language specified by Language was
117 returned in DriverName.
119 @retval EFI_INVALID_PARAMETER Language is NULL.
121 @retval EFI_INVALID_PARAMETER DriverName is NULL.
123 @retval EFI_UNSUPPORTED The driver specified by This does not support
124 the language specified by Language.
129 ScsiDiskComponentNameGetDriverName (
130 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
132 OUT CHAR16
**DriverName
137 Retrieves a Unicode string that is the user readable name of the controller
138 that is being managed by a driver.
140 This function retrieves the user readable name of the controller specified by
141 ControllerHandle and ChildHandle in the form of a Unicode string. If the
142 driver specified by This has a user readable name in the language specified by
143 Language, then a pointer to the controller name is returned in ControllerName,
144 and EFI_SUCCESS is returned. If the driver specified by This is not currently
145 managing the controller specified by ControllerHandle and ChildHandle,
146 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
147 support the language specified by Language, then EFI_UNSUPPORTED is returned.
149 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
150 EFI_COMPONENT_NAME_PROTOCOL instance.
152 @param ControllerHandle[in] The handle of a controller that the driver
153 specified by This is managing. This handle
154 specifies the controller whose name is to be
157 @param ChildHandle[in] The handle of the child controller to retrieve
158 the name of. This is an optional parameter that
159 may be NULL. It will be NULL for device
160 drivers. It will also be NULL for a bus drivers
161 that wish to retrieve the name of the bus
162 controller. It will not be NULL for a bus
163 driver that wishes to retrieve the name of a
166 @param Language[in] A pointer to a Null-terminated ASCII string
167 array indicating the language. This is the
168 language of the driver name that the caller is
169 requesting, and it must match one of the
170 languages specified in SupportedLanguages. The
171 number of languages supported by a driver is up
172 to the driver writer. Language is specified in
173 RFC 3066 or ISO 639-2 language code format.
175 @param ControllerName[out] A pointer to the Unicode string to return.
176 This Unicode string is the name of the
177 controller specified by ControllerHandle and
178 ChildHandle in the language specified by
179 Language from the point of view of the driver
182 @retval EFI_SUCCESS The Unicode string for the user readable name in
183 the language specified by Language for the
184 driver specified by This was returned in
187 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
189 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
192 @retval EFI_INVALID_PARAMETER Language is NULL.
194 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
196 @retval EFI_UNSUPPORTED The driver specified by This is not currently
197 managing the controller specified by
198 ControllerHandle and ChildHandle.
200 @retval EFI_UNSUPPORTED The driver specified by This does not support
201 the language specified by Language.
206 ScsiDiskComponentNameGetControllerName (
207 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
208 IN EFI_HANDLE ControllerHandle
,
209 IN EFI_HANDLE ChildHandle OPTIONAL
,
211 OUT CHAR16
**ControllerName
218 IN EFI_BLOCK_IO_PROTOCOL
*This
,
219 IN BOOLEAN ExtendedVerification
229 This - The pointer of EFI_BLOCK_IO_PROTOCOL
230 ExtendedVerification - The flag about if extend verificate
242 IN EFI_BLOCK_IO_PROTOCOL
*This
,
252 The function is to Read Block from SCSI Disk
256 This - The pointer of EFI_BLOCK_IO_PROTOCOL
257 MediaId - The Id of Media detected
258 LBA - The logic block address
259 BufferSize - The size of Buffer
260 Buffer - The buffer to fill the read out data
264 EFI_INVALID_PARAMETER - Invalid parameter passed in.
265 EFI_SUCCESS - Successfully to read out block.
266 EFI_DEVICE_ERROR - Fail to detect media.
267 EFI_NO_MEDIA - Media is not present.
268 EFI_MEDIA_CHANGED - Media has changed.
269 EFI_BAD_BUFFER_SIZE - The buffer size is not multiple of BlockSize.
276 ScsiDiskWriteBlocks (
277 IN EFI_BLOCK_IO_PROTOCOL
*This
,
287 The function is to Write Block to SCSI Disk
291 This - The pointer of EFI_BLOCK_IO_PROTOCOL
292 MediaId - The Id of Media detected
293 LBA - The logic block address
294 BufferSize - The size of Buffer
295 Buffer - The buffer to fill the read out data
299 EFI_INVALID_PARAMETER - Invalid parameter passed in.
300 EFI_SUCCESS - Successfully to read out block.
301 EFI_DEVICE_ERROR - Fail to detect media.
302 EFI_NO_MEDIA - Media is not present.
303 EFI_MEDIA_CHANGED - Media has changed.
304 EFI_BAD_BUFFER_SIZE - The buffer size is not multiple of BlockSize.
311 ScsiDiskFlushBlocks (
312 IN EFI_BLOCK_IO_PROTOCOL
*This
322 This - The pointer of EFI_BLOCK_IO_PROTOCOL
332 ScsiDiskDetectMedia (
333 SCSI_DISK_DEV
*ScsiDiskDevice
,
341 Dectect Device and read out capacity ,if error occurs, parse the sense key.
345 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
346 MustReadCapacity - The flag about reading device capacity
347 MediaChange - The pointer of flag indicates if media has changed
351 EFI_DEVICE_ERROR - Indicates that error occurs
352 EFI_SUCCESS - Successfully to detect media
358 ScsiDiskTestUnitReady (
359 SCSI_DISK_DEV
*ScsiDiskDevice
,
361 EFI_SCSI_SENSE_DATA
**SenseDataArray
,
362 UINTN
*NumberOfSenseKeys
368 When Test Unit Ready command succeeds, retrieve Sense Keys via Request Sense;
369 When Test Unit Ready command encounters any error caused by host adapter or
370 target, return error without retrieving Sense Keys.
374 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
375 NeedRetry - The pointer of flag indicates try again
376 SenseDataArray - The pointer of an array of sense data
377 NumberOfSenseKeys - The pointer of the number of sense data array
381 EFI_DEVICE_ERROR - Indicates that error occurs
382 EFI_SUCCESS - Successfully to test unit
388 DetectMediaParsingSenseKeys (
389 SCSI_DISK_DEV
*ScsiDiskDevice
,
390 EFI_SCSI_SENSE_DATA
*SenseData
,
391 UINTN NumberOfSenseKeys
,
398 Parsing Sense Keys which got from request sense command.
402 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
403 SenseData - The pointer of EFI_SCSI_SENSE_DATA
404 NumberOfSenseKeys - The number of sense key
405 Action - The pointer of action which indicates what is need to do next
409 EFI_DEVICE_ERROR - Indicates that error occurs
410 EFI_SUCCESS - Successfully to complete the parsing
416 ScsiDiskReadCapacity (
417 SCSI_DISK_DEV
*ScsiDiskDevice
,
419 EFI_SCSI_SENSE_DATA
**SenseDataArray
,
420 UINTN
*NumberOfSenseKeys
426 Send read capacity command to device and get the device parameter
430 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
431 NeedRetry - The pointer of flag indicates if need a retry
432 SenseDataArray - The pointer of an array of sense data
433 NumberOfSenseKeys - The number of sense key
437 EFI_DEVICE_ERROR - Indicates that error occurs
438 EFI_SUCCESS - Successfully to read capacity
444 CheckHostAdapterStatus (
445 UINT8 HostAdapterStatus
451 Check the HostAdapter status
455 HostAdapterStatus - Host Adapter status
475 Check the target status
479 TargetStatus - Target status
491 ScsiDiskRequestSenseKeys (
492 SCSI_DISK_DEV
*ScsiDiskDevice
,
494 EFI_SCSI_SENSE_DATA
**SenseDataArray
,
495 UINTN
*NumberOfSenseKeys
,
496 BOOLEAN AskResetIfError
502 Retrieve all sense keys from the device.
503 When encountering error during the process,
504 if retrieve sense keys before error encounterred,
505 return the sense keys with return status set to EFI_SUCCESS,
506 and NeedRetry set to FALSE; otherwize, return the proper return
511 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
512 NeedRetry - The pointer of flag indicates if need a retry
513 SenseDataArray - The pointer of an array of sense data
514 NumberOfSenseKeys - The number of sense key
515 AskResetIfError - The flag indicates if need reset when error occurs
519 EFI_DEVICE_ERROR - Indicates that error occurs
520 EFI_SUCCESS - Successfully to request sense key
526 ScsiDiskInquiryDevice (
527 SCSI_DISK_DEV
*ScsiDiskDevice
,
534 Send out Inquiry command to Device
538 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
539 NeedRetry - Indicates if needs try again when error happens
543 EFI_DEVICE_ERROR - Indicates that error occurs
544 EFI_SUCCESS - Successfully to detect media
551 SCSI_DISK_DEV
*ScsiDiskDevice
561 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
571 ScsiDiskReadSectors (
572 SCSI_DISK_DEV
*ScsiDiskDevice
,
581 Read sector from SCSI Disk
585 ScsiDiskDevice - The poiniter of SCSI_DISK_DEV
586 Buffer - The buffer to fill in the read out data
587 Lba - Logic block address
588 NumberOfBlocks - The number of blocks to read
599 ScsiDiskWriteSectors (
600 SCSI_DISK_DEV
*ScsiDiskDevice
,
609 Write SCSI Disk sectors
613 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
614 Buffer - The data buffer to write sector
615 Lba - Logic block address
616 NumberOfBlocks - The number of blocks to write
628 SCSI_DISK_DEV
*ScsiDiskDevice
,
630 EFI_SCSI_SENSE_DATA
**SenseDataArray
,
631 UINTN
*NumberOfSenseKeys
,
646 ScsiDiskDevice - The pointer of ScsiDiskDevice
647 NeedRetry - The pointer of flag indicates if needs retry if error happens
648 SenseDataArray - The pointer of an array of sense data
649 NumberOfSenseKeys - The number of sense key
650 Timeout - The time to complete the command
651 DataBuffer - The buffer to fill with the read out data
652 DataLength - The length of buffer
653 StartLba - The start logic block address
654 SectorSize - The size of sector
665 SCSI_DISK_DEV
*ScsiDiskDevice
,
667 EFI_SCSI_SENSE_DATA
**SenseDataArray
,
668 UINTN
*NumberOfSenseKeys
,
683 ScsiDiskDevice - The pointer of ScsiDiskDevice
684 NeedRetry - The pointer of flag indicates if needs retry if error happens
685 SenseDataArray - The pointer of an array of sense data
686 NumberOfSenseKeys - The number of sense key
687 Timeout - The time to complete the command
688 DataBuffer - The buffer to fill with the read out data
689 DataLength - The length of buffer
690 StartLba - The start logic block address
691 SectorSize - The size of sector
702 SCSI_DISK_DEV
*ScsiDiskDevice
,
703 EFI_SCSI_DISK_CAPACITY_DATA
*Capacity
709 Get information from media read capacity command
713 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
714 Capacity - The pointer of EFI_SCSI_DISK_CAPACITY_DATA
725 IN EFI_SCSI_SENSE_DATA
*SenseData
,
732 Check sense key to find if media presents
736 SenseData - The pointer of EFI_SCSI_SENSE_DATA
737 SenseCounts - The number of sense key
747 ScsiDiskIsMediaError (
748 IN EFI_SCSI_SENSE_DATA
*SenseData
,
759 SenseData - The pointer of EFI_SCSI_SENSE_DATA
760 SenseCounts - The number of sense key
770 ScsiDiskIsHardwareError (
771 IN EFI_SCSI_SENSE_DATA
*SenseData
,
778 Check sense key to find if hardware error happens
782 SenseData - The pointer of EFI_SCSI_SENSE_DATA
783 SenseCounts - The number of sense key
793 ScsiDiskIsMediaChange (
794 IN EFI_SCSI_SENSE_DATA
*SenseData
,
803 Check sense key to find if media has changed
807 SenseData - The pointer of EFI_SCSI_SENSE_DATA
808 SenseCounts - The number of sense key
818 ScsiDiskIsResetBefore (
819 IN EFI_SCSI_SENSE_DATA
*SenseData
,
826 Check sense key to find if reset happens
830 SenseData - The pointer of EFI_SCSI_SENSE_DATA
831 SenseCounts - The number of sense key
841 ScsiDiskIsDriveReady (
842 IN EFI_SCSI_SENSE_DATA
*SenseData
,
843 IN UINTN SenseCounts
,
844 OUT BOOLEAN
*NeedRetry
850 Check sense key to find if the drive is ready
854 SenseData - The pointer of EFI_SCSI_SENSE_DATA
855 SenseCounts - The number of sense key
856 RetryLater - The flag means if need a retry
866 ScsiDiskHaveSenseKey (
867 IN EFI_SCSI_SENSE_DATA
*SenseData
,
874 Check sense key to find if it has sense key
878 SenseData - The pointer of EFI_SCSI_SENSE_DATA
879 SenseCounts - The number of sense key
889 ReleaseScsiDiskDeviceResources (
890 IN SCSI_DISK_DEV
*ScsiDiskDevice
896 Release resource about disk device
900 ScsiDiskDevice - The pointer of SCSI_DISK_DEV