2012-09-08 06:44:07 +08:00
|
|
|
/*
|
|
|
|
* The file intends to implement PE based on the information from
|
|
|
|
* platforms. Basically, there have 3 types of PEs: PHB/Bus/Device.
|
|
|
|
* All the PEs should be organized as hierarchy tree. The first level
|
|
|
|
* of the tree will be associated to existing PHBs since the particular
|
|
|
|
* PE is only meaningful in one PHB domain.
|
|
|
|
*
|
|
|
|
* Copyright Benjamin Herrenschmidt & Gavin Shan, IBM Corporation 2012.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2013-06-27 13:46:43 +08:00
|
|
|
#include <linux/delay.h>
|
2012-09-08 06:44:07 +08:00
|
|
|
#include <linux/export.h>
|
|
|
|
#include <linux/gfp.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
|
|
|
|
#include <asm/pci-bridge.h>
|
|
|
|
#include <asm/ppc-pci.h>
|
|
|
|
|
2014-07-17 12:41:43 +08:00
|
|
|
static int eeh_pe_aux_size = 0;
|
2012-09-08 06:44:07 +08:00
|
|
|
static LIST_HEAD(eeh_phb_pe);
|
|
|
|
|
2014-07-17 12:41:43 +08:00
|
|
|
/**
|
|
|
|
* eeh_set_pe_aux_size - Set PE auxillary data size
|
|
|
|
* @size: PE auxillary data size
|
|
|
|
*
|
|
|
|
* Set PE auxillary data size
|
|
|
|
*/
|
|
|
|
void eeh_set_pe_aux_size(int size)
|
|
|
|
{
|
|
|
|
if (size < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
eeh_pe_aux_size = size;
|
|
|
|
}
|
|
|
|
|
2012-09-08 06:44:07 +08:00
|
|
|
/**
|
|
|
|
* eeh_pe_alloc - Allocate PE
|
|
|
|
* @phb: PCI controller
|
|
|
|
* @type: PE type
|
|
|
|
*
|
|
|
|
* Allocate PE instance dynamically.
|
|
|
|
*/
|
|
|
|
static struct eeh_pe *eeh_pe_alloc(struct pci_controller *phb, int type)
|
|
|
|
{
|
|
|
|
struct eeh_pe *pe;
|
2014-07-17 12:41:43 +08:00
|
|
|
size_t alloc_size;
|
|
|
|
|
|
|
|
alloc_size = sizeof(struct eeh_pe);
|
|
|
|
if (eeh_pe_aux_size) {
|
|
|
|
alloc_size = ALIGN(alloc_size, cache_line_size());
|
|
|
|
alloc_size += eeh_pe_aux_size;
|
|
|
|
}
|
2012-09-08 06:44:07 +08:00
|
|
|
|
|
|
|
/* Allocate PHB PE */
|
2014-07-17 12:41:43 +08:00
|
|
|
pe = kzalloc(alloc_size, GFP_KERNEL);
|
2012-09-08 06:44:07 +08:00
|
|
|
if (!pe) return NULL;
|
|
|
|
|
|
|
|
/* Initialize PHB PE */
|
|
|
|
pe->type = type;
|
|
|
|
pe->phb = phb;
|
|
|
|
INIT_LIST_HEAD(&pe->child_list);
|
|
|
|
INIT_LIST_HEAD(&pe->child);
|
|
|
|
INIT_LIST_HEAD(&pe->edevs);
|
|
|
|
|
2014-07-17 12:41:43 +08:00
|
|
|
pe->data = (void *)pe + ALIGN(sizeof(struct eeh_pe),
|
|
|
|
cache_line_size());
|
2012-09-08 06:44:07 +08:00
|
|
|
return pe;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eeh_phb_pe_create - Create PHB PE
|
|
|
|
* @phb: PCI controller
|
|
|
|
*
|
|
|
|
* The function should be called while the PHB is detected during
|
|
|
|
* system boot or PCI hotplug in order to create PHB PE.
|
|
|
|
*/
|
2012-12-22 06:04:10 +08:00
|
|
|
int eeh_phb_pe_create(struct pci_controller *phb)
|
2012-09-08 06:44:07 +08:00
|
|
|
{
|
|
|
|
struct eeh_pe *pe;
|
|
|
|
|
|
|
|
/* Allocate PHB PE */
|
|
|
|
pe = eeh_pe_alloc(phb, EEH_PE_PHB);
|
|
|
|
if (!pe) {
|
|
|
|
pr_err("%s: out of memory!\n", __func__);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Put it into the list */
|
|
|
|
list_add_tail(&pe->child, &eeh_phb_pe);
|
|
|
|
|
|
|
|
pr_debug("EEH: Add PE for PHB#%d\n", phb->global_number);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eeh_phb_pe_get - Retrieve PHB PE based on the given PHB
|
|
|
|
* @phb: PCI controller
|
|
|
|
*
|
|
|
|
* The overall PEs form hierarchy tree. The first layer of the
|
|
|
|
* hierarchy tree is composed of PHB PEs. The function is used
|
|
|
|
* to retrieve the corresponding PHB PE according to the given PHB.
|
|
|
|
*/
|
2013-06-20 13:20:53 +08:00
|
|
|
struct eeh_pe *eeh_phb_pe_get(struct pci_controller *phb)
|
2012-09-08 06:44:07 +08:00
|
|
|
{
|
|
|
|
struct eeh_pe *pe;
|
|
|
|
|
|
|
|
list_for_each_entry(pe, &eeh_phb_pe, child) {
|
|
|
|
/*
|
|
|
|
* Actually, we needn't check the type since
|
|
|
|
* the PE for PHB has been determined when that
|
|
|
|
* was created.
|
|
|
|
*/
|
2012-09-21 07:29:46 +08:00
|
|
|
if ((pe->type & EEH_PE_PHB) && pe->phb == phb)
|
2012-09-08 06:44:07 +08:00
|
|
|
return pe;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-09-08 06:44:08 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* eeh_pe_next - Retrieve the next PE in the tree
|
|
|
|
* @pe: current PE
|
|
|
|
* @root: root PE
|
|
|
|
*
|
|
|
|
* The function is used to retrieve the next PE in the
|
|
|
|
* hierarchy PE tree.
|
|
|
|
*/
|
|
|
|
static struct eeh_pe *eeh_pe_next(struct eeh_pe *pe,
|
|
|
|
struct eeh_pe *root)
|
|
|
|
{
|
|
|
|
struct list_head *next = pe->child_list.next;
|
|
|
|
|
|
|
|
if (next == &pe->child_list) {
|
|
|
|
while (1) {
|
|
|
|
if (pe == root)
|
|
|
|
return NULL;
|
|
|
|
next = pe->child.next;
|
|
|
|
if (next != &pe->parent->child_list)
|
|
|
|
break;
|
|
|
|
pe = pe->parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list_entry(next, struct eeh_pe, child);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eeh_pe_traverse - Traverse PEs in the specified PHB
|
|
|
|
* @root: root PE
|
|
|
|
* @fn: callback
|
|
|
|
* @flag: extra parameter to callback
|
|
|
|
*
|
|
|
|
* The function is used to traverse the specified PE and its
|
|
|
|
* child PEs. The traversing is to be terminated once the
|
|
|
|
* callback returns something other than NULL, or no more PEs
|
|
|
|
* to be traversed.
|
|
|
|
*/
|
powerpc/eeh: Use partial hotplug for EEH unaware drivers
When EEH error happens to one specific PE, some devices with drivers
supporting EEH won't except hotplug on the device. However, there
might have other deivces without driver, or with driver without EEH
support. For the case, we need do partial hotplug in order to make
sure that the PE becomes absolutely quite during reset. Otherise,
the PE reset might fail and leads to failure of error recovery.
The current code doesn't handle that 'mixed' case properly, it either
uses the error callbacks to the drivers, or tries hotplug, but doesn't
handle a PE (EEH domain) composed of a combination of the two.
The patch intends to support so-called "partial" hotplug for EEH:
Before we do reset, we stop and remove those PCI devices without
EEH sensitive driver. The corresponding EEH devices are not detached
from its PE, but with special flag. After the reset is done, those
EEH devices with the special flag will be scanned one by one.
Signed-off-by: Gavin Shan <shangw@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-07-24 10:24:58 +08:00
|
|
|
void *eeh_pe_traverse(struct eeh_pe *root,
|
|
|
|
eeh_traverse_func fn, void *flag)
|
2012-09-08 06:44:08 +08:00
|
|
|
{
|
|
|
|
struct eeh_pe *pe;
|
|
|
|
void *ret;
|
|
|
|
|
|
|
|
for (pe = root; pe; pe = eeh_pe_next(pe, root)) {
|
|
|
|
ret = fn(pe, flag);
|
|
|
|
if (ret) return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-09-08 06:44:15 +08:00
|
|
|
/**
|
|
|
|
* eeh_pe_dev_traverse - Traverse the devices from the PE
|
|
|
|
* @root: EEH PE
|
|
|
|
* @fn: function callback
|
|
|
|
* @flag: extra parameter to callback
|
|
|
|
*
|
|
|
|
* The function is used to traverse the devices of the specified
|
|
|
|
* PE and its child PEs.
|
|
|
|
*/
|
|
|
|
void *eeh_pe_dev_traverse(struct eeh_pe *root,
|
|
|
|
eeh_traverse_func fn, void *flag)
|
|
|
|
{
|
|
|
|
struct eeh_pe *pe;
|
2013-07-24 10:24:56 +08:00
|
|
|
struct eeh_dev *edev, *tmp;
|
2012-09-08 06:44:15 +08:00
|
|
|
void *ret;
|
|
|
|
|
|
|
|
if (!root) {
|
2014-07-17 12:41:41 +08:00
|
|
|
pr_warn("%s: Invalid PE %p\n",
|
|
|
|
__func__, root);
|
2012-09-08 06:44:15 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Traverse root PE */
|
|
|
|
for (pe = root; pe; pe = eeh_pe_next(pe, root)) {
|
2013-07-24 10:24:56 +08:00
|
|
|
eeh_pe_for_each_dev(pe, edev, tmp) {
|
2012-09-08 06:44:15 +08:00
|
|
|
ret = fn(edev, flag);
|
2013-06-25 14:35:27 +08:00
|
|
|
if (ret)
|
2012-09-12 03:16:18 +08:00
|
|
|
return ret;
|
2012-09-08 06:44:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-09-08 06:44:08 +08:00
|
|
|
/**
|
|
|
|
* __eeh_pe_get - Check the PE address
|
|
|
|
* @data: EEH PE
|
|
|
|
* @flag: EEH device
|
|
|
|
*
|
|
|
|
* For one particular PE, it can be identified by PE address
|
|
|
|
* or tranditional BDF address. BDF address is composed of
|
|
|
|
* Bus/Device/Function number. The extra data referred by flag
|
|
|
|
* indicates which type of address should be used.
|
|
|
|
*/
|
|
|
|
static void *__eeh_pe_get(void *data, void *flag)
|
|
|
|
{
|
|
|
|
struct eeh_pe *pe = (struct eeh_pe *)data;
|
|
|
|
struct eeh_dev *edev = (struct eeh_dev *)flag;
|
|
|
|
|
|
|
|
/* Unexpected PHB PE */
|
2012-09-12 03:16:16 +08:00
|
|
|
if (pe->type & EEH_PE_PHB)
|
2012-09-08 06:44:08 +08:00
|
|
|
return NULL;
|
|
|
|
|
2014-11-25 06:27:00 +08:00
|
|
|
/*
|
|
|
|
* We prefer PE address. For most cases, we should
|
|
|
|
* have non-zero PE address
|
|
|
|
*/
|
|
|
|
if (eeh_has_flag(EEH_VALID_PE_ZERO)) {
|
|
|
|
if (edev->pe_config_addr == pe->addr)
|
|
|
|
return pe;
|
|
|
|
} else {
|
|
|
|
if (edev->pe_config_addr &&
|
|
|
|
(edev->pe_config_addr == pe->addr))
|
2012-09-08 06:44:08 +08:00
|
|
|
return pe;
|
2014-11-25 06:27:00 +08:00
|
|
|
}
|
2012-09-08 06:44:08 +08:00
|
|
|
|
|
|
|
/* Try BDF address */
|
2013-06-20 13:20:54 +08:00
|
|
|
if (edev->config_addr &&
|
2012-09-08 06:44:08 +08:00
|
|
|
(edev->config_addr == pe->config_addr))
|
|
|
|
return pe;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eeh_pe_get - Search PE based on the given address
|
|
|
|
* @edev: EEH device
|
|
|
|
*
|
|
|
|
* Search the corresponding PE based on the specified address which
|
|
|
|
* is included in the eeh device. The function is used to check if
|
|
|
|
* the associated PE has been created against the PE address. It's
|
|
|
|
* notable that the PE address has 2 format: traditional PE address
|
|
|
|
* which is composed of PCI bus/device/function number, or unified
|
|
|
|
* PE address.
|
|
|
|
*/
|
2013-06-20 13:20:54 +08:00
|
|
|
struct eeh_pe *eeh_pe_get(struct eeh_dev *edev)
|
2012-09-08 06:44:08 +08:00
|
|
|
{
|
|
|
|
struct eeh_pe *root = eeh_phb_pe_get(edev->phb);
|
|
|
|
struct eeh_pe *pe;
|
|
|
|
|
|
|
|
pe = eeh_pe_traverse(root, __eeh_pe_get, edev);
|
|
|
|
|
|
|
|
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;
|
2015-03-17 13:15:07 +08:00
|
|
|
struct pci_dn *pdn = eeh_dev_to_pdn(edev);
|
2012-09-08 06:44:08 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-03-17 13:15:07 +08:00
|
|
|
pdn = pdn ? pdn->parent : NULL;
|
|
|
|
while (pdn) {
|
2012-09-08 06:44:08 +08:00
|
|
|
/* We're poking out of PCI territory */
|
2015-03-17 13:15:07 +08:00
|
|
|
parent = pdn_to_eeh_dev(pdn);
|
|
|
|
if (!parent)
|
|
|
|
return NULL;
|
2012-09-08 06:44:08 +08:00
|
|
|
|
|
|
|
if (parent->pe)
|
|
|
|
return parent->pe;
|
|
|
|
|
2015-03-17 13:15:07 +08:00
|
|
|
pdn = pdn->parent;
|
2012-09-08 06:44:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-09-08 06:44:09 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* eeh_add_to_parent_pe - Add EEH device to parent PE
|
|
|
|
* @edev: EEH device
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
int eeh_add_to_parent_pe(struct eeh_dev *edev)
|
|
|
|
{
|
|
|
|
struct eeh_pe *pe, *parent;
|
|
|
|
|
2015-03-27 08:22:17 +08:00
|
|
|
/* Check if the PE number is valid */
|
|
|
|
if (!eeh_has_flag(EEH_VALID_PE_ZERO) && !edev->pe_config_addr) {
|
|
|
|
pr_err("%s: Invalid PE#0 for edev 0x%x on PHB#%d\n",
|
|
|
|
__func__, edev->config_addr, edev->phb->global_number);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-09-08 06:44:09 +08:00
|
|
|
/*
|
|
|
|
* Search the PE has been existing or not according
|
|
|
|
* to the PE address. If that has been existing, the
|
|
|
|
* PE should be composed of PCI bus and its subordinate
|
|
|
|
* components.
|
|
|
|
*/
|
|
|
|
pe = eeh_pe_get(edev);
|
2012-09-12 03:16:16 +08:00
|
|
|
if (pe && !(pe->type & EEH_PE_INVALID)) {
|
2012-09-08 06:44:09 +08:00
|
|
|
/* Mark the PE as type of PCI bus */
|
|
|
|
pe->type = EEH_PE_BUS;
|
|
|
|
edev->pe = pe;
|
|
|
|
|
|
|
|
/* Put the edev to PE */
|
|
|
|
list_add_tail(&edev->list, &pe->edevs);
|
2015-03-17 13:15:08 +08:00
|
|
|
pr_debug("EEH: Add %04x:%02x:%02x.%01x to Bus PE#%x\n",
|
|
|
|
edev->phb->global_number,
|
|
|
|
edev->config_addr >> 8,
|
|
|
|
PCI_SLOT(edev->config_addr & 0xFF),
|
|
|
|
PCI_FUNC(edev->config_addr & 0xFF),
|
|
|
|
pe->addr);
|
2012-09-12 03:16:16 +08:00
|
|
|
return 0;
|
|
|
|
} else if (pe && (pe->type & EEH_PE_INVALID)) {
|
|
|
|
list_add_tail(&edev->list, &pe->edevs);
|
|
|
|
edev->pe = pe;
|
|
|
|
/*
|
|
|
|
* We're running to here because of PCI hotplug caused by
|
|
|
|
* EEH recovery. We need clear EEH_PE_INVALID until the top.
|
|
|
|
*/
|
|
|
|
parent = pe;
|
|
|
|
while (parent) {
|
|
|
|
if (!(parent->type & EEH_PE_INVALID))
|
|
|
|
break;
|
2013-07-24 10:24:55 +08:00
|
|
|
parent->type &= ~(EEH_PE_INVALID | EEH_PE_KEEP);
|
2012-09-12 03:16:16 +08:00
|
|
|
parent = parent->parent;
|
|
|
|
}
|
|
|
|
|
2015-03-17 13:15:08 +08:00
|
|
|
pr_debug("EEH: Add %04x:%02x:%02x.%01x to Device "
|
|
|
|
"PE#%x, Parent PE#%x\n",
|
|
|
|
edev->phb->global_number,
|
|
|
|
edev->config_addr >> 8,
|
|
|
|
PCI_SLOT(edev->config_addr & 0xFF),
|
|
|
|
PCI_FUNC(edev->config_addr & 0xFF),
|
|
|
|
pe->addr, pe->parent->addr);
|
2012-09-08 06:44:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a new EEH PE */
|
|
|
|
pe = eeh_pe_alloc(edev->phb, EEH_PE_DEVICE);
|
|
|
|
if (!pe) {
|
|
|
|
pr_err("%s: out of memory!\n", __func__);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
pe->addr = edev->pe_config_addr;
|
|
|
|
pe->config_addr = edev->config_addr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put the new EEH PE into hierarchy tree. If the parent
|
|
|
|
* can't be found, the newly created PE will be attached
|
|
|
|
* 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(edev->phb);
|
|
|
|
if (!parent) {
|
|
|
|
pr_err("%s: No PHB PE is found (PHB Domain=%d)\n",
|
|
|
|
__func__, edev->phb->global_number);
|
|
|
|
edev->pe = NULL;
|
|
|
|
kfree(pe);
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pe->parent = parent;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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->list, &pe->edevs);
|
|
|
|
edev->pe = pe;
|
2015-03-17 13:15:08 +08:00
|
|
|
pr_debug("EEH: Add %04x:%02x:%02x.%01x to "
|
|
|
|
"Device PE#%x, Parent PE#%x\n",
|
|
|
|
edev->phb->global_number,
|
|
|
|
edev->config_addr >> 8,
|
|
|
|
PCI_SLOT(edev->config_addr & 0xFF),
|
|
|
|
PCI_FUNC(edev->config_addr & 0xFF),
|
|
|
|
pe->addr, pe->parent->addr);
|
2012-09-08 06:44:09 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-09-08 06:44:10 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* eeh_rmv_from_parent_pe - Remove one EEH device from the associated PE
|
|
|
|
* @edev: EEH device
|
|
|
|
*
|
|
|
|
* The PE hierarchy tree might be changed when doing PCI hotplug.
|
|
|
|
* Also, the PCI devices or buses could be removed from the system
|
|
|
|
* during EEH recovery. So we have to call the function remove the
|
|
|
|
* corresponding PE accordingly if necessary.
|
|
|
|
*/
|
2013-07-24 10:24:55 +08:00
|
|
|
int eeh_rmv_from_parent_pe(struct eeh_dev *edev)
|
2012-09-08 06:44:10 +08:00
|
|
|
{
|
2012-09-12 03:16:16 +08:00
|
|
|
struct eeh_pe *pe, *parent, *child;
|
|
|
|
int cnt;
|
2012-09-08 06:44:10 +08:00
|
|
|
|
|
|
|
if (!edev->pe) {
|
2015-03-17 13:15:08 +08:00
|
|
|
pr_debug("%s: No PE found for device %04x:%02x:%02x.%01x\n",
|
|
|
|
__func__, edev->phb->global_number,
|
|
|
|
edev->config_addr >> 8,
|
|
|
|
PCI_SLOT(edev->config_addr & 0xFF),
|
|
|
|
PCI_FUNC(edev->config_addr & 0xFF));
|
2012-09-08 06:44:10 +08:00
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the EEH device */
|
2014-09-17 10:48:26 +08:00
|
|
|
pe = eeh_dev_to_pe(edev);
|
2012-09-08 06:44:10 +08:00
|
|
|
edev->pe = NULL;
|
|
|
|
list_del(&edev->list);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the parent PE includes any EEH devices.
|
|
|
|
* If not, we should delete that. Also, we should
|
|
|
|
* delete the parent PE if it doesn't have associated
|
|
|
|
* child PEs and EEH devices.
|
|
|
|
*/
|
|
|
|
while (1) {
|
|
|
|
parent = pe->parent;
|
2012-09-12 03:16:16 +08:00
|
|
|
if (pe->type & EEH_PE_PHB)
|
2012-09-08 06:44:10 +08:00
|
|
|
break;
|
|
|
|
|
2013-07-24 10:24:55 +08:00
|
|
|
if (!(pe->state & EEH_PE_KEEP)) {
|
2012-09-12 03:16:17 +08:00
|
|
|
if (list_empty(&pe->edevs) &&
|
|
|
|
list_empty(&pe->child_list)) {
|
|
|
|
list_del(&pe->child);
|
|
|
|
kfree(pe);
|
|
|
|
} else {
|
|
|
|
break;
|
2012-09-12 03:16:16 +08:00
|
|
|
}
|
2012-09-12 03:16:17 +08:00
|
|
|
} else {
|
|
|
|
if (list_empty(&pe->edevs)) {
|
|
|
|
cnt = 0;
|
|
|
|
list_for_each_entry(child, &pe->child_list, child) {
|
2012-11-23 05:58:26 +08:00
|
|
|
if (!(child->type & EEH_PE_INVALID)) {
|
2012-09-12 03:16:17 +08:00
|
|
|
cnt++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-09-12 03:16:16 +08:00
|
|
|
|
2012-09-12 03:16:17 +08:00
|
|
|
if (!cnt)
|
|
|
|
pe->type |= EEH_PE_INVALID;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2012-09-08 06:44:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pe = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-09-08 06:44:12 +08:00
|
|
|
|
2013-06-20 13:21:01 +08:00
|
|
|
/**
|
|
|
|
* eeh_pe_update_time_stamp - Update PE's frozen time stamp
|
|
|
|
* @pe: EEH PE
|
|
|
|
*
|
|
|
|
* We have time stamp for each PE to trace its time of getting
|
|
|
|
* frozen in last hour. The function should be called to update
|
|
|
|
* the time stamp on first error of the specific PE. On the other
|
|
|
|
* handle, we needn't account for errors happened in last hour.
|
|
|
|
*/
|
|
|
|
void eeh_pe_update_time_stamp(struct eeh_pe *pe)
|
|
|
|
{
|
|
|
|
struct timeval tstamp;
|
|
|
|
|
|
|
|
if (!pe) return;
|
|
|
|
|
|
|
|
if (pe->freeze_count <= 0) {
|
|
|
|
pe->freeze_count = 0;
|
|
|
|
do_gettimeofday(&pe->tstamp);
|
|
|
|
} else {
|
|
|
|
do_gettimeofday(&tstamp);
|
|
|
|
if (tstamp.tv_sec - pe->tstamp.tv_sec > 3600) {
|
|
|
|
pe->tstamp = tstamp;
|
|
|
|
pe->freeze_count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-08 06:44:12 +08:00
|
|
|
/**
|
|
|
|
* __eeh_pe_state_mark - Mark the state for the PE
|
|
|
|
* @data: EEH PE
|
|
|
|
* @flag: state
|
|
|
|
*
|
|
|
|
* The function is used to mark the indicated state for the given
|
|
|
|
* PE. Also, the associated PCI devices will be put into IO frozen
|
|
|
|
* state as well.
|
|
|
|
*/
|
|
|
|
static void *__eeh_pe_state_mark(void *data, void *flag)
|
|
|
|
{
|
|
|
|
struct eeh_pe *pe = (struct eeh_pe *)data;
|
|
|
|
int state = *((int *)flag);
|
2013-07-24 10:24:56 +08:00
|
|
|
struct eeh_dev *edev, *tmp;
|
2012-09-08 06:44:12 +08:00
|
|
|
struct pci_dev *pdev;
|
|
|
|
|
powerpc/eeh: No hotplug on permanently removed dev
The issue was detected in a bit complicated test case where
we have multiple hierarchical PEs shown as following figure:
+-----------------+
| PE#3 p2p#0 |
| p2p#1 |
+-----------------+
|
+-----------------+
| PE#4 pdev#0 |
| pdev#1 |
+-----------------+
PE#4 (have 2 PCI devices) is the child of PE#3, which has 2 p2p
bridges. We accidentally had less-known scenario: PE#4 was removed
permanently from the system because of permanent failure (e.g.
exceeding the max allowd failure times in last hour), then we detects
EEH errors on PE#3 and tried to recover it. However, eeh_dev instances
for pdev#0/1 were not detached from PE#4, which was still connected to
PE#3. All of that was because of the fact that we rely on count-based
pcibios_release_device(), which isn't reliable enough. When doing
recovery for PE#3, we still apply hotplug on PE#4 and pdev#0/1, which
are not valid any more. Eventually, we run into kernel crash.
The patch fixes above issue from two aspects. For unplug, we simply
skip those permanently removed PE, whose state is (EEH_PE_STATE_ISOLATED
&& !EEH_PE_STATE_RECOVERING) and its frozen count should be greater
than EEH_MAX_ALLOWED_FREEZES. For plug, we marked all permanently
removed EEH devices with EEH_DEV_REMOVED and return 0xFF's on read
its PCI config so that PCI core will omit them.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-04-24 16:00:19 +08:00
|
|
|
/* Keep the state of permanently removed PE intact */
|
2014-12-11 11:28:55 +08:00
|
|
|
if (pe->state & EEH_PE_REMOVED)
|
powerpc/eeh: No hotplug on permanently removed dev
The issue was detected in a bit complicated test case where
we have multiple hierarchical PEs shown as following figure:
+-----------------+
| PE#3 p2p#0 |
| p2p#1 |
+-----------------+
|
+-----------------+
| PE#4 pdev#0 |
| pdev#1 |
+-----------------+
PE#4 (have 2 PCI devices) is the child of PE#3, which has 2 p2p
bridges. We accidentally had less-known scenario: PE#4 was removed
permanently from the system because of permanent failure (e.g.
exceeding the max allowd failure times in last hour), then we detects
EEH errors on PE#3 and tried to recover it. However, eeh_dev instances
for pdev#0/1 were not detached from PE#4, which was still connected to
PE#3. All of that was because of the fact that we rely on count-based
pcibios_release_device(), which isn't reliable enough. When doing
recovery for PE#3, we still apply hotplug on PE#4 and pdev#0/1, which
are not valid any more. Eventually, we run into kernel crash.
The patch fixes above issue from two aspects. For unplug, we simply
skip those permanently removed PE, whose state is (EEH_PE_STATE_ISOLATED
&& !EEH_PE_STATE_RECOVERING) and its frozen count should be greater
than EEH_MAX_ALLOWED_FREEZES. For plug, we marked all permanently
removed EEH devices with EEH_DEV_REMOVED and return 0xFF's on read
its PCI config so that PCI core will omit them.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-04-24 16:00:19 +08:00
|
|
|
return NULL;
|
|
|
|
|
2012-09-08 06:44:12 +08:00
|
|
|
pe->state |= state;
|
powerpc/eeh: No hotplug on permanently removed dev
The issue was detected in a bit complicated test case where
we have multiple hierarchical PEs shown as following figure:
+-----------------+
| PE#3 p2p#0 |
| p2p#1 |
+-----------------+
|
+-----------------+
| PE#4 pdev#0 |
| pdev#1 |
+-----------------+
PE#4 (have 2 PCI devices) is the child of PE#3, which has 2 p2p
bridges. We accidentally had less-known scenario: PE#4 was removed
permanently from the system because of permanent failure (e.g.
exceeding the max allowd failure times in last hour), then we detects
EEH errors on PE#3 and tried to recover it. However, eeh_dev instances
for pdev#0/1 were not detached from PE#4, which was still connected to
PE#3. All of that was because of the fact that we rely on count-based
pcibios_release_device(), which isn't reliable enough. When doing
recovery for PE#3, we still apply hotplug on PE#4 and pdev#0/1, which
are not valid any more. Eventually, we run into kernel crash.
The patch fixes above issue from two aspects. For unplug, we simply
skip those permanently removed PE, whose state is (EEH_PE_STATE_ISOLATED
&& !EEH_PE_STATE_RECOVERING) and its frozen count should be greater
than EEH_MAX_ALLOWED_FREEZES. For plug, we marked all permanently
removed EEH devices with EEH_DEV_REMOVED and return 0xFF's on read
its PCI config so that PCI core will omit them.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-04-24 16:00:19 +08:00
|
|
|
|
|
|
|
/* Offline PCI devices if applicable */
|
2014-10-01 15:07:49 +08:00
|
|
|
if (!(state & EEH_PE_ISOLATED))
|
powerpc/eeh: No hotplug on permanently removed dev
The issue was detected in a bit complicated test case where
we have multiple hierarchical PEs shown as following figure:
+-----------------+
| PE#3 p2p#0 |
| p2p#1 |
+-----------------+
|
+-----------------+
| PE#4 pdev#0 |
| pdev#1 |
+-----------------+
PE#4 (have 2 PCI devices) is the child of PE#3, which has 2 p2p
bridges. We accidentally had less-known scenario: PE#4 was removed
permanently from the system because of permanent failure (e.g.
exceeding the max allowd failure times in last hour), then we detects
EEH errors on PE#3 and tried to recover it. However, eeh_dev instances
for pdev#0/1 were not detached from PE#4, which was still connected to
PE#3. All of that was because of the fact that we rely on count-based
pcibios_release_device(), which isn't reliable enough. When doing
recovery for PE#3, we still apply hotplug on PE#4 and pdev#0/1, which
are not valid any more. Eventually, we run into kernel crash.
The patch fixes above issue from two aspects. For unplug, we simply
skip those permanently removed PE, whose state is (EEH_PE_STATE_ISOLATED
&& !EEH_PE_STATE_RECOVERING) and its frozen count should be greater
than EEH_MAX_ALLOWED_FREEZES. For plug, we marked all permanently
removed EEH devices with EEH_DEV_REMOVED and return 0xFF's on read
its PCI config so that PCI core will omit them.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-04-24 16:00:19 +08:00
|
|
|
return NULL;
|
|
|
|
|
2013-07-24 10:24:56 +08:00
|
|
|
eeh_pe_for_each_dev(pe, edev, tmp) {
|
|
|
|
pdev = eeh_dev_to_pci_dev(edev);
|
2012-09-08 06:44:12 +08:00
|
|
|
if (pdev)
|
|
|
|
pdev->error_state = pci_channel_io_frozen;
|
|
|
|
}
|
|
|
|
|
2014-10-01 15:07:53 +08:00
|
|
|
/* Block PCI config access if required */
|
|
|
|
if (pe->state & EEH_PE_CFG_RESTRICTED)
|
|
|
|
pe->state |= EEH_PE_CFG_BLOCKED;
|
|
|
|
|
2012-09-08 06:44:12 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eeh_pe_state_mark - Mark specified state for PE and its associated device
|
|
|
|
* @pe: EEH PE
|
|
|
|
*
|
|
|
|
* EEH error affects the current PE and its child PEs. The function
|
|
|
|
* is used to mark appropriate state for the affected PEs and the
|
|
|
|
* associated devices.
|
|
|
|
*/
|
|
|
|
void eeh_pe_state_mark(struct eeh_pe *pe, int state)
|
|
|
|
{
|
|
|
|
eeh_pe_traverse(pe, __eeh_pe_state_mark, &state);
|
|
|
|
}
|
|
|
|
|
powerpc/eeh: No hotplug on permanently removed dev
The issue was detected in a bit complicated test case where
we have multiple hierarchical PEs shown as following figure:
+-----------------+
| PE#3 p2p#0 |
| p2p#1 |
+-----------------+
|
+-----------------+
| PE#4 pdev#0 |
| pdev#1 |
+-----------------+
PE#4 (have 2 PCI devices) is the child of PE#3, which has 2 p2p
bridges. We accidentally had less-known scenario: PE#4 was removed
permanently from the system because of permanent failure (e.g.
exceeding the max allowd failure times in last hour), then we detects
EEH errors on PE#3 and tried to recover it. However, eeh_dev instances
for pdev#0/1 were not detached from PE#4, which was still connected to
PE#3. All of that was because of the fact that we rely on count-based
pcibios_release_device(), which isn't reliable enough. When doing
recovery for PE#3, we still apply hotplug on PE#4 and pdev#0/1, which
are not valid any more. Eventually, we run into kernel crash.
The patch fixes above issue from two aspects. For unplug, we simply
skip those permanently removed PE, whose state is (EEH_PE_STATE_ISOLATED
&& !EEH_PE_STATE_RECOVERING) and its frozen count should be greater
than EEH_MAX_ALLOWED_FREEZES. For plug, we marked all permanently
removed EEH devices with EEH_DEV_REMOVED and return 0xFF's on read
its PCI config so that PCI core will omit them.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-04-24 16:00:19 +08:00
|
|
|
static void *__eeh_pe_dev_mode_mark(void *data, void *flag)
|
|
|
|
{
|
|
|
|
struct eeh_dev *edev = data;
|
|
|
|
int mode = *((int *)flag);
|
|
|
|
|
|
|
|
edev->mode |= mode;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eeh_pe_dev_state_mark - Mark state for all device under the PE
|
|
|
|
* @pe: EEH PE
|
|
|
|
*
|
|
|
|
* Mark specific state for all child devices of the PE.
|
|
|
|
*/
|
|
|
|
void eeh_pe_dev_mode_mark(struct eeh_pe *pe, int mode)
|
|
|
|
{
|
|
|
|
eeh_pe_dev_traverse(pe, __eeh_pe_dev_mode_mark, &mode);
|
|
|
|
}
|
|
|
|
|
2012-09-08 06:44:12 +08:00
|
|
|
/**
|
|
|
|
* __eeh_pe_state_clear - Clear state for the PE
|
|
|
|
* @data: EEH PE
|
|
|
|
* @flag: state
|
|
|
|
*
|
|
|
|
* The function is used to clear the indicated state from the
|
|
|
|
* given PE. Besides, we also clear the check count of the PE
|
|
|
|
* as well.
|
|
|
|
*/
|
|
|
|
static void *__eeh_pe_state_clear(void *data, void *flag)
|
|
|
|
{
|
|
|
|
struct eeh_pe *pe = (struct eeh_pe *)data;
|
|
|
|
int state = *((int *)flag);
|
2014-09-30 10:38:59 +08:00
|
|
|
struct eeh_dev *edev, *tmp;
|
|
|
|
struct pci_dev *pdev;
|
2012-09-08 06:44:12 +08:00
|
|
|
|
powerpc/eeh: No hotplug on permanently removed dev
The issue was detected in a bit complicated test case where
we have multiple hierarchical PEs shown as following figure:
+-----------------+
| PE#3 p2p#0 |
| p2p#1 |
+-----------------+
|
+-----------------+
| PE#4 pdev#0 |
| pdev#1 |
+-----------------+
PE#4 (have 2 PCI devices) is the child of PE#3, which has 2 p2p
bridges. We accidentally had less-known scenario: PE#4 was removed
permanently from the system because of permanent failure (e.g.
exceeding the max allowd failure times in last hour), then we detects
EEH errors on PE#3 and tried to recover it. However, eeh_dev instances
for pdev#0/1 were not detached from PE#4, which was still connected to
PE#3. All of that was because of the fact that we rely on count-based
pcibios_release_device(), which isn't reliable enough. When doing
recovery for PE#3, we still apply hotplug on PE#4 and pdev#0/1, which
are not valid any more. Eventually, we run into kernel crash.
The patch fixes above issue from two aspects. For unplug, we simply
skip those permanently removed PE, whose state is (EEH_PE_STATE_ISOLATED
&& !EEH_PE_STATE_RECOVERING) and its frozen count should be greater
than EEH_MAX_ALLOWED_FREEZES. For plug, we marked all permanently
removed EEH devices with EEH_DEV_REMOVED and return 0xFF's on read
its PCI config so that PCI core will omit them.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-04-24 16:00:19 +08:00
|
|
|
/* Keep the state of permanently removed PE intact */
|
2014-12-11 11:28:55 +08:00
|
|
|
if (pe->state & EEH_PE_REMOVED)
|
powerpc/eeh: No hotplug on permanently removed dev
The issue was detected in a bit complicated test case where
we have multiple hierarchical PEs shown as following figure:
+-----------------+
| PE#3 p2p#0 |
| p2p#1 |
+-----------------+
|
+-----------------+
| PE#4 pdev#0 |
| pdev#1 |
+-----------------+
PE#4 (have 2 PCI devices) is the child of PE#3, which has 2 p2p
bridges. We accidentally had less-known scenario: PE#4 was removed
permanently from the system because of permanent failure (e.g.
exceeding the max allowd failure times in last hour), then we detects
EEH errors on PE#3 and tried to recover it. However, eeh_dev instances
for pdev#0/1 were not detached from PE#4, which was still connected to
PE#3. All of that was because of the fact that we rely on count-based
pcibios_release_device(), which isn't reliable enough. When doing
recovery for PE#3, we still apply hotplug on PE#4 and pdev#0/1, which
are not valid any more. Eventually, we run into kernel crash.
The patch fixes above issue from two aspects. For unplug, we simply
skip those permanently removed PE, whose state is (EEH_PE_STATE_ISOLATED
&& !EEH_PE_STATE_RECOVERING) and its frozen count should be greater
than EEH_MAX_ALLOWED_FREEZES. For plug, we marked all permanently
removed EEH devices with EEH_DEV_REMOVED and return 0xFF's on read
its PCI config so that PCI core will omit them.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-04-24 16:00:19 +08:00
|
|
|
return NULL;
|
|
|
|
|
2012-09-08 06:44:12 +08:00
|
|
|
pe->state &= ~state;
|
powerpc/eeh: No hotplug on permanently removed dev
The issue was detected in a bit complicated test case where
we have multiple hierarchical PEs shown as following figure:
+-----------------+
| PE#3 p2p#0 |
| p2p#1 |
+-----------------+
|
+-----------------+
| PE#4 pdev#0 |
| pdev#1 |
+-----------------+
PE#4 (have 2 PCI devices) is the child of PE#3, which has 2 p2p
bridges. We accidentally had less-known scenario: PE#4 was removed
permanently from the system because of permanent failure (e.g.
exceeding the max allowd failure times in last hour), then we detects
EEH errors on PE#3 and tried to recover it. However, eeh_dev instances
for pdev#0/1 were not detached from PE#4, which was still connected to
PE#3. All of that was because of the fact that we rely on count-based
pcibios_release_device(), which isn't reliable enough. When doing
recovery for PE#3, we still apply hotplug on PE#4 and pdev#0/1, which
are not valid any more. Eventually, we run into kernel crash.
The patch fixes above issue from two aspects. For unplug, we simply
skip those permanently removed PE, whose state is (EEH_PE_STATE_ISOLATED
&& !EEH_PE_STATE_RECOVERING) and its frozen count should be greater
than EEH_MAX_ALLOWED_FREEZES. For plug, we marked all permanently
removed EEH devices with EEH_DEV_REMOVED and return 0xFF's on read
its PCI config so that PCI core will omit them.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-04-24 16:00:19 +08:00
|
|
|
|
2014-09-30 10:38:59 +08:00
|
|
|
/*
|
|
|
|
* Special treatment on clearing isolated state. Clear
|
|
|
|
* check count since last isolation and put all affected
|
|
|
|
* devices to normal state.
|
|
|
|
*/
|
|
|
|
if (!(state & EEH_PE_ISOLATED))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pe->check_count = 0;
|
|
|
|
eeh_pe_for_each_dev(pe, edev, tmp) {
|
|
|
|
pdev = eeh_dev_to_pci_dev(edev);
|
|
|
|
if (!pdev)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pdev->error_state = pci_channel_io_normal;
|
|
|
|
}
|
2012-09-08 06:44:12 +08:00
|
|
|
|
2014-10-01 15:07:53 +08:00
|
|
|
/* Unblock PCI config access if required */
|
|
|
|
if (pe->state & EEH_PE_CFG_RESTRICTED)
|
|
|
|
pe->state &= ~EEH_PE_CFG_BLOCKED;
|
|
|
|
|
2012-09-08 06:44:12 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eeh_pe_state_clear - Clear state for the PE and its children
|
|
|
|
* @pe: PE
|
|
|
|
* @state: state to be cleared
|
|
|
|
*
|
|
|
|
* When the PE and its children has been recovered from error,
|
|
|
|
* we need clear the error state for that. The function is used
|
|
|
|
* for the purpose.
|
|
|
|
*/
|
|
|
|
void eeh_pe_state_clear(struct eeh_pe *pe, int state)
|
|
|
|
{
|
|
|
|
eeh_pe_traverse(pe, __eeh_pe_state_clear, &state);
|
|
|
|
}
|
2012-09-08 06:44:15 +08:00
|
|
|
|
2015-07-30 07:26:51 +08:00
|
|
|
/**
|
|
|
|
* eeh_pe_state_mark_with_cfg - Mark PE state with unblocked config space
|
|
|
|
* @pe: PE
|
|
|
|
* @state: PE state to be set
|
|
|
|
*
|
|
|
|
* Set specified flag to PE and its child PEs. The PCI config space
|
|
|
|
* of some PEs is blocked automatically when EEH_PE_ISOLATED is set,
|
|
|
|
* which isn't needed in some situations. The function allows to set
|
|
|
|
* the specified flag to indicated PEs without blocking their PCI
|
|
|
|
* config space.
|
|
|
|
*/
|
|
|
|
void eeh_pe_state_mark_with_cfg(struct eeh_pe *pe, int state)
|
|
|
|
{
|
|
|
|
eeh_pe_traverse(pe, __eeh_pe_state_mark, &state);
|
|
|
|
if (!(state & EEH_PE_ISOLATED))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Clear EEH_PE_CFG_BLOCKED, which might be set just now */
|
|
|
|
state = EEH_PE_CFG_BLOCKED;
|
|
|
|
eeh_pe_traverse(pe, __eeh_pe_state_clear, &state);
|
|
|
|
}
|
|
|
|
|
2013-06-27 13:46:43 +08:00
|
|
|
/*
|
|
|
|
* Some PCI bridges (e.g. PLX bridges) have primary/secondary
|
|
|
|
* buses assigned explicitly by firmware, and we probably have
|
|
|
|
* lost that after reset. So we have to delay the check until
|
|
|
|
* the PCI-CFG registers have been restored for the parent
|
|
|
|
* bridge.
|
2012-09-08 06:44:15 +08:00
|
|
|
*
|
2013-06-27 13:46:43 +08:00
|
|
|
* Don't use normal PCI-CFG accessors, which probably has been
|
|
|
|
* blocked on normal path during the stage. So we need utilize
|
|
|
|
* eeh operations, which is always permitted.
|
2012-09-08 06:44:15 +08:00
|
|
|
*/
|
2015-03-17 13:15:07 +08:00
|
|
|
static void eeh_bridge_check_link(struct eeh_dev *edev)
|
2013-06-27 13:46:43 +08:00
|
|
|
{
|
2015-03-17 13:15:07 +08:00
|
|
|
struct pci_dn *pdn = eeh_dev_to_pdn(edev);
|
2013-06-27 13:46:43 +08:00
|
|
|
int cap;
|
|
|
|
uint32_t val;
|
|
|
|
int timeout = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We only check root port and downstream ports of
|
|
|
|
* PCIe switches
|
|
|
|
*/
|
2013-07-24 10:24:59 +08:00
|
|
|
if (!(edev->mode & (EEH_DEV_ROOT_PORT | EEH_DEV_DS_PORT)))
|
2013-06-27 13:46:43 +08:00
|
|
|
return;
|
|
|
|
|
2013-07-24 10:24:59 +08:00
|
|
|
pr_debug("%s: Check PCIe link for %04x:%02x:%02x.%01x ...\n",
|
|
|
|
__func__, edev->phb->global_number,
|
|
|
|
edev->config_addr >> 8,
|
|
|
|
PCI_SLOT(edev->config_addr & 0xFF),
|
|
|
|
PCI_FUNC(edev->config_addr & 0xFF));
|
2013-06-27 13:46:43 +08:00
|
|
|
|
|
|
|
/* Check slot status */
|
2013-07-24 10:24:59 +08:00
|
|
|
cap = edev->pcie_cap;
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->read_config(pdn, cap + PCI_EXP_SLTSTA, 2, &val);
|
2013-06-27 13:46:43 +08:00
|
|
|
if (!(val & PCI_EXP_SLTSTA_PDS)) {
|
|
|
|
pr_debug(" No card in the slot (0x%04x) !\n", val);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check power status if we have the capability */
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->read_config(pdn, cap + PCI_EXP_SLTCAP, 2, &val);
|
2013-06-27 13:46:43 +08:00
|
|
|
if (val & PCI_EXP_SLTCAP_PCP) {
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->read_config(pdn, cap + PCI_EXP_SLTCTL, 2, &val);
|
2013-06-27 13:46:43 +08:00
|
|
|
if (val & PCI_EXP_SLTCTL_PCC) {
|
|
|
|
pr_debug(" In power-off state, power it on ...\n");
|
|
|
|
val &= ~(PCI_EXP_SLTCTL_PCC | PCI_EXP_SLTCTL_PIC);
|
|
|
|
val |= (0x0100 & PCI_EXP_SLTCTL_PIC);
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->write_config(pdn, cap + PCI_EXP_SLTCTL, 2, val);
|
2013-06-27 13:46:43 +08:00
|
|
|
msleep(2 * 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable link */
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->read_config(pdn, cap + PCI_EXP_LNKCTL, 2, &val);
|
2013-06-27 13:46:43 +08:00
|
|
|
val &= ~PCI_EXP_LNKCTL_LD;
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->write_config(pdn, cap + PCI_EXP_LNKCTL, 2, val);
|
2013-06-27 13:46:43 +08:00
|
|
|
|
|
|
|
/* Check link */
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->read_config(pdn, cap + PCI_EXP_LNKCAP, 4, &val);
|
2013-06-27 13:46:43 +08:00
|
|
|
if (!(val & PCI_EXP_LNKCAP_DLLLARC)) {
|
|
|
|
pr_debug(" No link reporting capability (0x%08x) \n", val);
|
|
|
|
msleep(1000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait the link is up until timeout (5s) */
|
|
|
|
timeout = 0;
|
|
|
|
while (timeout < 5000) {
|
|
|
|
msleep(20);
|
|
|
|
timeout += 20;
|
|
|
|
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->read_config(pdn, cap + PCI_EXP_LNKSTA, 2, &val);
|
2013-06-27 13:46:43 +08:00
|
|
|
if (val & PCI_EXP_LNKSTA_DLLLA)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val & PCI_EXP_LNKSTA_DLLLA)
|
|
|
|
pr_debug(" Link up (%s)\n",
|
|
|
|
(val & PCI_EXP_LNKSTA_CLS_2_5GB) ? "2.5GB" : "5GB");
|
|
|
|
else
|
|
|
|
pr_debug(" Link not ready (0x%04x)\n", val);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BYTE_SWAP(OFF) (8*((OFF)/4)+3-(OFF))
|
|
|
|
#define SAVED_BYTE(OFF) (((u8 *)(edev->config_space))[BYTE_SWAP(OFF)])
|
|
|
|
|
2015-03-17 13:15:07 +08:00
|
|
|
static void eeh_restore_bridge_bars(struct eeh_dev *edev)
|
2013-06-27 13:46:43 +08:00
|
|
|
{
|
2015-03-17 13:15:07 +08:00
|
|
|
struct pci_dn *pdn = eeh_dev_to_pdn(edev);
|
2013-06-27 13:46:43 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device BARs: 0x10 - 0x18
|
|
|
|
* Bus numbers and windows: 0x18 - 0x30
|
|
|
|
*/
|
|
|
|
for (i = 4; i < 13; i++)
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->write_config(pdn, i*4, 4, edev->config_space[i]);
|
2013-06-27 13:46:43 +08:00
|
|
|
/* Rom: 0x38 */
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->write_config(pdn, 14*4, 4, edev->config_space[14]);
|
2013-06-27 13:46:43 +08:00
|
|
|
|
|
|
|
/* Cache line & Latency timer: 0xC 0xD */
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->write_config(pdn, PCI_CACHE_LINE_SIZE, 1,
|
2013-06-27 13:46:43 +08:00
|
|
|
SAVED_BYTE(PCI_CACHE_LINE_SIZE));
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->write_config(pdn, PCI_LATENCY_TIMER, 1,
|
2013-06-27 13:46:43 +08:00
|
|
|
SAVED_BYTE(PCI_LATENCY_TIMER));
|
|
|
|
/* Max latency, min grant, interrupt ping and line: 0x3C */
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->write_config(pdn, 15*4, 4, edev->config_space[15]);
|
2013-06-27 13:46:43 +08:00
|
|
|
|
|
|
|
/* PCI Command: 0x4 */
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->write_config(pdn, PCI_COMMAND, 4, edev->config_space[1]);
|
2013-06-27 13:46:43 +08:00
|
|
|
|
|
|
|
/* Check the PCIe link is ready */
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_bridge_check_link(edev);
|
2013-06-27 13:46:43 +08:00
|
|
|
}
|
|
|
|
|
2015-03-17 13:15:07 +08:00
|
|
|
static void eeh_restore_device_bars(struct eeh_dev *edev)
|
2012-09-08 06:44:15 +08:00
|
|
|
{
|
2015-03-17 13:15:07 +08:00
|
|
|
struct pci_dn *pdn = eeh_dev_to_pdn(edev);
|
2012-09-08 06:44:15 +08:00
|
|
|
int i;
|
|
|
|
u32 cmd;
|
|
|
|
|
|
|
|
for (i = 4; i < 10; i++)
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->write_config(pdn, i*4, 4, edev->config_space[i]);
|
2012-09-08 06:44:15 +08:00
|
|
|
/* 12 == Expansion ROM Address */
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->write_config(pdn, 12*4, 4, edev->config_space[12]);
|
2012-09-08 06:44:15 +08:00
|
|
|
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->write_config(pdn, PCI_CACHE_LINE_SIZE, 1,
|
2012-09-08 06:44:15 +08:00
|
|
|
SAVED_BYTE(PCI_CACHE_LINE_SIZE));
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->write_config(pdn, PCI_LATENCY_TIMER, 1,
|
2012-09-08 06:44:15 +08:00
|
|
|
SAVED_BYTE(PCI_LATENCY_TIMER));
|
|
|
|
|
|
|
|
/* max latency, min grant, interrupt pin and line */
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->write_config(pdn, 15*4, 4, edev->config_space[15]);
|
2012-09-08 06:44:15 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Restore PERR & SERR bits, some devices require it,
|
|
|
|
* don't touch the other command bits
|
|
|
|
*/
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->read_config(pdn, PCI_COMMAND, 4, &cmd);
|
2012-09-08 06:44:15 +08:00
|
|
|
if (edev->config_space[1] & PCI_COMMAND_PARITY)
|
|
|
|
cmd |= PCI_COMMAND_PARITY;
|
|
|
|
else
|
|
|
|
cmd &= ~PCI_COMMAND_PARITY;
|
|
|
|
if (edev->config_space[1] & PCI_COMMAND_SERR)
|
|
|
|
cmd |= PCI_COMMAND_SERR;
|
|
|
|
else
|
|
|
|
cmd &= ~PCI_COMMAND_SERR;
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_ops->write_config(pdn, PCI_COMMAND, 4, cmd);
|
2013-06-27 13:46:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eeh_restore_one_device_bars - Restore the Base Address Registers for one device
|
|
|
|
* @data: EEH device
|
|
|
|
* @flag: Unused
|
|
|
|
*
|
|
|
|
* Loads the PCI configuration space base address registers,
|
|
|
|
* the expansion ROM base address, the latency timer, and etc.
|
|
|
|
* from the saved values in the device node.
|
|
|
|
*/
|
|
|
|
static void *eeh_restore_one_device_bars(void *data, void *flag)
|
|
|
|
{
|
|
|
|
struct eeh_dev *edev = (struct eeh_dev *)data;
|
2015-03-17 13:15:07 +08:00
|
|
|
struct pci_dn *pdn = eeh_dev_to_pdn(edev);
|
2013-06-27 13:46:43 +08:00
|
|
|
|
powerpc/eeh: Use partial hotplug for EEH unaware drivers
When EEH error happens to one specific PE, some devices with drivers
supporting EEH won't except hotplug on the device. However, there
might have other deivces without driver, or with driver without EEH
support. For the case, we need do partial hotplug in order to make
sure that the PE becomes absolutely quite during reset. Otherise,
the PE reset might fail and leads to failure of error recovery.
The current code doesn't handle that 'mixed' case properly, it either
uses the error callbacks to the drivers, or tries hotplug, but doesn't
handle a PE (EEH domain) composed of a combination of the two.
The patch intends to support so-called "partial" hotplug for EEH:
Before we do reset, we stop and remove those PCI devices without
EEH sensitive driver. The corresponding EEH devices are not detached
from its PE, but with special flag. After the reset is done, those
EEH devices with the special flag will be scanned one by one.
Signed-off-by: Gavin Shan <shangw@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-07-24 10:24:58 +08:00
|
|
|
/* Do special restore for bridges */
|
2013-07-24 10:24:59 +08:00
|
|
|
if (edev->mode & EEH_DEV_BRIDGE)
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_restore_bridge_bars(edev);
|
2013-06-27 13:46:43 +08:00
|
|
|
else
|
2015-03-17 13:15:07 +08:00
|
|
|
eeh_restore_device_bars(edev);
|
2012-09-08 06:44:15 +08:00
|
|
|
|
2015-03-17 13:15:07 +08:00
|
|
|
if (eeh_ops->restore_config && pdn)
|
|
|
|
eeh_ops->restore_config(pdn);
|
2014-01-03 17:47:12 +08:00
|
|
|
|
2012-09-08 06:44:15 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eeh_pe_restore_bars - Restore the PCI config space info
|
|
|
|
* @pe: EEH PE
|
|
|
|
*
|
|
|
|
* This routine performs a recursive walk to the children
|
|
|
|
* of this device as well.
|
|
|
|
*/
|
|
|
|
void eeh_pe_restore_bars(struct eeh_pe *pe)
|
|
|
|
{
|
2012-09-12 03:16:18 +08:00
|
|
|
/*
|
|
|
|
* We needn't take the EEH lock since eeh_pe_dev_traverse()
|
|
|
|
* will take that.
|
|
|
|
*/
|
2012-09-08 06:44:15 +08:00
|
|
|
eeh_pe_dev_traverse(pe, eeh_restore_one_device_bars, NULL);
|
|
|
|
}
|
2012-09-08 06:44:19 +08:00
|
|
|
|
2014-06-11 16:26:44 +08:00
|
|
|
/**
|
|
|
|
* eeh_pe_loc_get - Retrieve location code binding to the given PE
|
|
|
|
* @pe: EEH PE
|
|
|
|
*
|
|
|
|
* Retrieve the location code of the given PE. If the primary PE bus
|
|
|
|
* is root bus, we will grab location code from PHB device tree node
|
|
|
|
* or root port. Otherwise, the upstream bridge's device tree node
|
|
|
|
* of the primary PE bus will be checked for the location code.
|
|
|
|
*/
|
|
|
|
const char *eeh_pe_loc_get(struct eeh_pe *pe)
|
|
|
|
{
|
|
|
|
struct pci_bus *bus = eeh_pe_bus_get(pe);
|
2015-12-02 13:25:32 +08:00
|
|
|
struct device_node *dn;
|
2014-07-15 13:42:22 +08:00
|
|
|
const char *loc = NULL;
|
2014-06-11 16:26:44 +08:00
|
|
|
|
2015-12-02 13:25:32 +08:00
|
|
|
while (bus) {
|
|
|
|
dn = pci_bus_to_OF_node(bus);
|
|
|
|
if (!dn) {
|
|
|
|
bus = bus->parent;
|
|
|
|
continue;
|
|
|
|
}
|
2014-06-11 16:26:44 +08:00
|
|
|
|
2015-12-02 13:25:32 +08:00
|
|
|
if (pci_is_root_bus(bus))
|
2014-07-15 13:42:22 +08:00
|
|
|
loc = of_get_property(dn, "ibm,io-base-loc-code", NULL);
|
2015-12-02 13:25:32 +08:00
|
|
|
else
|
|
|
|
loc = of_get_property(dn, "ibm,slot-location-code",
|
|
|
|
NULL);
|
|
|
|
|
2014-06-11 16:26:44 +08:00
|
|
|
if (loc)
|
2015-12-02 13:25:32 +08:00
|
|
|
return loc;
|
2014-06-11 16:26:44 +08:00
|
|
|
|
2015-12-02 13:25:32 +08:00
|
|
|
bus = bus->parent;
|
2014-06-11 16:26:44 +08:00
|
|
|
}
|
|
|
|
|
2015-12-02 13:25:32 +08:00
|
|
|
return "N/A";
|
2014-06-11 16:26:44 +08:00
|
|
|
}
|
|
|
|
|
2012-09-08 06:44:19 +08:00
|
|
|
/**
|
|
|
|
* eeh_pe_bus_get - Retrieve PCI bus according to the given PE
|
|
|
|
* @pe: EEH PE
|
|
|
|
*
|
|
|
|
* Retrieve the PCI bus according to the given PE. Basically,
|
|
|
|
* there're 3 types of PEs: PHB/Bus/Device. For PHB PE, the
|
|
|
|
* primary PCI bus will be retrieved. The parent bus will be
|
|
|
|
* returned for BUS PE. However, we don't have associated PCI
|
|
|
|
* bus for DEVICE PE.
|
|
|
|
*/
|
|
|
|
struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe)
|
|
|
|
{
|
|
|
|
struct pci_bus *bus = NULL;
|
|
|
|
struct eeh_dev *edev;
|
|
|
|
struct pci_dev *pdev;
|
|
|
|
|
2012-09-12 03:16:16 +08:00
|
|
|
if (pe->type & EEH_PE_PHB) {
|
2012-09-08 06:44:19 +08:00
|
|
|
bus = pe->phb->bus;
|
2013-06-05 15:34:02 +08:00
|
|
|
} else if (pe->type & EEH_PE_BUS ||
|
|
|
|
pe->type & EEH_PE_DEVICE) {
|
2016-02-09 12:50:21 +08:00
|
|
|
if (pe->state & EEH_PE_PRI_BUS) {
|
2013-06-20 13:20:55 +08:00
|
|
|
bus = pe->bus;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2012-09-08 06:44:19 +08:00
|
|
|
edev = list_first_entry(&pe->edevs, struct eeh_dev, list);
|
|
|
|
pdev = eeh_dev_to_pci_dev(edev);
|
|
|
|
if (pdev)
|
|
|
|
bus = pdev->bus;
|
|
|
|
}
|
|
|
|
|
2013-06-20 13:20:55 +08:00
|
|
|
out:
|
2012-09-08 06:44:19 +08:00
|
|
|
return bus;
|
|
|
|
}
|