1 /** @file
2   Header file for SCSI Disk Driver.
3 
4 Copyright (c) 2004 - 2016, 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/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>
31 
32 
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>
41 
42 #include <IndustryStandard/Scsi.h>
43 #include <IndustryStandard/Atapi.h>
44 
45 #define IS_DEVICE_FIXED(a)        (a)->FixedDevice ? 1 : 0
46 
47 typedef struct {
48   UINT32                    MaxLbaCnt;
49   UINT32                    MaxBlkDespCnt;
50   UINT32                    GranularityAlignment;
51 } SCSI_UNMAP_PARAM_INFO;
52 
53 #define SCSI_DISK_DEV_SIGNATURE SIGNATURE_32 ('s', 'c', 'd', 'k')
54 
55 typedef struct {
56   UINT32                    Signature;
57 
58   EFI_HANDLE                Handle;
59 
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;
65   UINT8                     DeviceType;
66   BOOLEAN                   FixedDevice;
67   UINT16                    Reserved;
68 
69   EFI_SCSI_SENSE_DATA       *SenseData;
70   UINTN                     SenseDataNumber;
71   EFI_SCSI_INQUIRY_DATA     InquiryData;
72 
73   EFI_UNICODE_STRING_TABLE  *ControllerNameTable;
74 
75   EFI_DISK_INFO_PROTOCOL    DiskInfo;
76 
77   //
78   // The following fields are only valid for ATAPI/SATA device
79   //
80   UINT32                    Channel;
81   UINT32                    Device;
82   ATAPI_IDENTIFY_DATA       IdentifyData;
83 
84   //
85   // Scsi UNMAP command parameters information
86   //
87   SCSI_UNMAP_PARAM_INFO     UnmapInfo;
88   BOOLEAN                   BlockLimitsVpdSupported;
89 
90   //
91   // The flag indicates if 16-byte command can be used
92   //
93   BOOLEAN                   Cdb16Byte;
94 
95   //
96   // The queue for asynchronous task requests
97   //
98   LIST_ENTRY                AsyncTaskQueue;
99 } SCSI_DISK_DEV;
100 
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)
104 
105 #define SCSI_DISK_DEV_FROM_DISKINFO(a) CR (a, SCSI_DISK_DEV, DiskInfo, SCSI_DISK_DEV_SIGNATURE)
106 
107 //
108 // Asynchronous I/O request
109 //
110 //
111 // Private data structure for a BlockIo2 request
112 //
113 typedef struct {
114   EFI_BLOCK_IO2_TOKEN                  *Token;
115   //
116   // The flag indicates if the last Scsi Read/Write sub-task for a BlockIo2
117   // request is sent to device
118   //
119   BOOLEAN                              LastScsiRW;
120 
121   //
122   // The queue for Scsi Read/Write sub-tasks of a BlockIo2 request
123   //
124   LIST_ENTRY                           ScsiRWQueue;
125 
126   LIST_ENTRY                           Link;
127 } SCSI_BLKIO2_REQUEST;
128 
129 //
130 // Private data structure for a SCSI Read/Write request
131 //
132 typedef struct {
133   SCSI_DISK_DEV                        *ScsiDiskDevice;
134   UINT64                               Timeout;
135   EFI_SCSI_SENSE_DATA                  *SenseData;
136   UINT8                                SenseDataLength;
137   UINT8                                HostAdapterStatus;
138   UINT8                                TargetStatus;
139   UINT8                                *InBuffer;
140   UINT8                                *OutBuffer;
141   UINT32                               DataLength;
142   UINT64                               StartLba;
143   UINT32                               SectorCount;
144   UINT8                                TimesRetry;
145 
146   //
147   // The BlockIo2 request this SCSI command belongs to
148   //
149   SCSI_BLKIO2_REQUEST                  *BlkIo2Req;
150 
151   LIST_ENTRY                           Link;
152 } SCSI_ASYNC_RW_REQUEST;
153 
154 //
155 // Private data structure for an EraseBlock request
156 //
157 typedef struct {
158   EFI_ERASE_BLOCK_TOKEN                *Token;
159 
160   EFI_SCSI_IO_SCSI_REQUEST_PACKET      CommandPacket;
161 
162   LIST_ENTRY                           Link;
163 } SCSI_ERASEBLK_REQUEST;
164 
165 //
166 // Global Variables
167 //
168 extern EFI_DRIVER_BINDING_PROTOCOL   gScsiDiskDriverBinding;
169 extern EFI_COMPONENT_NAME_PROTOCOL   gScsiDiskComponentName;
170 extern EFI_COMPONENT_NAME2_PROTOCOL  gScsiDiskComponentName2;
171 //
172 // action code used in detect media process
173 //
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
178 
179 #define SCSI_COMMAND_VERSION_1      0x01
180 #define SCSI_COMMAND_VERSION_2      0x02
181 #define SCSI_COMMAND_VERSION_3      0x03
182 
183 //
184 // SCSI Disk Timeout Experience Value
185 //
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.
189 //
190 #define SCSI_DISK_TIMEOUT           EFI_TIMER_PERIOD_SECONDS (30)
191 
192 /**
193   Test to see if this driver supports ControllerHandle.
194 
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.
200 
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
204                               device to start.
205 
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
209 
210 **/
211 EFI_STATUS
212 EFIAPI
213 ScsiDiskDriverBindingSupported (
214   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
215   IN EFI_HANDLE                   Controller,
216   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath   OPTIONAL
217   );
218 
219 /**
220   Start this driver on ControllerHandle.
221 
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
226   restrictions.
227 
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
231                                device to start.
232 
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
236 
237 **/
238 EFI_STATUS
239 EFIAPI
240 ScsiDiskDriverBindingStart (
241   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
242   IN EFI_HANDLE                   Controller,
243   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath   OPTIONAL
244   );
245 
246 /**
247   Stop this driver on ControllerHandle.
248 
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.
254 
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.
260 
261   @retval EFI_SUCCESS       This driver is removed ControllerHandle
262   @retval other             This driver was not removed from this device
263 
264 **/
265 EFI_STATUS
266 EFIAPI
267 ScsiDiskDriverBindingStop (
268   IN  EFI_DRIVER_BINDING_PROTOCOL     *This,
269   IN  EFI_HANDLE                      Controller,
270   IN  UINTN                           NumberOfChildren,
271   IN  EFI_HANDLE                      *ChildHandleBuffer   OPTIONAL
272   );
273 
274 //
275 // EFI Component Name Functions
276 //
277 /**
278   Retrieves a Unicode string that is the user readable name of the driver.
279 
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.
286 
287   @param  This                  A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
288                                 EFI_COMPONENT_NAME_PROTOCOL instance.
289 
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.
298 
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.
303 
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.
307 
308   @retval EFI_INVALID_PARAMETER Language is NULL.
309 
310   @retval EFI_INVALID_PARAMETER DriverName is NULL.
311 
312   @retval EFI_UNSUPPORTED       The driver specified by This does not support
313                                 the language specified by Language.
314 
315 **/
316 EFI_STATUS
317 EFIAPI
318 ScsiDiskComponentNameGetDriverName (
319   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
320   IN  CHAR8                        *Language,
321   OUT CHAR16                       **DriverName
322   );
323 
324 
325 /**
326   Retrieves a Unicode string that is the user readable name of the controller
327   that is being managed by a driver.
328 
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.
337 
338   @param  This                  A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
339                                 EFI_COMPONENT_NAME_PROTOCOL instance.
340 
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
344                                 returned.
345 
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
353                                 child controller.
354 
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.
363 
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
369                                 specified by This.
370 
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
374                                 DriverName.
375 
376   @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
377 
378   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
379                                 EFI_HANDLE.
380 
381   @retval EFI_INVALID_PARAMETER Language is NULL.
382 
383   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
384 
385   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
386                                 managing the controller specified by
387                                 ControllerHandle and ChildHandle.
388 
389   @retval EFI_UNSUPPORTED       The driver specified by This does not support
390                                 the language specified by Language.
391 
392 **/
393 EFI_STATUS
394 EFIAPI
395 ScsiDiskComponentNameGetControllerName (
396   IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,
397   IN  EFI_HANDLE                                      ControllerHandle,
398   IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,
399   IN  CHAR8                                           *Language,
400   OUT CHAR16                                          **ControllerName
401   );
402 
403 /**
404   Reset SCSI Disk.
405 
406 
407   @param  This                 The pointer of EFI_BLOCK_IO_PROTOCOL
408   @param  ExtendedVerification The flag about if extend verificate
409 
410   @retval EFI_SUCCESS          The device was reset.
411   @retval EFI_DEVICE_ERROR     The device is not functioning properly and could
412                                not be reset.
413   @return EFI_STATUS is retured from EFI_SCSI_IO_PROTOCOL.ResetDevice().
414 
415 **/
416 EFI_STATUS
417 EFIAPI
418 ScsiDiskReset (
419   IN  EFI_BLOCK_IO_PROTOCOL   *This,
420   IN  BOOLEAN                 ExtendedVerification
421   );
422 
423 
424 /**
425   The function is to Read Block from SCSI Disk.
426 
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
432 
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.
439 
440 **/
441 EFI_STATUS
442 EFIAPI
443 ScsiDiskReadBlocks (
444   IN  EFI_BLOCK_IO_PROTOCOL   *This,
445   IN  UINT32                  MediaId,
446   IN  EFI_LBA                 Lba,
447   IN  UINTN                   BufferSize,
448   OUT VOID                    *Buffer
449   );
450 
451 
452 /**
453   The function is to Write Block to SCSI Disk.
454 
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
460 
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.
468 
469 **/
470 EFI_STATUS
471 EFIAPI
472 ScsiDiskWriteBlocks (
473   IN  EFI_BLOCK_IO_PROTOCOL   *This,
474   IN  UINT32                  MediaId,
475   IN  EFI_LBA                 Lba,
476   IN  UINTN                   BufferSize,
477   IN  VOID                    *Buffer
478   );
479 
480 
481 /**
482   Flush Block to Disk.
483 
484   EFI_SUCCESS is returned directly.
485 
486   @param  This              The pointer of EFI_BLOCK_IO_PROTOCOL
487 
488   @retval EFI_SUCCESS       All outstanding data was written to the device
489 
490 **/
491 EFI_STATUS
492 EFIAPI
493 ScsiDiskFlushBlocks (
494   IN  EFI_BLOCK_IO_PROTOCOL   *This
495   );
496 
497 
498 /**
499   Reset SCSI Disk.
500 
501   @param  This                 The pointer of EFI_BLOCK_IO2_PROTOCOL.
502   @param  ExtendedVerification The flag about if extend verificate.
503 
504   @retval EFI_SUCCESS          The device was reset.
505   @retval EFI_DEVICE_ERROR     The device is not functioning properly and could
506                                not be reset.
507   @return EFI_STATUS is returned from EFI_SCSI_IO_PROTOCOL.ResetDevice().
508 
509 **/
510 EFI_STATUS
511 EFIAPI
512 ScsiDiskResetEx (
513   IN  EFI_BLOCK_IO2_PROTOCOL  *This,
514   IN  BOOLEAN                 ExtendedVerification
515   );
516 
517 /**
518   The function is to Read Block from SCSI Disk.
519 
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.
526 
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
538                                 alignment.
539   @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a
540                                 lack of resources.
541 
542 **/
543 EFI_STATUS
544 EFIAPI
545 ScsiDiskReadBlocksEx (
546   IN     EFI_BLOCK_IO2_PROTOCOL   *This,
547   IN     UINT32                   MediaId,
548   IN     EFI_LBA                  Lba,
549   IN OUT EFI_BLOCK_IO2_TOKEN      *Token,
550   IN     UINTN                    BufferSize,
551   OUT    VOID                     *Buffer
552   );
553 
554 /**
555   The function is to Write Block to SCSI Disk.
556 
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.
563 
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
574                                 alignment.
575 
576 **/
577 EFI_STATUS
578 EFIAPI
579 ScsiDiskWriteBlocksEx (
580   IN     EFI_BLOCK_IO2_PROTOCOL *This,
581   IN     UINT32                 MediaId,
582   IN     EFI_LBA                Lba,
583   IN OUT EFI_BLOCK_IO2_TOKEN    *Token,
584   IN     UINTN                  BufferSize,
585   IN     VOID                   *Buffer
586   );
587 
588 /**
589   Flush the Block Device.
590 
591   @param  This       Indicates a pointer to the calling context.
592   @param  Token      A pointer to the token associated with the transaction.
593 
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
596                               write data.
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.
600 
601 **/
602 EFI_STATUS
603 EFIAPI
604 ScsiDiskFlushBlocksEx (
605   IN     EFI_BLOCK_IO2_PROTOCOL  *This,
606   IN OUT EFI_BLOCK_IO2_TOKEN     *Token
607   );
608 
609 /**
610   Erase a specified number of device blocks.
611 
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
618                                   transaction.
619   @param[in]       Size           The size in bytes to be erased. This must be
620                                   a multiple of the physical block size of the
621                                   device.
622 
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
627                                   protection.
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
631                                   valid.
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.
634 
635 **/
636 EFI_STATUS
637 EFIAPI
638 ScsiDiskEraseBlocks (
639   IN     EFI_ERASE_BLOCK_PROTOCOL      *This,
640   IN     UINT32                        MediaId,
641   IN     EFI_LBA                       Lba,
642   IN OUT EFI_ERASE_BLOCK_TOKEN         *Token,
643   IN     UINTN                         Size
644   );
645 
646 
647 /**
648   Provides inquiry information for the controller type.
649 
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.
652 
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.
656 
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
661 
662 **/
663 EFI_STATUS
664 EFIAPI
665 ScsiDiskInfoInquiry (
666   IN     EFI_DISK_INFO_PROTOCOL   *This,
667   IN OUT VOID                     *InquiryData,
668   IN OUT UINT32                   *InquiryDataSize
669   );
670 
671 
672 /**
673   Provides identify information for the controller type.
674 
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.
677 
678   @param[in]     This               Pointer to the EFI_DISK_INFO_PROTOCOL
679                                     instance.
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
682                                     size.
683 
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
688 
689 **/
690 EFI_STATUS
691 EFIAPI
692 ScsiDiskInfoIdentify (
693   IN     EFI_DISK_INFO_PROTOCOL   *This,
694   IN OUT VOID                     *IdentifyData,
695   IN OUT UINT32                   *IdentifyDataSize
696   );
697 
698 
699 /**
700   Provides sense data information for the controller type.
701 
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.
704 
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.
709 
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.
714 
715 **/
716 EFI_STATUS
717 EFIAPI
718 ScsiDiskInfoSenseData (
719   IN     EFI_DISK_INFO_PROTOCOL   *This,
720   IN OUT VOID                     *SenseData,
721   IN OUT UINT32                   *SenseDataSize,
722   OUT    UINT8                    *SenseDataNumber
723   );
724 
725 /**
726   This function is used by the IDE bus driver to get controller information.
727 
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.
731 
732   @retval EFI_SUCCESS       IdeChannel and IdeDevice are valid.
733   @retval EFI_UNSUPPORTED   This is not an IDE device.
734 
735 **/
736 EFI_STATUS
737 EFIAPI
738 ScsiDiskInfoWhichIde (
739   IN  EFI_DISK_INFO_PROTOCOL   *This,
740   OUT UINT32                   *IdeChannel,
741   OUT UINT32                   *IdeDevice
742   );
743 
744 
745 /**
746   Detect Device and read out capacity ,if error occurs, parse the sense key.
747 
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
751 
752   @retval EFI_DEVICE_ERROR  Indicates that error occurs
753   @retval EFI_SUCCESS       Successfully to detect media
754 
755 **/
756 EFI_STATUS
757 ScsiDiskDetectMedia (
758   IN   SCSI_DISK_DEV   *ScsiDiskDevice,
759   IN   BOOLEAN         MustReadCapacity,
760   OUT  BOOLEAN         *MediaChange
761   );
762 
763 /**
764   To test device.
765 
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.
769 
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
774 
775   @retval EFI_DEVICE_ERROR   Indicates that error occurs
776   @retval EFI_SUCCESS        Successfully to test unit
777 
778 **/
779 EFI_STATUS
780 ScsiDiskTestUnitReady (
781   IN  SCSI_DISK_DEV         *ScsiDiskDevice,
782   OUT BOOLEAN               *NeedRetry,
783   OUT EFI_SCSI_SENSE_DATA   **SenseDataArray,
784   OUT UINTN                 *NumberOfSenseKeys
785   );
786 
787 
788 /**
789   Parsing Sense Keys which got from request sense command.
790 
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
795 
796   @retval EFI_DEVICE_ERROR   Indicates that error occurs
797   @retval EFI_SUCCESS        Successfully to complete the parsing
798 
799 **/
800 EFI_STATUS
801 DetectMediaParsingSenseKeys (
802   OUT  SCSI_DISK_DEV           *ScsiDiskDevice,
803   IN   EFI_SCSI_SENSE_DATA     *SenseData,
804   IN   UINTN                   NumberOfSenseKeys,
805   OUT  UINTN                   *Action
806   );
807 
808 
809 /**
810   Send read capacity command to device and get the device parameter.
811 
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
816 
817   @retval EFI_DEVICE_ERROR   Indicates that error occurs
818   @retval EFI_SUCCESS        Successfully to read capacity
819 
820 **/
821 EFI_STATUS
822 ScsiDiskReadCapacity (
823   IN  OUT  SCSI_DISK_DEV           *ScsiDiskDevice,
824       OUT  BOOLEAN                 *NeedRetry,
825       OUT  EFI_SCSI_SENSE_DATA     **SenseDataArray,
826       OUT  UINTN                   *NumberOfSenseKeys
827   );
828 
829 /**
830   Check the HostAdapter status and re-interpret it in EFI_STATUS.
831 
832   @param  HostAdapterStatus  Host Adapter status
833 
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.
838 
839 **/
840 EFI_STATUS
841 CheckHostAdapterStatus (
842   IN UINT8   HostAdapterStatus
843   );
844 
845 
846 /**
847   Check the target status and re-interpret it in EFI_STATUS.
848 
849   @param  TargetStatus  Target status
850 
851   @retval EFI_NOT_READY       Device is NOT ready.
852   @retval EFI_DEVICE_ERROR
853   @retval EFI_SUCCESS
854 
855 **/
856 EFI_STATUS
857 CheckTargetStatus (
858   IN  UINT8   TargetStatus
859   );
860 
861 /**
862   Retrieve all sense keys from the device.
863 
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.
867 
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
873 
874   @retval EFI_DEVICE_ERROR   Indicates that error occurs
875   @retval EFI_SUCCESS        Successfully to request sense key
876 
877 **/
878 EFI_STATUS
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
885   );
886 
887 /**
888   Send out Inquiry command to Device.
889 
890   @param  ScsiDiskDevice  The pointer of SCSI_DISK_DEV
891   @param  NeedRetry       Indicates if needs try again when error happens
892 
893   @retval  EFI_DEVICE_ERROR  Indicates that error occurs
894   @retval  EFI_SUCCESS       Successfully to detect media
895 
896 **/
897 EFI_STATUS
898 ScsiDiskInquiryDevice (
899   IN OUT  SCSI_DISK_DEV   *ScsiDiskDevice,
900      OUT  BOOLEAN         *NeedRetry
901   );
902 
903 /**
904   Parse Inquiry data.
905 
906   @param  ScsiDiskDevice  The pointer of SCSI_DISK_DEV
907 
908 **/
909 VOID
910 ParseInquiryData (
911   IN OUT SCSI_DISK_DEV   *ScsiDiskDevice
912   );
913 
914 /**
915   Read sector from SCSI Disk.
916 
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
921 
922   @retval EFI_DEVICE_ERROR  Indicates a device error.
923   @retval EFI_SUCCESS       Operation is successful.
924 
925 **/
926 EFI_STATUS
927 ScsiDiskReadSectors (
928   IN   SCSI_DISK_DEV     *ScsiDiskDevice,
929   OUT  VOID              *Buffer,
930   IN   EFI_LBA           Lba,
931   IN   UINTN             NumberOfBlocks
932   );
933 
934 /**
935   Write sector to SCSI Disk.
936 
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
941 
942   @retval EFI_DEVICE_ERROR  Indicates a device error.
943   @retval EFI_SUCCESS       Operation is successful.
944 
945 **/
946 EFI_STATUS
947 ScsiDiskWriteSectors (
948   IN  SCSI_DISK_DEV     *ScsiDiskDevice,
949   IN  VOID              *Buffer,
950   IN  EFI_LBA           Lba,
951   IN  UINTN             NumberOfBlocks
952   );
953 
954 /**
955   Asynchronously read sector from SCSI Disk.
956 
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.
963 
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.
967 
968 **/
969 EFI_STATUS
970 ScsiDiskAsyncReadSectors (
971   IN   SCSI_DISK_DEV         *ScsiDiskDevice,
972   OUT  VOID                  *Buffer,
973   IN   EFI_LBA               Lba,
974   IN   UINTN                 NumberOfBlocks,
975   IN   EFI_BLOCK_IO2_TOKEN   *Token
976   );
977 
978 /**
979   Asynchronously write sector to SCSI Disk.
980 
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.
987 
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.
991 
992 **/
993 EFI_STATUS
994 ScsiDiskAsyncWriteSectors (
995   IN  SCSI_DISK_DEV          *ScsiDiskDevice,
996   IN  VOID                   *Buffer,
997   IN  EFI_LBA                Lba,
998   IN  UINTN                  NumberOfBlocks,
999   IN  EFI_BLOCK_IO2_TOKEN    *Token
1000   );
1001 
1002 /**
1003   Submit Read(10) command.
1004 
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
1012 
1013   @return  EFI_STATUS is returned by calling ScsiRead10Command().
1014 **/
1015 EFI_STATUS
1016 ScsiDiskRead10 (
1017   IN     SCSI_DISK_DEV         *ScsiDiskDevice,
1018      OUT BOOLEAN               *NeedRetry,
1019   IN     UINT64                Timeout,
1020      OUT UINT8                 *DataBuffer,
1021   IN OUT UINT32                *DataLength,
1022   IN     UINT32                StartLba,
1023   IN     UINT32                SectorCount
1024   );
1025 
1026 /**
1027   Submit Write(10) Command.
1028 
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
1036 
1037   @return  EFI_STATUS is returned by calling ScsiWrite10Command().
1038 
1039 **/
1040 EFI_STATUS
1041 ScsiDiskWrite10 (
1042   IN     SCSI_DISK_DEV         *ScsiDiskDevice,
1043      OUT BOOLEAN               *NeedRetry,
1044   IN     UINT64                Timeout,
1045   IN     UINT8                 *DataBuffer,
1046   IN OUT UINT32                *DataLength,
1047   IN     UINT32                StartLba,
1048   IN     UINT32                SectorCount
1049   );
1050 
1051 /**
1052   Submit Read(16) command.
1053 
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
1061 
1062   @return  EFI_STATUS is returned by calling ScsiRead16Command().
1063 **/
1064 EFI_STATUS
1065 ScsiDiskRead16 (
1066   IN     SCSI_DISK_DEV         *ScsiDiskDevice,
1067      OUT BOOLEAN               *NeedRetry,
1068   IN     UINT64                Timeout,
1069      OUT UINT8                 *DataBuffer,
1070   IN OUT UINT32                *DataLength,
1071   IN     UINT64                StartLba,
1072   IN     UINT32                SectorCount
1073   );
1074 
1075 /**
1076   Submit Write(16) Command.
1077 
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
1085 
1086   @return  EFI_STATUS is returned by calling ScsiWrite16Command().
1087 
1088 **/
1089 EFI_STATUS
1090 ScsiDiskWrite16 (
1091   IN     SCSI_DISK_DEV         *ScsiDiskDevice,
1092      OUT BOOLEAN               *NeedRetry,
1093   IN     UINT64                Timeout,
1094   IN     UINT8                 *DataBuffer,
1095   IN OUT UINT32                *DataLength,
1096   IN     UINT64                StartLba,
1097   IN     UINT32                SectorCount
1098   );
1099 
1100 /**
1101   Submit Async Read(10) command.
1102 
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.
1113 
1114   @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a
1115                                 lack of resources.
1116   @return others                Status returned by calling
1117                                 ScsiRead10CommandEx().
1118 
1119 **/
1120 EFI_STATUS
1121 ScsiDiskAsyncRead10 (
1122   IN     SCSI_DISK_DEV         *ScsiDiskDevice,
1123   IN     UINT64                Timeout,
1124   IN     UINT8                 TimesRetry,
1125      OUT UINT8                 *DataBuffer,
1126   IN     UINT32                DataLength,
1127   IN     UINT32                StartLba,
1128   IN     UINT32                SectorCount,
1129   IN OUT SCSI_BLKIO2_REQUEST   *BlkIo2Req,
1130   IN     EFI_BLOCK_IO2_TOKEN   *Token
1131   );
1132 
1133 /**
1134   Submit Async Write(10) command.
1135 
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.
1146 
1147   @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a
1148                                 lack of resources.
1149   @return others                Status returned by calling
1150                                 ScsiWrite10CommandEx().
1151 
1152 **/
1153 EFI_STATUS
1154 ScsiDiskAsyncWrite10 (
1155   IN     SCSI_DISK_DEV         *ScsiDiskDevice,
1156   IN     UINT64                Timeout,
1157   IN     UINT8                 TimesRetry,
1158   IN     UINT8                 *DataBuffer,
1159   IN     UINT32                DataLength,
1160   IN     UINT32                StartLba,
1161   IN     UINT32                SectorCount,
1162   IN OUT SCSI_BLKIO2_REQUEST   *BlkIo2Req,
1163   IN     EFI_BLOCK_IO2_TOKEN   *Token
1164   );
1165 
1166 /**
1167   Submit Async Read(16) command.
1168 
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.
1179 
1180   @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a
1181                                 lack of resources.
1182   @return others                Status returned by calling
1183                                 ScsiRead16CommandEx().
1184 
1185 **/
1186 EFI_STATUS
1187 ScsiDiskAsyncRead16 (
1188   IN     SCSI_DISK_DEV         *ScsiDiskDevice,
1189   IN     UINT64                Timeout,
1190   IN     UINT8                 TimesRetry,
1191      OUT UINT8                 *DataBuffer,
1192   IN     UINT32                DataLength,
1193   IN     UINT64                StartLba,
1194   IN     UINT32                SectorCount,
1195   IN OUT SCSI_BLKIO2_REQUEST   *BlkIo2Req,
1196   IN     EFI_BLOCK_IO2_TOKEN   *Token
1197   );
1198 
1199 /**
1200   Submit Async Write(16) command.
1201 
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.
1212 
1213   @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a
1214                                 lack of resources.
1215   @return others                Status returned by calling
1216                                 ScsiWrite16CommandEx().
1217 
1218 **/
1219 EFI_STATUS
1220 ScsiDiskAsyncWrite16 (
1221   IN     SCSI_DISK_DEV         *ScsiDiskDevice,
1222   IN     UINT64                Timeout,
1223   IN     UINT8                 TimesRetry,
1224   IN     UINT8                 *DataBuffer,
1225   IN     UINT32                DataLength,
1226   IN     UINT64                StartLba,
1227   IN     UINT32                SectorCount,
1228   IN OUT SCSI_BLKIO2_REQUEST   *BlkIo2Req,
1229   IN     EFI_BLOCK_IO2_TOKEN   *Token
1230   );
1231 
1232 /**
1233   Get information from media read capacity command.
1234 
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
1238 **/
1239 VOID
1240 GetMediaInfo (
1241   IN OUT SCSI_DISK_DEV                  *ScsiDiskDevice,
1242   IN     EFI_SCSI_DISK_CAPACITY_DATA    *Capacity10,
1243   IN     EFI_SCSI_DISK_CAPACITY_DATA16  *Capacity16
1244   );
1245 
1246 /**
1247   Check sense key to find if media presents.
1248 
1249   @param  SenseData   The pointer of EFI_SCSI_SENSE_DATA
1250   @param  SenseCounts The number of sense key
1251 
1252   @retval TRUE    NOT any media
1253   @retval FALSE   Media presents
1254 **/
1255 BOOLEAN
1256 ScsiDiskIsNoMedia (
1257   IN  EFI_SCSI_SENSE_DATA   *SenseData,
1258   IN  UINTN                 SenseCounts
1259   );
1260 
1261 /**
1262   Parse sense key.
1263 
1264   @param  SenseData    The pointer of EFI_SCSI_SENSE_DATA
1265   @param  SenseCounts  The number of sense key
1266 
1267   @retval TRUE   Error
1268   @retval FALSE  NOT error
1269 
1270 **/
1271 BOOLEAN
1272 ScsiDiskIsMediaError (
1273   IN  EFI_SCSI_SENSE_DATA   *SenseData,
1274   IN  UINTN                 SenseCounts
1275   );
1276 
1277 /**
1278   Check sense key to find if hardware error happens.
1279 
1280   @param  SenseData     The pointer of EFI_SCSI_SENSE_DATA
1281   @param  SenseCounts   The number of sense key
1282 
1283   @retval TRUE  Hardware error exits.
1284   @retval FALSE NO error.
1285 
1286 **/
1287 BOOLEAN
1288 ScsiDiskIsHardwareError (
1289   IN  EFI_SCSI_SENSE_DATA   *SenseData,
1290   IN  UINTN                 SenseCounts
1291   );
1292 
1293 /**
1294   Check sense key to find if media has changed.
1295 
1296   @param  SenseData    The pointer of EFI_SCSI_SENSE_DATA
1297   @param  SenseCounts  The number of sense key
1298 
1299   @retval TRUE   Media is changed.
1300   @retval FALSE  Medit is NOT changed.
1301 **/
1302 BOOLEAN
1303 ScsiDiskIsMediaChange (
1304   IN  EFI_SCSI_SENSE_DATA   *SenseData,
1305   IN  UINTN                 SenseCounts
1306   );
1307 
1308 /**
1309   Check sense key to find if reset happens.
1310 
1311   @param  SenseData    The pointer of EFI_SCSI_SENSE_DATA
1312   @param  SenseCounts  The number of sense key
1313 
1314   @retval TRUE  It is reset before.
1315   @retval FALSE It is NOT reset before.
1316 
1317 **/
1318 BOOLEAN
1319 ScsiDiskIsResetBefore (
1320   IN  EFI_SCSI_SENSE_DATA   *SenseData,
1321   IN  UINTN                 SenseCounts
1322   );
1323 
1324 /**
1325   Check sense key to find if the drive is ready.
1326 
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
1330 
1331   @retval TRUE  Drive is ready.
1332   @retval FALSE Drive is NOT ready.
1333 
1334 **/
1335 BOOLEAN
1336 ScsiDiskIsDriveReady (
1337   IN  EFI_SCSI_SENSE_DATA   *SenseData,
1338   IN  UINTN                 SenseCounts,
1339   OUT BOOLEAN               *RetryLater
1340   );
1341 
1342 /**
1343   Check sense key to find if it has sense key.
1344 
1345   @param  SenseData   - The pointer of EFI_SCSI_SENSE_DATA
1346   @param  SenseCounts - The number of sense key
1347 
1348   @retval TRUE  It has sense key.
1349   @retval FALSE It has NOT any sense key.
1350 
1351 **/
1352 BOOLEAN
1353 ScsiDiskHaveSenseKey (
1354   IN  EFI_SCSI_SENSE_DATA   *SenseData,
1355   IN  UINTN                 SenseCounts
1356   );
1357 
1358 /**
1359   Release resource about disk device.
1360 
1361   @param  ScsiDiskDevice  The pointer of SCSI_DISK_DEV
1362 
1363 **/
1364 VOID
1365 ReleaseScsiDiskDeviceResources (
1366   IN  SCSI_DISK_DEV   *ScsiDiskDevice
1367   );
1368 
1369 /**
1370   Determine if Block Io should be produced.
1371 
1372 
1373   @param  ChildHandle  Child Handle to retrieve Parent information.
1374 
1375   @retval  TRUE    Should produce Block Io.
1376   @retval  FALSE   Should not produce Block Io.
1377 
1378 **/
1379 BOOLEAN
1380 DetermineInstallBlockIo (
1381   IN  EFI_HANDLE      ChildHandle
1382   );
1383 
1384 /**
1385   Initialize the installation of DiskInfo protocol.
1386 
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.
1391 
1392   @param  ScsiDiskDevice  The pointer of SCSI_DISK_DEV.
1393   @param  ChildHandle     Child handle to install DiskInfo protocol.
1394 
1395 **/
1396 VOID
1397 InitializeInstallDiskInfo (
1398   IN  SCSI_DISK_DEV   *ScsiDiskDevice,
1399   IN  EFI_HANDLE      ChildHandle
1400   );
1401 
1402 /**
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.
1408 
1409 
1410   @param  ProtocolGuid   ProtocolGuid pointer.
1411   @param  ChildHandle    Child Handle to retrieve Parent information.
1412 
1413 **/
1414 VOID *
1415 EFIAPI
1416 GetParentProtocol (
1417   IN  EFI_GUID                          *ProtocolGuid,
1418   IN  EFI_HANDLE                        ChildHandle
1419   );
1420 
1421 /**
1422   Determine if EFI Erase Block Protocol should be produced.
1423 
1424   @param   ScsiDiskDevice    The pointer of SCSI_DISK_DEV.
1425   @param   ChildHandle       Handle of device.
1426 
1427   @retval  TRUE    Should produce EFI Erase Block Protocol.
1428   @retval  FALSE   Should not produce EFI Erase Block Protocol.
1429 
1430 **/
1431 BOOLEAN
1432 DetermineInstallEraseBlock (
1433   IN  SCSI_DISK_DEV          *ScsiDiskDevice,
1434   IN  EFI_HANDLE             ChildHandle
1435   );
1436 
1437 #endif
1438