161ae650dSJack F Vogel /****************************************************************************** 261ae650dSJack F Vogel 3f4cc2d17SEric Joyner Copyright (c) 2013-2018, Intel Corporation 461ae650dSJack F Vogel All rights reserved. 561ae650dSJack F Vogel 661ae650dSJack F Vogel Redistribution and use in source and binary forms, with or without 761ae650dSJack F Vogel modification, are permitted provided that the following conditions are met: 861ae650dSJack F Vogel 961ae650dSJack F Vogel 1. Redistributions of source code must retain the above copyright notice, 1061ae650dSJack F Vogel this list of conditions and the following disclaimer. 1161ae650dSJack F Vogel 1261ae650dSJack F Vogel 2. Redistributions in binary form must reproduce the above copyright 1361ae650dSJack F Vogel notice, this list of conditions and the following disclaimer in the 1461ae650dSJack F Vogel documentation and/or other materials provided with the distribution. 1561ae650dSJack F Vogel 1661ae650dSJack F Vogel 3. Neither the name of the Intel Corporation nor the names of its 1761ae650dSJack F Vogel contributors may be used to endorse or promote products derived from 1861ae650dSJack F Vogel this software without specific prior written permission. 1961ae650dSJack F Vogel 2061ae650dSJack F Vogel THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 2161ae650dSJack F Vogel AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2261ae650dSJack F Vogel IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2361ae650dSJack F Vogel ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 2461ae650dSJack F Vogel LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2561ae650dSJack F Vogel CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2661ae650dSJack F Vogel SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2761ae650dSJack F Vogel INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2861ae650dSJack F Vogel CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2961ae650dSJack F Vogel ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3061ae650dSJack F Vogel POSSIBILITY OF SUCH DAMAGE. 3161ae650dSJack F Vogel 3261ae650dSJack F Vogel ******************************************************************************/ 3361ae650dSJack F Vogel /*$FreeBSD$*/ 3461ae650dSJack F Vogel 3561ae650dSJack F Vogel #include "ixl.h" 3661ae650dSJack F Vogel #include "ixl_pf.h" 3761ae650dSJack F Vogel 38cb6b8299SEric Joyner #ifdef IXL_IW 39cb6b8299SEric Joyner #include "ixl_iw.h" 40cb6b8299SEric Joyner #include "ixl_iw_int.h" 41cb6b8299SEric Joyner #endif 42cb6b8299SEric Joyner 434294f337SSean Bruno #ifdef PCI_IOV 444294f337SSean Bruno #include "ixl_pf_iov.h" 45dcd7b3b2SJack F Vogel #endif 46dcd7b3b2SJack F Vogel 4761ae650dSJack F Vogel /********************************************************************* 4861ae650dSJack F Vogel * Driver version 4961ae650dSJack F Vogel *********************************************************************/ 50f4cc2d17SEric Joyner #define IXL_DRIVER_VERSION_MAJOR 2 51*b4a7ce06SEric Joyner #define IXL_DRIVER_VERSION_MINOR 2 52f4cc2d17SEric Joyner #define IXL_DRIVER_VERSION_BUILD 0 53ceebc2f3SEric Joyner 541031d839SEric Joyner #define IXL_DRIVER_VERSION_STRING \ 551031d839SEric Joyner __XSTRING(IXL_DRIVER_VERSION_MAJOR) "." \ 561031d839SEric Joyner __XSTRING(IXL_DRIVER_VERSION_MINOR) "." \ 57f4cc2d17SEric Joyner __XSTRING(IXL_DRIVER_VERSION_BUILD) "-k" 5861ae650dSJack F Vogel 5961ae650dSJack F Vogel /********************************************************************* 6061ae650dSJack F Vogel * PCI Device ID Table 6161ae650dSJack F Vogel * 6261ae650dSJack F Vogel * Used by probe to select devices to load on 6361ae650dSJack F Vogel * 641031d839SEric Joyner * ( Vendor ID, Device ID, Branding String ) 6561ae650dSJack F Vogel *********************************************************************/ 6661ae650dSJack F Vogel 671031d839SEric Joyner static pci_vendor_info_t ixl_vendor_info_array[] = 6861ae650dSJack F Vogel { 691031d839SEric Joyner PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710, "Intel(R) Ethernet Controller X710 for 10GbE SFP+"), 701031d839SEric Joyner PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B, "Intel(R) Ethernet Controller XL710 for 40GbE backplane"), 711031d839SEric Joyner PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C, "Intel(R) Ethernet Controller X710 for 10GbE backplane"), 721031d839SEric Joyner PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A, "Intel(R) Ethernet Controller XL710 for 40GbE QSFP+"), 731031d839SEric Joyner PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B, "Intel(R) Ethernet Controller XL710 for 40GbE QSFP+"), 741031d839SEric Joyner PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C, "Intel(R) Ethernet Controller X710 for 10GbE QSFP+"), 751031d839SEric Joyner PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T, "Intel(R) Ethernet Controller X710 for 10GBASE-T"), 761031d839SEric Joyner PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T4, "Intel(R) Ethernet Controller X710/X557-AT 10GBASE-T"), 771031d839SEric Joyner PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_X722, "Intel(R) Ethernet Connection X722 for 10GbE backplane"), 781031d839SEric Joyner PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_X722, "Intel(R) Ethernet Connection X722 for 10GbE QSFP+"), 791031d839SEric Joyner PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722, "Intel(R) Ethernet Connection X722 for 10GbE SFP+"), 801031d839SEric Joyner PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_X722, "Intel(R) Ethernet Connection X722 for 1GbE"), 811031d839SEric Joyner PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_X722, "Intel(R) Ethernet Connection X722 for 10GBASE-T"), 821031d839SEric Joyner PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_I_X722, "Intel(R) Ethernet Connection X722 for 10GbE SFP+"), 831031d839SEric Joyner PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_B, "Intel(R) Ethernet Controller XXV710 for 25GbE backplane"), 841031d839SEric Joyner PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_SFP28, "Intel(R) Ethernet Controller XXV710 for 25GbE SFP28"), 8561ae650dSJack F Vogel /* required last entry */ 861031d839SEric Joyner PVID_END 8761ae650dSJack F Vogel }; 8861ae650dSJack F Vogel 8961ae650dSJack F Vogel /********************************************************************* 9061ae650dSJack F Vogel * Function prototypes 9161ae650dSJack F Vogel *********************************************************************/ 921031d839SEric Joyner /*** IFLIB interface ***/ 931031d839SEric Joyner static void *ixl_register(device_t dev); 941031d839SEric Joyner static int ixl_if_attach_pre(if_ctx_t ctx); 951031d839SEric Joyner static int ixl_if_attach_post(if_ctx_t ctx); 961031d839SEric Joyner static int ixl_if_detach(if_ctx_t ctx); 971031d839SEric Joyner static int ixl_if_shutdown(if_ctx_t ctx); 981031d839SEric Joyner static int ixl_if_suspend(if_ctx_t ctx); 991031d839SEric Joyner static int ixl_if_resume(if_ctx_t ctx); 1001031d839SEric Joyner static int ixl_if_msix_intr_assign(if_ctx_t ctx, int msix); 1011031d839SEric Joyner static void ixl_if_enable_intr(if_ctx_t ctx); 1021031d839SEric Joyner static void ixl_if_disable_intr(if_ctx_t ctx); 1031031d839SEric Joyner static int ixl_if_rx_queue_intr_enable(if_ctx_t ctx, uint16_t rxqid); 1041031d839SEric Joyner static int ixl_if_tx_queue_intr_enable(if_ctx_t ctx, uint16_t txqid); 1051031d839SEric Joyner static int ixl_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int ntxqs, int ntxqsets); 1061031d839SEric Joyner static int ixl_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int nqs, int nqsets); 1071031d839SEric Joyner static void ixl_if_queues_free(if_ctx_t ctx); 1081031d839SEric Joyner static void ixl_if_update_admin_status(if_ctx_t ctx); 1091031d839SEric Joyner static void ixl_if_multi_set(if_ctx_t ctx); 1101031d839SEric Joyner static int ixl_if_mtu_set(if_ctx_t ctx, uint32_t mtu); 1111031d839SEric Joyner static void ixl_if_media_status(if_ctx_t ctx, struct ifmediareq *ifmr); 1121031d839SEric Joyner static int ixl_if_media_change(if_ctx_t ctx); 1131031d839SEric Joyner static int ixl_if_promisc_set(if_ctx_t ctx, int flags); 1141031d839SEric Joyner static void ixl_if_timer(if_ctx_t ctx, uint16_t qid); 1151031d839SEric Joyner static void ixl_if_vlan_register(if_ctx_t ctx, u16 vtag); 1161031d839SEric Joyner static void ixl_if_vlan_unregister(if_ctx_t ctx, u16 vtag); 1171031d839SEric Joyner static uint64_t ixl_if_get_counter(if_ctx_t ctx, ift_counter cnt); 1181031d839SEric Joyner static int ixl_if_i2c_req(if_ctx_t ctx, struct ifi2creq *req); 1191031d839SEric Joyner static int ixl_if_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t data); 120cf150917SEric Joyner static bool ixl_if_needs_restart(if_ctx_t ctx, enum iflib_restart_event event); 12177c1fcecSEric Joyner #ifdef PCI_IOV 12277c1fcecSEric Joyner static void ixl_if_vflr_handle(if_ctx_t ctx); 12377c1fcecSEric Joyner #endif 1246c426059SEric Joyner 1251031d839SEric Joyner /*** Other ***/ 126ba76aa63SGleb Smirnoff static u_int ixl_mc_filter_apply(void *, struct sockaddr_dl *, u_int); 1271031d839SEric Joyner static void ixl_save_pf_tunables(struct ixl_pf *); 1281031d839SEric Joyner static int ixl_allocate_pci_resources(struct ixl_pf *); 129*b4a7ce06SEric Joyner static void ixl_setup_ssctx(struct ixl_pf *pf); 130*b4a7ce06SEric Joyner static void ixl_admin_timer(void *arg); 13161ae650dSJack F Vogel 13261ae650dSJack F Vogel /********************************************************************* 13361ae650dSJack F Vogel * FreeBSD Device Interface Entry Points 13461ae650dSJack F Vogel *********************************************************************/ 13561ae650dSJack F Vogel 13661ae650dSJack F Vogel static device_method_t ixl_methods[] = { 13761ae650dSJack F Vogel /* Device interface */ 1381031d839SEric Joyner DEVMETHOD(device_register, ixl_register), 1391031d839SEric Joyner DEVMETHOD(device_probe, iflib_device_probe), 1401031d839SEric Joyner DEVMETHOD(device_attach, iflib_device_attach), 1411031d839SEric Joyner DEVMETHOD(device_detach, iflib_device_detach), 1421031d839SEric Joyner DEVMETHOD(device_shutdown, iflib_device_shutdown), 14356c2c47bSJack F Vogel #ifdef PCI_IOV 14477c1fcecSEric Joyner DEVMETHOD(pci_iov_init, iflib_device_iov_init), 14577c1fcecSEric Joyner DEVMETHOD(pci_iov_uninit, iflib_device_iov_uninit), 14677c1fcecSEric Joyner DEVMETHOD(pci_iov_add_vf, iflib_device_iov_add_vf), 14756c2c47bSJack F Vogel #endif 1481031d839SEric Joyner DEVMETHOD_END 14961ae650dSJack F Vogel }; 15061ae650dSJack F Vogel 15161ae650dSJack F Vogel static driver_t ixl_driver = { 15261ae650dSJack F Vogel "ixl", ixl_methods, sizeof(struct ixl_pf), 15361ae650dSJack F Vogel }; 15461ae650dSJack F Vogel 15561ae650dSJack F Vogel devclass_t ixl_devclass; 15661ae650dSJack F Vogel DRIVER_MODULE(ixl, pci, ixl_driver, ixl_devclass, 0, 0); 1570dc34160SWarner Losh IFLIB_PNP_INFO(pci, ixl, ixl_vendor_info_array); 1581031d839SEric Joyner MODULE_VERSION(ixl, 3); 159cb6b8299SEric Joyner 16061ae650dSJack F Vogel MODULE_DEPEND(ixl, pci, 1, 1, 1); 16161ae650dSJack F Vogel MODULE_DEPEND(ixl, ether, 1, 1, 1); 1621031d839SEric Joyner MODULE_DEPEND(ixl, iflib, 1, 1, 1); 1631031d839SEric Joyner 1641031d839SEric Joyner static device_method_t ixl_if_methods[] = { 1651031d839SEric Joyner DEVMETHOD(ifdi_attach_pre, ixl_if_attach_pre), 1661031d839SEric Joyner DEVMETHOD(ifdi_attach_post, ixl_if_attach_post), 1671031d839SEric Joyner DEVMETHOD(ifdi_detach, ixl_if_detach), 1681031d839SEric Joyner DEVMETHOD(ifdi_shutdown, ixl_if_shutdown), 1691031d839SEric Joyner DEVMETHOD(ifdi_suspend, ixl_if_suspend), 1701031d839SEric Joyner DEVMETHOD(ifdi_resume, ixl_if_resume), 1711031d839SEric Joyner DEVMETHOD(ifdi_init, ixl_if_init), 1721031d839SEric Joyner DEVMETHOD(ifdi_stop, ixl_if_stop), 1731031d839SEric Joyner DEVMETHOD(ifdi_msix_intr_assign, ixl_if_msix_intr_assign), 1741031d839SEric Joyner DEVMETHOD(ifdi_intr_enable, ixl_if_enable_intr), 1751031d839SEric Joyner DEVMETHOD(ifdi_intr_disable, ixl_if_disable_intr), 1761031d839SEric Joyner DEVMETHOD(ifdi_rx_queue_intr_enable, ixl_if_rx_queue_intr_enable), 1771031d839SEric Joyner DEVMETHOD(ifdi_tx_queue_intr_enable, ixl_if_tx_queue_intr_enable), 1781031d839SEric Joyner DEVMETHOD(ifdi_tx_queues_alloc, ixl_if_tx_queues_alloc), 1791031d839SEric Joyner DEVMETHOD(ifdi_rx_queues_alloc, ixl_if_rx_queues_alloc), 1801031d839SEric Joyner DEVMETHOD(ifdi_queues_free, ixl_if_queues_free), 1811031d839SEric Joyner DEVMETHOD(ifdi_update_admin_status, ixl_if_update_admin_status), 1821031d839SEric Joyner DEVMETHOD(ifdi_multi_set, ixl_if_multi_set), 1831031d839SEric Joyner DEVMETHOD(ifdi_mtu_set, ixl_if_mtu_set), 1841031d839SEric Joyner DEVMETHOD(ifdi_media_status, ixl_if_media_status), 1851031d839SEric Joyner DEVMETHOD(ifdi_media_change, ixl_if_media_change), 1861031d839SEric Joyner DEVMETHOD(ifdi_promisc_set, ixl_if_promisc_set), 1871031d839SEric Joyner DEVMETHOD(ifdi_timer, ixl_if_timer), 1881031d839SEric Joyner DEVMETHOD(ifdi_vlan_register, ixl_if_vlan_register), 1891031d839SEric Joyner DEVMETHOD(ifdi_vlan_unregister, ixl_if_vlan_unregister), 1901031d839SEric Joyner DEVMETHOD(ifdi_get_counter, ixl_if_get_counter), 1911031d839SEric Joyner DEVMETHOD(ifdi_i2c_req, ixl_if_i2c_req), 1921031d839SEric Joyner DEVMETHOD(ifdi_priv_ioctl, ixl_if_priv_ioctl), 193cf150917SEric Joyner DEVMETHOD(ifdi_needs_restart, ixl_if_needs_restart), 19477c1fcecSEric Joyner #ifdef PCI_IOV 19577c1fcecSEric Joyner DEVMETHOD(ifdi_iov_init, ixl_if_iov_init), 19677c1fcecSEric Joyner DEVMETHOD(ifdi_iov_uninit, ixl_if_iov_uninit), 19777c1fcecSEric Joyner DEVMETHOD(ifdi_iov_vf_add, ixl_if_iov_vf_add), 19877c1fcecSEric Joyner DEVMETHOD(ifdi_vflr_handle, ixl_if_vflr_handle), 19977c1fcecSEric Joyner #endif 2001031d839SEric Joyner // ifdi_led_func 2011031d839SEric Joyner // ifdi_debug 2021031d839SEric Joyner DEVMETHOD_END 2031031d839SEric Joyner }; 2041031d839SEric Joyner 2051031d839SEric Joyner static driver_t ixl_if_driver = { 2061031d839SEric Joyner "ixl_if", ixl_if_methods, sizeof(struct ixl_pf) 2071031d839SEric Joyner }; 20831830672SJack F Vogel 20961ae650dSJack F Vogel /* 21061ae650dSJack F Vogel ** TUNEABLE PARAMETERS: 21161ae650dSJack F Vogel */ 21261ae650dSJack F Vogel 21320b91f0aSPawel Biernacki static SYSCTL_NODE(_hw, OID_AUTO, ixl, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 21477c1fcecSEric Joyner "ixl driver parameters"); 21561ae650dSJack F Vogel 216*b4a7ce06SEric Joyner #ifdef IXL_DEBUG_FC 21761ae650dSJack F Vogel /* 218ceebc2f3SEric Joyner * Leave this on unless you need to send flow control 219ceebc2f3SEric Joyner * frames (or other control frames) from software 220ceebc2f3SEric Joyner */ 2214294f337SSean Bruno static int ixl_enable_tx_fc_filter = 1; 2224294f337SSean Bruno TUNABLE_INT("hw.ixl.enable_tx_fc_filter", 2234294f337SSean Bruno &ixl_enable_tx_fc_filter); 2244294f337SSean Bruno SYSCTL_INT(_hw_ixl, OID_AUTO, enable_tx_fc_filter, CTLFLAG_RDTUN, 2254294f337SSean Bruno &ixl_enable_tx_fc_filter, 0, 2264294f337SSean Bruno "Filter out packets with Ethertype 0x8808 from being sent out by non-HW sources"); 227*b4a7ce06SEric Joyner #endif 228*b4a7ce06SEric Joyner 229*b4a7ce06SEric Joyner #ifdef IXL_DEBUG 230*b4a7ce06SEric Joyner static int ixl_debug_recovery_mode = 0; 231*b4a7ce06SEric Joyner TUNABLE_INT("hw.ixl.debug_recovery_mode", 232*b4a7ce06SEric Joyner &ixl_debug_recovery_mode); 233*b4a7ce06SEric Joyner SYSCTL_INT(_hw_ixl, OID_AUTO, debug_recovery_mode, CTLFLAG_RDTUN, 234*b4a7ce06SEric Joyner &ixl_debug_recovery_mode, 0, 235*b4a7ce06SEric Joyner "Act like when FW entered recovery mode (for debuging)"); 236*b4a7ce06SEric Joyner #endif 2374294f337SSean Bruno 2381031d839SEric Joyner static int ixl_i2c_access_method = 0; 2391031d839SEric Joyner TUNABLE_INT("hw.ixl.i2c_access_method", 2401031d839SEric Joyner &ixl_i2c_access_method); 2411031d839SEric Joyner SYSCTL_INT(_hw_ixl, OID_AUTO, i2c_access_method, CTLFLAG_RDTUN, 2421031d839SEric Joyner &ixl_i2c_access_method, 0, 2431031d839SEric Joyner IXL_SYSCTL_HELP_I2C_METHOD); 2441031d839SEric Joyner 24577c1fcecSEric Joyner static int ixl_enable_vf_loopback = 1; 24677c1fcecSEric Joyner TUNABLE_INT("hw.ixl.enable_vf_loopback", 24777c1fcecSEric Joyner &ixl_enable_vf_loopback); 24877c1fcecSEric Joyner SYSCTL_INT(_hw_ixl, OID_AUTO, enable_vf_loopback, CTLFLAG_RDTUN, 24977c1fcecSEric Joyner &ixl_enable_vf_loopback, 0, 25077c1fcecSEric Joyner IXL_SYSCTL_HELP_VF_LOOPBACK); 25177c1fcecSEric Joyner 252ceebc2f3SEric Joyner /* 253ceebc2f3SEric Joyner * Different method for processing TX descriptor 254ceebc2f3SEric Joyner * completion. 255ceebc2f3SEric Joyner */ 256ceebc2f3SEric Joyner static int ixl_enable_head_writeback = 1; 257ceebc2f3SEric Joyner TUNABLE_INT("hw.ixl.enable_head_writeback", 258ceebc2f3SEric Joyner &ixl_enable_head_writeback); 259ceebc2f3SEric Joyner SYSCTL_INT(_hw_ixl, OID_AUTO, enable_head_writeback, CTLFLAG_RDTUN, 260ceebc2f3SEric Joyner &ixl_enable_head_writeback, 0, 261ceebc2f3SEric Joyner "For detecting last completed TX descriptor by hardware, use value written by HW instead of checking descriptors"); 262ceebc2f3SEric Joyner 2634294f337SSean Bruno static int ixl_core_debug_mask = 0; 2644294f337SSean Bruno TUNABLE_INT("hw.ixl.core_debug_mask", 2654294f337SSean Bruno &ixl_core_debug_mask); 2664294f337SSean Bruno SYSCTL_INT(_hw_ixl, OID_AUTO, core_debug_mask, CTLFLAG_RDTUN, 2674294f337SSean Bruno &ixl_core_debug_mask, 0, 2684294f337SSean Bruno "Display debug statements that are printed in non-shared code"); 2694294f337SSean Bruno 2704294f337SSean Bruno static int ixl_shared_debug_mask = 0; 2714294f337SSean Bruno TUNABLE_INT("hw.ixl.shared_debug_mask", 2724294f337SSean Bruno &ixl_shared_debug_mask); 2734294f337SSean Bruno SYSCTL_INT(_hw_ixl, OID_AUTO, shared_debug_mask, CTLFLAG_RDTUN, 2744294f337SSean Bruno &ixl_shared_debug_mask, 0, 2754294f337SSean Bruno "Display debug statements that are printed in shared code"); 2764294f337SSean Bruno 2771031d839SEric Joyner #if 0 27861ae650dSJack F Vogel /* 27961ae650dSJack F Vogel ** Controls for Interrupt Throttling 28061ae650dSJack F Vogel ** - true/false for dynamic adjustment 28161ae650dSJack F Vogel ** - default values for static ITR 28261ae650dSJack F Vogel */ 2831031d839SEric Joyner static int ixl_dynamic_rx_itr = 0; 28461ae650dSJack F Vogel TUNABLE_INT("hw.ixl.dynamic_rx_itr", &ixl_dynamic_rx_itr); 28561ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, dynamic_rx_itr, CTLFLAG_RDTUN, 28661ae650dSJack F Vogel &ixl_dynamic_rx_itr, 0, "Dynamic RX Interrupt Rate"); 28761ae650dSJack F Vogel 2881031d839SEric Joyner static int ixl_dynamic_tx_itr = 0; 28961ae650dSJack F Vogel TUNABLE_INT("hw.ixl.dynamic_tx_itr", &ixl_dynamic_tx_itr); 29061ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, dynamic_tx_itr, CTLFLAG_RDTUN, 29161ae650dSJack F Vogel &ixl_dynamic_tx_itr, 0, "Dynamic TX Interrupt Rate"); 2921031d839SEric Joyner #endif 29361ae650dSJack F Vogel 2944294f337SSean Bruno static int ixl_rx_itr = IXL_ITR_8K; 29561ae650dSJack F Vogel TUNABLE_INT("hw.ixl.rx_itr", &ixl_rx_itr); 29661ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, rx_itr, CTLFLAG_RDTUN, 29761ae650dSJack F Vogel &ixl_rx_itr, 0, "RX Interrupt Rate"); 29861ae650dSJack F Vogel 2994294f337SSean Bruno static int ixl_tx_itr = IXL_ITR_4K; 30061ae650dSJack F Vogel TUNABLE_INT("hw.ixl.tx_itr", &ixl_tx_itr); 30161ae650dSJack F Vogel SYSCTL_INT(_hw_ixl, OID_AUTO, tx_itr, CTLFLAG_RDTUN, 30261ae650dSJack F Vogel &ixl_tx_itr, 0, "TX Interrupt Rate"); 30361ae650dSJack F Vogel 304cb6b8299SEric Joyner #ifdef IXL_IW 305cb6b8299SEric Joyner int ixl_enable_iwarp = 0; 306cb6b8299SEric Joyner TUNABLE_INT("hw.ixl.enable_iwarp", &ixl_enable_iwarp); 307ceebc2f3SEric Joyner SYSCTL_INT(_hw_ixl, OID_AUTO, enable_iwarp, CTLFLAG_RDTUN, 308ceebc2f3SEric Joyner &ixl_enable_iwarp, 0, "iWARP enabled"); 309ceebc2f3SEric Joyner 310ceebc2f3SEric Joyner #if __FreeBSD_version < 1100000 311ceebc2f3SEric Joyner int ixl_limit_iwarp_msix = 1; 312ceebc2f3SEric Joyner #else 313ceebc2f3SEric Joyner int ixl_limit_iwarp_msix = IXL_IW_MAX_MSIX; 314ceebc2f3SEric Joyner #endif 315ceebc2f3SEric Joyner TUNABLE_INT("hw.ixl.limit_iwarp_msix", &ixl_limit_iwarp_msix); 316ceebc2f3SEric Joyner SYSCTL_INT(_hw_ixl, OID_AUTO, limit_iwarp_msix, CTLFLAG_RDTUN, 317b97de13aSMarius Strobl &ixl_limit_iwarp_msix, 0, "Limit MSI-X vectors assigned to iWARP"); 318cb6b8299SEric Joyner #endif 319cb6b8299SEric Joyner 3201031d839SEric Joyner extern struct if_txrx ixl_txrx_hwb; 3211031d839SEric Joyner extern struct if_txrx ixl_txrx_dwb; 322e5100ee2SJack F Vogel 3231031d839SEric Joyner static struct if_shared_ctx ixl_sctx_init = { 3241031d839SEric Joyner .isc_magic = IFLIB_MAGIC, 3251031d839SEric Joyner .isc_q_align = PAGE_SIZE, 3267f87c040SMarius Strobl .isc_tx_maxsize = IXL_TSO_SIZE + sizeof(struct ether_vlan_header), 3271031d839SEric Joyner .isc_tx_maxsegsize = IXL_MAX_DMA_SEG_SIZE, 3287f87c040SMarius Strobl .isc_tso_maxsize = IXL_TSO_SIZE + sizeof(struct ether_vlan_header), 3297f87c040SMarius Strobl .isc_tso_maxsegsize = IXL_MAX_DMA_SEG_SIZE, 3301031d839SEric Joyner .isc_rx_maxsize = 16384, 3311031d839SEric Joyner .isc_rx_nsegments = IXL_MAX_RX_SEGS, 3321031d839SEric Joyner .isc_rx_maxsegsize = IXL_MAX_DMA_SEG_SIZE, 3331031d839SEric Joyner .isc_nfl = 1, 3341031d839SEric Joyner .isc_ntxqs = 1, 3351031d839SEric Joyner .isc_nrxqs = 1, 3361031d839SEric Joyner 3371031d839SEric Joyner .isc_admin_intrcnt = 1, 3381031d839SEric Joyner .isc_vendor_info = ixl_vendor_info_array, 3391031d839SEric Joyner .isc_driver_version = IXL_DRIVER_VERSION_STRING, 3401031d839SEric Joyner .isc_driver = &ixl_if_driver, 34137761e2eSEric Joyner .isc_flags = IFLIB_NEED_SCRATCH | IFLIB_NEED_ZERO_CSUM | IFLIB_TSO_INIT_IP | IFLIB_ADMIN_ALWAYS_RUN, 3421031d839SEric Joyner 3431031d839SEric Joyner .isc_nrxd_min = {IXL_MIN_RING}, 3441031d839SEric Joyner .isc_ntxd_min = {IXL_MIN_RING}, 3451031d839SEric Joyner .isc_nrxd_max = {IXL_MAX_RING}, 3461031d839SEric Joyner .isc_ntxd_max = {IXL_MAX_RING}, 3471031d839SEric Joyner .isc_nrxd_default = {IXL_DEFAULT_RING}, 3481031d839SEric Joyner .isc_ntxd_default = {IXL_DEFAULT_RING}, 3491031d839SEric Joyner }; 3501031d839SEric Joyner 3511031d839SEric Joyner if_shared_ctx_t ixl_sctx = &ixl_sctx_init; 3521031d839SEric Joyner 3531031d839SEric Joyner /*** Functions ***/ 3541031d839SEric Joyner static void * 3551031d839SEric Joyner ixl_register(device_t dev) 3561031d839SEric Joyner { 3571031d839SEric Joyner return (ixl_sctx); 3581031d839SEric Joyner } 35961ae650dSJack F Vogel 36061ae650dSJack F Vogel static int 3611031d839SEric Joyner ixl_allocate_pci_resources(struct ixl_pf *pf) 36261ae650dSJack F Vogel { 3631031d839SEric Joyner device_t dev = iflib_get_dev(pf->vsi.ctx); 36477c1fcecSEric Joyner struct i40e_hw *hw = &pf->hw; 36577c1fcecSEric Joyner int rid; 36661ae650dSJack F Vogel 3671031d839SEric Joyner /* Map BAR0 */ 3681031d839SEric Joyner rid = PCIR_BAR(0); 3691031d839SEric Joyner pf->pci_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 3701031d839SEric Joyner &rid, RF_ACTIVE); 37161ae650dSJack F Vogel 3721031d839SEric Joyner if (!(pf->pci_mem)) { 3731031d839SEric Joyner device_printf(dev, "Unable to allocate bus resource: PCI memory\n"); 37461ae650dSJack F Vogel return (ENXIO); 37561ae650dSJack F Vogel } 37661ae650dSJack F Vogel 3771031d839SEric Joyner /* Save off the PCI information */ 3781031d839SEric Joyner hw->vendor_id = pci_get_vendor(dev); 3791031d839SEric Joyner hw->device_id = pci_get_device(dev); 3801031d839SEric Joyner hw->revision_id = pci_read_config(dev, PCIR_REVID, 1); 3811031d839SEric Joyner hw->subsystem_vendor_id = 3821031d839SEric Joyner pci_read_config(dev, PCIR_SUBVEND_0, 2); 3831031d839SEric Joyner hw->subsystem_device_id = 3841031d839SEric Joyner pci_read_config(dev, PCIR_SUBDEV_0, 2); 3854294f337SSean Bruno 3861031d839SEric Joyner hw->bus.device = pci_get_slot(dev); 3871031d839SEric Joyner hw->bus.func = pci_get_function(dev); 3884294f337SSean Bruno 3891031d839SEric Joyner /* Save off register access information */ 3901031d839SEric Joyner pf->osdep.mem_bus_space_tag = 3911031d839SEric Joyner rman_get_bustag(pf->pci_mem); 3921031d839SEric Joyner pf->osdep.mem_bus_space_handle = 3931031d839SEric Joyner rman_get_bushandle(pf->pci_mem); 3941031d839SEric Joyner pf->osdep.mem_bus_space_size = rman_get_size(pf->pci_mem); 3951031d839SEric Joyner pf->osdep.flush_reg = I40E_GLGEN_STAT; 3961031d839SEric Joyner pf->osdep.dev = dev; 397cb6b8299SEric Joyner 3981031d839SEric Joyner pf->hw.hw_addr = (u8 *) &pf->osdep.mem_bus_space_handle; 3991031d839SEric Joyner pf->hw.back = &pf->osdep; 4004294f337SSean Bruno 4014294f337SSean Bruno return (0); 4024294f337SSean Bruno } 4034294f337SSean Bruno 404*b4a7ce06SEric Joyner static void 405*b4a7ce06SEric Joyner ixl_setup_ssctx(struct ixl_pf *pf) 406*b4a7ce06SEric Joyner { 407*b4a7ce06SEric Joyner if_softc_ctx_t scctx = pf->vsi.shared; 408*b4a7ce06SEric Joyner struct i40e_hw *hw = &pf->hw; 409*b4a7ce06SEric Joyner 410*b4a7ce06SEric Joyner if (IXL_PF_IN_RECOVERY_MODE(pf)) { 411*b4a7ce06SEric Joyner scctx->isc_ntxqsets_max = scctx->isc_nrxqsets_max = 1; 412*b4a7ce06SEric Joyner scctx->isc_ntxqsets = scctx->isc_nrxqsets = 1; 413*b4a7ce06SEric Joyner } else if (hw->mac.type == I40E_MAC_X722) 414*b4a7ce06SEric Joyner scctx->isc_ntxqsets_max = scctx->isc_nrxqsets_max = 128; 415*b4a7ce06SEric Joyner else 416*b4a7ce06SEric Joyner scctx->isc_ntxqsets_max = scctx->isc_nrxqsets_max = 64; 417*b4a7ce06SEric Joyner 418*b4a7ce06SEric Joyner if (pf->vsi.enable_head_writeback) { 419*b4a7ce06SEric Joyner scctx->isc_txqsizes[0] = roundup2(scctx->isc_ntxd[0] 420*b4a7ce06SEric Joyner * sizeof(struct i40e_tx_desc) + sizeof(u32), DBA_ALIGN); 421*b4a7ce06SEric Joyner scctx->isc_txrx = &ixl_txrx_hwb; 422*b4a7ce06SEric Joyner } else { 423*b4a7ce06SEric Joyner scctx->isc_txqsizes[0] = roundup2(scctx->isc_ntxd[0] 424*b4a7ce06SEric Joyner * sizeof(struct i40e_tx_desc), DBA_ALIGN); 425*b4a7ce06SEric Joyner scctx->isc_txrx = &ixl_txrx_dwb; 426*b4a7ce06SEric Joyner } 427*b4a7ce06SEric Joyner 428*b4a7ce06SEric Joyner scctx->isc_txrx->ift_legacy_intr = ixl_intr; 429*b4a7ce06SEric Joyner scctx->isc_rxqsizes[0] = roundup2(scctx->isc_nrxd[0] 430*b4a7ce06SEric Joyner * sizeof(union i40e_32byte_rx_desc), DBA_ALIGN); 431*b4a7ce06SEric Joyner scctx->isc_msix_bar = PCIR_BAR(IXL_MSIX_BAR); 432*b4a7ce06SEric Joyner scctx->isc_tx_nsegments = IXL_MAX_TX_SEGS; 433*b4a7ce06SEric Joyner scctx->isc_tx_tso_segments_max = IXL_MAX_TSO_SEGS; 434*b4a7ce06SEric Joyner scctx->isc_tx_tso_size_max = IXL_TSO_SIZE; 435*b4a7ce06SEric Joyner scctx->isc_tx_tso_segsize_max = IXL_MAX_DMA_SEG_SIZE; 436*b4a7ce06SEric Joyner scctx->isc_rss_table_size = pf->hw.func_caps.rss_table_size; 437*b4a7ce06SEric Joyner scctx->isc_tx_csum_flags = CSUM_OFFLOAD; 438*b4a7ce06SEric Joyner scctx->isc_capabilities = scctx->isc_capenable = IXL_CAPS; 439*b4a7ce06SEric Joyner } 440*b4a7ce06SEric Joyner 441*b4a7ce06SEric Joyner static void 442*b4a7ce06SEric Joyner ixl_admin_timer(void *arg) 443*b4a7ce06SEric Joyner { 444*b4a7ce06SEric Joyner struct ixl_pf *pf = (struct ixl_pf *)arg; 445*b4a7ce06SEric Joyner 446*b4a7ce06SEric Joyner /* Fire off the admin task */ 447*b4a7ce06SEric Joyner iflib_admin_intr_deferred(pf->vsi.ctx); 448*b4a7ce06SEric Joyner 449*b4a7ce06SEric Joyner /* Reschedule the admin timer */ 450*b4a7ce06SEric Joyner callout_schedule(&pf->admin_timer, hz/2); 451*b4a7ce06SEric Joyner } 452*b4a7ce06SEric Joyner 453*b4a7ce06SEric Joyner static int 454*b4a7ce06SEric Joyner ixl_attach_pre_recovery_mode(struct ixl_pf *pf) 455*b4a7ce06SEric Joyner { 456*b4a7ce06SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 457*b4a7ce06SEric Joyner struct i40e_hw *hw = &pf->hw; 458*b4a7ce06SEric Joyner device_t dev = pf->dev; 459*b4a7ce06SEric Joyner 460*b4a7ce06SEric Joyner device_printf(dev, "Firmware recovery mode detected. Limiting functionality. Refer to Intel(R) Ethernet Adapters and Devices User Guide for details on firmware recovery mode.\n"); 461*b4a7ce06SEric Joyner 462*b4a7ce06SEric Joyner i40e_get_mac_addr(hw, hw->mac.addr); 463*b4a7ce06SEric Joyner 464*b4a7ce06SEric Joyner if (vsi->shared->isc_intr == IFLIB_INTR_MSIX) { 465*b4a7ce06SEric Joyner ixl_configure_intr0_msix(pf); 466*b4a7ce06SEric Joyner ixl_enable_intr0(hw); 467*b4a7ce06SEric Joyner } 468*b4a7ce06SEric Joyner 469*b4a7ce06SEric Joyner ixl_setup_ssctx(pf); 470*b4a7ce06SEric Joyner 471*b4a7ce06SEric Joyner return (0); 472*b4a7ce06SEric Joyner } 473*b4a7ce06SEric Joyner 47461ae650dSJack F Vogel static int 4751031d839SEric Joyner ixl_if_attach_pre(if_ctx_t ctx) 47661ae650dSJack F Vogel { 4771031d839SEric Joyner device_t dev; 47861ae650dSJack F Vogel struct ixl_pf *pf; 47961ae650dSJack F Vogel struct i40e_hw *hw; 48061ae650dSJack F Vogel struct ixl_vsi *vsi; 481*b4a7ce06SEric Joyner enum i40e_get_fw_lldp_status_resp lldp_status; 4821031d839SEric Joyner struct i40e_filter_control_settings filter; 4834294f337SSean Bruno enum i40e_status_code status; 48461ae650dSJack F Vogel int error = 0; 48561ae650dSJack F Vogel 4861031d839SEric Joyner dev = iflib_get_dev(ctx); 4871031d839SEric Joyner pf = iflib_get_softc(ctx); 48877c1fcecSEric Joyner 489c65f571cSLeandro Lupori INIT_DBG_DEV(dev, "begin"); 490c65f571cSLeandro Lupori 4911031d839SEric Joyner vsi = &pf->vsi; 4921031d839SEric Joyner vsi->back = pf; 4931031d839SEric Joyner pf->dev = dev; 49461ae650dSJack F Vogel hw = &pf->hw; 49561ae650dSJack F Vogel 49677c1fcecSEric Joyner vsi->dev = dev; 4971031d839SEric Joyner vsi->hw = &pf->hw; 4981031d839SEric Joyner vsi->id = 0; 4991031d839SEric Joyner vsi->num_vlans = 0; 5001031d839SEric Joyner vsi->ctx = ctx; 5011031d839SEric Joyner vsi->media = iflib_get_media(ctx); 502*b4a7ce06SEric Joyner vsi->shared = iflib_get_softc_ctx(ctx); 503*b4a7ce06SEric Joyner 504*b4a7ce06SEric Joyner snprintf(pf->admin_mtx_name, sizeof(pf->admin_mtx_name), 505*b4a7ce06SEric Joyner "%s:admin", device_get_nameunit(dev)); 506*b4a7ce06SEric Joyner mtx_init(&pf->admin_mtx, pf->admin_mtx_name, NULL, MTX_DEF); 507*b4a7ce06SEric Joyner callout_init_mtx(&pf->admin_timer, &pf->admin_mtx, 0); 50861ae650dSJack F Vogel 5094294f337SSean Bruno /* Save tunable values */ 5101031d839SEric Joyner ixl_save_pf_tunables(pf); 51161ae650dSJack F Vogel 51261ae650dSJack F Vogel /* Do PCI setup - map BAR0, etc */ 51361ae650dSJack F Vogel if (ixl_allocate_pci_resources(pf)) { 51461ae650dSJack F Vogel device_printf(dev, "Allocation of PCI resources failed\n"); 51561ae650dSJack F Vogel error = ENXIO; 5161031d839SEric Joyner goto err_pci_res; 51761ae650dSJack F Vogel } 51861ae650dSJack F Vogel 51961ae650dSJack F Vogel /* Establish a clean starting point */ 52061ae650dSJack F Vogel i40e_clear_hw(hw); 521*b4a7ce06SEric Joyner i40e_set_mac_type(hw); 522*b4a7ce06SEric Joyner 523*b4a7ce06SEric Joyner error = ixl_pf_reset(pf); 524*b4a7ce06SEric Joyner if (error) 52561ae650dSJack F Vogel goto err_out; 52661ae650dSJack F Vogel 52761ae650dSJack F Vogel /* Initialize the shared code */ 5284294f337SSean Bruno status = i40e_init_shared_code(hw); 5294294f337SSean Bruno if (status) { 5304294f337SSean Bruno device_printf(dev, "Unable to initialize shared code, error %s\n", 5314294f337SSean Bruno i40e_stat_str(hw, status)); 53261ae650dSJack F Vogel error = EIO; 53361ae650dSJack F Vogel goto err_out; 53461ae650dSJack F Vogel } 53561ae650dSJack F Vogel 53661ae650dSJack F Vogel /* Set up the admin queue */ 5374294f337SSean Bruno hw->aq.num_arq_entries = IXL_AQ_LEN; 5384294f337SSean Bruno hw->aq.num_asq_entries = IXL_AQ_LEN; 5394294f337SSean Bruno hw->aq.arq_buf_size = IXL_AQ_BUF_SZ; 5404294f337SSean Bruno hw->aq.asq_buf_size = IXL_AQ_BUF_SZ; 5414294f337SSean Bruno 5424294f337SSean Bruno status = i40e_init_adminq(hw); 5434294f337SSean Bruno if (status != 0 && status != I40E_ERR_FIRMWARE_API_VERSION) { 5444294f337SSean Bruno device_printf(dev, "Unable to initialize Admin Queue, error %s\n", 5454294f337SSean Bruno i40e_stat_str(hw, status)); 546fdb6f38aSEric Joyner error = EIO; 547fdb6f38aSEric Joyner goto err_out; 548fdb6f38aSEric Joyner } 5491d767a8eSEric Joyner ixl_print_nvm_version(pf); 5501d767a8eSEric Joyner 5514294f337SSean Bruno if (status == I40E_ERR_FIRMWARE_API_VERSION) { 55261ae650dSJack F Vogel device_printf(dev, "The driver for the device stopped " 553ceebc2f3SEric Joyner "because the NVM image is newer than expected.\n"); 554ceebc2f3SEric Joyner device_printf(dev, "You must install the most recent version of " 55561ae650dSJack F Vogel "the network driver.\n"); 556fdb6f38aSEric Joyner error = EIO; 55761ae650dSJack F Vogel goto err_out; 55861ae650dSJack F Vogel } 55961ae650dSJack F Vogel 56061ae650dSJack F Vogel if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && 561ceebc2f3SEric Joyner hw->aq.api_min_ver > I40E_FW_MINOR_VERSION(hw)) { 56261ae650dSJack F Vogel device_printf(dev, "The driver for the device detected " 563ceebc2f3SEric Joyner "a newer version of the NVM image than expected.\n"); 564ceebc2f3SEric Joyner device_printf(dev, "Please install the most recent version " 565ceebc2f3SEric Joyner "of the network driver.\n"); 566ceebc2f3SEric Joyner } else if (hw->aq.api_maj_ver == 1 && hw->aq.api_min_ver < 4) { 56761ae650dSJack F Vogel device_printf(dev, "The driver for the device detected " 568ceebc2f3SEric Joyner "an older version of the NVM image than expected.\n"); 569ceebc2f3SEric Joyner device_printf(dev, "Please update the NVM image.\n"); 570ceebc2f3SEric Joyner } 57161ae650dSJack F Vogel 572*b4a7ce06SEric Joyner if (IXL_PF_IN_RECOVERY_MODE(pf)) { 573*b4a7ce06SEric Joyner error = ixl_attach_pre_recovery_mode(pf); 574*b4a7ce06SEric Joyner if (error) 575*b4a7ce06SEric Joyner goto err_out; 576*b4a7ce06SEric Joyner return (error); 577*b4a7ce06SEric Joyner } 578*b4a7ce06SEric Joyner 57961ae650dSJack F Vogel /* Clear PXE mode */ 58061ae650dSJack F Vogel i40e_clear_pxe_mode(hw); 58161ae650dSJack F Vogel 58261ae650dSJack F Vogel /* Get capabilities from the device */ 58361ae650dSJack F Vogel error = ixl_get_hw_capabilities(pf); 58461ae650dSJack F Vogel if (error) { 5851031d839SEric Joyner device_printf(dev, "get_hw_capabilities failed: %d\n", 5861031d839SEric Joyner error); 58761ae650dSJack F Vogel goto err_get_cap; 58861ae650dSJack F Vogel } 58961ae650dSJack F Vogel 59061ae650dSJack F Vogel /* Set up host memory cache */ 591*b4a7ce06SEric Joyner error = ixl_setup_hmc(pf); 592*b4a7ce06SEric Joyner if (error) 59361ae650dSJack F Vogel goto err_mac_hmc; 59461ae650dSJack F Vogel 595d4683565SEric Joyner /* Disable LLDP from the firmware for certain NVM versions */ 596d4683565SEric Joyner if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || 597ceebc2f3SEric Joyner (pf->hw.aq.fw_maj_ver < 4)) { 598*b4a7ce06SEric Joyner i40e_aq_stop_lldp(hw, true, false, NULL); 599ceebc2f3SEric Joyner pf->state |= IXL_PF_STATE_FW_LLDP_DISABLED; 600ceebc2f3SEric Joyner } 60161ae650dSJack F Vogel 6024294f337SSean Bruno /* Get MAC addresses from hardware */ 60361ae650dSJack F Vogel i40e_get_mac_addr(hw, hw->mac.addr); 60461ae650dSJack F Vogel error = i40e_validate_mac_addr(hw->mac.addr); 60561ae650dSJack F Vogel if (error) { 60661ae650dSJack F Vogel device_printf(dev, "validate_mac_addr failed: %d\n", error); 60761ae650dSJack F Vogel goto err_mac_hmc; 60861ae650dSJack F Vogel } 60961ae650dSJack F Vogel bcopy(hw->mac.addr, hw->mac.perm_addr, ETHER_ADDR_LEN); 6101031d839SEric Joyner iflib_set_mac(ctx, hw->mac.addr); 61161ae650dSJack F Vogel i40e_get_port_mac_addr(hw, hw->mac.port_addr); 61261ae650dSJack F Vogel 6131031d839SEric Joyner /* Set up the device filtering */ 6141031d839SEric Joyner bzero(&filter, sizeof(filter)); 6151031d839SEric Joyner filter.enable_ethtype = TRUE; 6161031d839SEric Joyner filter.enable_macvlan = TRUE; 6171031d839SEric Joyner filter.enable_fdir = FALSE; 6181031d839SEric Joyner filter.hash_lut_size = I40E_HASH_LUT_SIZE_512; 6191031d839SEric Joyner if (i40e_set_filter_control(hw, &filter)) 6201031d839SEric Joyner device_printf(dev, "i40e_set_filter_control() failed\n"); 6211031d839SEric Joyner 622ceebc2f3SEric Joyner /* Query device FW LLDP status */ 623*b4a7ce06SEric Joyner if (i40e_get_fw_lldp_status(hw, &lldp_status) == I40E_SUCCESS) { 624*b4a7ce06SEric Joyner if (lldp_status == I40E_GET_FW_LLDP_STATUS_DISABLED) { 625*b4a7ce06SEric Joyner atomic_set_32(&pf->state, 626*b4a7ce06SEric Joyner IXL_PF_STATE_FW_LLDP_DISABLED); 627*b4a7ce06SEric Joyner } else { 628*b4a7ce06SEric Joyner atomic_clear_32(&pf->state, 629*b4a7ce06SEric Joyner IXL_PF_STATE_FW_LLDP_DISABLED); 630*b4a7ce06SEric Joyner } 631*b4a7ce06SEric Joyner } 632*b4a7ce06SEric Joyner 633ceebc2f3SEric Joyner /* Tell FW to apply DCB config on link up */ 634ceebc2f3SEric Joyner i40e_aq_set_dcb_parameters(hw, true, NULL); 635ceebc2f3SEric Joyner 6361031d839SEric Joyner /* Fill out iflib parameters */ 637*b4a7ce06SEric Joyner ixl_setup_ssctx(pf); 6384294f337SSean Bruno 63977c1fcecSEric Joyner INIT_DBG_DEV(dev, "end"); 6401031d839SEric Joyner return (0); 6411031d839SEric Joyner 6421031d839SEric Joyner err_mac_hmc: 643*b4a7ce06SEric Joyner ixl_shutdown_hmc(pf); 6441031d839SEric Joyner err_get_cap: 6451031d839SEric Joyner i40e_shutdown_adminq(hw); 6461031d839SEric Joyner err_out: 6471031d839SEric Joyner ixl_free_pci_resources(pf); 6481031d839SEric Joyner err_pci_res: 649*b4a7ce06SEric Joyner mtx_lock(&pf->admin_mtx); 650*b4a7ce06SEric Joyner callout_stop(&pf->admin_timer); 651*b4a7ce06SEric Joyner mtx_unlock(&pf->admin_mtx); 652*b4a7ce06SEric Joyner mtx_destroy(&pf->admin_mtx); 6531031d839SEric Joyner return (error); 65461ae650dSJack F Vogel } 65561ae650dSJack F Vogel 6561031d839SEric Joyner static int 6571031d839SEric Joyner ixl_if_attach_post(if_ctx_t ctx) 6581031d839SEric Joyner { 6591031d839SEric Joyner device_t dev; 6601031d839SEric Joyner struct ixl_pf *pf; 6611031d839SEric Joyner struct i40e_hw *hw; 6621031d839SEric Joyner struct ixl_vsi *vsi; 6631031d839SEric Joyner int error = 0; 6641031d839SEric Joyner enum i40e_status_code status; 6651031d839SEric Joyner 6661031d839SEric Joyner dev = iflib_get_dev(ctx); 6671031d839SEric Joyner pf = iflib_get_softc(ctx); 668c65f571cSLeandro Lupori 669c65f571cSLeandro Lupori INIT_DBG_DEV(dev, "begin"); 670c65f571cSLeandro Lupori 6711031d839SEric Joyner vsi = &pf->vsi; 6721031d839SEric Joyner vsi->ifp = iflib_get_ifp(ctx); 6731031d839SEric Joyner hw = &pf->hw; 6741031d839SEric Joyner 67577c1fcecSEric Joyner /* Save off determined number of queues for interface */ 67677c1fcecSEric Joyner vsi->num_rx_queues = vsi->shared->isc_nrxqsets; 67777c1fcecSEric Joyner vsi->num_tx_queues = vsi->shared->isc_ntxqsets; 67877c1fcecSEric Joyner 6794294f337SSean Bruno /* Setup OS network interface / ifnet */ 6801031d839SEric Joyner if (ixl_setup_interface(dev, pf)) { 6814294f337SSean Bruno device_printf(dev, "interface setup failed!\n"); 6824294f337SSean Bruno error = EIO; 6831031d839SEric Joyner goto err; 684223d846dSEric Joyner } 68561ae650dSJack F Vogel 686*b4a7ce06SEric Joyner if (IXL_PF_IN_RECOVERY_MODE(pf)) { 687*b4a7ce06SEric Joyner /* Keep admin queue interrupts active while driver is loaded */ 688*b4a7ce06SEric Joyner if (vsi->shared->isc_intr == IFLIB_INTR_MSIX) { 689*b4a7ce06SEric Joyner ixl_configure_intr0_msix(pf); 690*b4a7ce06SEric Joyner ixl_enable_intr0(hw); 691*b4a7ce06SEric Joyner } 692*b4a7ce06SEric Joyner 693*b4a7ce06SEric Joyner ixl_add_sysctls_recovery_mode(pf); 694*b4a7ce06SEric Joyner 695*b4a7ce06SEric Joyner /* Start the admin timer */ 696*b4a7ce06SEric Joyner mtx_lock(&pf->admin_mtx); 697*b4a7ce06SEric Joyner callout_reset(&pf->admin_timer, hz/2, ixl_admin_timer, pf); 698*b4a7ce06SEric Joyner mtx_unlock(&pf->admin_mtx); 699*b4a7ce06SEric Joyner return (0); 700*b4a7ce06SEric Joyner } 701*b4a7ce06SEric Joyner 70261ae650dSJack F Vogel /* Determine link state */ 7034294f337SSean Bruno if (ixl_attach_get_link_status(pf)) { 7044294f337SSean Bruno error = EINVAL; 7051031d839SEric Joyner goto err; 706e5100ee2SJack F Vogel } 70761ae650dSJack F Vogel 708b6c8f260SJack F Vogel error = ixl_switch_config(pf); 709b6c8f260SJack F Vogel if (error) { 7106c426059SEric Joyner device_printf(dev, "Initial ixl_switch_config() failed: %d\n", 7116c426059SEric Joyner error); 7121031d839SEric Joyner goto err; 713b6c8f260SJack F Vogel } 714b6c8f260SJack F Vogel 7151031d839SEric Joyner /* Add protocol filters to list */ 7161031d839SEric Joyner ixl_init_filters(vsi); 7171031d839SEric Joyner 7181031d839SEric Joyner /* Init queue allocation manager */ 7191031d839SEric Joyner error = ixl_pf_qmgr_init(&pf->qmgr, hw->func_caps.num_tx_qp); 7201031d839SEric Joyner if (error) { 7211031d839SEric Joyner device_printf(dev, "Failed to init queue manager for PF queues, error %d\n", 7221031d839SEric Joyner error); 7231031d839SEric Joyner goto err; 7241031d839SEric Joyner } 7251031d839SEric Joyner /* reserve a contiguous allocation for the PF's VSI */ 7261031d839SEric Joyner error = ixl_pf_qmgr_alloc_contiguous(&pf->qmgr, 7271031d839SEric Joyner max(vsi->num_rx_queues, vsi->num_tx_queues), &pf->qtag); 7281031d839SEric Joyner if (error) { 7291031d839SEric Joyner device_printf(dev, "Failed to reserve queues for PF LAN VSI, error %d\n", 7301031d839SEric Joyner error); 7311031d839SEric Joyner goto err; 7321031d839SEric Joyner } 7331031d839SEric Joyner device_printf(dev, "Allocating %d queues for PF LAN VSI; %d queues active\n", 7341031d839SEric Joyner pf->qtag.num_allocated, pf->qtag.num_active); 7351031d839SEric Joyner 736223d846dSEric Joyner /* Limit PHY interrupts to link, autoneg, and modules failure */ 7374294f337SSean Bruno status = i40e_aq_set_phy_int_mask(hw, IXL_DEFAULT_PHY_INT_MASK, 738223d846dSEric Joyner NULL); 7394294f337SSean Bruno if (status) { 7404294f337SSean Bruno device_printf(dev, "i40e_aq_set_phy_mask() failed: err %s," 7414294f337SSean Bruno " aq_err %s\n", i40e_stat_str(hw, status), 7424294f337SSean Bruno i40e_aq_str(hw, hw->aq.asq_last_status)); 7431031d839SEric Joyner goto err; 744223d846dSEric Joyner } 745b6c8f260SJack F Vogel 7461031d839SEric Joyner /* Get the bus configuration and set the shared code */ 747cb6b8299SEric Joyner ixl_get_bus_info(pf); 74861ae650dSJack F Vogel 7491031d839SEric Joyner /* Keep admin queue interrupts active while driver is loaded */ 7501031d839SEric Joyner if (vsi->shared->isc_intr == IFLIB_INTR_MSIX) { 7516c426059SEric Joyner ixl_configure_intr0_msix(pf); 752cb6b8299SEric Joyner ixl_enable_intr0(hw); 753cb6b8299SEric Joyner } 754cb6b8299SEric Joyner 755cb6b8299SEric Joyner /* Set initial advertised speed sysctl value */ 756ceebc2f3SEric Joyner ixl_set_initial_advertised_speeds(pf); 757cb6b8299SEric Joyner 758fdb6f38aSEric Joyner /* Initialize statistics & add sysctls */ 759fdb6f38aSEric Joyner ixl_add_device_sysctls(pf); 76061ae650dSJack F Vogel ixl_pf_reset_stats(pf); 76161ae650dSJack F Vogel ixl_update_stats_counters(pf); 76261ae650dSJack F Vogel ixl_add_hw_stats(pf); 76361ae650dSJack F Vogel 7641031d839SEric Joyner hw->phy.get_link_info = true; 7651031d839SEric Joyner i40e_get_link_status(hw, &pf->link_up); 7661031d839SEric Joyner ixl_update_link_status(pf); 76761ae650dSJack F Vogel 76856c2c47bSJack F Vogel #ifdef PCI_IOV 7694294f337SSean Bruno ixl_initialize_sriov(pf); 77056c2c47bSJack F Vogel #endif 77156c2c47bSJack F Vogel 772cb6b8299SEric Joyner #ifdef IXL_IW 773cb6b8299SEric Joyner if (hw->func_caps.iwarp && ixl_enable_iwarp) { 774cb6b8299SEric Joyner pf->iw_enabled = (pf->iw_msix > 0) ? true : false; 775cb6b8299SEric Joyner if (pf->iw_enabled) { 776cb6b8299SEric Joyner error = ixl_iw_pf_attach(pf); 777cb6b8299SEric Joyner if (error) { 778cb6b8299SEric Joyner device_printf(dev, 779b97de13aSMarius Strobl "interfacing to iWARP driver failed: %d\n", 780cb6b8299SEric Joyner error); 7811031d839SEric Joyner goto err; 782ceebc2f3SEric Joyner } else 783ceebc2f3SEric Joyner device_printf(dev, "iWARP ready\n"); 784cb6b8299SEric Joyner } else 785b97de13aSMarius Strobl device_printf(dev, "iWARP disabled on this device " 786b97de13aSMarius Strobl "(no MSI-X vectors)\n"); 787cb6b8299SEric Joyner } else { 788cb6b8299SEric Joyner pf->iw_enabled = false; 789cb6b8299SEric Joyner device_printf(dev, "The device is not iWARP enabled\n"); 790cb6b8299SEric Joyner } 791cb6b8299SEric Joyner #endif 792*b4a7ce06SEric Joyner /* Start the admin timer */ 793*b4a7ce06SEric Joyner mtx_lock(&pf->admin_mtx); 794*b4a7ce06SEric Joyner callout_reset(&pf->admin_timer, hz/2, ixl_admin_timer, pf); 795*b4a7ce06SEric Joyner mtx_unlock(&pf->admin_mtx); 796cb6b8299SEric Joyner 7971031d839SEric Joyner INIT_DBG_DEV(dev, "end"); 79861ae650dSJack F Vogel return (0); 79961ae650dSJack F Vogel 8001031d839SEric Joyner err: 8011031d839SEric Joyner INIT_DEBUGOUT("end: error %d", error); 8021031d839SEric Joyner /* ixl_if_detach() is called on error from this */ 80361ae650dSJack F Vogel return (error); 80461ae650dSJack F Vogel } 80561ae650dSJack F Vogel 80677c1fcecSEric Joyner /** 80777c1fcecSEric Joyner * XXX: iflib always ignores the return value of detach() 80877c1fcecSEric Joyner * -> This means that this isn't allowed to fail 80977c1fcecSEric Joyner */ 81061ae650dSJack F Vogel static int 8111031d839SEric Joyner ixl_if_detach(if_ctx_t ctx) 81261ae650dSJack F Vogel { 8131031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 81461ae650dSJack F Vogel struct ixl_vsi *vsi = &pf->vsi; 8151031d839SEric Joyner struct i40e_hw *hw = &pf->hw; 8161031d839SEric Joyner device_t dev = pf->dev; 8176c426059SEric Joyner enum i40e_status_code status; 81877c1fcecSEric Joyner #ifdef IXL_IW 81956c2c47bSJack F Vogel int error; 82056c2c47bSJack F Vogel #endif 82161ae650dSJack F Vogel 8221031d839SEric Joyner INIT_DBG_DEV(dev, "begin"); 823cb6b8299SEric Joyner 824*b4a7ce06SEric Joyner /* Stop the admin timer */ 825*b4a7ce06SEric Joyner mtx_lock(&pf->admin_mtx); 826*b4a7ce06SEric Joyner callout_stop(&pf->admin_timer); 827*b4a7ce06SEric Joyner mtx_unlock(&pf->admin_mtx); 828*b4a7ce06SEric Joyner mtx_destroy(&pf->admin_mtx); 829*b4a7ce06SEric Joyner 830cb6b8299SEric Joyner #ifdef IXL_IW 831cb6b8299SEric Joyner if (ixl_enable_iwarp && pf->iw_enabled) { 832cb6b8299SEric Joyner error = ixl_iw_pf_detach(pf); 833cb6b8299SEric Joyner if (error == EBUSY) { 834cb6b8299SEric Joyner device_printf(dev, "iwarp in use; stop it first.\n"); 83577c1fcecSEric Joyner //return (error); 836cb6b8299SEric Joyner } 837cb6b8299SEric Joyner } 838cb6b8299SEric Joyner #endif 8391031d839SEric Joyner /* Remove all previously allocated media types */ 8401031d839SEric Joyner ifmedia_removeall(vsi->media); 841cb6b8299SEric Joyner 8421031d839SEric Joyner /* Shutdown LAN HMC */ 843*b4a7ce06SEric Joyner ixl_shutdown_hmc(pf); 8441031d839SEric Joyner 8451031d839SEric Joyner /* Shutdown admin queue */ 8461031d839SEric Joyner ixl_disable_intr0(hw); 8471031d839SEric Joyner status = i40e_shutdown_adminq(hw); 8481031d839SEric Joyner if (status) 8491031d839SEric Joyner device_printf(dev, 8501031d839SEric Joyner "i40e_shutdown_adminq() failed with status %s\n", 8511031d839SEric Joyner i40e_stat_str(hw, status)); 8521031d839SEric Joyner 8534294f337SSean Bruno ixl_pf_qmgr_destroy(&pf->qmgr); 85461ae650dSJack F Vogel ixl_free_pci_resources(pf); 8551031d839SEric Joyner ixl_free_mac_filters(vsi); 8561031d839SEric Joyner INIT_DBG_DEV(dev, "end"); 85761ae650dSJack F Vogel return (0); 85861ae650dSJack F Vogel } 85961ae650dSJack F Vogel 8601031d839SEric Joyner static int 8611031d839SEric Joyner ixl_if_shutdown(if_ctx_t ctx) 8621031d839SEric Joyner { 8631031d839SEric Joyner int error = 0; 8641031d839SEric Joyner 8651031d839SEric Joyner INIT_DEBUGOUT("ixl_if_shutdown: begin"); 8661031d839SEric Joyner 8671031d839SEric Joyner /* TODO: Call ixl_if_stop()? */ 8681031d839SEric Joyner 8691031d839SEric Joyner /* TODO: Then setup low power mode */ 8701031d839SEric Joyner 8711031d839SEric Joyner return (error); 8721031d839SEric Joyner } 87361ae650dSJack F Vogel 87461ae650dSJack F Vogel static int 8751031d839SEric Joyner ixl_if_suspend(if_ctx_t ctx) 87661ae650dSJack F Vogel { 8771031d839SEric Joyner int error = 0; 8781031d839SEric Joyner 8791031d839SEric Joyner INIT_DEBUGOUT("ixl_if_suspend: begin"); 8801031d839SEric Joyner 8811031d839SEric Joyner /* TODO: Call ixl_if_stop()? */ 8821031d839SEric Joyner 8831031d839SEric Joyner /* TODO: Then setup low power mode */ 8841031d839SEric Joyner 8851031d839SEric Joyner return (error); 8861031d839SEric Joyner } 8871031d839SEric Joyner 8881031d839SEric Joyner static int 8891031d839SEric Joyner ixl_if_resume(if_ctx_t ctx) 8901031d839SEric Joyner { 8911031d839SEric Joyner struct ifnet *ifp = iflib_get_ifp(ctx); 8921031d839SEric Joyner 8931031d839SEric Joyner INIT_DEBUGOUT("ixl_if_resume: begin"); 8941031d839SEric Joyner 8951031d839SEric Joyner /* Read & clear wake-up registers */ 8961031d839SEric Joyner 8971031d839SEric Joyner /* Required after D3->D0 transition */ 8981031d839SEric Joyner if (ifp->if_flags & IFF_UP) 8991031d839SEric Joyner ixl_if_init(ctx); 9001031d839SEric Joyner 90161ae650dSJack F Vogel return (0); 90261ae650dSJack F Vogel } 90361ae650dSJack F Vogel 9041031d839SEric Joyner void 9051031d839SEric Joyner ixl_if_init(if_ctx_t ctx) 9061031d839SEric Joyner { 9071031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 9081031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 9091031d839SEric Joyner struct i40e_hw *hw = &pf->hw; 91077c1fcecSEric Joyner struct ifnet *ifp = iflib_get_ifp(ctx); 9111031d839SEric Joyner device_t dev = iflib_get_dev(ctx); 9121031d839SEric Joyner u8 tmpaddr[ETHER_ADDR_LEN]; 9131031d839SEric Joyner int ret; 9141031d839SEric Joyner 915*b4a7ce06SEric Joyner if (IXL_PF_IN_RECOVERY_MODE(pf)) 916*b4a7ce06SEric Joyner return; 9171031d839SEric Joyner /* 9181031d839SEric Joyner * If the aq is dead here, it probably means something outside of the driver 9191031d839SEric Joyner * did something to the adapter, like a PF reset. 92077c1fcecSEric Joyner * So, rebuild the driver's state here if that occurs. 9211031d839SEric Joyner */ 9221031d839SEric Joyner if (!i40e_check_asq_alive(&pf->hw)) { 9231031d839SEric Joyner device_printf(dev, "Admin Queue is down; resetting...\n"); 9241031d839SEric Joyner ixl_teardown_hw_structs(pf); 925*b4a7ce06SEric Joyner ixl_rebuild_hw_structs_after_reset(pf, false); 9261031d839SEric Joyner } 9271031d839SEric Joyner 9281031d839SEric Joyner /* Get the latest mac address... User might use a LAA */ 9291031d839SEric Joyner bcopy(IF_LLADDR(vsi->ifp), tmpaddr, ETH_ALEN); 9301031d839SEric Joyner if (!cmp_etheraddr(hw->mac.addr, tmpaddr) && 9311031d839SEric Joyner (i40e_validate_mac_addr(tmpaddr) == I40E_SUCCESS)) { 9321031d839SEric Joyner ixl_del_filter(vsi, hw->mac.addr, IXL_VLAN_ANY); 9331031d839SEric Joyner bcopy(tmpaddr, hw->mac.addr, ETH_ALEN); 9341031d839SEric Joyner ret = i40e_aq_mac_address_write(hw, 9351031d839SEric Joyner I40E_AQC_WRITE_TYPE_LAA_ONLY, 9361031d839SEric Joyner hw->mac.addr, NULL); 9371031d839SEric Joyner if (ret) { 9381031d839SEric Joyner device_printf(dev, "LLA address change failed!!\n"); 9391031d839SEric Joyner return; 9401031d839SEric Joyner } 9411031d839SEric Joyner ixl_add_filter(vsi, hw->mac.addr, IXL_VLAN_ANY); 9421031d839SEric Joyner } 9431031d839SEric Joyner 9441031d839SEric Joyner iflib_set_mac(ctx, hw->mac.addr); 9451031d839SEric Joyner 9461031d839SEric Joyner /* Prepare the VSI: rings, hmc contexts, etc... */ 9471031d839SEric Joyner if (ixl_initialize_vsi(vsi)) { 9481031d839SEric Joyner device_printf(dev, "initialize vsi failed!!\n"); 9491031d839SEric Joyner return; 9501031d839SEric Joyner } 9511031d839SEric Joyner 95277c1fcecSEric Joyner /* Reconfigure multicast filters in HW */ 9531031d839SEric Joyner ixl_if_multi_set(ctx); 9541031d839SEric Joyner 9551031d839SEric Joyner /* Set up RSS */ 9561031d839SEric Joyner ixl_config_rss(pf); 9571031d839SEric Joyner 958b97de13aSMarius Strobl /* Set up MSI-X routing and the ITR settings */ 9591031d839SEric Joyner if (vsi->shared->isc_intr == IFLIB_INTR_MSIX) { 9601031d839SEric Joyner ixl_configure_queue_intr_msix(pf); 9611031d839SEric Joyner ixl_configure_itr(pf); 9621031d839SEric Joyner } else 9631031d839SEric Joyner ixl_configure_legacy(pf); 9641031d839SEric Joyner 9651031d839SEric Joyner if (vsi->enable_head_writeback) 9661031d839SEric Joyner ixl_init_tx_cidx(vsi); 9671031d839SEric Joyner else 9681031d839SEric Joyner ixl_init_tx_rsqs(vsi); 9691031d839SEric Joyner 9701031d839SEric Joyner ixl_enable_rings(vsi); 9711031d839SEric Joyner 9721031d839SEric Joyner i40e_aq_set_default_vsi(hw, vsi->seid, NULL); 9731031d839SEric Joyner 97477c1fcecSEric Joyner /* Re-add configure filters to HW */ 9751031d839SEric Joyner ixl_reconfigure_filters(vsi); 9761031d839SEric Joyner 97777c1fcecSEric Joyner /* Configure promiscuous mode */ 97877c1fcecSEric Joyner ixl_if_promisc_set(ctx, if_getflags(ifp)); 97977c1fcecSEric Joyner 9801031d839SEric Joyner #ifdef IXL_IW 9811031d839SEric Joyner if (ixl_enable_iwarp && pf->iw_enabled) { 9821031d839SEric Joyner ret = ixl_iw_pf_init(pf); 9831031d839SEric Joyner if (ret) 9841031d839SEric Joyner device_printf(dev, 9851031d839SEric Joyner "initialize iwarp failed, code %d\n", ret); 9861031d839SEric Joyner } 9871031d839SEric Joyner #endif 9881031d839SEric Joyner } 9891031d839SEric Joyner 9901031d839SEric Joyner void 9911031d839SEric Joyner ixl_if_stop(if_ctx_t ctx) 9921031d839SEric Joyner { 9931031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 9941031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 9951031d839SEric Joyner 9961031d839SEric Joyner INIT_DEBUGOUT("ixl_if_stop: begin\n"); 9971031d839SEric Joyner 998*b4a7ce06SEric Joyner if (IXL_PF_IN_RECOVERY_MODE(pf)) 999*b4a7ce06SEric Joyner return; 1000*b4a7ce06SEric Joyner 10011031d839SEric Joyner // TODO: This may need to be reworked 10021031d839SEric Joyner #ifdef IXL_IW 10031031d839SEric Joyner /* Stop iWARP device */ 10041031d839SEric Joyner if (ixl_enable_iwarp && pf->iw_enabled) 10051031d839SEric Joyner ixl_iw_pf_stop(pf); 10061031d839SEric Joyner #endif 10071031d839SEric Joyner 10081031d839SEric Joyner ixl_disable_rings_intr(vsi); 100977c1fcecSEric Joyner ixl_disable_rings(pf, vsi, &pf->qtag); 10101031d839SEric Joyner } 10111031d839SEric Joyner 10121031d839SEric Joyner static int 10131031d839SEric Joyner ixl_if_msix_intr_assign(if_ctx_t ctx, int msix) 10141031d839SEric Joyner { 10151031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 10161031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 10171031d839SEric Joyner struct ixl_rx_queue *rx_que = vsi->rx_queues; 10181031d839SEric Joyner struct ixl_tx_queue *tx_que = vsi->tx_queues; 10191031d839SEric Joyner int err, i, rid, vector = 0; 10201031d839SEric Joyner char buf[16]; 10211031d839SEric Joyner 102277c1fcecSEric Joyner MPASS(vsi->shared->isc_nrxqsets > 0); 102377c1fcecSEric Joyner MPASS(vsi->shared->isc_ntxqsets > 0); 102477c1fcecSEric Joyner 10251031d839SEric Joyner /* Admin Que must use vector 0*/ 10261031d839SEric Joyner rid = vector + 1; 10271031d839SEric Joyner err = iflib_irq_alloc_generic(ctx, &vsi->irq, rid, IFLIB_INTR_ADMIN, 10281031d839SEric Joyner ixl_msix_adminq, pf, 0, "aq"); 10291031d839SEric Joyner if (err) { 10301031d839SEric Joyner iflib_irq_free(ctx, &vsi->irq); 10311031d839SEric Joyner device_printf(iflib_get_dev(ctx), 103277c1fcecSEric Joyner "Failed to register Admin Que handler"); 10331031d839SEric Joyner return (err); 10341031d839SEric Joyner } 103577c1fcecSEric Joyner /* Create soft IRQ for handling VFLRs */ 1036af06fa26SEric Joyner iflib_softirq_alloc_generic(ctx, NULL, IFLIB_INTR_IOV, pf, 0, "iov"); 10371031d839SEric Joyner 10381031d839SEric Joyner /* Now set up the stations */ 103977c1fcecSEric Joyner for (i = 0, vector = 1; i < vsi->shared->isc_nrxqsets; i++, vector++, rx_que++) { 10401031d839SEric Joyner rid = vector + 1; 10411031d839SEric Joyner 10421031d839SEric Joyner snprintf(buf, sizeof(buf), "rxq%d", i); 10431031d839SEric Joyner err = iflib_irq_alloc_generic(ctx, &rx_que->que_irq, rid, 10441031d839SEric Joyner IFLIB_INTR_RX, ixl_msix_que, rx_que, rx_que->rxr.me, buf); 10451031d839SEric Joyner /* XXX: Does the driver work as expected if there are fewer num_rx_queues than 10461031d839SEric Joyner * what's expected in the iflib context? */ 10471031d839SEric Joyner if (err) { 10481031d839SEric Joyner device_printf(iflib_get_dev(ctx), 104977c1fcecSEric Joyner "Failed to allocate queue RX int vector %d, err: %d\n", i, err); 10501031d839SEric Joyner vsi->num_rx_queues = i + 1; 10511031d839SEric Joyner goto fail; 10521031d839SEric Joyner } 10531031d839SEric Joyner rx_que->msix = vector; 10541031d839SEric Joyner } 10551031d839SEric Joyner 10561031d839SEric Joyner bzero(buf, sizeof(buf)); 10571031d839SEric Joyner 105877c1fcecSEric Joyner for (i = 0; i < vsi->shared->isc_ntxqsets; i++, tx_que++) { 10591031d839SEric Joyner snprintf(buf, sizeof(buf), "txq%d", i); 10601031d839SEric Joyner iflib_softirq_alloc_generic(ctx, 106177c1fcecSEric Joyner &vsi->rx_queues[i % vsi->shared->isc_nrxqsets].que_irq, 10621031d839SEric Joyner IFLIB_INTR_TX, tx_que, tx_que->txr.me, buf); 10631031d839SEric Joyner 10641031d839SEric Joyner /* TODO: Maybe call a strategy function for this to figure out which 10651031d839SEric Joyner * interrupts to map Tx queues to. I don't know if there's an immediately 10661031d839SEric Joyner * better way than this other than a user-supplied map, though. */ 106777c1fcecSEric Joyner tx_que->msix = (i % vsi->shared->isc_nrxqsets) + 1; 10681031d839SEric Joyner } 10691031d839SEric Joyner 10701031d839SEric Joyner return (0); 10711031d839SEric Joyner fail: 10721031d839SEric Joyner iflib_irq_free(ctx, &vsi->irq); 10731031d839SEric Joyner rx_que = vsi->rx_queues; 10741031d839SEric Joyner for (int i = 0; i < vsi->num_rx_queues; i++, rx_que++) 10751031d839SEric Joyner iflib_irq_free(ctx, &rx_que->que_irq); 10761031d839SEric Joyner return (err); 10771031d839SEric Joyner } 10781031d839SEric Joyner 10791031d839SEric Joyner /* 10801031d839SEric Joyner * Enable all interrupts 10811031d839SEric Joyner * 10821031d839SEric Joyner * Called in: 10831031d839SEric Joyner * iflib_init_locked, after ixl_if_init() 10841031d839SEric Joyner */ 10851031d839SEric Joyner static void 10861031d839SEric Joyner ixl_if_enable_intr(if_ctx_t ctx) 10871031d839SEric Joyner { 10881031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 10891031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 10901031d839SEric Joyner struct i40e_hw *hw = vsi->hw; 10911031d839SEric Joyner struct ixl_rx_queue *que = vsi->rx_queues; 10921031d839SEric Joyner 10931031d839SEric Joyner ixl_enable_intr0(hw); 10941031d839SEric Joyner /* Enable queue interrupts */ 10951031d839SEric Joyner for (int i = 0; i < vsi->num_rx_queues; i++, que++) 10961031d839SEric Joyner /* TODO: Queue index parameter is probably wrong */ 10971031d839SEric Joyner ixl_enable_queue(hw, que->rxr.me); 10981031d839SEric Joyner } 10991031d839SEric Joyner 11001031d839SEric Joyner /* 11011031d839SEric Joyner * Disable queue interrupts 11021031d839SEric Joyner * 11031031d839SEric Joyner * Other interrupt causes need to remain active. 11041031d839SEric Joyner */ 11051031d839SEric Joyner static void 11061031d839SEric Joyner ixl_if_disable_intr(if_ctx_t ctx) 11071031d839SEric Joyner { 11081031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 11091031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 11101031d839SEric Joyner struct i40e_hw *hw = vsi->hw; 11111031d839SEric Joyner struct ixl_rx_queue *rx_que = vsi->rx_queues; 11121031d839SEric Joyner 11131031d839SEric Joyner if (vsi->shared->isc_intr == IFLIB_INTR_MSIX) { 11141031d839SEric Joyner for (int i = 0; i < vsi->num_rx_queues; i++, rx_que++) 11151031d839SEric Joyner ixl_disable_queue(hw, rx_que->msix - 1); 11161031d839SEric Joyner } else { 11171031d839SEric Joyner // Set PFINT_LNKLST0 FIRSTQ_INDX to 0x7FF 11181031d839SEric Joyner // stops queues from triggering interrupts 11191031d839SEric Joyner wr32(hw, I40E_PFINT_LNKLST0, 0x7FF); 11201031d839SEric Joyner } 11211031d839SEric Joyner } 11221031d839SEric Joyner 11231031d839SEric Joyner static int 11241031d839SEric Joyner ixl_if_rx_queue_intr_enable(if_ctx_t ctx, uint16_t rxqid) 11251031d839SEric Joyner { 11261031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 11271031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 11281031d839SEric Joyner struct i40e_hw *hw = vsi->hw; 11291031d839SEric Joyner struct ixl_rx_queue *rx_que = &vsi->rx_queues[rxqid]; 11301031d839SEric Joyner 11311031d839SEric Joyner ixl_enable_queue(hw, rx_que->msix - 1); 11321031d839SEric Joyner return (0); 11331031d839SEric Joyner } 11341031d839SEric Joyner 11351031d839SEric Joyner static int 11361031d839SEric Joyner ixl_if_tx_queue_intr_enable(if_ctx_t ctx, uint16_t txqid) 11371031d839SEric Joyner { 11381031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 11391031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 11401031d839SEric Joyner struct i40e_hw *hw = vsi->hw; 11411031d839SEric Joyner struct ixl_tx_queue *tx_que = &vsi->tx_queues[txqid]; 11421031d839SEric Joyner 11431031d839SEric Joyner ixl_enable_queue(hw, tx_que->msix - 1); 11441031d839SEric Joyner return (0); 11451031d839SEric Joyner } 11461031d839SEric Joyner 11471031d839SEric Joyner static int 11481031d839SEric Joyner ixl_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int ntxqs, int ntxqsets) 11491031d839SEric Joyner { 11501031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 11511031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 11521031d839SEric Joyner if_softc_ctx_t scctx = vsi->shared; 11531031d839SEric Joyner struct ixl_tx_queue *que; 11541031d839SEric Joyner int i, j, error = 0; 11551031d839SEric Joyner 115677c1fcecSEric Joyner MPASS(scctx->isc_ntxqsets > 0); 11571031d839SEric Joyner MPASS(ntxqs == 1); 115877c1fcecSEric Joyner MPASS(scctx->isc_ntxqsets == ntxqsets); 11591031d839SEric Joyner 11601031d839SEric Joyner /* Allocate queue structure memory */ 11611031d839SEric Joyner if (!(vsi->tx_queues = 11621031d839SEric Joyner (struct ixl_tx_queue *) malloc(sizeof(struct ixl_tx_queue) *ntxqsets, M_IXL, M_NOWAIT | M_ZERO))) { 11631031d839SEric Joyner device_printf(iflib_get_dev(ctx), "Unable to allocate TX ring memory\n"); 11641031d839SEric Joyner return (ENOMEM); 11651031d839SEric Joyner } 11661031d839SEric Joyner 11671031d839SEric Joyner for (i = 0, que = vsi->tx_queues; i < ntxqsets; i++, que++) { 11681031d839SEric Joyner struct tx_ring *txr = &que->txr; 11691031d839SEric Joyner 11701031d839SEric Joyner txr->me = i; 11711031d839SEric Joyner que->vsi = vsi; 11721031d839SEric Joyner 11731031d839SEric Joyner if (!vsi->enable_head_writeback) { 11741031d839SEric Joyner /* Allocate report status array */ 11751031d839SEric Joyner if (!(txr->tx_rsq = malloc(sizeof(qidx_t) * scctx->isc_ntxd[0], M_IXL, M_NOWAIT))) { 11761031d839SEric Joyner device_printf(iflib_get_dev(ctx), "failed to allocate tx_rsq memory\n"); 11771031d839SEric Joyner error = ENOMEM; 11781031d839SEric Joyner goto fail; 11791031d839SEric Joyner } 11801031d839SEric Joyner /* Init report status array */ 11811031d839SEric Joyner for (j = 0; j < scctx->isc_ntxd[0]; j++) 11821031d839SEric Joyner txr->tx_rsq[j] = QIDX_INVALID; 11831031d839SEric Joyner } 11841031d839SEric Joyner /* get the virtual and physical address of the hardware queues */ 11851031d839SEric Joyner txr->tail = I40E_QTX_TAIL(txr->me); 11861031d839SEric Joyner txr->tx_base = (struct i40e_tx_desc *)vaddrs[i * ntxqs]; 11871031d839SEric Joyner txr->tx_paddr = paddrs[i * ntxqs]; 11881031d839SEric Joyner txr->que = que; 11891031d839SEric Joyner } 11901031d839SEric Joyner 11911031d839SEric Joyner return (0); 11921031d839SEric Joyner fail: 11931031d839SEric Joyner ixl_if_queues_free(ctx); 11941031d839SEric Joyner return (error); 11951031d839SEric Joyner } 11961031d839SEric Joyner 11971031d839SEric Joyner static int 11981031d839SEric Joyner ixl_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int nrxqs, int nrxqsets) 11991031d839SEric Joyner { 12001031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 12011031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 12021031d839SEric Joyner struct ixl_rx_queue *que; 12031031d839SEric Joyner int i, error = 0; 12041031d839SEric Joyner 120577c1fcecSEric Joyner #ifdef INVARIANTS 120677c1fcecSEric Joyner if_softc_ctx_t scctx = vsi->shared; 120777c1fcecSEric Joyner MPASS(scctx->isc_nrxqsets > 0); 12081031d839SEric Joyner MPASS(nrxqs == 1); 120977c1fcecSEric Joyner MPASS(scctx->isc_nrxqsets == nrxqsets); 121077c1fcecSEric Joyner #endif 12111031d839SEric Joyner 12121031d839SEric Joyner /* Allocate queue structure memory */ 12131031d839SEric Joyner if (!(vsi->rx_queues = 12141031d839SEric Joyner (struct ixl_rx_queue *) malloc(sizeof(struct ixl_rx_queue) * 12151031d839SEric Joyner nrxqsets, M_IXL, M_NOWAIT | M_ZERO))) { 12161031d839SEric Joyner device_printf(iflib_get_dev(ctx), "Unable to allocate RX ring memory\n"); 12171031d839SEric Joyner error = ENOMEM; 12181031d839SEric Joyner goto fail; 12191031d839SEric Joyner } 12201031d839SEric Joyner 12211031d839SEric Joyner for (i = 0, que = vsi->rx_queues; i < nrxqsets; i++, que++) { 12221031d839SEric Joyner struct rx_ring *rxr = &que->rxr; 12231031d839SEric Joyner 12241031d839SEric Joyner rxr->me = i; 12251031d839SEric Joyner que->vsi = vsi; 12261031d839SEric Joyner 12271031d839SEric Joyner /* get the virtual and physical address of the hardware queues */ 12281031d839SEric Joyner rxr->tail = I40E_QRX_TAIL(rxr->me); 12291031d839SEric Joyner rxr->rx_base = (union i40e_rx_desc *)vaddrs[i * nrxqs]; 12301031d839SEric Joyner rxr->rx_paddr = paddrs[i * nrxqs]; 12311031d839SEric Joyner rxr->que = que; 12321031d839SEric Joyner } 12331031d839SEric Joyner 12341031d839SEric Joyner return (0); 12351031d839SEric Joyner fail: 12361031d839SEric Joyner ixl_if_queues_free(ctx); 12371031d839SEric Joyner return (error); 12381031d839SEric Joyner } 12391031d839SEric Joyner 12401031d839SEric Joyner static void 12411031d839SEric Joyner ixl_if_queues_free(if_ctx_t ctx) 12421031d839SEric Joyner { 12431031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 12441031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 12451031d839SEric Joyner 124677c1fcecSEric Joyner if (!vsi->enable_head_writeback) { 12471031d839SEric Joyner struct ixl_tx_queue *que; 12481031d839SEric Joyner int i = 0; 12491031d839SEric Joyner 12501031d839SEric Joyner for (i = 0, que = vsi->tx_queues; i < vsi->num_tx_queues; i++, que++) { 12511031d839SEric Joyner struct tx_ring *txr = &que->txr; 12521031d839SEric Joyner if (txr->tx_rsq != NULL) { 12531031d839SEric Joyner free(txr->tx_rsq, M_IXL); 12541031d839SEric Joyner txr->tx_rsq = NULL; 12551031d839SEric Joyner } 12561031d839SEric Joyner } 12571031d839SEric Joyner } 12581031d839SEric Joyner 12591031d839SEric Joyner if (vsi->tx_queues != NULL) { 12601031d839SEric Joyner free(vsi->tx_queues, M_IXL); 12611031d839SEric Joyner vsi->tx_queues = NULL; 12621031d839SEric Joyner } 12631031d839SEric Joyner if (vsi->rx_queues != NULL) { 12641031d839SEric Joyner free(vsi->rx_queues, M_IXL); 12651031d839SEric Joyner vsi->rx_queues = NULL; 12661031d839SEric Joyner } 1267*b4a7ce06SEric Joyner 1268*b4a7ce06SEric Joyner if (!IXL_PF_IN_RECOVERY_MODE(pf)) 1269*b4a7ce06SEric Joyner sysctl_ctx_free(&vsi->sysctl_ctx); 12701031d839SEric Joyner } 12711031d839SEric Joyner 12721031d839SEric Joyner void 12731031d839SEric Joyner ixl_update_link_status(struct ixl_pf *pf) 12741031d839SEric Joyner { 12751031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 1276c9da8d8bSEric Joyner struct i40e_hw *hw = &pf->hw; 12771031d839SEric Joyner u64 baudrate; 12781031d839SEric Joyner 12791031d839SEric Joyner if (pf->link_up) { 12801031d839SEric Joyner if (vsi->link_active == FALSE) { 12811031d839SEric Joyner vsi->link_active = TRUE; 1282c9da8d8bSEric Joyner baudrate = ixl_max_aq_speed_to_value(hw->phy.link_info.link_speed); 12831031d839SEric Joyner iflib_link_state_change(vsi->ctx, LINK_STATE_UP, baudrate); 12841031d839SEric Joyner ixl_link_up_msg(pf); 12851031d839SEric Joyner #ifdef PCI_IOV 12861031d839SEric Joyner ixl_broadcast_link_state(pf); 12871031d839SEric Joyner #endif 12881031d839SEric Joyner } 12891031d839SEric Joyner } else { /* Link down */ 12901031d839SEric Joyner if (vsi->link_active == TRUE) { 12911031d839SEric Joyner vsi->link_active = FALSE; 12921031d839SEric Joyner iflib_link_state_change(vsi->ctx, LINK_STATE_DOWN, 0); 12931031d839SEric Joyner #ifdef PCI_IOV 12941031d839SEric Joyner ixl_broadcast_link_state(pf); 12951031d839SEric Joyner #endif 12961031d839SEric Joyner } 12971031d839SEric Joyner } 12981031d839SEric Joyner } 12991031d839SEric Joyner 130077c1fcecSEric Joyner static void 130177c1fcecSEric Joyner ixl_handle_lan_overflow_event(struct ixl_pf *pf, struct i40e_arq_event_info *e) 130277c1fcecSEric Joyner { 130377c1fcecSEric Joyner device_t dev = pf->dev; 130477c1fcecSEric Joyner u32 rxq_idx, qtx_ctl; 130577c1fcecSEric Joyner 130677c1fcecSEric Joyner rxq_idx = (e->desc.params.external.param0 & I40E_PRTDCB_RUPTQ_RXQNUM_MASK) >> 130777c1fcecSEric Joyner I40E_PRTDCB_RUPTQ_RXQNUM_SHIFT; 130877c1fcecSEric Joyner qtx_ctl = e->desc.params.external.param1; 130977c1fcecSEric Joyner 131077c1fcecSEric Joyner device_printf(dev, "LAN overflow event: global rxq_idx %d\n", rxq_idx); 131177c1fcecSEric Joyner device_printf(dev, "LAN overflow event: QTX_CTL 0x%08x\n", qtx_ctl); 131277c1fcecSEric Joyner } 131377c1fcecSEric Joyner 13141031d839SEric Joyner static int 13151031d839SEric Joyner ixl_process_adminq(struct ixl_pf *pf, u16 *pending) 13161031d839SEric Joyner { 13171031d839SEric Joyner enum i40e_status_code status = I40E_SUCCESS; 13181031d839SEric Joyner struct i40e_arq_event_info event; 13191031d839SEric Joyner struct i40e_hw *hw = &pf->hw; 13201031d839SEric Joyner device_t dev = pf->dev; 13211031d839SEric Joyner u16 opcode; 13221031d839SEric Joyner u32 loop = 0, reg; 13231031d839SEric Joyner 13241031d839SEric Joyner event.buf_len = IXL_AQ_BUF_SZ; 13251031d839SEric Joyner event.msg_buf = malloc(event.buf_len, M_IXL, M_NOWAIT | M_ZERO); 13261031d839SEric Joyner if (!event.msg_buf) { 13271031d839SEric Joyner device_printf(dev, "%s: Unable to allocate memory for Admin" 13281031d839SEric Joyner " Queue event!\n", __func__); 13291031d839SEric Joyner return (ENOMEM); 13301031d839SEric Joyner } 13311031d839SEric Joyner 13321031d839SEric Joyner /* clean and process any events */ 13331031d839SEric Joyner do { 13341031d839SEric Joyner status = i40e_clean_arq_element(hw, &event, pending); 13351031d839SEric Joyner if (status) 13361031d839SEric Joyner break; 13371031d839SEric Joyner opcode = LE16_TO_CPU(event.desc.opcode); 13381031d839SEric Joyner ixl_dbg(pf, IXL_DBG_AQ, 13391031d839SEric Joyner "Admin Queue event: %#06x\n", opcode); 13401031d839SEric Joyner switch (opcode) { 13411031d839SEric Joyner case i40e_aqc_opc_get_link_status: 13421031d839SEric Joyner ixl_link_event(pf, &event); 13431031d839SEric Joyner break; 13441031d839SEric Joyner case i40e_aqc_opc_send_msg_to_pf: 13451031d839SEric Joyner #ifdef PCI_IOV 13461031d839SEric Joyner ixl_handle_vf_msg(pf, &event); 13471031d839SEric Joyner #endif 13481031d839SEric Joyner break; 13491031d839SEric Joyner /* 13501031d839SEric Joyner * This should only occur on no-drop queues, which 13511031d839SEric Joyner * aren't currently configured. 13521031d839SEric Joyner */ 13531031d839SEric Joyner case i40e_aqc_opc_event_lan_overflow: 135477c1fcecSEric Joyner ixl_handle_lan_overflow_event(pf, &event); 13551031d839SEric Joyner break; 13561031d839SEric Joyner default: 13571031d839SEric Joyner break; 13581031d839SEric Joyner } 13591031d839SEric Joyner } while (*pending && (loop++ < IXL_ADM_LIMIT)); 13601031d839SEric Joyner 13611031d839SEric Joyner free(event.msg_buf, M_IXL); 13621031d839SEric Joyner 13631031d839SEric Joyner /* Re-enable admin queue interrupt cause */ 13641031d839SEric Joyner reg = rd32(hw, I40E_PFINT_ICR0_ENA); 13651031d839SEric Joyner reg |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; 13661031d839SEric Joyner wr32(hw, I40E_PFINT_ICR0_ENA, reg); 13671031d839SEric Joyner 13681031d839SEric Joyner return (status); 13691031d839SEric Joyner } 13701031d839SEric Joyner 13711031d839SEric Joyner static void 13721031d839SEric Joyner ixl_if_update_admin_status(if_ctx_t ctx) 13731031d839SEric Joyner { 13741031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 13751031d839SEric Joyner struct i40e_hw *hw = &pf->hw; 13761031d839SEric Joyner u16 pending; 13771031d839SEric Joyner 13781031d839SEric Joyner if (pf->state & IXL_PF_STATE_ADAPTER_RESETTING) 13791031d839SEric Joyner ixl_handle_empr_reset(pf); 13801031d839SEric Joyner 1381*b4a7ce06SEric Joyner /* 1382*b4a7ce06SEric Joyner * Admin Queue is shut down while handling reset. 1383*b4a7ce06SEric Joyner * Don't proceed if it hasn't been re-initialized 1384*b4a7ce06SEric Joyner * e.g due to an issue with new FW. 1385*b4a7ce06SEric Joyner */ 1386*b4a7ce06SEric Joyner if (!i40e_check_asq_alive(&pf->hw)) 1387*b4a7ce06SEric Joyner return; 1388*b4a7ce06SEric Joyner 13891031d839SEric Joyner if (pf->state & IXL_PF_STATE_MDD_PENDING) 13901031d839SEric Joyner ixl_handle_mdd_event(pf); 13911031d839SEric Joyner 13921031d839SEric Joyner ixl_process_adminq(pf, &pending); 13931031d839SEric Joyner ixl_update_link_status(pf); 13941031d839SEric Joyner 13951031d839SEric Joyner /* 13961031d839SEric Joyner * If there are still messages to process, reschedule ourselves. 13971031d839SEric Joyner * Otherwise, re-enable our interrupt and go to sleep. 13981031d839SEric Joyner */ 13991031d839SEric Joyner if (pending > 0) 14001031d839SEric Joyner iflib_admin_intr_deferred(ctx); 14011031d839SEric Joyner else 14021031d839SEric Joyner ixl_enable_intr0(hw); 14031031d839SEric Joyner } 14041031d839SEric Joyner 14051031d839SEric Joyner static void 14061031d839SEric Joyner ixl_if_multi_set(if_ctx_t ctx) 14071031d839SEric Joyner { 14081031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 14091031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 14101031d839SEric Joyner struct i40e_hw *hw = vsi->hw; 1411ba76aa63SGleb Smirnoff int mcnt, flags; 141277c1fcecSEric Joyner int del_mcnt; 14131031d839SEric Joyner 14141031d839SEric Joyner IOCTL_DEBUGOUT("ixl_if_multi_set: begin"); 14151031d839SEric Joyner 1416ba76aa63SGleb Smirnoff mcnt = min(if_llmaddr_count(iflib_get_ifp(ctx)), MAX_MULTICAST_ADDR); 141777c1fcecSEric Joyner /* Delete filters for removed multicast addresses */ 141877c1fcecSEric Joyner del_mcnt = ixl_del_multi(vsi); 141977c1fcecSEric Joyner vsi->num_macs -= del_mcnt; 14201031d839SEric Joyner 14211031d839SEric Joyner if (__predict_false(mcnt == MAX_MULTICAST_ADDR)) { 14221031d839SEric Joyner i40e_aq_set_vsi_multicast_promiscuous(hw, 14231031d839SEric Joyner vsi->seid, TRUE, NULL); 14241031d839SEric Joyner return; 14251031d839SEric Joyner } 14261031d839SEric Joyner /* (re-)install filters for all mcast addresses */ 142777c1fcecSEric Joyner /* XXX: This bypasses filter count tracking code! */ 1428ba76aa63SGleb Smirnoff mcnt = if_foreach_llmaddr(iflib_get_ifp(ctx), ixl_mc_filter_apply, vsi); 14291031d839SEric Joyner if (mcnt > 0) { 143077c1fcecSEric Joyner vsi->num_macs += mcnt; 14311031d839SEric Joyner flags = (IXL_FILTER_ADD | IXL_FILTER_USED | IXL_FILTER_MC); 14321031d839SEric Joyner ixl_add_hw_filters(vsi, flags, mcnt); 14331031d839SEric Joyner } 14341031d839SEric Joyner 143577c1fcecSEric Joyner ixl_dbg_filter(pf, "%s: filter mac total: %d\n", 143677c1fcecSEric Joyner __func__, vsi->num_macs); 14371031d839SEric Joyner IOCTL_DEBUGOUT("ixl_if_multi_set: end"); 14381031d839SEric Joyner } 14391031d839SEric Joyner 14401031d839SEric Joyner static int 14411031d839SEric Joyner ixl_if_mtu_set(if_ctx_t ctx, uint32_t mtu) 14421031d839SEric Joyner { 14431031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 14441031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 14451031d839SEric Joyner 14461031d839SEric Joyner IOCTL_DEBUGOUT("ioctl: SIOCSIFMTU (Set Interface MTU)"); 14471031d839SEric Joyner if (mtu > IXL_MAX_FRAME - ETHER_HDR_LEN - ETHER_CRC_LEN - 14481031d839SEric Joyner ETHER_VLAN_ENCAP_LEN) 14491031d839SEric Joyner return (EINVAL); 14501031d839SEric Joyner 14511031d839SEric Joyner vsi->shared->isc_max_frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN + 14521031d839SEric Joyner ETHER_VLAN_ENCAP_LEN; 14531031d839SEric Joyner 14541031d839SEric Joyner return (0); 14551031d839SEric Joyner } 14561031d839SEric Joyner 14571031d839SEric Joyner static void 14581031d839SEric Joyner ixl_if_media_status(if_ctx_t ctx, struct ifmediareq *ifmr) 14591031d839SEric Joyner { 14601031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 14611031d839SEric Joyner struct i40e_hw *hw = &pf->hw; 14621031d839SEric Joyner 14631031d839SEric Joyner INIT_DEBUGOUT("ixl_media_status: begin"); 14641031d839SEric Joyner 14651031d839SEric Joyner ifmr->ifm_status = IFM_AVALID; 14661031d839SEric Joyner ifmr->ifm_active = IFM_ETHER; 14671031d839SEric Joyner 14681031d839SEric Joyner if (!pf->link_up) { 14691031d839SEric Joyner return; 14701031d839SEric Joyner } 14711031d839SEric Joyner 14721031d839SEric Joyner ifmr->ifm_status |= IFM_ACTIVE; 14731031d839SEric Joyner /* Hardware is always full-duplex */ 14741031d839SEric Joyner ifmr->ifm_active |= IFM_FDX; 14751031d839SEric Joyner 14761031d839SEric Joyner switch (hw->phy.link_info.phy_type) { 14771031d839SEric Joyner /* 100 M */ 14781031d839SEric Joyner case I40E_PHY_TYPE_100BASE_TX: 14791031d839SEric Joyner ifmr->ifm_active |= IFM_100_TX; 14801031d839SEric Joyner break; 14811031d839SEric Joyner /* 1 G */ 14821031d839SEric Joyner case I40E_PHY_TYPE_1000BASE_T: 14831031d839SEric Joyner ifmr->ifm_active |= IFM_1000_T; 14841031d839SEric Joyner break; 14851031d839SEric Joyner case I40E_PHY_TYPE_1000BASE_SX: 14861031d839SEric Joyner ifmr->ifm_active |= IFM_1000_SX; 14871031d839SEric Joyner break; 14881031d839SEric Joyner case I40E_PHY_TYPE_1000BASE_LX: 14891031d839SEric Joyner ifmr->ifm_active |= IFM_1000_LX; 14901031d839SEric Joyner break; 14911031d839SEric Joyner case I40E_PHY_TYPE_1000BASE_T_OPTICAL: 14921031d839SEric Joyner ifmr->ifm_active |= IFM_1000_T; 14931031d839SEric Joyner break; 14941031d839SEric Joyner /* 10 G */ 14951031d839SEric Joyner case I40E_PHY_TYPE_10GBASE_SFPP_CU: 14961031d839SEric Joyner ifmr->ifm_active |= IFM_10G_TWINAX; 14971031d839SEric Joyner break; 14981031d839SEric Joyner case I40E_PHY_TYPE_10GBASE_SR: 14991031d839SEric Joyner ifmr->ifm_active |= IFM_10G_SR; 15001031d839SEric Joyner break; 15011031d839SEric Joyner case I40E_PHY_TYPE_10GBASE_LR: 15021031d839SEric Joyner ifmr->ifm_active |= IFM_10G_LR; 15031031d839SEric Joyner break; 15041031d839SEric Joyner case I40E_PHY_TYPE_10GBASE_T: 15051031d839SEric Joyner ifmr->ifm_active |= IFM_10G_T; 15061031d839SEric Joyner break; 15071031d839SEric Joyner case I40E_PHY_TYPE_XAUI: 15081031d839SEric Joyner case I40E_PHY_TYPE_XFI: 15091031d839SEric Joyner ifmr->ifm_active |= IFM_10G_TWINAX; 15101031d839SEric Joyner break; 15111031d839SEric Joyner case I40E_PHY_TYPE_10GBASE_AOC: 15121031d839SEric Joyner ifmr->ifm_active |= IFM_10G_AOC; 15131031d839SEric Joyner break; 15141031d839SEric Joyner /* 25 G */ 15151031d839SEric Joyner case I40E_PHY_TYPE_25GBASE_KR: 15161031d839SEric Joyner ifmr->ifm_active |= IFM_25G_KR; 15171031d839SEric Joyner break; 15181031d839SEric Joyner case I40E_PHY_TYPE_25GBASE_CR: 15191031d839SEric Joyner ifmr->ifm_active |= IFM_25G_CR; 15201031d839SEric Joyner break; 15211031d839SEric Joyner case I40E_PHY_TYPE_25GBASE_SR: 15221031d839SEric Joyner ifmr->ifm_active |= IFM_25G_SR; 15231031d839SEric Joyner break; 15241031d839SEric Joyner case I40E_PHY_TYPE_25GBASE_LR: 15251031d839SEric Joyner ifmr->ifm_active |= IFM_25G_LR; 15261031d839SEric Joyner break; 15271031d839SEric Joyner case I40E_PHY_TYPE_25GBASE_AOC: 15281031d839SEric Joyner ifmr->ifm_active |= IFM_25G_AOC; 15291031d839SEric Joyner break; 15301031d839SEric Joyner case I40E_PHY_TYPE_25GBASE_ACC: 15311031d839SEric Joyner ifmr->ifm_active |= IFM_25G_ACC; 15321031d839SEric Joyner break; 15331031d839SEric Joyner /* 40 G */ 15341031d839SEric Joyner case I40E_PHY_TYPE_40GBASE_CR4: 15351031d839SEric Joyner case I40E_PHY_TYPE_40GBASE_CR4_CU: 15361031d839SEric Joyner ifmr->ifm_active |= IFM_40G_CR4; 15371031d839SEric Joyner break; 15381031d839SEric Joyner case I40E_PHY_TYPE_40GBASE_SR4: 15391031d839SEric Joyner ifmr->ifm_active |= IFM_40G_SR4; 15401031d839SEric Joyner break; 15411031d839SEric Joyner case I40E_PHY_TYPE_40GBASE_LR4: 15421031d839SEric Joyner ifmr->ifm_active |= IFM_40G_LR4; 15431031d839SEric Joyner break; 15441031d839SEric Joyner case I40E_PHY_TYPE_XLAUI: 15451031d839SEric Joyner ifmr->ifm_active |= IFM_OTHER; 15461031d839SEric Joyner break; 15471031d839SEric Joyner case I40E_PHY_TYPE_1000BASE_KX: 15481031d839SEric Joyner ifmr->ifm_active |= IFM_1000_KX; 15491031d839SEric Joyner break; 15501031d839SEric Joyner case I40E_PHY_TYPE_SGMII: 15511031d839SEric Joyner ifmr->ifm_active |= IFM_1000_SGMII; 15521031d839SEric Joyner break; 15531031d839SEric Joyner /* ERJ: What's the difference between these? */ 15541031d839SEric Joyner case I40E_PHY_TYPE_10GBASE_CR1_CU: 15551031d839SEric Joyner case I40E_PHY_TYPE_10GBASE_CR1: 15561031d839SEric Joyner ifmr->ifm_active |= IFM_10G_CR1; 15571031d839SEric Joyner break; 15581031d839SEric Joyner case I40E_PHY_TYPE_10GBASE_KX4: 15591031d839SEric Joyner ifmr->ifm_active |= IFM_10G_KX4; 15601031d839SEric Joyner break; 15611031d839SEric Joyner case I40E_PHY_TYPE_10GBASE_KR: 15621031d839SEric Joyner ifmr->ifm_active |= IFM_10G_KR; 15631031d839SEric Joyner break; 15641031d839SEric Joyner case I40E_PHY_TYPE_SFI: 15651031d839SEric Joyner ifmr->ifm_active |= IFM_10G_SFI; 15661031d839SEric Joyner break; 15671031d839SEric Joyner /* Our single 20G media type */ 15681031d839SEric Joyner case I40E_PHY_TYPE_20GBASE_KR2: 15691031d839SEric Joyner ifmr->ifm_active |= IFM_20G_KR2; 15701031d839SEric Joyner break; 15711031d839SEric Joyner case I40E_PHY_TYPE_40GBASE_KR4: 15721031d839SEric Joyner ifmr->ifm_active |= IFM_40G_KR4; 15731031d839SEric Joyner break; 15741031d839SEric Joyner case I40E_PHY_TYPE_XLPPI: 15751031d839SEric Joyner case I40E_PHY_TYPE_40GBASE_AOC: 15761031d839SEric Joyner ifmr->ifm_active |= IFM_40G_XLPPI; 15771031d839SEric Joyner break; 15781031d839SEric Joyner /* Unknown to driver */ 15791031d839SEric Joyner default: 15801031d839SEric Joyner ifmr->ifm_active |= IFM_UNKNOWN; 15811031d839SEric Joyner break; 15821031d839SEric Joyner } 15831031d839SEric Joyner /* Report flow control status as well */ 15841031d839SEric Joyner if (hw->phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) 15851031d839SEric Joyner ifmr->ifm_active |= IFM_ETH_TXPAUSE; 15861031d839SEric Joyner if (hw->phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX) 15871031d839SEric Joyner ifmr->ifm_active |= IFM_ETH_RXPAUSE; 15881031d839SEric Joyner } 15891031d839SEric Joyner 15901031d839SEric Joyner static int 15911031d839SEric Joyner ixl_if_media_change(if_ctx_t ctx) 15921031d839SEric Joyner { 15931031d839SEric Joyner struct ifmedia *ifm = iflib_get_media(ctx); 15941031d839SEric Joyner 15951031d839SEric Joyner INIT_DEBUGOUT("ixl_media_change: begin"); 15961031d839SEric Joyner 15971031d839SEric Joyner if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) 15981031d839SEric Joyner return (EINVAL); 15991031d839SEric Joyner 16001031d839SEric Joyner if_printf(iflib_get_ifp(ctx), "Media change is not supported.\n"); 16011031d839SEric Joyner return (ENODEV); 16021031d839SEric Joyner } 16031031d839SEric Joyner 16041031d839SEric Joyner static int 16051031d839SEric Joyner ixl_if_promisc_set(if_ctx_t ctx, int flags) 16061031d839SEric Joyner { 16071031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 16081031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 16091031d839SEric Joyner struct ifnet *ifp = iflib_get_ifp(ctx); 16101031d839SEric Joyner struct i40e_hw *hw = vsi->hw; 16111031d839SEric Joyner int err; 16121031d839SEric Joyner bool uni = FALSE, multi = FALSE; 16131031d839SEric Joyner 16141031d839SEric Joyner if (flags & IFF_PROMISC) 16151031d839SEric Joyner uni = multi = TRUE; 1616ba76aa63SGleb Smirnoff else if (flags & IFF_ALLMULTI || if_llmaddr_count(ifp) >= 1617ba76aa63SGleb Smirnoff MAX_MULTICAST_ADDR) 16181031d839SEric Joyner multi = TRUE; 16191031d839SEric Joyner 16201031d839SEric Joyner err = i40e_aq_set_vsi_unicast_promiscuous(hw, 16211031d839SEric Joyner vsi->seid, uni, NULL, true); 16221031d839SEric Joyner if (err) 16231031d839SEric Joyner return (err); 16241031d839SEric Joyner err = i40e_aq_set_vsi_multicast_promiscuous(hw, 16251031d839SEric Joyner vsi->seid, multi, NULL); 16261031d839SEric Joyner return (err); 16271031d839SEric Joyner } 16281031d839SEric Joyner 16291031d839SEric Joyner static void 16301031d839SEric Joyner ixl_if_timer(if_ctx_t ctx, uint16_t qid) 16311031d839SEric Joyner { 1632*b4a7ce06SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 1633*b4a7ce06SEric Joyner 16341031d839SEric Joyner if (qid != 0) 16351031d839SEric Joyner return; 16361031d839SEric Joyner 1637*b4a7ce06SEric Joyner ixl_update_stats_counters(pf); 16381031d839SEric Joyner } 16391031d839SEric Joyner 16401031d839SEric Joyner static void 16411031d839SEric Joyner ixl_if_vlan_register(if_ctx_t ctx, u16 vtag) 16421031d839SEric Joyner { 16431031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 16441031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 16451031d839SEric Joyner struct i40e_hw *hw = vsi->hw; 16461031d839SEric Joyner 16471031d839SEric Joyner if ((vtag == 0) || (vtag > 4095)) /* Invalid */ 16481031d839SEric Joyner return; 16491031d839SEric Joyner 16501031d839SEric Joyner ++vsi->num_vlans; 16511031d839SEric Joyner ixl_add_filter(vsi, hw->mac.addr, vtag); 16521031d839SEric Joyner } 16531031d839SEric Joyner 16541031d839SEric Joyner static void 16551031d839SEric Joyner ixl_if_vlan_unregister(if_ctx_t ctx, u16 vtag) 16561031d839SEric Joyner { 16571031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 16581031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 16591031d839SEric Joyner struct i40e_hw *hw = vsi->hw; 16601031d839SEric Joyner 16611031d839SEric Joyner if ((vtag == 0) || (vtag > 4095)) /* Invalid */ 16621031d839SEric Joyner return; 16631031d839SEric Joyner 16641031d839SEric Joyner --vsi->num_vlans; 16651031d839SEric Joyner ixl_del_filter(vsi, hw->mac.addr, vtag); 16661031d839SEric Joyner } 16671031d839SEric Joyner 16681031d839SEric Joyner static uint64_t 16691031d839SEric Joyner ixl_if_get_counter(if_ctx_t ctx, ift_counter cnt) 16701031d839SEric Joyner { 16711031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 16721031d839SEric Joyner struct ixl_vsi *vsi = &pf->vsi; 16731031d839SEric Joyner if_t ifp = iflib_get_ifp(ctx); 16741031d839SEric Joyner 16751031d839SEric Joyner switch (cnt) { 16761031d839SEric Joyner case IFCOUNTER_IPACKETS: 16771031d839SEric Joyner return (vsi->ipackets); 16781031d839SEric Joyner case IFCOUNTER_IERRORS: 16791031d839SEric Joyner return (vsi->ierrors); 16801031d839SEric Joyner case IFCOUNTER_OPACKETS: 16811031d839SEric Joyner return (vsi->opackets); 16821031d839SEric Joyner case IFCOUNTER_OERRORS: 16831031d839SEric Joyner return (vsi->oerrors); 16841031d839SEric Joyner case IFCOUNTER_COLLISIONS: 16851031d839SEric Joyner /* Collisions are by standard impossible in 40G/10G Ethernet */ 16861031d839SEric Joyner return (0); 16871031d839SEric Joyner case IFCOUNTER_IBYTES: 16881031d839SEric Joyner return (vsi->ibytes); 16891031d839SEric Joyner case IFCOUNTER_OBYTES: 16901031d839SEric Joyner return (vsi->obytes); 16911031d839SEric Joyner case IFCOUNTER_IMCASTS: 16921031d839SEric Joyner return (vsi->imcasts); 16931031d839SEric Joyner case IFCOUNTER_OMCASTS: 16941031d839SEric Joyner return (vsi->omcasts); 16951031d839SEric Joyner case IFCOUNTER_IQDROPS: 16961031d839SEric Joyner return (vsi->iqdrops); 16971031d839SEric Joyner case IFCOUNTER_OQDROPS: 16981031d839SEric Joyner return (vsi->oqdrops); 16991031d839SEric Joyner case IFCOUNTER_NOPROTO: 17001031d839SEric Joyner return (vsi->noproto); 17011031d839SEric Joyner default: 17021031d839SEric Joyner return (if_get_counter_default(ifp, cnt)); 17031031d839SEric Joyner } 17041031d839SEric Joyner } 17051031d839SEric Joyner 170677c1fcecSEric Joyner #ifdef PCI_IOV 17071031d839SEric Joyner static void 17081031d839SEric Joyner ixl_if_vflr_handle(if_ctx_t ctx) 17091031d839SEric Joyner { 171077c1fcecSEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 17111031d839SEric Joyner 171277c1fcecSEric Joyner ixl_handle_vflr(pf); 17131031d839SEric Joyner } 171477c1fcecSEric Joyner #endif 17151031d839SEric Joyner 17161031d839SEric Joyner static int 17171031d839SEric Joyner ixl_if_i2c_req(if_ctx_t ctx, struct ifi2creq *req) 17181031d839SEric Joyner { 17191031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 17201031d839SEric Joyner 17211031d839SEric Joyner if (pf->read_i2c_byte == NULL) 17221031d839SEric Joyner return (EINVAL); 17231031d839SEric Joyner 17241031d839SEric Joyner for (int i = 0; i < req->len; i++) 17251031d839SEric Joyner if (pf->read_i2c_byte(pf, req->offset + i, 17261031d839SEric Joyner req->dev_addr, &req->data[i])) 17271031d839SEric Joyner return (EIO); 17281031d839SEric Joyner return (0); 17291031d839SEric Joyner } 17301031d839SEric Joyner 17311031d839SEric Joyner static int 17321031d839SEric Joyner ixl_if_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t data) 17331031d839SEric Joyner { 17341031d839SEric Joyner struct ixl_pf *pf = iflib_get_softc(ctx); 17351031d839SEric Joyner struct ifdrv *ifd = (struct ifdrv *)data; 17361031d839SEric Joyner int error = 0; 17371031d839SEric Joyner 1738ab43ce7aSEric Joyner /* 1739ab43ce7aSEric Joyner * The iflib_if_ioctl forwards SIOCxDRVSPEC and SIOGPRIVATE_0 without 1740ab43ce7aSEric Joyner * performing privilege checks. It is important that this function 1741ab43ce7aSEric Joyner * perform the necessary checks for commands which should only be 1742ab43ce7aSEric Joyner * executed by privileged threads. 1743ab43ce7aSEric Joyner */ 1744ab43ce7aSEric Joyner 1745ab43ce7aSEric Joyner switch(command) { 1746ab43ce7aSEric Joyner case SIOCGDRVSPEC: 1747ab43ce7aSEric Joyner case SIOCSDRVSPEC: 17481031d839SEric Joyner /* NVM update command */ 1749ab43ce7aSEric Joyner if (ifd->ifd_cmd == I40E_NVM_ACCESS) { 1750ab43ce7aSEric Joyner error = priv_check(curthread, PRIV_DRIVER); 1751ab43ce7aSEric Joyner if (error) 1752ab43ce7aSEric Joyner break; 17531031d839SEric Joyner error = ixl_handle_nvmupd_cmd(pf, ifd); 1754ab43ce7aSEric Joyner } else { 17551031d839SEric Joyner error = EINVAL; 1756ab43ce7aSEric Joyner } 1757ab43ce7aSEric Joyner break; 1758ab43ce7aSEric Joyner default: 1759ab43ce7aSEric Joyner error = EOPNOTSUPP; 1760ab43ce7aSEric Joyner } 17611031d839SEric Joyner 17621031d839SEric Joyner return (error); 17631031d839SEric Joyner } 17641031d839SEric Joyner 1765cf150917SEric Joyner /* ixl_if_needs_restart - Tell iflib when the driver needs to be reinitialized 1766cf150917SEric Joyner * @ctx: iflib context 1767cf150917SEric Joyner * @event: event code to check 1768cf150917SEric Joyner * 1769cf150917SEric Joyner * Defaults to returning false for every event. 1770cf150917SEric Joyner * 1771cf150917SEric Joyner * @returns true if iflib needs to reinit the interface, false otherwise 1772cf150917SEric Joyner */ 1773cf150917SEric Joyner static bool 1774cf150917SEric Joyner ixl_if_needs_restart(if_ctx_t ctx __unused, enum iflib_restart_event event) 1775cf150917SEric Joyner { 1776cf150917SEric Joyner switch (event) { 1777cf150917SEric Joyner case IFLIB_RESTART_VLAN_CONFIG: 1778cf150917SEric Joyner default: 1779cf150917SEric Joyner return (false); 1780cf150917SEric Joyner } 1781cf150917SEric Joyner } 1782cf150917SEric Joyner 1783ba76aa63SGleb Smirnoff static u_int 1784ba76aa63SGleb Smirnoff ixl_mc_filter_apply(void *arg, struct sockaddr_dl *sdl, u_int count __unused) 17851031d839SEric Joyner { 17861031d839SEric Joyner struct ixl_vsi *vsi = arg; 17871031d839SEric Joyner 1788ba76aa63SGleb Smirnoff ixl_add_mc_filter(vsi, (u8*)LLADDR(sdl)); 17891031d839SEric Joyner return (1); 17901031d839SEric Joyner } 17911031d839SEric Joyner 17921031d839SEric Joyner /* 17931031d839SEric Joyner * Sanity check and save off tunable values. 17941031d839SEric Joyner */ 17951031d839SEric Joyner static void 17961031d839SEric Joyner ixl_save_pf_tunables(struct ixl_pf *pf) 17971031d839SEric Joyner { 17981031d839SEric Joyner device_t dev = pf->dev; 17991031d839SEric Joyner 18001031d839SEric Joyner /* Save tunable information */ 1801*b4a7ce06SEric Joyner #ifdef IXL_DEBUG_FC 18021031d839SEric Joyner pf->enable_tx_fc_filter = ixl_enable_tx_fc_filter; 1803*b4a7ce06SEric Joyner #endif 1804*b4a7ce06SEric Joyner #ifdef IXL_DEBUG 1805*b4a7ce06SEric Joyner pf->recovery_mode = ixl_debug_recovery_mode; 1806*b4a7ce06SEric Joyner #endif 18071031d839SEric Joyner pf->dbg_mask = ixl_core_debug_mask; 18081031d839SEric Joyner pf->hw.debug_mask = ixl_shared_debug_mask; 18091031d839SEric Joyner pf->vsi.enable_head_writeback = !!(ixl_enable_head_writeback); 181077c1fcecSEric Joyner pf->enable_vf_loopback = !!(ixl_enable_vf_loopback); 18111031d839SEric Joyner #if 0 18121031d839SEric Joyner pf->dynamic_rx_itr = ixl_dynamic_rx_itr; 18131031d839SEric Joyner pf->dynamic_tx_itr = ixl_dynamic_tx_itr; 18141031d839SEric Joyner #endif 18151031d839SEric Joyner 18161031d839SEric Joyner if (ixl_i2c_access_method > 3 || ixl_i2c_access_method < 0) 18171031d839SEric Joyner pf->i2c_access_method = 0; 18181031d839SEric Joyner else 18191031d839SEric Joyner pf->i2c_access_method = ixl_i2c_access_method; 18201031d839SEric Joyner 18211031d839SEric Joyner if (ixl_tx_itr < 0 || ixl_tx_itr > IXL_MAX_ITR) { 18221031d839SEric Joyner device_printf(dev, "Invalid tx_itr value of %d set!\n", 18231031d839SEric Joyner ixl_tx_itr); 18241031d839SEric Joyner device_printf(dev, "tx_itr must be between %d and %d, " 18251031d839SEric Joyner "inclusive\n", 18261031d839SEric Joyner 0, IXL_MAX_ITR); 18271031d839SEric Joyner device_printf(dev, "Using default value of %d instead\n", 18281031d839SEric Joyner IXL_ITR_4K); 18291031d839SEric Joyner pf->tx_itr = IXL_ITR_4K; 18301031d839SEric Joyner } else 18311031d839SEric Joyner pf->tx_itr = ixl_tx_itr; 18321031d839SEric Joyner 18331031d839SEric Joyner if (ixl_rx_itr < 0 || ixl_rx_itr > IXL_MAX_ITR) { 18341031d839SEric Joyner device_printf(dev, "Invalid rx_itr value of %d set!\n", 18351031d839SEric Joyner ixl_rx_itr); 18361031d839SEric Joyner device_printf(dev, "rx_itr must be between %d and %d, " 18371031d839SEric Joyner "inclusive\n", 18381031d839SEric Joyner 0, IXL_MAX_ITR); 18391031d839SEric Joyner device_printf(dev, "Using default value of %d instead\n", 18401031d839SEric Joyner IXL_ITR_8K); 18411031d839SEric Joyner pf->rx_itr = IXL_ITR_8K; 18421031d839SEric Joyner } else 18431031d839SEric Joyner pf->rx_itr = ixl_rx_itr; 18441031d839SEric Joyner } 18451031d839SEric Joyner 1846