Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp2013006lqg; Mon, 4 Mar 2024 10:05:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWksyo0YqjOv5loBBgL6Q4sSxilt1fh7Eh4AXrpocBSJOU9J+FKDR2920a76vXnSqujTVNNtwDv7BIoiIeBRUtiy6R8zeJ4djYQYPj8Kg== X-Google-Smtp-Source: AGHT+IGjDtoRw2dLRiPzvgDjNGU5lAVmOYwL6bb6TeUnGtdhnRBKtV4pDjOZs8zUNTCvzN690ZjO X-Received: by 2002:a17:906:349a:b0:a45:22e2:bd9 with SMTP id g26-20020a170906349a00b00a4522e20bd9mr2943671ejb.16.1709575545195; Mon, 04 Mar 2024 10:05:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709575545; cv=pass; d=google.com; s=arc-20160816; b=QG5cmVJT6OYIKMxLTcBdvOQCW3V9Qya5P6Eh7ON+8DyVttlX9X4AXSuL1vjfsRC5T2 tD5glsuxqlj7BdXuGFD2sMDJ6ttygMBx7i6Mybggaw1bsevXZgV/A2wfARfvdbqhAKRm aGPpU0FAX52o+0+r04OQ4lNVG5tCJnsDYS1jcvNV1TWYMlsNV33ZQXyJulxRV3FAF2l8 84B7TqF4TsdbcgSPSk2cSILWAx/3j7V8HbGvXdCR9lYIjZFZ6MHbfdPGxrMNPurmdV/2 KSTLtB0uxhgafU39D6JAMoOCJL3hVJXSIv0NZ8H9H58AlI9S/FDgrtA+Mbl4pN0joTEt ZxJA== ARC-Message-Signature: i=2; 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=8YiDpDIM0BycPU613AmPVRr2t9ovVi4sRUPjQzL1Jt8=; fh=G7FOX+4ISUGxLvJA5diFV7lBbyZ1waIrm2h0N4338ls=; b=qh8c6/umAZYIIksNgZUc1LduHLN3Y75sQnpJ8+6xBr3ngDKK6GMz5TCPJPcxVpreuE yrF50/t1yC8uhB4pZzy3za1r4pSaidbzwGgznbH9JKeoO4u7jO+uCJwiCL5MF395DOHX 7MIDjOKciMwGiMrwaOAFSM4t45U7A+Yh89XWHqWOQTMkrtahX02cgAhy07mrLLSiBxbO shpb8m+qFI2c0CR8CQUrIu1Jnhum128fhse39CeXScJdgbfF+FeDFaKRPga6KJGz8IVq upsu+8kbyE1hT4QnNX8YH3YJTQRcVa95MuHeITDrquwcn7vmJWfIfU82dBafihZztfxh VkmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KBo3kTAa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-91057-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91057-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id bp12-20020a17090726cc00b00a43fe0538ecsi4387475ejc.516.2024.03.04.10.05.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 10:05:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-91057-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KBo3kTAa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-91057-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91057-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 am.mirrors.kernel.org (Postfix) with ESMTPS id C03381F25E70 for ; Mon, 4 Mar 2024 18:05:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EAFDF62171; Mon, 4 Mar 2024 18:05:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KBo3kTAa" 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 DC18C6214C; Mon, 4 Mar 2024 18:05:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709575519; cv=none; b=O0JtZFemzaMzAZlux+WdZRhL6jVjxfVdBU5trxMX4bFsle5jmxOrXtT2Ra286kn0wTqRDA/iv1SjrkcXq4nRhcAefJFYwOVC02F9AyyydHdUMylHAJc/dVSov/L5kQ/DhJ0hO2rYKGxHEyMWVzPwx2W3bVB+JDcWDy/z2NJSyX8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709575519; c=relaxed/simple; bh=ITqX/m4LMI7f8HrdMK/9Khp0LrIi2sxZUpdGbycpoq4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iwzIscmA19lg+7KNssadOMtsgNoO+cVlF6EzFQpJPbQwE9BhKPRQavwmqyvia1spQ4HyxQ4mRPFPZ7Sq5QUvFsMSe7tD7EGymy4EOKVdRZlEkMmWujmi5T3Mbr9XW7oK14IttUnFZoZ8x26NO6AQGRhQ5joAyXCXHtw5b6RarbY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KBo3kTAa; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31450C433F1; Mon, 4 Mar 2024 18:05:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709575518; bh=ITqX/m4LMI7f8HrdMK/9Khp0LrIi2sxZUpdGbycpoq4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KBo3kTAatAZMO7zhDLDphgexXMPY6kMyyAMrZXeBasREtmhsiJ7INJNGU5LZycxkP PnSLRTis7zfRKpWD8C+upVt8GMgHwgx4SWF53h8xs6/fZ5XyDewiEFWyGPCrAeoHiT Hegbo+76XaT4Fnok4CEswLxJZ9ac2uJLvxliJh1GzisQTQIByxZfP/NcODa+F5O6Zt fixzstprzsw1vyx01Qb5qw6kGDndKAe6nS+74FCvLftrqaaeWUftjbTaF7cRoVaDYk 3owDU8NFSPAsCLqT1FTgJzulOINYOjS2LB90VXq2+6Cqi/3bgG+d5FyU6l5naNYwW4 IKKnmKAx6P/rA== Date: Mon, 4 Mar 2024 23:35:06 +0530 From: Manivannan Sadhasivam To: Krishna chaitanya chundru Cc: Bjorn Andersson , Konrad Dybcio , Lorenzo Pieralisi , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Rob Herring , Bjorn Helgaas , Krzysztof Kozlowski , Conor Dooley , Manivannan Sadhasivam , Rob Herring , Johan Hovold , Brian Masney , Georgi Djakov , linux-arm-msm@vger.kernel.org, linux-pci@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, vireshk@kernel.org, quic_vbadigan@quicinc.com, quic_skananth@quicinc.com, quic_nitegupt@quicinc.com, quic_parass@quicinc.com Subject: Re: [PATCH v8 7/7] PCI: qcom: Add OPP support to scale performance state of power domain Message-ID: <20240304180506.GE31079@thinkpad> References: <20240302-opp_support-v8-0-158285b86b10@quicinc.com> <20240302-opp_support-v8-7-158285b86b10@quicinc.com> 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: <20240302-opp_support-v8-7-158285b86b10@quicinc.com> On Sat, Mar 02, 2024 at 09:30:01AM +0530, Krishna chaitanya chundru wrote: > QCOM Resource Power Manager-hardened (RPMh) is a hardware block which > maintains hardware state of a regulator by performing max aggregation of > the requests made by all of the clients. > > PCIe controller can operate on different RPMh performance state of power > domain based on the speed of the link. And this performance state varies > from target to target, like some controllers support GEN3 in NOM (Nominal) > voltage corner, while some other supports GEN3 in low SVS (static voltage > scaling). > > The SoC can be more power efficient if we scale the performance state > based on the aggregate PCIe link bandwidth. > > Add Operating Performance Points (OPP) support to vote for RPMh state based > on the aggregate link bandwidth. > > OPP can handle ICC bw voting also, so move ICC bw voting through OPP > framework if OPP entries are present. > > Different link configurations may share the same aggregate bandwidth, > e.g., a 2.5 GT/s x2 link and a 5.0 GT/s x1 link have the same bandwidth > and share the same OPP entry. > > As we are moving ICC voting as part of OPP, don't initialize ICC if OPP > is supported. > > Signed-off-by: Krishna chaitanya chundru > --- > drivers/pci/controller/dwc/pcie-qcom.c | 81 +++++++++++++++++++++++++++------- > 1 file changed, 66 insertions(+), 15 deletions(-) > > diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c > index a0266bfe71f1..2ec14bfafcfc 100644 > --- a/drivers/pci/controller/dwc/pcie-qcom.c > +++ b/drivers/pci/controller/dwc/pcie-qcom.c > @@ -22,6 +22,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -244,6 +245,7 @@ struct qcom_pcie { > const struct qcom_pcie_cfg *cfg; > struct dentry *debugfs; > bool suspended; > + bool opp_supported; You can just use "pcie->icc_mem" to differentiate between OPP and ICC. No need of a new flag. > }; > > #define to_qcom_pcie(x) dev_get_drvdata((x)->dev) > @@ -1405,15 +1407,13 @@ static int qcom_pcie_icc_init(struct qcom_pcie *pcie) > return 0; > } > > -static void qcom_pcie_icc_update(struct qcom_pcie *pcie) > +static void qcom_pcie_icc_opp_update(struct qcom_pcie *pcie) > { > struct dw_pcie *pci = pcie->pci; > - u32 offset, status; > + u32 offset, status, freq; > + struct dev_pm_opp *opp; > int speed, width; > - int ret; > - > - if (!pcie->icc_mem) > - return; > + int ret, mbps; > > offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); > status = readw(pci->dbi_base + offset + PCI_EXP_LNKSTA); > @@ -1425,11 +1425,30 @@ static void qcom_pcie_icc_update(struct qcom_pcie *pcie) > speed = FIELD_GET(PCI_EXP_LNKSTA_CLS, status); > width = FIELD_GET(PCI_EXP_LNKSTA_NLW, status); > > - ret = icc_set_bw(pcie->icc_mem, 0, width * QCOM_PCIE_LINK_SPEED_TO_BW(speed)); > - if (ret) { > - dev_err(pci->dev, "failed to set interconnect bandwidth: %d\n", > - ret); > + if (pcie->opp_supported) { > + mbps = pcie_link_speed_to_mbps(pcie_link_speed[speed]); > + if (mbps < 0) > + return; > + > + freq = mbps * 1000; > + opp = dev_pm_opp_find_freq_exact(pci->dev, freq * width, true); > + if (!IS_ERR(opp)) { > + ret = dev_pm_opp_set_opp(pci->dev, opp); > + if (ret) > + dev_err(pci->dev, "Failed to set opp: freq %ld ret %d\n", > + dev_pm_opp_get_freq(opp), ret); > + dev_pm_opp_put(opp); > + } > + } else { > + ret = icc_set_bw(pcie->icc_mem, 0, > + width * QCOM_PCIE_LINK_SPEED_TO_BW(speed)); > + if (ret) { > + dev_err(pci->dev, > + "failed to set interconnect bandwidth for pcie-mem: %d\n", ret); "PCIe-MEM" > + } > } > + > + return; > } > > static int qcom_pcie_link_transition_count(struct seq_file *s, void *data) > @@ -1472,8 +1491,10 @@ static void qcom_pcie_init_debugfs(struct qcom_pcie *pcie) > static int qcom_pcie_probe(struct platform_device *pdev) > { > const struct qcom_pcie_cfg *pcie_cfg; > + unsigned long max_freq = INT_MAX; > struct device *dev = &pdev->dev; > struct qcom_pcie *pcie; > + struct dev_pm_opp *opp; > struct dw_pcie_rp *pp; > struct resource *res; > struct dw_pcie *pci; > @@ -1540,9 +1561,36 @@ static int qcom_pcie_probe(struct platform_device *pdev) > goto err_pm_runtime_put; > } > > - ret = qcom_pcie_icc_init(pcie); > - if (ret) > + /* OPP table is optional */ > + ret = devm_pm_opp_of_add_table(dev); > + if (ret && ret != -ENODEV) { > + dev_err_probe(dev, ret, "Failed to add OPP table\n"); > goto err_pm_runtime_put; > + } > + > + /* > + * Use highest OPP here if the OPP table is present. At the end of Why highest opp? For ICC, we set minimal bandwidth before. > + * the probe(), OPP will be updated using qcom_pcie_icc_opp_update(). > + */ > + if (ret != -ENODEV) { if (!ret) > + opp = dev_pm_opp_find_freq_floor(dev, &max_freq); > + if (!IS_ERR(opp)) { > + ret = dev_pm_opp_set_opp(dev, opp); > + if (ret) > + dev_err_probe(pci->dev, ret, > + "Failed to set opp: freq %ld\n", "Failed to set OPP for freq: %ld\n" > + dev_pm_opp_get_freq(opp)); > + dev_pm_opp_put(opp); > + } > + pcie->opp_supported = true; > + } > + > + /* Skip ICC init if OPP is supported as ICC bw is handled by OPP */ > + if (!pcie->opp_supported) { > + ret = qcom_pcie_icc_init(pcie); First check whether ICC is present or not and then check OPP as a fallback. This avoids an extra flag. - Mani > + if (ret) > + goto err_pm_runtime_put; > + } > > ret = pcie->cfg->ops->get_resources(pcie); > if (ret) > @@ -1562,7 +1610,7 @@ static int qcom_pcie_probe(struct platform_device *pdev) > goto err_phy_exit; > } > > - qcom_pcie_icc_update(pcie); > + qcom_pcie_icc_opp_update(pcie); > > if (pcie->mhi) > qcom_pcie_init_debugfs(pcie); > @@ -1621,10 +1669,13 @@ static int qcom_pcie_suspend_noirq(struct device *dev) > qcom_pcie_host_init(&pcie->pci->pp); > pcie->suspended = false; > } > - qcom_pcie_icc_update(pcie); > + qcom_pcie_icc_opp_update(pcie); > return ret; > } > > + if (pcie->opp_supported) > + dev_pm_opp_set_opp(pcie->pci->dev, NULL); > + > return 0; > } > > @@ -1647,7 +1698,7 @@ static int qcom_pcie_resume_noirq(struct device *dev) > pcie->suspended = false; > } > > - qcom_pcie_icc_update(pcie); > + qcom_pcie_icc_opp_update(pcie); > > return 0; > } > > -- > 2.42.0 > -- மணிவண்ணன் சதாசிவம்