]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiScsiLib/UefiScsiLib.c
Minor grammatical work--mostly adding periods. Items with ONLY period added did...
[mirror_edk2.git] / MdePkg / Library / UefiScsiLib / UefiScsiLib.c
index d2ad70b380438796c85059f14efa3d5e112ea0dc..8f885fa9b414fd62a24a2c26a84d1ba9bb6e528d 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
   UEFI SCSI Library implementation\r
 \r
-  Copyright (c) 2006 - 2008, Intel Corporation.<BR>\r
-  All rights reserved. This program and the accompanying materials                          \r
+  Copyright (c) 2006 - 2010, 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
+  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
@@ -14,6 +14,7 @@
 \r
 \r
 #include <Uefi.h>\r
+#include <Library/BaseLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/UefiScsiLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #define EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK 0xe0\r
   \r
   //\r
-  // Scsi Command Length six or ten\r
+  // Scsi Command Length\r
   //\r
-#define EFI_SCSI_OP_LENGTH_SIX 0x6\r
-#define EFI_SCSI_OP_LENGTH_TEN 0xa\r
+#define EFI_SCSI_OP_LENGTH_SIX      0x6\r
+#define EFI_SCSI_OP_LENGTH_TEN      0xa\r
+#define EFI_SCSI_OP_LENGTH_SIXTEEN  0x10\r
 \r
 \r
 \r
@@ -67,7 +69,7 @@
                                     If SenseDataLength is 0, then this parameter is\r
                                     optional and may be NULL.\r
   @param[in, out] SenseDataLength   On input, a pointer to the length in bytes of\r
-                                    the SenseData buffer. On output, a poiinter to\r
+                                    the SenseData buffer. On output, a pointer to\r
                                     the number of bytes written to the SenseData buffer. \r
   @param[out]     HostAdapterStatus The status of the SCSI Host Controller that produces\r
                                     the SCSI bus containing the SCSI target specified by\r
@@ -75,7 +77,7 @@
                                     See the EFI SCSI I/O Protocol in the UEFI Specification\r
                                     for details on the possible return values.\r
   @param[out]     TargetStatus      The status returned by the SCSI target specified\r
-                                    by ScsiIo when the SCSI Request Packat was executed\r
+                                    by ScsiIo when the SCSI Request Packet was executed\r
                                     on the SCSI Host Controller. See the EFI SCSI I/O\r
                                     Protocol in the UEFI Specification for details on\r
                                     the possible return values. \r
                                Packet to execute.  See HostAdapterStatus, TargetStatus,\r
                                SenseDataLength, and SenseData in that order for\r
                                additional status information.\r
