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