4 * Copyright (c) 2016-2017 Solarflare Communications Inc.
7 * This software was jointly developed between OKTET Labs (under contract
8 * for Solarflare) and Solarflare Communications, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
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.
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.
37 #include <rte_ethdev.h>
38 #include <rte_kvargs.h>
39 #include <rte_spinlock.h>
43 #include "sfc_filter.h"
49 #define SFC_DEV_TO_PCI(eth_dev) \
50 RTE_DEV_TO_PCI((eth_dev)->device)
52 #if EFSYS_OPT_RX_SCALE
53 /** RSS key length (bytes) */
54 #define SFC_RSS_KEY_SIZE 40
55 /** RSS hash offloads mask */
56 #define SFC_RSS_OFFLOADS (ETH_RSS_IP | ETH_RSS_TCP)
61 * | UNINITIALIZED |<-----------+
63 * |.eth_dev_init |.eth_dev_uninit
65 * +---------------+------------+
67 * +---------------+<-----------+
71 * | CONFIGURING |------------^
72 * +---------------+ failed |
79 * +---------------+------------+
81 * +---------------+<-----------+
85 * | STARTING |------------^
86 * +---------------+ failed |
93 * +---------------+------------+
97 enum sfc_adapter_state {
98 SFC_ADAPTER_UNINITIALIZED = 0,
99 SFC_ADAPTER_INITIALIZED,
100 SFC_ADAPTER_CONFIGURING,
101 SFC_ADAPTER_CONFIGURED,
103 SFC_ADAPTER_STARTING,
105 SFC_ADAPTER_STOPPING,
110 enum sfc_dev_filter_mode {
111 SFC_DEV_FILTER_MODE_PROMISC = 0,
112 SFC_DEV_FILTER_MODE_ALLMULTI,
114 SFC_DEV_FILTER_NMODES
117 enum sfc_mcdi_state {
118 SFC_MCDI_UNINITIALIZED = 0,
119 SFC_MCDI_INITIALIZED,
129 enum sfc_mcdi_state state;
130 efx_mcdi_transport_t transport;
132 uint32_t proxy_handle;
133 efx_rc_t proxy_result;
137 efx_intr_type_t type;
138 rte_intr_callback_fn handler;
147 unsigned int lsc_seq;
149 uint32_t phy_adv_cap_mask;
150 uint32_t phy_adv_cap;
152 unsigned int flow_ctrl;
153 boolean_t flow_ctrl_autoneg;
159 unsigned int max_mcast_addrs;
160 unsigned int nb_mcast_addrs;
161 uint8_t *mcast_addrs;
163 rte_spinlock_t mac_stats_lock;
164 uint64_t *mac_stats_buf;
165 efsys_mem_t mac_stats_dma_mem;
166 boolean_t mac_stats_reset_pending;
167 uint16_t mac_stats_update_period_ms;
168 uint32_t mac_stats_update_generation;
169 boolean_t mac_stats_periodic_dma_supported;
170 uint64_t mac_stats_last_request_timestamp;
172 uint32_t mac_stats_mask[EFX_MAC_STATS_MASK_NPAGES];
175 /* Adapter private data */
178 * PMD setup and configuration is not thread safe. Since it is not
179 * performance sensitive, it is better to guarantee thread-safety
180 * and add device level lock. Adapter control operations which
181 * change its state should acquire the lock.
184 enum sfc_adapter_state state;
185 struct rte_eth_dev *eth_dev;
186 struct rte_kvargs *kvargs;
192 rte_spinlock_t nic_lock;
194 struct sfc_mcdi mcdi;
195 struct sfc_intr intr;
196 struct sfc_port port;
197 struct sfc_filter filter;
199 unsigned int rxq_max;
200 unsigned int txq_max;
202 unsigned int txq_max_entries;
205 unsigned int evq_count;
207 unsigned int mgmt_evq_index;
208 rte_spinlock_t mgmt_evq_lock;
209 struct sfc_evq *mgmt_evq;
211 unsigned int rxq_count;
212 struct sfc_rxq_info *rxq_info;
214 unsigned int txq_count;
215 struct sfc_txq_info *txq_info;
219 unsigned int rss_channels;
221 #if EFSYS_OPT_RX_SCALE
222 efx_rx_scale_support_t rss_support;
223 efx_rx_hash_support_t hash_support;
224 efx_rx_hash_type_t rss_hash_types;
225 unsigned int rss_tbl[EFX_RSS_TBL_SIZE];
226 uint8_t rss_key[SFC_RSS_KEY_SIZE];
229 const struct sfc_dp_rx *dp_rx;
230 const struct sfc_dp_tx *dp_tx;
234 * Add wrapper functions to acquire/release lock to be able to remove or
235 * change the lock in one place.
239 sfc_adapter_lock_init(struct sfc_adapter *sa)
241 rte_spinlock_init(&sa->lock);
245 sfc_adapter_is_locked(struct sfc_adapter *sa)
247 return rte_spinlock_is_locked(&sa->lock);
251 sfc_adapter_lock(struct sfc_adapter *sa)
253 rte_spinlock_lock(&sa->lock);
257 sfc_adapter_trylock(struct sfc_adapter *sa)
259 return rte_spinlock_trylock(&sa->lock);
263 sfc_adapter_unlock(struct sfc_adapter *sa)
265 rte_spinlock_unlock(&sa->lock);
269 sfc_adapter_lock_fini(__rte_unused struct sfc_adapter *sa)
271 /* Just for symmetry of the API */
274 /** Get the number of milliseconds since boot from the default timer */
275 static inline uint64_t
276 sfc_get_system_msecs(void)
278 return rte_get_timer_cycles() * MS_PER_S / rte_get_timer_hz();
281 int sfc_dma_alloc(const struct sfc_adapter *sa, const char *name, uint16_t id,
282 size_t len, int socket_id, efsys_mem_t *esmp);
283 void sfc_dma_free(const struct sfc_adapter *sa, efsys_mem_t *esmp);
285 int sfc_probe(struct sfc_adapter *sa);
286 void sfc_unprobe(struct sfc_adapter *sa);
287 int sfc_attach(struct sfc_adapter *sa);
288 void sfc_detach(struct sfc_adapter *sa);
289 int sfc_start(struct sfc_adapter *sa);
290 void sfc_stop(struct sfc_adapter *sa);
292 int sfc_mcdi_init(struct sfc_adapter *sa);
293 void sfc_mcdi_fini(struct sfc_adapter *sa);
295 int sfc_configure(struct sfc_adapter *sa);
296 void sfc_close(struct sfc_adapter *sa);
298 int sfc_intr_attach(struct sfc_adapter *sa);
299 void sfc_intr_detach(struct sfc_adapter *sa);
300 int sfc_intr_configure(struct sfc_adapter *sa);
301 void sfc_intr_close(struct sfc_adapter *sa);
302 int sfc_intr_start(struct sfc_adapter *sa);
303 void sfc_intr_stop(struct sfc_adapter *sa);
305 int sfc_port_attach(struct sfc_adapter *sa);
306 void sfc_port_detach(struct sfc_adapter *sa);
307 int sfc_port_configure(struct sfc_adapter *sa);
308 void sfc_port_close(struct sfc_adapter *sa);
309 int sfc_port_start(struct sfc_adapter *sa);
310 void sfc_port_stop(struct sfc_adapter *sa);
311 void sfc_port_link_mode_to_info(efx_link_mode_t link_mode,
312 struct rte_eth_link *link_info);
313 int sfc_port_update_mac_stats(struct sfc_adapter *sa);
314 int sfc_port_reset_mac_stats(struct sfc_adapter *sa);
315 int sfc_set_rx_mode(struct sfc_adapter *sa);