]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h
MdeModulePkg/ScsiDisk: Using back-off algorithm to dynamically adjust transfer length...
[mirror_edk2.git] / MdeModulePkg / Bus / Scsi / ScsiDiskDxe / ScsiDisk.h
1 /** @file
2 Header file for SCSI Disk Driver.
3
4 Copyright (c) 2004 - 2014, 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
9
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.
12
13 **/
14
15 #ifndef _SCSI_DISK_H_
16 #define _SCSI_DISK_H_
17
18
19 #include <Uefi.h>
20
21
22 #include <Protocol/ScsiIo.h>
23 #include <Protocol/ComponentName.h>
24 #include <Protocol/BlockIo.h>
25 #include <Protocol/DriverBinding.h>
26 #include <Protocol/ScsiPassThruExt.h>
27 #include <Protocol/ScsiPassThru.h>
28 #include <Protocol/DiskInfo.h>
29
30
31 #include <Library/DebugLib.h>
32 #include <Library/UefiDriverEntryPoint.h>
33 #include <Library/UefiLib.h>
34 #include <Library/BaseMemoryLib.h>
35 #include <Library/MemoryAllocationLib.h>
36 #include <Library/UefiScsiLib.h>
37 #include <Library/UefiBootServicesTableLib.h>
38 #include <Library/DevicePathLib.h>
39
40 #include <IndustryStandard/Scsi.h>
41 #include <IndustryStandard/Atapi.h>
42
43 #define IS_DEVICE_FIXED(a) (a)->FixedDevice ? 1 : 0
44
45 #define SCSI_DISK_DEV_SIGNATURE SIGNATURE_32 ('s', 'c', 'd', 'k')
46
47 typedef struct {
48 UINT32 Signature;
49
50 EFI_HANDLE Handle;
51
52 EFI_BLOCK_IO_PROTOCOL BlkIo;
53 EFI_BLOCK_IO_MEDIA BlkIoMedia;
54 EFI_SCSI_IO_PROTOCOL *ScsiIo;
55 UINT8 DeviceType;
56 BOOLEAN FixedDevice;
57 UINT16 Reserved;
58
59 EFI_SCSI_SENSE_DATA *SenseData;
60 UINTN SenseDataNumber;
61 EFI_SCSI_INQUIRY_DATA InquiryData;
62
63 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
64
65 EFI_DISK_INFO_PROTOCOL DiskInfo;
66
67 //
68 // The following fields are only valid for ATAPI/SATA device
69 //
70 UINT32 Channel;
71 UINT32 Device;
72 ATAPI_IDENTIFY_DATA IdentifyData;
73
74 //
75 // The flag indicates if 16-byte command can be used
76 //
77 BOOLEAN Cdb16Byte;
78 } SCSI_DISK_DEV;
79
80 #define SCSI_DISK_DEV_FROM_THIS(a) CR (a, SCSI_DISK_DEV, BlkIo, SCSI_DISK_DEV_SIGNATURE)
81
82 #define SCSI_DISK_DEV_FROM_DISKINFO(a) CR (a, SCSI_DISK_DEV, DiskInfo, SCSI_DISK_DEV_SIGNATURE)
83
84 //
85 // Global Variables
86 //
87 extern EFI_DRIVER_BINDING_PROTOCOL gScsiDiskDriverBinding;
88 extern EFI_COMPONENT_NAME_PROTOCOL gScsiDiskComponentName;
89 extern EFI_COMPONENT_NAME2_PROTOCOL gScsiDiskComponentName2;
90 //
91 // action code used in detect media process
92 //
93 #define ACTION_NO_ACTION 0x00
94 #define ACTION_READ_CAPACITY 0x01
95 #define ACTION_RETRY_COMMAND_LATER 0x02
96 #define ACTION_RETRY_WITH_BACKOFF_ALGO 0x03
97
98 #define SCSI_COMMAND_VERSION_1 0x01
99 #define SCSI_COMMAND_VERSION_2 0x02
100 #define SCSI_COMMAND_VERSION_3 0x03
101
102 //
103 // SCSI Disk Timeout Experience Value
104 //
105 #define SCSI_DISK_TIMEOUT EFI_TIMER_PERIOD_SECONDS (3)
106
107 /**
108 Test to see if this driver supports ControllerHandle.
109
110 This service is called by the EFI boot service ConnectController(). In order
111 to make drivers as small as possible, there are a few calling restrictions for
112 this service. ConnectController() must follow these calling restrictions.
113 If any other agent wishes to call Supported() it must also follow these
114 calling restrictions.
115
116 @param This Protocol instance pointer.
117 @param ControllerHandle Handle of device to test
118 @param RemainingDevicePath Optional parameter use to pick a specific child
119 device to start.
120
121 @retval EFI_SUCCESS This driver supports this device
122 @retval EFI_ALREADY_STARTED This driver is already running on this device
123 @retval other This driver does not support this device
124
125 **/
126 EFI_STATUS
127 EFIAPI
128 ScsiDiskDriverBindingSupported (
129 IN EFI_DRIVER_BINDING_PROTOCOL *This,
130 IN EFI_HANDLE Controller,
131 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
132 );
133
134 /**
135 Start this driver on ControllerHandle.
136
137 This service is called by the EFI boot service ConnectController(). In order
138 to make drivers as small as possible, there are a few calling restrictions for
139 this service. ConnectController() must follow these calling restrictions. If
140 any other agent wishes to call Start() it must also follow these calling
141 restrictions.
142
143 @param This Protocol instance pointer.
144 @param ControllerHandle Handle of device to bind driver to
145 @param RemainingDevicePath Optional parameter use to pick a specific child
146 device to start.
147
148 @retval EFI_SUCCESS This driver is added to ControllerHandle
149 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
150 @retval other This driver does not support this device
151
152 **/
153 EFI_STATUS
154 EFIAPI
155 ScsiDiskDriverBindingStart (
156 IN EFI_DRIVER_BINDING_PROTOCOL *This,
157 IN EFI_HANDLE Controller,
158 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
159 );
160
161 /**
162 Stop this driver on ControllerHandle.
163
164 This service is called by the EFI boot service DisconnectController().
165 In order to make drivers as small as possible, there are a few calling
166 restrictions for this service. DisconnectController() must follow these
167 calling restrictions. If any other agent wishes to call Stop() it must
168 also follow these calling restrictions.
169
170 @param This Protocol instance pointer.
171 @param ControllerHandle Handle of device to stop driver on
172 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
173 children is zero stop the entire bus driver.
174 @param ChildHandleBuffer List of Child Handles to Stop.
175
176 @retval EFI_SUCCESS This driver is removed ControllerHandle
177 @retval other This driver was not removed from this device
178
179 **/
180 EFI_STATUS
181 EFIAPI
182 ScsiDiskDriverBindingStop (
183 IN EFI_DRIVER_BINDING_PROTOCOL *This,
184 IN EFI_HANDLE Controller,
185 IN UINTN NumberOfChildren,
186 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
187 );
188
189 //
190 // EFI Component Name Functions
191 //
192 /**
193 Retrieves a Unicode string that is the user readable name of the driver.
194
195 This function retrieves the user readable name of a driver in the form of a
196 Unicode string. If the driver specified by This has a user readable name in
197 the language specified by Language, then a pointer to the driver name is
198 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
199 by This does not support the language specified by Language,
200 then EFI_UNSUPPORTED is returned.
201
202 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
203 EFI_COMPONENT_NAME_PROTOCOL instance.
204
205 @param Language A pointer to a Null-terminated ASCII string
206 array indicating the language. This is the
207 language of the driver name that the caller is
208 requesting, and it must match one of the
209 languages specified in SupportedLanguages. The
210 number of languages supported by a driver is up
211 to the driver writer. Language is specified
212 in RFC 4646 or ISO 639-2 language code format.
213
214 @param DriverName A pointer to the Unicode string to return.
215 This Unicode string is the name of the
216 driver specified by This in the language
217 specified by Language.
218
219 @retval EFI_SUCCESS The Unicode string for the Driver specified by
220 This and the language specified by Language was
221 returned in DriverName.
222
223 @retval EFI_INVALID_PARAMETER Language is NULL.
224
225 @retval EFI_INVALID_PARAMETER DriverName is NULL.
226
227 @retval EFI_UNSUPPORTED The driver specified by This does not support
228 the language specified by Language.
229
230 **/
231 EFI_STATUS
232 EFIAPI
233 ScsiDiskComponentNameGetDriverName (
234 IN EFI_COMPONENT_NAME_PROTOCOL *This,
235 IN CHAR8 *Language,
236 OUT CHAR16 **DriverName
237 );
238
239
240 /**
241 Retrieves a Unicode string that is the user readable name of the controller
242 that is being managed by a driver.
243
244 This function retrieves the user readable name of the controller specified by
245 ControllerHandle and ChildHandle in the form of a Unicode string. If the
246 driver specified by This has a user readable name in the language specified by
247 Language, then a pointer to the controller name is returned in ControllerName,
248 and EFI_SUCCESS is returned. If the driver specified by This is not currently
249 managing the controller specified by ControllerHandle and ChildHandle,
250 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
251 support the language specified by Language, then EFI_UNSUPPORTED is returned.
252
253 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
254 EFI_COMPONENT_NAME_PROTOCOL instance.
255
256 @param ControllerHandle The handle of a controller that the driver
257 specified by This is managing. This handle
258 specifies the controller whose name is to be
259 returned.
260
261 @param ChildHandle The handle of the child controller to retrieve
262 the name of. This is an optional parameter that
263 may be NULL. It will be NULL for device
264 drivers. It will also be NULL for a bus drivers
265 that wish to retrieve the name of the bus
266 controller. It will not be NULL for a bus
267 driver that wishes to retrieve the name of a
268 child controller.
269
270 @param Language A pointer to a Null-terminated ASCII string
271 array indicating the language. This is the
272 language of the driver name that the caller is
273 requesting, and it must match one of the
274 languages specified in SupportedLanguages. The
275 number of languages supported by a driver is up
276 to the driver writer. Language is specified in
277 RFC 4646 or ISO 639-2 language code format.
278
279 @param ControllerName A pointer to the Unicode string to return.
280 This Unicode string is the name of the
281 controller specified by ControllerHandle and
282 ChildHandle in the language specified by
283 Language from the point of view of the driver
284 specified by This.
285
286 @retval EFI_SUCCESS The Unicode string for the user readable name in
287 the language specified by Language for the
288 driver specified by This was returned in
289 DriverName.
290
291 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
292
293 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
294 EFI_HANDLE.
295
296 @retval EFI_INVALID_PARAMETER Language is NULL.
297
298 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
299
300 @retval EFI_UNSUPPORTED The driver specified by This is not currently
301 managing the controller specified by
302 ControllerHandle and ChildHandle.
303
304 @retval EFI_UNSUPPORTED The driver specified by This does not support
305 the language specified by Language.
306
307 **/
308 EFI_STATUS
309 EFIAPI
310 ScsiDiskComponentNameGetControllerName (
311 IN EFI_COMPONENT_NAME_PROTOCOL *This,
312 IN EFI_HANDLE ControllerHandle,
313 IN EFI_HANDLE ChildHandle OPTIONAL,
314 IN CHAR8 *Language,
315 OUT CHAR16 **ControllerName
316 );
317
318 /**
319 Reset SCSI Disk.
320
321
322 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
323 @param ExtendedVerification The flag about if extend verificate
324
325 @retval EFI_SUCCESS The device was reset.
326 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
327 not be reset.
328 @return EFI_STATUS is retured from EFI_SCSI_IO_PROTOCOL.ResetDevice().
329
330 **/
331 EFI_STATUS
332 EFIAPI
333 ScsiDiskReset (
334 IN EFI_BLOCK_IO_PROTOCOL *This,
335 IN BOOLEAN ExtendedVerification
336 );
337
338
339 /**
340 The function is to Read Block from SCSI Disk.
341
342 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
343 @param MediaId The Id of Media detected
344 @param Lba The logic block address
345 @param BufferSize The size of Buffer
346 @param Buffer The buffer to fill the read out data
347
348 @retval EFI_SUCCESS Successfully to read out block.
349 @retval EFI_DEVICE_ERROR Fail to detect media.
350 @retval EFI_NO_MEDIA Media is not present.
351 @retval EFI_MEDIA_CHANGED Media has changed.
352 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
353 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
354
355 **/
356 EFI_STATUS
357 EFIAPI
358 ScsiDiskReadBlocks (
359 IN EFI_BLOCK_IO_PROTOCOL *This,
360 IN UINT32 MediaId,
361 IN EFI_LBA Lba,
362 IN UINTN BufferSize,
363 OUT VOID *Buffer
364 );
365
366
367 /**
368 The function is to Write Block to SCSI Disk.
369
370 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
371 @param MediaId The Id of Media detected
372 @param Lba The logic block address
373 @param BufferSize The size of Buffer
374 @param Buffer The buffer to fill the read out data
375
376 @retval EFI_SUCCESS Successfully to read out block.
377 @retval EFI_WRITE_PROTECTED The device can not be written to.
378 @retval EFI_DEVICE_ERROR Fail to detect media.
379 @retval EFI_NO_MEDIA Media is not present.
380 @retval EFI_MEDIA_CHNAGED Media has changed.
381 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
382 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
383
384 **/
385 EFI_STATUS
386 EFIAPI
387 ScsiDiskWriteBlocks (
388 IN EFI_BLOCK_IO_PROTOCOL *This,
389 IN UINT32 MediaId,
390 IN EFI_LBA Lba,
391 IN UINTN BufferSize,
392 IN VOID *Buffer
393 );
394
395
396 /**
397 Flush Block to Disk.
398
399 EFI_SUCCESS is returned directly.
400
401 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
402
403 @retval EFI_SUCCESS All outstanding data was written to the device
404
405 **/
406 EFI_STATUS
407 EFIAPI
408 ScsiDiskFlushBlocks (
409 IN EFI_BLOCK_IO_PROTOCOL *This
410 );
411
412
413 /**
414 Provides inquiry information for the controller type.
415
416 This function is used by the IDE bus driver to get inquiry data. Data format
417 of Identify data is defined by the Interface GUID.
418
419 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
420 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
421 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
422
423 @retval EFI_SUCCESS The command was accepted without any errors.
424 @retval EFI_NOT_FOUND Device does not support this data class
425 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
426 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
427
428 **/
429 EFI_STATUS
430 EFIAPI
431 ScsiDiskInfoInquiry (
432 IN EFI_DISK_INFO_PROTOCOL *This,
433 IN OUT VOID *InquiryData,
434 IN OUT UINT32 *InquiryDataSize
435 );
436
437
438 /**
439 Provides identify information for the controller type.
440
441 This function is used by the IDE bus driver to get identify data. Data format
442 of Identify data is defined by the Interface GUID.
443
444 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
445 instance.
446 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
447 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
448 size.
449
450 @retval EFI_SUCCESS The command was accepted without any errors.
451 @retval EFI_NOT_FOUND Device does not support this data class
452 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
453 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
454
455 **/
456 EFI_STATUS
457 EFIAPI
458 ScsiDiskInfoIdentify (
459 IN EFI_DISK_INFO_PROTOCOL *This,
460 IN OUT VOID *IdentifyData,
461 IN OUT UINT32 *IdentifyDataSize
462 );
463
464
465 /**
466 Provides sense data information for the controller type.
467
468 This function is used by the IDE bus driver to get sense data.
469 Data format of Sense data is defined by the Interface GUID.
470
471 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
472 @param[in, out] SenseData Pointer to the SenseData.
473 @param[in, out] SenseDataSize Size of SenseData in bytes.
474 @param[out] SenseDataNumber Pointer to the value for the sense data size.
475
476 @retval EFI_SUCCESS The command was accepted without any errors.
477 @retval EFI_NOT_FOUND Device does not support this data class.
478 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
479 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
480
481 **/
482 EFI_STATUS
483 EFIAPI
484 ScsiDiskInfoSenseData (
485 IN EFI_DISK_INFO_PROTOCOL *This,
486 IN OUT VOID *SenseData,
487 IN OUT UINT32 *SenseDataSize,
488 OUT UINT8 *SenseDataNumber
489 );
490
491 /**
492 This function is used by the IDE bus driver to get controller information.
493
494 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
495 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
496 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
497
498 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
499 @retval EFI_UNSUPPORTED This is not an IDE device.
500
501 **/
502 EFI_STATUS
503 EFIAPI
504 ScsiDiskInfoWhichIde (
505 IN EFI_DISK_INFO_PROTOCOL *This,
506 OUT UINT32 *IdeChannel,
507 OUT UINT32 *IdeDevice
508 );
509
510
511 /**
512 Detect Device and read out capacity ,if error occurs, parse the sense key.
513
514 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
515 @param MustReadCapacity The flag about reading device capacity
516 @param MediaChange The pointer of flag indicates if media has changed
517
518 @retval EFI_DEVICE_ERROR Indicates that error occurs
519 @retval EFI_SUCCESS Successfully to detect media
520
521 **/
522 EFI_STATUS
523 ScsiDiskDetectMedia (
524 IN SCSI_DISK_DEV *ScsiDiskDevice,
525 IN BOOLEAN MustReadCapacity,
526 OUT BOOLEAN *MediaChange
527 );
528
529 /**
530 To test device.
531
532 When Test Unit Ready command succeeds, retrieve Sense Keys via Request Sense;
533 When Test Unit Ready command encounters any error caused by host adapter or
534 target, return error without retrieving Sense Keys.
535
536 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
537 @param NeedRetry The pointer of flag indicates try again
538 @param SenseDataArray The pointer of an array of sense data
539 @param NumberOfSenseKeys The pointer of the number of sense data array
540
541 @retval EFI_DEVICE_ERROR Indicates that error occurs
542 @retval EFI_SUCCESS Successfully to test unit
543
544 **/
545 EFI_STATUS
546 ScsiDiskTestUnitReady (
547 IN SCSI_DISK_DEV *ScsiDiskDevice,
548 OUT BOOLEAN *NeedRetry,
549 OUT EFI_SCSI_SENSE_DATA **SenseDataArray,
550 OUT UINTN *NumberOfSenseKeys
551 );
552
553
554 /**
555 Parsing Sense Keys which got from request sense command.
556
557 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
558 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
559 @param NumberOfSenseKeys The number of sense key
560 @param Action The pointer of action which indicates what is need to do next
561
562 @retval EFI_DEVICE_ERROR Indicates that error occurs
563 @retval EFI_SUCCESS Successfully to complete the parsing
564
565 **/
566 EFI_STATUS
567 DetectMediaParsingSenseKeys (
568 OUT SCSI_DISK_DEV *ScsiDiskDevice,
569 IN EFI_SCSI_SENSE_DATA *SenseData,
570 IN UINTN NumberOfSenseKeys,
571 OUT UINTN *Action
572 );
573
574
575 /**
576 Send read capacity command to device and get the device parameter.
577
578 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
579 @param NeedRetry The pointer of flag indicates if need a retry
580 @param SenseDataArray The pointer of an array of sense data
581 @param NumberOfSenseKeys The number of sense key
582
583 @retval EFI_DEVICE_ERROR Indicates that error occurs
584 @retval EFI_SUCCESS Successfully to read capacity
585
586 **/
587 EFI_STATUS
588 ScsiDiskReadCapacity (
589 IN OUT SCSI_DISK_DEV *ScsiDiskDevice,
590 OUT BOOLEAN *NeedRetry,
591 OUT EFI_SCSI_SENSE_DATA **SenseDataArray,
592 OUT UINTN *NumberOfSenseKeys
593 );
594
595 /**
596 Check the HostAdapter status and re-interpret it in EFI_STATUS.
597
598 @param HostAdapterStatus Host Adapter status
599
600 @retval EFI_SUCCESS Host adapter is OK.
601 @retval EFI_TIMEOUT Timeout.
602 @retval EFI_NOT_READY Adapter NOT ready.
603 @retval EFI_DEVICE_ERROR Adapter device error.
604
605 **/
606 EFI_STATUS
607 CheckHostAdapterStatus (
608 IN UINT8 HostAdapterStatus
609 );
610
611
612 /**
613 Check the target status and re-interpret it in EFI_STATUS.
614
615 @param TargetStatus Target status
616
617 @retval EFI_NOT_READY Device is NOT ready.
618 @retval EFI_DEVICE_ERROR
619 @retval EFI_SUCCESS
620
621 **/
622 EFI_STATUS
623 CheckTargetStatus (
624 IN UINT8 TargetStatus
625 );
626
627 /**
628 Retrieve all sense keys from the device.
629
630 When encountering error during the process, if retrieve sense keys before
631 error encountered, it returns the sense keys with return status set to EFI_SUCCESS,
632 and NeedRetry set to FALSE; otherwize, return the proper return status.
633
634 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
635 @param NeedRetry The pointer of flag indicates if need a retry
636 @param SenseDataArray The pointer of an array of sense data
637 @param NumberOfSenseKeys The number of sense key
638 @param AskResetIfError The flag indicates if need reset when error occurs
639
640 @retval EFI_DEVICE_ERROR Indicates that error occurs
641 @retval EFI_SUCCESS Successfully to request sense key
642
643 **/
644 EFI_STATUS
645 ScsiDiskRequestSenseKeys (
646 IN OUT SCSI_DISK_DEV *ScsiDiskDevice,
647 OUT BOOLEAN *NeedRetry,
648 OUT EFI_SCSI_SENSE_DATA **SenseDataArray,
649 OUT UINTN *NumberOfSenseKeys,
650 IN BOOLEAN AskResetIfError
651 );
652
653 /**
654 Send out Inquiry command to Device.
655
656 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
657 @param NeedRetry Indicates if needs try again when error happens
658
659 @retval EFI_DEVICE_ERROR Indicates that error occurs
660 @retval EFI_SUCCESS Successfully to detect media
661
662 **/
663 EFI_STATUS
664 ScsiDiskInquiryDevice (
665 IN OUT SCSI_DISK_DEV *ScsiDiskDevice,
666 OUT BOOLEAN *NeedRetry
667 );
668
669 /**
670 Parse Inquiry data.
671
672 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
673
674 **/
675 VOID
676 ParseInquiryData (
677 IN OUT SCSI_DISK_DEV *ScsiDiskDevice
678 );
679
680 /**
681 Read sector from SCSI Disk.
682
683 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
684 @param Buffer The buffer to fill in the read out data
685 @param Lba Logic block address
686 @param NumberOfBlocks The number of blocks to read
687
688 @retval EFI_DEVICE_ERROR Indicates a device error.
689 @retval EFI_SUCCESS Operation is successful.
690
691 **/
692 EFI_STATUS
693 ScsiDiskReadSectors (
694 IN SCSI_DISK_DEV *ScsiDiskDevice,
695 OUT VOID *Buffer,
696 IN EFI_LBA Lba,
697 IN UINTN NumberOfBlocks
698 );
699
700 /**
701 Write sector to SCSI Disk.
702
703 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
704 @param Buffer The buffer of data to be written into SCSI Disk
705 @param Lba Logic block address
706 @param NumberOfBlocks The number of blocks to read
707
708 @retval EFI_DEVICE_ERROR Indicates a device error.
709 @retval EFI_SUCCESS Operation is successful.
710
711 **/
712 EFI_STATUS
713 ScsiDiskWriteSectors (
714 IN SCSI_DISK_DEV *ScsiDiskDevice,
715 IN VOID *Buffer,
716 IN EFI_LBA Lba,
717 IN UINTN NumberOfBlocks
718 );
719
720 /**
721 Submit Read(10) command.
722
723 @param ScsiDiskDevice The pointer of ScsiDiskDevice
724 @param NeedRetry The pointer of flag indicates if needs retry if error happens
725 @param Timeout The time to complete the command
726 @param DataBuffer The buffer to fill with the read out data
727 @param DataLength The length of buffer
728 @param StartLba The start logic block address
729 @param SectorCount The number of blocks to read
730
731 @return EFI_STATUS is returned by calling ScsiRead10Command().
732 **/
733 EFI_STATUS
734 ScsiDiskRead10 (
735 IN SCSI_DISK_DEV *ScsiDiskDevice,
736 OUT BOOLEAN *NeedRetry,
737 IN UINT64 Timeout,
738 OUT UINT8 *DataBuffer,
739 IN OUT UINT32 *DataLength,
740 IN UINT32 StartLba,
741 IN UINT32 SectorCount
742 );
743
744 /**
745 Submit Write(10) Command.
746
747 @param ScsiDiskDevice The pointer of ScsiDiskDevice
748 @param NeedRetry The pointer of flag indicates if needs retry if error happens
749 @param Timeout The time to complete the command
750 @param DataBuffer The buffer to fill with the read out data
751 @param DataLength The length of buffer
752 @param StartLba The start logic block address
753 @param SectorCount The number of blocks to write
754
755 @return EFI_STATUS is returned by calling ScsiWrite10Command().
756
757 **/
758 EFI_STATUS
759 ScsiDiskWrite10 (
760 IN SCSI_DISK_DEV *ScsiDiskDevice,
761 OUT BOOLEAN *NeedRetry,
762 IN UINT64 Timeout,
763 IN UINT8 *DataBuffer,
764 IN OUT UINT32 *DataLength,
765 IN UINT32 StartLba,
766 IN UINT32 SectorCount
767 );
768
769 /**
770 Submit Read(16) command.
771
772 @param ScsiDiskDevice The pointer of ScsiDiskDevice
773 @param NeedRetry The pointer of flag indicates if needs retry if error happens
774 @param Timeout The time to complete the command
775 @param DataBuffer The buffer to fill with the read out data
776 @param DataLength The length of buffer
777 @param StartLba The start logic block address
778 @param SectorCount The number of blocks to read
779
780 @return EFI_STATUS is returned by calling ScsiRead16Command().
781 **/
782 EFI_STATUS
783 ScsiDiskRead16 (
784 IN SCSI_DISK_DEV *ScsiDiskDevice,
785 OUT BOOLEAN *NeedRetry,
786 IN UINT64 Timeout,
787 OUT UINT8 *DataBuffer,
788 IN OUT UINT32 *DataLength,
789 IN UINT64 StartLba,
790 IN UINT32 SectorCount
791 );
792
793 /**
794 Submit Write(16) Command.
795
796 @param ScsiDiskDevice The pointer of ScsiDiskDevice
797 @param NeedRetry The pointer of flag indicates if needs retry if error happens
798 @param Timeout The time to complete the command
799 @param DataBuffer The buffer to fill with the read out data
800 @param DataLength The length of buffer
801 @param StartLba The start logic block address
802 @param SectorCount The number of blocks to write
803
804 @return EFI_STATUS is returned by calling ScsiWrite16Command().
805
806 **/
807 EFI_STATUS
808 ScsiDiskWrite16 (
809 IN SCSI_DISK_DEV *ScsiDiskDevice,
810 OUT BOOLEAN *NeedRetry,
811 IN UINT64 Timeout,
812 IN UINT8 *DataBuffer,
813 IN OUT UINT32 *DataLength,
814 IN UINT64 StartLba,
815 IN UINT32 SectorCount
816 );
817
818 /**
819 Get information from media read capacity command.
820
821 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
822 @param Capacity10 The pointer of EFI_SCSI_DISK_CAPACITY_DATA
823 @param Capacity16 The pointer of EFI_SCSI_DISK_CAPACITY_DATA16
824 **/
825 VOID
826 GetMediaInfo (
827 IN OUT SCSI_DISK_DEV *ScsiDiskDevice,
828 IN EFI_SCSI_DISK_CAPACITY_DATA *Capacity10,
829 IN EFI_SCSI_DISK_CAPACITY_DATA16 *Capacity16
830 );
831
832 /**
833 Check sense key to find if media presents.
834
835 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
836 @param SenseCounts The number of sense key
837
838 @retval TRUE NOT any media
839 @retval FALSE Media presents
840 **/
841 BOOLEAN
842 ScsiDiskIsNoMedia (
843 IN EFI_SCSI_SENSE_DATA *SenseData,
844 IN UINTN SenseCounts
845 );
846
847 /**
848 Parse sense key.
849
850 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
851 @param SenseCounts The number of sense key
852
853 @retval TRUE Error
854 @retval FALSE NOT error
855
856 **/
857 BOOLEAN
858 ScsiDiskIsMediaError (
859 IN EFI_SCSI_SENSE_DATA *SenseData,
860 IN UINTN SenseCounts
861 );
862
863 /**
864 Check sense key to find if hardware error happens.
865
866 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
867 @param SenseCounts The number of sense key
868
869 @retval TRUE Hardware error exits.
870 @retval FALSE NO error.
871
872 **/
873 BOOLEAN
874 ScsiDiskIsHardwareError (
875 IN EFI_SCSI_SENSE_DATA *SenseData,
876 IN UINTN SenseCounts
877 );
878
879 /**
880 Check sense key to find if media has changed.
881
882 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
883 @param SenseCounts The number of sense key
884
885 @retval TRUE Media is changed.
886 @retval FALSE Medit is NOT changed.
887 **/
888 BOOLEAN
889 ScsiDiskIsMediaChange (
890 IN EFI_SCSI_SENSE_DATA *SenseData,
891 IN UINTN SenseCounts
892 );
893
894 /**
895 Check sense key to find if reset happens.
896
897 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
898 @param SenseCounts The number of sense key
899
900 @retval TRUE It is reset before.
901 @retval FALSE It is NOT reset before.
902
903 **/
904 BOOLEAN
905 ScsiDiskIsResetBefore (
906 IN EFI_SCSI_SENSE_DATA *SenseData,
907 IN UINTN SenseCounts
908 );
909
910 /**
911 Check sense key to find if the drive is ready.
912
913 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
914 @param SenseCounts The number of sense key
915 @param RetryLater The flag means if need a retry
916
917 @retval TRUE Drive is ready.
918 @retval FALSE Drive is NOT ready.
919
920 **/
921 BOOLEAN
922 ScsiDiskIsDriveReady (
923 IN EFI_SCSI_SENSE_DATA *SenseData,
924 IN UINTN SenseCounts,
925 OUT BOOLEAN *RetryLater
926 );
927
928 /**
929 Check sense key to find if it has sense key.
930
931 @param SenseData - The pointer of EFI_SCSI_SENSE_DATA
932 @param SenseCounts - The number of sense key
933
934 @retval TRUE It has sense key.
935 @retval FALSE It has NOT any sense key.
936
937 **/
938 BOOLEAN
939 ScsiDiskHaveSenseKey (
940 IN EFI_SCSI_SENSE_DATA *SenseData,
941 IN UINTN SenseCounts
942 );
943
944 /**
945 Release resource about disk device.
946
947 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
948
949 **/
950 VOID
951 ReleaseScsiDiskDeviceResources (
952 IN SCSI_DISK_DEV *ScsiDiskDevice
953 );
954
955 /**
956 Determine if Block Io should be produced.
957
958
959 @param ChildHandle Child Handle to retrieve Parent information.
960
961 @retval TRUE Should produce Block Io.
962 @retval FALSE Should not produce Block Io.
963
964 **/
965 BOOLEAN
966 DetermineInstallBlockIo (
967 IN EFI_HANDLE ChildHandle
968 );
969
970 /**
971 Initialize the installation of DiskInfo protocol.
972
973 This function prepares for the installation of DiskInfo protocol on the child handle.
974 By default, it installs DiskInfo protocol with SCSI interface GUID. If it further
975 detects that the physical device is an ATAPI/AHCI device, it then updates interface GUID
976 to be IDE/AHCI interface GUID.
977
978 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
979 @param ChildHandle Child handle to install DiskInfo protocol.
980
981 **/
982 VOID
983 InitializeInstallDiskInfo (
984 IN SCSI_DISK_DEV *ScsiDiskDevice,
985 IN EFI_HANDLE ChildHandle
986 );
987
988 /**
989 Search protocol database and check to see if the protocol
990 specified by ProtocolGuid is present on a ControllerHandle and opened by
991 ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
992 If the ControllerHandle is found, then the protocol specified by ProtocolGuid
993 will be opened on it.
994
995
996 @param ProtocolGuid ProtocolGuid pointer.
997 @param ChildHandle Child Handle to retrieve Parent information.
998
999 **/
1000 VOID *
1001 EFIAPI
1002 GetParentProtocol (
1003 IN EFI_GUID *ProtocolGuid,
1004 IN EFI_HANDLE ChildHandle
1005 );
1006
1007 #endif