]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiScsiLib/UefiScsiLib.c
Fix ScsiLib build break by << operator, which is replaced by LShiftU64 of BaseLib.
[mirror_edk2.git] / MdePkg / Library / UefiScsiLib / UefiScsiLib.c
index 5f125ab29f6352b256e5afd9ecab605ac171c342..8fcc3d157dce8684d716443184632d8318109b6f 100644 (file)
@@ -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
@@ -143,7 +144,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
@@ -192,7 +193,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
@@ -276,7 +277,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
@@ -338,7 +339,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
@@ -428,11 +429,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
@@ -516,7 +517,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
@@ -539,7 +540,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
@@ -554,7 +555,7 @@ 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                  Partial medium indicator.\r
 \r
   @retval  EFI_SUCCESS           Command is executed successfully.\r
   @retval  EFI_BAD_BUFFER_SIZE   The SCSI Request Packet was executed, but the entire\r
@@ -579,7 +580,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
@@ -610,10 +611,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
@@ -635,6 +636,103 @@ 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           Command is 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
+  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
@@ -715,7 +813,7 @@ 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[1]                        = (UINT8) (LShiftU64 (Lun, 5) & 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
@@ -817,7 +915,7 @@ 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[1]                        = (UINT8) (LShiftU64 (Lun, 5) & 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