1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2014-2021 Netronome Systems, Inc.
7 * vim:shiftwidth=8:noexpandtab
9 * @file dpdk/pmd/nfp_rxtx.h
11 * Netronome NFP Rx/Tx specific header file
17 #include <linux/types.h>
20 #define NFP_DESC_META_LEN(d) ((d)->rxd.meta_len_dd & PCIE_DESC_RX_META_LEN_MASK)
22 #define NFP_HASH_OFFSET ((uint8_t *)mbuf->buf_addr + mbuf->data_off - 4)
23 #define NFP_HASH_TYPE_OFFSET ((uint8_t *)mbuf->buf_addr + mbuf->data_off - 8)
25 #define RTE_MBUF_DMA_ADDR_DEFAULT(mb) \
26 ((uint64_t)((mb)->buf_iova + RTE_PKTMBUF_HEADROOM))
29 * The maximum number of descriptors is limited by design as
30 * DPDK uses uint16_t variables for these values
32 #define NFP_NET_MAX_TX_DESC (32 * 1024)
33 #define NFP_NET_MIN_TX_DESC 256
35 #define NFP_NET_MAX_RX_DESC (32 * 1024)
36 #define NFP_NET_MIN_RX_DESC 256
38 /* Descriptor alignment */
39 #define NFP_ALIGN_RING_DESC 128
41 /* TX descriptor format */
42 #define PCIE_DESC_TX_EOP (1 << 7)
43 #define PCIE_DESC_TX_OFFSET_MASK (0x7f)
45 /* Flags in the host TX descriptor */
46 #define PCIE_DESC_TX_CSUM (1 << 7)
47 #define PCIE_DESC_TX_IP4_CSUM (1 << 6)
48 #define PCIE_DESC_TX_TCP_CSUM (1 << 5)
49 #define PCIE_DESC_TX_UDP_CSUM (1 << 4)
50 #define PCIE_DESC_TX_VLAN (1 << 3)
51 #define PCIE_DESC_TX_LSO (1 << 2)
52 #define PCIE_DESC_TX_ENCAP_NONE (0)
53 #define PCIE_DESC_TX_ENCAP_VXLAN (1 << 1)
54 #define PCIE_DESC_TX_ENCAP_GRE (1 << 0)
56 #define NFDK_TX_MAX_DATA_PER_HEAD 0x00001000
57 #define NFDK_DESC_TX_DMA_LEN_HEAD 0x0fff
58 #define NFDK_DESC_TX_TYPE_HEAD 0xf000
59 #define NFDK_DESC_TX_DMA_LEN 0x3fff
60 #define NFDK_TX_DESC_PER_SIMPLE_PKT 2
61 #define NFDK_DESC_TX_TYPE_TSO 2
62 #define NFDK_DESC_TX_TYPE_SIMPLE 8
63 #define NFDK_DESC_TX_TYPE_GATHER 1
64 #define NFDK_DESC_TX_EOP BIT(14)
65 #define NFDK_DESC_TX_L4_CSUM BIT(1)
66 #define NFDK_DESC_TX_L3_CSUM BIT(0)
68 #define NFDK_TX_MAX_DATA_PER_DESC 0x00004000
69 #define NFDK_TX_DESC_GATHER_MAX 17
70 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
71 #define NFDK_TX_DESC_BLOCK_SZ 256
72 #define NFDK_TX_DESC_BLOCK_CNT (NFDK_TX_DESC_BLOCK_SZ / \
73 sizeof(struct nfp_net_nfdk_tx_desc))
74 #define NFDK_TX_DESC_STOP_CNT (NFDK_TX_DESC_BLOCK_CNT * \
75 NFDK_TX_DESC_PER_SIMPLE_PKT)
76 #define NFDK_TX_MAX_DATA_PER_BLOCK 0x00010000
77 #define D_BLOCK_CPL(idx) (NFDK_TX_DESC_BLOCK_CNT - \
78 (idx) % NFDK_TX_DESC_BLOCK_CNT)
79 #define D_IDX(ring, idx) ((idx) & ((ring)->tx_count - 1))
81 struct nfp_net_nfd3_tx_desc {
84 uint8_t dma_addr_hi; /* High bits of host buf address */
85 __le16 dma_len; /* Length to DMA for this desc */
86 uint8_t offset_eop; /* Offset in buf where pkt starts +
87 * highest bit is eop flag.
89 __le32 dma_addr_lo; /* Low 32bit of host buf addr */
91 __le16 mss; /* MSS to be used for LSO */
92 uint8_t lso_hdrlen; /* LSO, where the data starts */
93 uint8_t flags; /* TX Flags, see @PCIE_DESC_TX_* */
98 * L3 and L4 header offsets required
104 __le16 vlan; /* VLAN tag to add if indicated */
106 __le16 data_len; /* Length of frame + meta data */
112 struct nfp_net_nfdk_tx_desc {
115 __le16 dma_addr_hi; /* High bits of host buf address */
116 __le16 dma_len_type; /* Length to DMA for this desc */
117 __le32 dma_addr_lo; /* Low 32bit of host buf addr */
121 __le16 mss; /* MSS to be used for LSO */
122 uint8_t lso_hdrlen; /* LSO, TCP payload offset */
123 uint8_t lso_totsegs; /* LSO, total segments */
124 uint8_t l3_offset; /* L3 header offset */
125 uint8_t l4_offset; /* L4 header offset */
126 __le16 lso_meta_res; /* Rsvd bits in TSO metadata */
130 uint8_t flags; /* TX Flags, see @NFDK_DESC_TX_* */
131 uint8_t reserved[7]; /* meta byte placeholder */
140 struct nfp_net_hw *hw; /* Backpointer to nfp_net structure */
143 * Queue information: @qidx is the queue index from Linux's
144 * perspective. @tx_qcidx is the index of the Queue
145 * Controller Peripheral queue relative to the TX queue BAR.
146 * @cnt is the size of the queue in number of
147 * descriptors. @qcp_q is a pointer to the base of the queue
148 * structure on the NFP
153 * Read and Write pointers. @wr_p and @rd_p are host side pointer,
154 * they are free running and have little relation to the QCP pointers *
155 * @qcp_rd_p is a local copy queue controller peripheral read pointer
163 uint32_t tx_free_thresh;
166 * For each descriptor keep a reference to the mbuf and
167 * DMA address used until completion is signalled.
170 struct rte_mbuf *mbuf;
174 * Information about the host side queue location. @txds is
175 * the virtual address for the queue, @dma is the DMA address
176 * of the queue and @size is the size in bytes for the queue
180 struct nfp_net_nfd3_tx_desc *txds;
181 struct nfp_net_nfdk_tx_desc *ktxds;
185 * At this point 48 bytes have been used for all the fields in the
186 * TX critical path. We have room for 8 bytes and still all placed
187 * in a cache line. We are not using the threshold values below but
188 * if we need to, we can add the most used in the remaining bytes.
190 uint32_t tx_rs_thresh; /* not used by now. Future? */
191 uint32_t tx_pthresh; /* not used by now. Future? */
192 uint32_t tx_hthresh; /* not used by now. Future? */
193 uint32_t tx_wthresh; /* not used by now. Future? */
195 uint16_t data_pending; /* used by nfdk only */
201 /* RX and freelist descriptor format */
202 #define PCIE_DESC_RX_DD (1 << 7)
203 #define PCIE_DESC_RX_META_LEN_MASK (0x7f)
205 /* Flags in the RX descriptor */
206 #define PCIE_DESC_RX_RSS (1 << 15)
207 #define PCIE_DESC_RX_I_IP4_CSUM (1 << 14)
208 #define PCIE_DESC_RX_I_IP4_CSUM_OK (1 << 13)
209 #define PCIE_DESC_RX_I_TCP_CSUM (1 << 12)
210 #define PCIE_DESC_RX_I_TCP_CSUM_OK (1 << 11)
211 #define PCIE_DESC_RX_I_UDP_CSUM (1 << 10)
212 #define PCIE_DESC_RX_I_UDP_CSUM_OK (1 << 9)
213 #define PCIE_DESC_RX_SPARE (1 << 8)
214 #define PCIE_DESC_RX_EOP (1 << 7)
215 #define PCIE_DESC_RX_IP4_CSUM (1 << 6)
216 #define PCIE_DESC_RX_IP4_CSUM_OK (1 << 5)
217 #define PCIE_DESC_RX_TCP_CSUM (1 << 4)
218 #define PCIE_DESC_RX_TCP_CSUM_OK (1 << 3)
219 #define PCIE_DESC_RX_UDP_CSUM (1 << 2)
220 #define PCIE_DESC_RX_UDP_CSUM_OK (1 << 1)
221 #define PCIE_DESC_RX_VLAN (1 << 0)
223 #define PCIE_DESC_RX_L4_CSUM_OK (PCIE_DESC_RX_TCP_CSUM_OK | \
224 PCIE_DESC_RX_UDP_CSUM_OK)
226 struct nfp_net_rx_desc {
228 /* Freelist descriptor */
251 struct nfp_net_rx_buff {
252 struct rte_mbuf *mbuf;
256 struct nfp_net_hw *hw; /* Backpointer to nfp_net structure */
259 * @qcp_fl and @qcp_rx are pointers to the base addresses of the
260 * freelist and RX queue controller peripheral queue structures on the
267 * Read and Write pointers. @wr_p and @rd_p are host side
268 * pointer, they are free running and have little relation to
269 * the QCP pointers. @wr_p is where the driver adds new
270 * freelist descriptors and @rd_p is where the driver start
271 * reading descriptors for newly arrive packets from.
276 * For each buffer placed on the freelist, record the
279 struct nfp_net_rx_buff *rxbufs;
282 * Information about the host side queue location. @rxds is
283 * the virtual address for the queue
285 struct nfp_net_rx_desc *rxds;
288 * The mempool is created by the user specifying a mbuf size.
289 * We save here the reference of the mempool needed in the RX
290 * path and the mbuf size for checking received packets can be
291 * safely copied to the mbuf using the NFP_NET_RX_OFFSET
293 struct rte_mempool *mem_pool;
297 * Next two fields are used for giving more free descriptors
300 uint16_t rx_free_thresh;
303 /* the size of the queue in number of descriptors */
307 * Fields above this point fit in a single cache line and are all used
308 * in the RX critical path. Fields below this point are just used
309 * during queue configuration or not used at all (yet)
312 /* referencing dev->data->port_id */
315 uint8_t crc_len; /* Not used by now */
316 uint8_t drop_en; /* Not used by now */
318 /* DMA address of the queue */
322 * Queue information: @qidx is the queue index from Linux's
323 * perspective. @fl_qcidx is the index of the Queue
324 * Controller peripheral queue relative to the RX queue BAR
325 * used for the freelist and @rx_qcidx is the Queue Controller
326 * Peripheral index for the RX queue.
333 int nfp_net_rx_freelist_setup(struct rte_eth_dev *dev);
334 uint32_t nfp_net_rx_queue_count(void *rx_queue);
335 uint16_t nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
337 void nfp_net_rx_queue_release(struct rte_eth_dev *dev, uint16_t queue_idx);
338 void nfp_net_reset_rx_queue(struct nfp_net_rxq *rxq);
339 int nfp_net_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
340 uint16_t nb_desc, unsigned int socket_id,
341 const struct rte_eth_rxconf *rx_conf,
342 struct rte_mempool *mp);
343 void nfp_net_tx_queue_release(struct rte_eth_dev *dev, uint16_t queue_idx);
344 void nfp_net_reset_tx_queue(struct nfp_net_txq *txq);
345 int nfp_net_nfd3_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
346 uint16_t nb_desc, unsigned int socket_id,
347 const struct rte_eth_txconf *tx_conf);
348 uint16_t nfp_net_nfd3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
350 int nfp_net_nfdk_tx_queue_setup(struct rte_eth_dev *dev,
353 unsigned int socket_id,
354 const struct rte_eth_txconf *tx_conf);
356 #endif /* _NFP_RXTX_H_ */
359 * c-file-style: "Linux"
360 * indent-tabs-mode: t