From patchwork Thu Oct 31 16:27:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13858172 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2051.outbound.protection.outlook.com [40.107.21.51]) (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 3CB991BBBE0 for ; Thu, 31 Oct 2024 16:27:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730392043; cv=fail; b=Vv2uU53X1OH4T7XCr1jGk4/yUVpX3cm/HunQdDp7bGE5r0owJyJLaogpIJGutAwMGtFYhs+rsSzbDMM6it848HK5CI3QJNVULJoo89I/2cbBJ6k/6R/CO4CePEEMa/dG19eLCvnndBQM5+/eg8XVPIb+45HU4JWaMJfEJkndHVk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730392043; c=relaxed/simple; bh=WztdJXCK+bOn8jeGvfQAh0AF4COBEh+c0a1xNE6MdUc=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=O222GVxHvhCZCLSP4gL1h5eYJgIABOnto1AMmZnGCua8CQ03p5FbPwUv+H3XmzaaYvDDvMtJrNM4UYomsLmk8i5TCfflKuA0z/UMTeKOkPSEMW/6aS5VrufrdKav8LBi7XFSmT7m8RppEsN0XrFZGflIdQ/g3gZuAes9ruOywS8= 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=Bz+Q8Wdi; arc=fail smtp.client-ip=40.107.21.51 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="Bz+Q8Wdi" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OUZIFn7/A2V2TsW3x3N3GGhrbAD1xOCpEfiCUuKW77KckS0+SjK/YdH+du9TLwZiUKCKUI5ff5O5xUiesTE4FfLTOsMkCjni6oQbrlwE167rdhBlhLjKOa2y077LNl37aqstITiZkOsN3eWI+Dxk2WMA4ryFwUDgQ3ghBIIOc6PkEazsRE6tBNhp77Msp4gIeLCvUX9UmY5TGzX+uqCKteFHexGs+PqHiNwtWJIyH8IkaqI5uZziSvFTqeYNtd0mW7aAzX/+sIt39QtKCngzvRTWCaHs/c30qiT93yMS1WbqvgWPUrdPfL3tQstQPfiP9BmXQt9dmC6uM5fBxsTjhQ== 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=Oan0nT460bnBSfdOKCXlsarwBLEOZ6HSByQIFZo5Sn4=; b=rN/wty1IPczsVy4Z+8AGBwTW+oUQs/hvWhoBL7XBY6JLSngz/GLrN1qEsghctkdU9I1BAeMHVouQjC9CaQBRyeg900pptNo9BB41thQWsYHaVRryVhkvhFGFRals8xWloAQE3gXvjJ1gnjDCIK52D+/Tk2C2/H1gzG9KlGKbKIGGzX0mn0nhNDbp+/eDVmWcIgyIsObPKnXCInCvnipD9kWy/Eb8Fwv4VxWdlth70hpacaHhpp0uGV0tkIfW14+WCoQ0zipnQrFJg47MfZcm/hKF1D07h0nv6rZcvX2T6y4qHHrt2KKGcUE7Bc1nqxwQB5ADxxlhNFEiYIdIHxCozQ== 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=Oan0nT460bnBSfdOKCXlsarwBLEOZ6HSByQIFZo5Sn4=; b=Bz+Q8Wdif90oVm6wCofNWsvzKqPytHIH7O7fij6LknfwV+XPrLCc6RImiqorCUal+bD2w2ySRwRJ5msUz2AlE/GLU50NY6OtsvRKrZvdVMGh7n9fAPIm2P2lD2mf+xGjf1zIB5CCaCnVERkiAMzW/Klx9msoRl225jqmPkEK4+lYIoFpPV2R5fvy4nNgYqRpz+ce1J+coam/cw6+zzQW/jmQKlZjjdKfSoNlfYMk62B9hg6WsKueoHnFu+gdpE3g8QjhvCh6e2JLXuW9xyBR93+BGaMM6Xa7Kxp46rxiypsWPBKpSYxCyu9XaziK1TRVix6Jv7xGC9jHYwcOQ5yzyQ== 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 PA1PR04MB11081.eurprd04.prod.outlook.com (2603:10a6:102:485::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Thu, 31 Oct 2024 16:27:17 +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.8093.027; Thu, 31 Oct 2024 16:27:16 +0000 From: Frank Li Date: Thu, 31 Oct 2024 12:27:00 -0400 Subject: [PATCH v4 1/5] PCI: endpoint: Add pci_epc_get_fn() API for customizable filtering Message-Id: <20241031-ep-msi-v4-1-717da2d99b28@nxp.com> References: <20241031-ep-msi-v4-0-717da2d99b28@nxp.com> In-Reply-To: <20241031-ep-msi-v4-0-717da2d99b28@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=1730392028; l=3101; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=WztdJXCK+bOn8jeGvfQAh0AF4COBEh+c0a1xNE6MdUc=; b=5R7ouNHd90vplufWGmVJaXnpYoRGO/hg16Xps5b38myeJ5Rvm7rUk9iQDjrnayCIReb1GHWsh I7Qu7uZx4FfBE8DwSjryyLQy5AqsqdkTvNlxPbHByxwA2nccdUyPCrd X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR08CA0056.namprd08.prod.outlook.com (2603:10b6:a03:117::33) 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_|PA1PR04MB11081:EE_ X-MS-Office365-Filtering-Correlation-Id: 1af4b9e5-ba50-4a91-2294-08dcf9c8e20f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|52116014|7416014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?s5xAVL3CvBH00V/UeUJOCvASOMSwKML?= =?utf-8?q?Uv99iniiY1+SfZNGzOHLtrh5lY+A6H0ozJbWvWJgSRzrrwW6oAfyMPFPz63UvhdVt?= =?utf-8?q?JL90ilwJu7xu6w1q97zzQVLSYqPK0pP99a68TgtdPEfETHjAUOOGGwm8yUg3SeM9J?= =?utf-8?q?ftrtdkTS2nXLIezMXckbL42f60IeKjQ94U5XH6m4W7t/kW8kAtfksCnB87K8LXs3Y?= =?utf-8?q?F+HRzDquzaNCRhpUwu71t187LdMRJP5r2KSjz+0KnqJ8/uMwxjuNtxstjCCPKc1+v?= =?utf-8?q?QMiDiqfv8yVanV6YKf3W5LGBswXg88g23djQ7uH895WETIawrq6XXvKrog0P2LKfH?= =?utf-8?q?0LbfRqA65Tx7meIcl+ZYLz1d9krIjSw0hGXB3Jx8yZDGlEEqEuxHsO8khp6OKs1Lj?= =?utf-8?q?8qXmfODepWXoVYPBlt/Dh9ZASHqPyb3Knp98uhfJ5M23MzBC32rjo4T8liOG2b2OJ?= =?utf-8?q?h/Rlg0U7iDeuw9PVGlLPETkoiMKxAtLvjGgHKz86DS/m8KwWs/XETINQ6LPlWZ8pf?= =?utf-8?q?GWj06D0rhxjvwl+fpnMNiVOplnkMFe3UdLgv7TN70CGmrW55cJ6a61Qlh7u6OFjj4?= =?utf-8?q?i5tyaay7J+6fCju1YzvgeqUnWVDc0IhQRIG+lnlfSMYeHQwYXMYRxCQyqoP8Okzgx?= =?utf-8?q?1etV/a9DXhg8kCOF2+WrhGq99HQBQPhduHlsAE25p72/uUOI3N4x0eGKCoiAmnRwl?= =?utf-8?q?j8bBkFATQBeFJ0agcwObQ6rA5L8sNaZcjLGckQlKfac2xjjKfz96TefZRuTebprP1?= =?utf-8?q?ouC9xnsnnLhX5lZA2Xq7eZHFoz8/yUaBYicYl/xSICdwC11bP9EX2r3EsKZj9CQ12?= =?utf-8?q?bCHcwAFGjzuYrfdOKf8yLXuLBtL1z+MFkSjSTt7e0XmN6QvFTiA838x1Ksf59etig?= =?utf-8?q?kEiRn3XKn67zznu6hodCLMzkJSHCwsYVqO5oYETVidOhh7XBgZec/DFSWoXN7SnbE?= =?utf-8?q?cn4/pD7Eb4DEWqsXCoXe8bPJQ7O064c1OA8ZRP6WhyqN7LCWgFMrAIM/gL9CUovcG?= =?utf-8?q?uklE+iEc8HiclKmukGaGtinOPUK3VbqVGGWiSC1T6c6FcuNo5tjiztbgy+gs4ZnP5?= =?utf-8?q?fOKDu3UnHcHOB5w+PRrh9/Y++3MgoPqFPoQTqEaAWNl8Q/ml9u1KxZRso7JOI6/Yt?= =?utf-8?q?PpK5VDzob+HBnYTAIyN3HIZ1x9jAI2r3vz8boQvETj9R6TOnwqF2nygf2VK2+nSco?= =?utf-8?q?e51uFskSvfc1mj1EZbz7cobgibSac360oQKCR184F8roFc7/hBRSyNNkYEiAvhFo0?= =?utf-8?q?v5Ew6AUNNnNRnkQEtLYZh5c+5rBeI+vVK6vsn262O7PWhYMVb7ECZVMc=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)(366016)(376014)(52116014)(7416014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?rpgUtSHOCTCAa1qDAukBEtDJQhDJ?= =?utf-8?q?xW0Rndgxggi2Lm03Mv1Pnb6CuP+q9zVkXo0qGSuEGyCA7uNPPYaCOat/9rbBttDHJ?= =?utf-8?q?nbPKe36ucMNVwC4bWf7OGbnstook4N1A93+VpXfKnqG9wGptn32fMbtj9d4FRo+h1?= =?utf-8?q?zq3ThcacvcofStbJbiqstf/Q3pJ8kz7S6uRfTfGCJPHnVLxExF4IaTOvhlAZHZ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d+9owoIycoin?= =?utf-8?q?YdK2jPCQAXYqa6prioRE3jLKHTKh0B4ZXnHewiqOv+FqOuF046i8sw/xu6+4c9H0N?= =?utf-8?q?B+OXL6/GtvJd6O1WqUQgPf01silMNqe1rkXUT+A/d7jLQIGTf8dTlz9VO0OEZoBcT?= =?utf-8?q?G6J37fXL78L5EHKUcYUJjM2XQilphgQM7zfs+FWzuNegIkyMac/SNq39JZn+9vGFw?= =?utf-8?q?H6BM+Oc6DuDQfauNygQdEy9gBx08duHMAIInnjf7T8UO+703rN9tJIBAMsadX/4YQ?= =?utf-8?q?o+zpl6RWvCDWyFbLBSCqRecA7IMxgAxBm7EpxT9eoZ7rV/kyWdQ85eSzAbZo+aZAL?= =?utf-8?q?Fkt8NcjlouuJ+ZbpAaRtf11OcZEHdT8y8EcmosnQeor2whEG7TXlos+odJ5EeFWMd?= =?utf-8?q?v8SfbhZRUqmDkLphNiPIawnxcn4hrNzjazs3Cpskn9i842s9t0psPbn8=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1af4b9e5-ba50-4a91-2294-08dcf9c8e20f X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2024 16:27:16.2338 (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: 8gtkQKvmiGvI98OyIatVYcmvRcEYlgXl3v6i6O2ByG0jjg49qgoajaEGNbPFX7JKg5nJvj9/3gAVT1wDlflBzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR04MB11081 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. Signed-off-by: Frank Li --- change from v3 to v4 - 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 17f0071092550..14e6011df4b2c 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 42ef06136bd1a..682808f4510be 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -266,7 +266,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);