From patchwork Thu Sep 24 15:59:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jay Cornwall X-Patchwork-Id: 7261731 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0CB1DBEEC1 for ; Thu, 24 Sep 2015 23:36:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D85ED2082E for ; Thu, 24 Sep 2015 23:36:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8EAAD20761 for ; Thu, 24 Sep 2015 23:36:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753190AbbIXXgJ (ORCPT ); Thu, 24 Sep 2015 19:36:09 -0400 Received: from mail-bl2on0074.outbound.protection.outlook.com ([65.55.169.74]:29616 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753043AbbIXXgH (ORCPT ); Thu, 24 Sep 2015 19:36:07 -0400 X-Greylist: delayed 2047 seconds by postgrey-1.27 at vger.kernel.org; Thu, 24 Sep 2015 19:36:07 EDT Received: from BY2PR12CA0006.namprd12.prod.outlook.com (10.160.121.16) by BLUPR12MB0418.namprd12.prod.outlook.com (10.162.92.11) with Microsoft SMTP Server (TLS) id 15.1.274.16; Thu, 24 Sep 2015 23:01:58 +0000 Received: from DM3NAM03FT002.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::205) by BY2PR12CA0006.outlook.office365.com (2a01:111:e400:2c84::16) with Microsoft SMTP Server (TLS) id 15.1.280.20 via Frontend Transport; Thu, 24 Sep 2015 23:01:58 +0000 Authentication-Results: spf=fail (sender IP is 165.204.84.221) smtp.mailfrom=jcornwall.me; jcornwall.me; dkim=none (message not signed) header.d=none; jcornwall.me; dmarc=none action=none header.from=jcornwall.me; Received-SPF: Fail (protection.outlook.com: domain of jcornwall.me does not designate 165.204.84.221 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.221; helo=atltwp01.amd.com; Received: from atltwp01.amd.com (165.204.84.221) by DM3NAM03FT002.mail.protection.outlook.com (10.152.82.127) with Microsoft SMTP Server id 15.1.274.4 via Frontend Transport; Thu, 24 Sep 2015 23:01:58 +0000 X-WSS-ID: 0NV7EN8-07-XY5-02 X-M-MSG: Received: from satlvexedge01.amd.com (satlvexedge01.amd.com [10.177.96.28]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by atltwp01.amd.com (Axway MailGate 5.3.1) with ESMTPS id 2B2A5CAE634; Thu, 24 Sep 2015 19:01:56 -0400 (EDT) Received: from SATLEXDAG01.amd.com (10.181.40.3) by satlvexedge01.amd.com (10.177.96.28) with Microsoft SMTP Server (TLS) id 14.3.195.1; Thu, 24 Sep 2015 18:02:09 -0500 Received: from jcornwal-tn.amd.com (10.180.168.240) by SATLEXDAG01.amd.com (10.181.40.3) with Microsoft SMTP Server id 14.3.195.1; Thu, 24 Sep 2015 19:01:56 -0400 From: Jay Cornwall To: CC: Jay Cornwall Subject: [PATCH v3] PCI: Add pci_enable_atomic_request Date: Thu, 24 Sep 2015 10:59:50 -0500 Message-ID: <1443110390-4080-1-git-send-email-jay@jcornwall.me> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Matching-Connectors: 130876093184099493; (3b476b41-6bd3-4b00-1a0b-08d2adb5efdc); () X-Forefront-Antispam-Report: CIP:165.204.84.221; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(87936001)(53416004)(11100500001)(50986999)(189998001)(97736004)(106466001)(46102003)(85426001)(33646002)(5001860100001)(19580405001)(4001540100001)(5003940100001)(5001830100001)(47776003)(229853001)(62966003)(110136002)(105606002)(2351001)(5007970100001)(36756003)(86362001)(64706001)(48376002)(77156002)(92566002)(77096005)(50226001)(68736005)(74482002)(50466002)(19580395003); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0418; H:atltwp01.amd.com; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0418; 2:uSV9c1ljJkBRT7S5ZFyBZMGV2VYt9ZKyrEUIAIPf63hJL1bwiZ2RKuINQtSjc2VY6HhWHTStqo7F0EbVyDFBrml5qI9k9neBLBbuZpksmTP+9ap28eH79bqPdFmqTI5Y6qpRi9SXCigE+BVXMOJ91ZKSKS28159eUZKzDZ3Jd2U=; 3:907EQHuMNLoXrLFxASz6aqrAt9sIxFLiePLNTO+b4N2no7nAUJjhIOUqnL+13JBEAC8hycE5vSeisix1J/yPds2DR61WiQN9cEEKeOZdljFui+bO0IEztmy97tQ1nJHSBQhOgIOjgh0AnPc+cmitCIDbBverrNFjaras3OW+Grn3Mwe+cRX3J86BEk6ohfKg/oy8jXkarsW8Y2R1JddPblje0sZmEw5rDmGYXHeK1X0WbNywWda0OGfxtUEYy2RW; 25:tWt76qVWPT8fDGNQ+f8uKW78odY256vaLjHGPITcaa757F9mixg2eUIayHeKWt4wky5ZnjubJnFqwhfaoCtRaFD16CLpxai4dniA4zlhtmiZX4f07nAbEk5xW9qDX/f4WOxq2dF9ldkw6xSjaKA8xLzjPT9cyWIcIjD4DQer2jz0zk2x1WqHrpeiO4v6bbGG6q82t5B3+Fx9S18d7lily9mlb+GrS2TUu4TnaYH57sPCn9FSmuFgr4JNzU7QV/5QGqjEx1w1fIPT1b8ekTMm1w== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0418; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(520078)(5005006)(8121501046)(3002001); SRVR:BLUPR12MB0418; BCL:0; PCL:0; RULEID:(400006); SRVR:BLUPR12MB0418; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0418; 4:Sv8wlTLGiFYHaP8JZ9ad0atDuQPX97QtVn517HHH6v2PiU9qdRzhHmw2TOsrRy5exRL8+GbX2LAwf5Y89WnB2L8o/5kQttpj5qZYlw8LR+AUpEERIhp9ZX6Jrm0bv6zHYfq9dFAwwhIWu2HoLI6osNEOa/fwFbhQEsTyLX38gYpbsfK/7oCUgQeuexdYupCWyuKT/d+z2YWIYvYDUNuR2WM6YRt7rltVek6PJeOXBMBriwfEVoK2baBqBudPxmNRcKwPcpfp84V75n2uE9YbIDtbVxB75US1zJhvZ264hr1vTM/Cwgdhz5vYE6uh2LUmIUvMGN3XqTKWI3nxvm+Dw5kPIgdLHvrN5hMc4xlcwT8= X-Forefront-PRVS: 070912876F X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR12MB0418; 23:6w2g9O+TIntRm7bF6hzV3HCdlGW5Xxg85bYXcwhaJ?= =?us-ascii?Q?gRsD/kThKhwVjNxNlBducEO8VOl8RQrQZoZdVBgGmICczm5kH2AhqrlbZKcA?= =?us-ascii?Q?fN1sRO3biX1PEuLtJL56V203xsXjVGY5L0Zjj9OYhopDtxn0m2QHs/OqLEaF?= =?us-ascii?Q?MBpw53Y5+zHyaU49geemSHwi54vtpoIt6rJiAFNtYV/cqOhmYir8vZFj/R3s?= =?us-ascii?Q?bk3Xb35Pg/kRAwoFIi/MWogIMdpHgLXshYcc86pQ1FCx1jS51JSHdgirA4qp?= =?us-ascii?Q?jGxPepN8GAM2v0rcwNS6L4p9LAMfYkT9HrVT7x9EPjt1hXtRFgVOlmUMdhOr?= =?us-ascii?Q?eQ04G2ZdBXie7CF4euclD+fp0P5mGOMISg/0mGbB5gkM0NuBupeadQlNTktW?= =?us-ascii?Q?EYoqocC6Pbx+M+REkIRZ0Es0JP5QwoK93Gbta9E8TiLJxe3NK7WHLcHpTPYx?= =?us-ascii?Q?Dn16FptCEIybH5Docwplfq6bQtdmQjSxflr7PoTu3qmcR4iTq6OwHp+oNXRz?= =?us-ascii?Q?7DrAsRAaepJQO+Q10g3dc+WtpL6zeHFSaIVVD7sssGqIG7A00pPrgCenR7E2?= =?us-ascii?Q?RCRE6yVOO7rLMTY3+upzMFQ8vdMyLiMzKkB1q9SVffzd5C+3n6vD9hSjC5c/?= =?us-ascii?Q?icdMH+/V291LCUD4hPtBCWk8lc7nPI+4F3N6QqXAoLdfeECtWri6O2k94PHu?= =?us-ascii?Q?BoEs5zoHZeoVyXfv0P3JXuHxfwOHvrndbrSjHiiBSqt/bTkWE2p+ubwvkCX1?= =?us-ascii?Q?uCXp1uUi8xLMi3AHViJ017eF/BZZKvMMiccmewVUQ3+yeCqbnEUdmMI5VolQ?= =?us-ascii?Q?dqe1wV/S9giORpcaSxNAzBRgpMNbLz0g7JeTKOajhlXfMkcsWkBDajzo4pnu?= =?us-ascii?Q?KwvgAbbKS1sET/EPhQSnU1ylyNKob14D7x8VoFCI1cxi0122SJBglnavOK9J?= =?us-ascii?Q?Tn7k+jkHkFp6OyLaErzW3Te/e9qaIiFOSFwN/P6HYK1GuCWmT87+f9Da1NY6?= =?us-ascii?Q?Njqppy1GWZ3334NtSG/M9sSqGodYZMec4kHuBGORwwHB6Dyxknmz1Oi4A7+b?= =?us-ascii?Q?wq/JGt6qt+FSJ6+PVgOVdgOezNayrOfIi+3dEmOR91u5OR8Iac3rixJjk/nY?= =?us-ascii?Q?ucuMP2DvNw=3D?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0418; 5:Pqf90GL9r0fp9+4d4XbPvhG9ycc9fbfDqOXCmsooQNVk3/dFSZVVXRVk6IArEVmp6U/GsrrZ5DODUFlREIKu4ZA91aYnisaxNb4XrzLW1onLeX8qmHK5HnjHKbOihV+LgaQuVteL9jZFeFymqKKO9jECCNvuYGBNXHoSs0zz1SI=; 24:uK944wRozT+5EXOJ9/ZawExfuGFxHznqn0FWv0Bb+29WyBWW7VQn1ZIS3iqW1OsBW37YKgIAyouThjwfMZycR9c6D6NORY7UXzGYVAlKLeU= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Sep 2015 23:01:58.0974 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[165.204.84.221]; Helo=[atltwp01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0418 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, DATE_IN_PAST_06_12, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 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_request 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 Signed-off-by: Jay Cornwall --- drivers/pci/pci.c | 70 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 1 + include/uapi/linux/pci_regs.h | 5 ++++ 3 files changed, 76 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 6a9a111..edc56e4 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2453,6 +2453,76 @@ bool pci_acs_path_enabled(struct pci_dev *start, } /** + * pci_enable_atomic_request - enable or disable AtomicOp requester + * @dev: the PCI device + * + * Return 0 if the device is capable of generating AtomicOp requests, + * all upstream bridges support AtomicOp routing, and the root port supports + * 32-bit, 64-bit and/or 128-bit AtomicOp completion, or negative otherwise. + */ +int pci_enable_atomic_request(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: + case PCI_EXP_TYPE_ROOT_PORT: + 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_ROUTING)) + 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; + } + + + bus = bus->parent; + } + + pcie_capability_set_word(dev, PCI_EXP_DEVCTL2, + PCI_EXP_DEVCTL2_ATOMICOP_REQ); + + return 0; +} +EXPORT_SYMBOL(pci_enable_atomic_request); + +/** * 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 e90eb22..4e50003 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1801,6 +1801,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_request(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 413417f..013c2bd 100644 --- a/include/uapi/linux/pci_regs.h +++ b/include/uapi/linux/pci_regs.h @@ -571,6 +571,10 @@ */ #define PCI_EXP_DEVCAP2 36 /* Device Capabilities 2 */ #define PCI_EXP_DEVCAP2_ARI 0x00000020 /* Alternative Routing-ID */ +#define PCI_EXP_DEVCAP2_ATOMIC_ROUTING 0x00000040 /* AtomicOp routing */ +#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 */ @@ -578,6 +582,7 @@ #define PCI_EXP_DEVCTL2 40 /* Device Control 2 */ #define PCI_EXP_DEVCTL2_COMP_TIMEOUT 0x000f /* Completion Timeout Value */ #define PCI_EXP_DEVCTL2_ARI 0x0020 /* Alternative Routing-ID */ +#define PCI_EXP_DEVCTL2_ATOMICOP_REQ 0x0040 /* Allow AtomicOp requests */ #define PCI_EXP_DEVCTL2_IDO_REQ_EN 0x0100 /* Allow IDO for requests */ #define PCI_EXP_DEVCTL2_IDO_CMP_EN 0x0200 /* Allow IDO for completions */ #define PCI_EXP_DEVCTL2_LTR_EN 0x0400 /* Enable LTR mechanism */