Message ID | 20230103074907.12784-2-manivannan.sadhasivam@linaro.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4491743wrt; Mon, 2 Jan 2023 23:52:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXs3bXc9HjrBeprMrwdjvAZdoX1Llld5A1i9MW+oZhzdxB883C9QPg773OKFpOyWrreVPsWn X-Received: by 2002:a17:902:768a:b0:189:7919:de3c with SMTP id m10-20020a170902768a00b001897919de3cmr50547599pll.43.1672732360653; Mon, 02 Jan 2023 23:52:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672732360; cv=none; d=google.com; s=arc-20160816; b=r6d8liLwApE1XOoq5lyxdcEkhJtw9Ojn07xLaTX56vm6+5oLOpijK5i/IMSVSo4gPq WRZBrfEMQJUQz/uZmEL8qQv9kJOVnH7Dp5mLis9KZW6Uesw1X/hkEVMHpoWWXI6oOU+1 wRgqucmipwPLwOZIH1TlBQrqw33JUth3o8fy/HzoOZS6dmOxrwCqRjX671TLt2tJkZTc ZX2+FmW2u8khWcWoHbgFEu35fbLkdArIcAzGkbu1UeQ3zV0XBz+Z7PnZqvG2ivTNX2vJ DjjjaqTyf6Xc9W1LBaQS6NbmSO+KCorxZjtf7Nigj3Sk7GwU92+oXSHw4LFda2cQqlxT LFog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+UK7YFXk4569dzdxh4KbKdmm7jq8EMlrS+pPCmhUndQ=; b=QVDoAfDBQI98OAuJbJO+ARhUNpwx/Im8PUwQ7TO13jh596H+vK3fufkqEHWFvLek51 mHTdsAsRnKxGtuvxRAm4NiL00yXeiqV56G4YOCUb1Qn8vlqBQLdgt0hNaHYUvpGXjqha 3FcDJySlF3u1RHXhXuJhULn0FWDA4Oy6eUw6lh8+YcpHJ68jyeH0UFWUuMQnYmgJbVOI 8+ybd3BRK+gY6Bw37/LVU6w5saQBlftsVKyQ9Qjd5s483X1KDV9qN03DaUtCXjm6wP25 vLcUdfTTxD0tzKxEG1wroH1BDjV2Qsn+R9dzQRkskiCLlooc6CKZfVi3G8S7hQwqPBlS KBZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XDzlCQKQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g7-20020a1709029f8700b00189891763f3si29577309plq.600.2023.01.02.23.52.28; Mon, 02 Jan 2023 23:52:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XDzlCQKQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236872AbjACHtn (ORCPT <rfc822;tmhikaru@gmail.com> + 99 others); Tue, 3 Jan 2023 02:49:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230478AbjACHth (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 3 Jan 2023 02:49:37 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CD5FDEFD for <linux-kernel@vger.kernel.org>; Mon, 2 Jan 2023 23:49:36 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id h7-20020a17090aa88700b00225f3e4c992so22490505pjq.1 for <linux-kernel@vger.kernel.org>; Mon, 02 Jan 2023 23:49:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+UK7YFXk4569dzdxh4KbKdmm7jq8EMlrS+pPCmhUndQ=; b=XDzlCQKQP7cwi2YOhJd1r6+8fWXBSxLqj1d91S6NVRw2GvouAuIrW11piBS0LbVASB xhYe0r8UzoBgjuvzds8MZzmpfZr9jCHfjRcdhXOffIdKPFSAHvqTcJ99+1itBH4jCzrD Gg941FAUFxgIJcvmFImp/IoLscUKwKnuKP8vzCmCAqKnf55xuF9dE9/kLxQiDHUeGZ7g myJuTPLZspUnJ2QRZFDFQ+v81mzvniVeuZLDlbsRjMNPlVyGVxwylXM2ArIRXvDPvfMT fQEM/uOWRB6G/PDDa/ilwX61QKrszuQXi+Vo1e7LHBGQ24J5OkIpZ1YxZcQfiFuJNGb0 N2mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+UK7YFXk4569dzdxh4KbKdmm7jq8EMlrS+pPCmhUndQ=; b=gPR7oPJxSNCekZlIseGuD9fTrsHBSvuEkcistnGR98bEi5DwGs8D4kujcvDfKH6SP1 sWldF9S8hSLsvc2tcIjeslOn23slfCajvLTbB1B04C2ww+yU060kRM5TFRiKnbsHvudO FlULCUOrbDJg0952pXbYYhrbL5yfIZ5ECFJ3kIXxoXST6odVZQWSQqrhvicItnaM7km4 jw9Nd577LF+N2vMebWtttppP0JBqwV3sLNqJii0KU/fphfxIlI9Q0P5koPkz8lJ5FJhS xv2v5spO83xzmC5zdxsQAD/35CzDO7sWr3A2iUcBm6JwcN/kYqXAt3kZX1kawIrZRZHx RVjA== X-Gm-Message-State: AFqh2kosJM8E6vGNR7toOtV08YNPESL2LEDgHAz6fJ25Ab44P0jYof6q m2/y4FU0Ad4linU2DIJRBGvi X-Received: by 2002:a17:902:e1ca:b0:192:caf4:4661 with SMTP id t10-20020a170902e1ca00b00192caf44661mr6241295pla.15.1672732175859; Mon, 02 Jan 2023 23:49:35 -0800 (PST) Received: from localhost.localdomain ([220.158.158.30]) by smtp.gmail.com with ESMTPSA id q15-20020a17090311cf00b00189f2fdc178sm21488305plh.177.2023.01.02.23.49.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jan 2023 23:49:34 -0800 (PST) From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> To: lpieralisi@kernel.org, robh@kernel.org Cc: andersson@kernel.org, konrad.dybcio@linaro.org, kw@linux.com, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, quic_krichai@quicinc.com, johan+linaro@kernel.org, steev@kali.org, Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Subject: [PATCH 1/1] PCI: qcom: Add support for system suspend and resume Date: Tue, 3 Jan 2023 13:19:07 +0530 Message-Id: <20230103074907.12784-2-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230103074907.12784-1-manivannan.sadhasivam@linaro.org> References: <20230103074907.12784-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753987007799595606?= X-GMAIL-MSGID: =?utf-8?q?1753987007799595606?= |
Series |
PCI: qcom: Add support for system suspend and resume
|
|
Commit Message
Manivannan Sadhasivam
Jan. 3, 2023, 7:49 a.m. UTC
During the system suspend, vote for minimal interconnect bandwidth and
also turn OFF the resources like clock and PHY if there are no active
devices connected to the controller. For the controllers with active
devices, the resources are kept ON as removing the resources will
trigger access violation during the late end of suspend cycle as kernel
tries to access the config space of PCIe devices to mask the 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 storage devices like NVMe.
And finally, during resume, turn ON the resources if the controller was
truly suspended (resources OFF) and update the interconnect bandwidth
based on PCIe Gen speed.
Suggested-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
drivers/pci/controller/dwc/pcie-qcom.c | 52 ++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
Comments
On 03/01/23 13:19, Manivannan Sadhasivam wrote: > During the system suspend, vote for minimal interconnect bandwidth and > also turn OFF the resources like clock and PHY if there are no active > devices connected to the controller. For the controllers with active > devices, the resources are kept ON as removing the resources will > trigger access violation during the late end of suspend cycle as kernel > tries to access the config space of PCIe devices to mask the 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 storage devices like NVMe. > > And finally, during resume, turn ON the resources if the controller was > truly suspended (resources OFF) and update the interconnect bandwidth > based on PCIe Gen speed. > > Suggested-by: Krishna chaitanya chundru <quic_krichai@quicinc.com> > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> > --- Nice to have another driver added to the list of system suspend support! Acked-by: Dhruva Gole <d-gole@ti.com> > drivers/pci/controller/dwc/pcie-qcom.c | 52 ++++++++++++++++++++++++++ > 1 file changed, 52 insertions(+) > > diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c > index 5696e327795b..48810f1f2dba 100644 > --- a/drivers/pci/controller/dwc/pcie-qcom.c > +++ b/drivers/pci/controller/dwc/pcie-qcom.c > @@ -227,6 +227,7 @@ struct qcom_pcie { > struct gpio_desc *reset; > struct icc_path *icc_mem; > const struct qcom_pcie_cfg *cfg;qcom_pcie_icc_update > + bool suspended; > }; > > #define to_qcom_pcie(x) dev_get_drvdata((x)->dev) > @@ -1835,6 +1836,52 @@ static int qcom_pcie_remove(struct platform_device *pdev) > return 0; > } > > +static int qcom_pcie_suspend_noirq(struct device *dev) > +{ > + struct qcom_pcie *pcie = dev_get_drvdata(dev); > + int ret; > + > + ret = icc_set_bw(pcie->icc_mem, 0, 0); > + if (ret) { > + dev_err(pcie->pci->dev, "Failed to set interconnect bandwidth: %d\n", ret); > + return ret; > + } > + > + /* > + * 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; > + } > + > + return 0; > +} > + > +static int qcom_pcie_resume_noirq(struct device *dev) > +{ > + struct qcom_pcie *pcie = dev_get_drvdata(dev); > + > + if (pcie->suspended) { > + qcom_pcie_host_init(&pcie->pci->pp); > + pcie->suspended = false; > + } > + > + qcom_pcie_icc_update(pcie); > + > + return 0; > +} > + > static const struct of_device_id qcom_pcie_match[] = { > { .compatible = "qcom,pcie-apq8064", .data = &cfg_2_1_0 }, > { .compatible = "qcom,pcie-apq8084", .data = &cfg_1_0_0 }, > @@ -1870,12 +1917,17 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x0302, qcom_fixup_class); > DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x1000, qcom_fixup_class); > DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x1001, qcom_fixup_class); > > +static const struct dev_pm_ops qcom_pcie_pm_ops = { > + NOIRQ_SYSTEM_SLEEP_PM_OPS(qcom_pcie_suspend_noirq, qcom_pcie_resume_noirq) > +}; > + > static struct platform_driver qcom_pcie_driver = { > .probe = qcom_pcie_probe, > .remove = qcom_pcie_remove, > .driver = { > .name = "qcom-pcie", > .of_match_table = qcom_pcie_match, > + .pm = &qcom_pcie_pm_ops, > }, > }; > module_platform_driver(qcom_pcie_driver); Out of curiosity, were you able to measure how much power you were able to save after adding suspend support for PCIe? I don't know if clock gating really saves much amount of power, but yeah its true that we can't really cut off the power domain entirely in this case.
On Tue, Jan 03, 2023 at 01:19:07PM +0530, Manivannan Sadhasivam wrote: > During the system suspend, vote for minimal interconnect bandwidth and > also turn OFF the resources like clock and PHY if there are no active > devices connected to the controller. For the controllers with active > devices, the resources are kept ON as removing the resources will > trigger access violation during the late end of suspend cycle as kernel > tries to access the config space of PCIe devices to mask the 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 storage devices like NVMe. > > And finally, during resume, turn ON the resources if the controller was > truly suspended (resources OFF) and update the interconnect bandwidth > based on PCIe Gen speed. > > Suggested-by: Krishna chaitanya chundru <quic_krichai@quicinc.com> > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> > --- > drivers/pci/controller/dwc/pcie-qcom.c | 52 ++++++++++++++++++++++++++ > 1 file changed, 52 insertions(+) I just gave this a quick spin on the sc8280xp-crd, and unfortunately this change appears to break suspend (e.g. hangs during suspend or resume). Setting a non-zero (250 MBps) peak bandwidth during suspend makes things work again. Presumably something is relying on these interconnect clocks to remain enabled. And isn't that expected as we need to set a non-zero icc bw to enable the interconnect clocks during probe? I'm afraid I won't have time to look into this for a while myself, but have you tried this on the CRD, Mani? One obvious difference is the modem on the CRD which I believe neither of our X13s have, but this seems like more of a general problem. Johan
On Tue, Jan 03, 2023 at 02:16:47PM +0100, Johan Hovold wrote: > On Tue, Jan 03, 2023 at 01:19:07PM +0530, Manivannan Sadhasivam wrote: > > During the system suspend, vote for minimal interconnect bandwidth and > > also turn OFF the resources like clock and PHY if there are no active > > devices connected to the controller. For the controllers with active > > devices, the resources are kept ON as removing the resources will > > trigger access violation during the late end of suspend cycle as kernel > > tries to access the config space of PCIe devices to mask the 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 storage devices like NVMe. > > > > And finally, during resume, turn ON the resources if the controller was > > truly suspended (resources OFF) and update the interconnect bandwidth > > based on PCIe Gen speed. > > > > Suggested-by: Krishna chaitanya chundru <quic_krichai@quicinc.com> > > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> > > --- > > drivers/pci/controller/dwc/pcie-qcom.c | 52 ++++++++++++++++++++++++++ > > 1 file changed, 52 insertions(+) > > I just gave this a quick spin on the sc8280xp-crd, and unfortunately > this change appears to break suspend (e.g. hangs during suspend or > resume). Setting a non-zero (250 MBps) peak bandwidth during suspend > makes things work again. > > Presumably something is relying on these interconnect clocks to remain > enabled. And isn't that expected as we need to set a non-zero icc bw to > enable the interconnect clocks during probe? > After suspend, I assumed that there won't be any access to the controller specific registers, so thought it should be fine. And it works on X13s too. Maybe, the access to device config space is triggering issues on CRD? I will check with Qcom. > I'm afraid I won't have time to look into this for a while myself, but > have you tried this on the CRD, Mani? > Thanks for testing, Johan! I did not test this on CRD. Since both X13s and CRD are sharing the same SoC, I thought it would work on CRD too. But since you have tested and reported the issue, I will look into it. > One obvious difference is the modem on the CRD which I believe neither > of our X13s have, but this seems like more of a general problem. > Yeah, this seems to be a platform issue. I will check on this behaviour and report back. Thanks, Mani > Johan
On Tue, Jan 03, 2023 at 04:46:11PM +0530, Dhruva Gole wrote: > > > On 03/01/23 13:19, Manivannan Sadhasivam wrote: > > During the system suspend, vote for minimal interconnect bandwidth and > > also turn OFF the resources like clock and PHY if there are no active > > devices connected to the controller. For the controllers with active > > devices, the resources are kept ON as removing the resources will > > trigger access violation during the late end of suspend cycle as kernel > > tries to access the config space of PCIe devices to mask the 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 storage devices like NVMe. > > > > And finally, during resume, turn ON the resources if the controller was > > truly suspended (resources OFF) and update the interconnect bandwidth > > based on PCIe Gen speed. > > > > Suggested-by: Krishna chaitanya chundru <quic_krichai@quicinc.com> > > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> > > --- > > Nice to have another driver added to the list of system suspend > support! > > Acked-by: Dhruva Gole <d-gole@ti.com> > > > drivers/pci/controller/dwc/pcie-qcom.c | 52 ++++++++++++++++++++++++++ > > 1 file changed, 52 insertions(+) > > > > diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c > > index 5696e327795b..48810f1f2dba 100644 > > --- a/drivers/pci/controller/dwc/pcie-qcom.c > > +++ b/drivers/pci/controller/dwc/pcie-qcom.c > > @@ -227,6 +227,7 @@ struct qcom_pcie { > > struct gpio_desc *reset; > > struct icc_path *icc_mem; > > const struct qcom_pcie_cfg *cfg;qcom_pcie_icc_update > > + bool suspended; > > }; > > #define to_qcom_pcie(x) dev_get_drvdata((x)->dev) > > @@ -1835,6 +1836,52 @@ static int qcom_pcie_remove(struct platform_device *pdev) > > return 0; > > } > > +static int qcom_pcie_suspend_noirq(struct device *dev) > > +{ > > + struct qcom_pcie *pcie = dev_get_drvdata(dev); > > + int ret; > > + > > + ret = icc_set_bw(pcie->icc_mem, 0, 0); > > + if (ret) { > > + dev_err(pcie->pci->dev, "Failed to set interconnect bandwidth: %d\n", ret); > > + return ret; > > + } > > + > > + /* > > + * 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; > > + } > > + > > + return 0; > > +} > > + > > +static int qcom_pcie_resume_noirq(struct device *dev) > > +{ > > + struct qcom_pcie *pcie = dev_get_drvdata(dev); > > + > > + if (pcie->suspended) { > > + qcom_pcie_host_init(&pcie->pci->pp); > > + pcie->suspended = false; > > + } > > + > > + qcom_pcie_icc_update(pcie); > > + > > + return 0; > > +} > > + > > static const struct of_device_id qcom_pcie_match[] = { > > { .compatible = "qcom,pcie-apq8064", .data = &cfg_2_1_0 }, > > { .compatible = "qcom,pcie-apq8084", .data = &cfg_1_0_0 }, > > @@ -1870,12 +1917,17 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x0302, qcom_fixup_class); > > DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x1000, qcom_fixup_class); > > DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x1001, qcom_fixup_class); > > +static const struct dev_pm_ops qcom_pcie_pm_ops = { > > + NOIRQ_SYSTEM_SLEEP_PM_OPS(qcom_pcie_suspend_noirq, qcom_pcie_resume_noirq) > > +}; > > + > > static struct platform_driver qcom_pcie_driver = { > > .probe = qcom_pcie_probe, > > .remove = qcom_pcie_remove, > > .driver = { > > .name = "qcom-pcie", > > .of_match_table = qcom_pcie_match, > > + .pm = &qcom_pcie_pm_ops, > > }, > > }; > > module_platform_driver(qcom_pcie_driver); > > Out of curiosity, were you able to measure how much power you were able > to save after adding suspend support for PCIe? I don't know if clock > gating really saves much amount of power, but yeah its true that we > can't really cut off the power domain entirely in this case. > I did not measure the power consumption and I agree that we won't save much power with setting icc bandwidth to 0. But it is better to have something than nothing. And in the coming days, I have plans to look into other power saving measures also. Thanks, Mani > -- > Thanks and Regards, > Dhruva Gole
On Thu, Jan 05, 2023 at 07:06:39PM +0530, Manivannan Sadhasivam wrote: > On Tue, Jan 03, 2023 at 04:46:11PM +0530, Dhruva Gole wrote: > > > > > > On 03/01/23 13:19, Manivannan Sadhasivam wrote: > > > During the system suspend, vote for minimal interconnect bandwidth and > > > also turn OFF the resources like clock and PHY if there are no active > > > devices connected to the controller. For the controllers with active > > > devices, the resources are kept ON as removing the resources will > > > trigger access violation during the late end of suspend cycle as kernel > > > tries to access the config space of PCIe devices to mask the 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 storage devices like NVMe. > > > > > > And finally, during resume, turn ON the resources if the controller was > > > truly suspended (resources OFF) and update the interconnect bandwidth > > > based on PCIe Gen speed. > > > > > > Suggested-by: Krishna chaitanya chundru <quic_krichai@quicinc.com> > > > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> > > > --- > > > > Nice to have another driver added to the list of system suspend > > support! > > > > Acked-by: Dhruva Gole <d-gole@ti.com> > > > > > drivers/pci/controller/dwc/pcie-qcom.c | 52 ++++++++++++++++++++++++++ > > > 1 file changed, 52 insertions(+) > > > > > > diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c > > > index 5696e327795b..48810f1f2dba 100644 > > > --- a/drivers/pci/controller/dwc/pcie-qcom.c > > > +++ b/drivers/pci/controller/dwc/pcie-qcom.c > > > @@ -227,6 +227,7 @@ struct qcom_pcie { > > > struct gpio_desc *reset; > > > struct icc_path *icc_mem; > > > const struct qcom_pcie_cfg *cfg;qcom_pcie_icc_update > > > + bool suspended; > > > }; > > > #define to_qcom_pcie(x) dev_get_drvdata((x)->dev) > > > @@ -1835,6 +1836,52 @@ static int qcom_pcie_remove(struct platform_device *pdev) > > > return 0; > > > } > > > +static int qcom_pcie_suspend_noirq(struct device *dev) > > > +{ > > > + struct qcom_pcie *pcie = dev_get_drvdata(dev); > > > + int ret; > > > + > > > + ret = icc_set_bw(pcie->icc_mem, 0, 0); > > > + if (ret) { > > > + dev_err(pcie->pci->dev, "Failed to set interconnect bandwidth: %d\n", ret); > > > + return ret; > > > + } > > > + > > > + /* > > > + * 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; > > > + } > > > + > > > + return 0; > > > +} > > > + > > > +static int qcom_pcie_resume_noirq(struct device *dev) > > > +{ > > > + struct qcom_pcie *pcie = dev_get_drvdata(dev); > > > + > > > + if (pcie->suspended) { > > > + qcom_pcie_host_init(&pcie->pci->pp); > > > + pcie->suspended = false; > > > + } > > > + > > > + qcom_pcie_icc_update(pcie); > > > + > > > + return 0; > > > +} > > > + > > > static const struct of_device_id qcom_pcie_match[] = { > > > { .compatible = "qcom,pcie-apq8064", .data = &cfg_2_1_0 }, > > > { .compatible = "qcom,pcie-apq8084", .data = &cfg_1_0_0 }, > > > @@ -1870,12 +1917,17 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x0302, qcom_fixup_class); > > > DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x1000, qcom_fixup_class); > > > DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x1001, qcom_fixup_class); > > > +static const struct dev_pm_ops qcom_pcie_pm_ops = { > > > + NOIRQ_SYSTEM_SLEEP_PM_OPS(qcom_pcie_suspend_noirq, qcom_pcie_resume_noirq) > > > +}; > > > + > > > static struct platform_driver qcom_pcie_driver = { > > > .probe = qcom_pcie_probe, > > > .remove = qcom_pcie_remove, > > > .driver = { > > > .name = "qcom-pcie", > > > .of_match_table = qcom_pcie_match, > > > + .pm = &qcom_pcie_pm_ops, > > > }, > > > }; > > > module_platform_driver(qcom_pcie_driver); > > > > Out of curiosity, were you able to measure how much power you were able > > to save after adding suspend support for PCIe? I don't know if clock > > gating really saves much amount of power, but yeah its true that we > > can't really cut off the power domain entirely in this case. > > > > I did not measure the power consumption and I agree that we won't save much > power with setting icc bandwidth to 0. But it is better to have something > than nothing. And in the coming days, I have plans to look into other power > saving measures also. On a sc7280 system I see a reduction of ~30mW with this patch when no PCI card is plugged in. The reduction seems to come from powering the PHY down. Interestingly on that system power consumption during suspend (without this patch) is ~30mW higher *without* a PCI card vs. with a card. Maybe the PHY doesn't enter a low power mode when no card is plugged in?
On Fri, Jan 06, 2023 at 06:17:19PM +0000, Matthias Kaehlcke wrote: > On Thu, Jan 05, 2023 at 07:06:39PM +0530, Manivannan Sadhasivam wrote: > > On Tue, Jan 03, 2023 at 04:46:11PM +0530, Dhruva Gole wrote: > > > > > > > > > On 03/01/23 13:19, Manivannan Sadhasivam wrote: > > > > During the system suspend, vote for minimal interconnect bandwidth and > > > > also turn OFF the resources like clock and PHY if there are no active > > > > devices connected to the controller. For the controllers with active > > > > devices, the resources are kept ON as removing the resources will > > > > trigger access violation during the late end of suspend cycle as kernel > > > > tries to access the config space of PCIe devices to mask the 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 storage devices like NVMe. > > > > > > > > And finally, during resume, turn ON the resources if the controller was > > > > truly suspended (resources OFF) and update the interconnect bandwidth > > > > based on PCIe Gen speed. > > > > > > > > Suggested-by: Krishna chaitanya chundru <quic_krichai@quicinc.com> > > > > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> > > > > --- > > > > > > Nice to have another driver added to the list of system suspend > > > support! > > > > > > Acked-by: Dhruva Gole <d-gole@ti.com> > > > > > > > drivers/pci/controller/dwc/pcie-qcom.c | 52 ++++++++++++++++++++++++++ > > > > 1 file changed, 52 insertions(+) > > > > > > > > diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c > > > > index 5696e327795b..48810f1f2dba 100644 > > > > --- a/drivers/pci/controller/dwc/pcie-qcom.c > > > > +++ b/drivers/pci/controller/dwc/pcie-qcom.c > > > > @@ -227,6 +227,7 @@ struct qcom_pcie { > > > > struct gpio_desc *reset; > > > > struct icc_path *icc_mem; > > > > const struct qcom_pcie_cfg *cfg;qcom_pcie_icc_update > > > > + bool suspended; > > > > }; > > > > #define to_qcom_pcie(x) dev_get_drvdata((x)->dev) > > > > @@ -1835,6 +1836,52 @@ static int qcom_pcie_remove(struct platform_device *pdev) > > > > return 0; > > > > } > > > > +static int qcom_pcie_suspend_noirq(struct device *dev) > > > > +{ > > > > + struct qcom_pcie *pcie = dev_get_drvdata(dev); > > > > + int ret; > > > > + > > > > + ret = icc_set_bw(pcie->icc_mem, 0, 0); > > > > + if (ret) { > > > > + dev_err(pcie->pci->dev, "Failed to set interconnect bandwidth: %d\n", ret); > > > > + return ret; > > > > + } > > > > + > > > > + /* > > > > + * 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; > > > > + } > > > > + > > > > + return 0; > > > > +} > > > > + > > > > +static int qcom_pcie_resume_noirq(struct device *dev) > > > > +{ > > > > + struct qcom_pcie *pcie = dev_get_drvdata(dev); > > > > + > > > > + if (pcie->suspended) { > > > > + qcom_pcie_host_init(&pcie->pci->pp); > > > > + pcie->suspended = false; > > > > + } > > > > + > > > > + qcom_pcie_icc_update(pcie); > > > > + > > > > + return 0; > > > > +} > > > > + > > > > static const struct of_device_id qcom_pcie_match[] = { > > > > { .compatible = "qcom,pcie-apq8064", .data = &cfg_2_1_0 }, > > > > { .compatible = "qcom,pcie-apq8084", .data = &cfg_1_0_0 }, > > > > @@ -1870,12 +1917,17 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x0302, qcom_fixup_class); > > > > DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x1000, qcom_fixup_class); > > > > DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x1001, qcom_fixup_class); > > > > +static const struct dev_pm_ops qcom_pcie_pm_ops = { > > > > + NOIRQ_SYSTEM_SLEEP_PM_OPS(qcom_pcie_suspend_noirq, qcom_pcie_resume_noirq) > > > > +}; > > > > + > > > > static struct platform_driver qcom_pcie_driver = { > > > > .probe = qcom_pcie_probe, > > > > .remove = qcom_pcie_remove, > > > > .driver = { > > > > .name = "qcom-pcie", > > > > .of_match_table = qcom_pcie_match, > > > > + .pm = &qcom_pcie_pm_ops, > > > > }, > > > > }; > > > > module_platform_driver(qcom_pcie_driver); > > > > > > Out of curiosity, were you able to measure how much power you were able > > > to save after adding suspend support for PCIe? I don't know if clock > > > gating really saves much amount of power, but yeah its true that we > > > can't really cut off the power domain entirely in this case. > > > > > > > I did not measure the power consumption and I agree that we won't save much > > power with setting icc bandwidth to 0. But it is better to have something > > than nothing. And in the coming days, I have plans to look into other power > > saving measures also. > > On a sc7280 system I see a reduction of ~30mW with this patch when no PCI > card is plugged in. The reduction seems to come from powering the PHY down. > Thanks a lot for testing! > Interestingly on that system power consumption during suspend (without this > patch) is ~30mW higher *without* a PCI card vs. with a card. Maybe the PHY > doesn't enter a low power mode when no card is plugged in? Yeah, both PHY and controllers are never put into low power mode even if there are no devices connected. I don't know if the low power mode is possible at all with PHY. Thanks, Mani
On Sat, Jan 07, 2023 at 12:32:52AM +0530, Manivannan Sadhasivam wrote: > On Fri, Jan 06, 2023 at 06:17:19PM +0000, Matthias Kaehlcke wrote: > > On Thu, Jan 05, 2023 at 07:06:39PM +0530, Manivannan Sadhasivam wrote: > > > On Tue, Jan 03, 2023 at 04:46:11PM +0530, Dhruva Gole wrote: > > > > > > > > > > > > On 03/01/23 13:19, Manivannan Sadhasivam wrote: > > > > > During the system suspend, vote for minimal interconnect bandwidth and > > > > > also turn OFF the resources like clock and PHY if there are no active > > > > > devices connected to the controller. For the controllers with active > > > > > devices, the resources are kept ON as removing the resources will > > > > > trigger access violation during the late end of suspend cycle as kernel > > > > > tries to access the config space of PCIe devices to mask the 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 storage devices like NVMe. > > > > > > > > > > And finally, during resume, turn ON the resources if the controller was > > > > > truly suspended (resources OFF) and update the interconnect bandwidth > > > > > based on PCIe Gen speed. > > > > > > > > > > Suggested-by: Krishna chaitanya chundru <quic_krichai@quicinc.com> > > > > > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> > > > > > --- > > > > > > > > Nice to have another driver added to the list of system suspend > > > > support! > > > > > > > > Acked-by: Dhruva Gole <d-gole@ti.com> > > > > > > > > > drivers/pci/controller/dwc/pcie-qcom.c | 52 ++++++++++++++++++++++++++ > > > > > 1 file changed, 52 insertions(+) > > > > > > > > > > diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c > > > > > index 5696e327795b..48810f1f2dba 100644 > > > > > --- a/drivers/pci/controller/dwc/pcie-qcom.c > > > > > +++ b/drivers/pci/controller/dwc/pcie-qcom.c > > > > > @@ -227,6 +227,7 @@ struct qcom_pcie { > > > > > struct gpio_desc *reset; > > > > > struct icc_path *icc_mem; > > > > > const struct qcom_pcie_cfg *cfg;qcom_pcie_icc_update > > > > > + bool suspended; > > > > > }; > > > > > #define to_qcom_pcie(x) dev_get_drvdata((x)->dev) > > > > > @@ -1835,6 +1836,52 @@ static int qcom_pcie_remove(struct platform_device *pdev) > > > > > return 0; > > > > > } > > > > > +static int qcom_pcie_suspend_noirq(struct device *dev) > > > > > +{ > > > > > + struct qcom_pcie *pcie = dev_get_drvdata(dev); > > > > > + int ret; > > > > > + > > > > > + ret = icc_set_bw(pcie->icc_mem, 0, 0); > > > > > + if (ret) { > > > > > + dev_err(pcie->pci->dev, "Failed to set interconnect bandwidth: %d\n", ret); > > > > > + return ret; > > > > > + } > > > > > + > > > > > + /* > > > > > + * 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; > > > > > + } > > > > > + > > > > > + return 0; > > > > > +} > > > > > + > > > > > +static int qcom_pcie_resume_noirq(struct device *dev) > > > > > +{ > > > > > + struct qcom_pcie *pcie = dev_get_drvdata(dev); > > > > > + > > > > > + if (pcie->suspended) { > > > > > + qcom_pcie_host_init(&pcie->pci->pp); > > > > > + pcie->suspended = false; > > > > > + } > > > > > + > > > > > + qcom_pcie_icc_update(pcie); > > > > > + > > > > > + return 0; > > > > > +} > > > > > + > > > > > static const struct of_device_id qcom_pcie_match[] = { > > > > > { .compatible = "qcom,pcie-apq8064", .data = &cfg_2_1_0 }, > > > > > { .compatible = "qcom,pcie-apq8084", .data = &cfg_1_0_0 }, > > > > > @@ -1870,12 +1917,17 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x0302, qcom_fixup_class); > > > > > DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x1000, qcom_fixup_class); > > > > > DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x1001, qcom_fixup_class); > > > > > +static const struct dev_pm_ops qcom_pcie_pm_ops = { > > > > > + NOIRQ_SYSTEM_SLEEP_PM_OPS(qcom_pcie_suspend_noirq, qcom_pcie_resume_noirq) > > > > > +}; > > > > > + > > > > > static struct platform_driver qcom_pcie_driver = { > > > > > .probe = qcom_pcie_probe, > > > > > .remove = qcom_pcie_remove, > > > > > .driver = { > > > > > .name = "qcom-pcie", > > > > > .of_match_table = qcom_pcie_match, > > > > > + .pm = &qcom_pcie_pm_ops, > > > > > }, > > > > > }; > > > > > module_platform_driver(qcom_pcie_driver); > > > > > > > > Out of curiosity, were you able to measure how much power you were able > > > > to save after adding suspend support for PCIe? I don't know if clock > > > > gating really saves much amount of power, but yeah its true that we > > > > can't really cut off the power domain entirely in this case. > > > > > > > > > > I did not measure the power consumption and I agree that we won't save much > > > power with setting icc bandwidth to 0. But it is better to have something > > > than nothing. And in the coming days, I have plans to look into other power > > > saving measures also. > > > > On a sc7280 system I see a reduction of ~30mW with this patch when no PCI > > card is plugged in. The reduction seems to come from powering the PHY down. > > > > Thanks a lot for testing! > > > Interestingly on that system power consumption during suspend (without this > > patch) is ~30mW higher *without* a PCI card vs. with a card. Maybe the PHY > > doesn't enter a low power mode when no card is plugged in? > > Yeah, both PHY and controllers are never put into low power mode even if there > are no devices connected. I don't know if the low power mode is possible at > all with PHY. It's still interesting that the PHY apparently at least enters a *lower* power mode when a card is plugged in, the extra 30mW are only seen without a card.
diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index 5696e327795b..48810f1f2dba 100644 --- a/drivers/pci/controller/dwc/pcie-qcom.c +++ b/drivers/pci/controller/dwc/pcie-qcom.c @@ -227,6 +227,7 @@ struct qcom_pcie { struct gpio_desc *reset; struct icc_path *icc_mem; const struct qcom_pcie_cfg *cfg; + bool suspended; }; #define to_qcom_pcie(x) dev_get_drvdata((x)->dev) @@ -1835,6 +1836,52 @@ static int qcom_pcie_remove(struct platform_device *pdev) return 0; } +static int qcom_pcie_suspend_noirq(struct device *dev) +{ + struct qcom_pcie *pcie = dev_get_drvdata(dev); + int ret; + + ret = icc_set_bw(pcie->icc_mem, 0, 0); + if (ret) { + dev_err(pcie->pci->dev, "Failed to set interconnect bandwidth: %d\n", ret); + return ret; + } + + /* + * 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; + } + + return 0; +} + +static int qcom_pcie_resume_noirq(struct device *dev) +{ + struct qcom_pcie *pcie = dev_get_drvdata(dev); + + if (pcie->suspended) { + qcom_pcie_host_init(&pcie->pci->pp); + pcie->suspended = false; + } + + qcom_pcie_icc_update(pcie); + + return 0; +} + static const struct of_device_id qcom_pcie_match[] = { { .compatible = "qcom,pcie-apq8064", .data = &cfg_2_1_0 }, { .compatible = "qcom,pcie-apq8084", .data = &cfg_1_0_0 }, @@ -1870,12 +1917,17 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x0302, qcom_fixup_class); DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x1000, qcom_fixup_class); DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_QCOM, 0x1001, qcom_fixup_class); +static const struct dev_pm_ops qcom_pcie_pm_ops = { + NOIRQ_SYSTEM_SLEEP_PM_OPS(qcom_pcie_suspend_noirq, qcom_pcie_resume_noirq) +}; + static struct platform_driver qcom_pcie_driver = { .probe = qcom_pcie_probe, .remove = qcom_pcie_remove, .driver = { .name = "qcom-pcie", .of_match_table = qcom_pcie_match, + .pm = &qcom_pcie_pm_ops, }, }; module_platform_driver(qcom_pcie_driver);