From patchwork Wed Dec 18 23:08:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13914247 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2041.outbound.protection.outlook.com [40.107.20.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C99B1FE457 for ; Wed, 18 Dec 2024 23:09:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563371; cv=fail; b=J1B1Y/sOq5x4nYtg2iC+BL6TTJudAy2NMMnTXiA351HeeHwTMkgVWeZaMlFRT7S9uBrSYOam0g4+IHQToJAQZnJXjkS7jcXIzibHzjjDfqE/Gz82CJL/lvgos+9Qj7JCO+d2OuuFEjWXfKvBIy1diPjjSSQQG1mYfbp16IlduCU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734563371; c=relaxed/simple; bh=WMSa85DyIKk5/tdaJfRJ0u1YGaIJIzUsaDVlLKYUQJw=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=j9yJdEmAXmGNcXObTl94N25ec8K/3BIqxap7++yysk8r76GZttiND5gFzkFFkd4u23ejeJMZA51UdBCC+Wse+SEQfBG/WAMzVIH/UFqGEtv/QBwGCL8WfnKq3keJFDjEGXZsjfMgRb9OEI/wNGpioPM2XsTqjxo8HuKdmeW8YPA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=DWCs4eCc; arc=fail smtp.client-ip=40.107.20.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="DWCs4eCc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LxyxAMaX0raiZBEuLZqrHMxYyN7AIoIv5Xe6F2RS0BhEdmKAbOEBLo2WluGCf3fIC2t8vA1oJV2kWWapgtXq1OuZEMN8BwT01cE2oQJ+6ehpVGlBvvbV4MCj/gtRdNdqhY2ok0gS04+051/PaVij5/cOfHCd8/zjWUSIO1ixFmWN7VBIyohUZkJNEYHMIn+4Dx3Argo7gJc0dEtp4CnuBnA5YEsmoKoq0HdrkRvKH0iJPLyvsmHLMXYWbwhREb5OrOC9uAS9moopyPgAqaFxZ2NPMPfq6NkTAj7gN+OPQsSMwQTruXs6u+6RURaVzbjIX4jxko+9uUslttsf6sic3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FY59PU0GNRFhFxBLb2ptFRe692gLTht110jB5MwRR8U=; b=gahCxM1vlVBCMvuURO/s+0yEaBCULUxhV01Q/7Hosk1lLq8SO+86x07K0n0X9NFCCU1OOPI+ZS0lqAH8YZTfhgLKKPNKZGKKdjUs3kRTRpzgbVsuNoIMlUGLbSUlrSfg3PN5zS0LssHa6a2e8OVUVtyfLgqfino0xgCpGbh2lapDO//yJPZmjKvtpYkoYRYIsd5WKfDQKjUMkyCxBNJ4u/8LdT42WTgn84p7Krx/xZUI2yI73gVtDJDgjg3rj3lqQEk4mwF17hmFm9RImAccCUt2K51Em4vCRojUmuOwW93TG0ahq3m74txDzGokIN0YwoEm1Dkf/60MaY+qSR72Uw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FY59PU0GNRFhFxBLb2ptFRe692gLTht110jB5MwRR8U=; b=DWCs4eCctgOi2sZM3eMHvIVlMlKumoHQeHIlgF9K76aiWiJgoImViIY+7ZfdOwQG44OXBXw0RUitQ7dmcJRxC11IWEymQNsLQOOhJLgcGPtkMC89a8S2rmvlK6vmJr7ha++ZuwMGale9u7hyfINu3GxoHw7l7Z3uo/ofSQgIZHjKzSH3BFZ+niXXGoaSpydVu2imbSvTJPj8ji3umGLsF92s9vOBHDUJjAFMCehsCt3S3Op3R/EeN6f/PT39lcVqBzcNe7i3U9VfFqhLd/asuvh1adLBvOiF+iZQcHE/rpFoTQy+HpEbREw8S/P0bi04gVi8EKFX8q3k1hUYk8GNJA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by DB9PR04MB9939.eurprd04.prod.outlook.com (2603:10a6:10:4c4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.22; Wed, 18 Dec 2024 23:09:25 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.8272.005; Wed, 18 Dec 2024 23:09:25 +0000 From: Frank Li Date: Wed, 18 Dec 2024 18:08:40 -0500 Subject: [PATCH v13 5/9] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Message-Id: <20241218-ep-msi-v13-5-646e2192dc24@nxp.com> References: <20241218-ep-msi-v13-0-646e2192dc24@nxp.com> In-Reply-To: <20241218-ep-msi-v13-0-646e2192dc24@nxp.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman , "Rafael J. Wysocki" , Thomas Gleixner , Anup Patel , Marc Zyngier Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, imx@lists.linux.dev, Niklas Cassel , dlemoal@kernel.org, jdmason@kudzu.us, linux-arm-kernel@lists.infradead.org, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1734563338; l=6819; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=WMSa85DyIKk5/tdaJfRJ0u1YGaIJIzUsaDVlLKYUQJw=; b=jqLq6ZrEIqu8eczljjH4I0jmrLY3w4hnwATqHYpITE2jw5OFWYmkHvPFgLrGbXucIftzD6+Fw cDCD54z84XGCfyXHVm+23MeYkzZnf6BaER74RM2V0gEWVeHQXBlEj3z X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0075.namprd13.prod.outlook.com (2603:10b6:a03:2c4::20) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|DB9PR04MB9939:EE_ X-MS-Office365-Filtering-Correlation-Id: a110d0a8-d652-4bf1-371f-08dd1fb90415 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016|52116014|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?TCU/7oo/kJJCBMfPmIxE4MRBCGm/PiJ?= =?utf-8?q?holdm44UUwSM05my9Cw+uB7sfMAE/WJbqR/eZpkqVX31BehGfIwHHtBNYMwfLJ9p7?= =?utf-8?q?HanGLL7y8bhM2BbgcRzb4flh2AxFvc3i3BdXL6D5Mz5NiCg/zxV943cy2nH+3hyg/?= =?utf-8?q?zkdwUhuglk9pBe2MSKqeWPlEMjN5e3vJB1v2l9syU3QTAy7m/gv87H2qNAGrIYDxp?= =?utf-8?q?jTERYhvcQPXB8lD3xzmVEnx9SNELvbTvssPb2g1H6zxI3VJOy2xVNw+jwtNygP1KO?= =?utf-8?q?LjeYmS2ArV5BV7+KWeLYGoLDGcyr292uyV65XDU5/Tblth9VJiIQzufduywZfTmHQ?= =?utf-8?q?LKMCDe9ne4qfLk4+s/h6G1O7urcbBdHAj9Sw7t4RjZ5hqlb4qAxAhSlXvOBPaVihq?= =?utf-8?q?XrK9JwRqHNevrK6Yz2CzRg05+cFEs5NMtg6m/iFU0ha3ZFOZ1gYhhMarMG8B2O6HO?= =?utf-8?q?Zhv1+rcQ3Keoo4k/ISHMFUkhoJSvAft902D6FUMH1PcO0ZqWKt/YQOKCoZ91kugGD?= =?utf-8?q?XktV/1i21zEeMvGlfpUXROyIMDYJiM2ZtOieYU6tJWf3yo+qwkBBCeztxdDOj6LtJ?= =?utf-8?q?WuwAJ3s1KV6oM6syx0teNYn9eJE1sbRO+aXnRk5C+f9tYUItz12DKjl5ekjDkgGbV?= =?utf-8?q?mHGxpd6L6sU32xy75cO14fKOjcpTRwxJ+Y78cgpuF/HRZDGV/GUtuXrUTxSkauNDH?= =?utf-8?q?1KH3UyGoIs4t3730yGClSF2LqP/iPtd6ZrOYV5umnYWJJIAnx7YGbQYxNOivpE9G2?= =?utf-8?q?ho5AM5iqSDT6ltCjQ6AJ/GO6zMNj8g5QO3ddI15ib+UISDvT+jZuyRb9rthRNC2id?= =?utf-8?q?ErbyxOq0ubCD7O6zkkJ2dXXzjwzBKESHXCi53JHXshpKP8DIb+j08HJXPz5s9wiIH?= =?utf-8?q?pE3uTv4fyTxoRHiGEoqwODuutcickCvRioCMdijNf6QhNOGnhqWb0AkENkQqzE7xC?= =?utf-8?q?3WvL5vlmIHPrgCMAVE5e8SZX9NtmUcFEc7Wbp4CBB+1K55KMnuSq86sJullH6CggH?= =?utf-8?q?tDPAHxh62oKzNTUtr7af1vg/Pwm3GrxK5sBNg3LlhawtLrHirXlJcyGmGQSaIOd2z?= =?utf-8?q?dn0xS1IWRPTaMBsm78FbBR1UuNqwIBMz6Njd28RzyBSVAOxbkxQ5ZDvWLfpJF6Z7/?= =?utf-8?q?jwEePGFkMssUL4sex5lCBKkquxmefvk/gBX2Cn/70mJoawY/GwgJ+XLmQGBr76/5p?= =?utf-8?q?WboFIOcl3xWW0FdnpM78RWRVxOc1gqW8hqFQKWSW2waAen97x0WHBk+sAx5MzSUfX?= =?utf-8?q?1D377s/VQUAp8WOUpqLlmCjZ4MryuMb5xp3YZQt+kQjoPA3AcHc+pFW385C/REBWQ?= =?utf-8?q?zH+e6AYkcu9UIqVK4+jCdSGf9gKYb6d78myy28KQRcgQVDR+lLhsoAoAsXVXXJFBZ?= =?utf-8?q?Xln27BsUWTkLmPpSAMaswzbj3uIxsigNw=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(366016)(52116014)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?QlaynTPwqO1vJCVTfjpL4pt7AWvV?= =?utf-8?q?tXsPzRc4nPUJowmNxvcSf9rk7ro8hOiPTwGgdhtkBM7mmgVAhJY+m7XBXPq2Lg2Wu?= =?utf-8?q?B/umN4jV+iXySqj9U9zF4JfERDAamc8HV/KCySjdArkie6g0DFz1SeuJRR3ZLPf5v?= =?utf-8?q?dowIV2TyFcw2u+KNDhbP1LKjyTXuD284ZxXVB+R80Qohf7+/bpY/0kLJz0kZTqz5T?= =?utf-8?q?diquVmTZI7m8ZeJAxZWb7+dgiNwxrB8tDIFR74eo7xv88EC/gi/vfRzXbMJCeEnQ5?= =?utf-8?q?yP+xGCm6T2UGCMGWh1b0gbxVxoCbBQIGyw/wa/Rl2FQcr8S+6rr+RPhdPN/wd1uL9?= =?utf-8?q?OUmqHJMiTRXQ+LJJ1dmP+AGri5tDc5+TgsQI3OixLNc32lXrrTna0WxhLNJUX1vu8?= =?utf-8?q?vwF8CSjTvrQ1yHEl7hOn79S6t+BtJT9jBEZ3N1q85gHioKxcCwJKAujxf8pwHvni3?= =?utf-8?q?jv8zD5UyHhvW82CZEuSf2hveWPahHZIESwaDh+7qgDz4NiIwZ9F45RS3jvVlhaart?= =?utf-8?q?BpGG7dbeA9pwVHE3gE0f++KgcztmHME7TJSN3TmN1wFhe7gbXz4wfasRvl58Ev3Us?= =?utf-8?q?1F66+is5kxTE46PuX3AXpxgiHEZKu56H8eUFYqxd/AYBsUFN7rgjZ+E4Z4kQHn2nd?= =?utf-8?q?98HAip+UA7au5k5zrIjcuwAf5CxpBd2tw2V285cAXx4lqHhYKTh0cVCxTAcd5kA3l?= =?utf-8?q?xf+iA5nLek3ZrxFdaaT6dP/276nBFCImfGClAjwtIk4JLA5OuIWZrsZwUObx08HCt?= =?utf-8?q?hK/gI0pDs1/mKk0849ywdjhsbhGrrUUwodk9Oh62QZnNYsyaymH6bAnad6Pkl6UMn?= =?utf-8?q?kxO0p9QrzFDpQYHqda5QQ6npTOQPBSevUj49WsS1IMdEgb8VSQNeR7Vh6JV5193/u?= =?utf-8?q?9YaYH3bU3Vhwq5iH44+e8IRql88QELr66PZhZ6T05ytQMoFUMr+FzLdlVcIP/Mur9?= =?utf-8?q?LMw7/hak7I6KiHhdN76mssdiNtS/x2atxz7WZLIV5Tn4vURagoPrGTTmD7uuWGZ0U?= =?utf-8?q?/0y6m9heHgako0NBEOcOB+rLAgLWt3wwK0yd8tr5rMgy/k9bc59gIZPnY7jA//Mp2?= =?utf-8?q?mDVvS7rkYJyBhsDbwsjSN0/DfCRND+cTH+8Zua0EriL9Byg4gmN7gP7/6JV7OEtMy?= =?utf-8?q?Ee4YnGdpWZmnz0aXQKekiRrFYLh5K5ROeUz1IIf2A9KyjdLqY3ULdLeDF6uBDCFvY?= =?utf-8?q?0z7V+vZkOTeo15gTja4FF3Z2NF3pFCNLdZ6gp/0/x79RJoYgGMiIAkaAOHc9zimIg?= =?utf-8?q?ik/Db2melzvfk4npLOTUwpiN+/Zg+2MWTGvvPF9GCfDJSuqmgb69lxlrhYuunqzG3?= =?utf-8?q?4WU9oFK4pkrcC0FZ1H7dBE2pD7JdUVzOldH8YgB4PGLwkjLZUlmvwo5oNpK0lBczH?= =?utf-8?q?3GWLsfDxLTS86xOmdGkqI0ZxhWzob6PhVB3xdteQQ/feeBtFgXKopcac3o8mufIvJ?= =?utf-8?q?dNby9ypvTuuyRhAk5SgAg4VIze5EK70J8yvY71PZOnyZJVVYK7n2NuYUP3LmWbxgX?= =?utf-8?q?GHIqwzt0/V/L?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a110d0a8-d652-4bf1-371f-08dd1fb90415 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Dec 2024 23:09:25.5157 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: m3Yi9eqwe75FzBt/7jQuogdEoZomHmoPKpa8y1ZA5+tBaXFCLKeZ7+APk6aCyanVmo+uXXqYJ7l42xxBushw2g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9939 Doorbell feature is implemented by mapping the EP's MSI interrupt controller message address to a dedicated BAR in the EPC core. It is the responsibility of the EPF driver to pass the actual message data to be written by the host to the doorbell BAR region through its own logic. Tested-by: Niklas Cassel Signed-off-by: Frank Li --- Change from v12 to v13 - Use DOMAIN_BUS_DEVICE_PCI_EP_MSI Change from v10 to v12 - none Change from v9 to v10 - Create msi domain for each function device. - Remove only function support limiation. My hardware only support one function, so not test more than one case. - use "msi-map" descript msi information msi-map = ; Chagne from v8 to v9 - sort header file - use pci_epc_get(dev_name(msi_desc_to_dev(desc))); - check epf number at pci_epf_alloc_doorbell - Add comments for miss msi-parent case change from v5 to v8 -none Change from v4 to v5 - Remove request_irq() in pci_epc_alloc_doorbell() and leave to EP function driver, so ep function driver can register differece call back function for difference doorbell events and set irq affinity to differece CPU core. - Improve error message when MSI allocate failure. Change from v3 to v4 - msi change to use msi_get_virq() avoid use msi_for_each_desc(). - add new struct for pci_epf_doorbell_msg to msi msg,virq and irq name. - move mutex lock to epc function - initialize variable at declear place. - passdown epf to epc*() function to simplify code. --- drivers/pci/endpoint/pci-ep-msi.c | 104 ++++++++++++++++++++++++++++++++++++++ include/linux/pci-ep-msi.h | 5 ++ include/linux/pci-epf.h | 16 ++++++ 3 files changed, 125 insertions(+) diff --git a/drivers/pci/endpoint/pci-ep-msi.c b/drivers/pci/endpoint/pci-ep-msi.c index 7aedc1cafbd14..33503d86cf2bc 100644 --- a/drivers/pci/endpoint/pci-ep-msi.c +++ b/drivers/pci/endpoint/pci-ep-msi.c @@ -34,3 +34,107 @@ int pci_epf_msi_domain_get_msi_rid(struct device *dev, u32 *rid) return 0; } EXPORT_SYMBOL_GPL(pci_epf_msi_domain_get_msi_rid); + +static void pci_epf_write_msi_msg(struct irq_data *d, struct msi_msg *msg) +{ + struct msi_desc *desc = irq_data_get_msi_desc(d); + struct pci_epf *epf = to_pci_epf(desc->dev); + + if (epf && epf->db_msg && desc->msi_index < epf->num_db) + memcpy(&epf->db_msg[desc->msi_index].msg, msg, sizeof(*msg)); +} + +static void pci_epf_msi_set_desc(msi_alloc_info_t *arg, struct msi_desc *desc) +{ + arg->desc = desc; + arg->hwirq = desc->msi_index; +} + +static const struct msi_domain_template pci_epf_msi_template = { + .chip = { + .name = "EP-MSI", + .irq_mask = irq_chip_mask_parent, + .irq_unmask = irq_chip_unmask_parent, + .irq_write_msi_msg = pci_epf_write_msi_msg, + /* The rest is filled in by the MSI parent */ + }, + + .ops = { + .set_desc = pci_epf_msi_set_desc, + }, + + .info = { + .bus_token = DOMAIN_BUS_DEVICE_PCI_EP_MSI, + }, +}; + +static int pci_epf_device_msi_init_and_alloc_irqs(struct device *dev, unsigned int nvec) +{ + struct irq_domain *domain = dev->msi.domain; + + if (!domain) + return -EINVAL; + + if (!msi_create_device_irq_domain(dev, MSI_DEFAULT_DOMAIN, + &pci_epf_msi_template, nvec, NULL, NULL)) + return -ENODEV; + + return msi_domain_alloc_irqs_range(dev, MSI_DEFAULT_DOMAIN, 0, nvec - 1); +} + +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 num_db) +{ + struct pci_epc *epc = epf->epc; + struct device *dev = &epf->dev; + struct irq_domain *dom; + void *msg; + u32 rid; + int ret; + int i; + + rid = (epf->func_no & 0x7) | (epf->vfunc_no << 3); + dom = of_msi_map_get_device_domain(epc->dev.parent, rid, DOMAIN_BUS_PLATFORM_PCI_EP_MSI); + if (!dom) { + dev_err(dev, "Can't find msi domain\n"); + return -EINVAL; + } + + dev_set_msi_domain(dev, dom); + + msg = kcalloc(num_db, sizeof(struct pci_epf_doorbell_msg), GFP_KERNEL); + if (!msg) + return -ENOMEM; + + epf->num_db = num_db; + epf->db_msg = msg; + + ret = pci_epf_device_msi_init_and_alloc_irqs(dev, num_db); + if (ret) { + /* + * The pcie_ep DT node has to specify 'msi-parent' for EP + * doorbell support to work. Right now only GIC ITS is + * supported. If you have GIC ITS and reached this print, + * perhaps you are missing 'msi-map' in DT. + */ + dev_err(dev, "Failed to allocate MSI\n"); + kfree(msg); + return -ENOMEM; + } + + for (i = 0; i < num_db; i++) + epf->db_msg[i].virq = msi_get_virq(dev, i); + + return ret; +} +EXPORT_SYMBOL_GPL(pci_epf_alloc_doorbell); + +void pci_epf_free_doorbell(struct pci_epf *epf) +{ + msi_domain_free_irqs_all(&epf->dev, MSI_DEFAULT_DOMAIN); + msi_remove_device_irq_domain(&epf->dev, MSI_DEFAULT_DOMAIN); + + kfree(epf->db_msg); + epf->db_msg = NULL; + epf->num_db = 0; +} +EXPORT_SYMBOL_GPL(pci_epf_free_doorbell); diff --git a/include/linux/pci-ep-msi.h b/include/linux/pci-ep-msi.h index 75236867426a4..26b1c86893ee4 100644 --- a/include/linux/pci-ep-msi.h +++ b/include/linux/pci-ep-msi.h @@ -18,4 +18,9 @@ static inline int pci_epf_msi_domain_get_msi_rid(struct device *dev, u32 *rid) } #endif +struct pci_epf; + +int pci_epf_alloc_doorbell(struct pci_epf *epf, u16 nums); +void pci_epf_free_doorbell(struct pci_epf *epf); + #endif /* __PCI_EP_MSI__ */ diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 18a3aeb62ae4e..5374e6515ffa0 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -12,6 +12,7 @@ #include #include #include +#include #include struct pci_epf; @@ -125,6 +126,17 @@ struct pci_epf_bar { int flags; }; +/** + * struct pci_epf_doorbell_msg - represents doorbell message + * @msi_msg: MSI message + * @virq: irq number of this doorbell MSI message + * @name: irq name for doorbell interrupt + */ +struct pci_epf_doorbell_msg { + struct msi_msg msg; + int virq; +}; + /** * struct pci_epf - represents the PCI EPF device * @dev: the PCI EPF device @@ -152,6 +164,8 @@ struct pci_epf_bar { * @vfunction_num_map: bitmap to manage virtual function number * @pci_vepf: list of virtual endpoint functions associated with this function * @event_ops: Callbacks for capturing the EPC events + * @db_msg: data for MSI from RC side + * @num_db: number of doorbells */ struct pci_epf { struct device dev; @@ -182,6 +196,8 @@ struct pci_epf { unsigned long vfunction_num_map; struct list_head pci_vepf; const struct pci_epc_event_ops *event_ops; + struct pci_epf_doorbell_msg *db_msg; + u16 num_db; }; /**