diff mbox series

[v2,12/17] PCI: Refactor pci_dev_wait to take pci_init_event

Message ID 20200302184429.12880-13-stanspas@amazon.com (mailing list archive)
State Superseded, archived
Headers show
Series Improve PCI device post-reset readiness polling | expand

Commit Message

Stanislav Spassov March 2, 2020, 6:44 p.m. UTC
From: Stanislav Spassov <stanspas@amazon.de>

Knowing what kind of event knocked the device out could be useful not
only for log output, but also to use different timeout/waiting behavior.

Note: we do lose some specificity in log output due to the aliasing of
FLR and AF_FLR, but it is doubtful the distinction is worthwhile.

Also, "bus reset" does not exactly match the more generic name for
PCI_INIT_EVENT_RESET, which could break programs that scrape kernel
output for overly specific patterns.

Signed-off-by: Stanislav Spassov <stanspas@amazon.de>
---
 drivers/pci/pci.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 9435e2b19f7b..5d62d4841d68 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1030,8 +1030,9 @@  void pci_wakeup_bus(struct pci_bus *bus)
 		pci_walk_bus(bus, pci_wakeup, NULL);
 }
 
-static int pci_dev_wait(struct pci_dev *dev, char *reset_type)
+static int pci_dev_wait(struct pci_dev *dev, enum pci_init_event event)
 {
+	const char *event_name = pci_init_event_name(event);
 	int timeout = PCIE_RESET_READY_POLL_MS;
 	int delay = 1;
 	u32 id;
@@ -1052,13 +1053,13 @@  static int pci_dev_wait(struct pci_dev *dev, char *reset_type)
 	while (id == ~0) {
 		if (delay > timeout) {
 			pci_warn(dev, "not ready %dms after %s; giving up\n",
-				 delay - 1, reset_type);
+				 delay - 1, event_name);
 			return -ETIMEDOUT;
 		}
 
 		if (delay > 1000)
 			pci_info(dev, "not ready %dms after %s; waiting\n",
-				 delay - 1, reset_type);
+				 delay - 1, event_name);
 
 		msleep(delay);
 		delay *= 2;
@@ -1067,7 +1068,7 @@  static int pci_dev_wait(struct pci_dev *dev, char *reset_type)
 
 	if (delay > 1000)
 		pci_info(dev, "ready %dms after %s\n", delay - 1,
-			 reset_type);
+			 event_name);
 
 	return 0;
 }
@@ -4515,7 +4516,7 @@  int pcie_flr(struct pci_dev *dev)
 
 	msleep(dev->delay[PCI_INIT_EVENT_FLR]);
 
-	return pci_dev_wait(dev, "FLR");
+	return pci_dev_wait(dev, PCI_INIT_EVENT_FLR);
 }
 EXPORT_SYMBOL_GPL(pcie_flr);
 
@@ -4554,7 +4555,7 @@  static int pci_af_flr(struct pci_dev *dev, int probe)
 
 	msleep(dev->delay[PCI_INIT_EVENT_FLR]);
 
-	return pci_dev_wait(dev, "AF_FLR");
+	return pci_dev_wait(dev, PCI_INIT_EVENT_FLR);
 }
 
 /**
@@ -4601,7 +4602,7 @@  static int pci_pm_reset(struct pci_dev *dev, int probe)
 	pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, csr);
 	pci_dev_d3_sleep(dev);
 
-	return pci_dev_wait(dev, "PM D3hot->D0");
+	return pci_dev_wait(dev, PCI_INIT_EVENT_D3HOT_TO_D0);
 }
 
 /**
@@ -4843,7 +4844,7 @@  int pci_bridge_secondary_bus_reset(struct pci_dev *dev)
 {
 	pcibios_reset_secondary_bus(dev);
 
-	return pci_dev_wait(dev, "bus reset");
+	return pci_dev_wait(dev, PCI_INIT_EVENT_RESET);
 }
 EXPORT_SYMBOL_GPL(pci_bridge_secondary_bus_reset);