From patchwork Mon Nov 24 22:49:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 5370561 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 58C24C11AC for ; Mon, 24 Nov 2014 22:58:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4AB782015D for ; Mon, 24 Nov 2014 22:58:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 037B220154 for ; Mon, 24 Nov 2014 22:58:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751342AbaKXW6v (ORCPT ); Mon, 24 Nov 2014 17:58:51 -0500 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:37287 "EHLO e23smtp07.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750848AbaKXW6t (ORCPT ); Mon, 24 Nov 2014 17:58:49 -0500 Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 25 Nov 2014 08:58:47 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp07.au.ibm.com (202.81.31.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 25 Nov 2014 08:58:46 +1000 Received: from d23relay10.au.ibm.com (d23relay10.au.ibm.com [9.190.26.77]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id D1B722CE806D for ; Tue, 25 Nov 2014 09:49:28 +1100 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id sAOMnSwF32440402 for ; Tue, 25 Nov 2014 09:49:28 +1100 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id sAOMnRx2025591 for ; Tue, 25 Nov 2014 09:49:27 +1100 Received: from shangw (haven.au.ibm.com [9.192.253.15]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id sAOMnRGG025571; Tue, 25 Nov 2014 09:49:27 +1100 Received: by shangw (Postfix, from userid 1000) id 816013E0480; Tue, 25 Nov 2014 09:49:26 +1100 (EST) From: Gavin Shan To: linux-pci@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org, benh@kernel.crashing.org, mpe@ellerman.id.au, Gavin Shan Subject: [PATCH 3/8] powerpc/powernv: Export functions to retrieve slot status Date: Tue, 25 Nov 2014 09:49:20 +1100 Message-Id: <1416869365-7671-4-git-send-email-gwshan@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1416869365-7671-1-git-send-email-gwshan@linux.vnet.ibm.com> References: <1416869365-7671-1-git-send-email-gwshan@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14112422-0025-0000-0000-00000092A97B Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The patch exports two functions, which base on corresponding OPAL APIs to retrieve PCI slot status: pnv_pci_get_power_status() opal_pci_get_power_status() pnv_pci_get_presence_status() opal_pci_get_presence_status() Signed-off-by: Gavin Shan --- arch/powerpc/include/asm/opal.h | 6 +++- arch/powerpc/include/asm/pnv-pci.h | 3 ++ arch/powerpc/platforms/powernv/eeh-ioda.c | 34 ++--------------------- arch/powerpc/platforms/powernv/opal-wrappers.S | 2 ++ arch/powerpc/platforms/powernv/pci.c | 38 ++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/pci.h | 1 + 6 files changed, 51 insertions(+), 33 deletions(-) diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h index b59811f..b75be1c 100644 --- a/arch/powerpc/include/asm/opal.h +++ b/arch/powerpc/include/asm/opal.h @@ -153,6 +153,8 @@ struct opal_sg_list { #define OPAL_HANDLE_HMI 98 #define OPAL_REGISTER_DUMP_REGION 101 #define OPAL_UNREGISTER_DUMP_REGION 102 +#define OPAL_PCI_GET_POWER_STATUS 110 +#define OPAL_PCI_GET_PRESENCE_STATUS 111 #ifndef __ASSEMBLY__ @@ -905,7 +907,7 @@ int64_t opal_get_epow_status(__be64 *status); int64_t opal_set_system_attention_led(uint8_t led_action); int64_t opal_pci_next_error(uint64_t phb_id, __be64 *first_frozen_pe, __be16 *pci_error_type, __be16 *severity); -int64_t opal_pci_poll(uint64_t id); +int64_t opal_pci_poll(uint64_t id, uint8_t *val); int64_t opal_return_cpu(void); int64_t opal_check_token(uint64_t token); int64_t opal_reinit_cpus(uint64_t flags); @@ -946,6 +948,8 @@ int64_t opal_handle_hmi(void); int64_t opal_register_dump_region(uint32_t id, uint64_t start, uint64_t end); int64_t opal_unregister_dump_region(uint32_t id); int64_t opal_pci_set_phb_cxl_mode(uint64_t phb_id, uint64_t mode, uint64_t pe_number); +int64_t opal_pci_get_power_status(uint64_t id, uint8_t *status); +int64_t opal_pci_get_presence_status(uint64_t id, uint8_t *status); /* Internal functions */ extern int early_init_dt_scan_opal(unsigned long node, const char *uname, diff --git a/arch/powerpc/include/asm/pnv-pci.h b/arch/powerpc/include/asm/pnv-pci.h index f09a22f..527d97a 100644 --- a/arch/powerpc/include/asm/pnv-pci.h +++ b/arch/powerpc/include/asm/pnv-pci.h @@ -13,6 +13,9 @@ #include #include +extern int pnv_pci_get_power_status(unsigned int index, unsigned char *status); +extern int pnv_pci_get_presence_status(unsigned int index, unsigned char *status); + int pnv_phb_to_cxl(struct pci_dev *dev); int pnv_cxl_ioda_msi_setup(struct pci_dev *dev, unsigned int hwirq, unsigned int virq); diff --git a/arch/powerpc/platforms/powernv/eeh-ioda.c b/arch/powerpc/platforms/powernv/eeh-ioda.c index 4bf2fb5..fb66c74 100644 --- a/arch/powerpc/platforms/powernv/eeh-ioda.c +++ b/arch/powerpc/platforms/powernv/eeh-ioda.c @@ -490,24 +490,6 @@ static int ioda_eeh_get_state(struct eeh_pe *pe) return ioda_eeh_get_pe_state(pe); } -static s64 ioda_eeh_phb_poll(uint64_t id) -{ - s64 rc = OPAL_HARDWARE; - - while (1) { - rc = opal_pci_poll(id); - if (rc <= 0) - break; - - if (system_state < SYSTEM_RUNNING) - udelay(1000 * rc); - else - msleep(rc); - } - - return rc; -} - int ioda_eeh_phb_reset(struct pci_controller *hose, int option) { struct pnv_phb *phb = hose->private_data; @@ -542,13 +524,7 @@ int ioda_eeh_phb_reset(struct pci_controller *hose, int option) * need the PCI bus settlement delay. */ rc = opal_pci_reset(phb->opal_id, reset_scope); - if (rc > 0) - rc = ioda_eeh_phb_poll(phb->opal_id); - - if (rc != OPAL_SUCCESS) - return -EIO; - - return 0; + return pnv_pci_poll(phb->opal_id, rc, NULL); } static int __ioda_eeh_bridge_reset(struct pci_dev *dev, int option) @@ -641,13 +617,7 @@ static int ioda_eeh_bridge_reset(struct pci_dev *dev, int option) phb = hose->private_data; id |= ((phb->opal_id << 16) | (dev->bus->number << 8) | (dev->devfn)); rc = opal_pci_reset(id, reset_scope); - if (rc > 0) - rc = ioda_eeh_phb_poll(id); - - if (rc != OPAL_SUCCESS) - return -EIO; - - return 0; + return pnv_pci_poll(id, rc, NULL); } static int pnv_pci_dev_reset_type(struct pci_dev *pdev, void *data) diff --git a/arch/powerpc/platforms/powernv/opal-wrappers.S b/arch/powerpc/platforms/powernv/opal-wrappers.S index b6474a1..b2c15ff 100644 --- a/arch/powerpc/platforms/powernv/opal-wrappers.S +++ b/arch/powerpc/platforms/powernv/opal-wrappers.S @@ -249,3 +249,5 @@ OPAL_CALL(opal_handle_hmi, OPAL_HANDLE_HMI); OPAL_CALL(opal_register_dump_region, OPAL_REGISTER_DUMP_REGION); OPAL_CALL(opal_unregister_dump_region, OPAL_UNREGISTER_DUMP_REGION); OPAL_CALL(opal_pci_set_phb_cxl_mode, OPAL_PCI_SET_PHB_CXL_MODE); +OPAL_CALL(opal_pci_get_power_status, OPAL_PCI_GET_POWER_STATUS); +OPAL_CALL(opal_pci_get_presence_status, OPAL_PCI_GET_PRESENCE_STATUS); diff --git a/arch/powerpc/platforms/powernv/pci.c b/arch/powerpc/platforms/powernv/pci.c index b2187d0..f5bae4f 100644 --- a/arch/powerpc/platforms/powernv/pci.c +++ b/arch/powerpc/platforms/powernv/pci.c @@ -45,6 +45,44 @@ #define cfg_dbg(fmt...) do { } while(0) //#define cfg_dbg(fmt...) printk(fmt) +int pnv_pci_poll(uint64_t id, int64_t rval, uint8_t *pval) +{ + while (rval > 0) { + rval = opal_pci_poll(id, pval); + if (rval <= 0) + break; + + if (system_state < SYSTEM_RUNNING) + udelay(1000 * rval); + else + msleep(rval); + } + + return rval ? -EIO : 0; +} + +int pnv_pci_get_power_status(unsigned int index, unsigned char *status) +{ + uint64_t id = (0x1ul << 63); + long rc; + + id |= index; + rc = opal_pci_get_power_status(id, status); + return pnv_pci_poll(id, rc, status); +} +EXPORT_SYMBOL_GPL(pnv_pci_get_power_status); + +int pnv_pci_get_presence_status(unsigned int index, unsigned char *status) +{ + uint64_t id = (0x1ul << 63); + long rc; + + id |= index; + rc = opal_pci_get_presence_status(id, status); + return pnv_pci_poll(id, rc, status); +} +EXPORT_SYMBOL_GPL(pnv_pci_get_presence_status); + #ifdef CONFIG_PCI_MSI static int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type) { diff --git a/arch/powerpc/platforms/powernv/pci.h b/arch/powerpc/platforms/powernv/pci.h index 6c02ff8..396fe02 100644 --- a/arch/powerpc/platforms/powernv/pci.h +++ b/arch/powerpc/platforms/powernv/pci.h @@ -217,6 +217,7 @@ extern struct pci_ops pnv_pci_ops; extern struct pnv_eeh_ops ioda_eeh_ops; #endif +int pnv_pci_poll(uint64_t id, int64_t rval, uint8_t *pval); void pnv_pci_dump_phb_diag_data(struct pci_controller *hose, unsigned char *log_buff); int pnv_pci_cfg_read(struct device_node *dn,