Skip to content

Commit

Permalink
PCI: altera: Poll for link up status after retraining the link
Browse files Browse the repository at this point in the history
Some PCIe devices take a long time to reach link up state after retrain.
Poll for link up status after retraining the link.  This is to make sure
the link is up before we access configuration space.

[bhelgaas: changelog]
Signed-off-by: Ley Foon Tan <lftan@altera.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
  • Loading branch information
Ley Foon Tan authored and Bjorn Helgaas committed Jul 22, 2016
1 parent c622032 commit 3a928e9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion drivers/pci/host/pcie-altera.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
#define TLP_LOOP 500
#define RP_DEVFN 0

#define LINK_UP_TIMEOUT 5000

#define INTX_NUM 4

#define DWORD_MASK 3
Expand Down Expand Up @@ -101,6 +103,7 @@ static void altera_pcie_retrain(struct pci_dev *dev)
{
u16 linkcap, linkstat;
struct altera_pcie *pcie = dev->bus->sysdata;
int timeout = 0;

if (!altera_pcie_link_is_up(pcie))
return;
Expand All @@ -115,9 +118,16 @@ static void altera_pcie_retrain(struct pci_dev *dev)
return;

pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &linkstat);
if ((linkstat & PCI_EXP_LNKSTA_CLS) == PCI_EXP_LNKSTA_CLS_2_5GB)
if ((linkstat & PCI_EXP_LNKSTA_CLS) == PCI_EXP_LNKSTA_CLS_2_5GB) {
pcie_capability_set_word(dev, PCI_EXP_LNKCTL,
PCI_EXP_LNKCTL_RL);
while (!altera_pcie_link_is_up(pcie)) {
timeout++;
if (timeout > LINK_UP_TIMEOUT)
break;
udelay(5);
}
}
}
DECLARE_PCI_FIXUP_EARLY(0x1172, PCI_ANY_ID, altera_pcie_retrain);

Expand Down

0 comments on commit 3a928e9

Please sign in to comment.