Commit 67086e32 authored by Wei Yang's avatar Wei Yang Committed by Michael Ellerman

powerpc/eeh: powerpc/eeh: Support error recovery for VF PE

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.
Signed-off-by: default avatarWei Yang <weiyang@linux.vnet.ibm.com>
Acked-by: default avatarGavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 0dc2830e
...@@ -140,9 +140,11 @@ struct eeh_dev { ...@@ -140,9 +140,11 @@ struct eeh_dev {
int af_cap; /* Saved AF capability */ int af_cap; /* Saved AF capability */
struct eeh_pe *pe; /* Associated PE */ struct eeh_pe *pe; /* Associated PE */
struct list_head list; /* Form link list in the PE */ struct list_head list; /* Form link list in the PE */
struct list_head rmv_list; /* Record the removed edevs */
struct pci_controller *phb; /* Associated PHB */ struct pci_controller *phb; /* Associated PHB */
struct pci_dn *pdn; /* Associated PCI device node */ struct pci_dn *pdn; /* Associated PCI device node */
struct pci_dev *pdev; /* Associated PCI device */ struct pci_dev *pdev; /* Associated PCI device */
bool in_error; /* Error flag for edev */
struct pci_dev *physfn; /* Associated SRIOV PF */ struct pci_dev *physfn; /* Associated SRIOV PF */
struct pci_bus *bus; /* PCI bus for partial hotplug */ struct pci_bus *bus; /* PCI bus for partial hotplug */
}; };
......
...@@ -212,6 +212,7 @@ struct pci_dn { ...@@ -212,6 +212,7 @@ struct pci_dn {
#define IODA_INVALID_PE (-1) #define IODA_INVALID_PE (-1)
#ifdef CONFIG_PPC_POWERNV #ifdef CONFIG_PPC_POWERNV
int pe_number; int pe_number;
int vf_index; /* VF index in the PF */
#ifdef CONFIG_PCI_IOV #ifdef CONFIG_PCI_IOV
u16 vfs_expanded; /* number of VFs IOV BAR expanded */ u16 vfs_expanded; /* number of VFs IOV BAR expanded */
u16 num_vfs; /* number of VFs enabled*/ u16 num_vfs; /* number of VFs enabled*/
......
...@@ -1246,6 +1246,14 @@ void eeh_remove_device(struct pci_dev *dev) ...@@ -1246,6 +1246,14 @@ void eeh_remove_device(struct pci_dev *dev)
* from the parent PE during the BAR resotre. * from the parent PE during the BAR resotre.
*/ */
edev->pdev = NULL; 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 = false;
dev->dev.archdata.edev = NULL; dev->dev.archdata.edev = NULL;
if (!(edev->pe->state & EEH_PE_KEEP)) if (!(edev->pe->state & EEH_PE_KEEP))
eeh_rmv_from_parent_pe(edev); eeh_rmv_from_parent_pe(edev);
......
...@@ -67,6 +67,7 @@ void *eeh_dev_init(struct pci_dn *pdn, void *data) ...@@ -67,6 +67,7 @@ void *eeh_dev_init(struct pci_dn *pdn, void *data)
edev->pdn = pdn; edev->pdn = pdn;
edev->phb = phb; edev->phb = phb;
INIT_LIST_HEAD(&edev->list); INIT_LIST_HEAD(&edev->list);
INIT_LIST_HEAD(&edev->rmv_list);
return NULL; return NULL;
} }
......
...@@ -34,6 +34,11 @@ ...@@ -34,6 +34,11 @@
#include <asm/prom.h> #include <asm/prom.h>
#include <asm/rtas.h> #include <asm/rtas.h>
struct eeh_rmv_data {
struct list_head edev_list;
int removed;
};
/** /**
* eeh_pcid_name - Retrieve name of PCI device driver * eeh_pcid_name - Retrieve name of PCI device driver
* @pdev: PCI device * @pdev: PCI device
...@@ -211,6 +216,7 @@ static void *eeh_report_error(void *data, void *userdata) ...@@ -211,6 +216,7 @@ static void *eeh_report_error(void *data, void *userdata)
if (rc == PCI_ERS_RESULT_NEED_RESET) *res = rc; if (rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;
if (*res == PCI_ERS_RESULT_NONE) *res = rc; if (*res == PCI_ERS_RESULT_NONE) *res = rc;
edev->in_error = true;
eeh_pcid_put(dev); eeh_pcid_put(dev);
return NULL; return NULL;
} }
...@@ -282,7 +288,8 @@ static void *eeh_report_reset(void *data, void *userdata) ...@@ -282,7 +288,8 @@ static void *eeh_report_reset(void *data, void *userdata)
if (!driver->err_handler || if (!driver->err_handler ||
!driver->err_handler->slot_reset || !driver->err_handler->slot_reset ||
(edev->mode & EEH_DEV_NO_HANDLER)) { (edev->mode & EEH_DEV_NO_HANDLER) ||
(!edev->in_error)) {
eeh_pcid_put(dev); eeh_pcid_put(dev);
return NULL; return NULL;
} }
...@@ -326,6 +333,7 @@ static void *eeh_report_resume(void *data, void *userdata) ...@@ -326,6 +333,7 @@ static void *eeh_report_resume(void *data, void *userdata)
{ {
struct eeh_dev *edev = (struct eeh_dev *)data; struct eeh_dev *edev = (struct eeh_dev *)data;
struct pci_dev *dev = eeh_dev_to_pci_dev(edev); struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
bool was_in_error;
struct pci_driver *driver; struct pci_driver *driver;
if (!dev || eeh_dev_removed(edev)) if (!dev || eeh_dev_removed(edev))
...@@ -335,11 +343,13 @@ static void *eeh_report_resume(void *data, void *userdata) ...@@ -335,11 +343,13 @@ static void *eeh_report_resume(void *data, void *userdata)
driver = eeh_pcid_get(dev); driver = eeh_pcid_get(dev);
if (!driver) return NULL; if (!driver) return NULL;
was_in_error = edev->in_error;
edev->in_error = false;
eeh_enable_irq(dev); eeh_enable_irq(dev);
if (!driver->err_handler || if (!driver->err_handler ||
!driver->err_handler->resume || !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; edev->mode &= ~EEH_DEV_NO_HANDLER;
eeh_pcid_put(dev); eeh_pcid_put(dev);
return NULL; return NULL;
...@@ -386,12 +396,40 @@ static void *eeh_report_failure(void *data, void *userdata) ...@@ -386,12 +396,40 @@ static void *eeh_report_failure(void *data, void *userdata)
return NULL; 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;
}
#ifdef CONFIG_PPC_POWERNV
pci_iov_add_virtfn(edev->physfn, pdn->vf_index, 0);
#endif
return NULL;
}
static void *eeh_rmv_device(void *data, void *userdata) static void *eeh_rmv_device(void *data, void *userdata)
{ {
struct pci_driver *driver; struct pci_driver *driver;
struct eeh_dev *edev = (struct eeh_dev *)data; struct eeh_dev *edev = (struct eeh_dev *)data;
struct pci_dev *dev = eeh_dev_to_pci_dev(edev); 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;
/* /*
* Actually, we should remove the PCI bridges as well. * Actually, we should remove the PCI bridges as well.
...@@ -416,7 +454,8 @@ static void *eeh_rmv_device(void *data, void *userdata) ...@@ -416,7 +454,8 @@ static void *eeh_rmv_device(void *data, void *userdata)
driver = eeh_pcid_get(dev); driver = eeh_pcid_get(dev);
if (driver) { if (driver) {
eeh_pcid_put(dev); eeh_pcid_put(dev);
if (driver->err_handler && if (removed &&
driver->err_handler &&
driver->err_handler->error_detected && driver->err_handler->error_detected &&
driver->err_handler->slot_reset) driver->err_handler->slot_reset)
return NULL; return NULL;
...@@ -427,11 +466,29 @@ static void *eeh_rmv_device(void *data, void *userdata) ...@@ -427,11 +466,29 @@ static void *eeh_rmv_device(void *data, void *userdata)
pci_name(dev)); pci_name(dev));
edev->bus = dev->bus; edev->bus = dev->bus;
edev->mode |= EEH_DEV_DISCONNECTED; edev->mode |= EEH_DEV_DISCONNECTED;
(*removed)++; if (removed)
(*removed)++;
pci_lock_rescan_remove(); if (edev->physfn) {
pci_stop_and_remove_bus_device(dev); #ifdef CONFIG_PPC_POWERNV
pci_unlock_rescan_remove(); struct pci_dn *pdn = eeh_dev_to_pdn(edev);
pci_iov_remove_virtfn(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;
#endif
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; return NULL;
} }
...@@ -545,11 +602,13 @@ int eeh_pe_reset_and_recover(struct eeh_pe *pe) ...@@ -545,11 +602,13 @@ int eeh_pe_reset_and_recover(struct eeh_pe *pe)
* During the reset, udev might be invoked because those affected * During the reset, udev might be invoked because those affected
* PCI devices will be removed and then added. * 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 pci_bus *frozen_bus = eeh_pe_bus_get(pe);
struct timeval tstamp; struct timeval tstamp;
int cnt, rc, removed = 0; int cnt, rc;
struct eeh_dev *edev;
/* pcibios will clear the counter; save the value */ /* pcibios will clear the counter; save the value */
cnt = pe->freeze_count; cnt = pe->freeze_count;
...@@ -563,12 +622,16 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus) ...@@ -563,12 +622,16 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus)
*/ */
eeh_pe_state_mark(pe, EEH_PE_KEEP); eeh_pe_state_mark(pe, EEH_PE_KEEP);
if (bus) { if (bus) {
eeh_pe_state_clear(pe, EEH_PE_PRI_BUS); if (pe->type & EEH_PE_VF) {
pci_lock_rescan_remove(); eeh_pe_dev_traverse(pe, eeh_rmv_device, NULL);
pcibios_remove_pci_devices(bus); } else {
pci_unlock_rescan_remove(); eeh_pe_state_clear(pe, EEH_PE_PRI_BUS);
pci_lock_rescan_remove();
pcibios_remove_pci_devices(bus);
pci_unlock_rescan_remove();
}
} else if (frozen_bus) { } else if (frozen_bus) {
eeh_pe_dev_traverse(pe, eeh_rmv_device, &removed); eeh_pe_dev_traverse(pe, eeh_rmv_device, &rmv_data);
} }
/* /*
...@@ -610,14 +673,22 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus) ...@@ -610,14 +673,22 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus)
* PE. We should disconnect it so the binding can be * PE. We should disconnect it so the binding can be
* rebuilt when adding PCI devices. * rebuilt when adding PCI devices.
*/ */
edev = list_first_entry(&pe->edevs, struct eeh_dev, list);
eeh_pe_traverse(pe, eeh_pe_detach_dev, NULL); eeh_pe_traverse(pe, eeh_pe_detach_dev, NULL);
pcibios_add_pci_devices(bus); if (pe->type & EEH_PE_VF)
} else if (frozen_bus && removed) { 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"); pr_info("EEH: Sleep 5s ahead of partial hotplug\n");
ssleep(5); ssleep(5);
edev = list_first_entry(&pe->edevs, struct eeh_dev, list);
eeh_pe_traverse(pe, eeh_pe_detach_dev, NULL); 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); eeh_pe_state_clear(pe, EEH_PE_KEEP);
...@@ -636,8 +707,10 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus) ...@@ -636,8 +707,10 @@ static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus)
static void eeh_handle_normal_event(struct eeh_pe *pe) static void eeh_handle_normal_event(struct eeh_pe *pe)
{ {
struct pci_bus *frozen_bus; struct pci_bus *frozen_bus;
struct eeh_dev *edev, *tmp;
int rc = 0; int rc = 0;
enum pci_ers_result result = PCI_ERS_RESULT_NONE; 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); frozen_bus = eeh_pe_bus_get(pe);
if (!frozen_bus) { if (!frozen_bus) {
...@@ -692,7 +765,7 @@ static void eeh_handle_normal_event(struct eeh_pe *pe) ...@@ -692,7 +765,7 @@ static void eeh_handle_normal_event(struct eeh_pe *pe)
*/ */
if (result == PCI_ERS_RESULT_NONE) { if (result == PCI_ERS_RESULT_NONE) {
pr_info("EEH: Reset with hotplug activity\n"); 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) { if (rc) {
pr_warn("%s: Unable to reset, err=%d\n", pr_warn("%s: Unable to reset, err=%d\n",
__func__, rc); __func__, rc);
...@@ -744,7 +817,7 @@ static void eeh_handle_normal_event(struct eeh_pe *pe) ...@@ -744,7 +817,7 @@ static void eeh_handle_normal_event(struct eeh_pe *pe)
/* If any device called out for a reset, then reset the slot */ /* If any device called out for a reset, then reset the slot */
if (result == PCI_ERS_RESULT_NEED_RESET) { if (result == PCI_ERS_RESULT_NEED_RESET) {
pr_info("EEH: Reset without hotplug activity\n"); pr_info("EEH: Reset without hotplug activity\n");
rc = eeh_reset_device(pe, NULL); rc = eeh_reset_device(pe, NULL, &rmv_data);
if (rc) { if (rc) {
pr_warn("%s: Cannot reset, err=%d\n", pr_warn("%s: Cannot reset, err=%d\n",
__func__, rc); __func__, rc);
...@@ -764,6 +837,15 @@ static void eeh_handle_normal_event(struct eeh_pe *pe) ...@@ -764,6 +837,15 @@ static void eeh_handle_normal_event(struct eeh_pe *pe)
goto hard_fail; 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 */ /* Tell all device drivers that they can resume operations */
pr_info("EEH: Notify device driver to resume\n"); pr_info("EEH: Notify device driver to resume\n");
eeh_pe_dev_traverse(pe, eeh_report_resume, NULL); eeh_pe_dev_traverse(pe, eeh_report_resume, NULL);
...@@ -803,12 +885,17 @@ static void eeh_handle_normal_event(struct eeh_pe *pe) ...@@ -803,12 +885,17 @@ static void eeh_handle_normal_event(struct eeh_pe *pe)
* the their PCI config any more. * the their PCI config any more.
*/ */
if (frozen_bus) { if (frozen_bus) {
eeh_pe_state_clear(pe, EEH_PE_PRI_BUS); if (pe->type & EEH_PE_VF) {
eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED); eeh_pe_dev_traverse(pe, eeh_rmv_device, NULL);
eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
} else {
eeh_pe_state_clear(pe, EEH_PE_PRI_BUS);
eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
pci_lock_rescan_remove(); pci_lock_rescan_remove();
pcibios_remove_pci_devices(frozen_bus); pcibios_remove_pci_devices(frozen_bus);
pci_unlock_rescan_remove(); pci_unlock_rescan_remove();
}
} }
} }
......
...@@ -139,6 +139,7 @@ struct pci_dn *pci_get_pdn(struct pci_dev *pdev) ...@@ -139,6 +139,7 @@ struct pci_dn *pci_get_pdn(struct pci_dev *pdev)
#ifdef CONFIG_PCI_IOV #ifdef CONFIG_PCI_IOV
static struct pci_dn *add_one_dev_pci_data(struct pci_dn *parent, static struct pci_dn *add_one_dev_pci_data(struct pci_dn *parent,
struct pci_dev *pdev, struct pci_dev *pdev,
int vf_index,
int busno, int devfn) int busno, int devfn)
{ {
struct pci_dn *pdn; struct pci_dn *pdn;
...@@ -158,6 +159,7 @@ static struct pci_dn *add_one_dev_pci_data(struct pci_dn *parent, ...@@ -158,6 +159,7 @@ static struct pci_dn *add_one_dev_pci_data(struct pci_dn *parent,
pdn->busno = busno; pdn->busno = busno;
pdn->devfn = devfn; pdn->devfn = devfn;
#ifdef CONFIG_PPC_POWERNV #ifdef CONFIG_PPC_POWERNV
pdn->vf_index = vf_index;
pdn->pe_number = IODA_INVALID_PE; pdn->pe_number = IODA_INVALID_PE;
#endif #endif
INIT_LIST_HEAD(&pdn->child_list); INIT_LIST_HEAD(&pdn->child_list);
...@@ -197,7 +199,7 @@ struct pci_dn *add_dev_pci_data(struct pci_dev *pdev) ...@@ -197,7 +199,7 @@ struct pci_dn *add_dev_pci_data(struct pci_dev *pdev)
return NULL; return NULL;
for (i = 0; i < pci_sriov_get_totalvfs(pdev); i++) { 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_bus(pdev, i),
pci_iov_virtfn_devfn(pdev, i)); pci_iov_virtfn_devfn(pdev, i));
if (!pdn) { if (!pdn) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment