[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260118135440.1958279-10-den@valinux.co.jp>
Date: Sun, 18 Jan 2026 22:54:11 +0900
From: Koichiro Den <den@...inux.co.jp>
To: Frank.Li@....com,
dave.jiang@...el.com,
cassel@...nel.org,
mani@...nel.org,
kwilczynski@...nel.org,
kishon@...nel.org,
bhelgaas@...gle.com,
geert+renesas@...der.be,
robh@...nel.org,
vkoul@...nel.org,
jdmason@...zu.us,
allenbh@...il.com,
jingoohan1@...il.com,
lpieralisi@...nel.org
Cc: linux-pci@...r.kernel.org,
linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org,
linux-renesas-soc@...r.kernel.org,
devicetree@...r.kernel.org,
dmaengine@...r.kernel.org,
iommu@...ts.linux.dev,
ntb@...ts.linux.dev,
netdev@...r.kernel.org,
linux-kselftest@...r.kernel.org,
arnd@...db.de,
gregkh@...uxfoundation.org,
joro@...tes.org,
will@...nel.org,
robin.murphy@....com,
magnus.damm@...il.com,
krzk+dt@...nel.org,
conor+dt@...nel.org,
corbet@....net,
skhan@...uxfoundation.org,
andriy.shevchenko@...ux.intel.com,
jbrunet@...libre.com,
utkarsh02t@...il.com
Subject: [RFC PATCH v4 09/38] NTB: core: Add mw_set_trans_ranges() for subrange programming
At the BAR level, multiple MWs may be packed into a single BAR. In
addition, a single MW may itself be subdivided into multiple address
subranges, each of which can be mapped independently by the underlying
NTB hardware.
Introduce an optional ntb_dev_ops callback, .mw_set_trans_ranges(), to
describe and program such layouts explicitly. The helper allows an NTB
driver to provide, for each MW, a list of contiguous subranges that
together cover the MW address space.
Signed-off-by: Koichiro Den <den@...inux.co.jp>
---
include/linux/ntb.h | 46 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/include/linux/ntb.h b/include/linux/ntb.h
index 8ff9d663096b..84908753f446 100644
--- a/include/linux/ntb.h
+++ b/include/linux/ntb.h
@@ -206,6 +206,11 @@ static inline int ntb_ctx_ops_is_valid(const struct ntb_ctx_ops *ops)
1;
}
+struct ntb_mw_subrange {
+ dma_addr_t addr;
+ resource_size_t size;
+};
+
/**
* struct ntb_dev_ops - ntb device operations
* @port_number: See ntb_port_number().
@@ -218,6 +223,7 @@ static inline int ntb_ctx_ops_is_valid(const struct ntb_ctx_ops *ops)
* @mw_count: See ntb_mw_count().
* @mw_get_align: See ntb_mw_get_align().
* @mw_set_trans: See ntb_mw_set_trans().
+ * @mw_set_trans_ranges:See ntb_mw_set_trans_ranges().
* @mw_clear_trans: See ntb_mw_clear_trans().
* @peer_mw_count: See ntb_peer_mw_count().
* @peer_mw_get_addr: See ntb_peer_mw_get_addr().
@@ -276,6 +282,9 @@ struct ntb_dev_ops {
resource_size_t *size_max);
int (*mw_set_trans)(struct ntb_dev *ntb, int pidx, int widx,
dma_addr_t addr, resource_size_t size);
+ int (*mw_set_trans_ranges)(struct ntb_dev *ntb, int pidx, int widx,
+ unsigned int num_ranges,
+ const struct ntb_mw_subrange *ranges);
int (*mw_clear_trans)(struct ntb_dev *ntb, int pidx, int widx);
int (*peer_mw_count)(struct ntb_dev *ntb);
int (*peer_mw_get_addr)(struct ntb_dev *ntb, int widx,
@@ -350,6 +359,7 @@ static inline int ntb_dev_ops_is_valid(const struct ntb_dev_ops *ops)
ops->mw_get_align &&
(ops->mw_set_trans ||
ops->peer_mw_set_trans) &&
+ /* ops->mw_set_trans_ranges && */
/* ops->mw_clear_trans && */
ops->peer_mw_count &&
ops->peer_mw_get_addr &&
@@ -860,6 +870,42 @@ static inline int ntb_mw_set_trans(struct ntb_dev *ntb, int pidx, int widx,
return ntb->ops->mw_set_trans(ntb, pidx, widx, addr, size);
}
+/**
+ * ntb_mw_set_trans_ranges() - set the translations of an inbound memory
+ * window, composed of multiple subranges.
+ * @ntb: NTB device context.
+ * @pidx: Port index of peer device.
+ * @widx: Memory window index.
+ * @num_ranges: The number of ranges described by @ranges array.
+ * @ranges: Array of subranges. The subranges are interpreted in ascending
+ * window offset order (i.e. ranges[0] maps the first part of the MW,
+ * ranges[1] the next part, ...).
+ *
+ * Return: Zero on success, otherwise an error number. If the driver does
+ * not implement the callback, return -EOPNOTSUPP.
+ */
+static inline int ntb_mw_set_trans_ranges(struct ntb_dev *ntb, int pidx, int widx,
+ unsigned int num_ranges,
+ const struct ntb_mw_subrange *ranges)
+{
+ if (!num_ranges || !ranges)
+ return -EINVAL;
+
+ if (ntb->ops->mw_set_trans_ranges)
+ return ntb->ops->mw_set_trans_ranges(ntb, pidx, widx,
+ num_ranges, ranges);
+
+ /*
+ * Fallback for drivers that only support the legacy single-range
+ * translation API.
+ */
+ if (num_ranges == 1)
+ return ntb_mw_set_trans(ntb, pidx, widx,
+ ranges[0].addr, ranges[0].size);
+
+ return -EOPNOTSUPP;
+}
+
/**
* ntb_mw_clear_trans() - clear the translation address of an inbound memory
* window
--
2.51.0
Powered by blists - more mailing lists