]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiScsiLib/UefiScsiLib.c
Refine file header for INF files of MDE library instances.
[mirror_edk2.git] / MdePkg / Library / UefiScsiLib / UefiScsiLib.c
index 6bfc8cfc35a67ee96252044f38a89dce6bc99b55..847029789a28062f46e4ed018287cfeb62a60522 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   UEFI SCSI Library implementation\r
 \r
-  Copyright (c) 2006 - 2007, Intel Corporation.<BR>\r
+  Copyright (c) 2006 - 2008, Intel Corporation.<BR>\r
   All rights reserved. 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
 **/\r
 \r
 \r
-#include <PiDxe.h>\r
+#include <Uefi.h>\r
+#include <Library/DebugLib.h>\r
 #include <Library/ScsiLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 \r
-#include <IndustryStandard/scsi.h>\r
+#include <IndustryStandard/Scsi.h>\r
 \r
+//\r
+// Max bytes needed to represent ID of a SCSI device\r
+//\r
+#define EFI_SCSI_TARGET_MAX_BYTES (0x10)\r
 \r
-/**
+//\r
+// bit5..7 are for Logical unit number\r
+// 11100000b (0xe0)\r
+//\r
+#define EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK 0xe0\r
+\r
+//\r
+// Scsi Command Length six or ten\r
+//\r
+#define EFI_SCSI_OP_LENGTH_SIX 0x6\r
+#define EFI_SCSI_OP_LENGTH_TEN 0xa\r
+\r
+/**\r
   Function test the ready status of the SCSI unit.\r
-
-  @param[in]     ScsiIo             A pointer to SCSI IO protocol.
-  @param[in]     Timeout            The length of timeout period.
-  @param[out]    SenseData          A pointer to output sense data.
-  @param[out]    SenseDataLength    The length of output sense data.
-  @param[out]    HostAdapterStatus  The status of Host Adapter.
-  @param[out]    TargetStatus       The status of the target.
-
+\r
+  Submit SCSI test unit ready command with SCSI request packet specified by this scsi command, TimeOut\r
+  and SenseData, then get the status of the target Scsi unit.\r
+\r
+  If SenseDataLength is NULL, then ASSERT().\r
+\r
+  If HostAdapterStatus is NULL, then ASSERT().\r
+\r
+  If TargetStatus 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]     SenseData          A pointer to output sense data.\r
+  @param[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
+\r
   @retval EFI_SUCCESS           The status of the unit is tested successfully.\r
   @retval EFI_BAD_BUFFER_SIZE   The SCSI Request Packet was executed, \r
                                 but the entire DataBuffer could not be transferred.\r
                                 queued.\r
   @retval EFI_DEVICE_ERROR      A device error occurred while attempting to send \r
                                 the SCSI Request Packet.\r
-  @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid.  \r
+  @retval EFI_INVALID_PARAMETER ScsiIo is NULL.\r
   @retval EFI_UNSUPPORTED       The command described by the SCSI Request Packet\r
                                 is not supported by the SCSI initiator(i.e., SCSI \r
                                 Host Controller).\r
   @retval EFI_TIMEOUT           A timeout occurred while waiting for the SCSI \r
                                 Request Packet to execute.\r
-
+\r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 ScsiTestUnitReadyCommand (\r
   IN  EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
   IN  UINT64                Timeout,\r
-  OUT VOID                  *SenseData,\r
+  IN  VOID                  *SenseData,\r
   OUT UINT8                 *SenseDataLength,\r
   OUT UINT8                 *HostAdapterStatus,\r
   OUT UINT8                 *TargetStatus\r
@@ -63,11 +90,18 @@ ScsiTestUnitReadyCommand (
   UINT8                           *Target;\r
   UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
   EFI_STATUS                      Status;\r
-  UINT8                           Cdb[6];\r
-\r
+  UINT8                           Cdb[EFI_SCSI_OP_LENGTH_SIX];\r
+\r
+  ASSERT (SenseDataLength != NULL);\r
+  ASSERT (HostAdapterStatus != NULL);\r
+  ASSERT (TargetStatus != NULL);\r
+  \r
+  if (ScsiIo == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
 \r
   ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r
-  ZeroMem (Cdb, 6);\r
+  ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIX);\r
 \r
   CommandPacket.Timeout         = Timeout;\r
   CommandPacket.InDataBuffer    = NULL;\r
@@ -83,8 +117,8 @@ ScsiTestUnitReadyCommand (
   ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
 \r
   Cdb[0]                        = EFI_SCSI_OP_TEST_UNIT_READY;\r
-  Cdb[1]                        = (UINT8) (Lun & 0xe0);\r
-  CommandPacket.CdbLength       = (UINT8) 6;\r
+  Cdb[1]                        = (UINT8) (Lun & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
+  CommandPacket.CdbLength       = (UINT8) EFI_SCSI_OP_LENGTH_SIX;\r
   CommandPacket.SenseDataLength = *SenseDataLength;\r
 \r
   Status                        = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);\r
@@ -97,38 +131,50 @@ ScsiTestUnitReadyCommand (
 }\r
 \r
 \r
-/**
+/**\r
   Function to submit SCSI inquiry command.\r
-
-  @param[in]     ScsiIo             SCSI IO Protocol to use
-  @param[in]     Timeout            The length of timeout period.
-  @param[out]    SenseData          A pointer to output sense data.
-  @param[in,out] SenseDataLength    The length of output sense data.
-  @param[out]    HostAdapterStatus  The status of Host Adapter.
-  @param[out]    TargetStatus       The status of the target.
-  @param[in,out] InquirydataBuffer  A pointer to inquiry data buffer.
-  @param[in,out] InquiryDataLength  The length of inquiry data buffer.
-  @param[in]     EnableVitalProductData  Boolean to enable Vital Product Data.
-
-  @retval EFI_SUCCESS         The status of the unit is tested successfully.\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 TransferLength.\r
-  @retval EFI_NOT_READY   The SCSI Request Packet could not be sent because \r
-                          there are too many SCSI Command Packets already \r
-                          queued.\r
-  @retval EFI_DEVICE_ERROR  A device error occurred while attempting to send \r
-                            the SCSI Request Packet.\r
-  @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid.  \r
-  @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet\r
-                          is not supported by the SCSI initiator(i.e., SCSI \r
-                          Host Controller).\r
-  @retval EFI_TIMEOUT     A timeout occurred while waiting for the SCSI \r
-                          Request Packet to execute.\r
-
+\r
+  Submit SCSI inquiry command with the SCSI request packet specified by this SCSI command and input\r
+  parameters, then return the status of Scsi unit execution.\r
+\r
+  If SenseDataLength is NULL, then ASSERT().\r
+\r
+  If HostAdapterStatus is NULL, then ASSERT().\r
+\r
+  If TargetStatus is NULL, then ASSERT().\r
+\r
+  If InquiryDataLength 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]     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] InquirydataBuffer  A pointer to inquiry data buffer.\r
+  @param[in, out] InquiryDataLength  The length of inquiry data buffer.\r
+  @param[in]     EnableVitalProductData  Boolean to enable Vital Product Data.\r
+\r
+  @retval EFI_SUCCESS                Command is executed successfully.\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 TransferLength.\r
+  @retval EFI_NOT_READY              The SCSI Request Packet could not be sent because \r
+                                     there are too many SCSI Command Packets already \r
+                                     queued.\r
+  @retval EFI_DEVICE_ERROR           A device error occurred while attempting to send \r
+                                     the SCSI Request Packet.\r
+  @retval EFI_INVALID_PARAMETER      ScsiIo is NULL.\r
+  @retval EFI_UNSUPPORTED            The command described by the SCSI Request Packet\r
+                                     is not supported by the SCSI initiator(i.e., SCSI \r
+                                     Host Controller).\r
+  @retval EFI_TIMEOUT                A timeout occurred while waiting for the SCSI \r
+                                     Request Packet to execute.\r
+\r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 ScsiInquiryCommand (\r
   IN  EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
   IN  UINT64                Timeout,\r
@@ -146,10 +192,19 @@ ScsiInquiryCommand (
   UINT8                           *Target;\r
   UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
   EFI_STATUS                      Status;\r
-  UINT8                           Cdb[6];\r
+  UINT8                           Cdb[EFI_SCSI_OP_LENGTH_SIX];\r
+\r
+  ASSERT (SenseDataLength != NULL);\r
+  ASSERT (HostAdapterStatus != NULL);\r
+  ASSERT (TargetStatus != NULL);\r
+  ASSERT (InquiryDataLength != NULL);\r
+  \r
+  if (ScsiIo == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
 \r
   ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r
-  ZeroMem (Cdb, 6);\r
+  ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIX);\r
 \r
   CommandPacket.Timeout         = Timeout;\r
   CommandPacket.InDataBuffer    = InquiryDataBuffer;\r
@@ -162,7 +217,7 @@ ScsiInquiryCommand (
   ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
 \r
   Cdb[0]  = EFI_SCSI_OP_INQUIRY;\r
-  Cdb[1]  = (UINT8) (Lun & 0xe0);\r
+  Cdb[1]  = (UINT8) (Lun & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
   if (EnableVitalProductData) {\r
     Cdb[1] |= 0x01;\r
   }\r
@@ -172,7 +227,7 @@ ScsiInquiryCommand (
   }\r
 \r
   Cdb[4]                      = (UINT8) (*InquiryDataLength);\r
-  CommandPacket.CdbLength     = (UINT8) 6;\r
+  CommandPacket.CdbLength     = (UINT8) EFI_SCSI_OP_LENGTH_SIX;\r
   CommandPacket.DataDirection = EFI_SCSI_DATA_IN;\r
 \r
   Status                      = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);\r
@@ -186,21 +241,32 @@ ScsiInquiryCommand (
 }\r
 \r
 \r
-/**
+/**\r
   Function to submit SCSI mode sense 10 command.\r
-
-  @param[in]     ScsiIo             A pointer to SCSI IO protocol.
-  @param[in]     Timeout            The length of timeout period.
-  @param[out]    SenseData          A pointer to output sense data.
-  @param[in,out] SenseDataLength    The length of output sense data.
-  @param[out]    HostAdapterStatus  The status of Host Adapter.
-  @param[out]    TargetStatus       The status of the target.
-  @param[in]     DataBuffer         A pointer to input data buffer.
-  @param[in,out] DataLength         The length of input data buffer.
-  @param[in]     DBDField           The DBD Field (Optional).
-  @param[in]     PageControl        Page Control.
-  @param[in]     PageCode           Page code.
-
+\r
+  Submit SCSI Mode Sense (10) command with the SCSI request packet specified by this SCSI command and\r
+  the input parameters, then return the status of Scsi unit execution.\r
+\r
+  If SenseDataLength is NULL, then ASSERT().\r
+\r
+  If HostAdapterStatus is NULL, then ASSERT().\r
+\r
+  If TargetStatus is NULL, then ASSERT().\r
+\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]     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]     DataBuffer         A pointer to input data buffer.\r
+  @param[in, out] DataLength         The length of input data buffer.\r
+  @param[in]     DBDField           The DBD Field (Optional).\r
+  @param[in]     PageControl        Page Control.\r
+  @param[in]     PageCode           Page code.\r
+\r
   @retval EFI_SUCCESS               The status of the unit is tested successfully.\r
   @retval EFI_BAD_BUFFER_SIZE       The SCSI Request Packet was executed, \r
                                     but the entire DataBuffer could not be transferred.\r
@@ -211,15 +277,16 @@ ScsiInquiryCommand (
                                     queued.\r
   @retval EFI_DEVICE_ERROR          A device error occurred while attempting to send \r
                                     the SCSI Request Packet.\r
-  @retval EFI_INVALID_PARAMETER     The contents of CommandPacket are invalid.  \r
+  @retval EFI_INVALID_PARAMETER     ScsiIo is NULL. \r
   @retval EFI_UNSUPPORTED           The command described by the SCSI Request Packet\r
                                     is not supported by the SCSI initiator(i.e., SCSI \r
                                     Host Controller).\r
   @retval EFI_TIMEOUT               A timeout occurred while waiting for the SCSI \r
                                     Request Packet to execute.\r
-
+\r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 ScsiModeSense10Command (\r
   IN  EFI_SCSI_IO_PROTOCOL    *ScsiIo,\r
   IN  UINT64                  Timeout,\r
@@ -239,10 +306,19 @@ ScsiModeSense10Command (
   UINT8                           *Target;\r
   UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
   EFI_STATUS                      Status;\r
-  UINT8                           Cdb[10];\r
+  UINT8                           Cdb[EFI_SCSI_OP_LENGTH_TEN];\r
+\r
+  ASSERT (SenseDataLength != NULL);\r
+  ASSERT (HostAdapterStatus != NULL);\r
+  ASSERT (TargetStatus != NULL);\r
+  ASSERT (DataLength != NULL);\r
+  \r
+  if (ScsiIo == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
 \r
   ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r
-  ZeroMem (Cdb, 10);\r
+  ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TEN);\r
 \r
   CommandPacket.Timeout         = Timeout;\r
   CommandPacket.InDataBuffer    = DataBuffer;\r
@@ -256,12 +332,18 @@ ScsiModeSense10Command (
   ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
 \r
   Cdb[0]                        = EFI_SCSI_OP_MODE_SEN10;\r
-  Cdb[1]                        = (UINT8) ((Lun & 0xe0) + ((DBDField << 3) & 0x08));\r
+  //\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
+  //\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[7]                        = (UINT8) (*DataLength >> 8);\r
   Cdb[8]                        = (UINT8) (*DataLength);\r
 \r
-  CommandPacket.CdbLength       = 10;\r
+  CommandPacket.CdbLength       = EFI_SCSI_OP_LENGTH_TEN;\r
   CommandPacket.DataDirection   = EFI_SCSI_DATA_IN;\r
   CommandPacket.SenseDataLength = *SenseDataLength;\r
 \r
@@ -276,42 +358,37 @@ ScsiModeSense10Command (
 }\r
 \r
 \r
-/**
+/**\r
   Function to submit SCSI request sense command.\r
-  ScsiIo               - A pointer to SCSI IO protocol.\r
-  Timeout              - The length of timeout period.\r
-  SenseData            - A pointer to output sense data.\r
-  SenseDataLength      - The length of output sense data.\r
-  HostAdapterStatus    - The status of Host Adapter.\r
-  TargetStatus         - The status of the target.\r
-
-  @param[in]     ScsiIo             SCSI IO Protocol to use
-  @param[in]     Timeout            TODO:
-  @param[out]    SenseData          TODO:
-  @param[in,out] SenseDataLength    TODO:
-  @param[out]    HostAdapterStatus  TODO:
-  @param[out]    TargetStatus       TODO:
-
-  @retval EFI_SUCCESS        Valid data returned
-  @retval EFI_SUCCESS        The status of the unit is tested successfully.\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 TransferLength.\r
-  @retval EFI_NOT_READY             The SCSI Request Packet could not be sent because \r
-                                    there are too many SCSI Command Packets already \r
-                                    queued.\r
-  @retval EFI_DEVICE_ERROR          A device error occurred while attempting to send \r
-                                    the SCSI Request Packet.\r
-  @retval EFI_INVALID_PARAMETER     The contents of CommandPacket are invalid.  \r
-  @retval EFI_UNSUPPORTED           The command described by the SCSI Request Packet\r
-                                    is not supported by the SCSI initiator(i.e., SCSI \r
-                                    Host Controller).\r
-  @retval EFI_TIMEOUT               A timeout occurred while waiting for the SCSI \r
-                                    Request Packet to execute.\r
-
+\r
+  Submit SCSI request sense command with the SCSI requested packet specified by this\r
+  SCSI command, TimeOut and SenseData, and then return the status of scsi unit execution.\r
+\r
+  If SenseDataLength is NULL, then ASSERT().\r
+  \r
+  If HostAdapterStatus is NULL, then ASSERT().\r
+  \r
+  If TargetStatus 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]       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
+\r
+  @retval EFI_SUCCESS                   Command is 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
+  @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
+  @retval EFI_INVALID_PARAMETER         ScsiIo is NULL.\r
+\r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 ScsiRequestSenseCommand (\r
   IN  EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
   IN  UINT64                Timeout,\r
@@ -326,10 +403,18 @@ ScsiRequestSenseCommand (
   UINT8                           *Target;\r
   UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
   EFI_STATUS                      Status;\r
-  UINT8                           Cdb[6];\r
+  UINT8                           Cdb[EFI_SCSI_OP_LENGTH_SIX];\r
+\r
+  ASSERT (SenseDataLength != NULL);\r
+  ASSERT (HostAdapterStatus != NULL);\r
+  ASSERT (TargetStatus != NULL);\r
+  \r
+  if (ScsiIo == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
 \r
   ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r
-  ZeroMem (Cdb, 6);\r
+  ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIX);\r
 \r
   CommandPacket.Timeout         = Timeout;\r
   CommandPacket.InDataBuffer    = SenseData;\r
@@ -343,10 +428,10 @@ ScsiRequestSenseCommand (
   ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
 \r
   Cdb[0]                        = EFI_SCSI_OP_REQUEST_SENSE;\r
-  Cdb[1]                        = (UINT8) (Lun & 0xe0);\r
+  Cdb[1]                        = (UINT8) (Lun & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
   Cdb[4]                        = (UINT8) (*SenseDataLength);\r
 \r
-  CommandPacket.CdbLength       = (UINT8) 6;\r
+  CommandPacket.CdbLength       = (UINT8) EFI_SCSI_OP_LENGTH_SIX;\r
   CommandPacket.DataDirection   = EFI_SCSI_DATA_IN;\r
   CommandPacket.SenseDataLength = 0;\r
 \r
@@ -360,38 +445,44 @@ ScsiRequestSenseCommand (
 }\r
 \r
 \r
-/**
+/**\r
   Function to submit read capacity command.\r
 \r
-  @param[in]     ScsiIo             A pointer to SCSI IO protocol.
-  @param[in]     Timeout            The length of timeout period.
-  @param[out]    SenseData          A pointer to output sense data.
-  @param[in,out] SenseDataLength    The length of output sense data.
-  @param[out]    HostAdapterStatus  The status of Host Adapter.
-  @param[out]    TargetStatus       The status of the target.
-  @param[out]    DataBuffer         A pointer to a data buffer.
-  @param[in,out] DataLength         The length of data buffer.
-  @param[in]     PMI                Partial medium indicator.
-
-  @retval  EFI_SUCCESS                The status of the unit is tested successfully.\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 TransferLength.\r
-  @retval  EFI_NOT_READY              The SCSI Request Packet could not be sent because \r
-                                      there are too many SCSI Command Packets already \r
-                                      queued.\r
-  @retval  EFI_DEVICE_ERROR           A device error occurred while attempting to send \r
-                                      the SCSI Request Packet.\r
-  @retval  EFI_INVALID_PARAMETER      The contents of CommandPacket are invalid.  \r
-  @retval  EFI_UNSUPPORTED            The command described by the SCSI Request Packet\r
-                                      is not supported by the SCSI initiator(i.e., SCSI \r
-                                      Host Controller).\r
-  @retval  EFI_TIMEOUT                A timeout occurred while waiting for the SCSI \r
-                                      Request Packet to execute.\r
-
+  Submit SCSI read capacity command with the SCSI request packet specified by this SCSI \r
+  command and the input parameters, and then return the status of Scsi unit execution.\r
+\r
+  If SenseDataLength is NULL, then ASSERT().\r
+\r
+  If HostAdapterStatus is NULL, then ASSERT().\r
+\r
+  If TargetStatus is NULL, then ASSERT().\r
+\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]     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[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                Command is executed successfully.\r
+  @retval  EFI_WARN_BUFFER_TOO_SMALL  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
+  @retval  EFI_INVALID_PARAMETER      ScsiIo is NULL.\r
+\r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 ScsiReadCapacityCommand (\r
   IN  EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
   IN  UINT64                Timeout,\r
@@ -409,10 +500,19 @@ ScsiReadCapacityCommand (
   UINT8                           *Target;\r
   UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
   EFI_STATUS                      Status;\r
-  UINT8                           Cdb[10];\r
+  UINT8                           Cdb[EFI_SCSI_OP_LENGTH_TEN];\r
+\r
+  ASSERT (SenseDataLength != NULL);\r
+  ASSERT (HostAdapterStatus != NULL);\r
+  ASSERT (TargetStatus != NULL);\r
+  ASSERT (DataLength != NULL);\r
+  \r
+  if (ScsiIo == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
 \r
   ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r
-  ZeroMem (Cdb, 10);\r
+  ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TEN);\r
 \r
   CommandPacket.Timeout         = Timeout;\r
   CommandPacket.InDataBuffer    = DataBuffer;\r
@@ -426,7 +526,7 @@ ScsiReadCapacityCommand (
   ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
 \r
   Cdb[0]  = EFI_SCSI_OP_READ_CAPACITY;\r
-  Cdb[1]  = (UINT8) (Lun & 0xe0);\r
+  Cdb[1]  = (UINT8) (Lun & 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
@@ -436,7 +536,7 @@ ScsiReadCapacityCommand (
     Cdb[8] |= 0x01;\r
   }\r
 \r
-  CommandPacket.CdbLength       = 10;\r
+  CommandPacket.CdbLength       = EFI_SCSI_OP_LENGTH_TEN;\r
   CommandPacket.DataDirection   = EFI_SCSI_DATA_IN;\r
   CommandPacket.SenseDataLength = *SenseDataLength;\r
 \r
@@ -451,39 +551,45 @@ ScsiReadCapacityCommand (
 }\r
 \r
 \r
-/**
+/**\r
   Function to submit read 10 command.\r
-
-  @param[in]     ScsiIo             A pointer to SCSI IO protocol.
-  @param[in]     Timeout            The length of timeout period.
-  @param[out]    SenseData          A pointer to output sense data.
-  @param[in,out] SenseDataLength    The length of output sense data.
-  @param[out]    HostAdapterStatus  The status of Host Adapter.
-  @param[out]    TargetStatus       The status of the target.
-  @param[out]    DataBuffer         Read 10 command data.
-  @param[in,out] DataLength         The length of data buffer.
-  @param[in]     StartLba           The start address of LBA.
-  @param[in]     SectorSize         The sector size.
-
-  @retval EFI_SUCCESS               The status of the unit is tested successfully.\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 TransferLength.\r
-  @retval EFI_NOT_READY             The SCSI Request Packet could not be sent because \r
-                                    there are too many SCSI Command Packets already \r
-                                    queued.\r
-  @retval EFI_DEVICE_ERROR          A device error occurred while attempting to send \r
-                                    the SCSI Request Packet.\r
-  @retval EFI_INVALID_PARAMETER     The contents of CommandPacket are invalid.  \r
-  @retval EFI_UNSUPPORTED           The command described by the SCSI Request Packet\r
-                                    is not supported by the SCSI initiator(i.e., SCSI \r
-                                    Host Controller).\r
-  @retval EFI_TIMEOUT               A timeout occurred while waiting for the SCSI \r
-                                    Request Packet to execute.\r
-
+\r
+  Submit SCSI read (10) command with the SCSI request packet specified by this SCSI command \r
+  and the input parameters, and then return the status of Scsi unit execution.\r
+\r
+  If SenseDataLength is NULL, then ASSERT().\r
+\r
+  If HostAdapterStatus is NULL, then ASSERT().\r
+\r
+  If TargetStatus is NULL, then ASSERT().\r
+\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]     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[out]    DataBuffer           Read 10 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                Command is executed successfully.\r
+  @retval  EFI_WARN_BUFFER_TOO_SMALL  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
+  @retval  EFI_INVALID_PARAMETER      ScsiIo is NULL.\r
+\r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 ScsiRead10Command (\r
   IN  EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
   IN  UINT64                Timeout,\r
@@ -502,10 +608,19 @@ ScsiRead10Command (
   UINT8                           *Target;\r
   UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
   EFI_STATUS                      Status;\r
-  UINT8                           Cdb[10];\r
+  UINT8                           Cdb[EFI_SCSI_OP_LENGTH_TEN];\r
+\r
+  ASSERT (SenseDataLength != NULL);\r
+  ASSERT (HostAdapterStatus != NULL);\r
+  ASSERT (TargetStatus != NULL);\r
+  ASSERT (DataLength != NULL);\r
+  \r
+  if (ScsiIo == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
 \r
   ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r
-  ZeroMem (Cdb, 10);\r
+  ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TEN);\r
 \r
   CommandPacket.Timeout         = Timeout;\r
   CommandPacket.InDataBuffer    = DataBuffer;\r
@@ -519,7 +634,7 @@ ScsiRead10Command (
   ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
 \r
   Cdb[0]                        = EFI_SCSI_OP_READ10;\r
-  Cdb[1]                        = (UINT8) (Lun & 0xe0);\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
@@ -527,7 +642,7 @@ ScsiRead10Command (
   Cdb[7]                        = (UINT8) (SectorSize >> 8);\r
   Cdb[8]                        = (UINT8) (SectorSize & 0xff);\r
 \r
-  CommandPacket.CdbLength       = 10;\r
+  CommandPacket.CdbLength       = EFI_SCSI_OP_LENGTH_TEN;\r
   CommandPacket.DataDirection   = EFI_SCSI_DATA_IN;\r
   CommandPacket.SenseDataLength = *SenseDataLength;\r
 \r
@@ -542,39 +657,45 @@ ScsiRead10Command (
 }\r
 \r
 \r
-/**
+/**\r
   Function to submit SCSI write 10 command.\r
-
-  @param[in]     ScsiIo             SCSI IO Protocol to use
-  @param[in]     Timeout            The length of timeout period.
-  @param[out]    SenseData          A pointer to output sense data.
-  @param[in,out] SenseDataLength    The length of output sense data.
-  @param[out]    HostAdapterStatus  The status of Host Adapter.
-  @param[out]    TargetStatus       The status of the target.
-  @param[out]    DataBuffer         A pointer to a data buffer.
-  @param[in,out] DataLength         The length of data buffer.
-  @param[in]     StartLba           The start address of LBA.
-  @param[in]     SectorSize         The sector size.
-
-  @retval EFI_SUCCESS               The status of the unit is tested successfully.\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
-  @retval EFI_NOT_READY             The SCSI Request Packet could not be sent because \r
-                                    there are too many SCSI Command Packets already \r
-                                    queued.\r
-  @retval EFI_DEVICE_ERROR          A device error occurred while attempting to send \r
-                                    the SCSI Request Packet.\r
-  @retval EFI_INVALID_PARAMETER     The contents of CommandPacket are invalid.  \r
-  @retval EFI_UNSUPPORTED           The command described by the SCSI Request Packet\r
-                                    is not supported by the SCSI initiator(i.e., SCSI \r
-                                    Host Controller).\r
-  @retval EFI_TIMEOUT               A timeout occurred while waiting for the SCSI \r
-                                    Request Packet to execute.\r
-
+\r
+  Submit SCSI write (10) command with the SCSI request packet specified by this SCSI command and the\r
+  input parameters, and then return the status of Scsi unit execution.\r
+\r
+  If SenseDataLength is NULL, then ASSERT().\r
+\r
+  If HostAdapterStatus is NULL, then ASSERT().\r
+\r
+  If TargetStatus is NULL, then ASSERT().\r
+\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]     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[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                Command is executed successfully.\r
+  @retval  EFI_WARN_BUFFER_TOO_SMALL  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
+  @retval  EFI_INVALID_PARAMETER      ScsiIo is NULL.\r
+\r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 ScsiWrite10Command (\r
   IN  EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
   IN  UINT64                Timeout,\r
@@ -593,10 +714,19 @@ ScsiWrite10Command (
   UINT8                           *Target;\r
   UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
   EFI_STATUS                      Status;\r
-  UINT8                           Cdb[10];\r
+  UINT8                           Cdb[EFI_SCSI_OP_LENGTH_TEN];\r
+\r
+  ASSERT (SenseDataLength != NULL);\r
+  ASSERT (HostAdapterStatus != NULL);\r
+  ASSERT (TargetStatus != NULL);\r
+  ASSERT (DataLength != NULL);\r
+  \r
+  if (ScsiIo == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
 \r
   ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r
-  ZeroMem (Cdb, 10);\r
+  ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TEN);\r
 \r
   CommandPacket.Timeout         = Timeout;\r
   CommandPacket.OutDataBuffer    = DataBuffer;\r
@@ -610,7 +740,7 @@ ScsiWrite10Command (
   ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
 \r
   Cdb[0]                        = EFI_SCSI_OP_WRITE10;\r
-  Cdb[1]                        = (UINT8) (Lun & 0xe0);\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
@@ -618,7 +748,7 @@ ScsiWrite10Command (
   Cdb[7]                        = (UINT8) (SectorSize >> 8);\r
   Cdb[8]                        = (UINT8) SectorSize;\r
 \r
-  CommandPacket.CdbLength       = 10;\r
+  CommandPacket.CdbLength       = EFI_SCSI_OP_LENGTH_TEN;\r
   CommandPacket.DataDirection   = EFI_SCSI_DATA_OUT;\r
   CommandPacket.SenseDataLength = *SenseDataLength;\r
 \r
@@ -627,7 +757,8 @@ ScsiWrite10Command (
   *HostAdapterStatus            = CommandPacket.HostAdapterStatus;\r
   *TargetStatus                 = CommandPacket.TargetStatus;\r
   *SenseDataLength              = CommandPacket.SenseDataLength;\r
-  *DataLength                   = CommandPacket.InTransferLength;\r
+  *DataLength                   = CommandPacket.OutTransferLength;\r
 \r
   return Status;\r
 }\r
+\r