From nobody Mon Feb 9 12:45:47 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54BD7C761A6 for ; Mon, 27 Mar 2023 13:39:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232693AbjC0Ni7 (ORCPT ); Mon, 27 Mar 2023 09:38:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232637AbjC0Niq (ORCPT ); Mon, 27 Mar 2023 09:38:46 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F23E059D8 for ; Mon, 27 Mar 2023 06:38:40 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id f22so4336898plr.0 for ; Mon, 27 Mar 2023 06:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679924320; 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=JlUhxZtTocfXELpvEKmzZqrwx3UgsE37/RP0AJKegdQ=; b=X5+yPGerKGUvVqU1BxVZnvCpGawgV7XhiAR2mK8UUv9lQIFnBiqh39gQg269ZE6OB2 wFFGi+NXsOwuF3sVuHXozgNz2VK4PHZtAB8+Y7YcfcEX/ec63ML0qsW/JDRVLUUkrcf/ iqLj7XTLRyBatYSIZhQfpE5xPO+QQbIzymWnlZhcmJ4UNhPXC3O7BhhUdN+m46jK6Prk OnmJ1xGc8kijdV3KrYdgGaYKcETSvgj8MbsBjWyI3jR0cL+yDDtV9G4eW71QZH48o1C/ dRcba60Ny9CEfxv9bZ/cLsg1pvhl+EyfM6XWthg4kSxhuRK/NvBrXIMwJXagJnRnTGQP Q7/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679924320; 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=JlUhxZtTocfXELpvEKmzZqrwx3UgsE37/RP0AJKegdQ=; b=IimXSm4M6qLwCUCTVF1kiJtVeePZitYIFz4OuDTH+SY1eq1eSd73w2b9a/JFrU4oMJ p+Ar3UoRNUBfjPew4rwAFKWEzDPJzV4yzBG1fmYUWCAyLdfQUzr1S2vUDIos0XuW39vf Vu1FtkPv4Jp40IV0nMhdxQ2wUVLfXJiB5srvG5Wx4aC6prRbkl7xvrFQLpSF21fSWz7g 2gLuI5tx8WebjMgIqXVEONvWdLY2s8S3ugYPygeCSJdwvJmak8LViMZE/qT/03cdv8kQ JJGRxO/1VxlpSFvPljABF/kjbtWzL0hLkXEOMKzi4G+D0/jo7zQXRcZ7Mpfjr2hoE/LH T/nQ== X-Gm-Message-State: AAQBX9czcg0HAMhkGRTR3k0NMzoYPEebfBrVunF7l56oSRZagiYjsEi5 rmECb+GLYl3LDRFBDPjyR9zN X-Google-Smtp-Source: AKy350bH0Ne6ntCWly/rerByN7MgS/5gUCbKt3pHvbZ0h+Bnd/tYsp/HB9lhC7tJCPWa/0QqRDZbtA== X-Received: by 2002:a17:902:fb08:b0:1a2:1fb9:3b2 with SMTP id le8-20020a170902fb0800b001a21fb903b2mr9573410plb.11.1679924320374; Mon, 27 Mar 2023 06:38:40 -0700 (PDT) Received: from localhost.localdomain ([117.193.215.38]) by smtp.gmail.com with ESMTPSA id p6-20020a1709028a8600b00194c2f78581sm19187668plo.199.2023.03.27.06.38.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 06:38:40 -0700 (PDT) From: Manivannan Sadhasivam To: lpieralisi@kernel.org, kw@linux.com, robh@kernel.org Cc: andersson@kernel.org, konrad.dybcio@linaro.org, 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, mka@chromium.org, Manivannan Sadhasivam , Dhruva Gole Subject: [PATCH v3 1/1] PCI: qcom: Add support for system suspend and resume Date: Mon, 27 Mar 2023 19:08:24 +0530 Message-Id: <20230327133824.29136-2-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230327133824.29136-1-manivannan.sadhasivam@linaro.org> References: <20230327133824.29136-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Acked-by: Dhruva Gole Signed-off-by: Manivannan Sadhasivam --- drivers/pci/controller/dwc/pcie-qcom.c | 62 ++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controlle= r/dwc/pcie-qcom.c index a232b04af048..f33df536d9be 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; }; =20 #define to_qcom_pcie(x) dev_get_drvdata((x)->dev) @@ -1820,6 +1821,62 @@ static int qcom_pcie_probe(struct platform_device *p= dev) return ret; } =20 +static int qcom_pcie_suspend_noirq(struct device *dev) +{ + struct qcom_pcie *pcie =3D dev_get_drvdata(dev); + int ret; + + /* + * Set minimum bandwidth required to keep data path functional during + * suspend. + */ + ret =3D icc_set_bw(pcie->icc_mem, 0, MBps_to_icc(250)); + if (ret) { + dev_err(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 =3D true; + } + + return 0; +} + +static int qcom_pcie_resume_noirq(struct device *dev) +{ + struct qcom_pcie *pcie =3D dev_get_drvdata(dev); + int ret; + + if (pcie->suspended) { + ret =3D qcom_pcie_host_init(&pcie->pci->pp); + if (ret) + return ret; + + pcie->suspended =3D false; + } + + qcom_pcie_icc_update(pcie); + + return 0; +} + static const struct of_device_id qcom_pcie_match[] =3D { { .compatible =3D "qcom,pcie-apq8064", .data =3D &cfg_2_1_0 }, { .compatible =3D "qcom,pcie-apq8084", .data =3D &cfg_1_0_0 }, @@ -1856,12 +1913,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); =20 +static const struct dev_pm_ops qcom_pcie_pm_ops =3D { + NOIRQ_SYSTEM_SLEEP_PM_OPS(qcom_pcie_suspend_noirq, qcom_pcie_resume_noirq) +}; + static struct platform_driver qcom_pcie_driver =3D { .probe =3D qcom_pcie_probe, .driver =3D { .name =3D "qcom-pcie", .suppress_bind_attrs =3D true, .of_match_table =3D qcom_pcie_match, + .pm =3D &qcom_pcie_pm_ops, }, }; builtin_platform_driver(qcom_pcie_driver); --=20 2.25.1