]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
Clean up the private GUID definition in module Level.
[mirror_edk2.git] / MdeModulePkg / Bus / Scsi / ScsiBusDxe / ScsiBus.c
index 2325b645ed5e6fa3e8936a1ff0594c3f1704f9a4..b1c4d207f9de8bf415b3b7a157906391dcba334e 100644 (file)
@@ -2,8 +2,8 @@
   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 - 2008, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+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
 http://opensource.org/licenses/bsd-license.php\r
@@ -26,14 +26,6 @@ EFI_DRIVER_BINDING_PROTOCOL gSCSIBusDriverBinding = {
   NULL\r
 };\r
 \r
-\r
-//\r
-// The ScsiBusProtocol is just used to locate ScsiBusDev\r
-// structure in the SCSIBusDriverBindingStop(). Then we can\r
-// Close all opened protocols and release this structure.\r
-//\r
-EFI_GUID  mScsiBusProtocolGuid = EFI_SCSI_BUS_PROTOCOL_GUID;\r
-\r
 VOID  *mWorkingBuffer;\r
 \r
 /**\r
@@ -142,11 +134,20 @@ SCSIBusDriverBindingSupported (
   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-  EFI_SCSI_PASS_THRU_PROTOCOL *PassThru;\r
+  EFI_STATUS                      Status;\r
+  EFI_SCSI_PASS_THRU_PROTOCOL     *PassThru;\r
   EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtPassThru;\r
+  UINT64                          Lun;\r
+  UINT8                           *TargetId;\r
+  SCSI_TARGET_ID                  ScsiTargetId;\r
+\r
+  TargetId = &ScsiTargetId.ScsiId.ExtScsi[0];\r
+  SetMem (TargetId, TARGET_MAX_BYTES, 0xFF);\r
+\r
   //\r
-  // Check for the existence of Extended SCSI Pass Thru Protocol and 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
@@ -159,43 +160,78 @@ SCSIBusDriverBindingSupported (
 \r
   if (Status == EFI_ALREADY_STARTED) {\r
     return EFI_SUCCESS;\r
-  }\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    Status = gBS->OpenProtocol (\r
-                    Controller,\r
-                    &gEfiScsiPassThruProtocolGuid,\r
-                    (VOID **)&PassThru,\r
-                    This->DriverBindingHandle,\r
-                    Controller,\r
-                    EFI_OPEN_PROTOCOL_BY_DRIVER\r
-                    );\r
-\r
-    if (Status == EFI_ALREADY_STARTED) {\r
+  } else if (!EFI_ERROR(Status)) {\r
+    //\r
+    // Check if RemainingDevicePath is NULL or the End of Device Path Node,\r
+    // if yes, return EFI_SUCCESS.\r
+    //\r
+    if ((RemainingDevicePath == NULL) || IsDevicePathEnd (RemainingDevicePath)) {\r
+      //\r
+      // Close protocol regardless of RemainingDevicePath validation\r
+      //\r
+      gBS->CloseProtocol (\r
+             Controller,\r
+             &gEfiExtScsiPassThruProtocolGuid,\r
+             This->DriverBindingHandle,\r
+             Controller\r
+             );      \r
       return EFI_SUCCESS;\r
+    } else {\r
+      //\r
+      // If RemainingDevicePath isn't the End of Device Path Node, check its validation\r
+      //\r
+      Status = ExtPassThru->GetTargetLun (ExtPassThru, RemainingDevicePath, &TargetId, &Lun);\r
+      //\r
+      // Close protocol regardless of RemainingDevicePath validation\r
+      //\r
+      gBS->CloseProtocol (\r
+             Controller,\r
+             &gEfiExtScsiPassThruProtocolGuid,\r
+             This->DriverBindingHandle,\r
+             Controller\r
+             );      \r
+      if (!EFI_ERROR(Status)) {\r
+        return EFI_SUCCESS;\r
+      }\r
     }\r
+  }\r
 \r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
-\r
-    gBS->CloseProtocol (\r
-      Controller,\r
-      &gEfiScsiPassThruProtocolGuid,\r
-      This->DriverBindingHandle,\r
-      Controller\r
-      );\r
+  //\r
+  // Come here in 2 condition: \r
+  // 1. ExtPassThru doesn't exist.\r
+  // 2. ExtPassThru exists but RemainingDevicePath is invalid.\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiScsiPassThruProtocolGuid,\r
+                  (VOID **)&PassThru,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  \r
+  if (Status == EFI_ALREADY_STARTED) {\r
     return EFI_SUCCESS;\r
   }\r
-\r
+  \r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
+  //\r
+  // Test RemainingDevicePath is valid or not.\r
+  //\r
+  if ((RemainingDevicePath != NULL) && !IsDevicePathEnd (RemainingDevicePath)) {\r
+    Status = PassThru->GetTargetLun (PassThru, RemainingDevicePath, &ScsiTargetId.ScsiId.Scsi, &Lun);\r
+  }\r
+  \r
   gBS->CloseProtocol (\r
-    Controller,\r
-    &gEfiExtScsiPassThruProtocolGuid,\r
-    This->DriverBindingHandle,\r
-    Controller\r
-    );\r
-\r
-  return EFI_SUCCESS;\r
+         Controller,\r
+         &gEfiScsiPassThruProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+  return Status;\r
 }\r
 \r
 \r
@@ -235,25 +271,20 @@ SCSIBusDriverBindingStart (
   EFI_STATUS                            DevicePathStatus;\r
   EFI_STATUS                            PassThruStatus;\r
   SCSI_BUS_DEVICE                       *ScsiBusDev;\r
-  SCSI_TARGET_ID                        *ScsiTargetId;\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
   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
+  TargetId = &ScsiTargetId.ScsiId.ExtScsi[0];\r
+  SetMem (TargetId, TARGET_MAX_BYTES, 0xFF);\r
   \r
   DevicePathStatus = gBS->OpenProtocol (\r
                             Controller,\r
@@ -350,7 +381,7 @@ SCSIBusDriverBindingStart (
     // \r
     Status = gBS->InstallProtocolInterface (\r
                     &Controller,\r
-                    &mScsiBusProtocolGuid,\r
+                    &gEfiCallerIdGuid,\r
                     EFI_NATIVE_INTERFACE,\r
                     &ScsiBusDev->BusIdentify\r
                     );\r
@@ -364,7 +395,7 @@ SCSIBusDriverBindingStart (
     //\r
     Status = gBS->OpenProtocol (\r
                     Controller,\r
-                    &mScsiBusProtocolGuid,\r
+                    &gEfiCallerIdGuid,\r
                     (VOID **) &BusIdentify,\r
                     This->DriverBindingHandle,\r
                     Controller,\r
@@ -377,16 +408,33 @@ SCSIBusDriverBindingStart (
     ScsiBusDev = SCSI_BUS_CONTROLLER_DEVICE_FROM_THIS (BusIdentify);\r
   }\r
 \r
+  Lun  = 0;\r
   if (RemainingDevicePath == NULL) {\r
-    SetMem (ScsiTargetId, TARGET_MAX_BYTES,0xFF);\r
-    Lun  = 0;\r
+    //\r
+    // If RemainingDevicePath is NULL, \r
+    // must enumerate all SCSI devices anyway\r
+    //\r
     FromFirstTarget = TRUE;\r
-  } else {\r
+  } else if (!IsDevicePathEnd (RemainingDevicePath)) {\r
+    //\r
+    // If RemainingDevicePath isn't the End of Device Path Node, \r
+    // only scan the specified device by RemainingDevicePath\r
+    //\r
     if (ScsiBusDev->ExtScsiSupport) {\r
-      ScsiBusDev->ExtScsiInterface->GetTargetLun (ScsiBusDev->ExtScsiInterface, RemainingDevicePath, &TargetId, &Lun);  \r
+      Status = ScsiBusDev->ExtScsiInterface->GetTargetLun (ScsiBusDev->ExtScsiInterface, RemainingDevicePath, &TargetId, &Lun);  \r
     } else {\r
-      ScsiBusDev->ScsiInterface->GetTargetLun (ScsiBusDev->ScsiInterface, RemainingDevicePath, &ScsiTargetId->ScsiId.Scsi, &Lun);\r
+      Status = ScsiBusDev->ScsiInterface->GetTargetLun (ScsiBusDev->ScsiInterface, RemainingDevicePath, &ScsiTargetId.ScsiId.Scsi, &Lun);\r
+    }\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
     }\r
+  } else {\r
+    //\r
+    // If RemainingDevicePath is the End of Device Path Node,\r
+    // skip enumerate any device and return EFI_SUCESSS\r
+    // \r
+    ScanOtherPuns = FALSE;\r
   }\r
 \r
   while(ScanOtherPuns) {\r
@@ -398,7 +446,7 @@ SCSIBusDriverBindingStart (
       if (ScsiBusDev->ExtScsiSupport) {\r
         Status = ScsiBusDev->ExtScsiInterface->GetNextTargetLun (ScsiBusDev->ExtScsiInterface, &TargetId, &Lun);\r
       } else {\r
-        Status = ScsiBusDev->ScsiInterface->GetNextDevice (ScsiBusDev->ScsiInterface, &ScsiTargetId->ScsiId.Scsi, &Lun);\r
+        Status = ScsiBusDev->ScsiInterface->GetNextDevice (ScsiBusDev->ScsiInterface, &ScsiTargetId.ScsiId.Scsi, &Lun);\r
       }\r
       if (EFI_ERROR (Status)) {\r
         //\r
@@ -413,11 +461,11 @@ SCSIBusDriverBindingStart (
     // Avoid creating handle for the host adapter.\r
     //\r
     if (ScsiBusDev->ExtScsiSupport) {\r
-      if ((ScsiTargetId->ScsiId.Scsi) == ScsiBusDev->ExtScsiInterface->Mode->AdapterId) {\r
+      if ((ScsiTargetId.ScsiId.Scsi) == ScsiBusDev->ExtScsiInterface->Mode->AdapterId) {\r
         continue;\r
       }\r
     } else {\r
-      if ((ScsiTargetId->ScsiId.Scsi) == ScsiBusDev->ScsiInterface->Mode->AdapterId) {\r
+      if ((ScsiTargetId.ScsiId.Scsi) == ScsiBusDev->ScsiInterface->Mode->AdapterId) {\r
         continue;\r
       }\r
     }\r
@@ -425,9 +473,8 @@ SCSIBusDriverBindingStart (
     // Scan for the scsi device, if it attaches to the scsi bus,\r
     // then create handle and install scsi i/o protocol.\r
     //\r
-    Status = ScsiScanCreateDevice (This, Controller, ScsiTargetId, Lun, ScsiBusDev);\r
+    Status = ScsiScanCreateDevice (This, Controller, &ScsiTargetId, Lun, ScsiBusDev);\r
   }\r
-  FreePool (ScsiTargetId);\r
   return EFI_SUCCESS;\r
 \r
 ErrorExit:\r
@@ -505,7 +552,7 @@ SCSIBusDriverBindingStop (
     //\r
     Status = gBS->OpenProtocol (\r
                     Controller,\r
-                    &mScsiBusProtocolGuid,\r
+                    &gEfiCallerIdGuid,\r
                     (VOID **) &Scsidentifier,\r
                     This->DriverBindingHandle,\r
                     Controller,\r
@@ -523,7 +570,7 @@ SCSIBusDriverBindingStop (
     //\r
     gBS->UninstallProtocolInterface (\r
            Controller,\r
-           &mScsiBusProtocolGuid,\r
+           &gEfiCallerIdGuid,\r
            &ScsiBusDev->BusIdentify\r
            );\r
 \r
@@ -971,10 +1018,63 @@ ScsiScanCreateDevice (
   EFI_STATUS                Status;\r
   SCSI_IO_DEV               *ScsiIoDevice;\r
   EFI_DEVICE_PATH_PROTOCOL  *ScsiDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *RemainingDevicePath;\r
+  EFI_HANDLE                 DeviceHandle;\r
+\r
+  DevicePath          = NULL;\r
+  RemainingDevicePath = NULL;\r
+  ScsiDevicePath      = NULL;\r
+  ScsiIoDevice        = NULL;\r
+\r
+  //\r
+  // Build Device Path\r
+  //\r
+  if (ScsiBusDev->ExtScsiSupport){\r
+    Status = ScsiBusDev->ExtScsiInterface->BuildDevicePath (\r
+                                             ScsiBusDev->ExtScsiInterface,\r
+                                             &TargetId->ScsiId.ExtScsi[0],\r
+                                             Lun,\r
+                                             &ScsiDevicePath\r
+                                             );\r
+  } else {\r
+    Status = ScsiBusDev->ScsiInterface->BuildDevicePath (\r
+                                          ScsiBusDev->ScsiInterface,\r
+                                          TargetId->ScsiId.Scsi,\r
+                                          Lun,\r
+                                          &ScsiDevicePath\r
+                                          );\r
+  }\r
+\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  DevicePath = AppendDevicePathNode (\r
+                 ScsiBusDev->DevicePath,\r
+                 ScsiDevicePath\r
+                 );\r
+\r
+  if (DevicePath == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ErrorExit;\r
+  }\r
+\r
+  DeviceHandle = NULL;\r
+  RemainingDevicePath = DevicePath;\r
+  Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &DeviceHandle);\r
+  if (!EFI_ERROR (Status) && (DeviceHandle != NULL) && IsDevicePathEnd(RemainingDevicePath)) {\r
+    //\r
+    // The device has been started, directly return to fast boot.\r
+    //\r
+    Status = EFI_ALREADY_STARTED;\r
+    goto ErrorExit;\r
+  }\r
 \r
   ScsiIoDevice = AllocateZeroPool (sizeof (SCSI_IO_DEV));\r
   if (ScsiIoDevice == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ErrorExit;\r
   }\r
 \r
   ScsiIoDevice->Signature                 = SCSI_IO_DEV_SIGNATURE;\r
@@ -998,52 +1098,12 @@ ScsiScanCreateDevice (
   ScsiIoDevice->ScsiIo.ResetDevice        = ScsiResetDevice;\r
   ScsiIoDevice->ScsiIo.ExecuteScsiCommand = ScsiExecuteSCSICommand;\r
 \r
-\r
   if (!DiscoverScsiDevice (ScsiIoDevice)) {\r
-    FreePool (ScsiIoDevice);\r
-    return EFI_OUT_OF_RESOURCES;\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ErrorExit;\r
   }\r
 \r
-  //\r
-  // Set Device Path\r
-  //\r
-  ScsiDevicePath = NULL;\r
-  if (ScsiIoDevice->ExtScsiSupport){\r
-    Status = ScsiIoDevice->ExtScsiPassThru->BuildDevicePath (\r
-                                          ScsiIoDevice->ExtScsiPassThru,\r
-                                          &ScsiIoDevice->Pun.ScsiId.ExtScsi[0],\r
-                                          ScsiIoDevice->Lun,\r
-                                          &ScsiDevicePath\r
-                                          );\r
-  } else {\r
-    Status = ScsiIoDevice->ScsiPassThru->BuildDevicePath (\r
-                                          ScsiIoDevice->ScsiPassThru,\r
-                                          ScsiIoDevice->Pun.ScsiId.Scsi,\r
-                                          ScsiIoDevice->Lun,\r
-                                          &ScsiDevicePath\r
-                                          );\r
-  }\r
-\r
-  if (EFI_ERROR(Status)) {\r
-    FreePool (ScsiIoDevice);\r
-    return Status;\r
-  }\r
-\r
-  ScsiIoDevice->DevicePath = AppendDevicePathNode (\r
-                              ScsiBusDev->DevicePath,\r
-                              ScsiDevicePath\r
-                              );\r
-  //\r
-  // The memory space for ScsiDevicePath is allocated in\r
-  // ScsiPassThru->BuildDevicePath() function; It is no longer used\r
-  // after EfiAppendDevicePathNode,so free the memory it occupies.\r
-  //\r
-  FreePool (ScsiDevicePath);\r
-\r
-  if (ScsiIoDevice->DevicePath == NULL) {\r
-    FreePool (ScsiIoDevice);\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
+  ScsiIoDevice->DevicePath = DevicePath;\r
 \r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &ScsiIoDevice->Handle,\r
@@ -1054,31 +1114,48 @@ ScsiScanCreateDevice (
                   NULL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    FreePool (ScsiIoDevice->DevicePath);\r
-    FreePool (ScsiIoDevice);\r
-    return EFI_OUT_OF_RESOURCES;\r
+    goto ErrorExit;\r
   } else {\r
     if (ScsiBusDev->ExtScsiSupport) {\r
       gBS->OpenProtocol (\r
-            Controller,\r
-            &gEfiExtScsiPassThruProtocolGuid,\r
-            (VOID **) &(ScsiBusDev->ExtScsiInterface),\r
-            This->DriverBindingHandle,\r
-            ScsiIoDevice->Handle,\r
-            EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
-            );\r
+             Controller,\r
+             &gEfiExtScsiPassThruProtocolGuid,\r
+             (VOID **) &(ScsiBusDev->ExtScsiInterface),\r
+             This->DriverBindingHandle,\r
+             ScsiIoDevice->Handle,\r
+             EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+             );\r
      } else {\r
       gBS->OpenProtocol (\r
-            Controller,\r
-            &gEfiScsiPassThruProtocolGuid,\r
-            (VOID **) &(ScsiBusDev->ScsiInterface),\r
-            This->DriverBindingHandle,\r
-            ScsiIoDevice->Handle,\r
-            EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
-            );\r
+             Controller,\r
+             &gEfiScsiPassThruProtocolGuid,\r
+             (VOID **) &(ScsiBusDev->ScsiInterface),\r
+             This->DriverBindingHandle,\r
+             ScsiIoDevice->Handle,\r
+             EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+             );\r
      }\r
   }\r
   return EFI_SUCCESS;\r
+\r
+ErrorExit:\r
+  \r
+  //\r
+  // The memory space for ScsiDevicePath is allocated in\r
+  // ScsiPassThru->BuildDevicePath() function; It is no longer used\r
+  // after AppendDevicePathNode,so free the memory it occupies.\r
+  //\r
+  FreePool (ScsiDevicePath);\r
+\r
+  if (DevicePath != NULL) {\r
+    FreePool (DevicePath);\r
+  }\r
+\r
+  if (ScsiIoDevice != NULL) {\r
+    FreePool (ScsiIoDevice);\r
+  }\r
+\r
+  return Status;\r
 }\r
 \r
 \r
@@ -1103,6 +1180,8 @@ DiscoverScsiDevice (
   UINT8                 TargetStatus;\r
   EFI_SCSI_SENSE_DATA   SenseData;\r
   EFI_SCSI_INQUIRY_DATA InquiryData;\r
+  UINT8                 MaxRetry;\r
+  UINT8                 Index;\r
 \r
   HostAdapterStatus = 0;\r
   TargetStatus      = 0;\r
@@ -1110,22 +1189,35 @@ DiscoverScsiDevice (
   // Using Inquiry command to scan for the device\r
   //\r
   InquiryDataLength = sizeof (EFI_SCSI_INQUIRY_DATA);\r
-  SenseDataLength   = sizeof (EFI_SCSI_SENSE_DATA);\r
-\r
-  Status = ScsiInquiryCommand (\r
-            &ScsiIoDevice->ScsiIo,\r
-            EFI_TIMER_PERIOD_SECONDS (1),\r
-            (VOID *) &SenseData,\r
-            &SenseDataLength,\r
-            &HostAdapterStatus,\r
-            &TargetStatus,\r
-            (VOID *) &InquiryData,\r
-            &InquiryDataLength,\r
-            FALSE\r
-            );\r
-  if (EFI_ERROR (Status) && Status != EFI_BAD_BUFFER_SIZE) {\r
+  SenseDataLength   = (UINT8) sizeof (EFI_SCSI_SENSE_DATA);\r
+  ZeroMem (&InquiryData, InquiryDataLength);\r
+\r
+  MaxRetry = 2;\r
+  for (Index = 0; Index < MaxRetry; Index++) {\r
+    Status = ScsiInquiryCommand (\r
+              &ScsiIoDevice->ScsiIo,\r
+              EFI_TIMER_PERIOD_SECONDS (1),\r
+              (VOID *) &SenseData,\r
+              &SenseDataLength,\r
+              &HostAdapterStatus,\r
+              &TargetStatus,\r
+              (VOID *) &InquiryData,\r
+              &InquiryDataLength,\r
+              FALSE\r
+              );\r
+    if (!EFI_ERROR (Status)) {\r
+      break;\r
+    } else if ((Status == EFI_BAD_BUFFER_SIZE) || \r
+               (Status == EFI_INVALID_PARAMETER) ||\r
+               (Status == EFI_UNSUPPORTED)) {\r
+      return FALSE;\r
+    }\r
+  }\r
+\r
+  if (Index == MaxRetry) {\r
     return FALSE;\r
   }\r
+  \r
   //\r
   // Retrieved inquiry data successfully\r
   //\r
@@ -1155,7 +1247,7 @@ DiscoverScsiDevice (
     //\r
     // ANSI-approved version\r
     //\r
-    ScsiIoDevice->ScsiVersion = (UINT8) (InquiryData.Version & 0x03);\r
+    ScsiIoDevice->ScsiVersion = (UINT8) (InquiryData.Version & 0x07);\r
   }\r
 \r
   return TRUE;\r