1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation.
10 extern int ntb_logtype;
12 #define NTB_LOG(level, fmt, args...) \
13 rte_log(RTE_LOG_ ## level, ntb_logtype, "%s(): " fmt "\n", \
17 #define NTB_INTEL_VENDOR_ID 0x8086
20 #define NTB_INTEL_DEV_ID_B2B_SKX 0x201C
22 /* Reserved to app to use. */
23 #define NTB_SPAD_USER "spad_user_"
24 #define NTB_SPAD_USER_LEN (sizeof(NTB_SPAD_USER) - 1)
25 #define NTB_SPAD_USER_MAX_NUM 4
26 #define NTB_ATTR_NAME_LEN 30
28 #define NTB_DFLT_TX_FREE_THRESH 256
69 /* Define spad registers usage. 0 is reserved. */
86 * NTB device operations
87 * @ntb_dev_init: Init ntb dev.
88 * @get_peer_mw_addr: To get the addr of peer mw[mw_idx].
89 * @mw_set_trans: Set translation of internal memory that remote can access.
90 * @ioremap: Translate the remote host address to bar address.
91 * @get_link_status: get link status, link speed and link width.
92 * @set_link: Set local side up/down.
93 * @spad_read: Read local/peer spad register val.
94 * @spad_write: Write val to local/peer spad register.
95 * @db_read: Read doorbells status.
96 * @db_clear: Clear local doorbells.
97 * @db_set_mask: Set bits in db mask, preventing db interrpts generated
99 * @peer_db_set: Set doorbell bit to generate peer interrupt for that bit.
100 * @vector_bind: Bind vector source [intr] to msix vector [msix].
103 int (*ntb_dev_init)(const struct rte_rawdev *dev);
104 void *(*get_peer_mw_addr)(const struct rte_rawdev *dev, int mw_idx);
105 int (*mw_set_trans)(const struct rte_rawdev *dev, int mw_idx,
106 uint64_t addr, uint64_t size);
107 void *(*ioremap)(const struct rte_rawdev *dev, uint64_t addr);
108 int (*get_link_status)(const struct rte_rawdev *dev);
109 int (*set_link)(const struct rte_rawdev *dev, bool up);
110 uint32_t (*spad_read)(const struct rte_rawdev *dev, int spad,
112 int (*spad_write)(const struct rte_rawdev *dev, int spad,
113 bool peer, uint32_t spad_v);
114 uint64_t (*db_read)(const struct rte_rawdev *dev);
115 int (*db_clear)(const struct rte_rawdev *dev, uint64_t db_bits);
116 int (*db_set_mask)(const struct rte_rawdev *dev, uint64_t db_mask);
117 int (*peer_db_set)(const struct rte_rawdev *dev, uint8_t db_bit);
118 int (*vector_bind)(const struct rte_rawdev *dev, uint8_t intr,
123 uint64_t addr; /* buffer addr */
124 uint16_t len; /* buffer length */
129 #define NTB_FLAG_EOP 1 /* end of packet */
131 uint16_t len; /* buffer length */
132 uint16_t flags; /* flags */
135 struct ntb_rx_entry {
136 struct rte_mbuf *mbuf;
139 struct ntb_rx_queue {
140 struct ntb_desc *rx_desc_ring;
141 volatile struct ntb_used *rx_used_ring;
143 volatile uint16_t *used_cnt;
148 uint16_t rx_free_thresh;
150 struct rte_mempool *mpool; /* mempool for mbuf allocation */
151 struct ntb_rx_entry *sw_ring;
153 uint16_t queue_id; /* DPDK queue index. */
154 uint16_t port_id; /* Device port identifier. */
159 struct ntb_tx_entry {
160 struct rte_mbuf *mbuf;
165 struct ntb_tx_queue {
166 volatile struct ntb_desc *tx_desc_ring;
167 struct ntb_used *tx_used_ring;
168 volatile uint16_t *avail_cnt;
170 uint16_t last_avail; /* Next need to be free. */
171 uint16_t last_used; /* Next need to be sent. */
174 /* Total number of TX descriptors ready to be allocated. */
176 uint16_t tx_free_thresh;
178 struct ntb_tx_entry *sw_ring;
180 uint16_t queue_id; /* DPDK queue index. */
181 uint16_t port_id; /* Device port identifier. */
187 uint16_t avail_cnt __rte_cache_aligned;
188 uint16_t used_cnt __rte_cache_aligned;
189 struct ntb_desc desc_ring[] __rte_cache_aligned;
192 /* ntb private data. */
198 uint64_t db_valid_mask;
203 enum ntb_link link_status;
204 enum ntb_speed link_speed;
205 enum ntb_width link_width;
207 const struct ntb_dev_ops *ntb_ops;
209 struct rte_pci_device *pci_dev;
214 /* remote mem base addr */
215 uint64_t *peer_mw_base;
217 uint16_t queue_pairs;
219 uint32_t hdr_size_per_queue;
221 struct ntb_rx_queue **rx_queues;
222 struct ntb_tx_queue **tx_queues;
224 /* memzone to populate RX ring. */
225 const struct rte_memzone **mz;
228 uint8_t peer_used_mws;
230 uint64_t *ntb_xstats;
231 uint64_t *ntb_xstats_off;
233 /* Reserve several spad for app to use. */
234 int spad_user_list[NTB_SPAD_USER_MAX_NUM];