[RFC PATCH v4 20/38] NTB: ntb_transport: Move internal types to ntb_transport_internal.h

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

Move internal structs and definitions from ntb_transport_core.c into a
new internal header so they can be shared by upcoming split-out modules.

No functional change.

Signed-off-by: Koichiro Den <den@valinux.co.jp>
---
drivers/ntb/ntb_transport_core.c | 144 +-----------------------
drivers/ntb/ntb_transport_internal.h | 159 +++++++++++++++++++++++++++
2 files changed, 161 insertions(+), 142 deletions(-)
create mode 100644 drivers/ntb/ntb_transport_internal.h

diff --git a/drivers/ntb/ntb_transport_core.c b/drivers/ntb/ntb_transport_core.c
index 7b320249629c..71f01fa0ff05 100644
--- a/drivers/ntb/ntb_transport_core.c
+++ b/drivers/ntb/ntb_transport_core.c
@@ -64,6 +64,8 @@
#include "linux/ntb.h"
#include "linux/ntb_transport.h"

+#include "ntb_transport_internal.h"
+
#define NTB_TRANSPORT_VERSION 4
#define NTB_TRANSPORT_VER "4"
#define NTB_TRANSPORT_NAME "ntb_transport"
@@ -106,153 +108,12 @@ static struct dentry *nt_debugfs_dir;
/* Only two-ports NTB devices are supported */
#define PIDX NTB_DEF_PEER_IDX

-struct ntb_queue_entry {
- /* ntb_queue list reference */
- struct list_head entry;
- /* pointers to data to be transferred */
- void *cb_data;
- void *buf;
- unsigned int len;
- unsigned int flags;
- int retries;
- int errors;
- unsigned int tx_index;
- unsigned int rx_index;
-
- struct ntb_transport_qp *qp;
- union {
- struct ntb_payload_header __iomem *tx_hdr;
- struct ntb_payload_header *rx_hdr;
- };
-};
-
-struct ntb_rx_info {
- unsigned int entry;
-};
-
-struct ntb_transport_qp {
- struct ntb_transport_ctx *transport;
- struct ntb_dev *ndev;
- void *cb_data;
- struct dma_chan *tx_dma_chan;
- struct dma_chan *rx_dma_chan;
-
- bool client_ready;
- bool link_is_up;
- bool active;
-
- u8 qp_num; /* Only 64 QP's are allowed. 0-63 */
- u64 qp_bit;
-
- struct ntb_rx_info __iomem *rx_info;
- struct ntb_rx_info *remote_rx_info;
-
- void (*tx_handler)(struct ntb_transport_qp *qp, void *qp_data,
- void *data, int len);
- struct list_head tx_free_q;
- spinlock_t ntb_tx_free_q_lock;
- void __iomem *tx_mw;
- phys_addr_t tx_mw_phys;
- size_t tx_mw_size;
- dma_addr_t tx_mw_dma_addr;
- unsigned int tx_index;
- unsigned int tx_max_entry;
- unsigned int tx_max_frame;
-
- void (*rx_handler)(struct ntb_transport_qp *qp, void *qp_data,
- void *data, int len);
- struct list_head rx_post_q;
- struct list_head rx_pend_q;
- struct list_head rx_free_q;
- /* ntb_rx_q_lock: synchronize access to rx_XXXX_q */
- spinlock_t ntb_rx_q_lock;
- void *rx_buff;
- unsigned int rx_index;
- unsigned int rx_max_entry;
- unsigned int rx_max_frame;
- unsigned int rx_alloc_entry;
- dma_cookie_t last_cookie;
- struct tasklet_struct rxc_db_work;
-
- void (*event_handler)(void *data, int status);
- struct delayed_work link_work;
- struct work_struct link_cleanup;
-
- struct dentry *debugfs_dir;
- struct dentry *debugfs_stats;
-
- /* Stats */
- u64 rx_bytes;
- u64 rx_pkts;
- u64 rx_ring_empty;
- u64 rx_err_no_buf;
- u64 rx_err_oflow;
- u64 rx_err_ver;
- u64 rx_memcpy;
- u64 rx_async;
- u64 tx_bytes;
- u64 tx_pkts;
- u64 tx_ring_full;
- u64 tx_err_no_buf;
- u64 tx_memcpy;
- u64 tx_async;
-
- bool use_msi;
- int msi_irq;
- struct ntb_msi_desc msi_desc;
- struct ntb_msi_desc peer_msi_desc;
-};
-
-struct ntb_transport_mw {
- phys_addr_t phys_addr;
- resource_size_t phys_size;
- void __iomem *vbase;
- size_t xlat_size;
- size_t buff_size;
- size_t alloc_size;
- void *alloc_addr;
- void *virt_addr;
- dma_addr_t dma_addr;
-};
-
struct ntb_transport_client_dev {
struct list_head entry;
struct ntb_transport_ctx *nt;
struct device dev;
};

