From patchwork Tue Nov 12 17:48:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13872700 Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2053.outbound.protection.outlook.com [40.107.249.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 82541212F05 for ; Tue, 12 Nov 2024 17:48:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.249.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731433723; cv=fail; b=DBvQDtBhwcIvdtM26QupXvMlG2mcpyqjS9ljjlh2z8moFAb7jJnaPH6YJ2ZmHDe+6eG4nIIRpg1h8pzkP+NNX0ULCiXHDrTp27pc1R4iBHiWS6BSfqk5KJolz2le7Cl8zX9fZ7COZiEzfKSMleWwYf4Nc0pFglK6toqD7gHoJJg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731433723; c=relaxed/simple; bh=61Lz+aGDQkYpdiQf7LVfcFjngzuH5VC8R5EMQvdL0Ao=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=HEhMSvdWIEZxn+QMsaayE3s3S3XkT+1uRY/ZDw4Vy060fSUqcGNGesufj8K8kfnT7spnbXwZ979Q4rgShZD6QVfZsd4zQYxfYthWHo7wi4bzdBzIUo7Ole/RrnAqIBF7eVKy6fJWGt1KbEegxugEHxTEblxAJdUTZGyVg+xKfng= 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=h4EMPc5G; arc=fail smtp.client-ip=40.107.249.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="h4EMPc5G" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qBL1lA1iUKa/zM1+ZDwCL8k7JiJ0yFQvcoVL0MeD1z9gpBS/o9j2IvPzVsur9BIIGkC8DmudhbZ+ssTncwaf278ksP/pFxmTZHzfqH0dgwvbjo1ofcOS8pBY5eSY30SGDmTdczzsNLCDav82g5USm7LRZ90WWBHMNzVq6Qja73XchIWQTmNTZF0aauNddkKf/LVybMn32HEAqt/9ZiHz4sB9nScnD8VLtYziXmLZW7cYvwSVoQ3icWaN9buTJWMdXoZWQi3l/nEUPjZftl/BRIbSl6g1KWoIxdBJ/SfHoF8REf6o3qvmsFz5gJgSfsPmQ/+sdqn0pZWhyNPS4Y1ykA== 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=oBHqw5apHMvrrXufyd1Q/VZQPQg6/TA5tygGYqkmzJc=; b=iEMfnG4C9eEBrIC6DEQpluLW51MctiamrXVRoE3kbHVQtxsIOhsLc3c8N0L7jLztk/6BP72JwV69BPVO9nd/fNttnKSb6QAL/w4ZBqTWGYms4av79QRpvXD7Fma2uZhmOwmfs2Vvwi/KqrLpvQVAyuVNq/1i3g1arYOEnTfYD51D6lZ0L3azYW5MxOmTgr6E69MO+lo7cXKFl8tg1Ogn7Nay6uJT5ffiYFtbpDiabPqhPf0/LB6FqZRNOl8C5eIk9rhqpqL5e2rV/TCDD2x1MxPw08S8NKUr4J4XT+5l6blYHh1HCzHOwmiZcd7BhjiC9DeXS0Z0lO7J824xqrJUPQ== 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=oBHqw5apHMvrrXufyd1Q/VZQPQg6/TA5tygGYqkmzJc=; b=h4EMPc5G/OaGpSPvriP85Yd/7zGBaNLnbBIN0glCiMUpefrZGfhcJnIXyvN/aREknF+RLaQSM5Yaxe0gjSpstFJskg9Uzbd1GrZv3e8AnU38Sp/sy2h7D+SqrbORZ2LBtjkh9htO6o6EbUOeyuSW9tdKkW2T085U+8Dkv7+cWJrBgwprwsTJfYZemkQolf/RNBbkJk2OGH/90tnIj6I/Fj19c88yLLnpzO9FIecF55FjuN1dIPno9ZF/dY0BYwJUcdmh/YUZC8SrZ+dd/xyIaCDADuY2Aq1FEyo0XYnsHnvcvP/BNBugwWW8l9v//ZQHGPMn0oQo9bKe3LTT9ZL5Pw== 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 AS8PR04MB9510.eurprd04.prod.outlook.com (2603:10a6:20b:44a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17; Tue, 12 Nov 2024 17:48:39 +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; Tue, 12 Nov 2024 17:48:39 +0000 From: Frank Li Date: Tue, 12 Nov 2024 12:48:14 -0500 Subject: [PATCH v6 1/5] PCI: endpoint: Add pci_epc_get_fn() API for customizable filtering Message-Id: <20241112-ep-msi-v6-1-45f9722e3c2a@nxp.com> References: <20241112-ep-msi-v6-0-45f9722e3c2a@nxp.com> In-Reply-To: <20241112-ep-msi-v6-0-45f9722e3c2a@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=1731433711; l=3147; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=61Lz+aGDQkYpdiQf7LVfcFjngzuH5VC8R5EMQvdL0Ao=; b=JfBGlLbUICVEhgeq1pCm2JEL5YtsQO+gOFr9hG95EmvmL14CIRu9p//oyfgLDJIvgJx9XO7Ko 5WY02KqrduVAkmrx0gA9rBrV1uF/bcJAWy8H3QdO/CChFUV6On2trZ6 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0076.namprd03.prod.outlook.com (2603:10b6:a03:331::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_|AS8PR04MB9510:EE_ X-MS-Office365-Filtering-Correlation-Id: 2cbb45f0-b439-4e87-6e5d-08dd03423d84 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?uZ1FM1wbEh+lyRGU1CZXJmbxl9gSMrj?= =?utf-8?q?5bbe94fhPnQCkKGEplv1iqZIpsfaoyN5+CmeG6cjwWj+wAEcqF5DYuZ3XVbMB1ZaK?= =?utf-8?q?ENMUvRgtMMlWmYM3wmnp9kkbi/9CwEGUnEKGyUcg09/UXCr8ObM3fcsG0xqc/7lMa?= =?utf-8?q?rzZLx9mnvisPQKRruwZgDe0kCnvkCpS6F5qJXglRuTGm9wzJpY5IxNvdr4GGuVbHX?= =?utf-8?q?ILIUSuni5EWU/N8KQJ3eR+moiYM4ud46hUOmQBdWvL6T/F6pu02eqdY297HwG6Lmi?= =?utf-8?q?wb/Tyzu1EMHjnvyxwTDykpKz6MHQ5BA1gaeaCpDI59FGFiSwy2dlWd1sgTEIOX/LF?= =?utf-8?q?udfsjxQdowwcvk93lFkAcOZBBerPukKqeYx6ylEtiEW3qEivUNEGPqjpQuHSwBlTq?= =?utf-8?q?9lvxVcu1zcZAD0GipIqv7xVWWaRXUlq94eDaL9XC00PyV04tKzjcTLkIKNAWWE7TO?= =?utf-8?q?u3OExU3Ywy5+sUT5InL7kt7SPb7Ur2YwIeOMTY0QJljcKzjmEhpgXxGJ828UCYkxI?= =?utf-8?q?2RHbRNwhVrgT0gNeyy46UXpkPVaUGh3DSLWyRQOV2eOZf8RhBV0h4ufG5o77MWf0h?= =?utf-8?q?NHyIv9rytESfIt9umQNiciohpZSArHoCzkAVYwHbUrQY08YlV94bP9Q20B6pIq3Dr?= =?utf-8?q?CQyylkWpJDEAOQzwl5sMz9H3CEMh2FbGCzDJdbmpr5ZjaKvv8baHyh+c+JdkL5vOL?= =?utf-8?q?prgpLeJdiqHSVanwPl9o6BwXYLGjBXXxqYa5iGNPs8GtTd7olWS7WyNKoFk24hX/r?= =?utf-8?q?cIddl+BNR8e7UzGVfoj62MJdaHVxmmI/vveovimrwKT2wWFx1oiKyyPFsxFviqsBL?= =?utf-8?q?/atpAZmWqEN+bY42KWLl8sfrmTE5smghWqUgO0PkGpvNxo4/X8WFxw0T9rbrOMGgo?= =?utf-8?q?oH66ouweKyMTe0QWw/4XMnN6OfT9iS8ckJNvrX70lYHnmV6eKYyWcsrmooOYcgv3h?= =?utf-8?q?QW+j+t3aE1zDaG68YsWl1PpI6F/huZyzQOd72svhGVTtMqgfepJ2c2efLuz8VKTkb?= =?utf-8?q?JJ/tQmi/Q91nQ3QeXdZwImhv8UYeUPQTw/b/+Ru4Z3WR1jmkSGMpLd2fiyX21yvca?= =?utf-8?q?wzISbELpu/gxsISo357encb/MRdNzstaYCY8wcMeO4m49eFgdI3Di4fsmyVSmFo4P?= =?utf-8?q?kaHKIPOqwOGo0LEsGP9GtUB8gEKV8xGDzQYiJnKhRSRKqeV9362v3dfZ2AOx4TZLi?= =?utf-8?q?92dPi/2ON2CevOU6zPGGr/0py6LZy1+gNjdhSgOod4BbLCjfl6E5iU0OYiCEnOLC7?= =?utf-8?q?5wmZt7VeDi167NQtbomJZeet8hxaAwAcgzcy9xu3RXgupvh9RAefJ0mA=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)(376014)(7416014)(52116014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?uEJH/KOeUiqUacKQh+zca5K0iCxc?= =?utf-8?q?w7vR6pTFj5sQVMd8xDAyJxrSUD6mxe0O3ms8VCqdf/G1PeO8hkeZUF/NaHMpIEdP8?= =?utf-8?q?X6JKrHV0ijl9zgY8p0NDueX9FQm09LC2PI09j/vNe3z44Z39S8+EMTmi1A9rVZgUb?= =?utf-8?q?7NpRsa4G5XKgxWUfsSvualXK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z9xCD0QKvj98zqccvKJBUdAMcaYLXb?= =?utf-8?q?62KOK9hLFNz1iMQnB+L09fp8jpphDbY7sWZiV6Oy0MfOPRaEs6FVou3konipwPDRz?= =?utf-8?q?ICf5i9Xp19PglohwGXDON14bNJxc0Ku6JBuSBhAPsAvbEd0H4bOkQc/KVqhPffmJt?= =?utf-8?q?EwqGi97Cy7vhYPhJdbcXydcTEgTnX/jQrMNJ1nifUqXM3fgylSgCWxC0gzzBVnLhw?= =?utf-8?q?fh29Gt8NiTRiHJ+/t72YQm9X0k2l5Dgnzr3xZ3oM/uF7hz30xOkn3KiOTWgVGqHHH?= =?utf-8?q?nKoIsHBqGoAEagsL5WX6bM6c3xjXgbtMN/w+/sAHkNJuWhI3acYN4YrIFiz5fC2j2?= =?utf-8?q?pK9ChXhB+m7RwhJnXsBrlEfENQzOrVdE8OTEyG4z49VY5QRdzlvoF3yu/hyWApDlT?= =?utf-8?q?SH2WKa5fBqiCCM9iLJZBtTguLEOv8NIclChtUozUrh48VP6rEJH8JrgY=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2cbb45f0-b439-4e87-6e5d-08dd03423d84 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2024 17:48:39.2573 (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: xQGL0p8n/m5JTwcLA6YgLIT7HH/XFQUKEJUauZjfPOCLMSPgpP1yh/n87DvHHWmcvZxdNTWrZzq7V0JaVxsYhw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB9510 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 v6 - 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);