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);