From nobody Mon Nov 25 20:37:13 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-