Skip to contentSkip to conversation

EEH core pci_dn de-lousing

PATCH Superseded Oliver O'Halloran 3 participants 27 messages Jul 6, 2020 – Jul 14, 2020

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Oliver O'Halloran

author reviewer
#0 lore raw

Removes most of the uses of pci_dn in the EEH core. There's a few stragglers remaining in pseries specific bits of kernel/eeh*.c mainly the the support for "open sriov" where the hypervisor allows the guest to manage SR-IOV physical functions. We can largely ignore that on non-pseries platforms though.

There'll be a follow up to this which actually removes the use of pci_dn from PowerNV entirely and we can start looking at properly supporting native PCIe. At last.

Oliver

author reviewer
#1 lore raw

PATCH 1/14 powerpc/eeh: Remove eeh_dev_phb_init_dynamic()

This function is a one line wrapper around eeh_phb_pe_create() and despite the name it doesn't create any eeh_dev structures. Replace it with direct calls to eeh_phb_pe_create() since that does what it says on the tin and removes a layer of indirection.

---
 arch/powerpc/include/asm/eeh.h             |  1 -
 arch/powerpc/kernel/eeh.c                  |  2 +-
 arch/powerpc/kernel/eeh_dev.c              | 13 -------------
 arch/powerpc/kernel/of_platform.c          |  4 ++--
 arch/powerpc/platforms/pseries/pci_dlpar.c |  2 +-
 5 files changed, 4 insertions(+), 18 deletions(-)
arch/powerpc/include/asm/eeh.h +0 -1
index 964a54292b36..646307481493 100644
@@ -294,7 +294,6 @@ const char *eeh_pe_loc_get(struct eeh_pe *pe);
 struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe);
 
 struct eeh_dev *eeh_dev_init(struct pci_dn *pdn);
-void eeh_dev_phb_init_dynamic(struct pci_controller *phb);
 void eeh_show_enabled(void);
 int __init eeh_ops_register(struct eeh_ops *ops);
 int __exit eeh_ops_unregister(const char *name);
arch/powerpc/kernel/eeh.c +1 -1
index d407981dec76..859f76020256 100644
@@ -1096,7 +1096,7 @@ static int eeh_init(void)
 
 	/* Initialize PHB PEs */
 	list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
-		eeh_dev_phb_init_dynamic(hose);
+		eeh_phb_pe_create(hose);
 
 	eeh_addr_cache_init();
 
arch/powerpc/kernel/eeh_dev.c +0 -13
index 7370185c7a05..8e159a12f10c 100644
@@ -52,16 +52,3 @@ struct eeh_dev *eeh_dev_init(struct pci_dn *pdn)
 
 	return edev;
 }
-
-/**
- * eeh_dev_phb_init_dynamic - Create EEH devices for devices included in PHB
- * @phb: PHB
- *
- * Scan the PHB OF node and its child association, then create the
- * EEH devices accordingly
- */
-void eeh_dev_phb_init_dynamic(struct pci_controller *phb)
-{
-	/* EEH PE for PHB */
-	eeh_phb_pe_create(phb);
-}
arch/powerpc/kernel/of_platform.c +2 -2
index 71a3f97dc988..f89376ff633e 100644
@@ -62,8 +62,8 @@ static int of_pci_phb_probe(struct platform_device *dev)
 	/* Init pci_dn data structures */
 	pci_devs_phb_init_dynamic(phb);
 
-	/* Create EEH PEs for the PHB */
-	eeh_dev_phb_init_dynamic(phb);
+	/* Create EEH PE for the PHB */
+	eeh_phb_pe_create(phb);
 
 	/* Scan the bus */
 	pcibios_scan_phb(phb);
arch/powerpc/platforms/pseries/pci_dlpar.c +1 -1
index b3a38f5a6b68..f9ae17e8a0f4 100644
@@ -34,7 +34,7 @@ struct pci_controller *init_phb_dynamic(struct device_node *dn)
 	pci_devs_phb_init_dynamic(phb);
 
 	/* Create EEH devices for the PHB */
-	eeh_dev_phb_init_dynamic(phb);
+	eeh_phb_pe_create(phb);
 
 	if (dn->child)
 		pseries_eeh_init_edev_recursive(PCI_DN(dn));
Signature · 1 line
2.26.2
#2 lore raw

Re: [PATCH 01/14] powerpc/eeh: Remove eeh_dev_phb_init_dynamic()

I love your patch! Yet something to improve:

Hi Oliver,

I love your patch! Yet something to improve:

[auto build test ERROR on powerpc/next]
[also build test ERROR on v5.8-rc4 next-20200706]
[cannot apply to scottwood/next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Oliver-O-Halloran/powerpc-eeh-Remove-eeh_dev_phb_init_dynamic/20200706-103630
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc64-randconfig-r006-20200706 (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc64

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

arch/powerpc/kernel/of_platform.c: In function 'of_pci_phb_probe':

>> arch/powerpc/kernel/of_platform.c:66:2: error: implicit declaration of function 'eeh_phb_pe_create' [-Werror=implicit-function-declaration]
      66 |  eeh_phb_pe_create(phb);
         |  ^~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

vim +/eeh_phb_pe_create +66 arch/powerpc/kernel/of_platform.c

    28	
    29	/* The probing of PCI controllers from of_platform is currently
    30	 * 64 bits only, mostly due to gratuitous differences between
    31	 * the 32 and 64 bits PCI code on PowerPC and the 32 bits one
    32	 * lacking some bits needed here.
    33	 */
    34	
    35	static int of_pci_phb_probe(struct platform_device *dev)
    36	{
    37		struct pci_controller *phb;
    38	
    39		/* Check if we can do that ... */
    40		if (ppc_md.pci_setup_phb == NULL)
    41			return -ENODEV;
    42	
    43		pr_info("Setting up PCI bus %pOF\n", dev->dev.of_node);
    44	
    45		/* Alloc and setup PHB data structure */
    46		phb = pcibios_alloc_controller(dev->dev.of_node);
    47		if (!phb)
    48			return -ENODEV;
    49	
    50		/* Setup parent in sysfs */
    51		phb->parent = &dev->dev;
    52	
    53		/* Setup the PHB using arch provided callback */
    54		if (ppc_md.pci_setup_phb(phb)) {
    55			pcibios_free_controller(phb);
    56			return -ENODEV;
    57		}
    58	
    59		/* Process "ranges" property */
    60		pci_process_bridge_OF_ranges(phb, dev->dev.of_node, 0);
    61	
    62		/* Init pci_dn data structures */
    63		pci_devs_phb_init_dynamic(phb);
    64	
    65		/* Create EEH PE for the PHB */
  > 66		eeh_phb_pe_create(phb);
    67	
    68		/* Scan the bus */
    69		pcibios_scan_phb(phb);
    70		if (phb->bus == NULL)
    71			return -ENXIO;
    72	
    73		/* Claim resources. This might need some rework as well depending
    74		 * whether we are doing probe-only or not, like assigning unassigned
    75		 * resources etc...
    76		 */
    77		pcibios_claim_one_bus(phb->bus);
    78	
    79		/* Add probed PCI devices to the device model */
    80		pci_bus_add_devices(phb->bus);
    81	
    82		return 0;
    83	}
    84	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

author reviewer
#3 lore raw

PATCH 2/14 powerpc/eeh: Remove eeh_dev.c

In reply to Oliver O'Halloran

The only thing in this file is eeh_dev_init() which is allocates and initialises an eeh_dev based on a pci_dn. This is only ever called from pci_dn.c so move it into there and remove the file.

---
 arch/powerpc/include/asm/eeh.h |  6 ----
 arch/powerpc/kernel/Makefile   |  2 +-
 arch/powerpc/kernel/eeh_dev.c  | 54 ----------------------------------
 arch/powerpc/kernel/pci_dn.c   | 20 +++++++++++++
 4 files changed, 21 insertions(+), 61 deletions(-)
 delete mode 100644 arch/powerpc/kernel/eeh_dev.c
arch/powerpc/include/asm/eeh.h +0 -6
index 646307481493..e22881a0c415 100644
@@ -293,7 +293,6 @@ void eeh_pe_restore_bars(struct eeh_pe *pe);
 const char *eeh_pe_loc_get(struct eeh_pe *pe);
 struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe);
 
-struct eeh_dev *eeh_dev_init(struct pci_dn *pdn);
 void eeh_show_enabled(void);
 int __init eeh_ops_register(struct eeh_ops *ops);
 int __exit eeh_ops_unregister(const char *name);
@@ -339,11 +338,6 @@ static inline bool eeh_enabled(void)
 
 static inline void eeh_show_enabled(void) { }
 
-static inline void *eeh_dev_init(struct pci_dn *pdn, void *data)
-{
-	return NULL;
-}
-
 static inline void eeh_dev_phb_init_dynamic(struct pci_controller *phb) { }
 
 static inline int eeh_check_failure(const volatile void __iomem *token)
arch/powerpc/kernel/Makefile +1 -1
index 244542ae2a91..c5211bdcf1b6 100644
@@ -71,7 +71,7 @@ obj-$(CONFIG_PPC_RTAS_DAEMON)	+= rtasd.o
 obj-$(CONFIG_RTAS_FLASH)	+= rtas_flash.o
 obj-$(CONFIG_RTAS_PROC)		+= rtas-proc.o
 obj-$(CONFIG_PPC_DT_CPU_FTRS)	+= dt_cpu_ftrs.o
-obj-$(CONFIG_EEH)              += eeh.o eeh_pe.o eeh_dev.o eeh_cache.o \
+obj-$(CONFIG_EEH)              += eeh.o eeh_pe.o eeh_cache.o \
 				  eeh_driver.o eeh_event.o eeh_sysfs.o
 obj-$(CONFIG_GENERIC_TBSYNC)	+= smp-tbsync.o
 obj-$(CONFIG_CRASH_DUMP)	+= crash_dump.o
arch/powerpc/kernel/eeh_dev.c deleted +0 -54

54 lines not on this page · raw message

arch/powerpc/kernel/pci_dn.c +20 -0
index 4e654df55969..f790a8d06f50 100644
@@ -124,6 +124,26 @@ struct pci_dn *pci_get_pdn(struct pci_dev *pdev)
 	return NULL;
 }
 
+#ifdef CONFIG_EEH
+static struct eeh_dev *eeh_dev_init(struct pci_dn *pdn)
+{
+	struct eeh_dev *edev;
+
+	/* Allocate EEH device */
+	edev = kzalloc(sizeof(*edev), GFP_KERNEL);
+	if (!edev)
+		return NULL;
+
+	/* Associate EEH device with OF node */
+	pdn->edev = edev;
+	edev->pdn = pdn;
+	edev->bdfn = (pdn->busno << 8) | pdn->devfn;
+	edev->controller = pdn->phb;
+
+	return edev;
+}
+#endif /* CONFIG_EEH */
+
 #ifdef CONFIG_PCI_IOV
 static struct pci_dn *add_one_sriov_vf_pdn(struct pci_dn *parent,
 					   int vf_index,
Signature · 1 line
2.26.2
author reviewer
#4 lore raw

PATCH 3/14 powerpc/eeh: Move vf_index out of pci_dn and into eeh_dev

In reply to Oliver O'Halloran

Drivers that do not support the PCI error handling callbacks are handled by tearing down the device and re-probing them. If the device to be removed is a virtual function we need to know the index of the index of the VF so that we can remove it with the pci_iov_{add|remove}_virtfn() API.

Currently this is handled by looking up the pci_dn, and using the vf_index that was stashed there when the pci_dn for the VF was created in pcibios_sriov_enable(). We would like to eliminate the use of pci_dn outside of pseries though so we need to provide the generic EEH code with some other way to find the vf_index.

The easiest thing to do here is move the vf_index field out of pci_dn and into eeh_dev. Currently pci_dn and eeh_dev are allocated and initialized together so this is a fairly minimal change in preparation for splitting pci_dn and eeh_dev in the future.

---
 arch/powerpc/include/asm/eeh.h        | 3 +++
 arch/powerpc/include/asm/pci-bridge.h | 1 -
 arch/powerpc/kernel/eeh_driver.c      | 6 ++----
 arch/powerpc/kernel/pci_dn.c          | 7 ++++---
 4 files changed, 9 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/eeh.h +3 -0
index e22881a0c415..3d648e042835 100644
@@ -148,7 +148,10 @@ struct eeh_dev {
 	struct pci_dn *pdn;		/* Associated PCI device node	*/
 	struct pci_dev *pdev;		/* Associated PCI device	*/
 	bool in_error;			/* Error flag for edev		*/
+
+	/* VF specific properties */
 	struct pci_dev *physfn;		/* Associated SRIOV PF		*/
+	int vf_index;			/* Index of this VF 		*/
 };
 
 /* "fmt" must be a simple literal string */
arch/powerpc/include/asm/pci-bridge.h +0 -1
index b92e81b256e5..d2a2a14e56f9 100644
@@ -202,7 +202,6 @@ struct pci_dn {
 #define IODA_INVALID_PE		0xFFFFFFFF
 	unsigned int pe_number;
 #ifdef CONFIG_PCI_IOV
-	int     vf_index;		/* VF index in the PF */
 	u16     vfs_expanded;		/* number of VFs IOV BAR expanded */
 	u16     num_vfs;		/* number of VFs enabled*/
 	unsigned int *pe_num_map;	/* PE# for the first VF PE or array */
arch/powerpc/kernel/eeh_driver.c +2 -4
index 7b048cee767c..b70b9273f45a 100644
@@ -477,7 +477,7 @@ static void *eeh_add_virt_device(struct eeh_dev *edev)
 	}
 
 #ifdef CONFIG_PCI_IOV
-	pci_iov_add_virtfn(edev->physfn, eeh_dev_to_pdn(edev)->vf_index);
+	pci_iov_add_virtfn(edev->physfn, edev->vf_index);
 #endif
 	return NULL;
 }
