From patchwork Sat Dec 9 04:09:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Kuehling X-Patchwork-Id: 10103547 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 EB1CA60325 for ; Sat, 9 Dec 2017 04:10:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D001C2902E for ; Sat, 9 Dec 2017 04:10:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C14AD29035; Sat, 9 Dec 2017 04:10:08 +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 A07282902E for ; Sat, 9 Dec 2017 04:10:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753611AbdLIEKF (ORCPT ); Fri, 8 Dec 2017 23:10:05 -0500 Received: from mail-dm3nam03on0088.outbound.protection.outlook.com ([104.47.41.88]:25504 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753341AbdLIEKE (ORCPT ); Fri, 8 Dec 2017 23:10:04 -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=bO5WEmnRtl1smFOZvnGLo1RQxtSNbB3X4OVpYdy07LU=; b=XtAWiKSSnxUR9gpVgZLZ+iKM4gzreBQ71aOQPkbtAXV0+TAj+8m5Eo2GzczYfM9N5bCgiS6raEKrIcTDeB/nS6Za2pQndrRDXMDWsWSaTOZ8RYAGUBStlo90Gp56B1RnZeiL4kjZ6/Dccp2IwjmiU3DaSlnAW+5hvChSJNP/J2k= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Felix.Kuehling@amd.com; Received: from Harpoon.amd.com (165.204.55.251) by CY4PR1201MB0229.namprd12.prod.outlook.com (10.172.78.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.302.9; Sat, 9 Dec 2017 04:10:02 +0000 From: Felix Kuehling To: oded.gabbay@gmail.com, amd-gfx@lists.freedesktop.org Cc: Jay Cornwall , linux-pci@vger.kernel.org, Felix Kuehling Subject: [PATCH 29/37] PCI: Add pci_enable_atomic_ops_to_root Date: Fri, 8 Dec 2017 23:09:07 -0500 Message-Id: <1512792555-26042-30-git-send-email-Felix.Kuehling@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1512792555-26042-1-git-send-email-Felix.Kuehling@amd.com> References: <1512792555-26042-1-git-send-email-Felix.Kuehling@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.55.251] X-ClientProxiedBy: DM5PR1601CA0022.namprd16.prod.outlook.com (10.174.111.35) To CY4PR1201MB0229.namprd12.prod.outlook.com (10.172.78.150) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3fdac895-7d68-429b-3922-08d53ebab890 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603307); SRVR:CY4PR1201MB0229; X-Microsoft-Exchange-Diagnostics: 1; CY4PR1201MB0229; 3:kKJ3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rcYy59ByWCN2P2pt14xTC2ENx3XBchIYNigJLoW0xBWPFJ0+/ItX5Muj1QQjObJnSU/8bB/FIqTuBQA0vSzwPC1rbxgr47K0Og5qoWI5r9R8G1s4WA5GQVIh+gFX0hCsIClrhu8lax0vTvEwFtNHH/um6aHnSotblvDhqlRMn1orSVZywpiVQjNUWLt3LenNTbKuF1Y5x7lLpjcF4Dajt1dZBJ5SIa1h0nGrCxCaaARJlNbLwqhiLwnOhX0+inYRTOp84bvVjhYdqNVFNRnF8ZSQ0tmC7lYMTdf2JiXvKJG86Ce7hciWr09BjGikNEWlnjOQS3abb36ACalvkjwPZM/vXNdJx; 4:7WC0nW+EfHTo3zKT4RvqinhqnfDKMbhDJkfPvyK8+aYZ4NK7b0T78nfY/pmIjioWuo6tDVEISWe+qzw9V2jpcJNx/D14BRRyt4oUOTQH3CctvWdCi2zeuOEf8VrO1EwiA3rmIQbMsA76nzSwXKH/RvkrHPvhJ+GMy2gAlD1WzV+Bn29sxatYgd8eqkOLp6F/1MsXHRjtvwPQdR3aIhVBrJFJLLsAy/PMurdLRuqPJfT5o60r2M3vaw9rY4DLbRhoZySmB3QPAMfGRgwl1BALA7bDLESaFHBWzCQ8PlGSkDgUvEptjil1a1X1T17k0tP0d7cEVtj3GQsPWpBezUuCTSU8hHvfw9ueOYLUSk+mp3IdTI02r0/wSWr4MEN+uLGQ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(767451399110)(211171220733660); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231022)(6055026)(6041248)(20161123560025)(20161123562025)(20161123558100)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(6072148)(201708071742011); SRVR:CY4PR1201MB0229; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:CY4PR1201MB0229; X-Forefront-PRVS: 05168A3970 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(376002)(39860400002)(366004)(199004)(189003)(72206003)(16586007)(105586002)(81156014)(8676002)(316002)(16526018)(53936002)(50466002)(81166006)(478600001)(54906003)(48376002)(59450400001)(106356001)(68736007)(39060400002)(50226002)(52116002)(2950100002)(51416003)(7696005)(6486002)(53416004)(97736004)(8936002)(305945005)(25786009)(4326008)(7736002)(66066001)(2906002)(3846002)(76176011)(36756003)(6116002)(5660300001)(47776003)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR1201MB0229; H:Harpoon.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; CY4PR1201MB0229; 23:bZyUC/VbzkkzYPkbFSoEg3vhn6GNGjSnhdB9UY8?= =?us-ascii?Q?gD/oNRkNx7BIaTX4xNCt91RVsrzdZrGDWxDQaKB6V7Sp5/wcHt2EZLDu0FbJ?= =?us-ascii?Q?9N1/YHqBglIyfucL6Txg1SxKOyuYXnuVZ1XC2RSNg5f4+BuQftf57keTY8tG?= =?us-ascii?Q?rUp2AYPFYU9fPQj7/y5A1Px06PnkLlpz+XFxnh5XqT6GOu+8ooL9TyQATNMt?= =?us-ascii?Q?qUbY9yoGRoF4FJy3fPbm3eW9+ToUa+chpoZJIR/NUWTsELMdniLhIOdxFP82?= =?us-ascii?Q?GNyf8MCjSGBXEp8ZWNO5YWzPW2dFr8xTkabbOPKgmPDdRvYnzVeUobtvMTvJ?= =?us-ascii?Q?w5CaGUKGbUJm4QjmzV0VtS0M7H3gqRLoM7aLRCubGeqvzapC0YurDN2BTviG?= =?us-ascii?Q?Hlcf0BM5XQo7CsWwqYz2Xq/hgtwWv7w2UBimhrXuTyQ30N1YhEbdimbG8sEq?= =?us-ascii?Q?2rdB0pvDIPvDPR9qhunp3TH0Lexgcrb5jql6e+JlQh8wi50lib/jT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2iR8iG0YUiIDZRobT9lEX69KAM7oFWj6WvuFwcKSz4nJ5AE=; 5:eDjavPC6Tus7zHjeGMsm+X+ikZ3vElOzBmuEjkuW3SZuG+Ra/+7wqlFFYkIPbamfpTfh3/VqOke2FQbVQ9LljLG8KhAjQMicMOljpf8dLYoDmRuWIpJHATdSBowfAcr0HMYT6fj6lfPMPENOEigvD6l0p7cMrUdNi2zL/seb9ew=; 24:Cyd/CLZJK/MVToEIYW0OXq7YICTBEmGRbgFBJ1XQLFcbuOR3jY8UGJ/efrlrm9klzSWCqnL1r8FM3GVSpmDQC5F4U7kYI3Kcjzpl2gqtXeM=; 7:jnlFhcpjd7LRtcm2Dh6LNmopximLyjkvhO7kX9OzgVSdp1GL6L5IRq9TNJPFXuHLBOCvIrzr/hBIREX0FMnPFmFBAwUOUEyCZ3jg21XEsCMLSOQZDQsO2GU7j+pqtpu31XGViCKMBchuEF0+VKt70MjAg/UrIlIca6FA+4EKNQcgja9H4rVBreSvr5HjuecaESdkyCB453rtJgZusHjxnRVZGKZ1Q2Io26Eq6Bc3MNIkclEA5JmS+x7Cew3MYm2k SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR1201MB0229; 20:UYXq7jl1jvp6juMPPlMtk8ZT/KKx+rNYg+34R1usIze6rGl0OPySk4UMKKNV0gVMLFzHObbdZkDibBef1TpKoAmn9683wyCBfLKnLUCSo+/E3ztlPBUlktXDBcaVlWqgRS3YfYhGO9AQ5p5cKJZifwA6rJcB3tjbC8Up7mSQRm0eNfn95wfxjA624Z5OxMnYktVR8K6ClRFLUpUlb7SHVvN6BBKcPOgkIEbwnpuB8etJYcKmE9HQEVCsMYNX2eOX X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2017 04:10:02.0966 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3fdac895-7d68-429b-3922-08d53ebab890 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB0229 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 CC: linux-pci@vger.kernel.org Signed-off-by: Jay Cornwall Signed-off-by: Felix Kuehling --- drivers/pci/pci.c | 81 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 1 + include/uapi/linux/pci_regs.h | 2 ++ 3 files changed, 84 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 6078dfc..89a8bb0 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2966,6 +2966,87 @@ bool pci_acs_path_enabled(struct pci_dev *start, } /** + * pci_enable_atomic_ops_to_root - enable AtomicOp requests to root port + * @dev: the PCI device + * + * Return 0 if the device is capable of generating AtomicOp requests, + * all upstream bridges support AtomicOp routing, egress blocking is disabled + * on all upstream ports, and the root port supports 32-bit, 64-bit and/or + * 128-bit AtomicOp completion, or negative otherwise. + */ +int pci_enable_atomic_ops_to_root(struct pci_dev *dev) +{ + 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 & (PCI_EXP_DEVCAP2_ATOMIC_COMP32 | + PCI_EXP_DEVCAP2_ATOMIC_COMP64 | + PCI_EXP_DEVCAP2_ATOMIC_COMP128))) + return -EINVAL; + break; + } + + /* + * Upstream ports may block AtomicOps on egress. + */ + if (pci_pcie_type(bridge) == PCI_EXP_TYPE_UPSTREAM) { + 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 f4f8ee5..2a39f63 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2062,6 +2062,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); #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 f8d5804..45f251a 100644 --- a/include/uapi/linux/pci_regs.h +++ b/include/uapi/linux/pci_regs.h @@ -623,7 +623,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_COMP32 0x00000080 /* 32b AtomicOp completion */ #define PCI_EXP_DEVCAP2_ATOMIC_COMP64 0x00000100 /* Atomic 64-bit compare */ +#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 */