From patchwork Wed Dec 4 23:25:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13894450 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2055.outbound.protection.outlook.com [40.107.241.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3518320D4FD for ; Wed, 4 Dec 2024 23:26:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.241.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733354801; cv=fail; b=g+/LHDY3NTjOT7v2rfen+h2wPoLKwKjMIsUbuuBTsph7IzRHyjhJr1qd52Sc6ip9YNy+y2PQKM9KHtyz7iXN6kshfSwHgyKRa7Z+3+Ezk+jKljtNyUYhlajq2HR8Rua3He+ktIt3Hxzx9agBwniAboTzliLek6nWSf16awOCL58= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733354801; c=relaxed/simple; bh=jquS+fkORuaDI0V6B3sVnjDD5bRTRvh+jlQ8JabJKoI=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=ljcVR+OaxBr1JM2SvmAe0xM5NuCEJ4ssDRkmdruvd9Vr3XS55KI0Fmbj1F7C01cCXLUigB7V5ndCU4rZ3/qVZO/oPeCeMBkycGG2487ktR0hCOvicmCloXHFJLg3ZhNlgy+DCgJHZ5k4za/iawruBDj6Q8aFY00o/CHywD8t/q4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=Rk6XlC57; arc=fail smtp.client-ip=40.107.241.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="Rk6XlC57" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KFGfQgJnryOxM2LL8CelRq0izRvc4xcjS/jKuimam295rxQkryjEGN6OK3USkLGUiJ1UM2FzGfqtLOQBTel7X8XHmwiu5toc6hCgAtgF8mTHZ5efH8lG3eOhKyEv38B/V1Q1H2LYNE2//YhzhlnoIhdR2m84cHTFPINsNgOsjwJkoJJ1RlvnfeDN2bKrRjmYzyMn54eKQXPtKTlGYfBDYlQvybi5y7q6pGX7eV7VIWj6Ilf/c8WloetMax22IqIB6xeweSo/u++yxcf12rgzpYqdj18BqoHltLrdfu+5St/umQjxWiGNaNIcvuqOvjq/TQLXffSvHKKVfZka50I3pw== 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=3TmAzFSRs/v5m1fkHfAiLGwO4KW6dmerf3DMnppfYHQ=; b=hQX1eAFfe5AE7M4Ri9TU8rGIKEc0Xuco/7V1dFWepIgqRZxzu+qHXseg83iaowpECPwmpqcdueBl2DivOb5dRsUA5ONlR4AW7ozLyM+r7j3u4wMMIuXObI8DeYwbALs50Xo8iyCwyrnPB1h4bUOqgVbalsZsPo/rAdysUOC2hu7fupebvkhAGMR5HTp87B3ska3aNIVUBlarZqr2W0KzDfsM1ZfV70HGzetLoYujtxtkrq28paZwSsllzQsmuH+XEylKLtxm2w9dXKTLr9zAJgF9bOogmmW/ZiUQuMDvQur44scfg8ES52iqllkOD+7Sod8tN+fthwoIuJSO+pbVSg== 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=3TmAzFSRs/v5m1fkHfAiLGwO4KW6dmerf3DMnppfYHQ=; b=Rk6XlC57E+brjVP+cCp1xCjY3QuUTLKFnRwaJzl9y7sj0ScZ97wFsmbFin3jmsqOHjUKK6Fq9U+Zid+sss+p8d56ycdK/RwU5y7lQs9N3cnjPl+btULqQ5E6PQngwvDmegZYWuM6fMeUk0dDVPTTMD48hO5ZWBqqU5poffahyIuRSC0+CKA4smL8sUA/DTb4H4yu34fXK9uLDretu77Oxh2Zt4RJDFyxQKAnyi2JpKTRruzZ38XcqhT+m1H4H5B6V8Vmze59GX7BvwGpphXI3Du/pW5Iw+OhPB+XbIem7VBgo1puobW54gdbkkMBep+IUOVNYhuaPsoVei+BvlK4Iw== 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 DU4PR04MB11006.eurprd04.prod.outlook.com (2603:10a6:10:58a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Wed, 4 Dec 2024 23:26: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%5]) with mapi id 15.20.8230.010; Wed, 4 Dec 2024 23:26:36 +0000 From: Frank Li Date: Wed, 04 Dec 2024 18:25:55 -0500 Subject: [PATCH v10 5/7] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20241204-ep-msi-v10-5-87c378dbcd6d@nxp.com> References: <20241204-ep-msi-v10-0-87c378dbcd6d@nxp.com> In-Reply-To: <20241204-ep-msi-v10-0-87c378dbcd6d@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman , "Rafael J. Wysocki" , Thomas Gleixner , Anup Patel , Marc Zyngier Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, jdmason@kudzu.us, linux-arm-kernel@lists.infradead.org, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1733354769; l=7892; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=jquS+fkORuaDI0V6B3sVnjDD5bRTRvh+jlQ8JabJKoI=; b=1CNbkwrByCgtoyf57mJ/pWLaEDnijc0Yl8FZCRRvijPzsHsYRcSNpV2xQIQRag+vTzZQDs/PW jc65noXZrOZBwWUMAR451WurunySukstJJgyqke27wpYosa1xRlruJU X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR05CA0031.namprd05.prod.outlook.com (2603:10b6:a03:33f::6) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|DU4PR04MB11006:EE_ X-MS-Office365-Filtering-Correlation-Id: 78dc9732-163f-40c8-6068-08dd14bb1881 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|52116014|376014|7416014|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?PGDEB5BRVVtdeTDv5B1B7ixdf21aO1t?= =?utf-8?q?B6x2sDLh7zsvslaIQaB5l+9OrUu4Fv80rt9gOKsrs//+KMvCQ31Ual44Lt8mFNnPz?= =?utf-8?q?LKAruQZumAYCi+HfYjC8hd3P/Emm+CUFMYfrgACEAsOVmXrE0K5LdKgvYc0Zeln9f?= =?utf-8?q?cSyuKECAmpQ2FF/BwJvnsnoI2qzPZ5MuUn9+Pz6wDgh45krpYW0PAZUi4HL8tC+Gd?= =?utf-8?q?qjImCEVkw6ltfrRREMqCviyTAHIauEieHa4RkESp7UE1OGyECsyvZg85aEA+LpL6D?= =?utf-8?q?d5zREdmth4HUy6QputG2DDdLhGxkA+fzAKctYPo5cKmEPoY2QZdmTgPBnFu1RNXeP?= =?utf-8?q?SMnFDjN6mzg8JiYZCUTzRblQ/tuynvfPZwH4CpQSjmCsxEz7/2jBpv9eFr+oJkDaz?= =?utf-8?q?rzqO163qC68DLUKgO5AWZ4rLjTzTEhj2B53uvS/7w44uYGhx47PTkdZEu7yBFrdBW?= =?utf-8?q?jkGNbCAtQagjZgqnDu0EFOGILisen/FXzK5F6ehbgfh5eDmkhSRCA3X5ER0gV4pqm?= =?utf-8?q?e8p6X1kgIAeW2qtqCOdwR1SoN9+f3hhbdzyDItHHnXeH1aNOX2hzimkx7SShMJgqi?= =?utf-8?q?acBdvdOJCgQGZ57rOAoDiWCEhpRPj+3Tx6g6c2p2rnw5ZPkL7ZtLNovuuCTNJiAcU?= =?utf-8?q?L0NvKKdShPxVfJMnzl7Gq9gWCsLbvhOVxuVx/YQdjGdf8TOB4U+UKfr7phWogTbth?= =?utf-8?q?rl27907GD95Jjw8rn77lYS2YKTD/U07kidAsW1b/AW2ppTK8aHW9ep8vDtp++1b3S?= =?utf-8?q?ywli5p3Fmqf+ccPAW78UdaUPzyhwiSHIhbOyggOZDo32FWZnI7U8yG2iYRzNARw5G?= =?utf-8?q?KRSoLQDRdRl6N/EVaXZeNmn5LoG3KyvCrBdwEfWFgfY7vGeF8zBgWFa3sMqzNut7G?= =?utf-8?q?wEWhBTsM3/c+mhqMkanXeBALAfmbvQ0is/asptoukLDkXY5GUqqJ51uKn6tzoVQOC?= =?utf-8?q?XJDcWlNr8E4Syemci9Ezj+rXLkPeKaRL8z1VUzdFYXBkJMntMoFxKvTqnIhGXZvbl?= =?utf-8?q?nScRcrPZRXloy2iG9HVsRwA6OrIMrmJ2sjAe6sK+IYmLYY7PQRGeRWb+egPLp3tAC?= =?utf-8?q?oSZLvTn4nKcbRbVU9ydD9cgjuO5mUrUSz33SYhJLkFplR8K49zXbpgtXBjPmuDHc/?= =?utf-8?q?Q3FXtwAm1iorn7TZygWZcl7On4HnGtCsEuH2CvNTYTAGwaGa+4NFiiu2HBj5d2CXV?= =?utf-8?q?rv5yxfPPbv/CMz63nXPfnEePdu0Q/Vwb6pUt4M05Ob/yviyqflVx1xjt+PinS2qWb?= =?utf-8?q?i82yCj4zIre21k9tkrf0Gz+glyneC/dZVQ3pQImPla5h1jIDV4vjb/sJQAcPyV8gl?= =?utf-8?q?UQKv0nijny8yQkcb8KUbyY8JCn2dwSJWNksYcwM6O9KMsekLBzCPikQ=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)(366016)(52116014)(376014)(7416014)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?IJuLWJ+JMpqEsebCXvCymPb8il6q?= =?utf-8?q?c3HOFv84nhuKc0a2WLQ+yvXPOqQbvVZYL7u3DANFhb39/L5hVr8wyc6YwtgLZvxFd?= =?utf-8?q?WZzRfiZgjk29+h2UymFw2JaR63JPUGEj4A+W5qGsfFZX8FVbnN+ftxFOKfjfVyIf/?= =?utf-8?q?fcykUuAI2YAgV6XAEhV8x4AOM5t5uTBwuVeZ7epxHGmG+4/aLasS+HzNR3nk+TK7j?= =?utf-8?q?h0B3nWCkCFnEOeJFYNQBdBSIHCdAOwnSCENAez5RqCkyZ6r91xurIQULXyX1wDpDB?= =?utf-8?q?67wyPKhc3ztk3yLEzTWU5GvOlraJjF69w8wgbkxfSp3nhQQq/vTBiroeHwJsPrtby?= =?utf-8?q?wdItSoJfLVJBxhVlNPhnkplVA538lcEOpviQOAtyB6h9hjbnARjbxqk9WKGhrkyk9?= =?utf-8?q?LvD6zUfC4bBMpzN6fqbddUMyB8xt4Qr5J/qr1WZfWVTESI5XXMoRUZkC8re8FPn1W?= =?utf-8?q?0DD1qSPES2z2SIM1V/qdgwgUS+VnCbgEfdy5bJasqQOcud7x4gMiJPI3XkEhN+Paz?= =?utf-8?q?Ez35NwR3DjCw1h9seDHc2JFVMCu6K3AMwdpR3Fo4z9GOK5mjZbA0iXX3xIEikB/cF?= =?utf-8?q?5kG9g0DlnsR1LuiW0BV9HXULWZvmQAhYSKpFMfggyt/1m3Uet54sUIIcKVcEne0yH?= =?utf-8?q?sCz/tCTxlG8Ja0ZgHJiY3/n1U5A1SvJqhS60qP89mFlfqJIb02WZzVwls0oHmMXqb?= =?utf-8?q?OoDs0o7P5MywoQ2uGxNbE52XGb3gIB+XHZRnpq1L1eC8VhCkgBhLWWIHXwM7ZoRCL?= =?utf-8?q?QPeZYeV3MIQAIIV7As/L7bOg4mcgS0ggSEevoObxyTvTqbTBp1JDFmU8Wm/A2EkY4?= =?utf-8?q?mwCFUQVfdCuxlQKjnXuVHI+Khtqwnfc7zU0KYzOxzBPzc6ZqEvmaEbLohD1vfRrF2?= =?utf-8?q?rziY16khIEayYSzrHnfXpiCMP/XRbsQlSe+nCw4Zjl66L7BhyZluLPfWJmE4xCP8z?= =?utf-8?q?EssY6VkgNnuqYc2sKfOnjaFz+omJpfjE5Z3UIulDAVTt+u8A6DXUk3f4cOleA6ydV?= =?utf-8?q?g2Ql3rMwY22uAWJWiNiTuIdLzB30hOuj9nRENtDLW89poR7O6gFuyrV+oDhD9PhVN?= =?utf-8?q?OWnv0JN1mMe7Yjjp667llgmIFya+QrC0vn8KIQE/HmuKF+Oe70wbzUyF0kJyIMNFB?= =?utf-8?q?BBuJx9EnOVVAPkUhJ/euiPlmj/ht6IH7n26VhbB1YfoNIBRUYhk2FqFfZH4fmteEZ?= =?utf-8?q?NtzMfnIOXPe3sp1u/GNVnygr9iQYJZFtb6aiDUCpb9zfwIfuspuubOLT1MeBA0P2/?= =?utf-8?q?f+KqcHfrkVHdzLGGlU04kamrHdo+eU55Vl5XLifH9LwW1rvahMFvNkHyCkZL3uoHt?= =?utf-8?q?89EmO9iTF6XFmD0yAJGMEJ/aEDMGwJ+PX7zh1mCivq2uaa/9NN1QIM6nA1FFfNZR9?= =?utf-8?q?/068S5Xv+b9Xb2RItjnf4MD58VLhtGwJI8c8gNcV74E5yZIjpSrjqlFAxSyqD2Ude?= =?utf-8?q?pSRX5o7cUUNtqrecypy3CR1YWFHAYmqh1e8AaiJJkZC0DKAZQKSYiVBrhgeR0Op0L?= =?utf-8?q?8gE6pdnZvAEO?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 78dc9732-163f-40c8-6068-08dd14bb1881 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2024 23:26:35.9938 (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: 0g3aA09ic9tLv4Q1SvGJoEb8b8G9SpboSJOfQyM6TRKTsKGt0eFzFkYdwbGKn+bIjPIm4ivRAA1cpOhwtjplUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU4PR04MB11006 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, 'pcitest -B' return success. If EP side doesn't support MSI, the same to 'F'. F: 'pcitest -B' return failure, other case as usual. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- Change from v9 to v10 - none 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 | 132 ++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index ef6677f34116e..a0a0e86a081cb 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) @@ -74,6 +83,9 @@ struct pci_epf_test_reg { u32 irq_type; u32 irq_number; u32 flags; + u32 doorbell_bar; + u32 doorbell_offset; + u32 doorbell_data; } __packed; static struct pci_epf_header test_header = { @@ -642,6 +654,117 @@ 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]; + + reg->status |= STATUS_DOORBELL_SUCCESS; + 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 (reg->doorbell_bar > 0) { + free_irq(epf->db_msg[0].virq, epf_test); + reg->doorbell_bar = 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) +{ + struct pci_epf *epf = epf_test->epf; + struct pci_epf_bar db_bar = {}; + 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) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + 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) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + 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); + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + pci_epf_test_doorbell_cleanup(epf_test); + return; + } + + reg->doorbell_data = msg->data; + reg->doorbell_bar = bar; + + msg = &epf->db_msg[0].msg; + ret = pci_epf_align_inbound_addr(epf, bar, ((u64)msg->address_hi << 32) | msg->address_lo, + &db_bar.phys_addr, &offset); + + if (ret) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + pci_epf_test_doorbell_cleanup(epf_test); + return; + } + + reg->doorbell_offset = offset; + + db_bar.barno = bar; + db_bar.size = epf->bar[bar].size; + db_bar.flags = epf->bar[bar].flags; + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &db_bar); + if (ret) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + pci_epf_test_doorbell_cleanup(epf_test); + } else { + reg->status |= STATUS_DOORBELL_ENABLE_SUCCESS; + } +} + +static void pci_epf_test_disable_doorbell(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) +{ + enum pci_barno bar = reg->doorbell_bar; + 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) { + reg->status |= STATUS_DOORBELL_DISABLE_FAIL; + return; + } + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf->bar[bar]); + if (ret) + reg->status |= STATUS_DOORBELL_DISABLE_FAIL; + else + reg->status |= STATUS_DOORBELL_DISABLE_SUCCESS; + + pci_epf_test_doorbell_cleanup(epf_test); +} + static void pci_epf_test_cmd_handler(struct work_struct *work) { u32 command; @@ -688,6 +811,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; @@ -934,6 +1065,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); }