From patchwork Wed Dec 18 23:08:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13914243 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 C3F591922F1 for ; Wed, 18 Dec 2024 23:09:10 +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=1734563352; cv=fail; b=HfdQW7w5pIhNPPe5YCGODHvQc4CAeG4XUAAJZ2CyUgMY/8RQQ26xl7ISw0jRLc+/BVbqsaAc8+vyctaQQWL1rTDJ2/XWIjvpDKe0iV6v7fRtOeD5mrzfUcztfz0IAt+LkpYiYiAPt6myIP+lFbB4F1JyRCUjqCZU9dCZ+abzTdE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563352; c=relaxed/simple; bh=CjpdDETOi2VIxmLfWYm/yAsNYvD4NkW7aNy1uWn3fGs=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=GYmwuTTKd+yS0gs9lGg167wV3yZj3PHCYHUz+58kTX/C75ydP53PhFliRfZgiI/BU/ZPdNDy6C8TQgOf54TZpfVByN1irw0GEct5zjLRV1rKYMA3gaqfTxPWZmOxWe48nJ7jsoxHVloLxwmBrtNHwFDYJaaU0UihNR+r7a+EEKI= 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=ML7XN7tr; 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="ML7XN7tr" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tTPCMXdEzpd7dJv3fxJoOIpZggpwoWiPPZvysOU1SexVRZRTSP6DIENwuxs6CRWpqGzzJ39GO/GhkICA5ZCIdDctDiWsPNnAxcAQDqbRaWJ6obn9vx1yb0Fb3JcTjeKcjQvnx89ETF+8dBfbs1P3D4MrDjhOwAYPwKhMt89q4pnbt3Bbw3AuQyJKpDofMOB7jgBR15UEifJRvwpoVju/TOKbNwIZ7USiAXxtRmzHtoWrtdIxC+0TCOeC35IIaDX6elqEC/gpgfwZFee8dXQ+RkFw/UALMryLzqHmcLBHy7BvduDYkyP47De5X9L6Yf87HLhdD+V+g4N6lapWqJ7N0g== 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=Pf/oi8vmEOUmPTe7wYXgmKpdXfPYSmq7cIctdRdF074=; b=ezpesn+qj9TlNoARNIBIGNbPcQ8eUz1jS/Oz4bquWXAVG63UqpmCM9asfnkGulY4GA8CGkB2FsemEWzwXyS7cEy0ltwa72OUYuG7OLX0dh8hGHn8arkd7MWWMIrbbnIycjKXydKA4mR8G/SImNl7tSCjDcXjY5I02JZx7z6mo6O0xoflvY9QcEySpSK2Swi54B6Q5qCb/qmOjt4l+lPAc+v5yue8ZgPacIRWTc1TI7uXpM8iPVIFXPWd1D8zoYwBc/IuoAFSncmp+BwQRVRD/mUzBNVMmgwJytq4swHNRjPURjfgbT+Lz/y976Iz3LJMExGrpF5ibKFHhyAlMqEqDw== 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=Pf/oi8vmEOUmPTe7wYXgmKpdXfPYSmq7cIctdRdF074=; b=ML7XN7tryuuhkW1RlMZvxZW7vSj3mRHTizY81xXBuD8O3eBsHZeUc6qVjIVKxuvPyKPfiuE0zjwsrs8EYDlBXHuu5/ZAG95QkZnu0WZ8+6ey+ncTx6osPrjgM6SUQSL6Zz52tvtOdtfFD8+ZVsftYUfhI8lku+2VwMxEY0ME8ilzSmKrP6zltEj46htQ+ZvdSzc0DD/Q6OaFxevCxda0q68fjO5qo+Lbnl/foPo+e2uo2+DtNyCtP3atQ57k+IAqsSymjr8JVzZEjSIfQ3HmMupvyQP5BAp158AiHP0oPEojumIjnFGLIYwnPDITxOFuK8+4He+0drbp0j5a1OwOOQ== 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:07 +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:07 +0000 From: Frank Li Date: Wed, 18 Dec 2024 18:08:36 -0500 Subject: [PATCH v13 1/9] genirq/msi: Provide DOMAIN_BUS_PLATFORM_PCI_EP_MSI Message-Id: <20241218-ep-msi-v13-1-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=3489; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=CjpdDETOi2VIxmLfWYm/yAsNYvD4NkW7aNy1uWn3fGs=; b=MyLtN5Xnebvp0UjV1seHBr/iqAA/dHH6fsYXDWuHyp3lb2ig+UkGEU44nLIpoyKvuPIKdOijh 0I0mj1vsg5eBKrxgVWB95Q3e6idWqosEfYo1NhVwZw7832xUyzr1xBg 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: 7f858bc7-828f-4e3e-cbee-08dd1fb8f984 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?mmIW5BPfoF/WqSjjiu2XdgmqV+WlToX?= =?utf-8?q?Yb/JhLewB+7jSj5VqMsBnIGF6bDIhQbxwuvfTf26vYPfe+Z905age3TlKBZSrfhG/?= =?utf-8?q?cg1qCv8Ts0q3tdD/Lrh/fQz3D/9GA9mys2Tu387SZB2t/USbJ30cVmks8BUZ4gRwZ?= =?utf-8?q?LsWr3oJJ7OkerGwvEUzng5ITK+IDDHfMLbPWk3wEkCbQjv2fDIKl9Gr+KUgDUbTuc?= =?utf-8?q?bbJYXQYQKRbeXwnN/7AoQ4uY1zYASIFmQCVg9WONmpZ3hc/Obp8th5ET9cZgPs2/r?= =?utf-8?q?x4IEtmxLLcMBUZUpCEvPJbFRFWf/8k0nt3Azyxol9UPxgbsxhw5Wy3Z7GXEAXAkEf?= =?utf-8?q?o8/WKHvLKnN9arrhcuW8dyIvpHDzA3yCBtUVYWeGc49bMNrtIUL42UHUJYS1B6j5U?= =?utf-8?q?TAlNca0U1yiIXBCY6b25MS+K4wfgC7jUqFnS6olW4LBnOR7qiiD0J0Z7YRujaAOaa?= =?utf-8?q?uoknyOciLNV+KE6vyz5DwZPMGWN3QUVj71MGyP0naFIZYLx2wHMhGdeweAGF04qU+?= =?utf-8?q?BBzHuPibm7ltbaNVTwyUqfyRZQ4YB1L80EeuCdmTw+dYXoq5O1usaGPjLTCPTUxdj?= =?utf-8?q?ipwSJ5UFQoHOeMWM7CuNfy3ygyEAsy8AU/lymcN1/rLJ1Kf6pvnd0bAlNgbKn85aR?= =?utf-8?q?LTauj7oMUFFzgD7uSP9AfP5G3eC7uKbUvv462cJJXuvxyGGNzPfPxqhQPQYx1Frau?= =?utf-8?q?AnZ5aasCo55aVEUaS1pWfaHO8rQe1q5jSU5jrhmv2JKmx5LAeo+BAqn+NklOmlY1k?= =?utf-8?q?bG6JpHfR2hSpJEmRhl5RhxJsgBOG8tcRcuuwGN0sEg0NFv53SPEJ2oO3D041QIHfM?= =?utf-8?q?5Ym7gkZTM7tIoeQJVxVw/eTkEULV32WwIbKakXZB9wnoRzOiEWriHeVzbWpzSRC+3?= =?utf-8?q?tlAcnUfW4fWdaVxkdxZ+kopSOTkypYL7SdQGMgjYj9JSOn0aVQNQKI0txWAUdKBQn?= =?utf-8?q?ToRhIFxyLpDXT88Bdla+skmNIQoNy7MhcUTMPn/nWDAKqGnN4DiD+Lm1sHFaFjzOw?= =?utf-8?q?yi3IsbKkpcDL/Axn7vXThPkMQ4JwvRdDoNnPwtBrqFArCcV2BwWUq813i6RoeqCta?= =?utf-8?q?VSZPf3xJZrOwDT1ymp76VcwNTmwyjQH9it3S5wYIZuZpBHA1g9KNRt4g8OjzQsqiJ?= =?utf-8?q?VU8mRK66ow+6dF5npH+Up28HcuEfeB8v5BjzZW20aeMVaqZq3BJguLW74ulsODpqI?= =?utf-8?q?mI334LElzLv9ZiyxL8PMkefkZC+frPXzWuL+rirocXl1+FT1s33DusmXKpY7qsO8p?= =?utf-8?q?tUjmv7Cdhot15pqy7Xocw9WXBUcK0PR0t6dHLjwu5IwmZtGcUP5Cr1cCCUSIsFE3d?= =?utf-8?q?M1RbR/CQ9mFC8XrWl5tF4WVMt41RbxTmh7PIebmdjvZr3BQGyVyk7PdsmGla+tvrZ?= =?utf-8?q?mWCrTdjUo4cef2bM9a/Z+uOe7I+ylwOqg=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?NIJyoTfFKNSldNKddV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Spjl5?= =?utf-8?q?0cqOXS42iuhNaSfVjysH7kPQN6jpF/YaH9HXUP27z9E6KGE9HIml3dYqGDGK/hz5o?= =?utf-8?q?LSNFrLWAy/Rkfa3lGbrCUtnMiiFBUKGPoI6oQoIhIdlh2ESH1Uf6E9NezQyfxcVLX?= =?utf-8?q?6cMWW3cXcQDTMMYoohoirR84IpYpOws8XfIfSO1YRQStG1yTNAISL/AfbAgMEZBdK?= =?utf-8?q?uhAxtFICiS5TYnTXe5depDWs4EV55FtEhN7CChmG2KY7k74yeKMwKIzcGiFBI5qF5?= =?utf-8?q?8PETZfKZyU4VzHBhjQAOyr+YjkI03jd7gu8y6P1iVp5Sl6+amtUw0PjfvfujiYO2P?= =?utf-8?q?GA9SS9A1wNmBMWkqHus5Q2vw2CsEdtC2WPrg015EI98k8DD2c+6mUNt1FaKdXosXK?= =?utf-8?q?7HqKCIFTv9IXExGy9udUlbmc+xOckvMtnAuDp4K7I6mykAZ4uOhRf0egLndsZ/UQK?= =?utf-8?q?mYf+zQL2mLqQwsMF/KYkECcup0U7ZpQyZ/PrrU7B0BsGNK+Jvrrwe8u1Yprvbi5wj?= =?utf-8?q?Usnrvn91EX3Ru6H5ldNB7kLgScgNudxgY04EMSr++oUstAYrF4TgjlxSeTvXL9STt?= =?utf-8?q?G4hKnqHVlPgdd5Neh8xhvU3oFA8HI0pvlMRWcyi0jcCQA8zU6iOoF0brVRWpNRuTh?= =?utf-8?q?U4mmJz0XqLnR?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f858bc7-828f-4e3e-cbee-08dd1fb8f984 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:07.7969 (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: PAxs/fLh5AqOgBgcnhBQKhp/YLgYFjsffk5pOGvLOkEsJY0aMRbDMdDiG1IpAvZd7UrhV+QTle1kXZyKuaJYbg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9939 ┌────────────────────────────────┐ │ │ │ PCI Endpoint Controller │ │ │ │ ┌─────┐ ┌─────┐ ┌─────┐ │ PCI Bus │ │ │ │ │ │ │ │ ─────────► │ │Func1│ │Func2│ ... │Func │ │ Doorbell │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ └──┬──┘ └──┬──┘ └──┬──┘ │ │ │ │ │ │ └──────┼────────┼───────────┼────┘ │ │ │ ▼ ▼ ▼ ┌────────────────────────┐ │ MSI Controller │ └────────────────────────┘ Add domain BUS_PLATFORM_PCI_EP_MSI to allocate MSI domain for Endpoint function in PCI Endpoint (EP) controller, So PCI Root Complex (RC) can write MSI message to MSI controller to trigger doorbell IRQ for difference EP functions. Signed-off-by: Frank Li --- change from v12 to v13 - new patch --- drivers/irqchip/irq-msi-lib.c | 4 ++++ drivers/irqchip/irq-msi-lib.h | 6 ++++++ include/linux/irqdomain_defs.h | 2 ++ 3 files changed, 12 insertions(+) diff --git a/drivers/irqchip/irq-msi-lib.c b/drivers/irqchip/irq-msi-lib.c index d8e29fc0d4068..cf39f2e481477 100644 --- a/drivers/irqchip/irq-msi-lib.c +++ b/drivers/irqchip/irq-msi-lib.c @@ -57,6 +57,10 @@ bool msi_lib_init_dev_msi_info(struct device *dev, struct irq_domain *domain, return false; break; + case DOMAIN_BUS_DEVICE_PCI_EP_MSI: + if (WARN_ON_ONCE(!IS_ENABLED(CONFIG_PCI_ENDPOINT))) + return false; + fallthrough; case DOMAIN_BUS_DEVICE_MSI: /* * Per device MSI should never have any MSI feature bits diff --git a/drivers/irqchip/irq-msi-lib.h b/drivers/irqchip/irq-msi-lib.h index 681ceabb7bc74..5ccfdb14fce1d 100644 --- a/drivers/irqchip/irq-msi-lib.h +++ b/drivers/irqchip/irq-msi-lib.h @@ -17,6 +17,12 @@ #define MATCH_PLATFORM_MSI BIT(DOMAIN_BUS_PLATFORM_MSI) +#ifdef CONFIG_PCI_ENDPOINT +#define MATCH_PLATFORM_PCI_EP_MSI BIT(DOMAIN_BUS_PLATFORM_PCI_EP_MSI) +#else +#define MATCH_PLATFORM_PCI_EP_MSI (0) +#endif + int msi_lib_irq_domain_select(struct irq_domain *d, struct irq_fwspec *fwspec, enum irq_domain_bus_token bus_token); diff --git a/include/linux/irqdomain_defs.h b/include/linux/irqdomain_defs.h index 36653e2ee1c92..feecbc27c2575 100644 --- a/include/linux/irqdomain_defs.h +++ b/include/linux/irqdomain_defs.h @@ -15,6 +15,7 @@ enum irq_domain_bus_token { DOMAIN_BUS_GENERIC_MSI, DOMAIN_BUS_PCI_MSI, DOMAIN_BUS_PLATFORM_MSI, + DOMAIN_BUS_PLATFORM_PCI_EP_MSI, DOMAIN_BUS_NEXUS, DOMAIN_BUS_IPI, DOMAIN_BUS_FSL_MC_MSI, @@ -27,6 +28,7 @@ enum irq_domain_bus_token { DOMAIN_BUS_AMDVI, DOMAIN_BUS_DEVICE_MSI, DOMAIN_BUS_WIRED_TO_MSI, + DOMAIN_BUS_DEVICE_PCI_EP_MSI, }; #endif /* _LINUX_IRQDOMAIN_DEFS_H */ 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+B7tJs0k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qAx6wUDvU4HuYGhX9aYRqemWbTFSA7Ju?= =?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+MQZiWHIYEdTWEZRt+eIdXC9hSkj7Dlbv0b1fTB0bSdM5q2b5c6L0J7?= =?utf-8?q?b+V/X6fIUm+3fIJ8TvjGu+kHqXtAKw0Aa3yN8f+CaODYLcqpGJiEKDfHTeOgYuEOp?= =?utf-8?q?S84XW/wMKnL601+nyH+qKfSIHVXYWS38zfqREDsFYgb0PwYDUgCAf2/Br5hfUkJAK?= =?utf-8?q?F66bcRM7YXCMxmdSOaHwJ0IteoWZwnB8nfM4h0Kf/gZyj4cQAK+L4fZqa37bltrKH?= =?utf-8?q?11gpCH3ljefLS9+dmztq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I22bIiBtwo1qU/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__ */ From patchwork Wed Dec 18 23:08:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13914245 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2078.outbound.protection.outlook.com [40.107.22.78]) (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 5E7C51FD7BF for ; Wed, 18 Dec 2024 23:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.78 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563361; cv=fail; b=dMN7dEWC+Qkza/zmOJEa4jiydqW9P63Q6BFl4PCmmI7Z8nkjZ27J4yQ5UigUFAxI+C4J/MiqBDh0cjZqrOEtbN7kXfs9OKSx+ScTnPMVwP8MuEJa9XhzwQZndElXWDHi9U6MuxXcybPiILgOdizh2jrBDo4O2l4ni87pEdarWXk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563361; c=relaxed/simple; bh=mH/HfWSB72ELMEfQcYQ6cyfemrKZKDjtNGbdbaIdvQY=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=oyzb3Mwqp6dafOHl0VSXigdPuWpMW2ucZMazBJMVXywPbWSpcMhxTwgew3t6yOTMo1B7uMkTWFnvZFU6ZmrVt7TqX4Rjg2PkgLi5N5vqv65lNLNHR0ioT0RQJWfCW/+i8G3PpsBpQnmZkQwdcjIPMTG5DFLhZz0yhF5eT3zxgv0= 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=Qv4q/OUu; arc=fail smtp.client-ip=40.107.22.78 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="Qv4q/OUu" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=m02Bt6HKJucz5NSqWFUrMq+txOZxRCnMxbjB5VTz/rNguQcqVIhJiO714/RDpSfdnbXgnYnEIaJPbbYT7e9FxSkuqBxU2qrQsiM8GfFOl4obkPRT6KzzfIqqH/aznW8C3uecvv0gHuEw6pkB3khdgEVw435j3nEt5RHV6QdbLCdy/IQntViivit1hTiWkGNTCSMz0jMNCPOSss9rd9eZ8FdQ8TazKgTeQnBa0b0GQoijerAfC0hUS7CSmTmjfC1ox+5ZImoBIKmH9ska08iMrFMo5sAWq+lkIZ0lHAnR9ktQDWvNk5TDr4VToqxdutEor01Ih6yQGOp99C3+t731xg== 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=kimtkzi0tQgW2H+hE5yDJkVcjZYWfJxLal/759/AiPY=; b=hguFu45yDcR1mprgdW9yzTbQERw/Y+r3k5lzxMMGoW9ivCMHcVJaXbzLVWFPwKBppWqWyfI1K/VNEuGYHhqQk8/JEqZF9Cey8zanU9aQeAqSEw6EIOALyhmjayDdCaK8TmBCqGv64COL67BvNNNv/ix1VoA8qmVhaG8vsj/cfcU2nTQnAYfUcT0ngnse60WT36GyBwxC+OhONo6NKl9nWdBqebc6iwCPWDukY3PZ7J7+DYQTAHXouzcmtMc1N+MRr8Xmhtr67kVGbo1KVitWIbGWHggT5L380HJAP4nl4g+7pvSnuQAvGBozM0C3xyzDJIOnU+8WsHNVAD0y/Ntq2A== 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=kimtkzi0tQgW2H+hE5yDJkVcjZYWfJxLal/759/AiPY=; b=Qv4q/OUutkuW8cqI69xv+IAhgjc3Kq7qGUNvARpFlS3kiRwa1wmwmhyd++xIIJ8TEXjoHHKNDASbWoOmVZs93suNOYPKFyw6Pvya/bp/9AU1PVglx6D43EtKkWqVbt4NIIIn1UFwAWigMrxB6i9G5OzgVlxdghWGo6lQj1y0LV058fHuDx+4kOmH6JOrLQpemnkp2EsaJLUUhEgXPsaUtYmTdub16LNj8N1ZfAMHDRzW8BHf/vHGVJI9EOjWuX2/HUTuiGL+2JOv2Z9G5GmHXZLN6C5x50SmO7fFZ1eTxLP9Y2tBqUFB5fGGooI8j5kcmTRkrFASUT68SJzj/qo3hw== 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:16 +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:16 +0000 From: Frank Li Date: Wed, 18 Dec 2024 18:08:38 -0500 Subject: [PATCH v13 3/9] irqchip/gic-v3-its: Add helper function its_pmsi_prepare_devid() Message-Id: <20241218-ep-msi-v13-3-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=2002; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=mH/HfWSB72ELMEfQcYQ6cyfemrKZKDjtNGbdbaIdvQY=; b=eNl/J8BE9Qsa2PmKzqDaaOiXIGwP1SfQYeNr8M/BU/MKJno+0cBLI1ItCfZwl5sepybqrdD+4 1YTX89sSZheAgmKru98XpDEQ+sdJ/UIoZzjFPMJ2MaFMPVpGO9TtiQI 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: d19b22af-ee4d-4ccd-b705-08dd1fb8feca 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?4dkQqfWE0Ffm+5sGz33YeB4QaoylKdi?= =?utf-8?q?GKKNTgrYaVK1yf3GUiXfAUvsG9X53QzU7Ry19q7YqmDSDGVLW0Nl4l8pTQ4aosLYI?= =?utf-8?q?ffUjz5PxX5FcIb/YPSp8Z1GljnlprMtQgDRf/f6VhqHa0sO7JFzmh1OAMDCUdixNN?= =?utf-8?q?Gb88t/NWCZJ9uFNORREffH8RlUVeHffhLni8SAKC6Hhk9azXCJVo7DFEmnDNsLLVM?= =?utf-8?q?NXUD0H387utznDAFKIv/ddHa4O4yTfJ+2jKUb9Ozv07uEczZqkN95mAUCha0ASvs2?= =?utf-8?q?cuw7UyUIRXzIV3ZIVY0yTxid0fUbvOIJXPEZnHsrH902jT1IV9MysZLX67gLXyei8?= =?utf-8?q?AVm5ilEE3JbngtaIvF2+E5Mrw2fbc3gXUJdEzaDy/cGnGCOKigPYZ2UdH4oIU7/z2?= =?utf-8?q?8vGsbgrZc1cF1I28k84SBezt+Wpp95pdjDlWDFEPa9onDlAwQFJdEJD7GSGmkNdkF?= =?utf-8?q?6hqGmPBx4VqDUk7cRMM7IuWhwDIoTVxRoLju14dkyntcFaoeikJ8a5XWcgIn+7P9k?= =?utf-8?q?CzdezizjwhfeduMDvYN+AW38xLbl8CfVx6arqAJACll3WC0s91aXHFM/sD6TsFXhL?= =?utf-8?q?amQy3HDK+Q+op9eW1d0HkE7khxx7wZXL7ykNCeaVZF781EySnqyAjIkQwdeFpXDGC?= =?utf-8?q?BUvTfWUDa8jpJMBgRd7sjayzORoQtJfmfbeqYMUcOySh8iXxCbax4KcCYdjTjRfon?= =?utf-8?q?tLq/FgDFtxYhU2rBCqknNY+51KmgM/Sm2IKnm5FEsmqggS9eciTUSBHM7qCWddIgO?= =?utf-8?q?uzvwKfa++EV+nSGYyFhP2TRhflf/EFtm52vfW/u3CVJwhtvJFiykgfs/1QfAIuWn1?= =?utf-8?q?CCdpVb4vIepUD+8AxogDFJRIYHbikcM6AI1CHcjf3oEhujlh0fpbazC/pGC+6z7Gr?= =?utf-8?q?FVKDFsdvLBCns813A+jnqE1VX/QOn3HYlnLVDfYKspgOMatl+Xesk4oZcNz9bt1ve?= =?utf-8?q?OdZBgk+y31Valuqa6qc6b7lsjcPgwS6oocX67eq7wxYKfuboP+n/hCATKSWdCEEir?= =?utf-8?q?bLh37SU4i4ZP/VoD+N0kdvsOH9O2wn85KiN1JIQz+hp7nupBAmLA6qphdjI02lSc2?= =?utf-8?q?fLdeiwMcPSlpTCFj8Aja5UX5C+vNYV67VqZF91rweXDIxBML2DWMHKxgj6T/n20H1?= =?utf-8?q?pDCpiuipwVlOfs2ATDSNewEW9dtZsk6f0ZjxlIMeAnqpflytOD+9mLmbFQ5/Q9WF5?= =?utf-8?q?s+37pgrQRsDytd2Zt2RrgUCczyorEUwXfTKqaqtPx98S9WVINLVu03URQ/gZqj7ft?= =?utf-8?q?TdwxCTc1HcDJNjYPU7oKzc2AAMgqNmQADaZfABudOHVP44cSWWmpccFbOPcaJTNCj?= =?utf-8?q?5GWodBvgAI0R+xaIEx+6PIV81OiHZFhOLYgy5Ou5bsjqi7KqyZE4V8/yni6rE0mB1?= =?utf-8?q?rOVNVoLvS6gVHfP1/3J4TXtwZEx1bpbag=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?WiYNKGMRLI72Lzs6s7eVcW1tHdQW?= =?utf-8?q?yGEgMTitQ5z/EpOLh0+DIHCcaFNpw2LxS3zZoNF4OmGW924xYI/JxoOIDkpabPNMC?= =?utf-8?q?gEz1382LpV9gInAQZe9N5dsZSXuCeaCVH4NOifTv46gTAuZVo/xHGV5NVSJrvsA08?= =?utf-8?q?ckpS33771k5q0pX/WgDj86k+ackuiqiLpcwtFlOoC8BTlLy1zHO8Kkmd2QWJpfhf5?= =?utf-8?q?FGcU0HgCj0AUb2huovanh74WRaYcioNezf2rNScsETi/cTXcuK65CDfUHIxm6G7Au?= =?utf-8?q?PzIrA+H8irMM0wySevLPxBLnWuUcOWNJ5ajKuYXco2nRuttPwujvxeKXJB6yyWfnV?= =?utf-8?q?AuWFbDxalflePA7P/EzyDujQLGXt4C0IZGIDo0f+HN/uBYjrpuZCHDxMupVfrleVz?= =?utf-8?q?vX0InQ0Ql0KnB6rby6RZoErHd/gErWBBBYGO0s4URsB1faGXAXO1P1AvZA4GNwyrf?= =?utf-8?q?L0tUwdmggPVfJcxAIS6X0YV6jYGOo41xMvSFAn7stSzh6av5ofFs9TAOULSiHUfem?= =?utf-8?q?LJfYl4BV9rMdY5JT6INsporwpNKbFs1zvnOvqtXeeB5Qf9yWtAM72o+cnKyBt9EZ1?= =?utf-8?q?wMvjD+oNNww16HfynSs9qfPVFJ1EfNwaFy89/yMwovOIjo7lYLi/+DRZYQe8fnfoh?= =?utf-8?q?cn8JoCWkCJ48ChJLWFTuQ0QOmwvvIyw4LvH9xLohqLOaCCkSOJJmEjnVG+f37D2il?= =?utf-8?q?B1g3O/wHhRpIJBQW4Dp/WMojijOidFjG5rzvjuXAGO5XAWfFzWYfuX7HgcO9ngVgl?= =?utf-8?q?zwSfV5WZSmqaGbolUBMDha8S5jFNUWdBE0fn75qq58ph1Ay8GLUee441uPWZTeJ3e?= =?utf-8?q?51QTEMe4GiP1d/vdpH7VZlwbPFuK15WkSSckah7jMAS8J4AqeK8iCtaKsmjpByqI1?= =?utf-8?q?Y81F948/5EW52hvvVMfyRp8a/kb1dTKpzCJxtq+WnGJiSASxhDMQt/pLYxAlPc/Ji?= =?utf-8?q?ScsLcUTWfENUqzqyMQjfZOmS0Plegtoqnlt3GoWf1BNGEMTIUn7Ycwqed1n5S1Oa7?= =?utf-8?q?xRgv1fR3+zT6sCyAHd5OJpk6kEfNamKn58AsAGi3MnXlpPchDFgKsUv6YQtgvusVi?= =?utf-8?q?VaGLMQ0b9S88EJyo2AD1QEl9bZKe7p4frV9Uq8x4FPewE0g6r7fpPpEtzWHnOrC0W?= =?utf-8?q?wfwu5kf5jYj2VlNWT88WoAD+bdOmWkdWpA/o9OIuQFBAHP3vPM75ML+bSiQZVMCdt?= =?utf-8?q?tdH1mUBjJ6rE90h5g8DQYQJzEDUXEYU/vXPa0YmIBu49q9odnfgFUi214xbOelpUd?= =?utf-8?q?+JGl/35ZZdH/QbffS6nrw62Icut1QYAClOb6tCm7hRcBVo2pvZ6fbtIFIN+on1Uwu?= =?utf-8?q?jTGetFELvNQk7uzI1R9j3L3GR0u1q5J1kO+BU5kkL1zyoAlFJ0hdTy6q3avDjT50k?= =?utf-8?q?NQ8KMpugCA+7jLv3WkGD4N4dcrv+1uAmG/lCB/JBNfVU4elp/txQFU4Mrxq3Buz89?= =?utf-8?q?YAcXaGO5TTdi+6HamtqpZ8nTfXE8Zkk2fwm8mGaNu+UCOPC0NhrQEACr/K0EDotlB?= =?utf-8?q?/iPyr7o+f3H/?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d19b22af-ee4d-4ccd-b705-08dd1fb8feca 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:16.6526 (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: D2jJZPCe/OO7WB+dhZTT8jrvnkQozxZ5YV+J8/MYC9xX/HesApvUaL5wEmEvINhTY5b57oMgOLIV3ERnuVbMIA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9939 Add helper function its_pmsi_prepare_devid() to pave road to support new DOMAIN_BUS_DEVICE_PCI_EP_MSI. No function change. Signed-off-by: Frank Li --- change from v12 to v13 - new patch --- drivers/irqchip/irq-gic-v3-its-msi-parent.c | 30 ++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3-its-msi-parent.c b/drivers/irqchip/irq-gic-v3-its-msi-parent.c index 75aa0d4bd1346..b2a4b67545b82 100644 --- a/drivers/irqchip/irq-gic-v3-its-msi-parent.c +++ b/drivers/irqchip/irq-gic-v3-its-msi-parent.c @@ -132,19 +132,10 @@ int __weak iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id) return -1; } -static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev, - int nvec, msi_alloc_info_t *info) +static int its_pmsi_prepare_devid(struct irq_domain *domain, struct device *dev, + int nvec, msi_alloc_info_t *info, u32 dev_id) { struct msi_domain_info *msi_info; - u32 dev_id; - int ret; - - if (dev->of_node) - ret = of_pmsi_get_dev_id(domain->parent, dev, &dev_id); - else - ret = iort_pmsi_get_dev_id(dev, &dev_id); - if (ret) - return ret; /* ITS specific DeviceID, as the core ITS ignores dev. */ info->scratchpad[0].ul = dev_id; @@ -165,6 +156,23 @@ static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev, dev, nvec, info); } +static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev, + int nvec, msi_alloc_info_t *info) +{ + u32 dev_id; + int ret; + + if (dev->of_node) + ret = of_pmsi_get_dev_id(domain->parent, dev, &dev_id); + else + ret = iort_pmsi_get_dev_id(dev, &dev_id); + + if (ret) + return ret; + + return its_pmsi_prepare_devid(domain, dev, nvec, info, dev_id); +} + static bool its_init_dev_msi_info(struct device *dev, struct irq_domain *domain, struct irq_domain *real_parent, struct msi_domain_info *info) { From patchwork Wed Dec 18 23:08:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13914246 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2084.outbound.protection.outlook.com [40.107.22.84]) (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 9395D1FDE27 for ; Wed, 18 Dec 2024 23:09:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563365; cv=fail; b=tEiJSv0jIfAZIKlBpgUEHrUTytlj0slPgwDTZRQcmywU2c8FxqQtkOUZjdx8mRkrvuTa4Y9Gz0pdSrMiHeHekqcKtpBabSg3cH8jfKFkQPBDoLPQC2gqCf3jZH88GOVATFJLON0dfRdx6NEUJJjCk6zynB2qbDYDElcq9ajrOGw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563365; c=relaxed/simple; bh=4WwkstL35KhL3qhGUlXubFCz9/fgciZTvqmYrG8rlZw=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=Df49Qt8zVBeBDg6sRzg1BYG7AL5cY52EB8mJhdQDoWtYlbwfyMBtlM+WyU7dnd2RU4Jvf8pJzUJWZR1ghPwrKH7QPcATrXw84H/44aFG2dzKZJNoAKNL40+KrkZQ5hrALDNWKzztSs+zr0gGjIcJzrizrJvioxYH6gFr0kg9Xvg= 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=hVJnwl2z; arc=fail smtp.client-ip=40.107.22.84 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="hVJnwl2z" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xcewkx4zqwRui28rgSoFK2Tnm3svSa+UJhTIVx7mlMFs/ppY+TpwIFrhMrAlyGJZIKMq6TFH0IeGDNPZAr3+1LmCPT/Y+pEbwk4gDP/d+ye3Azkc85qUIdLnX5NyDWkX1ISF3qVuU4z27ZU/aa4YaF4hu5UZpP5Qfw/mxwurVZOIwPevC8rdFGJW3Ne60PNwXrV9Q9x8+3ahlPAT1JgAvjncSHAeFauQ8vqY6eYfj0Ngm6MKIx4G3EhlF8GFU85mUY73AikWdZ1ty4gg6eBxPhp9M3mfqHn/AybQoFcCOJS073E98u9rzcpAULZmdmiRBGZoUM2aqfDNmLPD8/R2aQ== 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=o3FjoyRz3SjkhMK8MORPoSjLFnPjDhKj+yUIz4mwf6s=; b=M7i1zrpCtAVtXOLWlotReZGc773qtNZxBS3UYR81BwhtlgKGE9j+lKDpCE04+pyokJoZiwaTKGpxWqPAjRnnWPMg3JnIkKZ5JuC7kENjOrvRvkpXS8O7JmzpFdoO8kOX3WRmh+eOQZ9r/a1xb8+SNbX0Mlghw+gbE8+W7sszVWlNWWxupNb6tWpkr6XAJf8kEymzSsLAHv0Au10VnaOSUXMkXvaztLA0ABLxqR95QYlrSXnJveVxqwQeBoIP4NKPEzrbRE4SbLCLYXd8Q3TTjdvwaJ9cQhAT7cu3c/cHxB97SYVyjC3qcBjBfT2wPXg9IChV1j3VwrOaxOuFLKUzmw== 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=o3FjoyRz3SjkhMK8MORPoSjLFnPjDhKj+yUIz4mwf6s=; b=hVJnwl2zwYvih5KGR6HoF5kNITia0jIAB0unx6f/ndM8pOplQURwF2nOc7DwwlrMbe5tusYNhZSAhag+ZXYQHuom1kDVuJ3/mgNEpJu9Vcys/uVDrU3EMA/IKslJiJq9eo8JPhslE90l0Us9FpU4RUnCjC9SJxpp2iMlrgHS0c66J/SvH9d0XFvxRBZshUsz4dElB/rZRizcHrodGXd5rB5+trK7zMu+79ySpUcEYZm9IcsFVNMztNOWK6nd/uxZ/8Nr9sKWeevjOYDf9shuo6v+f/1uTUsHYGSuIMml4up8KA+NwMHWganOP13BOsz+8lR/lcwZ1xB0BjcMFzA7kQ== 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:21 +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:21 +0000 From: Frank Li Date: Wed, 18 Dec 2024 18:08:39 -0500 Subject: [PATCH v13 4/9] irqchip/gic-v3-its: Add DOMAIN_BUS_DEVICE_PCI_EP_MSI support Message-Id: <20241218-ep-msi-v13-4-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=3555; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=4WwkstL35KhL3qhGUlXubFCz9/fgciZTvqmYrG8rlZw=; b=nzwsc8/qZUuzDYm+GQxGjDUKpheDTKeoYWbKwVPnApomjR+n6TZNUIS6Bqo+80gxDr8rTYBSu Sp1XHabTldFC+iFxgIO+gpSeHK93A5PiIrfk6hIghkofGzJE2nwCFyT 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: 97b9c9e9-75ac-4805-c8ed-08dd1fb90174 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?b1y/2NlElL8Xgv0F0kf1r8RiHSZM3jX?= =?utf-8?q?rBgU0eQxdn8MJDwAVsz9vxLoSM1RUozKCZbsQfqIMwJ1274a4nCQElr4hJoivQC+0?= =?utf-8?q?ejbDNebDfdSGnRZnrLQysvA8pQlIGIsV2xTV1EzK2Pj/hyAMC/LhIRcRVtZHfKGTy?= =?utf-8?q?6zgkZjbfAuhh7kYi6WngLM9c2TpfNfvuxHH3TKsUz1OP6kl+A/yos3WdkiwR2/l6m?= =?utf-8?q?863i7+HzVZE/5AxyW8fGIjsacZ7CSHjrmL+sjVbliFNijbQZxQYBvxK/pd1hJvbqU?= =?utf-8?q?dEa+v8M82iieJa++YFs1xS8Wp3nLMbv0UqVOBXGndXOhIY8jV3Sos5mRccv/8rDmd?= =?utf-8?q?lEKnYSgOEuEqQ/CrIyRLYg2KtBtudySha1ZUoklSVx8w2e6fSdliZ774tTXs6T68x?= =?utf-8?q?JmMQmw9WNxvZGGxHAo8RMogkJnq92tYAIfsXtmMJg7N5z9irzFqxxW5EriKbSUKeF?= =?utf-8?q?BhSTLlhIBCwLpGCXA91WfiDTfY1hvJ0WMYiHYjziSmsdGO/Tap8BUgOJg6mvHx6HV?= =?utf-8?q?RiZL4vttS9GrYuZR45KNQaB8tvpkCysRIjel1A9Jc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ispam-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?HMzVtKr2gfMu/IGNqLugg4CeIJi8?= =?utf-8?q?86WX1jI9rj6i2336pyaU3cpKUklHiBpdcZX9o6CMELs7tCW7nq3FPeplC/n+ofpEY?= =?utf-8?q?9gZYZclJ8NoNMy/F1PclGOTKqWxR4fO7drFa0+Mluku6d8YPfGRFZcLkKyS9jp2rW?= =?utf-8?q?Sl3nI4cRfEYJGEAdTpPyqwYhu2lLBOT6yxaDYAJOWr2/vzreWhXkwHXfKPLZ+rkge?= =?utf-8?q?RomXMKhsEX5itqEiatwjqt1kJ6NYvCmj46EqDmqMLHR3Z3a7dugxpnKCjycrcJHPz?= =?utf-8?q?GD1EgepFgqsfU9YtePiodtvjVH3G8npqb2KwoCJX+pem1AWGyRMTG4fOiiPd64bIA?= =?utf-8?q?eSvwOTlPdStuK+AbrUp/9oSx19WD7jP9YIiBYrEcsvNeCjsIFJOHwMk04YWp3zHSx?= =?utf-8?q?u4AR94Os+u0Hs9X0PhvSsxFYd1x+EHjjnLliaKRcW5WieLKuVwkchhUl8toK3n5SS?= =?utf-8?q?iBGKw+tf9srj4C/7Pzax5F8XiqcwwmiRoga4tvYI4ArxNH2VRPVmSWbVyK3axql2r?= =?utf-8?q?0E4Cmh1u5ZUAmyOZfuWG5QcUH4UP6eYEGvFZjTGyPqqZ3VLxGrdcX6I/Jc4jsNuvO?= =?utf-8?q?1BLa63YU9oh1xt+gmvN1rdul16Xl6QHJckJ02T0IxtuDgN6dO35lv1z0zphB/fXyF?= =?utf-8?q?RGyRygRk85OV0r9KlwyUcOShWD6U/Fp59hQ7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-CrossTenant-Network-Message-Id: 97b9c9e9-75ac-4805-c8ed-08dd1fb90174 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:21.1077 (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: dfHcn2FxTiEQy7lOhYBCIoXzBgoSHTLPajp9kPs+EjJ5IspD++cNw50rQ9hRdWyL03b6f8l/wlM0146tqUSgUg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9939 ┌────────────────────────────────┐ │ │ │ PCI Endpoint Controller │ │ │ │ ┌─────┐ ┌─────┐ ┌─────┐ │ PCI Bus │ │ │ │ │ │ │ │ ─────────► │ │Func1│ │Func2│ ... │Func │ │ Doorbell │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ └──┬──┘ └──┬──┘ └──┬──┘ │ │ │ │ │ │ └──────┼────────┼───────────┼────┘ │ │ │ ▼ ▼ ▼ ┌────────────────────────┐ │ MSI Controller │ └────────────────────────┘ Add domain DOMAIN_BUS_DEVICE_PCI_EP_MSI to allocate MSI domain for Endpoint function in PCI Endpoint (EP) controller, So PCI Root Complex (RC) can write MSI message to MSI controller to trigger doorbell IRQ for difference EP functions. Signed-off-by: Frank Li --- change from v12 to v13 - new patch --- drivers/irqchip/irq-gic-v3-its-msi-parent.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/irqchip/irq-gic-v3-its-msi-parent.c b/drivers/irqchip/irq-gic-v3-its-msi-parent.c index b2a4b67545b82..16e7d53f0b133 100644 --- a/drivers/irqchip/irq-gic-v3-its-msi-parent.c +++ b/drivers/irqchip/irq-gic-v3-its-msi-parent.c @@ -5,6 +5,7 @@ // Copyright (C) 2022 Intel #include +#include #include #include "irq-gic-common.h" @@ -173,6 +174,19 @@ static int its_pmsi_prepare(struct irq_domain *domain, struct device *dev, return its_pmsi_prepare_devid(domain, dev, nvec, info, dev_id); } +static int its_pci_ep_msi_prepare(struct irq_domain *domain, struct device *dev, + int nvec, msi_alloc_info_t *info) +{ + u32 dev_id; + int ret; + + ret = pci_epf_msi_domain_get_msi_rid(dev, &dev_id); + if (ret) + return ret; + + return its_pmsi_prepare_devid(domain, dev, nvec, info, dev_id); +} + static bool its_init_dev_msi_info(struct device *dev, struct irq_domain *domain, struct irq_domain *real_parent, struct msi_domain_info *info) { @@ -205,6 +219,9 @@ static bool its_init_dev_msi_info(struct device *dev, struct irq_domain *domain, */ info->ops->msi_prepare = its_pmsi_prepare; break; + case DOMAIN_BUS_DEVICE_PCI_EP_MSI: + info->ops->msi_prepare = its_pci_ep_msi_prepare; + break; default: /* Confused. How did the lib return true? */ WARN_ON_ONCE(1); @@ -218,7 +235,7 @@ const struct msi_parent_ops gic_v3_its_msi_parent_ops = { .supported_flags = ITS_MSI_FLAGS_SUPPORTED, .required_flags = ITS_MSI_FLAGS_REQUIRED, .bus_select_token = DOMAIN_BUS_NEXUS, - .bus_select_mask = MATCH_PCI_MSI | MATCH_PLATFORM_MSI, + .bus_select_mask = MATCH_PCI_MSI | MATCH_PLATFORM_MSI | MATCH_PLATFORM_PCI_EP_MSI, .prefix = "ITS-", .init_dev_msi_info = its_init_dev_msi_info, }; From patchwork Wed Dec 18 23:08:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13914247 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2041.outbound.protection.outlook.com [40.107.20.41]) (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 2C99B1FE457 for ; Wed, 18 Dec 2024 23:09:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563371; cv=fail; b=J1B1Y/sOq5x4nYtg2iC+BL6TTJudAy2NMMnTXiA351HeeHwTMkgVWeZaMlFRT7S9uBrSYOam0g4+IHQToJAQZnJXjkS7jcXIzibHzjjDfqE/Gz82CJL/lvgos+9Qj7JCO+d2OuuFEjWXfKvBIy1diPjjSSQQG1mYfbp16IlduCU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563371; c=relaxed/simple; bh=WMSa85DyIKk5/tdaJfRJ0u1YGaIJIzUsaDVlLKYUQJw=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=j9yJdEmAXmGNcXObTl94N25ec8K/3BIqxap7++yysk8r76GZttiND5gFzkFFkd4u23ejeJMZA51UdBCC+Wse+SEQfBG/WAMzVIH/UFqGEtv/QBwGCL8WfnKq3keJFDjEGXZsjfMgRb9OEI/wNGpioPM2XsTqjxo8HuKdmeW8YPA= 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=DWCs4eCc; arc=fail smtp.client-ip=40.107.20.41 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="DWCs4eCc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LxyxAMaX0raiZBEuLZqrHMxYyN7AIoIv5Xe6F2RS0BhEdmKAbOEBLo2WluGCf3fIC2t8vA1oJV2kWWapgtXq1OuZEMN8BwT01cE2oQJ+6ehpVGlBvvbV4MCj/gtRdNdqhY2ok0gS04+051/PaVij5/cOfHCd8/zjWUSIO1ixFmWN7VBIyohUZkJNEYHMIn+4Dx3Argo7gJc0dEtp4CnuBnA5YEsmoKoq0HdrkRvKH0iJPLyvsmHLMXYWbwhREb5OrOC9uAS9moopyPgAqaFxZ2NPMPfq6NkTAj7gN+OPQsSMwQTruXs6u+6RURaVzbjIX4jxko+9uUslttsf6sic3Q== 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=FY59PU0GNRFhFxBLb2ptFRe692gLTht110jB5MwRR8U=; b=gahCxM1vlVBCMvuURO/s+0yEaBCULUxhV01Q/7Hosk1lLq8SO+86x07K0n0X9NFCCU1OOPI+ZS0lqAH8YZTfhgLKKPNKZGKKdjUs3kRTRpzgbVsuNoIMlUGLbSUlrSfg3PN5zS0LssHa6a2e8OVUVtyfLgqfino0xgCpGbh2lapDO//yJPZmjKvtpYkoYRYIsd5WKfDQKjUMkyCxBNJ4u/8LdT42WTgn84p7Krx/xZUI2yI73gVtDJDgjg3rj3lqQEk4mwF17hmFm9RImAccCUt2K51Em4vCRojUmuOwW93TG0ahq3m74txDzGokIN0YwoEm1Dkf/60MaY+qSR72Uw== 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=FY59PU0GNRFhFxBLb2ptFRe692gLTht110jB5MwRR8U=; b=DWCs4eCctgOi2sZM3eMHvIVlMlKumoHQeHIlgF9K76aiWiJgoImViIY+7ZfdOwQG44OXBXw0RUitQ7dmcJRxC11IWEymQNsLQOOhJLgcGPtkMC89a8S2rmvlK6vmJr7ha++ZuwMGale9u7hyfINu3GxoHw7l7Z3uo/ofSQgIZHjKzSH3BFZ+niXXGoaSpydVu2imbSvTJPj8ji3umGLsF92s9vOBHDUJjAFMCehsCt3S3Op3R/EeN6f/PT39lcVqBzcNe7i3U9VfFqhLd/asuvh1adLBvOiF+iZQcHE/rpFoTQy+HpEbREw8S/P0bi04gVi8EKFX8q3k1hUYk8GNJA== 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:25 +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:25 +0000 From: Frank Li Date: Wed, 18 Dec 2024 18:08:40 -0500 Subject: [PATCH v13 5/9] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Message-Id: <20241218-ep-msi-v13-5-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=6819; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=WMSa85DyIKk5/tdaJfRJ0u1YGaIJIzUsaDVlLKYUQJw=; b=jqLq6ZrEIqu8eczljjH4I0jmrLY3w4hnwATqHYpITE2jw5OFWYmkHvPFgLrGbXucIftzD6+Fw cDCD54z84XGCfyXHVm+23MeYkzZnf6BaER74RM2V0gEWVeHQXBlEj3z 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: a110d0a8-d652-4bf1-371f-08dd1fb90415 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?TCU/7oo/kJJCBMfPmIxE4MRBCGm/PiJ?= =?utf-8?q?holdm44UUwSM05my9Cw+uB7sfMAE/WJbqR/eZpkqVX31BehGfIwHHtBNYMwfLJ9p7?= =?utf-8?q?HanGLL7y8bhM2BbgcRzb4flh2AxFvc3i3BdXL6D5Mz5NiCg/zx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q86sJullH6CggH?= =?utf-8?q?tDPAHxh62oKzNTUtr7af1vg/Pwm3GrxK5sBNg3LlhawtLrHirXlJcyGmGQSaIOd2z?= =?utf-8?q?dn0xS1IWRPTaMBsm78FbBR1UuNqwIBMz6Njd28RzyBSVAOxbkxQ5ZDvWLfpJF6Z7/?= =?utf-8?q?jwEePGFkMssUL4sex5lCBKkquxmefvk/gBX2Cn/70mJoawY/GwgJ+XLmQGBr76/5p?= =?utf-8?q?WboFIOcl3xWW0FdnpM78RWRVxOc1gqW8hqFQKWSW2waAen97x0WHBk+sAx5MzSUfX?= =?utf-8?q?1D377s/VQUAp8WOUpqLlmCjZ4MryuMb5xp3YZQt+kQjoPA3AcHc+pFW385C/REBWQ?= =?utf-8?q?zH+e6AYkcu9UIqVK4+jCdSGf9gKYb6d78myy28KQRcgQVDR+lLhsoAoAsXVXXJFBZ?= =?utf-8?q?Xln27BsUWTkLmPpSAMaswzbj3uIxsigNw=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?QlaynTPwqO1vJCVTfjpL4pt7AWvV?= =?utf-8?q?tXsPzRc4nPUJowmNxvcSf9rk7ro8hOiPTwGgdhtkBM7mmgVAhJY+m7XBXPq2Lg2Wu?= =?utf-8?q?B/umN4jV+iXySqj9U9zF4JfERDAamc8HV/KCySjdArkie6g0DFz1SeuJRR3ZLPf5v?= =?utf-8?q?dowIV2TyFcw2u+KNDhbP1LKjyTXuD284ZxXVB+R80Qohf7+/bpY/0kLJz0kZTqz5T?= =?utf-8?q?diquVmTZI7m8ZeJAxZWb7+dgiNwxrB8tDIFR74eo7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N7gP7/6JV7OEtMy?= =?utf-8?q?Ee4YnGdpWZmnz0aXQKekiRrFYLh5K5ROeUz1IIf2A9KyjdLqY3ULdLeDF6uBDCFvY?= =?utf-8?q?0z7V+vZkOTeo15gTja4FF3Z2NF3pFCNLdZ6gp/0/x79RJoYgGMiIAkaAOHc9zimIg?= =?utf-8?q?ik/Db2melzvfk4npLOTUwpiN+/Zg+2MWTGvvPF9GCfDJSuqmgb69lxlrhYuunqzG3?= =?utf-8?q?4WU9oFK4pkrcC0FZ1H7dBE2pD7JdUVzOldH8YgB4PGLwkjLZUlmvwo5oNpK0lBczH?= =?utf-8?q?3GWLsfDxLTS86xOmdGkqI0ZxhWzob6PhVB3xdteQQ/feeBtFgXKopcac3o8mufIvJ?= =?utf-8?q?dNby9ypvTuuyRhAk5SgAg4VIze5EK70J8yvY71PZOnyZJVVYK7n2NuYUP3LmWbxgX?= =?utf-8?q?GHIqwzt0/V/L?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a110d0a8-d652-4bf1-371f-08dd1fb90415 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:25.5157 (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: m3Yi9eqwe75FzBt/7jQuogdEoZomHmoPKpa8y1ZA5+tBaXFCLKeZ7+APk6aCyanVmo+uXXqYJ7l42xxBushw2g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9939 Doorbell feature is implemented by mapping the EP's MSI interrupt controller message address to a dedicated BAR in the EPC core. It is the responsibility of the EPF driver to pass the actual message data to be written by the host to the doorbell BAR region through its own logic. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- Change from v12 to v13 - Use DOMAIN_BUS_DEVICE_PCI_EP_MSI Change from v10 to v12 - none Change from v9 to v10 - Create msi domain for each function device. - Remove only function support limiation. My hardware only support one function, so not test more than one case. - use "msi-map" descript msi information msi-map = ; Chagne from v8 to v9 - sort header file - use pci_epc_get(dev_name(msi_desc_to_dev(desc))); - check epf number at pci_epf_alloc_doorbell - Add comments for miss msi-parent case change from v5 to v8 -none Change from v4 to v5 - Remove request_irq() in pci_epc_alloc_doorbell() and leave to EP function driver, so ep function driver can register differece call back function for difference doorbell events and set irq affinity to differece CPU core. - Improve error message when MSI allocate failure. Change from v3 to v4 - msi change to use msi_get_virq() avoid use msi_for_each_desc(). - add new struct for pci_epf_doorbell_msg to msi msg,virq and irq name. - move mutex lock to epc function - initialize variable at declear place. - passdown epf to epc*() function to simplify code. --- drivers/pci/endpoint/pci-ep-msi.c | 104 ++++++++++++++++++++++++++++++++++++++ include/linux/pci-ep-msi.h | 5 ++ include/linux/pci-epf.h | 16 ++++++ 3 files changed, 125 insertions(+) diff --git a/drivers/pci/endpoint/pci-ep-msi.c b/drivers/pci/endpoint/pci-ep-msi.c index 7aedc1cafbd14..33503d86cf2bc 100644 --- a/drivers/pci/endpoint/pci-ep-msi.c +++ b/drivers/pci/endpoint/pci-ep-msi.c @@ -34,3 +34,107 @@ int pci_epf_msi_domain_get_msi_rid(struct device *dev, u32 *rid) return 0; } EXPORT_SYMBOL_GPL(pci_epf_msi_domain_get_msi_rid); + +static void pci_epf_write_msi_msg(struct irq_data *d, struct msi_msg *msg) +{ + struct msi_desc *desc = irq_data_get_msi_desc(d); + struct pci_epf *epf = to_pci_epf(desc->dev); + + if (epf && epf->db_msg && desc->msi_index < epf->num_db) + memcpy(&epf->db_msg[desc->msi_index].msg, msg, sizeof(*msg)); +} + +static void pci_epf_msi_set_desc(msi_alloc_info_t *arg, struct msi_desc *desc) +{ + arg->desc = desc; + arg->hwirq = desc->msi_index; +} + +static const struct msi_domain_template pci_epf_msi_template = { + .chip = { + .name = "EP-MSI", + .irq_mask = irq_chip_mask_parent, + .irq_unmask = irq_chip_unmask_parent, + .irq_write_msi_msg = pci_epf_write_msi_msg, + /* The rest is filled in by the MSI parent */ + }, + + .ops = { + .set_desc = pci_epf_msi_set_desc, + }, + + .info = { + .bus_token = DOMAIN_BUS_DEVICE_PCI_EP_MSI, + }, +}; + +static int pci_epf_device_msi_init_and_alloc_irqs(struct device *dev, unsigned int nvec) +{ + struct irq_domain *domain = dev->msi.domain; + + if (!domain) + return -EINVAL; + + if (!msi_create_device_irq_domain(dev, MSI_DEFAULT_DOMAIN, + &pci_epf_msi_template, nvec, NULL, NULL)) + return -ENODEV; + + return msi_domain_alloc_irqs_range(dev, MSI_DEFAULT_DOMAIN, 0, nvec - 1); +} + +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 num_db) +{ + struct pci_epc *epc = epf->epc; + struct device *dev = &epf->dev; + struct irq_domain *dom; + void *msg; + u32 rid; + int ret; + int i; + + rid = (epf->func_no & 0x7) | (epf->vfunc_no << 3); + dom = of_msi_map_get_device_domain(epc->dev.parent, rid, DOMAIN_BUS_PLATFORM_PCI_EP_MSI); + if (!dom) { + dev_err(dev, "Can't find msi domain\n"); + return -EINVAL; + } + + dev_set_msi_domain(dev, dom); + + msg = kcalloc(num_db, sizeof(struct pci_epf_doorbell_msg), GFP_KERNEL); + if (!msg) + return -ENOMEM; + + epf->num_db = num_db; + epf->db_msg = msg; + + ret = pci_epf_device_msi_init_and_alloc_irqs(dev, num_db); + if (ret) { + /* + * The pcie_ep DT node has to specify 'msi-parent' for EP + * doorbell support to work. Right now only GIC ITS is + * supported. If you have GIC ITS and reached this print, + * perhaps you are missing 'msi-map' in DT. + */ + dev_err(dev, "Failed to allocate MSI\n"); + kfree(msg); + return -ENOMEM; + } + + for (i = 0; i < num_db; i++) + epf->db_msg[i].virq = msi_get_virq(dev, i); + + return ret; +} +EXPORT_SYMBOL_GPL(pci_epf_alloc_doorbell); + +void pci_epf_free_doorbell(struct pci_epf *epf) +{ + msi_domain_free_irqs_all(&epf->dev, MSI_DEFAULT_DOMAIN); + msi_remove_device_irq_domain(&epf->dev, MSI_DEFAULT_DOMAIN); + + kfree(epf->db_msg); + epf->db_msg = NULL; + epf->num_db = 0; +} +EXPORT_SYMBOL_GPL(pci_epf_free_doorbell); diff --git a/include/linux/pci-ep-msi.h b/include/linux/pci-ep-msi.h index 75236867426a4..26b1c86893ee4 100644 --- a/include/linux/pci-ep-msi.h +++ b/include/linux/pci-ep-msi.h @@ -18,4 +18,9 @@ static inline int pci_epf_msi_domain_get_msi_rid(struct device *dev, u32 *rid) } #endif +struct pci_epf; + +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 nums); +void pci_epf_free_doorbell(struct pci_epf *epf); + #endif /* __PCI_EP_MSI__ */ diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 18a3aeb62ae4e..5374e6515ffa0 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -12,6 +12,7 @@ #include #include #include +#include #include struct pci_epf; @@ -125,6 +126,17 @@ struct pci_epf_bar { int flags; }; +/** + * struct pci_epf_doorbell_msg - represents doorbell message + * @msi_msg: MSI message + * @virq: irq number of this doorbell MSI message + * @name: irq name for doorbell interrupt + */ +struct pci_epf_doorbell_msg { + struct msi_msg msg; + int virq; +}; + /** * struct pci_epf - represents the PCI EPF device * @dev: the PCI EPF device @@ -152,6 +164,8 @@ struct pci_epf_bar { * @vfunction_num_map: bitmap to manage virtual function number * @pci_vepf: list of virtual endpoint functions associated with this function * @event_ops: Callbacks for capturing the EPC events + * @db_msg: data for MSI from RC side + * @num_db: number of doorbells */ struct pci_epf { struct device dev; @@ -182,6 +196,8 @@ struct pci_epf { unsigned long vfunction_num_map; struct list_head pci_vepf; const struct pci_epc_event_ops *event_ops; + struct pci_epf_doorbell_msg *db_msg; + u16 num_db; }; /** From patchwork Wed Dec 18 23:08:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13914248 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2041.outbound.protection.outlook.com [40.107.20.41]) (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 94E5E1FE44B for ; Wed, 18 Dec 2024 23:09:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563373; cv=fail; b=sYJ6+o38VOshYyhtiz2tOYdlaQlIhTxXKsKmKB43LIoR7vbPf1+wqryt3PjD2pi4/T1YWlQiyWuDrMs9x1uQMUyzSKjys1cwG+0Aem4hcW3YlwNfmCKrtAg6Jqprra89eKSqf+Oos8Q67sPtNX+P1K5OPILRVw3wk9peDz1ZSeU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563373; c=relaxed/simple; bh=cLEkpOzWDRZk+G7yo89vdyDGtgAmLrqYZZa7SH+fYhc=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=hu00kSBjBzWOHJK/39jGVtk1fEFGmmoWqcMz5TnWiZOMXeWqkQhJNewGDltG5a6HS2Vu0JuwRrbMfkNuUsp0a9l5Za5jB5n6P2DfkghVCftewIs0qw6wOccPXXknSpT4b/ggat0G3+VNt9gSYEJ0tg/b1Ll8XYQ8B0bpY4kE7Po= 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=AawwPuAp; arc=fail smtp.client-ip=40.107.20.41 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="AawwPuAp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vaYdJ2wLjmmJV3xWTQ8LC8cMRSHIDOjOHgQ5HlkQe+zW3kDlIxQJFsLKwWI8PrMea9n8zz3H3twsXrlNkRB3IxwrTBIg6oFZM8GjsfR18P6PYqVHA71FB3QKs/TqFZw7khg3kXUmxNuReMTQtKoQCE0HswuFxz/2OC6s5orWwUktSWxeC8lHawd4dUjFbtfZZdtJtY2uSSxXe3ks0RVmYOk+28YLfChK4mfkhyX70C7/hwGfx7NBtGST7y62QpKwd4rV9OGNeo41696qfALSZWny/E/0kHgLfat3/c5MFHWWDetzWC+c0FxOgj9gSHJOaVkDe4E6Xno102kw85mmYA== 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=UUqKjyu4iesfDGdWp0mMyRh8NSm81pkKsC7XKJ0FTec=; b=UURrI0chQfJArJL1IErtC8IbdXJ3c7wMvSP2wlLlw/Q/D29QTpxUpN02SanAbT59wf4O9CRCjOfyTEIXrtQlLVHBXRN/a1OyoCIL/keIPxrsDb/U/E3QIwhvDOudv3b89OVG0HEZ7d9s1E6J3FGrzTnRhAB5n3xDQak+URGwsKZ2UZmX8BAtE9qQLEc2o4oZZJK0IJSqJ255YsTi6uKYJsXnRdMX82Irf6X/fg6JfHZLXgCKD94R6DCOIYt0ezMIZaab6zGbSvhbrinwjWWI4psovysClr+j9lzB4+0Cd8RUopHzO3+9S9b/Acqb96gIlvRmJKbmc9Wm3xy0OzOCdg== 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=UUqKjyu4iesfDGdWp0mMyRh8NSm81pkKsC7XKJ0FTec=; b=AawwPuApiA6uOnkKJqWoVxQ8cHqw23si70805NWj1NBOd2CvyfMbki2liJflVOjpCYXPSytBYfpHc9UifOrl9oiAVKHaq0stRlDteSqM6liOcdJ9lgGJC830EEgiGtfyaSqEryVOvGg3rsUAUsaNJRByDw2GwTBVBvg1CRCJR2TOPdnqPlxiMMBoCa6osaiZ/z3CvkpjnOXiOxXmaOFrh63HAXuww3s+wNXn70vb7rbK5XOiYCTh64zUKEQibypoYxbzAyjLt80ToZaAnqHyzP9s/sYsmHHg2oXdebvex0J9R7YeG4PYCBnu9P+vP731VP2midcj7GztDwxjwj9vEA== 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:30 +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:29 +0000 From: Frank Li Date: Wed, 18 Dec 2024 18:08:41 -0500 Subject: [PATCH v13 6/9] PCI: endpoint: Add pci_epf_align_inbound_addr() helper for address alignment Message-Id: <20241218-ep-msi-v13-6-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=3395; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=cLEkpOzWDRZk+G7yo89vdyDGtgAmLrqYZZa7SH+fYhc=; b=C39v0uNfyK10Ox21VMlwGjoNNXDHIVqO9nFn6qXIlEJ4FhDDAx0w1lHOIx1kZDrH0K0e+RvDW Tdt4ZQexwqeBMGreNN3l86QwaiI06sPW+ihlXrc3oc3ZsXyXezkdsCb 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: 966937db-8ef7-4e65-38a1-08dd1fb906b9 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?SabVmRtc9TNeKlR+MjsBLrEBqaSaBqk?= =?utf-8?q?GaDuYmjy8TXIpF631rMPTHSpMcLnQBMpxPMB3mFCf6xcIG+8irqX3aOokFNJd37hQ?= =?utf-8?q?BAlQQ0tw6p72LYyawI0ArG9EV7a/hs8vw/YiCvD3Xsh2rOCImJpYf9iqG+DOWQx8i?= =?utf-8?q?iMycQm2kkRV4CK1+PrIkI7aHwQkPmff7tzI0TVj18M7NHIqpbzwtjeqkgPjpTHEi4?= =?utf-8?q?jdfgrknijqIn2csLV6i4MOCWGE2ainJU/vyhyfvdh63m7MSgU8V96FXAKdE7BDQLm?= =?utf-8?q?Kt6NOnEq2j5FOax+D4VZpZNrMpbGurM7q8m8EeJZjN/cKyKgQXHsti4zZ0MrmpUJL?= =?utf-8?q?fzpnwFNmS/+EEJeSyrl/PqolSIu4jIgqQ/uuZBh1J8VTjBDnsyO9WepCg93frMkmu?= =?utf-8?q?2vxMUu9rSJPsDXwdMXo67z+cuLsz+ZPScb6z9SZsWn/EVPCy0OFkIZFi8CrAj/1z6?= =?utf-8?q?yEvoSNy1DDDaaCh039NQfCkYinydPZkz/+jErzOmghqaIrGxDp3mKhO4mVcvgHNuP?= =?utf-8?q?j1PU/MZFgfjAvu8ic8Ti8amJ9ZHmRiWoxNHmcjRIWbOvaO5mWbuaqNhiAUQ5KwhR9?= =?utf-8?q?t8CQDqpc9PzJNx403i8cxUGzv0e/BvBhKPRrx1t4ypZbqGWnN+8tK+9Yodqqpd0AN?= =?utf-8?q?zHhGjxsvvkArAj08anm9CxaZkI/Grwo36kmuvI3C/L22WvLQoMrQcv1eCbAMXRNnX?= =?utf-8?q?RmRet2vZHhGkFM75J2O+ZGTpaEXuhgxec79x74kdrckFAMyfaaQPv08ivTmSNNgbu?= =?utf-8?q?IdFYGtQPWA8mLpJQmyeq5/tb8lk58dfqKDMzpxLi8beJCgGWausVbs5lIByozpquX?= =?utf-8?q?91v7lAGbJad4Yv22eK/jVKs2DOrIaz0MZJVVsgTMUS2nzJOnt9GVaQSL/mXjqZJN9?= =?utf-8?q?CUmUMg970q42cAWl8jMmPTXTDCpD90FnQNPaUFMrf2Kxu5WB8TmbgsxueAWmM0osF?= =?utf-8?q?z8VWZ/Ad3rmcTrW75ReK+9LURf0ZSxfzx8ulyl4LbAIs2vQ/B50KTAiPf34kPgW32?= =?utf-8?q?BolNj2EFp5aj/pGNGjtQpLdHnf8pbE6dYE/gIDDvKU0YpiGvx5ZXfaQGnPUxM56ra?= =?utf-8?q?CbtBDehoB0rmgi1bsP7KhiGY70F/w7cp9mItcC21vx7N6FL2CQmHSwYyCFlJAIHZL?= =?utf-8?q?BYIoiz565xwDf8ySmRM8o1DJPLJmI1DGak0hBDV1kK17pCvlCeivzFLigreKmfhDK?= =?utf-8?q?PX84digDD7SH6Sbp549f8Ey8oc7Fma9TMXvJzuxxjgyk8daOpfq6ijTofMuKkkWob?= =?utf-8?q?vkwxW0DF0xVNvb0VUWLkoDMlvum3xJuOkvgqxAPBQSHhFvzNPuAekHIFt0nqyMqwx?= =?utf-8?q?Hp3p2lAoGx+AVR0DoNfJkWOWmstDL4pg9uEp/mIVRXnNahz8mc78/fdqOLiuvzFjV?= =?utf-8?q?pN5ftNFPyGgWZU1g6km4VQsrdKugWYwIA=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?tuF062KE48P5P/FKQFjuHgTijbUJ?= =?utf-8?q?lZzXq518tjwRTCdYs2nQn6tPRlKaWkhRk7EwDyJS3ig9hZ2L7ddi/9k/9owjQ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r?= =?utf-8?q?7qoD+wYlk25z1NqaC1H74bjYupKGOua/q4nTzr1dHZ0vcX/CdEBGdDAObJYebESqA?= =?utf-8?q?jokESzjIMXFMLHl3s7Pe29kT/6l9Mvvpr1mnCQTKgFUl1pJ2DInTHIoxs7Vs2QuIg?= =?utf-8?q?tn7sEBJzAEZShypsQLH5IhfClkk8GQkT/BaODNbbDV2pnfDu6ARQ9dzWcGQfOSg+j?= =?utf-8?q?q6Qa427kWIh42uADwj9bmLucihVO303yhpGHAtk+QLSOmnRyPzuC6uLQlMLO2r4E3?= =?utf-8?q?4R8rB42GIqxcz5UdC8GE5IHntx3chVkZG3x8LHGsUqtyMDeV0kQJFzQoC4kGnr045?= =?utf-8?q?D1kzzBa0bsPQ1LaYUoKCC8TZmrA+1t+M78E2+6vd6MoRVInLCvki0kXuLVS/jU1AH?= =?utf-8?q?5wWYNXiEDukWEvksVLj9/GpC4IuM0o1Q+d+gvS/JxyOo59HYmHsbzWn6xjgDCyf9J?= =?utf-8?q?ElU4b77g/YLwMrA9fL0KK6tCYHtqXq+9ntSn75PvPyRMMr6jmWpmUvc8SzoGirbU+?= =?utf-8?q?cnZo3m9EisKOtuDAz4gRahkrtwZxSVudPajKtWKMfVigF90ILZGc8Gp7HEyY7lA59?= =?utf-8?q?oLMqwQmd3W7c?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 966937db-8ef7-4e65-38a1-08dd1fb906b9 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:29.9448 (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: pNFM1dkWl2D1MGuJKqPtZTtWgtPbH5IosXzkz4hAfm8HN7kmhSVRRPLMC/3eXZh/GGewrvPTUUFI/3tew6dzTA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9939 Introduce the helper function pci_epf_align_inbound_addr() to adjust addresses according to PCI BAR alignment requirements, converting addresses into base and offset values. Signed-off-by: Frank Li --- Change form v9 to v13 - none change from v8 to v9 - pci_epf_align_inbound_addr(), base and off must be not NULL - rm pci_epf_align_inbound_addr_lo_hi() change from v7 to v8 - change name to pci_epf_align_inbound_addr() - update comment said only need for memory, which not allocated by pci_epf_alloc_space(). change from v6 to v7 - new patch --- drivers/pci/endpoint/pci-epf-core.c | 44 +++++++++++++++++++++++++++++++++++++ include/linux/pci-epf.h | 3 +++ 2 files changed, 47 insertions(+) diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 8fa2797d4169a..d7a80f9c1e661 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -464,6 +464,50 @@ struct pci_epf *pci_epf_create(const char *name) } EXPORT_SYMBOL_GPL(pci_epf_create); +/** + * pci_epf_align_inbound_addr() - Get base address and offset that match BAR's + * alignment requirement + * @epf: the EPF device + * @addr: the address of the memory + * @bar: the BAR number corresponding to map addr + * @base: return base address, which match BAR's alignment requirement. + * @off: return offset. + * + * Helper function to convert input 'addr' to base and offset, which match + * BAR's alignment requirement. + * + * The pci_epf_alloc_space() function already accounts for alignment. This is + * primarily intended for use with other memory regions not allocated by + * pci_epf_alloc_space(), such as peripheral register spaces or the trigger + * address for a platform MSI controller. + */ +int pci_epf_align_inbound_addr(struct pci_epf *epf, enum pci_barno bar, + u64 addr, u64 *base, size_t *off) +{ + const struct pci_epc_features *epc_features; + u64 align; + + if (!base || !off) + return -EINVAL; + + epc_features = pci_epc_get_features(epf->epc, epf->func_no, epf->vfunc_no); + if (!epc_features) { + dev_err(&epf->dev, "epc_features not implemented\n"); + return -EOPNOTSUPP; + } + + align = epc_features->align; + align = align ? align : 128; + if (epc_features->bar[bar].type == BAR_FIXED) + align = max(epc_features->bar[bar].fixed_size, align); + + *base = round_down(addr, align); + *off = addr & (align - 1); + + return 0; +} +EXPORT_SYMBOL_GPL(pci_epf_align_inbound_addr); + static void pci_epf_dev_release(struct device *dev) { struct pci_epf *epf = to_pci_epf(dev); diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 5374e6515ffa0..2847d195433bf 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -238,6 +238,9 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar, enum pci_epc_interface_type type); void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar, enum pci_epc_interface_type type); + +int pci_epf_align_inbound_addr(struct pci_epf *epf, enum pci_barno bar, + u64 addr, u64 *base, size_t *off); int pci_epf_bind(struct pci_epf *epf); void pci_epf_unbind(struct pci_epf *epf); int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf); From patchwork Wed Dec 18 23:08:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13914249 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2068.outbound.protection.outlook.com [40.107.20.68]) (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 BDBE51FE473 for ; Wed, 18 Dec 2024 23:09:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563379; cv=fail; b=pg5HKQZroIKNE2Yj23ajPeCpqU2lkX189Bs+zAPY20yHzCrep4ZlcyYqhicMPyJyrrhnN8xGxiIC0EBkzrllfgabl1E0H5UdiwdMKUVMkX1QPZzlVZCW2GK6uUKubu1beEF8GXgDK269fGco6+X7xjpCgi8us5cBkqnEwkouU2U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563379; c=relaxed/simple; bh=+tf6wudUoIbEsl/FZUMDaGOl5nvUQhr4hR8U75xWVfI=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=uG1fX3CsPHRKIQyxieJNFinmsNHgRo5nOday3EFYMOrlUJZ9YVPVXT2d6ra9VHdtX/6cQm1oHzz7dSFR+Kumr9K4WeZZwNa64Wpoj2aJ2SlMImGFBc5RQvNttP9IKx95PNmDK7GcCUxrsuhArrjUZVhGEI3KI1WIReRVAD42nLk= 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=TQvHSC6K; arc=fail smtp.client-ip=40.107.20.68 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="TQvHSC6K" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=psVHzcxMOXFsFoOaPAodoe/yzvVk0DWwy1PvrsUZpPISztU6hO22OezdKap/6gmH9WacZODU2t0nOYYmtH1xMR6g+jrPsLjsqQnQQX2wTrJztI9zjf7vOp0uvRyL9ektJ6GXn4t5BzgdY0jzpl0gnRrSPyf+qd3kwJbQyq6L0Gu0AAp3Qd9dqOROZeAAupKyiqqdrBI9sM6HsDjPv4qpuLq+KkegY76S6EWjTGoVC15Z6u01vLUy++43SNRDxOw78/l2MvVT9RDDnHxM/+I3B9TfjqbfVfSiGrRS3hYTiUYO/S4sgMueOIuqfQWdwvhjHUex6Zhn0Oe4y39FqEkTqA== 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=2EsQMPhR1nPrXLiGi6B1VPzpAgUnb47cDPExYl7k0lA=; b=iAagzOryysy0Me4sL+UvglvfyxjmFZ5bZJ9VrGLHIB/iunG98MJJ4NlVTKxqqWjXb0JMoRg3BEAxe9VG9RHYF2Txyd4C6OlAPToX6PAB9SJzKeo3maO3VCF5rtO9M8jbbEGpwqJwqxmxuvapcrWzOwLTQOlVm2Lc6kFs3JgVYGuV3J7fQPta095KwjHSj/gO+bWkVYkU9NgiOS+IwHwSfpsaGwp8zkI/qEjktTkbzFQZAY1vB1K21kopDX3C43QtmPcTWYFKmLlafMT2UT1OLAAZt7jevIbq2tzIaQSFUz+b0k2EW+PZimpXQYwwhJv0kRwH912nnCeYH9mBYqVYqg== 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=2EsQMPhR1nPrXLiGi6B1VPzpAgUnb47cDPExYl7k0lA=; b=TQvHSC6KNLGS12PopZgoWkkNMY1/l4cegWywpUgUXTAEKpZUMl2/zyjMk5YPGe0zzF56i8xaqsvE5Nz5FpMw3yjHUNIn2q7XPGzbBmPw+D5b4/KMSyL9kG7rFPd8leFSHXn2L7q3eCsytWvQwd2ow+8ny5QV1klsAC0T2WFFVf1IOt+C8veLEuXmD4yt09Cu2sYLNK/7S2v3rHcDOqRYtOzfMGkgdAnWis3fyl91m3V/eKgI1GjGQ9T/HvARuycdZ2tkHnyykNNfYdOQBtmw4EhAqQIKryat2NPXmV3bXcswfOyhgEpEXpI0QpSXM7ng9TtdqAzGaOo6wGvSAqrMJA== 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:34 +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:34 +0000 From: Frank Li Date: Wed, 18 Dec 2024 18:08:42 -0500 Subject: [PATCH v13 7/9] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20241218-ep-msi-v13-7-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=7892; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=+tf6wudUoIbEsl/FZUMDaGOl5nvUQhr4hR8U75xWVfI=; b=npYniliL17rb38kwx/P4jIuV8n0K8bEGquKoLUhFzPbCPZ29imQcvss7wSPWZNXcEAOJ2U+EA ja0KUdLbalnCGf/F2xFERIfVhzWAWL8Arb6S1T1ABVXbXLUWTX1Twkl 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: 3e51f7d8-6d3a-47e9-4c8d-08dd1fb9095b 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?7pcgq3x9RGqSnryvYVhc+zxkydYfWps?= =?utf-8?q?PrefJQ9HEXH8KweQUbQkm08AxnE2lia5PFxG4J7WJjUkpBJd96eRMjyHoYD8gTEXh?= =?utf-8?q?mtcC7/WbcYav4ZivBoVtYiib0eIe1ffTYWKlY8OKxriDZCg7Dd0zmNlsrTgbAT4Pn?= =?utf-8?q?e+++LNCRV4FY6kb6MXb8MINDyDj3EGBaT1H4wsmvAfS5nypq8yEMqguWQf9ORhEEk?= =?utf-8?q?p3x3fz205WRX6LiJRILzGqQWgZvRLF3BU2IulNXjLhUEcPIpPS/z/tahCq2FYHs1k?= =?utf-8?q?PhN1sxnvAX4IVFZFvhvsLey9emtQKxfPYnlBvfAy2tKCA6JjhTlCPCQKtAaJxQ50S?= =?utf-8?q?2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9MOsw2vlzU1C+MRC+jqk/8YdfwF1EPGCM5EfrT6uHmR2XDq5SgBIpeFFVtYN?= =?utf-8?q?B/sKEjflIXnGDXvOotkjs+XmYNcBhKbEcdP988HAhNXypw4d+izJjPxyl4ZO1iAsg?= =?utf-8?q?st/B6O4JbFTGQgD1QDJsOQSBbuwBhM9yWehTswYp7uGlnloPVHqd1/DPqXVXJfN1t?= =?utf-8?q?rki9tKbthmyGdWX0G3LmVv/s4oUCt4r8g=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?+V4mIw/UwwNqKZvZoUzRwT0oVANz?= =?utf-8?q?m9/oWL6DyI2Qw35SQQbH6YIuYNA4ArnPXQt+ew6aGrMDgFDJt/duyDAvXlI2M4Js0?= =?utf-8?q?cbwF85qGHKUd3V1nqKhxfcp3Lqi1IGigehZsL6JbaSKx4eh5tczZuG+Ba14QOpBDx?= =?utf-8?q?JqbGHM3HZfgq30y22048shmlZDGSZNvzgafrW8Wavt+mwSd4IxNUjuSAHIQf6eTC+?= =?utf-8?q?wwmfERQZnKWsgDjpr8RBUb6MQTIAE2/HMlb67ZVjLYO+h1c+r95U8BXndUDv9MIO2?= =?utf-8?q?lqfNmHrP71USa6t08EZI8pkLxm7deFR6nEB4kYIgVhlQrAk6MzIjMHkBiYoFD9m5o?= =?utf-8?q?uWTXOXZPWPApvydmc1pZEHAoQGVyvF0s3I3dPrxJubebXF04W1uMrr4v+k49cVO+M?= =?utf-8?q?Qj9HtequIkRE4yheAien7Z5mNwul1NcOhA1gRgiaC6jhUP11ZHJ31WIr+Ag72Z5sM?= =?utf-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0w1mqklUvcmHS0fSM8FNy/79aX3IsqsYNZLLitRTT/4x0LBwHPsmYJzKHj?= =?utf-8?q?55WXewQghwQzZqA3qC88AjKZzRMuNA+eyrXnwcZQbMlIcyfR3j6kFOXelXZjWUDOs?= =?utf-8?q?zzXZgw2dULasqPrEOvEV7/OMilxrrHaN+U2hxPrLX62Tb+qbIfH3zZ9dIuUOzD8W8?= =?utf-8?q?ra/6e/TQkay8?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e51f7d8-6d3a-47e9-4c8d-08dd1fb9095b 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:34.3649 (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: g3D0I/rG6j6tZfedXqxto7EeETXsGKE+mfn53kxbH+PiT75NYhOTV4UcR1UXwm78wYbuGf+TP67lI69XWST28g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9939 Add three registers: doorbell_bar, doorbell_addr, and doorbell_data. Use pci_epf_alloc_doorbell() to allocate a doorbell address space. Enable the Root Complex (RC) side driver to trigger pci-epc-test's doorbell callback handler by writing doorbell_data to the mapped doorbell_bar's address space. Set STATUS_DOORBELL_SUCCESS in the doorbell callback to indicate completion. Avoid breaking compatibility between host and endpoint, add new command COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. Host side need send COMMAND_ENABLE_DOORBELL to map one bar's inbound address to MSI space. the command COMMAND_DISABLE_DOORBELL to recovery original inbound address mapping. Host side new driver Host side old driver EP: new driver S F EP: old driver F F S: If EP side support MSI, 'pcitest -B' return success. If EP side doesn't support MSI, the same to 'F'. F: 'pcitest -B' return failure, other case as usual. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- Change from v9 to v13 - none Change from v8 to v9 - move pci_epf_alloc_doorbell() into pci_epf_{enable/disable}_doorbell(). - remove doorbell_done in commit message. - rename pci_epf_{enable/disable}_doorbell() to pci_epf_test_{enable/disable}_doorbell() to align corrent code style. Change from v7 to v8 - rename to pci_epf_align_inbound_addr_lo_hi() Change from v6 to v7 - use help function pci_epf_align_addr_lo_hi() Change from v5 to v6 - rename doorbell_addr to doorbell_offset Chagne from v4 to v5 - Add doorbell free at unbind function. - Move msi irq handler to here to more complex user case, such as differece doorbell can use difference handler function. - Add Niklas's code to handle fixed bar's case. If need add your signed-off tag or co-developer tag, please let me know. change from v3 to v4 - remove revid requirement - Add command COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. - call pci_epc_set_bar() to map inbound address to MSI space only at COMMAND_ENABLE_DOORBELL. --- drivers/pci/endpoint/functions/pci-epf-test.c | 132 ++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index ef6677f34116e..a0a0e86a081cb 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -11,12 +11,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include #define IRQ_TYPE_INTX 0 @@ -29,6 +31,8 @@ #define COMMAND_READ BIT(3) #define COMMAND_WRITE BIT(4) #define COMMAND_COPY BIT(5) +#define COMMAND_ENABLE_DOORBELL BIT(6) +#define COMMAND_DISABLE_DOORBELL BIT(7) #define STATUS_READ_SUCCESS BIT(0) #define STATUS_READ_FAIL BIT(1) @@ -39,6 +43,11 @@ #define STATUS_IRQ_RAISED BIT(6) #define STATUS_SRC_ADDR_INVALID BIT(7) #define STATUS_DST_ADDR_INVALID BIT(8) +#define STATUS_DOORBELL_SUCCESS BIT(9) +#define STATUS_DOORBELL_ENABLE_SUCCESS BIT(10) +#define STATUS_DOORBELL_ENABLE_FAIL BIT(11) +#define STATUS_DOORBELL_DISABLE_SUCCESS BIT(12) +#define STATUS_DOORBELL_DISABLE_FAIL BIT(13) #define FLAG_USE_DMA BIT(0) @@ -74,6 +83,9 @@ struct pci_epf_test_reg { u32 irq_type; u32 irq_number; u32 flags; + u32 doorbell_bar; + u32 doorbell_offset; + u32 doorbell_data; } __packed; static struct pci_epf_header test_header = { @@ -642,6 +654,117 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test, } } +static irqreturn_t pci_epf_test_doorbell_handler(int irq, void *data) +{ + struct pci_epf_test *epf_test = data; + enum pci_barno test_reg_bar = epf_test->test_reg_bar; + struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + + reg->status |= STATUS_DOORBELL_SUCCESS; + pci_epf_test_raise_irq(epf_test, reg); + + return IRQ_HANDLED; +} + +static void pci_epf_test_doorbell_cleanup(struct pci_epf_test *epf_test) +{ + struct pci_epf_test_reg *reg = epf_test->reg[epf_test->test_reg_bar]; + struct pci_epf *epf = epf_test->epf; + + if (reg->doorbell_bar > 0) { + free_irq(epf->db_msg[0].virq, epf_test); + reg->doorbell_bar = NO_BAR; + } + + if (epf->db_msg) + pci_epf_free_doorbell(epf); +} + +static void pci_epf_test_enable_doorbell(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) +{ + struct pci_epf *epf = epf_test->epf; + struct pci_epf_bar db_bar = {}; + struct pci_epc *epc = epf->epc; + struct msi_msg *msg; + enum pci_barno bar; + size_t offset; + int ret; + + ret = pci_epf_alloc_doorbell(epf, 1); + if (ret) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + msg = &epf->db_msg[0].msg; + bar = pci_epc_get_next_free_bar(epf_test->epc_features, epf_test->test_reg_bar + 1); + if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + return; + } + + ret = request_irq(epf->db_msg[0].virq, pci_epf_test_doorbell_handler, 0, + "pci-test-doorbell", epf_test); + if (ret) { + dev_err(&epf->dev, + "Failed to request irq %d, doorbell feature is not supported\n", + epf->db_msg[0].virq); + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + pci_epf_test_doorbell_cleanup(epf_test); + return; + } + + reg->doorbell_data = msg->data; + reg->doorbell_bar = bar; + + msg = &epf->db_msg[0].msg; + ret = pci_epf_align_inbound_addr(epf, bar, ((u64)msg->address_hi << 32) | msg->address_lo, + &db_bar.phys_addr, &offset); + + if (ret) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + pci_epf_test_doorbell_cleanup(epf_test); + return; + } + + reg->doorbell_offset = offset; + + db_bar.barno = bar; + db_bar.size = epf->bar[bar].size; + db_bar.flags = epf->bar[bar].flags; + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &db_bar); + if (ret) { + reg->status |= STATUS_DOORBELL_ENABLE_FAIL; + pci_epf_test_doorbell_cleanup(epf_test); + } else { + reg->status |= STATUS_DOORBELL_ENABLE_SUCCESS; + } +} + +static void pci_epf_test_disable_doorbell(struct pci_epf_test *epf_test, + struct pci_epf_test_reg *reg) +{ + enum pci_barno bar = reg->doorbell_bar; + struct pci_epf *epf = epf_test->epf; + struct pci_epc *epc = epf->epc; + int ret; + + if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) { + reg->status |= STATUS_DOORBELL_DISABLE_FAIL; + return; + } + + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf->bar[bar]); + if (ret) + reg->status |= STATUS_DOORBELL_DISABLE_FAIL; + else + reg->status |= STATUS_DOORBELL_DISABLE_SUCCESS; + + pci_epf_test_doorbell_cleanup(epf_test); +} + static void pci_epf_test_cmd_handler(struct work_struct *work) { u32 command; @@ -688,6 +811,14 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) pci_epf_test_copy(epf_test, reg); pci_epf_test_raise_irq(epf_test, reg); break; + case COMMAND_ENABLE_DOORBELL: + pci_epf_test_enable_doorbell(epf_test, reg); + pci_epf_test_raise_irq(epf_test, reg); + break; + case COMMAND_DISABLE_DOORBELL: + pci_epf_test_disable_doorbell(epf_test, reg); + pci_epf_test_raise_irq(epf_test, reg); + break; default: dev_err(dev, "Invalid command 0x%x\n", command); break; @@ -934,6 +1065,7 @@ static void pci_epf_test_unbind(struct pci_epf *epf) pci_epf_test_clean_dma_chan(epf_test); pci_epf_test_clear_bar(epf); } + pci_epf_test_doorbell_cleanup(epf_test); pci_epf_test_free_space(epf); } From patchwork Wed Dec 18 23:08:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13914250 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2064.outbound.protection.outlook.com [40.107.20.64]) (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 389C91FECD2 for ; Wed, 18 Dec 2024 23:09:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563383; cv=fail; b=HmPRQhZwfgQYrABFsZMm+aJw39pbeouoKlwNjAYYjmhDPrMYr/MUG7K6ZYZwhkefgCsANkl8Y4omiOmLBFR5L4bOWIrhHZpEvNYDLXscWlEXILC8QbWLshKqfiZOrBIehe8qd86cJKIzVyOQbVCuhz7mlOQ7LHMXw7oAyKhLiSA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563383; c=relaxed/simple; bh=l2C6LMJUqwjfL15mBdBVMv+pFsAcLtUzpfL941VFEhU=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=eftJLqzlI0E0AzROhoHyKks2M7X/dnJiRNdlrFTTeK8S3FqQh+pLmn2h/8Jr9n8zVN3zSZGVDz3L/EiLDOvmBVElci452OwKBAtfFe+4AEgxAYqv5hBfqQfgIboNU0DDcPcUsqslOcqflPXPkmjQKaDuof1cucmTagsnpLWLx3o= 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=FkoWw0px; arc=fail smtp.client-ip=40.107.20.64 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="FkoWw0px" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WFu6SC2/R0VBrev13OPujGXA4mzh4USOzvNuco3IB7BrcFRJNu6mMXpv1Jz61F6wwcsvgDRYWDAi3sbR9f/zXmVeJCjim01ecOUeRs+sEi0dT1G1H199KVVEbUzlKvPhhjKl6eBCtsdTd0KNG5OMqvF4R89bQ8tvXtSCbSnBiKVBFYYTuZB6CUL0DlOTjNpTn7ofhDXNzhXU0M2KAKKnxBheO2zXiWePWq+2AXAKjnnkfAB/Q9WQcN8ZwCSWPSetJPK0k1yQ15NTAh5t0f7Z76Q1DFYdmGJhpO1QWB+GFTdC00wpdY7gG6r4wvJQX/yhi1T1bkpk7DTsNQBe2mwPvQ== 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=qMhmx3IfMKOGBT5AVmm/AVxd6Wdf4EwS7VY3c3uyOJQ=; b=D0TGwIRTSPSLIBbx36WwjCyeokt72Ujc+7K/ubEzxfDh8/SNHyg01MxuYC+sTYp5t89+a2JvNqkkKvezfY+HWPK6qRlFqTQrOExImnnRKP1YZZ72BRjUqeYoHl/ox5AI1kmLGC9DBeeu+OPp7XaJvPb6S1N9tJ8dWGmXt07ig3LafWMTfZTaLWu8JOgQ5HFy4N0X+GoA09XeLdOTM2QrUvEhA5I7oqhvdNCc7N46w/o+kmhd43TZj56xiCewZzRDm+9bmic+Vyj3TjvpIaHg5Iz+wr14NjMK/PgHCKl1nUWeP0Y2aML9i8plrWMROFXu5stKwJ4vPQsYu1uaI7k1ZQ== 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=qMhmx3IfMKOGBT5AVmm/AVxd6Wdf4EwS7VY3c3uyOJQ=; b=FkoWw0pxN73Pc0zHafqohI6P3FSl1/jOxVG9Ow1kwWDzFLBpoDnBQGZYl8FzulDQayZGIrUeCp7fTUgpcQGYgFeaL3gOZg7+gFR7yJXSh6KaapNdCUFZFNGCElGJF9zLND/HiVDGWhmITZ2hfwuglD5fymPbICOZd1Bsp8l0t3jAja5Ul5OeFgLQVmNfFG+vYumNSspdkO+xgaBGofYQNoJBTkGu1vniK3oUJDbg3Z6vYVv9/pKVGH+5xwUYaNSMauDbp1ohGe7XEs2WptRJxBB9rg2l6dI6jdCHJ9h2mPbezbj3m+kdrabySLYxcT/7JbrRni0WL636Kke3nEEcKQ== 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:38 +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:38 +0000 From: Frank Li Date: Wed, 18 Dec 2024 18:08:43 -0500 Subject: [PATCH v13 8/9] misc: pci_endpoint_test: Add doorbell test case Message-Id: <20241218-ep-msi-v13-8-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=1734563339; l=5981; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=l2C6LMJUqwjfL15mBdBVMv+pFsAcLtUzpfL941VFEhU=; b=91oNFsG/tnoV+sN6DpKwYVDM/B8v2uynPI0+sX3ID3wYxbkT5ABMfcnrDgnFh0e8F5EyGWcYy CqBo5OASkCwDzFU8LgGfGB40n6qYwgzCRiAxJdAduyWosOcUOadnu/J 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: 60a3e669-3326-4d3f-8d2a-08dd1fb90bfe 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?WT8Mn6pwwygjvKcJSljnn/U8udU69Hl?= =?utf-8?q?XXEu5py9JZAcob6Pg7lWaYaMXaf95XJPv5DNGe0RVirh0WwRsCJPubrGt3eYMCOl+?= =?utf-8?q?a+EN54mchdzufAjFJZGR7mLshAJxkyMzHo8MC8ERmtE5fU6qqx4gdz0aVI1CFJGNp?= =?utf-8?q?aqFKNi8nRsbjr8ZaSNnW/zlJ3uZw21SlhxYz+TIBgsE+1yVNuORcVl2/LEewliS9l?= =?utf-8?q?GAm+keWV3K99dSun9XKGEQdgcLnFH+ufwVA0V+A6GFzWIt9SISN4d6Et7ksAlsLEd?= =?utf-8?q?whMayL3tNAsY89E9VRh8CobJbrQkZLu4TwkKEHg46s+ljkO64n/cb1iK6yiWpYwy1?= =?utf-8?q?4OFGwJ74Pz43lx1lOMXcLleBFwSYvA8xWRLKSeHPe4LGvnGIa23cZndc75LYsi6DJ?= =?utf-8?q?d+ZJm/W/3+lWgVwO/Uu2ZuUvcqEfPCBrNMPfyKm7hanM8gWZlrKGgYn23AEupja2p?= =?utf-8?q?8KyakzLBhR3tRWdu40oxRh79T/MoFJUf5o3DP1zYmdYbfI0u2mCmPNB3CtndG0XiJ?= =?utf-8?q?uJZvbRoFv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rgRQ9Duarq77lf5+UjmUqIrCOgvKQ=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?AXXc6svhBdfJrSuYjs3xbsBS26Ni?= =?utf-8?q?MvUXchcm8RSXJAbCILwEVhfAyoT+FW2zX/iJPOKLtvvjcVhogCyKrtB/4Pchn7KML?= =?utf-8?q?JuNMtOkLze/EjbBTNhcTa7tz+JyPMB5wE3LqJMtFVFieveB0iynu4z9XRniSbnlIo?= =?utf-8?q?t5I3BE2zL85MkJA8KeV4EmRNCHpCIctR3KM3yqkmHHff5mC6g9aJiDVJTGpkJf82L?= =?utf-8?q?5ZRn2VGQTemG4iPGiBf2qZr9YVLi1kIWZnA+rJBRUW11NXTV1bO0RvLI+0KhofpWx?= =?utf-8?q?M/DOiTeJyoT4kcyQoxTyGnThYUXoWNvMRR+MeBZ+W3X2FQEwFHwViIYPm/o0brbv9?= =?utf-8?q?hhPavQwm7w5h5aSdOV0TCcjfb+ojHMA7G3tCsC89xc/eUnw3Chu3rq3YTcVWkONWY?= =?utf-8?q?zssGGkTKt6ITZC1Sg2uPua2SLsJXX4BOkYS1DMih5Gj7a7SnEz0nmJoTZp/gAjWG0?= =?utf-8?q?f8Q9DTF06c3nHI7TSInaNPiy6AmLsFN9u5xlWbUFNOOC0dA9DuGrpGB6Wj6TUyTIY?= =?utf-8?q?Fx3voCPXrmmSVW0I0Ijp0LF3P2TjWPWv/kRz3Xyd7l4q7cPed1sTJfbK3ImnpnVjJ?= =?utf-8?q?oXbtV+n8hLlX7UrrkXLGmMJA0mRxT1iNxR1YHXNq/r6FYk3y5dX6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Ow7DIiF?= =?utf-8?q?nNDY8X83GgK1?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 60a3e669-3326-4d3f-8d2a-08dd1fb90bfe 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:38.7910 (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: E6NatG5Afnz7WEyiQJTfL7pW8DfbYaGto6o8qKXS908t3ayNWyJ2PE9FjOnP/uHqsc+NdFVFcHJRuDhU56cicg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9939 Add three registers: PCIE_ENDPOINT_TEST_DB_BAR, PCIE_ENDPOINT_TEST_DB_ADDR, and PCIE_ENDPOINT_TEST_DB_DATA. Trigger the doorbell by writing data from PCI_ENDPOINT_TEST_DB_DATA to the address provided by PCI_ENDPOINT_TEST_DB_OFFSET and wait for endpoint feedback. Add two command to COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL to enable EP side's doorbell support and avoid compatible problem, which host side driver miss-match with endpoint side function driver. See below table: Host side new driver Host side old driver EP: new driver S F EP: old driver F F S: If EP side support MSI, 'pcitest -B' return success. If EP side doesn't support MSI, the same to 'F'. F: 'pcitest -B' return failure, other case as usual. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- Change from v9 to v13 - none Change from v8 to v9 - change PCITEST_DOORBELL to 0xa Change form v6 to v8 - none Change from v5 to v6 - %s/PCI_ENDPOINT_TEST_DB_ADDR/PCI_ENDPOINT_TEST_DB_OFFSET/g Change from v4 to v5 - remove unused varible - add irq_type at pci_endpoint_test_doorbell(); change from v3 to v4 - Add COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. - Remove new DID requirement. --- drivers/misc/pci_endpoint_test.c | 80 ++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/pcitest.h | 1 + 2 files changed, 81 insertions(+) diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 3aaaf47fa4ee2..b3f36b6ba8ba2 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -42,6 +42,8 @@ #define COMMAND_READ BIT(3) #define COMMAND_WRITE BIT(4) #define COMMAND_COPY BIT(5) +#define COMMAND_ENABLE_DOORBELL BIT(6) +#define COMMAND_DISABLE_DOORBELL BIT(7) #define PCI_ENDPOINT_TEST_STATUS 0x8 #define STATUS_READ_SUCCESS BIT(0) @@ -53,6 +55,11 @@ #define STATUS_IRQ_RAISED BIT(6) #define STATUS_SRC_ADDR_INVALID BIT(7) #define STATUS_DST_ADDR_INVALID BIT(8) +#define STATUS_DOORBELL_SUCCESS BIT(9) +#define STATUS_DOORBELL_ENABLE_SUCCESS BIT(10) +#define STATUS_DOORBELL_ENABLE_FAIL BIT(11) +#define STATUS_DOORBELL_DISABLE_SUCCESS BIT(12) +#define STATUS_DOORBELL_DISABLE_FAIL BIT(13) #define PCI_ENDPOINT_TEST_LOWER_SRC_ADDR 0x0c #define PCI_ENDPOINT_TEST_UPPER_SRC_ADDR 0x10 @@ -67,6 +74,10 @@ #define PCI_ENDPOINT_TEST_IRQ_NUMBER 0x28 #define PCI_ENDPOINT_TEST_FLAGS 0x2c +#define PCI_ENDPOINT_TEST_DB_BAR 0x30 +#define PCI_ENDPOINT_TEST_DB_OFFSET 0x34 +#define PCI_ENDPOINT_TEST_DB_DATA 0x38 + #define FLAG_USE_DMA BIT(0) #define PCI_DEVICE_ID_TI_AM654 0xb00c @@ -108,6 +119,7 @@ enum pci_barno { BAR_3, BAR_4, BAR_5, + NO_BAR = -1, }; struct pci_endpoint_test { @@ -746,6 +758,71 @@ static bool pci_endpoint_test_set_irq(struct pci_endpoint_test *test, return false; } +static bool pci_endpoint_test_doorbell(struct pci_endpoint_test *test) +{ + struct pci_dev *pdev = test->pdev; + struct device *dev = &pdev->dev; + int irq_type = test->irq_type; + enum pci_barno bar; + u32 data, status; + u32 addr; + + if (irq_type < IRQ_TYPE_INTX || irq_type > IRQ_TYPE_MSIX) { + dev_err(dev, "Invalid IRQ type option\n"); + return false; + } + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, + COMMAND_ENABLE_DOORBELL); + + wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); + + status = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + if (status & STATUS_DOORBELL_ENABLE_FAIL) { + dev_err(dev, "Failed to enable doorbell\n"); + return false; + } + + data = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_DATA); + addr = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_OFFSET); + bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_STATUS, 0); + + bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR); + + writel(data, test->bar[bar] + addr); + + wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); + + status = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + + if (!(status & STATUS_DOORBELL_SUCCESS)) + dev_err(dev, "Endpoint have not received Doorbell\n"); + + pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, + COMMAND_DISABLE_DOORBELL); + + wait_for_completion_timeout(&test->irq_raised, msecs_to_jiffies(1000)); + + status |= pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); + + if (status & STATUS_DOORBELL_DISABLE_FAIL) { + dev_err(dev, "Failed to disable doorbell\n"); + return false; + } + + if (!(status & STATUS_DOORBELL_SUCCESS)) + return false; + + return true; +} + static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -793,6 +870,9 @@ static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd, case PCITEST_CLEAR_IRQ: ret = pci_endpoint_test_clear_irq(test); break; + case PCITEST_DOORBELL: + ret = pci_endpoint_test_doorbell(test); + break; } ret: diff --git a/include/uapi/linux/pcitest.h b/include/uapi/linux/pcitest.h index 94b46b043b536..b82e7f2ed937d 100644 --- a/include/uapi/linux/pcitest.h +++ b/include/uapi/linux/pcitest.h @@ -20,6 +20,7 @@ #define PCITEST_MSIX _IOW('P', 0x7, int) #define PCITEST_SET_IRQTYPE _IOW('P', 0x8, int) #define PCITEST_GET_IRQTYPE _IO('P', 0x9) +#define PCITEST_DOORBELL _IO('P', 0xa) #define PCITEST_CLEAR_IRQ _IO('P', 0x10) #define PCITEST_FLAGS_USE_DMA 0x00000001 From patchwork Wed Dec 18 23:08:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13914251 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2071.outbound.protection.outlook.com [40.107.21.71]) (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 373961FD7A4 for ; Wed, 18 Dec 2024 23:09:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563388; cv=fail; b=gpXylzTTz3rkdtAhtbFB90T0wrqENw/YSOwhZsibSkE0yI5hDL4p5K63JWiu29jZx8AHtRFWwoE3CiMwIM1MP7LMZU4pWS9ZzcrlvnE+3yv7KB086qeXJPi2T/RMx+9WRkHOAspgAimYYcvDJ+QA/91+SLHY7yZXhrrD4ya7zHQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563388; c=relaxed/simple; bh=XbEugLgmvGxvNIdnJ6oC4l02fBY7NXWQcWS+O1eGi8g=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=UZnBAjc/KK3CgkdLPcuEnjeqVv4LKAnVdZx9lOnb3DdJ/Ud9XlfAOpt41EAyCuetBlupR/81wxC09q7DBj/opNpxgze9RQZLd7JfewKnrgJxLMn1Bm946ACFvA6eDLh4Ksppot4W7za2aZv99RSmXlp+psFDellLcGg+JSQX71I= 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=Gn2r9Z1o; arc=fail smtp.client-ip=40.107.21.71 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="Gn2r9Z1o" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gEEfZP6YRt292ER38JoR5047gIIPdRqJ5n1c4EBk3Sk45m7r1HvuuCclqxBVVFERefV6gCsnAIz3QCGDilyjfUiFmuqPkCwqNlCkuuv0P8nsrin2onUYwd+bVNjRIxWnJtwaBBXzlOaR3MC5ChGospo149R1GQ98f0Iv6Wjk3pwxjmJ2kuMhlBhQUNASSzWq5euyO44AGjwWN+O1Dm2ghRSFtkCPyatH4hFtCMMQttlGXHj0b6HYx+nlIfj1m7K8UoYFfHJqNy6rIloiBozmhnsI5qzHgTJdve0QaYlscJuL5rmJMUlIbswNJ0QvMRQuD3Jsh/gIVFRkXU3E5wAJmw== 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=+mzp2Bo8HWoNWJlsXVMdq+48BQWLo31kyjde7J1Sd90=; b=l5nLquMZ/L1Sr2XFNClL5TT63TFHP9Ogjci/HEDxSk1ZFojw7b9ucgwdNJ/VBXVpB3gvq7ayVH7NBhmicE5MwxTHauHg0oPMxmG+4BvO8dt6pvoHSF3hyTRD+mYvK8P5zdrNOYNoxom7uMc58oQN5QvuNoTugvPDIT+xy+VzjZSEijbL1EkKH7HCbQwBE59q6nX3vAQuR1q/Wn/STz9DQbncItx1RT6f/i0ZLTEyHog/qoA+mipezYv8FLXybOVYzjNDpLqqw30J0lBVJho2ADMwYdo9UwbWjuocjgTIQ+CxQyNMSOhOtHQtP3Z9VJmYDxyNs+rwOxaffC2pDgaKwA== 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=+mzp2Bo8HWoNWJlsXVMdq+48BQWLo31kyjde7J1Sd90=; b=Gn2r9Z1oOrSYoSNtnMQ0F1kjE5JEHjPWcDaMp7Sw+WsMRLsZrWcmcCG+RM3vzgER4SLZelVqos0FZT4UD3k0aISdYKOFJ3a66cODnQ0j1UG5TMK2AMP7+wnjdoU16zUvBcFkO4ZhxRfLz7V6l3+eNZqF7g/aPMVhZM226OLOJlMbPFR+IKpRSsH8jZTtlhOEy1tKIb1rx6CCQjKwMeUbPGpAvluNlsBvuUBE8838fLv1s4WZlc19h46o+bhRGVKsI+ZFyVlZCoHMfMurE0mj9R7WeaHtWFimPO4N7XwYCMVK3ezoqFGha1QQbxwN45owweKBlTeezwy+SeVAA2oEdQ== 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:43 +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:43 +0000 From: Frank Li Date: Wed, 18 Dec 2024 18:08:44 -0500 Subject: [PATCH v13 9/9] tools: PCI: Add 'B' option for test doorbell Message-Id: <20241218-ep-msi-v13-9-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=1734563339; l=1851; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=XbEugLgmvGxvNIdnJ6oC4l02fBY7NXWQcWS+O1eGi8g=; b=81AcSMGeFlxfUHquQMk7Fg7MeC1faazKrYD5j8kpN0H3MYmxZsXa70fmnVx9A7kvHwfdm4OsW TMLtqgFVYcBB1vz7Y03kl4pAs7ZepKqfVBPN9zKKSsUyzcBBPR+sAua 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: d4ada4fa-9cb3-4f1a-b49a-08dd1fb90ea2 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?W0FApkig5edrjnomyGjaBZqyendADio?= =?utf-8?q?7lq0tARUziazNhRBcq1HQ308zONHOTYexPBvvx0d6aRM5MAe/QTwss4bDOCyrbwjS?= =?utf-8?q?QKyWQ7BOtZBhlYsnMYR4GFagvcVf0Zh+N45FWd3LwNpft7LIhXteDXDQE/sn1QkdT?= =?utf-8?q?ker0tkTHO0U/65K6mYskYgi2Q442yxyT618iSOqQ2Vl7npwdmhyzSQ+d6YTwpVn+y?= =?utf-8?q?MZaQE7rh63BgRL2jbv6EANW/+yHbmu4Vm7ClhtlM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BDv5o+4TTMWphLZgBQlqYUKx?= =?utf-8?q?oAARv61Evu80/E4CvcktwBpHMdioF7sdPO9tluzh0Y90zLjwPlxIVdetJIs3shdmb?= =?utf-8?q?A2mUiNoSrwXaXw4Uh7sc8nWDTXHE0vbzGL27fgV0Wue3NOrjWSNmKq1Xp5SttAYZX?= =?utf-8?q?t/ZSb5JEdtgcFCkoPGG4KXpQ442l0YuahsFc8Kf4VqIWlxPCk9aeVMZv216oFz+5/?= =?utf-8?q?ZYpwCUK8Q6O3GxXXpwVrciwImtNwqHbvAIE7VmP56aGojCEkalxT9ndNc+VFKkaXD?= =?utf-8?q?50YNgQ2vTg9QPxq7YCrsHohO7GXAWgkzQ=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?SQ3l8lWo6GN0FSS0QMSDl3AEMTl2?= =?utf-8?q?ddf0Wb7MSf+gscmOK3DrO/Q9iuyXWKFOx2B+CfIgv6+Cw0zmD+bDiiCZEZ0Wf38Cf?= =?utf-8?q?+puVt9yCGWPx2pvKAjNA8E6cb8tGm/WeKtrUf4g0k5ZmyQdX8KFUbGTRbZ4ROdDKq?= =?utf-8?q?QcffyA5TgG6kTQCpi/cAYGZ487oAjf4ua/ycP2RviEwdA+Dy+hJDmXOs7AoWbvHIP?= =?utf-8?q?tgasOrVXOflpV7q4+GO3XLUjM/rRWII9F/GOJB+nTrGneRoG5mcu2OlDQkmsbiy/M?= =?utf-8?q?JWPo6ZYe/cUiWW0VRTeHNejMtJXjyWqvSDayn9oNdY1oI0swgk88p72kHH2eDDKLB?= =?utf-8?q?iDPvyhjt8dbv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WJEPtXyQp0L0TOZ44JVwQOumBVszgK3TOi8zmNUBohg0VcLsjmDzmT?= =?utf-8?q?pDbABUnFLiJ2pjfUd5bMqOX7kZcf3l5sfRjVYWLI0wSKj70HB3h9ZUGE5svqVgxJi?= =?utf-8?q?qxLcg17SD0FAVrgA76eJNArhVHMYMyFcLLekoMTApm7+iUccGQkdBnl3uDK/nhBru?= =?utf-8?q?+EM1/XJbe7Jv6meww7E7MK3t9HoLOauCWwPmdl53P+nfZeFbf8S/bDMmKjiB2rG+/?= =?utf-8?q?nJUaw0nEP6WxEQf3M0yNlpt5M2+kiFGwQ2tdjzLJSnl0tw78sXB+Zh9s=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d4ada4fa-9cb3-4f1a-b49a-08dd1fb90ea2 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:43.2164 (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: nJZTYQL2gyBaNYzeAj9nov/0qtEXJP8j+V9zwTdOc1zQOdmEDJAv6xcBHu/5kAwV4XwIGyqmf0UGDY2L01JSnw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9939 Add doorbell test support. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- Change from v3 to v13 - none --- tools/pci/pcitest.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/pci/pcitest.c b/tools/pci/pcitest.c index 7b530d838d408..fcff0224a3381 100644 --- a/tools/pci/pcitest.c +++ b/tools/pci/pcitest.c @@ -34,6 +34,7 @@ struct pci_test { bool copy; unsigned long size; bool use_dma; + bool doorbell; }; static int run_test(struct pci_test *test) @@ -147,6 +148,15 @@ static int run_test(struct pci_test *test) fprintf(stdout, "%s\n", result[ret]); } + if (test->doorbell) { + ret = ioctl(fd, PCITEST_DOORBELL, 0); + fprintf(stdout, "Ringing doorbell on the EP\t\t"); + if (ret < 0) + fprintf(stdout, "TEST FAILED\n"); + else + fprintf(stdout, "%s\n", result[ret]); + } + fflush(stdout); close(fd); return (ret < 0) ? ret : 1 - ret; /* return 0 if test succeeded */ @@ -172,7 +182,7 @@ int main(int argc, char **argv) /* set default endpoint device */ test->device = "/dev/pci-endpoint-test.0"; - while ((c = getopt(argc, argv, "D:b:m:x:i:deIlhrwcs:")) != EOF) + while ((c = getopt(argc, argv, "D:b:m:x:i:BdeIlhrwcs:")) != EOF) switch (c) { case 'D': test->device = optarg; @@ -222,6 +232,9 @@ int main(int argc, char **argv) case 'd': test->use_dma = true; continue; + case 'B': + test->doorbell = true; + continue; case 'h': default: usage: @@ -241,6 +254,7 @@ int main(int argc, char **argv) "\t-w Write buffer test\n" "\t-c Copy buffer test\n" "\t-s Size of buffer {default: 100KB}\n" + "\t-B Doorbell test\n" "\t-h Print this help message\n", argv[0]); return -EINVAL;