From patchwork Tue Nov 12 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: 13872701 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2050.outbound.protection.outlook.com [40.107.20.50]) (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 07C71215039 for ; Tue, 12 Nov 2024 17:48:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731433728; cv=fail; b=QLpeKrZvHhd3hRfHZ4LWaqESEcNl3Rmgo9xiuNF3zsO9Qoc5HjooOEZIunbPEfPRKzoi9XSAVf3fMyfG/FL1YXePKLcnQorZdw3DQDgnInlNZ9f/HtLDICfsuFopIVFAxK6n/8ltjC2kvxTrN+TwOv7T4bUC+/AD+mDHcoBk/8s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731433728; c=relaxed/simple; bh=YT99E9eq13FEX+qUFaoGejBUqS7EaIaDgacmztfhmnw=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=ODQ0IzlL/jbaFwT3sZZgk3EBpUIvulEmcWIMYurZkI8oyW00FCkaKJl/J8iKvT5EnljZ4cCdXqnyQZ70mmOV/FUtulOFFnvFPPC0lUGhDDjca3KfM7T7mW0brLpd6QfP1DdlFfsD2926ydzzYY7M0/ZVkKp6sowyzrH/+qO1fPA= 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=Pyrwu7vH; arc=fail smtp.client-ip=40.107.20.50 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="Pyrwu7vH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KZAjuLdPctdELsZH4lR0hr+bbPx2MAtRFru8O73t1Yap4rMc9LLLeebEBGJ9dWpUtJ52e9G3aqcFai3Xx12PA1SwbIhMpPa6e2HfbIwU2kJwfM0jutS3a1kl+AVJ/cobhU/ZLUovBpNtL0gWV7ffkP6/yuqqjOWSVAUaYRsMG9HN+NzI/51O081+DhaVG8y11NxVXQRm+hGB1F5VJCWzl2NlZHIaJT4IO7prmqKjEbr97sJTIMxJL9sJ/UkdkoAXxGKMDSvfUn1ALn1uT1lTivRtimEFVa9xClDruzOgIpX9m5jFLz1nUtjzu0i/p05PFu8FBBErAkhEy3folbgaaQ== 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=0C1f/pv6sXoxTlSc1BeTk4SRqkS6VfLm5JtkIQZDNKI=; b=HGijjyuYX3EjDmNExNBvLGDqvEHijQdZYIuIsdyBYM+JlwyNyFVvIZf8ekVIFsriFXQVSQ2owOF9ONgNgDV8lTnZwoAoHCnZpAT/TKxRzV2aMJ78NUjR0B4YhIxegU5Ns1j4qPGTiL8ZIe1w+rpn+RpKrudaZ2j2EasYLg27wlmtCbrLf2sTApyPcg4y4l+0WQ7UwiZZNiz3iFgqnQFv1OO9DpAE00m/QhvD/NbkSmvVBIXAPBruFn0esnsq53Snw3der3YDPXIvdLbOmm0KBa3TDYlaPlIbR+MFs8vBGOFoe0frR0YZfNm2c+fBzxXcrbCzEbesc3WCPLfHoK5H3A== 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=0C1f/pv6sXoxTlSc1BeTk4SRqkS6VfLm5JtkIQZDNKI=; b=Pyrwu7vHT6SQbsoWn27SSPf+A3Qy9NkOAxMnL0YHWdhmTopBciuLnWZqsIgeXZyX5zoX6zGy+GjrNVy2AeZDEdfHzsoIXmQsc4A1wfvanL0VXb7RbI/3FxWVqnQRjBqETzkFUItpI5Casn+KwKX2pKxzPafnwxeqAYZE8EPMZPNCJrjHLyBYoAPHzK3NNiXbPuoMjygcU2Eh8v22VXPBqYTNje31OJoDsjdT+H0smg2D02CH7M092WhX7c5rclML4cYoabg2vYXDzSzmeEAE1Iu+Sy3wB0etJCL7ak4iQWwY993jWJWrub2IaWi2avjlMlkDB2sRkSkelO0eRuwZyg== 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 AS8PR04MB9510.eurprd04.prod.outlook.com (2603:10a6:20b:44a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.17; Tue, 12 Nov 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%4]) with mapi id 15.20.8137.027; Tue, 12 Nov 2024 17:48:43 +0000 From: Frank Li Date: Tue, 12 Nov 2024 12:48:15 -0500 Subject: [PATCH v6 2/5] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Message-Id: <20241112-ep-msi-v6-2-45f9722e3c2a@nxp.com> References: <20241112-ep-msi-v6-0-45f9722e3c2a@nxp.com> In-Reply-To: <20241112-ep-msi-v6-0-45f9722e3c2a@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=1731433711; l=6297; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=YT99E9eq13FEX+qUFaoGejBUqS7EaIaDgacmztfhmnw=; b=3G7wSUQ8lVrRXb76K5hYxWOK7cOGMX6K7i9qKqWPomG9g6fOex46BZ9Dk8QR0E7s+K0JR3lpL +lTN1oCDqjmCB11vht+gh8gERaJydPQKuyuwjLxlpjt/DWiNYxfSNRh X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0076.namprd03.prod.outlook.com (2603:10b6:a03:331::21) 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_|AS8PR04MB9510:EE_ X-MS-Office365-Filtering-Correlation-Id: 41a15fc5-a550-43b7-07ae-08dd03423fc7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?45tbRQNyCrI4Mm3elpSSFj7zx5cE9mP?= =?utf-8?q?7jo/VYTUs/EsqoTaVtXLr8QyFEp6WoW/weJ9AxrZytglXRp47+TqdwzBVKrgSXiOq?= =?utf-8?q?T1WiB1a7nc0I/H3ID51B8iicR3BNGzZJKCyv5gC611oREDzh4sVlWMNOHzNcny7yw?= =?utf-8?q?EGuoEynRQgEZZ94vkJ+SX0lkYaBHb39aeMxjLihoGr/ebxy2bwCHLOJuWSjHGAUfL?= =?utf-8?q?ZjNE8kl1+ubJFBLth/e+Zya7mkc4Qik5qyvVa0Jvo3rw5LuP+aGA/ZZtCOjm9sgw0?= =?utf-8?q?QiG3zYaZZiHAxpHk5YUuVEmlYkFfWWlA1narIs250+QlJrJLjXleu9TJ9eKWKHxN9?= =?utf-8?q?jtcAbWwvgpdf3Y3mk3Qy7xh4bkPYRYLlZOmg514rik7fCXsTCxcE0RE9OceKCI/zY?= =?utf-8?q?1UxRf8d+w5SUbWMqvX+stXNZWqE+H576VN/l5h1FQ5thgc0KT5T3jfssU8EK3LLPY?= =?utf-8?q?iWXeb9+NaMboYDwaGVq/zdecslGmHvMprt0iFOXVZ6Njnu888/RH6dSG82owkLAJ8?= =?utf-8?q?PRmHuwWcGsF3mRCIucUczzYTWxpB6lCaiErTQn9a4a3wnPuFRUazh2+NYjWHgCEXS?= =?utf-8?q?YNTMtCiUcxINT9qIkV9Ymr4oOGUukj1rlPNVwDc87VNageWWKrw31Ce4lX0OdlkmM?= =?utf-8?q?4Xu2elbxqCNvJ7JtjkuVaqjw4OtW5XQ65UGMdKZv4cG2/gWoRWOVryVEUiICk5dQi?= =?utf-8?q?t5Rp8gqhPyiibVxHWoiucXvozJZshrZ8+FSJjXMD4wpifELH8VcWL/NVbhOZVAm/t?= =?utf-8?q?rLoKVOYd85Zhott0irwK04hIDk5Wv4D28ElNvSkJc4E2LHwNPye0d7lY/IwUOCO6i?= =?utf-8?q?c5cm5CZakPem/g/p0ZAPs2k9ViLLyRSP51cIAXNE2jBDFC4c+lTtxCRR25q9M4cUI?= =?utf-8?q?VHPfT2V8w8HuKew1vuiPVd7kwnVAE92/jI/ow+Y3zN0W8BNxqONiGPhNoyeJDkQVW?= =?utf-8?q?qcpad7wyz5db8SpTNZWyhfnzbti/R9M34E8OGdZFSumka+FXw2Fhdu2q7+gWAbf1l?= =?utf-8?q?QgFreaWxfPhMl+s6S37JYvuu5nYr/VsswgO0nyeFBWvHK8kah0NDrNJB3x/q/Asvx?= =?utf-8?q?GWqiNOM6OgF2GzhBblDnmt84B/G0JaE7XVehOYgHYVXseOKJdZqK38TQmSGfBQDWk?= =?utf-8?q?BCk4TeEoVhn+EerG9u55wKcje8/ga+PPYypjUnmGn935jtNYCdVoSCjGyy5QcwSqo?= =?utf-8?q?ZVYjOp52n+myCNeXZ5ue5n3mR/aC8xLHij2Tzw0/OSMcv7cBuGHr4cd0YdNuawikt?= =?utf-8?q?bl9Vsolku6wuyTOVoSTjGFxAP0d9mIu/DNRcpeSH25ROG6/8hZZwadVw=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)(376014)(7416014)(52116014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?3t50EB9K2xyYA7rN0OZJIXpRo4Bg?= =?utf-8?q?FDiDg4W0CLW9r5ih9ysX44hQ5xlklrUFUP3rcHXTRhBM+OTXn+FTApmujlD2cKe/J?= =?utf-8?q?IWWTa80IBzy1BA9Y2rcZggu29rlzg187y8NcprN/b0xhB6N//sPQuY5yVx9tQr4na?= =?utf-8?q?hFzbgPM+RV8KCSJ5UPDVvaQWsiJkrPFpbZ3GvQF7tSxMbblmwMphyi7S739zunr/C?= =?utf-8?q?kMaTSdKvLn0NOGsmTMQRyqaxMMQoBVlg9LaFm7sGv/agLs42odC5vqacHat6tdzGP?= =?utf-8?q?tG30/oMzvd61LLqj+asUUKVacX5olhUzC5xGfCI10cEm2RlrVnNMfsHuPj95NquUw?= =?utf-8?q?zy0kdMZZ0oqkPKmOOvtVGMuJB4wYiLA+mYBTWkW6FmuRqh0DTzYP8jrObtEwpqmuF?= =?utf-8?q?voaTs/1fduWW9MurnZ4/TuFQsAIbd7y2km0poay8XF8+uPAKuQfedlDUSt1X2n/ix?= =?utf-8?q?9yEHlPeysRT6tBZVfUsbUbAndJrQ6dqO0xlIfy5+9N/tJ01eA+xY3QchzRB7ueRWw?= =?utf-8?q?KuCaSvTNw6C6fevD8ChbCl4P+Dr1gUSsCfZKgvDAJCVlio80oCFXBGQg5nemhRt/I?= =?utf-8?q?LntgmeETQ82JO3TkrH64TNw8OBx1GjeVWwXISSNljT8zissp80TPXfPXGRe2Mq++o?= =?utf-8?q?LL873WzGB0T0/XngFyuoRGXOufSgs09ozvgiRXSlaHZH4wgtygpux4KUdRXvMwvEi?= =?utf-8?q?Aktw2Vjs5Q2GLCDmYl/6se2R1RbnX02wIOhfPiyvM27MhaJFcmxVjVA1Kn6NdlSol?= =?utf-8?q?6LHsyzpjm9uU2JcM+LNFCLK1ZH93RKMrna6i3giY1dQ1Pl3CBcFnlYyXTf958gbsU?= =?utf-8?q?y/azBi7gySJWswj/U5jbTN+bO2CtJrYrKD8ynqf6OZSYRnMHTxZLBpeesrvsZUu5f?= =?utf-8?q?bRS9VzTIjEeGjJns+ZoIqh4v5DLwdFFJ4zjatEQjWEKL4VJVXMZ5eQPb5IrREl0D5?= =?utf-8?q?b6cRQgSuvm0AQATWQ0mXh3b/PNxNZyWr1oGCxi0MPBzdKqu+zVlubNYXvsbQfSv6q?= =?utf-8?q?NIdP1cq2POHNU/sqHWfvjHtLGufFwAKSr+kG6C3JWCRDDDqZDHKTGCVDUioTvaGQw?= =?utf-8?q?Lj18HkQtjHiOJ5svRCBNf9tsTYpsKOmaONQGrorugoZGQcqdWIcHQ/eU2LHObAf2o?= =?utf-8?q?EfXzxMuQmNKUIjfy7op1UhLLNoD3qzFl4UZTaL+HbdPJaNpCPp5jG74t0Ms92Wrok?= =?utf-8?q?NIv8BpyjF+/vzFwW61J+mC06q3jaFxAfkoazwlPSdjeK2PxmPqZnVa62WMjGW+tOT?= =?utf-8?q?oSkxU855jp49DY3kuMbwiEe4IzarWixr0zl8zNOJy9nBQaJRxzyvzE5yDBY7pZBpN?= =?utf-8?q?GoQJZfNci68hq0Jeiw5Hd5Sy3NDMT4fwEcHuncuHdqvlTEPf5uvR6IOmdPCXG5WJ5?= =?utf-8?q?Knfd46m5nn8ioAGJms3T9T00c2fLphm9vWh3R4oz1qoCL78gL6x0KEwcFdVwpBDgK?= =?utf-8?q?fNYYK9usaKyvimtpxLBH4RroF+oUMW+F9H80qffjM2tg5FKnlZVrVN9Y=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41a15fc5-a550-43b7-07ae-08dd03423fc7 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2024 17:48:43.0516 (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: 1QZiWkSYEZ/Qq1DiMO0HLyfBes9+5ifUZtFYwHkhXqUHJER6OwZk27hOgUj9c+5LBd8JSvSrwvxaL0IBLwjdzQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB9510 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 v6 -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; }; /**