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