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