@@ -521,9 +521,7 @@ static void eeh_rmv_device(struct eeh_dev *edev, void *userdata)
 
 	if (edev->physfn) {
 #ifdef CONFIG_PCI_IOV
-		struct pci_dn *pdn = eeh_dev_to_pdn(edev);
-
-		pci_iov_remove_virtfn(edev->physfn, pdn->vf_index);
+		pci_iov_remove_virtfn(edev->physfn, edev->vf_index);
 		edev->pdev = NULL;
 #endif
 		if (rmv_data)
arch/powerpc/kernel/pci_dn.c +4 -3
index f790a8d06f50..bf11ac8427ac 100644
@@ -146,7 +146,6 @@ static struct eeh_dev *eeh_dev_init(struct pci_dn *pdn)
 
 #ifdef CONFIG_PCI_IOV
 static struct pci_dn *add_one_sriov_vf_pdn(struct pci_dn *parent,
-					   int vf_index,
 					   int busno, int devfn)
 {
 	struct pci_dn *pdn;
@@ -163,7 +162,6 @@ static struct pci_dn *add_one_sriov_vf_pdn(struct pci_dn *parent,
 	pdn->parent = parent;
 	pdn->busno = busno;
 	pdn->devfn = devfn;
-	pdn->vf_index = vf_index;
 	pdn->pe_number = IODA_INVALID_PE;
 	INIT_LIST_HEAD(&pdn->child_list);
 	INIT_LIST_HEAD(&pdn->list);
@@ -194,7 +192,7 @@ struct pci_dn *add_sriov_vf_pdns(struct pci_dev *pdev)
 	for (i = 0; i < pci_sriov_get_totalvfs(pdev); i++) {
 		struct eeh_dev *edev __maybe_unused;
 
-		pdn = add_one_sriov_vf_pdn(parent, i,
+		pdn = add_one_sriov_vf_pdn(parent,
 					   pci_iov_virtfn_bus(pdev, i),
 					   pci_iov_virtfn_devfn(pdev, i));
 		if (!pdn) {
@@ -207,7 +205,10 @@ struct pci_dn *add_sriov_vf_pdns(struct pci_dev *pdev)
 		/* Create the EEH device for the VF */
 		edev = eeh_dev_init(pdn);
 		BUG_ON(!edev);
+
+		/* FIXME: these should probably be populated by the EEH probe */
 		edev->physfn = pdev;
+		edev->vf_index = i;
 #endif /* CONFIG_EEH */
 	}
 	return pci_get_pdn(pdev);
Signature · 1 line
2.26.2
Reviewed-by on v1 3/14
#5 lore raw

Re: [PATCH 03/14] powerpc/eeh: Move vf_index out of pci_dn and into eeh_dev

Quoted 3 lines · Oliver O'Halloran

Drivers that do not support the PCI error handling callbacks are handled by tearing down the device and re-probing them. If the device to be removed is a virtual function we need to know the index of the index of the VF so that

Too many indexes in "the index of the index of "?

Quoted 8 lines

we can remove it with the pci_iov_{add|remove}_virtfn() API.

Currently this is handled by looking up the pci_dn, and using the vf_index that was stashed there when the pci_dn for the VF was created in pcibios_sriov_enable(). We would like to eliminate the use of pci_dn outside of pseries though so we need to provide the generic EEH code with some other way to find the vf_index.

Quoted 6 lines

The easiest thing to do here is move the vf_index field out of pci_dn and into eeh_dev. Currently pci_dn and eeh_dev are allocated and initialized together so this is a fairly minimal change in preparation for splitting pci_dn and eeh_dev in the future.

Quoted 99 lines
---
 arch/powerpc/include/asm/eeh.h        | 3 +++
 arch/powerpc/include/asm/pci-bridge.h | 1 -
 arch/powerpc/kernel/eeh_driver.c      | 6 ++----
 arch/powerpc/kernel/pci_dn.c          | 7 ++++---
 4 files changed, 9 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/eeh.h +3 -0
index e22881a0c415..3d648e042835 100644
@@ -148,7 +148,10 @@ struct eeh_dev {
 	struct pci_dn *pdn;		/* Associated PCI device node	*/
 	struct pci_dev *pdev;		/* Associated PCI device	*/
 	bool in_error;			/* Error flag for edev		*/
+
+	/* VF specific properties */
 	struct pci_dev *physfn;		/* Associated SRIOV PF		*/
+	int vf_index;			/* Index of this VF 		*/
 };
 
 /* "fmt" must be a simple literal string */
arch/powerpc/include/asm/pci-bridge.h +0 -1
index b92e81b256e5..d2a2a14e56f9 100644
@@ -202,7 +202,6 @@ struct pci_dn {
 #define IODA_INVALID_PE		0xFFFFFFFF
 	unsigned int pe_number;
 #ifdef CONFIG_PCI_IOV
-	int     vf_index;		/* VF index in the PF */
 	u16     vfs_expanded;		/* number of VFs IOV BAR expanded */
 	u16     num_vfs;		/* number of VFs enabled*/
 	unsigned int *pe_num_map;	/* PE# for the first VF PE or array */
arch/powerpc/kernel/eeh_driver.c +2 -4
index 7b048cee767c..b70b9273f45a 100644
@@ -477,7 +477,7 @@ static void *eeh_add_virt_device(struct eeh_dev *edev)
 	}
 
 #ifdef CONFIG_PCI_IOV
-	pci_iov_add_virtfn(edev->physfn, eeh_dev_to_pdn(edev)->vf_index);
+	pci_iov_add_virtfn(edev->physfn, edev->vf_index);
 #endif
 	return NULL;
 }
@@ -521,9 +521,7 @@ static void eeh_rmv_device(struct eeh_dev *edev, void *userdata)
 
 	if (edev->physfn) {
 #ifdef CONFIG_PCI_IOV
-		struct pci_dn *pdn = eeh_dev_to_pdn(edev);
-
-		pci_iov_remove_virtfn(edev->physfn, pdn->vf_index);
+		pci_iov_remove_virtfn(edev->physfn, edev->vf_index);
 		edev->pdev = NULL;
 #endif
 		if (rmv_data)
arch/powerpc/kernel/pci_dn.c +4 -3
index f790a8d06f50..bf11ac8427ac 100644
@@ -146,7 +146,6 @@ static struct eeh_dev *eeh_dev_init(struct pci_dn *pdn)
 
 #ifdef CONFIG_PCI_IOV
 static struct pci_dn *add_one_sriov_vf_pdn(struct pci_dn *parent,
-					   int vf_index,
 					   int busno, int devfn)
 {
 	struct pci_dn *pdn;
@@ -163,7 +162,6 @@ static struct pci_dn *add_one_sriov_vf_pdn(struct pci_dn *parent,
 	pdn->parent = parent;
 	pdn->busno = busno;
 	pdn->devfn = devfn;
-	pdn->vf_index = vf_index;
 	pdn->pe_number = IODA_INVALID_PE;
 	INIT_LIST_HEAD(&pdn->child_list);
 	INIT_LIST_HEAD(&pdn->list);
@@ -194,7 +192,7 @@ struct pci_dn *add_sriov_vf_pdns(struct pci_dev *pdev)
 	for (i = 0; i < pci_sriov_get_totalvfs(pdev); i++) {
 		struct eeh_dev *edev __maybe_unused;
 
-		pdn = add_one_sriov_vf_pdn(parent, i,
+		pdn = add_one_sriov_vf_pdn(parent,
 					   pci_iov_virtfn_bus(pdev, i),
 					   pci_iov_virtfn_devfn(pdev, i));
 		if (!pdn) {
@@ -207,7 +205,10 @@ struct pci_dn *add_sriov_vf_pdns(struct pci_dev *pdev)
 		/* Create the EEH device for the VF */
 		edev = eeh_dev_init(pdn);
 		BUG_ON(!edev);
+
+		/* FIXME: these should probably be populated by the EEH probe */
 		edev->physfn = pdev;
+		edev->vf_index = i;
 #endif /* CONFIG_EEH */
 	}
 	return pci_get_pdn(pdev);
Signature · 1 line
Alexey
author reviewer
#6 lore raw

Re: [PATCH 03/14] powerpc/eeh: Move vf_index out of pci_dn and into eeh_dev

Quoted 9 lines · Alexey Kardashevskiy
Quoted 3 lines · Oliver O'Halloran

Drivers that do not support the PCI error handling callbacks are handled by tearing down the device and re-probing them. If the device to be removed is a virtual function we need to know the index of the index of the VF so that

Too many indexes in "the index of the index of "?

I'll index you!

(yes)

author reviewer
#7 lore raw

PATCH 4/14 powerpc/pseries: Stop using pdn->pe_number

In reply to Oliver O'Halloran

The pci_dn->pe_number field is mainly used to track the IODA PE number of a device on PowerNV. At some point it grew a user in the pseries SR-IOV support which muddies the waters a bit, so remove it.

---
 arch/powerpc/platforms/pseries/eeh_pseries.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
arch/powerpc/platforms/pseries/eeh_pseries.c +4 -6
index ace117f99d94..18a2522b9b5e 100644
@@ -52,8 +52,6 @@ void pseries_pcibios_bus_add_device(struct pci_dev *pdev)
 	dev_dbg(&pdev->dev, "EEH: Setting up device\n");
 #ifdef CONFIG_PCI_IOV
 	if (pdev->is_virtfn) {
-		struct pci_dn *physfn_pdn;
-
 		pdn->device_id  =  pdev->device;
 		pdn->vendor_id  =  pdev->vendor;
 		pdn->class_code =  pdev->class;
@@ -63,8 +61,6 @@ void pseries_pcibios_bus_add_device(struct pci_dev *pdev)
 		 * completion from platform.
 		 */
 		pdn->last_allow_rc =  0;
-		physfn_pdn      =  pci_get_pdn(pdev->physfn);
-		pdn->pe_number  =  physfn_pdn->pe_num_map[pdn->vf_index];
 	}
 #endif
 	pseries_eeh_init_edev(pdn);
@@ -772,8 +768,8 @@ int pseries_send_allow_unfreeze(struct pci_dn *pdn,
 
 static int pseries_call_allow_unfreeze(struct eeh_dev *edev)
 {
+	int cur_vfs = 0, rc = 0, vf_index, bus, devfn, vf_pe_num;
 	struct pci_dn *pdn, *tmp, *parent, *physfn_pdn;
-	int cur_vfs = 0, rc = 0, vf_index, bus, devfn;
 	u16 *vf_pe_array;
 
 	vf_pe_array = kzalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL);
@@ -806,8 +802,10 @@ static int pseries_call_allow_unfreeze(struct eeh_dev *edev)
 			}
 		} else {
 			pdn = pci_get_pdn(edev->pdev);
-			vf_pe_array[0] = cpu_to_be16(pdn->pe_number);
 			physfn_pdn = pci_get_pdn(edev->physfn);
+
+			vf_pe_num = physfn_pdn->pe_num_map[edev->vf_index];
+			vf_pe_array[0] = cpu_to_be16(vf_pe_num);
 			rc = pseries_send_allow_unfreeze(physfn_pdn,
 							 vf_pe_array, 1);
 			pdn->last_allow_rc = rc;
Signature · 1 line
2.26.2
Reviewed-by on v1 4/14
#8 lore raw

Re: [PATCH 04/14] powerpc/pseries: Stop using pdn->pe_number

Quoted 5 lines · Oliver O'Halloran

The pci_dn->pe_number field is mainly used to track the IODA PE number of a device on PowerNV. At some point it grew a user in the pseries SR-IOV support which muddies the waters a bit, so remove it.

Quoted 49 lines
---
 arch/powerpc/platforms/pseries/eeh_pseries.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
arch/powerpc/platforms/pseries/eeh_pseries.c +4 -6
index ace117f99d94..18a2522b9b5e 100644
@@ -52,8 +52,6 @@ void pseries_pcibios_bus_add_device(struct pci_dev *pdev)
 	dev_dbg(&pdev->dev, "EEH: Setting up device\n");
 #ifdef CONFIG_PCI_IOV
 	if (pdev->is_virtfn) {
-		struct pci_dn *physfn_pdn;
-
 		pdn->device_id  =  pdev->device;
 		pdn->vendor_id  =  pdev->vendor;
 		pdn->class_code =  pdev->class;
@@ -63,8 +61,6 @@ void pseries_pcibios_bus_add_device(struct pci_dev *pdev)
 		 * completion from platform.
 		 */
 		pdn->last_allow_rc =  0;
-		physfn_pdn      =  pci_get_pdn(pdev->physfn);
-		pdn->pe_number  =  physfn_pdn->pe_num_map[pdn->vf_index];
 	}
 #endif
 	pseries_eeh_init_edev(pdn);
@@ -772,8 +768,8 @@ int pseries_send_allow_unfreeze(struct pci_dn *pdn,
 
 static int pseries_call_allow_unfreeze(struct eeh_dev *edev)
 {
+	int cur_vfs = 0, rc = 0, vf_index, bus, devfn, vf_pe_num;
 	struct pci_dn *pdn, *tmp, *parent, *physfn_pdn;
-	int cur_vfs = 0, rc = 0, vf_index, bus, devfn;
 	u16 *vf_pe_array;
 
 	vf_pe_array = kzalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL);
@@ -806,8 +802,10 @@ static int pseries_call_allow_unfreeze(struct eeh_dev *edev)
 			}
 		} else {
 			pdn = pci_get_pdn(edev->pdev);
-			vf_pe_array[0] = cpu_to_be16(pdn->pe_number);
 			physfn_pdn = pci_get_pdn(edev->physfn);
+
+			vf_pe_num = physfn_pdn->pe_num_map[edev->vf_index];
+			vf_pe_array[0] = cpu_to_be16(vf_pe_num);
 			rc = pseries_send_allow_unfreeze(physfn_pdn,
 							 vf_pe_array, 1);
 			pdn->last_allow_rc = rc;
Signature · 1 line
Alexey
author reviewer
#9 lore raw

PATCH 5/14 powerpc/eeh: Kill off eeh_ops->get_pe_addr()

In reply to Oliver O'Halloran

This is used in precisely one place which is in pseries specific platform code. There's no need to have the callback in eeh_ops since the platform chooses the EEH PE addresses anyway. The PowerNV implementation has always been a stub too so remove it.

---
 arch/powerpc/include/asm/eeh.h               |  1 -
 arch/powerpc/platforms/powernv/eeh-powernv.c | 13 ------------
 arch/powerpc/platforms/pseries/eeh_pseries.c | 22 ++++++++++----------
 3 files changed, 11 insertions(+), 25 deletions(-)
arch/powerpc/include/asm/eeh.h +0 -1
index 3d648e042835..1bddc0dfe099 100644
@@ -220,7 +220,6 @@ struct eeh_ops {
 	int (*init)(void);
 	struct eeh_dev *(*probe)(struct pci_dev *pdev);
 	int (*set_option)(struct eeh_pe *pe, int option);
-	int (*get_pe_addr)(struct eeh_pe *pe);
 	int (*get_state)(struct eeh_pe *pe, int *delay);
 	int (*reset)(struct eeh_pe *pe, int option);
 	int (*get_log)(struct eeh_pe *pe, int severity, char *drv_log, unsigned long len);
arch/powerpc/platforms/powernv/eeh-powernv.c +0 -13
index 79409e005fcd..bcd0515d8f79 100644
@@ -535,18 +535,6 @@ static int pnv_eeh_set_option(struct eeh_pe *pe, int option)
 	return 0;
 }
 
-/**
- * pnv_eeh_get_pe_addr - Retrieve PE address
- * @pe: EEH PE
- *
- * Retrieve the PE address according to the given tranditional
- * PCI BDF (Bus/Device/Function) address.
- */
-static int pnv_eeh_get_pe_addr(struct eeh_pe *pe)
-{
-	return pe->addr;
-}
-
 static void pnv_eeh_get_phb_diag(struct eeh_pe *pe)
 {
 	struct pnv_phb *phb = pe->phb->private_data;
@@ -1670,7 +1658,6 @@ static struct eeh_ops pnv_eeh_ops = {
 	.init                   = pnv_eeh_init,
 	.probe			= pnv_eeh_probe,
 	.set_option             = pnv_eeh_set_option,
-	.get_pe_addr            = pnv_eeh_get_pe_addr,
 	.get_state              = pnv_eeh_get_state,
 	.reset                  = pnv_eeh_reset,
 	.get_log                = pnv_eeh_get_log,
arch/powerpc/platforms/pseries/eeh_pseries.c +11 -11
index 18a2522b9b5e..088771fa38be 100644
@@ -32,6 +32,8 @@
 #include <asm/ppc-pci.h>
 #include <asm/rtas.h>
 
+static int pseries_eeh_get_pe_addr(struct pci_dn *pdn);
+
 /* RTAS tokens */
 static int ibm_set_eeh_option;
 static int ibm_set_slot_reset;
@@ -301,7 +303,7 @@ void pseries_eeh_init_edev(struct pci_dn *pdn)
 		eeh_edev_dbg(edev, "EEH failed to enable on device (code %d)\n", ret);
 	} else {
 		/* Retrieve PE address */
-		edev->pe_config_addr = eeh_ops->get_pe_addr(&pe);
+		edev->pe_config_addr = pseries_eeh_get_pe_addr(pdn);
 		pe.addr = edev->pe_config_addr;
 
 		/* Some older systems (Power4) allow the ibm,set-eeh-option
@@ -431,8 +433,10 @@ static int pseries_eeh_set_option(struct eeh_pe *pe, int option)
  * It's notable that zero'ed return value means invalid PE config
  * address.
  */
-static int pseries_eeh_get_pe_addr(struct eeh_pe *pe)
+static int pseries_eeh_get_pe_addr(struct pci_dn *pdn)
 {
+	int config_addr = rtas_config_addr(pdn->busno, pdn->devfn, 0);
+	int buid = pdn->phb->buid;
 	int ret = 0;
 	int rets[3];
 
@@ -443,18 +447,16 @@ static int pseries_eeh_get_pe_addr(struct eeh_pe *pe)
 		 * meaningless.
 		 */
 		ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
-				pe->config_addr, BUID_HI(pe->phb->buid),
-				BUID_LO(pe->phb->buid), 1);
+				config_addr, BUID_HI(buid), BUID_LO(buid), 1);
 		if (ret || (rets[0] == 0))
 			return 0;
 
 		/* Retrieve the associated PE config address */
 		ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
-				pe->config_addr, BUID_HI(pe->phb->buid),
-				BUID_LO(pe->phb->buid), 0);
+				config_addr, BUID_HI(buid), BUID_LO(buid), 0);
 		if (ret) {
 			pr_warn("%s: Failed to get address for PHB#%x-PE#%x\n",
-				__func__, pe->phb->global_number, pe->config_addr);
+				__func__, pdn->phb->global_number, config_addr);
 			return 0;
 		}
 
@@ -463,11 +465,10 @@ static int pseries_eeh_get_pe_addr(struct eeh_pe *pe)
 
 	if (ibm_get_config_addr_info != RTAS_UNKNOWN_SERVICE) {
 		ret = rtas_call(ibm_get_config_addr_info, 4, 2, rets,
-				pe->config_addr, BUID_HI(pe->phb->buid),
-				BUID_LO(pe->phb->buid), 0);
+				config_addr, BUID_HI(buid), BUID_LO(buid), 0);
 		if (ret) {
 			pr_warn("%s: Failed to get address for PHB#%x-PE#%x\n",
-				__func__, pe->phb->global_number, pe->config_addr);
+				__func__, pdn->phb->global_number, config_addr);
 			return 0;
 		}
 
@@ -839,7 +840,6 @@ static struct eeh_ops pseries_eeh_ops = {
 	.init			= pseries_eeh_init,
 	.probe			= pseries_eeh_probe,
 	.set_option		= pseries_eeh_set_option,
-	.get_pe_addr		= pseries_eeh_get_pe_addr,
 	.get_state		= pseries_eeh_get_state,
 	.reset			= pseries_eeh_reset,
 	.get_log		= pseries_eeh_get_log,
Signature · 1 line
2.26.2
Reviewed-by on v1 5/14
#10 lore raw

Re: [PATCH 05/14] powerpc/eeh: Kill off eeh_ops->get_pe_addr()

Quoted 78 lines · Oliver O'Halloran

This is used in precisely one place which is in pseries specific platform code. There's no need to have the callback in eeh_ops since the platform chooses the EEH PE addresses anyway. The PowerNV implementation has always been a stub too so remove it.

---
 arch/powerpc/include/asm/eeh.h               |  1 -
 arch/powerpc/platforms/powernv/eeh-powernv.c | 13 ------------
 arch/powerpc/platforms/pseries/eeh_pseries.c | 22 ++++++++++----------
 3 files changed, 11 insertions(+), 25 deletions(-)
arch/powerpc/include/asm/eeh.h +0 -1
index 3d648e042835..1bddc0dfe099 100644
@@ -220,7 +220,6 @@ struct eeh_ops {
 	int (*init)(void);
 	struct eeh_dev *(*probe)(struct pci_dev *pdev);
 	int (*set_option)(struct eeh_pe *pe, int option);
-	int (*get_pe_addr)(struct eeh_pe *pe);
 	int (*get_state)(struct eeh_pe *pe, int *delay);
 	int (*reset)(struct eeh_pe *pe, int option);
 	int (*get_log)(struct eeh_pe *pe, int severity, char *drv_log, unsigned long len);
arch/powerpc/platforms/powernv/eeh-powernv.c +0 -13
index 79409e005fcd..bcd0515d8f79 100644
@@ -535,18 +535,6 @@ static int pnv_eeh_set_option(struct eeh_pe *pe, int option)
 	return 0;
 }
 
-/**
- * pnv_eeh_get_pe_addr - Retrieve PE address
- * @pe: EEH PE
- *
- * Retrieve the PE address according to the given tranditional
- * PCI BDF (Bus/Device/Function) address.
- */
-static int pnv_eeh_get_pe_addr(struct eeh_pe *pe)
-{
-	return pe->addr;
-}
-
 static void pnv_eeh_get_phb_diag(struct eeh_pe *pe)
 {
 	struct pnv_phb *phb = pe->phb->private_data;
@@ -1670,7 +1658,6 @@ static struct eeh_ops pnv_eeh_ops = {
 	.init                   = pnv_eeh_init,
 	.probe			= pnv_eeh_probe,
 	.set_option             = pnv_eeh_set_option,
-	.get_pe_addr            = pnv_eeh_get_pe_addr,
 	.get_state              = pnv_eeh_get_state,
 	.reset                  = pnv_eeh_reset,
 	.get_log                = pnv_eeh_get_log,
arch/powerpc/platforms/pseries/eeh_pseries.c +3 -1
index 18a2522b9b5e..088771fa38be 100644
@@ -32,6 +32,8 @@
 #include <asm/ppc-pci.h>
 #include <asm/rtas.h>
 
+static int pseries_eeh_get_pe_addr(struct pci_dn *pdn);
+
 /* RTAS tokens */
 static int ibm_set_eeh_option;
 static int ibm_set_slot_reset;
@@ -301,7 +303,7 @@ void pseries_eeh_init_edev(struct pci_dn *pdn)
 		eeh_edev_dbg(edev, "EEH failed to enable on device (code %d)\n", ret);
 	} else {
 		/* Retrieve PE address */
-		edev->pe_config_addr = eeh_ops->get_pe_addr(&pe);
+		edev->pe_config_addr = pseries_eeh_get_pe_addr(pdn);
 		pe.addr = edev->pe_config_addr;
 
 		/* Some older systems (Power4) allow the ibm,set-eeh-option

arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_eeh_set_option(struct eeh_pe *pe, int option) · line 438

Quoted 7 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +2 -1
@@ -431,8 +433,10 @@ static int pseries_eeh_set_option(struct eeh_pe *pe, int option)
  * It's notable that zero'ed return value means invalid PE config
  * address.
  */
-static int pseries_eeh_get_pe_addr(struct eeh_pe *pe)
+static int pseries_eeh_get_pe_addr(struct pci_dn *pdn)
 {
+	int config_addr = rtas_config_addr(pdn->busno, pdn->devfn, 0);

Why not use pe->config_addr (and why we have two addresses in eeh_pe anyway)?

Ah, I guess I just trust you with this one :)

Quoted 49 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +6 -9
+	int buid = pdn->phb->buid;
 	int ret = 0;
 	int rets[3];
 
@@ -443,18 +447,16 @@ static int pseries_eeh_get_pe_addr(struct eeh_pe *pe)
 		 * meaningless.
 		 */
 		ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
-				pe->config_addr, BUID_HI(pe->phb->buid),
-				BUID_LO(pe->phb->buid), 1);
+				config_addr, BUID_HI(buid), BUID_LO(buid), 1);
 		if (ret || (rets[0] == 0))
 			return 0;
 
 		/* Retrieve the associated PE config address */
 		ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
-				pe->config_addr, BUID_HI(pe->phb->buid),
-				BUID_LO(pe->phb->buid), 0);
+				config_addr, BUID_HI(buid), BUID_LO(buid), 0);
 		if (ret) {
 			pr_warn("%s: Failed to get address for PHB#%x-PE#%x\n",
-				__func__, pe->phb->global_number, pe->config_addr);
+				__func__, pdn->phb->global_number, config_addr);
 			return 0;
 		}
 
@@ -463,11 +465,10 @@ static int pseries_eeh_get_pe_addr(struct eeh_pe *pe)
 
 	if (ibm_get_config_addr_info != RTAS_UNKNOWN_SERVICE) {
 		ret = rtas_call(ibm_get_config_addr_info, 4, 2, rets,
-				pe->config_addr, BUID_HI(pe->phb->buid),
-				BUID_LO(pe->phb->buid), 0);
+				config_addr, BUID_HI(buid), BUID_LO(buid), 0);
 		if (ret) {
 			pr_warn("%s: Failed to get address for PHB#%x-PE#%x\n",
-				__func__, pe->phb->global_number, pe->config_addr);
+				__func__, pdn->phb->global_number, config_addr);
 			return 0;
 		}
 
@@ -839,7 +840,6 @@ static struct eeh_ops pseries_eeh_ops = {
 	.init			= pseries_eeh_init,
 	.probe			= pseries_eeh_probe,
 	.set_option		= pseries_eeh_set_option,
-	.get_pe_addr		= pseries_eeh_get_pe_addr,
 	.get_state		= pseries_eeh_get_state,
 	.reset			= pseries_eeh_reset,
 	.get_log		= pseries_eeh_get_log,
Signature · 1 line
Alexey
author reviewer
#11 lore raw

Re: [PATCH 05/14] powerpc/eeh: Kill off eeh_ops->get_pe_addr()

Quoted 80 lines · Alexey Kardashevskiy
Quoted 76 lines · Oliver O'Halloran

This is used in precisely one place which is in pseries specific platform code. There's no need to have the callback in eeh_ops since the platform chooses the EEH PE addresses anyway. The PowerNV implementation has always been a stub too so remove it.

---
 arch/powerpc/include/asm/eeh.h               |  1 -
 arch/powerpc/platforms/powernv/eeh-powernv.c | 13 ------------
 arch/powerpc/platforms/pseries/eeh_pseries.c | 22 ++++++++++----------
 3 files changed, 11 insertions(+), 25 deletions(-)
arch/powerpc/include/asm/eeh.h +0 -1
index 3d648e042835..1bddc0dfe099 100644
@@ -220,7 +220,6 @@ struct eeh_ops {
      int (*init)(void);
      struct eeh_dev *(*probe)(struct pci_dev *pdev);
      int (*set_option)(struct eeh_pe *pe, int option);
-     int (*get_pe_addr)(struct eeh_pe *pe);
      int (*get_state)(struct eeh_pe *pe, int *delay);
      int (*reset)(struct eeh_pe *pe, int option);
      int (*get_log)(struct eeh_pe *pe, int severity, char *drv_log, unsigned long len);
arch/powerpc/platforms/powernv/eeh-powernv.c +0 -13
index 79409e005fcd..bcd0515d8f79 100644
@@ -535,18 +535,6 @@ static int pnv_eeh_set_option(struct eeh_pe *pe, int option)
      return 0;
 }
 
-/**
- * pnv_eeh_get_pe_addr - Retrieve PE address
- * @pe: EEH PE
- *
- * Retrieve the PE address according to the given tranditional
- * PCI BDF (Bus/Device/Function) address.
- */
-static int pnv_eeh_get_pe_addr(struct eeh_pe *pe)
-{
-     return pe->addr;
-}
-
 static void pnv_eeh_get_phb_diag(struct eeh_pe *pe)
 {
      struct pnv_phb *phb = pe->phb->private_data;
@@ -1670,7 +1658,6 @@ static struct eeh_ops pnv_eeh_ops = {
      .init                   = pnv_eeh_init,
      .probe                  = pnv_eeh_probe,
      .set_option             = pnv_eeh_set_option,
-     .get_pe_addr            = pnv_eeh_get_pe_addr,
      .get_state              = pnv_eeh_get_state,
      .reset                  = pnv_eeh_reset,
      .get_log                = pnv_eeh_get_log,
arch/powerpc/platforms/pseries/eeh_pseries.c +3 -1
index 18a2522b9b5e..088771fa38be 100644
@@ -32,6 +32,8 @@
 #include <asm/ppc-pci.h>
 #include <asm/rtas.h>
 
+static int pseries_eeh_get_pe_addr(struct pci_dn *pdn);
+
 /* RTAS tokens */
 static int ibm_set_eeh_option;
 static int ibm_set_slot_reset;
@@ -301,7 +303,7 @@ void pseries_eeh_init_edev(struct pci_dn *pdn)
              eeh_edev_dbg(edev, "EEH failed to enable on device (code %d)\n", ret);
      } else {
              /* Retrieve PE address */
-             edev->pe_config_addr = eeh_ops->get_pe_addr(&pe);
+             edev->pe_config_addr = pseries_eeh_get_pe_addr(pdn);
              pe.addr = edev->pe_config_addr;
 
Quoted 11 lines

arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_eeh_set_option(struct eeh_pe *pe, int option) · line 438

Quoted 9 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +2 -1
              /* Some older systems (Power4) allow the ibm,set-eeh-option
@@ -431,8 +433,10 @@ static int pseries_eeh_set_option(struct eeh_pe *pe, int option)
  * It's notable that zero'ed return value means invalid PE config
  * address.
  */
-static int pseries_eeh_get_pe_addr(struct eeh_pe *pe)
+static int pseries_eeh_get_pe_addr(struct pci_dn *pdn)
 {
+     int config_addr = rtas_config_addr(pdn->busno, pdn->devfn, 0);

Why not use pe->config_addr

I wanted to get rid of the PE argument. The only caller (pseries_eeh_init_edev()) doesn't even pass a real PE, just the "fake" PE which only has one initialised field which is... sketch IMO. The other reason is for Wen's post-kdump pseries PHB reset patch. In that situation we want the reset to be done before we've done any PCI setup so there won't be any eeh_pe structures available. We will however have pci_dn's since they're set up before we start scanning PHBs. I also think some of the "fake pe" stuff in pseries_eeh_init_edev() is broken so the fewer users of that we have the better.

Quoted 1 line

(and why we have two addresses in eeh_pe anyway)?

I don't know :(

It's one of those things I've been meaning to look at but haven't found the will to jump down that particular rabbit hole.

I did take a cursory look and there's some comments about pe->addr being zero in some cases so EEH falls back to matching on pe->config_addr when searching for a PE. IIRC when I looked I couldn't work out why pe->config_addr would ever be zero. On PowerNV zero is a valid PE address and we set the EEH_VALID_PE_ZERO flag to disable that fallback logic so the reason is probably some weird pseries thing.

Quoted 60 lines

Ah, I guess I just trust you with this one :)

Quoted 42 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +6 -8
+     int buid = pdn->phb->buid;
      int ret = 0;
      int rets[3];
 
@@ -443,18 +447,16 @@ static int pseries_eeh_get_pe_addr(struct eeh_pe *pe)
               * meaningless.
               */
              ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
-                             pe->config_addr, BUID_HI(pe->phb->buid),
-                             BUID_LO(pe->phb->buid), 1);
+                             config_addr, BUID_HI(buid), BUID_LO(buid), 1);
              if (ret || (rets[0] == 0))
                      return 0;
 
              /* Retrieve the associated PE config address */
              ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
-                             pe->config_addr, BUID_HI(pe->phb->buid),
-                             BUID_LO(pe->phb->buid), 0);
+                             config_addr, BUID_HI(buid), BUID_LO(buid), 0);
              if (ret) {
                      pr_warn("%s: Failed to get address for PHB#%x-PE#%x\n",
-                             __func__, pe->phb->global_number, pe->config_addr);
+                             __func__, pdn->phb->global_number, config_addr);
                      return 0;
              }
 
@@ -463,11 +465,10 @@ static int pseries_eeh_get_pe_addr(struct eeh_pe *pe)
 
      if (ibm_get_config_addr_info != RTAS_UNKNOWN_SERVICE) {
              ret = rtas_call(ibm_get_config_addr_info, 4, 2, rets,
-                             pe->config_addr, BUID_HI(pe->phb->buid),
-                             BUID_LO(pe->phb->buid), 0);
+                             config_addr, BUID_HI(buid), BUID_LO(buid), 0);
              if (ret) {
                      pr_warn("%s: Failed to get address for PHB#%x-PE#%x\n",
-                             __func__, pe->phb->global_number, pe->config_addr);
+                             __func__, pdn->phb->global_number, config_addr);
                      return 0;
              }
 

