From patchwork Fri Nov 8 19:43:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13868878 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2074.outbound.protection.outlook.com [40.107.21.74]) (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 6BFA51EBA0C for ; Fri, 8 Nov 2024 19:44:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731095042; cv=fail; b=pl876ZpNp2jPRBCI2Wml6qmPtFOFAr7hLaoRH4z7iyFCtiy94f3ze8EHF4rvkNYlmhfOMA7DMTsQt5EQRqusQlkEjetiTS4aR6vgfdnLaYZUNe74CcUJQzYsD2732kCgcRQ16EzjWDDTGwVXQgIbxhKl9J8FFIvhVwtOcZi5Hqo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731095042; c=relaxed/simple; bh=pYt5jLNYZmjwZJXEi4DDlIg0upH0rCO+gYIhEutBvCg=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=PutdOO5Ko90RfQVGfbwlv9NtyHQgVoLy4Y3qH04viHx2HbgQhIl9nkug5dVxdr+8YHM+u7vjN1jhpNjnWaH95n1J5B9g7AiueuHMrBp9FosL0+WSTsj5SK1+I3hsPTLrS+U4uwYQnH7jUiYisvaxRlNv6nIdF3hV41SdfuL/wM4= 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=KWvZfuxN; arc=fail smtp.client-ip=40.107.21.74 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="KWvZfuxN" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KjYqbyYOQxP8U1vnHqaNvIsEgPGq19dNe/UBHmAL4otL8VPtMvQ5LI3p8bMpIo1yn5M34yRvcxEd/mGeNOek0BmVAClK960hnTHbHv9hwDRBzKYJtcnnohCER8wf1/A/uhqCVu/S5HNBRbRucI2cf9RlJCpUBL4x2GkQXKvYq2UGFZpUaF6MCiuY7mrmNwTq1xpQlE4iprDda43n8UESuXf7Id8c6MxIgwwdxjP2C7RdW0Uze3BKrIlEyLNdvzy4PSLiE9d/PPTlRxCzZQKGJPnVQOwAqdBA3BSnZiGDrDKBihOlKc0fcVcVLQpfmwAyS0QGAGAcrG5R1iLad5OKNw== 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=HDKjFU4cXoZFEgIfqxFbVQhZAT91I1Dpe/rORgznK00=; b=TT6FBwKQL4CZwiKImXAClFADjqiC9AcZkk3DOqIA5Z+nVTsgqGFibpvSv9kfJmfDpblcWCcRqAFGcJflbf22GpmhSdEu4HZ9HWq/LRmfbHRA6xh7O4xcRFJHyGgddBbdhaHIczg0gkr92dhyHla+JNRA7vX8O2IqWSNkhw36vabSX+QtRKBWdKRY31kU8n//Yl/5FHPrM0ehDHzjV1DtO/u01krg1WHJrv7H4l4ry5/0XdBASH8q1ylW2iko3MkuL/BaycoO7X0mgpgLZNta89957AyQRhKWfCTvNxvn1ogOstBBjEZ0u5u0fORvzAnid7ioIItP1+9zU7WlpEFL6Q== 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=HDKjFU4cXoZFEgIfqxFbVQhZAT91I1Dpe/rORgznK00=; b=KWvZfuxNQ/eIBUnqYVS8crOC1r0R/KQpk+59Y+xCwSspAoYBd9xI/bVMk5/THbEhpR/DeRHnkrAnIadcSJ+fCtzHm/y1mGRUKOihWZcGmo14sc58uBfgBa7jxLD+dg+QoP3/McBPPKXsZj117jL8RM30jR98mSy5z+MnlC97ZT6cKo/YDKsjaqkKz0vPZ3yJMVnbPPi6QHtgW1bfMYzgl3jgcBQB176BWWhBU4miuUOQiExCLC1M/OmdGU3rFX7QZ/OlbTX2t96ZY+ZBOXLVEFrLAy/Zo3s9THzDS89lAtdkrlybIMmKs67XiQnCOieQkr1+U7LQvMA1hfvZng34tg== 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 PAXPR04MB8669.eurprd04.prod.outlook.com (2603:10a6:102:21c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.21; Fri, 8 Nov 2024 19:43:57 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8137.021; Fri, 8 Nov 2024 19:43:57 +0000 From: Frank Li Date: Fri, 08 Nov 2024 14:43:30 -0500 Subject: [PATCH v5 3/5] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20241108-ep-msi-v5-3-a14951c0d007@nxp.com> References: <20241108-ep-msi-v5-0-a14951c0d007@nxp.com> In-Reply-To: <20241108-ep-msi-v5-0-a14951c0d007@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 Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1731095022; l=7940; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=pYt5jLNYZmjwZJXEi4DDlIg0upH0rCO+gYIhEutBvCg=; b=+Oon8qydEw9hdV8US6oyNRAUhHdoe/xxsI0lkNdnDSUxaqIUS0awY3qKYNCFnWbbq9X7xDxfd 0ybJMRHNRd7DxpYoEMsSEbgwq4iwrj8WN24HlDKZCRAkFnKXEqMPBeU X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY1P220CA0026.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:5c3::17) 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_|PAXPR04MB8669:EE_ X-MS-Office365-Filtering-Correlation-Id: 3abdebfc-6d88-4adf-764a-08dd002daf3d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|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?= =?utf-8?q?DrYoD51TgOfd8uCUBTDvs4PcHxO0BEGYpw24QrXDb+el8AKn623ItDrZ86Gfgea8b?= =?utf-8?q?PspE13vWYeOXeKFlkij0c3IbyR3YqkwQ3WHHwrQhEXs7bSccieNZASJMPSZoh4vUU?= =?utf-8?q?JfoLxv41XFNSpFlpT/Eo9CalbAn/JGJmOSvRVYVUxZqUFs9xypGhZ1bPKdrzn48xS?= =?utf-8?q?G5q2di6sXJL7mHfh2H4eLK+4n12xlIhT10/JNJ14u5wtdIfxjeQGIsTJkPtiA9wR1?= =?utf-8?q?TTimhg/+kkZ30Kjwn0A1e8lhQiGox0+sijAX5bT9nWNKqzEXqCBzKTG2XL/M+3RWu?= =?utf-8?q?E01pUppTFQld9OR82w4qNcNJNHmZC6Oyg1wAfwd3m353ynIbAYpIhtx7j9utQpWjF?= =?utf-8?q?TAcV3ZQdTXejqSrtOyUoxLYV3hGn9LjlfokwsTgdj8MQ94hRimKOUxUXLza6f3Uis?= =?utf-8?q?U/+uIcV6YEoOF05IHRbPogKiFy5RekzOKn1271oylF8R7xpBBhW2VhYo=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)(1800799024)(366016)(376014)(52116014)(7416014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?cBN/L/PYoCIWZ/P6VP+/tsWVWKgN?= =?utf-8?q?MB9a4CAO+jDDChWJL3iXk6ftMvGy5hSjvl5xrL5mJz5jwLe1jsMRIFyMT72Gn9vbQ?= =?utf-8?q?QuqMjY20yvQRhuVY0PlMqCvCw8smJvI4wmovFattbejROBIQFOu4qd0jdhzm0Neox?= =?utf-8?q?EETa+JaBVsniaiPPKYEpvEBOWmsxii15kb4i1pHRs7TdE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7hL4TSQi1nGVPrQnLcTy3W8?= =?utf-8?q?JdYHENBeJyvZL4D1bcRW/JN2EK6HvmhURL0fxUb0oiJMt0DdLEqFxW2LbGbfSlmVu?= =?utf-8?q?GeQ0uJqOvQXkJncBbW8C361cwg314pmuseyTPFAp3qJFzqG/WGO29dNaTkuyfn6ex?= =?utf-8?q?nJSnEnz7xvcFRzMmf7x0rcjv5FYFQIT6n5gi4v6MljyHiMnWhfA/4fHD9/fk2smy6?= =?utf-8?q?jbPEBzsW70RvDTyN9ndGzW1mqa8wyzhjM8qSup+S2gSjGBDfus8IWQAsIh/26Hud7?= =?utf-8?q?AwCsWnFCV2cY392T8Oie1CU3LK7Rtyese/SZk1LTWlRCea+KAdC6bZ4oCdLQb7bP9?= =?utf-8?q?tSH6htOCbSbu3rLttXS/k4Ha95Zm21Un5QODAMZXkdeTHgGYPjixty+K2tyeTVJbw?= =?utf-8?q?qcSlOyDhiXnqm+Es2kRuE+3dDXOpkHvOQ4RWU7arwSgpj5LuA+UlOiemBF+dp4CRY?= =?utf-8?q?6wW6+NaQEdC+?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3abdebfc-6d88-4adf-764a-08dd002daf3d X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2024 19:43:57.0759 (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: x3yULh7EzlssD2/epa1bIeceDlBqeRRs5umjC4szxJqa3XAUh8bmP87i9d5bQ5H+6cVbxNiK8aJKIabVqxAXRA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8669 Add three registers: doorbell_bar, doorbell_addr, and doorbell_data, along with doorbell_done. 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 doorbell_done in the doorbell callback to indicate completion. To avoid broken compatibility, 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. Signed-off-by: Frank Li --- 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 | 129 ++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 7c2ed6eae53ad..52e36c7c04c85 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_addr; + u32 doorbell_data; } __packed; static struct pci_epf_header test_header = { @@ -630,6 +642,63 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, } } +static void pci_epf_enable_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; + struct pci_epf_bar db_bar; + struct msi_msg *msg; + u64 doorbell_addr; + u32 align; + int ret; + + align = epf_test->epc_features->align; + align = align ? align : 128; + + if (epf_test->epc_features->bar[bar].type == BAR_FIXED) + align = max(epf_test->epc_features->bar[bar].fixed_size, align); + + if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + msg = &epf->db_msg[0].msg; + doorbell_addr = msg->address_hi; + doorbell_addr <<= 32; + doorbell_addr |= msg->address_lo; + + db_bar.phys_addr = round_down(doorbell_addr, align); + db_bar.barno = bar; + db_bar.size = epf->bar[bar].size; + db_bar.flags = epf->bar[bar].flags; + db_bar.addr = NULL; + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &db_bar); + if (!ret) + reg->status |= STATUS_DOORBELL_ENABLE_SUCCESS; +} + +static void pci_epf_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; +} + static void pci_epf_test_cmd_handler(struct work_struct *work) { u32 command; @@ -676,6 +745,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_enable_doorbell(epf_test, reg); + pci_epf_test_raise_irq(epf_test, reg); + break; + case COMMAND_DISABLE_DOORBELL: + pci_epf_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; @@ -810,6 +887,18 @@ static int pci_epf_test_link_down(struct pci_epf *epf) return 0; } +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 const struct pci_epc_event_ops pci_epf_test_event_ops = { .epc_init = pci_epf_test_epc_init, .epc_deinit = pci_epf_test_epc_deinit, @@ -909,12 +998,46 @@ static int pci_epf_test_bind(struct pci_epf *epf) if (ret) return ret; + ret = pci_epf_alloc_doorbell(epf, 1); + if (!ret) { + struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + struct msi_msg *msg = &epf->db_msg[0].msg; + u32 align = epc_features->align; + u64 doorbell_addr; + enum pci_barno bar; + + bar = pci_epc_get_next_free_bar(epc_features, test_reg_bar + 1); + + 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); + return 0; + } + + align = align ? align : 128; + + if (epf_test->epc_features->bar[bar].type == BAR_FIXED) + align = max(epf_test->epc_features->bar[bar].fixed_size, align); + + doorbell_addr = msg->address_hi; + doorbell_addr <<= 32; + doorbell_addr |= msg->address_lo; + + reg->doorbell_addr = doorbell_addr & (align - 1); + reg->doorbell_data = msg->data; + reg->doorbell_bar = bar; + } + return 0; } static void pci_epf_test_unbind(struct pci_epf *epf) { struct pci_epf_test *epf_test = epf_get_drvdata(epf); + struct pci_epf_test_reg *reg = epf_test->reg[epf_test->test_reg_bar]; struct pci_epc *epc = epf->epc; cancel_delayed_work(&epf_test->cmd_handler); @@ -922,6 +1045,12 @@ static void pci_epf_test_unbind(struct pci_epf *epf) pci_epf_test_clean_dma_chan(epf_test); pci_epf_test_clear_bar(epf); } + + if (reg->doorbell_bar > 0) { + free_irq(epf->db_msg[0].virq, epf_test); + pci_epf_free_doorbell(epf); + } + pci_epf_test_free_space(epf); }