2 * Copyright (c) 2016 Solarflare Communications Inc.
5 * This software was jointly developed between OKTET Labs (under contract
6 * for Solarflare) and Solarflare Communications, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
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.
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.
35 #include <rte_ethdev.h>
36 #include <rte_kvargs.h>
37 #include <rte_spinlock.h>
41 #include "sfc_filter.h"
47 #define SFC_DEV_TO_PCI(eth_dev) \
48 RTE_DEV_TO_PCI((eth_dev)->device)
50 #if EFSYS_OPT_RX_SCALE
51 /** RSS key length (bytes) */
52 #define SFC_RSS_KEY_SIZE 40
53 /** RSS hash offloads mask */
54 #define SFC_RSS_OFFLOADS (ETH_RSS_IP | ETH_RSS_TCP)
59 * | UNINITIALIZED |<-----------+
61 * |.eth_dev_init |.eth_dev_uninit
63 * +---------------+------------+
65 * +---------------+<-----------+
69 * | CONFIGURING |------------^
70 * +---------------+ failed |
77 * +---------------+------------+
79 * +---------------+<-----------+
83 * | STARTING |------------^
84 * +---------------+ failed |
91 * +---------------+------------+
95 enum sfc_adapter_state {
96 SFC_ADAPTER_UNINITIALIZED = 0,
97 SFC_ADAPTER_INITIALIZED,
98 SFC_ADAPTER_CONFIGURING,
99 SFC_ADAPTER_CONFIGURED,
101 SFC_ADAPTER_STARTING,
103 SFC_ADAPTER_STOPPING,
108 enum sfc_dev_filter_mode {
109 SFC_DEV_FILTER_MODE_PROMISC = 0,
110 SFC_DEV_FILTER_MODE_ALLMULTI,
112 SFC_DEV_FILTER_NMODES
115 enum sfc_mcdi_state {
116 SFC_MCDI_UNINITIALIZED = 0,
117 SFC_MCDI_INITIALIZED,
127 enum sfc_mcdi_state state;
128 efx_mcdi_transport_t transport;
133 efx_intr_type_t type;
134 rte_intr_callback_fn handler;
143 unsigned int lsc_seq;
145 uint32_t phy_adv_cap_mask;
146 uint32_t phy_adv_cap;
148 unsigned int flow_ctrl;
149 boolean_t flow_ctrl_autoneg;
155 unsigned int max_mcast_addrs;
156 unsigned int nb_mcast_addrs;
157 uint8_t *mcast_addrs;
159 rte_spinlock_t mac_stats_lock;
160 uint64_t *mac_stats_buf;
161 efsys_mem_t mac_stats_dma_mem;
162 boolean_t mac_stats_reset_pending;
163 uint16_t mac_stats_update_period_ms;
164 uint32_t mac_stats_update_generation;
166 uint32_t mac_stats_mask[EFX_MAC_STATS_MASK_NPAGES];
169 /* Adapter private data */
172 * PMD setup and configuration is not thread safe. Since it is not
173 * performance sensitive, it is better to guarantee thread-safety
174 * and add device level lock. Adapter control operations which
175 * change its state should acquire the lock.
178 enum sfc_adapter_state state;
179 struct rte_eth_dev *eth_dev;
180 struct rte_kvargs *kvargs;
186 rte_spinlock_t nic_lock;
188 struct sfc_mcdi mcdi;
189 struct sfc_intr intr;
190 struct sfc_port port;
191 struct sfc_filter filter;
193 unsigned int rxq_max;
194 unsigned int txq_max;
196 unsigned int txq_max_entries;
199 unsigned int evq_count;
200 struct sfc_evq_info *evq_info;
202 unsigned int mgmt_evq_index;
203 rte_spinlock_t mgmt_evq_lock;
205 unsigned int rxq_count;
206 struct sfc_rxq_info *rxq_info;
208 unsigned int txq_count;
209 struct sfc_txq_info *txq_info;
213 unsigned int rss_channels;
215 #if EFSYS_OPT_RX_SCALE
216 efx_rx_scale_support_t rss_support;
217 efx_rx_hash_support_t hash_support;
218 efx_rx_hash_type_t rss_hash_types;
219 unsigned int rss_tbl[EFX_RSS_TBL_SIZE];
220 uint8_t rss_key[SFC_RSS_KEY_SIZE];
225 * Add wrapper functions to acquire/release lock to be able to remove or
226 * change the lock in one place.
230 sfc_adapter_lock_init(struct sfc_adapter *sa)
232 rte_spinlock_init(&sa->lock);
236 sfc_adapter_is_locked(struct sfc_adapter *sa)
238 return rte_spinlock_is_locked(&sa->lock);
242 sfc_adapter_lock(struct sfc_adapter *sa)
244 rte_spinlock_lock(&sa->lock);
248 sfc_adapter_trylock(struct sfc_adapter *sa)
250 return rte_spinlock_trylock(&sa->lock);
254 sfc_adapter_unlock(struct sfc_adapter *sa)
256 rte_spinlock_unlock(&sa->lock);
260 sfc_adapter_lock_fini(__rte_unused struct sfc_adapter *sa)
262 /* Just for symmetry of the API */
265 int sfc_dma_alloc(const struct sfc_adapter *sa, const char *name, uint16_t id,
266 size_t len, int socket_id, efsys_mem_t *esmp);
267 void sfc_dma_free(const struct sfc_adapter *sa, efsys_mem_t *esmp);
269 int sfc_attach(struct sfc_adapter *sa);
270 void sfc_detach(struct sfc_adapter *sa);
271 int sfc_start(struct sfc_adapter *sa);
272 void sfc_stop(struct sfc_adapter *sa);
274 int sfc_mcdi_init(struct sfc_adapter *sa);
275 void sfc_mcdi_fini(struct sfc_adapter *sa);
277 int sfc_configure(struct sfc_adapter *sa);
278 void sfc_close(struct sfc_adapter *sa);
280 int sfc_intr_attach(struct sfc_adapter *sa);
281 void sfc_intr_detach(struct sfc_adapter *sa);
282 int sfc_intr_init(struct sfc_adapter *sa);
283 void sfc_intr_fini(struct sfc_adapter *sa);
284 int sfc_intr_start(struct sfc_adapter *sa);
285 void sfc_intr_stop(struct sfc_adapter *sa);
287 int sfc_port_init(struct sfc_adapter *sa);
288 void sfc_port_fini(struct sfc_adapter *sa);
289 int sfc_port_start(struct sfc_adapter *sa);
290 void sfc_port_stop(struct sfc_adapter *sa);
291 void sfc_port_link_mode_to_info(efx_link_mode_t link_mode,
292 struct rte_eth_link *link_info);
293 int sfc_port_update_mac_stats(struct sfc_adapter *sa);
294 int sfc_port_reset_mac_stats(struct sfc_adapter *sa);
295 int sfc_set_rx_mode(struct sfc_adapter *sa);