From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web12.9199.1604468018442720164 for ; Tue, 03 Nov 2020 21:33:39 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=VUsjkmwj; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: hao.a.wu@intel.com) IronPort-SDR: yIpYz/0g8Mil6dGOyJeapVSygzdAx9eJFWoteNVCdxNrZf4wRtS6dyInXoSzn5bIZxWprjKBeO bu5WNoKbbknA== X-IronPort-AV: E=McAfee;i="6000,8403,9794"; a="230793421" X-IronPort-AV: E=Sophos;i="5.77,450,1596524400"; d="scan'208";a="230793421" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 21:33:37 -0800 IronPort-SDR: mRGwKped8H/iiycywgpbVUB8n3Dm7TVQ49m+RU4lV9Qp6gfokm2bsBjA7YGF9Is5Fijql8rP1c Cg1d75jVT/DA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,450,1596524400"; d="scan'208";a="357922717" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by fmsmga002.fm.intel.com with ESMTP; 03 Nov 2020 21:33:36 -0800 Received: from orsmsx609.amr.corp.intel.com (10.22.229.22) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 3 Nov 2020 21:33:36 -0800 Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by ORSMSX609.amr.corp.intel.com (10.22.229.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 3 Nov 2020 21:33:35 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx612.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Tue, 3 Nov 2020 21:33:35 -0800 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.49) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Tue, 3 Nov 2020 21:33:35 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NpHxPmPpaag34oNkyoQW42eBAYLqLpHQS9bz1hAPBOzHXpeQ2AEjZJ8FSu2zU+31NG/yqkbEwxoob/Ls/XuVg6XloJjjsB7emV13aEkgziqzfIZqTR2IT6jQJdrPNB0Dynkn4AUc67xxKp44SXYFDIa8EKevZQgwyM4NZylMguh2cpZUnjbPPYxqIzA0muMqt3e77i3nCGjJSJP5uMcbF0ZBVaBR9hEIxcqBZZGJ3fZKzyQul3RJJDTUGxSLH678OV//iz/chQuHvOwwfhbKivt6BBWCqhMwWrFDeXXVkXyeeJN2R29Zs7CsgjQxcCWn6ASh5BXxdVDBon1bOiXxaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bxeho/J7oKcYqZCF30XdoK1iXbP0DE3+xfNQNsx96GI=; b=esQcmgghGHcBGjHED4IIayRWfrXJbTz4b4hztHKkW08vJZ8PJOPrn2s42zMbGEXDinkqzj50s5udm4ur5+Ard5dp5qKTfYDbLXSaTl99F666yYd+E1leTFlVzXuip+JME8aCftCNsTLGe3n6QEqluYIVFCpZ5TUb8jgbR+zT7X4qjLVF3NxzBtd9AE72HKRexJbbUIvP7XgMq/dV/12fAMbKwWg+/msTpebwc7Vk4Ti1UDeGMdspdTalNdbEc2kzribCMKsGYwcpS4lAyFnU2aLHaOfFx1+Lp7WEH2/wn9OUOnwzZbDcsMY9DhqDgsbfpMvgZQtPm0UEYzXAa1FOew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bxeho/J7oKcYqZCF30XdoK1iXbP0DE3+xfNQNsx96GI=; b=VUsjkmwjlFJ6wqUwfIHMpijYEasMWQYgpZxc0/jP6dUHzDjb2L37ZBtq4pCbnSUxt9eIPFODsdvjdWQVJ9XQ4w6NZZ8vadgOtwtzaFFPECWrYVi7QwR6ooG9yCLdP0awCC60YfVxHQ9FXR9sMUfQqpPSS4jqUlOFPJi5oOk8OBg= Received: from BN8PR11MB3666.namprd11.prod.outlook.com (2603:10b6:408:8c::19) by BN6PR11MB1379.namprd11.prod.outlook.com (2603:10b6:404:48::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.29; Wed, 4 Nov 2020 05:33:34 +0000 Received: from BN8PR11MB3666.namprd11.prod.outlook.com ([fe80::c123:faac:1da3:f807]) by BN8PR11MB3666.namprd11.prod.outlook.com ([fe80::c123:faac:1da3:f807%5]) with mapi id 15.20.3499.032; Wed, 4 Nov 2020 05:33:34 +0000 From: "Wu, Hao A" To: "Albecki, Mateusz" , "devel@edk2.groups.io" CC: "Ni, Ray" Subject: Re: [PATCH 3/4] MdeModulePkg/AtaAtapiPassThru: Restart failed packets Thread-Topic: [PATCH 3/4] MdeModulePkg/AtaAtapiPassThru: Restart failed packets Thread-Index: AQHWseShACyiNc8NskGonVb7hl9/0Km3UBaA Date: Wed, 4 Nov 2020 05:33:34 +0000 Message-ID: References: <20201103132348.2916-1-mateusz.albecki@intel.com> <20201103132348.2916-4-mateusz.albecki@intel.com> In-Reply-To: <20201103132348.2916-4-mateusz.albecki@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.218] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: aa97b327-1142-46e3-3cd2-08d880832c56 x-ms-traffictypediagnostic: BN6PR11MB1379: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3173; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: dH2usE+V2MdA4TLVsDLyzegxPLJKSpVwV67tTOQ7b+1sS3oEfWP3wQRPpBRmb+AWVOi2uC7F/eqYSqxwtpPK8IZzrRB57jnqh2KiFymA88XDJduwMJR4aU41UcfX5i611kgrgiWC7ZRc2rjug8zVeLbylQk7EvEcHFgmamOhyqxklzQqdZ2FDJcITWWea3pQaA2l4jgOxxbIR+dmTYRAHtrVGB5XjMdp3JBCTXLrUytExKrurbYzvFSRW19PksRT0lKCZz93ZkyOkFcYlgPtUtf7raKi0r2BQ0VIb+Z+Fq4A0md5zISMP1RQSLWklQECZTa8vEpDzRKqrz1YxbkP7rexadxbzdBoNVSp/Oy46HFSKTlC/I+wobIjUGcwnPQaoHDcr2nulGWqKfmVbtkjKg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR11MB3666.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(346002)(39860400002)(136003)(366004)(376002)(2906002)(4326008)(6506007)(30864003)(5660300002)(86362001)(9686003)(71200400001)(52536014)(55016002)(8936002)(7696005)(53546011)(107886003)(186003)(26005)(8676002)(76116006)(478600001)(83380400001)(316002)(33656002)(66556008)(66946007)(64756008)(66446008)(66476007)(110136005)(966005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: lnhAnuoeONZ9qlUIk5WoLzKJYfmpZOfTLi4JOUOk63VT4vRqaLi9oL/zK7FIiAIbTtepyvBGP2WhsxZ1f2SSOTu4FuSsQDqNO0P2RhY1fnFUmlwwaBl6k1WyRs+Lf1U3zLPlbRgENUKjv64au8Zyj4WJero8FbHnzyENSnrof1SVxJxTdcWq1xEYDNE1DgfBieKmCJoqk/4t2NkLew0UBobL8F4aDaOVJibnjFWm5vjtska4AwRyQ+4AkDM5IKmEVTdc5dNxUWncOE82xUYVVrHdKzbfmzFlVUHw/Ll5P4pfd7uH8HLEhGTabNQQITM5v7qm/Zx60gURalDxP1xlC5vzVRCUt82mCw36wNSVCqp5YBB0oAeJaGS9vGVZCG98upBlmRGJfK5MudbJISXT//WdjUVS++rLV+7PosWTGLWBAr+YeBCT42mrc7yEvgJasWJrGXJeBtWVQWfZ2WvOM7A0NNzuxjsQnhZ8kdxYaTlbHHsQg2M07kRCao/9ok4NdE2eNyal4UIqNMb+0yxVrMiFC+hK6GOqPYQRjP3ExeaUemn21YA+zQOC3XxJ5iG+GqYycKlOgD7IHc/GZ1RzTAnZUNEVexIwr7NfEDHVHJzVS84u/02UiO6dUqt6uPPpUlw3AcYmYas8kha+J/KYgw== MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN8PR11MB3666.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: aa97b327-1142-46e3-3cd2-08d880832c56 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Nov 2020 05:33:34.4506 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: X/XtnA2z9Y7boLEWO2Mjbpa6YU9+4bbJ5ygoV1G5M2mYNPfyGD+zT+HJ0eMyhxBWuBi/jvbsBtE8PPnNUNJ2TA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR11MB1379 Return-Path: hao.a.wu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: Albecki, Mateusz > Sent: Tuesday, November 3, 2020 9:24 PM > To: devel@edk2.groups.io > Cc: Albecki, Mateusz ; Ni, Ray > ; Wu, Hao A > Subject: [PATCH 3/4] MdeModulePkg/AtaAtapiPassThru: Restart failed > packets >=20 > From: Albecki >=20 > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3026 >=20 > This commit adds code to restart the ATA packets that failed due to the C= RC > error or other link condition. For sync transfers the code will try to ge= t the > command working for up to 5 times and for async in accordance to the > RetryTimes field in Task structure. For sync case the count of 5 retries = has For "... for async in accordance to the RetryTimes field in Task structure.= ", how about reword it to "for async transfers, the command retry will happen = until the timeout value specified by the requester is reached"? Judging from how the 'RetryTimes' field being assigned in AtaPassThruPassTh= ru(): Task->RetryTimes =3D DivU64x32(Packet->Timeout, 1000) + 1; I think it is relative to the timeout value for the PassThru packet. Best Regards, Hao Wu > been chosen arbitrarily and if needed can be increased or decreased. >=20 > Signed-off-by: Mateusz Albecki >=20 > Cc: Ray Ni > Cc: Hao A Wu >=20 > --- > .../Bus/Ata/AtaAtapiPassThru/AhciMode.c | 305 +++++++++++------- > .../Bus/Ata/AtaAtapiPassThru/AhciMode.h | 2 + > 2 files changed, 182 insertions(+), 125 deletions(-) >=20 > diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c > b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c > index cf735d5983..4fe7e4b1dc 100644 > --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c > +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c > @@ -897,6 +897,7 @@ AhciPioTransfer ( > EFI_AHCI_COMMAND_FIS CFis; > EFI_AHCI_COMMAND_LIST CmdList; > UINT32 PrdCount; > + UINT32 Retry; >=20 > if (Read) { > Flag =3D EfiPciIoOperationBusMasterWrite; @@ -931,49 +932,56 @@ > AhciPioTransfer ( > CmdList.AhciCmdCfl =3D EFI_AHCI_FIS_REGISTER_H2D_LENGTH / 4; > CmdList.AhciCmdW =3D Read ? 0 : 1; >=20 > - AhciBuildCommand ( > - PciIo, > - AhciRegisters, > - Port, > - PortMultiplier, > - &CFis, > - &CmdList, > - AtapiCommand, > - AtapiCommandLength, > - 0, > - (VOID *)(UINTN)PhyAddr, > - DataCount > - ); > + for (Retry =3D 0; Retry < AHCI_COMMAND_RETRIES; Retry++) { > + AhciBuildCommand ( > + PciIo, > + AhciRegisters, > + Port, > + PortMultiplier, > + &CFis, > + &CmdList, > + AtapiCommand, > + AtapiCommandLength, > + 0, > + (VOID *)(UINTN)PhyAddr, > + DataCount > + ); >=20 > - Status =3D AhciStartCommand ( > - PciIo, > - Port, > - 0, > - Timeout > - ); > - if (EFI_ERROR (Status)) { > - goto Exit; > - } > + Status =3D AhciStartCommand ( > + PciIo, > + Port, > + 0, > + Timeout > + ); > + if (EFI_ERROR (Status)) { > + break; > + } >=20 > - if (Read && (AtapiCommand =3D=3D 0)) { > - Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, SataFisPi= oSetup); > - if (Status =3D=3D EFI_SUCCESS) { > - PrdCount =3D *(volatile UINT32 *) (&(AhciRegisters- > >AhciCmdList[0].AhciCmdPrdbc)); > - if (PrdCount =3D=3D DataCount) { > - Status =3D EFI_SUCCESS; > - } else { > - Status =3D EFI_DEVICE_ERROR; > + if (Read && (AtapiCommand =3D=3D 0)) { > + Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, SataFis= PioSetup); > + if (Status =3D=3D EFI_SUCCESS) { > + PrdCount =3D *(volatile UINT32 *) (&(AhciRegisters- > >AhciCmdList[0].AhciCmdPrdbc)); > + if (PrdCount =3D=3D DataCount) { > + Status =3D EFI_SUCCESS; > + } else { > + Status =3D EFI_DEVICE_ERROR; > + } > } > + } else { > + Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, > + SataFisD2H); > } > - } else { > - Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, SataFisD2= H); > - } >=20 > - if (Status =3D=3D EFI_DEVICE_ERROR) { > - AhciRecoverPortError (PciIo, Port); > + if (Status =3D=3D EFI_DEVICE_ERROR) { > + DEBUG ((DEBUG_ERROR, "PIO command failed at retry %d\n", Retry)); > + Status =3D AhciRecoverPortError (PciIo, Port); > + if (EFI_ERROR (Status)) { > + break; > + } > + } else { > + break; > + } > } >=20 > -Exit: > AhciStopCommand ( > PciIo, > Port, > @@ -992,7 +1000,6 @@ Exit: > ); >=20 > AhciDumpPortStatus (PciIo, AhciRegisters, Port, AtaStatusBlock); > - > return Status; > } >=20 > @@ -1046,9 +1053,9 @@ AhciDmaTransfer ( > EFI_PCI_IO_PROTOCOL_OPERATION Flag; > EFI_AHCI_COMMAND_FIS CFis; > EFI_AHCI_COMMAND_LIST CmdList; > - > EFI_PCI_IO_PROTOCOL *PciIo; > EFI_TPL OldTpl; > + UINT32 Retry; >=20 > Map =3D NULL; > PciIo =3D Instance->PciIo; > @@ -1058,36 +1065,16 @@ AhciDmaTransfer ( > } >=20 > // > - // Before starting the Blocking BlockIO operation, push to finish all = non- > blocking > - // BlockIO tasks. > - // Delay 100us to simulate the blocking time out checking. > + // DMA buffer allocation. Needs to be done only once for both sync > + and async // DMA transfers irrespective of number of retries. > // > - OldTpl =3D gBS->RaiseTPL (TPL_NOTIFY); > - while ((Task =3D=3D NULL) && (!IsListEmpty (&Instance->NonBlockingTask= List))) > { > - AsyncNonBlockingTransferRoutine (NULL, Instance); > - // > - // Stall for 100us. > - // > - MicroSecondDelay (100); > - } > - gBS->RestoreTPL (OldTpl); > - > - if ((Task =3D=3D NULL) || ((Task !=3D NULL) && (!Task->IsStart))) { > - // > - // Mark the Task to indicate that it has been started. > - // > - if (Task !=3D NULL) { > - Task->IsStart =3D TRUE; > - } > + if ((Task =3D=3D NULL) || ((Task !=3D NULL) && (Task->Map =3D=3D NULL)= )) { > if (Read) { > Flag =3D EfiPciIoOperationBusMasterWrite; > } else { > Flag =3D EfiPciIoOperationBusMasterRead; > } >=20 > - // > - // Construct command list and command table with pci bus address. > - // > MapLength =3D DataCount; > Status =3D PciIo->Map ( > PciIo, > @@ -1101,63 +1088,123 @@ AhciDmaTransfer ( > if (EFI_ERROR (Status) || (DataCount !=3D MapLength)) { > return EFI_BAD_BUFFER_SIZE; > } > - > if (Task !=3D NULL) { > Task->Map =3D Map; > } > - // > - // Package read needed > - // > + } > + > + if (Task =3D=3D NULL || (Task !=3D NULL && !Task->IsStart)) { > AhciBuildCommandFis (&CFis, AtaCommandBlock); >=20 > ZeroMem (&CmdList, sizeof (EFI_AHCI_COMMAND_LIST)); >=20 > CmdList.AhciCmdCfl =3D EFI_AHCI_FIS_REGISTER_H2D_LENGTH / 4; > CmdList.AhciCmdW =3D Read ? 0 : 1; > + } >=20 > - AhciBuildCommand ( > - PciIo, > - AhciRegisters, > - Port, > - PortMultiplier, > - &CFis, > - &CmdList, > - AtapiCommand, > - AtapiCommandLength, > - 0, > - (VOID *)(UINTN)PhyAddr, > - DataCount > - ); > - > - Status =3D AhciStartCommand ( > - PciIo, > - Port, > - 0, > - Timeout > - ); > - if (EFI_ERROR (Status)) { > - goto Exit; > + if (Task =3D=3D NULL) { > + // > + // Before starting the Blocking BlockIO operation, push to finish al= l non- > blocking > + // BlockIO tasks. > + // Delay 100us to simulate the blocking time out checking. > + // > + OldTpl =3D gBS->RaiseTPL (TPL_NOTIFY); > + while (!IsListEmpty (&Instance->NonBlockingTaskList)) { > + AsyncNonBlockingTransferRoutine (NULL, Instance); > + // > + // Stall for 100us. > + // > + MicroSecondDelay (100); > } > - } > + gBS->RestoreTPL (OldTpl); > + for (Retry =3D 0; Retry < AHCI_COMMAND_RETRIES; Retry++) { > + AhciBuildCommand ( > + PciIo, > + AhciRegisters, > + Port, > + PortMultiplier, > + &CFis, > + &CmdList, > + AtapiCommand, > + AtapiCommandLength, > + 0, > + (VOID *)(UINTN)PhyAddr, > + DataCount > + ); >=20 > - if (Task !=3D NULL) { > - Status =3D AhciCheckFisReceived (PciIo, Port, SataFisD2H); > - if (Status =3D=3D EFI_NOT_READY) { > - if (!Task->InfiniteWait && Task->RetryTimes =3D=3D 0) { > - Status =3D EFI_TIMEOUT; > + Status =3D AhciStartCommand ( > + PciIo, > + Port, > + 0, > + Timeout > + ); > + if (EFI_ERROR (Status)) { > + break; > + } > + Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, SataFis= D2H); > + if (Status =3D=3D EFI_DEVICE_ERROR) { > + DEBUG ((DEBUG_ERROR, "DMA command failed at retry: %d\n", > Retry)); > + Status =3D AhciRecoverPortError (PciIo, Port); > + if (EFI_ERROR (Status)) { > + break; > + } > } else { > - Task->RetryTimes--; > + break; > } > } > } else { > - Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, SataFisD2= H); > - } > + if (!Task->IsStart) { > + AhciBuildCommand ( > + PciIo, > + AhciRegisters, > + Port, > + PortMultiplier, > + &CFis, > + &CmdList, > + AtapiCommand, > + AtapiCommandLength, > + 0, > + (VOID *)(UINTN)PhyAddr, > + DataCount > + ); >=20 > - if (Status =3D=3D EFI_DEVICE_ERROR) { > - AhciRecoverPortError (PciIo, Port); > + Status =3D AhciStartCommand ( > + PciIo, > + Port, > + 0, > + Timeout > + ); > + if (!EFI_ERROR (Status)) { > + Task->IsStart =3D TRUE; > + } > + } > + if (Task->IsStart) { > + Status =3D AhciCheckFisReceived (PciIo, Port, SataFisD2H); > + if (Status =3D=3D EFI_DEVICE_ERROR) { > + DEBUG ((DEBUG_ERROR, "DMA command failed at retry: %d\n", Task- > >RetryTimes)); > + Status =3D AhciRecoverPortError (PciIo, Port); > + // > + // If recovery passed mark the Task as not started and change th= e > status > + // to EFI_NOT_READY. This will make the higher level call this f= unction > again > + // and on next call the command will be re-issued due to IsStart= being > FALSE. > + // This also makes the next condition decrement the RetryTimes. > + // > + if (Status =3D=3D EFI_SUCCESS) { > + Task->IsStart =3D FALSE; > + Status =3D EFI_NOT_READY; > + } > + } > + > + if (Status =3D=3D EFI_NOT_READY) { > + if (!Task->InfiniteWait && Task->RetryTimes =3D=3D 0) { > + Status =3D EFI_TIMEOUT; > + } else { > + Task->RetryTimes--; > + } > + } > + } > } >=20 > -Exit: > // > // For Blocking mode, the command should be stopped, the Fis should be > disabled > // and the PciIo should be unmapped. > @@ -1234,6 +1281,7 @@ AhciNonDataTransfer ( > EFI_STATUS Status; > EFI_AHCI_COMMAND_FIS CFis; > EFI_AHCI_COMMAND_LIST CmdList; > + UINT32 Retry; >=20 > // > // Package read needed > @@ -1244,36 +1292,43 @@ AhciNonDataTransfer ( >=20 > CmdList.AhciCmdCfl =3D EFI_AHCI_FIS_REGISTER_H2D_LENGTH / 4; >=20 > - AhciBuildCommand ( > - PciIo, > - AhciRegisters, > - Port, > - PortMultiplier, > - &CFis, > - &CmdList, > - AtapiCommand, > - AtapiCommandLength, > - 0, > - NULL, > - 0 > - ); > + for (Retry =3D 0; Retry < AHCI_COMMAND_RETRIES; Retry++) { > + AhciBuildCommand ( > + PciIo, > + AhciRegisters, > + Port, > + PortMultiplier, > + &CFis, > + &CmdList, > + AtapiCommand, > + AtapiCommandLength, > + 0, > + NULL, > + 0 > + ); >=20 > - Status =3D AhciStartCommand ( > - PciIo, > - Port, > - 0, > - Timeout > - ); > - if (EFI_ERROR (Status)) { > - goto Exit; > - } > + Status =3D AhciStartCommand ( > + PciIo, > + Port, > + 0, > + Timeout > + ); > + if (EFI_ERROR (Status)) { > + break; > + } >=20 > - Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, SataFisD2H)= ; > - if (Status =3D=3D EFI_DEVICE_ERROR) { > - AhciRecoverPortError (PciIo, Port); > + Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, SataFisD2= H); > + if (Status =3D=3D EFI_DEVICE_ERROR) { > + DEBUG ((DEBUG_ERROR, "Non data transfer failed at retry %d\n", > Retry)); > + Status =3D AhciRecoverPortError (PciIo, Port); > + if (EFI_ERROR (Status)) { > + break; > + } > + } else { > + break; > + } > } >=20 > -Exit: > AhciStopCommand ( > PciIo, > Port, > diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h > b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h > index 4d2aafe483..0540b0f4fa 100644 > --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h > +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h > @@ -192,6 +192,8 @@ typedef union { > #define AHCI_PORT_DEVSLP_DITO_MASK 0x01FF8000 > #define AHCI_PORT_DEVSLP_DM_MASK 0x1E000000 >=20 > +#define AHCI_COMMAND_RETRIES 5 > + > #pragma pack(1) > // > // Command List structure includes total 32 entries. > -- > 2.28.0.windows.1