Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+51 -66
+6 -10
drivers/pci/host/pci-dra7xx.c
··· 93 93 94 94 static int dra7xx_pcie_establish_link(struct pcie_port *pp) 95 95 { 96 - u32 reg; 97 - unsigned int retries = 1000; 98 96 struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp); 97 + u32 reg; 98 + unsigned int retries; 99 99 100 100 if (dw_pcie_link_up(pp)) { 101 101 dev_err(pp->dev, "link is already up\n"); ··· 106 106 reg |= LTSSM_EN; 107 107 dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD, reg); 108 108 109 - while (retries--) { 109 + for (retries = 0; retries < 1000; retries++) { 110 110 if (dw_pcie_link_up(pp)) 111 - break; 111 + return 0; 112 112 usleep_range(10, 20); 113 113 } 114 114 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; 121 117 } 122 118 123 119 static void dra7xx_pcie_enable_interrupts(struct pcie_port *pp)
+15 -19
drivers/pci/host/pci-exynos.c
··· 316 316 317 317 static int exynos_pcie_establish_link(struct pcie_port *pp) 318 318 { 319 - u32 val; 320 - int count = 0; 321 319 struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); 320 + u32 val; 321 + unsigned int retries; 322 322 323 323 if (dw_pcie_link_up(pp)) { 324 324 dev_err(pp->dev, "Link already up\n"); ··· 357 357 PCIE_APP_LTSSM_ENABLE); 358 358 359 359 /* 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; 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 379 static void exynos_pcie_clear_irq_pulse(struct pcie_port *pp)
+9 -11
drivers/pci/host/pci-imx6.c
··· 335 335 336 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 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 353 static irqreturn_t imx6_pcie_msi_handler(int irq, void *arg)
+7 -9
drivers/pci/host/pci-keystone.c
··· 88 88 static int ks_pcie_establish_link(struct keystone_pcie *ks_pcie) 89 89 { 90 90 struct pcie_port *pp = &ks_pcie->pp; 91 - int count = 200; 91 + unsigned int retries; 92 92 93 93 dw_pcie_setup_rc(pp); 94 94 ··· 99 99 100 100 ks_dw_pcie_initiate_link_train(ks_pcie); 101 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 105 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); 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 113 static void ks_pcie_msi_irq_handler(unsigned int irq, struct irq_desc *desc)
+6 -8
drivers/pci/host/pci-layerscape.c
··· 64 64 65 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 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 79 static void ls_pcie_host_init(struct pcie_port *pp)
+8 -9
drivers/pci/host/pcie-spear13xx.c
··· 146 146 static int spear13xx_pcie_establish_link(struct pcie_port *pp) 147 147 { 148 148 u32 val; 149 - int count = 0; 150 149 struct spear13xx_pcie *spear13xx_pcie = to_spear13xx_pcie(pp); 151 150 struct pcie_app_reg *app_reg = spear13xx_pcie->app_base; 152 151 u32 exp_cap_off = EXP_CAP_ID_OFFSET; 152 + unsigned int retries; 153 153 154 154 if (dw_pcie_link_up(pp)) { 155 155 dev_err(pp->dev, "link already up\n"); ··· 201 201 &app_reg->app_ctrl_0); 202 202 203 203 /* 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; 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 216 static irqreturn_t spear13xx_pcie_irq_handler(int irq, void *arg)