public inbox for linux-arm-msm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 1/3] PCI: qcom: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed
@ 2023-10-04 16:44 Manivannan Sadhasivam
  2023-10-04 16:44 ` [PATCH v4 2/3] PCI: qcom-ep: " Manivannan Sadhasivam
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Manivannan Sadhasivam @ 2023-10-04 16:44 UTC (permalink / raw)
  To: lpieralisi, kw
  Cc: andersson, konrad.dybcio, bhelgaas, linux-arm-msm, linux-pci,
	linux-kernel, abel.vesa, Manivannan Sadhasivam

Instead of hardcoding the link speed in MBps, use existing
PCIE_SPEED2MBS_ENC() macro that does the encoding of the link speed for us.
Also, let's Wrap it with QCOM_PCIE_LINK_SPEED_TO_BW() macro to do the
conversion to ICC speed.

This eliminates the need for a switch case in qcom_pcie_icc_update() and
also works for future Gen speeds without any code modifications.

Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---

Changes in v4:

* Modified the subject and commit message as per Bjorn's suggestion

Changes in v3:

- Used Mbps_to_icc() macro and changed the commit message a bit

Changes in v2:

- Switched to QCOM_PCIE_LINK_SPEED_TO_BW() macro as per Bjorn's suggestion
  https://lore.kernel.org/linux-pci/20230924160713.217086-1-manivannan.sadhasivam@linaro.org/

 drivers/pci/controller/dwc/pcie-qcom.c | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c
index e2f29404c84e..367acb419a2b 100644
--- a/drivers/pci/controller/dwc/pcie-qcom.c
+++ b/drivers/pci/controller/dwc/pcie-qcom.c
@@ -148,6 +148,9 @@
 
 #define QCOM_PCIE_CRC8_POLYNOMIAL		(BIT(2) | BIT(1) | BIT(0))
 
+#define QCOM_PCIE_LINK_SPEED_TO_BW(speed) \
+		Mbps_to_icc(PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]))
+
 #define QCOM_PCIE_1_0_0_MAX_CLOCKS		4
 struct qcom_pcie_resources_1_0_0 {
 	struct clk_bulk_data clks[QCOM_PCIE_1_0_0_MAX_CLOCKS];
@@ -1347,7 +1350,7 @@ static int qcom_pcie_icc_init(struct qcom_pcie *pcie)
 	 * Set an initial peak bandwidth corresponding to single-lane Gen 1
 	 * for the pcie-mem path.
 	 */
-	ret = icc_set_bw(pcie->icc_mem, 0, MBps_to_icc(250));
+	ret = icc_set_bw(pcie->icc_mem, 0, QCOM_PCIE_LINK_SPEED_TO_BW(1));
 	if (ret) {
 		dev_err(pci->dev, "failed to set interconnect bandwidth: %d\n",
 			ret);
@@ -1360,7 +1363,7 @@ static int qcom_pcie_icc_init(struct qcom_pcie *pcie)
 static void qcom_pcie_icc_update(struct qcom_pcie *pcie)
 {
 	struct dw_pcie *pci = pcie->pci;
-	u32 offset, status, bw;
+	u32 offset, status;
 	int speed, width;
 	int ret;
 
@@ -1377,22 +1380,7 @@ 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);
 
-	switch (speed) {
-	case 1:
-		bw = MBps_to_icc(250);
-		break;
-	case 2:
-		bw = MBps_to_icc(500);
-		break;
-	default:
-		WARN_ON_ONCE(1);
-		fallthrough;
-	case 3:
-		bw = MBps_to_icc(985);
-		break;
-	}
-
-	ret = icc_set_bw(pcie->icc_mem, 0, width * bw);
+	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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v4 2/3] PCI: qcom-ep: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed
  2023-10-04 16:44 [PATCH v4 1/3] PCI: qcom: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed Manivannan Sadhasivam
@ 2023-10-04 16:44 ` Manivannan Sadhasivam
  2023-10-06 21:17   ` Konrad Dybcio
  2023-10-04 16:44 ` [PATCH v4 3/3] PCI: tegra194: Use Mbps_to_icc() macro for setting icc speed Manivannan Sadhasivam
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Manivannan Sadhasivam @ 2023-10-04 16:44 UTC (permalink / raw)
  To: lpieralisi, kw
  Cc: andersson, konrad.dybcio, bhelgaas, linux-arm-msm, linux-pci,
	linux-kernel, abel.vesa, Manivannan Sadhasivam

