1 /****************************************************************************** 2 3 Copyright (c) 2013-2018, Intel Corporation 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions are met: 8 9 1. Redistributions of source code must retain the above copyright notice, 10 this list of conditions and the following disclaimer. 11 12 2. Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions and the following disclaimer in the 14 documentation and/or other materials provided with the distribution. 15 16 3. Neither the name of the Intel Corporation nor the names of its 17 contributors may be used to endorse or promote products derived from 18 this software without specific prior written permission. 19 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 POSSIBILITY OF SUCH DAMAGE. 31 32 ******************************************************************************/ 33 34 #include "ixl.h" 35 #include "ixl_pf.h" 36 37 #include <net/if_vf_status.h> 38 39 #ifdef IXL_IW 40 #include "ixl_iw.h" 41 #include "ixl_iw_int.h" 42 #endif 43 44 #ifdef PCI_IOV 45 #include "ixl_pf_iov.h" 46 #endif 47 48 /********************************************************************* 49 * Driver version 50 *********************************************************************/ 51 #define IXL_DRIVER_VERSION_MAJOR 2 52 #define IXL_DRIVER_VERSION_MINOR 3 53 #define IXL_DRIVER_VERSION_BUILD 3 54 55 #define IXL_DRIVER_VERSION_STRING \ 56 __XSTRING(IXL_DRIVER_VERSION_MAJOR) "." \ 57 __XSTRING(IXL_DRIVER_VERSION_MINOR) "." \ 58 __XSTRING(IXL_DRIVER_VERSION_BUILD) "-k" 59 60 /* Version 1 driver.ixl extension schema; documented in ixl(4). */ 61 #define IXL_VF_STATUS_NAMESPACE "driver.ixl" 62 #define IXL_VF_STATUS_VERSION 1 63 #define IXL_VF_STATUS_MDD_BLOCKED "mdd-blocked" 64 #define IXL_VF_STATUS_MDD_TX_EVENTS "mdd-tx-events" 65 #define IXL_VF_STATUS_MDD_RX_EVENTS "mdd-rx-events" 66 67 enum ixl_vf_status_field { 68 IXL_VF_STATUS_FIELD_MDD_BLOCKED, 69 IXL_VF_STATUS_FIELD_MDD_TX_EVENTS, 70 IXL_VF_STATUS_FIELD_MDD_RX_EVENTS, 71 IXL_VF_STATUS_NUM_FIELDS 72 }; 73 74 /********************************************************************* 75 * PCI Device ID Table 76 * 77 * Used by probe to select devices to load on 78 * 79 * ( Vendor ID, Device ID, Branding String ) 80 *********************************************************************/ 81 82 static const pci_vendor_info_t ixl_vendor_info_array[] = 83 { 84 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710, "Intel(R) Ethernet Controller X710 for 10GbE SFP+"), 85 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B, "Intel(R) Ethernet Controller XL710 for 40GbE backplane"), 86 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C, "Intel(R) Ethernet Controller X710 for 10GbE backplane"), 87 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A, "Intel(R) Ethernet Controller XL710 for 40GbE QSFP+"), 88 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B, "Intel(R) Ethernet Controller XL710 for 40GbE QSFP+"), 89 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C, "Intel(R) Ethernet Controller X710 for 10GbE QSFP+"), 90 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T, "Intel(R) Ethernet Controller X710 for 10GBASE-T"), 91 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T4, "Intel(R) Ethernet Controller X710/X557-AT 10GBASE-T"), 92 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_X722, "Intel(R) Ethernet Connection X722 for 10GbE backplane"), 93 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_X722, "Intel(R) Ethernet Connection X722 for 10GbE QSFP+"), 94 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722, "Intel(R) Ethernet Connection X722 for 10GbE SFP+"), 95 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_X722, "Intel(R) Ethernet Connection X722 for 1GbE"), 96 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_X722, "Intel(R) Ethernet Connection X722 for 10GBASE-T"), 97 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_I_X722, "Intel(R) Ethernet Connection X722 for 10GbE SFP+"), 98 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_B, "Intel(R) Ethernet Controller XXV710 for 25GbE backplane"), 99 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_SFP28, "Intel(R) Ethernet Controller XXV710 for 25GbE SFP28"), 100 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_BC, "Intel(R) Ethernet Controller X710 for 10GBASE-T"), 101 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_SFP, "Intel(R) Ethernet Controller X710 for 10GbE SFP+"), 102 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_B, "Intel(R) Ethernet Controller X710 for 10GbE backplane"), 103 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_5G_BASE_T_BC, "Intel(R) Ethernet Controller V710 for 5GBASE-T"), 104 PVIDV(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_BC, "Intel(R) Ethernet Controller I710 for 1GBASE-T"), 105 /* required last entry */ 106 PVID_END 107 }; 108 109 /********************************************************************* 110 * Function prototypes 111 *********************************************************************/ 112 /*** IFLIB interface ***/ 113 static void *ixl_register(device_t dev); 114 static int ixl_if_attach_pre(if_ctx_t ctx); 115 static int ixl_if_attach_post(if_ctx_t ctx); 116 static int ixl_if_detach(if_ctx_t ctx); 117 static int ixl_if_shutdown(if_ctx_t ctx); 118 static int ixl_if_suspend(if_ctx_t ctx); 119 static int ixl_if_resume(if_ctx_t ctx); 120 static int ixl_if_msix_intr_assign(if_ctx_t ctx, int msix); 121 static void ixl_if_enable_intr(if_ctx_t ctx); 122 static void ixl_if_disable_intr(if_ctx_t ctx); 123 static int ixl_if_rx_queue_intr_enable(if_ctx_t ctx, uint16_t rxqid); 124 static int ixl_if_tx_queue_intr_enable(if_ctx_t ctx, uint16_t txqid); 125 static int ixl_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int ntxqs, int ntxqsets); 126 static int ixl_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int nqs, int nqsets); 127 static void ixl_if_queues_free(if_ctx_t ctx); 128 static void ixl_if_update_admin_status(if_ctx_t ctx); 129 static void ixl_if_multi_set(if_ctx_t ctx); 130 static int ixl_if_mtu_set(if_ctx_t ctx, uint32_t mtu); 131 static void ixl_if_media_status(if_ctx_t ctx, struct ifmediareq *ifmr); 132 static int ixl_if_media_change(if_ctx_t ctx); 133 static int ixl_if_promisc_set(if_ctx_t ctx, int flags); 134 static void ixl_if_timer(if_ctx_t ctx, uint16_t qid); 135 static void ixl_if_vlan_register(if_ctx_t ctx, u16 vtag); 136 static void ixl_if_vlan_unregister(if_ctx_t ctx, u16 vtag); 137 static uint64_t ixl_if_get_counter(if_ctx_t ctx, ift_counter cnt); 138 static int ixl_if_i2c_req(if_ctx_t ctx, struct ifi2creq *req); 139 static int ixl_if_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t data); 140 static bool ixl_if_needs_restart(if_ctx_t ctx, enum iflib_restart_event event); 141 static void ixl_if_led_func(if_ctx_t ctx, int onoff); 142 static int ixl_if_vf_status(if_ctx_t ctx, 143 struct if_vf_status **statusp); 144 #ifdef PCI_IOV 145 static void ixl_if_vflr_handle(if_ctx_t ctx); 146 #endif 147 148 /*** Other ***/ 149 static void ixl_save_pf_tunables(struct ixl_pf *); 150 static int ixl_allocate_pci_resources(struct ixl_pf *); 151 static void ixl_setup_ssctx(struct ixl_pf *pf); 152 static void ixl_admin_timer(void *arg); 153 154 /********************************************************************* 155 * FreeBSD Device Interface Entry Points 156 *********************************************************************/ 157 158 static device_method_t ixl_methods[] = { 159 /* Device interface */ 160 DEVMETHOD(device_register, ixl_register), 161 DEVMETHOD(device_probe, iflib_device_probe), 162 DEVMETHOD(device_attach, iflib_device_attach), 163 DEVMETHOD(device_detach, iflib_device_detach), 164 DEVMETHOD(device_shutdown, iflib_device_shutdown), 165 DEVMETHOD(device_suspend, iflib_device_suspend), 166 DEVMETHOD(device_resume, iflib_device_resume), 167 #ifdef PCI_IOV 168 DEVMETHOD(pci_iov_init, iflib_device_iov_init), 169 DEVMETHOD(pci_iov_uninit, iflib_device_iov_uninit), 170 DEVMETHOD(pci_iov_add_vf, iflib_device_iov_add_vf), 171 #endif 172 DEVMETHOD_END 173 }; 174 175 static driver_t ixl_driver = { 176 "ixl", ixl_methods, sizeof(struct ixl_pf), 177 }; 178 179 DRIVER_MODULE(ixl, pci, ixl_driver, 0, 0); 180 IFLIB_PNP_INFO(pci, ixl, ixl_vendor_info_array); 181 MODULE_VERSION(ixl, 3); 182 183 MODULE_DEPEND(ixl, pci, 1, 1, 1); 184 MODULE_DEPEND(ixl, ether, 1, 1, 1); 185 MODULE_DEPEND(ixl, iflib, 1, 1, 1); 186 187 static device_method_t ixl_if_methods[] = { 188 DEVMETHOD(ifdi_attach_pre, ixl_if_attach_pre), 189 DEVMETHOD(ifdi_attach_post, ixl_if_attach_post), 190 DEVMETHOD(ifdi_detach, ixl_if_detach), 191 DEVMETHOD(ifdi_shutdown, ixl_if_shutdown), 192 DEVMETHOD(ifdi_suspend, ixl_if_suspend), 193 DEVMETHOD(ifdi_resume, ixl_if_resume), 194 DEVMETHOD(ifdi_init, ixl_if_init), 195 DEVMETHOD(ifdi_stop, ixl_if_stop), 196 DEVMETHOD(ifdi_msix_intr_assign, ixl_if_msix_intr_assign), 197 DEVMETHOD(ifdi_intr_enable, ixl_if_enable_intr), 198 DEVMETHOD(ifdi_intr_disable, ixl_if_disable_intr), 199 DEVMETHOD(ifdi_rx_queue_intr_enable, ixl_if_rx_queue_intr_enable), 200 DEVMETHOD(ifdi_tx_queue_intr_enable, ixl_if_tx_queue_intr_enable), 201 DEVMETHOD(ifdi_tx_queues_alloc, ixl_if_tx_queues_alloc), 202 DEVMETHOD(ifdi_rx_queues_alloc, ixl_if_rx_queues_alloc), 203 DEVMETHOD(ifdi_queues_free, ixl_if_queues_free), 204 DEVMETHOD(ifdi_update_admin_status, ixl_if_update_admin_status), 205 DEVMETHOD(ifdi_multi_set, ixl_if_multi_set), 206 DEVMETHOD(ifdi_mtu_set, ixl_if_mtu_set), 207 DEVMETHOD(ifdi_media_status, ixl_if_media_status), 208 DEVMETHOD(ifdi_media_change, ixl_if_media_change), 209 DEVMETHOD(ifdi_promisc_set, ixl_if_promisc_set), 210 DEVMETHOD(ifdi_timer, ixl_if_timer), 211 DEVMETHOD(ifdi_vlan_register, ixl_if_vlan_register), 212 DEVMETHOD(ifdi_vlan_unregister, ixl_if_vlan_unregister), 213 DEVMETHOD(ifdi_get_counter, ixl_if_get_counter), 214 DEVMETHOD(ifdi_i2c_req, ixl_if_i2c_req), 215 DEVMETHOD(ifdi_priv_ioctl, ixl_if_priv_ioctl), 216 DEVMETHOD(ifdi_needs_restart, ixl_if_needs_restart), 217 DEVMETHOD(ifdi_led_func, ixl_if_led_func), 218 DEVMETHOD(ifdi_vf_status, ixl_if_vf_status), 219 #ifdef PCI_IOV 220 DEVMETHOD(ifdi_iov_init, ixl_if_iov_init), 221 DEVMETHOD(ifdi_iov_uninit, ixl_if_iov_uninit), 222 DEVMETHOD(ifdi_iov_vf_add, ixl_if_iov_vf_add), 223 DEVMETHOD(ifdi_vflr_handle, ixl_if_vflr_handle), 224 #endif 225 // ifdi_debug 226 DEVMETHOD_END 227 }; 228 229 static driver_t ixl_if_driver = { 230 "ixl_if", ixl_if_methods, sizeof(struct ixl_pf) 231 }; 232 233 /* 234 ** TUNEABLE PARAMETERS: 235 */ 236 237 static SYSCTL_NODE(_hw, OID_AUTO, ixl, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 238 "ixl driver parameters"); 239 240 #ifdef IXL_DEBUG_FC 241 /* 242 * Leave this on unless you need to send flow control 243 * frames (or other control frames) from software 244 */ 245 static int ixl_enable_tx_fc_filter = 1; 246 TUNABLE_INT("hw.ixl.enable_tx_fc_filter", 247 &ixl_enable_tx_fc_filter); 248 SYSCTL_INT(_hw_ixl, OID_AUTO, enable_tx_fc_filter, CTLFLAG_RDTUN, 249 &ixl_enable_tx_fc_filter, 0, 250 "Filter out packets with Ethertype 0x8808 from being sent out by non-HW sources"); 251 #endif 252 253 #ifdef IXL_DEBUG 254 static int ixl_debug_recovery_mode = 0; 255 TUNABLE_INT("hw.ixl.debug_recovery_mode", 256 &ixl_debug_recovery_mode); 257 SYSCTL_INT(_hw_ixl, OID_AUTO, debug_recovery_mode, CTLFLAG_RDTUN, 258 &ixl_debug_recovery_mode, 0, 259 "Act like when FW entered recovery mode (for debugging)"); 260 #endif 261 262 static int ixl_i2c_access_method = 0; 263 TUNABLE_INT("hw.ixl.i2c_access_method", 264 &ixl_i2c_access_method); 265 SYSCTL_INT(_hw_ixl, OID_AUTO, i2c_access_method, CTLFLAG_RDTUN, 266 &ixl_i2c_access_method, 0, 267 IXL_SYSCTL_HELP_I2C_METHOD); 268 269 static int ixl_enable_vf_loopback = 1; 270 TUNABLE_INT("hw.ixl.enable_vf_loopback", 271 &ixl_enable_vf_loopback); 272 SYSCTL_INT(_hw_ixl, OID_AUTO, enable_vf_loopback, CTLFLAG_RDTUN, 273 &ixl_enable_vf_loopback, 0, 274 IXL_SYSCTL_HELP_VF_LOOPBACK); 275 276 static int ixl_mdd_auto_reset_vf; 277 TUNABLE_INT("hw.ixl.mdd_auto_reset_vf", &ixl_mdd_auto_reset_vf); 278 SYSCTL_INT(_hw_ixl, OID_AUTO, mdd_auto_reset_vf, CTLFLAG_RDTUN, 279 &ixl_mdd_auto_reset_vf, 0, 280 "Automatically reset VFs blocked by malicious-driver detection"); 281 282 /* 283 * Different method for processing TX descriptor 284 * completion. 285 */ 286 static int ixl_enable_head_writeback = 1; 287 TUNABLE_INT("hw.ixl.enable_head_writeback", 288 &ixl_enable_head_writeback); 289 SYSCTL_INT(_hw_ixl, OID_AUTO, enable_head_writeback, CTLFLAG_RDTUN, 290 &ixl_enable_head_writeback, 0, 291 "For detecting last completed TX descriptor by hardware, use value written by HW instead of checking descriptors"); 292 293 static int ixl_core_debug_mask = 0; 294 TUNABLE_INT("hw.ixl.core_debug_mask", 295 &ixl_core_debug_mask); 296 SYSCTL_INT(_hw_ixl, OID_AUTO, core_debug_mask, CTLFLAG_RDTUN, 297 &ixl_core_debug_mask, 0, 298 "Display debug statements that are printed in non-shared code"); 299 300 static int ixl_shared_debug_mask = 0; 301 TUNABLE_INT("hw.ixl.shared_debug_mask", 302 &ixl_shared_debug_mask); 303 SYSCTL_INT(_hw_ixl, OID_AUTO, shared_debug_mask, CTLFLAG_RDTUN, 304 &ixl_shared_debug_mask, 0, 305 "Display debug statements that are printed in shared code"); 306 307 #if 0 308 /* 309 ** Controls for Interrupt Throttling 310 ** - true/false for dynamic adjustment 311 ** - default values for static ITR 312 */ 313 static int ixl_dynamic_rx_itr = 0; 314 TUNABLE_INT("hw.ixl.dynamic_rx_itr", &ixl_dynamic_rx_itr); 315 SYSCTL_INT(_hw_ixl, OID_AUTO, dynamic_rx_itr, CTLFLAG_RDTUN, 316 &ixl_dynamic_rx_itr, 0, "Dynamic RX Interrupt Rate"); 317 318 static int ixl_dynamic_tx_itr = 0; 319 TUNABLE_INT("hw.ixl.dynamic_tx_itr", &ixl_dynamic_tx_itr); 320 SYSCTL_INT(_hw_ixl, OID_AUTO, dynamic_tx_itr, CTLFLAG_RDTUN, 321 &ixl_dynamic_tx_itr, 0, "Dynamic TX Interrupt Rate"); 322 #endif 323 324 static int ixl_rx_itr = IXL_ITR_8K; 325 TUNABLE_INT("hw.ixl.rx_itr", &ixl_rx_itr); 326 SYSCTL_INT(_hw_ixl, OID_AUTO, rx_itr, CTLFLAG_RDTUN, 327 &ixl_rx_itr, 0, "RX Interrupt Rate"); 328 329 static int ixl_tx_itr = IXL_ITR_4K; 330 TUNABLE_INT("hw.ixl.tx_itr", &ixl_tx_itr); 331 SYSCTL_INT(_hw_ixl, OID_AUTO, tx_itr, CTLFLAG_RDTUN, 332 &ixl_tx_itr, 0, "TX Interrupt Rate"); 333 334 static int ixl_flow_control = -1; 335 SYSCTL_INT(_hw_ixl, OID_AUTO, flow_control, CTLFLAG_RDTUN, 336 &ixl_flow_control, 0, "Initial Flow Control setting"); 337 338 #ifdef IXL_IW 339 int ixl_enable_iwarp = 0; 340 TUNABLE_INT("hw.ixl.enable_iwarp", &ixl_enable_iwarp); 341 SYSCTL_INT(_hw_ixl, OID_AUTO, enable_iwarp, CTLFLAG_RDTUN, 342 &ixl_enable_iwarp, 0, "iWARP enabled"); 343 344 int ixl_limit_iwarp_msix = IXL_IW_MAX_MSIX; 345 TUNABLE_INT("hw.ixl.limit_iwarp_msix", &ixl_limit_iwarp_msix); 346 SYSCTL_INT(_hw_ixl, OID_AUTO, limit_iwarp_msix, CTLFLAG_RDTUN, 347 &ixl_limit_iwarp_msix, 0, "Limit MSI-X vectors assigned to iWARP"); 348 #endif 349 350 extern struct if_txrx ixl_txrx_hwb; 351 extern struct if_txrx ixl_txrx_dwb; 352 353 static struct if_shared_ctx ixl_sctx_init = { 354 .isc_magic = IFLIB_MAGIC, 355 .isc_q_align = PAGE_SIZE, 356 .isc_tx_maxsize = IXL_TSO_SIZE + sizeof(struct ether_vlan_header), 357 .isc_tx_maxsegsize = IXL_MAX_DMA_SEG_SIZE, 358 .isc_tso_maxsize = IXL_TSO_SIZE + sizeof(struct ether_vlan_header), 359 .isc_tso_maxsegsize = IXL_MAX_DMA_SEG_SIZE, 360 .isc_rx_maxsize = 16384, 361 .isc_rx_nsegments = IXL_MAX_RX_SEGS, 362 .isc_rx_maxsegsize = IXL_MAX_DMA_SEG_SIZE, 363 .isc_nfl = 1, 364 .isc_ntxqs = 1, 365 .isc_nrxqs = 1, 366 367 .isc_admin_intrcnt = 1, 368 .isc_vendor_info = ixl_vendor_info_array, 369 .isc_driver_version = IXL_DRIVER_VERSION_STRING, 370 .isc_driver = &ixl_if_driver, 371 .isc_flags = IFLIB_NEED_SCRATCH | IFLIB_NEED_ZERO_CSUM | IFLIB_TSO_INIT_IP | IFLIB_ADMIN_ALWAYS_RUN, 372 373 .isc_nrxd_min = {IXL_MIN_RING}, 374 .isc_ntxd_min = {IXL_MIN_RING}, 375 .isc_nrxd_max = {IXL_MAX_RING}, 376 .isc_ntxd_max = {IXL_MAX_RING}, 377 .isc_nrxd_default = {IXL_DEFAULT_RING}, 378 .isc_ntxd_default = {IXL_DEFAULT_RING}, 379 }; 380 381 /*** Functions ***/ 382 static void * 383 ixl_register(device_t dev) 384 { 385 return (&ixl_sctx_init); 386 } 387 static int 388 ixl_allocate_pci_resources(struct ixl_pf *pf) 389 { 390 device_t dev = iflib_get_dev(pf->vsi.ctx); 391 struct i40e_hw *hw = &pf->hw; 392 int rid; 393 394 /* Map BAR0 */ 395 rid = PCIR_BAR(0); 396 pf->pci_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 397 &rid, RF_ACTIVE); 398 399 if (!(pf->pci_mem)) { 400 device_printf(dev, "Unable to allocate bus resource: PCI memory\n"); 401 return (ENXIO); 402 } 403 404 /* Save off the PCI information */ 405 hw->vendor_id = pci_get_vendor(dev); 406 hw->device_id = pci_get_device(dev); 407 hw->revision_id = pci_read_config(dev, PCIR_REVID, 1); 408 hw->subsystem_vendor_id = 409 pci_read_config(dev, PCIR_SUBVEND_0, 2); 410 hw->subsystem_device_id = 411 pci_read_config(dev, PCIR_SUBDEV_0, 2); 412 413 hw->bus.device = pci_get_slot(dev); 414 hw->bus.func = pci_get_function(dev); 415 416 /* Save off register access information */ 417 pf->osdep.mem_bus_space_tag = 418 rman_get_bustag(pf->pci_mem); 419 pf->osdep.mem_bus_space_handle = 420 rman_get_bushandle(pf->pci_mem); 421 pf->osdep.mem_bus_space_size = rman_get_size(pf->pci_mem); 422 pf->osdep.flush_reg = I40E_GLGEN_STAT; 423 pf->osdep.dev = dev; 424 425 pf->hw.hw_addr = (u8 *) &pf->osdep.mem_bus_space_handle; 426 pf->hw.back = &pf->osdep; 427 428 return (0); 429 } 430 431 static void 432 ixl_setup_ssctx(struct ixl_pf *pf) 433 { 434 if_softc_ctx_t scctx = pf->vsi.shared; 435 struct i40e_hw *hw = &pf->hw; 436 437 if (IXL_PF_IN_RECOVERY_MODE(pf)) { 438 scctx->isc_ntxqsets_max = scctx->isc_nrxqsets_max = 1; 439 scctx->isc_ntxqsets = scctx->isc_nrxqsets = 1; 440 } else if (hw->mac.type == I40E_MAC_X722) 441 scctx->isc_ntxqsets_max = scctx->isc_nrxqsets_max = 128; 442 else 443 scctx->isc_ntxqsets_max = scctx->isc_nrxqsets_max = 64; 444 445 if (pf->vsi.enable_head_writeback) { 446 scctx->isc_txqsizes[0] = roundup2(scctx->isc_ntxd[0] 447 * sizeof(struct i40e_tx_desc) + sizeof(u32), DBA_ALIGN); 448 scctx->isc_txrx = &ixl_txrx_hwb; 449 } else { 450 scctx->isc_txqsizes[0] = roundup2(scctx->isc_ntxd[0] 451 * sizeof(struct i40e_tx_desc), DBA_ALIGN); 452 scctx->isc_txrx = &ixl_txrx_dwb; 453 } 454 455 scctx->isc_txrx->ift_legacy_intr = ixl_intr; 456 scctx->isc_rxqsizes[0] = roundup2(scctx->isc_nrxd[0] 457 * sizeof(union i40e_32byte_rx_desc), DBA_ALIGN); 458 scctx->isc_msix_bar = PCIR_BAR(IXL_MSIX_BAR); 459 scctx->isc_tx_nsegments = IXL_MAX_TX_SEGS; 460 scctx->isc_tx_tso_segments_max = IXL_MAX_TSO_SEGS; 461 scctx->isc_tx_tso_size_max = IXL_TSO_SIZE; 462 scctx->isc_tx_tso_segsize_max = IXL_MAX_DMA_SEG_SIZE; 463 scctx->isc_rss_table_size = pf->hw.func_caps.rss_table_size; 464 scctx->isc_tx_csum_flags = CSUM_OFFLOAD; 465 scctx->isc_capabilities = scctx->isc_capenable = IXL_CAPS; 466 } 467 468 static void 469 ixl_admin_timer(void *arg) 470 { 471 struct ixl_pf *pf = (struct ixl_pf *)arg; 472 473 if (ixl_test_state(&pf->state, IXL_STATE_LINK_POLLING)) { 474 struct i40e_hw *hw = &pf->hw; 475 sbintime_t stime; 476 enum i40e_status_code status; 477 478 hw->phy.get_link_info = TRUE; 479 status = i40e_get_link_status(hw, &pf->link_up); 480 if (status == I40E_SUCCESS) { 481 ixl_clear_state(&pf->state, IXL_STATE_LINK_POLLING); 482 /* OS link info is updated in the admin task */ 483 } else { 484 device_printf(pf->dev, 485 "%s: i40e_get_link_status status %s, aq error %s\n", 486 __func__, i40e_stat_str(hw, status), 487 i40e_aq_str(hw, hw->aq.asq_last_status)); 488 stime = getsbinuptime(); 489 if (stime - pf->link_poll_start > IXL_PF_MAX_LINK_POLL) { 490 device_printf(pf->dev, "Polling link status failed\n"); 491 ixl_clear_state(&pf->state, IXL_STATE_LINK_POLLING); 492 } 493 } 494 } 495 496 /* Fire off the admin task */ 497 iflib_admin_intr_deferred(pf->vsi.ctx); 498 499 /* Reschedule the admin timer */ 500 callout_schedule(&pf->admin_timer, hz/2); 501 } 502 503 static int 504 ixl_attach_pre_recovery_mode(struct ixl_pf *pf) 505 { 506 struct ixl_vsi *vsi = &pf->vsi; 507 struct i40e_hw *hw = &pf->hw; 508 device_t dev = pf->dev; 509 510 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"); 511 512 i40e_get_mac_addr(hw, hw->mac.addr); 513 514 if (vsi->shared->isc_intr == IFLIB_INTR_MSIX) { 515 ixl_configure_intr0_msix(pf); 516 ixl_enable_intr0(hw); 517 } 518 519 ixl_setup_ssctx(pf); 520 521 return (0); 522 } 523 524 static int 525 ixl_if_attach_pre(if_ctx_t ctx) 526 { 527 device_t dev; 528 struct ixl_pf *pf; 529 struct i40e_hw *hw; 530 struct ixl_vsi *vsi; 531 enum i40e_get_fw_lldp_status_resp lldp_status; 532 struct i40e_filter_control_settings filter; 533 enum i40e_status_code status; 534 int error = 0; 535 536 dev = iflib_get_dev(ctx); 537 pf = iflib_get_softc(ctx); 538 539 INIT_DBG_DEV(dev, "begin"); 540 541 vsi = &pf->vsi; 542 vsi->back = pf; 543 pf->dev = dev; 544 hw = &pf->hw; 545 546 vsi->dev = dev; 547 vsi->hw = &pf->hw; 548 vsi->id = 0; 549 vsi->num_vlans = 0; 550 vsi->ctx = ctx; 551 vsi->media = iflib_get_media(ctx); 552 vsi->shared = iflib_get_softc_ctx(ctx); 553 554 snprintf(pf->admin_mtx_name, sizeof(pf->admin_mtx_name), 555 "%s:admin", device_get_nameunit(dev)); 556 mtx_init(&pf->admin_mtx, pf->admin_mtx_name, NULL, MTX_DEF); 557 callout_init_mtx(&pf->admin_timer, &pf->admin_mtx, 0); 558 559 /* Save tunable values */ 560 ixl_save_pf_tunables(pf); 561 562 /* Do PCI setup - map BAR0, etc */ 563 if (ixl_allocate_pci_resources(pf)) { 564 device_printf(dev, "Allocation of PCI resources failed\n"); 565 error = ENXIO; 566 goto err_pci_res; 567 } 568 569 /* Establish a clean starting point */ 570 i40e_clear_hw(hw); 571 i40e_set_mac_type(hw); 572 573 error = ixl_pf_reset(pf); 574 if (error) 575 goto err_out; 576 577 /* Initialize the shared code */ 578 status = i40e_init_shared_code(hw); 579 if (status) { 580 device_printf(dev, "Unable to initialize shared code, error %s\n", 581 i40e_stat_str(hw, status)); 582 error = EIO; 583 goto err_out; 584 } 585 586 /* Set up the admin queue */ 587 hw->aq.num_arq_entries = IXL_AQ_LEN; 588 hw->aq.num_asq_entries = IXL_AQ_LEN; 589 hw->aq.arq_buf_size = IXL_AQ_BUF_SZ; 590 hw->aq.asq_buf_size = IXL_AQ_BUF_SZ; 591 592 status = i40e_init_adminq(hw); 593 if (status != 0 && status != I40E_ERR_FIRMWARE_API_VERSION) { 594 device_printf(dev, "Unable to initialize Admin Queue, error %s\n", 595 i40e_stat_str(hw, status)); 596 error = EIO; 597 goto err_out; 598 } 599 ixl_print_nvm_version(pf); 600 601 if (status == I40E_ERR_FIRMWARE_API_VERSION) { 602 device_printf(dev, "The driver for the device stopped " 603 "because the NVM image is newer than expected.\n"); 604 device_printf(dev, "You must install the most recent version of " 605 "the network driver.\n"); 606 error = EIO; 607 goto err_out; 608 } 609 610 if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && 611 hw->aq.api_min_ver > I40E_FW_MINOR_VERSION(hw)) { 612 device_printf(dev, "The driver for the device detected " 613 "a newer version of the NVM image than expected.\n"); 614 device_printf(dev, "Please install the most recent version " 615 "of the network driver.\n"); 616 } else if (hw->aq.api_maj_ver == 1 && hw->aq.api_min_ver < 4) { 617 device_printf(dev, "The driver for the device detected " 618 "an older version of the NVM image than expected.\n"); 619 device_printf(dev, "Please update the NVM image.\n"); 620 } 621 622 if (IXL_PF_IN_RECOVERY_MODE(pf)) { 623 error = ixl_attach_pre_recovery_mode(pf); 624 if (error) 625 goto err_out; 626 return (error); 627 } 628 629 /* Clear PXE mode */ 630 i40e_clear_pxe_mode(hw); 631 632 /* Get capabilities from the device */ 633 error = ixl_get_hw_capabilities(pf); 634 if (error) { 635 device_printf(dev, "get_hw_capabilities failed: %d\n", 636 error); 637 goto err_get_cap; 638 } 639 640 /* Set up host memory cache */ 641 error = ixl_setup_hmc(pf); 642 if (error) 643 goto err_mac_hmc; 644 645 /* Disable LLDP from the firmware for certain NVM versions */ 646 if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || 647 (pf->hw.aq.fw_maj_ver < 4)) { 648 i40e_aq_stop_lldp(hw, true, false, NULL); 649 ixl_set_state(&pf->state, IXL_STATE_FW_LLDP_DISABLED); 650 } 651 652 /* Try enabling Energy Efficient Ethernet (EEE) mode */ 653 if (i40e_enable_eee(hw, true) == I40E_SUCCESS) 654 ixl_set_state(&pf->state, IXL_STATE_EEE_ENABLED); 655 else 656 ixl_clear_state(&pf->state, IXL_STATE_EEE_ENABLED); 657 658 /* Get MAC addresses from hardware */ 659 i40e_get_mac_addr(hw, hw->mac.addr); 660 error = i40e_validate_mac_addr(hw->mac.addr); 661 if (error) { 662 device_printf(dev, "validate_mac_addr failed: %d\n", error); 663 goto err_mac_hmc; 664 } 665 bcopy(hw->mac.addr, hw->mac.perm_addr, ETHER_ADDR_LEN); 666 iflib_set_mac(ctx, hw->mac.addr); 667 i40e_get_port_mac_addr(hw, hw->mac.port_addr); 668 669 /* Set up the device filtering */ 670 bzero(&filter, sizeof(filter)); 671 filter.enable_ethtype = TRUE; 672 filter.enable_macvlan = TRUE; 673 filter.enable_fdir = FALSE; 674 filter.hash_lut_size = I40E_HASH_LUT_SIZE_512; 675 if (i40e_set_filter_control(hw, &filter)) 676 device_printf(dev, "i40e_set_filter_control() failed\n"); 677 678 /* Query device FW LLDP status */ 679 if (i40e_get_fw_lldp_status(hw, &lldp_status) == I40E_SUCCESS) { 680 if (lldp_status == I40E_GET_FW_LLDP_STATUS_DISABLED) { 681 ixl_set_state(&pf->state, 682 IXL_STATE_FW_LLDP_DISABLED); 683 } else { 684 ixl_clear_state(&pf->state, 685 IXL_STATE_FW_LLDP_DISABLED); 686 } 687 } 688 689 /* Tell FW to apply DCB config on link up */ 690 i40e_aq_set_dcb_parameters(hw, true, NULL); 691 692 /* Fill out iflib parameters */ 693 ixl_setup_ssctx(pf); 694 695 INIT_DBG_DEV(dev, "end"); 696 return (0); 697 698 err_mac_hmc: 699 ixl_shutdown_hmc(pf); 700 err_get_cap: 701 i40e_shutdown_adminq(hw); 702 err_out: 703 ixl_free_pci_resources(pf); 704 err_pci_res: 705 mtx_lock(&pf->admin_mtx); 706 callout_stop(&pf->admin_timer); 707 mtx_unlock(&pf->admin_mtx); 708 mtx_destroy(&pf->admin_mtx); 709 return (error); 710 } 711 712 static int 713 ixl_if_attach_post(if_ctx_t ctx) 714 { 715 device_t dev; 716 struct ixl_pf *pf; 717 struct i40e_hw *hw; 718 struct ixl_vsi *vsi; 719 int error = 0; 720 enum i40e_status_code status; 721 722 dev = iflib_get_dev(ctx); 723 pf = iflib_get_softc(ctx); 724 725 INIT_DBG_DEV(dev, "begin"); 726 727 vsi = &pf->vsi; 728 vsi->ifp = iflib_get_ifp(ctx); 729 hw = &pf->hw; 730 731 /* Save off determined number of queues for interface */ 732 vsi->num_rx_queues = vsi->shared->isc_nrxqsets; 733 vsi->num_tx_queues = vsi->shared->isc_ntxqsets; 734 735 /* Setup OS network interface / ifnet */ 736 if (ixl_setup_interface(dev, pf)) { 737 device_printf(dev, "interface setup failed!\n"); 738 error = EIO; 739 goto err; 740 } 741 742 if (IXL_PF_IN_RECOVERY_MODE(pf)) { 743 /* Keep admin queue interrupts active while driver is loaded */ 744 if (vsi->shared->isc_intr == IFLIB_INTR_MSIX) { 745 ixl_configure_intr0_msix(pf); 746 ixl_enable_intr0(hw); 747 } 748 749 ixl_add_sysctls_recovery_mode(pf); 750 751 /* Start the admin timer */ 752 mtx_lock(&pf->admin_mtx); 753 callout_reset(&pf->admin_timer, hz/2, ixl_admin_timer, pf); 754 mtx_unlock(&pf->admin_mtx); 755 return (0); 756 } 757 758 error = ixl_switch_config(pf); 759 if (error) { 760 device_printf(dev, "Initial ixl_switch_config() failed: %d\n", 761 error); 762 goto err; 763 } 764 765 /* Add protocol filters to list */ 766 ixl_init_filters(vsi); 767 768 /* Init queue allocation manager */ 769 error = ixl_pf_qmgr_init(&pf->qmgr, hw->func_caps.num_tx_qp); 770 if (error) { 771 device_printf(dev, "Failed to init queue manager for PF queues, error %d\n", 772 error); 773 goto err; 774 } 775 /* reserve a contiguous allocation for the PF's VSI */ 776 error = ixl_pf_qmgr_alloc_contiguous(&pf->qmgr, 777 max(vsi->num_rx_queues, vsi->num_tx_queues), &pf->qtag); 778 if (error) { 779 device_printf(dev, "Failed to reserve queues for PF LAN VSI, error %d\n", 780 error); 781 goto err; 782 } 783 device_printf(dev, "Allocating %d queues for PF LAN VSI; %d queues active\n", 784 pf->qtag.num_allocated, pf->qtag.num_active); 785 786 /* Determine link state */ 787 error = ixl_attach_get_link_status(pf); 788 if (error == EINVAL) 789 goto err; 790 791 /* Limit PHY interrupts to link, autoneg, and modules failure */ 792 status = i40e_aq_set_phy_int_mask(hw, IXL_DEFAULT_PHY_INT_MASK, 793 NULL); 794 if (status) { 795 device_printf(dev, "i40e_aq_set_phy_mask() failed: err %s," 796 " aq_err %s\n", i40e_stat_str(hw, status), 797 i40e_aq_str(hw, hw->aq.asq_last_status)); 798 goto err; 799 } 800 801 /* Get the bus configuration and set the shared code */ 802 ixl_get_bus_info(pf); 803 804 /* Keep admin queue interrupts active while driver is loaded */ 805 if (vsi->shared->isc_intr == IFLIB_INTR_MSIX) { 806 ixl_configure_intr0_msix(pf); 807 ixl_enable_intr0(hw); 808 } 809 810 /* Set initial advertised speed sysctl value */ 811 ixl_set_initial_advertised_speeds(pf); 812 813 /* Initialize statistics & add sysctls */ 814 ixl_add_device_sysctls(pf); 815 ixl_pf_reset_stats(pf); 816 ixl_update_stats_counters(pf); 817 ixl_add_hw_stats(pf); 818 ixl_vsi_reset_stats(vsi); 819 820 /* 821 * Driver may have been reloaded. Ensure that the link state 822 * is consistent with current settings. 823 */ 824 ixl_set_link(pf, ixl_test_state(&pf->state, IXL_STATE_LINK_ACTIVE_ON_DOWN)); 825 826 hw->phy.get_link_info = true; 827 status = i40e_get_link_status(hw, &pf->link_up); 828 if (status != I40E_SUCCESS) { 829 device_printf(dev, 830 "%s get link status, status: %s aq_err=%s\n", 831 __func__, i40e_stat_str(hw, status), 832 i40e_aq_str(hw, hw->aq.asq_last_status)); 833 /* 834 * Most probably FW has not finished configuring PHY. 835 * Retry periodically in a timer callback. 836 */ 837 ixl_set_state(&pf->state, IXL_STATE_LINK_POLLING); 838 pf->link_poll_start = getsbinuptime(); 839 } else 840 ixl_update_link_status(pf); 841 842 #ifdef PCI_IOV 843 ixl_initialize_sriov(pf); 844 #endif 845 846 #ifdef IXL_IW 847 if (hw->func_caps.iwarp && ixl_enable_iwarp) { 848 pf->iw_enabled = (pf->iw_msix > 0) ? true : false; 849 if (pf->iw_enabled) { 850 error = ixl_iw_pf_attach(pf); 851 if (error) { 852 device_printf(dev, 853 "interfacing to iWARP driver failed: %d\n", 854 error); 855 goto err; 856 } else 857 device_printf(dev, "iWARP ready\n"); 858 } else 859 device_printf(dev, "iWARP disabled on this device " 860 "(no MSI-X vectors)\n"); 861 } else { 862 pf->iw_enabled = false; 863 device_printf(dev, "The device is not iWARP enabled\n"); 864 } 865 #endif 866 /* Start the admin timer */ 867 mtx_lock(&pf->admin_mtx); 868 callout_reset(&pf->admin_timer, hz/2, ixl_admin_timer, pf); 869 mtx_unlock(&pf->admin_mtx); 870 871 INIT_DBG_DEV(dev, "end"); 872 return (0); 873 874 err: 875 INIT_DEBUGOUT("end: error %d", error); 876 /* ixl_if_detach() is called on error from this */ 877 return (error); 878 } 879 880 /** 881 * XXX: iflib always ignores the return value of detach() 882 * -> This means that this isn't allowed to fail 883 */ 884 static int 885 ixl_if_detach(if_ctx_t ctx) 886 { 887 struct ixl_pf *pf = iflib_get_softc(ctx); 888 struct ixl_vsi *vsi = &pf->vsi; 889 struct i40e_hw *hw = &pf->hw; 890 device_t dev = pf->dev; 891 enum i40e_status_code status; 892 #ifdef IXL_IW 893 int error; 894 #endif 895 896 INIT_DBG_DEV(dev, "begin"); 897 898 /* Stop the admin timer */ 899 mtx_lock(&pf->admin_mtx); 900 callout_stop(&pf->admin_timer); 901 mtx_unlock(&pf->admin_mtx); 902 mtx_destroy(&pf->admin_mtx); 903 904 #ifdef IXL_IW 905 if (ixl_enable_iwarp && pf->iw_enabled) { 906 error = ixl_iw_pf_detach(pf); 907 if (error == EBUSY) { 908 device_printf(dev, "iwarp in use; stop it first.\n"); 909 //return (error); 910 } 911 } 912 #endif 913 /* Remove all previously allocated media types */ 914 ifmedia_removeall(vsi->media); 915 916 /* Shutdown LAN HMC */ 917 ixl_shutdown_hmc(pf); 918 919 /* Shutdown admin queue */ 920 ixl_disable_intr0(hw); 921 status = i40e_shutdown_adminq(hw); 922 if (status) 923 device_printf(dev, 924 "i40e_shutdown_adminq() failed with status %s\n", 925 i40e_stat_str(hw, status)); 926 927 ixl_pf_qmgr_destroy(&pf->qmgr); 928 ixl_free_pci_resources(pf); 929 ixl_free_filters(&vsi->ftl); 930 INIT_DBG_DEV(dev, "end"); 931 return (0); 932 } 933 934 static int 935 ixl_if_shutdown(if_ctx_t ctx) 936 { 937 int error = 0; 938 939 INIT_DEBUGOUT("ixl_if_shutdown: begin"); 940 941 /* TODO: Call ixl_if_stop()? */ 942 943 /* TODO: Then setup low power mode */ 944 945 return (error); 946 } 947 948 static int 949 ixl_if_suspend(if_ctx_t ctx) 950 { 951 int error = 0; 952 953 INIT_DEBUGOUT("ixl_if_suspend: begin"); 954 955 /* TODO: Call ixl_if_stop()? */ 956 957 /* TODO: Then setup low power mode */ 958 959 return (error); 960 } 961 962 static int 963 ixl_if_resume(if_ctx_t ctx) 964 { 965 INIT_DEBUGOUT("ixl_if_resume: begin"); 966 967 /* Read & clear wake-up registers */ 968 969 return (0); 970 } 971 972 void 973 ixl_if_init(if_ctx_t ctx) 974 { 975 struct ixl_pf *pf = iflib_get_softc(ctx); 976 struct ixl_vsi *vsi = &pf->vsi; 977 struct i40e_hw *hw = &pf->hw; 978 if_t ifp = iflib_get_ifp(ctx); 979 device_t dev = iflib_get_dev(ctx); 980 u8 tmpaddr[ETHER_ADDR_LEN]; 981 int ret; 982 983 if (IXL_PF_IN_RECOVERY_MODE(pf)) 984 goto fail; 985 /* 986 * If the aq is dead here, it probably means something outside of the driver 987 * did something to the adapter, like a PF reset. 988 * So, rebuild the driver's state here if that occurs. 989 */ 990 if (!i40e_check_asq_alive(&pf->hw)) { 991 device_printf(dev, "Admin Queue is down; resetting...\n"); 992 (void)ixl_teardown_hw_structs(pf); 993 ret = ixl_rebuild_hw_structs_after_reset(pf, false); 994 if (ret != 0) 995 goto fail; 996 } 997 998 /* Get the latest mac address... User might use a LAA */ 999 bcopy(if_getlladdr(vsi->ifp), tmpaddr, ETH_ALEN); 1000 if (!ixl_ether_is_equal(hw->mac.addr, tmpaddr) && 1001 (i40e_validate_mac_addr(tmpaddr) == I40E_SUCCESS)) { 1002 ret = i40e_aq_mac_address_write(hw, 1003 I40E_AQC_WRITE_TYPE_LAA_ONLY, 1004 tmpaddr, NULL); 1005 if (ret) { 1006 device_printf(dev, "LLA address change failed!!\n"); 1007 goto fail; 1008 } 1009 ixl_del_all_vlan_filters(vsi, hw->mac.addr); 1010 bcopy(tmpaddr, hw->mac.addr, ETH_ALEN); 1011 /* 1012 * New filters are configured by ixl_reconfigure_filters 1013 * at the end of ixl_init_locked. 1014 */ 1015 } 1016 1017 iflib_set_mac(ctx, hw->mac.addr); 1018 1019 /* Prepare the VSI: rings, hmc contexts, etc... */ 1020 if (ixl_initialize_vsi(vsi)) { 1021 device_printf(dev, "initialize vsi failed!!\n"); 1022 goto fail; 1023 } 1024 1025 ixl_set_link(pf, true); 1026 1027 /* Reconfigure multicast filters in HW */ 1028 ixl_if_multi_set(ctx); 1029 1030 /* Set up RSS */ 1031 ixl_config_rss(pf); 1032 1033 /* Set up MSI-X routing and the ITR settings */ 1034 if (vsi->shared->isc_intr == IFLIB_INTR_MSIX) { 1035 ixl_configure_queue_intr_msix(pf); 1036 ixl_configure_itr(pf); 1037 } else 1038 ixl_configure_legacy(pf); 1039 1040 if (vsi->enable_head_writeback) 1041 ixl_init_tx_cidx(vsi); 1042 else 1043 ixl_init_tx_rsqs(vsi); 1044 1045 ret = ixl_enable_rings(vsi); 1046 if (ret != 0) { 1047 device_printf(dev, "enable rings failed: %d\n", ret); 1048 ixl_disable_rings(pf, vsi, &pf->qtag); 1049 goto fail; 1050 } 1051 1052 i40e_aq_set_default_vsi(hw, vsi->seid, NULL); 1053 1054 /* Re-add configure filters to HW */ 1055 ixl_reconfigure_filters(vsi); 1056 1057 /* Configure promiscuous mode */ 1058 ixl_if_promisc_set(ctx, if_getflags(ifp)); 1059 1060 #ifdef IXL_IW 1061 if (ixl_enable_iwarp && pf->iw_enabled) { 1062 ret = ixl_iw_pf_init(pf); 1063 if (ret) 1064 device_printf(dev, 1065 "initialize iwarp failed, code %d\n", ret); 1066 } 1067 #endif 1068 return; 1069 1070 fail: 1071 iflib_init_failed(ctx); 1072 } 1073 1074 void 1075 ixl_if_stop(if_ctx_t ctx) 1076 { 1077 struct ixl_pf *pf = iflib_get_softc(ctx); 1078 if_t ifp = iflib_get_ifp(ctx); 1079 struct ixl_vsi *vsi = &pf->vsi; 1080 1081 INIT_DEBUGOUT("ixl_if_stop: begin\n"); 1082 1083 ixl_led_restore(pf); 1084 if (IXL_PF_IN_RECOVERY_MODE(pf)) 1085 return; 1086 1087 // TODO: This may need to be reworked 1088 #ifdef IXL_IW 1089 /* Stop iWARP device */ 1090 if (ixl_enable_iwarp && pf->iw_enabled) 1091 ixl_iw_pf_stop(pf); 1092 #endif 1093 1094 ixl_disable_rings_intr(vsi); 1095 ixl_disable_rings(pf, vsi, &pf->qtag); 1096 1097 /* 1098 * Don't set link state if only reconfiguring 1099 * e.g. on MTU change. 1100 */ 1101 if ((if_getflags(ifp) & IFF_UP) == 0 && 1102 !ixl_test_state(&pf->state, IXL_STATE_LINK_ACTIVE_ON_DOWN)) 1103 ixl_set_link(pf, false); 1104 } 1105 1106 #define IXL_PHY_DEBUG_ALL \ 1107 (I40E_AQ_PHY_DEBUG_DISABLE_LINK_FW | \ 1108 I40E_AQ_PHY_DEBUG_DISABLE_ALL_LINK_FW) 1109 1110 static bool 1111 ixl_phy_controls_leds(const struct i40e_hw *hw) 1112 { 1113 1114 /* These external 10GBASE-T PHYs own the identification LED. */ 1115 return (hw->device_id == I40E_DEV_ID_10G_BASE_T || 1116 hw->device_id == I40E_DEV_ID_10G_BASE_T4); 1117 } 1118 1119 static void 1120 ixl_if_led_func(if_ctx_t ctx, int onoff) 1121 { 1122 struct ixl_pf *pf; 1123 struct i40e_hw *hw; 1124 enum i40e_status_code status; 1125 u16 phy_status; 1126 1127 pf = iflib_get_softc(ctx); 1128 hw = &pf->hw; 1129 if (!onoff) { 1130 ixl_led_restore(pf); 1131 return; 1132 } 1133 if (pf->led_active) 1134 return; 1135 1136 pf->led_phy_controlled = ixl_phy_controls_leds(hw); 1137 if (!pf->led_phy_controlled) { 1138 pf->led_status = i40e_led_get(hw); 1139 pf->led_active = true; 1140 i40e_led_set(hw, 0xf, false); 1141 return; 1142 } 1143 1144 if ((hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) == 0) 1145 (void)i40e_aq_set_phy_debug(hw, IXL_PHY_DEBUG_ALL, NULL); 1146 pf->led_phy_addr = I40E_PHY_LED_PROV_REG_1; 1147 status = i40e_led_get_phy(hw, &pf->led_phy_addr, &phy_status); 1148 if (status != I40E_SUCCESS) { 1149 if ((hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) == 0) 1150 (void)i40e_aq_set_phy_debug(hw, 0, NULL); 1151 return; 1152 } 1153 pf->led_status = phy_status; 1154 pf->led_active = true; 1155 status = i40e_led_set_phy(hw, true, pf->led_phy_addr, 0); 1156 if (status != I40E_SUCCESS) 1157 ixl_led_restore(pf); 1158 } 1159 1160 void 1161 ixl_led_restore(struct ixl_pf *pf) 1162 { 1163 struct i40e_hw *hw; 1164 1165 if (!pf->led_active) 1166 return; 1167 1168 hw = &pf->hw; 1169 if (pf->led_phy_controlled) { 1170 (void)i40e_led_set_phy(hw, false, pf->led_phy_addr, 1171 pf->led_status | I40E_PHY_LED_MODE_ORIG); 1172 if ((hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) == 0) 1173 (void)i40e_aq_set_phy_debug(hw, 0, NULL); 1174 } else { 1175 i40e_led_set(hw, pf->led_status, false); 1176 } 1177 pf->led_active = false; 1178 } 1179 1180 static int 1181 ixl_if_msix_intr_assign(if_ctx_t ctx, int msix) 1182 { 1183 struct ixl_pf *pf = iflib_get_softc(ctx); 1184 struct ixl_vsi *vsi = &pf->vsi; 1185 struct ixl_rx_queue *rx_que = vsi->rx_queues; 1186 struct ixl_tx_queue *tx_que = vsi->tx_queues; 1187 int err, i, rid, vector = 0; 1188 char buf[16]; 1189 1190 MPASS(vsi->shared->isc_nrxqsets > 0); 1191 MPASS(vsi->shared->isc_ntxqsets > 0); 1192 1193 /* Admin Que must use vector 0*/ 1194 rid = vector + 1; 1195 err = iflib_irq_alloc_generic(ctx, &vsi->irq, rid, IFLIB_INTR_ADMIN, 1196 ixl_msix_adminq, pf, 0, "aq"); 1197 if (err) { 1198 iflib_irq_free(ctx, &vsi->irq); 1199 device_printf(iflib_get_dev(ctx), 1200 "Failed to register Admin Que handler"); 1201 return (err); 1202 } 1203 1204 #ifdef PCI_IOV 1205 /* Create soft IRQ for handling VFLRs */ 1206 iflib_softirq_alloc_generic(ctx, NULL, IFLIB_INTR_IOV, pf, 0, "iov"); 1207 #endif 1208 1209 /* Now set up the stations */ 1210 for (i = 0, vector = 1; i < vsi->shared->isc_nrxqsets; i++, vector++, rx_que++) { 1211 rid = vector + 1; 1212 1213 snprintf(buf, sizeof(buf), "rxq%d", i); 1214 err = iflib_irq_alloc_generic(ctx, &rx_que->que_irq, rid, 1215 IFLIB_INTR_RXTX, ixl_msix_que, rx_que, rx_que->rxr.me, buf); 1216 /* XXX: Does the driver work as expected if there are fewer num_rx_queues than 1217 * what's expected in the iflib context? */ 1218 if (err) { 1219 device_printf(iflib_get_dev(ctx), 1220 "Failed to allocate queue RX int vector %d, err: %d\n", i, err); 1221 vsi->num_rx_queues = i + 1; 1222 goto fail; 1223 } 1224 rx_que->msix = vector; 1225 } 1226 1227 bzero(buf, sizeof(buf)); 1228 1229 for (i = 0; i < vsi->shared->isc_ntxqsets; i++, tx_que++) { 1230 snprintf(buf, sizeof(buf), "txq%d", i); 1231 iflib_softirq_alloc_generic(ctx, 1232 &vsi->rx_queues[i % vsi->shared->isc_nrxqsets].que_irq, 1233 IFLIB_INTR_TX, tx_que, tx_que->txr.me, buf); 1234 1235 /* TODO: Maybe call a strategy function for this to figure out which 1236 * interrupts to map Tx queues to. I don't know if there's an immediately 1237 * better way than this other than a user-supplied map, though. */ 1238 tx_que->msix = (i % vsi->shared->isc_nrxqsets) + 1; 1239 } 1240 1241 return (0); 1242 fail: 1243 iflib_irq_free(ctx, &vsi->irq); 1244 rx_que = vsi->rx_queues; 1245 for (int i = 0; i < vsi->num_rx_queues; i++, rx_que++) 1246 iflib_irq_free(ctx, &rx_que->que_irq); 1247 return (err); 1248 } 1249 1250 /* 1251 * Enable all interrupts 1252 * 1253 * Called in: 1254 * iflib_init_locked, after ixl_if_init() 1255 */ 1256 static void 1257 ixl_if_enable_intr(if_ctx_t ctx) 1258 { 1259 struct ixl_pf *pf = iflib_get_softc(ctx); 1260 struct ixl_vsi *vsi = &pf->vsi; 1261 struct i40e_hw *hw = vsi->hw; 1262 struct ixl_rx_queue *rx_que = vsi->rx_queues; 1263 1264 ixl_enable_intr0(hw); 1265 /* Enable queue interrupts */ 1266 if (vsi->shared->isc_intr == IFLIB_INTR_MSIX) { 1267 for (int i = 0; i < vsi->num_rx_queues; i++, rx_que++) 1268 ixl_enable_queue(hw, rx_que->rxr.me); 1269 } else { 1270 /* 1271 * Set PFINT_LNKLST0 FIRSTQ_INDX to 0x0 to enable 1272 * triggering interrupts by queues. 1273 */ 1274 wr32(hw, I40E_PFINT_LNKLST0, 0x0); 1275 } 1276 } 1277 1278 /* 1279 * Disable queue interrupts 1280 * 1281 * Other interrupt causes need to remain active. 1282 */ 1283 static void 1284 ixl_if_disable_intr(if_ctx_t ctx) 1285 { 1286 struct ixl_pf *pf = iflib_get_softc(ctx); 1287 struct ixl_vsi *vsi = &pf->vsi; 1288 struct i40e_hw *hw = vsi->hw; 1289 struct ixl_rx_queue *rx_que = vsi->rx_queues; 1290 1291 if (vsi->shared->isc_intr == IFLIB_INTR_MSIX) { 1292 for (int i = 0; i < vsi->num_rx_queues; i++, rx_que++) 1293 ixl_disable_queue(hw, rx_que->rxr.me); 1294 } else { 1295 /* 1296 * Set PFINT_LNKLST0 FIRSTQ_INDX to End of List (0x7FF) 1297 * to stop queues from triggering interrupts. 1298 */ 1299 wr32(hw, I40E_PFINT_LNKLST0, IXL_QUEUE_EOL); 1300 } 1301 } 1302 1303 static int 1304 ixl_if_rx_queue_intr_enable(if_ctx_t ctx, uint16_t rxqid) 1305 { 1306 struct ixl_pf *pf = iflib_get_softc(ctx); 1307 struct ixl_vsi *vsi = &pf->vsi; 1308 struct i40e_hw *hw = vsi->hw; 1309 struct ixl_rx_queue *rx_que = &vsi->rx_queues[rxqid]; 1310 1311 ixl_enable_queue(hw, rx_que->msix - 1); 1312 return (0); 1313 } 1314 1315 static int 1316 ixl_if_tx_queue_intr_enable(if_ctx_t ctx, uint16_t txqid) 1317 { 1318 struct ixl_pf *pf = iflib_get_softc(ctx); 1319 struct ixl_vsi *vsi = &pf->vsi; 1320 struct i40e_hw *hw = vsi->hw; 1321 struct ixl_tx_queue *tx_que = &vsi->tx_queues[txqid]; 1322 1323 ixl_enable_queue(hw, tx_que->msix - 1); 1324 return (0); 1325 } 1326 1327 static int 1328 ixl_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int ntxqs, int ntxqsets) 1329 { 1330 struct ixl_pf *pf = iflib_get_softc(ctx); 1331 struct ixl_vsi *vsi = &pf->vsi; 1332 if_softc_ctx_t scctx = vsi->shared; 1333 struct ixl_tx_queue *que; 1334 int i, j, error = 0; 1335 1336 MPASS(scctx->isc_ntxqsets > 0); 1337 MPASS(ntxqs == 1); 1338 MPASS(scctx->isc_ntxqsets == ntxqsets); 1339 1340 /* Allocate queue structure memory */ 1341 if (!(vsi->tx_queues = 1342 (struct ixl_tx_queue *) malloc(sizeof(struct ixl_tx_queue) *ntxqsets, M_IXL, M_NOWAIT | M_ZERO))) { 1343 device_printf(iflib_get_dev(ctx), "Unable to allocate TX ring memory\n"); 1344 return (ENOMEM); 1345 } 1346 1347 for (i = 0, que = vsi->tx_queues; i < ntxqsets; i++, que++) { 1348 struct tx_ring *txr = &que->txr; 1349 1350 txr->me = i; 1351 que->vsi = vsi; 1352 1353 if (!vsi->enable_head_writeback) { 1354 /* Allocate report status array */ 1355 if (!(txr->tx_rsq = malloc(sizeof(qidx_t) * scctx->isc_ntxd[0], M_IXL, M_NOWAIT))) { 1356 device_printf(iflib_get_dev(ctx), "failed to allocate tx_rsq memory\n"); 1357 error = ENOMEM; 1358 goto fail; 1359 } 1360 /* Init report status array */ 1361 for (j = 0; j < scctx->isc_ntxd[0]; j++) 1362 txr->tx_rsq[j] = QIDX_INVALID; 1363 } 1364 /* get the virtual and physical address of the hardware queues */ 1365 txr->tail = I40E_QTX_TAIL(txr->me); 1366 txr->tx_base = (struct i40e_tx_desc *)vaddrs[i * ntxqs]; 1367 txr->tx_paddr = paddrs[i * ntxqs]; 1368 txr->que = que; 1369 } 1370 1371 return (0); 1372 fail: 1373 ixl_if_queues_free(ctx); 1374 return (error); 1375 } 1376 1377 static int 1378 ixl_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int nrxqs, int nrxqsets) 1379 { 1380 struct ixl_pf *pf = iflib_get_softc(ctx); 1381 struct ixl_vsi *vsi = &pf->vsi; 1382 struct ixl_rx_queue *que; 1383 int i, error = 0; 1384 1385 #ifdef INVARIANTS 1386 if_softc_ctx_t scctx = vsi->shared; 1387 MPASS(scctx->isc_nrxqsets > 0); 1388 MPASS(nrxqs == 1); 1389 MPASS(scctx->isc_nrxqsets == nrxqsets); 1390 #endif 1391 1392 /* Allocate queue structure memory */ 1393 if (!(vsi->rx_queues = 1394 (struct ixl_rx_queue *) malloc(sizeof(struct ixl_rx_queue) * 1395 nrxqsets, M_IXL, M_NOWAIT | M_ZERO))) { 1396 device_printf(iflib_get_dev(ctx), "Unable to allocate RX ring memory\n"); 1397 error = ENOMEM; 1398 goto fail; 1399 } 1400 1401 for (i = 0, que = vsi->rx_queues; i < nrxqsets; i++, que++) { 1402 struct rx_ring *rxr = &que->rxr; 1403 1404 rxr->me = i; 1405 que->vsi = vsi; 1406 1407 /* get the virtual and physical address of the hardware queues */ 1408 rxr->tail = I40E_QRX_TAIL(rxr->me); 1409 rxr->rx_base = (union i40e_rx_desc *)vaddrs[i * nrxqs]; 1410 rxr->rx_paddr = paddrs[i * nrxqs]; 1411 rxr->que = que; 1412 } 1413 1414 return (0); 1415 fail: 1416 ixl_if_queues_free(ctx); 1417 return (error); 1418 } 1419 1420 static void 1421 ixl_if_queues_free(if_ctx_t ctx) 1422 { 1423 struct ixl_pf *pf = iflib_get_softc(ctx); 1424 struct ixl_vsi *vsi = &pf->vsi; 1425 1426 if (vsi->tx_queues != NULL && !vsi->enable_head_writeback) { 1427 struct ixl_tx_queue *que; 1428 int i = 0; 1429 1430 for (i = 0, que = vsi->tx_queues; i < vsi->num_tx_queues; i++, que++) { 1431 struct tx_ring *txr = &que->txr; 1432 if (txr->tx_rsq != NULL) { 1433 free(txr->tx_rsq, M_IXL); 1434 txr->tx_rsq = NULL; 1435 } 1436 } 1437 } 1438 1439 if (vsi->tx_queues != NULL) { 1440 free(vsi->tx_queues, M_IXL); 1441 vsi->tx_queues = NULL; 1442 } 1443 if (vsi->rx_queues != NULL) { 1444 free(vsi->rx_queues, M_IXL); 1445 vsi->rx_queues = NULL; 1446 } 1447 1448 if (!IXL_PF_IN_RECOVERY_MODE(pf)) 1449 sysctl_ctx_free(&vsi->sysctl_ctx); 1450 } 1451 1452 void 1453 ixl_update_link_status(struct ixl_pf *pf) 1454 { 1455 struct ixl_vsi *vsi = &pf->vsi; 1456 struct i40e_hw *hw = &pf->hw; 1457 u64 baudrate; 1458 1459 if (pf->link_up) { 1460 if (vsi->link_active == FALSE) { 1461 vsi->link_active = TRUE; 1462 baudrate = ixl_max_aq_speed_to_value(hw->phy.link_info.link_speed); 1463 iflib_link_state_change(vsi->ctx, LINK_STATE_UP, baudrate); 1464 ixl_link_up_msg(pf); 1465 #ifdef PCI_IOV 1466 ixl_broadcast_link_state(pf); 1467 #endif 1468 } 1469 } else { /* Link down */ 1470 if (vsi->link_active == TRUE) { 1471 vsi->link_active = FALSE; 1472 iflib_link_state_change(vsi->ctx, LINK_STATE_DOWN, 0); 1473 #ifdef PCI_IOV 1474 ixl_broadcast_link_state(pf); 1475 #endif 1476 } 1477 } 1478 } 1479 1480 static void 1481 ixl_handle_lan_overflow_event(struct ixl_pf *pf, struct i40e_arq_event_info *e) 1482 { 1483 device_t dev = pf->dev; 1484 u32 rxq_idx, qtx_ctl; 1485 1486 rxq_idx = (le32toh(e->desc.params.external.param0) & 1487 I40E_PRTDCB_RUPTQ_RXQNUM_MASK) >> 1488 I40E_PRTDCB_RUPTQ_RXQNUM_SHIFT; 1489 qtx_ctl = le32toh(e->desc.params.external.param1); 1490 1491 device_printf(dev, "LAN overflow event: global rxq_idx %d\n", rxq_idx); 1492 device_printf(dev, "LAN overflow event: QTX_CTL 0x%08x\n", qtx_ctl); 1493 } 1494 1495 static int 1496 ixl_process_adminq(struct ixl_pf *pf, u16 *pending) 1497 { 1498 enum i40e_status_code status = I40E_SUCCESS; 1499 struct i40e_arq_event_info event; 1500 struct i40e_hw *hw = &pf->hw; 1501 device_t dev = pf->dev; 1502 u16 opcode; 1503 u32 loop = 0, reg; 1504 1505 event.buf_len = IXL_AQ_BUF_SZ; 1506 event.msg_buf = malloc(event.buf_len, M_IXL, M_NOWAIT | M_ZERO); 1507 if (!event.msg_buf) { 1508 device_printf(dev, "%s: Unable to allocate memory for Admin" 1509 " Queue event!\n", __func__); 1510 return (ENOMEM); 1511 } 1512 1513 /* clean and process any events */ 1514 do { 1515 status = i40e_clean_arq_element(hw, &event, pending); 1516 if (status) 1517 break; 1518 opcode = LE16_TO_CPU(event.desc.opcode); 1519 ixl_dbg(pf, IXL_DBG_AQ, 1520 "Admin Queue event: %#06x\n", opcode); 1521 switch (opcode) { 1522 case i40e_aqc_opc_get_link_status: 1523 ixl_link_event(pf, &event); 1524 break; 1525 case i40e_aqc_opc_send_msg_to_pf: 1526 #ifdef PCI_IOV 1527 ixl_handle_vf_msg(pf, &event); 1528 #endif 1529 break; 1530 /* 1531 * This should only occur on no-drop queues, which 1532 * aren't currently configured. 1533 */ 1534 case i40e_aqc_opc_event_lan_overflow: 1535 ixl_handle_lan_overflow_event(pf, &event); 1536 break; 1537 default: 1538 break; 1539 } 1540 } while (*pending && (loop++ < IXL_ADM_LIMIT)); 1541 1542 free(event.msg_buf, M_IXL); 1543 1544 /* Re-enable admin queue interrupt cause */ 1545 reg = rd32(hw, I40E_PFINT_ICR0_ENA); 1546 reg |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; 1547 wr32(hw, I40E_PFINT_ICR0_ENA, reg); 1548 1549 return (status); 1550 } 1551 1552 static void 1553 ixl_if_update_admin_status(if_ctx_t ctx) 1554 { 1555 struct ixl_pf *pf = iflib_get_softc(ctx); 1556 struct i40e_hw *hw = &pf->hw; 1557 u16 pending; 1558 1559 if (IXL_PF_IS_RESETTING(pf)) 1560 ixl_handle_empr_reset(pf); 1561 1562 /* 1563 * Admin Queue is shut down while handling reset. 1564 * Don't proceed if it hasn't been re-initialized 1565 * e.g due to an issue with new FW. 1566 */ 1567 if (!i40e_check_asq_alive(&pf->hw)) 1568 return; 1569 1570 if (ixl_test_state(&pf->state, IXL_STATE_MDD_PENDING)) 1571 ixl_handle_mdd_event(pf); 1572 1573 ixl_process_adminq(pf, &pending); 1574 ixl_update_link_status(pf); 1575 1576 /* 1577 * If there are still messages to process, reschedule ourselves. 1578 * Otherwise, re-enable our interrupt and go to sleep. 1579 */ 1580 if (pending > 0) 1581 iflib_admin_intr_deferred(ctx); 1582 else 1583 ixl_enable_intr0(hw); 1584 } 1585 1586 static void 1587 ixl_if_multi_set(if_ctx_t ctx) 1588 { 1589 struct ixl_pf *pf = iflib_get_softc(ctx); 1590 struct ixl_vsi *vsi = &pf->vsi; 1591 struct i40e_hw *hw = vsi->hw; 1592 enum i40e_status_code status; 1593 int mcnt; 1594 if_t ifp = iflib_get_ifp(ctx); 1595 1596 IOCTL_DEBUGOUT("ixl_if_multi_set: begin"); 1597 1598 /* Delete filters for removed multicast addresses */ 1599 ixl_del_multi(vsi, false); 1600 1601 mcnt = min(if_llmaddr_count(ifp), MAX_MULTICAST_ADDR); 1602 if (__predict_false(mcnt == MAX_MULTICAST_ADDR)) { 1603 /* Check if promisc mode is already enabled, if yes return */ 1604 if (vsi->flags & IXL_FLAGS_MC_PROMISC) 1605 return; 1606 1607 status = i40e_aq_set_vsi_multicast_promiscuous(hw, 1608 vsi->seid, TRUE, NULL); 1609 if (status != I40E_SUCCESS) 1610 if_printf(ifp, "Failed to enable multicast promiscuous " 1611 "mode, status: %s\n", i40e_stat_str(hw, status)); 1612 else { 1613 if_printf(ifp, "Enabled multicast promiscuous mode\n"); 1614 1615 /* Set the flag to track promiscuous mode */ 1616 vsi->flags |= IXL_FLAGS_MC_PROMISC; 1617 } 1618 /* Delete all existing MC filters */ 1619 ixl_del_multi(vsi, true); 1620 return; 1621 } 1622 1623 ixl_add_multi(vsi); 1624 IOCTL_DEBUGOUT("ixl_if_multi_set: end"); 1625 } 1626 1627 static int 1628 ixl_if_mtu_set(if_ctx_t ctx, uint32_t mtu) 1629 { 1630 struct ixl_pf *pf = iflib_get_softc(ctx); 1631 struct ixl_vsi *vsi = &pf->vsi; 1632 1633 IOCTL_DEBUGOUT("ioctl: SIOCSIFMTU (Set Interface MTU)"); 1634 if (mtu > IXL_MAX_FRAME - ETHER_HDR_LEN - ETHER_CRC_LEN - 1635 ETHER_VLAN_ENCAP_LEN) 1636 return (EINVAL); 1637 1638 vsi->shared->isc_max_frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN + 1639 ETHER_VLAN_ENCAP_LEN; 1640 1641 return (0); 1642 } 1643 1644 static void 1645 ixl_if_media_status(if_ctx_t ctx, struct ifmediareq *ifmr) 1646 { 1647 struct ixl_pf *pf = iflib_get_softc(ctx); 1648 struct i40e_hw *hw = &pf->hw; 1649 1650 INIT_DEBUGOUT("ixl_media_status: begin"); 1651 1652 ifmr->ifm_status = IFM_AVALID; 1653 ifmr->ifm_active = IFM_ETHER; 1654 1655 if (!pf->link_up) { 1656 return; 1657 } 1658 1659 ifmr->ifm_status |= IFM_ACTIVE; 1660 /* Hardware is always full-duplex */ 1661 ifmr->ifm_active |= IFM_FDX; 1662 1663 switch (hw->phy.link_info.phy_type) { 1664 /* 100 M */ 1665 case I40E_PHY_TYPE_100BASE_TX: 1666 ifmr->ifm_active |= IFM_100_TX; 1667 break; 1668 /* 1 G */ 1669 case I40E_PHY_TYPE_1000BASE_T: 1670 ifmr->ifm_active |= IFM_1000_T; 1671 break; 1672 case I40E_PHY_TYPE_1000BASE_SX: 1673 ifmr->ifm_active |= IFM_1000_SX; 1674 break; 1675 case I40E_PHY_TYPE_1000BASE_LX: 1676 ifmr->ifm_active |= IFM_1000_LX; 1677 break; 1678 case I40E_PHY_TYPE_1000BASE_T_OPTICAL: 1679 ifmr->ifm_active |= IFM_1000_T; 1680 break; 1681 /* 2.5 G */ 1682 case I40E_PHY_TYPE_2_5GBASE_T_LINK_STATUS: 1683 ifmr->ifm_active |= IFM_2500_T; 1684 break; 1685 /* 5 G */ 1686 case I40E_PHY_TYPE_5GBASE_T_LINK_STATUS: 1687 ifmr->ifm_active |= IFM_5000_T; 1688 break; 1689 /* 10 G */ 1690 case I40E_PHY_TYPE_10GBASE_SFPP_CU: 1691 ifmr->ifm_active |= IFM_10G_TWINAX; 1692 break; 1693 case I40E_PHY_TYPE_10GBASE_SR: 1694 ifmr->ifm_active |= IFM_10G_SR; 1695 break; 1696 case I40E_PHY_TYPE_10GBASE_LR: 1697 ifmr->ifm_active |= IFM_10G_LR; 1698 break; 1699 case I40E_PHY_TYPE_10GBASE_T: 1700 ifmr->ifm_active |= IFM_10G_T; 1701 break; 1702 case I40E_PHY_TYPE_XAUI: 1703 case I40E_PHY_TYPE_XFI: 1704 ifmr->ifm_active |= IFM_10G_TWINAX; 1705 break; 1706 case I40E_PHY_TYPE_10GBASE_AOC: 1707 ifmr->ifm_active |= IFM_10G_AOC; 1708 break; 1709 /* 25 G */ 1710 case I40E_PHY_TYPE_25GBASE_KR: 1711 ifmr->ifm_active |= IFM_25G_KR; 1712 break; 1713 case I40E_PHY_TYPE_25GBASE_CR: 1714 ifmr->ifm_active |= IFM_25G_CR; 1715 break; 1716 case I40E_PHY_TYPE_25GBASE_SR: 1717 ifmr->ifm_active |= IFM_25G_SR; 1718 break; 1719 case I40E_PHY_TYPE_25GBASE_LR: 1720 ifmr->ifm_active |= IFM_25G_LR; 1721 break; 1722 case I40E_PHY_TYPE_25GBASE_AOC: 1723 ifmr->ifm_active |= IFM_25G_AOC; 1724 break; 1725 case I40E_PHY_TYPE_25GBASE_ACC: 1726 ifmr->ifm_active |= IFM_25G_ACC; 1727 break; 1728 /* 40 G */ 1729 case I40E_PHY_TYPE_40GBASE_CR4: 1730 case I40E_PHY_TYPE_40GBASE_CR4_CU: 1731 ifmr->ifm_active |= IFM_40G_CR4; 1732 break; 1733 case I40E_PHY_TYPE_40GBASE_SR4: 1734 ifmr->ifm_active |= IFM_40G_SR4; 1735 break; 1736 case I40E_PHY_TYPE_40GBASE_LR4: 1737 ifmr->ifm_active |= IFM_40G_LR4; 1738 break; 1739 case I40E_PHY_TYPE_XLAUI: 1740 ifmr->ifm_active |= IFM_OTHER; 1741 break; 1742 case I40E_PHY_TYPE_1000BASE_KX: 1743 ifmr->ifm_active |= IFM_1000_KX; 1744 break; 1745 case I40E_PHY_TYPE_SGMII: 1746 ifmr->ifm_active |= IFM_1000_SGMII; 1747 break; 1748 /* ERJ: What's the difference between these? */ 1749 case I40E_PHY_TYPE_10GBASE_CR1_CU: 1750 case I40E_PHY_TYPE_10GBASE_CR1: 1751 ifmr->ifm_active |= IFM_10G_CR1; 1752 break; 1753 case I40E_PHY_TYPE_10GBASE_KX4: 1754 ifmr->ifm_active |= IFM_10G_KX4; 1755 break; 1756 case I40E_PHY_TYPE_10GBASE_KR: 1757 ifmr->ifm_active |= IFM_10G_KR; 1758 break; 1759 case I40E_PHY_TYPE_SFI: 1760 ifmr->ifm_active |= IFM_10G_SFI; 1761 break; 1762 /* Our single 20G media type */ 1763 case I40E_PHY_TYPE_20GBASE_KR2: 1764 ifmr->ifm_active |= IFM_20G_KR2; 1765 break; 1766 case I40E_PHY_TYPE_40GBASE_KR4: 1767 ifmr->ifm_active |= IFM_40G_KR4; 1768 break; 1769 case I40E_PHY_TYPE_XLPPI: 1770 case I40E_PHY_TYPE_40GBASE_AOC: 1771 ifmr->ifm_active |= IFM_40G_XLPPI; 1772 break; 1773 /* Unknown to driver */ 1774 default: 1775 ifmr->ifm_active |= IFM_UNKNOWN; 1776 break; 1777 } 1778 /* Report flow control status as well */ 1779 if (hw->phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) 1780 ifmr->ifm_active |= IFM_ETH_TXPAUSE; 1781 if (hw->phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX) 1782 ifmr->ifm_active |= IFM_ETH_RXPAUSE; 1783 } 1784 1785 static int 1786 ixl_if_media_change(if_ctx_t ctx) 1787 { 1788 struct ifmedia *ifm = iflib_get_media(ctx); 1789 1790 INIT_DEBUGOUT("ixl_media_change: begin"); 1791 1792 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) 1793 return (EINVAL); 1794 1795 if_printf(iflib_get_ifp(ctx), "Media change is not supported.\n"); 1796 return (ENODEV); 1797 } 1798 1799 static int 1800 ixl_if_promisc_set(if_ctx_t ctx, int flags) 1801 { 1802 struct ixl_pf *pf = iflib_get_softc(ctx); 1803 struct ixl_vsi *vsi = &pf->vsi; 1804 if_t ifp = iflib_get_ifp(ctx); 1805 struct i40e_hw *hw = vsi->hw; 1806 int err; 1807 bool uni = FALSE, multi = FALSE; 1808 1809 if (flags & IFF_PROMISC) 1810 uni = multi = TRUE; 1811 else if (flags & IFF_ALLMULTI || if_llmaddr_count(ifp) >= 1812 MAX_MULTICAST_ADDR) 1813 multi = TRUE; 1814 1815 err = i40e_aq_set_vsi_unicast_promiscuous(hw, 1816 vsi->seid, uni, NULL, true); 1817 if (err) 1818 return (err); 1819 err = i40e_aq_set_vsi_multicast_promiscuous(hw, 1820 vsi->seid, multi, NULL); 1821 1822 /* Update the multicast promiscuous flag based on the new state */ 1823 if (multi) 1824 vsi->flags |= IXL_FLAGS_MC_PROMISC; 1825 else 1826 vsi->flags &= ~IXL_FLAGS_MC_PROMISC; 1827 1828 return (err); 1829 } 1830 1831 static void 1832 ixl_if_timer(if_ctx_t ctx, uint16_t qid) 1833 { 1834 struct ixl_pf *pf = iflib_get_softc(ctx); 1835 1836 if (qid != 0) 1837 return; 1838 1839 ixl_update_stats_counters(pf); 1840 } 1841 1842 static void 1843 ixl_if_vlan_register(if_ctx_t ctx, u16 vtag) 1844 { 1845 struct ixl_pf *pf = iflib_get_softc(ctx); 1846 struct ixl_vsi *vsi = &pf->vsi; 1847 struct i40e_hw *hw = vsi->hw; 1848 if_t ifp = iflib_get_ifp(ctx); 1849 1850 if ((vtag == 0) || (vtag > 4095)) /* Invalid */ 1851 return; 1852 1853 /* 1854 * Keep track of registered VLANS to know what 1855 * filters have to be configured when VLAN_HWFILTER 1856 * capability is enabled. 1857 */ 1858 ++vsi->num_vlans; 1859 bit_set(vsi->vlans_map, vtag); 1860 1861 if ((if_getcapenable(ifp) & IFCAP_VLAN_HWFILTER) == 0) 1862 return; 1863 1864 if (vsi->num_vlans < IXL_MAX_VLAN_FILTERS) 1865 ixl_add_filter(vsi, hw->mac.addr, vtag); 1866 else if (vsi->num_vlans == IXL_MAX_VLAN_FILTERS) { 1867 /* 1868 * There is not enough HW resources to add filters 1869 * for all registered VLANs. Re-configure filtering 1870 * to allow reception of all expected traffic. 1871 */ 1872 device_printf(vsi->dev, 1873 "Not enough HW filters for all VLANs. VLAN HW filtering disabled"); 1874 ixl_del_all_vlan_filters(vsi, hw->mac.addr); 1875 ixl_add_filter(vsi, hw->mac.addr, IXL_VLAN_ANY); 1876 } 1877 } 1878 1879 static void 1880 ixl_if_vlan_unregister(if_ctx_t ctx, u16 vtag) 1881 { 1882 struct ixl_pf *pf = iflib_get_softc(ctx); 1883 struct ixl_vsi *vsi = &pf->vsi; 1884 struct i40e_hw *hw = vsi->hw; 1885 if_t ifp = iflib_get_ifp(ctx); 1886 1887 if ((vtag == 0) || (vtag > 4095)) /* Invalid */ 1888 return; 1889 1890 --vsi->num_vlans; 1891 bit_clear(vsi->vlans_map, vtag); 1892 1893 if ((if_getcapenable(ifp) & IFCAP_VLAN_HWFILTER) == 0) 1894 return; 1895 1896 /* One filter is used for untagged frames */ 1897 if (vsi->num_vlans < IXL_MAX_VLAN_FILTERS - 1) 1898 ixl_del_filter(vsi, hw->mac.addr, vtag); 1899 else if (vsi->num_vlans == IXL_MAX_VLAN_FILTERS - 1) { 1900 ixl_del_filter(vsi, hw->mac.addr, IXL_VLAN_ANY); 1901 ixl_add_vlan_filters(vsi, hw->mac.addr); 1902 } 1903 } 1904 1905 static uint64_t 1906 ixl_if_get_counter(if_ctx_t ctx, ift_counter cnt) 1907 { 1908 struct ixl_pf *pf = iflib_get_softc(ctx); 1909 struct ixl_vsi *vsi = &pf->vsi; 1910 if_t ifp = iflib_get_ifp(ctx); 1911 1912 switch (cnt) { 1913 case IFCOUNTER_IPACKETS: 1914 return (vsi->ipackets); 1915 case IFCOUNTER_IERRORS: 1916 return (vsi->ierrors); 1917 case IFCOUNTER_OPACKETS: 1918 return (vsi->opackets); 1919 case IFCOUNTER_OERRORS: 1920 return (if_get_counter_default(ifp, cnt) + vsi->oerrors); 1921 case IFCOUNTER_COLLISIONS: 1922 /* Collisions are by standard impossible in 40G/10G Ethernet */ 1923 return (0); 1924 case IFCOUNTER_IBYTES: 1925 return (vsi->ibytes); 1926 case IFCOUNTER_OBYTES: 1927 return (vsi->obytes); 1928 case IFCOUNTER_IMCASTS: 1929 return (vsi->imcasts); 1930 case IFCOUNTER_OMCASTS: 1931 return (vsi->omcasts); 1932 case IFCOUNTER_IQDROPS: 1933 return (vsi->iqdrops); 1934 case IFCOUNTER_OQDROPS: 1935 return (if_get_counter_default(ifp, cnt) + vsi->oqdrops); 1936 case IFCOUNTER_NOPROTO: 1937 return (vsi->noproto); 1938 default: 1939 return (if_get_counter_default(ifp, cnt)); 1940 } 1941 } 1942 1943 #ifdef PCI_IOV 1944 static void 1945 ixl_if_vflr_handle(if_ctx_t ctx) 1946 { 1947 struct ixl_pf *pf = iflib_get_softc(ctx); 1948 1949 ixl_handle_vflr(pf); 1950 } 1951 #endif 1952 1953 static int 1954 ixl_if_i2c_req(if_ctx_t ctx, struct ifi2creq *req) 1955 { 1956 struct ixl_pf *pf = iflib_get_softc(ctx); 1957 1958 if (pf->read_i2c_byte == NULL) 1959 return (EINVAL); 1960 1961 for (int i = 0; i < req->len; i++) 1962 if (pf->read_i2c_byte(pf, req->offset + i, 1963 req->dev_addr, &req->data[i])) 1964 return (EIO); 1965 return (0); 1966 } 1967 1968 static int 1969 ixl_if_priv_ioctl(if_ctx_t ctx, u_long command, caddr_t data) 1970 { 1971 struct ixl_pf *pf = iflib_get_softc(ctx); 1972 struct ifdrv *ifd = (struct ifdrv *)data; 1973 int error = 0; 1974 1975 /* 1976 * The iflib_if_ioctl forwards SIOCxDRVSPEC and SIOGPRIVATE_0 without 1977 * performing privilege checks. It is important that this function 1978 * perform the necessary checks for commands which should only be 1979 * executed by privileged threads. 1980 */ 1981 1982 switch(command) { 1983 case SIOCGDRVSPEC: 1984 case SIOCSDRVSPEC: 1985 /* NVM update command */ 1986 if (ifd->ifd_cmd == I40E_NVM_ACCESS) { 1987 error = priv_check(curthread, PRIV_DRIVER); 1988 if (error) 1989 break; 1990 error = ixl_handle_nvmupd_cmd(pf, ifd); 1991 } else { 1992 error = EINVAL; 1993 } 1994 break; 1995 default: 1996 error = EOPNOTSUPP; 1997 } 1998 1999 return (error); 2000 } 2001 2002 /* ixl_if_needs_restart - Tell iflib when the driver needs to be reinitialized 2003 * @ctx: iflib context 2004 * @event: event code to check 2005 * 2006 * Defaults to returning false for every event. 2007 * 2008 * @returns true if iflib needs to reinit the interface, false otherwise 2009 */ 2010 static bool 2011 ixl_if_needs_restart(if_ctx_t ctx __unused, enum iflib_restart_event event) 2012 { 2013 switch (event) { 2014 case IFLIB_RESTART_VLAN_CONFIG: 2015 default: 2016 return (false); 2017 } 2018 } 2019 2020 static int 2021 ixl_if_vf_status(if_ctx_t ctx, struct if_vf_status **statusp) 2022 { 2023 struct ixl_pf *pf; 2024 struct if_vf_extension *extension; 2025 struct if_vf_info *info; 2026 struct if_vf_status *status; 2027 struct ixl_vf *vf; 2028 2029 pf = iflib_get_softc(ctx); 2030 if (!pf->iov_attached) 2031 return (EOPNOTSUPP); 2032 2033 status = if_vf_status_alloc(pf->num_vfs); 2034 if (status == NULL) 2035 return (ENOMEM); 2036 for (int i = 0; i < pf->num_vfs; i++) { 2037 vf = &pf->vfs[i]; 2038 info = &status->vfs[i]; 2039 info->fields = IFVF_F_CONFIGURED | IFVF_F_INITIALIZED | 2040 IFVF_F_VLAN_MODE | IFVF_F_VLAN_COUNT | 2041 IFVF_F_NUM_TX_QUEUES | IFVF_F_NUM_RX_QUEUES | 2042 IFVF_F_ALLOW_SET_MAC | 2043 IFVF_F_ALLOW_SET_VLAN | IFVF_F_MAC_ANTI_SPOOF | 2044 IFVF_F_ALLOW_PROMISC | IFVF_F_TRAFFIC_ALLOWED | 2045 IFVF_F_FAULT_BLOCKED; 2046 info->index = i; 2047 info->configured = (vf->vf_flags & VF_FLAG_ENABLED) != 0; 2048 info->initialized = (vf->vf_flags & VF_FLAG_INITIALIZED) != 0; 2049 if (info->initialized) { 2050 snprintf(info->api_version, sizeof(info->api_version), 2051 "%u.%u", vf->version.major, vf->version.minor); 2052 info->fields |= IFVF_F_API_VERSION; 2053 } 2054 if (!ETHER_IS_ZERO(vf->mac)) { 2055 memcpy(info->mac, vf->mac, sizeof(info->mac)); 2056 info->fields |= IFVF_F_MAC; 2057 } 2058 if (vf->default_vlan == 0) { 2059 info->vlan_mode = IFVF_VLAN_TRUNK; 2060 info->vlan_count = vf->vsi.num_vlans; 2061 info->vlan_limit = IXL_VF_MAX_VLAN_FILTERS; 2062 info->fields |= IFVF_F_VLAN_LIMIT; 2063 } else { 2064 info->vlan_mode = IFVF_VLAN_ACCESS; 2065 info->vlan = vf->default_vlan; 2066 info->vlan_pcp = 0; 2067 info->vlan_proto = ETHERTYPE_VLAN; 2068 info->vlan_count = 1; 2069 info->fields |= IFVF_F_VLAN | IFVF_F_VLAN_PCP | 2070 IFVF_F_VLAN_PROTO; 2071 } 2072 info->tx_queue_count = vf->qtag.num_active; 2073 info->rx_queue_count = vf->qtag.num_active; 2074 info->allow_set_mac = 2075 (vf->vf_flags & VF_FLAG_SET_MAC_CAP) != 0; 2076 info->allow_set_vlan = 2077 (vf->vf_flags & VF_FLAG_VLAN_CAP) != 0; 2078 info->mac_anti_spoof = 2079 (vf->vf_flags & VF_FLAG_MAC_ANTI_SPOOF) != 0; 2080 info->allow_promisc = 2081 (vf->vf_flags & VF_FLAG_PROMISC_CAP) != 0; 2082 info->traffic_allowed = info->configured && !vf->mdd_blocked; 2083 info->fault_blocked = vf->mdd_blocked; 2084 2085 extension = if_vf_status_add_extension(info, 2086 IXL_VF_STATUS_NAMESPACE, IXL_VF_STATUS_VERSION, 2087 IXL_VF_STATUS_NUM_FIELDS); 2088 if (extension == NULL) { 2089 if_vf_status_free(status); 2090 return (ENOMEM); 2091 } 2092 if_vf_extension_set_bool(extension, 2093 IXL_VF_STATUS_FIELD_MDD_BLOCKED, 2094 IXL_VF_STATUS_MDD_BLOCKED, vf->mdd_blocked); 2095 if_vf_extension_set_number(extension, 2096 IXL_VF_STATUS_FIELD_MDD_TX_EVENTS, 2097 IXL_VF_STATUS_MDD_TX_EVENTS, vf->mdd_tx_events); 2098 if_vf_extension_set_number(extension, 2099 IXL_VF_STATUS_FIELD_MDD_RX_EVENTS, 2100 IXL_VF_STATUS_MDD_RX_EVENTS, vf->mdd_rx_events); 2101 } 2102 *statusp = status; 2103 return (0); 2104 } 2105 2106 /* 2107 * Sanity check and save off tunable values. 2108 */ 2109 static void 2110 ixl_save_pf_tunables(struct ixl_pf *pf) 2111 { 2112 device_t dev = pf->dev; 2113 2114 /* Save tunable information */ 2115 #ifdef IXL_DEBUG_FC 2116 pf->enable_tx_fc_filter = ixl_enable_tx_fc_filter; 2117 #endif 2118 #ifdef IXL_DEBUG 2119 pf->recovery_mode = ixl_debug_recovery_mode; 2120 #endif 2121 pf->dbg_mask = ixl_core_debug_mask; 2122 pf->hw.debug_mask = ixl_shared_debug_mask; 2123 pf->vsi.enable_head_writeback = !!(ixl_enable_head_writeback); 2124 pf->enable_vf_loopback = !!(ixl_enable_vf_loopback); 2125 pf->mdd_auto_reset_vf = !!(ixl_mdd_auto_reset_vf); 2126 #if 0 2127 pf->dynamic_rx_itr = ixl_dynamic_rx_itr; 2128 pf->dynamic_tx_itr = ixl_dynamic_tx_itr; 2129 #endif 2130 2131 if (ixl_i2c_access_method > 3 || ixl_i2c_access_method < 0) 2132 pf->i2c_access_method = 0; 2133 else 2134 pf->i2c_access_method = ixl_i2c_access_method; 2135 2136 if (ixl_tx_itr < 0 || ixl_tx_itr > IXL_MAX_ITR) { 2137 device_printf(dev, "Invalid tx_itr value of %d set!\n", 2138 ixl_tx_itr); 2139 device_printf(dev, "tx_itr must be between %d and %d, " 2140 "inclusive\n", 2141 0, IXL_MAX_ITR); 2142 device_printf(dev, "Using default value of %d instead\n", 2143 IXL_ITR_4K); 2144 pf->tx_itr = IXL_ITR_4K; 2145 } else 2146 pf->tx_itr = ixl_tx_itr; 2147 2148 if (ixl_rx_itr < 0 || ixl_rx_itr > IXL_MAX_ITR) { 2149 device_printf(dev, "Invalid rx_itr value of %d set!\n", 2150 ixl_rx_itr); 2151 device_printf(dev, "rx_itr must be between %d and %d, " 2152 "inclusive\n", 2153 0, IXL_MAX_ITR); 2154 device_printf(dev, "Using default value of %d instead\n", 2155 IXL_ITR_8K); 2156 pf->rx_itr = IXL_ITR_8K; 2157 } else 2158 pf->rx_itr = ixl_rx_itr; 2159 2160 pf->fc = -1; 2161 if (ixl_flow_control != -1) { 2162 if (ixl_flow_control < 0 || ixl_flow_control > 3) { 2163 device_printf(dev, 2164 "Invalid flow_control value of %d set!\n", 2165 ixl_flow_control); 2166 device_printf(dev, 2167 "flow_control must be between %d and %d, " 2168 "inclusive\n", 0, 3); 2169 device_printf(dev, 2170 "Using default configuration instead\n"); 2171 } else 2172 pf->fc = ixl_flow_control; 2173 } 2174 } 2175