]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiScsiLib/UefiScsiLib.c
Code Scrub the common includes in MdePkg.
[mirror_edk2.git] / MdePkg / Library / UefiScsiLib / UefiScsiLib.c
index 20088d5cbfa7d2f490c511e3952af3e83a4c5c4b..ac032cd4d5bce9964a97ecb2716204291809d812 100644 (file)
 \r
 \r
 #include <PiDxe.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
-/**
+/**\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
+  @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 the sense data that \r
+                                    was generated by the execution of the SCSI Request Packet.\r
+  @param[in out] SenseDataLength    On input, the length in bytes of the SenseData buffer. On\r
+                                    output, the number of bytes written to the SenseData buffer.\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 The contents of CommandPacket are invalid, or 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
-  OUT UINT8                 *SenseDataLength,\r
+  IN OUT VOID               *SenseData,\r
+  IN OUT UINT8              *SenseDataLength,\r
   OUT UINT8                 *HostAdapterStatus,\r
   OUT UINT8                 *TargetStatus\r
   )\r
@@ -65,6 +69,13 @@ ScsiTestUnitReadyCommand (
   EFI_STATUS                      Status;\r
   UINT8                           Cdb[6];\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
@@ -97,19 +108,20 @@ 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.
-
+\r
+  @param[in]     ScsiIo             SCSI IO Protocol to use\r
+  @param[in]     Timeout            The length of timeout period.\r
+  @param[out]    SenseData          A pointer to output sense data.\r
+  @param[in out] SenseDataLength    On input, the length in bytes of the SenseData buffer. On\r
+                                    output, the number of bytes written to the SenseData buffer.\r
+  @param[out]    HostAdapterStatus  The status of Host Adapter.\r
+  @param[out]    TargetStatus       The status of the target.\r
+  @param[in]     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         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
@@ -120,15 +132,16 @@ ScsiTestUnitReadyCommand (
                           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 The contents of CommandPacket are invalid, or 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
@@ -136,7 +149,7 @@ ScsiInquiryCommand (
   IN OUT UINT8              *SenseDataLength,\r
   OUT UINT8                 *HostAdapterStatus,\r
   OUT UINT8                 *TargetStatus,\r
-  IN OUT VOID               *InquiryDataBuffer,\r
+  IN VOID                   *InquiryDataBuffer,\r
   IN OUT UINT32             *InquiryDataLength,\r
   IN  BOOLEAN               EnableVitalProductData\r
   )\r
@@ -148,6 +161,15 @@ ScsiInquiryCommand (
   EFI_STATUS                      Status;\r
   UINT8                           Cdb[6];\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
 \r
@@ -186,23 +208,24 @@ 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
+  @param[in]     ScsiIo             A pointer to SCSI IO protocol.\r
+  @param[in]     Timeout            The length of timeout period.\r
+  @param[out]    SenseData          A pointer to output sense data.\r
+  @param[in out] SenseDataLength    On input, the length in bytes of the SenseData buffer. On\r
+                                    output, the number of bytes written to the SenseData buffer.\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_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, \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
@@ -211,15 +234,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     The contents of CommandPacket are invalid, or 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
@@ -241,6 +265,15 @@ ScsiModeSense10Command (
   EFI_STATUS                      Status;\r
   UINT8                           Cdb[10];\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
 \r
@@ -276,25 +309,20 @@ 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
+\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    On input, the length in bytes of the SenseData buffer. On\r
+                                    output, the number of bytes written to the SenseData buffer.\r
+  @param[out]    HostAdapterStatus  The status of Host Adapter.\r
+  @param[out]    TargetStatus       The status of the target.\r
+\r
+  @retval EFI_SUCCESS        Valid data returned\r
   @retval EFI_SUCCESS        The status of the unit is tested successfully.\r
-  @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, \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
@@ -303,15 +331,16 @@ ScsiModeSense10Command (
                                     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     The contents of CommandPacket are invalid, or 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
 ScsiRequestSenseCommand (\r
   IN  EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
   IN  UINT64                Timeout,\r
@@ -328,6 +357,14 @@ ScsiRequestSenseCommand (
   EFI_STATUS                      Status;\r
   UINT8                           Cdb[6];\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
 \r
@@ -360,21 +397,22 @@ 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.
-
+  @param[in]     ScsiIo             A pointer to SCSI IO protocol.\r
+  @param[in]     Timeout            The length of timeout period.\r
+  @param[out]    SenseData          A pointer to output sense data.\r
+  @param[in out] SenseDataLength    On input, the length in bytes of the SenseData buffer. On\r
+                                    output, the number of bytes written to the SenseData buffer.\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                The status of the unit is tested successfully.\r
-  @retval  EFI_WARN_BUFFER_TOO_SMALL  The SCSI Request Packet was executed, \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
@@ -383,15 +421,16 @@ ScsiRequestSenseCommand (
                                       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      The contents of CommandPacket are invalid, or 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
 ScsiReadCapacityCommand (\r
   IN  EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
   IN  UINT64                Timeout,\r
@@ -411,6 +450,15 @@ ScsiReadCapacityCommand (
   EFI_STATUS                      Status;\r
   UINT8                           Cdb[10];\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
 \r
@@ -451,22 +499,23 @@ 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.
-
+\r
+  @param[in]     ScsiIo             A pointer to SCSI IO protocol.\r
+  @param[in]     Timeout            The length of timeout period.\r
+  @param[out]    SenseData          A pointer to output sense data.\r
+  @param[in out] SenseDataLength    On input, the length in bytes of the SenseData buffer. On\r
+                                    output, the number of bytes written to the SenseData buffer.\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               The status of the unit is tested successfully.\r
-  @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, \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
@@ -475,15 +524,16 @@ ScsiReadCapacityCommand (
                                     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     The contents of CommandPacket are invalid, or 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
 ScsiRead10Command (\r
   IN  EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
   IN  UINT64                Timeout,\r
@@ -504,6 +554,15 @@ ScsiRead10Command (
   EFI_STATUS                      Status;\r
   UINT8                           Cdb[10];\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
 \r
@@ -542,22 +601,23 @@ 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.
-
+\r
+  @param[in]     ScsiIo             SCSI IO Protocol to use\r
+  @param[in]     Timeout            The length of timeout period.\r
+  @param[out]    SenseData          A pointer to output sense data.\r
+  @param[in out] SenseDataLength    On input, the length in bytes of the SenseData buffer. On\r
+                                    output, the number of bytes written to the SenseData buffer.\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               The status of the unit is tested successfully.\r
-  @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, \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
@@ -566,15 +626,16 @@ ScsiRead10Command (
                                     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     The contents of CommandPacket are invalid, or 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
 ScsiWrite10Command (\r
   IN  EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
   IN  UINT64                Timeout,\r
@@ -595,6 +656,15 @@ ScsiWrite10Command (
   EFI_STATUS                      Status;\r
   UINT8                           Cdb[10];\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
 \r
@@ -627,7 +697,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