]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/pci/pci.c
Merge branch 'pci/enumeration'
[linux.git] / drivers / pci / pci.c
index 4bafa817c40a9b2f6805bb7c92bbc566262033ae..2aaab81341ac9557b1d682076a479ea9eaaf20c5 100644 (file)
@@ -4138,6 +4138,35 @@ static int pci_pm_reset(struct pci_dev *dev, int probe)
 
        return pci_dev_wait(dev, "PM D3->D0", PCIE_RESET_READY_POLL_MS);
 }
+/**
+ * pcie_wait_for_link - Wait until link is active or inactive
+ * @pdev: Bridge device
+ * @active: waiting for active or inactive?
+ *
+ * Use this to wait till link becomes active or inactive.
+ */
+bool pcie_wait_for_link(struct pci_dev *pdev, bool active)
+{
+       int timeout = 1000;
+       bool ret;
+       u16 lnk_status;
+
+       for (;;) {
+               pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status);
+               ret = !!(lnk_status & PCI_EXP_LNKSTA_DLLLA);
+               if (ret == active)
+                       return true;
+               if (timeout <= 0)
+                       break;
+               msleep(10);
+               timeout -= 10;
+       }
+
+       pci_info(pdev, "Data Link Layer Link Active not %s in 1000 msec\n",
+                active ? "set" : "cleared");
+
+       return false;
+}
 
 void pci_reset_secondary_bus(struct pci_dev *dev)
 {