1 /******************************************************************************
3 Copyright (c) 2013-2019, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
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.
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.
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.
32 ******************************************************************************/
40 #include "ixl_iw_int.h"
44 #include "ixl_pf_iov.h"
47 /*********************************************************************
49 *********************************************************************/
50 #define IXL_DRIVER_VERSION_MAJOR 1
51 #define IXL_DRIVER_VERSION_MINOR 11
52 #define IXL_DRIVER_VERSION_BUILD 9
54 char ixl_driver_version[] = __XSTRING(IXL_DRIVER_VERSION_MAJOR) "."
55 __XSTRING(IXL_DRIVER_VERSION_MINOR) "."
56 __XSTRING(IXL_DRIVER_VERSION_BUILD) "-k";
58 /*********************************************************************
61 * Used by probe to select devices to load on
62 * Last field stores an index into ixl_strings
63 * Last entry must be all 0s
65 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index }
66 *********************************************************************/
68 static ixl_vendor_info_t ixl_vendor_info_array[] =
70 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710, 0, 0, 0},
71 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B, 0, 0, 0},
72 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C, 0, 0, 0},
73 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A, 0, 0, 0},
74 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B, 0, 0, 0},
75 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C, 0, 0, 0},
76 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T, 0, 0, 0},
77 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T4, 0, 0, 0},
78 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_X722, 0, 0, 0},
79 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_X722, 0, 0, 0},
80 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722, 0, 0, 0},
81 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_X722, 0, 0, 0},
82 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_X722, 0, 0, 0},
83 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_I_X722, 0, 0, 0},
84 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_B, 0, 0, 0},
85 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_SFP28, 0, 0, 0},
86 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_BC, 0, 0, 0},
87 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_SFP, 0, 0, 0},
88 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_B, 0, 0, 0},
89 /* required last entry */
93 /*********************************************************************
94 * Table of branding strings
95 *********************************************************************/
97 static char *ixl_strings[] = {
98 "Intel(R) Ethernet Connection 700 Series PF Driver"
102 /*********************************************************************
103 * Function prototypes
104 *********************************************************************/
105 static int ixl_probe(device_t);
106 static int ixl_attach(device_t);
107 static int ixl_detach(device_t);
108 static int ixl_shutdown(device_t);
110 static int ixl_save_pf_tunables(struct ixl_pf *);
112 /*********************************************************************
113 * FreeBSD Device Interface Entry Points
114 *********************************************************************/
116 static device_method_t ixl_methods[] = {
117 /* Device interface */
118 DEVMETHOD(device_probe, ixl_probe),
119 DEVMETHOD(device_attach, ixl_attach),
120 DEVMETHOD(device_detach, ixl_detach),
121 DEVMETHOD(device_shutdown, ixl_shutdown),
123 DEVMETHOD(pci_iov_init, ixl_iov_init),
124 DEVMETHOD(pci_iov_uninit, ixl_iov_uninit),
125 DEVMETHOD(pci_iov_add_vf, ixl_add_vf),
130 static driver_t ixl_driver = {
131 "ixl", ixl_methods, sizeof(struct ixl_pf),
134 devclass_t ixl_devclass;
135 DRIVER_MODULE(ixl, pci, ixl_driver, ixl_devclass, 0, 0);
137 MODULE_VERSION(ixl, 1);
139 MODULE_DEPEND(ixl, pci, 1, 1, 1);
140 MODULE_DEPEND(ixl, ether, 1, 1, 1);
141 #if defined(DEV_NETMAP) && __FreeBSD_version >= 1100000
142 MODULE_DEPEND(ixl, netmap, 1, 1, 1);
143 #endif /* DEV_NETMAP */
146 ** TUNEABLE PARAMETERS:
149 static SYSCTL_NODE(_hw, OID_AUTO, ixl, CTLFLAG_RD, 0,
150 "IXL driver parameters");
153 * MSIX should be the default for best performance,
154 * but this allows it to be forced off for testing.
156 static int ixl_enable_msix = 1;
157 TUNABLE_INT("hw.ixl.enable_msix", &ixl_enable_msix);
158 SYSCTL_INT(_hw_ixl, OID_AUTO, enable_msix, CTLFLAG_RDTUN, &ixl_enable_msix, 0,
159 "Enable MSI-X interrupts");
162 ** Number of descriptors per ring
163 ** - TX and RX sizes are independently configurable
165 static int ixl_tx_ring_size = IXL_DEFAULT_RING;
166 TUNABLE_INT("hw.ixl.tx_ring_size", &ixl_tx_ring_size);
167 SYSCTL_INT(_hw_ixl, OID_AUTO, tx_ring_size, CTLFLAG_RDTUN,
168 &ixl_tx_ring_size, 0, "TX Descriptor Ring Size");
170 static int ixl_rx_ring_size = IXL_DEFAULT_RING;
171 TUNABLE_INT("hw.ixl.rx_ring_size", &ixl_rx_ring_size);
172 SYSCTL_INT(_hw_ixl, OID_AUTO, rx_ring_size, CTLFLAG_RDTUN,
173 &ixl_rx_ring_size, 0, "RX Descriptor Ring Size");
176 ** This can be set manually, if left as 0 the
177 ** number of queues will be calculated based
178 ** on cpus and msix vectors available.
180 static int ixl_max_queues = 0;
181 TUNABLE_INT("hw.ixl.max_queues", &ixl_max_queues);
182 SYSCTL_INT(_hw_ixl, OID_AUTO, max_queues, CTLFLAG_RDTUN,
183 &ixl_max_queues, 0, "Number of Queues");
186 * Leave this on unless you need to send flow control
187 * frames (or other control frames) from software
189 static int ixl_enable_tx_fc_filter = 1;
190 TUNABLE_INT("hw.ixl.enable_tx_fc_filter",
191 &ixl_enable_tx_fc_filter);
192 SYSCTL_INT(_hw_ixl, OID_AUTO, enable_tx_fc_filter, CTLFLAG_RDTUN,
193 &ixl_enable_tx_fc_filter, 0,
194 "Filter out packets with Ethertype 0x8808 from being sent out by non-HW sources");
196 static int ixl_i2c_access_method = 0;
197 TUNABLE_INT("hw.ixl.i2c_access_method",
198 &ixl_i2c_access_method);
199 SYSCTL_INT(_hw_ixl, OID_AUTO, i2c_access_method, CTLFLAG_RDTUN,
200 &ixl_i2c_access_method, 0,
201 IXL_SYSCTL_HELP_I2C_METHOD);
204 * Different method for processing TX descriptor
207 static int ixl_enable_head_writeback = 1;
208 TUNABLE_INT("hw.ixl.enable_head_writeback",
209 &ixl_enable_head_writeback);
210 SYSCTL_INT(_hw_ixl, OID_AUTO, enable_head_writeback, CTLFLAG_RDTUN,
211 &ixl_enable_head_writeback, 0,
212 "For detecting last completed TX descriptor by hardware, use value written by HW instead of checking descriptors");
214 static int ixl_core_debug_mask = 0;
215 TUNABLE_INT("hw.ixl.core_debug_mask",
216 &ixl_core_debug_mask);
217 SYSCTL_INT(_hw_ixl, OID_AUTO, core_debug_mask, CTLFLAG_RDTUN,
218 &ixl_core_debug_mask, 0,
219 "Display debug statements that are printed in non-shared code");
221 static int ixl_shared_debug_mask = 0;
222 TUNABLE_INT("hw.ixl.shared_debug_mask",
223 &ixl_shared_debug_mask);
224 SYSCTL_INT(_hw_ixl, OID_AUTO, shared_debug_mask, CTLFLAG_RDTUN,
225 &ixl_shared_debug_mask, 0,
226 "Display debug statements that are printed in shared code");
230 ** Controls for Interrupt Throttling
231 ** - true/false for dynamic adjustment
232 ** - default values for static ITR
234 static int ixl_dynamic_rx_itr = 1;
235 TUNABLE_INT("hw.ixl.dynamic_rx_itr", &ixl_dynamic_rx_itr);
236 SYSCTL_INT(_hw_ixl, OID_AUTO, dynamic_rx_itr, CTLFLAG_RDTUN,
237 &ixl_dynamic_rx_itr, 0, "Dynamic RX Interrupt Rate");
239 static int ixl_dynamic_tx_itr = 1;
240 TUNABLE_INT("hw.ixl.dynamic_tx_itr", &ixl_dynamic_tx_itr);
241 SYSCTL_INT(_hw_ixl, OID_AUTO, dynamic_tx_itr, CTLFLAG_RDTUN,
242 &ixl_dynamic_tx_itr, 0, "Dynamic TX Interrupt Rate");
244 static int ixl_rx_itr = IXL_ITR_8K;
245 TUNABLE_INT("hw.ixl.rx_itr", &ixl_rx_itr);
246 SYSCTL_INT(_hw_ixl, OID_AUTO, rx_itr, CTLFLAG_RDTUN,
247 &ixl_rx_itr, 0, "RX Interrupt Rate");
249 static int ixl_tx_itr = IXL_ITR_4K;
250 TUNABLE_INT("hw.ixl.tx_itr", &ixl_tx_itr);
251 SYSCTL_INT(_hw_ixl, OID_AUTO, tx_itr, CTLFLAG_RDTUN,
252 &ixl_tx_itr, 0, "TX Interrupt Rate");
255 int ixl_enable_iwarp = 0;
256 TUNABLE_INT("hw.ixl.enable_iwarp", &ixl_enable_iwarp);
257 SYSCTL_INT(_hw_ixl, OID_AUTO, enable_iwarp, CTLFLAG_RDTUN,
258 &ixl_enable_iwarp, 0, "iWARP enabled");
260 #if __FreeBSD_version < 1100000
261 int ixl_limit_iwarp_msix = 1;
263 int ixl_limit_iwarp_msix = IXL_IW_MAX_MSIX;
265 TUNABLE_INT("hw.ixl.limit_iwarp_msix", &ixl_limit_iwarp_msix);
266 SYSCTL_INT(_hw_ixl, OID_AUTO, limit_iwarp_msix, CTLFLAG_RDTUN,
267 &ixl_limit_iwarp_msix, 0, "Limit MSIX vectors assigned to iWARP");
271 #define NETMAP_IXL_MAIN /* only bring in one part of the netmap code */
272 #include <dev/netmap/if_ixl_netmap.h>
273 #endif /* DEV_NETMAP */
275 /*********************************************************************
276 * Device identification routine
278 * ixl_probe determines if the driver should be loaded on
279 * the hardware based on PCI vendor/device id of the device.
281 * return BUS_PROBE_DEFAULT on success, positive on failure
282 *********************************************************************/
285 ixl_probe(device_t dev)
287 ixl_vendor_info_t *ent;
289 u16 pci_vendor_id, pci_device_id;
290 u16 pci_subvendor_id, pci_subdevice_id;
291 char device_name[256];
294 INIT_DEBUGOUT("ixl_probe: begin");
296 pci_vendor_id = pci_get_vendor(dev);
297 if (pci_vendor_id != I40E_INTEL_VENDOR_ID)
300 pci_device_id = pci_get_device(dev);
301 pci_subvendor_id = pci_get_subvendor(dev);
302 pci_subdevice_id = pci_get_subdevice(dev);
304 ent = ixl_vendor_info_array;
305 while (ent->vendor_id != 0) {
306 if ((pci_vendor_id == ent->vendor_id) &&
307 (pci_device_id == ent->device_id) &&
309 ((pci_subvendor_id == ent->subvendor_id) ||
310 (ent->subvendor_id == 0)) &&
312 ((pci_subdevice_id == ent->subdevice_id) ||
313 (ent->subdevice_id == 0))) {
314 sprintf(device_name, "%s, Version - %s",
315 ixl_strings[ent->index],
317 device_set_desc_copy(dev, device_name);
318 return (BUS_PROBE_DEFAULT);
326 * Sanity check and save off tunable values.
329 ixl_save_pf_tunables(struct ixl_pf *pf)
331 device_t dev = pf->dev;
333 /* Save tunable information */
334 pf->enable_msix = ixl_enable_msix;
335 pf->max_queues = ixl_max_queues;
336 pf->enable_tx_fc_filter = ixl_enable_tx_fc_filter;
337 pf->dynamic_rx_itr = ixl_dynamic_rx_itr;
338 pf->dynamic_tx_itr = ixl_dynamic_tx_itr;
339 pf->dbg_mask = ixl_core_debug_mask;
340 pf->hw.debug_mask = ixl_shared_debug_mask;
342 if (ixl_enable_head_writeback == 0)
343 device_printf(dev, "Head writeback mode cannot be disabled "
344 "when netmap is enabled\n");
345 pf->vsi.enable_head_writeback = 1;
347 pf->vsi.enable_head_writeback = !!(ixl_enable_head_writeback);
349 ixl_vsi_setup_rings_size(&pf->vsi, ixl_tx_ring_size, ixl_rx_ring_size);
351 if (ixl_i2c_access_method > IXL_I2C_ACCESS_METHOD_TYPE_LENGTH - 1
352 || ixl_i2c_access_method < IXL_I2C_ACCESS_METHOD_BEST_AVAILABLE)
353 pf->i2c_access_method = IXL_I2C_ACCESS_METHOD_BEST_AVAILABLE;
355 pf->i2c_access_method =
356 (enum ixl_i2c_access_method_t)ixl_i2c_access_method;
358 if (ixl_tx_itr < 0 || ixl_tx_itr > IXL_MAX_ITR) {
359 device_printf(dev, "Invalid tx_itr value of %d set!\n",
361 device_printf(dev, "tx_itr must be between %d and %d, "
364 device_printf(dev, "Using default value of %d instead\n",
366 pf->tx_itr = IXL_ITR_4K;
368 pf->tx_itr = ixl_tx_itr;
370 if (ixl_rx_itr < 0 || ixl_rx_itr > IXL_MAX_ITR) {
371 device_printf(dev, "Invalid rx_itr value of %d set!\n",
373 device_printf(dev, "rx_itr must be between %d and %d, "
376 device_printf(dev, "Using default value of %d instead\n",
378 pf->rx_itr = IXL_ITR_8K;
380 pf->rx_itr = ixl_rx_itr;
386 ixl_attach_recovery_mode(struct ixl_pf *pf)
388 struct ixl_vsi *vsi = &pf->vsi;
389 struct i40e_hw *hw = &pf->hw;
390 device_t dev = pf->dev;
393 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");
395 atomic_set_int(&pf->state, IXL_PF_STATE_RECOVERY_MODE);
397 i40e_get_mac_addr(hw, hw->mac.addr);
399 pf->msix = ixl_init_msix(pf);
400 ixl_setup_stations(pf);
401 ixl_setup_interface(pf->dev, vsi);
404 error = ixl_setup_adminq_msix(pf);
406 device_printf(dev, "ixl_setup_adminq_msix() error: %d\n",
408 goto recovery_err_late;
410 error = ixl_setup_adminq_tq(pf);
412 device_printf(dev, "ixl_setup_adminq_tq() error: %d\n",
414 goto recovery_err_late;
416 ixl_configure_intr0_msix(pf);
417 ixl_enable_intr0(hw);
419 error = ixl_setup_legacy(pf);
421 error = ixl_setup_adminq_tq(pf);
423 device_printf(dev, "ixl_setup_adminq_tq() error: %d\n",
425 goto recovery_err_late;
429 /* Get the bus configuration and set the shared code's config */
430 ixl_get_bus_info(pf);
432 /* Initialize statistics & add sysctls */
433 ixl_add_device_sysctls(pf);
435 /* Start the local timer */
437 callout_reset(&pf->timer, hz, ixl_local_timer, pf);
444 /*********************************************************************
445 * Device initialization routine
447 * The attach entry point is called when the driver is being loaded.
448 * This routine identifies the type of hardware, allocates all resources
449 * and initializes the hardware.
451 * return 0 on success, positive on failure
452 *********************************************************************/
455 ixl_attach(device_t dev)
460 enum i40e_get_fw_lldp_status_resp lldp_status;
461 enum i40e_status_code status;
464 INIT_DEBUGOUT("ixl_attach: begin");
466 /* Allocate, clear, and link in our primary soft structure */
467 pf = device_get_softc(dev);
468 pf->dev = pf->osdep.dev = dev;
472 ** Note this assumes we have a single embedded VSI,
473 ** this could be enhanced later to allocate multiple
479 /* Save tunable values */
480 error = ixl_save_pf_tunables(pf);
485 IXL_PF_LOCK_INIT(pf, device_get_nameunit(dev));
487 /* Set up the timer callout */
488 callout_init_mtx(&pf->timer, &pf->pf_mtx, 0);
490 /* Do PCI setup - map BAR0, etc */
491 if (ixl_allocate_pci_resources(pf)) {
496 /* Establish a clean starting point */
499 /* Don't try to reset device if it's in recovery mode */
500 if (!ixl_fw_recovery_mode(pf)) {
501 status = i40e_pf_reset(hw);
503 device_printf(dev, "PF reset failure %s\n",
504 i40e_stat_str(hw, status));
510 /* Initialize the shared code */
511 status = i40e_init_shared_code(hw);
513 device_printf(dev, "Unable to initialize shared code, error %s\n",
514 i40e_stat_str(hw, status));
519 /* Set up the admin queue */
520 hw->aq.num_arq_entries = IXL_AQ_LEN;
521 hw->aq.num_asq_entries = IXL_AQ_LEN;
522 hw->aq.arq_buf_size = IXL_AQ_BUF_SZ;
523 hw->aq.asq_buf_size = IXL_AQ_BUF_SZ;
525 status = i40e_init_adminq(hw);
526 if (status != 0 && status != I40E_ERR_FIRMWARE_API_VERSION) {
527 device_printf(dev, "Unable to initialize Admin Queue, error %s\n",
528 i40e_stat_str(hw, status));
532 ixl_print_nvm_version(pf);
534 if (status == I40E_ERR_FIRMWARE_API_VERSION) {
535 device_printf(dev, "The driver for the device stopped "
536 "because the NVM image is newer than expected.\n");
537 device_printf(dev, "You must install the most recent version of "
538 "the network driver.\n");
543 if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
544 hw->aq.api_min_ver > I40E_FW_MINOR_VERSION(hw)) {
545 device_printf(dev, "The driver for the device detected "
546 "a newer version of the NVM image than expected.\n");
547 device_printf(dev, "Please install the most recent version "
548 "of the network driver.\n");
549 } else if (hw->aq.api_maj_ver == 1 && hw->aq.api_min_ver < 4) {
550 device_printf(dev, "The driver for the device detected "
551 "an older version of the NVM image than expected.\n");
552 device_printf(dev, "Please update the NVM image.\n");
555 if (ixl_fw_recovery_mode(pf))
556 return ixl_attach_recovery_mode(pf);
559 i40e_clear_pxe_mode(hw);
561 /* Get capabilities from the device */
562 error = ixl_get_hw_capabilities(pf);
564 device_printf(dev, "HW capabilities failure!\n");
569 * Allocate interrupts and figure out number of queues to use
572 pf->msix = ixl_init_msix(pf);
574 /* Set up host memory cache */
575 status = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
576 hw->func_caps.num_rx_qp, 0, 0);
578 device_printf(dev, "init_lan_hmc failed: %s\n",
579 i40e_stat_str(hw, status));
583 status = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
585 device_printf(dev, "configure_lan_hmc failed: %s\n",
586 i40e_stat_str(hw, status));
590 /* Init queue allocation manager */
591 error = ixl_pf_qmgr_init(&pf->qmgr, hw->func_caps.num_tx_qp);
593 device_printf(dev, "Failed to init queue manager for PF queues, error %d\n",
597 /* reserve a contiguous allocation for the PF's VSI */
598 error = ixl_pf_qmgr_alloc_contiguous(&pf->qmgr, vsi->num_queues, &pf->qtag);
600 device_printf(dev, "Failed to reserve queues for PF LAN VSI, error %d\n",
604 device_printf(dev, "Allocating %d queues for PF LAN VSI; %d queues active\n",
605 pf->qtag.num_allocated, pf->qtag.num_active);
607 /* Disable LLDP from the firmware on XL710 for certain NVM versions */
608 if (hw->mac.type == I40E_MAC_XL710 &&
609 (((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver < 3)) ||
610 (hw->aq.fw_maj_ver < 4))) {
611 i40e_aq_stop_lldp(hw, true, false, NULL);
612 pf->state |= IXL_PF_STATE_FW_LLDP_DISABLED;
615 /* Try enabling Energy Efficient Ethernet (EEE) mode */
616 if(i40e_enable_eee(hw, true) == I40E_SUCCESS)
617 atomic_set_int(&pf->state, IXL_PF_STATE_EEE_ENABLED);
619 atomic_clear_int(&pf->state, IXL_PF_STATE_EEE_ENABLED);
621 /* Get MAC addresses from hardware */
622 i40e_get_mac_addr(hw, hw->mac.addr);
623 error = i40e_validate_mac_addr(hw->mac.addr);
625 device_printf(dev, "validate_mac_addr failed: %d\n", error);
628 bcopy(hw->mac.addr, hw->mac.perm_addr, ETHER_ADDR_LEN);
629 i40e_get_port_mac_addr(hw, hw->mac.port_addr);
631 /* Query device FW LLDP status */
632 if (i40e_get_fw_lldp_status(hw, &lldp_status) == I40E_SUCCESS) {
633 if (lldp_status == I40E_GET_FW_LLDP_STATUS_DISABLED) {
634 atomic_set_int(&pf->state,
635 IXL_PF_STATE_FW_LLDP_DISABLED);
637 atomic_clear_int(&pf->state,
638 IXL_PF_STATE_FW_LLDP_DISABLED);
642 /* Tell FW to apply DCB config on link up */
643 i40e_aq_set_dcb_parameters(hw, true, NULL);
645 /* Set up SW VSI and allocate queue memory and rings */
646 if (ixl_setup_stations(pf)) {
647 device_printf(dev, "setup stations failed!\n");
652 /* Setup OS network interface / ifnet */
653 if (ixl_setup_interface(dev, vsi)) {
654 device_printf(dev, "interface setup failed!\n");
659 /* Determine link state */
660 if (ixl_attach_get_link_status(pf)) {
665 error = ixl_switch_config(pf);
667 device_printf(dev, "Initial ixl_switch_config() failed: %d\n",
672 /* Limit PHY interrupts to link, autoneg, and modules failure */
673 status = i40e_aq_set_phy_int_mask(hw, IXL_DEFAULT_PHY_INT_MASK,
676 device_printf(dev, "i40e_aq_set_phy_mask() failed: err %s,"
677 " aq_err %s\n", i40e_stat_str(hw, status),
678 i40e_aq_str(hw, hw->aq.asq_last_status));
682 /* Get the bus configuration and set the shared code's config */
683 ixl_get_bus_info(pf);
686 * In MSI-X mode, initialize the Admin Queue interrupt,
687 * so userland tools can communicate with the adapter regardless of
688 * the ifnet interface's status.
691 error = ixl_setup_adminq_msix(pf);
693 device_printf(dev, "ixl_setup_adminq_msix() error: %d\n",
697 error = ixl_setup_adminq_tq(pf);
699 device_printf(dev, "ixl_setup_adminq_tq() error: %d\n",
703 ixl_configure_intr0_msix(pf);
704 ixl_enable_intr0(hw);
706 error = ixl_setup_queue_msix(vsi);
708 device_printf(dev, "ixl_setup_queue_msix() error: %d\n",
710 error = ixl_setup_queue_tqs(vsi);
712 device_printf(dev, "ixl_setup_queue_tqs() error: %d\n",
715 error = ixl_setup_legacy(pf);
717 error = ixl_setup_adminq_tq(pf);
719 device_printf(dev, "ixl_setup_adminq_tq() error: %d\n",
724 error = ixl_setup_queue_tqs(vsi);
726 device_printf(dev, "ixl_setup_queue_tqs() error: %d\n",
731 device_printf(dev, "interrupt setup error: %d\n", error);
734 /* Set initial advertised speed sysctl value */
735 ixl_set_initial_advertised_speeds(pf);
737 /* Initialize statistics & add sysctls */
738 ixl_add_device_sysctls(pf);
740 ixl_pf_reset_stats(pf);
741 ixl_update_stats_counters(pf);
742 ixl_add_hw_stats(pf);
744 /* Add protocol filters to list */
745 ixl_init_filters(vsi);
747 /* Register for VLAN events */
748 vsi->vlan_attach = EVENTHANDLER_REGISTER(vlan_config,
749 ixl_register_vlan, vsi, EVENTHANDLER_PRI_FIRST);
750 vsi->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig,
751 ixl_unregister_vlan, vsi, EVENTHANDLER_PRI_FIRST);
754 ixl_initialize_sriov(pf);
758 ixl_netmap_attach(vsi);
759 #endif /* DEV_NETMAP */
762 if (hw->func_caps.iwarp && ixl_enable_iwarp) {
763 pf->iw_enabled = (pf->iw_msix > 0) ? true : false;
764 if (pf->iw_enabled) {
765 error = ixl_iw_pf_attach(pf);
768 "interfacing to iwarp driver failed: %d\n",
772 device_printf(dev, "iWARP ready\n");
775 "iwarp disabled on this device (no msix vectors)\n");
777 pf->iw_enabled = false;
778 device_printf(dev, "The device is not iWARP enabled\n");
781 /* Start the local timer */
783 callout_reset(&pf->timer, hz, ixl_local_timer, pf);
786 INIT_DEBUGOUT("ixl_attach: end");
790 if (vsi->ifp != NULL) {
791 ether_ifdetach(vsi->ifp);
795 i40e_shutdown_lan_hmc(hw);
797 i40e_shutdown_adminq(hw);
799 ixl_free_pci_resources(pf);
801 IXL_PF_LOCK_DESTROY(pf);
805 /*********************************************************************
806 * Device removal routine
808 * The detach entry point is called when the driver is being removed.
809 * This routine stops the adapter and deallocates all the resources
810 * that were allocated for driver operation.
812 * return 0 on success, positive on failure
813 *********************************************************************/
816 ixl_detach(device_t dev)
818 struct ixl_pf *pf = device_get_softc(dev);
819 struct i40e_hw *hw = &pf->hw;
820 struct ixl_vsi *vsi = &pf->vsi;
821 enum i40e_status_code status;
822 #if defined(PCI_IOV) || defined(IXL_IW)
826 INIT_DEBUGOUT("ixl_detach: begin");
828 /* Make sure VLANS are not using driver */
829 if (vsi->ifp->if_vlantrunk != NULL) {
830 device_printf(dev, "Vlan in use, detach first\n");
835 error = pci_iov_detach(dev);
837 device_printf(dev, "SR-IOV in use; detach first.\n");
842 /* Remove all previously allocated media types */
843 ifmedia_removeall(&vsi->media);
845 ether_ifdetach(vsi->ifp);
846 if (vsi->ifp->if_drv_flags & IFF_DRV_RUNNING)
849 /* Shutdown LAN HMC */
850 if (hw->hmc.hmc_obj) {
851 status = i40e_shutdown_lan_hmc(hw);
854 "Shutdown LAN HMC failed with code %s\n", i40e_stat_str(hw, status));
857 /* Teardown LAN queue resources */
858 ixl_teardown_queue_msix(vsi);
859 ixl_free_queue_tqs(vsi);
861 /* Timer enqueues admin task. Stop it before freeing the admin taskqueue */
862 callout_drain(&pf->timer);
864 /* Shutdown admin queue */
865 ixl_disable_intr0(hw);
866 ixl_teardown_adminq_msix(pf);
868 status = i40e_shutdown_adminq(hw);
871 "Shutdown Admin queue failed with code %d\n", status);
873 ixl_free_adminq_tq(pf);
875 /* Unregister VLAN events */
876 if (vsi->vlan_attach != NULL)
877 EVENTHANDLER_DEREGISTER(vlan_config, vsi->vlan_attach);
878 if (vsi->vlan_detach != NULL)
879 EVENTHANDLER_DEREGISTER(vlan_unconfig, vsi->vlan_detach);
882 if (ixl_enable_iwarp && pf->iw_enabled) {
883 error = ixl_iw_pf_detach(pf);
884 if (error == EBUSY) {
885 device_printf(dev, "iwarp in use; stop it first.\n");
892 netmap_detach(vsi->ifp);
893 #endif /* DEV_NETMAP */
894 ixl_pf_qmgr_destroy(&pf->qmgr);
895 ixl_free_pci_resources(pf);
896 bus_generic_detach(dev);
899 IXL_PF_LOCK_DESTROY(pf);
903 /*********************************************************************
905 * Shutdown entry point
907 **********************************************************************/
910 ixl_shutdown(device_t dev)
912 struct ixl_pf *pf = device_get_softc(dev);