]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PCI: endpoint: pci-epf-vntb: Reject unusable doorbell counts
authorKoichiro Den <den@valinux.co.jp>
Wed, 13 May 2026 02:49:15 +0000 (11:49 +0900)
committerBjorn Helgaas <bhelgaas@google.com>
Mon, 22 Jun 2026 20:31:11 +0000 (15:31 -0500)
pci-epf-vntb reserves slot 0 for link events and keeps slot 1 unused for
legacy layout compatibility. A db_count smaller than MIN_DB_COUNT leaves
no usable doorbell slot after those reservations.

Reject such configurations when configuring interrupts.

While at it, move MAX_DB_COUNT next to MIN_DB_COUNT. They are used as a
pair in the range check, and keeping them together makes the valid doorbell
range easier to read.

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-5-den@valinux.co.jp
drivers/pci/endpoint/functions/pci-epf-vntb.c

index d31e2eee086991067fecbab47faf5f0601de2a5e..818ae59999766b0a06c4e890f399f9bc452d3fc5 100644 (file)
@@ -67,7 +67,6 @@ static struct workqueue_struct *kpcintb_workqueue;
 #define NTB_MW_OFFSET                  2
 #define DB_COUNT_MASK                  GENMASK(15, 0)
 #define MSIX_ENABLE                    BIT(16)
-#define MAX_DB_COUNT                   32
 #define MAX_MW                         4
 
 /* Limit per-work execution to avoid monopolizing kworker on doorbell storms. */
@@ -89,6 +88,9 @@ enum epf_irq_slot {
        EPF_IRQ_DB_START,
 };
 
+#define MIN_DB_COUNT                   (EPF_IRQ_DB_START + 1)
+#define MAX_DB_COUNT                   32
+
 /*
  * +--------------------------------------------------+ Base
  * |                                                  |
@@ -512,9 +514,9 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb)
                return -EINVAL;
        }
 
-       if (!ntb->db_count || ntb->db_count > MAX_DB_COUNT) {
-               dev_err(dev, "DB count %d out of range (1 - %d)\n",
-                       ntb->db_count, MAX_DB_COUNT);
+       if (ntb->db_count < MIN_DB_COUNT || ntb->db_count > MAX_DB_COUNT) {
+               dev_err(dev, "DB count %d out of range (%d - %d)\n",
+                       ntb->db_count, MIN_DB_COUNT, MAX_DB_COUNT);
                return -EINVAL;
        }