arch/powerpc/platforms/pseries/eeh_pseries.c static struct eeh_ops pseries_eeh_ops = { · line 845

Quoted 7 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +0 -1
@@ -839,7 +840,6 @@ static struct eeh_ops pseries_eeh_ops = {
      .init                   = pseries_eeh_init,
      .probe                  = pseries_eeh_probe,
      .set_option             = pseries_eeh_set_option,
-     .get_pe_addr            = pseries_eeh_get_pe_addr,
      .get_state              = pseries_eeh_get_state,
      .reset                  = pseries_eeh_reset,
      .get_log                = pseries_eeh_get_log,

--
Alexey

author reviewer
#12 lore raw

PATCH 6/14 powerpc/eeh: Remove VF config space restoration

In reply to Oliver O'Halloran

There's a bunch of strange things about this code. First up is that none of the fields being written to are functional for a VF. The SR-IOV specification lists then as "Reserved, but OS should preserve" so writing new values to them doesn't do anything and is clearly wrong from a correctness perspective.

However, since VFs are designed to be managed by the OS there is an argument to be made that we should be saving and restoring some parts of config space. We already sort of do that by saving the first 64 bytes of config space in the eeh_dev (see eeh_dev->config_space[]). This is inadequate since it doesn't even consider saving and restoring the PCI capability structures. However, this is a problem with EEH in general and that needs to be fixed for non-VF devices too.

There's no real reason to keep around this around so delete it.

---
 arch/powerpc/include/asm/eeh.h               |  1 -
 arch/powerpc/kernel/eeh.c                    | 59 --------------------
 arch/powerpc/platforms/powernv/eeh-powernv.c | 20 ++-----
 arch/powerpc/platforms/pseries/eeh_pseries.c | 26 +--------
 4 files changed, 7 insertions(+), 99 deletions(-)
arch/powerpc/include/asm/eeh.h +0 -1
index 1bddc0dfe099..046c5a2fe411 100644
@@ -314,7 +314,6 @@ int eeh_pe_reset(struct eeh_pe *pe, int option, bool include_passed);
 int eeh_pe_configure(struct eeh_pe *pe);
 int eeh_pe_inject_err(struct eeh_pe *pe, int type, int func,
 		      unsigned long addr, unsigned long mask);
-int eeh_restore_vf_config(struct pci_dn *pdn);
 
 /**
  * EEH_POSSIBLE_ERROR() -- test for possible MMIO failure.
arch/powerpc/kernel/eeh.c +0 -59

65 lines not on this page · raw message

arch/powerpc/platforms/powernv/eeh-powernv.c +6 -14
index bcd0515d8f79..8f3a7611efc1 100644
@@ -1629,20 +1629,12 @@ static int pnv_eeh_restore_config(struct pci_dn *pdn)
 	if (!edev)
 		return -EEXIST;
 
-	/*
-	 * We have to restore the PCI config space after reset since the
-	 * firmware can't see SRIOV VFs.
-	 *
-	 * FIXME: The MPS, error routing rules, timeout setting are worthy
-	 * to be exported by firmware in extendible way.
-	 */
-	if (edev->physfn) {
-		ret = eeh_restore_vf_config(pdn);
-	} else {
-		phb = pdn->phb->private_data;
-		ret = opal_pci_reinit(phb->opal_id,
-				      OPAL_REINIT_PCI_DEV, config_addr);
-	}
+	if (edev->physfn)
+		return 0;
+
+	phb = edev->controller->private_data;
+	ret = opal_pci_reinit(phb->opal_id,
+			      OPAL_REINIT_PCI_DEV, edev->bdfn);
 
 	if (ret) {
 		pr_warn("%s: Can't reinit PCI dev 0x%x (%lld)\n",
arch/powerpc/platforms/pseries/eeh_pseries.c +1 -25
index 088771fa38be..83122bf65a8c 100644
@@ -718,30 +718,6 @@ static int pseries_eeh_write_config(struct pci_dn *pdn, int where, int size, u32
 	return rtas_write_config(pdn, where, size, val);
 }
 
-static int pseries_eeh_restore_config(struct pci_dn *pdn)
-{
-	struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
-	s64 ret = 0;
-
-	if (!edev)
-		return -EEXIST;
-
-	/*
-	 * FIXME: The MPS, error routing rules, timeout setting are worthy
-	 * to be exported by firmware in extendible way.
-	 */
-	if (edev->physfn)
-		ret = eeh_restore_vf_config(pdn);
-
-	if (ret) {
-		pr_warn("%s: Can't reinit PCI dev 0x%x (%lld)\n",
-			__func__, edev->pe_config_addr, ret);
-		return -EIO;
-	}
-
-	return ret;
-}
-
 #ifdef CONFIG_PCI_IOV
 int pseries_send_allow_unfreeze(struct pci_dn *pdn,
 				u16 *vf_pe_array, int cur_vfs)
@@ -848,7 +824,7 @@ static struct eeh_ops pseries_eeh_ops = {
 	.read_config		= pseries_eeh_read_config,
 	.write_config		= pseries_eeh_write_config,
 	.next_error		= NULL,
-	.restore_config		= pseries_eeh_restore_config,
+	.restore_config		= NULL, /* NB: configure_bridge() does this */
 #ifdef CONFIG_PCI_IOV
 	.notify_resume		= pseries_notify_resume
 #endif
Signature · 1 line
2.26.2
Reviewed-by on v1 6/14
#13 lore raw

Re: [PATCH 06/14] powerpc/eeh: Remove VF config space restoration

Quoted 14 lines · Oliver O'Halloran

There's a bunch of strange things about this code. First up is that none of the fields being written to are functional for a VF. The SR-IOV specification lists then as "Reserved, but OS should preserve" so writing new values to them doesn't do anything and is clearly wrong from a correctness perspective.

However, since VFs are designed to be managed by the OS there is an argument to be made that we should be saving and restoring some parts of config space. We already sort of do that by saving the first 64 bytes of config space in the eeh_dev (see eeh_dev->config_space[]). This is inadequate since it doesn't even consider saving and restoring the PCI capability structures. However, this is a problem with EEH in general and that needs to be fixed for non-VF devices too.

Quoted 3 lines

There's no real reason to keep around this around so delete it.

Quoted 156 lines
---
 arch/powerpc/include/asm/eeh.h               |  1 -
 arch/powerpc/kernel/eeh.c                    | 59 --------------------
 arch/powerpc/platforms/powernv/eeh-powernv.c | 20 ++-----
 arch/powerpc/platforms/pseries/eeh_pseries.c | 26 +--------
 4 files changed, 7 insertions(+), 99 deletions(-)
arch/powerpc/include/asm/eeh.h +0 -1
index 1bddc0dfe099..046c5a2fe411 100644
@@ -314,7 +314,6 @@ int eeh_pe_reset(struct eeh_pe *pe, int option, bool include_passed);
 int eeh_pe_configure(struct eeh_pe *pe);
 int eeh_pe_inject_err(struct eeh_pe *pe, int type, int func,
 		      unsigned long addr, unsigned long mask);
-int eeh_restore_vf_config(struct pci_dn *pdn);
 
 /**
  * EEH_POSSIBLE_ERROR() -- test for possible MMIO failure.
arch/powerpc/kernel/eeh.c +0 -59
index 859f76020256..a4df6f6de0bd 100644
@@ -742,65 +742,6 @@ static void eeh_restore_dev_state(struct eeh_dev *edev, void *userdata)
 		pci_restore_state(pdev);
 }
 
-int eeh_restore_vf_config(struct pci_dn *pdn)
-{
-	struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
-	u32 devctl, cmd, cap2, aer_capctl;
-	int old_mps;
-
-	if (edev->pcie_cap) {
-		/* Restore MPS */
-		old_mps = (ffs(pdn->mps) - 8) << 5;
-		eeh_ops->read_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
-				     2, &devctl);
-		devctl &= ~PCI_EXP_DEVCTL_PAYLOAD;
-		devctl |= old_mps;
-		eeh_ops->write_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
-				      2, devctl);
-
-		/* Disable Completion Timeout if possible */
-		eeh_ops->read_config(pdn, edev->pcie_cap + PCI_EXP_DEVCAP2,
-				     4, &cap2);
-		if (cap2 & PCI_EXP_DEVCAP2_COMP_TMOUT_DIS) {
-			eeh_ops->read_config(pdn,
-					     edev->pcie_cap + PCI_EXP_DEVCTL2,
-					     4, &cap2);
-			cap2 |= PCI_EXP_DEVCTL2_COMP_TMOUT_DIS;
-			eeh_ops->write_config(pdn,
-					      edev->pcie_cap + PCI_EXP_DEVCTL2,
-					      4, cap2);
-		}
-	}
-
-	/* Enable SERR and parity checking */
-	eeh_ops->read_config(pdn, PCI_COMMAND, 2, &cmd);
-	cmd |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
-	eeh_ops->write_config(pdn, PCI_COMMAND, 2, cmd);
-
-	/* Enable report various errors */
-	if (edev->pcie_cap) {
-		eeh_ops->read_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
-				     2, &devctl);
-		devctl &= ~PCI_EXP_DEVCTL_CERE;
-		devctl |= (PCI_EXP_DEVCTL_NFERE |
-			   PCI_EXP_DEVCTL_FERE |
-			   PCI_EXP_DEVCTL_URRE);
-		eeh_ops->write_config(pdn, edev->pcie_cap + PCI_EXP_DEVCTL,
-				      2, devctl);
-	}
-
-	/* Enable ECRC generation and check */
-	if (edev->pcie_cap && edev->aer_cap) {
-		eeh_ops->read_config(pdn, edev->aer_cap + PCI_ERR_CAP,
-				     4, &aer_capctl);
-		aer_capctl |= (PCI_ERR_CAP_ECRC_GENE | PCI_ERR_CAP_ECRC_CHKE);
-		eeh_ops->write_config(pdn, edev->aer_cap + PCI_ERR_CAP,
-				      4, aer_capctl);
-	}
-
-	return 0;
-}
-
 /**
  * pcibios_set_pcie_reset_state - Set PCI-E reset state
  * @dev: pci device struct
arch/powerpc/platforms/powernv/eeh-powernv.c +6 -14
index bcd0515d8f79..8f3a7611efc1 100644
@@ -1629,20 +1629,12 @@ static int pnv_eeh_restore_config(struct pci_dn *pdn)
 	if (!edev)
 		return -EEXIST;
 
-	/*
-	 * We have to restore the PCI config space after reset since the
-	 * firmware can't see SRIOV VFs.
-	 *
-	 * FIXME: The MPS, error routing rules, timeout setting are worthy
-	 * to be exported by firmware in extendible way.
-	 */
-	if (edev->physfn) {
-		ret = eeh_restore_vf_config(pdn);
-	} else {
-		phb = pdn->phb->private_data;
-		ret = opal_pci_reinit(phb->opal_id,
-				      OPAL_REINIT_PCI_DEV, config_addr);
-	}
+	if (edev->physfn)
+		return 0;
+
+	phb = edev->controller->private_data;
+	ret = opal_pci_reinit(phb->opal_id,
+			      OPAL_REINIT_PCI_DEV, edev->bdfn);
 
 	if (ret) {
 		pr_warn("%s: Can't reinit PCI dev 0x%x (%lld)\n",
arch/powerpc/platforms/pseries/eeh_pseries.c +0 -24
index 088771fa38be..83122bf65a8c 100644
@@ -718,30 +718,6 @@ static int pseries_eeh_write_config(struct pci_dn *pdn, int where, int size, u32
 	return rtas_write_config(pdn, where, size, val);
 }
 
-static int pseries_eeh_restore_config(struct pci_dn *pdn)
-{
-	struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
-	s64 ret = 0;
-
-	if (!edev)
-		return -EEXIST;
-
-	/*
-	 * FIXME: The MPS, error routing rules, timeout setting are worthy
-	 * to be exported by firmware in extendible way.
-	 */
-	if (edev->physfn)
-		ret = eeh_restore_vf_config(pdn);
-
-	if (ret) {
-		pr_warn("%s: Can't reinit PCI dev 0x%x (%lld)\n",
-			__func__, edev->pe_config_addr, ret);
-		return -EIO;
-	}
-
-	return ret;
-}
-
 #ifdef CONFIG_PCI_IOV
 int pseries_send_allow_unfreeze(struct pci_dn *pdn,
 				u16 *vf_pe_array, int cur_vfs)

arch/powerpc/platforms/pseries/eeh_pseries.c static struct eeh_ops pseries_eeh_ops = { · line 827

Quoted 5 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +1 -1
@@ -848,7 +824,7 @@ static struct eeh_ops pseries_eeh_ops = {
 	.read_config		= pseries_eeh_read_config,
 	.write_config		= pseries_eeh_write_config,
 	.next_error		= NULL,
-	.restore_config		= pseries_eeh_restore_config,
+	.restore_config		= NULL, /* NB: configure_bridge() does this */

configure_bridge() calls rtas_call(ibm_configure_pe, 3, 1, NULL...) which reconfigures the PE and which is quite different from what pseries_eeh_restore_config() used to do although the comment suggests it is about the same thing. I am pretty sure the new code produces a better result so I suggest ditching this comment and adding a note to the commit log may be. Thanks,

Quoted 4 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +0 -0
 #ifdef CONFIG_PCI_IOV
 	.notify_resume		= pseries_notify_resume
 #endif
Signature · 1 line
Alexey
author reviewer
#14 lore raw

Re: [PATCH 06/14] powerpc/eeh: Remove VF config space restoration

Quoted 12 lines · Alexey Kardashevskiy

arch/powerpc/platforms/pseries/eeh_pseries.c static struct eeh_ops pseries_eeh_ops = { · line 827

Quoted 10 lines

#ifdef CONFIG_PCI_IOV
int pseries_send_allow_unfreeze(struct pci_dn *pdn,

                              u16 *vf_pe_array, int cur_vfs)
arch/powerpc/platforms/pseries/eeh_pseries.c +1 -1
@@ -848,7 +824,7 @@ static struct eeh_ops pseries_eeh_ops = {
      .read_config            = pseries_eeh_read_config,
      .write_config           = pseries_eeh_write_config,
      .next_error             = NULL,
-     .restore_config         = pseries_eeh_restore_config,
+     .restore_config         = NULL, /* NB: configure_bridge() does this */
Quoted 6 lines

configure_bridge() calls rtas_call(ibm_configure_pe, 3, 1, NULL...) which reconfigures the PE and which is quite different from what pseries_eeh_restore_config() used to do although the comment suggests it is about the same thing. I am pretty sure the new code produces a better result so I suggest ditching this comment and adding a note to the commit log may be. Thanks,

I put the comment there largely because the EEH core seems to think that restore_config() is what should be called to reset the device's config space to the defaults set be firmware. On PowerNV it does actually do that and configure_bridge is this:

static int pnv_eeh_configure_bridge(struct eeh_pe *pe)

{
        return 0;
}

So... there's definitely something strange going on there. I don't remember the exact details, but I think the generic EEH code calls into RTAS to collect debug data and apparently that requires the device to be accessible via MMIO (i.e BARs need to be restored) which is why the pseries .configure_bridge() calls configure_pe. It might work out better, but having something called "restore_config" that doesn't actually restore the config is uh... modern. It's something that probably needs a rework at some point. Anyway, I think the comment is more helpful than it is misleading. Especially if you consider the PowerNV behaviour.

Quoted 7 lines

arch/powerpc/platforms/pseries/eeh_pseries.c static struct eeh_ops pseries_eeh_ops = { · line 830

Quoted 4 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +0 -0
 #ifdef CONFIG_PCI_IOV
      .notify_resume          = pseries_notify_resume
 #endif

--
Alexey

#15 lore raw

Re: [PATCH 06/14] powerpc/eeh: Remove VF config space restoration

Quoted 30 lines · Oliver O'Halloran
Quoted 12 lines · Alexey Kardashevskiy

arch/powerpc/platforms/pseries/eeh_pseries.c static struct eeh_ops pseries_eeh_ops = { · line 827

Quoted 10 lines

#ifdef CONFIG_PCI_IOV
int pseries_send_allow_unfreeze(struct pci_dn *pdn,

                              u16 *vf_pe_array, int cur_vfs)
arch/powerpc/platforms/pseries/eeh_pseries.c +1 -1
@@ -848,7 +824,7 @@ static struct eeh_ops pseries_eeh_ops = {
      .read_config            = pseries_eeh_read_config,
      .write_config           = pseries_eeh_write_config,
      .next_error             = NULL,
-     .restore_config         = pseries_eeh_restore_config,
+     .restore_config         = NULL, /* NB: configure_bridge() does this */
Quoted 6 lines

configure_bridge() calls rtas_call(ibm_configure_pe, 3, 1, NULL...) which reconfigures the PE and which is quite different from what pseries_eeh_restore_config() used to do although the comment suggests it is about the same thing. I am pretty sure the new code produces a better result so I suggest ditching this comment and adding a note to the commit log may be. Thanks,

I put the comment there largely because the EEH core seems to think that restore_config() is what should be called to reset the device's config space to the defaults set be firmware. On PowerNV it does actually do that and configure_bridge is this:

static int pnv_eeh_configure_bridge(struct eeh_pe *pe)

{
        return 0;
}
Quoted 5 lines

So... there's definitely something strange going on there. I don't remember the exact details, but I think the generic EEH code calls into RTAS to collect debug data and apparently that requires the device to be accessible via MMIO (i.e BARs need to be restored) which is why the pseries .configure_bridge() calls configure_pe.

ah ok, makes more now, cool. thanks,

Quoted 14 lines

It might
work out better, but having something called "restore_config" that doesn't actually restore the config is uh... modern. It's something that probably needs a rework at some point. Anyway, I think the comment is more helpful than it is misleading. Especially if you consider the PowerNV behaviour.

Quoted 7 lines

arch/powerpc/platforms/pseries/eeh_pseries.c static struct eeh_ops pseries_eeh_ops = { · line 830

Quoted 4 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +0 -0
 #ifdef CONFIG_PCI_IOV
      .notify_resume          = pseries_notify_resume
 #endif

--
Alexey

Signature · 1 line
Alexey
author reviewer
#16 lore raw

PATCH 7/14 powerpc/eeh: Pass eeh_dev to eeh_ops->restore_config()

In reply to Oliver O'Halloran

Mechanical conversion of the eeh_ops interfaces to use eeh_dev to reference a specific device rather than pci_dn. No functional changes.

---
 arch/powerpc/include/asm/eeh.h               | 2 +-
 arch/powerpc/kernel/eeh.c                    | 5 ++---
 arch/powerpc/kernel/eeh_pe.c                 | 6 ++----
 arch/powerpc/platforms/powernv/eeh-powernv.c | 6 ++----
 4 files changed, 7 insertions(+), 12 deletions(-)
arch/powerpc/include/asm/eeh.h +1 -1
index 046c5a2fe411..3eeaa5ef852f 100644
@@ -229,7 +229,7 @@ struct eeh_ops {
 	int (*read_config)(struct pci_dn *pdn, int where, int size, u32 *val);
 	int (*write_config)(struct pci_dn *pdn, int where, int size, u32 val);
 	int (*next_error)(struct eeh_pe **pe);
-	int (*restore_config)(struct pci_dn *pdn);
+	int (*restore_config)(struct eeh_dev *edev);
 	int (*notify_resume)(struct pci_dn *pdn);
 };
 
arch/powerpc/kernel/eeh.c +2 -3
index a4df6f6de0bd..1cef0f4bb2d5 100644
@@ -726,7 +726,6 @@ static void eeh_disable_and_save_dev_state(struct eeh_dev *edev,
 
 static void eeh_restore_dev_state(struct eeh_dev *edev, void *userdata)
 {
-	struct pci_dn *pdn = eeh_dev_to_pdn(edev);
 	struct pci_dev *pdev = eeh_dev_to_pci_dev(edev);
 	struct pci_dev *dev = userdata;
 
@@ -734,8 +733,8 @@ static void eeh_restore_dev_state(struct eeh_dev *edev, void *userdata)
 		return;
 
 	/* Apply customization from firmware */
-	if (pdn && eeh_ops->restore_config)
-		eeh_ops->restore_config(pdn);
+	if (eeh_ops->restore_config)
+		eeh_ops->restore_config(edev);
 
 	/* The caller should restore state for the specified device */
 	if (pdev != dev)
arch/powerpc/kernel/eeh_pe.c +2 -4
index 177852e39a25..d71493f66917 100644
@@ -843,16 +843,14 @@ static void eeh_restore_device_bars(struct eeh_dev *edev)
  */
 static void eeh_restore_one_device_bars(struct eeh_dev *edev, void *flag)
 {
-	struct pci_dn *pdn = eeh_dev_to_pdn(edev);
-
 	/* Do special restore for bridges */
 	if (edev->mode & EEH_DEV_BRIDGE)
 		eeh_restore_bridge_bars(edev);
 	else
 		eeh_restore_device_bars(edev);
 
-	if (eeh_ops->restore_config && pdn)
-		eeh_ops->restore_config(pdn);
+	if (eeh_ops->restore_config)
+		eeh_ops->restore_config(edev);
 }
 
 /**
arch/powerpc/platforms/powernv/eeh-powernv.c +2 -4
index 8f3a7611efc1..a41e67f674e6 100644
@@ -1619,12 +1619,10 @@ static int pnv_eeh_next_error(struct eeh_pe **pe)
 	return ret;
 }
 
-static int pnv_eeh_restore_config(struct pci_dn *pdn)
+static int pnv_eeh_restore_config(struct eeh_dev *edev)
 {
-	struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
 	struct pnv_phb *phb;
 	s64 ret = 0;
-	int config_addr = (pdn->busno << 8) | (pdn->devfn);
 
 	if (!edev)
 		return -EEXIST;
@@ -1638,7 +1636,7 @@ static int pnv_eeh_restore_config(struct pci_dn *pdn)
 
 	if (ret) {
 		pr_warn("%s: Can't reinit PCI dev 0x%x (%lld)\n",
-			__func__, config_addr, ret);
+			__func__, edev->bdfn, ret);
 		return -EIO;
 	}
 
Signature · 1 line
2.26.2
author reviewer
#17 lore raw

PATCH 8/14 powerpc/eeh: Pass eeh_dev to eeh_ops->resume_notify()

In reply to Oliver O'Halloran

Mechanical conversion of the eeh_ops interfaces to use eeh_dev to reference a specific device rather than pci_dn. No functional changes.

---
 arch/powerpc/include/asm/eeh.h               | 2 +-
 arch/powerpc/kernel/eeh_driver.c             | 4 ++--
 arch/powerpc/kernel/eeh_sysfs.c              | 2 +-
 arch/powerpc/platforms/pseries/eeh_pseries.c | 4 +---
 4 files changed, 5 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/eeh.h +1 -1
index 3eeaa5ef852f..2728a3790f6c 100644
@@ -230,7 +230,7 @@ struct eeh_ops {
 	int (*write_config)(struct pci_dn *pdn, int where, int size, u32 val);
 	int (*next_error)(struct eeh_pe **pe);
 	int (*restore_config)(struct eeh_dev *edev);
-	int (*notify_resume)(struct pci_dn *pdn);
+	int (*notify_resume)(struct eeh_dev *edev);
 };
 
 extern int eeh_subsystem_flags;
arch/powerpc/kernel/eeh_driver.c +2 -2
index b70b9273f45a..b84d3cb2532e 100644
@@ -425,8 +425,8 @@ static enum pci_ers_result eeh_report_resume(struct eeh_dev *edev,
 
 	pci_uevent_ers(edev->pdev, PCI_ERS_RESULT_RECOVERED);
 #ifdef CONFIG_PCI_IOV
-	if (eeh_ops->notify_resume && eeh_dev_to_pdn(edev))
-		eeh_ops->notify_resume(eeh_dev_to_pdn(edev));
+	if (eeh_ops->notify_resume)
+		eeh_ops->notify_resume(edev);
 #endif
 	return PCI_ERS_RESULT_NONE;
 }
arch/powerpc/kernel/eeh_sysfs.c +1 -1
index 4fb0f1e1017a..429620da73ba 100644
@@ -99,7 +99,7 @@ static ssize_t eeh_notify_resume_store(struct device *dev,
 	if (!edev || !edev->pe || !eeh_ops->notify_resume)
 		return -ENODEV;
 
-	if (eeh_ops->notify_resume(pci_get_pdn(pdev)))
+	if (eeh_ops->notify_resume(edev))
 		return -EIO;
 
 	return count;
arch/powerpc/platforms/pseries/eeh_pseries.c +1 -3
index 83122bf65a8c..7a4c7a373241 100644
@@ -793,10 +793,8 @@ static int pseries_call_allow_unfreeze(struct eeh_dev *edev)
 	return rc;
 }
 
-static int pseries_notify_resume(struct pci_dn *pdn)
+static int pseries_notify_resume(struct eeh_dev *edev)
 {
-	struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
-
 	if (!edev)
 		return -EEXIST;
 
Signature · 1 line
2.26.2
author reviewer
#18 lore raw

PATCH 9/14 powerpc/eeh: Pass eeh_dev to eeh_ops->{read|write}_config()

In reply to Oliver O'Halloran

Mechanical conversion of the eeh_ops interfaces to use eeh_dev to reference a specific device rather than pci_dn. No functional changes.

---
 arch/powerpc/include/asm/eeh.h               |  4 +-
 arch/powerpc/kernel/eeh.c                    | 22 +++++----
 arch/powerpc/kernel/eeh_pe.c                 | 47 +++++++++-----------
 arch/powerpc/platforms/powernv/eeh-powernv.c | 43 ++++++++++--------
 arch/powerpc/platforms/pseries/eeh_pseries.c | 16 ++++---
 5 files changed, 68 insertions(+), 64 deletions(-)
arch/powerpc/include/asm/eeh.h +2 -2
index 2728a3790f6c..293a55dc803b 100644
@@ -226,8 +226,8 @@ struct eeh_ops {
 	int (*configure_bridge)(struct eeh_pe *pe);
 	int (*err_inject)(struct eeh_pe *pe, int type, int func,
 			  unsigned long addr, unsigned long mask);
-	int (*read_config)(struct pci_dn *pdn, int where, int size, u32 *val);
-	int (*write_config)(struct pci_dn *pdn, int where, int size, u32 val);
+	int (*read_config)(struct eeh_dev *edev, int where, int size, u32 *val);
+	int (*write_config)(struct eeh_dev *edev, int where, int size, u32 val);
 	int (*next_error)(struct eeh_pe **pe);
 	int (*restore_config)(struct eeh_dev *edev);
 	int (*notify_resume)(struct eeh_dev *edev);
arch/powerpc/kernel/eeh.c +10 -12
index 1cef0f4bb2d5..1a12c8bdf61e 100644
@@ -185,21 +185,21 @@ static size_t eeh_dump_dev_log(struct eeh_dev *edev, char *buf, size_t len)
 		pdn->phb->global_number, pdn->busno,
 		PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
 
-	eeh_ops->read_config(pdn, PCI_VENDOR_ID, 4, &cfg);
+	eeh_ops->read_config(edev, PCI_VENDOR_ID, 4, &cfg);
 	n += scnprintf(buf+n, len-n, "dev/vend:%08x\n", cfg);
 	pr_warn("EEH: PCI device/vendor: %08x\n", cfg);
 
-	eeh_ops->read_config(pdn, PCI_COMMAND, 4, &cfg);
+	eeh_ops->read_config(edev, PCI_COMMAND, 4, &cfg);
 	n += scnprintf(buf+n, len-n, "cmd/stat:%x\n", cfg);
 	pr_warn("EEH: PCI cmd/status register: %08x\n", cfg);
 
 	/* Gather bridge-specific registers */
 	if (edev->mode & EEH_DEV_BRIDGE) {
-		eeh_ops->read_config(pdn, PCI_SEC_STATUS, 2, &cfg);
+		eeh_ops->read_config(edev, PCI_SEC_STATUS, 2, &cfg);
 		n += scnprintf(buf+n, len-n, "sec stat:%x\n", cfg);
 		pr_warn("EEH: Bridge secondary status: %04x\n", cfg);
 
-		eeh_ops->read_config(pdn, PCI_BRIDGE_CONTROL, 2, &cfg);
+		eeh_ops->read_config(edev, PCI_BRIDGE_CONTROL, 2, &cfg);
 		n += scnprintf(buf+n, len-n, "brdg ctl:%x\n", cfg);
 		pr_warn("EEH: Bridge control: %04x\n", cfg);
 	}
@@ -207,11 +207,11 @@ static size_t eeh_dump_dev_log(struct eeh_dev *edev, char *buf, size_t len)
 	/* Dump out the PCI-X command and status regs */
 	cap = edev->pcix_cap;
 	if (cap) {
-		eeh_ops->read_config(pdn, cap, 4, &cfg);
+		eeh_ops->read_config(edev, cap, 4, &cfg);
 		n += scnprintf(buf+n, len-n, "pcix-cmd:%x\n", cfg);
 		pr_warn("EEH: PCI-X cmd: %08x\n", cfg);
 
-		eeh_ops->read_config(pdn, cap+4, 4, &cfg);
+		eeh_ops->read_config(edev, cap+4, 4, &cfg);
 		n += scnprintf(buf+n, len-n, "pcix-stat:%x\n", cfg);
 		pr_warn("EEH: PCI-X status: %08x\n", cfg);
 	}
@@ -223,7 +223,7 @@ static size_t eeh_dump_dev_log(struct eeh_dev *edev, char *buf, size_t len)
 		pr_warn("EEH: PCI-E capabilities and status follow:\n");
 
 		for (i=0; i<=8; i++) {
-			eeh_ops->read_config(pdn, cap+4*i, 4, &cfg);
+			eeh_ops->read_config(edev, cap+4*i, 4, &cfg);
 			n += scnprintf(buf+n, len-n, "%02x:%x\n", 4*i, cfg);
 
 			if ((i % 4) == 0) {
@@ -250,7 +250,7 @@ static size_t eeh_dump_dev_log(struct eeh_dev *edev, char *buf, size_t len)
 		pr_warn("EEH: PCI-E AER capability register set follows:\n");
 
 		for (i=0; i<=13; i++) {
-			eeh_ops->read_config(pdn, cap+4*i, 4, &cfg);
+			eeh_ops->read_config(edev, cap+4*i, 4, &cfg);
 			n += scnprintf(buf+n, len-n, "%02x:%x\n", 4*i, cfg);
 
 			if ((i % 4) == 0) {
@@ -917,15 +917,13 @@ int eeh_pe_reset_full(struct eeh_pe *pe, bool include_passed)
  */
 void eeh_save_bars(struct eeh_dev *edev)
 {
-	struct pci_dn *pdn;
 	int i;
 
-	pdn = eeh_dev_to_pdn(edev);
-	if (!pdn)
+	if (!edev)
 		return;
 
 	for (i = 0; i < 16; i++)
-		eeh_ops->read_config(pdn, i * 4, 4, &edev->config_space[i]);
+		eeh_ops->read_config(edev, i * 4, 4, &edev->config_space[i]);
 
 	/*
 	 * For PCI bridges including root port, we need enable bus
arch/powerpc/kernel/eeh_pe.c +22 -25

130 lines not on this page · raw message

arch/powerpc/platforms/powernv/eeh-powernv.c +24 -19

129 lines not on this page · raw message

arch/powerpc/platforms/pseries/eeh_pseries.c +10 -6
index 7a4c7a373241..e75579b857ce 100644
@@ -692,29 +692,33 @@ static int pseries_eeh_configure_bridge(struct eeh_pe *pe)
 
 /**
  * pseries_eeh_read_config - Read PCI config space
- * @pdn: PCI device node
- * @where: PCI address
+ * @edev: EEH device handle
+ * @where: PCI config space offset
  * @size: size to read
  * @val: return value
  *
  * Read config space from the speicifed device
  */
-static int pseries_eeh_read_config(struct pci_dn *pdn, int where, int size, u32 *val)
+static int pseries_eeh_read_config(struct eeh_dev *edev, int where, int size, u32 *val)
 {
+	struct pci_dn *pdn = eeh_dev_to_pdn(edev);
+
 	return rtas_read_config(pdn, where, size, val);
 }
 
 /**
  * pseries_eeh_write_config - Write PCI config space
- * @pdn: PCI device node
- * @where: PCI address
+ * @edev: EEH device handle
+ * @where: PCI config space offset
  * @size: size to write
  * @val: value to be written
  *
  * Write config space to the specified device
  */
-static int pseries_eeh_write_config(struct pci_dn *pdn, int where, int size, u32 val)
+static int pseries_eeh_write_config(struct eeh_dev *edev, int where, int size, u32 val)
 {
+	struct pci_dn *pdn = eeh_dev_to_pdn(edev);
+
 	return rtas_write_config(pdn, where, size, val);
 }
 
Signature · 1 line
2.26.2
author reviewer
#19 lore raw

PATCH 10/14 powerpc/eeh: Remove spurious use of pci_dn in eeh_dump_dev_log

In reply to Oliver O'Halloran

Retrieve the domain, bus, device, and function numbers from the edev.

---
 arch/powerpc/kernel/eeh.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
arch/powerpc/kernel/eeh.c +4 -10
index 1a12c8bdf61e..f203ffc5c57d 100644
@@ -167,23 +167,17 @@ void eeh_show_enabled(void)
  */
 static size_t eeh_dump_dev_log(struct eeh_dev *edev, char *buf, size_t len)
 {
-	struct pci_dn *pdn = eeh_dev_to_pdn(edev);
 	u32 cfg;
 	int cap, i;
 	int n = 0, l = 0;
 	char buffer[128];
 
-	if (!pdn) {
-		pr_warn("EEH: Note: No error log for absent device.\n");
-		return 0;
-	}
-
 	n += scnprintf(buf+n, len-n, "%04x:%02x:%02x.%01x\n",
-		       pdn->phb->global_number, pdn->busno,
-		       PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
+			edev->pe->phb->global_number, edev->bdfn >> 8,
+			PCI_SLOT(edev->bdfn), PCI_FUNC(edev->bdfn));
 	pr_warn("EEH: of node=%04x:%02x:%02x.%01x\n",
-		pdn->phb->global_number, pdn->busno,
-		PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
+		edev->pe->phb->global_number, edev->bdfn >> 8,
+		PCI_SLOT(edev->bdfn), PCI_FUNC(edev->bdfn));
 
 	eeh_ops->read_config(edev, PCI_VENDOR_ID, 4, &cfg);
 	n += scnprintf(buf+n, len-n, "dev/vend:%08x\n", cfg);
Signature · 1 line
2.26.2
author reviewer
#20 lore raw

PATCH 11/14 powerpc/eeh: Remove class code field from edev

In reply to Oliver O'Halloran

The edev->class_code field is never referenced anywhere except for the platform specific probe functions. The same information is available in the pci_dev for PowerNV and in the pci_dn on pseries so we can remove the field.

---
 arch/powerpc/include/asm/eeh.h               | 1 -
 arch/powerpc/platforms/powernv/eeh-powernv.c | 5 ++---
 arch/powerpc/platforms/pseries/eeh_pseries.c | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)
arch/powerpc/include/asm/eeh.h +0 -1
index 293a55dc803b..a2f7ed204ece 100644
@@ -133,7 +133,6 @@ static inline bool eeh_pe_passed(struct eeh_pe *pe)
 
 struct eeh_dev {
 	int mode;			/* EEH mode			*/
-	int class_code;			/* Class code of the device	*/
 	int bdfn;			/* bdfn of device (for cfg ops) */
 	struct pci_controller *controller;
 	int pe_config_addr;		/* PE config address		*/
arch/powerpc/platforms/powernv/eeh-powernv.c +2 -3
index c9f2f454d053..7cbb03a97a61 100644
@@ -372,19 +372,18 @@ static struct eeh_dev *pnv_eeh_probe(struct pci_dev *pdev)
 	}
 
 	/* Skip for PCI-ISA bridge */
-	if ((pdn->class_code >> 8) == PCI_CLASS_BRIDGE_ISA)
+	if ((pdev->class >> 8) == PCI_CLASS_BRIDGE_ISA)
 		return NULL;
 
 	eeh_edev_dbg(edev, "Probing device\n");
 
 	/* Initialize eeh device */
-	edev->class_code = pdn->class_code;
 	edev->mode	&= 0xFFFFFF00;
 	edev->pcix_cap = pnv_eeh_find_cap(pdn, PCI_CAP_ID_PCIX);
 	edev->pcie_cap = pnv_eeh_find_cap(pdn, PCI_CAP_ID_EXP);
 	edev->af_cap   = pnv_eeh_find_cap(pdn, PCI_CAP_ID_AF);
 	edev->aer_cap  = pnv_eeh_find_ecap(pdn, PCI_EXT_CAP_ID_ERR);
-	if ((edev->class_code >> 8) == PCI_CLASS_BRIDGE_PCI) {
+	if ((pdev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
 		edev->mode |= EEH_DEV_BRIDGE;
 		if (edev->pcie_cap) {
 			pnv_pci_cfg_read(pdn, edev->pcie_cap + PCI_EXP_FLAGS,
arch/powerpc/platforms/pseries/eeh_pseries.c +1 -2
index e75579b857ce..daf6caeca8f0 100644
@@ -273,12 +273,11 @@ void pseries_eeh_init_edev(struct pci_dn *pdn)
 	 * correctly reflects that current device is root port
 	 * or PCIe switch downstream port.
 	 */
-	edev->class_code = pdn->class_code;
 	edev->pcix_cap = pseries_eeh_find_cap(pdn, PCI_CAP_ID_PCIX);
 	edev->pcie_cap = pseries_eeh_find_cap(pdn, PCI_CAP_ID_EXP);
 	edev->aer_cap = pseries_eeh_find_ecap(pdn, PCI_EXT_CAP_ID_ERR);
 	edev->mode &= 0xFFFFFF00;
-	if ((edev->class_code >> 8) == PCI_CLASS_BRIDGE_PCI) {
+	if ((pdn->class_code >> 8) == PCI_CLASS_BRIDGE_PCI) {
 		edev->mode |= EEH_DEV_BRIDGE;
 		if (edev->pcie_cap) {
 			rtas_read_config(pdn, edev->pcie_cap + PCI_EXP_FLAGS,
Signature · 1 line
2.26.2
author reviewer
#21 lore raw

PATCH 12/14 powerpc/eeh: Rename eeh_{add_to|remove_from}_parent_pe()

In reply to Oliver O'Halloran

The naming of eeh_{add_to|remove_from}_parent_pe() doesn't really reflect what they actually do. If the PE referred to be edev->pe_config_addr already exists under that PHB then the edev is added to that PE. However, if the PE doesn't exist the a new one is created for the edev.

The bulk of the implementation of eeh_add_to_parent_pe() covers that second case. Similarly, most of eeh_remove_from_parent_pe() is determining when it's safe to delete a PE.

---
 arch/powerpc/include/asm/eeh.h               | 4 ++--
 arch/powerpc/kernel/eeh.c                    | 4 ++--
 arch/powerpc/kernel/eeh_driver.c             | 2 +-
 arch/powerpc/kernel/eeh_pe.c                 | 8 ++++----
 arch/powerpc/kernel/pci_dn.c                 | 2 +-
 arch/powerpc/platforms/powernv/eeh-powernv.c | 2 +-
 arch/powerpc/platforms/pseries/eeh_pseries.c | 8 ++++----
 7 files changed, 15 insertions(+), 15 deletions(-)
arch/powerpc/include/asm/eeh.h +2 -2
index a2f7ed204ece..8d34e5b790c2 100644
@@ -283,8 +283,8 @@ struct eeh_pe *eeh_phb_pe_get(struct pci_controller *phb);
 struct eeh_pe *eeh_pe_next(struct eeh_pe *pe, struct eeh_pe *root);
 struct eeh_pe *eeh_pe_get(struct pci_controller *phb,
 			  int pe_no, int config_addr);
-int eeh_add_to_parent_pe(struct eeh_dev *edev);
-int eeh_rmv_from_parent_pe(struct eeh_dev *edev);
+int eeh_pe_tree_insert(struct eeh_dev *edev);
+int eeh_pe_tree_remove(struct eeh_dev *edev);
 void eeh_pe_update_time_stamp(struct eeh_pe *pe);
 void *eeh_pe_traverse(struct eeh_pe *root,
 		      eeh_pe_traverse_func fn, void *flag);
arch/powerpc/kernel/eeh.c +2 -2
index f203ffc5c57d..94682382fc8c 100644
@@ -1107,7 +1107,7 @@ void eeh_probe_device(struct pci_dev *dev)
 	 * FIXME: HEY MA, LOOK AT ME, NO LOCKING!
 	 */
 	if (edev->pdev && edev->pdev != dev) {
-		eeh_rmv_from_parent_pe(edev);
+		eeh_pe_tree_remove(edev);
 		eeh_addr_cache_rmv_dev(edev->pdev);
 		eeh_sysfs_remove_device(edev->pdev);
 
@@ -1186,7 +1186,7 @@ void eeh_remove_device(struct pci_dev *dev)
 	edev->in_error = false;
 	dev->dev.archdata.edev = NULL;
 	if (!(edev->pe->state & EEH_PE_KEEP))
-		eeh_rmv_from_parent_pe(edev);
+		eeh_pe_tree_remove(edev);
 	else
 		edev->mode |= EEH_DEV_DISCONNECTED;
 }
arch/powerpc/kernel/eeh_driver.c +1 -1
index b84d3cb2532e..4197e4559f65 100644
@@ -542,7 +542,7 @@ static void *eeh_pe_detach_dev(struct eeh_pe *pe, void *userdata)
 			continue;
 
 		edev->mode &= ~(EEH_DEV_DISCONNECTED | EEH_DEV_IRQ_DISABLED);
-		eeh_rmv_from_parent_pe(edev);
+		eeh_pe_tree_remove(edev);
 	}
 
 	return NULL;
arch/powerpc/kernel/eeh_pe.c +4 -4
index f20fb0ee6aec..97bf09db2ecd 100644
@@ -356,7 +356,7 @@ static struct eeh_pe *eeh_pe_get_parent(struct eeh_dev *edev)
 }
 
 /**
- * eeh_add_to_parent_pe - Add EEH device to parent PE
+ * eeh_pe_tree_insert - Add EEH device to parent PE
  * @edev: EEH device
  *
  * Add EEH device to the parent PE. If the parent PE already
@@ -364,7 +364,7 @@ static struct eeh_pe *eeh_pe_get_parent(struct eeh_dev *edev)
  * we have to create new PE to hold the EEH device and the new
  * PE will be linked to its parent PE as well.
  */
-int eeh_add_to_parent_pe(struct eeh_dev *edev)
+int eeh_pe_tree_insert(struct eeh_dev *edev)
 {
 	struct eeh_pe *pe, *parent;
 	struct pci_dn *pdn = eeh_dev_to_pdn(edev);
@@ -459,7 +459,7 @@ int eeh_add_to_parent_pe(struct eeh_dev *edev)
 }
 
 /**
- * eeh_rmv_from_parent_pe - Remove one EEH device from the associated PE
+ * eeh_pe_tree_remove - Remove one EEH device from the associated PE
  * @edev: EEH device
  *
  * The PE hierarchy tree might be changed when doing PCI hotplug.
@@ -467,7 +467,7 @@ int eeh_add_to_parent_pe(struct eeh_dev *edev)
  * during EEH recovery. So we have to call the function remove the
  * corresponding PE accordingly if necessary.
  */
-int eeh_rmv_from_parent_pe(struct eeh_dev *edev)
+int eeh_pe_tree_remove(struct eeh_dev *edev)
 {
 	struct eeh_pe *pe, *parent, *child;
 	bool keep, recover;
arch/powerpc/kernel/pci_dn.c +1 -1
index bf11ac8427ac..e99b7c547d7e 100644
@@ -263,7 +263,7 @@ void remove_sriov_vf_pdns(struct pci_dev *pdev)
 				 * have a configured PE.
 				 */
 				if (edev->pe)
-					eeh_rmv_from_parent_pe(edev);
+					eeh_pe_tree_remove(edev);
 
 				pdn->edev = NULL;
 				kfree(edev);
arch/powerpc/platforms/powernv/eeh-powernv.c +1 -1
index 7cbb03a97a61..8c9fca773692 100644
@@ -399,7 +399,7 @@ static struct eeh_dev *pnv_eeh_probe(struct pci_dev *pdev)
 	edev->pe_config_addr = phb->ioda.pe_rmap[config_addr];
 
 	/* Create PE */
-	ret = eeh_add_to_parent_pe(edev);
+	ret = eeh_pe_tree_insert(edev);
 	if (ret) {
 		eeh_edev_warn(edev, "Failed to add device to PE (code %d)\n", ret);
 		return NULL;
arch/powerpc/platforms/pseries/eeh_pseries.c +4 -4
index daf6caeca8f0..72556f4436a8 100644
@@ -71,8 +71,8 @@ void pseries_pcibios_bus_add_device(struct pci_dev *pdev)
 		struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
 
 		edev->pe_config_addr =  (pdn->busno << 16) | (pdn->devfn << 8);
-		eeh_rmv_from_parent_pe(edev); /* Remove as it is adding to bus pe */
-		eeh_add_to_parent_pe(edev);   /* Add as VF PE type */
+		eeh_pe_tree_remove(edev); /* Remove as it is adding to bus pe */
+		eeh_pe_tree_insert(edev);   /* Add as VF PE type */
 	}
 #endif
 	eeh_probe_device(pdev);
@@ -315,14 +315,14 @@ void pseries_eeh_init_edev(struct pci_dn *pdn)
 
 		if (enable) {
 			eeh_add_flag(EEH_ENABLED);
-			eeh_add_to_parent_pe(edev);
+			eeh_pe_tree_insert(edev);
 		} else if (pdn->parent && pdn_to_eeh_dev(pdn->parent) &&
 			   (pdn_to_eeh_dev(pdn->parent))->pe) {
 			/* This device doesn't support EEH, but it may have an
 			 * EEH parent, in which case we mark it as supported.
 			 */
 			edev->pe_config_addr = pdn_to_eeh_dev(pdn->parent)->pe_config_addr;
-			eeh_add_to_parent_pe(edev);
+			eeh_pe_tree_insert(edev);
 		}
 		eeh_edev_dbg(edev, "EEH is %s on device (code %d)\n",
 			     (enable ? "enabled" : "unsupported"), ret);
Signature · 1 line
2.26.2
author reviewer
#22 lore raw

PATCH 13/14 powerpc/eeh: Drop pdn use in eeh_pe_tree_insert()

In reply to Oliver O'Halloran

This is mostly just to make the subsequent diffs less noisy. No functional changes.

One thing that needs calling out is the removal of the "config_addr" variable and replacing it with edev->bdfn. The contents of edev->bdfn are the same, however it's worth pointing out that what RTAS calls a "config_addr" isn't the same as the bdfn. The config_addr is supposed to
be: <bus><devfn><reg> with each field being an 8 bit number. Various parts of the EEH code use BDFN and "config_addr" as interchangeable quantities even though they aren't really.

---
 arch/powerpc/kernel/eeh_pe.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
arch/powerpc/kernel/eeh_pe.c +7 -8
index 97bf09db2ecd..898205829a8f 100644
@@ -366,9 +366,8 @@ static struct eeh_pe *eeh_pe_get_parent(struct eeh_dev *edev)
  */
 int eeh_pe_tree_insert(struct eeh_dev *edev)
 {
+	struct pci_controller *hose = edev->controller;
 	struct eeh_pe *pe, *parent;
-	struct pci_dn *pdn = eeh_dev_to_pdn(edev);
-	int config_addr = (pdn->busno << 8) | (pdn->devfn);
 
 	/* Check if the PE number is valid */
 	if (!eeh_has_flag(EEH_VALID_PE_ZERO) && !edev->pe_config_addr) {
@@ -382,7 +381,7 @@ int eeh_pe_tree_insert(struct eeh_dev *edev)
 	 * PE should be composed of PCI bus and its subordinate
 	 * components.
 	 */
-	pe = eeh_pe_get(pdn->phb, edev->pe_config_addr, config_addr);
+	pe = eeh_pe_get(hose, edev->pe_config_addr, edev->bdfn);
 	if (pe) {
 		if (pe->type & EEH_PE_INVALID) {
 			list_add_tail(&edev->entry, &pe->edevs);
@@ -416,15 +415,15 @@ int eeh_pe_tree_insert(struct eeh_dev *edev)
 
 	/* Create a new EEH PE */
 	if (edev->physfn)
-		pe = eeh_pe_alloc(pdn->phb, EEH_PE_VF);
+		pe = eeh_pe_alloc(hose, EEH_PE_VF);
 	else
-		pe = eeh_pe_alloc(pdn->phb, EEH_PE_DEVICE);
+		pe = eeh_pe_alloc(hose, EEH_PE_DEVICE);
 	if (!pe) {
 		pr_err("%s: out of memory!\n", __func__);
 		return -ENOMEM;
 	}
 	pe->addr	= edev->pe_config_addr;
-	pe->config_addr	= config_addr;
+	pe->config_addr	= edev->bdfn;
 
 	/*
 	 * Put the new EEH PE into hierarchy tree. If the parent
@@ -434,10 +433,10 @@ int eeh_pe_tree_insert(struct eeh_dev *edev)
 	 */
 	parent = eeh_pe_get_parent(edev);
 	if (!parent) {
-		parent = eeh_phb_pe_get(pdn->phb);
+		parent = eeh_phb_pe_get(hose);
 		if (!parent) {
 			pr_err("%s: No PHB PE is found (PHB Domain=%d)\n",
-				__func__, pdn->phb->global_number);
+				__func__, hose->global_number);
 			edev->pe = NULL;
 			kfree(pe);
 			return -EEXIST;
Signature · 1 line
2.26.2
author reviewer
#23 lore raw

PATCH 14/14 powerpc/eeh: Move PE tree setup into the platform

In reply to Oliver O'Halloran

The EEH core has a concept of a "PE tree" to support PowerNV. The PE tree follows the PCI bus structures because a reset asserted on an upstream bridge will be propagated to the downstream bridges. On pseries there's a 1-1 correspondence between what the guest sees are a PHB and a PE so the "tree" is really just a single node.

Current the EEH core is reponsible for setting up this PE tree which it does by traversing the pci_dn tree. The structure of the pci_dn tree matches the bus tree on PowerNV which leads to the PE tree being "correct" this setup method doesn't make a whole lot of sense and it's actively confusing for the pseries case where it doesn't really do anything.

We want to remove the dependence on pci_dn anyway so this patch move choosing where to insert a new PE into the platform code rather than being part of the generic EEH code. For PowerNV this simplifies the tree building logic and removes the use of pci_dn. For pseries we keep the existing logic. I'm not really convinced it does anything due to the 1-1 PE-to-PHB correspondence so every device under that PHB should be in the same PE, but I'd rather not remove it entirely until we've had a chance to look at it more deeply.

---
 arch/powerpc/include/asm/eeh.h               |  2 +-
 arch/powerpc/kernel/eeh_pe.c                 | 70 ++++++--------------
 arch/powerpc/platforms/powernv/eeh-powernv.c | 27 +++++++-
 arch/powerpc/platforms/pseries/eeh_pseries.c | 59 +++++++++++++++--
 4 files changed, 101 insertions(+), 57 deletions(-)
arch/powerpc/include/asm/eeh.h +1 -1
index 8d34e5b790c2..1cab629dbc74 100644
@@ -283,7 +283,7 @@ struct eeh_pe *eeh_phb_pe_get(struct pci_controller *phb);
 struct eeh_pe *eeh_pe_next(struct eeh_pe *pe, struct eeh_pe *root);
 struct eeh_pe *eeh_pe_get(struct pci_controller *phb,
 			  int pe_no, int config_addr);
-int eeh_pe_tree_insert(struct eeh_dev *edev);
+int eeh_pe_tree_insert(struct eeh_dev *edev, struct eeh_pe *new_pe_parent);
 int eeh_pe_tree_remove(struct eeh_dev *edev);
 void eeh_pe_update_time_stamp(struct eeh_pe *pe);
 void *eeh_pe_traverse(struct eeh_pe *root,
arch/powerpc/kernel/eeh_pe.c +19 -51

106 lines not on this page · raw message

arch/powerpc/platforms/powernv/eeh-powernv.c +26 -1
index 8c9fca773692..9af8c3b98853 100644
@@ -338,6 +338,28 @@ static int pnv_eeh_find_ecap(struct pci_dn *pdn, int cap)
 	return 0;
 }
 
+static struct eeh_pe *pnv_eeh_get_upstream_pe(struct pci_dev *pdev)
+{
+	struct pci_controller *hose = pdev->bus->sysdata;
+	struct pnv_phb *phb = hose->private_data;
+	struct pci_dev *parent = pdev->bus->self;
+
+#ifdef CONFIG_PCI_IOV
+	/* for VFs we use the PF's PE as the upstream PE */
+	if (pdev->is_virtfn)
+		parent = pdev->physfn;
+#endif
+
+	/* otherwise use the PE of our parent bridge */
+	if (parent) {
+		struct pnv_ioda_pe *ioda_pe = pnv_ioda_get_pe(parent);
+
+		return eeh_pe_get(phb->hose, ioda_pe->pe_number, 0);
+	}
+
+	return NULL;
+}
+
 /**
  * pnv_eeh_probe - Do probe on PCI device
  * @pdev: pci_dev to probe
@@ -350,6 +372,7 @@ static struct eeh_dev *pnv_eeh_probe(struct pci_dev *pdev)
 	struct pci_controller *hose = pdn->phb;
 	struct pnv_phb *phb = hose->private_data;
 	struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
+	struct eeh_pe *upstream_pe;
 	uint32_t pcie_flags;
 	int ret;
 	int config_addr = (pdn->busno << 8) | (pdn->devfn);
@@ -398,8 +421,10 @@ static struct eeh_dev *pnv_eeh_probe(struct pci_dev *pdev)
 
 	edev->pe_config_addr = phb->ioda.pe_rmap[config_addr];
 
+	upstream_pe = pnv_eeh_get_upstream_pe(pdev);
+
 	/* Create PE */
-	ret = eeh_pe_tree_insert(edev);
+	ret = eeh_pe_tree_insert(edev, upstream_pe);
 	if (ret) {
 		eeh_edev_warn(edev, "Failed to add device to PE (code %d)\n", ret);
 		return NULL;
arch/powerpc/platforms/pseries/eeh_pseries.c +55 -4

94 lines not on this page · raw message

Signature · 1 line
2.26.2
Reviewed-by on v1 14/14
#24 lore raw

Re: [PATCH 14/14] powerpc/eeh: Move PE tree setup into the platform

Quoted 99 lines · Oliver O'Halloran

The EEH core has a concept of a "PE tree" to support PowerNV. The PE tree follows the PCI bus structures because a reset asserted on an upstream bridge will be propagated to the downstream bridges. On pseries there's a 1-1 correspondence between what the guest sees are a PHB and a PE so the "tree" is really just a single node.

Current the EEH core is reponsible for setting up this PE tree which it does by traversing the pci_dn tree. The structure of the pci_dn tree matches the bus tree on PowerNV which leads to the PE tree being "correct" this setup method doesn't make a whole lot of sense and it's actively confusing for the pseries case where it doesn't really do anything.

We want to remove the dependence on pci_dn anyway so this patch move choosing where to insert a new PE into the platform code rather than being part of the generic EEH code. For PowerNV this simplifies the tree building logic and removes the use of pci_dn. For pseries we keep the existing logic. I'm not really convinced it does anything due to the 1-1 PE-to-PHB correspondence so every device under that PHB should be in the same PE, but I'd rather not remove it entirely until we've had a chance to look at it more deeply.

---
 arch/powerpc/include/asm/eeh.h               |  2 +-
 arch/powerpc/kernel/eeh_pe.c                 | 70 ++++++--------------
 arch/powerpc/platforms/powernv/eeh-powernv.c | 27 +++++++-
 arch/powerpc/platforms/pseries/eeh_pseries.c | 59 +++++++++++++++--
 4 files changed, 101 insertions(+), 57 deletions(-)
arch/powerpc/include/asm/eeh.h +1 -1
index 8d34e5b790c2..1cab629dbc74 100644
@@ -283,7 +283,7 @@ struct eeh_pe *eeh_phb_pe_get(struct pci_controller *phb);
 struct eeh_pe *eeh_pe_next(struct eeh_pe *pe, struct eeh_pe *root);
 struct eeh_pe *eeh_pe_get(struct pci_controller *phb,
 			  int pe_no, int config_addr);
-int eeh_pe_tree_insert(struct eeh_dev *edev);
+int eeh_pe_tree_insert(struct eeh_dev *edev, struct eeh_pe *new_pe_parent);
 int eeh_pe_tree_remove(struct eeh_dev *edev);
 void eeh_pe_update_time_stamp(struct eeh_pe *pe);
 void *eeh_pe_traverse(struct eeh_pe *root,
arch/powerpc/kernel/eeh_pe.c +4 -41
index 898205829a8f..ea2f8b362d18 100644
@@ -318,53 +318,20 @@ struct eeh_pe *eeh_pe_get(struct pci_controller *phb,
 	return pe;
 }
 
-/**
- * eeh_pe_get_parent - Retrieve the parent PE
- * @edev: EEH device
- *
- * The whole PEs existing in the system are organized as hierarchy
- * tree. The function is used to retrieve the parent PE according
- * to the parent EEH device.
- */
-static struct eeh_pe *eeh_pe_get_parent(struct eeh_dev *edev)
-{
-	struct eeh_dev *parent;
-	struct pci_dn *pdn = eeh_dev_to_pdn(edev);
-
-	/*
-	 * It might have the case for the indirect parent
-	 * EEH device already having associated PE, but
-	 * the direct parent EEH device doesn't have yet.
-	 */
-	if (edev->physfn)
-		pdn = pci_get_pdn(edev->physfn);
-	else
-		pdn = pdn ? pdn->parent : NULL;
-	while (pdn) {
-		/* We're poking out of PCI territory */
-		parent = pdn_to_eeh_dev(pdn);
-		if (!parent)
-			return NULL;
-
-		if (parent->pe)
-			return parent->pe;
-
-		pdn = pdn->parent;
-	}
-
-	return NULL;
-}
-
 /**
  * eeh_pe_tree_insert - Add EEH device to parent PE
  * @edev: EEH device
+ * @new_pe_parent: PE to create additional PEs under
  *
- * Add EEH device to the parent PE. If the parent PE already
- * exists, the PE type will be changed to EEH_PE_BUS. Otherwise,
- * we have to create new PE to hold the EEH device and the new
- * PE will be linked to its parent PE as well.
+ * Add EEH device to the PE in edev->pe_config_addr. If a PE already
+ * exists with that address then @edev is added to that PE. Otherwise
+ * a new PE is created and inserted into the PE tree as a child of

arch/powerpc/kernel/eeh_pe.c struct eeh_pe *eeh_pe_get(struct pci_controller *phb, · line 337

Quoted 10 lines
arch/powerpc/kernel/eeh_pe.c +5 -1
+ * @new_pe_parent.
+ *
+ * If @new_pe_parent is NULL then the new PE will be inserted under
+ * directly under the the PHB.
  */
-int eeh_pe_tree_insert(struct eeh_dev *edev)
+int eeh_pe_tree_insert(struct eeh_dev *edev, struct eeh_pe *new_pe_parent)
 {
 	struct pci_controller *hose = edev->controller;
 	struct eeh_pe *pe, *parent;

We can ditch this "parent" in that single place now and use "pe" instead. And name the new parameter simply "parent". Dunno if it improves things though.

Quoted 10 lines
arch/powerpc/kernel/eeh_pe.c +1 -1
@@ -399,7 +366,7 @@ int eeh_pe_tree_insert(struct eeh_dev *edev)
 			}
 
 			eeh_edev_dbg(edev,
-				     "Added to device PE (parent: PE#%x)\n",
+				     "Added to existing PE (parent: PE#%x)\n",
 				     pe->parent->addr);
 		} else {
 			/* Mark the PE as type of PCI bus */

arch/powerpc/kernel/eeh_pe.c int eeh_pe_tree_insert(struct eeh_dev *edev) · line 403

Quoted 10 lines
arch/powerpc/kernel/eeh_pe.c +3 -4
@@ -431,10 +398,9 @@ int eeh_pe_tree_insert(struct eeh_dev *edev)
 	 * to PHB directly. Otherwise, we have to associate the
 	 * PE with its parent.
 	 */
-	parent = eeh_pe_get_parent(edev);
-	if (!parent) {
-		parent = eeh_phb_pe_get(hose);
-		if (!parent) {
+	if (!new_pe_parent) {
+		new_pe_parent = eeh_phb_pe_get(hose);
+		if (!new_pe_parent) {

afaict only pseries can realisticly pass new_pe_parent==NULL so this chunk could go to pseries_eeh_pe_get_parent.

Quoted 120 lines
arch/powerpc/kernel/eeh_pe.c +6 -4
 			pr_err("%s: No PHB PE is found (PHB Domain=%d)\n",
 				__func__, hose->global_number);
 			edev->pe = NULL;
@@ -442,17 +408,19 @@ int eeh_pe_tree_insert(struct eeh_dev *edev)
 			return -EEXIST;
 		}
 	}
-	pe->parent = parent;
+
+	/* link new PE into the tree */
+	pe->parent = new_pe_parent;
+	list_add_tail(&pe->child, &new_pe_parent->child_list);
 
 	/*
 	 * Put the newly created PE into the child list and
 	 * link the EEH device accordingly.
 	 */
-	list_add_tail(&pe->child, &parent->child_list);
 	list_add_tail(&edev->entry, &pe->edevs);
 	edev->pe = pe;
-	eeh_edev_dbg(edev, "Added to device PE (parent: PE#%x)\n",
-		     pe->parent->addr);
+	eeh_edev_dbg(edev, "Added to new (parent: PE#%x)\n",
+		     new_pe_parent->addr);
 
 	return 0;
 }
arch/powerpc/platforms/powernv/eeh-powernv.c +26 -1
index 8c9fca773692..9af8c3b98853 100644
@@ -338,6 +338,28 @@ static int pnv_eeh_find_ecap(struct pci_dn *pdn, int cap)
 	return 0;
 }
 
+static struct eeh_pe *pnv_eeh_get_upstream_pe(struct pci_dev *pdev)
+{
+	struct pci_controller *hose = pdev->bus->sysdata;
+	struct pnv_phb *phb = hose->private_data;
+	struct pci_dev *parent = pdev->bus->self;
+
+#ifdef CONFIG_PCI_IOV
+	/* for VFs we use the PF's PE as the upstream PE */
+	if (pdev->is_virtfn)
+		parent = pdev->physfn;
+#endif
+
+	/* otherwise use the PE of our parent bridge */
+	if (parent) {
+		struct pnv_ioda_pe *ioda_pe = pnv_ioda_get_pe(parent);
+
+		return eeh_pe_get(phb->hose, ioda_pe->pe_number, 0);
+	}
+
+	return NULL;
+}
+
 /**
  * pnv_eeh_probe - Do probe on PCI device
  * @pdev: pci_dev to probe
@@ -350,6 +372,7 @@ static struct eeh_dev *pnv_eeh_probe(struct pci_dev *pdev)
 	struct pci_controller *hose = pdn->phb;
 	struct pnv_phb *phb = hose->private_data;
 	struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
+	struct eeh_pe *upstream_pe;
 	uint32_t pcie_flags;
 	int ret;
 	int config_addr = (pdn->busno << 8) | (pdn->devfn);
@@ -398,8 +421,10 @@ static struct eeh_dev *pnv_eeh_probe(struct pci_dev *pdev)
 
 	edev->pe_config_addr = phb->ioda.pe_rmap[config_addr];
 
+	upstream_pe = pnv_eeh_get_upstream_pe(pdev);
+
 	/* Create PE */
-	ret = eeh_pe_tree_insert(edev);
+	ret = eeh_pe_tree_insert(edev, upstream_pe);
 	if (ret) {
 		eeh_edev_warn(edev, "Failed to add device to PE (code %d)\n", ret);
 		return NULL;
arch/powerpc/platforms/pseries/eeh_pseries.c +20 -1
index 72556f4436a8..98f9a1b269be 100644
@@ -68,11 +68,16 @@ void pseries_pcibios_bus_add_device(struct pci_dev *pdev)
 	pseries_eeh_init_edev(pdn);
 #ifdef CONFIG_PCI_IOV
 	if (pdev->is_virtfn) {
+		/*
+		 * FIXME: This really should be handled by choosing the right
+		 *        parent PE in in pseries_eeh_init_edev().
+		 */
+		struct eeh_pe *physfn_pe = pci_dev_to_eeh_dev(pdev->physfn)->pe;
 		struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
 
 		edev->pe_config_addr =  (pdn->busno << 16) | (pdn->devfn << 8);
 		eeh_pe_tree_remove(edev); /* Remove as it is adding to bus pe */
-		eeh_pe_tree_insert(edev);   /* Add as VF PE type */
+		eeh_pe_tree_insert(edev, physfn_pe);   /* Add as VF PE type */
 	}
 #endif
 	eeh_probe_device(pdev);
@@ -218,6 +223,43 @@ static int pseries_eeh_find_ecap(struct pci_dn *pdn, int cap)
 	return 0;
 }
 
+/**
+ * pseries_eeh_pe_get_parent - Retrieve the parent PE
+ * @edev: EEH device
+ *
+ * The whole PEs existing in the system are organized as hierarchy
+ * tree. The function is used to retrieve the parent PE according
+ * to the parent EEH device.
+ */
+static struct eeh_pe *pseries_eeh_pe_get_parent(struct eeh_dev *edev)
+{
+	struct eeh_dev *parent;
+	struct pci_dn *pdn = eeh_dev_to_pdn(edev);
+
+	/*

arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_eeh_find_ecap(struct pci_dn *pdn, int cap) · line 249

Quoted 10 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +10 -0
+	 * It might have the case for the indirect parent
+	 * EEH device already having associated PE, but
+	 * the direct parent EEH device doesn't have yet.
+	 */
+	if (edev->physfn)
+		pdn = pci_get_pdn(edev->physfn);
+	else
+		pdn = pdn ? pdn->parent : NULL;
+	while (pdn) {
+		/* We're poking out of PCI territory */

We are traversing up PCI hierarchy here - pci_dn->parent, how is this out of PCI territory? Or I understand "out of" incorrectly?

Quoted 26 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +15 -0
+		parent = pdn_to_eeh_dev(pdn);
+		if (!parent)
+			return NULL;
+
+		if (parent->pe)
+			return parent->pe;
+
+		pdn = pdn->parent;
+	}
+
+	return NULL;
+}
+
 /**
  * pseries_eeh_init_edev - initialise the eeh_dev and eeh_pe for a pci_dn
  *
@@ -301,6 +343,8 @@ void pseries_eeh_init_edev(struct pci_dn *pdn)
 	if (ret) {
 		eeh_edev_dbg(edev, "EEH failed to enable on device (code %d)\n", ret);
 	} else {
+		struct eeh_pe *parent;
+
 		/* Retrieve PE address */
 		edev->pe_config_addr = pseries_eeh_get_pe_addr(pdn);
 		pe.addr = edev->pe_config_addr;

arch/powerpc/platforms/pseries/eeh_pseries.c void pseries_eeh_init_edev(struct pci_dn *pdn) · line 365

Quoted 10 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +6 -1
@@ -313,16 +357,23 @@ void pseries_eeh_init_edev(struct pci_dn *pdn)
 		if (ret > 0 && ret != EEH_STATE_NOT_SUPPORT)
 			enable = 1;
 
-		if (enable) {
+		/* This device doesn't support EEH, but it may have an
+		 * EEH parent, in which case we mark it as supported.
+		 */
+		parent = pseries_eeh_pe_get_parent(edev);
+		if (parent && !enable)
+			edev->pe_config_addr = parent->addr;

What if pseries_eeh_pe_get_parent() returned NULL - we won't write edev->pe_config_addr so it remains 0 which is fine just by accident? :)

I'd make pseries_eeh_pe_get_parent() always return not NULL (a parent or a hose) and simplify the block below.

I mean the change is alright but part of the excersise is making the code more readable but there also can go forever :) so

Quoted 17 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +4 -2
+
+		if (enable || parent) {
 			eeh_add_flag(EEH_ENABLED);
-			eeh_pe_tree_insert(edev);
+			eeh_pe_tree_insert(edev, parent);
 		} else if (pdn->parent && pdn_to_eeh_dev(pdn->parent) &&
 			   (pdn_to_eeh_dev(pdn->parent))->pe) {
 			/* This device doesn't support EEH, but it may have an
 			 * EEH parent, in which case we mark it as supported.
 			 */
 			edev->pe_config_addr = pdn_to_eeh_dev(pdn->parent)->pe_config_addr;
-			eeh_pe_tree_insert(edev);
+			eeh_pe_tree_insert(edev, parent);
 		}
 		eeh_edev_dbg(edev, "EEH is %s on device (code %d)\n",
 			     (enable ? "enabled" : "unsupported"), ret);
Signature · 1 line
Alexey
author reviewer
#25 lore raw

Re: [PATCH 14/14] powerpc/eeh: Move PE tree setup into the platform

Quoted 21 lines · Alexey Kardashevskiy
Quoted 19 lines · Oliver O'Halloran

/**
* eeh_pe_tree_insert - Add EEH device to parent PE
* @edev: EEH device
+ * @new_pe_parent: PE to create additional PEs under
*
- * Add EEH device to the parent PE. If the parent PE already
- * exists, the PE type will be changed to EEH_PE_BUS. Otherwise,
- * we have to create new PE to hold the EEH device and the new
- * PE will be linked to its parent PE as well.
+ * Add EEH device to the PE in edev->pe_config_addr. If a PE already
+ * exists with that address then @edev is added to that PE. Otherwise
+ * a new PE is created and inserted into the PE tree as a child of
+ * @new_pe_parent.
+ *
+ * If @new_pe_parent is NULL then the new PE will be inserted under
+ * directly under the the PHB.
*/

arch/powerpc/kernel/eeh_pe.c +1 -1
-int eeh_pe_tree_insert(struct eeh_dev *edev)
+int eeh_pe_tree_insert(struct eeh_dev *edev, struct eeh_pe *new_pe_parent)
Quoted 8 lines
Quoted 3 lines
 {
      struct pci_controller *hose = edev->controller;
      struct eeh_pe *pe, *parent;

We can ditch this "parent" in that single place now and use "pe" instead. And name the new parameter simply "parent". Dunno if it improves things though.

I did this at some point and then decided not to. It added a bunch of noise to the diff and calling the parameter "parent" ended up being pretty unreadable. The parameter is "the parent of the PE that will be created to contain edev", or "parent of the parent PE". It's pretty unwieldy.

Quoted 17 lines
Quoted 17 lines
arch/powerpc/kernel/eeh_pe.c +1 -5
@@ -399,7 +366,7 @@ int eeh_pe_tree_insert(struct eeh_dev *edev)
                      }
 
                      eeh_edev_dbg(edev,
-                                  "Added to device PE (parent: PE#%x)\n",
+                                  "Added to existing PE (parent: PE#%x)\n",
                                   pe->parent->addr);
              } else {
                      /* Mark the PE as type of PCI bus */
@@ -431,10 +398,9 @@ int eeh_pe_tree_insert(struct eeh_dev *edev)
       * to PHB directly. Otherwise, we have to associate the
       * PE with its parent.
       */
-     parent = eeh_pe_get_parent(edev);
-     if (!parent) {
-             parent = eeh_phb_pe_get(hose);
-             if (!parent) {
Quoted 8 lines

arch/powerpc/kernel/eeh_pe.c int eeh_pe_tree_insert(struct eeh_dev *edev) · line 403

Quoted 3 lines
arch/powerpc/kernel/eeh_pe.c +3 -0
+     if (!new_pe_parent) {
+             new_pe_parent = eeh_phb_pe_get(hose);
+             if (!new_pe_parent) {

afaict only pseries can realisticly pass new_pe_parent==NULL so this chunk could go to pseries_eeh_pe_get_parent.

pnv_eeh_get_upstream_pe() will never return the PHB PE so new_pe_parent will be NULL for the first PE created under a PowerNV PHB. I guess we could move the PHB PE handling into the platform too, but I think that just results in having to special case PHB PEs in two places rather than one.

Quoted 12 lines
Quoted 12 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +12 -0
+static struct eeh_pe *pseries_eeh_pe_get_parent(struct eeh_dev *edev)
+{
+     struct eeh_dev *parent;
+     struct pci_dn *pdn = eeh_dev_to_pdn(edev);
+
+     /*
+      * It might have the case for the indirect parent
+      * EEH device already having associated PE, but
+      * the direct parent EEH device doesn't have yet.
+      */
+     if (edev->physfn)
+             pdn = pci_get_pdn(edev->physfn);
Quoted 13 lines

arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_eeh_find_ecap(struct pci_dn *pdn, int cap) · line 249

Quoted 4 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +4 -0
+     else
+             pdn = pdn ? pdn->parent : NULL;
+     while (pdn) {
+             /* We're poking out of PCI territory */

We are traversing up PCI hierarchy here - pci_dn->parent, how is this out of PCI territory? Or I understand "out of" incorrectly?

Quoted 3 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +3 -0
+             parent = pdn_to_eeh_dev(pdn);
+             if (!parent)
+                     return NULL;

If there's no eeh dev then the node we're looking at is a PHB rather than an actual PCI device so it stops looking. I think. The comment was copied over from the existing code and I haven't spent a whole lot of time parsing it's meaning.

Quoted 13 lines
Quoted 13 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +2 -0
@@ -301,6 +343,8 @@ void pseries_eeh_init_edev(struct pci_dn *pdn)
      if (ret) {
              eeh_edev_dbg(edev, "EEH failed to enable on device (code %d)\n", ret);
      } else {
+             struct eeh_pe *parent;
+
              /* Retrieve PE address */
              edev->pe_config_addr = pseries_eeh_get_pe_addr(pdn);
              pe.addr = edev->pe_config_addr;
@@ -313,16 +357,23 @@ void pseries_eeh_init_edev(struct pci_dn *pdn)
              if (ret > 0 && ret != EEH_STATE_NOT_SUPPORT)
                      enable = 1;
 
Quoted 11 lines

arch/powerpc/platforms/pseries/eeh_pseries.c void pseries_eeh_init_edev(struct pci_dn *pdn) · line 365

Quoted 7 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +6 -1
-             if (enable) {
+             /* This device doesn't support EEH, but it may have an
+              * EEH parent, in which case we mark it as supported.
+              */
+             parent = pseries_eeh_pe_get_parent(edev);
+             if (parent && !enable)
+                     edev->pe_config_addr = parent->addr;

What if pseries_eeh_pe_get_parent() returned NULL - we won't write edev->pe_config_addr so it remains 0 which is fine just by accident? :)

edev->pe_config_addr is set above when we call pseries_eeh_get_pe_addr(). The check there is mainly to cover the case where pseries_eeh_get_pe_addr() fails because the device is on a subordinate bus rather than the root bus of the PE. PAPR says the get-pe-addr-info RTAS call can fail in that situation and that you're supposed to traverse up the DT to find the pe_config_addr, which is what pe_get_parent() does. Yeah it's confusing, but that's what it does today too.

Quoted 16 lines
Quoted 14 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +4 -2
+
+             if (enable || parent) {
                      eeh_add_flag(EEH_ENABLED);
-                     eeh_pe_tree_insert(edev);
+                     eeh_pe_tree_insert(edev, parent);
 
              } else if (pdn->parent && pdn_to_eeh_dev(pdn->parent) &&
                         (pdn_to_eeh_dev(pdn->parent))->pe) {
                      /* This device doesn't support EEH, but it may have an
                       * EEH parent, in which case we mark it as supported.
                       */
                      edev->pe_config_addr = pdn_to_eeh_dev(pdn->parent)->pe_config_addr;
-                     eeh_pe_tree_insert(edev);
+                     eeh_pe_tree_insert(edev, parent);

I think I was supposed to delete this hunk and then forgot to since it handles the same case mentioned above.

Quoted 7 lines
Quoted 4 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +0 -0
              }
              eeh_edev_dbg(edev, "EEH is %s on device (code %d)\n",
                           (enable ? "enabled" : "unsupported"), ret);

--
Alexey

#26 lore raw

Re: [PATCH 14/14] powerpc/eeh: Move PE tree setup into the platform

Quoted 31 lines · Oliver O'Halloran
Quoted 21 lines · Alexey Kardashevskiy
Quoted 19 lines · Oliver O'Halloran

/**
* eeh_pe_tree_insert - Add EEH device to parent PE
* @edev: EEH device
+ * @new_pe_parent: PE to create additional PEs under
*
- * Add EEH device to the parent PE. If the parent PE already
- * exists, the PE type will be changed to EEH_PE_BUS. Otherwise,
- * we have to create new PE to hold the EEH device and the new
- * PE will be linked to its parent PE as well.
+ * Add EEH device to the PE in edev->pe_config_addr. If a PE already
+ * exists with that address then @edev is added to that PE. Otherwise
+ * a new PE is created and inserted into the PE tree as a child of
+ * @new_pe_parent.
+ *
+ * If @new_pe_parent is NULL then the new PE will be inserted under
+ * directly under the the PHB.
*/

arch/powerpc/kernel/eeh_pe.c +1 -1
-int eeh_pe_tree_insert(struct eeh_dev *edev)
+int eeh_pe_tree_insert(struct eeh_dev *edev, struct eeh_pe *new_pe_parent)
Quoted 8 lines
Quoted 3 lines
 {
      struct pci_controller *hose = edev->controller;
      struct eeh_pe *pe, *parent;

We can ditch this "parent" in that single place now and use "pe" instead. And name the new parameter simply "parent". Dunno if it improves things though.

Quoted 5 lines

I did this at some point and then decided not to. It added a bunch of noise to the diff and calling the parameter "parent" ended up being pretty unreadable. The parameter is "the parent of the PE that will be created to contain edev", or "parent of the parent PE". It's pretty unwieldy.

Ok fine but we still do not need both pe and parent in that function (may be one day...).

Quoted 55 lines
Quoted 18 lines
Quoted 18 lines
arch/powerpc/kernel/eeh_pe.c +1 -5
@@ -399,7 +366,7 @@ int eeh_pe_tree_insert(struct eeh_dev *edev)
                      }
 
                      eeh_edev_dbg(edev,
-                                  "Added to device PE (parent: PE#%x)\n",
+                                  "Added to existing PE (parent: PE#%x)\n",
                                   pe->parent->addr);
              } else {
                      /* Mark the PE as type of PCI bus */
@@ -431,10 +398,9 @@ int eeh_pe_tree_insert(struct eeh_dev *edev)
       * to PHB directly. Otherwise, we have to associate the
       * PE with its parent.
       */
-     parent = eeh_pe_get_parent(edev);
-     if (!parent) {
-             parent = eeh_phb_pe_get(hose);
-             if (!parent) {
Quoted 8 lines

arch/powerpc/kernel/eeh_pe.c int eeh_pe_tree_insert(struct eeh_dev *edev) · line 403

Quoted 3 lines
arch/powerpc/kernel/eeh_pe.c +3 -0
+     if (!new_pe_parent) {
+             new_pe_parent = eeh_phb_pe_get(hose);
+             if (!new_pe_parent) {

afaict only pseries can realisticly pass new_pe_parent==NULL so this chunk could go to pseries_eeh_pe_get_parent.

pnv_eeh_get_upstream_pe() will never return the PHB PE so new_pe_parent will be NULL for the first PE created under a PowerNV PHB. I guess we could move the PHB PE handling into the platform too, but I think that just results in having to special case PHB PEs in two places rather than one.

Quoted 22 lines
Quoted 6 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +6 -0
+static struct eeh_pe *pseries_eeh_pe_get_parent(struct eeh_dev *edev)
+{
+     struct eeh_dev *parent;
+     struct pci_dn *pdn = eeh_dev_to_pdn(edev);
+
+     /*

arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_eeh_find_ecap(struct pci_dn *pdn, int cap) · line 249

Quoted 10 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +10 -0
+      * It might have the case for the indirect parent
+      * EEH device already having associated PE, but
+      * the direct parent EEH device doesn't have yet.
+      */
+     if (edev->physfn)
+             pdn = pci_get_pdn(edev->physfn);
+     else
+             pdn = pdn ? pdn->parent : NULL;
+     while (pdn) {
+             /* We're poking out of PCI territory */

We are traversing up PCI hierarchy here - pci_dn->parent, how is this out of PCI territory? Or I understand "out of" incorrectly?

Quoted 8 lines
Quoted 3 lines

arch/powerpc/platforms/pseries/eeh_pseries.c static int pseries_eeh_find_ecap(struct pci_dn *pdn, int cap) · line 252

Quoted 3 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +3 -0
+             parent = pdn_to_eeh_dev(pdn);
+             if (!parent)
+                     return NULL;

If there's no eeh dev then the node we're looking at is a PHB rather than an actual PCI device so it stops looking. I think. The comment was copied over from the existing code and I haven't spent a whole lot of time parsing it's meaning.

I noticed cut-n-paste. May be just ditch it if nobody can parse it?

Quoted 54 lines
Quoted 16 lines
Quoted 16 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +2 -0
@@ -301,6 +343,8 @@ void pseries_eeh_init_edev(struct pci_dn *pdn)
      if (ret) {
              eeh_edev_dbg(edev, "EEH failed to enable on device (code %d)\n", ret);
      } else {
+             struct eeh_pe *parent;
+
              /* Retrieve PE address */
              edev->pe_config_addr = pseries_eeh_get_pe_addr(pdn);
              pe.addr = edev->pe_config_addr;
@@ -313,16 +357,23 @@ void pseries_eeh_init_edev(struct pci_dn *pdn)
              if (ret > 0 && ret != EEH_STATE_NOT_SUPPORT)
                      enable = 1;
 
Quoted 11 lines

arch/powerpc/platforms/pseries/eeh_pseries.c void pseries_eeh_init_edev(struct pci_dn *pdn) · line 365

Quoted 7 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +6 -1
-             if (enable) {
+             /* This device doesn't support EEH, but it may have an
+              * EEH parent, in which case we mark it as supported.
+              */
+             parent = pseries_eeh_pe_get_parent(edev);
+             if (parent && !enable)
+                     edev->pe_config_addr = parent->addr;

What if pseries_eeh_pe_get_parent() returned NULL - we won't write edev->pe_config_addr so it remains 0 which is fine just by accident? :)

edev->pe_config_addr is set above when we call pseries_eeh_get_pe_addr(). The check there is mainly to cover the case where pseries_eeh_get_pe_addr() fails because the device is on a subordinate bus rather than the root bus of the PE. PAPR says the get-pe-addr-info RTAS call can fail in that situation and that you're supposed to traverse up the DT to find the pe_config_addr, which is what pe_get_parent() does. Yeah it's confusing, but that's what it does today too.

Quoted 16 lines
Quoted 14 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +4 -2
+
+             if (enable || parent) {
                      eeh_add_flag(EEH_ENABLED);
-                     eeh_pe_tree_insert(edev);
+                     eeh_pe_tree_insert(edev, parent);
 
              } else if (pdn->parent && pdn_to_eeh_dev(pdn->parent) &&
                         (pdn_to_eeh_dev(pdn->parent))->pe) {
                      /* This device doesn't support EEH, but it may have an
                       * EEH parent, in which case we mark it as supported.
                       */
                      edev->pe_config_addr = pdn_to_eeh_dev(pdn->parent)->pe_config_addr;
-                     eeh_pe_tree_insert(edev);
+                     eeh_pe_tree_insert(edev, parent);
Quoted 2 lines

I think I was supposed to delete this hunk and then forgot to since it handles the same case mentioned above.

A-ha!

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
arch/powerpc/platforms/pseries/eeh_pseries.c +0 -0
              }
              eeh_edev_dbg(edev, "EEH is %s on device (code %d)\n",
                           (enable ? "enabled" : "unsupported"), ret);

--
Alexey

Signature · 1 line
Alexey