Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6667196rdb; Tue, 2 Jan 2024 09:09:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IEHX128edod4m0LxCOupQcJqg9Kfs/rC5RzysAX+UZOMc21KZ13MusM90DnM/3QUnbJmHY1 X-Received: by 2002:a17:90a:e98c:b0:28b:c1ad:9cf5 with SMTP id v12-20020a17090ae98c00b0028bc1ad9cf5mr5948122pjy.26.1704215377941; Tue, 02 Jan 2024 09:09:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704215377; cv=none; d=google.com; s=arc-20160816; b=V39Eh2K69DZD3GwzA+pfdgZVksgK+o8+RpPqmuFKBHI29J62Mmm8bx9Ip0JJaNTfko PDX3FSJ3gMzhA/fVjHm8Ff+RU2M580Q8krg/Bu0xV3fzzeQpsbG/knwDJOJvpuk7kf/6 RuQ1yscGBCB+cLQF6CGfj023cqI0sY2k7jTeSaBDvq7317YGDgStK4qkH/JAQoOtVCLt uZN3VlrhKgo8+B+vc1AHMea5GB5RXYk96CzBOXHL55/5JaPH5kSSGT0u4qL5b7oDd6mC MBHzaYUrS8q124Dc9/3JGKvzSQbX43Q//Oo7cDiWZCDJ8DnNn9ybGltXjHywtjvjLaMf Uppw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=CXR1xrhhVt2XMLdrJSQyf40UOFm6Z+aJRxVclSlLD78=; fh=QczJFdjYvwNSMArv4vfOEk08vhOwVb3PLIQtzOJcXB0=; b=yFS3LNr6JnkJx7OnyQYpgf21+wVsQmrL1W4V/4qdqQ5oy3jc+03g7djP8Ne0uCo4Uy sN5KNBz53+50cuVbqsqqsf9EsrIHmgIZgkIU3cZ32cqNcC6l+eHNoUxYD3Tt3fCNCbTq wZ6JwzMi7d4smYy+gX7nawo82gsADmUcNeM1r5yiWLSLmT9ZKD8AedztQna3/fOPWNF7 XwJrvWjXabqWBXmwcuhI/7XVluyOm/LEf+1tvCPob3UAHmbdp59nsqy5Yf7gSWrRzvHp HRjet8d6fkp2HA8ZhT0lE0X+UsO/AuJqiN+rRtUbxOxm2es0SVpC3k/uXx/q504GF/Cm gXFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cSFnBOTE; spf=pass (google.com: domain of linux-kernel+bounces-14638-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14638-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id il5-20020a17090b164500b0028bdb493d1esi22025067pjb.115.2024.01.02.09.09.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 09:09:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14638-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cSFnBOTE; spf=pass (google.com: domain of linux-kernel+bounces-14638-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14638-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C40F8B2265F for ; Tue, 2 Jan 2024 17:08:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 146D015ACB; Tue, 2 Jan 2024 17:08:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cSFnBOTE" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 382DB156F8; Tue, 2 Jan 2024 17:08:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23FCDC433C7; Tue, 2 Jan 2024 17:07:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704215284; bh=Vh7w2Zm7IPKpg3RcIIgKY9vwrmakmJ0aX6srxDGwVyU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=cSFnBOTEKpnf4UcrIpY77YNDqkZHRmqkyJ6pkhJTiQfsoFM5rEd0Xm2NfuVZ8XRBQ 8c3m0Yi0gxXzhu8XRQQKi4CbPo4gUxYBZU4R45xzsDhkja4/fQcYecs7jkRy/IXevr RMbrizQXkucVLYt3DGTwH9CpYGcdob4Glhl3sTXXhBg2Qt1UCTQlz9PuNYxDjrDMg+ K+ML+1WtLx2LftKvRWBnnwZtnQV6nAKqlz69rIvlxUZ7bz9j5b6whtF4f+19G/hMIL iAxcoka1U8VZu3dqs08zIWZ0xGMiySqMsHVFv9Gungo/SIEi/148tAsrxT6P0vkno6 YkY2fDmX+BKpw== Date: Tue, 2 Jan 2024 22:37:49 +0530 From: Manivannan Sadhasivam To: Konrad Dybcio Cc: Bjorn Andersson , Lorenzo Pieralisi , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Rob Herring , Bjorn Helgaas , Philipp Zabel , Stanimir Varbanov , Andrew Murray , Vinod Koul , Marijn Suijten , linux-arm-msm@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Bjorn Andersson Subject: Re: [PATCH 4/4] PCI: qcom: Implement RC shutdown/power up Message-ID: <20240102170749.GF4917@thinkpad> References: <20231227-topic-8280_pcie-v1-0-095491baf9e4@linaro.org> <20231227-topic-8280_pcie-v1-4-095491baf9e4@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231227-topic-8280_pcie-v1-4-095491baf9e4@linaro.org> On Wed, Dec 27, 2023 at 11:17:22PM +0100, Konrad Dybcio wrote: > Currently, we've only been minimizing the power draw while keeping the > RC up at all times. This is suboptimal, as it draws a whole lot of power > and prevents the SoC from power collapsing. > > Implement full shutdown and re-initialization to allow for powering off > the controller. > > This is mainly intended for v1_9_0 (sc8280xp), but the hardware is rather > similar across the board. More platform-specific details may be added in > the future as necessary. > > Co-developed-by: Bjorn Andersson There should be s-o-b for Bjorn also. > Signed-off-by: Konrad Dybcio Before going into the patch, I should ask you how you are dealing with properly powering down the PCIe device drivers before pulling the plug here. - Mani > --- > drivers/pci/controller/dwc/Kconfig | 1 + > drivers/pci/controller/dwc/pcie-qcom.c | 132 +++++++++++++++++++++++++-------- > 2 files changed, 102 insertions(+), 31 deletions(-) > > diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dwc/Kconfig > index 5ac021dbd46a..591c4109ed62 100644 > --- a/drivers/pci/controller/dwc/Kconfig > +++ b/drivers/pci/controller/dwc/Kconfig > @@ -268,6 +268,7 @@ config PCIE_DW_PLAT_EP > config PCIE_QCOM > bool "Qualcomm PCIe controller (host mode)" > depends on OF && (ARCH_QCOM || COMPILE_TEST) > + depends on QCOM_COMMAND_DB || QCOM_COMMAND_DB=n > depends on PCI_MSI > select PCIE_DW_HOST > select CRC8 > diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c > index 3d77269e70da..a9e24fcd1f66 100644 > --- a/drivers/pci/controller/dwc/pcie-qcom.c > +++ b/drivers/pci/controller/dwc/pcie-qcom.c > @@ -30,13 +30,18 @@ > #include > #include > #include > +#include > > #include "../../pci.h" > #include "pcie-designware.h" > > +#include > +#include > + > /* PARF registers */ > #define PARF_SYS_CTRL 0x00 > #define PARF_PM_CTRL 0x20 > +#define PARF_PM_STTS 0x24 > #define PARF_PCS_DEEMPH 0x34 > #define PARF_PCS_SWING 0x38 > #define PARF_PHY_CTRL 0x40 > @@ -80,7 +85,10 @@ > #define L1_CLK_RMV_DIS BIT(1) > > /* PARF_PM_CTRL register fields */ > -#define REQ_NOT_ENTR_L1 BIT(5) > +#define REQ_NOT_ENTR_L1 BIT(5) /* "Prevent L0->L1" */ > + > +/* PARF_PM_STTS register fields */ > +#define PM_ENTER_L23 BIT(5) > > /* PARF_PCS_DEEMPH register fields */ > #define PCS_DEEMPH_TX_DEEMPH_GEN1(x) FIELD_PREP(GENMASK(21, 16), x) > @@ -122,6 +130,7 @@ > > /* ELBI_SYS_CTRL register fields */ > #define ELBI_SYS_CTRL_LT_ENABLE BIT(0) > +#define ELBI_SYS_CTRL_PME_TURNOFF_MSG BIT(4) > > /* AXI_MSTR_RESP_COMP_CTRL0 register fields */ > #define CFG_REMOTE_RD_REQ_BRIDGE_SIZE_2K 0x4 > @@ -244,6 +253,7 @@ struct qcom_pcie { > const struct qcom_pcie_cfg *cfg; > struct dentry *debugfs; > bool suspended; > + bool soc_is_rpmh; > }; > > #define to_qcom_pcie(x) dev_get_drvdata((x)->dev) > @@ -273,6 +283,24 @@ static int qcom_pcie_start_link(struct dw_pcie *pci) > return 0; > } > > +static int qcom_pcie_stop_link(struct dw_pcie *pci) > +{ > + struct qcom_pcie *pcie = to_qcom_pcie(pci); > + u32 ret_l23, val; > + > + writel(ELBI_SYS_CTRL_PME_TURNOFF_MSG, pcie->elbi + ELBI_SYS_CTRL); > + readl(pcie->elbi + ELBI_SYS_CTRL); > + > + ret_l23 = readl_poll_timeout(pcie->parf + PARF_PM_STTS, val, > + val & PM_ENTER_L23, 10000, 100000); > + if (ret_l23) { > + dev_err(pci->dev, "Failed to enter L2/L3\n"); > + return -ETIMEDOUT; > + } > + > + return 0; > +} > + > static void qcom_pcie_clear_hpc(struct dw_pcie *pci) > { > u16 offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); > @@ -991,9 +1019,19 @@ static void qcom_pcie_host_post_init_2_7_0(struct qcom_pcie *pcie) > static void qcom_pcie_deinit_2_7_0(struct qcom_pcie *pcie) > { > struct qcom_pcie_resources_2_7_0 *res = &pcie->res.v2_7_0; > + u32 val; > + > + /* Disable PCIe clocks and resets */ > + val = readl(pcie->parf + PARF_PHY_CTRL); > + val |= PHY_TEST_PWR_DOWN; > + writel(val, pcie->parf + PARF_PHY_CTRL); > + readl(pcie->parf + PARF_PHY_CTRL); > > clk_bulk_disable_unprepare(res->num_clks, res->clks); > > + reset_control_assert(res->rst); > + usleep_range(2000, 2500); > + > regulator_bulk_disable(ARRAY_SIZE(res->supplies), res->supplies); > } > > @@ -1553,6 +1591,9 @@ static int qcom_pcie_probe(struct platform_device *pdev) > goto err_phy_exit; > } > > + /* If the soc features RPMh, cmd_db must have been prepared by now */ > + pcie->soc_is_rpmh = !cmd_db_ready(); > + > qcom_pcie_icc_update(pcie); > > if (pcie->mhi) > @@ -1569,60 +1610,89 @@ static int qcom_pcie_probe(struct platform_device *pdev) > return ret; > } > > -static int qcom_pcie_suspend_noirq(struct device *dev) > +static int qcom_pcie_resume_noirq(struct device *dev) > { > struct qcom_pcie *pcie = dev_get_drvdata(dev); > int ret; > > /* > - * Set minimum bandwidth required to keep data path functional during > - * suspend. > + * Undo the tag change from qcom_pcie_suspend_noirq first in case > + * RPM(h) spontaneously decides to power collapse the platform based > + * on other inputs. > */ > - ret = icc_set_bw(pcie->icc_mem, 0, kBps_to_icc(1)); > + icc_set_tag(pcie->icc_mem, pcie->soc_is_rpmh ? QCOM_ICC_TAG_ALWAYS : RPM_ALWAYS_TAG); > + /* Flush the tag change */ > + ret = icc_set_bw(pcie->icc_mem, 0, pcie->last_bw); > if (ret) { > - dev_err(dev, "Failed to set interconnect bandwidth: %d\n", ret); > + dev_err(pcie->pci->dev, "failed to set interconnect bandwidth: %d\n", ret); > return ret; > } > > - pcie->last_bw = kBps_to_icc(1); > + /* Only check this now to make sure the icc vote is in before going furhter. */ > + if (!pcie->suspended) > + return 0; > > - /* > - * Turn OFF the resources only for controllers without active PCIe > - * devices. For controllers with active devices, the resources are kept > - * ON and the link is expected to be in L0/L1 (sub)states. > - * > - * Turning OFF the resources for controllers with active PCIe devices > - * will trigger access violation during the end of the suspend cycle, > - * as kernel tries to access the PCIe devices config space for masking > - * MSIs. > - * > - * Also, it is not desirable to put the link into L2/L3 state as that > - * implies VDD supply will be removed and the devices may go into > - * powerdown state. This will affect the lifetime of the storage devices > - * like NVMe. > - */ > - if (!dw_pcie_link_up(pcie->pci)) { > - qcom_pcie_host_deinit(&pcie->pci->pp); > - pcie->suspended = true; > - } > + ret = qcom_pcie_host_init(&pcie->pci->pp); > + if (ret) > + goto revert_icc_tag; > + > + dw_pcie_setup_rc(&pcie->pci->pp); > + > + ret = qcom_pcie_start_link(pcie->pci); > + if (ret) > + goto deinit_host; > + > + /* Ignore the retval, the devices may come up later. */ > + dw_pcie_wait_for_link(pcie->pci); > + > + qcom_pcie_icc_update(pcie); > + > + pcie->suspended = false; > > return 0; > + > +deinit_host: > + qcom_pcie_host_deinit(&pcie->pci->pp); > +revert_icc_tag: > + icc_set_tag(pcie->icc_mem, pcie->soc_is_rpmh ? QCOM_ICC_TAG_WAKE : RPM_ACTIVE_TAG); > + /* Ignore the retval, failing here would be tragic anyway.. */ > + icc_set_bw(pcie->icc_mem, 0, pcie->last_bw); > + > + return ret; > } > > -static int qcom_pcie_resume_noirq(struct device *dev) > +static int qcom_pcie_suspend_noirq(struct device *dev) > { > struct qcom_pcie *pcie = dev_get_drvdata(dev); > int ret; > > - if (pcie->suspended) { > - ret = qcom_pcie_host_init(&pcie->pci->pp); > + if (pcie->suspended) > + return 0; > + > + if (dw_pcie_link_up(pcie->pci)) { > + ret = qcom_pcie_stop_link(pcie->pci); > if (ret) > return ret; > + } > > - pcie->suspended = false; > + qcom_pcie_host_deinit(&pcie->pci->pp); > + > + /* > + * The PCIe RC may be covertly accessed by the secure firmware on sleep exit. > + * Use the WAKE bucket to let RPMh pull the plug on PCIe in sleep, > + * but guarantee it comes back for resume. > + */ > + icc_set_tag(pcie->icc_mem, pcie->soc_is_rpmh ? QCOM_ICC_TAG_WAKE : RPM_ACTIVE_TAG); > + /* Flush the tag change */ > + ret = icc_set_bw(pcie->icc_mem, 0, pcie->last_bw); > + if (ret) { > + dev_err(pcie->pci->dev, "failed to set interconnect bandwidth: %d\n", ret); > + > + /* Revert everything and hope the next icc_set_bw goes through.. */ > + return qcom_pcie_resume_noirq(dev); > } > > - qcom_pcie_icc_update(pcie); > + pcie->suspended = true; > > return 0; > } > > -- > 2.43.0 > -- மணிவண்ணன் சதாசிவம்