Skip to content

Commit 6cbb247

Browse files
committed
PCI: designware: Wait for link to come up with consistent style
All the DesignWare-based host drivers loop waiting for the link to come up, but they do it several ways that are needlessly different. Wait for the link to come up in a consistent style across all the DesignWare drivers. No functional change. Signed-off-by: Bjorn Helgaas <[email protected]> Acked-by: Pratyush Anand <[email protected]>
1 parent 1d3f9ba commit 6cbb247

File tree

6 files changed

+51
-66
lines changed

6 files changed

+51
-66
lines changed

drivers/pci/host/pci-dra7xx.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ static int dra7xx_pcie_link_up(struct pcie_port *pp)
9393

9494
static int dra7xx_pcie_establish_link(struct pcie_port *pp)
9595
{
96-
u32 reg;
97-
unsigned int retries = 1000;
9896
struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
97+
u32 reg;
98+
unsigned int retries;
9999

100100
if (dw_pcie_link_up(pp)) {
101101
dev_err(pp->dev, "link is already up\n");
@@ -106,18 +106,14 @@ static int dra7xx_pcie_establish_link(struct pcie_port *pp)
106106
reg |= LTSSM_EN;
107107
dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD, reg);
108108

109-
while (retries--) {
109+
for (retries = 0; retries < 1000; retries++) {
110110
if (dw_pcie_link_up(pp))
111-
break;
111+
return 0;
112112
usleep_range(10, 20);
113113
}
114114

115-
if (retries == 0) {
116-
dev_err(pp->dev, "link is not up\n");
117-
return -ETIMEDOUT;
118-
}
119-
120-
return 0;
115+
dev_err(pp->dev, "link is not up\n");
116+
return -EINVAL;
121117
}
122118

123119
static void dra7xx_pcie_enable_interrupts(struct pcie_port *pp)

drivers/pci/host/pci-exynos.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ static void exynos_pcie_assert_reset(struct pcie_port *pp)
316316

317317
static int exynos_pcie_establish_link(struct pcie_port *pp)
318318
{
319-
u32 val;
320-
int count = 0;
321319
struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
320+
u32 val;
321+
unsigned int retries;
322322

323323
if (dw_pcie_link_up(pp)) {
324324
dev_err(pp->dev, "Link already up\n");
@@ -357,27 +357,23 @@ static int exynos_pcie_establish_link(struct pcie_port *pp)
357357
PCIE_APP_LTSSM_ENABLE);
358358

359359
/* check if the link is up or not */
360-
while (!dw_pcie_link_up(pp)) {
361-
mdelay(100);
362-
count++;
363-
if (count == 10) {
364-
while (exynos_phy_readl(exynos_pcie,
365-
PCIE_PHY_PLL_LOCKED) == 0) {
366-
val = exynos_blk_readl(exynos_pcie,
367-
PCIE_PHY_PLL_LOCKED);
368-
dev_info(pp->dev, "PLL Locked: 0x%x\n", val);
369-
}
370-
/* power off phy */
371-
exynos_pcie_power_off_phy(pp);
372-
373-
dev_err(pp->dev, "PCIe Link Fail\n");
374-
return -EINVAL;
360+
for (retries = 0; retries < 10; retries++) {
361+
if (dw_pcie_link_up(pp)) {
362+
dev_info(pp->dev, "Link up\n");
363+
return 0;
375364
}
365+
mdelay(100);
376366
}
377367

378-
dev_info(pp->dev, "Link up\n");
368+
while (exynos_phy_readl(exynos_pcie, PCIE_PHY_PLL_LOCKED) == 0) {
369+
val = exynos_blk_readl(exynos_pcie, PCIE_PHY_PLL_LOCKED);
370+
dev_info(pp->dev, "PLL Locked: 0x%x\n", val);
371+
}
372+
/* power off phy */
373+
exynos_pcie_power_off_phy(pp);
379374

380-
return 0;
375+
dev_err(pp->dev, "PCIe Link Fail\n");
376+
return -EINVAL;
381377
}
382378

383379
static void exynos_pcie_clear_irq_pulse(struct pcie_port *pp)

drivers/pci/host/pci-imx6.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -335,21 +335,19 @@ static void imx6_pcie_init_phy(struct pcie_port *pp)
335335

336336
static int imx6_pcie_wait_for_link(struct pcie_port *pp)
337337
{
338-
int count = 200;
338+
unsigned int retries;
339339

340-
while (!dw_pcie_link_up(pp)) {
340+
for (retries = 0; retries < 200; retries++) {
341+
if (dw_pcie_link_up(pp))
342+
return 0;
341343
usleep_range(100, 1000);
342-
if (--count)
343-
continue;
344-
345-
dev_err(pp->dev, "phy link never came up\n");
346-
dev_dbg(pp->dev, "DEBUG_R0: 0x%08x, DEBUG_R1: 0x%08x\n",
347-
readl(pp->dbi_base + PCIE_PHY_DEBUG_R0),
348-
readl(pp->dbi_base + PCIE_PHY_DEBUG_R1));
349-
return -EINVAL;
350344
}
351345

352-
return 0;
346+
dev_err(pp->dev, "phy link never came up\n");
347+
dev_dbg(pp->dev, "DEBUG_R0: 0x%08x, DEBUG_R1: 0x%08x\n",
348+
readl(pp->dbi_base + PCIE_PHY_DEBUG_R0),
349+
readl(pp->dbi_base + PCIE_PHY_DEBUG_R1));
350+
return -EINVAL;
353351
}
354352

355353
static irqreturn_t imx6_pcie_msi_handler(int irq, void *arg)

drivers/pci/host/pci-keystone.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ DECLARE_PCI_FIXUP_ENABLE(PCI_ANY_ID, PCI_ANY_ID, quirk_limit_mrrs);
8888
static int ks_pcie_establish_link(struct keystone_pcie *ks_pcie)
8989
{
9090
struct pcie_port *pp = &ks_pcie->pp;
91-
int count = 200;
91+
unsigned int retries;
9292

9393
dw_pcie_setup_rc(pp);
9494

@@ -99,17 +99,15 @@ static int ks_pcie_establish_link(struct keystone_pcie *ks_pcie)
9999

100100
ks_dw_pcie_initiate_link_train(ks_pcie);
101101
/* check if the link is up or not */
102-
while (!dw_pcie_link_up(pp)) {
102+
for (retries = 0; retries < 200; retries++) {
103+
if (dw_pcie_link_up(pp))
104+
return 0;
103105
usleep_range(100, 1000);
104-
if (--count) {
105-
ks_dw_pcie_initiate_link_train(ks_pcie);
106-
continue;
107-
}
108-
dev_err(pp->dev, "phy link never came up\n");
109-
return -EINVAL;
106+
ks_dw_pcie_initiate_link_train(ks_pcie);
110107
}
111108

112-
return 0;
109+
dev_err(pp->dev, "phy link never came up\n");
110+
return -EINVAL;
113111
}
114112

115113
static void ks_pcie_msi_irq_handler(unsigned int irq, struct irq_desc *desc)

drivers/pci/host/pci-layerscape.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,16 @@ static int ls_pcie_link_up(struct pcie_port *pp)
6464

6565
static int ls_pcie_establish_link(struct pcie_port *pp)
6666
{
67-
int count = 0;
67+
unsigned int retries;
6868

69-
while (!dw_pcie_link_up(pp)) {
69+
for (retries = 0; retries < 200; retries++) {
70+
if (dw_pcie_link_up(pp))
71+
return 0;
7072
usleep_range(100, 1000);
71-
count++;
72-
if (count >= 200) {
73-
dev_err(pp->dev, "phy link never came up\n");
74-
return -EINVAL;
75-
}
7673
}
7774

78-
return 0;
75+
dev_err(pp->dev, "phy link never came up\n");
76+
return -EINVAL;
7977
}
8078

8179
static void ls_pcie_host_init(struct pcie_port *pp)

drivers/pci/host/pcie-spear13xx.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ struct pcie_app_reg {
146146
static int spear13xx_pcie_establish_link(struct pcie_port *pp)
147147
{
148148
u32 val;
149-
int count = 0;
150149
struct spear13xx_pcie *spear13xx_pcie = to_spear13xx_pcie(pp);
151150
struct pcie_app_reg *app_reg = spear13xx_pcie->app_base;
152151
u32 exp_cap_off = EXP_CAP_ID_OFFSET;
152+
unsigned int retries;
153153

154154
if (dw_pcie_link_up(pp)) {
155155
dev_err(pp->dev, "link already up\n");
@@ -201,17 +201,16 @@ static int spear13xx_pcie_establish_link(struct pcie_port *pp)
201201
&app_reg->app_ctrl_0);
202202

203203
/* check if the link is up or not */
204-
while (!dw_pcie_link_up(pp)) {
205-
mdelay(100);
206-
count++;
207-
if (count == 10) {
208-
dev_err(pp->dev, "link Fail\n");
209-
return -EINVAL;
204+
for (retries = 0; retries < 10; retries++) {
205+
if (dw_pcie_link_up(pp)) {
206+
dev_info(pp->dev, "link up\n");
207+
return 0;
210208
}
209+
mdelay(100);
211210
}
212-
dev_info(pp->dev, "link up\n");
213211

214-
return 0;
212+
dev_err(pp->dev, "link Fail\n");
213+
return -EINVAL;
215214
}
216215

217216
static irqreturn_t spear13xx_pcie_irq_handler(int irq, void *arg)

0 commit comments

Comments
 (0)