From patchwork Thu Jan 4 22:17:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Kuehling X-Patchwork-Id: 10145679 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 D6564601A1 for ; Thu, 4 Jan 2018 22:17:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2690F28863 for ; Thu, 4 Jan 2018 22:18:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B42A28867; Thu, 4 Jan 2018 22:18:00 +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 352292885F for ; Thu, 4 Jan 2018 22:17:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753481AbeADWR6 (ORCPT ); Thu, 4 Jan 2018 17:17:58 -0500 Received: from mail-by2nam03on0078.outbound.protection.outlook.com ([104.47.42.78]:32395 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752552AbeADWR5 (ORCPT ); Thu, 4 Jan 2018 17:17:57 -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=0WmjdW5ZZLH7em1qxG50mg23yxMVuiQ9rK0OPvzWOI8=; b=MsUq8dIMEjl6grS2xaaLydeDdtZs8UKhJ9fW8oBke6eU4LZuSTK79DcQtqQ0JAKgq+1DN+myB4moEXOugXzv5ukKBeg3OvnhwFdTj4xZ0N1bX2W4zvFWaqYPU+So9pIUVnc24nPo0LMv6x+VfaO157tP/kZlimyBCRFIWK36AoA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Felix.Kuehling@amd.com; Received: from Harpoon.amd.com (165.204.55.251) by CY4PR1201MB0230.namprd12.prod.outlook.com (10.172.79.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.386.5; Thu, 4 Jan 2018 22:17:54 +0000 From: Felix Kuehling To: amd-gfx@lists.freedesktop.org, oded.gabbay@gmail.com Cc: Jay Cornwall , linux-pci@vger.kernel.org, Felix Kuehling Subject: [PATCH 1/9] PCI: Add pci_enable_atomic_ops_to_root Date: Thu, 4 Jan 2018 17:17:40 -0500 Message-Id: <1515104268-25087-2-git-send-email-Felix.Kuehling@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515104268-25087-1-git-send-email-Felix.Kuehling@amd.com> References: <1515104268-25087-1-git-send-email-Felix.Kuehling@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.55.251] X-ClientProxiedBy: DM5PR06CA0094.namprd06.prod.outlook.com (10.174.189.35) To CY4PR1201MB0230.namprd12.prod.outlook.com (10.172.79.7) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9c373aa5-683c-4b70-4782-08d553c100f6 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(48565401081)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060); SRVR:CY4PR1201MB0230; X-Microsoft-Exchange-Diagnostics: 1; CY4PR1201MB0230; 3:MgHf9k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1FryjArryyQeQpAzwT0bmTnj+Xmj67XvV9QxD0BJ1azT4BA37niM3LFozl7AynaJ84wzUdBV/hQp6tvwqjHrWpETCKR3GdDs8Q26zZPeJiR8hcyszOytH7jprzmofYdEdHE4JFEIZul/nqh3u41RAq+qF3OnrqewYXvbzeA/movIEiTWRBIBDEFtFhwiF+D3g/3kT6gqa45uZNSOtWqjHGM7EhuXZHv99WIkC0h9nAhnLZulzN2Jnbpeh1fakAR52eH9SyzIFGDVvK/Gvu8YfYuHUFpIvFFV6W3vksQv5yg5V7F+C4j+QX35zExMC2iKdvlPci4pZ10mwsaJd; 4:cnlxRTE5E0v0MDM32COjYaFpMLxjA6rjvlX+3GrQjZJ8zB3eVUYqGMpSdRIdSfmSDSFXJeVquGfGkWKAWShQVnaa07Y7pyC8Glk24B2y659sisppnwvF1tTVDgpFM/yMA//cEpxDDCoTuLfJ167vWAiYj1t2tT7idnvGIyILAlnOnXegJC72Lve02Q4C/z9uJl9xs8etNa+bcNoAuHCt+3rZXZVx0j2jDCYF4iOikkOEuLHa9/rFyNS8IrT17uUNezbux3HcbxYNn5sjO8f4xmyzdist7o/NNn8rpu40+wL0pPH82T2H42evvVx8aT4yBAFf5ufue36zFANnQ/mP875IhXCHz7l4D2pxNEMuPksL1IDR8BTO5M/n6RJCxS0O X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(767451399110)(211171220733660); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(3231023)(944501075)(10201501046)(6055026)(6041268)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011); SRVR:CY4PR1201MB0230; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:CY4PR1201MB0230; X-Forefront-PRVS: 054231DC40 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(346002)(39860400002)(39380400002)(366004)(396003)(189003)(199004)(66066001)(36756003)(47776003)(68736007)(478600001)(6116002)(8936002)(3846002)(81166006)(4326008)(53416004)(50226002)(72206003)(54906003)(39060400002)(25786009)(386003)(16526018)(5660300001)(316002)(59450400001)(8676002)(81156014)(305945005)(7736002)(7696005)(52116002)(6666003)(76176011)(51416003)(2906002)(97736004)(2950100002)(106356001)(105586002)(86362001)(16586007)(6486002)(48376002)(53936002)(50466002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR1201MB0230; H:Harpoon.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:3; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR1201MB0230; 23:2yP/4AarAgYbIEq9CGp1CJ5hj6CanPMZQ/OAo2m?= =?us-ascii?Q?2EcqTWLU6TOEKOXmkqPXeBdyA+d2GYQyjdIH1toWWYe3aEOIZu4CRwxV8e8T?= =?us-ascii?Q?ZeSslv4VE+m5IGSqeMIN0IxrFyjiWDXHPpOMUpMMFGxicpcYupfCO35wP/NW?= =?us-ascii?Q?KYK7RG4srEvk5MSvkMKQAa5Dd7i6FAe/f5cb1brwHnW2yEsMbfswdOgE4uCO?= =?us-ascii?Q?bywVAjadpbA/dDqBu+a5sA+h/imh+/D7i1k5Ncznr8cXiCC5y+UjjN6dsDYk?= =?us-ascii?Q?/+4ppNbqT2gwX9ibwKlaYeAIMIeilPEYddur/mvt7/hf5eVlvsxEsVzhLfoL?= =?us-ascii?Q?yIJVrLPN4HwqB6l//bdDxcHFNVpefOBg02ji6yuuLmg0kXJS0INvc6cSVedI?= =?us-ascii?Q?eCVBrmzHFDrgwfoai+42wyyMonAf/GnT72yjqJWcPpCD4kR+pf/wbob7BeDZ?= =?us-ascii?Q?3qgeSsehrhEK8XOVsZCYTTJItACg9kC3SP1Jy3e7uqP1mvVcJekGSAp/RbAw?= =?us-ascii?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YRWNFYZB1w51h7OJpMN7wsuRec4N9A82ujIdNWHNxriHSLdW4ZK3RdPxEDbX/qkLbRDbuWHvxdJiCDrafWPR5Vi6UO4YZfEkWJNs=; 5:9SgeZ0ISr6YxbzgL8yLfvVgDaMaLcz2uM97bOIrbvXEj4329nouEAJ9tyLT9sS+h2qvWrwhMZUO4Hvi457d6m/VKJ52BprLCl4ILTT90WV/dJ2aj85DXcwlLaI2+GmyI2NoRFf4QlwzUAkriqWpKWks0K6H6M0V84iEWyKL4oPc=; 24:qi1mM0aa+afp3LqVC+sBRRYA7bJDuzguxho8ZQeBD0cRWoI4W0MESwxUhGGTL/PY0MZbP8AyBjsey47voDdug/jBRuHVE4volA7P+JqXdSw=; 7:weZEXdDpOBPdSK0XIbBzKMpbu4SCZCcDQ8upRQnzDDjmL3vsBmGKUJkkHuRggCU2JI4FGifGFOL5gcCqWDmKPshsMX7zGAt99/FJaHqSQKWNn7h3Q0RiavnLZ+ODAfRIOJD8OzaJCfCqr4Cazj7sp/CEBVq0RSVxoLzYmZ1x+kN7nV/106t8C94MHdnjkde84hS/0RYZr5muUtKUlXkRsgP+YlFlDXLb5nxe2qxBVAJsbdLNt9YXZRjHP1sOeQ/p SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR1201MB0230; 20:/mCAxViEbwUQO4v1r1PgYxJsrite7YbWmBpWU0oWMA31uM+AFDUiLBKVKXsZ0pKwen+JxeeDQSv3Cqcu4m27jWk+XR0oESDOeEkv2eXolgdAgDT69drfCpy4/vkF/d+Cvnmv6DhKhUm+Yeo3zbtJzfpKH8TPRN0+JOt6CcZ7Tv0Oof0jL7zbr/FYgNbUVs/LeYaQcO+hhU7wCUKjFV0GUSkDBQMA/M3zYQCtwlBc1mve0hy6aUouzGgip187nnC8 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jan 2018 22:17:54.8664 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9c373aa5-683c-4b70-4782-08d553c100f6 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB0230 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. AtomicOp requests are permitted only if a component's DEVCTL2.ATOMICOP_REQUESTER_ENABLE field is set. This capability cannot be detected but is a no-op if set on a component with no support. These requests can only be serviced if the upstream components support AtomicOp completion and/or routing to a component which does. 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). When AtomicOp requests are disabled the GPU logs attempts to initiate requests to an MMIO register for debugging. 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 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 */