mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 v7 8/9] PCI: endpoint: pci-epf-test: Reuse pre-exposed doorbell targets
Date: Mon, 16 Feb 2026 11:18:42 -0500	[thread overview]
Message-ID: <aZNDYmR3e2z-VnZA@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20260215163847.3522572-9-den@valinux.co.jp>

On Mon, Feb 16, 2026 at 01:38:46AM +0900, Koichiro Den wrote:
> pci-epf-test advertises the doorbell target to the RC as a BAR number
> and an offset, and the RC rings the doorbell with a single DWORD MMIO
> write.
>
> Some doorbell backends may report that the doorbell target is already
> exposed via a platform-owned fixed BAR (db_msg[0].bar/offset). In that
> case, reuse the pre-exposed window and do not reprogram the BAR with
> pci_epc_set_bar().
>
> Also honor db_msg[0].irq_flags when requesting the doorbell IRQ, and
> only restore the original BAR mapping on disable if pci-epf-test
> programmed it.
>
> Signed-off-by: Koichiro Den <den@valinux.co.jp>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
>  drivers/pci/endpoint/functions/pci-epf-test.c | 84 +++++++++++++------
>  1 file changed, 57 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
> index defe1e2ea427..7b0955b4c703 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-test.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-test.c
> @@ -87,6 +87,7 @@ struct pci_epf_test {
>  	const struct pci_epc_features *epc_features;
>  	struct pci_epf_bar	db_bar;
>  	bool			db_irq_requested;
> +	bool			db_bar_programmed;
>  	size_t			bar_size[PCI_STD_NUM_BARS];
>  };
>
> @@ -730,7 +731,9 @@ static void pci_epf_test_enable_doorbell(struct pci_epf_test *epf_test,
>  {
>  	u32 status = le32_to_cpu(reg->status);
>  	struct pci_epf *epf = epf_test->epf;
> +	struct pci_epf_doorbell_msg *db;
>  	struct pci_epc *epc = epf->epc;
> +	unsigned long irq_flags;
>  	struct msi_msg *msg;
>  	enum pci_barno bar;
>  	size_t offset;
> @@ -742,13 +745,28 @@ static void pci_epf_test_enable_doorbell(struct pci_epf_test *epf_test,
>  	if (ret)
>  		goto set_status_err;
>
> -	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)
> -		goto err_doorbell_cleanup;
> +	db = &epf->db_msg[0];
> +	msg = &db->msg;
> +	epf_test->db_bar_programmed = false;
> +
> +	if (db->bar != NO_BAR) {
> +		/*
> +		 * The doorbell target is already exposed via a platform-owned
> +		 * fixed BAR
> +		 */
> +		bar = db->bar;
> +		offset = db->offset;
> +	} else {
> +		bar = pci_epc_get_next_free_bar(epf_test->epc_features,
> +						epf_test->test_reg_bar + 1);
> +		if (bar < BAR_0)
> +			goto err_doorbell_cleanup;
> +	}
> +
> +	irq_flags = epf->db_msg[0].irq_flags | IRQF_ONESHOT;
>
>  	ret = request_threaded_irq(epf->db_msg[0].virq, NULL,
> -				   pci_epf_test_doorbell_handler, IRQF_ONESHOT,
> +				   pci_epf_test_doorbell_handler, irq_flags,
>  				   "pci-ep-test-doorbell", epf_test);
>  	if (ret) {
>  		dev_err(&epf->dev,
> @@ -761,25 +779,33 @@ static void pci_epf_test_enable_doorbell(struct pci_epf_test *epf_test,
>  	reg->doorbell_data = cpu_to_le32(msg->data);
>  	reg->doorbell_bar = cpu_to_le32(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 (db->bar == NO_BAR) {
> +		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)
> -		goto err_doorbell_cleanup;
> +		if (ret)
> +			goto err_doorbell_cleanup;
> +	}
>
>  	if (size_add(offset, sizeof(u32)) > epf->bar[bar].size)
>  		goto err_doorbell_cleanup;
>
>  	reg->doorbell_offset = cpu_to_le32(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;
> +	if (db->bar == NO_BAR) {
> +		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)
> -		goto err_doorbell_cleanup;
> +		ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf_test->db_bar);
> +		if (ret)
> +			goto err_doorbell_cleanup;
> +
> +		epf_test->db_bar_programmed = true;
> +	}
>
>  	status |= STATUS_DOORBELL_ENABLE_SUCCESS;
>  	reg->status = cpu_to_le32(status);
> @@ -806,17 +832,21 @@ static void pci_epf_test_disable_doorbell(struct pci_epf_test *epf_test,
>
>  	pci_epf_test_doorbell_cleanup(epf_test);
>
> -	/*
> -	 * The doorbell feature temporarily overrides the inbound translation
> -	 * to point to the address stored in epf_test->db_bar.phys_addr, i.e.,
> -	 * it calls set_bar() twice without ever calling clear_bar(), as
> -	 * calling clear_bar() would clear the BAR's PCI address assigned by
> -	 * the host. Thus, when disabling the doorbell, restore the inbound
> -	 * translation to point to the memory allocated for the BAR.
> -	 */
> -	ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf->bar[bar]);
> -	if (ret)
> -		goto set_status_err;
> +	if (epf_test->db_bar_programmed) {
> +		/*
> +		 * The doorbell feature temporarily overrides the inbound translation
> +		 * to point to the address stored in epf_test->db_bar.phys_addr, i.e.,
> +		 * it calls set_bar() twice without ever calling clear_bar(), as
> +		 * calling clear_bar() would clear the BAR's PCI address assigned by
> +		 * the host. Thus, when disabling the doorbell, restore the inbound
> +		 * translation to point to the memory allocated for the BAR.
> +		 */
> +		ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf->bar[bar]);
> +		if (ret)
> +			goto set_status_err;
> +
> +		epf_test->db_bar_programmed = false;
> +	}
>
>  	status |= STATUS_DOORBELL_DISABLE_SUCCESS;
>  	reg->status = cpu_to_le32(status);
> --
> 2.51.0
>

  reply	other threads:[~2026-02-16 16:18 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-15 16:38 [PATCH v7 0/9] PCI: endpoint: pci-ep-msi: Add embedded doorbell fallback Koichiro Den
2026-02-15 16:38 ` [PATCH v7 1/9] PCI: endpoint: Describe reserved subregions within BARs Koichiro Den
2026-02-15 16:38 ` [PATCH v7 2/9] PCI: dw-rockchip: Describe RK3588 BAR4 DMA ctrl window Koichiro Den
2026-02-15 16:38 ` [PATCH v7 3/9] PCI: endpoint: Add auxiliary resource query API Koichiro Den
2026-02-16 15:56   ` Frank Li
2026-02-15 16:38 ` [PATCH v7 4/9] PCI: dwc: Record integrated eDMA register window Koichiro Den
2026-02-15 16:38 ` [PATCH v7 5/9] PCI: dwc: ep: Expose integrated eDMA resources via EPC aux-resource API Koichiro Den
2026-02-16 14:12   ` Niklas Cassel
2026-02-16 15:06     ` Koichiro Den
2026-02-16 16:02   ` Frank Li
2026-02-15 16:38 ` [PATCH v7 6/9] PCI: endpoint: pci-ep-msi: Refactor doorbell allocation for new backends Koichiro Den
2026-02-16 16:07   ` Frank Li
2026-02-15 16:38 ` [PATCH v7 7/9] PCI: endpoint: pci-epf-vntb: Reuse pre-exposed doorbells and IRQ flags Koichiro Den
2026-02-16 16:14   ` Frank Li
2026-02-17  1:39     ` Koichiro Den
2026-02-15 16:38 ` [PATCH v7 8/9] PCI: endpoint: pci-epf-test: Reuse pre-exposed doorbell targets Koichiro Den
2026-02-16 16:18   ` Frank Li [this message]
2026-02-15 16:38 ` [PATCH v7 9/9] PCI: endpoint: pci-ep-msi: Add embedded eDMA doorbell fallback Koichiro Den
2026-02-16 16:24   ` Frank Li
2026-02-17  1:42     ` Koichiro Den
2026-02-17  4:00   ` Koichiro Den

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=aZNDYmR3e2z-VnZA@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

all inboxes | Powered by JetHome®