-  @retval EFI_BAD_BUFFER_SIZE  The SCSI Request Packet was executed, \r
-                               but the entire DataBuffer could not be transferred.\r
-                               The actual number of bytes transferred is returned\r
-                               in InTransferLength.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -147,7 +145,7 @@ ScsiTestUnitReadyCommand (
   ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
 \r
   Cdb[0]                        = EFI_SCSI_OP_TEST_UNIT_READY;\r
-  Cdb[1]                        = (UINT8) (Lun & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
+  Cdb[1]                        = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
   CommandPacket.CdbLength       = (UINT8) EFI_SCSI_OP_LENGTH_SIX;\r
   CommandPacket.SenseDataLength = *SenseDataLength;\r
 \r
@@ -196,7 +194,7 @@ ScsiTestUnitReadyCommand (
                                          SCSI I/O Protocol in the UEFI Specification\r
                                          for details on the possible return values.\r
   @param[out]     TargetStatus           The status returned by the SCSI target specified\r
-                                         by ScsiIo when the SCSI Request Packat was\r
+                                         by ScsiIo when the SCSI Request Packet was\r
                                          executed on the SCSI Host Controller.\r
                                          See the EFI SCSI I/O Protocol in the UEFI\r
                                          Specification for details on the possible\r
@@ -215,7 +213,7 @@ ScsiTestUnitReadyCommand (
                                          If FALSE, then the standard inquiry data is\r
                                          returned in InquiryDataBuffer. \r
 \r
-  @retval EFI_SUCCESS          The command was executed successfully. See HostAdapterStatus,\r
+  @retval EFI_SUCCESS          The command executed successfully. See HostAdapterStatus,\r
                                TargetStatus, SenseDataLength, and SenseData in that order\r
                                for additional status information.\r
   @retval EFI_BAD_BUFFER_SIZE  The SCSI Request Packet was executed, but the entire\r
@@ -280,7 +278,7 @@ ScsiInquiryCommand (
   ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
 \r
   Cdb[0]  = EFI_SCSI_OP_INQUIRY;\r
-  Cdb[1]  = (UINT8) (Lun & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
+  Cdb[1]  = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
   if (EnableVitalProductData) {\r
     Cdb[1] |= 0x01;\r
   }\r
@@ -342,7 +340,7 @@ ScsiInquiryCommand (
                                      UEFI Specification for details on the possible\r
                                      return values.\r
   @param[out]     TargetStatus       The status returned by the SCSI target specified\r
-                                     by ScsiIo when the SCSI Request Packat was executed\r
+                                     by ScsiIo when the SCSI Request Packet was executed\r
                                      on the SCSI Host Controller.  See the EFI SCSI\r
                                      I/O Protocol in the UEFI Specification for details\r
                                      on the possible return values.\r
@@ -359,7 +357,7 @@ ScsiInquiryCommand (
   @param[in]      PageControl        Specifies the PC field of the CDB for this SCSI Command. \r
   @param[in]      PageCode           Specifies the Page Control field of the CDB for this SCSI Command. \r
 \r
-  @retval EFI_SUCCESS               The command was executed successfully.\r
+  @retval EFI_SUCCESS               The command executed successfully.\r
                                     See HostAdapterStatus, TargetStatus, SenseDataLength,\r
                                     and SenseData in that order for additional status information.\r
   @retval EFI_BAD_BUFFER_SIZE       The SCSI Request Packet was executed, but the\r
@@ -432,11 +430,11 @@ ScsiModeSense10Command (
   //\r
   // DBDField is in Cdb[1] bit3 of (bit7..0)\r
   //\r
-  Cdb[1]                        = (UINT8) ((Lun & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK) + ((DBDField << 3) & 0x08));\r
+  Cdb[1]                        = (UINT8) ((LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK) + ((DBDField << 3) & 0x08));\r
   //\r
   // PageControl is in Cdb[2] bit7..6, PageCode is in Cdb[2] bit5..0\r
   //\r
-  Cdb[2]                        = (UINT8) ((PageControl & 0xc0) | (PageCode & 0x3f));\r
+  Cdb[2]                        = (UINT8) (((PageControl << 6) & 0xc0) | (PageCode & 0x3f));\r
   Cdb[7]                        = (UINT8) (*DataLength >> 8);\r
   Cdb[8]                        = (UINT8) (*DataLength);\r
 \r
@@ -473,7 +471,7 @@ ScsiModeSense10Command (
   @param[out]      HostAdapterStatus    The status of Host Adapter.\r
   @param[out]      TargetStatus         The status of the target.\r
 \r
-  @retval EFI_SUCCESS                   Command is executed successfully.\r
+  @retval EFI_SUCCESS                   The command executed successfully.\r
   @retval EFI_NOT_READY                 The SCSI Request Packet could not be sent because there are\r
                                         too many SCSI Command Packets already queued.\r
   @retval EFI_DEVICE_ERROR              A device error occurred while attempting to send SCSI Request Packet.\r
@@ -520,7 +518,7 @@ ScsiRequestSenseCommand (
   ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
 \r
   Cdb[0]                        = EFI_SCSI_OP_REQUEST_SENSE;\r
-  Cdb[1]                        = (UINT8) (Lun & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
+  Cdb[1]                        = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
   Cdb[4]                        = (UINT8) (*SenseDataLength);\r
 \r
   CommandPacket.CdbLength       = (UINT8) EFI_SCSI_OP_LENGTH_SIX;\r
@@ -543,7 +541,7 @@ ScsiRequestSenseCommand (
   Executes the SCSI Read Capacity command on the SCSI target specified by ScsiIo.\r
   If Timeout is zero, then this function waits indefinitely for the command to complete.\r
   If Timeout is greater than zero, then the command is executed and will timeout after\r
-  Timeout 100 ns units.  The PMI parameter is used to construct the CDB for this SCSI command.\r
+  Timeout 100 ns units.  The Pmi parameter is used to construct the CDB for this SCSI command.\r
   If ScsiIo is NULL, then ASSERT().\r
   If SenseDataLength is NULL, then ASSERT().\r
   If HostAdapterStatus is NULL, then ASSERT().\r
@@ -558,9 +556,9 @@ ScsiRequestSenseCommand (
   @param[out]     TargetStatus         The status of the target.\r
   @param[in, out] DataBuffer           A pointer to a data buffer.\r
   @param[in, out] DataLength           The length of data buffer.\r
-  @param[in]      PMI                  Partial medium indicator.\r
+  @param[in]      Pmi                  A partial medium indicator.\r
 \r
-  @retval  EFI_SUCCESS           Command is executed successfully.\r
+  @retval  EFI_SUCCESS           The command executed successfully.\r
   @retval  EFI_BAD_BUFFER_SIZE   The SCSI Request Packet was executed, but the entire\r
                                  DataBuffer could not be transferred. The actual\r
                                  number of bytes transferred is returned in DataLength.\r
@@ -583,7 +581,7 @@ ScsiReadCapacityCommand (
      OUT UINT8                 *TargetStatus,\r
   IN OUT VOID                  *DataBuffer,   OPTIONAL\r
   IN OUT UINT32                *DataLength,\r
-  IN     BOOLEAN               PMI\r
+  IN     BOOLEAN               Pmi\r
   )\r
 {\r
   EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r
@@ -614,10 +612,10 @@ ScsiReadCapacityCommand (
   ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
 \r
   Cdb[0]  = EFI_SCSI_OP_READ_CAPACITY;\r
-  Cdb[1]  = (UINT8) (Lun & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
-  if (!PMI) {\r
+  Cdb[1]  = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
+  if (!Pmi) {\r
     //\r
-    // Partial medium indicator,if PMI is FALSE, the Cdb.2 ~ Cdb.5 MUST BE ZERO.\r
+    // Partial medium indicator,if Pmi is FALSE, the Cdb.2 ~ Cdb.5 MUST BE ZERO.\r
     //\r
     ZeroMem ((Cdb + 2), 4);\r
   } else {\r
@@ -639,6 +637,109 @@ ScsiReadCapacityCommand (
 }\r
 \r
 \r
+/**\r
+  Execute Read Capacity SCSI 16 command on a specific SCSI target.\r
+\r
+  Executes the SCSI Read Capacity 16 command on the SCSI target specified by ScsiIo.\r
+  If Timeout is zero, then this function waits indefinitely for the command to complete.\r
+  If Timeout is greater than zero, then the command is executed and will timeout after\r
+  Timeout 100 ns units.  The Pmi parameter is used to construct the CDB for this SCSI command.\r
+  If ScsiIo is NULL, then ASSERT().\r
+  If SenseDataLength is NULL, then ASSERT().\r
+  If HostAdapterStatus is NULL, then ASSERT().\r
+  If TargetStatus is NULL, then ASSERT().\r
+  If DataLength is NULL, then ASSERT().\r
+\r
+  @param[in]      ScsiIo               A pointer to SCSI IO protocol.\r
+  @param[in]      Timeout              The length of timeout period.\r
+  @param[in, out] SenseData            A pointer to output sense data.\r
+  @param[in, out] SenseDataLength      The length of output sense data.\r
+  @param[out]     HostAdapterStatus    The status of Host Adapter.\r
+  @param[out]     TargetStatus         The status of the target.\r
+  @param[in, out] DataBuffer           A pointer to a data buffer.\r
+  @param[in, out] DataLength           The length of data buffer.\r
+  @param[in]      Pmi                  Partial medium indicator.\r
+\r
+  @retval  EFI_SUCCESS           The command executed successfully.\r
+  @retval  EFI_BAD_BUFFER_SIZE   The SCSI Request Packet was executed, but the entire\r
+                                 DataBuffer could not be transferred. The actual\r
+                                 number of bytes transferred is returned in DataLength.\r
+  @retval  EFI_NOT_READY         The SCSI Request Packet could not be sent because\r
+                                 there are too many SCSI Command Packets already queued.\r
+  @retval  EFI_DEVICE_ERROR      A device error occurred while attempting to send SCSI Request Packet.\r
+  @retval  EFI_UNSUPPORTED       The command described by the SCSI Request Packet\r
+                                 is not supported by the SCSI initiator(i.e., SCSI  Host Controller)\r
+  @retval  EFI_TIMEOUT           A timeout occurred while waiting for the SCSI Request Packet to execute.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ScsiReadCapacity16Command (\r
+  IN     EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
+  IN     UINT64                Timeout,\r
+  IN OUT VOID                  *SenseData,  OPTIONAL\r
+  IN OUT UINT8                 *SenseDataLength,\r
+     OUT UINT8                 *HostAdapterStatus,\r
+     OUT UINT8                 *TargetStatus,\r
+  IN OUT VOID                  *DataBuffer, OPTIONAL\r
+  IN OUT UINT32                *DataLength,\r
+  IN     BOOLEAN               Pmi\r
+  )\r
+{\r
+  EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r
+  UINT64                          Lun;\r
+  UINT8                           *Target;\r
+  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
+  EFI_STATUS                      Status;\r
+  UINT8                           Cdb[16];\r
+\r
+  ASSERT (SenseDataLength != NULL);\r
+  ASSERT (HostAdapterStatus != NULL);\r
+  ASSERT (TargetStatus != NULL);\r
+  ASSERT (DataLength != NULL);\r
+  ASSERT (ScsiIo != NULL);\r
+\r
+  ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r
+  ZeroMem (Cdb, 16);\r
+\r
+  CommandPacket.Timeout         = Timeout;\r
+  CommandPacket.InDataBuffer    = DataBuffer;\r
+  CommandPacket.SenseData       = SenseData;\r
+  CommandPacket.InTransferLength= *DataLength;\r
+  CommandPacket.Cdb             = Cdb;\r
+  //\r
+  // Fill Cdb for Read Capacity Command\r
+  //\r
+  Target = &TargetArray[0];\r
+  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
+\r
+  Cdb[0]  = EFI_SCSI_OP_READ_CAPACITY16;\r
+  Cdb[1]  = 0x10;\r
+  if (!Pmi) {\r
+    //\r
+    // Partial medium indicator,if Pmi is FALSE, the Cdb.2 ~ Cdb.9 MUST BE ZERO.\r
+    //\r
+    ZeroMem ((Cdb + 2), 8);\r
+  } else {\r
+    Cdb[14] |= 0x01;\r
+  }\r
+\r
+  Cdb[13] = 0x20;\r
+  CommandPacket.CdbLength       = 16;\r
+  CommandPacket.DataDirection   = EFI_SCSI_DATA_IN;\r
+  CommandPacket.SenseDataLength = *SenseDataLength;\r
+\r
+  Status                        = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);\r
+\r
+  *HostAdapterStatus            = CommandPacket.HostAdapterStatus;\r
+  *TargetStatus                 = CommandPacket.TargetStatus;\r
+  *SenseDataLength              = CommandPacket.SenseDataLength;\r
+  *DataLength                   = CommandPacket.InTransferLength;\r
+\r
+  return Status;\r
+}\r
+\r
+\r
 /**\r
   Execute Read(10) SCSI command on a specific SCSI target.\r
 \r
@@ -665,7 +766,7 @@ ScsiReadCapacityCommand (
   @param[in]      StartLba             The start address of LBA.\r
   @param[in]      SectorSize           The sector size.\r
 \r
-  @retval  EFI_SUCCESS          Command is executed successfully.\r
+  @retval  EFI_SUCCESS          The command is executed successfully.\r
   @retval  EFI_BAD_BUFFER_SIZE  The SCSI Request Packet was executed, but the entire DataBuffer could\r
                                 not be transferred. The actual number of bytes transferred is returned in DataLength.\r
   @retval  EFI_NOT_READY        The SCSI Request Packet could not be sent because there are too many \r
@@ -719,13 +820,9 @@ ScsiRead10Command (
   ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
 \r
   Cdb[0]                        = EFI_SCSI_OP_READ10;\r
-  Cdb[1]                        = (UINT8) (Lun & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
-  Cdb[2]                        = (UINT8) (StartLba >> 24);\r
-  Cdb[3]                        = (UINT8) (StartLba >> 16);\r
-  Cdb[4]                        = (UINT8) (StartLba >> 8);\r
-  Cdb[5]                        = (UINT8) (StartLba & 0xff);\r
-  Cdb[7]                        = (UINT8) (SectorSize >> 8);\r
-  Cdb[8]                        = (UINT8) (SectorSize & 0xff);\r
+  Cdb[1]                        = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
+  WriteUnaligned32 ((UINT32 *)&Cdb[2], SwapBytes32 (StartLba));\r
+  WriteUnaligned16 ((UINT16 *)&Cdb[7], SwapBytes16 ((UINT16) SectorSize));\r
 \r
   CommandPacket.CdbLength       = EFI_SCSI_OP_LENGTH_TEN;\r
   CommandPacket.DataDirection   = EFI_SCSI_DATA_IN;\r
@@ -767,7 +864,7 @@ ScsiRead10Command (
   @param[in]      StartLba             The start address of LBA.\r
   @param[in]      SectorSize           The sector size.\r
 \r
-  @retval  EFI_SUCCESS          Command is executed successfully.\r
+  @retval  EFI_SUCCESS          The command executed successfully.\r
   @retval  EFI_BAD_BUFFER_SIZE  The SCSI Request Packet was executed, but the entire DataBuffer could\r
                                 not be transferred. The actual number of bytes transferred is returned in DataLength.\r
   @retval  EFI_NOT_READY        The SCSI Request Packet could not be sent because there are too many \r
@@ -821,13 +918,9 @@ ScsiWrite10Command (
   ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
 \r
   Cdb[0]                        = EFI_SCSI_OP_WRITE10;\r
-  Cdb[1]                        = (UINT8) (Lun & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
-  Cdb[2]                        = (UINT8) (StartLba >> 24);\r
-  Cdb[3]                        = (UINT8) (StartLba >> 16);\r
-  Cdb[4]                        = (UINT8) (StartLba >> 8);\r
-  Cdb[5]                        = (UINT8) StartLba;\r
-  Cdb[7]                        = (UINT8) (SectorSize >> 8);\r
-  Cdb[8]                        = (UINT8) SectorSize;\r
+  Cdb[1]                        = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
+  WriteUnaligned32 ((UINT32 *)&Cdb[2], SwapBytes32 (StartLba));\r
+  WriteUnaligned16 ((UINT16 *)&Cdb[7], SwapBytes16 ((UINT16) SectorSize));\r
 \r
   CommandPacket.CdbLength       = EFI_SCSI_OP_LENGTH_TEN;\r
   CommandPacket.DataDirection   = EFI_SCSI_DATA_OUT;\r
@@ -843,3 +936,198 @@ ScsiWrite10Command (
   return Status;\r
 }\r
 \r
+/**\r
+  Execute Read(16) SCSI command on a specific SCSI target.\r
+\r
+  Executes the SCSI Read(16) command on the SCSI target specified by ScsiIo.\r
+  If Timeout is zero, then this function waits indefinitely for the command to complete.\r
+  If Timeout is greater than zero, then the command is executed and will timeout\r
+  after Timeout 100 ns units.  The StartLba and SectorSize parameters are used to\r
+  construct the CDB for this SCSI command.\r
+  If ScsiIo is NULL, then ASSERT().\r
+  If SenseDataLength is NULL, then ASSERT().\r
+  If HostAdapterStatus is NULL, then ASSERT().\r
+  If TargetStatus is NULL, then ASSERT().\r
+  If DataLength is NULL, then ASSERT().\r
+\r
+\r
+  @param[in]      ScsiIo               A pointer to SCSI IO protocol.\r
+  @param[in]      Timeout              The length of timeout period.\r
+  @param[in, out] SenseData            A pointer to output sense data.\r
+  @param[in, out] SenseDataLength      The length of output sense data.\r
+  @param[out]     HostAdapterStatus    The status of Host Adapter.\r
+  @param[out]     TargetStatus         The status of the target.\r
+  @param[in, out] DataBuffer           Read 16 command data.\r
+  @param[in, out] DataLength           The length of data buffer.\r
+  @param[in]      StartLba             The start address of LBA.\r
+  @param[in]      SectorSize           The sector size.\r
+\r
+  @retval  EFI_SUCCESS          The command executed successfully.\r
+  @retval  EFI_BAD_BUFFER_SIZE  The SCSI Request Packet was executed, but the entire DataBuffer could\r
+                                not be transferred. The actual number of bytes transferred is returned in DataLength.\r
+  @retval  EFI_NOT_READY        The SCSI Request Packet could not be sent because there are too many \r
+                                SCSI Command Packets already queued.\r
+  @retval  EFI_DEVICE_ERROR     A device error occurred while attempting to send SCSI Request Packet.\r
+  @retval  EFI_UNSUPPORTED      The command described by the SCSI Request Packet is not supported by \r
+                                the SCSI initiator(i.e., SCSI  Host Controller)\r
+  @retval  EFI_TIMEOUT          A timeout occurred while waiting for the SCSI Request Packet to execute.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ScsiRead16Command (\r
+  IN     EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
+  IN     UINT64                Timeout,\r
+  IN OUT VOID                  *SenseData,   OPTIONAL\r
+  IN OUT UINT8                 *SenseDataLength,\r
+     OUT UINT8                 *HostAdapterStatus,\r
+     OUT UINT8                 *TargetStatus,\r
+  IN OUT VOID                  *DataBuffer,  OPTIONAL\r
+  IN OUT UINT32                *DataLength,\r
+  IN     UINT64                StartLba,\r
+  IN     UINT32                SectorSize\r
+  )\r
+{\r
+  EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r
+  UINT64                          Lun;\r
+  UINT8                           *Target;\r
+  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
+  EFI_STATUS                      Status;\r
+  UINT8                           Cdb[EFI_SCSI_OP_LENGTH_SIXTEEN];\r
+\r
+  ASSERT (SenseDataLength != NULL);\r
+  ASSERT (HostAdapterStatus != NULL);\r
+  ASSERT (TargetStatus != NULL);\r
+  ASSERT (DataLength != NULL);\r
+  ASSERT (ScsiIo != NULL);\r
+\r
+  ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r
+  ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIXTEEN);\r
+\r
+  CommandPacket.Timeout          = Timeout;\r
+  CommandPacket.InDataBuffer     = DataBuffer;\r
+  CommandPacket.SenseData        = SenseData;\r
+  CommandPacket.InTransferLength = *DataLength;\r
+  CommandPacket.Cdb              = Cdb;\r
+  //\r
+  // Fill Cdb for Read (16) Command\r
+  //\r
+  Target = &TargetArray[0];\r
+  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
+\r
+  Cdb[0]                        = EFI_SCSI_OP_READ16;\r
+  Cdb[1]                        = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
+  WriteUnaligned64 ((UINT64 *)&Cdb[2], SwapBytes64 (StartLba));\r
+  WriteUnaligned32 ((UINT32 *)&Cdb[10], SwapBytes32 (SectorSize));\r
+\r
+  CommandPacket.CdbLength       = EFI_SCSI_OP_LENGTH_SIXTEEN;\r
+  CommandPacket.DataDirection   = EFI_SCSI_DATA_IN;\r
+  CommandPacket.SenseDataLength = *SenseDataLength;\r
+\r
+  Status                        = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);\r
+\r
+  *HostAdapterStatus            = CommandPacket.HostAdapterStatus;\r
+  *TargetStatus                 = CommandPacket.TargetStatus;\r
+  *SenseDataLength              = CommandPacket.SenseDataLength;\r
+  *DataLength                   = CommandPacket.InTransferLength;\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Execute Write(16) SCSI command on a specific SCSI target.\r
+\r
+  Executes the SCSI Write(16) command on the SCSI target specified by ScsiIo.\r
+  If Timeout is zero, then this function waits indefinitely for the command to complete.\r
+  If Timeout is greater than zero, then the command is executed and will timeout after\r
+  Timeout 100 ns units.  The StartLba and SectorSize parameters are used to construct\r
+  the CDB for this SCSI command.\r
+  If ScsiIo is NULL, then ASSERT().\r
+  If SenseDataLength is NULL, then ASSERT().\r
+  If HostAdapterStatus is NULL, then ASSERT().\r
+  If TargetStatus is NULL, then ASSERT().\r
+  If DataLength is NULL, then ASSERT().\r
+\r
+  @param[in]      ScsiIo               SCSI IO Protocol to use\r
+  @param[in]      Timeout              The length of timeout period.\r
+  @param[in, out] SenseData            A pointer to output sense data.\r
+  @param[in, out] SenseDataLength      The length of output sense data.\r
+  @param[out]     HostAdapterStatus    The status of Host Adapter.\r
+  @param[out]     TargetStatus         The status of the target.\r
+  @param[in, out] DataBuffer           A pointer to a data buffer.\r
+  @param[in, out] DataLength           The length of data buffer.\r
+  @param[in]      StartLba             The start address of LBA.\r
+  @param[in]      SectorSize           The sector size.\r
+\r
+  @retval  EFI_SUCCESS          The command is executed successfully.\r
+  @retval  EFI_BAD_BUFFER_SIZE  The SCSI Request Packet was executed, but the entire DataBuffer could\r
+                                not be transferred. The actual number of bytes transferred is returned in DataLength.\r
+  @retval  EFI_NOT_READY        The SCSI Request Packet could not be sent because there are too many \r
+                                SCSI Command Packets already queued.\r
+  @retval  EFI_DEVICE_ERROR     A device error occurred while attempting to send SCSI Request Packet.\r
+  @retval  EFI_UNSUPPORTED      The command described by the SCSI Request Packet is not supported by \r
+                                the SCSI initiator(i.e., SCSI  Host Controller)\r
+  @retval  EFI_TIMEOUT          A timeout occurred while waiting for the SCSI Request Packet to execute.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ScsiWrite16Command (\r
+  IN     EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
+  IN     UINT64                Timeout,\r
+  IN OUT VOID                  *SenseData,   OPTIONAL\r
+  IN OUT UINT8                 *SenseDataLength,\r
+     OUT UINT8                 *HostAdapterStatus,\r
+     OUT UINT8                 *TargetStatus,\r
+  IN OUT VOID                  *DataBuffer,  OPTIONAL\r
+  IN OUT UINT32                *DataLength,\r
+  IN     UINT64                StartLba,\r
+  IN     UINT32                SectorSize\r
+  )\r
+{\r
+  EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r
+  UINT64                          Lun;\r
+  UINT8                           *Target;\r
+  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
+  EFI_STATUS                      Status;\r
+  UINT8                           Cdb[EFI_SCSI_OP_LENGTH_SIXTEEN];\r
+\r
+  ASSERT (SenseDataLength != NULL);\r
+  ASSERT (HostAdapterStatus != NULL);\r
+  ASSERT (TargetStatus != NULL);\r
+  ASSERT (DataLength != NULL);\r
+  ASSERT (ScsiIo != NULL);\r
+\r
+  ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r
+  ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIXTEEN);\r
+\r
+  CommandPacket.Timeout           = Timeout;\r
+  CommandPacket.OutDataBuffer     = DataBuffer;\r
+  CommandPacket.SenseData         = SenseData;\r
+  CommandPacket.OutTransferLength = *DataLength;\r
+  CommandPacket.Cdb               = Cdb;\r
+  //\r
+  // Fill Cdb for Write (16) Command\r
+  //\r
+  Target = &TargetArray[0];\r
+  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
+\r
+  Cdb[0]                        = EFI_SCSI_OP_WRITE16;\r
+  Cdb[1]                        = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
+  WriteUnaligned64 ((UINT64 *)&Cdb[2], SwapBytes64 (StartLba));\r
+  WriteUnaligned32 ((UINT32 *)&Cdb[10], SwapBytes32 (SectorSize));\r
+\r
+  CommandPacket.CdbLength       = EFI_SCSI_OP_LENGTH_SIXTEEN;\r
+  CommandPacket.DataDirection   = EFI_SCSI_DATA_OUT;\r
+  CommandPacket.SenseDataLength = *SenseDataLength;\r
+\r
+  Status                        = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);\r
+\r
+  *HostAdapterStatus            = CommandPacket.HostAdapterStatus;\r
+  *TargetStatus                 = CommandPacket.TargetStatus;\r
+  *SenseDataLength              = CommandPacket.SenseDataLength;\r
+  *DataLength                   = CommandPacket.OutTransferLength;\r
+\r
+  return Status;\r
+}\r