Re: [PATCH 03/10] PCI: endpoint: pci-epf-vntb: Report 0-based doorbell vector via ntb_db_event()

Frank Li <[email protected]> Wed, 25 Feb 2026 15:54:16 -0500
Newsgroups dev.linux.lists.ntb,org.kernel.vger.linux-kernel,org.kernel.vger.linux-pci
Message-ID <aZ9heHxFL66Z4raB@lizhi-Precision-Tower-5810>
On Tue, Feb 24, 2026 at 10:34:52PM +0900, Koichiro Den wrote:
> ntb_db_event() expects the vector number to be relative to the first
> doorbell vector starting at 0.
>
> pci-epf-vntb reserves vector 0 for link events and uses higher vector
> indices for doorbells. By passing the raw slot index to ntb_db_event(),
> it effectively assumes that doorbell 0 maps to vector 1.
>
> However, because the host uses a legacy slot layout and writes doorbell
> 0 into the third slot, doorbell 0 ultimately appears as vector 2 from
> the NTB core perspective.
>
> Adjust pci-epf-vntb to:
>   - skip the unused second slot, and
>   - report doorbells as 0-based vectors (DB#0 -> vector 0).
>
> This change does not introduce a behavioral difference until
> .db_vector_count()/.db_vector_mask() are implemented, because without
> those callbacks NTB clients effectively ignore the vector number.
>
> Fixes: e35f56bb0330 ("PCI: endpoint: Support NTB transfer between RC and EP")
> Signed-off-by: Koichiro Den <[email protected]>
> ---
Reviewed-by: Frank Li <[email protected]>
>  drivers/pci/endpoint/functions/pci-epf-vntb.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c
> index c00898ac8269..cbce50afc4dc 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c
> @@ -266,10 +266,10 @@ static void epf_ntb_cmd_handler(struct work_struct *work)
>
>  	ntb = container_of(work, struct epf_ntb, cmd_handler.work);
>
> -	for (i = 1; i < ntb->db_count && !ntb->msi_doorbell; i++) {
> +	for (i = 2; i < ntb->db_count && !ntb->msi_doorbell; i++) {
>  		if (ntb->epf_db[i]) {
> -			atomic64_or(1 << (i - 1), &ntb->db);
> -			ntb_db_event(&ntb->ntb, i);
> +			atomic64_or(1 << (i - 2), &ntb->db);
> +			ntb_db_event(&ntb->ntb, i - 2);
>  			ntb->epf_db[i] = 0;
>  		}
>  	}
> @@ -335,10 +335,10 @@ static irqreturn_t epf_ntb_doorbell_handler(int irq, void *data)
>  	struct epf_ntb *ntb = data;
>  	int i;
>
> -	for (i = 1; i < ntb->db_count; i++)
> +	for (i = 2; i < ntb->db_count; i++)
>  		if (irq == ntb->epf->db_msg[i].virq) {
> -			atomic64_or(1 << (i - 1), &ntb->db);
> -			ntb_db_event(&ntb->ntb, i);
> +			atomic64_or(1 << (i - 2), &ntb->db);
> +			ntb_db_event(&ntb->ntb, i - 2);
>  		}
>
>  	return IRQ_HANDLED;
> --
> 2.51.0
>