From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web09.6797.1604632335114915607 for ; Thu, 05 Nov 2020 19:12:15 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=CB4zuJJr; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: hao.a.wu@intel.com) IronPort-SDR: /nSwi/6ow+AxUjzto4gPOpPGec0aZZEsjBvXXEp6BZjy3a/1rAjWfVtwch/BkXjLcG+HqKAmTa PdUiDaT7x4wQ== X-IronPort-AV: E=McAfee;i="6000,8403,9796"; a="156496468" X-IronPort-AV: E=Sophos;i="5.77,454,1596524400"; d="scan'208";a="156496468" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2020 19:12:13 -0800 IronPort-SDR: xFQpNuYGHCoVeOG17bFcfaMi1yypJ7UtdISVIWPq8yaeymlhCyA13i15DgrMIphtq9MtWI+LFG 6RkvZ37B3ivg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,454,1596524400"; d="scan'208";a="471905078" Received: from orsmsx606.amr.corp.intel.com ([10.22.229.19]) by orsmga004.jf.intel.com with ESMTP; 05 Nov 2020 19:12:13 -0800 Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) by ORSMSX606.amr.corp.intel.com (10.22.229.19) 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:12:13 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx601.amr.corp.intel.com (10.22.229.14) 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:12:13 -0800 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (104.47.36.50) 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:12:05 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D77VceImX7NYqilXF1R2yvKfBIUY91vDTIWCo5Tw1X/OP0C0F5f3EmnoRDlT3SguveKnOYfXgjvCzf88SZ8cN+3GHfSCcqLxzR4pB+fkJyKqhLLYM0G3G+JFTieMX2+uWwDTsv8j9LEpalgIpgfkmqsJrzp5L0E0RNi3bxefpVSqPiJnXm7Efgd9Rytx/GTQaP7Mc0MzvpAKzi0xoDtBTzU3ugHyoidqcsPNLLRnAQhD+T+br4bvkLj34X5pYgjo0WV4qtFLH1mvwhYDT4VbZijF8mNMDQpp4pa7CiewmuwmilUyUPVpE8kgLo3QfWmMd7YwNQmqm8DhRBlYoti0VA== 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=xi/N235da9u6epQyn2HUvh3hq3i1MWwnt3VK7YqczXI=; b=ArvDqCnibwbNLkHIWmlxj8MhxVRM7ucr5Yfvhq5vPz025XKGuG9HJupB41Y5k1C+6k4MswPErga+jb1Alz2oet4tX0anFm9sdoZRKn/+o1urKQS65owp0/Cxs62s8JQRGZCSYhg5zOUReRAlacVz1ksCcSWPNT3jbe8T00UGMozFHP7qJUEgjifarshxkj5AGyRoN+GKRbErG+ut+uPc/aWP6FJjHv5o93VIsByapxQMeT52b7UNm8Z9RW5i7IBhcHWBONnquXslVtGDYthSLx4WPjQa6VJ9imHM7yg1jWdyR/13rIuf507UZksb1GBzimujxsVW0+tDAHe8pGQyzw== 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=xi/N235da9u6epQyn2HUvh3hq3i1MWwnt3VK7YqczXI=; b=CB4zuJJr9mkVSMclHg2QDp75MHySfAYU/XpVkkCaZY0tKBKoJRONKXjaAEFL0q7sqjmEbKrfJTBOI4JcrdQHJ3BinQtlxRHItiBIDgxEuycCyQudq1TzAVeGBo8UHdXYTAfl07tnBb/7JrL+usCnLAUWSx6LcPHlaCucXoFYsd0= 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:12:03 +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:12:03 +0000 From: "Wu, Hao A" To: "Albecki, Mateusz" , "devel@edk2.groups.io" CC: "Ni, Ray" Subject: Re: [PATCHv3 1/4] MdeModulePkg/AtaAtapiPassThru: Check IS to check for command completion Thread-Topic: [PATCHv3 1/4] MdeModulePkg/AtaAtapiPassThru: Check IS to check for command completion Thread-Index: AQHWs3ISSimrd6og0km3lSsJPdfacqm6bi2g Date: Fri, 6 Nov 2020 03:12:03 +0000 Message-ID: References: <20201105124847.3136-2-mateusz.albecki@intel.com> In-Reply-To: <20201105124847.3136-2-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: 4421ddba-37b4-411c-9173-08d88201bc55 x-ms-traffictypediagnostic: BN6PR11MB1555: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7691; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: GU+Z0oXI8RdVlHoO0f2MXjgVzrIIaNkw4UCKDz6cTQCqviZxbnhoNN5+a8fNL7hDCFN6yugtNHui0Kwsyt4QdfZG5TIeZXIcOJnPN9vy1CgrANrv7MCG2JTmubc4pqVfqqiqmP6wZwvslBhLSBKRRrgG+NvrzPgaXHjxV+F9pR4B/KEVRH1GEEQHNeFdzK5DtvkXSzrxTHVNipDtLVIyJNZ6z8VK1GTaNL08eANMmI8AckQOZc2yny6OnHlCIbY+D4/ajT/IgWrlTOY4HUhxL/2VJad7P/kALeAzDcWOsur/Djb4ihDBEhKDwte4lVw0lJFtlDCMrKodHw064hgBFVF8i80ERcQ1DMolh7F7CJ3sH4vQtLRAyy6yqP7lBJovckVMQ6Ko0+psRTIqN6cWlQ== 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: NIywWbMcO9ALMLU1QMTeIQyJlmzTji8yGDWftXV3yNBUcGBbyuCDh7PMoAsmDK4VUsLxPOjuwxofpUwSTlAQt9H2Q6nBxN2fjI8qw0cZisaXZ4/MTpXpd0gBrZC/qSQVdfs70JwTJl6hqz15B8zlUXovmYP8sRZ+70HrpVL8Sor61pyBXJYZl3ssc3D8Ny07x0NClOodpx1dpRJwlKG3h6ktXaJmBMJ/tKryikCjZQzqiTsO4vp31SywUKVx5ReGBeFHwdoH3UWBl6Ny7ckF6dMT9c8Uj8VQD5O97tsJKTFylekrRkGrYPA24mO0m5mj+0nDE6mK+E/aUEQ9finhi9SM12s8L8IV3ZNDtcT94EEhPHD0hd02x5RC4v5vq/nXlZtL/oXvQ3NIRsGou8gW43WlmCubY+Jp5h6CGrIKNA4LtBuXelQnrXSX3oqFJy8GZQYp0zj5SSY07+sa+j1rPFMaAFWCSSj7lLDDxZvCmYIkAY4rMWqfCFxlhEsy+WvYv2sU1miCtcwur7lQAifQCnUZFtQJ13v2eX2FyVrrqXqFgoUlz7c+YlwwIoIk9+uhZSjiDmK1gGwI/Y6t2RtrmanL08gM/jj/im3yFHLyeJpX1I2yLoWuwHgIUe4vz+ShnEAlkjaps0edriop98S2JA== 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: 4421ddba-37b4-411c-9173-08d88201bc55 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Nov 2020 03:12:03.8558 (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: Mblc+rnitdJNAI5KwhvymAxIFXZTRBtyPEfrBnAqQJkApykTZvTxdS95ZA8dHdS93MjAFpejeiaeII5Be+CRNg== 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 1/4] MdeModulePkg/AtaAtapiPassThru: Check IS to check > for command completion >=20 > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3024 >=20 > AHCI driver used to poll D2H register type to determine whether the FIS h= as > been received. This caused a problem of long timeouts when the link got a > CRC error and the FIS never arrives. To fix this this change switches AHC= I > driver to poll the IS register which will signal both the reception of FI= S and the > occurance of error. >=20 > Signed-off-by: Mateusz Albecki >=20 > Cc: Ray Ni > Cc: Hao A Wu Reviewed-by: Hao A Wu Best Regards, Hao Wu >=20 > --- > .../Bus/Ata/AtaAtapiPassThru/AhciMode.c | 292 ++++++++---------- > .../Bus/Ata/AtaAtapiPassThru/AhciMode.h | 11 +- > 2 files changed, 132 insertions(+), 171 deletions(-) >=20 > diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c > b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c > index 7e2fade400..180a60b5aa 100644 > --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c > +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c > @@ -1,7 +1,7 @@ > /** @file > The file for AHCI mode of ATA host controller. >=20 > - Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
> + Copyright (c) 2010 - 2020, Intel Corporation. All rights > + reserved.
> (C) Copyright 2015 Hewlett Packard Enterprise Development LP
> SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > @@ -248,32 +248,23 @@ AhciWaitMemSet ( > /** > Check the memory status to the test value. >=20 > - @param[in] Address The memory address to test. > - @param[in] MaskValue The mask value of memory. > - @param[in] TestValue The test value of memory. > - @param[in, out] Task Optional. Pointer to the > ATA_NONBLOCK_TASK used by > - non-blocking mode. If NULL, then ju= st try once. > + @param[in] Address The memory address to test. > + @param[in] MaskValue The mask value of memory. > + @param[in] TestValue The test value of memory. >=20 > - @retval EFI_NOTREADY The memory is not set. > - @retval EFI_TIMEOUT The memory setting retry times out. > + @retval EFI_NOT_READY The memory is not set. > @retval EFI_SUCCESS The memory is correct set. > - > **/ > EFI_STATUS > EFIAPI > AhciCheckMemSet ( > IN UINTN Address, > IN UINT32 MaskValue, > - IN UINT32 TestValue, > - IN OUT ATA_NONBLOCK_TASK *Task > + IN UINT32 TestValue > ) > { > UINT32 Value; >=20 > - if (Task !=3D NULL) { > - Task->RetryTimes--; > - } > - > Value =3D *(volatile UINT32 *) Address; > Value &=3D MaskValue; >=20 > @@ -281,11 +272,7 @@ AhciCheckMemSet ( > return EFI_SUCCESS; > } >=20 > - if ((Task !=3D NULL) && !Task->InfiniteWait && (Task->RetryTimes =3D= =3D 0)) { > - return EFI_TIMEOUT; > - } else { > - return EFI_NOT_READY; > - } > + return EFI_NOT_READY; > } >=20 >=20 > @@ -357,7 +344,7 @@ AhciDumpPortStatus ( > FisBaseAddr =3D (UINTN)AhciRegisters->AhciRFis + Port * sizeof > (EFI_AHCI_RECEIVED_FIS); > Offset =3D FisBaseAddr + EFI_AHCI_D2H_FIS_OFFSET; >=20 > - Status =3D AhciCheckMemSet (Offset, EFI_AHCI_FIS_TYPE_MASK, > EFI_AHCI_FIS_REGISTER_D2H, NULL); > + Status =3D AhciCheckMemSet (Offset, EFI_AHCI_FIS_TYPE_MASK, > + EFI_AHCI_FIS_REGISTER_D2H); > if (!EFI_ERROR (Status)) { > // > // If D2H FIS is received, update StatusBlock with its content. > @@ -621,6 +608,102 @@ AhciBuildCommandFis ( > CmdFis->AhciCFisDevHead =3D (UINT8) (AtaCommandBlock- > >AtaDeviceHead | 0xE0); > } >=20 > +/** > + Checks if specified FIS has been received. > + > + @param[in] PciIo Pointer to AHCI controller PciIo. > + @param[in] Port SATA port index on which to check. > + @param[in] FisType FIS type for which to check. > + > + @retval EFI_SUCCESS FIS received. > + @retval EFI_NOT_READY FIS not received yet. > + @retval EFI_DEVICE_ERROR AHCI controller reported an error on port. > +**/ > +EFI_STATUS > +AhciCheckFisReceived ( > + IN EFI_PCI_IO_PROTOCOL *PciIo, > + IN UINT8 Port, > + IN SATA_FIS_TYPE FisType > + ) > +{ > + UINT32 Offset; > + UINT32 PortInterrupt; > + UINT32 PortTfd; > + > + Offset =3D EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + > + EFI_AHCI_PORT_IS; PortInterrupt =3D AhciReadReg (PciIo, Offset); if > + ((PortInterrupt & EFI_AHCI_PORT_IS_ERROR_MASK) !=3D 0) { > + DEBUG ((DEBUG_ERROR, "AHCI: Error interrupt reported PxIS: %X\n", > PortInterrupt)); > + return EFI_DEVICE_ERROR; > + } > + // > + // For PIO setup FIS - According to SATA 2.6 spec section 11.7, D2h FI= S > means an error encountered. > + // But Qemu and Marvel 9230 sata controller may just receive a D2h > + FIS from device // after the transaction is finished successfully. > + // To get better device compatibilities, we further check if the PxTFD= 's ERR > bit is set. > + // By this way, we can know if there is a real error happened. > + // > + if (((FisType =3D=3D SataFisD2H) && ((PortInterrupt & > EFI_AHCI_PORT_IS_DHRS) !=3D 0)) || > + ((FisType =3D=3D SataFisPioSetup) && (PortInterrupt & > (EFI_AHCI_PORT_IS_PSS | EFI_AHCI_PORT_IS_DHRS)) !=3D 0) || > + ((FisType =3D=3D SataFisDmaSetup) && (PortInterrupt & > (EFI_AHCI_PORT_IS_DSS | EFI_AHCI_PORT_IS_DHRS)) !=3D 0)) { > + Offset =3D EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + > EFI_AHCI_PORT_TFD; > + PortTfd =3D AhciReadReg (PciIo, (UINT32) Offset); > + if ((PortTfd & EFI_AHCI_PORT_TFD_ERR) !=3D 0) { > + return EFI_DEVICE_ERROR; > + } else { > + return EFI_SUCCESS; > + } > + } > + > + return EFI_NOT_READY; > +} > + > +/** > + Waits until specified FIS has been received. > + > + @param[in] PciIo Pointer to AHCI controller PciIo. > + @param[in] Port SATA port index on which to check. > + @param[in] Timeout Time after which function should stop polling. > + @param[in] FisType FIS type for which to check. > + > + @retval EFI_SUCCESS FIS received. > + @retval EFI_TIMEOUT FIS failed to arrive within a specified time= period. > + @retval EFI_DEVICE_ERROR AHCI controller reported an error on port. > +**/ > +EFI_STATUS > +AhciWaitUntilFisReceived ( > + IN EFI_PCI_IO_PROTOCOL *PciIo, > + IN UINT8 Port, > + IN UINT64 Timeout, > + IN SATA_FIS_TYPE FisType > + ) > +{ > + EFI_STATUS Status; > + BOOLEAN InfiniteWait; > + UINT64 Delay; > + > + Delay =3D DivU64x32 (Timeout, 1000) + 1; if (Timeout =3D=3D 0) { > + InfiniteWait =3D TRUE; > + } else { > + InfiniteWait =3D FALSE; > + } > + > + do { > + Status =3D AhciCheckFisReceived (PciIo, Port, FisType); > + if (Status !=3D EFI_NOT_READY) { > + return Status; > + } > + // > + // Stall for 100 microseconds. > + // > + MicroSecondDelay (100); > + Delay--; > + } while (InfiniteWait || (Delay > 0)); > + > + return EFI_TIMEOUT; > +} > + > /** > Start a PIO data transfer on specific port. >=20 > @@ -665,26 +748,13 @@ AhciPioTransfer ( > ) > { > EFI_STATUS Status; > - UINTN FisBaseAddr; > - UINTN Offset; > EFI_PHYSICAL_ADDRESS PhyAddr; > VOID *Map; > UINTN MapLength; > EFI_PCI_IO_PROTOCOL_OPERATION Flag; > - UINT64 Delay; > EFI_AHCI_COMMAND_FIS CFis; > EFI_AHCI_COMMAND_LIST CmdList; > - UINT32 PortTfd; > UINT32 PrdCount; > - BOOLEAN InfiniteWait; > - BOOLEAN PioFisReceived; > - BOOLEAN D2hFisReceived; > - > - if (Timeout =3D=3D 0) { > - InfiniteWait =3D TRUE; > - } else { > - InfiniteWait =3D FALSE; > - } >=20 > if (Read) { > Flag =3D EfiPciIoOperationBusMasterWrite; @@ -743,87 +813,18 @@ > AhciPioTransfer ( > goto Exit; > } >=20 > - // > - // Check the status and wait the driver sending data > - // > - FisBaseAddr =3D (UINTN)AhciRegisters->AhciRFis + Port * sizeof > (EFI_AHCI_RECEIVED_FIS); > - > if (Read && (AtapiCommand =3D=3D 0)) { > - // > - // Wait device sends the PIO setup fis before data transfer > - // > - Status =3D EFI_TIMEOUT; > - Delay =3D DivU64x32 (Timeout, 1000) + 1; > - do { > - PioFisReceived =3D FALSE; > - D2hFisReceived =3D FALSE; > - Offset =3D FisBaseAddr + EFI_AHCI_PIO_FIS_OFFSET; > - Status =3D AhciCheckMemSet (Offset, EFI_AHCI_FIS_TYPE_MASK, > EFI_AHCI_FIS_PIO_SETUP, NULL); > - if (!EFI_ERROR (Status)) { > - PioFisReceived =3D TRUE; > - } > - // > - // According to SATA 2.6 spec section 11.7, D2h FIS means an error > encountered. > - // But Qemu and Marvel 9230 sata controller may just receive a D2h= FIS > from device > - // after the transaction is finished successfully. > - // To get better device compatibilities, we further check if the P= xTFD's > ERR bit is set. > - // By this way, we can know if there is a real error happened. > - // > - Offset =3D FisBaseAddr + EFI_AHCI_D2H_FIS_OFFSET; > - Status =3D AhciCheckMemSet (Offset, EFI_AHCI_FIS_TYPE_MASK, > EFI_AHCI_FIS_REGISTER_D2H, NULL); > - if (!EFI_ERROR (Status)) { > - D2hFisReceived =3D TRUE; > - } > - > - if (PioFisReceived || D2hFisReceived) { > - Offset =3D EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH = + > EFI_AHCI_PORT_TFD; > - PortTfd =3D AhciReadReg (PciIo, (UINT32) Offset); > - // > - // PxTFD will be updated if there is a D2H or SetupFIS received. > - // > - if ((PortTfd & EFI_AHCI_PORT_TFD_ERR) !=3D 0) { > - Status =3D EFI_DEVICE_ERROR; > - break; > - } > - > - PrdCount =3D *(volatile UINT32 *) (&(AhciRegisters- > >AhciCmdList[0].AhciCmdPrdbc)); > - if (PrdCount =3D=3D DataCount) { > - Status =3D EFI_SUCCESS; > - break; > - } > - } > - > - // > - // Stall for 100 microseconds. > - // > - MicroSecondDelay(100); > - > - Delay--; > - if (Delay =3D=3D 0) { > - Status =3D EFI_TIMEOUT; > + 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; > } > - } while (InfiniteWait || (Delay > 0)); > - } else { > - // > - // Wait for D2H Fis is received > - // > - Offset =3D FisBaseAddr + EFI_AHCI_D2H_FIS_OFFSET; > - Status =3D AhciWaitMemSet ( > - Offset, > - EFI_AHCI_FIS_TYPE_MASK, > - EFI_AHCI_FIS_REGISTER_D2H, > - Timeout > - ); > - > - if (EFI_ERROR (Status)) { > - goto Exit; > - } > - > - Offset =3D EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + > EFI_AHCI_PORT_TFD; > - PortTfd =3D AhciReadReg (PciIo, (UINT32) Offset); > - if ((PortTfd & EFI_AHCI_PORT_TFD_ERR) !=3D 0) { > - Status =3D EFI_DEVICE_ERROR; > } > + } else { > + Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, > + SataFisD2H); > } >=20 > Exit: > @@ -893,15 +894,12 @@ AhciDmaTransfer ( > ) > { > EFI_STATUS Status; > - UINTN Offset; > EFI_PHYSICAL_ADDRESS PhyAddr; > VOID *Map; > UINTN MapLength; > EFI_PCI_IO_PROTOCOL_OPERATION Flag; > EFI_AHCI_COMMAND_FIS CFis; > EFI_AHCI_COMMAND_LIST CmdList; > - UINTN FisBaseAddr; > - UINT32 PortTfd; >=20 > EFI_PCI_IO_PROTOCOL *PciIo; > EFI_TPL OldTpl; > @@ -996,38 +994,17 @@ AhciDmaTransfer ( > } > } >=20 > - // > - // Wait for command complete > - // > - FisBaseAddr =3D (UINTN)AhciRegisters->AhciRFis + Port * sizeof > (EFI_AHCI_RECEIVED_FIS); > - Offset =3D FisBaseAddr + EFI_AHCI_D2H_FIS_OFFSET; > if (Task !=3D NULL) { > - // > - // For Non-blocking > - // > - Status =3D AhciCheckMemSet ( > - Offset, > - EFI_AHCI_FIS_TYPE_MASK, > - EFI_AHCI_FIS_REGISTER_D2H, > - Task > - ); > + 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; > + } else { > + Task->RetryTimes--; > + } > + } > } else { > - Status =3D AhciWaitMemSet ( > - Offset, > - EFI_AHCI_FIS_TYPE_MASK, > - EFI_AHCI_FIS_REGISTER_D2H, > - Timeout > - ); > - } > - > - if (EFI_ERROR (Status)) { > - goto Exit; > - } > - > - Offset =3D EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + > EFI_AHCI_PORT_TFD; > - PortTfd =3D AhciReadReg (PciIo, (UINT32) Offset); > - if ((PortTfd & EFI_AHCI_PORT_TFD_ERR) !=3D 0) { > - Status =3D EFI_DEVICE_ERROR; > + Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, > + SataFisD2H); > } >=20 > Exit: > @@ -1105,9 +1082,6 @@ AhciNonDataTransfer ( > ) > { > EFI_STATUS Status; > - UINTN FisBaseAddr; > - UINTN Offset; > - UINT32 PortTfd; > EFI_AHCI_COMMAND_FIS CFis; > EFI_AHCI_COMMAND_LIST CmdList; >=20 > @@ -1144,27 +1118,7 @@ AhciNonDataTransfer ( > goto Exit; > } >=20 > - // > - // Wait device sends the Response Fis > - // > - FisBaseAddr =3D (UINTN)AhciRegisters->AhciRFis + Port * sizeof > (EFI_AHCI_RECEIVED_FIS); > - Offset =3D FisBaseAddr + EFI_AHCI_D2H_FIS_OFFSET; > - Status =3D AhciWaitMemSet ( > - Offset, > - EFI_AHCI_FIS_TYPE_MASK, > - EFI_AHCI_FIS_REGISTER_D2H, > - Timeout > - ); > - > - if (EFI_ERROR (Status)) { > - goto Exit; > - } > - > - Offset =3D EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + > EFI_AHCI_PORT_TFD; > - PortTfd =3D AhciReadReg (PciIo, (UINT32) Offset); > - if ((PortTfd & EFI_AHCI_PORT_TFD_ERR) !=3D 0) { > - Status =3D EFI_DEVICE_ERROR; > - } > + Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, SataFisD2H)= ; >=20 > Exit: > AhciStopCommand ( > diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h > b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h > index 786413930a..6bcff1bb7b 100644 > --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h > +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h > @@ -1,7 +1,7 @@ > /** @file > Header file for AHCI mode of ATA host controller. >=20 > - Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
> + Copyright (c) 2010 - 2020, Intel Corporation. All rights > + reserved.
> SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > **/ > @@ -96,7 +96,7 @@ typedef union { > #define EFI_AHCI_PORT_IS 0x0010 > #define EFI_AHCI_PORT_IS_DHRS BIT0 > #define EFI_AHCI_PORT_IS_PSS BIT1 > -#define EFI_AHCI_PORT_IS_SSS BIT2 > +#define EFI_AHCI_PORT_IS_DSS BIT2 > #define EFI_AHCI_PORT_IS_SDBS BIT3 > #define EFI_AHCI_PORT_IS_UFS BIT4 > #define EFI_AHCI_PORT_IS_DPS BIT5 > @@ -113,6 +113,7 @@ typedef union { > #define EFI_AHCI_PORT_IS_CPDS BIT31 > #define EFI_AHCI_PORT_IS_CLEAR 0xFFFFFFFF > #define EFI_AHCI_PORT_IS_FIS_CLEAR 0x0000000F > +#define EFI_AHCI_PORT_IS_ERROR_MASK (EFI_AHCI_PORT_IS_INFS > | EFI_AHCI_PORT_IS_IFS | EFI_AHCI_PORT_IS_HBDS | > EFI_AHCI_PORT_IS_HBFS | EFI_AHCI_PORT_IS_TFES) >=20 > #define EFI_AHCI_PORT_IE 0x0014 > #define EFI_AHCI_PORT_CMD 0x0018 > @@ -240,6 +241,12 @@ typedef struct { > UINT8 AhciCFisRsvd5[44]; > } EFI_AHCI_COMMAND_FIS; >=20 > +typedef enum { > + SataFisD2H =3D 0, > + SataFisPioSetup, > + SataFisDmaSetup > +} SATA_FIS_TYPE; > + > // > // ACMD: ATAPI command (12 or 16 bytes) // > -- > 2.28.0.windows.1