]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
MdeModulePkg/ScsiBusDxe: remove redundant "else" after "break" statement
[mirror_edk2.git] / MdeModulePkg / Bus / Scsi / ScsiBusDxe / ScsiBus.c
index b1c4d207f9de8bf415b3b7a157906391dcba334e..1068770cd87f02903ca28e31b4ae94da09487fcc 100644 (file)
@@ -2,7 +2,7 @@
   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 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, 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
@@ -71,6 +71,49 @@ NotifyFunction (
   IN  VOID       *Context\r
   );\r
 \r
+/**\r
+  Allocates an aligned buffer for SCSI device.\r
+\r
+  This function allocates an aligned buffer for the SCSI device to perform\r
+  SCSI pass through operations. The alignment requirement is from SCSI pass\r
+  through interface.\r
+\r
+  @param  ScsiIoDevice      The SCSI child device involved for the operation.\r
+  @param  BufferSize        The request buffer size.\r
+\r
+  @return A pointer to the aligned buffer or NULL if the allocation fails.\r
+\r
+**/\r
+VOID *\r
+AllocateAlignedBuffer (\r
+  IN SCSI_IO_DEV              *ScsiIoDevice,\r
+  IN UINTN                    BufferSize\r
+  )\r
+{\r
+  return AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), ScsiIoDevice->ScsiIo.IoAlign);\r
+}\r
+\r
+/**\r
+  Frees an aligned buffer for SCSI device.\r
+\r
+  This function frees an aligned buffer for the SCSI device to perform\r
+  SCSI pass through operations.\r
+\r
+  @param  Buffer            The aligned buffer to be freed.\r
+  @param  BufferSize        The request buffer size.\r
+\r
+**/\r
+VOID\r
+FreeAlignedBuffer (\r
+  IN VOID                     *Buffer,\r
+  IN UINTN                    BufferSize\r
+  )\r
+{\r
+  if (Buffer != NULL) {\r
+    FreeAlignedPages (Buffer, EFI_SIZE_TO_PAGES (BufferSize));\r
+  }\r
+}\r
+\r
 /**\r
   The user Entry Point for module ScsiBus. The user code starts with this function.\r
 \r
@@ -298,6 +341,15 @@ SCSIBusDriverBindingStart (
     return DevicePathStatus;\r
   }\r
 \r
+  //\r
+  // Report Status Code to indicate SCSI bus starts\r
+  //\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_IO_BUS_SCSI | EFI_IOB_PC_INIT),\r
+    ParentDevicePath\r
+    );  \r
+\r
   //\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
@@ -408,6 +460,15 @@ SCSIBusDriverBindingStart (
     ScsiBusDev = SCSI_BUS_CONTROLLER_DEVICE_FROM_THIS (BusIdentify);\r
   }\r
 \r
+  //\r
+  // Report Status Code to indicate detecting devices on bus\r
+  //\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_IO_BUS_SCSI | EFI_IOB_PC_DETECT),\r
+    ParentDevicePath\r
+    );\r
+\r
   Lun  = 0;\r
   if (RemainingDevicePath == NULL) {\r
     //\r
@@ -785,6 +846,15 @@ ScsiResetBus (
 \r
   ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This);\r
 \r
+  //\r
+  // Report Status Code to indicate reset happens\r
+  //\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_PC_RESET),\r
+    ScsiIoDevice->ScsiBusDeviceData->DevicePath\r
+    );\r
+\r
   if (ScsiIoDevice->ExtScsiSupport){\r
     return ScsiIoDevice->ExtScsiPassThru->ResetChannel (ScsiIoDevice->ExtScsiPassThru);\r
   } else {\r
@@ -814,6 +884,16 @@ ScsiResetDevice (
   UINT8        Target[TARGET_MAX_BYTES];\r
 \r
   ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This);\r
+\r
+  //\r
+  // Report Status Code to indicate reset happens\r
+  //\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_PC_RESET),\r
+    ScsiIoDevice->ScsiBusDeviceData->DevicePath\r
+    );\r
+  \r
   CopyMem (Target,&ScsiIoDevice->Pun, TARGET_MAX_BYTES);\r
 \r
 \r
@@ -906,13 +986,35 @@ ScsiExecuteSCSICommand (
 \r
   if (ScsiIoDevice->ExtScsiSupport) {\r
     ExtRequestPacket = (EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *) Packet;\r
-    Status = ScsiIoDevice->ExtScsiPassThru->PassThru (\r
-                                          ScsiIoDevice->ExtScsiPassThru,\r
-                                          Target,\r
-                                          ScsiIoDevice->Lun,\r
-                                          ExtRequestPacket,\r
-                                          Event\r
-                                          );\r
+\r
+    if (((ScsiIoDevice->ExtScsiPassThru->Mode->Attributes & EFI_SCSI_PASS_THRU_ATTRIBUTES_NONBLOCKIO) != 0) && (Event !=  NULL)) {\r
+      Status = ScsiIoDevice->ExtScsiPassThru->PassThru (\r
+                                                ScsiIoDevice->ExtScsiPassThru,\r
+                                                Target,\r
+                                                ScsiIoDevice->Lun,\r
+                                                ExtRequestPacket,\r
+                                                Event\r
+                                                );\r
+    } else {\r
+      //\r
+      // If there's no event or the SCSI Device doesn't support NON-BLOCKING,\r
+      // let the 'Event' parameter for PassThru() be NULL.\r
+      //\r
+      Status = ScsiIoDevice->ExtScsiPassThru->PassThru (\r
+                                                ScsiIoDevice->ExtScsiPassThru,\r
+                                                Target,\r
+                                                ScsiIoDevice->Lun,\r
+                                                ExtRequestPacket,\r
+                                                NULL\r
+                                                );\r
+      if ((!EFI_ERROR(Status)) && (Event != NULL)) {\r
+        //\r
+        // Signal Event to tell caller to pick up the SCSI IO packet if the\r
+        // PassThru() succeeds.\r
+        //\r
+        gBS->SignalEvent (Event);\r
+      }\r
+    }\r
   } else {\r
 \r
     mWorkingBuffer = AllocatePool (sizeof(EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET));\r
@@ -938,7 +1040,7 @@ ScsiExecuteSCSICommand (
       //\r
       Status = gBS->CreateEvent (\r
                        EVT_NOTIFY_SIGNAL,\r
-                       TPL_CALLBACK,\r
+                       TPL_NOTIFY,\r
                        NotifyFunction,\r
                        &EventData,\r
                        &PacketEvent\r
@@ -972,7 +1074,7 @@ ScsiExecuteSCSICommand (
                                           ScsiIoDevice->Pun.ScsiId.Scsi,\r
                                           ScsiIoDevice->Lun,\r
                                           mWorkingBuffer,\r
-                                          Event\r
+                                          NULL\r
                                           );\r
       if (EFI_ERROR(Status)) {\r
         FreePool(mWorkingBuffer);\r
@@ -985,6 +1087,13 @@ ScsiExecuteSCSICommand (
       // free mWorkingBuffer.\r
       //\r
       FreePool(mWorkingBuffer);\r
+\r
+      //\r
+      // Signal Event to tell caller to pick up the SCSI IO Packet.\r
+      //\r
+      if (Event != NULL) {\r
+        gBS->SignalEvent (Event);\r
+      }\r
     }\r
   }\r
   return Status;\r
@@ -1078,6 +1187,7 @@ ScsiScanCreateDevice (
   }\r
 \r
   ScsiIoDevice->Signature                 = SCSI_IO_DEV_SIGNATURE;\r
+  ScsiIoDevice->ScsiBusDeviceData         = ScsiBusDev;\r
   CopyMem(&ScsiIoDevice->Pun, TargetId, TARGET_MAX_BYTES);\r
   ScsiIoDevice->Lun                       = Lun;\r
 \r
@@ -1098,6 +1208,15 @@ ScsiScanCreateDevice (
   ScsiIoDevice->ScsiIo.ResetDevice        = ScsiResetDevice;\r
   ScsiIoDevice->ScsiIo.ExecuteScsiCommand = ScsiExecuteSCSICommand;\r
 \r
+  //\r
+  // Report Status Code here since the new SCSI device will be discovered\r
+  //\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_IO_BUS_SCSI | EFI_IOB_PC_ENABLE),\r
+    ScsiBusDev->DevicePath\r
+    );\r
+\r
   if (!DiscoverScsiDevice (ScsiIoDevice)) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto ErrorExit;\r
@@ -1178,79 +1297,89 @@ DiscoverScsiDevice (
   UINT8                 SenseDataLength;\r
   UINT8                 HostAdapterStatus;\r
   UINT8                 TargetStatus;\r
-  EFI_SCSI_SENSE_DATA   SenseData;\r
-  EFI_SCSI_INQUIRY_DATA InquiryData;\r
+  EFI_SCSI_INQUIRY_DATA *InquiryData;\r
   UINT8                 MaxRetry;\r
   UINT8                 Index;\r
+  BOOLEAN               ScsiDeviceFound;\r
 \r
   HostAdapterStatus = 0;\r
   TargetStatus      = 0;\r
+\r
+  InquiryData = AllocateAlignedBuffer (ScsiIoDevice, sizeof (EFI_SCSI_INQUIRY_DATA));\r
+  if (InquiryData == NULL) {\r
+    ScsiDeviceFound = FALSE;\r
+    goto Done;\r
+  }\r
+\r
   //\r
   // Using Inquiry command to scan for the device\r
   //\r
   InquiryDataLength = sizeof (EFI_SCSI_INQUIRY_DATA);\r
-  SenseDataLength   = (UINT8) sizeof (EFI_SCSI_SENSE_DATA);\r
-  ZeroMem (&InquiryData, InquiryDataLength);\r
+  SenseDataLength   = 0;\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
+              SCSI_BUS_TIMEOUT,\r
+              NULL,\r
               &SenseDataLength,\r
               &HostAdapterStatus,\r
               &TargetStatus,\r
-              (VOID *) &InquiryData,\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
+    if ((Status == EFI_BAD_BUFFER_SIZE) ||\r
+        (Status == EFI_INVALID_PARAMETER) ||\r
+        (Status == EFI_UNSUPPORTED)) {\r
+      ScsiDeviceFound = FALSE;\r
+      goto Done;\r
     }\r
   }\r
 \r
   if (Index == MaxRetry) {\r
-    return FALSE;\r
+    ScsiDeviceFound = FALSE;\r
+    goto Done;\r
   }\r
   \r
   //\r
   // Retrieved inquiry data successfully\r
   //\r
-  if ((InquiryData.Peripheral_Qualifier != 0) &&\r
-      (InquiryData.Peripheral_Qualifier != 3)) {\r
-    return FALSE;\r
+  if (InquiryData->Peripheral_Qualifier != 0) {\r
+    ScsiDeviceFound = FALSE;\r
+    goto Done;\r
   }\r
 \r
-  if (InquiryData.Peripheral_Qualifier == 3) {\r
-    if (InquiryData.Peripheral_Type != 0x1f) {\r
-      return FALSE;\r
-    }\r
-  }\r
-\r
-  if (0x1e >= InquiryData.Peripheral_Type && InquiryData.Peripheral_Type >= 0xa) {\r
-    return FALSE;\r
+  if (0x1e >= InquiryData->Peripheral_Type && InquiryData->Peripheral_Type >= 0xa) {\r
+    ScsiDeviceFound = FALSE;\r
+    goto Done;\r
   }\r
 \r
   //\r
   // valid device type and peripheral qualifier combination.\r
   //\r
-  ScsiIoDevice->ScsiDeviceType  = InquiryData.Peripheral_Type;\r
-  ScsiIoDevice->RemovableDevice = InquiryData.Rmb;\r
-  if (InquiryData.Version == 0) {\r
+  ScsiIoDevice->ScsiDeviceType  = InquiryData->Peripheral_Type;\r
+  ScsiIoDevice->RemovableDevice = InquiryData->Rmb;\r
+  if (InquiryData->Version == 0) {\r
     ScsiIoDevice->ScsiVersion = 0;\r
   } else {\r
     //\r
     // ANSI-approved version\r
     //\r
-    ScsiIoDevice->ScsiVersion = (UINT8) (InquiryData.Version & 0x07);\r
+    ScsiIoDevice->ScsiVersion = (UINT8) (InquiryData->Version & 0x07);\r
   }\r
 \r
-  return TRUE;\r
+  ScsiDeviceFound = TRUE;\r
+\r
+Done:\r
+  FreeAlignedBuffer (InquiryData, sizeof (EFI_SCSI_INQUIRY_DATA));\r
+\r
+  return ScsiDeviceFound;\r
 }\r
 \r
 \r