3 Copyright (c) 2004 - 2007, 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
;
60 // action code used in detect media process
62 #define ACTION_NO_ACTION 0x00
63 #define ACTION_READ_CAPACITY 0x01
64 #define ACTION_RETRY_COMMAND_LATER 0x02
68 ScsiDiskDriverBindingSupported (
69 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
70 IN EFI_HANDLE Controller
,
71 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
76 ScsiDiskDriverBindingStart (
77 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
78 IN EFI_HANDLE Controller
,
79 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
84 ScsiDiskDriverBindingStop (
85 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
86 IN EFI_HANDLE Controller
,
87 IN UINTN NumberOfChildren
,
88 IN EFI_HANDLE
*ChildHandleBuffer
92 // EFI Component Name Functions
96 ScsiDiskComponentNameGetDriverName (
97 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
99 OUT CHAR16
**DriverName
104 ScsiDiskComponentNameGetControllerName (
105 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
106 IN EFI_HANDLE ControllerHandle
,
107 IN EFI_HANDLE ChildHandle OPTIONAL
,
109 OUT CHAR16
**ControllerName
115 IN EFI_BLOCK_IO_PROTOCOL
*This
,
116 IN BOOLEAN ExtendedVerification
126 This - The pointer of EFI_BLOCK_IO_PROTOCOL
127 ExtendedVerification - The flag about if extend verificate
139 IN EFI_BLOCK_IO_PROTOCOL
*This
,
149 The function is to Read Block from SCSI Disk
153 This - The pointer of EFI_BLOCK_IO_PROTOCOL
154 MediaId - The Id of Media detected
155 LBA - The logic block address
156 BufferSize - The size of Buffer
157 Buffer - The buffer to fill the read out data
161 EFI_INVALID_PARAMETER - Invalid parameter passed in.
162 EFI_SUCCESS - Successfully to read out block.
163 EFI_DEVICE_ERROR - Fail to detect media.
164 EFI_NO_MEDIA - Media is not present.
165 EFI_MEDIA_CHANGED - Media has changed.
166 EFI_BAD_BUFFER_SIZE - The buffer size is not multiple of BlockSize.
173 ScsiDiskWriteBlocks (
174 IN EFI_BLOCK_IO_PROTOCOL
*This
,
184 The function is to Write Block to SCSI Disk
188 This - The pointer of EFI_BLOCK_IO_PROTOCOL
189 MediaId - The Id of Media detected
190 LBA - The logic block address
191 BufferSize - The size of Buffer
192 Buffer - The buffer to fill the read out data
196 EFI_INVALID_PARAMETER - Invalid parameter passed in.
197 EFI_SUCCESS - Successfully to read out block.
198 EFI_DEVICE_ERROR - Fail to detect media.
199 EFI_NO_MEDIA - Media is not present.
200 EFI_MEDIA_CHANGED - Media has changed.
201 EFI_BAD_BUFFER_SIZE - The buffer size is not multiple of BlockSize.
208 ScsiDiskFlushBlocks (
209 IN EFI_BLOCK_IO_PROTOCOL
*This
219 This - The pointer of EFI_BLOCK_IO_PROTOCOL
229 ScsiDiskDetectMedia (
230 SCSI_DISK_DEV
*ScsiDiskDevice
,
238 Dectect Device and read out capacity ,if error occurs, parse the sense key.
242 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
243 MustReadCapacity - The flag about reading device capacity
244 MediaChange - The pointer of flag indicates if media has changed
248 EFI_DEVICE_ERROR - Indicates that error occurs
249 EFI_SUCCESS - Successfully to detect media
255 ScsiDiskTestUnitReady (
256 SCSI_DISK_DEV
*ScsiDiskDevice
,
258 EFI_SCSI_SENSE_DATA
**SenseDataArray
,
259 UINTN
*NumberOfSenseKeys
265 When Test Unit Ready command succeeds, retrieve Sense Keys via Request Sense;
266 When Test Unit Ready command encounters any error caused by host adapter or
267 target, return error without retrieving Sense Keys.
271 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
272 NeedRetry - The pointer of flag indicates try again
273 SenseDataArray - The pointer of an array of sense data
274 NumberOfSenseKeys - The pointer of the number of sense data array
278 EFI_DEVICE_ERROR - Indicates that error occurs
279 EFI_SUCCESS - Successfully to test unit
285 DetectMediaParsingSenseKeys (
286 SCSI_DISK_DEV
*ScsiDiskDevice
,
287 EFI_SCSI_SENSE_DATA
*SenseData
,
288 UINTN NumberOfSenseKeys
,
295 Parsing Sense Keys which got from request sense command.
299 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
300 SenseData - The pointer of EFI_SCSI_SENSE_DATA
301 NumberOfSenseKeys - The number of sense key
302 Action - The pointer of action which indicates what is need to do next
306 EFI_DEVICE_ERROR - Indicates that error occurs
307 EFI_SUCCESS - Successfully to complete the parsing
313 ScsiDiskReadCapacity (
314 SCSI_DISK_DEV
*ScsiDiskDevice
,
316 EFI_SCSI_SENSE_DATA
**SenseDataArray
,
317 UINTN
*NumberOfSenseKeys
323 Send read capacity command to device and get the device parameter
327 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
328 NeedRetry - The pointer of flag indicates if need a retry
329 SenseDataArray - The pointer of an array of sense data
330 NumberOfSenseKeys - The number of sense key
334 EFI_DEVICE_ERROR - Indicates that error occurs
335 EFI_SUCCESS - Successfully to read capacity
341 CheckHostAdapterStatus (
342 UINT8 HostAdapterStatus
348 Check the HostAdapter status
352 HostAdapterStatus - Host Adapter status
372 Check the target status
376 TargetStatus - Target status
388 ScsiDiskRequestSenseKeys (
389 SCSI_DISK_DEV
*ScsiDiskDevice
,
391 EFI_SCSI_SENSE_DATA
**SenseDataArray
,
392 UINTN
*NumberOfSenseKeys
,
393 BOOLEAN AskResetIfError
399 Retrieve all sense keys from the device.
400 When encountering error during the process,
401 if retrieve sense keys before error encounterred,
402 return the sense keys with return status set to EFI_SUCCESS,
403 and NeedRetry set to FALSE; otherwize, return the proper return
408 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
409 NeedRetry - The pointer of flag indicates if need a retry
410 SenseDataArray - The pointer of an array of sense data
411 NumberOfSenseKeys - The number of sense key
412 AskResetIfError - The flag indicates if need reset when error occurs
416 EFI_DEVICE_ERROR - Indicates that error occurs
417 EFI_SUCCESS - Successfully to request sense key
423 ScsiDiskInquiryDevice (
424 SCSI_DISK_DEV
*ScsiDiskDevice
,
431 Send out Inquiry command to Device
435 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
436 NeedRetry - Indicates if needs try again when error happens
440 EFI_DEVICE_ERROR - Indicates that error occurs
441 EFI_SUCCESS - Successfully to detect media
448 SCSI_DISK_DEV
*ScsiDiskDevice
458 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
468 ScsiDiskReadSectors (
469 SCSI_DISK_DEV
*ScsiDiskDevice
,
478 Read sector from SCSI Disk
482 ScsiDiskDevice - The poiniter of SCSI_DISK_DEV
483 Buffer - The buffer to fill in the read out data
484 Lba - Logic block address
485 NumberOfBlocks - The number of blocks to read
496 ScsiDiskWriteSectors (
497 SCSI_DISK_DEV
*ScsiDiskDevice
,
506 Write SCSI Disk sectors
510 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
511 Buffer - The data buffer to write sector
512 Lba - Logic block address
513 NumberOfBlocks - The number of blocks to write
525 SCSI_DISK_DEV
*ScsiDiskDevice
,
527 EFI_SCSI_SENSE_DATA
**SenseDataArray
,
528 UINTN
*NumberOfSenseKeys
,
543 ScsiDiskDevice - The pointer of ScsiDiskDevice
544 NeedRetry - The pointer of flag indicates if needs retry if error happens
545 SenseDataArray - The pointer of an array of sense data
546 NumberOfSenseKeys - The number of sense key
547 Timeout - The time to complete the command
548 DataBuffer - The buffer to fill with the read out data
549 DataLength - The length of buffer
550 StartLba - The start logic block address
551 SectorSize - The size of sector
562 SCSI_DISK_DEV
*ScsiDiskDevice
,
564 EFI_SCSI_SENSE_DATA
**SenseDataArray
,
565 UINTN
*NumberOfSenseKeys
,
580 ScsiDiskDevice - The pointer of ScsiDiskDevice
581 NeedRetry - The pointer of flag indicates if needs retry if error happens
582 SenseDataArray - The pointer of an array of sense data
583 NumberOfSenseKeys - The number of sense key
584 Timeout - The time to complete the command
585 DataBuffer - The buffer to fill with the read out data
586 DataLength - The length of buffer
587 StartLba - The start logic block address
588 SectorSize - The size of sector
599 SCSI_DISK_DEV
*ScsiDiskDevice
,
600 EFI_SCSI_DISK_CAPACITY_DATA
*Capacity
606 Get information from media read capacity command
610 ScsiDiskDevice - The pointer of SCSI_DISK_DEV
611 Capacity - The pointer of EFI_SCSI_DISK_CAPACITY_DATA
622 IN EFI_SCSI_SENSE_DATA
*SenseData
,
629 Check sense key to find if media presents
633 SenseData - The pointer of EFI_SCSI_SENSE_DATA
634 SenseCounts - The number of sense key
644 ScsiDiskIsMediaError (
645 IN EFI_SCSI_SENSE_DATA
*SenseData
,
656 SenseData - The pointer of EFI_SCSI_SENSE_DATA
657 SenseCounts - The number of sense key
667 ScsiDiskIsHardwareError (
668 IN EFI_SCSI_SENSE_DATA
*SenseData
,
675 Check sense key to find if hardware error happens
679 SenseData - The pointer of EFI_SCSI_SENSE_DATA
680 SenseCounts - The number of sense key
690 ScsiDiskIsMediaChange (
691 IN EFI_SCSI_SENSE_DATA
*SenseData
,
700 Check sense key to find if media has changed
704 SenseData - The pointer of EFI_SCSI_SENSE_DATA
705 SenseCounts - The number of sense key
715 ScsiDiskIsResetBefore (
716 IN EFI_SCSI_SENSE_DATA
*SenseData
,
723 Check sense key to find if reset happens
727 SenseData - The pointer of EFI_SCSI_SENSE_DATA
728 SenseCounts - The number of sense key
738 ScsiDiskIsDriveReady (
739 IN EFI_SCSI_SENSE_DATA
*SenseData
,
740 IN UINTN SenseCounts
,
741 OUT BOOLEAN
*NeedRetry
747 Check sense key to find if the drive is ready
751 SenseData - The pointer of EFI_SCSI_SENSE_DATA
752 SenseCounts - The number of sense key
753 RetryLater - The flag means if need a retry
763 ScsiDiskHaveSenseKey (
764 IN EFI_SCSI_SENSE_DATA
*SenseData
,
771 Check sense key to find if it has sense key
775 SenseData - The pointer of EFI_SCSI_SENSE_DATA
776 SenseCounts - The number of sense key
786 ReleaseScsiDiskDeviceResources (
787 IN SCSI_DISK_DEV
*ScsiDiskDevice
793 Release resource about disk device
797 ScsiDiskDevice - The pointer of SCSI_DISK_DEV