[PATCH 15/16] NTB: ntb_transport: Report the direct-DMA payload limit

Koichiro Den <[email protected]>
Newsgroups dev.linux.lists.ntb,org.kernel.vger.linux-kernel,org.kernel.vger.netdev
Message-ID <[email protected]>
ntb_transport_max_size() currently reports the copy-path limit, which
reserves space for struct ntb_payload_header. Direct DMA bypasses that
layout, so the same limit is unnecessarily restrictive.

For active direct-DMA TX, derive the limit from the DMA device's segment
and mapping limits. Keep it within INT_MAX because transport callbacks
report lengths as int. Continue reporting the copy-path limit until direct
TX is active.

This lets ntb_netdev use ETH_MAX_MTU over direct DMA. If the queue later
falls back to the copy path, larger frames are rejected.

Signed-off-by: Koichiro Den <[email protected]>
---
 drivers/ntb/ntb_transport.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index 9f5d6a407be7..2f69328d5201 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -3787,10 +3787,19 @@ unsigned int ntb_transport_max_size(struct ntb_transport_qp *qp)
 	unsigned int max_size;
 	unsigned int copy_align;
 	struct dma_chan *rx_chan, *tx_chan;
+	struct device *dma_dev;
 
 	if (!qp)
 		return 0;
 
+	if (ntb_transport_link_query(qp) && ntb_direct_tx_enabled(qp)) {
+		dma_dev = dmaengine_get_dma_device(qp->direct_dma_chan);
+		max_size = min_t(size_t, dma_get_max_seg_size(dma_dev),
+				 dma_max_mapping_size(dma_dev));
+
+		return min_t(unsigned int, max_size, INT_MAX);
+	}
+
 	rx_chan = qp->rx_dma_chan;
 	tx_chan = qp->tx_dma_chan;
 
-- 
2.51.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.