From nobody Sat Nov 23 05:45:29 2024 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013034.outbound.protection.outlook.com [52.101.67.34]) (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 BB9551B393F; Thu, 14 Nov 2024 22:53:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.34 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731624792; cv=fail; b=pb4pwUn8L4D7UPfdkBCmTpMcW06WxW1+Af3S94TnnCaJJWbgADkfCEqhrR9fmuqouaH8Jb8sO+BGxPK1Vd5KS3yeCC90bDCjc/tsRgkYiitikeTlSZvNSVV4QXMTPnphEH9SEdeudepDS37Nk8Khe1OVZDoHmyftI5mhtaWToFw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731624792; c=relaxed/simple; bh=0yAMagX3u9+aZDCSSioQiAmKlqCp0jSmM1pLy+8moi0=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=V8ENH0Nucmw80LuDyusZ4Y3i6/C9P436769+UpK+c0uCflRM/Oc7ICVThx40R7WcrRgQiYBtymYZRfDajpczSn/F/0XMbjlNu60GmvyEDpogzToF6xqa81ofRJstq6ffNkQB3OB1hmL33ASr1XMzkc6kL5xN+sd2qafVPDJhlJQ= 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=S4Lql5T2; arc=fail smtp.client-ip=52.101.67.34 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="S4Lql5T2" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xjCvIIpSp69BKK0TMNpp/TEsfMteG+XE4TSr9zCZSuI34oT6HtsE9pKcwor3QVtJeCWFOf/EIZXaTI7xftuYRuHJgf3PwUUYqD9lVk0ZwlJ1TkjMApFNl5MZ2T/hwqaqt5XISAzuT8K1enopNz2ZrHhyWHKgSnDNvLSAIGeZPp1OmH6QM/CWJ22vV+MYjXo0d0KDKnqNPKsKQCsCLcL0L6pdhizTOXKEosFLoFwdez2kczAs8dhEGwXehk23Ye2ej9MYtJvWJzGyJw8iUp9B0KgN19myk32nacCtr9BhYfqFBZsDof3mIGW6tUV1OLJHbSLPmUGtya7cA/JPeQO4xQ== 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=S0KC6fMx3yDLGEroWZHuxH6YFJ99NVir6SglA7R8IoU=; b=pniwC+AAvj2EFKtoEHlStDoKk4N0BdzY/51KwROynhNl0JorIghpgUbYfMOh4iSvcbtRDPh+HMQ3mc5viQ3XiwuBw9Vh+pVlVtFkynMPdPrP2XfWBTX6dafaeqXt8LqU3tH5FUzxG2wUDCQd62VhAB1ng2UnGV29CB4jTMxFTuxZrShiTdQKVKUNFhEz/AluWZLurbZEpi17C4F3Ockp4GgdynEwB+bVfffCBgch5iuFQWCTXTw8ZO5ZtHEt2F+UgruVVSaW/ny0+ZCkxey9eXnyTjtoVimk3GeO8zTm+EyEKz6lMC/SnC36uQndeeoaBQhTG9La0tQvjd08FuJS/g== 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=S0KC6fMx3yDLGEroWZHuxH6YFJ99NVir6SglA7R8IoU=; b=S4Lql5T2KaTLOBOuZKrppzQPJnNPqGDLi0c/fUti/oSxh+1yXTZXHwQlwNanUko9Uj2cnG40hALipH82vUSBCS2Ty5tKQqWVOjpc+S2DQM5W/aP+9T9P6VKBzd26vC6xaNSyCeWw8CxFo4Iy6UL4guuF47vd0lmZvM73Hu5qkHhiX8O6gLBN1FRZba/FKw1dSMzpT4eEIp2yPfIK+c0G2CiHzOnTscOWO5m42kW88QXRLWyfzmmEYRaN03+8RIBED7+fmYXKk9h91841b7Ve/TjUQDpmPjpgLsWtehLI/mHx/jNng5xukzZEM6SaYMI/ADwVMBQEib189X1SgqtosQ== 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 DUZPR04MB9967.eurprd04.prod.outlook.com (2603:10a6:10:4dd::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17; Thu, 14 Nov 2024 22:53:07 +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.027; Thu, 14 Nov 2024 22:53:07 +0000 From: Frank Li Date: Thu, 14 Nov 2024 17:52:40 -0500 Subject: [PATCH v7 4/6] PCI: endpoint: pci-epf-test: Add doorbell test support Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-ep-msi-v7-4-d4ac7aafbd2c@nxp.com> References: <20241114-ep-msi-v7-0-d4ac7aafbd2c@nxp.com> In-Reply-To: <20241114-ep-msi-v7-0-d4ac7aafbd2c@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzysztof_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=1731624768; l=7661; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=0yAMagX3u9+aZDCSSioQiAmKlqCp0jSmM1pLy+8moi0=; b=9fgUJt1DvuUMv+mualC4PrkA/qGPlkwbMMF6lQzDwfwBiDhnpYfaQGOTdKPycxxlit8ArsMx9 bDQ+Bcr6jjyCP0lRg/fm5OD4mrSuKQE8yOlYzDPs2S4XVNgFoRKGIj5 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0166.namprd03.prod.outlook.com (2603:10b6:a03:338::21) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|DUZPR04MB9967:EE_ X-MS-Office365-Filtering-Correlation-Id: c25f5d4d-47b6-48b6-72cb-08dd04ff1adc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|7416014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?SFNFc1pHK21RanpuYjhRWlNHT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Ex?= =?utf-8?Q?vZtFMiGTFwkOYjjYokdyiKpSMghnCc2gMLCAg=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)(52116014)(7416014)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SEFrNHp1VzNTdGVRV2tCRmY1YldlNlQzZGFTUnpZRXZZRFo1RTNYYzQ5VkZI?= =?utf-8?B?aUo4MVBNODZVb1FhamNxYWNJemVudDBDVUhzSmhSa2ZaY3pxWUxQbWttVGxr?= =?utf-8?B?WE00eitKM2tYWEQ0dk01Nkl2QUhNSzJZMFFLa1ZDL2gwenJIbHZocWVNR2ZG?= =?utf-8?B?SFpUcWN5OWdocWRUV1NwUUxCUnhOb2VmZFoySUNxckZscXVMdFA5NXVOMjdj?= =?utf-8?B?ZGpQSVRwSUQ3bkRZNHk4NVpDT2lWb3JEYjhONGxDNklCNWRqbWo2c1hlQTdD?= =?utf-8?B?d1RvWnpHMEJTLzN1UjBNZGFuUFhjRllYdHFnb3p5N2dBcy9vakNxVStBeFk5?= =?utf-8?B?NWxOL04zZWgrZVVGdFZVM1JEdTZJdWtoVWROaFIwZ25NMjk5VHFENVpmWSs0?= =?utf-8?B?MVdsYktEZjJXa3RnWTViT00wSnVYdm42TkhQeEozQTJna2FTWTZWdzRDUWxX?= =?utf-8?B?NmxKc3FtWHBWSThUU3EyZC9qV0hjR1pGZFlSNGI2bHRkRHh1WjhXaUM0V3dW?= =?utf-8?B?TmZ0RUpCSFpDYmxuWGx6LzlKZXZvVDErOTJFSW03TXhBN0FPdU1IK0lMSGg2?= =?utf-8?B?SGVnWWpOcHl5QTBTUXo2NlordkV3SGZCTHpKOTBMTjhHajZCaEJ1VFJiVl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RNTVRDNzd4MnN4SE9r?= =?utf-8?B?SDFYc25VbkttOFhqNHZkS0ZoTVkyNEh4dlI0c1ptZTJMNWpRV012VnptdFdI?= =?utf-8?B?N1BKbkcvMG9qb0xMUDljb1E4RUhheE03aVhWbWNMRnY5TnZialIwdVN2akJ6?= =?utf-8?B?bHBWZEpMcmNVb29GS0x1NUhLTGIxZDFqSERyUW9jT3JtTmFwSjF6eHdxTFB1?= =?utf-8?B?enJuYkk1dDRmRlJFTDRPUUdKUmluSm11a2R4MjYzKzkxKzVndzV0TjZaOHll?= =?utf-8?B?ditWQWNEOVptdlhESm44YlhudVhmM0N1OWRISmpVOXFuanBCODZ6T291MUNR?= =?utf-8?B?Y2dEcXR6d09DSy9yYjNOODk3bTNqTm4yamFkQXc4TktYa2N2R1pjbHJsQTds?= =?utf-8?B?akVxYlZpczRkZXhxcFRoQ3dIUGdqd2FibnJUWmQvbW9jdnVjM2M4cHBBdWR2?= =?utf-8?B?S0IwQ0l1bVNzbkgvVUsrNFhkNk9GYUlPY0dSZ05WRmdTaDNwNmY2b1BjaHFK?= =?utf-8?B?a3llR04zcG1uT1JoWHVOWXNick0yNXlxVU1nWEZqQ1NJU1J0ZHR2eFFodlpx?= =?utf-8?Q?sRXM=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c25f5d4d-47b6-48b6-72cb-08dd04ff1adc X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 22:53:07.1727 (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: Yba3KdaYOb4T7Ri4RSsXR76RcaRKIjGGKOUJRb6jX2Zgtb5iinmcm76soTv9c+1ovN5cHt3zLdvkGelWn9vS3w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB9967 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. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- 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 | 117 ++++++++++++++++++++++= ++++ 1 file changed, 117 insertions(+) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/en= dpoint/functions/pci-epf-test.c index ef6677f34116e..6077a51bbd7c4 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 =20 #include #include +#include #include =20 #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) =20 #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) =20 #define FLAG_USE_DMA BIT(0) =20 @@ -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; =20 static struct pci_epf_header test_header =3D { @@ -642,6 +654,63 @@ static void pci_epf_test_raise_irq(struct pci_epf_test= *epf_test, } } =20 +static void pci_epf_enable_doorbell(struct pci_epf_test *epf_test, struct = pci_epf_test_reg *reg) +{ + enum pci_barno bar =3D reg->doorbell_bar; + struct pci_epf *epf =3D epf_test->epf; + struct pci_epc *epc =3D epf->epc; + struct pci_epf_bar db_bar; + struct msi_msg *msg; + size_t offset; + int ret; + + if (bar < BAR_0 || bar =3D=3D epf_test->test_reg_bar || !epf->db_msg) { + reg->status |=3D STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + msg =3D &epf->db_msg[0].msg; + ret =3D pci_epf_align_addr_lo_hi(epf, bar, msg->address_lo, msg->address_= hi, + &db_bar.phys_addr, &offset); + + if (ret) { + reg->status |=3D STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + reg->doorbell_offset =3D offset; + + db_bar.barno =3D bar; + db_bar.size =3D epf->bar[bar].size; + db_bar.flags =3D epf->bar[bar].flags; + db_bar.addr =3D NULL; + + ret =3D pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &db_bar); + if (!ret) + reg->status |=3D STATUS_DOORBELL_ENABLE_SUCCESS; + else + reg->status |=3D STATUS_DOORBELL_ENABLE_FAIL; +} + +static void pci_epf_disable_doorbell(struct pci_epf_test *epf_test, struct= pci_epf_test_reg *reg) +{ + enum pci_barno bar =3D reg->doorbell_bar; + struct pci_epf *epf =3D epf_test->epf; + struct pci_epc *epc =3D epf->epc; + int ret; + + if (bar < BAR_0 || bar =3D=3D epf_test->test_reg_bar || !epf->db_msg) { + reg->status |=3D STATUS_DOORBELL_DISABLE_FAIL; + return; + } + + ret =3D pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf->bar[bar]); + if (ret) + reg->status |=3D STATUS_DOORBELL_DISABLE_FAIL; + else + reg->status |=3D STATUS_DOORBELL_DISABLE_SUCCESS; +} + static void pci_epf_test_cmd_handler(struct work_struct *work) { u32 command; @@ -688,6 +757,14 @@ static void pci_epf_test_cmd_handler(struct work_struc= t *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; @@ -822,6 +899,18 @@ static int pci_epf_test_link_down(struct pci_epf *epf) return 0; } =20 +static irqreturn_t pci_epf_test_doorbell_handler(int irq, void *data) +{ + struct pci_epf_test *epf_test =3D data; + enum pci_barno test_reg_bar =3D epf_test->test_reg_bar; + struct pci_epf_test_reg *reg =3D epf_test->reg[test_reg_bar]; + + reg->status |=3D 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 =3D { .epc_init =3D pci_epf_test_epc_init, .epc_deinit =3D pci_epf_test_epc_deinit, @@ -921,12 +1010,34 @@ static int pci_epf_test_bind(struct pci_epf *epf) if (ret) return ret; =20 + ret =3D pci_epf_alloc_doorbell(epf, 1); + if (!ret) { + struct pci_epf_test_reg *reg =3D epf_test->reg[test_reg_bar]; + struct msi_msg *msg =3D &epf->db_msg[0].msg; + enum pci_barno bar; + + bar =3D pci_epc_get_next_free_bar(epc_features, test_reg_bar + 1); + + ret =3D 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; + } + + reg->doorbell_data =3D msg->data; + reg->doorbell_bar =3D bar; + } + return 0; } =20 static void pci_epf_test_unbind(struct pci_epf *epf) { struct pci_epf_test *epf_test =3D epf_get_drvdata(epf); + struct pci_epf_test_reg *reg =3D epf_test->reg[epf_test->test_reg_bar]; struct pci_epc *epc =3D epf->epc; =20 cancel_delayed_work_sync(&epf_test->cmd_handler); @@ -934,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); } =20 --=20 2.34.1