Fixed unexpected timeout in Usb MassStorage Driver.

Fixed unexpected timeout in Uhci/Ehci driver.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4038 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
yshang1
2007-10-08 06:14:13 +00:00
parent ba5711102a
commit 41e8ff2781
22 changed files with 386 additions and 262 deletions

View File

@@ -126,14 +126,14 @@ EhcReset (
// Host Controller must be Halt when Reset it
//
if (!EhcIsHalt (Ehc)) {
Status = EhcHaltHC (Ehc, EHC_GENERIC_TIME);
Status = EhcHaltHC (Ehc, EHC_GENERIC_TIMEOUT);
if (EFI_ERROR (Status)) {
Status = EFI_DEVICE_ERROR;
goto ON_EXIT;
}
}
//
// Clean up the asynchronous transfers, currently only
// interrupt supports asynchronous operation.
@@ -142,7 +142,7 @@ EhcReset (
EhcAckAllInterrupt (Ehc);
EhcFreeSched (Ehc);
Status = EhcResetHC (Ehc, EHC_STALL_1_SECOND);
Status = EhcResetHC (Ehc, EHC_RESET_TIMEOUT);
if (EFI_ERROR (Status)) {
goto ON_EXIT;
@@ -251,7 +251,7 @@ EhcSetState (
switch (State) {
case EfiUsbHcStateHalt:
Status = EhcHaltHC (Ehc, EHC_GENERIC_TIME);
Status = EhcHaltHC (Ehc, EHC_GENERIC_TIMEOUT);
break;
case EfiUsbHcStateOperational:
@@ -260,7 +260,17 @@ EhcSetState (
break;
}
Status = EhcRunHC (Ehc, EHC_GENERIC_TIME);
//
// Software must not write a one to this field unless the host controller
// is in the Halted state. Doing so will yield undefined results.
// refers to Spec[EHCI1.0-2.3.1]
//
if (!EHC_REG_BIT_IS_SET (Ehc, EHC_USBSTS_OFFSET, USBSTS_HALT)) {
Status = EFI_DEVICE_ERROR;
break;
}
Status = EhcRunHC (Ehc, EHC_GENERIC_TIMEOUT);
break;
case EfiUsbHcStateSuspend:
@@ -437,14 +447,14 @@ EhcSetRootHubPortFeature (
// Make sure Host Controller not halt before reset it
//
if (EhcIsHalt (Ehc)) {
Status = EhcRunHC (Ehc, EHC_GENERIC_TIME);
Status = EhcRunHC (Ehc, EHC_GENERIC_TIMEOUT);
if (EFI_ERROR (Status)) {
EHC_DEBUG (("EhcSetRootHubPortFeature :failed to start HC - %r\n", Status));
break;
}
}
//
// Set one to PortReset bit must also set zero to PortEnable bit
//
@@ -1539,7 +1549,7 @@ EhcDriverBindingStart (
// Robustnesss improvement such as for UoL
//
EhcClearLegacySupport (Ehc);
EhcResetHC (Ehc, EHC_STALL_1_SECOND);
EhcResetHC (Ehc, EHC_RESET_TIMEOUT);
Status = EhcInitHC (Ehc);
@@ -1551,12 +1561,12 @@ EhcDriverBindingStart (
//
// Start the asynchronous interrupt monitor
//
Status = gBS->SetTimer (Ehc->PollTimer, TimerPeriodic, EHC_ASYNC_POLL_TIME);
Status = gBS->SetTimer (Ehc->PollTimer, TimerPeriodic, EHC_ASYNC_POLL_INTERVAL);
if (EFI_ERROR (Status)) {
EHC_ERROR (("EhcDriverBindingStart: failed to start async interrupt monitor\n"));
EhcHaltHC (Ehc, EHC_GENERIC_TIME);
EhcHaltHC (Ehc, EHC_GENERIC_TIMEOUT);
goto UNINSTALL_USBHC;
}
@@ -1659,8 +1669,8 @@ EhcDriverBindingStop (
// Stop AsyncRequest Polling timer then stop the EHCI driver
// and uninstall the EHCI protocl.
//
gBS->SetTimer (Ehc->PollTimer, TimerCancel, EHC_ASYNC_POLL_TIME);
EhcHaltHC (Ehc, EHC_GENERIC_TIME);
gBS->SetTimer (Ehc->PollTimer, TimerCancel, EHC_ASYNC_POLL_INTERVAL);
EhcHaltHC (Ehc, EHC_GENERIC_TIMEOUT);
Status = gBS->UninstallProtocolInterface (
Controller,

View File

@@ -49,18 +49,35 @@ typedef struct _USB2_HC_DEV USB2_HC_DEV;
#include "EhciDebug.h"
enum {
USB2_HC_DEV_SIGNATURE = EFI_SIGNATURE_32 ('e', 'h', 'c', 'i'),
EHC_STALL_1_MICROSECOND = 1,
EHC_STALL_1_MILLISECOND = 1000 * EHC_STALL_1_MICROSECOND,
EHC_STALL_1_SECOND = 1000 * EHC_STALL_1_MILLISECOND,
EHC_1_MICROSECOND = 1,
EHC_1_MILLISECOND = 1000 * EHC_1_MICROSECOND,
EHC_1_SECOND = 1000 * EHC_1_MILLISECOND,
EHC_SET_PORT_RESET_TIME = 50 * EHC_STALL_1_MILLISECOND,
EHC_CLEAR_PORT_RESET_TIME = EHC_STALL_1_MILLISECOND,
EHC_GENERIC_TIME = 10 * EHC_STALL_1_MILLISECOND,
EHC_SYNC_POLL_TIME = 20 * EHC_STALL_1_MICROSECOND,
EHC_ASYNC_POLL_TIME = 50 * 10000UL, // The unit of time is 100us
//
// EHCI register operation timeout, set by experience
//
EHC_RESET_TIMEOUT = 1 * EHC_1_SECOND,
EHC_GENERIC_TIMEOUT = 10 * EHC_1_MILLISECOND,
EHC_TPL = TPL_NOTIFY
//
// Wait for roothub port power stable, refers to Spec[EHCI1.0-2.3.9]
//
EHC_ROOT_PORT_RECOVERY_STALL = 20 * EHC_1_MILLISECOND,
//
// Sync and Async transfer polling interval, set by experience,
// and the unit of Async is 100us, means 50ms as interval.
//
EHC_SYNC_POLL_INTERVAL = 20 * EHC_1_MICROSECOND,
EHC_ASYNC_POLL_INTERVAL = 50 * 10000U,
//
// EHC raises TPL to TPL_NOTIFY to serialize all its operations
// to protect shared data structures.
//
EHC_TPL = TPL_NOTIFY,
USB2_HC_DEV_SIGNATURE = EFI_SIGNATURE_32 ('e', 'h', 'c', 'i'),
};
//

View File

@@ -214,12 +214,12 @@ EhcWaitOpRegBit (
{
UINT32 Index;
for (Index = 0; Index < Timeout / EHC_SYNC_POLL_TIME + 1; Index++) {
for (Index = 0; Index < Timeout / EHC_SYNC_POLL_INTERVAL + 1; Index++) {
if (EHC_REG_BIT_IS_SET (Ehc, Offset, Bit) == WaitToSet) {
return EFI_SUCCESS;
}
gBS->Stall (EHC_SYNC_POLL_TIME);
gBS->Stall (EHC_SYNC_POLL_INTERVAL);
}
return EFI_TIMEOUT;
@@ -614,14 +614,19 @@ EhcInitHC (
//
EhcSetOpRegBit (Ehc, EHC_CONFIG_FLAG_OFFSET, CONFIGFLAG_ROUTE_EHC);
Status = EhcEnablePeriodSchd (Ehc, EHC_GENERIC_TIME);
//
// Wait roothub port power stable
//
gBS->Stall (EHC_ROOT_PORT_RECOVERY_STALL);
Status = EhcEnablePeriodSchd (Ehc, EHC_GENERIC_TIMEOUT);
if (EFI_ERROR (Status)) {
EHC_ERROR (("EhcInitHC: failed to enable period schedule\n"));
return Status;
}
Status = EhcEnableAsyncSchd (Ehc, EHC_GENERIC_TIME);
Status = EhcEnableAsyncSchd (Ehc, EHC_GENERIC_TIMEOUT);
if (EFI_ERROR (Status)) {
EHC_ERROR (("EhcInitHC: failed to enable async schedule\n"));

View File

@@ -342,7 +342,7 @@ EhcUnlinkQhFromAsync (
//
// Set and wait the door bell to synchronize with the hardware
//
Status = EhcSetAndWaitDoorBell (Ehc, EHC_GENERIC_TIME);
Status = EhcSetAndWaitDoorBell (Ehc, EHC_GENERIC_TIMEOUT);
if (EFI_ERROR (Status)) {
EHC_ERROR (("EhcUnlinkQhFromAsync: Failed to synchronize with doorbell\n"));
@@ -659,7 +659,7 @@ EhcExecTransfer (
BOOLEAN Finished;
Status = EFI_SUCCESS;
Loop = (TimeOut * EHC_STALL_1_MILLISECOND / EHC_SYNC_POLL_TIME) + 1;
Loop = (TimeOut * EHC_1_MILLISECOND / EHC_SYNC_POLL_INTERVAL) + 1;
Finished = FALSE;
for (Index = 0; Index < Loop; Index++) {
@@ -669,7 +669,7 @@ EhcExecTransfer (
break;
}
gBS->Stall (EHC_SYNC_POLL_TIME);
gBS->Stall (EHC_SYNC_POLL_INTERVAL);
}
if (!Finished) {