Re: [PATCH 05/10] PCI: endpoint: pci-epf-vntb: Implement db_vector_count/mask for doorbells
Koichiro Den <[email protected]> Fri, 27 Feb 2026 15:23:53 +0900
| Newsgroups | dev.linux.lists.ntb,org.kernel.vger.linux-kernel,org.kernel.vger.linux-pci |
|---|---|
| Message-ID | <cizc5inlzty54m54zj2aenk3btdpof5a546jexyukzhfjzygew@3ujqgv5exkve> |
On Wed, Feb 25, 2026 at 04:02:01PM -0500, Frank Li wrote: > On Tue, Feb 24, 2026 at 10:34:54PM +0900, Koichiro Den wrote: > > Implement .db_vector_count and .db_vector_mask so ntb core/clients can map > > doorbell events to per-vector work and avoid the thundering-herd behavior. > > > > pci-epf-vntb reserves two slots in db_count: slot 0 for link events and > > slot 1 which is historically unused. Therefore the number of doorbell > > vectors is (db_count - 2). > > > > Report vectors as 0..N-1 and return BIT_ULL(db_vector) for the > > corresponding doorbell bit. While at it, use vntb_epf_db_vector_mask() > > to simplify vntb_epf_db_valid_mask(). > > > > Signed-off-by: Koichiro Den <[email protected]> > > --- > > drivers/pci/endpoint/functions/pci-epf-vntb.c | 36 +++++++++++++++++-- > > 1 file changed, 34 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c > > index 2eb3db035644..b651c54d6bef 100644 > > --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c > > +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c > > @@ -1267,12 +1267,42 @@ static int vntb_epf_peer_mw_count(struct ntb_dev *ntb) > > return ntb_ndev(ntb)->num_mws; > > } > > > > +static int vntb_epf_db_vector_count(struct ntb_dev *ntb) > > +{ > > + struct epf_ntb *ndev = ntb_ndev(ntb); > > + > > + /* > > + * ndev->db_count is the total number of doorbell slots exposed to > > + * the peer, including: > > + * - slot #0 reserved for link events > > + * - slot #1 historically unused (kept for protocol compatibility) > > + * > > + * Report only usable per-vector doorbell interrupts. > > + */ > > + if (ndev->db_count < 2) > > + return 0; > > + > > + return ndev->db_count - 2; > > return max(ndev->db_count - 2, 0); db_count is u32, so it could underflow. If a one-liner is preferred, something like: max_t(u32, ndev->db_count, 2U) - 2 would work. Personally, I think the original version is clearer. Thanks, Koichiro > > Frank > > +} > > + > > static u64 vntb_epf_db_valid_mask(struct ntb_dev *ntb) > > { > > - if (ntb_ndev(ntb)->db_count < 2) > > + return BIT_ULL(vntb_epf_db_vector_count(ntb)) - 1; > > +} > > + > > +static u64 vntb_epf_db_vector_mask(struct ntb_dev *ntb, int db_vector) > > +{ > > + int nr_vec; > > + > > + /* > > + * Doorbell vectors are numbered [0 .. nr_vec - 1], where nr_vec > > + * excludes the two reserved slots described above. > > + */ > > + nr_vec = vntb_epf_db_vector_count(ntb); > > + if (db_vector < 0 || db_vector >= nr_vec) > > return 0; > > > > - return BIT_ULL(ntb_ndev(ntb)->db_count - 2) - 1; > > + return BIT_ULL(db_vector); > > } > > > > static int vntb_epf_db_set_mask(struct ntb_dev *ntb, u64 db_bits) > > @@ -1512,6 +1542,8 @@ static const struct ntb_dev_ops vntb_epf_ops = { > > .spad_count = vntb_epf_spad_count, > > .peer_mw_count = vntb_epf_peer_mw_count, > > .db_valid_mask = vntb_epf_db_valid_mask, > > + .db_vector_count = vntb_epf_db_vector_count, > > + .db_vector_mask = vntb_epf_db_vector_mask, > > .db_set_mask = vntb_epf_db_set_mask, > > .mw_set_trans = vntb_epf_mw_set_trans, > > .mw_clear_trans = vntb_epf_mw_clear_trans, > > -- > > 2.51.0 > >