Skip to content

Commit dc2f2a9

Browse files
Mani-Sadhasivamkwilczynski
authored andcommitted
PCI: qcom-ep: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed
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 <[email protected]> Link: https://lore.kernel.org/linux-pci/[email protected] Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Reviewed-by: Konrad Dybcio <[email protected]>
1 parent 8da2e9a commit dc2f2a9

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

drivers/pci/controller/dwc/pcie-qcom-ep.c

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/reset.h>
2424
#include <linux/module.h>
2525

26+
#include "../../pci.h"
2627
#include "pcie-designware.h"
2728

2829
/* PARF registers */
@@ -135,10 +136,8 @@
135136
#define CORE_RESET_TIME_US_MAX 1005
136137
#define WAKE_DELAY_US 2000 /* 2 ms */
137138

138-
#define PCIE_GEN1_BW_MBPS 250
139-
#define PCIE_GEN2_BW_MBPS 500
140-
#define PCIE_GEN3_BW_MBPS 985
141-
#define PCIE_GEN4_BW_MBPS 1969
139+
#define QCOM_PCIE_LINK_SPEED_TO_BW(speed) \
140+
Mbps_to_icc(PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]))
142141

143142
#define to_pcie_ep(x) dev_get_drvdata((x)->dev)
144143

@@ -266,7 +265,7 @@ static void qcom_pcie_dw_stop_link(struct dw_pcie *pci)
266265
static void qcom_pcie_ep_icc_update(struct qcom_pcie_ep *pcie_ep)
267266
{
268267
struct dw_pcie *pci = &pcie_ep->pci;
269-
u32 offset, status, bw;
268+
u32 offset, status;
270269
int speed, width;
271270
int ret;
272271

@@ -279,25 +278,7 @@ static void qcom_pcie_ep_icc_update(struct qcom_pcie_ep *pcie_ep)
279278
speed = FIELD_GET(PCI_EXP_LNKSTA_CLS, status);
280279
width = FIELD_GET(PCI_EXP_LNKSTA_NLW, status);
281280

282-
switch (speed) {
283-
case 1:
284-
bw = MBps_to_icc(PCIE_GEN1_BW_MBPS);
285-
break;
286-
case 2:
287-
bw = MBps_to_icc(PCIE_GEN2_BW_MBPS);
288-
break;
289-
case 3:
290-
bw = MBps_to_icc(PCIE_GEN3_BW_MBPS);
291-
break;
292-
default:
293-
dev_warn(pci->dev, "using default GEN4 bandwidth\n");
294-
fallthrough;
295-
case 4:
296-
bw = MBps_to_icc(PCIE_GEN4_BW_MBPS);
297-
break;
298-
}
299-
300-
ret = icc_set_bw(pcie_ep->icc_mem, 0, width * bw);
281+
ret = icc_set_bw(pcie_ep->icc_mem, 0, width * QCOM_PCIE_LINK_SPEED_TO_BW(speed));
301282
if (ret)
302283
dev_err(pci->dev, "failed to set interconnect bandwidth: %d\n",
303284
ret);
@@ -335,7 +316,7 @@ static int qcom_pcie_enable_resources(struct qcom_pcie_ep *pcie_ep)
335316
* Set an initial peak bandwidth corresponding to single-lane Gen 1
336317
* for the pcie-mem path.
337318
*/
338-
ret = icc_set_bw(pcie_ep->icc_mem, 0, MBps_to_icc(PCIE_GEN1_BW_MBPS));
319+
ret = icc_set_bw(pcie_ep->icc_mem, 0, QCOM_PCIE_LINK_SPEED_TO_BW(1));
339320
if (ret) {
340321
dev_err(pci->dev, "failed to set interconnect bandwidth: %d\n",
341322
ret);

0 commit comments

Comments
 (0)