Instead of hardcoding the link speed in MBps, use existing
PCIE_SPEED2MBS_ENC() macro that does the encoding of the link speed for us.
Also, let's Wrap it with QCOM_PCIE_LINK_SPEED_TO_BW() macro to do the
conversion to ICC speed.

This eliminates the need for a switch case in qcom_pcie_icc_update() and
also works for future Gen speeds without any code modifications.

Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---

Changes in v4:

* Modified the subject and commit message as per Bjorn's suggestion

Changes in v3:

- New patch

 drivers/pci/controller/dwc/pcie-qcom-ep.c | 31 +++++------------------
 1 file changed, 6 insertions(+), 25 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c
index 8bd8107690a6..32c8d9e37876 100644
--- a/drivers/pci/controller/dwc/pcie-qcom-ep.c
+++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c
@@ -23,6 +23,7 @@
 #include <linux/reset.h>
 #include <linux/module.h>
 
+#include "../../pci.h"
 #include "pcie-designware.h"
 
 /* PARF registers */
@@ -135,10 +136,8 @@
 #define CORE_RESET_TIME_US_MAX			1005
 #define WAKE_DELAY_US				2000 /* 2 ms */
 
-#define PCIE_GEN1_BW_MBPS			250
-#define PCIE_GEN2_BW_MBPS			500
-#define PCIE_GEN3_BW_MBPS			985
-#define PCIE_GEN4_BW_MBPS			1969
+#define QCOM_PCIE_LINK_SPEED_TO_BW(speed) \
+		Mbps_to_icc(PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]))
 
 #define to_pcie_ep(x)				dev_get_drvdata((x)->dev)
 
