]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Bus / Scsi / ScsiDiskDxe / ScsiDisk.h
1 /** @file
2 Header file for SCSI Disk Driver.
3
4 Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 1985 - 2022, American Megatrends International LLC.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef _SCSI_DISK_H_
11 #define _SCSI_DISK_H_
12
13 #include <Uefi.h>
14
15 #include <Protocol/ScsiIo.h>
16 #include <Protocol/ComponentName.h>
17 #include <Protocol/BlockIo.h>
18 #include <Protocol/BlockIo2.h>
19 #include <Protocol/EraseBlock.h>
20 #include <Protocol/DriverBinding.h>
21 #include <Protocol/ScsiPassThruExt.h>
22 #include <Protocol/ScsiPassThru.h>
23 #include <Protocol/DiskInfo.h>
24 #include <Protocol/StorageSecurityCommand.h>
25
26 #include <Library/DebugLib.h>
27 #include <Library/UefiDriverEntryPoint.h>
28 #include <Library/UefiLib.h>
29 #include <Library/BaseMemoryLib.h>
30 #include <Library/MemoryAllocationLib.h>
31 #include <Library/UefiScsiLib.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/DevicePathLib.h>
34 #include <Library/PrintLib.h>
35
36 #include <IndustryStandard/Scsi.h>
37 #include <IndustryStandard/Atapi.h>
38
39 #define IS_DEVICE_FIXED(a) (a)->FixedDevice ? 1 : 0
40
41 #define IS_ALIGNED(addr, size) (((UINTN) (addr) & (size - 1)) == 0)
42
43 #define UFS_WLUN_RPMB 0xC4
44
45 typedef struct {
46 UINT32 MaxLbaCnt;
47 UINT32 MaxBlkDespCnt;
48 UINT32 GranularityAlignment;
49 } SCSI_UNMAP_PARAM_INFO;
50
51 #define SCSI_DISK_DEV_SIGNATURE SIGNATURE_32 ('s', 'c', 'd', 'k')
52
53 typedef struct {
54 UINT32 Signature;
55
56 EFI_HANDLE Handle;
57
58 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL StorageSecurity;
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 #define SCSI_DISK_DEV_FROM_STORSEC(a) CR (a, SCSI_DISK_DEV, StorageSecurity, SCSI_DISK_DEV_SIGNATURE)
105
106 #define SCSI_DISK_DEV_FROM_DISKINFO(a) CR (a, SCSI_DISK_DEV, DiskInfo, SCSI_DISK_DEV_SIGNATURE)
107
108 //
109 // Asynchronous I/O request
110 //
111 //
112 // Private data structure for a BlockIo2 request
113 //
114 typedef struct {
115 EFI_BLOCK_IO2_TOKEN *Token;
116 //
117 // The flag indicates if the last Scsi Read/Write sub-task for a BlockIo2
118 // request is sent to device
119 //
120 BOOLEAN LastScsiRW;
121
122 //
123 // The queue for Scsi Read/Write sub-tasks of a BlockIo2 request
124 //
125 LIST_ENTRY ScsiRWQueue;
126
127 LIST_ENTRY Link;
128 } SCSI_BLKIO2_REQUEST;
129
130 //
131 // Private data structure for a SCSI Read/Write request
132 //
133 typedef struct {
134 SCSI_DISK_DEV *ScsiDiskDevice;
135 UINT64 Timeout;
136 EFI_SCSI_SENSE_DATA *SenseData;
137 UINT8 SenseDataLength;
138 UINT8 HostAdapterStatus;
139 UINT8 TargetStatus;
140 UINT8 *InBuffer;
141 UINT8 *OutBuffer;
142 UINT32 DataLength;
143 UINT64 StartLba;
144 UINT32 SectorCount;
145 UINT8 TimesRetry;
146
147 //
148 // The BlockIo2 request this SCSI command belongs to
149 //
150 SCSI_BLKIO2_REQUEST *BlkIo2Req;
151
152 LIST_ENTRY Link;
153 } SCSI_ASYNC_RW_REQUEST;
154
155 //
156 // Private data structure for an EraseBlock request
157 //
158 typedef struct {
159 EFI_ERASE_BLOCK_TOKEN *Token;
160
161 EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;
162
163 LIST_ENTRY Link;
164 } SCSI_ERASEBLK_REQUEST;
165
166 //
167 // Global Variables
168 //
169 extern EFI_DRIVER_BINDING_PROTOCOL gScsiDiskDriverBinding;
170 extern EFI_COMPONENT_NAME_PROTOCOL gScsiDiskComponentName;
171 extern EFI_COMPONENT_NAME2_PROTOCOL gScsiDiskComponentName2;
172 //
173 // action code used in detect media process
174 //
175 #define ACTION_NO_ACTION 0x00
176 #define ACTION_READ_CAPACITY 0x01
177 #define ACTION_RETRY_COMMAND_LATER 0x02
178 #define ACTION_RETRY_WITH_BACKOFF_ALGO 0x03
179
180 #define SCSI_COMMAND_VERSION_1 0x01
181 #define SCSI_COMMAND_VERSION_2 0x02
182 #define SCSI_COMMAND_VERSION_3 0x03
183
184 // Per SCSI spec, EFI_SCSI_INQUIRY_DATA.Reserved_5_95[3 - 10] has the Vendor identification
185 // EFI_SCSI_INQUIRY_DATA.Reserved_5_95[11 - 26] has the product identification
186 #define VENDOR_IDENTIFICATION_OFFSET 3
187 #define VENDOR_IDENTIFICATION_LENGTH 8
188 #define PRODUCT_IDENTIFICATION_OFFSET 11
189 #define PRODUCT_IDENTIFICATION_LENGTH 16
190
191 //
192 // SCSI Disk Timeout Experience Value
193 //
194 // As ScsiDisk and ScsiBus driver are used to manage SCSI or ATAPI devices, the timeout
195 // value is updated to 30s to follow ATA/ATAPI spec in which the device may take up to 30s
196 // to respond command.
197 //
198 #define SCSI_DISK_TIMEOUT EFI_TIMER_PERIOD_SECONDS (30)
199
200 /**
201 Test to see if this driver supports ControllerHandle.
202
203 This service is called by the EFI boot service ConnectController(). In order
204 to make drivers as small as possible, there are a few calling restrictions for
205 this service. ConnectController() must follow these calling restrictions.
206 If any other agent wishes to call Supported() it must also follow these
207 calling restrictions.
208
209 @param This Protocol instance pointer.
210 @param ControllerHandle Handle of device to test
211 @param RemainingDevicePath Optional parameter use to pick a specific child
212 device to start.
213
214 @retval EFI_SUCCESS This driver supports this device
215 @retval EFI_ALREADY_STARTED This driver is already running on this device
216 @retval other This driver does not support this device
217
218 **/
219 EFI_STATUS
220 EFIAPI
221 ScsiDiskDriverBindingSupported (
222 IN EFI_DRIVER_BINDING_PROTOCOL *This,
223 IN EFI_HANDLE Controller,
224 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
225 );
226
227 /**
228 Start this driver on ControllerHandle.
229
230 This service is called by the EFI boot service ConnectController(). In order
231 to make drivers as small as possible, there are a few calling restrictions for
232 this service. ConnectController() must follow these calling restrictions. If
233 any other agent wishes to call Start() it must also follow these calling
234 restrictions.
235
236 @param This Protocol instance pointer.
237 @param ControllerHandle Handle of device to bind driver to
238 @param RemainingDevicePath Optional parameter use to pick a specific child
239 device to start.
240
241 @retval EFI_SUCCESS This driver is added to ControllerHandle
242 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
243 @retval other This driver does not support this device
244
245 **/
246 EFI_STATUS
247 EFIAPI
248 ScsiDiskDriverBindingStart (
249 IN EFI_DRIVER_BINDING_PROTOCOL *This,
250 IN EFI_HANDLE Controller,
251 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
252 );
253
254 /**
255 Stop this driver on ControllerHandle.
256
257 This service is called by the EFI boot service DisconnectController().
258 In order to make drivers as small as possible, there are a few calling
259 restrictions for this service. DisconnectController() must follow these
260 calling restrictions. If any other agent wishes to call Stop() it must
261 also follow these calling restrictions.
262
263 @param This Protocol instance pointer.
264 @param ControllerHandle Handle of device to stop driver on
265 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
266 children is zero stop the entire bus driver.
267 @param ChildHandleBuffer List of Child Handles to Stop.
268
269 @retval EFI_SUCCESS This driver is removed ControllerHandle
270 @retval other This driver was not removed from this device
271
272 **/
273 EFI_STATUS
274 EFIAPI
275 ScsiDiskDriverBindingStop (
276 IN EFI_DRIVER_BINDING_PROTOCOL *This,
277 IN EFI_HANDLE Controller,
278 IN UINTN NumberOfChildren,
279 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
280 );
281
282 //
283 // EFI Component Name Functions
284 //
285
286 /**
287 Retrieves a Unicode string that is the user readable name of the driver.
288
289 This function retrieves the user readable name of a driver in the form of a
290 Unicode string. If the driver specified by This has a user readable name in
291 the language specified by Language, then a pointer to the driver name is
292 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
293 by This does not support the language specified by Language,
294 then EFI_UNSUPPORTED is returned.
295
296 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
297 EFI_COMPONENT_NAME_PROTOCOL instance.
298
299 @param Language A pointer to a Null-terminated ASCII string
300 array indicating the language. This is the
301 language of the driver name that the caller is
302 requesting, and it must match one of the
303 languages specified in SupportedLanguages. The
304 number of languages supported by a driver is up
305 to the driver writer. Language is specified
306 in RFC 4646 or ISO 639-2 language code format.
307
308 @param DriverName A pointer to the Unicode string to return.
309 This Unicode string is the name of the
310 driver specified by This in the language
311 specified by Language.
312
313 @retval EFI_SUCCESS The Unicode string for the Driver specified by
314 This and the language specified by Language was
315 returned in DriverName.
316
317 @retval EFI_INVALID_PARAMETER Language is NULL.
318
319 @retval EFI_INVALID_PARAMETER DriverName is NULL.
320
321 @retval EFI_UNSUPPORTED The driver specified by This does not support
322 the language specified by Language.
323
324 **/
325 EFI_STATUS
326 EFIAPI
327 ScsiDiskComponentNameGetDriverName (
328 IN EFI_COMPONENT_NAME_PROTOCOL *This,
329 IN CHAR8 *Language,
330 OUT CHAR16 **DriverName
331 );
332
333 /**
334 Retrieves a Unicode string that is the user readable name of the controller
335 that is being managed by a driver.
336
337 This function retrieves the user readable name of the controller specified by
338 ControllerHandle and ChildHandle in the form of a Unicode string. If the
339 driver specified by This has a user readable name in the language specified by
340 Language, then a pointer to the controller name is returned in ControllerName,
341 and EFI_SUCCESS is returned. If the driver specified by This is not currently
342 managing the controller specified by ControllerHandle and ChildHandle,
343 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
344 support the language specified by Language, then EFI_UNSUPPORTED is returned.
345
346 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
347 EFI_COMPONENT_NAME_PROTOCOL instance.
348
349 @param ControllerHandle The handle of a controller that the driver
350 specified by This is managing. This handle
351 specifies the controller whose name is to be
352 returned.
353
354 @param ChildHandle The handle of the child controller to retrieve
355 the name of. This is an optional parameter that
356 may be NULL. It will be NULL for device
357 drivers. It will also be NULL for a bus drivers
358 that wish to retrieve the name of the bus
359 controller. It will not be NULL for a bus
360 driver that wishes to retrieve the name of a
361 child controller.
362
363 @param Language A pointer to a Null-terminated ASCII string
364 array indicating the language. This is the
365 language of the driver name that the caller is
366 requesting, and it must match one of the
367 languages specified in SupportedLanguages. The
368 number of languages supported by a driver is up
369 to the driver writer. Language is specified in
370 RFC 4646 or ISO 639-2 language code format.
371
372 @param ControllerName A pointer to the Unicode string to return.
373 This Unicode string is the name of the
374 controller specified by ControllerHandle and
375 ChildHandle in the language specified by
376 Language from the point of view of the driver
377 specified by This.
378
379 @retval EFI_SUCCESS The Unicode string for the user readable name in
380 the language specified by Language for the
381 driver specified by This was returned in
382 DriverName.
383
384 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
385
386 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
387 EFI_HANDLE.
388
389 @retval EFI_INVALID_PARAMETER Language is NULL.
390
391 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
392
393 @retval EFI_UNSUPPORTED The driver specified by This is not currently
394 managing the controller specified by
395 ControllerHandle and ChildHandle.
396
397 @retval EFI_UNSUPPORTED The driver specified by This does not support
398 the language specified by Language.
399
400 **/
401 EFI_STATUS
402 EFIAPI
403 ScsiDiskComponentNameGetControllerName (
404 IN EFI_COMPONENT_NAME_PROTOCOL *This,
405 IN EFI_HANDLE ControllerHandle,
406 IN EFI_HANDLE ChildHandle OPTIONAL,
407 IN CHAR8 *Language,
408 OUT CHAR16 **ControllerName
409 );
410
411 /**
412 Reset SCSI Disk.
413
414
415 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
416 @param ExtendedVerification The flag about if extend verificate
417
418 @retval EFI_SUCCESS The device was reset.
419 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
420 not be reset.
421 @return EFI_STATUS is returned from EFI_SCSI_IO_PROTOCOL.ResetDevice().
422
423 **/
424 EFI_STATUS
425 EFIAPI
426 ScsiDiskReset (
427 IN EFI_BLOCK_IO_PROTOCOL *This,
428 IN BOOLEAN ExtendedVerification
429 );
430
431 /**
432 The function is to Read Block from SCSI Disk.
433
434 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
435 @param MediaId The Id of Media detected
436 @param Lba The logic block address
437 @param BufferSize The size of Buffer
438 @param Buffer The buffer to fill the read out data
439
440 @retval EFI_SUCCESS Successfully to read out block.
441 @retval EFI_DEVICE_ERROR Fail to detect media.
442 @retval EFI_NO_MEDIA Media is not present.
443 @retval EFI_MEDIA_CHANGED Media has changed.
444 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
445 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
446
447 **/
448 EFI_STATUS
449 EFIAPI
450 ScsiDiskReadBlocks (
451 IN EFI_BLOCK_IO_PROTOCOL *This,
452 IN UINT32 MediaId,
453 IN EFI_LBA Lba,
454 IN UINTN BufferSize,
455 OUT VOID *Buffer
456 );
457
458 /**
459 The function is to Write Block to SCSI Disk.
460
461 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
462 @param MediaId The Id of Media detected
463 @param Lba The logic block address
464 @param BufferSize The size of Buffer
465 @param Buffer The buffer to fill the read out data
466
467 @retval EFI_SUCCESS Successfully to read out block.
468 @retval EFI_WRITE_PROTECTED The device can not be written to.
469 @retval EFI_DEVICE_ERROR Fail to detect media.
470 @retval EFI_NO_MEDIA Media is not present.
471 @retval EFI_MEDIA_CHANGED Media has changed.
472 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
473 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
474
475 **/
476 EFI_STATUS
477 EFIAPI
478 ScsiDiskWriteBlocks (
479 IN EFI_BLOCK_IO_PROTOCOL *This,
480 IN UINT32 MediaId,
481 IN EFI_LBA Lba,
482 IN UINTN BufferSize,
483 IN VOID *Buffer
484 );
485
486 /**
487 Flush Block to Disk.
488
489 EFI_SUCCESS is returned directly.
490
491 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
492
493 @retval EFI_SUCCESS All outstanding data was written to the device
494
495 **/
496 EFI_STATUS
497 EFIAPI
498 ScsiDiskFlushBlocks (
499 IN EFI_BLOCK_IO_PROTOCOL *This
500 );
501
502 /**
503 Reset SCSI Disk.
504
505 @param This The pointer of EFI_BLOCK_IO2_PROTOCOL.
506 @param ExtendedVerification The flag about if extend verificate.
507
508 @retval EFI_SUCCESS The device was reset.
509 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
510 not be reset.
511 @return EFI_STATUS is returned from EFI_SCSI_IO_PROTOCOL.ResetDevice().
512
513 **/
514 EFI_STATUS
515 EFIAPI
516 ScsiDiskResetEx (
517 IN EFI_BLOCK_IO2_PROTOCOL *This,
518 IN BOOLEAN ExtendedVerification
519 );
520
521 /**
522 The function is to Read Block from SCSI Disk.
523
524 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
525 @param MediaId The Id of Media detected.
526 @param Lba The logic block address.
527 @param Token A pointer to the token associated with the transaction.
528 @param BufferSize The size of Buffer.
529 @param Buffer The buffer to fill the read out data.
530
531 @retval EFI_SUCCESS The read request was queued if Token-> Event is
532 not NULL. The data was read correctly from the
533 device if theToken-> Event is NULL.
534 @retval EFI_DEVICE_ERROR The device reported an error while attempting
535 to perform the read operation.
536 @retval EFI_NO_MEDIA There is no media in the device.
537 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
538 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
539 the intrinsic block size of the device.
540 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
541 valid, or the buffer is not on proper
542 alignment.
543 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
544 lack of resources.
545
546 **/
547 EFI_STATUS
548 EFIAPI
549 ScsiDiskReadBlocksEx (
550 IN EFI_BLOCK_IO2_PROTOCOL *This,
551 IN UINT32 MediaId,
552 IN EFI_LBA Lba,
553 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
554 IN UINTN BufferSize,
555 OUT VOID *Buffer
556 );
557
558 /**
559 The function is to Write Block to SCSI Disk.
560
561 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
562 @param MediaId The Id of Media detected.
563 @param Lba The logic block address.
564 @param Token A pointer to the token associated with the transaction.
565 @param BufferSize The size of Buffer.
566 @param Buffer The buffer to fill the read out data.
567
568 @retval EFI_SUCCESS The data were written correctly to the device.
569 @retval EFI_WRITE_PROTECTED The device cannot be written to.
570 @retval EFI_NO_MEDIA There is no media in the device.
571 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
572 @retval EFI_DEVICE_ERROR The device reported an error while attempting
573 to perform the write operation.
574 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
575 the intrinsic block size of the device.
576 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
577 valid, or the buffer is not on proper
578 alignment.
579
580 **/
581 EFI_STATUS
582 EFIAPI
583 ScsiDiskWriteBlocksEx (
584 IN EFI_BLOCK_IO2_PROTOCOL *This,
585 IN UINT32 MediaId,
586 IN EFI_LBA Lba,
587 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
588 IN UINTN BufferSize,
589 IN VOID *Buffer
590 );
591
592 /**
593 Flush the Block Device.
594
595 @param This Indicates a pointer to the calling context.
596 @param Token A pointer to the token associated with the transaction.
597
598 @retval EFI_SUCCESS All outstanding data was written to the device.
599 @retval EFI_DEVICE_ERROR The device reported an error while attempting to
600 write data.
601 @retval EFI_WRITE_PROTECTED The device cannot be written to.
602 @retval EFI_NO_MEDIA There is no media in the device.
603 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
604
605 **/
606 EFI_STATUS
607 EFIAPI
608 ScsiDiskFlushBlocksEx (
609 IN EFI_BLOCK_IO2_PROTOCOL *This,
610 IN OUT EFI_BLOCK_IO2_TOKEN *Token
611 );
612
613 /**
614 Erase a specified number of device blocks.
615
616 @param[in] This Indicates a pointer to the calling context.
617 @param[in] MediaId The media ID that the erase request is for.
618 @param[in] Lba The starting logical block address to be
619 erased. The caller is responsible for erasing
620 only legitimate locations.
621 @param[in, out] Token A pointer to the token associated with the
622 transaction.
623 @param[in] Size The size in bytes to be erased. This must be
624 a multiple of the physical block size of the
625 device.
626
627 @retval EFI_SUCCESS The erase request was queued if Event is not
628 NULL. The data was erased correctly to the
629 device if the Event is NULL.to the device.
630 @retval EFI_WRITE_PROTECTED The device cannot be erased due to write
631 protection.
632 @retval EFI_DEVICE_ERROR The device reported an error while attempting
633 to perform the erase operation.
634 @retval EFI_INVALID_PARAMETER The erase request contains LBAs that are not
635 valid.
636 @retval EFI_NO_MEDIA There is no media in the device.
637 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
638
639 **/
640 EFI_STATUS
641 EFIAPI
642 ScsiDiskEraseBlocks (
643 IN EFI_ERASE_BLOCK_PROTOCOL *This,
644 IN UINT32 MediaId,
645 IN EFI_LBA Lba,
646 IN OUT EFI_ERASE_BLOCK_TOKEN *Token,
647 IN UINTN Size
648 );
649
650 /**
651 Send a security protocol command to a device that receives data and/or the result
652 of one or more commands sent by SendData.
653
654 The ReceiveData function sends a security protocol command to the given MediaId.
655 The security protocol command sent is defined by SecurityProtocolId and contains
656 the security protocol specific data SecurityProtocolSpecificData. The function
657 returns the data from the security protocol command in PayloadBuffer.
658
659 For devices supporting the SCSI command set, the security protocol command is sent
660 using the SECURITY PROTOCOL IN command defined in SPC-4.
661
662 If PayloadBufferSize is too small to store the available data from the security
663 protocol command, the function shall copy PayloadBufferSize bytes into the
664 PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.
665
666 If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,
667 the function shall return EFI_INVALID_PARAMETER.
668
669 If the given MediaId does not support security protocol commands, the function shall
670 return EFI_UNSUPPORTED. If there is no media in the device, the function returns
671 EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the device,
672 the function returns EFI_MEDIA_CHANGED.
673
674 If the security protocol fails to complete within the Timeout period, the function
675 shall return EFI_TIMEOUT.
676
677 If the security protocol command completes without an error, the function shall
678 return EFI_SUCCESS. If the security protocol command completes with an error, the
679 function shall return EFI_DEVICE_ERROR.
680
681 @param This Indicates a pointer to the calling context.
682 @param MediaId ID of the medium to receive data from.
683 @param Timeout The timeout, in 100ns units, to use for the execution
684 of the security protocol command. A Timeout value of 0
685 means that this function will wait indefinitely for the
686 security protocol command to execute. If Timeout is greater
687 than zero, then this function will return EFI_TIMEOUT if the
688 time required to execute the receive data command is greater than Timeout.
689 @param SecurityProtocolId The value of the "Security Protocol" parameter of
690 the security protocol command to be sent.
691 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
692 of the security protocol command to be sent.
693 @param PayloadBufferSize Size in bytes of the payload data buffer.
694 @param PayloadBuffer A pointer to a destination buffer to store the security
695 protocol command specific payload data for the security
696 protocol command. The caller is responsible for having
697 either implicit or explicit ownership of the buffer.
698 @param PayloadTransferSize A pointer to a buffer to store the size in bytes of the
699 data written to the payload data buffer.
700
701 @retval EFI_SUCCESS The security protocol command completed successfully.
702 @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to store the available
703 data from the device. The PayloadBuffer contains the truncated data.
704 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
705 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
706 @retval EFI_NO_MEDIA There is no media in the device.
707 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
708 @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize is NULL and
709 PayloadBufferSize is non-zero.
710 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
711 protocol command to execute.
712
713 **/
714 EFI_STATUS
715 EFIAPI
716 ScsiDiskReceiveData (
717 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,
718 IN UINT32 MediaId OPTIONAL,
719 IN UINT64 Timeout,
720 IN UINT8 SecurityProtocolId,
721 IN UINT16 SecurityProtocolSpecificData,
722 IN UINTN PayloadBufferSize,
723 OUT VOID *PayloadBuffer,
724 OUT UINTN *PayloadTransferSize
725 );
726
727 /**
728 Send a security protocol command to a device.
729
730 The SendData function sends a security protocol command containing the payload
731 PayloadBuffer to the given MediaId. The security protocol command sent is
732 defined by SecurityProtocolId and contains the security protocol specific data
733 SecurityProtocolSpecificData. If the underlying protocol command requires a
734 specific padding for the command payload, the SendData function shall add padding
735 bytes to the command payload to satisfy the padding requirements.
736
737 For devices supporting the SCSI command set, the security protocol command is sent
738 using the SECURITY PROTOCOL OUT command defined in SPC-4.
739
740 If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall
741 return EFI_INVALID_PARAMETER.
742
743 If the given MediaId does not support security protocol commands, the function
744 shall return EFI_UNSUPPORTED. If there is no media in the device, the function
745 returns EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the
746 device, the function returns EFI_MEDIA_CHANGED.
747
748 If the security protocol fails to complete within the Timeout period, the function
749 shall return EFI_TIMEOUT.
750
751 If the security protocol command completes without an error, the function shall return
752 EFI_SUCCESS. If the security protocol command completes with an error, the function
753 shall return EFI_DEVICE_ERROR.
754
755 @param This Indicates a pointer to the calling context.
756 @param MediaId ID of the medium to receive data from.
757 @param Timeout The timeout, in 100ns units, to use for the execution
758 of the security protocol command. A Timeout value of 0
759 means that this function will wait indefinitely for the
760 security protocol command to execute. If Timeout is greater
761 than zero, then this function will return EFI_TIMEOUT if the
762 time required to execute the receive data command is greater than Timeout.
763 @param SecurityProtocolId The value of the "Security Protocol" parameter of
764 the security protocol command to be sent.
765 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
766 of the security protocol command to be sent.
767 @param PayloadBufferSize Size in bytes of the payload data buffer.
768 @param PayloadBuffer A pointer to a destination buffer to store the security
769 protocol command specific payload data for the security
770 protocol command.
771
772 @retval EFI_SUCCESS The security protocol command completed successfully.
773 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
774 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
775 @retval EFI_NO_MEDIA There is no media in the device.
776 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
777 @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize is non-zero.
778 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
779 protocol command to execute.
780
781 **/
782 EFI_STATUS
783 EFIAPI
784 ScsiDiskSendData (
785 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,
786 IN UINT32 MediaId OPTIONAL,
787 IN UINT64 Timeout,
788 IN UINT8 SecurityProtocolId,
789 IN UINT16 SecurityProtocolSpecificData,
790 IN UINTN PayloadBufferSize,
791 OUT VOID *PayloadBuffer
792 );
793
794 /**
795 Provides inquiry information for the controller type.
796
797 This function is used by the IDE bus driver to get inquiry data. Data format
798 of Identify data is defined by the Interface GUID.
799
800 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
801 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
802 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
803
804 @retval EFI_SUCCESS The command was accepted without any errors.
805 @retval EFI_NOT_FOUND Device does not support this data class
806 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
807 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
808
809 **/
810 EFI_STATUS
811 EFIAPI
812 ScsiDiskInfoInquiry (
813 IN EFI_DISK_INFO_PROTOCOL *This,
814 IN OUT VOID *InquiryData,
815 IN OUT UINT32 *InquiryDataSize
816 );
817
818 /**
819 Provides identify information for the controller type.
820
821 This function is used by the IDE bus driver to get identify data. Data format
822 of Identify data is defined by the Interface GUID.
823
824 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
825 instance.
826 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
827 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
828 size.
829
830 @retval EFI_SUCCESS The command was accepted without any errors.
831 @retval EFI_NOT_FOUND Device does not support this data class
832 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
833 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
834
835 **/
836 EFI_STATUS
837 EFIAPI
838 ScsiDiskInfoIdentify (
839 IN EFI_DISK_INFO_PROTOCOL *This,
840 IN OUT VOID *IdentifyData,
841 IN OUT UINT32 *IdentifyDataSize
842 );
843
844 /**
845 Provides sense data information for the controller type.
846
847 This function is used by the IDE bus driver to get sense data.
848 Data format of Sense data is defined by the Interface GUID.
849
850 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
851 @param[in, out] SenseData Pointer to the SenseData.
852 @param[in, out] SenseDataSize Size of SenseData in bytes.
853 @param[out] SenseDataNumber Pointer to the value for the sense data size.
854
855 @retval EFI_SUCCESS The command was accepted without any errors.
856 @retval EFI_NOT_FOUND Device does not support this data class.
857 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
858 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
859
860 **/
861 EFI_STATUS
862 EFIAPI
863 ScsiDiskInfoSenseData (
864 IN EFI_DISK_INFO_PROTOCOL *This,
865 IN OUT VOID *SenseData,
866 IN OUT UINT32 *SenseDataSize,
867 OUT UINT8 *SenseDataNumber
868 );
869
870 /**
871 This function is used by the IDE bus driver to get controller information.
872
873 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
874 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
875 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
876
877 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
878 @retval EFI_UNSUPPORTED This is not an IDE device.
879
880 **/
881 EFI_STATUS
882 EFIAPI
883 ScsiDiskInfoWhichIde (
884 IN EFI_DISK_INFO_PROTOCOL *This,
885 OUT UINT32 *IdeChannel,
886 OUT UINT32 *IdeDevice
887 );
888
889 /**
890 Detect Device and read out capacity ,if error occurs, parse the sense key.
891
892 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
893 @param MustReadCapacity The flag about reading device capacity
894 @param MediaChange The pointer of flag indicates if media has changed
895
896 @retval EFI_DEVICE_ERROR Indicates that error occurs
897 @retval EFI_SUCCESS Successfully to detect media
898
899 **/
900 EFI_STATUS
901 ScsiDiskDetectMedia (
902 IN SCSI_DISK_DEV *ScsiDiskDevice,
903 IN BOOLEAN MustReadCapacity,
904 OUT BOOLEAN *MediaChange
905 );
906
907 /**
908 To test device.
909
910 When Test Unit Ready command succeeds, retrieve Sense Keys via Request Sense;
911 When Test Unit Ready command encounters any error caused by host adapter or
912 target, return error without retrieving Sense Keys.
913
914 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
915 @param NeedRetry The pointer of flag indicates try again
916 @param SenseDataArray The pointer of an array of sense data
917 @param NumberOfSenseKeys The pointer of the number of sense data array
918
919 @retval EFI_DEVICE_ERROR Indicates that error occurs
920 @retval EFI_SUCCESS Successfully to test unit
921
922 **/
923 EFI_STATUS
924 ScsiDiskTestUnitReady (
925 IN SCSI_DISK_DEV *ScsiDiskDevice,
926 OUT BOOLEAN *NeedRetry,
927 OUT EFI_SCSI_SENSE_DATA **SenseDataArray,
928 OUT UINTN *NumberOfSenseKeys
929 );
930
931 /**
932 Parsing Sense Keys which got from request sense command.
933
934 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
935 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
936 @param NumberOfSenseKeys The number of sense key
937 @param Action The pointer of action which indicates what is need to do next
938
939 @retval EFI_DEVICE_ERROR Indicates that error occurs
940 @retval EFI_SUCCESS Successfully to complete the parsing
941
942 **/
943 EFI_STATUS
944 DetectMediaParsingSenseKeys (
945 OUT SCSI_DISK_DEV *ScsiDiskDevice,
946 IN EFI_SCSI_SENSE_DATA *SenseData,
947 IN UINTN NumberOfSenseKeys,
948 OUT UINTN *Action
949 );
950
951 /**
952 Send read capacity command to device and get the device parameter.
953
954 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
955 @param NeedRetry The pointer of flag indicates if need a retry
956 @param SenseDataArray The pointer of an array of sense data
957 @param NumberOfSenseKeys The number of sense key
958
959 @retval EFI_DEVICE_ERROR Indicates that error occurs
960 @retval EFI_SUCCESS Successfully to read capacity
961
962 **/
963 EFI_STATUS
964 ScsiDiskReadCapacity (
965 IN OUT SCSI_DISK_DEV *ScsiDiskDevice,
966 OUT BOOLEAN *NeedRetry,
967 OUT EFI_SCSI_SENSE_DATA **SenseDataArray,
968 OUT UINTN *NumberOfSenseKeys
969 );
970
971 /**
972 Check the HostAdapter status and re-interpret it in EFI_STATUS.
973
974 @param HostAdapterStatus Host Adapter status
975
976 @retval EFI_SUCCESS Host adapter is OK.
977 @retval EFI_TIMEOUT Timeout.
978 @retval EFI_NOT_READY Adapter NOT ready.
979 @retval EFI_DEVICE_ERROR Adapter device error.
980
981 **/
982 EFI_STATUS
983 CheckHostAdapterStatus (
984 IN UINT8 HostAdapterStatus
985 );
986
987 /**
988 Check the target status and re-interpret it in EFI_STATUS.
989
990 @param TargetStatus Target status
991
992 @retval EFI_NOT_READY Device is NOT ready.
993 @retval EFI_DEVICE_ERROR
994 @retval EFI_SUCCESS
995
996 **/
997 EFI_STATUS
998 CheckTargetStatus (
999 IN UINT8 TargetStatus
1000 );
1001
1002 /**
1003 Retrieve all sense keys from the device.
1004
1005 When encountering error during the process, if retrieve sense keys before
1006 error encountered, it returns the sense keys with return status set to EFI_SUCCESS,
1007 and NeedRetry set to FALSE; otherwise, return the proper return status.
1008
1009 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1010 @param NeedRetry The pointer of flag indicates if need a retry
1011 @param SenseDataArray The pointer of an array of sense data
1012 @param NumberOfSenseKeys The number of sense key
1013 @param AskResetIfError The flag indicates if need reset when error occurs
1014
1015 @retval EFI_DEVICE_ERROR Indicates that error occurs
1016 @retval EFI_SUCCESS Successfully to request sense key
1017
1018 **/
1019 EFI_STATUS
1020 ScsiDiskRequestSenseKeys (
1021 IN OUT SCSI_DISK_DEV *ScsiDiskDevice,
1022 OUT BOOLEAN *NeedRetry,
1023 OUT EFI_SCSI_SENSE_DATA **SenseDataArray,
1024 OUT UINTN *NumberOfSenseKeys,
1025 IN BOOLEAN AskResetIfError
1026 );
1027
1028 /**
1029 Send out Inquiry command to Device.
1030
1031 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1032 @param NeedRetry Indicates if needs try again when error happens
1033
1034 @retval EFI_DEVICE_ERROR Indicates that error occurs
1035 @retval EFI_SUCCESS Successfully to detect media
1036
1037 **/
1038 EFI_STATUS
1039 ScsiDiskInquiryDevice (
1040 IN OUT SCSI_DISK_DEV *ScsiDiskDevice,
1041 OUT BOOLEAN *NeedRetry
1042 );
1043
1044 /**
1045 Parse Inquiry data.
1046
1047 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1048
1049 **/
1050 VOID
1051 ParseInquiryData (
1052 IN OUT SCSI_DISK_DEV *ScsiDiskDevice
1053 );
1054
1055 /**
1056 Read sector from SCSI Disk.
1057
1058 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1059 @param Buffer The buffer to fill in the read out data
1060 @param Lba Logic block address
1061 @param NumberOfBlocks The number of blocks to read
1062
1063 @retval EFI_DEVICE_ERROR Indicates a device error.
1064 @retval EFI_SUCCESS Operation is successful.
1065
1066 **/
1067 EFI_STATUS
1068 ScsiDiskReadSectors (
1069 IN SCSI_DISK_DEV *ScsiDiskDevice,
1070 OUT VOID *Buffer,
1071 IN EFI_LBA Lba,
1072 IN UINTN NumberOfBlocks
1073 );
1074
1075 /**
1076 Write sector to SCSI Disk.
1077
1078 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1079 @param Buffer The buffer of data to be written into SCSI Disk
1080 @param Lba Logic block address
1081 @param NumberOfBlocks The number of blocks to read
1082
1083 @retval EFI_DEVICE_ERROR Indicates a device error.
1084 @retval EFI_SUCCESS Operation is successful.
1085
1086 **/
1087 EFI_STATUS
1088 ScsiDiskWriteSectors (
1089 IN SCSI_DISK_DEV *ScsiDiskDevice,
1090 IN VOID *Buffer,
1091 IN EFI_LBA Lba,
1092 IN UINTN NumberOfBlocks
1093 );
1094
1095 /**
1096 Asynchronously read sector from SCSI Disk.
1097
1098 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1099 @param Buffer The buffer to fill in the read out data.
1100 @param Lba Logic block address.
1101 @param NumberOfBlocks The number of blocks to read.
1102 @param Token A pointer to the token associated with the
1103 non-blocking read request.
1104
1105 @retval EFI_INVALID_PARAMETER Token is NULL or Token->Event is NULL.
1106 @retval EFI_DEVICE_ERROR Indicates a device error.
1107 @retval EFI_SUCCESS Operation is successful.
1108
1109 **/
1110 EFI_STATUS
1111 ScsiDiskAsyncReadSectors (
1112 IN SCSI_DISK_DEV *ScsiDiskDevice,
1113 OUT VOID *Buffer,
1114 IN EFI_LBA Lba,
1115 IN UINTN NumberOfBlocks,
1116 IN EFI_BLOCK_IO2_TOKEN *Token
1117 );
1118
1119 /**
1120 Asynchronously write sector to SCSI Disk.
1121
1122 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1123 @param Buffer The buffer of data to be written into SCSI Disk.
1124 @param Lba Logic block address.
1125 @param NumberOfBlocks The number of blocks to read.
1126 @param Token A pointer to the token associated with the
1127 non-blocking read request.
1128
1129 @retval EFI_INVALID_PARAMETER Token is NULL or Token->Event is NULL
1130 @retval EFI_DEVICE_ERROR Indicates a device error.
1131 @retval EFI_SUCCESS Operation is successful.
1132
1133 **/
1134 EFI_STATUS
1135 ScsiDiskAsyncWriteSectors (
1136 IN SCSI_DISK_DEV *ScsiDiskDevice,
1137 IN VOID *Buffer,
1138 IN EFI_LBA Lba,
1139 IN UINTN NumberOfBlocks,
1140 IN EFI_BLOCK_IO2_TOKEN *Token
1141 );
1142
1143 /**
1144 Submit Read(10) command.
1145
1146 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1147 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1148 @param Timeout The time to complete the command
1149 @param DataBuffer The buffer to fill with the read out data
1150 @param DataLength The length of buffer
1151 @param StartLba The start logic block address
1152 @param SectorCount The number of blocks to read
1153
1154 @return EFI_STATUS is returned by calling ScsiRead10Command().
1155 **/
1156 EFI_STATUS
1157 ScsiDiskRead10 (
1158 IN SCSI_DISK_DEV *ScsiDiskDevice,
1159 OUT BOOLEAN *NeedRetry,
1160 IN UINT64 Timeout,
1161 OUT UINT8 *DataBuffer,
1162 IN OUT UINT32 *DataLength,
1163 IN UINT32 StartLba,
1164 IN UINT32 SectorCount
1165 );
1166
1167 /**
1168 Submit Write(10) Command.
1169
1170 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1171 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1172 @param Timeout The time to complete the command
1173 @param DataBuffer The buffer to fill with the read out data
1174 @param DataLength The length of buffer
1175 @param StartLba The start logic block address
1176 @param SectorCount The number of blocks to write
1177
1178 @return EFI_STATUS is returned by calling ScsiWrite10Command().
1179
1180 **/
1181 EFI_STATUS
1182 ScsiDiskWrite10 (
1183 IN SCSI_DISK_DEV *ScsiDiskDevice,
1184 OUT BOOLEAN *NeedRetry,
1185 IN UINT64 Timeout,
1186 IN UINT8 *DataBuffer,
1187 IN OUT UINT32 *DataLength,
1188 IN UINT32 StartLba,
1189 IN UINT32 SectorCount
1190 );
1191
1192 /**
1193 Submit Read(16) command.
1194
1195 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1196 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1197 @param Timeout The time to complete the command
1198 @param DataBuffer The buffer to fill with the read out data
1199 @param DataLength The length of buffer
1200 @param StartLba The start logic block address
1201 @param SectorCount The number of blocks to read
1202
1203 @return EFI_STATUS is returned by calling ScsiRead16Command().
1204 **/
1205 EFI_STATUS
1206 ScsiDiskRead16 (
1207 IN SCSI_DISK_DEV *ScsiDiskDevice,
1208 OUT BOOLEAN *NeedRetry,
1209 IN UINT64 Timeout,
1210 OUT UINT8 *DataBuffer,
1211 IN OUT UINT32 *DataLength,
1212 IN UINT64 StartLba,
1213 IN UINT32 SectorCount
1214 );
1215
1216 /**
1217 Submit Write(16) Command.
1218
1219 @param ScsiDiskDevice The pointer of ScsiDiskDevice
1220 @param NeedRetry The pointer of flag indicates if needs retry if error happens
1221 @param Timeout The time to complete the command
1222 @param DataBuffer The buffer to fill with the read out data
1223 @param DataLength The length of buffer
1224 @param StartLba The start logic block address
1225 @param SectorCount The number of blocks to write
1226
1227 @return EFI_STATUS is returned by calling ScsiWrite16Command().
1228
1229 **/
1230 EFI_STATUS
1231 ScsiDiskWrite16 (
1232 IN SCSI_DISK_DEV *ScsiDiskDevice,
1233 OUT BOOLEAN *NeedRetry,
1234 IN UINT64 Timeout,
1235 IN UINT8 *DataBuffer,
1236 IN OUT UINT32 *DataLength,
1237 IN UINT64 StartLba,
1238 IN UINT32 SectorCount
1239 );
1240
1241 /**
1242 Submit Async Read(10) command.
1243
1244 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1245 @param Timeout The time to complete the command.
1246 @param TimesRetry The number of times the command has been retried.
1247 @param DataBuffer The buffer to fill with the read out data.
1248 @param DataLength The length of buffer.
1249 @param StartLba The start logic block address.
1250 @param SectorCount The number of blocks to read.
1251 @param BlkIo2Req The upstream BlockIo2 request.
1252 @param Token The pointer to the token associated with the
1253 non-blocking read request.
1254
1255 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1256 lack of resources.
1257 @return others Status returned by calling
1258 ScsiRead10CommandEx().
1259
1260 **/
1261 EFI_STATUS
1262 ScsiDiskAsyncRead10 (
1263 IN SCSI_DISK_DEV *ScsiDiskDevice,
1264 IN UINT64 Timeout,
1265 IN UINT8 TimesRetry,
1266 OUT UINT8 *DataBuffer,
1267 IN UINT32 DataLength,
1268 IN UINT32 StartLba,
1269 IN UINT32 SectorCount,
1270 IN OUT SCSI_BLKIO2_REQUEST *BlkIo2Req,
1271 IN EFI_BLOCK_IO2_TOKEN *Token
1272 );
1273
1274 /**
1275 Submit Async Write(10) command.
1276
1277 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1278 @param Timeout The time to complete the command.
1279 @param TimesRetry The number of times the command has been retried.
1280 @param DataBuffer The buffer contains the data to write.
1281 @param DataLength The length of buffer.
1282 @param StartLba The start logic block address.
1283 @param SectorCount The number of blocks to write.
1284 @param BlkIo2Req The upstream BlockIo2 request.
1285 @param Token The pointer to the token associated with the
1286 non-blocking read request.
1287
1288 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1289 lack of resources.
1290 @return others Status returned by calling
1291 ScsiWrite10CommandEx().
1292
1293 **/
1294 EFI_STATUS
1295 ScsiDiskAsyncWrite10 (
1296 IN SCSI_DISK_DEV *ScsiDiskDevice,
1297 IN UINT64 Timeout,
1298 IN UINT8 TimesRetry,
1299 IN UINT8 *DataBuffer,
1300 IN UINT32 DataLength,
1301 IN UINT32 StartLba,
1302 IN UINT32 SectorCount,
1303 IN OUT SCSI_BLKIO2_REQUEST *BlkIo2Req,
1304 IN EFI_BLOCK_IO2_TOKEN *Token
1305 );
1306
1307 /**
1308 Submit Async Read(16) command.
1309
1310 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1311 @param Timeout The time to complete the command.
1312 @param TimesRetry The number of times the command has been retried.
1313 @param DataBuffer The buffer to fill with the read out data.
1314 @param DataLength The length of buffer.
1315 @param StartLba The start logic block address.
1316 @param SectorCount The number of blocks to read.
1317 @param BlkIo2Req The upstream BlockIo2 request.
1318 @param Token The pointer to the token associated with the
1319 non-blocking read request.
1320
1321 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1322 lack of resources.
1323 @return others Status returned by calling
1324 ScsiRead16CommandEx().
1325
1326 **/
1327 EFI_STATUS
1328 ScsiDiskAsyncRead16 (
1329 IN SCSI_DISK_DEV *ScsiDiskDevice,
1330 IN UINT64 Timeout,
1331 IN UINT8 TimesRetry,
1332 OUT UINT8 *DataBuffer,
1333 IN UINT32 DataLength,
1334 IN UINT64 StartLba,
1335 IN UINT32 SectorCount,
1336 IN OUT SCSI_BLKIO2_REQUEST *BlkIo2Req,
1337 IN EFI_BLOCK_IO2_TOKEN *Token
1338 );
1339
1340 /**
1341 Submit Async Write(16) command.
1342
1343 @param ScsiDiskDevice The pointer of ScsiDiskDevice.
1344 @param Timeout The time to complete the command.
1345 @param TimesRetry The number of times the command has been retried.
1346 @param DataBuffer The buffer contains the data to write.
1347 @param DataLength The length of buffer.
1348 @param StartLba The start logic block address.
1349 @param SectorCount The number of blocks to write.
1350 @param BlkIo2Req The upstream BlockIo2 request.
1351 @param Token The pointer to the token associated with the
1352 non-blocking read request.
1353
1354 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
1355 lack of resources.
1356 @return others Status returned by calling
1357 ScsiWrite16CommandEx().
1358
1359 **/
1360 EFI_STATUS
1361 ScsiDiskAsyncWrite16 (
1362 IN SCSI_DISK_DEV *ScsiDiskDevice,
1363 IN UINT64 Timeout,
1364 IN UINT8 TimesRetry,
1365 IN UINT8 *DataBuffer,
1366 IN UINT32 DataLength,
1367 IN UINT64 StartLba,
1368 IN UINT32 SectorCount,
1369 IN OUT SCSI_BLKIO2_REQUEST *BlkIo2Req,
1370 IN EFI_BLOCK_IO2_TOKEN *Token
1371 );
1372
1373 /**
1374 Get information from media read capacity command.
1375
1376 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1377 @param Capacity10 The pointer of EFI_SCSI_DISK_CAPACITY_DATA
1378 @param Capacity16 The pointer of EFI_SCSI_DISK_CAPACITY_DATA16
1379 **/
1380 VOID
1381 GetMediaInfo (
1382 IN OUT SCSI_DISK_DEV *ScsiDiskDevice,
1383 IN EFI_SCSI_DISK_CAPACITY_DATA *Capacity10,
1384 IN EFI_SCSI_DISK_CAPACITY_DATA16 *Capacity16
1385 );
1386
1387 /**
1388 Check sense key to find if media presents.
1389
1390 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1391 @param SenseCounts The number of sense key
1392
1393 @retval TRUE NOT any media
1394 @retval FALSE Media presents
1395 **/
1396 BOOLEAN
1397 ScsiDiskIsNoMedia (
1398 IN EFI_SCSI_SENSE_DATA *SenseData,
1399 IN UINTN SenseCounts
1400 );
1401
1402 /**
1403 Parse sense key.
1404
1405 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1406 @param SenseCounts The number of sense key
1407
1408 @retval TRUE Error
1409 @retval FALSE NOT error
1410
1411 **/
1412 BOOLEAN
1413 ScsiDiskIsMediaError (
1414 IN EFI_SCSI_SENSE_DATA *SenseData,
1415 IN UINTN SenseCounts
1416 );
1417
1418 /**
1419 Check sense key to find if hardware error happens.
1420
1421 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1422 @param SenseCounts The number of sense key
1423
1424 @retval TRUE Hardware error exits.
1425 @retval FALSE NO error.
1426
1427 **/
1428 BOOLEAN
1429 ScsiDiskIsHardwareError (
1430 IN EFI_SCSI_SENSE_DATA *SenseData,
1431 IN UINTN SenseCounts
1432 );
1433
1434 /**
1435 Check sense key to find if media has changed.
1436
1437 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1438 @param SenseCounts The number of sense key
1439
1440 @retval TRUE Media is changed.
1441 @retval FALSE Media is NOT changed.
1442 **/
1443 BOOLEAN
1444 ScsiDiskIsMediaChange (
1445 IN EFI_SCSI_SENSE_DATA *SenseData,
1446 IN UINTN SenseCounts
1447 );
1448
1449 /**
1450 Check sense key to find if reset happens.
1451
1452 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1453 @param SenseCounts The number of sense key
1454
1455 @retval TRUE It is reset before.
1456 @retval FALSE It is NOT reset before.
1457
1458 **/
1459 BOOLEAN
1460 ScsiDiskIsResetBefore (
1461 IN EFI_SCSI_SENSE_DATA *SenseData,
1462 IN UINTN SenseCounts
1463 );
1464
1465 /**
1466 Check sense key to find if the drive is ready.
1467
1468 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
1469 @param SenseCounts The number of sense key
1470 @param RetryLater The flag means if need a retry
1471
1472 @retval TRUE Drive is ready.
1473 @retval FALSE Drive is NOT ready.
1474
1475 **/
1476 BOOLEAN
1477 ScsiDiskIsDriveReady (
1478 IN EFI_SCSI_SENSE_DATA *SenseData,
1479 IN UINTN SenseCounts,
1480 OUT BOOLEAN *RetryLater
1481 );
1482
1483 /**
1484 Check sense key to find if it has sense key.
1485
1486 @param SenseData - The pointer of EFI_SCSI_SENSE_DATA
1487 @param SenseCounts - The number of sense key
1488
1489 @retval TRUE It has sense key.
1490 @retval FALSE It has NOT any sense key.
1491
1492 **/
1493 BOOLEAN
1494 ScsiDiskHaveSenseKey (
1495 IN EFI_SCSI_SENSE_DATA *SenseData,
1496 IN UINTN SenseCounts
1497 );
1498
1499 /**
1500 Release resource about disk device.
1501
1502 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
1503
1504 **/
1505 VOID
1506 ReleaseScsiDiskDeviceResources (
1507 IN SCSI_DISK_DEV *ScsiDiskDevice
1508 );
1509
1510 /**
1511 Determine if Block Io should be produced.
1512
1513
1514 @param ChildHandle Child Handle to retrieve Parent information.
1515
1516 @retval TRUE Should produce Block Io.
1517 @retval FALSE Should not produce Block Io.
1518
1519 **/
1520 BOOLEAN
1521 DetermineInstallBlockIo (
1522 IN EFI_HANDLE ChildHandle
1523 );
1524
1525 /**
1526 Initialize the installation of DiskInfo protocol.
1527
1528 This function prepares for the installation of DiskInfo protocol on the child handle.
1529 By default, it installs DiskInfo protocol with SCSI interface GUID. If it further
1530 detects that the physical device is an ATAPI/AHCI device, it then updates interface GUID
1531 to be IDE/AHCI interface GUID.
1532
1533 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1534 @param ChildHandle Child handle to install DiskInfo protocol.
1535
1536 **/
1537 VOID
1538 InitializeInstallDiskInfo (
1539 IN SCSI_DISK_DEV *ScsiDiskDevice,
1540 IN EFI_HANDLE ChildHandle
1541 );
1542
1543 /**
1544 Search protocol database and check to see if the protocol
1545 specified by ProtocolGuid is present on a ControllerHandle and opened by
1546 ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1547 If the ControllerHandle is found, then the protocol specified by ProtocolGuid
1548 will be opened on it.
1549
1550
1551 @param ProtocolGuid ProtocolGuid pointer.
1552 @param ChildHandle Child Handle to retrieve Parent information.
1553
1554 **/
1555 VOID *
1556 EFIAPI
1557 GetParentProtocol (
1558 IN EFI_GUID *ProtocolGuid,
1559 IN EFI_HANDLE ChildHandle
1560 );
1561
1562 /**
1563 Determine if EFI Erase Block Protocol should be produced.
1564
1565 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1566 @param ChildHandle Handle of device.
1567
1568 @retval TRUE Should produce EFI Erase Block Protocol.
1569 @retval FALSE Should not produce EFI Erase Block Protocol.
1570
1571 **/
1572 BOOLEAN
1573 DetermineInstallEraseBlock (
1574 IN SCSI_DISK_DEV *ScsiDiskDevice,
1575 IN EFI_HANDLE ChildHandle
1576 );
1577
1578 /**
1579 Determine if EFI Storage Security Command Protocol should be produced.
1580
1581 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
1582 @param ChildHandle Handle of device.
1583
1584 @retval TRUE Should produce EFI Storage Security Command Protocol.
1585 @retval FALSE Should not produce EFI Storage Security Command Protocol.
1586
1587 **/
1588 BOOLEAN
1589 DetermineInstallStorageSecurity (
1590 IN SCSI_DISK_DEV *ScsiDiskDevice,
1591 IN EFI_HANDLE ChildHandle
1592 );
1593
1594 #endif