From nobody Sun May 12 23:46:39 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+66923+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+66923+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1604409851; cv=none; d=zohomail.com; s=zohoarc; b=N6yZYYfljgsNDZAE1Fo0vGSt3+Eff34AJrUg5IjYa+NxviTmcsKh4uK9PPEzgm/hCDjU66WR2qRQqF99bhEGCPM2B3mEKGQbR/4X/e5iR0/FC5OJiBnjkSvebkOXqS+jkQ3xaNrTgsVJaG4saBSzMgX65ZbnEkCFsRNr3TdVKyI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604409851; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=UOe2SdMeaQL9QDEncE4VbBDcyPAxqKF8NBWrhuyHU8A=; b=PYbK8+4CeqQDgDm53D6uUMLuZ+r87Xd+gIdSaXeM92Ty9wHMTviaRCrarIlimGCk48DR7fToJHm0aSPXvKTIpt4/xmf/NyIRGRac8q0EFNlptKlfOi38ufWpFOPez8SEMMqlBOeP8c3hE3KqeNSB7g+m8D9CGoSd5A8WM8gFYMw= 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+66923+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 1604409851627188.5721772601279; Tue, 3 Nov 2020 05:24:11 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id aZ1vYY1788612xrhueFmG2Od; Tue, 03 Nov 2020 05:24:11 -0800 X-Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web11.3908.1604409850765584058 for ; Tue, 03 Nov 2020 05:24:10 -0800 IronPort-SDR: V+WxzXuhJlBWJLY462pHZv7No8TpCA1FzS2MjVHlKJiSq1kjWZ6KWu01jvHjNJg9XGRV+aNbhb sXjXt/Ji+I9A== X-IronPort-AV: E=McAfee;i="6000,8403,9793"; a="169155207" X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="169155207" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 05:24:08 -0800 IronPort-SDR: feDTFAe9bh7aU2mVVtivaB9szbQdK3Ur2wekpNgy/WRKXcJC+3yXatNbR10CDukUhuGkL5d40r d5wXE+cfmz3g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="363023594" X-Received: from gklab-27-32.ger.corp.intel.com ([10.102.28.45]) by FMSMGA003.fm.intel.com with ESMTP; 03 Nov 2020 05:24:07 -0800 From: "Albecki, Mateusz" To: devel@edk2.groups.io Cc: Albecki , Ray Ni , Hao A Wu Subject: [edk2-devel] [PATCH 1/4] MdeModulePkg/AtaAtapiPassThru: Check IS to check for command completion Date: Tue, 3 Nov 2020 14:23:45 +0100 Message-Id: <20201103132348.2916-2-mateusz.albecki@intel.com> In-Reply-To: <20201103132348.2916-1-mateusz.albecki@intel.com> References: <20201103132348.2916-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: dCkjX4EkDH09s8FAKhh1Qvrfx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1604409851; bh=KS0veMlVGutrXpatNpyFZ4oFMU7Xz2PUljo0R7JPzDc=; h=Cc:Date:From:Reply-To:Subject:To; b=WaMAaktngISL0kXZkKJxAfw1H7o2b+l/z2uCpjdS8HDrQ5erDed8fvMydpXMDmOUe2T IWghTU6mo9jhZy34UC5Wo+/a55uqs6OYxPUNGZ7UTtuOSvHEBS385SHmsP90Pk40ZbzVV sjBHKsd2rpq/ws1ForYvhC56opsOTRocSLo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Albecki BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3024 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 Reviewed-by: Hao A Wu --- .../Bus/Ata/AtaAtapiPassThru/AhciMode.c | 292 ++++++++---------- .../Bus/Ata/AtaAtapiPassThru/AhciMode.h | 9 +- 2 files changed, 131 insertions(+), 170 deletions(-) diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c b/MdeModulePk= g/Bus/Ata/AtaAtapiPassThru/AhciMode.c index 7e2fade400..4b42e72226 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c @@ -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. - - @retval EFI_NOTREADY The memory is not set. - @retval EFI_TIMEOUT The memory setting retry times out. - @retval EFI_SUCCESS The memory is correct set. + @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_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..a3cd351f6e 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h @@ -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 (#66923): https://edk2.groups.io/g/devel/message/66923 Mute This Topic: https://groups.io/mt/78005848/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 Sun May 12 23:46:39 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+66924+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+66924+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1604409853; cv=none; d=zohomail.com; s=zohoarc; b=Cav9REPllBFKixq6QSxHsR3TuoCz1RY6fT13HDPogUQ259HrywOyPdpPslX9sufLzLUo5DHqAcAhG6ca7UALTJkWq+1myY1f/AZIw+I5PXn4gOUeU6qQf+GXVavGjbu7tORA7sz0u9qhf6CcJR2jNRSftc3MFlBujNzSx68gEBU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604409853; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=LREVC1nmIz1nydgBdiHZwzV8vqlODRVVpbGM8N+PSUw=; b=W1e8nmIsyW+lCGVIflcKNRafaDxJmnIu8f/O3KJHY9L1BlDzMs2fC44MZLtTHzS/7ZBUHUK5G26VoZBL3fdzZe5RJ8X8xmUrayR+CVJCDg7jsfS8Pftw9/9jvlrVKhoooaa+hEnXWyn4hA2bsfNxPM7fpVTRr+C07n7OelG2a1E= 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+66924+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 1604409853262211.47021836292015; Tue, 3 Nov 2020 05:24:13 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9npxYY1788612xTvt76QUBOX; Tue, 03 Nov 2020 05:24:12 -0800 X-Received: from mga03.intel.com (mga03.intel.com []) by mx.groups.io with SMTP id smtpd.web11.3908.1604409850765584058 for ; Tue, 03 Nov 2020 05:24:12 -0800 IronPort-SDR: lflwP7qR09t85+/tEuXlqru+S8W/RawQtkbyGoxmZjw+84CYy+onhXTf0wy8sw5bdL/gQNCK3q IT3mAPbouxHg== X-IronPort-AV: E=McAfee;i="6000,8403,9793"; a="169155221" X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="169155221" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 05:24:11 -0800 IronPort-SDR: yMY4xLJ5IB9WYWL51tLPyECNQSfHkXj15iO0eZnBSFzxQcidnHhCVvScQFs0YXX19NnDgT8zF5 nM4AagjmNglQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="363023615" X-Received: from gklab-27-32.ger.corp.intel.com ([10.102.28.45]) by FMSMGA003.fm.intel.com with ESMTP; 03 Nov 2020 05:24:10 -0800 From: "Albecki, Mateusz" To: devel@edk2.groups.io Cc: Albecki , Ray Ni , Hao A Wu Subject: [edk2-devel] [PATCH 2/4] MdeModulePkg/AtaAtapiPassThru: Add SATA error recovery flow Date: Tue, 3 Nov 2020 14:23:46 +0100 Message-Id: <20201103132348.2916-3-mateusz.albecki@intel.com> In-Reply-To: <20201103132348.2916-1-mateusz.albecki@intel.com> References: <20201103132348.2916-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: T5Q11r6nDXi4M8DcSM1AepMkx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1604409852; bh=cUdyMF6Da8DVM6nF7mDSqLifOCR4J8sKjkzBgM+WxQg=; h=Cc:Date:From:Reply-To:Subject:To; b=rH9w+VTSv1A6+NvPNOYqJbD4IAX1MwCNrgkZ004hNzJDKZOClEdNF7+Ud7Fd4X6R4Ar mZSvxPW6hPxJUToVIVovG2LjjHV8t88lFx4QtaIp7ujondhebQedDEflDs0uAjOe63t6q XeuEjRybdi2Ff/9Q2gDuNR1Ze0beT6kbCto= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Albecki BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3025 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 Reviewed-by: 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 4b42e72226..cf735d5983 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 a3cd351f6e..4d2aafe483 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 (#66924): https://edk2.groups.io/g/devel/message/66924 Mute This Topic: https://groups.io/mt/78005850/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 Sun May 12 23:46:39 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+66925+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+66925+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1604409855; cv=none; d=zohomail.com; s=zohoarc; b=j8yPrhBsXJi2nlnL2EQb1mQt8JOTJxeyz1VGSvOc4YT/XVanqS8y4oTWv1ev0ClZv4NL5Im/aUAKRzr6OsGd6IEa/bCckFmhryWrxWd8PEGjowNncYBrqeI5jWe5LSdHeGorY7rHTPjYKKVRrLBuu8m6M+eJAgu/92H3LKHkni0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604409855; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=7A/el34vldM+IdJ33DjP4sJYNZT19tu9dUDDgInmfvc=; b=oArGeaY6lDTrOMU9zRMJ5KxmbSRQZaOAvzsndCikqwljE56bXuaSaMeniVGpd5Vw62wOgwP8k6EpITxEJfbWHGJWCoG/ITFFgVbapyw9qPvpDo0jAHPONDveeicqQOa7Ne/D9SpKCzPAyR8jZRN2qDVHV/jl/0oo+5qPiDW9gvo= 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+66925+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 1604409855674375.5926248294936; Tue, 3 Nov 2020 05:24:15 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id hSuKYY1788612xo4G6lJ09u4; Tue, 03 Nov 2020 05:24:15 -0800 X-Received: from mga03.intel.com (mga03.intel.com []) by mx.groups.io with SMTP id smtpd.web11.3908.1604409850765584058 for ; Tue, 03 Nov 2020 05:24:14 -0800 IronPort-SDR: NJnHRDg9s55M10V+i5CpJbkTRR2g37oQxIes87pBk1SxRPlzTwW4vnB6uI0eU2ZQYZqdMMZrcK d5lzlILKj5qw== X-IronPort-AV: E=McAfee;i="6000,8403,9793"; a="169155229" X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="169155229" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 05:24:14 -0800 IronPort-SDR: Y2+LFXKezjQ/OXDoSUZq++ATBPBWhpri/vEkDiudW9ZFtLux9ogW3gOFxIxKY3Q0aEifog6F23 BlDtor5xpXpA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="363023639" X-Received: from gklab-27-32.ger.corp.intel.com ([10.102.28.45]) by FMSMGA003.fm.intel.com with ESMTP; 03 Nov 2020 05:24:12 -0800 From: "Albecki, Mateusz" To: devel@edk2.groups.io Cc: Albecki , Ray Ni , Hao A Wu Subject: [edk2-devel] [PATCH 3/4] MdeModulePkg/AtaAtapiPassThru: Restart failed packets Date: Tue, 3 Nov 2020 14:23:47 +0100 Message-Id: <20201103132348.2916-4-mateusz.albecki@intel.com> In-Reply-To: <20201103132348.2916-1-mateusz.albecki@intel.com> References: <20201103132348.2916-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: gVRdre8dNCTzuZmryL0abLVox1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1604409855; bh=xMzrZl5VlGMx44eMzUciRtKFCMMbmlgehFAJtgj6DHQ=; h=Cc:Date:From:Reply-To:Subject:To; b=cXivd04KiscgLU1QMQkMb46VS+BIdXQweVdqRtV573e029c2l4TQB7Qtq1wNcLr1XK8 E9LyWUsawfi2a/Bro5I1kEUuxim4SIY5IjfMEZ7/PQFXJh3Mb05PoC5v8NSjylt4VwhrE sOBgCzEtvJt1cVjq/RqNd25YhSDlrBL62tg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Albecki BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3026 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 and for async in accordance to the RetryTimes field in Task structure. 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 cf735d5983..4fe7e4b1dc 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c @@ -897,6 +897,7 @@ AhciPioTransfer ( EFI_AHCI_COMMAND_FIS CFis; EFI_AHCI_COMMAND_LIST CmdList; UINT32 PrdCount; + UINT32 Retry; =20 if (Read) { Flag =3D EfiPciIoOperationBusMasterWrite; @@ -931,49 +932,56 @@ AhciPioTransfer ( CmdList.AhciCmdCfl =3D EFI_AHCI_FIS_REGISTER_H2D_LENGTH / 4; CmdList.AhciCmdW =3D Read ? 0 : 1; =20 - AhciBuildCommand ( - PciIo, - AhciRegisters, - Port, - PortMultiplier, - &CFis, - &CmdList, - AtapiCommand, - AtapiCommandLength, - 0, - (VOID *)(UINTN)PhyAddr, - DataCount - ); + for (Retry =3D 0; Retry < AHCI_COMMAND_RETRIES; Retry++) { + AhciBuildCommand ( + PciIo, + AhciRegisters, + Port, + PortMultiplier, + &CFis, + &CmdList, + AtapiCommand, + AtapiCommandLength, + 0, + (VOID *)(UINTN)PhyAddr, + DataCount + ); =20 - Status =3D AhciStartCommand ( - PciIo, - Port, - 0, - Timeout - ); - if (EFI_ERROR (Status)) { - goto Exit; - } + Status =3D AhciStartCommand ( + PciIo, + Port, + 0, + Timeout + ); + if (EFI_ERROR (Status)) { + break; + } =20 - if (Read && (AtapiCommand =3D=3D 0)) { - Status =3D AhciWaitUntilFisReceived (PciIo, Port, Timeout, 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 + ); =20 - if (Status =3D=3D EFI_DEVICE_ERROR) { - AhciRecoverPortError (PciIo, Port); + Status =3D AhciStartCommand ( + PciIo, + Port, + 0, + Timeout + ); + if (!EFI_ERROR (Status)) { + Task->IsStart =3D TRUE; + } + } + if (Task->IsStart) { + Status =3D AhciCheckFisReceived (PciIo, Port, SataFisD2H); + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "DMA command failed at retry: %d\n", Task->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; + } + } + + 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 4d2aafe483..0540b0f4fa 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.h @@ -192,6 +192,8 @@ typedef union { #define AHCI_PORT_DEVSLP_DITO_MASK 0x01FF8000 #define AHCI_PORT_DEVSLP_DM_MASK 0x1E000000 =20 +#define AHCI_COMMAND_RETRIES 5 + #pragma pack(1) // // Command List structure includes total 32 entries. --=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 (#66925): https://edk2.groups.io/g/devel/message/66925 Mute This Topic: https://groups.io/mt/78005851/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 Sun May 12 23:46:39 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+66926+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+66926+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1604409858; cv=none; d=zohomail.com; s=zohoarc; b=OiRgP5+aznJ+l8FzIzvAbAimK5RlapDSwqMj0SyAoCQJES5gQ5RTppM8phZt/19RApRkjFh7tlcMXvLtIg9igw7Yb3U+fUlm4F46rN8cJbad35X3njOBGgxwmMkikdKemEfuYt621w/kRnyefRru4M1FKrIBXZ86TOe7f42R0TQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604409858; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=5oBPbDVZAZdw5JZwwr92zYh2hgVZjsbjgZyJhurWukA=; b=Q/5XItTM/7P6eWwoDo9deulGgVSbrHsglkF6Q/ZBaUb2VCR5ILcvafpEW7bW17JI++ikHmiInuDdvYVZzz1393JS/6QWqU1/rkCbEXg1eOCPaFSot3NJMcyngkHeK2Y0h11htvrXsInnf3j4yaWnANtW9mFNJa9X2i9FZ9FUGQ8= 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+66926+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 1604409858209548.1038515980678; Tue, 3 Nov 2020 05:24:18 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id DX1cYY1788612xeGhbM1y5bb; Tue, 03 Nov 2020 05:24:17 -0800 X-Received: from mga03.intel.com (mga03.intel.com []) by mx.groups.io with SMTP id smtpd.web11.3908.1604409850765584058 for ; Tue, 03 Nov 2020 05:24:17 -0800 IronPort-SDR: ZNYQd6Kwqt7zvTllFkkJ1FHrRmLc11bjcmkSkmUT32CVDtafRYLNGttltk5aO290a320EHSOks q4axGt9Mkm/g== X-IronPort-AV: E=McAfee;i="6000,8403,9793"; a="169155239" X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="169155239" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 05:24:16 -0800 IronPort-SDR: c3iPYtL1jYeLdksiXuCVrHEUFJmsVa/cEYBGYf2u8PVvMzF9cnNcs5aK6yyFBLWVZ9KKWDK+uF uug4Aqu9u++w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="363023670" X-Received: from gklab-27-32.ger.corp.intel.com ([10.102.28.45]) by FMSMGA003.fm.intel.com with ESMTP; 03 Nov 2020 05:24:15 -0800 From: "Albecki, Mateusz" To: devel@edk2.groups.io Cc: Albecki , Ray Ni , Hao A Wu Subject: [edk2-devel] [PATCH 4/4] MdeModulePkg/AtaAtapiPassThru: Trace ATA packets Date: Tue, 3 Nov 2020 14:23:48 +0100 Message-Id: <20201103132348.2916-5-mateusz.albecki@intel.com> In-Reply-To: <20201103132348.2916-1-mateusz.albecki@intel.com> References: <20201103132348.2916-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: qZl2N8Bp3Ys4xFAVFgCIG4J5x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1604409857; bh=OfOY09BgBob4Qvz3pe9SS9P0sHRVwE8gqEcH852tZHo=; h=Cc:Date:From:Reply-To:Subject:To; b=iLOqPTjiHWRbWlsT1DHQa4SKG+RHL6113awuqNSMYRdjaGcaKlWNvTpCWm6bVTm154B OF46bz7GDMuNnPdpBIgWAowhSl+CmgNVtep0EIaanMve7yk0BgJde/twx9UvAYIIky0rU No5ZsxNU8r3kmG0mepIxVzGpc7xtKUrpmnw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Albecki 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 4fe7e4b1dc..3a7a6eb018 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 commmand: \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:\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 commmand: \n")); + AhciPrintCommandBlock (AtaCommandBlock, DEBUG_VERBOSE); Status =3D AhciStartCommand ( PciIo, Port, @@ -1168,6 +1233,8 @@ AhciDmaTransfer ( DataCount ); =20 + DEBUG ((DEBUG_VERBOSE, "Starting commmand: \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:\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 commmand: \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:\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 (#66926): https://edk2.groups.io/g/devel/message/66926 Mute This Topic: https://groups.io/mt/78005852/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-