Path: blob/master/arch/powerpc/platforms/pseries/eeh_pseries.c
26481 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* The file intends to implement the platform dependent EEH operations on pseries.3* Actually, the pseries platform is built based on RTAS heavily. That means the4* pseries platform dependent EEH operations will be built on RTAS calls. The functions5* are derived from arch/powerpc/platforms/pseries/eeh.c and necessary cleanup has6* been done.7*8* Copyright Benjamin Herrenschmidt & Gavin Shan, IBM Corporation 2011.9* Copyright IBM Corporation 2001, 2005, 200610* Copyright Dave Engebretsen & Todd Inglett 200111* Copyright Linas Vepstas 2005, 200612*/1314#include <linux/atomic.h>15#include <linux/delay.h>16#include <linux/export.h>17#include <linux/init.h>18#include <linux/list.h>19#include <linux/of.h>20#include <linux/pci.h>21#include <linux/proc_fs.h>22#include <linux/rbtree.h>23#include <linux/sched.h>24#include <linux/seq_file.h>25#include <linux/spinlock.h>26#include <linux/crash_dump.h>2728#include <asm/eeh.h>29#include <asm/eeh_event.h>30#include <asm/io.h>31#include <asm/machdep.h>32#include <asm/ppc-pci.h>33#include <asm/rtas.h>3435/* RTAS tokens */36static int ibm_set_eeh_option;37static int ibm_set_slot_reset;38static int ibm_read_slot_reset_state;39static int ibm_read_slot_reset_state2;40static int ibm_slot_error_detail;41static int ibm_get_config_addr_info;42static int ibm_get_config_addr_info2;43static int ibm_configure_pe;4445static void pseries_eeh_init_edev(struct pci_dn *pdn);4647static void pseries_pcibios_bus_add_device(struct pci_dev *pdev)48{49struct pci_dn *pdn = pci_get_pdn(pdev);5051if (eeh_has_flag(EEH_FORCE_DISABLED))52return;5354dev_dbg(&pdev->dev, "EEH: Setting up device\n");55#ifdef CONFIG_PCI_IOV56if (pdev->is_virtfn) {57pdn->device_id = pdev->device;58pdn->vendor_id = pdev->vendor;59pdn->class_code = pdev->class;60/*61* Last allow unfreeze return code used for retrieval62* by user space in eeh-sysfs to show the last command63* completion from platform.64*/65pdn->last_allow_rc = 0;66}67#endif68pseries_eeh_init_edev(pdn);69#ifdef CONFIG_PCI_IOV70if (pdev->is_virtfn) {71/*72* FIXME: This really should be handled by choosing the right73* parent PE in pseries_eeh_init_edev().74*/75struct eeh_pe *physfn_pe = pci_dev_to_eeh_dev(pdev->physfn)->pe;76struct eeh_dev *edev = pdn_to_eeh_dev(pdn);7778edev->pe_config_addr = (pdn->busno << 16) | (pdn->devfn << 8);79eeh_pe_tree_remove(edev); /* Remove as it is adding to bus pe */80eeh_pe_tree_insert(edev, physfn_pe); /* Add as VF PE type */81}82#endif83eeh_probe_device(pdev);84}858687/**88* pseries_eeh_get_pe_config_addr - Find the pe_config_addr for a device89* @pdn: pci_dn of the input device90*91* The EEH RTAS calls use a tuple consisting of: (buid_hi, buid_lo,92* pe_config_addr) as a handle to a given PE. This function finds the93* pe_config_addr based on the device's config addr.94*95* Keep in mind that the pe_config_addr *might* be numerically identical to the96* device's config addr, but the two are conceptually distinct.97*98* Returns the pe_config_addr, or a negative error code.99*/100static int pseries_eeh_get_pe_config_addr(struct pci_dn *pdn)101{102int config_addr = rtas_config_addr(pdn->busno, pdn->devfn, 0);103struct pci_controller *phb = pdn->phb;104int ret, rets[3];105106if (ibm_get_config_addr_info2 != RTAS_UNKNOWN_SERVICE) {107/*108* First of all, use function 1 to determine if this device is109* part of a PE or not. ret[0] being zero indicates it's not.110*/111ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,112config_addr, BUID_HI(phb->buid),113BUID_LO(phb->buid), 1);114if (ret || (rets[0] == 0))115return -ENOENT;116117/* Retrieve the associated PE config address with function 0 */118ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,119config_addr, BUID_HI(phb->buid),120BUID_LO(phb->buid), 0);121if (ret) {122pr_warn("%s: Failed to get address for PHB#%x-PE#%x\n",123__func__, phb->global_number, config_addr);124return -ENXIO;125}126127return rets[0];128}129130if (ibm_get_config_addr_info != RTAS_UNKNOWN_SERVICE) {131ret = rtas_call(ibm_get_config_addr_info, 4, 2, rets,132config_addr, BUID_HI(phb->buid),133BUID_LO(phb->buid), 0);134if (ret) {135pr_warn("%s: Failed to get address for PHB#%x-PE#%x\n",136__func__, phb->global_number, config_addr);137return -ENXIO;138}139140return rets[0];141}142143/*144* PAPR does describe a process for finding the pe_config_addr that was145* used before the ibm,get-config-addr-info calls were added. However,146* I haven't found *any* systems that don't have that RTAS call147* implemented. If you happen to find one that needs the old DT based148* process, patches are welcome!149*/150return -ENOENT;151}152153/**154* pseries_eeh_phb_reset - Reset the specified PHB155* @phb: PCI controller156* @config_addr: the associated config address157* @option: reset option158*159* Reset the specified PHB/PE160*/161static int pseries_eeh_phb_reset(struct pci_controller *phb, int config_addr, int option)162{163int ret;164165/* Reset PE through RTAS call */166ret = rtas_call(ibm_set_slot_reset, 4, 1, NULL,167config_addr, BUID_HI(phb->buid),168BUID_LO(phb->buid), option);169170/* If fundamental-reset not supported, try hot-reset */171if (option == EEH_RESET_FUNDAMENTAL && ret == -8) {172option = EEH_RESET_HOT;173ret = rtas_call(ibm_set_slot_reset, 4, 1, NULL,174config_addr, BUID_HI(phb->buid),175BUID_LO(phb->buid), option);176}177178/* We need reset hold or settlement delay */179if (option == EEH_RESET_FUNDAMENTAL || option == EEH_RESET_HOT)180msleep(EEH_PE_RST_HOLD_TIME);181else182msleep(EEH_PE_RST_SETTLE_TIME);183184return ret;185}186187/**188* pseries_eeh_phb_configure_bridge - Configure PCI bridges in the indicated PE189* @phb: PCI controller190* @config_addr: the associated config address191*192* The function will be called to reconfigure the bridges included193* in the specified PE so that the mulfunctional PE would be recovered194* again.195*/196static int pseries_eeh_phb_configure_bridge(struct pci_controller *phb, int config_addr)197{198int ret;199/* Waiting 0.2s maximum before skipping configuration */200int max_wait = 200;201202while (max_wait > 0) {203ret = rtas_call(ibm_configure_pe, 3, 1, NULL,204config_addr, BUID_HI(phb->buid),205BUID_LO(phb->buid));206207if (!ret)208return ret;209if (ret < 0)210break;211212/*213* If RTAS returns a delay value that's above 100ms, cut it214* down to 100ms in case firmware made a mistake. For more215* on how these delay values work see rtas_busy_delay_time216*/217if (ret > RTAS_EXTENDED_DELAY_MIN+2 &&218ret <= RTAS_EXTENDED_DELAY_MAX)219ret = RTAS_EXTENDED_DELAY_MIN+2;220221max_wait -= rtas_busy_delay_time(ret);222223if (max_wait < 0)224break;225226rtas_busy_delay(ret);227}228229pr_warn("%s: Unable to configure bridge PHB#%x-PE#%x (%d)\n",230__func__, phb->global_number, config_addr, ret);231/* PAPR defines -3 as "Parameter Error" for this function: */232if (ret == -3)233return -EINVAL;234else235return -EIO;236}237238/*239* Buffer for reporting slot-error-detail rtas calls. Its here240* in BSS, and not dynamically alloced, so that it ends up in241* RMO where RTAS can access it.242*/243static unsigned char slot_errbuf[RTAS_ERROR_LOG_MAX];244static DEFINE_SPINLOCK(slot_errbuf_lock);245static int eeh_error_buf_size;246247static int pseries_eeh_cap_start(struct pci_dn *pdn)248{249u32 status;250251if (!pdn)252return 0;253254rtas_pci_dn_read_config(pdn, PCI_STATUS, 2, &status);255if (!(status & PCI_STATUS_CAP_LIST))256return 0;257258return PCI_CAPABILITY_LIST;259}260261262static int pseries_eeh_find_cap(struct pci_dn *pdn, int cap)263{264int pos = pseries_eeh_cap_start(pdn);265int cnt = 48; /* Maximal number of capabilities */266u32 id;267268if (!pos)269return 0;270271while (cnt--) {272rtas_pci_dn_read_config(pdn, pos, 1, &pos);273if (pos < 0x40)274break;275pos &= ~3;276rtas_pci_dn_read_config(pdn, pos + PCI_CAP_LIST_ID, 1, &id);277if (id == 0xff)278break;279if (id == cap)280return pos;281pos += PCI_CAP_LIST_NEXT;282}283284return 0;285}286287static int pseries_eeh_find_ecap(struct pci_dn *pdn, int cap)288{289struct eeh_dev *edev = pdn_to_eeh_dev(pdn);290u32 header;291int pos = 256;292int ttl = (4096 - 256) / 8;293294if (!edev || !edev->pcie_cap)295return 0;296if (rtas_pci_dn_read_config(pdn, pos, 4, &header) != PCIBIOS_SUCCESSFUL)297return 0;298else if (!header)299return 0;300301while (ttl-- > 0) {302if (PCI_EXT_CAP_ID(header) == cap && pos)303return pos;304305pos = PCI_EXT_CAP_NEXT(header);306if (pos < 256)307break;308309if (rtas_pci_dn_read_config(pdn, pos, 4, &header) != PCIBIOS_SUCCESSFUL)310break;311}312313return 0;314}315316/**317* pseries_eeh_pe_get_parent - Retrieve the parent PE318* @edev: EEH device319*320* The whole PEs existing in the system are organized as hierarchy321* tree. The function is used to retrieve the parent PE according322* to the parent EEH device.323*/324static struct eeh_pe *pseries_eeh_pe_get_parent(struct eeh_dev *edev)325{326struct eeh_dev *parent;327struct pci_dn *pdn = eeh_dev_to_pdn(edev);328329/*330* It might have the case for the indirect parent331* EEH device already having associated PE, but332* the direct parent EEH device doesn't have yet.333*/334if (edev->physfn)335pdn = pci_get_pdn(edev->physfn);336else337pdn = pdn ? pdn->parent : NULL;338while (pdn) {339/* We're poking out of PCI territory */340parent = pdn_to_eeh_dev(pdn);341if (!parent)342return NULL;343344if (parent->pe)345return parent->pe;346347pdn = pdn->parent;348}349350return NULL;351}352353/**354* pseries_eeh_init_edev - initialise the eeh_dev and eeh_pe for a pci_dn355*356* @pdn: PCI device node357*358* When we discover a new PCI device via the device-tree we create a359* corresponding pci_dn and we allocate, but don't initialise, an eeh_dev.360* This function takes care of the initialisation and inserts the eeh_dev361* into the correct eeh_pe. If no eeh_pe exists we'll allocate one.362*/363static void pseries_eeh_init_edev(struct pci_dn *pdn)364{365struct eeh_pe pe, *parent;366struct eeh_dev *edev;367u32 pcie_flags;368int ret;369370if (WARN_ON_ONCE(!eeh_has_flag(EEH_PROBE_MODE_DEVTREE)))371return;372373/*374* Find the eeh_dev for this pdn. The storage for the eeh_dev was375* allocated at the same time as the pci_dn.376*377* XXX: We should probably re-visit that.378*/379edev = pdn_to_eeh_dev(pdn);380if (!edev)381return;382383/*384* If ->pe is set then we've already probed this device. We hit385* this path when a pci_dev is removed and rescanned while recovering386* a PE (i.e. for devices where the driver doesn't support error387* recovery).388*/389if (edev->pe)390return;391392/* Check class/vendor/device IDs */393if (!pdn->vendor_id || !pdn->device_id || !pdn->class_code)394return;395396/* Skip for PCI-ISA bridge */397if ((pdn->class_code >> 8) == PCI_CLASS_BRIDGE_ISA)398return;399400eeh_edev_dbg(edev, "Probing device\n");401402/*403* Update class code and mode of eeh device. We need404* correctly reflects that current device is root port405* or PCIe switch downstream port.406*/407edev->pcix_cap = pseries_eeh_find_cap(pdn, PCI_CAP_ID_PCIX);408edev->pcie_cap = pseries_eeh_find_cap(pdn, PCI_CAP_ID_EXP);409edev->aer_cap = pseries_eeh_find_ecap(pdn, PCI_EXT_CAP_ID_ERR);410edev->mode &= 0xFFFFFF00;411if ((pdn->class_code >> 8) == PCI_CLASS_BRIDGE_PCI) {412edev->mode |= EEH_DEV_BRIDGE;413if (edev->pcie_cap) {414rtas_pci_dn_read_config(pdn, edev->pcie_cap + PCI_EXP_FLAGS,4152, &pcie_flags);416pcie_flags = (pcie_flags & PCI_EXP_FLAGS_TYPE) >> 4;417if (pcie_flags == PCI_EXP_TYPE_ROOT_PORT)418edev->mode |= EEH_DEV_ROOT_PORT;419else if (pcie_flags == PCI_EXP_TYPE_DOWNSTREAM)420edev->mode |= EEH_DEV_DS_PORT;421}422}423424/* first up, find the pe_config_addr for the PE containing the device */425ret = pseries_eeh_get_pe_config_addr(pdn);426if (ret < 0) {427eeh_edev_dbg(edev, "Unable to find pe_config_addr\n");428goto err;429}430431/* Try enable EEH on the fake PE */432memset(&pe, 0, sizeof(struct eeh_pe));433pe.phb = pdn->phb;434pe.addr = ret;435436eeh_edev_dbg(edev, "Enabling EEH on device\n");437ret = eeh_ops->set_option(&pe, EEH_OPT_ENABLE);438if (ret) {439eeh_edev_dbg(edev, "EEH failed to enable on device (code %d)\n", ret);440goto err;441}442443edev->pe_config_addr = pe.addr;444445eeh_add_flag(EEH_ENABLED);446447parent = pseries_eeh_pe_get_parent(edev);448eeh_pe_tree_insert(edev, parent);449eeh_save_bars(edev);450eeh_edev_dbg(edev, "EEH enabled for device");451452return;453454err:455eeh_edev_dbg(edev, "EEH is unsupported on device (code = %d)\n", ret);456}457458static struct eeh_dev *pseries_eeh_probe(struct pci_dev *pdev)459{460struct eeh_dev *edev;461struct pci_dn *pdn;462463pdn = pci_get_pdn_by_devfn(pdev->bus, pdev->devfn);464if (!pdn)465return NULL;466467/*468* If the system supports EEH on this device then the eeh_dev was469* configured and inserted into a PE in pseries_eeh_init_edev()470*/471edev = pdn_to_eeh_dev(pdn);472if (!edev || !edev->pe)473return NULL;474475return edev;476}477478/**479* pseries_eeh_init_edev_recursive - Enable EEH for the indicated device480* @pdn: PCI device node481*482* This routine must be used to perform EEH initialization for the483* indicated PCI device that was added after system boot (e.g.484* hotplug, dlpar).485*/486void pseries_eeh_init_edev_recursive(struct pci_dn *pdn)487{488struct pci_dn *n;489490if (!pdn)491return;492493list_for_each_entry(n, &pdn->child_list, list)494pseries_eeh_init_edev_recursive(n);495496pseries_eeh_init_edev(pdn);497}498EXPORT_SYMBOL_GPL(pseries_eeh_init_edev_recursive);499500/**501* pseries_eeh_set_option - Initialize EEH or MMIO/DMA reenable502* @pe: EEH PE503* @option: operation to be issued504*505* The function is used to control the EEH functionality globally.506* Currently, following options are support according to PAPR:507* Enable EEH, Disable EEH, Enable MMIO and Enable DMA508*/509static int pseries_eeh_set_option(struct eeh_pe *pe, int option)510{511int ret = 0;512513/*514* When we're enabling or disabling EEH functionality on515* the particular PE, the PE config address is possibly516* unavailable. Therefore, we have to figure it out from517* the FDT node.518*/519switch (option) {520case EEH_OPT_DISABLE:521case EEH_OPT_ENABLE:522case EEH_OPT_THAW_MMIO:523case EEH_OPT_THAW_DMA:524break;525case EEH_OPT_FREEZE_PE:526/* Not support */527return 0;528default:529pr_err("%s: Invalid option %d\n", __func__, option);530return -EINVAL;531}532533ret = rtas_call(ibm_set_eeh_option, 4, 1, NULL,534pe->addr, BUID_HI(pe->phb->buid),535BUID_LO(pe->phb->buid), option);536537return ret;538}539540/**541* pseries_eeh_get_state - Retrieve PE state542* @pe: EEH PE543* @delay: suggested time to wait if state is unavailable544*545* Retrieve the state of the specified PE. On RTAS compliant546* pseries platform, there already has one dedicated RTAS function547* for the purpose. It's notable that the associated PE config address548* might be ready when calling the function. Therefore, endeavour to549* use the PE config address if possible. Further more, there're 2550* RTAS calls for the purpose, we need to try the new one and back551* to the old one if the new one couldn't work properly.552*/553static int pseries_eeh_get_state(struct eeh_pe *pe, int *delay)554{555int ret;556int rets[4];557int result;558559if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {560ret = rtas_call(ibm_read_slot_reset_state2, 3, 4, rets,561pe->addr, BUID_HI(pe->phb->buid),562BUID_LO(pe->phb->buid));563} else if (ibm_read_slot_reset_state != RTAS_UNKNOWN_SERVICE) {564/* Fake PE unavailable info */565rets[2] = 0;566ret = rtas_call(ibm_read_slot_reset_state, 3, 3, rets,567pe->addr, BUID_HI(pe->phb->buid),568BUID_LO(pe->phb->buid));569} else {570return EEH_STATE_NOT_SUPPORT;571}572573if (ret)574return ret;575576/* Parse the result out */577if (!rets[1])578return EEH_STATE_NOT_SUPPORT;579580switch(rets[0]) {581case 0:582result = EEH_STATE_MMIO_ACTIVE |583EEH_STATE_DMA_ACTIVE |584EEH_STATE_MMIO_ENABLED |585EEH_STATE_DMA_ENABLED;586break;587case 1:588result = EEH_STATE_RESET_ACTIVE |589EEH_STATE_MMIO_ACTIVE |590EEH_STATE_DMA_ACTIVE;591break;592case 2:593result = 0;594break;595case 4:596result = EEH_STATE_MMIO_ENABLED;597break;598case 5:599if (rets[2]) {600if (delay)601*delay = rets[2];602result = EEH_STATE_UNAVAILABLE;603} else {604result = EEH_STATE_NOT_SUPPORT;605}606break;607default:608result = EEH_STATE_NOT_SUPPORT;609}610611return result;612}613614/**615* pseries_eeh_reset - Reset the specified PE616* @pe: EEH PE617* @option: reset option618*619* Reset the specified PE620*/621static int pseries_eeh_reset(struct eeh_pe *pe, int option)622{623return pseries_eeh_phb_reset(pe->phb, pe->addr, option);624}625626/**627* pseries_eeh_get_log - Retrieve error log628* @pe: EEH PE629* @severity: temporary or permanent error log630* @drv_log: driver log to be combined with retrieved error log631* @len: length of driver log632*633* Retrieve the temporary or permanent error from the PE.634* Actually, the error will be retrieved through the dedicated635* RTAS call.636*/637static int pseries_eeh_get_log(struct eeh_pe *pe, int severity, char *drv_log, unsigned long len)638{639unsigned long flags;640int ret;641642spin_lock_irqsave(&slot_errbuf_lock, flags);643memset(slot_errbuf, 0, eeh_error_buf_size);644645ret = rtas_call(ibm_slot_error_detail, 8, 1, NULL, pe->addr,646BUID_HI(pe->phb->buid), BUID_LO(pe->phb->buid),647virt_to_phys(drv_log), len,648virt_to_phys(slot_errbuf), eeh_error_buf_size,649severity);650if (!ret)651log_error(slot_errbuf, ERR_TYPE_RTAS_LOG, 0);652spin_unlock_irqrestore(&slot_errbuf_lock, flags);653654return ret;655}656657/**658* pseries_eeh_configure_bridge - Configure PCI bridges in the indicated PE659* @pe: EEH PE660*661*/662static int pseries_eeh_configure_bridge(struct eeh_pe *pe)663{664return pseries_eeh_phb_configure_bridge(pe->phb, pe->addr);665}666667/**668* pseries_eeh_read_config - Read PCI config space669* @edev: EEH device handle670* @where: PCI config space offset671* @size: size to read672* @val: return value673*674* Read config space from the speicifed device675*/676static int pseries_eeh_read_config(struct eeh_dev *edev, int where, int size, u32 *val)677{678struct pci_dn *pdn = eeh_dev_to_pdn(edev);679680return rtas_pci_dn_read_config(pdn, where, size, val);681}682683/**684* pseries_eeh_write_config - Write PCI config space685* @edev: EEH device handle686* @where: PCI config space offset687* @size: size to write688* @val: value to be written689*690* Write config space to the specified device691*/692static int pseries_eeh_write_config(struct eeh_dev *edev, int where, int size, u32 val)693{694struct pci_dn *pdn = eeh_dev_to_pdn(edev);695696return rtas_pci_dn_write_config(pdn, where, size, val);697}698699#ifdef CONFIG_PCI_IOV700static int pseries_send_allow_unfreeze(struct pci_dn *pdn, u16 *vf_pe_array, int cur_vfs)701{702int rc;703int ibm_allow_unfreeze = rtas_function_token(RTAS_FN_IBM_OPEN_SRIOV_ALLOW_UNFREEZE);704unsigned long buid, addr;705706addr = rtas_config_addr(pdn->busno, pdn->devfn, 0);707buid = pdn->phb->buid;708spin_lock(&rtas_data_buf_lock);709memcpy(rtas_data_buf, vf_pe_array, RTAS_DATA_BUF_SIZE);710rc = rtas_call(ibm_allow_unfreeze, 5, 1, NULL,711addr,712BUID_HI(buid),713BUID_LO(buid),714rtas_data_buf, cur_vfs * sizeof(u16));715spin_unlock(&rtas_data_buf_lock);716if (rc)717pr_warn("%s: Failed to allow unfreeze for PHB#%x-PE#%lx, rc=%x\n",718__func__,719pdn->phb->global_number, addr, rc);720return rc;721}722723static int pseries_call_allow_unfreeze(struct eeh_dev *edev)724{725int cur_vfs = 0, rc = 0, vf_index, bus, devfn, vf_pe_num;726struct pci_dn *pdn, *tmp, *parent, *physfn_pdn;727u16 *vf_pe_array;728729vf_pe_array = kzalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL);730if (!vf_pe_array)731return -ENOMEM;732if (pci_num_vf(edev->physfn ? edev->physfn : edev->pdev)) {733if (edev->pdev->is_physfn) {734cur_vfs = pci_num_vf(edev->pdev);735pdn = eeh_dev_to_pdn(edev);736parent = pdn->parent;737for (vf_index = 0; vf_index < cur_vfs; vf_index++)738vf_pe_array[vf_index] =739cpu_to_be16(pdn->pe_num_map[vf_index]);740rc = pseries_send_allow_unfreeze(pdn, vf_pe_array,741cur_vfs);742pdn->last_allow_rc = rc;743for (vf_index = 0; vf_index < cur_vfs; vf_index++) {744list_for_each_entry_safe(pdn, tmp,745&parent->child_list,746list) {747bus = pci_iov_virtfn_bus(edev->pdev,748vf_index);749devfn = pci_iov_virtfn_devfn(edev->pdev,750vf_index);751if (pdn->busno != bus ||752pdn->devfn != devfn)753continue;754pdn->last_allow_rc = rc;755}756}757} else {758pdn = pci_get_pdn(edev->pdev);759physfn_pdn = pci_get_pdn(edev->physfn);760761vf_pe_num = physfn_pdn->pe_num_map[edev->vf_index];762vf_pe_array[0] = cpu_to_be16(vf_pe_num);763rc = pseries_send_allow_unfreeze(physfn_pdn,764vf_pe_array, 1);765pdn->last_allow_rc = rc;766}767}768769kfree(vf_pe_array);770return rc;771}772773static int pseries_notify_resume(struct eeh_dev *edev)774{775if (!edev)776return -EEXIST;777778if (rtas_function_token(RTAS_FN_IBM_OPEN_SRIOV_ALLOW_UNFREEZE) == RTAS_UNKNOWN_SERVICE)779return -EINVAL;780781if (edev->pdev->is_physfn || edev->pdev->is_virtfn)782return pseries_call_allow_unfreeze(edev);783784return 0;785}786#endif787788/**789* pseries_eeh_err_inject - Inject specified error to the indicated PE790* @pe: the indicated PE791* @type: error type792* @func: specific error type793* @addr: address794* @mask: address mask795* The routine is called to inject specified error, which is796* determined by @type and @func, to the indicated PE797*/798static int pseries_eeh_err_inject(struct eeh_pe *pe, int type, int func,799unsigned long addr, unsigned long mask)800{801struct eeh_dev *pdev;802803/* Check on PCI error type */804if (type != EEH_ERR_TYPE_32 && type != EEH_ERR_TYPE_64)805return -EINVAL;806807switch (func) {808case EEH_ERR_FUNC_LD_MEM_ADDR:809case EEH_ERR_FUNC_LD_MEM_DATA:810case EEH_ERR_FUNC_ST_MEM_ADDR:811case EEH_ERR_FUNC_ST_MEM_DATA:812/* injects a MMIO error for all pdev's belonging to PE */813pci_lock_rescan_remove();814list_for_each_entry(pdev, &pe->edevs, entry)815eeh_pe_inject_mmio_error(pdev->pdev);816pci_unlock_rescan_remove();817break;818default:819return -ERANGE;820}821822return 0;823}824825static struct eeh_ops pseries_eeh_ops = {826.name = "pseries",827.probe = pseries_eeh_probe,828.set_option = pseries_eeh_set_option,829.get_state = pseries_eeh_get_state,830.reset = pseries_eeh_reset,831.get_log = pseries_eeh_get_log,832.configure_bridge = pseries_eeh_configure_bridge,833.err_inject = pseries_eeh_err_inject,834.read_config = pseries_eeh_read_config,835.write_config = pseries_eeh_write_config,836.next_error = NULL,837.restore_config = NULL, /* NB: configure_bridge() does this */838#ifdef CONFIG_PCI_IOV839.notify_resume = pseries_notify_resume840#endif841};842843/**844* eeh_pseries_init - Register platform dependent EEH operations845*846* EEH initialization on pseries platform. This function should be847* called before any EEH related functions.848*/849static int __init eeh_pseries_init(void)850{851struct pci_controller *phb;852struct pci_dn *pdn;853int ret, config_addr;854855/* figure out EEH RTAS function call tokens */856ibm_set_eeh_option = rtas_function_token(RTAS_FN_IBM_SET_EEH_OPTION);857ibm_set_slot_reset = rtas_function_token(RTAS_FN_IBM_SET_SLOT_RESET);858ibm_read_slot_reset_state2 = rtas_function_token(RTAS_FN_IBM_READ_SLOT_RESET_STATE2);859ibm_read_slot_reset_state = rtas_function_token(RTAS_FN_IBM_READ_SLOT_RESET_STATE);860ibm_slot_error_detail = rtas_function_token(RTAS_FN_IBM_SLOT_ERROR_DETAIL);861ibm_get_config_addr_info2 = rtas_function_token(RTAS_FN_IBM_GET_CONFIG_ADDR_INFO2);862ibm_get_config_addr_info = rtas_function_token(RTAS_FN_IBM_GET_CONFIG_ADDR_INFO);863ibm_configure_pe = rtas_function_token(RTAS_FN_IBM_CONFIGURE_PE);864865/*866* ibm,configure-pe and ibm,configure-bridge have the same semantics,867* however ibm,configure-pe can be faster. If we can't find868* ibm,configure-pe then fall back to using ibm,configure-bridge.869*/870if (ibm_configure_pe == RTAS_UNKNOWN_SERVICE)871ibm_configure_pe = rtas_function_token(RTAS_FN_IBM_CONFIGURE_BRIDGE);872873/*874* Necessary sanity check. We needn't check "get-config-addr-info"875* and its variant since the old firmware probably support address876* of domain/bus/slot/function for EEH RTAS operations.877*/878if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE ||879ibm_set_slot_reset == RTAS_UNKNOWN_SERVICE ||880(ibm_read_slot_reset_state2 == RTAS_UNKNOWN_SERVICE &&881ibm_read_slot_reset_state == RTAS_UNKNOWN_SERVICE) ||882ibm_slot_error_detail == RTAS_UNKNOWN_SERVICE ||883ibm_configure_pe == RTAS_UNKNOWN_SERVICE) {884pr_info("EEH functionality not supported\n");885return -EINVAL;886}887888/* Initialize error log size */889eeh_error_buf_size = rtas_get_error_log_max();890891/* Set EEH probe mode */892eeh_add_flag(EEH_PROBE_MODE_DEVTREE | EEH_ENABLE_IO_FOR_LOG);893894/* Set EEH machine dependent code */895ppc_md.pcibios_bus_add_device = pseries_pcibios_bus_add_device;896897if (is_kdump_kernel() || reset_devices) {898pr_info("Issue PHB reset ...\n");899list_for_each_entry(phb, &hose_list, list_node) {900// Skip if the slot is empty901if (list_empty(&PCI_DN(phb->dn)->child_list))902continue;903904pdn = list_first_entry(&PCI_DN(phb->dn)->child_list, struct pci_dn, list);905config_addr = pseries_eeh_get_pe_config_addr(pdn);906907/* invalid PE config addr */908if (config_addr < 0)909continue;910911pseries_eeh_phb_reset(phb, config_addr, EEH_RESET_FUNDAMENTAL);912pseries_eeh_phb_reset(phb, config_addr, EEH_RESET_DEACTIVATE);913pseries_eeh_phb_configure_bridge(phb, config_addr);914}915}916917ret = eeh_init(&pseries_eeh_ops);918if (!ret)919pr_info("EEH: pSeries platform initialized\n");920else921pr_info("EEH: pSeries platform initialization failure (%d)\n",922ret);923return ret;924}925machine_arch_initcall(pseries, eeh_pseries_init);926927928