From patchwork Wed Dec 18 23:08: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: 13914244 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2069.outbound.protection.outlook.com [40.107.21.69]) (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 33B5D1FCFF1 for ; Wed, 18 Dec 2024 23:09:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563355; cv=fail; b=hNdCp9v9P4S5sf1LQoG+Ntjma4Y4MhtOleEFtCRKTRf1zUx4YelIwD+JrrNeMboUHahOJ+bnM8A1tbyI6ym/qz5t4moyP8DzssVH3vN83n5wz3dH0hFbsIaL7tZUVCn31PzQxUiJRsY1HgMzDwpU8p78PxehT4g80s1XQJRWrww= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563355; c=relaxed/simple; bh=8xX2O9aY64VFlNrJ4JMgzHNkAgqXMerbLBmBZNQGjz4=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=Vp3FWxkjvOyi3ADISmn+0nTJPEVFkp86eSWpErozpaGlreRyvoW3SZUA8ogfbwoaseBRP4P/QDcpDoFDl/sN0oxefVg6FKBm68CCsSwFqTEGRTqOarhG3LhCzji19hI8aJnsDgNUo1zW9N4OxJNysp9XiQoebLbZKGjRf/BynVY= 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=d9tYeYXh; arc=fail smtp.client-ip=40.107.21.69 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="d9tYeYXh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=L2odVTGpHsQGT4I57ySQgdqfrpU9ngIbQQcUOg3Gbr9/QorDlBQUEWmeXu3nausyWKWKNi0WkWghSLEBw7rWV4r61LOdR/1/amnzOqfOk2M/Pp+lLirzhDIct8ludNuUOCCaFJgumI4yeKi4fwQuLTXW+B/pMLfrUEpZ87Xlv6zv7+B3wg+4iS0XD3yIr5sJsK4KLazhOf1P2SCCVO5bOHh0mWyPRy6mIFmR1ZGzDiV93hgHwdZK1ftBvt0JoDP5Z5f/z+bTSqHv4EONy0ioqVYo2L+VXn28zznDhAL1V2PYxmPEJaD+42N4024aBzBc8swVrekmRGmSFNZ8eZT2zg== 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=qpwCdcZnpLhPQg1A7kmXJAjEvFPbhbqVp3GHX678bwU=; b=qPAM/ZpXQNEGFjxANvgBO632EEWldEWzZ9D8wSRL0LuVrzIDEKGmPi9Is407hKpqR1ORBgeBup6LfHQy0cx82/AoC4GBEkY0Pp8iNHOmtIa0bzqim16vbbe5uY1qautQ4gH2qEZoPJAVeMFYwbsZQtsKeN0/Fh+O/sG464c+jZ6R4JEn/Cx7PJMc7yAyBJYsW758j743xqcM0wrHQhIc55PPxdOAIgrRZvScgagLC1G9RNGLhZKSefjAtYSLC+JFosMNTQZaB7Bj7R9kJOjJLIiKpLmJ5VSg0ERxnorog4/ZrEdFW9c+gaZ+PFyJB5kl/SzSQYr1NKfmmvzxxxoJBw== 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=qpwCdcZnpLhPQg1A7kmXJAjEvFPbhbqVp3GHX678bwU=; b=d9tYeYXh38HYN6LSwAabCbAAh8zSjgbD/xDUIn9LVbQNxvSWHFkXUsoMBm5AxI3/2Zb8jCefJzsuBB1pAv2NoL5U4XmS0seawniikuJMIIxW0yQfZZUwGin1R2uxBFktrggP3ffcPSF6BEnf0/xNTBop4qjoXumAdY3qTC9b0aXU/gUUXcv0vlZtv+8sF/DbdL+BaIsnGgWwycNKpoRnK0hV7yfg9g82Q6IUPg+bWM1twBuiriTVA4ErVO2/Ez1I8/MsUCyFj3cRJK6gRUhg4qN+kAs3Hm3FVLuhP/Nk2UHbB1sNvtFVf3cX4X+9noZZNzXK2V/ZmX5qPrW8B4nKlA== 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 DB9PR04MB9939.eurprd04.prod.outlook.com (2603:10a6:10:4c4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.22; Wed, 18 Dec 2024 23:09:12 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.8272.005; Wed, 18 Dec 2024 23:09:12 +0000 From: Frank Li Date: Wed, 18 Dec 2024 18:08:37 -0500 Subject: [PATCH v13 2/9] PCI: EP: Add helper function pci_epf_msi_domain_get_msi_rid() Message-Id: <20241218-ep-msi-v13-2-646e2192dc24@nxp.com> References: <20241218-ep-msi-v13-0-646e2192dc24@nxp.com> In-Reply-To: <20241218-ep-msi-v13-0-646e2192dc24@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 , "Rafael J. Wysocki" , Thomas Gleixner , Anup Patel , Marc Zyngier Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, jdmason@kudzu.us, linux-arm-kernel@lists.infradead.org, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1734563338; l=2838; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=8xX2O9aY64VFlNrJ4JMgzHNkAgqXMerbLBmBZNQGjz4=; b=4g3MAO978FVxgvHLb5QWKbUbMkZqfKtyTdfff+gf+cXJVSTis8LFOmkaEsaV7iJbi37aX4tUu bwAocx0Wl/pCT8ZyKH65Y7Mshm+6cJDZgx908faRugQGZ7F6i19R7V3 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0075.namprd13.prod.outlook.com (2603:10b6:a03:2c4::20) 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_|DB9PR04MB9939:EE_ X-MS-Office365-Filtering-Correlation-Id: 7c48fefa-cc85-4491-8ae2-08dd1fb8fc28 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016|52116014|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?JG2BBmBWb1ImRPX1BU7mRsuA2bP3d22?= =?utf-8?q?sykd26pUU+vjlsWVpzPB0lFTjQxs+J61y3nv9mVSWKiu32+CgteFw5X77oxzTL6bb?= =?utf-8?q?3KJV3YnTSEhw9eIrTvA/qzqnuXYUZrmjn16AHQUFN76xCRe3tC+bB9APKNpBuQClU?= =?utf-8?q?Cy59EpiW+B7tJs0kK3ILm0ac6ycqAVOWgYq+5yLn5cRH/DtDqPDTrkJsxklLOi8nI?= =?utf-8?q?A7exg+RmzhBwUCLd463YY1Ec6PFzvylcsHFSHBQoOJ0AyYRVnnNhuvvhfYRV92IB+?= =?utf-8?q?lH+gC309BI5JPaodx17oF3oJj/9J6VArUrXMG5YG7bYMeMbZxTC/2fz8Kh0SNRqoe?= =?utf-8?q?wKFT7n2il66PfRo+S2neK7gv23DprmLYdX0Cs98CcByg3mWO5X88+y9m/YjbaczNn?= =?utf-8?q?bT73rjqEcEHiDWGFHDwZLPuhNGaAnm1sbWbrk+YF3TWn3FOLh4HdM1mG6rRNBdECS?= =?utf-8?q?l5YnxxZMCKVT9fUhhAxcBZLhTnU1pDiR3BEpxyu3iHLpJ9aiiJnre5TKe+LRidEI9?= =?utf-8?q?SSRN/mLS/5utpEkMq5RddUakbNP7yWvN0BCCkVQzOtcyRHXs5KOUpwyEm+R6oxNYR?= =?utf-8?q?7ICHNvKQSpXshv1P2UMYKdJmaXOGOORp+OFKk58SlOozWcY3O0CBVJXx4hZGDN74R?= =?utf-8?q?vyGCAOvqUz3VVNkLwzGtZLjG2yW8V8hqztqf6JNBCRhofXBG0sZGeZMtU1lMgmLlo?= =?utf-8?q?I98LAJfw8aBWMhK2h9rid6Jfp883Q1TmpNq8cgJVNR+IWkNN1oKswLNoQZWDewCV+?= =?utf-8?q?27cTOSKB3ewxldJ8WUtbiWiIuJ0FwxBU0yWShbbQByLbV8930Eq2YxZfbCAhG5GI6?= =?utf-8?q?rxbkVqo4VR8KzmL60094jWEoHklIOOrAloXBhGWSYUG5hr6PLjhmCL0/yMY0mD14k?= =?utf-8?q?R4BMcD4B5tBcmsmlyNyQzFV5G2CxIz2TuWFw/DwhBAPROZAVTj680OYAbKZe8gcn7?= =?utf-8?q?OhqZEd49QucgcRfP07bgquo68gIDFgTkGog32710n2aUM3M5pmq79LEYapvOVkyJE?= =?utf-8?q?R6ib7agqZIU5xBcUzoxj/8u7ojfvpVRFsqAx6wUDvU4HuYGhX9aYRqemWbTFSA7Ju?= =?utf-8?q?GOsFsT47KBd0/vBRJKdtzcGk7DdKBZIyQlffsUIu1sSMsdtVeWFNww3SVchASwTzh?= =?utf-8?q?HiFpeW2CIcwtSPhji+W5mTcPmJanH1bIT/CPA0kVzXAU4HXOQ68uMsDA/h8wJLSrZ?= =?utf-8?q?Iav0tyOSLlYxoQv7mhD8yiYV4r81Nk4iiDp6X9QkMm/RPDV820IR/GowqBaf73iE5?= =?utf-8?q?oDBki1qU+i5/EczVEWX4284mS2/dPaoic4lhApKgFOPZLpBmM0GwPm5kjaGstXHrG?= =?utf-8?q?zMacOsUvMp5E8HmMclGBfklBonBAWmWqAtzSIqUL9YKDZYCPPEb61rTC6YljfuKhQ?= =?utf-8?q?K/xJN/+sNla2W+ttOIIm0Y77ozicK7aLw=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)(376014)(7416014)(1800799024)(366016)(52116014)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?AWLusw7oMpN+LCd4jIAH3mHoMlxo?= =?utf-8?q?lLAHwJfCel+MQZiWHIYEd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2rN1AFaiCV4iR79Y7xthM3wX/cxLgydkoWuQ4jXkQYs8pho87N5tn?= =?utf-8?q?L+LQS079pos2PLm4I/+4mCMxmqGxBdVS2Azhu4Hg4zDEDt+z/XvT0pxGewMnycKPH?= =?utf-8?q?moWzRXPRopD8/NRK2U/u5BS9fJRHgdr2hH50dVlbZi4jhCSWeAEMUD71W2C5QpNBu?= =?utf-8?q?KAlToi/0TADzJqnyEXZzgFdCNzfK4ZTf/JA2n3XyXbzcoK9LxwVkaFohKR7B5vvQl?= =?utf-8?q?FdQQND65MwuY6ISw+GI22bIiBtwo1qU/LV8J6yX+zEOupoGdJvX1VGNEv908ThNhj?= =?utf-8?q?Lo64fKJDGNLfUzfkTvcFS6NNbGpQ5jVyiVEIeAmHdIyUw7LVT/bQHeecg/o4ZLvr5?= =?utf-8?q?htJdBBWrpv5nYdZnhq34XfcgBDzudOzJT5nvJz+Nkwp7qs4/jxtC6TWcZpMbT3YD9?= =?utf-8?q?GAlYRZ6TgAmoNwtNV8RhDr+rdDjhTMmMBTYJpDy3UhTxiXgl3jWyP9d1jobgXeaqw?= =?utf-8?q?QHB7Jhqg/qEQv0G1zmHHq3qwWUKTWpfu4vmDJyvB512EUCkCSKGaIly/a2wECLkg+?= =?utf-8?q?G64/eRjAcCDArdXbApLOp5mzPGL+IN5KGrX/3e4LmT+8kVFCVNDUggAT+KqETJ3uH?= =?utf-8?q?41e0ErlcDzBG?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7c48fefa-cc85-4491-8ae2-08dd1fb8fc28 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Dec 2024 23:09:12.2241 (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: KnED7z48Ll3DzSbNKiGr1BANMMMDCpZNePQPpfhclIw/zRGCy6JDdFNkZTh7Wy/SNdtMXzI2JrBYdGdfbd7DXA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9939 Add helper function pci_epf_msi_domain_get_msi_rid() to convert EP device id to msi domain's request ID to pave the road to support RC-to-EP doorbell with platform MSI controller. Signed-off-by: Frank Li --- change from v12 to v13 - new patch --- drivers/pci/endpoint/Makefile | 2 +- drivers/pci/endpoint/pci-ep-msi.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/pci-ep-msi.h | 21 +++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/drivers/pci/endpoint/Makefile b/drivers/pci/endpoint/Makefile index 95b2fe47e3b06..a1ccce440c2c5 100644 --- a/drivers/pci/endpoint/Makefile +++ b/drivers/pci/endpoint/Makefile @@ -5,4 +5,4 @@ obj-$(CONFIG_PCI_ENDPOINT_CONFIGFS) += pci-ep-cfs.o obj-$(CONFIG_PCI_ENDPOINT) += pci-epc-core.o pci-epf-core.o\ - pci-epc-mem.o functions/ + pci-epc-mem.o pci-ep-msi.o functions/ diff --git a/drivers/pci/endpoint/pci-ep-msi.c b/drivers/pci/endpoint/pci-ep-msi.c new file mode 100644 index 0000000000000..7aedc1cafbd14 --- /dev/null +++ b/drivers/pci/endpoint/pci-ep-msi.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * PCI Endpoint *Controller* (EPC) MSI library + * + * Copyright (C) 2024 NXP + * Author: Frank Li + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int pci_epf_msi_domain_get_msi_rid(struct device *dev, u32 *rid) +{ + struct pci_epf *epf = to_pci_epf(dev); + struct pci_epc *epc = epf->epc; + + if (!rid) + return -EINVAL; + + /* + * PCI Endpoint device ID can't full reuse PCI's BDF, BUS number is + * Root Complex Bus number, which is no means for EP side. Move func_no + * as low 3 bits to partially match PCI's BDF. + */ + *rid = of_msi_map_id(epc->dev.parent, NULL, (epf->func_no & 0x7) | (epf->vfunc_no << 3)); + + return 0; +} +EXPORT_SYMBOL_GPL(pci_epf_msi_domain_get_msi_rid); diff --git a/include/linux/pci-ep-msi.h b/include/linux/pci-ep-msi.h new file mode 100644 index 0000000000000..75236867426a4 --- /dev/null +++ b/include/linux/pci-ep-msi.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * PCI Endpoint *Function* side MSI header file + * + * Copyright (C) 2024 NXP + * Author: Frank Li + */ + +#ifndef __PCI_EP_MSI__ +#define __PCI_EP_MSI__ + +#ifdef CONFIG_PCI_ENDPOINT +int pci_epf_msi_domain_get_msi_rid(struct device *dev, u32 *rid); +#else +static inline int pci_epf_msi_domain_get_msi_rid(struct device *dev, u32 *rid) +{ + return -EINVAL; +} +#endif + +#endif /* __PCI_EP_MSI__ */