[RFC PATCH v4 07/38] NTB: epf: Reserve a subset of MSI vectors for non-NTB users

Koichiro Den
2026-01-18T13:55:11Z

The ntb_hw_epf driver currently uses all MSI/MSI-X vectors allocated for
the endpoint as doorbell interrupts. On SoCs that also run other
functions on the same PCIe controller (e.g. DesignWare eDMA), we need to
reserve some vectors for those other consumers.

Introduce NTB_EPF_IRQ_RESERVE and track the total number of allocated
vectors in ntb_epf_dev's 'num_irqs' field. Use only (num_irqs -
NTB_EPF_IRQ_RESERVE) vectors for NTB doorbells and free all num_irqs
vectors in the teardown path, so that the remaining vectors can be used
by other endpoint functions such as the integrated DesignWare eDMA.

This makes it possible to share the PCIe controller MSI space between
NTB and other on-chip IP blocks.

Signed-off-by: Koichiro Den <den@valinux.co.jp>
---
drivers/ntb/hw/epf/ntb_hw_epf.c | 36 ++++++++++++++++++++++-----------
1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/drivers/ntb/hw/epf/ntb_hw_epf.c b/drivers/ntb/hw/epf/ntb_hw_epf.c
index 4b3fa996219a..dbb5bebe63a5 100644
--- a/drivers/ntb/hw/epf/ntb_hw_epf.c
+++ b/drivers/ntb/hw/epf/ntb_hw_epf.c
@@ -54,6 +54,7 @@

#define NTB_EPF_MIN_DB_COUNT 3
#define NTB_EPF_MAX_DB_COUNT 31
+#define NTB_EPF_IRQ_RESERVE 8

#define NTB_EPF_COMMAND_TIMEOUT 1000 /* 1 Sec */

@@ -92,6 +93,9 @@ struct ntb_epf_dev {
unsigned int spad_count;
unsigned int db_count;

+ unsigned int num_irqs;
+ unsigned int num_ntb_irqs;
+
void __iomem *ctrl_reg;
void __iomem *db_reg;
void __iomem *peer_spad_reg;
@@ -345,7 +349,7 @@ static int ntb_epf_init_isr(struct ntb_epf_dev *ndev, int msi_min, int msi_max)
u32 argument = MSIX_ENABLE;
int irq;
int ret;
- int i;
+ int i = 0;

irq = pci_alloc_irq_vectors(pdev, msi_min, msi_max, PCI_IRQ_MSIX);
if (irq < 0) {
@@ -359,33 +363,40 @@ static int ntb_epf_init_isr(struct ntb_epf_dev *ndev, int msi_min, int msi_max)
argument &= ~MSIX_ENABLE;
}

+ ndev->num_irqs = irq;
+ irq -= NTB_EPF_IRQ_RESERVE;
+ if (irq <= 0) {
+ dev_err(dev, "Not enough irqs allocated\n");
+ ret = -ENOSPC;
+ goto err_out;
+ }
+ ndev->num_ntb_irqs = irq;
+
for (i = 0; i < irq; i++) {
ret = request_irq(pci_irq_vector(pdev, i), ntb_epf_vec_isr,
0, "ntb_epf", ndev);
if (ret) {
dev_err(dev, "Failed to request irq\n");
- goto err_request_irq;
+ goto err_out;
}
}

- ndev->db_count = irq - 1;
+ ndev->db_count = irq;

ret = ntb_epf_send_command(ndev, CMD_CONFIGURE_DOORBELL,
argument | irq);
if (ret) {
dev_err(dev, "Failed to configure doorbell\n");
- goto err_configure_db;
+ goto err_out;
}

return 0;

-err_configure_db:
- for (i = 0; i < ndev->db_count + 1; i++)
+err_out:
+ while (i-- > 0)
free_irq(pci_irq_vector(pdev, i), ndev);

-err_request_irq:
pci_free_irq_vectors(pdev);
-
return ret;
}

@@ -502,7 +513,7 @@ static int ntb_epf_peer_db_set(struct ntb_dev *ntb, u64 db_bits)
u32 db_offset;
u32 db_data;

- if (interrupt_num > ndev->db_count) {
+ if (interrupt_num >= ndev->db_count) {
dev_err(dev, "DB interrupt %d greater than Max Supported %d\n",
interrupt_num, ndev->db_count);
return -EINVAL;
@@ -512,6 +523,7 @@ static int ntb_epf_peer_db_set(struct ntb_dev *ntb, u64 db_bits)

db_data = readl(ndev->ctrl_reg + NTB_EPF_DB_DATA(interrupt_num));
db_offset = readl(ndev->ctrl_reg + NTB_EPF_DB_OFFSET(interrupt_num));
+
writel(db_data, ndev->db_reg + (db_entry_size * interrupt_num) +
db_offset);

@@ -595,8 +607,8 @@ static int ntb_epf_init_dev(struct ntb_epf_dev *ndev)
int ret;

/* One Link interrupt and rest doorbell interrupt */
- ret = ntb_epf_init_isr(ndev, NTB_EPF_MIN_DB_COUNT + 1,
- NTB_EPF_MAX_DB_COUNT + 1);
+ ret = ntb_epf_init_isr(ndev, NTB_EPF_MIN_DB_COUNT + NTB_EPF_IRQ_RESERVE,
+ NTB_EPF_MAX_DB_COUNT + NTB_EPF_IRQ_RESERVE);
if (ret) {
dev_err(dev, "Failed to init ISR\n");
return ret;
@@ -704,7 +716,7 @@ static void ntb_epf_cleanup_isr(struct ntb_epf_dev *ndev)

ntb_epf_send_command(ndev, CMD_TEARDOWN_DOORBELL, ndev->db_count + 1);

- for (i = 0; i < ndev->db_count + 1; i++)
+ for (i = 0; i < ndev->num_ntb_irqs; i++)
free_irq(pci_irq_vector(pdev, i), ndev);
pci_free_irq_vectors(pdev);
}
--
2.51.0