From patchwork Wed Oct 9 13:14:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Eichenberger X-Patchwork-Id: 13828436 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 A7A6CCEDD90 for ; Wed, 9 Oct 2024 13:24:57 +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=+aPVZqKoHAIyYW4ZUYe5ZVOvVWla1BASLvw4osJ0NuE=; b=1OWXCsSKEs0YB3IrUrH413Cy0R lRFFp9SY0xarEiHeSga2bz3tdr+kuQcyhd/O6Bjw4k2PNDLzxM1y0tdYwPBf6LsLWm1Dz1HoGsoJ9 8coZtNYe98b10j9N+mfcgEKKYdwbpVjrpoiF1vT93UeRmUuf8VBxxUcV76McPK8EGcmVAQ+hYjH8T sbjcypdl8YnyKKsWfMPJLHQJtjM7c9zdxZgBvm4Z+VufcblUEV+Xwk93VbnSWeF74g28RfH8jEZ35 zRS8DbmG3NyIpouE92/UQjz6Xxm9DQ4fMnfGXRC5RCIRtfmWf/mPkGM1IRvn6GRUYyYO1OtNSxU3F onUT+M5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syWgK-00000009Oim-0T2e; Wed, 09 Oct 2024 13:24:48 +0000 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syWZB-00000009NC1-0aAJ for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 13:17:26 +0000 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2facf48157dso72597841fa.2 for ; Wed, 09 Oct 2024 06:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728479842; x=1729084642; 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=+aPVZqKoHAIyYW4ZUYe5ZVOvVWla1BASLvw4osJ0NuE=; b=jxzop6N7CJUPwnqVblXVFu6Shel7FEJnvksIMqdZ7dRZpNOb1LTqZJ0SS9UEANu8YZ Oia/aYnVtuRt9SM3owS7imX1QP8wX/HpK9pu5OVhEj40DOL/n4dcabAUvLT7TgCVw5Ny 52auRoPVf7KXHsX5l5R1JgDtTan6q4xSDVLGi5WrBOS0Dlv258a4YrdQNpbVC7a0r93O j2lCCbArTcy8/8XIV/omgOnTqOMNvPYmbzXpFBM3UT8ufqi439SciP60jxjaXfZktY7+ eEcTYGBCidSA3Y4bUi5PB9OBgm0IB4cCGeNcMGz8vmq+xT43F5nKMBB8JJ3F95gkEUQN hl+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728479842; x=1729084642; 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=+aPVZqKoHAIyYW4ZUYe5ZVOvVWla1BASLvw4osJ0NuE=; b=N7q+/GQbsI+IlzAdUEdlBQSDoukt4fNgIJQs5k0/lFyhSvCmrhrcxqYvRcDwRxxZWn eMS43QGIKFcDFGDiQ38xu8/pqHXFB91+ybVxVdFYA9Wson30Xa0UoE+3FbfJ2v4MdnAR y+HdUNMUppfyHgjNZXPnmJWEH1u8ChkrlQfFOd+C26jAOimwOQZhX6UZD0g5jqqBBlJe +X8Il03rnGSyGz7okxhvpJPyAZpLLCb3U3qi7wdVeT3YnD+ZMiu5EDiYPeI3zv9/TXmN 0BZrR/kdkQbiMjvXXspmMqqwIg3cq+6P9HE49kjtEnyuu+5MmQXoinE4U5u9IFYfoXxj js6w== X-Forwarded-Encrypted: i=1; AJvYcCUHsmtIRy2PV6D0Z/Ec89FqtR/foWqmK5Db0gaO0N+vp9mgKhdLcxj9eUag5YvvxkagDr2QqRwEBjbwHLLeTNUd@lists.infradead.org X-Gm-Message-State: AOJu0Yw71MgvK+BgaP71VWmEyn1Pe4Mwd0864lLkWNcm37muzT9ypWq8 oAZgE0Yq6PN1KDFtmrWrOgqxwkanFEx7qt7JRFox5gx8Mt0prCTx X-Google-Smtp-Source: AGHT+IFi8gXrgp3qSEUKJjN3obp7dTqaJsNxBSiC83wyzLDBc3Lx9ddW7vTT5a689gPE43Ak6IZ6ew== X-Received: by 2002:a05:6512:31cf:b0:536:554a:24c2 with SMTP id 2adb3069b0e04-539c48c35d7mr1710763e87.13.1728479841617; Wed, 09 Oct 2024 06:17:21 -0700 (PDT) Received: from eichest-laptop.corp.toradex.com (31-10-206-125.static.upc.ch. [31.10.206.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-430d59b2c35sm20189955e9.37.2024.10.09.06.17.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 06:17:21 -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 v2] PCI: imx6: Add suspend/resume support for i.MX6QDL Date: Wed, 9 Oct 2024 15:14:05 +0200 Message-ID: <20241009131659.29616-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-20241009_061725_217615_7263AEF6 X-CRM114-Status: GOOD ( 23.98 ) 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. 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 --- v1 -> v2: Share most code with other i.MX platforms and set suspend support flag for i.MX6QDL. Version 1 can be found here: https://lore.kernel.org/all/20240819090428.17349-1-eichest@gmail.com/ drivers/pci/controller/dwc/pci-imx6.c | 44 +++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 808d1f1054173..f33bef0aa1071 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -1238,8 +1238,23 @@ static int imx_pcie_suspend_noirq(struct device *dev) 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); + /* + * Do not turn off the PCIe controller because of ERR003756, ERR004490, ERR005188, + * they all document issues with LLTSSM and the PCIe controller which + * does not come out of reset properly. Therefore, try to keep the controller enabled + * and only reset the link. However, the reference clock still needs to be turned off, + * else the controller will freeze on resume. + */ + if (imx_pcie->drvdata->variant == IMX6Q) { + /* Reset the PCIe device */ + gpiod_set_value_cansleep(imx_pcie->reset_gpiod, 1); + + if (imx_pcie->drvdata->enable_ref_clk) + imx_pcie->drvdata->enable_ref_clk(imx_pcie, false); + } else { + imx_pcie_stop_link(imx_pcie->pci); + imx_pcie_host_exit(pp); + } return 0; } @@ -1253,6 +1268,28 @@ static int imx_pcie_resume_noirq(struct device *dev) if (!(imx_pcie->drvdata->flags & IMX_PCIE_FLAG_SUPPORTS_SUSPEND)) return 0; + /* + * Even though the i.MX6Q does not support proper suspend/resume, we + * need to reset the link after resume or the memory mapped PCIe I/O + * space will be inaccessible. This will cause the system to freeze. + */ + if (imx_pcie->drvdata->variant == IMX6Q) { + if (imx_pcie->drvdata->enable_ref_clk) + imx_pcie->drvdata->enable_ref_clk(imx_pcie, true); + + imx_pcie_deassert_core_reset(imx_pcie); + + /* + * Setup the root complex again and enable msi. Without this PCIe will + * not work in msi mode and drivers will crash if they try to access + * the device memory area + */ + dw_pcie_setup_rc(&imx_pcie->pci->pp); + imx_pcie_msi_save_restore(imx_pcie, false); + + return 0; + } + ret = imx_pcie_host_init(pp); if (ret) return ret; @@ -1485,7 +1522,8 @@ 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_SUPPORTS_SUSPEND, .dbi_length = 0x200, .gpr = "fsl,imx6q-iomuxc-gpr", .clk_names = imx6q_clks,