From patchwork Sat Nov 16 14:40: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: 13877605 Received: from PA4PR04CU001.outbound.protection.outlook.com (mail-francecentralazon11013004.outbound.protection.outlook.com [40.107.162.4]) (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 BFB0C5227 for ; Sat, 16 Nov 2024 14:41:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.162.4 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768069; cv=fail; b=DZIV5oupa2KhTlsUaR5J1DR1aq3n5jhVJndpMORAcTFdWfHhtRgJH84/VJJYrKeL/7rOadqNPVIMxnyt/f7DPhQwYGYz2mjLXoqMRJZGyFZMIJPA9k1hIngAGhqXrBNqgbE9gieDsS0oJ+ztqgwmU8jHsRrNIpBldmxMxYalCrY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768069; c=relaxed/simple; bh=ddQJGOgVqT+GFgYeTaZpLu0yEfEdWMMFBmUhAfO/2D0=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=LlmeOxYBznLWpm/c/1HE/BCUtHLqskP7Mf7FD77lPAhDLT6JitatuUumeVo1u/WsgtUp8fgpriVHphENMe/TV+WVIKzjtg9oClI1nqbup34ONbpbsf5LscAFP/DW7v4aQnBeJurY3Vqhb/TKhU0Cfz+rt2LuJfe1AevZ/Y5UIJE= 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=Z58OAdVb; arc=fail smtp.client-ip=40.107.162.4 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="Z58OAdVb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=s2expSynKsyytdb4fzV5R6TB15t+hBvwSnaNC0om07ZalP90VWum1MgCW3VYz1Z7h9r5JV48UA+Y8Nn0u75lDEnd/oSc6haQ/Dbfkg8dc+qGsXSHW5XV3w2Hs6/CmcJIDJKXxPv4GwGu8lqFcyjRLQyHky00a5giAKvynRSleGRcc3SCVs3UirGh3TrsYbqz0tdqqGmzS9Mbuuq+HF3tX72aQm8x1RlDUu1hJ3YCZ2PfHLZw5dcHE2/gbnRCoZ28lPCF8DXUgDyQV+44EFykN9hcwEwgYYk7Evt4rubW/GNjTeESs33KXHi2tuuwEUf247e/reMPnqx3Nic/MzTRtg== 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=uuDh6IPej+1IZb3dyW/IgKJh0HGNgajYdvzA9re1UFo=; b=ZN+ErnvkayKuYasKjNFcO8kI2DEhDu4k0sZQghaTL8gXCw1uB/T7v7e4YfqFZx74xdxrWpzAckEi5T/wYHrs5A0sOuawhUiu0LSFG9WjKD2jahej723VT3F/sJkNDZ9R79cY7P989g99nQuPKCX3UFvL2Ljz3P50Kc/LsnR1DjCSvVW3lFYHyZDH/91vl6EfFKdyVUhmXlkNjFsy8jP5XIvHjEsDJHcoWcRsQsfKHqFWgUDjMNojyuhghLbHZD04fCVcFxxUdnl5G7UHsNadgsTpy221YqRXWRd409rxtnzqAn44LI/5BS/ihXJBLQww4rjxB1WMjJQjBWZcM0r73Q== 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=uuDh6IPej+1IZb3dyW/IgKJh0HGNgajYdvzA9re1UFo=; b=Z58OAdVbyeK8UF+6CkzovPGv0cxJ4q+AWg5wxJZ6aJ7pzj2tqlqOIQfDbdJ5wwsi3zZ2H0l91PStt8pQBM4krq3povx1pQdhSfeJFt+5DoCtspCGZCRIJ2yRkPOlDK9U/ivWwxuLCZKvrP91IjDOMEYoSu7wOqoCDVqRMk9NKiS2R8VGMu8PF+4IbE9xMeMsw2VU1sIE7/p77L6YAcONi2tMpj+1q+PKyjl9RrNI3MXOj2bafDaHpG83qsshJJ9jsIj/jFlGXIwj4ifJ3+5J7re8Gxeruzd7XkGRhbQDAPwKuda4qUykWze34J3vf2eDvhALqaPAGf4UNSqVXy7/Lw== 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 AM8PR04MB7265.eurprd04.prod.outlook.com (2603:10a6:20b:1d8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.21; Sat, 16 Nov 2024 14:41:05 +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.8158.017; Sat, 16 Nov 2024 14:41:05 +0000 From: Frank Li Date: Sat, 16 Nov 2024 09:40:41 -0500 Subject: [PATCH v8 1/6] PCI: endpoint: Add pci_epc_get_fn() API for customizable filtering Message-Id: <20241116-ep-msi-v8-1-6f1f68ffd1bb@nxp.com> References: <20241116-ep-msi-v8-0-6f1f68ffd1bb@nxp.com> In-Reply-To: <20241116-ep-msi-v8-0-6f1f68ffd1bb@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=1731768057; l=3147; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=ddQJGOgVqT+GFgYeTaZpLu0yEfEdWMMFBmUhAfO/2D0=; b=dXe9DHNGqYLK+qXJ2TN3yOPspSfJDJxkPRLRNRLERHxH8JKxDZSImzBlBlcstbyHCxB/ouU5p zH+un8sDzAvBfsES4zxwH9bSQbt1JkFhgWGdEwcasiQtoECyDcdeMHD X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0210.namprd13.prod.outlook.com (2603:10b6:a03:2c3::35) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM8PR04MB7265:EE_ X-MS-Office365-Filtering-Correlation-Id: 1f56f913-096f-4c86-7a71-08dd064cb31d 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?BSSNLUGHKvtnxnvWsxWfYL5rpDWI8Jg?= =?utf-8?q?a3TKNj4vhmRcKswdePg0ys+fJY8lXBYIOE31M19wLXrWOVGoary6T0cjvx2K8hNIq?= =?utf-8?q?avjuFlZsGCZLBbJoMxtpZvDkAmq8JJ5r1q5gPbk2ESfVd7KWO/8RGpbLFz9rjM8Xs?= =?utf-8?q?wBHDxRlwcIOl4ERyHeSKyXRkCdncjaV320vGSswBzbWWIGb2fsXX4qGdunIzss24d?= =?utf-8?q?com69vmLSWrdGp2OPCpOXSCNJjKupTXXaWKEjlMKmR2YPO4dwxNQGipQzzs9AD6ji?= =?utf-8?q?S3aNTkGtB67Zlq3SzO9FDzKx6q3QCaFg/NIZe98xwsAq03AELwOHoazTY3ov330iB?= =?utf-8?q?O+1NzmRhxO5iM70QBIk4l0vZcDvJMyzTx5gnGhaVv25vnMJYw2VkwAw5Qg+8JUXjH?= =?utf-8?q?GDfYzSjZDpuhIByZQNvvLU9NvatcjW7HNpoOn/ntKQSQ0WMBnyq+EBvNORM/4h67T?= =?utf-8?q?dnq+ne8lI0qxs3Ax5QJpWpMmZR7cxTrfI0w/2hiegKVUnHu/rKm1bLItoxvaoeh2j?= =?utf-8?q?H7EjJpZgB+KtBFN/19dBrV+MItQzvxUau7EjL0xt5+15TMlTtWNMIAAh1nfiyhCid?= =?utf-8?q?wPdK+iQMqkjB6FW2kfkr65nU1yd7oY69FOvB1LoMOIXqLDrEztzyAN6h3KFkg8nIm?= =?utf-8?q?RVxKkFQBwa6cgsKM4sUBiptEpp+dkhINFtUL3JbQPEVor45TDrpywWZjOz1KNA3Ib?= =?utf-8?q?vlbE605k6UQreGDlIv32/qgx+DkL/qnuYQxhpthTJVc6BcMUd4qHKrqfljsBa1teB?= =?utf-8?q?oeOOU6Ag+NK44zSwHQ54eFKMm+eP4FF+ySeqLweffEhflDIetvYZUgOWStHWSI6cl?= =?utf-8?q?G1mb/izSWA/G68+nz8lgu8Dmnmh3RWz34PnhU4ntdJZPMWmSytac9PZYuRfJL/JWm?= =?utf-8?q?LPWur84NigvBXMeN57jMbjowb6wlpZvf8abHSD81SteReNMnDF/3qgRSGAFi4ulwh?= =?utf-8?q?k6hBhNbIQC9s0fXPS9FMBEk777Kez5sROyPr6mtY7hY0Vutz1vq29TwfLk9tmizec?= =?utf-8?q?j8EQAwA9eJ0XKOdx5ZPIBp4bRq6BeGB1xaJT9LCSRQ3bZ6+GyxUJCi0UjBvlGml3i?= =?utf-8?q?YkJECy10zfqP/Mvix52aLjF//ahz+si41/bLm28ZqSUVaG2TKO2O6WnPQQy8F3W4v?= =?utf-8?q?n9CQGaRKyHFsOBqf/o3fgFkPDD5Kvo6OQItZmRbZE1hiMowhlkQRpBEKeOJpqc14N?= =?utf-8?q?GVm/p6+cNpj0vQSG0xsBTAIzZfU2AEaiElmn+e4VQaCWdtzskfO4EGLp+6TRP4Cs1?= =?utf-8?q?K2uyuHzMkf+s8JzWl45Riz8ynxCVAZssPDo3RF3cy3YU/6wI6KG84H1I=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?LMkH5y0NLu6u+dd2VqvQQEKpJE2q?= =?utf-8?q?yhW8ajwdIfTJ1iUwCi7+DgXeZCUQJj58uT7qshetuk9JcKGUazAuVG7k60GksSsfM?= =?utf-8?q?94ge2P5R0oFPxybu+erj4wuzMZPcKGm7qM/iL+MD35jgG4RaZlY/ZfjeaBcTP1K+F?= =?utf-8?q?zWIAFEbkVDuz7tsscjTgMoqn/k2O8MmlarYLnvesqcIxSI97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ToDKLjRtrFrs+etUXAo?= =?utf-8?q?Rlz6MUg+A9cK3iH45Vf2Au0RRDAgr7LKvi250phCqMnDTcCOVS6yGewVATmKyyVw8?= =?utf-8?q?1Pgzzs+58CBx6/xE/hXnBRdqb2/egTiwV5jL6+SC4pHLlyGV+vpzcrobrf+WQF49K?= =?utf-8?q?GhmpAb+ObAJwdtiDoff45nDYLZl+C+HRjBR9X/SCz29p7vJRQFEdcZO0Ha4OU4O/B?= =?utf-8?q?22pDeK2XvSwjdOHauSFk6TsDSeILyKV/6QgJEEFDQcEbiUKBbUGybvZzzerquo6gk?= =?utf-8?q?vlxbjFy9kxFkYIhm4GY+fPWJaaGGABgtIXZqlP+bVnamSxjZuHluqrzvGhuHXWrwu?= =?utf-8?q?Z6cK+33W/0WGlxFest7b6vhyZgN93yfZnN1zzOAzKxpnPEF1RkuF6jSn+Npjowbg1?= =?utf-8?q?WXsW/2YE+w52DhilKNvevYe7ev2SdAwKDw8ssbqOyXa2vqppGlPvaxnQ=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1f56f913-096f-4c86-7a71-08dd064cb31d X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2024 14:41:04.9634 (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: 2eBvPdj+gRWFU5d2hJMWl5AILsfRaMWlyXQlR/I3HNLTAe+TMgFrwt7YNg/vlw5kRWtQeu9htdwW2wQATM0m3Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7265 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 v8 - 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 Sat Nov 16 14:40: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: 13877606 Received: from PA4PR04CU001.outbound.protection.outlook.com (mail-francecentralazon11013004.outbound.protection.outlook.com [40.107.162.4]) (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 2D2441C68F for ; Sat, 16 Nov 2024 14:41:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.162.4 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768072; cv=fail; b=HcTK7IXtqWPqJj59hyWqM0WigW1+xmHwM1WWjhcbRp83eiOKvFUC8zZIJlxvbd9f3rAP8FE78ivaLm/i8NjRY3R5n7u6MvNlPZjYgUW8yxiaR/iQm6E1l/vve2UZWMGwYPazN7h4hacA0aPwQytGY03EHUzS074OGzHno4p3TSA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768072; c=relaxed/simple; bh=/7Pai0goKHvPIK+tBY0qEDaD68qr8tke0aMwrO4/bPg=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=Jn8GzFWODKVVkfOElk+ON+XoEbD0xSIlIcKkESkNP8jPSp8BUnBj6xBjjY3pK69X8Xzwh+tElHmlR3gmdkpiIf8bXteoUevaIzqVUxPR/G8Nk1OlBqFRdnT89o8IXala0WQ9A/7CuDtMPhQcIRmS3XPcbKF70RSA/8zUNCTIQIU= 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=VYLo6CEC; arc=fail smtp.client-ip=40.107.162.4 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="VYLo6CEC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cG9PPusefQ5OmzuxUgymceolTmwb2bgqaYcJPBMg9qUJi6OSp8tfiIfuu9GWIh1QfWvVkdA3nOR2LLD2qf3yV07NEv3QCgIF3RWXRvZiqfCSAkPFlnNy8dLVjDOJZ10bQxopPaLH8tw+oWX+ahZWNlr4/iTv4MtyJ2grgqMPHKy1R9bHxXW+1B2y92SGt47QnliY7Tm6DsyClnY1FWB8U1vlSsBsy2zv7unbycILeketJdP2EBi49QXkRM/wyKChiku97UzNxEYPaMNhqI/NfBOXlv33Q96A3GE29FDvpLMp5oaWeCeGFo4LUbEsY0Duhnod46ad0nO+QaMe9P0FPg== 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=1sA9ZGGwKCFVa3/DR6CR6X7jz2TH0pu4avIrpxeaQ+U=; b=NL4KMSl8o1A2OcMzEKlRHwSd11bKtRQnXQKHMTEKhL/itMgJAQJVlAmjS9I6zZuzE/rLYaGtfwpf1EwUHcJbYroXG3fWJlLQfzEdbA9XZ7dl5l9+1O5GnODiwWGyWi7q+eXB3TqRiMx3+JGwuv/c/08Wsc1kE+tLfQbBCytqEpjtTt+qRAQK7jQwMKQUY8z1IoQs9VV6KMhDWK4qKkdyroVxbdRiIP6Gr8pVleRI8J0cMRsEsz4CpmIZBKjT80bX77ebuh2D04vzkqiiBkHBpKBRyg9qYSx2F8KtqNRWgU5VeV/6ZV+uDu2EkF1ZJ6BQh3L4HZdYTfJ5aUQHY1f/KA== 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=1sA9ZGGwKCFVa3/DR6CR6X7jz2TH0pu4avIrpxeaQ+U=; b=VYLo6CECcQITJTotF/xsVEFajkV1DBcCoae8tEgpnI5TG4qfWMq8ay+6N9+7rYpSWoVG2Ud6iiNGU4GJoCEBOxzfV7s2ocPlOOUwRKyr8HxZ9cnfLB2N1esJXqTBc7KcJHQVdtLwNFqfgm48WvRoQA9y5svcNyzjU1aKF7vLI2VIzOISdDb1OH5LvBLAOG4grmtma1ApRSjqsNG1x/ZLRSNtYAjhBlIRN5pmI8scxik9eUqWu4VtivzHNlaE5hIk1rt9tjDlM1qCNS0cr0iQY9vCz0lAwfK952r2PKISxH+gmoorL5RDUsQWKIxeK1gdgJkkRLLZVoy+0NvqgoFQrQ== 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 AM8PR04MB7265.eurprd04.prod.outlook.com (2603:10a6:20b:1d8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.21; Sat, 16 Nov 2024 14:41:08 +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.8158.017; Sat, 16 Nov 2024 14:41:08 +0000 From: Frank Li Date: Sat, 16 Nov 2024 09:40:42 -0500 Subject: [PATCH v8 2/6] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Message-Id: <20241116-ep-msi-v8-2-6f1f68ffd1bb@nxp.com> References: <20241116-ep-msi-v8-0-6f1f68ffd1bb@nxp.com> In-Reply-To: <20241116-ep-msi-v8-0-6f1f68ffd1bb@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=1731768057; l=6297; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=/7Pai0goKHvPIK+tBY0qEDaD68qr8tke0aMwrO4/bPg=; b=aolckxJBE7NIPP15dDaja5aOivqFX0rMvEJ8oN4Hfa2HiMT43Xbadu4x5MwNsXYQhI7hH5Bcz FOhmx3bYlXpCsw5gwKb0AWcFpsBYTJIddaRZFz3EOrNtMS612sVDdNt X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0210.namprd13.prod.outlook.com (2603:10b6:a03:2c3::35) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM8PR04MB7265:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ad3b6f4-3474-4720-7133-08dd064cb565 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?VYNLkNG/OtZCNgBMt+LFrCN0EiIB21e?= =?utf-8?q?oz8bh4nHwmZM8OMNfoVg9crq3aH4gSDVEB1z0PMSqLIj/oXlgpupFxJrm5aWSKbOt?= =?utf-8?q?yTCtHGN6pA+x7dLdL2cRMnLZN3huaukdp0r8sbBqyw4stM5Srsa2GnUCkZIk+gM3y?= =?utf-8?q?3wB4lFS0QH0MGXJgkSbl0oqPgR26rPsgWsxr6NL+itrHiIulcmUv9y7UWmiLuXYP2?= =?utf-8?q?OM4wwuaVxzKd4xjnZvkI9lDj4bQVUlYCvACU/MRXy/hIFjitia9jo04XYYYR25BmS?= =?utf-8?q?q9m9sv7GSIk4Jo/ouBEwODEl8EosFreb0jkX0WFhvyA2XbHzHOqvgk7F2nyI2pefF?= =?utf-8?q?RFUcXOEJ/tLk2Jbnd9zJNIym9I59KGZFTTIGPkF1c3e/kMmrIIJ8vyhmrKa0RmA7b?= =?utf-8?q?tQ52ePSsURK0EImt5h1QDDYj+NntIHyYMNDxPxEB3cX7TSibZS4/LkmH67iDW5lhm?= =?utf-8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=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?cX9fKJEUqh0ycMUymq8txwjhupcO?= =?utf-8?q?poVxGFYg2PIu9Pz0iLoEus3ENpVHgSIAfyjlhNI8zqhfImGqx4tA0q0WJMluPkw1b?= =?utf-8?q?/lczRzzyMncfpU7lGn209ComIwsSy49WlJFpw8cPWJw2Q90xWLw3iNKTHBdRagKA/?= =?utf-8?q?8ABzbtOIaldlXwyAEQFChOtVHw7TPtrB2HzAz4N0QCptgj/fkuC/olvuDgIQq8fse?= =?utf-8?q?+nYRiZg8H0127ZA1R731bwC0Uqgb4QXPpFtRmK+EPDRGseq3RVJkqTQFcd4phx/Eq?= =?utf-8?q?DVIYbLTmtA5+qq211EFUuMcwm3oAMA17fnI+RRH/MgIOwkn/aVHp36HKwuhbTTljX?= =?utf-8?q?b3XJ8CbMDKijKw4/EDYmlrhUmg/rDlh0R4KHuLIchWi9vWY+4LxBDF0KZBUS217Q2?= =?utf-8?q?++wOlMjo5bkGSab9qlXWDUkhoa8ZM3t+ZoY1QEzJoALYe5CF7JWayjCQAxsdT57yZ?= =?utf-8?q?p6tZj+RQPNFBq1rkrFOHgiHRbFJ++4DqaQ0H04vTa9CcwOEtZq8xQSk5hzxVwAmi2?= =?utf-8?q?7HwYuxcA4WYMTzuSKCMVCYmsAYeQCifiN378zFm809lDVumrLGsQOM8u4rFdhDJFU?= =?utf-8?q?pD4ndSvLuv3puYb6WbAYBILgFAWC/n2PmTTRivVV5DtWsZWDi2d4Ht5QwczgOx2Qs?= =?utf-8?q?qNZ1HVERFVocqbQXpdv3MkKvym5z8yVvc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3474-4720-7133-08dd064cb565 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2024 14:41:08.7943 (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: YMeSCH2ur+wcKpQgYegsA4kG8+vP5dDwZLlh5/jrzByZ3/iv1kiKQSVlaGRac9ZXA0tYhq5hNDj5w7jFkKdrdA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7265 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 v8 -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 Sat Nov 16 14:40:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13877607 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013018.outbound.protection.outlook.com [52.101.67.18]) (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 3DDAC144D1A for ; Sat, 16 Nov 2024 14:41:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.18 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768077; cv=fail; b=WnsSHF4XU2/WUSkDcAgN2FrWEDQ3zaBsVcyfV+QjW0ysFQU3ovah0LaU6srYcGFHN8HuI1uFX0xDhrHssl2+wXfhuHFFMq9hX0fGrFUiA809tJpgRUAChKbi9GGUZnClzwWAnMfkgcj7lI1UCLwutuURX+3kWyCfEUFa2yXYVlw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768077; c=relaxed/simple; bh=ALBAmWL9QxkgiZp6flstYazhrERZ/ebCU5ovpzJ3ESM=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=AnJ6EWE+Y7o6XrIK+oY5aYm+HAduj84CxlTIbthjjpDlst/sfHQEK3H44MW6mN/2LMkS1eF5W70KAWb2H37tFwjqcvJzuuiGSjDRyGlLelGlfXk+/cR8V/BIdy1mBxDWs3KuTi1Ma1nlan/XYXdsT3OQNwU2nW7jVHZz6WWSBxg= 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=GT4aJ7Zj; arc=fail smtp.client-ip=52.101.67.18 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="GT4aJ7Zj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Lt6Kd3TCWAxZ7fa6SKW3oP2rXFY42zpkGwnlXRIredkQwyZSFep+IAd5cjgS+TKToKE06XVxvNqY4mg+bqyneMEkHqh+ysuy67yjs86Vh8JAohpolGNtvRJRPWTyXOAkwAYzeIf+0uSm0Sf76ZQZWJAGzVl+ONUUWM/1DB9hoP6xLJz3+jAosmGk31N0+vtey7Jg1qQ2y5cTpqbptc6uJU931r7i9KE53gNwjHKqubCk7Q90PPzvK7ZeTYB8KRSn8wznLcjO5iosEe8eotPCu45cq/ieGmIfV8hk3Z4cxBC6N5kamLyVyFvttSzjnF5FlTw+7vw5uxhju/EQgs/q0g== 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=MY5/Xe0JHtvYAV4/rZwMg3zPMgkyu1iopPbYp02fQO4=; b=tTL44kJ4POM5JNokvJfO7jRYotlEKAoFxAvAqjzj36SyLzr/9ULqfZAu1hfIA9TqGz2MLYYmcynuFfxk2iRbx/WC1crRYelvtXHt1JdoxFItYsGpPKzuC/4dhhGpy+Ud+cyP2DfjmfbqCQuZSHbp7nWlHm7Ow6hlB9lC+kpzyGt8PCKhluFC4Y7VrRWUAaLu75XRZSmj58ngK+LzfXKv/RTtYYdAFFm3tH4PLdNzFGKvFYTzbUht8ZgbrfXaxjKv3sQBzSNRV/AQ4Nd7wKF+BNKka9i/iyjIf/aXaOvcx+Ig13OeUu4cysduSRGZ1bYl9OXo2UjWWXOqHncJMulhaQ== 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=MY5/Xe0JHtvYAV4/rZwMg3zPMgkyu1iopPbYp02fQO4=; b=GT4aJ7ZjVt7VuNYzLZ1Q2yuOBd477oXfQY1XItrIoPO7K9jW9ggWwRa1n/k0QMjZVieX2VMfXRJnD3qTQDNmxXz7mv3KvZ2sKsMUhoAPTgeqB2YKOJ7wxfFryXTVQ93oLqiF6ueVfy4mmt4MqqihjE0CLlTnBPJJJsuPUTAR5mxUAf0GF0OKUoIBvTNpkFPmJEtccRMGMNymg+RSLGi8vuIEQTLuYLxI3oZPEjtZy116FNwEPkZ743TFr7rcpjWRatk35EK+JnuDdC7C1pWXQNLIs1ttSVUskWFNXSQ6ud5cc2utBoY5OEex3U1hCX2G5pnkutwxHtHE88kLWqSe2A== 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 AM8PR04MB7265.eurprd04.prod.outlook.com (2603:10a6:20b:1d8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.21; Sat, 16 Nov 2024 14:41:12 +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.8158.017; Sat, 16 Nov 2024 14:41:12 +0000 From: Frank Li Date: Sat, 16 Nov 2024 09:40:43 -0500 Subject: [PATCH v8 3/6] PCI: endpoint: Add pci_epf_align_addr() helper for address alignment Message-Id: <20241116-ep-msi-v8-3-6f1f68ffd1bb@nxp.com> References: <20241116-ep-msi-v8-0-6f1f68ffd1bb@nxp.com> In-Reply-To: <20241116-ep-msi-v8-0-6f1f68ffd1bb@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=1731768057; l=3556; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=ALBAmWL9QxkgiZp6flstYazhrERZ/ebCU5ovpzJ3ESM=; b=3llnIb+dDZT9nhTeO3V4fobFNL3Innm/Y9a784osQBC92UaQLwFT+sfqe/wq9QXW9m6CdK/yZ P9w6p3MbsNdBi3w4NL4lPEtLdmjpwEa3OzaDBship1VdShJ6XCXIBte X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0210.namprd13.prod.outlook.com (2603:10b6:a03:2c3::35) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM8PR04MB7265:EE_ X-MS-Office365-Filtering-Correlation-Id: 01f8ab64-7d1b-4892-4844-08dd064cb7b2 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?wFlGqhcvbXh8B0tOCd4fbOPNBnwUvel?= =?utf-8?q?lmlZ0DEsR2kuZJ/CEk944fUn2LWV0Jew83EVessem3V9q7He14DrWIqK0EC0L1a6U?= =?utf-8?q?weYnGu1Sfj/nXpw8W4PP0owABBXaqFuy2xKomOFytwsYFgj851mCW/WwD+T5bTFNn?= =?utf-8?q?4MKouM4AAhZWbIEq7dISSc92tEnGsK92DbjOsTNxbT2ci+V7aJ98AJf2ywwnXO4TY?= =?utf-8?q?SQPYQOdN7D37PqtWipEwKJotjriTdWDpifKzEcZqTbzaB38O7rlzy4EhO4S79oM32?= =?utf-8?q?3tK6RrKevuTg/TAUSBOIj//wR6ZIpfr4e2ugG9Jv3tmygTV+NjOhd1+zXKvAzMUl6?= =?utf-8?q?74FwSjZUdBvZrq9TMhdDvGidPoYyoHvkAR+iUl+vchmtzCer7U1EZZrd7brMMPXoX?= =?utf-8?q?PbX6+3KSSXOL9hZn8OPq/PO0PV4xQMSmtWCJwQ7lMMyHxz8FXKDHNyqJpOuVBKJal?= =?utf-8?q?cJ4YzPu/+TacHnJVamg/OB3l95TmjGmOJXrM1E/WUMKj+Nt2L31F0+LwsNJysPE/s?= =?utf-8?q?zH2pB+iAOQOrrVyoo6asgsu+N6hZI7MlWnk6zmlDneW14NnWJ+NUR6bWB7VstLU04?= =?utf-8?q?P/LvK661FnqsGZcZDR1EBLZcahwZdDEms05b50obCxFqIG8bKlX4mjwn4eu2SYgis?= =?utf-8?q?SjPFF/L+FHjXHkXbIJaYGZpYteYOjEQBxLyzpGTf2sRk/AQaD75+iCMKWyx310XIv?= =?utf-8?q?C8BNTs8fPcQZ3wbhnHe8907DtVPXWcM3aP5pKV7bM3p3RzccupVT1N/jciYaLQJIw?= =?utf-8?q?3mZkUGZ/rOm8OXzr+ghhX1Y8d9275rGlo0Gv8YbZh1+Y1hYI0Xx3T9fcH/wOSa9IS?= =?utf-8?q?qNpfhUTF29rp0wcJgGgMiBQ4ULUSOToAIwpMY6jQBEhyfflg0aizOHzXkiZ8dU2zv?= =?utf-8?q?wDQRblTasYEGoTsvkprswC2NdjR9UFo6B3ip+RAhvypFupmBUXYRTJm8A1byS2YtZ?= =?utf-8?q?Foi5hVc3lueMgIfVYDf/IKx0ajEM4wNLkXdX0VJxU9rwJUbdJUa2coirKJ4TIz5Bb?= =?utf-8?q?EWw+ne4DGw9M1Sl/PryIs+1J7nOL1gfO0VPD7PSNvjmdmdcODuFE/WfabMfYCav+N?= =?utf-8?q?41Yi2TpCh+17tPnegSVKC3JMTL6ynDXA4WNrSThmgurdFroHLD5wqpeYzUdJENi6C?= =?utf-8?q?z6Cr995KNqEMoJ3ytDm/hUCeqN+GUGr5KkCzeuaI3/nOuOUJHPbyTcI9Ptc8X4PAo?= =?utf-8?q?Ms40Ri6MagIiVDJg8NViL+r8/2LPtz/RlCpfGHsS66AjLk+nwCJCEb385hLmRslxq?= =?utf-8?q?hi6hpbN3CsiTRmTXS0A4/aSmnddmikCPsxk0oqBPQqoGI3lGXRFxkZ6c=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?brJ+FA8THI1xTig0I0c/ixQaIb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?utf-8?q?Ql6nddWs4QAXnONIHef6V8s9YxLfp56KeSwi/iLX5fTcxbiNX5AvxY2b/qvZI1aKW?= =?utf-8?q?H1qSYgXp7q2tatHy8adxKW8FAkOrBJJ/bjq0Hd0GfDscH/HH3bjJ+csKul5H0jsbE?= =?utf-8?q?bC9UhSjJgbVA0dEhT94Zd/KWPTHNJAdeyc9Zzr8o9bFx87COh9MSYdntARjhX8Vzv?= =?utf-8?q?tMpCLo/EmadvxhGGPFRn0GZhC8wIhpEKcYwEo6jsNEEfWOZRgCm57NSqTOEEJ5eIr?= =?utf-8?q?Oir3TxRKq04t0ZgPuAbzZdh5voMo1dXqOmeETSyiJ2IBf0FR+5CE+cyetOF3OtrRU?= =?utf-8?q?OXXDY4Y0TBMXaMI5t/BorVYmKNcqCNzvy/YIkojbhgr6AOs/kc2AIR5HkMiW55VuI?= =?utf-8?q?NKMfyokzao7pefT9GbIa58tbgcTSgaaltcMluZbrBsMPNDyR9BfG1GExsjntLeVgt?= =?utf-8?q?XA4IA6L0bUyaxmA48VJeFmHRdvD/6Av57AFQwSSg/k6FJH40/g5+MZ3Od/7mC9pqz?= =?utf-8?q?aCOezeLpqbNNOWumGv8aiExI7wqn/BA5xfcl4/SL2REomeiVvy9IJCiJihQstT621?= =?utf-8?q?dkDifOycBpGH060yeoqLSWTBgfYpiFItpO1FXFUnx/ctOYuh88oSFy5I=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 01f8ab64-7d1b-4892-4844-08dd064cb7b2 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2024 14:41:12.6467 (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: jJhWBaPWvJiS1vDuCnL8fuwBUjpBXXys6jI3e9zDknpHKNhHq6vaZs+byhAmT2L69YIoMLlx2WkBkLhCZ/oQ3Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7265 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 v7 to v8 - change name to pci_epf_align_inbound_addr() - update comment said only need for memory, which not allocated by pci_epf_alloc_space(). change from v6 to v7 - new patch --- drivers/pci/endpoint/pci-epf-core.c | 45 +++++++++++++++++++++++++++++++++++++ include/linux/pci-epf.h | 14 ++++++++++++ 2 files changed, 59 insertions(+) diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 8fa2797d4169a..4dfc218ebe20b 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -464,6 +464,51 @@ struct pci_epf *pci_epf_create(const char *name) } EXPORT_SYMBOL_GPL(pci_epf_create); +/** + * pci_epf_align_inbound_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. + * + * The pci_epf_alloc_space() function already accounts for alignment. This is + * primarily intended for use with other memory regions not allocated by + * pci_epf_alloc_space(), such as peripheral register spaces or the trigger + * address for a platform MSI controller. + */ +int pci_epf_align_inbound_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_inbound_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..eff73ccb5e702 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -238,6 +238,20 @@ 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_inbound_addr(struct pci_epf *epf, enum pci_barno bar, + u64 addr, u64 *base, size_t *off); +static inline int pci_epf_align_inbound_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_inbound_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 Sat Nov 16 14:40:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13877608 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013018.outbound.protection.outlook.com [52.101.67.18]) (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 942FC15445D for ; Sat, 16 Nov 2024 14:41:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.18 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768079; cv=fail; b=hm4zE8RbPpOnQUFoho6tJPuPy1huFhc/nxS38INEEr3wYPGuseBStjtxELJUjtxtDAl6i1E/fQ32nQPYrG3fYlCjoFB0rKYO1FIMMU9hmEPeKCQRTo1FN8xkZgkHbV/GM8Oblnlz/6Tv1PRV3r6ScF+8R5wsggiUJ8R/jFpY+cY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768079; c=relaxed/simple; bh=4vKx2rPx2m7XWgRxYUh6kb9XgUf/PMkH85+H1/AB+sM=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=n424jQT1uZuY48TZcFjF3GrIebgS4Mo/3EgiApxV+vU4xvdgAzONDWDL0pU/SsS8t/64NMzkQGVRaUtwd2IFjDoeaGw37midYt4PAYdGodI8Np3dnZLkM4tn354NC61W6w7RShJmUQv55aI56ZLy6ZnMqcXSdeeUMJLRj7EMHok= 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=a34Q5pii; arc=fail smtp.client-ip=52.101.67.18 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="a34Q5pii" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AMoY2i0eUKmk54rBAvn91rFyjdWFgnLwbKUXaPfsbtxLVBjPb/AN4i/O/MsT3Hf+hVxw/GXGW/LWNjd+Hf/U89tX+luS9yPNjsNBb9hAHzg+trAFco7r1HpUuK8Pm96C2Fdpz2R0cgdYi4VGRkKk4uV3P08KLMTbm2BPKqSTCadOY2VgNBbKKjVqetbs/xMKpja7D7HV84Z6Nj214SAU8FXXwqm0AF9qWoz5+nAwP1nyac8/pQ/6hbZu7o/3SY8G8xdS8q8gSp22Agy+ZHjoJGc6pq0aViPCmUbioMCGasGZsIssZI+3RJJ6dZaTlr8mneSvViOT8EyE3bgMkFAbxQ== 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=AJ22JWiQxp/Dsr6tuhGS3SeKCcsaE199Pas5L1A5Z/k=; b=gupbtZb4kROgRKjpwTf9q79RnzDbmLSHY9qKpZ1xbIsiC15xBDMoWzvyd1tydJ/A048g1Psp6/TJ7D0gb3xxfLA88BKxLkgUoPQY6VB3Rvq1Jz8evwh6MAG8F1EjVpJyWHsSQ11X46NUrlligCn96VOfcWGdRqqXLderKC4NYXCcqgUagBDBGyz0iBAiPM3YOCrMqWifeYiQAQnL/6kq7pZOuEJ5olqInRjWVrOWcgB1byzGpcHtSxT+vunRMuZ2tEwD+Z+UKb1omx6GsXweNvBKYoqfRC+SMupLwaRamzB79h/fZqiu1OrJKMHuxj+twDC66AACLQW6xumC1pE+uw== 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=AJ22JWiQxp/Dsr6tuhGS3SeKCcsaE199Pas5L1A5Z/k=; b=a34Q5piiA4DrLGgONnQjt7iRkD1fj6vJIDRZqGUODznLa70MPv4MceZpg6/Fwjd7WUpdoi1x1BEHeUF0ZrsQ17/uaesJenu78TiM10iwZw4GzsPr3cRbyI1nT0WT0jhmbvzQzQj6VQ7I4IMw6Biez8RPYgp51Puvbju+f+rSseaqB4yYOHcrMzDHATtMxNPpGa3RQltciSA5OylF2/RW8+8072qXZjBy/lKZb7DcyUabkDHFGiKllfQBwLOC+CPuuRqpjL/HxvJQyWDyqDe6jPUs1kvk5yJ1eM/HlriBo0NEXE+6kKXgOENLGBbd8nVwrtB3Dfmb12ho7ubL/HXd4w== 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 AM8PR04MB7265.eurprd04.prod.outlook.com (2603:10a6:20b:1d8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.21; Sat, 16 Nov 2024 14:41:16 +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.8158.017; Sat, 16 Nov 2024 14:41:16 +0000 From: Frank Li Date: Sat, 16 Nov 2024 09:40:44 -0500 Subject: [PATCH v8 4/6] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20241116-ep-msi-v8-4-6f1f68ffd1bb@nxp.com> References: <20241116-ep-msi-v8-0-6f1f68ffd1bb@nxp.com> In-Reply-To: <20241116-ep-msi-v8-0-6f1f68ffd1bb@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=1731768057; l=7742; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=4vKx2rPx2m7XWgRxYUh6kb9XgUf/PMkH85+H1/AB+sM=; b=Jy4o0qZTn0v5n8B1dAPRcLp2iYSVwNri5rxx4sVkbNfB4zlzngT9PCf95RinIkM9JM7xNXYyL aw5yWDOuiMxD33SVtRLQj5WhtiCnPevt0aVOW3/zTEOAN211kdT581I X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0210.namprd13.prod.outlook.com (2603:10b6:a03:2c3::35) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM8PR04MB7265:EE_ X-MS-Office365-Filtering-Correlation-Id: e820607b-6aaf-4abc-14e2-08dd064cb9f7 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?bDJrUlW9vgSGQOuLX3JmXZJUASxWzGw?= =?utf-8?q?NqV7rrNVKd3hYXCAHyMEdH+O8gWbS5tWh5PQS6DsWKNx0/nGN/D+9rtjzoSMaoQcu?= =?utf-8?q?2TP8twPTrpl3W+7E6Ql1ApBHsj+jADJSrosVK4jRW8+xAwveHoJMdKglH1rdKBsne?= =?utf-8?q?Z6d6ps8tWmcjSEv/TUkIQ32xPDgR8RONpFO/zima0N6oEHuZ97vq0Ad4RM2Q+Jvrg?= =?utf-8?q?y8dQ9oSPkQCg88pJhClk8BQotI0PO38KzFxK207OMiC+IS4DIEr6Yf8rh0XBKY44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P4dh5kIgVYcmG894WOGceb0bfYuFH8E157n1w0azJnqGUflbjX8XMrTRl2o8kui3?= =?utf-8?q?V40d3jolu8SGqhj/hQDi3cm+6sHJxp3JXq2liOepZ+DhT0tTlDe5qwW9K+i9pOGX8?= =?utf-8?q?oeR2WPqoJePZpgdk0DuFhGt75Z5PaAu8kmAURMN/Ibqwk36oj4Twpgd8=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?8D8WfqaOYRntjRrQMex3C0qKPiFP?= =?utf-8?q?mH0+ckepTDM2iqkKQUFLNHKYQs9NzKJyQY+L6dJuq9m6jqtRUqxMTYMDUEk6W96ME?= =?utf-8?q?vwElgBZqilFNyVTiiMcfFSuz8PqVpbE+lk6gkCKBfLskpawZR9tNyFlMuyIgyIFdT?= =?utf-8?q?kjONTTQsZC3sSTqX1UiUHAv32gdiyWzJj+HG3TXw3mML6hoVxqsHAwAWbsOzFX5F7?= =?utf-8?q?uJ3fGV0HkadX+NO7avlMmWQ6ZQc79Ms1wO4T9W1HDkXXNrePC/oma6NckRj+sX94B?= =?utf-8?q?b4Op2j+t1Ic36LkVMRJv1lugzXL2LLTgrADinnz/MXGXm3KxeEBCGrtGJXKmSzT/8?= =?utf-8?q?FQxR2gY1wARjFkf4pyCoXOiS33+X3KBZxiXUf1NIOyxmlJbCYcmAL/KfwfHDezEan?= =?utf-8?q?6vtPffAw0hYTTPBb7We0aAWhb4soXLXsMtSx6oZEoOIOrutITW0+15By66fQrO1sR?= =?utf-8?q?Etc5bcCs4B0UHVxGb6qMlPtMe2zQWmlQCHg9XiLp94Bbt3uf+EKxmU+a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Z?= =?utf-8?q?rq+HaycHXslCuY8HGuoX9SdJ0yxjLMlR3QGhYP+emjsB6SEbu70h1CU4VZY68ukvx?= =?utf-8?q?HOQnaXGgGwynJzvow2shRy5wY5xaiHqnMor/Y4sayi2OIMgxnhpUL0WQ=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e820607b-6aaf-4abc-14e2-08dd064cb9f7 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2024 14:41:16.4653 (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: ybkk0/tJOnwHSzvDL/ZxIUQtgr0dWwXoBt7/0GVZ8QE5iRV0gdN6z7Xnyn8yVpI/sA9KPfru8xJaRGF45OKSvg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7265 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 v7 to v8 - rename to pci_epf_align_inbound_addr_lo_hi() Change from v6 to v7 - use help function pci_epf_align_addr_lo_hi() Change from v5 to v6 - rename doorbell_addr to doorbell_offset Chagne from v4 to v5 - Add doorbell free at unbind function. - Move msi irq handler to here to more complex user case, such as differece doorbell can use difference handler function. - Add Niklas's code to handle fixed bar's case. If need add your signed-off tag or co-developer tag, please let me know. change from v3 to v4 - remove revid requirement - Add command COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. - call pci_epc_set_bar() to map inbound address to MSI space only at COMMAND_ENABLE_DOORBELL. --- drivers/pci/endpoint/functions/pci-epf-test.c | 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..410b2f4bb7ce7 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_inbound_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 Sat Nov 16 14:40:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13877609 Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazon11011059.outbound.protection.outlook.com [52.101.70.59]) (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 D2F17188CC9 for ; Sat, 16 Nov 2024 14:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.70.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768085; cv=fail; b=irjWZL63JmeP41AinUtMhUrPgpXN9LCFhmuBdjGbUstqbmMP2JwVwGKl5l2Vl83sn0TItGBRsaYz/RsSbmDugYrK6oE9oFKVkhuHeyzo1VjAF1tBqD0ceh+B983ssWoc6x3tR1PpySj2htlbgx/o+Cm4dvtRHiwjE6vjpXtKEpw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768085; c=relaxed/simple; bh=bfBlohtvx2bmitM09sd2P0/1msiF1RQlPsCuEI4gWds=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=XP6s6tJIABxLC3YdHs64hc2tqu/IarHZTTq7YCKWaEtOdH2IHWndxovES5LefVySOWjhN3L1DchcbiI4mEUSgvGi4wrt9JTRDEKPoXx/+M+mmuXRITHldz+NHz5L42vRgp21wQq7N88b48g+o9iqKZcTEYqLOhMoiIIDvmC+VeE= 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=Em70wJrX; arc=fail smtp.client-ip=52.101.70.59 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="Em70wJrX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yUPAes3xkdt3aj0dclhi2rtwtKmr43o/MdQwFFgdJAMDIsm8HNYZjPRzP9PpyEgxR9BA5YNennzwSrxkngrW8bJFiMszdLUh/jvyPILoSYe1bYfKlDHKEKRX3XN5b+OOghV6t41xaI6Ni9XC6WQGsC/6E5qjHMF5rt2rE3/cyFX5VfgCmD3K02sa00Ri+unrMapRXXSDjCAszjZlm+QGWBWMFUu6fnFhHNk/8ICjoZAbRcKVGoUf4SArXdkUHVApneDntYQxA1y9y0NtZRazBJuJsrThaVpTQN/HFZn5YSCqpLBZg8WiFhJnuNG1NxZH+sl0HcNMewAeszwBk0Aj8g== 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=sPLSAjBxVhmW/iYWYZ4v4ELai9IvZTkeFFwJE94I+Ww=; b=Dk0GX3ypQa9NdnxPOkwHb0bqBnoXJwkeEn8zvOfmzOrafBrxK+hG4WDI+Cb9VIDlBmsnCotxiPGHtXEJxtPJqdDcglHiGfudiWcLcJw90dybRJ18KH1/k3PzQkBR+dkt8oqbJ4WjnI/7HqsogKYBsGBPI1pPjuy7SMxclmtTUguEEw0mEjcQCD60uUkoUpAaGpeTxG5Umj71/zeAS8AqVwD7SZt5L2sMh+UXszLgkrR14krWO0Y2eRhAQKJDgCT474ET2870hCsUIuFJTu5qxCzW4ZCTW/4kszBvG/qA9kn/KOx9IUvSSEjEE7RQ9sfW6fmgYdk+JDQQR6YWmD7qrg== 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=sPLSAjBxVhmW/iYWYZ4v4ELai9IvZTkeFFwJE94I+Ww=; b=Em70wJrXGL49ancuIJAdvqVAMXtEX1nyZgS5QiRTXGvakNekPe3n39GCVpLvRnCyIO5tfS1/Bqy8imNQCRvUIIEuR8YVBzNhyQTqv13lXiiNDSPkAh4cySjpDLmqKbe25mY5aqIA76xkjIm6AWCI2Gt/vb+nKq7zic/lbrMiUH5uSHvVFeZFBhWorgtHPqPZJTI0bB2RKZpP5gVmLTQoOLx62dMSy2DtwszJC7D1e3zvc3kpTR2oPwCWSbFW+FadZSwkl2l/2fBAeWj1tCSotUqG8WZbVdbG8s/4v5ybjrjN207AbswJbma+y2kmvr7KsulEDBbOBm8MhISUuWxPZA== 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 AM8PR04MB7265.eurprd04.prod.outlook.com (2603:10a6:20b:1d8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.21; Sat, 16 Nov 2024 14:41:20 +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.8158.017; Sat, 16 Nov 2024 14:41:20 +0000 From: Frank Li Date: Sat, 16 Nov 2024 09:40:45 -0500 Subject: [PATCH v8 5/6] misc: pci_endpoint_test: Add doorbell test case Message-Id: <20241116-ep-msi-v8-5-6f1f68ffd1bb@nxp.com> References: <20241116-ep-msi-v8-0-6f1f68ffd1bb@nxp.com> In-Reply-To: <20241116-ep-msi-v8-0-6f1f68ffd1bb@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=1731768057; l=5527; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=bfBlohtvx2bmitM09sd2P0/1msiF1RQlPsCuEI4gWds=; b=R7yeWlooL09qMBHQ6B5jA/netTygU+2xCXeQeYPhP+4oTtMk6hlya2JAMPdOt0Vf3T3S8Yn25 btDmwrEgvaHC4gfzw8jCL01LTijIf38ZbKNdoh06soCMTO8Oh6eK/0I X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0210.namprd13.prod.outlook.com (2603:10b6:a03:2c3::35) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM8PR04MB7265:EE_ X-MS-Office365-Filtering-Correlation-Id: fa82eb39-b14d-47bf-2fd5-08dd064cbc42 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?8UAWDwGMa3QiaXDBKTe9SSD0xpdhxAq?= =?utf-8?q?FvKuZ87IkPUCzeWLuQ9zZS6ESTuDkrv1WYTWaWP0FMaSnwAougWEcYTzYt/5/eJqO?= =?utf-8?q?w/nINR54joCBDpMRVTllunWskQdziKpFSyT/4tFfkLIWkhbQPDaAvEurTPQaaROEd?= =?utf-8?q?Frr7QRUgvNT2GSXm7KSvjQ0xcWQanC14MlsWLisTmxBMgGFS1OYF8+oF7jehR/ilA?= =?utf-8?q?OzB0E1GEplCkZ66MhQ2IP5I7sCn4aHYPPk12RC0PVvmPQH0w28Pc7ZjXV5AJDZgD5?= =?utf-8?q?mZ/qxRGl7MDmX5G6sskZ5jXfKTlD5nLCsw0BL3GTilC1BHzhOP21c7vQWOWxEJgk1?= =?utf-8?q?+kPyF7cQXPjHRiJWNGqwc0yd8VhqcSwwCazBAosFltRYa1E1fu05LeESwkPA4s97G?= =?utf-8?q?XUM5MouPjO+JY991aKcxT1xCHw5pT/Bt39oZ1gHN1tcJ5KqbWiLdUdN0mlSJZO8dA?= =?utf-8?q?kwONxDJ2jMfUR0Se1BtQmIYySbGU2ufgilU80L43d6HoPNwvfY5FRIHPar2VdlPzp?= =?utf-8?q?OAR3aHzcBUIUP8Le/bKT0AfqHEBFGxUANG3GF5Oi/5IAg0nyKlpfESEFoE7BrNSY0?= =?utf-8?q?2ISvc32giLbi9NREeLvK6vi4RtJ3DscXlYrAOfZQ8l2bMWZa3gzG22rgt7A0qiAQ2?= =?utf-8?q?DFpDaiVaD1vH12Un6LTauGnBaQop9Ui2/nMNVEWd3eSOI1FWdG35rIyKBNH+lHDmM?= =?utf-8?q?I8X1E6zqldIGjEQBAnyzI9ERNBGfwJ7HARxdDtoKlVzei3SM19bnWUWrlvPTW6SiC?= =?utf-8?q?8Cg+C76MuPJos0dveVjmeiV/J2Tbt7rzDgKdWR7LHhPrsHP0fI1nbrgW+c9IdcejH?= =?utf-8?q?pJeEqf1o2tokNQT9lXFvnihWPBKzpqF+g/iORwPSPYNeR/T0Stxfza38FS2Dm+Rql?= =?utf-8?q?g4uQAs4Q9GU/BfpCVOjmTIQ6ezZWKjjPuku8qWXyH0vY0iyzJz4MYDzPeqxLv0V7f?= =?utf-8?q?4fYguagU2ICuzergp79GbvlHu+8aM4i+CgT4D8bble2fybipGuvs3um/yaMSy7/u3?= =?utf-8?q?+1iexyO5YfrIs+vEk+5GMstpLGfiClnQksrUhoV3+YJIYfX3PgzlwHbDNa4w/GuoK?= =?utf-8?q?7vfxiBGph+2EzP+a2twobgedOGHtBiEdruPHtajS4N1h6LjiAGTkbQzw96xiQg2oP?= =?utf-8?q?EUp97fKxxBa0PzXrW7ujpAOjCAWR4QGYWqyX/7NdP7iORtbUd8acKIpAwsMhiKh9O?= =?utf-8?q?X1AUpzJMAAIWfUXELBsMRBIjwCm58FkXwaHsa0AX9n6vVn7xSzruyFGYWLhCAf+zY?= =?utf-8?q?Xr+mQj1/KVo3kaU7wi4K76gxy3g0tqpNqOET5YnKgw30U/nHtYmZIKEw=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?9yKk09pwJK2nTkBSvtJG6bPQjsJ+?= =?utf-8?q?SPk+Fw01Ki1K7AzPVQTlJDyH4VKKcUig9quxaumJfON0YrF74tk+WIlxXG0ffU7f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iGObIq/wRvc6mX0n6j+zZNLmRfzr63BYagf9F9vxv11UudIr?= =?utf-8?q?aIKh09Mquhd9dyVrbcNuAZGXsb4M63lDV1MgCi2hIuAQVoGlTLb0nOO1PVKvbaIRt?= =?utf-8?q?fvsbdSfOSUu9w4o5ZRi6HZY86UwvgvoJor6fy1SQh8Qkw2K9Feefot/ct7nOOKTHs?= =?utf-8?q?5eyayz8HIF9X1QniMkxyqlJY6IHfvUHUA2N5GHwdDCAaPSBGTIJ1K9n3drZeuX4Ug?= =?utf-8?q?FIzOHyarwiKUgEH+d5gIGIQGso2meV+UclNcOsn5Sah8HakvM0Sv/JZmK879fRURb?= =?utf-8?q?EKDbP2OgyjZdrzO4nikiE4yXatUEyK47ntDRcK/81M+j0WMQm1hHvaIlacPwmiJAn?= =?utf-8?q?0RjnoYum560luUafBM88z+xNsrvHO4l6Je0OXEzcooZzFWpD6rn3NAqAAn1MkGC+U?= =?utf-8?q?IqSC21dJV3zCZW6bSnxQ1W6ovE2D/NIyRnCvEMeoQ3Db8nsb7prLhoDPfO31jcivg?= =?utf-8?q?EGSQbmpO3cpfXdxJoQVPlBAx3TDE646bhhq4wQqXROoluY3LP6b9p7KQ=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fa82eb39-b14d-47bf-2fd5-08dd064cbc42 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2024 14:41:20.2970 (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: Ty/GE/nqDJ8h0fSl6AgUCQ7yhYY2iGRdWNSTO0FHJWo25HH0FlDwnJ3deqDM93ckkhreJeVGq8XhV1FEDcVZRw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7265 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 v8 - 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 Sat Nov 16 14:40:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13877610 Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazon11011059.outbound.protection.outlook.com [52.101.70.59]) (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 31755188904 for ; Sat, 16 Nov 2024 14:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.70.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768088; cv=fail; b=m9RDzSCgsc6QcZIozfWRJ7drHGGKuln4vYqgjAoDsz4LQNOa0GJNl4+RSvmNmgGPKZSyWWb7vXoaOtEVDTUVLV1965Ty1GJrmOlOMXxou2J43Z+442iWFoYSTndWKHmhq4lDO31cFJ5P3lZlM2MxqdpKNlLOLb/4EudJg2kzc8Y= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768088; c=relaxed/simple; bh=PMPeULWcd9APEf5NgSWWzp7T5Vx20NKWDiBCjH7nCZ0=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=rVswaRo56SJbG5cV4lKEwZUEQvncUFDeO4Jxn7j99SpxMEdEpNbZIesiRNLbEQjkLAxDHSriyYhxeoiHLXIUzVA+YufDM2HKNVzsIOFv9y9U2qiedvzfJovScXyTnURH7CB195WFe4BK4pZpnA48ZmrDTt7qVJ90QC0ZX2IaZ74= 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=n0nd+Anm; arc=fail smtp.client-ip=52.101.70.59 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="n0nd+Anm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=okmLCxSWKzH8j6tXc4JjsdkY4D2xEN1qPAMFnahjRyfjjq9R1IoRxyXxe8NO683tpygD8fr5XnEUf2L78vf2vNC4v2DbTr4Cj6TzweF6cya+jF8W1KjyRyZvSDGueZ2N+ZPnXkz65KrEPJAd6ffA5VxQzBosl85B9VnZxFiVpPRLUPUSwbf9NkAc3MRrYqfPoBRKP02PN/y3pzEhdAAW7IGyudwlwYW6IEgk10hvgli1j4EaGdxIfNJC4EntOLAWAVBiDNNH2e6frTSa/Qj11edQUlwbF7CWwD8dV5nxwEDFHzPTv06ldrzoAD7i0DPFpOWSa4RV62kXl4B+bQdsag== 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=uwKvm2PFG7IelxAqz673F2KybERhxfLWfXM1E5u8duU=; b=WyRVkUZ2VV2axrfoEnddbli0XSQIrsvFLA1yiLPyxjC3mkyv4g3ulVraj7ZPGGkeZcCb/8iglwwtI0sOatD96VpuSacemWx4s4oh0VQJAoPWdXvLbttprD2rL51wucUyPpy/MdJDXhtA8pOdNU1bD6WSHKYi2wrEbth7L453ormnaXHS8EpCr8WOsge9i+u5jAEJ1bBw6mG4sU9hH7Kbt/F3ymTdF+PvicYnXmzFyzZ6CC3WlzwCGLvxzn//rQJCphOYpP6LKNzbhITrwjSCCgjHrP/f8zpdpVgZlQDgjdiyd6Yx/0CzDHoM905yvkADGRB7ZsDY8W3grBujjVwQSw== 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=uwKvm2PFG7IelxAqz673F2KybERhxfLWfXM1E5u8duU=; b=n0nd+AnmNV4NoF2TeffY6DIcIICa7zUKLfRbvWO7m3T4556v7Vu7DYzk54QgErlD/E9tsq04VsCOs2xyhH+Aezm3ZK2WHH435uXnkq0IwyyUtSP8NVN6X/jtHlh3ZDBVZicpDjQBeF1sFAgqYO6J9hoD5GMBVeHrzX5LrDUtUk3ONEk26W+KXwySHyvEJ4k9n/YRHw9TmWpqt00v1/ouktoxetEtxqEQNbdubVjv76WU2yMmKRPiskKtCk+O6jvrtI+K0YFuouwhFudZTZVP/pYwLpvCMQ7NKpI/WKdAkbtMfgem3O3PWiYx/iz+x3pSC9/jRzRsqGp+7+K++/XKtg== 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 AM8PR04MB7265.eurprd04.prod.outlook.com (2603:10a6:20b:1d8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.21; Sat, 16 Nov 2024 14:41:24 +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.8158.017; Sat, 16 Nov 2024 14:41:24 +0000 From: Frank Li Date: Sat, 16 Nov 2024 09:40:46 -0500 Subject: [PATCH v8 6/6] tools: PCI: Add 'B' option for test doorbell Message-Id: <20241116-ep-msi-v8-6-6f1f68ffd1bb@nxp.com> References: <20241116-ep-msi-v8-0-6f1f68ffd1bb@nxp.com> In-Reply-To: <20241116-ep-msi-v8-0-6f1f68ffd1bb@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=1731768057; l=1850; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=PMPeULWcd9APEf5NgSWWzp7T5Vx20NKWDiBCjH7nCZ0=; b=SoKGk63GaV3YU7XiowdjYlWsuvNkLChxn7Ujnh30C8YKXF7nI7eRONMoL0yKyljgwCpeCUpOw yZegV3FcFcDAFCoLusTbNUlZtnKt+uzTUf1Mz0hvgLd7K5cj4ajccFx X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0210.namprd13.prod.outlook.com (2603:10b6:a03:2c3::35) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM8PR04MB7265:EE_ X-MS-Office365-Filtering-Correlation-Id: d54d38f2-020f-4751-2b97-08dd064cbe86 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|7416014|376014|366016|38350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LNu7/ggyyj0yN9esWMA0LyuDEofWKnaQx2iQGyRFos4LwLHSEB/I+ZN++ydXqIyb?= =?utf-8?q?2MLb98/Kuxq4AsjhiKIY4KvsnWtTksR67AZh7j/XOjKx/kW9DfhyX55ZKcya3tCRD?= =?utf-8?q?3qDXcaBZrJCvnuCb2lh6Epq3frpJEcv84WhsUgQmAammpE1N+vBomOD2R2qLr26nE?= =?utf-8?q?OXscCCB1vv9cOyD4n5EliohILYxzBIun0bF5TClhee37GWGeZfn27gcT1wEiq6dhd?= =?utf-8?q?d2YeQt8GTAARHaO6EMbMZVu4bX1j1wjY1KRFIphX16MJhkLC579ZSP0hsJqYZmu4+?= =?utf-8?q?LWAdCS8hRI0Lmm8PiG0+LoYXvyVeiBM9+ny2RLnqoxIpy6wJifEmloh4/X+qeaKGf?= =?utf-8?q?vcyEV9DCc+DzkECH2A0mogVJcf3yNdsQ2cJOQBnxPGp3zaC3BWg9XAaqzzXz3Q057?= =?utf-8?q?cVBGKTRJMIBu8HLohpHZ8FHrUdPogZP8rIlg2QUG/H1QusQPJyz6UXc4=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?f3ZFFATHV1bVk9xKrm0+aNccZ0AC?= =?utf-8?q?Q6mZJsLcJ0iBTkTCCjhKAAQUoN851bB7LqbSZoVMi1XVv47Zc8Dt8pULJOrraobwS?= =?utf-8?q?mXp79s0lD5SBROySjG9ccj7KU5Uy5gkJDaHRE9iUCbzYPbgzVGMriY6OZIpGzpb28?= =?utf-8?q?vY34kOL1Vk4U/dPeRkKjjYSnFV45a+xWiEsnHF7XGm7x+lZVNzap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VrM?= =?utf-8?q?WO7VCCinWw828Bb17Q5IVcWKHhChnUdtdCcTAD12RN0zjv60kdWbe3a/3nYButKfr?= =?utf-8?q?YBHNpk0ligMG6TihBk4H5ZLFNIsc6N1K8bgR+Y3nsG2uFNcUfbCI4gwn/LQZEi74M?= =?utf-8?q?YXmo3bBA0M4QW5WBeONYUxG3SuVZeH55wHFQFGCPpJb/o2Y4gBWSi+k1uUABS96kM?= =?utf-8?q?ptZMf7JB7DK+fMWQpD91yqf0WmhmND4EoC0Yp2m39P6fYQgpQ19GehDfgcQIJz4f+?= =?utf-8?q?fvMjyKE++nyxSYSJUs6dnLRanhf1Lee0gbblY6kT3SvMvJGVR8QEmzfrP7QP83fiT?= =?utf-8?q?OZf/JOY8HfQ/SndQJ0u7SsvxeqVqOmddqeMR3wbKemAb5DtpYvvP5v/sDJHPbpCZ9?= =?utf-8?q?sPNyRT46dfrRS9FMbSdyjuPD/nqgJ15FzHnlgfAdfb2OLpk6abFmHjcY=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d54d38f2-020f-4751-2b97-08dd064cbe86 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2024 14:41:24.1365 (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: 2pigb8NQxYoKCEgvM8rdYRamBcYtymuuZQ6BKIP3N0ojMg3D2FwR9z9GqUo8ZB7suBSzSPLEMbOPLowFZ8X6YQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7265 Add doorbell test support. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- Change from v3 to v8 - 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;