]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/UsbBus: reduce the port status polling before port reset
authorFeng Tian <feng.tian@intel.com>
Wed, 6 Jul 2016 02:18:37 +0000 (10:18 +0800)
committerFeng Tian <feng.tian@intel.com>
Mon, 25 Jul 2016 01:36:41 +0000 (09:36 +0800)
This change is used to remove the port status polling in port reset
functions.

Why it's needed is because:
1) The same polling on same port has taken place prior to this removed
one. See UsbEnumeratePort()->GetPortStatus(). So this polling in
UsbEnumerateNewDev()->ResetPort() is redundant.
2) EDKII Xhci driver hooks all GetPortStatus() operations. If we don't
remove this one, XHCI driver's XhcPollPortStatusChange() may enter twice
in reset process and wrongly think the device is unplugged.

Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.tian@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c

index 79453fed268f8e6b9dbe5fda926fedfd168df141..ea54d37c9350a292d8c866c5e101e804663681dd 100644 (file)
@@ -643,6 +643,7 @@ UsbFindChild (
 \r
   @param  HubIf                 The HUB that has the device connected.\r
   @param  Port                  The port index of the hub (started with zero).\r
+  @param  ResetIsNeeded         The boolean to control whether skip the reset of the port.\r
 \r
   @retval EFI_SUCCESS           The device is enumerated (added or removed).\r
   @retval EFI_OUT_OF_RESOURCES  Failed to allocate resource for the device.\r
@@ -652,7 +653,8 @@ UsbFindChild (
 EFI_STATUS\r
 UsbEnumerateNewDev (\r
   IN USB_INTERFACE        *HubIf,\r
-  IN UINT8                Port\r
+  IN UINT8                Port,\r
+  IN BOOLEAN              ResetIsNeeded\r
   )\r
 {\r
   USB_BUS                 *Bus;\r
@@ -677,16 +679,18 @@ UsbEnumerateNewDev (
   // and the hub is a EHCI root hub, ResetPort will release\r
   // the device to its companion UHCI and return an error.\r
   //\r
-  Status = HubApi->ResetPort (HubIf, Port);\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to reset port %d - %r\n", Port, Status));\r
-\r
-    return Status;\r
+  if (ResetIsNeeded) {\r
+    Status = HubApi->ResetPort (HubIf, Port);\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to reset port %d - %r\n", Port, Status));\r
+  \r
+      return Status;\r
+    }\r
+    DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: hub port %d is reset\n", Port));\r
+  } else {\r
+    DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: hub port %d reset is skipped\n", Port));\r
   }\r
 \r
-  DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: hub port %d is reset\n", Port));\r
-\r
   Child = UsbCreateDevice (HubIf, Port);\r
 \r
   if (Child == NULL) {\r
@@ -964,7 +968,11 @@ UsbEnumeratePort (
     // Now, new device connected, enumerate and configure the device \r
     //\r
     DEBUG (( EFI_D_INFO, "UsbEnumeratePort: new device connected at port %d\n", Port));\r
-    Status = UsbEnumerateNewDev (HubIf, Port);\r
+    if (USB_BIT_IS_SET (PortState.PortChangeStatus, USB_PORT_STAT_C_RESET)) {\r
+      Status = UsbEnumerateNewDev (HubIf, Port, FALSE);\r
+    } else {\r
+      Status = UsbEnumerateNewDev (HubIf, Port, TRUE);\r
+    }\r
   \r
   } else {\r
     DEBUG (( EFI_D_INFO, "UsbEnumeratePort: device disconnected event on port %d\n", Port));\r
index e3752d1f83ef7fa1835bce82fa1845c911f5989d..f51a51f191ad1cf1536355899f4fb227be06da37 100644 (file)
@@ -2,7 +2,7 @@
 \r
     Unified interface for RootHub and Hub.\r
 \r
-Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR> \r
+Copyright (c) 2007 - 2016, 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
@@ -968,15 +968,6 @@ UsbHubResetPort (
   UINTN                   Index;\r
   EFI_STATUS              Status;\r
 \r
-  Status = UsbHubGetPortStatus (HubIf, Port, &PortState);\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  } else if (USB_BIT_IS_SET (PortState.PortChangeStatus, USB_PORT_STAT_C_RESET)) {\r
-    DEBUG (( EFI_D_INFO, "UsbHubResetPort: skip reset on hub %p port %d\n", HubIf, Port));\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
   Status  = UsbHubSetPortFeature (HubIf, Port, (EFI_USB_PORT_FEATURE) USB_HUB_PORT_RESET);\r
 \r
   if (EFI_ERROR (Status)) {\r
@@ -1282,15 +1273,6 @@ UsbRootHubResetPort (
   //\r
   Bus     = RootIf->Device->Bus;\r
 \r
-  Status = UsbHcGetRootHubPortStatus (Bus, Port, &PortState);\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  } else if (USB_BIT_IS_SET (PortState.PortChangeStatus, USB_PORT_STAT_C_RESET)) {\r
-    DEBUG (( EFI_D_INFO, "UsbRootHubResetPort: skip reset on root port %d\n", Port));\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
   Status  = UsbHcSetRootHubPortFeature (Bus, Port, EfiUsbPortReset);\r
 \r
   if (EFI_ERROR (Status)) {\r