@@ -266,7 +265,7 @@ static void qcom_pcie_dw_stop_link(struct dw_pcie *pci)
 static void qcom_pcie_ep_icc_update(struct qcom_pcie_ep *pcie_ep)
 {
 	struct dw_pcie *pci = &pcie_ep->pci;
-	u32 offset, status, bw;
+	u32 offset, status;
 	int speed, width;
 	int ret;
 
@@ -279,25 +278,7 @@ static void qcom_pcie_ep_icc_update(struct qcom_pcie_ep *pcie_ep)
 	speed = FIELD_GET(PCI_EXP_LNKSTA_CLS, status);
 	width = FIELD_GET(PCI_EXP_LNKSTA_NLW, status);
 
-	switch (speed) {
-	case 1:
-		bw = MBps_to_icc(PCIE_GEN1_BW_MBPS);
-		break;
-	case 2:
-		bw = MBps_to_icc(PCIE_GEN2_BW_MBPS);
-		break;
-	case 3:
-		bw = MBps_to_icc(PCIE_GEN3_BW_MBPS);
-		break;
-	default:
-		dev_warn(pci->dev, "using default GEN4 bandwidth\n");
-		fallthrough;
-	case 4:
-		bw = MBps_to_icc(PCIE_GEN4_BW_MBPS);
-		break;
-	}
-
-	ret = icc_set_bw(pcie_ep->icc_mem, 0, width * bw);
+	ret = icc_set_bw(pcie_ep->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);
@@ -335,7 +316,7 @@ static int qcom_pcie_enable_resources(struct qcom_pcie_ep *pcie_ep)
 	 * Set an initial peak bandwidth corresponding to single-lane Gen 1
 	 * for the pcie-mem path.
 	 */
-	ret = icc_set_bw(pcie_ep->icc_mem, 0, MBps_to_icc(PCIE_GEN1_BW_MBPS));
+	ret = icc_set_bw(pcie_ep->icc_mem, 0, QCOM_PCIE_LINK_SPEED_TO_BW(1));
 	if (ret) {
 		dev_err(pci->dev, "failed to set interconnect bandwidth: %d\n",
 			ret);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v4 3/3] PCI: tegra194: Use Mbps_to_icc() macro for setting icc speed
  2023-10-04 16:44 [PATCH v4 1/3] PCI: qcom: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed Manivannan Sadhasivam
  2023-10-04 16:44 ` [PATCH v4 2/3] PCI: qcom-ep: " Manivannan Sadhasivam
@ 2023-10-04 16:44 ` Manivannan Sadhasivam
  2023-10-06 21:18   ` Konrad Dybcio
  2023-10-06 21:17 ` [PATCH v4 1/3] PCI: qcom: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed Konrad Dybcio
  2023-10-14 19:32 ` Krzysztof Wilczyński
  3 siblings, 1 reply; 7+ messages in thread
From: Manivannan Sadhasivam @ 2023-10-04 16:44 UTC (permalink / raw)
  To: lpieralisi, kw
  Cc: andersson, konrad.dybcio, bhelgaas, linux-arm-msm, linux-pci,
	linux-kernel, abel.vesa, Manivannan Sadhasivam, Vidya Sagar

PCIe speed returned by the PCIE_SPEED2MBS_ENC() macro is in Mbps. So
instead of converting it to MBps explicitly and using the MBps_to_icc()
macro, let's use the Mbps_to_icc() macro to pass the value directly.

Cc: Vidya Sagar <vidyas@nvidia.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---

Changes in v4:

* No change

Changes in v3:

- New patch

 drivers/pci/controller/dwc/pcie-tegra194.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c
index 4bba31502ce1..5feac690e127 100644
--- a/drivers/pci/controller/dwc/pcie-tegra194.c
+++ b/drivers/pci/controller/dwc/pcie-tegra194.c
@@ -321,9 +321,9 @@ static void tegra_pcie_icc_set(struct tegra_pcie_dw *pcie)
 	speed = FIELD_GET(PCI_EXP_LNKSTA_CLS, val);
 	width = FIELD_GET(PCI_EXP_LNKSTA_NLW, val);
 
-	val = width * (PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]) / BITS_PER_BYTE);
+	val = width * PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]);
 
-	if (icc_set_bw(pcie->icc_path, MBps_to_icc(val), 0))
+	if (icc_set_bw(pcie->icc_path, Mbps_to_icc(val), 0))
 		dev_err(pcie->dev, "can't set bw[%u]\n", val);
 
 	if (speed >= ARRAY_SIZE(pcie_gen_freq))
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 1/3] PCI: qcom: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed
  2023-10-04 16:44 [PATCH v4 1/3] PCI: qcom: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed Manivannan Sadhasivam
  2023-10-04 16:44 ` [PATCH v4 2/3] PCI: qcom-ep: " Manivannan Sadhasivam
  2023-10-04 16:44 ` [PATCH v4 3/3] PCI: tegra194: Use Mbps_to_icc() macro for setting icc speed Manivannan Sadhasivam
@ 2023-10-06 21:17 ` Konrad Dybcio
  2023-10-14 19:32 ` Krzysztof Wilczyński
  3 siblings, 0 replies; 7+ messages in thread
From: Konrad Dybcio @ 2023-10-06 21:17 UTC (permalink / raw)
  To: Manivannan Sadhasivam, lpieralisi, kw
  Cc: andersson, bhelgaas, linux-arm-msm, linux-pci, linux-kernel,
	abel.vesa

On 4.10.2023 18:44, Manivannan Sadhasivam wrote:
> Instead of hardcoding the link speed in MBps, use existing
> PCIE_SPEED2MBS_ENC() macro that does the encoding of the link speed for us.
> Also, let's Wrap it with QCOM_PCIE_LINK_SPEED_TO_BW() macro to do the
> conversion to ICC speed.
> 
> This eliminates the need for a switch case in qcom_pcie_icc_update() and
> also works for future Gen speeds without any code modifications.
> 
> Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>

Konrad

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 2/3] PCI: qcom-ep: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed
  2023-10-04 16:44 ` [PATCH v4 2/3] PCI: qcom-ep: " Manivannan Sadhasivam
@ 2023-10-06 21:17   ` Konrad Dybcio
  0 siblings, 0 replies; 7+ messages in thread
From: Konrad Dybcio @ 2023-10-06 21:17 UTC (permalink / raw)
  To: Manivannan Sadhasivam, lpieralisi, kw
  Cc: andersson, bhelgaas, linux-arm-msm, linux-pci, linux-kernel,
	abel.vesa

On 4.10.2023 18:44, Manivannan Sadhasivam wrote:
> Instead of hardcoding the link speed in MBps, use existing
> PCIE_SPEED2MBS_ENC() macro that does the encoding of the link speed for us.
> Also, let's Wrap it with QCOM_PCIE_LINK_SPEED_TO_BW() macro to do the
> conversion to ICC speed.
> 
> This eliminates the need for a switch case in qcom_pcie_icc_update() and
> also works for future Gen speeds without any code modifications.
> 
> Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>

Konrad

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 3/3] PCI: tegra194: Use Mbps_to_icc() macro for setting icc speed
  2023-10-04 16:44 ` [PATCH v4 3/3] PCI: tegra194: Use Mbps_to_icc() macro for setting icc speed Manivannan Sadhasivam
@ 2023-10-06 21:18   ` Konrad Dybcio
  0 siblings, 0 replies; 7+ messages in thread
From: Konrad Dybcio @ 2023-10-06 21:18 UTC (permalink / raw)
  To: Manivannan Sadhasivam, lpieralisi, kw
  Cc: andersson, bhelgaas, linux-arm-msm, linux-pci, linux-kernel,
	abel.vesa, Vidya Sagar

On 4.10.2023 18:44, Manivannan Sadhasivam wrote:
> PCIe speed returned by the PCIE_SPEED2MBS_ENC() macro is in Mbps. So
> instead of converting it to MBps explicitly and using the MBps_to_icc()
> macro, let's use the Mbps_to_icc() macro to pass the value directly.
> 
> Cc: Vidya Sagar <vidyas@nvidia.com>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>

Konrad

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 1/3] PCI: qcom: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed
  2023-10-04 16:44 [PATCH v4 1/3] PCI: qcom: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed Manivannan Sadhasivam
                   ` (2 preceding siblings ...)
  2023-10-06 21:17 ` [PATCH v4 1/3] PCI: qcom: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed Konrad Dybcio
@ 2023-10-14 19:32 ` Krzysztof Wilczyński
  3 siblings, 0 replies; 7+ messages in thread
From: Krzysztof Wilczyński @ 2023-10-14 19:32 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: lpieralisi, andersson, konrad.dybcio, bhelgaas, linux-arm-msm,
	linux-pci, linux-kernel, abel.vesa

Hello,

> Instead of hardcoding the link speed in MBps, use existing
> PCIE_SPEED2MBS_ENC() macro that does the encoding of the link speed for us.
> Also, let's Wrap it with QCOM_PCIE_LINK_SPEED_TO_BW() macro to do the
> conversion to ICC speed.
> 
> This eliminates the need for a switch case in qcom_pcie_icc_update() and
> also works for future Gen speeds without any code modifications.
[...]

Applied to controller/speed, thank you!

[1/3] PCI: qcom: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed
      https://git.kernel.org/pci/pci/c/8da2e9af0bb5
[2/3] PCI: qcom-ep: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed
      https://git.kernel.org/pci/pci/c/dc2f2a9d1cf2
[3/3] PCI: tegra194: Use Mbps_to_icc() macro for setting icc speed
      https://git.kernel.org/pci/pci/c/85e9eb3e7727

	Krzysztof

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-10-14 19:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-04 16:44 [PATCH v4 1/3] PCI: qcom: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed Manivannan Sadhasivam
2023-10-04 16:44 ` [PATCH v4 2/3] PCI: qcom-ep: " Manivannan Sadhasivam
2023-10-06 21:17   ` Konrad Dybcio
2023-10-04 16:44 ` [PATCH v4 3/3] PCI: tegra194: Use Mbps_to_icc() macro for setting icc speed Manivannan Sadhasivam
2023-10-06 21:18   ` Konrad Dybcio
2023-10-06 21:17 ` [PATCH v4 1/3] PCI: qcom: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed Konrad Dybcio
2023-10-14 19:32 ` Krzysztof Wilczyński

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox