From nobody Sat Nov 23 01:49:04 2024 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013042.outbound.protection.outlook.com [52.101.67.42]) (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 7DE461B0F05; Thu, 14 Nov 2024 22:52:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731624780; cv=fail; b=rb6BaSRbJphLupW3lWLnDzGIacaPboimnwUD68bRbsHjWsYtnYL2XTSjKjDU4Mynvra/rgtOp88/3E1j4ttzeZWIBAp0pEORZg3uUQ/J02rYUtsOSiJ/0hBE4hgYJbZMbZ+u61baZKYmzAYPYIRVYf522N1SqmLccbqH4BpiciA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731624780; c=relaxed/simple; bh=GejaoXH9F7tp0F2pj5fsUPiC1b7nvtn4F6gvoOZt97U=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=mspUTk7Ivp0H3P3XsTCDsr2kkpf1E5Fy3JptlRDKVT/REuM9mfJQ5PlEEMJLfsUuamOFnZ4DE4xC33fz/lCro2Kys60t2XNzL8yhap8EDrXSCwDUkfn6Qb4594ZbIQ4Uu4f+9RfVAgaZqa7u4Hx2YXL6ET0q841TS2PINiBVaNI= 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=KqOoP8Xv; arc=fail smtp.client-ip=52.101.67.42 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="KqOoP8Xv" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=k4jtABZTNzPujeKVUT8fcqZPqlUGQK+hwrKdYTbg2SGzqJ7siUUKkPxUEHikUzXAP50ekkYOuXcFqrBmaB/G/700wUpLGhA1GjG1ceEzd4+Xqz+CkmoSOOWPmZvpid+QAgJhG4+/086TjzjxXzFqaL6C5O6kqkL4TJIXm8chzQ8dckVcxI9yYdK4lB5Ij2MfIyLuBuCa9QrOV1pP8x5Y7C543Tjc+4jR3sEwAGaYcGkfQptLbikrQyMv7DYUQa/p8tel7dIal3MuYsRr0OLo3qxi6XN43CEuWfIlfZIW88m9Z97VDZGgUI93fhGLP+nqZhcj9p3HTw49AtrYmUQ4jw== 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=sJXulzg+iI1qW2v4QK7V0AHZaG9zbHgVHKDqdV6gZXk=; b=MA01XCXJcfoeP5xkomNoQibnVJg+JBoVbTRkA72R6ON7oyK3EB2wCHQTJe+Vl+1N8e/wrmy3Z86p3Ki3xUtQSUz38m05XW90CY+YHUZxDfAlflZjQt/DvD4s/AIkNSowHmjVHAzSbss/WVYJmFtOwFiUf8V0+61sdkvtDSm5K4AkQxLFlokTH1kOPR66X/7HJd4m6DPeq4YZN6ItiWnO9gv6J7mKNedFhxuAK45tVCeK1bBTBdbTFBcbo6HkZz7DJRGl74XqPnTwz6xn7xyFXVQ2gvVjwX7OTe2vFbNbaFWjXpIB30mTtYSWJUtDT2WjnJ3R3PEHT7gLuyTHYgKSug== 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=sJXulzg+iI1qW2v4QK7V0AHZaG9zbHgVHKDqdV6gZXk=; b=KqOoP8XvPqW69NrQ4Toj8pj+5Y4PzmXpaAjLcN6UQh4gzZ+fE/ZrIMCWtFXPH9wFXRy6bC//6SQc3chUxZBnjhDfK4KIeFfNLaTBEQurA6g1FbyEDuLPtKAJaevvrc0kevy0HVk8sHNkiykj7lDuI2T1yHUvfpmst7jCdVoKTlNUHD9aoJpmUV3oKwpIcqJOFYUgA1QZoUo9/IR+QsDOPz1DZCzfssoDP84JsLPWdarADzduzLWI039g0rEf893qTFLljc8jfy5ny9PCxw2ZIIliwe+zopYE7bGCkut7lw7VO5dRcPKL+1vGiJOoBnaHH51+mwQXnEJtxwRgQ3oStg== 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:52:56 +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:52:56 +0000 From: Frank Li Date: Thu, 14 Nov 2024 17:52:37 -0500 Subject: [PATCH v7 1/6] PCI: endpoint: Add pci_epc_get_fn() API for customizable filtering Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-ep-msi-v7-1-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=3147; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=GejaoXH9F7tp0F2pj5fsUPiC1b7nvtn4F6gvoOZt97U=; b=H4UfBsT1veKOUojtt3FbC39Xu2ea4QWtLIu+xbDCdzobu6XLfkOlZQucb/5ZCIHUVD7LhQNbq Ls/XtDOpllRAJg/DDl0QHJFWr1S1lOBLHnFYM1i4mobJmy77SbFZ+FN 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: 8e47ca00-af8a-46ba-29c2-08dd04ff1432 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: =?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5bmV5SnJuQjFoYVQ0UzVmN2hkblc1?= =?utf-8?Q?juPRtZ/AmKi4TZT+Lrb7XVP+HX0jD+PZZ9enM=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?dWVLRkNkKzhVMnU1eXFPeWFSdkRtK09LaE4xZlQwQ0pkNWEzb1IzVWJOTTdM?= =?utf-8?B?cjVHaCtLLzRBTUlQcHRRWGs3b0dlTjFiS1lxTXZ2c1pSU0FBcmw3a3ZyM25I?= =?utf-8?B?VmpOa0pKZGdubUwxZ1hzOUpKQlJaTWlyYWh3UEFOYmZ4TWxmOS9uYllQL0lj?= =?utf-8?B?VSs1YWIvaGwxajhGZ2tMQmJWeVNzdXNQMEVQWmFmOTVsUHQ0RXdSTHFPZTBz?= =?utf-8?B?VVhKYjgvZ3RDQ01mVi9zbkFTTVhISG9TK0czb1g1T05wcno3eTBQRml6U2Fh?= =?utf-8?B?K2c5MXIydnFCWlhxd3pqS3RuZVZpVElNR2d5T3pBYVZUdFZ2YlA2SXhCa0VY?= =?utf-8?B?QXR5NWFTR3FaNThnOGczL21CR0JteDltb3dhUUE3TzBUY1FILzhqcVNrN1N3?= =?utf-8?B?Z2F6Y3RvQzlYYnNHRXlTRU5aQUd1bDRyU0hxRVRVQ3dydXZRdmd3ZFhJVkEx?= =?utf-8?B?a1pKNk15OW1yOFMram1IMWdSTjlFV21WeGVtS2Fud0JuZEl2cHJKUE1QdVN5?= =?utf-8?B?TjFLMEhjL21QbUFJRmRrVXlaMUpQUERhM3pnTlRMM2FDSStyWGcwNXhIOU9B?= =?utf-8?B?U1VtWjZyeko2MGE3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NMkE1cUR1ZGhjOHhBL1hMcTRHM2kvSUNMTjNjeDkwbXhueHZa?= =?utf-8?B?cThBaXZMQzBzUFRvSnVXbTFJY1k5NG1LVUdSTnNKd2NVcWFWZ1htTFVBMVF6?= =?utf-8?B?UFlzaUJnaUtmRkFkSTMxd1ArUGZ6VkZldktiUkxmUmRTeDZ0eXVVOHR2d21J?= =?utf-8?B?NHNUdFFFVHQyVTByT2ZqZ0x5N3RuZU1WQ3k2VXR6YVVHTDZiQmg4MVBZY05u?= =?utf-8?B?T1owWXNVZEdCbjhnMHhSTWprQlBBaHBrS0d0enJOUWhOZEU5YnRFQjlFRlZD?= =?utf-8?B?UTRrWnJVWGdScEN3UGFrcnVXZldwTzAwNllZaGVYWDM3bzRqa2ZPZ0pKVWtN?= =?utf-8?B?RlZZajExMU5ma1VBbENyb2YrYndvM1pzMVZUU0RHS3ZOMVF0eTFMYlFOVTZI?= =?utf-8?B?L0pCTFNsYWF0MXlSN1NZL3F2eVJFOE04OFVmOVp4dzkycklKclo0U3NXMERu?= =?utf-8?B?cFBjZE9LOEZJaGVQN00ySjlDRjI0emE1citUY0NQMzQwdVY4NUxwMitNMHRo?= =?utf-8?B?ZitVclNweVhqSXdjZktkWGpZMU9EMGpvOEZLSDI3Ti9JOXNuM0lPSGgwVU1X?= =?utf-8?Q?I7Ik=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e47ca00-af8a-46ba-29c2-08dd04ff1432 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:52:55.9585 (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: Rr0w/jDvnhhgV95z0Qvdv9H1bgE9wMjh1kHTbhC3bDuSo5VQKnFJn+W5sH6R7gyklQ95TLjMDqe85AHArm+E1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB9967 Introduce the pci_epc_get_fn() API, allowing a custom filter callback function to be passed. Reimplement pci_epc_get() using pci_epc_get_fn() with a match name callback. Prepare the codebase for adding RC-to-EP doorbell support. Add DEFINE_FREE(pci_epc_put) to implement scope based auto cleanup. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- change from v3 to v7 - none --- drivers/pci/endpoint/pci-epc-core.c | 23 +++++++++++++++++++++-- include/linux/pci-epc.h | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci= -epc-core.c index bed7c7d1fe3c3..f5538c007678e 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -48,6 +48,11 @@ void pci_epc_put(struct pci_epc *epc) } EXPORT_SYMBOL_GPL(pci_epc_put); =20 +static bool pci_epc_match_name(struct device *dev, void *name) +{ + return strcmp(dev_name(dev), name) =3D=3D 0; +} + /** * pci_epc_get() - get the PCI endpoint controller * @epc_name: device name of the endpoint controller @@ -56,6 +61,20 @@ EXPORT_SYMBOL_GPL(pci_epc_put); * endpoint controller */ struct pci_epc *pci_epc_get(const char *epc_name) +{ + return pci_epc_get_fn(pci_epc_match_name, (void *)epc_name); +} +EXPORT_SYMBOL_GPL(pci_epc_get); + +/** + * pci_epc_get_fn() - get the PCI endpoint controller + * @fn: callback match filter function, return true when matched + * @param: parameter for callback function fn + * + * Invoke to get struct pci_epc * corresponding to the device name of the + * endpoint controller + */ +struct pci_epc *pci_epc_get_fn(bool (*fn)(struct device *dev, void *param)= , void *param) { int ret =3D -EINVAL; struct pci_epc *epc; @@ -64,7 +83,7 @@ struct pci_epc *pci_epc_get(const char *epc_name) =20 class_dev_iter_init(&iter, &pci_epc_class, NULL, NULL); while ((dev =3D class_dev_iter_next(&iter))) { - if (strcmp(epc_name, dev_name(dev))) + if (!fn(dev, param)) continue; =20 epc =3D to_pci_epc(dev); @@ -82,7 +101,7 @@ struct pci_epc *pci_epc_get(const char *epc_name) class_dev_iter_exit(&iter); return ERR_PTR(ret); } -EXPORT_SYMBOL_GPL(pci_epc_get); +EXPORT_SYMBOL_GPL(pci_epc_get_fn); =20 /** * pci_epc_get_first_free_bar() - helper to get first unreserved BAR diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index de8cc3658220b..d3d3b8c914614 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -300,7 +300,9 @@ pci_epc_get_first_free_bar(const struct pci_epc_feature= s *epc_features); enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features *epc_features, enum pci_barno bar); struct pci_epc *pci_epc_get(const char *epc_name); +struct pci_epc *pci_epc_get_fn(bool (*fn)(struct device *dev, void *param)= , void *param); void pci_epc_put(struct pci_epc *epc); +DEFINE_FREE(pci_epc_put, void *, if (!(_T)) pci_epc_put(_T)) =20 int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t base, size_t size, size_t page_size); --=20 2.34.1 From nobody Sat Nov 23 01:49:04 2024 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013009.outbound.protection.outlook.com [52.101.67.9]) (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 6B4101B219A; Thu, 14 Nov 2024 22:53:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.9 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731624784; cv=fail; b=GyfE6KIA5EhOpSFwBy6+Uiho50U/IhHiJFTN3pMyma8idWg3WFjHZFnY0Dg6zUTU0tUgE0abV7c8erscQzDMqM4spSl79KdSTrGj9uyKJLDvR+dhMJ+X6Jt4hQXwTH0Cv7uyY7qkRX4uPkPtOhPjm+CKVMaEolmaXrP38DNsQEk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731624784; c=relaxed/simple; bh=NrKifoN1fmq3Tc8fKoWlpGpdQXpHuqlY0N137rNr0VI=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=HwuklcsRZzr+WttofqXc1C2bOx3x2m19HOs4QJsLnB0CfkNgejqbs0NdAlBktHCeCfeuBN9XRPTuMRr6kKLmf3xyhKqbaCYz49FhoWH0TCuU2/s3kfwz6BUDw8//OtqIx1IlWng6016upclaAFp/A6x3vHGPRhge4zt0+4fDS/A= 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=V35hZwqm; arc=fail smtp.client-ip=52.101.67.9 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="V35hZwqm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=M/8+ow8iBEjbj41VXvfMfk/OB7s7Tr34iT0Q5Stc35BGBpPkGIxpv3sHN0GJBeifFKQvRMa2fUNofx2Jc4nPnib5SCneZS2uuPoc+GEupn12X44Dnz2GTfM0SD4pqDntzqcYR6wIg/2cenlbhE7m0P6AeQLjPYrnpeyvZIE1+5P0owx2ZWEhUaJKT9bMaoK8Gd1MAq1WwpCAXh2Mr7SrqkWbwnxB++aZPaH53HnazUnISwrNiSQZonwUF2NHcQdZAQnjDtttR/qLPLzm3v7bc2WQgqA0EqISHpvbP/7Vo8xLUWO4Kjl8Dib2raUSTQzBE20OK4XnXETxkuwRh33eXg== 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=97UWWYJzp/qrNarYH1kVajK0y5wQMq7H3SLhCi+mabM=; b=IC/52BPpisd3yxHRs4XSAMZLWYhkEouwdCrykH+O7AMp+2s8J2pW8Qg0JJwXTkkCa9G/sjIkY2a+EV37NZTJYysxKvBmj+lGjqUP8yoBzyjJxF9s8GYsE46gywM3EG351hRG4elS3GmjQIieUdY20QW28VpEyb6IkIy+2ZgkyPccxqFZrdcqhQfxrEzZxIJZYTFcH+ecAaW22+NVEnSAAuYn8EcNj/5uOdD9gFQb1HqLeS2myVDu1rvK2llVasWoSzv0uyDxhqG6dy/2g05t7UJntLqkQznE/5dsane8rZvzvYraVQ1c2roKYRSeVcMPhCwNqK5Km1ZTxHaeklkyBQ== 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=97UWWYJzp/qrNarYH1kVajK0y5wQMq7H3SLhCi+mabM=; b=V35hZwqmyM/cGct4CzQ/p0SBXwgZplqu707YnGpBR3ekh13d4v+6YG1oK0q9llkOSKsYxgkcaFYC0ZMo8yDByp7pWPRvzZWcRn25YlJpTs4Vhk0PQ6po31O1XxaPA0Vur5E7M6KrBqcWSwVp2tub5x1aHQlDfDkhxfEvldgaD8GtB1BfA3gWFEuwVlvTY8sgUjzT5yE01LqM1VLCvtVCbmERNSpX3J2KPeYX2OsNPuhZrUIrBu5pMedlOkQEPs6v0VUBh87u4LwgC6TkQ59vHr9LYEbS5jIaoYrHjI6GAIHsA1yd1mQl9NZLD+gYmicfeR9vP5DAuPROhVxloEelfg== 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:52:59 +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:52:59 +0000 From: Frank Li Date: Thu, 14 Nov 2024 17:52:38 -0500 Subject: [PATCH v7 2/6] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-ep-msi-v7-2-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=6297; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=NrKifoN1fmq3Tc8fKoWlpGpdQXpHuqlY0N137rNr0VI=; b=+dhFZexOlmiNWGCmaGYzMnUICE36RgzqikUVOQnHKaHm47Tm2h9Jm/2NGci9z6i9OG2MzMOmh xmHaZTkOifVBRLzTvkNasACSNNZ1TS2fP/h7KBEf1rKFI6zQYL4/JSz 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: d1460550-54d1-424f-e012-08dd04ff166f 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?bFZ2RFM2TWN0ZisvVlh1WEV6aHVJWFB2TjF5M3NWQ0tjamJOSEIrMEpjbGhz?= =?utf-8?B?ck1WQW5yU3Zyam5iUDB6VXJneURQZHlTTzhiaVUwemRIYVRQVTYvQ214QzNa?= =?utf-8?B?cFNpQkh2Lzk3dXVweDlCdDRuczV1OE8rR1pEcEl6bVF4WlgzNXZ4cmIzTStw?= =?utf-8?B?ZjlzUnZRNUNJYkFURk1NQnQraExCd0FvUGhJMHBtTnZCSWN5V0g2SVA1VmQ3?= =?utf-8?B?T1l1MDlVTVJJc24wbzAzZWthYTNmVFVJbmdUc2xEYitROXIvL2ErODVHcDNY?= =?utf-8?B?NXVQNHdMMVZNWjBhajRYdStJTGF1VEhXL0JJa0V5eDBYVm14MmszbDRlWllk?= =?utf-8?B?OEF0R2d4an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JbnJX?= =?utf-8?B?ODRNc09iQVlWQ3FiVXFUSUprOE9lWDNLdkY2dzNYNFoycVJHS1U0SzZGZXl4?= =?utf-8?B?YUZSdTRacHFId2N3dk1OOEhSK3FGKzNNWlM0U0Z5R3dOZzZYWnRPYjhhZk0r?= =?utf-8?B?Q3NyR0R6NE95ZHM5N2ZwN1VwWVc1NTBFL1B3OTdGUzNQaDZQcVprUm9ZR2pL?= =?utf-8?B?UnQwNUY4RU1JN3lGWGsyMm5BTnlhcDlHVjNWOWdoQ2pmbDY0cGg2aWh6RElZ?= =?utf-8?B?NWMyMi9SSzhVSEhRV21EeS9YMzJUeG1yQjkreTZnZ3F5V3hUMDk5ZTl0Q0hl?= =?utf-8?B?UmROdzJ1a3FNbU9ucHkwTHZJVDdGMU0vUzRQSTcxWU9MSGk0S2dDbWpCKzN3?= =?utf-8?B?YnpxeFdVajU1OWlHc2haaGRjUmtYVFBENEpQZksrWGZPNTd5SXIwSW5rSytL?= =?utf-8?B?OUhBQWY3ZWhqV3h5YnhvMzZsZEtVZUF3T3lTc0lJWWt6Q01rQkpsdlVCcGJw?= =?utf-8?B?MlZSbEc0N3FhQlV4QmtCNVQ3ODRkNWRlM0hUTXU3cng5V0RiVzNYV1pCRTFq?= =?utf-8?Q?UdEb7NPzSMyJnFzDbGA5IqSitB7l2iHA90IhY=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?a3RFaTI2MVY1ZmVvWXl2OWtkL2p2S3pjRUZFSUszTTdRbnhIQWs4Nkh1RU04?= =?utf-8?B?dGpMMWliNHJ0NCt1NkFURHl2OUd4bVBXaD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B?VmhoMGNHQkt5TCtaY0xMWVhtMmVOMXVZTDhUYTdudVY2M3V3NExKSm82bjBm?= =?utf-8?B?b0tqVmlDa3gyTFU3b21na1kwaXpvY1cyZ2s1clR2YlIzVCtUa3AwMkxTUkdv?= =?utf-8?B?VFlJcWdkTnd0UzhkcmpGYWJVT0ZmbzNtdllDVFdnWTJ3VElGYWhpRW9XOGlI?= =?utf-8?B?Um1RRlAxUWZnTGsxelVEZEYvNEhPOGxLRklpa2FZMzNEbVdvYzVIZ2xJWnNJ?= =?utf-8?Q?dKV4=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d1460550-54d1-424f-e012-08dd04ff166f 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:52:59.7063 (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: pCQYSSamR2PcjhAWw//mfeziiKhfB5uH9RojzzOpuFx23lFXGcVHTzhGZN6ONh9Y31Vd0lTAnWDcOYYQxbNgdg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB9967 Doorbell feature is implemented by mapping the EP's MSI interrupt controller message address to a dedicated BAR in the EPC core. It is the responsibility of the EPF driver to pass the actual message data to be written by the host to the doorbell BAR region through its own logic. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- change from v5 to v7 -none Change from v4 to v5 - Remove request_irq() in pci_epc_alloc_doorbell() and leave to EP function driver, so ep function driver can register differece call back function for difference doorbell events and set irq affinity to differece CPU core. - Improve error message when MSI allocate failure. Change from v3 to v4 - msi change to use msi_get_virq() avoid use msi_for_each_desc(). - add new struct for pci_epf_doorbell_msg to msi msg,virq and irq name. - move mutex lock to epc function - initialize variable at declear place. - passdown epf to epc*() function to simplify code. --- drivers/pci/endpoint/Makefile | 2 +- drivers/pci/endpoint/pci-ep-msi.c | 99 +++++++++++++++++++++++++++++++++++= ++++ include/linux/pci-ep-msi.h | 15 ++++++ include/linux/pci-epf.h | 16 +++++++ 4 files changed, 131 insertions(+), 1 deletion(-) diff --git a/drivers/pci/endpoint/Makefile b/drivers/pci/endpoint/Makefile index 95b2fe47e3b06..a1ccce440c2c5 100644 --- a/drivers/pci/endpoint/Makefile +++ b/drivers/pci/endpoint/Makefile @@ -5,4 +5,4 @@ =20 obj-$(CONFIG_PCI_ENDPOINT_CONFIGFS) +=3D pci-ep-cfs.o obj-$(CONFIG_PCI_ENDPOINT) +=3D pci-epc-core.o pci-epf-core.o\ - pci-epc-mem.o functions/ + pci-epc-mem.o pci-ep-msi.o functions/ diff --git a/drivers/pci/endpoint/pci-ep-msi.c b/drivers/pci/endpoint/pci-e= p-msi.c new file mode 100644 index 0000000000000..7868a529dce37 --- /dev/null +++ b/drivers/pci/endpoint/pci-ep-msi.c @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * PCI Endpoint *Controller* (EPC) MSI library + * + * Copyright (C) 2024 NXP + * Author: Frank Li + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static bool pci_epc_match_parent(struct device *dev, void *param) +{ + return dev->parent =3D=3D param; +} + +static void pci_epc_write_msi_msg(struct msi_desc *desc, struct msi_msg *m= sg) +{ + struct pci_epc *epc __free(pci_epc_put) =3D NULL; + struct pci_epf *epf; + + epc =3D pci_epc_get_fn(pci_epc_match_parent, desc->dev); + if (!epc) + return; + + /* Only support one EPF for doorbell */ + epf =3D list_first_entry_or_null(&epc->pci_epf, struct pci_epf, list); + + if (epf && epf->db_msg && desc->msi_index < epf->num_db) + memcpy(&epf->db_msg[desc->msi_index].msg, msg, sizeof(*msg)); +} + +static void pci_epc_free_doorbell(struct pci_epc *epc, struct pci_epf *epf) +{ + guard(mutex)(&epc->lock); + + platform_device_msi_free_irqs_all(epc->dev.parent); +} + +static int pci_epc_alloc_doorbell(struct pci_epc *epc, struct pci_epf *epf) +{ + struct device *dev =3D epc->dev.parent; + u16 num_db =3D epf->num_db; + int i =3D 0; + int ret; + + guard(mutex)(&epc->lock); + + ret =3D platform_device_msi_init_and_alloc_irqs(dev, num_db, pci_epc_writ= e_msi_msg); + if (ret) { + dev_err(dev, "Failed to allocate MSI, may miss 'msi-parent' at your DTS\= n"); + return -ENOMEM; + } + + for (i =3D 0; i < num_db; i++) + epf->db_msg[i].virq =3D msi_get_virq(dev, i); + + return 0; +}; + +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 num_db) +{ + struct pci_epc *epc =3D epf->epc; + void *msg; + int ret; + + msg =3D kcalloc(num_db, sizeof(struct pci_epf_doorbell_msg), GFP_KERNEL); + if (!msg) + return -ENOMEM; + + epf->num_db =3D num_db; + epf->db_msg =3D msg; + + ret =3D pci_epc_alloc_doorbell(epc, epf); + if (ret) + kfree(msg); + + return ret; +} +EXPORT_SYMBOL_GPL(pci_epf_alloc_doorbell); + +void pci_epf_free_doorbell(struct pci_epf *epf) +{ + struct pci_epc *epc =3D epf->epc; + + pci_epc_free_doorbell(epc, epf); + + kfree(epf->db_msg); + epf->db_msg =3D NULL; + epf->num_db =3D 0; +} +EXPORT_SYMBOL_GPL(pci_epf_free_doorbell); diff --git a/include/linux/pci-ep-msi.h b/include/linux/pci-ep-msi.h new file mode 100644 index 0000000000000..f0cfecf491199 --- /dev/null +++ b/include/linux/pci-ep-msi.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * PCI Endpoint *Function* side MSI header file + * + * Copyright (C) 2024 NXP + * Author: Frank Li + */ + +#ifndef __PCI_EP_MSI__ +#define __PCI_EP_MSI__ + +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 nums); +void pci_epf_free_doorbell(struct pci_epf *epf); + +#endif /* __PCI_EP_MSI__ */ diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 18a3aeb62ae4e..5374e6515ffa0 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -12,6 +12,7 @@ #include #include #include +#include #include =20 struct pci_epf; @@ -125,6 +126,17 @@ struct pci_epf_bar { int flags; }; =20 +/** + * struct pci_epf_doorbell_msg - represents doorbell message + * @msi_msg: MSI message + * @virq: irq number of this doorbell MSI message + * @name: irq name for doorbell interrupt + */ +struct pci_epf_doorbell_msg { + struct msi_msg msg; + int virq; +}; + /** * struct pci_epf - represents the PCI EPF device * @dev: the PCI EPF device @@ -152,6 +164,8 @@ struct pci_epf_bar { * @vfunction_num_map: bitmap to manage virtual function number * @pci_vepf: list of virtual endpoint functions associated with this func= tion * @event_ops: Callbacks for capturing the EPC events + * @db_msg: data for MSI from RC side + * @num_db: number of doorbells */ struct pci_epf { struct device dev; @@ -182,6 +196,8 @@ struct pci_epf { unsigned long vfunction_num_map; struct list_head pci_vepf; const struct pci_epc_event_ops *event_ops; + struct pci_epf_doorbell_msg *db_msg; + u16 num_db; }; =20 /** --=20 2.34.1 From nobody Sat Nov 23 01:49:04 2024 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013009.outbound.protection.outlook.com [52.101.67.9]) (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 DDFC71B21BD; Thu, 14 Nov 2024 22:53:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.9 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731624787; cv=fail; b=G9dR7EoqQGghyII6G2tIBHXm/IRBjW4clhYmMUYBulciHwXFKNstrUNgMFRBQJKl6qjfdNcHdIA2s+GMssZuYZoMo6QseO8QpJt9UBom7IuhSvyzj2MA1XDIxURyo8Ekakwtgz72JxsbBCxNbS51T3bYTbB7lQi6YEv3q20qvC8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731624787; c=relaxed/simple; bh=W0/3suDS2X+PR81+KxkOxEg/dzb/QOb1xgTjwq/FHuI=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=fnnw3RErGN6hnD7S1/PjHQui43dMZZyoBGliRH/fJ3/ZwP/pei45vAbhafapqpTeZ0VV3WwfsX/nv1RgiBfMvYP+crf/QqCUiu9CquWYzjOQUQFqyTAbibjzCPsuFtCjXh8K+wzR34LvG4iUr6HshEGY+7hqbjjzvJPap/CpZ0Y= 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=ZOX/8pNl; arc=fail smtp.client-ip=52.101.67.9 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="ZOX/8pNl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=I8HBaMTw/OzKG1jvGCi2ac8yGMVPuRCuTzRXvFJskwF260MEnb1j4JxXSzFdWy/nCVpeTG9azfW7c0FSjRhOr3fErRMbd2qUPue6enHam+5FQCh/Lfz5N/OpfVJVRmcNmKlHria9qdoOXrUmCc9kpb+3PqKBIzOuXQFvFMGy8aaB90+IJfeHCPAlonG/PM7o4pVE0t6bF+JzDrlZxLh0j0GMG590Jsd6XxYd6kGwsQXrwzO4OWKzo2J2ic9UO71kw8enMSSD1I2r5jmUdw2Y8shreOJTdzlBEMPPKbz3FBxnY/Vmig20tvbhqW8rgIf77ZJTjVEihbcAp5XBKPB0fA== 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=jlXLZ5x5NHDqWvGgBVnFd6Us3IzJiiZwh2cGtn9n1VI=; b=IABAhDDYt4lnlQWiokDVNV/WrtxQLxx4X58R5Qn2iQ/U+n5b1lLzkksCB5DqKJVTEX4zbLiAZLZ8W3HqL70WAp29yJx6Kv0OF9w3/zhCSjEShorktPAykTLR3FZU5tnE2JGBClLv+WpQMTYtGqSEa6jYtEmbbjctImdSBKglzEkA93zA6lmGpj0+U5+CyU0nE73UeWzodRFs1G9HWMQAG39ZY/NVERiy/2ZsK5YQgsrRoV+SrA7ylgOvvbObABdAXps6iVCmF9fDgVnOT0nL2rxH0r4GHbhrr1IBiwgmOztqohXuIctt5KxZgeiefCIbNnLlDPq/VzQEY1yogY+48A== 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=jlXLZ5x5NHDqWvGgBVnFd6Us3IzJiiZwh2cGtn9n1VI=; b=ZOX/8pNlL25L0j65I8JmSeyP1oChN/1ji5owb5iwKIUXUeNJGCFzP0TB79pQ1aO4TjtuVpUfgifNn2p2c+qof3WgrZfrn5qIxCJfQBaeQ8VoO/FCOs1QDSYZRsT1pt0cQEj4eJVObEPpj9eUz7Pv302CfvldtEjbM01OJgAnMFPFAqUJK25kg0znqASEH7xnrP6Juj9y6gaBhHhMo51awTkPhqUoOa0DGjEQL3MdgeRI9A9jFV5QAQr0Ep2PgXK6lcIPDY4EK4iuXSzbgCiViHFt/4ZLSp2yqAegpXfVwkVmZ2kjDwlV0dYD1Huxl6m2QxoRnt9i8cQp5ME0QMU1gg== 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:03 +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:03 +0000 From: Frank Li Date: Thu, 14 Nov 2024 17:52:39 -0500 Subject: [PATCH v7 3/6] PCI: endpoint: Add pci_epf_align_addr() helper for address alignment Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-ep-msi-v7-3-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=3039; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=W0/3suDS2X+PR81+KxkOxEg/dzb/QOb1xgTjwq/FHuI=; b=CmGk9/KoFwJjo4n4AYZ5ddK4TCAISmSrzK3mH0rPCsmbJ7Vw9rX50/YwCUG/5kAYwaiugj2as fdXFX0Nr5PnDggkHNsGFbI6vtmt+fbnqzAyIahih/VWC8vSQTmkbUFz 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: ac137464-518c-4b74-da2c-08dd04ff18a6 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?WEJiWjZZdmNERXNDUUdYWUt0VFBtZDJrK21LTk1GbjlibkhMdEhvUzNPTXdT?= =?utf-8?B?TUgyUDBFemlMUVFnb3dvNk1kVGk4QkFhTkxVUTRUNFIya3dncWptQm5SRTVl?= =?utf-8?B?Q0VkWnY3VVgxY0ZPZktGT3RaWFAxWFBLZjl0dzNTRHh3QjlPQVBweFc4KzQx?= =?utf-8?B?U1o0bVUwU1RiWnlpMWpYVmx2bGtwN0dUekY5alBXQWw3bnhzeXhmbVZWVzA4?= =?utf-8?B?L3B1a2VXaHpYbXI1cXlaUlEzUkdsSVpURDBweUZBRzMwd2ZmN25RZ3NsZEtv?= =?utf-8?B?RGtNaTBtcnlEM3VORHozQSsxa0xOU0NoNWtnVnV1Um9PcFU0dWJBK1FqaCs2?= =?utf-8?B?VEFrRVZ4YTlOdHo5RWdNWC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UwxdWlmSnNIWnAyWVRRRDluL0lzOElITzRWbUZZNCttL2hEZEkr?= =?utf-8?B?Qk9kajRWVkxuUENKd1lBQytYV3RPQm9kbjNCYmxBcFlzSmNRZDdRWFlJaFly?= =?utf-8?B?UHVCRElSdjNxb2hoclRLYTFacHBnSXloNFVyNE1yOTFBOW5VbHM2T1JYRGJt?= =?utf-8?B?aXlxRWIxbUtQLytUVWM3djJmQTRWU1M5d3VwbXRQcTFRQUhQcUQwWm5RbmpB?= =?utf-8?B?amxkTmZacUpkV25GVVBXeEtHQUo5OVZ6d3AzYTFMbW5nWFR4WDdvTGV4dWh3?= =?utf-8?B?N2ZPbW1OL2Q1TjFXKzFnL2ZpSHFZT3pTMWZSSjJPc0psYlJwdkIzVDNielJ2?= =?utf-8?B?MUJTakcrWXhDL3RtT1RYcWk3eUhpSXkzUFRJTVRCMWZyWVBSVmRua1Z6SExN?= =?utf-8?B?MkVUR0hzdDJuMEpydXdjNXFmaEdEK1BaajhRQlppVFpZcTQ1eDVURUtFZVor?= =?utf-8?B?ZUhlQVlYNFhaNE81L2djL2tka0FZM3JjM2toSFNNY1A4U1FTYkJiNWRWa0sy?= =?utf-8?Q?xUka5+RLHA19QCQoXxxY0Wo8CpaRX1cldrCe4=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?bm9GMkIzN1laZ3ZWYWZmSFY4eEYxT1h0ZHZzUkhSMjRRNkVxR1ptdHNqUU40?= =?utf-8?B?dWNHL1h0c3Rpb25GMnlUM0dmN290LzB6eVlURHUwbFU0UVZTRnJOaEM5RUFk?= =?utf-8?B?clFXc0VCUSt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HNw?= =?utf-8?B?MnZmOGJIVzZrMXNCRGpiTHliTWIxTFVvSktZVnRWSHlmMk54MTdLWHErY0g5?= =?utf-8?B?ZHRENVp3Zk14SmQyL3d6U1NSQVc1eDdhUEhPSTh3a0lxdDBFUmlrZ0ZiYWdl?= =?utf-8?B?QkNaOVBVMFU1aFluQS9LeU5DcHVpV3ZtOHlTYXpSUXBVQXJ4UXAzY3V2T0o0?= =?utf-8?Q?zp2I=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac137464-518c-4b74-da2c-08dd04ff18a6 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:03.4053 (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: eTGBBSplcryIC1HMs5mNKXcuLd5/dPYTzyA8lUDtilA3NVu2Olygw0363iYd+HcJ0O7PYMmqGUFmvbvQmT3Dhw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB9967 Introduce the helper function pci_epf_align_addr() to adjust addresses according to PCI BAR alignment requirements, converting addresses into base and offset values. Signed-off-by: Frank Li Tested-by: Niklas Cassel --- change from v6 to v7 - new patch --- drivers/pci/endpoint/pci-epf-core.c | 39 +++++++++++++++++++++++++++++++++= ++++ include/linux/pci-epf.h | 13 +++++++++++++ 2 files changed, 52 insertions(+) diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci= -epf-core.c index 8fa2797d4169a..a3f172cc786e9 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -464,6 +464,45 @@ struct pci_epf *pci_epf_create(const char *name) } EXPORT_SYMBOL_GPL(pci_epf_create); =20 +/** + * pci_epf_align_addr() - Get base address and offset that match bar's + * alignment requirement + * @epf: the EPF device + * @addr: the address of the memory + * @bar: the BAR number corresponding to map addr + * @base: return base address, which match BAR's alignment requirement, no= thing + * return if NULL + * @off: return offset, nothing return if NULL + * + * Helper function to convert input 'addr' to base and offset, which match + * BAR's alignment requirement. + */ +int pci_epf_align_addr(struct pci_epf *epf, enum pci_barno bar, u64 addr, = u64 *base, size_t *off) +{ + const struct pci_epc_features *epc_features; + u64 align; + + epc_features =3D pci_epc_get_features(epf->epc, epf->func_no, epf->vfunc_= no); + if (!epc_features) { + dev_err(&epf->dev, "epc_features not implemented\n"); + return -EOPNOTSUPP; + } + + align =3D epc_features->align; + align =3D align ? align : 128; + if (epc_features->bar[bar].type =3D=3D BAR_FIXED) + align =3D max(epc_features->bar[bar].fixed_size, align); + + if (base) + *base =3D round_down(addr, align); + + if (off) + *off =3D addr & (align - 1); + + return 0; +} +EXPORT_SYMBOL_GPL(pci_epf_align_addr); + static void pci_epf_dev_release(struct device *dev) { struct pci_epf *epf =3D to_pci_epf(dev); diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 5374e6515ffa0..20f4f31ba9b36 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -238,6 +238,19 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t = size, enum pci_barno bar, enum pci_epc_interface_type type); void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno ba= r, enum pci_epc_interface_type type); + +int pci_epf_align_addr(struct pci_epf *epf, enum pci_barno bar, u64 addr, = u64 *base, size_t *off); +static inline int pci_epf_align_addr_lo_hi(struct pci_epf *epf, enum pci_b= arno bar, + u32 low, u32 high, u64 *base, size_t *off) +{ + u64 addr =3D high; + + addr <<=3D 32; + addr |=3D low; + + return pci_epf_align_addr(epf, bar, addr, base, off); +} + int pci_epf_bind(struct pci_epf *epf); void pci_epf_unbind(struct pci_epf *epf); int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf); --=20 2.34.1 From nobody Sat Nov 23 01:49:04 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|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8?B?dW1VSWZkcnY0NDY4d0s0T2c1QzM4VkUzMVdCNmlFdVp6UVJWSjJQU2RVTGEx?= =?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?= =?ut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V3p0MUtnVG5D?= =?utf-8?B?N0hqRmNtR1FKODBHSkZORWNpdXNGWkNla0J1YkNnMDRNTVRDNzd4MnN4SE9r?= =?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 From nobody Sat Nov 23 01:49:04 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 55F881B3956; Thu, 14 Nov 2024 22:53:12 +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=1731624794; cv=fail; b=o8r0SViS3wzswqVbVfbZg/ysOpRQ2yTsG8lZR0azDJAnusZ6oKUScQ+PpTu9JNgt1eSgPkAfdQTH/R/BUEZHUMmi8h5/IiQxoMAbUAiOG/Q6zhs6l6S65BJtxDIyNQpWVNcTTZrNtc7fozZa1caCuO7pPAz5ASkTk6UFmRBQyIo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731624794; c=relaxed/simple; bh=QTWqCilF4zeHBfeRMKTgOmEbv94DuAHrD35HEjvlft8=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=MmrFHOMoVPzb+CL8W550xEf+ZDrJghKtBhmCCMlO0znDPK1oWrCXSSGYCP6wK31r8sBgkf4CYl8JYkMIPd1Y0vToEnrleRUW1WjKH5QUKUCnmhCK+1yw2JVcIFDuTkSYOXbjq/YdoRMcSxOEaXInP++RZ/2kz1ikZ6sm9JFDh8Q= 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=mf5hW/Dj; 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="mf5hW/Dj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=X0yHbBgcPQsW7keSYSozGbjb+AMbFgIXm+1k2q4NQiIlrUxQCUsw2n/fiuCeifxIC7YLAbwmzWg5esUexuGBl2M8WBOAS3cLzr3vljeyNaJhwJc79tCG/tNJY8GKf8R0XepQfJ5SmK4sTZLCjjkHGpFThmMCYB1eKW9Bb5annUe8AQh/TVjLi4ClmpNX9azH3LZ6gYbHlz34CPVZp0dcpj8gLk/62xRJNqsvAV+kgv8dqWHV4r3p0IRzbKQomuWpt4wBFYZ5WQ/XppaWunmdr3VgW9XOGuNVgHYUXnrpDSTrSO9D/f8TqQFnR9mJihiuOxKrEn/n+EyJjAQiLyFyEA== 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=95seh1SLCdzbaMMMU9WaEBSdML7dm8hPVr5F6qDIHEo=; b=qmdJVo1AqDAlnUlI6jFTsr3RPFud+rapsDtn2eXL7Mev7om1reFWqqCZZ9r10PFamcLbdL2FW7sJiCem9l62uikpRAaITE9QcK4CfrMl44kA/o31FRHsF72gV12GKVSN3PMg0I7/HTTbiIO+APR1II5EK36PIVCOW0R03y7ZgEuyTdrAw3MrBJMrdFI7mgJUpYdhdwHinzH4hiIntVfTx7oVHx76GK91BSAym7L/jFoFbI31n7NY+Gv++3kYkoz9Z5v6oPjdj9SuDSyxYrInEJ/Kwj0suzt0ljulKcKeVLwlQ86hwcWjMwcBb+mT9h1q+5LtxPurwC8Dn36XhJqlPg== 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=95seh1SLCdzbaMMMU9WaEBSdML7dm8hPVr5F6qDIHEo=; b=mf5hW/DjQ894C1SKRhYNjEtp/zPi6XEEX/KwBfcgMQv3VuQYI4P/LgNc7HuY8CHCzSoZS8lQkSZajjRNkxS99swXZpmsU4IJ0nh/sW/3bNst9Ua58rbyfa7bqPlsNh6tjHiGT1OG5WvrKOzhPBT8DuXgH68+elCYGK8Gh371k97yFZqAnEAkiPvgT6wU3YL5IdoaGmxnA730Ip85hDxkSyhzcAECpX9FLQptA07DjCXACcR3ex5Z533c8EB310GYmzm2wofzwWIuHqtnYIPvinA7nrOJROAbpX1vAz+Iv1IUbdPdKLM6Z3K44BElCwkEVmEBzhlQ7xZS8sVRgn5maQ== 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:11 +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:11 +0000 From: Frank Li Date: Thu, 14 Nov 2024 17:52:41 -0500 Subject: [PATCH v7 5/6] misc: pci_endpoint_test: Add doorbell test case Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-ep-msi-v7-5-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=5527; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=QTWqCilF4zeHBfeRMKTgOmEbv94DuAHrD35HEjvlft8=; b=A4qJoTr2gXtOiudcsj8dKulpIdx+DfKQ+rWaDyuzLoFSoZaT4JDWva4fMaYuIzJiyyQgXdqzg NOGm9dE9jptCj/oJEEj/RKt/QQoAuKuN86K2ha9rRENdhNfvW4EEarV 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: 05103112-3b53-4e3a-6a9b-08dd04ff1d1e 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?emMvcFczVkVwQUxDdG02M2cyWXVHUVB4SjN2MGhobkJyZWJyRVdqMFcrYWtn?= =?utf-8?B?WkpGeVBzd2NJWmYwWjB3cXptMnorY3piSStyNkI0WkcxbkZteW0rOTltS1Q4?= =?utf-8?B?NlAwM1A5a01qQkhZZkMwVUhNNUJFMVNPN0l0dUJJL2xTTW8rMHlCZi9WZWxC?= =?utf-8?B?NHJJRFMxcnl1bExUaHBoZ1JXd1BK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FJT1lLUU9VenBnWXo5aDJPeEd2SGxMV0JEeXlrYTZ3Y0ZvZ3RGZGs0?= =?utf-8?B?WDNYZ3RYZWF3KzRhTkhQWXZ1b0ZhVDNNMnNLWG1hckt4UWxaZ1NLSUlUZ0dv?= =?utf-8?B?TXY0Mkpub2ZYemVXOTl4c2wvSENwK3VINFRNbEJsdTk3V05SWEtrTnJRME9u?= =?utf-8?B?eW84ajRVa284VDJUeFMvWlIwWUl0Zmh3RjBxTHBlY041QmhpNXpHOGlhWHVl?= =?utf-8?B?ZnExRzFyYTRIY0FraDk5TWdGYS9NYkhkUGQ0NlNidzhvNEFVWmdiMy9CQVdJ?= =?utf-8?B?V3QxK2I3NG5WRzd0b0VuUEpyazJzRVF2OENaQmtzS25rQncxYlorbkNUL2t4?= =?utf-8?B?NitrMmVhS2tkdEVlaXRHQzcxZmYxb1FyZzA2RHg1MkkrREdVOGx1Ymxjc0Zw?= =?utf-8?B?dmRhb3BmSEQxUWIvbEdyMk1ybTV1SklrUjc0bXpLTnE4K2d6VkgyOU9PZ3hF?= =?utf-8?B?MENycldvT0RpaUNUQjE3b1hYS3BZalpWeHBUUXZIb1FJaEdxM052ZEd4UVhM?= =?utf-8?B?MU90NG5vcTRiMm1pNFdHV2p0MlhRQ0pydVNQNFFESG1PdjA2T0tIZHEwYjY4?= =?utf-8?B?U1hKUWJ5Nmk5MnNhZjdMZHdiMnNYSU1BWm9adXRNcFg0WXd5cmxQT2R6WXhJ?= =?utf-8?B?L1hYcW9qQUlIaTlRTmZsSjhKMzB3YzZKaE0wdVJzRUliUDF3Y0tZbDNseitq?= =?utf-8?Q?j3ppu2emZI7ogBhIcFMHFxrOGfhhE/lTGYgIM=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);DI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5NzVlWlBEaWRxZGNnVjJVUjlQODN3?= =?utf-8?B?bnZiMktFQWJBZGtJMFZzY1RIZXhiRXBGVDN6Rk40amZMZmlQMVVzVkY5Rmh2?= =?utf-8?B?RXdrT0NzU25sTUphY0pzUHBhQzVtQk5pYkNxb0tqakdtVis1M3pxWmFqU2Fn?= =?utf-8?B?cWlQUUI4TTRrMEU2MGJOeVpjMjlqTGlnOWh5d3haVlFGRHpSNHRMbG82ejJ1?= =?utf-8?B?YWZ4VXNleFNWZVIwZ1gxZU9xcWFOYTBadHpDU2ZqYVpMQlNJRFBOOHVzMGFs?= =?utf-8?B?YlEvRlQ4UlRJK1lNS0d5TDNJVlZYL2lheGp1NkROQnJpRmF1d05qWFdvajdX?= =?utf-8?B?TGNHelhNR3dqSU9QL1E5M0lULzQvbzMzSFZPZ0JIZ0o2T3cvbFJZaUltL2Ew?= =?utf-8?Q?CQgI=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 05103112-3b53-4e3a-6a9b-08dd04ff1d1e 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:10.9464 (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: aBUpvDhni6lNoHoLArVYorCmqZciuSLvLwUhX+zpmifXBZBm7C0j1SNifb8HDy3Nqvh5gdHAOqwc222KzX621A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB9967 Add three registers: PCIE_ENDPOINT_TEST_DB_BAR, PCIE_ENDPOINT_TEST_DB_ADDR, and PCIE_ENDPOINT_TEST_DB_DATA. Trigger the doorbell by writing data from PCI_ENDPOINT_TEST_DB_DATA to the address provided by PCI_ENDPOINT_TEST_DB_OFFSET and wait for endpoint feedback. Add two command to COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL to enable EP side's doorbell support and avoid compatible problem. 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 form v6 to v7 - none Change from v5 to v6 - %s/PCI_ENDPOINT_TEST_DB_ADDR/PCI_ENDPOINT_TEST_DB_OFFSET/g Change from v4 to v5 - remove unused varible - add irq_type at pci_endpoint_test_doorbell(); change from v3 to v4 - Add COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. - Remove new DID requirement. --- drivers/misc/pci_endpoint_test.c | 71 ++++++++++++++++++++++++++++++++++++= ++++ include/uapi/linux/pcitest.h | 1 + 2 files changed, 72 insertions(+) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_t= est.c index 3aaaf47fa4ee2..dc766055aa594 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -42,6 +42,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 PCI_ENDPOINT_TEST_STATUS 0x8 #define STATUS_READ_SUCCESS BIT(0) @@ -53,6 +55,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 PCI_ENDPOINT_TEST_LOWER_SRC_ADDR 0x0c #define PCI_ENDPOINT_TEST_UPPER_SRC_ADDR 0x10 @@ -67,6 +74,10 @@ #define PCI_ENDPOINT_TEST_IRQ_NUMBER 0x28 =20 #define PCI_ENDPOINT_TEST_FLAGS 0x2c +#define PCI_ENDPOINT_TEST_DB_BAR 0x30 +#define PCI_ENDPOINT_TEST_DB_OFFSET 0x34 +#define PCI_ENDPOINT_TEST_DB_DATA 0x38 + #define FLAG_USE_DMA BIT(0) =20 #define PCI_DEVICE_ID_TI_AM654 0xb00c @@ -108,6 +119,7 @@ enum pci_barno { BAR_3, BAR_4, BAR_5, + NO_BAR =3D -1, }; =20 struct pci_endpoint_test { @@ -746,6 +758,62 @@ static bool pci_endpoint_test_set_irq(struct pci_endpo= int_test *test, return false; } =20 +static bool pci_endpoint_test_doorbell(struct pci_endpoint_test *test) +{ + struct pci_dev *pdev =3D test->pdev; + struct device *dev =3D &pdev->dev; + int irq_type =3D test->irq_type; + enum pci_barno bar; + u32 data, status; + u32 addr; + + if (irq_type < IRQ_TYPE_INTX || irq_type > IRQ_TYPE_MSIX) { + dev_err(dev, "Invalid IRQ type option\n"); + return false; + } + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, + COMMAND_ENABLE_DOORBELL); + + wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); + + status =3D pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + if (status & STATUS_DOORBELL_ENABLE_FAIL) + return false; + + data =3D pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_DATA); + addr =3D pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_OFFSET); + bar =3D pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_STATUS, 0); + + bar =3D pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR); + + writel(data, test->bar[bar] + addr); + + wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); + + status =3D pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, + COMMAND_DISABLE_DOORBELL); + + wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); + + status |=3D pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + + if ((status & STATUS_DOORBELL_SUCCESS) && + (status & STATUS_DOORBELL_DISABLE_SUCCESS)) + return true; + + return false; +} + static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -793,6 +861,9 @@ static long pci_endpoint_test_ioctl(struct file *file, = unsigned int cmd, case PCITEST_CLEAR_IRQ: ret =3D pci_endpoint_test_clear_irq(test); break; + case PCITEST_DOORBELL: + ret =3D pci_endpoint_test_doorbell(test); + break; } =20 ret: diff --git a/include/uapi/linux/pcitest.h b/include/uapi/linux/pcitest.h index 94b46b043b536..06d9f548b510e 100644 --- a/include/uapi/linux/pcitest.h +++ b/include/uapi/linux/pcitest.h @@ -21,6 +21,7 @@ #define PCITEST_SET_IRQTYPE _IOW('P', 0x8, int) #define PCITEST_GET_IRQTYPE _IO('P', 0x9) #define PCITEST_CLEAR_IRQ _IO('P', 0x10) +#define PCITEST_DOORBELL _IO('P', 0x11) =20 #define PCITEST_FLAGS_USE_DMA 0x00000001 =20 --=20 2.34.1 From nobody Sat Nov 23 01:49:04 2024 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013010.outbound.protection.outlook.com [52.101.67.10]) (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 30B231B4F32; Thu, 14 Nov 2024 22:53:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.10 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731624798; cv=fail; b=frZXUZGxgYNLms5WdibHTL2KbQuHyqi7sGCNOThU3o+c1Bc8j4MudfYsgCFysdWgPSqOw0fYfEJx2QrUwWM7UNKDWxHSkdxs42JiA+RNxjJmH9Hqmuwho1TyJ7L9QESpP4XXsOV8vGT3pkJBjvRGUJYLVua2IuK+5hWk1B818UE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731624798; c=relaxed/simple; bh=oknEewV2xVMtzJTDODMiOCPDBkOTwQAdC4P3/r2BxdI=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=gZNb/lxh9R+NdRquq3uKpSvjOzZTKPri8feugf7MpAxODW/i3fM9JDXkaUTZoiYtiKKqvxrCzIWPqcEIXdZFi0NAysLH3f+R/tMG+fIypCN8iJZtsU9pKnuUvg4UL2WGLuT9QfVIjJJQDisXf97LjYwGR/XuNMSzu12LDXQYIuU= 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=M/q3eAz5; arc=fail smtp.client-ip=52.101.67.10 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="M/q3eAz5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Bim/R/MIQz3nQD+OPU6mZEsrHczy/f2NNb5+5/g55MNV9dN70P1WZTELW1Dmfp0sv2Kgu+lzeECL7kjWpVP2STQtiXW0mLqyKDUpLHiEC4Z3jiPJfRsy0BZ2+DwdqI5OAQATHfl0E5bXD9STY0XbfTTuZu4QZh/0QUjq3oszqX/PCVg5NZsWSyg8Y/fb15MEhAwWzA6ErdZ2LXbQA2nm5y6/laqFrn+qFtyQCC2WcBUtbWqnhDJ6lLwFW0CXuDzhtPDOoOgauHf19tV22GnrwWX/0FKCLBGqU6r6bbAzn4nk9h1DbTie4D/IbT8RGO9fzt072GDBIuIlhzjKmB8CgQ== 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=S0okuXE5bsrRrOlA41c2rexmWqw6sMQqJ3MoKe+r0Ws=; b=JdwaH6aogcLvESBeaAM25AWtLfkINg3ySUAq8AEFjD2V12lNvqNbCb7hL3hZq4bGeT+pv+U0z6FRO1vJwXgJ5RY0Xry7OS2YpKt6p9mInrlDS6kOu2u3s28y3EbsoFCufmM1kChktjk6nA3ozEs1BRokiJV2sAAkp/unp8uVn+OCqsBCX2QVo645g4lu++/O5vr7uKbn9e3uBIcGdVjXuNz7xJsBzxaITuqDUT8lYlz/LBPyw5ZRTzPvjCHQKOSC3NgU/eS3R8ZSFff5NyndKKk5x1BQvG7nervZw4CjppWY3bwp+io/iX9TEYJXyUEOvDJ0paJQQ94s8vTvmDn+pA== 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=S0okuXE5bsrRrOlA41c2rexmWqw6sMQqJ3MoKe+r0Ws=; b=M/q3eAz5CMimhbmjhfobDajo0uxzV2UlLUikN9RyLJ+COn2pOvivLi6e3rEpNDHF/RvwoXYgfpr4XpMUfBAQXqx0Y0mqHMeKBB5OI+aF2oLbKA1qQaZmQHxrx+zBiivOusl7RFANlAF1SN7DyRhHMgoDje2upyDoP7oZNPchUtYq5RNoOPPaLdm5BEBKj3fmBChGEjR1CQxaBrjV/mYk8xIE4Mfk+Mv3tojHCds71NwpWhCOaK7rnJmm3IoJ9po97+z4qlKnAFcxtrVdN5RwmVYxvJjFWmqI1/ckEhqbmr4qWF0mwOkWifPN2zyvrK/eqi/UWwjIA15NjjFPoOBEXQ== 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:14 +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:14 +0000 From: Frank Li Date: Thu, 14 Nov 2024 17:52:42 -0500 Subject: [PATCH v7 6/6] tools: PCI: Add 'B' option for test doorbell Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-ep-msi-v7-6-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=1850; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=oknEewV2xVMtzJTDODMiOCPDBkOTwQAdC4P3/r2BxdI=; b=9k/vJr6UUB9pNZzPDpHLHIM0mezAXfMKXbugs9YpjsSgJjN+MFI/oSSFlf5lys+74e3Jkh3q9 k9Yx5SJu2KlBdklaDsa/tIv++BjhbR3QETAJ6uEYExaTrc2CCHrhExi 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: dd25aa24-1480-4fb6-0de7-08dd04ff1f5c 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?TnhOQnFOM09DcVF5Szd5cWMwU2s5MGsrZG9zalRwNmJPcjlkYjJnR3Z1ZlJK?= =?utf-8?B?alVxeFBnOTBWUDNLSXV4b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ront-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?SXYyb0R4RGhYNng2VjlJZHhaeko0T0RyMWliWEZESmk5MVhieW5ON2F6WHZq?= =?utf-8?B?Tzg4aHEwci9SejFJMlFGRXBLdys3MFlqb3hjdGV1N2ExWnNOeHNGcEs0c0VN?= =?utf-8?B?a0MwQkZlOHJlUjl1cmRmZ0hpenVING9WVVpZQUR4cEp2YlhmNG0wYUI0eFBF?= =?utf-8?B?QmdxbktpL3pLQzdDQWt1R0xXQWxYNk5zTndaWjF3Z0s1QmFNamNWY0NRRS9y?= =?utf-8?B?SlVUbGt6b0ZyUnc5OHdVYlJvOFBVYlBaMmhvSHkvYklWQW9iU2l6KytwZjlJ?= =?utf-8?B?RlpNNEc4dXFwTUlRa1MxbGM5VUY2V1gzKzgwL1o4aGJRN1JKMzNNTVJGZnh2?= =?utf-8?B?eEJucHVOZjlyREtEYnMrQ3BLQmV0djdRdEkzL2ZWcUtwYmxjU0hHU2tIREJI?= =?utf-8?B?SDhBU05oNHpLSDRUaUNyV3Y2Q0p2QXFDNUJIWHpLOVlMZ0I3LzhUcWVYcnhF?= =?utf-8?B?YXRDT1lHSTQ5SWdCZmxHWjZUZnBncjJmNVJDMERCaEM3L1FzVW1KOUJyVFFZ?= =?utf-8?B?L21zODlrVXlZempkdHkvakljeDNRWmdxcjk2MHdwekdVOHREWEgwSjhES0Np?= =?utf-8?B?cThIYzhDd0FVNk81OHFhY01tR0lmc295OE9xSHpoOVR1c3pwRlF1WDFNY3FH?= =?utf-8?B?ZHRBdldlQmNObkErWVJ3MWRXV0VvbG1UVnhPdkhHM29vN3Q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Sm43WUM1bDh3VXU1L0ExK3V2QXZ3?= =?utf-8?B?bEZPc3cxNDM5c2pQMExGQm9BMWEyVmY4Q3RsU3ZuNU9rRWtXZDdqRTRYMDZU?= =?utf-8?B?MHJFRzlwVS9DV1NaYkt4VjNJWEFwbzZSSEdHM1BNNjRVb1lQd0VRN3FFeHlz?= =?utf-8?B?cUMvN0JNVnBpQWM0YlNSYXhQb085c3BXUFJYekpmZmhVZWJKMlFpRytBeC9y?= =?utf-8?B?d2RuN0dDOVJxVnAyakhVS1kxU3Z4VFNmVnJpU3RDL01raVFZbVRGSzZrSDJ6?= =?utf-8?B?TlNKdXNGbW9Pa1NPRlkzc2RmYVA2NUZ1Qi8rMEpCRHFFZVIrVTZiakZ1emFh?= =?utf-8?B?THBmRjNMTGhpVjQrVUM1ckt3N2FnM1NrMkdRYmxRRDdSM1ZvN05aMmtGN1Za?= =?utf-8?B?WjBYcmgxKy93SmVTWHFQS3ptcW4zNWtyWFQ3RlVlZGRpVXE1MEZHS01KZ3pB?= =?utf-8?B?Tys2cmtqa3lRU0xsOEZWbXdtTjRTcit0ZisvYkwvTHUvQ29TMjVHdVlJK2dk?= =?utf-8?Q?PnZc=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd25aa24-1480-4fb6-0de7-08dd04ff1f5c 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:14.6983 (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: fzELQ5OxVBQ+sNN5x6IdbyW3SK/GY8pkAy+pficpgLFMmkux3sy+bBMYljvJcWCVqeBtin3/3hJp0xRd+C/0Aw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB9967 Add doorbell test support. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- Change from v3 to v7 - none --- tools/pci/pcitest.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/pci/pcitest.c b/tools/pci/pcitest.c index 470258009ddc2..bbe26ebbfd945 100644 --- a/tools/pci/pcitest.c +++ b/tools/pci/pcitest.c @@ -34,6 +34,7 @@ struct pci_test { bool copy; unsigned long size; bool use_dma; + bool doorbell; }; =20 static int run_test(struct pci_test *test) @@ -147,6 +148,15 @@ static int run_test(struct pci_test *test) fprintf(stdout, "%s\n", result[ret]); } =20 + if (test->doorbell) { + ret =3D ioctl(fd, PCITEST_DOORBELL, 0); + fprintf(stdout, "Ringing doorbell on the EP\t\t"); + if (ret < 0) + fprintf(stdout, "TEST FAILED\n"); + else + fprintf(stdout, "%s\n", result[ret]); + } + fflush(stdout); close(fd); return (ret < 0) ? ret : 1 - ret; /* return 0 if test succeeded */ @@ -172,7 +182,7 @@ int main(int argc, char **argv) /* set default endpoint device */ test->device =3D "/dev/pci-endpoint-test.0"; =20 - while ((c =3D getopt(argc, argv, "D:b:m:x:i:deIlhrwcs:")) !=3D EOF) + while ((c =3D getopt(argc, argv, "D:b:m:x:i:BdeIlhrwcs:")) !=3D EOF) switch (c) { case 'D': test->device =3D optarg; @@ -222,6 +232,9 @@ int main(int argc, char **argv) case 'd': test->use_dma =3D true; continue; + case 'B': + test->doorbell =3D true; + continue; case 'h': default: usage: @@ -241,6 +254,7 @@ int main(int argc, char **argv) "\t-w Write buffer test\n" "\t-c Copy buffer test\n" "\t-s Size of buffer {default: 100KB}\n" + "\t-B Doorbell test\n" "\t-h Print this help message\n", argv[0]); return -EINVAL; --=20 2.34.1