]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
MdeModulePkg/UsbMass: Fix hot-plug USB CDROM can't be recognized
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMassStorageDxe / UsbMassBoot.c
index 96c3622821c754107db9c2c3fc170e08bf7d9e97..12e68d21497a4504ea37c5038600cc5df22cabb6 100644 (file)
@@ -2,7 +2,7 @@
   Implementation of the command set of USB Mass Storage Specification\r
   for Bootability, Revision 1.0.\r
 \r
-Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2018, 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
@@ -20,7 +20,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
   @param  UsbMass                The device whose sense data is requested.\r
 \r
-  @retval EFI_SUCCESS            The command is excuted successfully.\r
+  @retval EFI_SUCCESS            The command is executed successfully.\r
   @retval EFI_DEVICE_ERROR       Failed to request sense.\r
   @retval EFI_NO_RESPONSE        The device media doesn't response this request.\r
   @retval EFI_INVALID_PARAMETER  The command has some invalid parameters.\r
@@ -80,7 +80,14 @@ UsbBootRequestSense (
   switch (USB_BOOT_SENSE_KEY (SenseData.SenseKey)) {\r
 \r
   case USB_BOOT_SENSE_NO_SENSE:\r
-    Status = EFI_NO_RESPONSE;\r
+    if (SenseData.Asc == USB_BOOT_ASC_NO_ADDITIONAL_SENSE_INFORMATION) {\r
+      //\r
+      // It is not an error if a device does not have additional sense information\r
+      //\r
+      Status = EFI_SUCCESS;\r
+    } else {\r
+      Status = EFI_NO_RESPONSE;\r
+    }\r
     break;\r
 \r
   case USB_BOOT_SENSE_RECOVERED:\r
@@ -113,6 +120,12 @@ UsbBootRequestSense (
       Status = EFI_MEDIA_CHANGED;\r
       Media->ReadOnly = FALSE;\r
       Media->MediaId++;\r
+    } else if (SenseData.Asc == USB_BOOT_ASC_NOT_READY) {\r
+      Status = EFI_NOT_READY;\r
+    } else if (SenseData.Asc == USB_BOOT_ASC_NO_MEDIA) {\r
+      Status = EFI_NOT_READY;\r
+    } else if (SenseData.Asc == USB_BOOT_ASC_POWER_ON) {\r
+      Status = EFI_SUCCESS;\r
     }\r
     break;\r
 \r
@@ -152,7 +165,7 @@ UsbBootRequestSense (
   @param  DataLen                The length of expected data\r
   @param  Timeout                The timeout used to transfer\r
 \r
-  @retval EFI_SUCCESS            Command is excuted successfully\r
+  @retval EFI_SUCCESS            Command is executed successfully\r
   @retval Others                 Command execution failed.\r
 \r
 **/\r
@@ -189,11 +202,6 @@ UsbBootExecCmd (
     return EFI_TIMEOUT;\r
   }\r
 \r
-  if (Status == EFI_DEVICE_ERROR) {\r
-    DEBUG ((EFI_D_ERROR, "UsbBootExecCmd: Device Error to Exec 0x%x Cmd\n", *(UINT8 *)Cmd));\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-\r
   //\r
   // If ExecCommand() returns no error and CmdResult is success,\r
   // then the commnad transfer is successful.\r
@@ -276,7 +284,7 @@ UsbBootExecCmdWithRetry (
                DataLen,\r
                Timeout\r
                );\r
-    if (Status == EFI_SUCCESS || Status == EFI_MEDIA_CHANGED || Status == EFI_NO_MEDIA || Status == EFI_DEVICE_ERROR) {\r
+    if (Status == EFI_SUCCESS || Status == EFI_MEDIA_CHANGED || Status == EFI_NO_MEDIA) {\r
       break;\r
     }\r
     //\r
@@ -624,8 +632,10 @@ UsbBootGetParams (
 {\r
   EFI_BLOCK_IO_MEDIA          *Media;\r
   EFI_STATUS                  Status;\r
+  UINT8                       CmdSet;\r
 \r
   Media  = &(UsbMass->BlockIoMedia);\r
+  CmdSet = ((EFI_USB_INTERFACE_DESCRIPTOR *) (UsbMass->Context))->InterfaceSubClass;\r
 \r
   Status = UsbBootInquiry (UsbMass);\r
   if (EFI_ERROR (Status)) {\r
@@ -660,9 +670,18 @@ UsbBootGetParams (
     Media->BlockSize        = 0x0800;\r
   }\r
 \r
-  Status = UsbBootDetectMedia (UsbMass);\r
+  if ((UsbMass->Pdt != USB_PDT_CDROM) && (CmdSet == USB_MASS_STORE_SCSI)) {\r
+    //\r
+    // ModeSense is required for the device with PDT of 0x00/0x07/0x0E,\r
+    // which is from [MassStorageBootabilitySpec-Page7].\r
+    // ModeSense(10) is useless here, while ModeSense(6) defined in SCSI\r
+    // could get the information of WriteProtected.\r
+    // Since not all device support this command, so skip if fail.\r
+    //\r
+    UsbScsiModeSense (UsbMass);\r
+  }\r
 \r
-  return Status;\r
+  return UsbBootReadCapacity (UsbMass);\r
 }\r
 \r
 \r
@@ -693,7 +712,7 @@ UsbBootDetectMedia (
   CmdSet = ((EFI_USB_INTERFACE_DESCRIPTOR *) (UsbMass->Context))->InterfaceSubClass;\r
 \r
   Status = UsbBootIsUnitReady (UsbMass);\r
-  if (EFI_ERROR (Status) && (Status != EFI_MEDIA_CHANGED)) {\r
+  if (EFI_ERROR (Status)) {\r
     goto ON_ERROR;\r
   }\r
 \r