From patchwork Mon Oct 21 12:49:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Eichenberger X-Patchwork-Id: 13844129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7E619D15D8B for ; Mon, 21 Oct 2024 13:03:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=3Q32sh+uJFSpt9TLvxk2ifmsRw8yfE9HNNl0na2PYAU=; b=NpF3GI0ilWR6ufEu/TJ19Jkqb7 w/apqEe9+0o9ekkiBYH6vXSN8xRZpN2g6u2cScqWbaUKaor7ETI58i/9VGMRziRwqMbMbJhetpeky ijGBcIgmAiaYFj5lWmpZJ9duPMmRooUNpNZgqdakOmFefbi1cGO2LRf5SK9B8JWW40gV0etb0GHKT DBPxge9laSEnfSyO3MDG6TS+7nKDACU/a0zosJM93i43LjyfIbN/tgVVk49jweLiZ4XOAueq1hxdl TH9T49f/KbTVjM3ITmgVEN0ZhCPfdkBjHOWXrJvmywe84doMiD29WqGQa4nD5KOEMLMEFQGmFqUJR cUz/qCFQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t2s4K-00000007MKj-0muK; Mon, 21 Oct 2024 13:03:32 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t2rqp-00000007K7T-0faP for linux-arm-kernel@bombadil.infradead.org; Mon, 21 Oct 2024 12:49:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=3Q32sh+uJFSpt9TLvxk2ifmsRw8yfE9HNNl0na2PYAU=; b=HSxvwKGbqq8Avme23k8VomuDO7 mwXrQPtSmURfXGMWzZFfxVF36bDFSk5F9AnFSc+vRFRtinhsGivVHJ3djXv7h1W/pbUm4S+nKwaqD 9FE4RHE17enYiBuT0ic0iVzridwRdiJTcisfQjsQNaLVFGcVF6IOmYvgF92hP5mZNsca4iPDMlLIP nn9FQeu4evOZGnyr7iTVZy0P2kgTZShqoFPwHXR+UeGLXPi5186h5t7xVYBDrpOwZUgkRhLpOznf9 18fIlzLUe05mak9aLRFBJR+GyBShJlykoCsFovw53Yl+nfpb6f6fcfL/SI7ZmDzzwhPNq8ic44Z9N vADeUWNA==; Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t2rql-00000007vwE-3ipz for linux-arm-kernel@lists.infradead.org; Mon, 21 Oct 2024 12:49:33 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4315abed18aso40907925e9.2 for ; Mon, 21 Oct 2024 05:49:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729514967; x=1730119767; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3Q32sh+uJFSpt9TLvxk2ifmsRw8yfE9HNNl0na2PYAU=; b=WBkx9P0F3f0pBZNwH+ETe2n7dmoJguZOgcWi2/aoIH4KNyflcq4ynhG8HnumzttwX+ 3SIH+EH9AGChyLKitfZwehanu92nCXpr9RfrfPSPgTT0Thms0tH3sWyJD2KwnhCLxBNd SnIlzeWUnfmFofoC/jVuUeDq0He1oZKWivZ00N6oDS1GQFyOcrV8ye4zBOvyNeHF+oP9 F+5+MJN+8ao13UMDwuq6sVlfoSgCWqRxh7cxB+vEVl+N4ML2lDCfqcfYrMXAvaCQy0Wh ivLKgykQBf1yw9x0W/RVHOhkH3jfrhMS/kNTEjweHZROEKDIvyb7UPLO5W5nhBxpLQzo ZtfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729514967; x=1730119767; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3Q32sh+uJFSpt9TLvxk2ifmsRw8yfE9HNNl0na2PYAU=; b=esjQ8HR18I7s6ycSsjo5ZTnVYRM3sN1yZTU6S3cBuQAM7H3kD5Qm+07BjfMel7Fb0D THL6qEs8lT060bLlGiC/lAJZyobcO20/IsBYpfYD89hxsP1/UbYStDtAi/yVp56gd6+x 3zToM7tp/ekrT3RO9AJn2XTLlIc9FL8aOhs2MRRtW5PgNNzOvZewHd2TQEqmIlfK1tOZ 8H6h45Ec03mdKuH2JmeeR+gf8UzH85GkoxbUAP++FpPthQdQdr4zbLNTfZ05f/WzQVu4 57RaAzqcczQzW4no2e5lC/B8C2KhSTK1lqjjR1iJb3CtAztvUXcZCVeVSNrz7QjQiYHu 7/Vw== X-Forwarded-Encrypted: i=1; AJvYcCXvD1kT3CjCkTrnNx98jBPzo0CffBiP5vY2medEm4DtrUfTPfyea8t69mQn0ksp0VCdf0VtcX+AyLJNukfYmihd@lists.infradead.org X-Gm-Message-State: AOJu0YxAKQ1CXvAQ3G0KTcOb49U6HpuZ2cjcEIllCO3PpVGh0hTbFk5j cGlnMkSjpnXyrZQDCTncuY5Pl14UPQnsQgiVmtOCiy0r0lfwL56P X-Google-Smtp-Source: AGHT+IF7y/aVuMR4dM/wOhaLHG4+/0yWCkNhdRhKrO6vRCRYPe8M7QABDKRdq1+Ho2EKQbs991Zaig== X-Received: by 2002:a05:600c:4595:b0:431:3b53:105e with SMTP id 5b1f17b1804b1-4316163bccfmr99788485e9.9.1729514966811; Mon, 21 Oct 2024 05:49:26 -0700 (PDT) Received: from eichest-laptop.. ([178.197.202.204]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4316f5c2df7sm56460595e9.33.2024.10.21.05.49.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 05:49:26 -0700 (PDT) From: Stefan Eichenberger To: hongxing.zhu@nxp.com, l.stach@pengutronix.de, lpieralisi@kernel.org, kw@linux.com, manivannan.sadhasivam@linaro.org, robh@kernel.org, bhelgaas@google.com, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, francesco.dolcini@toradex.com, Frank.li@nxp.com Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, Stefan Eichenberger Subject: [PATCH v3] PCI: imx6: Add suspend/resume support for i.MX6QDL Date: Mon, 21 Oct 2024 14:49:13 +0200 Message-ID: <20241021124922.5361-1-eichest@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241021_134932_120074_5BC1666E X-CRM114-Status: GOOD ( 22.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Stefan Eichenberger The suspend/resume support is broken on the i.MX6QDL platform. This patch resets the link upon resuming to recover functionality. It shares most of the sequences with other i.MX devices but does not touch the critical registers, which might break PCIe. This patch addresses the same issue as the following downstream commit: https://github.com/nxp-imx/linux-imx/commit/4e92355e1f79d225ea842511fcfd42b343b32995 In comparison this patch will also reset the device if possible because the downstream patch alone would still make the ath10k driver crash. Without this patch suspend/resume will not work if a PCIe device is connected. The kernel will hang on resume and print an error: ath10k_pci 0000:01:00.0: Unable to change power state from D3hot to D0, device inaccessible 8<--- cut here --- Unhandled fault: imprecise external abort (0x1406) at 0x0106f944 Signed-off-by: Stefan Eichenberger --- Changes in v3: - Added a new flag to the driver data to indicate that the suspend/resume is broken on the i.MX6QDL platform. (Frank) - Fix comments to be more relevant (Mani) - Use imx_pcie_assert_core_reset in suspend (Mani) drivers/pci/controller/dwc/pci-imx6.c | 57 +++++++++++++++++++++------ 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 808d1f1054173..09e3b15f0908a 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -82,6 +82,11 @@ enum imx_pcie_variants { #define IMX_PCIE_FLAG_HAS_SERDES BIT(6) #define IMX_PCIE_FLAG_SUPPORT_64BIT BIT(7) #define IMX_PCIE_FLAG_CPU_ADDR_FIXUP BIT(8) +/** + * Because of ERR005723 (PCIe does not support L2 power down) we need to + * workaround suspend resume on some devices which are affected by this errata. + */ +#define IMX_PCIE_FLAG_BROKEN_SUSPEND BIT(9) #define imx_check_flag(pci, val) (pci->drvdata->flags & val) @@ -1237,9 +1242,19 @@ static int imx_pcie_suspend_noirq(struct device *dev) return 0; imx_pcie_msi_save_restore(imx_pcie, true); - imx_pcie_pm_turnoff(imx_pcie); - imx_pcie_stop_link(imx_pcie->pci); - imx_pcie_host_exit(pp); + if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_BROKEN_SUSPEND)) { + /** + * The minimum for a workaround would be to set PERST# and to + * set the PCIE_TEST_PD flag. However, we can also disable the + * clock which saves some power. + */ + imx_pcie_assert_core_reset(imx_pcie); + imx_pcie->drvdata->enable_ref_clk(imx_pcie, false); + } else { + imx_pcie_pm_turnoff(imx_pcie); + imx_pcie_stop_link(imx_pcie->pci); + imx_pcie_host_exit(pp); + } return 0; } @@ -1253,14 +1268,32 @@ static int imx_pcie_resume_noirq(struct device *dev) if (!(imx_pcie->drvdata->flags & IMX_PCIE_FLAG_SUPPORTS_SUSPEND)) return 0; - ret = imx_pcie_host_init(pp); - if (ret) - return ret; - imx_pcie_msi_save_restore(imx_pcie, false); - dw_pcie_setup_rc(pp); + if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_BROKEN_SUSPEND)) { + ret = imx_pcie->drvdata->enable_ref_clk(imx_pcie, true); + if (ret) + return ret; + ret = imx_pcie_deassert_core_reset(imx_pcie); + if (ret) + return ret; + /** + * Using PCIE_TEST_PD seems to disable msi and powers down the + * root complex. This is why we have to setup the rc again and + * why we have to restore the msi register. + */ + ret = dw_pcie_setup_rc(&imx_pcie->pci->pp); + if (ret) + return ret; + imx_pcie_msi_save_restore(imx_pcie, false); + } else { + ret = imx_pcie_host_init(pp); + if (ret) + return ret; + imx_pcie_msi_save_restore(imx_pcie, false); + dw_pcie_setup_rc(pp); - if (imx_pcie->link_is_up) - imx_pcie_start_link(imx_pcie->pci); + if (imx_pcie->link_is_up) + imx_pcie_start_link(imx_pcie->pci); + } return 0; } @@ -1485,7 +1518,9 @@ static const struct imx_pcie_drvdata drvdata[] = { [IMX6Q] = { .variant = IMX6Q, .flags = IMX_PCIE_FLAG_IMX_PHY | - IMX_PCIE_FLAG_IMX_SPEED_CHANGE, + IMX_PCIE_FLAG_IMX_SPEED_CHANGE | + IMX_PCIE_FLAG_BROKEN_SUSPEND | + IMX_PCIE_FLAG_SUPPORTS_SUSPEND, .dbi_length = 0x200, .gpr = "fsl,imx6q-iomuxc-gpr", .clk_names = imx6q_clks,