[PATCH 06/15] PCI: endpoint: pci-epf-vntb: Fold MW runtime state into a struct

From: Koichiro Den

Date: Thu Mar 12 2026 - 12:56:06 EST


The next patches add per-memory-window offsets, shared BAR placement,
and optional DMA export state. Keeping per-window state in parallel
arrays would make that work noisy and error-prone.

Group the runtime memory-window state into struct epf_ntb_mw so
follow-up changes can extend a single object instead of touching
multiple arrays.

No functional change intended.

Signed-off-by: Koichiro Den <den@xxxxxxxxxxxxx>
---
drivers/pci/endpoint/functions/pci-epf-vntb.c | 42 ++++++++++---------
1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c
index bd9a3380a537..16656659a9ce 100644
--- a/drivers/pci/endpoint/functions/pci-epf-vntb.c
+++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c
@@ -128,6 +128,12 @@ struct epf_ntb_ctrl {
u32 db_offset[MAX_DB_COUNT];
} __packed;

+struct epf_ntb_mw {
+ u64 size;
+ phys_addr_t vpci_mw_phys;
+ void __iomem *vpci_mw_addr;
+};
+
struct epf_ntb {
struct ntb_dev ntb;
struct pci_epf *epf;
@@ -136,7 +142,7 @@ struct epf_ntb {
u32 num_mws;
u32 db_count;
u32 spad_count;
- u64 mws_size[MAX_MW];
+ struct epf_ntb_mw mw[MAX_MW];
atomic64_t db;
atomic64_t peer_db_pending;
struct work_struct peer_db_work;
@@ -159,9 +165,6 @@ struct epf_ntb {

u32 *epf_db;

- phys_addr_t vpci_mw_phy[MAX_MW];
- void __iomem *vpci_mw_addr[MAX_MW];
-
struct delayed_work cmd_handler;
};

@@ -227,7 +230,7 @@ static int epf_ntb_configure_mw(struct epf_ntb *ntb, u32 mw)
u64 addr, size;
int ret = 0;

- phys_addr = ntb->vpci_mw_phy[mw];
+ phys_addr = ntb->mw[mw].vpci_mw_phys;
addr = ntb->reg->addr;
size = ntb->reg->size;

@@ -254,7 +257,7 @@ static void epf_ntb_teardown_mw(struct epf_ntb *ntb, u32 mw)
pci_epc_unmap_addr(ntb->epf->epc,
ntb->epf->func_no,
ntb->epf->vfunc_no,
- ntb->vpci_mw_phy[mw]);
+ ntb->mw[mw].vpci_mw_phys);
}

/**
@@ -763,7 +766,7 @@ static int epf_ntb_mw_bar_init(struct epf_ntb *ntb)
struct device *dev = &ntb->epf->dev;

for (i = 0; i < ntb->num_mws; i++) {
- size = ntb->mws_size[i];
+ size = ntb->mw[i].size;
barno = ntb->epf_ntb_bar[BAR_MW1 + i];

ntb->epf->bar[barno].barno = barno;
@@ -784,10 +787,11 @@ static int epf_ntb_mw_bar_init(struct epf_ntb *ntb)
}

/* Allocate EPC outbound memory windows to vpci vntb device */
- ntb->vpci_mw_addr[i] = pci_epc_mem_alloc_addr(ntb->epf->epc,
- &ntb->vpci_mw_phy[i],
- size);
- if (!ntb->vpci_mw_addr[i]) {
+ ntb->mw[i].vpci_mw_addr =
+ pci_epc_mem_alloc_addr(ntb->epf->epc,
+ &ntb->mw[i].vpci_mw_phys,
+ size);
+ if (!ntb->mw[i].vpci_mw_addr) {
ret = -ENOMEM;
dev_err(dev, "Failed to allocate source address\n");
goto err_set_bar;
@@ -824,9 +828,9 @@ static void epf_ntb_mw_bar_clear(struct epf_ntb *ntb, int num_mws)
&ntb->epf->bar[barno]);

pci_epc_mem_free_addr(ntb->epf->epc,
- ntb->vpci_mw_phy[i],
- ntb->vpci_mw_addr[i],
- ntb->mws_size[i]);
+ ntb->mw[i].vpci_mw_phys,
+ ntb->mw[i].vpci_mw_addr,
+ ntb->mw[i].size);
}
}

@@ -1065,7 +1069,7 @@ static ssize_t epf_ntb_##_name##_show(struct config_item *item, \
return -ERANGE; \
} \
idx = array_index_nospec(idx, ntb->num_mws); \
- return sprintf(page, "%llu\n", ntb->mws_size[idx]); \
+ return sprintf(page, "%llu\n", ntb->mw[idx].size); \
}

#define EPF_NTB_MW_W(_name) \
@@ -1093,7 +1097,7 @@ static ssize_t epf_ntb_##_name##_store(struct config_item *item, \
return -ERANGE; \
} \
idx = array_index_nospec(idx, ntb->num_mws); \
- ntb->mws_size[idx] = val; \
+ ntb->mw[idx].size = val; \
\
return len; \
}
@@ -1400,10 +1404,10 @@ static int vntb_epf_peer_mw_get_addr(struct ntb_dev *ndev, int idx,
struct epf_ntb *ntb = ntb_ndev(ndev);

if (base)
- *base = ntb->vpci_mw_phy[idx];
+ *base = ntb->mw[idx].vpci_mw_phys;

if (size)
- *size = ntb->mws_size[idx];
+ *size = ntb->mw[idx].size;

return 0;
}
@@ -1556,7 +1560,7 @@ static int vntb_epf_mw_get_align(struct ntb_dev *ndev, int pidx, int idx,
*size_align = 1;

if (size_max)
- *size_max = ntb->mws_size[idx];
+ *size_max = ntb->mw[idx].size;

return 0;
}
--
2.51.0