Skip to contentSkip to conversation

VF EEH on Power8

PATCH Superseded Wei Yang 2 participants 14 messages Nov 4, 2015

Subsystems (3)

v12 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

v12 cover VF EEH on Power8

This patchset enables EEH on SRIOV VFs. The general idea is to create proper VF edev and VF PE and handle them properly.

Different from the Bus PE, VF PE just contain one VF. This introduces the difference of EEH error handling on a VF PE. Generally, it has several differences.

First, the VF's removal and re-enumerate rely on its PF. VF has a tight relationship between its PF. This is not proper to enumerate a VF by usual scan procedure. That's why virtfn_add/virtfn_remove are exported in this patch set.

Second, the reset/restore of a VF is done in kernel space. FW is not aware of the VF, this means the usual reset function done in FW will not work. One of the patch will imitate the reset/restore function in kernel space.

Third, the VF may be removed during the PF's error_detected function. In this case, the original error_detected->slot_reset->resume sequence is not proper to those removed VFs, since they are re-created by PF in a fresh state. A flag in eeh_dev is introduce to mark the eeh_dev is in error state. By doing so, we track whether this device needs to be reset or not.

This has been tested both on host and in guest on Power8 with latest kernel version.

v12:
* rebased on v4.3
* Rephrase some commit log to make it more clear and specific
* move vf_index assignment in CONFIG_PPC_POWERNV
* merge "Cache VF index in pci_dn" with "Support error recovery for VF PE"
* check the return value after eeh_dev_init() for VF
* initialize the parameter before pass to read_config()
* make pnv_pci_fixup_vf_mps() a dedicated patch, which fixup and store mps value in pci_dn
v11:
* move vf_index assignment in marco CONFIG_PPC_POWERNV
* merge Patch "Cache VF index in pci_dn" into Patch "Support error recovery for VF PE"
v10:
* rebased on v4.2
* delete the last patch "powerpc/powernv: compound PE for VFs" since after redesign of SRIOV, there is no compound PE for VFs now.
* add two patches which fix problems found during tests powerpc/eeh: Support error recovery for VF PE
powerpc/eeh: Handle hot removed VF when PF is EEH aware
v9:
* split pcibios_bus_add_device() into a separate patch
* Bjorn acked the PCI part and agreed this patch set to be merged from ppc tree
* rebased on mpe/linux.git next branch
v8:
* fix on checking the return value of pnv_eeh_do_flr()
* introduced a weak function pcibios_bus_add_device() to create PE for VFs
v7:
* fix compile error when PCI_IOV is not set
v6:
* code / commit log refactor by Gavin
v5:
* remove the compound field, iterate on Master VF PE instead
* some code refine on PCI config restore and reset on VF
the wait time for assert and deassert
PCI device address format
check on edev->pcie_cap and edev->aer_cap before access them
v4:
* refine the change logs, comment and code style
* change pnv_pci_fixup_vf_eeh() to pnv_eeh_vf_final_fixup() and remove the CONFIG_PCI_IOV macro
* reorder patch 5/6 to make the logic more reasonable
* remove remove_dev_pci_data()
* remove the EEH_DEV_VF flag, use edev->physfn to identify a VF EEH DEV and remove related CONFIG_PCI_IOV macro
* add the option for VF reset
* fix the pnv_eeh_cfg_blocked() logic
* replace pnv_pci_cfg_{read,write} with eeh_ops->{read,write}_config in pnv_eeh_vf_restore_config()
* rename pnv_eeh_vf_restore_config() to pnv_eeh_restore_vf_config()
* rename pnv_pci_fixup_vf_caps() to pnv_pci_vf_header_fixup() and move it to arch/powerpc/platforms/powernv/pci.c
* add a field compound in pnv_ioda_pe to link compound PEs
* handle compound PE for VF PEs
v3:
* add back vf_index in pci_dn to track the VF's index
* rename ppdev in eeh_dev to physfn for consistency
* move edev->physfn assignment before dev->dev.archdata.edev is set
* move pnv_pci_fixup_vf_eeh() and pnv_pci_fixup_vf_caps() to eeh-powernv.c
* more clear and detail in commit log and comment in code
* merge eeh_rmv_virt_device() with eeh_rmv_device()
* move the cfg_blocked check logic from pnv_eeh_read/write_config() to pnv_eeh_cfg_blocked()
* move the vf reset/restore logic into its own patch, two patches are created.
powerpc/powernv: Support PCI config restore for VFs powerpc/powernv: Support EEH reset for VFs
* simplify the vf reset logic
v2:
* add prefix pci_iov_ to virtfn_add/virtfn_remove
* use EEH_DEV_VF as a flag for a VF's eeh_dev
* use eeh_dev instead of edev in change log
* remove vf_index in eeh_dev, calculate it from pdn->busno and devfn
* do eeh_add_device_late() and eeh_sysfs_add_device() both after pci_dev is well initialized
* do FLR to reset a VF PE
* imitate the restore function in FW for VF
* remove the reverse order patch, since it is still under discussion

Wei Yang (9):
PCI/IOV: Rename and export virtfn_add/virtfn_remove
PCI: Add pcibios_bus_add_device() weak function powerpc/pci: Remove VFs prior to PF powerpc/eeh: Cache only BARs, not windows or IOV BARs powerpc/powernv: EEH device for VF powerpc/eeh: Create PE for VFs powerpc/powernv: Support EEH reset for VF PE powerpc/powernv: Support PCI config restore for VFs powerpc/eeh: Support error recovery for VF PE

 arch/powerpc/include/asm/eeh.h               |  10 ++
 arch/powerpc/include/asm/pci-bridge.h        |   2 +
 arch/powerpc/kernel/eeh.c                    |  17 ++-
 arch/powerpc/kernel/eeh_cache.c              |  11 +-
 arch/powerpc/kernel/eeh_dev.c                |   1 +
 arch/powerpc/kernel/eeh_driver.c             | 127 ++++++++++++----
 arch/powerpc/kernel/eeh_pe.c                 |  13 +-
 arch/powerpc/kernel/pci-hotplug.c            |   2 +-
 arch/powerpc/kernel/pci_dn.c                 |  17 ++-
 arch/powerpc/platforms/powernv/eeh-powernv.c | 219 ++++++++++++++++++++++++++-
 arch/powerpc/platforms/powernv/pci.c         |  18 +++
 drivers/pci/bus.c                            |   3 +
 drivers/pci/iov.c                            |  10 +-
 include/linux/pci.h                          |   8 +
 14 files changed, 411 insertions(+), 47 deletions(-)
Signature · 1 line
2.5.0
author
#1 lore raw

PATCH v12 1/9 PCI/IOV: Rename and export virtfn_add/virtfn_remove

During EEH recovery, hotplug is applied to the devices which don't have drivers or their drivers don't support EEH. However, the hotplug, which was implemented based on PCI bus, can't be applied to VF directly.

Rename virtn_{add,remove}() and export them so they can be used in PCI hotplug during EEH recovery.

---
 drivers/pci/iov.c   | 10 +++++-----
 include/linux/pci.h |  8 ++++++++
 2 files changed, 13 insertions(+), 5 deletions(-)
drivers/pci/iov.c +5 -5
index ee0ebff..cc941dd 100644
@@ -108,7 +108,7 @@ resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno)
 	return dev->sriov->barsz[resno - PCI_IOV_RESOURCES];
 }
 
-static int virtfn_add(struct pci_dev *dev, int id, int reset)
+int pci_iov_virtfn_add(struct pci_dev *dev, int id, int reset)
 {
 	int i;
 	int rc = -ENOMEM;
@@ -183,7 +183,7 @@ failed:
 	return rc;
 }
 
-static void virtfn_remove(struct pci_dev *dev, int id, int reset)
+void pci_iov_virtfn_remove(struct pci_dev *dev, int id, int reset)
 {
 	char buf[VIRTFN_ID_LEN];
 	struct pci_dev *virtfn;
@@ -320,7 +320,7 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
 	}
 
 	for (i = 0; i < initial; i++) {
-		rc = virtfn_add(dev, i, 0);
+		rc = pci_iov_virtfn_add(dev, i, 0);
 		if (rc)
 			goto failed;
 	}
@@ -332,7 +332,7 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
 
 failed:
 	for (j = 0; j < i; j++)
-		virtfn_remove(dev, j, 0);
+		pci_iov_virtfn_remove(dev, j, 0);
 
 	iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE);
 	pci_cfg_access_lock(dev);
@@ -361,7 +361,7 @@ static void sriov_disable(struct pci_dev *dev)
 		return;
 
 	for (i = 0; i < iov->num_VFs; i++)
-		virtfn_remove(dev, i, 0);
+		pci_iov_virtfn_remove(dev, i, 0);
 
 	pcibios_sriov_disable(dev);
 
include/linux/pci.h +8 -0
index e90eb22..3628a09 100644
@@ -1719,6 +1719,8 @@ int pci_iov_virtfn_devfn(struct pci_dev *dev, int id);
 
 int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn);
 void pci_disable_sriov(struct pci_dev *dev);
+int pci_iov_virtfn_add(struct pci_dev *dev, int id, int reset);
+void pci_iov_virtfn_remove(struct pci_dev *dev, int id, int reset);
 int pci_num_vf(struct pci_dev *dev);
 int pci_vfs_assigned(struct pci_dev *dev);
 int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
@@ -1736,6 +1738,12 @@ static inline int pci_iov_virtfn_devfn(struct pci_dev *dev, int id)
 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
 { return -ENODEV; }
 static inline void pci_disable_sriov(struct pci_dev *dev) { }
+static inline int pci_iov_virtfn_add(struct pci_dev *dev, int id, int reset)
+{
+	return -ENOSYS;
+}
+static inline void pci_iov_virtfn_remove(struct pci_dev *dev, int id, int reset)
+{ }
 static inline int pci_num_vf(struct pci_dev *dev) { return 0; }
 static inline int pci_vfs_assigned(struct pci_dev *dev)
 { return 0; }
Signature · 1 line
2.5.0
author
#2 lore raw

PATCH v12 2/9 PCI: Add pcibios_bus_add_device() weak function

In reply to Wei Yang

