From: Frank Li <Frank.li@nxp.com>
To: Koichiro Den <den@valinux.co.jp>
Cc: jingoohan1@gmail.com, mani@kernel.org, lpieralisi@kernel.org,
kwilczynski@kernel.org, robh@kernel.org, bhelgaas@google.com,
heiko@sntech.de, kishon@kernel.org, jdmason@kudzu.us,
dave.jiang@intel.com, allenbh@gmail.com, cassel@kernel.org,
shawn.lin@rock-chips.com, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org, ntb@lists.linux.dev
Subject: Re: [PATCH v8 7/9] PCI: endpoint: pci-epf-vntb: Reuse pre-exposed doorbells and IRQ flags
Date: Tue, 17 Feb 2026 11:54:29 -0500 [thread overview]
Message-ID: <aZSdRWdevAr6TpBP@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20260217080601.3808847-8-den@valinux.co.jp>
On Tue, Feb 17, 2026 at 05:05:59PM +0900, Koichiro Den wrote:
> Support doorbell backends where the doorbell target is already exposed
> via a platform-owned fixed BAR mapping and/or where the doorbell IRQ
> must be requested with specific flags.
>
> When pci_epf_alloc_doorbell() provides db_msg[].bar/offset, reuse the
> pre-exposed BAR window and skip programming a new inbound mapping. Also
> honor db_msg[].irq_flags when requesting the doorbell IRQ.
>
> Multiple doorbells may share the same Linux IRQ. Avoid duplicate
> request_irq() calls by requesting each unique virq once.
>
> This makes pci-epf-vntb work with platform-defined or embedded doorbell
Nit: Make pci-epf-vntb work with ...
> backends without exposing backend-specific details to the consumer
> layer.
>
> Signed-off-by: Koichiro Den <den@valinux.co.jp>
> ---
> Changes since v7:
> - Deduplicate request_irq()/free_irq() calls based on virq (shared
> IRQ) rather than doorbell type.
>
> drivers/pci/endpoint/functions/pci-epf-vntb.c | 61 ++++++++++++++++++-
> 1 file changed, 58 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c
> index 52cf442ca1d9..b1e8414c4e43 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c
> @@ -134,6 +134,11 @@ struct epf_ntb {
> u16 vntb_vid;
>
> bool linkup;
> +
> + /*
> + * True when doorbells are interrupt-driven (MSI or embedded), false
> + * when polled.
> + */
> bool msi_doorbell;
> u32 spad_size;
>
> @@ -517,6 +522,17 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb)
> return 0;
> }
>
> +static bool epf_ntb_db_irq_is_first(const struct pci_epf *epf, unsigned int idx)
epf_ntb_db_irq_is_duplicated() look better, below 'if' needn't !
Frank
> +{
> + unsigned int i;
> +
> + for (i = 0; i < idx; i++)
> + if (epf->db_msg[i].virq == epf->db_msg[idx].virq)
> + return false;
> +
> + return true;
> +}
> +
> static int epf_ntb_db_bar_init_msi_doorbell(struct epf_ntb *ntb,
> struct pci_epf_bar *db_bar,
> const struct pci_epc_features *epc_features,
> @@ -533,9 +549,24 @@ static int epf_ntb_db_bar_init_msi_doorbell(struct epf_ntb *ntb,
> if (ret)
> return ret;
>
> + /*
> + * The doorbell target may already be exposed by a platform-owned fixed
> + * BAR. In that case, we must reuse it and the requested db_bar must
> + * match.
> + */
> + if (epf->db_msg[0].bar != NO_BAR && epf->db_msg[0].bar != barno) {
> + ret = -EINVAL;
> + goto err_free_doorbell;
> + }
> +
> for (req = 0; req < ntb->db_count; req++) {
> + /* Avoid requesting duplicate handlers */
> + if (!epf_ntb_db_irq_is_first(epf, req))
> + continue;
> +
> ret = request_irq(epf->db_msg[req].virq, epf_ntb_doorbell_handler,
> - 0, "pci_epf_vntb_db", ntb);
> + epf->db_msg[req].irq_flags, "pci_epf_vntb_db",
> + ntb);
>
> if (ret) {
> dev_err(&epf->dev,
> @@ -545,6 +576,22 @@ static int epf_ntb_db_bar_init_msi_doorbell(struct epf_ntb *ntb,
> }
> }
>
> + if (epf->db_msg[0].bar != NO_BAR) {
> + for (i = 0; i < ntb->db_count; i++) {
> + msg = &epf->db_msg[i].msg;
> +
> + if (epf->db_msg[i].bar != barno) {
> + ret = -EINVAL;
> + goto err_free_irq;
> + }
> +
> + ntb->reg->db_data[i] = msg->data;
> + ntb->reg->db_offset[i] = epf->db_msg[i].offset;
> + }
> + goto out;
> + }
> +
> + /* Program inbound mapping for the doorbell */
> msg = &epf->db_msg[0].msg;
>
> high = 0;
> @@ -591,6 +638,7 @@ static int epf_ntb_db_bar_init_msi_doorbell(struct epf_ntb *ntb,
> ntb->reg->db_offset[i] = offset;
> }
>
> +out:
> ntb->reg->db_entry_size = 0;
>
> ntb->msi_doorbell = true;
> @@ -598,9 +646,13 @@ static int epf_ntb_db_bar_init_msi_doorbell(struct epf_ntb *ntb,
> return 0;
>
> err_free_irq:
> - for (req--; req >= 0; req--)
> + for (req--; req >= 0; req--) {
> + if (!epf_ntb_db_irq_is_first(epf, req))
> + continue;
> free_irq(epf->db_msg[req].virq, ntb);
> + }
>
> +err_free_doorbell:
> pci_epf_free_doorbell(ntb->epf);
> return ret;
> }
> @@ -666,8 +718,11 @@ static void epf_ntb_db_bar_clear(struct epf_ntb *ntb)
> if (ntb->msi_doorbell) {
> int i;
>
> - for (i = 0; i < ntb->db_count; i++)
> + for (i = 0; i < ntb->db_count; i++) {
> + if (!epf_ntb_db_irq_is_first(ntb->epf, i))
> + continue;
> free_irq(ntb->epf->db_msg[i].virq, ntb);
> + }
> }
>
> if (ntb->epf->db_msg)
> --
> 2.51.0
>
next prev parent reply other threads:[~2026-02-17 16:54 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-17 8:05 [PATCH v8 0/9] PCI: endpoint: pci-ep-msi: Add embedded doorbell fallback Koichiro Den
2026-02-17 8:05 ` [PATCH v8 1/9] PCI: endpoint: Describe reserved subregions within BARs Koichiro Den
2026-02-17 8:05 ` [PATCH v8 2/9] PCI: dw-rockchip: Describe RK3588 BAR4 DMA ctrl window Koichiro Den
2026-02-17 8:05 ` [PATCH v8 3/9] PCI: endpoint: Add auxiliary resource query API Koichiro Den
2026-02-17 16:41 ` Frank Li
2026-02-17 8:05 ` [PATCH v8 4/9] PCI: dwc: Record integrated eDMA register window Koichiro Den
2026-02-17 8:05 ` [PATCH v8 5/9] PCI: dwc: ep: Expose integrated eDMA resources via EPC aux-resource API Koichiro Den
2026-02-17 8:05 ` [PATCH v8 6/9] PCI: endpoint: pci-ep-msi: Refactor doorbell allocation for new backends Koichiro Den
2026-02-17 16:43 ` Frank Li
2026-02-17 8:05 ` [PATCH v8 7/9] PCI: endpoint: pci-epf-vntb: Reuse pre-exposed doorbells and IRQ flags Koichiro Den
2026-02-17 16:54 ` Frank Li [this message]
2026-02-18 2:33 ` Koichiro Den
2026-02-17 8:06 ` [PATCH v8 8/9] PCI: endpoint: pci-epf-test: Reuse pre-exposed doorbell targets Koichiro Den
2026-02-17 10:15 ` Niklas Cassel
2026-02-18 3:34 ` Koichiro Den
2026-02-17 8:06 ` [PATCH v8 9/9] PCI: endpoint: pci-ep-msi: Add embedded eDMA doorbell fallback Koichiro Den
2026-02-17 16:45 ` 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=aZSdRWdevAr6TpBP@lizhi-Precision-Tower-5810 \
--to=frank.li@nxp.com \
--cc=allenbh@gmail.com \
--cc=bhelgaas@google.com \
--cc=cassel@kernel.org \
--cc=dave.jiang@intel.com \
--cc=den@valinux.co.jp \
--cc=heiko@sntech.de \
--cc=jdmason@kudzu.us \
--cc=jingoohan1@gmail.com \
--cc=kishon@kernel.org \
--cc=kwilczynski@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=ntb@lists.linux.dev \
--cc=robh@kernel.org \
--cc=shawn.lin@rock-chips.com \
/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