/** @file\r
SCSI disk driver that layers on every SCSI IO protocol in the system.\r
\r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
\r
The user code starts with this function.\r
\r
- @param ImageHandle The firmware allocated handle for the EFI image. \r
+ @param ImageHandle The firmware allocated handle for the EFI image.\r
@param SystemTable A pointer to the EFI System Table.\r
- \r
+\r
@retval EFI_SUCCESS The entry point is executed successfully.\r
@retval other Some error occurs when executing this entry point.\r
\r
\r
Status = ScsiIo->GetDeviceType (ScsiIo, &DeviceType);\r
if (!EFI_ERROR (Status)) {\r
- if ((DeviceType == EFI_SCSI_TYPE_DISK) || (DeviceType == EFI_SCSI_TYPE_CDROM)) {\r
+ if ((DeviceType == EFI_SCSI_TYPE_DISK) ||\r
+ (DeviceType == EFI_SCSI_TYPE_CDROM) ||\r
+ (DeviceType == EFI_SCSI_TYPE_WLUN)) {\r
Status = EFI_SUCCESS;\r
} else {\r
Status = EFI_UNSUPPORTED;\r
ScsiDiskDevice->BlkIo2.ReadBlocksEx = ScsiDiskReadBlocksEx;\r
ScsiDiskDevice->BlkIo2.WriteBlocksEx = ScsiDiskWriteBlocksEx;\r
ScsiDiskDevice->BlkIo2.FlushBlocksEx = ScsiDiskFlushBlocksEx;\r
+ ScsiDiskDevice->StorageSecurity.ReceiveData = ScsiDiskReceiveData;\r
+ ScsiDiskDevice->StorageSecurity.SendData = ScsiDiskSendData;\r
ScsiDiskDevice->EraseBlock.Revision = EFI_ERASE_BLOCK_PROTOCOL_REVISION;\r
ScsiDiskDevice->EraseBlock.EraseLengthGranularity = 1;\r
ScsiDiskDevice->EraseBlock.EraseBlocks = ScsiDiskEraseBlocks;\r
ScsiDiskDevice->BlkIo.Media->ReadOnly = TRUE;\r
MustReadCapacity = FALSE;\r
break;\r
+\r
+ case EFI_SCSI_TYPE_WLUN:\r
+ MustReadCapacity = FALSE;\r
+ break;\r
}\r
//\r
// The Sense Data Array's initial size is 6\r
// Determine if Block IO & Block IO2 should be produced on this controller\r
// handle\r
//\r
- if (DetermineInstallBlockIo(Controller)) {\r
- InitializeInstallDiskInfo(ScsiDiskDevice, Controller);\r
+ if (DetermineInstallBlockIo (Controller)) {\r
+ InitializeInstallDiskInfo (ScsiDiskDevice, Controller);\r
Status = gBS->InstallMultipleProtocolInterfaces (\r
&Controller,\r
&gEfiBlockIoProtocolGuid,\r
&ScsiDiskDevice->DiskInfo,\r
NULL\r
);\r
- if (!EFI_ERROR(Status)) {\r
- if (DetermineInstallEraseBlock(ScsiDiskDevice, Controller)) {\r
+ if (!EFI_ERROR (Status)) {\r
+ if (DetermineInstallEraseBlock (ScsiDiskDevice, Controller)) {\r
Status = gBS->InstallProtocolInterface (\r
&Controller,\r
&gEfiEraseBlockProtocolGuid,\r
EFI_NATIVE_INTERFACE,\r
&ScsiDiskDevice->EraseBlock\r
);\r
- if (EFI_ERROR(Status)) {\r
- DEBUG ((EFI_D_ERROR, "ScsiDisk: Failed to install the Erase Block Protocol! Status = %r\n", Status));\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((DEBUG_ERROR, "ScsiDisk: Failed to install the Erase Block Protocol! Status = %r\n", Status));\r
+ }\r
+ }\r
+ if (DetermineInstallStorageSecurity (ScsiDiskDevice, Controller)) {\r
+ Status = gBS->InstallProtocolInterface (\r
+ &Controller,\r
+ &gEfiStorageSecurityCommandProtocolGuid,\r
+ EFI_NATIVE_INTERFACE,\r
+ &ScsiDiskDevice->StorageSecurity\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((DEBUG_ERROR, "ScsiDisk: Failed to install the Storage Security Command Protocol! Status = %r\n", Status));\r
}\r
}\r
ScsiDiskDevice->ControllerNameTable = NULL;\r
);\r
return EFI_SUCCESS;\r
}\r
- } \r
+ }\r
}\r
\r
gBS->FreePool (ScsiDiskDevice->SenseData);\r
Controller\r
);\r
return Status;\r
- \r
+\r
}\r
\r
\r
restrictions for this service. DisconnectController() must follow these\r
calling restrictions. If any other agent wishes to call Stop() it must\r
also follow these calling restrictions.\r
- \r
+\r
@param This Protocol instance pointer.\r
@param ControllerHandle Handle of device to stop driver on\r
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
MediaChange = FALSE;\r
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
ScsiDiskDevice = SCSI_DISK_DEV_FROM_BLKIO (This);\r
+ Media = ScsiDiskDevice->BlkIo.Media;\r
\r
if (!IS_DEVICE_FIXED(ScsiDiskDevice)) {\r
\r
&ScsiDiskDevice->BlkIo2,\r
&ScsiDiskDevice->BlkIo2\r
);\r
- if (DetermineInstallEraseBlock(ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
+ if (DetermineInstallEraseBlock (ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
gBS->ReinstallProtocolInterface (\r
ScsiDiskDevice->Handle,\r
&gEfiEraseBlockProtocolGuid,\r
&ScsiDiskDevice->EraseBlock\r
);\r
}\r
- Status = EFI_MEDIA_CHANGED;\r
+ if (DetermineInstallStorageSecurity (ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
+ gBS->ReinstallProtocolInterface (\r
+ ScsiDiskDevice->Handle,\r
+ &gEfiStorageSecurityCommandProtocolGuid,\r
+ &ScsiDiskDevice->StorageSecurity,\r
+ &ScsiDiskDevice->StorageSecurity\r
+ );\r
+ }\r
+ if (Media->MediaPresent) {\r
+ Status = EFI_MEDIA_CHANGED;\r
+ } else {\r
+ Status = EFI_NO_MEDIA;\r
+ }\r
goto Done;\r
}\r
}\r
//\r
// Get the intrinsic block size\r
//\r
- Media = ScsiDiskDevice->BlkIo.Media;\r
BlockSize = Media->BlockSize;\r
\r
+ if (BlockSize == 0) {\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Done;\r
+ }\r
+\r
NumberOfBlocks = BufferSize / BlockSize;\r
\r
if (!(Media->MediaPresent)) {\r
@retval EFI_WRITE_PROTECTED The device can not be written to.\r
@retval EFI_DEVICE_ERROR Fail to detect media.\r
@retval EFI_NO_MEDIA Media is not present.\r
- @retval EFI_MEDIA_CHNAGED Media has changed.\r
+ @retval EFI_MEDIA_CHANGED Media has changed.\r
@retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r
@retval EFI_INVALID_PARAMETER Invalid parameter passed in.\r
\r
MediaChange = FALSE;\r
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
ScsiDiskDevice = SCSI_DISK_DEV_FROM_BLKIO (This);\r
+ Media = ScsiDiskDevice->BlkIo.Media;\r
\r
if (!IS_DEVICE_FIXED(ScsiDiskDevice)) {\r
\r
&ScsiDiskDevice->BlkIo2,\r
&ScsiDiskDevice->BlkIo2\r
);\r
- if (DetermineInstallEraseBlock(ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
+ if (DetermineInstallEraseBlock (ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
gBS->ReinstallProtocolInterface (\r
ScsiDiskDevice->Handle,\r
&gEfiEraseBlockProtocolGuid,\r
&ScsiDiskDevice->EraseBlock\r
);\r
}\r
- Status = EFI_MEDIA_CHANGED;\r
+ if (DetermineInstallStorageSecurity (ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
+ gBS->ReinstallProtocolInterface (\r
+ ScsiDiskDevice->Handle,\r
+ &gEfiStorageSecurityCommandProtocolGuid,\r
+ &ScsiDiskDevice->StorageSecurity,\r
+ &ScsiDiskDevice->StorageSecurity\r
+ );\r
+ }\r
+ if (Media->MediaPresent) {\r
+ Status = EFI_MEDIA_CHANGED;\r
+ } else {\r
+ Status = EFI_NO_MEDIA;\r
+ }\r
goto Done;\r
}\r
}\r
//\r
// Get the intrinsic block size\r
//\r
- Media = ScsiDiskDevice->BlkIo.Media;\r
BlockSize = Media->BlockSize;\r
\r
+ if (BlockSize == 0) {\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Done;\r
+ }\r
+\r
NumberOfBlocks = BufferSize / BlockSize;\r
\r
if (!(Media->MediaPresent)) {\r
MediaChange = FALSE;\r
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
ScsiDiskDevice = SCSI_DISK_DEV_FROM_BLKIO2 (This);\r
+ Media = ScsiDiskDevice->BlkIo.Media;\r
\r
if (!IS_DEVICE_FIXED(ScsiDiskDevice)) {\r
\r
&ScsiDiskDevice->BlkIo2,\r
&ScsiDiskDevice->BlkIo2\r
);\r
- if (DetermineInstallEraseBlock(ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
+ if (DetermineInstallEraseBlock (ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
gBS->ReinstallProtocolInterface (\r
ScsiDiskDevice->Handle,\r
&gEfiEraseBlockProtocolGuid,\r
&ScsiDiskDevice->EraseBlock\r
);\r
}\r
- Status = EFI_MEDIA_CHANGED;\r
+ if (DetermineInstallStorageSecurity (ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
+ gBS->ReinstallProtocolInterface (\r
+ ScsiDiskDevice->Handle,\r
+ &gEfiStorageSecurityCommandProtocolGuid,\r
+ &ScsiDiskDevice->StorageSecurity,\r
+ &ScsiDiskDevice->StorageSecurity\r
+ );\r
+ }\r
+ if (Media->MediaPresent) {\r
+ Status = EFI_MEDIA_CHANGED;\r
+ } else {\r
+ Status = EFI_NO_MEDIA;\r
+ }\r
goto Done;\r
}\r
}\r
//\r
// Get the intrinsic block size\r
//\r
- Media = ScsiDiskDevice->BlkIo2.Media;\r
BlockSize = Media->BlockSize;\r
\r
+ if (BlockSize == 0) {\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Done;\r
+ }\r
+\r
NumberOfBlocks = BufferSize / BlockSize;\r
\r
if (!(Media->MediaPresent)) {\r
MediaChange = FALSE;\r
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
ScsiDiskDevice = SCSI_DISK_DEV_FROM_BLKIO2 (This);\r
+ Media = ScsiDiskDevice->BlkIo.Media;\r
\r
if (!IS_DEVICE_FIXED(ScsiDiskDevice)) {\r
\r
&ScsiDiskDevice->BlkIo2,\r
&ScsiDiskDevice->BlkIo2\r
);\r
- if (DetermineInstallEraseBlock(ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
+ if (DetermineInstallEraseBlock (ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
gBS->ReinstallProtocolInterface (\r
ScsiDiskDevice->Handle,\r
&gEfiEraseBlockProtocolGuid,\r
&ScsiDiskDevice->EraseBlock\r
);\r
}\r
- Status = EFI_MEDIA_CHANGED;\r
+ if (DetermineInstallStorageSecurity (ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
+ gBS->ReinstallProtocolInterface (\r
+ ScsiDiskDevice->Handle,\r
+ &gEfiStorageSecurityCommandProtocolGuid,\r
+ &ScsiDiskDevice->StorageSecurity,\r
+ &ScsiDiskDevice->StorageSecurity\r
+ );\r
+ }\r
+ if (Media->MediaPresent) {\r
+ Status = EFI_MEDIA_CHANGED;\r
+ } else {\r
+ Status = EFI_NO_MEDIA;\r
+ }\r
goto Done;\r
}\r
}\r
//\r
// Get the intrinsic block size\r
//\r
- Media = ScsiDiskDevice->BlkIo2.Media;\r
BlockSize = Media->BlockSize;\r
\r
+ if (BlockSize == 0) {\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Done;\r
+ }\r
+\r
NumberOfBlocks = BufferSize / BlockSize;\r
\r
if (!(Media->MediaPresent)) {\r
MediaChange = FALSE;\r
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
ScsiDiskDevice = SCSI_DISK_DEV_FROM_BLKIO2 (This);\r
+ Media = ScsiDiskDevice->BlkIo.Media;\r
\r
if (!IS_DEVICE_FIXED(ScsiDiskDevice)) {\r
\r
&ScsiDiskDevice->BlkIo2,\r
&ScsiDiskDevice->BlkIo2\r
);\r
- if (DetermineInstallEraseBlock(ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
+ if (DetermineInstallEraseBlock (ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
gBS->ReinstallProtocolInterface (\r
ScsiDiskDevice->Handle,\r
&gEfiEraseBlockProtocolGuid,\r
&ScsiDiskDevice->EraseBlock\r
);\r
}\r
- Status = EFI_MEDIA_CHANGED;\r
+ if (DetermineInstallStorageSecurity (ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
+ gBS->ReinstallProtocolInterface (\r
+ ScsiDiskDevice->Handle,\r
+ &gEfiStorageSecurityCommandProtocolGuid,\r
+ &ScsiDiskDevice->StorageSecurity,\r
+ &ScsiDiskDevice->StorageSecurity\r
+ );\r
+ }\r
+ if (Media->MediaPresent) {\r
+ Status = EFI_MEDIA_CHANGED;\r
+ } else {\r
+ Status = EFI_NO_MEDIA;\r
+ }\r
goto Done;\r
}\r
}\r
\r
- Media = ScsiDiskDevice->BlkIo2.Media;\r
-\r
if (!(Media->MediaPresent)) {\r
Status = EFI_NO_MEDIA;\r
goto Done;\r
Status = CheckHostAdapterStatus (CommandPacket->HostAdapterStatus);\r
if (EFI_ERROR(Status)) {\r
DEBUG ((\r
- EFI_D_ERROR,\r
+ DEBUG_ERROR,\r
"ScsiDiskAsyncUnmapNotify: Host adapter indicating error status 0x%x.\n",\r
CommandPacket->HostAdapterStatus\r
));\r
Status = CheckTargetStatus (CommandPacket->TargetStatus);\r
if (EFI_ERROR(Status)) {\r
DEBUG ((\r
- EFI_D_ERROR,\r
+ DEBUG_ERROR,\r
"ScsiDiskAsyncUnmapNotify: Target indicating error status 0x%x.\n",\r
CommandPacket->HostAdapterStatus\r
));\r
Status = CheckHostAdapterStatus (CommandPacket->HostAdapterStatus);\r
if (EFI_ERROR(Status)) {\r
DEBUG ((\r
- EFI_D_ERROR,\r
+ DEBUG_ERROR,\r
"ScsiDiskUnmap: Host adapter indicating error status 0x%x.\n",\r
CommandPacket->HostAdapterStatus\r
));\r
Status = CheckTargetStatus (CommandPacket->TargetStatus);\r
if (EFI_ERROR(Status)) {\r
DEBUG ((\r
- EFI_D_ERROR,\r
+ DEBUG_ERROR,\r
"ScsiDiskUnmap: Target indicating error status 0x%x.\n",\r
CommandPacket->HostAdapterStatus\r
));\r
&ScsiDiskDevice->BlkIo2,\r
&ScsiDiskDevice->BlkIo2\r
);\r
- if (DetermineInstallEraseBlock(ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
+ if (DetermineInstallEraseBlock (ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
gBS->ReinstallProtocolInterface (\r
ScsiDiskDevice->Handle,\r
&gEfiEraseBlockProtocolGuid,\r
&ScsiDiskDevice->EraseBlock\r
);\r
}\r
+ if (DetermineInstallStorageSecurity (ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
+ gBS->ReinstallProtocolInterface (\r
+ ScsiDiskDevice->Handle,\r
+ &gEfiStorageSecurityCommandProtocolGuid,\r
+ &ScsiDiskDevice->StorageSecurity,\r
+ &ScsiDiskDevice->StorageSecurity\r
+ );\r
+ }\r
Status = EFI_MEDIA_CHANGED;\r
goto Done;\r
}\r
return Status;\r
}\r
\r
+/**\r
+ Send a security protocol command to a device that receives data and/or the result\r
+ of one or more commands sent by SendData.\r
+\r
+ The ReceiveData function sends a security protocol command to the given MediaId.\r
+ The security protocol command sent is defined by SecurityProtocolId and contains\r
+ the security protocol specific data SecurityProtocolSpecificData. The function\r
+ returns the data from the security protocol command in PayloadBuffer.\r
+\r
+ For devices supporting the SCSI command set, the security protocol command is sent\r
+ using the SECURITY PROTOCOL IN command defined in SPC-4.\r
+\r
+ If PayloadBufferSize is too small to store the available data from the security\r
+ protocol command, the function shall copy PayloadBufferSize bytes into the\r
+ PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.\r
+\r
+ If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,\r
+ the function shall return EFI_INVALID_PARAMETER.\r
+\r
+ If the given MediaId does not support security protocol commands, the function shall\r
+ return EFI_UNSUPPORTED. If there is no media in the device, the function returns\r
+ EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the device,\r
+ the function returns EFI_MEDIA_CHANGED.\r
+\r
+ If the security protocol fails to complete within the Timeout period, the function\r
+ shall return EFI_TIMEOUT.\r
+\r
+ If the security protocol command completes without an error, the function shall\r
+ return EFI_SUCCESS. If the security protocol command completes with an error, the\r
+ function shall return EFI_DEVICE_ERROR.\r
+\r
+ @param This Indicates a pointer to the calling context.\r
+ @param MediaId ID of the medium to receive data from.\r
+ @param Timeout The timeout, in 100ns units, to use for the execution\r
+ of the security protocol command. A Timeout value of 0\r
+ means that this function will wait indefinitely for the\r
+ security protocol command to execute. If Timeout is greater\r
+ than zero, then this function will return EFI_TIMEOUT if the\r
+ time required to execute the receive data command is greater than Timeout.\r
+ @param SecurityProtocolId The value of the "Security Protocol" parameter of\r
+ the security protocol command to be sent.\r
+ @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter\r
+ of the security protocol command to be sent.\r
+ @param PayloadBufferSize Size in bytes of the payload data buffer.\r
+ @param PayloadBuffer A pointer to a destination buffer to store the security\r
+ protocol command specific payload data for the security\r
+ protocol command. The caller is responsible for having\r
+ either implicit or explicit ownership of the buffer.\r
+ @param PayloadTransferSize A pointer to a buffer to store the size in bytes of the\r
+ data written to the payload data buffer.\r
+\r
+ @retval EFI_SUCCESS The security protocol command completed successfully.\r
+ @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to store the available\r
+ data from the device. The PayloadBuffer contains the truncated data.\r
+ @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.\r
+ @retval EFI_DEVICE_ERROR The security protocol command completed with an error.\r
+ @retval EFI_NO_MEDIA There is no media in the device.\r
+ @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r
+ @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize is NULL and\r
+ PayloadBufferSize is non-zero.\r
+ @retval EFI_TIMEOUT A timeout occurred while waiting for the security\r
+ protocol command to execute.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ScsiDiskReceiveData (\r
+ IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,\r
+ IN UINT32 MediaId OPTIONAL,\r
+ IN UINT64 Timeout,\r
+ IN UINT8 SecurityProtocolId,\r
+ IN UINT16 SecurityProtocolSpecificData,\r
+ IN UINTN PayloadBufferSize,\r
+ OUT VOID *PayloadBuffer,\r
+ OUT UINTN *PayloadTransferSize\r
+ )\r
+{\r
+ SCSI_DISK_DEV *ScsiDiskDevice;\r
+ EFI_BLOCK_IO_MEDIA *Media;\r
+ EFI_STATUS Status;\r
+ BOOLEAN MediaChange;\r
+ EFI_TPL OldTpl;\r
+ UINT8 SenseDataLength;\r
+ UINT8 HostAdapterStatus;\r
+ UINT8 TargetStatus;\r
+ VOID *AlignedBuffer;\r
+ BOOLEAN AlignedBufferAllocated;\r
+\r
+ AlignedBuffer = NULL;\r
+ MediaChange = FALSE;\r
+ AlignedBufferAllocated = FALSE;\r
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+ ScsiDiskDevice = SCSI_DISK_DEV_FROM_STORSEC (This);\r
+ Media = ScsiDiskDevice->BlkIo.Media;\r
+\r
+ SenseDataLength = (UINT8) (ScsiDiskDevice->SenseDataNumber * sizeof (EFI_SCSI_SENSE_DATA));\r
+\r
+ if (!IS_DEVICE_FIXED (ScsiDiskDevice)) {\r
+ Status = ScsiDiskDetectMedia (ScsiDiskDevice, FALSE, &MediaChange);\r
+ if (EFI_ERROR (Status)) {\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Done;\r
+ }\r
+\r
+ if (MediaChange) {\r
+ gBS->ReinstallProtocolInterface (\r
+ ScsiDiskDevice->Handle,\r
+ &gEfiBlockIoProtocolGuid,\r
+ &ScsiDiskDevice->BlkIo,\r
+ &ScsiDiskDevice->BlkIo\r
+ );\r
+ gBS->ReinstallProtocolInterface (\r
+ ScsiDiskDevice->Handle,\r
+ &gEfiBlockIo2ProtocolGuid,\r
+ &ScsiDiskDevice->BlkIo2,\r
+ &ScsiDiskDevice->BlkIo2\r
+ );\r
+ if (DetermineInstallEraseBlock (ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
+ gBS->ReinstallProtocolInterface (\r
+ ScsiDiskDevice->Handle,\r
+ &gEfiEraseBlockProtocolGuid,\r
+ &ScsiDiskDevice->EraseBlock,\r
+ &ScsiDiskDevice->EraseBlock\r
+ );\r
+ }\r
+ if (DetermineInstallStorageSecurity (ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
+ gBS->ReinstallProtocolInterface (\r
+ ScsiDiskDevice->Handle,\r
+ &gEfiStorageSecurityCommandProtocolGuid,\r
+ &ScsiDiskDevice->StorageSecurity,\r
+ &ScsiDiskDevice->StorageSecurity\r
+ );\r
+ }\r
+ if (Media->MediaPresent) {\r
+ Status = EFI_MEDIA_CHANGED;\r
+ } else {\r
+ Status = EFI_NO_MEDIA;\r
+ }\r
+ goto Done;\r
+ }\r
+ }\r
+\r
+ //\r
+ // Validate Media\r
+ //\r
+ if (!(Media->MediaPresent)) {\r
+ Status = EFI_NO_MEDIA;\r
+ goto Done;\r
+ }\r
+\r
+ if ((MediaId != 0) && (MediaId != Media->MediaId)) {\r
+ Status = EFI_MEDIA_CHANGED;\r
+ goto Done;\r
+ }\r
+\r
+ if (PayloadBufferSize != 0) {\r
+ if ((PayloadBuffer == NULL) || (PayloadTransferSize == NULL)) {\r
+ Status = EFI_INVALID_PARAMETER;\r
+ goto Done;\r
+ }\r
+\r
+ if ((ScsiDiskDevice->ScsiIo->IoAlign > 1) && !IS_ALIGNED (PayloadBuffer, ScsiDiskDevice->ScsiIo->IoAlign)) {\r
+ AlignedBuffer = AllocateAlignedBuffer (ScsiDiskDevice, PayloadBufferSize);\r
+ if (AlignedBuffer == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Done;\r
+ }\r
+ ZeroMem (AlignedBuffer, PayloadBufferSize);\r
+ AlignedBufferAllocated = TRUE;\r
+ } else {\r
+ AlignedBuffer = PayloadBuffer;\r
+ }\r
+ }\r
+\r
+ Status = ScsiSecurityProtocolInCommand (\r
+ ScsiDiskDevice->ScsiIo,\r
+ Timeout,\r
+ ScsiDiskDevice->SenseData,\r
+ &SenseDataLength,\r
+ &HostAdapterStatus,\r
+ &TargetStatus,\r
+ SecurityProtocolId,\r
+ SecurityProtocolSpecificData,\r
+ FALSE,\r
+ PayloadBufferSize,\r
+ AlignedBuffer,\r
+ PayloadTransferSize\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto Done;\r
+ }\r
+\r
+ if (AlignedBufferAllocated) {\r
+ CopyMem (PayloadBuffer, AlignedBuffer, PayloadBufferSize);\r
+ }\r
+\r
+ if (PayloadBufferSize < *PayloadTransferSize) {\r
+ Status = EFI_WARN_BUFFER_TOO_SMALL;\r
+ goto Done;\r
+ }\r
+\r
+ Status = CheckHostAdapterStatus (HostAdapterStatus);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Done;\r
+ }\r
+\r
+ Status = CheckTargetStatus (TargetStatus);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Done;\r
+ }\r
+\r
+Done:\r
+ if (AlignedBufferAllocated) {\r
+ ZeroMem (AlignedBuffer, PayloadBufferSize);\r
+ FreeAlignedBuffer (AlignedBuffer, PayloadBufferSize);\r
+ }\r
+ gBS->RestoreTPL (OldTpl);\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Send a security protocol command to a device.\r
+\r
+ The SendData function sends a security protocol command containing the payload\r
+ PayloadBuffer to the given MediaId. The security protocol command sent is\r
+ defined by SecurityProtocolId and contains the security protocol specific data\r
+ SecurityProtocolSpecificData. If the underlying protocol command requires a\r
+ specific padding for the command payload, the SendData function shall add padding\r
+ bytes to the command payload to satisfy the padding requirements.\r
+\r
+ For devices supporting the SCSI command set, the security protocol command is sent\r
+ using the SECURITY PROTOCOL OUT command defined in SPC-4.\r
+\r
+ If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall\r
+ return EFI_INVALID_PARAMETER.\r
+\r
+ If the given MediaId does not support security protocol commands, the function\r
+ shall return EFI_UNSUPPORTED. If there is no media in the device, the function\r
+ returns EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the\r
+ device, the function returns EFI_MEDIA_CHANGED.\r
+\r
+ If the security protocol fails to complete within the Timeout period, the function\r
+ shall return EFI_TIMEOUT.\r
+\r
+ If the security protocol command completes without an error, the function shall return\r
+ EFI_SUCCESS. If the security protocol command completes with an error, the function\r
+ shall return EFI_DEVICE_ERROR.\r
+\r
+ @param This Indicates a pointer to the calling context.\r
+ @param MediaId ID of the medium to receive data from.\r
+ @param Timeout The timeout, in 100ns units, to use for the execution\r
+ of the security protocol command. A Timeout value of 0\r
+ means that this function will wait indefinitely for the\r
+ security protocol command to execute. If Timeout is greater\r
+ than zero, then this function will return EFI_TIMEOUT if the\r
+ time required to execute the receive data command is greater than Timeout.\r
+ @param SecurityProtocolId The value of the "Security Protocol" parameter of\r
+ the security protocol command to be sent.\r
+ @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter\r
+ of the security protocol command to be sent.\r
+ @param PayloadBufferSize Size in bytes of the payload data buffer.\r
+ @param PayloadBuffer A pointer to a destination buffer to store the security\r
+ protocol command specific payload data for the security\r
+ protocol command.\r
+\r
+ @retval EFI_SUCCESS The security protocol command completed successfully.\r
+ @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.\r
+ @retval EFI_DEVICE_ERROR The security protocol command completed with an error.\r
+ @retval EFI_NO_MEDIA There is no media in the device.\r
+ @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r
+ @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize is non-zero.\r
+ @retval EFI_TIMEOUT A timeout occurred while waiting for the security\r
+ protocol command to execute.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ScsiDiskSendData (\r
+ IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,\r
+ IN UINT32 MediaId OPTIONAL,\r
+ IN UINT64 Timeout,\r
+ IN UINT8 SecurityProtocolId,\r
+ IN UINT16 SecurityProtocolSpecificData,\r
+ IN UINTN PayloadBufferSize,\r
+ OUT VOID *PayloadBuffer\r
+ )\r
+{\r
+ SCSI_DISK_DEV *ScsiDiskDevice;\r
+ EFI_BLOCK_IO_MEDIA *Media;\r
+ EFI_STATUS Status;\r
+ BOOLEAN MediaChange;\r
+ EFI_TPL OldTpl;\r
+ UINT8 SenseDataLength;\r
+ UINT8 HostAdapterStatus;\r
+ UINT8 TargetStatus;\r
+ VOID *AlignedBuffer;\r
+ BOOLEAN AlignedBufferAllocated;\r
+\r
+ AlignedBuffer = NULL;\r
+ MediaChange = FALSE;\r
+ AlignedBufferAllocated = FALSE;\r
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+ ScsiDiskDevice = SCSI_DISK_DEV_FROM_STORSEC (This);\r
+ Media = ScsiDiskDevice->BlkIo.Media;\r
+\r
+ SenseDataLength = (UINT8) (ScsiDiskDevice->SenseDataNumber * sizeof (EFI_SCSI_SENSE_DATA));\r
+\r
+ if (!IS_DEVICE_FIXED (ScsiDiskDevice)) {\r
+ Status = ScsiDiskDetectMedia (ScsiDiskDevice, FALSE, &MediaChange);\r
+ if (EFI_ERROR (Status)) {\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Done;\r
+ }\r
+\r
+ if (MediaChange) {\r
+ gBS->ReinstallProtocolInterface (\r
+ ScsiDiskDevice->Handle,\r
+ &gEfiBlockIoProtocolGuid,\r
+ &ScsiDiskDevice->BlkIo,\r
+ &ScsiDiskDevice->BlkIo\r
+ );\r
+ gBS->ReinstallProtocolInterface (\r
+ ScsiDiskDevice->Handle,\r
+ &gEfiBlockIo2ProtocolGuid,\r
+ &ScsiDiskDevice->BlkIo2,\r
+ &ScsiDiskDevice->BlkIo2\r
+ );\r
+ if (DetermineInstallEraseBlock (ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
+ gBS->ReinstallProtocolInterface (\r
+ ScsiDiskDevice->Handle,\r
+ &gEfiEraseBlockProtocolGuid,\r
+ &ScsiDiskDevice->EraseBlock,\r
+ &ScsiDiskDevice->EraseBlock\r
+ );\r
+ }\r
+ if (DetermineInstallStorageSecurity (ScsiDiskDevice, ScsiDiskDevice->Handle)) {\r
+ gBS->ReinstallProtocolInterface (\r
+ ScsiDiskDevice->Handle,\r
+ &gEfiStorageSecurityCommandProtocolGuid,\r
+ &ScsiDiskDevice->StorageSecurity,\r
+ &ScsiDiskDevice->StorageSecurity\r
+ );\r
+ }\r
+ if (Media->MediaPresent) {\r
+ Status = EFI_MEDIA_CHANGED;\r
+ } else {\r
+ Status = EFI_NO_MEDIA;\r
+ }\r
+ goto Done;\r
+ }\r
+ }\r
+\r
+ //\r
+ // Validate Media\r
+ //\r
+ if (!(Media->MediaPresent)) {\r
+ Status = EFI_NO_MEDIA;\r
+ goto Done;\r
+ }\r
+\r
+ if ((MediaId != 0) && (MediaId != Media->MediaId)) {\r
+ Status = EFI_MEDIA_CHANGED;\r
+ goto Done;\r
+ }\r
+\r
+ if (Media->ReadOnly) {\r
+ Status = EFI_WRITE_PROTECTED;\r
+ goto Done;\r
+ }\r
+\r
+ if (PayloadBufferSize != 0) {\r
+ if (PayloadBuffer == NULL) {\r
+ Status = EFI_INVALID_PARAMETER;\r
+ goto Done;\r
+ }\r
+\r
+ if ((ScsiDiskDevice->ScsiIo->IoAlign > 1) && !IS_ALIGNED (PayloadBuffer, ScsiDiskDevice->ScsiIo->IoAlign)) {\r
+ AlignedBuffer = AllocateAlignedBuffer (ScsiDiskDevice, PayloadBufferSize);\r
+ if (AlignedBuffer == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Done;\r
+ }\r
+ CopyMem (AlignedBuffer, PayloadBuffer, PayloadBufferSize);\r
+ AlignedBufferAllocated = TRUE;\r
+ } else {\r
+ AlignedBuffer = PayloadBuffer;\r
+ }\r
+ }\r
+\r
+ Status = ScsiSecurityProtocolOutCommand (\r
+ ScsiDiskDevice->ScsiIo,\r
+ Timeout,\r
+ ScsiDiskDevice->SenseData,\r
+ &SenseDataLength,\r
+ &HostAdapterStatus,\r
+ &TargetStatus,\r
+ SecurityProtocolId,\r
+ SecurityProtocolSpecificData,\r
+ FALSE,\r
+ PayloadBufferSize,\r
+ AlignedBuffer\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto Done;\r
+ }\r
+\r
+ Status = CheckHostAdapterStatus (HostAdapterStatus);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Done;\r
+ }\r
+\r
+ Status = CheckTargetStatus (TargetStatus);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Done;\r
+ }\r
+\r
+Done:\r
+ if (AlignedBufferAllocated) {\r
+ ZeroMem (AlignedBuffer, PayloadBufferSize);\r
+ FreeAlignedBuffer (AlignedBuffer, PayloadBufferSize);\r
+ }\r
+ gBS->RestoreTPL (OldTpl);\r
+ return Status;\r
+}\r
+\r
\r
/**\r
Detect Device and read out capacity ,if error occurs, parse the sense key.\r
\r
@param ScsiDiskDevice The pointer of SCSI_DISK_DEV\r
@param MustReadCapacity The flag about reading device capacity\r
- @param MediaChange The pointer of flag indicates if media has changed \r
+ @param MediaChange The pointer of flag indicates if media has changed\r
\r
@retval EFI_DEVICE_ERROR Indicates that error occurs\r
@retval EFI_SUCCESS Successfully to detect media\r
NeedReadCapacity = TRUE;\r
}\r
\r
+ //\r
+ // READ_CAPACITY command is not supported by any of the UFS WLUNs.\r
+ //\r
+ if (ScsiDiskDevice->DeviceType == EFI_SCSI_TYPE_WLUN) {\r
+ NeedReadCapacity = FALSE;\r
+ MustReadCapacity = FALSE;\r
+ ScsiDiskDevice->BlkIo.Media->MediaPresent = TRUE;\r
+ }\r
+\r
//\r
// either NeedReadCapacity is TRUE, or MustReadCapacity is TRUE,\r
// retrieve capacity via Read Capacity command\r
} else {\r
break;\r
}\r
- } else { \r
+ } else {\r
Retry++;\r
if (!NeedRetry || (Retry >= MaxRetry)) {\r
goto EXIT;\r
// Sanity checks for coping with broken devices\r
//\r
if (PageLength > sizeof SupportedVpdPages->SupportedVpdPageList) {\r
- DEBUG ((EFI_D_WARN,\r
+ DEBUG ((DEBUG_WARN,\r
"%a: invalid PageLength (%u) in Supported VPD Pages page\n",\r
__FUNCTION__, (UINT32)PageLength));\r
PageLength = 0;\r
if ((PageLength > 0) &&\r
(SupportedVpdPages->SupportedVpdPageList[0] !=\r
EFI_SCSI_PAGE_CODE_SUPPORTED_VPD)) {\r
- DEBUG ((EFI_D_WARN,\r
+ DEBUG ((DEBUG_WARN,\r
"%a: Supported VPD Pages page doesn't start with code 0x%02x\n",\r
__FUNCTION__, EFI_SCSI_PAGE_CODE_SUPPORTED_VPD));\r
PageLength = 0;\r
if ((Index > 0) &&\r
(SupportedVpdPages->SupportedVpdPageList[Index] <=\r
SupportedVpdPages->SupportedVpdPageList[Index - 1])) {\r
- DEBUG ((EFI_D_WARN,\r
+ DEBUG ((DEBUG_WARN,\r
"%a: non-ascending code in Supported VPD Pages page @ %u\n",\r
__FUNCTION__, Index));\r
Index = 0;\r
EFI_SCSI_PAGE_CODE_BLOCK_LIMITS_VPD\r
);\r
if (!EFI_ERROR (Status)) {\r
- ScsiDiskDevice->BlkIo.Media->OptimalTransferLengthGranularity = \r
+ ScsiDiskDevice->BlkIo.Media->OptimalTransferLengthGranularity =\r
(BlockLimits->OptimalTransferLengthGranularity2 << 8) |\r
BlockLimits->OptimalTransferLengthGranularity1;\r
\r
} else if (Status == EFI_NOT_READY) {\r
*NeedRetry = TRUE;\r
return EFI_DEVICE_ERROR;\r
- \r
+\r
} else if ((Status == EFI_INVALID_PARAMETER) || (Status == EFI_UNSUPPORTED)) {\r
*NeedRetry = FALSE;\r
return EFI_DEVICE_ERROR;\r
*NeedRetry = FALSE;\r
return EFI_DEVICE_ERROR;\r
}\r
- \r
+\r
//\r
// if goes here, meant ScsiInquiryCommand() failed.\r
// if ScsiDiskRequestSenseKeys() succeeds at last,\r
\r
@param ScsiDiskDevice The pointer of SCSI_DISK_DEV\r
@param SenseData The pointer of EFI_SCSI_SENSE_DATA\r
- @param NumberOfSenseKeys The number of sense key \r
+ @param NumberOfSenseKeys The number of sense key\r
@param Action The pointer of action which indicates what is need to do next\r
\r
@retval EFI_DEVICE_ERROR Indicates that error occurs\r
ScsiDiskDevice->BlkIo.Media->MediaPresent = FALSE;\r
ScsiDiskDevice->BlkIo.Media->LastBlock = 0;\r
*Action = ACTION_NO_ACTION;\r
- DEBUG ((EFI_D_VERBOSE, "ScsiDisk: ScsiDiskIsNoMedia\n"));\r
+ DEBUG ((DEBUG_VERBOSE, "ScsiDisk: ScsiDiskIsNoMedia\n"));\r
return EFI_SUCCESS;\r
}\r
\r
if (ScsiDiskIsMediaChange (SenseData, NumberOfSenseKeys)) {\r
ScsiDiskDevice->BlkIo.Media->MediaId++;\r
- DEBUG ((EFI_D_VERBOSE, "ScsiDisk: ScsiDiskIsMediaChange!\n"));\r
+ DEBUG ((DEBUG_VERBOSE, "ScsiDisk: ScsiDiskIsMediaChange!\n"));\r
return EFI_SUCCESS;\r
}\r
\r
if (ScsiDiskIsResetBefore (SenseData, NumberOfSenseKeys)) {\r
*Action = ACTION_RETRY_COMMAND_LATER;\r
- DEBUG ((EFI_D_VERBOSE, "ScsiDisk: ScsiDiskIsResetBefore!\n"));\r
+ DEBUG ((DEBUG_VERBOSE, "ScsiDisk: ScsiDiskIsResetBefore!\n"));\r
return EFI_SUCCESS;\r
}\r
\r
if (ScsiDiskIsMediaError (SenseData, NumberOfSenseKeys)) {\r
- DEBUG ((EFI_D_VERBOSE, "ScsiDisk: ScsiDiskIsMediaError\n"));\r
+ DEBUG ((DEBUG_VERBOSE, "ScsiDisk: ScsiDiskIsMediaError\n"));\r
*Action = ACTION_RETRY_WITH_BACKOFF_ALGO;\r
return EFI_DEVICE_ERROR;\r
}\r
\r
if (ScsiDiskIsHardwareError (SenseData, NumberOfSenseKeys)) {\r
- DEBUG ((EFI_D_VERBOSE, "ScsiDisk: ScsiDiskIsHardwareError\n"));\r
+ DEBUG ((DEBUG_VERBOSE, "ScsiDisk: ScsiDiskIsHardwareError\n"));\r
*Action = ACTION_RETRY_WITH_BACKOFF_ALGO;\r
return EFI_DEVICE_ERROR;\r
}\r
if (!ScsiDiskIsDriveReady (SenseData, NumberOfSenseKeys, &RetryLater)) {\r
if (RetryLater) {\r
*Action = ACTION_RETRY_COMMAND_LATER;\r
- DEBUG ((EFI_D_VERBOSE, "ScsiDisk: ScsiDiskDriveNotReady!\n"));\r
+ DEBUG ((DEBUG_VERBOSE, "ScsiDisk: ScsiDiskDriveNotReady!\n"));\r
return EFI_SUCCESS;\r
}\r
*Action = ACTION_NO_ACTION;\r
}\r
\r
*Action = ACTION_RETRY_WITH_BACKOFF_ALGO;\r
- DEBUG ((EFI_D_VERBOSE, "ScsiDisk: Sense Key = 0x%x ASC = 0x%x!\n", SenseData->Sense_Key, SenseData->Addnl_Sense_Code));\r
+ DEBUG ((DEBUG_VERBOSE, "ScsiDisk: Sense Key = 0x%x ASC = 0x%x!\n", SenseData->Sense_Key, SenseData->Addnl_Sense_Code));\r
return EFI_SUCCESS;\r
}\r
\r
*NeedRetry = FALSE;\r
\r
//\r
- // submit Read Capacity(10) Command. If it returns capacity of FFFFFFFFh, \r
+ // submit Read Capacity(10) Command. If it returns capacity of FFFFFFFFh,\r
// 16 byte command should be used to access large hard disk >2TB\r
//\r
CommandStatus = ScsiReadCapacityCommand (\r
// go ahead to check HostAdapterStatus and TargetStatus\r
// (EFI_TIMEOUT, EFI_DEVICE_ERROR, EFI_WARN_BUFFER_TOO_SMALL)\r
//\r
- \r
+\r
Status = CheckHostAdapterStatus (HostAdapterStatus);\r
if ((Status == EFI_TIMEOUT) || (Status == EFI_NOT_READY)) {\r
*NeedRetry = TRUE;\r
return EFI_DEVICE_ERROR;\r
- \r
+\r
} else if (Status == EFI_DEVICE_ERROR) {\r
//\r
// reset the scsi channel\r
*NeedRetry = FALSE;\r
return EFI_DEVICE_ERROR;\r
}\r
- \r
+\r
//\r
// if goes here, meant ScsiReadCapacityCommand() failed.\r
// if ScsiDiskRequestSenseKeys() succeeds at last,\r
@param TargetStatus Target status\r
\r
@retval EFI_NOT_READY Device is NOT ready.\r
- @retval EFI_DEVICE_ERROR \r
+ @retval EFI_DEVICE_ERROR\r
@retval EFI_SUCCESS\r
\r
**/\r
\r
When encountering error during the process, if retrieve sense keys before\r
error encountered, it returns the sense keys with return status set to EFI_SUCCESS,\r
- and NeedRetry set to FALSE; otherwize, return the proper return status.\r
+ and NeedRetry set to FALSE; otherwise, return the proper return status.\r
\r
@param ScsiDiskDevice The pointer of SCSI_DISK_DEV\r
@param NeedRetry The pointer of flag indicates if need a retry\r
);\r
if ((Status == EFI_SUCCESS) || (Status == EFI_WARN_BUFFER_TOO_SMALL)) {\r
FallStatus = EFI_SUCCESS;\r
- \r
+\r
} else if ((Status == EFI_TIMEOUT) || (Status == EFI_NOT_READY)) {\r
*NeedRetry = TRUE;\r
FallStatus = EFI_DEVICE_ERROR;\r
- \r
+\r
} else if ((Status == EFI_INVALID_PARAMETER) || (Status == EFI_UNSUPPORTED)) {\r
*NeedRetry = FALSE;\r
FallStatus = EFI_DEVICE_ERROR;\r
- \r
+\r
} else if (Status == EFI_DEVICE_ERROR) {\r
if (AskResetIfError) {\r
ScsiDiskDevice->ScsiIo->ResetDevice (ScsiDiskDevice->ScsiIo);\r
}\r
- \r
+\r
FallStatus = EFI_DEVICE_ERROR;\r
}\r
\r
// no more sense key or number of sense keys exceeds predefined,\r
// skip the loop.\r
//\r
- if ((PtrSenseData->Sense_Key == EFI_SCSI_SK_NO_SENSE) || \r
+ if ((PtrSenseData->Sense_Key == EFI_SCSI_SK_NO_SENSE) ||\r
(*NumberOfSenseKeys == ScsiDiskDevice->SenseDataNumber)) {\r
SenseReq = FALSE;\r
}\r
UINT8 *Ptr;\r
\r
if (!ScsiDiskDevice->Cdb16Byte) {\r
- ScsiDiskDevice->BlkIo.Media->LastBlock = (Capacity10->LastLba3 << 24) |\r
+ ScsiDiskDevice->BlkIo.Media->LastBlock = ((UINT32) Capacity10->LastLba3 << 24) |\r
(Capacity10->LastLba2 << 16) |\r
(Capacity10->LastLba1 << 8) |\r
Capacity10->LastLba0;\r
- \r
+\r
ScsiDiskDevice->BlkIo.Media->BlockSize = (Capacity10->BlockSize3 << 24) |\r
- (Capacity10->BlockSize2 << 16) | \r
+ (Capacity10->BlockSize2 << 16) |\r
(Capacity10->BlockSize1 << 8) |\r
Capacity10->BlockSize0;\r
ScsiDiskDevice->BlkIo.Media->LowestAlignedLba = 0;\r
*Ptr = Capacity16->LastLba7;\r
\r
ScsiDiskDevice->BlkIo.Media->BlockSize = (Capacity16->BlockSize3 << 24) |\r
- (Capacity16->BlockSize2 << 16) | \r
+ (Capacity16->BlockSize2 << 16) |\r
(Capacity16->BlockSize1 << 8) |\r
Capacity16->BlockSize0;\r
\r
\r
BlocksRemaining = NumberOfBlocks;\r
BlockSize = ScsiDiskDevice->BlkIo.Media->BlockSize;\r
- \r
+\r
//\r
// limit the data bytes that can be transferred by one Read(10) or Read(16) Command\r
//\r
// As ScsiDisk and ScsiBus driver are used to manage SCSI or ATAPI devices, we have to use\r
// the lowest transfer rate to calculate the possible maximum timeout value for each operation.\r
// From the above table, we could know 2.1Mbytes per second is lowest one.\r
- // The timout value is rounded up to nearest integar and here an additional 30s is added\r
+ // The timeout value is rounded up to nearest integer and here an additional 30s is added\r
// to follow ATA spec in which it mentioned that the device may take up to 30s to respond\r
// commands in the Standby/Idle mode.\r
//\r
// it is invalid to request more sectors in the CDB than the entire\r
// transfer (ie. ByteCount) can carry.\r
//\r
- // In addition, ByteCount is only expected to go down, or stay unchaged.\r
+ // In addition, ByteCount is only expected to go down, or stay unchanged.\r
// Therefore we don't need to update Timeout: the original timeout should\r
// accommodate shorter transfers too.\r
//\r
// As ScsiDisk and ScsiBus driver are used to manage SCSI or ATAPI devices, we have to use\r
// the lowest transfer rate to calculate the possible maximum timeout value for each operation.\r
// From the above table, we could know 2.1Mbytes per second is lowest one.\r
- // The timout value is rounded up to nearest integar and here an additional 30s is added\r
+ // The timeout value is rounded up to nearest integer and here an additional 30s is added\r
// to follow ATA spec in which it mentioned that the device may take up to 30s to respond\r
// commands in the Standby/Idle mode.\r
//\r
&ByteCount,\r
Lba,\r
SectorCount\r
- ); \r
+ );\r
}\r
if (!EFI_ERROR (Status)) {\r
break;\r
// it is invalid to request more sectors in the CDB than the entire\r
// transfer (ie. ByteCount) can carry.\r
//\r
- // In addition, ByteCount is only expected to go down, or stay unchaged.\r
+ // In addition, ByteCount is only expected to go down, or stay unchanged.\r
// Therefore we don't need to update Timeout: the original timeout should\r
// accommodate shorter transfers too.\r
//\r
// we have to use the lowest transfer rate to calculate the possible\r
// maximum timeout value for each operation.\r
// From the above table, we could know 2.1Mbytes per second is lowest one.\r
- // The timout value is rounded up to nearest integar and here an additional\r
+ // The timeout value is rounded up to nearest integer and here an additional\r
// 30s is added to follow ATA spec in which it mentioned that the device\r
// may take up to 30s to respond commands in the Standby/Idle mode.\r
//\r
// we have to use the lowest transfer rate to calculate the possible\r
// maximum timeout value for each operation.\r
// From the above table, we could know 2.1Mbytes per second is lowest one.\r
- // The timout value is rounded up to nearest integar and here an additional\r
+ // The timeout value is rounded up to nearest integer and here an additional\r
// 30s is added to follow ATA spec in which it mentioned that the device\r
// may take up to 30s to respond commands in the Standby/Idle mode.\r
//\r
UINTN Action;\r
\r
//\r
- // Implement a backoff algorithem to resolve some compatibility issues that\r
+ // Implement a backoff algorithm to resolve some compatibility issues that\r
// some SCSI targets or ATAPI devices couldn't correctly response reading/writing\r
// big data in a single operation.\r
- // This algorithem will at first try to execute original request. If the request fails\r
+ // This algorithm will at first try to execute original request. If the request fails\r
// with media error sense data or else, it will reduce the transfer length to half and\r
// try again till the operation succeeds or fails with one sector transfer length.\r
//\r
}\r
\r
if ((TargetStatus == EFI_EXT_SCSI_STATUS_TARGET_CHECK_CONDITION) || (EFI_ERROR (ReturnStatus))) {\r
- DEBUG ((EFI_D_ERROR, "ScsiDiskRead10: Check Condition happened!\n"));\r
+ DEBUG ((DEBUG_ERROR, "ScsiDiskRead10: Check Condition happened!\n"));\r
Status = DetectMediaParsingSenseKeys (ScsiDiskDevice, ScsiDiskDevice->SenseData, SenseDataLength / sizeof (EFI_SCSI_SENSE_DATA), &Action);\r
if (Action == ACTION_RETRY_COMMAND_LATER) {\r
*NeedRetry = TRUE;\r
UINTN Action;\r
\r
//\r
- // Implement a backoff algorithem to resolve some compatibility issues that\r
+ // Implement a backoff algorithm to resolve some compatibility issues that\r
// some SCSI targets or ATAPI devices couldn't correctly response reading/writing\r
// big data in a single operation.\r
- // This algorithem will at first try to execute original request. If the request fails\r
+ // This algorithm will at first try to execute original request. If the request fails\r
// with media error sense data or else, it will reduce the transfer length to half and\r
// try again till the operation succeeds or fails with one sector transfer length.\r
//\r
}\r
\r
if ((TargetStatus == EFI_EXT_SCSI_STATUS_TARGET_CHECK_CONDITION) || (EFI_ERROR (ReturnStatus))) {\r
- DEBUG ((EFI_D_ERROR, "ScsiDiskWrite10: Check Condition happened!\n"));\r
+ DEBUG ((DEBUG_ERROR, "ScsiDiskWrite10: Check Condition happened!\n"));\r
Status = DetectMediaParsingSenseKeys (ScsiDiskDevice, ScsiDiskDevice->SenseData, SenseDataLength / sizeof (EFI_SCSI_SENSE_DATA), &Action);\r
if (Action == ACTION_RETRY_COMMAND_LATER) {\r
*NeedRetry = TRUE;\r
UINTN Action;\r
\r
//\r
- // Implement a backoff algorithem to resolve some compatibility issues that\r
+ // Implement a backoff algorithm to resolve some compatibility issues that\r
// some SCSI targets or ATAPI devices couldn't correctly response reading/writing\r
// big data in a single operation.\r
- // This algorithem will at first try to execute original request. If the request fails\r
+ // This algorithm will at first try to execute original request. If the request fails\r
// with media error sense data or else, it will reduce the transfer length to half and\r
// try again till the operation succeeds or fails with one sector transfer length.\r
//\r
}\r
\r
if ((TargetStatus == EFI_EXT_SCSI_STATUS_TARGET_CHECK_CONDITION) || (EFI_ERROR (ReturnStatus))) {\r
- DEBUG ((EFI_D_ERROR, "ScsiDiskRead16: Check Condition happened!\n"));\r
+ DEBUG ((DEBUG_ERROR, "ScsiDiskRead16: Check Condition happened!\n"));\r
Status = DetectMediaParsingSenseKeys (ScsiDiskDevice, ScsiDiskDevice->SenseData, SenseDataLength / sizeof (EFI_SCSI_SENSE_DATA), &Action);\r
if (Action == ACTION_RETRY_COMMAND_LATER) {\r
*NeedRetry = TRUE;\r
UINTN Action;\r
\r
//\r
- // Implement a backoff algorithem to resolve some compatibility issues that\r
+ // Implement a backoff algorithm to resolve some compatibility issues that\r
// some SCSI targets or ATAPI devices couldn't correctly response reading/writing\r
// big data in a single operation.\r
- // This algorithem will at first try to execute original request. If the request fails\r
+ // This algorithm will at first try to execute original request. If the request fails\r
// with media error sense data or else, it will reduce the transfer length to half and\r
// try again till the operation succeeds or fails with one sector transfer length.\r
//\r
}\r
\r
if ((TargetStatus == EFI_EXT_SCSI_STATUS_TARGET_CHECK_CONDITION) || (EFI_ERROR (ReturnStatus))) {\r
- DEBUG ((EFI_D_ERROR, "ScsiDiskWrite16: Check Condition happened!\n"));\r
+ DEBUG ((DEBUG_ERROR, "ScsiDiskWrite16: Check Condition happened!\n"));\r
Status = DetectMediaParsingSenseKeys (ScsiDiskDevice, ScsiDiskDevice->SenseData, SenseDataLength / sizeof (EFI_SCSI_SENSE_DATA), &Action);\r
if (Action == ACTION_RETRY_COMMAND_LATER) {\r
*NeedRetry = TRUE;\r
}\r
\r
if (Request->TargetStatus == EFI_EXT_SCSI_STATUS_TARGET_CHECK_CONDITION) {\r
- DEBUG ((EFI_D_ERROR, "ScsiDiskNotify: Check Condition happened!\n"));\r
+ DEBUG ((DEBUG_ERROR, "ScsiDiskNotify: Check Condition happened!\n"));\r
\r
Status = DetectMediaParsingSenseKeys (\r
ScsiDiskDevice,\r
SensePtr = SenseData;\r
\r
for (Index = 0; Index < SenseCounts; Index++) {\r
- \r
+\r
//\r
// Sense Key is EFI_SCSI_SK_HARDWARE_ERROR (0x4)\r
//\r
SensePtr = SenseData;\r
\r
for (Index = 0; Index < SenseCounts; Index++) {\r
- \r
+\r
//\r
// Sense Key is EFI_SCSI_SK_UNIT_ATTENTION (0x6)\r
// Additional Sense Code is EFI_SCSI_ASC_RESET (0x29)\r
\r
@param SenseData The pointer of EFI_SCSI_SENSE_DATA\r
@param SenseCounts The number of sense key\r
- @param RetryLater The flag means if need a retry \r
+ @param RetryLater The flag means if need a retry\r
\r
@retval TRUE Drive is ready.\r
@retval FALSE Drive is NOT ready.\r
SensePtr = SenseData;\r
\r
for (Index = 0; Index < SenseCounts; Index++) {\r
- \r
+\r
//\r
// Sense Key is SK_NO_SENSE (0x0)\r
//\r
\r
/**\r
Determine if Block Io & Block Io2 should be produced.\r
- \r
+\r
\r
@param ChildHandle Child Handle to retrieve Parent information.\r
- \r
+\r
@retval TRUE Should produce Block Io & Block Io2.\r
@retval FALSE Should not produce Block Io & Block Io2.\r
\r
-**/ \r
+**/\r
BOOLEAN\r
DetermineInstallBlockIo (\r
IN EFI_HANDLE ChildHandle\r
- ) \r
+ )\r
{\r
EFI_SCSI_PASS_THRU_PROTOCOL *ScsiPassThru;\r
EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtScsiPassThru;\r
return TRUE;\r
}\r
}\r
- \r
+\r
return FALSE;\r
}\r
\r
specified by ProtocolGuid is present on a ControllerHandle and opened by\r
ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
If the ControllerHandle is found, then the protocol specified by ProtocolGuid\r
- will be opened on it. \r
- \r
+ will be opened on it.\r
+\r
\r
@param ProtocolGuid ProtocolGuid pointer.\r
@param ChildHandle Child Handle to retrieve Parent information.\r
- \r
-**/ \r
+\r
+**/\r
VOID *\r
EFIAPI\r
GetParentProtocol (\r
IN EFI_GUID *ProtocolGuid,\r
IN EFI_HANDLE ChildHandle\r
- ) \r
+ )\r
{\r
UINTN Index;\r
UINTN HandleCount;\r
- VOID *Interface; \r
+ VOID *Interface;\r
EFI_STATUS Status;\r
EFI_HANDLE *HandleBuffer;\r
\r
}\r
\r
//\r
- // Iterate to find who is parent handle that is opened with ProtocolGuid by ChildHandle \r
+ // Iterate to find who is parent handle that is opened with ProtocolGuid by ChildHandle\r
//\r
for (Index = 0; Index < HandleCount; Index++) {\r
Status = EfiTestChildHandle (HandleBuffer[Index], ChildHandle, ProtocolGuid);\r
\r
gBS->FreePool (HandleBuffer);\r
return NULL;\r
-} \r
+}\r
\r
/**\r
Determine if EFI Erase Block Protocol should be produced.\r
RetVal = TRUE;\r
CapacityData16 = NULL;\r
\r
+ //\r
+ // UNMAP command is not supported by any of the UFS WLUNs.\r
+ //\r
+ if (ScsiDiskDevice->DeviceType == EFI_SCSI_TYPE_WLUN) {\r
+ RetVal = FALSE;\r
+ goto Done;\r
+ }\r
+\r
Status = gBS->HandleProtocol (\r
ChildHandle,\r
&gEfiDevicePathProtocolGuid,\r
if (((CapacityData16->LowestAlignLogic2 & BIT7) == 0) ||\r
((CapacityData16->LowestAlignLogic2 & BIT6) == 0)) {\r
DEBUG ((\r
- EFI_D_VERBOSE,\r
+ DEBUG_VERBOSE,\r
"ScsiDisk EraseBlock: Either TPE or TPRZ is not set: 0x%x.\n",\r
CapacityData16->LowestAlignLogic2\r
));\r
}\r
} else {\r
DEBUG ((\r
- EFI_D_VERBOSE,\r
+ DEBUG_VERBOSE,\r
"ScsiDisk EraseBlock: ReadCapacity16 failed with status %r.\n",\r
CommandStatus\r
));\r
if ((ScsiDiskDevice->UnmapInfo.MaxLbaCnt == 0) ||\r
(ScsiDiskDevice->UnmapInfo.MaxBlkDespCnt == 0)) {\r
DEBUG ((\r
- EFI_D_VERBOSE,\r
+ DEBUG_VERBOSE,\r
"ScsiDisk EraseBlock: The device server does not implement the UNMAP command.\n"\r
));\r
\r
return RetVal;\r
}\r
\r
+/**\r
+ Determine if EFI Storage Security Command Protocol should be produced.\r
+\r
+ @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.\r
+ @param ChildHandle Handle of device.\r
+\r
+ @retval TRUE Should produce EFI Storage Security Command Protocol.\r
+ @retval FALSE Should not produce EFI Storage Security Command Protocol.\r
+\r
+**/\r
+BOOLEAN\r
+DetermineInstallStorageSecurity (\r
+ IN SCSI_DISK_DEV *ScsiDiskDevice,\r
+ IN EFI_HANDLE ChildHandle\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ UFS_DEVICE_PATH *UfsDevice;\r
+ BOOLEAN RetVal;\r
+ EFI_DEVICE_PATH_PROTOCOL *DevicePathNode;\r
+\r
+ UfsDevice = NULL;\r
+ RetVal = TRUE;\r
+\r
+ Status = gBS->HandleProtocol (\r
+ ChildHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ (VOID **) &DevicePathNode\r
+ );\r
+ //\r
+ // Device Path protocol must be installed on the device handle.\r
+ //\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ while (!IsDevicePathEndType (DevicePathNode)) {\r
+ //\r
+ // For now, only support Storage Security Command Protocol on UFS devices.\r
+ //\r
+ if ((DevicePathNode->Type == MESSAGING_DEVICE_PATH) &&\r
+ (DevicePathNode->SubType == MSG_UFS_DP)) {\r
+ UfsDevice = (UFS_DEVICE_PATH *) DevicePathNode;\r
+ break;\r
+ }\r
+\r
+ DevicePathNode = NextDevicePathNode (DevicePathNode);\r
+ }\r
+ if (UfsDevice == NULL) {\r
+ RetVal = FALSE;\r
+ goto Done;\r
+ }\r
+\r
+ if (UfsDevice->Lun != UFS_WLUN_RPMB) {\r
+ RetVal = FALSE;\r
+ }\r
+\r
+Done:\r
+ return RetVal;\r
+}\r
+\r
/**\r
Provides inquiry information for the controller type.\r
- \r
+\r
This function is used by the IDE bus driver to get inquiry data. Data format\r
of Identify data is defined by the Interface GUID.\r
\r
@param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.\r
\r
@retval EFI_SUCCESS The command was accepted without any errors.\r
- @retval EFI_NOT_FOUND Device does not support this data class \r
- @retval EFI_DEVICE_ERROR Error reading InquiryData from device \r
- @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough \r
+ @retval EFI_NOT_FOUND Device does not support this data class\r
+ @retval EFI_DEVICE_ERROR Error reading InquiryData from device\r
+ @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough\r
\r
**/\r
EFI_STATUS\r
This function is used by the IDE bus driver to get identify data. Data format\r
of Identify data is defined by the Interface GUID.\r
\r
- @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL \r
+ @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL\r
instance.\r
@param[in, out] IdentifyData Pointer to a buffer for the identify data.\r
@param[in, out] IdentifyDataSize Pointer to the value for the identify data\r
size.\r
\r
@retval EFI_SUCCESS The command was accepted without any errors.\r
- @retval EFI_NOT_FOUND Device does not support this data class \r
- @retval EFI_DEVICE_ERROR Error reading IdentifyData from device \r
- @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough \r
+ @retval EFI_NOT_FOUND Device does not support this data class\r
+ @retval EFI_DEVICE_ERROR Error reading IdentifyData from device\r
+ @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough\r
\r
**/\r
EFI_STATUS\r
\r
if (CompareGuid (&This->Interface, &gEfiDiskInfoScsiInterfaceGuid) || CompareGuid (&This->Interface, &gEfiDiskInfoUfsInterfaceGuid)) {\r
//\r
- // Physical SCSI bus does not support this data class. \r
+ // Physical SCSI bus does not support this data class.\r
//\r
return EFI_NOT_FOUND;\r
}\r
\r
/**\r
Provides sense data information for the controller type.\r
- \r
- This function is used by the IDE bus driver to get sense data. \r
+\r
+ This function is used by the IDE bus driver to get sense data.\r
Data format of Sense data is defined by the Interface GUID.\r
\r
@param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r
/**\r
This function is used by the IDE bus driver to get controller information.\r
\r
- @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance. \r
+ @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r
@param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.\r
@param[out] IdeDevice Pointer to the Ide Device number. Master or slave.\r
\r
via SCSI Request Packet.\r
\r
@param ScsiDiskDevice The pointer of SCSI_DISK_DEV\r
- \r
+\r
@retval EFI_SUCCESS The ATAPI device identify data were retrieved successfully.\r
@retval others Some error occurred during the identification that ATAPI device.\r
\r
-**/ \r
+**/\r
EFI_STATUS\r
AtapiIdentifyDevice (\r
IN OUT SCSI_DISK_DEV *ScsiDiskDevice\r
\r
@param ScsiDiskDevice The pointer of SCSI_DISK_DEV.\r
@param ChildHandle Child handle to install DiskInfo protocol.\r
- \r
-**/ \r
+\r
+**/\r
VOID\r
InitializeInstallDiskInfo (\r
IN SCSI_DISK_DEV *ScsiDiskDevice,\r
\r
Status = gBS->HandleProtocol (ChildHandle, &gEfiDevicePathProtocolGuid, (VOID **) &DevicePathNode);\r
//\r
- // Device Path protocol must be installed on the device handle. \r
+ // Device Path protocol must be installed on the device handle.\r
//\r
ASSERT_EFI_ERROR (Status);\r
//\r
ScsiDiskDevice->Channel = AtapiDevicePath->PrimarySecondary;\r
ScsiDiskDevice->Device = AtapiDevicePath->SlaveMaster;\r
//\r
- // Update the DiskInfo.Interface to IDE interface GUID for the physical ATAPI device. \r
+ // Update the DiskInfo.Interface to IDE interface GUID for the physical ATAPI device.\r
//\r
CopyGuid (&ScsiDiskDevice->DiskInfo.Interface, &gEfiDiskInfoIdeInterfaceGuid);\r
} else {\r
ScsiDiskDevice->Channel = SataDevicePath->HBAPortNumber;\r
ScsiDiskDevice->Device = SataDevicePath->PortMultiplierPortNumber;\r
//\r
- // Update the DiskInfo.Interface to AHCI interface GUID for the physical AHCI device. \r
+ // Update the DiskInfo.Interface to AHCI interface GUID for the physical AHCI device.\r
//\r
CopyGuid (&ScsiDiskDevice->DiskInfo.Interface, &gEfiDiskInfoAhciInterfaceGuid);\r
}\r