[PATCH v5 5/5] PCI: qcom: Use frequency and level based OPP lookup

Krishna Chaitanya Chundru posted 5 patches 2 months ago
[PATCH v5 5/5] PCI: qcom: Use frequency and level based OPP lookup
Posted by Krishna Chaitanya Chundru 2 months ago
PCIe link configurations such as 8GT/s x2 and 16GT/s x1 may operate at
the same frequency but differ in other characteristics like RPMh votes.
The existing OPP selection based solely on frequency cannot distinguish
between such cases.

In such cases, frequency alone is insufficient to identify the correct OPP.
Use the newly introduced dev_pm_opp_find_key_exact() API to match both
frequency and level when selecting an OPP, here level indicates PCIe
data rate.

To support older device tree's where opp-level is not defined, check if
opp-level is present or not using dev_pm_opp_find_level_exact(). if
not present fallback to frequency only match.

Signed-off-by: Krishna Chaitanya Chundru <krishna.chundru@oss.qualcomm.com>
---
 drivers/pci/controller/dwc/pcie-qcom.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c
index 805edbbfe7eba496bc99ca82051dee43d240f359..03b3a1d3a40359a0c70704873b72539ffa43e722 100644
--- a/drivers/pci/controller/dwc/pcie-qcom.c
+++ b/drivers/pci/controller/dwc/pcie-qcom.c
@@ -1565,6 +1565,7 @@ static void qcom_pcie_icc_opp_update(struct qcom_pcie *pcie)
 {
 	u32 offset, status, width, speed;
 	struct dw_pcie *pci = pcie->pci;
+	struct dev_pm_opp_key key;
 	unsigned long freq_kbps;
 	struct dev_pm_opp *opp;
 	int ret, freq_mbps;
@@ -1592,8 +1593,20 @@ static void qcom_pcie_icc_opp_update(struct qcom_pcie *pcie)
 			return;
 
 		freq_kbps = freq_mbps * KILO;
-		opp = dev_pm_opp_find_freq_exact(pci->dev, freq_kbps * width,
-						 true);
+		opp = dev_pm_opp_find_level_exact(pci->dev, speed);
+		if (IS_ERR(opp)) {
+			 /* opp-level is not defined use only frequency */
+			opp = dev_pm_opp_find_freq_exact(pci->dev, freq_kbps * width,
+							 true);
+		} else {
+			/* put opp-level OPP */
+			dev_pm_opp_put(opp);
+
+			key.freq = freq_kbps * width;
+			key.level = speed;
+			key.bw = 0;
+			opp = dev_pm_opp_find_key_exact(pci->dev, &key, true);
+		}
 		if (!IS_ERR(opp)) {
 			ret = dev_pm_opp_set_opp(pci->dev, opp);
 			if (ret)

-- 
2.34.1
Re: [PATCH v5 5/5] PCI: qcom: Use frequency and level based OPP lookup
Posted by Bjorn Helgaas 1 month, 2 weeks ago
On Mon, Oct 13, 2025 at 04:23:32PM +0530, Krishna Chaitanya Chundru wrote:
> PCIe link configurations such as 8GT/s x2 and 16GT/s x1 may operate at
> the same frequency but differ in other characteristics like RPMh votes.
> The existing OPP selection based solely on frequency cannot distinguish
> between such cases.
> 
> In such cases, frequency alone is insufficient to identify the correct OPP.
> Use the newly introduced dev_pm_opp_find_key_exact() API to match both
> frequency and level when selecting an OPP, here level indicates PCIe
> data rate.
> 
> To support older device tree's where opp-level is not defined, check if
> opp-level is present or not using dev_pm_opp_find_level_exact(). if
> not present fallback to frequency only match.

What are the names of the DT properties here for the exact (frequency
+ level) and frequency-only values?  I'd like to mention them in the
commit log so we can look at a DT and figure out what to expect from
this change.
Re: [PATCH v5 5/5] PCI: qcom: Use frequency and level based OPP lookup
Posted by Manivannan Sadhasivam 1 month, 2 weeks ago
On Wed, Oct 29, 2025 at 03:39:48PM -0500, Bjorn Helgaas wrote:
> On Mon, Oct 13, 2025 at 04:23:32PM +0530, Krishna Chaitanya Chundru wrote:
> > PCIe link configurations such as 8GT/s x2 and 16GT/s x1 may operate at
> > the same frequency but differ in other characteristics like RPMh votes.
> > The existing OPP selection based solely on frequency cannot distinguish
> > between such cases.
> > 
> > In such cases, frequency alone is insufficient to identify the correct OPP.
> > Use the newly introduced dev_pm_opp_find_key_exact() API to match both
> > frequency and level when selecting an OPP, here level indicates PCIe
> > data rate.
> > 
> > To support older device tree's where opp-level is not defined, check if
> > opp-level is present or not using dev_pm_opp_find_level_exact(). if
> > not present fallback to frequency only match.
> 
> What are the names of the DT properties here for the exact (frequency
> + level) and frequency-only values?  I'd like to mention them in the
> commit log so we can look at a DT and figure out what to expect from
> this change.

Frequency: opp-hz
Level: opp-level

- Mani

-- 
மணிவண்ணன் சதாசிவம்
Re: [PATCH v5 5/5] PCI: qcom: Use frequency and level based OPP lookup
Posted by Konrad Dybcio 1 month, 3 weeks ago
On 10/13/25 12:53 PM, Krishna Chaitanya Chundru wrote:
> PCIe link configurations such as 8GT/s x2 and 16GT/s x1 may operate at
> the same frequency but differ in other characteristics like RPMh votes.
> The existing OPP selection based solely on frequency cannot distinguish
> between such cases.
> 
> In such cases, frequency alone is insufficient to identify the correct OPP.
> Use the newly introduced dev_pm_opp_find_key_exact() API to match both
> frequency and level when selecting an OPP, here level indicates PCIe
> data rate.
> 
> To support older device tree's where opp-level is not defined, check if
> opp-level is present or not using dev_pm_opp_find_level_exact(). if
> not present fallback to frequency only match.
> 
> Signed-off-by: Krishna Chaitanya Chundru <krishna.chundru@oss.qualcomm.com>
> ---
>  drivers/pci/controller/dwc/pcie-qcom.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c
> index 805edbbfe7eba496bc99ca82051dee43d240f359..03b3a1d3a40359a0c70704873b72539ffa43e722 100644
> --- a/drivers/pci/controller/dwc/pcie-qcom.c
> +++ b/drivers/pci/controller/dwc/pcie-qcom.c
> @@ -1565,6 +1565,7 @@ static void qcom_pcie_icc_opp_update(struct qcom_pcie *pcie)
>  {
>  	u32 offset, status, width, speed;
>  	struct dw_pcie *pci = pcie->pci;
> +	struct dev_pm_opp_key key;

You need to zero-initialize this, or it'll explode the second
struct dev_pm_opp_key {} grows

Konrad
Re: [PATCH v5 5/5] PCI: qcom: Use frequency and level based OPP lookup
Posted by Manivannan Sadhasivam 1 month, 3 weeks ago
On Wed, Oct 22, 2025 at 06:37:41PM +0200, Konrad Dybcio wrote:
> On 10/13/25 12:53 PM, Krishna Chaitanya Chundru wrote:
> > PCIe link configurations such as 8GT/s x2 and 16GT/s x1 may operate at
> > the same frequency but differ in other characteristics like RPMh votes.
> > The existing OPP selection based solely on frequency cannot distinguish
> > between such cases.
> > 
> > In such cases, frequency alone is insufficient to identify the correct OPP.
> > Use the newly introduced dev_pm_opp_find_key_exact() API to match both
> > frequency and level when selecting an OPP, here level indicates PCIe
> > data rate.
> > 
> > To support older device tree's where opp-level is not defined, check if
> > opp-level is present or not using dev_pm_opp_find_level_exact(). if
> > not present fallback to frequency only match.
> > 
> > Signed-off-by: Krishna Chaitanya Chundru <krishna.chundru@oss.qualcomm.com>
> > ---
> >  drivers/pci/controller/dwc/pcie-qcom.c | 17 +++++++++++++++--
> >  1 file changed, 15 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c
> > index 805edbbfe7eba496bc99ca82051dee43d240f359..03b3a1d3a40359a0c70704873b72539ffa43e722 100644
> > --- a/drivers/pci/controller/dwc/pcie-qcom.c
> > +++ b/drivers/pci/controller/dwc/pcie-qcom.c
> > @@ -1565,6 +1565,7 @@ static void qcom_pcie_icc_opp_update(struct qcom_pcie *pcie)
> >  {
> >  	u32 offset, status, width, speed;
> >  	struct dw_pcie *pci = pcie->pci;
> > +	struct dev_pm_opp_key key;
> 
> You need to zero-initialize this, or it'll explode the second
> struct dev_pm_opp_key {} grows
> 

I've fixed it up while applying, thanks!

- Mani

-- 
மணிவண்ணன் சதாசிவம்