net/mlx5: fix build with clang 14
[dpdk.git] / drivers / net / nfp / nfp_rxtx.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2014-2021 Netronome Systems, Inc.
3  * All rights reserved.
4  */
5
6 /*
7  * vim:shiftwidth=8:noexpandtab
8  *
9  * @file dpdk/pmd/nfp_rxtx.h
10  *
11  * Netronome NFP Rx/Tx specific header file
12  */
13
14 #ifndef _NFP_RXTX_H_
15 #define _NFP_RXTX_H_
16
17 #include <linux/types.h>
18 #include <rte_io.h>
19
20 #define NFP_DESC_META_LEN(d) ((d)->rxd.meta_len_dd & PCIE_DESC_RX_META_LEN_MASK)
21
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)
24
25 #define RTE_MBUF_DMA_ADDR_DEFAULT(mb) \
26         ((uint64_t)((mb)->buf_iova + RTE_PKTMBUF_HEADROOM))
27
28 /*
29  * The maximum number of descriptors is limited by design as
30  * DPDK uses uint16_t variables for these values
31  */
32 #define NFP_NET_MAX_TX_DESC (32 * 1024)
33 #define NFP_NET_MIN_TX_DESC 256
34
35 #define NFP_NET_MAX_RX_DESC (32 * 1024)
36 #define NFP_NET_MIN_RX_DESC 256
37
38 /* Descriptor alignment */
39 #define NFP_ALIGN_RING_DESC 128
40
41 /* TX descriptor format */
42 #define PCIE_DESC_TX_EOP                (1 << 7)
43 #define PCIE_DESC_TX_OFFSET_MASK        (0x7f)
44
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)
55
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)
67
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))
80
81 struct nfp_net_nfd3_tx_desc {
82         union {
83                 struct {
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.
88                                              */
89                         __le32 dma_addr_lo; /* Low 32bit of host buf addr */
90
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_* */
94
95                         union {
96                                 struct {
97                                         /*
98                                          * L3 and L4 header offsets required
99                                          * for TSOv2
100                                          */
101                                         uint8_t l3_offset;
102                                         uint8_t l4_offset;
103                                 };
104                                 __le16 vlan; /* VLAN tag to add if indicated */
105                         };
106                         __le16 data_len;    /* Length of frame + meta data */
107                 } __rte_packed;
108                 __le32 vals[4];
109         };
110 };
111
112 struct nfp_net_nfdk_tx_desc {
113         union {
114                 struct {
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 */
118                 };
119
120                 struct {
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 */
127                 };
128
129                 struct {
130                         uint8_t flags;  /* TX Flags, see @NFDK_DESC_TX_* */
131                         uint8_t reserved[7];    /* meta byte placeholder */
132                 };
133
134                 __le32 vals[2];
135                 __le64 raw;
136         };
137 };
138
139 struct nfp_net_txq {
140         struct nfp_net_hw *hw; /* Backpointer to nfp_net structure */
141
142         /*
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
149          */
150         uint8_t *qcp_q;
151
152         /*
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
156          */
157
158         uint32_t wr_p;
159         uint32_t rd_p;
160
161         uint32_t tx_count;
162
163         uint32_t tx_free_thresh;
164
165         /*
166          * For each descriptor keep a reference to the mbuf and
167          * DMA address used until completion is signalled.
168          */
169         struct {
170                 struct rte_mbuf *mbuf;
171         } *txbufs;
172
173         /*
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
177          * (needed for free)
178          */
179         union {
180                 struct nfp_net_nfd3_tx_desc *txds;
181                 struct nfp_net_nfdk_tx_desc *ktxds;
182         };
183
184         /*
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.
189          */
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? */
194         uint16_t port_id;
195         uint16_t data_pending; /* used by nfdk only */
196         int qidx;
197         int tx_qcidx;
198         __le64 dma;
199 } __rte_aligned(64);
200
201 /* RX and freelist descriptor format */
202 #define PCIE_DESC_RX_DD                 (1 << 7)
203 #define PCIE_DESC_RX_META_LEN_MASK      (0x7f)
204
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)
222
223 #define PCIE_DESC_RX_L4_CSUM_OK         (PCIE_DESC_RX_TCP_CSUM_OK | \
224                                          PCIE_DESC_RX_UDP_CSUM_OK)
225
226 struct nfp_net_rx_desc {
227         union {
228                 /* Freelist descriptor */
229                 struct {
230                         uint8_t dma_addr_hi;
231                         __le16 spare;
232                         uint8_t dd;
233
234                         __le32 dma_addr_lo;
235                 } __rte_packed fld;
236
237                 /* RX descriptor */
238                 struct {
239                         __le16 data_len;
240                         uint8_t reserved;
241                         uint8_t meta_len_dd;
242
243                         __le16 flags;
244                         __le16 vlan;
245                 } __rte_packed rxd;
246
247                 __le32 vals[2];
248         };
249 };
250
251 struct nfp_net_rx_buff {
252         struct rte_mbuf *mbuf;
253 };
254
255 struct nfp_net_rxq {
256         struct nfp_net_hw *hw;  /* Backpointer to nfp_net structure */
257
258          /*
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
261           * NFP
262           */
263         uint8_t *qcp_fl;
264         uint8_t *qcp_rx;
265
266         /*
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.
272          */
273         uint32_t rd_p;
274
275         /*
276          * For each buffer placed on the freelist, record the
277          * associated SKB
278          */
279         struct nfp_net_rx_buff *rxbufs;
280
281         /*
282          * Information about the host side queue location.  @rxds is
283          * the virtual address for the queue
284          */
285         struct nfp_net_rx_desc *rxds;
286
287         /*
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
292          */
293         struct rte_mempool *mem_pool;
294         uint16_t mbuf_size;
295
296         /*
297          * Next two fields are used for giving more free descriptors
298          * to the NFP
299          */
300         uint16_t rx_free_thresh;
301         uint16_t nb_rx_hold;
302
303          /* the size of the queue in number of descriptors */
304         uint16_t rx_count;
305
306         /*
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)
310          */
311
312         /* referencing dev->data->port_id */
313         uint16_t port_id;
314
315         uint8_t  crc_len; /* Not used by now */
316         uint8_t  drop_en; /* Not used by now */
317
318         /* DMA address of the queue */
319         __le64 dma;
320
321         /*
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.
327          */
328         int qidx;
329         int fl_qcidx;
330         int rx_qcidx;
331 } __rte_aligned(64);
332
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,
336                                   uint16_t nb_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,
349                                   uint16_t nb_pkts);
350 int nfp_net_nfdk_tx_queue_setup(struct rte_eth_dev *dev,
351                 uint16_t queue_idx,
352                 uint16_t nb_desc,
353                 unsigned int socket_id,
354                 const struct rte_eth_txconf *tx_conf);
355
356 #endif /* _NFP_RXTX_H_ */
357 /*
358  * Local variables:
359  * c-file-style: "Linux"
360  * indent-tabs-mode: t
361  * End:
362  */