From patchwork Thu Mar 2 08:36:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 63280 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp4120126wrd; Thu, 2 Mar 2023 00:43:18 -0800 (PST) X-Google-Smtp-Source: AK7set8PtvoUjkZHT79v6413UVH7j77pUFLlAd+xA2iIEjDRyrQY7+GPnYHI/Tj+wwcjo2z4zVwM X-Received: by 2002:a05:6402:451:b0:4af:59c0:5add with SMTP id p17-20020a056402045100b004af59c05addmr8794013edw.37.1677746598157; Thu, 02 Mar 2023 00:43:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677746598; cv=none; d=google.com; s=arc-20160816; b=V/RIhKVKvpIYrq+RJ8meve4vH7pf1UPNGlBfa8h+P8lj05oTk7yAzGoHT/42E98bKD /zax6jovxcCa7RRp36jnERp5pcK7L/Ps8UIcoeiHsKTCT3anclNNEgCHmwC1TYEZQ0R1 IFZONUKYmZ4ZPDHULXUpsb8Ld2S1kSpvIXdD7AEgpVcImlG9xszHaRfPTLwGCIoN35Ig WgebmN72qZtqhWg0Z8ymxEzpWjiU1AqyEuXO+xM3OeZCmlyly/mwnboHlpXrS8UNw6c2 fVqKoNYvzRqOZASd5CYuf2kfIZqyd8zwDkSCc+gpvAUvmjQlJCsyfeh+5IoAdWKPTb7C tY9A== 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=jmxYusaZZcaCSm0sR5ZUszZ82Vp7I8hpbdJ8Cb+CdPo=; b=Kr7knKNLo98UsCHYUYHTbG71hwYGgbz0Hxj7RU1kD6rYaTOkMkKFEPamrdc/gB3a8l aXDUiOvsbAYc1BcUrsGvq/GamzZDPtfP1l7UxXubDpknzfAJiJkf/qwWNjcExjCfVOWK 7cArKrLsnBDqUKKDpLA8q9WBX8DCgnRWtZhXp9TkbPbh3qouj23kYF4ljPIs804s6ZKM f+1gP9o6al0+HjnfGYQhJcSsnOtHOa5jRmQqzIVBdcxXZDhbwwcAUl24KVKd1XvaKSQ9 w9xNjeGmTFcsgeOFZvsbcIL8BPv6AWBcO8lrJ6I/1KsneoXJlDc16HbsnJAPznyxcRq/ TIvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r9craTUy; 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 d21-20020aa7ce15000000b004bf6ddc13d8si2101247edv.439.2023.03.02.00.42.55; Thu, 02 Mar 2023 00:43:18 -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=r9craTUy; 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 S229739AbjCBIgq (ORCPT + 99 others); Thu, 2 Mar 2023 03:36:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbjCBIgl (ORCPT ); Thu, 2 Mar 2023 03:36:41 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2338C126C9 for ; Thu, 2 Mar 2023 00:36:40 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id y11so12652180plg.1 for ; Thu, 02 Mar 2023 00:36:40 -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=jmxYusaZZcaCSm0sR5ZUszZ82Vp7I8hpbdJ8Cb+CdPo=; b=r9craTUyVx3uiDtRuxr4/PsO6K1XvUWzzxWl78/dUjOl/L8wD227JYgVbaPKALXV7d AwT7JyTJwWwqbbltakIJvLX7CLUB9tmZ1FAl26xyS0zQ4e2XWy2rNSyswo+znHykXIiC L64ErgYtW/eym+pT0buE046/tPbGvVYkktuAY8B6bPd8sNrozAnmkfHC/vmZLEAOoMp3 M4qfTRtDIzP6p9xtkg40jGtlNXciUo0Qs2fXCIdEmBrglff/9oNBHZIWaxlkD1cMMpzg c2+DVFhE+Ma6GV881wTGMjyGitPtrtUuS8A3BgZf7ykT6iVpDyqmxJh1+m01dAvEkO4M JaWw== 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=jmxYusaZZcaCSm0sR5ZUszZ82Vp7I8hpbdJ8Cb+CdPo=; b=J5oJip+y51aPKj3ejD0M8+ps6uE9HK36VbruduzIGGhP0rGqtxiiKP0Gnso5RD9OQM CsOFZbAhomQ1J7Qm5GI0ZYhXzL33S/d6N6EfuPQn0iBOK6rq1QIJD+C3nyr9t7kUHGH0 4ftYlF2aTZ1+pC5hHygspQLlzeNUrFC2esp7w2ghTjxozyVv+MsyWzrzzcwzFfc+8vSK 69eG2mKjni5z8JFfOv694tCe9/yTDQwUUFMZ9sfHTFaFYi3jyTGxOKNDE7VMHv+Asb2x 0dW51qG6dkkBHSZDSP+LmSwpbjJX/OV1d2Z2/aBZB2kridNH3RYm6nUatLrL2jQEyhh8 QJ8w== X-Gm-Message-State: AO0yUKVDix+4RrOBOYxZtKcGfaptO34seQ+fwHgWiTXI2PCV7qKEHryt brstpXFsMA0KU6nJZeLWlRdA X-Received: by 2002:a17:902:da90:b0:19c:e405:4446 with SMTP id j16-20020a170902da9000b0019ce4054446mr10433381plx.30.1677746199325; Thu, 02 Mar 2023 00:36:39 -0800 (PST) Received: from localhost.localdomain ([59.97.53.52]) by smtp.gmail.com with ESMTPSA id p7-20020a1709028a8700b00198ef93d556sm9791912plo.147.2023.03.02.00.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 00:36:38 -0800 (PST) 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 v2 1/1] PCI: qcom: Add support for system suspend and resume Date: Thu, 2 Mar 2023 14:06:25 +0530 Message-Id: <20230302083625.188482-2-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230302083625.188482-1-manivannan.sadhasivam@linaro.org> References: <20230302083625.188482-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759244558923001577?= X-GMAIL-MSGID: =?utf-8?q?1759244816786566199?= 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 | 53 ++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index a232b04af048..7147f0103026 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) @@ -1820,6 +1821,53 @@ static int qcom_pcie_probe(struct platform_device *pdev) return ret; } +static int qcom_pcie_suspend_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 */ + ret = icc_set_bw(pcie->icc_mem, 0, MBps_to_icc(250)); + 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 }, @@ -1856,12 +1904,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, .driver = { .name = "qcom-pcie", .suppress_bind_attrs = true, .of_match_table = qcom_pcie_match, + .pm = &qcom_pcie_pm_ops, }, }; builtin_platform_driver(qcom_pcie_driver);