From patchwork Thu Nov 14 22:52:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13875712 Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazon11012053.outbound.protection.outlook.com [52.101.66.53]) (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 81AEE1B140D for ; Thu, 14 Nov 2024 22:52:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.66.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731624781; cv=fail; b=ZpiSWMr1CkuNPoUUf+PFM3KVL8kvcj5spuO9DW0ZSdiO8z1T8VXNYZeE3oucCBRQsevM4XtC0pmUBVe6SpGOwY0p3d6lp2zkUP2SFtt7EKwyJF3/TBhaHY3n+QXEsR2Ylc1lHT1122i0wuWPc/CwI5O3Lwz1Ihe9Ji2V63azuqs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731624781; c=relaxed/simple; bh=GejaoXH9F7tp0F2pj5fsUPiC1b7nvtn4F6gvoOZt97U=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=KKFPcpaMBvxhjhwOV5w2HGN13NIMtdxtFHU3EoKOXCFCKO541Sb1VJq+SN8zkEQHIHJI0Y3ln9zng/V0SSiu9YHLqUav9qYSif8u362nyZaLbNyrGybu1UlZ+6CZbqkLwILPCbwz7TvHQXNTsxYAIFgJVf9tOtUB5kEPjA/9NQ8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=KqOoP8Xv; arc=fail smtp.client-ip=52.101.66.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="KqOoP8Xv" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=k4jtABZTNzPujeKVUT8fcqZPqlUGQK+hwrKdYTbg2SGzqJ7siUUKkPxUEHikUzXAP50ekkYOuXcFqrBmaB/G/700wUpLGhA1GjG1ceEzd4+Xqz+CkmoSOOWPmZvpid+QAgJhG4+/086TjzjxXzFqaL6C5O6kqkL4TJIXm8chzQ8dckVcxI9yYdK4lB5Ij2MfIyLuBuCa9QrOV1pP8x5Y7C543Tjc+4jR3sEwAGaYcGkfQptLbikrQyMv7DYUQa/p8tel7dIal3MuYsRr0OLo3qxi6XN43CEuWfIlfZIW88m9Z97VDZGgUI93fhGLP+nqZhcj9p3HTw49AtrYmUQ4jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=sJXulzg+iI1qW2v4QK7V0AHZaG9zbHgVHKDqdV6gZXk=; b=MA01XCXJcfoeP5xkomNoQibnVJg+JBoVbTRkA72R6ON7oyK3EB2wCHQTJe+Vl+1N8e/wrmy3Z86p3Ki3xUtQSUz38m05XW90CY+YHUZxDfAlflZjQt/DvD4s/AIkNSowHmjVHAzSbss/WVYJmFtOwFiUf8V0+61sdkvtDSm5K4AkQxLFlokTH1kOPR66X/7HJd4m6DPeq4YZN6ItiWnO9gv6J7mKNedFhxuAK45tVCeK1bBTBdbTFBcbo6HkZz7DJRGl74XqPnTwz6xn7xyFXVQ2gvVjwX7OTe2vFbNbaFWjXpIB30mTtYSWJUtDT2WjnJ3R3PEHT7gLuyTHYgKSug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sJXulzg+iI1qW2v4QK7V0AHZaG9zbHgVHKDqdV6gZXk=; b=KqOoP8XvPqW69NrQ4Toj8pj+5Y4PzmXpaAjLcN6UQh4gzZ+fE/ZrIMCWtFXPH9wFXRy6bC//6SQc3chUxZBnjhDfK4KIeFfNLaTBEQurA6g1FbyEDuLPtKAJaevvrc0kevy0HVk8sHNkiykj7lDuI2T1yHUvfpmst7jCdVoKTlNUHD9aoJpmUV3oKwpIcqJOFYUgA1QZoUo9/IR+QsDOPz1DZCzfssoDP84JsLPWdarADzduzLWI039g0rEf893qTFLljc8jfy5ny9PCxw2ZIIliwe+zopYE7bGCkut7lw7VO5dRcPKL+1vGiJOoBnaHH51+mwQXnEJtxwRgQ3oStg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by DUZPR04MB9967.eurprd04.prod.outlook.com (2603:10a6:10:4dd::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17; Thu, 14 Nov 2024 22:52:56 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8137.027; Thu, 14 Nov 2024 22:52:56 +0000 From: Frank Li Date: Thu, 14 Nov 2024 17:52:37 -0500 Subject: [PATCH v7 1/6] PCI: endpoint: Add pci_epc_get_fn() API for customizable filtering Message-Id: <20241114-ep-msi-v7-1-d4ac7aafbd2c@nxp.com> References: <20241114-ep-msi-v7-0-d4ac7aafbd2c@nxp.com> In-Reply-To: <20241114-ep-msi-v7-0-d4ac7aafbd2c@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1731624768; l=3147; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=GejaoXH9F7tp0F2pj5fsUPiC1b7nvtn4F6gvoOZt97U=; b=H4UfBsT1veKOUojtt3FbC39Xu2ea4QWtLIu+xbDCdzobu6XLfkOlZQucb/5ZCIHUVD7LhQNbq Ls/XtDOpllRAJg/DDl0QHJFWr1S1lOBLHnFYM1i4mobJmy77SbFZ+FN X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0166.namprd03.prod.outlook.com (2603:10b6:a03:338::21) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|DUZPR04MB9967:EE_ X-MS-Office365-Filtering-Correlation-Id: 8e47ca00-af8a-46ba-29c2-08dd04ff1432 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|7416014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?IQtx8+cNzbVWPTWLoke8KzRJAFkkrHL?= =?utf-8?q?lqKJFGL3NoDluIvDPSi5yBjcvfAyFfdgdYofCxMTb0ufxWoVuIAyF+23fpsZTTKn4?= =?utf-8?q?47KOjYWBEG3eBuIoLLRLhqKSysKsc1d6qHdNkv4y/NutGoIS4HcOdzjLB9za3I1d8?= =?utf-8?q?CPkx/fAIoERpZlJz9uxkVr96PEr8+vHq8aDGLdomN+rtwSSGtknvJ2t3rS+6FE4R0?= =?utf-8?q?GHelvpgU4hTXb7TZ1T8NsMYEFT1vN9E8fSeUhJghWmGr9uG3OOSo8usTf7H3a69PV?= =?utf-8?q?YOSfuRFtHEbXLXrou9f3/p9n5stgAIgikVBK22Z371/c0iFSaZ/M8+O/4Qq2tu/2D?= =?utf-8?q?SXSS4dT9lzvPeosaxXZmaaqhyM7u07Vk7JoxnYzvW0pNG3rJLbhweR1j3i2gLleTh?= =?utf-8?q?HlRKiMwtyntoRDWiXqu2Sdl+9K6cDZCinwx4YpIKwf5E4bAngDUFpGiR0uLfLQ7GM?= =?utf-8?q?mEzIv95+svEZQie21veTABJ324B7f2APKgX1Rv5IrQTTVbHmVPIIL8cwFBKNCe2oc?= =?utf-8?q?pb0D+hOeEwKcwn1zxjOKDIQm9BmM2fFgmrSaLORA/EpwhDOyolHUy672W9yGx1LZn?= =?utf-8?q?OPGXfRXn9pts5dWOJTAJv3jICJLFG8KEDJWApv31PWeID29q9X72Rmsyacvn8MlTX?= =?utf-8?q?WlZnY3Y+nSSW7E/YxZEoOAhpDZ8etWucFpYdhLrl5XK9p//TysnVIVYjULt5uzNT6?= =?utf-8?q?VdUK4A/oRPHDwzqEmOr6BGYR1AAtazzCzFGRaOWlYdHuDFrH91+drlr2Z/GD3cj0Q?= =?utf-8?q?hFsLRBH/M1qNSOYFSMjd79cmH1nnlEjtoVOQoICOvwKc4F/pmiaQ1FQZaCGISz36C?= =?utf-8?q?OVNCpUeqzBRVe5QOIWdB7dEGI7pa95JsmLuv5HeZCELayQlUr6oNZT5G8CU5hIGoM?= =?utf-8?q?ge/irzpQEGkbJIg3UNujwFrVtzxdodBZDWCak91V6dz0Ii0Wv2mEja4yrN8Mrcu9S?= =?utf-8?q?eqf3zwBWQWUdercuv2EwSRNQC1iPpH8Tu0bXOrSs6idrnlBy85Zzk5G5ybUN/Wi8Y?= =?utf-8?q?TdHkFq3OIb2b1Sri2L0XZAfpKLvX1IsAaThBM508kq5fxsBCBHQCR4Vxqe8Qt8DHI?= =?utf-8?q?HfLmUg2KwKxarRu11hBPvMO1fyKXs9RCDdNPToNadSTUxb4xfvnx3M2JfQBrR/Ryp?= =?utf-8?q?IgWl/sOyLlidF0rurkhqU4GUkjASGHwUACQ6n5f4cMfPZ/uFRIhdM5qCcKlR9yHLs?= =?utf-8?q?BdmwQKumYOtWfzknOD0JCZczohkWskIyloWUup7xdiDyVkDqA2HLLjOCDHQGwR9ne?= =?utf-8?q?yJrnB1haT4S5f7hdnW5juPRtZ/AmKi4TZT+Lrb7XVP+HX0jD+PZZ9enM=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(52116014)(7416014)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?ueKFCd+8U2u5yqOyaRvDm+OKhN1f?= =?utf-8?q?T0CJd5a3oR3UbNM7Lr5Gh+K/4AMIPptQXk7oGeN1bKYqMvvsZRSAArl7kvr3nHVjN?= =?utf-8?q?kJJdgnmL1gXs9JJBRZMirahwPANbfxMlf9/nbYP/IcU+5ab/hl1j8FgkLBbVySsus?= =?utf-8?q?P0EPZ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qc+SG7J/AYpkcQzhNMlfZcbxfbrer0kHubplSbPIbs6A?= =?utf-8?q?M2A5qDudhc8xA/XLq4G3i/ICLN3cx90mxnxvZq8AivLC0sPToJuWm1IcY94mKUGRN?= =?utf-8?q?sJwcUqaVgXmLUA1QzPYsiBgiKfFAdI31wP+PfzVFevKbRLfRdSx6tyuU8tvwmI4sT?= =?utf-8?q?tQETt2U0rOfjgLy7tneMVCy6UtzaUGL6bBh81PYcNnOZ0YsUdGBn8g0xRMjkBPAhp?= =?utf-8?q?kKGtzrNQhNdE9btEB9EFVCQ4kZrUXgRpCwPakruWfWpO006YYheXX37o4jkfOgJJU?= =?utf-8?q?kMFVYj111NfkUAlCrof+bwo3Zs1VTSDGKvN1Qty1LbQNU6H/JBLSlaat1yR7SY/qv?= =?utf-8?q?yRE8M88Uf9Zxw92rIJrZ4SsW0DnpPcdOK8FIheP7M2J9CF24za5r+TcCP340uV85L?= =?utf-8?q?p2+M0thf+UrSpyXjIwcfKdXjY1OD0jo8FKH27N/I9sn3IOHh0UMWI7Ik=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e47ca00-af8a-46ba-29c2-08dd04ff1432 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2024 22:52:55.9585 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Rr0w/jDvnhhgV95z0Qvdv9H1bgE9wMjh1kHTbhC3bDuSo5VQKnFJn+W5sH6R7gyklQ95TLjMDqe85AHArm+E1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB9967 Introduce the pci_epc_get_fn() API, allowing a custom filter callback function to be passed. Reimplement pci_epc_get() using pci_epc_get_fn() with a match name callback. Prepare the codebase for adding RC-to-EP doorbell support. Add DEFINE_FREE(pci_epc_put) to implement scope based auto cleanup. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- change from v3 to v7 - none --- drivers/pci/endpoint/pci-epc-core.c | 23 +++++++++++++++++++++-- include/linux/pci-epc.h | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index bed7c7d1fe3c3..f5538c007678e 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -48,6 +48,11 @@ void pci_epc_put(struct pci_epc *epc) } EXPORT_SYMBOL_GPL(pci_epc_put); +static bool pci_epc_match_name(struct device *dev, void *name) +{ + return strcmp(dev_name(dev), name) == 0; +} + /** * pci_epc_get() - get the PCI endpoint controller * @epc_name: device name of the endpoint controller @@ -56,6 +61,20 @@ EXPORT_SYMBOL_GPL(pci_epc_put); * endpoint controller */ struct pci_epc *pci_epc_get(const char *epc_name) +{ + return pci_epc_get_fn(pci_epc_match_name, (void *)epc_name); +} +EXPORT_SYMBOL_GPL(pci_epc_get); + +/** + * pci_epc_get_fn() - get the PCI endpoint controller + * @fn: callback match filter function, return true when matched + * @param: parameter for callback function fn + * + * Invoke to get struct pci_epc * corresponding to the device name of the + * endpoint controller + */ +struct pci_epc *pci_epc_get_fn(bool (*fn)(struct device *dev, void *param), void *param) { int ret = -EINVAL; struct pci_epc *epc; @@ -64,7 +83,7 @@ struct pci_epc *pci_epc_get(const char *epc_name) class_dev_iter_init(&iter, &pci_epc_class, NULL, NULL); while ((dev = class_dev_iter_next(&iter))) { - if (strcmp(epc_name, dev_name(dev))) + if (!fn(dev, param)) continue; epc = to_pci_epc(dev); @@ -82,7 +101,7 @@ struct pci_epc *pci_epc_get(const char *epc_name) class_dev_iter_exit(&iter); return ERR_PTR(ret); } -EXPORT_SYMBOL_GPL(pci_epc_get); +EXPORT_SYMBOL_GPL(pci_epc_get_fn); /** * pci_epc_get_first_free_bar() - helper to get first unreserved BAR diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index de8cc3658220b..d3d3b8c914614 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -300,7 +300,9 @@ pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features); enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features *epc_features, enum pci_barno bar); struct pci_epc *pci_epc_get(const char *epc_name); +struct pci_epc *pci_epc_get_fn(bool (*fn)(struct device *dev, void *param), void *param); void pci_epc_put(struct pci_epc *epc); +DEFINE_FREE(pci_epc_put, void *, if (!(_T)) pci_epc_put(_T)) int pci_epc_mem_init(struct pci_epc *epc, phys_addr_t base, size_t size, size_t page_size);