net/sfc: advertise offload capabilities by Rx datapaths
[dpdk.git] / drivers / net / sfc / sfc_dp_rx.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2017-2018 Solarflare Communications Inc.
4  * All rights reserved.
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 <rte_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         /** Associated event queue size */
78         unsigned int            evq_entries;
79         /** Hardware event ring */
80         void                    *evq_hw_ring;
81
82         /** The queue index in hardware (required to push right doorbell) */
83         unsigned int            hw_index;
84         /**
85          * Virtual address of the memory-mapped BAR to push Rx refill
86          * doorbell
87          */
88         volatile void           *mem_bar;
89         /** VI window size shift */
90         unsigned int            vi_window_shift;
91 };
92
93 /**
94  * Get Rx datapath specific device info.
95  *
96  * @param dev_info              Device info to be adjusted
97  */
98 typedef void (sfc_dp_rx_get_dev_info_t)(struct rte_eth_dev_info *dev_info);
99
100 /**
101  * Test if an Rx datapath supports specific mempool ops.
102  *
103  * @param pool                  The name of the pool operations to test.
104  *
105  * @return Check status.
106  * @retval      0               Best mempool ops choice.
107  * @retval      1               Mempool ops are supported.
108  * @retval      -ENOTSUP        Mempool ops not supported.
109  */
110 typedef int (sfc_dp_rx_pool_ops_supported_t)(const char *pool);
111
112 /**
113  * Get size of receive and event queue rings by the number of Rx
114  * descriptors and mempool configuration.
115  *
116  * @param nb_rx_desc            Number of Rx descriptors
117  * @param mb_pool               mbuf pool with Rx buffers
118  * @param rxq_entries           Location for number of Rx ring entries
119  * @param evq_entries           Location for number of event ring entries
120  * @param rxq_max_fill_level    Location for maximum Rx ring fill level
121  *
122  * @return 0 or positive errno.
123  */
124 typedef int (sfc_dp_rx_qsize_up_rings_t)(uint16_t nb_rx_desc,
125                                          struct sfc_dp_rx_hw_limits *limits,
126                                          struct rte_mempool *mb_pool,
127                                          unsigned int *rxq_entries,
128                                          unsigned int *evq_entries,
129                                          unsigned int *rxq_max_fill_level);
130
131 /**
132  * Allocate and initialize datapath receive queue.
133  *
134  * @param port_id       The port identifier
135  * @param queue_id      The queue identifier
136  * @param pci_addr      PCI function address
137  * @param socket_id     Socket identifier to allocate memory
138  * @param info          Receive queue information
139  * @param dp_rxqp       Location for generic datapath receive queue pointer
140  *
141  * @return 0 or positive errno.
142  */
143 typedef int (sfc_dp_rx_qcreate_t)(uint16_t port_id, uint16_t queue_id,
144                                   const struct rte_pci_addr *pci_addr,
145                                   int socket_id,
146                                   const struct sfc_dp_rx_qcreate_info *info,
147                                   struct sfc_dp_rxq **dp_rxqp);
148
149 /**
150  * Free resources allocated for datapath recevie queue.
151  */
152 typedef void (sfc_dp_rx_qdestroy_t)(struct sfc_dp_rxq *dp_rxq);
153
154 /**
155  * Receive queue start callback.
156  *
157  * It handovers EvQ to the datapath.
158  */
159 typedef int (sfc_dp_rx_qstart_t)(struct sfc_dp_rxq *dp_rxq,
160                                  unsigned int evq_read_ptr);
161
162 /**
163  * Receive queue stop function called before flush.
164  */
165 typedef void (sfc_dp_rx_qstop_t)(struct sfc_dp_rxq *dp_rxq,
166                                  unsigned int *evq_read_ptr);
167
168 /**
169  * Receive event handler used during queue flush only.
170  */
171 typedef bool (sfc_dp_rx_qrx_ev_t)(struct sfc_dp_rxq *dp_rxq, unsigned int id);
172
173 /**
174  * Packed stream receive event handler used during queue flush only.
175  */
176 typedef bool (sfc_dp_rx_qrx_ps_ev_t)(struct sfc_dp_rxq *dp_rxq,
177                                      unsigned int id);
178
179 /**
180  * Receive queue purge function called after queue flush.
181  *
182  * Should be used to free unused recevie buffers.
183  */
184 typedef void (sfc_dp_rx_qpurge_t)(struct sfc_dp_rxq *dp_rxq);
185
186 /** Get packet types recognized/classified */
187 typedef const uint32_t * (sfc_dp_rx_supported_ptypes_get_t)(
188                                 uint32_t tunnel_encaps);
189
190 /** Get number of pending Rx descriptors */
191 typedef unsigned int (sfc_dp_rx_qdesc_npending_t)(struct sfc_dp_rxq *dp_rxq);
192
193 /** Check Rx descriptor status */
194 typedef int (sfc_dp_rx_qdesc_status_t)(struct sfc_dp_rxq *dp_rxq,
195                                        uint16_t offset);
196
197 /** Receive datapath definition */
198 struct sfc_dp_rx {
199         struct sfc_dp                           dp;
200
201         unsigned int                            features;
202 #define SFC_DP_RX_FEAT_MULTI_PROCESS            0x1
203 #define SFC_DP_RX_FEAT_FLOW_FLAG                0x2
204 #define SFC_DP_RX_FEAT_FLOW_MARK                0x4
205         /**
206          * Rx offload capabilities supported by the datapath on device
207          * level only if HW/FW supports it.
208          */
209         uint64_t                                dev_offload_capa;
210         /**
211          * Rx offload capabilities supported by the datapath per-queue
212          * if HW/FW supports it.
213          */
214         uint64_t                                queue_offload_capa;
215         sfc_dp_rx_get_dev_info_t                *get_dev_info;
216         sfc_dp_rx_pool_ops_supported_t          *pool_ops_supported;
217         sfc_dp_rx_qsize_up_rings_t              *qsize_up_rings;
218         sfc_dp_rx_qcreate_t                     *qcreate;
219         sfc_dp_rx_qdestroy_t                    *qdestroy;
220         sfc_dp_rx_qstart_t                      *qstart;
221         sfc_dp_rx_qstop_t                       *qstop;
222         sfc_dp_rx_qrx_ev_t                      *qrx_ev;
223         sfc_dp_rx_qrx_ps_ev_t                   *qrx_ps_ev;
224         sfc_dp_rx_qpurge_t                      *qpurge;
225         sfc_dp_rx_supported_ptypes_get_t        *supported_ptypes_get;
226         sfc_dp_rx_qdesc_npending_t              *qdesc_npending;
227         sfc_dp_rx_qdesc_status_t                *qdesc_status;
228         eth_rx_burst_t                          pkt_burst;
229 };
230
231 static inline struct sfc_dp_rx *
232 sfc_dp_find_rx_by_name(struct sfc_dp_list *head, const char *name)
233 {
234         struct sfc_dp *p = sfc_dp_find_by_name(head, SFC_DP_RX, name);
235
236         return (p == NULL) ? NULL : container_of(p, struct sfc_dp_rx, dp);
237 }
238
239 static inline struct sfc_dp_rx *
240 sfc_dp_find_rx_by_caps(struct sfc_dp_list *head, unsigned int avail_caps)
241 {
242         struct sfc_dp *p = sfc_dp_find_by_caps(head, SFC_DP_RX, avail_caps);
243
244         return (p == NULL) ? NULL : container_of(p, struct sfc_dp_rx, dp);
245 }
246
247 static inline uint64_t
248 sfc_dp_rx_offload_capa(const struct sfc_dp_rx *dp_rx)
249 {
250         return dp_rx->dev_offload_capa | dp_rx->queue_offload_capa;
251 }
252
253 /** Get Rx datapath ops by the datapath RxQ handle */
254 const struct sfc_dp_rx *sfc_dp_rx_by_dp_rxq(const struct sfc_dp_rxq *dp_rxq);
255
256 extern struct sfc_dp_rx sfc_efx_rx;
257 extern struct sfc_dp_rx sfc_ef10_rx;
258 extern struct sfc_dp_rx sfc_ef10_essb_rx;
259
260 #ifdef __cplusplus
261 }
262 #endif
263 #endif /* _SFC_DP_RX_H */