From patchwork Thu Oct 31 16:27:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13858178 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2045.outbound.protection.outlook.com [40.107.21.45]) (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 D9D061C57A0; Thu, 31 Oct 2024 16:27:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730392051; cv=fail; b=PJcXyIXLSeuPahNQrAKRtJpIi0oMCyRCgreYwfFwEwwjumpVrFAjx1RqdlgpEikKL8VnV3/um67X9UZLmHTRjD1nI0oFtEqjRBTrTbvrGhzdo6+AUJV5gpobIs2kH2FZwzFbW2YUs+7D5johtoSLIZ+xWoqGoGRvA1iR98iM9rI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730392051; c=relaxed/simple; bh=86w1a1XMlWfuSdwPQdmN0jUXDLe71oOcpkgioiRNwn8=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=iIR4jlVTToQtbJBpYe2iDu9vBj2eE7HrpvdxwqO4vetddsYMBf54otP/7g9Mub+7ilqIhDJf+5u4FjyBQ8goDftSftk5qKfJUB8IJ6Nw6hMuu4k/dZlVeoh9hTdD0XyeWakNVsLetWeHfeFpzy3WweHXU8XDBtFZd/RdAYQCONQ= 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=ht7dQOvC; arc=fail smtp.client-ip=40.107.21.45 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="ht7dQOvC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cF6HEfjo4H0D9XuIfEDOesG5ZjDKkkxwUZflaUYzT5CzFxd9yrL2KPCQX/6CkDliwXMfkakOI9qN+70bkHRa05A8T+9C/oVRabJbn8xoYTJeevvROSqWS/dljvjFXk75D54gQxdIcstE8BSeTBdX699GKdsoQkVWfOoqVaAVTLeDaIX1D/G9i4k36xI5LQXSAt7GteQIO/EKihl15pkI/wWbHxKmFGtIgy+OFfRcEWfJOn+HOrCOwbIGbQoMKAdKZ3dKj+bQznvxCS0BsGGB+Os0s0l1NWk8L0icWvSWxgIdS02ldkpBEZOZCVmtTkZ2eeqpdhPpRHL5+uHUfnMuog== 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=3cvWynPFHPf07oWxi8rpPdNTX2d96vmSUu2BSeQ+qNo=; b=cpmAF6tv3VRU2PWPl0zcZ3tqp49idxdiV7zlmXUQ92td/4Tn0lvkgg1MO3Js+7UbmrXX5bS8JNBR6AerF1nPpq90hXg/k4McNY0sfNqdNMCHQf16RYuatNzmSHegl+lOKT8vjpeAjQCnQMLElbjLdlE39gtMvpfhqSMIBRFjlYk/t+slS+LOUfQBlpz68y4nIRMZWdll7q2pEhEDRgvGA6Cvu4gtSQFC5ms+P9uan/cF8B0TiLGjI0TJzmG4dmSSn1yffUQL1FzbHHjBz94gCTFZPCDzZdxtlahH2mu5HN0k+WB3QBQQ3QCKMNfJN39EsQmIOHmI6DVI62dF3zFRgQ== 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=3cvWynPFHPf07oWxi8rpPdNTX2d96vmSUu2BSeQ+qNo=; b=ht7dQOvCWErj22QXpnKF2/zKboJSQnuGF+KSrAZqRIdPqlMTYSEwztgy69Jax/xFe7TNkDy39VBZ79i7Y60nUL763I08Fsn6x9WoToNL+DNSMg4Oz1xmBHEsT0Bkr+b4egnJBG96a9z6dxwd0N+zav9K39BRrJCXGgvxAn9IggfuNUAHq6Bf8RWx/n39jHQXF3Jln9u35GRaaTHwRxinoQKcfoAViqeIRzivJzus7h+tvYJhb8nboZI3c5Qfa5Ecksd5tQwtFL+5kZwy4Ymv3yjneI4VfJZTTQSWVStguQkq9eMevcZz06t99MKLzjrSeiNX/a93AtEbqV6U4zuh4A== 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 PA1PR04MB11081.eurprd04.prod.outlook.com (2603:10a6:102:485::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Thu, 31 Oct 2024 16:27:20 +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.8093.027; Thu, 31 Oct 2024 16:27:20 +0000 From: Frank Li Date: Thu, 31 Oct 2024 12:27:01 -0400 Subject: [PATCH v4 2/5] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Message-Id: <20241031-ep-msi-v4-2-717da2d99b28@nxp.com> References: <20241031-ep-msi-v4-0-717da2d99b28@nxp.com> In-Reply-To: <20241031-ep-msi-v4-0-717da2d99b28@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=1730392028; l=7322; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=86w1a1XMlWfuSdwPQdmN0jUXDLe71oOcpkgioiRNwn8=; b=Erbraa3lsZzknZGivE+84oK60M+flb/gF0e77hX/NWhTBmb/4Fv2V9SDcue/dnaM6Yr3otQWY Nj8ux8LJNtUCL+TTzRHEDBJSc/BTiSKVg3NyDMucbA62MPprlfnikLM X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR08CA0056.namprd08.prod.outlook.com (2603:10b6:a03:117::33) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA1PR04MB11081:EE_ X-MS-Office365-Filtering-Correlation-Id: fd943788-ace9-494a-cc8a-08dcf9c8e44c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|52116014|7416014|38350700014; X-Micros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IV/nMPLOtpHm3nuKiiLEwJhTMTHIKhnxZo4JwZZR1XTDqfmPfC?= =?utf-8?q?89DQGmEozhQW3KmlLpZ+7clp7ozbvBF4KI4KglCGlzXKZwmCMnESJhEhjAsuTI6Bf?= =?utf-8?q?FWMY2mzn/FHuGAXRSuKBB13nfYhg/SXkdFKhcFOOZ05vZ+F826jBrdxhbX3Dim3V8?= =?utf-8?q?KXDDzce78SIH7RIZOobYEzf3PZQl6pveC+MiRvNLcVK0QRxuYLmpuukl0buZmTysn?= =?utf-8?q?+LfQBVXOXAMmBOkQPH4+fl4PR5bnhoOOkhbIE+WoJxA4qePFxrDuGk8Z7/68sPsL3?= =?utf-8?q?qVwaCuyeTOqgBcNUPv02Wekjm1yJQ0lz2GgbEjeJAi+Bbgq4rq1aQQe5wYNYsUj6j?= =?utf-8?q?WDDD/RCAGr1ZeyRnv6sLVrfHD2fi6FYqCXo8cWv6/y+F5YqwBeQqwr321EZw78c9y?= =?utf-8?q?xUlwesK25otlqzXpWP8FOVbjg0Z6cvvafG3NFMdRGhAVUvM5rHe7ClnM=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)(376014)(52116014)(7416014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?SPrLaJTn8ByqsbAVoGKQjjlOtSaB?= =?utf-8?q?7pftYkJ31Kba1/VbUFzuwRc3eliJKuC11+fHqNC7HyM9kFjsADF2Ysy80fqk781sX?= =?utf-8?q?nDSBEabX/a9b5toclGcXKU7zpJK4DjqJ+lp/ZzecEZ8m62vK9zVrvYEfjqhSoGnl0?= =?utf-8?q?QzF8lqKtNRFg0xTEofYVZBBecyr6TqT0HElQpZqkwcIDoOstaYKqHcDuo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v2B?= =?utf-8?q?HZ+J1BhwMeaEOYT+sMvXNgROxrbm2p7/DmUBqbaCKBT7pL8/GKTBuM9qu+yY0UeEl?= =?utf-8?q?xBlLxmRIPbE3DrL0v92AuQJ46F3SkzdGMAZq6DxBstm8p5IiUDKG8WhpFXq2VCavs?= =?utf-8?q?BNz5IqzzbrGovu+uJniyEhlibfiqJTkAXE4MOTb9MsTE8F3twZF0gZJdhx48weAYj?= =?utf-8?q?FAlx6srCZ9ig6864DmyXcmrLY1D5liF3krftA9JWocIwZIKC8fBCeJWn/sRPhd5kH?= =?utf-8?q?xBcPcq1jlOJ7IRBa6/TLny0g2bZpDg/TKcBhflSlNC6tBPikAivFDERujPRywzlLK?= =?utf-8?q?i6xilvGEU5K0oQGGumJK968YD/NwoTpHHhZSxku+cBW+ixYMSnDl4vYkbStdvh7Io?= =?utf-8?q?4KTVSlT2WedmRiX2iwimXbTE2boZ2DIPErF5Kd1pDrJyJmavnk2KALtY=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fd943788-ace9-494a-cc8a-08dcf9c8e44c X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2024 16:27:20.0550 (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: YLxwMhjvEXGTZP4T6hLcaYhnFKI8fZqNPBGpEoMGDbBSZNFaXWNsPyBAm9/1K4eJ5A9IWOwM8mon/Lyi9UMfzQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR04MB11081 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. Signed-off-by: Frank Li --- 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 | 128 ++++++++++++++++++++++++++++++++++++++ include/linux/pci-ep-msi.h | 15 +++++ include/linux/pci-epf.h | 19 ++++++ 4 files changed, 163 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..91207fb66db32 --- /dev/null +++ b/drivers/pci/endpoint/pci-ep-msi.c @@ -0,0 +1,128 @@ +// 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 irqreturn_t pci_epf_doorbell_handler(int irq, void *data) +{ + struct pci_epf *epf = data; + struct msi_desc *desc = irq_get_msi_desc(irq); + + if (desc && epf->event_ops && epf->event_ops->doorbell) + epf->event_ops->doorbell(epf, desc->msi_index); + + return IRQ_HANDLED; +} + +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) +{ + int i; + + guard(mutex)(&epc->lock); + + for (i = 0; i < epf->num_db && epf->db_msg[i].virq; i++) { + free_irq(epf->db_msg[i].virq, epf); + epf->db_msg[i].virq = 0; + kfree(epf->db_msg[i].name); + epf->db_msg[i].name = NULL; + } + + 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\n"); + return -ENOMEM; + } + + for (i = 0; i < num_db; i++) { + epf->db_msg[i].virq = msi_get_virq(dev, i); + epf->db_msg[i].name = kasprintf(GFP_KERNEL, "pci-epc-doorbell%d", i); + ret = request_irq(epf->db_msg[i].virq, pci_epf_doorbell_handler, 0, + epf->db_msg[i].name, epf); + if (ret) { + dev_err(dev, "Failed to request doorbell\n"); + pci_epc_free_doorbell(epc, epf); + return ret; + } + } + + 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..50c0f877f2efb 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; @@ -75,6 +76,7 @@ struct pci_epf_ops { * @link_up: Callback for the EPC link up event * @link_down: Callback for the EPC link down event * @bus_master_enable: Callback for the EPC Bus Master Enable event + * @doorbell: Callback for EPC receive MSI from RC side */ struct pci_epc_event_ops { int (*epc_init)(struct pci_epf *epf); @@ -82,6 +84,7 @@ struct pci_epc_event_ops { int (*link_up)(struct pci_epf *epf); int (*link_down)(struct pci_epf *epf); int (*bus_master_enable)(struct pci_epf *epf); + int (*doorbell)(struct pci_epf *epf, int index); }; /** @@ -125,6 +128,18 @@ 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; + char *name; +}; + /** * struct pci_epf - represents the PCI EPF device * @dev: the PCI EPF device @@ -152,6 +167,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 +199,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; }; /**