From: Geoff <geoff@hostfission.com>
Date: Tue, 23 Jan 2018 00:04:29 -0400
Subject: [PATCH] tr bus resets fix

fixing tr bus resets?

Bugzilla: N/A
Upstream-status: Fedora mustard
---
 drivers/pci/pci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)



diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 4a7c686..6099a32 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1112,12 +1112,12 @@ int pci_save_state(struct pci_dev *dev)
 EXPORT_SYMBOL(pci_save_state);
 
 static void pci_restore_config_dword(struct pci_dev *pdev, int offset,
-				     u32 saved_val, int retry)
+				     u32 saved_val, int retry, int force)
 {
 	u32 val;
 
 	pci_read_config_dword(pdev, offset, &val);
-	if (val == saved_val)
+	if (!force && val == saved_val)
 		return;
 
 	for (;;) {
@@ -1136,25 +1136,25 @@ static void pci_restore_config_dword(struct pci_dev *pdev, int offset,
 }
 
 static void pci_restore_config_space_range(struct pci_dev *pdev,
-					   int start, int end, int retry)
+					   int start, int end, int retry, int force)
 {
 	int index;
 
 	for (index = end; index >= start; index--)
 		pci_restore_config_dword(pdev, 4 * index,
 					 pdev->saved_config_space[index],
-					 retry);
+					 retry, force);
 }
 
-static void pci_restore_config_space(struct pci_dev *pdev)
+static void pci_restore_config_space(struct pci_dev *pdev, int force)
 {
 	if (pdev->hdr_type == PCI_HEADER_TYPE_NORMAL) {
-		pci_restore_config_space_range(pdev, 10, 15, 0);
+		pci_restore_config_space_range(pdev, 10, 15, 0, force);
 		/* Restore BARs before the command register. */
-		pci_restore_config_space_range(pdev, 4, 9, 10);
-		pci_restore_config_space_range(pdev, 0, 3, 0);
+		pci_restore_config_space_range(pdev, 4, 9, 10, force);
+		pci_restore_config_space_range(pdev, 0, 3, 0, force);
 	} else {
-		pci_restore_config_space_range(pdev, 0, 15, 0);
+		pci_restore_config_space_range(pdev, 0, 15, 0, force);
 	}
 }
 
@@ -1162,7 +1162,7 @@ static void pci_restore_config_space(struct pci_dev *pdev)
  * pci_restore_state - Restore the saved state of a PCI device
  * @dev: - PCI device that we're dealing with
  */
-void pci_restore_state(struct pci_dev *dev)
+void _pci_restore_state(struct pci_dev *dev, int force)
 {
 	if (!dev->state_saved)
 		return;
@@ -1176,7 +1176,7 @@ void pci_restore_state(struct pci_dev *dev)
 
 	pci_cleanup_aer_error_status_regs(dev);
 
-	pci_restore_config_space(dev);
+	pci_restore_config_space(dev, force);
 
 	pci_restore_pcix_state(dev);
 	pci_restore_msi_state(dev);
@@ -1187,6 +1187,11 @@ void pci_restore_state(struct pci_dev *dev)
 
 	dev->state_saved = false;
 }
+
+void pci_restore_state(struct pci_dev *dev)
+{
+	_pci_restore_state(dev, 0);
+}
 EXPORT_SYMBOL(pci_restore_state);
 
 struct pci_saved_state {
@@ -4083,6 +4088,8 @@ void pci_reset_secondary_bus(struct pci_dev *dev)
 {
 	u16 ctrl;
 
+        pci_save_state(dev);
+
 	pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &ctrl);
 	ctrl |= PCI_BRIDGE_CTL_BUS_RESET;
 	pci_write_config_word(dev, PCI_BRIDGE_CONTROL, ctrl);
@@ -4092,9 +4099,13 @@ void pci_reset_secondary_bus(struct pci_dev *dev)
 	 */
 	msleep(2);
 
+        pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &ctrl);
+
 	ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET;
 	pci_write_config_word(dev, PCI_BRIDGE_CONTROL, ctrl);
 
+        _pci_restore_state(dev, 1);
+
 	/*
 	 * Trhfa for conventional PCI is 2^25 clock cycles.
 	 * Assuming a minimum 33MHz clock this results in a 1s
