b817f3429ff946bb9ac3e1a741e1d2e3b57d9d68
[dpdk.git] / drivers / net / sfc / sfc_dp_rx.h
1 /*-
2  *   BSD LICENSE
3  *
4  * Copyright (c) 2017 Solarflare Communications Inc.
5  * All rights reserved.
6  *
7  * This software was jointly developed between OKTET Labs (under contract
8  * for Solarflare) and Solarflare Communications, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  *    this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  *    this list of conditions and the following disclaimer in the documentation
17  *    and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 #ifndef _SFC_DP_RX_H
33 #define _SFC_DP_RX_H
34
35 #include <rte_mempool.h>
36 #include <rte_ethdev.h>
37
38 #include "sfc_dp.h"
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 /**
45  * Generic receive queue information used on data path.
46  * It must be kept as small as it is possible since it is built into
47  * the structure used on datapath.
48  */
49 struct sfc_dp_rxq {
50         struct sfc_dp_queue     dpq;
51 };
52
53 /**
54  * Datapath receive queue creation information.
55  *
56  * The structure is used just to pass information from control path to
57  * datapath. It could be just function arguments, but it would be hardly
58  * readable.
59  */
60 struct sfc_dp_rx_qcreate_info {
61         /** Memory pool to allocate Rx buffer from */
62         struct rte_mempool      *refill_mb_pool;
63         /** Maximum number of pushed Rx descriptors in the queue */
64         unsigned int            max_fill_level;
65         /** Minimum number of unused Rx descriptors to do refill */
66         unsigned int            refill_threshold;
67         /**
68          * Usable mbuf data space in accordance with alignment and
69          * padding requirements imposed by HW.
70          */
71         unsigned int            buf_size;
72
73         /**
74          * Maximum number of Rx descriptors completed in one Rx event.
75          * Just for sanity checks if datapath would like to do.
76          */
77         unsigned int            batch_max;
78
79         /** Pseudo-header size */
80         unsigned int            prefix_size;
81
82         /** Receive queue flags initializer */
83         unsigned int            flags;
84 #define SFC_RXQ_FLAG_RSS_HASH   0x1
85
86         /** Rx queue size */
87         unsigned int            rxq_entries;
88         /** DMA-mapped Rx descriptors ring */
89         void                    *rxq_hw_ring;
90
91         /** Associated event queue size */
92         unsigned int            evq_entries;
93         /** Hardware event ring */
94         void                    *evq_hw_ring;
95
96         /** The queue index in hardware (required to push right doorbell) */
97         unsigned int            hw_index;
98         /**
99          * Virtual address of the memory-mapped BAR to push Rx refill
100          * doorbell
101          */
102         volatile void           *mem_bar;
103 };
104
105 /**
106  * Get Rx datapath specific device info.
107  *
108  * @param dev_info              Device info to be adjusted
109  */
110 typedef void (sfc_dp_rx_get_dev_info_t)(struct rte_eth_dev_info *dev_info);
111
112 /**
113  * Get size of receive and event queue rings by the number of Rx
114  * descriptors.
115  *
116  * @param nb_rx_desc            Number of Rx descriptors
117  * @param rxq_entries           Location for number of Rx ring entries
118  * @param evq_entries           Location for number of event ring entries
119  * @param rxq_max_fill_level    Location for maximum Rx ring fill level
120  *
121  * @return 0 or positive errno.
122  */
123 typedef int (sfc_dp_rx_qsize_up_rings_t)(uint16_t nb_rx_desc,
124                                          unsigned int *rxq_entries,
125                                          unsigned int *evq_entries,
126                                          unsigned int *rxq_max_fill_level);
127
128 /**
129  * Allocate and initialize datapath receive queue.
130  *
131  * @param port_id       The port identifier
132  * @param queue_id      The queue identifier
133  * @param pci_addr      PCI function address
134  * @param socket_id     Socket identifier to allocate memory
135  * @param info          Receive queue information
136  * @param dp_rxqp       Location for generic datapath receive queue pointer
137  *
138  * @return 0 or positive errno.
139  */
140 typedef int (sfc_dp_rx_qcreate_t)(uint16_t port_id, uint16_t queue_id,
141                                   const struct rte_pci_addr *pci_addr,
142                                   int socket_id,
143                                   const struct sfc_dp_rx_qcreate_info *info,
144                                   struct sfc_dp_rxq **dp_rxqp);
145
146 /**
147  * Free resources allocated for datapath recevie queue.
148  */
149 typedef void (sfc_dp_rx_qdestroy_t)(struct sfc_dp_rxq *dp_rxq);
150
151 /**
152  * Receive queue start callback.
153  *
154  * It handovers EvQ to the datapath.
155  */
156 typedef int (sfc_dp_rx_qstart_t)(struct sfc_dp_rxq *dp_rxq,
157                                  unsigned int evq_read_ptr);
158
159 /**
160  * Receive queue stop function called before flush.
161  */
162 typedef void (sfc_dp_rx_qstop_t)(struct sfc_dp_rxq *dp_rxq,
163                                  unsigned int *evq_read_ptr);
164
165 /**
166  * Receive event handler used during queue flush only.
167  */
168 typedef bool (sfc_dp_rx_qrx_ev_t)(struct sfc_dp_rxq *dp_rxq, 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         sfc_dp_rx_get_dev_info_t                *get_dev_info;
197         sfc_dp_rx_qsize_up_rings_t              *qsize_up_rings;
198         sfc_dp_rx_qcreate_t                     *qcreate;
199         sfc_dp_rx_qdestroy_t                    *qdestroy;
200         sfc_dp_rx_qstart_t                      *qstart;
201         sfc_dp_rx_qstop_t                       *qstop;
202         sfc_dp_rx_qrx_ev_t                      *qrx_ev;
203         sfc_dp_rx_qpurge_t                      *qpurge;
204         sfc_dp_rx_supported_ptypes_get_t        *supported_ptypes_get;
205         sfc_dp_rx_qdesc_npending_t              *qdesc_npending;
206         sfc_dp_rx_qdesc_status_t                *qdesc_status;
207         eth_rx_burst_t                          pkt_burst;
208 };
209
210 static inline struct sfc_dp_rx *
211 sfc_dp_find_rx_by_name(struct sfc_dp_list *head, const char *name)
212 {
213         struct sfc_dp *p = sfc_dp_find_by_name(head, SFC_DP_RX, name);
214
215         return (p == NULL) ? NULL : container_of(p, struct sfc_dp_rx, dp);
216 }
217
218 static inline struct sfc_dp_rx *
219 sfc_dp_find_rx_by_caps(struct sfc_dp_list *head, unsigned int avail_caps)
220 {
221         struct sfc_dp *p = sfc_dp_find_by_caps(head, SFC_DP_RX, avail_caps);
222
223         return (p == NULL) ? NULL : container_of(p, struct sfc_dp_rx, dp);
224 }
225
226 extern struct sfc_dp_rx sfc_efx_rx;
227 extern struct sfc_dp_rx sfc_ef10_rx;
228
229 #ifdef __cplusplus
230 }
231 #endif
232 #endif /* _SFC_DP_RX_H */