From patchwork Tue Oct 15 22:07:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13837318 Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11010020.outbound.protection.outlook.com [52.101.69.20]) (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 609C91CF7AE for ; Tue, 15 Oct 2024 22:08:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.69.20 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729030089; cv=fail; b=DR8v0V04aXm1AEGDwc+w7UKWm4DLxLdXkHwnYAcv/oXe60FW5187GM83Dv8cuAkaO+MAkAtR0WQG9QEGa9ERwgkaGV5869VyoLn3luKZrp9qokKSinA3We/EZd3ZR34V0h08sN10SISK52VWrYPt/PxbyzaBjp3HoJ2nYqWlOH4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729030089; c=relaxed/simple; bh=UAeOGcPYB4r9eUK8PFb6MZTw8YYA0IZ33NSNOk8EfxU=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=p1wgiatj+hWTCbXfgadrXbB5JrxW7OfCj6AIqmm3+PhWzAaXDpSLNDAYGC3SUAojzfzdKVQmThXanr3sfqhQVZkNHhp0P659VGg1BceH81P4VTIvqtFpp665mKl9PFNw2KrcoyS+HisQv3ncb1waTLqavjiWEvv4Sl9ORHGms4w= 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=nxN7KuKY; arc=fail smtp.client-ip=52.101.69.20 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="nxN7KuKY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mM9s9bJMAz1R3sMLJGDRUSFZXyrydEj8M4ztuy3RlNDabdc90u2zhxKJxbh8ZO/zVgeV7QLanRWGM+LG+ltFoDtCACbjxvPCbI1h+8bHUntMXSvR1tbE3Wvkxpdoccpgy5eNTs2vbtD08j+/vjc9fqb4EfHD9xgD8yCVNjPp8eaeVl2TkeCsLUAERuL69dlLTaUXx9Dh7C1TvVWULX0rB6SbjC6nSB6KqWgcUbXnKtQDNTQTh8Y7EU1DMLXlBNkJ0vOKw5ZJaj2tQvp+MxNNJwHZLfCGVM1MooYDS9QvbhbZPZR4zQ3GfkuSdaRuwmzBIQth2/cz2ze6t+D9CwQO5Q== 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=Zr2KqpZqpb5XrDUTkmOe8bdajmgYdiot4oZ3RjQBM0w=; b=gh6SMFVlFy4yMma36jmQ+0XwDqMaKTQa824Nrn0sl5ZOjqEA9Q3h+YuguK0Ai9rZ5PW0SCy7SNn90ApmcI4QmWA4YiWJtXbWNizuzHeHS7WNuf/CTlH7uCbSh3d0IgORkKuM5Rss5lvtg3ourOhA83kqdPgndqkqWkjvttCkT0yba2hAcMSgShrocA2DiaUuOvZ7ptZosdvPWyfd/2ZMd+Gchg2BpIpYgCd4Py+vC3vjjhEKJT2vsDkAxMlG1J+6jbE8/ow7+QvzfLzyZRAbCcfuM1fPOxBn8Jl8vrcdMTWiMPCJRZV+pBBolCkOP+/Eo/leEvVxnc2QfNtHsa+llg== 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=Zr2KqpZqpb5XrDUTkmOe8bdajmgYdiot4oZ3RjQBM0w=; b=nxN7KuKYSnChn2PTYvJR+zduQlNR9YZyZNobm8Vu0f+bJ3jU72mzJPKYZocs65Lrlvdby2UtgqIbw/V6XTil5+1X6J/rTESvOpMJ/Jc/5SfW+O4WAJtrcfBucl+MCEAQ4/605JhNxLFEe2MDe2phhT9QJ0b3eQCjG5h8E/38PcCAB5OWyGLBxjCW2HyuYyI2ccsEgiqiW9kXQ6n6tCtVNUsQK2+P7rNOF9dy+MUygAsKmi7HF6NtY7kaWnHRrAJLarlQPCn8ky2kmqg8dF+pvGJjO3mo/43L8IJDDGHScBsdlff9eWQupxMcHiYHTaDRLPval1ya62kkALtaUdjoNA== 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 DBBPR04MB7788.eurprd04.prod.outlook.com (2603:10a6:10:1e4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Tue, 15 Oct 2024 22:08: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.8069.016; Tue, 15 Oct 2024 22:08:05 +0000 From: Frank Li Date: Tue, 15 Oct 2024 18:07:15 -0400 Subject: [PATCH v3 2/6] PCI: endpoint: Add pci_epc_get_fn() API for customizable filtering Message-Id: <20241015-ep-msi-v3-2-cedc89a16c1a@nxp.com> References: <20241015-ep-msi-v3-0-cedc89a16c1a@nxp.com> In-Reply-To: <20241015-ep-msi-v3-0-cedc89a16c1a@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=1729030073; l=3066; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=UAeOGcPYB4r9eUK8PFb6MZTw8YYA0IZ33NSNOk8EfxU=; b=3F6duJQ0TcqVVtPOFL5oV8U1QskUO8PM3H1Gy7/b/4jHvG4fr5KMxRuWupP9aMcxm4cPVOV/F Mfwf/Nv//SkAkZtpcfn/hGK1qMFhqUXDzBzPdGCQDHE6V9TbZY1t5Di X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0059.namprd13.prod.outlook.com (2603:10b6:a03:2c2::34) 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_|DBBPR04MB7788:EE_ X-MS-Office365-Filtering-Correlation-Id: f5434e67-3416-4b9c-d4ec-08dced65d811 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Ztp0Xccjru7LZp3Amf9UsrcGnk0juvm?= =?utf-8?q?ctl8ZYSFRv+avNyETvqt0nSZOIwPkoIdYIKo5a/9kPz6SPAmrOj3LMAgTurENn6CL?= =?utf-8?q?xoBxxh0Yt7bx4M0MnrCGYkuPyyGMpquvu2azh80hW5MI/tFD22mMH5+TswpXGXYi8?= =?utf-8?q?27Q3HqDkVVUmSFDJWQupD5XGxeNkWPn59JDIe6WOne4PwAzNdl2sAnpYmOiiaOdTy?= =?utf-8?q?EiB2RRxps4qDRI5jpLG9r1UgLj5nwWy/hB7NKUYK5ntvgwGLYXZJmsZovuGvIfAGk?= =?utf-8?q?BMfOisopOoMeKlPNNupTeeZTwnG1dS5bOQoiaSdXC84j0GRA+TB7gm6Jmj2kinFlQ?= =?utf-8?q?kc2sL4lqbncR2MkAZhim+2aCyH+mEuy2F4aj8lntkmnUfLZUL1lltqqV+IHa6sWiI?= =?utf-8?q?yJFVsKml5eXxrVKF4CCtVXu546bOG3oJjFSYcVvs5y9kbOGBSCb+l4EvPYoztRpJx?= =?utf-8?q?8uNQlXR0uzvS/6v0HIif42YQbG+8HAD5FtUSPGkwGotyCWMLmL4xu+vFXGZlEyMPz?= =?utf-8?q?c0Ew5ziroJWP/2tnLxBJV+Qz8TMBjLPe4+ynYQefD9uco5OPVeCZjQ5mGsLZLqEko?= =?utf-8?q?PHy5hZHyviC/jwgZpFBTi8I10LXdQLPhTNInN8PU1EW32/rjPDjAGptHz/mlLXbEM?= =?utf-8?q?axVPlTuEKp4zOv49di3XOnpj0/BlhkmxD5PBrL3Zg64JOkRWU1jCM9xg+bAi4zGoY?= =?utf-8?q?Ivk7tw0SaGAHg1ax34ThsGCb4XB6ajRTZScowNpx2hY9xeT3EWnU6Q0okTGcl4vr1?= =?utf-8?q?FyR6CBm0ojqKpVembk7K9H+uBDowL+BWUwY6lgYSBBrGZzW+ixjLFt1pE00ed/+tm?= =?utf-8?q?QuNrkTZrTMn+4c+slqbbztrqoFHNYS6IEf/HIT43puWzqbYAjCSOK8UQwWf8nyPL/?= =?utf-8?q?bsSUpwySCzpHTYmdz4MEBBzmYoOcjMbQNRRN8GUgdPqbMMUPWeqv9izBb3Qqk3Pa+?= =?utf-8?q?ZJ1DjsnSORNwA90xNZa8BuOLU5Vl8VEG50mAfyQP7eHGXnzRw80w16f8Tyimrnvw8?= =?utf-8?q?WSgFGuPJoeTF3Y0vyhNkiBX4kPXeeukInPTKZKEtJcPQwX8uG65/njY1GJTgHdZ5P?= =?utf-8?q?nIxFzIw+CPz38mdz0xw3PxtcYSvGgXpluCou/lPuxRjy7UuUnNYrItSi8R5UczU+a?= =?utf-8?q?9oKvUdS36e9y88rjRqPMd12UW1fYhoB5CkGiyNMLvl6hGhvK58vfXN8BgTqJ3Oblh?= =?utf-8?q?Rxc52KxV9f+0RCpLXlZp+oSzEQi+2dO3k2UPYNOgK32ByXFmRWdrYv5nkwHK7Fn0Z?= =?utf-8?q?qqlIoG6Ozon1RWDRD67OxbeqEle4kjWbFCA=3D=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)(7416014)(376014)(52116014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?MI31ZfHR51rID8lgTJCcd0S6FxiS?= =?utf-8?q?4oyREKgQdTs5dRjqLV+gxx8hRNH5sEoPLGo0P/iOFHgAfOITJaAz/8d1XvN8cgvuQ?= =?utf-8?q?imj29EVeWnrJgRpA2Qxztctv8kqwbH4ePEgmaVwNL+Fbq3IJdhzlql6zHhL9rNmyM?= =?utf-8?q?QJlBu4WoPbDk9KL8WuJFf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Lsip/8yN4gP4409kciLTOwGNDguQ/v39g8RxKyQu+r2O1O?= =?utf-8?q?I6+ahx5o4NDrSd8bDl52YSSH3wMPCRvdgi8IMwTTYigGTl8fd5Ni/1W0f61nA9IIo?= =?utf-8?q?wCNe68V1PaKv4zTD6ewVLdPMOSGGdWD+6SNO40GiB4Be2DOcYB/ePJ+dRtEX5ptaL?= =?utf-8?q?UP2MrzOJU1jmJe7/MQRLuSPln2uM+J42e5vQ3mQsFxc8Y2hBja26xbew0BCZ+FWg/?= =?utf-8?q?D7rnH/pz9015lTy864FSNA5c6WfseFC7ZwuDCMpkNgSdIFa8qAP3t+MwkIjOn3YyI?= =?utf-8?q?aRYwqwCaxWUFh/k+KT3gmzupn58EfIv6+yrdcbgxL4TzF/G/agmHQo1QL3GqQFgBM?= =?utf-8?q?ZZKIlO85xXRMgYClXrqYuWGXuVxaXQWdiJ2uT227wplgy8A5cJVtaGL+76Rvt2OhB?= =?utf-8?q?6FfmFBjlDGQdiRdgCCMkHf88lXIyP1r8MkNNffP+yQBAoAZV9HgHYgPQ=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f5434e67-3416-4b9c-d4ec-08dced65d811 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2024 22:08:05.3419 (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: 1zUJIOBKA94J9XelJrZMX5hCCdpoQXAJjgBxZ/mfBvkeehhEc8mqkJPbj4EHxQxeVHC9EgqoKOkPm94SiBZgYw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7788 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 --- 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);