1 /******************************************************************************
3 Copyright (c) 2013-2015, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ******************************************************************************/
40 #include "ixl_pf_qmgr.h"
42 #define VF_FLAG_ENABLED 0x01
43 #define VF_FLAG_SET_MAC_CAP 0x02
44 #define VF_FLAG_VLAN_CAP 0x04
45 #define VF_FLAG_PROMISC_CAP 0x08
46 #define VF_FLAG_MAC_ANTI_SPOOF 0x10
48 #define IXL_PF_STATE_EMPR_RESETTING (1 << 0)
54 uint8_t mac[ETHER_ADDR_LEN];
58 struct ixl_pf_qtag qtag;
59 struct sysctl_ctx_list ctx;
62 /* Physical controller structure */
65 struct i40e_osdep osdep;
69 struct resource *pci_mem;
70 struct resource *msix_mem;
73 * Interrupt resources: this set is
74 * either used for legacy, or for Link
88 bool init_in_progress;
91 struct ixl_pf_qmgr qmgr;
92 struct ixl_pf_qtag qtag;
98 bool enable_tx_fc_filter;
109 struct taskqueue *tq;
113 int advertised_speed;
114 int fc; /* link flow ctrl setting */
115 enum ixl_dbg_mask dbg_mask;
118 /* Misc stats maintained by the driver */
122 /* Statistics from hw */
123 struct i40e_hw_port_stats stats;
124 struct i40e_hw_port_stats stats_offsets;
125 bool stat_offsets_loaded;
131 struct task vflr_task;
136 * Defines used for NVM update ioctls.
137 * This value is used in the Solaris tool, too.
139 #define I40E_NVM_ACCESS \
140 (((((((('E' << 4) + '1') << 4) + 'K') << 4) + 'G') << 4) | 5)
142 #define IXL_DEFAULT_PHY_INT_MASK \
143 ((~(I40E_AQ_EVENT_LINK_UPDOWN | I40E_AQ_EVENT_MODULE_QUAL_FAIL \
144 | I40E_AQ_EVENT_MEDIA_NA)) & 0x3FF)
146 /*** Sysctl help messages; displayed with "sysctl -d" ***/
148 #define IXL_SYSCTL_HELP_SET_ADVERTISE \
149 "\nControl advertised link speed.\n" \
151 "\t 0x1 - advertise 100M\n" \
152 "\t 0x2 - advertise 1G\n" \
153 "\t 0x4 - advertise 10G\n" \
154 "\t 0x8 - advertise 20G\n" \
155 "\t0x10 - advertise 25G\n" \
156 "\t0x20 - advertise 40G\n\n" \
157 "Set to 0 to disable link.\n" \
158 "Use \"sysctl -x\" to view flags properly."
160 #define IXL_SYSCTL_HELP_FC \
161 "\nSet flow control mode using the values below.\n" \
165 "\t3 - tx and rx pause"
167 #define IXL_SYSCTL_HELP_LINK_STATUS \
168 "\nExecutes a \"Get Link Status\" command on the Admin Queue, and displays" \
171 static char *ixl_fc_string[6] = {
180 static MALLOC_DEFINE(M_IXL, "ixl", "ixl driver allocations");
182 /*** Functions / Macros ***/
183 /* Adjust the level here to 10 or over to print stats messages */
184 #define I40E_VC_DEBUG(p, level, ...) \
187 ixl_dbg(p, IXL_DBG_IOV_VC, ##__VA_ARGS__); \
190 #define i40e_send_vf_nack(pf, vf, op, st) \
191 ixl_send_vf_nack_msg((pf), (vf), (op), (st), __FILE__, __LINE__)
193 #define IXL_PF_LOCK_INIT(_sc, _name) \
194 mtx_init(&(_sc)->pf_mtx, _name, "IXL PF Lock", MTX_DEF)
195 #define IXL_PF_LOCK(_sc) mtx_lock(&(_sc)->pf_mtx)
196 #define IXL_PF_UNLOCK(_sc) mtx_unlock(&(_sc)->pf_mtx)
197 #define IXL_PF_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->pf_mtx)
198 #define IXL_PF_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->pf_mtx, MA_OWNED)
201 #define ixl_dbg(p, m, s, ...) ixl_debug_core(p, m, s, ##__VA_ARGS__)
202 void ixl_debug_core(struct ixl_pf *, enum ixl_dbg_mask, char *, ...);
204 /* For stats sysctl naming */
205 #define QUEUE_NAME_LEN 32
207 /* For netmap(4) compatibility */
208 #define ixl_disable_intr(vsi) ixl_disable_rings_intr(vsi)
211 * PF-only function declarations
214 void ixl_set_busmaster(device_t);
215 void ixl_set_msix_enable(device_t);
216 int ixl_setup_interface(device_t, struct ixl_vsi *);
217 void ixl_print_nvm_cmd(device_t, struct i40e_nvm_access *);
218 char * ixl_aq_speed_to_str(enum i40e_aq_link_speed);
220 void ixl_handle_que(void *context, int pending);
222 void ixl_init(void *);
223 void ixl_local_timer(void *);
224 void ixl_register_vlan(void *, struct ifnet *, u16);
225 void ixl_unregister_vlan(void *, struct ifnet *, u16);
226 void ixl_intr(void *);
227 void ixl_msix_que(void *);
228 void ixl_msix_adminq(void *);
229 void ixl_do_adminq(void *, int);
231 int ixl_res_alloc_cmp(const void *, const void *);
232 char * ixl_switch_res_type_string(u8);
233 char * ixl_switch_element_string(struct sbuf *,
234 struct i40e_aqc_switch_config_element_resp *);
235 void ixl_add_sysctls_mac_stats(struct sysctl_ctx_list *,
236 struct sysctl_oid_list *, struct i40e_hw_port_stats *);
237 void ixl_add_sysctls_eth_stats(struct sysctl_ctx_list *,
238 struct sysctl_oid_list *,
239 struct i40e_eth_stats *);
241 void ixl_media_status(struct ifnet *, struct ifmediareq *);
242 int ixl_media_change(struct ifnet *);
243 int ixl_ioctl(struct ifnet *, u_long, caddr_t);
245 void ixl_enable_queue(struct i40e_hw *, int);
246 void ixl_disable_queue(struct i40e_hw *, int);
247 void ixl_enable_intr0(struct i40e_hw *);
248 void ixl_disable_intr0(struct i40e_hw *);
249 void ixl_nvm_version_str(struct i40e_hw *hw, struct sbuf *buf);
250 void ixl_stat_update48(struct i40e_hw *, u32, u32, bool,
252 void ixl_stat_update32(struct i40e_hw *, u32, bool,
255 void ixl_stop(struct ixl_pf *);
256 void ixl_add_vsi_sysctls(struct ixl_pf *pf, struct ixl_vsi *vsi, struct sysctl_ctx_list *ctx, const char *sysctl_name);
257 int ixl_get_hw_capabilities(struct ixl_pf *);
258 void ixl_link_up_msg(struct ixl_pf *);
259 void ixl_update_link_status(struct ixl_pf *);
260 int ixl_allocate_pci_resources(struct ixl_pf *);
261 int ixl_setup_stations(struct ixl_pf *);
262 int ixl_switch_config(struct ixl_pf *);
263 void ixl_stop_locked(struct ixl_pf *);
264 int ixl_teardown_hw_structs(struct ixl_pf *);
265 int ixl_reset(struct ixl_pf *);
266 void ixl_init_locked(struct ixl_pf *);
267 void ixl_set_rss_key(struct ixl_pf *);
268 void ixl_set_rss_pctypes(struct ixl_pf *);
269 void ixl_set_rss_hlut(struct ixl_pf *);
270 int ixl_setup_adminq_msix(struct ixl_pf *);
271 int ixl_setup_adminq_tq(struct ixl_pf *);
272 int ixl_teardown_adminq_msix(struct ixl_pf *);
273 void ixl_configure_intr0_msix(struct ixl_pf *);
274 void ixl_configure_queue_intr_msix(struct ixl_pf *);
275 void ixl_free_adminq_tq(struct ixl_pf *);
276 int ixl_setup_legacy(struct ixl_pf *);
277 int ixl_init_msix(struct ixl_pf *);
278 void ixl_configure_itr(struct ixl_pf *);
279 void ixl_configure_legacy(struct ixl_pf *);
280 void ixl_free_pci_resources(struct ixl_pf *);
281 void ixl_link_event(struct ixl_pf *, struct i40e_arq_event_info *);
282 void ixl_config_rss(struct ixl_pf *);
283 int ixl_set_advertised_speeds(struct ixl_pf *, int);
284 void ixl_get_initial_advertised_speeds(struct ixl_pf *);
285 void ixl_print_nvm_version(struct ixl_pf *pf);
286 void ixl_add_device_sysctls(struct ixl_pf *);
287 void ixl_handle_mdd_event(struct ixl_pf *);
288 void ixl_add_hw_stats(struct ixl_pf *);
289 void ixl_update_stats_counters(struct ixl_pf *);
290 void ixl_pf_reset_stats(struct ixl_pf *);
291 void ixl_get_bus_info(struct ixl_pf *pf);
292 int ixl_aq_get_link_status(struct ixl_pf *,
293 struct i40e_aqc_get_link_status *);
295 int ixl_handle_nvmupd_cmd(struct ixl_pf *, struct ifdrv *);
296 void ixl_handle_empr_reset(struct ixl_pf *);
297 int ixl_rebuild_hw_structs_after_reset(struct ixl_pf *);
299 void ixl_set_queue_rx_itr(struct ixl_queue *);
300 void ixl_set_queue_tx_itr(struct ixl_queue *);
302 void ixl_add_filter(struct ixl_vsi *, u8 *, s16 vlan);
303 void ixl_del_filter(struct ixl_vsi *, u8 *, s16 vlan);
304 void ixl_reconfigure_filters(struct ixl_vsi *vsi);
306 int ixl_disable_rings(struct ixl_vsi *);
307 int ixl_disable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
308 int ixl_disable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
309 int ixl_disable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16);
311 int ixl_enable_rings(struct ixl_vsi *);
312 int ixl_enable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
313 int ixl_enable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
314 int ixl_enable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16);
316 void ixl_update_eth_stats(struct ixl_vsi *);
317 void ixl_cap_txcsum_tso(struct ixl_vsi *, struct ifnet *, int);
318 int ixl_initialize_vsi(struct ixl_vsi *);
319 void ixl_add_ifmedia(struct ixl_vsi *, u64);
320 int ixl_setup_queue_msix(struct ixl_vsi *);
321 int ixl_setup_queue_tqs(struct ixl_vsi *);
322 int ixl_teardown_queue_msix(struct ixl_vsi *);
323 void ixl_free_queue_tqs(struct ixl_vsi *);
324 void ixl_enable_intr(struct ixl_vsi *);
325 void ixl_disable_rings_intr(struct ixl_vsi *);
326 void ixl_set_promisc(struct ixl_vsi *);
327 void ixl_add_multi(struct ixl_vsi *);
328 void ixl_del_multi(struct ixl_vsi *);
329 void ixl_setup_vlan_filters(struct ixl_vsi *);
330 void ixl_init_filters(struct ixl_vsi *);
331 void ixl_add_hw_filters(struct ixl_vsi *, int, int);
332 void ixl_del_hw_filters(struct ixl_vsi *, int);
333 struct ixl_mac_filter *
334 ixl_find_filter(struct ixl_vsi *, u8 *, s16);
335 void ixl_add_mc_filter(struct ixl_vsi *, u8 *);
336 void ixl_free_mac_filters(struct ixl_vsi *vsi);
337 void ixl_update_vsi_stats(struct ixl_vsi *);
338 void ixl_vsi_reset_stats(struct ixl_vsi *);
341 * I2C Function prototypes
343 int ixl_find_i2c_interface(struct ixl_pf *);
344 s32 ixl_read_i2c_byte(struct ixl_pf *pf, u8 byte_offset,
345 u8 dev_addr, u8 *data);
346 s32 ixl_write_i2c_byte(struct ixl_pf *pf, u8 byte_offset,
347 u8 dev_addr, u8 data);
349 #endif /* _IXL_PF_H_ */