net/af_packet: make qdisc bypass configurable
[dpdk.git] / drivers / net / sfc / sfc.h
1 /*-
2  *   BSD LICENSE
3  *
4  * Copyright (c) 2016-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_H
33 #define _SFC_H
34
35 #include <stdbool.h>
36
37 #include <rte_pci.h>
38 #include <rte_ethdev.h>
39 #include <rte_kvargs.h>
40 #include <rte_spinlock.h>
41
42 #include "efx.h"
43
44 #include "sfc_filter.h"
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 #if EFSYS_OPT_RX_SCALE
51 /** RSS hash offloads mask */
52 #define SFC_RSS_OFFLOADS        (ETH_RSS_IP | ETH_RSS_TCP)
53 #endif
54
55 /*
56  * +---------------+
57  * | UNINITIALIZED |<-----------+
58  * +---------------+            |
59  *      |.eth_dev_init          |.eth_dev_uninit
60  *      V                       |
61  * +---------------+------------+
62  * |  INITIALIZED  |
63  * +---------------+<-----------<---------------+
64  *      |.dev_configure         |               |
65  *      V                       |failed         |
66  * +---------------+------------+               |
67  * |  CONFIGURING  |                            |
68  * +---------------+----+                       |
69  *      |success        |                       |
70  *      |               |               +---------------+
71  *      |               |               |    CLOSING    |
72  *      |               |               +---------------+
73  *      |               |                       ^
74  *      V               |.dev_configure         |
75  * +---------------+----+                       |.dev_close
76  * |  CONFIGURED   |----------------------------+
77  * +---------------+<-----------+
78  *      |.dev_start             |
79  *      V                       |
80  * +---------------+            |
81  * |   STARTING    |------------^
82  * +---------------+ failed     |
83  *      |success                |
84  *      |               +---------------+
85  *      |               |   STOPPING    |
86  *      |               +---------------+
87  *      |                       ^
88  *      V                       |.dev_stop
89  * +---------------+------------+
90  * |    STARTED    |
91  * +---------------+
92  */
93 enum sfc_adapter_state {
94         SFC_ADAPTER_UNINITIALIZED = 0,
95         SFC_ADAPTER_INITIALIZED,
96         SFC_ADAPTER_CONFIGURING,
97         SFC_ADAPTER_CONFIGURED,
98         SFC_ADAPTER_CLOSING,
99         SFC_ADAPTER_STARTING,
100         SFC_ADAPTER_STARTED,
101         SFC_ADAPTER_STOPPING,
102
103         SFC_ADAPTER_NSTATES
104 };
105
106 enum sfc_dev_filter_mode {
107         SFC_DEV_FILTER_MODE_PROMISC = 0,
108         SFC_DEV_FILTER_MODE_ALLMULTI,
109
110         SFC_DEV_FILTER_NMODES
111 };
112
113 enum sfc_mcdi_state {
114         SFC_MCDI_UNINITIALIZED = 0,
115         SFC_MCDI_INITIALIZED,
116         SFC_MCDI_BUSY,
117         SFC_MCDI_COMPLETED,
118
119         SFC_MCDI_NSTATES
120 };
121
122 struct sfc_mcdi {
123         rte_spinlock_t                  lock;
124         efsys_mem_t                     mem;
125         enum sfc_mcdi_state             state;
126         efx_mcdi_transport_t            transport;
127         bool                            logging;
128         uint32_t                        proxy_handle;
129         efx_rc_t                        proxy_result;
130 };
131
132 struct sfc_intr {
133         efx_intr_type_t                 type;
134         rte_intr_callback_fn            handler;
135         boolean_t                       lsc_intr;
136 };
137
138 struct sfc_rxq_info;
139 struct sfc_txq_info;
140 struct sfc_dp_rx;
141
142 struct sfc_port {
143         unsigned int                    lsc_seq;
144
145         uint32_t                        phy_adv_cap_mask;
146         uint32_t                        phy_adv_cap;
147
148         unsigned int                    flow_ctrl;
149         boolean_t                       flow_ctrl_autoneg;
150         size_t                          pdu;
151
152         /*
153          * Flow API isolated mode overrides promisc and allmulti settings;
154          * they won't be applied if isolated mode is active
155          */
156         boolean_t                       isolated;
157         boolean_t                       promisc;
158         boolean_t                       allmulti;
159
160         unsigned int                    max_mcast_addrs;
161         unsigned int                    nb_mcast_addrs;
162         uint8_t                         *mcast_addrs;
163
164         rte_spinlock_t                  mac_stats_lock;
165         uint64_t                        *mac_stats_buf;
166         unsigned int                    mac_stats_nb_supported;
167         efsys_mem_t                     mac_stats_dma_mem;
168         boolean_t                       mac_stats_reset_pending;
169         uint16_t                        mac_stats_update_period_ms;
170         uint32_t                        mac_stats_update_generation;
171         boolean_t                       mac_stats_periodic_dma_supported;
172         uint64_t                        mac_stats_last_request_timestamp;
173
174         uint32_t                mac_stats_mask[EFX_MAC_STATS_MASK_NPAGES];
175 };
176
177 /* Adapter private data */
178 struct sfc_adapter {
179         /*
180          * PMD setup and configuration is not thread safe. Since it is not
181          * performance sensitive, it is better to guarantee thread-safety
182          * and add device level lock. Adapter control operations which
183          * change its state should acquire the lock.
184          */
185         rte_spinlock_t                  lock;
186         enum sfc_adapter_state          state;
187         struct rte_pci_addr             pci_addr;
188         uint16_t                        port_id;
189         struct rte_eth_dev              *eth_dev;
190         struct rte_kvargs               *kvargs;
191         bool                            debug_init;
192         int                             socket_id;
193         efsys_bar_t                     mem_bar;
194         efx_family_t                    family;
195         efx_nic_t                       *nic;
196         rte_spinlock_t                  nic_lock;
197
198         struct sfc_mcdi                 mcdi;
199         struct sfc_intr                 intr;
200         struct sfc_port                 port;
201         struct sfc_filter               filter;
202
203         unsigned int                    rxq_max;
204         unsigned int                    txq_max;
205
206         unsigned int                    txq_max_entries;
207
208         uint32_t                        evq_flags;
209         unsigned int                    evq_count;
210
211         unsigned int                    mgmt_evq_index;
212         rte_spinlock_t                  mgmt_evq_lock;
213         struct sfc_evq                  *mgmt_evq;
214
215         unsigned int                    rxq_count;
216         struct sfc_rxq_info             *rxq_info;
217
218         unsigned int                    txq_count;
219         struct sfc_txq_info             *txq_info;
220
221         boolean_t                       tso;
222
223         unsigned int                    rss_channels;
224
225 #if EFSYS_OPT_RX_SCALE
226         efx_rx_scale_context_type_t     rss_support;
227         efx_rx_hash_support_t           hash_support;
228         efx_rx_hash_type_t              rss_hash_types;
229         unsigned int                    rss_tbl[EFX_RSS_TBL_SIZE];
230         uint8_t                         rss_key[EFX_RSS_KEY_SIZE];
231 #endif
232
233         /*
234          * Shared memory copy of the Rx datapath name to be used by
235          * the secondary process to find Rx datapath to be used.
236          */
237         char                            *dp_rx_name;
238         const struct sfc_dp_rx          *dp_rx;
239
240         /*
241          * Shared memory copy of the Tx datapath name to be used by
242          * the secondary process to find Rx datapath to be used.
243          */
244         char                            *dp_tx_name;
245         const struct sfc_dp_tx          *dp_tx;
246 };
247
248 /*
249  * Add wrapper functions to acquire/release lock to be able to remove or
250  * change the lock in one place.
251  */
252
253 static inline void
254 sfc_adapter_lock_init(struct sfc_adapter *sa)
255 {
256         rte_spinlock_init(&sa->lock);
257 }
258
259 static inline int
260 sfc_adapter_is_locked(struct sfc_adapter *sa)
261 {
262         return rte_spinlock_is_locked(&sa->lock);
263 }
264
265 static inline void
266 sfc_adapter_lock(struct sfc_adapter *sa)
267 {
268         rte_spinlock_lock(&sa->lock);
269 }
270
271 static inline int
272 sfc_adapter_trylock(struct sfc_adapter *sa)
273 {
274         return rte_spinlock_trylock(&sa->lock);
275 }
276
277 static inline void
278 sfc_adapter_unlock(struct sfc_adapter *sa)
279 {
280         rte_spinlock_unlock(&sa->lock);
281 }
282
283 static inline void
284 sfc_adapter_lock_fini(__rte_unused struct sfc_adapter *sa)
285 {
286         /* Just for symmetry of the API */
287 }
288
289 /** Get the number of milliseconds since boot from the default timer */
290 static inline uint64_t
291 sfc_get_system_msecs(void)
292 {
293         return rte_get_timer_cycles() * MS_PER_S / rte_get_timer_hz();
294 }
295
296 int sfc_dma_alloc(const struct sfc_adapter *sa, const char *name, uint16_t id,
297                   size_t len, int socket_id, efsys_mem_t *esmp);
298 void sfc_dma_free(const struct sfc_adapter *sa, efsys_mem_t *esmp);
299
300 int sfc_probe(struct sfc_adapter *sa);
301 void sfc_unprobe(struct sfc_adapter *sa);
302 int sfc_attach(struct sfc_adapter *sa);
303 void sfc_detach(struct sfc_adapter *sa);
304 int sfc_start(struct sfc_adapter *sa);
305 void sfc_stop(struct sfc_adapter *sa);
306
307 int sfc_mcdi_init(struct sfc_adapter *sa);
308 void sfc_mcdi_fini(struct sfc_adapter *sa);
309
310 int sfc_configure(struct sfc_adapter *sa);
311 void sfc_close(struct sfc_adapter *sa);
312
313 int sfc_intr_attach(struct sfc_adapter *sa);
314 void sfc_intr_detach(struct sfc_adapter *sa);
315 int sfc_intr_configure(struct sfc_adapter *sa);
316 void sfc_intr_close(struct sfc_adapter *sa);
317 int sfc_intr_start(struct sfc_adapter *sa);
318 void sfc_intr_stop(struct sfc_adapter *sa);
319
320 int sfc_port_attach(struct sfc_adapter *sa);
321 void sfc_port_detach(struct sfc_adapter *sa);
322 int sfc_port_configure(struct sfc_adapter *sa);
323 void sfc_port_close(struct sfc_adapter *sa);
324 int sfc_port_start(struct sfc_adapter *sa);
325 void sfc_port_stop(struct sfc_adapter *sa);
326 void sfc_port_link_mode_to_info(efx_link_mode_t link_mode,
327                                 struct rte_eth_link *link_info);
328 int sfc_port_update_mac_stats(struct sfc_adapter *sa);
329 int sfc_port_reset_mac_stats(struct sfc_adapter *sa);
330 int sfc_set_rx_mode(struct sfc_adapter *sa);
331
332
333 #ifdef __cplusplus
334 }
335 #endif
336
337 #endif  /* _SFC_H */