]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
Add compiler hint of "GLOBAL_REMOVE_IF_UNREFERENCED" to prevent static unicode string...
[mirror_edk2.git] / MdeModulePkg / Bus / Scsi / ScsiBusDxe / ScsiBus.c
index 1110310f92e8bfa9a32c0c935c77848bf8e678b6..0defe736cb26c5f8f9e19d585be994766f20a6d4 100644 (file)
@@ -109,18 +109,16 @@ InitializeScsiBus(
   //\r
   // Install driver model protocol(s).\r
   //\r
-  Status = EfiLibInstallAllDriverProtocols (\r
+  Status = EfiLibInstallDriverBindingComponentName2 (\r
              ImageHandle,\r
              SystemTable,\r
              &gSCSIBusDriverBinding,\r
              ImageHandle,\r
              &gScsiBusComponentName,\r
-             NULL,\r
-             NULL\r
+             &gScsiBusComponentName2\r
              );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-\r
   return Status;\r
 }\r
 \r
@@ -231,124 +229,156 @@ Returns:
   EFI_DEVICE_ERROR    - This driver cannot be started due to device Error\r
 \r
 --*/\r
-// TODO:    This - add argument and description to function comment\r
-// TODO:    Controller - add argument and description to function comment\r
-// TODO:    RemainingDevicePath - add argument and description to function comment\r
 {\r
-  EFI_STATUS                  Status;\r
-  UINT64                      Lun;\r
-  BOOLEAN                     ScanOtherPuns;\r
-  SCSI_BUS_DEVICE             *ScsiBusDev;\r
-  BOOLEAN                     FromFirstTarget;\r
-  SCSI_TARGET_ID              *ScsiTargetId;\r
-  UINT8                       *TargetId;\r
-\r
-  TargetId = NULL;\r
-  ScanOtherPuns = TRUE;\r
+  UINT64                                Lun;\r
+  UINT8                                 *TargetId;\r
+  BOOLEAN                               ScanOtherPuns;\r
+  BOOLEAN                               FromFirstTarget;\r
+  BOOLEAN                               ExtScsiSupport;\r
+  EFI_STATUS                            Status;\r
+  EFI_STATUS                            DevicePathStatus;\r
+  EFI_STATUS                            PassThruStatus;\r
+  SCSI_BUS_DEVICE                       *ScsiBusDev;\r
+  SCSI_TARGET_ID                        *ScsiTargetId;\r
+  EFI_DEVICE_PATH_PROTOCOL              *ParentDevicePath;\r
+  EFI_SCSI_PASS_THRU_PROTOCOL           *ScsiInterface;\r
+  EFI_EXT_SCSI_PASS_THRU_PROTOCOL       *ExtScsiInterface;\r
+  EFI_SCSI_BUS_PROTOCOL                 *BusIdentify;\r
+\r
+  TargetId        = NULL;\r
+  ScsiTargetId    = NULL;\r
+  ScanOtherPuns   = TRUE;\r
   FromFirstTarget = FALSE;\r
-  //\r
-  // Allocate SCSI_BUS_DEVICE structure\r
-  //\r
-  ScsiBusDev = NULL;\r
-  ScsiBusDev = AllocateZeroPool (sizeof (SCSI_BUS_DEVICE));\r
-  if (ScsiBusDev == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  ScsiTargetId = NULL;\r
-  ScsiTargetId = AllocateZeroPool (sizeof (SCSI_TARGET_ID));\r
+  ExtScsiSupport  = FALSE;\r
+  PassThruStatus  = EFI_SUCCESS;\r
+    \r
+  ScsiTargetId = AllocateZeroPool(sizeof(SCSI_TARGET_ID));\r
   if (ScsiTargetId == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
   TargetId = &ScsiTargetId->ScsiId.ExtScsi[0];\r
-\r
-  Status = gBS->OpenProtocol (\r
-                  Controller,\r
-                  &gEfiDevicePathProtocolGuid,\r
-                  (VOID **) &(ScsiBusDev->DevicePath),\r
-                  This->DriverBindingHandle,\r
-                  Controller,\r
-                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
-                  );\r
-  if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
-    gBS->FreePool (ScsiBusDev);\r
-    return Status;\r
+  \r
+  DevicePathStatus = gBS->OpenProtocol (\r
+                            Controller,\r
+                            &gEfiDevicePathProtocolGuid,\r
+                            (VOID **) &ParentDevicePath,\r
+                            This->DriverBindingHandle,\r
+                            Controller,\r
+                            EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                            );\r
+  if (EFI_ERROR (DevicePathStatus) && (DevicePathStatus != EFI_ALREADY_STARTED)) {\r
+    return DevicePathStatus;\r
   }\r
 \r
   //\r
-  // First consume Extended SCSI Pass Thru protocol, if fail, then consume\r
-  // SCSI Pass Thru protocol\r
+  // To keep backward compatibility, UEFI ExtPassThru Protocol is supported as well as \r
+  // EFI PassThru Protocol. From priority perspective, ExtPassThru Protocol is firstly\r
+  // tried to open on host controller handle. If fails, then PassThru Protocol is tried instead.\r
   //\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiExtScsiPassThruProtocolGuid,\r
-                  (VOID **) &(ScsiBusDev->ExtScsiInterface),\r
+                  (VOID **) &ExtScsiInterface,\r
                   This->DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
-  if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
+  //\r
+  // Fail to open UEFI ExtendPassThru Protocol, then try to open EFI PassThru Protocol instead.\r
+  //\r
+  if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) {\r
     Status = gBS->OpenProtocol (\r
                     Controller,\r
                     &gEfiScsiPassThruProtocolGuid,\r
-                    (VOID **) &(ScsiBusDev->ScsiInterface),\r
+                    (VOID **) &ScsiInterface,\r
                     This->DriverBindingHandle,\r
                     Controller,\r
                     EFI_OPEN_PROTOCOL_BY_DRIVER\r
                     );\r
-    if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
-      gBS->CloseProtocol (\r
-             Controller,\r
-             &gEfiDevicePathProtocolGuid,\r
-             This->DriverBindingHandle,\r
-             Controller\r
-             );\r
-      gBS->FreePool (ScsiBusDev);\r
+    //\r
+    // Fail to open EFI PassThru Protocol, Close the DevicePathProtocol if it is opened by this time.\r
+    //\r
+    if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {\r
+      if (!EFI_ERROR(DevicePathStatus)) {\r
+        gBS->CloseProtocol (\r
+               Controller,\r
+               &gEfiDevicePathProtocolGuid,\r
+               This->DriverBindingHandle,\r
+               Controller\r
+               );\r
+      } \r
       return Status;\r
-    }\r
-    DEBUG ((EFI_D_INFO, "Open Scsi Pass Thrugh Protocol\n"));\r
-    ScsiBusDev->ExtScsiSupport  = FALSE;\r
+    } \r
   } else {\r
-    DEBUG ((EFI_D_INFO, "Open Extended Scsi Pass Thrugh Protocol\n"));\r
-    ScsiBusDev->ExtScsiSupport  = TRUE;\r
+    //\r
+    // Succeed to open ExtPassThru Protocol, and meanwhile open PassThru Protocol \r
+    // with BY_DRIVER if it is also present on the handle. The intent is to prevent \r
+    // another SCSI Bus Driver to work on the same host handle.\r
+    //\r
+    ExtScsiSupport = TRUE;\r
+    PassThruStatus = gBS->OpenProtocol (\r
+                            Controller,\r
+                            &gEfiScsiPassThruProtocolGuid,\r
+                            (VOID **) &ScsiInterface,\r
+                            This->DriverBindingHandle,\r
+                            Controller,\r
+                            EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                            );\r
   }\r
-\r
-  ScsiBusDev->Signature = SCSI_BUS_DEVICE_SIGNATURE;\r
-  //\r
-  // Attach EFI_SCSI_BUS_PROTOCOL to controller handle\r
-  //\r
-  Status = gBS->InstallProtocolInterface (\r
-                  &Controller,\r
-                  &mScsiBusProtocolGuid,\r
-                  EFI_NATIVE_INTERFACE,\r
-                  &ScsiBusDev->BusIdentify\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    gBS->CloseProtocol (\r
-           Controller,\r
-           &gEfiDevicePathProtocolGuid,\r
-           This->DriverBindingHandle,\r
-           Controller\r
-           );\r
+    \r
+  if (Status != EFI_ALREADY_STARTED) {\r
+    //\r
+    // Go through here means either ExtPassThru or PassThru Protocol is successfully opened\r
+    // on this handle for this time. Then construct Host controller private data.\r
+    //\r
+    ScsiBusDev = NULL;\r
+    ScsiBusDev = AllocateZeroPool(sizeof(SCSI_BUS_DEVICE));\r
+    if (ScsiBusDev == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto ErrorExit;\r
+    }\r
+    ScsiBusDev->Signature        = SCSI_BUS_DEVICE_SIGNATURE;\r
+    ScsiBusDev->ExtScsiSupport   = ExtScsiSupport;\r
+    ScsiBusDev->DevicePath       = ParentDevicePath;\r
     if (ScsiBusDev->ExtScsiSupport) {\r
-      gBS->CloseProtocol (\r
-             Controller,\r
-             &gEfiExtScsiPassThruProtocolGuid,\r
-             This->DriverBindingHandle,\r
-             Controller\r
-             );\r
+      ScsiBusDev->ExtScsiInterface = ExtScsiInterface;\r
     } else {\r
-      gBS->CloseProtocol (\r
-             Controller,\r
-             &gEfiScsiPassThruProtocolGuid,\r
-             This->DriverBindingHandle,\r
-             Controller\r
-             );\r
+      ScsiBusDev->ScsiInterface    = ScsiInterface;    \r
     }\r
-    gBS->FreePool (ScsiBusDev);\r
-    return Status;\r
+\r
+    //\r
+    // Install EFI_SCSI_BUS_PROTOCOL to the controller handle, So ScsiBusDev could be\r
+    // retrieved on this controller handle. With ScsiBusDev, we can know which PassThru\r
+    // Protocol is present on the handle, UEFI ExtPassThru Protocol or EFI PassThru Protocol.\r
+    // \r
+    Status = gBS->InstallProtocolInterface (\r
+                    &Controller,\r
+                    &mScsiBusProtocolGuid,\r
+                    EFI_NATIVE_INTERFACE,\r
+                    &ScsiBusDev->BusIdentify\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      goto ErrorExit;\r
+    }\r
+  } else {\r
+    //\r
+    // Go through here means Start() is re-invoked again, nothing special is required to do except\r
+    // picking up Host controller private information.\r
+    //\r
+    Status = gBS->OpenProtocol (\r
+                    Controller,\r
+                    &mScsiBusProtocolGuid,\r
+                    (VOID **) &BusIdentify,\r
+                    This->DriverBindingHandle,\r
+                    Controller,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+    ScsiBusDev = SCSI_BUS_CONTROLLER_DEVICE_FROM_THIS (BusIdentify);\r
   }\r
 \r
   if (RemainingDevicePath == NULL) {\r
@@ -357,7 +387,7 @@ Returns:
     FromFirstTarget = TRUE;\r
   } else {\r
     if (ScsiBusDev->ExtScsiSupport) {\r
-      ScsiBusDev->ExtScsiInterface->GetTargetLun (ScsiBusDev->ExtScsiInterface, RemainingDevicePath, &TargetId, &Lun);\r
+      ScsiBusDev->ExtScsiInterface->GetTargetLun (ScsiBusDev->ExtScsiInterface, RemainingDevicePath, &TargetId, &Lun);  \r
     } else {\r
       ScsiBusDev->ScsiInterface->GetTargetLun (ScsiBusDev->ScsiInterface, RemainingDevicePath, &ScsiTargetId->ScsiId.Scsi, &Lun);\r
     }\r
@@ -401,6 +431,38 @@ Returns:
     //\r
     Status = ScsiScanCreateDevice (This, Controller, ScsiTargetId, Lun, ScsiBusDev);\r
   }\r
+  gBS->FreePool (ScsiTargetId);\r
+  return EFI_SUCCESS;\r
+  \r
+ErrorExit:\r
+  \r
+  if (ScsiBusDev != NULL) {\r
+    gBS->FreePool (ScsiBusDev);\r
+  }\r
+  \r
+  if (ExtScsiSupport) {\r
+    gBS->CloseProtocol (\r
+           Controller,\r
+           &gEfiExtScsiPassThruProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           Controller\r
+           );\r
+    if (!EFI_ERROR (PassThruStatus)) {\r
+      gBS->CloseProtocol (\r
+             Controller,\r
+             &gEfiScsiPassThruProtocolGuid,\r
+             This->DriverBindingHandle,\r
+             Controller\r
+             );\r
+    }\r
+  } else {\r
+    gBS->CloseProtocol (\r
+           Controller,\r
+           &gEfiScsiPassThruProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           Controller\r
+           );\r
+  }\r
   return Status;\r
 }\r
 \r
@@ -414,20 +476,23 @@ SCSIBusDriverBindingStop (
   )\r
 /*++\r
 \r
-  Routine Description:\r
+Routine Description:\r
 \r
-  Arguments:\r
+  Stop this driver on ControllerHandle. Support stoping any child handles\r
+  created by this driver.\r
 \r
-  Returns:\r
+Arguments:\r
 \r
+  This              - Protocol instance pointer.\r
+  Controller        - Handle of device to stop driver on\r
+  NumberOfChildren  - Number of Children in the ChildHandleBuffer\r
+  ChildHandleBuffer - List of handles for the children we need to stop.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS\r
+  Others\r
 --*/\r
-// TODO:    This - add argument and description to function comment\r
-// TODO:    Controller - add argument and description to function comment\r
-// TODO:    NumberOfChildren - add argument and description to function comment\r
-// TODO:    ChildHandleBuffer - add argument and description to function comment\r
-// TODO:    EFI_SUCCESS - add return value to function comment\r
-// TODO:    EFI_DEVICE_ERROR - add return value to function comment\r
-// TODO:    EFI_SUCCESS - add return value to function comment\r
 {\r
   EFI_STATUS                  Status;\r
   BOOLEAN                     AllChildrenStopped;\r
@@ -582,17 +647,21 @@ ScsiGetDeviceType (
   )\r
 /*++\r
 \r
-  Routine Description:\r
-    Retrieves the device type information of the SCSI Controller.\r
+Routine Description:\r
 \r
-  Arguments:\r
-    This                  - Protocol instance pointer.\r
-    DeviceType            - A pointer to the device type information\r
-                            retrieved from the SCSI Controller.\r
+  Retrieves the device type information of the SCSI Controller.\r
+    \r
+Arguments:\r
 \r
-  Returns:\r
-    EFI_SUCCESS           - Retrieves the device type information successfully.\r
-    EFI_INVALID_PARAMETER - The DeviceType is NULL.\r
+  This                  - Protocol instance pointer.\r
+  DeviceType            - A pointer to the device type information\r
+                            retrieved from the SCSI Controller. \r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - Retrieves the device type information successfully.\r
+  EFI_INVALID_PARAMETER - The DeviceType is NULL.\r
+  \r
 --*/\r
 {\r
   SCSI_IO_DEV *ScsiIoDevice;\r
@@ -614,19 +683,24 @@ ScsiGetDeviceLocation (
   OUT UINT64                  *Lun\r
   )\r
 /*++\r
-  Routine Description:\r
-    Retrieves the device location in the SCSI channel.\r
-\r
-  Arguments:\r
-    This                  - Protocol instance pointer.\r
-    Target                - A pointer to the Target ID of a SCSI device\r
-                            on the SCSI channel.\r
-    Lun                   - A pointer to the LUN of the SCSI device on\r
-                            the SCSI channel.\r
-\r
-  Returns:\r
-    EFI_SUCCESS           - Retrieves the device location successfully.\r
-    EFI_INVALID_PARAMETER - The Target or Lun is NULL.\r
+\r
+Routine Description:\r
+\r
+  Retrieves the device location in the SCSI channel.\r
+    \r
+Arguments:\r
+\r
+  This                  - Protocol instance pointer.\r
+  Target                - A pointer to the Target Array which represents ID of a SCSI device \r
+                          on the SCSI channel. \r
+  Lun                   - A pointer to the LUN of the SCSI device on \r
+                          the SCSI channel.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - Retrieves the device location successfully.\r
+  EFI_INVALID_PARAMETER - The Target or Lun is NULL.\r
+\r
 --*/\r
 {\r
   SCSI_IO_DEV *ScsiIoDevice;\r
@@ -635,11 +709,11 @@ ScsiGetDeviceLocation (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  ScsiIoDevice  = SCSI_IO_DEV_FROM_THIS (This);\r
+  ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This);\r
 \r
   CopyMem (*Target,&ScsiIoDevice->Pun, TARGET_MAX_BYTES);\r
 \r
-  *Lun          = ScsiIoDevice->Lun;\r
+  *Lun         = ScsiIoDevice->Lun;\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -651,19 +725,22 @@ ScsiResetBus (
   )\r
 /*++\r
 \r
-  Routine Description:\r
-    Resets the SCSI Bus that the SCSI Controller is attached to.\r
+Routine Description:\r
 \r
-  Arguments:\r
-    This                  - Protocol instance pointer.\r
+  Resets the SCSI Bus that the SCSI Controller is attached to.\r
+    \r
+Arguments:\r
 \r
-  Returns:\r
-    EFI_SUCCESS           - The SCSI bus is reset successfully.\r
-    EFI_DEVICE_ERROR      - Errors encountered when resetting the SCSI bus.\r
-    EFI_UNSUPPORTED       - The bus reset operation is not supported by the\r
-                            SCSI Host Controller.\r
-    EFI_TIMEOUT           - A timeout occurred while attempting to reset\r
-                            the SCSI bus.\r
+  This                  - Protocol instance pointer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The SCSI bus is reset successfully.\r
+  EFI_DEVICE_ERROR      - Errors encountered when resetting the SCSI bus.\r
+  EFI_UNSUPPORTED       - The bus reset operation is not supported by the\r
+                          SCSI Host Controller.\r
+  EFI_TIMEOUT           - A timeout occurred while attempting to reset \r
+                          the SCSI bus.\r
 --*/\r
 {\r
   SCSI_IO_DEV *ScsiIoDevice;\r
@@ -684,24 +761,26 @@ ScsiResetDevice (
   )\r
 /*++\r
 \r
-  Routine Description:\r
-    Resets the SCSI Controller that the device handle specifies.\r
+Routine Description:\r
 \r
-  Arguments:\r
-    This                  - Protocol instance pointer.\r
+  Resets the SCSI Controller that the device handle specifies.\r
+    \r
+Arguments:\r
 \r
+  This                  - Protocol instance pointer.\r
+    \r
+Returns:\r
 \r
-  Returns:\r
-    EFI_SUCCESS           - Reset the SCSI controller successfully.\r
-    EFI_DEVICE_ERROR      - Errors are encountered when resetting the\r
-                            SCSI Controller.\r
-    EFI_UNSUPPORTED       - The SCSI bus does not support a device\r
-                            reset operation.\r
-    EFI_TIMEOUT           - A timeout occurred while attempting to\r
-                            reset the SCSI Controller.\r
+  EFI_SUCCESS           - Reset the SCSI controller successfully.\r
+  EFI_DEVICE_ERROR      - Errors are encountered when resetting the\r
+                          SCSI Controller.\r
+  EFI_UNSUPPORTED       - The SCSI bus does not support a device \r
+                          reset operation.\r
+  EFI_TIMEOUT           - A timeout occurred while attempting to \r
+                          reset the SCSI Controller.\r
 --*/\r
 {\r
-  SCSI_IO_DEV *ScsiIoDevice;\r
+  SCSI_IO_DEV  *ScsiIoDevice;\r
   UINT8        Target[TARGET_MAX_BYTES];\r
 \r
   ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This);\r
@@ -732,64 +811,67 @@ ScsiExecuteSCSICommand (
   )\r
 /*++\r
 \r
-  Routine Description:\r
-    Sends a SCSI Request Packet to the SCSI Controller for execution.\r
-\r
-  Arguments:\r
-    This                  - Protocol instance pointer.\r
-    Packet                - The SCSI request packet to send to the SCSI\r
-                            Controller specified by the device handle.\r
-    Event                 - If the SCSI bus where the SCSI device is attached\r
-                            does not support non-blocking I/O, then Event is\r
-                            ignored, and blocking I/O is performed.\r
-                            If Event is NULL, then blocking I/O is performed.\r
-                            If Event is not NULL and non-blocking I/O is\r
-                            supported, then non-blocking I/O is performed,\r
-                            and Event will be signaled when the SCSI Request\r
-                            Packet completes.\r
-  Returns:\r
-    EFI_SUCCESS           - The SCSI Request Packet was sent by the host\r
-                            successfully, and TransferLength bytes were\r
-                            transferred to/from DataBuffer.See\r
-                            HostAdapterStatus, TargetStatus,\r
-                            SenseDataLength, and SenseData in that order\r
-                            for additional status information.\r
-    EFI_WARN_BUFFER_TOO_SMALL - 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. See HostAdapterStatus,\r
-                            TargetStatus, SenseDataLength, and SenseData in\r
-                            that order for additional status information.\r
-    EFI_NOT_READY         - The SCSI Request Packet could not be sent because\r
-                            there are too many SCSI Command Packets already\r
-                            queued.The caller may retry again later.\r
-    EFI_DEVICE_ERROR      - A device error occurred while attempting to send\r
-                            the SCSI Request Packet. See HostAdapterStatus,\r
-                            TargetStatus, SenseDataLength, and SenseData in\r
-                            that order for additional status information.\r
-    EFI_INVALID_PARAMETER - The contents of CommandPacket are invalid.\r
-                            The SCSI Request Packet was not sent, so no\r
-                            additional status information is available.\r
-    EFI_UNSUPPORTED       - The command described by the SCSI Request Packet\r
-                            is not supported by the SCSI initiator(i.e., SCSI\r
-                            Host Controller). The SCSI Request Packet was not\r
-                            sent, so no additional status information is\r
-                            available.\r
-    EFI_TIMEOUT           - A timeout occurred while waiting for the SCSI\r
-                            Request Packet to execute. See HostAdapterStatus,\r
-                            TargetStatus, SenseDataLength, and SenseData in\r
-                            that order for additional status information.\r
+Routine Description:\r
+\r
+  Sends a SCSI Request Packet to the SCSI Controller for execution.\r
+    \r
+Arguments:\r
+\r
+  This                  - Protocol instance pointer.\r
+  Packet                - The SCSI request packet to send to the SCSI \r
+                          Controller specified by the device handle.\r
+  Event                 - If the SCSI bus where the SCSI device is attached\r
+                          does not support non-blocking I/O, then Event is \r
+                          ignored, and blocking I/O is performed.  \r
+                          If Event is NULL, then blocking I/O is performed.\r
+                          If Event is not NULL and non-blocking I/O is \r
+                          supported, then non-blocking I/O is performed,\r
+                          and Event will be signaled when the SCSI Request\r
+                          Packet completes.\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The SCSI Request Packet was sent by the host \r
+                          successfully, and TransferLength bytes were \r
+                          transferred to/from DataBuffer.See \r
+                          HostAdapterStatus, TargetStatus, \r
+                          SenseDataLength, and SenseData in that order\r
+                          for additional status information.\r
+  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. See HostAdapterStatus, \r
+                          TargetStatus, SenseDataLength, and SenseData in \r
+                          that order for additional status information.\r
+  EFI_NOT_READY         - The SCSI Request Packet could not be sent because \r
+                          there are too many SCSI Command Packets already \r
+                          queued.The caller may retry again later.\r
+  EFI_DEVICE_ERROR      - A device error occurred while attempting to send \r
+                          the SCSI Request Packet. See HostAdapterStatus, \r
+                          TargetStatus, SenseDataLength, and SenseData in \r
+                          that order for additional status information.\r
+  EFI_INVALID_PARAMETER - The contents of CommandPacket are invalid.  \r
+                          The SCSI Request Packet was not sent, so no \r
+                          additional status information is available.\r
+  EFI_UNSUPPORTED       - The command described by the SCSI Request Packet\r
+                          is not supported by the SCSI initiator(i.e., SCSI \r
+                          Host Controller). The SCSI Request Packet was not\r
+                          sent, so no additional status information is \r
+                          available.\r
+  EFI_TIMEOUT           - A timeout occurred while waiting for the SCSI \r
+                          Request Packet to execute. See HostAdapterStatus,\r
+                          TargetStatus, SenseDataLength, and SenseData in \r
+                          that order for additional status information.\r
 --*/\r
 {\r
-  SCSI_IO_DEV                             *ScsiIoDevice;\r
-  EFI_STATUS                              Status;\r
+  SCSI_IO_DEV                                 *ScsiIoDevice;\r
+  EFI_STATUS                                  Status;\r
   UINT8                                       Target[TARGET_MAX_BYTES];\r
   EFI_EVENT                                   PacketEvent;\r
   EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET  *ExtRequestPacket;\r
-  SCSI_EVENT_DATA                             EventData;\r
+  SCSI_EVENT_DATA                             EventData;                                     \r
 \r
   PacketEvent = NULL;\r
-\r
+  \r
   if (Packet == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -1106,7 +1188,7 @@ Returns:
     }\r
   }\r
 \r
-  if (0x1e >= InquiryData.Peripheral_Type >= 0xa) {\r
+  if (0x1e >= InquiryData.Peripheral_Type && InquiryData.Peripheral_Type >= 0xa) {\r
     return FALSE;\r
   }\r
 \r