From patchwork Tue Dec 3 20:36:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13892938 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2067.outbound.protection.outlook.com [40.107.241.67]) (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 A6522209F38 for ; Tue, 3 Dec 2024 20:37:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.241.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733258245; cv=fail; b=a5IgLw9ACPV4c3VPORhJvzXDUpPI7i+B4szMASlR2sqiT7x+2qioEzxrPPpsKHm9MpEQOTQUDDih8U3KJ4pDOQe5aVMm6KONJbLz206tsxsxppoRz9Q0tfJRqfIFUKrDqBapsFyEDb8FtT5k9tHVxMXWSYVNwGjlG/FlAvlr55I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733258245; c=relaxed/simple; bh=CYzhaaTxCf0bfjgS3xeE4SAfmPxICO3mdD1dysE5nTU=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=u2GySaLNehXMSlXTpDXZojK+DwVhVkJywuYbwcRgnqSjtF78D+ttyiEAT3NrgDrQAD8Y7jof63G/hnK9j0QuQFCj2Y+u8hDjyKnJcLL0KOo0muM/quRX1temK765zWSg8U55mb6rWnnta6DVU0aYtArsnl5Wk1NdVJN2vy/Iga0= 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=eO5yCdF+; arc=fail smtp.client-ip=40.107.241.67 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="eO5yCdF+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tx1GMIzWCp9YOhKrYJG+n/8vta/3cwPZTcM3KdA4QkPes+2+qbDMEc/I/U2Poga3QQUv0EswXijWCdJ5Ga15zVvGII65nbu+9z0ZATnMA2kEglU40rQYQ99vBX93Fa53s5s6VO+8GJ4p6TEenCf4FwEL/5ZLIpVrRQB43gAt33Nd4dzPSzN3ZYipRTk+vwHxdyhyOhKfriRYU1PLvnmPFmOxSOvRJ2BwKprLHaZoVuDCD+kIjjvmDzDCqb5UDowTyfiClx+TbtS2uA7LwnveCQExREPlLm/aSrDHJoZuMF1pIda7XYteVDguFnhtYObdUwNWSHuzYXKVlGVJaCgFLQ== 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=Qc6rNEIOQHfLuONmH/Q5URdGsc82rTkhcNlw3A3hyEU=; b=wRvJizvCbepdDup21Bn9VpF1RL+2fM43OHsG9jxDXPnniKejuSBlK64GM6A9YheeLTrq1rtqoQ7O4gDpZ9soblzGwGB8YJW4dWb/m8GPns0jfveeaBxJymL8b0GW84rA9ICS1+/xQpCv6h4U5+FiNWbmGBJgnvhezO+lpJMKRRVifvMEY3ppIw1m+aci9eHnNKcPloJ3QEn/esRwak1X6K2LAlaD4dweJy6rA1nH5U0Spytfqs46H2qRRYczn5kpO7O5DCtxvdxwAvBDKlmXx4PCfz5Mr2BrCcGSP5Mjx9FgxSYEPl/j74SUb1ViuhnY9PWw0qhYo+7hAkhpCFmohw== 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=Qc6rNEIOQHfLuONmH/Q5URdGsc82rTkhcNlw3A3hyEU=; b=eO5yCdF+QdSToFJ03imfzf099S+YF8g+gzl5yAAiAyzbXxh0CNuo7puQFQ8XLBFoqZeb7khAvhZhwaWuAOiOpYRFRgy5vWFSMRHM02Bxold6Kz6V6csIcZkzly8dkpM6u3xCfNcXyNnz4ndX0EEIthcaLqUP498XtJ149WgGq/uxG6nQ/Pt1xmkHU5S+2fJVCwAxin1lq+7V0DlebpiYly33CYKvF2Wrb5K6tQN5DwvMHl5wtegGeP8t6lf/lRNg6K8Rhq63d6Y3fx0w0BKH4VNc+o3Vpxnpn7u/PQU8bA/XlS9uB1dtGxv8Jw54fwRgoc5hthdL63kQlPoTgK6nFg== 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 AM0PR04MB7108.eurprd04.prod.outlook.com (2603:10a6:208:19e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.17; Tue, 3 Dec 2024 20:37:18 +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.8207.017; Tue, 3 Dec 2024 20:37:18 +0000 From: Frank Li Date: Tue, 03 Dec 2024 15:36:51 -0500 Subject: [PATCH v9 2/6] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Message-Id: <20241203-ep-msi-v9-2-a60dbc3f15dd@nxp.com> References: <20241203-ep-msi-v9-0-a60dbc3f15dd@nxp.com> In-Reply-To: <20241203-ep-msi-v9-0-a60dbc3f15dd@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 Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, maz@kernel.org, jdmason@kudzu.us, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1733258225; l=6716; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=CYzhaaTxCf0bfjgS3xeE4SAfmPxICO3mdD1dysE5nTU=; b=7Na5mclwPapwPDJLqjKuUX45flvuWvukbKCw2Y7BGCgWFsNBh/D0BIF4MVP3TSPe/RJRSwTCd IJdXngvQQ3IDGpRs9Gs20sSi4oVsrARSRkzzsUOQHRQEhX7G8tOgAaL X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR05CA0013.namprd05.prod.outlook.com (2603:10b6:a03:c0::26) 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_|AM0PR04MB7108:EE_ X-MS-Office365-Filtering-Correlation-Id: 51b6b03d-6a20-4aa3-5ee6-08dd13da4767 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|52116014|7416014|376014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?gDRc8UapCKmBuQA7ZTGpCoE0MAljvNp?= =?utf-8?q?K62yxBD6vruuGaUKT9FvDdUuh9LwPU0VLrkKSr75aU8urzjdvMSoBqaGsLi5FN865?= =?utf-8?q?dBNMSmUgDmXKrxKxEzy0D0N4nm384U6KyQ5K7cLO3hGTxI48hHHaymBzYDUSN4iDz?= =?utf-8?q?kccyPeW7MzUWeEimHMgo+2PYOUg/vDsy+9EpPKXA9zkpxM0PCfNCt5xY9dQbhK5H6?= =?utf-8?q?CUwqqh/yYg9z/kpvJc56BQCUBCvyKmunWKXzdmjfNIwduE2BBTOkQoG5/BmoJeMIx?= =?utf-8?q?SDz7E0r0YyG1Q1skyOk/ZaIikgwVic6e3m2kqNkSXLmkSi2nHf8G8kQ0Hhn8aPJ4J?= =?utf-8?q?IneX9pKbOkKOUcMxTewOLtyFNBSraZN6smgY6OSi6Ol4fd6+J5GilC664VNzrrlaH?= =?utf-8?q?+FCwxynxMbEnQ9EplSiMKPfqyrlw5nsj7/dtKZ7v+qW+9dvCes3PanZVm5a43S8wl?= =?utf-8?q?udefcUZnwcei0iN5ZdW3BkC4lLhECIb4Trja96PanM2VJsn3Ps+AApLtgD6iw30fG?= =?utf-8?q?D7FR/MlEFD166ijUrPCl13nJNsHFEoJGRJeQ40nhXJEbXVOfd2Y1v0CpNSDXgE79c?= =?utf-8?q?za8Kl26VWTh1R79thrTetiu/rny5uragTKam+MFSNPwmPR+95xAZtJiwPhxS6i04V?= =?utf-8?q?LaEvjy24tZQEbfuxPLWbhwYFh4saDOMYgPBkJzGQ2jiLO85BPiJFUF8RY5sSZski/?= =?utf-8?q?hJj/XI/L2A/rFVbr36uBWVRTrX3dypmIl1DGBdilNf1BOvs8fGPpiXDKFTEtLddyD?= =?utf-8?q?DgtcebYexG5g5jVNZf/kUF7Lxm4OKXNN1hzGEoAxW3ntOva3njfrhcq5fN6LgRKJY?= =?utf-8?q?92mArWIiHz8YKPRHRa+JleTT6ta516b+qryft4l5xFtvAxk9lg/87ozS73g8ATeWT?= =?utf-8?q?jnaI962JrEK6bQhqo0Ui8IbDU7sa/RIjrTXo/fXNIXDZUtAanPpAqtP6qBMo1IjSU?= =?utf-8?q?PesZTem8IcMBKEqwyufbP0lxJv2B5Z7AbH46VnOBGHQqQtdKTs8YCrz2r0y38Fubx?= =?utf-8?q?bqAdBj1snTA4T0gOtFjskRawRyi31Nr4sTa+NoIZezfLSghE4pT4DnONTWfSk9A8Q?= =?utf-8?q?FcNCVNE2xav3kF8q04gLBq1b9HxgjJkfdHqwWCGfuIvPmjx9DDF3rDcLyafiMBzKe?= =?utf-8?q?378MC2jUb/WGOXNHwe1ysFh/LtGWKQGZuQHB51dOx9o3qHLrMUzF0fM+X0VbNFmrL?= =?utf-8?q?9RcIK+7Mgt3g42f1Kc+5oTqi81W5ZV7BPaXgCA4Lpdfgo4AGG6D8hBAozvemdMhNd?= =?utf-8?q?YO7pl1fbcoD5F5lvyVEpdzRBRDRknihNIA73me5zI3JoH06Gq1WVGS35fc3c3SWl6?= =?utf-8?q?nSUenhPj4Gtct5azT0402EOU5oTtQVAmFA=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(52116014)(7416014)(376014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?HHH6vJH6xZC/v3hxwD5MkSlWN6zB?= =?utf-8?q?NOuJJOAXrYFALcYiq7/MRT0LeGBj1Pj2qR+xJYn47+XxnFZJw8YAfcSi5fBWF5COU?= =?utf-8?q?JMObC24s+oiUk/NDHVV8a9V7SfWRCb+cV0Z+N45D15N9Yn+tAwE60YfAp+qj10Bte?= =?utf-8?q?ZAcYYbjxShK2cYBuTvtqPMKsfx6qzJVlY1eI2wT+LHLU0GqRzv6uA/ichzZOSQOLe?= =?utf-8?q?W32QaxtBMs15ONw8D6ow0Tq+j7gYM6fvK+JEKkaC8kZowm/aEvzMZt6Q3OuiYIrpK?= =?utf-8?q?z2OXd0w8XrmTxGJ1DAuiNFX4UnzjWIV42xHs+gWjU+v0gO7OLGOGV3pEiFjR/8BKb?= =?utf-8?q?9O1Tea2u8eEtzba8NQZXoI0RR4qnfPQas0Vh69VszA7wb7x+mOVs7juFL2qdxWhI7?= =?utf-8?q?RG1tEUjK9+BRbZyS3a3O4bNtxwNiPCOJUex4/aYGN+kzJC6TDS2lJgheWd/tJ4J6z?= =?utf-8?q?TCkA7fp9om7fY502fSxYwY1PA2AJst8/xAxUMeFR1PkEJyiJ5GWodFPvzu83hT2Y4?= =?utf-8?q?bQl/q5GVKItZFns1mwU+yKZIwczMDLMqQRoX9h5BujrLsabql4bfYiFjvyC46I0V2?= =?utf-8?q?Oq7YVvN35JXMFVd3cxkJ/Un9TA3BwiQFt+jaUHADe3Yd/rl43O0wRkAuUqmi5Ed64?= =?utf-8?q?xCRn6wLAyjlJ7NKU6ciDW7rHAPoQMOFavvd5dWbl/yFtujBn6jpgVDIC5GXHSmWkm?= =?utf-8?q?z8vaYv6uPGdiQw1mbmBXrnHI5jYVtihYyY0xT9fbAve+YihnlY8xSaWNO1hdg6Us5?= =?utf-8?q?m+SyOC6bkaHE8CudQmJSzjq+eCgUVNmfEMDeAamcdW9Udu7FwzpBhfj9DN3qEV+H8?= =?utf-8?q?irMz02hbRrToWYnwKsYH92N1k0ki81V5EiOISNqMbTOzyPR1CkJ7c+6kAMXdiXpzv?= =?utf-8?q?7pzd3LcBNNJMwf6s+FK89cuhPEKlfqSMrtYU30DE0xjREt50TqLDZ1u98Q8MwEzwh?= =?utf-8?q?R0JrkTuY5aedDGIfSMuVowyFxZThFUCURqEzVG98rd07qjUCVhgCZZCfEXW6RVpPs?= =?utf-8?q?8zxyt+8nMlkAeXjAggddoCTpqVVm/OM93uaqGLhT5/27Ijo1Yan7G+gtrrjaBNTFh?= =?utf-8?q?qk8hadM5zdLpUoVzG1gD4Bj0SziPo9ggvmhfki//xBuHBahY7ViIhBZM3aytsdzfv?= =?utf-8?q?NwRqvXQe4sRD9NJ2gtwiXhrb8r28RlFTobzzTz3E57cY1Sb6YLghZQ8yjsk6ZAEEl?= =?utf-8?q?y/sz12u1gbs/XhH3a9V8fSuxDk3HasZkAtznDgm2F/XGCEvAGPvLFYsrf/FP6TH7+?= =?utf-8?q?26EYzYloJQNbfZPfVUhTxJig/8huTFkrNHupdA0subfNyZ8it33lo4bQ4jd7m49Pt?= =?utf-8?q?ajy20iEg1YHMPzy+q325yDro90CfUgph4Se2Dfu68Id6XBE5qQnD1mHmkfycpxWYL?= =?utf-8?q?TVukUTjoUJdfXN668AaAj5Np/XgYWG1E3dyV9nBVlv9ePcJ1sc3MOjwazeLt6OpqW?= =?utf-8?q?E9v8F5UgePBW5jYV28M2UAEVFEvATa745j8xfJFnbHOlb5Z87dCqtvSw=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51b6b03d-6a20-4aa3-5ee6-08dd13da4767 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2024 20:37:17.9120 (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: 3smYZyPOqBZVc+eaTcNBEWOFg+xrUjCg4jwNep+YIBNHaodUWo407/meWnBnQjQV/JVVH0ucnqOlYC5mBw6qJQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB7108 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 --- 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 | 106 ++++++++++++++++++++++++++++++++++++++ include/linux/pci-ep-msi.h | 15 ++++++ include/linux/pci-epf.h | 16 ++++++ 4 files changed, 138 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..8f92f447712d8 --- /dev/null +++ b/drivers/pci/endpoint/pci-ep-msi.c @@ -0,0 +1,106 @@ +// 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_epc_write_msi_msg(struct msi_desc *desc, struct msi_msg *msg) +{ + struct pci_epc *epc; + struct pci_epf *epf; + + epc = pci_epc_get(dev_name(msi_desc_to_dev(desc))); + if (!epc) + return; + + 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)); + + pci_epc_put(epc); +} + +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); + + if (list_first_entry_or_null(&epc->pci_epf, struct pci_epf, list) != epf) { + dev_err(dev, "MSI doorbell only support one endpoint function\n"); + return -EINVAL; + } + + ret = platform_device_msi_init_and_alloc_irqs(dev, num_db, pci_epc_write_msi_msg); + 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-parent' in DT. + */ + dev_err(dev, "Failed to allocate MSI\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; }; /**