Add a weak function pcibios_bus_add_device() for arch dependent code could do proper setup. For example, powerpc could setup EEH related resources.

---
 drivers/pci/bus.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pci/bus.c +3 -0
index d3346d2..2b8b756 100644
@@ -269,6 +269,7 @@ bool pci_bus_clip_resource(struct pci_dev *dev, int idx)
 
 void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { }
 
+void __weak pcibios_bus_add_device(struct pci_dev *dev) { }
 /**
  * pci_bus_add_device - start driver for a single device
  * @dev: device to add
@@ -279,6 +280,8 @@ void pci_bus_add_device(struct pci_dev *dev)
 {
 	int retval;
 
+	pcibios_bus_add_device(dev);
+
 	/*
 	 * Can not put in pci_device_add yet because resources
 	 * are not assigned yet for some devices.
Signature · 1 line
2.5.0
author
#3 lore raw

PATCH v12 3/9 powerpc/pci: Remove VFs prior to PF

In reply to Wei Yang

As commit ac205b7bb72f ("PCI: make sriov work with hotplug remove") indicates, VFs which is on the same PCI bus as their PF, should be removed before the PF. Otherwise, the PCI hot unplugging of PCI devices on the PCI bus would cause kernel crash.

The patch applies the above pattern to PowerPC PCI hotplug path.

---
 arch/powerpc/kernel/pci-hotplug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/pci-hotplug.c +1 -1
index 7f9ed0c..59c4361 100644
@@ -55,7 +55,7 @@ void pcibios_remove_pci_devices(struct pci_bus *bus)
 
 	pr_debug("PCI: Removing devices on bus %04x:%02x\n",
 		 pci_domain_nr(bus),  bus->number);
-	list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) {
+	list_for_each_entry_safe_reverse(dev, tmp, &bus->devices, bus_list) {
 		pr_debug("   Removing %s...\n", pci_name(dev));
 		pci_stop_and_remove_bus_device(dev);
 	}
Signature · 1 line
2.5.0
author
#4 lore raw

PATCH v12 4/9 powerpc/eeh: Cache only BARs, not windows or IOV BARs

In reply to Wei Yang

This restricts the EEH address cache to use only the first 7 BARs. This makes __eeh_addr_cache_insert_dev() ignore PCI bridge window and IOV BARs. As the result of this change, eeh_addr_cache_get_dev() will return VFs from VF's resource addresses instead of parent PFs.

This removes extra check for a PCI bridge as we limit __eeh_addr_cache_insert_dev() to 7 BARs and this effectively excludes PCI bridges from being cached.

---
 arch/powerpc/kernel/eeh_cache.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
arch/powerpc/kernel/eeh_cache.c +5 -6
index a1e86e1..ddbcfab 100644
@@ -195,8 +195,11 @@ static void __eeh_addr_cache_insert_dev(struct pci_dev *dev)
 		return;
 	}
 
-	/* Walk resources on this device, poke them into the tree */
-	for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
+	/*
+	 * Walk resources on this device, poke the first 7 (6 normal BAR and 1
+	 * ROM BAR) into the tree.
+	 */
+	for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
 		resource_size_t start = pci_resource_start(dev,i);
 		resource_size_t end = pci_resource_end(dev,i);
 		unsigned long flags = pci_resource_flags(dev,i);
@@ -222,10 +225,6 @@ void eeh_addr_cache_insert_dev(struct pci_dev *dev)
 {
 	unsigned long flags;
 
-	/* Ignore PCI bridges */
-	if ((dev->class >> 16) == PCI_BASE_CLASS_BRIDGE)
-		return;
-
 	spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
 	__eeh_addr_cache_insert_dev(dev);
 	spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
Signature · 1 line
2.5.0
author
#5 lore raw

PATCH v12 5/9 powerpc/powernv: EEH device for VF

In reply to Wei Yang

VFs and their corresponding pci_dn instances are created and released dynamically as their PF's SRIOV capability is enabled and disabled. The patch creates and releases EEH devices for VFs when creating and releasing their pci_dn instances, which means EEH devices and pci_dn instances have same life cycle. Also, VF's EEH device is identified by (struct eeh_dev::physfn).

---
 arch/powerpc/include/asm/eeh.h |  1 +
 arch/powerpc/kernel/pci_dn.c   | 13 +++++++++++++
 2 files changed, 14 insertions(+)
arch/powerpc/include/asm/eeh.h +1 -0
index c5eb86f..6c383ad 100644
@@ -140,6 +140,7 @@ struct eeh_dev {
 	struct pci_controller *phb;	/* Associated PHB		*/
 	struct pci_dn *pdn;		/* Associated PCI device node	*/
 	struct pci_dev *pdev;		/* Associated PCI device	*/
+	struct pci_dev *physfn;		/* Associated PF PORT		*/
 	struct pci_bus *bus;		/* PCI bus for partial hotplug	*/
 };
 
arch/powerpc/kernel/pci_dn.c +13 -0
index b3b4df9..5091b05 100644
@@ -178,7 +178,9 @@ static struct pci_dn *add_one_dev_pci_data(struct pci_dn *parent,
 struct pci_dn *add_dev_pci_data(struct pci_dev *pdev)
 {
 #ifdef CONFIG_PCI_IOV
+	struct pci_controller *hose = pci_bus_to_host(pdev->bus);
 	struct pci_dn *parent, *pdn;
+	struct eeh_dev *edev;
 	int i;
 
 	/* Only support IOV for now */
@@ -204,6 +206,10 @@ struct pci_dn *add_dev_pci_data(struct pci_dev *pdev)
 				 __func__, i);
 			return NULL;
 		}
+		eeh_dev_init(pdn, hose);
+		edev = pdn_to_eeh_dev(pdn);
+		BUG_ON(!edev);
+		edev->physfn = pdev;
 	}
 #endif /* CONFIG_PCI_IOV */
 
@@ -252,10 +258,17 @@ void remove_dev_pci_data(struct pci_dev *pdev)
 	for (i = 0; i < pci_sriov_get_totalvfs(pdev); i++) {
 		list_for_each_entry_safe(pdn, tmp,
 			&parent->child_list, list) {
+			struct eeh_dev *edev;
 			if (pdn->busno != pci_iov_virtfn_bus(pdev, i) ||
 			    pdn->devfn != pci_iov_virtfn_devfn(pdev, i))
 				continue;
 
+			edev = pdn_to_eeh_dev(pdn);
+			if (edev) {
+				pdn->edev = NULL;
+				kfree(edev);
+			}
+
 			if (!list_empty(&pdn->list))
 				list_del(&pdn->list);
 
Signature · 1 line
2.5.0
author
#6 lore raw

PATCH v12 6/9 powerpc/eeh: Create PE for VFs

In reply to Wei Yang

The patch creates PEs for VFs in the weak function pcibios_bus_add_device(). Those PEs for VFs are identified with newly introduced flag EEH_PE_VF so that we handle them differently during EEH recovery.

---
 arch/powerpc/include/asm/eeh.h               |  1 +
 arch/powerpc/kernel/eeh_pe.c                 | 10 ++++++++--
 arch/powerpc/platforms/powernv/eeh-powernv.c | 16 ++++++++++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/eeh.h +1 -0
index 6c383ad..ec21f8f 100644
@@ -72,6 +72,7 @@ struct pci_dn;
 #define EEH_PE_PHB	(1 << 1)	/* PHB PE    */
 #define EEH_PE_DEVICE 	(1 << 2)	/* Device PE */
 #define EEH_PE_BUS	(1 << 3)	/* Bus PE    */
+#define EEH_PE_VF	(1 << 4)	/* VF PE     */
 
 #define EEH_PE_ISOLATED		(1 << 0)	/* Isolated PE		*/
 #define EEH_PE_RECOVERING	(1 << 1)	/* Recovering PE	*/
arch/powerpc/kernel/eeh_pe.c +8 -2
index 8654cb1..29240ad 100644
@@ -299,7 +299,10 @@ static struct eeh_pe *eeh_pe_get_parent(struct eeh_dev *edev)
 	 * EEH device already having associated PE, but
 	 * the direct parent EEH device doesn't have yet.
 	 */
-	pdn = pdn ? pdn->parent : NULL;
+	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);
@@ -382,7 +385,10 @@ int eeh_add_to_parent_pe(struct eeh_dev *edev)
 	}
 
 	/* Create a new EEH PE */
