]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
clean up the un-suitable ';' location when declaring the functions.
[mirror_edk2.git] / MdeModulePkg / Bus / Scsi / ScsiBusDxe / ScsiBus.c
index 1b895cb427d60510acfb5588d67c5b15786ce383..f59116733e9fe1151a24724981260c80fea83b2a 100644 (file)
@@ -1,6 +1,8 @@
-/*++\r
+/** @file\r
+  SCSI Bus driver that layers on every SCSI Pass Thru and\r
+  Extended SCSI Pass Thru protocol in the system.\r
 \r
-Copyright (c) 2006, Intel Corporation\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
@@ -9,18 +11,10 @@ http://opensource.org/licenses/bsd-license.php
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-Module Name:\r
-\r
-    scsibus.c\r
-\r
-Abstract:\r
-\r
-\r
-Revision History\r
---*/\r
+**/\r
 \r
 \r
-#include <PiDxe.h>\r
+#include <Uefi.h>\r
 \r
 \r
 #include <Protocol/ScsiPassThru.h>\r
@@ -66,8 +60,7 @@ EFIAPI
 ScsiioToPassThruPacket (\r
   IN      EFI_SCSI_IO_SCSI_REQUEST_PACKET         *Packet,\r
   IN OUT  EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET  *CommandPacket\r
-  )\r
-;\r
+  );\r
 \r
 \r
 STATIC\r
@@ -76,16 +69,14 @@ EFIAPI
 PassThruToScsiioPacket (\r
   IN     EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET  *ScsiPacket,\r
   IN OUT EFI_SCSI_IO_SCSI_REQUEST_PACKET         *Packet\r
-  )\r
-;\r
+  );\r
 STATIC\r
 VOID\r
 EFIAPI\r
 NotifyFunction (\r
   EFI_EVENT  Event,\r
   VOID       *Context\r
-  )\r
-;\r
+  );\r
 \r
 /**\r
   The user Entry Point for module ScsiBus. The user code starts with this function.\r
@@ -109,18 +100,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 +220,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 +378,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 +422,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 +467,23 @@ SCSIBusDriverBindingStop (
   )\r
 /*++\r
 \r
-  Routine Description:\r
+Routine Description:\r
+\r
+  Stop this driver on ControllerHandle. Support stoping any child handles\r
+  created by this driver.\r
+\r
+Arguments:\r
 \r
-  Arguments:\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
+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
@@ -547,7 +603,7 @@ SCSIBusDriverBindingStop (
         gBS->OpenProtocol (\r
                Controller,\r
                &gEfiExtScsiPassThruProtocolGuid,\r
-               (VOID **) &(EFI_EXT_SCSI_PASS_THRU_PROTOCOL*)ScsiPassThru,\r
+               &ScsiPassThru,\r
                This->DriverBindingHandle,\r
                ChildHandleBuffer[Index],\r
                EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
@@ -556,7 +612,7 @@ SCSIBusDriverBindingStop (
         gBS->OpenProtocol (\r
                Controller,\r
                &gEfiScsiPassThruProtocolGuid,\r
-               (VOID **) &(EFI_SCSI_PASS_THRU_PROTOCOL*)ScsiPassThru,\r
+               &ScsiPassThru,\r
                This->DriverBindingHandle,\r
                ChildHandleBuffer[Index],\r
                EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
@@ -582,17 +638,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 +674,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 +700,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 +716,22 @@ ScsiResetBus (
   )\r
 /*++\r
 \r
-  Routine Description:\r
-    Resets the SCSI Bus that the SCSI Controller is attached to.\r
+Routine Description:\r
+\r
+  Resets the SCSI Bus that the SCSI Controller is attached to.\r
+    \r
+Arguments:\r
+\r
+  This                  - Protocol instance pointer.\r
 \r
-  Arguments:\r
-    This                  - Protocol instance pointer.\r
+Returns:\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
+  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 +752,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 +802,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
@@ -1075,7 +1148,7 @@ Returns:
   InquiryDataLength = sizeof (EFI_SCSI_INQUIRY_DATA);\r
   SenseDataLength   = sizeof (EFI_SCSI_SENSE_DATA);\r
 \r
-  Status = SubmitInquiryCommand (\r
+  Status = ScsiInquiryCommand (\r
             &ScsiIoDevice->ScsiIo,\r
             EfiScsiStallSeconds (1),\r
             (VOID *) &SenseData,\r
@@ -1106,7 +1179,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