From patchwork Fri Jan 5 00:44:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Kuehling X-Patchwork-Id: 10145901 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 13EB360244 for ; Fri, 5 Jan 2018 00:45:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A9B928882 for ; Fri, 5 Jan 2018 00:45:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D91728885; Fri, 5 Jan 2018 00:45:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1205028882 for ; Fri, 5 Jan 2018 00:45:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751193AbeAEApX (ORCPT ); Thu, 4 Jan 2018 19:45:23 -0500 Received: from mail-sn1nam01on0087.outbound.protection.outlook.com ([104.47.32.87]:42880 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751148AbeAEApV (ORCPT ); Thu, 4 Jan 2018 19:45:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=FsurBhFl/IJySPzekd2vHTCgHnLsqMh4BajQ6oA+yCQ=; b=xaD5HVf8DllnIojJKpRd77CZl/Vt/gPbDJwKxMqbGRr2+5lBdGozGRMDOR0ovKPw5AEweDM/sFusBHjSB+BA35uVjJjqOzMp8H2Zc/oOwouO/N095Yc/5IjHTlwgRR+FTQDRRDc8O1oddbjPMEKBSAwelTusluE928I3JNaCzTc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Felix.Kuehling@amd.com; Received: from Harpoon.amd.com (165.204.55.251) by MWHPR1201MB0238.namprd12.prod.outlook.com (10.174.99.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.386.5; Fri, 5 Jan 2018 00:45:18 +0000 From: Felix Kuehling To: linux-pci@vger.kernel.org, helgaas@kernel.org Cc: oded.gabbay@gmail.com, Jay.Cornwall@amd.com, Felix Kuehling Subject: [PATCH 1/2] PCI: Add pci_enable_atomic_ops_to_root Date: Thu, 4 Jan 2018 19:44:59 -0500 Message-Id: <1515113100-4718-1-git-send-email-Felix.Kuehling@amd.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [165.204.55.251] X-ClientProxiedBy: MWHPR22CA0003.namprd22.prod.outlook.com (10.172.163.141) To MWHPR1201MB0238.namprd12.prod.outlook.com (10.174.99.135) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: eafd80bd-ae63-4119-0a07-08d553d5981c X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(48565401081)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060); SRVR:MWHPR1201MB0238; X-Microsoft-Exchange-Diagnostics: 1; MWHPR1201MB0238; 3:hrs7/4c+oZDMC/9Ov7yE13xG3u6/u9K6uEyv3DCmfDsCd2NvzllgpBgAgRoxDt4Xj98cnQRQay6sHPyxT8QKIxEsl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UAslT/7UJfBDqriQaQYsHkA/WXg+PqgkQXnWVoB5Di5GYw1fPpVo6bJf6V75NPFkW62ewrDn823Wwvmwjuf4EBLZ3SII2+NYSHO6O6Kn7zc5LYYtJchEHvPNryQw459Scl37QFMwzC0NmfQTWJcT7/8k85qFaCkZiK/EuFVZtgL0ffdzRUgeUOggE3dQ7vjZ7bBGPxidCPQeA3zmgOiVHHc6p5tBatD2NIdTr+fYkAwXnsodtDTupaiQpL2iN3G7yWgt+P9zL117AvR; 4:WJHd/3n7I0Hqgk0HsjMFi7e6DWBUgSuxwJyQOhUoG2IZo1y7wVRuypzjEqQfSsgeUVxL79kCVdyhFqPlOw9QAFhYIaHRUl/xAw4DWlmh/JH6zAHb+iAmuBpomYO7se6yj+Eqi4Um9UbVlhN1bLfbHL80aSU41znIMvNUwQifqUOaLXPzvyuA4Rd+w6acac1JiqxgGRvtMv3zyS7jaUUeduqzgEeXFxCIxrOdkEnfhQByrBGXssD+R9b/qKqEMsDbklJPzoP14+I/KPZkGWi8bPu8nftxpdUdYqKvc0NGcqTOLPul59XBwddNqUqg2pBK39EaomRc++ru7prvENHdAWel5d7wnE/GwEdmDcQRAz84k15BmYtxzD3NPMV1k/A8aUFVienpJ/3YRe6XCdWJ4tlRC3tdxAt21//u gHjoCuU= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(131327999870524)(767451399110)(211171220733660); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(5005006)(8121501046)(10201501046)(3002001)(3231023)(944501075)(93006095)(93001095)(6055026)(6041268)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123562045)(6072148)(201708071742011); SRVR:MWHPR1201MB0238; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:MWHPR1201MB0238; X-Forefront-PRVS: 05437568AA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39860400002)(396003)(366004)(39380400002)(346002)(376002)(189003)(199004)(39060400002)(105586002)(106356001)(72206003)(478600001)(2906002)(6116002)(4326008)(3846002)(53936002)(16586007)(316002)(51416003)(52116002)(386003)(81166006)(97736004)(8676002)(86362001)(81156014)(59450400001)(16526018)(7696005)(50226002)(36756003)(8936002)(5660300001)(68736007)(6666003)(53416004)(6486002)(48376002)(50466002)(305945005)(7736002)(66066001)(47776003)(25786009); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR1201MB0238; H:Harpoon.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR1201MB0238; 23:MpXcOjCQxKjQX7t20DlAoPezlnzGQ9rf/x+1Tzy?= =?us-ascii?Q?pNl+V2A5cBf0+nzFQLCLsEYCvusYqP3pqRd734SRezWfkQ3wdeLIh2/AvomN?= =?us-ascii?Q?rQ+1k5VHeLsso2Ji4K7PZ5oSU7BagSIf4/+I3ACalRNe4+uwSpFOC5iMtP3c?= =?us-ascii?Q?hwBSM72u5S591hx/SqIDqzridFp/lOYiGxhmDach5w0FkqouzmgP8H+IJflq?= =?us-ascii?Q?1f+vYWjdhjhJO/khkpoi6NdB/fS3yWhvH8IgT2q1UJ3zfeJ6kbeZd1cfJRCY?= =?us-ascii?Q?wkGLymuUfWOI20d8Tk5LK752DC0Y2rVRJyzsVnOe1et2gbQLjDGP5ym1Jthx?= =?us-ascii?Q?0Ffp7SkyGGaogHMKpYsVwisSflWgmx8vDPiwzui4ayoqd8FGnAuDtZ9BIwM4?= =?us-ascii?Q?42fCHH7vUilD7LsJ8hSauqsktYFymykVNdjZu7dcRKW3g3YuG6GhPkRF4BIU?= =?us-ascii?Q?UgO4Chp8pgHvj/tbcqbQr3ewLKlDGi70M5k087ugLjy3Xt/3apiSUCNBohcz?= =?us-ascii?Q?/xBQllm0NLWky36r4x9bT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; 5:YerZW/2khMSatZ/rpXati/Lwgvwcc/ibIfBYvHoIaVW4WMZHjJwD31UonPe2+NLxy01npImMYwjOjK6ltRfgH8jYx9xEGW+1pxvumuyPP3L2SaPPfbQEYOpr5OB/oF39UsrJ1Lqd62uU7aFVvPVQCbp6ThkTXFoUqzWpA+UoC2E=; 24:yG3c6eV92Q+GBvGWDWEEAYKAdiyM2546BRgEyHvOvZl7cyY4cmDj+cLwcdimFXmGiTNFhuyPDnInopMBjwxc1n/AC4VrKuuIe6JatMc0m1Y=; 7:t4GwNjsZyGe8S28TW7g0m26hpgHPFhJk+GL+xuvgm/TgC7PQIwhjfg0hwueRRqX3LQKeXOcG7nkvQqlpH5nyaDAZuXxBPdJS4YOMoIwLNk8krK3Fgt7wyyGhIFwx3GqrdtTLcQyEXiP6pEj+1yloq/74X2b7OnwR+9r06W0aVz8kOnxerTzpqE/ad/S5TekLAQXIfMx2ldXNajxhtJRuZ/Q6M93Us8ai7LJy3rDq/oFTMTMX41xLmydrZnqGhKN6 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR1201MB0238; 20:I0ztnVtO9aYnENxf5DhNhCCwKcULQpNEb2/kjoKqf2NQ04Ypmtxi8D+Uf263jbvqxpZn6GB9CyWhSRfUx70VOdrpe5YDaHcejcqQQ4dRG44bezj5nQkWN9MKqqmjQx4Fx9C7/+gH9AobAvnQQyDWlTMjOV1DQhGifLcG3yQk+AoEqoPXHCD7AmzBnVJDfTsarxV4RjXkjeJBaOKY56Lp333eKAkgCMsibXiyXkiQdWPKIo1p3t7k5Zbmy1nccvNz X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2018 00:45:18.3532 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eafd80bd-ae63-4119-0a07-08d553d5981c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB0238 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jay Cornwall The PCIe 3.0 AtomicOp (6.15) feature allows atomic transctions to be requested by, routed through and completed by PCIe components. Routing and completion do not require software support. Component support for each is detectable via the DEVCAP2 register. A Requester is permitted to use AtomicOps only if its PCI_EXP_DEVCTL2_ATOMIC_REQ is set. A driver should set PCI_EXP_DEVCTL2_ATOMIC_REQ only if the Completer and all intermediate routing elements support AtomicOps. A concrete example is the AMD Fiji-class GPU, which is specified to support AtomicOp requests, routed through a PLX 8747 switch (advertising AtomicOp routing) to a Haswell host bridge (advertising AtomicOp completion support). Add pci_enable_atomic_ops_to_root for per-device control over AtomicOp requests. Upstream bridges are checked for AtomicOp routing capability and the call fails if any lack this capability. The root port is checked for AtomicOp completion capabilities and the call fails if it does not support any. Routes to other PCIe components are not checked for AtomicOp routing and completion capabilities. v2: Check for AtomicOp route to root port with AtomicOp completion v3: Style fixes v4: Endpoint to root port only, check upstream egress blocking v5: Rebase, use existing PCI_EXP_DEVCTL2_ATOMIC_EGRESS_BLOCK define v6: Add comp_caps param, fix upstream port detection, cosmetic/comments v7: Reword commit message CC: linux-pci@vger.kernel.org Signed-off-by: Jay Cornwall Signed-off-by: Felix Kuehling --- drivers/pci/pci.c | 80 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 1 + include/uapi/linux/pci_regs.h | 4 ++- 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 4a7c686..9cea399 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3066,6 +3066,86 @@ int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size) } /** + * pci_enable_atomic_ops_to_root - enable AtomicOp requests to root port + * @dev: the PCI device + * @comp_caps: Caps required for atomic request completion + * + * Return 0 if all upstream bridges support AtomicOp routing, egress + * blocking is disabled on all upstream ports, and the root port + * supports the requested completion capabilities (32-bit, 64-bit + * and/or 128-bit AtomicOp completion), or negative otherwise. + */ +int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 comp_caps) +{ + struct pci_bus *bus = dev->bus; + + if (!pci_is_pcie(dev)) + return -EINVAL; + + switch (pci_pcie_type(dev)) { + /* + * PCIe 3.0, 6.15 specifies that endpoints and root ports are permitted + * to implement AtomicOp requester capabilities. + */ + case PCI_EXP_TYPE_ENDPOINT: + case PCI_EXP_TYPE_LEG_END: + case PCI_EXP_TYPE_RC_END: + break; + default: + return -EINVAL; + } + + while (bus->parent) { + struct pci_dev *bridge = bus->self; + u32 cap; + + pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap); + + switch (pci_pcie_type(bridge)) { + /* + * Upstream, downstream and root ports may implement AtomicOp + * routing capabilities. AtomicOp routing via a root port is + * not considered. + */ + case PCI_EXP_TYPE_UPSTREAM: + case PCI_EXP_TYPE_DOWNSTREAM: + if (!(cap & PCI_EXP_DEVCAP2_ATOMIC_ROUTE)) + return -EINVAL; + break; + + /* + * Root ports are permitted to implement AtomicOp completion + * capabilities. + */ + case PCI_EXP_TYPE_ROOT_PORT: + if ((cap & comp_caps) != comp_caps) + return -EINVAL; + break; + } + + /* + * Upstream ports may block AtomicOps on egress. + */ + if (!bridge->has_secondary_link) { + u32 ctl2; + + pcie_capability_read_dword(bridge, PCI_EXP_DEVCTL2, + &ctl2); + if (ctl2 & PCI_EXP_DEVCTL2_ATOMIC_EGRESS_BLOCK) + return -EINVAL; + } + + bus = bus->parent; + } + + pcie_capability_set_word(dev, PCI_EXP_DEVCTL2, + PCI_EXP_DEVCTL2_ATOMIC_REQ); + + return 0; +} +EXPORT_SYMBOL(pci_enable_atomic_ops_to_root); + +/** * pci_swizzle_interrupt_pin - swizzle INTx for device behind bridge * @dev: the PCI device * @pin: the INTx pin (1=INTA, 2=INTB, 3=INTC, 4=INTD) diff --git a/include/linux/pci.h b/include/linux/pci.h index c170c92..52a17754 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2061,6 +2061,7 @@ void pci_request_acs(void); bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags); bool pci_acs_path_enabled(struct pci_dev *start, struct pci_dev *end, u16 acs_flags); +int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 comp_caps); #define PCI_VPD_LRDT 0x80 /* Large Resource Data Type */ #define PCI_VPD_LRDT_ID(x) ((x) | PCI_VPD_LRDT) diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h index 70c2b2a..f31b56b 100644 --- a/include/uapi/linux/pci_regs.h +++ b/include/uapi/linux/pci_regs.h @@ -624,7 +624,9 @@ #define PCI_EXP_DEVCAP2 36 /* Device Capabilities 2 */ #define PCI_EXP_DEVCAP2_ARI 0x00000020 /* Alternative Routing-ID */ #define PCI_EXP_DEVCAP2_ATOMIC_ROUTE 0x00000040 /* Atomic Op routing */ -#define PCI_EXP_DEVCAP2_ATOMIC_COMP64 0x00000100 /* Atomic 64-bit compare */ +#define PCI_EXP_DEVCAP2_ATOMIC_COMP32 0x00000080 /* 32b AtomicOp completion */ +#define PCI_EXP_DEVCAP2_ATOMIC_COMP64 0x00000100 /* 64b AtomicOp completion */ +#define PCI_EXP_DEVCAP2_ATOMIC_COMP128 0x00000200 /* 128b AtomicOp completion */ #define PCI_EXP_DEVCAP2_LTR 0x00000800 /* Latency tolerance reporting */ #define PCI_EXP_DEVCAP2_OBFF_MASK 0x000c0000 /* OBFF support mechanism */ #define PCI_EXP_DEVCAP2_OBFF_MSG 0x00040000 /* New message signaling */