From patchwork Wed Aug 15 13:49:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Douglas X-Patchwork-Id: 10566645 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-2.web.codeaurora.org (Postfix) with ESMTP id 24B7C13B6 for ; Wed, 15 Aug 2018 14:07:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13C441FFFE for ; Wed, 15 Aug 2018 14:07:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 077C3285D6; Wed, 15 Aug 2018 14:07: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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 54E2B1FFFE for ; Wed, 15 Aug 2018 14:07:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729047AbeHOQ7l (ORCPT ); Wed, 15 Aug 2018 12:59:41 -0400 Received: from mail-eopbgr700059.outbound.protection.outlook.com ([40.107.70.59]:27264 "EHLO NAM04-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729125AbeHOQ7l (ORCPT ); Wed, 15 Aug 2018 12:59:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w59MpjsJcq4pQZylcUgEew4rfizrfxmgd/j3zX/PezU=; b=BR4KKF+T4uvdsKs7lOPzfqhUPLptmE4yeIV19WGVILHHcLpwqExSj+AZIe9IQ95LTFv8CW7joGUNgVSeYYvwIFARkbGsQFsGr+LgWJKcyx5BipbF6cVEhO2wRK2Msgv0mBsJDTzvyRKbDyWcvE+DzQMTO87FWrHWYtwj6NBfVWo= Received: from CO2PR07CA0055.namprd07.prod.outlook.com (2603:10b6:100::23) by BL2PR07MB2289.namprd07.prod.outlook.com (2a01:111:e400:c752::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1038.23; Wed, 15 Aug 2018 13:49:14 +0000 Received: from BY2NAM05FT026.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e52::209) by CO2PR07CA0055.outlook.office365.com (2603:10b6:100::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1059.19 via Frontend Transport; Wed, 15 Aug 2018 13:49:13 +0000 Authentication-Results: spf=softfail (sender IP is 158.140.1.28) smtp.mailfrom=cadence.com; arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=fail action=none header.from=cadence.com; Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by BY2NAM05FT026.mail.protection.outlook.com (10.152.100.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.1080.6 via Frontend Transport; Wed, 15 Aug 2018 13:49:13 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id w7FDnBLf021269 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Wed, 15 Aug 2018 06:49:12 -0700 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 15 Aug 2018 15:49:24 +0200 Received: from lvloginb.cadence.com (10.165.177.11) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 15 Aug 2018 15:49:23 +0200 Received: from lvloginb.cadence.com (localhost [127.0.0.1]) by lvloginb.cadence.com (8.14.4/8.14.4) with ESMTP id w7FDnAgP024205; Wed, 15 Aug 2018 14:49:10 +0100 Received: (from adouglas@localhost) by lvloginb.cadence.com (8.14.4/8.14.4/Submit) id w7FDnAWA024193; Wed, 15 Aug 2018 14:49:10 +0100 From: Alan Douglas To: CC: , , , , , , Alan Douglas Subject: [PATCH v2 5/5] PCI: cadence: Add MSI-X capability to EP driver Date: Wed, 15 Aug 2018 14:49:08 +0100 Message-ID: <1534340948-24093-1-git-send-email-adouglas@cadence.com> X-Mailer: git-send-email 2.2.2 MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(376002)(346002)(396003)(136003)(39860400002)(2980300002)(3190300001)(36092001)(189003)(199004)(16586007)(5660300001)(8676002)(305945005)(426003)(36756003)(14444005)(42186006)(316002)(8936002)(476003)(2616005)(54906003)(107886003)(47776003)(7636002)(50226002)(86362001)(246002)(106466001)(478600001)(50466002)(126002)(356003)(2351001)(4326008)(51416003)(26826003)(486006)(186003)(26005)(87636003)(2906002)(336012)(6916009)(105596002)(48376002);DIR:OUT;SFP:1101;SCL:1;SRVR:BL2PR07MB2289;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;MX:1;A:1; X-Microsoft-Exchange-Diagnostics: 1;BY2NAM05FT026;1:RIZovJmmPfD26QNVqHHx7UmX2Jx05dHBlpVjQ9C2bnwtjy03Yr0ALhdZrVyYcTQeK8wtCb06wR4OYUYNQyxoo9NBZC0lxnsuaPqFNqtxpxwVhvPeE6zDToNh7lULOiTT X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 57b75223-5b67-4816-5122-08d602b5e2ab X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060);SRVR:BL2PR07MB2289; X-Microsoft-Exchange-Diagnostics: 1;BL2PR07MB2289;3:g6SDC3GmNF01sjVf3eUN8c7WJAT3U0Jzsq+ozskjutB4AAx3/9yqahNGY2RZu0EFFNaAQX0YtrU7cUUtrnsGaR252+CpetSH7MlRL3/552AaVq7G0OiYrtbNL0ofoyeQLR3CSp7iyT6qT/lPwYsHq3yr9V6hWplS3aVIdx2eapAVboLlYbIfsxgLu/F6gpfeaHMbaaK8PZKh5hdxTS6L8hDGgq848EhZehQqHoJkFaj0KcSK1kpUUbalR1hw9BWNTqAzFSrHpWDe3bGDWOgU91Ut3KhmaF890m218cqcpMezX3IhHyh6L5hhfcaed0Lu5je747QR1mjMgRtgIrZfM0hEuDWSFlC8L/EXD0AAaX8=;25:omQR0TAz0wp08FEaTHRaHs5tD2DE2OKzq1XV8jETITMBNR6N7mGeFbv/Oq4RX8XxjhBtk7Tq6Do2wN1ZJWisFooATiYJlXcuI2mqmuYQr41ra5UWuzr+u3k+PkvtV7Ufc9qjdbG1M34ScQ56ipi/V4y4I/tlBy4WrLLhNaladFTKk1C2jie6oRv6ETSWl4yatwjYxEiOrUlFVrwkdC58irOLJVO7rb+uXyRbsBbUMdS4Vf34qrhqrzvSo6Yp20QzUZG+eV4vOUkOr/o3Gp9QfkCtLwSsXpXiPs5bshwPIjd0+xej7j9pijNp+pl/QdeYVHMxL2LdtQYiqH2mndzmrA== X-MS-TrafficTypeDiagnostic: BL2PR07MB2289: X-Microsoft-Exchange-Diagnostics: 1;BL2PR07MB2289;31:jPoVVPUoB3WQ2FZVp4aC1YkQatDTCDsV1K0nxjf4EjzlHvc6zHFlVbr2ZnwMtHuO54CsQiUUrmc1RXWDjBjx8q6wPWXryCUDa2Zw7rLWoHcDEb2lr8PvQlsJF2re17qur17wnA00c2kmZj4gzUOxHylBcEZZ/sPg0rSC4kjXbDiptUAmUettuoQOPAw+9WowjSQ2TaVUiK5uSKh8K+nfIQzyXif4EjPAPJ5TKSEb6Z0=;20:uRL8AU5QozU9wfQG3HyNnmX8dcsj6PitIhnvKv4Pbo3jrvWYWIrsc9qAcgzW8Itv+PiwRDRqUzQ7JZOg8CGwZzj47gbCTT2Iap4EpVJhNC7gN2mBNG5cRxQ/s7JJrrWu5HI/y/gqNnvhUSzUcU4H+PrMncHDJmf0ZmeCCwSj/yhyceoa2QqqjMSWPgJ0HX9XRXEXFxKcMqHuO/JLmb7bsJlWN1bG9UMID9tTOSd33tYiAYfvdryUSl950bo8KLTa2WJE+qQGZr53r+U0wbD/ucu1T7m0EJ8YKSyXdP6dphsJKMSN4fi48+ucziyrqz2nTL7x5D1txZtOIaS3IVSIoN9ZLdj7QN9iJW9SzXt9jnbs+SdQjiHdL3+DEeFI246lACJqRB15iXPPiBVqf1lySQ64Bx7NK86w1eFxfjd6cKvY+FidnM6CKUJZdbZP93oiNRB/VP8LHY/dQXFptMH0q4GY919SnwbTgD5RIz2Jc6DMjEaGE4UX4FcnKyEDaXeZ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(72806322054110); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231311)(944501410)(52105095)(93006095)(93003095)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123558120)(20161123560045)(6072148)(201708071742011)(7699016);SRVR:BL2PR07MB2289;BCL:0;PCL:0;RULEID:;SRVR:BL2PR07MB2289; X-Microsoft-Exchange-Diagnostics: 1;BL2PR07MB2289;4:Q3SUl5swyv7PuMHTW14UTlr043FlJVPtsRwjmMSrJJ97H98UZ+oyFgL+YlwVP8x9fY1X0cYk+K5JVtxqcc5OqPEJCu1pjwKCc7WZyE7qxedUBbmgHY77UZy6Pq96Nf8Ul33jp21I1U9M+3YHwUEdJjrOIRPg2dFtB8cECcV26YmPlC3EjXQl9sjyqeJor/TanZdJWgLm/1NLNx5zExz0dnnQKZyVyow6yL6EtBlGCK4WJiJ9w22yOVBovgwEWpGiXzl4BbJSG8rKcaI6W/Z9Azxc3X7PJepOSVZb4DZ7ro1qfDjPuR49wRCbdZ1/OADR X-Forefront-PRVS: 07658B8EA3 X-Microsoft-Exchange-Diagnostics: 1;BL2PR07MB2289;23:9hXi01zKOO0vhSPG8d1omIeiIUGsXviGJPAw4AVZZm3k6KNVfxA/p2YElIJ5biE01dDsydGxI9otNk9WsrBcT/0vrxChRbwCCbMVE2zM0A0de+UbUAhTaOcAOWusop+sYEsW9RR8yG1kLeOWDd+xzT6g7ehqF0m63L12IvM1iTGOSV+ml52VORgKx7Zmjkq+ST1C17JXsM4Iflco3JpUUs8XERvHKLeAsrZZ0Xq8e49kYCO9t/RGm0llHCVpwcdOq0y08APfHj3V72lS6x+e9GkRjdBbrdkyTS7ALFY0OMVjfFUWY74H3B34gLBkHarclq2ImFiFK4ZyRpopRTVz5Sbq+uOQUcSr6ZQV169DSUHuwTkoxIPBivkvuM59UUuGjeqtcEknx9H2+hXPoMb3uc9Iq0B9Uqw6S2tDa3PIdXNsfhYVhHAG8nsmpC3M5zrBixdGos5Lpgrm/YA7P1wcHIHLEYwOAJ7WlIoHrRSf5/VOPM4hqeN2ItgXeMgvlND5pt5LxK+dJbMWAbret4aFXtFYAKYY+WX7svrIUy8+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Zq6VudXJAMmhrJ73bwpZFtlx92958hNOVDG5wRx880Cjl57qzk+w1pG6acd39ROT9JyKvk X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2018 13:49:13.4093 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 57b75223-5b67-4816-5122-08d602b5e2ab X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR07MB2289 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 Add set_msix and get_msix functions to driver, and handle PCI_EPC_IRQ_MSIX request in raise_irq. BAR5 is used for the MSI-X vectors. Signed-off-by: Alan Douglas --- drivers/pci/controller/pcie-cadence-ep.c | 107 ++++++++++++++++++++++++++++++- drivers/pci/controller/pcie-cadence.h | 1 + 2 files changed, 107 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/pcie-cadence-ep.c b/drivers/pci/controller/pcie-cadence-ep.c index 1248d75..259b9a6 100644 --- a/drivers/pci/controller/pcie-cadence-ep.c +++ b/drivers/pci/controller/pcie-cadence-ep.c @@ -16,6 +16,7 @@ #define CDNS_PCIE_EP_MIN_APERTURE 128 /* 128 bytes */ #define CDNS_PCIE_EP_IRQ_PCI_ADDR_NONE 0x1 #define CDNS_PCIE_EP_IRQ_PCI_ADDR_LEGACY 0x3 +#define CDNS_PCIE_EP_MSIX_BAR 0x5 /** * struct cdns_pcie_ep - private data for this PCIe endpoint controller driver @@ -255,6 +256,43 @@ static int cdns_pcie_ep_get_msi(struct pci_epc *epc, u8 fn) return mme; } +static int cdns_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no) +{ + struct cdns_pcie_ep *ep = epc_get_drvdata(epc); + struct cdns_pcie *pcie = &ep->pcie; + u32 cap = CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET; + u32 val, reg; + + reg = cap + PCI_MSIX_FLAGS; + val = cdns_pcie_ep_fn_readw(pcie, func_no, reg); + if (!(val & PCI_MSIX_FLAGS_ENABLE)) + return -EINVAL; + + val &= PCI_MSIX_FLAGS_QSIZE; + + return val; +} + +static int cdns_pcie_ep_set_msix(struct pci_epc *epc, u8 fn, u16 interrupts) +{ + struct cdns_pcie_ep *ep = epc_get_drvdata(epc); + struct cdns_pcie *pcie = &ep->pcie; + u32 cap = CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET; + u32 val, reg; + + reg = cap + PCI_MSIX_FLAGS; + val = cdns_pcie_ep_fn_readw(pcie, fn, reg); + val &= ~PCI_MSIX_FLAGS_QSIZE; + val |= interrupts; + cdns_pcie_ep_fn_writew(pcie, fn, reg, val); + /* Set MSIX BAR and offset */ + cdns_pcie_ep_fn_writel(pcie, fn, 0xb4, CDNS_PCIE_EP_MSIX_BAR); + /* Set PBA BAR and offset. BAR must match MSIX BAR */ + cdns_pcie_ep_fn_writel(pcie, fn, 0xb8, 0x10000 | CDNS_PCIE_EP_MSIX_BAR); + + return 0; +} + static void cdns_pcie_ep_assert_intx(struct cdns_pcie_ep *ep, u8 fn, u8 intx, bool is_asserted) { @@ -366,8 +404,69 @@ static int cdns_pcie_ep_send_msi_irq(struct cdns_pcie_ep *ep, u8 fn, return 0; } +static int cdns_pcie_ep_send_msix_irq(struct cdns_pcie_ep *ep, u8 fn, + u16 interrupt_num) +{ + struct cdns_pcie *pcie = &ep->pcie; + u32 cap = CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET; + u16 flags; + u64 pci_addr_mask = 0xff; + u16 tbl_offset = 0; + u32 bar_addr_upper, bar_addr_lower; + u32 msg_addr_upper, msg_addr_lower; + u32 msg_data; + u64 tbl_addr, msg_addr; + void __iomem *msix_tbl; + + /* Check whether the MSI-X feature has been enabled by the PCI host. */ + flags = cdns_pcie_ep_fn_readw(pcie, fn, cap + PCI_MSIX_FLAGS); + if (!(flags & PCI_MSIX_FLAGS_ENABLE)) + return -EINVAL; + /* We want local address, not address on host. Table is at offset 0 */ + bar_addr_lower = cdns_pcie_readl(pcie, + CDNS_PCIE_AT_IB_EP_FUNC_BAR_ADDR0(fn, CDNS_PCIE_EP_MSIX_BAR)); + bar_addr_upper = cdns_pcie_readl(pcie, + CDNS_PCIE_AT_IB_EP_FUNC_BAR_ADDR1(fn, CDNS_PCIE_EP_MSIX_BAR)); + + tbl_addr = ((u64)bar_addr_upper) << 32 | bar_addr_lower; + tbl_addr += (tbl_offset + ((interrupt_num - 1) * PCI_MSIX_ENTRY_SIZE)); + tbl_addr &= PCI_BASE_ADDRESS_MEM_MASK; + msix_tbl = phys_to_virt(tbl_addr); + if (!msix_tbl) + return -EINVAL; + + msg_addr_lower = readl(msix_tbl + PCI_MSIX_ENTRY_LOWER_ADDR); + msg_addr_upper = readl(msix_tbl + PCI_MSIX_ENTRY_UPPER_ADDR); + msg_addr = ((u64)msg_addr_upper) << 32 | msg_addr_lower; + + msg_data = readl(msix_tbl + PCI_MSIX_ENTRY_VECTOR_CTRL); + if (msg_data & 0x1) + return -EINVAL; + + msg_data = readl(msix_tbl + PCI_MSIX_ENTRY_DATA); + + iounmap(msix_tbl); + + /* Set the outbound region if needed. */ + if (unlikely(ep->irq_pci_addr != (msg_addr & ~pci_addr_mask) || + ep->irq_pci_fn != fn)) { + /* First region was reserved for IRQ writes. */ + cdns_pcie_set_outbound_region(pcie, fn, 0, + false, + ep->irq_phys_addr, + msg_addr & ~pci_addr_mask, + pci_addr_mask + 1); + ep->irq_pci_addr = (msg_addr & ~pci_addr_mask); + ep->irq_pci_fn = fn; + } + writel(msg_data, ep->irq_cpu_addr + (msg_addr & pci_addr_mask)); + + return 0; +} + static int cdns_pcie_ep_raise_irq(struct pci_epc *epc, u8 fn, - enum pci_epc_irq_type type, u8 interrupt_num) + enum pci_epc_irq_type type, + u16 interrupt_num) { struct cdns_pcie_ep *ep = epc_get_drvdata(epc); u32 link_status; @@ -384,6 +483,9 @@ static int cdns_pcie_ep_raise_irq(struct pci_epc *epc, u8 fn, case PCI_EPC_IRQ_MSI: return cdns_pcie_ep_send_msi_irq(ep, fn, interrupt_num); + case PCI_EPC_IRQ_MSIX: + return cdns_pcie_ep_send_msix_irq(ep, fn, interrupt_num); + default: break; } @@ -430,6 +532,8 @@ static int cdns_pcie_ep_start(struct pci_epc *epc) .unmap_addr = cdns_pcie_ep_unmap_addr, .set_msi = cdns_pcie_ep_set_msi, .get_msi = cdns_pcie_ep_get_msi, + .set_msix = cdns_pcie_ep_set_msix, + .get_msix = cdns_pcie_ep_get_msix, .raise_irq = cdns_pcie_ep_raise_irq, .start = cdns_pcie_ep_start, }; @@ -501,6 +605,7 @@ static int cdns_pcie_ep_probe(struct platform_device *pdev) } epc_set_drvdata(epc, ep); + epc->features |= EPC_FEATURE_MSIX_AVAILABLE; if (of_property_read_u8(np, "max-functions", &epc->max_functions) < 0) epc->max_functions = 1; diff --git a/drivers/pci/controller/pcie-cadence.h b/drivers/pci/controller/pcie-cadence.h index 4bb2733..bd83b5b 100644 --- a/drivers/pci/controller/pcie-cadence.h +++ b/drivers/pci/controller/pcie-cadence.h @@ -93,6 +93,7 @@ #define CDNS_PCIE_EP_FUNC_BASE(fn) (((fn) << 12) & GENMASK(19, 12)) #define CDNS_PCIE_EP_FUNC_MSI_CAP_OFFSET 0x90 +#define CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET 0xb0 /* * Root Port Registers (PCI configuration space for the root port function)