net/nfp: split datapath structs into separate file
[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 /*
21  * The maximum number of descriptors is limited by design as
22  * DPDK uses uint16_t variables for these values
23  */
24 #define NFP_NET_MAX_TX_DESC (32 * 1024)
25 #define NFP_NET_MIN_TX_DESC 64
26
27 #define NFP_NET_MAX_RX_DESC (32 * 1024)
28 #define NFP_NET_MIN_RX_DESC 64
29
30 /* Descriptor alignment */
31 #define NFP_ALIGN_RING_DESC 128
32
33 /* TX descriptor format */
34 #define PCIE_DESC_TX_EOP                (1 << 7)
35 #define PCIE_DESC_TX_OFFSET_MASK        (0x7f)
36
37 /* Flags in the host TX descriptor */
38 #define PCIE_DESC_TX_CSUM               (1 << 7)
39 #define PCIE_DESC_TX_IP4_CSUM           (1 << 6)
40 #define PCIE_DESC_TX_TCP_CSUM           (1 << 5)
41 #define PCIE_DESC_TX_UDP_CSUM           (1 << 4)
42 #define PCIE_DESC_TX_VLAN               (1 << 3)
43 #define PCIE_DESC_TX_LSO                (1 << 2)
44 #define PCIE_DESC_TX_ENCAP_NONE         (0)
45 #define PCIE_DESC_TX_ENCAP_VXLAN        (1 << 1)
46 #define PCIE_DESC_TX_ENCAP_GRE          (1 << 0)
47
48 struct nfp_net_tx_desc {
49         union {
50                 struct {
51                         uint8_t dma_addr_hi; /* High bits of host buf address */
52                         __le16 dma_len;     /* Length to DMA for this desc */
53                         uint8_t offset_eop; /* Offset in buf where pkt starts +
54                                              * highest bit is eop flag.
55                                              */
56                         __le32 dma_addr_lo; /* Low 32bit of host buf addr */
57
58                         __le16 mss;         /* MSS to be used for LSO */
59                         uint8_t lso_hdrlen; /* LSO, where the data starts */
60                         uint8_t flags;      /* TX Flags, see @PCIE_DESC_TX_* */
61
62                         union {
63                                 struct {
64                                         /*
65                                          * L3 and L4 header offsets required
66                                          * for TSOv2
67                                          */
68                                         uint8_t l3_offset;
69                                         uint8_t l4_offset;
70                                 };
71                                 __le16 vlan; /* VLAN tag to add if indicated */
72                         };
73                         __le16 data_len;    /* Length of frame + meta data */
74                 } __rte_packed;
75                 __le32 vals[4];
76         };
77 };
78
79 struct nfp_net_txq {
80         struct nfp_net_hw *hw; /* Backpointer to nfp_net structure */
81
82         /*
83          * Queue information: @qidx is the queue index from Linux's
84          * perspective.  @tx_qcidx is the index of the Queue
85          * Controller Peripheral queue relative to the TX queue BAR.
86          * @cnt is the size of the queue in number of
87          * descriptors. @qcp_q is a pointer to the base of the queue
88          * structure on the NFP
89          */
90         uint8_t *qcp_q;
91
92         /*
93          * Read and Write pointers.  @wr_p and @rd_p are host side pointer,
94          * they are free running and have little relation to the QCP pointers *
95          * @qcp_rd_p is a local copy queue controller peripheral read pointer
96          */
97
98         uint32_t wr_p;
99         uint32_t rd_p;
100
101         uint32_t tx_count;
102
103         uint32_t tx_free_thresh;
104
105         /*
106          * For each descriptor keep a reference to the mbuf and
107          * DMA address used until completion is signalled.
108          */
109         struct {
110                 struct rte_mbuf *mbuf;
111         } *txbufs;
112
113         /*
114          * Information about the host side queue location. @txds is
115          * the virtual address for the queue, @dma is the DMA address
116          * of the queue and @size is the size in bytes for the queue
117          * (needed for free)
118          */
119         struct nfp_net_tx_desc *txds;
120
121         /*
122          * At this point 48 bytes have been used for all the fields in the
123          * TX critical path. We have room for 8 bytes and still all placed
124          * in a cache line. We are not using the threshold values below but
125          * if we need to, we can add the most used in the remaining bytes.
126          */
127         uint32_t tx_rs_thresh; /* not used by now. Future? */
128         uint32_t tx_pthresh;   /* not used by now. Future? */
129         uint32_t tx_hthresh;   /* not used by now. Future? */
130         uint32_t tx_wthresh;   /* not used by now. Future? */
131         uint16_t port_id;
132         int qidx;
133         int tx_qcidx;
134         __le64 dma;
135 } __rte_aligned(64);
136
137 /* RX and freelist descriptor format */
138 #define PCIE_DESC_RX_DD                 (1 << 7)
139 #define PCIE_DESC_RX_META_LEN_MASK      (0x7f)
140
141 /* Flags in the RX descriptor */
142 #define PCIE_DESC_RX_RSS                (1 << 15)
143 #define PCIE_DESC_RX_I_IP4_CSUM         (1 << 14)
144 #define PCIE_DESC_RX_I_IP4_CSUM_OK      (1 << 13)
145 #define PCIE_DESC_RX_I_TCP_CSUM         (1 << 12)
146 #define PCIE_DESC_RX_I_TCP_CSUM_OK      (1 << 11)
147 #define PCIE_DESC_RX_I_UDP_CSUM         (1 << 10)
148 #define PCIE_DESC_RX_I_UDP_CSUM_OK      (1 <<  9)
149 #define PCIE_DESC_RX_SPARE              (1 <<  8)
150 #define PCIE_DESC_RX_EOP                (1 <<  7)
151 #define PCIE_DESC_RX_IP4_CSUM           (1 <<  6)
152 #define PCIE_DESC_RX_IP4_CSUM_OK        (1 <<  5)
153 #define PCIE_DESC_RX_TCP_CSUM           (1 <<  4)
154 #define PCIE_DESC_RX_TCP_CSUM_OK        (1 <<  3)
155 #define PCIE_DESC_RX_UDP_CSUM           (1 <<  2)
156 #define PCIE_DESC_RX_UDP_CSUM_OK        (1 <<  1)
157 #define PCIE_DESC_RX_VLAN               (1 <<  0)
158
159 #define PCIE_DESC_RX_L4_CSUM_OK         (PCIE_DESC_RX_TCP_CSUM_OK | \
160                                          PCIE_DESC_RX_UDP_CSUM_OK)
161
162 struct nfp_net_rx_desc {
163         union {
164                 /* Freelist descriptor */
165                 struct {
166                         uint8_t dma_addr_hi;
167                         __le16 spare;
168                         uint8_t dd;
169
170                         __le32 dma_addr_lo;
171                 } __rte_packed fld;
172
173                 /* RX descriptor */
174                 struct {
175                         __le16 data_len;
176                         uint8_t reserved;
177                         uint8_t meta_len_dd;
178
179                         __le16 flags;
180                         __le16 vlan;
181                 } __rte_packed rxd;
182
183                 __le32 vals[2];
184         };
185 };
186
187 struct nfp_net_rx_buff {
188         struct rte_mbuf *mbuf;
189 };
190
191 struct nfp_net_rxq {
192         struct nfp_net_hw *hw;  /* Backpointer to nfp_net structure */
193
194          /*
195           * @qcp_fl and @qcp_rx are pointers to the base addresses of the
196           * freelist and RX queue controller peripheral queue structures on the
197           * NFP
198           */
199         uint8_t *qcp_fl;
200         uint8_t *qcp_rx;
201
202         /*
203          * Read and Write pointers.  @wr_p and @rd_p are host side
204          * pointer, they are free running and have little relation to
205          * the QCP pointers. @wr_p is where the driver adds new
206          * freelist descriptors and @rd_p is where the driver start
207          * reading descriptors for newly arrive packets from.
208          */
209         uint32_t rd_p;
210
211         /*
212          * For each buffer placed on the freelist, record the
213          * associated SKB
214          */
215         struct nfp_net_rx_buff *rxbufs;
216
217         /*
218          * Information about the host side queue location.  @rxds is
219          * the virtual address for the queue
220          */
221         struct nfp_net_rx_desc *rxds;
222
223         /*
224          * The mempool is created by the user specifying a mbuf size.
225          * We save here the reference of the mempool needed in the RX
226          * path and the mbuf size for checking received packets can be
227          * safely copied to the mbuf using the NFP_NET_RX_OFFSET
228          */
229         struct rte_mempool *mem_pool;
230         uint16_t mbuf_size;
231
232         /*
233          * Next two fields are used for giving more free descriptors
234          * to the NFP
235          */
236         uint16_t rx_free_thresh;
237         uint16_t nb_rx_hold;
238
239          /* the size of the queue in number of descriptors */
240         uint16_t rx_count;
241
242         /*
243          * Fields above this point fit in a single cache line and are all used
244          * in the RX critical path. Fields below this point are just used
245          * during queue configuration or not used at all (yet)
246          */
247
248         /* referencing dev->data->port_id */
249         uint16_t port_id;
250
251         uint8_t  crc_len; /* Not used by now */
252         uint8_t  drop_en; /* Not used by now */
253
254         /* DMA address of the queue */
255         __le64 dma;
256
257         /*
258          * Queue information: @qidx is the queue index from Linux's
259          * perspective.  @fl_qcidx is the index of the Queue
260          * Controller peripheral queue relative to the RX queue BAR
261          * used for the freelist and @rx_qcidx is the Queue Controller
262          * Peripheral index for the RX queue.
263          */
264         int qidx;
265         int fl_qcidx;
266         int rx_qcidx;
267 } __rte_aligned(64);
268
269 #endif /* _NFP_RXTX_H_ */
270 /*
271  * Local variables:
272  * c-file-style: "Linux"
273  * indent-tabs-mode: t
274  * End:
275  */
276