-struct ntb_transport_ctx {
- struct list_head entry;
- struct list_head client_devs;
-
- struct ntb_dev *ndev;
-
- struct ntb_transport_mw *mw_vec;
- struct ntb_transport_qp *qp_vec;
- unsigned int mw_count;
- unsigned int qp_count;
- u64 qp_bitmap;
- u64 qp_bitmap_free;
-
- bool use_msi;
- unsigned int msi_spad_offset;
- u64 msi_db_mask;
-
- bool link_is_up;
- struct delayed_work link_work;
- struct work_struct link_cleanup;
-
- struct dentry *debugfs_node_dir;
-
- /* Make sure workq of link event be executed serially */
- struct mutex link_event_lock;
-};
-
-enum {
- DESC_DONE_FLAG = BIT(0),
- LINK_DOWN_FLAG = BIT(1),
-};
-
struct ntb_payload_header {
unsigned int ver;
unsigned int len;
@@ -274,7 +135,6 @@ enum {
#define drv_client(__drv) \
container_of((__drv), struct ntb_transport_client, driver)

-#define QP_TO_MW(nt, qp) ((qp) % nt->mw_count)
#define NTB_QP_DEF_NUM_ENTRIES 100
#define NTB_LINK_DOWN_TIMEOUT 10

diff --git a/drivers/ntb/ntb_transport_internal.h b/drivers/ntb/ntb_transport_internal.h
new file mode 100644
index 000000000000..aff9b70671c6
--- /dev/null
+++ b/drivers/ntb/ntb_transport_internal.h
@@ -0,0 +1,159 @@
+/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
+/*
+ * Copyright(c) 2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2015 EMC Corporation. All Rights Reserved.
+ */
+#ifndef _NTB_TRANSPORT_INTERNAL_H_
+#define _NTB_TRANSPORT_INTERNAL_H_
+
+#include <linux/dcache.h>
+#include <linux/dmaengine.h>
+#include <linux/mutex.h>
+#include <linux/ntb.h>
+#include <linux/spinlock.h>
+#include <linux/types.h>
+
+#define QP_TO_MW(nt, qp) ((qp) % nt->mw_count)
+
+struct ntb_queue_entry {
+ /* ntb_queue list reference */
+ struct list_head entry;
+ /* pointers to data to be transferred */
+ void *cb_data;
+ void *buf;
+ unsigned int len;
+ unsigned int flags;
+ int retries;
+ int errors;
+ unsigned int tx_index;
+ unsigned int rx_index;
+
+ struct ntb_transport_qp *qp;
+ union {
+ struct ntb_payload_header __iomem *tx_hdr;
+ struct ntb_payload_header *rx_hdr;
+ };
+};
+
+struct ntb_rx_info {
+ unsigned int entry;
+};
+
+struct ntb_transport_qp {
+ struct ntb_transport_ctx *transport;
+ struct ntb_dev *ndev;
+ void *cb_data;
+ struct dma_chan *tx_dma_chan;
+ struct dma_chan *rx_dma_chan;
+
+ bool client_ready;
+ bool link_is_up;
+ bool active;
+
+ u8 qp_num; /* Only 64 QP's are allowed. 0-63 */
+ u64 qp_bit;
+
+ struct ntb_rx_info __iomem *rx_info;
+ struct ntb_rx_info *remote_rx_info;
+
+ void (*tx_handler)(struct ntb_transport_qp *qp, void *qp_data,
+ void *data, int len);
+ struct list_head tx_free_q;
+ spinlock_t ntb_tx_free_q_lock;
+ void __iomem *tx_mw;
+ phys_addr_t tx_mw_phys;
+ size_t tx_mw_size;
+ dma_addr_t tx_mw_dma_addr;
+ unsigned int tx_index;
+ unsigned int tx_max_entry;
+ unsigned int tx_max_frame;
+
+ void (*rx_handler)(struct ntb_transport_qp *qp, void *qp_data,
+ void *data, int len);
+ struct list_head rx_post_q;
+ struct list_head rx_pend_q;
+ struct list_head rx_free_q;
+ /* ntb_rx_q_lock: synchronize access to rx_XXXX_q */
+ spinlock_t ntb_rx_q_lock;
+ void *rx_buff;
+ unsigned int rx_index;
+ unsigned int rx_max_entry;
+ unsigned int rx_max_frame;
+ unsigned int rx_alloc_entry;
+ dma_cookie_t last_cookie;
+ struct tasklet_struct rxc_db_work;
+
+ void (*event_handler)(void *data, int status);
+ struct delayed_work link_work;
+ struct work_struct link_cleanup;
+
+ struct dentry *debugfs_dir;
+ struct dentry *debugfs_stats;
+
+ /* Stats */
+ u64 rx_bytes;
+ u64 rx_pkts;
+ u64 rx_ring_empty;
+ u64 rx_err_no_buf;
+ u64 rx_err_oflow;
+ u64 rx_err_ver;
+ u64 rx_memcpy;
+ u64 rx_async;
+ u64 tx_bytes;
+ u64 tx_pkts;
+ u64 tx_ring_full;
+ u64 tx_err_no_buf;
+ u64 tx_memcpy;
+ u64 tx_async;
+
+ bool use_msi;
+ int msi_irq;
+ struct ntb_msi_desc msi_desc;
+ struct ntb_msi_desc peer_msi_desc;
+};
+
+struct ntb_transport_mw {
+ phys_addr_t phys_addr;
+ resource_size_t phys_size;
+ void __iomem *vbase;
+ size_t xlat_size;
+ size_t buff_size;
+ size_t alloc_size;
+ void *alloc_addr;
+ void *virt_addr;
+ dma_addr_t dma_addr;
+};
+
+struct ntb_transport_ctx {
+ struct list_head entry;
+ struct list_head client_devs;
+
+ struct ntb_dev *ndev;
+
+ struct ntb_transport_mw *mw_vec;
+ struct ntb_transport_qp *qp_vec;
+ unsigned int mw_count;
+ unsigned int qp_count;
+ u64 qp_bitmap;
+ u64 qp_bitmap_free;
+
+ bool use_msi;
+ unsigned int msi_spad_offset;
+ u64 msi_db_mask;
+
+ bool link_is_up;
+ struct delayed_work link_work;
+ struct work_struct link_cleanup;
+
+ struct dentry *debugfs_node_dir;
+
+ /* Make sure workq of link event be executed serially */
+ struct mutex link_event_lock;
+};
+
+enum {
+ DESC_DONE_FLAG = BIT(0),
+ LINK_DOWN_FLAG = BIT(1),
+};
+
+#endif /* _NTB_TRANSPORT_INTERNAL_H_ */
--
2.51.0