-	pe = eeh_pe_alloc(edev->phb, EEH_PE_DEVICE);
+	if (edev->physfn)
+		pe = eeh_pe_alloc(edev->phb, EEH_PE_VF);
+	else
+		pe = eeh_pe_alloc(edev->phb, EEH_PE_DEVICE);
 	if (!pe) {
 		pr_err("%s: out of memory!\n", __func__);
 		return -ENOMEM;
arch/powerpc/platforms/powernv/eeh-powernv.c +16 -0
index 3bb6acb..131c7d0 100644
@@ -1532,6 +1532,22 @@ static struct eeh_ops pnv_eeh_ops = {
 	.restore_config		= pnv_eeh_restore_config
 };
 
+void pcibios_bus_add_device(struct pci_dev *pdev)
+{
+	struct pci_dn *pdn = pci_get_pdn(pdev);
+
+	if (!pdev->is_virtfn)
+		return;
+
+	/*
+	 * The following operations will fail if VF's sysfs files
+	 * aren't created or its resources aren't finalized.
+	 */
+	eeh_add_device_early(pdn);
+	eeh_add_device_late(pdev);
+	eeh_sysfs_add_device(pdev);
+}
+
 /**
  * eeh_powernv_init - Register platform dependent EEH operations
  *
Signature · 1 line
2.5.0
author
#7 lore raw

PATCH v12 7/9 powerpc/powernv: Support EEH reset for VF PE

In reply to Wei Yang

PEs for VFs don't have primary bus. So they have to have their own reset backend, which is used during EEH recovery. The patch implements the reset backend for VF's PE by issuing FLR or AF FLR to the VFs, which are contained in the PE.

---
 arch/powerpc/include/asm/eeh.h               |   1 +
 arch/powerpc/kernel/eeh.c                    |   9 +-
 arch/powerpc/platforms/powernv/eeh-powernv.c | 133 ++++++++++++++++++++++++++-
 3 files changed, 139 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/eeh.h +1 -0
index ec21f8f..331c856 100644
@@ -136,6 +136,7 @@ struct eeh_dev {
 	int pcix_cap;			/* Saved PCIx capability	*/
 	int pcie_cap;			/* Saved PCIe capability	*/
 	int aer_cap;			/* Saved AER capability		*/
+	int af_cap;			/* Saved AF capability		*/
 	struct eeh_pe *pe;		/* Associated PE		*/
 	struct list_head list;		/* Form link list in the PE	*/
 	struct pci_controller *phb;	/* Associated PHB		*/
arch/powerpc/kernel/eeh.c +6 -3
index e968533..41a4b30 100644
@@ -760,7 +760,8 @@ int pcibios_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state stat
 	case pcie_deassert_reset:
 		eeh_ops->reset(pe, EEH_RESET_DEACTIVATE);
 		eeh_unfreeze_pe(pe, false);
-		eeh_pe_state_clear(pe, EEH_PE_CFG_BLOCKED);
+		if (!(pe->type & EEH_PE_VF))
+			eeh_pe_state_clear(pe, EEH_PE_CFG_BLOCKED);
 		eeh_pe_dev_traverse(pe, eeh_restore_dev_state, dev);
 		eeh_pe_state_clear(pe, EEH_PE_ISOLATED);
 		break;
@@ -768,14 +769,16 @@ int pcibios_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state stat
 		eeh_pe_state_mark_with_cfg(pe, EEH_PE_ISOLATED);
 		eeh_ops->set_option(pe, EEH_OPT_FREEZE_PE);
 		eeh_pe_dev_traverse(pe, eeh_disable_and_save_dev_state, dev);
-		eeh_pe_state_mark(pe, EEH_PE_CFG_BLOCKED);
+		if (!(pe->type & EEH_PE_VF))
+			eeh_pe_state_mark(pe, EEH_PE_CFG_BLOCKED);
 		eeh_ops->reset(pe, EEH_RESET_HOT);
 		break;
 	case pcie_warm_reset:
 		eeh_pe_state_mark_with_cfg(pe, EEH_PE_ISOLATED);
 		eeh_ops->set_option(pe, EEH_OPT_FREEZE_PE);
 		eeh_pe_dev_traverse(pe, eeh_disable_and_save_dev_state, dev);
-		eeh_pe_state_mark(pe, EEH_PE_CFG_BLOCKED);
+		if (!(pe->type & EEH_PE_VF))
+			eeh_pe_state_mark(pe, EEH_PE_CFG_BLOCKED);
 		eeh_ops->reset(pe, EEH_RESET_FUNDAMENTAL);
 		break;
 	default:
arch/powerpc/platforms/powernv/eeh-powernv.c +132 -1

157 lines not on this page · raw message

Signature · 1 line
2.5.0
author
#8 lore raw

PATCH v12 8/9 powerpc/powernv: Support PCI config restore for VFs

In reply to Wei Yang

After PE reset, OPAL API opal_pci_reinit() is called on all devices contained in the PE to reinitialize them. While skiboot is not aware of VFs, we have to implement the function in kernel to reinitialize VFs after reset on PE for VFs.

In this patch, two functions pnv_pci_fixup_vf_mps() and pnv_eeh_restore_vf_config() both manipulate the MPS of the VF, since for a VF it has three cases.

1. Normal creation for a VF
In this case, pnv_pci_fixup_vf_mps() is called to make the MPS a proper value compared with its parent.
2. EEH recovery without VF removed
In this case, MPS is stored in pci_dn and pnv_eeh_restore_vf_config() is called to restore it and reinitialize other part.
3. EEH recovery with VF removed
In this case, VF will be removed then re-created. Both functions are called. First pnv_pci_fixup_vf_mps() is called to store the proper MPS to pci_dn and then pnv_eeh_restore_vf_config() is called to do proper thing.

This patch introduces two functions:
pnv_pci_fixup_vf_mps() to fixup the PCI device's MPS to make sure it is smaller than parent's and store this value in pci_dn for future use. pnv_eeh_restore_vf_config() to re-initialize on VF by restore MPS, disable completion timeout, enable SERR, etc.

---
 arch/powerpc/include/asm/pci-bridge.h        |  1 +
 arch/powerpc/platforms/powernv/eeh-powernv.c | 70 +++++++++++++++++++++++++++-
 arch/powerpc/platforms/powernv/pci.c         | 18 +++++++
 3 files changed, 88 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/pci-bridge.h +1 -0
index 843dd3a2..9b365d6 100644
@@ -219,6 +219,7 @@ struct pci_dn {
 #define IODA_INVALID_M64        (-1)
 	int     (*m64_map)[PCI_SRIOV_NUM_BARS];
 #endif /* CONFIG_PCI_IOV */
+	int     mps;			/* Maximum Payload Size */
 #endif
 	struct list_head child_list;
 	struct list_head list;
arch/powerpc/platforms/powernv/eeh-powernv.c +69 -1

82 lines not on this page · raw message

arch/powerpc/platforms/powernv/pci.c +18 -0
index f2dd772..50794d7 100644
@@ -778,6 +778,24 @@ static void pnv_p7ioc_rc_quirk(struct pci_dev *dev)
 }
 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_IBM, 0x3b9, pnv_p7ioc_rc_quirk);
 
