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.web08.6678.1604632468170813673 for ; Thu, 05 Nov 2020 19:14:28 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=soDY40Z4; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: hao.a.wu@intel.com) IronPort-SDR: wdvrMb1djd6FOzJEjBjVWrM2G9H1QyyWNtKNsJ6He4LGkqPqQXJvmfs8Q+Hi1BV2bAXjZ51dl0 UYiytoB0yAYg== X-IronPort-AV: E=McAfee;i="6000,8403,9796"; a="231123276" X-IronPort-AV: E=Sophos;i="5.77,454,1596524400"; d="scan'208";a="231123276" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2020 19:14:27 -0800 IronPort-SDR: b2jlHA59/MnEjU6xQrxpRuHNFLI/CI7+p0h8WD003reSvzW6M9hWj/Fng05FSsgntShoMR8atA dTttCloU/BSQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,454,1596524400"; d="scan'208";a="427206803" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by fmsmga001.fm.intel.com with ESMTP; 05 Nov 2020 19:14:27 -0800 Received: from orsmsx609.amr.corp.intel.com (10.22.229.22) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 5 Nov 2020 19:14:26 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) 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 via Frontend Transport; Thu, 5 Nov 2020 19:14:26 -0800 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.168) 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; Thu, 5 Nov 2020 19:14:25 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iKPQhjGLxmCU0prloMkw++yNF3scGJu7SAk0TWEiER+FcjfrFnGLC/IoVscG3iFByDa8j0NrVB/LKFslaVVDsi86PYk7tUtjWSCxMwokJppARx9SLH0akM+pa3flNsh/pvqlcbmUP/qjKZG2F5DvOv5qci2+eCxaEnJRJ/XpLywyr0dGF2FBW5JxhmLJMWjmPz9u9ujKsEueSMUEGC4xruqDFu5wVmn7u5OkYt1Ex0byyqj+Oq7U9ki56nDZBFSN1pdaykNHlYsTBFVHU7DyqxWbvbonP5W1JiN9Ipq7/CAdjh4HQ4WjC80eHsh44aEwxVxkYdgeIDcbepj+Imx8OA== 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=+KRsN3djT/3wKKCvp0Fwq1SrnBKmmpfZUQ2WuWkoHAQ=; b=BH9fYlHE68uu+PE6i3SSvmPkkvhVlSHGH+X6o4tn04fTNMW98i/BB4Ssb0LlesvvsyaP+i1Wd5LZC4V2lKCRFcHj0xfFy0FXK7dwPrT4H71Gg10EZxMRtITPwlJK3nuYZuiKozjqOVY5kq3ibmV9MhHvWznBHw1e8pj7SsOLCCcOTq6FmIxDtzNT/l2RUpstSg4EuGFCwmwF64XvBLr4hiSK3zISkXBM63tK289Oqp6kSqLUpeR21pL+LuKxmh+OYQib7W6J9DYxKNRj17IShkWWDt84KZ607gOHq+bi1PC/LqJSh0uSsMwbPBmAQ1taH6PV4lhx6qKUUHw+X8LNZg== 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=+KRsN3djT/3wKKCvp0Fwq1SrnBKmmpfZUQ2WuWkoHAQ=; b=soDY40Z4N4OlcTiEPI2u6xMfXYOwm0UfFpXdBfNfajDzdERunoGQ2P4+I3mV5y6HX6DT5PX0pOrM/0sWaaDgRYkoulwbyKk3ykv9UcRzZ8w3/mhq6XmW4RNIkQxxmAl2Yqe10MdJh8yGoxSw2Yv9GCxJpzYbr7q/IeLYUUx6dt0= Received: from BN8PR11MB3666.namprd11.prod.outlook.com (2603:10b6:408:8c::19) by BN6PR11MB1555.namprd11.prod.outlook.com (2603:10b6:405:c::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18; Fri, 6 Nov 2020 03:14:23 +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; Fri, 6 Nov 2020 03:14:23 +0000 From: "Wu, Hao A" To: "Albecki, Mateusz" , "devel@edk2.groups.io" CC: "Ni, Ray" Subject: Re: [PATCHv3 3/4] MdeModulePkg/AtaAtapiPassThru: Restart failed packets Thread-Topic: [PATCHv3 3/4] MdeModulePkg/AtaAtapiPassThru: Restart failed packets Thread-Index: AQHWs3IUvIidhniCT0iJoaa8Mq7ueam6bs0w Date: Fri, 6 Nov 2020 03:14:23 +0000 Message-ID: References: <20201105124847.3136-2-mateusz.albecki@intel.com> <20201105124847.3136-4-mateusz.albecki@intel.com> In-Reply-To: <20201105124847.3136-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: 343afd52-2f87-4fb9-fc8b-08d882020fbc x-ms-traffictypediagnostic: BN6PR11MB1555: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1775; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: KcB0C/6HGAKbSNLl3iRj0oWEOSB2gqFVmzzEJnTXDZcRYz0uL6uaRhLELmV8B/0MmwDUp3QuS3Y6RWlOLlygxLY/xizDKK+bDdFG4Hx7gDUGeNHNDEueP2NkImKUqbgYOScxhz5YOCigvQtLdWDLtLbeuiSXqX1M1ZtSzWBHqY+xsY91oMNKh4McdAqjo1/cdbN+AvVy/W9ARjUa4DiofP2GCmFb9iTrBp36FcLjOw3QwQ6rK/xTJuQ9iMMEeqR2D70v/YfHBWYInhEOT9VBeDeI7BJFIXNCwAajD4F74Tt0GSGRyTgt/9QXS+47sC0XoiFg9+fB9mxSJFYISxqyrmiUfJjWdEd0KKGSYWLtqVY7DJyvhZgG4tzFYXKEgrE7/NdVEx/1LhBbQZz1fCD6CA== 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)(376002)(366004)(136003)(396003)(39860400002)(346002)(33656002)(52536014)(110136005)(83380400001)(966005)(76116006)(71200400001)(30864003)(316002)(55016002)(478600001)(86362001)(107886003)(2906002)(64756008)(4326008)(7696005)(186003)(53546011)(66446008)(8936002)(26005)(5660300002)(8676002)(66946007)(66556008)(6506007)(66476007)(9686003);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: FSBEYggHG2iubjNufHgkM6ATuuUDxW7p2im2QeQ9WHECAnMaqz026WJhg4ttivn3I7eWBESQFvaOFNetDgxfxZDBPc8LTHS4nWRnF4Z/sw4YjP2l4fHbNlS4/x1L9VxPoKvWteoG+SCsfmJoB3/vlvd9r9lW1ka5bUzVM+nlnWKEqgYEvfyb38ZM+FBjJjj3ygjG2VAjKvbe/6gsWeYwfhTwwp0NQJm/XS9yUa6NYVPzZ4j5Q7EGo8djVC9ypYPwLYMDomytBUFL/BeVmMFl8vLqlr0GGFE+4tJTBkpA+f3V5kAyis/2u5fGcKwfkcQPQAQcbhWda6RbG9IIKyXKSR585TLnu9dwMidLer9zfIM9vs/eLq2+D8LliT9951SNXjQZ+lKgq8Ca+bnxFPtAxigjes1oM/QFhEcuPLAEMBOq871BaIKZrvzea580BqzwjRG3lweDfKZtFCXYNI1pemzsw/AjxyDNcjnQD3EI8NLR9yc09sKAshyMkWzdm37Bkk33i9MZJk8bHQlm27sXpguuZ6/LnOQW/ad9ZKEhb5N7JWk66mFPFv1qhvgYy8JhpWjvYDyrdWsAYLjfRc/iDsxdRULdPMmlSgUcMD+oTOUyBqHCMxlSc+mhYmTOy8n0xy+04JVMEvp7GIwObd8oVQ== 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: 343afd52-2f87-4fb9-fc8b-08d882020fbc X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Nov 2020 03:14:23.6765 (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: BTymmxYqQK6Xnv9fX1lJbdYHXX/E29K56Ou/5KWXtozBnX8eqSuoeQ6y8j48JClqnzZCPrSxEm0FySB3p1xPug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR11MB1555 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: Thursday, November 5, 2020 8:49 PM > To: devel@edk2.groups.io > Cc: Albecki, Mateusz ; Ni, Ray > ; Wu, Hao A > Subject: [PATCHv3 3/4] MdeModulePkg/AtaAtapiPassThru: Restart failed > packets >=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. For async traansfers, the command wil > be retried until the timeout value timeout specified by the requester is Reviewed-by: Hao A Wu Best Regards, Hao Wu > reached. For sync case the count of 5 retries has 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 > --- > .../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 0b7141c4f1..47275a851a 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 > + ); > + > + 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; > + } > + } >=20 > - if (Status =3D=3D EFI_DEVICE_ERROR) { > - AhciRecoverPortError (PciIo, Port); > + 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 338447a55f..ced2648970 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