From nobody Mon Nov 25 17:57:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+67034+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+67034+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1604580086; cv=none; d=zohomail.com; s=zohoarc; b=et05gWhwtXO737J68mlAfJXcDrMuK3LchMe6Kgwzmd78sm3kaLvdmHgqTDkeiQhaN3zzF8PUNM6FjZW/d2/PsVp/kZIc8hOleI8oWG666pVk9CP6UyULhI1cUCqq+MUWjJnzQWg7DQJlyrxcXyycRSHnGAFLi6e+FRSazCz1Pd8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604580086; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=cFzIXtZKTjQGeaJkVNnK30diKwEmqXdInMdMvPP8Hvk=; b=OH2F+4UQXabLOajiv4jN+ijfN+EHpI3ky/i3mz723fxMiLWP6Sa4v3ADpOlwR95GVKoYaT45oRrHX10vFJT36a7LiXT8ASSsGquE0TfP+uPbUFuEXdBqUGVWef53TFqOUwFPrw+/nFIl9IXb9LQdyFVZtGNWTJX67m80PLb3w3Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+67034+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1604580086392659.3584865191016; Thu, 5 Nov 2020 04:41:26 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id papCYY1788612xt31cn9VIdS; Thu, 05 Nov 2020 04:41:25 -0800 X-Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.6849.1604580085233921336 for ; Thu, 05 Nov 2020 04:41:25 -0800 IronPort-SDR: M98/VWbkJ6//gR7Ndn8VkWrJSeEsmLYd5f/BcqV3Nyfgrgz6ruf6m8Przwiy6M0VtuROpyyPic hz8qSZcxi9ZQ== X-IronPort-AV: E=McAfee;i="6000,8403,9795"; a="233540152" X-IronPort-AV: E=Sophos;i="5.77,453,1596524400"; d="scan'208";a="233540152" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2020 04:41:21 -0800 IronPort-SDR: 7k35RwNzBlN4r6B2WxtKmEXVE47gUbvQTi1VAlpRGeruBpytgOHp48mP5oLJN9Z9NmXK27SHt7 vEzV7GFNpt9w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,453,1596524400"; d="scan'208";a="527949667" X-Received: from gklab-27-32.ger.corp.intel.com ([10.102.28.45]) by fmsmga006.fm.intel.com with ESMTP; 05 Nov 2020 04:41:19 -0800 From: "Albecki, Mateusz" To: devel@edk2.groups.io Cc: Mateusz Albecki , Ray Ni , Hao A Wu Subject: [edk2-devel] [PATCHv2 1/4] MdeModulePkg/AtaAtapiPassThru: Check IS to check for command completion Date: Thu, 5 Nov 2020 13:40:43 +0100 Message-Id: <20201105124046.3744-2-mateusz.albecki@intel.com> In-Reply-To: <20201105124046.3744-1-mateusz.albecki@intel.com> References: <20201105124046.3744-1-mateusz.albecki@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,mateusz.albecki@intel.com X-Gm-Message-State: 3BmbXTL6lv8osnBc1YdifIf5x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1604580085; bh=yzopZIov2ezZYMx5bn0EPmHkdWOE6nCJX69n81eYLV8=; h=Cc:Date:From:Reply-To:Subject:To; b=PKROQyu3mstZfcUbNhNJvcBX53ZwNs9kW7iv6bSHDHEMmeSkTcY847ieCvmuS/0FRmG MJEGlsagDAE4DK4DgRBx/FhuuB5dRTpEnBWx8RCarzDzADrkAMZttiFR6qhLAns+Qk59k ICkLAeVYn1Oa+v/o2m0ZIN2Y8WTiypK+Ax8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" AHCI driver used to poll D2H register type to determine whether the FIS has 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 AHCI driver to poll the IS register which will signal both the reception of FIS and the occurance of error. Signed-off-by: Mateusz Albecki Cc: Ray Ni Cc: Hao A Wu --- .../Bus/Ata/AtaAtapiPassThru/AhciMode.c | 292 ++++++++---------- .../Bus/Ata/AtaAtapiPassThru/AhciMode.h | 11 +- 2 files changed, 132 insertions(+), 171 deletions(-) diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c b/MdeModulePk= g/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 just= 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_AH= CI_RECEIVED_FIS); Offset =3D FisBaseAddr + EFI_AHCI_D2H_FIS_OFFSET; =20 - Status =3D AhciCheckMemSet (Offset, EFI_AHCI_FIS_TYPE_MASK, EFI_AHCI_F= IS_REGISTER_D2H, NULL); + Status =3D AhciCheckMemSet (Offset, EFI_AHCI_FIS_TYPE_MASK, EFI_AHCI_F= IS_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_AH= CI_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", Port= Interrupt)); + return EFI_DEVICE_ERROR; + } + // + // For PIO setup FIS - 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 f= rom 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_D= HRS) !=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 p= eriod. + @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 e= ncountered. - // But Qemu and Marvel 9230 sata controller may just receive a D2h F= IS from device - // after the transaction is finished successfully. - // To get better device compatibilities, we further check if the PxT= FD'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, SataFisPioS= etup); + if (Status =3D=3D EFI_SUCCESS) { + PrdCount =3D *(volatile UINT32 *) (&(AhciRegisters->AhciCmdList[0].A= hciCmdPrdbc)); + 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_AH= CI_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_AH= CI_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/MdeModulePk= g/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 | EF= I_AHCI_PORT_IS_IFS | EFI_AHCI_PORT_IS_HBDS | EFI_AHCI_PORT_IS_HBFS | EFI_AH= CI_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) // --=20 2.28.0.windows.1 --------------------------------------------------------------------- Intel Technology Poland sp. z o.o. ul. Sowackiego 173 | 80-298 Gdask | Sd Rejonowy Gdask Pnoc | VII Wydzia Gos= podarczy Krajowego Rejestru Sdowego - KRS 101882 | NIP 957-07-52-316 | Kapi= ta zakadowy 200.000 PLN. Ta wiadomo wraz z zacznikami jest przeznaczona dla okrelonego adresata i mo= e zawiera informacje poufne. W razie przypadkowego otrzymania tej wiadomoci= , prosimy o powiadomienie nadawcy oraz trwae jej usunicie; jakiekolwiek prz= egldanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the s= ole use of the intended recipient(s). If you are not the intended recipient= , please contact the sender and delete all copies; any review or distributi= on by others is strictly prohibited. =20 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#67034): https://edk2.groups.io/g/devel/message/67034 Mute This Topic: https://groups.io/mt/78049727/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 17:57:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+67035+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+67035+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1604580101; cv=none; d=zohomail.com; s=zohoarc; b=ARxnPFLBEQi9s8On6uFyeQV3ciW/OVGz6HgxsJPG32Bnw1tV3plA2OWL+2M4Z+D2qdokJsqhU/a9Oz8txs4dVYyASJ6DC3/ZBLGFLOZpRz5ncQO7RYkSXxrIkRCcddsX/sgc6iiskN5Mn3VrrfeImhAxGXIQ+dR3V8SLE1MGOYA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604580101; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=2I+Bprk0eKeLX+Kb/DyziXzJ5tOUwbGOGqzicfb+B38=; b=npMMRHjATqkfEsH6U7KnngwxAtGrB8lZPF/XDP+6HVV0VH28bqR70mcA8lwrSk+zy6HAF3LjbTsmr1qI3THWRQqZq8r7KHCmpiYhOc8793TeiW7iGaY68aBb6D7swhSRV1P5bdxaQV8xRW5LbqFOjauN76zoXPsbiGtOJQP6aEM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+67035+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1604580101357377.28950223821346; Thu, 5 Nov 2020 04:41:41 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id jG9nYY1788612xMrhDF8xivx; Thu, 05 Nov 2020 04:41:40 -0800 X-Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web08.6941.1604580100503308618 for ; Thu, 05 Nov 2020 04:41:40 -0800 IronPort-SDR: dOu2FXVpBfac7QlKvnaCmEI3Ki7JZURjIFhZhuKDrXKkwE2JOaLjbFHzpGfVLrarXujAHZXzD3 mCZIw4HYzgcw== X-IronPort-AV: E=McAfee;i="6000,8403,9795"; a="254080655" X-IronPort-AV: E=Sophos;i="5.77,453,1596524400"; d="scan'208";a="254080655" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2020 04:41:40 -0800 IronPort-SDR: 7qPFYJ6YwaxHOfwupyUyIRnpyNV3kzKRF8tiLmnoK/lV/FEd9ZXA8W4WkKAitDeCHmLtovxqlO zl5M9udwDrrw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,453,1596524400"; d="scan'208";a="527949746" X-Received: from gklab-27-32.ger.corp.intel.com ([10.102.28.45]) by fmsmga006.fm.intel.com with ESMTP; 05 Nov 2020 04:41:38 -0800 From: "Albecki, Mateusz" To: devel@edk2.groups.io Cc: Mateusz Albecki , Ray Ni , Hao A Wu Subject: [edk2-devel] [PATCH v2 2/4] MdeModulePkg/AtaAtapiPassThru: Add SATA error recovery flow Date: Thu, 5 Nov 2020 13:40:44 +0100 Message-Id: <20201105124046.3744-3-mateusz.albecki@intel.com> In-Reply-To: <20201105124046.3744-1-mateusz.albecki@intel.com> References: <20201105124046.3744-1-mateusz.albecki@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,mateusz.albecki@intel.com X-Gm-Message-State: SXDeJqWx87wlGPSNJ1ZpfFE4x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1604580100; bh=J6WVmoQB/FiD4jUVQ9OopUVQKh1jRaHDcADzBf2qVBo=; h=Cc:Date:From:Reply-To:Subject:To; b=Yk+8NAOfpI9FtgKKaW/dSkWgr4lz14X8NX99z/8dKn/UjumnUSRUEjZa9DJOFeHBCiw CRWQo6Xpka9LitzC2k48bScPsNwgPhAajC+Ff+uhgHAQWInXsgnwJvTghAlxUPrJfrVo0 7BXwGOSerD6IWArEyti04iTLSigzj4jWt/I= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This commit adds error recovery flow on SATA port when the error condition is reported. Commit only implements SATA port reset flow which is executed when PxTFD indicates BSY or DRQ. Commit does not implement HBA level reset. Signed-off-by: Mateusz Albecki Cc: Ray Ni Cc: Hao A Wu --- .../Bus/Ata/AtaAtapiPassThru/AhciMode.c | 178 +++++++++++++++--- .../Bus/Ata/AtaAtapiPassThru/AhciMode.h | 5 +- 2 files changed, 159 insertions(+), 24 deletions(-) diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c b/MdeModulePk= g/Bus/Ata/AtaAtapiPassThru/AhciMode.c index 180a60b5aa..0b7141c4f1 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c @@ -608,6 +608,148 @@ AhciBuildCommandFis ( CmdFis->AhciCFisDevHead =3D (UINT8) (AtaCommandBlock->AtaDeviceHead = | 0xE0); } =20 +/** + Wait until SATA device reports it is ready for operation. + + @param[in] PciIo Pointer to AHCI controller PciIo. + @param[in] Port SATA port index on which to reset. + + @retval EFI_SUCCESS Device ready for operation. + @retval EFI_TIMEOUT Device failed to get ready within required period. +**/ +EFI_STATUS +AhciWaitDeviceReady ( + IN EFI_PCI_IO_PROTOCOL *PciIo, + IN UINT8 Port + ) +{ + UINT32 PhyDetectDelay; + UINT32 Data; + UINT32 Offset; + + // + // According to SATA1.0a spec section 5.2, we need to wait for PxTFD.BSY= and PxTFD.DRQ + // and PxTFD.ERR to be zero. The maximum wait time is 16s which is defin= ed at ATA spec. + // + PhyDetectDelay =3D 16 * 1000; + do { + Offset =3D EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + EFI_= AHCI_PORT_SERR; + if (AhciReadReg(PciIo, Offset) !=3D 0) { + AhciWriteReg (PciIo, Offset, AhciReadReg(PciIo, Offset)); + } + Offset =3D EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + EFI_= AHCI_PORT_TFD; + + Data =3D AhciReadReg (PciIo, Offset) & EFI_AHCI_PORT_TFD_MASK; + if (Data =3D=3D 0) { + break; + } + + MicroSecondDelay (1000); + PhyDetectDelay--; + } while (PhyDetectDelay > 0); + + if (PhyDetectDelay =3D=3D 0) { + DEBUG ((DEBUG_ERROR, "Port %d Device not ready (TFD=3D0x%X)\n", Port, = Data)); + return EFI_TIMEOUT; + } else { + return EFI_SUCCESS; + } +} + + +/** + Reset the SATA port. Algorithm follows AHCI spec 1.3.1 section 10.4.2 + + @param[in] PciIo Pointer to AHCI controller PciIo. + @param[in] Port SATA port index on which to reset. + + @retval EFI_SUCCESS Port reset. + @retval Others Failed to reset the port. +**/ +EFI_STATUS +AhciResetPort ( + IN EFI_PCI_IO_PROTOCOL *PciIo, + IN UINT8 Port + ) +{ + UINT32 Offset; + EFI_STATUS Status; + + Offset =3D EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + EFI_AH= CI_PORT_SCTL; + AhciOrReg (PciIo, Offset, EFI_AHCI_PORT_SCTL_DET_INIT); + // + // SW is required to keep DET set to 0x1 at least for 1 milisecond to en= sure that + // at least one COMRESET signal is sent. + // + MicroSecondDelay(1000); + AhciAndReg (PciIo, Offset, ~(UINT32)EFI_AHCI_PORT_SSTS_DET_MASK); + + Offset =3D EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + EFI_AH= CI_PORT_SSTS; + Status =3D AhciWaitMmioSet (PciIo, Offset, EFI_AHCI_PORT_SSTS_DET_MASK, = EFI_AHCI_PORT_SSTS_DET_PCE, ATA_ATAPI_TIMEOUT); + if (EFI_ERROR (Status)) { + return Status; + } + + return AhciWaitDeviceReady (PciIo, Port); +} + +/** + Recovers the SATA port from error condition. + This function implements algorithm described in + AHCI spec 1.3.1 section 6.2.2 + + @param[in] PciIo Pointer to AHCI controller PciIo. + @param[in] Port SATA port index on which to check. + + @retval EFI_SUCCESS Port recovered. + @retval Others Failed to recover port. +**/ +EFI_STATUS +AhciRecoverPortError ( + IN EFI_PCI_IO_PROTOCOL *PciIo, + IN UINT8 Port + ) +{ + UINT32 Offset; + UINT32 PortInterrupt; + UINT32 PortTfd; + EFI_STATUS Status; + + Offset =3D EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + EFI_AH= CI_PORT_IS; + PortInterrupt =3D AhciReadReg (PciIo, Offset); + if ((PortInterrupt & EFI_AHCI_PORT_IS_FATAL_ERROR_MASK) =3D=3D 0) { + // + // No fatal error detected. Exit with success as port should still be = operational. + // No need to clear IS as it will be cleared when the next command sta= rts. + // + return EFI_SUCCESS; + } + + Offset =3D EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + EFI_AH= CI_PORT_CMD; + AhciAndReg (PciIo, Offset, ~(UINT32)EFI_AHCI_PORT_CMD_ST); + + Status =3D AhciWaitMmioSet (PciIo, Offset, EFI_AHCI_PORT_CMD_CR, 0, ATA_= ATAPI_TIMEOUT); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Ahci port %d is in hung state, aborting recovery= \n", Port)); + return Status; + } + + // + // If TFD.BSY or TFD.DRQ is still set it means that drive is hung and so= ftware has + // to reset it before sending any additional commands. + // + Offset =3D EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + EFI_AH= CI_PORT_TFD; + PortTfd =3D AhciReadReg (PciIo, Offset); + if ((PortTfd & (EFI_AHCI_PORT_TFD_BSY | EFI_AHCI_PORT_TFD_DRQ)) !=3D 0) { + Status =3D AhciResetPort (PciIo, Port); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to reset the port %d\n", Port)); + } + } + + return EFI_SUCCESS; +} + /** Checks if specified FIS has been received. =20 @@ -827,6 +969,10 @@ AhciPioTransfer ( Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, SataFisD2H); } =20 + if (Status =3D=3D EFI_DEVICE_ERROR) { + AhciRecoverPortError (PciIo, Port); + } + Exit: AhciStopCommand ( PciIo, @@ -1007,6 +1153,10 @@ AhciDmaTransfer ( Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, SataFisD2H); } =20 + if (Status =3D=3D EFI_DEVICE_ERROR) { + AhciRecoverPortError (PciIo, Port); + } + Exit: // // For Blocking mode, the command should be stopped, the Fis should be d= isabled @@ -1119,6 +1269,9 @@ AhciNonDataTransfer ( } =20 Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, SataFisD2H); + if (Status =3D=3D EFI_DEVICE_ERROR) { + AhciRecoverPortError (PciIo, Port); + } =20 Exit: AhciStopCommand ( @@ -2583,29 +2736,8 @@ AhciModeInitialization ( continue; } =20 - // - // According to SATA1.0a spec section 5.2, we need to wait for PxTFD= .BSY and PxTFD.DRQ - // and PxTFD.ERR to be zero. The maximum wait time is 16s which is d= efined at ATA spec. - // - PhyDetectDelay =3D 16 * 1000; - do { - Offset =3D EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + = EFI_AHCI_PORT_SERR; - if (AhciReadReg(PciIo, Offset) !=3D 0) { - AhciWriteReg (PciIo, Offset, AhciReadReg(PciIo, Offset)); - } - Offset =3D EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + = EFI_AHCI_PORT_TFD; - - Data =3D AhciReadReg (PciIo, Offset) & EFI_AHCI_PORT_TFD_MASK; - if (Data =3D=3D 0) { - break; - } - - MicroSecondDelay (1000); - PhyDetectDelay--; - } while (PhyDetectDelay > 0); - - if (PhyDetectDelay =3D=3D 0) { - DEBUG ((EFI_D_ERROR, "Port %d Device presence detected but phy not= ready (TFD=3D0x%X)\n", Port, Data)); + Status =3D AhciWaitDeviceReady (PciIo, Port); + if (EFI_ERROR (Status)) { continue; } =20 diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h b/MdeModulePk= g/Bus/Ata/AtaAtapiPassThru/AhciMode.h index 6bcff1bb7b..338447a55f 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h @@ -114,6 +114,7 @@ typedef union { #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 | EF= I_AHCI_PORT_IS_IFS | EFI_AHCI_PORT_IS_HBDS | EFI_AHCI_PORT_IS_HBFS | EFI_AH= CI_PORT_IS_TFES) +#define EFI_AHCI_PORT_IS_FATAL_ERROR_MASK (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 @@ -122,9 +123,11 @@ typedef union { #define EFI_AHCI_PORT_CMD_SUD BIT1 #define EFI_AHCI_PORT_CMD_POD BIT2 #define EFI_AHCI_PORT_CMD_CLO BIT3 -#define EFI_AHCI_PORT_CMD_CR BIT15 #define EFI_AHCI_PORT_CMD_FRE BIT4 +#define EFI_AHCI_PORT_CMD_CCS_MASK (BIT8 | BIT9 | BIT10 | BIT1= 1 | BIT12) +#define EFI_AHCI_PORT_CMD_CCS_SHIFT 8 #define EFI_AHCI_PORT_CMD_FR BIT14 +#define EFI_AHCI_PORT_CMD_CR BIT15 #define EFI_AHCI_PORT_CMD_MASK ~(EFI_AHCI_PORT_CMD_ST | EF= I_AHCI_PORT_CMD_FRE | EFI_AHCI_PORT_CMD_COL) #define EFI_AHCI_PORT_CMD_PMA BIT17 #define EFI_AHCI_PORT_CMD_HPCP BIT18 --=20 2.28.0.windows.1 --------------------------------------------------------------------- Intel Technology Poland sp. z o.o. ul. Sowackiego 173 | 80-298 Gdask | Sd Rejonowy Gdask Pnoc | VII Wydzia Gos= podarczy Krajowego Rejestru Sdowego - KRS 101882 | NIP 957-07-52-316 | Kapi= ta zakadowy 200.000 PLN. Ta wiadomo wraz z zacznikami jest przeznaczona dla okrelonego adresata i mo= e zawiera informacje poufne. W razie przypadkowego otrzymania tej wiadomoci= , prosimy o powiadomienie nadawcy oraz trwae jej usunicie; jakiekolwiek prz= egldanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the s= ole use of the intended recipient(s). If you are not the intended recipient= , please contact the sender and delete all copies; any review or distributi= on by others is strictly prohibited. =20 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#67035): https://edk2.groups.io/g/devel/message/67035 Mute This Topic: https://groups.io/mt/78049731/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 17:57:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+67036+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+67036+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1604580116; cv=none; d=zohomail.com; s=zohoarc; b=GlHQavYtULxlY1aNIVuWZ3ZFJkBDpm4iUERZOM2YXwL/o/2Rgs1QohxV7pKNyF+5fnki84uoLlnKYIBs8lQ/o7L75EED3bCAwLLubw891xjQSSOa3vVwfp4SvBjwPnCxXRLjg7Ux7HxgfrXKeQDmFakrp1ujUO5Is1biGuVYM5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604580116; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=lVxYDNC5shmV5W2ERpSwR0R0x8ELvCbo4EJsl8siFzQ=; b=WXIfDwcLhHMeZsYfmcm2gmzL+7QMuiPV8CwMvDzl05ifdfGcxmAXGEI7Hs0Lk9KQx17hhkpcT+cpxV3pvEU6VVp1+/pAeVyD6PLKq7+0UR5uFW5E3Vocx3RQ8jxANR6hgoojVIf22jGhNYCsXDMd1tNVrnQkmaaNOliJ27zArDg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+67036+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1604580116390984.8249132479746; Thu, 5 Nov 2020 04:41:56 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id uWIvYY1788612xUnj3lkH9Z1; Thu, 05 Nov 2020 04:41:54 -0800 X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web08.6944.1604580114483596974 for ; Thu, 05 Nov 2020 04:41:54 -0800 IronPort-SDR: lDvrFW9bDZnZqSr98rJy7dFvljdJZrZPGlnw+KQ1RyVrkRjXGgIMisjws9K3PczDoMZZkX0Yzi XiJM+CJSB4Vg== X-IronPort-AV: E=McAfee;i="6000,8403,9795"; a="187281457" X-IronPort-AV: E=Sophos;i="5.77,453,1596524400"; d="scan'208";a="187281457" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2020 04:41:53 -0800 IronPort-SDR: uSL/4VV58E60rP8draX1QuiToBh4rooErgowwUz5denJvucpXoHwn08pfAndPYl5pl7wlyv4PK 8WQSmbSdh4Tw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,453,1596524400"; d="scan'208";a="527949793" X-Received: from gklab-27-32.ger.corp.intel.com ([10.102.28.45]) by fmsmga006.fm.intel.com with ESMTP; 05 Nov 2020 04:41:52 -0800 From: "Albecki, Mateusz" To: devel@edk2.groups.io Cc: Mateusz Albecki , Ray Ni , Hao A Wu Subject: [edk2-devel] [PATCH v2 3/4] MdeModulePkg/AtaAtapiPassThru: Restart failed packets Date: Thu, 5 Nov 2020 13:40:45 +0100 Message-Id: <20201105124046.3744-4-mateusz.albecki@intel.com> In-Reply-To: <20201105124046.3744-1-mateusz.albecki@intel.com> References: <20201105124046.3744-1-mateusz.albecki@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,mateusz.albecki@intel.com X-Gm-Message-State: ikV0EaxPaTkbkGLVIADkWV4Ux1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1604580114; bh=uMKxQh2bqxMpfODAzklX0DUHDuqSYAiSXqBQejFrmLE=; h=Cc:Date:From:Reply-To:Subject:To; b=IgnKK7vDBcNLMon9kOsj2z4MjYWiNswcJP7em28mU8syxETdaTCp/352i4AQumUtOg1 3z+W9F7ojr4/zau3tXJgr5PfjCx53InM67OkmK4v+oiUyALouXygyobOaZ1fXDp/VyQ9k 3o215Uq9BFPvFzrn2/wQjYj3QelybT9abnU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This commit adds code to restart the ATA packets that failed due to the CRC error or other link condition. For sync transfers the code will try to get 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 reached. For sync case the count of 5 retries has been chosen arbitrarily and if needed can be increased or decreased. Signed-off-by: Mateusz Albecki 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(-) diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c b/MdeModulePk= g/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, SataFisPioS= etup); - if (Status =3D=3D EFI_SUCCESS) { - PrdCount =3D *(volatile UINT32 *) (&(AhciRegisters->AhciCmdList[0].A= hciCmdPrdbc)); - 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, 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; + } } + } else { + Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, SataFisD2= H); } - } else { - Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, SataFisD2H); - } =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 no= n-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 a= sync + // DMA transfers irrespective of number of retries. // - OldTpl =3D gBS->RaiseTPL (TPL_NOTIFY); - while ((Task =3D=3D NULL) && (!IsListEmpty (&Instance->NonBlockingTaskLi= st))) { - 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 all = 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, SataFisD2= H); + 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, SataFisD2H); - } + 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->Re= tryTimes)); + Status =3D AhciRecoverPortError (PciIo, Port); + // + // If recovery passed mark the Task as not started and change the = status + // to EFI_NOT_READY. This will make the higher level call this fun= ction again + // and on next call the command will be re-issued due to IsStart b= eing 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 d= isabled // 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, SataFisD2H); + 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/MdeModulePk= g/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. --=20 2.28.0.windows.1 --------------------------------------------------------------------- Intel Technology Poland sp. z o.o. ul. Sowackiego 173 | 80-298 Gdask | Sd Rejonowy Gdask Pnoc | VII Wydzia Gos= podarczy Krajowego Rejestru Sdowego - KRS 101882 | NIP 957-07-52-316 | Kapi= ta zakadowy 200.000 PLN. Ta wiadomo wraz z zacznikami jest przeznaczona dla okrelonego adresata i mo= e zawiera informacje poufne. W razie przypadkowego otrzymania tej wiadomoci= , prosimy o powiadomienie nadawcy oraz trwae jej usunicie; jakiekolwiek prz= egldanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the s= ole use of the intended recipient(s). If you are not the intended recipient= , please contact the sender and delete all copies; any review or distributi= on by others is strictly prohibited. =20 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#67036): https://edk2.groups.io/g/devel/message/67036 Mute This Topic: https://groups.io/mt/78049737/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Nov 25 17:57:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+67037+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+67037+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1604580117; cv=none; d=zohomail.com; s=zohoarc; b=duP/PUVb28anDGOxDGGIijbm7X+9TKk7P/q4nZXo5xNZ6MuSmkDKNZ9/kw5erEj3uDX+k9YZQnSiXkgGrC9RFkOVc/472PnJ4jVicAnIPnwBeq8mUvOD4xpRwwdv+ous0IunOXFPyyH4EU+OHIZRjJUFCvMjPF2MdVksgHeZzuM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604580117; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=j/UUcq79o2RkRdSQKwRjABgbiN1WPHd3bCr2r3ohC/k=; b=PuKNChdeMjae+qI5RW0xNvNHIQwURPFG1SqnIixt2s01ukAqN+WEkfAEAwYDgIuW1HMILLASq1QjOFzI/PdmgkO+EsWcsQX80pGkvjvehziJHgK2u86yO4bsgG3QDXWt92Dnjg0D/sEXQk1xLg1xvxbTaTayyzF4HvxWtdMtefY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+67037+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1604580117276671.2986727188032; Thu, 5 Nov 2020 04:41:57 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5BspYY1788612xxGvRk5MgU9; Thu, 05 Nov 2020 04:41:56 -0800 X-Received: from mga01.intel.com (mga01.intel.com []) by mx.groups.io with SMTP id smtpd.web08.6944.1604580114483596974 for ; Thu, 05 Nov 2020 04:41:56 -0800 IronPort-SDR: 20I11y6DTtT1XEX+US8//XZ7S8xHhLwgMM9Zr7GFPm/1F1mGIu+GU9ouGTTWZq2333oNGmhrQN trE6KKxK6czg== X-IronPort-AV: E=McAfee;i="6000,8403,9795"; a="187281468" X-IronPort-AV: E=Sophos;i="5.77,453,1596524400"; d="scan'208";a="187281468" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2020 04:41:55 -0800 IronPort-SDR: AUhZz/nkJe4Uz9n36x8wE7lg8zG0swsAUPcu29uGBiyg2vthjZoglAQtbkUsWuR+oaeWlnK6gA NH684DlXKQjQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,453,1596524400"; d="scan'208";a="527949806" X-Received: from gklab-27-32.ger.corp.intel.com ([10.102.28.45]) by fmsmga006.fm.intel.com with ESMTP; 05 Nov 2020 04:41:54 -0800 From: "Albecki, Mateusz" To: devel@edk2.groups.io Cc: Mateusz Albecki , Ray Ni , Hao A Wu Subject: [edk2-devel] [PATCH v2 4/4] MdeModulePkg/AtaAtapiPassThru: Trace ATA packets Date: Thu, 5 Nov 2020 13:40:46 +0100 Message-Id: <20201105124046.3744-5-mateusz.albecki@intel.com> In-Reply-To: <20201105124046.3744-1-mateusz.albecki@intel.com> References: <20201105124046.3744-1-mateusz.albecki@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,mateusz.albecki@intel.com X-Gm-Message-State: dZCIyEerk9RBKaBwUd7irdi6x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1604580116; bh=K3Q064u82yoBKf8LeO5qQbTptMGO1k1Oh6kLW+qR+MA=; h=Cc:Date:From:Reply-To:Subject:To; b=b6YTyuuBNVHsnQdLRywjkBe2HQhdF39enWx/6b9lqZgQJ5Z5AfW0o3TvLokB2KpASe6 /E7ocN27iwDhv3dKd1DzSonIn5PR5n8e6yx9pYuXlMqQ1oBKc1bkbT/CR85VAdI9wZy+d WUJXjEG2l9ufUWUiWzfWys6yhiul/0ipMcU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This simplify ATA driver debugging all ATA packets will be printed to debug port on DEBUG_VERBOSE level along with the packet execution status. Additionally failed packets and the failed packet execution status will be printed on DEBUG_ERROR level. Signed-off-by: Mateusz Albecki Cc: Ray Ni Cc: Hao A Wu --- .../Bus/Ata/AtaAtapiPassThru/AhciMode.c | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c b/MdeModulePk= g/Bus/Ata/AtaAtapiPassThru/AhciMode.c index 47275a851a..e506c8f2d5 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c @@ -846,6 +846,54 @@ AhciWaitUntilFisReceived ( return EFI_TIMEOUT; } =20 +/** + Prints contents of the ATA command block into the debug port. + + @param[in] AtaCommandBlock AtaCommandBlock to print. + @param[in] DebugLevel Debug level on which to print. +**/ +VOID +AhciPrintCommandBlock ( + IN EFI_ATA_COMMAND_BLOCK *AtaCommandBlock, + IN UINT32 DebugLevel + ) +{ + DEBUG ((DebugLevel, "ATA COMMAND BLOCK:\n")); + DEBUG ((DebugLevel, "AtaCommand: %d\n", AtaCommandBlock->AtaCommand)); + DEBUG ((DebugLevel, "AtaFeatures: %X\n", AtaCommandBlock->AtaFeatures)); + DEBUG ((DebugLevel, "AtaSectorNumber: %d\n", AtaCommandBlock->AtaSectorN= umber)); + DEBUG ((DebugLevel, "AtaCylinderLow: %X\n", AtaCommandBlock->AtaCylinder= High)); + DEBUG ((DebugLevel, "AtaCylinderHigh: %X\n", AtaCommandBlock->AtaCylinde= rHigh)); + DEBUG ((DebugLevel, "AtaDeviceHead: %d\n", AtaCommandBlock->AtaDeviceHea= d)); + DEBUG ((DebugLevel, "AtaSectorNumberExp: %d\n", AtaCommandBlock->AtaSect= orNumberExp)); + DEBUG ((DebugLevel, "AtaCylinderLowExp: %X\n", AtaCommandBlock->AtaCylin= derLowExp)); + DEBUG ((DebugLevel, "AtaCylinderHighExp: %X\n", AtaCommandBlock->AtaCyli= nderHighExp)); + DEBUG ((DebugLevel, "AtaFeaturesExp: %X\n", AtaCommandBlock->AtaFeatures= Exp)); + DEBUG ((DebugLevel, "AtaSectorCount: %d\n", AtaCommandBlock->AtaSectorCo= unt)); + DEBUG ((DebugLevel, "AtaSectorCountExp: %d\n", AtaCommandBlock->AtaSecto= rCountExp)); +} + +/** + Prints contents of the ATA status block into the debug port. + + @param[in] AtaStatusBlock AtaStatusBlock to print. + @param[in] DebugLevel Debug level on which to print. +**/ +VOID +AhciPrintStatusBlock ( + IN EFI_ATA_STATUS_BLOCK *AtaStatusBlock, + IN UINT32 DebugLevel + ) +{ + // + // Only print status and error since we have all of the rest printed as + // a part of command block print. + // + DEBUG ((DebugLevel, "ATA STATUS BLOCK:\n")); + DEBUG ((DebugLevel, "AtaStatus: %d\n", AtaStatusBlock->AtaStatus)); + DEBUG ((DebugLevel, "AtaError: %d\n", AtaStatusBlock->AtaError)); +} + /** Start a PIO data transfer on specific port. =20 @@ -947,6 +995,8 @@ AhciPioTransfer ( DataCount ); =20 + DEBUG ((DEBUG_VERBOSE, "Starting command for PIO transfer:\n")); + AhciPrintCommandBlock (AtaCommandBlock, DEBUG_VERBOSE); Status =3D AhciStartCommand ( PciIo, Port, @@ -1000,6 +1050,19 @@ AhciPioTransfer ( ); =20 AhciDumpPortStatus (PciIo, AhciRegisters, Port, AtaStatusBlock); + + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "Failed to execute command: for PIO transfer\n")); + // + // Repeat command block here to make sure it is printed on + // device error debug level. + // + AhciPrintCommandBlock (AtaCommandBlock, DEBUG_ERROR); + AhciPrintStatusBlock (AtaStatusBlock, DEBUG_ERROR); + } else { + AhciPrintStatusBlock (AtaStatusBlock, DEBUG_VERBOSE); + } + return Status; } =20 @@ -1132,6 +1195,8 @@ AhciDmaTransfer ( DataCount ); =20 + DEBUG ((DEBUG_VERBOSE, "Starting command for sync DMA transfer:\n")); + AhciPrintCommandBlock (AtaCommandBlock, DEBUG_VERBOSE); Status =3D AhciStartCommand ( PciIo, Port, @@ -1168,6 +1233,8 @@ AhciDmaTransfer ( DataCount ); =20 + DEBUG ((DEBUG_VERBOSE, "Starting command for async DMA transfer:\n")= ); + AhciPrintCommandBlock (AtaCommandBlock, DEBUG_VERBOSE); Status =3D AhciStartCommand ( PciIo, Port, @@ -1238,6 +1305,19 @@ AhciDmaTransfer ( } =20 AhciDumpPortStatus (PciIo, AhciRegisters, Port, AtaStatusBlock); + + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "Failed to execute command for DMA transfer:\n")); + // + // Repeat command block here to make sure it is printed on + // device error debug level. + // + AhciPrintCommandBlock (AtaCommandBlock, DEBUG_ERROR); + AhciPrintStatusBlock (AtaStatusBlock, DEBUG_ERROR); + } else { + AhciPrintStatusBlock (AtaStatusBlock, DEBUG_VERBOSE); + } + return Status; } =20 @@ -1307,6 +1387,8 @@ AhciNonDataTransfer ( 0 ); =20 + DEBUG ((DEBUG_VERBOSE, "Starting command for non data transfer:\n")); + AhciPrintCommandBlock (AtaCommandBlock, DEBUG_VERBOSE); Status =3D AhciStartCommand ( PciIo, Port, @@ -1343,6 +1425,18 @@ AhciNonDataTransfer ( =20 AhciDumpPortStatus (PciIo, AhciRegisters, Port, AtaStatusBlock); =20 + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "Failed to execute command for non data transfer:= \n")); + // + // Repeat command block here to make sure it is printed on + // device error debug level. + // + AhciPrintCommandBlock (AtaCommandBlock, DEBUG_ERROR); + AhciPrintStatusBlock (AtaStatusBlock, DEBUG_ERROR); + } else { + AhciPrintStatusBlock (AtaStatusBlock, DEBUG_VERBOSE); + } + return Status; } =20 --=20 2.28.0.windows.1 --------------------------------------------------------------------- Intel Technology Poland sp. z o.o. ul. Sowackiego 173 | 80-298 Gdask | Sd Rejonowy Gdask Pnoc | VII Wydzia Gos= podarczy Krajowego Rejestru Sdowego - KRS 101882 | NIP 957-07-52-316 | Kapi= ta zakadowy 200.000 PLN. Ta wiadomo wraz z zacznikami jest przeznaczona dla okrelonego adresata i mo= e zawiera informacje poufne. W razie przypadkowego otrzymania tej wiadomoci= , prosimy o powiadomienie nadawcy oraz trwae jej usunicie; jakiekolwiek prz= egldanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the s= ole use of the intended recipient(s). If you are not the intended recipient= , please contact the sender and delete all copies; any review or distributi= on by others is strictly prohibited. =20 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#67037): https://edk2.groups.io/g/devel/message/67037 Mute This Topic: https://groups.io/mt/78049738/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-