+#ifdef CONFIG_PCI_IOV
+static void pnv_pci_fixup_vf_mps(struct pci_dev *pdev)
+{
+	struct pci_dn *pdn = pci_get_pdn(pdev);
+	int parent_mps;
+
+	if (!pdev->is_virtfn)
+		return;
+
+	/* Synchronize MPS for VF and PF */
+	parent_mps = pcie_get_mps(pdev->physfn);
+	if ((128 << pdev->pcie_mpss) >= parent_mps)
+		pcie_set_mps(pdev, parent_mps);
+	pdn->mps = pcie_get_mps(pdev);
+}
+DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pnv_pci_fixup_vf_mps);
+#endif /* CONFIG_PCI_IOV */
+
 void __init pnv_pci_init(void)
 {
 	struct device_node *np;
Signature · 1 line
2.5.0
author
#9 lore raw

PATCH v12 9/9 powerpc/eeh: Support error recovery for VF PE

In reply to Wei Yang

PFs are enumerated on PCI bus, while VFs are created by PF's driver.

In EEH recovery, it has two cases:
1. Device and driver is EEH aware, error handlers are called.
2. Device and driver is not EEH aware, un-plug the device and plug it again by enumerating it.

The special thing happens on the second case. For a PF, we could use the original pci core to enumerate the bus, while for VF we need to record the VFs which aer un-plugged then plug it again.

Also The patch caches the VF index in pci_dn, which can be used to calculate VF's bus, device and function number. Those information helps to locate the VF's PCI device instance when doing hotplug during EEH recovery if necessary.

---
 arch/powerpc/include/asm/eeh.h        |   7 ++
 arch/powerpc/include/asm/pci-bridge.h |   1 +
 arch/powerpc/kernel/eeh.c             |   8 +++
 arch/powerpc/kernel/eeh_dev.c         |   1 +
 arch/powerpc/kernel/eeh_driver.c      | 127 +++++++++++++++++++++++++++-------
 arch/powerpc/kernel/eeh_pe.c          |   3 +-
 arch/powerpc/kernel/pci_dn.c          |   4 +-
 7 files changed, 123 insertions(+), 28 deletions(-)
arch/powerpc/include/asm/eeh.h +7 -0
index 331c856..1f68190 100644
@@ -127,6 +127,11 @@ static inline bool eeh_pe_passed(struct eeh_pe *pe)
 #define EEH_DEV_SYSFS		(1 << 9)	/* Sysfs created	*/
 #define EEH_DEV_REMOVED		(1 << 10)	/* Removed permanently	*/
 
+struct eeh_rmv_data {
+	struct list_head edev_list;
+	int removed;
+};
+
 struct eeh_dev {
 	int mode;			/* EEH mode			*/
 	int class_code;			/* Class code of the device	*/
@@ -139,9 +144,11 @@ struct eeh_dev {
 	int af_cap;			/* Saved AF capability		*/
 	struct eeh_pe *pe;		/* Associated PE		*/
 	struct list_head list;		/* Form link list in the PE	*/
+	struct list_head rmv_list;	/* Record the removed edev 	*/
 	struct pci_controller *phb;	/* Associated PHB		*/
 	struct pci_dn *pdn;		/* Associated PCI device node	*/
 	struct pci_dev *pdev;		/* Associated PCI device	*/
+	bool   in_error;		/* Error flag for eeh_dev	*/
 	struct pci_dev *physfn;		/* Associated PF PORT		*/
 	struct pci_bus *bus;		/* PCI bus for partial hotplug	*/
 };
arch/powerpc/include/asm/pci-bridge.h +1 -0
index 9b365d6..533e6e9 100644
@@ -211,6 +211,7 @@ struct pci_dn {
 #define IODA_INVALID_PE		(-1)
 #ifdef CONFIG_PPC_POWERNV
 	int	pe_number;
+	int     vf_index;		/* VF index in the PF */
 #ifdef CONFIG_PCI_IOV
 	u16     vfs_expanded;		/* number of VFs IOV BAR expanded */
 	u16     num_vfs;		/* number of VFs enabled*/
arch/powerpc/kernel/eeh.c +8 -0
index 41a4b30..0f36750 100644
@@ -1245,6 +1245,14 @@ void eeh_remove_device(struct pci_dev *dev)
 	 * from the parent PE during the BAR resotre.
 	 */
 	edev->pdev = NULL;
+
+	/*
+	 * The flag "in_error" is used to trace EEH devices for VFs
+	 * in error state or not. It's set in eeh_report_error(). If
+	 * it's not set, eeh_report_{reset,resume}() won't be called
+	 * for the VF EEH device.
+	 */
+	edev->in_error = 0;
 	dev->dev.archdata.edev = NULL;
 	if (!(edev->pe->state & EEH_PE_KEEP))
 		eeh_rmv_from_parent_pe(edev);
arch/powerpc/kernel/eeh_dev.c +1 -0
index aabba94..7815095 100644
@@ -67,6 +67,7 @@ void *eeh_dev_init(struct pci_dn *pdn, void *data)
 	edev->pdn = pdn;
 	edev->phb = phb;
 	INIT_LIST_HEAD(&edev->list);
+	INIT_LIST_HEAD(&edev->rmv_list);
 
 	return NULL;
 }
arch/powerpc/kernel/eeh_driver.c +101 -26

237 lines not on this page · raw message

arch/powerpc/kernel/eeh_pe.c +2 -1
index 29240ad..b7facb9 100644
@@ -936,7 +936,8 @@ struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe)
 	if (pe->type & EEH_PE_PHB) {
 		bus = pe->phb->bus;
 	} else if (pe->type & EEH_PE_BUS ||
-		   pe->type & EEH_PE_DEVICE) {
+		   pe->type & EEH_PE_DEVICE ||
+		   pe->type & EEH_PE_VF) {
 		if (pe->bus) {
 			bus = pe->bus;
 			goto out;
arch/powerpc/kernel/pci_dn.c +3 -1
index 5091b05..9e9cb16 100644
@@ -139,6 +139,7 @@ struct pci_dn *pci_get_pdn(struct pci_dev *pdev)
 #ifdef CONFIG_PCI_IOV
 static struct pci_dn *add_one_dev_pci_data(struct pci_dn *parent,
 					   struct pci_dev *pdev,
+					   int vf_index,
 					   int busno, int devfn)
 {
 	struct pci_dn *pdn;
@@ -158,6 +159,7 @@ static struct pci_dn *add_one_dev_pci_data(struct pci_dn *parent,
 	pdn->busno = busno;
 	pdn->devfn = devfn;
 #ifdef CONFIG_PPC_POWERNV
+	pdn->vf_index = vf_index;
 	pdn->pe_number = IODA_INVALID_PE;
 #endif
 	INIT_LIST_HEAD(&pdn->child_list);
@@ -198,7 +200,7 @@ struct pci_dn *add_dev_pci_data(struct pci_dev *pdev)
 		return NULL;
 
 	for (i = 0; i < pci_sriov_get_totalvfs(pdev); i++) {
-		pdn = add_one_dev_pci_data(parent, NULL,
+		pdn = add_one_dev_pci_data(parent, NULL, i,
 					   pci_iov_virtfn_bus(pdev, i),
 					   pci_iov_virtfn_devfn(pdev, i));
 		if (!pdn) {
Signature · 1 line
2.5.0
#10 lore raw

Re: [PATCH V12 9/9] powerpc/eeh: Support error recovery for VF PE

Quoted 32 lines · Wei Yang

PFs are enumerated on PCI bus, while VFs are created by PF's driver.

In EEH recovery, it has two cases:
1. Device and driver is EEH aware, error handlers are called.
2. Device and driver is not EEH aware, un-plug the device and plug it again by enumerating it.

The special thing happens on the second case. For a PF, we could use the original pci core to enumerate the bus, while for VF we need to record the VFs which aer un-plugged then plug it again.

Also The patch caches the VF index in pci_dn, which can be used to calculate VF's bus, device and function number. Those information helps to locate the VF's PCI device instance when doing hotplug during EEH recovery if necessary.

---
  arch/powerpc/include/asm/eeh.h        |   7 ++
  arch/powerpc/include/asm/pci-bridge.h |   1 +
  arch/powerpc/kernel/eeh.c             |   8 +++
  arch/powerpc/kernel/eeh_dev.c         |   1 +
  arch/powerpc/kernel/eeh_driver.c      | 127 +++++++++++++++++++++++++++-------
  arch/powerpc/kernel/eeh_pe.c          |   3 +-
  arch/powerpc/kernel/pci_dn.c          |   4 +-
  7 files changed, 123 insertions(+), 28 deletions(-)
arch/powerpc/include/asm/eeh.h +0 -0
index 331c856..1f68190 100644

arch/powerpc/include/asm/eeh.h static inline bool eeh_pe_passed(struct eeh_pe *pe) · line 133

Quoted 7 lines
arch/powerpc/include/asm/eeh.h +4 -0
@@ -127,6 +127,11 @@ static inline bool eeh_pe_passed(struct eeh_pe *pe)
  #define EEH_DEV_SYSFS		(1 << 9)	/* Sysfs created	*/
  #define EEH_DEV_REMOVED		(1 << 10)	/* Removed permanently	*/
 
+struct eeh_rmv_data {
+	struct list_head edev_list;
+	int removed;
+};

This struct is only used in arch/powerpc/kernel/eeh_driver.c so move it there.

Quoted 34 lines
arch/powerpc/include/asm/eeh.h +3 -0
+
  struct eeh_dev {
  	int mode;			/* EEH mode			*/
  	int class_code;			/* Class code of the device	*/
@@ -139,9 +144,11 @@ struct eeh_dev {
  	int af_cap;			/* Saved AF capability		*/
  	struct eeh_pe *pe;		/* Associated PE		*/
  	struct list_head list;		/* Form link list in the PE	*/
+	struct list_head rmv_list;	/* Record the removed edev 	*/
  	struct pci_controller *phb;	/* Associated PHB		*/
  	struct pci_dn *pdn;		/* Associated PCI device node	*/
  	struct pci_dev *pdev;		/* Associated PCI device	*/
+	bool   in_error;		/* Error flag for eeh_dev	*/
  	struct pci_dev *physfn;		/* Associated PF PORT		*/
  	struct pci_bus *bus;		/* PCI bus for partial hotplug	*/
  };
arch/powerpc/include/asm/pci-bridge.h +1 -0
index 9b365d6..533e6e9 100644
@@ -211,6 +211,7 @@ struct pci_dn {
  #define IODA_INVALID_PE		(-1)
  #ifdef CONFIG_PPC_POWERNV
  	int	pe_number;
+	int     vf_index;		/* VF index in the PF */
  #ifdef CONFIG_PCI_IOV
  	u16     vfs_expanded;		/* number of VFs IOV BAR expanded */
  	u16     num_vfs;		/* number of VFs enabled*/
arch/powerpc/kernel/eeh.c +0 -0
index 41a4b30..0f36750 100644
@@ -1245,6 +1245,14 @@ void eeh_remove_device(struct pci_dev *dev)
  	 * from the parent PE during the BAR resotre.

arch/powerpc/kernel/eeh.c void eeh_remove_device(struct pci_dev *dev) · line 1255

Quoted 10 lines
arch/powerpc/kernel/eeh.c +8 -0
  	 */
  	edev->pdev = NULL;
+
+	/*
+	 * The flag "in_error" is used to trace EEH devices for VFs
+	 * in error state or not. It's set in eeh_report_error(). If
+	 * it's not set, eeh_report_{reset,resume}() won't be called
+	 * for the VF EEH device.
+	 */
+	edev->in_error = 0;

It is a bool, so "= false".

Quoted 315 lines
arch/powerpc/kernel/eeh.c +0 -0
  	dev->dev.archdata.edev = NULL;
  	if (!(edev->pe->state & EEH_PE_KEEP))
  		eeh_rmv_from_parent_pe(edev);
arch/powerpc/kernel/eeh_dev.c +1 -0
index aabba94..7815095 100644
@@ -67,6 +67,7 @@ void *eeh_dev_init(struct pci_dn *pdn, void *data)
  	edev->pdn = pdn;
  	edev->phb = phb;
  	INIT_LIST_HEAD(&edev->list);
+	INIT_LIST_HEAD(&edev->rmv_list);
 
  	return NULL;
  }
arch/powerpc/kernel/eeh_driver.c +101 -26
index 89eb4bc..06d20d6 100644
@@ -211,6 +211,7 @@ static void *eeh_report_error(void *data, void *userdata)
  	if (rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
  	if (*res == PCI_ERS_RESULT_NONE) *res = rc;
 
+	edev->in_error = true;
  	eeh_pcid_put(dev);
  	return NULL;
  }
@@ -282,7 +283,8 @@ static void *eeh_report_reset(void *data, void *userdata)
 
  	if (!driver->err_handler ||
  	    !driver->err_handler->slot_reset ||
-	    (edev->mode & EEH_DEV_NO_HANDLER)) {
+	    (edev->mode & EEH_DEV_NO_HANDLER) ||
+	    (!edev->in_error)) {
  		eeh_pcid_put(dev);
  		return NULL;
  	}
@@ -326,6 +328,7 @@ static void *eeh_report_resume(void *data, void *userdata)
  {
  	struct eeh_dev *edev = (struct eeh_dev *)data;
  	struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
+	bool was_in_error;
  	struct pci_driver *driver;
 
  	if (!dev || eeh_dev_removed(edev))
@@ -335,11 +338,13 @@ static void *eeh_report_resume(void *data, void *userdata)
  	driver = eeh_pcid_get(dev);
  	if (!driver) return NULL;
 
+	was_in_error = edev->in_error;
+	edev->in_error = false;
  	eeh_enable_irq(dev);
 
  	if (!driver->err_handler ||
  	    !driver->err_handler->resume ||
-	    (edev->mode & EEH_DEV_NO_HANDLER)) {
+	    (edev->mode & EEH_DEV_NO_HANDLER) || !was_in_error) {
  		edev->mode &= ~EEH_DEV_NO_HANDLER;
  		eeh_pcid_put(dev);
  		return NULL;
@@ -386,12 +391,39 @@ static void *eeh_report_failure(void *data, void *userdata)
  	return NULL;
  }
 
+static void *eeh_add_virt_device(void *data, void *userdata)
+{
+	struct pci_driver *driver;
+	struct eeh_dev *edev = (struct eeh_dev *)data;
+	struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
+	struct pci_dn *pdn = eeh_dev_to_pdn(edev);
+
+	if (!(edev->physfn)) {
+		pr_warn("%s: EEH dev %04x:%02x:%02x.%01x not for VF\n",
+			__func__, edev->phb->global_number, pdn->busno,
+			PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
+		return NULL;
+	}
+
+	driver = eeh_pcid_get(dev);
+	if (driver) {
+		eeh_pcid_put(dev);
+		if (driver->err_handler)
+			return NULL;
+	}
+
+	pci_iov_virtfn_add(edev->physfn, pdn->vf_index, 0);
+	return NULL;
+}
+
  static void *eeh_rmv_device(void *data, void *userdata)
  {
  	struct pci_driver *driver;
  	struct eeh_dev *edev = (struct eeh_dev *)data;
  	struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
-	int *removed = (int *)userdata;
+	struct eeh_rmv_data *rmv_data = (struct eeh_rmv_data *)userdata;
+	int *removed = rmv_data ? &rmv_data->removed : NULL;
+	struct pci_dn *pdn = eeh_dev_to_pdn(edev);
 
  	/*
  	 * Actually, we should remove the PCI bridges as well.
@@ -416,7 +448,7 @@ static void *eeh_rmv_device(void *data, void *userdata)
  	driver = eeh_pcid_get(dev);
  	if (driver) {
  		eeh_pcid_put(dev);
-		if (driver->err_handler)
+		if (removed && driver->err_handler)
  			return NULL;
  	}
 
@@ -425,11 +457,26 @@ static void *eeh_rmv_device(void *data, void *userdata)
  		 pci_name(dev));
  	edev->bus = dev->bus;
  	edev->mode |= EEH_DEV_DISCONNECTED;
-	(*removed)++;
+	if (removed)
+		(*removed)++;
 
-	pci_lock_rescan_remove();
-	pci_stop_and_remove_bus_device(dev);
-	pci_unlock_rescan_remove();
+	if (edev->physfn) {
+		pci_iov_virtfn_remove(edev->physfn, pdn->vf_index, 0);
+		edev->pdev = NULL;
+
+		/*
+		 * We have to set the VF PE number to invalid one, which is
+		 * required to plug the VF successfully.
+		 */
+		pdn->pe_number = IODA_INVALID_PE;
+
+		if (rmv_data)
+			list_add(&edev->rmv_list, &rmv_data->edev_list);
+	} else {
+		pci_lock_rescan_remove();
+		pci_stop_and_remove_bus_device(dev);
+		pci_unlock_rescan_remove();
+	}
 
  	return NULL;
  }
@@ -543,11 +590,13 @@ int eeh_pe_reset_and_recover(struct eeh_pe *pe)
   * During the reset, udev might be invoked because those affected
   * PCI devices will be removed and then added.
   */
-static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus)
+static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus,
+				struct eeh_rmv_data *rmv_data)
  {
  	struct pci_bus *frozen_bus = eeh_pe_bus_get(pe);
  	struct timeval tstamp;
-	int cnt, rc, removed = 0;
+	int cnt, rc;
+	struct eeh_dev *edev;
 
  	/* pcibios will clear the counter; save the value */
  	cnt = pe->freeze_count;
@@ -561,12 +610,15 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus)
  	 */
  	eeh_pe_state_mark(pe, EEH_PE_KEEP);
  	if (bus) {
-		pci_lock_rescan_remove();
-		pcibios_remove_pci_devices(bus);
-		pci_unlock_rescan_remove();
-	} else if (frozen_bus) {
-		eeh_pe_dev_traverse(pe, eeh_rmv_device, &removed);
-	}
+		if (pe->type & EEH_PE_VF) {
+			eeh_pe_dev_traverse(pe, eeh_rmv_device, NULL);
+		} else {
+			pci_lock_rescan_remove();
+			pcibios_remove_pci_devices(bus);
+			pci_unlock_rescan_remove();
+		}
+	} else if (frozen_bus)
+		eeh_pe_dev_traverse(pe, eeh_rmv_device, rmv_data);
 
  	/*
  	 * Reset the pci controller. (Asserts RST#; resets config space).
@@ -607,14 +659,22 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus)
  		 * PE. We should disconnect it so the binding can be
  		 * rebuilt when adding PCI devices.
  		 */
+		edev = list_first_entry(&pe->edevs, struct eeh_dev, list);
  		eeh_pe_traverse(pe, eeh_pe_detach_dev, NULL);
-		pcibios_add_pci_devices(bus);
-	} else if (frozen_bus && removed) {
+		if (pe->type & EEH_PE_VF)
+			eeh_add_virt_device(edev, NULL);
+		else
+			pcibios_add_pci_devices(bus);
+	} else if (frozen_bus && rmv_data->removed) {
  		pr_info("EEH: Sleep 5s ahead of partial hotplug\n");
  		ssleep(5);
 
+		edev = list_first_entry(&pe->edevs, struct eeh_dev, list);
  		eeh_pe_traverse(pe, eeh_pe_detach_dev, NULL);
-		pcibios_add_pci_devices(frozen_bus);
+		if (pe->type & EEH_PE_VF)
+			eeh_add_virt_device(edev, NULL);
+		else
+			pcibios_add_pci_devices(frozen_bus);
  	}
  	eeh_pe_state_clear(pe, EEH_PE_KEEP);
 
@@ -633,8 +693,10 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus)
  static void eeh_handle_normal_event(struct eeh_pe *pe)
  {
  	struct pci_bus *frozen_bus;
+	struct eeh_dev *edev, *tmp;
  	int rc = 0;
  	enum pci_ers_result result = PCI_ERS_RESULT_NONE;
+	struct eeh_rmv_data rmv_data = {LIST_HEAD_INIT(rmv_data.edev_list), 0};
 
  	frozen_bus = eeh_pe_bus_get(pe);
  	if (!frozen_bus) {
@@ -681,7 +743,7 @@ static void eeh_handle_normal_event(struct eeh_pe *pe)
  	 */
  	if (result == PCI_ERS_RESULT_NONE) {
  		pr_info("EEH: Reset with hotplug activity\n");
-		rc = eeh_reset_device(pe, frozen_bus);
+		rc = eeh_reset_device(pe, frozen_bus, NULL);
  		if (rc) {
  			pr_warn("%s: Unable to reset, err=%d\n",
  				__func__, rc);
@@ -733,7 +795,7 @@ static void eeh_handle_normal_event(struct eeh_pe *pe)
  	/* If any device called out for a reset, then reset the slot */
  	if (result == PCI_ERS_RESULT_NEED_RESET) {
  		pr_info("EEH: Reset without hotplug activity\n");
-		rc = eeh_reset_device(pe, NULL);
+		rc = eeh_reset_device(pe, NULL, &rmv_data);
  		if (rc) {
  			pr_warn("%s: Cannot reset, err=%d\n",
  				__func__, rc);
@@ -753,6 +815,15 @@ static void eeh_handle_normal_event(struct eeh_pe *pe)
  		goto hard_fail;
  	}
 
+	/*
+	 * For those hot removed VFs, we should add back them after PF get
+	 * recovered properly.
+	 */
+	list_for_each_entry_safe(edev, tmp, &rmv_data.edev_list, rmv_list) {
+		eeh_add_virt_device(edev, NULL);
+		list_del(&edev->rmv_list);
+	}
+
  	/* Tell all device drivers that they can resume operations */
  	pr_info("EEH: Notify device driver to resume\n");
  	eeh_pe_dev_traverse(pe, eeh_report_resume, NULL);
@@ -792,11 +863,15 @@ perm_error:
  	 * the their PCI config any more.
  	 */
  	if (frozen_bus) {
-		eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
-
-		pci_lock_rescan_remove();
-		pcibios_remove_pci_devices(frozen_bus);
-		pci_unlock_rescan_remove();
+		if (pe->type & EEH_PE_VF) {
+			eeh_pe_dev_traverse(pe, eeh_rmv_device, NULL);
+			eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
+		} else {
+			eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
+			pci_lock_rescan_remove();
+			pcibios_remove_pci_devices(frozen_bus);
+			pci_unlock_rescan_remove();
+		}
  	}
  }
 
arch/powerpc/kernel/eeh_pe.c +2 -1
index 29240ad..b7facb9 100644
@@ -936,7 +936,8 @@ struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe)
  	if (pe->type & EEH_PE_PHB) {
  		bus = pe->phb->bus;
  	} else if (pe->type & EEH_PE_BUS ||
-		   pe->type & EEH_PE_DEVICE) {
+		   pe->type & EEH_PE_DEVICE ||
+		   pe->type & EEH_PE_VF) {
  		if (pe->bus) {
  			bus = pe->bus;
  			goto out;
arch/powerpc/kernel/pci_dn.c +3 -1
index 5091b05..9e9cb16 100644
@@ -139,6 +139,7 @@ struct pci_dn *pci_get_pdn(struct pci_dev *pdev)
  #ifdef CONFIG_PCI_IOV
  static struct pci_dn *add_one_dev_pci_data(struct pci_dn *parent,
  					   struct pci_dev *pdev,
+					   int vf_index,
  					   int busno, int devfn)
  {
  	struct pci_dn *pdn;
@@ -158,6 +159,7 @@ static struct pci_dn *add_one_dev_pci_data(struct pci_dn *parent,
  	pdn->busno = busno;
  	pdn->devfn = devfn;
  #ifdef CONFIG_PPC_POWERNV
+	pdn->vf_index = vf_index;
  	pdn->pe_number = IODA_INVALID_PE;
  #endif
  	INIT_LIST_HEAD(&pdn->child_list);
@@ -198,7 +200,7 @@ struct pci_dn *add_dev_pci_data(struct pci_dev *pdev)
  		return NULL;
 
  	for (i = 0; i < pci_sriov_get_totalvfs(pdev); i++) {
-		pdn = add_one_dev_pci_data(parent, NULL,
+		pdn = add_one_dev_pci_data(parent, NULL, i,
  					   pci_iov_virtfn_bus(pdev, i),
  					   pci_iov_virtfn_devfn(pdev, i));
  		if (!pdn) {
Signature · 1 line
Alexey
author
#11 lore raw

Re: [PATCH V12 9/9] powerpc/eeh: Support error recovery for VF PE

Quoted 36 lines · Alexey Kardashevskiy
Quoted 35 lines · Wei Yang

PFs are enumerated on PCI bus, while VFs are created by PF's driver.

In EEH recovery, it has two cases:
1. Device and driver is EEH aware, error handlers are called.
2. Device and driver is not EEH aware, un-plug the device and plug it again by enumerating it.

The special thing happens on the second case. For a PF, we could use the original pci core to enumerate the bus, while for VF we need to record the VFs which aer un-plugged then plug it again.

Also The patch caches the VF index in pci_dn, which can be used to calculate VF's bus, device and function number. Those information helps to locate the VF's PCI device instance when doing hotplug during EEH recovery if necessary.

---
 arch/powerpc/include/asm/eeh.h        |   7 ++
 arch/powerpc/include/asm/pci-bridge.h |   1 +
 arch/powerpc/kernel/eeh.c             |   8 +++
 arch/powerpc/kernel/eeh_dev.c         |   1 +
 arch/powerpc/kernel/eeh_driver.c      | 127 +++++++++++++++++++++++++++-------
 arch/powerpc/kernel/eeh_pe.c          |   3 +-
 arch/powerpc/kernel/pci_dn.c          |   4 +-
 7 files changed, 123 insertions(+), 28 deletions(-)
arch/powerpc/include/asm/eeh.h +0 -0
index 331c856..1f68190 100644
@@ -127,6 +127,11 @@ static inline bool eeh_pe_passed(struct eeh_pe *pe)
 #define EEH_DEV_SYSFS		(1 << 9)	/* Sysfs created	*/
 #define EEH_DEV_REMOVED		(1 << 10)	/* Removed permanently	*/
 
Quoted 8 lines

arch/powerpc/include/asm/eeh.h static inline bool eeh_pe_passed(struct eeh_pe *pe) · line 133

Quoted 4 lines
arch/powerpc/include/asm/eeh.h +4 -0
+struct eeh_rmv_data {
+	struct list_head edev_list;
+	int removed;
+};

This struct is only used in arch/powerpc/kernel/eeh_driver.c so move it there.

Will move this in next version.

Quoted 40 lines
Quoted 40 lines
arch/powerpc/include/asm/eeh.h +3 -0
+
 struct eeh_dev {
 	int mode;			/* EEH mode			*/
 	int class_code;			/* Class code of the device	*/
@@ -139,9 +144,11 @@ struct eeh_dev {
 	int af_cap;			/* Saved AF capability		*/
 	struct eeh_pe *pe;		/* Associated PE		*/
 	struct list_head list;		/* Form link list in the PE	*/
+	struct list_head rmv_list;	/* Record the removed edev 	*/
 	struct pci_controller *phb;	/* Associated PHB		*/
 	struct pci_dn *pdn;		/* Associated PCI device node	*/
 	struct pci_dev *pdev;		/* Associated PCI device	*/
+	bool   in_error;		/* Error flag for eeh_dev	*/
 	struct pci_dev *physfn;		/* Associated PF PORT		*/
 	struct pci_bus *bus;		/* PCI bus for partial hotplug	*/
 };
arch/powerpc/include/asm/pci-bridge.h +1 -0
index 9b365d6..533e6e9 100644
@@ -211,6 +211,7 @@ struct pci_dn {
 #define IODA_INVALID_PE		(-1)
 #ifdef CONFIG_PPC_POWERNV
 	int	pe_number;
+	int     vf_index;		/* VF index in the PF */
 #ifdef CONFIG_PCI_IOV
 	u16     vfs_expanded;		/* number of VFs IOV BAR expanded */
 	u16     num_vfs;		/* number of VFs enabled*/
arch/powerpc/kernel/eeh.c +3 -0
index 41a4b30..0f36750 100644
@@ -1245,6 +1245,14 @@ void eeh_remove_device(struct pci_dev *dev)
 	 * from the parent PE during the BAR resotre.
 	 */
 	edev->pdev = NULL;
+
+	/*
+	 * The flag "in_error" is used to trace EEH devices for VFs
Quoted 9 lines

arch/powerpc/kernel/eeh.c void eeh_remove_device(struct pci_dev *dev) · line 1255

Quoted 5 lines
arch/powerpc/kernel/eeh.c +5 -0
+	 * in error state or not. It's set in eeh_report_error(). If
+	 * it's not set, eeh_report_{reset,resume}() won't be called
+	 * for the VF EEH device.
+	 */
+	edev->in_error = 0;

It is a bool, so "= false".

Correct.

Quoted 320 lines
Quoted 316 lines
arch/powerpc/kernel/eeh.c +0 -0
 	dev->dev.archdata.edev = NULL;
 	if (!(edev->pe->state & EEH_PE_KEEP))
 		eeh_rmv_from_parent_pe(edev);
arch/powerpc/kernel/eeh_dev.c +1 -0
index aabba94..7815095 100644
@@ -67,6 +67,7 @@ void *eeh_dev_init(struct pci_dn *pdn, void *data)
 	edev->pdn = pdn;
 	edev->phb = phb;
 	INIT_LIST_HEAD(&edev->list);
+	INIT_LIST_HEAD(&edev->rmv_list);
 
 	return NULL;
 }
arch/powerpc/kernel/eeh_driver.c +101 -26
index 89eb4bc..06d20d6 100644
@@ -211,6 +211,7 @@ static void *eeh_report_error(void *data, void *userdata)
 	if (rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
 	if (*res == PCI_ERS_RESULT_NONE) *res = rc;
 
+	edev->in_error = true;
 	eeh_pcid_put(dev);
 	return NULL;
 }
@@ -282,7 +283,8 @@ static void *eeh_report_reset(void *data, void *userdata)
 
 	if (!driver->err_handler ||
 	    !driver->err_handler->slot_reset ||
-	    (edev->mode & EEH_DEV_NO_HANDLER)) {
+	    (edev->mode & EEH_DEV_NO_HANDLER) ||
+	    (!edev->in_error)) {
 		eeh_pcid_put(dev);
 		return NULL;
 	}
@@ -326,6 +328,7 @@ static void *eeh_report_resume(void *data, void *userdata)
 {
 	struct eeh_dev *edev = (struct eeh_dev *)data;
 	struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
+	bool was_in_error;
 	struct pci_driver *driver;
 
 	if (!dev || eeh_dev_removed(edev))
@@ -335,11 +338,13 @@ static void *eeh_report_resume(void *data, void *userdata)
 	driver = eeh_pcid_get(dev);
 	if (!driver) return NULL;
 
+	was_in_error = edev->in_error;
+	edev->in_error = false;
 	eeh_enable_irq(dev);
 
 	if (!driver->err_handler ||
 	    !driver->err_handler->resume ||
-	    (edev->mode & EEH_DEV_NO_HANDLER)) {
+	    (edev->mode & EEH_DEV_NO_HANDLER) || !was_in_error) {
 		edev->mode &= ~EEH_DEV_NO_HANDLER;
 		eeh_pcid_put(dev);
 		return NULL;
@@ -386,12 +391,39 @@ static void *eeh_report_failure(void *data, void *userdata)
 	return NULL;
 }
 
+static void *eeh_add_virt_device(void *data, void *userdata)
+{
+	struct pci_driver *driver;
+	struct eeh_dev *edev = (struct eeh_dev *)data;
+	struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
+	struct pci_dn *pdn = eeh_dev_to_pdn(edev);
+
+	if (!(edev->physfn)) {
+		pr_warn("%s: EEH dev %04x:%02x:%02x.%01x not for VF\n",
+			__func__, edev->phb->global_number, pdn->busno,
+			PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
+		return NULL;
+	}
+
+	driver = eeh_pcid_get(dev);
+	if (driver) {
+		eeh_pcid_put(dev);
+		if (driver->err_handler)
+			return NULL;
+	}
+
+	pci_iov_virtfn_add(edev->physfn, pdn->vf_index, 0);
+	return NULL;
+}
+
 static void *eeh_rmv_device(void *data, void *userdata)
 {
 	struct pci_driver *driver;
 	struct eeh_dev *edev = (struct eeh_dev *)data;
 	struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
-	int *removed = (int *)userdata;
+	struct eeh_rmv_data *rmv_data = (struct eeh_rmv_data *)userdata;
+	int *removed = rmv_data ? &rmv_data->removed : NULL;
+	struct pci_dn *pdn = eeh_dev_to_pdn(edev);
 
 	/*
 	 * Actually, we should remove the PCI bridges as well.
@@ -416,7 +448,7 @@ static void *eeh_rmv_device(void *data, void *userdata)
 	driver = eeh_pcid_get(dev);
 	if (driver) {
 		eeh_pcid_put(dev);
-		if (driver->err_handler)
+		if (removed && driver->err_handler)
 			return NULL;
 	}
 
@@ -425,11 +457,26 @@ static void *eeh_rmv_device(void *data, void *userdata)
 		 pci_name(dev));
 	edev->bus = dev->bus;
 	edev->mode |= EEH_DEV_DISCONNECTED;
-	(*removed)++;
+	if (removed)
+		(*removed)++;
 
-	pci_lock_rescan_remove();
-	pci_stop_and_remove_bus_device(dev);
-	pci_unlock_rescan_remove();
+	if (edev->physfn) {
+		pci_iov_virtfn_remove(edev->physfn, pdn->vf_index, 0);
+		edev->pdev = NULL;
+
+		/*
+		 * We have to set the VF PE number to invalid one, which is
+		 * required to plug the VF successfully.
+		 */
+		pdn->pe_number = IODA_INVALID_PE;
+
+		if (rmv_data)
+			list_add(&edev->rmv_list, &rmv_data->edev_list);
+	} else {
+		pci_lock_rescan_remove();
+		pci_stop_and_remove_bus_device(dev);
+		pci_unlock_rescan_remove();
+	}
 
 	return NULL;
 }
@@ -543,11 +590,13 @@ int eeh_pe_reset_and_recover(struct eeh_pe *pe)
  * During the reset, udev might be invoked because those affected
  * PCI devices will be removed and then added.
  */
-static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus)
+static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus,
+				struct eeh_rmv_data *rmv_data)
 {
 	struct pci_bus *frozen_bus = eeh_pe_bus_get(pe);
 	struct timeval tstamp;
-	int cnt, rc, removed = 0;
+	int cnt, rc;
+	struct eeh_dev *edev;
 
 	/* pcibios will clear the counter; save the value */
 	cnt = pe->freeze_count;
@@ -561,12 +610,15 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus)
 	 */
 	eeh_pe_state_mark(pe, EEH_PE_KEEP);
 	if (bus) {
-		pci_lock_rescan_remove();
-		pcibios_remove_pci_devices(bus);
-		pci_unlock_rescan_remove();
-	} else if (frozen_bus) {
-		eeh_pe_dev_traverse(pe, eeh_rmv_device, &removed);
-	}
+		if (pe->type & EEH_PE_VF) {
+			eeh_pe_dev_traverse(pe, eeh_rmv_device, NULL);
+		} else {
+			pci_lock_rescan_remove();
+			pcibios_remove_pci_devices(bus);
+			pci_unlock_rescan_remove();
+		}
+	} else if (frozen_bus)
+		eeh_pe_dev_traverse(pe, eeh_rmv_device, rmv_data);
 
 	/*
 	 * Reset the pci controller. (Asserts RST#; resets config space).
@@ -607,14 +659,22 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus)
 		 * PE. We should disconnect it so the binding can be
 		 * rebuilt when adding PCI devices.
 		 */
+		edev = list_first_entry(&pe->edevs, struct eeh_dev, list);
 		eeh_pe_traverse(pe, eeh_pe_detach_dev, NULL);
-		pcibios_add_pci_devices(bus);
-	} else if (frozen_bus && removed) {
+		if (pe->type & EEH_PE_VF)
+			eeh_add_virt_device(edev, NULL);
+		else
+			pcibios_add_pci_devices(bus);
+	} else if (frozen_bus && rmv_data->removed) {
 		pr_info("EEH: Sleep 5s ahead of partial hotplug\n");
 		ssleep(5);
 
+		edev = list_first_entry(&pe->edevs, struct eeh_dev, list);
 		eeh_pe_traverse(pe, eeh_pe_detach_dev, NULL);
-		pcibios_add_pci_devices(frozen_bus);
+		if (pe->type & EEH_PE_VF)
+			eeh_add_virt_device(edev, NULL);
+		else
+			pcibios_add_pci_devices(frozen_bus);
 	}
 	eeh_pe_state_clear(pe, EEH_PE_KEEP);
 
@@ -633,8 +693,10 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus)
 static void eeh_handle_normal_event(struct eeh_pe *pe)
 {
 	struct pci_bus *frozen_bus;
+	struct eeh_dev *edev, *tmp;
 	int rc = 0;
 	enum pci_ers_result result = PCI_ERS_RESULT_NONE;
+	struct eeh_rmv_data rmv_data = {LIST_HEAD_INIT(rmv_data.edev_list), 0};
 
 	frozen_bus = eeh_pe_bus_get(pe);
 	if (!frozen_bus) {
@@ -681,7 +743,7 @@ static void eeh_handle_normal_event(struct eeh_pe *pe)
 	 */
 	if (result == PCI_ERS_RESULT_NONE) {
 		pr_info("EEH: Reset with hotplug activity\n");
-		rc = eeh_reset_device(pe, frozen_bus);
+		rc = eeh_reset_device(pe, frozen_bus, NULL);
 		if (rc) {
 			pr_warn("%s: Unable to reset, err=%d\n",
 				__func__, rc);
@@ -733,7 +795,7 @@ static void eeh_handle_normal_event(struct eeh_pe *pe)
 	/* If any device called out for a reset, then reset the slot */
 	if (result == PCI_ERS_RESULT_NEED_RESET) {
 		pr_info("EEH: Reset without hotplug activity\n");
-		rc = eeh_reset_device(pe, NULL);
+		rc = eeh_reset_device(pe, NULL, &rmv_data);
 		if (rc) {
 			pr_warn("%s: Cannot reset, err=%d\n",
 				__func__, rc);
@@ -753,6 +815,15 @@ static void eeh_handle_normal_event(struct eeh_pe *pe)
 		goto hard_fail;
 	}
 
+	/*
+	 * For those hot removed VFs, we should add back them after PF get
+	 * recovered properly.
+	 */
+	list_for_each_entry_safe(edev, tmp, &rmv_data.edev_list, rmv_list) {
+		eeh_add_virt_device(edev, NULL);
+		list_del(&edev->rmv_list);
+	}
+
 	/* Tell all device drivers that they can resume operations */
 	pr_info("EEH: Notify device driver to resume\n");
 	eeh_pe_dev_traverse(pe, eeh_report_resume, NULL);
@@ -792,11 +863,15 @@ perm_error:
 	 * the their PCI config any more.
 	 */
 	if (frozen_bus) {
-		eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
-
-		pci_lock_rescan_remove();
-		pcibios_remove_pci_devices(frozen_bus);
-		pci_unlock_rescan_remove();
+		if (pe->type & EEH_PE_VF) {
+			eeh_pe_dev_traverse(pe, eeh_rmv_device, NULL);
+			eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
+		} else {
+			eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
+			pci_lock_rescan_remove();
+			pcibios_remove_pci_devices(frozen_bus);
+			pci_unlock_rescan_remove();
+		}
 	}
 }
 
arch/powerpc/kernel/eeh_pe.c +2 -1
index 29240ad..b7facb9 100644
@@ -936,7 +936,8 @@ struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe)
 	if (pe->type & EEH_PE_PHB) {
 		bus = pe->phb->bus;
 	} else if (pe->type & EEH_PE_BUS ||
-		   pe->type & EEH_PE_DEVICE) {
+		   pe->type & EEH_PE_DEVICE ||
+		   pe->type & EEH_PE_VF) {
 		if (pe->bus) {
 			bus = pe->bus;
 			goto out;
arch/powerpc/kernel/pci_dn.c +3 -1
index 5091b05..9e9cb16 100644
@@ -139,6 +139,7 @@ struct pci_dn *pci_get_pdn(struct pci_dev *pdev)
 #ifdef CONFIG_PCI_IOV
 static struct pci_dn *add_one_dev_pci_data(struct pci_dn *parent,
 					   struct pci_dev *pdev,
+					   int vf_index,
 					   int busno, int devfn)
 {
 	struct pci_dn *pdn;
@@ -158,6 +159,7 @@ static struct pci_dn *add_one_dev_pci_data(struct pci_dn *parent,
 	pdn->busno = busno;
 	pdn->devfn = devfn;
 #ifdef CONFIG_PPC_POWERNV
+	pdn->vf_index = vf_index;
 	pdn->pe_number = IODA_INVALID_PE;
 #endif
 	INIT_LIST_HEAD(&pdn->child_list);
@@ -198,7 +200,7 @@ struct pci_dn *add_dev_pci_data(struct pci_dev *pdev)
 		return NULL;
 
 	for (i = 0; i < pci_sriov_get_totalvfs(pdev); i++) {
-		pdn = add_one_dev_pci_data(parent, NULL,
+		pdn = add_one_dev_pci_data(parent, NULL, i,
 					   pci_iov_virtfn_bus(pdev, i),
 					   pci_iov_virtfn_devfn(pdev, i));
 		if (!pdn) {
Signature · 1 line
Alexey
Signature · 2 lines
Richard Yang
Help you, Help me
Reviewed-by on the v12 series
#12 lore raw
In reply to Wei Yang
Quoted 16 lines · Wei Yang

This patchset enables EEH on SRIOV VFs. The general idea is to create proper VF edev and VF PE and handle them properly.

Different from the Bus PE, VF PE just contain one VF. This introduces the difference of EEH error handling on a VF PE. Generally, it has several differences.

First, the VF's removal and re-enumerate rely on its PF. VF has a tight relationship between its PF. This is not proper to enumerate a VF by usual scan procedure. That's why virtfn_add/virtfn_remove are exported in this patch set.

Second, the reset/restore of a VF is done in kernel space. FW is not aware of the VF, this means the usual reset function done in FW will not work. One of the patch will imitate the reset/restore function in kernel space.

Quoted 8 lines

Third, the VF may be removed during the PF's error_detected function. In this case, the original error_detected->slot_reset->resume sequence is not proper to those removed VFs, since they are re-created by PF in a fresh state. A flag in eeh_dev is introduce to mark the eeh_dev is in error state. By doing so, we track whether this device needs to be reset or not.

This has been tested both on host and in guest on Power8 with latest kernel version.

With the small issues in 9/9 fixed,

Quoted 108 lines

v12:
* rebased on v4.3
* Rephrase some commit log to make it more clear and specific
* move vf_index assignment in CONFIG_PPC_POWERNV
* merge "Cache VF index in pci_dn" with "Support error recovery for VF PE"
* check the return value after eeh_dev_init() for VF
* initialize the parameter before pass to read_config()
* make pnv_pci_fixup_vf_mps() a dedicated patch, which fixup and store mps value in pci_dn
v11:
* move vf_index assignment in marco CONFIG_PPC_POWERNV
* merge Patch "Cache VF index in pci_dn" into Patch "Support error recovery for VF PE"
v10:
* rebased on v4.2
* delete the last patch "powerpc/powernv: compound PE for VFs" since after redesign of SRIOV, there is no compound PE for VFs now.
* add two patches which fix problems found during tests powerpc/eeh: Support error recovery for VF PE
powerpc/eeh: Handle hot removed VF when PF is EEH aware
v9:
* split pcibios_bus_add_device() into a separate patch
* Bjorn acked the PCI part and agreed this patch set to be merged from ppc tree
* rebased on mpe/linux.git next branch
v8:
* fix on checking the return value of pnv_eeh_do_flr()
* introduced a weak function pcibios_bus_add_device() to create PE for VFs
v7:
* fix compile error when PCI_IOV is not set
v6:
* code / commit log refactor by Gavin
v5:
* remove the compound field, iterate on Master VF PE instead
* some code refine on PCI config restore and reset on VF
the wait time for assert and deassert
PCI device address format
check on edev->pcie_cap and edev->aer_cap before access them
v4:
* refine the change logs, comment and code style
* change pnv_pci_fixup_vf_eeh() to pnv_eeh_vf_final_fixup() and remove the CONFIG_PCI_IOV macro
* reorder patch 5/6 to make the logic more reasonable
* remove remove_dev_pci_data()
* remove the EEH_DEV_VF flag, use edev->physfn to identify a VF EEH DEV and remove related CONFIG_PCI_IOV macro
* add the option for VF reset
* fix the pnv_eeh_cfg_blocked() logic
* replace pnv_pci_cfg_{read,write} with eeh_ops->{read,write}_config in pnv_eeh_vf_restore_config()
* rename pnv_eeh_vf_restore_config() to pnv_eeh_restore_vf_config()
* rename pnv_pci_fixup_vf_caps() to pnv_pci_vf_header_fixup() and move it to arch/powerpc/platforms/powernv/pci.c
* add a field compound in pnv_ioda_pe to link compound PEs
* handle compound PE for VF PEs
v3:
* add back vf_index in pci_dn to track the VF's index
* rename ppdev in eeh_dev to physfn for consistency
* move edev->physfn assignment before dev->dev.archdata.edev is set
* move pnv_pci_fixup_vf_eeh() and pnv_pci_fixup_vf_caps() to eeh-powernv.c
* more clear and detail in commit log and comment in code
* merge eeh_rmv_virt_device() with eeh_rmv_device()
* move the cfg_blocked check logic from pnv_eeh_read/write_config() to pnv_eeh_cfg_blocked()
* move the vf reset/restore logic into its own patch, two patches are created.
powerpc/powernv: Support PCI config restore for VFs powerpc/powernv: Support EEH reset for VFs
* simplify the vf reset logic
v2:
* add prefix pci_iov_ to virtfn_add/virtfn_remove
* use EEH_DEV_VF as a flag for a VF's eeh_dev
* use eeh_dev instead of edev in change log
* remove vf_index in eeh_dev, calculate it from pdn->busno and devfn
* do eeh_add_device_late() and eeh_sysfs_add_device() both after pci_dev is well initialized
* do FLR to reset a VF PE
* imitate the restore function in FW for VF
* remove the reverse order patch, since it is still under discussion

Wei Yang (9):
PCI/IOV: Rename and export virtfn_add/virtfn_remove
PCI: Add pcibios_bus_add_device() weak function powerpc/pci: Remove VFs prior to PF powerpc/eeh: Cache only BARs, not windows or IOV BARs powerpc/powernv: EEH device for VF powerpc/eeh: Create PE for VFs powerpc/powernv: Support EEH reset for VF PE powerpc/powernv: Support PCI config restore for VFs powerpc/eeh: Support error recovery for VF PE

  arch/powerpc/include/asm/eeh.h               |  10 ++
  arch/powerpc/include/asm/pci-bridge.h        |   2 +
  arch/powerpc/kernel/eeh.c                    |  17 ++-
  arch/powerpc/kernel/eeh_cache.c              |  11 +-
  arch/powerpc/kernel/eeh_dev.c                |   1 +
  arch/powerpc/kernel/eeh_driver.c             | 127 ++++++++++++----
  arch/powerpc/kernel/eeh_pe.c                 |  13 +-
  arch/powerpc/kernel/pci-hotplug.c            |   2 +-
  arch/powerpc/kernel/pci_dn.c                 |  17 ++-
  arch/powerpc/platforms/powernv/eeh-powernv.c | 219 ++++++++++++++++++++++++++-
  arch/powerpc/platforms/powernv/pci.c         |  18 +++
  drivers/pci/bus.c                            |   3 +
  drivers/pci/iov.c                            |  10 +-
  include/linux/pci.h                          |   8 +
  14 files changed, 411 insertions(+), 47 deletions(-)
Signature · 1 line
Alexey
author
#13 lore raw
Quoted 23 lines · Alexey Kardashevskiy
Quoted 22 lines · Wei Yang

This patchset enables EEH on SRIOV VFs. The general idea is to create proper VF edev and VF PE and handle them properly.

Different from the Bus PE, VF PE just contain one VF. This introduces the difference of EEH error handling on a VF PE. Generally, it has several differences.

First, the VF's removal and re-enumerate rely on its PF. VF has a tight relationship between its PF. This is not proper to enumerate a VF by usual scan procedure. That's why virtfn_add/virtfn_remove are exported in this patch set.

Second, the reset/restore of a VF is done in kernel space. FW is not aware of the VF, this means the usual reset function done in FW will not work. One of the patch will imitate the reset/restore function in kernel space.

Third, the VF may be removed during the PF's error_detected function. In this case, the original error_detected->slot_reset->resume sequence is not proper to those removed VFs, since they are re-created by PF in a fresh state. A flag in eeh_dev is introduce to mark the eeh_dev is in error state. By doing so, we track whether this device needs to be reset or not.

Quoted 7 lines
Quoted 2 lines

This has been tested both on host and in guest on Power8 with latest kernel version.

With the small issues in 9/9 fixed,

Thanks for your comment. I appreciate your time and efforts.

Have a good night.

Quoted 113 lines
Quoted 109 lines

v12:
* rebased on v4.3
* Rephrase some commit log to make it more clear and specific
* move vf_index assignment in CONFIG_PPC_POWERNV
* merge "Cache VF index in pci_dn" with "Support error recovery for VF PE"
* check the return value after eeh_dev_init() for VF
* initialize the parameter before pass to read_config()
* make pnv_pci_fixup_vf_mps() a dedicated patch, which fixup and store mps value in pci_dn
v11:
* move vf_index assignment in marco CONFIG_PPC_POWERNV
* merge Patch "Cache VF index in pci_dn" into Patch "Support error recovery for VF PE"
v10:
* rebased on v4.2
* delete the last patch "powerpc/powernv: compound PE for VFs" since after redesign of SRIOV, there is no compound PE for VFs now.
* add two patches which fix problems found during tests powerpc/eeh: Support error recovery for VF PE
powerpc/eeh: Handle hot removed VF when PF is EEH aware
v9:
* split pcibios_bus_add_device() into a separate patch
* Bjorn acked the PCI part and agreed this patch set to be merged from ppc tree
* rebased on mpe/linux.git next branch
v8:
* fix on checking the return value of pnv_eeh_do_flr()
* introduced a weak function pcibios_bus_add_device() to create PE for VFs
v7:
* fix compile error when PCI_IOV is not set
v6:
* code / commit log refactor by Gavin
v5:
* remove the compound field, iterate on Master VF PE instead
* some code refine on PCI config restore and reset on VF
the wait time for assert and deassert
PCI device address format
check on edev->pcie_cap and edev->aer_cap before access them
v4:
* refine the change logs, comment and code style
* change pnv_pci_fixup_vf_eeh() to pnv_eeh_vf_final_fixup() and remove the CONFIG_PCI_IOV macro
* reorder patch 5/6 to make the logic more reasonable
* remove remove_dev_pci_data()
* remove the EEH_DEV_VF flag, use edev->physfn to identify a VF EEH DEV and remove related CONFIG_PCI_IOV macro
* add the option for VF reset
* fix the pnv_eeh_cfg_blocked() logic
* replace pnv_pci_cfg_{read,write} with eeh_ops->{read,write}_config in pnv_eeh_vf_restore_config()
* rename pnv_eeh_vf_restore_config() to pnv_eeh_restore_vf_config()
* rename pnv_pci_fixup_vf_caps() to pnv_pci_vf_header_fixup() and move it to arch/powerpc/platforms/powernv/pci.c
* add a field compound in pnv_ioda_pe to link compound PEs
* handle compound PE for VF PEs
v3:
* add back vf_index in pci_dn to track the VF's index
* rename ppdev in eeh_dev to physfn for consistency
* move edev->physfn assignment before dev->dev.archdata.edev is set
* move pnv_pci_fixup_vf_eeh() and pnv_pci_fixup_vf_caps() to eeh-powernv.c
* more clear and detail in commit log and comment in code
* merge eeh_rmv_virt_device() with eeh_rmv_device()
* move the cfg_blocked check logic from pnv_eeh_read/write_config() to pnv_eeh_cfg_blocked()
* move the vf reset/restore logic into its own patch, two patches are created.
powerpc/powernv: Support PCI config restore for VFs powerpc/powernv: Support EEH reset for VFs
* simplify the vf reset logic
v2:
* add prefix pci_iov_ to virtfn_add/virtfn_remove
* use EEH_DEV_VF as a flag for a VF's eeh_dev
* use eeh_dev instead of edev in change log
* remove vf_index in eeh_dev, calculate it from pdn->busno and devfn
* do eeh_add_device_late() and eeh_sysfs_add_device() both after pci_dev is well initialized
* do FLR to reset a VF PE
* imitate the restore function in FW for VF
* remove the reverse order patch, since it is still under discussion

Wei Yang (9):
PCI/IOV: Rename and export virtfn_add/virtfn_remove
PCI: Add pcibios_bus_add_device() weak function powerpc/pci: Remove VFs prior to PF powerpc/eeh: Cache only BARs, not windows or IOV BARs powerpc/powernv: EEH device for VF powerpc/eeh: Create PE for VFs powerpc/powernv: Support EEH reset for VF PE powerpc/powernv: Support PCI config restore for VFs powerpc/eeh: Support error recovery for VF PE

 arch/powerpc/include/asm/eeh.h               |  10 ++
 arch/powerpc/include/asm/pci-bridge.h        |   2 +
 arch/powerpc/kernel/eeh.c                    |  17 ++-
 arch/powerpc/kernel/eeh_cache.c              |  11 +-
 arch/powerpc/kernel/eeh_dev.c                |   1 +
 arch/powerpc/kernel/eeh_driver.c             | 127 ++++++++++++----
 arch/powerpc/kernel/eeh_pe.c                 |  13 +-
 arch/powerpc/kernel/pci-hotplug.c            |   2 +-
 arch/powerpc/kernel/pci_dn.c                 |  17 ++-
 arch/powerpc/platforms/powernv/eeh-powernv.c | 219 ++++++++++++++++++++++++++-
 arch/powerpc/platforms/powernv/pci.c         |  18 +++
 drivers/pci/bus.c                            |   3 +
 drivers/pci/iov.c                            |  10 +-
 include/linux/pci.h                          |   8 +
 14 files changed, 411 insertions(+), 47 deletions(-)
Signature · 1 line
Alexey
Signature · 2 lines
Richard Yang
Help you, Help me