summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoichiro Den <den@valinux.co.jp>2026-05-13 11:49:18 +0900
committerBjorn Helgaas <bhelgaas@google.com>2026-06-23 11:37:27 -0500
commit2579f3f7f52090463596765040aaad71e91ef4d5 (patch)
tree54cf3f34dda54eb3451882459d8e00b1c7b1f86b
parent823468a4ea1613f1c1235bd16af8b9c6eb9c9677 (diff)
PCI: endpoint: pci-epf-vntb: Implement .db_vector_count()/mask() for doorbells
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. Build db_valid_mask from a validated vector count so out-of-range db_count values cannot create invalid shifts. Signed-off-by: Koichiro Den <den@valinux.co.jp> Signed-off-by: Manivannan Sadhasivam <mani@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> Link: https://patch.msgid.link/20260513024923.451765-8-den@valinux.co.jp
-rw-r--r--drivers/pci/endpoint/functions/pci-epf-vntb.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c
index 58e41d95d029..c3caec927d74 100644
--- a/drivers/pci/endpoint/functions/pci-epf-vntb.c
+++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c
@@ -1362,12 +1362,48 @@ 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);
+ u32 db_count = READ_ONCE(ndev->db_count);
+
+ /*
+ * 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 (db_count < MIN_DB_COUNT || db_count > MAX_DB_COUNT)
+ return 0;
+
+ return db_count - EPF_IRQ_DB_START;
+}
+
static u64 vntb_epf_db_valid_mask(struct ntb_dev *ntb)
{
- if (ntb_ndev(ntb)->db_count < EPF_IRQ_DB_START)
+ int nr_vec = vntb_epf_db_vector_count(ntb);
+
+ if (!nr_vec)
+ return 0;
+
+ return GENMASK_ULL(nr_vec - 1, 0);
+}
+
+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 - EPF_IRQ_DB_START) - 1;
+ return BIT_ULL(db_vector);
}
static int vntb_epf_db_set_mask(struct ntb_dev *ntb, u64 db_bits)
@@ -1617,6 +1653,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,