From patchwork Mon Oct 23 13:08:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Philippe Bergheaud X-Patchwork-Id: 829294 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yLGw10Rbfz9t6C for ; Tue, 24 Oct 2017 00:09:53 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yLGw04QZszDqkJ for ; Tue, 24 Oct 2017 00:09:52 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=felix@linux.vnet.ibm.com; receiver=) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yLGvs2BW3zDqkr for ; Tue, 24 Oct 2017 00:09:45 +1100 (AEDT) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9ND6sb1046202 for ; Mon, 23 Oct 2017 09:09:42 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0b-001b2d01.pphosted.com with ESMTP id 2dsfjumkvx-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 23 Oct 2017 09:09:42 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 23 Oct 2017 14:09:22 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 23 Oct 2017 14:09:19 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9ND9ILA18808918; Mon, 23 Oct 2017 13:09:18 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0AB47AE045; Mon, 23 Oct 2017 14:03:18 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E20D1AE051; Mon, 23 Oct 2017 14:03:17 +0100 (BST) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 23 Oct 2017 14:03:17 +0100 (BST) Received: from w541.lab.toulouse-stg.fr.ibm.com (t42p.lab.toulouse-stg.fr.ibm.com [9.101.4.37]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 67599220076; Mon, 23 Oct 2017 15:09:18 +0200 (CEST) From: Philippe Bergheaud To: skiboot@lists.ozlabs.org Date: Mon, 23 Oct 2017 15:08:29 +0200 X-Mailer: git-send-email 2.14.2 X-TM-AS-GCONF: 00 x-cbid: 17102313-0016-0000-0000-000004F8EBA4 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17102313-0017-0000-0000-00002834590B Message-Id: <20171023130830.18818-1-felix@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-23_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710230187 Subject: [Skiboot] [PATCH 1/2] phb4: set PHB CMPM registers for tunneled operations X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" P9 supports PCI tunneled operations (atomics and as_notify) that require setting the PHB ASN Compare/Mask register with a 16-bit indication. This register is currently initialized by enable_capi_mode(). As tunneled operations may also operate in PCI mode, a new API is required to set the PHB ASN register without switching to CAPI mode. This patch provides two new OPAL calls to get/set any of the three PHB CMPM registers that obey the same logic (ASN, NBW, and CAPI). This new API aims at letting the operating system choose indications, that may change in the future. Compatibility with older kernel versions is made by enable_capi_mode(). Signed-off-by: Philippe Bergheaud Acked-by:  Christophe Lombard --- core/pci-opal.c | 36 ++++++ .../opal-pci-get-set-pbcq-tunnel-bar-160-161.rst | 76 +++++++++++++ doc/opal-api/opal-pci-get-set-phb-cmpm-158-159.rst | 100 ++++++++++++++++ hw/phb4.c | 126 +++++++++++++++++++-- include/opal-api.h | 11 +- include/pci.h | 4 + include/phb4-regs.h | 8 +- 7 files changed, 345 insertions(+), 16 deletions(-) create mode 100644 doc/opal-api/opal-pci-get-set-pbcq-tunnel-bar-160-161.rst create mode 100644 doc/opal-api/opal-pci-get-set-phb-cmpm-158-159.rst diff --git a/core/pci-opal.c b/core/pci-opal.c index b8aec941..bbbbcd5d 100644 --- a/core/pci-opal.c +++ b/core/pci-opal.c @@ -1016,3 +1016,39 @@ static int64_t opal_pci_set_p2p(uint64_t phbid_init, uint64_t phbid_target, return OPAL_SUCCESS; } opal_call(OPAL_PCI_SET_P2P, opal_pci_set_p2p, 4); + +static int64_t opal_pci_get_phb_cmpm(uint64_t phb_id, uint64_t phb_reg, + uint64_t *ind) +{ + struct phb *phb = pci_get_phb(phb_id); + int64_t rc; + + if (!phb) + return OPAL_PARAMETER; + if (!phb->ops->get_cmpm) + return OPAL_UNSUPPORTED; + + phb_lock(phb); + rc = phb->ops->get_cmpm(phb, phb_reg, ind); + phb_unlock(phb); + return rc; +} +opal_call(OPAL_PCI_GET_PHB_CMPM, opal_pci_get_phb_cmpm, 3); + +static int64_t opal_pci_set_phb_cmpm(uint64_t phb_id, uint64_t phb_reg, + uint64_t ind) +{ + struct phb *phb = pci_get_phb(phb_id); + int64_t rc; + + if (!phb) + return OPAL_PARAMETER; + if (!phb->ops->set_cmpm) + return OPAL_UNSUPPORTED; + + phb_lock(phb); + rc = phb->ops->set_cmpm(phb, phb_reg, ind); + phb_unlock(phb); + return rc; +} +opal_call(OPAL_PCI_SET_PHB_CMPM, opal_pci_set_phb_cmpm, 3); diff --git a/doc/opal-api/opal-pci-get-set-pbcq-tunnel-bar-160-161.rst b/doc/opal-api/opal-pci-get-set-pbcq-tunnel-bar-160-161.rst new file mode 100644 index 00000000..0af06774 --- /dev/null +++ b/doc/opal-api/opal-pci-get-set-pbcq-tunnel-bar-160-161.rst @@ -0,0 +1,76 @@ +OPAL_PCI_GET_PBCQ_TUNNEL_BAR +============================ +:: + + #define OPAL_PCI_GET_PBCQ_TUNNEL_BAR 160 + + int64_t opal_pci_get_pbcq_tunnel_bar(uint64_t phb_id, uint64_t *val) + +The host calls this function to read the address out of the PBCQ Tunnel +Bar register. + +Parameters +---------- +:: + + uint64_t phb_id + uint64_t *val + +``phb_id`` + The value from the PHB node ibm,opal-phbid property for the device. + +``val`` + A pointer to the address where the address store in the PBCQ Tunnel Bar + register will be copied. + +Return Values +------------- + +``OPAL_SUCCESS`` + Operation was successful + +``OPAL_PARAMETER`` + Invalid PHB + +``OPAL_UNSUPPORTED`` + Not supported by hardware + +OPAL_PCI_SET_PBCQ_TUNNEL_BAR +============================ +:: + + #define OPAL_PCI_SET_PBCQ_TUNNEL_BAR 161 + + int64_t opal_pci_set_pbcq_tunnel_bar(uint64_t phb_id, uint64_t addr) + +The host calls this function to set the PBCQ Tunnel Bar register. + +Parameters +---------- +:: + + uint64_t phb_id + uint64_t addr + +``phb_id`` + The value from the PHB node ibm,opal-phbid property for the device. + +``addr`` + The value of the address chosen for the PBCQ Tunnel Bar register. + If the address is 0, then the PBCQ Tunnel Bar register will be reset. + It the address is non-zero, then the PBCQ Tunnel Bar register will be + set with :: + + Bit[0:42] Bit[8:50] of the address + +Return Values +------------- + +``OPAL_SUCCESS`` + Operation was successful + +``OPAL_PARAMETER`` + Invalid PHB or addr parameter + +``OPAL_UNSUPPORTED`` + Not supported by hardware diff --git a/doc/opal-api/opal-pci-get-set-phb-cmpm-158-159.rst b/doc/opal-api/opal-pci-get-set-phb-cmpm-158-159.rst new file mode 100644 index 00000000..7eabdde3 --- /dev/null +++ b/doc/opal-api/opal-pci-get-set-phb-cmpm-158-159.rst @@ -0,0 +1,100 @@ +OPAL_PCI_GET_PHB_CMPM +===================== +:: + + #define OPAL_PCI_GET_PHB_CMPM 158 + + int64_t opal_pci_get_phb_cmpm(uint64_t phb_id, uint64_t phb_reg, + uint64_t *val) + +The host calls this function to read the indication out of a CMPM register +of the PHB. + +Parameters +---------- +:: + + uint64_t phb_id + uint64_t phb_reg + uint64_t *val + +``phb_id`` + The value from the PHB node ibm,opal-phbid property for the device. + +``phb_reg`` + Which CMPM register should be accessed, i.e. one of :: + + /* PHB Compare/Mask registers */ + enum { + OPAL_PHB_ASN_CMPM = 0, + OPAL_PHB_CAPI_CMPM = 1, + OPAL_PHB_PBL_NBW_CMPM = 2, + }; + +``val`` + A pointer to the address where the indication of the PHB CMPM register + will be copied. + +Return Values +------------- + +``OPAL_SUCCESS`` + Operation was successful + +``OPAL_PARAMETER`` + Invalid PHB or phb_reg parameter + +``OPAL_UNSUPPORTED`` + Not supported by hardware + +OPAL_PCI_SET_PHB_CMPM +===================== +:: + + #define OPAL_PCI_SET_PHB_CMPM 159 + + int64_t opal_pci_set_phb_cmpm(uint64_t phb_id, uint64_t phb_reg, + uint64_t ind) + +The host calls this function to set a CMPM register of the PHB. + +Parameters +---------- +:: + + uint64_t phb_id + uint64_t phb_reg + uint64_t ind + +``phb_id`` + The value from the PHB node ibm,opal-phbid property for the device. + +``phb_reg`` + Which CMPM register should be accessed, i.e. one of :: + + /* PHB Compare/Mask registers */ + enum { + OPAL_PHB_ASN_CMPM = 0, + OPAL_PHB_CAPI_CMPM = 1, + OPAL_PHB_PBL_NBW_CMPM = 2, + }; + +``ind`` + The value of the indication chosen for the PHB CMPM register. + The PHB CMPM register will be set with :: + + Bit[0:15] the indication value + Bit[16:31] the (hard-coded) mask value + Bit[63] the enable bit + +Return Values +------------- + +``OPAL_SUCCESS`` + Operation was successful + +``OPAL_PARAMETER`` + Invalid PHB, phb_reg, or ind parameter + +``OPAL_UNSUPPORTED`` + Not supported by hardware diff --git a/hw/phb4.c b/hw/phb4.c index c64ded92..1add8a75 100644 --- a/hw/phb4.c +++ b/hw/phb4.c @@ -3731,16 +3731,25 @@ static int64_t enable_capi_mode(struct phb4 *p, uint64_t pe_number, */ /* - * Bit [0:7] XSL_DSNCTL[capiind] - * Init_25 - CAPI Compare/Mask + * Init_26 - CAPI Compare/Mask + * If unset, then capiind=0x0200. */ - out_be64(p->regs + PHB_CAPI_CMPM, - 0x0200FE0000000000Ull | PHB_CAPI_CMPM_ENABLE); + reg = in_be64(p->regs + PHB_CAPI_CMPM); + if (!reg) { + reg = 0x0200fe0000000000ull | PHB_CAPI_CMPM_ENABLE; + out_be64(p->regs + PHB_CAPI_CMPM, reg); + } if (!(p->rev == PHB4_REV_NIMBUS_DD10)) { - /* Init_24 - ASN Compare/Mask */ - out_be64(p->regs + PHB_PBL_ASN_CMPM, - 0x0400FF0000000000Ull | PHB_PBL_ASN_ENABLE); + /* + * Init_25 - ASN Compare/Mask + * If unset, then asnind=0x0400. + */ + reg = in_be64(p->regs + PHB_ASN_CMPM); + if (!reg) { + reg = 0x0400ff0000000000ull | PHB_ASN_CMPM_ENABLE; + out_be64(p->regs + PHB_ASN_CMPM, reg); + } /* PBCQ Tunnel Bar Register * Write Tunnel register to match PSL TNR register @@ -3990,6 +3999,99 @@ static int64_t phb4_set_capp_recovery(struct phb *phb) return 0; } +/* + * Return the indication of a PHB CMPM register. + */ +static int64_t phb4_get_cmpm(struct phb *phb, uint64_t phb_reg, uint64_t *ind) +{ + struct phb4 *p = phb_to_phb4(phb); + uint64_t offset; + + switch (phb_reg) { + case OPAL_PHB_ASN_CMPM: + offset = PHB_ASN_CMPM; + break; + case OPAL_PHB_CAPI_CMPM: + offset = PHB_CAPI_CMPM; + break; + case OPAL_PHB_PBL_NBW_CMPM: + offset = PHB_PBL_NBW_CMPM; + break; + default: + return OPAL_UNSUPPORTED; + } + + *ind = in_be64(p->regs + offset) >> 48; + return OPAL_SUCCESS; +} + +/* + * Set the 16-bit indication of a PHB CMPM register. + * Set (hard-coded) mask value, and enable bit. + * + * This interface aims at letting linux choose the indications, + * if they need to be changed in the future. + * + * Compatibility with older versions of linux, that do not set CMPM + * indications with phb4_set_cmpm(), is ensured by enable_capi_mode(), + * that will set the default hard-coded values that were assumed then. + */ +static int64_t phb4_set_cmpm(struct phb *phb, uint64_t phb_reg, uint64_t ind) +{ + struct phb4 *p = phb_to_phb4(phb); + uint64_t mask, offset, enable; + + /* Indication is a 16-bit value */ + if (ind >> 16) + return OPAL_PARAMETER; + /* + * The following bits of the PCI address are reserved: + * Bit 59 indicates TVE#1 + * Bit 60 indicates MSI-X + */ + if (ind & 0x1800ull) + return OPAL_PARAMETER; + + switch (phb_reg) { + case OPAL_PHB_ASN_CMPM: + /* + * Init_25 - ASN Compare/Mask + * matches XSL_DSNCTL[ASB_Addr] + */ + offset = PHB_ASN_CMPM; + enable = PHB_ASN_CMPM_ENABLE; + mask = 0xff00ull; + break; + case OPAL_PHB_CAPI_CMPM: + /* + * Init_26 - CAPI Compare/Mask + * matches XSL_DSNCTL[capiind] + */ + offset = PHB_CAPI_CMPM; + enable = PHB_CAPI_CMPM_ENABLE; + mask = 0xfe00ull; + break; + case OPAL_PHB_PBL_NBW_CMPM: + /* + * Init_124 - NBW Compare/Mask + * matches XSL_DSNCTL[nbwind] + */ + offset = PHB_PBL_NBW_CMPM; + enable = PHB_PBL_NBW_CMPM_ENABLE; + mask = 0xff00ull; + break; + default: + return OPAL_UNSUPPORTED; + } + + /* Masked indication should not be null */ + if (!(ind & mask)) + return OPAL_PARAMETER; + + out_be64(p->regs + offset, (ind << 48) | (mask << 32) | enable); + return OPAL_SUCCESS; +} + static const struct phb_ops phb4_ops = { .cfg_read8 = phb4_pcicfg_read8, .cfg_read16 = phb4_pcicfg_read16, @@ -4025,6 +4127,8 @@ static const struct phb_ops phb4_ops = { .set_capi_mode = phb4_set_capi_mode, .set_p2p = phb4_set_p2p, .set_capp_recovery = phb4_set_capp_recovery, + .get_cmpm = phb4_get_cmpm, + .set_cmpm = phb4_set_cmpm, }; static void phb4_init_ioda3(struct phb4 *p) @@ -4059,10 +4163,10 @@ static void phb4_init_ioda3(struct phb4 *p) /* See enable_capi_mode() */ /* Init_25 - ASN Compare/Mask */ - /* See enable_capi_mode() */ + /* See phb4_set_cmpm() and enable_capi_mode() */ /* Init_26 - CAPI Compare/Mask */ - /* See enable_capi_mode() */ + /* See phb4_set_cmpm() and enable_capi_mode() */ /* Init_27 - PCIE Outbound upper address */ out_be64(p->regs + PHB_M64_UPPER_BITS, 0); @@ -4412,8 +4516,8 @@ static void phb4_init_hw(struct phb4 *p, bool first_init) * don't bother as we are doing a PERST soon. */ - /* Init_124 : NBW. XXX TODO */ - /* See enable_capi_mode() */ + /* Init_124 - NBW Compare/Mask */ + /* See phb4_set_cmpm() and enable_capi_mode() */ /* Init_125 : Setup PCI command/status on root complex * I don't know why the spec does this now and not earlier, so diff --git a/include/opal-api.h b/include/opal-api.h index 0bc036ed..ce948136 100644 --- a/include/opal-api.h +++ b/include/opal-api.h @@ -214,7 +214,9 @@ #define OPAL_SET_POWER_SHIFT_RATIO 155 #define OPAL_SENSOR_GROUP_CLEAR 156 #define OPAL_PCI_SET_P2P 157 -#define OPAL_LAST 157 +#define OPAL_PCI_GET_PHB_CMPM 158 +#define OPAL_PCI_SET_PHB_CMPM 159 +#define OPAL_LAST 159 /* Device tree flags */ @@ -1274,6 +1276,13 @@ enum { OPAL_PCI_P2P_TARGET = 1, }; +/* PHB Compare/Mask registers */ +enum { + OPAL_PHB_ASN_CMPM = 0, + OPAL_PHB_CAPI_CMPM = 1, + OPAL_PHB_PBL_NBW_CMPM = 2, +}; + #endif /* __ASSEMBLY__ */ #endif /* __OPAL_API_H */ diff --git a/include/pci.h b/include/pci.h index c085b6b8..cdf82ee8 100644 --- a/include/pci.h +++ b/include/pci.h @@ -333,6 +333,10 @@ struct phb_ops { /* PCI peer-to-peer setup */ void (*set_p2p)(struct phb *phb, uint64_t mode, uint64_t flags, uint16_t pe_number); + + /* Get/set PHB Compare/Mask registers */ + int64_t (*get_cmpm)(struct phb *phb, uint64_t phb_reg, uint64_t *ind); + int64_t (*set_cmpm)(struct phb *phb, uint64_t phb_reg, uint64_t ind); }; enum phb_type { diff --git a/include/phb4-regs.h b/include/phb4-regs.h index e83c8c39..b33185ed 100644 --- a/include/phb4-regs.h +++ b/include/phb4-regs.h @@ -71,8 +71,8 @@ #define PHB_PEST_BAR 0x1a8 #define PHB_PEST_BAR_ENABLE PPC_BIT(0) #define PHB_PEST_BASE_ADDRESS PPC_BITMASK(8,51) -#define PHB_PBL_ASN_CMPM 0x1C0 -#define PHB_PBL_ASN_ENABLE PPC_BIT(63) +#define PHB_ASN_CMPM 0x1C0 +#define PHB_ASN_CMPM_ENABLE PPC_BIT(63) #define PHB_CAPI_CMPM 0x1C8 #define PHB_CAPI_CMPM_ENABLE PPC_BIT(63) #define PHB_M64_UPPER_BITS 0x1f0 @@ -250,8 +250,8 @@ #define PHB_PBL_CONTROL 0x1800 #define PHB_PBL_TIMEOUT_CTRL 0x1810 #define PHB_PBL_NPTAG_ENABLE 0x1820 -#define PHB_PBL_NBW_CMP_MASK 0x1830 -#define PHB_PBL_NBW_MASK_ENABLE PPC_BIT(63) +#define PHB_PBL_NBW_CMPM 0x1830 +#define PHB_PBL_NBW_CMPM_ENABLE PPC_BIT(63) #define PHB_PBL_SYS_LINK_INIT 0x1838 #define PHB_PBL_BUF_STATUS 0x1840 #define PHB_PBL_ERR_STATUS 0x1900