xref: /dpdk/drivers/net/nfp/nfp_rxtx.h (revision 4dcbf32ffefd84dbb5924de3b2c6dd517f7809c8)
174f99d45SHeinrich Kuhn /* SPDX-License-Identifier: BSD-3-Clause
274f99d45SHeinrich Kuhn  * Copyright (c) 2014-2021 Netronome Systems, Inc.
374f99d45SHeinrich Kuhn  * All rights reserved.
474f99d45SHeinrich Kuhn  */
574f99d45SHeinrich Kuhn 
672de00c6SChaoyong He #ifndef __NFP_RXTX_H__
772de00c6SChaoyong He #define __NFP_RXTX_H__
874f99d45SHeinrich Kuhn 
9027a02c6SChaoyong He #include <ethdev_driver.h>
1074f99d45SHeinrich Kuhn 
1174f99d45SHeinrich Kuhn /* Descriptor alignment */
1274f99d45SHeinrich Kuhn #define NFP_ALIGN_RING_DESC 128
1374f99d45SHeinrich Kuhn 
14f8a8c5fbSChaoyong He struct nfp_net_dp_buf {
15f8a8c5fbSChaoyong He 	struct rte_mbuf *mbuf;
16f8a8c5fbSChaoyong He };
17f8a8c5fbSChaoyong He 
1854713740SChang Miao struct nfp_tx_ipsec_desc_msg {
1954713740SChang Miao 	uint32_t sa_idx;        /**< SA index in driver table */
2054713740SChang Miao 	uint32_t enc;           /**< IPsec enable flag */
2154713740SChang Miao 	union {
2254713740SChang Miao 		uint64_t value;
2354713740SChang Miao 		struct {
2454713740SChang Miao 			uint32_t low;
2554713740SChang Miao 			uint32_t hi;
2654713740SChang Miao 		};
2754713740SChang Miao 	} esn;                  /**< Extended Sequence Number */
2854713740SChang Miao };
2954713740SChang Miao 
3027595cd8STyler Retzlaff struct __rte_aligned(64) nfp_net_txq {
31dd173601SChaoyong He 	/** Backpointer to nfp_net structure */
32dd173601SChaoyong He 	struct nfp_net_hw *hw;
33ff9f5a56SChaoyong He 	struct nfp_net_hw_priv *hw_priv;
3474f99d45SHeinrich Kuhn 
35dd173601SChaoyong He 	/**
3674f99d45SHeinrich Kuhn 	 * For each descriptor keep a reference to the mbuf and
3774f99d45SHeinrich Kuhn 	 * DMA address used until completion is signalled.
3874f99d45SHeinrich Kuhn 	 */
39f8a8c5fbSChaoyong He 	struct nfp_net_dp_buf *txbufs;
4074f99d45SHeinrich Kuhn 
41dd173601SChaoyong He 	/**
42dd173601SChaoyong He 	 * Information about the host side queue location.
43dd173601SChaoyong He 	 * It is the virtual address for the queue.
4474f99d45SHeinrich Kuhn 	 */
456c6976e5SJin Liu 	union {
463ddd127dSJin Liu 		struct nfp_net_nfd3_tx_desc *txds;
476c6976e5SJin Liu 		struct nfp_net_nfdk_tx_desc *ktxds;
486c6976e5SJin Liu 	};
4974f99d45SHeinrich Kuhn 
504c486f33SChaoyong He 	/**
514c486f33SChaoyong He 	 * Host side read and write pointer, they are free running and
524c486f33SChaoyong He 	 * have little relation to the QCP pointers.
534c486f33SChaoyong He 	 */
544c486f33SChaoyong He 	uint32_t wr_p;
554c486f33SChaoyong He 	uint32_t rd_p;
564c486f33SChaoyong He 
574c486f33SChaoyong He 	/** The size of the queue in number of descriptors. */
584c486f33SChaoyong He 	uint32_t tx_count;
594c486f33SChaoyong He 
604c486f33SChaoyong He 	uint32_t tx_free_thresh;
614c486f33SChaoyong He 
62dd173601SChaoyong He 	/** The index of the QCP queue relative to the TX queue BAR. */
63dd173601SChaoyong He 	uint32_t tx_qcidx;
64dd173601SChaoyong He 
65dd173601SChaoyong He 	/** The queue index from Linux's perspective. */
66dd173601SChaoyong He 	uint16_t qidx;
6774f99d45SHeinrich Kuhn 	uint16_t port_id;
68dd173601SChaoyong He 
69dd173601SChaoyong He 	/** Used by NFDk only */
70dd173601SChaoyong He 	uint16_t data_pending;
71dd173601SChaoyong He 
72fb6befdfSLong Wu 	/** Used by NFDk vector xmit only */
73fb6befdfSLong Wu 	bool simple_always;
74fb6befdfSLong Wu 
75dd173601SChaoyong He 	/**
76ff9f5a56SChaoyong He 	 * At this point 58 bytes have been used for all the fields in the
77fb6befdfSLong Wu 	 * TX critical path. We have room for 5 bytes and still all placed
78dd173601SChaoyong He 	 * in a cache line.
79dd173601SChaoyong He 	 */
80dd173601SChaoyong He 	uint64_t dma;
81ff9da649SLong Wu 
82ff9da649SLong Wu 	/** TX pointer ring write back area (indexed by queue id) */
83ff9da649SLong Wu 	uint64_t *txrwb;
84ff9da649SLong Wu 
85ff9da649SLong Wu 	/** TX pointer ring write back area DMA address */
86ff9da649SLong Wu 	uint64_t txrwb_dma;
874c486f33SChaoyong He 
884c486f33SChaoyong He 	/** Point to the base of the queue structure on the NFP. */
894c486f33SChaoyong He 	uint8_t *qcp_q;
9027595cd8STyler Retzlaff };
9174f99d45SHeinrich Kuhn 
9274f99d45SHeinrich Kuhn /* RX and freelist descriptor format */
9374f99d45SHeinrich Kuhn #define PCIE_DESC_RX_DD                 (1 << 7)
9474f99d45SHeinrich Kuhn #define PCIE_DESC_RX_META_LEN_MASK      (0x7f)
9574f99d45SHeinrich Kuhn 
9674f99d45SHeinrich Kuhn /* Flags in the RX descriptor */
9774f99d45SHeinrich Kuhn #define PCIE_DESC_RX_RSS                (1 << 15)
9874f99d45SHeinrich Kuhn #define PCIE_DESC_RX_I_IP4_CSUM         (1 << 14)
9974f99d45SHeinrich Kuhn #define PCIE_DESC_RX_I_IP4_CSUM_OK      (1 << 13)
10074f99d45SHeinrich Kuhn #define PCIE_DESC_RX_I_TCP_CSUM         (1 << 12)
10174f99d45SHeinrich Kuhn #define PCIE_DESC_RX_I_TCP_CSUM_OK      (1 << 11)
10274f99d45SHeinrich Kuhn #define PCIE_DESC_RX_I_UDP_CSUM         (1 << 10)
10374f99d45SHeinrich Kuhn #define PCIE_DESC_RX_I_UDP_CSUM_OK      (1 <<  9)
10474f99d45SHeinrich Kuhn #define PCIE_DESC_RX_SPARE              (1 <<  8)
10574f99d45SHeinrich Kuhn #define PCIE_DESC_RX_EOP                (1 <<  7)
10674f99d45SHeinrich Kuhn #define PCIE_DESC_RX_IP4_CSUM           (1 <<  6)
10774f99d45SHeinrich Kuhn #define PCIE_DESC_RX_IP4_CSUM_OK        (1 <<  5)
10874f99d45SHeinrich Kuhn #define PCIE_DESC_RX_TCP_CSUM           (1 <<  4)
10974f99d45SHeinrich Kuhn #define PCIE_DESC_RX_TCP_CSUM_OK        (1 <<  3)
11074f99d45SHeinrich Kuhn #define PCIE_DESC_RX_UDP_CSUM           (1 <<  2)
11174f99d45SHeinrich Kuhn #define PCIE_DESC_RX_UDP_CSUM_OK        (1 <<  1)
11274f99d45SHeinrich Kuhn #define PCIE_DESC_RX_VLAN               (1 <<  0)
11374f99d45SHeinrich Kuhn 
11474f99d45SHeinrich Kuhn #define PCIE_DESC_RX_L4_CSUM_OK         (PCIE_DESC_RX_TCP_CSUM_OK | \
11574f99d45SHeinrich Kuhn 					 PCIE_DESC_RX_UDP_CSUM_OK)
11674f99d45SHeinrich Kuhn 
11774f99d45SHeinrich Kuhn struct nfp_net_rx_desc {
11874f99d45SHeinrich Kuhn 	union {
119b2e42cafSQin Ke 		/** Freelist descriptor. */
120e7750639SAndre Muezerie 		struct __rte_packed_begin {
121b2e42cafSQin Ke 			uint16_t dma_addr_hi;  /**< High bits of buffer address. */
122b2e42cafSQin Ke 			uint8_t spare;         /**< Reserved, must be zero. */
123b2e42cafSQin Ke 			uint8_t dd;            /**< Whether descriptor available. */
124b2e42cafSQin Ke 			uint32_t dma_addr_lo;  /**< Low bits of buffer address. */
125e7750639SAndre Muezerie 		} __rte_packed_end fld;
12674f99d45SHeinrich Kuhn 
127b2e42cafSQin Ke 		/** RX descriptor. */
128e7750639SAndre Muezerie 		struct __rte_packed_begin {
129b2e42cafSQin Ke 			uint16_t data_len;     /**< Length of frame + metadata. */
130b2e42cafSQin Ke 			uint8_t reserved;      /**< Reserved, must be zero. */
131b2e42cafSQin Ke 			uint8_t meta_len_dd;   /**< Length of metadata + done flag. */
13274f99d45SHeinrich Kuhn 
133b2e42cafSQin Ke 			uint16_t flags;        /**< RX flags. */
134b2e42cafSQin Ke 			uint16_t offload_info; /**< Offloading info. */
135e7750639SAndre Muezerie 		} __rte_packed_end rxd;
13674f99d45SHeinrich Kuhn 
137b2e42cafSQin Ke 		/** Reserved. */
138e1fdb79bSChaoyong He 		uint32_t vals[2];
13974f99d45SHeinrich Kuhn 	};
14074f99d45SHeinrich Kuhn };
14174f99d45SHeinrich Kuhn 
14227595cd8STyler Retzlaff struct __rte_aligned(64) nfp_net_rxq {
143f061491dSChaoyong He 	/** Backpointer to nfp_net structure */
144f061491dSChaoyong He 	struct nfp_net_hw *hw;
145ff9f5a56SChaoyong He 	struct nfp_net_hw_priv *hw_priv;
14674f99d45SHeinrich Kuhn 
147f061491dSChaoyong He 	/**
148f061491dSChaoyong He 	 * Point to the base addresses of the freelist queue
149f061491dSChaoyong He 	 * controller peripheral queue structures on the NFP.
15074f99d45SHeinrich Kuhn 	 */
15174f99d45SHeinrich Kuhn 	uint8_t *qcp_fl;
15274f99d45SHeinrich Kuhn 
153f061491dSChaoyong He 	/**
15474f99d45SHeinrich Kuhn 	 * For each buffer placed on the freelist, record the
155f061491dSChaoyong He 	 * associated mbuf.
15674f99d45SHeinrich Kuhn 	 */
157f8a8c5fbSChaoyong He 	struct nfp_net_dp_buf *rxbufs;
15874f99d45SHeinrich Kuhn 
159f061491dSChaoyong He 	/**
160f061491dSChaoyong He 	 * Information about the host side queue location.
161f061491dSChaoyong He 	 * It is the virtual address for the queue.
16274f99d45SHeinrich Kuhn 	 */
16374f99d45SHeinrich Kuhn 	struct nfp_net_rx_desc *rxds;
16474f99d45SHeinrich Kuhn 
165f061491dSChaoyong He 	/**
16674f99d45SHeinrich Kuhn 	 * The mempool is created by the user specifying a mbuf size.
16774f99d45SHeinrich Kuhn 	 * We save here the reference of the mempool needed in the RX
16874f99d45SHeinrich Kuhn 	 * path and the mbuf size for checking received packets can be
169f061491dSChaoyong He 	 * safely copied to the mbuf using the NFP_NET_RX_OFFSET.
17074f99d45SHeinrich Kuhn 	 */
17174f99d45SHeinrich Kuhn 	struct rte_mempool *mem_pool;
1724c486f33SChaoyong He 
1734c486f33SChaoyong He 	/**
1744c486f33SChaoyong He 	 * Host side read pointer, free running and have little relation
1754c486f33SChaoyong He 	 * to the QCP pointers. It is where the driver start reading
1764c486f33SChaoyong He 	 * descriptors for newly arrive packets from.
1774c486f33SChaoyong He 	 */
1784c486f33SChaoyong He 	uint32_t rd_p;
1794c486f33SChaoyong He 
18074f99d45SHeinrich Kuhn 	uint16_t mbuf_size;
18174f99d45SHeinrich Kuhn 
182f061491dSChaoyong He 	/**
18374f99d45SHeinrich Kuhn 	 * Next two fields are used for giving more free descriptors
184f061491dSChaoyong He 	 * to the NFP.
18574f99d45SHeinrich Kuhn 	 */
18674f99d45SHeinrich Kuhn 	uint16_t rx_free_thresh;
18774f99d45SHeinrich Kuhn 	uint16_t nb_rx_hold;
18874f99d45SHeinrich Kuhn 
189f061491dSChaoyong He 	/** Referencing dev->data->port_id */
19074f99d45SHeinrich Kuhn 	uint16_t port_id;
19174f99d45SHeinrich Kuhn 
192f061491dSChaoyong He 	/** The queue index from Linux's perspective */
193f061491dSChaoyong He 	uint16_t qidx;
19474f99d45SHeinrich Kuhn 
195f061491dSChaoyong He 	/**
196ff9f5a56SChaoyong He 	 * At this point 62 bytes have been used for all the fields in the
197ff9f5a56SChaoyong He 	 * RX critical path. We have room for 2 bytes and still all placed
198f061491dSChaoyong He 	 * in a cache line.
19974f99d45SHeinrich Kuhn 	 */
200f061491dSChaoyong He 
2014c486f33SChaoyong He 	/** The size of the queue in number of descriptors */
2024c486f33SChaoyong He 	uint16_t rx_count;
2034c486f33SChaoyong He 
2044c486f33SChaoyong He 	/**
2054c486f33SChaoyong He 	 * The index of the QCP queue relative to the RX queue BAR
2064c486f33SChaoyong He 	 * used for the freelist.
2074c486f33SChaoyong He 	 */
2084c486f33SChaoyong He 	uint32_t fl_qcidx;
2094c486f33SChaoyong He 
210f061491dSChaoyong He 	/** DMA address of the queue */
211f061491dSChaoyong He 	uint64_t dma;
21227595cd8STyler Retzlaff };
21374f99d45SHeinrich Kuhn 
214d981d315SChaoyong He static inline void
215d981d315SChaoyong He nfp_net_mbuf_alloc_failed(struct nfp_net_rxq *rxq)
216d981d315SChaoyong He {
217d981d315SChaoyong He 	rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
218d981d315SChaoyong He }
219d981d315SChaoyong He 
220027a02c6SChaoyong He void nfp_net_rx_cksum(struct nfp_net_rxq *rxq, struct nfp_net_rx_desc *rxd,
221027a02c6SChaoyong He 		struct rte_mbuf *mb);
22279c7601aSHeinrich Kuhn int nfp_net_rx_freelist_setup(struct rte_eth_dev *dev);
2238d7d4fcdSKonstantin Ananyev uint32_t nfp_net_rx_queue_count(void *rx_queue);
22479c7601aSHeinrich Kuhn uint16_t nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
22579c7601aSHeinrich Kuhn 		uint16_t nb_pkts);
2267483341aSXueming Li void nfp_net_rx_queue_release(struct rte_eth_dev *dev, uint16_t queue_idx);
22779c7601aSHeinrich Kuhn void nfp_net_reset_rx_queue(struct nfp_net_rxq *rxq);
22879c7601aSHeinrich Kuhn int nfp_net_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
22979c7601aSHeinrich Kuhn 		uint16_t nb_desc, unsigned int socket_id,
23079c7601aSHeinrich Kuhn 		const struct rte_eth_rxconf *rx_conf,
23179c7601aSHeinrich Kuhn 		struct rte_mempool *mp);
2327483341aSXueming Li void nfp_net_tx_queue_release(struct rte_eth_dev *dev, uint16_t queue_idx);
23379c7601aSHeinrich Kuhn void nfp_net_reset_tx_queue(struct nfp_net_txq *txq);
234ffe84fcbSChaoyong He 
2358d961320SJin Liu int nfp_net_tx_queue_setup(struct rte_eth_dev *dev,
23652ddc4c2SJin Liu 		uint16_t queue_idx,
23752ddc4c2SJin Liu 		uint16_t nb_desc,
23852ddc4c2SJin Liu 		unsigned int socket_id,
23952ddc4c2SJin Liu 		const struct rte_eth_txconf *tx_conf);
2408ceb85c3SChaoyong He uint32_t nfp_net_tx_free_bufs(struct nfp_net_txq *txq);
24130198b3fSLong Wu void nfp_net_rx_queue_info_get(struct rte_eth_dev *dev,
24230198b3fSLong Wu 		uint16_t queue_id,
24330198b3fSLong Wu 		struct rte_eth_rxq_info *qinfo);
244fbe2e2ecSLong Wu void nfp_net_tx_queue_info_get(struct rte_eth_dev *dev,
245fbe2e2ecSLong Wu 		uint16_t queue_id,
246fbe2e2ecSLong Wu 		struct rte_eth_txq_info *qinfo);
247b6755530SLong Wu void nfp_net_recv_pkts_set(struct rte_eth_dev *eth_dev);
248*4dcbf32fSChaoyong He int nfp_net_rx_burst_mode_get(struct rte_eth_dev *eth_dev, uint16_t queue_id,
249*4dcbf32fSChaoyong He 		struct rte_eth_burst_mode *mode);
250*4dcbf32fSChaoyong He int nfp_net_tx_burst_mode_get(struct rte_eth_dev *eth_dev, uint16_t queue_id,
251*4dcbf32fSChaoyong He 		struct rte_eth_burst_mode *mode);
25262edcfd6SLong Wu void nfp_net_parse_ptype(struct nfp_net_rxq *rxq,
25362edcfd6SLong Wu 		struct nfp_net_rx_desc *rxds,
25462edcfd6SLong Wu 		struct rte_mbuf *mb);
25579c7601aSHeinrich Kuhn 
25672de00c6SChaoyong He #endif /* __NFP_RXTX_H__ */
257