161ae650dSJack F Vogel /****************************************************************************** 261ae650dSJack F Vogel 361ae650dSJack F Vogel Copyright (c) 2013-2014, 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 3561ae650dSJack F Vogel #include "opt_inet.h" 3661ae650dSJack F Vogel #include "opt_inet6.h" 3761ae650dSJack F Vogel #include "ixl.h" 3861ae650dSJack F Vogel #include "ixl_pf.h" 3961ae650dSJack F Vogel 4061ae650dSJack F Vogel /********************************************************************* 4161ae650dSJack F Vogel * Driver version 4261ae650dSJack F Vogel *********************************************************************/ 4361ae650dSJack F Vogel char ixl_driver_version[] = "1.2.2"; 4461ae650dSJack F Vogel 4561ae650dSJack F Vogel /********************************************************************* 4661ae650dSJack F Vogel * PCI Device ID Table 4761ae650dSJack F Vogel * 4861ae650dSJack F Vogel * Used by probe to select devices to load on 4961ae650dSJack F Vogel * Last field stores an index into ixl_strings 5061ae650dSJack F Vogel * Last entry must be all 0s 5161ae650dSJack F Vogel * 5261ae650dSJack F Vogel * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index } 5361ae650dSJack F Vogel *********************************************************************/ 5461ae650dSJack F Vogel 5561ae650dSJack F Vogel static ixl_vendor_info_t ixl_vendor_info_array[] = 5661ae650dSJack F Vogel { 5761ae650dSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710, 0, 0, 0}, 5861ae650dSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_A, 0, 0, 0}, 5961ae650dSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B, 0, 0, 0}, 6061ae650dSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C, 0, 0, 0}, 6161ae650dSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A, 0, 0, 0}, 6261ae650dSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B, 0, 0, 0}, 6361ae650dSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C, 0, 0, 0}, 6461ae650dSJack F Vogel {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T, 0, 0, 0}, 6561ae650dSJack F Vogel /* required last entry */ 6661ae650dSJack F Vogel {0, 0, 0, 0, 0} 6761ae650dSJack F Vogel }; 6861ae650dSJack F Vogel 6961ae650dSJack F Vogel /********************************************************************* 7061ae650dSJack F Vogel * Table of branding strings 7161ae650dSJack F Vogel *********************************************************************/ 7261ae650dSJack F Vogel 7361ae650dSJack F Vogel static char *ixl_strings[] = { 7461ae650dSJack F Vogel "Intel(R) Ethernet Connection XL710 Driver" 7561ae650dSJack F Vogel }; 7661ae650dSJack F Vogel 7761ae650dSJack F Vogel 7861ae650dSJack F Vogel /********************************************************************* 7961ae650dSJack F Vogel * Function prototypes 8061ae650dSJack F Vogel *********************************************************************/ 8161ae650dSJack F Vogel static int ixl_probe(device_t); 8261ae650dSJack F Vogel static int ixl_attach(device_t); 8361ae650dSJack F Vogel static int ixl_detach(device_t); 8461ae650dSJack F Vogel static int ixl_shutdown(device_t); 8561ae650dSJack F Vogel static int ixl_get_hw_capabilities(struct ixl_pf *); 8661ae650dSJack F Vogel static void ixl_cap_txcsum_tso(struct ixl_vsi *, struct ifnet *, int); 8761ae650dSJack F Vogel static int ixl_ioctl(struct ifnet *, u_long, caddr_t); 8861ae650dSJack F Vogel static void ixl_init(void *); 8961ae650dSJack F Vogel static void ixl_init_locked(struct ixl_pf *); 9061ae650dSJack F Vogel static void ixl_stop(struct ixl_pf *); 9161ae650dSJack F Vogel static void ixl_media_status(struct ifnet *, struct ifmediareq *); 9261ae650dSJack F Vogel static int ixl_media_change(struct ifnet *); 9361ae650dSJack F Vogel static void ixl_update_link_status(struct ixl_pf *); 9461ae650dSJack F Vogel static int ixl_allocate_pci_resources(struct ixl_pf *); 9561ae650dSJack F Vogel static u16 ixl_get_bus_info(struct i40e_hw *, device_t); 9661ae650dSJack F Vogel static int ixl_setup_stations(struct ixl_pf *); 9761ae650dSJack F Vogel static int ixl_setup_vsi(struct ixl_vsi *); 9861ae650dSJack F Vogel static int ixl_initialize_vsi(struct ixl_vsi *); 9961ae650dSJack F Vogel static int ixl_assign_vsi_msix(struct ixl_pf *); 10061ae650dSJack F Vogel static int ixl_assign_vsi_legacy(struct ixl_pf *); 10161ae650dSJack F Vogel static int ixl_init_msix(struct ixl_pf *); 10261ae650dSJack F Vogel static void ixl_configure_msix(struct ixl_pf *); 10361ae650dSJack F Vogel static void ixl_configure_itr(struct ixl_pf *); 10461ae650dSJack F Vogel static void ixl_configure_legacy(struct ixl_pf *); 10561ae650dSJack F Vogel static void ixl_free_pci_resources(struct ixl_pf *); 10661ae650dSJack F Vogel static void ixl_local_timer(void *); 10761ae650dSJack F Vogel static int ixl_setup_interface(device_t, struct ixl_vsi *); 10861ae650dSJack F Vogel static bool ixl_config_link(struct i40e_hw *); 10961ae650dSJack F Vogel static void ixl_config_rss(struct ixl_vsi *); 11061ae650dSJack F Vogel static void ixl_set_queue_rx_itr(struct ixl_queue *); 11161ae650dSJack F Vogel static void ixl_set_queue_tx_itr(struct ixl_queue *); 11261ae650dSJack F Vogel 11361ae650dSJack F Vogel static void ixl_enable_rings(struct ixl_vsi *); 11461ae650dSJack F Vogel static void ixl_disable_rings(struct ixl_vsi *); 11561ae650dSJack F Vogel static void ixl_enable_intr(struct ixl_vsi *); 11661ae650dSJack F Vogel static void ixl_disable_intr(struct ixl_vsi *); 11761ae650dSJack F Vogel 11861ae650dSJack F Vogel static void ixl_enable_adminq(struct i40e_hw *); 11961ae650dSJack F Vogel static void ixl_disable_adminq(struct i40e_hw *); 12061ae650dSJack F Vogel static void ixl_enable_queue(struct i40e_hw *, int); 12161ae650dSJack F Vogel static void ixl_disable_queue(struct i40e_hw *, int); 12261ae650dSJack F Vogel static void ixl_enable_legacy(struct i40e_hw *); 12361ae650dSJack F Vogel static void ixl_disable_legacy(struct i40e_hw *); 12461ae650dSJack F Vogel 12561ae650dSJack F Vogel static void ixl_set_promisc(struct ixl_vsi *); 12661ae650dSJack F Vogel static void ixl_add_multi(struct ixl_vsi *); 12761ae650dSJack F Vogel static void ixl_del_multi(struct ixl_vsi *); 12861ae650dSJack F Vogel static void ixl_register_vlan(void *, struct ifnet *, u16); 12961ae650dSJack F Vogel static void ixl_unregister_vlan(void *, struct ifnet *, u16); 13061ae650dSJack F Vogel static void ixl_setup_vlan_filters(struct ixl_vsi *); 13161ae650dSJack F Vogel 13261ae650dSJack F Vogel static void ixl_init_filters(struct ixl_vsi *); 13361ae650dSJack F Vogel static void ixl_add_filter(struct ixl_vsi *, u8 *, s16 vlan); 13461ae650dSJack F Vogel static void ixl_del_filter(struct ixl_vsi *, u8 *, s16 vlan); 13561ae650dSJack F Vogel static void ixl_add_hw_filters(struct ixl_vsi *, int, int); 13661ae650dSJack F Vogel static void ixl_del_hw_filters(struct ixl_vsi *, int); 13761ae650dSJack F Vogel static struct ixl_mac_filter * 13861ae650dSJack F Vogel ixl_find_filter(struct ixl_vsi *, u8 *, s16); 13961ae650dSJack F Vogel static void ixl_add_mc_filter(struct ixl_vsi *, u8 *); 14061ae650dSJack F Vogel 14161ae650dSJack F Vogel /* Sysctl debug interface */ 14261ae650dSJack F Vogel static int ixl_debug_info(SYSCTL_HANDLER_ARGS); 14361ae650dSJack F Vogel static void ixl_print_debug_info(struct ixl_pf *); 14461ae650dSJack F Vogel 14561ae650dSJack F Vogel /* The MSI/X Interrupt handlers */ 14661ae650dSJack F Vogel static void ixl_intr(void *); 14761ae650dSJack F Vogel static void ixl_msix_que(void *); 14861ae650dSJack F Vogel static void ixl_msix_adminq(void *); 14961ae650dSJack F Vogel static void ixl_handle_mdd_event(struct ixl_pf *); 15061ae650dSJack F Vogel 15161ae650dSJack F Vogel /* Deferred interrupt tasklets */ 15261ae650dSJack F Vogel static void ixl_do_adminq(void *, int); 15361ae650dSJack F Vogel 15461ae650dSJack F Vogel /* Sysctl handlers */ 15561ae650dSJack F Vogel static int ixl_set_flowcntl(SYSCTL_HANDLER_ARGS); 15661ae650dSJack F Vogel static int ixl_set_advertise(SYSCTL_HANDLER_ARGS); 15761ae650dSJack F Vogel static int ixl_current_speed(SYSCTL_HANDLER_ARGS); 15861ae650dSJack F Vogel 15961ae650dSJack F Vogel /* Statistics */ 16061ae650dSJack F Vogel static void ixl_add_hw_stats(struct ixl_pf *); 16161ae650dSJack F Vogel static void ixl_add_sysctls_mac_stats(struct sysctl_ctx_list *, 16261ae650dSJack F Vogel struct sysctl_oid_list *, struct i40e_hw_port_stats *); 16361ae650dSJack F Vogel static void ixl_add_sysctls_eth_stats(struct sysctl_ctx_list *, 16461ae650dSJack F Vogel struct sysctl_oid_list *, 16561ae650dSJack F Vogel struct i40e_eth_stats *); 16661ae650dSJack F Vogel static void ixl_update_stats_counters(struct ixl_pf *); 16761ae650dSJack F Vogel static void ixl_update_eth_stats(struct ixl_vsi *); 16861ae650dSJack F Vogel static void ixl_pf_reset_stats(struct ixl_pf *); 16961ae650dSJack F Vogel static void ixl_vsi_reset_stats(struct ixl_vsi *); 17061ae650dSJack F Vogel static void ixl_stat_update48(struct i40e_hw *, u32, u32, bool, 17161ae650dSJack F Vogel u64 *, u64 *); 17261ae650dSJack F Vogel static void ixl_stat_update32(struct i40e_hw *, u32, bool, 17361ae650dSJack F Vogel u64 *, u64 *); 17461ae650dSJack F Vogel 17561ae650dSJack F Vogel #ifdef IXL_DEBUG 17661ae650dSJack F Vogel static int ixl_sysctl_link_status(SYSCTL_HANDLER_ARGS); 17761ae650dSJack F Vogel static int ixl_sysctl_phy_abilities(SYSCTL_HANDLER_ARGS); 17861ae650dSJack F Vogel static int ixl_sysctl_sw_filter_list(SYSCTL_HANDLER_ARGS); 17961ae650dSJack F Vogel static int ixl_sysctl_hw_res_info(SYSCTL_HANDLER_ARGS); 18061ae650dSJack F Vogel static int ixl_sysctl_dump_txd(SYSCTL_HANDLER_ARGS); 18161ae650dSJack F Vogel #endif 18261ae650dSJack F Vogel 18361ae650dSJack F Vogel /********************************************************************* 18461ae650dSJack F Vogel * FreeBSD Device Interface Entry Points 18561ae650dSJack F Vogel *********************************************************************/ 18661ae650dSJack F Vogel 18761ae650dSJack F Vogel static device_method_t ixl_methods[] = { 18861ae650dSJack F Vogel /* Device interface */ 18961ae650dSJack F Vogel DEVMETHOD(device_probe, ixl_probe), 19061ae650dSJack F Vogel DEVMETHOD(device_attach, ixl_attach), 19161ae650dSJack F Vogel DEVMETHOD(device_detach, ixl_detach), 19261ae650dSJack F Vogel DEVMETHOD(device_shutdown, ixl_shutdown), 19361ae650dSJack F Vogel {0, 0} 19461ae650dSJack F Vogel }; 19561ae650dSJack F Vogel 19661ae650dSJack F Vogel static driver_t ixl_driver = { 19761ae650dSJack F Vogel "ixl", ixl_methods, sizeof(struct ixl_pf), 19861ae650dSJack F Vogel }; 19961ae650dSJack F Vogel 20061ae650dSJack F Vogel devclass_t ixl_devclass; 20161ae650dSJack F Vogel DRIVER_MODULE(ixl, pci, ixl_driver, ixl_devclass, 0, 0); 20261ae650dSJack F Vogel 20361ae650dSJack F Vogel MODULE_DEPEND(ixl, pci, 1, 1, 1); 20461ae650dSJack F Vogel MODULE_DEPEND(ixl, ether, 1, 1, 1); 20561ae650dSJack F Vogel 20661ae650dSJack F Vogel /* 20761ae650dSJack F Vogel ** Global reset mutex 20861ae650dSJack F Vogel */ 20961ae650dSJack F Vogel static struct mtx ixl_reset_mtx; 21061ae650dSJack F Vogel 21161ae650dSJack F Vogel /* 21261ae650dSJack F Vogel ** TUNEABLE PARAMETERS: 21361ae650dSJack F Vogel */ 21461ae650dSJack F Vogel 21561ae650dSJack F Vogel static SYSCTL_NODE(_hw, OID_AUTO, ixl, CTLFLAG_RD, 0, 21661ae650dSJack F Vogel "IXL driver parameters"); 21761ae650dSJack F Vogel 21861ae650dSJack F Vogel /* 21961ae650dSJack F Vogel * MSIX should be the default for best performance, 22061ae650dSJack F Vogel * but this allows it to be forced off for testing. 22161ae650dSJack F Vogel */ 22261ae650dSJack F Vogel static int ixl_enable_msix = 1; 22361ae650dSJack F Vogel TUNABLE_INT("hw.ixl.enable_msix", &ixl_enable_msix); 22461ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, enable_msix, CTLFLAG_RDTUN, &ixl_enable_msix, 0, 22561ae650dSJack F Vogel "Enable MSI-X interrupts"); 22661ae650dSJack F Vogel 22761ae650dSJack F Vogel /* 22861ae650dSJack F Vogel ** Number of descriptors per ring: 22961ae650dSJack F Vogel ** - TX and RX are the same size 23061ae650dSJack F Vogel */ 23161ae650dSJack F Vogel static int ixl_ringsz = DEFAULT_RING; 23261ae650dSJack F Vogel TUNABLE_INT("hw.ixl.ringsz", &ixl_ringsz); 23361ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, ring_size, CTLFLAG_RDTUN, 23461ae650dSJack F Vogel &ixl_ringsz, 0, "Descriptor Ring Size"); 23561ae650dSJack F Vogel 23661ae650dSJack F Vogel /* 23761ae650dSJack F Vogel ** This can be set manually, if left as 0 the 23861ae650dSJack F Vogel ** number of queues will be calculated based 23961ae650dSJack F Vogel ** on cpus and msix vectors available. 24061ae650dSJack F Vogel */ 24161ae650dSJack F Vogel int ixl_max_queues = 0; 24261ae650dSJack F Vogel TUNABLE_INT("hw.ixl.max_queues", &ixl_max_queues); 24361ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, max_queues, CTLFLAG_RDTUN, 24461ae650dSJack F Vogel &ixl_max_queues, 0, "Number of Queues"); 24561ae650dSJack F Vogel 24661ae650dSJack F Vogel /* 24761ae650dSJack F Vogel ** Controls for Interrupt Throttling 24861ae650dSJack F Vogel ** - true/false for dynamic adjustment 24961ae650dSJack F Vogel ** - default values for static ITR 25061ae650dSJack F Vogel */ 25161ae650dSJack F Vogel int ixl_dynamic_rx_itr = 0; 25261ae650dSJack F Vogel TUNABLE_INT("hw.ixl.dynamic_rx_itr", &ixl_dynamic_rx_itr); 25361ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, dynamic_rx_itr, CTLFLAG_RDTUN, 25461ae650dSJack F Vogel &ixl_dynamic_rx_itr, 0, "Dynamic RX Interrupt Rate"); 25561ae650dSJack F Vogel 25661ae650dSJack F Vogel int ixl_dynamic_tx_itr = 0; 25761ae650dSJack F Vogel TUNABLE_INT("hw.ixl.dynamic_tx_itr", &ixl_dynamic_tx_itr); 25861ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, dynamic_tx_itr, CTLFLAG_RDTUN, 25961ae650dSJack F Vogel &ixl_dynamic_tx_itr, 0, "Dynamic TX Interrupt Rate"); 26061ae650dSJack F Vogel 26161ae650dSJack F Vogel int ixl_rx_itr = IXL_ITR_8K; 26261ae650dSJack F Vogel TUNABLE_INT("hw.ixl.rx_itr", &ixl_rx_itr); 26361ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, rx_itr, CTLFLAG_RDTUN, 26461ae650dSJack F Vogel &ixl_rx_itr, 0, "RX Interrupt Rate"); 26561ae650dSJack F Vogel 26661ae650dSJack F Vogel int ixl_tx_itr = IXL_ITR_4K; 26761ae650dSJack F Vogel TUNABLE_INT("hw.ixl.tx_itr", &ixl_tx_itr); 26861ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, tx_itr, CTLFLAG_RDTUN, 26961ae650dSJack F Vogel &ixl_tx_itr, 0, "TX Interrupt Rate"); 27061ae650dSJack F Vogel 27161ae650dSJack F Vogel #ifdef IXL_FDIR 27261ae650dSJack F Vogel static int ixl_enable_fdir = 1; 27361ae650dSJack F Vogel TUNABLE_INT("hw.ixl.enable_fdir", &ixl_enable_fdir); 27461ae650dSJack F Vogel /* Rate at which we sample */ 27561ae650dSJack F Vogel int ixl_atr_rate = 20; 27661ae650dSJack F Vogel TUNABLE_INT("hw.ixl.atr_rate", &ixl_atr_rate); 27761ae650dSJack F Vogel #endif 27861ae650dSJack F Vogel 27961ae650dSJack F Vogel static char *ixl_fc_string[6] = { 28061ae650dSJack F Vogel "None", 28161ae650dSJack F Vogel "Rx", 28261ae650dSJack F Vogel "Tx", 28361ae650dSJack F Vogel "Full", 28461ae650dSJack F Vogel "Priority", 28561ae650dSJack F Vogel "Default" 28661ae650dSJack F Vogel }; 28761ae650dSJack F Vogel 28861ae650dSJack F Vogel 28961ae650dSJack F Vogel /********************************************************************* 29061ae650dSJack F Vogel * Device identification routine 29161ae650dSJack F Vogel * 29261ae650dSJack F Vogel * ixl_probe determines if the driver should be loaded on 29361ae650dSJack F Vogel * the hardware based on PCI vendor/device id of the device. 29461ae650dSJack F Vogel * 29561ae650dSJack F Vogel * return BUS_PROBE_DEFAULT on success, positive on failure 29661ae650dSJack F Vogel *********************************************************************/ 29761ae650dSJack F Vogel 29861ae650dSJack F Vogel static int 29961ae650dSJack F Vogel ixl_probe(device_t dev) 30061ae650dSJack F Vogel { 30161ae650dSJack F Vogel ixl_vendor_info_t *ent; 30261ae650dSJack F Vogel 30361ae650dSJack F Vogel u16 pci_vendor_id, pci_device_id; 30461ae650dSJack F Vogel u16 pci_subvendor_id, pci_subdevice_id; 30561ae650dSJack F Vogel char device_name[256]; 30661ae650dSJack F Vogel static bool lock_init = FALSE; 30761ae650dSJack F Vogel 30861ae650dSJack F Vogel INIT_DEBUGOUT("ixl_probe: begin"); 30961ae650dSJack F Vogel 31061ae650dSJack F Vogel pci_vendor_id = pci_get_vendor(dev); 31161ae650dSJack F Vogel if (pci_vendor_id != I40E_INTEL_VENDOR_ID) 31261ae650dSJack F Vogel return (ENXIO); 31361ae650dSJack F Vogel 31461ae650dSJack F Vogel pci_device_id = pci_get_device(dev); 31561ae650dSJack F Vogel pci_subvendor_id = pci_get_subvendor(dev); 31661ae650dSJack F Vogel pci_subdevice_id = pci_get_subdevice(dev); 31761ae650dSJack F Vogel 31861ae650dSJack F Vogel ent = ixl_vendor_info_array; 31961ae650dSJack F Vogel while (ent->vendor_id != 0) { 32061ae650dSJack F Vogel if ((pci_vendor_id == ent->vendor_id) && 32161ae650dSJack F Vogel (pci_device_id == ent->device_id) && 32261ae650dSJack F Vogel 32361ae650dSJack F Vogel ((pci_subvendor_id == ent->subvendor_id) || 32461ae650dSJack F Vogel (ent->subvendor_id == 0)) && 32561ae650dSJack F Vogel 32661ae650dSJack F Vogel ((pci_subdevice_id == ent->subdevice_id) || 32761ae650dSJack F Vogel (ent->subdevice_id == 0))) { 32861ae650dSJack F Vogel sprintf(device_name, "%s, Version - %s", 32961ae650dSJack F Vogel ixl_strings[ent->index], 33061ae650dSJack F Vogel ixl_driver_version); 33161ae650dSJack F Vogel device_set_desc_copy(dev, device_name); 33261ae650dSJack F Vogel /* One shot mutex init */ 33361ae650dSJack F Vogel if (lock_init == FALSE) { 33461ae650dSJack F Vogel lock_init = TRUE; 33561ae650dSJack F Vogel mtx_init(&ixl_reset_mtx, 33661ae650dSJack F Vogel "ixl_reset", 33761ae650dSJack F Vogel "IXL RESET Lock", MTX_DEF); 33861ae650dSJack F Vogel } 33961ae650dSJack F Vogel return (BUS_PROBE_DEFAULT); 34061ae650dSJack F Vogel } 34161ae650dSJack F Vogel ent++; 34261ae650dSJack F Vogel } 34361ae650dSJack F Vogel return (ENXIO); 34461ae650dSJack F Vogel } 34561ae650dSJack F Vogel 34661ae650dSJack F Vogel /********************************************************************* 34761ae650dSJack F Vogel * Device initialization routine 34861ae650dSJack F Vogel * 34961ae650dSJack F Vogel * The attach entry point is called when the driver is being loaded. 35061ae650dSJack F Vogel * This routine identifies the type of hardware, allocates all resources 35161ae650dSJack F Vogel * and initializes the hardware. 35261ae650dSJack F Vogel * 35361ae650dSJack F Vogel * return 0 on success, positive on failure 35461ae650dSJack F Vogel *********************************************************************/ 35561ae650dSJack F Vogel 35661ae650dSJack F Vogel static int 35761ae650dSJack F Vogel ixl_attach(device_t dev) 35861ae650dSJack F Vogel { 35961ae650dSJack F Vogel struct ixl_pf *pf; 36061ae650dSJack F Vogel struct i40e_hw *hw; 36161ae650dSJack F Vogel struct ixl_vsi *vsi; 36261ae650dSJack F Vogel u16 bus; 36361ae650dSJack F Vogel int error = 0; 36461ae650dSJack F Vogel 36561ae650dSJack F Vogel INIT_DEBUGOUT("ixl_attach: begin"); 36661ae650dSJack F Vogel 36761ae650dSJack F Vogel /* Allocate, clear, and link in our primary soft structure */ 36861ae650dSJack F Vogel pf = device_get_softc(dev); 36961ae650dSJack F Vogel pf->dev = pf->osdep.dev = dev; 37061ae650dSJack F Vogel hw = &pf->hw; 37161ae650dSJack F Vogel 37261ae650dSJack F Vogel /* 37361ae650dSJack F Vogel ** Note this assumes we have a single embedded VSI, 37461ae650dSJack F Vogel ** this could be enhanced later to allocate multiple 37561ae650dSJack F Vogel */ 37661ae650dSJack F Vogel vsi = &pf->vsi; 37761ae650dSJack F Vogel vsi->dev = pf->dev; 37861ae650dSJack F Vogel 37961ae650dSJack F Vogel /* Core Lock Init*/ 38061ae650dSJack F Vogel IXL_PF_LOCK_INIT(pf, device_get_nameunit(dev)); 38161ae650dSJack F Vogel 38261ae650dSJack F Vogel /* Set up the timer callout */ 38361ae650dSJack F Vogel callout_init_mtx(&pf->timer, &pf->pf_mtx, 0); 38461ae650dSJack F Vogel 38561ae650dSJack F Vogel /* Set up sysctls */ 38661ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 38761ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 38861ae650dSJack F Vogel OID_AUTO, "fc", CTLTYPE_INT | CTLFLAG_RW, 38961ae650dSJack F Vogel pf, 0, ixl_set_flowcntl, "I", "Flow Control"); 39061ae650dSJack F Vogel 39161ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 39261ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 39361ae650dSJack F Vogel OID_AUTO, "advertise_speed", CTLTYPE_INT | CTLFLAG_RW, 39461ae650dSJack F Vogel pf, 0, ixl_set_advertise, "I", "Advertised Speed"); 39561ae650dSJack F Vogel 39661ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 39761ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 39861ae650dSJack F Vogel OID_AUTO, "current_speed", CTLTYPE_STRING | CTLFLAG_RD, 39961ae650dSJack F Vogel pf, 0, ixl_current_speed, "A", "Current Port Speed"); 40061ae650dSJack F Vogel 40161ae650dSJack F Vogel SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), 40261ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 40361ae650dSJack F Vogel OID_AUTO, "rx_itr", CTLTYPE_INT | CTLFLAG_RW, 40461ae650dSJack F Vogel &ixl_rx_itr, IXL_ITR_8K, "RX ITR"); 40561ae650dSJack F Vogel 40661ae650dSJack F Vogel SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), 40761ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 40861ae650dSJack F Vogel OID_AUTO, "dynamic_rx_itr", CTLTYPE_INT | CTLFLAG_RW, 40961ae650dSJack F Vogel &ixl_dynamic_rx_itr, 0, "Dynamic RX ITR"); 41061ae650dSJack F Vogel 41161ae650dSJack F Vogel SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), 41261ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 41361ae650dSJack F Vogel OID_AUTO, "tx_itr", CTLTYPE_INT | CTLFLAG_RW, 41461ae650dSJack F Vogel &ixl_tx_itr, IXL_ITR_4K, "TX ITR"); 41561ae650dSJack F Vogel 41661ae650dSJack F Vogel SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), 41761ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 41861ae650dSJack F Vogel OID_AUTO, "dynamic_tx_itr", CTLTYPE_INT | CTLFLAG_RW, 41961ae650dSJack F Vogel &ixl_dynamic_tx_itr, 0, "Dynamic TX ITR"); 42061ae650dSJack F Vogel 42161ae650dSJack F Vogel #ifdef IXL_DEBUG 42261ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 42361ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 42461ae650dSJack F Vogel OID_AUTO, "link_status", CTLTYPE_STRING | CTLFLAG_RD, 42561ae650dSJack F Vogel pf, 0, ixl_sysctl_link_status, "A", "Current Link Status"); 42661ae650dSJack F Vogel 42761ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 42861ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 42961ae650dSJack F Vogel OID_AUTO, "phy_abilities", CTLTYPE_STRING | CTLFLAG_RD, 43061ae650dSJack F Vogel pf, 0, ixl_sysctl_phy_abilities, "A", "PHY Abilities"); 43161ae650dSJack F Vogel 43261ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 43361ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 43461ae650dSJack F Vogel OID_AUTO, "filter_list", CTLTYPE_STRING | CTLFLAG_RD, 43561ae650dSJack F Vogel pf, 0, ixl_sysctl_sw_filter_list, "A", "SW Filter List"); 43661ae650dSJack F Vogel 43761ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 43861ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 43961ae650dSJack F Vogel OID_AUTO, "hw_res_info", CTLTYPE_STRING | CTLFLAG_RD, 44061ae650dSJack F Vogel pf, 0, ixl_sysctl_hw_res_info, "A", "HW Resource Allocation"); 44161ae650dSJack F Vogel 44261ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 44361ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 44461ae650dSJack F Vogel OID_AUTO, "dump_desc", CTLTYPE_INT | CTLFLAG_WR, 44561ae650dSJack F Vogel pf, 0, ixl_sysctl_dump_txd, "I", "Desc dump"); 44661ae650dSJack F Vogel #endif 44761ae650dSJack F Vogel 44861ae650dSJack F Vogel /* Save off the information about this board */ 44961ae650dSJack F Vogel hw->vendor_id = pci_get_vendor(dev); 45061ae650dSJack F Vogel hw->device_id = pci_get_device(dev); 45161ae650dSJack F Vogel hw->revision_id = pci_read_config(dev, PCIR_REVID, 1); 45261ae650dSJack F Vogel hw->subsystem_vendor_id = 45361ae650dSJack F Vogel pci_read_config(dev, PCIR_SUBVEND_0, 2); 45461ae650dSJack F Vogel hw->subsystem_device_id = 45561ae650dSJack F Vogel pci_read_config(dev, PCIR_SUBDEV_0, 2); 45661ae650dSJack F Vogel 45761ae650dSJack F Vogel hw->bus.device = pci_get_slot(dev); 45861ae650dSJack F Vogel hw->bus.func = pci_get_function(dev); 45961ae650dSJack F Vogel 46061ae650dSJack F Vogel /* Do PCI setup - map BAR0, etc */ 46161ae650dSJack F Vogel if (ixl_allocate_pci_resources(pf)) { 46261ae650dSJack F Vogel device_printf(dev, "Allocation of PCI resources failed\n"); 46361ae650dSJack F Vogel error = ENXIO; 46461ae650dSJack F Vogel goto err_out; 46561ae650dSJack F Vogel } 46661ae650dSJack F Vogel 46761ae650dSJack F Vogel /* Create for initial debugging use */ 46861ae650dSJack F Vogel SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 46961ae650dSJack F Vogel SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 47061ae650dSJack F Vogel OID_AUTO, "debug", CTLTYPE_INT|CTLFLAG_RW, pf, 0, 47161ae650dSJack F Vogel ixl_debug_info, "I", "Debug Information"); 47261ae650dSJack F Vogel 47361ae650dSJack F Vogel 47461ae650dSJack F Vogel /* Establish a clean starting point */ 47561ae650dSJack F Vogel i40e_clear_hw(hw); 47661ae650dSJack F Vogel error = i40e_pf_reset(hw); 47761ae650dSJack F Vogel if (error) { 47861ae650dSJack F Vogel device_printf(dev,"PF reset failure %x\n", error); 47961ae650dSJack F Vogel error = EIO; 48061ae650dSJack F Vogel goto err_out; 48161ae650dSJack F Vogel } 48261ae650dSJack F Vogel 48361ae650dSJack F Vogel /* For now always do an initial CORE reset on first device */ 48461ae650dSJack F Vogel { 48561ae650dSJack F Vogel static int ixl_dev_count; 48661ae650dSJack F Vogel static int ixl_dev_track[32]; 48761ae650dSJack F Vogel u32 my_dev; 48861ae650dSJack F Vogel int i, found = FALSE; 48961ae650dSJack F Vogel u16 bus = pci_get_bus(dev); 49061ae650dSJack F Vogel 49161ae650dSJack F Vogel mtx_lock(&ixl_reset_mtx); 49261ae650dSJack F Vogel my_dev = (bus << 8) | hw->bus.device; 49361ae650dSJack F Vogel 49461ae650dSJack F Vogel for (i = 0; i < ixl_dev_count; i++) { 49561ae650dSJack F Vogel if (ixl_dev_track[i] == my_dev) 49661ae650dSJack F Vogel found = TRUE; 49761ae650dSJack F Vogel } 49861ae650dSJack F Vogel 49961ae650dSJack F Vogel if (!found) { 50061ae650dSJack F Vogel u32 reg; 50161ae650dSJack F Vogel 50261ae650dSJack F Vogel ixl_dev_track[ixl_dev_count] = my_dev; 50361ae650dSJack F Vogel ixl_dev_count++; 50461ae650dSJack F Vogel 50561ae650dSJack F Vogel INIT_DEBUGOUT("Initial CORE RESET\n"); 50661ae650dSJack F Vogel wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); 50761ae650dSJack F Vogel ixl_flush(hw); 50861ae650dSJack F Vogel i = 50; 50961ae650dSJack F Vogel do { 51061ae650dSJack F Vogel i40e_msec_delay(50); 51161ae650dSJack F Vogel reg = rd32(hw, I40E_GLGEN_RSTAT); 51261ae650dSJack F Vogel if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK)) 51361ae650dSJack F Vogel break; 51461ae650dSJack F Vogel } while (i--); 51561ae650dSJack F Vogel 51661ae650dSJack F Vogel /* paranoia */ 51761ae650dSJack F Vogel wr32(hw, I40E_PF_ATQLEN, 0); 51861ae650dSJack F Vogel wr32(hw, I40E_PF_ATQBAL, 0); 51961ae650dSJack F Vogel wr32(hw, I40E_PF_ATQBAH, 0); 52061ae650dSJack F Vogel i40e_clear_pxe_mode(hw); 52161ae650dSJack F Vogel } 52261ae650dSJack F Vogel mtx_unlock(&ixl_reset_mtx); 52361ae650dSJack F Vogel } 52461ae650dSJack F Vogel 52561ae650dSJack F Vogel /* Set admin queue parameters */ 52661ae650dSJack F Vogel hw->aq.num_arq_entries = IXL_AQ_LEN; 52761ae650dSJack F Vogel hw->aq.num_asq_entries = IXL_AQ_LEN; 52861ae650dSJack F Vogel hw->aq.arq_buf_size = IXL_AQ_BUFSZ; 52961ae650dSJack F Vogel hw->aq.asq_buf_size = IXL_AQ_BUFSZ; 53061ae650dSJack F Vogel 53161ae650dSJack F Vogel /* Initialize the shared code */ 53261ae650dSJack F Vogel error = i40e_init_shared_code(hw); 53361ae650dSJack F Vogel if (error) { 53461ae650dSJack F Vogel device_printf(dev,"Unable to initialize the shared code\n"); 53561ae650dSJack F Vogel error = EIO; 53661ae650dSJack F Vogel goto err_out; 53761ae650dSJack F Vogel } 53861ae650dSJack F Vogel 53961ae650dSJack F Vogel /* Set up the admin queue */ 54061ae650dSJack F Vogel error = i40e_init_adminq(hw); 54161ae650dSJack F Vogel if (error) { 54261ae650dSJack F Vogel device_printf(dev, "The driver for the device stopped " 54361ae650dSJack F Vogel "because the NVM image is newer than expected.\n" 54461ae650dSJack F Vogel "You must install the most recent version of " 54561ae650dSJack F Vogel " the network driver.\n"); 54661ae650dSJack F Vogel goto err_out; 54761ae650dSJack F Vogel } 54861ae650dSJack F Vogel device_printf(dev, "%s\n", ixl_fw_version_str(hw)); 54961ae650dSJack F Vogel 55061ae650dSJack F Vogel if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && 55161ae650dSJack F Vogel hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) 55261ae650dSJack F Vogel device_printf(dev, "The driver for the device detected " 55361ae650dSJack F Vogel "a newer version of the NVM image than expected.\n" 55461ae650dSJack F Vogel "Please install the most recent version of the network driver.\n"); 55561ae650dSJack F Vogel else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || 55661ae650dSJack F Vogel hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) 55761ae650dSJack F Vogel device_printf(dev, "The driver for the device detected " 55861ae650dSJack F Vogel "an older version of the NVM image than expected.\n" 55961ae650dSJack F Vogel "Please update the NVM image.\n"); 56061ae650dSJack F Vogel 56161ae650dSJack F Vogel /* Clear PXE mode */ 56261ae650dSJack F Vogel i40e_clear_pxe_mode(hw); 56361ae650dSJack F Vogel 56461ae650dSJack F Vogel /* Get capabilities from the device */ 56561ae650dSJack F Vogel error = ixl_get_hw_capabilities(pf); 56661ae650dSJack F Vogel if (error) { 56761ae650dSJack F Vogel device_printf(dev, "HW capabilities failure!\n"); 56861ae650dSJack F Vogel goto err_get_cap; 56961ae650dSJack F Vogel } 57061ae650dSJack F Vogel 57161ae650dSJack F Vogel /* Set up host memory cache */ 57261ae650dSJack F Vogel error = i40e_init_lan_hmc(hw, vsi->num_queues, vsi->num_queues, 0, 0); 57361ae650dSJack F Vogel if (error) { 57461ae650dSJack F Vogel device_printf(dev, "init_lan_hmc failed: %d\n", error); 57561ae650dSJack F Vogel goto err_get_cap; 57661ae650dSJack F Vogel } 57761ae650dSJack F Vogel 57861ae650dSJack F Vogel error = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); 57961ae650dSJack F Vogel if (error) { 58061ae650dSJack F Vogel device_printf(dev, "configure_lan_hmc failed: %d\n", error); 58161ae650dSJack F Vogel goto err_mac_hmc; 58261ae650dSJack F Vogel } 58361ae650dSJack F Vogel 58461ae650dSJack F Vogel /* Disable LLDP from the firmware */ 58561ae650dSJack F Vogel i40e_aq_stop_lldp(hw, TRUE, NULL); 58661ae650dSJack F Vogel 58761ae650dSJack F Vogel i40e_get_mac_addr(hw, hw->mac.addr); 58861ae650dSJack F Vogel error = i40e_validate_mac_addr(hw->mac.addr); 58961ae650dSJack F Vogel if (error) { 59061ae650dSJack F Vogel device_printf(dev, "validate_mac_addr failed: %d\n", error); 59161ae650dSJack F Vogel goto err_mac_hmc; 59261ae650dSJack F Vogel } 59361ae650dSJack F Vogel bcopy(hw->mac.addr, hw->mac.perm_addr, ETHER_ADDR_LEN); 59461ae650dSJack F Vogel i40e_get_port_mac_addr(hw, hw->mac.port_addr); 59561ae650dSJack F Vogel 59661ae650dSJack F Vogel if (ixl_setup_stations(pf) != 0) { 59761ae650dSJack F Vogel device_printf(dev, "setup stations failed!\n"); 59861ae650dSJack F Vogel error = ENOMEM; 59961ae650dSJack F Vogel goto err_mac_hmc; 60061ae650dSJack F Vogel } 60161ae650dSJack F Vogel 60261ae650dSJack F Vogel /* Initialize mac filter list for VSI */ 60361ae650dSJack F Vogel SLIST_INIT(&vsi->ftl); 60461ae650dSJack F Vogel 60561ae650dSJack F Vogel /* Set up interrupt routing here */ 60661ae650dSJack F Vogel if (pf->msix > 1) 60761ae650dSJack F Vogel error = ixl_assign_vsi_msix(pf); 60861ae650dSJack F Vogel else 60961ae650dSJack F Vogel error = ixl_assign_vsi_legacy(pf); 61061ae650dSJack F Vogel if (error) 61161ae650dSJack F Vogel goto err_late; 61261ae650dSJack F Vogel 61361ae650dSJack F Vogel i40e_msec_delay(75); 61461ae650dSJack F Vogel error = i40e_aq_set_link_restart_an(hw, TRUE, NULL); 61561ae650dSJack F Vogel if (error) { 61661ae650dSJack F Vogel device_printf(dev, "link restart failed, aq_err=%d\n", 61761ae650dSJack F Vogel pf->hw.aq.asq_last_status); 61861ae650dSJack F Vogel } 61961ae650dSJack F Vogel 62061ae650dSJack F Vogel /* Determine link state */ 62161ae650dSJack F Vogel vsi->link_up = ixl_config_link(hw); 62261ae650dSJack F Vogel 62361ae650dSJack F Vogel /* Report if Unqualified modules are found */ 62461ae650dSJack F Vogel if ((vsi->link_up == FALSE) && 62561ae650dSJack F Vogel (pf->hw.phy.link_info.link_info & 62661ae650dSJack F Vogel I40E_AQ_MEDIA_AVAILABLE) && 62761ae650dSJack F Vogel (!(pf->hw.phy.link_info.an_info & 62861ae650dSJack F Vogel I40E_AQ_QUALIFIED_MODULE))) 62961ae650dSJack F Vogel device_printf(dev, "Link failed because " 63061ae650dSJack F Vogel "an unqualified module was detected\n"); 63161ae650dSJack F Vogel 63261ae650dSJack F Vogel /* Setup OS specific network interface */ 63361ae650dSJack F Vogel if (ixl_setup_interface(dev, vsi) != 0) 63461ae650dSJack F Vogel goto err_late; 63561ae650dSJack F Vogel 63661ae650dSJack F Vogel /* Get the bus configuration and set the shared code */ 63761ae650dSJack F Vogel bus = ixl_get_bus_info(hw, dev); 63861ae650dSJack F Vogel i40e_set_pci_config_data(hw, bus); 63961ae650dSJack F Vogel 64061ae650dSJack F Vogel /* Initialize statistics */ 64161ae650dSJack F Vogel ixl_pf_reset_stats(pf); 64261ae650dSJack F Vogel ixl_update_stats_counters(pf); 64361ae650dSJack F Vogel ixl_add_hw_stats(pf); 64461ae650dSJack F Vogel 64561ae650dSJack F Vogel /* Register for VLAN events */ 64661ae650dSJack F Vogel vsi->vlan_attach = EVENTHANDLER_REGISTER(vlan_config, 64761ae650dSJack F Vogel ixl_register_vlan, vsi, EVENTHANDLER_PRI_FIRST); 64861ae650dSJack F Vogel vsi->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig, 64961ae650dSJack F Vogel ixl_unregister_vlan, vsi, EVENTHANDLER_PRI_FIRST); 65061ae650dSJack F Vogel 65161ae650dSJack F Vogel INIT_DEBUGOUT("ixl_attach: end"); 65261ae650dSJack F Vogel return (0); 65361ae650dSJack F Vogel 65461ae650dSJack F Vogel err_late: 65561ae650dSJack F Vogel ixl_free_vsi(vsi); 65661ae650dSJack F Vogel err_mac_hmc: 65761ae650dSJack F Vogel i40e_shutdown_lan_hmc(hw); 65861ae650dSJack F Vogel err_get_cap: 65961ae650dSJack F Vogel i40e_shutdown_adminq(hw); 66061ae650dSJack F Vogel err_out: 66161ae650dSJack F Vogel if (vsi->ifp != NULL) 66261ae650dSJack F Vogel if_free(vsi->ifp); 66361ae650dSJack F Vogel ixl_free_pci_resources(pf); 66461ae650dSJack F Vogel IXL_PF_LOCK_DESTROY(pf); 66561ae650dSJack F Vogel return (error); 66661ae650dSJack F Vogel } 66761ae650dSJack F Vogel 66861ae650dSJack F Vogel /********************************************************************* 66961ae650dSJack F Vogel * Device removal routine 67061ae650dSJack F Vogel * 67161ae650dSJack F Vogel * The detach entry point is called when the driver is being removed. 67261ae650dSJack F Vogel * This routine stops the adapter and deallocates all the resources 67361ae650dSJack F Vogel * that were allocated for driver operation. 67461ae650dSJack F Vogel * 67561ae650dSJack F Vogel * return 0 on success, positive on failure 67661ae650dSJack F Vogel *********************************************************************/ 67761ae650dSJack F Vogel 67861ae650dSJack F Vogel static int 67961ae650dSJack F Vogel ixl_detach(device_t dev) 68061ae650dSJack F Vogel { 68161ae650dSJack F Vogel struct ixl_pf *pf = device_get_softc(dev); 68261ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 68361ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 68461ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 68561ae650dSJack F Vogel i40e_status status; 68661ae650dSJack F Vogel 68761ae650dSJack F Vogel INIT_DEBUGOUT("ixl_detach: begin"); 68861ae650dSJack F Vogel 68961ae650dSJack F Vogel /* Make sure VLANS are not using driver */ 69061ae650dSJack F Vogel if (vsi->ifp->if_vlantrunk != NULL) { 69161ae650dSJack F Vogel device_printf(dev,"Vlan in use, detach first\n"); 69261ae650dSJack F Vogel return (EBUSY); 69361ae650dSJack F Vogel } 69461ae650dSJack F Vogel 69561ae650dSJack F Vogel IXL_PF_LOCK(pf); 69661ae650dSJack F Vogel ixl_stop(pf); 69761ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 69861ae650dSJack F Vogel 69961ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, que++) { 70061ae650dSJack F Vogel if (que->tq) { 70161ae650dSJack F Vogel taskqueue_drain(que->tq, &que->task); 70261ae650dSJack F Vogel taskqueue_drain(que->tq, &que->tx_task); 70361ae650dSJack F Vogel taskqueue_free(que->tq); 70461ae650dSJack F Vogel } 70561ae650dSJack F Vogel } 70661ae650dSJack F Vogel 70761ae650dSJack F Vogel /* Shutdown LAN HMC */ 70861ae650dSJack F Vogel status = i40e_shutdown_lan_hmc(hw); 70961ae650dSJack F Vogel if (status) 71061ae650dSJack F Vogel device_printf(dev, 71161ae650dSJack F Vogel "Shutdown LAN HMC failed with code %d\n", status); 71261ae650dSJack F Vogel 71361ae650dSJack F Vogel /* Shutdown admin queue */ 71461ae650dSJack F Vogel status = i40e_shutdown_adminq(hw); 71561ae650dSJack F Vogel if (status) 71661ae650dSJack F Vogel device_printf(dev, 71761ae650dSJack F Vogel "Shutdown Admin queue failed with code %d\n", status); 71861ae650dSJack F Vogel 71961ae650dSJack F Vogel /* Unregister VLAN events */ 72061ae650dSJack F Vogel if (vsi->vlan_attach != NULL) 72161ae650dSJack F Vogel EVENTHANDLER_DEREGISTER(vlan_config, vsi->vlan_attach); 72261ae650dSJack F Vogel if (vsi->vlan_detach != NULL) 72361ae650dSJack F Vogel EVENTHANDLER_DEREGISTER(vlan_unconfig, vsi->vlan_detach); 72461ae650dSJack F Vogel 72561ae650dSJack F Vogel ether_ifdetach(vsi->ifp); 72661ae650dSJack F Vogel callout_drain(&pf->timer); 72761ae650dSJack F Vogel 72861ae650dSJack F Vogel ixl_free_pci_resources(pf); 72961ae650dSJack F Vogel bus_generic_detach(dev); 73061ae650dSJack F Vogel if_free(vsi->ifp); 73161ae650dSJack F Vogel ixl_free_vsi(vsi); 73261ae650dSJack F Vogel IXL_PF_LOCK_DESTROY(pf); 73361ae650dSJack F Vogel return (0); 73461ae650dSJack F Vogel } 73561ae650dSJack F Vogel 73661ae650dSJack F Vogel /********************************************************************* 73761ae650dSJack F Vogel * 73861ae650dSJack F Vogel * Shutdown entry point 73961ae650dSJack F Vogel * 74061ae650dSJack F Vogel **********************************************************************/ 74161ae650dSJack F Vogel 74261ae650dSJack F Vogel static int 74361ae650dSJack F Vogel ixl_shutdown(device_t dev) 74461ae650dSJack F Vogel { 74561ae650dSJack F Vogel struct ixl_pf *pf = device_get_softc(dev); 74661ae650dSJack F Vogel IXL_PF_LOCK(pf); 74761ae650dSJack F Vogel ixl_stop(pf); 74861ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 74961ae650dSJack F Vogel return (0); 75061ae650dSJack F Vogel } 75161ae650dSJack F Vogel 75261ae650dSJack F Vogel 75361ae650dSJack F Vogel /********************************************************************* 75461ae650dSJack F Vogel * 75561ae650dSJack F Vogel * Get the hardware capabilities 75661ae650dSJack F Vogel * 75761ae650dSJack F Vogel **********************************************************************/ 75861ae650dSJack F Vogel 75961ae650dSJack F Vogel static int 76061ae650dSJack F Vogel ixl_get_hw_capabilities(struct ixl_pf *pf) 76161ae650dSJack F Vogel { 76261ae650dSJack F Vogel struct i40e_aqc_list_capabilities_element_resp *buf; 76361ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 76461ae650dSJack F Vogel device_t dev = pf->dev; 76561ae650dSJack F Vogel int error, len; 76661ae650dSJack F Vogel u16 needed; 76761ae650dSJack F Vogel bool again = TRUE; 76861ae650dSJack F Vogel 76961ae650dSJack F Vogel len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); 77061ae650dSJack F Vogel retry: 77161ae650dSJack F Vogel if (!(buf = (struct i40e_aqc_list_capabilities_element_resp *) 77261ae650dSJack F Vogel malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO))) { 77361ae650dSJack F Vogel device_printf(dev, "Unable to allocate cap memory\n"); 77461ae650dSJack F Vogel return (ENOMEM); 77561ae650dSJack F Vogel } 77661ae650dSJack F Vogel 77761ae650dSJack F Vogel /* This populates the hw struct */ 77861ae650dSJack F Vogel error = i40e_aq_discover_capabilities(hw, buf, len, 77961ae650dSJack F Vogel &needed, i40e_aqc_opc_list_func_capabilities, NULL); 78061ae650dSJack F Vogel free(buf, M_DEVBUF); 78161ae650dSJack F Vogel if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) && 78261ae650dSJack F Vogel (again == TRUE)) { 78361ae650dSJack F Vogel /* retry once with a larger buffer */ 78461ae650dSJack F Vogel again = FALSE; 78561ae650dSJack F Vogel len = needed; 78661ae650dSJack F Vogel goto retry; 78761ae650dSJack F Vogel } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { 78861ae650dSJack F Vogel device_printf(dev, "capability discovery failed: %d\n", 78961ae650dSJack F Vogel pf->hw.aq.asq_last_status); 79061ae650dSJack F Vogel return (ENODEV); 79161ae650dSJack F Vogel } 79261ae650dSJack F Vogel 79361ae650dSJack F Vogel /* Capture this PF's starting queue pair */ 79461ae650dSJack F Vogel pf->qbase = hw->func_caps.base_queue; 79561ae650dSJack F Vogel 79661ae650dSJack F Vogel #ifdef IXL_DEBUG 79761ae650dSJack F Vogel device_printf(dev,"pf_id=%d, num_vfs=%d, msix_pf=%d, " 79861ae650dSJack F Vogel "msix_vf=%d, fd_g=%d, fd_b=%d, tx_qp=%d rx_qp=%d qbase=%d\n", 79961ae650dSJack F Vogel hw->pf_id, hw->func_caps.num_vfs, 80061ae650dSJack F Vogel hw->func_caps.num_msix_vectors, 80161ae650dSJack F Vogel hw->func_caps.num_msix_vectors_vf, 80261ae650dSJack F Vogel hw->func_caps.fd_filters_guaranteed, 80361ae650dSJack F Vogel hw->func_caps.fd_filters_best_effort, 80461ae650dSJack F Vogel hw->func_caps.num_tx_qp, 80561ae650dSJack F Vogel hw->func_caps.num_rx_qp, 80661ae650dSJack F Vogel hw->func_caps.base_queue); 80761ae650dSJack F Vogel #endif 80861ae650dSJack F Vogel return (error); 80961ae650dSJack F Vogel } 81061ae650dSJack F Vogel 81161ae650dSJack F Vogel static void 81261ae650dSJack F Vogel ixl_cap_txcsum_tso(struct ixl_vsi *vsi, struct ifnet *ifp, int mask) 81361ae650dSJack F Vogel { 81461ae650dSJack F Vogel device_t dev = vsi->dev; 81561ae650dSJack F Vogel 81661ae650dSJack F Vogel /* Enable/disable TXCSUM/TSO4 */ 81761ae650dSJack F Vogel if (!(ifp->if_capenable & IFCAP_TXCSUM) 81861ae650dSJack F Vogel && !(ifp->if_capenable & IFCAP_TSO4)) { 81961ae650dSJack F Vogel if (mask & IFCAP_TXCSUM) { 82061ae650dSJack F Vogel ifp->if_capenable |= IFCAP_TXCSUM; 82161ae650dSJack F Vogel /* enable TXCSUM, restore TSO if previously enabled */ 82261ae650dSJack F Vogel if (vsi->flags & IXL_FLAGS_KEEP_TSO4) { 82361ae650dSJack F Vogel vsi->flags &= ~IXL_FLAGS_KEEP_TSO4; 82461ae650dSJack F Vogel ifp->if_capenable |= IFCAP_TSO4; 82561ae650dSJack F Vogel } 82661ae650dSJack F Vogel } 82761ae650dSJack F Vogel else if (mask & IFCAP_TSO4) { 82861ae650dSJack F Vogel ifp->if_capenable |= (IFCAP_TXCSUM | IFCAP_TSO4); 82961ae650dSJack F Vogel vsi->flags &= ~IXL_FLAGS_KEEP_TSO4; 83061ae650dSJack F Vogel device_printf(dev, 83161ae650dSJack F Vogel "TSO4 requires txcsum, enabling both...\n"); 83261ae650dSJack F Vogel } 83361ae650dSJack F Vogel } else if((ifp->if_capenable & IFCAP_TXCSUM) 83461ae650dSJack F Vogel && !(ifp->if_capenable & IFCAP_TSO4)) { 83561ae650dSJack F Vogel if (mask & IFCAP_TXCSUM) 83661ae650dSJack F Vogel ifp->if_capenable &= ~IFCAP_TXCSUM; 83761ae650dSJack F Vogel else if (mask & IFCAP_TSO4) 83861ae650dSJack F Vogel ifp->if_capenable |= IFCAP_TSO4; 83961ae650dSJack F Vogel } else if((ifp->if_capenable & IFCAP_TXCSUM) 84061ae650dSJack F Vogel && (ifp->if_capenable & IFCAP_TSO4)) { 84161ae650dSJack F Vogel if (mask & IFCAP_TXCSUM) { 84261ae650dSJack F Vogel vsi->flags |= IXL_FLAGS_KEEP_TSO4; 84361ae650dSJack F Vogel ifp->if_capenable &= ~(IFCAP_TXCSUM | IFCAP_TSO4); 84461ae650dSJack F Vogel device_printf(dev, 84561ae650dSJack F Vogel "TSO4 requires txcsum, disabling both...\n"); 84661ae650dSJack F Vogel } else if (mask & IFCAP_TSO4) 84761ae650dSJack F Vogel ifp->if_capenable &= ~IFCAP_TSO4; 84861ae650dSJack F Vogel } 84961ae650dSJack F Vogel 85061ae650dSJack F Vogel /* Enable/disable TXCSUM_IPV6/TSO6 */ 85161ae650dSJack F Vogel if (!(ifp->if_capenable & IFCAP_TXCSUM_IPV6) 85261ae650dSJack F Vogel && !(ifp->if_capenable & IFCAP_TSO6)) { 85361ae650dSJack F Vogel if (mask & IFCAP_TXCSUM_IPV6) { 85461ae650dSJack F Vogel ifp->if_capenable |= IFCAP_TXCSUM_IPV6; 85561ae650dSJack F Vogel if (vsi->flags & IXL_FLAGS_KEEP_TSO6) { 85661ae650dSJack F Vogel vsi->flags &= ~IXL_FLAGS_KEEP_TSO6; 85761ae650dSJack F Vogel ifp->if_capenable |= IFCAP_TSO6; 85861ae650dSJack F Vogel } 85961ae650dSJack F Vogel } else if (mask & IFCAP_TSO6) { 86061ae650dSJack F Vogel ifp->if_capenable |= (IFCAP_TXCSUM_IPV6 | IFCAP_TSO6); 86161ae650dSJack F Vogel vsi->flags &= ~IXL_FLAGS_KEEP_TSO6; 86261ae650dSJack F Vogel device_printf(dev, 86361ae650dSJack F Vogel "TSO6 requires txcsum6, enabling both...\n"); 86461ae650dSJack F Vogel } 86561ae650dSJack F Vogel } else if((ifp->if_capenable & IFCAP_TXCSUM_IPV6) 86661ae650dSJack F Vogel && !(ifp->if_capenable & IFCAP_TSO6)) { 86761ae650dSJack F Vogel if (mask & IFCAP_TXCSUM_IPV6) 86861ae650dSJack F Vogel ifp->if_capenable &= ~IFCAP_TXCSUM_IPV6; 86961ae650dSJack F Vogel else if (mask & IFCAP_TSO6) 87061ae650dSJack F Vogel ifp->if_capenable |= IFCAP_TSO6; 87161ae650dSJack F Vogel } else if ((ifp->if_capenable & IFCAP_TXCSUM_IPV6) 87261ae650dSJack F Vogel && (ifp->if_capenable & IFCAP_TSO6)) { 87361ae650dSJack F Vogel if (mask & IFCAP_TXCSUM_IPV6) { 87461ae650dSJack F Vogel vsi->flags |= IXL_FLAGS_KEEP_TSO6; 87561ae650dSJack F Vogel ifp->if_capenable &= ~(IFCAP_TXCSUM_IPV6 | IFCAP_TSO6); 87661ae650dSJack F Vogel device_printf(dev, 87761ae650dSJack F Vogel "TSO6 requires txcsum6, disabling both...\n"); 87861ae650dSJack F Vogel } else if (mask & IFCAP_TSO6) 87961ae650dSJack F Vogel ifp->if_capenable &= ~IFCAP_TSO6; 88061ae650dSJack F Vogel } 88161ae650dSJack F Vogel } 88261ae650dSJack F Vogel 88361ae650dSJack F Vogel /********************************************************************* 88461ae650dSJack F Vogel * Ioctl entry point 88561ae650dSJack F Vogel * 88661ae650dSJack F Vogel * ixl_ioctl is called when the user wants to configure the 88761ae650dSJack F Vogel * interface. 88861ae650dSJack F Vogel * 88961ae650dSJack F Vogel * return 0 on success, positive on failure 89061ae650dSJack F Vogel **********************************************************************/ 89161ae650dSJack F Vogel 89261ae650dSJack F Vogel static int 89361ae650dSJack F Vogel ixl_ioctl(struct ifnet * ifp, u_long command, caddr_t data) 89461ae650dSJack F Vogel { 89561ae650dSJack F Vogel struct ixl_vsi *vsi = ifp->if_softc; 89661ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)vsi->back; 89761ae650dSJack F Vogel struct ifreq *ifr = (struct ifreq *) data; 89861ae650dSJack F Vogel #if defined(INET) || defined(INET6) 89961ae650dSJack F Vogel struct ifaddr *ifa = (struct ifaddr *)data; 90061ae650dSJack F Vogel bool avoid_reset = FALSE; 90161ae650dSJack F Vogel #endif 90261ae650dSJack F Vogel int error = 0; 90361ae650dSJack F Vogel 90461ae650dSJack F Vogel switch (command) { 90561ae650dSJack F Vogel 90661ae650dSJack F Vogel case SIOCSIFADDR: 90761ae650dSJack F Vogel #ifdef INET 90861ae650dSJack F Vogel if (ifa->ifa_addr->sa_family == AF_INET) 90961ae650dSJack F Vogel avoid_reset = TRUE; 91061ae650dSJack F Vogel #endif 91161ae650dSJack F Vogel #ifdef INET6 91261ae650dSJack F Vogel if (ifa->ifa_addr->sa_family == AF_INET6) 91361ae650dSJack F Vogel avoid_reset = TRUE; 91461ae650dSJack F Vogel #endif 91561ae650dSJack F Vogel #if defined(INET) || defined(INET6) 91661ae650dSJack F Vogel /* 91761ae650dSJack F Vogel ** Calling init results in link renegotiation, 91861ae650dSJack F Vogel ** so we avoid doing it when possible. 91961ae650dSJack F Vogel */ 92061ae650dSJack F Vogel if (avoid_reset) { 92161ae650dSJack F Vogel ifp->if_flags |= IFF_UP; 92261ae650dSJack F Vogel if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) 92361ae650dSJack F Vogel ixl_init(pf); 9247e0dde7dSBjoern A. Zeeb #ifdef INET 92561ae650dSJack F Vogel if (!(ifp->if_flags & IFF_NOARP)) 92661ae650dSJack F Vogel arp_ifinit(ifp, ifa); 9277e0dde7dSBjoern A. Zeeb #endif 92861ae650dSJack F Vogel } else 92961ae650dSJack F Vogel error = ether_ioctl(ifp, command, data); 93061ae650dSJack F Vogel break; 93161ae650dSJack F Vogel #endif 93261ae650dSJack F Vogel case SIOCSIFMTU: 93361ae650dSJack F Vogel IOCTL_DEBUGOUT("ioctl: SIOCSIFMTU (Set Interface MTU)"); 93461ae650dSJack F Vogel if (ifr->ifr_mtu > IXL_MAX_FRAME - 93561ae650dSJack F Vogel ETHER_HDR_LEN - ETHER_CRC_LEN - ETHER_VLAN_ENCAP_LEN) { 93661ae650dSJack F Vogel error = EINVAL; 93761ae650dSJack F Vogel } else { 93861ae650dSJack F Vogel IXL_PF_LOCK(pf); 93961ae650dSJack F Vogel ifp->if_mtu = ifr->ifr_mtu; 94061ae650dSJack F Vogel vsi->max_frame_size = 94161ae650dSJack F Vogel ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN 94261ae650dSJack F Vogel + ETHER_VLAN_ENCAP_LEN; 94361ae650dSJack F Vogel ixl_init_locked(pf); 94461ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 94561ae650dSJack F Vogel } 94661ae650dSJack F Vogel break; 94761ae650dSJack F Vogel case SIOCSIFFLAGS: 94861ae650dSJack F Vogel IOCTL_DEBUGOUT("ioctl: SIOCSIFFLAGS (Set Interface Flags)"); 94961ae650dSJack F Vogel IXL_PF_LOCK(pf); 95061ae650dSJack F Vogel if (ifp->if_flags & IFF_UP) { 95161ae650dSJack F Vogel if ((ifp->if_drv_flags & IFF_DRV_RUNNING)) { 95261ae650dSJack F Vogel if ((ifp->if_flags ^ pf->if_flags) & 95361ae650dSJack F Vogel (IFF_PROMISC | IFF_ALLMULTI)) { 95461ae650dSJack F Vogel ixl_set_promisc(vsi); 95561ae650dSJack F Vogel } 95661ae650dSJack F Vogel } else 95761ae650dSJack F Vogel ixl_init_locked(pf); 95861ae650dSJack F Vogel } else 95961ae650dSJack F Vogel if (ifp->if_drv_flags & IFF_DRV_RUNNING) 96061ae650dSJack F Vogel ixl_stop(pf); 96161ae650dSJack F Vogel pf->if_flags = ifp->if_flags; 96261ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 96361ae650dSJack F Vogel break; 96461ae650dSJack F Vogel case SIOCADDMULTI: 96561ae650dSJack F Vogel IOCTL_DEBUGOUT("ioctl: SIOCADDMULTI"); 96661ae650dSJack F Vogel if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 96761ae650dSJack F Vogel IXL_PF_LOCK(pf); 96861ae650dSJack F Vogel ixl_disable_intr(vsi); 96961ae650dSJack F Vogel ixl_add_multi(vsi); 97061ae650dSJack F Vogel ixl_enable_intr(vsi); 97161ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 97261ae650dSJack F Vogel } 97361ae650dSJack F Vogel break; 97461ae650dSJack F Vogel case SIOCDELMULTI: 97561ae650dSJack F Vogel IOCTL_DEBUGOUT("ioctl: SIOCDELMULTI"); 97661ae650dSJack F Vogel if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 97761ae650dSJack F Vogel IXL_PF_LOCK(pf); 97861ae650dSJack F Vogel ixl_disable_intr(vsi); 97961ae650dSJack F Vogel ixl_del_multi(vsi); 98061ae650dSJack F Vogel ixl_enable_intr(vsi); 98161ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 98261ae650dSJack F Vogel } 98361ae650dSJack F Vogel break; 98461ae650dSJack F Vogel case SIOCSIFMEDIA: 98561ae650dSJack F Vogel case SIOCGIFMEDIA: 98661ae650dSJack F Vogel IOCTL_DEBUGOUT("ioctl: SIOCxIFMEDIA (Get/Set Interface Media)"); 98761ae650dSJack F Vogel error = ifmedia_ioctl(ifp, ifr, &vsi->media, command); 98861ae650dSJack F Vogel break; 98961ae650dSJack F Vogel case SIOCSIFCAP: 99061ae650dSJack F Vogel { 99161ae650dSJack F Vogel int mask = ifr->ifr_reqcap ^ ifp->if_capenable; 99261ae650dSJack F Vogel IOCTL_DEBUGOUT("ioctl: SIOCSIFCAP (Set Capabilities)"); 99361ae650dSJack F Vogel 99461ae650dSJack F Vogel ixl_cap_txcsum_tso(vsi, ifp, mask); 99561ae650dSJack F Vogel 99661ae650dSJack F Vogel if (mask & IFCAP_RXCSUM) 99761ae650dSJack F Vogel ifp->if_capenable ^= IFCAP_RXCSUM; 99861ae650dSJack F Vogel if (mask & IFCAP_RXCSUM_IPV6) 99961ae650dSJack F Vogel ifp->if_capenable ^= IFCAP_RXCSUM_IPV6; 100061ae650dSJack F Vogel if (mask & IFCAP_LRO) 100161ae650dSJack F Vogel ifp->if_capenable ^= IFCAP_LRO; 100261ae650dSJack F Vogel if (mask & IFCAP_VLAN_HWTAGGING) 100361ae650dSJack F Vogel ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING; 100461ae650dSJack F Vogel if (mask & IFCAP_VLAN_HWFILTER) 100561ae650dSJack F Vogel ifp->if_capenable ^= IFCAP_VLAN_HWFILTER; 100661ae650dSJack F Vogel if (mask & IFCAP_VLAN_HWTSO) 100761ae650dSJack F Vogel ifp->if_capenable ^= IFCAP_VLAN_HWTSO; 100861ae650dSJack F Vogel if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 100961ae650dSJack F Vogel IXL_PF_LOCK(pf); 101061ae650dSJack F Vogel ixl_init_locked(pf); 101161ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 101261ae650dSJack F Vogel } 101361ae650dSJack F Vogel VLAN_CAPABILITIES(ifp); 101461ae650dSJack F Vogel 101561ae650dSJack F Vogel break; 101661ae650dSJack F Vogel } 101761ae650dSJack F Vogel 101861ae650dSJack F Vogel default: 101961ae650dSJack F Vogel IOCTL_DEBUGOUT("ioctl: UNKNOWN (0x%X)\n", (int)command); 102061ae650dSJack F Vogel error = ether_ioctl(ifp, command, data); 102161ae650dSJack F Vogel break; 102261ae650dSJack F Vogel } 102361ae650dSJack F Vogel 102461ae650dSJack F Vogel return (error); 102561ae650dSJack F Vogel } 102661ae650dSJack F Vogel 102761ae650dSJack F Vogel 102861ae650dSJack F Vogel /********************************************************************* 102961ae650dSJack F Vogel * Init entry point 103061ae650dSJack F Vogel * 103161ae650dSJack F Vogel * This routine is used in two ways. It is used by the stack as 103261ae650dSJack F Vogel * init entry point in network interface structure. It is also used 103361ae650dSJack F Vogel * by the driver as a hw/sw initialization routine to get to a 103461ae650dSJack F Vogel * consistent state. 103561ae650dSJack F Vogel * 103661ae650dSJack F Vogel * return 0 on success, positive on failure 103761ae650dSJack F Vogel **********************************************************************/ 103861ae650dSJack F Vogel 103961ae650dSJack F Vogel static void 104061ae650dSJack F Vogel ixl_init_locked(struct ixl_pf *pf) 104161ae650dSJack F Vogel { 104261ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 104361ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 104461ae650dSJack F Vogel struct ifnet *ifp = vsi->ifp; 104561ae650dSJack F Vogel device_t dev = pf->dev; 104661ae650dSJack F Vogel struct i40e_filter_control_settings filter; 104761ae650dSJack F Vogel u8 tmpaddr[ETHER_ADDR_LEN]; 104861ae650dSJack F Vogel int ret; 104961ae650dSJack F Vogel 105061ae650dSJack F Vogel mtx_assert(&pf->pf_mtx, MA_OWNED); 105161ae650dSJack F Vogel INIT_DEBUGOUT("ixl_init: begin"); 105261ae650dSJack F Vogel ixl_stop(pf); 105361ae650dSJack F Vogel 105461ae650dSJack F Vogel /* Get the latest mac address... User might use a LAA */ 105561ae650dSJack F Vogel bcopy(IF_LLADDR(vsi->ifp), tmpaddr, 105661ae650dSJack F Vogel I40E_ETH_LENGTH_OF_ADDRESS); 105761ae650dSJack F Vogel if (!cmp_etheraddr(hw->mac.addr, tmpaddr) && 105861ae650dSJack F Vogel i40e_validate_mac_addr(tmpaddr)) { 105961ae650dSJack F Vogel bcopy(tmpaddr, hw->mac.addr, 106061ae650dSJack F Vogel I40E_ETH_LENGTH_OF_ADDRESS); 106161ae650dSJack F Vogel ret = i40e_aq_mac_address_write(hw, 106261ae650dSJack F Vogel I40E_AQC_WRITE_TYPE_LAA_ONLY, 106361ae650dSJack F Vogel hw->mac.addr, NULL); 106461ae650dSJack F Vogel if (ret) { 106561ae650dSJack F Vogel device_printf(dev, "LLA address" 106661ae650dSJack F Vogel "change failed!!\n"); 106761ae650dSJack F Vogel return; 106861ae650dSJack F Vogel } 106961ae650dSJack F Vogel } 107061ae650dSJack F Vogel 107161ae650dSJack F Vogel /* Set the various hardware offload abilities */ 107261ae650dSJack F Vogel ifp->if_hwassist = 0; 107361ae650dSJack F Vogel if (ifp->if_capenable & IFCAP_TSO) 107461ae650dSJack F Vogel ifp->if_hwassist |= CSUM_TSO; 107561ae650dSJack F Vogel if (ifp->if_capenable & IFCAP_TXCSUM) 107661ae650dSJack F Vogel ifp->if_hwassist |= (CSUM_TCP | CSUM_UDP); 107761ae650dSJack F Vogel if (ifp->if_capenable & IFCAP_TXCSUM_IPV6) 107861ae650dSJack F Vogel ifp->if_hwassist |= (CSUM_TCP_IPV6 | CSUM_UDP_IPV6); 107961ae650dSJack F Vogel 108061ae650dSJack F Vogel /* Set up the device filtering */ 108161ae650dSJack F Vogel bzero(&filter, sizeof(filter)); 108261ae650dSJack F Vogel filter.enable_ethtype = TRUE; 108361ae650dSJack F Vogel filter.enable_macvlan = TRUE; 108461ae650dSJack F Vogel #ifdef IXL_FDIR 108561ae650dSJack F Vogel filter.enable_fdir = TRUE; 108661ae650dSJack F Vogel #endif 108761ae650dSJack F Vogel if (i40e_set_filter_control(hw, &filter)) 108861ae650dSJack F Vogel device_printf(dev, "set_filter_control() failed\n"); 108961ae650dSJack F Vogel 109061ae650dSJack F Vogel /* Set up RSS */ 109161ae650dSJack F Vogel ixl_config_rss(vsi); 109261ae650dSJack F Vogel 109361ae650dSJack F Vogel /* Setup the VSI */ 109461ae650dSJack F Vogel ixl_setup_vsi(vsi); 109561ae650dSJack F Vogel 109661ae650dSJack F Vogel /* 109761ae650dSJack F Vogel ** Prepare the rings, hmc contexts, etc... 109861ae650dSJack F Vogel */ 109961ae650dSJack F Vogel if (ixl_initialize_vsi(vsi)) { 110061ae650dSJack F Vogel device_printf(dev, "initialize vsi failed!!\n"); 110161ae650dSJack F Vogel return; 110261ae650dSJack F Vogel } 110361ae650dSJack F Vogel 110461ae650dSJack F Vogel /* Add protocol filters to list */ 110561ae650dSJack F Vogel ixl_init_filters(vsi); 110661ae650dSJack F Vogel 110761ae650dSJack F Vogel /* Setup vlan's if needed */ 110861ae650dSJack F Vogel ixl_setup_vlan_filters(vsi); 110961ae650dSJack F Vogel 111061ae650dSJack F Vogel /* Start the local timer */ 111161ae650dSJack F Vogel callout_reset(&pf->timer, hz, ixl_local_timer, pf); 111261ae650dSJack F Vogel 111361ae650dSJack F Vogel /* Set up MSI/X routing and the ITR settings */ 111461ae650dSJack F Vogel if (ixl_enable_msix) { 111561ae650dSJack F Vogel ixl_configure_msix(pf); 111661ae650dSJack F Vogel ixl_configure_itr(pf); 111761ae650dSJack F Vogel } else 111861ae650dSJack F Vogel ixl_configure_legacy(pf); 111961ae650dSJack F Vogel 112061ae650dSJack F Vogel ixl_enable_rings(vsi); 112161ae650dSJack F Vogel 112261ae650dSJack F Vogel i40e_aq_set_default_vsi(hw, vsi->seid, NULL); 112361ae650dSJack F Vogel 112461ae650dSJack F Vogel /* Set MTU in hardware*/ 112561ae650dSJack F Vogel int aq_error = i40e_aq_set_mac_config(hw, vsi->max_frame_size, 112661ae650dSJack F Vogel TRUE, 0, NULL); 112761ae650dSJack F Vogel if (aq_error) 112861ae650dSJack F Vogel device_printf(vsi->dev, 112961ae650dSJack F Vogel "aq_set_mac_config in init error, code %d\n", 113061ae650dSJack F Vogel aq_error); 113161ae650dSJack F Vogel 113261ae650dSJack F Vogel /* And now turn on interrupts */ 113361ae650dSJack F Vogel ixl_enable_intr(vsi); 113461ae650dSJack F Vogel 113561ae650dSJack F Vogel /* Now inform the stack we're ready */ 113661ae650dSJack F Vogel ifp->if_drv_flags |= IFF_DRV_RUNNING; 113761ae650dSJack F Vogel ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 113861ae650dSJack F Vogel 113961ae650dSJack F Vogel return; 114061ae650dSJack F Vogel } 114161ae650dSJack F Vogel 114261ae650dSJack F Vogel static void 114361ae650dSJack F Vogel ixl_init(void *arg) 114461ae650dSJack F Vogel { 114561ae650dSJack F Vogel struct ixl_pf *pf = arg; 114661ae650dSJack F Vogel 114761ae650dSJack F Vogel IXL_PF_LOCK(pf); 114861ae650dSJack F Vogel ixl_init_locked(pf); 114961ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 115061ae650dSJack F Vogel return; 115161ae650dSJack F Vogel } 115261ae650dSJack F Vogel 115361ae650dSJack F Vogel /* 115461ae650dSJack F Vogel ** 115561ae650dSJack F Vogel ** MSIX Interrupt Handlers and Tasklets 115661ae650dSJack F Vogel ** 115761ae650dSJack F Vogel */ 115861ae650dSJack F Vogel static void 115961ae650dSJack F Vogel ixl_handle_que(void *context, int pending) 116061ae650dSJack F Vogel { 116161ae650dSJack F Vogel struct ixl_queue *que = context; 116261ae650dSJack F Vogel struct ixl_vsi *vsi = que->vsi; 116361ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 116461ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 116561ae650dSJack F Vogel struct ifnet *ifp = vsi->ifp; 116661ae650dSJack F Vogel bool more; 116761ae650dSJack F Vogel 116861ae650dSJack F Vogel if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 116961ae650dSJack F Vogel more = ixl_rxeof(que, IXL_RX_LIMIT); 117061ae650dSJack F Vogel IXL_TX_LOCK(txr); 117161ae650dSJack F Vogel ixl_txeof(que); 117261ae650dSJack F Vogel if (!drbr_empty(ifp, txr->br)) 117361ae650dSJack F Vogel ixl_mq_start_locked(ifp, txr); 117461ae650dSJack F Vogel IXL_TX_UNLOCK(txr); 117561ae650dSJack F Vogel if (more) { 117661ae650dSJack F Vogel taskqueue_enqueue(que->tq, &que->task); 117761ae650dSJack F Vogel return; 117861ae650dSJack F Vogel } 117961ae650dSJack F Vogel } 118061ae650dSJack F Vogel 118161ae650dSJack F Vogel /* Reenable this interrupt - hmmm */ 118261ae650dSJack F Vogel ixl_enable_queue(hw, que->me); 118361ae650dSJack F Vogel return; 118461ae650dSJack F Vogel } 118561ae650dSJack F Vogel 118661ae650dSJack F Vogel 118761ae650dSJack F Vogel /********************************************************************* 118861ae650dSJack F Vogel * 118961ae650dSJack F Vogel * Legacy Interrupt Service routine 119061ae650dSJack F Vogel * 119161ae650dSJack F Vogel **********************************************************************/ 119261ae650dSJack F Vogel void 119361ae650dSJack F Vogel ixl_intr(void *arg) 119461ae650dSJack F Vogel { 119561ae650dSJack F Vogel struct ixl_pf *pf = arg; 119661ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 119761ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 119861ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 119961ae650dSJack F Vogel struct ifnet *ifp = vsi->ifp; 120061ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 120161ae650dSJack F Vogel u32 reg, icr0, mask; 120261ae650dSJack F Vogel bool more_tx, more_rx; 120361ae650dSJack F Vogel 120461ae650dSJack F Vogel ++que->irqs; 120561ae650dSJack F Vogel 120661ae650dSJack F Vogel /* Protect against spurious interrupts */ 120761ae650dSJack F Vogel if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) 120861ae650dSJack F Vogel return; 120961ae650dSJack F Vogel 121061ae650dSJack F Vogel icr0 = rd32(hw, I40E_PFINT_ICR0); 121161ae650dSJack F Vogel 121261ae650dSJack F Vogel reg = rd32(hw, I40E_PFINT_DYN_CTL0); 121361ae650dSJack F Vogel reg = reg | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK; 121461ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTL0, reg); 121561ae650dSJack F Vogel 121661ae650dSJack F Vogel mask = rd32(hw, I40E_PFINT_ICR0_ENA); 121761ae650dSJack F Vogel 121861ae650dSJack F Vogel if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { 121961ae650dSJack F Vogel taskqueue_enqueue(pf->tq, &pf->adminq); 122061ae650dSJack F Vogel return; 122161ae650dSJack F Vogel } 122261ae650dSJack F Vogel 122361ae650dSJack F Vogel more_rx = ixl_rxeof(que, IXL_RX_LIMIT); 122461ae650dSJack F Vogel 122561ae650dSJack F Vogel IXL_TX_LOCK(txr); 122661ae650dSJack F Vogel more_tx = ixl_txeof(que); 122761ae650dSJack F Vogel if (!drbr_empty(vsi->ifp, txr->br)) 122861ae650dSJack F Vogel more_tx = 1; 122961ae650dSJack F Vogel IXL_TX_UNLOCK(txr); 123061ae650dSJack F Vogel 123161ae650dSJack F Vogel /* re-enable other interrupt causes */ 123261ae650dSJack F Vogel wr32(hw, I40E_PFINT_ICR0_ENA, mask); 123361ae650dSJack F Vogel 123461ae650dSJack F Vogel /* And now the queues */ 123561ae650dSJack F Vogel reg = rd32(hw, I40E_QINT_RQCTL(0)); 123661ae650dSJack F Vogel reg |= I40E_QINT_RQCTL_CAUSE_ENA_MASK; 123761ae650dSJack F Vogel wr32(hw, I40E_QINT_RQCTL(0), reg); 123861ae650dSJack F Vogel 123961ae650dSJack F Vogel reg = rd32(hw, I40E_QINT_TQCTL(0)); 124061ae650dSJack F Vogel reg |= I40E_QINT_TQCTL_CAUSE_ENA_MASK; 124161ae650dSJack F Vogel reg &= ~I40E_PFINT_ICR0_INTEVENT_MASK; 124261ae650dSJack F Vogel wr32(hw, I40E_QINT_TQCTL(0), reg); 124361ae650dSJack F Vogel 124461ae650dSJack F Vogel ixl_enable_legacy(hw); 124561ae650dSJack F Vogel 124661ae650dSJack F Vogel return; 124761ae650dSJack F Vogel } 124861ae650dSJack F Vogel 124961ae650dSJack F Vogel 125061ae650dSJack F Vogel /********************************************************************* 125161ae650dSJack F Vogel * 125261ae650dSJack F Vogel * MSIX VSI Interrupt Service routine 125361ae650dSJack F Vogel * 125461ae650dSJack F Vogel **********************************************************************/ 125561ae650dSJack F Vogel void 125661ae650dSJack F Vogel ixl_msix_que(void *arg) 125761ae650dSJack F Vogel { 125861ae650dSJack F Vogel struct ixl_queue *que = arg; 125961ae650dSJack F Vogel struct ixl_vsi *vsi = que->vsi; 126061ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 126161ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 126261ae650dSJack F Vogel bool more_tx, more_rx; 126361ae650dSJack F Vogel 126461ae650dSJack F Vogel /* Protect against spurious interrupts */ 126561ae650dSJack F Vogel if (!(vsi->ifp->if_drv_flags & IFF_DRV_RUNNING)) 126661ae650dSJack F Vogel return; 126761ae650dSJack F Vogel 126861ae650dSJack F Vogel ++que->irqs; 126961ae650dSJack F Vogel 127061ae650dSJack F Vogel more_rx = ixl_rxeof(que, IXL_RX_LIMIT); 127161ae650dSJack F Vogel 127261ae650dSJack F Vogel IXL_TX_LOCK(txr); 127361ae650dSJack F Vogel more_tx = ixl_txeof(que); 127461ae650dSJack F Vogel /* 127561ae650dSJack F Vogel ** Make certain that if the stack 127661ae650dSJack F Vogel ** has anything queued the task gets 127761ae650dSJack F Vogel ** scheduled to handle it. 127861ae650dSJack F Vogel */ 127961ae650dSJack F Vogel if (!drbr_empty(vsi->ifp, txr->br)) 128061ae650dSJack F Vogel more_tx = 1; 128161ae650dSJack F Vogel IXL_TX_UNLOCK(txr); 128261ae650dSJack F Vogel 128361ae650dSJack F Vogel ixl_set_queue_rx_itr(que); 128461ae650dSJack F Vogel ixl_set_queue_tx_itr(que); 128561ae650dSJack F Vogel 128661ae650dSJack F Vogel if (more_tx || more_rx) 128761ae650dSJack F Vogel taskqueue_enqueue(que->tq, &que->task); 128861ae650dSJack F Vogel else 128961ae650dSJack F Vogel ixl_enable_queue(hw, que->me); 129061ae650dSJack F Vogel 129161ae650dSJack F Vogel return; 129261ae650dSJack F Vogel } 129361ae650dSJack F Vogel 129461ae650dSJack F Vogel 129561ae650dSJack F Vogel /********************************************************************* 129661ae650dSJack F Vogel * 129761ae650dSJack F Vogel * MSIX Admin Queue Interrupt Service routine 129861ae650dSJack F Vogel * 129961ae650dSJack F Vogel **********************************************************************/ 130061ae650dSJack F Vogel static void 130161ae650dSJack F Vogel ixl_msix_adminq(void *arg) 130261ae650dSJack F Vogel { 130361ae650dSJack F Vogel struct ixl_pf *pf = arg; 130461ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 130561ae650dSJack F Vogel u32 reg, mask; 130661ae650dSJack F Vogel 130761ae650dSJack F Vogel ++pf->admin_irq; 130861ae650dSJack F Vogel 130961ae650dSJack F Vogel reg = rd32(hw, I40E_PFINT_ICR0); 131061ae650dSJack F Vogel mask = rd32(hw, I40E_PFINT_ICR0_ENA); 131161ae650dSJack F Vogel 131261ae650dSJack F Vogel /* Check on the cause */ 131361ae650dSJack F Vogel if (reg & I40E_PFINT_ICR0_ADMINQ_MASK) 131461ae650dSJack F Vogel mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; 131561ae650dSJack F Vogel 131661ae650dSJack F Vogel if (reg & I40E_PFINT_ICR0_MAL_DETECT_MASK) { 131761ae650dSJack F Vogel ixl_handle_mdd_event(pf); 131861ae650dSJack F Vogel mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; 131961ae650dSJack F Vogel } 132061ae650dSJack F Vogel 132161ae650dSJack F Vogel if (reg & I40E_PFINT_ICR0_VFLR_MASK) 132261ae650dSJack F Vogel mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; 132361ae650dSJack F Vogel 132461ae650dSJack F Vogel reg = rd32(hw, I40E_PFINT_DYN_CTL0); 132561ae650dSJack F Vogel reg = reg | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK; 132661ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTL0, reg); 132761ae650dSJack F Vogel 132861ae650dSJack F Vogel taskqueue_enqueue(pf->tq, &pf->adminq); 132961ae650dSJack F Vogel return; 133061ae650dSJack F Vogel } 133161ae650dSJack F Vogel 133261ae650dSJack F Vogel /********************************************************************* 133361ae650dSJack F Vogel * 133461ae650dSJack F Vogel * Media Ioctl callback 133561ae650dSJack F Vogel * 133661ae650dSJack F Vogel * This routine is called whenever the user queries the status of 133761ae650dSJack F Vogel * the interface using ifconfig. 133861ae650dSJack F Vogel * 133961ae650dSJack F Vogel **********************************************************************/ 134061ae650dSJack F Vogel static void 134161ae650dSJack F Vogel ixl_media_status(struct ifnet * ifp, struct ifmediareq * ifmr) 134261ae650dSJack F Vogel { 134361ae650dSJack F Vogel struct ixl_vsi *vsi = ifp->if_softc; 134461ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)vsi->back; 134561ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 134661ae650dSJack F Vogel 134761ae650dSJack F Vogel INIT_DEBUGOUT("ixl_media_status: begin"); 134861ae650dSJack F Vogel IXL_PF_LOCK(pf); 134961ae650dSJack F Vogel 135061ae650dSJack F Vogel ixl_update_link_status(pf); 135161ae650dSJack F Vogel 135261ae650dSJack F Vogel ifmr->ifm_status = IFM_AVALID; 135361ae650dSJack F Vogel ifmr->ifm_active = IFM_ETHER; 135461ae650dSJack F Vogel 135561ae650dSJack F Vogel if (!vsi->link_up) { 135661ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 135761ae650dSJack F Vogel return; 135861ae650dSJack F Vogel } 135961ae650dSJack F Vogel 136061ae650dSJack F Vogel ifmr->ifm_status |= IFM_ACTIVE; 136161ae650dSJack F Vogel /* Hardware is always full-duplex */ 136261ae650dSJack F Vogel ifmr->ifm_active |= IFM_FDX; 136361ae650dSJack F Vogel 136461ae650dSJack F Vogel switch (hw->phy.link_info.phy_type) { 136561ae650dSJack F Vogel /* 100 M */ 136661ae650dSJack F Vogel case I40E_PHY_TYPE_100BASE_TX: 136761ae650dSJack F Vogel ifmr->ifm_active |= IFM_100_TX; 136861ae650dSJack F Vogel break; 136961ae650dSJack F Vogel /* 1 G */ 137061ae650dSJack F Vogel case I40E_PHY_TYPE_1000BASE_T: 137161ae650dSJack F Vogel ifmr->ifm_active |= IFM_1000_T; 137261ae650dSJack F Vogel break; 137361ae650dSJack F Vogel case I40E_PHY_TYPE_1000BASE_SX: 137461ae650dSJack F Vogel ifmr->ifm_active |= IFM_1000_SX; 137561ae650dSJack F Vogel break; 137661ae650dSJack F Vogel case I40E_PHY_TYPE_1000BASE_LX: 137761ae650dSJack F Vogel ifmr->ifm_active |= IFM_1000_LX; 137861ae650dSJack F Vogel break; 137961ae650dSJack F Vogel /* 10 G */ 138061ae650dSJack F Vogel case I40E_PHY_TYPE_10GBASE_CR1_CU: 138161ae650dSJack F Vogel case I40E_PHY_TYPE_10GBASE_SFPP_CU: 138261ae650dSJack F Vogel ifmr->ifm_active |= IFM_10G_TWINAX; 138361ae650dSJack F Vogel break; 138461ae650dSJack F Vogel case I40E_PHY_TYPE_10GBASE_SR: 138561ae650dSJack F Vogel ifmr->ifm_active |= IFM_10G_SR; 138661ae650dSJack F Vogel break; 138761ae650dSJack F Vogel case I40E_PHY_TYPE_10GBASE_LR: 138861ae650dSJack F Vogel ifmr->ifm_active |= IFM_10G_LR; 138961ae650dSJack F Vogel break; 139061ae650dSJack F Vogel case I40E_PHY_TYPE_10GBASE_T: 139161ae650dSJack F Vogel ifmr->ifm_active |= IFM_10G_T; 139261ae650dSJack F Vogel break; 139361ae650dSJack F Vogel /* 40 G */ 139461ae650dSJack F Vogel case I40E_PHY_TYPE_40GBASE_CR4: 139561ae650dSJack F Vogel case I40E_PHY_TYPE_40GBASE_CR4_CU: 139661ae650dSJack F Vogel ifmr->ifm_active |= IFM_40G_CR4; 139761ae650dSJack F Vogel break; 139861ae650dSJack F Vogel case I40E_PHY_TYPE_40GBASE_SR4: 139961ae650dSJack F Vogel ifmr->ifm_active |= IFM_40G_SR4; 140061ae650dSJack F Vogel break; 140161ae650dSJack F Vogel case I40E_PHY_TYPE_40GBASE_LR4: 140261ae650dSJack F Vogel ifmr->ifm_active |= IFM_40G_LR4; 140361ae650dSJack F Vogel break; 140461ae650dSJack F Vogel default: 140561ae650dSJack F Vogel ifmr->ifm_active |= IFM_UNKNOWN; 140661ae650dSJack F Vogel break; 140761ae650dSJack F Vogel } 140861ae650dSJack F Vogel /* Report flow control status as well */ 140961ae650dSJack F Vogel if (hw->phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) 141061ae650dSJack F Vogel ifmr->ifm_active |= IFM_ETH_TXPAUSE; 141161ae650dSJack F Vogel if (hw->phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX) 141261ae650dSJack F Vogel ifmr->ifm_active |= IFM_ETH_RXPAUSE; 141361ae650dSJack F Vogel 141461ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 141561ae650dSJack F Vogel 141661ae650dSJack F Vogel return; 141761ae650dSJack F Vogel } 141861ae650dSJack F Vogel 141961ae650dSJack F Vogel /********************************************************************* 142061ae650dSJack F Vogel * 142161ae650dSJack F Vogel * Media Ioctl callback 142261ae650dSJack F Vogel * 142361ae650dSJack F Vogel * This routine is called when the user changes speed/duplex using 142461ae650dSJack F Vogel * media/mediopt option with ifconfig. 142561ae650dSJack F Vogel * 142661ae650dSJack F Vogel **********************************************************************/ 142761ae650dSJack F Vogel static int 142861ae650dSJack F Vogel ixl_media_change(struct ifnet * ifp) 142961ae650dSJack F Vogel { 143061ae650dSJack F Vogel struct ixl_vsi *vsi = ifp->if_softc; 143161ae650dSJack F Vogel struct ifmedia *ifm = &vsi->media; 143261ae650dSJack F Vogel 143361ae650dSJack F Vogel INIT_DEBUGOUT("ixl_media_change: begin"); 143461ae650dSJack F Vogel 143561ae650dSJack F Vogel if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) 143661ae650dSJack F Vogel return (EINVAL); 143761ae650dSJack F Vogel 143861ae650dSJack F Vogel if_printf(ifp, "Media change is currently not supported.\n"); 143961ae650dSJack F Vogel 144061ae650dSJack F Vogel return (ENODEV); 144161ae650dSJack F Vogel } 144261ae650dSJack F Vogel 144361ae650dSJack F Vogel 144461ae650dSJack F Vogel #ifdef IXL_FDIR 144561ae650dSJack F Vogel /* 144661ae650dSJack F Vogel ** ATR: Application Targetted Receive - creates a filter 144761ae650dSJack F Vogel ** based on TX flow info that will keep the receive 144861ae650dSJack F Vogel ** portion of the flow on the same queue. Based on the 144961ae650dSJack F Vogel ** implementation this is only available for TCP connections 145061ae650dSJack F Vogel */ 145161ae650dSJack F Vogel void 145261ae650dSJack F Vogel ixl_atr(struct ixl_queue *que, struct tcphdr *th, int etype) 145361ae650dSJack F Vogel { 145461ae650dSJack F Vogel struct ixl_vsi *vsi = que->vsi; 145561ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 145661ae650dSJack F Vogel struct i40e_filter_program_desc *FDIR; 145761ae650dSJack F Vogel u32 ptype, dtype; 145861ae650dSJack F Vogel int idx; 145961ae650dSJack F Vogel 146061ae650dSJack F Vogel /* check if ATR is enabled and sample rate */ 146161ae650dSJack F Vogel if ((!ixl_enable_fdir) || (!txr->atr_rate)) 146261ae650dSJack F Vogel return; 146361ae650dSJack F Vogel /* 146461ae650dSJack F Vogel ** We sample all TCP SYN/FIN packets, 146561ae650dSJack F Vogel ** or at the selected sample rate 146661ae650dSJack F Vogel */ 146761ae650dSJack F Vogel txr->atr_count++; 146861ae650dSJack F Vogel if (((th->th_flags & (TH_FIN | TH_SYN)) == 0) && 146961ae650dSJack F Vogel (txr->atr_count < txr->atr_rate)) 147061ae650dSJack F Vogel return; 147161ae650dSJack F Vogel txr->atr_count = 0; 147261ae650dSJack F Vogel 147361ae650dSJack F Vogel /* Get a descriptor to use */ 147461ae650dSJack F Vogel idx = txr->next_avail; 147561ae650dSJack F Vogel FDIR = (struct i40e_filter_program_desc *) &txr->base[idx]; 147661ae650dSJack F Vogel if (++idx == que->num_desc) 147761ae650dSJack F Vogel idx = 0; 147861ae650dSJack F Vogel txr->avail--; 147961ae650dSJack F Vogel txr->next_avail = idx; 148061ae650dSJack F Vogel 148161ae650dSJack F Vogel ptype = (que->me << I40E_TXD_FLTR_QW0_QINDEX_SHIFT) & 148261ae650dSJack F Vogel I40E_TXD_FLTR_QW0_QINDEX_MASK; 148361ae650dSJack F Vogel 148461ae650dSJack F Vogel ptype |= (etype == ETHERTYPE_IP) ? 148561ae650dSJack F Vogel (I40E_FILTER_PCTYPE_NONF_IPV4_TCP << 148661ae650dSJack F Vogel I40E_TXD_FLTR_QW0_PCTYPE_SHIFT) : 148761ae650dSJack F Vogel (I40E_FILTER_PCTYPE_NONF_IPV6_TCP << 148861ae650dSJack F Vogel I40E_TXD_FLTR_QW0_PCTYPE_SHIFT); 148961ae650dSJack F Vogel 149061ae650dSJack F Vogel ptype |= vsi->id << I40E_TXD_FLTR_QW0_DEST_VSI_SHIFT; 149161ae650dSJack F Vogel 149261ae650dSJack F Vogel dtype = I40E_TX_DESC_DTYPE_FILTER_PROG; 149361ae650dSJack F Vogel 149461ae650dSJack F Vogel /* 149561ae650dSJack F Vogel ** We use the TCP TH_FIN as a trigger to remove 149661ae650dSJack F Vogel ** the filter, otherwise its an update. 149761ae650dSJack F Vogel */ 149861ae650dSJack F Vogel dtype |= (th->th_flags & TH_FIN) ? 149961ae650dSJack F Vogel (I40E_FILTER_PROGRAM_DESC_PCMD_REMOVE << 150061ae650dSJack F Vogel I40E_TXD_FLTR_QW1_PCMD_SHIFT) : 150161ae650dSJack F Vogel (I40E_FILTER_PROGRAM_DESC_PCMD_ADD_UPDATE << 150261ae650dSJack F Vogel I40E_TXD_FLTR_QW1_PCMD_SHIFT); 150361ae650dSJack F Vogel 150461ae650dSJack F Vogel dtype |= I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX << 150561ae650dSJack F Vogel I40E_TXD_FLTR_QW1_DEST_SHIFT; 150661ae650dSJack F Vogel 150761ae650dSJack F Vogel dtype |= I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID << 150861ae650dSJack F Vogel I40E_TXD_FLTR_QW1_FD_STATUS_SHIFT; 150961ae650dSJack F Vogel 151061ae650dSJack F Vogel FDIR->qindex_flex_ptype_vsi = htole32(ptype); 151161ae650dSJack F Vogel FDIR->dtype_cmd_cntindex = htole32(dtype); 151261ae650dSJack F Vogel return; 151361ae650dSJack F Vogel } 151461ae650dSJack F Vogel #endif 151561ae650dSJack F Vogel 151661ae650dSJack F Vogel 151761ae650dSJack F Vogel static void 151861ae650dSJack F Vogel ixl_set_promisc(struct ixl_vsi *vsi) 151961ae650dSJack F Vogel { 152061ae650dSJack F Vogel struct ifnet *ifp = vsi->ifp; 152161ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 152261ae650dSJack F Vogel int err, mcnt = 0; 152361ae650dSJack F Vogel bool uni = FALSE, multi = FALSE; 152461ae650dSJack F Vogel 152561ae650dSJack F Vogel if (ifp->if_flags & IFF_ALLMULTI) 152661ae650dSJack F Vogel multi = TRUE; 152761ae650dSJack F Vogel else { /* Need to count the multicast addresses */ 152861ae650dSJack F Vogel struct ifmultiaddr *ifma; 152961ae650dSJack F Vogel if_maddr_rlock(ifp); 153061ae650dSJack F Vogel TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 153161ae650dSJack F Vogel if (ifma->ifma_addr->sa_family != AF_LINK) 153261ae650dSJack F Vogel continue; 153361ae650dSJack F Vogel if (mcnt == MAX_MULTICAST_ADDR) 153461ae650dSJack F Vogel break; 153561ae650dSJack F Vogel mcnt++; 153661ae650dSJack F Vogel } 153761ae650dSJack F Vogel if_maddr_runlock(ifp); 153861ae650dSJack F Vogel } 153961ae650dSJack F Vogel 154061ae650dSJack F Vogel if (mcnt >= MAX_MULTICAST_ADDR) 154161ae650dSJack F Vogel multi = TRUE; 154261ae650dSJack F Vogel if (ifp->if_flags & IFF_PROMISC) 154361ae650dSJack F Vogel uni = TRUE; 154461ae650dSJack F Vogel 154561ae650dSJack F Vogel err = i40e_aq_set_vsi_unicast_promiscuous(hw, 154661ae650dSJack F Vogel vsi->seid, uni, NULL); 154761ae650dSJack F Vogel err = i40e_aq_set_vsi_multicast_promiscuous(hw, 154861ae650dSJack F Vogel vsi->seid, multi, NULL); 154961ae650dSJack F Vogel return; 155061ae650dSJack F Vogel } 155161ae650dSJack F Vogel 155261ae650dSJack F Vogel /********************************************************************* 155361ae650dSJack F Vogel * Filter Routines 155461ae650dSJack F Vogel * 155561ae650dSJack F Vogel * Routines for multicast and vlan filter management. 155661ae650dSJack F Vogel * 155761ae650dSJack F Vogel *********************************************************************/ 155861ae650dSJack F Vogel static void 155961ae650dSJack F Vogel ixl_add_multi(struct ixl_vsi *vsi) 156061ae650dSJack F Vogel { 156161ae650dSJack F Vogel struct ifmultiaddr *ifma; 156261ae650dSJack F Vogel struct ifnet *ifp = vsi->ifp; 156361ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 156461ae650dSJack F Vogel int mcnt = 0, flags; 156561ae650dSJack F Vogel 156661ae650dSJack F Vogel IOCTL_DEBUGOUT("ixl_add_multi: begin"); 156761ae650dSJack F Vogel 156861ae650dSJack F Vogel if_maddr_rlock(ifp); 156961ae650dSJack F Vogel /* 157061ae650dSJack F Vogel ** First just get a count, to decide if we 157161ae650dSJack F Vogel ** we simply use multicast promiscuous. 157261ae650dSJack F Vogel */ 157361ae650dSJack F Vogel TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 157461ae650dSJack F Vogel if (ifma->ifma_addr->sa_family != AF_LINK) 157561ae650dSJack F Vogel continue; 157661ae650dSJack F Vogel mcnt++; 157761ae650dSJack F Vogel } 157861ae650dSJack F Vogel if_maddr_runlock(ifp); 157961ae650dSJack F Vogel 158061ae650dSJack F Vogel if (__predict_false(mcnt >= MAX_MULTICAST_ADDR)) { 158161ae650dSJack F Vogel /* delete existing MC filters */ 158261ae650dSJack F Vogel ixl_del_hw_filters(vsi, mcnt); 158361ae650dSJack F Vogel i40e_aq_set_vsi_multicast_promiscuous(hw, 158461ae650dSJack F Vogel vsi->seid, TRUE, NULL); 158561ae650dSJack F Vogel return; 158661ae650dSJack F Vogel } 158761ae650dSJack F Vogel 158861ae650dSJack F Vogel mcnt = 0; 158961ae650dSJack F Vogel if_maddr_rlock(ifp); 159061ae650dSJack F Vogel TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 159161ae650dSJack F Vogel if (ifma->ifma_addr->sa_family != AF_LINK) 159261ae650dSJack F Vogel continue; 159361ae650dSJack F Vogel ixl_add_mc_filter(vsi, 159461ae650dSJack F Vogel (u8*)LLADDR((struct sockaddr_dl *) ifma->ifma_addr)); 159561ae650dSJack F Vogel mcnt++; 159661ae650dSJack F Vogel } 159761ae650dSJack F Vogel if_maddr_runlock(ifp); 159861ae650dSJack F Vogel if (mcnt > 0) { 159961ae650dSJack F Vogel flags = (IXL_FILTER_ADD | IXL_FILTER_USED | IXL_FILTER_MC); 160061ae650dSJack F Vogel ixl_add_hw_filters(vsi, flags, mcnt); 160161ae650dSJack F Vogel } 160261ae650dSJack F Vogel 160361ae650dSJack F Vogel IOCTL_DEBUGOUT("ixl_add_multi: end"); 160461ae650dSJack F Vogel return; 160561ae650dSJack F Vogel } 160661ae650dSJack F Vogel 160761ae650dSJack F Vogel static void 160861ae650dSJack F Vogel ixl_del_multi(struct ixl_vsi *vsi) 160961ae650dSJack F Vogel { 161061ae650dSJack F Vogel struct ifnet *ifp = vsi->ifp; 161161ae650dSJack F Vogel struct ifmultiaddr *ifma; 161261ae650dSJack F Vogel struct ixl_mac_filter *f; 161361ae650dSJack F Vogel int mcnt = 0; 161461ae650dSJack F Vogel bool match = FALSE; 161561ae650dSJack F Vogel 161661ae650dSJack F Vogel IOCTL_DEBUGOUT("ixl_del_multi: begin"); 161761ae650dSJack F Vogel 161861ae650dSJack F Vogel /* Search for removed multicast addresses */ 161961ae650dSJack F Vogel if_maddr_rlock(ifp); 162061ae650dSJack F Vogel SLIST_FOREACH(f, &vsi->ftl, next) { 162161ae650dSJack F Vogel if ((f->flags & IXL_FILTER_USED) && (f->flags & IXL_FILTER_MC)) { 162261ae650dSJack F Vogel match = FALSE; 162361ae650dSJack F Vogel TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 162461ae650dSJack F Vogel if (ifma->ifma_addr->sa_family != AF_LINK) 162561ae650dSJack F Vogel continue; 162661ae650dSJack F Vogel u8 *mc_addr = (u8 *)LLADDR((struct sockaddr_dl *)ifma->ifma_addr); 162761ae650dSJack F Vogel if (cmp_etheraddr(f->macaddr, mc_addr)) { 162861ae650dSJack F Vogel match = TRUE; 162961ae650dSJack F Vogel break; 163061ae650dSJack F Vogel } 163161ae650dSJack F Vogel } 163261ae650dSJack F Vogel if (match == FALSE) { 163361ae650dSJack F Vogel f->flags |= IXL_FILTER_DEL; 163461ae650dSJack F Vogel mcnt++; 163561ae650dSJack F Vogel } 163661ae650dSJack F Vogel } 163761ae650dSJack F Vogel } 163861ae650dSJack F Vogel if_maddr_runlock(ifp); 163961ae650dSJack F Vogel 164061ae650dSJack F Vogel if (mcnt > 0) 164161ae650dSJack F Vogel ixl_del_hw_filters(vsi, mcnt); 164261ae650dSJack F Vogel } 164361ae650dSJack F Vogel 164461ae650dSJack F Vogel 164561ae650dSJack F Vogel /********************************************************************* 164661ae650dSJack F Vogel * Timer routine 164761ae650dSJack F Vogel * 164861ae650dSJack F Vogel * This routine checks for link status,updates statistics, 164961ae650dSJack F Vogel * and runs the watchdog check. 165061ae650dSJack F Vogel * 165161ae650dSJack F Vogel **********************************************************************/ 165261ae650dSJack F Vogel 165361ae650dSJack F Vogel static void 165461ae650dSJack F Vogel ixl_local_timer(void *arg) 165561ae650dSJack F Vogel { 165661ae650dSJack F Vogel struct ixl_pf *pf = arg; 165761ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 165861ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 165961ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 166061ae650dSJack F Vogel device_t dev = pf->dev; 166161ae650dSJack F Vogel int hung = 0; 166261ae650dSJack F Vogel u32 mask; 166361ae650dSJack F Vogel 166461ae650dSJack F Vogel mtx_assert(&pf->pf_mtx, MA_OWNED); 166561ae650dSJack F Vogel 166661ae650dSJack F Vogel /* Fire off the adminq task */ 166761ae650dSJack F Vogel taskqueue_enqueue(pf->tq, &pf->adminq); 166861ae650dSJack F Vogel 166961ae650dSJack F Vogel /* Update stats */ 167061ae650dSJack F Vogel ixl_update_stats_counters(pf); 167161ae650dSJack F Vogel 167261ae650dSJack F Vogel /* 167361ae650dSJack F Vogel ** Check status of the queues 167461ae650dSJack F Vogel */ 167561ae650dSJack F Vogel mask = (I40E_PFINT_DYN_CTLN_INTENA_MASK | 167661ae650dSJack F Vogel I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK); 167761ae650dSJack F Vogel 167861ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++,que++) { 167961ae650dSJack F Vogel /* Any queues with outstanding work get a sw irq */ 168061ae650dSJack F Vogel if (que->busy) 168161ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTLN(que->me), mask); 168261ae650dSJack F Vogel /* 168361ae650dSJack F Vogel ** Each time txeof runs without cleaning, but there 168461ae650dSJack F Vogel ** are uncleaned descriptors it increments busy. If 168561ae650dSJack F Vogel ** we get to 5 we declare it hung. 168661ae650dSJack F Vogel */ 168761ae650dSJack F Vogel if (que->busy == IXL_QUEUE_HUNG) { 168861ae650dSJack F Vogel ++hung; 168961ae650dSJack F Vogel /* Mark the queue as inactive */ 169061ae650dSJack F Vogel vsi->active_queues &= ~((u64)1 << que->me); 169161ae650dSJack F Vogel continue; 169261ae650dSJack F Vogel } else { 169361ae650dSJack F Vogel /* Check if we've come back from hung */ 169461ae650dSJack F Vogel if ((vsi->active_queues & ((u64)1 << que->me)) == 0) 169561ae650dSJack F Vogel vsi->active_queues |= ((u64)1 << que->me); 169661ae650dSJack F Vogel } 169761ae650dSJack F Vogel if (que->busy >= IXL_MAX_TX_BUSY) { 169861ae650dSJack F Vogel device_printf(dev,"Warning queue %d " 169961ae650dSJack F Vogel "appears to be hung!\n", i); 170061ae650dSJack F Vogel que->busy = IXL_QUEUE_HUNG; 170161ae650dSJack F Vogel ++hung; 170261ae650dSJack F Vogel } 170361ae650dSJack F Vogel } 170461ae650dSJack F Vogel /* Only reinit if all queues show hung */ 170561ae650dSJack F Vogel if (hung == vsi->num_queues) 170661ae650dSJack F Vogel goto hung; 170761ae650dSJack F Vogel 170861ae650dSJack F Vogel callout_reset(&pf->timer, hz, ixl_local_timer, pf); 170961ae650dSJack F Vogel return; 171061ae650dSJack F Vogel 171161ae650dSJack F Vogel hung: 171261ae650dSJack F Vogel device_printf(dev, "Local Timer: HANG DETECT - Resetting!!\n"); 171361ae650dSJack F Vogel ixl_init_locked(pf); 171461ae650dSJack F Vogel } 171561ae650dSJack F Vogel 171661ae650dSJack F Vogel /* 171761ae650dSJack F Vogel ** Note: this routine updates the OS on the link state 171861ae650dSJack F Vogel ** the real check of the hardware only happens with 171961ae650dSJack F Vogel ** a link interrupt. 172061ae650dSJack F Vogel */ 172161ae650dSJack F Vogel static void 172261ae650dSJack F Vogel ixl_update_link_status(struct ixl_pf *pf) 172361ae650dSJack F Vogel { 172461ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 172561ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 172661ae650dSJack F Vogel struct ifnet *ifp = vsi->ifp; 172761ae650dSJack F Vogel device_t dev = pf->dev; 172861ae650dSJack F Vogel enum i40e_fc_mode fc; 172961ae650dSJack F Vogel 173061ae650dSJack F Vogel 173161ae650dSJack F Vogel if (vsi->link_up){ 173261ae650dSJack F Vogel if (vsi->link_active == FALSE) { 173361ae650dSJack F Vogel i40e_aq_get_link_info(hw, TRUE, NULL, NULL); 173461ae650dSJack F Vogel if (bootverbose) { 173561ae650dSJack F Vogel fc = hw->fc.current_mode; 173661ae650dSJack F Vogel device_printf(dev,"Link is up %d Gbps %s," 173761ae650dSJack F Vogel " Flow Control: %s\n", 173861ae650dSJack F Vogel ((vsi->link_speed == I40E_LINK_SPEED_40GB)? 40:10), 173961ae650dSJack F Vogel "Full Duplex", ixl_fc_string[fc]); 174061ae650dSJack F Vogel } 174161ae650dSJack F Vogel vsi->link_active = TRUE; 174261ae650dSJack F Vogel if_link_state_change(ifp, LINK_STATE_UP); 174361ae650dSJack F Vogel } 174461ae650dSJack F Vogel } else { /* Link down */ 174561ae650dSJack F Vogel if (vsi->link_active == TRUE) { 174661ae650dSJack F Vogel if (bootverbose) 174761ae650dSJack F Vogel device_printf(dev,"Link is Down\n"); 174861ae650dSJack F Vogel if_link_state_change(ifp, LINK_STATE_DOWN); 174961ae650dSJack F Vogel vsi->link_active = FALSE; 175061ae650dSJack F Vogel } 175161ae650dSJack F Vogel } 175261ae650dSJack F Vogel 175361ae650dSJack F Vogel return; 175461ae650dSJack F Vogel } 175561ae650dSJack F Vogel 175661ae650dSJack F Vogel /********************************************************************* 175761ae650dSJack F Vogel * 175861ae650dSJack F Vogel * This routine disables all traffic on the adapter by issuing a 175961ae650dSJack F Vogel * global reset on the MAC and deallocates TX/RX buffers. 176061ae650dSJack F Vogel * 176161ae650dSJack F Vogel **********************************************************************/ 176261ae650dSJack F Vogel 176361ae650dSJack F Vogel static void 176461ae650dSJack F Vogel ixl_stop(struct ixl_pf *pf) 176561ae650dSJack F Vogel { 176661ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 176761ae650dSJack F Vogel struct ifnet *ifp = vsi->ifp; 176861ae650dSJack F Vogel 176961ae650dSJack F Vogel mtx_assert(&pf->pf_mtx, MA_OWNED); 177061ae650dSJack F Vogel 177161ae650dSJack F Vogel INIT_DEBUGOUT("ixl_stop: begin\n"); 177261ae650dSJack F Vogel ixl_disable_intr(vsi); 177361ae650dSJack F Vogel ixl_disable_rings(vsi); 177461ae650dSJack F Vogel 177561ae650dSJack F Vogel /* Tell the stack that the interface is no longer active */ 177661ae650dSJack F Vogel ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); 177761ae650dSJack F Vogel 177861ae650dSJack F Vogel /* Stop the local timer */ 177961ae650dSJack F Vogel callout_stop(&pf->timer); 178061ae650dSJack F Vogel 178161ae650dSJack F Vogel return; 178261ae650dSJack F Vogel } 178361ae650dSJack F Vogel 178461ae650dSJack F Vogel 178561ae650dSJack F Vogel /********************************************************************* 178661ae650dSJack F Vogel * 178761ae650dSJack F Vogel * Setup MSIX Interrupt resources and handlers for the VSI 178861ae650dSJack F Vogel * 178961ae650dSJack F Vogel **********************************************************************/ 179061ae650dSJack F Vogel static int 179161ae650dSJack F Vogel ixl_assign_vsi_legacy(struct ixl_pf *pf) 179261ae650dSJack F Vogel { 179361ae650dSJack F Vogel device_t dev = pf->dev; 179461ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 179561ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 179661ae650dSJack F Vogel int error, rid = 0; 179761ae650dSJack F Vogel 179861ae650dSJack F Vogel if (pf->msix == 1) 179961ae650dSJack F Vogel rid = 1; 180061ae650dSJack F Vogel pf->res = bus_alloc_resource_any(dev, SYS_RES_IRQ, 180161ae650dSJack F Vogel &rid, RF_SHAREABLE | RF_ACTIVE); 180261ae650dSJack F Vogel if (pf->res == NULL) { 180361ae650dSJack F Vogel device_printf(dev,"Unable to allocate" 180461ae650dSJack F Vogel " bus resource: vsi legacy/msi interrupt\n"); 180561ae650dSJack F Vogel return (ENXIO); 180661ae650dSJack F Vogel } 180761ae650dSJack F Vogel 180861ae650dSJack F Vogel /* Set the handler function */ 180961ae650dSJack F Vogel error = bus_setup_intr(dev, pf->res, 181061ae650dSJack F Vogel INTR_TYPE_NET | INTR_MPSAFE, NULL, 181161ae650dSJack F Vogel ixl_intr, pf, &pf->tag); 181261ae650dSJack F Vogel if (error) { 181361ae650dSJack F Vogel pf->res = NULL; 181461ae650dSJack F Vogel device_printf(dev, "Failed to register legacy/msi handler"); 181561ae650dSJack F Vogel return (error); 181661ae650dSJack F Vogel } 181761ae650dSJack F Vogel bus_describe_intr(dev, pf->res, pf->tag, "irq0"); 181861ae650dSJack F Vogel TASK_INIT(&que->tx_task, 0, ixl_deferred_mq_start, que); 181961ae650dSJack F Vogel TASK_INIT(&que->task, 0, ixl_handle_que, que); 182061ae650dSJack F Vogel que->tq = taskqueue_create_fast("ixl_que", M_NOWAIT, 182161ae650dSJack F Vogel taskqueue_thread_enqueue, &que->tq); 182261ae650dSJack F Vogel taskqueue_start_threads(&que->tq, 1, PI_NET, "%s que", 182361ae650dSJack F Vogel device_get_nameunit(dev)); 182461ae650dSJack F Vogel TASK_INIT(&pf->adminq, 0, ixl_do_adminq, pf); 182561ae650dSJack F Vogel pf->tq = taskqueue_create_fast("ixl_adm", M_NOWAIT, 182661ae650dSJack F Vogel taskqueue_thread_enqueue, &pf->tq); 182761ae650dSJack F Vogel taskqueue_start_threads(&pf->tq, 1, PI_NET, "%s adminq", 182861ae650dSJack F Vogel device_get_nameunit(dev)); 182961ae650dSJack F Vogel 183061ae650dSJack F Vogel return (0); 183161ae650dSJack F Vogel } 183261ae650dSJack F Vogel 183361ae650dSJack F Vogel 183461ae650dSJack F Vogel /********************************************************************* 183561ae650dSJack F Vogel * 183661ae650dSJack F Vogel * Setup MSIX Interrupt resources and handlers for the VSI 183761ae650dSJack F Vogel * 183861ae650dSJack F Vogel **********************************************************************/ 183961ae650dSJack F Vogel static int 184061ae650dSJack F Vogel ixl_assign_vsi_msix(struct ixl_pf *pf) 184161ae650dSJack F Vogel { 184261ae650dSJack F Vogel device_t dev = pf->dev; 184361ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 184461ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 184561ae650dSJack F Vogel struct tx_ring *txr; 184661ae650dSJack F Vogel int error, rid, vector = 0; 184761ae650dSJack F Vogel 184861ae650dSJack F Vogel /* Admin Que is vector 0*/ 184961ae650dSJack F Vogel rid = vector + 1; 185061ae650dSJack F Vogel pf->res = bus_alloc_resource_any(dev, 185161ae650dSJack F Vogel SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE); 185261ae650dSJack F Vogel if (!pf->res) { 185361ae650dSJack F Vogel device_printf(dev,"Unable to allocate" 185461ae650dSJack F Vogel " bus resource: Adminq interrupt [%d]\n", rid); 185561ae650dSJack F Vogel return (ENXIO); 185661ae650dSJack F Vogel } 185761ae650dSJack F Vogel /* Set the adminq vector and handler */ 185861ae650dSJack F Vogel error = bus_setup_intr(dev, pf->res, 185961ae650dSJack F Vogel INTR_TYPE_NET | INTR_MPSAFE, NULL, 186061ae650dSJack F Vogel ixl_msix_adminq, pf, &pf->tag); 186161ae650dSJack F Vogel if (error) { 186261ae650dSJack F Vogel pf->res = NULL; 186361ae650dSJack F Vogel device_printf(dev, "Failed to register Admin que handler"); 186461ae650dSJack F Vogel return (error); 186561ae650dSJack F Vogel } 186661ae650dSJack F Vogel bus_describe_intr(dev, pf->res, pf->tag, "aq"); 186761ae650dSJack F Vogel pf->admvec = vector; 186861ae650dSJack F Vogel /* Tasklet for Admin Queue */ 186961ae650dSJack F Vogel TASK_INIT(&pf->adminq, 0, ixl_do_adminq, pf); 187061ae650dSJack F Vogel pf->tq = taskqueue_create_fast("ixl_adm", M_NOWAIT, 187161ae650dSJack F Vogel taskqueue_thread_enqueue, &pf->tq); 187261ae650dSJack F Vogel taskqueue_start_threads(&pf->tq, 1, PI_NET, "%s adminq", 187361ae650dSJack F Vogel device_get_nameunit(pf->dev)); 187461ae650dSJack F Vogel ++vector; 187561ae650dSJack F Vogel 187661ae650dSJack F Vogel /* Now set up the stations */ 187761ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, vector++, que++) { 187861ae650dSJack F Vogel rid = vector + 1; 187961ae650dSJack F Vogel txr = &que->txr; 188061ae650dSJack F Vogel que->res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, 188161ae650dSJack F Vogel RF_SHAREABLE | RF_ACTIVE); 188261ae650dSJack F Vogel if (que->res == NULL) { 188361ae650dSJack F Vogel device_printf(dev,"Unable to allocate" 188461ae650dSJack F Vogel " bus resource: que interrupt [%d]\n", vector); 188561ae650dSJack F Vogel return (ENXIO); 188661ae650dSJack F Vogel } 188761ae650dSJack F Vogel /* Set the handler function */ 188861ae650dSJack F Vogel error = bus_setup_intr(dev, que->res, 188961ae650dSJack F Vogel INTR_TYPE_NET | INTR_MPSAFE, NULL, 189061ae650dSJack F Vogel ixl_msix_que, que, &que->tag); 189161ae650dSJack F Vogel if (error) { 189261ae650dSJack F Vogel que->res = NULL; 189361ae650dSJack F Vogel device_printf(dev, "Failed to register que handler"); 189461ae650dSJack F Vogel return (error); 189561ae650dSJack F Vogel } 189661ae650dSJack F Vogel bus_describe_intr(dev, que->res, que->tag, "q%d", i); 189761ae650dSJack F Vogel /* Bind the vector to a CPU */ 189861ae650dSJack F Vogel bus_bind_intr(dev, que->res, i); 189961ae650dSJack F Vogel que->msix = vector; 190061ae650dSJack F Vogel TASK_INIT(&que->tx_task, 0, ixl_deferred_mq_start, que); 190161ae650dSJack F Vogel TASK_INIT(&que->task, 0, ixl_handle_que, que); 190261ae650dSJack F Vogel que->tq = taskqueue_create_fast("ixl_que", M_NOWAIT, 190361ae650dSJack F Vogel taskqueue_thread_enqueue, &que->tq); 190461ae650dSJack F Vogel taskqueue_start_threads(&que->tq, 1, PI_NET, "%s que", 190561ae650dSJack F Vogel device_get_nameunit(pf->dev)); 190661ae650dSJack F Vogel } 190761ae650dSJack F Vogel 190861ae650dSJack F Vogel return (0); 190961ae650dSJack F Vogel } 191061ae650dSJack F Vogel 191161ae650dSJack F Vogel 191261ae650dSJack F Vogel /* 191361ae650dSJack F Vogel * Allocate MSI/X vectors 191461ae650dSJack F Vogel */ 191561ae650dSJack F Vogel static int 191661ae650dSJack F Vogel ixl_init_msix(struct ixl_pf *pf) 191761ae650dSJack F Vogel { 191861ae650dSJack F Vogel device_t dev = pf->dev; 191961ae650dSJack F Vogel int rid, want, vectors, queues, available; 192061ae650dSJack F Vogel 192161ae650dSJack F Vogel /* Override by tuneable */ 192261ae650dSJack F Vogel if (ixl_enable_msix == 0) 192361ae650dSJack F Vogel goto msi; 192461ae650dSJack F Vogel 192561ae650dSJack F Vogel /* 192661ae650dSJack F Vogel ** When used in a virtualized environment 192761ae650dSJack F Vogel ** PCI BUSMASTER capability may not be set 192861ae650dSJack F Vogel ** so explicity set it here and rewrite 192961ae650dSJack F Vogel ** the ENABLE in the MSIX control register 193061ae650dSJack F Vogel ** at this point to cause the host to 193161ae650dSJack F Vogel ** successfully initialize us. 193261ae650dSJack F Vogel */ 193361ae650dSJack F Vogel { 193461ae650dSJack F Vogel u16 pci_cmd_word; 193561ae650dSJack F Vogel int msix_ctrl; 193661ae650dSJack F Vogel pci_cmd_word = pci_read_config(dev, PCIR_COMMAND, 2); 193761ae650dSJack F Vogel pci_cmd_word |= PCIM_CMD_BUSMASTEREN; 193861ae650dSJack F Vogel pci_write_config(dev, PCIR_COMMAND, pci_cmd_word, 2); 193961ae650dSJack F Vogel pci_find_cap(dev, PCIY_MSIX, &rid); 194061ae650dSJack F Vogel rid += PCIR_MSIX_CTRL; 194161ae650dSJack F Vogel msix_ctrl = pci_read_config(dev, rid, 2); 194261ae650dSJack F Vogel msix_ctrl |= PCIM_MSIXCTRL_MSIX_ENABLE; 194361ae650dSJack F Vogel pci_write_config(dev, rid, msix_ctrl, 2); 194461ae650dSJack F Vogel } 194561ae650dSJack F Vogel 194661ae650dSJack F Vogel /* First try MSI/X */ 194761ae650dSJack F Vogel rid = PCIR_BAR(IXL_BAR); 194861ae650dSJack F Vogel pf->msix_mem = bus_alloc_resource_any(dev, 194961ae650dSJack F Vogel SYS_RES_MEMORY, &rid, RF_ACTIVE); 195061ae650dSJack F Vogel if (!pf->msix_mem) { 195161ae650dSJack F Vogel /* May not be enabled */ 195261ae650dSJack F Vogel device_printf(pf->dev, 195361ae650dSJack F Vogel "Unable to map MSIX table \n"); 195461ae650dSJack F Vogel goto msi; 195561ae650dSJack F Vogel } 195661ae650dSJack F Vogel 195761ae650dSJack F Vogel available = pci_msix_count(dev); 195861ae650dSJack F Vogel if (available == 0) { /* system has msix disabled */ 195961ae650dSJack F Vogel bus_release_resource(dev, SYS_RES_MEMORY, 196061ae650dSJack F Vogel rid, pf->msix_mem); 196161ae650dSJack F Vogel pf->msix_mem = NULL; 196261ae650dSJack F Vogel goto msi; 196361ae650dSJack F Vogel } 196461ae650dSJack F Vogel 196561ae650dSJack F Vogel /* Figure out a reasonable auto config value */ 196661ae650dSJack F Vogel queues = (mp_ncpus > (available - 1)) ? (available - 1) : mp_ncpus; 196761ae650dSJack F Vogel 196861ae650dSJack F Vogel /* Override with hardcoded value if sane */ 196961ae650dSJack F Vogel if ((ixl_max_queues != 0) && (ixl_max_queues <= queues)) 197061ae650dSJack F Vogel queues = ixl_max_queues; 197161ae650dSJack F Vogel 197261ae650dSJack F Vogel /* 197361ae650dSJack F Vogel ** Want one vector (RX/TX pair) per queue 197461ae650dSJack F Vogel ** plus an additional for the admin queue. 197561ae650dSJack F Vogel */ 197661ae650dSJack F Vogel want = queues + 1; 197761ae650dSJack F Vogel if (want <= available) /* Have enough */ 197861ae650dSJack F Vogel vectors = want; 197961ae650dSJack F Vogel else { 198061ae650dSJack F Vogel device_printf(pf->dev, 198161ae650dSJack F Vogel "MSIX Configuration Problem, " 198261ae650dSJack F Vogel "%d vectors available but %d wanted!\n", 198361ae650dSJack F Vogel available, want); 198461ae650dSJack F Vogel return (0); /* Will go to Legacy setup */ 198561ae650dSJack F Vogel } 198661ae650dSJack F Vogel 198761ae650dSJack F Vogel if (pci_alloc_msix(dev, &vectors) == 0) { 198861ae650dSJack F Vogel device_printf(pf->dev, 198961ae650dSJack F Vogel "Using MSIX interrupts with %d vectors\n", vectors); 199061ae650dSJack F Vogel pf->msix = vectors; 199161ae650dSJack F Vogel pf->vsi.num_queues = queues; 199261ae650dSJack F Vogel return (vectors); 199361ae650dSJack F Vogel } 199461ae650dSJack F Vogel msi: 199561ae650dSJack F Vogel vectors = pci_msi_count(dev); 199661ae650dSJack F Vogel pf->vsi.num_queues = 1; 199761ae650dSJack F Vogel pf->msix = 1; 199861ae650dSJack F Vogel ixl_max_queues = 1; 199961ae650dSJack F Vogel ixl_enable_msix = 0; 200061ae650dSJack F Vogel if (vectors == 1 && pci_alloc_msi(dev, &vectors) == 0) 200161ae650dSJack F Vogel device_printf(pf->dev,"Using an MSI interrupt\n"); 200261ae650dSJack F Vogel else { 200361ae650dSJack F Vogel pf->msix = 0; 200461ae650dSJack F Vogel device_printf(pf->dev,"Using a Legacy interrupt\n"); 200561ae650dSJack F Vogel } 200661ae650dSJack F Vogel return (vectors); 200761ae650dSJack F Vogel } 200861ae650dSJack F Vogel 200961ae650dSJack F Vogel 201061ae650dSJack F Vogel /* 201161ae650dSJack F Vogel * Plumb MSI/X vectors 201261ae650dSJack F Vogel */ 201361ae650dSJack F Vogel static void 201461ae650dSJack F Vogel ixl_configure_msix(struct ixl_pf *pf) 201561ae650dSJack F Vogel { 201661ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 201761ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 201861ae650dSJack F Vogel u32 reg; 201961ae650dSJack F Vogel u16 vector = 1; 202061ae650dSJack F Vogel 202161ae650dSJack F Vogel /* First set up the adminq - vector 0 */ 202261ae650dSJack F Vogel wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ 202361ae650dSJack F Vogel rd32(hw, I40E_PFINT_ICR0); /* read to clear */ 202461ae650dSJack F Vogel 202561ae650dSJack F Vogel reg = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | 202661ae650dSJack F Vogel I40E_PFINT_ICR0_ENA_GRST_MASK | 202761ae650dSJack F Vogel I40E_PFINT_ICR0_HMC_ERR_MASK | 202861ae650dSJack F Vogel I40E_PFINT_ICR0_ENA_ADMINQ_MASK | 202961ae650dSJack F Vogel I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | 203061ae650dSJack F Vogel I40E_PFINT_ICR0_ENA_VFLR_MASK | 203161ae650dSJack F Vogel I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK; 203261ae650dSJack F Vogel wr32(hw, I40E_PFINT_ICR0_ENA, reg); 203361ae650dSJack F Vogel 203461ae650dSJack F Vogel wr32(hw, I40E_PFINT_LNKLST0, 0x7FF); 203561ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITR0(IXL_RX_ITR), 0x003E); 203661ae650dSJack F Vogel 203761ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTL0, 203861ae650dSJack F Vogel I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | 203961ae650dSJack F Vogel I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); 204061ae650dSJack F Vogel 204161ae650dSJack F Vogel wr32(hw, I40E_PFINT_STAT_CTL0, 0); 204261ae650dSJack F Vogel 204361ae650dSJack F Vogel /* Next configure the queues */ 204461ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, vector++) { 204561ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTLN(i), i); 204661ae650dSJack F Vogel wr32(hw, I40E_PFINT_LNKLSTN(i), i); 204761ae650dSJack F Vogel 204861ae650dSJack F Vogel reg = I40E_QINT_RQCTL_CAUSE_ENA_MASK | 204961ae650dSJack F Vogel (IXL_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | 205061ae650dSJack F Vogel (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | 205161ae650dSJack F Vogel (i << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) | 205261ae650dSJack F Vogel (I40E_QUEUE_TYPE_TX << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); 205361ae650dSJack F Vogel wr32(hw, I40E_QINT_RQCTL(i), reg); 205461ae650dSJack F Vogel 205561ae650dSJack F Vogel reg = I40E_QINT_TQCTL_CAUSE_ENA_MASK | 205661ae650dSJack F Vogel (IXL_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | 205761ae650dSJack F Vogel (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | 205861ae650dSJack F Vogel ((i+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) | 205961ae650dSJack F Vogel (I40E_QUEUE_TYPE_RX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); 206061ae650dSJack F Vogel if (i == (vsi->num_queues - 1)) 206161ae650dSJack F Vogel reg |= (IXL_QUEUE_EOL 206261ae650dSJack F Vogel << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); 206361ae650dSJack F Vogel wr32(hw, I40E_QINT_TQCTL(i), reg); 206461ae650dSJack F Vogel } 206561ae650dSJack F Vogel } 206661ae650dSJack F Vogel 206761ae650dSJack F Vogel /* 206861ae650dSJack F Vogel * Configure for MSI single vector operation 206961ae650dSJack F Vogel */ 207061ae650dSJack F Vogel static void 207161ae650dSJack F Vogel ixl_configure_legacy(struct ixl_pf *pf) 207261ae650dSJack F Vogel { 207361ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 207461ae650dSJack F Vogel u32 reg; 207561ae650dSJack F Vogel 207661ae650dSJack F Vogel 207761ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITR0(0), 0); 207861ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITR0(1), 0); 207961ae650dSJack F Vogel 208061ae650dSJack F Vogel 208161ae650dSJack F Vogel /* Setup "other" causes */ 208261ae650dSJack F Vogel reg = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK 208361ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK 208461ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_GRST_MASK 208561ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK 208661ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_GPIO_MASK 208761ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_LINK_STAT_CHANGE_MASK 208861ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK 208961ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK 209061ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_VFLR_MASK 209161ae650dSJack F Vogel | I40E_PFINT_ICR0_ENA_ADMINQ_MASK 209261ae650dSJack F Vogel ; 209361ae650dSJack F Vogel wr32(hw, I40E_PFINT_ICR0_ENA, reg); 209461ae650dSJack F Vogel 209561ae650dSJack F Vogel /* SW_ITR_IDX = 0, but don't change INTENA */ 209661ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTL0, 209761ae650dSJack F Vogel I40E_PFINT_DYN_CTLN_SW_ITR_INDX_MASK | 209861ae650dSJack F Vogel I40E_PFINT_DYN_CTLN_INTENA_MSK_MASK); 209961ae650dSJack F Vogel /* SW_ITR_IDX = 0, OTHER_ITR_IDX = 0 */ 210061ae650dSJack F Vogel wr32(hw, I40E_PFINT_STAT_CTL0, 0); 210161ae650dSJack F Vogel 210261ae650dSJack F Vogel /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ 210361ae650dSJack F Vogel wr32(hw, I40E_PFINT_LNKLST0, 0); 210461ae650dSJack F Vogel 210561ae650dSJack F Vogel /* Associate the queue pair to the vector and enable the q int */ 210661ae650dSJack F Vogel reg = I40E_QINT_RQCTL_CAUSE_ENA_MASK 210761ae650dSJack F Vogel | (IXL_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) 210861ae650dSJack F Vogel | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); 210961ae650dSJack F Vogel wr32(hw, I40E_QINT_RQCTL(0), reg); 211061ae650dSJack F Vogel 211161ae650dSJack F Vogel reg = I40E_QINT_TQCTL_CAUSE_ENA_MASK 211261ae650dSJack F Vogel | (IXL_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) 211361ae650dSJack F Vogel | (IXL_QUEUE_EOL << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); 211461ae650dSJack F Vogel wr32(hw, I40E_QINT_TQCTL(0), reg); 211561ae650dSJack F Vogel 211661ae650dSJack F Vogel /* Next enable the queue pair */ 211761ae650dSJack F Vogel reg = rd32(hw, I40E_QTX_ENA(0)); 211861ae650dSJack F Vogel reg |= I40E_QTX_ENA_QENA_REQ_MASK; 211961ae650dSJack F Vogel wr32(hw, I40E_QTX_ENA(0), reg); 212061ae650dSJack F Vogel 212161ae650dSJack F Vogel reg = rd32(hw, I40E_QRX_ENA(0)); 212261ae650dSJack F Vogel reg |= I40E_QRX_ENA_QENA_REQ_MASK; 212361ae650dSJack F Vogel wr32(hw, I40E_QRX_ENA(0), reg); 212461ae650dSJack F Vogel } 212561ae650dSJack F Vogel 212661ae650dSJack F Vogel 212761ae650dSJack F Vogel /* 212861ae650dSJack F Vogel * Set the Initial ITR state 212961ae650dSJack F Vogel */ 213061ae650dSJack F Vogel static void 213161ae650dSJack F Vogel ixl_configure_itr(struct ixl_pf *pf) 213261ae650dSJack F Vogel { 213361ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 213461ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 213561ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 213661ae650dSJack F Vogel 213761ae650dSJack F Vogel vsi->rx_itr_setting = ixl_rx_itr; 213861ae650dSJack F Vogel if (ixl_dynamic_rx_itr) 213961ae650dSJack F Vogel vsi->rx_itr_setting |= IXL_ITR_DYNAMIC; 214061ae650dSJack F Vogel vsi->tx_itr_setting = ixl_tx_itr; 214161ae650dSJack F Vogel if (ixl_dynamic_tx_itr) 214261ae650dSJack F Vogel vsi->tx_itr_setting |= IXL_ITR_DYNAMIC; 214361ae650dSJack F Vogel 214461ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, que++) { 214561ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 214661ae650dSJack F Vogel struct rx_ring *rxr = &que->rxr; 214761ae650dSJack F Vogel 214861ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITRN(IXL_RX_ITR, i), 214961ae650dSJack F Vogel vsi->rx_itr_setting); 215061ae650dSJack F Vogel rxr->itr = vsi->rx_itr_setting; 215161ae650dSJack F Vogel rxr->latency = IXL_AVE_LATENCY; 215261ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITRN(IXL_TX_ITR, i), 215361ae650dSJack F Vogel vsi->tx_itr_setting); 215461ae650dSJack F Vogel txr->itr = vsi->tx_itr_setting; 215561ae650dSJack F Vogel txr->latency = IXL_AVE_LATENCY; 215661ae650dSJack F Vogel } 215761ae650dSJack F Vogel } 215861ae650dSJack F Vogel 215961ae650dSJack F Vogel 216061ae650dSJack F Vogel static int 216161ae650dSJack F Vogel ixl_allocate_pci_resources(struct ixl_pf *pf) 216261ae650dSJack F Vogel { 216361ae650dSJack F Vogel int rid; 216461ae650dSJack F Vogel device_t dev = pf->dev; 216561ae650dSJack F Vogel 216661ae650dSJack F Vogel rid = PCIR_BAR(0); 216761ae650dSJack F Vogel pf->pci_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 216861ae650dSJack F Vogel &rid, RF_ACTIVE); 216961ae650dSJack F Vogel 217061ae650dSJack F Vogel if (!(pf->pci_mem)) { 217161ae650dSJack F Vogel device_printf(dev,"Unable to allocate bus resource: memory\n"); 217261ae650dSJack F Vogel return (ENXIO); 217361ae650dSJack F Vogel } 217461ae650dSJack F Vogel 217561ae650dSJack F Vogel pf->osdep.mem_bus_space_tag = 217661ae650dSJack F Vogel rman_get_bustag(pf->pci_mem); 217761ae650dSJack F Vogel pf->osdep.mem_bus_space_handle = 217861ae650dSJack F Vogel rman_get_bushandle(pf->pci_mem); 217961ae650dSJack F Vogel pf->osdep.mem_bus_space_size = rman_get_size(pf->pci_mem); 218061ae650dSJack F Vogel pf->hw.hw_addr = (u8 *) &pf->osdep.mem_bus_space_handle; 218161ae650dSJack F Vogel 218261ae650dSJack F Vogel pf->hw.back = &pf->osdep; 218361ae650dSJack F Vogel 218461ae650dSJack F Vogel /* 218561ae650dSJack F Vogel ** Now setup MSI or MSI/X, should 218661ae650dSJack F Vogel ** return us the number of supported 218761ae650dSJack F Vogel ** vectors. (Will be 1 for MSI) 218861ae650dSJack F Vogel */ 218961ae650dSJack F Vogel pf->msix = ixl_init_msix(pf); 219061ae650dSJack F Vogel return (0); 219161ae650dSJack F Vogel } 219261ae650dSJack F Vogel 219361ae650dSJack F Vogel static void 219461ae650dSJack F Vogel ixl_free_pci_resources(struct ixl_pf * pf) 219561ae650dSJack F Vogel { 219661ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 219761ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 219861ae650dSJack F Vogel device_t dev = pf->dev; 219961ae650dSJack F Vogel int rid, memrid; 220061ae650dSJack F Vogel 220161ae650dSJack F Vogel memrid = PCIR_BAR(IXL_BAR); 220261ae650dSJack F Vogel 220361ae650dSJack F Vogel /* We may get here before stations are setup */ 220461ae650dSJack F Vogel if ((!ixl_enable_msix) || (que == NULL)) 220561ae650dSJack F Vogel goto early; 220661ae650dSJack F Vogel 220761ae650dSJack F Vogel /* 220861ae650dSJack F Vogel ** Release all msix VSI resources: 220961ae650dSJack F Vogel */ 221061ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, que++) { 221161ae650dSJack F Vogel rid = que->msix + 1; 221261ae650dSJack F Vogel if (que->tag != NULL) { 221361ae650dSJack F Vogel bus_teardown_intr(dev, que->res, que->tag); 221461ae650dSJack F Vogel que->tag = NULL; 221561ae650dSJack F Vogel } 221661ae650dSJack F Vogel if (que->res != NULL) 221761ae650dSJack F Vogel bus_release_resource(dev, SYS_RES_IRQ, rid, que->res); 221861ae650dSJack F Vogel } 221961ae650dSJack F Vogel 222061ae650dSJack F Vogel early: 222161ae650dSJack F Vogel /* Clean the AdminQ interrupt last */ 222261ae650dSJack F Vogel if (pf->admvec) /* we are doing MSIX */ 222361ae650dSJack F Vogel rid = pf->admvec + 1; 222461ae650dSJack F Vogel else 222561ae650dSJack F Vogel (pf->msix != 0) ? (rid = 1):(rid = 0); 222661ae650dSJack F Vogel 222761ae650dSJack F Vogel if (pf->tag != NULL) { 222861ae650dSJack F Vogel bus_teardown_intr(dev, pf->res, pf->tag); 222961ae650dSJack F Vogel pf->tag = NULL; 223061ae650dSJack F Vogel } 223161ae650dSJack F Vogel if (pf->res != NULL) 223261ae650dSJack F Vogel bus_release_resource(dev, SYS_RES_IRQ, rid, pf->res); 223361ae650dSJack F Vogel 223461ae650dSJack F Vogel if (pf->msix) 223561ae650dSJack F Vogel pci_release_msi(dev); 223661ae650dSJack F Vogel 223761ae650dSJack F Vogel if (pf->msix_mem != NULL) 223861ae650dSJack F Vogel bus_release_resource(dev, SYS_RES_MEMORY, 223961ae650dSJack F Vogel memrid, pf->msix_mem); 224061ae650dSJack F Vogel 224161ae650dSJack F Vogel if (pf->pci_mem != NULL) 224261ae650dSJack F Vogel bus_release_resource(dev, SYS_RES_MEMORY, 224361ae650dSJack F Vogel PCIR_BAR(0), pf->pci_mem); 224461ae650dSJack F Vogel 224561ae650dSJack F Vogel return; 224661ae650dSJack F Vogel } 224761ae650dSJack F Vogel 224861ae650dSJack F Vogel 224961ae650dSJack F Vogel /********************************************************************* 225061ae650dSJack F Vogel * 225161ae650dSJack F Vogel * Setup networking device structure and register an interface. 225261ae650dSJack F Vogel * 225361ae650dSJack F Vogel **********************************************************************/ 225461ae650dSJack F Vogel static int 225561ae650dSJack F Vogel ixl_setup_interface(device_t dev, struct ixl_vsi *vsi) 225661ae650dSJack F Vogel { 225761ae650dSJack F Vogel struct ifnet *ifp; 225861ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 225961ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 226061ae650dSJack F Vogel struct i40e_aq_get_phy_abilities_resp abilities_resp; 226161ae650dSJack F Vogel enum i40e_status_code aq_error = 0; 226261ae650dSJack F Vogel 226361ae650dSJack F Vogel INIT_DEBUGOUT("ixl_setup_interface: begin"); 226461ae650dSJack F Vogel 226561ae650dSJack F Vogel ifp = vsi->ifp = if_alloc(IFT_ETHER); 226661ae650dSJack F Vogel if (ifp == NULL) { 226761ae650dSJack F Vogel device_printf(dev, "can not allocate ifnet structure\n"); 226861ae650dSJack F Vogel return (-1); 226961ae650dSJack F Vogel } 227061ae650dSJack F Vogel if_initname(ifp, device_get_name(dev), device_get_unit(dev)); 227161ae650dSJack F Vogel ifp->if_mtu = ETHERMTU; 227261ae650dSJack F Vogel ifp->if_baudrate = 4000000000; // ?? 227361ae650dSJack F Vogel ifp->if_init = ixl_init; 227461ae650dSJack F Vogel ifp->if_softc = vsi; 227561ae650dSJack F Vogel ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 227661ae650dSJack F Vogel ifp->if_ioctl = ixl_ioctl; 227761ae650dSJack F Vogel 2278*4b443922SGleb Smirnoff #if __FreeBSD_version >= 1100000 2279*4b443922SGleb Smirnoff if_setgetcounterfn(ifp, ixl_get_counter); 2280*4b443922SGleb Smirnoff #endif 2281*4b443922SGleb Smirnoff 228261ae650dSJack F Vogel ifp->if_transmit = ixl_mq_start; 228361ae650dSJack F Vogel 228461ae650dSJack F Vogel ifp->if_qflush = ixl_qflush; 228561ae650dSJack F Vogel 228661ae650dSJack F Vogel ifp->if_snd.ifq_maxlen = que->num_desc - 2; 228761ae650dSJack F Vogel 228861ae650dSJack F Vogel ether_ifattach(ifp, hw->mac.addr); 228961ae650dSJack F Vogel 229061ae650dSJack F Vogel vsi->max_frame_size = 229161ae650dSJack F Vogel ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN 229261ae650dSJack F Vogel + ETHER_VLAN_ENCAP_LEN; 229361ae650dSJack F Vogel 229461ae650dSJack F Vogel /* 229561ae650dSJack F Vogel * Tell the upper layer(s) we support long frames. 229661ae650dSJack F Vogel */ 22971bffa951SGleb Smirnoff ifp->if_hdrlen = sizeof(struct ether_vlan_header); 229861ae650dSJack F Vogel 229961ae650dSJack F Vogel ifp->if_capabilities |= IFCAP_HWCSUM; 230061ae650dSJack F Vogel ifp->if_capabilities |= IFCAP_HWCSUM_IPV6; 230161ae650dSJack F Vogel ifp->if_capabilities |= IFCAP_TSO; 230261ae650dSJack F Vogel ifp->if_capabilities |= IFCAP_JUMBO_MTU; 230361ae650dSJack F Vogel ifp->if_capabilities |= IFCAP_LRO; 230461ae650dSJack F Vogel 230561ae650dSJack F Vogel /* VLAN capabilties */ 230661ae650dSJack F Vogel ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING 230761ae650dSJack F Vogel | IFCAP_VLAN_HWTSO 230861ae650dSJack F Vogel | IFCAP_VLAN_MTU 230961ae650dSJack F Vogel | IFCAP_VLAN_HWCSUM; 231061ae650dSJack F Vogel ifp->if_capenable = ifp->if_capabilities; 231161ae650dSJack F Vogel 231261ae650dSJack F Vogel /* 231361ae650dSJack F Vogel ** Don't turn this on by default, if vlans are 231461ae650dSJack F Vogel ** created on another pseudo device (eg. lagg) 231561ae650dSJack F Vogel ** then vlan events are not passed thru, breaking 231661ae650dSJack F Vogel ** operation, but with HW FILTER off it works. If 231761ae650dSJack F Vogel ** using vlans directly on the ixl driver you can 231861ae650dSJack F Vogel ** enable this and get full hardware tag filtering. 231961ae650dSJack F Vogel */ 232061ae650dSJack F Vogel ifp->if_capabilities |= IFCAP_VLAN_HWFILTER; 232161ae650dSJack F Vogel 232261ae650dSJack F Vogel /* 232361ae650dSJack F Vogel * Specify the media types supported by this adapter and register 232461ae650dSJack F Vogel * callbacks to update media and link information 232561ae650dSJack F Vogel */ 232661ae650dSJack F Vogel ifmedia_init(&vsi->media, IFM_IMASK, ixl_media_change, 232761ae650dSJack F Vogel ixl_media_status); 232861ae650dSJack F Vogel 232961ae650dSJack F Vogel aq_error = i40e_aq_get_phy_capabilities(hw, FALSE, TRUE, &abilities_resp, NULL); 233061ae650dSJack F Vogel if (aq_error) { 233161ae650dSJack F Vogel printf("Error getting supported media types, AQ error %d\n", aq_error); 233261ae650dSJack F Vogel return (EPERM); 233361ae650dSJack F Vogel } 233461ae650dSJack F Vogel 233561ae650dSJack F Vogel /* Display supported media types */ 233661ae650dSJack F Vogel if (abilities_resp.phy_type & (1 << I40E_PHY_TYPE_100BASE_TX)) 233761ae650dSJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_100_TX, 0, NULL); 233861ae650dSJack F Vogel 233961ae650dSJack F Vogel if (abilities_resp.phy_type & (1 << I40E_PHY_TYPE_1000BASE_T)) 234061ae650dSJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_1000_T, 0, NULL); 234161ae650dSJack F Vogel 234261ae650dSJack F Vogel if (abilities_resp.phy_type & (1 << I40E_PHY_TYPE_10GBASE_CR1_CU) || 234361ae650dSJack F Vogel abilities_resp.phy_type & (1 << I40E_PHY_TYPE_10GBASE_SFPP_CU)) 234461ae650dSJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_10G_TWINAX, 0, NULL); 234561ae650dSJack F Vogel if (abilities_resp.phy_type & (1 << I40E_PHY_TYPE_10GBASE_SR)) 234661ae650dSJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_10G_SR, 0, NULL); 234761ae650dSJack F Vogel if (abilities_resp.phy_type & (1 << I40E_PHY_TYPE_10GBASE_LR)) 234861ae650dSJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_10G_LR, 0, NULL); 234961ae650dSJack F Vogel if (abilities_resp.phy_type & (1 << I40E_PHY_TYPE_10GBASE_T)) 235061ae650dSJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_10G_T, 0, NULL); 235161ae650dSJack F Vogel 235261ae650dSJack F Vogel if (abilities_resp.phy_type & (1 << I40E_PHY_TYPE_40GBASE_CR4_CU) || 235361ae650dSJack F Vogel abilities_resp.phy_type & (1 << I40E_PHY_TYPE_40GBASE_CR4)) 235461ae650dSJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_40G_CR4, 0, NULL); 235561ae650dSJack F Vogel if (abilities_resp.phy_type & (1 << I40E_PHY_TYPE_40GBASE_SR4)) 235661ae650dSJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_40G_SR4, 0, NULL); 235761ae650dSJack F Vogel if (abilities_resp.phy_type & (1 << I40E_PHY_TYPE_40GBASE_LR4)) 235861ae650dSJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_40G_LR4, 0, NULL); 235961ae650dSJack F Vogel 236061ae650dSJack F Vogel /* Use autoselect media by default */ 236161ae650dSJack F Vogel ifmedia_add(&vsi->media, IFM_ETHER | IFM_AUTO, 0, NULL); 236261ae650dSJack F Vogel ifmedia_set(&vsi->media, IFM_ETHER | IFM_AUTO); 236361ae650dSJack F Vogel 236461ae650dSJack F Vogel return (0); 236561ae650dSJack F Vogel } 236661ae650dSJack F Vogel 236761ae650dSJack F Vogel static bool 236861ae650dSJack F Vogel ixl_config_link(struct i40e_hw *hw) 236961ae650dSJack F Vogel { 237061ae650dSJack F Vogel bool check; 237161ae650dSJack F Vogel 237261ae650dSJack F Vogel i40e_aq_get_link_info(hw, TRUE, NULL, NULL); 237361ae650dSJack F Vogel check = i40e_get_link_status(hw); 237461ae650dSJack F Vogel #ifdef IXL_DEBUG 237561ae650dSJack F Vogel printf("Link is %s\n", check ? "up":"down"); 237661ae650dSJack F Vogel #endif 237761ae650dSJack F Vogel return (check); 237861ae650dSJack F Vogel } 237961ae650dSJack F Vogel 238061ae650dSJack F Vogel /********************************************************************* 238161ae650dSJack F Vogel * 238261ae650dSJack F Vogel * Initialize this VSI 238361ae650dSJack F Vogel * 238461ae650dSJack F Vogel **********************************************************************/ 238561ae650dSJack F Vogel static int 238661ae650dSJack F Vogel ixl_setup_vsi(struct ixl_vsi *vsi) 238761ae650dSJack F Vogel { 238861ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 238961ae650dSJack F Vogel device_t dev = vsi->dev; 239061ae650dSJack F Vogel struct i40e_aqc_get_switch_config_resp *sw_config; 239161ae650dSJack F Vogel struct i40e_vsi_context ctxt; 239261ae650dSJack F Vogel u8 aq_buf[I40E_AQ_LARGE_BUF]; 239361ae650dSJack F Vogel int ret = I40E_SUCCESS; 239461ae650dSJack F Vogel u16 next = 0; 239561ae650dSJack F Vogel 239661ae650dSJack F Vogel sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; 239761ae650dSJack F Vogel ret = i40e_aq_get_switch_config(hw, sw_config, 239861ae650dSJack F Vogel sizeof(aq_buf), &next, NULL); 239961ae650dSJack F Vogel if (ret) { 240061ae650dSJack F Vogel device_printf(dev,"aq_get_switch_config failed!!\n"); 240161ae650dSJack F Vogel return (ret); 240261ae650dSJack F Vogel } 240361ae650dSJack F Vogel #ifdef IXL_DEBUG 240461ae650dSJack F Vogel printf("Switch config: header reported: %d in structure, %d total\n", 240561ae650dSJack F Vogel sw_config->header.num_reported, sw_config->header.num_total); 240661ae650dSJack F Vogel printf("type=%d seid=%d uplink=%d downlink=%d\n", 240761ae650dSJack F Vogel sw_config->element[0].element_type, 240861ae650dSJack F Vogel sw_config->element[0].seid, 240961ae650dSJack F Vogel sw_config->element[0].uplink_seid, 241061ae650dSJack F Vogel sw_config->element[0].downlink_seid); 241161ae650dSJack F Vogel #endif 241261ae650dSJack F Vogel /* Save off this important value */ 241361ae650dSJack F Vogel vsi->seid = sw_config->element[0].seid; 241461ae650dSJack F Vogel 241561ae650dSJack F Vogel memset(&ctxt, 0, sizeof(ctxt)); 241661ae650dSJack F Vogel ctxt.seid = vsi->seid; 241761ae650dSJack F Vogel ctxt.pf_num = hw->pf_id; 241861ae650dSJack F Vogel ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL); 241961ae650dSJack F Vogel if (ret) { 242061ae650dSJack F Vogel device_printf(dev,"get vsi params failed %x!!\n", ret); 242161ae650dSJack F Vogel return (ret); 242261ae650dSJack F Vogel } 242361ae650dSJack F Vogel #ifdef IXL_DEBUG 242461ae650dSJack F Vogel printf("get_vsi_params: seid: %d, uplinkseid: %d, vsi_number: %d, " 242561ae650dSJack F Vogel "vsis_allocated: %d, vsis_unallocated: %d, flags: 0x%x, " 242661ae650dSJack F Vogel "pfnum: %d, vfnum: %d, stat idx: %d, enabled: %d\n", ctxt.seid, 242761ae650dSJack F Vogel ctxt.uplink_seid, ctxt.vsi_number, 242861ae650dSJack F Vogel ctxt.vsis_allocated, ctxt.vsis_unallocated, 242961ae650dSJack F Vogel ctxt.flags, ctxt.pf_num, ctxt.vf_num, 243061ae650dSJack F Vogel ctxt.info.stat_counter_idx, ctxt.info.up_enable_bits); 243161ae650dSJack F Vogel #endif 243261ae650dSJack F Vogel /* 243361ae650dSJack F Vogel ** Set the queue and traffic class bits 243461ae650dSJack F Vogel ** - when multiple traffic classes are supported 243561ae650dSJack F Vogel ** this will need to be more robust. 243661ae650dSJack F Vogel */ 243761ae650dSJack F Vogel ctxt.info.valid_sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; 243861ae650dSJack F Vogel ctxt.info.mapping_flags |= I40E_AQ_VSI_QUE_MAP_CONTIG; 243961ae650dSJack F Vogel ctxt.info.queue_mapping[0] = 0; 244061ae650dSJack F Vogel ctxt.info.tc_mapping[0] = 0x0800; 244161ae650dSJack F Vogel 244261ae650dSJack F Vogel /* Set VLAN receive stripping mode */ 244361ae650dSJack F Vogel ctxt.info.valid_sections |= I40E_AQ_VSI_PROP_VLAN_VALID; 244461ae650dSJack F Vogel ctxt.info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL; 244561ae650dSJack F Vogel if (vsi->ifp->if_capenable & IFCAP_VLAN_HWTAGGING) 244661ae650dSJack F Vogel ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; 244761ae650dSJack F Vogel else 244861ae650dSJack F Vogel ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_EMOD_NOTHING; 244961ae650dSJack F Vogel 245061ae650dSJack F Vogel /* Keep copy of VSI info in VSI for statistic counters */ 245161ae650dSJack F Vogel memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info)); 245261ae650dSJack F Vogel 245361ae650dSJack F Vogel /* Reset VSI statistics */ 245461ae650dSJack F Vogel ixl_vsi_reset_stats(vsi); 245561ae650dSJack F Vogel vsi->hw_filters_add = 0; 245661ae650dSJack F Vogel vsi->hw_filters_del = 0; 245761ae650dSJack F Vogel 245861ae650dSJack F Vogel ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); 245961ae650dSJack F Vogel if (ret) 246061ae650dSJack F Vogel device_printf(dev,"update vsi params failed %x!!\n", 246161ae650dSJack F Vogel hw->aq.asq_last_status); 246261ae650dSJack F Vogel return (ret); 246361ae650dSJack F Vogel } 246461ae650dSJack F Vogel 246561ae650dSJack F Vogel 246661ae650dSJack F Vogel /********************************************************************* 246761ae650dSJack F Vogel * 246861ae650dSJack F Vogel * Initialize the VSI: this handles contexts, which means things 246961ae650dSJack F Vogel * like the number of descriptors, buffer size, 247061ae650dSJack F Vogel * plus we init the rings thru this function. 247161ae650dSJack F Vogel * 247261ae650dSJack F Vogel **********************************************************************/ 247361ae650dSJack F Vogel static int 247461ae650dSJack F Vogel ixl_initialize_vsi(struct ixl_vsi *vsi) 247561ae650dSJack F Vogel { 247661ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 247761ae650dSJack F Vogel device_t dev = vsi->dev; 247861ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 247961ae650dSJack F Vogel int err = 0; 248061ae650dSJack F Vogel 248161ae650dSJack F Vogel 248261ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, que++) { 248361ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 248461ae650dSJack F Vogel struct rx_ring *rxr = &que->rxr; 248561ae650dSJack F Vogel struct i40e_hmc_obj_txq tctx; 248661ae650dSJack F Vogel struct i40e_hmc_obj_rxq rctx; 248761ae650dSJack F Vogel u32 txctl; 248861ae650dSJack F Vogel u16 size; 248961ae650dSJack F Vogel 249061ae650dSJack F Vogel 249161ae650dSJack F Vogel /* Setup the HMC TX Context */ 249261ae650dSJack F Vogel size = que->num_desc * sizeof(struct i40e_tx_desc); 249361ae650dSJack F Vogel memset(&tctx, 0, sizeof(struct i40e_hmc_obj_txq)); 249461ae650dSJack F Vogel tctx.new_context = 1; 249561ae650dSJack F Vogel tctx.base = (txr->dma.pa/128); 249661ae650dSJack F Vogel tctx.qlen = que->num_desc; 249761ae650dSJack F Vogel tctx.fc_ena = 0; 249861ae650dSJack F Vogel tctx.rdylist = vsi->info.qs_handle[0]; /* index is TC */ 249961ae650dSJack F Vogel /* Enable HEAD writeback */ 250061ae650dSJack F Vogel tctx.head_wb_ena = 1; 250161ae650dSJack F Vogel tctx.head_wb_addr = txr->dma.pa + 250261ae650dSJack F Vogel (que->num_desc * sizeof(struct i40e_tx_desc)); 250361ae650dSJack F Vogel tctx.rdylist_act = 0; 250461ae650dSJack F Vogel err = i40e_clear_lan_tx_queue_context(hw, i); 250561ae650dSJack F Vogel if (err) { 250661ae650dSJack F Vogel device_printf(dev, "Unable to clear TX context\n"); 250761ae650dSJack F Vogel break; 250861ae650dSJack F Vogel } 250961ae650dSJack F Vogel err = i40e_set_lan_tx_queue_context(hw, i, &tctx); 251061ae650dSJack F Vogel if (err) { 251161ae650dSJack F Vogel device_printf(dev, "Unable to set TX context\n"); 251261ae650dSJack F Vogel break; 251361ae650dSJack F Vogel } 251461ae650dSJack F Vogel /* Associate the ring with this PF */ 251561ae650dSJack F Vogel txctl = I40E_QTX_CTL_PF_QUEUE; 251661ae650dSJack F Vogel txctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & 251761ae650dSJack F Vogel I40E_QTX_CTL_PF_INDX_MASK); 251861ae650dSJack F Vogel wr32(hw, I40E_QTX_CTL(i), txctl); 251961ae650dSJack F Vogel ixl_flush(hw); 252061ae650dSJack F Vogel 252161ae650dSJack F Vogel /* Do ring (re)init */ 252261ae650dSJack F Vogel ixl_init_tx_ring(que); 252361ae650dSJack F Vogel 252461ae650dSJack F Vogel /* Next setup the HMC RX Context */ 252561ae650dSJack F Vogel if (vsi->max_frame_size <= 2048) 252661ae650dSJack F Vogel rxr->mbuf_sz = MCLBYTES; 252761ae650dSJack F Vogel else 252861ae650dSJack F Vogel rxr->mbuf_sz = MJUMPAGESIZE; 252961ae650dSJack F Vogel 253061ae650dSJack F Vogel u16 max_rxmax = rxr->mbuf_sz * hw->func_caps.rx_buf_chain_len; 253161ae650dSJack F Vogel 253261ae650dSJack F Vogel /* Set up an RX context for the HMC */ 253361ae650dSJack F Vogel memset(&rctx, 0, sizeof(struct i40e_hmc_obj_rxq)); 253461ae650dSJack F Vogel rctx.dbuff = rxr->mbuf_sz >> I40E_RXQ_CTX_DBUFF_SHIFT; 253561ae650dSJack F Vogel /* ignore header split for now */ 253661ae650dSJack F Vogel rctx.hbuff = 0 >> I40E_RXQ_CTX_HBUFF_SHIFT; 253761ae650dSJack F Vogel rctx.rxmax = (vsi->max_frame_size < max_rxmax) ? 253861ae650dSJack F Vogel vsi->max_frame_size : max_rxmax; 253961ae650dSJack F Vogel rctx.dtype = 0; 254061ae650dSJack F Vogel rctx.dsize = 1; /* do 32byte descriptors */ 254161ae650dSJack F Vogel rctx.hsplit_0 = 0; /* no HDR split initially */ 254261ae650dSJack F Vogel rctx.base = (rxr->dma.pa/128); 254361ae650dSJack F Vogel rctx.qlen = que->num_desc; 254461ae650dSJack F Vogel rctx.tphrdesc_ena = 1; 254561ae650dSJack F Vogel rctx.tphwdesc_ena = 1; 254661ae650dSJack F Vogel rctx.tphdata_ena = 0; 254761ae650dSJack F Vogel rctx.tphhead_ena = 0; 254861ae650dSJack F Vogel rctx.lrxqthresh = 2; 254961ae650dSJack F Vogel rctx.crcstrip = 1; 255061ae650dSJack F Vogel rctx.l2tsel = 1; 255161ae650dSJack F Vogel rctx.showiv = 1; 255261ae650dSJack F Vogel rctx.fc_ena = 0; 255361ae650dSJack F Vogel rctx.prefena = 1; 255461ae650dSJack F Vogel 255561ae650dSJack F Vogel err = i40e_clear_lan_rx_queue_context(hw, i); 255661ae650dSJack F Vogel if (err) { 255761ae650dSJack F Vogel device_printf(dev, 255861ae650dSJack F Vogel "Unable to clear RX context %d\n", i); 255961ae650dSJack F Vogel break; 256061ae650dSJack F Vogel } 256161ae650dSJack F Vogel err = i40e_set_lan_rx_queue_context(hw, i, &rctx); 256261ae650dSJack F Vogel if (err) { 256361ae650dSJack F Vogel device_printf(dev, "Unable to set RX context %d\n", i); 256461ae650dSJack F Vogel break; 256561ae650dSJack F Vogel } 256661ae650dSJack F Vogel err = ixl_init_rx_ring(que); 256761ae650dSJack F Vogel if (err) { 256861ae650dSJack F Vogel device_printf(dev, "Fail in init_rx_ring %d\n", i); 256961ae650dSJack F Vogel break; 257061ae650dSJack F Vogel } 257161ae650dSJack F Vogel wr32(vsi->hw, I40E_QRX_TAIL(que->me), 0); 257261ae650dSJack F Vogel wr32(vsi->hw, I40E_QRX_TAIL(que->me), que->num_desc - 1); 257361ae650dSJack F Vogel } 257461ae650dSJack F Vogel return (err); 257561ae650dSJack F Vogel } 257661ae650dSJack F Vogel 257761ae650dSJack F Vogel 257861ae650dSJack F Vogel /********************************************************************* 257961ae650dSJack F Vogel * 258061ae650dSJack F Vogel * Free all VSI structs. 258161ae650dSJack F Vogel * 258261ae650dSJack F Vogel **********************************************************************/ 258361ae650dSJack F Vogel void 258461ae650dSJack F Vogel ixl_free_vsi(struct ixl_vsi *vsi) 258561ae650dSJack F Vogel { 258661ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)vsi->back; 258761ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 258861ae650dSJack F Vogel struct ixl_mac_filter *f; 258961ae650dSJack F Vogel 259061ae650dSJack F Vogel /* Free station queues */ 259161ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, que++) { 259261ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 259361ae650dSJack F Vogel struct rx_ring *rxr = &que->rxr; 259461ae650dSJack F Vogel 259561ae650dSJack F Vogel if (!mtx_initialized(&txr->mtx)) /* uninitialized */ 259661ae650dSJack F Vogel continue; 259761ae650dSJack F Vogel IXL_TX_LOCK(txr); 259861ae650dSJack F Vogel ixl_free_que_tx(que); 259961ae650dSJack F Vogel if (txr->base) 2600d94ca7cfSBjoern A. Zeeb i40e_free_dma_mem(&pf->hw, &txr->dma); 260161ae650dSJack F Vogel IXL_TX_UNLOCK(txr); 260261ae650dSJack F Vogel IXL_TX_LOCK_DESTROY(txr); 260361ae650dSJack F Vogel 260461ae650dSJack F Vogel if (!mtx_initialized(&rxr->mtx)) /* uninitialized */ 260561ae650dSJack F Vogel continue; 260661ae650dSJack F Vogel IXL_RX_LOCK(rxr); 260761ae650dSJack F Vogel ixl_free_que_rx(que); 260861ae650dSJack F Vogel if (rxr->base) 2609d94ca7cfSBjoern A. Zeeb i40e_free_dma_mem(&pf->hw, &rxr->dma); 261061ae650dSJack F Vogel IXL_RX_UNLOCK(rxr); 261161ae650dSJack F Vogel IXL_RX_LOCK_DESTROY(rxr); 261261ae650dSJack F Vogel 261361ae650dSJack F Vogel } 261461ae650dSJack F Vogel free(vsi->queues, M_DEVBUF); 261561ae650dSJack F Vogel 261661ae650dSJack F Vogel /* Free VSI filter list */ 261761ae650dSJack F Vogel while (!SLIST_EMPTY(&vsi->ftl)) { 261861ae650dSJack F Vogel f = SLIST_FIRST(&vsi->ftl); 261961ae650dSJack F Vogel SLIST_REMOVE_HEAD(&vsi->ftl, next); 262061ae650dSJack F Vogel free(f, M_DEVBUF); 262161ae650dSJack F Vogel } 262261ae650dSJack F Vogel } 262361ae650dSJack F Vogel 262461ae650dSJack F Vogel 262561ae650dSJack F Vogel /********************************************************************* 262661ae650dSJack F Vogel * 262761ae650dSJack F Vogel * Allocate memory for the VSI (virtual station interface) and their 262861ae650dSJack F Vogel * associated queues, rings and the descriptors associated with each, 262961ae650dSJack F Vogel * called only once at attach. 263061ae650dSJack F Vogel * 263161ae650dSJack F Vogel **********************************************************************/ 263261ae650dSJack F Vogel static int 263361ae650dSJack F Vogel ixl_setup_stations(struct ixl_pf *pf) 263461ae650dSJack F Vogel { 263561ae650dSJack F Vogel device_t dev = pf->dev; 263661ae650dSJack F Vogel struct ixl_vsi *vsi; 263761ae650dSJack F Vogel struct ixl_queue *que; 263861ae650dSJack F Vogel struct tx_ring *txr; 263961ae650dSJack F Vogel struct rx_ring *rxr; 264061ae650dSJack F Vogel int rsize, tsize; 264161ae650dSJack F Vogel int error = I40E_SUCCESS; 264261ae650dSJack F Vogel 264361ae650dSJack F Vogel vsi = &pf->vsi; 264461ae650dSJack F Vogel vsi->back = (void *)pf; 264561ae650dSJack F Vogel vsi->hw = &pf->hw; 264661ae650dSJack F Vogel vsi->id = 0; 264761ae650dSJack F Vogel vsi->num_vlans = 0; 264861ae650dSJack F Vogel 264961ae650dSJack F Vogel /* Get memory for the station queues */ 265061ae650dSJack F Vogel if (!(vsi->queues = 265161ae650dSJack F Vogel (struct ixl_queue *) malloc(sizeof(struct ixl_queue) * 265261ae650dSJack F Vogel vsi->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) { 265361ae650dSJack F Vogel device_printf(dev, "Unable to allocate queue memory\n"); 265461ae650dSJack F Vogel error = ENOMEM; 265561ae650dSJack F Vogel goto early; 265661ae650dSJack F Vogel } 265761ae650dSJack F Vogel 265861ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++) { 265961ae650dSJack F Vogel que = &vsi->queues[i]; 266061ae650dSJack F Vogel que->num_desc = ixl_ringsz; 266161ae650dSJack F Vogel que->me = i; 266261ae650dSJack F Vogel que->vsi = vsi; 266361ae650dSJack F Vogel /* mark the queue as active */ 266461ae650dSJack F Vogel vsi->active_queues |= (u64)1 << que->me; 266561ae650dSJack F Vogel txr = &que->txr; 266661ae650dSJack F Vogel txr->que = que; 266761ae650dSJack F Vogel txr->tail = I40E_QTX_TAIL(que->me); 266861ae650dSJack F Vogel 266961ae650dSJack F Vogel /* Initialize the TX lock */ 267061ae650dSJack F Vogel snprintf(txr->mtx_name, sizeof(txr->mtx_name), "%s:tx(%d)", 267161ae650dSJack F Vogel device_get_nameunit(dev), que->me); 267261ae650dSJack F Vogel mtx_init(&txr->mtx, txr->mtx_name, NULL, MTX_DEF); 267361ae650dSJack F Vogel /* Create the TX descriptor ring */ 267461ae650dSJack F Vogel tsize = roundup2((que->num_desc * 267561ae650dSJack F Vogel sizeof(struct i40e_tx_desc)) + 267661ae650dSJack F Vogel sizeof(u32), DBA_ALIGN); 2677d94ca7cfSBjoern A. Zeeb if (i40e_allocate_dma_mem(&pf->hw, 2678d94ca7cfSBjoern A. Zeeb &txr->dma, i40e_mem_reserved, tsize, DBA_ALIGN)) { 267961ae650dSJack F Vogel device_printf(dev, 268061ae650dSJack F Vogel "Unable to allocate TX Descriptor memory\n"); 268161ae650dSJack F Vogel error = ENOMEM; 268261ae650dSJack F Vogel goto fail; 268361ae650dSJack F Vogel } 268461ae650dSJack F Vogel txr->base = (struct i40e_tx_desc *)txr->dma.va; 268561ae650dSJack F Vogel bzero((void *)txr->base, tsize); 268661ae650dSJack F Vogel /* Now allocate transmit soft structs for the ring */ 268761ae650dSJack F Vogel if (ixl_allocate_tx_data(que)) { 268861ae650dSJack F Vogel device_printf(dev, 268961ae650dSJack F Vogel "Critical Failure setting up TX structures\n"); 269061ae650dSJack F Vogel error = ENOMEM; 269161ae650dSJack F Vogel goto fail; 269261ae650dSJack F Vogel } 269361ae650dSJack F Vogel /* Allocate a buf ring */ 269461ae650dSJack F Vogel txr->br = buf_ring_alloc(4096, M_DEVBUF, 269561ae650dSJack F Vogel M_WAITOK, &txr->mtx); 269661ae650dSJack F Vogel if (txr->br == NULL) { 269761ae650dSJack F Vogel device_printf(dev, 269861ae650dSJack F Vogel "Critical Failure setting up TX buf ring\n"); 269961ae650dSJack F Vogel error = ENOMEM; 270061ae650dSJack F Vogel goto fail; 270161ae650dSJack F Vogel } 270261ae650dSJack F Vogel 270361ae650dSJack F Vogel /* 270461ae650dSJack F Vogel * Next the RX queues... 270561ae650dSJack F Vogel */ 270661ae650dSJack F Vogel rsize = roundup2(que->num_desc * 270761ae650dSJack F Vogel sizeof(union i40e_rx_desc), DBA_ALIGN); 270861ae650dSJack F Vogel rxr = &que->rxr; 270961ae650dSJack F Vogel rxr->que = que; 271061ae650dSJack F Vogel rxr->tail = I40E_QRX_TAIL(que->me); 271161ae650dSJack F Vogel 271261ae650dSJack F Vogel /* Initialize the RX side lock */ 271361ae650dSJack F Vogel snprintf(rxr->mtx_name, sizeof(rxr->mtx_name), "%s:rx(%d)", 271461ae650dSJack F Vogel device_get_nameunit(dev), que->me); 271561ae650dSJack F Vogel mtx_init(&rxr->mtx, rxr->mtx_name, NULL, MTX_DEF); 271661ae650dSJack F Vogel 2717d94ca7cfSBjoern A. Zeeb if (i40e_allocate_dma_mem(&pf->hw, 2718d94ca7cfSBjoern A. Zeeb &rxr->dma, i40e_mem_reserved, rsize, 4096)) { 271961ae650dSJack F Vogel device_printf(dev, 272061ae650dSJack F Vogel "Unable to allocate RX Descriptor memory\n"); 272161ae650dSJack F Vogel error = ENOMEM; 272261ae650dSJack F Vogel goto fail; 272361ae650dSJack F Vogel } 272461ae650dSJack F Vogel rxr->base = (union i40e_rx_desc *)rxr->dma.va; 272561ae650dSJack F Vogel bzero((void *)rxr->base, rsize); 272661ae650dSJack F Vogel 272761ae650dSJack F Vogel /* Allocate receive soft structs for the ring*/ 272861ae650dSJack F Vogel if (ixl_allocate_rx_data(que)) { 272961ae650dSJack F Vogel device_printf(dev, 273061ae650dSJack F Vogel "Critical Failure setting up receive structs\n"); 273161ae650dSJack F Vogel error = ENOMEM; 273261ae650dSJack F Vogel goto fail; 273361ae650dSJack F Vogel } 273461ae650dSJack F Vogel } 273561ae650dSJack F Vogel 273661ae650dSJack F Vogel return (0); 273761ae650dSJack F Vogel 273861ae650dSJack F Vogel fail: 273961ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++) { 274061ae650dSJack F Vogel que = &vsi->queues[i]; 274161ae650dSJack F Vogel rxr = &que->rxr; 274261ae650dSJack F Vogel txr = &que->txr; 274361ae650dSJack F Vogel if (rxr->base) 2744d94ca7cfSBjoern A. Zeeb i40e_free_dma_mem(&pf->hw, &rxr->dma); 274561ae650dSJack F Vogel if (txr->base) 2746d94ca7cfSBjoern A. Zeeb i40e_free_dma_mem(&pf->hw, &txr->dma); 274761ae650dSJack F Vogel } 274861ae650dSJack F Vogel 274961ae650dSJack F Vogel early: 275061ae650dSJack F Vogel return (error); 275161ae650dSJack F Vogel } 275261ae650dSJack F Vogel 275361ae650dSJack F Vogel /* 275461ae650dSJack F Vogel ** Provide a update to the queue RX 275561ae650dSJack F Vogel ** interrupt moderation value. 275661ae650dSJack F Vogel */ 275761ae650dSJack F Vogel static void 275861ae650dSJack F Vogel ixl_set_queue_rx_itr(struct ixl_queue *que) 275961ae650dSJack F Vogel { 276061ae650dSJack F Vogel struct ixl_vsi *vsi = que->vsi; 276161ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 276261ae650dSJack F Vogel struct rx_ring *rxr = &que->rxr; 276361ae650dSJack F Vogel u16 rx_itr; 276461ae650dSJack F Vogel u16 rx_latency = 0; 276561ae650dSJack F Vogel int rx_bytes; 276661ae650dSJack F Vogel 276761ae650dSJack F Vogel 276861ae650dSJack F Vogel /* Idle, do nothing */ 276961ae650dSJack F Vogel if (rxr->bytes == 0) 277061ae650dSJack F Vogel return; 277161ae650dSJack F Vogel 277261ae650dSJack F Vogel if (ixl_dynamic_rx_itr) { 277361ae650dSJack F Vogel rx_bytes = rxr->bytes/rxr->itr; 277461ae650dSJack F Vogel rx_itr = rxr->itr; 277561ae650dSJack F Vogel 277661ae650dSJack F Vogel /* Adjust latency range */ 277761ae650dSJack F Vogel switch (rxr->latency) { 277861ae650dSJack F Vogel case IXL_LOW_LATENCY: 277961ae650dSJack F Vogel if (rx_bytes > 10) { 278061ae650dSJack F Vogel rx_latency = IXL_AVE_LATENCY; 278161ae650dSJack F Vogel rx_itr = IXL_ITR_20K; 278261ae650dSJack F Vogel } 278361ae650dSJack F Vogel break; 278461ae650dSJack F Vogel case IXL_AVE_LATENCY: 278561ae650dSJack F Vogel if (rx_bytes > 20) { 278661ae650dSJack F Vogel rx_latency = IXL_BULK_LATENCY; 278761ae650dSJack F Vogel rx_itr = IXL_ITR_8K; 278861ae650dSJack F Vogel } else if (rx_bytes <= 10) { 278961ae650dSJack F Vogel rx_latency = IXL_LOW_LATENCY; 279061ae650dSJack F Vogel rx_itr = IXL_ITR_100K; 279161ae650dSJack F Vogel } 279261ae650dSJack F Vogel break; 279361ae650dSJack F Vogel case IXL_BULK_LATENCY: 279461ae650dSJack F Vogel if (rx_bytes <= 20) { 279561ae650dSJack F Vogel rx_latency = IXL_AVE_LATENCY; 279661ae650dSJack F Vogel rx_itr = IXL_ITR_20K; 279761ae650dSJack F Vogel } 279861ae650dSJack F Vogel break; 279961ae650dSJack F Vogel } 280061ae650dSJack F Vogel 280161ae650dSJack F Vogel rxr->latency = rx_latency; 280261ae650dSJack F Vogel 280361ae650dSJack F Vogel if (rx_itr != rxr->itr) { 280461ae650dSJack F Vogel /* do an exponential smoothing */ 280561ae650dSJack F Vogel rx_itr = (10 * rx_itr * rxr->itr) / 280661ae650dSJack F Vogel ((9 * rx_itr) + rxr->itr); 280761ae650dSJack F Vogel rxr->itr = rx_itr & IXL_MAX_ITR; 280861ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITRN(IXL_RX_ITR, 280961ae650dSJack F Vogel que->me), rxr->itr); 281061ae650dSJack F Vogel } 281161ae650dSJack F Vogel } else { /* We may have have toggled to non-dynamic */ 281261ae650dSJack F Vogel if (vsi->rx_itr_setting & IXL_ITR_DYNAMIC) 281361ae650dSJack F Vogel vsi->rx_itr_setting = ixl_rx_itr; 281461ae650dSJack F Vogel /* Update the hardware if needed */ 281561ae650dSJack F Vogel if (rxr->itr != vsi->rx_itr_setting) { 281661ae650dSJack F Vogel rxr->itr = vsi->rx_itr_setting; 281761ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITRN(IXL_RX_ITR, 281861ae650dSJack F Vogel que->me), rxr->itr); 281961ae650dSJack F Vogel } 282061ae650dSJack F Vogel } 282161ae650dSJack F Vogel rxr->bytes = 0; 282261ae650dSJack F Vogel rxr->packets = 0; 282361ae650dSJack F Vogel return; 282461ae650dSJack F Vogel } 282561ae650dSJack F Vogel 282661ae650dSJack F Vogel 282761ae650dSJack F Vogel /* 282861ae650dSJack F Vogel ** Provide a update to the queue TX 282961ae650dSJack F Vogel ** interrupt moderation value. 283061ae650dSJack F Vogel */ 283161ae650dSJack F Vogel static void 283261ae650dSJack F Vogel ixl_set_queue_tx_itr(struct ixl_queue *que) 283361ae650dSJack F Vogel { 283461ae650dSJack F Vogel struct ixl_vsi *vsi = que->vsi; 283561ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 283661ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 283761ae650dSJack F Vogel u16 tx_itr; 283861ae650dSJack F Vogel u16 tx_latency = 0; 283961ae650dSJack F Vogel int tx_bytes; 284061ae650dSJack F Vogel 284161ae650dSJack F Vogel 284261ae650dSJack F Vogel /* Idle, do nothing */ 284361ae650dSJack F Vogel if (txr->bytes == 0) 284461ae650dSJack F Vogel return; 284561ae650dSJack F Vogel 284661ae650dSJack F Vogel if (ixl_dynamic_tx_itr) { 284761ae650dSJack F Vogel tx_bytes = txr->bytes/txr->itr; 284861ae650dSJack F Vogel tx_itr = txr->itr; 284961ae650dSJack F Vogel 285061ae650dSJack F Vogel switch (txr->latency) { 285161ae650dSJack F Vogel case IXL_LOW_LATENCY: 285261ae650dSJack F Vogel if (tx_bytes > 10) { 285361ae650dSJack F Vogel tx_latency = IXL_AVE_LATENCY; 285461ae650dSJack F Vogel tx_itr = IXL_ITR_20K; 285561ae650dSJack F Vogel } 285661ae650dSJack F Vogel break; 285761ae650dSJack F Vogel case IXL_AVE_LATENCY: 285861ae650dSJack F Vogel if (tx_bytes > 20) { 285961ae650dSJack F Vogel tx_latency = IXL_BULK_LATENCY; 286061ae650dSJack F Vogel tx_itr = IXL_ITR_8K; 286161ae650dSJack F Vogel } else if (tx_bytes <= 10) { 286261ae650dSJack F Vogel tx_latency = IXL_LOW_LATENCY; 286361ae650dSJack F Vogel tx_itr = IXL_ITR_100K; 286461ae650dSJack F Vogel } 286561ae650dSJack F Vogel break; 286661ae650dSJack F Vogel case IXL_BULK_LATENCY: 286761ae650dSJack F Vogel if (tx_bytes <= 20) { 286861ae650dSJack F Vogel tx_latency = IXL_AVE_LATENCY; 286961ae650dSJack F Vogel tx_itr = IXL_ITR_20K; 287061ae650dSJack F Vogel } 287161ae650dSJack F Vogel break; 287261ae650dSJack F Vogel } 287361ae650dSJack F Vogel 287461ae650dSJack F Vogel txr->latency = tx_latency; 287561ae650dSJack F Vogel 287661ae650dSJack F Vogel if (tx_itr != txr->itr) { 287761ae650dSJack F Vogel /* do an exponential smoothing */ 287861ae650dSJack F Vogel tx_itr = (10 * tx_itr * txr->itr) / 287961ae650dSJack F Vogel ((9 * tx_itr) + txr->itr); 288061ae650dSJack F Vogel txr->itr = tx_itr & IXL_MAX_ITR; 288161ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITRN(IXL_TX_ITR, 288261ae650dSJack F Vogel que->me), txr->itr); 288361ae650dSJack F Vogel } 288461ae650dSJack F Vogel 288561ae650dSJack F Vogel } else { /* We may have have toggled to non-dynamic */ 288661ae650dSJack F Vogel if (vsi->tx_itr_setting & IXL_ITR_DYNAMIC) 288761ae650dSJack F Vogel vsi->tx_itr_setting = ixl_tx_itr; 288861ae650dSJack F Vogel /* Update the hardware if needed */ 288961ae650dSJack F Vogel if (txr->itr != vsi->tx_itr_setting) { 289061ae650dSJack F Vogel txr->itr = vsi->tx_itr_setting; 289161ae650dSJack F Vogel wr32(hw, I40E_PFINT_ITRN(IXL_TX_ITR, 289261ae650dSJack F Vogel que->me), txr->itr); 289361ae650dSJack F Vogel } 289461ae650dSJack F Vogel } 289561ae650dSJack F Vogel txr->bytes = 0; 289661ae650dSJack F Vogel txr->packets = 0; 289761ae650dSJack F Vogel return; 289861ae650dSJack F Vogel } 289961ae650dSJack F Vogel 290061ae650dSJack F Vogel 290161ae650dSJack F Vogel static void 290261ae650dSJack F Vogel ixl_add_hw_stats(struct ixl_pf *pf) 290361ae650dSJack F Vogel { 290461ae650dSJack F Vogel device_t dev = pf->dev; 290561ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 290661ae650dSJack F Vogel struct ixl_queue *queues = vsi->queues; 290761ae650dSJack F Vogel struct i40e_eth_stats *vsi_stats = &vsi->eth_stats; 290861ae650dSJack F Vogel struct i40e_hw_port_stats *pf_stats = &pf->stats; 290961ae650dSJack F Vogel 291061ae650dSJack F Vogel struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(dev); 291161ae650dSJack F Vogel struct sysctl_oid *tree = device_get_sysctl_tree(dev); 291261ae650dSJack F Vogel struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree); 291361ae650dSJack F Vogel 291461ae650dSJack F Vogel struct sysctl_oid *vsi_node, *queue_node; 291561ae650dSJack F Vogel struct sysctl_oid_list *vsi_list, *queue_list; 291661ae650dSJack F Vogel 291761ae650dSJack F Vogel struct tx_ring *txr; 291861ae650dSJack F Vogel struct rx_ring *rxr; 291961ae650dSJack F Vogel 292061ae650dSJack F Vogel /* Driver statistics */ 292161ae650dSJack F Vogel SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "watchdog_events", 292261ae650dSJack F Vogel CTLFLAG_RD, &pf->watchdog_events, 292361ae650dSJack F Vogel "Watchdog timeouts"); 292461ae650dSJack F Vogel SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "admin_irq", 292561ae650dSJack F Vogel CTLFLAG_RD, &pf->admin_irq, 292661ae650dSJack F Vogel "Admin Queue IRQ Handled"); 292761ae650dSJack F Vogel 292861ae650dSJack F Vogel /* VSI statistics */ 292961ae650dSJack F Vogel #define QUEUE_NAME_LEN 32 293061ae650dSJack F Vogel char queue_namebuf[QUEUE_NAME_LEN]; 293161ae650dSJack F Vogel 293261ae650dSJack F Vogel // ERJ: Only one vsi now, re-do when >1 VSI enabled 293361ae650dSJack F Vogel // snprintf(vsi_namebuf, QUEUE_NAME_LEN, "vsi%d", vsi->info.stat_counter_idx); 293461ae650dSJack F Vogel vsi_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "vsi", 293561ae650dSJack F Vogel CTLFLAG_RD, NULL, "VSI-specific stats"); 293661ae650dSJack F Vogel vsi_list = SYSCTL_CHILDREN(vsi_node); 293761ae650dSJack F Vogel 293861ae650dSJack F Vogel ixl_add_sysctls_eth_stats(ctx, vsi_list, vsi_stats); 293961ae650dSJack F Vogel 294061ae650dSJack F Vogel /* Queue statistics */ 294161ae650dSJack F Vogel for (int q = 0; q < vsi->num_queues; q++) { 294261ae650dSJack F Vogel snprintf(queue_namebuf, QUEUE_NAME_LEN, "que%d", q); 294361ae650dSJack F Vogel queue_node = SYSCTL_ADD_NODE(ctx, vsi_list, OID_AUTO, queue_namebuf, 294461ae650dSJack F Vogel CTLFLAG_RD, NULL, "Queue #"); 294561ae650dSJack F Vogel queue_list = SYSCTL_CHILDREN(queue_node); 294661ae650dSJack F Vogel 294761ae650dSJack F Vogel txr = &(queues[q].txr); 294861ae650dSJack F Vogel rxr = &(queues[q].rxr); 294961ae650dSJack F Vogel 295061ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "mbuf_defrag_failed", 295161ae650dSJack F Vogel CTLFLAG_RD, &(queues[q].mbuf_defrag_failed), 295261ae650dSJack F Vogel "m_defrag() failed"); 295361ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "dropped", 295461ae650dSJack F Vogel CTLFLAG_RD, &(queues[q].dropped_pkts), 295561ae650dSJack F Vogel "Driver dropped packets"); 295661ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "irqs", 295761ae650dSJack F Vogel CTLFLAG_RD, &(queues[q].irqs), 295861ae650dSJack F Vogel "irqs on this queue"); 295961ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tso_tx", 296061ae650dSJack F Vogel CTLFLAG_RD, &(queues[q].tso), 296161ae650dSJack F Vogel "TSO"); 296261ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tx_dma_setup", 296361ae650dSJack F Vogel CTLFLAG_RD, &(queues[q].tx_dma_setup), 296461ae650dSJack F Vogel "Driver tx dma failure in xmit"); 296561ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "no_desc_avail", 296661ae650dSJack F Vogel CTLFLAG_RD, &(txr->no_desc), 296761ae650dSJack F Vogel "Queue No Descriptor Available"); 296861ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tx_packets", 296961ae650dSJack F Vogel CTLFLAG_RD, &(txr->total_packets), 297061ae650dSJack F Vogel "Queue Packets Transmitted"); 297161ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tx_bytes", 297261ae650dSJack F Vogel CTLFLAG_RD, &(txr->tx_bytes), 297361ae650dSJack F Vogel "Queue Bytes Transmitted"); 297461ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_packets", 297561ae650dSJack F Vogel CTLFLAG_RD, &(rxr->rx_packets), 297661ae650dSJack F Vogel "Queue Packets Received"); 297761ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_bytes", 297861ae650dSJack F Vogel CTLFLAG_RD, &(rxr->rx_bytes), 297961ae650dSJack F Vogel "Queue Bytes Received"); 298061ae650dSJack F Vogel } 298161ae650dSJack F Vogel 298261ae650dSJack F Vogel /* MAC stats */ 298361ae650dSJack F Vogel ixl_add_sysctls_mac_stats(ctx, child, pf_stats); 298461ae650dSJack F Vogel } 298561ae650dSJack F Vogel 298661ae650dSJack F Vogel static void 298761ae650dSJack F Vogel ixl_add_sysctls_eth_stats(struct sysctl_ctx_list *ctx, 298861ae650dSJack F Vogel struct sysctl_oid_list *child, 298961ae650dSJack F Vogel struct i40e_eth_stats *eth_stats) 299061ae650dSJack F Vogel { 299161ae650dSJack F Vogel struct ixl_sysctl_info ctls[] = 299261ae650dSJack F Vogel { 299361ae650dSJack F Vogel {ð_stats->rx_bytes, "good_octets_rcvd", "Good Octets Received"}, 299461ae650dSJack F Vogel {ð_stats->rx_unicast, "ucast_pkts_rcvd", 299561ae650dSJack F Vogel "Unicast Packets Received"}, 299661ae650dSJack F Vogel {ð_stats->rx_multicast, "mcast_pkts_rcvd", 299761ae650dSJack F Vogel "Multicast Packets Received"}, 299861ae650dSJack F Vogel {ð_stats->rx_broadcast, "bcast_pkts_rcvd", 299961ae650dSJack F Vogel "Broadcast Packets Received"}, 300061ae650dSJack F Vogel {ð_stats->rx_discards, "rx_discards", "Discarded RX packets"}, 300161ae650dSJack F Vogel {ð_stats->tx_bytes, "good_octets_txd", "Good Octets Transmitted"}, 300261ae650dSJack F Vogel {ð_stats->tx_unicast, "ucast_pkts_txd", "Unicast Packets Transmitted"}, 300361ae650dSJack F Vogel {ð_stats->tx_multicast, "mcast_pkts_txd", 300461ae650dSJack F Vogel "Multicast Packets Transmitted"}, 300561ae650dSJack F Vogel {ð_stats->tx_broadcast, "bcast_pkts_txd", 300661ae650dSJack F Vogel "Broadcast Packets Transmitted"}, 300761ae650dSJack F Vogel {ð_stats->tx_discards, "tx_discards", "Discarded TX packets"}, 300861ae650dSJack F Vogel // end 300961ae650dSJack F Vogel {0,0,0} 301061ae650dSJack F Vogel }; 301161ae650dSJack F Vogel 301261ae650dSJack F Vogel struct ixl_sysctl_info *entry = ctls; 301361ae650dSJack F Vogel while (entry->stat != 0) 301461ae650dSJack F Vogel { 301561ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, child, OID_AUTO, entry->name, 301661ae650dSJack F Vogel CTLFLAG_RD, entry->stat, 301761ae650dSJack F Vogel entry->description); 301861ae650dSJack F Vogel entry++; 301961ae650dSJack F Vogel } 302061ae650dSJack F Vogel } 302161ae650dSJack F Vogel 302261ae650dSJack F Vogel static void 302361ae650dSJack F Vogel ixl_add_sysctls_mac_stats(struct sysctl_ctx_list *ctx, 302461ae650dSJack F Vogel struct sysctl_oid_list *child, 302561ae650dSJack F Vogel struct i40e_hw_port_stats *stats) 302661ae650dSJack F Vogel { 302761ae650dSJack F Vogel struct sysctl_oid *stat_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "mac", 302861ae650dSJack F Vogel CTLFLAG_RD, NULL, "Mac Statistics"); 302961ae650dSJack F Vogel struct sysctl_oid_list *stat_list = SYSCTL_CHILDREN(stat_node); 303061ae650dSJack F Vogel 303161ae650dSJack F Vogel struct i40e_eth_stats *eth_stats = &stats->eth; 303261ae650dSJack F Vogel ixl_add_sysctls_eth_stats(ctx, stat_list, eth_stats); 303361ae650dSJack F Vogel 303461ae650dSJack F Vogel struct ixl_sysctl_info ctls[] = 303561ae650dSJack F Vogel { 303661ae650dSJack F Vogel {&stats->crc_errors, "crc_errors", "CRC Errors"}, 303761ae650dSJack F Vogel {&stats->illegal_bytes, "illegal_bytes", "Illegal Byte Errors"}, 303861ae650dSJack F Vogel {&stats->mac_local_faults, "local_faults", "MAC Local Faults"}, 303961ae650dSJack F Vogel {&stats->mac_remote_faults, "remote_faults", "MAC Remote Faults"}, 304061ae650dSJack F Vogel {&stats->rx_length_errors, "rx_length_errors", "Receive Length Errors"}, 304161ae650dSJack F Vogel /* Packet Reception Stats */ 304261ae650dSJack F Vogel {&stats->rx_size_64, "rx_frames_64", "64 byte frames received"}, 304361ae650dSJack F Vogel {&stats->rx_size_127, "rx_frames_65_127", "65-127 byte frames received"}, 304461ae650dSJack F Vogel {&stats->rx_size_255, "rx_frames_128_255", "128-255 byte frames received"}, 304561ae650dSJack F Vogel {&stats->rx_size_511, "rx_frames_256_511", "256-511 byte frames received"}, 304661ae650dSJack F Vogel {&stats->rx_size_1023, "rx_frames_512_1023", "512-1023 byte frames received"}, 304761ae650dSJack F Vogel {&stats->rx_size_1522, "rx_frames_1024_1522", "1024-1522 byte frames received"}, 304861ae650dSJack F Vogel {&stats->rx_size_big, "rx_frames_big", "1523-9522 byte frames received"}, 304961ae650dSJack F Vogel {&stats->rx_undersize, "rx_undersize", "Undersized packets received"}, 305061ae650dSJack F Vogel {&stats->rx_fragments, "rx_fragmented", "Fragmented packets received"}, 305161ae650dSJack F Vogel {&stats->rx_oversize, "rx_oversized", "Oversized packets received"}, 305261ae650dSJack F Vogel {&stats->rx_jabber, "rx_jabber", "Received Jabber"}, 305361ae650dSJack F Vogel {&stats->checksum_error, "checksum_errors", "Checksum Errors"}, 305461ae650dSJack F Vogel /* Packet Transmission Stats */ 305561ae650dSJack F Vogel {&stats->tx_size_64, "tx_frames_64", "64 byte frames transmitted"}, 305661ae650dSJack F Vogel {&stats->tx_size_127, "tx_frames_65_127", "65-127 byte frames transmitted"}, 305761ae650dSJack F Vogel {&stats->tx_size_255, "tx_frames_128_255", "128-255 byte frames transmitted"}, 305861ae650dSJack F Vogel {&stats->tx_size_511, "tx_frames_256_511", "256-511 byte frames transmitted"}, 305961ae650dSJack F Vogel {&stats->tx_size_1023, "tx_frames_512_1023", "512-1023 byte frames transmitted"}, 306061ae650dSJack F Vogel {&stats->tx_size_1522, "tx_frames_1024_1522", "1024-1522 byte frames transmitted"}, 306161ae650dSJack F Vogel {&stats->tx_size_big, "tx_frames_big", "1523-9522 byte frames transmitted"}, 306261ae650dSJack F Vogel /* Flow control */ 306361ae650dSJack F Vogel {&stats->link_xon_tx, "xon_txd", "Link XON transmitted"}, 306461ae650dSJack F Vogel {&stats->link_xon_rx, "xon_recvd", "Link XON received"}, 306561ae650dSJack F Vogel {&stats->link_xoff_tx, "xoff_txd", "Link XOFF transmitted"}, 306661ae650dSJack F Vogel {&stats->link_xoff_rx, "xoff_recvd", "Link XOFF received"}, 306761ae650dSJack F Vogel /* End */ 306861ae650dSJack F Vogel {0,0,0} 306961ae650dSJack F Vogel }; 307061ae650dSJack F Vogel 307161ae650dSJack F Vogel struct ixl_sysctl_info *entry = ctls; 307261ae650dSJack F Vogel while (entry->stat != 0) 307361ae650dSJack F Vogel { 307461ae650dSJack F Vogel SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, entry->name, 307561ae650dSJack F Vogel CTLFLAG_RD, entry->stat, 307661ae650dSJack F Vogel entry->description); 307761ae650dSJack F Vogel entry++; 307861ae650dSJack F Vogel } 307961ae650dSJack F Vogel } 308061ae650dSJack F Vogel 308161ae650dSJack F Vogel /* 308261ae650dSJack F Vogel ** ixl_config_rss - setup RSS 308361ae650dSJack F Vogel ** - note this is done for the single vsi 308461ae650dSJack F Vogel */ 308561ae650dSJack F Vogel static void ixl_config_rss(struct ixl_vsi *vsi) 308661ae650dSJack F Vogel { 308761ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)vsi->back; 308861ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 308961ae650dSJack F Vogel u32 lut = 0; 309061ae650dSJack F Vogel u64 set_hena, hena; 309161ae650dSJack F Vogel int i, j; 309261ae650dSJack F Vogel 309361ae650dSJack F Vogel static const u32 seed[I40E_PFQF_HKEY_MAX_INDEX + 1] = {0x41b01687, 309461ae650dSJack F Vogel 0x183cfd8c, 0xce880440, 0x580cbc3c, 0x35897377, 309561ae650dSJack F Vogel 0x328b25e1, 0x4fa98922, 0xb7d90c14, 0xd5bad70d, 309661ae650dSJack F Vogel 0xcd15a2c1, 0xe8580225, 0x4a1e9d11, 0xfe5731be}; 309761ae650dSJack F Vogel 309861ae650dSJack F Vogel /* Fill out hash function seed */ 309961ae650dSJack F Vogel for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) 310061ae650dSJack F Vogel wr32(hw, I40E_PFQF_HKEY(i), seed[i]); 310161ae650dSJack F Vogel 310261ae650dSJack F Vogel /* Enable PCTYPES for RSS: */ 310361ae650dSJack F Vogel set_hena = 310461ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | 310561ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP) | 310661ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) | 310761ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | 310861ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4) | 310961ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | 311061ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP) | 311161ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) | 311261ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | 311361ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6) | 311461ae650dSJack F Vogel ((u64)1 << I40E_FILTER_PCTYPE_L2_PAYLOAD); 311561ae650dSJack F Vogel 311661ae650dSJack F Vogel hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) | 311761ae650dSJack F Vogel ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32); 311861ae650dSJack F Vogel hena |= set_hena; 311961ae650dSJack F Vogel wr32(hw, I40E_PFQF_HENA(0), (u32)hena); 312061ae650dSJack F Vogel wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); 312161ae650dSJack F Vogel 312261ae650dSJack F Vogel /* Populate the LUT with max no. of queues in round robin fashion */ 312361ae650dSJack F Vogel for (i = j = 0; i < pf->hw.func_caps.rss_table_size; i++, j++) { 312461ae650dSJack F Vogel if (j == vsi->num_queues) 312561ae650dSJack F Vogel j = 0; 312661ae650dSJack F Vogel /* lut = 4-byte sliding window of 4 lut entries */ 312761ae650dSJack F Vogel lut = (lut << 8) | (j & 312861ae650dSJack F Vogel ((0x1 << pf->hw.func_caps.rss_table_entry_width) - 1)); 312961ae650dSJack F Vogel /* On i = 3, we have 4 entries in lut; write to the register */ 313061ae650dSJack F Vogel if ((i & 3) == 3) 313161ae650dSJack F Vogel wr32(hw, I40E_PFQF_HLUT(i >> 2), lut); 313261ae650dSJack F Vogel } 313361ae650dSJack F Vogel ixl_flush(hw); 313461ae650dSJack F Vogel } 313561ae650dSJack F Vogel 313661ae650dSJack F Vogel 313761ae650dSJack F Vogel /* 313861ae650dSJack F Vogel ** This routine is run via an vlan config EVENT, 313961ae650dSJack F Vogel ** it enables us to use the HW Filter table since 314061ae650dSJack F Vogel ** we can get the vlan id. This just creates the 314161ae650dSJack F Vogel ** entry in the soft version of the VFTA, init will 314261ae650dSJack F Vogel ** repopulate the real table. 314361ae650dSJack F Vogel */ 314461ae650dSJack F Vogel static void 314561ae650dSJack F Vogel ixl_register_vlan(void *arg, struct ifnet *ifp, u16 vtag) 314661ae650dSJack F Vogel { 314761ae650dSJack F Vogel struct ixl_vsi *vsi = ifp->if_softc; 314861ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 314961ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)vsi->back; 315061ae650dSJack F Vogel 315161ae650dSJack F Vogel if (ifp->if_softc != arg) /* Not our event */ 315261ae650dSJack F Vogel return; 315361ae650dSJack F Vogel 315461ae650dSJack F Vogel if ((vtag == 0) || (vtag > 4095)) /* Invalid */ 315561ae650dSJack F Vogel return; 315661ae650dSJack F Vogel 315761ae650dSJack F Vogel IXL_PF_LOCK(pf); 315861ae650dSJack F Vogel ++vsi->num_vlans; 315961ae650dSJack F Vogel ixl_add_filter(vsi, hw->mac.addr, vtag); 316061ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 316161ae650dSJack F Vogel } 316261ae650dSJack F Vogel 316361ae650dSJack F Vogel /* 316461ae650dSJack F Vogel ** This routine is run via an vlan 316561ae650dSJack F Vogel ** unconfig EVENT, remove our entry 316661ae650dSJack F Vogel ** in the soft vfta. 316761ae650dSJack F Vogel */ 316861ae650dSJack F Vogel static void 316961ae650dSJack F Vogel ixl_unregister_vlan(void *arg, struct ifnet *ifp, u16 vtag) 317061ae650dSJack F Vogel { 317161ae650dSJack F Vogel struct ixl_vsi *vsi = ifp->if_softc; 317261ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 317361ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)vsi->back; 317461ae650dSJack F Vogel 317561ae650dSJack F Vogel if (ifp->if_softc != arg) 317661ae650dSJack F Vogel return; 317761ae650dSJack F Vogel 317861ae650dSJack F Vogel if ((vtag == 0) || (vtag > 4095)) /* Invalid */ 317961ae650dSJack F Vogel return; 318061ae650dSJack F Vogel 318161ae650dSJack F Vogel IXL_PF_LOCK(pf); 318261ae650dSJack F Vogel --vsi->num_vlans; 318361ae650dSJack F Vogel ixl_del_filter(vsi, hw->mac.addr, vtag); 318461ae650dSJack F Vogel IXL_PF_UNLOCK(pf); 318561ae650dSJack F Vogel } 318661ae650dSJack F Vogel 318761ae650dSJack F Vogel /* 318861ae650dSJack F Vogel ** This routine updates vlan filters, called by init 318961ae650dSJack F Vogel ** it scans the filter table and then updates the hw 319061ae650dSJack F Vogel ** after a soft reset. 319161ae650dSJack F Vogel */ 319261ae650dSJack F Vogel static void 319361ae650dSJack F Vogel ixl_setup_vlan_filters(struct ixl_vsi *vsi) 319461ae650dSJack F Vogel { 319561ae650dSJack F Vogel struct ixl_mac_filter *f; 319661ae650dSJack F Vogel int cnt = 0, flags; 319761ae650dSJack F Vogel 319861ae650dSJack F Vogel if (vsi->num_vlans == 0) 319961ae650dSJack F Vogel return; 320061ae650dSJack F Vogel /* 320161ae650dSJack F Vogel ** Scan the filter list for vlan entries, 320261ae650dSJack F Vogel ** mark them for addition and then call 320361ae650dSJack F Vogel ** for the AQ update. 320461ae650dSJack F Vogel */ 320561ae650dSJack F Vogel SLIST_FOREACH(f, &vsi->ftl, next) { 320661ae650dSJack F Vogel if (f->flags & IXL_FILTER_VLAN) { 320761ae650dSJack F Vogel f->flags |= 320861ae650dSJack F Vogel (IXL_FILTER_ADD | 320961ae650dSJack F Vogel IXL_FILTER_USED); 321061ae650dSJack F Vogel cnt++; 321161ae650dSJack F Vogel } 321261ae650dSJack F Vogel } 321361ae650dSJack F Vogel if (cnt == 0) { 321461ae650dSJack F Vogel printf("setup vlan: no filters found!\n"); 321561ae650dSJack F Vogel return; 321661ae650dSJack F Vogel } 321761ae650dSJack F Vogel flags = IXL_FILTER_VLAN; 321861ae650dSJack F Vogel flags |= (IXL_FILTER_ADD | IXL_FILTER_USED); 321961ae650dSJack F Vogel ixl_add_hw_filters(vsi, flags, cnt); 322061ae650dSJack F Vogel return; 322161ae650dSJack F Vogel } 322261ae650dSJack F Vogel 322361ae650dSJack F Vogel /* 322461ae650dSJack F Vogel ** Initialize filter list and add filters that the hardware 322561ae650dSJack F Vogel ** needs to know about. 322661ae650dSJack F Vogel */ 322761ae650dSJack F Vogel static void 322861ae650dSJack F Vogel ixl_init_filters(struct ixl_vsi *vsi) 322961ae650dSJack F Vogel { 323061ae650dSJack F Vogel /* Add broadcast address */ 323161ae650dSJack F Vogel u8 bc[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 323261ae650dSJack F Vogel ixl_add_filter(vsi, bc, IXL_VLAN_ANY); 323361ae650dSJack F Vogel } 323461ae650dSJack F Vogel 323561ae650dSJack F Vogel /* 323661ae650dSJack F Vogel ** This routine adds mulicast filters 323761ae650dSJack F Vogel */ 323861ae650dSJack F Vogel static void 323961ae650dSJack F Vogel ixl_add_mc_filter(struct ixl_vsi *vsi, u8 *macaddr) 324061ae650dSJack F Vogel { 324161ae650dSJack F Vogel struct ixl_mac_filter *f; 324261ae650dSJack F Vogel 324361ae650dSJack F Vogel /* Does one already exist */ 324461ae650dSJack F Vogel f = ixl_find_filter(vsi, macaddr, IXL_VLAN_ANY); 324561ae650dSJack F Vogel if (f != NULL) 324661ae650dSJack F Vogel return; 324761ae650dSJack F Vogel 324861ae650dSJack F Vogel f = ixl_get_filter(vsi); 324961ae650dSJack F Vogel if (f == NULL) { 325061ae650dSJack F Vogel printf("WARNING: no filter available!!\n"); 325161ae650dSJack F Vogel return; 325261ae650dSJack F Vogel } 325361ae650dSJack F Vogel bcopy(macaddr, f->macaddr, ETHER_ADDR_LEN); 325461ae650dSJack F Vogel f->vlan = IXL_VLAN_ANY; 325561ae650dSJack F Vogel f->flags |= (IXL_FILTER_ADD | IXL_FILTER_USED 325661ae650dSJack F Vogel | IXL_FILTER_MC); 325761ae650dSJack F Vogel 325861ae650dSJack F Vogel return; 325961ae650dSJack F Vogel } 326061ae650dSJack F Vogel 326161ae650dSJack F Vogel /* 326261ae650dSJack F Vogel ** This routine adds macvlan filters 326361ae650dSJack F Vogel */ 326461ae650dSJack F Vogel static void 326561ae650dSJack F Vogel ixl_add_filter(struct ixl_vsi *vsi, u8 *macaddr, s16 vlan) 326661ae650dSJack F Vogel { 326761ae650dSJack F Vogel struct ixl_mac_filter *f, *tmp; 326861ae650dSJack F Vogel device_t dev = vsi->dev; 326961ae650dSJack F Vogel 327061ae650dSJack F Vogel DEBUGOUT("ixl_add_filter: begin"); 327161ae650dSJack F Vogel 327261ae650dSJack F Vogel /* Does one already exist */ 327361ae650dSJack F Vogel f = ixl_find_filter(vsi, macaddr, vlan); 327461ae650dSJack F Vogel if (f != NULL) 327561ae650dSJack F Vogel return; 327661ae650dSJack F Vogel /* 327761ae650dSJack F Vogel ** Is this the first vlan being registered, if so we 327861ae650dSJack F Vogel ** need to remove the ANY filter that indicates we are 327961ae650dSJack F Vogel ** not in a vlan, and replace that with a 0 filter. 328061ae650dSJack F Vogel */ 328161ae650dSJack F Vogel if ((vlan != IXL_VLAN_ANY) && (vsi->num_vlans == 1)) { 328261ae650dSJack F Vogel tmp = ixl_find_filter(vsi, macaddr, IXL_VLAN_ANY); 328361ae650dSJack F Vogel if (tmp != NULL) { 328461ae650dSJack F Vogel ixl_del_filter(vsi, macaddr, IXL_VLAN_ANY); 328561ae650dSJack F Vogel ixl_add_filter(vsi, macaddr, 0); 328661ae650dSJack F Vogel } 328761ae650dSJack F Vogel } 328861ae650dSJack F Vogel 328961ae650dSJack F Vogel f = ixl_get_filter(vsi); 329061ae650dSJack F Vogel if (f == NULL) { 329161ae650dSJack F Vogel device_printf(dev, "WARNING: no filter available!!\n"); 329261ae650dSJack F Vogel return; 329361ae650dSJack F Vogel } 329461ae650dSJack F Vogel bcopy(macaddr, f->macaddr, ETHER_ADDR_LEN); 329561ae650dSJack F Vogel f->vlan = vlan; 329661ae650dSJack F Vogel f->flags |= (IXL_FILTER_ADD | IXL_FILTER_USED); 329761ae650dSJack F Vogel if (f->vlan != IXL_VLAN_ANY) 329861ae650dSJack F Vogel f->flags |= IXL_FILTER_VLAN; 329961ae650dSJack F Vogel 330061ae650dSJack F Vogel ixl_add_hw_filters(vsi, f->flags, 1); 330161ae650dSJack F Vogel return; 330261ae650dSJack F Vogel } 330361ae650dSJack F Vogel 330461ae650dSJack F Vogel static void 330561ae650dSJack F Vogel ixl_del_filter(struct ixl_vsi *vsi, u8 *macaddr, s16 vlan) 330661ae650dSJack F Vogel { 330761ae650dSJack F Vogel struct ixl_mac_filter *f; 330861ae650dSJack F Vogel 330961ae650dSJack F Vogel f = ixl_find_filter(vsi, macaddr, vlan); 331061ae650dSJack F Vogel if (f == NULL) 331161ae650dSJack F Vogel return; 331261ae650dSJack F Vogel 331361ae650dSJack F Vogel f->flags |= IXL_FILTER_DEL; 331461ae650dSJack F Vogel ixl_del_hw_filters(vsi, 1); 331561ae650dSJack F Vogel 331661ae650dSJack F Vogel /* Check if this is the last vlan removal */ 331761ae650dSJack F Vogel if (vlan != IXL_VLAN_ANY && vsi->num_vlans == 0) { 331861ae650dSJack F Vogel /* Switch back to a non-vlan filter */ 331961ae650dSJack F Vogel ixl_del_filter(vsi, macaddr, 0); 332061ae650dSJack F Vogel ixl_add_filter(vsi, macaddr, IXL_VLAN_ANY); 332161ae650dSJack F Vogel } 332261ae650dSJack F Vogel return; 332361ae650dSJack F Vogel } 332461ae650dSJack F Vogel 332561ae650dSJack F Vogel /* 332661ae650dSJack F Vogel ** Find the filter with both matching mac addr and vlan id 332761ae650dSJack F Vogel */ 332861ae650dSJack F Vogel static struct ixl_mac_filter * 332961ae650dSJack F Vogel ixl_find_filter(struct ixl_vsi *vsi, u8 *macaddr, s16 vlan) 333061ae650dSJack F Vogel { 333161ae650dSJack F Vogel struct ixl_mac_filter *f; 333261ae650dSJack F Vogel bool match = FALSE; 333361ae650dSJack F Vogel 333461ae650dSJack F Vogel SLIST_FOREACH(f, &vsi->ftl, next) { 333561ae650dSJack F Vogel if (!cmp_etheraddr(f->macaddr, macaddr)) 333661ae650dSJack F Vogel continue; 333761ae650dSJack F Vogel if (f->vlan == vlan) { 333861ae650dSJack F Vogel match = TRUE; 333961ae650dSJack F Vogel break; 334061ae650dSJack F Vogel } 334161ae650dSJack F Vogel } 334261ae650dSJack F Vogel 334361ae650dSJack F Vogel if (!match) 334461ae650dSJack F Vogel f = NULL; 334561ae650dSJack F Vogel return (f); 334661ae650dSJack F Vogel } 334761ae650dSJack F Vogel 334861ae650dSJack F Vogel /* 334961ae650dSJack F Vogel ** This routine takes additions to the vsi filter 335061ae650dSJack F Vogel ** table and creates an Admin Queue call to create 335161ae650dSJack F Vogel ** the filters in the hardware. 335261ae650dSJack F Vogel */ 335361ae650dSJack F Vogel static void 335461ae650dSJack F Vogel ixl_add_hw_filters(struct ixl_vsi *vsi, int flags, int cnt) 335561ae650dSJack F Vogel { 335661ae650dSJack F Vogel struct i40e_aqc_add_macvlan_element_data *a, *b; 335761ae650dSJack F Vogel struct ixl_mac_filter *f; 335861ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 335961ae650dSJack F Vogel device_t dev = vsi->dev; 336061ae650dSJack F Vogel int err, j = 0; 336161ae650dSJack F Vogel 336261ae650dSJack F Vogel a = malloc(sizeof(struct i40e_aqc_add_macvlan_element_data) * cnt, 336361ae650dSJack F Vogel M_DEVBUF, M_NOWAIT | M_ZERO); 336461ae650dSJack F Vogel if (a == NULL) { 336561ae650dSJack F Vogel device_printf(dev, "add hw filter failed to get memory\n"); 336661ae650dSJack F Vogel return; 336761ae650dSJack F Vogel } 336861ae650dSJack F Vogel 336961ae650dSJack F Vogel /* 337061ae650dSJack F Vogel ** Scan the filter list, each time we find one 337161ae650dSJack F Vogel ** we add it to the admin queue array and turn off 337261ae650dSJack F Vogel ** the add bit. 337361ae650dSJack F Vogel */ 337461ae650dSJack F Vogel SLIST_FOREACH(f, &vsi->ftl, next) { 337561ae650dSJack F Vogel if (f->flags == flags) { 337661ae650dSJack F Vogel b = &a[j]; // a pox on fvl long names :) 337761ae650dSJack F Vogel bcopy(f->macaddr, b->mac_addr, ETHER_ADDR_LEN); 337861ae650dSJack F Vogel b->vlan_tag = 337961ae650dSJack F Vogel (f->vlan == IXL_VLAN_ANY ? 0 : f->vlan); 338061ae650dSJack F Vogel b->flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; 338161ae650dSJack F Vogel f->flags &= ~IXL_FILTER_ADD; 338261ae650dSJack F Vogel j++; 338361ae650dSJack F Vogel } 338461ae650dSJack F Vogel if (j == cnt) 338561ae650dSJack F Vogel break; 338661ae650dSJack F Vogel } 338761ae650dSJack F Vogel if (j > 0) { 338861ae650dSJack F Vogel err = i40e_aq_add_macvlan(hw, vsi->seid, a, j, NULL); 338961ae650dSJack F Vogel if (err) 339061ae650dSJack F Vogel device_printf(dev, "aq_add_macvlan failure %d\n", 339161ae650dSJack F Vogel hw->aq.asq_last_status); 339261ae650dSJack F Vogel else 339361ae650dSJack F Vogel vsi->hw_filters_add += j; 339461ae650dSJack F Vogel } 339561ae650dSJack F Vogel free(a, M_DEVBUF); 339661ae650dSJack F Vogel return; 339761ae650dSJack F Vogel } 339861ae650dSJack F Vogel 339961ae650dSJack F Vogel /* 340061ae650dSJack F Vogel ** This routine takes removals in the vsi filter 340161ae650dSJack F Vogel ** table and creates an Admin Queue call to delete 340261ae650dSJack F Vogel ** the filters in the hardware. 340361ae650dSJack F Vogel */ 340461ae650dSJack F Vogel static void 340561ae650dSJack F Vogel ixl_del_hw_filters(struct ixl_vsi *vsi, int cnt) 340661ae650dSJack F Vogel { 340761ae650dSJack F Vogel struct i40e_aqc_remove_macvlan_element_data *d, *e; 340861ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 340961ae650dSJack F Vogel device_t dev = vsi->dev; 341061ae650dSJack F Vogel struct ixl_mac_filter *f, *f_temp; 341161ae650dSJack F Vogel int err, j = 0; 341261ae650dSJack F Vogel 341361ae650dSJack F Vogel DEBUGOUT("ixl_del_hw_filters: begin\n"); 341461ae650dSJack F Vogel 341561ae650dSJack F Vogel d = malloc(sizeof(struct i40e_aqc_remove_macvlan_element_data) * cnt, 341661ae650dSJack F Vogel M_DEVBUF, M_NOWAIT | M_ZERO); 341761ae650dSJack F Vogel if (d == NULL) { 341861ae650dSJack F Vogel printf("del hw filter failed to get memory\n"); 341961ae650dSJack F Vogel return; 342061ae650dSJack F Vogel } 342161ae650dSJack F Vogel 342261ae650dSJack F Vogel SLIST_FOREACH_SAFE(f, &vsi->ftl, next, f_temp) { 342361ae650dSJack F Vogel if (f->flags & IXL_FILTER_DEL) { 342461ae650dSJack F Vogel e = &d[j]; // a pox on fvl long names :) 342561ae650dSJack F Vogel bcopy(f->macaddr, e->mac_addr, ETHER_ADDR_LEN); 342661ae650dSJack F Vogel e->vlan_tag = (f->vlan == IXL_VLAN_ANY ? 0 : f->vlan); 342761ae650dSJack F Vogel e->flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; 342861ae650dSJack F Vogel /* delete entry from vsi list */ 342961ae650dSJack F Vogel SLIST_REMOVE(&vsi->ftl, f, ixl_mac_filter, next); 343061ae650dSJack F Vogel free(f, M_DEVBUF); 343161ae650dSJack F Vogel j++; 343261ae650dSJack F Vogel } 343361ae650dSJack F Vogel if (j == cnt) 343461ae650dSJack F Vogel break; 343561ae650dSJack F Vogel } 343661ae650dSJack F Vogel if (j > 0) { 343761ae650dSJack F Vogel err = i40e_aq_remove_macvlan(hw, vsi->seid, d, j, NULL); 343861ae650dSJack F Vogel /* NOTE: returns ENOENT every time but seems to work fine, 343961ae650dSJack F Vogel so we'll ignore that specific error. */ 344061ae650dSJack F Vogel if (err && hw->aq.asq_last_status != I40E_AQ_RC_ENOENT) { 344161ae650dSJack F Vogel int sc = 0; 344261ae650dSJack F Vogel for (int i = 0; i < j; i++) 344361ae650dSJack F Vogel sc += (!d[i].error_code); 344461ae650dSJack F Vogel vsi->hw_filters_del += sc; 344561ae650dSJack F Vogel device_printf(dev, 344661ae650dSJack F Vogel "Failed to remove %d/%d filters, aq error %d\n", 344761ae650dSJack F Vogel j - sc, j, hw->aq.asq_last_status); 344861ae650dSJack F Vogel } else 344961ae650dSJack F Vogel vsi->hw_filters_del += j; 345061ae650dSJack F Vogel } 345161ae650dSJack F Vogel free(d, M_DEVBUF); 345261ae650dSJack F Vogel 345361ae650dSJack F Vogel DEBUGOUT("ixl_del_hw_filters: end\n"); 345461ae650dSJack F Vogel return; 345561ae650dSJack F Vogel } 345661ae650dSJack F Vogel 345761ae650dSJack F Vogel 345861ae650dSJack F Vogel static void 345961ae650dSJack F Vogel ixl_enable_rings(struct ixl_vsi *vsi) 346061ae650dSJack F Vogel { 346161ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 346261ae650dSJack F Vogel u32 reg; 346361ae650dSJack F Vogel 346461ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++) { 346561ae650dSJack F Vogel i40e_pre_tx_queue_cfg(hw, i, TRUE); 346661ae650dSJack F Vogel 346761ae650dSJack F Vogel reg = rd32(hw, I40E_QTX_ENA(i)); 346861ae650dSJack F Vogel reg |= I40E_QTX_ENA_QENA_REQ_MASK | 346961ae650dSJack F Vogel I40E_QTX_ENA_QENA_STAT_MASK; 347061ae650dSJack F Vogel wr32(hw, I40E_QTX_ENA(i), reg); 347161ae650dSJack F Vogel /* Verify the enable took */ 347261ae650dSJack F Vogel for (int j = 0; j < 10; j++) { 347361ae650dSJack F Vogel reg = rd32(hw, I40E_QTX_ENA(i)); 347461ae650dSJack F Vogel if (reg & I40E_QTX_ENA_QENA_STAT_MASK) 347561ae650dSJack F Vogel break; 347661ae650dSJack F Vogel i40e_msec_delay(10); 347761ae650dSJack F Vogel } 347861ae650dSJack F Vogel if ((reg & I40E_QTX_ENA_QENA_STAT_MASK) == 0) 347961ae650dSJack F Vogel printf("TX queue %d disabled!\n", i); 348061ae650dSJack F Vogel 348161ae650dSJack F Vogel reg = rd32(hw, I40E_QRX_ENA(i)); 348261ae650dSJack F Vogel reg |= I40E_QRX_ENA_QENA_REQ_MASK | 348361ae650dSJack F Vogel I40E_QRX_ENA_QENA_STAT_MASK; 348461ae650dSJack F Vogel wr32(hw, I40E_QRX_ENA(i), reg); 348561ae650dSJack F Vogel /* Verify the enable took */ 348661ae650dSJack F Vogel for (int j = 0; j < 10; j++) { 348761ae650dSJack F Vogel reg = rd32(hw, I40E_QRX_ENA(i)); 348861ae650dSJack F Vogel if (reg & I40E_QRX_ENA_QENA_STAT_MASK) 348961ae650dSJack F Vogel break; 349061ae650dSJack F Vogel i40e_msec_delay(10); 349161ae650dSJack F Vogel } 349261ae650dSJack F Vogel if ((reg & I40E_QRX_ENA_QENA_STAT_MASK) == 0) 349361ae650dSJack F Vogel printf("RX queue %d disabled!\n", i); 349461ae650dSJack F Vogel } 349561ae650dSJack F Vogel } 349661ae650dSJack F Vogel 349761ae650dSJack F Vogel static void 349861ae650dSJack F Vogel ixl_disable_rings(struct ixl_vsi *vsi) 349961ae650dSJack F Vogel { 350061ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 350161ae650dSJack F Vogel u32 reg; 350261ae650dSJack F Vogel 350361ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++) { 350461ae650dSJack F Vogel i40e_pre_tx_queue_cfg(hw, i, FALSE); 350561ae650dSJack F Vogel i40e_usec_delay(500); 350661ae650dSJack F Vogel 350761ae650dSJack F Vogel reg = rd32(hw, I40E_QTX_ENA(i)); 350861ae650dSJack F Vogel reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; 350961ae650dSJack F Vogel wr32(hw, I40E_QTX_ENA(i), reg); 351061ae650dSJack F Vogel /* Verify the disable took */ 351161ae650dSJack F Vogel for (int j = 0; j < 10; j++) { 351261ae650dSJack F Vogel reg = rd32(hw, I40E_QTX_ENA(i)); 351361ae650dSJack F Vogel if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK)) 351461ae650dSJack F Vogel break; 351561ae650dSJack F Vogel i40e_msec_delay(10); 351661ae650dSJack F Vogel } 351761ae650dSJack F Vogel if (reg & I40E_QTX_ENA_QENA_STAT_MASK) 351861ae650dSJack F Vogel printf("TX queue %d still enabled!\n", i); 351961ae650dSJack F Vogel 352061ae650dSJack F Vogel reg = rd32(hw, I40E_QRX_ENA(i)); 352161ae650dSJack F Vogel reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; 352261ae650dSJack F Vogel wr32(hw, I40E_QRX_ENA(i), reg); 352361ae650dSJack F Vogel /* Verify the disable took */ 352461ae650dSJack F Vogel for (int j = 0; j < 10; j++) { 352561ae650dSJack F Vogel reg = rd32(hw, I40E_QRX_ENA(i)); 352661ae650dSJack F Vogel if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK)) 352761ae650dSJack F Vogel break; 352861ae650dSJack F Vogel i40e_msec_delay(10); 352961ae650dSJack F Vogel } 353061ae650dSJack F Vogel if (reg & I40E_QRX_ENA_QENA_STAT_MASK) 353161ae650dSJack F Vogel printf("RX queue %d still enabled!\n", i); 353261ae650dSJack F Vogel } 353361ae650dSJack F Vogel } 353461ae650dSJack F Vogel 353561ae650dSJack F Vogel /** 353661ae650dSJack F Vogel * ixl_handle_mdd_event 353761ae650dSJack F Vogel * 353861ae650dSJack F Vogel * Called from interrupt handler to identify possibly malicious vfs 353961ae650dSJack F Vogel * (But also detects events from the PF, as well) 354061ae650dSJack F Vogel **/ 354161ae650dSJack F Vogel static void ixl_handle_mdd_event(struct ixl_pf *pf) 354261ae650dSJack F Vogel { 354361ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 354461ae650dSJack F Vogel device_t dev = pf->dev; 354561ae650dSJack F Vogel bool mdd_detected = false; 354661ae650dSJack F Vogel bool pf_mdd_detected = false; 354761ae650dSJack F Vogel u32 reg; 354861ae650dSJack F Vogel 354961ae650dSJack F Vogel /* find what triggered the MDD event */ 355061ae650dSJack F Vogel reg = rd32(hw, I40E_GL_MDET_TX); 355161ae650dSJack F Vogel if (reg & I40E_GL_MDET_TX_VALID_MASK) { 355261ae650dSJack F Vogel u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> 355361ae650dSJack F Vogel I40E_GL_MDET_TX_PF_NUM_SHIFT; 355461ae650dSJack F Vogel u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> 355561ae650dSJack F Vogel I40E_GL_MDET_TX_EVENT_SHIFT; 355661ae650dSJack F Vogel u8 queue = (reg & I40E_GL_MDET_TX_QUEUE_MASK) >> 355761ae650dSJack F Vogel I40E_GL_MDET_TX_QUEUE_SHIFT; 355861ae650dSJack F Vogel device_printf(dev, 355961ae650dSJack F Vogel "Malicious Driver Detection event 0x%02x" 356061ae650dSJack F Vogel " on TX queue %d pf number 0x%02x\n", 356161ae650dSJack F Vogel event, queue, pf_num); 356261ae650dSJack F Vogel wr32(hw, I40E_GL_MDET_TX, 0xffffffff); 356361ae650dSJack F Vogel mdd_detected = true; 356461ae650dSJack F Vogel } 356561ae650dSJack F Vogel reg = rd32(hw, I40E_GL_MDET_RX); 356661ae650dSJack F Vogel if (reg & I40E_GL_MDET_RX_VALID_MASK) { 356761ae650dSJack F Vogel u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> 356861ae650dSJack F Vogel I40E_GL_MDET_RX_FUNCTION_SHIFT; 356961ae650dSJack F Vogel u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> 357061ae650dSJack F Vogel I40E_GL_MDET_RX_EVENT_SHIFT; 357161ae650dSJack F Vogel u8 queue = (reg & I40E_GL_MDET_RX_QUEUE_MASK) >> 357261ae650dSJack F Vogel I40E_GL_MDET_RX_QUEUE_SHIFT; 357361ae650dSJack F Vogel device_printf(dev, 357461ae650dSJack F Vogel "Malicious Driver Detection event 0x%02x" 357561ae650dSJack F Vogel " on RX queue %d of function 0x%02x\n", 357661ae650dSJack F Vogel event, queue, func); 357761ae650dSJack F Vogel wr32(hw, I40E_GL_MDET_RX, 0xffffffff); 357861ae650dSJack F Vogel mdd_detected = true; 357961ae650dSJack F Vogel } 358061ae650dSJack F Vogel 358161ae650dSJack F Vogel if (mdd_detected) { 358261ae650dSJack F Vogel reg = rd32(hw, I40E_PF_MDET_TX); 358361ae650dSJack F Vogel if (reg & I40E_PF_MDET_TX_VALID_MASK) { 358461ae650dSJack F Vogel wr32(hw, I40E_PF_MDET_TX, 0xFFFF); 358561ae650dSJack F Vogel device_printf(dev, 358661ae650dSJack F Vogel "MDD TX event is for this function 0x%08x", 358761ae650dSJack F Vogel reg); 358861ae650dSJack F Vogel pf_mdd_detected = true; 358961ae650dSJack F Vogel } 359061ae650dSJack F Vogel reg = rd32(hw, I40E_PF_MDET_RX); 359161ae650dSJack F Vogel if (reg & I40E_PF_MDET_RX_VALID_MASK) { 359261ae650dSJack F Vogel wr32(hw, I40E_PF_MDET_RX, 0xFFFF); 359361ae650dSJack F Vogel device_printf(dev, 359461ae650dSJack F Vogel "MDD RX event is for this function 0x%08x", 359561ae650dSJack F Vogel reg); 359661ae650dSJack F Vogel pf_mdd_detected = true; 359761ae650dSJack F Vogel } 359861ae650dSJack F Vogel } 359961ae650dSJack F Vogel 360061ae650dSJack F Vogel /* re-enable mdd interrupt cause */ 360161ae650dSJack F Vogel reg = rd32(hw, I40E_PFINT_ICR0_ENA); 360261ae650dSJack F Vogel reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; 360361ae650dSJack F Vogel wr32(hw, I40E_PFINT_ICR0_ENA, reg); 360461ae650dSJack F Vogel ixl_flush(hw); 360561ae650dSJack F Vogel } 360661ae650dSJack F Vogel 360761ae650dSJack F Vogel static void 360861ae650dSJack F Vogel ixl_enable_intr(struct ixl_vsi *vsi) 360961ae650dSJack F Vogel { 361061ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 361161ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 361261ae650dSJack F Vogel 361361ae650dSJack F Vogel if (ixl_enable_msix) { 361461ae650dSJack F Vogel ixl_enable_adminq(hw); 361561ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, que++) 361661ae650dSJack F Vogel ixl_enable_queue(hw, que->me); 361761ae650dSJack F Vogel } else 361861ae650dSJack F Vogel ixl_enable_legacy(hw); 361961ae650dSJack F Vogel } 362061ae650dSJack F Vogel 362161ae650dSJack F Vogel static void 362261ae650dSJack F Vogel ixl_disable_intr(struct ixl_vsi *vsi) 362361ae650dSJack F Vogel { 362461ae650dSJack F Vogel struct i40e_hw *hw = vsi->hw; 362561ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 362661ae650dSJack F Vogel 362761ae650dSJack F Vogel if (ixl_enable_msix) { 362861ae650dSJack F Vogel ixl_disable_adminq(hw); 362961ae650dSJack F Vogel for (int i = 0; i < vsi->num_queues; i++, que++) 363061ae650dSJack F Vogel ixl_disable_queue(hw, que->me); 363161ae650dSJack F Vogel } else 363261ae650dSJack F Vogel ixl_disable_legacy(hw); 363361ae650dSJack F Vogel } 363461ae650dSJack F Vogel 363561ae650dSJack F Vogel static void 363661ae650dSJack F Vogel ixl_enable_adminq(struct i40e_hw *hw) 363761ae650dSJack F Vogel { 363861ae650dSJack F Vogel u32 reg; 363961ae650dSJack F Vogel 364061ae650dSJack F Vogel reg = I40E_PFINT_DYN_CTL0_INTENA_MASK | 364161ae650dSJack F Vogel I40E_PFINT_DYN_CTL0_CLEARPBA_MASK | 364261ae650dSJack F Vogel (IXL_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); 364361ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTL0, reg); 364461ae650dSJack F Vogel ixl_flush(hw); 364561ae650dSJack F Vogel return; 364661ae650dSJack F Vogel } 364761ae650dSJack F Vogel 364861ae650dSJack F Vogel static void 364961ae650dSJack F Vogel ixl_disable_adminq(struct i40e_hw *hw) 365061ae650dSJack F Vogel { 365161ae650dSJack F Vogel u32 reg; 365261ae650dSJack F Vogel 365361ae650dSJack F Vogel reg = IXL_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT; 365461ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTL0, reg); 365561ae650dSJack F Vogel 365661ae650dSJack F Vogel return; 365761ae650dSJack F Vogel } 365861ae650dSJack F Vogel 365961ae650dSJack F Vogel static void 366061ae650dSJack F Vogel ixl_enable_queue(struct i40e_hw *hw, int id) 366161ae650dSJack F Vogel { 366261ae650dSJack F Vogel u32 reg; 366361ae650dSJack F Vogel 366461ae650dSJack F Vogel reg = I40E_PFINT_DYN_CTLN_INTENA_MASK | 366561ae650dSJack F Vogel I40E_PFINT_DYN_CTLN_CLEARPBA_MASK | 366661ae650dSJack F Vogel (IXL_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); 366761ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTLN(id), reg); 366861ae650dSJack F Vogel } 366961ae650dSJack F Vogel 367061ae650dSJack F Vogel static void 367161ae650dSJack F Vogel ixl_disable_queue(struct i40e_hw *hw, int id) 367261ae650dSJack F Vogel { 367361ae650dSJack F Vogel u32 reg; 367461ae650dSJack F Vogel 367561ae650dSJack F Vogel reg = IXL_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT; 367661ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTLN(id), reg); 367761ae650dSJack F Vogel 367861ae650dSJack F Vogel return; 367961ae650dSJack F Vogel } 368061ae650dSJack F Vogel 368161ae650dSJack F Vogel static void 368261ae650dSJack F Vogel ixl_enable_legacy(struct i40e_hw *hw) 368361ae650dSJack F Vogel { 368461ae650dSJack F Vogel u32 reg; 368561ae650dSJack F Vogel reg = I40E_PFINT_DYN_CTL0_INTENA_MASK | 368661ae650dSJack F Vogel I40E_PFINT_DYN_CTL0_CLEARPBA_MASK | 368761ae650dSJack F Vogel (IXL_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); 368861ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTL0, reg); 368961ae650dSJack F Vogel } 369061ae650dSJack F Vogel 369161ae650dSJack F Vogel static void 369261ae650dSJack F Vogel ixl_disable_legacy(struct i40e_hw *hw) 369361ae650dSJack F Vogel { 369461ae650dSJack F Vogel u32 reg; 369561ae650dSJack F Vogel 369661ae650dSJack F Vogel reg = IXL_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT; 369761ae650dSJack F Vogel wr32(hw, I40E_PFINT_DYN_CTL0, reg); 369861ae650dSJack F Vogel 369961ae650dSJack F Vogel return; 370061ae650dSJack F Vogel } 370161ae650dSJack F Vogel 370261ae650dSJack F Vogel static void 370361ae650dSJack F Vogel ixl_update_stats_counters(struct ixl_pf *pf) 370461ae650dSJack F Vogel { 370561ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 370661ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 370761ae650dSJack F Vogel 370861ae650dSJack F Vogel struct i40e_hw_port_stats *nsd = &pf->stats; 370961ae650dSJack F Vogel struct i40e_hw_port_stats *osd = &pf->stats_offsets; 371061ae650dSJack F Vogel 371161ae650dSJack F Vogel /* Update hw stats */ 371261ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), 371361ae650dSJack F Vogel pf->stat_offsets_loaded, 371461ae650dSJack F Vogel &osd->crc_errors, &nsd->crc_errors); 371561ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), 371661ae650dSJack F Vogel pf->stat_offsets_loaded, 371761ae650dSJack F Vogel &osd->illegal_bytes, &nsd->illegal_bytes); 371861ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), 371961ae650dSJack F Vogel I40E_GLPRT_GORCL(hw->port), 372061ae650dSJack F Vogel pf->stat_offsets_loaded, 372161ae650dSJack F Vogel &osd->eth.rx_bytes, &nsd->eth.rx_bytes); 372261ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), 372361ae650dSJack F Vogel I40E_GLPRT_GOTCL(hw->port), 372461ae650dSJack F Vogel pf->stat_offsets_loaded, 372561ae650dSJack F Vogel &osd->eth.tx_bytes, &nsd->eth.tx_bytes); 372661ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), 372761ae650dSJack F Vogel pf->stat_offsets_loaded, 372861ae650dSJack F Vogel &osd->eth.rx_discards, 372961ae650dSJack F Vogel &nsd->eth.rx_discards); 373061ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_TDPC(hw->port), 373161ae650dSJack F Vogel pf->stat_offsets_loaded, 373261ae650dSJack F Vogel &osd->eth.tx_discards, 373361ae650dSJack F Vogel &nsd->eth.tx_discards); 373461ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), 373561ae650dSJack F Vogel I40E_GLPRT_UPRCL(hw->port), 373661ae650dSJack F Vogel pf->stat_offsets_loaded, 373761ae650dSJack F Vogel &osd->eth.rx_unicast, 373861ae650dSJack F Vogel &nsd->eth.rx_unicast); 373961ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), 374061ae650dSJack F Vogel I40E_GLPRT_UPTCL(hw->port), 374161ae650dSJack F Vogel pf->stat_offsets_loaded, 374261ae650dSJack F Vogel &osd->eth.tx_unicast, 374361ae650dSJack F Vogel &nsd->eth.tx_unicast); 374461ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), 374561ae650dSJack F Vogel I40E_GLPRT_MPRCL(hw->port), 374661ae650dSJack F Vogel pf->stat_offsets_loaded, 374761ae650dSJack F Vogel &osd->eth.rx_multicast, 374861ae650dSJack F Vogel &nsd->eth.rx_multicast); 374961ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), 375061ae650dSJack F Vogel I40E_GLPRT_MPTCL(hw->port), 375161ae650dSJack F Vogel pf->stat_offsets_loaded, 375261ae650dSJack F Vogel &osd->eth.tx_multicast, 375361ae650dSJack F Vogel &nsd->eth.tx_multicast); 375461ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), 375561ae650dSJack F Vogel I40E_GLPRT_BPRCL(hw->port), 375661ae650dSJack F Vogel pf->stat_offsets_loaded, 375761ae650dSJack F Vogel &osd->eth.rx_broadcast, 375861ae650dSJack F Vogel &nsd->eth.rx_broadcast); 375961ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), 376061ae650dSJack F Vogel I40E_GLPRT_BPTCL(hw->port), 376161ae650dSJack F Vogel pf->stat_offsets_loaded, 376261ae650dSJack F Vogel &osd->eth.tx_broadcast, 376361ae650dSJack F Vogel &nsd->eth.tx_broadcast); 376461ae650dSJack F Vogel 376561ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), 376661ae650dSJack F Vogel pf->stat_offsets_loaded, 376761ae650dSJack F Vogel &osd->tx_dropped_link_down, 376861ae650dSJack F Vogel &nsd->tx_dropped_link_down); 376961ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), 377061ae650dSJack F Vogel pf->stat_offsets_loaded, 377161ae650dSJack F Vogel &osd->mac_local_faults, 377261ae650dSJack F Vogel &nsd->mac_local_faults); 377361ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), 377461ae650dSJack F Vogel pf->stat_offsets_loaded, 377561ae650dSJack F Vogel &osd->mac_remote_faults, 377661ae650dSJack F Vogel &nsd->mac_remote_faults); 377761ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), 377861ae650dSJack F Vogel pf->stat_offsets_loaded, 377961ae650dSJack F Vogel &osd->rx_length_errors, 378061ae650dSJack F Vogel &nsd->rx_length_errors); 378161ae650dSJack F Vogel 378261ae650dSJack F Vogel /* Flow control (LFC) stats */ 378361ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), 378461ae650dSJack F Vogel pf->stat_offsets_loaded, 378561ae650dSJack F Vogel &osd->link_xon_rx, &nsd->link_xon_rx); 378661ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), 378761ae650dSJack F Vogel pf->stat_offsets_loaded, 378861ae650dSJack F Vogel &osd->link_xon_tx, &nsd->link_xon_tx); 378961ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), 379061ae650dSJack F Vogel pf->stat_offsets_loaded, 379161ae650dSJack F Vogel &osd->link_xoff_rx, &nsd->link_xoff_rx); 379261ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), 379361ae650dSJack F Vogel pf->stat_offsets_loaded, 379461ae650dSJack F Vogel &osd->link_xoff_tx, &nsd->link_xoff_tx); 379561ae650dSJack F Vogel 379661ae650dSJack F Vogel /* Priority flow control stats */ 379761ae650dSJack F Vogel #if 0 379861ae650dSJack F Vogel for (int i = 0; i < 8; i++) { 379961ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), 380061ae650dSJack F Vogel pf->stat_offsets_loaded, 380161ae650dSJack F Vogel &osd->priority_xon_rx[i], 380261ae650dSJack F Vogel &nsd->priority_xon_rx[i]); 380361ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), 380461ae650dSJack F Vogel pf->stat_offsets_loaded, 380561ae650dSJack F Vogel &osd->priority_xon_tx[i], 380661ae650dSJack F Vogel &nsd->priority_xon_tx[i]); 380761ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), 380861ae650dSJack F Vogel pf->stat_offsets_loaded, 380961ae650dSJack F Vogel &osd->priority_xoff_tx[i], 381061ae650dSJack F Vogel &nsd->priority_xoff_tx[i]); 381161ae650dSJack F Vogel ixl_stat_update32(hw, 381261ae650dSJack F Vogel I40E_GLPRT_RXON2OFFCNT(hw->port, i), 381361ae650dSJack F Vogel pf->stat_offsets_loaded, 381461ae650dSJack F Vogel &osd->priority_xon_2_xoff[i], 381561ae650dSJack F Vogel &nsd->priority_xon_2_xoff[i]); 381661ae650dSJack F Vogel } 381761ae650dSJack F Vogel #endif 381861ae650dSJack F Vogel 381961ae650dSJack F Vogel /* Packet size stats rx */ 382061ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), 382161ae650dSJack F Vogel I40E_GLPRT_PRC64L(hw->port), 382261ae650dSJack F Vogel pf->stat_offsets_loaded, 382361ae650dSJack F Vogel &osd->rx_size_64, &nsd->rx_size_64); 382461ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), 382561ae650dSJack F Vogel I40E_GLPRT_PRC127L(hw->port), 382661ae650dSJack F Vogel pf->stat_offsets_loaded, 382761ae650dSJack F Vogel &osd->rx_size_127, &nsd->rx_size_127); 382861ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), 382961ae650dSJack F Vogel I40E_GLPRT_PRC255L(hw->port), 383061ae650dSJack F Vogel pf->stat_offsets_loaded, 383161ae650dSJack F Vogel &osd->rx_size_255, &nsd->rx_size_255); 383261ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), 383361ae650dSJack F Vogel I40E_GLPRT_PRC511L(hw->port), 383461ae650dSJack F Vogel pf->stat_offsets_loaded, 383561ae650dSJack F Vogel &osd->rx_size_511, &nsd->rx_size_511); 383661ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), 383761ae650dSJack F Vogel I40E_GLPRT_PRC1023L(hw->port), 383861ae650dSJack F Vogel pf->stat_offsets_loaded, 383961ae650dSJack F Vogel &osd->rx_size_1023, &nsd->rx_size_1023); 384061ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), 384161ae650dSJack F Vogel I40E_GLPRT_PRC1522L(hw->port), 384261ae650dSJack F Vogel pf->stat_offsets_loaded, 384361ae650dSJack F Vogel &osd->rx_size_1522, &nsd->rx_size_1522); 384461ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), 384561ae650dSJack F Vogel I40E_GLPRT_PRC9522L(hw->port), 384661ae650dSJack F Vogel pf->stat_offsets_loaded, 384761ae650dSJack F Vogel &osd->rx_size_big, &nsd->rx_size_big); 384861ae650dSJack F Vogel 384961ae650dSJack F Vogel /* Packet size stats tx */ 385061ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), 385161ae650dSJack F Vogel I40E_GLPRT_PTC64L(hw->port), 385261ae650dSJack F Vogel pf->stat_offsets_loaded, 385361ae650dSJack F Vogel &osd->tx_size_64, &nsd->tx_size_64); 385461ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), 385561ae650dSJack F Vogel I40E_GLPRT_PTC127L(hw->port), 385661ae650dSJack F Vogel pf->stat_offsets_loaded, 385761ae650dSJack F Vogel &osd->tx_size_127, &nsd->tx_size_127); 385861ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), 385961ae650dSJack F Vogel I40E_GLPRT_PTC255L(hw->port), 386061ae650dSJack F Vogel pf->stat_offsets_loaded, 386161ae650dSJack F Vogel &osd->tx_size_255, &nsd->tx_size_255); 386261ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), 386361ae650dSJack F Vogel I40E_GLPRT_PTC511L(hw->port), 386461ae650dSJack F Vogel pf->stat_offsets_loaded, 386561ae650dSJack F Vogel &osd->tx_size_511, &nsd->tx_size_511); 386661ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), 386761ae650dSJack F Vogel I40E_GLPRT_PTC1023L(hw->port), 386861ae650dSJack F Vogel pf->stat_offsets_loaded, 386961ae650dSJack F Vogel &osd->tx_size_1023, &nsd->tx_size_1023); 387061ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), 387161ae650dSJack F Vogel I40E_GLPRT_PTC1522L(hw->port), 387261ae650dSJack F Vogel pf->stat_offsets_loaded, 387361ae650dSJack F Vogel &osd->tx_size_1522, &nsd->tx_size_1522); 387461ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), 387561ae650dSJack F Vogel I40E_GLPRT_PTC9522L(hw->port), 387661ae650dSJack F Vogel pf->stat_offsets_loaded, 387761ae650dSJack F Vogel &osd->tx_size_big, &nsd->tx_size_big); 387861ae650dSJack F Vogel 387961ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_RUC(hw->port), 388061ae650dSJack F Vogel pf->stat_offsets_loaded, 388161ae650dSJack F Vogel &osd->rx_undersize, &nsd->rx_undersize); 388261ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_RFC(hw->port), 388361ae650dSJack F Vogel pf->stat_offsets_loaded, 388461ae650dSJack F Vogel &osd->rx_fragments, &nsd->rx_fragments); 388561ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_ROC(hw->port), 388661ae650dSJack F Vogel pf->stat_offsets_loaded, 388761ae650dSJack F Vogel &osd->rx_oversize, &nsd->rx_oversize); 388861ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLPRT_RJC(hw->port), 388961ae650dSJack F Vogel pf->stat_offsets_loaded, 389061ae650dSJack F Vogel &osd->rx_jabber, &nsd->rx_jabber); 389161ae650dSJack F Vogel pf->stat_offsets_loaded = true; 389261ae650dSJack F Vogel /* End hw stats */ 389361ae650dSJack F Vogel 389461ae650dSJack F Vogel /* Update vsi stats */ 389561ae650dSJack F Vogel ixl_update_eth_stats(vsi); 389661ae650dSJack F Vogel 389761ae650dSJack F Vogel /* OS statistics */ 389861ae650dSJack F Vogel // ERJ - these are per-port, update all vsis? 3899*4b443922SGleb Smirnoff IXL_SET_IERRORS(vsi, nsd->crc_errors + nsd->illegal_bytes); 390061ae650dSJack F Vogel } 390161ae650dSJack F Vogel 390261ae650dSJack F Vogel /* 390361ae650dSJack F Vogel ** Tasklet handler for MSIX Adminq interrupts 390461ae650dSJack F Vogel ** - do outside interrupt since it might sleep 390561ae650dSJack F Vogel */ 390661ae650dSJack F Vogel static void 390761ae650dSJack F Vogel ixl_do_adminq(void *context, int pending) 390861ae650dSJack F Vogel { 390961ae650dSJack F Vogel struct ixl_pf *pf = context; 391061ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 391161ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 391261ae650dSJack F Vogel struct i40e_arq_event_info event; 391361ae650dSJack F Vogel i40e_status ret; 391461ae650dSJack F Vogel u32 reg, loop = 0; 391561ae650dSJack F Vogel u16 opcode, result; 391661ae650dSJack F Vogel 391761ae650dSJack F Vogel event.msg_len = IXL_AQ_BUF_SZ; 391861ae650dSJack F Vogel event.msg_buf = malloc(event.msg_len, 391961ae650dSJack F Vogel M_DEVBUF, M_NOWAIT | M_ZERO); 392061ae650dSJack F Vogel if (!event.msg_buf) { 392161ae650dSJack F Vogel printf("Unable to allocate adminq memory\n"); 392261ae650dSJack F Vogel return; 392361ae650dSJack F Vogel } 392461ae650dSJack F Vogel 392561ae650dSJack F Vogel /* clean and process any events */ 392661ae650dSJack F Vogel do { 392761ae650dSJack F Vogel ret = i40e_clean_arq_element(hw, &event, &result); 392861ae650dSJack F Vogel if (ret) 392961ae650dSJack F Vogel break; 393061ae650dSJack F Vogel opcode = LE16_TO_CPU(event.desc.opcode); 393161ae650dSJack F Vogel switch (opcode) { 393261ae650dSJack F Vogel case i40e_aqc_opc_get_link_status: 393361ae650dSJack F Vogel vsi->link_up = ixl_config_link(hw); 393461ae650dSJack F Vogel ixl_update_link_status(pf); 393561ae650dSJack F Vogel break; 393661ae650dSJack F Vogel case i40e_aqc_opc_send_msg_to_pf: 393761ae650dSJack F Vogel /* process pf/vf communication here */ 393861ae650dSJack F Vogel break; 393961ae650dSJack F Vogel case i40e_aqc_opc_event_lan_overflow: 394061ae650dSJack F Vogel break; 394161ae650dSJack F Vogel default: 394261ae650dSJack F Vogel #ifdef IXL_DEBUG 394361ae650dSJack F Vogel printf("AdminQ unknown event %x\n", opcode); 394461ae650dSJack F Vogel #endif 394561ae650dSJack F Vogel break; 394661ae650dSJack F Vogel } 394761ae650dSJack F Vogel 394861ae650dSJack F Vogel } while (result && (loop++ < IXL_ADM_LIMIT)); 394961ae650dSJack F Vogel 395061ae650dSJack F Vogel reg = rd32(hw, I40E_PFINT_ICR0_ENA); 395161ae650dSJack F Vogel reg |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; 395261ae650dSJack F Vogel wr32(hw, I40E_PFINT_ICR0_ENA, reg); 395361ae650dSJack F Vogel free(event.msg_buf, M_DEVBUF); 395461ae650dSJack F Vogel 395561ae650dSJack F Vogel if (pf->msix > 1) 395661ae650dSJack F Vogel ixl_enable_adminq(&pf->hw); 395761ae650dSJack F Vogel else 395861ae650dSJack F Vogel ixl_enable_intr(vsi); 395961ae650dSJack F Vogel } 396061ae650dSJack F Vogel 396161ae650dSJack F Vogel static int 396261ae650dSJack F Vogel ixl_debug_info(SYSCTL_HANDLER_ARGS) 396361ae650dSJack F Vogel { 396461ae650dSJack F Vogel struct ixl_pf *pf; 396561ae650dSJack F Vogel int error, input = 0; 396661ae650dSJack F Vogel 396761ae650dSJack F Vogel error = sysctl_handle_int(oidp, &input, 0, req); 396861ae650dSJack F Vogel 396961ae650dSJack F Vogel if (error || !req->newptr) 397061ae650dSJack F Vogel return (error); 397161ae650dSJack F Vogel 397261ae650dSJack F Vogel if (input == 1) { 397361ae650dSJack F Vogel pf = (struct ixl_pf *)arg1; 397461ae650dSJack F Vogel ixl_print_debug_info(pf); 397561ae650dSJack F Vogel } 397661ae650dSJack F Vogel 397761ae650dSJack F Vogel return (error); 397861ae650dSJack F Vogel } 397961ae650dSJack F Vogel 398061ae650dSJack F Vogel static void 398161ae650dSJack F Vogel ixl_print_debug_info(struct ixl_pf *pf) 398261ae650dSJack F Vogel { 398361ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 398461ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 398561ae650dSJack F Vogel struct ixl_queue *que = vsi->queues; 398661ae650dSJack F Vogel struct rx_ring *rxr = &que->rxr; 398761ae650dSJack F Vogel struct tx_ring *txr = &que->txr; 398861ae650dSJack F Vogel u32 reg; 398961ae650dSJack F Vogel 399061ae650dSJack F Vogel 3991ff21e856SBjoern A. Zeeb printf("Queue irqs = %jx\n", (uintmax_t)que->irqs); 3992ff21e856SBjoern A. Zeeb printf("AdminQ irqs = %jx\n", (uintmax_t)pf->admin_irq); 399361ae650dSJack F Vogel printf("RX next check = %x\n", rxr->next_check); 3994ff21e856SBjoern A. Zeeb printf("RX not ready = %jx\n", (uintmax_t)rxr->not_done); 3995ff21e856SBjoern A. Zeeb printf("RX packets = %jx\n", (uintmax_t)rxr->rx_packets); 399661ae650dSJack F Vogel printf("TX desc avail = %x\n", txr->avail); 399761ae650dSJack F Vogel 399861ae650dSJack F Vogel reg = rd32(hw, I40E_GLV_GORCL(0xc)); 399961ae650dSJack F Vogel printf("RX Bytes = %x\n", reg); 400061ae650dSJack F Vogel reg = rd32(hw, I40E_GLPRT_GORCL(hw->port)); 400161ae650dSJack F Vogel printf("Port RX Bytes = %x\n", reg); 400261ae650dSJack F Vogel reg = rd32(hw, I40E_GLV_RDPC(0xc)); 400361ae650dSJack F Vogel printf("RX discard = %x\n", reg); 400461ae650dSJack F Vogel reg = rd32(hw, I40E_GLPRT_RDPC(hw->port)); 400561ae650dSJack F Vogel printf("Port RX discard = %x\n", reg); 400661ae650dSJack F Vogel 400761ae650dSJack F Vogel reg = rd32(hw, I40E_GLV_TEPC(0xc)); 400861ae650dSJack F Vogel printf("TX errors = %x\n", reg); 400961ae650dSJack F Vogel reg = rd32(hw, I40E_GLV_GOTCL(0xc)); 401061ae650dSJack F Vogel printf("TX Bytes = %x\n", reg); 401161ae650dSJack F Vogel 401261ae650dSJack F Vogel reg = rd32(hw, I40E_GLPRT_RUC(hw->port)); 401361ae650dSJack F Vogel printf("RX undersize = %x\n", reg); 401461ae650dSJack F Vogel reg = rd32(hw, I40E_GLPRT_RFC(hw->port)); 401561ae650dSJack F Vogel printf("RX fragments = %x\n", reg); 401661ae650dSJack F Vogel reg = rd32(hw, I40E_GLPRT_ROC(hw->port)); 401761ae650dSJack F Vogel printf("RX oversize = %x\n", reg); 401861ae650dSJack F Vogel reg = rd32(hw, I40E_GLPRT_RLEC(hw->port)); 401961ae650dSJack F Vogel printf("RX length error = %x\n", reg); 402061ae650dSJack F Vogel reg = rd32(hw, I40E_GLPRT_MRFC(hw->port)); 402161ae650dSJack F Vogel printf("mac remote fault = %x\n", reg); 402261ae650dSJack F Vogel reg = rd32(hw, I40E_GLPRT_MLFC(hw->port)); 402361ae650dSJack F Vogel printf("mac local fault = %x\n", reg); 402461ae650dSJack F Vogel } 402561ae650dSJack F Vogel 402661ae650dSJack F Vogel /** 402761ae650dSJack F Vogel * Update VSI-specific ethernet statistics counters. 402861ae650dSJack F Vogel **/ 402961ae650dSJack F Vogel void ixl_update_eth_stats(struct ixl_vsi *vsi) 403061ae650dSJack F Vogel { 403161ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)vsi->back; 403261ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 403361ae650dSJack F Vogel struct i40e_eth_stats *es; 403461ae650dSJack F Vogel struct i40e_eth_stats *oes; 4035*4b443922SGleb Smirnoff int i; 4036*4b443922SGleb Smirnoff uint64_t tx_discards; 4037*4b443922SGleb Smirnoff struct i40e_hw_port_stats *nsd; 403861ae650dSJack F Vogel u16 stat_idx = vsi->info.stat_counter_idx; 403961ae650dSJack F Vogel 404061ae650dSJack F Vogel es = &vsi->eth_stats; 404161ae650dSJack F Vogel oes = &vsi->eth_stats_offsets; 4042*4b443922SGleb Smirnoff nsd = &pf->stats; 404361ae650dSJack F Vogel 404461ae650dSJack F Vogel /* Gather up the stats that the hw collects */ 404561ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLV_TEPC(stat_idx), 404661ae650dSJack F Vogel vsi->stat_offsets_loaded, 404761ae650dSJack F Vogel &oes->tx_errors, &es->tx_errors); 404861ae650dSJack F Vogel ixl_stat_update32(hw, I40E_GLV_RDPC(stat_idx), 404961ae650dSJack F Vogel vsi->stat_offsets_loaded, 405061ae650dSJack F Vogel &oes->rx_discards, &es->rx_discards); 405161ae650dSJack F Vogel 405261ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLV_GORCH(stat_idx), 405361ae650dSJack F Vogel I40E_GLV_GORCL(stat_idx), 405461ae650dSJack F Vogel vsi->stat_offsets_loaded, 405561ae650dSJack F Vogel &oes->rx_bytes, &es->rx_bytes); 405661ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), 405761ae650dSJack F Vogel I40E_GLV_UPRCL(stat_idx), 405861ae650dSJack F Vogel vsi->stat_offsets_loaded, 405961ae650dSJack F Vogel &oes->rx_unicast, &es->rx_unicast); 406061ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), 406161ae650dSJack F Vogel I40E_GLV_MPRCL(stat_idx), 406261ae650dSJack F Vogel vsi->stat_offsets_loaded, 406361ae650dSJack F Vogel &oes->rx_multicast, &es->rx_multicast); 406461ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), 406561ae650dSJack F Vogel I40E_GLV_BPRCL(stat_idx), 406661ae650dSJack F Vogel vsi->stat_offsets_loaded, 406761ae650dSJack F Vogel &oes->rx_broadcast, &es->rx_broadcast); 406861ae650dSJack F Vogel 406961ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), 407061ae650dSJack F Vogel I40E_GLV_GOTCL(stat_idx), 407161ae650dSJack F Vogel vsi->stat_offsets_loaded, 407261ae650dSJack F Vogel &oes->tx_bytes, &es->tx_bytes); 407361ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), 407461ae650dSJack F Vogel I40E_GLV_UPTCL(stat_idx), 407561ae650dSJack F Vogel vsi->stat_offsets_loaded, 407661ae650dSJack F Vogel &oes->tx_unicast, &es->tx_unicast); 407761ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), 407861ae650dSJack F Vogel I40E_GLV_MPTCL(stat_idx), 407961ae650dSJack F Vogel vsi->stat_offsets_loaded, 408061ae650dSJack F Vogel &oes->tx_multicast, &es->tx_multicast); 408161ae650dSJack F Vogel ixl_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), 408261ae650dSJack F Vogel I40E_GLV_BPTCL(stat_idx), 408361ae650dSJack F Vogel vsi->stat_offsets_loaded, 408461ae650dSJack F Vogel &oes->tx_broadcast, &es->tx_broadcast); 408561ae650dSJack F Vogel vsi->stat_offsets_loaded = true; 408661ae650dSJack F Vogel 4087*4b443922SGleb Smirnoff tx_discards = es->tx_discards + nsd->tx_dropped_link_down; 4088*4b443922SGleb Smirnoff for (i = 0; i < vsi->num_queues; i++) 4089*4b443922SGleb Smirnoff tx_discards += vsi->queues[i].txr.br->br_drops; 409061ae650dSJack F Vogel 4091*4b443922SGleb Smirnoff /* Update ifnet stats */ 4092*4b443922SGleb Smirnoff IXL_SET_IPACKETS(vsi, es->rx_unicast + 4093*4b443922SGleb Smirnoff es->rx_multicast + 4094*4b443922SGleb Smirnoff es->rx_broadcast); 4095*4b443922SGleb Smirnoff IXL_SET_OPACKETS(vsi, es->tx_unicast + 4096*4b443922SGleb Smirnoff es->tx_multicast + 4097*4b443922SGleb Smirnoff es->tx_broadcast); 4098*4b443922SGleb Smirnoff IXL_SET_IBYTES(vsi, es->rx_bytes); 4099*4b443922SGleb Smirnoff IXL_SET_OBYTES(vsi, es->tx_bytes); 4100*4b443922SGleb Smirnoff IXL_SET_IMCASTS(vsi, es->rx_multicast); 4101*4b443922SGleb Smirnoff IXL_SET_OMCASTS(vsi, es->tx_multicast); 4102*4b443922SGleb Smirnoff 4103*4b443922SGleb Smirnoff IXL_SET_OERRORS(vsi, es->tx_errors); 4104*4b443922SGleb Smirnoff IXL_SET_IQDROPS(vsi, es->rx_discards + nsd->eth.rx_discards); 4105*4b443922SGleb Smirnoff IXL_SET_OQDROPS(vsi, tx_discards); 4106*4b443922SGleb Smirnoff IXL_SET_NOPROTO(vsi, es->rx_unknown_protocol); 4107*4b443922SGleb Smirnoff IXL_SET_COLLISIONS(vsi, 0); 410861ae650dSJack F Vogel } 410961ae650dSJack F Vogel 411061ae650dSJack F Vogel /** 411161ae650dSJack F Vogel * Reset all of the stats for the given pf 411261ae650dSJack F Vogel **/ 411361ae650dSJack F Vogel void ixl_pf_reset_stats(struct ixl_pf *pf) 411461ae650dSJack F Vogel { 411561ae650dSJack F Vogel bzero(&pf->stats, sizeof(struct i40e_hw_port_stats)); 411661ae650dSJack F Vogel bzero(&pf->stats_offsets, sizeof(struct i40e_hw_port_stats)); 411761ae650dSJack F Vogel pf->stat_offsets_loaded = false; 411861ae650dSJack F Vogel } 411961ae650dSJack F Vogel 412061ae650dSJack F Vogel /** 412161ae650dSJack F Vogel * Resets all stats of the given vsi 412261ae650dSJack F Vogel **/ 412361ae650dSJack F Vogel void ixl_vsi_reset_stats(struct ixl_vsi *vsi) 412461ae650dSJack F Vogel { 412561ae650dSJack F Vogel bzero(&vsi->eth_stats, sizeof(struct i40e_eth_stats)); 412661ae650dSJack F Vogel bzero(&vsi->eth_stats_offsets, sizeof(struct i40e_eth_stats)); 412761ae650dSJack F Vogel vsi->stat_offsets_loaded = false; 412861ae650dSJack F Vogel } 412961ae650dSJack F Vogel 413061ae650dSJack F Vogel /** 413161ae650dSJack F Vogel * Read and update a 48 bit stat from the hw 413261ae650dSJack F Vogel * 413361ae650dSJack F Vogel * Since the device stats are not reset at PFReset, they likely will not 413461ae650dSJack F Vogel * be zeroed when the driver starts. We'll save the first values read 413561ae650dSJack F Vogel * and use them as offsets to be subtracted from the raw values in order 413661ae650dSJack F Vogel * to report stats that count from zero. 413761ae650dSJack F Vogel **/ 413861ae650dSJack F Vogel static void 413961ae650dSJack F Vogel ixl_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, 414061ae650dSJack F Vogel bool offset_loaded, u64 *offset, u64 *stat) 414161ae650dSJack F Vogel { 414261ae650dSJack F Vogel u64 new_data; 414361ae650dSJack F Vogel 4144ff21e856SBjoern A. Zeeb #if defined(__FreeBSD__) && (__FreeBSD_version >= 1000000) && defined(__amd64__) 414561ae650dSJack F Vogel new_data = rd64(hw, loreg); 414661ae650dSJack F Vogel #else 414761ae650dSJack F Vogel /* 414861ae650dSJack F Vogel * Use two rd32's instead of one rd64; FreeBSD versions before 414961ae650dSJack F Vogel * 10 don't support 8 byte bus reads/writes. 415061ae650dSJack F Vogel */ 415161ae650dSJack F Vogel new_data = rd32(hw, loreg); 415261ae650dSJack F Vogel new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; 415361ae650dSJack F Vogel #endif 415461ae650dSJack F Vogel 415561ae650dSJack F Vogel if (!offset_loaded) 415661ae650dSJack F Vogel *offset = new_data; 415761ae650dSJack F Vogel if (new_data >= *offset) 415861ae650dSJack F Vogel *stat = new_data - *offset; 415961ae650dSJack F Vogel else 416061ae650dSJack F Vogel *stat = (new_data + ((u64)1 << 48)) - *offset; 416161ae650dSJack F Vogel *stat &= 0xFFFFFFFFFFFFULL; 416261ae650dSJack F Vogel } 416361ae650dSJack F Vogel 416461ae650dSJack F Vogel /** 416561ae650dSJack F Vogel * Read and update a 32 bit stat from the hw 416661ae650dSJack F Vogel **/ 416761ae650dSJack F Vogel static void 416861ae650dSJack F Vogel ixl_stat_update32(struct i40e_hw *hw, u32 reg, 416961ae650dSJack F Vogel bool offset_loaded, u64 *offset, u64 *stat) 417061ae650dSJack F Vogel { 417161ae650dSJack F Vogel u32 new_data; 417261ae650dSJack F Vogel 417361ae650dSJack F Vogel new_data = rd32(hw, reg); 417461ae650dSJack F Vogel if (!offset_loaded) 417561ae650dSJack F Vogel *offset = new_data; 417661ae650dSJack F Vogel if (new_data >= *offset) 417761ae650dSJack F Vogel *stat = (u32)(new_data - *offset); 417861ae650dSJack F Vogel else 417961ae650dSJack F Vogel *stat = (u32)((new_data + ((u64)1 << 32)) - *offset); 418061ae650dSJack F Vogel } 418161ae650dSJack F Vogel 418261ae650dSJack F Vogel /* 418361ae650dSJack F Vogel ** Set flow control using sysctl: 418461ae650dSJack F Vogel ** 0 - off 418561ae650dSJack F Vogel ** 1 - rx pause 418661ae650dSJack F Vogel ** 2 - tx pause 418761ae650dSJack F Vogel ** 3 - full 418861ae650dSJack F Vogel */ 418961ae650dSJack F Vogel static int 419061ae650dSJack F Vogel ixl_set_flowcntl(SYSCTL_HANDLER_ARGS) 419161ae650dSJack F Vogel { 419261ae650dSJack F Vogel /* 419361ae650dSJack F Vogel * TODO: ensure flow control is disabled if 419461ae650dSJack F Vogel * priority flow control is enabled 419561ae650dSJack F Vogel * 419661ae650dSJack F Vogel * TODO: ensure tx CRC by hardware should be enabled 419761ae650dSJack F Vogel * if tx flow control is enabled. 419861ae650dSJack F Vogel */ 419961ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 420061ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 420161ae650dSJack F Vogel device_t dev = pf->dev; 420261ae650dSJack F Vogel int requested_fc = 0, error = 0; 420361ae650dSJack F Vogel enum i40e_status_code aq_error = 0; 420461ae650dSJack F Vogel u8 fc_aq_err = 0; 420561ae650dSJack F Vogel 420661ae650dSJack F Vogel aq_error = i40e_aq_get_link_info(hw, TRUE, NULL, NULL); 420761ae650dSJack F Vogel if (aq_error) { 420861ae650dSJack F Vogel device_printf(dev, 420961ae650dSJack F Vogel "%s: Error retrieving link info from aq, %d\n", 421061ae650dSJack F Vogel __func__, aq_error); 421161ae650dSJack F Vogel return (EAGAIN); 421261ae650dSJack F Vogel } 421361ae650dSJack F Vogel 421461ae650dSJack F Vogel /* Read in new mode */ 421561ae650dSJack F Vogel requested_fc = hw->fc.current_mode; 421661ae650dSJack F Vogel error = sysctl_handle_int(oidp, &requested_fc, 0, req); 421761ae650dSJack F Vogel if ((error) || (req->newptr == NULL)) 421861ae650dSJack F Vogel return (error); 421961ae650dSJack F Vogel if (requested_fc < 0 || requested_fc > 3) { 422061ae650dSJack F Vogel device_printf(dev, 422161ae650dSJack F Vogel "Invalid fc mode; valid modes are 0 through 3\n"); 422261ae650dSJack F Vogel return (EINVAL); 422361ae650dSJack F Vogel } 422461ae650dSJack F Vogel 422561ae650dSJack F Vogel /* 422661ae650dSJack F Vogel ** Changing flow control mode currently does not work on 422761ae650dSJack F Vogel ** 40GBASE-CR4 PHYs 422861ae650dSJack F Vogel */ 422961ae650dSJack F Vogel if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_40GBASE_CR4 423061ae650dSJack F Vogel || hw->phy.link_info.phy_type == I40E_PHY_TYPE_40GBASE_CR4_CU) { 423161ae650dSJack F Vogel device_printf(dev, "Changing flow control mode unsupported" 423261ae650dSJack F Vogel " on 40GBase-CR4 media.\n"); 423361ae650dSJack F Vogel return (ENODEV); 423461ae650dSJack F Vogel } 423561ae650dSJack F Vogel 423661ae650dSJack F Vogel /* Set fc ability for port */ 423761ae650dSJack F Vogel hw->fc.requested_mode = requested_fc; 423861ae650dSJack F Vogel aq_error = i40e_set_fc(hw, &fc_aq_err, TRUE); 423961ae650dSJack F Vogel if (aq_error) { 424061ae650dSJack F Vogel device_printf(dev, 424161ae650dSJack F Vogel "%s: Error setting new fc mode %d; fc_err %#x\n", 424261ae650dSJack F Vogel __func__, aq_error, fc_aq_err); 424361ae650dSJack F Vogel return (EAGAIN); 424461ae650dSJack F Vogel } 424561ae650dSJack F Vogel 424661ae650dSJack F Vogel if (hw->fc.current_mode != hw->fc.requested_mode) { 424761ae650dSJack F Vogel device_printf(dev, "%s: FC set failure:\n", __func__); 424861ae650dSJack F Vogel device_printf(dev, "%s: Current: %s / Requested: %s\n", 424961ae650dSJack F Vogel __func__, 425061ae650dSJack F Vogel ixl_fc_string[hw->fc.current_mode], 425161ae650dSJack F Vogel ixl_fc_string[hw->fc.requested_mode]); 425261ae650dSJack F Vogel } 425361ae650dSJack F Vogel 425461ae650dSJack F Vogel return (0); 425561ae650dSJack F Vogel } 425661ae650dSJack F Vogel 425761ae650dSJack F Vogel static int 425861ae650dSJack F Vogel ixl_current_speed(SYSCTL_HANDLER_ARGS) 425961ae650dSJack F Vogel { 426061ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 426161ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 426261ae650dSJack F Vogel int error = 0, index = 0; 426361ae650dSJack F Vogel 426461ae650dSJack F Vogel char *speeds[] = { 426561ae650dSJack F Vogel "Unknown", 426661ae650dSJack F Vogel "100M", 426761ae650dSJack F Vogel "1G", 426861ae650dSJack F Vogel "10G", 426961ae650dSJack F Vogel "40G", 427061ae650dSJack F Vogel "20G" 427161ae650dSJack F Vogel }; 427261ae650dSJack F Vogel 427361ae650dSJack F Vogel ixl_update_link_status(pf); 427461ae650dSJack F Vogel 427561ae650dSJack F Vogel switch (hw->phy.link_info.link_speed) { 427661ae650dSJack F Vogel case I40E_LINK_SPEED_100MB: 427761ae650dSJack F Vogel index = 1; 427861ae650dSJack F Vogel break; 427961ae650dSJack F Vogel case I40E_LINK_SPEED_1GB: 428061ae650dSJack F Vogel index = 2; 428161ae650dSJack F Vogel break; 428261ae650dSJack F Vogel case I40E_LINK_SPEED_10GB: 428361ae650dSJack F Vogel index = 3; 428461ae650dSJack F Vogel break; 428561ae650dSJack F Vogel case I40E_LINK_SPEED_40GB: 428661ae650dSJack F Vogel index = 4; 428761ae650dSJack F Vogel break; 428861ae650dSJack F Vogel case I40E_LINK_SPEED_20GB: 428961ae650dSJack F Vogel index = 5; 429061ae650dSJack F Vogel break; 429161ae650dSJack F Vogel case I40E_LINK_SPEED_UNKNOWN: 429261ae650dSJack F Vogel default: 429361ae650dSJack F Vogel index = 0; 429461ae650dSJack F Vogel break; 429561ae650dSJack F Vogel } 429661ae650dSJack F Vogel 429761ae650dSJack F Vogel error = sysctl_handle_string(oidp, speeds[index], 429861ae650dSJack F Vogel strlen(speeds[index]), req); 429961ae650dSJack F Vogel return (error); 430061ae650dSJack F Vogel } 430161ae650dSJack F Vogel 430261ae650dSJack F Vogel /* 430361ae650dSJack F Vogel ** Control link advertise speed: 430461ae650dSJack F Vogel ** Flags: 430561ae650dSJack F Vogel ** 0x1 - advertise 100 Mb 430661ae650dSJack F Vogel ** 0x2 - advertise 1G 430761ae650dSJack F Vogel ** 0x4 - advertise 10G 430861ae650dSJack F Vogel ** 430961ae650dSJack F Vogel ** Does not work on 40G devices. 431061ae650dSJack F Vogel */ 431161ae650dSJack F Vogel static int 431261ae650dSJack F Vogel ixl_set_advertise(SYSCTL_HANDLER_ARGS) 431361ae650dSJack F Vogel { 431461ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 431561ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 431661ae650dSJack F Vogel device_t dev = pf->dev; 431761ae650dSJack F Vogel struct i40e_aq_get_phy_abilities_resp abilities; 431861ae650dSJack F Vogel struct i40e_aq_set_phy_config config; 431961ae650dSJack F Vogel int requested_ls = 0; 432061ae650dSJack F Vogel enum i40e_status_code aq_error = 0; 432161ae650dSJack F Vogel int error = 0; 432261ae650dSJack F Vogel 432361ae650dSJack F Vogel /* 432461ae650dSJack F Vogel ** FW doesn't support changing advertised speed 432561ae650dSJack F Vogel ** for 40G devices; speed is always 40G. 432661ae650dSJack F Vogel */ 432761ae650dSJack F Vogel if (i40e_is_40G_device(hw->device_id)) 432861ae650dSJack F Vogel return (ENODEV); 432961ae650dSJack F Vogel 433061ae650dSJack F Vogel /* Read in new mode */ 433161ae650dSJack F Vogel requested_ls = pf->advertised_speed; 433261ae650dSJack F Vogel error = sysctl_handle_int(oidp, &requested_ls, 0, req); 433361ae650dSJack F Vogel if ((error) || (req->newptr == NULL)) 433461ae650dSJack F Vogel return (error); 433561ae650dSJack F Vogel if (requested_ls < 1 || requested_ls > 7) { 433661ae650dSJack F Vogel device_printf(dev, 433761ae650dSJack F Vogel "Invalid advertised speed; valid modes are 0x1 through 0x7\n"); 433861ae650dSJack F Vogel return (EINVAL); 433961ae650dSJack F Vogel } 434061ae650dSJack F Vogel 434161ae650dSJack F Vogel /* Exit if no change */ 434261ae650dSJack F Vogel if (pf->advertised_speed == requested_ls) 434361ae650dSJack F Vogel return (0); 434461ae650dSJack F Vogel 434561ae650dSJack F Vogel /* Get current capability information */ 434661ae650dSJack F Vogel aq_error = i40e_aq_get_phy_capabilities(hw, FALSE, FALSE, &abilities, NULL); 434761ae650dSJack F Vogel if (aq_error) { 434861ae650dSJack F Vogel device_printf(dev, "%s: Error getting phy capabilities %d," 434961ae650dSJack F Vogel " aq error: %d\n", __func__, aq_error, 435061ae650dSJack F Vogel hw->aq.asq_last_status); 435161ae650dSJack F Vogel return (EAGAIN); 435261ae650dSJack F Vogel } 435361ae650dSJack F Vogel 435461ae650dSJack F Vogel /* Prepare new config */ 435561ae650dSJack F Vogel bzero(&config, sizeof(config)); 435661ae650dSJack F Vogel config.phy_type = abilities.phy_type; 435761ae650dSJack F Vogel config.abilities = abilities.abilities 435861ae650dSJack F Vogel | I40E_AQ_PHY_ENABLE_ATOMIC_LINK; 435961ae650dSJack F Vogel config.eee_capability = abilities.eee_capability; 436061ae650dSJack F Vogel config.eeer = abilities.eeer_val; 436161ae650dSJack F Vogel config.low_power_ctrl = abilities.d3_lpan; 436261ae650dSJack F Vogel /* Translate into aq cmd link_speed */ 436361ae650dSJack F Vogel if (requested_ls & 0x4) 436461ae650dSJack F Vogel config.link_speed |= I40E_LINK_SPEED_10GB; 436561ae650dSJack F Vogel if (requested_ls & 0x2) 436661ae650dSJack F Vogel config.link_speed |= I40E_LINK_SPEED_1GB; 436761ae650dSJack F Vogel if (requested_ls & 0x1) 436861ae650dSJack F Vogel config.link_speed |= I40E_LINK_SPEED_100MB; 436961ae650dSJack F Vogel 437061ae650dSJack F Vogel /* Do aq command & restart link */ 437161ae650dSJack F Vogel aq_error = i40e_aq_set_phy_config(hw, &config, NULL); 437261ae650dSJack F Vogel if (aq_error) { 437361ae650dSJack F Vogel device_printf(dev, "%s: Error setting new phy config %d," 437461ae650dSJack F Vogel " aq error: %d\n", __func__, aq_error, 437561ae650dSJack F Vogel hw->aq.asq_last_status); 437661ae650dSJack F Vogel return (EAGAIN); 437761ae650dSJack F Vogel } 437861ae650dSJack F Vogel 437961ae650dSJack F Vogel pf->advertised_speed = requested_ls; 438061ae650dSJack F Vogel ixl_update_link_status(pf); 438161ae650dSJack F Vogel return (0); 438261ae650dSJack F Vogel } 438361ae650dSJack F Vogel 438461ae650dSJack F Vogel /* 438561ae650dSJack F Vogel ** Get the width and transaction speed of 438661ae650dSJack F Vogel ** the bus this adapter is plugged into. 438761ae650dSJack F Vogel */ 438861ae650dSJack F Vogel static u16 438961ae650dSJack F Vogel ixl_get_bus_info(struct i40e_hw *hw, device_t dev) 439061ae650dSJack F Vogel { 439161ae650dSJack F Vogel u16 link; 439261ae650dSJack F Vogel u32 offset; 439361ae650dSJack F Vogel 439461ae650dSJack F Vogel 439561ae650dSJack F Vogel /* Get the PCI Express Capabilities offset */ 439661ae650dSJack F Vogel pci_find_cap(dev, PCIY_EXPRESS, &offset); 439761ae650dSJack F Vogel 439861ae650dSJack F Vogel /* ...and read the Link Status Register */ 439961ae650dSJack F Vogel link = pci_read_config(dev, offset + PCIER_LINK_STA, 2); 440061ae650dSJack F Vogel 440161ae650dSJack F Vogel switch (link & I40E_PCI_LINK_WIDTH) { 440261ae650dSJack F Vogel case I40E_PCI_LINK_WIDTH_1: 440361ae650dSJack F Vogel hw->bus.width = i40e_bus_width_pcie_x1; 440461ae650dSJack F Vogel break; 440561ae650dSJack F Vogel case I40E_PCI_LINK_WIDTH_2: 440661ae650dSJack F Vogel hw->bus.width = i40e_bus_width_pcie_x2; 440761ae650dSJack F Vogel break; 440861ae650dSJack F Vogel case I40E_PCI_LINK_WIDTH_4: 440961ae650dSJack F Vogel hw->bus.width = i40e_bus_width_pcie_x4; 441061ae650dSJack F Vogel break; 441161ae650dSJack F Vogel case I40E_PCI_LINK_WIDTH_8: 441261ae650dSJack F Vogel hw->bus.width = i40e_bus_width_pcie_x8; 441361ae650dSJack F Vogel break; 441461ae650dSJack F Vogel default: 441561ae650dSJack F Vogel hw->bus.width = i40e_bus_width_unknown; 441661ae650dSJack F Vogel break; 441761ae650dSJack F Vogel } 441861ae650dSJack F Vogel 441961ae650dSJack F Vogel switch (link & I40E_PCI_LINK_SPEED) { 442061ae650dSJack F Vogel case I40E_PCI_LINK_SPEED_2500: 442161ae650dSJack F Vogel hw->bus.speed = i40e_bus_speed_2500; 442261ae650dSJack F Vogel break; 442361ae650dSJack F Vogel case I40E_PCI_LINK_SPEED_5000: 442461ae650dSJack F Vogel hw->bus.speed = i40e_bus_speed_5000; 442561ae650dSJack F Vogel break; 442661ae650dSJack F Vogel case I40E_PCI_LINK_SPEED_8000: 442761ae650dSJack F Vogel hw->bus.speed = i40e_bus_speed_8000; 442861ae650dSJack F Vogel break; 442961ae650dSJack F Vogel default: 443061ae650dSJack F Vogel hw->bus.speed = i40e_bus_speed_unknown; 443161ae650dSJack F Vogel break; 443261ae650dSJack F Vogel } 443361ae650dSJack F Vogel 443461ae650dSJack F Vogel 443561ae650dSJack F Vogel device_printf(dev,"PCI Express Bus: Speed %s %s\n", 443661ae650dSJack F Vogel ((hw->bus.speed == i40e_bus_speed_8000) ? "8.0GT/s": 443761ae650dSJack F Vogel (hw->bus.speed == i40e_bus_speed_5000) ? "5.0GT/s": 443861ae650dSJack F Vogel (hw->bus.speed == i40e_bus_speed_2500) ? "2.5GT/s":"Unknown"), 443961ae650dSJack F Vogel (hw->bus.width == i40e_bus_width_pcie_x8) ? "Width x8" : 444061ae650dSJack F Vogel (hw->bus.width == i40e_bus_width_pcie_x4) ? "Width x4" : 444161ae650dSJack F Vogel (hw->bus.width == i40e_bus_width_pcie_x1) ? "Width x1" : 444261ae650dSJack F Vogel ("Unknown")); 444361ae650dSJack F Vogel 444461ae650dSJack F Vogel if ((hw->bus.width <= i40e_bus_width_pcie_x8) && 444561ae650dSJack F Vogel (hw->bus.speed < i40e_bus_speed_8000)) { 444661ae650dSJack F Vogel device_printf(dev, "PCI-Express bandwidth available" 444761ae650dSJack F Vogel " for this device\n is not sufficient for" 444861ae650dSJack F Vogel " normal operation.\n"); 444961ae650dSJack F Vogel device_printf(dev, "For expected performance a x8 " 445061ae650dSJack F Vogel "PCIE Gen3 slot is required.\n"); 445161ae650dSJack F Vogel } 445261ae650dSJack F Vogel 445361ae650dSJack F Vogel return (link); 445461ae650dSJack F Vogel } 445561ae650dSJack F Vogel 445661ae650dSJack F Vogel #ifdef IXL_DEBUG 445761ae650dSJack F Vogel static int 445861ae650dSJack F Vogel ixl_sysctl_link_status(SYSCTL_HANDLER_ARGS) 445961ae650dSJack F Vogel { 446061ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 446161ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 446261ae650dSJack F Vogel struct i40e_link_status link_status; 446361ae650dSJack F Vogel char buf[512]; 446461ae650dSJack F Vogel 446561ae650dSJack F Vogel enum i40e_status_code aq_error = 0; 446661ae650dSJack F Vogel 446761ae650dSJack F Vogel aq_error = i40e_aq_get_link_info(hw, TRUE, &link_status, NULL); 446861ae650dSJack F Vogel if (aq_error) { 446961ae650dSJack F Vogel printf("i40e_aq_get_link_info() error %d\n", aq_error); 447061ae650dSJack F Vogel return (EPERM); 447161ae650dSJack F Vogel } 447261ae650dSJack F Vogel 447361ae650dSJack F Vogel sprintf(buf, "\n" 447461ae650dSJack F Vogel "PHY Type : %#04x\n" 447561ae650dSJack F Vogel "Speed : %#04x\n" 447661ae650dSJack F Vogel "Link info: %#04x\n" 447761ae650dSJack F Vogel "AN info : %#04x\n" 447861ae650dSJack F Vogel "Ext info : %#04x", 447961ae650dSJack F Vogel link_status.phy_type, link_status.link_speed, 448061ae650dSJack F Vogel link_status.link_info, link_status.an_info, 448161ae650dSJack F Vogel link_status.ext_info); 448261ae650dSJack F Vogel 448361ae650dSJack F Vogel return (sysctl_handle_string(oidp, buf, strlen(buf), req)); 448461ae650dSJack F Vogel } 448561ae650dSJack F Vogel 448661ae650dSJack F Vogel static int 448761ae650dSJack F Vogel ixl_sysctl_phy_abilities(SYSCTL_HANDLER_ARGS) 448861ae650dSJack F Vogel { 448961ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 449061ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 449161ae650dSJack F Vogel struct i40e_aq_get_phy_abilities_resp abilities_resp; 449261ae650dSJack F Vogel char buf[512]; 449361ae650dSJack F Vogel 449461ae650dSJack F Vogel enum i40e_status_code aq_error = 0; 449561ae650dSJack F Vogel 449661ae650dSJack F Vogel // TODO: Print out list of qualified modules as well? 449761ae650dSJack F Vogel aq_error = i40e_aq_get_phy_capabilities(hw, TRUE, FALSE, &abilities_resp, NULL); 449861ae650dSJack F Vogel if (aq_error) { 449961ae650dSJack F Vogel printf("i40e_aq_get_phy_capabilities() error %d\n", aq_error); 450061ae650dSJack F Vogel return (EPERM); 450161ae650dSJack F Vogel } 450261ae650dSJack F Vogel 450361ae650dSJack F Vogel sprintf(buf, "\n" 450461ae650dSJack F Vogel "PHY Type : %#010x\n" 450561ae650dSJack F Vogel "Speed : %#04x\n" 450661ae650dSJack F Vogel "Abilities: %#04x\n" 450761ae650dSJack F Vogel "EEE cap : %#06x\n" 450861ae650dSJack F Vogel "EEER reg : %#010x\n" 450961ae650dSJack F Vogel "D3 Lpan : %#04x", 451061ae650dSJack F Vogel abilities_resp.phy_type, abilities_resp.link_speed, 451161ae650dSJack F Vogel abilities_resp.abilities, abilities_resp.eee_capability, 451261ae650dSJack F Vogel abilities_resp.eeer_val, abilities_resp.d3_lpan); 451361ae650dSJack F Vogel 451461ae650dSJack F Vogel return (sysctl_handle_string(oidp, buf, strlen(buf), req)); 451561ae650dSJack F Vogel } 451661ae650dSJack F Vogel 451761ae650dSJack F Vogel static int 451861ae650dSJack F Vogel ixl_sysctl_sw_filter_list(SYSCTL_HANDLER_ARGS) 451961ae650dSJack F Vogel { 452061ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 452161ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 452261ae650dSJack F Vogel struct ixl_mac_filter *f; 452361ae650dSJack F Vogel char *buf, *buf_i; 452461ae650dSJack F Vogel 452561ae650dSJack F Vogel int error = 0; 452661ae650dSJack F Vogel int ftl_len = 0; 452761ae650dSJack F Vogel int ftl_counter = 0; 452861ae650dSJack F Vogel int buf_len = 0; 452961ae650dSJack F Vogel int entry_len = 42; 453061ae650dSJack F Vogel 453161ae650dSJack F Vogel SLIST_FOREACH(f, &vsi->ftl, next) { 453261ae650dSJack F Vogel ftl_len++; 453361ae650dSJack F Vogel } 453461ae650dSJack F Vogel 453561ae650dSJack F Vogel if (ftl_len < 1) { 453661ae650dSJack F Vogel sysctl_handle_string(oidp, "(none)", 6, req); 453761ae650dSJack F Vogel return (0); 453861ae650dSJack F Vogel } 453961ae650dSJack F Vogel 454061ae650dSJack F Vogel buf_len = sizeof(char) * (entry_len + 1) * ftl_len + 2; 454161ae650dSJack F Vogel buf = buf_i = malloc(buf_len, M_DEVBUF, M_NOWAIT); 454261ae650dSJack F Vogel 454361ae650dSJack F Vogel sprintf(buf_i++, "\n"); 454461ae650dSJack F Vogel SLIST_FOREACH(f, &vsi->ftl, next) { 454561ae650dSJack F Vogel sprintf(buf_i, 454661ae650dSJack F Vogel MAC_FORMAT ", vlan %4d, flags %#06x", 454761ae650dSJack F Vogel MAC_FORMAT_ARGS(f->macaddr), f->vlan, f->flags); 454861ae650dSJack F Vogel buf_i += entry_len; 454961ae650dSJack F Vogel /* don't print '\n' for last entry */ 455061ae650dSJack F Vogel if (++ftl_counter != ftl_len) { 455161ae650dSJack F Vogel sprintf(buf_i, "\n"); 455261ae650dSJack F Vogel buf_i++; 455361ae650dSJack F Vogel } 455461ae650dSJack F Vogel } 455561ae650dSJack F Vogel 455661ae650dSJack F Vogel error = sysctl_handle_string(oidp, buf, strlen(buf), req); 455761ae650dSJack F Vogel if (error) 455861ae650dSJack F Vogel printf("sysctl error: %d\n", error); 455961ae650dSJack F Vogel free(buf, M_DEVBUF); 456061ae650dSJack F Vogel return error; 456161ae650dSJack F Vogel } 456261ae650dSJack F Vogel 456361ae650dSJack F Vogel #define IXL_SW_RES_SIZE 0x14 456461ae650dSJack F Vogel static int 456561ae650dSJack F Vogel ixl_sysctl_hw_res_info(SYSCTL_HANDLER_ARGS) 456661ae650dSJack F Vogel { 456761ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 456861ae650dSJack F Vogel struct i40e_hw *hw = &pf->hw; 456961ae650dSJack F Vogel device_t dev = pf->dev; 457061ae650dSJack F Vogel struct sbuf *buf; 457161ae650dSJack F Vogel int error = 0; 457261ae650dSJack F Vogel 457361ae650dSJack F Vogel u8 num_entries; 457461ae650dSJack F Vogel struct i40e_aqc_switch_resource_alloc_element_resp resp[IXL_SW_RES_SIZE]; 457561ae650dSJack F Vogel 457661ae650dSJack F Vogel buf = sbuf_new_for_sysctl(NULL, NULL, 0, req); 457761ae650dSJack F Vogel if (!buf) { 457861ae650dSJack F Vogel device_printf(dev, "Could not allocate sbuf for output.\n"); 457961ae650dSJack F Vogel return (ENOMEM); 458061ae650dSJack F Vogel } 458161ae650dSJack F Vogel 458261ae650dSJack F Vogel error = i40e_aq_get_switch_resource_alloc(hw, &num_entries, 458361ae650dSJack F Vogel resp, 458461ae650dSJack F Vogel IXL_SW_RES_SIZE, 458561ae650dSJack F Vogel NULL); 458661ae650dSJack F Vogel if (error) { 458761ae650dSJack F Vogel device_printf(dev, "%s: get_switch_resource_alloc() error %d, aq error %d\n", 458861ae650dSJack F Vogel __func__, error, hw->aq.asq_last_status); 458961ae650dSJack F Vogel sbuf_delete(buf); 459061ae650dSJack F Vogel return error; 459161ae650dSJack F Vogel } 459261ae650dSJack F Vogel device_printf(dev, "Num_entries: %d\n", num_entries); 459361ae650dSJack F Vogel 459461ae650dSJack F Vogel sbuf_cat(buf, "\n"); 459561ae650dSJack F Vogel sbuf_printf(buf, 459661ae650dSJack F Vogel "Type | Guaranteed | Total | Used | Un-allocated\n" 459761ae650dSJack F Vogel " | (this) | (all) | (this) | (all) \n"); 459861ae650dSJack F Vogel for (int i = 0; i < num_entries; i++) { 459961ae650dSJack F Vogel sbuf_printf(buf, 460061ae650dSJack F Vogel "%#4x | %10d %5d %6d %12d", 460161ae650dSJack F Vogel resp[i].resource_type, 460261ae650dSJack F Vogel resp[i].guaranteed, 460361ae650dSJack F Vogel resp[i].total, 460461ae650dSJack F Vogel resp[i].used, 460561ae650dSJack F Vogel resp[i].total_unalloced); 460661ae650dSJack F Vogel if (i < num_entries - 1) 460761ae650dSJack F Vogel sbuf_cat(buf, "\n"); 460861ae650dSJack F Vogel } 460961ae650dSJack F Vogel 461061ae650dSJack F Vogel error = sbuf_finish(buf); 461161ae650dSJack F Vogel if (error) { 461261ae650dSJack F Vogel device_printf(dev, "Error finishing sbuf: %d\n", error); 461361ae650dSJack F Vogel sbuf_delete(buf); 461461ae650dSJack F Vogel return error; 461561ae650dSJack F Vogel } 461661ae650dSJack F Vogel 461761ae650dSJack F Vogel error = sysctl_handle_string(oidp, sbuf_data(buf), sbuf_len(buf), req); 461861ae650dSJack F Vogel if (error) 461961ae650dSJack F Vogel device_printf(dev, "sysctl error: %d\n", error); 462061ae650dSJack F Vogel sbuf_delete(buf); 462161ae650dSJack F Vogel return error; 462261ae650dSJack F Vogel 462361ae650dSJack F Vogel } 462461ae650dSJack F Vogel 462561ae650dSJack F Vogel /* 462661ae650dSJack F Vogel ** Dump TX desc given index. 462761ae650dSJack F Vogel ** Doesn't work; don't use. 462861ae650dSJack F Vogel ** TODO: Also needs a queue index input! 462961ae650dSJack F Vogel **/ 463061ae650dSJack F Vogel static int 463161ae650dSJack F Vogel ixl_sysctl_dump_txd(SYSCTL_HANDLER_ARGS) 463261ae650dSJack F Vogel { 463361ae650dSJack F Vogel struct ixl_pf *pf = (struct ixl_pf *)arg1; 463461ae650dSJack F Vogel device_t dev = pf->dev; 463561ae650dSJack F Vogel struct sbuf *buf; 463661ae650dSJack F Vogel int error = 0; 463761ae650dSJack F Vogel 463861ae650dSJack F Vogel u16 desc_idx = 0; 463961ae650dSJack F Vogel 464061ae650dSJack F Vogel buf = sbuf_new_for_sysctl(NULL, NULL, 0, req); 464161ae650dSJack F Vogel if (!buf) { 464261ae650dSJack F Vogel device_printf(dev, "Could not allocate sbuf for output.\n"); 464361ae650dSJack F Vogel return (ENOMEM); 464461ae650dSJack F Vogel } 464561ae650dSJack F Vogel 464661ae650dSJack F Vogel /* Read in index */ 464761ae650dSJack F Vogel error = sysctl_handle_int(oidp, &desc_idx, 0, req); 464861ae650dSJack F Vogel if (error) 464961ae650dSJack F Vogel return (error); 465061ae650dSJack F Vogel if (req->newptr == NULL) 465161ae650dSJack F Vogel return (EIO); // fix 465261ae650dSJack F Vogel if (desc_idx > 1024) { // fix 465361ae650dSJack F Vogel device_printf(dev, 465461ae650dSJack F Vogel "Invalid descriptor index, needs to be < 1024\n"); // fix 465561ae650dSJack F Vogel return (EINVAL); 465661ae650dSJack F Vogel } 465761ae650dSJack F Vogel 465861ae650dSJack F Vogel // Don't use this sysctl yet 465961ae650dSJack F Vogel if (TRUE) 466061ae650dSJack F Vogel return (ENODEV); 466161ae650dSJack F Vogel 466261ae650dSJack F Vogel sbuf_cat(buf, "\n"); 466361ae650dSJack F Vogel 466461ae650dSJack F Vogel // set to queue 1? 466561ae650dSJack F Vogel struct ixl_queue *que = pf->vsi.queues; 466661ae650dSJack F Vogel struct tx_ring *txr = &(que[1].txr); 466761ae650dSJack F Vogel struct i40e_tx_desc *txd = &txr->base[desc_idx]; 466861ae650dSJack F Vogel 466961ae650dSJack F Vogel sbuf_printf(buf, "Que: %d, Desc: %d\n", que->me, desc_idx); 467061ae650dSJack F Vogel sbuf_printf(buf, "Addr: %#18lx\n", txd->buffer_addr); 467161ae650dSJack F Vogel sbuf_printf(buf, "Opts: %#18lx\n", txd->cmd_type_offset_bsz); 467261ae650dSJack F Vogel 467361ae650dSJack F Vogel error = sbuf_finish(buf); 467461ae650dSJack F Vogel if (error) { 467561ae650dSJack F Vogel device_printf(dev, "Error finishing sbuf: %d\n", error); 467661ae650dSJack F Vogel sbuf_delete(buf); 467761ae650dSJack F Vogel return error; 467861ae650dSJack F Vogel } 467961ae650dSJack F Vogel 468061ae650dSJack F Vogel error = sysctl_handle_string(oidp, sbuf_data(buf), sbuf_len(buf), req); 468161ae650dSJack F Vogel if (error) 468261ae650dSJack F Vogel device_printf(dev, "sysctl error: %d\n", error); 468361ae650dSJack F Vogel sbuf_delete(buf); 468461ae650dSJack F Vogel return error; 468561ae650dSJack F Vogel } 468661ae650dSJack F Vogel #endif 468761ae650dSJack F Vogel 4688