From patchwork Sat Nov 16 14:40: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: 13877606 Received: from PA4PR04CU001.outbound.protection.outlook.com (mail-francecentralazon11013004.outbound.protection.outlook.com [40.107.162.4]) (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 2D2441C68F for ; Sat, 16 Nov 2024 14:41:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.162.4 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768072; cv=fail; b=HcTK7IXtqWPqJj59hyWqM0WigW1+xmHwM1WWjhcbRp83eiOKvFUC8zZIJlxvbd9f3rAP8FE78ivaLm/i8NjRY3R5n7u6MvNlPZjYgUW8yxiaR/iQm6E1l/vve2UZWMGwYPazN7h4hacA0aPwQytGY03EHUzS074OGzHno4p3TSA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731768072; c=relaxed/simple; bh=/7Pai0goKHvPIK+tBY0qEDaD68qr8tke0aMwrO4/bPg=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=Jn8GzFWODKVVkfOElk+ON+XoEbD0xSIlIcKkESkNP8jPSp8BUnBj6xBjjY3pK69X8Xzwh+tElHmlR3gmdkpiIf8bXteoUevaIzqVUxPR/G8Nk1OlBqFRdnT89o8IXala0WQ9A/7CuDtMPhQcIRmS3XPcbKF70RSA/8zUNCTIQIU= 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=VYLo6CEC; arc=fail smtp.client-ip=40.107.162.4 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="VYLo6CEC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cG9PPusefQ5OmzuxUgymceolTmwb2bgqaYcJPBMg9qUJi6OSp8tfiIfuu9GWIh1QfWvVkdA3nOR2LLD2qf3yV07NEv3QCgIF3RWXRvZiqfCSAkPFlnNy8dLVjDOJZ10bQxopPaLH8tw+oWX+ahZWNlr4/iTv4MtyJ2grgqMPHKy1R9bHxXW+1B2y92SGt47QnliY7Tm6DsyClnY1FWB8U1vlSsBsy2zv7unbycILeketJdP2EBi49QXkRM/wyKChiku97UzNxEYPaMNhqI/NfBOXlv33Q96A3GE29FDvpLMp5oaWeCeGFo4LUbEsY0Duhnod46ad0nO+QaMe9P0FPg== 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=1sA9ZGGwKCFVa3/DR6CR6X7jz2TH0pu4avIrpxeaQ+U=; b=NL4KMSl8o1A2OcMzEKlRHwSd11bKtRQnXQKHMTEKhL/itMgJAQJVlAmjS9I6zZuzE/rLYaGtfwpf1EwUHcJbYroXG3fWJlLQfzEdbA9XZ7dl5l9+1O5GnODiwWGyWi7q+eXB3TqRiMx3+JGwuv/c/08Wsc1kE+tLfQbBCytqEpjtTt+qRAQK7jQwMKQUY8z1IoQs9VV6KMhDWK4qKkdyroVxbdRiIP6Gr8pVleRI8J0cMRsEsz4CpmIZBKjT80bX77ebuh2D04vzkqiiBkHBpKBRyg9qYSx2F8KtqNRWgU5VeV/6ZV+uDu2EkF1ZJ6BQh3L4HZdYTfJ5aUQHY1f/KA== 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=1sA9ZGGwKCFVa3/DR6CR6X7jz2TH0pu4avIrpxeaQ+U=; b=VYLo6CECcQITJTotF/xsVEFajkV1DBcCoae8tEgpnI5TG4qfWMq8ay+6N9+7rYpSWoVG2Ud6iiNGU4GJoCEBOxzfV7s2ocPlOOUwRKyr8HxZ9cnfLB2N1esJXqTBc7KcJHQVdtLwNFqfgm48WvRoQA9y5svcNyzjU1aKF7vLI2VIzOISdDb1OH5LvBLAOG4grmtma1ApRSjqsNG1x/ZLRSNtYAjhBlIRN5pmI8scxik9eUqWu4VtivzHNlaE5hIk1rt9tjDlM1qCNS0cr0iQY9vCz0lAwfK952r2PKISxH+gmoorL5RDUsQWKIxeK1gdgJkkRLLZVoy+0NvqgoFQrQ== 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 AM8PR04MB7265.eurprd04.prod.outlook.com (2603:10a6:20b:1d8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.21; Sat, 16 Nov 2024 14:41:08 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8158.017; Sat, 16 Nov 2024 14:41:08 +0000 From: Frank Li Date: Sat, 16 Nov 2024 09:40:42 -0500 Subject: [PATCH v8 2/6] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Message-Id: <20241116-ep-msi-v8-2-6f1f68ffd1bb@nxp.com> References: <20241116-ep-msi-v8-0-6f1f68ffd1bb@nxp.com> In-Reply-To: <20241116-ep-msi-v8-0-6f1f68ffd1bb@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, tglx@linutronix.de, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1731768057; l=6297; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=/7Pai0goKHvPIK+tBY0qEDaD68qr8tke0aMwrO4/bPg=; b=aolckxJBE7NIPP15dDaja5aOivqFX0rMvEJ8oN4Hfa2HiMT43Xbadu4x5MwNsXYQhI7hH5Bcz FOhmx3bYlXpCsw5gwKb0AWcFpsBYTJIddaRZFz3EOrNtMS612sVDdNt X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0210.namprd13.prod.outlook.com (2603:10b6:a03:2c3::35) 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_|AM8PR04MB7265:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ad3b6f4-3474-4720-7133-08dd064cb565 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|7416014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?VYNLkNG/OtZCNgBMt+LFrCN0EiIB21e?= =?utf-8?q?oz8bh4nHwmZM8OMNfoVg9crq3aH4gSDVEB1z0PMSqLIj/oXlgpupFxJrm5aWSKbOt?= =?utf-8?q?yTCtHGN6pA+x7dLdL2cRMnLZN3huaukdp0r8sbBqyw4stM5Srsa2GnUCkZIk+gM3y?= =?utf-8?q?3wB4lFS0QH0MGXJgkSbl0oqPgR26rPsgWsxr6NL+itrHiIulcmUv9y7UWmiLuXYP2?= =?utf-8?q?OM4wwuaVxzKd4xjnZvkI9lDj4bQVUlYCvACU/MRXy/hIFjitia9jo04XYYYR25BmS?= =?utf-8?q?q9m9sv7GSIk4Jo/ouBEwODEl8EosFreb0jkX0WFhvyA2XbHzHOqvgk7F2nyI2pefF?= =?utf-8?q?RFUcXOEJ/tLk2Jbnd9zJNIym9I59KGZFTTIGPkF1c3e/kMmrIIJ8vyhmrKa0RmA7b?= =?utf-8?q?tQ52ePSsURK0EImt5h1QDDYj+NntIHyYMNDxPxEB3cX7TSibZS4/LkmH67iDW5lhm?= =?utf-8?q?XXGn1vTFbW7Kx8PpDTDkj/Aq3DpOi8C4nnc6sWxEIQ4tv2ydrAccUXmUgwjnxXm6b?= =?utf-8?q?qggxR52GBbUQ1Zz3DWd5pVLyCtPVsEsi8Xdm1psllyf0SZusiq6pMu1i0e/k+nq4c?= =?utf-8?q?s+AK+hUy8/UqQ0sANgM0rFyRzRs98h9sAUtfHd43IDF+dKcE4SJDEDWQ/+LLKaGlY?= =?utf-8?q?gA1Lf5jHw1AaeIELqx59bk6z+H8XWQacNFd8L8JsTKL5yQm2v5hAVnGYviTLMjaTG?= =?utf-8?q?dYXxeGhjfvFks4IkY2uP4v6OETHYMgM2S20jVhYkrBCwF+IqopcUY4670Ja5plvdo?= =?utf-8?q?zie3XE5WcKXLnL4xPHBNGzdsnLFIjZwjTGItEAD+7TMxS4Vs6Z3DNr1QI+BsVBykx?= =?utf-8?q?t6WvO+qt0NPt7Z130xvuxYJAf2tjas+SeLS+a+f+zpbuH0+ZhRJW706eWRPtO+VFQ?= =?utf-8?q?rBtamEHyhEPshjC3FY/sQCZG3jmvxcvbnlC2T0sQoCngvv4EGkxz5crnQ0GBh8Wq3?= =?utf-8?q?eQiDw9ZEx0QfSi+MUY9Pw9Kob03aawp9mNNTVzQbJBDrdy9CbBvtbRQAuXbgHl3+X?= =?utf-8?q?HhYddpdHMA6wyZ5tPP5nJmmKM2OZTd0pYBrd/t5NPnbfn+Lt2WKY9W9DLCVtNMPHq?= =?utf-8?q?+Rl+scjzCP77ZR1y6Xr4hon1+DAKQOE/1gR7++bYW6smfOYNTqEj1A2gxdjGNqytP?= =?utf-8?q?sEA64TtOBgwxASlfidT8MvOPU8BfgmoJfx7pYUGecqzNzSjKlcMZDgrL+xFAYMP8s?= =?utf-8?q?WCEmcZs2uBSR7HmFYNy5GVy+teDe6Vgapjp2vmowuj8rOjsr7Uj/SbS9AdzKRvA7B?= =?utf-8?q?v0Xa6XInT8YEli1/DQqZ8NyQjeqZOYXb6x4bXUv4os5RFFJXj6S1/8/s=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(52116014)(7416014)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?cX9fKJEUqh0ycMUymq8txwjhupcO?= =?utf-8?q?poVxGFYg2PIu9Pz0iLoEus3ENpVHgSIAfyjlhNI8zqhfImGqx4tA0q0WJMluPkw1b?= =?utf-8?q?/lczRzzyMncfpU7lGn209ComIwsSy49WlJFpw8cPWJw2Q90xWLw3iNKTHBdRagKA/?= =?utf-8?q?8ABzbtOIaldlXwyAEQFChOtVHw7TPtrB2HzAz4N0QCptgj/fkuC/olvuDgIQq8fse?= =?utf-8?q?+nYRiZg8H0127ZA1R731bwC0Uqgb4QXPpFtRmK+EPDRGseq3RVJkqTQFcd4phx/Eq?= =?utf-8?q?DVIYbLTmtA5+qq211EFUuMcwm3oAMA17fnI+RRH/MgIOwkn/aVHp36HKwuhbTTljX?= =?utf-8?q?b3XJ8CbMDKijKw4/EDYmlrhUmg/rDlh0R4KHuLIchWi9vWY+4LxBDF0KZBUS217Q2?= =?utf-8?q?++wOlMjo5bkGSab9qlXWDUkhoa8ZM3t+ZoY1QEzJoALYe5CF7JWayjCQAxsdT57yZ?= =?utf-8?q?p6tZj+RQPNFBq1rkrFOHgiHRbFJ++4DqaQ0H04vTa9CcwOEtZq8xQSk5hzxVwAmi2?= =?utf-8?q?7HwYuxcA4WYMTzuSKCMVCYmsAYeQCifiN378zFm809lDVumrLGsQOM8u4rFdhDJFU?= =?utf-8?q?pD4ndSvLuv3puYb6WbAYBILgFAWC/n2PmTTRivVV5DtWsZWDi2d4Ht5QwczgOx2Qs?= =?utf-8?q?qNZ1HVERFVocqbQXpdv3MkKvym5z8yVvcDJCAnD3OikORR8teArHplS+M0IPqQ9gb?= =?utf-8?q?Ff1uIvf3oSsmBLnafzb/oaaN23wfaUm2FjyFZqI7Wrhz6l9EAkaPO69APMn2mmA1m?= =?utf-8?q?QvALsMNkdg/reQIOLjxgQle1wTE69CPOelVlc7/YoSNIJRrcse3wyh/ryOP5eM4yO?= =?utf-8?q?V2ly3rYhmtrd+BHf7LzaPOPim6ulXVLUjuiivMZFkvZnXwtl8aT7MSCKa0BkAl+Nj?= =?utf-8?q?uzH3j3KeZMAqcNQKVfBo8NIh+8uFAsMzLarqlPumU09knfyel1ND+n0FrHLo9g7we?= =?utf-8?q?1ySKcJP4cxhSznjIz+iXac6FNaxfOOB8cQzRjQ1z+0N124xRdwSlD/+kQAUeApgsf?= =?utf-8?q?RHlDXN6tXYAYkG//Cz9P7QOWYYEkWbMrn4ZIzDU5w8c6V350YTB/kNtPYkV2ZYYMv?= =?utf-8?q?UwmqPqocZOnDXPH380mZQy4sqWGrD2wkxlslKBKsfNRvFEVYYorKz34G+8zzo30O9?= =?utf-8?q?/E6udiwHy/J+5IqyxX+3jlCZHU4eVJwQlN8bsuNyKY0nf832EX6kUcyeI05G8vX2g?= =?utf-8?q?cmMhWlGdO3ET0W5jJhILEvRFt11rointgeDMYQt6cFRvQHMhAYmrHz+YJ+wmsCZCO?= =?utf-8?q?eB1OltYWYE7s2yMYRHSEciVZgvIuRe+2qtzW/7JpQH7+aEwZW3PQIaZAhZ/vle0IU?= =?utf-8?q?n8h+dW6AWk3RXHNIQx6lvNnl8s9HBf4Deokp4wgURx2Bf8T4pEKtWbueTq4wCFS8A?= =?utf-8?q?Pjzpfua8wJW4uR9SNRmQLQarEuX/6Qgv5GybSjCa/bOLPSm1ieOeVtbNmvaiAlPTE?= =?utf-8?q?Tj/ChmvI+tOWi3pkeRRQX3+SjnCaA8+70GJP2QgUT6sf7HSwI2f2flyM=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2ad3b6f4-3474-4720-7133-08dd064cb565 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2024 14:41:08.7943 (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: YMeSCH2ur+wcKpQgYegsA4kG8+vP5dDwZLlh5/jrzByZ3/iv1kiKQSVlaGRac9ZXA0tYhq5hNDj5w7jFkKdrdA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7265 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 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 | 99 +++++++++++++++++++++++++++++++++++++++ include/linux/pci-ep-msi.h | 15 ++++++ include/linux/pci-epf.h | 16 +++++++ 4 files changed, 131 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..7868a529dce37 --- /dev/null +++ b/drivers/pci/endpoint/pci-ep-msi.c @@ -0,0 +1,99 @@ +// 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 bool pci_epc_match_parent(struct device *dev, void *param) +{ + return dev->parent == param; +} + +static void pci_epc_write_msi_msg(struct msi_desc *desc, struct msi_msg *msg) +{ + struct pci_epc *epc __free(pci_epc_put) = NULL; + struct pci_epf *epf; + + epc = pci_epc_get_fn(pci_epc_match_parent, desc->dev); + if (!epc) + return; + + /* Only support one EPF for doorbell */ + epf = list_first_entry_or_null(&epc->pci_epf, struct pci_epf, list); + + 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_epc_free_doorbell(struct pci_epc *epc, struct pci_epf *epf) +{ + guard(mutex)(&epc->lock); + + platform_device_msi_free_irqs_all(epc->dev.parent); +} + +static int pci_epc_alloc_doorbell(struct pci_epc *epc, struct pci_epf *epf) +{ + struct device *dev = epc->dev.parent; + u16 num_db = epf->num_db; + int i = 0; + int ret; + + guard(mutex)(&epc->lock); + + ret = platform_device_msi_init_and_alloc_irqs(dev, num_db, pci_epc_write_msi_msg); + if (ret) { + dev_err(dev, "Failed to allocate MSI, may miss 'msi-parent' at your DTS\n"); + return -ENOMEM; + } + + for (i = 0; i < num_db; i++) + epf->db_msg[i].virq = msi_get_virq(dev, i); + + return 0; +}; + +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 num_db) +{ + struct pci_epc *epc = epf->epc; + void *msg; + int ret; + + 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_epc_alloc_doorbell(epc, epf); + if (ret) + kfree(msg); + + return ret; +} +EXPORT_SYMBOL_GPL(pci_epf_alloc_doorbell); + +void pci_epf_free_doorbell(struct pci_epf *epf) +{ + struct pci_epc *epc = epf->epc; + + pci_epc_free_doorbell(epc, epf); + + 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; }; /**