net/ixgbe/base: remove X550em SFP iXFI setup
[dpdk.git] / drivers / net / sfc / sfc.h
1 /*-
2  * Copyright (c) 2016 Solarflare Communications Inc.
3  * All rights reserved.
4  *
5  * This software was jointly developed between OKTET Labs (under contract
6  * for Solarflare) and Solarflare Communications, Inc.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  *    this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  *    this list of conditions and the following disclaimer in the documentation
15  *    and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #ifndef _SFC_H
31 #define _SFC_H
32
33 #include <stdbool.h>
34
35 #include <rte_ethdev.h>
36 #include <rte_kvargs.h>
37 #include <rte_spinlock.h>
38
39 #include "efx.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 #define SFC_DEV_TO_PCI(eth_dev) \
46         RTE_DEV_TO_PCI((eth_dev)->device)
47
48 #if EFSYS_OPT_RX_SCALE
49 /** RSS key length (bytes) */
50 #define SFC_RSS_KEY_SIZE        40
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                       |
66  * +---------------+            |
67  * |  CONFIGURING  |------------^
68  * +---------------+ failed     |
69  *      |success                |
70  *      |               +---------------+
71  *      |               |    CLOSING    |
72  *      |               +---------------+
73  *      |                       ^
74  *      V                       |.dev_close
75  * +---------------+------------+
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 };
129
130 struct sfc_intr {
131         efx_intr_type_t                 type;
132         rte_intr_callback_fn            handler;
133         boolean_t                       lsc_intr;
134 };
135
136 struct sfc_evq_info;
137 struct sfc_rxq_info;
138 struct sfc_txq_info;
139
140 struct sfc_port {
141         unsigned int                    lsc_seq;
142
143         uint32_t                        phy_adv_cap_mask;
144         uint32_t                        phy_adv_cap;
145
146         unsigned int                    flow_ctrl;
147         boolean_t                       flow_ctrl_autoneg;
148         size_t                          pdu;
149
150         boolean_t                       promisc;
151         boolean_t                       allmulti;
152
153         rte_spinlock_t                  mac_stats_lock;
154         uint64_t                        *mac_stats_buf;
155         efsys_mem_t                     mac_stats_dma_mem;
156
157         uint32_t                mac_stats_mask[EFX_MAC_STATS_MASK_NPAGES];
158 };
159
160 /* Adapter private data */
161 struct sfc_adapter {
162         /*
163          * PMD setup and configuration is not thread safe. Since it is not
164          * performance sensitive, it is better to guarantee thread-safety
165          * and add device level lock. Adapter control operations which
166          * change its state should acquire the lock.
167          */
168         rte_spinlock_t                  lock;
169         enum sfc_adapter_state          state;
170         struct rte_eth_dev              *eth_dev;
171         struct rte_kvargs               *kvargs;
172         bool                            debug_init;
173         int                             socket_id;
174         efsys_bar_t                     mem_bar;
175         efx_family_t                    family;
176         efx_nic_t                       *nic;
177         rte_spinlock_t                  nic_lock;
178
179         struct sfc_mcdi                 mcdi;
180         struct sfc_intr                 intr;
181         struct sfc_port                 port;
182
183         unsigned int                    rxq_max;
184         unsigned int                    txq_max;
185
186         unsigned int                    txq_max_entries;
187
188         uint32_t                        evq_flags;
189         unsigned int                    evq_count;
190         struct sfc_evq_info             *evq_info;
191
192         unsigned int                    mgmt_evq_index;
193         rte_spinlock_t                  mgmt_evq_lock;
194
195         unsigned int                    rxq_count;
196         struct sfc_rxq_info             *rxq_info;
197
198         unsigned int                    txq_count;
199         struct sfc_txq_info             *txq_info;
200
201         boolean_t                       tso;
202
203         unsigned int                    rss_channels;
204
205 #if EFSYS_OPT_RX_SCALE
206         efx_rx_scale_support_t          rss_support;
207         efx_rx_hash_support_t           hash_support;
208         efx_rx_hash_type_t              rss_hash_types;
209         unsigned int                    rss_tbl[EFX_RSS_TBL_SIZE];
210         uint8_t                         rss_key[SFC_RSS_KEY_SIZE];
211 #endif
212 };
213
214 /*
215  * Add wrapper functions to acquire/release lock to be able to remove or
216  * change the lock in one place.
217  */
218
219 static inline void
220 sfc_adapter_lock_init(struct sfc_adapter *sa)
221 {
222         rte_spinlock_init(&sa->lock);
223 }
224
225 static inline int
226 sfc_adapter_is_locked(struct sfc_adapter *sa)
227 {
228         return rte_spinlock_is_locked(&sa->lock);
229 }
230
231 static inline void
232 sfc_adapter_lock(struct sfc_adapter *sa)
233 {
234         rte_spinlock_lock(&sa->lock);
235 }
236
237 static inline int
238 sfc_adapter_trylock(struct sfc_adapter *sa)
239 {
240         return rte_spinlock_trylock(&sa->lock);
241 }
242
243 static inline void
244 sfc_adapter_unlock(struct sfc_adapter *sa)
245 {
246         rte_spinlock_unlock(&sa->lock);
247 }
248
249 static inline void
250 sfc_adapter_lock_fini(__rte_unused struct sfc_adapter *sa)
251 {
252         /* Just for symmetry of the API */
253 }
254
255 int sfc_dma_alloc(const struct sfc_adapter *sa, const char *name, uint16_t id,
256                   size_t len, int socket_id, efsys_mem_t *esmp);
257 void sfc_dma_free(const struct sfc_adapter *sa, efsys_mem_t *esmp);
258
259 int sfc_attach(struct sfc_adapter *sa);
260 void sfc_detach(struct sfc_adapter *sa);
261 int sfc_start(struct sfc_adapter *sa);
262 void sfc_stop(struct sfc_adapter *sa);
263
264 int sfc_mcdi_init(struct sfc_adapter *sa);
265 void sfc_mcdi_fini(struct sfc_adapter *sa);
266
267 int sfc_configure(struct sfc_adapter *sa);
268 void sfc_close(struct sfc_adapter *sa);
269
270 int sfc_intr_attach(struct sfc_adapter *sa);
271 void sfc_intr_detach(struct sfc_adapter *sa);
272 int sfc_intr_init(struct sfc_adapter *sa);
273 void sfc_intr_fini(struct sfc_adapter *sa);
274 int sfc_intr_start(struct sfc_adapter *sa);
275 void sfc_intr_stop(struct sfc_adapter *sa);
276
277 int sfc_port_init(struct sfc_adapter *sa);
278 void sfc_port_fini(struct sfc_adapter *sa);
279 int sfc_port_start(struct sfc_adapter *sa);
280 void sfc_port_stop(struct sfc_adapter *sa);
281 void sfc_port_link_mode_to_info(efx_link_mode_t link_mode,
282                                 struct rte_eth_link *link_info);
283 int sfc_port_update_mac_stats(struct sfc_adapter *sa);
284 int sfc_set_rx_mode(struct sfc_adapter *sa);
285
286
287 #ifdef __cplusplus
288 }
289 #endif
290
291 #endif  /* _SFC_H */