From patchwork Fri Apr 4 19:01:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 14038797 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A89C2C36010 for ; Fri, 4 Apr 2025 19:22:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To: In-Reply-To:References:Message-Id:Content-Transfer-Encoding:Content-Type: Subject:Date:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kKlGqegoRweF1++Jqh2S5594pr64Kj2EekHsAJSq3y8=; b=2XQOPjOqcWH9eYAjZGKOWMizR9 6ydxLYDkIKBAP/P9D2v5w3IFf7EmCHH3XPIi5H5YRCoVkF6OY21sNZZhxJ4VJoNXj+LoNghSRz0wV uV/exiWFXUvy3/RLGLkQ+hHllU4yMTXCuRMHIP/Jem8vCur9lmQ7KIpZ6PxHti6QpeKFy+WR2sX/1 +BdTWsZA2+6OFFK1BY5k0Nj0SLP+a5zneJlRFYJNvQgqAdairL5vySNZKHvflmK32owPmHvVQvo48 WLqvVSmavVPV8Y5/lVztCIOvXtdwvZlOPd6IEoMb+iVLPWsKyi0F5VV16K5MODIIYWWIYu5fRxW29 zdFMDqug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1u0mcC-0000000CcW7-3knw; Fri, 04 Apr 2025 19:22:08 +0000 Received: from mail-am6eur05on20609.outbound.protection.outlook.com ([2a01:111:f403:2612::609] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u0mJL-0000000Ca97-0By4 for linux-arm-kernel@lists.infradead.org; Fri, 04 Apr 2025 19:02:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uX3e9RQ3//xkoF94yKt0RgWiR/kgkGELjvPZyaYl+R3CFwNo6CUYPwKCdwfLlrkApQtKPjwTJzEgQzTwhwh42jnzuFMDsNrsWW8Qj4nWgVZ9iK/4aIy0RVMYw1NpCo389/qWWqDmjO0+wUWDqRw2KOw6vVcD6KSz+4je73E+0yBltPQa2sw36BGw5NOHdOhixfgyzJgHWw1QF3coh1JaheZf96tnvsj9Bl5PqwtDTXotXxfkdqBLXdniuOYfQQCQz1nhpwjOafG5RKNiy8IArFNhXxIIwa4SZcImUz5cg0wMgUUKyitl+gbbIYhxOMa7dO7HOmFuIkH2ly6dlc0cWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kKlGqegoRweF1++Jqh2S5594pr64Kj2EekHsAJSq3y8=; b=p6MZqwOP1tMulbHDZy9Mvb9Ljl2UtikBltz26BHlq6mK84ykgx5iSAnVGX1ZkdrbbnAKDTm8V71Y0Ch4+JnQdiuT7WU7g2yMILsz8EghdBBGLCtsqMv8SbL19hjnb8RP2JAI/1JetBUKAGxTF91XhCqNR5EaOYL7E1yhGIWczi5/oABd6t7439AiDBFykQfk8yYS/EJeD42zJylfVkbiHWriFwh5UVTEN0ZPpJFTJPMP9Y/gUfRGpD2mT6AgFeqdcL3aym1DcIrrPDiPclUuuQHls50Rpg7iAVCe9lxD1pCXDXbDQXFnXzI+IFSKWVJBupigi4lQ3Q5LFMPY9uTUaA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kKlGqegoRweF1++Jqh2S5594pr64Kj2EekHsAJSq3y8=; b=PEVhgMc+3D2R/3Qzi0t6rIb2tF+sSbPWIbjBYd/ahSudR4Z1NqMtr98x8wag/hssPNiZaItxlcpEkZNew6xcN2lLFg98by2diaWWA4cn0Bk9EVy/fea5W9T2pXD0ETjzRZDQgN3oedjYyuyEjvZq018mg5xqqR1eCLn96qVzeiUxfYh3n/3uY5v8GYlcl2SCYdaM6n2SLei2ncWi3VtEFyASAjM0UKyJ/TcQ0+pHOF70sIHs3yoSUBULZGbW1/l68TBmg3p8WmoOU0NiFWekFciMDTToMDnxe0T+zZEC1ZuTNX6RHUBb8mMbdH0epFLZayIIuDF5hazK2fcjdL6Pbw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by VI1PR04MB6957.eurprd04.prod.outlook.com (2603:10a6:803:135::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.49; Fri, 4 Apr 2025 19:02:36 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%2]) with mapi id 15.20.8534.048; Fri, 4 Apr 2025 19:02:36 +0000 From: Frank Li Date: Fri, 04 Apr 2025 15:01:11 -0400 Subject: [PATCH v16 10/15] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20250404-ep-msi-v16-10-d4919d68c0d0@nxp.com> References: <20250404-ep-msi-v16-0-d4919d68c0d0@nxp.com> In-Reply-To: <20250404-ep-msi-v16-0-d4919d68c0d0@nxp.com> To: Kishon Vijay Abraham I , "Rafael J. Wysocki" , Thomas Gleixner , Anup Patel , Kishon Vijay Abraham I , Marc Zyngier , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Manivannan Sadhasivam , =?utf-8?q?Krzysz?= =?utf-8?q?tof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Shuah Khan , Richard Zhu , Lucas Stach , Lorenzo Pieralisi , Rob Herring , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Krzysztof Kozlowski , Conor Dooley Cc: Niklas Cassel , dlemoal@kernel.org, jdmason@kudzu.us, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-kselftest@vger.kernel.org, imx@lists.linux.dev, devicetree@vger.kernel.org, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1743793288; l=8739; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=GZxnLuC67KA9+f1ZFFupamn6BH671XQaImre37vE7/Q=; b=VNgx6s12NV0Z48nCnx1GqOaQ124ymogqru/wrUmPfe6kQgvS1F1DECMLXAmWfg9SgFUnYRa9Z ozcB6MqJPgkCVjPTgUmiqsDj9oPrX/Y7cMwoDeyjlbC0x5caYPG4tQr X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: PH8P222CA0011.NAMP222.PROD.OUTLOOK.COM (2603:10b6:510:2d7::35) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|VI1PR04MB6957:EE_ X-MS-Office365-Filtering-Correlation-Id: 9a65c832-b880-419d-fb0b-08dd73ab4384 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|1800799024|366016|7416014|376014|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Pe55wIpBONCap6mg86j/vuKr4sV+TWw?= =?utf-8?q?f0k1xgrnv5Tx5ghO6mH5fFaB9mb/0KtgP4sUL5hjgbHN7pGV3nrmWSNGYAumTCaiX?= =?utf-8?q?C0CVepsnx5lT4btyCkLPjs5+NX9fi3nJew1N6ovU8ooVL6i6zGJpvxTY1URQ8mevm?= =?utf-8?q?edxoytCbNzlNsIqJr+SlnRW8AcYywUaqtB+STjc2bpkeZhAlvn3Bk9MvnhUAGFMt2?= =?utf-8?q?fVXLl4IP1CARe070EvHzqFUhl0BRvLS8dnn0daAKqJvxVGP0e4Jn0G8YVjTEwis8b?= =?utf-8?q?1qV6pYiC0RJgOVfcLhjQLSoEK2qYrDEx8hHGyv5iZ4yJEdUwKYa3kNTmKY63Z70I7?= =?utf-8?q?r0WAsyFAEPWK2t5xP/Yi/7l0nDp/Yomh+rSCBO8bgc0DrZqlcKojLTJ3GD+opamGy?= =?utf-8?q?3aV7OXwjHRY4K0yRn2/ITSXLcjXkPgnCbOlOw65QBlbAw9g1yLO5GVb2/iyCPGus5?= =?utf-8?q?8LydYkvPTYju+QvmrlfsOylXVnOYY4o79e7FYkYAl+RzdyCRJwh2fAwzwV48XHoLK?= =?utf-8?q?pDYVCZwfwXE+IZTr2yu8/DcSn7OBhWWhIhCel+pJLhDI12yfeIGCPSvvTdJI0Wope?= =?utf-8?q?0p6InluCxcoI783/uhNUo7/oez1ro7LTHEDPYWu8f1jOl2iM1hnstiWlPb7wjqX5o?= =?utf-8?q?0NpNQ4cYw2IGyK8XQgQMI3hOieUmkcNHwfSn/qSpUb20M399OqNhYGST79HvTdhzX?= =?utf-8?q?rrVkf6WbOK2M8qj1iSdCCp7NiGXYn/X8rLr9fv+X3JrNpZ29QzQy49ikf02OOrBIL?= =?utf-8?q?dfXHm0W82Bj0On9fI9hZWDAU0i9DxXu5i8C5bV5Qy/ddve4+XidGbHH6OoP2r/JT9?= =?utf-8?q?vwfzF4ZKtyZxdhOFeuA129fr83cMKIFIxmlZLYAWdpy+KNrEtpwdcimoK1++TyUuy?= =?utf-8?q?6O7nfhhFOM2mY2THv5MNFkHYep6++Raq19HoAQ0t06Mzaey8Eg8EP05ukYR6k4viD?= =?utf-8?q?tNmeP5XxJTr+rj1raL8aERMR3pwCeigI1uwpbsJxeVjtnL0grf8GzOQi6Yo4KSWzs?= =?utf-8?q?KSpGHruA5o4p7mt4E/gUZowkSIwok3TCfcvz/aUxRVM040mrmKEYJd0ZQ5u+Zyz1I?= =?utf-8?q?jqIf3WWdTwWzb1GwppV9S0LYGA9UJ5/j/TYjNE9k+Cf68v+5TA6dXtgwQFkpCqeI7?= =?utf-8?q?/i+qKRaoHdCWr6UfDI30Tm+kw3ddP5MGRUn5CsESuIC1W3foXjBmBmSTmvnRqRY1r?= =?utf-8?q?+FX0w/GRsXv0sEE/jIXhd/8j8YQzjHJojYnWky8UlAIE19EVvEa7qB4tyva9oBvyt?= =?utf-8?q?c/CwL2fNxbG1Oxmrcz7uy+vFe1xKIIZUwCW9QZ5UC0Od4sd6CHFN/rQELkF9OLFDR?= =?utf-8?q?dnaBZliAVNQsSzj74Ym9Er2lKHy35Se7X37YFCDV26zhg3zSOGkHWO8Lrsney70rN?= =?utf-8?q?mYR/dUiJInMkHbFOLCb/SESnehNHo80tQ=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(1800799024)(366016)(7416014)(376014)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Cj9X+jX0aoDxmLQ2P7Ws42e2ovv/?= =?utf-8?q?biIpLBCreATsflT9vt+AEbUNuYfOmrN50BQN+kGVUNKOFdtFzuQmTs3NG/E1cLLGC?= =?utf-8?q?NvqF2RB9gt3bFQ7qpKdK4nWdHlXTqCyxoHMEX2V9O/NXqwtsScKTApuKR5QIAW0Uy?= =?utf-8?q?t6JxkoIdKudLHJuCi9OoovBSmE6+EUbEk246ZpMeRqQQ+Zp7oh6HYNMnDlNTJDLT6?= =?utf-8?q?YMHLjMiVEN+Y7Ls6DbCgW31fkv0CHSqUrrrOSSki4izcAUSFhe89x3YBcBtBYmN9B?= =?utf-8?q?JQq/4TMLsw914Kjs5hTnxilTNZEbIETdV2fyXHCWzTNDd6+W6O0m1u+SSTHfs4w5A?= =?utf-8?q?gYBTR2to8WCDt6rpOTUUjqZ3rv7qU85DGsJ4MpLz9BuSs5G4xckxuEcNB4gKElppm?= =?utf-8?q?a70jk/dgefPTqZTP6P1ZTlnhuOCyuCV6B/AmsTi0nGaDcKs+z/ircNR52oQDL2Txr?= =?utf-8?q?ODjQdTwamscMV/HvBhwRILAIuA0Uth47jDTYJIRtNcvsL4gzIzQ0SJn7MCXripRtb?= =?utf-8?q?bVul0dUOS/mmpQKRzqGYLM3yhuTPDzK181nkX0Rey9rBrCr49Q9PDcfFnCEDfNvU+?= =?utf-8?q?2EWgvK9vsfrGohWzCo/qXYm0W0o1hvQd7fQHqzhJu77/3X86qgtqLKX96RYZdSWzm?= =?utf-8?q?rvZn4TBskRo5IYLW8/RDtceqQRN4vlUcjlCfcZ7X5YpDXq3scXsP1KdWcLtZK9xUM?= =?utf-8?q?90N6JWJsjV049nGfSb6zRFM0Cxi9O0K/ldLzX3nfffG8+ueY16nHfWFTuTHbw6+D6?= =?utf-8?q?Hbx0xSdjMC1cIq+gYuWcPPsGeNpF5LtU58mPZW9WSX1lIdGhwmIQMQ3O5/kWfMfsv?= =?utf-8?q?5WKGUPhGDKCFTfnF1+cPsiY11/dIYLOA1N9bqkae3LHhvdQq2Y4KH4t8gq3yNkL3u?= =?utf-8?q?1AGpsPuhIsmaV2GXi7mK/gtGltVNTP/JfqW+iXaPtQqjlaccwGUInpSlznihPSSg3?= =?utf-8?q?3p6MLUGDPj2CGU2d9AkDBK0joPvrcF9bhOHJrIutgYBt7a8agpk1vRhtl7IkNk02s?= =?utf-8?q?vuQkpwciVkHhmgORN/IzZ9thejcEcnN3YqFNPidy4PntzheIh/L1w395lmEBJjOYy?= =?utf-8?q?4D6881CL6xozcsTK8HkcYPaob3yE1wXLYJXU4fn3Q2T7MRv7IzSV34jFNlRB+PC0X?= =?utf-8?q?K3AVwsJCERMRdOrA6Ha0ySE3ISjgAJACfQ8IsuqEfcgvbkllVzmicPc8HUs6otgaZ?= =?utf-8?q?w+xXf00m15z0+cAxlE1fXlMUlEbOHgPakMfr7f1ykUtiqCb0o7QcX8pjC8OEzatbf?= =?utf-8?q?+1US3xrocwZ+pQ3yNyXMIejS7pUNgeok4SxXR4fzZ3VXc7MA+OHsAZwKYx8ahObpY?= =?utf-8?q?30Nj5WdkLeKeVXYG1MWhIKLTOSoZ7dcrP4L8DW+19WZObUraFBY/67BSoZQrxEX/W?= =?utf-8?q?pmrC5l9ONwHUMj8U9FoF8lEfK4zflol8JAgHd6h99m/0lfcz/k1NEZaQyU/KSxUnY?= =?utf-8?q?S7pFnuL1y/VwiXsx7IGFppbgIiJ2K0fKfwFc9jjzA5GCqTYUUcpGpYQM=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9a65c832-b880-419d-fb0b-08dd73ab4384 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2025 19:02:36.6961 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VuNNpvLlDtUgTruyxbmB5hZlvH1vM5KhQO8tDn/oR7l8L1sq8m1s3dE3G6SHsxwSqWK5IxS9tYGVgUZ2WUuFQA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6957 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250404_120239_241331_4C2B9252 X-CRM114-Status: GOOD ( 17.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add three registers: doorbell_bar, doorbell_addr, and doorbell_data. Use pci_epf_alloc_doorbell() to allocate a doorbell address space. Enable the Root Complex (RC) side driver to trigger pci-epc-test's doorbell callback handler by writing doorbell_data to the mapped doorbell_bar's address space. Set STATUS_DOORBELL_SUCCESS in the doorbell callback to indicate completion. Avoid breaking compatibility between host and endpoint, add new command COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. Host side need send COMMAND_ENABLE_DOORBELL to map one bar's inbound address to MSI space. the command COMMAND_DISABLE_DOORBELL to recovery original inbound address mapping. Host side new driver Host side old driver EP: new driver S F EP: old driver F F S: If EP side support MSI, 'pci_endpoint_test -f pcie_ep_doorbell' return success. If EP side doesn't support MSI, the same to 'F'. F: 'pci_endpoint_test -f pcie_ep_doorbell' return failure, other case as usual. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- change from v15 to v16 - use le32 for doorbell_* register and use cpu_to_le32() and le32_to_cpu() when use it. change from v14 to v15 - none Change from v9 to v14 - update commit message by use pci_endpoint_test -f pcie_ep_doorbell Change from v8 to v9 - move pci_epf_alloc_doorbell() into pci_epf_{enable/disable}_doorbell(). - remove doorbell_done in commit message. - rename pci_epf_{enable/disable}_doorbell() to pci_epf_test_{enable/disable}_doorbell() to align corrent code style. Change from v7 to v8 - rename to pci_epf_align_inbound_addr_lo_hi() Change from v6 to v7 - use help function pci_epf_align_addr_lo_hi() Change from v5 to v6 - rename doorbell_addr to doorbell_offset Chagne from v4 to v5 - Add doorbell free at unbind function. - Move msi irq handler to here to more complex user case, such as differece doorbell can use difference handler function. - Add Niklas's code to handle fixed bar's case. If need add your signed-off tag or co-developer tag, please let me know. change from v3 to v4 - remove revid requirement - Add command COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. - call pci_epc_set_bar() to map inbound address to MSI space only at COMMAND_ENABLE_DOORBELL. --- drivers/pci/endpoint/functions/pci-epf-test.c | 142 ++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 50eb4106369f4..b9cb1ab218f2b 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -11,12 +11,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include #define IRQ_TYPE_INTX 0 @@ -29,6 +31,8 @@ #define COMMAND_READ BIT(3) #define COMMAND_WRITE BIT(4) #define COMMAND_COPY BIT(5) +#define COMMAND_ENABLE_DOORBELL BIT(6) +#define COMMAND_DISABLE_DOORBELL BIT(7) #define STATUS_READ_SUCCESS BIT(0) #define STATUS_READ_FAIL BIT(1) @@ -39,6 +43,11 @@ #define STATUS_IRQ_RAISED BIT(6) #define STATUS_SRC_ADDR_INVALID BIT(7) #define STATUS_DST_ADDR_INVALID BIT(8) +#define STATUS_DOORBELL_SUCCESS BIT(9) +#define STATUS_DOORBELL_ENABLE_SUCCESS BIT(10) +#define STATUS_DOORBELL_ENABLE_FAIL BIT(11) +#define STATUS_DOORBELL_DISABLE_SUCCESS BIT(12) +#define STATUS_DOORBELL_DISABLE_FAIL BIT(13) #define FLAG_USE_DMA BIT(0) @@ -66,6 +75,7 @@ struct pci_epf_test { bool dma_supported; bool dma_private; const struct pci_epc_features *epc_features; + struct pci_epf_bar db_bar; }; struct pci_epf_test_reg { @@ -80,6 +90,9 @@ struct pci_epf_test_reg { __le32 irq_number; __le32 flags; __le32 caps; + __le32 doorbell_bar; + __le32 doorbell_offset; + __le32 doorbell_data; } __packed; static struct pci_epf_header test_header = { @@ -667,6 +680,126 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, } } +static irqreturn_t pci_epf_test_doorbell_handler(int irq, void *data) +{ + struct pci_epf_test *epf_test = data; + enum pci_barno test_reg_bar = epf_test->test_reg_bar; + struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + u32 status = le32_to_cpu(reg->status); + + status |= STATUS_DOORBELL_SUCCESS; + reg->status = cpu_to_le32(status); + pci_epf_test_raise_irq(epf_test, reg); + + return IRQ_HANDLED; +} + +static void pci_epf_test_doorbell_cleanup(struct pci_epf_test *epf_test) +{ + struct pci_epf_test_reg *reg = epf_test->reg[epf_test->test_reg_bar]; + struct pci_epf *epf = epf_test->epf; + + if (le32_to_cpu(reg->doorbell_bar) > 0) { + free_irq(epf->db_msg[0].virq, epf_test); + reg->doorbell_bar = cpu_to_le32(NO_BAR); + } + + if (epf->db_msg) + pci_epf_free_doorbell(epf); +} + +static void pci_epf_test_enable_doorbell(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) +{ + u32 status = le32_to_cpu(reg->status); + struct pci_epf *epf = epf_test->epf; + struct pci_epc *epc = epf->epc; + struct msi_msg *msg; + enum pci_barno bar; + size_t offset; + int ret; + + ret = pci_epf_alloc_doorbell(epf, 1); + if (ret) { + status |= STATUS_DOORBELL_ENABLE_FAIL; + goto set_status; + } + + msg = &epf->db_msg[0].msg; + bar = pci_epc_get_next_free_bar(epf_test->epc_features, epf_test->test_reg_bar + 1); + if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) { + status |= STATUS_DOORBELL_ENABLE_FAIL; + goto set_status; + } + + ret = request_irq(epf->db_msg[0].virq, pci_epf_test_doorbell_handler, 0, + "pci-test-doorbell", epf_test); + if (ret) { + dev_err(&epf->dev, + "Failed to request irq %d, doorbell feature is not supported\n", + epf->db_msg[0].virq); + status |= STATUS_DOORBELL_ENABLE_FAIL; + pci_epf_test_doorbell_cleanup(epf_test); + goto set_status; + } + + reg->doorbell_data = cpu_to_le32(msg->data); + reg->doorbell_bar = cpu_to_le32(bar); + + msg = &epf->db_msg[0].msg; + ret = pci_epf_align_inbound_addr(epf, bar, ((u64)msg->address_hi << 32) | msg->address_lo, + &epf_test->db_bar.phys_addr, &offset); + + if (ret) { + status |= STATUS_DOORBELL_ENABLE_FAIL; + pci_epf_test_doorbell_cleanup(epf_test); + goto set_status; + } + + reg->doorbell_offset = cpu_to_le32(offset); + + epf_test->db_bar.barno = bar; + epf_test->db_bar.size = epf->bar[bar].size; + epf_test->db_bar.flags = epf->bar[bar].flags; + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf_test->db_bar); + if (ret) { + status |= STATUS_DOORBELL_ENABLE_FAIL; + pci_epf_test_doorbell_cleanup(epf_test); + } else { + status |= STATUS_DOORBELL_ENABLE_SUCCESS; + } + +set_status: + reg->status = cpu_to_le32(status); +} + +static void pci_epf_test_disable_doorbell(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) +{ + enum pci_barno bar = le32_to_cpu(reg->doorbell_bar); + u32 status = le32_to_cpu(reg->status); + struct pci_epf *epf = epf_test->epf; + struct pci_epc *epc = epf->epc; + int ret; + + if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) { + status |= STATUS_DOORBELL_DISABLE_FAIL; + goto set_status; + } + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf->bar[bar]); + if (ret) + status |= STATUS_DOORBELL_DISABLE_FAIL; + else + status |= STATUS_DOORBELL_DISABLE_SUCCESS; + + pci_epf_test_doorbell_cleanup(epf_test); + +set_status: + reg->status = cpu_to_le32(status); +} + static void pci_epf_test_cmd_handler(struct work_struct *work) { u32 command; @@ -714,6 +847,14 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) pci_epf_test_copy(epf_test, reg); pci_epf_test_raise_irq(epf_test, reg); break; + case COMMAND_ENABLE_DOORBELL: + pci_epf_test_enable_doorbell(epf_test, reg); + pci_epf_test_raise_irq(epf_test, reg); + break; + case COMMAND_DISABLE_DOORBELL: + pci_epf_test_disable_doorbell(epf_test, reg); + pci_epf_test_raise_irq(epf_test, reg); + break; default: dev_err(dev, "Invalid command 0x%x\n", command); break; @@ -987,6 +1128,7 @@ static void pci_epf_test_unbind(struct pci_epf *epf) pci_epf_test_clean_dma_chan(epf_test); pci_epf_test_clear_bar(epf); } + pci_epf_test_doorbell_cleanup(epf_test); pci_epf_test_free_space(epf); }