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>
45 #define SFC_DEV_TO_PCI(eth_dev) \
46 RTE_DEV_TO_PCI((eth_dev)->device)
50 * | UNINITIALIZED |<-----------+
52 * |.eth_dev_init |.eth_dev_uninit
54 * +---------------+------------+
56 * +---------------+<-----------+
60 * | CONFIGURING |------------^
61 * +---------------+ failed |
68 * +---------------+------------+
70 * +---------------+<-----------+
74 * | STARTING |------------^
75 * +---------------+ failed |
82 * +---------------+------------+
86 enum sfc_adapter_state {
87 SFC_ADAPTER_UNINITIALIZED = 0,
88 SFC_ADAPTER_INITIALIZED,
89 SFC_ADAPTER_CONFIGURING,
90 SFC_ADAPTER_CONFIGURED,
100 SFC_MCDI_UNINITIALIZED = 0,
101 SFC_MCDI_INITIALIZED,
111 enum sfc_mcdi_state state;
112 efx_mcdi_transport_t transport;
117 efx_intr_type_t type;
125 unsigned int flow_ctrl;
126 boolean_t flow_ctrl_autoneg;
130 /* Adapter private data */
133 * PMD setup and configuration is not thread safe. Since it is not
134 * performance sensitive, it is better to guarantee thread-safety
135 * and add device level lock. Adapter control operations which
136 * change its state should acquire the lock.
139 enum sfc_adapter_state state;
140 struct rte_eth_dev *eth_dev;
141 struct rte_kvargs *kvargs;
147 rte_spinlock_t nic_lock;
149 struct sfc_mcdi mcdi;
150 struct sfc_intr intr;
151 struct sfc_port port;
153 unsigned int rxq_max;
154 unsigned int txq_max;
156 unsigned int txq_max_entries;
158 unsigned int evq_count;
159 struct sfc_evq_info *evq_info;
161 unsigned int mgmt_evq_index;
162 rte_spinlock_t mgmt_evq_lock;
164 unsigned int rxq_count;
165 struct sfc_rxq_info *rxq_info;
167 unsigned int txq_count;
168 struct sfc_txq_info *txq_info;
172 * Add wrapper functions to acquire/release lock to be able to remove or
173 * change the lock in one place.
177 sfc_adapter_lock_init(struct sfc_adapter *sa)
179 rte_spinlock_init(&sa->lock);
183 sfc_adapter_is_locked(struct sfc_adapter *sa)
185 return rte_spinlock_is_locked(&sa->lock);
189 sfc_adapter_lock(struct sfc_adapter *sa)
191 rte_spinlock_lock(&sa->lock);
195 sfc_adapter_trylock(struct sfc_adapter *sa)
197 return rte_spinlock_trylock(&sa->lock);
201 sfc_adapter_unlock(struct sfc_adapter *sa)
203 rte_spinlock_unlock(&sa->lock);
207 sfc_adapter_lock_fini(__rte_unused struct sfc_adapter *sa)
209 /* Just for symmetry of the API */
212 int sfc_dma_alloc(const struct sfc_adapter *sa, const char *name, uint16_t id,
213 size_t len, int socket_id, efsys_mem_t *esmp);
214 void sfc_dma_free(const struct sfc_adapter *sa, efsys_mem_t *esmp);
216 int sfc_attach(struct sfc_adapter *sa);
217 void sfc_detach(struct sfc_adapter *sa);
218 int sfc_start(struct sfc_adapter *sa);
219 void sfc_stop(struct sfc_adapter *sa);
221 int sfc_mcdi_init(struct sfc_adapter *sa);
222 void sfc_mcdi_fini(struct sfc_adapter *sa);
224 int sfc_configure(struct sfc_adapter *sa);
225 void sfc_close(struct sfc_adapter *sa);
227 int sfc_intr_attach(struct sfc_adapter *sa);
228 void sfc_intr_detach(struct sfc_adapter *sa);
229 int sfc_intr_init(struct sfc_adapter *sa);
230 void sfc_intr_fini(struct sfc_adapter *sa);
231 int sfc_intr_start(struct sfc_adapter *sa);
232 void sfc_intr_stop(struct sfc_adapter *sa);
234 int sfc_port_init(struct sfc_adapter *sa);
235 void sfc_port_fini(struct sfc_adapter *sa);
236 int sfc_port_start(struct sfc_adapter *sa);
237 void sfc_port_stop(struct sfc_adapter *sa);
238 void sfc_port_link_mode_to_info(efx_link_mode_t link_mode,
239 struct rte_eth_link *link_info);