c3cc4ff5b311e17f21cd3185d013f5a7a3e9869a
[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 };
36
37 /**
38  * Datapath receive queue creation information.
39  *
40  * The structure is used just to pass information from control path to
41  * datapath. It could be just function arguments, but it would be hardly
42  * readable.
43  */
44 struct sfc_dp_rx_qcreate_info {
45         /** Memory pool to allocate Rx buffer from */
46         struct rte_mempool      *refill_mb_pool;
47         /** Maximum number of pushed Rx descriptors in the queue */
48         unsigned int            max_fill_level;
49         /** Minimum number of unused Rx descriptors to do refill */
50         unsigned int            refill_threshold;
51         /**
52          * Usable mbuf data space in accordance with alignment and
53          * padding requirements imposed by HW.
54          */
55         unsigned int            buf_size;
56
57         /**
58          * Maximum number of Rx descriptors completed in one Rx event.
59          * Just for sanity checks if datapath would like to do.
60          */
61         unsigned int            batch_max;
62
63         /** Pseudo-header size */
64         unsigned int            prefix_size;
65
66         /** Receive queue flags initializer */
67         unsigned int            flags;
68 #define SFC_RXQ_FLAG_RSS_HASH   0x1
69
70         /** Rx queue size */
71         unsigned int            rxq_entries;
72         /** DMA-mapped Rx descriptors ring */
73         void                    *rxq_hw_ring;
74
75         /** Associated event queue size */
76         unsigned int            evq_entries;
77         /** Hardware event ring */
78         void                    *evq_hw_ring;
79
80         /** The queue index in hardware (required to push right doorbell) */
81         unsigned int            hw_index;
82         /**
83          * Virtual address of the memory-mapped BAR to push Rx refill
84          * doorbell
85          */
86         volatile void           *mem_bar;
87         /** VI window size shift */
88         unsigned int            vi_window_shift;
89 };
90
91 /**
92  * Get Rx datapath specific device info.
93  *
94  * @param dev_info              Device info to be adjusted
95  */
96 typedef void (sfc_dp_rx_get_dev_info_t)(struct rte_eth_dev_info *dev_info);
97
98 /**
99  * Test if an Rx datapath supports specific mempool ops.
100  *
101  * @param pool                  The name of the pool operations to test.
102  *
103  * @return Check status.
104  * @retval      0               Best mempool ops choice.
105  * @retval      1               Mempool ops are supported.
106  * @retval      -ENOTSUP        Mempool ops not supported.
107  */
108 typedef int (sfc_dp_rx_pool_ops_supported_t)(const char *pool);
109
110 /**
111  * Get size of receive and event queue rings by the number of Rx
112  * descriptors and mempool configuration.
113  *
114  * @param nb_rx_desc            Number of Rx descriptors
115  * @param mb_pool               mbuf pool with Rx buffers
116  * @param rxq_entries           Location for number of Rx ring entries
117  * @param evq_entries           Location for number of event ring entries
118  * @param rxq_max_fill_level    Location for maximum Rx ring fill level
119  *
120  * @return 0 or positive errno.
121  */
122 typedef int (sfc_dp_rx_qsize_up_rings_t)(uint16_t nb_rx_desc,
123                                          struct sfc_dp_rx_hw_limits *limits,
124                                          struct rte_mempool *mb_pool,
125                                          unsigned int *rxq_entries,
126                                          unsigned int *evq_entries,
127                                          unsigned int *rxq_max_fill_level);
128
129 /**
130  * Allocate and initialize datapath receive queue.
131  *
132  * @param port_id       The port identifier
133  * @param queue_id      The queue identifier
134  * @param pci_addr      PCI function address
135  * @param socket_id     Socket identifier to allocate memory
136  * @param info          Receive queue information
137  * @param dp_rxqp       Location for generic datapath receive queue pointer
138  *
139  * @return 0 or positive errno.
140  */
141 typedef int (sfc_dp_rx_qcreate_t)(uint16_t port_id, uint16_t queue_id,
142                                   const struct rte_pci_addr *pci_addr,
143                                   int socket_id,
144                                   const struct sfc_dp_rx_qcreate_info *info,
145                                   struct sfc_dp_rxq **dp_rxqp);
146
147 /**
148  * Free resources allocated for datapath recevie queue.
149  */
150 typedef void (sfc_dp_rx_qdestroy_t)(struct sfc_dp_rxq *dp_rxq);
151
152 /**
153  * Receive queue start callback.
154  *
155  * It handovers EvQ to the datapath.
156  */
157 typedef int (sfc_dp_rx_qstart_t)(struct sfc_dp_rxq *dp_rxq,
158                                  unsigned int evq_read_ptr);
159
160 /**
161  * Receive queue stop function called before flush.
162  */
163 typedef void (sfc_dp_rx_qstop_t)(struct sfc_dp_rxq *dp_rxq,
164                                  unsigned int *evq_read_ptr);
165
166 /**
167  * Receive event handler used during queue flush only.
168  */
169 typedef bool (sfc_dp_rx_qrx_ev_t)(struct sfc_dp_rxq *dp_rxq, unsigned int id);
170
171 /**
172  * Packed stream receive event handler used during queue flush only.
173  */
174 typedef bool (sfc_dp_rx_qrx_ps_ev_t)(struct sfc_dp_rxq *dp_rxq,
175                                      unsigned int id);
176
177 /**
178  * Receive queue purge function called after queue flush.
179  *
180  * Should be used to free unused recevie buffers.
181  */
182 typedef void (sfc_dp_rx_qpurge_t)(struct sfc_dp_rxq *dp_rxq);
183
184 /** Get packet types recognized/classified */
185 typedef const uint32_t * (sfc_dp_rx_supported_ptypes_get_t)(
186                                 uint32_t tunnel_encaps);
187
188 /** Get number of pending Rx descriptors */
189 typedef unsigned int (sfc_dp_rx_qdesc_npending_t)(struct sfc_dp_rxq *dp_rxq);
190
191 /** Check Rx descriptor status */
192 typedef int (sfc_dp_rx_qdesc_status_t)(struct sfc_dp_rxq *dp_rxq,
193                                        uint16_t offset);
194
195 /** Receive datapath definition */
196 struct sfc_dp_rx {
197         struct sfc_dp                           dp;
198
199         unsigned int                            features;
200 #define SFC_DP_RX_FEAT_SCATTER                  0x1
201 #define SFC_DP_RX_FEAT_MULTI_PROCESS            0x2
202 #define SFC_DP_RX_FEAT_TUNNELS                  0x4
203 #define SFC_DP_RX_FEAT_FLOW_FLAG                0x8
204 #define SFC_DP_RX_FEAT_FLOW_MARK                0x10
205 #define SFC_DP_RX_FEAT_CHECKSUM                 0x20
206         sfc_dp_rx_get_dev_info_t                *get_dev_info;
207         sfc_dp_rx_pool_ops_supported_t          *pool_ops_supported;
208         sfc_dp_rx_qsize_up_rings_t              *qsize_up_rings;
209         sfc_dp_rx_qcreate_t                     *qcreate;
210         sfc_dp_rx_qdestroy_t                    *qdestroy;
211         sfc_dp_rx_qstart_t                      *qstart;
212         sfc_dp_rx_qstop_t                       *qstop;
213         sfc_dp_rx_qrx_ev_t                      *qrx_ev;
214         sfc_dp_rx_qrx_ps_ev_t                   *qrx_ps_ev;
215         sfc_dp_rx_qpurge_t                      *qpurge;
216         sfc_dp_rx_supported_ptypes_get_t        *supported_ptypes_get;
217         sfc_dp_rx_qdesc_npending_t              *qdesc_npending;
218         sfc_dp_rx_qdesc_status_t                *qdesc_status;
219         eth_rx_burst_t                          pkt_burst;
220 };
221
222 static inline struct sfc_dp_rx *
223 sfc_dp_find_rx_by_name(struct sfc_dp_list *head, const char *name)
224 {
225         struct sfc_dp *p = sfc_dp_find_by_name(head, SFC_DP_RX, name);
226
227         return (p == NULL) ? NULL : container_of(p, struct sfc_dp_rx, dp);
228 }
229
230 static inline struct sfc_dp_rx *
231 sfc_dp_find_rx_by_caps(struct sfc_dp_list *head, unsigned int avail_caps)
232 {
233         struct sfc_dp *p = sfc_dp_find_by_caps(head, SFC_DP_RX, avail_caps);
234
235         return (p == NULL) ? NULL : container_of(p, struct sfc_dp_rx, dp);
236 }
237
238 /** Get Rx datapath ops by the datapath RxQ handle */
239 const struct sfc_dp_rx *sfc_dp_rx_by_dp_rxq(const struct sfc_dp_rxq *dp_rxq);
240
241 extern struct sfc_dp_rx sfc_efx_rx;
242 extern struct sfc_dp_rx sfc_ef10_rx;
243 extern struct sfc_dp_rx sfc_ef10_essb_rx;
244
245 #ifdef __cplusplus
246 }
247 #endif
248 #endif /* _SFC_DP_RX_H */