From: Frank Li <Frank.Li@nxp.com>
To: "Kishon Vijay Abraham I" <kishon@kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Anup Patel" <apatel@ventanamicro.com>,
"Kishon Vijay Abraham I" <kishon@kernel.org>,
"Marc Zyngier" <maz@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Danilo Krummrich" <dakr@kernel.org>,
"Manivannan Sadhasivam" <manivannan.sadhasivam@linaro.org>,
"Krzysztof Wilczyński" <kw@linux.com>,
"Kishon Vijay Abraham I" <kishon@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Arnd Bergmann" <arnd@arndb.de>, "Shuah Khan" <shuah@kernel.org>,
"Richard Zhu" <hongxing.zhu@nxp.com>,
"Lucas Stach" <l.stach@pengutronix.de>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Shawn Guo" <shawnguo@kernel.org>,
"Sascha Hauer" <s.hauer@pengutronix.de>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
"Fabio Estevam" <festevam@gmail.com>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>
Cc: Niklas Cassel <cassel@kernel.org>,
dlemoal@kernel.org, jdmason@kudzu.us,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org,
linux-kselftest@vger.kernel.org, imx@lists.linux.dev,
devicetree@vger.kernel.org, Frank Li <Frank.Li@nxp.com>
Subject: [PATCH v14 09/15] PCI: endpoint: pci-epf-test: Add doorbell test support
Date: Fri, 07 Feb 2025 14:39:51 -0500 [thread overview]
Message-ID: <20250207-ep-msi-v14-9-9671b136f2b8@nxp.com> (raw)
In-Reply-To: <20250207-ep-msi-v14-0-9671b136f2b8@nxp.com>
Add three registers: doorbell_bar, doorbell_addr, and doorbell_data. Use
pci_epf_alloc_doorbell() to allocate a doorbell address space.
Enable the Root Complex (RC) side driver to trigger pci-epc-test's doorbell
callback handler by writing doorbell_data to the mapped doorbell_bar's
address space.
Set STATUS_DOORBELL_SUCCESS in the doorbell callback to indicate
completion.
Avoid breaking compatibility between host and endpoint, add new command
COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL. Host side need send
COMMAND_ENABLE_DOORBELL to map one bar's inbound address to MSI space.
the command COMMAND_DISABLE_DOORBELL to recovery original inbound address
mapping.
Host side new driver Host side old driver
EP: new driver S F
EP: old driver F F
S: If EP side support MSI, 'pci_endpoint_test -f pcie_ep_doorbell' return
success.
If EP side doesn't support MSI, the same to 'F'.
F: 'pci_endpoint_test -f pcie_ep_doorbell' return failure, other case as
usual.
Tested-by: Niklas Cassel <cassel@kernel.org>
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
Change from v9 to v14
- update commit message by use pci_endpoint_test -f pcie_ep_doorbell
Change from v8 to v9
- move pci_epf_alloc_doorbell() into pci_epf_{enable/disable}_doorbell().
- remove doorbell_done in commit message.
- rename pci_epf_{enable/disable}_doorbell() to
pci_epf_test_{enable/disable}_doorbell() to align corrent code style.
Change from v7 to v8
- rename to pci_epf_align_inbound_addr_lo_hi()
Change from v6 to v7
- use help function pci_epf_align_addr_lo_hi()
Change from v5 to v6
- rename doorbell_addr to doorbell_offset
Chagne from v4 to v5
- Add doorbell free at unbind function.
- Move msi irq handler to here to more complex user case, such as differece
doorbell can use difference handler function.
- Add Niklas's code to handle fixed bar's case. If need add your signed-off
tag or co-developer tag, please let me know.
change from v3 to v4
- remove revid requirement
- Add command COMMAND_ENABLE_DOORBELL and COMMAND_DISABLE_DOORBELL.
- call pci_epc_set_bar() to map inbound address to MSI space only at
COMMAND_ENABLE_DOORBELL.
---
drivers/pci/endpoint/functions/pci-epf-test.c | 132 ++++++++++++++++++++++++++
1 file changed, 132 insertions(+)
diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index b94e205ae10b9..bba1229c46f14 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -11,12 +11,14 @@
#include <linux/dmaengine.h>
#include <linux/io.h>
#include <linux/module.h>
+#include <linux/msi.h>
#include <linux/slab.h>
#include <linux/pci_ids.h>
#include <linux/random.h>
#include <linux/pci-epc.h>
#include <linux/pci-epf.h>
+#include <linux/pci-ep-msi.h>
#include <linux/pci_regs.h>
#define IRQ_TYPE_INTX 0
@@ -29,6 +31,8 @@
#define COMMAND_READ BIT(3)
#define COMMAND_WRITE BIT(4)
#define COMMAND_COPY BIT(5)
+#define COMMAND_ENABLE_DOORBELL BIT(6)
+#define COMMAND_DISABLE_DOORBELL BIT(7)
#define STATUS_READ_SUCCESS BIT(0)
#define STATUS_READ_FAIL BIT(1)
@@ -39,6 +43,11 @@
#define STATUS_IRQ_RAISED BIT(6)
#define STATUS_SRC_ADDR_INVALID BIT(7)
#define STATUS_DST_ADDR_INVALID BIT(8)
+#define STATUS_DOORBELL_SUCCESS BIT(9)
+#define STATUS_DOORBELL_ENABLE_SUCCESS BIT(10)
+#define STATUS_DOORBELL_ENABLE_FAIL BIT(11)
+#define STATUS_DOORBELL_DISABLE_SUCCESS BIT(12)
+#define STATUS_DOORBELL_DISABLE_FAIL BIT(13)
#define FLAG_USE_DMA BIT(0)
@@ -63,6 +72,7 @@ struct pci_epf_test {
bool dma_supported;
bool dma_private;
const struct pci_epc_features *epc_features;
+ struct pci_epf_bar db_bar;
};
struct pci_epf_test_reg {
@@ -77,6 +87,9 @@ struct pci_epf_test_reg {
u32 irq_number;
u32 flags;
u32 caps;
+ u32 doorbell_bar;
+ u32 doorbell_offset;
+ u32 doorbell_data;
} __packed;
static struct pci_epf_header test_header = {
@@ -645,6 +658,116 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test,
}
}
+static irqreturn_t pci_epf_test_doorbell_handler(int irq, void *data)
+{
+ struct pci_epf_test *epf_test = data;
+ enum pci_barno test_reg_bar = epf_test->test_reg_bar;
+ struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar];
+
+ reg->status |= STATUS_DOORBELL_SUCCESS;
+ pci_epf_test_raise_irq(epf_test, reg);
+
+ return IRQ_HANDLED;
+}
+
+static void pci_epf_test_doorbell_cleanup(struct pci_epf_test *epf_test)
+{
+ struct pci_epf_test_reg *reg = epf_test->reg[epf_test->test_reg_bar];
+ struct pci_epf *epf = epf_test->epf;
+
+ if (reg->doorbell_bar > 0) {
+ free_irq(epf->db_msg[0].virq, epf_test);
+ reg->doorbell_bar = NO_BAR;
+ }
+
+ if (epf->db_msg)
+ pci_epf_free_doorbell(epf);
+}
+
+static void pci_epf_test_enable_doorbell(struct pci_epf_test *epf_test,
+ struct pci_epf_test_reg *reg)
+{
+ struct pci_epf *epf = epf_test->epf;
+ struct pci_epc *epc = epf->epc;
+ struct msi_msg *msg;
+ enum pci_barno bar;
+ size_t offset;
+ int ret;
+
+ ret = pci_epf_alloc_doorbell(epf, 1);
+ if (ret) {
+ reg->status |= STATUS_DOORBELL_ENABLE_FAIL;
+ return;
+ }
+
+ msg = &epf->db_msg[0].msg;
+ bar = pci_epc_get_next_free_bar(epf_test->epc_features, epf_test->test_reg_bar + 1);
+ if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) {
+ reg->status |= STATUS_DOORBELL_ENABLE_FAIL;
+ return;
+ }
+
+ ret = request_irq(epf->db_msg[0].virq, pci_epf_test_doorbell_handler, 0,
+ "pci-test-doorbell", epf_test);
+ if (ret) {
+ dev_err(&epf->dev,
+ "Failed to request irq %d, doorbell feature is not supported\n",
+ epf->db_msg[0].virq);
+ reg->status |= STATUS_DOORBELL_ENABLE_FAIL;
+ pci_epf_test_doorbell_cleanup(epf_test);
+ return;
+ }
+
+ reg->doorbell_data = msg->data;
+ reg->doorbell_bar = bar;
+
+ msg = &epf->db_msg[0].msg;
+ ret = pci_epf_align_inbound_addr(epf, bar, ((u64)msg->address_hi << 32) | msg->address_lo,
+ &epf_test->db_bar.phys_addr, &offset);
+
+ if (ret) {
+ reg->status |= STATUS_DOORBELL_ENABLE_FAIL;
+ pci_epf_test_doorbell_cleanup(epf_test);
+ return;
+ }
+
+ reg->doorbell_offset = offset;
+
+ epf_test->db_bar.barno = bar;
+ epf_test->db_bar.size = epf->bar[bar].size;
+ epf_test->db_bar.flags = epf->bar[bar].flags;
+
+ ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf_test->db_bar);
+ if (ret) {
+ reg->status |= STATUS_DOORBELL_ENABLE_FAIL;
+ pci_epf_test_doorbell_cleanup(epf_test);
+ } else {
+ reg->status |= STATUS_DOORBELL_ENABLE_SUCCESS;
+ }
+}
+
+static void pci_epf_test_disable_doorbell(struct pci_epf_test *epf_test,
+ struct pci_epf_test_reg *reg)
+{
+ enum pci_barno bar = reg->doorbell_bar;
+ struct pci_epf *epf = epf_test->epf;
+ struct pci_epc *epc = epf->epc;
+ int ret;
+
+ if (bar < BAR_0 || bar == epf_test->test_reg_bar || !epf->db_msg) {
+ reg->status |= STATUS_DOORBELL_DISABLE_FAIL;
+ return;
+ }
+
+ ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf->bar[bar]);
+ if (ret)
+ reg->status |= STATUS_DOORBELL_DISABLE_FAIL;
+ else
+ reg->status |= STATUS_DOORBELL_DISABLE_SUCCESS;
+
+ pci_epf_test_doorbell_cleanup(epf_test);
+}
+
static void pci_epf_test_cmd_handler(struct work_struct *work)
{
u32 command;
@@ -691,6 +814,14 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
pci_epf_test_copy(epf_test, reg);
pci_epf_test_raise_irq(epf_test, reg);
break;
+ case COMMAND_ENABLE_DOORBELL:
+ pci_epf_test_enable_doorbell(epf_test, reg);
+ pci_epf_test_raise_irq(epf_test, reg);
+ break;
+ case COMMAND_DISABLE_DOORBELL:
+ pci_epf_test_disable_doorbell(epf_test, reg);
+ pci_epf_test_raise_irq(epf_test, reg);
+ break;
default:
dev_err(dev, "Invalid command 0x%x\n", command);
break;
@@ -953,6 +1084,7 @@ static void pci_epf_test_unbind(struct pci_epf *epf)
pci_epf_test_clean_dma_chan(epf_test);
pci_epf_test_clear_bar(epf);
}
+ pci_epf_test_doorbell_cleanup(epf_test);
pci_epf_test_free_space(epf);
}
--
2.34.1
next prev parent reply other threads:[~2025-02-07 19:41 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-07 19:39 [PATCH v14 00/15] PCI: EP: Add RC-to-EP doorbell with platform MSI controller Frank Li
2025-02-07 19:39 ` [PATCH v14 01/15] platform-msi: Add msi_remove_device_irq_domain() in platform_device_msi_free_irqs_all() Frank Li
2025-02-07 19:39 ` [PATCH v14 02/15] irqdomain: Add IRQ_DOMAIN_FLAG_MSI_IMMUTABLE and irq_domain_is_msi_immutable() Frank Li
2025-02-07 19:39 ` [PATCH v14 03/15] irqchip/gic-v3-its: Set IRQ_DOMAIN_FLAG_MSI_IMMUTABLE for ITS Frank Li
2025-02-07 19:39 ` [PATCH v14 04/15] irqchip/gic-v3-its: Add support for device tree msi-map and msi-mask Frank Li
2025-02-07 19:39 ` [PATCH v14 05/15] PCI: endpoint: Set ID and of_node for function driver Frank Li
2025-02-07 19:39 ` [PATCH v14 06/15] PCI: endpoint: Add RC-to-EP doorbell support using platform MSI controller Frank Li
2025-02-08 14:17 ` kernel test robot
2025-02-07 19:39 ` [PATCH v14 07/15] PCI: endpoint: pci-ep-msi: Add MSI address/data pair mutable check Frank Li
2025-02-08 15:00 ` kernel test robot
2025-02-07 19:39 ` [PATCH v14 08/15] PCI: endpoint: Add pci_epf_align_inbound_addr() helper for address alignment Frank Li
2025-02-07 19:39 ` Frank Li [this message]
2025-02-08 15:43 ` [PATCH v14 09/15] PCI: endpoint: pci-epf-test: Add doorbell test support kernel test robot
2025-02-07 19:39 ` [PATCH v14 10/15] misc: pci_endpoint_test: Add doorbell test case Frank Li
2025-02-07 19:39 ` [PATCH v14 11/15] selftests: pci_endpoint: " Frank Li
2025-02-07 19:39 ` [PATCH v14 12/15] pci: imx6: Add helper function imx_pcie_add_lut_by_rid() Frank Li
2025-02-07 19:39 ` [PATCH v14 13/15] pci: imx6: Add LUT setting for MSI/IOMMU in Endpoint mode Frank Li
2025-02-07 19:39 ` [PATCH v14 14/15] arm64: dts: imx95: Add msi-map for pci-ep device Frank Li
2025-02-07 19:39 ` [PATCH v14 15/15] arm64: dts: imx95-19x19-evk: Add PCIe1 endpoint function overlay file Frank Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250207-ep-msi-v14-9-9671b136f2b8@nxp.com \
--to=frank.li@nxp.com \
--cc=apatel@ventanamicro.com \
--cc=arnd@arndb.de \
--cc=bhelgaas@google.com \
--cc=cassel@kernel.org \
--cc=conor+dt@kernel.org \
--cc=dakr@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlemoal@kernel.org \
--cc=festevam@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=hongxing.zhu@nxp.com \
--cc=imx@lists.linux.dev \
--cc=jdmason@kudzu.us \
--cc=kernel@pengutronix.de \
--cc=kishon@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=kw@linux.com \
--cc=l.stach@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=maz@kernel.org \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox