1 /******************************************************************************
3 Copyright (c) 2013-2015, 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 ******************************************************************************/
39 #include "ixl_pf_iov.h"
42 /*********************************************************************
44 *********************************************************************/
45 char ixl_driver_version[] = "1.6.6-k";
47 /*********************************************************************
50 * Used by probe to select devices to load on
51 * Last field stores an index into ixl_strings
52 * Last entry must be all 0s
54 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index }
55 *********************************************************************/
57 static ixl_vendor_info_t ixl_vendor_info_array[] =
59 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710, 0, 0, 0},
60 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B, 0, 0, 0},
61 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C, 0, 0, 0},
62 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A, 0, 0, 0},
63 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B, 0, 0, 0},
64 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C, 0, 0, 0},
65 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T, 0, 0, 0},
66 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T4, 0, 0, 0},
67 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_X722, 0, 0, 0},
68 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_X722, 0, 0, 0},
69 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722, 0, 0, 0},
70 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_X722, 0, 0, 0},
71 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_X722, 0, 0, 0},
72 {I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_I_X722, 0, 0, 0},
73 /* required last entry */
77 /*********************************************************************
78 * Table of branding strings
79 *********************************************************************/
81 static char *ixl_strings[] = {
82 "Intel(R) Ethernet Connection XL710/X722 Driver"
86 /*********************************************************************
88 *********************************************************************/
89 static int ixl_probe(device_t);
90 static int ixl_attach(device_t);
91 static int ixl_detach(device_t);
92 static int ixl_shutdown(device_t);
94 static int ixl_save_pf_tunables(struct ixl_pf *);
95 static int ixl_attach_get_link_status(struct ixl_pf *);
97 /*********************************************************************
98 * FreeBSD Device Interface Entry Points
99 *********************************************************************/
101 static device_method_t ixl_methods[] = {
102 /* Device interface */
103 DEVMETHOD(device_probe, ixl_probe),
104 DEVMETHOD(device_attach, ixl_attach),
105 DEVMETHOD(device_detach, ixl_detach),
106 DEVMETHOD(device_shutdown, ixl_shutdown),
108 DEVMETHOD(pci_iov_init, ixl_iov_init),
109 DEVMETHOD(pci_iov_uninit, ixl_iov_uninit),
110 DEVMETHOD(pci_iov_add_vf, ixl_add_vf),
115 static driver_t ixl_driver = {
116 "ixl", ixl_methods, sizeof(struct ixl_pf),
119 devclass_t ixl_devclass;
120 DRIVER_MODULE(ixl, pci, ixl_driver, ixl_devclass, 0, 0);
122 MODULE_DEPEND(ixl, pci, 1, 1, 1);
123 MODULE_DEPEND(ixl, ether, 1, 1, 1);
125 MODULE_DEPEND(ixl, netmap, 1, 1, 1);
126 #endif /* DEV_NETMAP */
129 ** TUNEABLE PARAMETERS:
132 static SYSCTL_NODE(_hw, OID_AUTO, ixl, CTLFLAG_RD, 0,
133 "IXL driver parameters");
136 * MSIX should be the default for best performance,
137 * but this allows it to be forced off for testing.
139 static int ixl_enable_msix = 1;
140 TUNABLE_INT("hw.ixl.enable_msix", &ixl_enable_msix);
141 SYSCTL_INT(_hw_ixl, OID_AUTO, enable_msix, CTLFLAG_RDTUN, &ixl_enable_msix, 0,
142 "Enable MSI-X interrupts");
145 ** Number of descriptors per ring:
146 ** - TX and RX are the same size
148 static int ixl_ring_size = DEFAULT_RING;
149 TUNABLE_INT("hw.ixl.ring_size", &ixl_ring_size);
150 SYSCTL_INT(_hw_ixl, OID_AUTO, ring_size, CTLFLAG_RDTUN,
151 &ixl_ring_size, 0, "Descriptor Ring Size");
154 ** This can be set manually, if left as 0 the
155 ** number of queues will be calculated based
156 ** on cpus and msix vectors available.
158 static int ixl_max_queues = 0;
159 TUNABLE_INT("hw.ixl.max_queues", &ixl_max_queues);
160 SYSCTL_INT(_hw_ixl, OID_AUTO, max_queues, CTLFLAG_RDTUN,
161 &ixl_max_queues, 0, "Number of Queues");
163 static int ixl_enable_tx_fc_filter = 1;
164 TUNABLE_INT("hw.ixl.enable_tx_fc_filter",
165 &ixl_enable_tx_fc_filter);
166 SYSCTL_INT(_hw_ixl, OID_AUTO, enable_tx_fc_filter, CTLFLAG_RDTUN,
167 &ixl_enable_tx_fc_filter, 0,
168 "Filter out packets with Ethertype 0x8808 from being sent out by non-HW sources");
170 static int ixl_core_debug_mask = 0;
171 TUNABLE_INT("hw.ixl.core_debug_mask",
172 &ixl_core_debug_mask);
173 SYSCTL_INT(_hw_ixl, OID_AUTO, core_debug_mask, CTLFLAG_RDTUN,
174 &ixl_core_debug_mask, 0,
175 "Display debug statements that are printed in non-shared code");
177 static int ixl_shared_debug_mask = 0;
178 TUNABLE_INT("hw.ixl.shared_debug_mask",
179 &ixl_shared_debug_mask);
180 SYSCTL_INT(_hw_ixl, OID_AUTO, shared_debug_mask, CTLFLAG_RDTUN,
181 &ixl_shared_debug_mask, 0,
182 "Display debug statements that are printed in shared code");
185 ** Controls for Interrupt Throttling
186 ** - true/false for dynamic adjustment
187 ** - default values for static ITR
189 static int ixl_dynamic_rx_itr = 1;
190 TUNABLE_INT("hw.ixl.dynamic_rx_itr", &ixl_dynamic_rx_itr);
191 SYSCTL_INT(_hw_ixl, OID_AUTO, dynamic_rx_itr, CTLFLAG_RDTUN,
192 &ixl_dynamic_rx_itr, 0, "Dynamic RX Interrupt Rate");
194 static int ixl_dynamic_tx_itr = 1;
195 TUNABLE_INT("hw.ixl.dynamic_tx_itr", &ixl_dynamic_tx_itr);
196 SYSCTL_INT(_hw_ixl, OID_AUTO, dynamic_tx_itr, CTLFLAG_RDTUN,
197 &ixl_dynamic_tx_itr, 0, "Dynamic TX Interrupt Rate");
199 static int ixl_rx_itr = IXL_ITR_8K;
200 TUNABLE_INT("hw.ixl.rx_itr", &ixl_rx_itr);
201 SYSCTL_INT(_hw_ixl, OID_AUTO, rx_itr, CTLFLAG_RDTUN,
202 &ixl_rx_itr, 0, "RX Interrupt Rate");
204 static int ixl_tx_itr = IXL_ITR_4K;
205 TUNABLE_INT("hw.ixl.tx_itr", &ixl_tx_itr);
206 SYSCTL_INT(_hw_ixl, OID_AUTO, tx_itr, CTLFLAG_RDTUN,
207 &ixl_tx_itr, 0, "TX Interrupt Rate");
210 #define NETMAP_IXL_MAIN /* only bring in one part of the netmap code */
211 #include <dev/netmap/if_ixl_netmap.h>
212 #endif /* DEV_NETMAP */
214 /*********************************************************************
215 * Device identification routine
217 * ixl_probe determines if the driver should be loaded on
218 * the hardware based on PCI vendor/device id of the device.
220 * return BUS_PROBE_DEFAULT on success, positive on failure
221 *********************************************************************/
224 ixl_probe(device_t dev)
226 ixl_vendor_info_t *ent;
228 u16 pci_vendor_id, pci_device_id;
229 u16 pci_subvendor_id, pci_subdevice_id;
230 char device_name[256];
233 INIT_DEBUGOUT("ixl_probe: begin");
235 pci_vendor_id = pci_get_vendor(dev);
236 if (pci_vendor_id != I40E_INTEL_VENDOR_ID)
239 pci_device_id = pci_get_device(dev);
240 pci_subvendor_id = pci_get_subvendor(dev);
241 pci_subdevice_id = pci_get_subdevice(dev);
243 ent = ixl_vendor_info_array;
244 while (ent->vendor_id != 0) {
245 if ((pci_vendor_id == ent->vendor_id) &&
246 (pci_device_id == ent->device_id) &&
248 ((pci_subvendor_id == ent->subvendor_id) ||
249 (ent->subvendor_id == 0)) &&
251 ((pci_subdevice_id == ent->subdevice_id) ||
252 (ent->subdevice_id == 0))) {
253 sprintf(device_name, "%s, Version - %s",
254 ixl_strings[ent->index],
256 device_set_desc_copy(dev, device_name);
257 return (BUS_PROBE_DEFAULT);
265 ixl_attach_get_link_status(struct ixl_pf *pf)
267 struct i40e_hw *hw = &pf->hw;
268 device_t dev = pf->dev;
271 if (((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver < 33)) ||
272 (hw->aq.fw_maj_ver < 4)) {
274 error = i40e_aq_set_link_restart_an(hw, TRUE, NULL);
276 device_printf(dev, "link restart failed, aq_err=%d\n",
277 pf->hw.aq.asq_last_status);
282 /* Determine link state */
283 hw->phy.get_link_info = TRUE;
284 i40e_get_link_status(hw, &pf->link_up);
289 * Sanity check and save off tunable values.
292 ixl_save_pf_tunables(struct ixl_pf *pf)
294 device_t dev = pf->dev;
296 /* Save tunable information */
297 pf->enable_msix = ixl_enable_msix;
298 pf->max_queues = ixl_max_queues;
299 pf->ringsz = ixl_ring_size;
300 pf->enable_tx_fc_filter = ixl_enable_tx_fc_filter;
301 pf->dynamic_rx_itr = ixl_dynamic_rx_itr;
302 pf->dynamic_tx_itr = ixl_dynamic_tx_itr;
303 pf->tx_itr = ixl_tx_itr;
304 pf->rx_itr = ixl_rx_itr;
305 pf->dbg_mask = ixl_core_debug_mask;
306 pf->hw.debug_mask = ixl_shared_debug_mask;
308 if (ixl_ring_size < IXL_MIN_RING
309 || ixl_ring_size > IXL_MAX_RING
310 || ixl_ring_size % IXL_RING_INCREMENT != 0) {
311 device_printf(dev, "Invalid ring_size value of %d set!\n",
313 device_printf(dev, "ring_size must be between %d and %d, "
314 "inclusive, and must be a multiple of %d\n",
315 IXL_MIN_RING, IXL_MAX_RING, IXL_RING_INCREMENT);
322 /*********************************************************************
323 * Device initialization routine
325 * The attach entry point is called when the driver is being loaded.
326 * This routine identifies the type of hardware, allocates all resources
327 * and initializes the hardware.
329 * return 0 on success, positive on failure
330 *********************************************************************/
333 ixl_attach(device_t dev)
338 enum i40e_status_code status;
341 INIT_DEBUGOUT("ixl_attach: begin");
343 /* Allocate, clear, and link in our primary soft structure */
344 pf = device_get_softc(dev);
345 pf->dev = pf->osdep.dev = dev;
349 ** Note this assumes we have a single embedded VSI,
350 ** this could be enhanced later to allocate multiple
355 /* Save tunable values */
356 error = ixl_save_pf_tunables(pf);
361 IXL_PF_LOCK_INIT(pf, device_get_nameunit(dev));
363 /* Set up the timer callout */
364 callout_init_mtx(&pf->timer, &pf->pf_mtx, 0);
366 /* Do PCI setup - map BAR0, etc */
367 if (ixl_allocate_pci_resources(pf)) {
368 device_printf(dev, "Allocation of PCI resources failed\n");
373 /* Establish a clean starting point */
375 status = i40e_pf_reset(hw);
377 device_printf(dev, "PF reset failure %s\n",
378 i40e_stat_str(hw, status));
383 /* Initialize the shared code */
384 status = i40e_init_shared_code(hw);
386 device_printf(dev, "Unable to initialize shared code, error %s\n",
387 i40e_stat_str(hw, status));
393 * Allocate interrupts and figure out number of queues to use
396 pf->msix = ixl_init_msix(pf);
398 /* Set up the admin queue */
399 hw->aq.num_arq_entries = IXL_AQ_LEN;
400 hw->aq.num_asq_entries = IXL_AQ_LEN;
401 hw->aq.arq_buf_size = IXL_AQ_BUF_SZ;
402 hw->aq.asq_buf_size = IXL_AQ_BUF_SZ;
404 status = i40e_init_adminq(hw);
405 if (status != 0 && status != I40E_ERR_FIRMWARE_API_VERSION) {
406 device_printf(dev, "Unable to initialize Admin Queue, error %s\n",
407 i40e_stat_str(hw, status));
411 ixl_print_nvm_version(pf);
413 if (status == I40E_ERR_FIRMWARE_API_VERSION) {
414 device_printf(dev, "The driver for the device stopped "
415 "because the NVM image is newer than expected.\n"
416 "You must install the most recent version of "
417 "the network driver.\n");
422 if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
423 hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
424 device_printf(dev, "The driver for the device detected "
425 "a newer version of the NVM image than expected.\n"
426 "Please install the most recent version of the network driver.\n");
427 else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
428 hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1))
429 device_printf(dev, "The driver for the device detected "
430 "an older version of the NVM image than expected.\n"
431 "Please update the NVM image.\n");
434 i40e_clear_pxe_mode(hw);
436 /* Get capabilities from the device */
437 error = ixl_get_hw_capabilities(pf);
439 device_printf(dev, "HW capabilities failure!\n");
443 /* Set up host memory cache */
444 status = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
445 hw->func_caps.num_rx_qp, 0, 0);
447 device_printf(dev, "init_lan_hmc failed: %s\n",
448 i40e_stat_str(hw, status));
452 status = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
454 device_printf(dev, "configure_lan_hmc failed: %s\n",
455 i40e_stat_str(hw, status));
459 /* Init queue allocation manager */
460 error = ixl_pf_qmgr_init(&pf->qmgr, hw->func_caps.num_tx_qp);
462 device_printf(dev, "Failed to init queue manager for PF queues, error %d\n",
466 /* reserve a contiguous allocation for the PF's VSI */
467 error = ixl_pf_qmgr_alloc_contiguous(&pf->qmgr, vsi->num_queues, &pf->qtag);
469 device_printf(dev, "Failed to reserve queues for PF LAN VSI, error %d\n",
473 device_printf(dev, "Allocating %d queues for PF LAN VSI; %d queues active\n",
474 pf->qtag.num_allocated, pf->qtag.num_active);
476 /* Disable LLDP from the firmware for certain NVM versions */
477 if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
478 (pf->hw.aq.fw_maj_ver < 4))
479 i40e_aq_stop_lldp(hw, TRUE, NULL);
481 /* Get MAC addresses from hardware */
482 i40e_get_mac_addr(hw, hw->mac.addr);
483 error = i40e_validate_mac_addr(hw->mac.addr);
485 device_printf(dev, "validate_mac_addr failed: %d\n", error);
488 bcopy(hw->mac.addr, hw->mac.perm_addr, ETHER_ADDR_LEN);
489 i40e_get_port_mac_addr(hw, hw->mac.port_addr);
491 /* Initialize mac filter list for VSI */
492 SLIST_INIT(&vsi->ftl);
494 /* Set up SW VSI and allocate queue memory and rings */
495 if (ixl_setup_stations(pf)) {
496 device_printf(dev, "setup stations failed!\n");
501 /* Setup OS network interface / ifnet */
502 if (ixl_setup_interface(dev, vsi)) {
503 device_printf(dev, "interface setup failed!\n");
508 /* Determine link state */
509 if (ixl_attach_get_link_status(pf)) {
514 error = ixl_switch_config(pf);
516 device_printf(dev, "Initial ixl_switch_config() failed: %d\n",
521 /* Limit PHY interrupts to link, autoneg, and modules failure */
522 status = i40e_aq_set_phy_int_mask(hw, IXL_DEFAULT_PHY_INT_MASK,
525 device_printf(dev, "i40e_aq_set_phy_mask() failed: err %s,"
526 " aq_err %s\n", i40e_stat_str(hw, status),
527 i40e_aq_str(hw, hw->aq.asq_last_status));
531 /* Get the bus configuration and set the shared code's config */
532 ixl_get_bus_info(hw, dev);
535 * In MSI-X mode, initialize the Admin Queue interrupt,
536 * so userland tools can communicate with the adapter regardless of
537 * the ifnet interface's status.
540 error = ixl_setup_adminq_msix(pf);
542 device_printf(dev, "ixl_setup_adminq_msix error: %d\n",
546 error = ixl_setup_adminq_tq(pf);
548 device_printf(dev, "ixl_setup_adminq_tq error: %d\n",
552 ixl_configure_intr0_msix(pf);
553 ixl_enable_adminq(hw);
556 /* Initialize statistics & add sysctls */
557 ixl_add_device_sysctls(pf);
559 ixl_pf_reset_stats(pf);
560 ixl_update_stats_counters(pf);
561 ixl_add_hw_stats(pf);
563 /* Register for VLAN events */
564 vsi->vlan_attach = EVENTHANDLER_REGISTER(vlan_config,
565 ixl_register_vlan, vsi, EVENTHANDLER_PRI_FIRST);
566 vsi->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig,
567 ixl_unregister_vlan, vsi, EVENTHANDLER_PRI_FIRST);
570 ixl_initialize_sriov(pf);
574 ixl_netmap_attach(vsi);
575 #endif /* DEV_NETMAP */
576 INIT_DEBUGOUT("ixl_attach: end");
580 if (vsi->ifp != NULL) {
581 ether_ifdetach(vsi->ifp);
585 i40e_shutdown_lan_hmc(hw);
587 i40e_shutdown_adminq(hw);
589 ixl_free_pci_resources(pf);
591 IXL_PF_LOCK_DESTROY(pf);
595 /*********************************************************************
596 * Device removal routine
598 * The detach entry point is called when the driver is being removed.
599 * This routine stops the adapter and deallocates all the resources
600 * that were allocated for driver operation.
602 * return 0 on success, positive on failure
603 *********************************************************************/
606 ixl_detach(device_t dev)
608 struct ixl_pf *pf = device_get_softc(dev);
609 struct i40e_hw *hw = &pf->hw;
610 struct ixl_vsi *vsi = &pf->vsi;
611 enum i40e_status_code status;
616 INIT_DEBUGOUT("ixl_detach: begin");
618 /* Make sure VLANS are not using driver */
619 if (vsi->ifp->if_vlantrunk != NULL) {
620 device_printf(dev, "Vlan in use, detach first\n");
625 error = pci_iov_detach(dev);
627 device_printf(dev, "SR-IOV in use; detach first.\n");
632 ether_ifdetach(vsi->ifp);
633 if (vsi->ifp->if_drv_flags & IFF_DRV_RUNNING)
636 ixl_free_queue_tqs(vsi);
638 /* Shutdown LAN HMC */
639 status = i40e_shutdown_lan_hmc(hw);
642 "Shutdown LAN HMC failed with code %d\n", status);
644 /* Shutdown admin queue */
645 ixl_disable_adminq(hw);
646 ixl_free_adminq_tq(pf);
647 ixl_teardown_adminq_msix(pf);
648 status = i40e_shutdown_adminq(hw);
651 "Shutdown Admin queue failed with code %d\n", status);
653 /* Unregister VLAN events */
654 if (vsi->vlan_attach != NULL)
655 EVENTHANDLER_DEREGISTER(vlan_config, vsi->vlan_attach);
656 if (vsi->vlan_detach != NULL)
657 EVENTHANDLER_DEREGISTER(vlan_unconfig, vsi->vlan_detach);
659 callout_drain(&pf->timer);
661 netmap_detach(vsi->ifp);
662 #endif /* DEV_NETMAP */
663 ixl_pf_qmgr_destroy(&pf->qmgr);
664 ixl_free_pci_resources(pf);
665 bus_generic_detach(dev);
668 IXL_PF_LOCK_DESTROY(pf);
672 /*********************************************************************
674 * Shutdown entry point
676 **********************************************************************/
679 ixl_shutdown(device_t dev)
681 struct ixl_pf *pf = device_get_softc(dev);