099f026a15349d7e7117b4eaf9dc2e7ca397d0d1
[dpdk.git] / drivers / net / sfc / sfc_dp_rx.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019-2021 Xilinx, Inc.
4  * Copyright(c) 2017-2019 Solarflare Communications Inc.
5  *
6  * This software was jointly developed between OKTET Labs (under contract
7  * for Solarflare) and Solarflare Communications, Inc.
8  */
9
10 #ifndef _SFC_DP_RX_H
11 #define _SFC_DP_RX_H
12
13 #include <rte_mempool.h>
14 #include <ethdev_driver.h>
15
16 #include "sfc_dp.h"
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 /**
23  * Generic receive queue information used on data path.
24  * It must be kept as small as it is possible since it is built into
25  * the structure used on datapath.
26  */
27 struct sfc_dp_rxq {
28         struct sfc_dp_queue     dpq;
29 };
30
31 /** Datapath receive queue descriptor number limitations */
32 struct sfc_dp_rx_hw_limits {
33         unsigned int rxq_max_entries;
34         unsigned int rxq_min_entries;
35         unsigned int evq_max_entries;
36         unsigned int evq_min_entries;
37 };
38
39 /**
40  * Datapath receive queue creation information.
41  *
42  * The structure is used just to pass information from control path to
43  * datapath. It could be just function arguments, but it would be hardly
44  * readable.
45  */
46 struct sfc_dp_rx_qcreate_info {
47         /** Memory pool to allocate Rx buffer from */
48         struct rte_mempool      *refill_mb_pool;
49         /** Maximum number of pushed Rx descriptors in the queue */
50         unsigned int            max_fill_level;
51         /** Minimum number of unused Rx descriptors to do refill */
52         unsigned int            refill_threshold;
53         /**
54          * Usable mbuf data space in accordance with alignment and
55          * padding requirements imposed by HW.
56          */
57         unsigned int            buf_size;
58
59         /**
60          * Maximum number of Rx descriptors completed in one Rx event.
61          * Just for sanity checks if datapath would like to do.
62          */
63         unsigned int            batch_max;
64
65         /** Pseudo-header size */
66         unsigned int            prefix_size;
67
68         /** Receive queue flags initializer */
69         unsigned int            flags;
70 #define SFC_RXQ_FLAG_RSS_HASH   0x1
71
72         /** Rx queue size */
73         unsigned int            rxq_entries;
74         /** DMA-mapped Rx descriptors ring */
75         void                    *rxq_hw_ring;
76
77         /** Event queue index in hardware */
78         unsigned int            evq_hw_index;
79         /** Associated event queue size */
80         unsigned int            evq_entries;
81         /** Hardware event ring */
82         void                    *evq_hw_ring;
83
84         /** The queue index in hardware (required to push right doorbell) */
85         unsigned int            hw_index;
86         /**
87          * Virtual address of the memory-mapped BAR to push Rx refill
88          * doorbell
89          */
90         volatile void           *mem_bar;
91         /** Function control window offset */
92         efsys_dma_addr_t        fcw_offset;
93         /** VI window size shift */
94         unsigned int            vi_window_shift;
95
96         /** Mask to extract user bits from Rx prefix mark field */
97         uint32_t                user_mark_mask;
98 };
99
100 /**
101  * Get Rx datapath specific device info.
102  *
103  * @param dev_info              Device info to be adjusted
104  */
105 typedef void (sfc_dp_rx_get_dev_info_t)(struct rte_eth_dev_info *dev_info);
106
107 /**
108  * Test if an Rx datapath supports specific mempool ops.
109  *
110  * @param pool                  The name of the pool operations to test.
111  *
112  * @return Check status.
113  * @retval      0               Best mempool ops choice.
114  * @retval      1               Mempool ops are supported.
115  * @retval      -ENOTSUP        Mempool ops not supported.
116  */
117 typedef int (sfc_dp_rx_pool_ops_supported_t)(const char *pool);
118
119 /**
120  * Get size of receive and event queue rings by the number of Rx
121  * descriptors and mempool configuration.
122  *
123  * @param nb_rx_desc            Number of Rx descriptors
124  * @param mb_pool               mbuf pool with Rx buffers
125  * @param rxq_entries           Location for number of Rx ring entries
126  * @param evq_entries           Location for number of event ring entries
127  * @param rxq_max_fill_level    Location for maximum Rx ring fill level
128  *
129  * @return 0 or positive errno.
130  */
131 typedef int (sfc_dp_rx_qsize_up_rings_t)(uint16_t nb_rx_desc,
132                                          struct sfc_dp_rx_hw_limits *limits,
133                                          struct rte_mempool *mb_pool,
134                                          unsigned int *rxq_entries,
135                                          unsigned int *evq_entries,
136                                          unsigned int *rxq_max_fill_level);
137
138 /**
139  * Allocate and initialize datapath receive queue.
140  *
141  * @param port_id       The port identifier
142  * @param queue_id      The queue identifier
143  * @param pci_addr      PCI function address
144  * @param socket_id     Socket identifier to allocate memory
145  * @param info          Receive queue information
146  * @param dp_rxqp       Location for generic datapath receive queue pointer
147  *
148  * @return 0 or positive errno.
149  */
150 typedef int (sfc_dp_rx_qcreate_t)(uint16_t port_id, uint16_t queue_id,
151                                   const struct rte_pci_addr *pci_addr,
152                                   int socket_id,
153                                   const struct sfc_dp_rx_qcreate_info *info,
154                                   struct sfc_dp_rxq **dp_rxqp);
155
156 /**
157  * Free resources allocated for datapath recevie queue.
158  */
159 typedef void (sfc_dp_rx_qdestroy_t)(struct sfc_dp_rxq *dp_rxq);
160
161 /**
162  * Receive queue start callback.
163  *
164  * It handovers EvQ to the datapath.
165  */
166 typedef int (sfc_dp_rx_qstart_t)(struct sfc_dp_rxq *dp_rxq,
167                                  unsigned int evq_read_ptr,
168                                  const efx_rx_prefix_layout_t *pinfo);
169
170 /**
171  * Receive queue stop function called before flush.
172  */
173 typedef void (sfc_dp_rx_qstop_t)(struct sfc_dp_rxq *dp_rxq,
174                                  unsigned int *evq_read_ptr);
175
176 /**
177  * Receive event handler used during queue flush only.
178  */
179 typedef bool (sfc_dp_rx_qrx_ev_t)(struct sfc_dp_rxq *dp_rxq, unsigned int id);
180
181 /**
182  * Packed stream receive event handler used during queue flush only.
183  */
184 typedef bool (sfc_dp_rx_qrx_ps_ev_t)(struct sfc_dp_rxq *dp_rxq,
185                                      unsigned int id);
186
187 /**
188  * Receive queue purge function called after queue flush.
189  *
190  * Should be used to free unused recevie buffers.
191  */
192 typedef void (sfc_dp_rx_qpurge_t)(struct sfc_dp_rxq *dp_rxq);
193
194 /** Get packet types recognized/classified */
195 typedef const uint32_t * (sfc_dp_rx_supported_ptypes_get_t)(
196                                 uint32_t tunnel_encaps);
197
198 /** Get number of pending Rx descriptors */
199 typedef unsigned int (sfc_dp_rx_qdesc_npending_t)(struct sfc_dp_rxq *dp_rxq);
200
201 /** Check Rx descriptor status */
202 typedef int (sfc_dp_rx_qdesc_status_t)(struct sfc_dp_rxq *dp_rxq,
203                                        uint16_t offset);
204 /** Enable Rx interrupts */
205 typedef int (sfc_dp_rx_intr_enable_t)(struct sfc_dp_rxq *dp_rxq);
206
207 /** Disable Rx interrupts */
208 typedef int (sfc_dp_rx_intr_disable_t)(struct sfc_dp_rxq *dp_rxq);
209
210 /** Get number of pushed Rx buffers */
211 typedef unsigned int (sfc_dp_rx_get_pushed_t)(struct sfc_dp_rxq *dp_rxq);
212
213 /** Receive datapath definition */
214 struct sfc_dp_rx {
215         struct sfc_dp                           dp;
216
217         unsigned int                            features;
218 #define SFC_DP_RX_FEAT_MULTI_PROCESS            0x1
219 #define SFC_DP_RX_FEAT_FLOW_FLAG                0x2
220 #define SFC_DP_RX_FEAT_FLOW_MARK                0x4
221 #define SFC_DP_RX_FEAT_INTR                     0x8
222 #define SFC_DP_RX_FEAT_STATS                    0x10
223         /**
224          * Rx offload capabilities supported by the datapath on device
225          * level only if HW/FW supports it.
226          */
227         uint64_t                                dev_offload_capa;
228         /**
229          * Rx offload capabilities supported by the datapath per-queue
230          * if HW/FW supports it.
231          */
232         uint64_t                                queue_offload_capa;
233         sfc_dp_rx_get_dev_info_t                *get_dev_info;
234         sfc_dp_rx_pool_ops_supported_t          *pool_ops_supported;
235         sfc_dp_rx_qsize_up_rings_t              *qsize_up_rings;
236         sfc_dp_rx_qcreate_t                     *qcreate;
237         sfc_dp_rx_qdestroy_t                    *qdestroy;
238         sfc_dp_rx_qstart_t                      *qstart;
239         sfc_dp_rx_qstop_t                       *qstop;
240         sfc_dp_rx_qrx_ev_t                      *qrx_ev;
241         sfc_dp_rx_qrx_ps_ev_t                   *qrx_ps_ev;
242         sfc_dp_rx_qpurge_t                      *qpurge;
243         sfc_dp_rx_supported_ptypes_get_t        *supported_ptypes_get;
244         sfc_dp_rx_qdesc_npending_t              *qdesc_npending;
245         sfc_dp_rx_qdesc_status_t                *qdesc_status;
246         sfc_dp_rx_intr_enable_t                 *intr_enable;
247         sfc_dp_rx_intr_disable_t                *intr_disable;
248         sfc_dp_rx_get_pushed_t                  *get_pushed;
249         eth_rx_burst_t                          pkt_burst;
250 };
251
252 static inline struct sfc_dp_rx *
253 sfc_dp_find_rx_by_name(struct sfc_dp_list *head, const char *name)
254 {
255         struct sfc_dp *p = sfc_dp_find_by_name(head, SFC_DP_RX, name);
256
257         return (p == NULL) ? NULL : container_of(p, struct sfc_dp_rx, dp);
258 }
259
260 static inline struct sfc_dp_rx *
261 sfc_dp_find_rx_by_caps(struct sfc_dp_list *head, unsigned int avail_caps)
262 {
263         struct sfc_dp *p = sfc_dp_find_by_caps(head, SFC_DP_RX, avail_caps);
264
265         return (p == NULL) ? NULL : container_of(p, struct sfc_dp_rx, dp);
266 }
267
268 static inline uint64_t
269 sfc_dp_rx_offload_capa(const struct sfc_dp_rx *dp_rx)
270 {
271         return dp_rx->dev_offload_capa | dp_rx->queue_offload_capa;
272 }
273
274 /** Get Rx datapath ops by the datapath RxQ handle */
275 const struct sfc_dp_rx *sfc_dp_rx_by_dp_rxq(const struct sfc_dp_rxq *dp_rxq);
276
277 extern struct sfc_dp_rx sfc_efx_rx;
278 extern struct sfc_dp_rx sfc_ef10_rx;
279 extern struct sfc_dp_rx sfc_ef10_essb_rx;
280 extern struct sfc_dp_rx sfc_ef100_rx;
281
282 #ifdef __cplusplus
283 }
284 #endif
285 #endif /* _SFC_DP_RX_H */