Re: [PATCH 07/10] NTB: epf: Make db_valid_mask cover only real doorbell bits
From: Koichiro Den
Date: Wed Feb 25 2026 - 20:26:20 EST
On Wed, Feb 25, 2026 at 04:07:14PM -0500, Frank Li wrote:
> On Tue, Feb 24, 2026 at 10:34:56PM +0900, Koichiro Den wrote:
> > ndev->db_count includes an unused doorbell slot due to the legacy extra
> > offset in the peer doorbell path. db_valid_mask must cover only the real
> > doorbell bits and exclude the unused slot.
> >
> > Set db_valid_mask to BIT_ULL(db_count - 1) - 1.
>
> db_count -1 or db_count-2, previous patch use db_count-2
pci-epf-vntb.c (struct epf_ntb) and ntb_hw_epf.c (struct ntb_epf_dev) define
"db_count" slightly differently, historically.
In pci-epf-vntb, db_count is configured via configfs and covers the entire
doorbell register range. The capacity is hard-wired into the shared register
space (e.g. db_data[MAX_DB_COUNT], db_offset[MAX_DB_COUNT]). The peer ringer
applies a +2 offset for DB, and that cannot be changed for interoperability
reasons.
In ntb_hw_epf, db_count subtracts one slot from the full range to exclude the
link event slot (#0). However, it still does not account for the legacy unused
slot (#1).
So effectively we have:
.---- pci-epf-vntb "db_count"
: .-- ntb_hw_epf "db_count"
: :
x #0 link event
x x #1 unused
x x #2 doorbell #0
x x #3 doorbell #1
x x ...
x x #N doorbell #(N-2)
This is why we see the apparent difference between "db_count - 1" and "db_count
- 2" in different places.
Koichiro
>
> Frank
> >
> > Fixes: 812ce2f8d14e ("NTB: Add support for EPF PCI Non-Transparent Bridge")
> > Signed-off-by: Koichiro Den <den@xxxxxxxxxxxxx>
> > ---
> > drivers/ntb/hw/epf/ntb_hw_epf.c | 8 +++++++-
> > 1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/ntb/hw/epf/ntb_hw_epf.c b/drivers/ntb/hw/epf/ntb_hw_epf.c
> > index bce7130fec39..ee499eaed4f3 100644
> > --- a/drivers/ntb/hw/epf/ntb_hw_epf.c
> > +++ b/drivers/ntb/hw/epf/ntb_hw_epf.c
> > @@ -580,7 +580,13 @@ static int ntb_epf_init_dev(struct ntb_epf_dev *ndev)
> > return ret;
> > }
> >
> > - ndev->db_valid_mask = BIT_ULL(ndev->db_count) - 1;
> > + if (ndev->db_count < NTB_EPF_MIN_DB_COUNT) {
> > + dev_err(dev, "db_count %u is less than %u\n", ndev->db_count,
> > + NTB_EPF_MIN_DB_COUNT);
> > + return -EINVAL;
> > + }
> > +
> > + ndev->db_valid_mask = BIT_ULL(ndev->db_count - 1) - 1;
> > ndev->mw_count = readl(ndev->ctrl_reg + NTB_EPF_MW_COUNT);
> > ndev->spad_count = readl(ndev->ctrl_reg + NTB_EPF_SPAD_COUNT);
> >
> > --
> > 2.51.0
> >