diff options
author | Bjorn Helgaas <bhelgaas@google.com> | 2015-06-02 17:47:17 -0400 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2015-06-10 14:52:59 -0400 |
commit | 6cbb247e85eb4449d31a8dcb9b3f0464772b1395 (patch) | |
tree | 4a73b6883501b2ec7dba50fdc377c1fc60c961c2 | |
parent | 1d3f9bac716a09af2d5d6e8601336ec9efcdccda (diff) |
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 <bhelgaas@google.com>
Acked-by: Pratyush Anand <pratyush.anand@gmail.com>
-rw-r--r-- | drivers/pci/host/pci-dra7xx.c | 16 | ||||
-rw-r--r-- | drivers/pci/host/pci-exynos.c | 34 | ||||
-rw-r--r-- | drivers/pci/host/pci-imx6.c | 20 | ||||
-rw-r--r-- | drivers/pci/host/pci-keystone.c | 16 | ||||
-rw-r--r-- | drivers/pci/host/pci-layerscape.c | 14 | ||||
-rw-r--r-- | drivers/pci/host/pcie-spear13xx.c | 17 |
6 files changed, 51 insertions, 66 deletions
diff --git a/drivers/pci/host/pci-dra7xx.c b/drivers/pci/host/pci-dra7xx.c index e3d15d7875c2..80db09e47800 100644 --- a/drivers/pci/host/pci-dra7xx.c +++ b/drivers/pci/host/pci-dra7xx.c | |||
@@ -93,9 +93,9 @@ static int dra7xx_pcie_link_up(struct pcie_port *pp) | |||
93 | 93 | ||
94 | static int dra7xx_pcie_establish_link(struct pcie_port *pp) | 94 | static int dra7xx_pcie_establish_link(struct pcie_port *pp) |
95 | { | 95 | { |
96 | u32 reg; | ||
97 | unsigned int retries = 1000; | ||
98 | struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp); | 96 | struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp); |
97 | u32 reg; | ||
98 | unsigned int retries; | ||
99 | 99 | ||
100 | if (dw_pcie_link_up(pp)) { | 100 | if (dw_pcie_link_up(pp)) { |
101 | dev_err(pp->dev, "link is already up\n"); | 101 | dev_err(pp->dev, "link is already up\n"); |
@@ -106,18 +106,14 @@ static int dra7xx_pcie_establish_link(struct pcie_port *pp) | |||
106 | reg |= LTSSM_EN; | 106 | reg |= LTSSM_EN; |
107 | dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD, reg); | 107 | dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD, reg); |
108 | 108 | ||
109 | while (retries--) { | 109 | for (retries = 0; retries < 1000; retries++) { |
110 | if (dw_pcie_link_up(pp)) | 110 | if (dw_pcie_link_up(pp)) |
111 | break; | 111 | return 0; |
112 | usleep_range(10, 20); | 112 | usleep_range(10, 20); |
113 | } | 113 | } |
114 | 114 | ||
115 | if (retries == 0) { | 115 | dev_err(pp->dev, "link is not up\n"); |
116 | dev_err(pp->dev, "link is not up\n"); | 116 | return -EINVAL; |
117 | return -ETIMEDOUT; | ||
118 | } | ||
119 | |||
120 | return 0; | ||
121 | } | 117 | } |
122 | 118 | ||
123 | static void dra7xx_pcie_enable_interrupts(struct pcie_port *pp) | 119 | static void dra7xx_pcie_enable_interrupts(struct pcie_port *pp) |
diff --git a/drivers/pci/host/pci-exynos.c b/drivers/pci/host/pci-exynos.c index c139237e0e52..f9f468d9a819 100644 --- a/drivers/pci/host/pci-exynos.c +++ b/drivers/pci/host/pci-exynos.c | |||
@@ -316,9 +316,9 @@ static void exynos_pcie_assert_reset(struct pcie_port *pp) | |||
316 | 316 | ||
317 | static int exynos_pcie_establish_link(struct pcie_port *pp) | 317 | static int exynos_pcie_establish_link(struct pcie_port *pp) |
318 | { | 318 | { |
319 | u32 val; | ||
320 | int count = 0; | ||
321 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); | 319 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); |
320 | u32 val; | ||
321 | unsigned int retries; | ||
322 | 322 | ||
323 | if (dw_pcie_link_up(pp)) { | 323 | if (dw_pcie_link_up(pp)) { |
324 | dev_err(pp->dev, "Link already up\n"); | 324 | dev_err(pp->dev, "Link already up\n"); |
@@ -357,27 +357,23 @@ static int exynos_pcie_establish_link(struct pcie_port *pp) | |||
357 | PCIE_APP_LTSSM_ENABLE); | 357 | PCIE_APP_LTSSM_ENABLE); |
358 | 358 | ||
359 | /* check if the link is up or not */ | 359 | /* check if the link is up or not */ |
360 | while (!dw_pcie_link_up(pp)) { | 360 | for (retries = 0; retries < 10; retries++) { |
361 | mdelay(100); | 361 | if (dw_pcie_link_up(pp)) { |
362 | count++; | 362 | dev_info(pp->dev, "Link up\n"); |
363 | if (count == 10) { | 363 | return 0; |
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; | ||
375 | } | 364 | } |
365 | mdelay(100); | ||
376 | } | 366 | } |
377 | 367 | ||
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); | ||
379 | 374 | ||
380 | return 0; | 375 | dev_err(pp->dev, "PCIe Link Fail\n"); |
376 | return -EINVAL; | ||
381 | } | 377 | } |
382 | 378 | ||
383 | static void exynos_pcie_clear_irq_pulse(struct pcie_port *pp) | 379 | static void exynos_pcie_clear_irq_pulse(struct pcie_port *pp) |
diff --git a/drivers/pci/host/pci-imx6.c b/drivers/pci/host/pci-imx6.c index 8cc012371ca7..af7da8ac8082 100644 --- a/drivers/pci/host/pci-imx6.c +++ b/drivers/pci/host/pci-imx6.c | |||
@@ -335,21 +335,19 @@ static void imx6_pcie_init_phy(struct pcie_port *pp) | |||
335 | 335 | ||
336 | static int imx6_pcie_wait_for_link(struct pcie_port *pp) | 336 | static int imx6_pcie_wait_for_link(struct pcie_port *pp) |
337 | { | 337 | { |
338 | int count = 200; | 338 | unsigned int retries; |
339 | 339 | ||
340 | while (!dw_pcie_link_up(pp)) { | 340 | for (retries = 0; retries < 200; retries++) { |
341 | if (dw_pcie_link_up(pp)) | ||
342 | return 0; | ||
341 | usleep_range(100, 1000); | 343 | 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; | ||
350 | } | 344 | } |
351 | 345 | ||
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; | ||
353 | } | 351 | } |
354 | 352 | ||
355 | static irqreturn_t imx6_pcie_msi_handler(int irq, void *arg) | 353 | static irqreturn_t imx6_pcie_msi_handler(int irq, void *arg) |
diff --git a/drivers/pci/host/pci-keystone.c b/drivers/pci/host/pci-keystone.c index 75333b0c4f0a..b75d684aefcd 100644 --- a/drivers/pci/host/pci-keystone.c +++ b/drivers/pci/host/pci-keystone.c | |||
@@ -88,7 +88,7 @@ DECLARE_PCI_FIXUP_ENABLE(PCI_ANY_ID, PCI_ANY_ID, quirk_limit_mrrs); | |||
88 | static int ks_pcie_establish_link(struct keystone_pcie *ks_pcie) | 88 | static int ks_pcie_establish_link(struct keystone_pcie *ks_pcie) |
89 | { | 89 | { |
90 | struct pcie_port *pp = &ks_pcie->pp; | 90 | struct pcie_port *pp = &ks_pcie->pp; |
91 | int count = 200; | 91 | unsigned int retries; |
92 | 92 | ||
93 | dw_pcie_setup_rc(pp); | 93 | dw_pcie_setup_rc(pp); |
94 | 94 | ||
@@ -99,17 +99,15 @@ static int ks_pcie_establish_link(struct keystone_pcie *ks_pcie) | |||
99 | 99 | ||
100 | ks_dw_pcie_initiate_link_train(ks_pcie); | 100 | ks_dw_pcie_initiate_link_train(ks_pcie); |
101 | /* check if the link is up or not */ | 101 | /* 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; | ||
103 | usleep_range(100, 1000); | 105 | usleep_range(100, 1000); |
104 | if (--count) { | 106 | ks_dw_pcie_initiate_link_train(ks_pcie); |
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; | ||
110 | } | 107 | } |
111 | 108 | ||
112 | return 0; | 109 | dev_err(pp->dev, "phy link never came up\n"); |
110 | return -EINVAL; | ||
113 | } | 111 | } |
114 | 112 | ||
115 | static void ks_pcie_msi_irq_handler(unsigned int irq, struct irq_desc *desc) | 113 | static void ks_pcie_msi_irq_handler(unsigned int irq, struct irq_desc *desc) |
diff --git a/drivers/pci/host/pci-layerscape.c b/drivers/pci/host/pci-layerscape.c index 434b116f1a7e..b2328ea13dcf 100644 --- a/drivers/pci/host/pci-layerscape.c +++ b/drivers/pci/host/pci-layerscape.c | |||
@@ -64,18 +64,16 @@ static int ls_pcie_link_up(struct pcie_port *pp) | |||
64 | 64 | ||
65 | static int ls_pcie_establish_link(struct pcie_port *pp) | 65 | static int ls_pcie_establish_link(struct pcie_port *pp) |
66 | { | 66 | { |
67 | int count = 0; | 67 | unsigned int retries; |
68 | 68 | ||
69 | while (!dw_pcie_link_up(pp)) { | 69 | for (retries = 0; retries < 200; retries++) { |
70 | if (dw_pcie_link_up(pp)) | ||
71 | return 0; | ||
70 | usleep_range(100, 1000); | 72 | 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 | } | ||
76 | } | 73 | } |
77 | 74 | ||
78 | return 0; | 75 | dev_err(pp->dev, "phy link never came up\n"); |
76 | return -EINVAL; | ||
79 | } | 77 | } |
80 | 78 | ||
81 | static void ls_pcie_host_init(struct pcie_port *pp) | 79 | static void ls_pcie_host_init(struct pcie_port *pp) |
diff --git a/drivers/pci/host/pcie-spear13xx.c b/drivers/pci/host/pcie-spear13xx.c index 020d78890719..dfec4281bd50 100644 --- a/drivers/pci/host/pcie-spear13xx.c +++ b/drivers/pci/host/pcie-spear13xx.c | |||
@@ -146,10 +146,10 @@ struct pcie_app_reg { | |||
146 | static int spear13xx_pcie_establish_link(struct pcie_port *pp) | 146 | static int spear13xx_pcie_establish_link(struct pcie_port *pp) |
147 | { | 147 | { |
148 | u32 val; | 148 | u32 val; |
149 | int count = 0; | ||
150 | struct spear13xx_pcie *spear13xx_pcie = to_spear13xx_pcie(pp); | 149 | struct spear13xx_pcie *spear13xx_pcie = to_spear13xx_pcie(pp); |
151 | struct pcie_app_reg *app_reg = spear13xx_pcie->app_base; | 150 | struct pcie_app_reg *app_reg = spear13xx_pcie->app_base; |
152 | u32 exp_cap_off = EXP_CAP_ID_OFFSET; | 151 | u32 exp_cap_off = EXP_CAP_ID_OFFSET; |
152 | unsigned int retries; | ||
153 | 153 | ||
154 | if (dw_pcie_link_up(pp)) { | 154 | if (dw_pcie_link_up(pp)) { |
155 | dev_err(pp->dev, "link already up\n"); | 155 | dev_err(pp->dev, "link already up\n"); |
@@ -201,17 +201,16 @@ static int spear13xx_pcie_establish_link(struct pcie_port *pp) | |||
201 | &app_reg->app_ctrl_0); | 201 | &app_reg->app_ctrl_0); |
202 | 202 | ||
203 | /* check if the link is up or not */ | 203 | /* check if the link is up or not */ |
204 | while (!dw_pcie_link_up(pp)) { | 204 | for (retries = 0; retries < 10; retries++) { |
205 | mdelay(100); | 205 | if (dw_pcie_link_up(pp)) { |
206 | count++; | 206 | dev_info(pp->dev, "link up\n"); |
207 | if (count == 10) { | 207 | return 0; |
208 | dev_err(pp->dev, "link Fail\n"); | ||
209 | return -EINVAL; | ||
210 | } | 208 | } |
209 | mdelay(100); | ||
211 | } | 210 | } |
212 | dev_info(pp->dev, "link up\n"); | ||
213 | 211 | ||
214 | return 0; | 212 | dev_err(pp->dev, "link Fail\n"); |
213 | return -EINVAL; | ||
215 | } | 214 | } |
216 | 215 | ||
217 | static irqreturn_t spear13xx_pcie_irq_handler(int irq, void *arg) | 216 | static irqreturn_t spear13xx_pcie_irq_handler(int irq, void *arg) |