From patchwork Mon Dec 9 17:48:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13900149 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2072.outbound.protection.outlook.com [40.107.247.72]) (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 5642A13775E for ; Mon, 9 Dec 2024 17:48:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.247.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733766525; cv=fail; b=cw7A30cWnc2SafY+24DGz7Gj8QWrNYBkF0WvauXizofVM7L4c5r/mvoulUmxQODlooClqO7wURfL9GeRtGpdmbtOttsSWhJspcxcPraG+N1yixzpFJiEmjoaY2sYizZ1/DUuLLbMWs1am3LDjla7DcrJrJ8gFxYU4EE1TMN31ak= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733766525; c=relaxed/simple; bh=VihzRogf7h7/CuH6TuzIZ4wGG6MH7XOdaToVHZQlB8w=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=sQM5El3+Qi/qAAbfvaBr5OwQBx83l3D+Iaouo6Z/+RPKTLmA0aUsSAn9gz81s8McJzn1h2UFJhgydOPnIXSedz4WCskB2HYrnMb2hhRMvRYdrJYTPZlYfCBtEK09xyHu17Ixnte8c7QtjyRe7QbXBp0Mb8ab2d1BGlwZOzXKH04= 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=UmgqvOUa; arc=fail smtp.client-ip=40.107.247.72 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="UmgqvOUa" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=h6HWiYbyHfficjZwsDlUNsOtTbLWbBOcrADrmMlh3cXqY/CPRE3sTDQ8e/uLJkE70IxHqom9iRZSF+zy5wyF8irMX9S9w8aBlS55poOC9lkRNelYxz/Qip5KZVvSX7e7pJ/de1U5YAJugU+lu2TbRPzm4JSihZQC79DIQXtOojKONJjGlV/UmMexTIAHxT5z99BSSkTveV/qw25+F8QoaVbnAb3/WQuc+595I5XxQ7bDLsMG/oSSv2h9O5ldAG07bE7ca1v2mdlBZ3WzlDHVxierZNeyasqMNf7fr58GlqhM5/zMPlkJL20tcZPLzkMSeK8PrQXBboQ5G272eq5gqw== 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=NKqUQqst3YIBTuYRldvFw9Qzk/qMXPj/XmdMGedG9uc=; b=CgCli4Rj5VR10tVzicFhdQ2ftzlVIiTx6ErKvLSOQkf5N4c/YOQdmm6OruIbiITS8XUKInWvejWvZOyGnrJvgTo4BmTyc6EzsQoOZ771MMhv5nWVIH78+e15aGk9q56J3ey1mNlLR+Jsxoi6HIaMAAqiqXVjLYAeszptgD/Sfv4FqPVgCtotcFRb7G4sL3+D2KU1DpRMEUzSmeFJhx39cZMXcvekuitJonowJpT01mvWtvy81TrFMsKfGDZar6cQHGGy8U13KXCP5j4/8wyznRW5/3wf/oKFzQw/KyXJaMdmQk6v8DhIkKm1aHOjH/oFDau8SIA5XKHWYISAoWfzmQ== 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=NKqUQqst3YIBTuYRldvFw9Qzk/qMXPj/XmdMGedG9uc=; b=UmgqvOUafVTi8FgfmGUkgdxYihSEo8lXvasuGqb5sFqWeIsetLqFV0CSZrC90r7P84m/642GLuLyuGHX8qlRqIy19ozDFFPGB9Kvga5/Xfo6rvRvwYM7aujKFU2nAq4dyroMzE8z4fFwmkczPmON3eCj4F5iT3sFTElV9Te9G9Vs6SieyXYedbmII8PmQ0tRsKMWjFiQ8fIJjn1t+nhoVAVjFqm3d+8RyLn5obp+vHlyuzSHcKv5kH/mvCcnJ1BLc6ibdntHzTuIOFojK79IaJPMrCSPafXRY/X9VynL3Qok/+ffSsdF5kuVAD9+sTqETqfCMOUHdZIDgiKEQ9HZ6Q== 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 GVXPR04MB11017.eurprd04.prod.outlook.com (2603:10a6:150:21c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Mon, 9 Dec 2024 17:48:39 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.8230.010; Mon, 9 Dec 2024 17:48:39 +0000 From: Frank Li Date: Mon, 09 Dec 2024 12:48:14 -0500 Subject: [PATCH v11 1/7] irqchip/gic-v3-its: Avoid overwriting msi_prepare callback if provided by msi_domain_info Message-Id: <20241209-ep-msi-v11-1-7434fa8397bd@nxp.com> References: <20241209-ep-msi-v11-0-7434fa8397bd@nxp.com> In-Reply-To: <20241209-ep-msi-v11-0-7434fa8397bd@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=1733766511; l=2525; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=VihzRogf7h7/CuH6TuzIZ4wGG6MH7XOdaToVHZQlB8w=; b=P5ZtWrjInra1d8pJDhRjqJfZU1RWwu/QYItIAZRTfGUhD8GNPrTVSje3doJAwgcn12AdAo5du TomJEVUaSQyD1nGqy/NvaVxDxYSTsRLwdrOzzJiSX61jC0E36iGuwsf X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY5PR17CA0070.namprd17.prod.outlook.com (2603:10b6:a03:167::47) 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_|GVXPR04MB11017:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d4403ed-8879-4073-9f46-08dd1879b6ce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|366016|1800799024|7416014|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?QvBGBlnRfKhOkK+BSrKgwGvTWx4/7Bd?= =?utf-8?q?TYheZmiiMUuhPMC+gbRQpP6Xnurg9BrQYIs2jDR8L+x2K77FKRefgjCXTSXVnzVlg?= =?utf-8?q?nI3V95xkYJt64aV0Xgoex7wZnpCycrUykeL5uCSaJomUyCYj+8X8vfcHeHgWsSC+b?= =?utf-8?q?FZAMHzq51N2qxviqXUyl4vXn8JqY7L+2pD/0bpnFNNZVFD1g289UHRkBcKD9Ri2Uf?= =?utf-8?q?4F6nw9WAVi19GoZPDlZU8L2qE1tNzWbZQOlQZ1N8QKKEDdaX5xjlhGIJ/gXVtD4Jy?= =?utf-8?q?1eJdUY/g4LH54jzprpLi21zH3MzEL9Jdt17H/8ynLWgEE4pHm3OtZTw4si8XTXvxk?= =?utf-8?q?IP2wK7MutoEFQnRMDq2rk+GNg6UBpp77sTFSvB+EYXtHaahcAqDP2Rfyn+WphSmzK?= =?utf-8?q?uhF3YTCa/76QPwqZ32mPjeYxLeD5RvozGbAfCHjk5SH+Qz7NiMKnTSuf/c9yRJIdY?= =?utf-8?q?G2Ga7gm5FOefndR/LYxUeBgc7gvaAlk7Kah9nMUkE6/XOx2RNxamLbtFz2c2diLzr?= =?utf-8?q?TVLQFKwa/UW8RemKZnxCS6QRny58r+YwcQvPwzqYPpUZVEzHalpTBNuJ9B4ewohG3?= =?utf-8?q?+fyx6N1Ke/hcgHqJ3GGOmCrXrppgs/sLeEjlxR1GPcmTNUqEAtmGjLvvEr7ZyWm30?= =?utf-8?q?RB1cQd2a2+OZ0cSVB9M6Aseoxivk46X36iadXCHVGpVOcaaMGPbkHSu/b94Vl9r1J?= =?utf-8?q?VTElmke1xXazZsPIG1tM+cwq5S74lGIzE29xWH96P9Bji34ISGUoNsDLd5WS30imj?= =?utf-8?q?8fAh87x9x45Ikt/snoj9uwMFQqIlre4UBJhuxbESJcu+N8ovDxQFC1Q93qI0N59hZ?= =?utf-8?q?CBEKz0BH+e2JshSUNJPdiCzP6D3moolqzbHg9XI7NP5sf0WjQ7nzNOjSbIVFkZRAB?= =?utf-8?q?vSLQO+Gjx5nrb2Nz5IIxGA4qQ1LO18tPll1bu8BJUK+81cP3I6woi3tnzCs7jtAG+?= =?utf-8?q?U/4787QA5XiaBZ9yTLBQuse3K5CHi2vsOdoJ8RCwBaZ1G10cKoZ55YihJWfFZVu6Q?= =?utf-8?q?mRe7sDU4OYypG30WYLqlGiKzBRm+STi42ymB47IGUVKYfPvZt89LZnK5KeGhfSqit?= =?utf-8?q?YorgAifLY+Ut8JN1XidMANfxGnDfXlcMZzXhPE3ov+OqLoa4QV2if+sjadX9cFwkb?= =?utf-8?q?RbaDsCld9DvbwdiVHIZ0357rTI0ADDgrEH0iuhfLPbDFSzzfNe7H65fi4a0Law4KP?= =?utf-8?q?IdLuBSdt+ZZhih1KJ1Wzfm/zFBium0Ymuis1JzlLh35rwDl9l9toom1en7GpEsj+r?= =?utf-8?q?MJhnI57zY4/v9rGlj7Z+PL7chxDApUuDuWl8FubdULdc0z0Tq1nIvTf1wVbBVcOm5?= =?utf-8?q?rd2EQ+EqkVQgpCgyZyRK8C5FoMoFDYUFtqgaGuhLt6B5H8ZBrfoPVXQ=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)(52116014)(376014)(366016)(1800799024)(7416014)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?xk5xjTHp1CgeAWZHJpMErbrnhMUd?= =?utf-8?q?cnhMRfqnvtHj4W0gFv+vdJ/MCfwLgCEev1oanoiZa001nkO8/gD09iO9cH0evm/qV?= =?utf-8?q?wIA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mzqFxQ2stg8QNFMvT9Ccnh+m5Y22HoLEa+Ql+i9zhynSVw46YYEIvtQraOxJ?= =?utf-8?q?PP4K1LbpsappYHBAUVvqo3G1scE+WVQHM94Q1eolU6z21CemNysYsP6TFF/DnRP9N?= =?utf-8?q?NRNRs8TxUcxzxGabLFsupq6g2UpSDOKfjH6/0/V5GE4suNcHQkRawB87t9Jpo6B4m?= =?utf-8?q?LaMV8CcxK+4/7IcynOcsuhbIP75Rf8g7IftqsCXPH+IMxTgm0wBOp8wYERCJmHYED?= =?utf-8?q?Nta6o38tz7AA8FjvROaB1JOK+XvOzbdIcQSUZSKD8mfFmcdxlMuAo4KXe33gmgz3e?= =?utf-8?q?DZBaL1+4RZM1CLMF445skrCMeKgDrjiaMP+JGmEXjYvsCfS+SAic1gvSa8X/iEM7A?= =?utf-8?q?cfHe3R6+ZJVwJL0zUmNqkvyFbB7b16p2Bi8hLfm0jtSmrw01qJb0a4kuylh7G+MYq?= =?utf-8?q?428xSLSIPffSpmvygdSTuwd7h3HePlhYzLi2w1ofnkf1QsDLZxOsZxUc+Tenc5HqY?= =?utf-8?q?eaJkkU7SvbGn5B5+Pn/QqHFcDZJ5msmIvWvgjtO4A+df0lFz/JJJqVew=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d4403ed-8879-4073-9f46-08dd1879b6ce X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 17:48:39.4774 (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: YTQfo+4V16oPhc6LJUBGg+6l/1tiFS1ul5l4tkdYUQGJI5Xng4eWM2fF2gRMK6VyDjGEpLzJi0UobGRq0ZpAVA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB11017 ┌───────────────────────────────┐ ┌───────┐ │ │ │ │ │ PCI Endpoint Controller (1) ├───►│ ITS │ │ │ │ │ └───────────────────────────────┘ └───────┘ ▲ ▲ │ │ ┌───┴──┐ ┌──┴───┐ │ │ │ │ │Func1 │ │Func2 │ │ (2) │ │ │ └──────┘ └──────┘ ▲ ▲ │ │ └─────────┴─────────────── PCIe Bus (1) is platform device, which is generally descripted by Device Tree(DT). (2) Func1 and Func2 is created by configfs The current platform MSI API supports only a single device. For instance, a platform device (e.g., PCI Endpoint Controller) calls platform_device_msi_init_and_alloc_irqs() to allocate MSI IRQs. Child devices (e.g., function devices created by configfs) require individual MSI domains, with the same MSI parent domain as the parent device. These individual domains need specialized msi_prepare callbacks to set msi_alloc_info_t. However, the current ITS implementation overwrites the msi_prepare callback with its_pmsi_prepare(). Modify the implementation to assign its_pmsi_prepare() only if msi_domain_info::msi_prepare is NULL, allowing customized callbacks where needed. Signed-off-by: Frank Li --- Change from v9 to v11 - new patch --- drivers/irqchip/irq-gic-v3-its-msi-parent.c | 3 ++- 1 file changed, 2 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 75aa0d4bd1346..33e94cfc4d506 100644 --- a/drivers/irqchip/irq-gic-v3-its-msi-parent.c +++ b/drivers/irqchip/irq-gic-v3-its-msi-parent.c @@ -195,7 +195,8 @@ static bool its_init_dev_msi_info(struct device *dev, struct irq_domain *domain, * FIXME: See the above PCI prepare comment. The domain * size is also known at domain creation time. */ - info->ops->msi_prepare = its_pmsi_prepare; + if (!info->ops->msi_prepare) + info->ops->msi_prepare = its_pmsi_prepare; break; default: /* Confused. How did the lib return true? */ From patchwork Mon Dec 9 17:48:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13900150 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2072.outbound.protection.outlook.com [40.107.247.72]) (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 98ED01B0433 for ; Mon, 9 Dec 2024 17:48:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.247.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733766528; cv=fail; b=DesRXiBKCEJ5mk20sb5hWdazPv/ncSLeiPXiYmUZlN7TTm7F3bXvm5MY4WpeClRW5tRYpxKG1N1W1ijHZ8NoAPoJPwoMSWMraOqUIgUp/OApMzIPZn1PdOsMwKr+b+uWvFzx6JzmsNSeCq393JMC+bvASAjmmUlNvcJoXfJFMnw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733766528; c=relaxed/simple; bh=QttR5tH/yvKIxFiJ4f9buzL9F0LcYD3wXvxdYIIaHrM=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=lRSpJ13Fg/rJqqh31KQS5PBcB5bgd6TasP7Xo/PDPlcjbtFN0R9RKLDBZ40YF5b34cDuUIRCU/RoxEOc30juB+n6jHGkTn7ewWqaFCrC6/NuD9qwzvlk51FTTpKdWNmxT5HDQSxVcqnoZJdwtOcyWzgYHSOslK2jVm2qGTw7b0k= 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=JVFmfs07; arc=fail smtp.client-ip=40.107.247.72 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="JVFmfs07" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ycpmUZwTqdBNHp5R3+KFzu6RBvip78v39sK3aTrGnsEQsJBqrBKh1hnMS1jR2xZLPjlB5KbRnMx3VSMnY7HfgnElLP22ZlGPMfF3TbfpfXdlvpju4HYR+IPiTYpqZdO/5ics4WE4goG1ECCyzQ2DrWsWl92GPBDRheYG5GDlRS//9Hrji4l/NAOzXvrlooRvegCYJBB5XHLI6LMBWkPzyfDFWPJXbmNExP0xbagxWu4HbI57jKnvj0u64p1rL34kdHBXGqTXWBRVbrO8iXHJ8dMMG6vq5wnO0N/YysEIq7BLRWRCKfBkTfBiinsxeRnn5upFpW5i3LVxt22HPzq5fg== 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=UwHmvm7ybUkTgCCj+32HWwVthgCGdLhI52uVsPchYtM=; b=TZ2vDupAjLXGgBhoHmhUzH/iid3ZMy7DPCQSQAGhCkebZHSO3wLJFr0BF4Uou1ee1A9aCdCtzo0aT+WF1fZDsKna+S+8OEwLgdfetpYiovnpBLNoS1F8nlXJNrMwkPUOUmmSegkCdtcuFwldXViKhAVPJHTLwVvxDiJ2st69zZAfLuwE1pSo0YRr+TdlWkeOyYuEfLnrH/dyJFuLH/VmJBTKhLwhRHjNGF2uoQgtfBSTIoF0xkWwtgevmh3eatgN4EZfgsGv+AIexH4YXP2/bqpfWfL8pbuOFGyZIUm3hz6DHaqFDtPMHBwrUODpVZvOp9B0Ciqppzt2TmjwLlXh7w== 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=UwHmvm7ybUkTgCCj+32HWwVthgCGdLhI52uVsPchYtM=; b=JVFmfs07SKDNw9nqPc6s/1Ji+eKU5G7ZwsQ+dyFIBgtloqh9ejncCqw/V0trxL9zxygj0U6PCehl7O6YzZ71FbME849BFlFd88V8KVj8ah1xWt6EKNNtIXPKue2IvDWYnl/Gnwin6xkDssVR9+FEdc6OCE9MQf0CieXocCNLp+eZB7nH3mMs2Chc5KQGIVEQ82w9tDGQyZTE4vZlmjvMtcpYz4HTwbMohuwgflRF8HEbXTqCMc6OBLe48yHbKn39B6cGKgwYmLutF0C2cQg++X8PK6jGZo3+/RlhzKyr6cC0h/ZQzTKwMdYUtIENfXKYbbhhNxgmXCL1I6j4nNX06Q== 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 GVXPR04MB11017.eurprd04.prod.outlook.com (2603:10a6:150:21c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Mon, 9 Dec 2024 17:48: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.8230.010; Mon, 9 Dec 2024 17:48:43 +0000 From: Frank Li Date: Mon, 09 Dec 2024 12:48:15 -0500 Subject: [PATCH v11 2/7] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Message-Id: <20241209-ep-msi-v11-2-7434fa8397bd@nxp.com> References: <20241209-ep-msi-v11-0-7434fa8397bd@nxp.com> In-Reply-To: <20241209-ep-msi-v11-0-7434fa8397bd@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=1733766511; l=8536; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=QttR5tH/yvKIxFiJ4f9buzL9F0LcYD3wXvxdYIIaHrM=; b=7JKPSA1DEScfwnrV95WQ0KgzMFedzlQq2s54m24Nwy+x/CRqDwuydiwWUU9VdnffkeFr+42Gd ojL6PJKeXkWAZwwatU1PqgbcZACRdS2pDta/y7E3oFBDE450jmsaN5F X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY5PR17CA0070.namprd17.prod.outlook.com (2603:10b6:a03:167::47) 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_|GVXPR04MB11017:EE_ X-MS-Office365-Filtering-Correlation-Id: c0dda56a-a96c-4e7e-abe0-08dd1879b957 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|366016|1800799024|7416014|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf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QDPx4YnYmNPHBYu0PYNIvqetHIOmdtP?= =?utf-8?q?YDT2P/AguTrulpQMPA/IYXsXr3v/zdTXmU1cpyDhSzHrhdPj4hgHlDXosS4TrwKjA?= =?utf-8?q?ZDsFJHzsJlwPyGQooPUnHwlhv91WTpQE5SEnzFmOa/iwZkMKbyoGkqqoe9XXSbdi6?= =?utf-8?q?gT0amzHHjOqXX4b71a8mj7nLu1b/OJE1kQeOxjNnvH458WCreQ4vNwvZxu+tq/hiA?= =?utf-8?q?6ueoCWgp2ogib6BwPP+BJ/Xg7wphNPyZbdWJiBku08EGiCWDydjwcADd83DxpLPnS?= =?utf-8?q?Q4VCxTG9s9EsFfU9J8oKLmyH71ERyeudGxXgROgA8dgHShmARBhAOTxvZIHh1Pfwi?= =?utf-8?q?2oapiT/mo7/0np5T3YGl7czFOpGa+pomIa6XCpW5bfBfP8d6exy4vXdAVY7TaomO8?= =?utf-8?q?SOQ4XQTomL2+6wru/tV4HWeHWX00W9jayBXsY3qsnaswEtkAvtk7StuaTsZeDLBy2?= =?utf-8?q?7/5a83lTbqZmXkYM7XZKtt8wwsZdjwe7H3dMsJE2fynQhUqZWuF/7rc=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)(52116014)(376014)(366016)(1800799024)(7416014)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?XUqYU5ONJmmf+/Dm2hYqxZVhNcDc?= =?utf-8?q?ScWiiXX9qywEXXwwjniAAuW4xWneEup39EXdJTcR/HCXYZIj3ULyAal/nNibVG1cG?= =?utf-8?q?gqBKJpALC67IhYoXp0yVF+CJ2vnakKpmsWPn73+67YE4i6O10gULSV11bQVSbpoP4?= =?utf-8?q?R2ZBg4sqAh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d8W9vLHJFa0jnqXKeQsFz+WJgboIrIqmeHW2NaSMfxZBHKe3LQl?= =?utf-8?q?t1n4Ld6OUWSC63JpPUzeyigF+o+ntMFo2Wgsdqtfo+m/pRXNO5Yr3YufW6A+d4hGj?= =?utf-8?q?pUOAB9SLzBmPj03dPS0yerFiQlCvB4ORsaKdgg9VMRP0/dofvTt0rIBzGEi30wC3H?= =?utf-8?q?BLRUkjPhotDYRLF02YqtkbqwD4dWtPNES/3tz/zKZJfF10LoYttdRVLdD5rsBO9ht?= =?utf-8?q?qpEZQZPGdcRUItoHPawWCqRrnyF9BqOdPfbzuOhuCa1V9POoMxiPqMhV1/HSiKgKy?= =?utf-8?q?suxN/buoZYtUk1K8OKG9cpWxS2OXYV5uefXQofIq9NbI0Q1ac/nUx3RnMxnfneOuh?= =?utf-8?q?+E0fE0VhxIZUeHbnvLWqmwWskvMGiIB1o5FmcfyIPq7lZsG+KXU3FGcV+e2OWzmBb?= =?utf-8?q?Dz/l2Z3vyzJlvElRgDoltSlNId29cWzjYgqWNxzLYqIdJDx1zXK6osyw=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c0dda56a-a96c-4e7e-abe0-08dd1879b957 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 17:48:43.7186 (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: X93YkVX90uW1UmiIE+8+TnXlfZ83/Jw64wSoNmuYesAYlnrhM1iU+aylGU18zZY7geTk3BJrD6zt6fvAfLwE3g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB11017 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 v10 to v11 - 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/Makefile | 2 +- drivers/pci/endpoint/pci-ep-msi.c | 148 ++++++++++++++++++++++++++++++++++++++ include/linux/pci-ep-msi.h | 15 ++++ include/linux/pci-epf.h | 16 +++++ 4 files changed, 180 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..b0a91fde202f3 --- /dev/null +++ b/drivers/pci/endpoint/pci-ep-msi.c @@ -0,0 +1,148 @@ +// 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 + +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 int pci_epf_msi_prepare(struct irq_domain *domain, struct device *dev, + int nvec, msi_alloc_info_t *arg) +{ + struct pci_epf *epf = to_pci_epf(dev); + struct msi_domain_info *msi_info; + struct pci_epc *epc = epf->epc; + + memset(arg, 0, sizeof(*arg)); + arg->scratchpad[0].ul = of_msi_map_id(epc->dev.parent, NULL, + (epf->func_no << 8) | epf->vfunc_no); + + /* + * @domain->msi_domain_info->hwsize contains the size of the device + * domain, but vector allocation happens one by one. + */ + msi_info = msi_get_domain_info(domain); + if (msi_info->hwsize > nvec) + nvec = msi_info->hwsize; + + /* Allocate at least 32 MSIs, and always as a power of 2 */ + nvec = max_t(int, 32, roundup_pow_of_two(nvec)); + + msi_info = msi_get_domain_info(domain->parent); + return msi_info->ops->msi_prepare(domain->parent, dev, nvec, arg); +} + +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 = { + .msi_prepare = pci_epf_msi_prepare, + .set_desc = pci_epf_msi_set_desc, + }, + + .info = { + .bus_token = DOMAIN_BUS_DEVICE_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 << 8) | epf->vfunc_no; + dom = of_msi_map_get_device_domain(epc->dev.parent, rid, DOMAIN_BUS_PLATFORM_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 new file mode 100644 index 0000000000000..f0cfecf491199 --- /dev/null +++ b/include/linux/pci-ep-msi.h @@ -0,0 +1,15 @@ +/* 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__ + +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 Mon Dec 9 17:48:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13900151 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2085.outbound.protection.outlook.com [40.107.247.85]) (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 14B751C5CD6 for ; Mon, 9 Dec 2024 17:48:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.247.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733766533; cv=fail; b=RoFeiqF1E7BnfNU5tRqygwMBzy8Hn+lG3P14VARLeNR3pchsxOl82RawBXPhocwMNwcG7VrSr1kcE86IF0SNCLq0osdrr0KYJFNJLodvMw2/9dQXyrdujA30hHH9c/hCAISfuIWLNBSmoQyAJfmwIQ+ZWvA7+e3Y0FKUZ2SflV4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733766533; c=relaxed/simple; bh=PgF8iXUfL14mEGYw4rl2HUwUv7bZbYuVrZCh/TdXXi0=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=lEgGZ4KJWOtnEf10QIJsnXzHCurkJ31tAZ60iU9q+6WmZymgINiw2aX+cI8pXaPySABKAPhXNaPliU4VheUGukWCf7OKYxNBoeMWA6uHO+NmLazDwJ3Q9qeNvI7AhyYwDUXVNq/5hrHVmmpoJV9N1mqwFiFZ/4eZVInKc8xKQww= 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=HsiGkUGo; arc=fail smtp.client-ip=40.107.247.85 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="HsiGkUGo" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JUE0ywnMedM9XhwZANz6RIp554NCm09v2feUmLrdsTvz/ISHXCXZJO3qaXqdUdCpyzQaeC5qMBVnBuFtPezG3CiPnuDL8UnozfTSbFmKi85b3NknUI5K3/Tt3wiuqTgWFy20rxCMGFW2ngGXiRe5fXG/kcMyknLB/vou3vvu2eHGss479z4F5fHp3tk/ZP667otdUCySAfSPnPPMOmXTmijHqetO8UWmGDVNavnns3s/bUhPbhnp5Lm0jfHfeF0efmVSIQWU+h3Axzif1BaZXETSs8UuPf5UtO8A6XMNWnnnl/SOQLOzB2j3po/kTaD5dq4fYyWbgrO5mKQeMZvayA== 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=mx8CH+EoHbmFyezPK355CdtDc8U5uUJoKs7Xm1ppR/E=; b=nlIbmBw4QIDr/NZaXxws3nSPvzZBJmjtGIhQObflUMlalPVjKUQ5ieMDa2mp0ckwmkOExODVGevkloJqpJipM33LMRASGsJERg8qvVeodw2wtIJZrKC9dzfUeDtirjvjK7RaZ5rytFT+NbUdTxXkaSgXGoXhon42GfvCswRatQ6OMH0IpNmJsXRjzF5PU9OXzzhPq+X/A5ys2F/kiPmltydQrLwaY3rzwuYc0hFv0P6E6LqfimcL0a+vBVNXMJMUZRHoutMHaeRYtAmprnPYQT4teNHxWaUUJ0KpN/pG13dtClxshl0WjaIJ3NLVkkvjNzFUN7ku5TXnLZOHRBQm4g== 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=mx8CH+EoHbmFyezPK355CdtDc8U5uUJoKs7Xm1ppR/E=; b=HsiGkUGoM+BegwZi5C2yUvUtnMKPzL2L+FJhZ1YMnWmJOSvczM++SiX7ATeN+CXtqef7zsgaw+NXX74oxeSEAd2RbpyAEUE5CBZjFGozyeTlKA2v6SWYZNx4bDwbyblrdCp5tHkvgcNFfcMSC/l7hqxbhcyVyxUeeGsuDUURYgO6HfRh3OMq8v1dK3iiG2wm7tzuxibrBNjhmjZI6p+fVucVpcMmbUVpzbNm9ybVcVmgDU5xMHhi8NIb7OaD6r3RHJjNkInH6toFplm5UFiw17bORN7zvrfLcnHVH79rv7D0WSDzfiIreOsWzXiPScD7tdOO1QEWCL2jvGGLpDNM2g== 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 GVXPR04MB11017.eurprd04.prod.outlook.com (2603:10a6:150:21c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Mon, 9 Dec 2024 17:48:48 +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.8230.010; Mon, 9 Dec 2024 17:48:48 +0000 From: Frank Li Date: Mon, 09 Dec 2024 12:48:16 -0500 Subject: [PATCH v11 3/7] PCI: endpoint: pci-ep-msi: Add MSI address/data pair mutable check Message-Id: <20241209-ep-msi-v11-3-7434fa8397bd@nxp.com> References: <20241209-ep-msi-v11-0-7434fa8397bd@nxp.com> In-Reply-To: <20241209-ep-msi-v11-0-7434fa8397bd@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=1733766511; l=2150; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=PgF8iXUfL14mEGYw4rl2HUwUv7bZbYuVrZCh/TdXXi0=; b=qGaobY/De0ThtjW3FuLJDy16y88UAzIa6rABWSn8fvT+DldmtXWM8xEM8g43FYYmWlrRS0HKp fETRrwaJJUkCUBsB06yHVNCYZoYbO8iSTsQhEJw6WJQxkHMImpOhDDK X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY5PR17CA0070.namprd17.prod.outlook.com (2603:10b6:a03:167::47) 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_|GVXPR04MB11017:EE_ X-MS-Office365-Filtering-Correlation-Id: 7e4d280e-3d1f-45fd-42da-08dd1879bbdf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|366016|1800799024|7416014|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?pmj+yNlFCPztNLP5rl4syRsM8Y+iUpU?= =?utf-8?q?2lX+Cu2Z330Sh3XzZVTjvA5G4wVAXUgmB7Il+TKlMJY46kKGCxtyWn/HE1CcXwuiF?= =?utf-8?q?w4Hqre9y1yMHXY23JG7lf/VcPBkHyo6uJAv2Zwzx4pgCoQ5iAT15UBmwea9P5QbRM?= =?ut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?kMCIfuTGbJJO9uT846CSwvxmBBxXv/7jFrNyHFvnR1s1Vada+xDUJeIT+FiA0V4AU?= =?utf-8?q?JL4jZle0NLczsAGsOHbUQnZXUggxOOj3Q8EnLgNE66NF7NoSWSxQkfUAFhtvWV+Uu?= =?utf-8?q?WFi3Psr9/GTVfvVuvGKvblNHTytG6B2R8CRgDnxRirq38ITHnSL5+XNIC2eh4lHFk?= =?utf-8?q?dc/D/r8C8D8zxrIFiwUn2WlrrXuU1a58A3OraqCjfClTDyYmdrncPefVizZn8vm/1?= =?utf-8?q?jryvdeLWSDRdAdSQLoCoOQa4fOrGcbS3DMkNbBR80vNbF5g69jqVMXS85sqtl5QeT?= =?utf-8?q?a6iaHkPlUIjAYD+1S8VciNeBSH36U49JrwpydQbeJaEXFDqR9C5CET4=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)(52116014)(376014)(366016)(1800799024)(7416014)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?w5inkS0r9/H0bf/ppmMuRCZg1lj9?= =?utf-8?q?cZS4hck2vOHSyw5eUN/wffJIR+0N1WNKG6Q8iEiFrO2jYBuEhcmL0xlwm7eE88V0M?= =?utf-8?q?Av8qxL/NcS5njE9UvhzMKfowPoc7gT124n7ALlyoaRyLxhIAU2p5U4opNLp+JnB2s?= =?utf-8?q?UyxadHUSi+1rCwYyKbOdmR+UCfXGgQ1hDS1ptvR202gFN3PRGFn4I44pO82vkhe6A?= =?utf-8?q?rtu1qgHc95IAdp+0BUlpwXe5p04xGbKmCVTmrlBzlNSa76yM01EOxcQKEwvz//PUW?= =?utf-8?q?H6lSA/uSVwK32pYRZL2qlYBgXu3xluGYkpanEGasVMNSxeuzGVcaa2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Sne1?= =?utf-8?q?d8pGQSSHjkE9sCQzLbpp869oCP10RicPvxI1S+wd6bmUavXXxPuhAUTwymqHbJKIg?= =?utf-8?q?yB6Drg1KygPuGQ5TRpjCpMo0U0Mbqygt/gDX6fk6HeAuLZw26JjQ8x3ao4Dpf7NK3?= =?utf-8?q?sVsbpwzbbuxqTkAaoO8R+1kTFen3K5c4a9gGMnFJd6UJ+8sYyUu8BZ2ccB1eMQcNW?= =?utf-8?q?Jnjm4QKq8rzc0NhQ8WFC109PgFL8FhFfL5RVmD8GeEZESw/qr8LuSe4ghJNFC4VXm?= =?utf-8?q?AANjsyId5EsWsNEPsVdQBu7M0LIOpSEDB5lJC3xG7LeL7UXTwo7XtvVs=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7e4d280e-3d1f-45fd-42da-08dd1879bbdf X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 17:48:47.9766 (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: dpVDYNBgyfJbm7mBVvJcf1YDxhd9ptxFS5ditAwlEuWnC/ZCNXsTdNkILVeGK2v7hcaNs1DyHpM6/sOvp4RypA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB11017 Some MSI controller change address/data pair when irq_set_affinity(). Current PCI endpoint can't support this type MSI controller. So add flag MSI_FLAG_MSG_IMMUTABLE in include/linux/msi.h, set this flags in ARM GIC ITS MSI controller and check it when allocate doorbell. Signed-off-by: Frank Li --- Change from v9 to v11 - new patch --- drivers/irqchip/irq-gic-v3-its-msi-parent.c | 1 + drivers/pci/endpoint/pci-ep-msi.c | 8 ++++++++ include/linux/msi.h | 2 ++ 3 files changed, 11 insertions(+) diff --git a/drivers/irqchip/irq-gic-v3-its-msi-parent.c b/drivers/irqchip/irq-gic-v3-its-msi-parent.c index 33e94cfc4d506..a34e9bf93f991 100644 --- a/drivers/irqchip/irq-gic-v3-its-msi-parent.c +++ b/drivers/irqchip/irq-gic-v3-its-msi-parent.c @@ -16,6 +16,7 @@ #define ITS_MSI_FLAGS_SUPPORTED (MSI_GENERIC_FLAGS_MASK | \ MSI_FLAG_PCI_MSIX | \ + MSI_FLAG_MSG_IMMUTABLE | \ MSI_FLAG_MULTI_PCI_MSI) #ifdef CONFIG_PCI_MSI diff --git a/drivers/pci/endpoint/pci-ep-msi.c b/drivers/pci/endpoint/pci-ep-msi.c index b0a91fde202f3..1c157e0a81456 100644 --- a/drivers/pci/endpoint/pci-ep-msi.c +++ b/drivers/pci/endpoint/pci-ep-msi.c @@ -107,6 +107,14 @@ int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 num_db) return -EINVAL; } + if (!dom->msi_parent_ops) + return -EINVAL; + + if (!(dom->msi_parent_ops->supported_flags & MSI_FLAG_MSG_IMMUTABLE)) { + dev_err(dev, "Can't support mutable address/data pair MSI controller\n"); + return -EINVAL; + } + dev_set_msi_domain(dev, dom); msg = kcalloc(num_db, sizeof(struct pci_epf_doorbell_msg), GFP_KERNEL); diff --git a/include/linux/msi.h b/include/linux/msi.h index b10093c4d00ea..d95d979e4747a 100644 --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -556,6 +556,8 @@ enum { MSI_FLAG_PCI_MSIX_ALLOC_DYN = (1 << 20), /* PCI MSIs cannot be steered separately to CPU cores */ MSI_FLAG_NO_AFFINITY = (1 << 21), + /* Address and data pair is mutable when irq_set_affinity() */ + MSI_FLAG_MSG_IMMUTABLE = (1 << 22), }; /** From patchwork Mon Dec 9 17:48:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13900152 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2085.outbound.protection.outlook.com [40.107.247.85]) (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 53D151C5CD6 for ; Mon, 9 Dec 2024 17:48:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.247.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733766535; cv=fail; b=jy3AaE2/jXnsyEpFN0er0CUIMGHrt/fERvSlKPiu6b1NxjXbJueSP45AXGe3714TxI2xXDmfLTklcscKMXt2hnSTwsrJkP4j0EcSZCNfUJfAKF7+f5+HygXi6AtegsF4y921T+GHZCjmhQEaBpytJN8iOUUduHpgpNL7NIwieJE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733766535; c=relaxed/simple; bh=3ddx5i2vZgkRmKAKHbO1+MH+deLur5mXWHjfPbO8T5c=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=awXExIY2zb8pOZMGXrAAMHqnoKMOjrpERHOZIPat/iJ27ls4eRQxc9fe/Ia+d0MqpWteFaBAu0i3BMWjmM2iYTJ6IDGx8848WgrgBRDR126PM2gpSW/c5U5fhmI1X3UZ28gpfDrA9YM0xJ+mPULmi7cDICiKrcSthfd+VDj31yo= 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=ihcBrur0; arc=fail smtp.client-ip=40.107.247.85 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="ihcBrur0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bGMdOGQh3QVAzHZyob+Pd8sv99go5CeZJd97QtEwtX/ByZuHJOvgam44OHmKcATl/O+ep2OuSlevdkrxXLQPfrULFl2NJHMOaSS0Cr+HSjVLYtdnIeJKVQH4TVXkl/Gne3nlgx/2CUCV3C+H26sVC5mz+y0k7bJixIP3tw2CiPofvQ5AYE+E32fPwRzAcIOTQ7Lq7VrlOaixxP7XJVUNj0+MS6jNXyOh1Wv7V1jkPdH3wslJLPjxJQkP+AJQSz/adBDWVbyhp6pTQpnHBy+caLJKwgGSKBydNoMhA6n5LdPuhrm1zU8V2eMe4q1V/BSqehv2ZI9ZsRF+UrtGx68yzg== 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=oszU2qojRF6w8uj4Xk3VbRlVoS3ouEiYM+63L8FZlXI=; b=cIzrAoJZ9/Y4h8E7qXWQDtLxHUXU5r0FjvngYtRpddwjwn3zkN4VKPiyg1J7pWEZL5UgfvRkZhmFgYEd+scoChgz2pc29mpYtkRBohOXD08KUaFG1S3BVGBebhHn25NjXE9gAd4yObrBH5GH6hOElZ6plQ1U2cosORmzrEwWUVAXsPFhX0+KS3M3d2EtAlYT7qhpCdIVfaaI64Z45oj6iQe8mcnVTSxpogs7Y1Gsv9CwKOsDSNzpmHoJOfeQPgpALjNEShq0IIAvgYZlpCRgStr6Nhll1kqgY/NqOyP/IJcT7kEdxBxK/epPe4HWpaLTDk6Nob+9zMTHrR0deFJejg== 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=oszU2qojRF6w8uj4Xk3VbRlVoS3ouEiYM+63L8FZlXI=; b=ihcBrur0Elz0h9YVqXoYt9DBdJ+r7Qv4TwkeVw4R4MUg/CvaA2QPiL8JqXVO1v6OMWzGTKF2WJV7J3VFDpY6/EJNyJOCJ+O3AT/YvZJQXMHfLOLhd7reRLVddokrK+8oHIwkx81gEMaoDAGsS2L4D5bwlmLlaIkwRGW/1Li90mGE8H9RqhpsMj2Maim0e/u8kowEKc4aSYHCif6/T/T8SuATyaC6vcoOT7tCS1M144jLYFbCRYlUxsErO+8WE6lv2AuXVchvUZnJqSZilVoJrAHzKH3qyrzjRCiAJgQ9KK1HDP22tmipetGYeJoC6QzGqzYXwIhAvRtOf7Jnl0qUZw== 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 GVXPR04MB11017.eurprd04.prod.outlook.com (2603:10a6:150:21c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Mon, 9 Dec 2024 17:48:52 +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.8230.010; Mon, 9 Dec 2024 17:48:52 +0000 From: Frank Li Date: Mon, 09 Dec 2024 12:48:17 -0500 Subject: [PATCH v11 4/7] PCI: endpoint: Add pci_epf_align_inbound_addr() helper for address alignment Message-Id: <20241209-ep-msi-v11-4-7434fa8397bd@nxp.com> References: <20241209-ep-msi-v11-0-7434fa8397bd@nxp.com> In-Reply-To: <20241209-ep-msi-v11-0-7434fa8397bd@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=1733766511; l=3395; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=3ddx5i2vZgkRmKAKHbO1+MH+deLur5mXWHjfPbO8T5c=; b=tPnkfLpbDfNGLxvDO7/ZFgSOGa8rVpKvB23zBdMz+eSYMSp7n7eemg5kEhPD+dtgDdCiAhIET MWuKIl778elCnLROlEm7vDF1f87MX9kDeORbql3et85CqncE7vLePsR X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY5PR17CA0070.namprd17.prod.outlook.com (2603:10b6:a03:167::47) 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_|GVXPR04MB11017:EE_ X-MS-Office365-Filtering-Correlation-Id: d2097a4b-1a1c-416d-80b2-08dd1879be67 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|366016|1800799024|7416014|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?NoRGP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5A+M+zAwFISKtoYx4nq?= =?utf-8?q?STNnS+IvxtYzSIATk3IajFUFyBxR6ezpvg88jyF5hbJCSzfNHNb25w+PrfpVCZER/?= =?utf-8?q?XQ+oFfIAYq5fbDp9meXzPzWaHRnnj9CMLMX/aH9Fm+A9iYpSN154MwCe9TL//4OcQ?= =?utf-8?q?KcMtD0SacChv92Ep6Ak2kS/VbcqjHzFzSj/Yxyh8Ni/hc6Sopx3hf4geqsw5QHdWi?= =?utf-8?q?rH+vYGqEpN3XZ24RW2qL1Bv6gZj7/NHqBxk318K3LofN+L9yxpbrNQ0vIO683rgJ0?= =?utf-8?q?+78E1bO3CLbNPacxjhnz9EML87EnQGsqXu601Ambk+7H5OKh7ODiN1fI19IDkMxr7?= =?utf-8?q?kt+G08ovMgUnxqpHiyydoWLnDb7/xZeoqotWdt3Fbv9EH5VrNEod6wCn5X2c8qS5N?= =?utf-8?q?cqF0dsbV6lrg9IPlHJPtbDcmhAmtI/YOoCp91diCC6J7J7HvlDM0VaVmq5Y7zdFK2?= =?utf-8?q?LbOWx+PcmSFXgt4GOQ9dC3QqGy83y0p9TusMR33HLHgX618trhOOxEw=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)(52116014)(376014)(366016)(1800799024)(7416014)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?gSgjtQtwUGBNlA3Fzhs3jvsFN+3W?= =?utf-8?q?vqDsp/X67UfNQKTq34Nl/qi6DYEOoyFRw6YPLz9LgOaHcErpvNARsLKNgeh681ntv?= =?utf-8?q?IbJV28sdAvtNgD84BHtNCxL/HlKVgQM1sy/UVIO4UVA0fqEO3/rzJ5jsa8mhP45Uq?= =?utf-8?q?ISrMWGHX1BU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BiOopyrI316Gx0aNIdIbQTHImWVnUGxnyB+trf4HC3lWyiELNu0?= =?utf-8?q?VIGzuEeE0DIx8KH2K61dbPhj+G63Qiyn0LFMgRAv1xF7EPH3KFx0+kEF0h55YdSS8?= =?utf-8?q?DWDhxVDLwDMQoWlC0O/CFFyqJMdA+Rv1SnPC6BFwuQ42Qxp0aSDChKhFv4hyjMJuN?= =?utf-8?q?DLcUulUdm2T48bKbzOiVG/m0c/jvratiX6iC9PUhrUgkg4Ioy6t5EQFbQazhessZA?= =?utf-8?q?HhHiG/Lqlsq0/IZVbFQBRGnA4/ijGQX48R1WIRsmgBAQl+3aHBgQDdj2fjH9kAKts?= =?utf-8?q?lHEf0YJ2PEKW6UtRjpDgS+chGIv4oUMgfqV2+H4yyq2jgaopyPvdY6E8hMpXv9YQX?= =?utf-8?q?bJUI3BM1yxUqn1n7q8MoYPDg7wcA6A18+WUbJVXR16l634oTXuSkk7cRK2k0P4ICT?= =?utf-8?q?mIc923hyf3p53J8qVeYGXF4gX6Hb7PG6RFT6UTDGhwe2ZmF93VoWqI6w=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d2097a4b-1a1c-416d-80b2-08dd1879be67 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 17:48:52.2069 (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: Aq/WU8doqzrAWUXlIeg6dX4D8EhUDXlStyl70wrauB0XI+KxtDRUVQJ2tExINOPkSN18pqzjUvYfC5f6RYJMfg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB11017 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 v11 - 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 Mon Dec 9 17:48:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13900153 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2076.outbound.protection.outlook.com [40.107.247.76]) (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 A6C801F0E22 for ; Mon, 9 Dec 2024 17:48:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.247.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733766541; cv=fail; b=H53Dgd+cH/G2abmJ66HPejWNwuX0+54wGRw3uQRG9WBY7VD6XK/BKTnbDreAWfEMPScVyzjvygC+j1c/Yc2EOaEmrbuufzU0QVTiRE8tV8+URD8kPCatWa9nfY8dNir7477zLTllDFwu/agsK4oRYp8ySqlXznuAWYYt9/jPWoo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733766541; c=relaxed/simple; bh=ecsUMST1rqgl5nkhoe/wR/oiBwEmdq7KRl7zuhcNim8=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=iYRN895TtKqI78JRI9WjjUlYdXzNlTOuk/AySREVHQsauwevN4/CftZmqUnbjuDkyq7WmEY2n31gluxPlRp9rgSScirJ/NmY9VbUB93UjDmoxGiG2gOYxSDqzYpaMY27HSEwBy4AwyR7ZOIvj4dCe8uBsm0UNaCISGSJRK76OBE= 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=RjNqUNt5; arc=fail smtp.client-ip=40.107.247.76 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="RjNqUNt5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pgWgeAjOv3Ot2XgiWyR63xYErmKvgwZHXYM9cu5uBcS3wLvrG+fGDQouoyKeiFQyQmlcZU5PjDrCg3yrddQSDIZGkRblwcCU2YoSSXGKX4nLjy8tI5FyNbxZVQmc4YBv8KSTzx2/FeWBO80BESv79i8CTlsZbVM65OM2Y+E0bxNrM4XDcq1MMrMrKlZM3GQNjtM3z8hNTcoNJu6t7nj5x2KLWHH2Rhu7Js6klUtEuOtygJqwGIQGc5LkpIGB2tMGk0NZDZCCjfFsm/B3xEh9vr9Dv7C2A4hYg01UtRKAuUeQXXBSHLcTyngQ/JZ2QQniSoCixp5MTmpFt7KRYVtbcA== 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=86wpQXYBbhA0fUx6zsRkAJcExYphOAfZcp3Q386zG4s=; b=hUC89UKWnH6w/WOgerKUOR5mYTXFtaFe/OBmOYnAzOv/jiZS3bN2eDxbS6+HO+PT0s2nrUYSGaQ1qSDEnbLxhoTsoTxf9G8EqYTWdjxlGFBJ9v923Z4xnaTWQn95GxSf5zaUNdLZ8k+pa5DFZqIMikaMsS/OQiohmg8lCqOPLXtaUkVPilBZZYlIRtxRyBhSOQt28eSIuASDOcdh958eiEhVUdgFKdPbmZ6+gkktNlGQco4FdGtV9WXzrRwFGr9qH5okmlkhsrp5I7LMK7MWpdHH9PM/H+QVLRb3vmE8kNNO7hoyCQRA32qvXZCPnEpj9UA7TQTjUW21Xpl8UzCmsw== 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=86wpQXYBbhA0fUx6zsRkAJcExYphOAfZcp3Q386zG4s=; b=RjNqUNt5Q0MrGRgCVaM2H6LWBKSitrHjBMiuF9yHp7v1Wy8G9eChb1Hot2lnB+0Vbv/SUBv18YhYu+mOl8FCgNdf2JiJmzyLDWA0u2FNeNwMkZ5TT7y+iOvcdsDbYvMRX3YAtQxZHMubpN4sMRa/4NkKp5thmD1n/8Z7KFHvHXDAtjVRD5AS4cSNu5Mlp+MEOkSHbmpdt/SvREb1c8WyccUQZl1D5883wkEtsMR2ttZxKN2ghkm3Jh9Mhq2D7wNZ+p8LMaf86aqR8hKTGqHWMFwyUONdchZsM5UPKdVawIa1JOfp8H5sgIEtILHey42NF2sxAqbeoEuxDrVADkqGnA== 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 GVXPR04MB11017.eurprd04.prod.outlook.com (2603:10a6:150:21c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Mon, 9 Dec 2024 17:48:56 +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.8230.010; Mon, 9 Dec 2024 17:48:56 +0000 From: Frank Li Date: Mon, 09 Dec 2024 12:48:18 -0500 Subject: [PATCH v11 5/7] PCI: endpoint: pci-epf-test: Add doorbell test support Message-Id: <20241209-ep-msi-v11-5-7434fa8397bd@nxp.com> References: <20241209-ep-msi-v11-0-7434fa8397bd@nxp.com> In-Reply-To: <20241209-ep-msi-v11-0-7434fa8397bd@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=1733766511; l=7892; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=ecsUMST1rqgl5nkhoe/wR/oiBwEmdq7KRl7zuhcNim8=; b=uxujQ6ohRzq4QBUCI2MSdKbUWs+86awXR45sexW93IlWsrlBWguXOEuw2DYxoC2Uyt4kjkNb9 dBYfD9YWLsLBpQqfN22jF0QmwCoqpNsAzTJ1vr1jLAB5yDOjJ1LMqkL X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY5PR17CA0070.namprd17.prod.outlook.com (2603:10b6:a03:167::47) 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_|GVXPR04MB11017:EE_ X-MS-Office365-Filtering-Correlation-Id: ddf06acc-f235-4701-cf32-08dd1879c0ef X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|366016|1800799024|7416014|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Vpo75sBMYxJ/Gk8jZ/BuQY4/M9bn6mY?= =?utf-8?q?m83jo5ZLDAxC0KFWbtkbLbTleVxzTycil0Fi48iRq0mscaF398os/RIYlNvYhm1cG?= =?utf-8?q?EHT/+8leoQC+dsKU217+yRA6l09w99qM68nXxfc57gsd4GTeDtPJ4V9OjuwQ09m+A?= =?utf-8?q?6Qe8BP7dACEXnYBFB9hoRqN1EuYlO1NSP9fZeIHgrmVx4/daVfH2ykUEHjgxaW9HF?= =?utf-8?q?I33w6E8D2Sa4YQTXq7DhRxLpqmB1vyJozbnFjmGAYEgg+uUillCvYQqQmqXPHtnJv?= =?utf-8?q?uEYe4In89a0yhAIdEFrCP7+EZizyYqbJ2l+HIy2c8NOfee06QNSMMywnJM1/ouVpR?= =?utf-8?q?gSvYmUlKaJTaLyZzbIXPEIsQDWUkVup/VzxQDo6KPFAPOSBytP7ehJVwIxOfiyZL2?= =?utf-8?q?8OFA0NAiV58VY84XTTlSEZKqoe4PlWm8hJXA7or5Ok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Op85l3sF1pH+U5zjVN?= =?utf-8?q?d/glarQu1zEzkABBeKwsa9sEbgkW1za73X9877iXelrlKxU3eeearec=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)(52116014)(376014)(366016)(1800799024)(7416014)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?36CMcDg6nBt5gGR+oD560Y1REFr6?= =?utf-8?q?FKKr0upRK/qi5oMdRK1C/jRWy0X0Gg1FmuRoyOYE0aE4gNR+21ZPMqZIl5UrDbLoO?= =?utf-8?q?IbyJT3h4lRw+op0kNbRlI/zGyTTUtCyqTGLvrqp4muZfsYCv1vrD0p9ITicOj4uyn?= =?utf-8?q?lku8TGQVmLrsqoB1zZvFaoEMm+9ncmfZU11dpZGcFI33QedRt4DOOH8LxvcbVI+Kv?= =?utf-8?q?tGcv1YaxfQKz2EGpFpkadLXTysL1wAzlk/WNyTgPNfHkJrbb4xK1Yy2fwrY+1cJ/b?= =?utf-8?q?8yf4MNPHff1AYDmysjYFfE1twntDvl2jRw/Gl4RuGdRfu8iAP1rqUNVLcGer9oErc?= =?utf-8?q?HmS/mRwR3njv+L+LMGXqKYt8H6iKVNpFkQheSSc4mLodbpRNUGoKRCezULt0hviKn?= =?utf-8?q?RVhtLrhy0lArMO0COdPAdWSfKhHwne8bbck47Wml5loj48WZxnBRvflMw/x/CFUmB?= =?utf-8?q?E4l48PAlp8FQ3g1FmhzwWG1E33boEtQmJSGg3gewRKucNRtOg3keNZWC9bR/I4pfj?= =?utf-8?q?g1IGLbuEvnw5L6P1spi6mO8M7CdlA2ODOL23TeEkB2MlDkSQ5pg0MmhXTJ1Xy9Mio?= =?utf-8?q?mJY3Svrz8BR8XW9/UK71CdTm7S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J7ZbUwY+9M34zvRjrElMLoD6a3q2A2F4=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ddf06acc-f235-4701-cf32-08dd1879c0ef X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 17:48:56.4770 (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: uIyRwQeWlVF1/wk3/UoD11qonQ0g27U0CETDxq33nHybu6t68EZMEEX4q9rcLr/YGnxiaKK4TjC9I8U32A/Hyg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB11017 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 v11 - 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 Mon Dec 9 17:48:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13900154 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2076.outbound.protection.outlook.com [40.107.247.76]) (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 26C901F0E34 for ; Mon, 9 Dec 2024 17:49:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.247.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733766544; cv=fail; b=ANfbu3PT0IhYRF/reaNpIkUbgq8TWLerKvjctEsEuatvQ+xK9R4xOMMV63HprPYeg7+n4n6Gpuu7KKbFKlrrFw1IGAry2JUrW4UjdNHi4kxqnz0zmSdUmwnEq2Luaei96abw+FYKf+NFsIdP1zcDStFzFLTTsmn6SEyR/2mZDlM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733766544; c=relaxed/simple; bh=PaYILZ+ZM1f1lH5TRWB+Pf5dVKwn8b6IHDryYNsxWvI=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=iZaNV2Va3giI6qYHMHbIDYSmte+13xLwakcSckwdHDlSO4YfucXkU7qqypeRdo18fzrH/Lqy4Z2Hn7QG56DH4rxG/ykdrM0MZch/0C9yDb9i1Q1HXVpaBzw7wIkTmQXg4Jz6XU3wQdMFhtNW15oamhZVxfq75SJPwoS9a5KqZ14= 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=PsMwRGOk; arc=fail smtp.client-ip=40.107.247.76 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="PsMwRGOk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Gts5lNCnXEkR1dUU9G9136D7OELkg0V0yYB8mxZEz6lllMqHYRZoNnbX1ucN3Ok2YBKfy5oRz3zdaF5wLZYGIE4E34Ii7vmDLdB9JBI93GO+NtPQGRimdLQbR1VYHkhie3/JO5lYb9N+W9AfXqYRIqnEXzbK/1TGWrlgZmz5J9wyjhTbgJtwJNSq8N/vKxnY2VvKMXnPC3pEetirKdPBL7F01ptpQZSSMdMFYC6bQuuwG7hNNYqfQtBs7NPS6aqsojn8FCONn1R0SoGsNqS9wHxtz/SshLbNyN7KeXj1iqqOmob9r97khk2znDfbpheS9Fr5287KIYthqKCh9oVJdg== 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=K5FPaZ3LayiFO3rfW5JsISxtSjCShLWFdWQKWv27vnM=; b=Tk88tRihZB0txaf2OpQO+0pAjg20iZd+Qu5yYJil7wJW3c99nz7+yTJRBImqebwJZqUZGvOB/iRd0D+mGWqDpSzzdMkhepjwTv23kKeTyTxG05VnDeWo8ALEb14qmW4fuACq85ONszbB0Ow9+AtZgHbtH8Vd+9XGSreLPLLhbR7YiR9dwWa8dsIGENkKurB9CVfrZE6eDLVpULBFkl3nPcraea/7ITZnqhDT4DLI4tGCSeiy617Pok0OsyXkqANjRRjkSSBp7VV7USAq6Y3kHsJHQbn9oB05g2iQZC/cn1PuFX41GhQcEgA597yrbx2NDHEl9E3B7xF8UppkFDpjaQ== 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=K5FPaZ3LayiFO3rfW5JsISxtSjCShLWFdWQKWv27vnM=; b=PsMwRGOkTaukH1ZMQFe96M8LsQ3NQTwx34wJozrD9pmYYRNVYGQqBo2SxD53jGDbmKxgkzamT6JxrCVz/7XYJGNP/fMd425BmqOSjR5aO+Bb1gziLTvUdcjQmvvgu2auTp5fy6PSRXvBelBWyog1KSsv4aK1Sb+lH1/H2G+rFfZxOgIQ6JiUkberEDPlTUe2YfJeufcJ8tSil1fss6ri4FFj6niAXqAcbXeY6c2khDAzzDKI+QKAoe4qk9/TmLP4hzd3vV2FRoqbauWnWCFc3FSDILHpohwkqeDWtaZoXwtXixJIlBOaYt/u7Qt7Id1vQoh2cqDRvTJRRxYf7+tmxQ== 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 GVXPR04MB11017.eurprd04.prod.outlook.com (2603:10a6:150:21c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Mon, 9 Dec 2024 17:49:00 +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.8230.010; Mon, 9 Dec 2024 17:49:00 +0000 From: Frank Li Date: Mon, 09 Dec 2024 12:48:19 -0500 Subject: [PATCH v11 6/7] misc: pci_endpoint_test: Add doorbell test case Message-Id: <20241209-ep-msi-v11-6-7434fa8397bd@nxp.com> References: <20241209-ep-msi-v11-0-7434fa8397bd@nxp.com> In-Reply-To: <20241209-ep-msi-v11-0-7434fa8397bd@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=1733766511; l=5981; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=PaYILZ+ZM1f1lH5TRWB+Pf5dVKwn8b6IHDryYNsxWvI=; b=6YkXa9efyhaPyEHdEfk/UPRrGP1U4en1a2QrC7PsgIw0Z/YNaRO82kfvV9ikJWCZk3sY4N0+D Vxp0bukLLIQBv5UpWDaMZvCtPkstjtAlQLWTqRtZSkFqO+Dbk9xmCJ6 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY5PR17CA0070.namprd17.prod.outlook.com (2603:10b6:a03:167::47) 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_|GVXPR04MB11017:EE_ X-MS-Office365-Filtering-Correlation-Id: 93ef8d64-4353-47c9-4ed5-08dd1879c379 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|366016|1800799024|7416014|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?KqgcC1mASV/ohKM24knHfl0+WHKEH+p?= =?utf-8?q?gQaEK0/q5euRSnhNZLKiIfFSUftNIR8pkgYMB1yGTa2M10HkiQzMesd6dsevYck2N?= =?utf-8?q?V6BN8VTZLFt3a3G92XO+MB0yzz+k8Lhf9wj4Y6crVibrG520thpJjMmjY0/JxlnxC?= =?utf-8?q?unLGZigLR5vfJVAUsB2fk5HaCsCxCVE5zWu3mJwzf0Ozyy9alt2xjwhQUNANMwcCy?= =?utf-8?q?mvNbNin7pBVwQqb5jeJPEpn5Ww+vYNbQP+Q90jaLZ3lOk9RZHGzGIrkvUd9UsSryd?= =?utf-8?q?xLoyP4TcStEMD5fRNlqot0eLOOZygONfC1jxu5Ddr0s71r16LsEATRssIR4lWElV8?= =?utf-8?q?rQzjV1x07GLU3E3i7IMFJTJTFkOQ1IU20bBIFpak+FxbExqMRw5yOEv/QeXbQJoP+?= =?utf-8?q?3UB7IUVLOccRnC1fkzkSq8VCYvdsjKYRi7yV38ghWNYGMD+mKOLnumlV6TKQosxy+?= =?utf-8?q?0FxOa8qO+c0LDkkiTT9T+Y23M2srRidkuBZFJymFeJUMvIIFasl+Ae3tqyUahzmx8?= =?utf-8?q?XgGXG2LaprZXxCF0WUS0hcE13BdzRV42dliZDRJgWbgzekVDGcyFkCL8P1G4ErHmB?= =?utf-8?q?Fqt/PthPtzUuvjXHEABm8rfpZ8DVSicxH7FPfCukKjwMZmLpL3nlk+ks2Ebp4WRyL?= =?utf-8?q?L9Qkz/6EVmKAU/dytdPgznKw7z0e7QjdvMByhLzq1PhuRrYB2TRxpdvS02XfrTAhy?= =?utf-8?q?Qei9Ui5BDxWxSof6nMzAwMtbhFSFR9cTPymNZheG4XXnSeZEW5yEFmsSW/gqMbbP/?= =?utf-8?q?7SYDnBbDXGIaackAxOnoZhXpqdWIKBN9NashBFMAFFYu7Xd37/ID+0EiV3lOdR+9i?= =?utf-8?q?2kCs92HQFoI9h0Jv8MGmmteiKq5eZs0d8Zo0U4YJJKL++B80JJ/fkqM8Ris39rBvQ?= =?utf-8?q?Um+YA2u4HG/72pNP7kWX18wPi/AwupR+jDc+DY6hvuA7/qKlVoldRWnY+UX/QYaQn?= =?utf-8?q?BzBK6TPqb/ejy9InAU6DLpRlKEUJpMrFQbklM79uyTO5OGjVLOlVj95lzKgS2mkdO?= =?utf-8?q?3YEXp1D4J2QrdqtxoFDc/DyWsEn47IiROPlT+DTN/8j7jo3ImOZE5ptmwPzTqaRtF?= =?utf-8?q?IFPGSP3o1tXwsAN0DCpxnpYxxQ0CQYSVJF3i2owXFgxcfpEqwy00Kfg4mdyyj9yeB?= =?utf-8?q?MeO6c3laTW3KS4uX147kaQ3GrgBW3HQ8bE39Qo5duv+nWS5vZh5lTmyW/JkpLAxvI?= =?utf-8?q?Y517dooQzdzVVn5Z+w3zAXywbq1+CCjti1+mH67HCuAsausSGpTVDuchZCZ3AnbfN?= =?utf-8?q?Kt8daeUZ8Rl5MvU5mBeMvX9SLaCyLcy5DFJVTWtpbL38YlLKDezq1X9nhZbE9fgMi?= =?utf-8?q?KJ3503SqdFJWXq/69hH1b7jwOn5Pp/TISXbeuDDFvgbODnX+2cSbpaI=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)(52116014)(376014)(366016)(1800799024)(7416014)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q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KtcDR8fVS059u3afzI2kV/o6wHS?= =?utf-8?q?XdRppadulzyifRKQexiK1Mm55td5rKk/KfazIrB/CRCfs/U50+H8oend+aJ0NUapC?= =?utf-8?q?d54kgbRGny0pnuMERCtFWfHIJhTws1YYj4qCFNJG0aDwzkieCvKKWTQ3ujHg6LtCN?= =?utf-8?q?28NlA1YZpJDSf5DlfZDehyJiJ5CATijP60ln3AtQplXnD5hu9YPS/SE+yh68hbpI7?= =?utf-8?q?+9S8izcZQBQDpNx8Md4Sk5PJz0DPOMUguP9+i4iJVB1Rl4QKpAT8fi/62N0Rcqq5y?= =?utf-8?q?CCd2zjdgYbfE7isE4HDA/qbFxK/iDfpZ6z1lSNiKjVMZb3rDHHSFnyFqI3qsq9v4d?= =?utf-8?q?/pwKGapssPV7Z6Tw+MMBRXebb1sT3dvu/UKJSMeADQv2zZF0AGMe9y+I8+ORwHXKJ?= =?utf-8?q?I1fbxXMZBCKFDsBp+Kk6+b8h1nnjJR0Oz5O1M3RlunHDc3lxkSEEUd3hCafZ7fIRh?= =?utf-8?q?ymZsejG2xitj7ntUR1SRtpM4EXV8Wm8he+GfUEzZKx7/okcYettkK77dgEHrN2gNG?= =?utf-8?q?G78+paoZnb5veLAtLEb10y93r36BSHKurFU6USCBlTnGU9o4+LogS+MV1Ui3bO+7n?= =?utf-8?q?UdMDiCwikfqhHTv3l1PocZKJ0JI1l8iwwS5I2HxID78GgkKszisOfu1tJCRLhofGm?= =?utf-8?q?44AcRwOmdS+e?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 93ef8d64-4353-47c9-4ed5-08dd1879c379 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 17:49:00.7013 (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: jzosXSegx4n4avDop9h0qMf9tGQZphrbd1JEZ56yoRfkWTPSPQs+5KhI483cHerdfwQBY31y3NPZpv0J3EMWwA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB11017 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 v11 - 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 Mon Dec 9 17:48:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13900155 Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2056.outbound.protection.outlook.com [40.107.249.56]) (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 885CF1F0E52 for ; Mon, 9 Dec 2024 17:49:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.249.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733766550; cv=fail; b=cBjXNsj1d002+Y8GeOXqeZjQKmDyPQQGZ8FGJrO5FkpiCRaBF8dxY3iygNrYzyolX+EbMTzhAFxN5/UG+FJ/TSYlkAqor/3kK1CmN8tF5Jjz4VUuKn7CCnNIeiVi3J0esmLPQShe3+ZbLQl5sTo5jUPo6t7KbyjWnmoRngoalPQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733766550; c=relaxed/simple; bh=nOdTcGsplP67pe89t/lWexxXwRfnbNq0CbahLICCrsE=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=l/vOkECBCyWqZSC6HbuL6Bfrxjo1fEx4lwNL9wWCBLSQJKkUafxpoDG6A21k0mDj/5gHSC+mL7Klo2ComN25mFL2YCGZwURQ8an1D+NKwGqMACa0c4GHy61fGBqrZc/I47ALAKLCFyq5GK0D2IzTzsoqvN0PY4La/eQY11Gmgio= 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=l9Yio8FF; arc=fail smtp.client-ip=40.107.249.56 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="l9Yio8FF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yFpd5+NAQMmFCP+pzEOSu7DJZ7aqa75pKDJGJlfqgmhMgtGTPUWppC0JcD57S03q8miulXn1O0DYNGawiqMbRGIJs1FwhAGnMz509EXD+lwu2DfrKaENqX48tJWTgIoPeoofka7YUeh2vdjZ+EYz/ZbqwX+pP2oa13Vnl0W0ydBruEFaW5j0Z1wJ3QzPT/tctY8C+W68mLPePKjiE0DJo03L/8pNiqj16VIvmmz9EWfK+j3oP1ULTUVIR88HU3jAAfFwD7L4nwVXq8rzeSGyeMXEYtidGBnGTORMis8KZcqrF7MkwXTjY5hZG7g+Ia7gEoo9A+M/9gycWpiwrKmMzw== 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=WrbcNtRasZ3J5xRN5xIPVWVszaYiQrxyw0UpP2GGNOs=; b=RrxOOgzFCReW5qbvZ0J2sD7OPZcH+sRP3L6hfV2Juj7HFQi9D726kgR0Ka0mZ6ur/TEOW1BUO5vyE777HybBhX146wy5WdERHJ4C0Opt7bYne3sBRnDBSzY2JMq6C+s0PSqI0Bck+mVuXZFPRWXb7rDhhscZvY/JklLm9oKv1CfxkgGL9zsxncKPNGYP6BvpC8GT0fH9AdU/+j2P4mNN0CHzA5s3rSl5BuBF2ePUi6E48ACKVyz1wvG8QDgm1n+ozcFIjUbcNf8lralprr9ZJBwcJXe3JzAGCVclXdNraU8enw3IS9W+2U/VctDoyTgPUAuu91mprNHg4wNw2XyCLA== 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=WrbcNtRasZ3J5xRN5xIPVWVszaYiQrxyw0UpP2GGNOs=; b=l9Yio8FFW3tv6e049eSbpVxfwMtVgPtDu44nLaMDX8evtAlewSr5aJdejPUe/oL7EC+Lx9z/L6QaIouZCZQC2Yi8HSnB71HBA45B/zDnPt4n0ITlHjTZ4SAg6ausjcXh0/ujsq/PfQUPHa6PVDn6liJajBQ9sEI/OvE6lOmzuUdEfkQ+Qhri4VQeOxoleiuxUcENUgJlxiOJNymrBChScpIpyrDqlA2uF3UZbi0pOWYcz92MPVokh1RlsADKKS+sqTvxMD8l3EbZl5ZEWC04Z7lziMheGNy+Qi+wW8dQczX87KnJPuHUSL2T4q54baod+9JinT3D8RCOLJXb+DfgrA== 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 PA4PR04MB9485.eurprd04.prod.outlook.com (2603:10a6:102:27d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Mon, 9 Dec 2024 17:49:05 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.8230.010; Mon, 9 Dec 2024 17:49:04 +0000 From: Frank Li Date: Mon, 09 Dec 2024 12:48:20 -0500 Subject: [PATCH v11 7/7] tools: PCI: Add 'B' option for test doorbell Message-Id: <20241209-ep-msi-v11-7-7434fa8397bd@nxp.com> References: <20241209-ep-msi-v11-0-7434fa8397bd@nxp.com> In-Reply-To: <20241209-ep-msi-v11-0-7434fa8397bd@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=1733766511; l=1851; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=nOdTcGsplP67pe89t/lWexxXwRfnbNq0CbahLICCrsE=; b=ZEtULO/MfiNHjiByrLc2lg/EpZTMdmcewapzhTVji0QmZrEurBIs+ciwtyS7UwcMz5AYau0yy kQ2vCkYBLeSAJ//UecOCZEPhcZ4pg8bBJJnNHqtfs6u9rjwGJIVJ2GU X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY5PR17CA0070.namprd17.prod.outlook.com (2603:10b6:a03:167::47) 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_|PA4PR04MB9485:EE_ X-MS-Office365-Filtering-Correlation-Id: 1493b9dd-235d-4bcc-df46-08dd1879c5fd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|52116014|376014|1800799024|366016|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?wTQ7CW28+gJTpdjMZRz8G+ZB+T2qfey?= =?utf-8?q?nAxLhLAHtNBz+pX8SFrOv1CALxMePZWXkPuzH6Z0GGFIoIvkRIUqCtO9mshpHj0FM?= =?utf-8?q?ImCW1R5KUhkggqAA+VOKtg79ISGEl42d1HFJV3NL4u+yGd3fHdvb1XTQU5vlzdPPK?= =?utf-8?q?gHlz3a6LyAwuI1D8L12T/zHumHcu77DrHx+2XGWMfhkXetjQlBF57Mq7du0pcwFgg?= =?utf-8?q?TKiJL/XAphwaL2WWNziF0rDaw6Y4gz9TzNH4D8ItiVh2eQNapYzbCGzyKvUZbSh4c?= =?utf-8?q?oLKNmMrzag+ZkddP1zXcaqzNdaP0L/HFfzNX8rjgQypUlj9FXizsHkyU6cygLgDr9?= =?utf-8?q?uopqUNZdnSfJK3Su0S3Q6sK5TJ+0oTQTA31P/uGlH3Wyjc/E2Hk8XecnvUlLiOFUF?= =?utf-8?q?jKl/Pn1vtSeAi46Pn1TKw2gw0h2T3l7HwS3wN7wxrnJqbaVuCmHOn6LP6BVy+//wm?= =?utf-8?q?QIqkTbjWy0rcfh6ohLAqz68IEhZXGgWz+XrlIe0irQEsG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X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(52116014)(376014)(1800799024)(366016)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?KUbyx/x3oqrmt7+5FzFiGMZk7F9p?= =?utf-8?q?P23MUIVYQwwwBG/p8RfAL/4QoK6o6+/NQ3gf0k0OoE0ca5HdGQlHBVfluAhIdQSL2?= =?utf-8?q?gD2ZW6qURZNdQ5NJGoVixkT9vliEOGwnbIgr6HqcjGeluzsLSJQfxu4lcYA5Va5wi?= =?utf-8?q?j5HPYRxWUbEm7tgAG54QWWxyWYKdniQSM+NWT7dYZH5iBZZtN5zhP2dhgVf5F5xAq?= =?utf-8?q?jqCxQjLi2IThENwsU9cv+YZRpcTtLj0qY8ALxWs1vtZgkzRaDJGZofuVgqBN7tK3l?= =?utf-8?q?da6wzQSFGT6kY+ZcBoNAVAfuJnkcco+GFYbmVLdkU//seb/GdFHl9yuOk1Zk/HPW6?= =?utf-8?q?HFHk7EMNiVEM8viZqk588W5C0xKGOBf4iDwQTz27aBh6znpO69HPzfinK3qjlcKdc?= =?utf-8?q?o6fMKSrcCRiig6asOjSD9w5yGJcLFFmCgIYZ5kiPdQ0n8lTvbJRlsPdGQ8aFzTZxK?= =?utf-8?q?q0dn1eMyPiP0x0eCv5bvX9H+/Yc2QUZK+4Im0daFSyhvxvH2F/R9z3Z6faQUGZwy6?= =?utf-8?q?RlOK+41gqAss4R1fp/xGPy7vuYVpO4A8g3tpoHyz1vv8LN2b5FOVl1yYCvOrn9Tbg?= =?utf-8?q?VEx038EwJ397RSOAUcAQpqk+uCWyXWko/g0oc7fux4w4MdG+IqstuTfgmwbjdp1wv?= =?utf-8?q?XKIVw3zf376a3XaPgasl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p.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1493b9dd-235d-4bcc-df46-08dd1879c5fd X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2024 17:49:04.9225 (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: E5P8YhVr0KwH2q1mONUdgTvElUDke2V6Pg3ZFIh+oQAhiJdAGoZp95baBHQB5+z+gZwxeeDKQYElXA8ntI+Isw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9485 Add doorbell test support. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- Change from v3 to v11 - 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;