From patchwork Thu Nov 14 22:52:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13875705 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 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?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=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-pci@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: =?utf-8?q?IQtx8+cNzbVWPTWLoke8KzRJAFkkrHL?= =?utf-8?q?lqKJFGL3NoDluIvDPSi5yBjcvfAyFfdgdYofCxMTb0ufxWoVuIAyF+23fpsZTTKn4?= =?utf-8?q?47KOjYWBEG3eBuIoLLRLhqKSysKsc1d6qHdNkv4y/NutGoIS4HcOdzjLB9za3I1d8?= =?utf-8?q?CPkx/fAIoERpZlJz9uxkVr96PEr8+vHq8aDGLdomN+rtwSSGtknvJ2t3rS+6FE4R0?= =?utf-8?q?GHelvpgU4hTXb7TZ1T8NsMYEFT1vN9E8fSeUhJghWmGr9uG3OOSo8usTf7H3a69PV?= =?utf-8?q?YOSfuRFtHEbXLXrou9f3/p9n5stgAIgikVBK22Z371/c0iFSaZ/M8+O/4Qq2tu/2D?= =?utf-8?q?SXSS4dT9lzvPeosaxXZmaaqhyM7u07Vk7JoxnYzvW0pNG3rJLbhweR1j3i2gLleTh?= =?utf-8?q?HlRKiMwtyntoRDWiXqu2Sdl+9K6cDZCinwx4YpIKwf5E4bAngDUFpGiR0uLfLQ7GM?= =?utf-8?q?mEzIv95+svEZQie21veTABJ324B7f2APKgX1Rv5IrQTTVbHmVPIIL8cwFBKNCe2oc?= =?utf-8?q?pb0D+hOeEwKcwn1zxjOKDIQm9BmM2fFgmrSaLORA/EpwhDOyolHUy672W9yGx1LZn?= =?utf-8?q?OPGXfRXn9pts5dWOJTAJv3jICJLFG8KEDJWApv31PWeID29q9X72Rmsyacvn8MlTX?= =?utf-8?q?WlZnY3Y+nSSW7E/YxZEoOAhpDZ8etWucFpYdhLrl5XK9p//TysnVIVYjULt5uzNT6?= =?utf-8?q?VdUK4A/oRPHDwzqEmOr6BGYR1AAtazzCzFGRaOWlYdHuDFrH91+drlr2Z/GD3cj0Q?= =?utf-8?q?hFsLRBH/M1qNSOYFSMjd79cmH1nnlEjtoVOQoICOvwKc4F/pmiaQ1FQZaCGISz36C?= =?utf-8?q?OVNCpUeqzBRVe5QOIWdB7dEGI7pa95JsmLuv5HeZCELayQlUr6oNZT5G8CU5hIGoM?= =?utf-8?q?ge/irzpQEGkbJIg3UNujwFrVtzxdodBZDWCak91V6dz0Ii0Wv2mEja4yrN8Mrcu9S?= =?utf-8?q?eqf3zwBWQWUdercuv2EwSRNQC1iPpH8Tu0bXOrSs6idrnlBy85Zzk5G5ybUN/Wi8Y?= =?utf-8?q?TdHkFq3OIb2b1Sri2L0XZAfpKLvX1IsAaThBM508kq5fxsBCBHQCR4Vxqe8Qt8DHI?= =?utf-8?q?HfLmUg2KwKxarRu11hBPvMO1fyKXs9RCDdNPToNadSTUxb4xfvnx3M2JfQBrR/Ryp?= =?utf-8?q?IgWl/sOyLlidF0rurkhqU4GUkjASGHwUACQ6n5f4cMfPZ/uFRIhdM5qCcKlR9yHLs?= =?utf-8?q?BdmwQKumYOtWfzknOD0JCZczohkWskIyloWUup7xdiDyVkDqA2HLLjOCDHQGwR9ne?= =?utf-8?q?yJrnB1haT4S5f7hdnW5juPRtZ/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?q?ueKFCd+8U2u5yqOyaRvDm+OKhN1f?= =?utf-8?q?T0CJd5a3oR3UbNM7Lr5Gh+K/4AMIPptQXk7oGeN1bKYqMvvsZRSAArl7kvr3nHVjN?= =?utf-8?q?kJJdgnmL1gXs9JJBRZMirahwPANbfxMlf9/nbYP/IcU+5ab/hl1j8FgkLBbVySsus?= =?utf-8?q?P0EPZaf95lPt4Ew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YpkcQzhNMlfZcbxfbrer0kHubplSbPIbs6A?= =?utf-8?q?M2A5qDudhc8xA/XLq4G3i/ICLN3cx90mxnxvZq8AivLC0sPToJuWm1IcY94mKUGRN?= =?utf-8?q?sJwcUqaVgXmLUA1QzPYsiBgiKfFAdI31wP+PfzVFevKbRLfRdSx6tyuU8tvwmI4sT?= =?utf-8?q?tQETt2U0rOfjgLy7tneMVCy6UtzaUGL6bBh81PYcNnOZ0YsUdGBn8g0xRMjkBPAhp?= =?utf-8?q?kKGtzrNQhNdE9btEB9EFVCQ4kZrUXgRpCwPakruWfWpO006YYheXX37o4jkfOgJJU?= =?utf-8?q?kMFVYj111NfkUAlCrof+bwo3Zs1VTSDGKvN1Qty1LbQNU6H/JBLSlaat1yR7SY/qv?= =?utf-8?q?yRE8M88Uf9Zxw92rIJrZ4SsW0DnpPcdOK8FIheP7M2J9CF24za5r+TcCP340uV85L?= =?utf-8?q?p2+M0thf+UrSpyXjIwcfKdXjY1OD0jo8FKH27N/I9sn3IOHh0UMWI7Ik=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); +static bool pci_epc_match_name(struct device *dev, void *name) +{ + return strcmp(dev_name(dev), name) == 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 = -EINVAL; struct pci_epc *epc; @@ -64,7 +83,7 @@ struct pci_epc *pci_epc_get(const char *epc_name) class_dev_iter_init(&iter, &pci_epc_class, NULL, NULL); while ((dev = class_dev_iter_next(&iter))) { - if (strcmp(epc_name, dev_name(dev))) + if (!fn(dev, param)) continue; epc = 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); /** * 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_features *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)) int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t base, size_t size, size_t page_size); From patchwork Thu Nov 14 22:52:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13875706 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 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?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=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-pci@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?q?lVvDS6Mctf+/VXuXEzhuIXPvN1y3sVC?= =?utf-8?q?KcjbNHB+0JclhsrMVAnrSvrjnbP0zUrgyDPdySO8biU0zdHaTPU6/CmxC3ZpSiBHv?= =?utf-8?q?/97uupx9Bt4ns5u8O+GZDpIzmQxZX35vxrb3M+pf9sRvQ5CIbATFMMBt+hLBwAoPh?= =?utf-8?q?I0pmNvBIcyWH6IP5Vd7OYu09UMRIsn0o03ekaa3fTUIngTslDb+Q9r//a+85Gp3X5?= =?utf-8?q?uP4wL1VMZ0aj4Xu+ILauTHW/BIkEyx0XVmx2k3l4eZYd8AtGgxjtCiROuUGpbf+JQ?= =?utf-8?q?1PE1XRaawybxtMA4z7GLnkUfFY7iCqlPcU6mTVlsA9GeQ4CnDrPIqJS1h2hFArY1c?= =?utf-8?q?jmL+B32xmCK0Ryp+fKj6GYTnvEnGlnXf2DnKBvZTAgt1tQ45mYJpz8znUuhkqb8M2?= =?utf-8?q?ciXWQkJKJomNJ437gejXgYlUmn2NNTMfb3iNjHSUO/YTKQwYIlTQC+RNVM+2SBLkD?= =?utf-8?q?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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?q?ktEi261V5feoYyv9kd/jvKzcEFEI?= =?utf-8?q?K3M7QnxHAk86HuEM8tjL1ib4rt4+u6ATDyv9GxmPWh3HZz7ltnwKLkeYugHpYtpOi?= =?utf-8?q?EtGT2dPjwXNxm1TQW+zBwbKmVyMxjsRjU2ksWwRrcGTY/OJatjTBRvtnOhV6V0ICm?= =?utf-8?q?yPgjheMcCu33cirNHn6fvXxuP5fA0QUa5szwNPfZSs1450cAmoRnQ3aAJW8r8PiAj?= =?utf-8?q?QIgMtexLhPA5XIHYSW58C5b6i3O4hroVXQoksyzPXfBPGh/Dnhe1xMwFDHg5e89xh?= =?utf-8?q?o4MJYLjNt5/4hmIFDAXqLDbMeLQ1K7gbkWlwo0tUruG7dltd0O3XAi88GxuqDUgHG?= =?utf-8?q?vrK8t+OT91O5hcdfDlZyTn73B2XMpI5clLXadc70CGAXMv/1SVDswJjRgG+D0kduj?= =?utf-8?q?Tq5A6M8F4JmnyLFGSQvdjJv0bFih96FnrexlIL45SgGK7EoztR3vmjALDXX6EEh9u?= =?utf-8?q?Gppu/G0QcJbqMN+OzDbnQPQyANCLpjhJQQ57oLUjM+DoJfY04FdNinRaak/FJYPoU?= =?utf-8?q?ITueWsfnX1o5GwUMcgJYr9lhWKmmOa+dkPEBS52a9MX0rD4PxpweIPFXW3vbybnyY?= =?utf-8?q?eE/mE1i838FwtbnedFT1bye4CumbRCqLjYCnw5HMf3pFC81LZS3knsF0nVSF/o5sU?= =?utf-8?q?xLRdiv6uIchb4RNeme5aYHvR7CWORj+9vyhASMteqeJZpk64/uv0xKO88aDCTZ+r7?= =?utf-8?q?ed98VHlk+RetUcMjla2Nxsg/bFdzOGLXwaBhNGUrAD/FkyiRQFknKytevmVysDBO4?= =?utf-8?q?VXaB68VxtaDqCf6XUiU8h+knB4k28xsSzPRYG9Ob6NrsUSRac7abS13EUbPsRoBVq?= =?utf-8?q?Ea9MsQWcPkX2xrOuXBhDZ/JtVoC5ehbJpjUxAa0iqhBhZ1cGqx/e9xyxCc7QxgQIv?= =?utf-8?q?m1QC0wn5IF6Hj62G/MHzJumPcsbuiSG7Sc4lG2yfDIvlEoy6vKRZNprM7/4fFAJHC?= =?utf-8?q?SSwYUD6Ca71yswUgqZw4+Y8Hm1qCH/Fv/Lt+ybPMUNiVbtJcKh0AI16zFzj5clGfk?= =?utf-8?q?vBQhHpwYywog2B5XcpYnnIpaIqTgblInAhRKZ7U8uxiy2MswvCwg4a05rAeDW9F9w?= =?utf-8?q?9ss1JPk3bZuOX2Wz5ID0xNsq0woxPlbLVd2wfPYouP2avoDWw/KixaGuAQwG3ENbc?= =?utf-8?q?R6WQ0+tRG/UKvySgKeGZ3vYnd3DQZ8cItYxONN+wdn7CtG15MqtQY93q1CaCzf+dd?= =?utf-8?q?aLu3jsUEAYwv0G60ClrPq0eIPfrqpRqC3KxyWTOuu7T9sAAE7daCqnanWvV/rl8aT?= =?utf-8?q?2WZz77f9okXQpeMEAY4aiyp2hrNbDfFpvtDNctUe9sesiVKBESFn2aFSuUK5MIvks?= =?utf-8?q?QOVhh0cGBKyL+ZcLLYXm2eN1uYL8Ta7nuV63uw4LJJo6n0foKjViCkx2LU7omgkY0?= =?utf-8?q?izocW2gk5rTvbR3T+Tkp02LSRGoTYIqgdNwtS8drjFabUOFfo3mvYCTWgY2wTIFah?= =?utf-8?q?iEoW8iHRmQFP1QfgLk1zUDdF/4HO8lKFIikaY33DmWoc5HglIZsIdKV4=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 @@ obj-$(CONFIG_PCI_ENDPOINT_CONFIGFS) += pci-ep-cfs.o obj-$(CONFIG_PCI_ENDPOINT) += 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-ep-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 == param; +} + +static void pci_epc_write_msi_msg(struct msi_desc *desc, struct msi_msg *msg) +{ + struct pci_epc *epc __free(pci_epc_put) = NULL; + struct pci_epf *epf; + + epc = pci_epc_get_fn(pci_epc_match_parent, desc->dev); + if (!epc) + return; + + /* Only support one EPF for doorbell */ + epf = 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 = epc->dev.parent; + u16 num_db = epf->num_db; + int i = 0; + int ret; + + guard(mutex)(&epc->lock); + + ret = platform_device_msi_init_and_alloc_irqs(dev, num_db, pci_epc_write_msi_msg); + if (ret) { + dev_err(dev, "Failed to allocate MSI, may miss 'msi-parent' at your DTS\n"); + return -ENOMEM; + } + + for (i = 0; i < num_db; i++) + epf->db_msg[i].virq = msi_get_virq(dev, i); + + return 0; +}; + +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 num_db) +{ + struct pci_epc *epc = epf->epc; + void *msg; + int ret; + + msg = kcalloc(num_db, sizeof(struct pci_epf_doorbell_msg), GFP_KERNEL); + if (!msg) + return -ENOMEM; + + epf->num_db = num_db; + epf->db_msg = msg; + + ret = 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 = epf->epc; + + pci_epc_free_doorbell(epc, epf); + + kfree(epf->db_msg); + epf->db_msg = NULL; + epf->num_db = 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 struct pci_epf; @@ -125,6 +126,17 @@ struct pci_epf_bar { int flags; }; +/** + * 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 function * @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; }; /** From patchwork Thu Nov 14 22:52:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13875707 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 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?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=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-pci@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?q?XBbZ6YvcDEsCQGXYKtTPmd2k+mKNMFn?= =?utf-8?q?9bnHLtHoS3OMwSMH2P0EziLQQgowo6MdTi8BAaNLUQ4T4R2kwgqjmBnRE5eCEdZv7?= =?utf-8?q?UX1cFOfKFOtZXP1XPKf9tw3SDxwB9OAPpxW8+41SZ4mU0STbZyi1jXVlvlkp7GTzF?= =?utf-8?q?9jPWAl7nxsyxfmVVW08/pukeWhzXmr5qyZRQ3RGlIZTD0pyFAG30wff7nQgsldKoD?= =?utf-8?q?kMi0mryD3uNDz3A+1kLNSCh5kgVuuRoOpU4ubA+Qjh+6TAkEVxa9Ntz9EgMX+Dpkd?= =?utf-8?q?6lyHLrxfvfFbGUqY02KmxvYG3k3aBvD9xQp5tTmHx9gsS3/gf4nqkI/5Y+nqCKND3?= =?utf-8?q?AAq9JSGB6hbZZBsJTX95mPN4Mv6RUayvBmPQkei87S1YSIwYjpPnKPV2t9sDLk6Ia?= =?utf-8?q?ClPI0Mv6wIx1Ew+ZgjoPd2KsDL6HoHQ6zvGall1fyrfeGNgubebC4TGYX4jjMLsWF?= =?utf-8?q?F/uUiJXjdTlPI4tx19cMk/bnia9Uzu7mkiPbTnh32PgwlMQUqT50/2ATqF4YYdfYM?= =?utf-8?q?BwHPpkCWxtzO6rXoMLcdAkcRLXRf2LKtR1bWTQp4lFKrZXuwRpxWk88iWpK10iyrz?= =?utf-8?q?QcOgjTTcOmg79T1HauJZbU48/REv9jJVv0B/aeNh4YzONyHSizlME9FmdwslKc6Qw?= =?utf-8?q?K0hQWevaO42vLmUSQVbY97kwGnZLBGwAzb8S/DeZNzVYKipWim+0dMBLM8+4MLLgs?= =?utf-8?q?HsdiqYcOvJoOLTWrCeKQJvXdiTnd2+asEwvLIzI7uVE9l5vbLuXFf7eJVaX1+Wwd7?= =?utf-8?q?pKpanq4rMazpcn5JJtw4i2PfOrroJGyelNfLO0jQHctvxuGSRxyfBT4NjANmiZt8T?= =?utf-8?q?qE0JlbepaChk0PyFC1C8obfKDr2X/qkpU5EYycfpmvYjW3vfVRjJm2iEGP1Fiw8e+?= =?utf-8?q?bp5BSrjNWCiL1uifJsHZp2YTQD9n/Is8IHO4VmFY4+m/hDdI+BOdj4VVLnPCJwYAC?= =?utf-8?q?+XWtOBodn3BblApYsJcQd7QXYIhYrPuBDIRv3qohhrTKa1ZppgIyh4Ur4Mr91A9nU?= =?utf-8?q?ls6ORXDbmiyqEb1mKP/+TUc7v2fA4VSS9wupmtPq1QAHPqD0ZnQnjAjldNfZqJdWn?= =?utf-8?q?FUPWxKGAJ99Vzwp3a1LmngXTxX7oLexuhw7fOmmN/d5N1W+1g/fiHqYOzS1fRJ2Os?= =?utf-8?q?JlbRpvB3T3bzRv1BSjG+YxC/tmOTXqi7yHiIy3PTIMTB1frYPRVdnkVzHLM2ETGHs?= =?utf-8?q?t2n0Jruwc5qfhGD+PZj8QBZiTZYq45x5TEKEeZ+eHeAYX4XZ4O5/gc/kdkAY3rc3k?= =?utf-8?q?hHSMcP8SQSbBb5dVkK2xUka5+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?q?noF2B37YZgvVaffHV8xF1OXtdvsR?= =?utf-8?q?HR24Q6EqGZmts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pXP7TkFdRi1nswSFhFefwqth4aX1/Gjo3YV3NphxIe3x?= =?utf-8?q?zJreHbRDWCPx3Vr3VTXRjc8TgYGFKdJQUbZqLsHzHKuYubY6LRHflN1Z8kMrxVo2S?= =?utf-8?q?EUUkAvMiO23isYRqxCH9oS+P4ZzqIOZF5hLOLTSMWYEC1TJCIkpdgALohcp5eaLO0?= =?utf-8?q?9IMiV1cNVK3rF0fLYFtDNU0QPrM26mlAVHX1m++uIcfvFVW89AIkFGxIHmwyGqrWf?= =?utf-8?q?3hUJyhsiWOjK1iApmUdj7y8jz9EkmzUwes3uMswB8NiFOoa1gB9GEMCK0g55ZoA9O?= =?utf-8?q?a3x1H4re0FYpbOKHlm7rHLprb9GirJD/TJaQaw37ddyCi0zyrwnMuttMZwYc6Unbo?= =?utf-8?q?yH+Kc70E3l21FFZHLeDUVPvPTAliNJhK5drqiPRBjWnrxNJXuaXtv1esudGTB89n/?= =?utf-8?q?S63+E3dCjrHuQ3rBEAmU4PgT5DXbjgm2TsnAE3oQsFrYxsp2vf8bHW6k1sBDjbLyb?= =?utf-8?q?Mb1LUoJKYVtVHyf2Nx17KXq+cH9dtD5ZwfMxJd2/wzSSRAW5x7aPHOI8wkIqt0ERi?= =?utf-8?q?kgFbageBCZ9PU0U5hYnA/KyNCpuiWvm8ySazRQpUArxQp3cuvOJ4zp2I=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 --- 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); +/** + * 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, nothing + * 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 = 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 = epc_features->align; + align = align ? align : 128; + if (epc_features->bar[bar].type == BAR_FIXED) + align = max(epc_features->bar[bar].fixed_size, align); + + if (base) + *base = round_down(addr, align); + + if (off) + *off = 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 = 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 bar, 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_barno bar, + u32 low, u32 high, u64 *base, size_t *off) +{ + u64 addr = high; + + addr <<= 32; + addr |= 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); From patchwork Thu Nov 14 22:52:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13875708 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 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?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=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-pci@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?q?HSEsZG+mQjznb8QZSGNMxYrynSe6qf0?= =?utf-8?q?vb4QliSIzkYk5pOGy3f1ftvrF0QWCcv1jQog18/KNN2WBAUH2bT+zBeyn9sFjJuZh?= =?utf-8?q?t8mhsgr8JZ31tyKOJlyzHTe9gVe9WUIyIoCSMlk0BS12oc/qHkJq1Zw5bSDfF+psm?= =?utf-8?q?NWJrWNvZNYcE/QzBYPif/2L6VTGxlyv6bir+7l86pnZLjYSVNNxkETtRwb7KpTuPl?= =?utf-8?q?qMS8qgWh+6rlZn9D5JG9rGoDCMk3iGBB6SdFg4TI47atOLqbfgCIcpScdjlPGlBPI?= =?utf-8?q?pkzdiRUfvefW/KgDzfbDSI/oKe0/UOMT40aq4C4udQn1tjQJKs3iT6Oyake6DnU9V?= =?utf-8?q?sfqJiixYrYsWm6kG6CCbRoRmk9wO6b1R2+IewzRcOv4apbCEyNMhp8mPqxrTj95oi?= =?utf-8?q?y+v1q42D5qeAahv1dozhZkgOnf4NSngrNjuy86lCgKaSKjLB5bRzOza1qn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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?q?HAk4zuW3SteQWkBFf5bWe6T3daSR?= =?utf-8?q?zYEvYDZ5E3Xc49VFHiJ81PM86UoQajcqacIzent0CUHsJhRkfZczqYLPmkmTlkXM4?= =?utf-8?q?z+J3kXXD4vM56IvAHMK2Y0QKkVC/h0zrHlvhqeMGfFHZTqcy9ghqdTWSpQLBRxNoe?= =?utf-8?q?fdZ2ICqrFlquLtP95uN27cdjPITpID7nDY4y85ZCOiVorDb8N4lC6IB5djmj6sXeA?= =?utf-8?q?7CwToZzG0BS/3uR0MdanPXcFYXtqgozy7gAs/ojCqU+AxY95lN/N3eh+eUFtVU3RD?= =?utf-8?q?u6IukhUdNhR0gnM299TqD5ZfY+41WlbKDf2WktgY5bOM0JuXvn6NHPxJ3A2gkaSY6?= =?utf-8?q?Vw4CQlW6lJsqmXpVI8TSq2d/jWHcGZFdYR4b6ltdDxuZ8WiC4WwVNftEJBHZCblnX?= =?utf-8?q?lz/9JevoT1+92EIm7MxA7AOuMH+ILHh6HegYjNpyyA0SQz66Z+vEwHfBLzJ90LN8G?= =?utf-8?q?j6BhBuTRbVP/DMNdOnV+fMiEB7PcOIKWsT+yynZFAV/WhwW4lpsQ/ZJOwG3EuxVkl?= =?utf-8?q?kOS6Z7eIPiOKPKiTY5hGFGg4V5XAa9Z6HW7p/0XKExXzS6zBlzBg+cjSigHdUr2W1?= =?utf-8?q?Kz5fnoCvFP1Ulkfmcb2j4hfqEd8lHJdG/GzBLro3oAjWgYWU2sN9u4emoIqh/4lRs?= =?utf-8?q?JJxwH6DdLDW+qPUxChdOMYR7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25f5d4d-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/endpoint/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 #include #include +#include #include #define IRQ_TYPE_INTX 0 @@ -29,6 +31,8 @@ #define COMMAND_READ BIT(3) #define COMMAND_WRITE BIT(4) #define COMMAND_COPY BIT(5) +#define COMMAND_ENABLE_DOORBELL BIT(6) +#define COMMAND_DISABLE_DOORBELL BIT(7) #define STATUS_READ_SUCCESS BIT(0) #define STATUS_READ_FAIL BIT(1) @@ -39,6 +43,11 @@ #define STATUS_IRQ_RAISED BIT(6) #define STATUS_SRC_ADDR_INVALID BIT(7) #define STATUS_DST_ADDR_INVALID BIT(8) +#define STATUS_DOORBELL_SUCCESS BIT(9) +#define STATUS_DOORBELL_ENABLE_SUCCESS BIT(10) +#define STATUS_DOORBELL_ENABLE_FAIL BIT(11) +#define STATUS_DOORBELL_DISABLE_SUCCESS BIT(12) +#define STATUS_DOORBELL_DISABLE_FAIL BIT(13) #define FLAG_USE_DMA BIT(0) @@ -74,6 +83,9 @@ struct pci_epf_test_reg { u32 irq_type; u32 irq_number; u32 flags; + u32 doorbell_bar; + u32 doorbell_offset; + u32 doorbell_data; } __packed; static struct pci_epf_header test_header = { @@ -642,6 +654,63 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, } } +static void pci_epf_enable_doorbell(struct pci_epf_test *epf_test, struct pci_epf_test_reg *reg) +{ + enum pci_barno bar = reg->doorbell_bar; + struct pci_epf *epf = epf_test->epf; + struct pci_epc *epc = epf->epc; + struct pci_epf_bar db_bar; + struct msi_msg *msg; + size_t offset; + int ret; + + if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + msg = &epf->db_msg[0].msg; + ret = pci_epf_align_addr_lo_hi(epf, bar, msg->address_lo, msg->address_hi, + &db_bar.phys_addr, &offset); + + if (ret) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + reg->doorbell_offset = offset; + + db_bar.barno = bar; + db_bar.size = epf->bar[bar].size; + db_bar.flags = epf->bar[bar].flags; + db_bar.addr = NULL; + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &db_bar); + if (!ret) + reg->status |= STATUS_DOORBELL_ENABLE_SUCCESS; + else + reg->status |= 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 = reg->doorbell_bar; + struct pci_epf *epf = epf_test->epf; + struct pci_epc *epc = epf->epc; + int ret; + + if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) { + reg->status |= STATUS_DOORBELL_DISABLE_FAIL; + return; + } + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf->bar[bar]); + if (ret) + reg->status |= STATUS_DOORBELL_DISABLE_FAIL; + else + reg->status |= STATUS_DOORBELL_DISABLE_SUCCESS; +} + static void pci_epf_test_cmd_handler(struct work_struct *work) { u32 command; @@ -688,6 +757,14 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) pci_epf_test_copy(epf_test, reg); pci_epf_test_raise_irq(epf_test, reg); break; + case COMMAND_ENABLE_DOORBELL: + pci_epf_enable_doorbell(epf_test, reg); + pci_epf_test_raise_irq(epf_test, reg); + break; + case COMMAND_DISABLE_DOORBELL: + pci_epf_disable_doorbell(epf_test, reg); + pci_epf_test_raise_irq(epf_test, reg); + break; default: dev_err(dev, "Invalid command 0x%x\n", command); break; @@ -822,6 +899,18 @@ static int pci_epf_test_link_down(struct pci_epf *epf) return 0; } +static irqreturn_t pci_epf_test_doorbell_handler(int irq, void *data) +{ + struct pci_epf_test *epf_test = data; + enum pci_barno test_reg_bar = epf_test->test_reg_bar; + struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + + reg->status |= STATUS_DOORBELL_SUCCESS; + pci_epf_test_raise_irq(epf_test, reg); + + return IRQ_HANDLED; +} + static const struct pci_epc_event_ops pci_epf_test_event_ops = { .epc_init = pci_epf_test_epc_init, .epc_deinit = pci_epf_test_epc_deinit, @@ -921,12 +1010,34 @@ static int pci_epf_test_bind(struct pci_epf *epf) if (ret) return ret; + ret = pci_epf_alloc_doorbell(epf, 1); + if (!ret) { + struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + struct msi_msg *msg = &epf->db_msg[0].msg; + enum pci_barno bar; + + bar = pci_epc_get_next_free_bar(epc_features, test_reg_bar + 1); + + ret = request_irq(epf->db_msg[0].virq, pci_epf_test_doorbell_handler, 0, + "pci-test-doorbell", epf_test); + if (ret) { + dev_err(&epf->dev, + "Failed to request irq %d, doorbell feature is not supported\n", + epf->db_msg[0].virq); + return 0; + } + + reg->doorbell_data = msg->data; + reg->doorbell_bar = bar; + } + return 0; } static void pci_epf_test_unbind(struct pci_epf *epf) { struct pci_epf_test *epf_test = epf_get_drvdata(epf); + struct pci_epf_test_reg *reg = epf_test->reg[epf_test->test_reg_bar]; struct pci_epc *epc = epf->epc; cancel_delayed_work_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); } From patchwork Thu Nov 14 22:52:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13875709 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 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?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=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-pci@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?q?zc/pW3VEpALCtm63g2YuGQPxJ3v0hhn?= =?utf-8?q?BrebrEWj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T2TxS/ZR0YItfhwF0qLpecN5Bhi5zG8iaXuefq1G1ra4HcAkh99M?= =?utf-8?q?gFa/MbHdPd46Sbw8o4AUZgb3/BAWIWt1+b74nVG7toEnPJrk2sEQv8CZBksKnkBw1?= =?utf-8?q?bZ+nCT/kx6+k2eaKkdtEeitGC71ff1oQrg06Dx52I+DGU8lublcsFpvdaopfHD1Qb?= =?utf-8?q?/lGr2Mrm5uJIkR74mzKNq8+gzVH29OOgxE0CrrWoODiiCTB17oXXKpYjZVxpTQvHo?= =?utf-8?q?QIhGq3NvdGxQXL1Ot4noq4b2mi4WGWjt2XQCJruSP4QDHmOv06OKHdq0b68SXJQby?= =?utf-8?q?6i92saf7Ldwb2sXIMAZoZutMpX4YwyrlPOdzYxI/XXqojAIHi9QNflJ8J30wc6JhM?= =?utf-8?q?0uRsEIbP1wcKYl3lz+jj3ppu2emZI7ogBhIcFMHFxrOGfhhE/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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?fgAYNK5AGjYOEhfZcVPCxh869mbM?= =?utf-8?q?1CbvppcSbHn7pU4I7dtrzWE2v1OY7piKxibDhcB3KMPjZMUaDF+IvCCO9Z2Kl/UOm?= =?utf-8?q?Cpp8A8PHN8Od5OcL595ADSByKAjcgqGmokxpsYteEXLIeb13Qx7fQR8Tj25yoJZsB?= =?utf-8?q?QqeSZ5wOg4HuO0sxtcAq4d8LgPyM4NqlM+0Vjd7uyDMRyiw7yMXy9NojXHouVVe93?= =?utf-8?q?QCd3/vEhhmkRUBWACAnyIq0CZJsi2vZjoCFM0qlE5uLpcO69yXlj3z8JN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f-8?q?kwAE1bsESMWvZbo2kxE9p0j7edAhpGJdIFwhqovML2k6fAyq/W2CZqbxtJKgINlc0?= =?utf-8?q?3zacIattzRf+hfwx/rSCy75eZPDidqdcgV2UR9P83wnvb2KEAbAdkI0VscTHexbEp?= =?utf-8?q?FT3zFN4jfLfiP1UsVF9FhvEwkOCsSnlMJacJsPpaC5mBNibCqoKjjGmV+53zqZajS?= =?utf-8?q?agqiPQB8M4k0E60bNyZc29jLig9hywxZVQFDzR4tLlo6z2uafxUsexSVeR0gX1eOq?= =?utf-8?q?qaNa0ZtzCSfjaZLBSIDPN8us0albQ/FT8RTI+YMKGyL3IVVX/iaxju6DNBriFauwN?= =?utf-8?q?jXWoj7WLcGzXMGwjIOP/Q93IT/4/o33HVOgBHgJ6Ow/lRYiIm/a0CQgI=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_test.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) #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) #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 #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) #define PCI_DEVICE_ID_TI_AM654 0xb00c @@ -108,6 +119,7 @@ enum pci_barno { BAR_3, BAR_4, BAR_5, + NO_BAR = -1, }; struct pci_endpoint_test { @@ -746,6 +758,62 @@ static bool pci_endpoint_test_set_irq(struct pci_endpoint_test *test, return false; } +static bool pci_endpoint_test_doorbell(struct pci_endpoint_test *test) +{ + struct pci_dev *pdev = test->pdev; + struct device *dev = &pdev->dev; + int irq_type = 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 = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + if (status & STATUS_DOORBELL_ENABLE_FAIL) + return false; + + data = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_DATA); + addr = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_OFFSET); + bar = 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 = 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 = 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 |= 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 = pci_endpoint_test_clear_irq(test); break; + case PCITEST_DOORBELL: + ret = pci_endpoint_test_doorbell(test); + break; } 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) #define PCITEST_FLAGS_USE_DMA 0x00000001 From patchwork Thu Nov 14 22:52:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13875710 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 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?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=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-pci@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?q?NxNBqN3OCqQyK7yqc0Sk90k+dosjTp6?= =?utf-8?q?bOr9db2gGvufRJjUqxPg90VP3KIuxl20WnvDs/DqfPgz/C823bqMeTsXavW0cC2Fu?= =?utf-8?q?ZgwKK4ZkwnnKWORQIw+8OkLFcvUkEoMH7mRMsIyq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ESBOJb5paeRxZvcGg3Y?= =?utf-8?q?/E/T2swLUMr1QKf/sXKfYkh2q8bKMeN6z3ZoQaraRd8/fh+oiJ2U7tfr4/p64FB2Y?= =?utf-8?q?22jqMFJybu91s/mJVFlFUaHPhZFZbmjVGAxMA2I5+LbXOaX3Fcpdn1qS5DLItG6Cg?= =?utf-8?q?vfFNRZTNaci02jirojvgQGPHQWaADY2YngKccDQ90cjttyS9J3qOnd0j38KZRzmmS?= =?utf-8?q?sCdQqCWTsnqJgF4GbNzJa77D5xz6rpirvVRG6IDmmprhFF+fGA+XndVes9DhPNuHS?= =?utf-8?q?yGOlkDbRr+XxaBccuZBHL/ALBUtWfoOj7vQrhBg/Ub56HiHVP52PKba4=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?q?Iv2oDxDhX6x6V9IdxZzJ4ODr1ibX?= =?utf-8?q?FDJi91XbynN7azXvjO88hq0r/Rz1I2QFEpKw+70Yjoxcteu7a1ZsNxsFpK4sEMkC0?= =?utf-8?q?BFe8reR9urdfgHizuH4oVUZYADxpJvbXf4m0aB4xPEBgqnKi/zKC7CAkuGLWAlX6N?= =?utf-8?q?sNwZZ1wgK5BaMjcVcCQE/rJUTlkzoFrRw98wUbRo8PUbPZ2hoHy/bIVAobSiz++pf?= =?utf-8?q?9IFZM4G8uqpMIQkS1lc9UF6WX3+80/Z8hbQ7RJ33MMRFfxvxBnpuNf9rDKDbs+CpK?= =?utf-8?q?Betv7QtI3/fVqKpblcSHGSkHDBHH8ASNh4zKH4TiCrWv6CJvAqC5BHXzK9YLgB7/8?= =?utf-8?q?TqeXrxEatC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3IXApo6RHGG3PM64UoYPwEQ7qExysqC/7BMVpiAc4bSRaxPoO9sp?= =?utf-8?q?WPRXzJffhUebJ2QiG+Ax/rwdn7GC9RqVp2jHUKY1SvxTSfVriStC/MkiQYmTFK6kH?= =?utf-8?q?2zNSJusFmoOkSOFY3sdfaP65FuB/+0JBDqEeR+U6bjFuzaaLpfF3LLhiV4+UC5rKw?= =?utf-8?q?7ag3Sk2GQblQD7R3Vo7NZ2kF7VZZ0Xrh1+/wJeSXqPKzmqn35krXT7FUeddiUq50F?= =?utf-8?q?GKMJgzAO+6rkjkyQSLl8FVmwmN4Sr+tf+/bL/Lu/CoS25GuYI+gdPnZc=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; }; 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]); } + if (test->doorbell) { + ret = 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 = "/dev/pci-endpoint-test.0"; - while ((c = getopt(argc, argv, "D:b:m:x:i:deIlhrwcs:")) != EOF) + while ((c = getopt(argc, argv, "D:b:m:x:i:BdeIlhrwcs:")) != EOF) switch (c) { case 'D': test->device = optarg; @@ -222,6 +232,9 @@ int main(int argc, char **argv) case 'd': test->use_dma = true; continue; + case 'B': + test->doorbell = 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;