[Skiboot] [PATCH 2/5] core/pci: Initialize AER capability in PCI core

Gavin Shan gwshan at linux.vnet.ibm.com
Fri Nov 18 16:05:16 AEDT 2016


Currently, AER capability is initialized in phb_ops->device_init()
which is called after the device is instantiated by PCI core, or
reinitializing the device after reset in EEH recovery path. It
means we are maintaining similar sets of codes for P7IOC, PHB3
and PHB4.

This moves the logic initializing AER capability from P7IOC, PHB3
and PHB4 to PCI core, thus the duplicated codes can be dropped.
No functional changes introduced by this.

Signed-off-by: Gavin Shan <gwshan at linux.vnet.ibm.com>
---
 core/pci.c     | 13 +++++++++++++
 hw/p7ioc-phb.c | 19 +++----------------
 hw/phb3.c      | 19 +++----------------
 hw/phb4.c      | 19 +++----------------
 4 files changed, 22 insertions(+), 48 deletions(-)

diff --git a/core/pci.c b/core/pci.c
index 12059a2..02993e9 100644
--- a/core/pci.c
+++ b/core/pci.c
@@ -188,9 +188,22 @@ static void pci_init_pcie_cap(struct phb *phb, struct pci_device *pd)
 		pd->mps = 4096;
 }
 
+static void pci_init_aer_cap(struct phb *phb, struct pci_device *pd)
+{
+	int64_t pos;
+
+	if (!pci_has_cap(pd, PCI_CFG_CAP_ID_EXP, false))
+		return;
+
+	pos = pci_find_ecap(phb, pd->bdfn, PCIECAP_ID_AER, NULL);
+	if (pos > 0)
+		pci_set_cap(pd, PCIECAP_ID_AER, pos, true);
+}
+
 void pci_init_capabilities(struct phb *phb, struct pci_device *pd)
 {
 	pci_init_pcie_cap(phb, pd);
+	pci_init_aer_cap(phb, pd);
 }
 
 static struct pci_device *pci_scan_one(struct phb *phb, struct pci_device *parent,
diff --git a/hw/p7ioc-phb.c b/hw/p7ioc-phb.c
index 50608e2..ba836c6 100644
--- a/hw/p7ioc-phb.c
+++ b/hw/p7ioc-phb.c
@@ -1508,26 +1508,13 @@ static int p7ioc_device_init(struct phb *phb,
 			     struct pci_device *dev,
 			     void *data __unused)
 {
-	int ecap = 0;
-	int aercap = 0;
-
-	/* Figure out AER capability */
-	if (pci_has_cap(dev, PCI_CFG_CAP_ID_EXP, false)) {
-		ecap = pci_cap(dev, PCI_CFG_CAP_ID_EXP, false);
-
-		if (!pci_has_cap(dev, PCIECAP_ID_AER, true)) {
-			aercap = pci_find_ecap(phb, dev->bdfn,
-					       PCIECAP_ID_AER, NULL);
-			if (aercap > 0)
-				pci_set_cap(dev, PCIECAP_ID_AER, aercap, true);
-		} else {
-			aercap = pci_cap(dev, PCIECAP_ID_AER, true);
-		}
-	}
+	int ecap, aercap;
 
 	/* Common initialization for the device */
 	pci_device_init(phb, dev);
 
+        ecap = pci_cap(dev, PCI_CFG_CAP_ID_EXP, false);
+        aercap = pci_cap(dev, PCIECAP_ID_AER, true);
 	if (dev->dev_type == PCIE_TYPE_ROOT_PORT)
 		p7ioc_root_port_init(phb, dev, ecap, aercap);
 	else if (dev->dev_type == PCIE_TYPE_SWITCH_UPPORT ||
diff --git a/hw/phb3.c b/hw/phb3.c
index 52b30c2..d6ff033 100644
--- a/hw/phb3.c
+++ b/hw/phb3.c
@@ -559,29 +559,16 @@ static int phb3_device_init(struct phb *phb,
 			    struct pci_device *dev,
 			    void *data __unused)
 {
-	int ecap = 0;
-	int aercap = 0;
+	int ecap, aercap;
 
 	/* Some special adapter tweaks for devices directly under the PHB */
 	phb3_check_device_quirks(phb, dev);
 
-	/* Figure out PCIe & AER capability */
-	if (pci_has_cap(dev, PCI_CFG_CAP_ID_EXP, false)) {
-		ecap = pci_cap(dev, PCI_CFG_CAP_ID_EXP, false);
-
-		if (!pci_has_cap(dev, PCIECAP_ID_AER, true)) {
-			aercap = pci_find_ecap(phb, dev->bdfn,
-					       PCIECAP_ID_AER, NULL);
-			if (aercap > 0)
-				pci_set_cap(dev, PCIECAP_ID_AER, aercap, true);
-		} else {
-			aercap = pci_cap(dev, PCIECAP_ID_AER, true);
-		}
-	}
-
 	/* Common initialization for the device */
 	pci_device_init(phb, dev);
 
+	ecap = pci_cap(dev, PCI_CFG_CAP_ID_EXP, false);
+	aercap = pci_cap(dev, PCIECAP_ID_AER, true);
 	if (dev->dev_type == PCIE_TYPE_ROOT_PORT)
 		phb3_root_port_init(phb, dev, ecap, aercap);
 	else if (dev->dev_type == PCIE_TYPE_SWITCH_UPPORT ||
diff --git a/hw/phb4.c b/hw/phb4.c
index a21aa1a..a1819ae 100644
--- a/hw/phb4.c
+++ b/hw/phb4.c
@@ -643,30 +643,17 @@ static void phb4_check_device_quirks(struct phb *phb, struct pci_device *dev)
 static int phb4_device_init(struct phb *phb, struct pci_device *dev,
 			    void *data __unused)
 {
-	int ecap = 0;
-	int aercap = 0;
+	int ecap, aercap;
 
 	/* Some special adapter tweaks for devices directly under the PHB */
 	if (dev->primary_bus == 1)
 		phb4_check_device_quirks(phb, dev);
 
-	/* Figure out PCIe & AER capability */
-	if (pci_has_cap(dev, PCI_CFG_CAP_ID_EXP, false)) {
-		ecap = pci_cap(dev, PCI_CFG_CAP_ID_EXP, false);
-
-		if (!pci_has_cap(dev, PCIECAP_ID_AER, true)) {
-			aercap = pci_find_ecap(phb, dev->bdfn,
-					       PCIECAP_ID_AER, NULL);
-			if (aercap > 0)
-				pci_set_cap(dev, PCIECAP_ID_AER, aercap, true);
-		} else {
-			aercap = pci_cap(dev, PCIECAP_ID_AER, true);
-		}
-	}
-
 	/* Common initialization for the device */
 	pci_device_init(phb, dev);
 
+	ecap = pci_cap(dev, PCI_CFG_CAP_ID_EXP, false);
+	aercap = pci_cap(dev, PCIECAP_ID_AER, true);
 	if (dev->dev_type == PCIE_TYPE_ROOT_PORT)
 		phb4_root_port_init(phb, dev, ecap, aercap);
 	else if (dev->dev_type == PCIE_TYPE_SWITCH_UPPORT ||
-- 
2.1.0



More information about the Skiboot mailing list