From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web11.7948.1613571068317636537 for ; Wed, 17 Feb 2021 06:11:08 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WlIR7nyi; spf=pass (domain: redhat.com, ip: 63.128.21.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613571067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U4S1XLqpd8tQ3iJ6NNna7t0XAT2FXjMInzesBwgSvV0=; b=WlIR7nyirm9iNonQQ/cjQyMEBXtT8yDe8BdV+ob1P1VpDsAfiYr8vEqnqXhBlFAcRqRmZ3 S/pRKy2QaGWawS26G35gQn9SHv0kDVNaFicMmj3Db7Dq+KMUfBFGtOLUAq8yNWGEVizQMm JEIuj8AMnHbHGaKHfL8NqixzdfymJ0k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-390-jvbiK111PbyDK_m8S6ecSw-1; Wed, 17 Feb 2021 09:11:03 -0500 X-MC-Unique: jvbiK111PbyDK_m8S6ecSw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10904803F47; Wed, 17 Feb 2021 14:11:02 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-115-236.ams2.redhat.com [10.36.115.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF72B19C46; Wed, 17 Feb 2021 14:11:00 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/UfsPassThruDxe: Improve Error handling of Ufs Pass Thru driver To: Jian J Wang , Hao A Wu , Ray Ni References: <20210211125934.11024-1-purna.chandra.rao.bandaru@intel.com> Cc: devel@edk2.groups.io, purna.chandra.rao.bandaru@intel.com From: "Laszlo Ersek" Message-ID: <079e009e-5248-f852-45a5-b1a714dbf272@redhat.com> Date: Wed, 17 Feb 2021 15:10:59 +0100 MIME-Version: 1.0 In-Reply-To: <20210211125934.11024-1-purna.chandra.rao.bandaru@intel.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Jian, Hao, Ray -- any feedback on this? Thanks Laszlo On 02/11/21 13:59, Purna Chandra Rao Bandaru wrote: > From: Bandaru > > https://bugzilla.tianocore.org/show_bug.cgi?id=3217 > > Following is the brief description of the changes > 1) There are cards that can take upto 600ms for Init and hence increase > the time out for fDeviceInit polling loop. > 2) Add UFS host conctroller reset in the last retry of Link start up. > 3) Retry sending NOP OUT command upto 10 times > > Signed-off-by: Bandaru > > Change-Id: I6c0dbc1c147487e51f0ed5f2425957ae089b0160 > --- > MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c | 26 +++++++++++++++++++++----- > MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c | 18 ++++++++++++------ > 2 files changed, 33 insertions(+), 11 deletions(-) > > diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c > index 9768c2e6fb..89048745be 100644 > --- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c > +++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c > @@ -1,6 +1,6 @@ > /** @file > > - Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.
> + Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.
> Copyright (c) Microsoft Corporation.
> SPDX-License-Identifier: BSD-2-Clause-Patent > > @@ -749,7 +749,7 @@ UfsFinishDeviceInitialization ( > { > EFI_STATUS Status; > UINT8 DeviceInitStatus; > - UINT8 Timeout; > + UINT16 Timeout; > > DeviceInitStatus = 0xFF; > > @@ -761,17 +761,23 @@ UfsFinishDeviceInitialization ( > return Status; > } > > - Timeout = 5; > + Timeout = 6000; //There are cards that can take upto 600ms. > do { > + MicroSecondDelay (100); //Give 100 us and then start polling. > Status = UfsReadFlag (Private, UfsFlagDevInit, &DeviceInitStatus); > if (EFI_ERROR (Status)) { > return Status; > } > - MicroSecondDelay (1); > Timeout--; > } while (DeviceInitStatus != 0 && Timeout != 0); > > + if (Timeout == 0) { > + DEBUG ((DEBUG_ERROR, "UfsFinishDeviceInitialization DeviceInitStatus=%x EFI_TIMEOUT \n", DeviceInitStatus)); > + return EFI_TIMEOUT; > + } else { > + DEBUG ((DEBUG_INFO, "UfsFinishDeviceInitialization Timeout left=%x EFI_SUCCESS \n", Timeout)); > return EFI_SUCCESS; > + } > } > > /** > @@ -905,9 +911,19 @@ UfsPassThruDriverBindingStart ( > // At the end of the UFS Interconnect Layer initialization on both host and device side, > // the host shall send a NOP OUT UPIU to verify that the device UTP Layer is ready. > // > + for (Index = 10; Index > 0; Index--) { > Status = UfsExecNopCmds (Private); > if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, "Ufs Sending NOP IN command Error, Status = %r\n", Status)); > + DEBUG ((DEBUG_ERROR, "Ufs Sending NOP IN command Error, Index = %x Status = %r\n", Index, Status)); > + MicroSecondDelay (100); //100 us > + continue; > + } else { > + DEBUG ((DEBUG_INFO, "Ufs Sent NOP OUT successfully and received NOP IN, Status = %r\n", Status)); > + break; > + } > + } > + if (!Index) { > + DEBUG ((DEBUG_INFO, "NOP OUT failed all the 10 times Status = %r\n", Status)); > goto Error; > } > > diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c > index 0b1030ab47..4fa5689196 100644 > --- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c > +++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c > @@ -2,7 +2,7 @@ > UfsPassThruDxe driver is used to produce EFI_EXT_SCSI_PASS_THRU protocol interface > for upper layer application to execute UFS-supported SCSI cmds. > > - Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.
> + Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.
> Copyright (c) Microsoft Corporation.
> SPDX-License-Identifier: BSD-2-Clause-Patent > > @@ -1929,17 +1929,15 @@ UfsDeviceDetection ( > > // > // Start UFS device detection. > - // Try up to 3 times for establishing data link with device. > + // Try up to 4 times for establishing data link with device. > // > - for (Retry = 0; Retry < 3; Retry++) { > + for (Retry = 0; Retry < 4; Retry++) { > LinkStartupCommand.Opcode = UfsUicDmeLinkStartup; > LinkStartupCommand.Arg1 = 0; > LinkStartupCommand.Arg2 = 0; > LinkStartupCommand.Arg3 = 0; > Status = UfsExecUicCommands (Private, &LinkStartupCommand); > - if (EFI_ERROR (Status)) { > - return EFI_DEVICE_ERROR; > - } > + if (!EFI_ERROR (Status)) { > > Status = UfsMmioRead32 (Private, UFS_HC_STATUS_OFFSET, &Data); > if (EFI_ERROR (Status)) { > @@ -1960,6 +1958,14 @@ UfsDeviceDetection ( > } > } > return EFI_SUCCESS; > + } > + } > + if (Retry == 2) { > + Status = UfsEnableHostController (Private); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "UfsDeviceDetection: Enable Host Controller Fails, Status = %r\n", Status)); > + return Status; > + } > } > } > >