]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c
MdeModulePkg: Change use of EFI_D_* to DEBUG_*
[mirror_edk2.git] / MdeModulePkg / Bus / Scsi / ScsiDiskDxe / ScsiDisk.c
index b5eff25b9b900e8111b7e64f5fd599d59b84da5f..b35d92fcd70eb7bb7af72c9b4cd003b1be8dc537 100644 (file)
@@ -1,14 +1,8 @@
 /** @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
@@ -79,9 +73,9 @@ FreeAlignedBuffer (
 \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
@@ -157,7 +151,9 @@ ScsiDiskDriverBindingSupported (
 \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
@@ -244,6 +240,8 @@ ScsiDiskDriverBindingStart (
   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
@@ -264,6 +262,10 @@ ScsiDiskDriverBindingStart (
     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
@@ -315,8 +317,8 @@ ScsiDiskDriverBindingStart (
     // 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
@@ -327,16 +329,27 @@ ScsiDiskDriverBindingStart (
                       &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
@@ -356,7 +369,7 @@ ScsiDiskDriverBindingStart (
           );\r
         return EFI_SUCCESS;\r
       }\r
-    } \r
+    }\r
   }\r
 \r
   gBS->FreePool (ScsiDiskDevice->SenseData);\r
@@ -368,7 +381,7 @@ ScsiDiskDriverBindingStart (
          Controller\r
          );\r
   return Status;\r
-  \r
+\r
 }\r
 \r
 \r
@@ -380,7 +393,7 @@ ScsiDiskDriverBindingStart (
   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
@@ -568,6 +581,7 @@ ScsiDiskReadBlocks (
   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
@@ -590,7 +604,7 @@ ScsiDiskReadBlocks (
              &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
@@ -598,16 +612,32 @@ ScsiDiskReadBlocks (
                &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
@@ -674,7 +704,7 @@ Done:
   @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
@@ -700,6 +730,7 @@ ScsiDiskWriteBlocks (
   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
@@ -722,7 +753,7 @@ ScsiDiskWriteBlocks (
              &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
@@ -730,16 +761,32 @@ ScsiDiskWriteBlocks (
                &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
@@ -922,6 +969,7 @@ ScsiDiskReadBlocksEx (
   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
@@ -944,7 +992,7 @@ ScsiDiskReadBlocksEx (
              &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
@@ -952,16 +1000,32 @@ ScsiDiskReadBlocksEx (
                &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
@@ -1081,6 +1145,7 @@ ScsiDiskWriteBlocksEx (
   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
@@ -1103,7 +1168,7 @@ ScsiDiskWriteBlocksEx (
              &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
@@ -1111,16 +1176,32 @@ ScsiDiskWriteBlocksEx (
                &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
@@ -1230,6 +1311,7 @@ ScsiDiskFlushBlocksEx (
   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
@@ -1252,7 +1334,7 @@ ScsiDiskFlushBlocksEx (
              &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
@@ -1260,13 +1342,23 @@ ScsiDiskFlushBlocksEx (
                &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
@@ -1328,7 +1420,7 @@ ScsiDiskAsyncUnmapNotify (
   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
@@ -1340,7 +1432,7 @@ ScsiDiskAsyncUnmapNotify (
   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
@@ -1522,7 +1614,7 @@ ScsiDiskUnmap (
   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
@@ -1534,7 +1626,7 @@ ScsiDiskUnmap (
   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
@@ -1631,7 +1723,7 @@ ScsiDiskEraseBlocks (
              &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
@@ -1639,6 +1731,14 @@ ScsiDiskEraseBlocks (
                &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
@@ -1695,13 +1795,438 @@ Done:
   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
@@ -1799,6 +2324,15 @@ ScsiDiskDetectMedia (
     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
@@ -1836,7 +2370,7 @@ ScsiDiskDetectMedia (
         } else {\r
           break;\r
         }\r
-      } else {   \r
+      } else {\r
         Retry++;\r
         if (!NeedRetry || (Retry >= MaxRetry)) {\r
           goto EXIT;\r
@@ -1976,7 +2510,7 @@ ScsiDiskInquiryDevice (
         // 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
@@ -1985,7 +2519,7 @@ ScsiDiskInquiryDevice (
         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
@@ -2001,7 +2535,7 @@ ScsiDiskInquiryDevice (
           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
@@ -2040,7 +2574,7 @@ ScsiDiskInquiryDevice (
                      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
@@ -2092,7 +2626,7 @@ ScsiDiskInquiryDevice (
   } 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
@@ -2128,7 +2662,7 @@ ScsiDiskInquiryDevice (
     *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
@@ -2284,7 +2818,7 @@ ScsiDiskTestUnitReady (
 \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
@@ -2327,30 +2861,30 @@ DetectMediaParsingSenseKeys (
     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
@@ -2358,7 +2892,7 @@ DetectMediaParsingSenseKeys (
   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
@@ -2366,7 +2900,7 @@ DetectMediaParsingSenseKeys (
   }\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
@@ -2425,7 +2959,7 @@ ScsiDiskReadCapacity (
   *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
@@ -2489,12 +3023,12 @@ ScsiDiskReadCapacity (
    // 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
@@ -2517,7 +3051,7 @@ ScsiDiskReadCapacity (
     *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
@@ -2597,7 +3131,7 @@ CheckHostAdapterStatus (
   @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
@@ -2632,7 +3166,7 @@ CheckTargetStatus (
 \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
@@ -2689,20 +3223,20 @@ ScsiDiskRequestSenseKeys (
               );\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
@@ -2724,7 +3258,7 @@ ScsiDiskRequestSenseKeys (
     // 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
@@ -2754,13 +3288,13 @@ GetMediaInfo (
   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
@@ -2780,7 +3314,7 @@ GetMediaInfo (
     *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
@@ -2851,7 +3385,7 @@ ScsiDiskReadSectors (
 \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
@@ -2904,7 +3438,7 @@ ScsiDiskReadSectors (
     // 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
@@ -2948,7 +3482,7 @@ ScsiDiskReadSectors (
       // 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
@@ -3069,7 +3603,7 @@ ScsiDiskWriteSectors (
     // 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
@@ -3095,7 +3629,7 @@ ScsiDiskWriteSectors (
                   &ByteCount,\r
                   Lba,\r
                   SectorCount\r
-                  );         \r
+                  );\r
         }\r
       if (!EFI_ERROR (Status)) {\r
         break;\r
@@ -3112,7 +3646,7 @@ ScsiDiskWriteSectors (
       // 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
@@ -3253,7 +3787,7 @@ ScsiDiskAsyncReadSectors (
     // 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
@@ -3470,7 +4004,7 @@ ScsiDiskAsyncWriteSectors (
     // 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
@@ -3609,10 +4143,10 @@ ScsiDiskRead10 (
   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
@@ -3672,7 +4206,7 @@ BackOff:
   }\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
@@ -3734,10 +4268,10 @@ ScsiDiskWrite10 (
   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
@@ -3796,7 +4330,7 @@ BackOff:
   }\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
@@ -3857,10 +4391,10 @@ ScsiDiskRead16 (
   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
@@ -3919,7 +4453,7 @@ BackOff:
   }\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
@@ -3981,10 +4515,10 @@ ScsiDiskWrite16 (
   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
@@ -4043,7 +4577,7 @@ BackOff:
   }\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
@@ -4152,7 +4686,7 @@ ScsiDiskNotify (
   }\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
@@ -4975,7 +5509,7 @@ ScsiDiskIsHardwareError (
   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
@@ -5052,7 +5586,7 @@ ScsiDiskIsResetBefore (
   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
@@ -5073,7 +5607,7 @@ ScsiDiskIsResetBefore (
 \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
@@ -5168,7 +5702,7 @@ ScsiDiskHaveSenseKey (
   SensePtr = SenseData;\r
 \r
   for (Index = 0; Index < SenseCounts; Index++) {\r
-    \r
+\r
     //\r
     // Sense Key is SK_NO_SENSE (0x0)\r
     //\r
@@ -5215,18 +5749,18 @@ ReleaseScsiDiskDeviceResources (
 \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
@@ -5252,7 +5786,7 @@ DetermineInstallBlockIo (
       return TRUE;\r
     }\r
   }\r
-  \r
+\r
   return FALSE;\r
 }\r
 \r
@@ -5261,23 +5795,23 @@ DetermineInstallBlockIo (
   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
@@ -5297,7 +5831,7 @@ GetParentProtocol (
   }\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
@@ -5312,7 +5846,7 @@ GetParentProtocol (
 \r
   gBS->FreePool (HandleBuffer);\r
   return NULL;\r
-} \r
+}\r
 \r
 /**\r
   Determine if EFI Erase Block Protocol should be produced.\r
@@ -5345,6 +5879,14 @@ DetermineInstallEraseBlock (
   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
@@ -5406,7 +5948,7 @@ DetermineInstallEraseBlock (
     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
@@ -5416,7 +5958,7 @@ DetermineInstallEraseBlock (
     }\r
   } else {\r
     DEBUG ((\r
-      EFI_D_VERBOSE,\r
+      DEBUG_VERBOSE,\r
       "ScsiDisk EraseBlock: ReadCapacity16 failed with status %r.\n",\r
       CommandStatus\r
       ));\r
@@ -5431,7 +5973,7 @@ DetermineInstallEraseBlock (
   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
@@ -5447,9 +5989,68 @@ Done:
   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
@@ -5458,9 +6059,9 @@ Done:
   @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
@@ -5492,16 +6093,16 @@ ScsiDiskInfoInquiry (
   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
@@ -5517,7 +6118,7 @@ ScsiDiskInfoIdentify (
 \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
@@ -5535,8 +6136,8 @@ ScsiDiskInfoIdentify (
 \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
@@ -5566,7 +6167,7 @@ ScsiDiskInfoSenseData (
 /**\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
@@ -5607,11 +6208,11 @@ ScsiDiskInfoWhichIde (
   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
@@ -5647,8 +6248,8 @@ AtapiIdentifyDevice (
 \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
@@ -5664,7 +6265,7 @@ InitializeInstallDiskInfo (
 \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
@@ -5696,7 +6297,7 @@ InitializeInstallDiskInfo (
             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
@@ -5707,7 +6308,7 @@ InitializeInstallDiskInfo (
             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