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