161ae650dSJack F Vogel /****************************************************************************** 261ae650dSJack F Vogel 3b6c8f260SJack F Vogel Copyright (c) 2013-2015, Intel Corporation 461ae650dSJack F Vogel All rights reserved. 561ae650dSJack F Vogel 661ae650dSJack F Vogel Redistribution and use in source and binary forms, with or without 761ae650dSJack F Vogel modification, are permitted provided that the following conditions are met: 861ae650dSJack F Vogel 961ae650dSJack F Vogel 1. Redistributions of source code must retain the above copyright notice, 1061ae650dSJack F Vogel this list of conditions and the following disclaimer. 1161ae650dSJack F Vogel 1261ae650dSJack F Vogel 2. Redistributions in binary form must reproduce the above copyright 1361ae650dSJack F Vogel notice, this list of conditions and the following disclaimer in the 1461ae650dSJack F Vogel documentation and/or other materials provided with the distribution. 1561ae650dSJack F Vogel 1661ae650dSJack F Vogel 3. Neither the name of the Intel Corporation nor the names of its 1761ae650dSJack F Vogel contributors may be used to endorse or promote products derived from 1861ae650dSJack F Vogel this software without specific prior written permission. 1961ae650dSJack F Vogel 2061ae650dSJack F Vogel THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 2161ae650dSJack F Vogel AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2261ae650dSJack F Vogel IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2361ae650dSJack F Vogel ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 2461ae650dSJack F Vogel LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2561ae650dSJack F Vogel CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2661ae650dSJack F Vogel SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2761ae650dSJack F Vogel INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2861ae650dSJack F Vogel CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2961ae650dSJack F Vogel ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3061ae650dSJack F Vogel POSSIBILITY OF SUCH DAMAGE. 3161ae650dSJack F Vogel 3261ae650dSJack F Vogel ******************************************************************************/ 3361ae650dSJack F Vogel /*$FreeBSD$*/ 3461ae650dSJack F Vogel 35b6c8f260SJack F Vogel #ifndef IXL_STANDALONE_BUILD 3661ae650dSJack F Vogel #include "opt_inet.h" 3761ae650dSJack F Vogel #include "opt_inet6.h" 38393c4bb1SJack F Vogel #include "opt_rss.h" 39b6c8f260SJack F Vogel #endif 40b6c8f260SJack F Vogel 4161ae650dSJack F Vogel #include "ixl.h" 4261ae650dSJack F Vogel #include "ixl_pf.h" 4361ae650dSJack F Vogel 44dcd7b3b2SJack F Vogel #ifdef RSS 45dcd7b3b2SJack F Vogel #include <net/rss_config.h> 46dcd7b3b2SJack F Vogel #endif 47dcd7b3b2SJack F Vogel 4861ae650dSJack F Vogel /********************************************************************* 4961ae650dSJack F Vogel * Driver version 5061ae650dSJack F Vogel *********************************************************************/ 5156c2c47bSJack F Vogel char ixl_driver_version[] = "1.4.1"; 5261ae650dSJack F Vogel 5361ae650dSJack F Vogel /********************************************************************* 5461ae650dSJack F Vogel * PCI Device ID Table 5561ae650dSJack F Vogel * 5661ae650dSJack F Vogel * Used by probe to select devices to load on 5761ae650dSJack F Vogel * Last field stores an index into ixl_strings 5861ae650dSJack F Vogel * Last entry must be all 0s 5961ae650dSJack F Vogel * 6061ae650dSJack F Vogel * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index } 6161ae650dSJack F Vogel *********************************************************************/ 6261ae650dSJack F Vogel 6361ae650dSJack F Vogel static ixl_vendor_info_t ixl_vendor_info_array[] = 6461ae650dSJack F Vogel { 6561ae650dSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710, 0, 0, 0}, 6661ae650dSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_A, 0, 0, 0}, 6761ae650dSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B, 0, 0, 0}, 6861ae650dSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C, 0, 0, 0}, 6961ae650dSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A, 0, 0, 0}, 7061ae650dSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B, 0, 0, 0}, 7161ae650dSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C, 0, 0, 0}, 7261ae650dSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T, 0, 0, 0}, 7356c2c47bSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2, 0, 0, 0}, 7461ae650dSJack F Vogel /* required last entry */ 7561ae650dSJack F Vogel {0, 0, 0, 0, 0} 7661ae650dSJack F Vogel }; 7761ae650dSJack F Vogel 7861ae650dSJack F Vogel /********************************************************************* 7961ae650dSJack F Vogel * Table of branding strings 8061ae650dSJack F Vogel *********************************************************************/ 8161ae650dSJack F Vogel 8261ae650dSJack F Vogel static char *ixl_strings[] = { 8361ae650dSJack F Vogel "Intel(R) Ethernet Connection XL710 Driver" 8461ae650dSJack F Vogel }; 8561ae650dSJack F Vogel 8661ae650dSJack F Vogel 8761ae650dSJack F Vogel /********************************************************************* 8861ae650dSJack F Vogel * Function prototypes 8961ae650dSJack F Vogel *********************************************************************/ 9061ae650dSJack F Vogel static int ixl_probe(device_t); 9161ae650dSJack F Vogel static int ixl_attach(device_t); 9261ae650dSJack F Vogel static int ixl_detach(device_t); 9361ae650dSJack F Vogel static int ixl_shutdown(device_t); 9461ae650dSJack F Vogel static int ixl_get_hw_capabilities(struct ixl_pf *); 9561ae650dSJack F Vogel static void ixl_cap_txcsum_tso(struct ixl_vsi *, struct ifnet *, int); 9661ae650dSJack F Vogel static int ixl_ioctl(struct ifnet *, u_long, caddr_t); 9761ae650dSJack F Vogel static void ixl_init(void *); 9861ae650dSJack F Vogel static void ixl_init_locked(struct ixl_pf *); 9961ae650dSJack F Vogel static void ixl_stop(struct ixl_pf *); 10061ae650dSJack F Vogel static void ixl_media_status(struct ifnet *, struct ifmediareq *); 10161ae650dSJack F Vogel static int ixl_media_change(struct ifnet *); 10261ae650dSJack F Vogel static void ixl_update_link_status(struct ixl_pf *); 10361ae650dSJack F Vogel static int ixl_allocate_pci_resources(struct ixl_pf *); 10461ae650dSJack F Vogel static u16 ixl_get_bus_info(struct i40e_hw *, device_t); 10561ae650dSJack F Vogel static int ixl_setup_stations(struct ixl_pf *); 106b6c8f260SJack F Vogel static int ixl_switch_config(struct ixl_pf *); 10761ae650dSJack F Vogel static int ixl_initialize_vsi(struct ixl_vsi *); 10861ae650dSJack F Vogel static int ixl_assign_vsi_msix(struct ixl_pf *); 10961ae650dSJack F Vogel static int ixl_assign_vsi_legacy(struct ixl_pf *); 11061ae650dSJack F Vogel static int ixl_init_msix(struct ixl_pf *); 11161ae650dSJack F Vogel static void ixl_configure_msix(struct ixl_pf *); 11261ae650dSJack F Vogel static void ixl_configure_itr(struct ixl_pf *); 11361ae650dSJack F Vogel static void ixl_configure_legacy(struct ixl_pf *); 11461ae650dSJack F Vogel static void ixl_free_pci_resources(struct ixl_pf *); 11561ae650dSJack F Vogel static void ixl_local_timer(void *); 11661ae650dSJack F Vogel static int ixl_setup_interface(device_t, struct ixl_vsi *); 11756c2c47bSJack F Vogel static void ixl_link_event(struct ixl_pf *, struct i40e_arq_event_info *); 11861ae650dSJack F Vogel static void ixl_config_rss(struct ixl_vsi *); 11961ae650dSJack F Vogel static void ixl_set_queue_rx_itr(struct ixl_queue *); 12061ae650dSJack F Vogel static void ixl_set_queue_tx_itr(struct ixl_queue *); 121e5100ee2SJack F Vogel static int ixl_set_advertised_speeds(struct ixl_pf *, int); 12261ae650dSJack F Vogel 12356c2c47bSJack F Vogel static int ixl_enable_rings(struct ixl_vsi *); 12456c2c47bSJack F Vogel static int ixl_disable_rings(struct ixl_vsi *); 12561ae650dSJack F Vogel static void ixl_enable_intr(struct ixl_vsi *); 12661ae650dSJack F Vogel static void ixl_disable_intr(struct ixl_vsi *); 12756c2c47bSJack F Vogel static void ixl_disable_rings_intr(struct ixl_vsi *); 12861ae650dSJack F Vogel 12961ae650dSJack F Vogel static void ixl_enable_adminq(struct i40e_hw *); 13061ae650dSJack F Vogel static void ixl_disable_adminq(struct i40e_hw *); 13161ae650dSJack F Vogel static void ixl_enable_queue(struct i40e_hw *, int); 13261ae650dSJack F Vogel static void ixl_disable_queue(struct i40e_hw *, int); 13361ae650dSJack F Vogel static void ixl_enable_legacy(struct i40e_hw *); 13461ae650dSJack F Vogel static void ixl_disable_legacy(struct i40e_hw *); 13561ae650dSJack F Vogel 13661ae650dSJack F Vogel static void ixl_set_promisc(struct ixl_vsi *); 13761ae650dSJack F Vogel static void ixl_add_multi(struct ixl_vsi *); 13861ae650dSJack F Vogel static void ixl_del_multi(struct ixl_vsi *); 13961ae650dSJack F Vogel static void ixl_register_vlan(void *, struct ifnet *, u16); 14061ae650dSJack F Vogel static void ixl_unregister_vlan(void *, struct ifnet *, u16); 14161ae650dSJack F Vogel static void ixl_setup_vlan_filters(struct ixl_vsi *); 14261ae650dSJack F Vogel 14361ae650dSJack F Vogel static void ixl_init_filters(struct ixl_vsi *); 14456c2c47bSJack F Vogel static void ixl_reconfigure_filters(struct ixl_vsi *vsi); 14561ae650dSJack F Vogel static void ixl_add_filter(struct ixl_vsi *, u8 *, s16 vlan); 14661ae650dSJack F Vogel static void ixl_del_filter(struct ixl_vsi *, u8 *, s16 vlan); 14761ae650dSJack F Vogel static void ixl_add_hw_filters(struct ixl_vsi *, int, int); 14861ae650dSJack F Vogel static void ixl_del_hw_filters(struct ixl_vsi *, int); 14961ae650dSJack F Vogel static struct ixl_mac_filter * 15061ae650dSJack F Vogel ixl_find_filter(struct ixl_vsi *, u8 *, s16); 15161ae650dSJack F Vogel static void ixl_add_mc_filter(struct ixl_vsi *, u8 *); 15256c2c47bSJack F Vogel static void ixl_free_mac_filters(struct ixl_vsi *vsi); 15356c2c47bSJack F Vogel 15461ae650dSJack F Vogel 15561ae650dSJack F Vogel /* Sysctl debug interface */ 15661ae650dSJack F Vogel static int ixl_debug_info(SYSCTL_HANDLER_ARGS); 15761ae650dSJack F Vogel static void ixl_print_debug_info(struct ixl_pf *); 15861ae650dSJack F Vogel 15961ae650dSJack F Vogel /* The MSI/X Interrupt handlers */ 16061ae650dSJack F Vogel static void ixl_intr(void *); 16161ae650dSJack F Vogel static void ixl_msix_que(void *); 16261ae650dSJack F Vogel static void ixl_msix_adminq(void *); 16361ae650dSJack F Vogel static void ixl_handle_mdd_event(struct ixl_pf *); 16461ae650dSJack F Vogel 16561ae650dSJack F Vogel /* Deferred interrupt tasklets */ 16661ae650dSJack F Vogel static void ixl_do_adminq(void *, int); 16761ae650dSJack F Vogel 16861ae650dSJack F Vogel /* Sysctl handlers */ 16961ae650dSJack F Vogel static int ixl_set_flowcntl(SYSCTL_HANDLER_ARGS); 17061ae650dSJack F Vogel static int ixl_set_advertise(SYSCTL_HANDLER_ARGS); 17161ae650dSJack F Vogel static int ixl_current_speed(SYSCTL_HANDLER_ARGS); 172e5100ee2SJack F Vogel static int ixl_sysctl_show_fw(SYSCTL_HANDLER_ARGS); 17361ae650dSJack F Vogel 17461ae650dSJack F Vogel /* Statistics */ 17561ae650dSJack F Vogel static void ixl_add_hw_stats(struct ixl_pf *); 17661ae650dSJack F Vogel static void ixl_add_sysctls_mac_stats(struct sysctl_ctx_list *, 17761ae650dSJack F Vogel struct sysctl_oid_list *, struct i40e_hw_port_stats *); 17861ae650dSJack F Vogel static void ixl_add_sysctls_eth_stats(struct sysctl_ctx_list *, 17961ae650dSJack F Vogel struct sysctl_oid_list *, 18061ae650dSJack F Vogel struct i40e_eth_stats *); 18161ae650dSJack F Vogel static void ixl_update_stats_counters(struct ixl_pf *); 18261ae650dSJack F Vogel static void ixl_update_eth_stats(struct ixl_vsi *); 18356c2c47bSJack F Vogel static void ixl_update_vsi_stats(struct ixl_vsi *); 18461ae650dSJack F Vogel static void ixl_pf_reset_stats(struct ixl_pf *); 18561ae650dSJack F Vogel static void ixl_vsi_reset_stats(struct ixl_vsi *); 18661ae650dSJack F Vogel static void ixl_stat_update48(struct i40e_hw *, u32, u32, bool, 18761ae650dSJack F Vogel u64 *, u64 *); 18861ae650dSJack F Vogel static void ixl_stat_update32(struct i40e_hw *, u32, bool, 18961ae650dSJack F Vogel u64 *, u64 *); 19061ae650dSJack F Vogel 191393c4bb1SJack F Vogel #ifdef IXL_DEBUG_SYSCTL 19261ae650dSJack F Vogel static int ixl_sysctl_link_status(SYSCTL_HANDLER_ARGS); 19361ae650dSJack F Vogel static int ixl_sysctl_phy_abilities(SYSCTL_HANDLER_ARGS); 19461ae650dSJack F Vogel static int ixl_sysctl_sw_filter_list(SYSCTL_HANDLER_ARGS); 195e5100ee2SJack F Vogel static int ixl_sysctl_hw_res_alloc(SYSCTL_HANDLER_ARGS); 196e5100ee2SJack F Vogel static int ixl_sysctl_switch_config(SYSCTL_HANDLER_ARGS); 19756c2c47bSJack F Vogel #endif 19856c2c47bSJack F Vogel 19956c2c47bSJack F Vogel #ifdef PCI_IOV 20056c2c47bSJack F Vogel static int ixl_adminq_err_to_errno(enum i40e_admin_queue_err err); 20156c2c47bSJack F Vogel 20256c2c47bSJack F Vogel static int ixl_init_iov(device_t dev, uint16_t num_vfs, const nvlist_t*); 20356c2c47bSJack F Vogel static void ixl_uninit_iov(device_t dev); 20456c2c47bSJack F Vogel static int ixl_add_vf(device_t dev, uint16_t vfnum, const nvlist_t*); 20556c2c47bSJack F Vogel 20656c2c47bSJack F Vogel static void ixl_handle_vf_msg(struct ixl_pf *, 20756c2c47bSJack F Vogel struct i40e_arq_event_info *); 20856c2c47bSJack F Vogel static void ixl_handle_vflr(void *arg, int pending); 20956c2c47bSJack F Vogel 21056c2c47bSJack F Vogel static void ixl_reset_vf(struct ixl_pf *pf, struct ixl_vf *vf); 21156c2c47bSJack F Vogel static void ixl_reinit_vf(struct ixl_pf *pf, struct ixl_vf *vf); 21261ae650dSJack F Vogel #endif 21361ae650dSJack F Vogel 21461ae650dSJack F Vogel /********************************************************************* 21561ae650dSJack F Vogel * FreeBSD Device Interface Entry Points 21661ae650dSJack F Vogel *********************************************************************/ 21761ae650dSJack F Vogel 21861ae650dSJack F Vogel static device_method_t ixl_methods[] = { 21961ae650dSJack F Vogel /* Device interface */ 22061ae650dSJack F Vogel DEVMETHOD(device_probe, ixl_probe), 22161ae650dSJack F Vogel DEVMETHOD(device_attach, ixl_attach), 22261ae650dSJack F Vogel DEVMETHOD(device_detach, ixl_detach), 22361ae650dSJack F Vogel DEVMETHOD(device_shutdown, ixl_shutdown), 22456c2c47bSJack F Vogel #ifdef PCI_IOV 22556c2c47bSJack F Vogel DEVMETHOD(pci_init_iov, ixl_init_iov), 22656c2c47bSJack F Vogel DEVMETHOD(pci_uninit_iov, ixl_uninit_iov), 22756c2c47bSJack F Vogel DEVMETHOD(pci_add_vf, ixl_add_vf), 22856c2c47bSJack F Vogel #endif 22961ae650dSJack F Vogel {0, 0} 23061ae650dSJack F Vogel }; 23161ae650dSJack F Vogel 23261ae650dSJack F Vogel static driver_t ixl_driver = { 23361ae650dSJack F Vogel "ixl", ixl_methods, sizeof(struct ixl_pf), 23461ae650dSJack F Vogel }; 23561ae650dSJack F Vogel 23661ae650dSJack F Vogel devclass_t ixl_devclass; 23761ae650dSJack F Vogel DRIVER_MODULE(ixl, pci, ixl_driver, ixl_devclass, 0, 0); 23861ae650dSJack F Vogel 23961ae650dSJack F Vogel MODULE_DEPEND(ixl, pci, 1, 1, 1); 24061ae650dSJack F Vogel MODULE_DEPEND(ixl, ether, 1, 1, 1); 24161ae650dSJack F Vogel 242*31830672SJack F Vogel #ifdef DEV_NETMAP 243*31830672SJack F Vogel MODULE_DEPEND(ixl, netmap, 1, 1, 1); 244*31830672SJack F Vogel #endif /* DEV_NETMAP */ 245*31830672SJack F Vogel 246*31830672SJack F Vogel 24761ae650dSJack F Vogel /* 24861ae650dSJack F Vogel ** Global reset mutex 24961ae650dSJack F Vogel */ 25061ae650dSJack F Vogel static struct mtx ixl_reset_mtx; 25161ae650dSJack F Vogel 25261ae650dSJack F Vogel /* 25361ae650dSJack F Vogel ** TUNEABLE PARAMETERS: 25461ae650dSJack F Vogel */ 25561ae650dSJack F Vogel 25661ae650dSJack F Vogel static SYSCTL_NODE(_hw, OID_AUTO, ixl, CTLFLAG_RD, 0, 25761ae650dSJack F Vogel "IXL driver parameters"); 25861ae650dSJack F Vogel 25961ae650dSJack F Vogel /* 26061ae650dSJack F Vogel * MSIX should be the default for best performance, 26161ae650dSJack F Vogel * but this allows it to be forced off for testing. 26261ae650dSJack F Vogel */ 26361ae650dSJack F Vogel static int ixl_enable_msix = 1; 26461ae650dSJack F Vogel TUNABLE_INT("hw.ixl.enable_msix", &ixl_enable_msix); 26561ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, enable_msix, CTLFLAG_RDTUN, &ixl_enable_msix, 0, 26661ae650dSJack F Vogel "Enable MSI-X interrupts"); 26761ae650dSJack F Vogel 26861ae650dSJack F Vogel /* 26961ae650dSJack F Vogel ** Number of descriptors per ring: 27061ae650dSJack F Vogel ** - TX and RX are the same size 27161ae650dSJack F Vogel */ 27261ae650dSJack F Vogel static int ixl_ringsz = DEFAULT_RING; 27361ae650dSJack F Vogel TUNABLE_INT("hw.ixl.ringsz", &ixl_ringsz); 27461ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, ring_size, CTLFLAG_RDTUN, 27561ae650dSJack F Vogel &ixl_ringsz, 0, "Descriptor Ring Size"); 27661ae650dSJack F Vogel 27761ae650dSJack F Vogel /* 27861ae650dSJack F Vogel ** This can be set manually, if left as 0 the 27961ae650dSJack F Vogel ** number of queues will be calculated based 28061ae650dSJack F Vogel ** on cpus and msix vectors available. 28161ae650dSJack F Vogel */ 28261ae650dSJack F Vogel int ixl_max_queues = 0; 28361ae650dSJack F Vogel TUNABLE_INT("hw.ixl.max_queues", &ixl_max_queues); 28461ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, max_queues, CTLFLAG_RDTUN, 28561ae650dSJack F Vogel &ixl_max_queues, 0, "Number of Queues"); 28661ae650dSJack F Vogel 28761ae650dSJack F Vogel /* 28861ae650dSJack F Vogel ** Controls for Interrupt Throttling 28961ae650dSJack F Vogel ** - true/false for dynamic adjustment 29061ae650dSJack F Vogel ** - default values for static ITR 29161ae650dSJack F Vogel */ 29261ae650dSJack F Vogel int ixl_dynamic_rx_itr = 0; 29361ae650dSJack F Vogel TUNABLE_INT("hw.ixl.dynamic_rx_itr", &ixl_dynamic_rx_itr); 29461ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, dynamic_rx_itr, CTLFLAG_RDTUN, 29561ae650dSJack F Vogel &ixl_dynamic_rx_itr, 0, "Dynamic RX Interrupt Rate"); 29661ae650dSJack F Vogel 29761ae650dSJack F Vogel int ixl_dynamic_tx_itr = 0; 29861ae650dSJack F Vogel TUNABLE_INT("hw.ixl.dynamic_tx_itr", &ixl_dynamic_tx_itr); 29961ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, dynamic_tx_itr, CTLFLAG_RDTUN, 30061ae650dSJack F Vogel &ixl_dynamic_tx_itr, 0, "Dynamic TX Interrupt Rate"); 30161ae650dSJack F Vogel 30261ae650dSJack F Vogel int ixl_rx_itr = IXL_ITR_8K; 30361ae650dSJack F Vogel TUNABLE_INT("hw.ixl.rx_itr", &ixl_rx_itr); 30461ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, rx_itr, CTLFLAG_RDTUN, 30561ae650dSJack F Vogel &ixl_rx_itr, 0, "RX Interrupt Rate"); 30661ae650dSJack F Vogel 30761ae650dSJack F Vogel int ixl_tx_itr = IXL_ITR_4K; 30861ae650dSJack F Vogel TUNABLE_INT("hw.ixl.tx_itr", &ixl_tx_itr); 30961ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, tx_itr, CTLFLAG_RDTUN, 31061ae650dSJack F Vogel &ixl_tx_itr, 0, "TX Interrupt Rate"); 31161ae650dSJack F Vogel 31261ae650dSJack F Vogel #ifdef IXL_FDIR 31361ae650dSJack F Vogel static int ixl_enable_fdir = 1; 31461ae650dSJack F Vogel TUNABLE_INT("hw.ixl.enable_fdir", &ixl_enable_fdir); 31561ae650dSJack F Vogel /* Rate at which we sample */ 31661ae650dSJack F Vogel int ixl_atr_rate = 20; 31761ae650dSJack F Vogel TUNABLE_INT("hw.ixl.atr_rate", &ixl_atr_rate); 31861ae650dSJack F Vogel #endif 31961ae650dSJack F Vogel 320*31830672SJack F Vogel #ifdef DEV_NETMAP 321*31830672SJack F Vogel #define NETMAP_IXL_MAIN /* only bring in one part of the netmap code */ 322*31830672SJack F Vogel #include <dev/netmap/if_ixl_netmap.h> 323*31830672SJack F Vogel #endif /* DEV_NETMAP */ 324e5100ee2SJack F Vogel 32561ae650dSJack F Vogel static char *ixl_fc_string[6] = { 32661ae650dSJack F Vogel "None", 32761ae650dSJack F Vogel "Rx", 32861ae650dSJack F Vogel "Tx", 32961ae650dSJack F Vogel "Full", 33061ae650dSJack F Vogel "Priority", 33161ae650dSJack F Vogel "Default" 33261ae650dSJack F Vogel }; 33361ae650dSJack F Vogel 33456c2c47bSJack F Vogel static MALLOC_DEFINE(M_IXL, "ixl", "ixl driver allocations"); 33556c2c47bSJack F Vogel 33656c2c47bSJack F Vogel static uint8_t ixl_bcast_addr[ETHER_ADDR_LEN] = 33756c2c47bSJack F Vogel {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 33861ae650dSJack F Vogel 33961ae650dSJack F Vogel /********************************************************************* 34061ae650dSJack F Vogel * Device identification routine 34161ae650dSJack F Vogel * 34261ae650dSJack F Vogel * ixl_probe determines if the driver should be loaded on 34361ae650dSJack F Vogel * the hardware based on PCI vendor/device id of the device. 34461ae650dSJack F Vogel * 34561ae650dSJack F Vogel * return BUS_PROBE_DEFAULT on success, positive on failure 34661ae650dSJack F Vogel *********************************************************************/ 34761ae650dSJack F Vogel 34861ae650dSJack F Vogel static int 34961ae650dSJack F Vogel ixl_probe(device_t dev) 35061ae650dSJack F Vogel { 35161ae650dSJack F Vogel ixl_vendor_info_t *ent; 35261ae650dSJack F Vogel 35361ae650dSJack F Vogel u16 pci_vendor_id, pci_device_id; 35461ae650dSJack F Vogel u16 pci_subvendor_id, pci_subdevice_id; 35561ae650dSJack F Vogel char device_name[256]; 35661ae650dSJack F Vogel static bool lock_init = FALSE; 35761ae650dSJack F Vogel 35861ae650dSJack F Vogel INIT_DEBUGOUT("ixl_probe: begin"); 35961ae650dSJack F Vogel 36061ae650dSJack F Vogel pci_vendor_id = pci_get_vendor(dev); 36161ae650dSJack F Vogel if (pci_vendor_id != I40E_INTEL_VENDOR_ID) 36261ae650dSJack F Vogel return (ENXIO); 36361ae650dSJack F Vogel 36461ae650dSJack F Vogel pci_device_id = pci_get_device(dev); 36561ae650dSJack F Vogel pci_subvendor_id = pci_get_subvendor(dev); 36661ae650dSJack F Vogel pci_subdevice_id = pci_get_subdevice(dev); 36761ae650dSJack F Vogel 36861ae650dSJack F Vogel ent = ixl_vendor_info_array; 36961ae650dSJack F Vogel while (ent->vendor_id != 0) { 37061ae650dSJack F Vogel if ((pci_vendor_id == ent->vendor_id) && 37161ae650dSJack F Vogel (pci_device_id == ent->device_id) && 37261ae650dSJack F Vogel 37361ae650dSJack F Vogel ((pci_subvendor_id == ent->subvendor_id) || 37461ae650dSJack F Vogel (ent->subvendor_id == 0)) && 37561ae650dSJack F Vogel 37661ae650dSJack F Vogel ((pci_subdevice_id == ent->subdevice_id) || 37761ae650dSJack F Vogel (ent->subdevice_id == 0))) { 37861ae650dSJack F Vogel sprintf(device_name, "%s, Version - %s", 37961ae650dSJack F Vogel ixl_strings[ent->index], 38061ae650dSJack F Vogel ixl_driver_version); 38161ae650dSJack F Vogel device_set_desc_copy(dev, device_name); 38261ae650dSJack F Vogel /* One shot mutex init */ 38361ae650dSJack F Vogel if (lock_init == FALSE) { 38461ae650dSJack F Vogel lock_init = TRUE; 38561ae650dSJack F Vogel mtx_init(&ixl_reset_mtx, 38661ae650dSJack F Vogel "ixl_reset", 38761ae650dSJack F Vogel "IXL RESET Lock", MTX_DEF); 38861ae650dSJack F Vogel } 38961ae650dSJack F Vogel return (BUS_PROBE_DEFAULT); 39061ae650dSJack F Vogel } 39161ae650dSJack F Vogel ent++; 39261ae650dSJack F Vogel } 39361ae650dSJack F Vogel return (ENXIO); 39461ae650dSJack F Vogel } 39561ae650dSJack F Vogel 39661ae650dSJack F Vogel /********************************************************************* 39761ae650dSJack F Vogel * Device initialization routine 39861ae650dSJack F Vogel * 39961ae650dSJack F Vogel * The attach entry point is called when the driver is being loaded. 40061ae650dSJack F Vogel * This routine identifies the type of hardware, allocates all resources 40161ae650dSJack F Vogel * and initializes the hardware. 40261ae650dSJack F Vogel * 40361ae650dSJack F Vogel * return 0 on success, positive on failure 40461ae650dSJack F Vogel *********************************************************************/ 40561ae650dSJack F Vogel 40661ae650dSJack F Vogel static int 40761ae650dSJack F Vogel ixl_attach(device_t dev) 40861ae650dSJack F Vogel { 40961ae650dSJack F Vogel struct ixl_pf *pf; 41061ae650dSJack F Vogel struct i40e_hw *hw; 41161ae650dSJack F Vogel struct ixl_vsi *vsi; 41261ae650dSJack F Vogel u16 bus; 41361ae650dSJack F Vogel int error = 0; 41456c2c47bSJack F Vogel #ifdef PCI_IOV 41556c2c47bSJack F Vogel nvlist_t *pf_schema, *vf_schema; 41656c2c47bSJack F Vogel int iov_error; 41756c2c47bSJack F Vogel #endif 41861ae650dSJack F Vogel 41961ae650dSJack F Vogel INIT_DEBUGOUT("ixl_attach: begin"); 42061ae650dSJack F Vogel 42161ae650dSJack F Vogel /* Allocate, clear, and link in our primary soft structure */ 42261ae650dSJack F Vogel pf = device_get_softc(dev); 42361ae650dSJack F Vogel pf->dev = pf->osdep.dev = dev; 42461ae650dSJack F Vogel hw = &pf->hw; 42561ae650dSJack F Vogel 42661ae650dSJack F Vogel /* 42761ae650dSJack F Vogel ** Note this assumes we have a single embedded VSI, 42861ae650dSJack F Vogel ** this could be enhanced later to allocate multiple 42961ae650dSJack F Vogel */ 43061ae650dSJack F Vogel vsi = &pf->vsi; 43161ae650dSJack F Vogel vsi->dev = pf->dev; 43261ae650dSJack F Vogel 43361ae650dSJack F Vogel /* Core Lock Init*/ 43461ae650dSJack F Vogel IXL_PF_LOCK_INIT(pf, device_get_nameunit(dev)); 43561ae650dSJack F Vogel 43661ae650dSJack F Vogel /* Set up the timer callout */ 43761ae650dSJack F Vogel callout_init_mtx(&pf->timer, &pf->pf_mtx, 0); 43861ae650dSJack F Vogel 43961ae650dSJack F Vogel /* Set up sysctls */ 44061ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 44161ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 44261ae650dSJack F Vogel OID_AUTO, "fc", CTLTYPE_INT | CTLFLAG_RW, 44361ae650dSJack F Vogel pf, 0, ixl_set_flowcntl, "I", "Flow Control"); 44461ae650dSJack F Vogel 44561ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 44661ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 44761ae650dSJack F Vogel OID_AUTO, "advertise_speed", CTLTYPE_INT | CTLFLAG_RW, 44861ae650dSJack F Vogel pf, 0, ixl_set_advertise, "I", "Advertised Speed"); 44961ae650dSJack F Vogel 45061ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 45161ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 45261ae650dSJack F Vogel OID_AUTO, "current_speed", CTLTYPE_STRING | CTLFLAG_RD, 45361ae650dSJack F Vogel pf, 0, ixl_current_speed, "A", "Current Port Speed"); 45461ae650dSJack F Vogel 455e5100ee2SJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 456e5100ee2SJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 457e5100ee2SJack F Vogel OID_AUTO, "fw_version", CTLTYPE_STRING | CTLFLAG_RD, 458e5100ee2SJack F Vogel pf, 0, ixl_sysctl_show_fw, "A", "Firmware version"); 459e5100ee2SJack F Vogel 46061ae650dSJack F Vogel SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), 46161ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 462f0188618SHans Petter Selasky OID_AUTO, "rx_itr", CTLFLAG_RW, 46361ae650dSJack F Vogel &ixl_rx_itr, IXL_ITR_8K, "RX ITR"); 46461ae650dSJack F Vogel 46561ae650dSJack F Vogel SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), 46661ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 467f0188618SHans Petter Selasky OID_AUTO, "dynamic_rx_itr", CTLFLAG_RW, 46861ae650dSJack F Vogel &ixl_dynamic_rx_itr, 0, "Dynamic RX ITR"); 46961ae650dSJack F Vogel 47061ae650dSJack F Vogel SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), 47161ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 472f0188618SHans Petter Selasky OID_AUTO, "tx_itr", CTLFLAG_RW, 47361ae650dSJack F Vogel &ixl_tx_itr, IXL_ITR_4K, "TX ITR"); 47461ae650dSJack F Vogel 47561ae650dSJack F Vogel SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), 47661ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 477f0188618SHans Petter Selasky OID_AUTO, "dynamic_tx_itr", CTLFLAG_RW, 47861ae650dSJack F Vogel &ixl_dynamic_tx_itr, 0, "Dynamic TX ITR"); 47961ae650dSJack F Vogel 480393c4bb1SJack F Vogel #ifdef IXL_DEBUG_SYSCTL 48161ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 48261ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 48361ae650dSJack F Vogel OID_AUTO, "link_status", CTLTYPE_STRING | CTLFLAG_RD, 48461ae650dSJack F Vogel pf, 0, ixl_sysctl_link_status, "A", "Current Link Status"); 48561ae650dSJack F Vogel 48661ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 48761ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 48861ae650dSJack F Vogel OID_AUTO, "phy_abilities", CTLTYPE_STRING | CTLFLAG_RD, 48961ae650dSJack F Vogel pf, 0, ixl_sysctl_phy_abilities, "A", "PHY Abilities"); 49061ae650dSJack F Vogel 49161ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 49261ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 49361ae650dSJack F Vogel OID_AUTO, "filter_list", CTLTYPE_STRING | CTLFLAG_RD, 49461ae650dSJack F Vogel pf, 0, ixl_sysctl_sw_filter_list, "A", "SW Filter List"); 49561ae650dSJack F Vogel 49661ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 49761ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 498e5100ee2SJack F Vogel OID_AUTO, "hw_res_alloc", CTLTYPE_STRING | CTLFLAG_RD, 499e5100ee2SJack F Vogel pf, 0, ixl_sysctl_hw_res_alloc, "A", "HW Resource Allocation"); 500e5100ee2SJack F Vogel 501e5100ee2SJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 502e5100ee2SJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 503e5100ee2SJack F Vogel OID_AUTO, "switch_config", CTLTYPE_STRING | CTLFLAG_RD, 504e5100ee2SJack F Vogel pf, 0, ixl_sysctl_switch_config, "A", "HW Switch Configuration"); 50561ae650dSJack F Vogel #endif 50661ae650dSJack F Vogel 507e5100ee2SJack F Vogel /* Save off the PCI information */ 50861ae650dSJack F Vogel hw->vendor_id = pci_get_vendor(dev); 50961ae650dSJack F Vogel hw->device_id = pci_get_device(dev); 51061ae650dSJack F Vogel hw->revision_id = pci_read_config(dev, PCIR_REVID, 1); 51161ae650dSJack F Vogel hw->subsystem_vendor_id = 51261ae650dSJack F Vogel pci_read_config(dev, PCIR_SUBVEND_0, 2); 51361ae650dSJack F Vogel hw->subsystem_device_id = 51461ae650dSJack F Vogel pci_read_config(dev, PCIR_SUBDEV_0, 2); 51561ae650dSJack F Vogel 51661ae650dSJack F Vogel hw->bus.device = pci_get_slot(dev); 51761ae650dSJack F Vogel hw->bus.func = pci_get_function(dev); 51861ae650dSJack F Vogel 51956c2c47bSJack F Vogel pf->vc_debug_lvl = 1; 52056c2c47bSJack F Vogel 52161ae650dSJack F Vogel /* Do PCI setup - map BAR0, etc */ 52261ae650dSJack F Vogel if (ixl_allocate_pci_resources(pf)) { 52361ae650dSJack F Vogel device_printf(dev, "Allocation of PCI resources failed\n"); 52461ae650dSJack F Vogel error = ENXIO; 52561ae650dSJack F Vogel goto err_out; 52661ae650dSJack F Vogel } 52761ae650dSJack F Vogel 52861ae650dSJack F Vogel /* Create for initial debugging use */ 52961ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 53061ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 53161ae650dSJack F Vogel OID_AUTO, "debug", CTLTYPE_INT|CTLFLAG_RW, pf, 0, 53261ae650dSJack F Vogel ixl_debug_info, "I", "Debug Information"); 53361ae650dSJack F Vogel 53461ae650dSJack F Vogel 53561ae650dSJack F Vogel /* Establish a clean starting point */ 53661ae650dSJack F Vogel i40e_clear_hw(hw); 53761ae650dSJack F Vogel error = i40e_pf_reset(hw); 53861ae650dSJack F Vogel if (error) { 53961ae650dSJack F Vogel device_printf(dev,"PF reset failure %x\n", error); 54061ae650dSJack F Vogel error = EIO; 54161ae650dSJack F Vogel goto err_out; 54261ae650dSJack F Vogel } 54361ae650dSJack F Vogel 54461ae650dSJack F Vogel /* Set admin queue parameters */ 54561ae650dSJack F Vogel hw->aq.num_arq_entries = IXL_AQ_LEN; 54661ae650dSJack F Vogel hw->aq.num_asq_entries = IXL_AQ_LEN; 54761ae650dSJack F Vogel hw->aq.arq_buf_size = IXL_AQ_BUFSZ; 54861ae650dSJack F Vogel hw->aq.asq_buf_size = IXL_AQ_BUFSZ; 54961ae650dSJack F Vogel 55061ae650dSJack F Vogel /* Initialize the shared code */ 55161ae650dSJack F Vogel error = i40e_init_shared_code(hw); 55261ae650dSJack F Vogel if (error) { 55361ae650dSJack F Vogel device_printf(dev,"Unable to initialize the shared code\n"); 55461ae650dSJack F Vogel error = EIO; 55561ae650dSJack F Vogel goto err_out; 55661ae650dSJack F Vogel } 55761ae650dSJack F Vogel 55861ae650dSJack F Vogel /* Set up the admin queue */ 55961ae650dSJack F Vogel error = i40e_init_adminq(hw); 56061ae650dSJack F Vogel if (error) { 56161ae650dSJack F Vogel device_printf(dev, "The driver for the device stopped " 56261ae650dSJack F Vogel "because the NVM image is newer than expected.\n" 56361ae650dSJack F Vogel "You must install the most recent version of " 56461ae650dSJack F Vogel " the network driver.\n"); 56561ae650dSJack F Vogel goto err_out; 56661ae650dSJack F Vogel } 56761ae650dSJack F Vogel device_printf(dev, "%s\n", ixl_fw_version_str(hw)); 56861ae650dSJack F Vogel 56961ae650dSJack F Vogel if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && 57061ae650dSJack F Vogel hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) 57161ae650dSJack F Vogel device_printf(dev, "The driver for the device detected " 57261ae650dSJack F Vogel "a newer version of the NVM image than expected.\n" 57361ae650dSJack F Vogel "Please install the most recent version of the network driver.\n"); 57461ae650dSJack F Vogel else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || 57561ae650dSJack F Vogel hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) 57661ae650dSJack F Vogel device_printf(dev, "The driver for the device detected " 57761ae650dSJack F Vogel "an older version of the NVM image than expected.\n" 57861ae650dSJack F Vogel "Please update the NVM image.\n"); 57961ae650dSJack F Vogel 58061ae650dSJack F Vogel /* Clear PXE mode */ 58161ae650dSJack F Vogel i40e_clear_pxe_mode(hw); 58261ae650dSJack F Vogel 58361ae650dSJack F Vogel /* Get capabilities from the device */ 58461ae650dSJack F Vogel error = ixl_get_hw_capabilities(pf); 58561ae650dSJack F Vogel if (error) { 58661ae650dSJack F Vogel device_printf(dev, "HW capabilities failure!\n"); 58761ae650dSJack F Vogel goto err_get_cap; 58861ae650dSJack F Vogel } 58961ae650dSJack F Vogel 59061ae650dSJack F Vogel /* Set up host memory cache */ 59156c2c47bSJack F Vogel error = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, 59256c2c47bSJack F Vogel hw->func_caps.num_rx_qp, 0, 0); 59361ae650dSJack F Vogel if (error) { 59461ae650dSJack F Vogel device_printf(dev, "init_lan_hmc failed: %d\n", error); 59561ae650dSJack F Vogel goto err_get_cap; 59661ae650dSJack F Vogel } 59761ae650dSJack F Vogel 59861ae650dSJack F Vogel error = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); 59961ae650dSJack F Vogel if (error) { 60061ae650dSJack F Vogel device_printf(dev, "configure_lan_hmc failed: %d\n", error); 60161ae650dSJack F Vogel goto err_mac_hmc; 60261ae650dSJack F Vogel } 60361ae650dSJack F Vogel 60461ae650dSJack F Vogel /* Disable LLDP from the firmware */ 60561ae650dSJack F Vogel i40e_aq_stop_lldp(hw, TRUE, NULL); 60661ae650dSJack F Vogel 60761ae650dSJack F Vogel i40e_get_mac_addr(hw, hw->mac.addr); 60861ae650dSJack F Vogel error = i40e_validate_mac_addr(hw->mac.addr); 60961ae650dSJack F Vogel if (error) { 61061ae650dSJack F Vogel device_printf(dev, "validate_mac_addr failed: %d\n", error); 61161ae650dSJack F Vogel goto err_mac_hmc; 61261ae650dSJack F Vogel } 61361ae650dSJack F Vogel bcopy(hw->mac.addr, hw->mac.perm_addr, ETHER_ADDR_LEN); 61461ae650dSJack F Vogel i40e_get_port_mac_addr(hw, hw->mac.port_addr); 61561ae650dSJack F Vogel 616e5100ee2SJack F Vogel /* Set up VSI and queues */ 61761ae650dSJack F Vogel if (ixl_setup_stations(pf) != 0) { 61861ae650dSJack F Vogel device_printf(dev, "setup stations failed!\n"); 61961ae650dSJack F Vogel error = ENOMEM; 62061ae650dSJack F Vogel goto err_mac_hmc; 62161ae650dSJack F Vogel } 62261ae650dSJack F Vogel 62361ae650dSJack F Vogel /* Initialize mac filter list for VSI */ 62461ae650dSJack F Vogel SLIST_INIT(&vsi->ftl); 62561ae650dSJack F Vogel 62661ae650dSJack F Vogel /* Set up interrupt routing here */ 62761ae650dSJack F Vogel if (pf->msix > 1) 62861ae650dSJack F Vogel error = ixl_assign_vsi_msix(pf); 62961ae650dSJack F Vogel else 63061ae650dSJack F Vogel error = ixl_assign_vsi_legacy(pf); 63161ae650dSJack F Vogel if (error) 63261ae650dSJack F Vogel goto err_late; 63361ae650dSJack F Vogel 634b6c8f260SJack F Vogel if (((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver < 33)) || 635b6c8f260SJack F Vogel (hw->aq.fw_maj_ver < 4)) { 63661ae650dSJack F Vogel i40e_msec_delay(75); 63761ae650dSJack F Vogel error = i40e_aq_set_link_restart_an(hw, TRUE, NULL); 638b6c8f260SJack F Vogel if (error) 63961ae650dSJack F Vogel device_printf(dev, "link restart failed, aq_err=%d\n", 64061ae650dSJack F Vogel pf->hw.aq.asq_last_status); 64161ae650dSJack F Vogel } 64261ae650dSJack F Vogel 64361ae650dSJack F Vogel /* Determine link state */ 64456c2c47bSJack F Vogel i40e_aq_get_link_info(hw, TRUE, NULL, NULL); 64556c2c47bSJack F Vogel pf->link_up = i40e_get_link_status(hw); 64661ae650dSJack F Vogel 64761ae650dSJack F Vogel /* Setup OS specific network interface */ 648e5100ee2SJack F Vogel if (ixl_setup_interface(dev, vsi) != 0) { 649e5100ee2SJack F Vogel device_printf(dev, "interface setup failed!\n"); 650e5100ee2SJack F Vogel error = EIO; 65161ae650dSJack F Vogel goto err_late; 652e5100ee2SJack F Vogel } 65361ae650dSJack F Vogel 654b6c8f260SJack F Vogel error = ixl_switch_config(pf); 655b6c8f260SJack F Vogel if (error) { 656b6c8f260SJack F Vogel device_printf(dev, "Initial switch config failed: %d\n", error); 657b6c8f260SJack F Vogel goto err_mac_hmc; 658b6c8f260SJack F Vogel } 659b6c8f260SJack F Vogel 660b6c8f260SJack F Vogel /* Limit phy interrupts to link and modules failure */ 661b6c8f260SJack F Vogel error = i40e_aq_set_phy_int_mask(hw, 662b6c8f260SJack F Vogel I40E_AQ_EVENT_LINK_UPDOWN | I40E_AQ_EVENT_MODULE_QUAL_FAIL, NULL); 663b6c8f260SJack F Vogel if (error) 664b6c8f260SJack F Vogel device_printf(dev, "set phy mask failed: %d\n", error); 665b6c8f260SJack F Vogel 66661ae650dSJack F Vogel /* Get the bus configuration and set the shared code */ 66761ae650dSJack F Vogel bus = ixl_get_bus_info(hw, dev); 66861ae650dSJack F Vogel i40e_set_pci_config_data(hw, bus); 66961ae650dSJack F Vogel 67061ae650dSJack F Vogel /* Initialize statistics */ 67161ae650dSJack F Vogel ixl_pf_reset_stats(pf); 67261ae650dSJack F Vogel ixl_update_stats_counters(pf); 67361ae650dSJack F Vogel ixl_add_hw_stats(pf); 67461ae650dSJack F Vogel 67561ae650dSJack F Vogel /* Register for VLAN events */ 67661ae650dSJack F Vogel vsi->vlan_attach = EVENTHANDLER_REGISTER(vlan_config, 67761ae650dSJack F Vogel ixl_register_vlan, vsi, EVENTHANDLER_PRI_FIRST); 67861ae650dSJack F Vogel vsi->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig, 67961ae650dSJack F Vogel ixl_unregister_vlan, vsi, EVENTHANDLER_PRI_FIRST); 68061ae650dSJack F Vogel 68156c2c47bSJack F Vogel #ifdef PCI_IOV 68256c2c47bSJack F Vogel /* SR-IOV is only supported when MSI-X is in use. */ 68356c2c47bSJack F Vogel if (pf->msix > 1) { 68456c2c47bSJack F Vogel pf_schema = pci_iov_schema_alloc_node(); 68556c2c47bSJack F Vogel vf_schema = pci_iov_schema_alloc_node(); 68656c2c47bSJack F Vogel pci_iov_schema_add_unicast_mac(vf_schema, "mac-addr", 0, NULL); 68756c2c47bSJack F Vogel pci_iov_schema_add_bool(vf_schema, "mac-anti-spoof", 68856c2c47bSJack F Vogel IOV_SCHEMA_HASDEFAULT, TRUE); 68956c2c47bSJack F Vogel pci_iov_schema_add_bool(vf_schema, "allow-set-mac", 69056c2c47bSJack F Vogel IOV_SCHEMA_HASDEFAULT, FALSE); 69156c2c47bSJack F Vogel pci_iov_schema_add_bool(vf_schema, "allow-promisc", 69256c2c47bSJack F Vogel IOV_SCHEMA_HASDEFAULT, FALSE); 693e5100ee2SJack F Vogel 69456c2c47bSJack F Vogel iov_error = pci_iov_attach(dev, pf_schema, vf_schema); 69556c2c47bSJack F Vogel if (iov_error != 0) 69656c2c47bSJack F Vogel device_printf(dev, 69756c2c47bSJack F Vogel "Failed to initialize SR-IOV (error=%d)\n", 69856c2c47bSJack F Vogel iov_error); 69956c2c47bSJack F Vogel } 70056c2c47bSJack F Vogel #endif 70156c2c47bSJack F Vogel 702*31830672SJack F Vogel #ifdef DEV_NETMAP 703*31830672SJack F Vogel ixl_netmap_attach(vsi); 704*31830672SJack F Vogel #endif /* DEV_NETMAP */ 705*31830672SJack F Vogel 70661ae650dSJack F Vogel INIT_DEBUGOUT("ixl_attach: end"); 70761ae650dSJack F Vogel return (0); 70861ae650dSJack F Vogel 70961ae650dSJack F Vogel err_late: 710e5100ee2SJack F Vogel if (vsi->ifp != NULL) 711e5100ee2SJack F Vogel if_free(vsi->ifp); 71261ae650dSJack F Vogel err_mac_hmc: 71361ae650dSJack F Vogel i40e_shutdown_lan_hmc(hw); 71461ae650dSJack F Vogel err_get_cap: 71561ae650dSJack F Vogel i40e_shutdown_adminq(hw); 71661ae650dSJack F Vogel err_out: 71761ae650dSJack F Vogel ixl_free_pci_resources(pf); 718e5100ee2SJack F Vogel ixl_free_vsi(vsi); 71961ae650dSJack F Vogel IXL_PF_LOCK_DESTROY(pf); 72061ae650dSJack F Vogel return (error); 72161ae650dSJack F Vogel } 72261ae650dSJack F Vogel 72361ae650dSJack F Vogel /********************************************************************* 72461ae650dSJack F Vogel * Device removal routine 72561ae650dSJack F Vogel * 72661ae650dSJack F Vogel * The detach entry point is called when the driver is being removed. 72761ae650dSJack F Vogel * This routine stops the adapter and deallocates all the resources 72861ae650dSJack F Vogel * that were allocated for driver operation. 72961ae650dSJack F Vogel * 73061ae650dSJack F Vogel * return 0 on success, positive on failure 73161ae650dSJack F Vogel *********************************************************************/ 73261ae650dSJack F Vogel 73361ae650dSJack F Vogel static int 73461ae650dSJack F Vogel ixl_detach(device_t dev) 73561ae650dSJack F Vogel { 73661ae650dSJack F Vogel struct ixl_pf *pf = device_get_softc(dev); 73761ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 73861ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 73961ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 74061ae650dSJack F Vogel i40e_status status; 74156c2c47bSJack F Vogel #ifdef PCI_IOV 74256c2c47bSJack F Vogel int error; 74356c2c47bSJack F Vogel #endif 74461ae650dSJack F Vogel 74561ae650dSJack F Vogel INIT_DEBUGOUT("ixl_detach: begin"); 74661ae650dSJack F Vogel 74761ae650dSJack F Vogel /* Make sure VLANS are not using driver */ 74861ae650dSJack F Vogel if (vsi->ifp->if_vlantrunk != NULL) { 74961ae650dSJack F Vogel device_printf(dev,"Vlan in use, detach first\n"); 75061ae650dSJack F Vogel return (EBUSY); 75161ae650dSJack F Vogel } 75261ae650dSJack F Vogel 75356c2c47bSJack F Vogel #ifdef PCI_IOV 75456c2c47bSJack F Vogel error = pci_iov_detach(dev); 75556c2c47bSJack F Vogel if (error != 0) { 75656c2c47bSJack F Vogel device_printf(dev, "SR-IOV in use; detach first.\n"); 75756c2c47bSJack F Vogel return (error); 75856c2c47bSJack F Vogel } 75956c2c47bSJack F Vogel #endif 76056c2c47bSJack F Vogel 761b6c8f260SJack F Vogel ether_ifdetach(vsi->ifp); 762b6c8f260SJack F Vogel if (vsi->ifp->if_drv_flags & IFF_DRV_RUNNING) { 76361ae650dSJack F Vogel IXL_PF_LOCK(pf); 76461ae650dSJack F Vogel ixl_stop(pf); 76561ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 766b6c8f260SJack F Vogel } 76761ae650dSJack F Vogel 76861ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, que++) { 76961ae650dSJack F Vogel if (que->tq) { 77061ae650dSJack F Vogel taskqueue_drain(que->tq, &que->task); 77161ae650dSJack F Vogel taskqueue_drain(que->tq, &que->tx_task); 77261ae650dSJack F Vogel taskqueue_free(que->tq); 77361ae650dSJack F Vogel } 77461ae650dSJack F Vogel } 77561ae650dSJack F Vogel 77661ae650dSJack F Vogel /* Shutdown LAN HMC */ 77761ae650dSJack F Vogel status = i40e_shutdown_lan_hmc(hw); 77861ae650dSJack F Vogel if (status) 77961ae650dSJack F Vogel device_printf(dev, 78061ae650dSJack F Vogel "Shutdown LAN HMC failed with code %d\n", status); 78161ae650dSJack F Vogel 78261ae650dSJack F Vogel /* Shutdown admin queue */ 78361ae650dSJack F Vogel status = i40e_shutdown_adminq(hw); 78461ae650dSJack F Vogel if (status) 78561ae650dSJack F Vogel device_printf(dev, 78661ae650dSJack F Vogel "Shutdown Admin queue failed with code %d\n", status); 78761ae650dSJack F Vogel 78861ae650dSJack F Vogel /* Unregister VLAN events */ 78961ae650dSJack F Vogel if (vsi->vlan_attach != NULL) 79061ae650dSJack F Vogel EVENTHANDLER_DEREGISTER(vlan_config, vsi->vlan_attach); 79161ae650dSJack F Vogel if (vsi->vlan_detach != NULL) 79261ae650dSJack F Vogel EVENTHANDLER_DEREGISTER(vlan_unconfig, vsi->vlan_detach); 79361ae650dSJack F Vogel 79461ae650dSJack F Vogel callout_drain(&pf->timer); 795*31830672SJack F Vogel #ifdef DEV_NETMAP 796*31830672SJack F Vogel netmap_detach(vsi->ifp); 797*31830672SJack F Vogel #endif /* DEV_NETMAP */ 79861ae650dSJack F Vogel ixl_free_pci_resources(pf); 79961ae650dSJack F Vogel bus_generic_detach(dev); 80061ae650dSJack F Vogel if_free(vsi->ifp); 80161ae650dSJack F Vogel ixl_free_vsi(vsi); 80261ae650dSJack F Vogel IXL_PF_LOCK_DESTROY(pf); 80361ae650dSJack F Vogel return (0); 80461ae650dSJack F Vogel } 80561ae650dSJack F Vogel 80661ae650dSJack F Vogel /********************************************************************* 80761ae650dSJack F Vogel * 80861ae650dSJack F Vogel * Shutdown entry point 80961ae650dSJack F Vogel * 81061ae650dSJack F Vogel **********************************************************************/ 81161ae650dSJack F Vogel 81261ae650dSJack F Vogel static int 81361ae650dSJack F Vogel ixl_shutdown(device_t dev) 81461ae650dSJack F Vogel { 81561ae650dSJack F Vogel struct ixl_pf *pf = device_get_softc(dev); 81661ae650dSJack F Vogel IXL_PF_LOCK(pf); 81761ae650dSJack F Vogel ixl_stop(pf); 81861ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 81961ae650dSJack F Vogel return (0); 82061ae650dSJack F Vogel } 82161ae650dSJack F Vogel 82261ae650dSJack F Vogel 82361ae650dSJack F Vogel /********************************************************************* 82461ae650dSJack F Vogel * 82561ae650dSJack F Vogel * Get the hardware capabilities 82661ae650dSJack F Vogel * 82761ae650dSJack F Vogel **********************************************************************/ 82861ae650dSJack F Vogel 82961ae650dSJack F Vogel static int 83061ae650dSJack F Vogel ixl_get_hw_capabilities(struct ixl_pf *pf) 83161ae650dSJack F Vogel { 83261ae650dSJack F Vogel struct i40e_aqc_list_capabilities_element_resp *buf; 83361ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 83461ae650dSJack F Vogel device_t dev = pf->dev; 83561ae650dSJack F Vogel int error, len; 83661ae650dSJack F Vogel u16 needed; 83761ae650dSJack F Vogel bool again = TRUE; 83861ae650dSJack F Vogel 83961ae650dSJack F Vogel len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); 84061ae650dSJack F Vogel retry: 84161ae650dSJack F Vogel if (!(buf = (struct i40e_aqc_list_capabilities_element_resp *) 84261ae650dSJack F Vogel malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO))) { 84361ae650dSJack F Vogel device_printf(dev, "Unable to allocate cap memory\n"); 84461ae650dSJack F Vogel return (ENOMEM); 84561ae650dSJack F Vogel } 84661ae650dSJack F Vogel 84761ae650dSJack F Vogel /* This populates the hw struct */ 84861ae650dSJack F Vogel error = i40e_aq_discover_capabilities(hw, buf, len, 84961ae650dSJack F Vogel &needed, i40e_aqc_opc_list_func_capabilities, NULL); 85061ae650dSJack F Vogel free(buf, M_DEVBUF); 85161ae650dSJack F Vogel if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) && 85261ae650dSJack F Vogel (again == TRUE)) { 85361ae650dSJack F Vogel /* retry once with a larger buffer */ 85461ae650dSJack F Vogel again = FALSE; 85561ae650dSJack F Vogel len = needed; 85661ae650dSJack F Vogel goto retry; 85761ae650dSJack F Vogel } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { 85861ae650dSJack F Vogel device_printf(dev, "capability discovery failed: %d\n", 85961ae650dSJack F Vogel pf->hw.aq.asq_last_status); 86061ae650dSJack F Vogel return (ENODEV); 86161ae650dSJack F Vogel } 86261ae650dSJack F Vogel 86361ae650dSJack F Vogel /* Capture this PF's starting queue pair */ 86461ae650dSJack F Vogel pf->qbase = hw->func_caps.base_queue; 86561ae650dSJack F Vogel 86661ae650dSJack F Vogel #ifdef IXL_DEBUG 86761ae650dSJack F Vogel device_printf(dev,"pf_id=%d, num_vfs=%d, msix_pf=%d, " 86861ae650dSJack F Vogel "msix_vf=%d, fd_g=%d, fd_b=%d, tx_qp=%d rx_qp=%d qbase=%d\n", 86961ae650dSJack F Vogel hw->pf_id, hw->func_caps.num_vfs, 87061ae650dSJack F Vogel hw->func_caps.num_msix_vectors, 87161ae650dSJack F Vogel hw->func_caps.num_msix_vectors_vf, 87261ae650dSJack F Vogel hw->func_caps.fd_filters_guaranteed, 87361ae650dSJack F Vogel hw->func_caps.fd_filters_best_effort, 87461ae650dSJack F Vogel hw->func_caps.num_tx_qp, 87561ae650dSJack F Vogel hw->func_caps.num_rx_qp, 87661ae650dSJack F Vogel hw->func_caps.base_queue); 87761ae650dSJack F Vogel #endif 87861ae650dSJack F Vogel return (error); 87961ae650dSJack F Vogel } 88061ae650dSJack F Vogel 88161ae650dSJack F Vogel static void 88261ae650dSJack F Vogel ixl_cap_txcsum_tso(struct ixl_vsi *vsi, struct ifnet *ifp, int mask) 88361ae650dSJack F Vogel { 88461ae650dSJack F Vogel device_t dev = vsi->dev; 88561ae650dSJack F Vogel 88661ae650dSJack F Vogel /* Enable/disable TXCSUM/TSO4 */ 88761ae650dSJack F Vogel if (!(ifp->if_capenable & IFCAP_TXCSUM) 88861ae650dSJack F Vogel && !(ifp->if_capenable & IFCAP_TSO4)) { 88961ae650dSJack F Vogel if (mask & IFCAP_TXCSUM) { 89061ae650dSJack F Vogel ifp->if_capenable |= IFCAP_TXCSUM; 89161ae650dSJack F Vogel /* enable TXCSUM, restore TSO if previously enabled */ 89261ae650dSJack F Vogel if (vsi->flags & IXL_FLAGS_KEEP_TSO4) { 89361ae650dSJack F Vogel vsi->flags &= ~IXL_FLAGS_KEEP_TSO4; 89461ae650dSJack F Vogel ifp->if_capenable |= IFCAP_TSO4; 89561ae650dSJack F Vogel } 89661ae650dSJack F Vogel } 89761ae650dSJack F Vogel else if (mask & IFCAP_TSO4) { 89861ae650dSJack F Vogel ifp->if_capenable |= (IFCAP_TXCSUM | IFCAP_TSO4); 89961ae650dSJack F Vogel vsi->flags &= ~IXL_FLAGS_KEEP_TSO4; 90061ae650dSJack F Vogel device_printf(dev, 90161ae650dSJack F Vogel "TSO4 requires txcsum, enabling both...\n"); 90261ae650dSJack F Vogel } 90361ae650dSJack F Vogel } else if((ifp->if_capenable & IFCAP_TXCSUM) 90461ae650dSJack F Vogel && !(ifp->if_capenable & IFCAP_TSO4)) { 90561ae650dSJack F Vogel if (mask & IFCAP_TXCSUM) 90661ae650dSJack F Vogel ifp->if_capenable &= ~IFCAP_TXCSUM; 90761ae650dSJack F Vogel else if (mask & IFCAP_TSO4) 90861ae650dSJack F Vogel ifp->if_capenable |= IFCAP_TSO4; 90961ae650dSJack F Vogel } else if((ifp->if_capenable & IFCAP_TXCSUM) 91061ae650dSJack F Vogel && (ifp->if_capenable & IFCAP_TSO4)) { 91161ae650dSJack F Vogel if (mask & IFCAP_TXCSUM) { 91261ae650dSJack F Vogel vsi->flags |= IXL_FLAGS_KEEP_TSO4; 91361ae650dSJack F Vogel ifp->if_capenable &= ~(IFCAP_TXCSUM | IFCAP_TSO4); 91461ae650dSJack F Vogel device_printf(dev, 91561ae650dSJack F Vogel "TSO4 requires txcsum, disabling both...\n"); 91661ae650dSJack F Vogel } else if (mask & IFCAP_TSO4) 91761ae650dSJack F Vogel ifp->if_capenable &= ~IFCAP_TSO4; 91861ae650dSJack F Vogel } 91961ae650dSJack F Vogel 92061ae650dSJack F Vogel /* Enable/disable TXCSUM_IPV6/TSO6 */ 92161ae650dSJack F Vogel if (!(ifp->if_capenable & IFCAP_TXCSUM_IPV6) 92261ae650dSJack F Vogel && !(ifp->if_capenable & IFCAP_TSO6)) { 92361ae650dSJack F Vogel if (mask & IFCAP_TXCSUM_IPV6) { 92461ae650dSJack F Vogel ifp->if_capenable |= IFCAP_TXCSUM_IPV6; 92561ae650dSJack F Vogel if (vsi->flags & IXL_FLAGS_KEEP_TSO6) { 92661ae650dSJack F Vogel vsi->flags &= ~IXL_FLAGS_KEEP_TSO6; 92761ae650dSJack F Vogel ifp->if_capenable |= IFCAP_TSO6; 92861ae650dSJack F Vogel } 92961ae650dSJack F Vogel } else if (mask & IFCAP_TSO6) { 93061ae650dSJack F Vogel ifp->if_capenable |= (IFCAP_TXCSUM_IPV6 | IFCAP_TSO6); 93161ae650dSJack F Vogel vsi->flags &= ~IXL_FLAGS_KEEP_TSO6; 93261ae650dSJack F Vogel device_printf(dev, 93361ae650dSJack F Vogel "TSO6 requires txcsum6, enabling both...\n"); 93461ae650dSJack F Vogel } 93561ae650dSJack F Vogel } else if((ifp->if_capenable & IFCAP_TXCSUM_IPV6) 93661ae650dSJack F Vogel && !(ifp->if_capenable & IFCAP_TSO6)) { 93761ae650dSJack F Vogel if (mask & IFCAP_TXCSUM_IPV6) 93861ae650dSJack F Vogel ifp->if_capenable &= ~IFCAP_TXCSUM_IPV6; 93961ae650dSJack F Vogel else if (mask & IFCAP_TSO6) 94061ae650dSJack F Vogel ifp->if_capenable |= IFCAP_TSO6; 94161ae650dSJack F Vogel } else if ((ifp->if_capenable & IFCAP_TXCSUM_IPV6) 94261ae650dSJack F Vogel && (ifp->if_capenable & IFCAP_TSO6)) { 94361ae650dSJack F Vogel if (mask & IFCAP_TXCSUM_IPV6) { 94461ae650dSJack F Vogel vsi->flags |= IXL_FLAGS_KEEP_TSO6; 94561ae650dSJack F Vogel ifp->if_capenable &= ~(IFCAP_TXCSUM_IPV6 | IFCAP_TSO6); 94661ae650dSJack F Vogel device_printf(dev, 94761ae650dSJack F Vogel "TSO6 requires txcsum6, disabling both...\n"); 94861ae650dSJack F Vogel } else if (mask & IFCAP_TSO6) 94961ae650dSJack F Vogel ifp->if_capenable &= ~IFCAP_TSO6; 95061ae650dSJack F Vogel } 95161ae650dSJack F Vogel } 95261ae650dSJack F Vogel 95361ae650dSJack F Vogel /********************************************************************* 95461ae650dSJack F Vogel * Ioctl entry point 95561ae650dSJack F Vogel * 95661ae650dSJack F Vogel * ixl_ioctl is called when the user wants to configure the 95761ae650dSJack F Vogel * interface. 95861ae650dSJack F Vogel * 95961ae650dSJack F Vogel * return 0 on success, positive on failure 96061ae650dSJack F Vogel **********************************************************************/ 96161ae650dSJack F Vogel 96261ae650dSJack F Vogel static int 96361ae650dSJack F Vogel ixl_ioctl(struct ifnet * ifp, u_long command, caddr_t data) 96461ae650dSJack F Vogel { 96561ae650dSJack F Vogel struct ixl_vsi *vsi = ifp->if_softc; 96656c2c47bSJack F Vogel struct ixl_pf *pf = vsi->back; 96761ae650dSJack F Vogel struct ifreq *ifr = (struct ifreq *) data; 96861ae650dSJack F Vogel #if defined(INET) || defined(INET6) 96961ae650dSJack F Vogel struct ifaddr *ifa = (struct ifaddr *)data; 97061ae650dSJack F Vogel bool avoid_reset = FALSE; 97161ae650dSJack F Vogel #endif 97261ae650dSJack F Vogel int error = 0; 97361ae650dSJack F Vogel 97461ae650dSJack F Vogel switch (command) { 97561ae650dSJack F Vogel 97661ae650dSJack F Vogel case SIOCSIFADDR: 97761ae650dSJack F Vogel #ifdef INET 97861ae650dSJack F Vogel if (ifa->ifa_addr->sa_family == AF_INET) 97961ae650dSJack F Vogel avoid_reset = TRUE; 98061ae650dSJack F Vogel #endif 98161ae650dSJack F Vogel #ifdef INET6 98261ae650dSJack F Vogel if (ifa->ifa_addr->sa_family == AF_INET6) 98361ae650dSJack F Vogel avoid_reset = TRUE; 98461ae650dSJack F Vogel #endif 98561ae650dSJack F Vogel #if defined(INET) || defined(INET6) 98661ae650dSJack F Vogel /* 98761ae650dSJack F Vogel ** Calling init results in link renegotiation, 98861ae650dSJack F Vogel ** so we avoid doing it when possible. 98961ae650dSJack F Vogel */ 99061ae650dSJack F Vogel if (avoid_reset) { 99161ae650dSJack F Vogel ifp->if_flags |= IFF_UP; 99261ae650dSJack F Vogel if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) 99361ae650dSJack F Vogel ixl_init(pf); 9947e0dde7dSBjoern A. Zeeb #ifdef INET 99561ae650dSJack F Vogel if (!(ifp->if_flags & IFF_NOARP)) 99661ae650dSJack F Vogel arp_ifinit(ifp, ifa); 9977e0dde7dSBjoern A. Zeeb #endif 99861ae650dSJack F Vogel } else 99961ae650dSJack F Vogel error = ether_ioctl(ifp, command, data); 100061ae650dSJack F Vogel break; 100161ae650dSJack F Vogel #endif 100261ae650dSJack F Vogel case SIOCSIFMTU: 100361ae650dSJack F Vogel IOCTL_DEBUGOUT("ioctl: SIOCSIFMTU (Set Interface MTU)"); 100461ae650dSJack F Vogel if (ifr->ifr_mtu > IXL_MAX_FRAME - 100561ae650dSJack F Vogel ETHER_HDR_LEN - ETHER_CRC_LEN - ETHER_VLAN_ENCAP_LEN) { 100661ae650dSJack F Vogel error = EINVAL; 100761ae650dSJack F Vogel } else { 100861ae650dSJack F Vogel IXL_PF_LOCK(pf); 100961ae650dSJack F Vogel ifp->if_mtu = ifr->ifr_mtu; 101061ae650dSJack F Vogel vsi->max_frame_size = 101161ae650dSJack F Vogel ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN 101261ae650dSJack F Vogel + ETHER_VLAN_ENCAP_LEN; 101361ae650dSJack F Vogel ixl_init_locked(pf); 101461ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 101561ae650dSJack F Vogel } 101661ae650dSJack F Vogel break; 101761ae650dSJack F Vogel case SIOCSIFFLAGS: 101861ae650dSJack F Vogel IOCTL_DEBUGOUT("ioctl: SIOCSIFFLAGS (Set Interface Flags)"); 101961ae650dSJack F Vogel IXL_PF_LOCK(pf); 102061ae650dSJack F Vogel if (ifp->if_flags & IFF_UP) { 102161ae650dSJack F Vogel if ((ifp->if_drv_flags & IFF_DRV_RUNNING)) { 102261ae650dSJack F Vogel if ((ifp->if_flags ^ pf->if_flags) & 102361ae650dSJack F Vogel (IFF_PROMISC | IFF_ALLMULTI)) { 102461ae650dSJack F Vogel ixl_set_promisc(vsi); 102561ae650dSJack F Vogel } 102661ae650dSJack F Vogel } else 102761ae650dSJack F Vogel ixl_init_locked(pf); 102861ae650dSJack F Vogel } else 102961ae650dSJack F Vogel if (ifp->if_drv_flags & IFF_DRV_RUNNING) 103061ae650dSJack F Vogel ixl_stop(pf); 103161ae650dSJack F Vogel pf->if_flags = ifp->if_flags; 103261ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 103361ae650dSJack F Vogel break; 103461ae650dSJack F Vogel case SIOCADDMULTI: 103561ae650dSJack F Vogel IOCTL_DEBUGOUT("ioctl: SIOCADDMULTI"); 103661ae650dSJack F Vogel if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 103761ae650dSJack F Vogel IXL_PF_LOCK(pf); 103861ae650dSJack F Vogel ixl_disable_intr(vsi); 103961ae650dSJack F Vogel ixl_add_multi(vsi); 104061ae650dSJack F Vogel ixl_enable_intr(vsi); 104161ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 104261ae650dSJack F Vogel } 104361ae650dSJack F Vogel break; 104461ae650dSJack F Vogel case SIOCDELMULTI: 104561ae650dSJack F Vogel IOCTL_DEBUGOUT("ioctl: SIOCDELMULTI"); 104661ae650dSJack F Vogel if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 104761ae650dSJack F Vogel IXL_PF_LOCK(pf); 104861ae650dSJack F Vogel ixl_disable_intr(vsi); 104961ae650dSJack F Vogel ixl_del_multi(vsi); 105061ae650dSJack F Vogel ixl_enable_intr(vsi); 105161ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 105261ae650dSJack F Vogel } 105361ae650dSJack F Vogel break; 105461ae650dSJack F Vogel case SIOCSIFMEDIA: 105561ae650dSJack F Vogel case SIOCGIFMEDIA: 105661ae650dSJack F Vogel IOCTL_DEBUGOUT("ioctl: SIOCxIFMEDIA (Get/Set Interface Media)"); 105761ae650dSJack F Vogel error = ifmedia_ioctl(ifp, ifr, &vsi->media, command); 105861ae650dSJack F Vogel break; 105961ae650dSJack F Vogel case SIOCSIFCAP: 106061ae650dSJack F Vogel { 106161ae650dSJack F Vogel int mask = ifr->ifr_reqcap ^ ifp->if_capenable; 106261ae650dSJack F Vogel IOCTL_DEBUGOUT("ioctl: SIOCSIFCAP (Set Capabilities)"); 106361ae650dSJack F Vogel 106461ae650dSJack F Vogel ixl_cap_txcsum_tso(vsi, ifp, mask); 106561ae650dSJack F Vogel 106661ae650dSJack F Vogel if (mask & IFCAP_RXCSUM) 106761ae650dSJack F Vogel ifp->if_capenable ^= IFCAP_RXCSUM; 106861ae650dSJack F Vogel if (mask & IFCAP_RXCSUM_IPV6) 106961ae650dSJack F Vogel ifp->if_capenable ^= IFCAP_RXCSUM_IPV6; 107061ae650dSJack F Vogel if (mask & IFCAP_LRO) 107161ae650dSJack F Vogel ifp->if_capenable ^= IFCAP_LRO; 107261ae650dSJack F Vogel if (mask & IFCAP_VLAN_HWTAGGING) 107361ae650dSJack F Vogel ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING; 107461ae650dSJack F Vogel if (mask & IFCAP_VLAN_HWFILTER) 107561ae650dSJack F Vogel ifp->if_capenable ^= IFCAP_VLAN_HWFILTER; 107661ae650dSJack F Vogel if (mask & IFCAP_VLAN_HWTSO) 107761ae650dSJack F Vogel ifp->if_capenable ^= IFCAP_VLAN_HWTSO; 107861ae650dSJack F Vogel if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 107961ae650dSJack F Vogel IXL_PF_LOCK(pf); 108061ae650dSJack F Vogel ixl_init_locked(pf); 108161ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 108261ae650dSJack F Vogel } 108361ae650dSJack F Vogel VLAN_CAPABILITIES(ifp); 108461ae650dSJack F Vogel 108561ae650dSJack F Vogel break; 108661ae650dSJack F Vogel } 108761ae650dSJack F Vogel 108861ae650dSJack F Vogel default: 108961ae650dSJack F Vogel IOCTL_DEBUGOUT("ioctl: UNKNOWN (0x%X)\n", (int)command); 109061ae650dSJack F Vogel error = ether_ioctl(ifp, command, data); 109161ae650dSJack F Vogel break; 109261ae650dSJack F Vogel } 109361ae650dSJack F Vogel 109461ae650dSJack F Vogel return (error); 109561ae650dSJack F Vogel } 109661ae650dSJack F Vogel 109761ae650dSJack F Vogel 109861ae650dSJack F Vogel /********************************************************************* 109961ae650dSJack F Vogel * Init entry point 110061ae650dSJack F Vogel * 110161ae650dSJack F Vogel * This routine is used in two ways. It is used by the stack as 110261ae650dSJack F Vogel * init entry point in network interface structure. It is also used 110361ae650dSJack F Vogel * by the driver as a hw/sw initialization routine to get to a 110461ae650dSJack F Vogel * consistent state. 110561ae650dSJack F Vogel * 110661ae650dSJack F Vogel * return 0 on success, positive on failure 110761ae650dSJack F Vogel **********************************************************************/ 110861ae650dSJack F Vogel 110961ae650dSJack F Vogel static void 111061ae650dSJack F Vogel ixl_init_locked(struct ixl_pf *pf) 111161ae650dSJack F Vogel { 111261ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 111361ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 111461ae650dSJack F Vogel struct ifnet *ifp = vsi->ifp; 111561ae650dSJack F Vogel device_t dev = pf->dev; 111661ae650dSJack F Vogel struct i40e_filter_control_settings filter; 111761ae650dSJack F Vogel u8 tmpaddr[ETHER_ADDR_LEN]; 111861ae650dSJack F Vogel int ret; 111961ae650dSJack F Vogel 112061ae650dSJack F Vogel mtx_assert(&pf->pf_mtx, MA_OWNED); 112161ae650dSJack F Vogel INIT_DEBUGOUT("ixl_init: begin"); 112261ae650dSJack F Vogel ixl_stop(pf); 112361ae650dSJack F Vogel 112461ae650dSJack F Vogel /* Get the latest mac address... User might use a LAA */ 112561ae650dSJack F Vogel bcopy(IF_LLADDR(vsi->ifp), tmpaddr, 112661ae650dSJack F Vogel I40E_ETH_LENGTH_OF_ADDRESS); 112761ae650dSJack F Vogel if (!cmp_etheraddr(hw->mac.addr, tmpaddr) && 112861ae650dSJack F Vogel i40e_validate_mac_addr(tmpaddr)) { 112961ae650dSJack F Vogel bcopy(tmpaddr, hw->mac.addr, 113061ae650dSJack F Vogel I40E_ETH_LENGTH_OF_ADDRESS); 113161ae650dSJack F Vogel ret = i40e_aq_mac_address_write(hw, 113261ae650dSJack F Vogel I40E_AQC_WRITE_TYPE_LAA_ONLY, 113361ae650dSJack F Vogel hw->mac.addr, NULL); 113461ae650dSJack F Vogel if (ret) { 113561ae650dSJack F Vogel device_printf(dev, "LLA address" 113661ae650dSJack F Vogel "change failed!!\n"); 113761ae650dSJack F Vogel return; 113861ae650dSJack F Vogel } 113961ae650dSJack F Vogel } 114061ae650dSJack F Vogel 114161ae650dSJack F Vogel /* Set the various hardware offload abilities */ 114261ae650dSJack F Vogel ifp->if_hwassist = 0; 114361ae650dSJack F Vogel if (ifp->if_capenable & IFCAP_TSO) 114461ae650dSJack F Vogel ifp->if_hwassist |= CSUM_TSO; 114561ae650dSJack F Vogel if (ifp->if_capenable & IFCAP_TXCSUM) 114661ae650dSJack F Vogel ifp->if_hwassist |= (CSUM_TCP | CSUM_UDP); 114761ae650dSJack F Vogel if (ifp->if_capenable & IFCAP_TXCSUM_IPV6) 114861ae650dSJack F Vogel ifp->if_hwassist |= (CSUM_TCP_IPV6 | CSUM_UDP_IPV6); 114961ae650dSJack F Vogel 115061ae650dSJack F Vogel /* Set up the device filtering */ 115161ae650dSJack F Vogel bzero(&filter, sizeof(filter)); 115261ae650dSJack F Vogel filter.enable_ethtype = TRUE; 115361ae650dSJack F Vogel filter.enable_macvlan = TRUE; 115461ae650dSJack F Vogel #ifdef IXL_FDIR 115561ae650dSJack F Vogel filter.enable_fdir = TRUE; 115661ae650dSJack F Vogel #endif 115761ae650dSJack F Vogel if (i40e_set_filter_control(hw, &filter)) 115861ae650dSJack F Vogel device_printf(dev, "set_filter_control() failed\n"); 115961ae650dSJack F Vogel 116061ae650dSJack F Vogel /* Set up RSS */ 116161ae650dSJack F Vogel ixl_config_rss(vsi); 116261ae650dSJack F Vogel 116361ae650dSJack F Vogel /* 1164b6c8f260SJack F Vogel ** Prepare the VSI: rings, hmc contexts, etc... 116561ae650dSJack F Vogel */ 116661ae650dSJack F Vogel if (ixl_initialize_vsi(vsi)) { 116761ae650dSJack F Vogel device_printf(dev, "initialize vsi failed!!\n"); 116861ae650dSJack F Vogel return; 116961ae650dSJack F Vogel } 117061ae650dSJack F Vogel 117161ae650dSJack F Vogel /* Add protocol filters to list */ 117261ae650dSJack F Vogel ixl_init_filters(vsi); 117361ae650dSJack F Vogel 117461ae650dSJack F Vogel /* Setup vlan's if needed */ 117561ae650dSJack F Vogel ixl_setup_vlan_filters(vsi); 117661ae650dSJack F Vogel 117761ae650dSJack F Vogel /* Start the local timer */ 117861ae650dSJack F Vogel callout_reset(&pf->timer, hz, ixl_local_timer, pf); 117961ae650dSJack F Vogel 118061ae650dSJack F Vogel /* Set up MSI/X routing and the ITR settings */ 118161ae650dSJack F Vogel if (ixl_enable_msix) { 118261ae650dSJack F Vogel ixl_configure_msix(pf); 118361ae650dSJack F Vogel ixl_configure_itr(pf); 118461ae650dSJack F Vogel } else 118561ae650dSJack F Vogel ixl_configure_legacy(pf); 118661ae650dSJack F Vogel 118761ae650dSJack F Vogel ixl_enable_rings(vsi); 118861ae650dSJack F Vogel 118961ae650dSJack F Vogel i40e_aq_set_default_vsi(hw, vsi->seid, NULL); 119061ae650dSJack F Vogel 119156c2c47bSJack F Vogel ixl_reconfigure_filters(vsi); 119256c2c47bSJack F Vogel 119361ae650dSJack F Vogel /* Set MTU in hardware*/ 119461ae650dSJack F Vogel int aq_error = i40e_aq_set_mac_config(hw, vsi->max_frame_size, 119561ae650dSJack F Vogel TRUE, 0, NULL); 119661ae650dSJack F Vogel if (aq_error) 119761ae650dSJack F Vogel device_printf(vsi->dev, 119861ae650dSJack F Vogel "aq_set_mac_config in init error, code %d\n", 119961ae650dSJack F Vogel aq_error); 120061ae650dSJack F Vogel 120161ae650dSJack F Vogel /* And now turn on interrupts */ 120261ae650dSJack F Vogel ixl_enable_intr(vsi); 120361ae650dSJack F Vogel 120461ae650dSJack F Vogel /* Now inform the stack we're ready */ 120561ae650dSJack F Vogel ifp->if_drv_flags |= IFF_DRV_RUNNING; 120661ae650dSJack F Vogel ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 120761ae650dSJack F Vogel 120861ae650dSJack F Vogel return; 120961ae650dSJack F Vogel } 121061ae650dSJack F Vogel 121161ae650dSJack F Vogel static void 121261ae650dSJack F Vogel ixl_init(void *arg) 121361ae650dSJack F Vogel { 121461ae650dSJack F Vogel struct ixl_pf *pf = arg; 121561ae650dSJack F Vogel 121661ae650dSJack F Vogel IXL_PF_LOCK(pf); 121761ae650dSJack F Vogel ixl_init_locked(pf); 121861ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 121961ae650dSJack F Vogel return; 122061ae650dSJack F Vogel } 122161ae650dSJack F Vogel 122261ae650dSJack F Vogel /* 122361ae650dSJack F Vogel ** 122461ae650dSJack F Vogel ** MSIX Interrupt Handlers and Tasklets 122561ae650dSJack F Vogel ** 122661ae650dSJack F Vogel */ 122761ae650dSJack F Vogel static void 122861ae650dSJack F Vogel ixl_handle_que(void *context, int pending) 122961ae650dSJack F Vogel { 123061ae650dSJack F Vogel struct ixl_queue *que = context; 123161ae650dSJack F Vogel struct ixl_vsi *vsi = que->vsi; 123261ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 123361ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 123461ae650dSJack F Vogel struct ifnet *ifp = vsi->ifp; 123561ae650dSJack F Vogel bool more; 123661ae650dSJack F Vogel 123761ae650dSJack F Vogel if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 123861ae650dSJack F Vogel more = ixl_rxeof(que, IXL_RX_LIMIT); 123961ae650dSJack F Vogel IXL_TX_LOCK(txr); 124061ae650dSJack F Vogel ixl_txeof(que); 124161ae650dSJack F Vogel if (!drbr_empty(ifp, txr->br)) 124261ae650dSJack F Vogel ixl_mq_start_locked(ifp, txr); 124361ae650dSJack F Vogel IXL_TX_UNLOCK(txr); 124461ae650dSJack F Vogel if (more) { 124561ae650dSJack F Vogel taskqueue_enqueue(que->tq, &que->task); 124661ae650dSJack F Vogel return; 124761ae650dSJack F Vogel } 124861ae650dSJack F Vogel } 124961ae650dSJack F Vogel 125061ae650dSJack F Vogel /* Reenable this interrupt - hmmm */ 125161ae650dSJack F Vogel ixl_enable_queue(hw, que->me); 125261ae650dSJack F Vogel return; 125361ae650dSJack F Vogel } 125461ae650dSJack F Vogel 125561ae650dSJack F Vogel 125661ae650dSJack F Vogel /********************************************************************* 125761ae650dSJack F Vogel * 125861ae650dSJack F Vogel * Legacy Interrupt Service routine 125961ae650dSJack F Vogel * 126061ae650dSJack F Vogel **********************************************************************/ 126161ae650dSJack F Vogel void 126261ae650dSJack F Vogel ixl_intr(void *arg) 126361ae650dSJack F Vogel { 126461ae650dSJack F Vogel struct ixl_pf *pf = arg; 126561ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 126661ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 126761ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 126861ae650dSJack F Vogel struct ifnet *ifp = vsi->ifp; 126961ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 127061ae650dSJack F Vogel u32 reg, icr0, mask; 127161ae650dSJack F Vogel bool more_tx, more_rx; 127261ae650dSJack F Vogel 127361ae650dSJack F Vogel ++que->irqs; 127461ae650dSJack F Vogel 127561ae650dSJack F Vogel /* Protect against spurious interrupts */ 127661ae650dSJack F Vogel if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) 127761ae650dSJack F Vogel return; 127861ae650dSJack F Vogel 127961ae650dSJack F Vogel icr0 = rd32(hw, I40E_PFINT_ICR0); 128061ae650dSJack F Vogel 128161ae650dSJack F Vogel reg = rd32(hw, I40E_PFINT_DYN_CTL0); 128261ae650dSJack F Vogel reg = reg | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK; 128361ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTL0, reg); 128461ae650dSJack F Vogel 128561ae650dSJack F Vogel mask = rd32(hw, I40E_PFINT_ICR0_ENA); 128661ae650dSJack F Vogel 128756c2c47bSJack F Vogel #ifdef PCI_IOV 128856c2c47bSJack F Vogel if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) 128956c2c47bSJack F Vogel taskqueue_enqueue(pf->tq, &pf->vflr_task); 129056c2c47bSJack F Vogel #endif 129156c2c47bSJack F Vogel 129261ae650dSJack F Vogel if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { 129361ae650dSJack F Vogel taskqueue_enqueue(pf->tq, &pf->adminq); 129461ae650dSJack F Vogel return; 129561ae650dSJack F Vogel } 129661ae650dSJack F Vogel 129761ae650dSJack F Vogel more_rx = ixl_rxeof(que, IXL_RX_LIMIT); 129861ae650dSJack F Vogel 129961ae650dSJack F Vogel IXL_TX_LOCK(txr); 130061ae650dSJack F Vogel more_tx = ixl_txeof(que); 130161ae650dSJack F Vogel if (!drbr_empty(vsi->ifp, txr->br)) 130261ae650dSJack F Vogel more_tx = 1; 130361ae650dSJack F Vogel IXL_TX_UNLOCK(txr); 130461ae650dSJack F Vogel 130561ae650dSJack F Vogel /* re-enable other interrupt causes */ 130661ae650dSJack F Vogel wr32(hw, I40E_PFINT_ICR0_ENA, mask); 130761ae650dSJack F Vogel 130861ae650dSJack F Vogel /* And now the queues */ 130961ae650dSJack F Vogel reg = rd32(hw, I40E_QINT_RQCTL(0)); 131061ae650dSJack F Vogel reg |= I40E_QINT_RQCTL_CAUSE_ENA_MASK; 131161ae650dSJack F Vogel wr32(hw, I40E_QINT_RQCTL(0), reg); 131261ae650dSJack F Vogel 131361ae650dSJack F Vogel reg = rd32(hw, I40E_QINT_TQCTL(0)); 131461ae650dSJack F Vogel reg |= I40E_QINT_TQCTL_CAUSE_ENA_MASK; 131561ae650dSJack F Vogel reg &= ~I40E_PFINT_ICR0_INTEVENT_MASK; 131661ae650dSJack F Vogel wr32(hw, I40E_QINT_TQCTL(0), reg); 131761ae650dSJack F Vogel 131861ae650dSJack F Vogel ixl_enable_legacy(hw); 131961ae650dSJack F Vogel 132061ae650dSJack F Vogel return; 132161ae650dSJack F Vogel } 132261ae650dSJack F Vogel 132361ae650dSJack F Vogel 132461ae650dSJack F Vogel /********************************************************************* 132561ae650dSJack F Vogel * 132661ae650dSJack F Vogel * MSIX VSI Interrupt Service routine 132761ae650dSJack F Vogel * 132861ae650dSJack F Vogel **********************************************************************/ 132961ae650dSJack F Vogel void 133061ae650dSJack F Vogel ixl_msix_que(void *arg) 133161ae650dSJack F Vogel { 133261ae650dSJack F Vogel struct ixl_queue *que = arg; 133361ae650dSJack F Vogel struct ixl_vsi *vsi = que->vsi; 133461ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 133561ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 133661ae650dSJack F Vogel bool more_tx, more_rx; 133761ae650dSJack F Vogel 133861ae650dSJack F Vogel /* Protect against spurious interrupts */ 133961ae650dSJack F Vogel if (!(vsi->ifp->if_drv_flags & IFF_DRV_RUNNING)) 134061ae650dSJack F Vogel return; 134161ae650dSJack F Vogel 134261ae650dSJack F Vogel ++que->irqs; 134361ae650dSJack F Vogel 134461ae650dSJack F Vogel more_rx = ixl_rxeof(que, IXL_RX_LIMIT); 134561ae650dSJack F Vogel 134661ae650dSJack F Vogel IXL_TX_LOCK(txr); 134761ae650dSJack F Vogel more_tx = ixl_txeof(que); 134861ae650dSJack F Vogel /* 134961ae650dSJack F Vogel ** Make certain that if the stack 135061ae650dSJack F Vogel ** has anything queued the task gets 135161ae650dSJack F Vogel ** scheduled to handle it. 135261ae650dSJack F Vogel */ 135361ae650dSJack F Vogel if (!drbr_empty(vsi->ifp, txr->br)) 135461ae650dSJack F Vogel more_tx = 1; 135561ae650dSJack F Vogel IXL_TX_UNLOCK(txr); 135661ae650dSJack F Vogel 135761ae650dSJack F Vogel ixl_set_queue_rx_itr(que); 135861ae650dSJack F Vogel ixl_set_queue_tx_itr(que); 135961ae650dSJack F Vogel 136061ae650dSJack F Vogel if (more_tx || more_rx) 136161ae650dSJack F Vogel taskqueue_enqueue(que->tq, &que->task); 136261ae650dSJack F Vogel else 136361ae650dSJack F Vogel ixl_enable_queue(hw, que->me); 136461ae650dSJack F Vogel 136561ae650dSJack F Vogel return; 136661ae650dSJack F Vogel } 136761ae650dSJack F Vogel 136861ae650dSJack F Vogel 136961ae650dSJack F Vogel /********************************************************************* 137061ae650dSJack F Vogel * 137161ae650dSJack F Vogel * MSIX Admin Queue Interrupt Service routine 137261ae650dSJack F Vogel * 137361ae650dSJack F Vogel **********************************************************************/ 137461ae650dSJack F Vogel static void 137561ae650dSJack F Vogel ixl_msix_adminq(void *arg) 137661ae650dSJack F Vogel { 137761ae650dSJack F Vogel struct ixl_pf *pf = arg; 137861ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 137961ae650dSJack F Vogel u32 reg, mask; 138061ae650dSJack F Vogel 138161ae650dSJack F Vogel ++pf->admin_irq; 138261ae650dSJack F Vogel 138361ae650dSJack F Vogel reg = rd32(hw, I40E_PFINT_ICR0); 138461ae650dSJack F Vogel mask = rd32(hw, I40E_PFINT_ICR0_ENA); 138561ae650dSJack F Vogel 138661ae650dSJack F Vogel /* Check on the cause */ 138761ae650dSJack F Vogel if (reg & I40E_PFINT_ICR0_ADMINQ_MASK) 138861ae650dSJack F Vogel mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; 138961ae650dSJack F Vogel 139061ae650dSJack F Vogel if (reg & I40E_PFINT_ICR0_MAL_DETECT_MASK) { 139161ae650dSJack F Vogel ixl_handle_mdd_event(pf); 139261ae650dSJack F Vogel mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; 139361ae650dSJack F Vogel } 139461ae650dSJack F Vogel 139556c2c47bSJack F Vogel #ifdef PCI_IOV 139656c2c47bSJack F Vogel if (reg & I40E_PFINT_ICR0_VFLR_MASK) { 139761ae650dSJack F Vogel mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; 139856c2c47bSJack F Vogel taskqueue_enqueue(pf->tq, &pf->vflr_task); 139956c2c47bSJack F Vogel } 140056c2c47bSJack F Vogel #endif 140161ae650dSJack F Vogel 140261ae650dSJack F Vogel reg = rd32(hw, I40E_PFINT_DYN_CTL0); 140361ae650dSJack F Vogel reg = reg | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK; 140461ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTL0, reg); 140561ae650dSJack F Vogel 140661ae650dSJack F Vogel taskqueue_enqueue(pf->tq, &pf->adminq); 140761ae650dSJack F Vogel return; 140861ae650dSJack F Vogel } 140961ae650dSJack F Vogel 141061ae650dSJack F Vogel /********************************************************************* 141161ae650dSJack F Vogel * 141261ae650dSJack F Vogel * Media Ioctl callback 141361ae650dSJack F Vogel * 141461ae650dSJack F Vogel * This routine is called whenever the user queries the status of 141561ae650dSJack F Vogel * the interface using ifconfig. 141661ae650dSJack F Vogel * 141761ae650dSJack F Vogel **********************************************************************/ 141861ae650dSJack F Vogel static void 141961ae650dSJack F Vogel ixl_media_status(struct ifnet * ifp, struct ifmediareq * ifmr) 142061ae650dSJack F Vogel { 142161ae650dSJack F Vogel struct ixl_vsi *vsi = ifp->if_softc; 142256c2c47bSJack F Vogel struct ixl_pf *pf = vsi->back; 142361ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 142461ae650dSJack F Vogel 142561ae650dSJack F Vogel INIT_DEBUGOUT("ixl_media_status: begin"); 142661ae650dSJack F Vogel IXL_PF_LOCK(pf); 142761ae650dSJack F Vogel 142856c2c47bSJack F Vogel hw->phy.get_link_info = TRUE; 142956c2c47bSJack F Vogel pf->link_up = i40e_get_link_status(hw); 143061ae650dSJack F Vogel ixl_update_link_status(pf); 143161ae650dSJack F Vogel 143261ae650dSJack F Vogel ifmr->ifm_status = IFM_AVALID; 143361ae650dSJack F Vogel ifmr->ifm_active = IFM_ETHER; 143461ae650dSJack F Vogel 143556c2c47bSJack F Vogel if (!pf->link_up) { 143661ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 143761ae650dSJack F Vogel return; 143861ae650dSJack F Vogel } 143961ae650dSJack F Vogel 144061ae650dSJack F Vogel ifmr->ifm_status |= IFM_ACTIVE; 144161ae650dSJack F Vogel /* Hardware is always full-duplex */ 144261ae650dSJack F Vogel ifmr->ifm_active |= IFM_FDX; 144361ae650dSJack F Vogel 144461ae650dSJack F Vogel switch (hw->phy.link_info.phy_type) { 144561ae650dSJack F Vogel /* 100 M */ 144661ae650dSJack F Vogel case I40E_PHY_TYPE_100BASE_TX: 144761ae650dSJack F Vogel ifmr->ifm_active |= IFM_100_TX; 144861ae650dSJack F Vogel break; 144961ae650dSJack F Vogel /* 1 G */ 145061ae650dSJack F Vogel case I40E_PHY_TYPE_1000BASE_T: 145161ae650dSJack F Vogel ifmr->ifm_active |= IFM_1000_T; 145261ae650dSJack F Vogel break; 145361ae650dSJack F Vogel case I40E_PHY_TYPE_1000BASE_SX: 145461ae650dSJack F Vogel ifmr->ifm_active |= IFM_1000_SX; 145561ae650dSJack F Vogel break; 145661ae650dSJack F Vogel case I40E_PHY_TYPE_1000BASE_LX: 145761ae650dSJack F Vogel ifmr->ifm_active |= IFM_1000_LX; 145861ae650dSJack F Vogel break; 145961ae650dSJack F Vogel /* 10 G */ 1460b6c8f260SJack F Vogel case I40E_PHY_TYPE_10GBASE_CR1: 146161ae650dSJack F Vogel case I40E_PHY_TYPE_10GBASE_CR1_CU: 146261ae650dSJack F Vogel case I40E_PHY_TYPE_10GBASE_SFPP_CU: 1463b6c8f260SJack F Vogel /* Using this until a real KR media type */ 1464b6c8f260SJack F Vogel case I40E_PHY_TYPE_10GBASE_KR: 1465b6c8f260SJack F Vogel case I40E_PHY_TYPE_10GBASE_KX4: 146661ae650dSJack F Vogel ifmr->ifm_active |= IFM_10G_TWINAX; 146761ae650dSJack F Vogel break; 146861ae650dSJack F Vogel case I40E_PHY_TYPE_10GBASE_SR: 146961ae650dSJack F Vogel ifmr->ifm_active |= IFM_10G_SR; 147061ae650dSJack F Vogel break; 147161ae650dSJack F Vogel case I40E_PHY_TYPE_10GBASE_LR: 147261ae650dSJack F Vogel ifmr->ifm_active |= IFM_10G_LR; 147361ae650dSJack F Vogel break; 147461ae650dSJack F Vogel case I40E_PHY_TYPE_10GBASE_T: 147561ae650dSJack F Vogel ifmr->ifm_active |= IFM_10G_T; 147661ae650dSJack F Vogel break; 147761ae650dSJack F Vogel /* 40 G */ 147861ae650dSJack F Vogel case I40E_PHY_TYPE_40GBASE_CR4: 147961ae650dSJack F Vogel case I40E_PHY_TYPE_40GBASE_CR4_CU: 148061ae650dSJack F Vogel ifmr->ifm_active |= IFM_40G_CR4; 148161ae650dSJack F Vogel break; 148261ae650dSJack F Vogel case I40E_PHY_TYPE_40GBASE_SR4: 148361ae650dSJack F Vogel ifmr->ifm_active |= IFM_40G_SR4; 148461ae650dSJack F Vogel break; 148561ae650dSJack F Vogel case I40E_PHY_TYPE_40GBASE_LR4: 148661ae650dSJack F Vogel ifmr->ifm_active |= IFM_40G_LR4; 148761ae650dSJack F Vogel break; 1488b6c8f260SJack F Vogel /* 1489b6c8f260SJack F Vogel ** Set these to CR4 because OS does not 1490b6c8f260SJack F Vogel ** have types available yet. 1491b6c8f260SJack F Vogel */ 1492b6c8f260SJack F Vogel case I40E_PHY_TYPE_40GBASE_KR4: 1493b6c8f260SJack F Vogel case I40E_PHY_TYPE_XLAUI: 1494b6c8f260SJack F Vogel case I40E_PHY_TYPE_XLPPI: 1495b6c8f260SJack F Vogel case I40E_PHY_TYPE_40GBASE_AOC: 1496b6c8f260SJack F Vogel ifmr->ifm_active |= IFM_40G_CR4; 1497b6c8f260SJack F Vogel break; 149861ae650dSJack F Vogel default: 149961ae650dSJack F Vogel ifmr->ifm_active |= IFM_UNKNOWN; 150061ae650dSJack F Vogel break; 150161ae650dSJack F Vogel } 150261ae650dSJack F Vogel /* Report flow control status as well */ 150361ae650dSJack F Vogel if (hw->phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) 150461ae650dSJack F Vogel ifmr->ifm_active |= IFM_ETH_TXPAUSE; 150561ae650dSJack F Vogel if (hw->phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX) 150661ae650dSJack F Vogel ifmr->ifm_active |= IFM_ETH_RXPAUSE; 150761ae650dSJack F Vogel 150861ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 150961ae650dSJack F Vogel 151061ae650dSJack F Vogel return; 151161ae650dSJack F Vogel } 151261ae650dSJack F Vogel 151361ae650dSJack F Vogel /********************************************************************* 151461ae650dSJack F Vogel * 151561ae650dSJack F Vogel * Media Ioctl callback 151661ae650dSJack F Vogel * 151761ae650dSJack F Vogel * This routine is called when the user changes speed/duplex using 151861ae650dSJack F Vogel * media/mediopt option with ifconfig. 151961ae650dSJack F Vogel * 152061ae650dSJack F Vogel **********************************************************************/ 152161ae650dSJack F Vogel static int 152261ae650dSJack F Vogel ixl_media_change(struct ifnet * ifp) 152361ae650dSJack F Vogel { 152461ae650dSJack F Vogel struct ixl_vsi *vsi = ifp->if_softc; 152561ae650dSJack F Vogel struct ifmedia *ifm = &vsi->media; 152661ae650dSJack F Vogel 152761ae650dSJack F Vogel INIT_DEBUGOUT("ixl_media_change: begin"); 152861ae650dSJack F Vogel 152961ae650dSJack F Vogel if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) 153061ae650dSJack F Vogel return (EINVAL); 153161ae650dSJack F Vogel 153261ae650dSJack F Vogel if_printf(ifp, "Media change is currently not supported.\n"); 153361ae650dSJack F Vogel 153461ae650dSJack F Vogel return (ENODEV); 153561ae650dSJack F Vogel } 153661ae650dSJack F Vogel 153761ae650dSJack F Vogel 153861ae650dSJack F Vogel #ifdef IXL_FDIR 153961ae650dSJack F Vogel /* 154061ae650dSJack F Vogel ** ATR: Application Targetted Receive - creates a filter 154161ae650dSJack F Vogel ** based on TX flow info that will keep the receive 154261ae650dSJack F Vogel ** portion of the flow on the same queue. Based on the 154361ae650dSJack F Vogel ** implementation this is only available for TCP connections 154461ae650dSJack F Vogel */ 154561ae650dSJack F Vogel void 154661ae650dSJack F Vogel ixl_atr(struct ixl_queue *que, struct tcphdr *th, int etype) 154761ae650dSJack F Vogel { 154861ae650dSJack F Vogel struct ixl_vsi *vsi = que->vsi; 154961ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 155061ae650dSJack F Vogel struct i40e_filter_program_desc *FDIR; 155161ae650dSJack F Vogel u32 ptype, dtype; 155261ae650dSJack F Vogel int idx; 155361ae650dSJack F Vogel 155461ae650dSJack F Vogel /* check if ATR is enabled and sample rate */ 155561ae650dSJack F Vogel if ((!ixl_enable_fdir) || (!txr->atr_rate)) 155661ae650dSJack F Vogel return; 155761ae650dSJack F Vogel /* 155861ae650dSJack F Vogel ** We sample all TCP SYN/FIN packets, 155961ae650dSJack F Vogel ** or at the selected sample rate 156061ae650dSJack F Vogel */ 156161ae650dSJack F Vogel txr->atr_count++; 156261ae650dSJack F Vogel if (((th->th_flags & (TH_FIN | TH_SYN)) == 0) && 156361ae650dSJack F Vogel (txr->atr_count < txr->atr_rate)) 156461ae650dSJack F Vogel return; 156561ae650dSJack F Vogel txr->atr_count = 0; 156661ae650dSJack F Vogel 156761ae650dSJack F Vogel /* Get a descriptor to use */ 156861ae650dSJack F Vogel idx = txr->next_avail; 156961ae650dSJack F Vogel FDIR = (struct i40e_filter_program_desc *) &txr->base[idx]; 157061ae650dSJack F Vogel if (++idx == que->num_desc) 157161ae650dSJack F Vogel idx = 0; 157261ae650dSJack F Vogel txr->avail--; 157361ae650dSJack F Vogel txr->next_avail = idx; 157461ae650dSJack F Vogel 157561ae650dSJack F Vogel ptype = (que->me << I40E_TXD_FLTR_QW0_QINDEX_SHIFT) & 157661ae650dSJack F Vogel I40E_TXD_FLTR_QW0_QINDEX_MASK; 157761ae650dSJack F Vogel 157861ae650dSJack F Vogel ptype |= (etype == ETHERTYPE_IP) ? 157961ae650dSJack F Vogel (I40E_FILTER_PCTYPE_NONF_IPV4_TCP << 158061ae650dSJack F Vogel I40E_TXD_FLTR_QW0_PCTYPE_SHIFT) : 158161ae650dSJack F Vogel (I40E_FILTER_PCTYPE_NONF_IPV6_TCP << 158261ae650dSJack F Vogel I40E_TXD_FLTR_QW0_PCTYPE_SHIFT); 158361ae650dSJack F Vogel 158461ae650dSJack F Vogel ptype |= vsi->id << I40E_TXD_FLTR_QW0_DEST_VSI_SHIFT; 158561ae650dSJack F Vogel 158661ae650dSJack F Vogel dtype = I40E_TX_DESC_DTYPE_FILTER_PROG; 158761ae650dSJack F Vogel 158861ae650dSJack F Vogel /* 158961ae650dSJack F Vogel ** We use the TCP TH_FIN as a trigger to remove 159061ae650dSJack F Vogel ** the filter, otherwise its an update. 159161ae650dSJack F Vogel */ 159261ae650dSJack F Vogel dtype |= (th->th_flags & TH_FIN) ? 159361ae650dSJack F Vogel (I40E_FILTER_PROGRAM_DESC_PCMD_REMOVE << 159461ae650dSJack F Vogel I40E_TXD_FLTR_QW1_PCMD_SHIFT) : 159561ae650dSJack F Vogel (I40E_FILTER_PROGRAM_DESC_PCMD_ADD_UPDATE << 159661ae650dSJack F Vogel I40E_TXD_FLTR_QW1_PCMD_SHIFT); 159761ae650dSJack F Vogel 159861ae650dSJack F Vogel dtype |= I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX << 159961ae650dSJack F Vogel I40E_TXD_FLTR_QW1_DEST_SHIFT; 160061ae650dSJack F Vogel 160161ae650dSJack F Vogel dtype |= I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID << 160261ae650dSJack F Vogel I40E_TXD_FLTR_QW1_FD_STATUS_SHIFT; 160361ae650dSJack F Vogel 160461ae650dSJack F Vogel FDIR->qindex_flex_ptype_vsi = htole32(ptype); 160561ae650dSJack F Vogel FDIR->dtype_cmd_cntindex = htole32(dtype); 160661ae650dSJack F Vogel return; 160761ae650dSJack F Vogel } 160861ae650dSJack F Vogel #endif 160961ae650dSJack F Vogel 161061ae650dSJack F Vogel 161161ae650dSJack F Vogel static void 161261ae650dSJack F Vogel ixl_set_promisc(struct ixl_vsi *vsi) 161361ae650dSJack F Vogel { 161461ae650dSJack F Vogel struct ifnet *ifp = vsi->ifp; 161561ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 161661ae650dSJack F Vogel int err, mcnt = 0; 161761ae650dSJack F Vogel bool uni = FALSE, multi = FALSE; 161861ae650dSJack F Vogel 161961ae650dSJack F Vogel if (ifp->if_flags & IFF_ALLMULTI) 162061ae650dSJack F Vogel multi = TRUE; 162161ae650dSJack F Vogel else { /* Need to count the multicast addresses */ 162261ae650dSJack F Vogel struct ifmultiaddr *ifma; 162361ae650dSJack F Vogel if_maddr_rlock(ifp); 162461ae650dSJack F Vogel TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 162561ae650dSJack F Vogel if (ifma->ifma_addr->sa_family != AF_LINK) 162661ae650dSJack F Vogel continue; 162761ae650dSJack F Vogel if (mcnt == MAX_MULTICAST_ADDR) 162861ae650dSJack F Vogel break; 162961ae650dSJack F Vogel mcnt++; 163061ae650dSJack F Vogel } 163161ae650dSJack F Vogel if_maddr_runlock(ifp); 163261ae650dSJack F Vogel } 163361ae650dSJack F Vogel 163461ae650dSJack F Vogel if (mcnt >= MAX_MULTICAST_ADDR) 163561ae650dSJack F Vogel multi = TRUE; 163661ae650dSJack F Vogel if (ifp->if_flags & IFF_PROMISC) 163761ae650dSJack F Vogel uni = TRUE; 163861ae650dSJack F Vogel 163961ae650dSJack F Vogel err = i40e_aq_set_vsi_unicast_promiscuous(hw, 164061ae650dSJack F Vogel vsi->seid, uni, NULL); 164161ae650dSJack F Vogel err = i40e_aq_set_vsi_multicast_promiscuous(hw, 164261ae650dSJack F Vogel vsi->seid, multi, NULL); 164361ae650dSJack F Vogel return; 164461ae650dSJack F Vogel } 164561ae650dSJack F Vogel 164661ae650dSJack F Vogel /********************************************************************* 164761ae650dSJack F Vogel * Filter Routines 164861ae650dSJack F Vogel * 164961ae650dSJack F Vogel * Routines for multicast and vlan filter management. 165061ae650dSJack F Vogel * 165161ae650dSJack F Vogel *********************************************************************/ 165261ae650dSJack F Vogel static void 165361ae650dSJack F Vogel ixl_add_multi(struct ixl_vsi *vsi) 165461ae650dSJack F Vogel { 165561ae650dSJack F Vogel struct ifmultiaddr *ifma; 165661ae650dSJack F Vogel struct ifnet *ifp = vsi->ifp; 165761ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 165861ae650dSJack F Vogel int mcnt = 0, flags; 165961ae650dSJack F Vogel 166061ae650dSJack F Vogel IOCTL_DEBUGOUT("ixl_add_multi: begin"); 166161ae650dSJack F Vogel 166261ae650dSJack F Vogel if_maddr_rlock(ifp); 166361ae650dSJack F Vogel /* 166461ae650dSJack F Vogel ** First just get a count, to decide if we 166561ae650dSJack F Vogel ** we simply use multicast promiscuous. 166661ae650dSJack F Vogel */ 166761ae650dSJack F Vogel TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 166861ae650dSJack F Vogel if (ifma->ifma_addr->sa_family != AF_LINK) 166961ae650dSJack F Vogel continue; 167061ae650dSJack F Vogel mcnt++; 167161ae650dSJack F Vogel } 167261ae650dSJack F Vogel if_maddr_runlock(ifp); 167361ae650dSJack F Vogel 167461ae650dSJack F Vogel if (__predict_false(mcnt >= MAX_MULTICAST_ADDR)) { 167561ae650dSJack F Vogel /* delete existing MC filters */ 167661ae650dSJack F Vogel ixl_del_hw_filters(vsi, mcnt); 167761ae650dSJack F Vogel i40e_aq_set_vsi_multicast_promiscuous(hw, 167861ae650dSJack F Vogel vsi->seid, TRUE, NULL); 167961ae650dSJack F Vogel return; 168061ae650dSJack F Vogel } 168161ae650dSJack F Vogel 168261ae650dSJack F Vogel mcnt = 0; 168361ae650dSJack F Vogel if_maddr_rlock(ifp); 168461ae650dSJack F Vogel TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 168561ae650dSJack F Vogel if (ifma->ifma_addr->sa_family != AF_LINK) 168661ae650dSJack F Vogel continue; 168761ae650dSJack F Vogel ixl_add_mc_filter(vsi, 168861ae650dSJack F Vogel (u8*)LLADDR((struct sockaddr_dl *) ifma->ifma_addr)); 168961ae650dSJack F Vogel mcnt++; 169061ae650dSJack F Vogel } 169161ae650dSJack F Vogel if_maddr_runlock(ifp); 169261ae650dSJack F Vogel if (mcnt > 0) { 169361ae650dSJack F Vogel flags = (IXL_FILTER_ADD | IXL_FILTER_USED | IXL_FILTER_MC); 169461ae650dSJack F Vogel ixl_add_hw_filters(vsi, flags, mcnt); 169561ae650dSJack F Vogel } 169661ae650dSJack F Vogel 169761ae650dSJack F Vogel IOCTL_DEBUGOUT("ixl_add_multi: end"); 169861ae650dSJack F Vogel return; 169961ae650dSJack F Vogel } 170061ae650dSJack F Vogel 170161ae650dSJack F Vogel static void 170261ae650dSJack F Vogel ixl_del_multi(struct ixl_vsi *vsi) 170361ae650dSJack F Vogel { 170461ae650dSJack F Vogel struct ifnet *ifp = vsi->ifp; 170561ae650dSJack F Vogel struct ifmultiaddr *ifma; 170661ae650dSJack F Vogel struct ixl_mac_filter *f; 170761ae650dSJack F Vogel int mcnt = 0; 170861ae650dSJack F Vogel bool match = FALSE; 170961ae650dSJack F Vogel 171061ae650dSJack F Vogel IOCTL_DEBUGOUT("ixl_del_multi: begin"); 171161ae650dSJack F Vogel 171261ae650dSJack F Vogel /* Search for removed multicast addresses */ 171361ae650dSJack F Vogel if_maddr_rlock(ifp); 171461ae650dSJack F Vogel SLIST_FOREACH(f, &vsi->ftl, next) { 171561ae650dSJack F Vogel if ((f->flags & IXL_FILTER_USED) && (f->flags & IXL_FILTER_MC)) { 171661ae650dSJack F Vogel match = FALSE; 171761ae650dSJack F Vogel TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 171861ae650dSJack F Vogel if (ifma->ifma_addr->sa_family != AF_LINK) 171961ae650dSJack F Vogel continue; 172061ae650dSJack F Vogel u8 *mc_addr = (u8 *)LLADDR((struct sockaddr_dl *)ifma->ifma_addr); 172161ae650dSJack F Vogel if (cmp_etheraddr(f->macaddr, mc_addr)) { 172261ae650dSJack F Vogel match = TRUE; 172361ae650dSJack F Vogel break; 172461ae650dSJack F Vogel } 172561ae650dSJack F Vogel } 172661ae650dSJack F Vogel if (match == FALSE) { 172761ae650dSJack F Vogel f->flags |= IXL_FILTER_DEL; 172861ae650dSJack F Vogel mcnt++; 172961ae650dSJack F Vogel } 173061ae650dSJack F Vogel } 173161ae650dSJack F Vogel } 173261ae650dSJack F Vogel if_maddr_runlock(ifp); 173361ae650dSJack F Vogel 173461ae650dSJack F Vogel if (mcnt > 0) 173561ae650dSJack F Vogel ixl_del_hw_filters(vsi, mcnt); 173661ae650dSJack F Vogel } 173761ae650dSJack F Vogel 173861ae650dSJack F Vogel 173961ae650dSJack F Vogel /********************************************************************* 174061ae650dSJack F Vogel * Timer routine 174161ae650dSJack F Vogel * 174261ae650dSJack F Vogel * This routine checks for link status,updates statistics, 174361ae650dSJack F Vogel * and runs the watchdog check. 174461ae650dSJack F Vogel * 174561ae650dSJack F Vogel **********************************************************************/ 174661ae650dSJack F Vogel 174761ae650dSJack F Vogel static void 174861ae650dSJack F Vogel ixl_local_timer(void *arg) 174961ae650dSJack F Vogel { 175061ae650dSJack F Vogel struct ixl_pf *pf = arg; 175161ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 175261ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 175361ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 175461ae650dSJack F Vogel device_t dev = pf->dev; 175561ae650dSJack F Vogel int hung = 0; 175661ae650dSJack F Vogel u32 mask; 175761ae650dSJack F Vogel 175861ae650dSJack F Vogel mtx_assert(&pf->pf_mtx, MA_OWNED); 175961ae650dSJack F Vogel 176061ae650dSJack F Vogel /* Fire off the adminq task */ 176161ae650dSJack F Vogel taskqueue_enqueue(pf->tq, &pf->adminq); 176261ae650dSJack F Vogel 176361ae650dSJack F Vogel /* Update stats */ 176461ae650dSJack F Vogel ixl_update_stats_counters(pf); 176561ae650dSJack F Vogel 176661ae650dSJack F Vogel /* 176761ae650dSJack F Vogel ** Check status of the queues 176861ae650dSJack F Vogel */ 176961ae650dSJack F Vogel mask = (I40E_PFINT_DYN_CTLN_INTENA_MASK | 177061ae650dSJack F Vogel I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK); 177161ae650dSJack F Vogel 177261ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++,que++) { 177361ae650dSJack F Vogel /* Any queues with outstanding work get a sw irq */ 177461ae650dSJack F Vogel if (que->busy) 177561ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTLN(que->me), mask); 177661ae650dSJack F Vogel /* 177761ae650dSJack F Vogel ** Each time txeof runs without cleaning, but there 177861ae650dSJack F Vogel ** are uncleaned descriptors it increments busy. If 177961ae650dSJack F Vogel ** we get to 5 we declare it hung. 178061ae650dSJack F Vogel */ 178161ae650dSJack F Vogel if (que->busy == IXL_QUEUE_HUNG) { 178261ae650dSJack F Vogel ++hung; 178361ae650dSJack F Vogel /* Mark the queue as inactive */ 178461ae650dSJack F Vogel vsi->active_queues &= ~((u64)1 << que->me); 178561ae650dSJack F Vogel continue; 178661ae650dSJack F Vogel } else { 178761ae650dSJack F Vogel /* Check if we've come back from hung */ 178861ae650dSJack F Vogel if ((vsi->active_queues & ((u64)1 << que->me)) == 0) 178961ae650dSJack F Vogel vsi->active_queues |= ((u64)1 << que->me); 179061ae650dSJack F Vogel } 179161ae650dSJack F Vogel if (que->busy >= IXL_MAX_TX_BUSY) { 1792393c4bb1SJack F Vogel #ifdef IXL_DEBUG 179361ae650dSJack F Vogel device_printf(dev,"Warning queue %d " 179461ae650dSJack F Vogel "appears to be hung!\n", i); 1795393c4bb1SJack F Vogel #endif 179661ae650dSJack F Vogel que->busy = IXL_QUEUE_HUNG; 179761ae650dSJack F Vogel ++hung; 179861ae650dSJack F Vogel } 179961ae650dSJack F Vogel } 180061ae650dSJack F Vogel /* Only reinit if all queues show hung */ 180161ae650dSJack F Vogel if (hung == vsi->num_queues) 180261ae650dSJack F Vogel goto hung; 180361ae650dSJack F Vogel 180461ae650dSJack F Vogel callout_reset(&pf->timer, hz, ixl_local_timer, pf); 180561ae650dSJack F Vogel return; 180661ae650dSJack F Vogel 180761ae650dSJack F Vogel hung: 180861ae650dSJack F Vogel device_printf(dev, "Local Timer: HANG DETECT - Resetting!!\n"); 180961ae650dSJack F Vogel ixl_init_locked(pf); 181061ae650dSJack F Vogel } 181161ae650dSJack F Vogel 181261ae650dSJack F Vogel /* 181361ae650dSJack F Vogel ** Note: this routine updates the OS on the link state 181461ae650dSJack F Vogel ** the real check of the hardware only happens with 181561ae650dSJack F Vogel ** a link interrupt. 181661ae650dSJack F Vogel */ 181761ae650dSJack F Vogel static void 181861ae650dSJack F Vogel ixl_update_link_status(struct ixl_pf *pf) 181961ae650dSJack F Vogel { 182061ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 182161ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 182261ae650dSJack F Vogel struct ifnet *ifp = vsi->ifp; 182361ae650dSJack F Vogel device_t dev = pf->dev; 182461ae650dSJack F Vogel 182556c2c47bSJack F Vogel if (pf->link_up){ 182661ae650dSJack F Vogel if (vsi->link_active == FALSE) { 1827b6c8f260SJack F Vogel pf->fc = hw->fc.current_mode; 182861ae650dSJack F Vogel if (bootverbose) { 182961ae650dSJack F Vogel device_printf(dev,"Link is up %d Gbps %s," 183061ae650dSJack F Vogel " Flow Control: %s\n", 183156c2c47bSJack F Vogel ((pf->link_speed == 183256c2c47bSJack F Vogel I40E_LINK_SPEED_40GB)? 40:10), 1833b6c8f260SJack F Vogel "Full Duplex", ixl_fc_string[pf->fc]); 183461ae650dSJack F Vogel } 183561ae650dSJack F Vogel vsi->link_active = TRUE; 1836393c4bb1SJack F Vogel /* 1837393c4bb1SJack F Vogel ** Warn user if link speed on NPAR enabled 1838393c4bb1SJack F Vogel ** partition is not at least 10GB 1839393c4bb1SJack F Vogel */ 1840393c4bb1SJack F Vogel if (hw->func_caps.npar_enable && 184156c2c47bSJack F Vogel (hw->phy.link_info.link_speed == 184256c2c47bSJack F Vogel I40E_LINK_SPEED_1GB || 184356c2c47bSJack F Vogel hw->phy.link_info.link_speed == 184456c2c47bSJack F Vogel I40E_LINK_SPEED_100MB)) 184556c2c47bSJack F Vogel device_printf(dev, "The partition detected" 184656c2c47bSJack F Vogel "link speed that is less than 10Gbps\n"); 184761ae650dSJack F Vogel if_link_state_change(ifp, LINK_STATE_UP); 184861ae650dSJack F Vogel } 184961ae650dSJack F Vogel } else { /* Link down */ 185061ae650dSJack F Vogel if (vsi->link_active == TRUE) { 185161ae650dSJack F Vogel if (bootverbose) 185261ae650dSJack F Vogel device_printf(dev,"Link is Down\n"); 185361ae650dSJack F Vogel if_link_state_change(ifp, LINK_STATE_DOWN); 185461ae650dSJack F Vogel vsi->link_active = FALSE; 185561ae650dSJack F Vogel } 185661ae650dSJack F Vogel } 185761ae650dSJack F Vogel 185861ae650dSJack F Vogel return; 185961ae650dSJack F Vogel } 186061ae650dSJack F Vogel 186161ae650dSJack F Vogel /********************************************************************* 186261ae650dSJack F Vogel * 186361ae650dSJack F Vogel * This routine disables all traffic on the adapter by issuing a 186461ae650dSJack F Vogel * global reset on the MAC and deallocates TX/RX buffers. 186561ae650dSJack F Vogel * 186661ae650dSJack F Vogel **********************************************************************/ 186761ae650dSJack F Vogel 186861ae650dSJack F Vogel static void 186961ae650dSJack F Vogel ixl_stop(struct ixl_pf *pf) 187061ae650dSJack F Vogel { 187161ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 187261ae650dSJack F Vogel struct ifnet *ifp = vsi->ifp; 187361ae650dSJack F Vogel 187461ae650dSJack F Vogel mtx_assert(&pf->pf_mtx, MA_OWNED); 187561ae650dSJack F Vogel 187661ae650dSJack F Vogel INIT_DEBUGOUT("ixl_stop: begin\n"); 187756c2c47bSJack F Vogel if (pf->num_vfs == 0) 187861ae650dSJack F Vogel ixl_disable_intr(vsi); 187956c2c47bSJack F Vogel else 188056c2c47bSJack F Vogel ixl_disable_rings_intr(vsi); 188161ae650dSJack F Vogel ixl_disable_rings(vsi); 188261ae650dSJack F Vogel 188361ae650dSJack F Vogel /* Tell the stack that the interface is no longer active */ 188461ae650dSJack F Vogel ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); 188561ae650dSJack F Vogel 188661ae650dSJack F Vogel /* Stop the local timer */ 188761ae650dSJack F Vogel callout_stop(&pf->timer); 188861ae650dSJack F Vogel 188961ae650dSJack F Vogel return; 189061ae650dSJack F Vogel } 189161ae650dSJack F Vogel 189261ae650dSJack F Vogel 189361ae650dSJack F Vogel /********************************************************************* 189461ae650dSJack F Vogel * 189561ae650dSJack F Vogel * Setup MSIX Interrupt resources and handlers for the VSI 189661ae650dSJack F Vogel * 189761ae650dSJack F Vogel **********************************************************************/ 189861ae650dSJack F Vogel static int 189961ae650dSJack F Vogel ixl_assign_vsi_legacy(struct ixl_pf *pf) 190061ae650dSJack F Vogel { 190161ae650dSJack F Vogel device_t dev = pf->dev; 190261ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 190361ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 190461ae650dSJack F Vogel int error, rid = 0; 190561ae650dSJack F Vogel 190661ae650dSJack F Vogel if (pf->msix == 1) 190761ae650dSJack F Vogel rid = 1; 190861ae650dSJack F Vogel pf->res = bus_alloc_resource_any(dev, SYS_RES_IRQ, 190961ae650dSJack F Vogel &rid, RF_SHAREABLE | RF_ACTIVE); 191061ae650dSJack F Vogel if (pf->res == NULL) { 191161ae650dSJack F Vogel device_printf(dev,"Unable to allocate" 191261ae650dSJack F Vogel " bus resource: vsi legacy/msi interrupt\n"); 191361ae650dSJack F Vogel return (ENXIO); 191461ae650dSJack F Vogel } 191561ae650dSJack F Vogel 191661ae650dSJack F Vogel /* Set the handler function */ 191761ae650dSJack F Vogel error = bus_setup_intr(dev, pf->res, 191861ae650dSJack F Vogel INTR_TYPE_NET | INTR_MPSAFE, NULL, 191961ae650dSJack F Vogel ixl_intr, pf, &pf->tag); 192061ae650dSJack F Vogel if (error) { 192161ae650dSJack F Vogel pf->res = NULL; 192261ae650dSJack F Vogel device_printf(dev, "Failed to register legacy/msi handler"); 192361ae650dSJack F Vogel return (error); 192461ae650dSJack F Vogel } 192561ae650dSJack F Vogel bus_describe_intr(dev, pf->res, pf->tag, "irq0"); 192661ae650dSJack F Vogel TASK_INIT(&que->tx_task, 0, ixl_deferred_mq_start, que); 192761ae650dSJack F Vogel TASK_INIT(&que->task, 0, ixl_handle_que, que); 192861ae650dSJack F Vogel que->tq = taskqueue_create_fast("ixl_que", M_NOWAIT, 192961ae650dSJack F Vogel taskqueue_thread_enqueue, &que->tq); 193061ae650dSJack F Vogel taskqueue_start_threads(&que->tq, 1, PI_NET, "%s que", 193161ae650dSJack F Vogel device_get_nameunit(dev)); 193261ae650dSJack F Vogel TASK_INIT(&pf->adminq, 0, ixl_do_adminq, pf); 193356c2c47bSJack F Vogel 193456c2c47bSJack F Vogel #ifdef PCI_IOV 193556c2c47bSJack F Vogel TASK_INIT(&pf->vflr_task, 0, ixl_handle_vflr, pf); 193656c2c47bSJack F Vogel #endif 193756c2c47bSJack F Vogel 193861ae650dSJack F Vogel pf->tq = taskqueue_create_fast("ixl_adm", M_NOWAIT, 193961ae650dSJack F Vogel taskqueue_thread_enqueue, &pf->tq); 194061ae650dSJack F Vogel taskqueue_start_threads(&pf->tq, 1, PI_NET, "%s adminq", 194161ae650dSJack F Vogel device_get_nameunit(dev)); 194261ae650dSJack F Vogel 194361ae650dSJack F Vogel return (0); 194461ae650dSJack F Vogel } 194561ae650dSJack F Vogel 194661ae650dSJack F Vogel 194761ae650dSJack F Vogel /********************************************************************* 194861ae650dSJack F Vogel * 194961ae650dSJack F Vogel * Setup MSIX Interrupt resources and handlers for the VSI 195061ae650dSJack F Vogel * 195161ae650dSJack F Vogel **********************************************************************/ 195261ae650dSJack F Vogel static int 195361ae650dSJack F Vogel ixl_assign_vsi_msix(struct ixl_pf *pf) 195461ae650dSJack F Vogel { 195561ae650dSJack F Vogel device_t dev = pf->dev; 195661ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 195761ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 195861ae650dSJack F Vogel struct tx_ring *txr; 195961ae650dSJack F Vogel int error, rid, vector = 0; 19609756bd59SAdrian Chadd #ifdef RSS 19619756bd59SAdrian Chadd cpuset_t cpu_mask; 19629756bd59SAdrian Chadd #endif 196361ae650dSJack F Vogel 196461ae650dSJack F Vogel /* Admin Que is vector 0*/ 196561ae650dSJack F Vogel rid = vector + 1; 196661ae650dSJack F Vogel pf->res = bus_alloc_resource_any(dev, 196761ae650dSJack F Vogel SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE); 196861ae650dSJack F Vogel if (!pf->res) { 196961ae650dSJack F Vogel device_printf(dev,"Unable to allocate" 197061ae650dSJack F Vogel " bus resource: Adminq interrupt [%d]\n", rid); 197161ae650dSJack F Vogel return (ENXIO); 197261ae650dSJack F Vogel } 197361ae650dSJack F Vogel /* Set the adminq vector and handler */ 197461ae650dSJack F Vogel error = bus_setup_intr(dev, pf->res, 197561ae650dSJack F Vogel INTR_TYPE_NET | INTR_MPSAFE, NULL, 197661ae650dSJack F Vogel ixl_msix_adminq, pf, &pf->tag); 197761ae650dSJack F Vogel if (error) { 197861ae650dSJack F Vogel pf->res = NULL; 197961ae650dSJack F Vogel device_printf(dev, "Failed to register Admin que handler"); 198061ae650dSJack F Vogel return (error); 198161ae650dSJack F Vogel } 198261ae650dSJack F Vogel bus_describe_intr(dev, pf->res, pf->tag, "aq"); 198361ae650dSJack F Vogel pf->admvec = vector; 198461ae650dSJack F Vogel /* Tasklet for Admin Queue */ 198561ae650dSJack F Vogel TASK_INIT(&pf->adminq, 0, ixl_do_adminq, pf); 198656c2c47bSJack F Vogel 198756c2c47bSJack F Vogel #ifdef PCI_IOV 198856c2c47bSJack F Vogel TASK_INIT(&pf->vflr_task, 0, ixl_handle_vflr, pf); 198956c2c47bSJack F Vogel #endif 199056c2c47bSJack F Vogel 199161ae650dSJack F Vogel pf->tq = taskqueue_create_fast("ixl_adm", M_NOWAIT, 199261ae650dSJack F Vogel taskqueue_thread_enqueue, &pf->tq); 199361ae650dSJack F Vogel taskqueue_start_threads(&pf->tq, 1, PI_NET, "%s adminq", 199461ae650dSJack F Vogel device_get_nameunit(pf->dev)); 199561ae650dSJack F Vogel ++vector; 199661ae650dSJack F Vogel 199761ae650dSJack F Vogel /* Now set up the stations */ 199861ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, vector++, que++) { 1999393c4bb1SJack F Vogel int cpu_id = i; 200061ae650dSJack F Vogel rid = vector + 1; 200161ae650dSJack F Vogel txr = &que->txr; 200261ae650dSJack F Vogel que->res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, 200361ae650dSJack F Vogel RF_SHAREABLE | RF_ACTIVE); 200461ae650dSJack F Vogel if (que->res == NULL) { 200561ae650dSJack F Vogel device_printf(dev,"Unable to allocate" 200661ae650dSJack F Vogel " bus resource: que interrupt [%d]\n", vector); 200761ae650dSJack F Vogel return (ENXIO); 200861ae650dSJack F Vogel } 200961ae650dSJack F Vogel /* Set the handler function */ 201061ae650dSJack F Vogel error = bus_setup_intr(dev, que->res, 201161ae650dSJack F Vogel INTR_TYPE_NET | INTR_MPSAFE, NULL, 201261ae650dSJack F Vogel ixl_msix_que, que, &que->tag); 201361ae650dSJack F Vogel if (error) { 201461ae650dSJack F Vogel que->res = NULL; 201561ae650dSJack F Vogel device_printf(dev, "Failed to register que handler"); 201661ae650dSJack F Vogel return (error); 201761ae650dSJack F Vogel } 201861ae650dSJack F Vogel bus_describe_intr(dev, que->res, que->tag, "q%d", i); 201961ae650dSJack F Vogel /* Bind the vector to a CPU */ 2020393c4bb1SJack F Vogel #ifdef RSS 2021393c4bb1SJack F Vogel cpu_id = rss_getcpu(i % rss_getnumbuckets()); 2022393c4bb1SJack F Vogel #endif 2023393c4bb1SJack F Vogel bus_bind_intr(dev, que->res, cpu_id); 202461ae650dSJack F Vogel que->msix = vector; 202561ae650dSJack F Vogel TASK_INIT(&que->tx_task, 0, ixl_deferred_mq_start, que); 202661ae650dSJack F Vogel TASK_INIT(&que->task, 0, ixl_handle_que, que); 202761ae650dSJack F Vogel que->tq = taskqueue_create_fast("ixl_que", M_NOWAIT, 202861ae650dSJack F Vogel taskqueue_thread_enqueue, &que->tq); 2029393c4bb1SJack F Vogel #ifdef RSS 2030977dc4e2SAdrian Chadd CPU_SETOF(cpu_id, &cpu_mask); 20319756bd59SAdrian Chadd taskqueue_start_threads_cpuset(&que->tq, 1, PI_NET, 20329756bd59SAdrian Chadd &cpu_mask, "%s (bucket %d)", 2033393c4bb1SJack F Vogel device_get_nameunit(dev), cpu_id); 2034393c4bb1SJack F Vogel #else 2035393c4bb1SJack F Vogel taskqueue_start_threads(&que->tq, 1, PI_NET, 2036393c4bb1SJack F Vogel "%s que", device_get_nameunit(dev)); 2037393c4bb1SJack F Vogel #endif 203861ae650dSJack F Vogel } 203961ae650dSJack F Vogel 204061ae650dSJack F Vogel return (0); 204161ae650dSJack F Vogel } 204261ae650dSJack F Vogel 204361ae650dSJack F Vogel 204461ae650dSJack F Vogel /* 204561ae650dSJack F Vogel * Allocate MSI/X vectors 204661ae650dSJack F Vogel */ 204761ae650dSJack F Vogel static int 204861ae650dSJack F Vogel ixl_init_msix(struct ixl_pf *pf) 204961ae650dSJack F Vogel { 205061ae650dSJack F Vogel device_t dev = pf->dev; 205161ae650dSJack F Vogel int rid, want, vectors, queues, available; 205261ae650dSJack F Vogel 205361ae650dSJack F Vogel /* Override by tuneable */ 205461ae650dSJack F Vogel if (ixl_enable_msix == 0) 205561ae650dSJack F Vogel goto msi; 205661ae650dSJack F Vogel 205761ae650dSJack F Vogel /* 205861ae650dSJack F Vogel ** When used in a virtualized environment 205961ae650dSJack F Vogel ** PCI BUSMASTER capability may not be set 206061ae650dSJack F Vogel ** so explicity set it here and rewrite 206161ae650dSJack F Vogel ** the ENABLE in the MSIX control register 206261ae650dSJack F Vogel ** at this point to cause the host to 206361ae650dSJack F Vogel ** successfully initialize us. 206461ae650dSJack F Vogel */ 206561ae650dSJack F Vogel { 206661ae650dSJack F Vogel u16 pci_cmd_word; 206761ae650dSJack F Vogel int msix_ctrl; 206861ae650dSJack F Vogel pci_cmd_word = pci_read_config(dev, PCIR_COMMAND, 2); 206961ae650dSJack F Vogel pci_cmd_word |= PCIM_CMD_BUSMASTEREN; 207061ae650dSJack F Vogel pci_write_config(dev, PCIR_COMMAND, pci_cmd_word, 2); 207161ae650dSJack F Vogel pci_find_cap(dev, PCIY_MSIX, &rid); 207261ae650dSJack F Vogel rid += PCIR_MSIX_CTRL; 207361ae650dSJack F Vogel msix_ctrl = pci_read_config(dev, rid, 2); 207461ae650dSJack F Vogel msix_ctrl |= PCIM_MSIXCTRL_MSIX_ENABLE; 207561ae650dSJack F Vogel pci_write_config(dev, rid, msix_ctrl, 2); 207661ae650dSJack F Vogel } 207761ae650dSJack F Vogel 207861ae650dSJack F Vogel /* First try MSI/X */ 207961ae650dSJack F Vogel rid = PCIR_BAR(IXL_BAR); 208061ae650dSJack F Vogel pf->msix_mem = bus_alloc_resource_any(dev, 208161ae650dSJack F Vogel SYS_RES_MEMORY, &rid, RF_ACTIVE); 208261ae650dSJack F Vogel if (!pf->msix_mem) { 208361ae650dSJack F Vogel /* May not be enabled */ 208461ae650dSJack F Vogel device_printf(pf->dev, 208561ae650dSJack F Vogel "Unable to map MSIX table \n"); 208661ae650dSJack F Vogel goto msi; 208761ae650dSJack F Vogel } 208861ae650dSJack F Vogel 208961ae650dSJack F Vogel available = pci_msix_count(dev); 209061ae650dSJack F Vogel if (available == 0) { /* system has msix disabled */ 209161ae650dSJack F Vogel bus_release_resource(dev, SYS_RES_MEMORY, 209261ae650dSJack F Vogel rid, pf->msix_mem); 209361ae650dSJack F Vogel pf->msix_mem = NULL; 209461ae650dSJack F Vogel goto msi; 209561ae650dSJack F Vogel } 209661ae650dSJack F Vogel 209761ae650dSJack F Vogel /* Figure out a reasonable auto config value */ 209861ae650dSJack F Vogel queues = (mp_ncpus > (available - 1)) ? (available - 1) : mp_ncpus; 209961ae650dSJack F Vogel 210061ae650dSJack F Vogel /* Override with hardcoded value if sane */ 210161ae650dSJack F Vogel if ((ixl_max_queues != 0) && (ixl_max_queues <= queues)) 210261ae650dSJack F Vogel queues = ixl_max_queues; 210361ae650dSJack F Vogel 2104393c4bb1SJack F Vogel #ifdef RSS 2105393c4bb1SJack F Vogel /* If we're doing RSS, clamp at the number of RSS buckets */ 2106393c4bb1SJack F Vogel if (queues > rss_getnumbuckets()) 2107393c4bb1SJack F Vogel queues = rss_getnumbuckets(); 2108393c4bb1SJack F Vogel #endif 2109393c4bb1SJack F Vogel 211061ae650dSJack F Vogel /* 211161ae650dSJack F Vogel ** Want one vector (RX/TX pair) per queue 211261ae650dSJack F Vogel ** plus an additional for the admin queue. 211361ae650dSJack F Vogel */ 211461ae650dSJack F Vogel want = queues + 1; 211561ae650dSJack F Vogel if (want <= available) /* Have enough */ 211661ae650dSJack F Vogel vectors = want; 211761ae650dSJack F Vogel else { 211861ae650dSJack F Vogel device_printf(pf->dev, 211961ae650dSJack F Vogel "MSIX Configuration Problem, " 212061ae650dSJack F Vogel "%d vectors available but %d wanted!\n", 212161ae650dSJack F Vogel available, want); 212261ae650dSJack F Vogel return (0); /* Will go to Legacy setup */ 212361ae650dSJack F Vogel } 212461ae650dSJack F Vogel 212561ae650dSJack F Vogel if (pci_alloc_msix(dev, &vectors) == 0) { 212661ae650dSJack F Vogel device_printf(pf->dev, 212761ae650dSJack F Vogel "Using MSIX interrupts with %d vectors\n", vectors); 212861ae650dSJack F Vogel pf->msix = vectors; 212961ae650dSJack F Vogel pf->vsi.num_queues = queues; 2130393c4bb1SJack F Vogel #ifdef RSS 2131393c4bb1SJack F Vogel /* 2132393c4bb1SJack F Vogel * If we're doing RSS, the number of queues needs to 2133393c4bb1SJack F Vogel * match the number of RSS buckets that are configured. 2134393c4bb1SJack F Vogel * 2135393c4bb1SJack F Vogel * + If there's more queues than RSS buckets, we'll end 2136393c4bb1SJack F Vogel * up with queues that get no traffic. 2137393c4bb1SJack F Vogel * 2138393c4bb1SJack F Vogel * + If there's more RSS buckets than queues, we'll end 2139393c4bb1SJack F Vogel * up having multiple RSS buckets map to the same queue, 2140393c4bb1SJack F Vogel * so there'll be some contention. 2141393c4bb1SJack F Vogel */ 2142393c4bb1SJack F Vogel if (queues != rss_getnumbuckets()) { 2143393c4bb1SJack F Vogel device_printf(dev, 2144393c4bb1SJack F Vogel "%s: queues (%d) != RSS buckets (%d)" 2145393c4bb1SJack F Vogel "; performance will be impacted.\n", 2146393c4bb1SJack F Vogel __func__, queues, rss_getnumbuckets()); 2147393c4bb1SJack F Vogel } 2148393c4bb1SJack F Vogel #endif 214961ae650dSJack F Vogel return (vectors); 215061ae650dSJack F Vogel } 215161ae650dSJack F Vogel msi: 215261ae650dSJack F Vogel vectors = pci_msi_count(dev); 215361ae650dSJack F Vogel pf->vsi.num_queues = 1; 215461ae650dSJack F Vogel pf->msix = 1; 215561ae650dSJack F Vogel ixl_max_queues = 1; 215661ae650dSJack F Vogel ixl_enable_msix = 0; 215761ae650dSJack F Vogel if (vectors == 1 && pci_alloc_msi(dev, &vectors) == 0) 215861ae650dSJack F Vogel device_printf(pf->dev,"Using an MSI interrupt\n"); 215961ae650dSJack F Vogel else { 216061ae650dSJack F Vogel pf->msix = 0; 216161ae650dSJack F Vogel device_printf(pf->dev,"Using a Legacy interrupt\n"); 216261ae650dSJack F Vogel } 216361ae650dSJack F Vogel return (vectors); 216461ae650dSJack F Vogel } 216561ae650dSJack F Vogel 216661ae650dSJack F Vogel 216761ae650dSJack F Vogel /* 216861ae650dSJack F Vogel * Plumb MSI/X vectors 216961ae650dSJack F Vogel */ 217061ae650dSJack F Vogel static void 217161ae650dSJack F Vogel ixl_configure_msix(struct ixl_pf *pf) 217261ae650dSJack F Vogel { 217361ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 217461ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 217561ae650dSJack F Vogel u32 reg; 217661ae650dSJack F Vogel u16 vector = 1; 217761ae650dSJack F Vogel 217861ae650dSJack F Vogel /* First set up the adminq - vector 0 */ 217961ae650dSJack F Vogel wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ 218061ae650dSJack F Vogel rd32(hw, I40E_PFINT_ICR0); /* read to clear */ 218161ae650dSJack F Vogel 218261ae650dSJack F Vogel reg = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | 218361ae650dSJack F Vogel I40E_PFINT_ICR0_ENA_GRST_MASK | 218461ae650dSJack F Vogel I40E_PFINT_ICR0_HMC_ERR_MASK | 218561ae650dSJack F Vogel I40E_PFINT_ICR0_ENA_ADMINQ_MASK | 218661ae650dSJack F Vogel I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | 218761ae650dSJack F Vogel I40E_PFINT_ICR0_ENA_VFLR_MASK | 218861ae650dSJack F Vogel I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK; 218961ae650dSJack F Vogel wr32(hw, I40E_PFINT_ICR0_ENA, reg); 219061ae650dSJack F Vogel 219161ae650dSJack F Vogel wr32(hw, I40E_PFINT_LNKLST0, 0x7FF); 219261ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITR0(IXL_RX_ITR), 0x003E); 219361ae650dSJack F Vogel 219461ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTL0, 219561ae650dSJack F Vogel I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | 219661ae650dSJack F Vogel I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); 219761ae650dSJack F Vogel 219861ae650dSJack F Vogel wr32(hw, I40E_PFINT_STAT_CTL0, 0); 219961ae650dSJack F Vogel 220061ae650dSJack F Vogel /* Next configure the queues */ 220161ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, vector++) { 220261ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTLN(i), i); 220361ae650dSJack F Vogel wr32(hw, I40E_PFINT_LNKLSTN(i), i); 220461ae650dSJack F Vogel 220561ae650dSJack F Vogel reg = I40E_QINT_RQCTL_CAUSE_ENA_MASK | 220661ae650dSJack F Vogel (IXL_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | 220761ae650dSJack F Vogel (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | 220861ae650dSJack F Vogel (i << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) | 220961ae650dSJack F Vogel (I40E_QUEUE_TYPE_TX << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); 221061ae650dSJack F Vogel wr32(hw, I40E_QINT_RQCTL(i), reg); 221161ae650dSJack F Vogel 221261ae650dSJack F Vogel reg = I40E_QINT_TQCTL_CAUSE_ENA_MASK | 221361ae650dSJack F Vogel (IXL_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | 221461ae650dSJack F Vogel (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | 221561ae650dSJack F Vogel ((i+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) | 221661ae650dSJack F Vogel (I40E_QUEUE_TYPE_RX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); 221761ae650dSJack F Vogel if (i == (vsi->num_queues - 1)) 221861ae650dSJack F Vogel reg |= (IXL_QUEUE_EOL 221961ae650dSJack F Vogel << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); 222061ae650dSJack F Vogel wr32(hw, I40E_QINT_TQCTL(i), reg); 222161ae650dSJack F Vogel } 222261ae650dSJack F Vogel } 222361ae650dSJack F Vogel 222461ae650dSJack F Vogel /* 222561ae650dSJack F Vogel * Configure for MSI single vector operation 222661ae650dSJack F Vogel */ 222761ae650dSJack F Vogel static void 222861ae650dSJack F Vogel ixl_configure_legacy(struct ixl_pf *pf) 222961ae650dSJack F Vogel { 223061ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 223161ae650dSJack F Vogel u32 reg; 223261ae650dSJack F Vogel 223361ae650dSJack F Vogel 223461ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITR0(0), 0); 223561ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITR0(1), 0); 223661ae650dSJack F Vogel 223761ae650dSJack F Vogel 223861ae650dSJack F Vogel /* Setup "other" causes */ 223961ae650dSJack F Vogel reg = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK 224061ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK 224161ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_GRST_MASK 224261ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK 224361ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_GPIO_MASK 224461ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_LINK_STAT_CHANGE_MASK 224561ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK 224661ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK 224761ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_VFLR_MASK 224861ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_ADMINQ_MASK 224961ae650dSJack F Vogel ; 225061ae650dSJack F Vogel wr32(hw, I40E_PFINT_ICR0_ENA, reg); 225161ae650dSJack F Vogel 225261ae650dSJack F Vogel /* SW_ITR_IDX = 0, but don't change INTENA */ 225361ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTL0, 225461ae650dSJack F Vogel I40E_PFINT_DYN_CTLN_SW_ITR_INDX_MASK | 225561ae650dSJack F Vogel I40E_PFINT_DYN_CTLN_INTENA_MSK_MASK); 225661ae650dSJack F Vogel /* SW_ITR_IDX = 0, OTHER_ITR_IDX = 0 */ 225761ae650dSJack F Vogel wr32(hw, I40E_PFINT_STAT_CTL0, 0); 225861ae650dSJack F Vogel 225961ae650dSJack F Vogel /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ 226061ae650dSJack F Vogel wr32(hw, I40E_PFINT_LNKLST0, 0); 226161ae650dSJack F Vogel 226261ae650dSJack F Vogel /* Associate the queue pair to the vector and enable the q int */ 226361ae650dSJack F Vogel reg = I40E_QINT_RQCTL_CAUSE_ENA_MASK 226461ae650dSJack F Vogel | (IXL_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) 226561ae650dSJack F Vogel | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); 226661ae650dSJack F Vogel wr32(hw, I40E_QINT_RQCTL(0), reg); 226761ae650dSJack F Vogel 226861ae650dSJack F Vogel reg = I40E_QINT_TQCTL_CAUSE_ENA_MASK 226961ae650dSJack F Vogel | (IXL_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) 227061ae650dSJack F Vogel | (IXL_QUEUE_EOL << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); 227161ae650dSJack F Vogel wr32(hw, I40E_QINT_TQCTL(0), reg); 227261ae650dSJack F Vogel 227361ae650dSJack F Vogel /* Next enable the queue pair */ 227461ae650dSJack F Vogel reg = rd32(hw, I40E_QTX_ENA(0)); 227561ae650dSJack F Vogel reg |= I40E_QTX_ENA_QENA_REQ_MASK; 227661ae650dSJack F Vogel wr32(hw, I40E_QTX_ENA(0), reg); 227761ae650dSJack F Vogel 227861ae650dSJack F Vogel reg = rd32(hw, I40E_QRX_ENA(0)); 227961ae650dSJack F Vogel reg |= I40E_QRX_ENA_QENA_REQ_MASK; 228061ae650dSJack F Vogel wr32(hw, I40E_QRX_ENA(0), reg); 228161ae650dSJack F Vogel } 228261ae650dSJack F Vogel 228361ae650dSJack F Vogel 228461ae650dSJack F Vogel /* 228561ae650dSJack F Vogel * Set the Initial ITR state 228661ae650dSJack F Vogel */ 228761ae650dSJack F Vogel static void 228861ae650dSJack F Vogel ixl_configure_itr(struct ixl_pf *pf) 228961ae650dSJack F Vogel { 229061ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 229161ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 229261ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 229361ae650dSJack F Vogel 229461ae650dSJack F Vogel vsi->rx_itr_setting = ixl_rx_itr; 229561ae650dSJack F Vogel if (ixl_dynamic_rx_itr) 229661ae650dSJack F Vogel vsi->rx_itr_setting |= IXL_ITR_DYNAMIC; 229761ae650dSJack F Vogel vsi->tx_itr_setting = ixl_tx_itr; 229861ae650dSJack F Vogel if (ixl_dynamic_tx_itr) 229961ae650dSJack F Vogel vsi->tx_itr_setting |= IXL_ITR_DYNAMIC; 230061ae650dSJack F Vogel 230161ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, que++) { 230261ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 230361ae650dSJack F Vogel struct rx_ring *rxr = &que->rxr; 230461ae650dSJack F Vogel 230561ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITRN(IXL_RX_ITR, i), 230661ae650dSJack F Vogel vsi->rx_itr_setting); 230761ae650dSJack F Vogel rxr->itr = vsi->rx_itr_setting; 230861ae650dSJack F Vogel rxr->latency = IXL_AVE_LATENCY; 230961ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITRN(IXL_TX_ITR, i), 231061ae650dSJack F Vogel vsi->tx_itr_setting); 231161ae650dSJack F Vogel txr->itr = vsi->tx_itr_setting; 231261ae650dSJack F Vogel txr->latency = IXL_AVE_LATENCY; 231361ae650dSJack F Vogel } 231461ae650dSJack F Vogel } 231561ae650dSJack F Vogel 231661ae650dSJack F Vogel 231761ae650dSJack F Vogel static int 231861ae650dSJack F Vogel ixl_allocate_pci_resources(struct ixl_pf *pf) 231961ae650dSJack F Vogel { 232061ae650dSJack F Vogel int rid; 232161ae650dSJack F Vogel device_t dev = pf->dev; 232261ae650dSJack F Vogel 232361ae650dSJack F Vogel rid = PCIR_BAR(0); 232461ae650dSJack F Vogel pf->pci_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 232561ae650dSJack F Vogel &rid, RF_ACTIVE); 232661ae650dSJack F Vogel 232761ae650dSJack F Vogel if (!(pf->pci_mem)) { 232861ae650dSJack F Vogel device_printf(dev,"Unable to allocate bus resource: memory\n"); 232961ae650dSJack F Vogel return (ENXIO); 233061ae650dSJack F Vogel } 233161ae650dSJack F Vogel 233261ae650dSJack F Vogel pf->osdep.mem_bus_space_tag = 233361ae650dSJack F Vogel rman_get_bustag(pf->pci_mem); 233461ae650dSJack F Vogel pf->osdep.mem_bus_space_handle = 233561ae650dSJack F Vogel rman_get_bushandle(pf->pci_mem); 233661ae650dSJack F Vogel pf->osdep.mem_bus_space_size = rman_get_size(pf->pci_mem); 2337cf3c0c32SRyan Stone pf->osdep.flush_reg = I40E_GLGEN_STAT; 233861ae650dSJack F Vogel pf->hw.hw_addr = (u8 *) &pf->osdep.mem_bus_space_handle; 233961ae650dSJack F Vogel 234061ae650dSJack F Vogel pf->hw.back = &pf->osdep; 234161ae650dSJack F Vogel 234261ae650dSJack F Vogel /* 234361ae650dSJack F Vogel ** Now setup MSI or MSI/X, should 234461ae650dSJack F Vogel ** return us the number of supported 234561ae650dSJack F Vogel ** vectors. (Will be 1 for MSI) 234661ae650dSJack F Vogel */ 234761ae650dSJack F Vogel pf->msix = ixl_init_msix(pf); 234861ae650dSJack F Vogel return (0); 234961ae650dSJack F Vogel } 235061ae650dSJack F Vogel 235161ae650dSJack F Vogel static void 235261ae650dSJack F Vogel ixl_free_pci_resources(struct ixl_pf * pf) 235361ae650dSJack F Vogel { 235461ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 235561ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 235661ae650dSJack F Vogel device_t dev = pf->dev; 235761ae650dSJack F Vogel int rid, memrid; 235861ae650dSJack F Vogel 235961ae650dSJack F Vogel memrid = PCIR_BAR(IXL_BAR); 236061ae650dSJack F Vogel 236161ae650dSJack F Vogel /* We may get here before stations are setup */ 236261ae650dSJack F Vogel if ((!ixl_enable_msix) || (que == NULL)) 236361ae650dSJack F Vogel goto early; 236461ae650dSJack F Vogel 236561ae650dSJack F Vogel /* 236661ae650dSJack F Vogel ** Release all msix VSI resources: 236761ae650dSJack F Vogel */ 236861ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, que++) { 236961ae650dSJack F Vogel rid = que->msix + 1; 237061ae650dSJack F Vogel if (que->tag != NULL) { 237161ae650dSJack F Vogel bus_teardown_intr(dev, que->res, que->tag); 237261ae650dSJack F Vogel que->tag = NULL; 237361ae650dSJack F Vogel } 237461ae650dSJack F Vogel if (que->res != NULL) 237561ae650dSJack F Vogel bus_release_resource(dev, SYS_RES_IRQ, rid, que->res); 237661ae650dSJack F Vogel } 237761ae650dSJack F Vogel 237861ae650dSJack F Vogel early: 237961ae650dSJack F Vogel /* Clean the AdminQ interrupt last */ 238061ae650dSJack F Vogel if (pf->admvec) /* we are doing MSIX */ 238161ae650dSJack F Vogel rid = pf->admvec + 1; 238261ae650dSJack F Vogel else 238361ae650dSJack F Vogel (pf->msix != 0) ? (rid = 1):(rid = 0); 238461ae650dSJack F Vogel 238561ae650dSJack F Vogel if (pf->tag != NULL) { 238661ae650dSJack F Vogel bus_teardown_intr(dev, pf->res, pf->tag); 238761ae650dSJack F Vogel pf->tag = NULL; 238861ae650dSJack F Vogel } 238961ae650dSJack F Vogel if (pf->res != NULL) 239061ae650dSJack F Vogel bus_release_resource(dev, SYS_RES_IRQ, rid, pf->res); 239161ae650dSJack F Vogel 239261ae650dSJack F Vogel if (pf->msix) 239361ae650dSJack F Vogel pci_release_msi(dev); 239461ae650dSJack F Vogel 239561ae650dSJack F Vogel if (pf->msix_mem != NULL) 239661ae650dSJack F Vogel bus_release_resource(dev, SYS_RES_MEMORY, 239761ae650dSJack F Vogel memrid, pf->msix_mem); 239861ae650dSJack F Vogel 239961ae650dSJack F Vogel if (pf->pci_mem != NULL) 240061ae650dSJack F Vogel bus_release_resource(dev, SYS_RES_MEMORY, 240161ae650dSJack F Vogel PCIR_BAR(0), pf->pci_mem); 240261ae650dSJack F Vogel 240361ae650dSJack F Vogel return; 240461ae650dSJack F Vogel } 240561ae650dSJack F Vogel 2406e5100ee2SJack F Vogel static void 2407e5100ee2SJack F Vogel ixl_add_ifmedia(struct ixl_vsi *vsi, u32 phy_type) 2408e5100ee2SJack F Vogel { 2409e5100ee2SJack F Vogel /* Display supported media types */ 2410e5100ee2SJack F Vogel if (phy_type & (1 << I40E_PHY_TYPE_100BASE_TX)) 2411e5100ee2SJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_100_TX, 0, NULL); 2412e5100ee2SJack F Vogel 2413e5100ee2SJack F Vogel if (phy_type & (1 << I40E_PHY_TYPE_1000BASE_T)) 2414e5100ee2SJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_1000_T, 0, NULL); 241556c2c47bSJack F Vogel if (phy_type & (1 << I40E_PHY_TYPE_1000BASE_SX)) 241656c2c47bSJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_1000_SX, 0, NULL); 241756c2c47bSJack F Vogel if (phy_type & (1 << I40E_PHY_TYPE_1000BASE_LX)) 241856c2c47bSJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_1000_LX, 0, NULL); 2419e5100ee2SJack F Vogel 2420e5100ee2SJack F Vogel if (phy_type & (1 << I40E_PHY_TYPE_10GBASE_CR1_CU) || 2421b6c8f260SJack F Vogel phy_type & (1 << I40E_PHY_TYPE_10GBASE_KX4) || 2422b6c8f260SJack F Vogel phy_type & (1 << I40E_PHY_TYPE_10GBASE_KR) || 2423b6c8f260SJack F Vogel phy_type & (1 << I40E_PHY_TYPE_10GBASE_AOC) || 2424b6c8f260SJack F Vogel phy_type & (1 << I40E_PHY_TYPE_XAUI) || 2425b6c8f260SJack F Vogel phy_type & (1 << I40E_PHY_TYPE_XFI) || 2426b6c8f260SJack F Vogel phy_type & (1 << I40E_PHY_TYPE_SFI) || 2427e5100ee2SJack F Vogel phy_type & (1 << I40E_PHY_TYPE_10GBASE_SFPP_CU)) 2428e5100ee2SJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_10G_TWINAX, 0, NULL); 2429b6c8f260SJack F Vogel 2430e5100ee2SJack F Vogel if (phy_type & (1 << I40E_PHY_TYPE_10GBASE_SR)) 2431e5100ee2SJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_10G_SR, 0, NULL); 2432e5100ee2SJack F Vogel if (phy_type & (1 << I40E_PHY_TYPE_10GBASE_LR)) 2433e5100ee2SJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_10G_LR, 0, NULL); 2434e5100ee2SJack F Vogel if (phy_type & (1 << I40E_PHY_TYPE_10GBASE_T)) 2435e5100ee2SJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_10G_T, 0, NULL); 2436e5100ee2SJack F Vogel 2437b6c8f260SJack F Vogel if (phy_type & (1 << I40E_PHY_TYPE_40GBASE_CR4) || 2438b6c8f260SJack F Vogel phy_type & (1 << I40E_PHY_TYPE_40GBASE_CR4_CU) || 2439b6c8f260SJack F Vogel phy_type & (1 << I40E_PHY_TYPE_40GBASE_AOC) || 2440b6c8f260SJack F Vogel phy_type & (1 << I40E_PHY_TYPE_XLAUI) || 2441b6c8f260SJack F Vogel phy_type & (1 << I40E_PHY_TYPE_XLPPI) || 2442b6c8f260SJack F Vogel /* KR4 uses CR4 until the OS has the real media type */ 2443b6c8f260SJack F Vogel phy_type & (1 << I40E_PHY_TYPE_40GBASE_KR4)) 2444e5100ee2SJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_40G_CR4, 0, NULL); 2445b6c8f260SJack F Vogel 2446e5100ee2SJack F Vogel if (phy_type & (1 << I40E_PHY_TYPE_40GBASE_SR4)) 2447e5100ee2SJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_40G_SR4, 0, NULL); 2448e5100ee2SJack F Vogel if (phy_type & (1 << I40E_PHY_TYPE_40GBASE_LR4)) 2449e5100ee2SJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_40G_LR4, 0, NULL); 2450e5100ee2SJack F Vogel } 245161ae650dSJack F Vogel 245261ae650dSJack F Vogel /********************************************************************* 245361ae650dSJack F Vogel * 245461ae650dSJack F Vogel * Setup networking device structure and register an interface. 245561ae650dSJack F Vogel * 245661ae650dSJack F Vogel **********************************************************************/ 245761ae650dSJack F Vogel static int 245861ae650dSJack F Vogel ixl_setup_interface(device_t dev, struct ixl_vsi *vsi) 245961ae650dSJack F Vogel { 246061ae650dSJack F Vogel struct ifnet *ifp; 246161ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 246261ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 2463b6c8f260SJack F Vogel struct i40e_aq_get_phy_abilities_resp abilities; 246461ae650dSJack F Vogel enum i40e_status_code aq_error = 0; 246561ae650dSJack F Vogel 246661ae650dSJack F Vogel INIT_DEBUGOUT("ixl_setup_interface: begin"); 246761ae650dSJack F Vogel 246861ae650dSJack F Vogel ifp = vsi->ifp = if_alloc(IFT_ETHER); 246961ae650dSJack F Vogel if (ifp == NULL) { 247061ae650dSJack F Vogel device_printf(dev, "can not allocate ifnet structure\n"); 247161ae650dSJack F Vogel return (-1); 247261ae650dSJack F Vogel } 247361ae650dSJack F Vogel if_initname(ifp, device_get_name(dev), device_get_unit(dev)); 247461ae650dSJack F Vogel ifp->if_mtu = ETHERMTU; 247561ae650dSJack F Vogel ifp->if_baudrate = 4000000000; // ?? 247661ae650dSJack F Vogel ifp->if_init = ixl_init; 247761ae650dSJack F Vogel ifp->if_softc = vsi; 247861ae650dSJack F Vogel ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 247961ae650dSJack F Vogel ifp->if_ioctl = ixl_ioctl; 248061ae650dSJack F Vogel 2481e5100ee2SJack F Vogel #if __FreeBSD_version >= 1100036 24824b443922SGleb Smirnoff if_setgetcounterfn(ifp, ixl_get_counter); 24834b443922SGleb Smirnoff #endif 24844b443922SGleb Smirnoff 248561ae650dSJack F Vogel ifp->if_transmit = ixl_mq_start; 248661ae650dSJack F Vogel 248761ae650dSJack F Vogel ifp->if_qflush = ixl_qflush; 248861ae650dSJack F Vogel 248961ae650dSJack F Vogel ifp->if_snd.ifq_maxlen = que->num_desc - 2; 249061ae650dSJack F Vogel 249161ae650dSJack F Vogel vsi->max_frame_size = 249261ae650dSJack F Vogel ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN 249361ae650dSJack F Vogel + ETHER_VLAN_ENCAP_LEN; 249461ae650dSJack F Vogel 249561ae650dSJack F Vogel /* 249661ae650dSJack F Vogel * Tell the upper layer(s) we support long frames. 249761ae650dSJack F Vogel */ 24981bffa951SGleb Smirnoff ifp->if_hdrlen = sizeof(struct ether_vlan_header); 249961ae650dSJack F Vogel 250061ae650dSJack F Vogel ifp->if_capabilities |= IFCAP_HWCSUM; 250161ae650dSJack F Vogel ifp->if_capabilities |= IFCAP_HWCSUM_IPV6; 250261ae650dSJack F Vogel ifp->if_capabilities |= IFCAP_TSO; 250361ae650dSJack F Vogel ifp->if_capabilities |= IFCAP_JUMBO_MTU; 250461ae650dSJack F Vogel ifp->if_capabilities |= IFCAP_LRO; 250561ae650dSJack F Vogel 250661ae650dSJack F Vogel /* VLAN capabilties */ 250761ae650dSJack F Vogel ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING 250861ae650dSJack F Vogel | IFCAP_VLAN_HWTSO 250961ae650dSJack F Vogel | IFCAP_VLAN_MTU 251061ae650dSJack F Vogel | IFCAP_VLAN_HWCSUM; 251161ae650dSJack F Vogel ifp->if_capenable = ifp->if_capabilities; 251261ae650dSJack F Vogel 251361ae650dSJack F Vogel /* 251461ae650dSJack F Vogel ** Don't turn this on by default, if vlans are 251561ae650dSJack F Vogel ** created on another pseudo device (eg. lagg) 251661ae650dSJack F Vogel ** then vlan events are not passed thru, breaking 251761ae650dSJack F Vogel ** operation, but with HW FILTER off it works. If 251861ae650dSJack F Vogel ** using vlans directly on the ixl driver you can 251961ae650dSJack F Vogel ** enable this and get full hardware tag filtering. 252061ae650dSJack F Vogel */ 252161ae650dSJack F Vogel ifp->if_capabilities |= IFCAP_VLAN_HWFILTER; 252261ae650dSJack F Vogel 252361ae650dSJack F Vogel /* 252461ae650dSJack F Vogel * Specify the media types supported by this adapter and register 252561ae650dSJack F Vogel * callbacks to update media and link information 252661ae650dSJack F Vogel */ 252761ae650dSJack F Vogel ifmedia_init(&vsi->media, IFM_IMASK, ixl_media_change, 252861ae650dSJack F Vogel ixl_media_status); 252961ae650dSJack F Vogel 2530b6c8f260SJack F Vogel aq_error = i40e_aq_get_phy_capabilities(hw, 2531b6c8f260SJack F Vogel FALSE, TRUE, &abilities, NULL); 2532b6c8f260SJack F Vogel /* May need delay to detect fiber correctly */ 2533e5100ee2SJack F Vogel if (aq_error == I40E_ERR_UNKNOWN_PHY) { 2534e5100ee2SJack F Vogel i40e_msec_delay(200); 2535393c4bb1SJack F Vogel aq_error = i40e_aq_get_phy_capabilities(hw, FALSE, 2536b6c8f260SJack F Vogel TRUE, &abilities, NULL); 2537b6c8f260SJack F Vogel } 2538b6c8f260SJack F Vogel if (aq_error) { 2539e5100ee2SJack F Vogel if (aq_error == I40E_ERR_UNKNOWN_PHY) 2540e5100ee2SJack F Vogel device_printf(dev, "Unknown PHY type detected!\n"); 2541e5100ee2SJack F Vogel else 2542b6c8f260SJack F Vogel device_printf(dev, 2543b6c8f260SJack F Vogel "Error getting supported media types, err %d," 2544e5100ee2SJack F Vogel " AQ error %d\n", aq_error, hw->aq.asq_last_status); 2545b6c8f260SJack F Vogel return (0); 2546b6c8f260SJack F Vogel } 2547b6c8f260SJack F Vogel 2548b6c8f260SJack F Vogel ixl_add_ifmedia(vsi, abilities.phy_type); 254961ae650dSJack F Vogel 255061ae650dSJack F Vogel /* Use autoselect media by default */ 255161ae650dSJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_AUTO, 0, NULL); 255261ae650dSJack F Vogel ifmedia_set(&vsi->media, IFM_ETHER | IFM_AUTO); 255361ae650dSJack F Vogel 2554e5100ee2SJack F Vogel ether_ifattach(ifp, hw->mac.addr); 2555e5100ee2SJack F Vogel 255661ae650dSJack F Vogel return (0); 255761ae650dSJack F Vogel } 255861ae650dSJack F Vogel 255956c2c47bSJack F Vogel /* 256056c2c47bSJack F Vogel ** Run when the Admin Queue gets a 256156c2c47bSJack F Vogel ** link transition interrupt. 256256c2c47bSJack F Vogel */ 256356c2c47bSJack F Vogel static void 256456c2c47bSJack F Vogel ixl_link_event(struct ixl_pf *pf, struct i40e_arq_event_info *e) 256561ae650dSJack F Vogel { 256656c2c47bSJack F Vogel struct i40e_hw *hw = &pf->hw; 256756c2c47bSJack F Vogel struct i40e_aqc_get_link_status *status = 256856c2c47bSJack F Vogel (struct i40e_aqc_get_link_status *)&e->desc.params.raw; 256961ae650dSJack F Vogel bool check; 257061ae650dSJack F Vogel 257156c2c47bSJack F Vogel hw->phy.get_link_info = TRUE; 257261ae650dSJack F Vogel check = i40e_get_link_status(hw); 257356c2c47bSJack F Vogel pf->link_up = check; 257461ae650dSJack F Vogel #ifdef IXL_DEBUG 257561ae650dSJack F Vogel printf("Link is %s\n", check ? "up":"down"); 257661ae650dSJack F Vogel #endif 257756c2c47bSJack F Vogel /* Report if Unqualified modules are found */ 257856c2c47bSJack F Vogel if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && 257956c2c47bSJack F Vogel (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && 258056c2c47bSJack F Vogel (!(status->link_info & I40E_AQ_LINK_UP))) 258156c2c47bSJack F Vogel device_printf(pf->dev, "Link failed because " 258256c2c47bSJack F Vogel "an unqualified module was detected\n"); 258356c2c47bSJack F Vogel 258456c2c47bSJack F Vogel return; 258561ae650dSJack F Vogel } 258661ae650dSJack F Vogel 258761ae650dSJack F Vogel /********************************************************************* 258861ae650dSJack F Vogel * 2589b6c8f260SJack F Vogel * Get Firmware Switch configuration 2590b6c8f260SJack F Vogel * - this will need to be more robust when more complex 2591b6c8f260SJack F Vogel * switch configurations are enabled. 259261ae650dSJack F Vogel * 259361ae650dSJack F Vogel **********************************************************************/ 259461ae650dSJack F Vogel static int 2595b6c8f260SJack F Vogel ixl_switch_config(struct ixl_pf *pf) 259661ae650dSJack F Vogel { 2597b6c8f260SJack F Vogel struct i40e_hw *hw = &pf->hw; 2598b6c8f260SJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 259961ae650dSJack F Vogel device_t dev = vsi->dev; 260061ae650dSJack F Vogel struct i40e_aqc_get_switch_config_resp *sw_config; 260161ae650dSJack F Vogel u8 aq_buf[I40E_AQ_LARGE_BUF]; 260256c2c47bSJack F Vogel int ret; 260361ae650dSJack F Vogel u16 next = 0; 260461ae650dSJack F Vogel 2605b6c8f260SJack F Vogel memset(&aq_buf, 0, sizeof(aq_buf)); 260661ae650dSJack F Vogel sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; 260761ae650dSJack F Vogel ret = i40e_aq_get_switch_config(hw, sw_config, 260861ae650dSJack F Vogel sizeof(aq_buf), &next, NULL); 260961ae650dSJack F Vogel if (ret) { 261056c2c47bSJack F Vogel device_printf(dev,"aq_get_switch_config failed (ret=%d)!!\n", 261156c2c47bSJack F Vogel ret); 261261ae650dSJack F Vogel return (ret); 261361ae650dSJack F Vogel } 261461ae650dSJack F Vogel #ifdef IXL_DEBUG 261556c2c47bSJack F Vogel device_printf(dev, 261656c2c47bSJack F Vogel "Switch config: header reported: %d in structure, %d total\n", 261761ae650dSJack F Vogel sw_config->header.num_reported, sw_config->header.num_total); 261856c2c47bSJack F Vogel for (int i = 0; i < sw_config->header.num_reported; i++) { 261956c2c47bSJack F Vogel device_printf(dev, 262056c2c47bSJack F Vogel "%d: type=%d seid=%d uplink=%d downlink=%d\n", i, 262156c2c47bSJack F Vogel sw_config->element[i].element_type, 262256c2c47bSJack F Vogel sw_config->element[i].seid, 262356c2c47bSJack F Vogel sw_config->element[i].uplink_seid, 262456c2c47bSJack F Vogel sw_config->element[i].downlink_seid); 262556c2c47bSJack F Vogel } 262661ae650dSJack F Vogel #endif 2627b6c8f260SJack F Vogel /* Simplified due to a single VSI at the moment */ 262856c2c47bSJack F Vogel vsi->uplink_seid = sw_config->element[0].uplink_seid; 262956c2c47bSJack F Vogel vsi->downlink_seid = sw_config->element[0].downlink_seid; 263061ae650dSJack F Vogel vsi->seid = sw_config->element[0].seid; 2631b6c8f260SJack F Vogel return (ret); 2632b6c8f260SJack F Vogel } 2633b6c8f260SJack F Vogel 2634b6c8f260SJack F Vogel /********************************************************************* 2635b6c8f260SJack F Vogel * 2636b6c8f260SJack F Vogel * Initialize the VSI: this handles contexts, which means things 2637b6c8f260SJack F Vogel * like the number of descriptors, buffer size, 2638b6c8f260SJack F Vogel * plus we init the rings thru this function. 2639b6c8f260SJack F Vogel * 2640b6c8f260SJack F Vogel **********************************************************************/ 2641b6c8f260SJack F Vogel static int 2642b6c8f260SJack F Vogel ixl_initialize_vsi(struct ixl_vsi *vsi) 2643b6c8f260SJack F Vogel { 264456c2c47bSJack F Vogel struct ixl_pf *pf = vsi->back; 2645b6c8f260SJack F Vogel struct ixl_queue *que = vsi->queues; 2646b6c8f260SJack F Vogel device_t dev = vsi->dev; 2647b6c8f260SJack F Vogel struct i40e_hw *hw = vsi->hw; 2648b6c8f260SJack F Vogel struct i40e_vsi_context ctxt; 2649b6c8f260SJack F Vogel int err = 0; 265061ae650dSJack F Vogel 265161ae650dSJack F Vogel memset(&ctxt, 0, sizeof(ctxt)); 265261ae650dSJack F Vogel ctxt.seid = vsi->seid; 265356c2c47bSJack F Vogel if (pf->veb_seid != 0) 265456c2c47bSJack F Vogel ctxt.uplink_seid = pf->veb_seid; 265561ae650dSJack F Vogel ctxt.pf_num = hw->pf_id; 2656b6c8f260SJack F Vogel err = i40e_aq_get_vsi_params(hw, &ctxt, NULL); 2657b6c8f260SJack F Vogel if (err) { 2658b6c8f260SJack F Vogel device_printf(dev,"get vsi params failed %x!!\n", err); 2659b6c8f260SJack F Vogel return (err); 266061ae650dSJack F Vogel } 266161ae650dSJack F Vogel #ifdef IXL_DEBUG 266261ae650dSJack F Vogel printf("get_vsi_params: seid: %d, uplinkseid: %d, vsi_number: %d, " 266361ae650dSJack F Vogel "vsis_allocated: %d, vsis_unallocated: %d, flags: 0x%x, " 266461ae650dSJack F Vogel "pfnum: %d, vfnum: %d, stat idx: %d, enabled: %d\n", ctxt.seid, 266561ae650dSJack F Vogel ctxt.uplink_seid, ctxt.vsi_number, 266661ae650dSJack F Vogel ctxt.vsis_allocated, ctxt.vsis_unallocated, 266761ae650dSJack F Vogel ctxt.flags, ctxt.pf_num, ctxt.vf_num, 266861ae650dSJack F Vogel ctxt.info.stat_counter_idx, ctxt.info.up_enable_bits); 266961ae650dSJack F Vogel #endif 267061ae650dSJack F Vogel /* 267161ae650dSJack F Vogel ** Set the queue and traffic class bits 267261ae650dSJack F Vogel ** - when multiple traffic classes are supported 267361ae650dSJack F Vogel ** this will need to be more robust. 267461ae650dSJack F Vogel */ 267561ae650dSJack F Vogel ctxt.info.valid_sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; 267661ae650dSJack F Vogel ctxt.info.mapping_flags |= I40E_AQ_VSI_QUE_MAP_CONTIG; 267761ae650dSJack F Vogel ctxt.info.queue_mapping[0] = 0; 267861ae650dSJack F Vogel ctxt.info.tc_mapping[0] = 0x0800; 267961ae650dSJack F Vogel 268061ae650dSJack F Vogel /* Set VLAN receive stripping mode */ 268161ae650dSJack F Vogel ctxt.info.valid_sections |= I40E_AQ_VSI_PROP_VLAN_VALID; 268261ae650dSJack F Vogel ctxt.info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL; 268361ae650dSJack F Vogel if (vsi->ifp->if_capenable & IFCAP_VLAN_HWTAGGING) 268461ae650dSJack F Vogel ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; 268561ae650dSJack F Vogel else 268661ae650dSJack F Vogel ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_EMOD_NOTHING; 268761ae650dSJack F Vogel 268861ae650dSJack F Vogel /* Keep copy of VSI info in VSI for statistic counters */ 268961ae650dSJack F Vogel memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info)); 269061ae650dSJack F Vogel 269161ae650dSJack F Vogel /* Reset VSI statistics */ 269261ae650dSJack F Vogel ixl_vsi_reset_stats(vsi); 269361ae650dSJack F Vogel vsi->hw_filters_add = 0; 269461ae650dSJack F Vogel vsi->hw_filters_del = 0; 269561ae650dSJack F Vogel 269656c2c47bSJack F Vogel ctxt.flags = htole16(I40E_AQ_VSI_TYPE_PF); 269756c2c47bSJack F Vogel 2698b6c8f260SJack F Vogel err = i40e_aq_update_vsi_params(hw, &ctxt, NULL); 2699b6c8f260SJack F Vogel if (err) { 270061ae650dSJack F Vogel device_printf(dev,"update vsi params failed %x!!\n", 270161ae650dSJack F Vogel hw->aq.asq_last_status); 2702b6c8f260SJack F Vogel return (err); 270361ae650dSJack F Vogel } 270461ae650dSJack F Vogel 270561ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, que++) { 270661ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 270761ae650dSJack F Vogel struct rx_ring *rxr = &que->rxr; 270861ae650dSJack F Vogel struct i40e_hmc_obj_txq tctx; 270961ae650dSJack F Vogel struct i40e_hmc_obj_rxq rctx; 271061ae650dSJack F Vogel u32 txctl; 271161ae650dSJack F Vogel u16 size; 271261ae650dSJack F Vogel 271361ae650dSJack F Vogel 271461ae650dSJack F Vogel /* Setup the HMC TX Context */ 271561ae650dSJack F Vogel size = que->num_desc * sizeof(struct i40e_tx_desc); 271661ae650dSJack F Vogel memset(&tctx, 0, sizeof(struct i40e_hmc_obj_txq)); 271761ae650dSJack F Vogel tctx.new_context = 1; 271856c2c47bSJack F Vogel tctx.base = (txr->dma.pa/IXL_TX_CTX_BASE_UNITS); 271961ae650dSJack F Vogel tctx.qlen = que->num_desc; 272061ae650dSJack F Vogel tctx.fc_ena = 0; 272161ae650dSJack F Vogel tctx.rdylist = vsi->info.qs_handle[0]; /* index is TC */ 272261ae650dSJack F Vogel /* Enable HEAD writeback */ 272361ae650dSJack F Vogel tctx.head_wb_ena = 1; 272461ae650dSJack F Vogel tctx.head_wb_addr = txr->dma.pa + 272561ae650dSJack F Vogel (que->num_desc * sizeof(struct i40e_tx_desc)); 272661ae650dSJack F Vogel tctx.rdylist_act = 0; 272761ae650dSJack F Vogel err = i40e_clear_lan_tx_queue_context(hw, i); 272861ae650dSJack F Vogel if (err) { 272961ae650dSJack F Vogel device_printf(dev, "Unable to clear TX context\n"); 273061ae650dSJack F Vogel break; 273161ae650dSJack F Vogel } 273261ae650dSJack F Vogel err = i40e_set_lan_tx_queue_context(hw, i, &tctx); 273361ae650dSJack F Vogel if (err) { 273461ae650dSJack F Vogel device_printf(dev, "Unable to set TX context\n"); 273561ae650dSJack F Vogel break; 273661ae650dSJack F Vogel } 273761ae650dSJack F Vogel /* Associate the ring with this PF */ 273861ae650dSJack F Vogel txctl = I40E_QTX_CTL_PF_QUEUE; 273961ae650dSJack F Vogel txctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & 274061ae650dSJack F Vogel I40E_QTX_CTL_PF_INDX_MASK); 274161ae650dSJack F Vogel wr32(hw, I40E_QTX_CTL(i), txctl); 274261ae650dSJack F Vogel ixl_flush(hw); 274361ae650dSJack F Vogel 274461ae650dSJack F Vogel /* Do ring (re)init */ 274561ae650dSJack F Vogel ixl_init_tx_ring(que); 274661ae650dSJack F Vogel 274761ae650dSJack F Vogel /* Next setup the HMC RX Context */ 274856c2c47bSJack F Vogel if (vsi->max_frame_size <= MCLBYTES) 274961ae650dSJack F Vogel rxr->mbuf_sz = MCLBYTES; 275061ae650dSJack F Vogel else 275161ae650dSJack F Vogel rxr->mbuf_sz = MJUMPAGESIZE; 275261ae650dSJack F Vogel 275361ae650dSJack F Vogel u16 max_rxmax = rxr->mbuf_sz * hw->func_caps.rx_buf_chain_len; 275461ae650dSJack F Vogel 275561ae650dSJack F Vogel /* Set up an RX context for the HMC */ 275661ae650dSJack F Vogel memset(&rctx, 0, sizeof(struct i40e_hmc_obj_rxq)); 275761ae650dSJack F Vogel rctx.dbuff = rxr->mbuf_sz >> I40E_RXQ_CTX_DBUFF_SHIFT; 275861ae650dSJack F Vogel /* ignore header split for now */ 275961ae650dSJack F Vogel rctx.hbuff = 0 >> I40E_RXQ_CTX_HBUFF_SHIFT; 276061ae650dSJack F Vogel rctx.rxmax = (vsi->max_frame_size < max_rxmax) ? 276161ae650dSJack F Vogel vsi->max_frame_size : max_rxmax; 276261ae650dSJack F Vogel rctx.dtype = 0; 276361ae650dSJack F Vogel rctx.dsize = 1; /* do 32byte descriptors */ 276461ae650dSJack F Vogel rctx.hsplit_0 = 0; /* no HDR split initially */ 276556c2c47bSJack F Vogel rctx.base = (rxr->dma.pa/IXL_RX_CTX_BASE_UNITS); 276661ae650dSJack F Vogel rctx.qlen = que->num_desc; 276761ae650dSJack F Vogel rctx.tphrdesc_ena = 1; 276861ae650dSJack F Vogel rctx.tphwdesc_ena = 1; 276961ae650dSJack F Vogel rctx.tphdata_ena = 0; 277061ae650dSJack F Vogel rctx.tphhead_ena = 0; 277161ae650dSJack F Vogel rctx.lrxqthresh = 2; 277261ae650dSJack F Vogel rctx.crcstrip = 1; 277361ae650dSJack F Vogel rctx.l2tsel = 1; 277461ae650dSJack F Vogel rctx.showiv = 1; 277561ae650dSJack F Vogel rctx.fc_ena = 0; 277661ae650dSJack F Vogel rctx.prefena = 1; 277761ae650dSJack F Vogel 277861ae650dSJack F Vogel err = i40e_clear_lan_rx_queue_context(hw, i); 277961ae650dSJack F Vogel if (err) { 278061ae650dSJack F Vogel device_printf(dev, 278161ae650dSJack F Vogel "Unable to clear RX context %d\n", i); 278261ae650dSJack F Vogel break; 278361ae650dSJack F Vogel } 278461ae650dSJack F Vogel err = i40e_set_lan_rx_queue_context(hw, i, &rctx); 278561ae650dSJack F Vogel if (err) { 278661ae650dSJack F Vogel device_printf(dev, "Unable to set RX context %d\n", i); 278761ae650dSJack F Vogel break; 278861ae650dSJack F Vogel } 278961ae650dSJack F Vogel err = ixl_init_rx_ring(que); 279061ae650dSJack F Vogel if (err) { 279161ae650dSJack F Vogel device_printf(dev, "Fail in init_rx_ring %d\n", i); 279261ae650dSJack F Vogel break; 279361ae650dSJack F Vogel } 279461ae650dSJack F Vogel wr32(vsi->hw, I40E_QRX_TAIL(que->me), 0); 2795*31830672SJack F Vogel #ifdef DEV_NETMAP 2796*31830672SJack F Vogel /* preserve queue */ 2797*31830672SJack F Vogel if (vsi->ifp->if_capenable & IFCAP_NETMAP) { 2798*31830672SJack F Vogel struct netmap_adapter *na = NA(vsi->ifp); 2799*31830672SJack F Vogel struct netmap_kring *kring = &na->rx_rings[i]; 2800*31830672SJack F Vogel int t = na->num_rx_desc - 1 - nm_kr_rxspace(kring); 2801*31830672SJack F Vogel wr32(vsi->hw, I40E_QRX_TAIL(que->me), t); 2802*31830672SJack F Vogel } else 2803*31830672SJack F Vogel #endif /* DEV_NETMAP */ 280461ae650dSJack F Vogel wr32(vsi->hw, I40E_QRX_TAIL(que->me), que->num_desc - 1); 280561ae650dSJack F Vogel } 280661ae650dSJack F Vogel return (err); 280761ae650dSJack F Vogel } 280861ae650dSJack F Vogel 280961ae650dSJack F Vogel 281061ae650dSJack F Vogel /********************************************************************* 281161ae650dSJack F Vogel * 281261ae650dSJack F Vogel * Free all VSI structs. 281361ae650dSJack F Vogel * 281461ae650dSJack F Vogel **********************************************************************/ 281561ae650dSJack F Vogel void 281661ae650dSJack F Vogel ixl_free_vsi(struct ixl_vsi *vsi) 281761ae650dSJack F Vogel { 281861ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)vsi->back; 281961ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 282061ae650dSJack F Vogel 282161ae650dSJack F Vogel /* Free station queues */ 282261ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, que++) { 282361ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 282461ae650dSJack F Vogel struct rx_ring *rxr = &que->rxr; 282561ae650dSJack F Vogel 282661ae650dSJack F Vogel if (!mtx_initialized(&txr->mtx)) /* uninitialized */ 282761ae650dSJack F Vogel continue; 282861ae650dSJack F Vogel IXL_TX_LOCK(txr); 282961ae650dSJack F Vogel ixl_free_que_tx(que); 283061ae650dSJack F Vogel if (txr->base) 2831d94ca7cfSBjoern A. Zeeb i40e_free_dma_mem(&pf->hw, &txr->dma); 283261ae650dSJack F Vogel IXL_TX_UNLOCK(txr); 283361ae650dSJack F Vogel IXL_TX_LOCK_DESTROY(txr); 283461ae650dSJack F Vogel 283561ae650dSJack F Vogel if (!mtx_initialized(&rxr->mtx)) /* uninitialized */ 283661ae650dSJack F Vogel continue; 283761ae650dSJack F Vogel IXL_RX_LOCK(rxr); 283861ae650dSJack F Vogel ixl_free_que_rx(que); 283961ae650dSJack F Vogel if (rxr->base) 2840d94ca7cfSBjoern A. Zeeb i40e_free_dma_mem(&pf->hw, &rxr->dma); 284161ae650dSJack F Vogel IXL_RX_UNLOCK(rxr); 284261ae650dSJack F Vogel IXL_RX_LOCK_DESTROY(rxr); 284361ae650dSJack F Vogel 284461ae650dSJack F Vogel } 284561ae650dSJack F Vogel free(vsi->queues, M_DEVBUF); 284661ae650dSJack F Vogel 284761ae650dSJack F Vogel /* Free VSI filter list */ 284856c2c47bSJack F Vogel ixl_free_mac_filters(vsi); 284956c2c47bSJack F Vogel } 285056c2c47bSJack F Vogel 285156c2c47bSJack F Vogel static void 285256c2c47bSJack F Vogel ixl_free_mac_filters(struct ixl_vsi *vsi) 285356c2c47bSJack F Vogel { 285456c2c47bSJack F Vogel struct ixl_mac_filter *f; 285556c2c47bSJack F Vogel 285661ae650dSJack F Vogel while (!SLIST_EMPTY(&vsi->ftl)) { 285761ae650dSJack F Vogel f = SLIST_FIRST(&vsi->ftl); 285861ae650dSJack F Vogel SLIST_REMOVE_HEAD(&vsi->ftl, next); 285961ae650dSJack F Vogel free(f, M_DEVBUF); 286061ae650dSJack F Vogel } 286161ae650dSJack F Vogel } 286261ae650dSJack F Vogel 286361ae650dSJack F Vogel 286461ae650dSJack F Vogel /********************************************************************* 286561ae650dSJack F Vogel * 286661ae650dSJack F Vogel * Allocate memory for the VSI (virtual station interface) and their 286761ae650dSJack F Vogel * associated queues, rings and the descriptors associated with each, 286861ae650dSJack F Vogel * called only once at attach. 286961ae650dSJack F Vogel * 287061ae650dSJack F Vogel **********************************************************************/ 287161ae650dSJack F Vogel static int 287261ae650dSJack F Vogel ixl_setup_stations(struct ixl_pf *pf) 287361ae650dSJack F Vogel { 287461ae650dSJack F Vogel device_t dev = pf->dev; 287561ae650dSJack F Vogel struct ixl_vsi *vsi; 287661ae650dSJack F Vogel struct ixl_queue *que; 287761ae650dSJack F Vogel struct tx_ring *txr; 287861ae650dSJack F Vogel struct rx_ring *rxr; 287961ae650dSJack F Vogel int rsize, tsize; 288061ae650dSJack F Vogel int error = I40E_SUCCESS; 288161ae650dSJack F Vogel 288261ae650dSJack F Vogel vsi = &pf->vsi; 288361ae650dSJack F Vogel vsi->back = (void *)pf; 288461ae650dSJack F Vogel vsi->hw = &pf->hw; 288561ae650dSJack F Vogel vsi->id = 0; 288661ae650dSJack F Vogel vsi->num_vlans = 0; 288756c2c47bSJack F Vogel vsi->back = pf; 288861ae650dSJack F Vogel 288961ae650dSJack F Vogel /* Get memory for the station queues */ 289061ae650dSJack F Vogel if (!(vsi->queues = 289161ae650dSJack F Vogel (struct ixl_queue *) malloc(sizeof(struct ixl_queue) * 289261ae650dSJack F Vogel vsi->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) { 289361ae650dSJack F Vogel device_printf(dev, "Unable to allocate queue memory\n"); 289461ae650dSJack F Vogel error = ENOMEM; 289561ae650dSJack F Vogel goto early; 289661ae650dSJack F Vogel } 289761ae650dSJack F Vogel 289861ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++) { 289961ae650dSJack F Vogel que = &vsi->queues[i]; 290061ae650dSJack F Vogel que->num_desc = ixl_ringsz; 290161ae650dSJack F Vogel que->me = i; 290261ae650dSJack F Vogel que->vsi = vsi; 290361ae650dSJack F Vogel /* mark the queue as active */ 290461ae650dSJack F Vogel vsi->active_queues |= (u64)1 << que->me; 290561ae650dSJack F Vogel txr = &que->txr; 290661ae650dSJack F Vogel txr->que = que; 290761ae650dSJack F Vogel txr->tail = I40E_QTX_TAIL(que->me); 290861ae650dSJack F Vogel 290961ae650dSJack F Vogel /* Initialize the TX lock */ 291061ae650dSJack F Vogel snprintf(txr->mtx_name, sizeof(txr->mtx_name), "%s:tx(%d)", 291161ae650dSJack F Vogel device_get_nameunit(dev), que->me); 291261ae650dSJack F Vogel mtx_init(&txr->mtx, txr->mtx_name, NULL, MTX_DEF); 291361ae650dSJack F Vogel /* Create the TX descriptor ring */ 291461ae650dSJack F Vogel tsize = roundup2((que->num_desc * 291561ae650dSJack F Vogel sizeof(struct i40e_tx_desc)) + 291661ae650dSJack F Vogel sizeof(u32), DBA_ALIGN); 2917d94ca7cfSBjoern A. Zeeb if (i40e_allocate_dma_mem(&pf->hw, 2918d94ca7cfSBjoern A. Zeeb &txr->dma, i40e_mem_reserved, tsize, DBA_ALIGN)) { 291961ae650dSJack F Vogel device_printf(dev, 292061ae650dSJack F Vogel "Unable to allocate TX Descriptor memory\n"); 292161ae650dSJack F Vogel error = ENOMEM; 292261ae650dSJack F Vogel goto fail; 292361ae650dSJack F Vogel } 292461ae650dSJack F Vogel txr->base = (struct i40e_tx_desc *)txr->dma.va; 292561ae650dSJack F Vogel bzero((void *)txr->base, tsize); 292661ae650dSJack F Vogel /* Now allocate transmit soft structs for the ring */ 292761ae650dSJack F Vogel if (ixl_allocate_tx_data(que)) { 292861ae650dSJack F Vogel device_printf(dev, 292961ae650dSJack F Vogel "Critical Failure setting up TX structures\n"); 293061ae650dSJack F Vogel error = ENOMEM; 293161ae650dSJack F Vogel goto fail; 293261ae650dSJack F Vogel } 293361ae650dSJack F Vogel /* Allocate a buf ring */ 293461ae650dSJack F Vogel txr->br = buf_ring_alloc(4096, M_DEVBUF, 293561ae650dSJack F Vogel M_WAITOK, &txr->mtx); 293661ae650dSJack F Vogel if (txr->br == NULL) { 293761ae650dSJack F Vogel device_printf(dev, 293861ae650dSJack F Vogel "Critical Failure setting up TX buf ring\n"); 293961ae650dSJack F Vogel error = ENOMEM; 294061ae650dSJack F Vogel goto fail; 294161ae650dSJack F Vogel } 294261ae650dSJack F Vogel 294361ae650dSJack F Vogel /* 294461ae650dSJack F Vogel * Next the RX queues... 294561ae650dSJack F Vogel */ 294661ae650dSJack F Vogel rsize = roundup2(que->num_desc * 294761ae650dSJack F Vogel sizeof(union i40e_rx_desc), DBA_ALIGN); 294861ae650dSJack F Vogel rxr = &que->rxr; 294961ae650dSJack F Vogel rxr->que = que; 295061ae650dSJack F Vogel rxr->tail = I40E_QRX_TAIL(que->me); 295161ae650dSJack F Vogel 295261ae650dSJack F Vogel /* Initialize the RX side lock */ 295361ae650dSJack F Vogel snprintf(rxr->mtx_name, sizeof(rxr->mtx_name), "%s:rx(%d)", 295461ae650dSJack F Vogel device_get_nameunit(dev), que->me); 295561ae650dSJack F Vogel mtx_init(&rxr->mtx, rxr->mtx_name, NULL, MTX_DEF); 295661ae650dSJack F Vogel 2957d94ca7cfSBjoern A. Zeeb if (i40e_allocate_dma_mem(&pf->hw, 2958d94ca7cfSBjoern A. Zeeb &rxr->dma, i40e_mem_reserved, rsize, 4096)) { 295961ae650dSJack F Vogel device_printf(dev, 296061ae650dSJack F Vogel "Unable to allocate RX Descriptor memory\n"); 296161ae650dSJack F Vogel error = ENOMEM; 296261ae650dSJack F Vogel goto fail; 296361ae650dSJack F Vogel } 296461ae650dSJack F Vogel rxr->base = (union i40e_rx_desc *)rxr->dma.va; 296561ae650dSJack F Vogel bzero((void *)rxr->base, rsize); 296661ae650dSJack F Vogel 296761ae650dSJack F Vogel /* Allocate receive soft structs for the ring*/ 296861ae650dSJack F Vogel if (ixl_allocate_rx_data(que)) { 296961ae650dSJack F Vogel device_printf(dev, 297061ae650dSJack F Vogel "Critical Failure setting up receive structs\n"); 297161ae650dSJack F Vogel error = ENOMEM; 297261ae650dSJack F Vogel goto fail; 297361ae650dSJack F Vogel } 297461ae650dSJack F Vogel } 297561ae650dSJack F Vogel 297661ae650dSJack F Vogel return (0); 297761ae650dSJack F Vogel 297861ae650dSJack F Vogel fail: 297961ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++) { 298061ae650dSJack F Vogel que = &vsi->queues[i]; 298161ae650dSJack F Vogel rxr = &que->rxr; 298261ae650dSJack F Vogel txr = &que->txr; 298361ae650dSJack F Vogel if (rxr->base) 2984d94ca7cfSBjoern A. Zeeb i40e_free_dma_mem(&pf->hw, &rxr->dma); 298561ae650dSJack F Vogel if (txr->base) 2986d94ca7cfSBjoern A. Zeeb i40e_free_dma_mem(&pf->hw, &txr->dma); 298761ae650dSJack F Vogel } 298861ae650dSJack F Vogel 298961ae650dSJack F Vogel early: 299061ae650dSJack F Vogel return (error); 299161ae650dSJack F Vogel } 299261ae650dSJack F Vogel 299361ae650dSJack F Vogel /* 299461ae650dSJack F Vogel ** Provide a update to the queue RX 299561ae650dSJack F Vogel ** interrupt moderation value. 299661ae650dSJack F Vogel */ 299761ae650dSJack F Vogel static void 299861ae650dSJack F Vogel ixl_set_queue_rx_itr(struct ixl_queue *que) 299961ae650dSJack F Vogel { 300061ae650dSJack F Vogel struct ixl_vsi *vsi = que->vsi; 300161ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 300261ae650dSJack F Vogel struct rx_ring *rxr = &que->rxr; 300361ae650dSJack F Vogel u16 rx_itr; 300461ae650dSJack F Vogel u16 rx_latency = 0; 300561ae650dSJack F Vogel int rx_bytes; 300661ae650dSJack F Vogel 300761ae650dSJack F Vogel 300861ae650dSJack F Vogel /* Idle, do nothing */ 300961ae650dSJack F Vogel if (rxr->bytes == 0) 301061ae650dSJack F Vogel return; 301161ae650dSJack F Vogel 301261ae650dSJack F Vogel if (ixl_dynamic_rx_itr) { 301361ae650dSJack F Vogel rx_bytes = rxr->bytes/rxr->itr; 301461ae650dSJack F Vogel rx_itr = rxr->itr; 301561ae650dSJack F Vogel 301661ae650dSJack F Vogel /* Adjust latency range */ 301761ae650dSJack F Vogel switch (rxr->latency) { 301861ae650dSJack F Vogel case IXL_LOW_LATENCY: 301961ae650dSJack F Vogel if (rx_bytes > 10) { 302061ae650dSJack F Vogel rx_latency = IXL_AVE_LATENCY; 302161ae650dSJack F Vogel rx_itr = IXL_ITR_20K; 302261ae650dSJack F Vogel } 302361ae650dSJack F Vogel break; 302461ae650dSJack F Vogel case IXL_AVE_LATENCY: 302561ae650dSJack F Vogel if (rx_bytes > 20) { 302661ae650dSJack F Vogel rx_latency = IXL_BULK_LATENCY; 302761ae650dSJack F Vogel rx_itr = IXL_ITR_8K; 302861ae650dSJack F Vogel } else if (rx_bytes <= 10) { 302961ae650dSJack F Vogel rx_latency = IXL_LOW_LATENCY; 303061ae650dSJack F Vogel rx_itr = IXL_ITR_100K; 303161ae650dSJack F Vogel } 303261ae650dSJack F Vogel break; 303361ae650dSJack F Vogel case IXL_BULK_LATENCY: 303461ae650dSJack F Vogel if (rx_bytes <= 20) { 303561ae650dSJack F Vogel rx_latency = IXL_AVE_LATENCY; 303661ae650dSJack F Vogel rx_itr = IXL_ITR_20K; 303761ae650dSJack F Vogel } 303861ae650dSJack F Vogel break; 303961ae650dSJack F Vogel } 304061ae650dSJack F Vogel 304161ae650dSJack F Vogel rxr->latency = rx_latency; 304261ae650dSJack F Vogel 304361ae650dSJack F Vogel if (rx_itr != rxr->itr) { 304461ae650dSJack F Vogel /* do an exponential smoothing */ 304561ae650dSJack F Vogel rx_itr = (10 * rx_itr * rxr->itr) / 304661ae650dSJack F Vogel ((9 * rx_itr) + rxr->itr); 304761ae650dSJack F Vogel rxr->itr = rx_itr & IXL_MAX_ITR; 304861ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITRN(IXL_RX_ITR, 304961ae650dSJack F Vogel que->me), rxr->itr); 305061ae650dSJack F Vogel } 305161ae650dSJack F Vogel } else { /* We may have have toggled to non-dynamic */ 305261ae650dSJack F Vogel if (vsi->rx_itr_setting & IXL_ITR_DYNAMIC) 305361ae650dSJack F Vogel vsi->rx_itr_setting = ixl_rx_itr; 305461ae650dSJack F Vogel /* Update the hardware if needed */ 305561ae650dSJack F Vogel if (rxr->itr != vsi->rx_itr_setting) { 305661ae650dSJack F Vogel rxr->itr = vsi->rx_itr_setting; 305761ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITRN(IXL_RX_ITR, 305861ae650dSJack F Vogel que->me), rxr->itr); 305961ae650dSJack F Vogel } 306061ae650dSJack F Vogel } 306161ae650dSJack F Vogel rxr->bytes = 0; 306261ae650dSJack F Vogel rxr->packets = 0; 306361ae650dSJack F Vogel return; 306461ae650dSJack F Vogel } 306561ae650dSJack F Vogel 306661ae650dSJack F Vogel 306761ae650dSJack F Vogel /* 306861ae650dSJack F Vogel ** Provide a update to the queue TX 306961ae650dSJack F Vogel ** interrupt moderation value. 307061ae650dSJack F Vogel */ 307161ae650dSJack F Vogel static void 307261ae650dSJack F Vogel ixl_set_queue_tx_itr(struct ixl_queue *que) 307361ae650dSJack F Vogel { 307461ae650dSJack F Vogel struct ixl_vsi *vsi = que->vsi; 307561ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 307661ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 307761ae650dSJack F Vogel u16 tx_itr; 307861ae650dSJack F Vogel u16 tx_latency = 0; 307961ae650dSJack F Vogel int tx_bytes; 308061ae650dSJack F Vogel 308161ae650dSJack F Vogel 308261ae650dSJack F Vogel /* Idle, do nothing */ 308361ae650dSJack F Vogel if (txr->bytes == 0) 308461ae650dSJack F Vogel return; 308561ae650dSJack F Vogel 308661ae650dSJack F Vogel if (ixl_dynamic_tx_itr) { 308761ae650dSJack F Vogel tx_bytes = txr->bytes/txr->itr; 308861ae650dSJack F Vogel tx_itr = txr->itr; 308961ae650dSJack F Vogel 309061ae650dSJack F Vogel switch (txr->latency) { 309161ae650dSJack F Vogel case IXL_LOW_LATENCY: 309261ae650dSJack F Vogel if (tx_bytes > 10) { 309361ae650dSJack F Vogel tx_latency = IXL_AVE_LATENCY; 309461ae650dSJack F Vogel tx_itr = IXL_ITR_20K; 309561ae650dSJack F Vogel } 309661ae650dSJack F Vogel break; 309761ae650dSJack F Vogel case IXL_AVE_LATENCY: 309861ae650dSJack F Vogel if (tx_bytes > 20) { 309961ae650dSJack F Vogel tx_latency = IXL_BULK_LATENCY; 310061ae650dSJack F Vogel tx_itr = IXL_ITR_8K; 310161ae650dSJack F Vogel } else if (tx_bytes <= 10) { 310261ae650dSJack F Vogel tx_latency = IXL_LOW_LATENCY; 310361ae650dSJack F Vogel tx_itr = IXL_ITR_100K; 310461ae650dSJack F Vogel } 310561ae650dSJack F Vogel break; 310661ae650dSJack F Vogel case IXL_BULK_LATENCY: 310761ae650dSJack F Vogel if (tx_bytes <= 20) { 310861ae650dSJack F Vogel tx_latency = IXL_AVE_LATENCY; 310961ae650dSJack F Vogel tx_itr = IXL_ITR_20K; 311061ae650dSJack F Vogel } 311161ae650dSJack F Vogel break; 311261ae650dSJack F Vogel } 311361ae650dSJack F Vogel 311461ae650dSJack F Vogel txr->latency = tx_latency; 311561ae650dSJack F Vogel 311661ae650dSJack F Vogel if (tx_itr != txr->itr) { 311761ae650dSJack F Vogel /* do an exponential smoothing */ 311861ae650dSJack F Vogel tx_itr = (10 * tx_itr * txr->itr) / 311961ae650dSJack F Vogel ((9 * tx_itr) + txr->itr); 312061ae650dSJack F Vogel txr->itr = tx_itr & IXL_MAX_ITR; 312161ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITRN(IXL_TX_ITR, 312261ae650dSJack F Vogel que->me), txr->itr); 312361ae650dSJack F Vogel } 312461ae650dSJack F Vogel 312561ae650dSJack F Vogel } else { /* We may have have toggled to non-dynamic */ 312661ae650dSJack F Vogel if (vsi->tx_itr_setting & IXL_ITR_DYNAMIC) 312761ae650dSJack F Vogel vsi->tx_itr_setting = ixl_tx_itr; 312861ae650dSJack F Vogel /* Update the hardware if needed */ 312961ae650dSJack F Vogel if (txr->itr != vsi->tx_itr_setting) { 313061ae650dSJack F Vogel txr->itr = vsi->tx_itr_setting; 313161ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITRN(IXL_TX_ITR, 313261ae650dSJack F Vogel que->me), txr->itr); 313361ae650dSJack F Vogel } 313461ae650dSJack F Vogel } 313561ae650dSJack F Vogel txr->bytes = 0; 313661ae650dSJack F Vogel txr->packets = 0; 313761ae650dSJack F Vogel return; 313861ae650dSJack F Vogel } 313961ae650dSJack F Vogel 314056c2c47bSJack F Vogel #define QUEUE_NAME_LEN 32 314156c2c47bSJack F Vogel 314256c2c47bSJack F Vogel static void 314356c2c47bSJack F Vogel ixl_add_vsi_sysctls(struct ixl_pf *pf, struct ixl_vsi *vsi, 314456c2c47bSJack F Vogel struct sysctl_ctx_list *ctx, const char *sysctl_name) 314556c2c47bSJack F Vogel { 314656c2c47bSJack F Vogel struct sysctl_oid *tree; 314756c2c47bSJack F Vogel struct sysctl_oid_list *child; 314856c2c47bSJack F Vogel struct sysctl_oid_list *vsi_list; 314956c2c47bSJack F Vogel 315056c2c47bSJack F Vogel tree = device_get_sysctl_tree(pf->dev); 315156c2c47bSJack F Vogel child = SYSCTL_CHILDREN(tree); 315256c2c47bSJack F Vogel vsi->vsi_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, sysctl_name, 315356c2c47bSJack F Vogel CTLFLAG_RD, NULL, "VSI Number"); 315456c2c47bSJack F Vogel vsi_list = SYSCTL_CHILDREN(vsi->vsi_node); 315556c2c47bSJack F Vogel 315656c2c47bSJack F Vogel ixl_add_sysctls_eth_stats(ctx, vsi_list, &vsi->eth_stats); 315756c2c47bSJack F Vogel } 315861ae650dSJack F Vogel 315961ae650dSJack F Vogel static void 316061ae650dSJack F Vogel ixl_add_hw_stats(struct ixl_pf *pf) 316161ae650dSJack F Vogel { 316261ae650dSJack F Vogel device_t dev = pf->dev; 316361ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 316461ae650dSJack F Vogel struct ixl_queue *queues = vsi->queues; 316561ae650dSJack F Vogel struct i40e_hw_port_stats *pf_stats = &pf->stats; 316661ae650dSJack F Vogel 316761ae650dSJack F Vogel struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(dev); 316861ae650dSJack F Vogel struct sysctl_oid *tree = device_get_sysctl_tree(dev); 316961ae650dSJack F Vogel struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree); 317056c2c47bSJack F Vogel struct sysctl_oid_list *vsi_list; 317161ae650dSJack F Vogel 317256c2c47bSJack F Vogel struct sysctl_oid *queue_node; 317356c2c47bSJack F Vogel struct sysctl_oid_list *queue_list; 317461ae650dSJack F Vogel 317561ae650dSJack F Vogel struct tx_ring *txr; 317661ae650dSJack F Vogel struct rx_ring *rxr; 317756c2c47bSJack F Vogel char queue_namebuf[QUEUE_NAME_LEN]; 317861ae650dSJack F Vogel 317961ae650dSJack F Vogel /* Driver statistics */ 318061ae650dSJack F Vogel SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "watchdog_events", 318161ae650dSJack F Vogel CTLFLAG_RD, &pf->watchdog_events, 318261ae650dSJack F Vogel "Watchdog timeouts"); 318361ae650dSJack F Vogel SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "admin_irq", 318461ae650dSJack F Vogel CTLFLAG_RD, &pf->admin_irq, 318561ae650dSJack F Vogel "Admin Queue IRQ Handled"); 318661ae650dSJack F Vogel 318756c2c47bSJack F Vogel SYSCTL_ADD_INT(ctx, child, OID_AUTO, "vc_debug_level", 318856c2c47bSJack F Vogel CTLFLAG_RW, &pf->vc_debug_lvl, 0, 318956c2c47bSJack F Vogel "PF/VF Virtual Channel debug logging level"); 319061ae650dSJack F Vogel 319156c2c47bSJack F Vogel ixl_add_vsi_sysctls(pf, &pf->vsi, ctx, "pf"); 319256c2c47bSJack F Vogel vsi_list = SYSCTL_CHILDREN(pf->vsi.vsi_node); 319361ae650dSJack F Vogel 319461ae650dSJack F Vogel /* Queue statistics */ 319561ae650dSJack F Vogel for (int q = 0; q < vsi->num_queues; q++) { 319661ae650dSJack F Vogel snprintf(queue_namebuf, QUEUE_NAME_LEN, "que%d", q); 319756c2c47bSJack F Vogel queue_node = SYSCTL_ADD_NODE(ctx, vsi_list, 319856c2c47bSJack F Vogel OID_AUTO, queue_namebuf, CTLFLAG_RD, NULL, "Queue #"); 319961ae650dSJack F Vogel queue_list = SYSCTL_CHILDREN(queue_node); 320061ae650dSJack F Vogel 320161ae650dSJack F Vogel txr = &(queues[q].txr); 320261ae650dSJack F Vogel rxr = &(queues[q].rxr); 320361ae650dSJack F Vogel 320461ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "mbuf_defrag_failed", 320561ae650dSJack F Vogel CTLFLAG_RD, &(queues[q].mbuf_defrag_failed), 320661ae650dSJack F Vogel "m_defrag() failed"); 320761ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "dropped", 320861ae650dSJack F Vogel CTLFLAG_RD, &(queues[q].dropped_pkts), 320961ae650dSJack F Vogel "Driver dropped packets"); 321061ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "irqs", 321161ae650dSJack F Vogel CTLFLAG_RD, &(queues[q].irqs), 321261ae650dSJack F Vogel "irqs on this queue"); 321361ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tso_tx", 321461ae650dSJack F Vogel CTLFLAG_RD, &(queues[q].tso), 321561ae650dSJack F Vogel "TSO"); 321661ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tx_dma_setup", 321761ae650dSJack F Vogel CTLFLAG_RD, &(queues[q].tx_dma_setup), 321861ae650dSJack F Vogel "Driver tx dma failure in xmit"); 321961ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "no_desc_avail", 322061ae650dSJack F Vogel CTLFLAG_RD, &(txr->no_desc), 322161ae650dSJack F Vogel "Queue No Descriptor Available"); 322261ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tx_packets", 322361ae650dSJack F Vogel CTLFLAG_RD, &(txr->total_packets), 322461ae650dSJack F Vogel "Queue Packets Transmitted"); 322561ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tx_bytes", 322661ae650dSJack F Vogel CTLFLAG_RD, &(txr->tx_bytes), 322761ae650dSJack F Vogel "Queue Bytes Transmitted"); 322861ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_packets", 322961ae650dSJack F Vogel CTLFLAG_RD, &(rxr->rx_packets), 323061ae650dSJack F Vogel "Queue Packets Received"); 323161ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_bytes", 323261ae650dSJack F Vogel CTLFLAG_RD, &(rxr->rx_bytes), 323361ae650dSJack F Vogel "Queue Bytes Received"); 323461ae650dSJack F Vogel } 323561ae650dSJack F Vogel 323661ae650dSJack F Vogel /* MAC stats */ 323761ae650dSJack F Vogel ixl_add_sysctls_mac_stats(ctx, child, pf_stats); 323861ae650dSJack F Vogel } 323961ae650dSJack F Vogel 324061ae650dSJack F Vogel static void 324161ae650dSJack F Vogel ixl_add_sysctls_eth_stats(struct sysctl_ctx_list *ctx, 324261ae650dSJack F Vogel struct sysctl_oid_list *child, 324361ae650dSJack F Vogel struct i40e_eth_stats *eth_stats) 324461ae650dSJack F Vogel { 324561ae650dSJack F Vogel struct ixl_sysctl_info ctls[] = 324661ae650dSJack F Vogel { 324761ae650dSJack F Vogel {ð_stats->rx_bytes, "good_octets_rcvd", "Good Octets Received"}, 324861ae650dSJack F Vogel {ð_stats->rx_unicast, "ucast_pkts_rcvd", 324961ae650dSJack F Vogel "Unicast Packets Received"}, 325061ae650dSJack F Vogel {ð_stats->rx_multicast, "mcast_pkts_rcvd", 325161ae650dSJack F Vogel "Multicast Packets Received"}, 325261ae650dSJack F Vogel {ð_stats->rx_broadcast, "bcast_pkts_rcvd", 325361ae650dSJack F Vogel "Broadcast Packets Received"}, 325461ae650dSJack F Vogel {ð_stats->rx_discards, "rx_discards", "Discarded RX packets"}, 325561ae650dSJack F Vogel {ð_stats->tx_bytes, "good_octets_txd", "Good Octets Transmitted"}, 325661ae650dSJack F Vogel {ð_stats->tx_unicast, "ucast_pkts_txd", "Unicast Packets Transmitted"}, 325761ae650dSJack F Vogel {ð_stats->tx_multicast, "mcast_pkts_txd", 325861ae650dSJack F Vogel "Multicast Packets Transmitted"}, 325961ae650dSJack F Vogel {ð_stats->tx_broadcast, "bcast_pkts_txd", 326061ae650dSJack F Vogel "Broadcast Packets Transmitted"}, 326161ae650dSJack F Vogel // end 326261ae650dSJack F Vogel {0,0,0} 326361ae650dSJack F Vogel }; 326461ae650dSJack F Vogel 326561ae650dSJack F Vogel struct ixl_sysctl_info *entry = ctls; 326661ae650dSJack F Vogel while (entry->stat != 0) 326761ae650dSJack F Vogel { 326861ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, child, OID_AUTO, entry->name, 326961ae650dSJack F Vogel CTLFLAG_RD, entry->stat, 327061ae650dSJack F Vogel entry->description); 327161ae650dSJack F Vogel entry++; 327261ae650dSJack F Vogel } 327361ae650dSJack F Vogel } 327461ae650dSJack F Vogel 327561ae650dSJack F Vogel static void 327661ae650dSJack F Vogel ixl_add_sysctls_mac_stats(struct sysctl_ctx_list *ctx, 327761ae650dSJack F Vogel struct sysctl_oid_list *child, 327861ae650dSJack F Vogel struct i40e_hw_port_stats *stats) 327961ae650dSJack F Vogel { 328061ae650dSJack F Vogel struct sysctl_oid *stat_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "mac", 328161ae650dSJack F Vogel CTLFLAG_RD, NULL, "Mac Statistics"); 328261ae650dSJack F Vogel struct sysctl_oid_list *stat_list = SYSCTL_CHILDREN(stat_node); 328361ae650dSJack F Vogel 328461ae650dSJack F Vogel struct i40e_eth_stats *eth_stats = &stats->eth; 328561ae650dSJack F Vogel ixl_add_sysctls_eth_stats(ctx, stat_list, eth_stats); 328661ae650dSJack F Vogel 328761ae650dSJack F Vogel struct ixl_sysctl_info ctls[] = 328861ae650dSJack F Vogel { 328961ae650dSJack F Vogel {&stats->crc_errors, "crc_errors", "CRC Errors"}, 329061ae650dSJack F Vogel {&stats->illegal_bytes, "illegal_bytes", "Illegal Byte Errors"}, 329161ae650dSJack F Vogel {&stats->mac_local_faults, "local_faults", "MAC Local Faults"}, 329261ae650dSJack F Vogel {&stats->mac_remote_faults, "remote_faults", "MAC Remote Faults"}, 329361ae650dSJack F Vogel {&stats->rx_length_errors, "rx_length_errors", "Receive Length Errors"}, 329461ae650dSJack F Vogel /* Packet Reception Stats */ 329561ae650dSJack F Vogel {&stats->rx_size_64, "rx_frames_64", "64 byte frames received"}, 329661ae650dSJack F Vogel {&stats->rx_size_127, "rx_frames_65_127", "65-127 byte frames received"}, 329761ae650dSJack F Vogel {&stats->rx_size_255, "rx_frames_128_255", "128-255 byte frames received"}, 329861ae650dSJack F Vogel {&stats->rx_size_511, "rx_frames_256_511", "256-511 byte frames received"}, 329961ae650dSJack F Vogel {&stats->rx_size_1023, "rx_frames_512_1023", "512-1023 byte frames received"}, 330061ae650dSJack F Vogel {&stats->rx_size_1522, "rx_frames_1024_1522", "1024-1522 byte frames received"}, 330161ae650dSJack F Vogel {&stats->rx_size_big, "rx_frames_big", "1523-9522 byte frames received"}, 330261ae650dSJack F Vogel {&stats->rx_undersize, "rx_undersize", "Undersized packets received"}, 330361ae650dSJack F Vogel {&stats->rx_fragments, "rx_fragmented", "Fragmented packets received"}, 330461ae650dSJack F Vogel {&stats->rx_oversize, "rx_oversized", "Oversized packets received"}, 330561ae650dSJack F Vogel {&stats->rx_jabber, "rx_jabber", "Received Jabber"}, 330661ae650dSJack F Vogel {&stats->checksum_error, "checksum_errors", "Checksum Errors"}, 330761ae650dSJack F Vogel /* Packet Transmission Stats */ 330861ae650dSJack F Vogel {&stats->tx_size_64, "tx_frames_64", "64 byte frames transmitted"}, 330961ae650dSJack F Vogel {&stats->tx_size_127, "tx_frames_65_127", "65-127 byte frames transmitted"}, 331061ae650dSJack F Vogel {&stats->tx_size_255, "tx_frames_128_255", "128-255 byte frames transmitted"}, 331161ae650dSJack F Vogel {&stats->tx_size_511, "tx_frames_256_511", "256-511 byte frames transmitted"}, 331261ae650dSJack F Vogel {&stats->tx_size_1023, "tx_frames_512_1023", "512-1023 byte frames transmitted"}, 331361ae650dSJack F Vogel {&stats->tx_size_1522, "tx_frames_1024_1522", "1024-1522 byte frames transmitted"}, 331461ae650dSJack F Vogel {&stats->tx_size_big, "tx_frames_big", "1523-9522 byte frames transmitted"}, 331561ae650dSJack F Vogel /* Flow control */ 331661ae650dSJack F Vogel {&stats->link_xon_tx, "xon_txd", "Link XON transmitted"}, 331761ae650dSJack F Vogel {&stats->link_xon_rx, "xon_recvd", "Link XON received"}, 331861ae650dSJack F Vogel {&stats->link_xoff_tx, "xoff_txd", "Link XOFF transmitted"}, 331961ae650dSJack F Vogel {&stats->link_xoff_rx, "xoff_recvd", "Link XOFF received"}, 332061ae650dSJack F Vogel /* End */ 332161ae650dSJack F Vogel {0,0,0} 332261ae650dSJack F Vogel }; 332361ae650dSJack F Vogel 332461ae650dSJack F Vogel struct ixl_sysctl_info *entry = ctls; 332561ae650dSJack F Vogel while (entry->stat != 0) 332661ae650dSJack F Vogel { 332761ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, entry->name, 332861ae650dSJack F Vogel CTLFLAG_RD, entry->stat, 332961ae650dSJack F Vogel entry->description); 333061ae650dSJack F Vogel entry++; 333161ae650dSJack F Vogel } 333261ae650dSJack F Vogel } 333361ae650dSJack F Vogel 333461ae650dSJack F Vogel /* 333561ae650dSJack F Vogel ** ixl_config_rss - setup RSS 333661ae650dSJack F Vogel ** - note this is done for the single vsi 333761ae650dSJack F Vogel */ 333861ae650dSJack F Vogel static void ixl_config_rss(struct ixl_vsi *vsi) 333961ae650dSJack F Vogel { 334061ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)vsi->back; 334161ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 334261ae650dSJack F Vogel u32 lut = 0; 3343393c4bb1SJack F Vogel u64 set_hena = 0, hena; 3344393c4bb1SJack F Vogel int i, j, que_id; 3345393c4bb1SJack F Vogel #ifdef RSS 3346393c4bb1SJack F Vogel u32 rss_hash_config; 3347393c4bb1SJack F Vogel u32 rss_seed[IXL_KEYSZ]; 3348393c4bb1SJack F Vogel #else 3349393c4bb1SJack F Vogel u32 rss_seed[IXL_KEYSZ] = {0x41b01687, 3350393c4bb1SJack F Vogel 0x183cfd8c, 0xce880440, 0x580cbc3c, 3351393c4bb1SJack F Vogel 0x35897377, 0x328b25e1, 0x4fa98922, 3352393c4bb1SJack F Vogel 0xb7d90c14, 0xd5bad70d, 0xcd15a2c1}; 3353393c4bb1SJack F Vogel #endif 335461ae650dSJack F Vogel 3355393c4bb1SJack F Vogel #ifdef RSS 3356393c4bb1SJack F Vogel /* Fetch the configured RSS key */ 3357393c4bb1SJack F Vogel rss_getkey((uint8_t *) &rss_seed); 3358393c4bb1SJack F Vogel #endif 335961ae650dSJack F Vogel 336061ae650dSJack F Vogel /* Fill out hash function seed */ 3361393c4bb1SJack F Vogel for (i = 0; i < IXL_KEYSZ; i++) 3362393c4bb1SJack F Vogel wr32(hw, I40E_PFQF_HKEY(i), rss_seed[i]); 336361ae650dSJack F Vogel 336461ae650dSJack F Vogel /* Enable PCTYPES for RSS: */ 3365393c4bb1SJack F Vogel #ifdef RSS 3366393c4bb1SJack F Vogel rss_hash_config = rss_gethashconfig(); 3367393c4bb1SJack F Vogel if (rss_hash_config & RSS_HASHTYPE_RSS_IPV4) 3368393c4bb1SJack F Vogel set_hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER); 3369393c4bb1SJack F Vogel if (rss_hash_config & RSS_HASHTYPE_RSS_TCP_IPV4) 3370393c4bb1SJack F Vogel set_hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP); 3371393c4bb1SJack F Vogel if (rss_hash_config & RSS_HASHTYPE_RSS_UDP_IPV4) 3372393c4bb1SJack F Vogel set_hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP); 3373393c4bb1SJack F Vogel if (rss_hash_config & RSS_HASHTYPE_RSS_IPV6) 3374393c4bb1SJack F Vogel set_hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER); 3375df1d7a71SJack F Vogel if (rss_hash_config & RSS_HASHTYPE_RSS_IPV6_EX) 3376df1d7a71SJack F Vogel set_hena |= ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6); 3377393c4bb1SJack F Vogel if (rss_hash_config & RSS_HASHTYPE_RSS_TCP_IPV6) 3378393c4bb1SJack F Vogel set_hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP); 3379393c4bb1SJack F Vogel if (rss_hash_config & RSS_HASHTYPE_RSS_UDP_IPV6) 3380393c4bb1SJack F Vogel set_hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP); 3381393c4bb1SJack F Vogel #else 338261ae650dSJack F Vogel set_hena = 338361ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | 338461ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP) | 338561ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) | 338661ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | 338761ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4) | 338861ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | 338961ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP) | 339061ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) | 339161ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | 339261ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6) | 339361ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_L2_PAYLOAD); 3394393c4bb1SJack F Vogel #endif 339561ae650dSJack F Vogel hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) | 339661ae650dSJack F Vogel ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32); 339761ae650dSJack F Vogel hena |= set_hena; 339861ae650dSJack F Vogel wr32(hw, I40E_PFQF_HENA(0), (u32)hena); 339961ae650dSJack F Vogel wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); 340061ae650dSJack F Vogel 340161ae650dSJack F Vogel /* Populate the LUT with max no. of queues in round robin fashion */ 340261ae650dSJack F Vogel for (i = j = 0; i < pf->hw.func_caps.rss_table_size; i++, j++) { 340361ae650dSJack F Vogel if (j == vsi->num_queues) 340461ae650dSJack F Vogel j = 0; 3405393c4bb1SJack F Vogel #ifdef RSS 3406393c4bb1SJack F Vogel /* 3407393c4bb1SJack F Vogel * Fetch the RSS bucket id for the given indirection entry. 3408393c4bb1SJack F Vogel * Cap it at the number of configured buckets (which is 3409393c4bb1SJack F Vogel * num_queues.) 3410393c4bb1SJack F Vogel */ 3411393c4bb1SJack F Vogel que_id = rss_get_indirection_to_bucket(i); 3412dcd7b3b2SJack F Vogel que_id = que_id % vsi->num_queues; 3413393c4bb1SJack F Vogel #else 3414393c4bb1SJack F Vogel que_id = j; 3415393c4bb1SJack F Vogel #endif 341661ae650dSJack F Vogel /* lut = 4-byte sliding window of 4 lut entries */ 3417393c4bb1SJack F Vogel lut = (lut << 8) | (que_id & 341861ae650dSJack F Vogel ((0x1 << pf->hw.func_caps.rss_table_entry_width) - 1)); 341961ae650dSJack F Vogel /* On i = 3, we have 4 entries in lut; write to the register */ 342061ae650dSJack F Vogel if ((i & 3) == 3) 342161ae650dSJack F Vogel wr32(hw, I40E_PFQF_HLUT(i >> 2), lut); 342261ae650dSJack F Vogel } 342361ae650dSJack F Vogel ixl_flush(hw); 342461ae650dSJack F Vogel } 342561ae650dSJack F Vogel 342661ae650dSJack F Vogel 342761ae650dSJack F Vogel /* 342861ae650dSJack F Vogel ** This routine is run via an vlan config EVENT, 342961ae650dSJack F Vogel ** it enables us to use the HW Filter table since 343061ae650dSJack F Vogel ** we can get the vlan id. This just creates the 343161ae650dSJack F Vogel ** entry in the soft version of the VFTA, init will 343261ae650dSJack F Vogel ** repopulate the real table. 343361ae650dSJack F Vogel */ 343461ae650dSJack F Vogel static void 343561ae650dSJack F Vogel ixl_register_vlan(void *arg, struct ifnet *ifp, u16 vtag) 343661ae650dSJack F Vogel { 343761ae650dSJack F Vogel struct ixl_vsi *vsi = ifp->if_softc; 343861ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 343961ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)vsi->back; 344061ae650dSJack F Vogel 344161ae650dSJack F Vogel if (ifp->if_softc != arg) /* Not our event */ 344261ae650dSJack F Vogel return; 344361ae650dSJack F Vogel 344461ae650dSJack F Vogel if ((vtag == 0) || (vtag > 4095)) /* Invalid */ 344561ae650dSJack F Vogel return; 344661ae650dSJack F Vogel 344761ae650dSJack F Vogel IXL_PF_LOCK(pf); 344861ae650dSJack F Vogel ++vsi->num_vlans; 344961ae650dSJack F Vogel ixl_add_filter(vsi, hw->mac.addr, vtag); 345061ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 345161ae650dSJack F Vogel } 345261ae650dSJack F Vogel 345361ae650dSJack F Vogel /* 345461ae650dSJack F Vogel ** This routine is run via an vlan 345561ae650dSJack F Vogel ** unconfig EVENT, remove our entry 345661ae650dSJack F Vogel ** in the soft vfta. 345761ae650dSJack F Vogel */ 345861ae650dSJack F Vogel static void 345961ae650dSJack F Vogel ixl_unregister_vlan(void *arg, struct ifnet *ifp, u16 vtag) 346061ae650dSJack F Vogel { 346161ae650dSJack F Vogel struct ixl_vsi *vsi = ifp->if_softc; 346261ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 346361ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)vsi->back; 346461ae650dSJack F Vogel 346561ae650dSJack F Vogel if (ifp->if_softc != arg) 346661ae650dSJack F Vogel return; 346761ae650dSJack F Vogel 346861ae650dSJack F Vogel if ((vtag == 0) || (vtag > 4095)) /* Invalid */ 346961ae650dSJack F Vogel return; 347061ae650dSJack F Vogel 347161ae650dSJack F Vogel IXL_PF_LOCK(pf); 347261ae650dSJack F Vogel --vsi->num_vlans; 347361ae650dSJack F Vogel ixl_del_filter(vsi, hw->mac.addr, vtag); 347461ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 347561ae650dSJack F Vogel } 347661ae650dSJack F Vogel 347761ae650dSJack F Vogel /* 347861ae650dSJack F Vogel ** This routine updates vlan filters, called by init 347961ae650dSJack F Vogel ** it scans the filter table and then updates the hw 348061ae650dSJack F Vogel ** after a soft reset. 348161ae650dSJack F Vogel */ 348261ae650dSJack F Vogel static void 348361ae650dSJack F Vogel ixl_setup_vlan_filters(struct ixl_vsi *vsi) 348461ae650dSJack F Vogel { 348561ae650dSJack F Vogel struct ixl_mac_filter *f; 348661ae650dSJack F Vogel int cnt = 0, flags; 348761ae650dSJack F Vogel 348861ae650dSJack F Vogel if (vsi->num_vlans == 0) 348961ae650dSJack F Vogel return; 349061ae650dSJack F Vogel /* 349161ae650dSJack F Vogel ** Scan the filter list for vlan entries, 349261ae650dSJack F Vogel ** mark them for addition and then call 349361ae650dSJack F Vogel ** for the AQ update. 349461ae650dSJack F Vogel */ 349561ae650dSJack F Vogel SLIST_FOREACH(f, &vsi->ftl, next) { 349661ae650dSJack F Vogel if (f->flags & IXL_FILTER_VLAN) { 349761ae650dSJack F Vogel f->flags |= 349861ae650dSJack F Vogel (IXL_FILTER_ADD | 349961ae650dSJack F Vogel IXL_FILTER_USED); 350061ae650dSJack F Vogel cnt++; 350161ae650dSJack F Vogel } 350261ae650dSJack F Vogel } 350361ae650dSJack F Vogel if (cnt == 0) { 350461ae650dSJack F Vogel printf("setup vlan: no filters found!\n"); 350561ae650dSJack F Vogel return; 350661ae650dSJack F Vogel } 350761ae650dSJack F Vogel flags = IXL_FILTER_VLAN; 350861ae650dSJack F Vogel flags |= (IXL_FILTER_ADD | IXL_FILTER_USED); 350961ae650dSJack F Vogel ixl_add_hw_filters(vsi, flags, cnt); 351061ae650dSJack F Vogel return; 351161ae650dSJack F Vogel } 351261ae650dSJack F Vogel 351361ae650dSJack F Vogel /* 351461ae650dSJack F Vogel ** Initialize filter list and add filters that the hardware 351561ae650dSJack F Vogel ** needs to know about. 351661ae650dSJack F Vogel */ 351761ae650dSJack F Vogel static void 351861ae650dSJack F Vogel ixl_init_filters(struct ixl_vsi *vsi) 351961ae650dSJack F Vogel { 352061ae650dSJack F Vogel /* Add broadcast address */ 352156c2c47bSJack F Vogel ixl_add_filter(vsi, ixl_bcast_addr, IXL_VLAN_ANY); 352261ae650dSJack F Vogel } 352361ae650dSJack F Vogel 352461ae650dSJack F Vogel /* 352561ae650dSJack F Vogel ** This routine adds mulicast filters 352661ae650dSJack F Vogel */ 352761ae650dSJack F Vogel static void 352861ae650dSJack F Vogel ixl_add_mc_filter(struct ixl_vsi *vsi, u8 *macaddr) 352961ae650dSJack F Vogel { 353061ae650dSJack F Vogel struct ixl_mac_filter *f; 353161ae650dSJack F Vogel 353261ae650dSJack F Vogel /* Does one already exist */ 353361ae650dSJack F Vogel f = ixl_find_filter(vsi, macaddr, IXL_VLAN_ANY); 353461ae650dSJack F Vogel if (f != NULL) 353561ae650dSJack F Vogel return; 353661ae650dSJack F Vogel 353761ae650dSJack F Vogel f = ixl_get_filter(vsi); 353861ae650dSJack F Vogel if (f == NULL) { 353961ae650dSJack F Vogel printf("WARNING: no filter available!!\n"); 354061ae650dSJack F Vogel return; 354161ae650dSJack F Vogel } 354261ae650dSJack F Vogel bcopy(macaddr, f->macaddr, ETHER_ADDR_LEN); 354361ae650dSJack F Vogel f->vlan = IXL_VLAN_ANY; 354461ae650dSJack F Vogel f->flags |= (IXL_FILTER_ADD | IXL_FILTER_USED 354561ae650dSJack F Vogel | IXL_FILTER_MC); 354661ae650dSJack F Vogel 354761ae650dSJack F Vogel return; 354861ae650dSJack F Vogel } 354961ae650dSJack F Vogel 355056c2c47bSJack F Vogel static void 355156c2c47bSJack F Vogel ixl_reconfigure_filters(struct ixl_vsi *vsi) 355256c2c47bSJack F Vogel { 355356c2c47bSJack F Vogel 355456c2c47bSJack F Vogel ixl_add_hw_filters(vsi, IXL_FILTER_USED, vsi->num_macs); 355556c2c47bSJack F Vogel } 355656c2c47bSJack F Vogel 355761ae650dSJack F Vogel /* 355861ae650dSJack F Vogel ** This routine adds macvlan filters 355961ae650dSJack F Vogel */ 356061ae650dSJack F Vogel static void 356161ae650dSJack F Vogel ixl_add_filter(struct ixl_vsi *vsi, u8 *macaddr, s16 vlan) 356261ae650dSJack F Vogel { 356361ae650dSJack F Vogel struct ixl_mac_filter *f, *tmp; 356456c2c47bSJack F Vogel struct ixl_pf *pf; 356556c2c47bSJack F Vogel device_t dev; 356661ae650dSJack F Vogel 356761ae650dSJack F Vogel DEBUGOUT("ixl_add_filter: begin"); 356861ae650dSJack F Vogel 356956c2c47bSJack F Vogel pf = vsi->back; 357056c2c47bSJack F Vogel dev = pf->dev; 357156c2c47bSJack F Vogel 357261ae650dSJack F Vogel /* Does one already exist */ 357361ae650dSJack F Vogel f = ixl_find_filter(vsi, macaddr, vlan); 357461ae650dSJack F Vogel if (f != NULL) 357561ae650dSJack F Vogel return; 357661ae650dSJack F Vogel /* 357761ae650dSJack F Vogel ** Is this the first vlan being registered, if so we 357861ae650dSJack F Vogel ** need to remove the ANY filter that indicates we are 357961ae650dSJack F Vogel ** not in a vlan, and replace that with a 0 filter. 358061ae650dSJack F Vogel */ 358161ae650dSJack F Vogel if ((vlan != IXL_VLAN_ANY) && (vsi->num_vlans == 1)) { 358261ae650dSJack F Vogel tmp = ixl_find_filter(vsi, macaddr, IXL_VLAN_ANY); 358361ae650dSJack F Vogel if (tmp != NULL) { 358461ae650dSJack F Vogel ixl_del_filter(vsi, macaddr, IXL_VLAN_ANY); 358561ae650dSJack F Vogel ixl_add_filter(vsi, macaddr, 0); 358661ae650dSJack F Vogel } 358761ae650dSJack F Vogel } 358861ae650dSJack F Vogel 358961ae650dSJack F Vogel f = ixl_get_filter(vsi); 359061ae650dSJack F Vogel if (f == NULL) { 359161ae650dSJack F Vogel device_printf(dev, "WARNING: no filter available!!\n"); 359261ae650dSJack F Vogel return; 359361ae650dSJack F Vogel } 359461ae650dSJack F Vogel bcopy(macaddr, f->macaddr, ETHER_ADDR_LEN); 359561ae650dSJack F Vogel f->vlan = vlan; 359661ae650dSJack F Vogel f->flags |= (IXL_FILTER_ADD | IXL_FILTER_USED); 359761ae650dSJack F Vogel if (f->vlan != IXL_VLAN_ANY) 359861ae650dSJack F Vogel f->flags |= IXL_FILTER_VLAN; 359956c2c47bSJack F Vogel else 360056c2c47bSJack F Vogel vsi->num_macs++; 360161ae650dSJack F Vogel 360261ae650dSJack F Vogel ixl_add_hw_filters(vsi, f->flags, 1); 360361ae650dSJack F Vogel return; 360461ae650dSJack F Vogel } 360561ae650dSJack F Vogel 360661ae650dSJack F Vogel static void 360761ae650dSJack F Vogel ixl_del_filter(struct ixl_vsi *vsi, u8 *macaddr, s16 vlan) 360861ae650dSJack F Vogel { 360961ae650dSJack F Vogel struct ixl_mac_filter *f; 361061ae650dSJack F Vogel 361161ae650dSJack F Vogel f = ixl_find_filter(vsi, macaddr, vlan); 361261ae650dSJack F Vogel if (f == NULL) 361361ae650dSJack F Vogel return; 361461ae650dSJack F Vogel 361561ae650dSJack F Vogel f->flags |= IXL_FILTER_DEL; 361661ae650dSJack F Vogel ixl_del_hw_filters(vsi, 1); 361756c2c47bSJack F Vogel vsi->num_macs--; 361861ae650dSJack F Vogel 361961ae650dSJack F Vogel /* Check if this is the last vlan removal */ 362061ae650dSJack F Vogel if (vlan != IXL_VLAN_ANY && vsi->num_vlans == 0) { 362161ae650dSJack F Vogel /* Switch back to a non-vlan filter */ 362261ae650dSJack F Vogel ixl_del_filter(vsi, macaddr, 0); 362361ae650dSJack F Vogel ixl_add_filter(vsi, macaddr, IXL_VLAN_ANY); 362461ae650dSJack F Vogel } 362561ae650dSJack F Vogel return; 362661ae650dSJack F Vogel } 362761ae650dSJack F Vogel 362861ae650dSJack F Vogel /* 362961ae650dSJack F Vogel ** Find the filter with both matching mac addr and vlan id 363061ae650dSJack F Vogel */ 363161ae650dSJack F Vogel static struct ixl_mac_filter * 363261ae650dSJack F Vogel ixl_find_filter(struct ixl_vsi *vsi, u8 *macaddr, s16 vlan) 363361ae650dSJack F Vogel { 363461ae650dSJack F Vogel struct ixl_mac_filter *f; 363561ae650dSJack F Vogel bool match = FALSE; 363661ae650dSJack F Vogel 363761ae650dSJack F Vogel SLIST_FOREACH(f, &vsi->ftl, next) { 363861ae650dSJack F Vogel if (!cmp_etheraddr(f->macaddr, macaddr)) 363961ae650dSJack F Vogel continue; 364061ae650dSJack F Vogel if (f->vlan == vlan) { 364161ae650dSJack F Vogel match = TRUE; 364261ae650dSJack F Vogel break; 364361ae650dSJack F Vogel } 364461ae650dSJack F Vogel } 364561ae650dSJack F Vogel 364661ae650dSJack F Vogel if (!match) 364761ae650dSJack F Vogel f = NULL; 364861ae650dSJack F Vogel return (f); 364961ae650dSJack F Vogel } 365061ae650dSJack F Vogel 365161ae650dSJack F Vogel /* 365261ae650dSJack F Vogel ** This routine takes additions to the vsi filter 365361ae650dSJack F Vogel ** table and creates an Admin Queue call to create 365461ae650dSJack F Vogel ** the filters in the hardware. 365561ae650dSJack F Vogel */ 365661ae650dSJack F Vogel static void 365761ae650dSJack F Vogel ixl_add_hw_filters(struct ixl_vsi *vsi, int flags, int cnt) 365861ae650dSJack F Vogel { 365961ae650dSJack F Vogel struct i40e_aqc_add_macvlan_element_data *a, *b; 366061ae650dSJack F Vogel struct ixl_mac_filter *f; 366156c2c47bSJack F Vogel struct ixl_pf *pf; 366256c2c47bSJack F Vogel struct i40e_hw *hw; 366356c2c47bSJack F Vogel device_t dev; 366461ae650dSJack F Vogel int err, j = 0; 366561ae650dSJack F Vogel 366656c2c47bSJack F Vogel pf = vsi->back; 366756c2c47bSJack F Vogel dev = pf->dev; 366856c2c47bSJack F Vogel hw = &pf->hw; 366956c2c47bSJack F Vogel IXL_PF_LOCK_ASSERT(pf); 367056c2c47bSJack F Vogel 367161ae650dSJack F Vogel a = malloc(sizeof(struct i40e_aqc_add_macvlan_element_data) * cnt, 367261ae650dSJack F Vogel M_DEVBUF, M_NOWAIT | M_ZERO); 367361ae650dSJack F Vogel if (a == NULL) { 3674393c4bb1SJack F Vogel device_printf(dev, "add_hw_filters failed to get memory\n"); 367561ae650dSJack F Vogel return; 367661ae650dSJack F Vogel } 367761ae650dSJack F Vogel 367861ae650dSJack F Vogel /* 367961ae650dSJack F Vogel ** Scan the filter list, each time we find one 368061ae650dSJack F Vogel ** we add it to the admin queue array and turn off 368161ae650dSJack F Vogel ** the add bit. 368261ae650dSJack F Vogel */ 368361ae650dSJack F Vogel SLIST_FOREACH(f, &vsi->ftl, next) { 368461ae650dSJack F Vogel if (f->flags == flags) { 368561ae650dSJack F Vogel b = &a[j]; // a pox on fvl long names :) 368661ae650dSJack F Vogel bcopy(f->macaddr, b->mac_addr, ETHER_ADDR_LEN); 368756c2c47bSJack F Vogel if (f->vlan == IXL_VLAN_ANY) { 368856c2c47bSJack F Vogel b->vlan_tag = 0; 368956c2c47bSJack F Vogel b->flags = I40E_AQC_MACVLAN_ADD_IGNORE_VLAN; 369056c2c47bSJack F Vogel } else { 369156c2c47bSJack F Vogel b->vlan_tag = f->vlan; 369256c2c47bSJack F Vogel b->flags = 0; 369356c2c47bSJack F Vogel } 369456c2c47bSJack F Vogel b->flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; 369561ae650dSJack F Vogel f->flags &= ~IXL_FILTER_ADD; 369661ae650dSJack F Vogel j++; 369761ae650dSJack F Vogel } 369861ae650dSJack F Vogel if (j == cnt) 369961ae650dSJack F Vogel break; 370061ae650dSJack F Vogel } 370161ae650dSJack F Vogel if (j > 0) { 370261ae650dSJack F Vogel err = i40e_aq_add_macvlan(hw, vsi->seid, a, j, NULL); 370361ae650dSJack F Vogel if (err) 3704b6c8f260SJack F Vogel device_printf(dev, "aq_add_macvlan err %d, " 3705b6c8f260SJack F Vogel "aq_error %d\n", err, hw->aq.asq_last_status); 370661ae650dSJack F Vogel else 370761ae650dSJack F Vogel vsi->hw_filters_add += j; 370861ae650dSJack F Vogel } 370961ae650dSJack F Vogel free(a, M_DEVBUF); 371061ae650dSJack F Vogel return; 371161ae650dSJack F Vogel } 371261ae650dSJack F Vogel 371361ae650dSJack F Vogel /* 371461ae650dSJack F Vogel ** This routine takes removals in the vsi filter 371561ae650dSJack F Vogel ** table and creates an Admin Queue call to delete 371661ae650dSJack F Vogel ** the filters in the hardware. 371761ae650dSJack F Vogel */ 371861ae650dSJack F Vogel static void 371961ae650dSJack F Vogel ixl_del_hw_filters(struct ixl_vsi *vsi, int cnt) 372061ae650dSJack F Vogel { 372161ae650dSJack F Vogel struct i40e_aqc_remove_macvlan_element_data *d, *e; 372256c2c47bSJack F Vogel struct ixl_pf *pf; 372356c2c47bSJack F Vogel struct i40e_hw *hw; 372456c2c47bSJack F Vogel device_t dev; 372561ae650dSJack F Vogel struct ixl_mac_filter *f, *f_temp; 372661ae650dSJack F Vogel int err, j = 0; 372761ae650dSJack F Vogel 372861ae650dSJack F Vogel DEBUGOUT("ixl_del_hw_filters: begin\n"); 372961ae650dSJack F Vogel 373056c2c47bSJack F Vogel pf = vsi->back; 373156c2c47bSJack F Vogel hw = &pf->hw; 373256c2c47bSJack F Vogel dev = pf->dev; 373356c2c47bSJack F Vogel 373461ae650dSJack F Vogel d = malloc(sizeof(struct i40e_aqc_remove_macvlan_element_data) * cnt, 373561ae650dSJack F Vogel M_DEVBUF, M_NOWAIT | M_ZERO); 373661ae650dSJack F Vogel if (d == NULL) { 373761ae650dSJack F Vogel printf("del hw filter failed to get memory\n"); 373861ae650dSJack F Vogel return; 373961ae650dSJack F Vogel } 374061ae650dSJack F Vogel 374161ae650dSJack F Vogel SLIST_FOREACH_SAFE(f, &vsi->ftl, next, f_temp) { 374261ae650dSJack F Vogel if (f->flags & IXL_FILTER_DEL) { 374361ae650dSJack F Vogel e = &d[j]; // a pox on fvl long names :) 374461ae650dSJack F Vogel bcopy(f->macaddr, e->mac_addr, ETHER_ADDR_LEN); 374561ae650dSJack F Vogel e->vlan_tag = (f->vlan == IXL_VLAN_ANY ? 0 : f->vlan); 374661ae650dSJack F Vogel e->flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; 374761ae650dSJack F Vogel /* delete entry from vsi list */ 374861ae650dSJack F Vogel SLIST_REMOVE(&vsi->ftl, f, ixl_mac_filter, next); 374961ae650dSJack F Vogel free(f, M_DEVBUF); 375061ae650dSJack F Vogel j++; 375161ae650dSJack F Vogel } 375261ae650dSJack F Vogel if (j == cnt) 375361ae650dSJack F Vogel break; 375461ae650dSJack F Vogel } 375561ae650dSJack F Vogel if (j > 0) { 375661ae650dSJack F Vogel err = i40e_aq_remove_macvlan(hw, vsi->seid, d, j, NULL); 375761ae650dSJack F Vogel /* NOTE: returns ENOENT every time but seems to work fine, 375861ae650dSJack F Vogel so we'll ignore that specific error. */ 3759393c4bb1SJack F Vogel // TODO: Does this still occur on current firmwares? 376061ae650dSJack F Vogel if (err && hw->aq.asq_last_status != I40E_AQ_RC_ENOENT) { 376161ae650dSJack F Vogel int sc = 0; 376261ae650dSJack F Vogel for (int i = 0; i < j; i++) 376361ae650dSJack F Vogel sc += (!d[i].error_code); 376461ae650dSJack F Vogel vsi->hw_filters_del += sc; 376561ae650dSJack F Vogel device_printf(dev, 376661ae650dSJack F Vogel "Failed to remove %d/%d filters, aq error %d\n", 376761ae650dSJack F Vogel j - sc, j, hw->aq.asq_last_status); 376861ae650dSJack F Vogel } else 376961ae650dSJack F Vogel vsi->hw_filters_del += j; 377061ae650dSJack F Vogel } 377161ae650dSJack F Vogel free(d, M_DEVBUF); 377261ae650dSJack F Vogel 377361ae650dSJack F Vogel DEBUGOUT("ixl_del_hw_filters: end\n"); 377461ae650dSJack F Vogel return; 377561ae650dSJack F Vogel } 377661ae650dSJack F Vogel 377756c2c47bSJack F Vogel static int 377861ae650dSJack F Vogel ixl_enable_rings(struct ixl_vsi *vsi) 377961ae650dSJack F Vogel { 378056c2c47bSJack F Vogel struct ixl_pf *pf = vsi->back; 378156c2c47bSJack F Vogel struct i40e_hw *hw = &pf->hw; 378256c2c47bSJack F Vogel int index, error; 378361ae650dSJack F Vogel u32 reg; 378461ae650dSJack F Vogel 378556c2c47bSJack F Vogel error = 0; 378661ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++) { 378756c2c47bSJack F Vogel index = vsi->first_queue + i; 378856c2c47bSJack F Vogel i40e_pre_tx_queue_cfg(hw, index, TRUE); 378961ae650dSJack F Vogel 379056c2c47bSJack F Vogel reg = rd32(hw, I40E_QTX_ENA(index)); 379161ae650dSJack F Vogel reg |= I40E_QTX_ENA_QENA_REQ_MASK | 379261ae650dSJack F Vogel I40E_QTX_ENA_QENA_STAT_MASK; 379356c2c47bSJack F Vogel wr32(hw, I40E_QTX_ENA(index), reg); 379461ae650dSJack F Vogel /* Verify the enable took */ 379561ae650dSJack F Vogel for (int j = 0; j < 10; j++) { 379656c2c47bSJack F Vogel reg = rd32(hw, I40E_QTX_ENA(index)); 379761ae650dSJack F Vogel if (reg & I40E_QTX_ENA_QENA_STAT_MASK) 379861ae650dSJack F Vogel break; 379961ae650dSJack F Vogel i40e_msec_delay(10); 380061ae650dSJack F Vogel } 380156c2c47bSJack F Vogel if ((reg & I40E_QTX_ENA_QENA_STAT_MASK) == 0) { 380256c2c47bSJack F Vogel device_printf(pf->dev, "TX queue %d disabled!\n", 380356c2c47bSJack F Vogel index); 380456c2c47bSJack F Vogel error = ETIMEDOUT; 380556c2c47bSJack F Vogel } 380661ae650dSJack F Vogel 380756c2c47bSJack F Vogel reg = rd32(hw, I40E_QRX_ENA(index)); 380861ae650dSJack F Vogel reg |= I40E_QRX_ENA_QENA_REQ_MASK | 380961ae650dSJack F Vogel I40E_QRX_ENA_QENA_STAT_MASK; 381056c2c47bSJack F Vogel wr32(hw, I40E_QRX_ENA(index), reg); 381161ae650dSJack F Vogel /* Verify the enable took */ 381261ae650dSJack F Vogel for (int j = 0; j < 10; j++) { 381356c2c47bSJack F Vogel reg = rd32(hw, I40E_QRX_ENA(index)); 381461ae650dSJack F Vogel if (reg & I40E_QRX_ENA_QENA_STAT_MASK) 381561ae650dSJack F Vogel break; 381661ae650dSJack F Vogel i40e_msec_delay(10); 381761ae650dSJack F Vogel } 381856c2c47bSJack F Vogel if ((reg & I40E_QRX_ENA_QENA_STAT_MASK) == 0) { 381956c2c47bSJack F Vogel device_printf(pf->dev, "RX queue %d disabled!\n", 382056c2c47bSJack F Vogel index); 382156c2c47bSJack F Vogel error = ETIMEDOUT; 382261ae650dSJack F Vogel } 382361ae650dSJack F Vogel } 382461ae650dSJack F Vogel 382556c2c47bSJack F Vogel return (error); 382656c2c47bSJack F Vogel } 382756c2c47bSJack F Vogel 382856c2c47bSJack F Vogel static int 382961ae650dSJack F Vogel ixl_disable_rings(struct ixl_vsi *vsi) 383061ae650dSJack F Vogel { 383156c2c47bSJack F Vogel struct ixl_pf *pf = vsi->back; 383256c2c47bSJack F Vogel struct i40e_hw *hw = &pf->hw; 383356c2c47bSJack F Vogel int index, error; 383461ae650dSJack F Vogel u32 reg; 383561ae650dSJack F Vogel 383656c2c47bSJack F Vogel error = 0; 383761ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++) { 383856c2c47bSJack F Vogel index = vsi->first_queue + i; 383956c2c47bSJack F Vogel 384056c2c47bSJack F Vogel i40e_pre_tx_queue_cfg(hw, index, FALSE); 384161ae650dSJack F Vogel i40e_usec_delay(500); 384261ae650dSJack F Vogel 384356c2c47bSJack F Vogel reg = rd32(hw, I40E_QTX_ENA(index)); 384461ae650dSJack F Vogel reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; 384556c2c47bSJack F Vogel wr32(hw, I40E_QTX_ENA(index), reg); 384661ae650dSJack F Vogel /* Verify the disable took */ 384761ae650dSJack F Vogel for (int j = 0; j < 10; j++) { 384856c2c47bSJack F Vogel reg = rd32(hw, I40E_QTX_ENA(index)); 384961ae650dSJack F Vogel if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK)) 385061ae650dSJack F Vogel break; 385161ae650dSJack F Vogel i40e_msec_delay(10); 385261ae650dSJack F Vogel } 385356c2c47bSJack F Vogel if (reg & I40E_QTX_ENA_QENA_STAT_MASK) { 385456c2c47bSJack F Vogel device_printf(pf->dev, "TX queue %d still enabled!\n", 385556c2c47bSJack F Vogel index); 385656c2c47bSJack F Vogel error = ETIMEDOUT; 385756c2c47bSJack F Vogel } 385861ae650dSJack F Vogel 385956c2c47bSJack F Vogel reg = rd32(hw, I40E_QRX_ENA(index)); 386061ae650dSJack F Vogel reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; 386156c2c47bSJack F Vogel wr32(hw, I40E_QRX_ENA(index), reg); 386261ae650dSJack F Vogel /* Verify the disable took */ 386361ae650dSJack F Vogel for (int j = 0; j < 10; j++) { 386456c2c47bSJack F Vogel reg = rd32(hw, I40E_QRX_ENA(index)); 386561ae650dSJack F Vogel if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK)) 386661ae650dSJack F Vogel break; 386761ae650dSJack F Vogel i40e_msec_delay(10); 386861ae650dSJack F Vogel } 386956c2c47bSJack F Vogel if (reg & I40E_QRX_ENA_QENA_STAT_MASK) { 387056c2c47bSJack F Vogel device_printf(pf->dev, "RX queue %d still enabled!\n", 387156c2c47bSJack F Vogel index); 387256c2c47bSJack F Vogel error = ETIMEDOUT; 387361ae650dSJack F Vogel } 387461ae650dSJack F Vogel } 387561ae650dSJack F Vogel 387656c2c47bSJack F Vogel return (error); 387756c2c47bSJack F Vogel } 387856c2c47bSJack F Vogel 387961ae650dSJack F Vogel /** 388061ae650dSJack F Vogel * ixl_handle_mdd_event 388161ae650dSJack F Vogel * 388261ae650dSJack F Vogel * Called from interrupt handler to identify possibly malicious vfs 388361ae650dSJack F Vogel * (But also detects events from the PF, as well) 388461ae650dSJack F Vogel **/ 388561ae650dSJack F Vogel static void ixl_handle_mdd_event(struct ixl_pf *pf) 388661ae650dSJack F Vogel { 388761ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 388861ae650dSJack F Vogel device_t dev = pf->dev; 388961ae650dSJack F Vogel bool mdd_detected = false; 389061ae650dSJack F Vogel bool pf_mdd_detected = false; 389161ae650dSJack F Vogel u32 reg; 389261ae650dSJack F Vogel 389361ae650dSJack F Vogel /* find what triggered the MDD event */ 389461ae650dSJack F Vogel reg = rd32(hw, I40E_GL_MDET_TX); 389561ae650dSJack F Vogel if (reg & I40E_GL_MDET_TX_VALID_MASK) { 389661ae650dSJack F Vogel u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> 389761ae650dSJack F Vogel I40E_GL_MDET_TX_PF_NUM_SHIFT; 389861ae650dSJack F Vogel u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> 389961ae650dSJack F Vogel I40E_GL_MDET_TX_EVENT_SHIFT; 390061ae650dSJack F Vogel u8 queue = (reg & I40E_GL_MDET_TX_QUEUE_MASK) >> 390161ae650dSJack F Vogel I40E_GL_MDET_TX_QUEUE_SHIFT; 390261ae650dSJack F Vogel device_printf(dev, 390361ae650dSJack F Vogel "Malicious Driver Detection event 0x%02x" 390461ae650dSJack F Vogel " on TX queue %d pf number 0x%02x\n", 390561ae650dSJack F Vogel event, queue, pf_num); 390661ae650dSJack F Vogel wr32(hw, I40E_GL_MDET_TX, 0xffffffff); 390761ae650dSJack F Vogel mdd_detected = true; 390861ae650dSJack F Vogel } 390961ae650dSJack F Vogel reg = rd32(hw, I40E_GL_MDET_RX); 391061ae650dSJack F Vogel if (reg & I40E_GL_MDET_RX_VALID_MASK) { 391161ae650dSJack F Vogel u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> 391261ae650dSJack F Vogel I40E_GL_MDET_RX_FUNCTION_SHIFT; 391361ae650dSJack F Vogel u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> 391461ae650dSJack F Vogel I40E_GL_MDET_RX_EVENT_SHIFT; 391561ae650dSJack F Vogel u8 queue = (reg & I40E_GL_MDET_RX_QUEUE_MASK) >> 391661ae650dSJack F Vogel I40E_GL_MDET_RX_QUEUE_SHIFT; 391761ae650dSJack F Vogel device_printf(dev, 391861ae650dSJack F Vogel "Malicious Driver Detection event 0x%02x" 391961ae650dSJack F Vogel " on RX queue %d of function 0x%02x\n", 392061ae650dSJack F Vogel event, queue, func); 392161ae650dSJack F Vogel wr32(hw, I40E_GL_MDET_RX, 0xffffffff); 392261ae650dSJack F Vogel mdd_detected = true; 392361ae650dSJack F Vogel } 392461ae650dSJack F Vogel 392561ae650dSJack F Vogel if (mdd_detected) { 392661ae650dSJack F Vogel reg = rd32(hw, I40E_PF_MDET_TX); 392761ae650dSJack F Vogel if (reg & I40E_PF_MDET_TX_VALID_MASK) { 392861ae650dSJack F Vogel wr32(hw, I40E_PF_MDET_TX, 0xFFFF); 392961ae650dSJack F Vogel device_printf(dev, 393061ae650dSJack F Vogel "MDD TX event is for this function 0x%08x", 393161ae650dSJack F Vogel reg); 393261ae650dSJack F Vogel pf_mdd_detected = true; 393361ae650dSJack F Vogel } 393461ae650dSJack F Vogel reg = rd32(hw, I40E_PF_MDET_RX); 393561ae650dSJack F Vogel if (reg & I40E_PF_MDET_RX_VALID_MASK) { 393661ae650dSJack F Vogel wr32(hw, I40E_PF_MDET_RX, 0xFFFF); 393761ae650dSJack F Vogel device_printf(dev, 393861ae650dSJack F Vogel "MDD RX event is for this function 0x%08x", 393961ae650dSJack F Vogel reg); 394061ae650dSJack F Vogel pf_mdd_detected = true; 394161ae650dSJack F Vogel } 394261ae650dSJack F Vogel } 394361ae650dSJack F Vogel 394461ae650dSJack F Vogel /* re-enable mdd interrupt cause */ 394561ae650dSJack F Vogel reg = rd32(hw, I40E_PFINT_ICR0_ENA); 394661ae650dSJack F Vogel reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; 394761ae650dSJack F Vogel wr32(hw, I40E_PFINT_ICR0_ENA, reg); 394861ae650dSJack F Vogel ixl_flush(hw); 394961ae650dSJack F Vogel } 395061ae650dSJack F Vogel 395161ae650dSJack F Vogel static void 395261ae650dSJack F Vogel ixl_enable_intr(struct ixl_vsi *vsi) 395361ae650dSJack F Vogel { 395461ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 395561ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 395661ae650dSJack F Vogel 395761ae650dSJack F Vogel if (ixl_enable_msix) { 395861ae650dSJack F Vogel ixl_enable_adminq(hw); 395961ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, que++) 396061ae650dSJack F Vogel ixl_enable_queue(hw, que->me); 396161ae650dSJack F Vogel } else 396261ae650dSJack F Vogel ixl_enable_legacy(hw); 396361ae650dSJack F Vogel } 396461ae650dSJack F Vogel 396561ae650dSJack F Vogel static void 396656c2c47bSJack F Vogel ixl_disable_rings_intr(struct ixl_vsi *vsi) 396761ae650dSJack F Vogel { 396861ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 396961ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 397061ae650dSJack F Vogel 397161ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, que++) 397261ae650dSJack F Vogel ixl_disable_queue(hw, que->me); 397356c2c47bSJack F Vogel } 397456c2c47bSJack F Vogel 397556c2c47bSJack F Vogel static void 397656c2c47bSJack F Vogel ixl_disable_intr(struct ixl_vsi *vsi) 397756c2c47bSJack F Vogel { 397856c2c47bSJack F Vogel struct i40e_hw *hw = vsi->hw; 397956c2c47bSJack F Vogel 398056c2c47bSJack F Vogel if (ixl_enable_msix) 398156c2c47bSJack F Vogel ixl_disable_adminq(hw); 398256c2c47bSJack F Vogel else 398361ae650dSJack F Vogel ixl_disable_legacy(hw); 398461ae650dSJack F Vogel } 398561ae650dSJack F Vogel 398661ae650dSJack F Vogel static void 398761ae650dSJack F Vogel ixl_enable_adminq(struct i40e_hw *hw) 398861ae650dSJack F Vogel { 398961ae650dSJack F Vogel u32 reg; 399061ae650dSJack F Vogel 399161ae650dSJack F Vogel reg = I40E_PFINT_DYN_CTL0_INTENA_MASK | 399261ae650dSJack F Vogel I40E_PFINT_DYN_CTL0_CLEARPBA_MASK | 399361ae650dSJack F Vogel (IXL_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); 399461ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTL0, reg); 399561ae650dSJack F Vogel ixl_flush(hw); 399661ae650dSJack F Vogel return; 399761ae650dSJack F Vogel } 399861ae650dSJack F Vogel 399961ae650dSJack F Vogel static void 400061ae650dSJack F Vogel ixl_disable_adminq(struct i40e_hw *hw) 400161ae650dSJack F Vogel { 400261ae650dSJack F Vogel u32 reg; 400361ae650dSJack F Vogel 400461ae650dSJack F Vogel reg = IXL_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT; 400561ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTL0, reg); 400661ae650dSJack F Vogel 400761ae650dSJack F Vogel return; 400861ae650dSJack F Vogel } 400961ae650dSJack F Vogel 401061ae650dSJack F Vogel static void 401161ae650dSJack F Vogel ixl_enable_queue(struct i40e_hw *hw, int id) 401261ae650dSJack F Vogel { 401361ae650dSJack F Vogel u32 reg; 401461ae650dSJack F Vogel 401561ae650dSJack F Vogel reg = I40E_PFINT_DYN_CTLN_INTENA_MASK | 401661ae650dSJack F Vogel I40E_PFINT_DYN_CTLN_CLEARPBA_MASK | 401761ae650dSJack F Vogel (IXL_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); 401861ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTLN(id), reg); 401961ae650dSJack F Vogel } 402061ae650dSJack F Vogel 402161ae650dSJack F Vogel static void 402261ae650dSJack F Vogel ixl_disable_queue(struct i40e_hw *hw, int id) 402361ae650dSJack F Vogel { 402461ae650dSJack F Vogel u32 reg; 402561ae650dSJack F Vogel 402661ae650dSJack F Vogel reg = IXL_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT; 402761ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTLN(id), reg); 402861ae650dSJack F Vogel 402961ae650dSJack F Vogel return; 403061ae650dSJack F Vogel } 403161ae650dSJack F Vogel 403261ae650dSJack F Vogel static void 403361ae650dSJack F Vogel ixl_enable_legacy(struct i40e_hw *hw) 403461ae650dSJack F Vogel { 403561ae650dSJack F Vogel u32 reg; 403661ae650dSJack F Vogel reg = I40E_PFINT_DYN_CTL0_INTENA_MASK | 403761ae650dSJack F Vogel I40E_PFINT_DYN_CTL0_CLEARPBA_MASK | 403861ae650dSJack F Vogel (IXL_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); 403961ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTL0, reg); 404061ae650dSJack F Vogel } 404161ae650dSJack F Vogel 404261ae650dSJack F Vogel static void 404361ae650dSJack F Vogel ixl_disable_legacy(struct i40e_hw *hw) 404461ae650dSJack F Vogel { 404561ae650dSJack F Vogel u32 reg; 404661ae650dSJack F Vogel 404761ae650dSJack F Vogel reg = IXL_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT; 404861ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTL0, reg); 404961ae650dSJack F Vogel 405061ae650dSJack F Vogel return; 405161ae650dSJack F Vogel } 405261ae650dSJack F Vogel 405361ae650dSJack F Vogel static void 405461ae650dSJack F Vogel ixl_update_stats_counters(struct ixl_pf *pf) 405561ae650dSJack F Vogel { 405661ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 405761ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 405856c2c47bSJack F Vogel struct ixl_vf *vf; 405961ae650dSJack F Vogel 406061ae650dSJack F Vogel struct i40e_hw_port_stats *nsd = &pf->stats; 406161ae650dSJack F Vogel struct i40e_hw_port_stats *osd = &pf->stats_offsets; 406261ae650dSJack F Vogel 406361ae650dSJack F Vogel /* Update hw stats */ 406461ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), 406561ae650dSJack F Vogel pf->stat_offsets_loaded, 406661ae650dSJack F Vogel &osd->crc_errors, &nsd->crc_errors); 406761ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), 406861ae650dSJack F Vogel pf->stat_offsets_loaded, 406961ae650dSJack F Vogel &osd->illegal_bytes, &nsd->illegal_bytes); 407061ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), 407161ae650dSJack F Vogel I40E_GLPRT_GORCL(hw->port), 407261ae650dSJack F Vogel pf->stat_offsets_loaded, 407361ae650dSJack F Vogel &osd->eth.rx_bytes, &nsd->eth.rx_bytes); 407461ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), 407561ae650dSJack F Vogel I40E_GLPRT_GOTCL(hw->port), 407661ae650dSJack F Vogel pf->stat_offsets_loaded, 407761ae650dSJack F Vogel &osd->eth.tx_bytes, &nsd->eth.tx_bytes); 407861ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), 407961ae650dSJack F Vogel pf->stat_offsets_loaded, 408061ae650dSJack F Vogel &osd->eth.rx_discards, 408161ae650dSJack F Vogel &nsd->eth.rx_discards); 408261ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), 408361ae650dSJack F Vogel I40E_GLPRT_UPRCL(hw->port), 408461ae650dSJack F Vogel pf->stat_offsets_loaded, 408561ae650dSJack F Vogel &osd->eth.rx_unicast, 408661ae650dSJack F Vogel &nsd->eth.rx_unicast); 408761ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), 408861ae650dSJack F Vogel I40E_GLPRT_UPTCL(hw->port), 408961ae650dSJack F Vogel pf->stat_offsets_loaded, 409061ae650dSJack F Vogel &osd->eth.tx_unicast, 409161ae650dSJack F Vogel &nsd->eth.tx_unicast); 409261ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), 409361ae650dSJack F Vogel I40E_GLPRT_MPRCL(hw->port), 409461ae650dSJack F Vogel pf->stat_offsets_loaded, 409561ae650dSJack F Vogel &osd->eth.rx_multicast, 409661ae650dSJack F Vogel &nsd->eth.rx_multicast); 409761ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), 409861ae650dSJack F Vogel I40E_GLPRT_MPTCL(hw->port), 409961ae650dSJack F Vogel pf->stat_offsets_loaded, 410061ae650dSJack F Vogel &osd->eth.tx_multicast, 410161ae650dSJack F Vogel &nsd->eth.tx_multicast); 410261ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), 410361ae650dSJack F Vogel I40E_GLPRT_BPRCL(hw->port), 410461ae650dSJack F Vogel pf->stat_offsets_loaded, 410561ae650dSJack F Vogel &osd->eth.rx_broadcast, 410661ae650dSJack F Vogel &nsd->eth.rx_broadcast); 410761ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), 410861ae650dSJack F Vogel I40E_GLPRT_BPTCL(hw->port), 410961ae650dSJack F Vogel pf->stat_offsets_loaded, 411061ae650dSJack F Vogel &osd->eth.tx_broadcast, 411161ae650dSJack F Vogel &nsd->eth.tx_broadcast); 411261ae650dSJack F Vogel 411361ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), 411461ae650dSJack F Vogel pf->stat_offsets_loaded, 411561ae650dSJack F Vogel &osd->tx_dropped_link_down, 411661ae650dSJack F Vogel &nsd->tx_dropped_link_down); 411761ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), 411861ae650dSJack F Vogel pf->stat_offsets_loaded, 411961ae650dSJack F Vogel &osd->mac_local_faults, 412061ae650dSJack F Vogel &nsd->mac_local_faults); 412161ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), 412261ae650dSJack F Vogel pf->stat_offsets_loaded, 412361ae650dSJack F Vogel &osd->mac_remote_faults, 412461ae650dSJack F Vogel &nsd->mac_remote_faults); 412561ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), 412661ae650dSJack F Vogel pf->stat_offsets_loaded, 412761ae650dSJack F Vogel &osd->rx_length_errors, 412861ae650dSJack F Vogel &nsd->rx_length_errors); 412961ae650dSJack F Vogel 413061ae650dSJack F Vogel /* Flow control (LFC) stats */ 413161ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), 413261ae650dSJack F Vogel pf->stat_offsets_loaded, 413361ae650dSJack F Vogel &osd->link_xon_rx, &nsd->link_xon_rx); 413461ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), 413561ae650dSJack F Vogel pf->stat_offsets_loaded, 413661ae650dSJack F Vogel &osd->link_xon_tx, &nsd->link_xon_tx); 413761ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), 413861ae650dSJack F Vogel pf->stat_offsets_loaded, 413961ae650dSJack F Vogel &osd->link_xoff_rx, &nsd->link_xoff_rx); 414061ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), 414161ae650dSJack F Vogel pf->stat_offsets_loaded, 414261ae650dSJack F Vogel &osd->link_xoff_tx, &nsd->link_xoff_tx); 414361ae650dSJack F Vogel 414461ae650dSJack F Vogel /* Packet size stats rx */ 414561ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), 414661ae650dSJack F Vogel I40E_GLPRT_PRC64L(hw->port), 414761ae650dSJack F Vogel pf->stat_offsets_loaded, 414861ae650dSJack F Vogel &osd->rx_size_64, &nsd->rx_size_64); 414961ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), 415061ae650dSJack F Vogel I40E_GLPRT_PRC127L(hw->port), 415161ae650dSJack F Vogel pf->stat_offsets_loaded, 415261ae650dSJack F Vogel &osd->rx_size_127, &nsd->rx_size_127); 415361ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), 415461ae650dSJack F Vogel I40E_GLPRT_PRC255L(hw->port), 415561ae650dSJack F Vogel pf->stat_offsets_loaded, 415661ae650dSJack F Vogel &osd->rx_size_255, &nsd->rx_size_255); 415761ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), 415861ae650dSJack F Vogel I40E_GLPRT_PRC511L(hw->port), 415961ae650dSJack F Vogel pf->stat_offsets_loaded, 416061ae650dSJack F Vogel &osd->rx_size_511, &nsd->rx_size_511); 416161ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), 416261ae650dSJack F Vogel I40E_GLPRT_PRC1023L(hw->port), 416361ae650dSJack F Vogel pf->stat_offsets_loaded, 416461ae650dSJack F Vogel &osd->rx_size_1023, &nsd->rx_size_1023); 416561ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), 416661ae650dSJack F Vogel I40E_GLPRT_PRC1522L(hw->port), 416761ae650dSJack F Vogel pf->stat_offsets_loaded, 416861ae650dSJack F Vogel &osd->rx_size_1522, &nsd->rx_size_1522); 416961ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), 417061ae650dSJack F Vogel I40E_GLPRT_PRC9522L(hw->port), 417161ae650dSJack F Vogel pf->stat_offsets_loaded, 417261ae650dSJack F Vogel &osd->rx_size_big, &nsd->rx_size_big); 417361ae650dSJack F Vogel 417461ae650dSJack F Vogel /* Packet size stats tx */ 417561ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), 417661ae650dSJack F Vogel I40E_GLPRT_PTC64L(hw->port), 417761ae650dSJack F Vogel pf->stat_offsets_loaded, 417861ae650dSJack F Vogel &osd->tx_size_64, &nsd->tx_size_64); 417961ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), 418061ae650dSJack F Vogel I40E_GLPRT_PTC127L(hw->port), 418161ae650dSJack F Vogel pf->stat_offsets_loaded, 418261ae650dSJack F Vogel &osd->tx_size_127, &nsd->tx_size_127); 418361ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), 418461ae650dSJack F Vogel I40E_GLPRT_PTC255L(hw->port), 418561ae650dSJack F Vogel pf->stat_offsets_loaded, 418661ae650dSJack F Vogel &osd->tx_size_255, &nsd->tx_size_255); 418761ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), 418861ae650dSJack F Vogel I40E_GLPRT_PTC511L(hw->port), 418961ae650dSJack F Vogel pf->stat_offsets_loaded, 419061ae650dSJack F Vogel &osd->tx_size_511, &nsd->tx_size_511); 419161ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), 419261ae650dSJack F Vogel I40E_GLPRT_PTC1023L(hw->port), 419361ae650dSJack F Vogel pf->stat_offsets_loaded, 419461ae650dSJack F Vogel &osd->tx_size_1023, &nsd->tx_size_1023); 419561ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), 419661ae650dSJack F Vogel I40E_GLPRT_PTC1522L(hw->port), 419761ae650dSJack F Vogel pf->stat_offsets_loaded, 419861ae650dSJack F Vogel &osd->tx_size_1522, &nsd->tx_size_1522); 419961ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), 420061ae650dSJack F Vogel I40E_GLPRT_PTC9522L(hw->port), 420161ae650dSJack F Vogel pf->stat_offsets_loaded, 420261ae650dSJack F Vogel &osd->tx_size_big, &nsd->tx_size_big); 420361ae650dSJack F Vogel 420461ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_RUC(hw->port), 420561ae650dSJack F Vogel pf->stat_offsets_loaded, 420661ae650dSJack F Vogel &osd->rx_undersize, &nsd->rx_undersize); 420761ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_RFC(hw->port), 420861ae650dSJack F Vogel pf->stat_offsets_loaded, 420961ae650dSJack F Vogel &osd->rx_fragments, &nsd->rx_fragments); 421061ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_ROC(hw->port), 421161ae650dSJack F Vogel pf->stat_offsets_loaded, 421261ae650dSJack F Vogel &osd->rx_oversize, &nsd->rx_oversize); 421361ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_RJC(hw->port), 421461ae650dSJack F Vogel pf->stat_offsets_loaded, 421561ae650dSJack F Vogel &osd->rx_jabber, &nsd->rx_jabber); 421661ae650dSJack F Vogel pf->stat_offsets_loaded = true; 421761ae650dSJack F Vogel /* End hw stats */ 421861ae650dSJack F Vogel 421961ae650dSJack F Vogel /* Update vsi stats */ 422056c2c47bSJack F Vogel ixl_update_vsi_stats(vsi); 422161ae650dSJack F Vogel 422256c2c47bSJack F Vogel for (int i = 0; i < pf->num_vfs; i++) { 422356c2c47bSJack F Vogel vf = &pf->vfs[i]; 422456c2c47bSJack F Vogel if (vf->vf_flags & VF_FLAG_ENABLED) 422556c2c47bSJack F Vogel ixl_update_eth_stats(&pf->vfs[i].vsi); 422656c2c47bSJack F Vogel } 422761ae650dSJack F Vogel } 422861ae650dSJack F Vogel 422961ae650dSJack F Vogel /* 423061ae650dSJack F Vogel ** Tasklet handler for MSIX Adminq interrupts 423161ae650dSJack F Vogel ** - do outside interrupt since it might sleep 423261ae650dSJack F Vogel */ 423361ae650dSJack F Vogel static void 423461ae650dSJack F Vogel ixl_do_adminq(void *context, int pending) 423561ae650dSJack F Vogel { 423661ae650dSJack F Vogel struct ixl_pf *pf = context; 423761ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 423861ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 423961ae650dSJack F Vogel struct i40e_arq_event_info event; 424061ae650dSJack F Vogel i40e_status ret; 424161ae650dSJack F Vogel u32 reg, loop = 0; 424261ae650dSJack F Vogel u16 opcode, result; 424361ae650dSJack F Vogel 4244e5100ee2SJack F Vogel event.buf_len = IXL_AQ_BUF_SZ; 4245e5100ee2SJack F Vogel event.msg_buf = malloc(event.buf_len, 424661ae650dSJack F Vogel M_DEVBUF, M_NOWAIT | M_ZERO); 424761ae650dSJack F Vogel if (!event.msg_buf) { 424861ae650dSJack F Vogel printf("Unable to allocate adminq memory\n"); 424961ae650dSJack F Vogel return; 425061ae650dSJack F Vogel } 425161ae650dSJack F Vogel 425256c2c47bSJack F Vogel IXL_PF_LOCK(pf); 425361ae650dSJack F Vogel /* clean and process any events */ 425461ae650dSJack F Vogel do { 425561ae650dSJack F Vogel ret = i40e_clean_arq_element(hw, &event, &result); 425661ae650dSJack F Vogel if (ret) 425761ae650dSJack F Vogel break; 425861ae650dSJack F Vogel opcode = LE16_TO_CPU(event.desc.opcode); 425961ae650dSJack F Vogel switch (opcode) { 426061ae650dSJack F Vogel case i40e_aqc_opc_get_link_status: 426156c2c47bSJack F Vogel ixl_link_event(pf, &event); 426261ae650dSJack F Vogel ixl_update_link_status(pf); 426361ae650dSJack F Vogel break; 426461ae650dSJack F Vogel case i40e_aqc_opc_send_msg_to_pf: 426556c2c47bSJack F Vogel #ifdef PCI_IOV 426656c2c47bSJack F Vogel ixl_handle_vf_msg(pf, &event); 426756c2c47bSJack F Vogel #endif 426861ae650dSJack F Vogel break; 426961ae650dSJack F Vogel case i40e_aqc_opc_event_lan_overflow: 427061ae650dSJack F Vogel break; 427161ae650dSJack F Vogel default: 427261ae650dSJack F Vogel #ifdef IXL_DEBUG 427361ae650dSJack F Vogel printf("AdminQ unknown event %x\n", opcode); 427461ae650dSJack F Vogel #endif 427561ae650dSJack F Vogel break; 427661ae650dSJack F Vogel } 427761ae650dSJack F Vogel 427861ae650dSJack F Vogel } while (result && (loop++ < IXL_ADM_LIMIT)); 427961ae650dSJack F Vogel 428061ae650dSJack F Vogel reg = rd32(hw, I40E_PFINT_ICR0_ENA); 428161ae650dSJack F Vogel reg |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; 428261ae650dSJack F Vogel wr32(hw, I40E_PFINT_ICR0_ENA, reg); 428361ae650dSJack F Vogel free(event.msg_buf, M_DEVBUF); 428461ae650dSJack F Vogel 428556c2c47bSJack F Vogel /* 428656c2c47bSJack F Vogel * If there are still messages to process, reschedule ourselves. 428756c2c47bSJack F Vogel * Otherwise, re-enable our interrupt and go to sleep. 428856c2c47bSJack F Vogel */ 428956c2c47bSJack F Vogel if (result > 0) 429056c2c47bSJack F Vogel taskqueue_enqueue(pf->tq, &pf->adminq); 429161ae650dSJack F Vogel else 429261ae650dSJack F Vogel ixl_enable_intr(vsi); 429356c2c47bSJack F Vogel 429456c2c47bSJack F Vogel IXL_PF_UNLOCK(pf); 429561ae650dSJack F Vogel } 429661ae650dSJack F Vogel 429761ae650dSJack F Vogel static int 429861ae650dSJack F Vogel ixl_debug_info(SYSCTL_HANDLER_ARGS) 429961ae650dSJack F Vogel { 430061ae650dSJack F Vogel struct ixl_pf *pf; 430161ae650dSJack F Vogel int error, input = 0; 430261ae650dSJack F Vogel 430361ae650dSJack F Vogel error = sysctl_handle_int(oidp, &input, 0, req); 430461ae650dSJack F Vogel 430561ae650dSJack F Vogel if (error || !req->newptr) 430661ae650dSJack F Vogel return (error); 430761ae650dSJack F Vogel 430861ae650dSJack F Vogel if (input == 1) { 430961ae650dSJack F Vogel pf = (struct ixl_pf *)arg1; 431061ae650dSJack F Vogel ixl_print_debug_info(pf); 431161ae650dSJack F Vogel } 431261ae650dSJack F Vogel 431361ae650dSJack F Vogel return (error); 431461ae650dSJack F Vogel } 431561ae650dSJack F Vogel 431661ae650dSJack F Vogel static void 431761ae650dSJack F Vogel ixl_print_debug_info(struct ixl_pf *pf) 431861ae650dSJack F Vogel { 431961ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 432061ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 432161ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 432261ae650dSJack F Vogel struct rx_ring *rxr = &que->rxr; 432361ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 432461ae650dSJack F Vogel u32 reg; 432561ae650dSJack F Vogel 432661ae650dSJack F Vogel 4327ff21e856SBjoern A. Zeeb printf("Queue irqs = %jx\n", (uintmax_t)que->irqs); 4328ff21e856SBjoern A. Zeeb printf("AdminQ irqs = %jx\n", (uintmax_t)pf->admin_irq); 432961ae650dSJack F Vogel printf("RX next check = %x\n", rxr->next_check); 4330ff21e856SBjoern A. Zeeb printf("RX not ready = %jx\n", (uintmax_t)rxr->not_done); 4331ff21e856SBjoern A. Zeeb printf("RX packets = %jx\n", (uintmax_t)rxr->rx_packets); 433261ae650dSJack F Vogel printf("TX desc avail = %x\n", txr->avail); 433361ae650dSJack F Vogel 433461ae650dSJack F Vogel reg = rd32(hw, I40E_GLV_GORCL(0xc)); 433561ae650dSJack F Vogel printf("RX Bytes = %x\n", reg); 433661ae650dSJack F Vogel reg = rd32(hw, I40E_GLPRT_GORCL(hw->port)); 433761ae650dSJack F Vogel printf("Port RX Bytes = %x\n", reg); 433861ae650dSJack F Vogel reg = rd32(hw, I40E_GLV_RDPC(0xc)); 433961ae650dSJack F Vogel printf("RX discard = %x\n", reg); 434061ae650dSJack F Vogel reg = rd32(hw, I40E_GLPRT_RDPC(hw->port)); 434161ae650dSJack F Vogel printf("Port RX discard = %x\n", reg); 434261ae650dSJack F Vogel 434361ae650dSJack F Vogel reg = rd32(hw, I40E_GLV_TEPC(0xc)); 434461ae650dSJack F Vogel printf("TX errors = %x\n", reg); 434561ae650dSJack F Vogel reg = rd32(hw, I40E_GLV_GOTCL(0xc)); 434661ae650dSJack F Vogel printf("TX Bytes = %x\n", reg); 434761ae650dSJack F Vogel 434861ae650dSJack F Vogel reg = rd32(hw, I40E_GLPRT_RUC(hw->port)); 434961ae650dSJack F Vogel printf("RX undersize = %x\n", reg); 435061ae650dSJack F Vogel reg = rd32(hw, I40E_GLPRT_RFC(hw->port)); 435161ae650dSJack F Vogel printf("RX fragments = %x\n", reg); 435261ae650dSJack F Vogel reg = rd32(hw, I40E_GLPRT_ROC(hw->port)); 435361ae650dSJack F Vogel printf("RX oversize = %x\n", reg); 435461ae650dSJack F Vogel reg = rd32(hw, I40E_GLPRT_RLEC(hw->port)); 435561ae650dSJack F Vogel printf("RX length error = %x\n", reg); 435661ae650dSJack F Vogel reg = rd32(hw, I40E_GLPRT_MRFC(hw->port)); 435761ae650dSJack F Vogel printf("mac remote fault = %x\n", reg); 435861ae650dSJack F Vogel reg = rd32(hw, I40E_GLPRT_MLFC(hw->port)); 435961ae650dSJack F Vogel printf("mac local fault = %x\n", reg); 436061ae650dSJack F Vogel } 436161ae650dSJack F Vogel 436261ae650dSJack F Vogel /** 436361ae650dSJack F Vogel * Update VSI-specific ethernet statistics counters. 436461ae650dSJack F Vogel **/ 436561ae650dSJack F Vogel void ixl_update_eth_stats(struct ixl_vsi *vsi) 436661ae650dSJack F Vogel { 436761ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)vsi->back; 436861ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 436961ae650dSJack F Vogel struct i40e_eth_stats *es; 437061ae650dSJack F Vogel struct i40e_eth_stats *oes; 43714b443922SGleb Smirnoff struct i40e_hw_port_stats *nsd; 437261ae650dSJack F Vogel u16 stat_idx = vsi->info.stat_counter_idx; 437361ae650dSJack F Vogel 437461ae650dSJack F Vogel es = &vsi->eth_stats; 437561ae650dSJack F Vogel oes = &vsi->eth_stats_offsets; 43764b443922SGleb Smirnoff nsd = &pf->stats; 437761ae650dSJack F Vogel 437861ae650dSJack F Vogel /* Gather up the stats that the hw collects */ 437961ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLV_TEPC(stat_idx), 438061ae650dSJack F Vogel vsi->stat_offsets_loaded, 438161ae650dSJack F Vogel &oes->tx_errors, &es->tx_errors); 438261ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLV_RDPC(stat_idx), 438361ae650dSJack F Vogel vsi->stat_offsets_loaded, 438461ae650dSJack F Vogel &oes->rx_discards, &es->rx_discards); 438561ae650dSJack F Vogel 438661ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLV_GORCH(stat_idx), 438761ae650dSJack F Vogel I40E_GLV_GORCL(stat_idx), 438861ae650dSJack F Vogel vsi->stat_offsets_loaded, 438961ae650dSJack F Vogel &oes->rx_bytes, &es->rx_bytes); 439061ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), 439161ae650dSJack F Vogel I40E_GLV_UPRCL(stat_idx), 439261ae650dSJack F Vogel vsi->stat_offsets_loaded, 439361ae650dSJack F Vogel &oes->rx_unicast, &es->rx_unicast); 439461ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), 439561ae650dSJack F Vogel I40E_GLV_MPRCL(stat_idx), 439661ae650dSJack F Vogel vsi->stat_offsets_loaded, 439761ae650dSJack F Vogel &oes->rx_multicast, &es->rx_multicast); 439861ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), 439961ae650dSJack F Vogel I40E_GLV_BPRCL(stat_idx), 440061ae650dSJack F Vogel vsi->stat_offsets_loaded, 440161ae650dSJack F Vogel &oes->rx_broadcast, &es->rx_broadcast); 440261ae650dSJack F Vogel 440361ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), 440461ae650dSJack F Vogel I40E_GLV_GOTCL(stat_idx), 440561ae650dSJack F Vogel vsi->stat_offsets_loaded, 440661ae650dSJack F Vogel &oes->tx_bytes, &es->tx_bytes); 440761ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), 440861ae650dSJack F Vogel I40E_GLV_UPTCL(stat_idx), 440961ae650dSJack F Vogel vsi->stat_offsets_loaded, 441061ae650dSJack F Vogel &oes->tx_unicast, &es->tx_unicast); 441161ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), 441261ae650dSJack F Vogel I40E_GLV_MPTCL(stat_idx), 441361ae650dSJack F Vogel vsi->stat_offsets_loaded, 441461ae650dSJack F Vogel &oes->tx_multicast, &es->tx_multicast); 441561ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), 441661ae650dSJack F Vogel I40E_GLV_BPTCL(stat_idx), 441761ae650dSJack F Vogel vsi->stat_offsets_loaded, 441861ae650dSJack F Vogel &oes->tx_broadcast, &es->tx_broadcast); 441961ae650dSJack F Vogel vsi->stat_offsets_loaded = true; 442056c2c47bSJack F Vogel } 442156c2c47bSJack F Vogel 442256c2c47bSJack F Vogel static void 442356c2c47bSJack F Vogel ixl_update_vsi_stats(struct ixl_vsi *vsi) 442456c2c47bSJack F Vogel { 442556c2c47bSJack F Vogel struct ixl_pf *pf; 442656c2c47bSJack F Vogel struct ifnet *ifp; 442756c2c47bSJack F Vogel struct i40e_eth_stats *es; 442856c2c47bSJack F Vogel u64 tx_discards; 442956c2c47bSJack F Vogel 443056c2c47bSJack F Vogel struct i40e_hw_port_stats *nsd; 443156c2c47bSJack F Vogel 443256c2c47bSJack F Vogel pf = vsi->back; 443356c2c47bSJack F Vogel ifp = vsi->ifp; 443456c2c47bSJack F Vogel es = &vsi->eth_stats; 443556c2c47bSJack F Vogel nsd = &pf->stats; 443656c2c47bSJack F Vogel 443756c2c47bSJack F Vogel ixl_update_eth_stats(vsi); 443861ae650dSJack F Vogel 44394b443922SGleb Smirnoff tx_discards = es->tx_discards + nsd->tx_dropped_link_down; 444056c2c47bSJack F Vogel for (int i = 0; i < vsi->num_queues; i++) 44414b443922SGleb Smirnoff tx_discards += vsi->queues[i].txr.br->br_drops; 444261ae650dSJack F Vogel 44434b443922SGleb Smirnoff /* Update ifnet stats */ 44444b443922SGleb Smirnoff IXL_SET_IPACKETS(vsi, es->rx_unicast + 44454b443922SGleb Smirnoff es->rx_multicast + 44464b443922SGleb Smirnoff es->rx_broadcast); 44474b443922SGleb Smirnoff IXL_SET_OPACKETS(vsi, es->tx_unicast + 44484b443922SGleb Smirnoff es->tx_multicast + 44494b443922SGleb Smirnoff es->tx_broadcast); 44504b443922SGleb Smirnoff IXL_SET_IBYTES(vsi, es->rx_bytes); 44514b443922SGleb Smirnoff IXL_SET_OBYTES(vsi, es->tx_bytes); 44524b443922SGleb Smirnoff IXL_SET_IMCASTS(vsi, es->rx_multicast); 44534b443922SGleb Smirnoff IXL_SET_OMCASTS(vsi, es->tx_multicast); 44544b443922SGleb Smirnoff 445556c2c47bSJack F Vogel IXL_SET_IERRORS(vsi, nsd->crc_errors + nsd->illegal_bytes + 445656c2c47bSJack F Vogel nsd->rx_undersize + nsd->rx_oversize + nsd->rx_fragments + 445756c2c47bSJack F Vogel nsd->rx_jabber); 44584b443922SGleb Smirnoff IXL_SET_OERRORS(vsi, es->tx_errors); 44594b443922SGleb Smirnoff IXL_SET_IQDROPS(vsi, es->rx_discards + nsd->eth.rx_discards); 44604b443922SGleb Smirnoff IXL_SET_OQDROPS(vsi, tx_discards); 44614b443922SGleb Smirnoff IXL_SET_NOPROTO(vsi, es->rx_unknown_protocol); 44624b443922SGleb Smirnoff IXL_SET_COLLISIONS(vsi, 0); 446361ae650dSJack F Vogel } 446461ae650dSJack F Vogel 446561ae650dSJack F Vogel /** 446661ae650dSJack F Vogel * Reset all of the stats for the given pf 446761ae650dSJack F Vogel **/ 446861ae650dSJack F Vogel void ixl_pf_reset_stats(struct ixl_pf *pf) 446961ae650dSJack F Vogel { 447061ae650dSJack F Vogel bzero(&pf->stats, sizeof(struct i40e_hw_port_stats)); 447161ae650dSJack F Vogel bzero(&pf->stats_offsets, sizeof(struct i40e_hw_port_stats)); 447261ae650dSJack F Vogel pf->stat_offsets_loaded = false; 447361ae650dSJack F Vogel } 447461ae650dSJack F Vogel 447561ae650dSJack F Vogel /** 447661ae650dSJack F Vogel * Resets all stats of the given vsi 447761ae650dSJack F Vogel **/ 447861ae650dSJack F Vogel void ixl_vsi_reset_stats(struct ixl_vsi *vsi) 447961ae650dSJack F Vogel { 448061ae650dSJack F Vogel bzero(&vsi->eth_stats, sizeof(struct i40e_eth_stats)); 448161ae650dSJack F Vogel bzero(&vsi->eth_stats_offsets, sizeof(struct i40e_eth_stats)); 448261ae650dSJack F Vogel vsi->stat_offsets_loaded = false; 448361ae650dSJack F Vogel } 448461ae650dSJack F Vogel 448561ae650dSJack F Vogel /** 448661ae650dSJack F Vogel * Read and update a 48 bit stat from the hw 448761ae650dSJack F Vogel * 448861ae650dSJack F Vogel * Since the device stats are not reset at PFReset, they likely will not 448961ae650dSJack F Vogel * be zeroed when the driver starts. We'll save the first values read 449061ae650dSJack F Vogel * and use them as offsets to be subtracted from the raw values in order 449161ae650dSJack F Vogel * to report stats that count from zero. 449261ae650dSJack F Vogel **/ 449361ae650dSJack F Vogel static void 449461ae650dSJack F Vogel ixl_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, 449561ae650dSJack F Vogel bool offset_loaded, u64 *offset, u64 *stat) 449661ae650dSJack F Vogel { 449761ae650dSJack F Vogel u64 new_data; 449861ae650dSJack F Vogel 4499ff21e856SBjoern A. Zeeb #if defined(__FreeBSD__) && (__FreeBSD_version >= 1000000) && defined(__amd64__) 450061ae650dSJack F Vogel new_data = rd64(hw, loreg); 450161ae650dSJack F Vogel #else 450261ae650dSJack F Vogel /* 450361ae650dSJack F Vogel * Use two rd32's instead of one rd64; FreeBSD versions before 450461ae650dSJack F Vogel * 10 don't support 8 byte bus reads/writes. 450561ae650dSJack F Vogel */ 450661ae650dSJack F Vogel new_data = rd32(hw, loreg); 450761ae650dSJack F Vogel new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; 450861ae650dSJack F Vogel #endif 450961ae650dSJack F Vogel 451061ae650dSJack F Vogel if (!offset_loaded) 451161ae650dSJack F Vogel *offset = new_data; 451261ae650dSJack F Vogel if (new_data >= *offset) 451361ae650dSJack F Vogel *stat = new_data - *offset; 451461ae650dSJack F Vogel else 451561ae650dSJack F Vogel *stat = (new_data + ((u64)1 << 48)) - *offset; 451661ae650dSJack F Vogel *stat &= 0xFFFFFFFFFFFFULL; 451761ae650dSJack F Vogel } 451861ae650dSJack F Vogel 451961ae650dSJack F Vogel /** 452061ae650dSJack F Vogel * Read and update a 32 bit stat from the hw 452161ae650dSJack F Vogel **/ 452261ae650dSJack F Vogel static void 452361ae650dSJack F Vogel ixl_stat_update32(struct i40e_hw *hw, u32 reg, 452461ae650dSJack F Vogel bool offset_loaded, u64 *offset, u64 *stat) 452561ae650dSJack F Vogel { 452661ae650dSJack F Vogel u32 new_data; 452761ae650dSJack F Vogel 452861ae650dSJack F Vogel new_data = rd32(hw, reg); 452961ae650dSJack F Vogel if (!offset_loaded) 453061ae650dSJack F Vogel *offset = new_data; 453161ae650dSJack F Vogel if (new_data >= *offset) 453261ae650dSJack F Vogel *stat = (u32)(new_data - *offset); 453361ae650dSJack F Vogel else 453461ae650dSJack F Vogel *stat = (u32)((new_data + ((u64)1 << 32)) - *offset); 453561ae650dSJack F Vogel } 453661ae650dSJack F Vogel 453761ae650dSJack F Vogel /* 453861ae650dSJack F Vogel ** Set flow control using sysctl: 453961ae650dSJack F Vogel ** 0 - off 454061ae650dSJack F Vogel ** 1 - rx pause 454161ae650dSJack F Vogel ** 2 - tx pause 454261ae650dSJack F Vogel ** 3 - full 454361ae650dSJack F Vogel */ 454461ae650dSJack F Vogel static int 454561ae650dSJack F Vogel ixl_set_flowcntl(SYSCTL_HANDLER_ARGS) 454661ae650dSJack F Vogel { 454761ae650dSJack F Vogel /* 454861ae650dSJack F Vogel * TODO: ensure flow control is disabled if 454961ae650dSJack F Vogel * priority flow control is enabled 455061ae650dSJack F Vogel * 455161ae650dSJack F Vogel * TODO: ensure tx CRC by hardware should be enabled 455261ae650dSJack F Vogel * if tx flow control is enabled. 455361ae650dSJack F Vogel */ 455461ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 455561ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 455661ae650dSJack F Vogel device_t dev = pf->dev; 4557b6c8f260SJack F Vogel int error = 0; 455861ae650dSJack F Vogel enum i40e_status_code aq_error = 0; 455961ae650dSJack F Vogel u8 fc_aq_err = 0; 456061ae650dSJack F Vogel 4561b6c8f260SJack F Vogel /* Get request */ 4562b6c8f260SJack F Vogel error = sysctl_handle_int(oidp, &pf->fc, 0, req); 456361ae650dSJack F Vogel if ((error) || (req->newptr == NULL)) 456461ae650dSJack F Vogel return (error); 4565b6c8f260SJack F Vogel if (pf->fc < 0 || pf->fc > 3) { 456661ae650dSJack F Vogel device_printf(dev, 456761ae650dSJack F Vogel "Invalid fc mode; valid modes are 0 through 3\n"); 456861ae650dSJack F Vogel return (EINVAL); 456961ae650dSJack F Vogel } 457061ae650dSJack F Vogel 457161ae650dSJack F Vogel /* 457261ae650dSJack F Vogel ** Changing flow control mode currently does not work on 457361ae650dSJack F Vogel ** 40GBASE-CR4 PHYs 457461ae650dSJack F Vogel */ 457561ae650dSJack F Vogel if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_40GBASE_CR4 457661ae650dSJack F Vogel || hw->phy.link_info.phy_type == I40E_PHY_TYPE_40GBASE_CR4_CU) { 457761ae650dSJack F Vogel device_printf(dev, "Changing flow control mode unsupported" 457861ae650dSJack F Vogel " on 40GBase-CR4 media.\n"); 457961ae650dSJack F Vogel return (ENODEV); 458061ae650dSJack F Vogel } 458161ae650dSJack F Vogel 458261ae650dSJack F Vogel /* Set fc ability for port */ 4583b6c8f260SJack F Vogel hw->fc.requested_mode = pf->fc; 458461ae650dSJack F Vogel aq_error = i40e_set_fc(hw, &fc_aq_err, TRUE); 458561ae650dSJack F Vogel if (aq_error) { 458661ae650dSJack F Vogel device_printf(dev, 458761ae650dSJack F Vogel "%s: Error setting new fc mode %d; fc_err %#x\n", 458861ae650dSJack F Vogel __func__, aq_error, fc_aq_err); 458961ae650dSJack F Vogel return (EAGAIN); 459061ae650dSJack F Vogel } 459161ae650dSJack F Vogel 459261ae650dSJack F Vogel return (0); 459361ae650dSJack F Vogel } 459461ae650dSJack F Vogel 459561ae650dSJack F Vogel static int 459661ae650dSJack F Vogel ixl_current_speed(SYSCTL_HANDLER_ARGS) 459761ae650dSJack F Vogel { 459861ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 459961ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 460061ae650dSJack F Vogel int error = 0, index = 0; 460161ae650dSJack F Vogel 460261ae650dSJack F Vogel char *speeds[] = { 460361ae650dSJack F Vogel "Unknown", 460461ae650dSJack F Vogel "100M", 460561ae650dSJack F Vogel "1G", 460661ae650dSJack F Vogel "10G", 460761ae650dSJack F Vogel "40G", 460861ae650dSJack F Vogel "20G" 460961ae650dSJack F Vogel }; 461061ae650dSJack F Vogel 461161ae650dSJack F Vogel ixl_update_link_status(pf); 461261ae650dSJack F Vogel 461361ae650dSJack F Vogel switch (hw->phy.link_info.link_speed) { 461461ae650dSJack F Vogel case I40E_LINK_SPEED_100MB: 461561ae650dSJack F Vogel index = 1; 461661ae650dSJack F Vogel break; 461761ae650dSJack F Vogel case I40E_LINK_SPEED_1GB: 461861ae650dSJack F Vogel index = 2; 461961ae650dSJack F Vogel break; 462061ae650dSJack F Vogel case I40E_LINK_SPEED_10GB: 462161ae650dSJack F Vogel index = 3; 462261ae650dSJack F Vogel break; 462361ae650dSJack F Vogel case I40E_LINK_SPEED_40GB: 462461ae650dSJack F Vogel index = 4; 462561ae650dSJack F Vogel break; 462661ae650dSJack F Vogel case I40E_LINK_SPEED_20GB: 462761ae650dSJack F Vogel index = 5; 462861ae650dSJack F Vogel break; 462961ae650dSJack F Vogel case I40E_LINK_SPEED_UNKNOWN: 463061ae650dSJack F Vogel default: 463161ae650dSJack F Vogel index = 0; 463261ae650dSJack F Vogel break; 463361ae650dSJack F Vogel } 463461ae650dSJack F Vogel 463561ae650dSJack F Vogel error = sysctl_handle_string(oidp, speeds[index], 463661ae650dSJack F Vogel strlen(speeds[index]), req); 463761ae650dSJack F Vogel return (error); 463861ae650dSJack F Vogel } 463961ae650dSJack F Vogel 4640e5100ee2SJack F Vogel static int 4641e5100ee2SJack F Vogel ixl_set_advertised_speeds(struct ixl_pf *pf, int speeds) 4642e5100ee2SJack F Vogel { 4643e5100ee2SJack F Vogel struct i40e_hw *hw = &pf->hw; 4644e5100ee2SJack F Vogel device_t dev = pf->dev; 4645e5100ee2SJack F Vogel struct i40e_aq_get_phy_abilities_resp abilities; 4646e5100ee2SJack F Vogel struct i40e_aq_set_phy_config config; 4647e5100ee2SJack F Vogel enum i40e_status_code aq_error = 0; 4648e5100ee2SJack F Vogel 4649e5100ee2SJack F Vogel /* Get current capability information */ 4650b6c8f260SJack F Vogel aq_error = i40e_aq_get_phy_capabilities(hw, 4651b6c8f260SJack F Vogel FALSE, FALSE, &abilities, NULL); 4652e5100ee2SJack F Vogel if (aq_error) { 4653b6c8f260SJack F Vogel device_printf(dev, 4654b6c8f260SJack F Vogel "%s: Error getting phy capabilities %d," 4655e5100ee2SJack F Vogel " aq error: %d\n", __func__, aq_error, 4656e5100ee2SJack F Vogel hw->aq.asq_last_status); 4657e5100ee2SJack F Vogel return (EAGAIN); 4658e5100ee2SJack F Vogel } 4659e5100ee2SJack F Vogel 4660e5100ee2SJack F Vogel /* Prepare new config */ 4661e5100ee2SJack F Vogel bzero(&config, sizeof(config)); 4662e5100ee2SJack F Vogel config.phy_type = abilities.phy_type; 4663e5100ee2SJack F Vogel config.abilities = abilities.abilities 4664e5100ee2SJack F Vogel | I40E_AQ_PHY_ENABLE_ATOMIC_LINK; 4665e5100ee2SJack F Vogel config.eee_capability = abilities.eee_capability; 4666e5100ee2SJack F Vogel config.eeer = abilities.eeer_val; 4667e5100ee2SJack F Vogel config.low_power_ctrl = abilities.d3_lpan; 4668e5100ee2SJack F Vogel /* Translate into aq cmd link_speed */ 466956c2c47bSJack F Vogel if (speeds & 0x8) 467056c2c47bSJack F Vogel config.link_speed |= I40E_LINK_SPEED_20GB; 4671e5100ee2SJack F Vogel if (speeds & 0x4) 4672e5100ee2SJack F Vogel config.link_speed |= I40E_LINK_SPEED_10GB; 4673e5100ee2SJack F Vogel if (speeds & 0x2) 4674e5100ee2SJack F Vogel config.link_speed |= I40E_LINK_SPEED_1GB; 4675e5100ee2SJack F Vogel if (speeds & 0x1) 4676e5100ee2SJack F Vogel config.link_speed |= I40E_LINK_SPEED_100MB; 4677e5100ee2SJack F Vogel 4678e5100ee2SJack F Vogel /* Do aq command & restart link */ 4679e5100ee2SJack F Vogel aq_error = i40e_aq_set_phy_config(hw, &config, NULL); 4680e5100ee2SJack F Vogel if (aq_error) { 4681b6c8f260SJack F Vogel device_printf(dev, 4682b6c8f260SJack F Vogel "%s: Error setting new phy config %d," 4683e5100ee2SJack F Vogel " aq error: %d\n", __func__, aq_error, 4684e5100ee2SJack F Vogel hw->aq.asq_last_status); 4685e5100ee2SJack F Vogel return (EAGAIN); 4686e5100ee2SJack F Vogel } 4687e5100ee2SJack F Vogel 4688393c4bb1SJack F Vogel /* 4689393c4bb1SJack F Vogel ** This seems a bit heavy handed, but we 4690393c4bb1SJack F Vogel ** need to get a reinit on some devices 4691393c4bb1SJack F Vogel */ 4692393c4bb1SJack F Vogel IXL_PF_LOCK(pf); 4693393c4bb1SJack F Vogel ixl_stop(pf); 4694393c4bb1SJack F Vogel ixl_init_locked(pf); 4695393c4bb1SJack F Vogel IXL_PF_UNLOCK(pf); 4696393c4bb1SJack F Vogel 4697e5100ee2SJack F Vogel return (0); 4698e5100ee2SJack F Vogel } 4699e5100ee2SJack F Vogel 470061ae650dSJack F Vogel /* 470161ae650dSJack F Vogel ** Control link advertise speed: 470261ae650dSJack F Vogel ** Flags: 470361ae650dSJack F Vogel ** 0x1 - advertise 100 Mb 470461ae650dSJack F Vogel ** 0x2 - advertise 1G 470561ae650dSJack F Vogel ** 0x4 - advertise 10G 470656c2c47bSJack F Vogel ** 0x8 - advertise 20G 470761ae650dSJack F Vogel ** 470861ae650dSJack F Vogel ** Does not work on 40G devices. 470961ae650dSJack F Vogel */ 471061ae650dSJack F Vogel static int 471161ae650dSJack F Vogel ixl_set_advertise(SYSCTL_HANDLER_ARGS) 471261ae650dSJack F Vogel { 471361ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 471461ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 471561ae650dSJack F Vogel device_t dev = pf->dev; 471661ae650dSJack F Vogel int requested_ls = 0; 471761ae650dSJack F Vogel int error = 0; 471861ae650dSJack F Vogel 471961ae650dSJack F Vogel /* 472061ae650dSJack F Vogel ** FW doesn't support changing advertised speed 472161ae650dSJack F Vogel ** for 40G devices; speed is always 40G. 472261ae650dSJack F Vogel */ 472361ae650dSJack F Vogel if (i40e_is_40G_device(hw->device_id)) 472461ae650dSJack F Vogel return (ENODEV); 472561ae650dSJack F Vogel 472661ae650dSJack F Vogel /* Read in new mode */ 472761ae650dSJack F Vogel requested_ls = pf->advertised_speed; 472861ae650dSJack F Vogel error = sysctl_handle_int(oidp, &requested_ls, 0, req); 472961ae650dSJack F Vogel if ((error) || (req->newptr == NULL)) 473061ae650dSJack F Vogel return (error); 473156c2c47bSJack F Vogel /* Check for sane value */ 473256c2c47bSJack F Vogel if (requested_ls < 0x1 || requested_ls > 0xE) { 473356c2c47bSJack F Vogel device_printf(dev, "Invalid advertised speed; " 473456c2c47bSJack F Vogel "valid modes are 0x1 through 0xE\n"); 473561ae650dSJack F Vogel return (EINVAL); 473661ae650dSJack F Vogel } 473756c2c47bSJack F Vogel /* Then check for validity based on adapter type */ 473856c2c47bSJack F Vogel switch (hw->device_id) { 473956c2c47bSJack F Vogel case I40E_DEV_ID_10G_BASE_T: 474056c2c47bSJack F Vogel if (requested_ls & 0x8) { 474156c2c47bSJack F Vogel device_printf(dev, 474256c2c47bSJack F Vogel "20Gbs speed not supported on this device.\n"); 474356c2c47bSJack F Vogel return (EINVAL); 474456c2c47bSJack F Vogel } 474556c2c47bSJack F Vogel break; 474656c2c47bSJack F Vogel case I40E_DEV_ID_20G_KR2: 474756c2c47bSJack F Vogel if (requested_ls & 0x1) { 474856c2c47bSJack F Vogel device_printf(dev, 474956c2c47bSJack F Vogel "100Mbs speed not supported on this device.\n"); 475056c2c47bSJack F Vogel return (EINVAL); 475156c2c47bSJack F Vogel } 475256c2c47bSJack F Vogel break; 475356c2c47bSJack F Vogel default: 475456c2c47bSJack F Vogel if (requested_ls & ~0x6) { 475556c2c47bSJack F Vogel device_printf(dev, 475656c2c47bSJack F Vogel "Only 1/10Gbs speeds are supported on this device.\n"); 475756c2c47bSJack F Vogel return (EINVAL); 475856c2c47bSJack F Vogel } 475956c2c47bSJack F Vogel break; 476056c2c47bSJack F Vogel } 476161ae650dSJack F Vogel 476261ae650dSJack F Vogel /* Exit if no change */ 476361ae650dSJack F Vogel if (pf->advertised_speed == requested_ls) 476461ae650dSJack F Vogel return (0); 476561ae650dSJack F Vogel 4766e5100ee2SJack F Vogel error = ixl_set_advertised_speeds(pf, requested_ls); 4767e5100ee2SJack F Vogel if (error) 4768e5100ee2SJack F Vogel return (error); 476961ae650dSJack F Vogel 477061ae650dSJack F Vogel pf->advertised_speed = requested_ls; 477161ae650dSJack F Vogel ixl_update_link_status(pf); 477261ae650dSJack F Vogel return (0); 477361ae650dSJack F Vogel } 477461ae650dSJack F Vogel 477561ae650dSJack F Vogel /* 477661ae650dSJack F Vogel ** Get the width and transaction speed of 477761ae650dSJack F Vogel ** the bus this adapter is plugged into. 477861ae650dSJack F Vogel */ 477961ae650dSJack F Vogel static u16 478061ae650dSJack F Vogel ixl_get_bus_info(struct i40e_hw *hw, device_t dev) 478161ae650dSJack F Vogel { 478261ae650dSJack F Vogel u16 link; 478361ae650dSJack F Vogel u32 offset; 478461ae650dSJack F Vogel 478561ae650dSJack F Vogel 478661ae650dSJack F Vogel /* Get the PCI Express Capabilities offset */ 478761ae650dSJack F Vogel pci_find_cap(dev, PCIY_EXPRESS, &offset); 478861ae650dSJack F Vogel 478961ae650dSJack F Vogel /* ...and read the Link Status Register */ 479061ae650dSJack F Vogel link = pci_read_config(dev, offset + PCIER_LINK_STA, 2); 479161ae650dSJack F Vogel 479261ae650dSJack F Vogel switch (link & I40E_PCI_LINK_WIDTH) { 479361ae650dSJack F Vogel case I40E_PCI_LINK_WIDTH_1: 479461ae650dSJack F Vogel hw->bus.width = i40e_bus_width_pcie_x1; 479561ae650dSJack F Vogel break; 479661ae650dSJack F Vogel case I40E_PCI_LINK_WIDTH_2: 479761ae650dSJack F Vogel hw->bus.width = i40e_bus_width_pcie_x2; 479861ae650dSJack F Vogel break; 479961ae650dSJack F Vogel case I40E_PCI_LINK_WIDTH_4: 480061ae650dSJack F Vogel hw->bus.width = i40e_bus_width_pcie_x4; 480161ae650dSJack F Vogel break; 480261ae650dSJack F Vogel case I40E_PCI_LINK_WIDTH_8: 480361ae650dSJack F Vogel hw->bus.width = i40e_bus_width_pcie_x8; 480461ae650dSJack F Vogel break; 480561ae650dSJack F Vogel default: 480661ae650dSJack F Vogel hw->bus.width = i40e_bus_width_unknown; 480761ae650dSJack F Vogel break; 480861ae650dSJack F Vogel } 480961ae650dSJack F Vogel 481061ae650dSJack F Vogel switch (link & I40E_PCI_LINK_SPEED) { 481161ae650dSJack F Vogel case I40E_PCI_LINK_SPEED_2500: 481261ae650dSJack F Vogel hw->bus.speed = i40e_bus_speed_2500; 481361ae650dSJack F Vogel break; 481461ae650dSJack F Vogel case I40E_PCI_LINK_SPEED_5000: 481561ae650dSJack F Vogel hw->bus.speed = i40e_bus_speed_5000; 481661ae650dSJack F Vogel break; 481761ae650dSJack F Vogel case I40E_PCI_LINK_SPEED_8000: 481861ae650dSJack F Vogel hw->bus.speed = i40e_bus_speed_8000; 481961ae650dSJack F Vogel break; 482061ae650dSJack F Vogel default: 482161ae650dSJack F Vogel hw->bus.speed = i40e_bus_speed_unknown; 482261ae650dSJack F Vogel break; 482361ae650dSJack F Vogel } 482461ae650dSJack F Vogel 482561ae650dSJack F Vogel 482661ae650dSJack F Vogel device_printf(dev,"PCI Express Bus: Speed %s %s\n", 482761ae650dSJack F Vogel ((hw->bus.speed == i40e_bus_speed_8000) ? "8.0GT/s": 482861ae650dSJack F Vogel (hw->bus.speed == i40e_bus_speed_5000) ? "5.0GT/s": 482961ae650dSJack F Vogel (hw->bus.speed == i40e_bus_speed_2500) ? "2.5GT/s":"Unknown"), 483061ae650dSJack F Vogel (hw->bus.width == i40e_bus_width_pcie_x8) ? "Width x8" : 483161ae650dSJack F Vogel (hw->bus.width == i40e_bus_width_pcie_x4) ? "Width x4" : 483261ae650dSJack F Vogel (hw->bus.width == i40e_bus_width_pcie_x1) ? "Width x1" : 483361ae650dSJack F Vogel ("Unknown")); 483461ae650dSJack F Vogel 483561ae650dSJack F Vogel if ((hw->bus.width <= i40e_bus_width_pcie_x8) && 483661ae650dSJack F Vogel (hw->bus.speed < i40e_bus_speed_8000)) { 483761ae650dSJack F Vogel device_printf(dev, "PCI-Express bandwidth available" 483856c2c47bSJack F Vogel " for this device\n may be insufficient for" 483956c2c47bSJack F Vogel " optimal performance.\n"); 484061ae650dSJack F Vogel device_printf(dev, "For expected performance a x8 " 484161ae650dSJack F Vogel "PCIE Gen3 slot is required.\n"); 484261ae650dSJack F Vogel } 484361ae650dSJack F Vogel 484461ae650dSJack F Vogel return (link); 484561ae650dSJack F Vogel } 484661ae650dSJack F Vogel 4847e5100ee2SJack F Vogel static int 4848e5100ee2SJack F Vogel ixl_sysctl_show_fw(SYSCTL_HANDLER_ARGS) 4849e5100ee2SJack F Vogel { 4850e5100ee2SJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 4851e5100ee2SJack F Vogel struct i40e_hw *hw = &pf->hw; 4852e5100ee2SJack F Vogel char buf[32]; 4853e5100ee2SJack F Vogel 4854e5100ee2SJack F Vogel snprintf(buf, sizeof(buf), 4855e5100ee2SJack F Vogel "f%d.%d a%d.%d n%02x.%02x e%08x", 4856e5100ee2SJack F Vogel hw->aq.fw_maj_ver, hw->aq.fw_min_ver, 4857e5100ee2SJack F Vogel hw->aq.api_maj_ver, hw->aq.api_min_ver, 4858e5100ee2SJack F Vogel (hw->nvm.version & IXL_NVM_VERSION_HI_MASK) >> 4859e5100ee2SJack F Vogel IXL_NVM_VERSION_HI_SHIFT, 4860e5100ee2SJack F Vogel (hw->nvm.version & IXL_NVM_VERSION_LO_MASK) >> 4861e5100ee2SJack F Vogel IXL_NVM_VERSION_LO_SHIFT, 4862e5100ee2SJack F Vogel hw->nvm.eetrack); 4863e5100ee2SJack F Vogel return (sysctl_handle_string(oidp, buf, strlen(buf), req)); 4864e5100ee2SJack F Vogel } 4865e5100ee2SJack F Vogel 4866e5100ee2SJack F Vogel 4867393c4bb1SJack F Vogel #ifdef IXL_DEBUG_SYSCTL 486861ae650dSJack F Vogel static int 486961ae650dSJack F Vogel ixl_sysctl_link_status(SYSCTL_HANDLER_ARGS) 487061ae650dSJack F Vogel { 487161ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 487261ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 487361ae650dSJack F Vogel struct i40e_link_status link_status; 487461ae650dSJack F Vogel char buf[512]; 487561ae650dSJack F Vogel 487661ae650dSJack F Vogel enum i40e_status_code aq_error = 0; 487761ae650dSJack F Vogel 487861ae650dSJack F Vogel aq_error = i40e_aq_get_link_info(hw, TRUE, &link_status, NULL); 487961ae650dSJack F Vogel if (aq_error) { 488061ae650dSJack F Vogel printf("i40e_aq_get_link_info() error %d\n", aq_error); 488161ae650dSJack F Vogel return (EPERM); 488261ae650dSJack F Vogel } 488361ae650dSJack F Vogel 488461ae650dSJack F Vogel sprintf(buf, "\n" 488561ae650dSJack F Vogel "PHY Type : %#04x\n" 488661ae650dSJack F Vogel "Speed : %#04x\n" 488761ae650dSJack F Vogel "Link info: %#04x\n" 488861ae650dSJack F Vogel "AN info : %#04x\n" 488961ae650dSJack F Vogel "Ext info : %#04x", 489061ae650dSJack F Vogel link_status.phy_type, link_status.link_speed, 489161ae650dSJack F Vogel link_status.link_info, link_status.an_info, 489261ae650dSJack F Vogel link_status.ext_info); 489361ae650dSJack F Vogel 489461ae650dSJack F Vogel return (sysctl_handle_string(oidp, buf, strlen(buf), req)); 489561ae650dSJack F Vogel } 489661ae650dSJack F Vogel 489761ae650dSJack F Vogel static int 489861ae650dSJack F Vogel ixl_sysctl_phy_abilities(SYSCTL_HANDLER_ARGS) 489961ae650dSJack F Vogel { 490061ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 490161ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 490261ae650dSJack F Vogel char buf[512]; 490361ae650dSJack F Vogel enum i40e_status_code aq_error = 0; 490461ae650dSJack F Vogel 490556c2c47bSJack F Vogel struct i40e_aq_get_phy_abilities_resp abilities; 490656c2c47bSJack F Vogel 490756c2c47bSJack F Vogel aq_error = i40e_aq_get_phy_capabilities(hw, 490856c2c47bSJack F Vogel TRUE, FALSE, &abilities, NULL); 490961ae650dSJack F Vogel if (aq_error) { 491061ae650dSJack F Vogel printf("i40e_aq_get_phy_capabilities() error %d\n", aq_error); 491161ae650dSJack F Vogel return (EPERM); 491261ae650dSJack F Vogel } 491361ae650dSJack F Vogel 491461ae650dSJack F Vogel sprintf(buf, "\n" 491561ae650dSJack F Vogel "PHY Type : %#010x\n" 491661ae650dSJack F Vogel "Speed : %#04x\n" 491761ae650dSJack F Vogel "Abilities: %#04x\n" 491861ae650dSJack F Vogel "EEE cap : %#06x\n" 491961ae650dSJack F Vogel "EEER reg : %#010x\n" 492061ae650dSJack F Vogel "D3 Lpan : %#04x", 492156c2c47bSJack F Vogel abilities.phy_type, abilities.link_speed, 492256c2c47bSJack F Vogel abilities.abilities, abilities.eee_capability, 492356c2c47bSJack F Vogel abilities.eeer_val, abilities.d3_lpan); 492461ae650dSJack F Vogel 492561ae650dSJack F Vogel return (sysctl_handle_string(oidp, buf, strlen(buf), req)); 492661ae650dSJack F Vogel } 492761ae650dSJack F Vogel 492861ae650dSJack F Vogel static int 492961ae650dSJack F Vogel ixl_sysctl_sw_filter_list(SYSCTL_HANDLER_ARGS) 493061ae650dSJack F Vogel { 493161ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 493261ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 493361ae650dSJack F Vogel struct ixl_mac_filter *f; 493461ae650dSJack F Vogel char *buf, *buf_i; 493561ae650dSJack F Vogel 493661ae650dSJack F Vogel int error = 0; 493761ae650dSJack F Vogel int ftl_len = 0; 493861ae650dSJack F Vogel int ftl_counter = 0; 493961ae650dSJack F Vogel int buf_len = 0; 494061ae650dSJack F Vogel int entry_len = 42; 494161ae650dSJack F Vogel 494261ae650dSJack F Vogel SLIST_FOREACH(f, &vsi->ftl, next) { 494361ae650dSJack F Vogel ftl_len++; 494461ae650dSJack F Vogel } 494561ae650dSJack F Vogel 494661ae650dSJack F Vogel if (ftl_len < 1) { 494761ae650dSJack F Vogel sysctl_handle_string(oidp, "(none)", 6, req); 494861ae650dSJack F Vogel return (0); 494961ae650dSJack F Vogel } 495061ae650dSJack F Vogel 495161ae650dSJack F Vogel buf_len = sizeof(char) * (entry_len + 1) * ftl_len + 2; 495261ae650dSJack F Vogel buf = buf_i = malloc(buf_len, M_DEVBUF, M_NOWAIT); 495361ae650dSJack F Vogel 495461ae650dSJack F Vogel sprintf(buf_i++, "\n"); 495561ae650dSJack F Vogel SLIST_FOREACH(f, &vsi->ftl, next) { 495661ae650dSJack F Vogel sprintf(buf_i, 495761ae650dSJack F Vogel MAC_FORMAT ", vlan %4d, flags %#06x", 495861ae650dSJack F Vogel MAC_FORMAT_ARGS(f->macaddr), f->vlan, f->flags); 495961ae650dSJack F Vogel buf_i += entry_len; 496061ae650dSJack F Vogel /* don't print '\n' for last entry */ 496161ae650dSJack F Vogel if (++ftl_counter != ftl_len) { 496261ae650dSJack F Vogel sprintf(buf_i, "\n"); 496361ae650dSJack F Vogel buf_i++; 496461ae650dSJack F Vogel } 496561ae650dSJack F Vogel } 496661ae650dSJack F Vogel 496761ae650dSJack F Vogel error = sysctl_handle_string(oidp, buf, strlen(buf), req); 496861ae650dSJack F Vogel if (error) 496961ae650dSJack F Vogel printf("sysctl error: %d\n", error); 497061ae650dSJack F Vogel free(buf, M_DEVBUF); 497161ae650dSJack F Vogel return error; 497261ae650dSJack F Vogel } 497361ae650dSJack F Vogel 497461ae650dSJack F Vogel #define IXL_SW_RES_SIZE 0x14 497561ae650dSJack F Vogel static int 4976393c4bb1SJack F Vogel ixl_res_alloc_cmp(const void *a, const void *b) 4977393c4bb1SJack F Vogel { 4978393c4bb1SJack F Vogel const struct i40e_aqc_switch_resource_alloc_element_resp *one, *two; 4979393c4bb1SJack F Vogel one = (struct i40e_aqc_switch_resource_alloc_element_resp *)a; 4980393c4bb1SJack F Vogel two = (struct i40e_aqc_switch_resource_alloc_element_resp *)b; 4981393c4bb1SJack F Vogel 4982393c4bb1SJack F Vogel return ((int)one->resource_type - (int)two->resource_type); 4983393c4bb1SJack F Vogel } 4984393c4bb1SJack F Vogel 4985393c4bb1SJack F Vogel static int 4986e5100ee2SJack F Vogel ixl_sysctl_hw_res_alloc(SYSCTL_HANDLER_ARGS) 498761ae650dSJack F Vogel { 498861ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 498961ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 499061ae650dSJack F Vogel device_t dev = pf->dev; 499161ae650dSJack F Vogel struct sbuf *buf; 499261ae650dSJack F Vogel int error = 0; 499361ae650dSJack F Vogel 499461ae650dSJack F Vogel u8 num_entries; 499561ae650dSJack F Vogel struct i40e_aqc_switch_resource_alloc_element_resp resp[IXL_SW_RES_SIZE]; 499661ae650dSJack F Vogel 499761ae650dSJack F Vogel buf = sbuf_new_for_sysctl(NULL, NULL, 0, req); 499861ae650dSJack F Vogel if (!buf) { 499961ae650dSJack F Vogel device_printf(dev, "Could not allocate sbuf for output.\n"); 500061ae650dSJack F Vogel return (ENOMEM); 500161ae650dSJack F Vogel } 500261ae650dSJack F Vogel 5003393c4bb1SJack F Vogel bzero(resp, sizeof(resp)); 500461ae650dSJack F Vogel error = i40e_aq_get_switch_resource_alloc(hw, &num_entries, 500561ae650dSJack F Vogel resp, 500661ae650dSJack F Vogel IXL_SW_RES_SIZE, 500761ae650dSJack F Vogel NULL); 500861ae650dSJack F Vogel if (error) { 500956c2c47bSJack F Vogel device_printf(dev, 501056c2c47bSJack F Vogel "%s: get_switch_resource_alloc() error %d, aq error %d\n", 501161ae650dSJack F Vogel __func__, error, hw->aq.asq_last_status); 501261ae650dSJack F Vogel sbuf_delete(buf); 501361ae650dSJack F Vogel return error; 501461ae650dSJack F Vogel } 5015393c4bb1SJack F Vogel 5016393c4bb1SJack F Vogel /* Sort entries by type for display */ 5017393c4bb1SJack F Vogel qsort(resp, num_entries, 5018393c4bb1SJack F Vogel sizeof(struct i40e_aqc_switch_resource_alloc_element_resp), 5019393c4bb1SJack F Vogel &ixl_res_alloc_cmp); 502061ae650dSJack F Vogel 502161ae650dSJack F Vogel sbuf_cat(buf, "\n"); 5022393c4bb1SJack F Vogel sbuf_printf(buf, "# of entries: %d\n", num_entries); 502361ae650dSJack F Vogel sbuf_printf(buf, 502461ae650dSJack F Vogel "Type | Guaranteed | Total | Used | Un-allocated\n" 502561ae650dSJack F Vogel " | (this) | (all) | (this) | (all) \n"); 502661ae650dSJack F Vogel for (int i = 0; i < num_entries; i++) { 502761ae650dSJack F Vogel sbuf_printf(buf, 502861ae650dSJack F Vogel "%#4x | %10d %5d %6d %12d", 502961ae650dSJack F Vogel resp[i].resource_type, 503061ae650dSJack F Vogel resp[i].guaranteed, 503161ae650dSJack F Vogel resp[i].total, 503261ae650dSJack F Vogel resp[i].used, 503361ae650dSJack F Vogel resp[i].total_unalloced); 503461ae650dSJack F Vogel if (i < num_entries - 1) 503561ae650dSJack F Vogel sbuf_cat(buf, "\n"); 503661ae650dSJack F Vogel } 503761ae650dSJack F Vogel 503861ae650dSJack F Vogel error = sbuf_finish(buf); 503961ae650dSJack F Vogel if (error) { 504061ae650dSJack F Vogel device_printf(dev, "Error finishing sbuf: %d\n", error); 504161ae650dSJack F Vogel sbuf_delete(buf); 504261ae650dSJack F Vogel return error; 504361ae650dSJack F Vogel } 504461ae650dSJack F Vogel 504561ae650dSJack F Vogel error = sysctl_handle_string(oidp, sbuf_data(buf), sbuf_len(buf), req); 504661ae650dSJack F Vogel if (error) 504761ae650dSJack F Vogel device_printf(dev, "sysctl error: %d\n", error); 504861ae650dSJack F Vogel sbuf_delete(buf); 504961ae650dSJack F Vogel return error; 5050e5100ee2SJack F Vogel } 505161ae650dSJack F Vogel 5052e5100ee2SJack F Vogel /* 5053e5100ee2SJack F Vogel ** Caller must init and delete sbuf; this function will clear and 5054e5100ee2SJack F Vogel ** finish it for caller. 5055e5100ee2SJack F Vogel */ 5056e5100ee2SJack F Vogel static char * 5057e5100ee2SJack F Vogel ixl_switch_element_string(struct sbuf *s, u16 seid, bool uplink) 5058e5100ee2SJack F Vogel { 5059e5100ee2SJack F Vogel sbuf_clear(s); 5060e5100ee2SJack F Vogel 5061e5100ee2SJack F Vogel if (seid == 0 && uplink) 5062e5100ee2SJack F Vogel sbuf_cat(s, "Network"); 5063e5100ee2SJack F Vogel else if (seid == 0) 5064e5100ee2SJack F Vogel sbuf_cat(s, "Host"); 5065e5100ee2SJack F Vogel else if (seid == 1) 5066e5100ee2SJack F Vogel sbuf_cat(s, "EMP"); 5067e5100ee2SJack F Vogel else if (seid <= 5) 5068e5100ee2SJack F Vogel sbuf_printf(s, "MAC %d", seid - 2); 5069e5100ee2SJack F Vogel else if (seid <= 15) 5070e5100ee2SJack F Vogel sbuf_cat(s, "Reserved"); 5071e5100ee2SJack F Vogel else if (seid <= 31) 5072e5100ee2SJack F Vogel sbuf_printf(s, "PF %d", seid - 16); 5073e5100ee2SJack F Vogel else if (seid <= 159) 5074e5100ee2SJack F Vogel sbuf_printf(s, "VF %d", seid - 32); 5075e5100ee2SJack F Vogel else if (seid <= 287) 5076e5100ee2SJack F Vogel sbuf_cat(s, "Reserved"); 5077e5100ee2SJack F Vogel else if (seid <= 511) 5078e5100ee2SJack F Vogel sbuf_cat(s, "Other"); // for other structures 5079e5100ee2SJack F Vogel else if (seid <= 895) 5080e5100ee2SJack F Vogel sbuf_printf(s, "VSI %d", seid - 512); 5081e5100ee2SJack F Vogel else if (seid <= 1023) 5082e5100ee2SJack F Vogel sbuf_printf(s, "Reserved"); 5083e5100ee2SJack F Vogel else 5084e5100ee2SJack F Vogel sbuf_cat(s, "Invalid"); 5085e5100ee2SJack F Vogel 5086e5100ee2SJack F Vogel sbuf_finish(s); 5087e5100ee2SJack F Vogel return sbuf_data(s); 5088e5100ee2SJack F Vogel } 5089e5100ee2SJack F Vogel 5090e5100ee2SJack F Vogel static int 5091e5100ee2SJack F Vogel ixl_sysctl_switch_config(SYSCTL_HANDLER_ARGS) 5092e5100ee2SJack F Vogel { 5093e5100ee2SJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 5094e5100ee2SJack F Vogel struct i40e_hw *hw = &pf->hw; 5095e5100ee2SJack F Vogel device_t dev = pf->dev; 5096e5100ee2SJack F Vogel struct sbuf *buf; 5097e5100ee2SJack F Vogel struct sbuf *nmbuf; 5098e5100ee2SJack F Vogel int error = 0; 5099e5100ee2SJack F Vogel u8 aq_buf[I40E_AQ_LARGE_BUF]; 5100e5100ee2SJack F Vogel 5101e5100ee2SJack F Vogel u16 next = 0; 5102e5100ee2SJack F Vogel struct i40e_aqc_get_switch_config_resp *sw_config; 5103e5100ee2SJack F Vogel sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; 5104e5100ee2SJack F Vogel 5105e5100ee2SJack F Vogel buf = sbuf_new_for_sysctl(NULL, NULL, 0, req); 5106e5100ee2SJack F Vogel if (!buf) { 5107e5100ee2SJack F Vogel device_printf(dev, "Could not allocate sbuf for sysctl output.\n"); 5108e5100ee2SJack F Vogel return (ENOMEM); 5109e5100ee2SJack F Vogel } 5110e5100ee2SJack F Vogel 5111e5100ee2SJack F Vogel error = i40e_aq_get_switch_config(hw, sw_config, 5112e5100ee2SJack F Vogel sizeof(aq_buf), &next, NULL); 5113e5100ee2SJack F Vogel if (error) { 511456c2c47bSJack F Vogel device_printf(dev, 511556c2c47bSJack F Vogel "%s: aq_get_switch_config() error %d, aq error %d\n", 5116e5100ee2SJack F Vogel __func__, error, hw->aq.asq_last_status); 5117e5100ee2SJack F Vogel sbuf_delete(buf); 5118e5100ee2SJack F Vogel return error; 5119e5100ee2SJack F Vogel } 5120e5100ee2SJack F Vogel 5121e5100ee2SJack F Vogel nmbuf = sbuf_new_auto(); 5122e5100ee2SJack F Vogel if (!nmbuf) { 5123e5100ee2SJack F Vogel device_printf(dev, "Could not allocate sbuf for name output.\n"); 5124e5100ee2SJack F Vogel return (ENOMEM); 5125e5100ee2SJack F Vogel } 5126e5100ee2SJack F Vogel 5127e5100ee2SJack F Vogel sbuf_cat(buf, "\n"); 5128e5100ee2SJack F Vogel // Assuming <= 255 elements in switch 5129e5100ee2SJack F Vogel sbuf_printf(buf, "# of elements: %d\n", sw_config->header.num_reported); 5130e5100ee2SJack F Vogel /* Exclude: 5131e5100ee2SJack F Vogel ** Revision -- all elements are revision 1 for now 5132e5100ee2SJack F Vogel */ 5133e5100ee2SJack F Vogel sbuf_printf(buf, 5134e5100ee2SJack F Vogel "SEID ( Name ) | Uplink | Downlink | Conn Type\n" 5135e5100ee2SJack F Vogel " | | | (uplink)\n"); 5136e5100ee2SJack F Vogel for (int i = 0; i < sw_config->header.num_reported; i++) { 5137e5100ee2SJack F Vogel // "%4d (%8s) | %8s %8s %#8x", 5138e5100ee2SJack F Vogel sbuf_printf(buf, "%4d", sw_config->element[i].seid); 5139e5100ee2SJack F Vogel sbuf_cat(buf, " "); 514056c2c47bSJack F Vogel sbuf_printf(buf, "(%8s)", ixl_switch_element_string(nmbuf, 514156c2c47bSJack F Vogel sw_config->element[i].seid, false)); 5142e5100ee2SJack F Vogel sbuf_cat(buf, " | "); 514356c2c47bSJack F Vogel sbuf_printf(buf, "%8s", ixl_switch_element_string(nmbuf, 514456c2c47bSJack F Vogel sw_config->element[i].uplink_seid, true)); 5145e5100ee2SJack F Vogel sbuf_cat(buf, " "); 514656c2c47bSJack F Vogel sbuf_printf(buf, "%8s", ixl_switch_element_string(nmbuf, 514756c2c47bSJack F Vogel sw_config->element[i].downlink_seid, false)); 5148e5100ee2SJack F Vogel sbuf_cat(buf, " "); 5149e5100ee2SJack F Vogel sbuf_printf(buf, "%#8x", sw_config->element[i].connection_type); 5150e5100ee2SJack F Vogel if (i < sw_config->header.num_reported - 1) 5151e5100ee2SJack F Vogel sbuf_cat(buf, "\n"); 5152e5100ee2SJack F Vogel } 5153e5100ee2SJack F Vogel sbuf_delete(nmbuf); 5154e5100ee2SJack F Vogel 5155e5100ee2SJack F Vogel error = sbuf_finish(buf); 5156e5100ee2SJack F Vogel if (error) { 5157e5100ee2SJack F Vogel device_printf(dev, "Error finishing sbuf: %d\n", error); 5158e5100ee2SJack F Vogel sbuf_delete(buf); 5159e5100ee2SJack F Vogel return error; 5160e5100ee2SJack F Vogel } 5161e5100ee2SJack F Vogel 5162e5100ee2SJack F Vogel error = sysctl_handle_string(oidp, sbuf_data(buf), sbuf_len(buf), req); 5163e5100ee2SJack F Vogel if (error) 5164e5100ee2SJack F Vogel device_printf(dev, "sysctl error: %d\n", error); 5165e5100ee2SJack F Vogel sbuf_delete(buf); 5166e5100ee2SJack F Vogel 5167e5100ee2SJack F Vogel return (error); 516861ae650dSJack F Vogel } 5169393c4bb1SJack F Vogel #endif /* IXL_DEBUG_SYSCTL */ 517061ae650dSJack F Vogel 517156c2c47bSJack F Vogel 517256c2c47bSJack F Vogel #ifdef PCI_IOV 517356c2c47bSJack F Vogel static int 517456c2c47bSJack F Vogel ixl_vf_alloc_vsi(struct ixl_pf *pf, struct ixl_vf *vf) 517556c2c47bSJack F Vogel { 517656c2c47bSJack F Vogel struct i40e_hw *hw; 517756c2c47bSJack F Vogel struct ixl_vsi *vsi; 517856c2c47bSJack F Vogel struct i40e_vsi_context vsi_ctx; 517956c2c47bSJack F Vogel int i; 518056c2c47bSJack F Vogel uint16_t first_queue; 518156c2c47bSJack F Vogel enum i40e_status_code code; 518256c2c47bSJack F Vogel 518356c2c47bSJack F Vogel hw = &pf->hw; 518456c2c47bSJack F Vogel vsi = &pf->vsi; 518556c2c47bSJack F Vogel 518656c2c47bSJack F Vogel vsi_ctx.pf_num = hw->pf_id; 518756c2c47bSJack F Vogel vsi_ctx.uplink_seid = pf->veb_seid; 518856c2c47bSJack F Vogel vsi_ctx.connection_type = IXL_VSI_DATA_PORT; 518956c2c47bSJack F Vogel vsi_ctx.vf_num = hw->func_caps.vf_base_id + vf->vf_num; 519056c2c47bSJack F Vogel vsi_ctx.flags = I40E_AQ_VSI_TYPE_VF; 519156c2c47bSJack F Vogel 519256c2c47bSJack F Vogel bzero(&vsi_ctx.info, sizeof(vsi_ctx.info)); 519356c2c47bSJack F Vogel 519456c2c47bSJack F Vogel vsi_ctx.info.valid_sections = htole16(I40E_AQ_VSI_PROP_SWITCH_VALID); 519556c2c47bSJack F Vogel vsi_ctx.info.switch_id = htole16(0); 519656c2c47bSJack F Vogel 519756c2c47bSJack F Vogel vsi_ctx.info.valid_sections |= htole16(I40E_AQ_VSI_PROP_SECURITY_VALID); 519856c2c47bSJack F Vogel vsi_ctx.info.sec_flags = 0; 519956c2c47bSJack F Vogel if (vf->vf_flags & VF_FLAG_MAC_ANTI_SPOOF) 520056c2c47bSJack F Vogel vsi_ctx.info.sec_flags |= I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK; 520156c2c47bSJack F Vogel 520256c2c47bSJack F Vogel vsi_ctx.info.valid_sections |= htole16(I40E_AQ_VSI_PROP_VLAN_VALID); 520356c2c47bSJack F Vogel vsi_ctx.info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | 520456c2c47bSJack F Vogel I40E_AQ_VSI_PVLAN_EMOD_NOTHING; 520556c2c47bSJack F Vogel 520656c2c47bSJack F Vogel vsi_ctx.info.valid_sections |= 520756c2c47bSJack F Vogel htole16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID); 520856c2c47bSJack F Vogel vsi_ctx.info.mapping_flags = htole16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); 520956c2c47bSJack F Vogel first_queue = vsi->num_queues + vf->vf_num * IXLV_MAX_QUEUES; 521056c2c47bSJack F Vogel for (i = 0; i < IXLV_MAX_QUEUES; i++) 521156c2c47bSJack F Vogel vsi_ctx.info.queue_mapping[i] = htole16(first_queue + i); 521256c2c47bSJack F Vogel for (; i < nitems(vsi_ctx.info.queue_mapping); i++) 521356c2c47bSJack F Vogel vsi_ctx.info.queue_mapping[i] = htole16(I40E_AQ_VSI_QUEUE_MASK); 521456c2c47bSJack F Vogel 521556c2c47bSJack F Vogel vsi_ctx.info.tc_mapping[0] = htole16( 521656c2c47bSJack F Vogel (0 << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | 521756c2c47bSJack F Vogel (1 << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT)); 521856c2c47bSJack F Vogel 521956c2c47bSJack F Vogel code = i40e_aq_add_vsi(hw, &vsi_ctx, NULL); 522056c2c47bSJack F Vogel if (code != I40E_SUCCESS) 522156c2c47bSJack F Vogel return (ixl_adminq_err_to_errno(hw->aq.asq_last_status)); 522256c2c47bSJack F Vogel vf->vsi.seid = vsi_ctx.seid; 522356c2c47bSJack F Vogel vf->vsi.vsi_num = vsi_ctx.vsi_number; 522456c2c47bSJack F Vogel vf->vsi.first_queue = first_queue; 522556c2c47bSJack F Vogel vf->vsi.num_queues = IXLV_MAX_QUEUES; 522656c2c47bSJack F Vogel 522756c2c47bSJack F Vogel code = i40e_aq_get_vsi_params(hw, &vsi_ctx, NULL); 522856c2c47bSJack F Vogel if (code != I40E_SUCCESS) 522956c2c47bSJack F Vogel return (ixl_adminq_err_to_errno(hw->aq.asq_last_status)); 523056c2c47bSJack F Vogel 523156c2c47bSJack F Vogel code = i40e_aq_config_vsi_bw_limit(hw, vf->vsi.seid, 0, 0, NULL); 523256c2c47bSJack F Vogel if (code != I40E_SUCCESS) { 523356c2c47bSJack F Vogel device_printf(pf->dev, "Failed to disable BW limit: %d\n", 523456c2c47bSJack F Vogel ixl_adminq_err_to_errno(hw->aq.asq_last_status)); 523556c2c47bSJack F Vogel return (ixl_adminq_err_to_errno(hw->aq.asq_last_status)); 523656c2c47bSJack F Vogel } 523756c2c47bSJack F Vogel 523856c2c47bSJack F Vogel memcpy(&vf->vsi.info, &vsi_ctx.info, sizeof(vf->vsi.info)); 523956c2c47bSJack F Vogel return (0); 524056c2c47bSJack F Vogel } 524156c2c47bSJack F Vogel 524256c2c47bSJack F Vogel static int 524356c2c47bSJack F Vogel ixl_vf_setup_vsi(struct ixl_pf *pf, struct ixl_vf *vf) 524456c2c47bSJack F Vogel { 524556c2c47bSJack F Vogel struct i40e_hw *hw; 524656c2c47bSJack F Vogel int error; 524756c2c47bSJack F Vogel 524856c2c47bSJack F Vogel hw = &pf->hw; 524956c2c47bSJack F Vogel 525056c2c47bSJack F Vogel error = ixl_vf_alloc_vsi(pf, vf); 525156c2c47bSJack F Vogel if (error != 0) 525256c2c47bSJack F Vogel return (error); 525356c2c47bSJack F Vogel 525456c2c47bSJack F Vogel vf->vsi.hw_filters_add = 0; 525556c2c47bSJack F Vogel vf->vsi.hw_filters_del = 0; 525656c2c47bSJack F Vogel ixl_add_filter(&vf->vsi, ixl_bcast_addr, IXL_VLAN_ANY); 525756c2c47bSJack F Vogel ixl_reconfigure_filters(&vf->vsi); 525856c2c47bSJack F Vogel 525956c2c47bSJack F Vogel return (0); 526056c2c47bSJack F Vogel } 526156c2c47bSJack F Vogel 526256c2c47bSJack F Vogel static void 526356c2c47bSJack F Vogel ixl_vf_map_vsi_queue(struct i40e_hw *hw, struct ixl_vf *vf, int qnum, 526456c2c47bSJack F Vogel uint32_t val) 526556c2c47bSJack F Vogel { 526656c2c47bSJack F Vogel uint32_t qtable; 526756c2c47bSJack F Vogel int index, shift; 526856c2c47bSJack F Vogel 526956c2c47bSJack F Vogel /* 527056c2c47bSJack F Vogel * Two queues are mapped in a single register, so we have to do some 527156c2c47bSJack F Vogel * gymnastics to convert the queue number into a register index and 527256c2c47bSJack F Vogel * shift. 527356c2c47bSJack F Vogel */ 527456c2c47bSJack F Vogel index = qnum / 2; 527556c2c47bSJack F Vogel shift = (qnum % 2) * I40E_VSILAN_QTABLE_QINDEX_1_SHIFT; 527656c2c47bSJack F Vogel 527756c2c47bSJack F Vogel qtable = rd32(hw, I40E_VSILAN_QTABLE(index, vf->vsi.vsi_num)); 527856c2c47bSJack F Vogel qtable &= ~(I40E_VSILAN_QTABLE_QINDEX_0_MASK << shift); 527956c2c47bSJack F Vogel qtable |= val << shift; 528056c2c47bSJack F Vogel wr32(hw, I40E_VSILAN_QTABLE(index, vf->vsi.vsi_num), qtable); 528156c2c47bSJack F Vogel } 528256c2c47bSJack F Vogel 528356c2c47bSJack F Vogel static void 528456c2c47bSJack F Vogel ixl_vf_map_queues(struct ixl_pf *pf, struct ixl_vf *vf) 528556c2c47bSJack F Vogel { 528656c2c47bSJack F Vogel struct i40e_hw *hw; 528756c2c47bSJack F Vogel uint32_t qtable; 528856c2c47bSJack F Vogel int i; 528956c2c47bSJack F Vogel 529056c2c47bSJack F Vogel hw = &pf->hw; 529156c2c47bSJack F Vogel 529256c2c47bSJack F Vogel /* 529356c2c47bSJack F Vogel * Contiguous mappings aren't actually supported by the hardware, 529456c2c47bSJack F Vogel * so we have to use non-contiguous mappings. 529556c2c47bSJack F Vogel */ 529656c2c47bSJack F Vogel wr32(hw, I40E_VSILAN_QBASE(vf->vsi.vsi_num), 529756c2c47bSJack F Vogel I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK); 529856c2c47bSJack F Vogel 529956c2c47bSJack F Vogel wr32(hw, I40E_VPLAN_MAPENA(vf->vf_num), 530056c2c47bSJack F Vogel I40E_VPLAN_MAPENA_TXRX_ENA_MASK); 530156c2c47bSJack F Vogel 530256c2c47bSJack F Vogel for (i = 0; i < vf->vsi.num_queues; i++) { 530356c2c47bSJack F Vogel qtable = (vf->vsi.first_queue + i) << 530456c2c47bSJack F Vogel I40E_VPLAN_QTABLE_QINDEX_SHIFT; 530556c2c47bSJack F Vogel 530656c2c47bSJack F Vogel wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_num), qtable); 530756c2c47bSJack F Vogel } 530856c2c47bSJack F Vogel 530956c2c47bSJack F Vogel /* Map queues allocated to VF to its VSI. */ 531056c2c47bSJack F Vogel for (i = 0; i < vf->vsi.num_queues; i++) 531156c2c47bSJack F Vogel ixl_vf_map_vsi_queue(hw, vf, i, vf->vsi.first_queue + i); 531256c2c47bSJack F Vogel 531356c2c47bSJack F Vogel /* Set rest of VSI queues as unused. */ 531456c2c47bSJack F Vogel for (; i < IXL_MAX_VSI_QUEUES; i++) 531556c2c47bSJack F Vogel ixl_vf_map_vsi_queue(hw, vf, i, 531656c2c47bSJack F Vogel I40E_VSILAN_QTABLE_QINDEX_0_MASK); 531756c2c47bSJack F Vogel 531856c2c47bSJack F Vogel ixl_flush(hw); 531956c2c47bSJack F Vogel } 532056c2c47bSJack F Vogel 532156c2c47bSJack F Vogel static void 532256c2c47bSJack F Vogel ixl_vf_vsi_release(struct ixl_pf *pf, struct ixl_vsi *vsi) 532356c2c47bSJack F Vogel { 532456c2c47bSJack F Vogel struct i40e_hw *hw; 532556c2c47bSJack F Vogel 532656c2c47bSJack F Vogel hw = &pf->hw; 532756c2c47bSJack F Vogel 532856c2c47bSJack F Vogel if (vsi->seid == 0) 532956c2c47bSJack F Vogel return; 533056c2c47bSJack F Vogel 533156c2c47bSJack F Vogel i40e_aq_delete_element(hw, vsi->seid, NULL); 533256c2c47bSJack F Vogel } 533356c2c47bSJack F Vogel 533456c2c47bSJack F Vogel static void 533556c2c47bSJack F Vogel ixl_vf_disable_queue_intr(struct i40e_hw *hw, uint32_t vfint_reg) 533656c2c47bSJack F Vogel { 533756c2c47bSJack F Vogel 533856c2c47bSJack F Vogel wr32(hw, vfint_reg, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK); 533956c2c47bSJack F Vogel ixl_flush(hw); 534056c2c47bSJack F Vogel } 534156c2c47bSJack F Vogel 534256c2c47bSJack F Vogel static void 534356c2c47bSJack F Vogel ixl_vf_unregister_intr(struct i40e_hw *hw, uint32_t vpint_reg) 534456c2c47bSJack F Vogel { 534556c2c47bSJack F Vogel 534656c2c47bSJack F Vogel wr32(hw, vpint_reg, I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK | 534756c2c47bSJack F Vogel I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK); 534856c2c47bSJack F Vogel ixl_flush(hw); 534956c2c47bSJack F Vogel } 535056c2c47bSJack F Vogel 535156c2c47bSJack F Vogel static void 535256c2c47bSJack F Vogel ixl_vf_release_resources(struct ixl_pf *pf, struct ixl_vf *vf) 535356c2c47bSJack F Vogel { 535456c2c47bSJack F Vogel struct i40e_hw *hw; 535556c2c47bSJack F Vogel uint32_t vfint_reg, vpint_reg; 535656c2c47bSJack F Vogel int i; 535756c2c47bSJack F Vogel 535856c2c47bSJack F Vogel hw = &pf->hw; 535956c2c47bSJack F Vogel 536056c2c47bSJack F Vogel ixl_vf_vsi_release(pf, &vf->vsi); 536156c2c47bSJack F Vogel 536256c2c47bSJack F Vogel /* Index 0 has a special register. */ 536356c2c47bSJack F Vogel ixl_vf_disable_queue_intr(hw, I40E_VFINT_DYN_CTL0(vf->vf_num)); 536456c2c47bSJack F Vogel 536556c2c47bSJack F Vogel for (i = 1; i < hw->func_caps.num_msix_vectors_vf; i++) { 536656c2c47bSJack F Vogel vfint_reg = IXL_VFINT_DYN_CTLN_REG(hw, i , vf->vf_num); 536756c2c47bSJack F Vogel ixl_vf_disable_queue_intr(hw, vfint_reg); 536856c2c47bSJack F Vogel } 536956c2c47bSJack F Vogel 537056c2c47bSJack F Vogel /* Index 0 has a special register. */ 537156c2c47bSJack F Vogel ixl_vf_unregister_intr(hw, I40E_VPINT_LNKLST0(vf->vf_num)); 537256c2c47bSJack F Vogel 537356c2c47bSJack F Vogel for (i = 1; i < hw->func_caps.num_msix_vectors_vf; i++) { 537456c2c47bSJack F Vogel vpint_reg = IXL_VPINT_LNKLSTN_REG(hw, i, vf->vf_num); 537556c2c47bSJack F Vogel ixl_vf_unregister_intr(hw, vpint_reg); 537656c2c47bSJack F Vogel } 537756c2c47bSJack F Vogel 537856c2c47bSJack F Vogel vf->vsi.num_queues = 0; 537956c2c47bSJack F Vogel } 538056c2c47bSJack F Vogel 538156c2c47bSJack F Vogel static int 538256c2c47bSJack F Vogel ixl_flush_pcie(struct ixl_pf *pf, struct ixl_vf *vf) 538356c2c47bSJack F Vogel { 538456c2c47bSJack F Vogel struct i40e_hw *hw; 538556c2c47bSJack F Vogel int i; 538656c2c47bSJack F Vogel uint16_t global_vf_num; 538756c2c47bSJack F Vogel uint32_t ciad; 538856c2c47bSJack F Vogel 538956c2c47bSJack F Vogel hw = &pf->hw; 539056c2c47bSJack F Vogel global_vf_num = hw->func_caps.vf_base_id + vf->vf_num; 539156c2c47bSJack F Vogel 539256c2c47bSJack F Vogel wr32(hw, I40E_PF_PCI_CIAA, IXL_PF_PCI_CIAA_VF_DEVICE_STATUS | 539356c2c47bSJack F Vogel (global_vf_num << I40E_PF_PCI_CIAA_VF_NUM_SHIFT)); 539456c2c47bSJack F Vogel for (i = 0; i < IXL_VF_RESET_TIMEOUT; i++) { 539556c2c47bSJack F Vogel ciad = rd32(hw, I40E_PF_PCI_CIAD); 539656c2c47bSJack F Vogel if ((ciad & IXL_PF_PCI_CIAD_VF_TRANS_PENDING_MASK) == 0) 539756c2c47bSJack F Vogel return (0); 539856c2c47bSJack F Vogel DELAY(1); 539956c2c47bSJack F Vogel } 540056c2c47bSJack F Vogel 540156c2c47bSJack F Vogel return (ETIMEDOUT); 540256c2c47bSJack F Vogel } 540356c2c47bSJack F Vogel 540456c2c47bSJack F Vogel static void 540556c2c47bSJack F Vogel ixl_reset_vf(struct ixl_pf *pf, struct ixl_vf *vf) 540656c2c47bSJack F Vogel { 540756c2c47bSJack F Vogel struct i40e_hw *hw; 540856c2c47bSJack F Vogel uint32_t vfrtrig; 540956c2c47bSJack F Vogel 541056c2c47bSJack F Vogel hw = &pf->hw; 541156c2c47bSJack F Vogel 541256c2c47bSJack F Vogel vfrtrig = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_num)); 541356c2c47bSJack F Vogel vfrtrig |= I40E_VPGEN_VFRTRIG_VFSWR_MASK; 541456c2c47bSJack F Vogel wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_num), vfrtrig); 541556c2c47bSJack F Vogel ixl_flush(hw); 541656c2c47bSJack F Vogel 541756c2c47bSJack F Vogel ixl_reinit_vf(pf, vf); 541856c2c47bSJack F Vogel } 541956c2c47bSJack F Vogel 542056c2c47bSJack F Vogel static void 542156c2c47bSJack F Vogel ixl_reinit_vf(struct ixl_pf *pf, struct ixl_vf *vf) 542256c2c47bSJack F Vogel { 542356c2c47bSJack F Vogel struct i40e_hw *hw; 542456c2c47bSJack F Vogel uint32_t vfrstat, vfrtrig; 542556c2c47bSJack F Vogel int i, error; 542656c2c47bSJack F Vogel 542756c2c47bSJack F Vogel hw = &pf->hw; 542856c2c47bSJack F Vogel 542956c2c47bSJack F Vogel error = ixl_flush_pcie(pf, vf); 543056c2c47bSJack F Vogel if (error != 0) 543156c2c47bSJack F Vogel device_printf(pf->dev, 543256c2c47bSJack F Vogel "Timed out waiting for PCIe activity to stop on VF-%d\n", 543356c2c47bSJack F Vogel vf->vf_num); 543456c2c47bSJack F Vogel 543556c2c47bSJack F Vogel for (i = 0; i < IXL_VF_RESET_TIMEOUT; i++) { 543656c2c47bSJack F Vogel DELAY(10); 543756c2c47bSJack F Vogel 543856c2c47bSJack F Vogel vfrstat = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_num)); 543956c2c47bSJack F Vogel if (vfrstat & I40E_VPGEN_VFRSTAT_VFRD_MASK) 544056c2c47bSJack F Vogel break; 544156c2c47bSJack F Vogel } 544256c2c47bSJack F Vogel 544356c2c47bSJack F Vogel if (i == IXL_VF_RESET_TIMEOUT) 544456c2c47bSJack F Vogel device_printf(pf->dev, "VF %d failed to reset\n", vf->vf_num); 544556c2c47bSJack F Vogel 544656c2c47bSJack F Vogel wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_num), I40E_VFR_COMPLETED); 544756c2c47bSJack F Vogel 544856c2c47bSJack F Vogel vfrtrig = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_num)); 544956c2c47bSJack F Vogel vfrtrig &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK; 545056c2c47bSJack F Vogel wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_num), vfrtrig); 545156c2c47bSJack F Vogel 545256c2c47bSJack F Vogel if (vf->vsi.seid != 0) 545356c2c47bSJack F Vogel ixl_disable_rings(&vf->vsi); 545456c2c47bSJack F Vogel 545556c2c47bSJack F Vogel ixl_vf_release_resources(pf, vf); 545656c2c47bSJack F Vogel ixl_vf_setup_vsi(pf, vf); 545756c2c47bSJack F Vogel ixl_vf_map_queues(pf, vf); 545856c2c47bSJack F Vogel 545956c2c47bSJack F Vogel wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_num), I40E_VFR_VFACTIVE); 546056c2c47bSJack F Vogel ixl_flush(hw); 546156c2c47bSJack F Vogel } 546256c2c47bSJack F Vogel 546356c2c47bSJack F Vogel static const char * 546456c2c47bSJack F Vogel ixl_vc_opcode_str(uint16_t op) 546556c2c47bSJack F Vogel { 546656c2c47bSJack F Vogel 546756c2c47bSJack F Vogel switch (op) { 546856c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_VERSION: 546956c2c47bSJack F Vogel return ("VERSION"); 547056c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_RESET_VF: 547156c2c47bSJack F Vogel return ("RESET_VF"); 547256c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: 547356c2c47bSJack F Vogel return ("GET_VF_RESOURCES"); 547456c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE: 547556c2c47bSJack F Vogel return ("CONFIG_TX_QUEUE"); 547656c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE: 547756c2c47bSJack F Vogel return ("CONFIG_RX_QUEUE"); 547856c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES: 547956c2c47bSJack F Vogel return ("CONFIG_VSI_QUEUES"); 548056c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP: 548156c2c47bSJack F Vogel return ("CONFIG_IRQ_MAP"); 548256c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_ENABLE_QUEUES: 548356c2c47bSJack F Vogel return ("ENABLE_QUEUES"); 548456c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_DISABLE_QUEUES: 548556c2c47bSJack F Vogel return ("DISABLE_QUEUES"); 548656c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS: 548756c2c47bSJack F Vogel return ("ADD_ETHER_ADDRESS"); 548856c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS: 548956c2c47bSJack F Vogel return ("DEL_ETHER_ADDRESS"); 549056c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_ADD_VLAN: 549156c2c47bSJack F Vogel return ("ADD_VLAN"); 549256c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_DEL_VLAN: 549356c2c47bSJack F Vogel return ("DEL_VLAN"); 549456c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: 549556c2c47bSJack F Vogel return ("CONFIG_PROMISCUOUS_MODE"); 549656c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_GET_STATS: 549756c2c47bSJack F Vogel return ("GET_STATS"); 549856c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_FCOE: 549956c2c47bSJack F Vogel return ("FCOE"); 550056c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_EVENT: 550156c2c47bSJack F Vogel return ("EVENT"); 550256c2c47bSJack F Vogel default: 550356c2c47bSJack F Vogel return ("UNKNOWN"); 550456c2c47bSJack F Vogel } 550556c2c47bSJack F Vogel } 550656c2c47bSJack F Vogel 550756c2c47bSJack F Vogel static int 550856c2c47bSJack F Vogel ixl_vc_opcode_level(uint16_t opcode) 550956c2c47bSJack F Vogel { 551056c2c47bSJack F Vogel 551156c2c47bSJack F Vogel switch (opcode) { 551256c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_GET_STATS: 551356c2c47bSJack F Vogel return (10); 551456c2c47bSJack F Vogel default: 551556c2c47bSJack F Vogel return (5); 551656c2c47bSJack F Vogel } 551756c2c47bSJack F Vogel } 551856c2c47bSJack F Vogel 551956c2c47bSJack F Vogel static void 552056c2c47bSJack F Vogel ixl_send_vf_msg(struct ixl_pf *pf, struct ixl_vf *vf, uint16_t op, 552156c2c47bSJack F Vogel enum i40e_status_code status, void *msg, uint16_t len) 552256c2c47bSJack F Vogel { 552356c2c47bSJack F Vogel struct i40e_hw *hw; 552456c2c47bSJack F Vogel int global_vf_id; 552556c2c47bSJack F Vogel 552656c2c47bSJack F Vogel hw = &pf->hw; 552756c2c47bSJack F Vogel global_vf_id = hw->func_caps.vf_base_id + vf->vf_num; 552856c2c47bSJack F Vogel 552956c2c47bSJack F Vogel I40E_VC_DEBUG(pf, ixl_vc_opcode_level(op), 553056c2c47bSJack F Vogel "Sending msg (op=%s[%d], status=%d) to VF-%d\n", 553156c2c47bSJack F Vogel ixl_vc_opcode_str(op), op, status, vf->vf_num); 553256c2c47bSJack F Vogel 553356c2c47bSJack F Vogel i40e_aq_send_msg_to_vf(hw, global_vf_id, op, status, msg, len, NULL); 553456c2c47bSJack F Vogel } 553556c2c47bSJack F Vogel 553656c2c47bSJack F Vogel static void 553756c2c47bSJack F Vogel ixl_send_vf_ack(struct ixl_pf *pf, struct ixl_vf *vf, uint16_t op) 553856c2c47bSJack F Vogel { 553956c2c47bSJack F Vogel 554056c2c47bSJack F Vogel ixl_send_vf_msg(pf, vf, op, I40E_SUCCESS, NULL, 0); 554156c2c47bSJack F Vogel } 554256c2c47bSJack F Vogel 554356c2c47bSJack F Vogel static void 554456c2c47bSJack F Vogel ixl_send_vf_nack_msg(struct ixl_pf *pf, struct ixl_vf *vf, uint16_t op, 554556c2c47bSJack F Vogel enum i40e_status_code status, const char *file, int line) 554656c2c47bSJack F Vogel { 554756c2c47bSJack F Vogel 554856c2c47bSJack F Vogel I40E_VC_DEBUG(pf, 1, 554956c2c47bSJack F Vogel "Sending NACK (op=%s[%d], err=%d) to VF-%d from %s:%d\n", 555056c2c47bSJack F Vogel ixl_vc_opcode_str(op), op, status, vf->vf_num, file, line); 555156c2c47bSJack F Vogel ixl_send_vf_msg(pf, vf, op, status, NULL, 0); 555256c2c47bSJack F Vogel } 555356c2c47bSJack F Vogel 555456c2c47bSJack F Vogel static void 555556c2c47bSJack F Vogel ixl_vf_version_msg(struct ixl_pf *pf, struct ixl_vf *vf, void *msg, 555656c2c47bSJack F Vogel uint16_t msg_size) 555756c2c47bSJack F Vogel { 555856c2c47bSJack F Vogel struct i40e_virtchnl_version_info reply; 555956c2c47bSJack F Vogel 556056c2c47bSJack F Vogel if (msg_size != sizeof(struct i40e_virtchnl_version_info)) { 556156c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_VERSION, 556256c2c47bSJack F Vogel I40E_ERR_PARAM); 556356c2c47bSJack F Vogel return; 556456c2c47bSJack F Vogel } 556556c2c47bSJack F Vogel 556656c2c47bSJack F Vogel reply.major = I40E_VIRTCHNL_VERSION_MAJOR; 556756c2c47bSJack F Vogel reply.minor = I40E_VIRTCHNL_VERSION_MINOR; 556856c2c47bSJack F Vogel ixl_send_vf_msg(pf, vf, I40E_VIRTCHNL_OP_VERSION, I40E_SUCCESS, &reply, 556956c2c47bSJack F Vogel sizeof(reply)); 557056c2c47bSJack F Vogel } 557156c2c47bSJack F Vogel 557256c2c47bSJack F Vogel static void 557356c2c47bSJack F Vogel ixl_vf_reset_msg(struct ixl_pf *pf, struct ixl_vf *vf, void *msg, 557456c2c47bSJack F Vogel uint16_t msg_size) 557556c2c47bSJack F Vogel { 557656c2c47bSJack F Vogel 557756c2c47bSJack F Vogel if (msg_size != 0) { 557856c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_RESET_VF, 557956c2c47bSJack F Vogel I40E_ERR_PARAM); 558056c2c47bSJack F Vogel return; 558156c2c47bSJack F Vogel } 558256c2c47bSJack F Vogel 558356c2c47bSJack F Vogel ixl_reset_vf(pf, vf); 558456c2c47bSJack F Vogel 558556c2c47bSJack F Vogel /* No response to a reset message. */ 558656c2c47bSJack F Vogel } 558756c2c47bSJack F Vogel 558856c2c47bSJack F Vogel static void 558956c2c47bSJack F Vogel ixl_vf_get_resources_msg(struct ixl_pf *pf, struct ixl_vf *vf, void *msg, 559056c2c47bSJack F Vogel uint16_t msg_size) 559156c2c47bSJack F Vogel { 559256c2c47bSJack F Vogel struct i40e_virtchnl_vf_resource reply; 559356c2c47bSJack F Vogel 559456c2c47bSJack F Vogel if (msg_size != 0) { 559556c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES, 559656c2c47bSJack F Vogel I40E_ERR_PARAM); 559756c2c47bSJack F Vogel return; 559856c2c47bSJack F Vogel } 559956c2c47bSJack F Vogel 560056c2c47bSJack F Vogel bzero(&reply, sizeof(reply)); 560156c2c47bSJack F Vogel 560256c2c47bSJack F Vogel reply.vf_offload_flags = I40E_VIRTCHNL_VF_OFFLOAD_L2; 560356c2c47bSJack F Vogel 560456c2c47bSJack F Vogel reply.num_vsis = 1; 560556c2c47bSJack F Vogel reply.num_queue_pairs = vf->vsi.num_queues; 560656c2c47bSJack F Vogel reply.max_vectors = pf->hw.func_caps.num_msix_vectors_vf; 560756c2c47bSJack F Vogel reply.vsi_res[0].vsi_id = vf->vsi.vsi_num; 560856c2c47bSJack F Vogel reply.vsi_res[0].vsi_type = I40E_VSI_SRIOV; 560956c2c47bSJack F Vogel reply.vsi_res[0].num_queue_pairs = vf->vsi.num_queues; 561056c2c47bSJack F Vogel memcpy(reply.vsi_res[0].default_mac_addr, vf->mac, ETHER_ADDR_LEN); 561156c2c47bSJack F Vogel 561256c2c47bSJack F Vogel ixl_send_vf_msg(pf, vf, I40E_VIRTCHNL_OP_GET_VF_RESOURCES, 561356c2c47bSJack F Vogel I40E_SUCCESS, &reply, sizeof(reply)); 561456c2c47bSJack F Vogel } 561556c2c47bSJack F Vogel 561656c2c47bSJack F Vogel static int 561756c2c47bSJack F Vogel ixl_vf_config_tx_queue(struct ixl_pf *pf, struct ixl_vf *vf, 561856c2c47bSJack F Vogel struct i40e_virtchnl_txq_info *info) 561956c2c47bSJack F Vogel { 562056c2c47bSJack F Vogel struct i40e_hw *hw; 562156c2c47bSJack F Vogel struct i40e_hmc_obj_txq txq; 562256c2c47bSJack F Vogel uint16_t global_queue_num, global_vf_num; 562356c2c47bSJack F Vogel enum i40e_status_code status; 562456c2c47bSJack F Vogel uint32_t qtx_ctl; 562556c2c47bSJack F Vogel 562656c2c47bSJack F Vogel hw = &pf->hw; 562756c2c47bSJack F Vogel global_queue_num = vf->vsi.first_queue + info->queue_id; 562856c2c47bSJack F Vogel global_vf_num = hw->func_caps.vf_base_id + vf->vf_num; 562956c2c47bSJack F Vogel bzero(&txq, sizeof(txq)); 563056c2c47bSJack F Vogel 563156c2c47bSJack F Vogel status = i40e_clear_lan_tx_queue_context(hw, global_queue_num); 563256c2c47bSJack F Vogel if (status != I40E_SUCCESS) 563356c2c47bSJack F Vogel return (EINVAL); 563456c2c47bSJack F Vogel 563556c2c47bSJack F Vogel txq.base = info->dma_ring_addr / IXL_TX_CTX_BASE_UNITS; 563656c2c47bSJack F Vogel 563756c2c47bSJack F Vogel txq.head_wb_ena = info->headwb_enabled; 563856c2c47bSJack F Vogel txq.head_wb_addr = info->dma_headwb_addr; 563956c2c47bSJack F Vogel txq.qlen = info->ring_len; 564056c2c47bSJack F Vogel txq.rdylist = le16_to_cpu(vf->vsi.info.qs_handle[0]); 564156c2c47bSJack F Vogel txq.rdylist_act = 0; 564256c2c47bSJack F Vogel 564356c2c47bSJack F Vogel status = i40e_set_lan_tx_queue_context(hw, global_queue_num, &txq); 564456c2c47bSJack F Vogel if (status != I40E_SUCCESS) 564556c2c47bSJack F Vogel return (EINVAL); 564656c2c47bSJack F Vogel 564756c2c47bSJack F Vogel qtx_ctl = I40E_QTX_CTL_VF_QUEUE | 564856c2c47bSJack F Vogel (hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) | 564956c2c47bSJack F Vogel (global_vf_num << I40E_QTX_CTL_VFVM_INDX_SHIFT); 565056c2c47bSJack F Vogel wr32(hw, I40E_QTX_CTL(global_queue_num), qtx_ctl); 565156c2c47bSJack F Vogel ixl_flush(hw); 565256c2c47bSJack F Vogel 565356c2c47bSJack F Vogel return (0); 565456c2c47bSJack F Vogel } 565556c2c47bSJack F Vogel 565656c2c47bSJack F Vogel static int 565756c2c47bSJack F Vogel ixl_vf_config_rx_queue(struct ixl_pf *pf, struct ixl_vf *vf, 565856c2c47bSJack F Vogel struct i40e_virtchnl_rxq_info *info) 565956c2c47bSJack F Vogel { 566056c2c47bSJack F Vogel struct i40e_hw *hw; 566156c2c47bSJack F Vogel struct i40e_hmc_obj_rxq rxq; 566256c2c47bSJack F Vogel uint16_t global_queue_num; 566356c2c47bSJack F Vogel enum i40e_status_code status; 566456c2c47bSJack F Vogel 566556c2c47bSJack F Vogel hw = &pf->hw; 566656c2c47bSJack F Vogel global_queue_num = vf->vsi.first_queue + info->queue_id; 566756c2c47bSJack F Vogel bzero(&rxq, sizeof(rxq)); 566856c2c47bSJack F Vogel 566956c2c47bSJack F Vogel if (info->databuffer_size > IXL_VF_MAX_BUFFER) 567056c2c47bSJack F Vogel return (EINVAL); 567156c2c47bSJack F Vogel 567256c2c47bSJack F Vogel if (info->max_pkt_size > IXL_VF_MAX_FRAME || 567356c2c47bSJack F Vogel info->max_pkt_size < ETHER_MIN_LEN) 567456c2c47bSJack F Vogel return (EINVAL); 567556c2c47bSJack F Vogel 567656c2c47bSJack F Vogel if (info->splithdr_enabled) { 567756c2c47bSJack F Vogel if (info->hdr_size > IXL_VF_MAX_HDR_BUFFER) 567856c2c47bSJack F Vogel return (EINVAL); 567956c2c47bSJack F Vogel 568056c2c47bSJack F Vogel rxq.hsplit_0 = info->rx_split_pos & 568156c2c47bSJack F Vogel (I40E_HMC_OBJ_RX_HSPLIT_0_SPLIT_L2 | 568256c2c47bSJack F Vogel I40E_HMC_OBJ_RX_HSPLIT_0_SPLIT_IP | 568356c2c47bSJack F Vogel I40E_HMC_OBJ_RX_HSPLIT_0_SPLIT_TCP_UDP | 568456c2c47bSJack F Vogel I40E_HMC_OBJ_RX_HSPLIT_0_SPLIT_SCTP); 568556c2c47bSJack F Vogel rxq.hbuff = info->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT; 568656c2c47bSJack F Vogel 568756c2c47bSJack F Vogel rxq.dtype = 2; 568856c2c47bSJack F Vogel } 568956c2c47bSJack F Vogel 569056c2c47bSJack F Vogel status = i40e_clear_lan_rx_queue_context(hw, global_queue_num); 569156c2c47bSJack F Vogel if (status != I40E_SUCCESS) 569256c2c47bSJack F Vogel return (EINVAL); 569356c2c47bSJack F Vogel 569456c2c47bSJack F Vogel rxq.base = info->dma_ring_addr / IXL_RX_CTX_BASE_UNITS; 569556c2c47bSJack F Vogel rxq.qlen = info->ring_len; 569656c2c47bSJack F Vogel 569756c2c47bSJack F Vogel rxq.dbuff = info->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT; 569856c2c47bSJack F Vogel 569956c2c47bSJack F Vogel rxq.dsize = 1; 570056c2c47bSJack F Vogel rxq.crcstrip = 1; 570156c2c47bSJack F Vogel rxq.l2tsel = 1; 570256c2c47bSJack F Vogel 570356c2c47bSJack F Vogel rxq.rxmax = info->max_pkt_size; 570456c2c47bSJack F Vogel rxq.tphrdesc_ena = 1; 570556c2c47bSJack F Vogel rxq.tphwdesc_ena = 1; 570656c2c47bSJack F Vogel rxq.tphdata_ena = 1; 570756c2c47bSJack F Vogel rxq.tphhead_ena = 1; 570856c2c47bSJack F Vogel rxq.lrxqthresh = 2; 570956c2c47bSJack F Vogel rxq.prefena = 1; 571056c2c47bSJack F Vogel 571156c2c47bSJack F Vogel status = i40e_set_lan_rx_queue_context(hw, global_queue_num, &rxq); 571256c2c47bSJack F Vogel if (status != I40E_SUCCESS) 571356c2c47bSJack F Vogel return (EINVAL); 571456c2c47bSJack F Vogel 571556c2c47bSJack F Vogel return (0); 571656c2c47bSJack F Vogel } 571756c2c47bSJack F Vogel 571856c2c47bSJack F Vogel static void 571956c2c47bSJack F Vogel ixl_vf_config_vsi_msg(struct ixl_pf *pf, struct ixl_vf *vf, void *msg, 572056c2c47bSJack F Vogel uint16_t msg_size) 572156c2c47bSJack F Vogel { 572256c2c47bSJack F Vogel struct i40e_virtchnl_vsi_queue_config_info *info; 572356c2c47bSJack F Vogel struct i40e_virtchnl_queue_pair_info *pair; 572456c2c47bSJack F Vogel int i; 572556c2c47bSJack F Vogel 572656c2c47bSJack F Vogel if (msg_size < sizeof(*info)) { 572756c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES, 572856c2c47bSJack F Vogel I40E_ERR_PARAM); 572956c2c47bSJack F Vogel return; 573056c2c47bSJack F Vogel } 573156c2c47bSJack F Vogel 573256c2c47bSJack F Vogel info = msg; 573356c2c47bSJack F Vogel if (info->num_queue_pairs == 0) { 573456c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES, 573556c2c47bSJack F Vogel I40E_ERR_PARAM); 573656c2c47bSJack F Vogel return; 573756c2c47bSJack F Vogel } 573856c2c47bSJack F Vogel 573956c2c47bSJack F Vogel if (msg_size != sizeof(*info) + info->num_queue_pairs * sizeof(*pair)) { 574056c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES, 574156c2c47bSJack F Vogel I40E_ERR_PARAM); 574256c2c47bSJack F Vogel return; 574356c2c47bSJack F Vogel } 574456c2c47bSJack F Vogel 574556c2c47bSJack F Vogel if (info->vsi_id != vf->vsi.vsi_num) { 574656c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES, 574756c2c47bSJack F Vogel I40E_ERR_PARAM); 574856c2c47bSJack F Vogel return; 574956c2c47bSJack F Vogel } 575056c2c47bSJack F Vogel 575156c2c47bSJack F Vogel for (i = 0; i < info->num_queue_pairs; i++) { 575256c2c47bSJack F Vogel pair = &info->qpair[i]; 575356c2c47bSJack F Vogel 575456c2c47bSJack F Vogel if (pair->txq.vsi_id != vf->vsi.vsi_num || 575556c2c47bSJack F Vogel pair->rxq.vsi_id != vf->vsi.vsi_num || 575656c2c47bSJack F Vogel pair->txq.queue_id != pair->rxq.queue_id || 575756c2c47bSJack F Vogel pair->txq.queue_id >= vf->vsi.num_queues) { 575856c2c47bSJack F Vogel 575956c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, 576056c2c47bSJack F Vogel I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES, I40E_ERR_PARAM); 576156c2c47bSJack F Vogel return; 576256c2c47bSJack F Vogel } 576356c2c47bSJack F Vogel 576456c2c47bSJack F Vogel if (ixl_vf_config_tx_queue(pf, vf, &pair->txq) != 0) { 576556c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, 576656c2c47bSJack F Vogel I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES, I40E_ERR_PARAM); 576756c2c47bSJack F Vogel return; 576856c2c47bSJack F Vogel } 576956c2c47bSJack F Vogel 577056c2c47bSJack F Vogel if (ixl_vf_config_rx_queue(pf, vf, &pair->rxq) != 0) { 577156c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, 577256c2c47bSJack F Vogel I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES, I40E_ERR_PARAM); 577356c2c47bSJack F Vogel return; 577456c2c47bSJack F Vogel } 577556c2c47bSJack F Vogel } 577656c2c47bSJack F Vogel 577756c2c47bSJack F Vogel ixl_send_vf_ack(pf, vf, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES); 577856c2c47bSJack F Vogel } 577956c2c47bSJack F Vogel 578056c2c47bSJack F Vogel static void 578156c2c47bSJack F Vogel ixl_vf_set_qctl(struct ixl_pf *pf, 578256c2c47bSJack F Vogel const struct i40e_virtchnl_vector_map *vector, 578356c2c47bSJack F Vogel enum i40e_queue_type cur_type, uint16_t cur_queue, 578456c2c47bSJack F Vogel enum i40e_queue_type *last_type, uint16_t *last_queue) 578556c2c47bSJack F Vogel { 578656c2c47bSJack F Vogel uint32_t offset, qctl; 578756c2c47bSJack F Vogel uint16_t itr_indx; 578856c2c47bSJack F Vogel 578956c2c47bSJack F Vogel if (cur_type == I40E_QUEUE_TYPE_RX) { 579056c2c47bSJack F Vogel offset = I40E_QINT_RQCTL(cur_queue); 579156c2c47bSJack F Vogel itr_indx = vector->rxitr_idx; 579256c2c47bSJack F Vogel } else { 579356c2c47bSJack F Vogel offset = I40E_QINT_TQCTL(cur_queue); 579456c2c47bSJack F Vogel itr_indx = vector->txitr_idx; 579556c2c47bSJack F Vogel } 579656c2c47bSJack F Vogel 579756c2c47bSJack F Vogel qctl = htole32((vector->vector_id << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | 579856c2c47bSJack F Vogel (*last_type << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) | 579956c2c47bSJack F Vogel (*last_queue << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) | 580056c2c47bSJack F Vogel I40E_QINT_RQCTL_CAUSE_ENA_MASK | 580156c2c47bSJack F Vogel (itr_indx << I40E_QINT_RQCTL_ITR_INDX_SHIFT)); 580256c2c47bSJack F Vogel 580356c2c47bSJack F Vogel wr32(&pf->hw, offset, qctl); 580456c2c47bSJack F Vogel 580556c2c47bSJack F Vogel *last_type = cur_type; 580656c2c47bSJack F Vogel *last_queue = cur_queue; 580756c2c47bSJack F Vogel } 580856c2c47bSJack F Vogel 580956c2c47bSJack F Vogel static void 581056c2c47bSJack F Vogel ixl_vf_config_vector(struct ixl_pf *pf, struct ixl_vf *vf, 581156c2c47bSJack F Vogel const struct i40e_virtchnl_vector_map *vector) 581256c2c47bSJack F Vogel { 581356c2c47bSJack F Vogel struct i40e_hw *hw; 581456c2c47bSJack F Vogel u_int qindex; 581556c2c47bSJack F Vogel enum i40e_queue_type type, last_type; 581656c2c47bSJack F Vogel uint32_t lnklst_reg; 581756c2c47bSJack F Vogel uint16_t rxq_map, txq_map, cur_queue, last_queue; 581856c2c47bSJack F Vogel 581956c2c47bSJack F Vogel hw = &pf->hw; 582056c2c47bSJack F Vogel 582156c2c47bSJack F Vogel rxq_map = vector->rxq_map; 582256c2c47bSJack F Vogel txq_map = vector->txq_map; 582356c2c47bSJack F Vogel 582456c2c47bSJack F Vogel last_queue = IXL_END_OF_INTR_LNKLST; 582556c2c47bSJack F Vogel last_type = I40E_QUEUE_TYPE_RX; 582656c2c47bSJack F Vogel 582756c2c47bSJack F Vogel /* 582856c2c47bSJack F Vogel * The datasheet says to optimize performance, RX queues and TX queues 582956c2c47bSJack F Vogel * should be interleaved in the interrupt linked list, so we process 583056c2c47bSJack F Vogel * both at once here. 583156c2c47bSJack F Vogel */ 583256c2c47bSJack F Vogel while ((rxq_map != 0) || (txq_map != 0)) { 583356c2c47bSJack F Vogel if (txq_map != 0) { 583456c2c47bSJack F Vogel qindex = ffs(txq_map) - 1; 583556c2c47bSJack F Vogel type = I40E_QUEUE_TYPE_TX; 583656c2c47bSJack F Vogel cur_queue = vf->vsi.first_queue + qindex; 583756c2c47bSJack F Vogel ixl_vf_set_qctl(pf, vector, type, cur_queue, 583856c2c47bSJack F Vogel &last_type, &last_queue); 583956c2c47bSJack F Vogel txq_map &= ~(1 << qindex); 584056c2c47bSJack F Vogel } 584156c2c47bSJack F Vogel 584256c2c47bSJack F Vogel if (rxq_map != 0) { 584356c2c47bSJack F Vogel qindex = ffs(rxq_map) - 1; 584456c2c47bSJack F Vogel type = I40E_QUEUE_TYPE_RX; 584556c2c47bSJack F Vogel cur_queue = vf->vsi.first_queue + qindex; 584656c2c47bSJack F Vogel ixl_vf_set_qctl(pf, vector, type, cur_queue, 584756c2c47bSJack F Vogel &last_type, &last_queue); 584856c2c47bSJack F Vogel rxq_map &= ~(1 << qindex); 584956c2c47bSJack F Vogel } 585056c2c47bSJack F Vogel } 585156c2c47bSJack F Vogel 585256c2c47bSJack F Vogel if (vector->vector_id == 0) 585356c2c47bSJack F Vogel lnklst_reg = I40E_VPINT_LNKLST0(vf->vf_num); 585456c2c47bSJack F Vogel else 585556c2c47bSJack F Vogel lnklst_reg = IXL_VPINT_LNKLSTN_REG(hw, vector->vector_id, 585656c2c47bSJack F Vogel vf->vf_num); 585756c2c47bSJack F Vogel wr32(hw, lnklst_reg, 585856c2c47bSJack F Vogel (last_queue << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT) | 585956c2c47bSJack F Vogel (last_type << I40E_VPINT_LNKLST0_FIRSTQ_TYPE_SHIFT)); 586056c2c47bSJack F Vogel 586156c2c47bSJack F Vogel ixl_flush(hw); 586256c2c47bSJack F Vogel } 586356c2c47bSJack F Vogel 586456c2c47bSJack F Vogel static void 586556c2c47bSJack F Vogel ixl_vf_config_irq_msg(struct ixl_pf *pf, struct ixl_vf *vf, void *msg, 586656c2c47bSJack F Vogel uint16_t msg_size) 586756c2c47bSJack F Vogel { 586856c2c47bSJack F Vogel struct i40e_virtchnl_irq_map_info *map; 586956c2c47bSJack F Vogel struct i40e_virtchnl_vector_map *vector; 587056c2c47bSJack F Vogel struct i40e_hw *hw; 587156c2c47bSJack F Vogel int i, largest_txq, largest_rxq; 587256c2c47bSJack F Vogel 587356c2c47bSJack F Vogel hw = &pf->hw; 587456c2c47bSJack F Vogel 587556c2c47bSJack F Vogel if (msg_size < sizeof(*map)) { 587656c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP, 587756c2c47bSJack F Vogel I40E_ERR_PARAM); 587856c2c47bSJack F Vogel return; 587956c2c47bSJack F Vogel } 588056c2c47bSJack F Vogel 588156c2c47bSJack F Vogel map = msg; 588256c2c47bSJack F Vogel if (map->num_vectors == 0) { 588356c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP, 588456c2c47bSJack F Vogel I40E_ERR_PARAM); 588556c2c47bSJack F Vogel return; 588656c2c47bSJack F Vogel } 588756c2c47bSJack F Vogel 588856c2c47bSJack F Vogel if (msg_size != sizeof(*map) + map->num_vectors * sizeof(*vector)) { 588956c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP, 589056c2c47bSJack F Vogel I40E_ERR_PARAM); 589156c2c47bSJack F Vogel return; 589256c2c47bSJack F Vogel } 589356c2c47bSJack F Vogel 589456c2c47bSJack F Vogel for (i = 0; i < map->num_vectors; i++) { 589556c2c47bSJack F Vogel vector = &map->vecmap[i]; 589656c2c47bSJack F Vogel 589756c2c47bSJack F Vogel if ((vector->vector_id >= hw->func_caps.num_msix_vectors_vf) || 589856c2c47bSJack F Vogel vector->vsi_id != vf->vsi.vsi_num) { 589956c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, 590056c2c47bSJack F Vogel I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP, I40E_ERR_PARAM); 590156c2c47bSJack F Vogel return; 590256c2c47bSJack F Vogel } 590356c2c47bSJack F Vogel 590456c2c47bSJack F Vogel if (vector->rxq_map != 0) { 590556c2c47bSJack F Vogel largest_rxq = fls(vector->rxq_map) - 1; 590656c2c47bSJack F Vogel if (largest_rxq >= vf->vsi.num_queues) { 590756c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, 590856c2c47bSJack F Vogel I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP, 590956c2c47bSJack F Vogel I40E_ERR_PARAM); 591056c2c47bSJack F Vogel return; 591156c2c47bSJack F Vogel } 591256c2c47bSJack F Vogel } 591356c2c47bSJack F Vogel 591456c2c47bSJack F Vogel if (vector->txq_map != 0) { 591556c2c47bSJack F Vogel largest_txq = fls(vector->txq_map) - 1; 591656c2c47bSJack F Vogel if (largest_txq >= vf->vsi.num_queues) { 591756c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, 591856c2c47bSJack F Vogel I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP, 591956c2c47bSJack F Vogel I40E_ERR_PARAM); 592056c2c47bSJack F Vogel return; 592156c2c47bSJack F Vogel } 592256c2c47bSJack F Vogel } 592356c2c47bSJack F Vogel 592456c2c47bSJack F Vogel if (vector->rxitr_idx > IXL_MAX_ITR_IDX || 592556c2c47bSJack F Vogel vector->txitr_idx > IXL_MAX_ITR_IDX) { 592656c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, 592756c2c47bSJack F Vogel I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP, 592856c2c47bSJack F Vogel I40E_ERR_PARAM); 592956c2c47bSJack F Vogel return; 593056c2c47bSJack F Vogel } 593156c2c47bSJack F Vogel 593256c2c47bSJack F Vogel ixl_vf_config_vector(pf, vf, vector); 593356c2c47bSJack F Vogel } 593456c2c47bSJack F Vogel 593556c2c47bSJack F Vogel ixl_send_vf_ack(pf, vf, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP); 593656c2c47bSJack F Vogel } 593756c2c47bSJack F Vogel 593856c2c47bSJack F Vogel static void 593956c2c47bSJack F Vogel ixl_vf_enable_queues_msg(struct ixl_pf *pf, struct ixl_vf *vf, void *msg, 594056c2c47bSJack F Vogel uint16_t msg_size) 594156c2c47bSJack F Vogel { 594256c2c47bSJack F Vogel struct i40e_virtchnl_queue_select *select; 594356c2c47bSJack F Vogel int error; 594456c2c47bSJack F Vogel 594556c2c47bSJack F Vogel if (msg_size != sizeof(*select)) { 594656c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES, 594756c2c47bSJack F Vogel I40E_ERR_PARAM); 594856c2c47bSJack F Vogel return; 594956c2c47bSJack F Vogel } 595056c2c47bSJack F Vogel 595156c2c47bSJack F Vogel select = msg; 595256c2c47bSJack F Vogel if (select->vsi_id != vf->vsi.vsi_num || 595356c2c47bSJack F Vogel select->rx_queues == 0 || select->tx_queues == 0) { 595456c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES, 595556c2c47bSJack F Vogel I40E_ERR_PARAM); 595656c2c47bSJack F Vogel return; 595756c2c47bSJack F Vogel } 595856c2c47bSJack F Vogel 595956c2c47bSJack F Vogel error = ixl_enable_rings(&vf->vsi); 596056c2c47bSJack F Vogel if (error) { 596156c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES, 596256c2c47bSJack F Vogel I40E_ERR_TIMEOUT); 596356c2c47bSJack F Vogel return; 596456c2c47bSJack F Vogel } 596556c2c47bSJack F Vogel 596656c2c47bSJack F Vogel ixl_send_vf_ack(pf, vf, I40E_VIRTCHNL_OP_ENABLE_QUEUES); 596756c2c47bSJack F Vogel } 596856c2c47bSJack F Vogel 596956c2c47bSJack F Vogel static void 597056c2c47bSJack F Vogel ixl_vf_disable_queues_msg(struct ixl_pf *pf, struct ixl_vf *vf, 597156c2c47bSJack F Vogel void *msg, uint16_t msg_size) 597256c2c47bSJack F Vogel { 597356c2c47bSJack F Vogel struct i40e_virtchnl_queue_select *select; 597456c2c47bSJack F Vogel int error; 597556c2c47bSJack F Vogel 597656c2c47bSJack F Vogel if (msg_size != sizeof(*select)) { 597756c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES, 597856c2c47bSJack F Vogel I40E_ERR_PARAM); 597956c2c47bSJack F Vogel return; 598056c2c47bSJack F Vogel } 598156c2c47bSJack F Vogel 598256c2c47bSJack F Vogel select = msg; 598356c2c47bSJack F Vogel if (select->vsi_id != vf->vsi.vsi_num || 598456c2c47bSJack F Vogel select->rx_queues == 0 || select->tx_queues == 0) { 598556c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES, 598656c2c47bSJack F Vogel I40E_ERR_PARAM); 598756c2c47bSJack F Vogel return; 598856c2c47bSJack F Vogel } 598956c2c47bSJack F Vogel 599056c2c47bSJack F Vogel error = ixl_disable_rings(&vf->vsi); 599156c2c47bSJack F Vogel if (error) { 599256c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES, 599356c2c47bSJack F Vogel I40E_ERR_TIMEOUT); 599456c2c47bSJack F Vogel return; 599556c2c47bSJack F Vogel } 599656c2c47bSJack F Vogel 599756c2c47bSJack F Vogel ixl_send_vf_ack(pf, vf, I40E_VIRTCHNL_OP_DISABLE_QUEUES); 599856c2c47bSJack F Vogel } 599956c2c47bSJack F Vogel 600056c2c47bSJack F Vogel static boolean_t 600156c2c47bSJack F Vogel ixl_zero_mac(const uint8_t *addr) 600256c2c47bSJack F Vogel { 600356c2c47bSJack F Vogel uint8_t zero[ETHER_ADDR_LEN] = {0, 0, 0, 0, 0, 0}; 600456c2c47bSJack F Vogel 600556c2c47bSJack F Vogel return (cmp_etheraddr(addr, zero)); 600656c2c47bSJack F Vogel } 600756c2c47bSJack F Vogel 600856c2c47bSJack F Vogel static boolean_t 600956c2c47bSJack F Vogel ixl_bcast_mac(const uint8_t *addr) 601056c2c47bSJack F Vogel { 601156c2c47bSJack F Vogel 601256c2c47bSJack F Vogel return (cmp_etheraddr(addr, ixl_bcast_addr)); 601356c2c47bSJack F Vogel } 601456c2c47bSJack F Vogel 601556c2c47bSJack F Vogel static int 601656c2c47bSJack F Vogel ixl_vf_mac_valid(struct ixl_vf *vf, const uint8_t *addr) 601756c2c47bSJack F Vogel { 601856c2c47bSJack F Vogel 601956c2c47bSJack F Vogel if (ixl_zero_mac(addr) || ixl_bcast_mac(addr)) 602056c2c47bSJack F Vogel return (EINVAL); 602156c2c47bSJack F Vogel 602256c2c47bSJack F Vogel /* 602356c2c47bSJack F Vogel * If the VF is not allowed to change its MAC address, don't let it 602456c2c47bSJack F Vogel * set a MAC filter for an address that is not a multicast address and 602556c2c47bSJack F Vogel * is not its assigned MAC. 602656c2c47bSJack F Vogel */ 602756c2c47bSJack F Vogel if (!(vf->vf_flags & VF_FLAG_SET_MAC_CAP) && 602856c2c47bSJack F Vogel !(ETHER_IS_MULTICAST(addr) || cmp_etheraddr(addr, vf->mac))) 602956c2c47bSJack F Vogel return (EPERM); 603056c2c47bSJack F Vogel 603156c2c47bSJack F Vogel return (0); 603256c2c47bSJack F Vogel } 603356c2c47bSJack F Vogel 603456c2c47bSJack F Vogel static void 603556c2c47bSJack F Vogel ixl_vf_add_mac_msg(struct ixl_pf *pf, struct ixl_vf *vf, void *msg, 603656c2c47bSJack F Vogel uint16_t msg_size) 603756c2c47bSJack F Vogel { 603856c2c47bSJack F Vogel struct i40e_virtchnl_ether_addr_list *addr_list; 603956c2c47bSJack F Vogel struct i40e_virtchnl_ether_addr *addr; 604056c2c47bSJack F Vogel struct ixl_vsi *vsi; 604156c2c47bSJack F Vogel int i; 604256c2c47bSJack F Vogel size_t expected_size; 604356c2c47bSJack F Vogel 604456c2c47bSJack F Vogel vsi = &vf->vsi; 604556c2c47bSJack F Vogel 604656c2c47bSJack F Vogel if (msg_size < sizeof(*addr_list)) { 604756c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS, 604856c2c47bSJack F Vogel I40E_ERR_PARAM); 604956c2c47bSJack F Vogel return; 605056c2c47bSJack F Vogel } 605156c2c47bSJack F Vogel 605256c2c47bSJack F Vogel addr_list = msg; 605356c2c47bSJack F Vogel expected_size = sizeof(*addr_list) + 605456c2c47bSJack F Vogel addr_list->num_elements * sizeof(*addr); 605556c2c47bSJack F Vogel 605656c2c47bSJack F Vogel if (addr_list->num_elements == 0 || 605756c2c47bSJack F Vogel addr_list->vsi_id != vsi->vsi_num || 605856c2c47bSJack F Vogel msg_size != expected_size) { 605956c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS, 606056c2c47bSJack F Vogel I40E_ERR_PARAM); 606156c2c47bSJack F Vogel return; 606256c2c47bSJack F Vogel } 606356c2c47bSJack F Vogel 606456c2c47bSJack F Vogel for (i = 0; i < addr_list->num_elements; i++) { 606556c2c47bSJack F Vogel if (ixl_vf_mac_valid(vf, addr_list->list[i].addr) != 0) { 606656c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, 606756c2c47bSJack F Vogel I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS, I40E_ERR_PARAM); 606856c2c47bSJack F Vogel return; 606956c2c47bSJack F Vogel } 607056c2c47bSJack F Vogel } 607156c2c47bSJack F Vogel 607256c2c47bSJack F Vogel for (i = 0; i < addr_list->num_elements; i++) { 607356c2c47bSJack F Vogel addr = &addr_list->list[i]; 607456c2c47bSJack F Vogel ixl_add_filter(vsi, addr->addr, IXL_VLAN_ANY); 607556c2c47bSJack F Vogel } 607656c2c47bSJack F Vogel 607756c2c47bSJack F Vogel ixl_send_vf_ack(pf, vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS); 607856c2c47bSJack F Vogel } 607956c2c47bSJack F Vogel 608056c2c47bSJack F Vogel static void 608156c2c47bSJack F Vogel ixl_vf_del_mac_msg(struct ixl_pf *pf, struct ixl_vf *vf, void *msg, 608256c2c47bSJack F Vogel uint16_t msg_size) 608356c2c47bSJack F Vogel { 608456c2c47bSJack F Vogel struct i40e_virtchnl_ether_addr_list *addr_list; 608556c2c47bSJack F Vogel struct i40e_virtchnl_ether_addr *addr; 608656c2c47bSJack F Vogel size_t expected_size; 608756c2c47bSJack F Vogel int i; 608856c2c47bSJack F Vogel 608956c2c47bSJack F Vogel if (msg_size < sizeof(*addr_list)) { 609056c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS, 609156c2c47bSJack F Vogel I40E_ERR_PARAM); 609256c2c47bSJack F Vogel return; 609356c2c47bSJack F Vogel } 609456c2c47bSJack F Vogel 609556c2c47bSJack F Vogel addr_list = msg; 609656c2c47bSJack F Vogel expected_size = sizeof(*addr_list) + 609756c2c47bSJack F Vogel addr_list->num_elements * sizeof(*addr); 609856c2c47bSJack F Vogel 609956c2c47bSJack F Vogel if (addr_list->num_elements == 0 || 610056c2c47bSJack F Vogel addr_list->vsi_id != vf->vsi.vsi_num || 610156c2c47bSJack F Vogel msg_size != expected_size) { 610256c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS, 610356c2c47bSJack F Vogel I40E_ERR_PARAM); 610456c2c47bSJack F Vogel return; 610556c2c47bSJack F Vogel } 610656c2c47bSJack F Vogel 610756c2c47bSJack F Vogel for (i = 0; i < addr_list->num_elements; i++) { 610856c2c47bSJack F Vogel addr = &addr_list->list[i]; 610956c2c47bSJack F Vogel if (ixl_zero_mac(addr->addr) || ixl_bcast_mac(addr->addr)) { 611056c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, 611156c2c47bSJack F Vogel I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS, I40E_ERR_PARAM); 611256c2c47bSJack F Vogel return; 611356c2c47bSJack F Vogel } 611456c2c47bSJack F Vogel } 611556c2c47bSJack F Vogel 611656c2c47bSJack F Vogel for (i = 0; i < addr_list->num_elements; i++) { 611756c2c47bSJack F Vogel addr = &addr_list->list[i]; 611856c2c47bSJack F Vogel ixl_del_filter(&vf->vsi, addr->addr, IXL_VLAN_ANY); 611956c2c47bSJack F Vogel } 612056c2c47bSJack F Vogel 612156c2c47bSJack F Vogel ixl_send_vf_ack(pf, vf, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS); 612256c2c47bSJack F Vogel } 612356c2c47bSJack F Vogel 612456c2c47bSJack F Vogel static enum i40e_status_code 612556c2c47bSJack F Vogel ixl_vf_enable_vlan_strip(struct ixl_pf *pf, struct ixl_vf *vf) 612656c2c47bSJack F Vogel { 612756c2c47bSJack F Vogel struct i40e_vsi_context vsi_ctx; 612856c2c47bSJack F Vogel 612956c2c47bSJack F Vogel vsi_ctx.seid = vf->vsi.seid; 613056c2c47bSJack F Vogel 613156c2c47bSJack F Vogel bzero(&vsi_ctx.info, sizeof(vsi_ctx.info)); 613256c2c47bSJack F Vogel vsi_ctx.info.valid_sections = htole16(I40E_AQ_VSI_PROP_VLAN_VALID); 613356c2c47bSJack F Vogel vsi_ctx.info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | 613456c2c47bSJack F Vogel I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; 613556c2c47bSJack F Vogel return (i40e_aq_update_vsi_params(&pf->hw, &vsi_ctx, NULL)); 613656c2c47bSJack F Vogel } 613756c2c47bSJack F Vogel 613856c2c47bSJack F Vogel static void 613956c2c47bSJack F Vogel ixl_vf_add_vlan_msg(struct ixl_pf *pf, struct ixl_vf *vf, void *msg, 614056c2c47bSJack F Vogel uint16_t msg_size) 614156c2c47bSJack F Vogel { 614256c2c47bSJack F Vogel struct i40e_virtchnl_vlan_filter_list *filter_list; 614356c2c47bSJack F Vogel enum i40e_status_code code; 614456c2c47bSJack F Vogel size_t expected_size; 614556c2c47bSJack F Vogel int i; 614656c2c47bSJack F Vogel 614756c2c47bSJack F Vogel if (msg_size < sizeof(*filter_list)) { 614856c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_ADD_VLAN, 614956c2c47bSJack F Vogel I40E_ERR_PARAM); 615056c2c47bSJack F Vogel return; 615156c2c47bSJack F Vogel } 615256c2c47bSJack F Vogel 615356c2c47bSJack F Vogel filter_list = msg; 615456c2c47bSJack F Vogel expected_size = sizeof(*filter_list) + 615556c2c47bSJack F Vogel filter_list->num_elements * sizeof(uint16_t); 615656c2c47bSJack F Vogel if (filter_list->num_elements == 0 || 615756c2c47bSJack F Vogel filter_list->vsi_id != vf->vsi.vsi_num || 615856c2c47bSJack F Vogel msg_size != expected_size) { 615956c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_ADD_VLAN, 616056c2c47bSJack F Vogel I40E_ERR_PARAM); 616156c2c47bSJack F Vogel return; 616256c2c47bSJack F Vogel } 616356c2c47bSJack F Vogel 616456c2c47bSJack F Vogel if (!(vf->vf_flags & VF_FLAG_VLAN_CAP)) { 616556c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_ADD_VLAN, 616656c2c47bSJack F Vogel I40E_ERR_PARAM); 616756c2c47bSJack F Vogel return; 616856c2c47bSJack F Vogel } 616956c2c47bSJack F Vogel 617056c2c47bSJack F Vogel for (i = 0; i < filter_list->num_elements; i++) { 617156c2c47bSJack F Vogel if (filter_list->vlan_id[i] > EVL_VLID_MASK) { 617256c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_ADD_VLAN, 617356c2c47bSJack F Vogel I40E_ERR_PARAM); 617456c2c47bSJack F Vogel return; 617556c2c47bSJack F Vogel } 617656c2c47bSJack F Vogel } 617756c2c47bSJack F Vogel 617856c2c47bSJack F Vogel code = ixl_vf_enable_vlan_strip(pf, vf); 617956c2c47bSJack F Vogel if (code != I40E_SUCCESS) { 618056c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_ADD_VLAN, 618156c2c47bSJack F Vogel I40E_ERR_PARAM); 618256c2c47bSJack F Vogel } 618356c2c47bSJack F Vogel 618456c2c47bSJack F Vogel for (i = 0; i < filter_list->num_elements; i++) 618556c2c47bSJack F Vogel ixl_add_filter(&vf->vsi, vf->mac, filter_list->vlan_id[i]); 618656c2c47bSJack F Vogel 618756c2c47bSJack F Vogel ixl_send_vf_ack(pf, vf, I40E_VIRTCHNL_OP_ADD_VLAN); 618856c2c47bSJack F Vogel } 618956c2c47bSJack F Vogel 619056c2c47bSJack F Vogel static void 619156c2c47bSJack F Vogel ixl_vf_del_vlan_msg(struct ixl_pf *pf, struct ixl_vf *vf, void *msg, 619256c2c47bSJack F Vogel uint16_t msg_size) 619356c2c47bSJack F Vogel { 619456c2c47bSJack F Vogel struct i40e_virtchnl_vlan_filter_list *filter_list; 619556c2c47bSJack F Vogel int i; 619656c2c47bSJack F Vogel size_t expected_size; 619756c2c47bSJack F Vogel 619856c2c47bSJack F Vogel if (msg_size < sizeof(*filter_list)) { 619956c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_DEL_VLAN, 620056c2c47bSJack F Vogel I40E_ERR_PARAM); 620156c2c47bSJack F Vogel return; 620256c2c47bSJack F Vogel } 620356c2c47bSJack F Vogel 620456c2c47bSJack F Vogel filter_list = msg; 620556c2c47bSJack F Vogel expected_size = sizeof(*filter_list) + 620656c2c47bSJack F Vogel filter_list->num_elements * sizeof(uint16_t); 620756c2c47bSJack F Vogel if (filter_list->num_elements == 0 || 620856c2c47bSJack F Vogel filter_list->vsi_id != vf->vsi.vsi_num || 620956c2c47bSJack F Vogel msg_size != expected_size) { 621056c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_DEL_VLAN, 621156c2c47bSJack F Vogel I40E_ERR_PARAM); 621256c2c47bSJack F Vogel return; 621356c2c47bSJack F Vogel } 621456c2c47bSJack F Vogel 621556c2c47bSJack F Vogel for (i = 0; i < filter_list->num_elements; i++) { 621656c2c47bSJack F Vogel if (filter_list->vlan_id[i] > EVL_VLID_MASK) { 621756c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_ADD_VLAN, 621856c2c47bSJack F Vogel I40E_ERR_PARAM); 621956c2c47bSJack F Vogel return; 622056c2c47bSJack F Vogel } 622156c2c47bSJack F Vogel } 622256c2c47bSJack F Vogel 622356c2c47bSJack F Vogel if (!(vf->vf_flags & VF_FLAG_VLAN_CAP)) { 622456c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_ADD_VLAN, 622556c2c47bSJack F Vogel I40E_ERR_PARAM); 622656c2c47bSJack F Vogel return; 622756c2c47bSJack F Vogel } 622856c2c47bSJack F Vogel 622956c2c47bSJack F Vogel for (i = 0; i < filter_list->num_elements; i++) 623056c2c47bSJack F Vogel ixl_del_filter(&vf->vsi, vf->mac, filter_list->vlan_id[i]); 623156c2c47bSJack F Vogel 623256c2c47bSJack F Vogel ixl_send_vf_ack(pf, vf, I40E_VIRTCHNL_OP_DEL_VLAN); 623356c2c47bSJack F Vogel } 623456c2c47bSJack F Vogel 623556c2c47bSJack F Vogel static void 623656c2c47bSJack F Vogel ixl_vf_config_promisc_msg(struct ixl_pf *pf, struct ixl_vf *vf, 623756c2c47bSJack F Vogel void *msg, uint16_t msg_size) 623856c2c47bSJack F Vogel { 623956c2c47bSJack F Vogel struct i40e_virtchnl_promisc_info *info; 624056c2c47bSJack F Vogel enum i40e_status_code code; 624156c2c47bSJack F Vogel 624256c2c47bSJack F Vogel if (msg_size != sizeof(*info)) { 624356c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, 624456c2c47bSJack F Vogel I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, I40E_ERR_PARAM); 624556c2c47bSJack F Vogel return; 624656c2c47bSJack F Vogel } 624756c2c47bSJack F Vogel 624856c2c47bSJack F Vogel if (!vf->vf_flags & VF_FLAG_PROMISC_CAP) { 624956c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, 625056c2c47bSJack F Vogel I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, I40E_ERR_PARAM); 625156c2c47bSJack F Vogel return; 625256c2c47bSJack F Vogel } 625356c2c47bSJack F Vogel 625456c2c47bSJack F Vogel info = msg; 625556c2c47bSJack F Vogel if (info->vsi_id != vf->vsi.vsi_num) { 625656c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, 625756c2c47bSJack F Vogel I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, I40E_ERR_PARAM); 625856c2c47bSJack F Vogel return; 625956c2c47bSJack F Vogel } 626056c2c47bSJack F Vogel 626156c2c47bSJack F Vogel code = i40e_aq_set_vsi_unicast_promiscuous(&pf->hw, info->vsi_id, 626256c2c47bSJack F Vogel info->flags & I40E_FLAG_VF_UNICAST_PROMISC, NULL); 626356c2c47bSJack F Vogel if (code != I40E_SUCCESS) { 626456c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, 626556c2c47bSJack F Vogel I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, code); 626656c2c47bSJack F Vogel return; 626756c2c47bSJack F Vogel } 626856c2c47bSJack F Vogel 626956c2c47bSJack F Vogel code = i40e_aq_set_vsi_multicast_promiscuous(&pf->hw, info->vsi_id, 627056c2c47bSJack F Vogel info->flags & I40E_FLAG_VF_MULTICAST_PROMISC, NULL); 627156c2c47bSJack F Vogel if (code != I40E_SUCCESS) { 627256c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, 627356c2c47bSJack F Vogel I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, code); 627456c2c47bSJack F Vogel return; 627556c2c47bSJack F Vogel } 627656c2c47bSJack F Vogel 627756c2c47bSJack F Vogel ixl_send_vf_ack(pf, vf, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE); 627856c2c47bSJack F Vogel } 627956c2c47bSJack F Vogel 628056c2c47bSJack F Vogel static void 628156c2c47bSJack F Vogel ixl_vf_get_stats_msg(struct ixl_pf *pf, struct ixl_vf *vf, void *msg, 628256c2c47bSJack F Vogel uint16_t msg_size) 628356c2c47bSJack F Vogel { 628456c2c47bSJack F Vogel struct i40e_virtchnl_queue_select *queue; 628556c2c47bSJack F Vogel 628656c2c47bSJack F Vogel if (msg_size != sizeof(*queue)) { 628756c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_GET_STATS, 628856c2c47bSJack F Vogel I40E_ERR_PARAM); 628956c2c47bSJack F Vogel return; 629056c2c47bSJack F Vogel } 629156c2c47bSJack F Vogel 629256c2c47bSJack F Vogel queue = msg; 629356c2c47bSJack F Vogel if (queue->vsi_id != vf->vsi.vsi_num) { 629456c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, I40E_VIRTCHNL_OP_GET_STATS, 629556c2c47bSJack F Vogel I40E_ERR_PARAM); 629656c2c47bSJack F Vogel return; 629756c2c47bSJack F Vogel } 629856c2c47bSJack F Vogel 629956c2c47bSJack F Vogel ixl_update_eth_stats(&vf->vsi); 630056c2c47bSJack F Vogel 630156c2c47bSJack F Vogel ixl_send_vf_msg(pf, vf, I40E_VIRTCHNL_OP_GET_STATS, 630256c2c47bSJack F Vogel I40E_SUCCESS, &vf->vsi.eth_stats, sizeof(vf->vsi.eth_stats)); 630356c2c47bSJack F Vogel } 630456c2c47bSJack F Vogel 630556c2c47bSJack F Vogel static void 630656c2c47bSJack F Vogel ixl_handle_vf_msg(struct ixl_pf *pf, struct i40e_arq_event_info *event) 630756c2c47bSJack F Vogel { 630856c2c47bSJack F Vogel struct ixl_vf *vf; 630956c2c47bSJack F Vogel void *msg; 631056c2c47bSJack F Vogel uint16_t vf_num, msg_size; 631156c2c47bSJack F Vogel uint32_t opcode; 631256c2c47bSJack F Vogel 631356c2c47bSJack F Vogel vf_num = le16toh(event->desc.retval) - pf->hw.func_caps.vf_base_id; 631456c2c47bSJack F Vogel opcode = le32toh(event->desc.cookie_high); 631556c2c47bSJack F Vogel 631656c2c47bSJack F Vogel if (vf_num >= pf->num_vfs) { 631756c2c47bSJack F Vogel device_printf(pf->dev, "Got msg from illegal VF: %d\n", vf_num); 631856c2c47bSJack F Vogel return; 631956c2c47bSJack F Vogel } 632056c2c47bSJack F Vogel 632156c2c47bSJack F Vogel vf = &pf->vfs[vf_num]; 632256c2c47bSJack F Vogel msg = event->msg_buf; 632356c2c47bSJack F Vogel msg_size = event->msg_len; 632456c2c47bSJack F Vogel 632556c2c47bSJack F Vogel I40E_VC_DEBUG(pf, ixl_vc_opcode_level(opcode), 632656c2c47bSJack F Vogel "Got msg %s(%d) from VF-%d of size %d\n", 632756c2c47bSJack F Vogel ixl_vc_opcode_str(opcode), opcode, vf_num, msg_size); 632856c2c47bSJack F Vogel 632956c2c47bSJack F Vogel switch (opcode) { 633056c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_VERSION: 633156c2c47bSJack F Vogel ixl_vf_version_msg(pf, vf, msg, msg_size); 633256c2c47bSJack F Vogel break; 633356c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_RESET_VF: 633456c2c47bSJack F Vogel ixl_vf_reset_msg(pf, vf, msg, msg_size); 633556c2c47bSJack F Vogel break; 633656c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: 633756c2c47bSJack F Vogel ixl_vf_get_resources_msg(pf, vf, msg, msg_size); 633856c2c47bSJack F Vogel break; 633956c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES: 634056c2c47bSJack F Vogel ixl_vf_config_vsi_msg(pf, vf, msg, msg_size); 634156c2c47bSJack F Vogel break; 634256c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP: 634356c2c47bSJack F Vogel ixl_vf_config_irq_msg(pf, vf, msg, msg_size); 634456c2c47bSJack F Vogel break; 634556c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_ENABLE_QUEUES: 634656c2c47bSJack F Vogel ixl_vf_enable_queues_msg(pf, vf, msg, msg_size); 634756c2c47bSJack F Vogel break; 634856c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_DISABLE_QUEUES: 634956c2c47bSJack F Vogel ixl_vf_disable_queues_msg(pf, vf, msg, msg_size); 635056c2c47bSJack F Vogel break; 635156c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS: 635256c2c47bSJack F Vogel ixl_vf_add_mac_msg(pf, vf, msg, msg_size); 635356c2c47bSJack F Vogel break; 635456c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS: 635556c2c47bSJack F Vogel ixl_vf_del_mac_msg(pf, vf, msg, msg_size); 635656c2c47bSJack F Vogel break; 635756c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_ADD_VLAN: 635856c2c47bSJack F Vogel ixl_vf_add_vlan_msg(pf, vf, msg, msg_size); 635956c2c47bSJack F Vogel break; 636056c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_DEL_VLAN: 636156c2c47bSJack F Vogel ixl_vf_del_vlan_msg(pf, vf, msg, msg_size); 636256c2c47bSJack F Vogel break; 636356c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: 636456c2c47bSJack F Vogel ixl_vf_config_promisc_msg(pf, vf, msg, msg_size); 636556c2c47bSJack F Vogel break; 636656c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_GET_STATS: 636756c2c47bSJack F Vogel ixl_vf_get_stats_msg(pf, vf, msg, msg_size); 636856c2c47bSJack F Vogel break; 636956c2c47bSJack F Vogel 637056c2c47bSJack F Vogel /* These two opcodes have been superseded by CONFIG_VSI_QUEUES. */ 637156c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_CONFIG_TX_QUEUE: 637256c2c47bSJack F Vogel case I40E_VIRTCHNL_OP_CONFIG_RX_QUEUE: 637356c2c47bSJack F Vogel default: 637456c2c47bSJack F Vogel i40e_send_vf_nack(pf, vf, opcode, I40E_ERR_NOT_IMPLEMENTED); 637556c2c47bSJack F Vogel break; 637656c2c47bSJack F Vogel } 637756c2c47bSJack F Vogel } 637856c2c47bSJack F Vogel 637956c2c47bSJack F Vogel /* Handle any VFs that have reset themselves via a Function Level Reset(FLR). */ 638056c2c47bSJack F Vogel static void 638156c2c47bSJack F Vogel ixl_handle_vflr(void *arg, int pending) 638256c2c47bSJack F Vogel { 638356c2c47bSJack F Vogel struct ixl_pf *pf; 638456c2c47bSJack F Vogel struct i40e_hw *hw; 638556c2c47bSJack F Vogel uint16_t global_vf_num; 638656c2c47bSJack F Vogel uint32_t vflrstat_index, vflrstat_mask, vflrstat, icr0; 638756c2c47bSJack F Vogel int i; 638856c2c47bSJack F Vogel 638956c2c47bSJack F Vogel pf = arg; 639056c2c47bSJack F Vogel hw = &pf->hw; 639156c2c47bSJack F Vogel 639256c2c47bSJack F Vogel IXL_PF_LOCK(pf); 639356c2c47bSJack F Vogel for (i = 0; i < pf->num_vfs; i++) { 639456c2c47bSJack F Vogel global_vf_num = hw->func_caps.vf_base_id + i; 639556c2c47bSJack F Vogel 639656c2c47bSJack F Vogel vflrstat_index = IXL_GLGEN_VFLRSTAT_INDEX(global_vf_num); 639756c2c47bSJack F Vogel vflrstat_mask = IXL_GLGEN_VFLRSTAT_MASK(global_vf_num); 639856c2c47bSJack F Vogel vflrstat = rd32(hw, I40E_GLGEN_VFLRSTAT(vflrstat_index)); 639956c2c47bSJack F Vogel if (vflrstat & vflrstat_mask) { 640056c2c47bSJack F Vogel wr32(hw, I40E_GLGEN_VFLRSTAT(vflrstat_index), 640156c2c47bSJack F Vogel vflrstat_mask); 640256c2c47bSJack F Vogel 640356c2c47bSJack F Vogel ixl_reinit_vf(pf, &pf->vfs[i]); 640456c2c47bSJack F Vogel } 640556c2c47bSJack F Vogel } 640656c2c47bSJack F Vogel 640756c2c47bSJack F Vogel icr0 = rd32(hw, I40E_PFINT_ICR0_ENA); 640856c2c47bSJack F Vogel icr0 |= I40E_PFINT_ICR0_ENA_VFLR_MASK; 640956c2c47bSJack F Vogel wr32(hw, I40E_PFINT_ICR0_ENA, icr0); 641056c2c47bSJack F Vogel ixl_flush(hw); 641156c2c47bSJack F Vogel 641256c2c47bSJack F Vogel IXL_PF_UNLOCK(pf); 641356c2c47bSJack F Vogel } 641456c2c47bSJack F Vogel 641556c2c47bSJack F Vogel static int 641656c2c47bSJack F Vogel ixl_adminq_err_to_errno(enum i40e_admin_queue_err err) 641756c2c47bSJack F Vogel { 641856c2c47bSJack F Vogel 641956c2c47bSJack F Vogel switch (err) { 642056c2c47bSJack F Vogel case I40E_AQ_RC_EPERM: 642156c2c47bSJack F Vogel return (EPERM); 642256c2c47bSJack F Vogel case I40E_AQ_RC_ENOENT: 642356c2c47bSJack F Vogel return (ENOENT); 642456c2c47bSJack F Vogel case I40E_AQ_RC_ESRCH: 642556c2c47bSJack F Vogel return (ESRCH); 642656c2c47bSJack F Vogel case I40E_AQ_RC_EINTR: 642756c2c47bSJack F Vogel return (EINTR); 642856c2c47bSJack F Vogel case I40E_AQ_RC_EIO: 642956c2c47bSJack F Vogel return (EIO); 643056c2c47bSJack F Vogel case I40E_AQ_RC_ENXIO: 643156c2c47bSJack F Vogel return (ENXIO); 643256c2c47bSJack F Vogel case I40E_AQ_RC_E2BIG: 643356c2c47bSJack F Vogel return (E2BIG); 643456c2c47bSJack F Vogel case I40E_AQ_RC_EAGAIN: 643556c2c47bSJack F Vogel return (EAGAIN); 643656c2c47bSJack F Vogel case I40E_AQ_RC_ENOMEM: 643756c2c47bSJack F Vogel return (ENOMEM); 643856c2c47bSJack F Vogel case I40E_AQ_RC_EACCES: 643956c2c47bSJack F Vogel return (EACCES); 644056c2c47bSJack F Vogel case I40E_AQ_RC_EFAULT: 644156c2c47bSJack F Vogel return (EFAULT); 644256c2c47bSJack F Vogel case I40E_AQ_RC_EBUSY: 644356c2c47bSJack F Vogel return (EBUSY); 644456c2c47bSJack F Vogel case I40E_AQ_RC_EEXIST: 644556c2c47bSJack F Vogel return (EEXIST); 644656c2c47bSJack F Vogel case I40E_AQ_RC_EINVAL: 644756c2c47bSJack F Vogel return (EINVAL); 644856c2c47bSJack F Vogel case I40E_AQ_RC_ENOTTY: 644956c2c47bSJack F Vogel return (ENOTTY); 645056c2c47bSJack F Vogel case I40E_AQ_RC_ENOSPC: 645156c2c47bSJack F Vogel return (ENOSPC); 645256c2c47bSJack F Vogel case I40E_AQ_RC_ENOSYS: 645356c2c47bSJack F Vogel return (ENOSYS); 645456c2c47bSJack F Vogel case I40E_AQ_RC_ERANGE: 645556c2c47bSJack F Vogel return (ERANGE); 645656c2c47bSJack F Vogel case I40E_AQ_RC_EFLUSHED: 645756c2c47bSJack F Vogel return (EINVAL); /* No exact equivalent in errno.h */ 645856c2c47bSJack F Vogel case I40E_AQ_RC_BAD_ADDR: 645956c2c47bSJack F Vogel return (EFAULT); 646056c2c47bSJack F Vogel case I40E_AQ_RC_EMODE: 646156c2c47bSJack F Vogel return (EPERM); 646256c2c47bSJack F Vogel case I40E_AQ_RC_EFBIG: 646356c2c47bSJack F Vogel return (EFBIG); 646456c2c47bSJack F Vogel default: 646556c2c47bSJack F Vogel return (EINVAL); 646656c2c47bSJack F Vogel } 646756c2c47bSJack F Vogel } 646856c2c47bSJack F Vogel 646956c2c47bSJack F Vogel static int 647056c2c47bSJack F Vogel ixl_init_iov(device_t dev, uint16_t num_vfs, const nvlist_t *params) 647156c2c47bSJack F Vogel { 647256c2c47bSJack F Vogel struct ixl_pf *pf; 647356c2c47bSJack F Vogel struct i40e_hw *hw; 647456c2c47bSJack F Vogel struct ixl_vsi *pf_vsi; 647556c2c47bSJack F Vogel enum i40e_status_code ret; 647656c2c47bSJack F Vogel int i, error; 647756c2c47bSJack F Vogel 647856c2c47bSJack F Vogel pf = device_get_softc(dev); 647956c2c47bSJack F Vogel hw = &pf->hw; 648056c2c47bSJack F Vogel pf_vsi = &pf->vsi; 648156c2c47bSJack F Vogel 648256c2c47bSJack F Vogel IXL_PF_LOCK(pf); 648356c2c47bSJack F Vogel pf->vfs = malloc(sizeof(struct ixl_vf) * num_vfs, M_IXL, M_NOWAIT | 648456c2c47bSJack F Vogel M_ZERO); 648556c2c47bSJack F Vogel 648656c2c47bSJack F Vogel if (pf->vfs == NULL) { 648756c2c47bSJack F Vogel error = ENOMEM; 648856c2c47bSJack F Vogel goto fail; 648956c2c47bSJack F Vogel } 649056c2c47bSJack F Vogel 649156c2c47bSJack F Vogel for (i = 0; i < num_vfs; i++) 649256c2c47bSJack F Vogel sysctl_ctx_init(&pf->vfs[i].ctx); 649356c2c47bSJack F Vogel 649456c2c47bSJack F Vogel ret = i40e_aq_add_veb(hw, pf_vsi->uplink_seid, pf_vsi->seid, 649556c2c47bSJack F Vogel 1, FALSE, FALSE, &pf->veb_seid, NULL); 649656c2c47bSJack F Vogel if (ret != I40E_SUCCESS) { 649756c2c47bSJack F Vogel error = ixl_adminq_err_to_errno(hw->aq.asq_last_status); 649856c2c47bSJack F Vogel device_printf(dev, "add_veb failed; code=%d error=%d", ret, 649956c2c47bSJack F Vogel error); 650056c2c47bSJack F Vogel goto fail; 650156c2c47bSJack F Vogel } 650256c2c47bSJack F Vogel 650356c2c47bSJack F Vogel ixl_configure_msix(pf); 650456c2c47bSJack F Vogel ixl_enable_adminq(hw); 650556c2c47bSJack F Vogel 650656c2c47bSJack F Vogel pf->num_vfs = num_vfs; 650756c2c47bSJack F Vogel IXL_PF_UNLOCK(pf); 650856c2c47bSJack F Vogel return (0); 650956c2c47bSJack F Vogel 651056c2c47bSJack F Vogel fail: 651156c2c47bSJack F Vogel free(pf->vfs, M_IXL); 651256c2c47bSJack F Vogel pf->vfs = NULL; 651356c2c47bSJack F Vogel IXL_PF_UNLOCK(pf); 651456c2c47bSJack F Vogel return (error); 651556c2c47bSJack F Vogel } 651656c2c47bSJack F Vogel 651756c2c47bSJack F Vogel static void 651856c2c47bSJack F Vogel ixl_uninit_iov(device_t dev) 651956c2c47bSJack F Vogel { 652056c2c47bSJack F Vogel struct ixl_pf *pf; 652156c2c47bSJack F Vogel struct i40e_hw *hw; 652256c2c47bSJack F Vogel struct ixl_vsi *vsi; 652356c2c47bSJack F Vogel struct ifnet *ifp; 652456c2c47bSJack F Vogel struct ixl_vf *vfs; 652556c2c47bSJack F Vogel int i, num_vfs; 652656c2c47bSJack F Vogel 652756c2c47bSJack F Vogel pf = device_get_softc(dev); 652856c2c47bSJack F Vogel hw = &pf->hw; 652956c2c47bSJack F Vogel vsi = &pf->vsi; 653056c2c47bSJack F Vogel ifp = vsi->ifp; 653156c2c47bSJack F Vogel 653256c2c47bSJack F Vogel IXL_PF_LOCK(pf); 653356c2c47bSJack F Vogel for (i = 0; i < pf->num_vfs; i++) { 653456c2c47bSJack F Vogel if (pf->vfs[i].vsi.seid != 0) 653556c2c47bSJack F Vogel i40e_aq_delete_element(hw, pf->vfs[i].vsi.seid, NULL); 653656c2c47bSJack F Vogel } 653756c2c47bSJack F Vogel 653856c2c47bSJack F Vogel if (pf->veb_seid != 0) { 653956c2c47bSJack F Vogel i40e_aq_delete_element(hw, pf->veb_seid, NULL); 654056c2c47bSJack F Vogel pf->veb_seid = 0; 654156c2c47bSJack F Vogel } 654256c2c47bSJack F Vogel 654356c2c47bSJack F Vogel if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0) 654456c2c47bSJack F Vogel ixl_disable_intr(vsi); 654556c2c47bSJack F Vogel 654656c2c47bSJack F Vogel vfs = pf->vfs; 654756c2c47bSJack F Vogel num_vfs = pf->num_vfs; 654856c2c47bSJack F Vogel 654956c2c47bSJack F Vogel pf->vfs = NULL; 655056c2c47bSJack F Vogel pf->num_vfs = 0; 655156c2c47bSJack F Vogel IXL_PF_UNLOCK(pf); 655256c2c47bSJack F Vogel 655356c2c47bSJack F Vogel /* Do this after the unlock as sysctl_ctx_free might sleep. */ 655456c2c47bSJack F Vogel for (i = 0; i < num_vfs; i++) 655556c2c47bSJack F Vogel sysctl_ctx_free(&vfs[i].ctx); 655656c2c47bSJack F Vogel free(vfs, M_IXL); 655756c2c47bSJack F Vogel } 655856c2c47bSJack F Vogel 655956c2c47bSJack F Vogel static int 656056c2c47bSJack F Vogel ixl_add_vf(device_t dev, uint16_t vfnum, const nvlist_t *params) 656156c2c47bSJack F Vogel { 656256c2c47bSJack F Vogel char sysctl_name[QUEUE_NAME_LEN]; 656356c2c47bSJack F Vogel struct ixl_pf *pf; 656456c2c47bSJack F Vogel struct ixl_vf *vf; 656556c2c47bSJack F Vogel const void *mac; 656656c2c47bSJack F Vogel size_t size; 656756c2c47bSJack F Vogel int error; 656856c2c47bSJack F Vogel 656956c2c47bSJack F Vogel pf = device_get_softc(dev); 657056c2c47bSJack F Vogel vf = &pf->vfs[vfnum]; 657156c2c47bSJack F Vogel 657256c2c47bSJack F Vogel IXL_PF_LOCK(pf); 657356c2c47bSJack F Vogel vf->vf_num = vfnum; 657456c2c47bSJack F Vogel 657556c2c47bSJack F Vogel vf->vsi.back = pf; 657656c2c47bSJack F Vogel vf->vf_flags = VF_FLAG_ENABLED; 657756c2c47bSJack F Vogel SLIST_INIT(&vf->vsi.ftl); 657856c2c47bSJack F Vogel 657956c2c47bSJack F Vogel error = ixl_vf_setup_vsi(pf, vf); 658056c2c47bSJack F Vogel if (error != 0) 658156c2c47bSJack F Vogel goto out; 658256c2c47bSJack F Vogel 658356c2c47bSJack F Vogel if (nvlist_exists_binary(params, "mac-addr")) { 658456c2c47bSJack F Vogel mac = nvlist_get_binary(params, "mac-addr", &size); 658556c2c47bSJack F Vogel bcopy(mac, vf->mac, ETHER_ADDR_LEN); 658656c2c47bSJack F Vogel 658756c2c47bSJack F Vogel if (nvlist_get_bool(params, "allow-set-mac")) 658856c2c47bSJack F Vogel vf->vf_flags |= VF_FLAG_SET_MAC_CAP; 658956c2c47bSJack F Vogel } else 659056c2c47bSJack F Vogel /* 659156c2c47bSJack F Vogel * If the administrator has not specified a MAC address then 659256c2c47bSJack F Vogel * we must allow the VF to choose one. 659356c2c47bSJack F Vogel */ 659456c2c47bSJack F Vogel vf->vf_flags |= VF_FLAG_SET_MAC_CAP; 659556c2c47bSJack F Vogel 659656c2c47bSJack F Vogel if (nvlist_get_bool(params, "mac-anti-spoof")) 659756c2c47bSJack F Vogel vf->vf_flags |= VF_FLAG_MAC_ANTI_SPOOF; 659856c2c47bSJack F Vogel 659956c2c47bSJack F Vogel if (nvlist_get_bool(params, "allow-promisc")) 660056c2c47bSJack F Vogel vf->vf_flags |= VF_FLAG_PROMISC_CAP; 660156c2c47bSJack F Vogel 660256c2c47bSJack F Vogel vf->vf_flags |= VF_FLAG_VLAN_CAP; 660356c2c47bSJack F Vogel 660456c2c47bSJack F Vogel ixl_reset_vf(pf, vf); 660556c2c47bSJack F Vogel out: 660656c2c47bSJack F Vogel IXL_PF_UNLOCK(pf); 660756c2c47bSJack F Vogel if (error == 0) { 660856c2c47bSJack F Vogel snprintf(sysctl_name, sizeof(sysctl_name), "vf%d", vfnum); 660956c2c47bSJack F Vogel ixl_add_vsi_sysctls(pf, &vf->vsi, &vf->ctx, sysctl_name); 661056c2c47bSJack F Vogel } 661156c2c47bSJack F Vogel 661256c2c47bSJack F Vogel return (error); 661356c2c47bSJack F Vogel } 661456c2c47bSJack F Vogel #endif /* PCI_IOV */ 6615