1758cc3dcSJack F Vogel /****************************************************************************** 2758cc3dcSJack F Vogel 38eb6488eSEric Joyner Copyright (c) 2001-2017, Intel Corporation 4758cc3dcSJack F Vogel All rights reserved. 5758cc3dcSJack F Vogel 6758cc3dcSJack F Vogel Redistribution and use in source and binary forms, with or without 7758cc3dcSJack F Vogel modification, are permitted provided that the following conditions are met: 8758cc3dcSJack F Vogel 9758cc3dcSJack F Vogel 1. Redistributions of source code must retain the above copyright notice, 10758cc3dcSJack F Vogel this list of conditions and the following disclaimer. 11758cc3dcSJack F Vogel 12758cc3dcSJack F Vogel 2. Redistributions in binary form must reproduce the above copyright 13758cc3dcSJack F Vogel notice, this list of conditions and the following disclaimer in the 14758cc3dcSJack F Vogel documentation and/or other materials provided with the distribution. 15758cc3dcSJack F Vogel 16758cc3dcSJack F Vogel 3. Neither the name of the Intel Corporation nor the names of its 17758cc3dcSJack F Vogel contributors may be used to endorse or promote products derived from 18758cc3dcSJack F Vogel this software without specific prior written permission. 19758cc3dcSJack F Vogel 20758cc3dcSJack F Vogel THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21758cc3dcSJack F Vogel AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22758cc3dcSJack F Vogel IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23758cc3dcSJack F Vogel ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24758cc3dcSJack F Vogel LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25758cc3dcSJack F Vogel CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26758cc3dcSJack F Vogel SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27758cc3dcSJack F Vogel INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28758cc3dcSJack F Vogel CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29758cc3dcSJack F Vogel ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30758cc3dcSJack F Vogel POSSIBILITY OF SUCH DAMAGE. 31758cc3dcSJack F Vogel 32758cc3dcSJack F Vogel ******************************************************************************/ 33758cc3dcSJack F Vogel /*$FreeBSD$*/ 34758cc3dcSJack F Vogel 35758cc3dcSJack F Vogel 36758cc3dcSJack F Vogel #include "opt_inet.h" 37758cc3dcSJack F Vogel #include "opt_inet6.h" 38758cc3dcSJack F Vogel #include "opt_rss.h" 39758cc3dcSJack F Vogel 40758cc3dcSJack F Vogel #include "ixgbe.h" 41c19c7afeSEric Joyner #include "ixgbe_sriov.h" 42c19c7afeSEric Joyner #include "ifdi_if.h" 43c19c7afeSEric Joyner 44c19c7afeSEric Joyner #include <net/netmap.h> 45c19c7afeSEric Joyner #include <dev/netmap/netmap_kern.h> 46758cc3dcSJack F Vogel 478eb6488eSEric Joyner /************************************************************************ 48758cc3dcSJack F Vogel * Driver version 498eb6488eSEric Joyner ************************************************************************/ 507d48aa4cSEric Joyner char ixgbe_driver_version[] = "4.0.1-k"; 51a9ca1c79SSean Bruno 52758cc3dcSJack F Vogel 538eb6488eSEric Joyner /************************************************************************ 54758cc3dcSJack F Vogel * PCI Device ID Table 55758cc3dcSJack F Vogel * 56758cc3dcSJack F Vogel * Used by probe to select devices to load on 57758cc3dcSJack F Vogel * Last field stores an index into ixgbe_strings 58758cc3dcSJack F Vogel * Last entry must be all 0s 59758cc3dcSJack F Vogel * 60758cc3dcSJack F Vogel * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index } 618eb6488eSEric Joyner ************************************************************************/ 62c19c7afeSEric Joyner static pci_vendor_info_t ixgbe_vendor_info_array[] = 63758cc3dcSJack F Vogel { 64fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AF_DUAL_PORT, "Intel(R) 82598EB AF (Dual Fiber)"), 65fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AF_SINGLE_PORT, "Intel(R) 82598EB AF (Fiber)"), 66fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_CX4, "Intel(R) 82598EB AT (CX4)"), 67fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AT, "Intel(R) 82598EB AT"), 68fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AT2, "Intel(R) 82598EB AT2"), 69fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598, "Intel(R) 82598"), 70fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_DA_DUAL_PORT, "Intel(R) 82598EB AF DA (Dual Fiber)"), 71fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_CX4_DUAL_PORT, "Intel(R) 82598EB AT (Dual CX4)"), 72fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_XF_LR, "Intel(R) 82598EB AF (Dual Fiber LR)"), 73fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM, "Intel(R) 82598EB AF (Dual Fiber SR)"), 74fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_SFP_LOM, "Intel(R) 82598EB LOM"), 75fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KX4, "Intel(R) X520 82599 (KX4)"), 76fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KX4_MEZZ, "Intel(R) X520 82599 (KX4 Mezzanine)"), 77fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP, "Intel(R) X520 82599ES (SFI/SFP+)"), 78fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_XAUI_LOM, "Intel(R) X520 82599 (XAUI/BX4)"), 79fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_CX4, "Intel(R) X520 82599 (Dual CX4)"), 80fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_T3_LOM, "Intel(R) X520-T 82599 LOM"), 81fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_COMBO_BACKPLANE, "Intel(R) X520 82599 (Combined Backplane)"), 82fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_BACKPLANE_FCOE, "Intel(R) X520 82599 (Backplane w/FCoE)"), 83fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_SF2, "Intel(R) X520 82599 (Dual SFP+)"), 84fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_FCOE, "Intel(R) X520 82599 (Dual SFP+ w/FCoE)"), 85fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599EN_SFP, "Intel(R) X520-1 82599EN (SFP+)"), 86fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_SF_QP, "Intel(R) X520-4 82599 (Quad SFP+)"), 87fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_QSFP_SF_QP, "Intel(R) X520-Q1 82599 (QSFP+)"), 88fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540T, "Intel(R) X540-AT2"), 89fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540T1, "Intel(R) X540-T1"), 90fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550T, "Intel(R) X550-T2"), 91fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550T1, "Intel(R) X550-T1"), 92fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_KR, "Intel(R) X552 (KR Backplane)"), 93fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_KX4, "Intel(R) X552 (KX4 Backplane)"), 94fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_10G_T, "Intel(R) X552/X557-AT (10GBASE-T)"), 95fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_1G_T, "Intel(R) X552 (1000BASE-T)"), 96fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_SFP, "Intel(R) X552 (SFP+)"), 97fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_KR, "Intel(R) X553 (KR Backplane)"), 98fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_KR_L, "Intel(R) X553 L (KR Backplane)"), 99fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_SFP, "Intel(R) X553 (SFP+)"), 100fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_SFP_N, "Intel(R) X553 N (SFP+)"), 101fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_SGMII, "Intel(R) X553 (1GbE SGMII)"), 102fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_SGMII_L, "Intel(R) X553 L (1GbE SGMII)"), 103fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_10G_T, "Intel(R) X553/X557-AT (10GBASE-T)"), 104fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_1G_T, "Intel(R) X553 (1GbE)"), 105fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_1G_T_L, "Intel(R) X553 L (1GbE)"), 106fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540_BYPASS, "Intel(R) X540-T2 (Bypass)"), 107fdbcd35aSKevin Bowling PVID(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_BYPASS, "Intel(R) X520 82599 (Bypass)"), 108758cc3dcSJack F Vogel /* required last entry */ 109c19c7afeSEric Joyner PVID_END 110758cc3dcSJack F Vogel }; 111758cc3dcSJack F Vogel 112c19c7afeSEric Joyner static void *ixgbe_register(device_t dev); 113c19c7afeSEric Joyner static int ixgbe_if_attach_pre(if_ctx_t ctx); 114c19c7afeSEric Joyner static int ixgbe_if_attach_post(if_ctx_t ctx); 115c19c7afeSEric Joyner static int ixgbe_if_detach(if_ctx_t ctx); 116c19c7afeSEric Joyner static int ixgbe_if_shutdown(if_ctx_t ctx); 117c19c7afeSEric Joyner static int ixgbe_if_suspend(if_ctx_t ctx); 118c19c7afeSEric Joyner static int ixgbe_if_resume(if_ctx_t ctx); 119c19c7afeSEric Joyner 120c19c7afeSEric Joyner static void ixgbe_if_stop(if_ctx_t ctx); 121c19c7afeSEric Joyner void ixgbe_if_enable_intr(if_ctx_t ctx); 122c19c7afeSEric Joyner static void ixgbe_if_disable_intr(if_ctx_t ctx); 123b2c1e8e6SEric Joyner static void ixgbe_link_intr_enable(if_ctx_t ctx); 124c19c7afeSEric Joyner static int ixgbe_if_rx_queue_intr_enable(if_ctx_t ctx, uint16_t qid); 125c19c7afeSEric Joyner static void ixgbe_if_media_status(if_ctx_t ctx, struct ifmediareq * ifmr); 126c19c7afeSEric Joyner static int ixgbe_if_media_change(if_ctx_t ctx); 127c19c7afeSEric Joyner static int ixgbe_if_msix_intr_assign(if_ctx_t, int); 128c19c7afeSEric Joyner static int ixgbe_if_mtu_set(if_ctx_t ctx, uint32_t mtu); 129c19c7afeSEric Joyner static void ixgbe_if_crcstrip_set(if_ctx_t ctx, int onoff, int strip); 130c19c7afeSEric Joyner static void ixgbe_if_multi_set(if_ctx_t ctx); 131c19c7afeSEric Joyner static int ixgbe_if_promisc_set(if_ctx_t ctx, int flags); 132c19c7afeSEric Joyner static int ixgbe_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, 133c19c7afeSEric Joyner uint64_t *paddrs, int nrxqs, int nrxqsets); 134c19c7afeSEric Joyner static int ixgbe_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, 135c19c7afeSEric Joyner uint64_t *paddrs, int nrxqs, int nrxqsets); 136c19c7afeSEric Joyner static void ixgbe_if_queues_free(if_ctx_t ctx); 137c19c7afeSEric Joyner static void ixgbe_if_timer(if_ctx_t ctx, uint16_t); 138c19c7afeSEric Joyner static void ixgbe_if_update_admin_status(if_ctx_t ctx); 139c19c7afeSEric Joyner static void ixgbe_if_vlan_register(if_ctx_t ctx, u16 vtag); 140c19c7afeSEric Joyner static void ixgbe_if_vlan_unregister(if_ctx_t ctx, u16 vtag); 141bca38080SAndrew Gallatin static int ixgbe_if_i2c_req(if_ctx_t ctx, struct ifi2creq *req); 142cf150917SEric Joyner static bool ixgbe_if_needs_restart(if_ctx_t ctx, enum iflib_restart_event event); 143c19c7afeSEric Joyner int ixgbe_intr(void *arg); 144758cc3dcSJack F Vogel 1458eb6488eSEric Joyner /************************************************************************ 146758cc3dcSJack F Vogel * Function prototypes 1478eb6488eSEric Joyner ************************************************************************/ 148758cc3dcSJack F Vogel #if __FreeBSD_version >= 1100036 149c19c7afeSEric Joyner static uint64_t ixgbe_if_get_counter(if_ctx_t, ift_counter); 150758cc3dcSJack F Vogel #endif 151758cc3dcSJack F Vogel 152c19c7afeSEric Joyner static void ixgbe_enable_queue(struct adapter *adapter, u32 vector); 153c19c7afeSEric Joyner static void ixgbe_disable_queue(struct adapter *adapter, u32 vector); 154c19c7afeSEric Joyner static void ixgbe_add_device_sysctls(if_ctx_t ctx); 155c19c7afeSEric Joyner static int ixgbe_allocate_pci_resources(if_ctx_t ctx); 156c19c7afeSEric Joyner static int ixgbe_setup_low_power_mode(if_ctx_t ctx); 157c19c7afeSEric Joyner 158c19c7afeSEric Joyner static void ixgbe_config_dmac(struct adapter *adapter); 159c19c7afeSEric Joyner static void ixgbe_configure_ivars(struct adapter *adapter); 160c19c7afeSEric Joyner static void ixgbe_set_ivar(struct adapter *adapter, u8 entry, u8 vector, 161c19c7afeSEric Joyner s8 type); 162c19c7afeSEric Joyner static u8 *ixgbe_mc_array_itr(struct ixgbe_hw *, u8 **, u32 *); 163c19c7afeSEric Joyner static bool ixgbe_sfp_probe(if_ctx_t ctx); 164c19c7afeSEric Joyner 165c19c7afeSEric Joyner static void ixgbe_free_pci_resources(if_ctx_t ctx); 166c19c7afeSEric Joyner 167c19c7afeSEric Joyner static int ixgbe_msix_link(void *arg); 168c19c7afeSEric Joyner static int ixgbe_msix_que(void *arg); 169c19c7afeSEric Joyner static void ixgbe_initialize_rss_mapping(struct adapter *adapter); 170c19c7afeSEric Joyner static void ixgbe_initialize_receive_units(if_ctx_t ctx); 171c19c7afeSEric Joyner static void ixgbe_initialize_transmit_units(if_ctx_t ctx); 172c19c7afeSEric Joyner 173c19c7afeSEric Joyner static int ixgbe_setup_interface(if_ctx_t ctx); 174c19c7afeSEric Joyner static void ixgbe_init_device_features(struct adapter *adapter); 175c19c7afeSEric Joyner static void ixgbe_check_fan_failure(struct adapter *, u32, bool); 176c19c7afeSEric Joyner static void ixgbe_add_media_types(if_ctx_t ctx); 177c19c7afeSEric Joyner static void ixgbe_update_stats_counters(struct adapter *adapter); 178b2c1e8e6SEric Joyner static void ixgbe_config_link(if_ctx_t ctx); 179c19c7afeSEric Joyner static void ixgbe_get_slot_info(struct adapter *); 180c19c7afeSEric Joyner static void ixgbe_check_wol_support(struct adapter *adapter); 181758cc3dcSJack F Vogel static void ixgbe_enable_rx_drop(struct adapter *); 182758cc3dcSJack F Vogel static void ixgbe_disable_rx_drop(struct adapter *); 183758cc3dcSJack F Vogel 184c19c7afeSEric Joyner static void ixgbe_add_hw_stats(struct adapter *adapter); 185f2c4db54SSteven Hartland static int ixgbe_set_flowcntl(struct adapter *, int); 186f2c4db54SSteven Hartland static int ixgbe_set_advertise(struct adapter *, int); 1878eb6488eSEric Joyner static int ixgbe_get_advertise(struct adapter *); 188c19c7afeSEric Joyner static void ixgbe_setup_vlan_hw_support(if_ctx_t ctx); 189c19c7afeSEric Joyner static void ixgbe_config_gpie(struct adapter *adapter); 190c19c7afeSEric Joyner static void ixgbe_config_delay_values(struct adapter *adapter); 1916f37f232SEric Joyner 1926f37f232SEric Joyner /* Sysctl handlers */ 193f2c4db54SSteven Hartland static int ixgbe_sysctl_flowcntl(SYSCTL_HANDLER_ARGS); 194f2c4db54SSteven Hartland static int ixgbe_sysctl_advertise(SYSCTL_HANDLER_ARGS); 1958eb6488eSEric Joyner static int ixgbe_sysctl_interrupt_rate_handler(SYSCTL_HANDLER_ARGS); 1966f37f232SEric Joyner static int ixgbe_sysctl_dmac(SYSCTL_HANDLER_ARGS); 1976f37f232SEric Joyner static int ixgbe_sysctl_phy_temp(SYSCTL_HANDLER_ARGS); 1986f37f232SEric Joyner static int ixgbe_sysctl_phy_overtemp_occurred(SYSCTL_HANDLER_ARGS); 199a9ca1c79SSean Bruno #ifdef IXGBE_DEBUG 200a9ca1c79SSean Bruno static int ixgbe_sysctl_power_state(SYSCTL_HANDLER_ARGS); 201a9ca1c79SSean Bruno static int ixgbe_sysctl_print_rss_config(SYSCTL_HANDLER_ARGS); 202a9ca1c79SSean Bruno #endif 2038eb6488eSEric Joyner static int ixgbe_sysctl_rdh_handler(SYSCTL_HANDLER_ARGS); 2048eb6488eSEric Joyner static int ixgbe_sysctl_rdt_handler(SYSCTL_HANDLER_ARGS); 2058eb6488eSEric Joyner static int ixgbe_sysctl_tdt_handler(SYSCTL_HANDLER_ARGS); 2068eb6488eSEric Joyner static int ixgbe_sysctl_tdh_handler(SYSCTL_HANDLER_ARGS); 2078eb6488eSEric Joyner static int ixgbe_sysctl_eee_state(SYSCTL_HANDLER_ARGS); 2086f37f232SEric Joyner static int ixgbe_sysctl_wol_enable(SYSCTL_HANDLER_ARGS); 2096f37f232SEric Joyner static int ixgbe_sysctl_wufc(SYSCTL_HANDLER_ARGS); 210758cc3dcSJack F Vogel 211758cc3dcSJack F Vogel /* Deferred interrupt tasklets */ 212c19c7afeSEric Joyner static void ixgbe_handle_msf(void *); 213c19c7afeSEric Joyner static void ixgbe_handle_mod(void *); 214c19c7afeSEric Joyner static void ixgbe_handle_phy(void *); 215758cc3dcSJack F Vogel 2168eb6488eSEric Joyner /************************************************************************ 217758cc3dcSJack F Vogel * FreeBSD Device Interface Entry Points 2188eb6488eSEric Joyner ************************************************************************/ 219a1edda90SAdrian Chadd static device_method_t ix_methods[] = { 220758cc3dcSJack F Vogel /* Device interface */ 221c19c7afeSEric Joyner DEVMETHOD(device_register, ixgbe_register), 222c19c7afeSEric Joyner DEVMETHOD(device_probe, iflib_device_probe), 223c19c7afeSEric Joyner DEVMETHOD(device_attach, iflib_device_attach), 224c19c7afeSEric Joyner DEVMETHOD(device_detach, iflib_device_detach), 225c19c7afeSEric Joyner DEVMETHOD(device_shutdown, iflib_device_shutdown), 226c19c7afeSEric Joyner DEVMETHOD(device_suspend, iflib_device_suspend), 227c19c7afeSEric Joyner DEVMETHOD(device_resume, iflib_device_resume), 22848056c88SJack F Vogel #ifdef PCI_IOV 229c19c7afeSEric Joyner DEVMETHOD(pci_iov_init, iflib_device_iov_init), 230c19c7afeSEric Joyner DEVMETHOD(pci_iov_uninit, iflib_device_iov_uninit), 231c19c7afeSEric Joyner DEVMETHOD(pci_iov_add_vf, iflib_device_iov_add_vf), 23248056c88SJack F Vogel #endif /* PCI_IOV */ 233758cc3dcSJack F Vogel DEVMETHOD_END 234758cc3dcSJack F Vogel }; 235758cc3dcSJack F Vogel 236a1edda90SAdrian Chadd static driver_t ix_driver = { 237a1edda90SAdrian Chadd "ix", ix_methods, sizeof(struct adapter), 238758cc3dcSJack F Vogel }; 239758cc3dcSJack F Vogel 240a1edda90SAdrian Chadd devclass_t ix_devclass; 241a1edda90SAdrian Chadd DRIVER_MODULE(ix, pci, ix_driver, ix_devclass, 0, 0); 242937b0f25SYuri Pankov IFLIB_PNP_INFO(pci, ix_driver, ixgbe_vendor_info_array); 243a1edda90SAdrian Chadd MODULE_DEPEND(ix, pci, 1, 1, 1); 244a1edda90SAdrian Chadd MODULE_DEPEND(ix, ether, 1, 1, 1); 245c19c7afeSEric Joyner MODULE_DEPEND(ix, iflib, 1, 1, 1); 246c19c7afeSEric Joyner 247c19c7afeSEric Joyner static device_method_t ixgbe_if_methods[] = { 248c19c7afeSEric Joyner DEVMETHOD(ifdi_attach_pre, ixgbe_if_attach_pre), 249c19c7afeSEric Joyner DEVMETHOD(ifdi_attach_post, ixgbe_if_attach_post), 250c19c7afeSEric Joyner DEVMETHOD(ifdi_detach, ixgbe_if_detach), 251c19c7afeSEric Joyner DEVMETHOD(ifdi_shutdown, ixgbe_if_shutdown), 252c19c7afeSEric Joyner DEVMETHOD(ifdi_suspend, ixgbe_if_suspend), 253c19c7afeSEric Joyner DEVMETHOD(ifdi_resume, ixgbe_if_resume), 254c19c7afeSEric Joyner DEVMETHOD(ifdi_init, ixgbe_if_init), 255c19c7afeSEric Joyner DEVMETHOD(ifdi_stop, ixgbe_if_stop), 256c19c7afeSEric Joyner DEVMETHOD(ifdi_msix_intr_assign, ixgbe_if_msix_intr_assign), 257c19c7afeSEric Joyner DEVMETHOD(ifdi_intr_enable, ixgbe_if_enable_intr), 258c19c7afeSEric Joyner DEVMETHOD(ifdi_intr_disable, ixgbe_if_disable_intr), 259b2c1e8e6SEric Joyner DEVMETHOD(ifdi_link_intr_enable, ixgbe_link_intr_enable), 260c19c7afeSEric Joyner DEVMETHOD(ifdi_tx_queue_intr_enable, ixgbe_if_rx_queue_intr_enable), 261c19c7afeSEric Joyner DEVMETHOD(ifdi_rx_queue_intr_enable, ixgbe_if_rx_queue_intr_enable), 262c19c7afeSEric Joyner DEVMETHOD(ifdi_tx_queues_alloc, ixgbe_if_tx_queues_alloc), 263c19c7afeSEric Joyner DEVMETHOD(ifdi_rx_queues_alloc, ixgbe_if_rx_queues_alloc), 264c19c7afeSEric Joyner DEVMETHOD(ifdi_queues_free, ixgbe_if_queues_free), 265c19c7afeSEric Joyner DEVMETHOD(ifdi_update_admin_status, ixgbe_if_update_admin_status), 266c19c7afeSEric Joyner DEVMETHOD(ifdi_multi_set, ixgbe_if_multi_set), 267c19c7afeSEric Joyner DEVMETHOD(ifdi_mtu_set, ixgbe_if_mtu_set), 268c19c7afeSEric Joyner DEVMETHOD(ifdi_crcstrip_set, ixgbe_if_crcstrip_set), 269c19c7afeSEric Joyner DEVMETHOD(ifdi_media_status, ixgbe_if_media_status), 270c19c7afeSEric Joyner DEVMETHOD(ifdi_media_change, ixgbe_if_media_change), 271c19c7afeSEric Joyner DEVMETHOD(ifdi_promisc_set, ixgbe_if_promisc_set), 272c19c7afeSEric Joyner DEVMETHOD(ifdi_timer, ixgbe_if_timer), 273c19c7afeSEric Joyner DEVMETHOD(ifdi_vlan_register, ixgbe_if_vlan_register), 274c19c7afeSEric Joyner DEVMETHOD(ifdi_vlan_unregister, ixgbe_if_vlan_unregister), 275c19c7afeSEric Joyner DEVMETHOD(ifdi_get_counter, ixgbe_if_get_counter), 276bca38080SAndrew Gallatin DEVMETHOD(ifdi_i2c_req, ixgbe_if_i2c_req), 277cf150917SEric Joyner DEVMETHOD(ifdi_needs_restart, ixgbe_if_needs_restart), 278c19c7afeSEric Joyner #ifdef PCI_IOV 279c19c7afeSEric Joyner DEVMETHOD(ifdi_iov_init, ixgbe_if_iov_init), 280c19c7afeSEric Joyner DEVMETHOD(ifdi_iov_uninit, ixgbe_if_iov_uninit), 281c19c7afeSEric Joyner DEVMETHOD(ifdi_iov_vf_add, ixgbe_if_iov_vf_add), 282c19c7afeSEric Joyner #endif /* PCI_IOV */ 283c19c7afeSEric Joyner DEVMETHOD_END 284c19c7afeSEric Joyner }; 285758cc3dcSJack F Vogel 286758cc3dcSJack F Vogel /* 2878eb6488eSEric Joyner * TUNEABLE PARAMETERS: 288758cc3dcSJack F Vogel */ 289758cc3dcSJack F Vogel 29020b91f0aSPawel Biernacki static SYSCTL_NODE(_hw, OID_AUTO, ix, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 29120b91f0aSPawel Biernacki "IXGBE driver parameters"); 292c19c7afeSEric Joyner static driver_t ixgbe_if_driver = { 293c19c7afeSEric Joyner "ixgbe_if", ixgbe_if_methods, sizeof(struct adapter) 294c19c7afeSEric Joyner }; 295758cc3dcSJack F Vogel 296758cc3dcSJack F Vogel static int ixgbe_max_interrupt_rate = (4000000 / IXGBE_LOW_LATENCY); 297758cc3dcSJack F Vogel SYSCTL_INT(_hw_ix, OID_AUTO, max_interrupt_rate, CTLFLAG_RDTUN, 298758cc3dcSJack F Vogel &ixgbe_max_interrupt_rate, 0, "Maximum interrupts per second"); 299758cc3dcSJack F Vogel 300f2c4db54SSteven Hartland /* Flow control setting, default to full */ 301f2c4db54SSteven Hartland static int ixgbe_flow_control = ixgbe_fc_full; 302f2c4db54SSteven Hartland SYSCTL_INT(_hw_ix, OID_AUTO, flow_control, CTLFLAG_RDTUN, 303f2c4db54SSteven Hartland &ixgbe_flow_control, 0, "Default flow control used for all adapters"); 304f2c4db54SSteven Hartland 305f2c4db54SSteven Hartland /* Advertise Speed, default to 0 (auto) */ 306f2c4db54SSteven Hartland static int ixgbe_advertise_speed = 0; 307f2c4db54SSteven Hartland SYSCTL_INT(_hw_ix, OID_AUTO, advertise_speed, CTLFLAG_RDTUN, 308f2c4db54SSteven Hartland &ixgbe_advertise_speed, 0, "Default advertised speed for all adapters"); 309f2c4db54SSteven Hartland 310758cc3dcSJack F Vogel /* 3118eb6488eSEric Joyner * Smart speed setting, default to on 3128eb6488eSEric Joyner * this only works as a compile option 3138eb6488eSEric Joyner * right now as its during attach, set 3148eb6488eSEric Joyner * this to 'ixgbe_smart_speed_off' to 3158eb6488eSEric Joyner * disable. 316758cc3dcSJack F Vogel */ 317758cc3dcSJack F Vogel static int ixgbe_smart_speed = ixgbe_smart_speed_on; 318758cc3dcSJack F Vogel 319758cc3dcSJack F Vogel /* 3208eb6488eSEric Joyner * MSI-X should be the default for best performance, 321758cc3dcSJack F Vogel * but this allows it to be forced off for testing. 322758cc3dcSJack F Vogel */ 323758cc3dcSJack F Vogel static int ixgbe_enable_msix = 1; 324758cc3dcSJack F Vogel SYSCTL_INT(_hw_ix, OID_AUTO, enable_msix, CTLFLAG_RDTUN, &ixgbe_enable_msix, 0, 325758cc3dcSJack F Vogel "Enable MSI-X interrupts"); 326758cc3dcSJack F Vogel 327758cc3dcSJack F Vogel /* 3288eb6488eSEric Joyner * Defining this on will allow the use 3298eb6488eSEric Joyner * of unsupported SFP+ modules, note that 3308eb6488eSEric Joyner * doing so you are on your own :) 331758cc3dcSJack F Vogel */ 332758cc3dcSJack F Vogel static int allow_unsupported_sfp = FALSE; 333fb6aa95dSSean Bruno SYSCTL_INT(_hw_ix, OID_AUTO, unsupported_sfp, CTLFLAG_RDTUN, 3348eb6488eSEric Joyner &allow_unsupported_sfp, 0, 3358eb6488eSEric Joyner "Allow unsupported SFP modules...use at your own risk"); 3368eb6488eSEric Joyner 3378eb6488eSEric Joyner /* 3388eb6488eSEric Joyner * Not sure if Flow Director is fully baked, 3398eb6488eSEric Joyner * so we'll default to turning it off. 3408eb6488eSEric Joyner */ 3418eb6488eSEric Joyner static int ixgbe_enable_fdir = 0; 3428eb6488eSEric Joyner SYSCTL_INT(_hw_ix, OID_AUTO, enable_fdir, CTLFLAG_RDTUN, &ixgbe_enable_fdir, 0, 3438eb6488eSEric Joyner "Enable Flow Director"); 3448eb6488eSEric Joyner 3458eb6488eSEric Joyner /* Receive-Side Scaling */ 3468eb6488eSEric Joyner static int ixgbe_enable_rss = 1; 3478eb6488eSEric Joyner SYSCTL_INT(_hw_ix, OID_AUTO, enable_rss, CTLFLAG_RDTUN, &ixgbe_enable_rss, 0, 3488eb6488eSEric Joyner "Enable Receive-Side Scaling (RSS)"); 349758cc3dcSJack F Vogel 350*64881da4SSai Rajesh Tallamraju /* 351*64881da4SSai Rajesh Tallamraju * AIM: Adaptive Interrupt Moderation 352*64881da4SSai Rajesh Tallamraju * which means that the interrupt rate 353*64881da4SSai Rajesh Tallamraju * is varied over time based on the 354*64881da4SSai Rajesh Tallamraju * traffic for that interrupt vector 355*64881da4SSai Rajesh Tallamraju */ 356*64881da4SSai Rajesh Tallamraju static int ixgbe_enable_aim = FALSE; 357*64881da4SSai Rajesh Tallamraju SYSCTL_INT(_hw_ix, OID_AUTO, enable_aim, CTLFLAG_RWTUN, &ixgbe_enable_aim, 0, 358*64881da4SSai Rajesh Tallamraju "Enable adaptive interrupt moderation"); 359*64881da4SSai Rajesh Tallamraju 360c19c7afeSEric Joyner #if 0 361758cc3dcSJack F Vogel /* Keep running tab on them for sanity check */ 362758cc3dcSJack F Vogel static int ixgbe_total_ports; 363c19c7afeSEric Joyner #endif 364758cc3dcSJack F Vogel 3658eb6488eSEric Joyner MALLOC_DEFINE(M_IXGBE, "ix", "ix driver allocations"); 366758cc3dcSJack F Vogel 367c19c7afeSEric Joyner /* 368c19c7afeSEric Joyner * For Flow Director: this is the number of TX packets we sample 369c19c7afeSEric Joyner * for the filter pool, this means every 20th packet will be probed. 370c19c7afeSEric Joyner * 371c19c7afeSEric Joyner * This feature can be disabled by setting this to 0. 372c19c7afeSEric Joyner */ 373c19c7afeSEric Joyner static int atr_sample_rate = 20; 374c19c7afeSEric Joyner 375c19c7afeSEric Joyner extern struct if_txrx ixgbe_txrx; 376c19c7afeSEric Joyner 377c19c7afeSEric Joyner static struct if_shared_ctx ixgbe_sctx_init = { 378c19c7afeSEric Joyner .isc_magic = IFLIB_MAGIC, 379c19c7afeSEric Joyner .isc_q_align = PAGE_SIZE,/* max(DBA_ALIGN, PAGE_SIZE) */ 3807f87c040SMarius Strobl .isc_tx_maxsize = IXGBE_TSO_SIZE + sizeof(struct ether_vlan_header), 381c19c7afeSEric Joyner .isc_tx_maxsegsize = PAGE_SIZE, 3827f87c040SMarius Strobl .isc_tso_maxsize = IXGBE_TSO_SIZE + sizeof(struct ether_vlan_header), 3837f87c040SMarius Strobl .isc_tso_maxsegsize = PAGE_SIZE, 384c19c7afeSEric Joyner .isc_rx_maxsize = PAGE_SIZE*4, 385c19c7afeSEric Joyner .isc_rx_nsegments = 1, 386c19c7afeSEric Joyner .isc_rx_maxsegsize = PAGE_SIZE*4, 387c19c7afeSEric Joyner .isc_nfl = 1, 388c19c7afeSEric Joyner .isc_ntxqs = 1, 389c19c7afeSEric Joyner .isc_nrxqs = 1, 390c19c7afeSEric Joyner 391c19c7afeSEric Joyner .isc_admin_intrcnt = 1, 392c19c7afeSEric Joyner .isc_vendor_info = ixgbe_vendor_info_array, 393c19c7afeSEric Joyner .isc_driver_version = ixgbe_driver_version, 394c19c7afeSEric Joyner .isc_driver = &ixgbe_if_driver, 3957aad1f4eSEric Joyner .isc_flags = IFLIB_TSO_INIT_IP, 396c19c7afeSEric Joyner 397c19c7afeSEric Joyner .isc_nrxd_min = {MIN_RXD}, 398c19c7afeSEric Joyner .isc_ntxd_min = {MIN_TXD}, 399c19c7afeSEric Joyner .isc_nrxd_max = {MAX_RXD}, 400c19c7afeSEric Joyner .isc_ntxd_max = {MAX_TXD}, 401c19c7afeSEric Joyner .isc_nrxd_default = {DEFAULT_RXD}, 402c19c7afeSEric Joyner .isc_ntxd_default = {DEFAULT_TXD}, 403c19c7afeSEric Joyner }; 404c19c7afeSEric Joyner 405c19c7afeSEric Joyner /************************************************************************ 406c19c7afeSEric Joyner * ixgbe_if_tx_queues_alloc 407c19c7afeSEric Joyner ************************************************************************/ 408c19c7afeSEric Joyner static int 409c19c7afeSEric Joyner ixgbe_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, 410c19c7afeSEric Joyner int ntxqs, int ntxqsets) 411c19c7afeSEric Joyner { 412c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 413c19c7afeSEric Joyner if_softc_ctx_t scctx = adapter->shared; 414c19c7afeSEric Joyner struct ix_tx_queue *que; 415c19c7afeSEric Joyner int i, j, error; 416c19c7afeSEric Joyner 417c19c7afeSEric Joyner MPASS(adapter->num_tx_queues > 0); 418c19c7afeSEric Joyner MPASS(adapter->num_tx_queues == ntxqsets); 419c19c7afeSEric Joyner MPASS(ntxqs == 1); 420c19c7afeSEric Joyner 421c19c7afeSEric Joyner /* Allocate queue structure memory */ 422c19c7afeSEric Joyner adapter->tx_queues = 423c19c7afeSEric Joyner (struct ix_tx_queue *)malloc(sizeof(struct ix_tx_queue) * ntxqsets, 424c19c7afeSEric Joyner M_IXGBE, M_NOWAIT | M_ZERO); 425c19c7afeSEric Joyner if (!adapter->tx_queues) { 426c19c7afeSEric Joyner device_printf(iflib_get_dev(ctx), 427c19c7afeSEric Joyner "Unable to allocate TX ring memory\n"); 428c19c7afeSEric Joyner return (ENOMEM); 429c19c7afeSEric Joyner } 430c19c7afeSEric Joyner 431c19c7afeSEric Joyner for (i = 0, que = adapter->tx_queues; i < ntxqsets; i++, que++) { 432c19c7afeSEric Joyner struct tx_ring *txr = &que->txr; 433c19c7afeSEric Joyner 434c19c7afeSEric Joyner /* In case SR-IOV is enabled, align the index properly */ 435c19c7afeSEric Joyner txr->me = ixgbe_vf_que_index(adapter->iov_mode, adapter->pool, 436c19c7afeSEric Joyner i); 437c19c7afeSEric Joyner 438c19c7afeSEric Joyner txr->adapter = que->adapter = adapter; 439c19c7afeSEric Joyner 440c19c7afeSEric Joyner /* Allocate report status array */ 441c19c7afeSEric Joyner txr->tx_rsq = (qidx_t *)malloc(sizeof(qidx_t) * scctx->isc_ntxd[0], M_IXGBE, M_NOWAIT | M_ZERO); 442c19c7afeSEric Joyner if (txr->tx_rsq == NULL) { 443c19c7afeSEric Joyner error = ENOMEM; 444c19c7afeSEric Joyner goto fail; 445c19c7afeSEric Joyner } 446c19c7afeSEric Joyner for (j = 0; j < scctx->isc_ntxd[0]; j++) 447c19c7afeSEric Joyner txr->tx_rsq[j] = QIDX_INVALID; 448c19c7afeSEric Joyner /* get the virtual and physical address of the hardware queues */ 449c19c7afeSEric Joyner txr->tail = IXGBE_TDT(txr->me); 450c19c7afeSEric Joyner txr->tx_base = (union ixgbe_adv_tx_desc *)vaddrs[i]; 451c19c7afeSEric Joyner txr->tx_paddr = paddrs[i]; 452c19c7afeSEric Joyner 453c19c7afeSEric Joyner txr->bytes = 0; 454c19c7afeSEric Joyner txr->total_packets = 0; 455c19c7afeSEric Joyner 456c19c7afeSEric Joyner /* Set the rate at which we sample packets */ 457c19c7afeSEric Joyner if (adapter->feat_en & IXGBE_FEATURE_FDIR) 458c19c7afeSEric Joyner txr->atr_sample = atr_sample_rate; 459c19c7afeSEric Joyner 460c19c7afeSEric Joyner } 461c19c7afeSEric Joyner 462c19c7afeSEric Joyner device_printf(iflib_get_dev(ctx), "allocated for %d queues\n", 463c19c7afeSEric Joyner adapter->num_tx_queues); 464c19c7afeSEric Joyner 465c19c7afeSEric Joyner return (0); 466c19c7afeSEric Joyner 467c19c7afeSEric Joyner fail: 468c19c7afeSEric Joyner ixgbe_if_queues_free(ctx); 469c19c7afeSEric Joyner 470c19c7afeSEric Joyner return (error); 471c19c7afeSEric Joyner } /* ixgbe_if_tx_queues_alloc */ 472c19c7afeSEric Joyner 473c19c7afeSEric Joyner /************************************************************************ 474c19c7afeSEric Joyner * ixgbe_if_rx_queues_alloc 475c19c7afeSEric Joyner ************************************************************************/ 476c19c7afeSEric Joyner static int 477c19c7afeSEric Joyner ixgbe_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, 478c19c7afeSEric Joyner int nrxqs, int nrxqsets) 479c19c7afeSEric Joyner { 480c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 481c19c7afeSEric Joyner struct ix_rx_queue *que; 482c19c7afeSEric Joyner int i; 483c19c7afeSEric Joyner 484c19c7afeSEric Joyner MPASS(adapter->num_rx_queues > 0); 485c19c7afeSEric Joyner MPASS(adapter->num_rx_queues == nrxqsets); 486c19c7afeSEric Joyner MPASS(nrxqs == 1); 487c19c7afeSEric Joyner 488c19c7afeSEric Joyner /* Allocate queue structure memory */ 489c19c7afeSEric Joyner adapter->rx_queues = 490c19c7afeSEric Joyner (struct ix_rx_queue *)malloc(sizeof(struct ix_rx_queue)*nrxqsets, 491c19c7afeSEric Joyner M_IXGBE, M_NOWAIT | M_ZERO); 492c19c7afeSEric Joyner if (!adapter->rx_queues) { 493c19c7afeSEric Joyner device_printf(iflib_get_dev(ctx), 494c19c7afeSEric Joyner "Unable to allocate TX ring memory\n"); 495c19c7afeSEric Joyner return (ENOMEM); 496c19c7afeSEric Joyner } 497c19c7afeSEric Joyner 498c19c7afeSEric Joyner for (i = 0, que = adapter->rx_queues; i < nrxqsets; i++, que++) { 499c19c7afeSEric Joyner struct rx_ring *rxr = &que->rxr; 500c19c7afeSEric Joyner 501c19c7afeSEric Joyner /* In case SR-IOV is enabled, align the index properly */ 502c19c7afeSEric Joyner rxr->me = ixgbe_vf_que_index(adapter->iov_mode, adapter->pool, 503c19c7afeSEric Joyner i); 504c19c7afeSEric Joyner 505c19c7afeSEric Joyner rxr->adapter = que->adapter = adapter; 506c19c7afeSEric Joyner 507c19c7afeSEric Joyner /* get the virtual and physical address of the hw queues */ 508c19c7afeSEric Joyner rxr->tail = IXGBE_RDT(rxr->me); 509c19c7afeSEric Joyner rxr->rx_base = (union ixgbe_adv_rx_desc *)vaddrs[i]; 510c19c7afeSEric Joyner rxr->rx_paddr = paddrs[i]; 511c19c7afeSEric Joyner rxr->bytes = 0; 512c19c7afeSEric Joyner rxr->que = que; 513c19c7afeSEric Joyner } 514c19c7afeSEric Joyner 515c19c7afeSEric Joyner device_printf(iflib_get_dev(ctx), "allocated for %d rx queues\n", 516c19c7afeSEric Joyner adapter->num_rx_queues); 517c19c7afeSEric Joyner 518c19c7afeSEric Joyner return (0); 519c19c7afeSEric Joyner } /* ixgbe_if_rx_queues_alloc */ 520c19c7afeSEric Joyner 521c19c7afeSEric Joyner /************************************************************************ 522c19c7afeSEric Joyner * ixgbe_if_queues_free 523c19c7afeSEric Joyner ************************************************************************/ 524c19c7afeSEric Joyner static void 525c19c7afeSEric Joyner ixgbe_if_queues_free(if_ctx_t ctx) 526c19c7afeSEric Joyner { 527c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 528c19c7afeSEric Joyner struct ix_tx_queue *tx_que = adapter->tx_queues; 529c19c7afeSEric Joyner struct ix_rx_queue *rx_que = adapter->rx_queues; 530c19c7afeSEric Joyner int i; 531c19c7afeSEric Joyner 532c19c7afeSEric Joyner if (tx_que != NULL) { 533c19c7afeSEric Joyner for (i = 0; i < adapter->num_tx_queues; i++, tx_que++) { 534c19c7afeSEric Joyner struct tx_ring *txr = &tx_que->txr; 535c19c7afeSEric Joyner if (txr->tx_rsq == NULL) 536c19c7afeSEric Joyner break; 537c19c7afeSEric Joyner 538c19c7afeSEric Joyner free(txr->tx_rsq, M_IXGBE); 539c19c7afeSEric Joyner txr->tx_rsq = NULL; 540c19c7afeSEric Joyner } 541c19c7afeSEric Joyner 542c19c7afeSEric Joyner free(adapter->tx_queues, M_IXGBE); 543c19c7afeSEric Joyner adapter->tx_queues = NULL; 544c19c7afeSEric Joyner } 545c19c7afeSEric Joyner if (rx_que != NULL) { 546c19c7afeSEric Joyner free(adapter->rx_queues, M_IXGBE); 547c19c7afeSEric Joyner adapter->rx_queues = NULL; 548c19c7afeSEric Joyner } 549c19c7afeSEric Joyner } /* ixgbe_if_queues_free */ 550c19c7afeSEric Joyner 5518eb6488eSEric Joyner /************************************************************************ 5528eb6488eSEric Joyner * ixgbe_initialize_rss_mapping 5538eb6488eSEric Joyner ************************************************************************/ 5548eb6488eSEric Joyner static void 5558eb6488eSEric Joyner ixgbe_initialize_rss_mapping(struct adapter *adapter) 556758cc3dcSJack F Vogel { 5576f37f232SEric Joyner struct ixgbe_hw *hw = &adapter->hw; 5588eb6488eSEric Joyner u32 reta = 0, mrqc, rss_key[10]; 5598eb6488eSEric Joyner int queue_id, table_size, index_mult; 5608eb6488eSEric Joyner int i, j; 5618eb6488eSEric Joyner u32 rss_hash_config; 5626f37f232SEric Joyner 5638eb6488eSEric Joyner if (adapter->feat_en & IXGBE_FEATURE_RSS) { 5648eb6488eSEric Joyner /* Fetch the configured RSS key */ 5658eb6488eSEric Joyner rss_getkey((uint8_t *)&rss_key); 566758cc3dcSJack F Vogel } else { 5678eb6488eSEric Joyner /* set up random bits */ 5688eb6488eSEric Joyner arc4rand(&rss_key, sizeof(rss_key), 0); 569758cc3dcSJack F Vogel } 570758cc3dcSJack F Vogel 5718eb6488eSEric Joyner /* Set multiplier for RETA setup and table size based on MAC */ 5728eb6488eSEric Joyner index_mult = 0x1; 5738eb6488eSEric Joyner table_size = 128; 5748eb6488eSEric Joyner switch (adapter->hw.mac.type) { 5758eb6488eSEric Joyner case ixgbe_mac_82598EB: 5768eb6488eSEric Joyner index_mult = 0x11; 577758cc3dcSJack F Vogel break; 5788eb6488eSEric Joyner case ixgbe_mac_X550: 5798eb6488eSEric Joyner case ixgbe_mac_X550EM_x: 5808eb6488eSEric Joyner case ixgbe_mac_X550EM_a: 5818eb6488eSEric Joyner table_size = 512; 5828eb6488eSEric Joyner break; 583758cc3dcSJack F Vogel default: 584758cc3dcSJack F Vogel break; 585758cc3dcSJack F Vogel } 586758cc3dcSJack F Vogel 5878eb6488eSEric Joyner /* Set up the redirection table */ 5888eb6488eSEric Joyner for (i = 0, j = 0; i < table_size; i++, j++) { 589c19c7afeSEric Joyner if (j == adapter->num_rx_queues) 5908eb6488eSEric Joyner j = 0; 591758cc3dcSJack F Vogel 5928eb6488eSEric Joyner if (adapter->feat_en & IXGBE_FEATURE_RSS) { 593a9ca1c79SSean Bruno /* 5948eb6488eSEric Joyner * Fetch the RSS bucket id for the given indirection 5958eb6488eSEric Joyner * entry. Cap it at the number of configured buckets 596c19c7afeSEric Joyner * (which is num_rx_queues.) 597a9ca1c79SSean Bruno */ 5988eb6488eSEric Joyner queue_id = rss_get_indirection_to_bucket(i); 599c19c7afeSEric Joyner queue_id = queue_id % adapter->num_rx_queues; 600758cc3dcSJack F Vogel } else 6018eb6488eSEric Joyner queue_id = (j * index_mult); 6028eb6488eSEric Joyner 6038eb6488eSEric Joyner /* 6048eb6488eSEric Joyner * The low 8 bits are for hash value (n+0); 6058eb6488eSEric Joyner * The next 8 bits are for hash value (n+1), etc. 6068eb6488eSEric Joyner */ 6078eb6488eSEric Joyner reta = reta >> 8; 6088eb6488eSEric Joyner reta = reta | (((uint32_t)queue_id) << 24); 6098eb6488eSEric Joyner if ((i & 3) == 3) { 6108eb6488eSEric Joyner if (i < 128) 6118eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); 6128eb6488eSEric Joyner else 6138eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32), 6148eb6488eSEric Joyner reta); 6158eb6488eSEric Joyner reta = 0; 6168eb6488eSEric Joyner } 617758cc3dcSJack F Vogel } 618758cc3dcSJack F Vogel 6198eb6488eSEric Joyner /* Now fill our hash function seeds */ 6208eb6488eSEric Joyner for (i = 0; i < 10; i++) 6218eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), rss_key[i]); 622758cc3dcSJack F Vogel 6238eb6488eSEric Joyner /* Perform hash on these packet types */ 6248eb6488eSEric Joyner if (adapter->feat_en & IXGBE_FEATURE_RSS) 6258eb6488eSEric Joyner rss_hash_config = rss_gethashconfig(); 626758cc3dcSJack F Vogel else { 627758cc3dcSJack F Vogel /* 6288eb6488eSEric Joyner * Disable UDP - IP fragments aren't currently being handled 6298eb6488eSEric Joyner * and so we end up with a mix of 2-tuple and 4-tuple 6308eb6488eSEric Joyner * traffic. 631758cc3dcSJack F Vogel */ 6328eb6488eSEric Joyner rss_hash_config = RSS_HASHTYPE_RSS_IPV4 6338eb6488eSEric Joyner | RSS_HASHTYPE_RSS_TCP_IPV4 6348eb6488eSEric Joyner | RSS_HASHTYPE_RSS_IPV6 6358eb6488eSEric Joyner | RSS_HASHTYPE_RSS_TCP_IPV6 6368eb6488eSEric Joyner | RSS_HASHTYPE_RSS_IPV6_EX 6378eb6488eSEric Joyner | RSS_HASHTYPE_RSS_TCP_IPV6_EX; 638758cc3dcSJack F Vogel } 639758cc3dcSJack F Vogel 6408eb6488eSEric Joyner mrqc = IXGBE_MRQC_RSSEN; 6418eb6488eSEric Joyner if (rss_hash_config & RSS_HASHTYPE_RSS_IPV4) 6428eb6488eSEric Joyner mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4; 6438eb6488eSEric Joyner if (rss_hash_config & RSS_HASHTYPE_RSS_TCP_IPV4) 6448eb6488eSEric Joyner mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_TCP; 6458eb6488eSEric Joyner if (rss_hash_config & RSS_HASHTYPE_RSS_IPV6) 6468eb6488eSEric Joyner mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6; 6478eb6488eSEric Joyner if (rss_hash_config & RSS_HASHTYPE_RSS_TCP_IPV6) 6488eb6488eSEric Joyner mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_TCP; 6498eb6488eSEric Joyner if (rss_hash_config & RSS_HASHTYPE_RSS_IPV6_EX) 6508eb6488eSEric Joyner mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_EX; 6518eb6488eSEric Joyner if (rss_hash_config & RSS_HASHTYPE_RSS_TCP_IPV6_EX) 6528eb6488eSEric Joyner mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP; 6538eb6488eSEric Joyner if (rss_hash_config & RSS_HASHTYPE_RSS_UDP_IPV4) 6548eb6488eSEric Joyner mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP; 6558eb6488eSEric Joyner if (rss_hash_config & RSS_HASHTYPE_RSS_UDP_IPV6) 6568eb6488eSEric Joyner mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP; 6578eb6488eSEric Joyner if (rss_hash_config & RSS_HASHTYPE_RSS_UDP_IPV6_EX) 6588eb6488eSEric Joyner mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP; 6598eb6488eSEric Joyner mrqc |= ixgbe_get_mrqc(adapter->iov_mode); 6608eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); 6618eb6488eSEric Joyner } /* ixgbe_initialize_rss_mapping */ 662758cc3dcSJack F Vogel 6638eb6488eSEric Joyner /************************************************************************ 6648eb6488eSEric Joyner * ixgbe_initialize_receive_units - Setup receive registers and features. 6658eb6488eSEric Joyner ************************************************************************/ 6668eb6488eSEric Joyner #define BSIZEPKT_ROUNDUP ((1<<IXGBE_SRRCTL_BSIZEPKT_SHIFT)-1) 667758cc3dcSJack F Vogel 668758cc3dcSJack F Vogel static void 669c19c7afeSEric Joyner ixgbe_initialize_receive_units(if_ctx_t ctx) 670758cc3dcSJack F Vogel { 671c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 672c19c7afeSEric Joyner if_softc_ctx_t scctx = adapter->shared; 67348056c88SJack F Vogel struct ixgbe_hw *hw = &adapter->hw; 674c19c7afeSEric Joyner struct ifnet *ifp = iflib_get_ifp(ctx); 675c19c7afeSEric Joyner struct ix_rx_queue *que; 6768eb6488eSEric Joyner int i, j; 6778eb6488eSEric Joyner u32 bufsz, fctrl, srrctl, rxcsum; 6788eb6488eSEric Joyner u32 hlreg; 67948056c88SJack F Vogel 68048056c88SJack F Vogel /* 6818eb6488eSEric Joyner * Make sure receives are disabled while 6828eb6488eSEric Joyner * setting up the descriptor ring 68348056c88SJack F Vogel */ 6848eb6488eSEric Joyner ixgbe_disable_rx(hw); 6858eb6488eSEric Joyner 6868eb6488eSEric Joyner /* Enable broadcasts */ 6878eb6488eSEric Joyner fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); 6888eb6488eSEric Joyner fctrl |= IXGBE_FCTRL_BAM; 6898eb6488eSEric Joyner if (adapter->hw.mac.type == ixgbe_mac_82598EB) { 6908eb6488eSEric Joyner fctrl |= IXGBE_FCTRL_DPF; 6918eb6488eSEric Joyner fctrl |= IXGBE_FCTRL_PMCF; 69248056c88SJack F Vogel } 6938eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); 6948eb6488eSEric Joyner 6958eb6488eSEric Joyner /* Set for Jumbo Frames? */ 6968eb6488eSEric Joyner hlreg = IXGBE_READ_REG(hw, IXGBE_HLREG0); 6978eb6488eSEric Joyner if (ifp->if_mtu > ETHERMTU) 6988eb6488eSEric Joyner hlreg |= IXGBE_HLREG0_JUMBOEN; 6998eb6488eSEric Joyner else 7008eb6488eSEric Joyner hlreg &= ~IXGBE_HLREG0_JUMBOEN; 7018eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg); 7028eb6488eSEric Joyner 7038eb6488eSEric Joyner bufsz = (adapter->rx_mbuf_sz + BSIZEPKT_ROUNDUP) >> 7048eb6488eSEric Joyner IXGBE_SRRCTL_BSIZEPKT_SHIFT; 7058eb6488eSEric Joyner 706c19c7afeSEric Joyner /* Setup the Base and Length of the Rx Descriptor Ring */ 707c19c7afeSEric Joyner for (i = 0, que = adapter->rx_queues; i < adapter->num_rx_queues; i++, que++) { 708c19c7afeSEric Joyner struct rx_ring *rxr = &que->rxr; 709c19c7afeSEric Joyner u64 rdba = rxr->rx_paddr; 710c19c7afeSEric Joyner 7118eb6488eSEric Joyner j = rxr->me; 7128eb6488eSEric Joyner 7138eb6488eSEric Joyner /* Setup the Base and Length of the Rx Descriptor Ring */ 7148eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), 7158eb6488eSEric Joyner (rdba & 0x00000000ffffffffULL)); 7168eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32)); 7178eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), 718c19c7afeSEric Joyner scctx->isc_nrxd[0] * sizeof(union ixgbe_adv_rx_desc)); 7198eb6488eSEric Joyner 7208eb6488eSEric Joyner /* Set up the SRRCTL register */ 7218eb6488eSEric Joyner srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(j)); 7228eb6488eSEric Joyner srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; 7238eb6488eSEric Joyner srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; 7248eb6488eSEric Joyner srrctl |= bufsz; 7258eb6488eSEric Joyner srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; 72648056c88SJack F Vogel 72748056c88SJack F Vogel /* 7288eb6488eSEric Joyner * Set DROP_EN iff we have no flow control and >1 queue. 7298eb6488eSEric Joyner * Note that srrctl was cleared shortly before during reset, 7308eb6488eSEric Joyner * so we do not need to clear the bit, but do it just in case 7318eb6488eSEric Joyner * this code is moved elsewhere. 73248056c88SJack F Vogel */ 733c19c7afeSEric Joyner if (adapter->num_rx_queues > 1 && 7348eb6488eSEric Joyner adapter->hw.fc.requested_mode == ixgbe_fc_none) { 7358eb6488eSEric Joyner srrctl |= IXGBE_SRRCTL_DROP_EN; 736758cc3dcSJack F Vogel } else { 7378eb6488eSEric Joyner srrctl &= ~IXGBE_SRRCTL_DROP_EN; 738758cc3dcSJack F Vogel } 739758cc3dcSJack F Vogel 7408eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(j), srrctl); 741758cc3dcSJack F Vogel 7428eb6488eSEric Joyner /* Setup the HW Rx Head and Tail Descriptor Pointers */ 7438eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0); 7448eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0); 745758cc3dcSJack F Vogel 7468eb6488eSEric Joyner /* Set the driver rx tail address */ 7478eb6488eSEric Joyner rxr->tail = IXGBE_RDT(rxr->me); 748a9ca1c79SSean Bruno } 749758cc3dcSJack F Vogel 750758cc3dcSJack F Vogel if (adapter->hw.mac.type != ixgbe_mac_82598EB) { 7518eb6488eSEric Joyner u32 psrtype = IXGBE_PSRTYPE_TCPHDR 7528eb6488eSEric Joyner | IXGBE_PSRTYPE_UDPHDR 7538eb6488eSEric Joyner | IXGBE_PSRTYPE_IPV4HDR 7548eb6488eSEric Joyner | IXGBE_PSRTYPE_IPV6HDR; 7558eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype); 7566f37f232SEric Joyner } 7576f37f232SEric Joyner 7588eb6488eSEric Joyner rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); 7598eb6488eSEric Joyner 7608eb6488eSEric Joyner ixgbe_initialize_rss_mapping(adapter); 7618eb6488eSEric Joyner 762c19c7afeSEric Joyner if (adapter->num_rx_queues > 1) { 7638eb6488eSEric Joyner /* RSS and RX IPP Checksum are mutually exclusive */ 7648eb6488eSEric Joyner rxcsum |= IXGBE_RXCSUM_PCSD; 7656f37f232SEric Joyner } 7666f37f232SEric Joyner 7678eb6488eSEric Joyner if (ifp->if_capenable & IFCAP_RXCSUM) 7688eb6488eSEric Joyner rxcsum |= IXGBE_RXCSUM_PCSD; 769758cc3dcSJack F Vogel 7708eb6488eSEric Joyner /* This is useful for calculating UDP/IP fragment checksums */ 7718eb6488eSEric Joyner if (!(rxcsum & IXGBE_RXCSUM_PCSD)) 7728eb6488eSEric Joyner rxcsum |= IXGBE_RXCSUM_IPPCSE; 773758cc3dcSJack F Vogel 7748eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); 775758cc3dcSJack F Vogel 7768eb6488eSEric Joyner } /* ixgbe_initialize_receive_units */ 777758cc3dcSJack F Vogel 7788eb6488eSEric Joyner /************************************************************************ 7798eb6488eSEric Joyner * ixgbe_initialize_transmit_units - Enable transmit units. 7808eb6488eSEric Joyner ************************************************************************/ 781758cc3dcSJack F Vogel static void 782c19c7afeSEric Joyner ixgbe_initialize_transmit_units(if_ctx_t ctx) 783758cc3dcSJack F Vogel { 784c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 785758cc3dcSJack F Vogel struct ixgbe_hw *hw = &adapter->hw; 786c19c7afeSEric Joyner if_softc_ctx_t scctx = adapter->shared; 787c19c7afeSEric Joyner struct ix_tx_queue *que; 788c19c7afeSEric Joyner int i; 789758cc3dcSJack F Vogel 790758cc3dcSJack F Vogel /* Setup the Base and Length of the Tx Descriptor Ring */ 791c19c7afeSEric Joyner for (i = 0, que = adapter->tx_queues; i < adapter->num_tx_queues; 792c19c7afeSEric Joyner i++, que++) { 793c19c7afeSEric Joyner struct tx_ring *txr = &que->txr; 794c19c7afeSEric Joyner u64 tdba = txr->tx_paddr; 795758cc3dcSJack F Vogel u32 txctrl = 0; 79648056c88SJack F Vogel int j = txr->me; 797758cc3dcSJack F Vogel 79848056c88SJack F Vogel IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j), 799758cc3dcSJack F Vogel (tdba & 0x00000000ffffffffULL)); 80048056c88SJack F Vogel IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32)); 80148056c88SJack F Vogel IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), 802c19c7afeSEric Joyner scctx->isc_ntxd[0] * sizeof(union ixgbe_adv_tx_desc)); 803758cc3dcSJack F Vogel 804758cc3dcSJack F Vogel /* Setup the HW Tx Head and Tail descriptor pointers */ 80548056c88SJack F Vogel IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0); 80648056c88SJack F Vogel IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0); 807758cc3dcSJack F Vogel 808758cc3dcSJack F Vogel /* Cache the tail address */ 8092dc2d580SEric Joyner txr->tail = IXGBE_TDT(txr->me); 8102dc2d580SEric Joyner 811088a0b27SEric Joyner txr->tx_rs_cidx = txr->tx_rs_pidx; 812088a0b27SEric Joyner txr->tx_cidx_processed = scctx->isc_ntxd[0] - 1; 813c19c7afeSEric Joyner for (int k = 0; k < scctx->isc_ntxd[0]; k++) 814c19c7afeSEric Joyner txr->tx_rsq[k] = QIDX_INVALID; 815758cc3dcSJack F Vogel 816758cc3dcSJack F Vogel /* Disable Head Writeback */ 817a9ca1c79SSean Bruno /* 818a9ca1c79SSean Bruno * Note: for X550 series devices, these registers are actually 819a9ca1c79SSean Bruno * prefixed with TPH_ isntead of DCA_, but the addresses and 820a9ca1c79SSean Bruno * fields remain the same. 821a9ca1c79SSean Bruno */ 822758cc3dcSJack F Vogel switch (hw->mac.type) { 823758cc3dcSJack F Vogel case ixgbe_mac_82598EB: 82448056c88SJack F Vogel txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j)); 825758cc3dcSJack F Vogel break; 826758cc3dcSJack F Vogel default: 82748056c88SJack F Vogel txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(j)); 828758cc3dcSJack F Vogel break; 829758cc3dcSJack F Vogel } 830758cc3dcSJack F Vogel txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN; 831758cc3dcSJack F Vogel switch (hw->mac.type) { 832758cc3dcSJack F Vogel case ixgbe_mac_82598EB: 83348056c88SJack F Vogel IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl); 834758cc3dcSJack F Vogel break; 835758cc3dcSJack F Vogel default: 83648056c88SJack F Vogel IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(j), txctrl); 837758cc3dcSJack F Vogel break; 838758cc3dcSJack F Vogel } 839758cc3dcSJack F Vogel 840758cc3dcSJack F Vogel } 841758cc3dcSJack F Vogel 842758cc3dcSJack F Vogel if (hw->mac.type != ixgbe_mac_82598EB) { 843758cc3dcSJack F Vogel u32 dmatxctl, rttdcs; 8448eb6488eSEric Joyner 845758cc3dcSJack F Vogel dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); 846758cc3dcSJack F Vogel dmatxctl |= IXGBE_DMATXCTL_TE; 847758cc3dcSJack F Vogel IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); 848758cc3dcSJack F Vogel /* Disable arbiter to set MTQC */ 849758cc3dcSJack F Vogel rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); 850758cc3dcSJack F Vogel rttdcs |= IXGBE_RTTDCS_ARBDIS; 851758cc3dcSJack F Vogel IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); 8528eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_MTQC, 8538eb6488eSEric Joyner ixgbe_get_mtqc(adapter->iov_mode)); 854758cc3dcSJack F Vogel rttdcs &= ~IXGBE_RTTDCS_ARBDIS; 855758cc3dcSJack F Vogel IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); 856758cc3dcSJack F Vogel } 857758cc3dcSJack F Vogel 8588eb6488eSEric Joyner } /* ixgbe_initialize_transmit_units */ 859758cc3dcSJack F Vogel 8608eb6488eSEric Joyner /************************************************************************ 861c19c7afeSEric Joyner * ixgbe_register 862c19c7afeSEric Joyner ************************************************************************/ 863c19c7afeSEric Joyner static void * 864c19c7afeSEric Joyner ixgbe_register(device_t dev) 865c19c7afeSEric Joyner { 866ffe3def9SMark Johnston return (&ixgbe_sctx_init); 867c19c7afeSEric Joyner } /* ixgbe_register */ 868c19c7afeSEric Joyner 869c19c7afeSEric Joyner /************************************************************************ 870c19c7afeSEric Joyner * ixgbe_if_attach_pre - Device initialization routine, part 1 871758cc3dcSJack F Vogel * 8728eb6488eSEric Joyner * Called when the driver is being loaded. 873c19c7afeSEric Joyner * Identifies the type of hardware, initializes the hardware, 874c19c7afeSEric Joyner * and initializes iflib structures. 875758cc3dcSJack F Vogel * 8768eb6488eSEric Joyner * return 0 on success, positive on failure 8778eb6488eSEric Joyner ************************************************************************/ 8788eb6488eSEric Joyner static int 879c19c7afeSEric Joyner ixgbe_if_attach_pre(if_ctx_t ctx) 880758cc3dcSJack F Vogel { 8818eb6488eSEric Joyner struct adapter *adapter; 882c19c7afeSEric Joyner device_t dev; 883c19c7afeSEric Joyner if_softc_ctx_t scctx; 8848eb6488eSEric Joyner struct ixgbe_hw *hw; 8858eb6488eSEric Joyner int error = 0; 8868eb6488eSEric Joyner u32 ctrl_ext; 8878eb6488eSEric Joyner 8888eb6488eSEric Joyner INIT_DEBUGOUT("ixgbe_attach: begin"); 8898eb6488eSEric Joyner 8908eb6488eSEric Joyner /* Allocate, clear, and link in our adapter structure */ 891c19c7afeSEric Joyner dev = iflib_get_dev(ctx); 892c19c7afeSEric Joyner adapter = iflib_get_softc(ctx); 8938eb6488eSEric Joyner adapter->hw.back = adapter; 894c19c7afeSEric Joyner adapter->ctx = ctx; 8958eb6488eSEric Joyner adapter->dev = dev; 896c19c7afeSEric Joyner scctx = adapter->shared = iflib_get_softc_ctx(ctx); 897c19c7afeSEric Joyner adapter->media = iflib_get_media(ctx); 8988eb6488eSEric Joyner hw = &adapter->hw; 8998eb6488eSEric Joyner 9008eb6488eSEric Joyner /* Determine hardware revision */ 9018eb6488eSEric Joyner hw->vendor_id = pci_get_vendor(dev); 9028eb6488eSEric Joyner hw->device_id = pci_get_device(dev); 9038eb6488eSEric Joyner hw->revision_id = pci_get_revid(dev); 9048eb6488eSEric Joyner hw->subsystem_vendor_id = pci_get_subvendor(dev); 9058eb6488eSEric Joyner hw->subsystem_device_id = pci_get_subdevice(dev); 906758cc3dcSJack F Vogel 9078eb6488eSEric Joyner /* Do base PCI setup - map BAR0 */ 908c19c7afeSEric Joyner if (ixgbe_allocate_pci_resources(ctx)) { 9098eb6488eSEric Joyner device_printf(dev, "Allocation of PCI resources failed\n"); 910c19c7afeSEric Joyner return (ENXIO); 9116f37f232SEric Joyner } 912758cc3dcSJack F Vogel 9138eb6488eSEric Joyner /* let hardware know driver is loaded */ 9148eb6488eSEric Joyner ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); 9158eb6488eSEric Joyner ctrl_ext |= IXGBE_CTRL_EXT_DRV_LOAD; 9168eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); 917758cc3dcSJack F Vogel 918758cc3dcSJack F Vogel /* 9198eb6488eSEric Joyner * Initialize the shared code 920758cc3dcSJack F Vogel */ 921c19c7afeSEric Joyner if (ixgbe_init_shared_code(hw) != 0) { 9228eb6488eSEric Joyner device_printf(dev, "Unable to initialize the shared code\n"); 9238eb6488eSEric Joyner error = ENXIO; 924c19c7afeSEric Joyner goto err_pci; 92530126537SJack F Vogel } 926758cc3dcSJack F Vogel 9278eb6488eSEric Joyner if (hw->mbx.ops.init_params) 9288eb6488eSEric Joyner hw->mbx.ops.init_params(hw); 929758cc3dcSJack F Vogel 9308eb6488eSEric Joyner hw->allow_unsupported_sfp = allow_unsupported_sfp; 931758cc3dcSJack F Vogel 932c19c7afeSEric Joyner if (hw->mac.type != ixgbe_mac_82598EB) 9338eb6488eSEric Joyner hw->phy.smart_speed = ixgbe_smart_speed; 9348eb6488eSEric Joyner 9358eb6488eSEric Joyner ixgbe_init_device_features(adapter); 9368eb6488eSEric Joyner 9378eb6488eSEric Joyner /* Enable WoL (if supported) */ 9388eb6488eSEric Joyner ixgbe_check_wol_support(adapter); 9398eb6488eSEric Joyner 9408eb6488eSEric Joyner /* Verify adapter fan is still functional (if applicable) */ 9418eb6488eSEric Joyner if (adapter->feat_en & IXGBE_FEATURE_FAN_FAIL) { 9428eb6488eSEric Joyner u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); 9438eb6488eSEric Joyner ixgbe_check_fan_failure(adapter, esdp, FALSE); 9448eb6488eSEric Joyner } 9458eb6488eSEric Joyner 9468eb6488eSEric Joyner /* Ensure SW/FW semaphore is free */ 9478eb6488eSEric Joyner ixgbe_init_swfw_semaphore(hw); 9488eb6488eSEric Joyner 9498eb6488eSEric Joyner /* Set an initial default flow control value */ 9508eb6488eSEric Joyner hw->fc.requested_mode = ixgbe_flow_control; 9518eb6488eSEric Joyner 9528eb6488eSEric Joyner hw->phy.reset_if_overtemp = TRUE; 9538eb6488eSEric Joyner error = ixgbe_reset_hw(hw); 9548eb6488eSEric Joyner hw->phy.reset_if_overtemp = FALSE; 9558eb6488eSEric Joyner if (error == IXGBE_ERR_SFP_NOT_PRESENT) { 956758cc3dcSJack F Vogel /* 9578eb6488eSEric Joyner * No optics in this port, set up 9588eb6488eSEric Joyner * so the timer routine will probe 9598eb6488eSEric Joyner * for later insertion. 960758cc3dcSJack F Vogel */ 9618eb6488eSEric Joyner adapter->sfp_probe = TRUE; 962c19c7afeSEric Joyner error = 0; 9638eb6488eSEric Joyner } else if (error == IXGBE_ERR_SFP_NOT_SUPPORTED) { 9648eb6488eSEric Joyner device_printf(dev, "Unsupported SFP+ module detected!\n"); 9658eb6488eSEric Joyner error = EIO; 966c19c7afeSEric Joyner goto err_pci; 9678eb6488eSEric Joyner } else if (error) { 9688eb6488eSEric Joyner device_printf(dev, "Hardware initialization failed\n"); 9698eb6488eSEric Joyner error = EIO; 970c19c7afeSEric Joyner goto err_pci; 97197f9586eSSean Bruno } 97297f9586eSSean Bruno 9738eb6488eSEric Joyner /* Make sure we have a good EEPROM before we read from it */ 9748eb6488eSEric Joyner if (ixgbe_validate_eeprom_checksum(&adapter->hw, NULL) < 0) { 9758eb6488eSEric Joyner device_printf(dev, "The EEPROM Checksum Is Not Valid\n"); 9768eb6488eSEric Joyner error = EIO; 977c19c7afeSEric Joyner goto err_pci; 97897f9586eSSean Bruno } 97997f9586eSSean Bruno 9808eb6488eSEric Joyner error = ixgbe_start_hw(hw); 9818eb6488eSEric Joyner switch (error) { 9828eb6488eSEric Joyner case IXGBE_ERR_EEPROM_VERSION: 9838eb6488eSEric Joyner device_printf(dev, "This device is a pre-production adapter/LOM. Please be aware there may be issues associated with your hardware.\nIf you are experiencing problems please contact your Intel or hardware representative who provided you with this hardware.\n"); 98497f9586eSSean Bruno break; 9858eb6488eSEric Joyner case IXGBE_ERR_SFP_NOT_SUPPORTED: 9868eb6488eSEric Joyner device_printf(dev, "Unsupported SFP+ Module\n"); 9878eb6488eSEric Joyner error = EIO; 988c19c7afeSEric Joyner goto err_pci; 9898eb6488eSEric Joyner case IXGBE_ERR_SFP_NOT_PRESENT: 9908eb6488eSEric Joyner device_printf(dev, "No SFP+ Module found\n"); 9918eb6488eSEric Joyner /* falls thru */ 99297f9586eSSean Bruno default: 99397f9586eSSean Bruno break; 99497f9586eSSean Bruno } 99597f9586eSSean Bruno 996c19c7afeSEric Joyner /* Most of the iflib initialization... */ 997c19c7afeSEric Joyner 998c19c7afeSEric Joyner iflib_set_mac(ctx, hw->mac.addr); 999c19c7afeSEric Joyner switch (adapter->hw.mac.type) { 1000c19c7afeSEric Joyner case ixgbe_mac_X550: 1001c19c7afeSEric Joyner case ixgbe_mac_X550EM_x: 1002c19c7afeSEric Joyner case ixgbe_mac_X550EM_a: 1003c19c7afeSEric Joyner scctx->isc_rss_table_size = 512; 1004c19c7afeSEric Joyner scctx->isc_ntxqsets_max = scctx->isc_nrxqsets_max = 64; 1005c19c7afeSEric Joyner break; 1006c19c7afeSEric Joyner default: 1007c19c7afeSEric Joyner scctx->isc_rss_table_size = 128; 1008c19c7afeSEric Joyner scctx->isc_ntxqsets_max = scctx->isc_nrxqsets_max = 16; 1009c19c7afeSEric Joyner } 1010c19c7afeSEric Joyner 1011c19c7afeSEric Joyner /* Allow legacy interrupts */ 1012c19c7afeSEric Joyner ixgbe_txrx.ift_legacy_intr = ixgbe_intr; 1013c19c7afeSEric Joyner 1014c19c7afeSEric Joyner scctx->isc_txqsizes[0] = 1015c19c7afeSEric Joyner roundup2(scctx->isc_ntxd[0] * sizeof(union ixgbe_adv_tx_desc) + 1016c19c7afeSEric Joyner sizeof(u32), DBA_ALIGN), 1017c19c7afeSEric Joyner scctx->isc_rxqsizes[0] = 1018c19c7afeSEric Joyner roundup2(scctx->isc_nrxd[0] * sizeof(union ixgbe_adv_rx_desc), 1019c19c7afeSEric Joyner DBA_ALIGN); 1020c19c7afeSEric Joyner 1021c19c7afeSEric Joyner /* XXX */ 1022c19c7afeSEric Joyner scctx->isc_tx_csum_flags = CSUM_IP | CSUM_TCP | CSUM_UDP | CSUM_TSO | 1023c19c7afeSEric Joyner CSUM_IP6_TCP | CSUM_IP6_UDP | CSUM_IP6_TSO; 1024c19c7afeSEric Joyner if (adapter->hw.mac.type == ixgbe_mac_82598EB) { 1025c19c7afeSEric Joyner scctx->isc_tx_nsegments = IXGBE_82598_SCATTER; 1026c19c7afeSEric Joyner } else { 1027c19c7afeSEric Joyner scctx->isc_tx_csum_flags |= CSUM_SCTP |CSUM_IP6_SCTP; 1028c19c7afeSEric Joyner scctx->isc_tx_nsegments = IXGBE_82599_SCATTER; 1029c19c7afeSEric Joyner } 1030749597dcSEric Joyner 1031749597dcSEric Joyner scctx->isc_msix_bar = pci_msix_table_bar(dev); 1032749597dcSEric Joyner 1033c19c7afeSEric Joyner scctx->isc_tx_tso_segments_max = scctx->isc_tx_nsegments; 1034c19c7afeSEric Joyner scctx->isc_tx_tso_size_max = IXGBE_TSO_SIZE; 1035c19c7afeSEric Joyner scctx->isc_tx_tso_segsize_max = PAGE_SIZE; 1036c19c7afeSEric Joyner 1037c19c7afeSEric Joyner scctx->isc_txrx = &ixgbe_txrx; 1038c19c7afeSEric Joyner 10397f87c040SMarius Strobl scctx->isc_capabilities = scctx->isc_capenable = IXGBE_CAPS; 1040c19c7afeSEric Joyner 1041c19c7afeSEric Joyner return (0); 1042c19c7afeSEric Joyner 1043c19c7afeSEric Joyner err_pci: 1044c19c7afeSEric Joyner ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); 1045c19c7afeSEric Joyner ctrl_ext &= ~IXGBE_CTRL_EXT_DRV_LOAD; 1046c19c7afeSEric Joyner IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, ctrl_ext); 1047c19c7afeSEric Joyner ixgbe_free_pci_resources(ctx); 1048c19c7afeSEric Joyner 1049c19c7afeSEric Joyner return (error); 1050c19c7afeSEric Joyner } /* ixgbe_if_attach_pre */ 1051c19c7afeSEric Joyner 1052c19c7afeSEric Joyner /********************************************************************* 1053c19c7afeSEric Joyner * ixgbe_if_attach_post - Device initialization routine, part 2 1054c19c7afeSEric Joyner * 1055c19c7afeSEric Joyner * Called during driver load, but after interrupts and 1056c19c7afeSEric Joyner * resources have been allocated and configured. 1057c19c7afeSEric Joyner * Sets up some data structures not relevant to iflib. 1058c19c7afeSEric Joyner * 1059c19c7afeSEric Joyner * return 0 on success, positive on failure 1060c19c7afeSEric Joyner *********************************************************************/ 1061c19c7afeSEric Joyner static int 1062c19c7afeSEric Joyner ixgbe_if_attach_post(if_ctx_t ctx) 1063c19c7afeSEric Joyner { 1064c19c7afeSEric Joyner device_t dev; 1065c19c7afeSEric Joyner struct adapter *adapter; 1066c19c7afeSEric Joyner struct ixgbe_hw *hw; 1067c19c7afeSEric Joyner int error = 0; 1068c19c7afeSEric Joyner 1069c19c7afeSEric Joyner dev = iflib_get_dev(ctx); 1070c19c7afeSEric Joyner adapter = iflib_get_softc(ctx); 1071c19c7afeSEric Joyner hw = &adapter->hw; 1072c19c7afeSEric Joyner 1073c19c7afeSEric Joyner 1074c19c7afeSEric Joyner if (adapter->intr_type == IFLIB_INTR_LEGACY && 1075c19c7afeSEric Joyner (adapter->feat_cap & IXGBE_FEATURE_LEGACY_IRQ) == 0) { 1076c19c7afeSEric Joyner device_printf(dev, "Device does not support legacy interrupts"); 1077c19c7afeSEric Joyner error = ENXIO; 1078c19c7afeSEric Joyner goto err; 1079c19c7afeSEric Joyner } 1080c19c7afeSEric Joyner 1081c19c7afeSEric Joyner /* Allocate multicast array memory. */ 1082c19c7afeSEric Joyner adapter->mta = malloc(sizeof(*adapter->mta) * 1083c19c7afeSEric Joyner MAX_NUM_MULTICAST_ADDRESSES, M_IXGBE, M_NOWAIT); 1084c19c7afeSEric Joyner if (adapter->mta == NULL) { 1085c19c7afeSEric Joyner device_printf(dev, "Can not allocate multicast setup array\n"); 1086c19c7afeSEric Joyner error = ENOMEM; 1087c19c7afeSEric Joyner goto err; 1088c19c7afeSEric Joyner } 1089c19c7afeSEric Joyner 1090c19c7afeSEric Joyner /* hw.ix defaults init */ 1091c19c7afeSEric Joyner ixgbe_set_advertise(adapter, ixgbe_advertise_speed); 1092c19c7afeSEric Joyner 10938eb6488eSEric Joyner /* Enable the optics for 82599 SFP+ fiber */ 10948eb6488eSEric Joyner ixgbe_enable_tx_laser(hw); 1095758cc3dcSJack F Vogel 10968eb6488eSEric Joyner /* Enable power to the phy. */ 10978eb6488eSEric Joyner ixgbe_set_phy_power(hw, TRUE); 10988eb6488eSEric Joyner 1099c19c7afeSEric Joyner ixgbe_initialize_iov(adapter); 1100c19c7afeSEric Joyner 1101c19c7afeSEric Joyner error = ixgbe_setup_interface(ctx); 1102c19c7afeSEric Joyner if (error) { 1103c19c7afeSEric Joyner device_printf(dev, "Interface setup failed: %d\n", error); 1104c19c7afeSEric Joyner goto err; 1105c19c7afeSEric Joyner } 1106c19c7afeSEric Joyner 1107c19c7afeSEric Joyner ixgbe_if_update_admin_status(ctx); 1108c19c7afeSEric Joyner 11098eb6488eSEric Joyner /* Initialize statistics */ 11108eb6488eSEric Joyner ixgbe_update_stats_counters(adapter); 1111c19c7afeSEric Joyner ixgbe_add_hw_stats(adapter); 11128eb6488eSEric Joyner 11138eb6488eSEric Joyner /* Check PCIE slot type/speed/width */ 11148eb6488eSEric Joyner ixgbe_get_slot_info(adapter); 1115758cc3dcSJack F Vogel 1116758cc3dcSJack F Vogel /* 11178eb6488eSEric Joyner * Do time init and sysctl init here, but 11188eb6488eSEric Joyner * only on the first port of a bypass adapter. 1119758cc3dcSJack F Vogel */ 11208eb6488eSEric Joyner ixgbe_bypass_init(adapter); 1121758cc3dcSJack F Vogel 11228eb6488eSEric Joyner /* Set an initial dmac value */ 11238eb6488eSEric Joyner adapter->dmac = 0; 11248eb6488eSEric Joyner /* Set initial advertised speeds (if applicable) */ 11258eb6488eSEric Joyner adapter->advertise = ixgbe_get_advertise(adapter); 1126758cc3dcSJack F Vogel 11278eb6488eSEric Joyner if (adapter->feat_cap & IXGBE_FEATURE_SRIOV) 11288eb6488eSEric Joyner ixgbe_define_iov_schemas(dev, &error); 1129758cc3dcSJack F Vogel 11308eb6488eSEric Joyner /* Add sysctls */ 1131c19c7afeSEric Joyner ixgbe_add_device_sysctls(ctx); 1132758cc3dcSJack F Vogel 11338eb6488eSEric Joyner return (0); 1134c19c7afeSEric Joyner err: 11358eb6488eSEric Joyner return (error); 1136c19c7afeSEric Joyner } /* ixgbe_if_attach_post */ 11378eb6488eSEric Joyner 11388eb6488eSEric Joyner /************************************************************************ 11398eb6488eSEric Joyner * ixgbe_check_wol_support 11406f37f232SEric Joyner * 11416f37f232SEric Joyner * Checks whether the adapter's ports are capable of 11426f37f232SEric Joyner * Wake On LAN by reading the adapter's NVM. 11436f37f232SEric Joyner * 11446f37f232SEric Joyner * Sets each port's hw->wol_enabled value depending 11456f37f232SEric Joyner * on the value read here. 11468eb6488eSEric Joyner ************************************************************************/ 11476f37f232SEric Joyner static void 11486f37f232SEric Joyner ixgbe_check_wol_support(struct adapter *adapter) 11496f37f232SEric Joyner { 11506f37f232SEric Joyner struct ixgbe_hw *hw = &adapter->hw; 11516f37f232SEric Joyner u16 dev_caps = 0; 11526f37f232SEric Joyner 11536f37f232SEric Joyner /* Find out WoL support for port */ 11546f37f232SEric Joyner adapter->wol_support = hw->wol_enabled = 0; 11556f37f232SEric Joyner ixgbe_get_device_caps(hw, &dev_caps); 11566f37f232SEric Joyner if ((dev_caps & IXGBE_DEVICE_CAPS_WOL_PORT0_1) || 11576f37f232SEric Joyner ((dev_caps & IXGBE_DEVICE_CAPS_WOL_PORT0) && 11586f37f232SEric Joyner hw->bus.func == 0)) 11596f37f232SEric Joyner adapter->wol_support = hw->wol_enabled = 1; 11606f37f232SEric Joyner 11616f37f232SEric Joyner /* Save initial wake up filter configuration */ 11626f37f232SEric Joyner adapter->wufc = IXGBE_READ_REG(hw, IXGBE_WUFC); 11636f37f232SEric Joyner 11646f37f232SEric Joyner return; 11658eb6488eSEric Joyner } /* ixgbe_check_wol_support */ 11666f37f232SEric Joyner 11678eb6488eSEric Joyner /************************************************************************ 11688eb6488eSEric Joyner * ixgbe_setup_interface 11698eb6488eSEric Joyner * 11708eb6488eSEric Joyner * Setup networking device structure and register an interface. 11718eb6488eSEric Joyner ************************************************************************/ 11726f37f232SEric Joyner static int 1173c19c7afeSEric Joyner ixgbe_setup_interface(if_ctx_t ctx) 11746f37f232SEric Joyner { 1175c19c7afeSEric Joyner struct ifnet *ifp = iflib_get_ifp(ctx); 1176c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 11776f37f232SEric Joyner 11788eb6488eSEric Joyner INIT_DEBUGOUT("ixgbe_setup_interface: begin"); 11796f37f232SEric Joyner 1180c19c7afeSEric Joyner if_setbaudrate(ifp, IF_Gbps(10)); 11816f37f232SEric Joyner 11828eb6488eSEric Joyner adapter->max_frame_size = ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN; 1183758cc3dcSJack F Vogel 11848eb6488eSEric Joyner adapter->phy_layer = ixgbe_get_supported_physical_layer(&adapter->hw); 11858eb6488eSEric Joyner 1186c19c7afeSEric Joyner ixgbe_add_media_types(ctx); 1187c19c7afeSEric Joyner 1188c19c7afeSEric Joyner /* Autoselect media by default */ 1189c19c7afeSEric Joyner ifmedia_set(adapter->media, IFM_ETHER | IFM_AUTO); 11908eb6488eSEric Joyner 11918eb6488eSEric Joyner return (0); 11928eb6488eSEric Joyner } /* ixgbe_setup_interface */ 1193758cc3dcSJack F Vogel 11948eb6488eSEric Joyner /************************************************************************ 1195c19c7afeSEric Joyner * ixgbe_if_get_counter 11968eb6488eSEric Joyner ************************************************************************/ 1197758cc3dcSJack F Vogel static uint64_t 1198c19c7afeSEric Joyner ixgbe_if_get_counter(if_ctx_t ctx, ift_counter cnt) 1199758cc3dcSJack F Vogel { 1200c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 1201c19c7afeSEric Joyner if_t ifp = iflib_get_ifp(ctx); 1202758cc3dcSJack F Vogel 1203758cc3dcSJack F Vogel switch (cnt) { 1204758cc3dcSJack F Vogel case IFCOUNTER_IPACKETS: 1205758cc3dcSJack F Vogel return (adapter->ipackets); 1206758cc3dcSJack F Vogel case IFCOUNTER_OPACKETS: 1207758cc3dcSJack F Vogel return (adapter->opackets); 1208758cc3dcSJack F Vogel case IFCOUNTER_IBYTES: 1209758cc3dcSJack F Vogel return (adapter->ibytes); 1210758cc3dcSJack F Vogel case IFCOUNTER_OBYTES: 1211758cc3dcSJack F Vogel return (adapter->obytes); 1212758cc3dcSJack F Vogel case IFCOUNTER_IMCASTS: 1213758cc3dcSJack F Vogel return (adapter->imcasts); 1214758cc3dcSJack F Vogel case IFCOUNTER_OMCASTS: 1215758cc3dcSJack F Vogel return (adapter->omcasts); 1216758cc3dcSJack F Vogel case IFCOUNTER_COLLISIONS: 1217758cc3dcSJack F Vogel return (0); 1218758cc3dcSJack F Vogel case IFCOUNTER_IQDROPS: 1219758cc3dcSJack F Vogel return (adapter->iqdrops); 1220625d12c6SJohn Baldwin case IFCOUNTER_OQDROPS: 1221c19c7afeSEric Joyner return (0); 1222758cc3dcSJack F Vogel case IFCOUNTER_IERRORS: 1223758cc3dcSJack F Vogel return (adapter->ierrors); 1224758cc3dcSJack F Vogel default: 1225758cc3dcSJack F Vogel return (if_get_counter_default(ifp, cnt)); 1226758cc3dcSJack F Vogel } 1227c19c7afeSEric Joyner } /* ixgbe_if_get_counter */ 1228758cc3dcSJack F Vogel 12298eb6488eSEric Joyner /************************************************************************ 1230bca38080SAndrew Gallatin * ixgbe_if_i2c_req 1231bca38080SAndrew Gallatin ************************************************************************/ 1232bca38080SAndrew Gallatin static int 1233bca38080SAndrew Gallatin ixgbe_if_i2c_req(if_ctx_t ctx, struct ifi2creq *req) 1234bca38080SAndrew Gallatin { 1235bca38080SAndrew Gallatin struct adapter *adapter = iflib_get_softc(ctx); 1236bca38080SAndrew Gallatin struct ixgbe_hw *hw = &adapter->hw; 1237bca38080SAndrew Gallatin int i; 1238bca38080SAndrew Gallatin 1239bca38080SAndrew Gallatin 1240bca38080SAndrew Gallatin if (hw->phy.ops.read_i2c_byte == NULL) 1241bca38080SAndrew Gallatin return (ENXIO); 1242bca38080SAndrew Gallatin for (i = 0; i < req->len; i++) 1243bca38080SAndrew Gallatin hw->phy.ops.read_i2c_byte(hw, req->offset + i, 1244bca38080SAndrew Gallatin req->dev_addr, &req->data[i]); 1245bca38080SAndrew Gallatin return (0); 1246bca38080SAndrew Gallatin } /* ixgbe_if_i2c_req */ 1247bca38080SAndrew Gallatin 1248cf150917SEric Joyner /* ixgbe_if_needs_restart - Tell iflib when the driver needs to be reinitialized 1249cf150917SEric Joyner * @ctx: iflib context 1250cf150917SEric Joyner * @event: event code to check 1251cf150917SEric Joyner * 1252cf150917SEric Joyner * Defaults to returning true for unknown events. 1253cf150917SEric Joyner * 1254cf150917SEric Joyner * @returns true if iflib needs to reinit the interface 1255cf150917SEric Joyner */ 1256cf150917SEric Joyner static bool 1257cf150917SEric Joyner ixgbe_if_needs_restart(if_ctx_t ctx __unused, enum iflib_restart_event event) 1258cf150917SEric Joyner { 1259cf150917SEric Joyner switch (event) { 1260cf150917SEric Joyner case IFLIB_RESTART_VLAN_CONFIG: 1261cf150917SEric Joyner return (false); 1262cf150917SEric Joyner default: 1263cf150917SEric Joyner return (true); 1264cf150917SEric Joyner } 1265cf150917SEric Joyner } 1266cf150917SEric Joyner 1267bca38080SAndrew Gallatin /************************************************************************ 12688eb6488eSEric Joyner * ixgbe_add_media_types 12698eb6488eSEric Joyner ************************************************************************/ 12708eb6488eSEric Joyner static void 1271c19c7afeSEric Joyner ixgbe_add_media_types(if_ctx_t ctx) 12728eb6488eSEric Joyner { 1273c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 12748eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 1275c19c7afeSEric Joyner device_t dev = iflib_get_dev(ctx); 12768eb6488eSEric Joyner u64 layer; 12778eb6488eSEric Joyner 1278c19c7afeSEric Joyner layer = adapter->phy_layer = ixgbe_get_supported_physical_layer(hw); 12798eb6488eSEric Joyner 12808eb6488eSEric Joyner /* Media types with matching FreeBSD media defines */ 12818eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_T) 1282c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_10G_T, 0, NULL); 12838eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_1000BASE_T) 1284c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_1000_T, 0, NULL); 12858eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_100BASE_TX) 1286c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_100_TX, 0, NULL); 12878eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_10BASE_T) 1288c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_10_T, 0, NULL); 12898eb6488eSEric Joyner 12908eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU || 12918eb6488eSEric Joyner layer & IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA) 1292c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_10G_TWINAX, 0, 12938eb6488eSEric Joyner NULL); 12948eb6488eSEric Joyner 12958eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_LR) { 1296c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_10G_LR, 0, NULL); 12978eb6488eSEric Joyner if (hw->phy.multispeed_fiber) 1298c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_1000_LX, 0, 12998eb6488eSEric Joyner NULL); 13008eb6488eSEric Joyner } 13018eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_SR) { 1302c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_10G_SR, 0, NULL); 13038eb6488eSEric Joyner if (hw->phy.multispeed_fiber) 1304c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_1000_SX, 0, 13058eb6488eSEric Joyner NULL); 13068eb6488eSEric Joyner } else if (layer & IXGBE_PHYSICAL_LAYER_1000BASE_SX) 1307c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_1000_SX, 0, NULL); 13088eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_CX4) 1309c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_10G_CX4, 0, NULL); 13108eb6488eSEric Joyner 13118eb6488eSEric Joyner #ifdef IFM_ETH_XTYPE 13128eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_KR) 1313c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_10G_KR, 0, NULL); 13148eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_KX4) 1315c19c7afeSEric Joyner ifmedia_add( adapter->media, IFM_ETHER | IFM_10G_KX4, 0, NULL); 13168eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_1000BASE_KX) 1317c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_1000_KX, 0, NULL); 13188eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_2500BASE_KX) 1319c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_2500_KX, 0, NULL); 13208eb6488eSEric Joyner #else 13218eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_KR) { 13228eb6488eSEric Joyner device_printf(dev, "Media supported: 10GbaseKR\n"); 13238eb6488eSEric Joyner device_printf(dev, "10GbaseKR mapped to 10GbaseSR\n"); 1324c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_10G_SR, 0, NULL); 13258eb6488eSEric Joyner } 13268eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_KX4) { 13278eb6488eSEric Joyner device_printf(dev, "Media supported: 10GbaseKX4\n"); 13288eb6488eSEric Joyner device_printf(dev, "10GbaseKX4 mapped to 10GbaseCX4\n"); 1329c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_10G_CX4, 0, NULL); 13308eb6488eSEric Joyner } 13318eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_1000BASE_KX) { 13328eb6488eSEric Joyner device_printf(dev, "Media supported: 1000baseKX\n"); 13338eb6488eSEric Joyner device_printf(dev, "1000baseKX mapped to 1000baseCX\n"); 1334c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_1000_CX, 0, NULL); 13358eb6488eSEric Joyner } 13368eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_2500BASE_KX) { 13378eb6488eSEric Joyner device_printf(dev, "Media supported: 2500baseKX\n"); 13388eb6488eSEric Joyner device_printf(dev, "2500baseKX mapped to 2500baseSX\n"); 1339c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_2500_SX, 0, NULL); 13408eb6488eSEric Joyner } 13418eb6488eSEric Joyner #endif 13428eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_1000BASE_BX) 13438eb6488eSEric Joyner device_printf(dev, "Media supported: 1000baseBX\n"); 13448eb6488eSEric Joyner 13458eb6488eSEric Joyner if (hw->device_id == IXGBE_DEV_ID_82598AT) { 1346c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_1000_T | IFM_FDX, 13478eb6488eSEric Joyner 0, NULL); 1348c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_1000_T, 0, NULL); 13498eb6488eSEric Joyner } 13508eb6488eSEric Joyner 1351c19c7afeSEric Joyner ifmedia_add(adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL); 13528eb6488eSEric Joyner } /* ixgbe_add_media_types */ 13538eb6488eSEric Joyner 13548eb6488eSEric Joyner /************************************************************************ 13558eb6488eSEric Joyner * ixgbe_is_sfp 13568eb6488eSEric Joyner ************************************************************************/ 13578eb6488eSEric Joyner static inline bool 13588eb6488eSEric Joyner ixgbe_is_sfp(struct ixgbe_hw *hw) 13598eb6488eSEric Joyner { 13608eb6488eSEric Joyner switch (hw->mac.type) { 13618eb6488eSEric Joyner case ixgbe_mac_82598EB: 13628eb6488eSEric Joyner if (hw->phy.type == ixgbe_phy_nl) 1363c19c7afeSEric Joyner return (TRUE); 1364c19c7afeSEric Joyner return (FALSE); 13658eb6488eSEric Joyner case ixgbe_mac_82599EB: 13668eb6488eSEric Joyner switch (hw->mac.ops.get_media_type(hw)) { 13678eb6488eSEric Joyner case ixgbe_media_type_fiber: 13688eb6488eSEric Joyner case ixgbe_media_type_fiber_qsfp: 1369c19c7afeSEric Joyner return (TRUE); 13708eb6488eSEric Joyner default: 1371c19c7afeSEric Joyner return (FALSE); 13728eb6488eSEric Joyner } 13738eb6488eSEric Joyner case ixgbe_mac_X550EM_x: 13748eb6488eSEric Joyner case ixgbe_mac_X550EM_a: 13758eb6488eSEric Joyner if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) 1376c19c7afeSEric Joyner return (TRUE); 1377c19c7afeSEric Joyner return (FALSE); 13788eb6488eSEric Joyner default: 1379c19c7afeSEric Joyner return (FALSE); 13808eb6488eSEric Joyner } 13818eb6488eSEric Joyner } /* ixgbe_is_sfp */ 13828eb6488eSEric Joyner 13838eb6488eSEric Joyner /************************************************************************ 13848eb6488eSEric Joyner * ixgbe_config_link 13858eb6488eSEric Joyner ************************************************************************/ 13868eb6488eSEric Joyner static void 1387b2c1e8e6SEric Joyner ixgbe_config_link(if_ctx_t ctx) 13888eb6488eSEric Joyner { 1389b2c1e8e6SEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 13908eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 13918eb6488eSEric Joyner u32 autoneg, err = 0; 13928eb6488eSEric Joyner bool sfp, negotiate; 13938eb6488eSEric Joyner 13948eb6488eSEric Joyner sfp = ixgbe_is_sfp(hw); 13958eb6488eSEric Joyner 13968eb6488eSEric Joyner if (sfp) { 1397b2c1e8e6SEric Joyner adapter->task_requests |= IXGBE_REQUEST_TASK_MOD; 1398b2c1e8e6SEric Joyner iflib_admin_intr_deferred(ctx); 13998eb6488eSEric Joyner } else { 14008eb6488eSEric Joyner if (hw->mac.ops.check_link) 14018eb6488eSEric Joyner err = ixgbe_check_link(hw, &adapter->link_speed, 14028eb6488eSEric Joyner &adapter->link_up, FALSE); 14038eb6488eSEric Joyner if (err) 1404c19c7afeSEric Joyner return; 14058eb6488eSEric Joyner autoneg = hw->phy.autoneg_advertised; 14068eb6488eSEric Joyner if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) 14078eb6488eSEric Joyner err = hw->mac.ops.get_link_capabilities(hw, &autoneg, 14088eb6488eSEric Joyner &negotiate); 14098eb6488eSEric Joyner if (err) 1410c19c7afeSEric Joyner return; 14118eb6488eSEric Joyner if (hw->mac.ops.setup_link) 14128eb6488eSEric Joyner err = hw->mac.ops.setup_link(hw, autoneg, 14138eb6488eSEric Joyner adapter->link_up); 14148eb6488eSEric Joyner } 14158eb6488eSEric Joyner } /* ixgbe_config_link */ 14168eb6488eSEric Joyner 14178eb6488eSEric Joyner /************************************************************************ 14188eb6488eSEric Joyner * ixgbe_update_stats_counters - Update board statistics counters. 14198eb6488eSEric Joyner ************************************************************************/ 14208eb6488eSEric Joyner static void 14218eb6488eSEric Joyner ixgbe_update_stats_counters(struct adapter *adapter) 14228eb6488eSEric Joyner { 14238eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 14248eb6488eSEric Joyner struct ixgbe_hw_stats *stats = &adapter->stats.pf; 14258eb6488eSEric Joyner u32 missed_rx = 0, bprc, lxon, lxoff, total; 1426e37d3dc1SEric Joyner u32 lxoffrxc; 14278eb6488eSEric Joyner u64 total_missed_rx = 0; 14288eb6488eSEric Joyner 14298eb6488eSEric Joyner stats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); 14308eb6488eSEric Joyner stats->illerrc += IXGBE_READ_REG(hw, IXGBE_ILLERRC); 14318eb6488eSEric Joyner stats->errbc += IXGBE_READ_REG(hw, IXGBE_ERRBC); 14328eb6488eSEric Joyner stats->mspdc += IXGBE_READ_REG(hw, IXGBE_MSPDC); 14338eb6488eSEric Joyner stats->mpc[0] += IXGBE_READ_REG(hw, IXGBE_MPC(0)); 14348eb6488eSEric Joyner 14358eb6488eSEric Joyner for (int i = 0; i < 16; i++) { 14368eb6488eSEric Joyner stats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); 14378eb6488eSEric Joyner stats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); 14388eb6488eSEric Joyner stats->qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); 14398eb6488eSEric Joyner } 14408eb6488eSEric Joyner stats->mlfc += IXGBE_READ_REG(hw, IXGBE_MLFC); 14418eb6488eSEric Joyner stats->mrfc += IXGBE_READ_REG(hw, IXGBE_MRFC); 14428eb6488eSEric Joyner stats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); 14438eb6488eSEric Joyner 14448eb6488eSEric Joyner /* Hardware workaround, gprc counts missed packets */ 14458eb6488eSEric Joyner stats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); 14468eb6488eSEric Joyner stats->gprc -= missed_rx; 14478eb6488eSEric Joyner 14488eb6488eSEric Joyner if (hw->mac.type != ixgbe_mac_82598EB) { 14498eb6488eSEric Joyner stats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL) + 14508eb6488eSEric Joyner ((u64)IXGBE_READ_REG(hw, IXGBE_GORCH) << 32); 14518eb6488eSEric Joyner stats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL) + 14528eb6488eSEric Joyner ((u64)IXGBE_READ_REG(hw, IXGBE_GOTCH) << 32); 14538eb6488eSEric Joyner stats->tor += IXGBE_READ_REG(hw, IXGBE_TORL) + 14548eb6488eSEric Joyner ((u64)IXGBE_READ_REG(hw, IXGBE_TORH) << 32); 14558eb6488eSEric Joyner stats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); 1456e37d3dc1SEric Joyner lxoffrxc = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); 1457e37d3dc1SEric Joyner stats->lxoffrxc += lxoffrxc; 14588eb6488eSEric Joyner } else { 14598eb6488eSEric Joyner stats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); 1460e37d3dc1SEric Joyner lxoffrxc = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); 1461e37d3dc1SEric Joyner stats->lxoffrxc += lxoffrxc; 14628eb6488eSEric Joyner /* 82598 only has a counter in the high register */ 14638eb6488eSEric Joyner stats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); 14648eb6488eSEric Joyner stats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); 14658eb6488eSEric Joyner stats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); 14668eb6488eSEric Joyner } 14678eb6488eSEric Joyner 14688eb6488eSEric Joyner /* 1469e37d3dc1SEric Joyner * For watchdog management we need to know if we have been paused 1470e37d3dc1SEric Joyner * during the last interval, so capture that here. 1471e37d3dc1SEric Joyner */ 1472e37d3dc1SEric Joyner if (lxoffrxc) 1473e37d3dc1SEric Joyner adapter->shared->isc_pause_frames = 1; 1474e37d3dc1SEric Joyner 1475e37d3dc1SEric Joyner /* 14768eb6488eSEric Joyner * Workaround: mprc hardware is incorrectly counting 14778eb6488eSEric Joyner * broadcasts, so for now we subtract those. 1478758cc3dcSJack F Vogel */ 14798eb6488eSEric Joyner bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); 14808eb6488eSEric Joyner stats->bprc += bprc; 14818eb6488eSEric Joyner stats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); 14828eb6488eSEric Joyner if (hw->mac.type == ixgbe_mac_82598EB) 14838eb6488eSEric Joyner stats->mprc -= bprc; 14848eb6488eSEric Joyner 14858eb6488eSEric Joyner stats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); 14868eb6488eSEric Joyner stats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); 14878eb6488eSEric Joyner stats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); 14888eb6488eSEric Joyner stats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); 14898eb6488eSEric Joyner stats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); 14908eb6488eSEric Joyner stats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); 14918eb6488eSEric Joyner 14928eb6488eSEric Joyner lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); 14938eb6488eSEric Joyner stats->lxontxc += lxon; 14948eb6488eSEric Joyner lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); 14958eb6488eSEric Joyner stats->lxofftxc += lxoff; 14968eb6488eSEric Joyner total = lxon + lxoff; 14978eb6488eSEric Joyner 14988eb6488eSEric Joyner stats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); 14998eb6488eSEric Joyner stats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); 15008eb6488eSEric Joyner stats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); 15018eb6488eSEric Joyner stats->gptc -= total; 15028eb6488eSEric Joyner stats->mptc -= total; 15038eb6488eSEric Joyner stats->ptc64 -= total; 15048eb6488eSEric Joyner stats->gotc -= total * ETHER_MIN_LEN; 15058eb6488eSEric Joyner 15068eb6488eSEric Joyner stats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); 15078eb6488eSEric Joyner stats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); 15088eb6488eSEric Joyner stats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); 15098eb6488eSEric Joyner stats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); 15108eb6488eSEric Joyner stats->mngprc += IXGBE_READ_REG(hw, IXGBE_MNGPRC); 15118eb6488eSEric Joyner stats->mngpdc += IXGBE_READ_REG(hw, IXGBE_MNGPDC); 15128eb6488eSEric Joyner stats->mngptc += IXGBE_READ_REG(hw, IXGBE_MNGPTC); 15138eb6488eSEric Joyner stats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); 15148eb6488eSEric Joyner stats->tpt += IXGBE_READ_REG(hw, IXGBE_TPT); 15158eb6488eSEric Joyner stats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); 15168eb6488eSEric Joyner stats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); 15178eb6488eSEric Joyner stats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); 15188eb6488eSEric Joyner stats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); 15198eb6488eSEric Joyner stats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); 15208eb6488eSEric Joyner stats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); 15218eb6488eSEric Joyner stats->xec += IXGBE_READ_REG(hw, IXGBE_XEC); 15228eb6488eSEric Joyner stats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); 15238eb6488eSEric Joyner stats->fclast += IXGBE_READ_REG(hw, IXGBE_FCLAST); 15248eb6488eSEric Joyner /* Only read FCOE on 82599 */ 15258eb6488eSEric Joyner if (hw->mac.type != ixgbe_mac_82598EB) { 15268eb6488eSEric Joyner stats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); 15278eb6488eSEric Joyner stats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); 15288eb6488eSEric Joyner stats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); 15298eb6488eSEric Joyner stats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); 15308eb6488eSEric Joyner stats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); 15318eb6488eSEric Joyner } 15328eb6488eSEric Joyner 15338eb6488eSEric Joyner /* Fill out the OS statistics structure */ 15348eb6488eSEric Joyner IXGBE_SET_IPACKETS(adapter, stats->gprc); 15358eb6488eSEric Joyner IXGBE_SET_OPACKETS(adapter, stats->gptc); 15368eb6488eSEric Joyner IXGBE_SET_IBYTES(adapter, stats->gorc); 15378eb6488eSEric Joyner IXGBE_SET_OBYTES(adapter, stats->gotc); 15388eb6488eSEric Joyner IXGBE_SET_IMCASTS(adapter, stats->mprc); 15398eb6488eSEric Joyner IXGBE_SET_OMCASTS(adapter, stats->mptc); 15408eb6488eSEric Joyner IXGBE_SET_COLLISIONS(adapter, 0); 15418eb6488eSEric Joyner IXGBE_SET_IQDROPS(adapter, total_missed_rx); 1542afb1aa4eSPiotr Pietruszewski 1543afb1aa4eSPiotr Pietruszewski /* 1544afb1aa4eSPiotr Pietruszewski * Aggregate following types of errors as RX errors: 1545afb1aa4eSPiotr Pietruszewski * - CRC error count, 1546afb1aa4eSPiotr Pietruszewski * - illegal byte error count, 1547afb1aa4eSPiotr Pietruszewski * - checksum error count, 1548afb1aa4eSPiotr Pietruszewski * - missed packets count, 1549afb1aa4eSPiotr Pietruszewski * - length error count, 1550afb1aa4eSPiotr Pietruszewski * - undersized packets count, 1551afb1aa4eSPiotr Pietruszewski * - fragmented packets count, 1552afb1aa4eSPiotr Pietruszewski * - oversized packets count, 1553afb1aa4eSPiotr Pietruszewski * - jabber count. 1554afb1aa4eSPiotr Pietruszewski */ 1555afb1aa4eSPiotr Pietruszewski IXGBE_SET_IERRORS(adapter, stats->crcerrs + stats->illerrc + stats->xec + 1556afb1aa4eSPiotr Pietruszewski stats->mpc[0] + stats->rlec + stats->ruc + stats->rfc + stats->roc + 1557afb1aa4eSPiotr Pietruszewski stats->rjc); 15588eb6488eSEric Joyner } /* ixgbe_update_stats_counters */ 15598eb6488eSEric Joyner 15608eb6488eSEric Joyner /************************************************************************ 15618eb6488eSEric Joyner * ixgbe_add_hw_stats 15628eb6488eSEric Joyner * 15638eb6488eSEric Joyner * Add sysctl variables, one per statistic, to the system. 15648eb6488eSEric Joyner ************************************************************************/ 15658eb6488eSEric Joyner static void 15668eb6488eSEric Joyner ixgbe_add_hw_stats(struct adapter *adapter) 15678eb6488eSEric Joyner { 1568c19c7afeSEric Joyner device_t dev = iflib_get_dev(adapter->ctx); 1569c19c7afeSEric Joyner struct ix_rx_queue *rx_que; 1570c19c7afeSEric Joyner struct ix_tx_queue *tx_que; 15718eb6488eSEric Joyner struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(dev); 15728eb6488eSEric Joyner struct sysctl_oid *tree = device_get_sysctl_tree(dev); 15738eb6488eSEric Joyner struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree); 15748eb6488eSEric Joyner struct ixgbe_hw_stats *stats = &adapter->stats.pf; 15758eb6488eSEric Joyner struct sysctl_oid *stat_node, *queue_node; 15768eb6488eSEric Joyner struct sysctl_oid_list *stat_list, *queue_list; 1577c19c7afeSEric Joyner int i; 15788eb6488eSEric Joyner 15798eb6488eSEric Joyner #define QUEUE_NAME_LEN 32 15808eb6488eSEric Joyner char namebuf[QUEUE_NAME_LEN]; 15818eb6488eSEric Joyner 15828eb6488eSEric Joyner /* Driver Statistics */ 15838eb6488eSEric Joyner SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "dropped", 15848eb6488eSEric Joyner CTLFLAG_RD, &adapter->dropped_pkts, "Driver dropped packets"); 15858eb6488eSEric Joyner SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "watchdog_events", 15868eb6488eSEric Joyner CTLFLAG_RD, &adapter->watchdog_events, "Watchdog timeouts"); 15878eb6488eSEric Joyner SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "link_irq", 15888eb6488eSEric Joyner CTLFLAG_RD, &adapter->link_irq, "Link MSI-X IRQ Handled"); 15898eb6488eSEric Joyner 1590c19c7afeSEric Joyner for (i = 0, tx_que = adapter->tx_queues; i < adapter->num_tx_queues; i++, tx_que++) { 1591c19c7afeSEric Joyner struct tx_ring *txr = &tx_que->txr; 15928eb6488eSEric Joyner snprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i); 15938eb6488eSEric Joyner queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf, 159420b91f0aSPawel Biernacki CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "Queue Name"); 15958eb6488eSEric Joyner queue_list = SYSCTL_CHILDREN(queue_node); 15968eb6488eSEric Joyner 15978eb6488eSEric Joyner SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "txd_head", 159820b91f0aSPawel Biernacki CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_NEEDGIANT, txr, 0, 15998eb6488eSEric Joyner ixgbe_sysctl_tdh_handler, "IU", "Transmit Descriptor Head"); 16008eb6488eSEric Joyner SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "txd_tail", 160120b91f0aSPawel Biernacki CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_NEEDGIANT, txr, 0, 16028eb6488eSEric Joyner ixgbe_sysctl_tdt_handler, "IU", "Transmit Descriptor Tail"); 16038eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tso_tx", 16048eb6488eSEric Joyner CTLFLAG_RD, &txr->tso_tx, "TSO"); 16058eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tx_packets", 16068eb6488eSEric Joyner CTLFLAG_RD, &txr->total_packets, 16078eb6488eSEric Joyner "Queue Packets Transmitted"); 16088eb6488eSEric Joyner } 16098eb6488eSEric Joyner 1610c19c7afeSEric Joyner for (i = 0, rx_que = adapter->rx_queues; i < adapter->num_rx_queues; i++, rx_que++) { 1611c19c7afeSEric Joyner struct rx_ring *rxr = &rx_que->rxr; 16128eb6488eSEric Joyner snprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i); 16138eb6488eSEric Joyner queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf, 161420b91f0aSPawel Biernacki CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "Queue Name"); 16158eb6488eSEric Joyner queue_list = SYSCTL_CHILDREN(queue_node); 16168eb6488eSEric Joyner 1617c19c7afeSEric Joyner SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "interrupt_rate", 161820b91f0aSPawel Biernacki CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, 161920b91f0aSPawel Biernacki &adapter->rx_queues[i], 0, 1620c19c7afeSEric Joyner ixgbe_sysctl_interrupt_rate_handler, "IU", 1621c19c7afeSEric Joyner "Interrupt Rate"); 1622c19c7afeSEric Joyner SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "irqs", 1623c19c7afeSEric Joyner CTLFLAG_RD, &(adapter->rx_queues[i].irqs), 1624c19c7afeSEric Joyner "irqs on this queue"); 16258eb6488eSEric Joyner SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "rxd_head", 162620b91f0aSPawel Biernacki CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_NEEDGIANT, rxr, 0, 16278eb6488eSEric Joyner ixgbe_sysctl_rdh_handler, "IU", "Receive Descriptor Head"); 16288eb6488eSEric Joyner SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "rxd_tail", 162920b91f0aSPawel Biernacki CTLTYPE_UINT | CTLFLAG_RD | CTLFLAG_NEEDGIANT, rxr, 0, 16308eb6488eSEric Joyner ixgbe_sysctl_rdt_handler, "IU", "Receive Descriptor Tail"); 16318eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_packets", 16328eb6488eSEric Joyner CTLFLAG_RD, &rxr->rx_packets, "Queue Packets Received"); 16338eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_bytes", 16348eb6488eSEric Joyner CTLFLAG_RD, &rxr->rx_bytes, "Queue Bytes Received"); 16358eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_copies", 16368eb6488eSEric Joyner CTLFLAG_RD, &rxr->rx_copies, "Copied RX Frames"); 16378eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_discarded", 16388eb6488eSEric Joyner CTLFLAG_RD, &rxr->rx_discarded, "Discarded RX packets"); 16398eb6488eSEric Joyner } 16408eb6488eSEric Joyner 16418eb6488eSEric Joyner /* MAC stats get their own sub node */ 16428eb6488eSEric Joyner 16438eb6488eSEric Joyner stat_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "mac_stats", 164420b91f0aSPawel Biernacki CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "MAC Statistics"); 16458eb6488eSEric Joyner stat_list = SYSCTL_CHILDREN(stat_node); 16468eb6488eSEric Joyner 1647afb1aa4eSPiotr Pietruszewski SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_errs", 1648afb1aa4eSPiotr Pietruszewski CTLFLAG_RD, &adapter->ierrors, IXGBE_SYSCTL_DESC_RX_ERRS); 16498eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "crc_errs", 16508eb6488eSEric Joyner CTLFLAG_RD, &stats->crcerrs, "CRC Errors"); 16518eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "ill_errs", 16528eb6488eSEric Joyner CTLFLAG_RD, &stats->illerrc, "Illegal Byte Errors"); 16538eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "byte_errs", 16548eb6488eSEric Joyner CTLFLAG_RD, &stats->errbc, "Byte Errors"); 16558eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "short_discards", 16568eb6488eSEric Joyner CTLFLAG_RD, &stats->mspdc, "MAC Short Packets Discarded"); 16578eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "local_faults", 16588eb6488eSEric Joyner CTLFLAG_RD, &stats->mlfc, "MAC Local Faults"); 16598eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "remote_faults", 16608eb6488eSEric Joyner CTLFLAG_RD, &stats->mrfc, "MAC Remote Faults"); 16618eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rec_len_errs", 16628eb6488eSEric Joyner CTLFLAG_RD, &stats->rlec, "Receive Length Errors"); 16638eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_missed_packets", 16648eb6488eSEric Joyner CTLFLAG_RD, &stats->mpc[0], "RX Missed Packet Count"); 16658eb6488eSEric Joyner 16668eb6488eSEric Joyner /* Flow Control stats */ 16678eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "xon_txd", 16688eb6488eSEric Joyner CTLFLAG_RD, &stats->lxontxc, "Link XON Transmitted"); 16698eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "xon_recvd", 16708eb6488eSEric Joyner CTLFLAG_RD, &stats->lxonrxc, "Link XON Received"); 16718eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "xoff_txd", 16728eb6488eSEric Joyner CTLFLAG_RD, &stats->lxofftxc, "Link XOFF Transmitted"); 16738eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "xoff_recvd", 16748eb6488eSEric Joyner CTLFLAG_RD, &stats->lxoffrxc, "Link XOFF Received"); 16758eb6488eSEric Joyner 16768eb6488eSEric Joyner /* Packet Reception Stats */ 16778eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "total_octets_rcvd", 16788eb6488eSEric Joyner CTLFLAG_RD, &stats->tor, "Total Octets Received"); 16798eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_octets_rcvd", 16808eb6488eSEric Joyner CTLFLAG_RD, &stats->gorc, "Good Octets Received"); 16818eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "total_pkts_rcvd", 16828eb6488eSEric Joyner CTLFLAG_RD, &stats->tpr, "Total Packets Received"); 16838eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_pkts_rcvd", 16848eb6488eSEric Joyner CTLFLAG_RD, &stats->gprc, "Good Packets Received"); 16858eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "mcast_pkts_rcvd", 16868eb6488eSEric Joyner CTLFLAG_RD, &stats->mprc, "Multicast Packets Received"); 16878eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "bcast_pkts_rcvd", 16888eb6488eSEric Joyner CTLFLAG_RD, &stats->bprc, "Broadcast Packets Received"); 16898eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_64", 16908eb6488eSEric Joyner CTLFLAG_RD, &stats->prc64, "64 byte frames received "); 16918eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_65_127", 16928eb6488eSEric Joyner CTLFLAG_RD, &stats->prc127, "65-127 byte frames received"); 16938eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_128_255", 16948eb6488eSEric Joyner CTLFLAG_RD, &stats->prc255, "128-255 byte frames received"); 16958eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_256_511", 16968eb6488eSEric Joyner CTLFLAG_RD, &stats->prc511, "256-511 byte frames received"); 16978eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_512_1023", 16988eb6488eSEric Joyner CTLFLAG_RD, &stats->prc1023, "512-1023 byte frames received"); 16998eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_1024_1522", 17008eb6488eSEric Joyner CTLFLAG_RD, &stats->prc1522, "1023-1522 byte frames received"); 17018eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_undersized", 17028eb6488eSEric Joyner CTLFLAG_RD, &stats->ruc, "Receive Undersized"); 17038eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_fragmented", 17048eb6488eSEric Joyner CTLFLAG_RD, &stats->rfc, "Fragmented Packets Received "); 17058eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_oversized", 17068eb6488eSEric Joyner CTLFLAG_RD, &stats->roc, "Oversized Packets Received"); 17078eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_jabberd", 17088eb6488eSEric Joyner CTLFLAG_RD, &stats->rjc, "Received Jabber"); 17098eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "management_pkts_rcvd", 17108eb6488eSEric Joyner CTLFLAG_RD, &stats->mngprc, "Management Packets Received"); 17118eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "management_pkts_drpd", 17128eb6488eSEric Joyner CTLFLAG_RD, &stats->mngptc, "Management Packets Dropped"); 17138eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "checksum_errs", 17148eb6488eSEric Joyner CTLFLAG_RD, &stats->xec, "Checksum Errors"); 17158eb6488eSEric Joyner 17168eb6488eSEric Joyner /* Packet Transmission Stats */ 17178eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_octets_txd", 17188eb6488eSEric Joyner CTLFLAG_RD, &stats->gotc, "Good Octets Transmitted"); 17198eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "total_pkts_txd", 17208eb6488eSEric Joyner CTLFLAG_RD, &stats->tpt, "Total Packets Transmitted"); 17218eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_pkts_txd", 17228eb6488eSEric Joyner CTLFLAG_RD, &stats->gptc, "Good Packets Transmitted"); 17238eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "bcast_pkts_txd", 17248eb6488eSEric Joyner CTLFLAG_RD, &stats->bptc, "Broadcast Packets Transmitted"); 17258eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "mcast_pkts_txd", 17268eb6488eSEric Joyner CTLFLAG_RD, &stats->mptc, "Multicast Packets Transmitted"); 17278eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "management_pkts_txd", 17288eb6488eSEric Joyner CTLFLAG_RD, &stats->mngptc, "Management Packets Transmitted"); 17298eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_64", 17308eb6488eSEric Joyner CTLFLAG_RD, &stats->ptc64, "64 byte frames transmitted "); 17318eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_65_127", 17328eb6488eSEric Joyner CTLFLAG_RD, &stats->ptc127, "65-127 byte frames transmitted"); 17338eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_128_255", 17348eb6488eSEric Joyner CTLFLAG_RD, &stats->ptc255, "128-255 byte frames transmitted"); 17358eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_256_511", 17368eb6488eSEric Joyner CTLFLAG_RD, &stats->ptc511, "256-511 byte frames transmitted"); 17378eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_512_1023", 17388eb6488eSEric Joyner CTLFLAG_RD, &stats->ptc1023, "512-1023 byte frames transmitted"); 17398eb6488eSEric Joyner SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_1024_1522", 17408eb6488eSEric Joyner CTLFLAG_RD, &stats->ptc1522, "1024-1522 byte frames transmitted"); 17418eb6488eSEric Joyner } /* ixgbe_add_hw_stats */ 17428eb6488eSEric Joyner 17438eb6488eSEric Joyner /************************************************************************ 17448eb6488eSEric Joyner * ixgbe_sysctl_tdh_handler - Transmit Descriptor Head handler function 17458eb6488eSEric Joyner * 17468eb6488eSEric Joyner * Retrieves the TDH value from the hardware 17478eb6488eSEric Joyner ************************************************************************/ 1748758cc3dcSJack F Vogel static int 1749758cc3dcSJack F Vogel ixgbe_sysctl_tdh_handler(SYSCTL_HANDLER_ARGS) 1750758cc3dcSJack F Vogel { 1751758cc3dcSJack F Vogel struct tx_ring *txr = ((struct tx_ring *)oidp->oid_arg1); 17528eb6488eSEric Joyner int error; 17538eb6488eSEric Joyner unsigned int val; 1754758cc3dcSJack F Vogel 17558eb6488eSEric Joyner if (!txr) 17568eb6488eSEric Joyner return (0); 17578eb6488eSEric Joyner 17588eb6488eSEric Joyner val = IXGBE_READ_REG(&txr->adapter->hw, IXGBE_TDH(txr->me)); 1759758cc3dcSJack F Vogel error = sysctl_handle_int(oidp, &val, 0, req); 1760758cc3dcSJack F Vogel if (error || !req->newptr) 1761758cc3dcSJack F Vogel return error; 1762758cc3dcSJack F Vogel 17638eb6488eSEric Joyner return (0); 17648eb6488eSEric Joyner } /* ixgbe_sysctl_tdh_handler */ 17658eb6488eSEric Joyner 17668eb6488eSEric Joyner /************************************************************************ 17678eb6488eSEric Joyner * ixgbe_sysctl_tdt_handler - Transmit Descriptor Tail handler function 17688eb6488eSEric Joyner * 1769758cc3dcSJack F Vogel * Retrieves the TDT value from the hardware 17708eb6488eSEric Joyner ************************************************************************/ 1771758cc3dcSJack F Vogel static int 1772758cc3dcSJack F Vogel ixgbe_sysctl_tdt_handler(SYSCTL_HANDLER_ARGS) 1773758cc3dcSJack F Vogel { 1774758cc3dcSJack F Vogel struct tx_ring *txr = ((struct tx_ring *)oidp->oid_arg1); 17758eb6488eSEric Joyner int error; 17768eb6488eSEric Joyner unsigned int val; 1777758cc3dcSJack F Vogel 17788eb6488eSEric Joyner if (!txr) 17798eb6488eSEric Joyner return (0); 17808eb6488eSEric Joyner 17818eb6488eSEric Joyner val = IXGBE_READ_REG(&txr->adapter->hw, IXGBE_TDT(txr->me)); 1782758cc3dcSJack F Vogel error = sysctl_handle_int(oidp, &val, 0, req); 1783758cc3dcSJack F Vogel if (error || !req->newptr) 1784758cc3dcSJack F Vogel return error; 1785758cc3dcSJack F Vogel 17868eb6488eSEric Joyner return (0); 17878eb6488eSEric Joyner } /* ixgbe_sysctl_tdt_handler */ 17888eb6488eSEric Joyner 17898eb6488eSEric Joyner /************************************************************************ 17908eb6488eSEric Joyner * ixgbe_sysctl_rdh_handler - Receive Descriptor Head handler function 17918eb6488eSEric Joyner * 1792758cc3dcSJack F Vogel * Retrieves the RDH value from the hardware 17938eb6488eSEric Joyner ************************************************************************/ 1794758cc3dcSJack F Vogel static int 1795758cc3dcSJack F Vogel ixgbe_sysctl_rdh_handler(SYSCTL_HANDLER_ARGS) 1796758cc3dcSJack F Vogel { 1797758cc3dcSJack F Vogel struct rx_ring *rxr = ((struct rx_ring *)oidp->oid_arg1); 17988eb6488eSEric Joyner int error; 17998eb6488eSEric Joyner unsigned int val; 1800758cc3dcSJack F Vogel 18018eb6488eSEric Joyner if (!rxr) 18028eb6488eSEric Joyner return (0); 18038eb6488eSEric Joyner 18048eb6488eSEric Joyner val = IXGBE_READ_REG(&rxr->adapter->hw, IXGBE_RDH(rxr->me)); 1805758cc3dcSJack F Vogel error = sysctl_handle_int(oidp, &val, 0, req); 1806758cc3dcSJack F Vogel if (error || !req->newptr) 1807758cc3dcSJack F Vogel return error; 1808758cc3dcSJack F Vogel 18098eb6488eSEric Joyner return (0); 18108eb6488eSEric Joyner } /* ixgbe_sysctl_rdh_handler */ 18118eb6488eSEric Joyner 18128eb6488eSEric Joyner /************************************************************************ 18138eb6488eSEric Joyner * ixgbe_sysctl_rdt_handler - Receive Descriptor Tail handler function 18148eb6488eSEric Joyner * 1815758cc3dcSJack F Vogel * Retrieves the RDT value from the hardware 18168eb6488eSEric Joyner ************************************************************************/ 1817758cc3dcSJack F Vogel static int 1818758cc3dcSJack F Vogel ixgbe_sysctl_rdt_handler(SYSCTL_HANDLER_ARGS) 1819758cc3dcSJack F Vogel { 1820758cc3dcSJack F Vogel struct rx_ring *rxr = ((struct rx_ring *)oidp->oid_arg1); 18218eb6488eSEric Joyner int error; 18228eb6488eSEric Joyner unsigned int val; 1823758cc3dcSJack F Vogel 18248eb6488eSEric Joyner if (!rxr) 18258eb6488eSEric Joyner return (0); 18268eb6488eSEric Joyner 18278eb6488eSEric Joyner val = IXGBE_READ_REG(&rxr->adapter->hw, IXGBE_RDT(rxr->me)); 1828758cc3dcSJack F Vogel error = sysctl_handle_int(oidp, &val, 0, req); 1829758cc3dcSJack F Vogel if (error || !req->newptr) 1830758cc3dcSJack F Vogel return error; 18318eb6488eSEric Joyner 18328eb6488eSEric Joyner return (0); 18338eb6488eSEric Joyner } /* ixgbe_sysctl_rdt_handler */ 18348eb6488eSEric Joyner 18358eb6488eSEric Joyner /************************************************************************ 1836c19c7afeSEric Joyner * ixgbe_if_vlan_register 18378eb6488eSEric Joyner * 18388eb6488eSEric Joyner * Run via vlan config EVENT, it enables us to use the 18398eb6488eSEric Joyner * HW Filter table since we can get the vlan id. This 18408eb6488eSEric Joyner * just creates the entry in the soft version of the 18418eb6488eSEric Joyner * VFTA, init will repopulate the real table. 18428eb6488eSEric Joyner ************************************************************************/ 18438eb6488eSEric Joyner static void 1844c19c7afeSEric Joyner ixgbe_if_vlan_register(if_ctx_t ctx, u16 vtag) 18458eb6488eSEric Joyner { 1846c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 18478eb6488eSEric Joyner u16 index, bit; 18488eb6488eSEric Joyner 18498eb6488eSEric Joyner index = (vtag >> 5) & 0x7F; 18508eb6488eSEric Joyner bit = vtag & 0x1F; 18518eb6488eSEric Joyner adapter->shadow_vfta[index] |= (1 << bit); 18528eb6488eSEric Joyner ++adapter->num_vlans; 1853c19c7afeSEric Joyner ixgbe_setup_vlan_hw_support(ctx); 1854c19c7afeSEric Joyner } /* ixgbe_if_vlan_register */ 18558eb6488eSEric Joyner 18568eb6488eSEric Joyner /************************************************************************ 1857c19c7afeSEric Joyner * ixgbe_if_vlan_unregister 18588eb6488eSEric Joyner * 18598eb6488eSEric Joyner * Run via vlan unconfig EVENT, remove our entry in the soft vfta. 18608eb6488eSEric Joyner ************************************************************************/ 18618eb6488eSEric Joyner static void 1862c19c7afeSEric Joyner ixgbe_if_vlan_unregister(if_ctx_t ctx, u16 vtag) 18638eb6488eSEric Joyner { 1864c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 18658eb6488eSEric Joyner u16 index, bit; 18668eb6488eSEric Joyner 18678eb6488eSEric Joyner index = (vtag >> 5) & 0x7F; 18688eb6488eSEric Joyner bit = vtag & 0x1F; 18698eb6488eSEric Joyner adapter->shadow_vfta[index] &= ~(1 << bit); 18708eb6488eSEric Joyner --adapter->num_vlans; 18718eb6488eSEric Joyner /* Re-init to load the changes */ 1872c19c7afeSEric Joyner ixgbe_setup_vlan_hw_support(ctx); 1873c19c7afeSEric Joyner } /* ixgbe_if_vlan_unregister */ 18748eb6488eSEric Joyner 18758eb6488eSEric Joyner /************************************************************************ 18768eb6488eSEric Joyner * ixgbe_setup_vlan_hw_support 18778eb6488eSEric Joyner ************************************************************************/ 18788eb6488eSEric Joyner static void 1879c19c7afeSEric Joyner ixgbe_setup_vlan_hw_support(if_ctx_t ctx) 18808eb6488eSEric Joyner { 1881c19c7afeSEric Joyner struct ifnet *ifp = iflib_get_ifp(ctx); 1882c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 18838eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 18848eb6488eSEric Joyner struct rx_ring *rxr; 18858eb6488eSEric Joyner int i; 18868eb6488eSEric Joyner u32 ctrl; 18878eb6488eSEric Joyner 18888eb6488eSEric Joyner 18898eb6488eSEric Joyner /* 18908eb6488eSEric Joyner * We get here thru init_locked, meaning 18918eb6488eSEric Joyner * a soft reset, this has already cleared 18928eb6488eSEric Joyner * the VFTA and other state, so if there 18938eb6488eSEric Joyner * have been no vlan's registered do nothing. 18948eb6488eSEric Joyner */ 18958eb6488eSEric Joyner if (adapter->num_vlans == 0) 18968eb6488eSEric Joyner return; 18978eb6488eSEric Joyner 18988eb6488eSEric Joyner /* Setup the queues for vlans */ 18999c92bb71SSean Bruno if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) { 1900c19c7afeSEric Joyner for (i = 0; i < adapter->num_rx_queues; i++) { 1901c19c7afeSEric Joyner rxr = &adapter->rx_queues[i].rxr; 19028eb6488eSEric Joyner /* On 82599 the VLAN enable is per/queue in RXDCTL */ 19038eb6488eSEric Joyner if (hw->mac.type != ixgbe_mac_82598EB) { 19048eb6488eSEric Joyner ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxr->me)); 19058eb6488eSEric Joyner ctrl |= IXGBE_RXDCTL_VME; 19068eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rxr->me), ctrl); 19078eb6488eSEric Joyner } 19088eb6488eSEric Joyner rxr->vtag_strip = TRUE; 1909758cc3dcSJack F Vogel } 19109c92bb71SSean Bruno } 1911758cc3dcSJack F Vogel 19128eb6488eSEric Joyner if ((ifp->if_capenable & IFCAP_VLAN_HWFILTER) == 0) 19138eb6488eSEric Joyner return; 19148eb6488eSEric Joyner /* 19158eb6488eSEric Joyner * A soft reset zero's out the VFTA, so 19168eb6488eSEric Joyner * we need to repopulate it now. 19178eb6488eSEric Joyner */ 19188eb6488eSEric Joyner for (i = 0; i < IXGBE_VFTA_SIZE; i++) 19198eb6488eSEric Joyner if (adapter->shadow_vfta[i] != 0) 19208eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), 19218eb6488eSEric Joyner adapter->shadow_vfta[i]); 19228eb6488eSEric Joyner 19238eb6488eSEric Joyner ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); 19248eb6488eSEric Joyner /* Enable the Filter Table if enabled */ 19258eb6488eSEric Joyner if (ifp->if_capenable & IFCAP_VLAN_HWFILTER) { 19268eb6488eSEric Joyner ctrl &= ~IXGBE_VLNCTRL_CFIEN; 19278eb6488eSEric Joyner ctrl |= IXGBE_VLNCTRL_VFE; 19288eb6488eSEric Joyner } 19298eb6488eSEric Joyner if (hw->mac.type == ixgbe_mac_82598EB) 19308eb6488eSEric Joyner ctrl |= IXGBE_VLNCTRL_VME; 19318eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl); 19328eb6488eSEric Joyner } /* ixgbe_setup_vlan_hw_support */ 19338eb6488eSEric Joyner 19348eb6488eSEric Joyner /************************************************************************ 19358eb6488eSEric Joyner * ixgbe_get_slot_info 19368eb6488eSEric Joyner * 19378eb6488eSEric Joyner * Get the width and transaction speed of 19388eb6488eSEric Joyner * the slot this adapter is plugged into. 19398eb6488eSEric Joyner ************************************************************************/ 19408eb6488eSEric Joyner static void 19418eb6488eSEric Joyner ixgbe_get_slot_info(struct adapter *adapter) 19428eb6488eSEric Joyner { 1943c19c7afeSEric Joyner device_t dev = iflib_get_dev(adapter->ctx); 19448eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 1945c19c7afeSEric Joyner int bus_info_valid = TRUE; 19468eb6488eSEric Joyner u32 offset; 19478eb6488eSEric Joyner u16 link; 19488eb6488eSEric Joyner 19498eb6488eSEric Joyner /* Some devices are behind an internal bridge */ 19508eb6488eSEric Joyner switch (hw->device_id) { 19518eb6488eSEric Joyner case IXGBE_DEV_ID_82599_SFP_SF_QP: 19528eb6488eSEric Joyner case IXGBE_DEV_ID_82599_QSFP_SF_QP: 19538eb6488eSEric Joyner goto get_parent_info; 19548eb6488eSEric Joyner default: 19558eb6488eSEric Joyner break; 19568eb6488eSEric Joyner } 19578eb6488eSEric Joyner 19588eb6488eSEric Joyner ixgbe_get_bus_info(hw); 19598eb6488eSEric Joyner 19608eb6488eSEric Joyner /* 19618eb6488eSEric Joyner * Some devices don't use PCI-E, but there is no need 19628eb6488eSEric Joyner * to display "Unknown" for bus speed and width. 19638eb6488eSEric Joyner */ 19648eb6488eSEric Joyner switch (hw->mac.type) { 19658eb6488eSEric Joyner case ixgbe_mac_X550EM_x: 19668eb6488eSEric Joyner case ixgbe_mac_X550EM_a: 19678eb6488eSEric Joyner return; 19688eb6488eSEric Joyner default: 19698eb6488eSEric Joyner goto display; 19708eb6488eSEric Joyner } 19718eb6488eSEric Joyner 19728eb6488eSEric Joyner get_parent_info: 19738eb6488eSEric Joyner /* 19748eb6488eSEric Joyner * For the Quad port adapter we need to parse back 19758eb6488eSEric Joyner * up the PCI tree to find the speed of the expansion 19768eb6488eSEric Joyner * slot into which this adapter is plugged. A bit more work. 19778eb6488eSEric Joyner */ 19788eb6488eSEric Joyner dev = device_get_parent(device_get_parent(dev)); 19798eb6488eSEric Joyner #ifdef IXGBE_DEBUG 19808eb6488eSEric Joyner device_printf(dev, "parent pcib = %x,%x,%x\n", pci_get_bus(dev), 19818eb6488eSEric Joyner pci_get_slot(dev), pci_get_function(dev)); 19828eb6488eSEric Joyner #endif 19838eb6488eSEric Joyner dev = device_get_parent(device_get_parent(dev)); 19848eb6488eSEric Joyner #ifdef IXGBE_DEBUG 19858eb6488eSEric Joyner device_printf(dev, "slot pcib = %x,%x,%x\n", pci_get_bus(dev), 19868eb6488eSEric Joyner pci_get_slot(dev), pci_get_function(dev)); 19878eb6488eSEric Joyner #endif 19888eb6488eSEric Joyner /* Now get the PCI Express Capabilities offset */ 19898eb6488eSEric Joyner if (pci_find_cap(dev, PCIY_EXPRESS, &offset)) { 19908eb6488eSEric Joyner /* 19918eb6488eSEric Joyner * Hmm...can't get PCI-Express capabilities. 19928eb6488eSEric Joyner * Falling back to default method. 19938eb6488eSEric Joyner */ 19948eb6488eSEric Joyner bus_info_valid = FALSE; 19958eb6488eSEric Joyner ixgbe_get_bus_info(hw); 19968eb6488eSEric Joyner goto display; 19978eb6488eSEric Joyner } 19988eb6488eSEric Joyner /* ...and read the Link Status Register */ 19998eb6488eSEric Joyner link = pci_read_config(dev, offset + PCIER_LINK_STA, 2); 20008eb6488eSEric Joyner ixgbe_set_pci_config_data_generic(hw, link); 20018eb6488eSEric Joyner 20028eb6488eSEric Joyner display: 20038eb6488eSEric Joyner device_printf(dev, "PCI Express Bus: Speed %s %s\n", 20048eb6488eSEric Joyner ((hw->bus.speed == ixgbe_bus_speed_8000) ? "8.0GT/s" : 20058eb6488eSEric Joyner (hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0GT/s" : 20068eb6488eSEric Joyner (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5GT/s" : 20078eb6488eSEric Joyner "Unknown"), 20088eb6488eSEric Joyner ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" : 20098eb6488eSEric Joyner (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" : 20108eb6488eSEric Joyner (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" : 20118eb6488eSEric Joyner "Unknown")); 20128eb6488eSEric Joyner 20138eb6488eSEric Joyner if (bus_info_valid) { 20148eb6488eSEric Joyner if ((hw->device_id != IXGBE_DEV_ID_82599_SFP_SF_QP) && 20158eb6488eSEric Joyner ((hw->bus.width <= ixgbe_bus_width_pcie_x4) && 20168eb6488eSEric Joyner (hw->bus.speed == ixgbe_bus_speed_2500))) { 20178eb6488eSEric Joyner device_printf(dev, "PCI-Express bandwidth available for this card\n is not sufficient for optimal performance.\n"); 20188eb6488eSEric Joyner device_printf(dev, "For optimal performance a x8 PCIE, or x4 PCIE Gen2 slot is required.\n"); 20198eb6488eSEric Joyner } 20208eb6488eSEric Joyner if ((hw->device_id == IXGBE_DEV_ID_82599_SFP_SF_QP) && 20218eb6488eSEric Joyner ((hw->bus.width <= ixgbe_bus_width_pcie_x8) && 20228eb6488eSEric Joyner (hw->bus.speed < ixgbe_bus_speed_8000))) { 20238eb6488eSEric Joyner device_printf(dev, "PCI-Express bandwidth available for this card\n is not sufficient for optimal performance.\n"); 20248eb6488eSEric Joyner device_printf(dev, "For optimal performance a x8 PCIE Gen3 slot is required.\n"); 20258eb6488eSEric Joyner } 20268eb6488eSEric Joyner } else 20278eb6488eSEric Joyner device_printf(dev, "Unable to determine slot speed/width. The speed/width reported are that of the internal switch.\n"); 20288eb6488eSEric Joyner 20298eb6488eSEric Joyner return; 20308eb6488eSEric Joyner } /* ixgbe_get_slot_info */ 20318eb6488eSEric Joyner 20328eb6488eSEric Joyner /************************************************************************ 2033c19c7afeSEric Joyner * ixgbe_if_msix_intr_assign 2034c19c7afeSEric Joyner * 2035c19c7afeSEric Joyner * Setup MSI-X Interrupt resources and handlers 20368eb6488eSEric Joyner ************************************************************************/ 2037c19c7afeSEric Joyner static int 2038c19c7afeSEric Joyner ixgbe_if_msix_intr_assign(if_ctx_t ctx, int msix) 20398eb6488eSEric Joyner { 2040c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 2041c19c7afeSEric Joyner struct ix_rx_queue *rx_que = adapter->rx_queues; 2042c19c7afeSEric Joyner struct ix_tx_queue *tx_que; 2043c19c7afeSEric Joyner int error, rid, vector = 0; 2044c19c7afeSEric Joyner int cpu_id = 0; 2045c19c7afeSEric Joyner char buf[16]; 20468eb6488eSEric Joyner 2047c19c7afeSEric Joyner /* Admin Que is vector 0*/ 2048c19c7afeSEric Joyner rid = vector + 1; 2049c19c7afeSEric Joyner for (int i = 0; i < adapter->num_rx_queues; i++, vector++, rx_que++) { 2050c19c7afeSEric Joyner rid = vector + 1; 2051c19c7afeSEric Joyner 2052c19c7afeSEric Joyner snprintf(buf, sizeof(buf), "rxq%d", i); 2053c19c7afeSEric Joyner error = iflib_irq_alloc_generic(ctx, &rx_que->que_irq, rid, 205481be6552SMatt Macy IFLIB_INTR_RXTX, ixgbe_msix_que, rx_que, rx_que->rxr.me, buf); 2055c19c7afeSEric Joyner 2056c19c7afeSEric Joyner if (error) { 2057c19c7afeSEric Joyner device_printf(iflib_get_dev(ctx), 2058c19c7afeSEric Joyner "Failed to allocate que int %d err: %d", i, error); 2059c19c7afeSEric Joyner adapter->num_rx_queues = i + 1; 2060c19c7afeSEric Joyner goto fail; 20618eb6488eSEric Joyner } 20628eb6488eSEric Joyner 2063c19c7afeSEric Joyner rx_que->msix = vector; 2064c19c7afeSEric Joyner if (adapter->feat_en & IXGBE_FEATURE_RSS) { 2065c19c7afeSEric Joyner /* 2066c19c7afeSEric Joyner * The queue ID is used as the RSS layer bucket ID. 2067c19c7afeSEric Joyner * We look up the queue ID -> RSS CPU ID and select 2068c19c7afeSEric Joyner * that. 2069c19c7afeSEric Joyner */ 2070c19c7afeSEric Joyner cpu_id = rss_getcpu(i % rss_getnumbuckets()); 20718eb6488eSEric Joyner } else { 2072c19c7afeSEric Joyner /* 2073b97de13aSMarius Strobl * Bind the MSI-X vector, and thus the 2074c19c7afeSEric Joyner * rings to the corresponding cpu. 2075c19c7afeSEric Joyner * 2076c19c7afeSEric Joyner * This just happens to match the default RSS 2077c19c7afeSEric Joyner * round-robin bucket -> queue -> CPU allocation. 2078c19c7afeSEric Joyner */ 2079c19c7afeSEric Joyner if (adapter->num_rx_queues > 1) 2080c19c7afeSEric Joyner cpu_id = i; 20818eb6488eSEric Joyner } 20828eb6488eSEric Joyner 2083c19c7afeSEric Joyner } 2084c19c7afeSEric Joyner for (int i = 0; i < adapter->num_tx_queues; i++) { 2085c19c7afeSEric Joyner snprintf(buf, sizeof(buf), "txq%d", i); 2086c19c7afeSEric Joyner tx_que = &adapter->tx_queues[i]; 2087c19c7afeSEric Joyner tx_que->msix = i % adapter->num_rx_queues; 2088c19c7afeSEric Joyner iflib_softirq_alloc_generic(ctx, 2089c19c7afeSEric Joyner &adapter->rx_queues[tx_que->msix].que_irq, 2090c19c7afeSEric Joyner IFLIB_INTR_TX, tx_que, tx_que->txr.me, buf); 2091c19c7afeSEric Joyner } 2092c19c7afeSEric Joyner rid = vector + 1; 2093c19c7afeSEric Joyner error = iflib_irq_alloc_generic(ctx, &adapter->irq, rid, 2094c19c7afeSEric Joyner IFLIB_INTR_ADMIN, ixgbe_msix_link, adapter, 0, "aq"); 2095c19c7afeSEric Joyner if (error) { 2096c19c7afeSEric Joyner device_printf(iflib_get_dev(ctx), 2097c19c7afeSEric Joyner "Failed to register admin handler"); 2098c19c7afeSEric Joyner return (error); 2099c19c7afeSEric Joyner } 2100c19c7afeSEric Joyner 2101c19c7afeSEric Joyner adapter->vector = vector; 2102c19c7afeSEric Joyner 2103c19c7afeSEric Joyner return (0); 2104c19c7afeSEric Joyner fail: 2105c19c7afeSEric Joyner iflib_irq_free(ctx, &adapter->irq); 2106c19c7afeSEric Joyner rx_que = adapter->rx_queues; 2107c19c7afeSEric Joyner for (int i = 0; i < adapter->num_rx_queues; i++, rx_que++) 2108c19c7afeSEric Joyner iflib_irq_free(ctx, &rx_que->que_irq); 2109c19c7afeSEric Joyner 2110c19c7afeSEric Joyner return (error); 2111c19c7afeSEric Joyner } /* ixgbe_if_msix_intr_assign */ 2112c19c7afeSEric Joyner 2113*64881da4SSai Rajesh Tallamraju static inline void 2114*64881da4SSai Rajesh Tallamraju ixgbe_perform_aim(struct adapter *adapter, struct ix_rx_queue *que) 2115*64881da4SSai Rajesh Tallamraju { 2116*64881da4SSai Rajesh Tallamraju uint32_t newitr = 0; 2117*64881da4SSai Rajesh Tallamraju struct rx_ring *rxr = &que->rxr; 2118*64881da4SSai Rajesh Tallamraju 2119*64881da4SSai Rajesh Tallamraju /* 2120*64881da4SSai Rajesh Tallamraju * Do Adaptive Interrupt Moderation: 2121*64881da4SSai Rajesh Tallamraju * - Write out last calculated setting 2122*64881da4SSai Rajesh Tallamraju * - Calculate based on average size over 2123*64881da4SSai Rajesh Tallamraju * the last interval. 2124*64881da4SSai Rajesh Tallamraju */ 2125*64881da4SSai Rajesh Tallamraju if (que->eitr_setting) { 2126*64881da4SSai Rajesh Tallamraju IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(que->msix), 2127*64881da4SSai Rajesh Tallamraju que->eitr_setting); 2128*64881da4SSai Rajesh Tallamraju } 2129*64881da4SSai Rajesh Tallamraju 2130*64881da4SSai Rajesh Tallamraju que->eitr_setting = 0; 2131*64881da4SSai Rajesh Tallamraju /* Idle, do nothing */ 2132*64881da4SSai Rajesh Tallamraju if (rxr->bytes == 0) { 2133*64881da4SSai Rajesh Tallamraju return; 2134*64881da4SSai Rajesh Tallamraju } 2135*64881da4SSai Rajesh Tallamraju 2136*64881da4SSai Rajesh Tallamraju if ((rxr->bytes) && (rxr->packets)) { 2137*64881da4SSai Rajesh Tallamraju newitr = (rxr->bytes / rxr->packets); 2138*64881da4SSai Rajesh Tallamraju } 2139*64881da4SSai Rajesh Tallamraju 2140*64881da4SSai Rajesh Tallamraju newitr += 24; /* account for hardware frame, crc */ 2141*64881da4SSai Rajesh Tallamraju /* set an upper boundary */ 2142*64881da4SSai Rajesh Tallamraju newitr = min(newitr, 3000); 2143*64881da4SSai Rajesh Tallamraju 2144*64881da4SSai Rajesh Tallamraju /* Be nice to the mid range */ 2145*64881da4SSai Rajesh Tallamraju if ((newitr > 300) && (newitr < 1200)) { 2146*64881da4SSai Rajesh Tallamraju newitr = (newitr / 3); 2147*64881da4SSai Rajesh Tallamraju } else { 2148*64881da4SSai Rajesh Tallamraju newitr = (newitr / 2); 2149*64881da4SSai Rajesh Tallamraju } 2150*64881da4SSai Rajesh Tallamraju 2151*64881da4SSai Rajesh Tallamraju if (adapter->hw.mac.type == ixgbe_mac_82598EB) { 2152*64881da4SSai Rajesh Tallamraju newitr |= newitr << 16; 2153*64881da4SSai Rajesh Tallamraju } else { 2154*64881da4SSai Rajesh Tallamraju newitr |= IXGBE_EITR_CNT_WDIS; 2155*64881da4SSai Rajesh Tallamraju } 2156*64881da4SSai Rajesh Tallamraju 2157*64881da4SSai Rajesh Tallamraju /* save for next interrupt */ 2158*64881da4SSai Rajesh Tallamraju que->eitr_setting = newitr; 2159*64881da4SSai Rajesh Tallamraju 2160*64881da4SSai Rajesh Tallamraju /* Reset state */ 2161*64881da4SSai Rajesh Tallamraju rxr->bytes = 0; 2162*64881da4SSai Rajesh Tallamraju rxr->packets = 0; 2163*64881da4SSai Rajesh Tallamraju 2164*64881da4SSai Rajesh Tallamraju return; 2165*64881da4SSai Rajesh Tallamraju } 2166*64881da4SSai Rajesh Tallamraju 2167c19c7afeSEric Joyner /********************************************************************* 21688eb6488eSEric Joyner * ixgbe_msix_que - MSI-X Queue Interrupt Service routine 2169c19c7afeSEric Joyner **********************************************************************/ 2170c19c7afeSEric Joyner static int 21718eb6488eSEric Joyner ixgbe_msix_que(void *arg) 21728eb6488eSEric Joyner { 2173c19c7afeSEric Joyner struct ix_rx_queue *que = arg; 21748eb6488eSEric Joyner struct adapter *adapter = que->adapter; 2175c19c7afeSEric Joyner struct ifnet *ifp = iflib_get_ifp(que->adapter->ctx); 21768eb6488eSEric Joyner 21778eb6488eSEric Joyner /* Protect against spurious interrupts */ 21788eb6488eSEric Joyner if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) 21796c351041SEric Joyner return (FILTER_HANDLED); 21808eb6488eSEric Joyner 21818eb6488eSEric Joyner ixgbe_disable_queue(adapter, que->msix); 21828eb6488eSEric Joyner ++que->irqs; 21838eb6488eSEric Joyner 2184*64881da4SSai Rajesh Tallamraju /* Check for AIM */ 2185*64881da4SSai Rajesh Tallamraju if (adapter->enable_aim) { 2186*64881da4SSai Rajesh Tallamraju ixgbe_perform_aim(adapter, que); 2187*64881da4SSai Rajesh Tallamraju } 2188*64881da4SSai Rajesh Tallamraju 2189c19c7afeSEric Joyner return (FILTER_SCHEDULE_THREAD); 21908eb6488eSEric Joyner } /* ixgbe_msix_que */ 21918eb6488eSEric Joyner 21928eb6488eSEric Joyner /************************************************************************ 21938eb6488eSEric Joyner * ixgbe_media_status - Media Ioctl callback 21948eb6488eSEric Joyner * 21958eb6488eSEric Joyner * Called whenever the user queries the status of 21968eb6488eSEric Joyner * the interface using ifconfig. 21978eb6488eSEric Joyner ************************************************************************/ 21988eb6488eSEric Joyner static void 2199c19c7afeSEric Joyner ixgbe_if_media_status(if_ctx_t ctx, struct ifmediareq * ifmr) 22008eb6488eSEric Joyner { 2201c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 22028eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 22038eb6488eSEric Joyner int layer; 22048eb6488eSEric Joyner 2205c19c7afeSEric Joyner INIT_DEBUGOUT("ixgbe_if_media_status: begin"); 2206c19c7afeSEric Joyner 22078eb6488eSEric Joyner ifmr->ifm_status = IFM_AVALID; 22088eb6488eSEric Joyner ifmr->ifm_active = IFM_ETHER; 22098eb6488eSEric Joyner 2210c19c7afeSEric Joyner if (!adapter->link_active) 22118eb6488eSEric Joyner return; 22128eb6488eSEric Joyner 22138eb6488eSEric Joyner ifmr->ifm_status |= IFM_ACTIVE; 22148eb6488eSEric Joyner layer = adapter->phy_layer; 22158eb6488eSEric Joyner 22168eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_T || 22178eb6488eSEric Joyner layer & IXGBE_PHYSICAL_LAYER_1000BASE_T || 22188eb6488eSEric Joyner layer & IXGBE_PHYSICAL_LAYER_100BASE_TX || 22198eb6488eSEric Joyner layer & IXGBE_PHYSICAL_LAYER_10BASE_T) 22208eb6488eSEric Joyner switch (adapter->link_speed) { 22218eb6488eSEric Joyner case IXGBE_LINK_SPEED_10GB_FULL: 22228eb6488eSEric Joyner ifmr->ifm_active |= IFM_10G_T | IFM_FDX; 22238eb6488eSEric Joyner break; 22248eb6488eSEric Joyner case IXGBE_LINK_SPEED_1GB_FULL: 22258eb6488eSEric Joyner ifmr->ifm_active |= IFM_1000_T | IFM_FDX; 22268eb6488eSEric Joyner break; 22278eb6488eSEric Joyner case IXGBE_LINK_SPEED_100_FULL: 22288eb6488eSEric Joyner ifmr->ifm_active |= IFM_100_TX | IFM_FDX; 22298eb6488eSEric Joyner break; 22308eb6488eSEric Joyner case IXGBE_LINK_SPEED_10_FULL: 22318eb6488eSEric Joyner ifmr->ifm_active |= IFM_10_T | IFM_FDX; 22328eb6488eSEric Joyner break; 22338eb6488eSEric Joyner } 22348eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU || 22358eb6488eSEric Joyner layer & IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA) 22368eb6488eSEric Joyner switch (adapter->link_speed) { 22378eb6488eSEric Joyner case IXGBE_LINK_SPEED_10GB_FULL: 22388eb6488eSEric Joyner ifmr->ifm_active |= IFM_10G_TWINAX | IFM_FDX; 22398eb6488eSEric Joyner break; 22408eb6488eSEric Joyner } 22418eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_LR) 22428eb6488eSEric Joyner switch (adapter->link_speed) { 22438eb6488eSEric Joyner case IXGBE_LINK_SPEED_10GB_FULL: 22448eb6488eSEric Joyner ifmr->ifm_active |= IFM_10G_LR | IFM_FDX; 22458eb6488eSEric Joyner break; 22468eb6488eSEric Joyner case IXGBE_LINK_SPEED_1GB_FULL: 22478eb6488eSEric Joyner ifmr->ifm_active |= IFM_1000_LX | IFM_FDX; 22488eb6488eSEric Joyner break; 22498eb6488eSEric Joyner } 22508eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_LRM) 22518eb6488eSEric Joyner switch (adapter->link_speed) { 22528eb6488eSEric Joyner case IXGBE_LINK_SPEED_10GB_FULL: 22538eb6488eSEric Joyner ifmr->ifm_active |= IFM_10G_LRM | IFM_FDX; 22548eb6488eSEric Joyner break; 22558eb6488eSEric Joyner case IXGBE_LINK_SPEED_1GB_FULL: 22568eb6488eSEric Joyner ifmr->ifm_active |= IFM_1000_LX | IFM_FDX; 22578eb6488eSEric Joyner break; 22588eb6488eSEric Joyner } 22598eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_SR || 22608eb6488eSEric Joyner layer & IXGBE_PHYSICAL_LAYER_1000BASE_SX) 22618eb6488eSEric Joyner switch (adapter->link_speed) { 22628eb6488eSEric Joyner case IXGBE_LINK_SPEED_10GB_FULL: 22638eb6488eSEric Joyner ifmr->ifm_active |= IFM_10G_SR | IFM_FDX; 22648eb6488eSEric Joyner break; 22658eb6488eSEric Joyner case IXGBE_LINK_SPEED_1GB_FULL: 22668eb6488eSEric Joyner ifmr->ifm_active |= IFM_1000_SX | IFM_FDX; 22678eb6488eSEric Joyner break; 22688eb6488eSEric Joyner } 22698eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_CX4) 22708eb6488eSEric Joyner switch (adapter->link_speed) { 22718eb6488eSEric Joyner case IXGBE_LINK_SPEED_10GB_FULL: 22728eb6488eSEric Joyner ifmr->ifm_active |= IFM_10G_CX4 | IFM_FDX; 22738eb6488eSEric Joyner break; 22748eb6488eSEric Joyner } 22758eb6488eSEric Joyner /* 22768eb6488eSEric Joyner * XXX: These need to use the proper media types once 22778eb6488eSEric Joyner * they're added. 22788eb6488eSEric Joyner */ 22798eb6488eSEric Joyner #ifndef IFM_ETH_XTYPE 22808eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_KR) 22818eb6488eSEric Joyner switch (adapter->link_speed) { 22828eb6488eSEric Joyner case IXGBE_LINK_SPEED_10GB_FULL: 22838eb6488eSEric Joyner ifmr->ifm_active |= IFM_10G_SR | IFM_FDX; 22848eb6488eSEric Joyner break; 22858eb6488eSEric Joyner case IXGBE_LINK_SPEED_2_5GB_FULL: 22868eb6488eSEric Joyner ifmr->ifm_active |= IFM_2500_SX | IFM_FDX; 22878eb6488eSEric Joyner break; 22888eb6488eSEric Joyner case IXGBE_LINK_SPEED_1GB_FULL: 22898eb6488eSEric Joyner ifmr->ifm_active |= IFM_1000_CX | IFM_FDX; 22908eb6488eSEric Joyner break; 22918eb6488eSEric Joyner } 22928eb6488eSEric Joyner else if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_KX4 || 22938eb6488eSEric Joyner layer & IXGBE_PHYSICAL_LAYER_2500BASE_KX || 22948eb6488eSEric Joyner layer & IXGBE_PHYSICAL_LAYER_1000BASE_KX) 22958eb6488eSEric Joyner switch (adapter->link_speed) { 22968eb6488eSEric Joyner case IXGBE_LINK_SPEED_10GB_FULL: 22978eb6488eSEric Joyner ifmr->ifm_active |= IFM_10G_CX4 | IFM_FDX; 22988eb6488eSEric Joyner break; 22998eb6488eSEric Joyner case IXGBE_LINK_SPEED_2_5GB_FULL: 23008eb6488eSEric Joyner ifmr->ifm_active |= IFM_2500_SX | IFM_FDX; 23018eb6488eSEric Joyner break; 23028eb6488eSEric Joyner case IXGBE_LINK_SPEED_1GB_FULL: 23038eb6488eSEric Joyner ifmr->ifm_active |= IFM_1000_CX | IFM_FDX; 23048eb6488eSEric Joyner break; 23058eb6488eSEric Joyner } 23068eb6488eSEric Joyner #else 23078eb6488eSEric Joyner if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_KR) 23088eb6488eSEric Joyner switch (adapter->link_speed) { 23098eb6488eSEric Joyner case IXGBE_LINK_SPEED_10GB_FULL: 23108eb6488eSEric Joyner ifmr->ifm_active |= IFM_10G_KR | IFM_FDX; 23118eb6488eSEric Joyner break; 23128eb6488eSEric Joyner case IXGBE_LINK_SPEED_2_5GB_FULL: 23138eb6488eSEric Joyner ifmr->ifm_active |= IFM_2500_KX | IFM_FDX; 23148eb6488eSEric Joyner break; 23158eb6488eSEric Joyner case IXGBE_LINK_SPEED_1GB_FULL: 23168eb6488eSEric Joyner ifmr->ifm_active |= IFM_1000_KX | IFM_FDX; 23178eb6488eSEric Joyner break; 23188eb6488eSEric Joyner } 23198eb6488eSEric Joyner else if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_KX4 || 23208eb6488eSEric Joyner layer & IXGBE_PHYSICAL_LAYER_2500BASE_KX || 23218eb6488eSEric Joyner layer & IXGBE_PHYSICAL_LAYER_1000BASE_KX) 23228eb6488eSEric Joyner switch (adapter->link_speed) { 23238eb6488eSEric Joyner case IXGBE_LINK_SPEED_10GB_FULL: 23248eb6488eSEric Joyner ifmr->ifm_active |= IFM_10G_KX4 | IFM_FDX; 23258eb6488eSEric Joyner break; 23268eb6488eSEric Joyner case IXGBE_LINK_SPEED_2_5GB_FULL: 23278eb6488eSEric Joyner ifmr->ifm_active |= IFM_2500_KX | IFM_FDX; 23288eb6488eSEric Joyner break; 23298eb6488eSEric Joyner case IXGBE_LINK_SPEED_1GB_FULL: 23308eb6488eSEric Joyner ifmr->ifm_active |= IFM_1000_KX | IFM_FDX; 23318eb6488eSEric Joyner break; 23328eb6488eSEric Joyner } 23338eb6488eSEric Joyner #endif 23348eb6488eSEric Joyner 23358eb6488eSEric Joyner /* If nothing is recognized... */ 23368eb6488eSEric Joyner if (IFM_SUBTYPE(ifmr->ifm_active) == 0) 23378eb6488eSEric Joyner ifmr->ifm_active |= IFM_UNKNOWN; 23388eb6488eSEric Joyner 23398eb6488eSEric Joyner /* Display current flow control setting used on link */ 23408eb6488eSEric Joyner if (hw->fc.current_mode == ixgbe_fc_rx_pause || 23418eb6488eSEric Joyner hw->fc.current_mode == ixgbe_fc_full) 23428eb6488eSEric Joyner ifmr->ifm_active |= IFM_ETH_RXPAUSE; 23438eb6488eSEric Joyner if (hw->fc.current_mode == ixgbe_fc_tx_pause || 23448eb6488eSEric Joyner hw->fc.current_mode == ixgbe_fc_full) 23458eb6488eSEric Joyner ifmr->ifm_active |= IFM_ETH_TXPAUSE; 23468eb6488eSEric Joyner } /* ixgbe_media_status */ 23478eb6488eSEric Joyner 23488eb6488eSEric Joyner /************************************************************************ 23498eb6488eSEric Joyner * ixgbe_media_change - Media Ioctl callback 23508eb6488eSEric Joyner * 23518eb6488eSEric Joyner * Called when the user changes speed/duplex using 23528eb6488eSEric Joyner * media/mediopt option with ifconfig. 23538eb6488eSEric Joyner ************************************************************************/ 23548eb6488eSEric Joyner static int 2355c19c7afeSEric Joyner ixgbe_if_media_change(if_ctx_t ctx) 23568eb6488eSEric Joyner { 2357c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 2358c19c7afeSEric Joyner struct ifmedia *ifm = iflib_get_media(ctx); 23598eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 23608eb6488eSEric Joyner ixgbe_link_speed speed = 0; 23618eb6488eSEric Joyner 2362c19c7afeSEric Joyner INIT_DEBUGOUT("ixgbe_if_media_change: begin"); 23638eb6488eSEric Joyner 23648eb6488eSEric Joyner if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) 23658eb6488eSEric Joyner return (EINVAL); 23668eb6488eSEric Joyner 23678eb6488eSEric Joyner if (hw->phy.media_type == ixgbe_media_type_backplane) 2368c19c7afeSEric Joyner return (EPERM); 23698eb6488eSEric Joyner 23708eb6488eSEric Joyner /* 23718eb6488eSEric Joyner * We don't actually need to check against the supported 23728eb6488eSEric Joyner * media types of the adapter; ifmedia will take care of 23738eb6488eSEric Joyner * that for us. 23748eb6488eSEric Joyner */ 23758eb6488eSEric Joyner switch (IFM_SUBTYPE(ifm->ifm_media)) { 23768eb6488eSEric Joyner case IFM_AUTO: 23778eb6488eSEric Joyner case IFM_10G_T: 23788eb6488eSEric Joyner speed |= IXGBE_LINK_SPEED_100_FULL; 23798eb6488eSEric Joyner speed |= IXGBE_LINK_SPEED_1GB_FULL; 23808eb6488eSEric Joyner speed |= IXGBE_LINK_SPEED_10GB_FULL; 23818eb6488eSEric Joyner break; 23828eb6488eSEric Joyner case IFM_10G_LRM: 23838eb6488eSEric Joyner case IFM_10G_LR: 23848eb6488eSEric Joyner #ifndef IFM_ETH_XTYPE 23858eb6488eSEric Joyner case IFM_10G_SR: /* KR, too */ 23868eb6488eSEric Joyner case IFM_10G_CX4: /* KX4 */ 23878eb6488eSEric Joyner #else 23888eb6488eSEric Joyner case IFM_10G_KR: 23898eb6488eSEric Joyner case IFM_10G_KX4: 23908eb6488eSEric Joyner #endif 23918eb6488eSEric Joyner speed |= IXGBE_LINK_SPEED_1GB_FULL; 23928eb6488eSEric Joyner speed |= IXGBE_LINK_SPEED_10GB_FULL; 23938eb6488eSEric Joyner break; 23948eb6488eSEric Joyner #ifndef IFM_ETH_XTYPE 23958eb6488eSEric Joyner case IFM_1000_CX: /* KX */ 23968eb6488eSEric Joyner #else 23978eb6488eSEric Joyner case IFM_1000_KX: 23988eb6488eSEric Joyner #endif 23998eb6488eSEric Joyner case IFM_1000_LX: 24008eb6488eSEric Joyner case IFM_1000_SX: 24018eb6488eSEric Joyner speed |= IXGBE_LINK_SPEED_1GB_FULL; 24028eb6488eSEric Joyner break; 24038eb6488eSEric Joyner case IFM_1000_T: 24048eb6488eSEric Joyner speed |= IXGBE_LINK_SPEED_100_FULL; 24058eb6488eSEric Joyner speed |= IXGBE_LINK_SPEED_1GB_FULL; 24068eb6488eSEric Joyner break; 24078eb6488eSEric Joyner case IFM_10G_TWINAX: 24088eb6488eSEric Joyner speed |= IXGBE_LINK_SPEED_10GB_FULL; 24098eb6488eSEric Joyner break; 24108eb6488eSEric Joyner case IFM_100_TX: 24118eb6488eSEric Joyner speed |= IXGBE_LINK_SPEED_100_FULL; 24128eb6488eSEric Joyner break; 24138eb6488eSEric Joyner case IFM_10_T: 24148eb6488eSEric Joyner speed |= IXGBE_LINK_SPEED_10_FULL; 24158eb6488eSEric Joyner break; 24168eb6488eSEric Joyner default: 24178eb6488eSEric Joyner goto invalid; 24188eb6488eSEric Joyner } 24198eb6488eSEric Joyner 24208eb6488eSEric Joyner hw->mac.autotry_restart = TRUE; 24218eb6488eSEric Joyner hw->mac.ops.setup_link(hw, speed, TRUE); 24228eb6488eSEric Joyner adapter->advertise = 24238eb6488eSEric Joyner ((speed & IXGBE_LINK_SPEED_10GB_FULL) ? 4 : 0) | 24248eb6488eSEric Joyner ((speed & IXGBE_LINK_SPEED_1GB_FULL) ? 2 : 0) | 24258eb6488eSEric Joyner ((speed & IXGBE_LINK_SPEED_100_FULL) ? 1 : 0) | 24268eb6488eSEric Joyner ((speed & IXGBE_LINK_SPEED_10_FULL) ? 8 : 0); 24278eb6488eSEric Joyner 24288eb6488eSEric Joyner return (0); 24298eb6488eSEric Joyner 24308eb6488eSEric Joyner invalid: 2431c19c7afeSEric Joyner device_printf(iflib_get_dev(ctx), "Invalid media type!\n"); 24328eb6488eSEric Joyner 24338eb6488eSEric Joyner return (EINVAL); 2434c19c7afeSEric Joyner } /* ixgbe_if_media_change */ 24358eb6488eSEric Joyner 24368eb6488eSEric Joyner /************************************************************************ 24378eb6488eSEric Joyner * ixgbe_set_promisc 24388eb6488eSEric Joyner ************************************************************************/ 2439c19c7afeSEric Joyner static int 2440c19c7afeSEric Joyner ixgbe_if_promisc_set(if_ctx_t ctx, int flags) 24418eb6488eSEric Joyner { 2442c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 2443c19c7afeSEric Joyner struct ifnet *ifp = iflib_get_ifp(ctx); 24448eb6488eSEric Joyner u32 rctl; 2445c19c7afeSEric Joyner int mcnt = 0; 24468eb6488eSEric Joyner 24478eb6488eSEric Joyner rctl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL); 24488eb6488eSEric Joyner rctl &= (~IXGBE_FCTRL_UPE); 24498eb6488eSEric Joyner if (ifp->if_flags & IFF_ALLMULTI) 24508eb6488eSEric Joyner mcnt = MAX_NUM_MULTICAST_ADDRESSES; 24518eb6488eSEric Joyner else { 2452ba76aa63SGleb Smirnoff mcnt = min(if_llmaddr_count(ifp), MAX_NUM_MULTICAST_ADDRESSES); 24538eb6488eSEric Joyner } 24548eb6488eSEric Joyner if (mcnt < MAX_NUM_MULTICAST_ADDRESSES) 24558eb6488eSEric Joyner rctl &= (~IXGBE_FCTRL_MPE); 24568eb6488eSEric Joyner IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, rctl); 24578eb6488eSEric Joyner 24588eb6488eSEric Joyner if (ifp->if_flags & IFF_PROMISC) { 24598eb6488eSEric Joyner rctl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); 24608eb6488eSEric Joyner IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, rctl); 24618eb6488eSEric Joyner } else if (ifp->if_flags & IFF_ALLMULTI) { 24628eb6488eSEric Joyner rctl |= IXGBE_FCTRL_MPE; 24638eb6488eSEric Joyner rctl &= ~IXGBE_FCTRL_UPE; 24648eb6488eSEric Joyner IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, rctl); 24658eb6488eSEric Joyner } 2466c19c7afeSEric Joyner return (0); 2467c19c7afeSEric Joyner } /* ixgbe_if_promisc_set */ 24688eb6488eSEric Joyner 24698eb6488eSEric Joyner /************************************************************************ 24708eb6488eSEric Joyner * ixgbe_msix_link - Link status change ISR (MSI/MSI-X) 24718eb6488eSEric Joyner ************************************************************************/ 2472c19c7afeSEric Joyner static int 24738eb6488eSEric Joyner ixgbe_msix_link(void *arg) 24748eb6488eSEric Joyner { 24758eb6488eSEric Joyner struct adapter *adapter = arg; 24768eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 24778eb6488eSEric Joyner u32 eicr, eicr_mask; 24788eb6488eSEric Joyner s32 retval; 24798eb6488eSEric Joyner 24808eb6488eSEric Joyner ++adapter->link_irq; 24818eb6488eSEric Joyner 24828eb6488eSEric Joyner /* Pause other interrupts */ 24838eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_OTHER); 24848eb6488eSEric Joyner 24858eb6488eSEric Joyner /* First get the cause */ 24868eb6488eSEric Joyner eicr = IXGBE_READ_REG(hw, IXGBE_EICS); 24878eb6488eSEric Joyner /* Be sure the queue bits are not cleared */ 24888eb6488eSEric Joyner eicr &= ~IXGBE_EICR_RTX_QUEUE; 24898eb6488eSEric Joyner /* Clear interrupt with write */ 24908eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); 24918eb6488eSEric Joyner 24928eb6488eSEric Joyner /* Link status change */ 24938eb6488eSEric Joyner if (eicr & IXGBE_EICR_LSC) { 24948eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); 2495b2c1e8e6SEric Joyner adapter->task_requests |= IXGBE_REQUEST_TASK_LSC; 24968eb6488eSEric Joyner } 24978eb6488eSEric Joyner 24988eb6488eSEric Joyner if (adapter->hw.mac.type != ixgbe_mac_82598EB) { 24998eb6488eSEric Joyner if ((adapter->feat_en & IXGBE_FEATURE_FDIR) && 25008eb6488eSEric Joyner (eicr & IXGBE_EICR_FLOW_DIR)) { 25018eb6488eSEric Joyner /* This is probably overkill :) */ 25028eb6488eSEric Joyner if (!atomic_cmpset_int(&adapter->fdir_reinit, 0, 1)) 2503c19c7afeSEric Joyner return (FILTER_HANDLED); 25048eb6488eSEric Joyner /* Disable the interrupt */ 2505c19c7afeSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EICR_FLOW_DIR); 2506b2c1e8e6SEric Joyner adapter->task_requests |= IXGBE_REQUEST_TASK_FDIR; 2507c19c7afeSEric Joyner } else 25088eb6488eSEric Joyner if (eicr & IXGBE_EICR_ECC) { 2509c19c7afeSEric Joyner device_printf(iflib_get_dev(adapter->ctx), 2510c19c7afeSEric Joyner "\nCRITICAL: ECC ERROR!! Please Reboot!!\n"); 25118eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); 25128eb6488eSEric Joyner } 25138eb6488eSEric Joyner 25148eb6488eSEric Joyner /* Check for over temp condition */ 25158eb6488eSEric Joyner if (adapter->feat_en & IXGBE_FEATURE_TEMP_SENSOR) { 25168eb6488eSEric Joyner switch (adapter->hw.mac.type) { 25178eb6488eSEric Joyner case ixgbe_mac_X550EM_a: 25188eb6488eSEric Joyner if (!(eicr & IXGBE_EICR_GPI_SDP0_X550EM_a)) 25198eb6488eSEric Joyner break; 25208eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIMC, 25218eb6488eSEric Joyner IXGBE_EICR_GPI_SDP0_X550EM_a); 25228eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EICR, 25238eb6488eSEric Joyner IXGBE_EICR_GPI_SDP0_X550EM_a); 25248eb6488eSEric Joyner retval = hw->phy.ops.check_overtemp(hw); 25258eb6488eSEric Joyner if (retval != IXGBE_ERR_OVERTEMP) 25268eb6488eSEric Joyner break; 2527c19c7afeSEric Joyner device_printf(iflib_get_dev(adapter->ctx), 2528c19c7afeSEric Joyner "\nCRITICAL: OVER TEMP!! PHY IS SHUT DOWN!!\n"); 2529c19c7afeSEric Joyner device_printf(iflib_get_dev(adapter->ctx), 2530c19c7afeSEric Joyner "System shutdown required!\n"); 25318eb6488eSEric Joyner break; 25328eb6488eSEric Joyner default: 25338eb6488eSEric Joyner if (!(eicr & IXGBE_EICR_TS)) 25348eb6488eSEric Joyner break; 25358eb6488eSEric Joyner retval = hw->phy.ops.check_overtemp(hw); 25368eb6488eSEric Joyner if (retval != IXGBE_ERR_OVERTEMP) 25378eb6488eSEric Joyner break; 2538c19c7afeSEric Joyner device_printf(iflib_get_dev(adapter->ctx), 2539c19c7afeSEric Joyner "\nCRITICAL: OVER TEMP!! PHY IS SHUT DOWN!!\n"); 2540c19c7afeSEric Joyner device_printf(iflib_get_dev(adapter->ctx), 2541c19c7afeSEric Joyner "System shutdown required!\n"); 25428eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_TS); 25438eb6488eSEric Joyner break; 25448eb6488eSEric Joyner } 25458eb6488eSEric Joyner } 25468eb6488eSEric Joyner 25478eb6488eSEric Joyner /* Check for VF message */ 25488eb6488eSEric Joyner if ((adapter->feat_en & IXGBE_FEATURE_SRIOV) && 25498eb6488eSEric Joyner (eicr & IXGBE_EICR_MAILBOX)) 2550b2c1e8e6SEric Joyner adapter->task_requests |= IXGBE_REQUEST_TASK_MBX; 25518eb6488eSEric Joyner } 25528eb6488eSEric Joyner 25538eb6488eSEric Joyner if (ixgbe_is_sfp(hw)) { 25548eb6488eSEric Joyner /* Pluggable optics-related interrupt */ 25558eb6488eSEric Joyner if (hw->mac.type >= ixgbe_mac_X540) 25568eb6488eSEric Joyner eicr_mask = IXGBE_EICR_GPI_SDP0_X540; 25578eb6488eSEric Joyner else 25588eb6488eSEric Joyner eicr_mask = IXGBE_EICR_GPI_SDP2_BY_MAC(hw); 25598eb6488eSEric Joyner 25608eb6488eSEric Joyner if (eicr & eicr_mask) { 25618eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask); 2562b2c1e8e6SEric Joyner adapter->task_requests |= IXGBE_REQUEST_TASK_MOD; 25638eb6488eSEric Joyner } 25648eb6488eSEric Joyner 25658eb6488eSEric Joyner if ((hw->mac.type == ixgbe_mac_82599EB) && 25668eb6488eSEric Joyner (eicr & IXGBE_EICR_GPI_SDP1_BY_MAC(hw))) { 25678eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EICR, 25688eb6488eSEric Joyner IXGBE_EICR_GPI_SDP1_BY_MAC(hw)); 2569b2c1e8e6SEric Joyner adapter->task_requests |= IXGBE_REQUEST_TASK_MSF; 25708eb6488eSEric Joyner } 25718eb6488eSEric Joyner } 25728eb6488eSEric Joyner 25738eb6488eSEric Joyner /* Check for fan failure */ 25748eb6488eSEric Joyner if (adapter->feat_en & IXGBE_FEATURE_FAN_FAIL) { 25758eb6488eSEric Joyner ixgbe_check_fan_failure(adapter, eicr, TRUE); 25768eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1_BY_MAC(hw)); 25778eb6488eSEric Joyner } 25788eb6488eSEric Joyner 25798eb6488eSEric Joyner /* External PHY interrupt */ 25808eb6488eSEric Joyner if ((hw->phy.type == ixgbe_phy_x550em_ext_t) && 25818eb6488eSEric Joyner (eicr & IXGBE_EICR_GPI_SDP0_X540)) { 25828eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP0_X540); 2583b2c1e8e6SEric Joyner adapter->task_requests |= IXGBE_REQUEST_TASK_PHY; 25848eb6488eSEric Joyner } 25858eb6488eSEric Joyner 2586b2c1e8e6SEric Joyner return (adapter->task_requests != 0) ? FILTER_SCHEDULE_THREAD : FILTER_HANDLED; 25878eb6488eSEric Joyner } /* ixgbe_msix_link */ 25888eb6488eSEric Joyner 25898eb6488eSEric Joyner /************************************************************************ 25908eb6488eSEric Joyner * ixgbe_sysctl_interrupt_rate_handler 25918eb6488eSEric Joyner ************************************************************************/ 2592758cc3dcSJack F Vogel static int 2593758cc3dcSJack F Vogel ixgbe_sysctl_interrupt_rate_handler(SYSCTL_HANDLER_ARGS) 2594758cc3dcSJack F Vogel { 2595c19c7afeSEric Joyner struct ix_rx_queue *que = ((struct ix_rx_queue *)oidp->oid_arg1); 25968eb6488eSEric Joyner int error; 2597758cc3dcSJack F Vogel unsigned int reg, usec, rate; 2598758cc3dcSJack F Vogel 2599758cc3dcSJack F Vogel reg = IXGBE_READ_REG(&que->adapter->hw, IXGBE_EITR(que->msix)); 2600758cc3dcSJack F Vogel usec = ((reg & 0x0FF8) >> 3); 2601758cc3dcSJack F Vogel if (usec > 0) 2602758cc3dcSJack F Vogel rate = 500000 / usec; 2603758cc3dcSJack F Vogel else 2604758cc3dcSJack F Vogel rate = 0; 2605758cc3dcSJack F Vogel error = sysctl_handle_int(oidp, &rate, 0, req); 2606758cc3dcSJack F Vogel if (error || !req->newptr) 2607758cc3dcSJack F Vogel return error; 2608758cc3dcSJack F Vogel reg &= ~0xfff; /* default, no limitation */ 2609758cc3dcSJack F Vogel ixgbe_max_interrupt_rate = 0; 2610758cc3dcSJack F Vogel if (rate > 0 && rate < 500000) { 2611758cc3dcSJack F Vogel if (rate < 1000) 2612758cc3dcSJack F Vogel rate = 1000; 2613758cc3dcSJack F Vogel ixgbe_max_interrupt_rate = rate; 2614758cc3dcSJack F Vogel reg |= ((4000000/rate) & 0xff8); 2615758cc3dcSJack F Vogel } 2616758cc3dcSJack F Vogel IXGBE_WRITE_REG(&que->adapter->hw, IXGBE_EITR(que->msix), reg); 2617758cc3dcSJack F Vogel 26188eb6488eSEric Joyner return (0); 26198eb6488eSEric Joyner } /* ixgbe_sysctl_interrupt_rate_handler */ 26208eb6488eSEric Joyner 26218eb6488eSEric Joyner /************************************************************************ 26228eb6488eSEric Joyner * ixgbe_add_device_sysctls 26238eb6488eSEric Joyner ************************************************************************/ 26246f37f232SEric Joyner static void 2625c19c7afeSEric Joyner ixgbe_add_device_sysctls(if_ctx_t ctx) 26266f37f232SEric Joyner { 2627c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 2628c19c7afeSEric Joyner device_t dev = iflib_get_dev(ctx); 26296f37f232SEric Joyner struct ixgbe_hw *hw = &adapter->hw; 26306f37f232SEric Joyner struct sysctl_oid_list *child; 2631c19c7afeSEric Joyner struct sysctl_ctx_list *ctx_list; 26326f37f232SEric Joyner 2633c19c7afeSEric Joyner ctx_list = device_get_sysctl_ctx(dev); 26346f37f232SEric Joyner child = SYSCTL_CHILDREN(device_get_sysctl_tree(dev)); 26356f37f232SEric Joyner 26366f37f232SEric Joyner /* Sysctls for all devices */ 2637c19c7afeSEric Joyner SYSCTL_ADD_PROC(ctx_list, child, OID_AUTO, "fc", 263820b91f0aSPawel Biernacki CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, 263920b91f0aSPawel Biernacki adapter, 0, ixgbe_sysctl_flowcntl, "I", 2640c19c7afeSEric Joyner IXGBE_SYSCTL_DESC_SET_FC); 26416f37f232SEric Joyner 2642c19c7afeSEric Joyner SYSCTL_ADD_PROC(ctx_list, child, OID_AUTO, "advertise_speed", 264320b91f0aSPawel Biernacki CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, 264420b91f0aSPawel Biernacki adapter, 0, ixgbe_sysctl_advertise, "I", 26458eb6488eSEric Joyner IXGBE_SYSCTL_DESC_ADV_SPEED); 26466f37f232SEric Joyner 2647*64881da4SSai Rajesh Tallamraju adapter->enable_aim = ixgbe_enable_aim; 2648*64881da4SSai Rajesh Tallamraju SYSCTL_ADD_INT(ctx_list, child, OID_AUTO, "enable_aim", CTLFLAG_RW, 2649*64881da4SSai Rajesh Tallamraju &adapter->enable_aim, 0, "Interrupt Moderation"); 2650*64881da4SSai Rajesh Tallamraju 2651a9ca1c79SSean Bruno #ifdef IXGBE_DEBUG 2652a9ca1c79SSean Bruno /* testing sysctls (for all devices) */ 2653c19c7afeSEric Joyner SYSCTL_ADD_PROC(ctx_list, child, OID_AUTO, "power_state", 265420b91f0aSPawel Biernacki CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, 265520b91f0aSPawel Biernacki adapter, 0, ixgbe_sysctl_power_state, 26568eb6488eSEric Joyner "I", "PCI Power State"); 2657a9ca1c79SSean Bruno 2658c19c7afeSEric Joyner SYSCTL_ADD_PROC(ctx_list, child, OID_AUTO, "print_rss_config", 265920b91f0aSPawel Biernacki CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_NEEDGIANT, adapter, 0, 2660a9ca1c79SSean Bruno ixgbe_sysctl_print_rss_config, "A", "Prints RSS Configuration"); 2661a9ca1c79SSean Bruno #endif 2662a9ca1c79SSean Bruno /* for X550 series devices */ 26636f37f232SEric Joyner if (hw->mac.type >= ixgbe_mac_X550) 2664c19c7afeSEric Joyner SYSCTL_ADD_PROC(ctx_list, child, OID_AUTO, "dmac", 266520b91f0aSPawel Biernacki CTLTYPE_U16 | CTLFLAG_RW | CTLFLAG_NEEDGIANT, 266620b91f0aSPawel Biernacki adapter, 0, ixgbe_sysctl_dmac, 26678eb6488eSEric Joyner "I", "DMA Coalesce"); 26686f37f232SEric Joyner 2669a9ca1c79SSean Bruno /* for WoL-capable devices */ 2670a9ca1c79SSean Bruno if (hw->device_id == IXGBE_DEV_ID_X550EM_X_10G_T) { 2671c19c7afeSEric Joyner SYSCTL_ADD_PROC(ctx_list, child, OID_AUTO, "wol_enable", 267220b91f0aSPawel Biernacki CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, adapter, 0, 26738eb6488eSEric Joyner ixgbe_sysctl_wol_enable, "I", "Enable/Disable Wake on LAN"); 26746f37f232SEric Joyner 2675c19c7afeSEric Joyner SYSCTL_ADD_PROC(ctx_list, child, OID_AUTO, "wufc", 267620b91f0aSPawel Biernacki CTLTYPE_U32 | CTLFLAG_RW | CTLFLAG_NEEDGIANT, 267720b91f0aSPawel Biernacki adapter, 0, ixgbe_sysctl_wufc, 26788eb6488eSEric Joyner "I", "Enable/Disable Wake Up Filters"); 26796f37f232SEric Joyner } 26806f37f232SEric Joyner 2681a9ca1c79SSean Bruno /* for X552/X557-AT devices */ 26826f37f232SEric Joyner if (hw->device_id == IXGBE_DEV_ID_X550EM_X_10G_T) { 26836f37f232SEric Joyner struct sysctl_oid *phy_node; 26846f37f232SEric Joyner struct sysctl_oid_list *phy_list; 26856f37f232SEric Joyner 2686c19c7afeSEric Joyner phy_node = SYSCTL_ADD_NODE(ctx_list, child, OID_AUTO, "phy", 268720b91f0aSPawel Biernacki CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "External PHY sysctls"); 26886f37f232SEric Joyner phy_list = SYSCTL_CHILDREN(phy_node); 26896f37f232SEric Joyner 2690c19c7afeSEric Joyner SYSCTL_ADD_PROC(ctx_list, phy_list, OID_AUTO, "temp", 269120b91f0aSPawel Biernacki CTLTYPE_U16 | CTLFLAG_RD | CTLFLAG_NEEDGIANT, 269220b91f0aSPawel Biernacki adapter, 0, ixgbe_sysctl_phy_temp, 26938eb6488eSEric Joyner "I", "Current External PHY Temperature (Celsius)"); 26946f37f232SEric Joyner 2695c19c7afeSEric Joyner SYSCTL_ADD_PROC(ctx_list, phy_list, OID_AUTO, 269620b91f0aSPawel Biernacki "overtemp_occurred", 269720b91f0aSPawel Biernacki CTLTYPE_U16 | CTLFLAG_RD | CTLFLAG_NEEDGIANT, adapter, 0, 26986f37f232SEric Joyner ixgbe_sysctl_phy_overtemp_occurred, "I", 26996f37f232SEric Joyner "External PHY High Temperature Event Occurred"); 27006f37f232SEric Joyner } 27018eb6488eSEric Joyner 27028eb6488eSEric Joyner if (adapter->feat_cap & IXGBE_FEATURE_EEE) { 2703c19c7afeSEric Joyner SYSCTL_ADD_PROC(ctx_list, child, OID_AUTO, "eee_state", 270420b91f0aSPawel Biernacki CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, adapter, 0, 27058eb6488eSEric Joyner ixgbe_sysctl_eee_state, "I", "EEE Power Save State"); 27068eb6488eSEric Joyner } 27078eb6488eSEric Joyner } /* ixgbe_add_device_sysctls */ 27088eb6488eSEric Joyner 27098eb6488eSEric Joyner /************************************************************************ 27108eb6488eSEric Joyner * ixgbe_allocate_pci_resources 27118eb6488eSEric Joyner ************************************************************************/ 27128eb6488eSEric Joyner static int 2713c19c7afeSEric Joyner ixgbe_allocate_pci_resources(if_ctx_t ctx) 27148eb6488eSEric Joyner { 2715c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 2716c19c7afeSEric Joyner device_t dev = iflib_get_dev(ctx); 27178eb6488eSEric Joyner int rid; 27188eb6488eSEric Joyner 27198eb6488eSEric Joyner rid = PCIR_BAR(0); 27208eb6488eSEric Joyner adapter->pci_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 27218eb6488eSEric Joyner RF_ACTIVE); 27228eb6488eSEric Joyner 27238eb6488eSEric Joyner if (!(adapter->pci_mem)) { 27248eb6488eSEric Joyner device_printf(dev, "Unable to allocate bus resource: memory\n"); 27258eb6488eSEric Joyner return (ENXIO); 27268eb6488eSEric Joyner } 27278eb6488eSEric Joyner 27288eb6488eSEric Joyner /* Save bus_space values for READ/WRITE_REG macros */ 27298eb6488eSEric Joyner adapter->osdep.mem_bus_space_tag = rman_get_bustag(adapter->pci_mem); 27308eb6488eSEric Joyner adapter->osdep.mem_bus_space_handle = 27318eb6488eSEric Joyner rman_get_bushandle(adapter->pci_mem); 27328eb6488eSEric Joyner /* Set hw values for shared code */ 27338eb6488eSEric Joyner adapter->hw.hw_addr = (u8 *)&adapter->osdep.mem_bus_space_handle; 27348eb6488eSEric Joyner 27358eb6488eSEric Joyner return (0); 27368eb6488eSEric Joyner } /* ixgbe_allocate_pci_resources */ 27378eb6488eSEric Joyner 27388eb6488eSEric Joyner /************************************************************************ 27398eb6488eSEric Joyner * ixgbe_detach - Device removal routine 27408eb6488eSEric Joyner * 27418eb6488eSEric Joyner * Called when the driver is being removed. 27428eb6488eSEric Joyner * Stops the adapter and deallocates all the resources 27438eb6488eSEric Joyner * that were allocated for driver operation. 27448eb6488eSEric Joyner * 27458eb6488eSEric Joyner * return 0 on success, positive on failure 27468eb6488eSEric Joyner ************************************************************************/ 27478eb6488eSEric Joyner static int 2748c19c7afeSEric Joyner ixgbe_if_detach(if_ctx_t ctx) 27498eb6488eSEric Joyner { 2750c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 2751c19c7afeSEric Joyner device_t dev = iflib_get_dev(ctx); 27528eb6488eSEric Joyner u32 ctrl_ext; 27538eb6488eSEric Joyner 27548eb6488eSEric Joyner INIT_DEBUGOUT("ixgbe_detach: begin"); 27558eb6488eSEric Joyner 27568eb6488eSEric Joyner if (ixgbe_pci_iov_detach(dev) != 0) { 27578eb6488eSEric Joyner device_printf(dev, "SR-IOV in use; detach first.\n"); 27588eb6488eSEric Joyner return (EBUSY); 27598eb6488eSEric Joyner } 27608eb6488eSEric Joyner 2761c19c7afeSEric Joyner ixgbe_setup_low_power_mode(ctx); 27628eb6488eSEric Joyner 27638eb6488eSEric Joyner /* let hardware know driver is unloading */ 27648eb6488eSEric Joyner ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); 27658eb6488eSEric Joyner ctrl_ext &= ~IXGBE_CTRL_EXT_DRV_LOAD; 27668eb6488eSEric Joyner IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, ctrl_ext); 27678eb6488eSEric Joyner 2768c19c7afeSEric Joyner ixgbe_free_pci_resources(ctx); 27698eb6488eSEric Joyner free(adapter->mta, M_IXGBE); 27708eb6488eSEric Joyner 27718eb6488eSEric Joyner return (0); 2772c19c7afeSEric Joyner } /* ixgbe_if_detach */ 27738eb6488eSEric Joyner 27748eb6488eSEric Joyner /************************************************************************ 27758eb6488eSEric Joyner * ixgbe_setup_low_power_mode - LPLU/WoL preparation 27768eb6488eSEric Joyner * 27778eb6488eSEric Joyner * Prepare the adapter/port for LPLU and/or WoL 27788eb6488eSEric Joyner ************************************************************************/ 27798eb6488eSEric Joyner static int 2780c19c7afeSEric Joyner ixgbe_setup_low_power_mode(if_ctx_t ctx) 27818eb6488eSEric Joyner { 2782c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 27838eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 2784c19c7afeSEric Joyner device_t dev = iflib_get_dev(ctx); 27858eb6488eSEric Joyner s32 error = 0; 27868eb6488eSEric Joyner 2787c19c7afeSEric Joyner if (!hw->wol_enabled) 2788c19c7afeSEric Joyner ixgbe_set_phy_power(hw, FALSE); 27898eb6488eSEric Joyner 27908eb6488eSEric Joyner /* Limit power management flow to X550EM baseT */ 27918eb6488eSEric Joyner if (hw->device_id == IXGBE_DEV_ID_X550EM_X_10G_T && 27928eb6488eSEric Joyner hw->phy.ops.enter_lplu) { 27938eb6488eSEric Joyner /* Turn off support for APM wakeup. (Using ACPI instead) */ 27948eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_GRC, 27958eb6488eSEric Joyner IXGBE_READ_REG(hw, IXGBE_GRC) & ~(u32)2); 27968eb6488eSEric Joyner 27978eb6488eSEric Joyner /* 27988eb6488eSEric Joyner * Clear Wake Up Status register to prevent any previous wakeup 27998eb6488eSEric Joyner * events from waking us up immediately after we suspend. 28008eb6488eSEric Joyner */ 28018eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_WUS, 0xffffffff); 28028eb6488eSEric Joyner 28038eb6488eSEric Joyner /* 28048eb6488eSEric Joyner * Program the Wakeup Filter Control register with user filter 28058eb6488eSEric Joyner * settings 28068eb6488eSEric Joyner */ 28078eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_WUFC, adapter->wufc); 28088eb6488eSEric Joyner 28098eb6488eSEric Joyner /* Enable wakeups and power management in Wakeup Control */ 28108eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_WUC, 28118eb6488eSEric Joyner IXGBE_WUC_WKEN | IXGBE_WUC_PME_EN); 28128eb6488eSEric Joyner 28138eb6488eSEric Joyner /* X550EM baseT adapters need a special LPLU flow */ 2814c19c7afeSEric Joyner hw->phy.reset_disable = TRUE; 2815c19c7afeSEric Joyner ixgbe_if_stop(ctx); 28168eb6488eSEric Joyner error = hw->phy.ops.enter_lplu(hw); 28178eb6488eSEric Joyner if (error) 28188eb6488eSEric Joyner device_printf(dev, "Error entering LPLU: %d\n", error); 2819c19c7afeSEric Joyner hw->phy.reset_disable = FALSE; 28208eb6488eSEric Joyner } else { 28218eb6488eSEric Joyner /* Just stop for other adapters */ 2822c19c7afeSEric Joyner ixgbe_if_stop(ctx); 28238eb6488eSEric Joyner } 28248eb6488eSEric Joyner 28258eb6488eSEric Joyner return error; 28268eb6488eSEric Joyner } /* ixgbe_setup_low_power_mode */ 28278eb6488eSEric Joyner 28288eb6488eSEric Joyner /************************************************************************ 28298eb6488eSEric Joyner * ixgbe_shutdown - Shutdown entry point 28308eb6488eSEric Joyner ************************************************************************/ 28318eb6488eSEric Joyner static int 2832c19c7afeSEric Joyner ixgbe_if_shutdown(if_ctx_t ctx) 28338eb6488eSEric Joyner { 28348eb6488eSEric Joyner int error = 0; 28358eb6488eSEric Joyner 28368eb6488eSEric Joyner INIT_DEBUGOUT("ixgbe_shutdown: begin"); 28378eb6488eSEric Joyner 2838c19c7afeSEric Joyner error = ixgbe_setup_low_power_mode(ctx); 28398eb6488eSEric Joyner 28408eb6488eSEric Joyner return (error); 2841c19c7afeSEric Joyner } /* ixgbe_if_shutdown */ 28428eb6488eSEric Joyner 28438eb6488eSEric Joyner /************************************************************************ 28448eb6488eSEric Joyner * ixgbe_suspend 28458eb6488eSEric Joyner * 28468eb6488eSEric Joyner * From D0 to D3 28478eb6488eSEric Joyner ************************************************************************/ 28488eb6488eSEric Joyner static int 2849c19c7afeSEric Joyner ixgbe_if_suspend(if_ctx_t ctx) 28508eb6488eSEric Joyner { 28518eb6488eSEric Joyner int error = 0; 28528eb6488eSEric Joyner 28538eb6488eSEric Joyner INIT_DEBUGOUT("ixgbe_suspend: begin"); 28548eb6488eSEric Joyner 2855c19c7afeSEric Joyner error = ixgbe_setup_low_power_mode(ctx); 28568eb6488eSEric Joyner 28578eb6488eSEric Joyner return (error); 2858c19c7afeSEric Joyner } /* ixgbe_if_suspend */ 28598eb6488eSEric Joyner 28608eb6488eSEric Joyner /************************************************************************ 28618eb6488eSEric Joyner * ixgbe_resume 28628eb6488eSEric Joyner * 28638eb6488eSEric Joyner * From D3 to D0 28648eb6488eSEric Joyner ************************************************************************/ 28658eb6488eSEric Joyner static int 2866c19c7afeSEric Joyner ixgbe_if_resume(if_ctx_t ctx) 28678eb6488eSEric Joyner { 2868c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 2869c19c7afeSEric Joyner device_t dev = iflib_get_dev(ctx); 2870c19c7afeSEric Joyner struct ifnet *ifp = iflib_get_ifp(ctx); 28718eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 28728eb6488eSEric Joyner u32 wus; 28738eb6488eSEric Joyner 28748eb6488eSEric Joyner INIT_DEBUGOUT("ixgbe_resume: begin"); 28758eb6488eSEric Joyner 28768eb6488eSEric Joyner /* Read & clear WUS register */ 28778eb6488eSEric Joyner wus = IXGBE_READ_REG(hw, IXGBE_WUS); 28788eb6488eSEric Joyner if (wus) 28798eb6488eSEric Joyner device_printf(dev, "Woken up by (WUS): %#010x\n", 28808eb6488eSEric Joyner IXGBE_READ_REG(hw, IXGBE_WUS)); 28818eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_WUS, 0xffffffff); 28828eb6488eSEric Joyner /* And clear WUFC until next low-power transition */ 28838eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); 28848eb6488eSEric Joyner 28858eb6488eSEric Joyner /* 28868eb6488eSEric Joyner * Required after D3->D0 transition; 28878eb6488eSEric Joyner * will re-advertise all previous advertised speeds 28888eb6488eSEric Joyner */ 28898eb6488eSEric Joyner if (ifp->if_flags & IFF_UP) 2890c19c7afeSEric Joyner ixgbe_if_init(ctx); 28918eb6488eSEric Joyner 28928eb6488eSEric Joyner return (0); 2893c19c7afeSEric Joyner } /* ixgbe_if_resume */ 28948eb6488eSEric Joyner 28958eb6488eSEric Joyner /************************************************************************ 2896c19c7afeSEric Joyner * ixgbe_if_mtu_set - Ioctl mtu entry point 28978eb6488eSEric Joyner * 2898c19c7afeSEric Joyner * Return 0 on success, EINVAL on failure 2899c19c7afeSEric Joyner ************************************************************************/ 2900c19c7afeSEric Joyner static int 2901c19c7afeSEric Joyner ixgbe_if_mtu_set(if_ctx_t ctx, uint32_t mtu) 2902c19c7afeSEric Joyner { 2903c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 2904c19c7afeSEric Joyner int error = 0; 2905c19c7afeSEric Joyner 2906c19c7afeSEric Joyner IOCTL_DEBUGOUT("ioctl: SIOCIFMTU (Set Interface MTU)"); 2907c19c7afeSEric Joyner 2908c19c7afeSEric Joyner if (mtu > IXGBE_MAX_MTU) { 2909c19c7afeSEric Joyner error = EINVAL; 2910c19c7afeSEric Joyner } else { 2911c19c7afeSEric Joyner adapter->max_frame_size = mtu + IXGBE_MTU_HDR; 2912c19c7afeSEric Joyner } 2913c19c7afeSEric Joyner 2914c19c7afeSEric Joyner return error; 2915c19c7afeSEric Joyner } /* ixgbe_if_mtu_set */ 2916c19c7afeSEric Joyner 2917c19c7afeSEric Joyner /************************************************************************ 2918c19c7afeSEric Joyner * ixgbe_if_crcstrip_set 29198eb6488eSEric Joyner ************************************************************************/ 29208eb6488eSEric Joyner static void 2921c19c7afeSEric Joyner ixgbe_if_crcstrip_set(if_ctx_t ctx, int onoff, int crcstrip) 29228eb6488eSEric Joyner { 2923c19c7afeSEric Joyner struct adapter *sc = iflib_get_softc(ctx); 2924c19c7afeSEric Joyner struct ixgbe_hw *hw = &sc->hw; 2925c19c7afeSEric Joyner /* crc stripping is set in two places: 2926c19c7afeSEric Joyner * IXGBE_HLREG0 (modified on init_locked and hw reset) 2927c19c7afeSEric Joyner * IXGBE_RDRXCTL (set by the original driver in 2928c19c7afeSEric Joyner * ixgbe_setup_hw_rsc() called in init_locked. 2929c19c7afeSEric Joyner * We disable the setting when netmap is compiled in). 2930c19c7afeSEric Joyner * We update the values here, but also in ixgbe.c because 2931c19c7afeSEric Joyner * init_locked sometimes is called outside our control. 2932c19c7afeSEric Joyner */ 2933c19c7afeSEric Joyner uint32_t hl, rxc; 29348eb6488eSEric Joyner 2935c19c7afeSEric Joyner hl = IXGBE_READ_REG(hw, IXGBE_HLREG0); 2936c19c7afeSEric Joyner rxc = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); 2937c19c7afeSEric Joyner #ifdef NETMAP 2938c19c7afeSEric Joyner if (netmap_verbose) 2939c19c7afeSEric Joyner D("%s read HLREG 0x%x rxc 0x%x", 2940c19c7afeSEric Joyner onoff ? "enter" : "exit", hl, rxc); 29418eb6488eSEric Joyner #endif 2942c19c7afeSEric Joyner /* hw requirements ... */ 2943c19c7afeSEric Joyner rxc &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; 2944c19c7afeSEric Joyner rxc |= IXGBE_RDRXCTL_RSCACKC; 2945c19c7afeSEric Joyner if (onoff && !crcstrip) { 2946c19c7afeSEric Joyner /* keep the crc. Fast rx */ 2947c19c7afeSEric Joyner hl &= ~IXGBE_HLREG0_RXCRCSTRP; 2948c19c7afeSEric Joyner rxc &= ~IXGBE_RDRXCTL_CRCSTRIP; 2949c19c7afeSEric Joyner } else { 2950c19c7afeSEric Joyner /* reset default mode */ 2951c19c7afeSEric Joyner hl |= IXGBE_HLREG0_RXCRCSTRP; 2952c19c7afeSEric Joyner rxc |= IXGBE_RDRXCTL_CRCSTRIP; 2953c19c7afeSEric Joyner } 2954c19c7afeSEric Joyner #ifdef NETMAP 2955c19c7afeSEric Joyner if (netmap_verbose) 2956c19c7afeSEric Joyner D("%s write HLREG 0x%x rxc 0x%x", 2957c19c7afeSEric Joyner onoff ? "enter" : "exit", hl, rxc); 2958c19c7afeSEric Joyner #endif 2959c19c7afeSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hl); 2960c19c7afeSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rxc); 2961c19c7afeSEric Joyner } /* ixgbe_if_crcstrip_set */ 29628eb6488eSEric Joyner 2963c19c7afeSEric Joyner /********************************************************************* 2964c19c7afeSEric Joyner * ixgbe_if_init - Init entry point 29658eb6488eSEric Joyner * 29668eb6488eSEric Joyner * Used in two ways: It is used by the stack as an init 29678eb6488eSEric Joyner * entry point in network interface structure. It is also 29688eb6488eSEric Joyner * used by the driver as a hw/sw initialization routine to 29698eb6488eSEric Joyner * get to a consistent state. 29708eb6488eSEric Joyner * 2971c19c7afeSEric Joyner * Return 0 on success, positive on failure 2972c19c7afeSEric Joyner **********************************************************************/ 29738eb6488eSEric Joyner void 2974c19c7afeSEric Joyner ixgbe_if_init(if_ctx_t ctx) 29758eb6488eSEric Joyner { 2976c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 2977c19c7afeSEric Joyner struct ifnet *ifp = iflib_get_ifp(ctx); 2978c19c7afeSEric Joyner device_t dev = iflib_get_dev(ctx); 29798eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 2980c19c7afeSEric Joyner struct ix_rx_queue *rx_que; 2981c19c7afeSEric Joyner struct ix_tx_queue *tx_que; 29828eb6488eSEric Joyner u32 txdctl, mhadd; 29838eb6488eSEric Joyner u32 rxdctl, rxctrl; 29848eb6488eSEric Joyner u32 ctrl_ext; 29858eb6488eSEric Joyner 2986c19c7afeSEric Joyner int i, j, err; 29878eb6488eSEric Joyner 2988c19c7afeSEric Joyner INIT_DEBUGOUT("ixgbe_if_init: begin"); 29898eb6488eSEric Joyner 29908eb6488eSEric Joyner /* Queue indices may change with IOV mode */ 29918eb6488eSEric Joyner ixgbe_align_all_queue_indices(adapter); 29928eb6488eSEric Joyner 29938eb6488eSEric Joyner /* reprogram the RAR[0] in case user changed it. */ 29948eb6488eSEric Joyner ixgbe_set_rar(hw, 0, hw->mac.addr, adapter->pool, IXGBE_RAH_AV); 29958eb6488eSEric Joyner 29968eb6488eSEric Joyner /* Get the latest mac address, User can use a LAA */ 29978eb6488eSEric Joyner bcopy(IF_LLADDR(ifp), hw->mac.addr, IXGBE_ETH_LENGTH_OF_ADDRESS); 29988eb6488eSEric Joyner ixgbe_set_rar(hw, 0, hw->mac.addr, adapter->pool, 1); 29998eb6488eSEric Joyner hw->addr_ctrl.rar_used_count = 1; 30008eb6488eSEric Joyner 30018eb6488eSEric Joyner ixgbe_init_hw(hw); 3002c19c7afeSEric Joyner 30038eb6488eSEric Joyner ixgbe_initialize_iov(adapter); 3004c19c7afeSEric Joyner 3005c19c7afeSEric Joyner ixgbe_initialize_transmit_units(ctx); 30068eb6488eSEric Joyner 30078eb6488eSEric Joyner /* Setup Multicast table */ 3008c19c7afeSEric Joyner ixgbe_if_multi_set(ctx); 30098eb6488eSEric Joyner 30108eb6488eSEric Joyner /* Determine the correct mbuf pool, based on frame size */ 30111b9d9394SEric Joyner adapter->rx_mbuf_sz = iflib_get_rx_mbuf_sz(ctx); 30128eb6488eSEric Joyner 30138eb6488eSEric Joyner /* Configure RX settings */ 3014c19c7afeSEric Joyner ixgbe_initialize_receive_units(ctx); 30158eb6488eSEric Joyner 3016b2c1e8e6SEric Joyner /* 3017b2c1e8e6SEric Joyner * Initialize variable holding task enqueue requests 3018b2c1e8e6SEric Joyner * from MSI-X interrupts 3019b2c1e8e6SEric Joyner */ 3020b2c1e8e6SEric Joyner adapter->task_requests = 0; 3021b2c1e8e6SEric Joyner 30228eb6488eSEric Joyner /* Enable SDP & MSI-X interrupts based on adapter */ 30238eb6488eSEric Joyner ixgbe_config_gpie(adapter); 30248eb6488eSEric Joyner 30258eb6488eSEric Joyner /* Set MTU size */ 30268eb6488eSEric Joyner if (ifp->if_mtu > ETHERMTU) { 30278eb6488eSEric Joyner /* aka IXGBE_MAXFRS on 82599 and newer */ 30288eb6488eSEric Joyner mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); 30298eb6488eSEric Joyner mhadd &= ~IXGBE_MHADD_MFS_MASK; 30308eb6488eSEric Joyner mhadd |= adapter->max_frame_size << IXGBE_MHADD_MFS_SHIFT; 30318eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); 30328eb6488eSEric Joyner } 30338eb6488eSEric Joyner 30348eb6488eSEric Joyner /* Now enable all the queues */ 3035c19c7afeSEric Joyner for (i = 0, tx_que = adapter->tx_queues; i < adapter->num_tx_queues; i++, tx_que++) { 3036c19c7afeSEric Joyner struct tx_ring *txr = &tx_que->txr; 3037c19c7afeSEric Joyner 30388eb6488eSEric Joyner txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(txr->me)); 30398eb6488eSEric Joyner txdctl |= IXGBE_TXDCTL_ENABLE; 30408eb6488eSEric Joyner /* Set WTHRESH to 8, burst writeback */ 30418eb6488eSEric Joyner txdctl |= (8 << 16); 30428eb6488eSEric Joyner /* 30438eb6488eSEric Joyner * When the internal queue falls below PTHRESH (32), 30448eb6488eSEric Joyner * start prefetching as long as there are at least 30458eb6488eSEric Joyner * HTHRESH (1) buffers ready. The values are taken 30468eb6488eSEric Joyner * from the Intel linux driver 3.8.21. 30478eb6488eSEric Joyner * Prefetching enables tx line rate even with 1 queue. 30488eb6488eSEric Joyner */ 30498eb6488eSEric Joyner txdctl |= (32 << 0) | (1 << 8); 30508eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(txr->me), txdctl); 30518eb6488eSEric Joyner } 30528eb6488eSEric Joyner 3053c19c7afeSEric Joyner for (i = 0, rx_que = adapter->rx_queues; i < adapter->num_rx_queues; i++, rx_que++) { 3054c19c7afeSEric Joyner struct rx_ring *rxr = &rx_que->rxr; 3055c19c7afeSEric Joyner 30568eb6488eSEric Joyner rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxr->me)); 30578eb6488eSEric Joyner if (hw->mac.type == ixgbe_mac_82598EB) { 30588eb6488eSEric Joyner /* 30598eb6488eSEric Joyner * PTHRESH = 21 30608eb6488eSEric Joyner * HTHRESH = 4 30618eb6488eSEric Joyner * WTHRESH = 8 30628eb6488eSEric Joyner */ 30638eb6488eSEric Joyner rxdctl &= ~0x3FFFFF; 30648eb6488eSEric Joyner rxdctl |= 0x080420; 30658eb6488eSEric Joyner } 30668eb6488eSEric Joyner rxdctl |= IXGBE_RXDCTL_ENABLE; 30678eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rxr->me), rxdctl); 3068c19c7afeSEric Joyner for (j = 0; j < 10; j++) { 30698eb6488eSEric Joyner if (IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxr->me)) & 30708eb6488eSEric Joyner IXGBE_RXDCTL_ENABLE) 30718eb6488eSEric Joyner break; 30728eb6488eSEric Joyner else 30738eb6488eSEric Joyner msec_delay(1); 30748eb6488eSEric Joyner } 30758eb6488eSEric Joyner wmb(); 30768eb6488eSEric Joyner } 30778eb6488eSEric Joyner 30788eb6488eSEric Joyner /* Enable Receive engine */ 30798eb6488eSEric Joyner rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); 30808eb6488eSEric Joyner if (hw->mac.type == ixgbe_mac_82598EB) 30818eb6488eSEric Joyner rxctrl |= IXGBE_RXCTRL_DMBYPS; 30828eb6488eSEric Joyner rxctrl |= IXGBE_RXCTRL_RXEN; 30838eb6488eSEric Joyner ixgbe_enable_rx_dma(hw, rxctrl); 30848eb6488eSEric Joyner 3085c19c7afeSEric Joyner /* Set up MSI/MSI-X routing */ 3086c19c7afeSEric Joyner if (ixgbe_enable_msix) { 30878eb6488eSEric Joyner ixgbe_configure_ivars(adapter); 30888eb6488eSEric Joyner /* Set up auto-mask */ 30898eb6488eSEric Joyner if (hw->mac.type == ixgbe_mac_82598EB) 30908eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); 30918eb6488eSEric Joyner else { 30928eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); 30938eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); 30948eb6488eSEric Joyner } 30958eb6488eSEric Joyner } else { /* Simple settings for Legacy/MSI */ 30968eb6488eSEric Joyner ixgbe_set_ivar(adapter, 0, 0, 0); 30978eb6488eSEric Joyner ixgbe_set_ivar(adapter, 0, 0, 1); 30988eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); 30998eb6488eSEric Joyner } 31008eb6488eSEric Joyner 31018eb6488eSEric Joyner ixgbe_init_fdir(adapter); 31028eb6488eSEric Joyner 31038eb6488eSEric Joyner /* 31048eb6488eSEric Joyner * Check on any SFP devices that 31058eb6488eSEric Joyner * need to be kick-started 31068eb6488eSEric Joyner */ 31078eb6488eSEric Joyner if (hw->phy.type == ixgbe_phy_none) { 31088eb6488eSEric Joyner err = hw->phy.ops.identify(hw); 31098eb6488eSEric Joyner if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { 31108eb6488eSEric Joyner device_printf(dev, 31118eb6488eSEric Joyner "Unsupported SFP+ module type was detected.\n"); 31128eb6488eSEric Joyner return; 31138eb6488eSEric Joyner } 31148eb6488eSEric Joyner } 31158eb6488eSEric Joyner 31168eb6488eSEric Joyner /* Set moderation on the Link interrupt */ 31178eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EITR(adapter->vector), IXGBE_LINK_ITR); 31188eb6488eSEric Joyner 3119c19c7afeSEric Joyner /* Enable power to the phy. */ 3120c19c7afeSEric Joyner ixgbe_set_phy_power(hw, TRUE); 3121c19c7afeSEric Joyner 31228eb6488eSEric Joyner /* Config/Enable Link */ 3123b2c1e8e6SEric Joyner ixgbe_config_link(ctx); 31248eb6488eSEric Joyner 31258eb6488eSEric Joyner /* Hardware Packet Buffer & Flow Control setup */ 31268eb6488eSEric Joyner ixgbe_config_delay_values(adapter); 31278eb6488eSEric Joyner 31288eb6488eSEric Joyner /* Initialize the FC settings */ 31298eb6488eSEric Joyner ixgbe_start_hw(hw); 31308eb6488eSEric Joyner 31318eb6488eSEric Joyner /* Set up VLAN support and filter */ 3132c19c7afeSEric Joyner ixgbe_setup_vlan_hw_support(ctx); 31338eb6488eSEric Joyner 31348eb6488eSEric Joyner /* Setup DMA Coalescing */ 31358eb6488eSEric Joyner ixgbe_config_dmac(adapter); 31368eb6488eSEric Joyner 31378eb6488eSEric Joyner /* And now turn on interrupts */ 3138c19c7afeSEric Joyner ixgbe_if_enable_intr(ctx); 31398eb6488eSEric Joyner 31408eb6488eSEric Joyner /* Enable the use of the MBX by the VF's */ 31418eb6488eSEric Joyner if (adapter->feat_en & IXGBE_FEATURE_SRIOV) { 31428eb6488eSEric Joyner ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); 31438eb6488eSEric Joyner ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; 31448eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); 31458eb6488eSEric Joyner } 31468eb6488eSEric Joyner 31478eb6488eSEric Joyner } /* ixgbe_init_locked */ 31488eb6488eSEric Joyner 31498eb6488eSEric Joyner /************************************************************************ 31508eb6488eSEric Joyner * ixgbe_set_ivar 31518eb6488eSEric Joyner * 31528eb6488eSEric Joyner * Setup the correct IVAR register for a particular MSI-X interrupt 31538eb6488eSEric Joyner * (yes this is all very magic and confusing :) 31548eb6488eSEric Joyner * - entry is the register array entry 31558eb6488eSEric Joyner * - vector is the MSI-X vector for this queue 31568eb6488eSEric Joyner * - type is RX/TX/MISC 31578eb6488eSEric Joyner ************************************************************************/ 31588eb6488eSEric Joyner static void 31598eb6488eSEric Joyner ixgbe_set_ivar(struct adapter *adapter, u8 entry, u8 vector, s8 type) 31608eb6488eSEric Joyner { 31618eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 31628eb6488eSEric Joyner u32 ivar, index; 31638eb6488eSEric Joyner 31648eb6488eSEric Joyner vector |= IXGBE_IVAR_ALLOC_VAL; 31658eb6488eSEric Joyner 31668eb6488eSEric Joyner switch (hw->mac.type) { 31678eb6488eSEric Joyner case ixgbe_mac_82598EB: 31688eb6488eSEric Joyner if (type == -1) 31698eb6488eSEric Joyner entry = IXGBE_IVAR_OTHER_CAUSES_INDEX; 31708eb6488eSEric Joyner else 31718eb6488eSEric Joyner entry += (type * 64); 31728eb6488eSEric Joyner index = (entry >> 2) & 0x1F; 31738eb6488eSEric Joyner ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); 31748eb6488eSEric Joyner ivar &= ~(0xFF << (8 * (entry & 0x3))); 31758eb6488eSEric Joyner ivar |= (vector << (8 * (entry & 0x3))); 31768eb6488eSEric Joyner IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR(index), ivar); 31778eb6488eSEric Joyner break; 31788eb6488eSEric Joyner case ixgbe_mac_82599EB: 31798eb6488eSEric Joyner case ixgbe_mac_X540: 31808eb6488eSEric Joyner case ixgbe_mac_X550: 31818eb6488eSEric Joyner case ixgbe_mac_X550EM_x: 31828eb6488eSEric Joyner case ixgbe_mac_X550EM_a: 31838eb6488eSEric Joyner if (type == -1) { /* MISC IVAR */ 31848eb6488eSEric Joyner index = (entry & 1) * 8; 31858eb6488eSEric Joyner ivar = IXGBE_READ_REG(hw, IXGBE_IVAR_MISC); 31868eb6488eSEric Joyner ivar &= ~(0xFF << index); 31878eb6488eSEric Joyner ivar |= (vector << index); 31888eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, ivar); 31898eb6488eSEric Joyner } else { /* RX/TX IVARS */ 31908eb6488eSEric Joyner index = (16 * (entry & 1)) + (8 * type); 31918eb6488eSEric Joyner ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(entry >> 1)); 31928eb6488eSEric Joyner ivar &= ~(0xFF << index); 31938eb6488eSEric Joyner ivar |= (vector << index); 31948eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_IVAR(entry >> 1), ivar); 31958eb6488eSEric Joyner } 31968eb6488eSEric Joyner default: 31978eb6488eSEric Joyner break; 31988eb6488eSEric Joyner } 31998eb6488eSEric Joyner } /* ixgbe_set_ivar */ 32008eb6488eSEric Joyner 32018eb6488eSEric Joyner /************************************************************************ 32028eb6488eSEric Joyner * ixgbe_configure_ivars 32038eb6488eSEric Joyner ************************************************************************/ 32048eb6488eSEric Joyner static void 32058eb6488eSEric Joyner ixgbe_configure_ivars(struct adapter *adapter) 32068eb6488eSEric Joyner { 3207c19c7afeSEric Joyner struct ix_rx_queue *rx_que = adapter->rx_queues; 3208c19c7afeSEric Joyner struct ix_tx_queue *tx_que = adapter->tx_queues; 32098eb6488eSEric Joyner u32 newitr; 32108eb6488eSEric Joyner 32118eb6488eSEric Joyner if (ixgbe_max_interrupt_rate > 0) 32128eb6488eSEric Joyner newitr = (4000000 / ixgbe_max_interrupt_rate) & 0x0FF8; 32138eb6488eSEric Joyner else { 32148eb6488eSEric Joyner /* 32158eb6488eSEric Joyner * Disable DMA coalescing if interrupt moderation is 32168eb6488eSEric Joyner * disabled. 32178eb6488eSEric Joyner */ 32188eb6488eSEric Joyner adapter->dmac = 0; 32198eb6488eSEric Joyner newitr = 0; 32208eb6488eSEric Joyner } 32218eb6488eSEric Joyner 3222c19c7afeSEric Joyner for (int i = 0; i < adapter->num_rx_queues; i++, rx_que++) { 3223c19c7afeSEric Joyner struct rx_ring *rxr = &rx_que->rxr; 32248eb6488eSEric Joyner 3225c19c7afeSEric Joyner /* First the RX queue entry */ 3226c19c7afeSEric Joyner ixgbe_set_ivar(adapter, rxr->me, rx_que->msix, 0); 3227c19c7afeSEric Joyner 3228c19c7afeSEric Joyner /* Set an Initial EITR value */ 3229c19c7afeSEric Joyner IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(rx_que->msix), newitr); 3230c19c7afeSEric Joyner } 3231c19c7afeSEric Joyner for (int i = 0; i < adapter->num_tx_queues; i++, tx_que++) { 3232c19c7afeSEric Joyner struct tx_ring *txr = &tx_que->txr; 3233c19c7afeSEric Joyner 3234c19c7afeSEric Joyner /* ... and the TX */ 3235c19c7afeSEric Joyner ixgbe_set_ivar(adapter, txr->me, tx_que->msix, 1); 3236c19c7afeSEric Joyner } 32378eb6488eSEric Joyner /* For the Link interrupt */ 32388eb6488eSEric Joyner ixgbe_set_ivar(adapter, 1, adapter->vector, -1); 32398eb6488eSEric Joyner } /* ixgbe_configure_ivars */ 32408eb6488eSEric Joyner 32418eb6488eSEric Joyner /************************************************************************ 32428eb6488eSEric Joyner * ixgbe_config_gpie 32438eb6488eSEric Joyner ************************************************************************/ 32448eb6488eSEric Joyner static void 32458eb6488eSEric Joyner ixgbe_config_gpie(struct adapter *adapter) 32468eb6488eSEric Joyner { 32478eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 32488eb6488eSEric Joyner u32 gpie; 32498eb6488eSEric Joyner 32508eb6488eSEric Joyner gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); 32518eb6488eSEric Joyner 3252c19c7afeSEric Joyner if (adapter->intr_type == IFLIB_INTR_MSIX) { 32538eb6488eSEric Joyner /* Enable Enhanced MSI-X mode */ 32548eb6488eSEric Joyner gpie |= IXGBE_GPIE_MSIX_MODE 32558eb6488eSEric Joyner | IXGBE_GPIE_EIAME 32568eb6488eSEric Joyner | IXGBE_GPIE_PBA_SUPPORT 32578eb6488eSEric Joyner | IXGBE_GPIE_OCD; 32588eb6488eSEric Joyner } 32598eb6488eSEric Joyner 32608eb6488eSEric Joyner /* Fan Failure Interrupt */ 32618eb6488eSEric Joyner if (adapter->feat_en & IXGBE_FEATURE_FAN_FAIL) 32628eb6488eSEric Joyner gpie |= IXGBE_SDP1_GPIEN; 32638eb6488eSEric Joyner 32648eb6488eSEric Joyner /* Thermal Sensor Interrupt */ 32658eb6488eSEric Joyner if (adapter->feat_en & IXGBE_FEATURE_TEMP_SENSOR) 32668eb6488eSEric Joyner gpie |= IXGBE_SDP0_GPIEN_X540; 32678eb6488eSEric Joyner 32688eb6488eSEric Joyner /* Link detection */ 32698eb6488eSEric Joyner switch (hw->mac.type) { 32708eb6488eSEric Joyner case ixgbe_mac_82599EB: 32718eb6488eSEric Joyner gpie |= IXGBE_SDP1_GPIEN | IXGBE_SDP2_GPIEN; 32728eb6488eSEric Joyner break; 32738eb6488eSEric Joyner case ixgbe_mac_X550EM_x: 32748eb6488eSEric Joyner case ixgbe_mac_X550EM_a: 32758eb6488eSEric Joyner gpie |= IXGBE_SDP0_GPIEN_X540; 32768eb6488eSEric Joyner break; 32778eb6488eSEric Joyner default: 32788eb6488eSEric Joyner break; 32798eb6488eSEric Joyner } 32808eb6488eSEric Joyner 32818eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); 32828eb6488eSEric Joyner 32838eb6488eSEric Joyner } /* ixgbe_config_gpie */ 32848eb6488eSEric Joyner 32858eb6488eSEric Joyner /************************************************************************ 32868eb6488eSEric Joyner * ixgbe_config_delay_values 32878eb6488eSEric Joyner * 32888eb6488eSEric Joyner * Requires adapter->max_frame_size to be set. 32898eb6488eSEric Joyner ************************************************************************/ 32908eb6488eSEric Joyner static void 32918eb6488eSEric Joyner ixgbe_config_delay_values(struct adapter *adapter) 32928eb6488eSEric Joyner { 32938eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 32948eb6488eSEric Joyner u32 rxpb, frame, size, tmp; 32958eb6488eSEric Joyner 32968eb6488eSEric Joyner frame = adapter->max_frame_size; 32978eb6488eSEric Joyner 32988eb6488eSEric Joyner /* Calculate High Water */ 32998eb6488eSEric Joyner switch (hw->mac.type) { 33008eb6488eSEric Joyner case ixgbe_mac_X540: 33018eb6488eSEric Joyner case ixgbe_mac_X550: 33028eb6488eSEric Joyner case ixgbe_mac_X550EM_x: 33038eb6488eSEric Joyner case ixgbe_mac_X550EM_a: 33048eb6488eSEric Joyner tmp = IXGBE_DV_X540(frame, frame); 33058eb6488eSEric Joyner break; 33068eb6488eSEric Joyner default: 33078eb6488eSEric Joyner tmp = IXGBE_DV(frame, frame); 33088eb6488eSEric Joyner break; 33098eb6488eSEric Joyner } 33108eb6488eSEric Joyner size = IXGBE_BT2KB(tmp); 33118eb6488eSEric Joyner rxpb = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0)) >> 10; 33128eb6488eSEric Joyner hw->fc.high_water[0] = rxpb - size; 33138eb6488eSEric Joyner 33148eb6488eSEric Joyner /* Now calculate Low Water */ 33158eb6488eSEric Joyner switch (hw->mac.type) { 33168eb6488eSEric Joyner case ixgbe_mac_X540: 33178eb6488eSEric Joyner case ixgbe_mac_X550: 33188eb6488eSEric Joyner case ixgbe_mac_X550EM_x: 33198eb6488eSEric Joyner case ixgbe_mac_X550EM_a: 33208eb6488eSEric Joyner tmp = IXGBE_LOW_DV_X540(frame); 33218eb6488eSEric Joyner break; 33228eb6488eSEric Joyner default: 33238eb6488eSEric Joyner tmp = IXGBE_LOW_DV(frame); 33248eb6488eSEric Joyner break; 33258eb6488eSEric Joyner } 33268eb6488eSEric Joyner hw->fc.low_water[0] = IXGBE_BT2KB(tmp); 33278eb6488eSEric Joyner 33288eb6488eSEric Joyner hw->fc.pause_time = IXGBE_FC_PAUSE; 33298eb6488eSEric Joyner hw->fc.send_xon = TRUE; 33308eb6488eSEric Joyner } /* ixgbe_config_delay_values */ 33318eb6488eSEric Joyner 33328eb6488eSEric Joyner /************************************************************************ 33338eb6488eSEric Joyner * ixgbe_set_multi - Multicast Update 33348eb6488eSEric Joyner * 33358eb6488eSEric Joyner * Called whenever multicast address list is updated. 33368eb6488eSEric Joyner ************************************************************************/ 3337ba76aa63SGleb Smirnoff static u_int 333821afed4bSKevin Bowling ixgbe_mc_filter_apply(void *arg, struct sockaddr_dl *sdl, u_int idx) 33398eb6488eSEric Joyner { 3340c19c7afeSEric Joyner struct adapter *adapter = arg; 3341c19c7afeSEric Joyner struct ixgbe_mc_addr *mta = adapter->mta; 3342c19c7afeSEric Joyner 334321afed4bSKevin Bowling if (idx == MAX_NUM_MULTICAST_ADDRESSES) 3344c19c7afeSEric Joyner return (0); 334521afed4bSKevin Bowling bcopy(LLADDR(sdl), mta[idx].addr, IXGBE_ETH_LENGTH_OF_ADDRESS); 334621afed4bSKevin Bowling mta[idx].vmdq = adapter->pool; 3347c19c7afeSEric Joyner 3348c19c7afeSEric Joyner return (1); 3349c19c7afeSEric Joyner } /* ixgbe_mc_filter_apply */ 3350c19c7afeSEric Joyner 3351c19c7afeSEric Joyner static void 3352c19c7afeSEric Joyner ixgbe_if_multi_set(if_ctx_t ctx) 3353c19c7afeSEric Joyner { 3354c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 33558eb6488eSEric Joyner struct ixgbe_mc_addr *mta; 3356c19c7afeSEric Joyner struct ifnet *ifp = iflib_get_ifp(ctx); 33578eb6488eSEric Joyner u8 *update_ptr; 33588eb6488eSEric Joyner u32 fctrl; 3359ba76aa63SGleb Smirnoff u_int mcnt; 33608eb6488eSEric Joyner 3361c19c7afeSEric Joyner IOCTL_DEBUGOUT("ixgbe_if_multi_set: begin"); 33628eb6488eSEric Joyner 33638eb6488eSEric Joyner mta = adapter->mta; 33648eb6488eSEric Joyner bzero(mta, sizeof(*mta) * MAX_NUM_MULTICAST_ADDRESSES); 33658eb6488eSEric Joyner 3366ba76aa63SGleb Smirnoff mcnt = if_foreach_llmaddr(iflib_get_ifp(ctx), ixgbe_mc_filter_apply, 3367ba76aa63SGleb Smirnoff adapter); 33688eb6488eSEric Joyner 33698eb6488eSEric Joyner fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL); 3370deecaa14SKevin Bowling 33718eb6488eSEric Joyner if (ifp->if_flags & IFF_PROMISC) 33728eb6488eSEric Joyner fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); 33738eb6488eSEric Joyner else if (mcnt >= MAX_NUM_MULTICAST_ADDRESSES || 33748eb6488eSEric Joyner ifp->if_flags & IFF_ALLMULTI) { 33758eb6488eSEric Joyner fctrl |= IXGBE_FCTRL_MPE; 33768eb6488eSEric Joyner fctrl &= ~IXGBE_FCTRL_UPE; 33778eb6488eSEric Joyner } else 33788eb6488eSEric Joyner fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); 33798eb6488eSEric Joyner 33808eb6488eSEric Joyner IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl); 33818eb6488eSEric Joyner 33828eb6488eSEric Joyner if (mcnt < MAX_NUM_MULTICAST_ADDRESSES) { 33838eb6488eSEric Joyner update_ptr = (u8 *)mta; 33848eb6488eSEric Joyner ixgbe_update_mc_addr_list(&adapter->hw, update_ptr, mcnt, 33858eb6488eSEric Joyner ixgbe_mc_array_itr, TRUE); 33868eb6488eSEric Joyner } 33878eb6488eSEric Joyner 3388c19c7afeSEric Joyner } /* ixgbe_if_multi_set */ 33898eb6488eSEric Joyner 33908eb6488eSEric Joyner /************************************************************************ 33918eb6488eSEric Joyner * ixgbe_mc_array_itr 33928eb6488eSEric Joyner * 33938eb6488eSEric Joyner * An iterator function needed by the multicast shared code. 33948eb6488eSEric Joyner * It feeds the shared code routine the addresses in the 33958eb6488eSEric Joyner * array of ixgbe_set_multi() one by one. 33968eb6488eSEric Joyner ************************************************************************/ 33978eb6488eSEric Joyner static u8 * 33988eb6488eSEric Joyner ixgbe_mc_array_itr(struct ixgbe_hw *hw, u8 **update_ptr, u32 *vmdq) 33998eb6488eSEric Joyner { 34008eb6488eSEric Joyner struct ixgbe_mc_addr *mta; 34018eb6488eSEric Joyner 34028eb6488eSEric Joyner mta = (struct ixgbe_mc_addr *)*update_ptr; 34038eb6488eSEric Joyner *vmdq = mta->vmdq; 34048eb6488eSEric Joyner 34058eb6488eSEric Joyner *update_ptr = (u8*)(mta + 1); 34068eb6488eSEric Joyner 34078eb6488eSEric Joyner return (mta->addr); 34088eb6488eSEric Joyner } /* ixgbe_mc_array_itr */ 34098eb6488eSEric Joyner 34108eb6488eSEric Joyner /************************************************************************ 34118eb6488eSEric Joyner * ixgbe_local_timer - Timer routine 34128eb6488eSEric Joyner * 34138eb6488eSEric Joyner * Checks for link status, updates statistics, 34148eb6488eSEric Joyner * and runs the watchdog check. 34158eb6488eSEric Joyner ************************************************************************/ 34168eb6488eSEric Joyner static void 3417c19c7afeSEric Joyner ixgbe_if_timer(if_ctx_t ctx, uint16_t qid) 34188eb6488eSEric Joyner { 3419c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 34208eb6488eSEric Joyner 3421c19c7afeSEric Joyner if (qid != 0) 3422c19c7afeSEric Joyner return; 34238eb6488eSEric Joyner 34248eb6488eSEric Joyner /* Check for pluggable optics */ 34258eb6488eSEric Joyner if (adapter->sfp_probe) 3426c19c7afeSEric Joyner if (!ixgbe_sfp_probe(ctx)) 3427c19c7afeSEric Joyner return; /* Nothing to do */ 34288eb6488eSEric Joyner 3429c19c7afeSEric Joyner ixgbe_check_link(&adapter->hw, &adapter->link_speed, 3430c19c7afeSEric Joyner &adapter->link_up, 0); 34318eb6488eSEric Joyner 3432c19c7afeSEric Joyner /* Fire off the adminq task */ 3433c19c7afeSEric Joyner iflib_admin_intr_deferred(ctx); 34348eb6488eSEric Joyner 3435c19c7afeSEric Joyner } /* ixgbe_if_timer */ 34368eb6488eSEric Joyner 34378eb6488eSEric Joyner /************************************************************************ 34388eb6488eSEric Joyner * ixgbe_sfp_probe 34398eb6488eSEric Joyner * 34408eb6488eSEric Joyner * Determine if a port had optics inserted. 34418eb6488eSEric Joyner ************************************************************************/ 34428eb6488eSEric Joyner static bool 3443c19c7afeSEric Joyner ixgbe_sfp_probe(if_ctx_t ctx) 34448eb6488eSEric Joyner { 3445c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 34468eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 3447c19c7afeSEric Joyner device_t dev = iflib_get_dev(ctx); 34488eb6488eSEric Joyner bool result = FALSE; 34498eb6488eSEric Joyner 34508eb6488eSEric Joyner if ((hw->phy.type == ixgbe_phy_nl) && 34518eb6488eSEric Joyner (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) { 34528eb6488eSEric Joyner s32 ret = hw->phy.ops.identify_sfp(hw); 34538eb6488eSEric Joyner if (ret) 34548eb6488eSEric Joyner goto out; 34558eb6488eSEric Joyner ret = hw->phy.ops.reset(hw); 34568eb6488eSEric Joyner adapter->sfp_probe = FALSE; 34578eb6488eSEric Joyner if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) { 34588eb6488eSEric Joyner device_printf(dev, "Unsupported SFP+ module detected!"); 34598eb6488eSEric Joyner device_printf(dev, 34608eb6488eSEric Joyner "Reload driver with supported module.\n"); 34618eb6488eSEric Joyner goto out; 34628eb6488eSEric Joyner } else 34638eb6488eSEric Joyner device_printf(dev, "SFP+ module detected!\n"); 34648eb6488eSEric Joyner /* We now have supported optics */ 34658eb6488eSEric Joyner result = TRUE; 34668eb6488eSEric Joyner } 34678eb6488eSEric Joyner out: 34688eb6488eSEric Joyner 34698eb6488eSEric Joyner return (result); 34708eb6488eSEric Joyner } /* ixgbe_sfp_probe */ 34718eb6488eSEric Joyner 34728eb6488eSEric Joyner /************************************************************************ 34738eb6488eSEric Joyner * ixgbe_handle_mod - Tasklet for SFP module interrupts 34748eb6488eSEric Joyner ************************************************************************/ 34758eb6488eSEric Joyner static void 3476c19c7afeSEric Joyner ixgbe_handle_mod(void *context) 34778eb6488eSEric Joyner { 3478c19c7afeSEric Joyner if_ctx_t ctx = context; 3479c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 34808eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 3481c19c7afeSEric Joyner device_t dev = iflib_get_dev(ctx); 34828eb6488eSEric Joyner u32 err, cage_full = 0; 34838eb6488eSEric Joyner 34848eb6488eSEric Joyner if (adapter->hw.need_crosstalk_fix) { 34858eb6488eSEric Joyner switch (hw->mac.type) { 34868eb6488eSEric Joyner case ixgbe_mac_82599EB: 34878eb6488eSEric Joyner cage_full = IXGBE_READ_REG(hw, IXGBE_ESDP) & 34888eb6488eSEric Joyner IXGBE_ESDP_SDP2; 34898eb6488eSEric Joyner break; 34908eb6488eSEric Joyner case ixgbe_mac_X550EM_x: 34918eb6488eSEric Joyner case ixgbe_mac_X550EM_a: 34928eb6488eSEric Joyner cage_full = IXGBE_READ_REG(hw, IXGBE_ESDP) & 34938eb6488eSEric Joyner IXGBE_ESDP_SDP0; 34948eb6488eSEric Joyner break; 34958eb6488eSEric Joyner default: 34968eb6488eSEric Joyner break; 34978eb6488eSEric Joyner } 34988eb6488eSEric Joyner 34998eb6488eSEric Joyner if (!cage_full) 3500c19c7afeSEric Joyner goto handle_mod_out; 35018eb6488eSEric Joyner } 35028eb6488eSEric Joyner 35038eb6488eSEric Joyner err = hw->phy.ops.identify_sfp(hw); 35048eb6488eSEric Joyner if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { 35058eb6488eSEric Joyner device_printf(dev, 35068eb6488eSEric Joyner "Unsupported SFP+ module type was detected.\n"); 3507c19c7afeSEric Joyner goto handle_mod_out; 35088eb6488eSEric Joyner } 35098eb6488eSEric Joyner 3510c19c7afeSEric Joyner if (hw->mac.type == ixgbe_mac_82598EB) 3511c19c7afeSEric Joyner err = hw->phy.ops.reset(hw); 3512c19c7afeSEric Joyner else 35138eb6488eSEric Joyner err = hw->mac.ops.setup_sfp(hw); 3514c19c7afeSEric Joyner 35158eb6488eSEric Joyner if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { 35168eb6488eSEric Joyner device_printf(dev, 35178eb6488eSEric Joyner "Setup failure - unsupported SFP+ module type.\n"); 3518c19c7afeSEric Joyner goto handle_mod_out; 35198eb6488eSEric Joyner } 3520b2c1e8e6SEric Joyner adapter->task_requests |= IXGBE_REQUEST_TASK_MSF; 3521c19c7afeSEric Joyner return; 3522c19c7afeSEric Joyner 3523c19c7afeSEric Joyner handle_mod_out: 3524b2c1e8e6SEric Joyner adapter->task_requests &= ~(IXGBE_REQUEST_TASK_MSF); 35258eb6488eSEric Joyner } /* ixgbe_handle_mod */ 35268eb6488eSEric Joyner 35278eb6488eSEric Joyner 35288eb6488eSEric Joyner /************************************************************************ 35298eb6488eSEric Joyner * ixgbe_handle_msf - Tasklet for MSF (multispeed fiber) interrupts 35308eb6488eSEric Joyner ************************************************************************/ 35318eb6488eSEric Joyner static void 3532c19c7afeSEric Joyner ixgbe_handle_msf(void *context) 35338eb6488eSEric Joyner { 3534c19c7afeSEric Joyner if_ctx_t ctx = context; 3535c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 35368eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 35378eb6488eSEric Joyner u32 autoneg; 35388eb6488eSEric Joyner bool negotiate; 35398eb6488eSEric Joyner 35408eb6488eSEric Joyner /* get_supported_phy_layer will call hw->phy.ops.identify_sfp() */ 35418eb6488eSEric Joyner adapter->phy_layer = ixgbe_get_supported_physical_layer(hw); 35428eb6488eSEric Joyner 35438eb6488eSEric Joyner autoneg = hw->phy.autoneg_advertised; 35448eb6488eSEric Joyner if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) 35458eb6488eSEric Joyner hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiate); 35468eb6488eSEric Joyner if (hw->mac.ops.setup_link) 35478eb6488eSEric Joyner hw->mac.ops.setup_link(hw, autoneg, TRUE); 35488eb6488eSEric Joyner 35498eb6488eSEric Joyner /* Adjust media types shown in ifconfig */ 3550c19c7afeSEric Joyner ifmedia_removeall(adapter->media); 3551c19c7afeSEric Joyner ixgbe_add_media_types(adapter->ctx); 3552c19c7afeSEric Joyner ifmedia_set(adapter->media, IFM_ETHER | IFM_AUTO); 35538eb6488eSEric Joyner } /* ixgbe_handle_msf */ 35548eb6488eSEric Joyner 35558eb6488eSEric Joyner /************************************************************************ 35568eb6488eSEric Joyner * ixgbe_handle_phy - Tasklet for external PHY interrupts 35578eb6488eSEric Joyner ************************************************************************/ 35588eb6488eSEric Joyner static void 3559c19c7afeSEric Joyner ixgbe_handle_phy(void *context) 35608eb6488eSEric Joyner { 3561c19c7afeSEric Joyner if_ctx_t ctx = context; 3562c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 35638eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 35648eb6488eSEric Joyner int error; 35658eb6488eSEric Joyner 35668eb6488eSEric Joyner error = hw->phy.ops.handle_lasi(hw); 35678eb6488eSEric Joyner if (error == IXGBE_ERR_OVERTEMP) 35688eb6488eSEric Joyner device_printf(adapter->dev, "CRITICAL: EXTERNAL PHY OVER TEMP!! PHY will downshift to lower power state!\n"); 35698eb6488eSEric Joyner else if (error) 35708eb6488eSEric Joyner device_printf(adapter->dev, 35718eb6488eSEric Joyner "Error handling LASI interrupt: %d\n", error); 35728eb6488eSEric Joyner } /* ixgbe_handle_phy */ 35738eb6488eSEric Joyner 35748eb6488eSEric Joyner /************************************************************************ 3575c19c7afeSEric Joyner * ixgbe_if_stop - Stop the hardware 35768eb6488eSEric Joyner * 35778eb6488eSEric Joyner * Disables all traffic on the adapter by issuing a 35788eb6488eSEric Joyner * global reset on the MAC and deallocates TX/RX buffers. 35798eb6488eSEric Joyner ************************************************************************/ 35808eb6488eSEric Joyner static void 3581c19c7afeSEric Joyner ixgbe_if_stop(if_ctx_t ctx) 35828eb6488eSEric Joyner { 3583c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 35848eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 35858eb6488eSEric Joyner 3586c19c7afeSEric Joyner INIT_DEBUGOUT("ixgbe_if_stop: begin\n"); 35878eb6488eSEric Joyner 35888eb6488eSEric Joyner ixgbe_reset_hw(hw); 35898eb6488eSEric Joyner hw->adapter_stopped = FALSE; 35908eb6488eSEric Joyner ixgbe_stop_adapter(hw); 35918eb6488eSEric Joyner if (hw->mac.type == ixgbe_mac_82599EB) 35928eb6488eSEric Joyner ixgbe_stop_mac_link_on_d3_82599(hw); 35938eb6488eSEric Joyner /* Turn off the laser - noop with no optics */ 35948eb6488eSEric Joyner ixgbe_disable_tx_laser(hw); 35958eb6488eSEric Joyner 35968eb6488eSEric Joyner /* Update the stack */ 35978eb6488eSEric Joyner adapter->link_up = FALSE; 3598c19c7afeSEric Joyner ixgbe_if_update_admin_status(ctx); 35998eb6488eSEric Joyner 36008eb6488eSEric Joyner /* reprogram the RAR[0] in case user changed it. */ 36018eb6488eSEric Joyner ixgbe_set_rar(&adapter->hw, 0, adapter->hw.mac.addr, 0, IXGBE_RAH_AV); 36028eb6488eSEric Joyner 36038eb6488eSEric Joyner return; 3604c19c7afeSEric Joyner } /* ixgbe_if_stop */ 36058eb6488eSEric Joyner 36068eb6488eSEric Joyner /************************************************************************ 36078eb6488eSEric Joyner * ixgbe_update_link_status - Update OS on link state 36088eb6488eSEric Joyner * 36098eb6488eSEric Joyner * Note: Only updates the OS on the cached link state. 36108eb6488eSEric Joyner * The real check of the hardware only happens with 36118eb6488eSEric Joyner * a link interrupt. 36128eb6488eSEric Joyner ************************************************************************/ 36138eb6488eSEric Joyner static void 3614c19c7afeSEric Joyner ixgbe_if_update_admin_status(if_ctx_t ctx) 36158eb6488eSEric Joyner { 3616c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 3617c19c7afeSEric Joyner device_t dev = iflib_get_dev(ctx); 36188eb6488eSEric Joyner 36198eb6488eSEric Joyner if (adapter->link_up) { 36208eb6488eSEric Joyner if (adapter->link_active == FALSE) { 36218eb6488eSEric Joyner if (bootverbose) 36228eb6488eSEric Joyner device_printf(dev, "Link is up %d Gbps %s \n", 36238eb6488eSEric Joyner ((adapter->link_speed == 128) ? 10 : 1), 36248eb6488eSEric Joyner "Full Duplex"); 36258eb6488eSEric Joyner adapter->link_active = TRUE; 36268eb6488eSEric Joyner /* Update any Flow Control changes */ 36278eb6488eSEric Joyner ixgbe_fc_enable(&adapter->hw); 36288eb6488eSEric Joyner /* Update DMA coalescing config */ 36298eb6488eSEric Joyner ixgbe_config_dmac(adapter); 3630c19c7afeSEric Joyner /* should actually be negotiated value */ 3631c19c7afeSEric Joyner iflib_link_state_change(ctx, LINK_STATE_UP, IF_Gbps(10)); 3632c19c7afeSEric Joyner 36338eb6488eSEric Joyner if (adapter->feat_en & IXGBE_FEATURE_SRIOV) 36348eb6488eSEric Joyner ixgbe_ping_all_vfs(adapter); 36358eb6488eSEric Joyner } 36368eb6488eSEric Joyner } else { /* Link down */ 36378eb6488eSEric Joyner if (adapter->link_active == TRUE) { 36388eb6488eSEric Joyner if (bootverbose) 36398eb6488eSEric Joyner device_printf(dev, "Link is Down\n"); 3640c19c7afeSEric Joyner iflib_link_state_change(ctx, LINK_STATE_DOWN, 0); 36418eb6488eSEric Joyner adapter->link_active = FALSE; 36428eb6488eSEric Joyner if (adapter->feat_en & IXGBE_FEATURE_SRIOV) 36438eb6488eSEric Joyner ixgbe_ping_all_vfs(adapter); 36448eb6488eSEric Joyner } 36458eb6488eSEric Joyner } 36468eb6488eSEric Joyner 3647b2c1e8e6SEric Joyner /* Handle task requests from msix_link() */ 3648b2c1e8e6SEric Joyner if (adapter->task_requests & IXGBE_REQUEST_TASK_MOD) 3649b2c1e8e6SEric Joyner ixgbe_handle_mod(ctx); 3650b2c1e8e6SEric Joyner if (adapter->task_requests & IXGBE_REQUEST_TASK_MSF) 3651b2c1e8e6SEric Joyner ixgbe_handle_msf(ctx); 3652b2c1e8e6SEric Joyner if (adapter->task_requests & IXGBE_REQUEST_TASK_MBX) 3653b2c1e8e6SEric Joyner ixgbe_handle_mbx(ctx); 3654b2c1e8e6SEric Joyner if (adapter->task_requests & IXGBE_REQUEST_TASK_FDIR) 3655b2c1e8e6SEric Joyner ixgbe_reinit_fdir(ctx); 3656b2c1e8e6SEric Joyner if (adapter->task_requests & IXGBE_REQUEST_TASK_PHY) 3657b2c1e8e6SEric Joyner ixgbe_handle_phy(ctx); 3658b2c1e8e6SEric Joyner adapter->task_requests = 0; 3659c19c7afeSEric Joyner 3660b2c1e8e6SEric Joyner ixgbe_update_stats_counters(adapter); 3661c19c7afeSEric Joyner } /* ixgbe_if_update_admin_status */ 36628eb6488eSEric Joyner 36638eb6488eSEric Joyner /************************************************************************ 36648eb6488eSEric Joyner * ixgbe_config_dmac - Configure DMA Coalescing 36658eb6488eSEric Joyner ************************************************************************/ 36668eb6488eSEric Joyner static void 36678eb6488eSEric Joyner ixgbe_config_dmac(struct adapter *adapter) 36688eb6488eSEric Joyner { 36698eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 36708eb6488eSEric Joyner struct ixgbe_dmac_config *dcfg = &hw->mac.dmac_config; 36718eb6488eSEric Joyner 36728eb6488eSEric Joyner if (hw->mac.type < ixgbe_mac_X550 || !hw->mac.ops.dmac_config) 36738eb6488eSEric Joyner return; 36748eb6488eSEric Joyner 36758eb6488eSEric Joyner if (dcfg->watchdog_timer ^ adapter->dmac || 36768eb6488eSEric Joyner dcfg->link_speed ^ adapter->link_speed) { 36778eb6488eSEric Joyner dcfg->watchdog_timer = adapter->dmac; 3678c19c7afeSEric Joyner dcfg->fcoe_en = FALSE; 36798eb6488eSEric Joyner dcfg->link_speed = adapter->link_speed; 36808eb6488eSEric Joyner dcfg->num_tcs = 1; 36818eb6488eSEric Joyner 36828eb6488eSEric Joyner INIT_DEBUGOUT2("dmac settings: watchdog %d, link speed %d\n", 36838eb6488eSEric Joyner dcfg->watchdog_timer, dcfg->link_speed); 36848eb6488eSEric Joyner 36858eb6488eSEric Joyner hw->mac.ops.dmac_config(hw); 36868eb6488eSEric Joyner } 36878eb6488eSEric Joyner } /* ixgbe_config_dmac */ 36888eb6488eSEric Joyner 36898eb6488eSEric Joyner /************************************************************************ 3690c19c7afeSEric Joyner * ixgbe_if_enable_intr 36918eb6488eSEric Joyner ************************************************************************/ 3692c19c7afeSEric Joyner void 3693c19c7afeSEric Joyner ixgbe_if_enable_intr(if_ctx_t ctx) 36948eb6488eSEric Joyner { 3695c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 36968eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 3697c19c7afeSEric Joyner struct ix_rx_queue *que = adapter->rx_queues; 36988eb6488eSEric Joyner u32 mask, fwsm; 36998eb6488eSEric Joyner 37008eb6488eSEric Joyner mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); 37018eb6488eSEric Joyner 37028eb6488eSEric Joyner switch (adapter->hw.mac.type) { 37038eb6488eSEric Joyner case ixgbe_mac_82599EB: 37048eb6488eSEric Joyner mask |= IXGBE_EIMS_ECC; 37058eb6488eSEric Joyner /* Temperature sensor on some adapters */ 37068eb6488eSEric Joyner mask |= IXGBE_EIMS_GPI_SDP0; 37078eb6488eSEric Joyner /* SFP+ (RX_LOS_N & MOD_ABS_N) */ 37088eb6488eSEric Joyner mask |= IXGBE_EIMS_GPI_SDP1; 37098eb6488eSEric Joyner mask |= IXGBE_EIMS_GPI_SDP2; 37108eb6488eSEric Joyner break; 37118eb6488eSEric Joyner case ixgbe_mac_X540: 37128eb6488eSEric Joyner /* Detect if Thermal Sensor is enabled */ 37138eb6488eSEric Joyner fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM); 37148eb6488eSEric Joyner if (fwsm & IXGBE_FWSM_TS_ENABLED) 37158eb6488eSEric Joyner mask |= IXGBE_EIMS_TS; 37168eb6488eSEric Joyner mask |= IXGBE_EIMS_ECC; 37178eb6488eSEric Joyner break; 37188eb6488eSEric Joyner case ixgbe_mac_X550: 37198eb6488eSEric Joyner /* MAC thermal sensor is automatically enabled */ 37208eb6488eSEric Joyner mask |= IXGBE_EIMS_TS; 37218eb6488eSEric Joyner mask |= IXGBE_EIMS_ECC; 37228eb6488eSEric Joyner break; 37238eb6488eSEric Joyner case ixgbe_mac_X550EM_x: 37248eb6488eSEric Joyner case ixgbe_mac_X550EM_a: 37258eb6488eSEric Joyner /* Some devices use SDP0 for important information */ 37268eb6488eSEric Joyner if (hw->device_id == IXGBE_DEV_ID_X550EM_X_SFP || 37278eb6488eSEric Joyner hw->device_id == IXGBE_DEV_ID_X550EM_A_SFP || 37288eb6488eSEric Joyner hw->device_id == IXGBE_DEV_ID_X550EM_A_SFP_N || 37298eb6488eSEric Joyner hw->device_id == IXGBE_DEV_ID_X550EM_X_10G_T) 37308eb6488eSEric Joyner mask |= IXGBE_EIMS_GPI_SDP0_BY_MAC(hw); 37318eb6488eSEric Joyner if (hw->phy.type == ixgbe_phy_x550em_ext_t) 37328eb6488eSEric Joyner mask |= IXGBE_EICR_GPI_SDP0_X540; 37338eb6488eSEric Joyner mask |= IXGBE_EIMS_ECC; 37348eb6488eSEric Joyner break; 37358eb6488eSEric Joyner default: 37368eb6488eSEric Joyner break; 37378eb6488eSEric Joyner } 37388eb6488eSEric Joyner 37398eb6488eSEric Joyner /* Enable Fan Failure detection */ 37408eb6488eSEric Joyner if (adapter->feat_en & IXGBE_FEATURE_FAN_FAIL) 37418eb6488eSEric Joyner mask |= IXGBE_EIMS_GPI_SDP1; 37428eb6488eSEric Joyner /* Enable SR-IOV */ 37438eb6488eSEric Joyner if (adapter->feat_en & IXGBE_FEATURE_SRIOV) 37448eb6488eSEric Joyner mask |= IXGBE_EIMS_MAILBOX; 37458eb6488eSEric Joyner /* Enable Flow Director */ 37468eb6488eSEric Joyner if (adapter->feat_en & IXGBE_FEATURE_FDIR) 37478eb6488eSEric Joyner mask |= IXGBE_EIMS_FLOW_DIR; 37488eb6488eSEric Joyner 37498eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); 37508eb6488eSEric Joyner 37518eb6488eSEric Joyner /* With MSI-X we use auto clear */ 3752c19c7afeSEric Joyner if (adapter->intr_type == IFLIB_INTR_MSIX) { 37538eb6488eSEric Joyner mask = IXGBE_EIMS_ENABLE_MASK; 37548eb6488eSEric Joyner /* Don't autoclear Link */ 37558eb6488eSEric Joyner mask &= ~IXGBE_EIMS_OTHER; 37568eb6488eSEric Joyner mask &= ~IXGBE_EIMS_LSC; 37578eb6488eSEric Joyner if (adapter->feat_cap & IXGBE_FEATURE_SRIOV) 37588eb6488eSEric Joyner mask &= ~IXGBE_EIMS_MAILBOX; 37598eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIAC, mask); 37606f37f232SEric Joyner } 37616f37f232SEric Joyner 3762758cc3dcSJack F Vogel /* 37638eb6488eSEric Joyner * Now enable all queues, this is done separately to 37648eb6488eSEric Joyner * allow for handling the extended (beyond 32) MSI-X 37658eb6488eSEric Joyner * vectors that can be used by 82599 3766758cc3dcSJack F Vogel */ 3767c19c7afeSEric Joyner for (int i = 0; i < adapter->num_rx_queues; i++, que++) 37688eb6488eSEric Joyner ixgbe_enable_queue(adapter, que->msix); 37698eb6488eSEric Joyner 37708eb6488eSEric Joyner IXGBE_WRITE_FLUSH(hw); 37718eb6488eSEric Joyner 3772c19c7afeSEric Joyner } /* ixgbe_if_enable_intr */ 37738eb6488eSEric Joyner 37748eb6488eSEric Joyner /************************************************************************ 37758eb6488eSEric Joyner * ixgbe_disable_intr 37768eb6488eSEric Joyner ************************************************************************/ 3777758cc3dcSJack F Vogel static void 3778c19c7afeSEric Joyner ixgbe_if_disable_intr(if_ctx_t ctx) 3779758cc3dcSJack F Vogel { 3780c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 3781c19c7afeSEric Joyner 3782c19c7afeSEric Joyner if (adapter->intr_type == IFLIB_INTR_MSIX) 37838eb6488eSEric Joyner IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, 0); 37848eb6488eSEric Joyner if (adapter->hw.mac.type == ixgbe_mac_82598EB) { 37858eb6488eSEric Joyner IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); 37868eb6488eSEric Joyner } else { 37878eb6488eSEric Joyner IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); 37888eb6488eSEric Joyner IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); 37898eb6488eSEric Joyner IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); 37908eb6488eSEric Joyner } 37918eb6488eSEric Joyner IXGBE_WRITE_FLUSH(&adapter->hw); 3792758cc3dcSJack F Vogel 3793c19c7afeSEric Joyner } /* ixgbe_if_disable_intr */ 37948eb6488eSEric Joyner 37958eb6488eSEric Joyner /************************************************************************ 3796b2c1e8e6SEric Joyner * ixgbe_link_intr_enable 3797b2c1e8e6SEric Joyner ************************************************************************/ 3798b2c1e8e6SEric Joyner static void 3799b2c1e8e6SEric Joyner ixgbe_link_intr_enable(if_ctx_t ctx) 3800b2c1e8e6SEric Joyner { 3801b2c1e8e6SEric Joyner struct ixgbe_hw *hw = &((struct adapter *)iflib_get_softc(ctx))->hw; 3802b2c1e8e6SEric Joyner 3803b2c1e8e6SEric Joyner /* Re-enable other interrupts */ 3804b2c1e8e6SEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC); 3805b2c1e8e6SEric Joyner } /* ixgbe_link_intr_enable */ 3806b2c1e8e6SEric Joyner 3807b2c1e8e6SEric Joyner /************************************************************************ 3808c19c7afeSEric Joyner * ixgbe_if_rx_queue_intr_enable 3809c19c7afeSEric Joyner ************************************************************************/ 3810c19c7afeSEric Joyner static int 3811c19c7afeSEric Joyner ixgbe_if_rx_queue_intr_enable(if_ctx_t ctx, uint16_t rxqid) 3812c19c7afeSEric Joyner { 3813c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 3814c19c7afeSEric Joyner struct ix_rx_queue *que = &adapter->rx_queues[rxqid]; 3815c19c7afeSEric Joyner 38162dc2d580SEric Joyner ixgbe_enable_queue(adapter, que->msix); 3817c19c7afeSEric Joyner 3818c19c7afeSEric Joyner return (0); 3819c19c7afeSEric Joyner } /* ixgbe_if_rx_queue_intr_enable */ 3820c19c7afeSEric Joyner 3821c19c7afeSEric Joyner /************************************************************************ 3822c19c7afeSEric Joyner * ixgbe_enable_queue 38238eb6488eSEric Joyner ************************************************************************/ 38248eb6488eSEric Joyner static void 3825c19c7afeSEric Joyner ixgbe_enable_queue(struct adapter *adapter, u32 vector) 38268eb6488eSEric Joyner { 38278eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 38282dc2d580SEric Joyner u64 queue = 1ULL << vector; 3829c19c7afeSEric Joyner u32 mask; 3830758cc3dcSJack F Vogel 3831c19c7afeSEric Joyner if (hw->mac.type == ixgbe_mac_82598EB) { 3832c19c7afeSEric Joyner mask = (IXGBE_EIMS_RTX_QUEUE & queue); 3833c19c7afeSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); 3834c19c7afeSEric Joyner } else { 3835c19c7afeSEric Joyner mask = (queue & 0xFFFFFFFF); 3836c19c7afeSEric Joyner if (mask) 3837c19c7afeSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); 3838c19c7afeSEric Joyner mask = (queue >> 32); 3839c19c7afeSEric Joyner if (mask) 3840c19c7afeSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); 3841c19c7afeSEric Joyner } 3842c19c7afeSEric Joyner } /* ixgbe_enable_queue */ 3843c19c7afeSEric Joyner 3844c19c7afeSEric Joyner /************************************************************************ 3845c19c7afeSEric Joyner * ixgbe_disable_queue 3846c19c7afeSEric Joyner ************************************************************************/ 3847c19c7afeSEric Joyner static void 3848c19c7afeSEric Joyner ixgbe_disable_queue(struct adapter *adapter, u32 vector) 3849c19c7afeSEric Joyner { 3850c19c7afeSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 38512dc2d580SEric Joyner u64 queue = 1ULL << vector; 3852c19c7afeSEric Joyner u32 mask; 3853c19c7afeSEric Joyner 3854c19c7afeSEric Joyner if (hw->mac.type == ixgbe_mac_82598EB) { 3855c19c7afeSEric Joyner mask = (IXGBE_EIMS_RTX_QUEUE & queue); 3856c19c7afeSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); 3857c19c7afeSEric Joyner } else { 3858c19c7afeSEric Joyner mask = (queue & 0xFFFFFFFF); 3859c19c7afeSEric Joyner if (mask) 3860c19c7afeSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); 3861c19c7afeSEric Joyner mask = (queue >> 32); 3862c19c7afeSEric Joyner if (mask) 3863c19c7afeSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); 3864c19c7afeSEric Joyner } 3865c19c7afeSEric Joyner } /* ixgbe_disable_queue */ 3866c19c7afeSEric Joyner 3867c19c7afeSEric Joyner /************************************************************************ 3868c19c7afeSEric Joyner * ixgbe_intr - Legacy Interrupt Service Routine 3869c19c7afeSEric Joyner ************************************************************************/ 3870c19c7afeSEric Joyner int 3871c19c7afeSEric Joyner ixgbe_intr(void *arg) 3872c19c7afeSEric Joyner { 3873c19c7afeSEric Joyner struct adapter *adapter = arg; 3874c19c7afeSEric Joyner struct ix_rx_queue *que = adapter->rx_queues; 3875c19c7afeSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 3876c19c7afeSEric Joyner if_ctx_t ctx = adapter->ctx; 3877c19c7afeSEric Joyner u32 eicr, eicr_mask; 3878758cc3dcSJack F Vogel 38798eb6488eSEric Joyner eicr = IXGBE_READ_REG(hw, IXGBE_EICR); 3880758cc3dcSJack F Vogel 38818eb6488eSEric Joyner ++que->irqs; 38828eb6488eSEric Joyner if (eicr == 0) { 3883c19c7afeSEric Joyner ixgbe_if_enable_intr(ctx); 3884c19c7afeSEric Joyner return (FILTER_HANDLED); 3885758cc3dcSJack F Vogel } 3886758cc3dcSJack F Vogel 38878eb6488eSEric Joyner /* Check for fan failure */ 3888c19c7afeSEric Joyner if ((hw->device_id == IXGBE_DEV_ID_82598AT) && 3889c19c7afeSEric Joyner (eicr & IXGBE_EICR_GPI_SDP1)) { 3890c19c7afeSEric Joyner device_printf(adapter->dev, 3891c19c7afeSEric Joyner "\nCRITICAL: FAN FAILURE!! REPLACE IMMEDIATELY!!\n"); 38928eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EICR_GPI_SDP1_BY_MAC(hw)); 3893758cc3dcSJack F Vogel } 3894758cc3dcSJack F Vogel 38958eb6488eSEric Joyner /* Link status change */ 3896c19c7afeSEric Joyner if (eicr & IXGBE_EICR_LSC) { 3897c19c7afeSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); 3898c19c7afeSEric Joyner iflib_admin_intr_deferred(ctx); 3899c19c7afeSEric Joyner } 39008eb6488eSEric Joyner 39018eb6488eSEric Joyner if (ixgbe_is_sfp(hw)) { 39028eb6488eSEric Joyner /* Pluggable optics-related interrupt */ 39038eb6488eSEric Joyner if (hw->mac.type >= ixgbe_mac_X540) 39048eb6488eSEric Joyner eicr_mask = IXGBE_EICR_GPI_SDP0_X540; 39058eb6488eSEric Joyner else 39068eb6488eSEric Joyner eicr_mask = IXGBE_EICR_GPI_SDP2_BY_MAC(hw); 39078eb6488eSEric Joyner 39088eb6488eSEric Joyner if (eicr & eicr_mask) { 39098eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask); 3910b2c1e8e6SEric Joyner adapter->task_requests |= IXGBE_REQUEST_TASK_MOD; 39118eb6488eSEric Joyner } 39128eb6488eSEric Joyner 39138eb6488eSEric Joyner if ((hw->mac.type == ixgbe_mac_82599EB) && 39148eb6488eSEric Joyner (eicr & IXGBE_EICR_GPI_SDP1_BY_MAC(hw))) { 39158eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_EICR, 39168eb6488eSEric Joyner IXGBE_EICR_GPI_SDP1_BY_MAC(hw)); 3917b2c1e8e6SEric Joyner adapter->task_requests |= IXGBE_REQUEST_TASK_MSF; 39188eb6488eSEric Joyner } 39198eb6488eSEric Joyner } 39208eb6488eSEric Joyner 39218eb6488eSEric Joyner /* External PHY interrupt */ 39228eb6488eSEric Joyner if ((hw->phy.type == ixgbe_phy_x550em_ext_t) && 39238eb6488eSEric Joyner (eicr & IXGBE_EICR_GPI_SDP0_X540)) 3924b2c1e8e6SEric Joyner adapter->task_requests |= IXGBE_REQUEST_TASK_PHY; 39258eb6488eSEric Joyner 3926c19c7afeSEric Joyner return (FILTER_SCHEDULE_THREAD); 3927c19c7afeSEric Joyner } /* ixgbe_intr */ 39288eb6488eSEric Joyner 39298eb6488eSEric Joyner /************************************************************************ 39308eb6488eSEric Joyner * ixgbe_free_pci_resources 39318eb6488eSEric Joyner ************************************************************************/ 39328eb6488eSEric Joyner static void 3933c19c7afeSEric Joyner ixgbe_free_pci_resources(if_ctx_t ctx) 39348eb6488eSEric Joyner { 3935c19c7afeSEric Joyner struct adapter *adapter = iflib_get_softc(ctx); 3936c19c7afeSEric Joyner struct ix_rx_queue *que = adapter->rx_queues; 3937c19c7afeSEric Joyner device_t dev = iflib_get_dev(ctx); 39388eb6488eSEric Joyner 3939b97de13aSMarius Strobl /* Release all MSI-X queue resources */ 3940c19c7afeSEric Joyner if (adapter->intr_type == IFLIB_INTR_MSIX) 3941c19c7afeSEric Joyner iflib_irq_free(ctx, &adapter->irq); 3942c19c7afeSEric Joyner 3943c19c7afeSEric Joyner if (que != NULL) { 3944c19c7afeSEric Joyner for (int i = 0; i < adapter->num_rx_queues; i++, que++) { 3945c19c7afeSEric Joyner iflib_irq_free(ctx, &que->que_irq); 3946c19c7afeSEric Joyner } 3947c19c7afeSEric Joyner } 39488eb6488eSEric Joyner 39498eb6488eSEric Joyner if (adapter->pci_mem != NULL) 3950c19c7afeSEric Joyner bus_release_resource(dev, SYS_RES_MEMORY, 3951b97de13aSMarius Strobl rman_get_rid(adapter->pci_mem), adapter->pci_mem); 39528eb6488eSEric Joyner } /* ixgbe_free_pci_resources */ 39538eb6488eSEric Joyner 39548eb6488eSEric Joyner /************************************************************************ 39558eb6488eSEric Joyner * ixgbe_sysctl_flowcntl 39568eb6488eSEric Joyner * 39578eb6488eSEric Joyner * SYSCTL wrapper around setting Flow Control 39588eb6488eSEric Joyner ************************************************************************/ 3959758cc3dcSJack F Vogel static int 3960f2c4db54SSteven Hartland ixgbe_sysctl_flowcntl(SYSCTL_HANDLER_ARGS) 3961758cc3dcSJack F Vogel { 3962f2c4db54SSteven Hartland struct adapter *adapter; 39638eb6488eSEric Joyner int error, fc; 3964758cc3dcSJack F Vogel 3965f2c4db54SSteven Hartland adapter = (struct adapter *)arg1; 39668eb6488eSEric Joyner fc = adapter->hw.fc.current_mode; 3967f2c4db54SSteven Hartland 3968f2c4db54SSteven Hartland error = sysctl_handle_int(oidp, &fc, 0, req); 3969758cc3dcSJack F Vogel if ((error) || (req->newptr == NULL)) 3970758cc3dcSJack F Vogel return (error); 3971758cc3dcSJack F Vogel 3972758cc3dcSJack F Vogel /* Don't bother if it's not changed */ 39738eb6488eSEric Joyner if (fc == adapter->hw.fc.current_mode) 3974758cc3dcSJack F Vogel return (0); 3975758cc3dcSJack F Vogel 3976f2c4db54SSteven Hartland return ixgbe_set_flowcntl(adapter, fc); 39778eb6488eSEric Joyner } /* ixgbe_sysctl_flowcntl */ 3978f2c4db54SSteven Hartland 39798eb6488eSEric Joyner /************************************************************************ 39808eb6488eSEric Joyner * ixgbe_set_flowcntl - Set flow control 39818eb6488eSEric Joyner * 39828eb6488eSEric Joyner * Flow control values: 39838eb6488eSEric Joyner * 0 - off 39848eb6488eSEric Joyner * 1 - rx pause 39858eb6488eSEric Joyner * 2 - tx pause 39868eb6488eSEric Joyner * 3 - full 39878eb6488eSEric Joyner ************************************************************************/ 3988f2c4db54SSteven Hartland static int 3989f2c4db54SSteven Hartland ixgbe_set_flowcntl(struct adapter *adapter, int fc) 3990f2c4db54SSteven Hartland { 3991f2c4db54SSteven Hartland switch (fc) { 3992758cc3dcSJack F Vogel case ixgbe_fc_rx_pause: 3993758cc3dcSJack F Vogel case ixgbe_fc_tx_pause: 3994758cc3dcSJack F Vogel case ixgbe_fc_full: 39958eb6488eSEric Joyner adapter->hw.fc.requested_mode = fc; 3996c19c7afeSEric Joyner if (adapter->num_rx_queues > 1) 3997758cc3dcSJack F Vogel ixgbe_disable_rx_drop(adapter); 3998758cc3dcSJack F Vogel break; 3999758cc3dcSJack F Vogel case ixgbe_fc_none: 4000758cc3dcSJack F Vogel adapter->hw.fc.requested_mode = ixgbe_fc_none; 4001c19c7afeSEric Joyner if (adapter->num_rx_queues > 1) 4002758cc3dcSJack F Vogel ixgbe_enable_rx_drop(adapter); 4003758cc3dcSJack F Vogel break; 4004758cc3dcSJack F Vogel default: 4005758cc3dcSJack F Vogel return (EINVAL); 4006758cc3dcSJack F Vogel } 40078eb6488eSEric Joyner 4008758cc3dcSJack F Vogel /* Don't autoneg if forcing a value */ 4009758cc3dcSJack F Vogel adapter->hw.fc.disable_fc_autoneg = TRUE; 4010758cc3dcSJack F Vogel ixgbe_fc_enable(&adapter->hw); 40118eb6488eSEric Joyner 4012f2c4db54SSteven Hartland return (0); 40138eb6488eSEric Joyner } /* ixgbe_set_flowcntl */ 40148eb6488eSEric Joyner 40158eb6488eSEric Joyner /************************************************************************ 40168eb6488eSEric Joyner * ixgbe_enable_rx_drop 40178eb6488eSEric Joyner * 40188eb6488eSEric Joyner * Enable the hardware to drop packets when the buffer is 40198eb6488eSEric Joyner * full. This is useful with multiqueue, so that no single 40208eb6488eSEric Joyner * queue being full stalls the entire RX engine. We only 40218eb6488eSEric Joyner * enable this when Multiqueue is enabled AND Flow Control 40228eb6488eSEric Joyner * is disabled. 40238eb6488eSEric Joyner ************************************************************************/ 40248eb6488eSEric Joyner static void 40258eb6488eSEric Joyner ixgbe_enable_rx_drop(struct adapter *adapter) 40268eb6488eSEric Joyner { 40278eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 40288eb6488eSEric Joyner struct rx_ring *rxr; 40298eb6488eSEric Joyner u32 srrctl; 40308eb6488eSEric Joyner 4031c19c7afeSEric Joyner for (int i = 0; i < adapter->num_rx_queues; i++) { 4032c19c7afeSEric Joyner rxr = &adapter->rx_queues[i].rxr; 40338eb6488eSEric Joyner srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(rxr->me)); 40348eb6488eSEric Joyner srrctl |= IXGBE_SRRCTL_DROP_EN; 40358eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(rxr->me), srrctl); 4036758cc3dcSJack F Vogel } 4037758cc3dcSJack F Vogel 40388eb6488eSEric Joyner /* enable drop for each vf */ 40398eb6488eSEric Joyner for (int i = 0; i < adapter->num_vfs; i++) { 40408eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_QDE, 40418eb6488eSEric Joyner (IXGBE_QDE_WRITE | (i << IXGBE_QDE_IDX_SHIFT) | 40428eb6488eSEric Joyner IXGBE_QDE_ENABLE)); 40438eb6488eSEric Joyner } 40448eb6488eSEric Joyner } /* ixgbe_enable_rx_drop */ 40458eb6488eSEric Joyner 40468eb6488eSEric Joyner /************************************************************************ 40478eb6488eSEric Joyner * ixgbe_disable_rx_drop 40488eb6488eSEric Joyner ************************************************************************/ 40498eb6488eSEric Joyner static void 40508eb6488eSEric Joyner ixgbe_disable_rx_drop(struct adapter *adapter) 40518eb6488eSEric Joyner { 40528eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 40538eb6488eSEric Joyner struct rx_ring *rxr; 40548eb6488eSEric Joyner u32 srrctl; 40558eb6488eSEric Joyner 4056c19c7afeSEric Joyner for (int i = 0; i < adapter->num_rx_queues; i++) { 4057c19c7afeSEric Joyner rxr = &adapter->rx_queues[i].rxr; 40588eb6488eSEric Joyner srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(rxr->me)); 40598eb6488eSEric Joyner srrctl &= ~IXGBE_SRRCTL_DROP_EN; 40608eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(rxr->me), srrctl); 40618eb6488eSEric Joyner } 40628eb6488eSEric Joyner 40638eb6488eSEric Joyner /* disable drop for each vf */ 40648eb6488eSEric Joyner for (int i = 0; i < adapter->num_vfs; i++) { 40658eb6488eSEric Joyner IXGBE_WRITE_REG(hw, IXGBE_QDE, 40668eb6488eSEric Joyner (IXGBE_QDE_WRITE | (i << IXGBE_QDE_IDX_SHIFT))); 40678eb6488eSEric Joyner } 40688eb6488eSEric Joyner } /* ixgbe_disable_rx_drop */ 40698eb6488eSEric Joyner 40708eb6488eSEric Joyner /************************************************************************ 40718eb6488eSEric Joyner * ixgbe_sysctl_advertise 40728eb6488eSEric Joyner * 40738eb6488eSEric Joyner * SYSCTL wrapper around setting advertised speed 40748eb6488eSEric Joyner ************************************************************************/ 4075758cc3dcSJack F Vogel static int 4076f2c4db54SSteven Hartland ixgbe_sysctl_advertise(SYSCTL_HANDLER_ARGS) 4077758cc3dcSJack F Vogel { 4078758cc3dcSJack F Vogel struct adapter *adapter; 40798eb6488eSEric Joyner int error, advertise; 4080758cc3dcSJack F Vogel 4081758cc3dcSJack F Vogel adapter = (struct adapter *)arg1; 4082f2c4db54SSteven Hartland advertise = adapter->advertise; 4083758cc3dcSJack F Vogel 4084f2c4db54SSteven Hartland error = sysctl_handle_int(oidp, &advertise, 0, req); 4085758cc3dcSJack F Vogel if ((error) || (req->newptr == NULL)) 4086758cc3dcSJack F Vogel return (error); 4087758cc3dcSJack F Vogel 4088f2c4db54SSteven Hartland return ixgbe_set_advertise(adapter, advertise); 40898eb6488eSEric Joyner } /* ixgbe_sysctl_advertise */ 4090f2c4db54SSteven Hartland 40918eb6488eSEric Joyner /************************************************************************ 40928eb6488eSEric Joyner * ixgbe_set_advertise - Control advertised link speed 40938eb6488eSEric Joyner * 40948eb6488eSEric Joyner * Flags: 40958eb6488eSEric Joyner * 0x1 - advertise 100 Mb 40968eb6488eSEric Joyner * 0x2 - advertise 1G 40978eb6488eSEric Joyner * 0x4 - advertise 10G 40988eb6488eSEric Joyner * 0x8 - advertise 10 Mb (yes, Mb) 40998eb6488eSEric Joyner ************************************************************************/ 4100f2c4db54SSteven Hartland static int 4101f2c4db54SSteven Hartland ixgbe_set_advertise(struct adapter *adapter, int advertise) 4102f2c4db54SSteven Hartland { 4103c19c7afeSEric Joyner device_t dev = iflib_get_dev(adapter->ctx); 4104f2c4db54SSteven Hartland struct ixgbe_hw *hw; 41058eb6488eSEric Joyner ixgbe_link_speed speed = 0; 41068eb6488eSEric Joyner ixgbe_link_speed link_caps = 0; 41078eb6488eSEric Joyner s32 err = IXGBE_NOT_IMPLEMENTED; 41088eb6488eSEric Joyner bool negotiate = FALSE; 4109f2c4db54SSteven Hartland 4110d775d23aSSteven Hartland /* Checks to validate new value */ 4111d775d23aSSteven Hartland if (adapter->advertise == advertise) /* no change */ 4112d775d23aSSteven Hartland return (0); 4113d775d23aSSteven Hartland 41148eb6488eSEric Joyner hw = &adapter->hw; 4115f2c4db54SSteven Hartland 4116a9ca1c79SSean Bruno /* No speed changes for backplane media */ 4117a9ca1c79SSean Bruno if (hw->phy.media_type == ixgbe_media_type_backplane) 4118a9ca1c79SSean Bruno return (ENODEV); 4119a9ca1c79SSean Bruno 4120758cc3dcSJack F Vogel if (!((hw->phy.media_type == ixgbe_media_type_copper) || 4121758cc3dcSJack F Vogel (hw->phy.multispeed_fiber))) { 41228eb6488eSEric Joyner device_printf(dev, "Advertised speed can only be set on copper or multispeed fiber media types.\n"); 4123758cc3dcSJack F Vogel return (EINVAL); 4124758cc3dcSJack F Vogel } 4125758cc3dcSJack F Vogel 41268eb6488eSEric Joyner if (advertise < 0x1 || advertise > 0xF) { 41278eb6488eSEric Joyner device_printf(dev, "Invalid advertised speed; valid modes are 0x1 through 0xF\n"); 4128758cc3dcSJack F Vogel return (EINVAL); 4129758cc3dcSJack F Vogel } 4130758cc3dcSJack F Vogel 41318eb6488eSEric Joyner if (hw->mac.ops.get_link_capabilities) { 41328eb6488eSEric Joyner err = hw->mac.ops.get_link_capabilities(hw, &link_caps, 41338eb6488eSEric Joyner &negotiate); 41348eb6488eSEric Joyner if (err != IXGBE_SUCCESS) { 41358eb6488eSEric Joyner device_printf(dev, "Unable to determine supported advertise speeds\n"); 41368eb6488eSEric Joyner return (ENODEV); 41378eb6488eSEric Joyner } 4138758cc3dcSJack F Vogel } 4139758cc3dcSJack F Vogel 4140758cc3dcSJack F Vogel /* Set new value and report new advertised mode */ 41418eb6488eSEric Joyner if (advertise & 0x1) { 41428eb6488eSEric Joyner if (!(link_caps & IXGBE_LINK_SPEED_100_FULL)) { 41438eb6488eSEric Joyner device_printf(dev, "Interface does not support 100Mb advertised speed\n"); 41448eb6488eSEric Joyner return (EINVAL); 41458eb6488eSEric Joyner } 4146758cc3dcSJack F Vogel speed |= IXGBE_LINK_SPEED_100_FULL; 41478eb6488eSEric Joyner } 41488eb6488eSEric Joyner if (advertise & 0x2) { 41498eb6488eSEric Joyner if (!(link_caps & IXGBE_LINK_SPEED_1GB_FULL)) { 41508eb6488eSEric Joyner device_printf(dev, "Interface does not support 1Gb advertised speed\n"); 41518eb6488eSEric Joyner return (EINVAL); 41528eb6488eSEric Joyner } 4153758cc3dcSJack F Vogel speed |= IXGBE_LINK_SPEED_1GB_FULL; 41548eb6488eSEric Joyner } 41558eb6488eSEric Joyner if (advertise & 0x4) { 41568eb6488eSEric Joyner if (!(link_caps & IXGBE_LINK_SPEED_10GB_FULL)) { 41578eb6488eSEric Joyner device_printf(dev, "Interface does not support 10Gb advertised speed\n"); 41588eb6488eSEric Joyner return (EINVAL); 41598eb6488eSEric Joyner } 4160758cc3dcSJack F Vogel speed |= IXGBE_LINK_SPEED_10GB_FULL; 41618eb6488eSEric Joyner } 41628eb6488eSEric Joyner if (advertise & 0x8) { 41638eb6488eSEric Joyner if (!(link_caps & IXGBE_LINK_SPEED_10_FULL)) { 41648eb6488eSEric Joyner device_printf(dev, "Interface does not support 10Mb advertised speed\n"); 41658eb6488eSEric Joyner return (EINVAL); 41668eb6488eSEric Joyner } 41678eb6488eSEric Joyner speed |= IXGBE_LINK_SPEED_10_FULL; 41688eb6488eSEric Joyner } 4169758cc3dcSJack F Vogel 4170758cc3dcSJack F Vogel hw->mac.autotry_restart = TRUE; 4171758cc3dcSJack F Vogel hw->mac.ops.setup_link(hw, speed, TRUE); 41728eb6488eSEric Joyner adapter->advertise = advertise; 4173758cc3dcSJack F Vogel 4174f2c4db54SSteven Hartland return (0); 41758eb6488eSEric Joyner } /* ixgbe_set_advertise */ 41768eb6488eSEric Joyner 41778eb6488eSEric Joyner /************************************************************************ 41788eb6488eSEric Joyner * ixgbe_get_advertise - Get current advertised speed settings 41798eb6488eSEric Joyner * 41808eb6488eSEric Joyner * Formatted for sysctl usage. 41818eb6488eSEric Joyner * Flags: 41828eb6488eSEric Joyner * 0x1 - advertise 100 Mb 41838eb6488eSEric Joyner * 0x2 - advertise 1G 41848eb6488eSEric Joyner * 0x4 - advertise 10G 41858eb6488eSEric Joyner * 0x8 - advertise 10 Mb (yes, Mb) 41868eb6488eSEric Joyner ************************************************************************/ 41878eb6488eSEric Joyner static int 41888eb6488eSEric Joyner ixgbe_get_advertise(struct adapter *adapter) 41898eb6488eSEric Joyner { 41908eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 41918eb6488eSEric Joyner int speed; 41928eb6488eSEric Joyner ixgbe_link_speed link_caps = 0; 41938eb6488eSEric Joyner s32 err; 41948eb6488eSEric Joyner bool negotiate = FALSE; 4195758cc3dcSJack F Vogel 4196758cc3dcSJack F Vogel /* 41978eb6488eSEric Joyner * Advertised speed means nothing unless it's copper or 41988eb6488eSEric Joyner * multi-speed fiber 4199758cc3dcSJack F Vogel */ 42008eb6488eSEric Joyner if (!(hw->phy.media_type == ixgbe_media_type_copper) && 42018eb6488eSEric Joyner !(hw->phy.multispeed_fiber)) 4202758cc3dcSJack F Vogel return (0); 4203758cc3dcSJack F Vogel 42048eb6488eSEric Joyner err = hw->mac.ops.get_link_capabilities(hw, &link_caps, &negotiate); 42058eb6488eSEric Joyner if (err != IXGBE_SUCCESS) 42068eb6488eSEric Joyner return (0); 42078eb6488eSEric Joyner 42088eb6488eSEric Joyner speed = 42098eb6488eSEric Joyner ((link_caps & IXGBE_LINK_SPEED_10GB_FULL) ? 4 : 0) | 42108eb6488eSEric Joyner ((link_caps & IXGBE_LINK_SPEED_1GB_FULL) ? 2 : 0) | 42118eb6488eSEric Joyner ((link_caps & IXGBE_LINK_SPEED_100_FULL) ? 1 : 0) | 42128eb6488eSEric Joyner ((link_caps & IXGBE_LINK_SPEED_10_FULL) ? 8 : 0); 42138eb6488eSEric Joyner 42148eb6488eSEric Joyner return speed; 42158eb6488eSEric Joyner } /* ixgbe_get_advertise */ 42168eb6488eSEric Joyner 42178eb6488eSEric Joyner /************************************************************************ 42188eb6488eSEric Joyner * ixgbe_sysctl_dmac - Manage DMA Coalescing 42198eb6488eSEric Joyner * 42208eb6488eSEric Joyner * Control values: 42218eb6488eSEric Joyner * 0/1 - off / on (use default value of 1000) 42228eb6488eSEric Joyner * 42238eb6488eSEric Joyner * Legal timer values are: 42248eb6488eSEric Joyner * 50,100,250,500,1000,2000,5000,10000 42258eb6488eSEric Joyner * 42268eb6488eSEric Joyner * Turning off interrupt moderation will also turn this off. 42278eb6488eSEric Joyner ************************************************************************/ 42286f37f232SEric Joyner static int 42296f37f232SEric Joyner ixgbe_sysctl_dmac(SYSCTL_HANDLER_ARGS) 42306f37f232SEric Joyner { 42316f37f232SEric Joyner struct adapter *adapter = (struct adapter *)arg1; 4232c19c7afeSEric Joyner struct ifnet *ifp = iflib_get_ifp(adapter->ctx); 42336f37f232SEric Joyner int error; 4234c19c7afeSEric Joyner u16 newval; 42356f37f232SEric Joyner 4236a9ca1c79SSean Bruno newval = adapter->dmac; 4237c19c7afeSEric Joyner error = sysctl_handle_16(oidp, &newval, 0, req); 42386f37f232SEric Joyner if ((error) || (req->newptr == NULL)) 42396f37f232SEric Joyner return (error); 42406f37f232SEric Joyner 4241a9ca1c79SSean Bruno switch (newval) { 42426f37f232SEric Joyner case 0: 42436f37f232SEric Joyner /* Disabled */ 4244a9ca1c79SSean Bruno adapter->dmac = 0; 42456f37f232SEric Joyner break; 4246a9ca1c79SSean Bruno case 1: 4247a9ca1c79SSean Bruno /* Enable and use default */ 42486f37f232SEric Joyner adapter->dmac = 1000; 42496f37f232SEric Joyner break; 42506f37f232SEric Joyner case 50: 42516f37f232SEric Joyner case 100: 42526f37f232SEric Joyner case 250: 42536f37f232SEric Joyner case 500: 42546f37f232SEric Joyner case 1000: 42556f37f232SEric Joyner case 2000: 42566f37f232SEric Joyner case 5000: 42576f37f232SEric Joyner case 10000: 42586f37f232SEric Joyner /* Legal values - allow */ 4259a9ca1c79SSean Bruno adapter->dmac = newval; 42606f37f232SEric Joyner break; 42616f37f232SEric Joyner default: 42626f37f232SEric Joyner /* Do nothing, illegal value */ 42636f37f232SEric Joyner return (EINVAL); 42646f37f232SEric Joyner } 42656f37f232SEric Joyner 42666f37f232SEric Joyner /* Re-initialize hardware if it's already running */ 42676f37f232SEric Joyner if (ifp->if_drv_flags & IFF_DRV_RUNNING) 4268c19c7afeSEric Joyner ifp->if_init(ifp); 42696f37f232SEric Joyner 42706f37f232SEric Joyner return (0); 42718eb6488eSEric Joyner } /* ixgbe_sysctl_dmac */ 42726f37f232SEric Joyner 4273a9ca1c79SSean Bruno #ifdef IXGBE_DEBUG 42748eb6488eSEric Joyner /************************************************************************ 42758eb6488eSEric Joyner * ixgbe_sysctl_power_state 42768eb6488eSEric Joyner * 4277a9ca1c79SSean Bruno * Sysctl to test power states 4278a9ca1c79SSean Bruno * Values: 4279a9ca1c79SSean Bruno * 0 - set device to D0 4280a9ca1c79SSean Bruno * 3 - set device to D3 4281a9ca1c79SSean Bruno * (none) - get current device power state 42828eb6488eSEric Joyner ************************************************************************/ 4283a9ca1c79SSean Bruno static int 4284a9ca1c79SSean Bruno ixgbe_sysctl_power_state(SYSCTL_HANDLER_ARGS) 4285a9ca1c79SSean Bruno { 4286a9ca1c79SSean Bruno struct adapter *adapter = (struct adapter *)arg1; 4287a9ca1c79SSean Bruno device_t dev = adapter->dev; 4288a9ca1c79SSean Bruno int curr_ps, new_ps, error = 0; 4289a9ca1c79SSean Bruno 4290a9ca1c79SSean Bruno curr_ps = new_ps = pci_get_powerstate(dev); 4291a9ca1c79SSean Bruno 4292a9ca1c79SSean Bruno error = sysctl_handle_int(oidp, &new_ps, 0, req); 4293a9ca1c79SSean Bruno if ((error) || (req->newptr == NULL)) 4294a9ca1c79SSean Bruno return (error); 4295a9ca1c79SSean Bruno 4296a9ca1c79SSean Bruno if (new_ps == curr_ps) 4297a9ca1c79SSean Bruno return (0); 4298a9ca1c79SSean Bruno 4299a9ca1c79SSean Bruno if (new_ps == 3 && curr_ps == 0) 4300a9ca1c79SSean Bruno error = DEVICE_SUSPEND(dev); 4301a9ca1c79SSean Bruno else if (new_ps == 0 && curr_ps == 3) 4302a9ca1c79SSean Bruno error = DEVICE_RESUME(dev); 4303a9ca1c79SSean Bruno else 4304a9ca1c79SSean Bruno return (EINVAL); 4305a9ca1c79SSean Bruno 4306a9ca1c79SSean Bruno device_printf(dev, "New state: %d\n", pci_get_powerstate(dev)); 4307a9ca1c79SSean Bruno 4308a9ca1c79SSean Bruno return (error); 43098eb6488eSEric Joyner } /* ixgbe_sysctl_power_state */ 4310a9ca1c79SSean Bruno #endif 43118eb6488eSEric Joyner 43128eb6488eSEric Joyner /************************************************************************ 43138eb6488eSEric Joyner * ixgbe_sysctl_wol_enable 43148eb6488eSEric Joyner * 43158eb6488eSEric Joyner * Sysctl to enable/disable the WoL capability, 43168eb6488eSEric Joyner * if supported by the adapter. 43178eb6488eSEric Joyner * 43186f37f232SEric Joyner * Values: 43196f37f232SEric Joyner * 0 - disabled 43206f37f232SEric Joyner * 1 - enabled 43218eb6488eSEric Joyner ************************************************************************/ 43226f37f232SEric Joyner static int 43236f37f232SEric Joyner ixgbe_sysctl_wol_enable(SYSCTL_HANDLER_ARGS) 43246f37f232SEric Joyner { 43256f37f232SEric Joyner struct adapter *adapter = (struct adapter *)arg1; 43266f37f232SEric Joyner struct ixgbe_hw *hw = &adapter->hw; 43276f37f232SEric Joyner int new_wol_enabled; 43286f37f232SEric Joyner int error = 0; 43296f37f232SEric Joyner 43306f37f232SEric Joyner new_wol_enabled = hw->wol_enabled; 43316f37f232SEric Joyner error = sysctl_handle_int(oidp, &new_wol_enabled, 0, req); 43326f37f232SEric Joyner if ((error) || (req->newptr == NULL)) 43336f37f232SEric Joyner return (error); 4334a9ca1c79SSean Bruno new_wol_enabled = !!(new_wol_enabled); 43356f37f232SEric Joyner if (new_wol_enabled == hw->wol_enabled) 43366f37f232SEric Joyner return (0); 43376f37f232SEric Joyner 43386f37f232SEric Joyner if (new_wol_enabled > 0 && !adapter->wol_support) 43396f37f232SEric Joyner return (ENODEV); 43406f37f232SEric Joyner else 4341a9ca1c79SSean Bruno hw->wol_enabled = new_wol_enabled; 43426f37f232SEric Joyner 43436f37f232SEric Joyner return (0); 43448eb6488eSEric Joyner } /* ixgbe_sysctl_wol_enable */ 43456f37f232SEric Joyner 43468eb6488eSEric Joyner /************************************************************************ 43478eb6488eSEric Joyner * ixgbe_sysctl_wufc - Wake Up Filter Control 43488eb6488eSEric Joyner * 43496f37f232SEric Joyner * Sysctl to enable/disable the types of packets that the 43506f37f232SEric Joyner * adapter will wake up on upon receipt. 43516f37f232SEric Joyner * Flags: 43526f37f232SEric Joyner * 0x1 - Link Status Change 43536f37f232SEric Joyner * 0x2 - Magic Packet 43546f37f232SEric Joyner * 0x4 - Direct Exact 43556f37f232SEric Joyner * 0x8 - Directed Multicast 43566f37f232SEric Joyner * 0x10 - Broadcast 43576f37f232SEric Joyner * 0x20 - ARP/IPv4 Request Packet 43586f37f232SEric Joyner * 0x40 - Direct IPv4 Packet 43596f37f232SEric Joyner * 0x80 - Direct IPv6 Packet 43606f37f232SEric Joyner * 43618eb6488eSEric Joyner * Settings not listed above will cause the sysctl to return an error. 43628eb6488eSEric Joyner ************************************************************************/ 43636f37f232SEric Joyner static int 43646f37f232SEric Joyner ixgbe_sysctl_wufc(SYSCTL_HANDLER_ARGS) 43656f37f232SEric Joyner { 43666f37f232SEric Joyner struct adapter *adapter = (struct adapter *)arg1; 43676f37f232SEric Joyner int error = 0; 43686f37f232SEric Joyner u32 new_wufc; 43696f37f232SEric Joyner 43706f37f232SEric Joyner new_wufc = adapter->wufc; 43716f37f232SEric Joyner 4372c19c7afeSEric Joyner error = sysctl_handle_32(oidp, &new_wufc, 0, req); 43736f37f232SEric Joyner if ((error) || (req->newptr == NULL)) 43746f37f232SEric Joyner return (error); 43756f37f232SEric Joyner if (new_wufc == adapter->wufc) 43766f37f232SEric Joyner return (0); 43776f37f232SEric Joyner 43786f37f232SEric Joyner if (new_wufc & 0xffffff00) 43796f37f232SEric Joyner return (EINVAL); 43808eb6488eSEric Joyner 43816f37f232SEric Joyner new_wufc &= 0xff; 43826f37f232SEric Joyner new_wufc |= (0xffffff & adapter->wufc); 43836f37f232SEric Joyner adapter->wufc = new_wufc; 43846f37f232SEric Joyner 43856f37f232SEric Joyner return (0); 43868eb6488eSEric Joyner } /* ixgbe_sysctl_wufc */ 43876f37f232SEric Joyner 4388a9ca1c79SSean Bruno #ifdef IXGBE_DEBUG 43898eb6488eSEric Joyner /************************************************************************ 43908eb6488eSEric Joyner * ixgbe_sysctl_print_rss_config 43918eb6488eSEric Joyner ************************************************************************/ 4392a9ca1c79SSean Bruno static int 4393a9ca1c79SSean Bruno ixgbe_sysctl_print_rss_config(SYSCTL_HANDLER_ARGS) 4394a9ca1c79SSean Bruno { 4395a9ca1c79SSean Bruno struct adapter *adapter = (struct adapter *)arg1; 4396a9ca1c79SSean Bruno struct ixgbe_hw *hw = &adapter->hw; 4397a9ca1c79SSean Bruno device_t dev = adapter->dev; 4398a9ca1c79SSean Bruno struct sbuf *buf; 43998eb6488eSEric Joyner int error = 0, reta_size; 4400a9ca1c79SSean Bruno u32 reg; 4401a9ca1c79SSean Bruno 4402a9ca1c79SSean Bruno buf = sbuf_new_for_sysctl(NULL, NULL, 128, req); 4403a9ca1c79SSean Bruno if (!buf) { 4404a9ca1c79SSean Bruno device_printf(dev, "Could not allocate sbuf for output.\n"); 4405a9ca1c79SSean Bruno return (ENOMEM); 4406a9ca1c79SSean Bruno } 4407a9ca1c79SSean Bruno 4408a9ca1c79SSean Bruno // TODO: use sbufs to make a string to print out 4409a9ca1c79SSean Bruno /* Set multiplier for RETA setup and table size based on MAC */ 4410a9ca1c79SSean Bruno switch (adapter->hw.mac.type) { 4411a9ca1c79SSean Bruno case ixgbe_mac_X550: 4412a9ca1c79SSean Bruno case ixgbe_mac_X550EM_x: 44138eb6488eSEric Joyner case ixgbe_mac_X550EM_a: 4414a9ca1c79SSean Bruno reta_size = 128; 4415a9ca1c79SSean Bruno break; 4416a9ca1c79SSean Bruno default: 4417a9ca1c79SSean Bruno reta_size = 32; 4418a9ca1c79SSean Bruno break; 4419a9ca1c79SSean Bruno } 4420a9ca1c79SSean Bruno 4421a9ca1c79SSean Bruno /* Print out the redirection table */ 4422a9ca1c79SSean Bruno sbuf_cat(buf, "\n"); 4423a9ca1c79SSean Bruno for (int i = 0; i < reta_size; i++) { 4424a9ca1c79SSean Bruno if (i < 32) { 4425a9ca1c79SSean Bruno reg = IXGBE_READ_REG(hw, IXGBE_RETA(i)); 4426a9ca1c79SSean Bruno sbuf_printf(buf, "RETA(%2d): 0x%08x\n", i, reg); 4427a9ca1c79SSean Bruno } else { 4428a9ca1c79SSean Bruno reg = IXGBE_READ_REG(hw, IXGBE_ERETA(i - 32)); 4429a9ca1c79SSean Bruno sbuf_printf(buf, "ERETA(%2d): 0x%08x\n", i - 32, reg); 4430a9ca1c79SSean Bruno } 4431a9ca1c79SSean Bruno } 4432a9ca1c79SSean Bruno 4433a9ca1c79SSean Bruno // TODO: print more config 4434a9ca1c79SSean Bruno 4435a9ca1c79SSean Bruno error = sbuf_finish(buf); 4436a9ca1c79SSean Bruno if (error) 4437a9ca1c79SSean Bruno device_printf(dev, "Error finishing sbuf: %d\n", error); 4438a9ca1c79SSean Bruno 4439a9ca1c79SSean Bruno sbuf_delete(buf); 44408eb6488eSEric Joyner 4441a9ca1c79SSean Bruno return (0); 44428eb6488eSEric Joyner } /* ixgbe_sysctl_print_rss_config */ 4443a9ca1c79SSean Bruno #endif /* IXGBE_DEBUG */ 4444a9ca1c79SSean Bruno 44458eb6488eSEric Joyner /************************************************************************ 44468eb6488eSEric Joyner * ixgbe_sysctl_phy_temp - Retrieve temperature of PHY 44478eb6488eSEric Joyner * 44488eb6488eSEric Joyner * For X552/X557-AT devices using an external PHY 44498eb6488eSEric Joyner ************************************************************************/ 44508eb6488eSEric Joyner static int 44518eb6488eSEric Joyner ixgbe_sysctl_phy_temp(SYSCTL_HANDLER_ARGS) 44528eb6488eSEric Joyner { 44538eb6488eSEric Joyner struct adapter *adapter = (struct adapter *)arg1; 44548eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 44558eb6488eSEric Joyner u16 reg; 44568eb6488eSEric Joyner 44578eb6488eSEric Joyner if (hw->device_id != IXGBE_DEV_ID_X550EM_X_10G_T) { 4458c19c7afeSEric Joyner device_printf(iflib_get_dev(adapter->ctx), 44598eb6488eSEric Joyner "Device has no supported external thermal sensor.\n"); 44608eb6488eSEric Joyner return (ENODEV); 44618eb6488eSEric Joyner } 44628eb6488eSEric Joyner 44638eb6488eSEric Joyner if (hw->phy.ops.read_reg(hw, IXGBE_PHY_CURRENT_TEMP, 44648eb6488eSEric Joyner IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, ®)) { 4465c19c7afeSEric Joyner device_printf(iflib_get_dev(adapter->ctx), 44668eb6488eSEric Joyner "Error reading from PHY's current temperature register\n"); 44678eb6488eSEric Joyner return (EAGAIN); 44688eb6488eSEric Joyner } 44698eb6488eSEric Joyner 44708eb6488eSEric Joyner /* Shift temp for output */ 44718eb6488eSEric Joyner reg = reg >> 8; 44728eb6488eSEric Joyner 4473c19c7afeSEric Joyner return (sysctl_handle_16(oidp, NULL, reg, req)); 44748eb6488eSEric Joyner } /* ixgbe_sysctl_phy_temp */ 44758eb6488eSEric Joyner 44768eb6488eSEric Joyner /************************************************************************ 44778eb6488eSEric Joyner * ixgbe_sysctl_phy_overtemp_occurred 44788eb6488eSEric Joyner * 44798eb6488eSEric Joyner * Reports (directly from the PHY) whether the current PHY 44808eb6488eSEric Joyner * temperature is over the overtemp threshold. 44818eb6488eSEric Joyner ************************************************************************/ 44828eb6488eSEric Joyner static int 44838eb6488eSEric Joyner ixgbe_sysctl_phy_overtemp_occurred(SYSCTL_HANDLER_ARGS) 44848eb6488eSEric Joyner { 44858eb6488eSEric Joyner struct adapter *adapter = (struct adapter *)arg1; 44868eb6488eSEric Joyner struct ixgbe_hw *hw = &adapter->hw; 44878eb6488eSEric Joyner u16 reg; 44888eb6488eSEric Joyner 44898eb6488eSEric Joyner if (hw->device_id != IXGBE_DEV_ID_X550EM_X_10G_T) { 4490c19c7afeSEric Joyner device_printf(iflib_get_dev(adapter->ctx), 44918eb6488eSEric Joyner "Device has no supported external thermal sensor.\n"); 44928eb6488eSEric Joyner return (ENODEV); 44938eb6488eSEric Joyner } 44948eb6488eSEric Joyner 44958eb6488eSEric Joyner if (hw->phy.ops.read_reg(hw, IXGBE_PHY_OVERTEMP_STATUS, 44968eb6488eSEric Joyner IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, ®)) { 4497c19c7afeSEric Joyner device_printf(iflib_get_dev(adapter->ctx), 44988eb6488eSEric Joyner "Error reading from PHY's temperature status register\n"); 44998eb6488eSEric Joyner return (EAGAIN); 45008eb6488eSEric Joyner } 45018eb6488eSEric Joyner 45028eb6488eSEric Joyner /* Get occurrence bit */ 45038eb6488eSEric Joyner reg = !!(reg & 0x4000); 45048eb6488eSEric Joyner 4505c19c7afeSEric Joyner return (sysctl_handle_16(oidp, 0, reg, req)); 45068eb6488eSEric Joyner } /* ixgbe_sysctl_phy_overtemp_occurred */ 45078eb6488eSEric Joyner 45088eb6488eSEric Joyner /************************************************************************ 45098eb6488eSEric Joyner * ixgbe_sysctl_eee_state 45108eb6488eSEric Joyner * 45118eb6488eSEric Joyner * Sysctl to set EEE power saving feature 45128eb6488eSEric Joyner * Values: 45138eb6488eSEric Joyner * 0 - disable EEE 45148eb6488eSEric Joyner * 1 - enable EEE 45158eb6488eSEric Joyner * (none) - get current device EEE state 45168eb6488eSEric Joyner ************************************************************************/ 45178eb6488eSEric Joyner static int 45188eb6488eSEric Joyner ixgbe_sysctl_eee_state(SYSCTL_HANDLER_ARGS) 45198eb6488eSEric Joyner { 45208eb6488eSEric Joyner struct adapter *adapter = (struct adapter *)arg1; 45218eb6488eSEric Joyner device_t dev = adapter->dev; 4522c19c7afeSEric Joyner struct ifnet *ifp = iflib_get_ifp(adapter->ctx); 45238eb6488eSEric Joyner int curr_eee, new_eee, error = 0; 45248eb6488eSEric Joyner s32 retval; 45258eb6488eSEric Joyner 45268eb6488eSEric Joyner curr_eee = new_eee = !!(adapter->feat_en & IXGBE_FEATURE_EEE); 45278eb6488eSEric Joyner 45288eb6488eSEric Joyner error = sysctl_handle_int(oidp, &new_eee, 0, req); 45298eb6488eSEric Joyner if ((error) || (req->newptr == NULL)) 45308eb6488eSEric Joyner return (error); 45318eb6488eSEric Joyner 45328eb6488eSEric Joyner /* Nothing to do */ 45338eb6488eSEric Joyner if (new_eee == curr_eee) 45348eb6488eSEric Joyner return (0); 45358eb6488eSEric Joyner 45368eb6488eSEric Joyner /* Not supported */ 45378eb6488eSEric Joyner if (!(adapter->feat_cap & IXGBE_FEATURE_EEE)) 45388eb6488eSEric Joyner return (EINVAL); 45398eb6488eSEric Joyner 45408eb6488eSEric Joyner /* Bounds checking */ 45418eb6488eSEric Joyner if ((new_eee < 0) || (new_eee > 1)) 45428eb6488eSEric Joyner return (EINVAL); 45438eb6488eSEric Joyner 4544d61b6a41SEric Joyner retval = ixgbe_setup_eee(&adapter->hw, new_eee); 45458eb6488eSEric Joyner if (retval) { 45468eb6488eSEric Joyner device_printf(dev, "Error in EEE setup: 0x%08X\n", retval); 45478eb6488eSEric Joyner return (EINVAL); 45488eb6488eSEric Joyner } 45498eb6488eSEric Joyner 45508eb6488eSEric Joyner /* Restart auto-neg */ 4551c19c7afeSEric Joyner ifp->if_init(ifp); 45528eb6488eSEric Joyner 45538eb6488eSEric Joyner device_printf(dev, "New EEE state: %d\n", new_eee); 45548eb6488eSEric Joyner 45558eb6488eSEric Joyner /* Cache new value */ 45568eb6488eSEric Joyner if (new_eee) 45578eb6488eSEric Joyner adapter->feat_en |= IXGBE_FEATURE_EEE; 45588eb6488eSEric Joyner else 45598eb6488eSEric Joyner adapter->feat_en &= ~IXGBE_FEATURE_EEE; 45608eb6488eSEric Joyner 45618eb6488eSEric Joyner return (error); 45628eb6488eSEric Joyner } /* ixgbe_sysctl_eee_state */ 45638eb6488eSEric Joyner 45648eb6488eSEric Joyner /************************************************************************ 45658eb6488eSEric Joyner * ixgbe_init_device_features 45668eb6488eSEric Joyner ************************************************************************/ 45678eb6488eSEric Joyner static void 45688eb6488eSEric Joyner ixgbe_init_device_features(struct adapter *adapter) 45698eb6488eSEric Joyner { 45708eb6488eSEric Joyner adapter->feat_cap = IXGBE_FEATURE_NETMAP 45718eb6488eSEric Joyner | IXGBE_FEATURE_RSS 45728eb6488eSEric Joyner | IXGBE_FEATURE_MSI 45738eb6488eSEric Joyner | IXGBE_FEATURE_MSIX 4574c19c7afeSEric Joyner | IXGBE_FEATURE_LEGACY_IRQ; 45758eb6488eSEric Joyner 45768eb6488eSEric Joyner /* Set capabilities first... */ 45778eb6488eSEric Joyner switch (adapter->hw.mac.type) { 45788eb6488eSEric Joyner case ixgbe_mac_82598EB: 45798eb6488eSEric Joyner if (adapter->hw.device_id == IXGBE_DEV_ID_82598AT) 45808eb6488eSEric Joyner adapter->feat_cap |= IXGBE_FEATURE_FAN_FAIL; 45818eb6488eSEric Joyner break; 45828eb6488eSEric Joyner case ixgbe_mac_X540: 45838eb6488eSEric Joyner adapter->feat_cap |= IXGBE_FEATURE_SRIOV; 45848eb6488eSEric Joyner adapter->feat_cap |= IXGBE_FEATURE_FDIR; 45858eb6488eSEric Joyner if ((adapter->hw.device_id == IXGBE_DEV_ID_X540_BYPASS) && 45868eb6488eSEric Joyner (adapter->hw.bus.func == 0)) 45878eb6488eSEric Joyner adapter->feat_cap |= IXGBE_FEATURE_BYPASS; 45888eb6488eSEric Joyner break; 45898eb6488eSEric Joyner case ixgbe_mac_X550: 45908eb6488eSEric Joyner adapter->feat_cap |= IXGBE_FEATURE_TEMP_SENSOR; 45918eb6488eSEric Joyner adapter->feat_cap |= IXGBE_FEATURE_SRIOV; 45928eb6488eSEric Joyner adapter->feat_cap |= IXGBE_FEATURE_FDIR; 45938eb6488eSEric Joyner break; 45948eb6488eSEric Joyner case ixgbe_mac_X550EM_x: 45958eb6488eSEric Joyner adapter->feat_cap |= IXGBE_FEATURE_SRIOV; 45968eb6488eSEric Joyner adapter->feat_cap |= IXGBE_FEATURE_FDIR; 45978eb6488eSEric Joyner break; 45988eb6488eSEric Joyner case ixgbe_mac_X550EM_a: 45998eb6488eSEric Joyner adapter->feat_cap |= IXGBE_FEATURE_SRIOV; 46008eb6488eSEric Joyner adapter->feat_cap |= IXGBE_FEATURE_FDIR; 46018eb6488eSEric Joyner adapter->feat_cap &= ~IXGBE_FEATURE_LEGACY_IRQ; 46028eb6488eSEric Joyner if ((adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_1G_T) || 46038eb6488eSEric Joyner (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_1G_T_L)) { 46048eb6488eSEric Joyner adapter->feat_cap |= IXGBE_FEATURE_TEMP_SENSOR; 46058eb6488eSEric Joyner adapter->feat_cap |= IXGBE_FEATURE_EEE; 46068eb6488eSEric Joyner } 46078eb6488eSEric Joyner break; 46088eb6488eSEric Joyner case ixgbe_mac_82599EB: 46098eb6488eSEric Joyner adapter->feat_cap |= IXGBE_FEATURE_SRIOV; 46108eb6488eSEric Joyner adapter->feat_cap |= IXGBE_FEATURE_FDIR; 46118eb6488eSEric Joyner if ((adapter->hw.device_id == IXGBE_DEV_ID_82599_BYPASS) && 46128eb6488eSEric Joyner (adapter->hw.bus.func == 0)) 46138eb6488eSEric Joyner adapter->feat_cap |= IXGBE_FEATURE_BYPASS; 46148eb6488eSEric Joyner if (adapter->hw.device_id == IXGBE_DEV_ID_82599_QSFP_SF_QP) 46158eb6488eSEric Joyner adapter->feat_cap &= ~IXGBE_FEATURE_LEGACY_IRQ; 46168eb6488eSEric Joyner break; 46178eb6488eSEric Joyner default: 46188eb6488eSEric Joyner break; 46198eb6488eSEric Joyner } 46208eb6488eSEric Joyner 46218eb6488eSEric Joyner /* Enabled by default... */ 46228eb6488eSEric Joyner /* Fan failure detection */ 46238eb6488eSEric Joyner if (adapter->feat_cap & IXGBE_FEATURE_FAN_FAIL) 46248eb6488eSEric Joyner adapter->feat_en |= IXGBE_FEATURE_FAN_FAIL; 46258eb6488eSEric Joyner /* Netmap */ 46268eb6488eSEric Joyner if (adapter->feat_cap & IXGBE_FEATURE_NETMAP) 46278eb6488eSEric Joyner adapter->feat_en |= IXGBE_FEATURE_NETMAP; 46288eb6488eSEric Joyner /* EEE */ 46298eb6488eSEric Joyner if (adapter->feat_cap & IXGBE_FEATURE_EEE) 46308eb6488eSEric Joyner adapter->feat_en |= IXGBE_FEATURE_EEE; 46318eb6488eSEric Joyner /* Thermal Sensor */ 46328eb6488eSEric Joyner if (adapter->feat_cap & IXGBE_FEATURE_TEMP_SENSOR) 46338eb6488eSEric Joyner adapter->feat_en |= IXGBE_FEATURE_TEMP_SENSOR; 46348eb6488eSEric Joyner 46358eb6488eSEric Joyner /* Enabled via global sysctl... */ 46368eb6488eSEric Joyner /* Flow Director */ 46378eb6488eSEric Joyner if (ixgbe_enable_fdir) { 46388eb6488eSEric Joyner if (adapter->feat_cap & IXGBE_FEATURE_FDIR) 46398eb6488eSEric Joyner adapter->feat_en |= IXGBE_FEATURE_FDIR; 46408eb6488eSEric Joyner else 46418eb6488eSEric Joyner device_printf(adapter->dev, "Device does not support Flow Director. Leaving disabled."); 46428eb6488eSEric Joyner } 46436f37f232SEric Joyner /* 46448eb6488eSEric Joyner * Message Signal Interrupts - Extended (MSI-X) 46458eb6488eSEric Joyner * Normal MSI is only enabled if MSI-X calls fail. 4646758cc3dcSJack F Vogel */ 46478eb6488eSEric Joyner if (!ixgbe_enable_msix) 46488eb6488eSEric Joyner adapter->feat_cap &= ~IXGBE_FEATURE_MSIX; 46498eb6488eSEric Joyner /* Receive-Side Scaling (RSS) */ 46508eb6488eSEric Joyner if ((adapter->feat_cap & IXGBE_FEATURE_RSS) && ixgbe_enable_rss) 46518eb6488eSEric Joyner adapter->feat_en |= IXGBE_FEATURE_RSS; 46528eb6488eSEric Joyner 46538eb6488eSEric Joyner /* Disable features with unmet dependencies... */ 46548eb6488eSEric Joyner /* No MSI-X */ 46558eb6488eSEric Joyner if (!(adapter->feat_cap & IXGBE_FEATURE_MSIX)) { 46568eb6488eSEric Joyner adapter->feat_cap &= ~IXGBE_FEATURE_RSS; 46578eb6488eSEric Joyner adapter->feat_cap &= ~IXGBE_FEATURE_SRIOV; 46588eb6488eSEric Joyner adapter->feat_en &= ~IXGBE_FEATURE_RSS; 46598eb6488eSEric Joyner adapter->feat_en &= ~IXGBE_FEATURE_SRIOV; 46608eb6488eSEric Joyner } 46618eb6488eSEric Joyner } /* ixgbe_init_device_features */ 46628eb6488eSEric Joyner 46638eb6488eSEric Joyner /************************************************************************ 46648eb6488eSEric Joyner * ixgbe_check_fan_failure 46658eb6488eSEric Joyner ************************************************************************/ 46668eb6488eSEric Joyner static void 46678eb6488eSEric Joyner ixgbe_check_fan_failure(struct adapter *adapter, u32 reg, bool in_interrupt) 46688eb6488eSEric Joyner { 46698eb6488eSEric Joyner u32 mask; 46708eb6488eSEric Joyner 46718eb6488eSEric Joyner mask = (in_interrupt) ? IXGBE_EICR_GPI_SDP1_BY_MAC(&adapter->hw) : 46728eb6488eSEric Joyner IXGBE_ESDP_SDP1; 46738eb6488eSEric Joyner 46748eb6488eSEric Joyner if (reg & mask) 46758eb6488eSEric Joyner device_printf(adapter->dev, "\nCRITICAL: FAN FAILURE!! REPLACE IMMEDIATELY!!\n"); 46768eb6488eSEric Joyner } /* ixgbe_check_fan_failure */ 4677