1 /******************************************************************************
3 Copyright (c) 2001-2012, 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 ******************************************************************************/
35 #ifdef HAVE_KERNEL_OPTION_HEADERS
37 #include "opt_inet6.h"
42 /*********************************************************************
43 * Set this to one to display debug statistics
44 *********************************************************************/
45 int ixgbe_display_debug_stats = 0;
47 /*********************************************************************
49 *********************************************************************/
50 char ixgbe_driver_version[] = "2.4.8";
52 /*********************************************************************
55 * Used by probe to select devices to load on
56 * Last field stores an index into ixgbe_strings
57 * Last entry must be all 0s
59 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index }
60 *********************************************************************/
62 static ixgbe_vendor_info_t ixgbe_vendor_info_array[] =
64 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AF_DUAL_PORT, 0, 0, 0},
65 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AF_SINGLE_PORT, 0, 0, 0},
66 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_CX4, 0, 0, 0},
67 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AT, 0, 0, 0},
68 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AT2, 0, 0, 0},
69 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598, 0, 0, 0},
70 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_DA_DUAL_PORT, 0, 0, 0},
71 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_CX4_DUAL_PORT, 0, 0, 0},
72 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_XF_LR, 0, 0, 0},
73 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM, 0, 0, 0},
74 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_SFP_LOM, 0, 0, 0},
75 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KX4, 0, 0, 0},
76 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KX4_MEZZ, 0, 0, 0},
77 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP, 0, 0, 0},
78 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_XAUI_LOM, 0, 0, 0},
79 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_CX4, 0, 0, 0},
80 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_T3_LOM, 0, 0, 0},
81 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_COMBO_BACKPLANE, 0, 0, 0},
82 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_BACKPLANE_FCOE, 0, 0, 0},
83 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_SF2, 0, 0, 0},
84 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_FCOE, 0, 0, 0},
85 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599EN_SFP, 0, 0, 0},
86 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540T1, 0, 0, 0},
87 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540T, 0, 0, 0},
88 /* required last entry */
92 /*********************************************************************
93 * Table of branding strings
94 *********************************************************************/
96 static char *ixgbe_strings[] = {
97 "Intel(R) PRO/10GbE PCI-Express Network Driver"
100 /*********************************************************************
101 * Function prototypes
102 *********************************************************************/
103 static int ixgbe_probe(device_t);
104 static int ixgbe_attach(device_t);
105 static int ixgbe_detach(device_t);
106 static int ixgbe_shutdown(device_t);
107 static void ixgbe_start(struct ifnet *);
108 static void ixgbe_start_locked(struct tx_ring *, struct ifnet *);
109 #if __FreeBSD_version >= 800000
110 static int ixgbe_mq_start(struct ifnet *, struct mbuf *);
111 static int ixgbe_mq_start_locked(struct ifnet *,
112 struct tx_ring *, struct mbuf *);
113 static void ixgbe_qflush(struct ifnet *);
115 static int ixgbe_ioctl(struct ifnet *, u_long, caddr_t);
116 static void ixgbe_init(void *);
117 static void ixgbe_init_locked(struct adapter *);
118 static void ixgbe_stop(void *);
119 static void ixgbe_media_status(struct ifnet *, struct ifmediareq *);
120 static int ixgbe_media_change(struct ifnet *);
121 static void ixgbe_identify_hardware(struct adapter *);
122 static int ixgbe_allocate_pci_resources(struct adapter *);
123 static int ixgbe_allocate_msix(struct adapter *);
124 static int ixgbe_allocate_legacy(struct adapter *);
125 static int ixgbe_allocate_queues(struct adapter *);
126 static int ixgbe_setup_msix(struct adapter *);
127 static void ixgbe_free_pci_resources(struct adapter *);
128 static void ixgbe_local_timer(void *);
129 static int ixgbe_setup_interface(device_t, struct adapter *);
130 static void ixgbe_config_link(struct adapter *);
132 static int ixgbe_allocate_transmit_buffers(struct tx_ring *);
133 static int ixgbe_setup_transmit_structures(struct adapter *);
134 static void ixgbe_setup_transmit_ring(struct tx_ring *);
135 static void ixgbe_initialize_transmit_units(struct adapter *);
136 static void ixgbe_free_transmit_structures(struct adapter *);
137 static void ixgbe_free_transmit_buffers(struct tx_ring *);
139 static int ixgbe_allocate_receive_buffers(struct rx_ring *);
140 static int ixgbe_setup_receive_structures(struct adapter *);
141 static int ixgbe_setup_receive_ring(struct rx_ring *);
142 static void ixgbe_initialize_receive_units(struct adapter *);
143 static void ixgbe_free_receive_structures(struct adapter *);
144 static void ixgbe_free_receive_buffers(struct rx_ring *);
145 static void ixgbe_setup_hw_rsc(struct rx_ring *);
147 static void ixgbe_enable_intr(struct adapter *);
148 static void ixgbe_disable_intr(struct adapter *);
149 static void ixgbe_update_stats_counters(struct adapter *);
150 static bool ixgbe_txeof(struct tx_ring *);
151 static bool ixgbe_rxeof(struct ix_queue *, int);
152 static void ixgbe_rx_checksum(u32, struct mbuf *, u32);
153 static void ixgbe_set_promisc(struct adapter *);
154 static void ixgbe_set_multi(struct adapter *);
155 static void ixgbe_update_link_status(struct adapter *);
156 static void ixgbe_refresh_mbufs(struct rx_ring *, int);
157 static int ixgbe_xmit(struct tx_ring *, struct mbuf **);
158 static int ixgbe_set_flowcntl(SYSCTL_HANDLER_ARGS);
159 static int ixgbe_set_advertise(SYSCTL_HANDLER_ARGS);
160 static int ixgbe_set_thermal_test(SYSCTL_HANDLER_ARGS);
161 static int ixgbe_dma_malloc(struct adapter *, bus_size_t,
162 struct ixgbe_dma_alloc *, int);
163 static void ixgbe_dma_free(struct adapter *, struct ixgbe_dma_alloc *);
164 static void ixgbe_add_rx_process_limit(struct adapter *, const char *,
165 const char *, int *, int);
166 static bool ixgbe_tx_ctx_setup(struct tx_ring *, struct mbuf *);
167 static bool ixgbe_tso_setup(struct tx_ring *, struct mbuf *, u32 *);
168 static void ixgbe_set_ivar(struct adapter *, u8, u8, s8);
169 static void ixgbe_configure_ivars(struct adapter *);
170 static u8 * ixgbe_mc_array_itr(struct ixgbe_hw *, u8 **, u32 *);
172 static void ixgbe_setup_vlan_hw_support(struct adapter *);
173 static void ixgbe_register_vlan(void *, struct ifnet *, u16);
174 static void ixgbe_unregister_vlan(void *, struct ifnet *, u16);
176 static void ixgbe_add_hw_stats(struct adapter *adapter);
178 static __inline void ixgbe_rx_discard(struct rx_ring *, int);
179 static __inline void ixgbe_rx_input(struct rx_ring *, struct ifnet *,
182 /* Support for pluggable optic modules */
183 static bool ixgbe_sfp_probe(struct adapter *);
184 static void ixgbe_setup_optics(struct adapter *);
186 /* Legacy (single vector interrupt handler */
187 static void ixgbe_legacy_irq(void *);
189 /* The MSI/X Interrupt handlers */
190 static void ixgbe_msix_que(void *);
191 static void ixgbe_msix_link(void *);
193 /* Deferred interrupt tasklets */
194 static void ixgbe_handle_que(void *, int);
195 static void ixgbe_handle_link(void *, int);
196 static void ixgbe_handle_msf(void *, int);
197 static void ixgbe_handle_mod(void *, int);
200 static void ixgbe_atr(struct tx_ring *, struct mbuf *);
201 static void ixgbe_reinit_fdir(void *, int);
204 /*********************************************************************
205 * FreeBSD Device Interface Entry Points
206 *********************************************************************/
208 static device_method_t ixgbe_methods[] = {
209 /* Device interface */
210 DEVMETHOD(device_probe, ixgbe_probe),
211 DEVMETHOD(device_attach, ixgbe_attach),
212 DEVMETHOD(device_detach, ixgbe_detach),
213 DEVMETHOD(device_shutdown, ixgbe_shutdown),
217 static driver_t ixgbe_driver = {
218 "ix", ixgbe_methods, sizeof(struct adapter),
221 devclass_t ixgbe_devclass;
222 DRIVER_MODULE(ixgbe, pci, ixgbe_driver, ixgbe_devclass, 0, 0);
224 MODULE_DEPEND(ixgbe, pci, 1, 1, 1);
225 MODULE_DEPEND(ixgbe, ether, 1, 1, 1);
228 ** TUNEABLE PARAMETERS:
232 ** AIM: Adaptive Interrupt Moderation
233 ** which means that the interrupt rate
234 ** is varied over time based on the
235 ** traffic for that interrupt vector
237 static int ixgbe_enable_aim = TRUE;
238 TUNABLE_INT("hw.ixgbe.enable_aim", &ixgbe_enable_aim);
240 static int ixgbe_max_interrupt_rate = (4000000 / IXGBE_LOW_LATENCY);
241 TUNABLE_INT("hw.ixgbe.max_interrupt_rate", &ixgbe_max_interrupt_rate);
243 /* How many packets rxeof tries to clean at a time */
244 static int ixgbe_rx_process_limit = 128;
245 TUNABLE_INT("hw.ixgbe.rx_process_limit", &ixgbe_rx_process_limit);
248 ** Smart speed setting, default to on
249 ** this only works as a compile option
250 ** right now as its during attach, set
251 ** this to 'ixgbe_smart_speed_off' to
254 static int ixgbe_smart_speed = ixgbe_smart_speed_on;
257 * MSIX should be the default for best performance,
258 * but this allows it to be forced off for testing.
260 static int ixgbe_enable_msix = 1;
261 TUNABLE_INT("hw.ixgbe.enable_msix", &ixgbe_enable_msix);
264 * Header split: this causes the hardware to DMA
265 * the header into a separate mbuf from the payload,
266 * it can be a performance win in some workloads, but
267 * in others it actually hurts, its off by default.
269 static int ixgbe_header_split = FALSE;
270 TUNABLE_INT("hw.ixgbe.hdr_split", &ixgbe_header_split);
273 * Number of Queues, can be set to 0,
274 * it then autoconfigures based on the
275 * number of cpus with a max of 8. This
276 * can be overriden manually here.
278 static int ixgbe_num_queues = 0;
279 TUNABLE_INT("hw.ixgbe.num_queues", &ixgbe_num_queues);
282 ** Number of TX descriptors per ring,
283 ** setting higher than RX as this seems
284 ** the better performing choice.
286 static int ixgbe_txd = PERFORM_TXD;
287 TUNABLE_INT("hw.ixgbe.txd", &ixgbe_txd);
289 /* Number of RX descriptors per ring */
290 static int ixgbe_rxd = PERFORM_RXD;
291 TUNABLE_INT("hw.ixgbe.rxd", &ixgbe_rxd);
293 /* Keep running tab on them for sanity check */
294 static int ixgbe_total_ports;
298 ** For Flow Director: this is the
299 ** number of TX packets we sample
300 ** for the filter pool, this means
301 ** every 20th packet will be probed.
303 ** This feature can be disabled by
304 ** setting this to 0.
306 static int atr_sample_rate = 20;
308 ** Flow Director actually 'steals'
309 ** part of the packet buffer as its
310 ** filter pool, this variable controls
312 ** 0 = 64K, 1 = 128K, 2 = 256K
314 static int fdir_pballoc = 1;
319 * The #ifdef DEV_NETMAP / #endif blocks in this file are meant to
320 * be a reference on how to implement netmap support in a driver.
321 * Additional comments are in ixgbe_netmap.h .
323 * <dev/netmap/ixgbe_netmap.h> contains functions for netmap support
324 * that extend the standard driver.
326 #include <dev/netmap/ixgbe_netmap.h>
327 #endif /* DEV_NETMAP */
329 /*********************************************************************
330 * Device identification routine
332 * ixgbe_probe determines if the driver should be loaded on
333 * adapter based on PCI vendor/device id of the adapter.
335 * return BUS_PROBE_DEFAULT on success, positive on failure
336 *********************************************************************/
339 ixgbe_probe(device_t dev)
341 ixgbe_vendor_info_t *ent;
343 u16 pci_vendor_id = 0;
344 u16 pci_device_id = 0;
345 u16 pci_subvendor_id = 0;
346 u16 pci_subdevice_id = 0;
347 char adapter_name[256];
349 INIT_DEBUGOUT("ixgbe_probe: begin");
351 pci_vendor_id = pci_get_vendor(dev);
352 if (pci_vendor_id != IXGBE_INTEL_VENDOR_ID)
355 pci_device_id = pci_get_device(dev);
356 pci_subvendor_id = pci_get_subvendor(dev);
357 pci_subdevice_id = pci_get_subdevice(dev);
359 ent = ixgbe_vendor_info_array;
360 while (ent->vendor_id != 0) {
361 if ((pci_vendor_id == ent->vendor_id) &&
362 (pci_device_id == ent->device_id) &&
364 ((pci_subvendor_id == ent->subvendor_id) ||
365 (ent->subvendor_id == 0)) &&
367 ((pci_subdevice_id == ent->subdevice_id) ||
368 (ent->subdevice_id == 0))) {
369 sprintf(adapter_name, "%s, Version - %s",
370 ixgbe_strings[ent->index],
371 ixgbe_driver_version);
372 device_set_desc_copy(dev, adapter_name);
374 return (BUS_PROBE_DEFAULT);
381 /*********************************************************************
382 * Device initialization routine
384 * The attach entry point is called when the driver is being loaded.
385 * This routine identifies the type of hardware, allocates all resources
386 * and initializes the hardware.
388 * return 0 on success, positive on failure
389 *********************************************************************/
392 ixgbe_attach(device_t dev)
394 struct adapter *adapter;
400 INIT_DEBUGOUT("ixgbe_attach: begin");
402 /* Allocate, clear, and link in our adapter structure */
403 adapter = device_get_softc(dev);
404 adapter->dev = adapter->osdep.dev = dev;
408 IXGBE_CORE_LOCK_INIT(adapter, device_get_nameunit(dev));
412 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
413 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
414 OID_AUTO, "fc", CTLTYPE_INT | CTLFLAG_RW,
415 adapter, 0, ixgbe_set_flowcntl, "I", "Flow Control");
417 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
418 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
419 OID_AUTO, "enable_aim", CTLTYPE_INT|CTLFLAG_RW,
420 &ixgbe_enable_aim, 1, "Interrupt Moderation");
423 ** Allow a kind of speed control by forcing the autoneg
424 ** advertised speed list to only a certain value, this
425 ** supports 1G on 82599 devices, and 100Mb on x540.
427 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
428 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
429 OID_AUTO, "advertise_speed", CTLTYPE_INT | CTLFLAG_RW,
430 adapter, 0, ixgbe_set_advertise, "I", "Link Speed");
432 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
433 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
434 OID_AUTO, "ts", CTLTYPE_INT | CTLFLAG_RW, adapter,
435 0, ixgbe_set_thermal_test, "I", "Thermal Test");
437 /* Set up the timer callout */
438 callout_init_mtx(&adapter->timer, &adapter->core_mtx, 0);
440 /* Determine hardware revision */
441 ixgbe_identify_hardware(adapter);
443 /* Do base PCI setup - map BAR0 */
444 if (ixgbe_allocate_pci_resources(adapter)) {
445 device_printf(dev, "Allocation of PCI resources failed\n");
450 /* Do descriptor calc and sanity checks */
451 if (((ixgbe_txd * sizeof(union ixgbe_adv_tx_desc)) % DBA_ALIGN) != 0 ||
452 ixgbe_txd < MIN_TXD || ixgbe_txd > MAX_TXD) {
453 device_printf(dev, "TXD config issue, using default!\n");
454 adapter->num_tx_desc = DEFAULT_TXD;
456 adapter->num_tx_desc = ixgbe_txd;
459 ** With many RX rings it is easy to exceed the
460 ** system mbuf allocation. Tuning nmbclusters
461 ** can alleviate this.
463 if (nmbclusters > 0 ) {
465 s = (ixgbe_rxd * adapter->num_queues) * ixgbe_total_ports;
466 if (s > nmbclusters) {
467 device_printf(dev, "RX Descriptors exceed "
468 "system mbuf max, using default instead!\n");
469 ixgbe_rxd = DEFAULT_RXD;
473 if (((ixgbe_rxd * sizeof(union ixgbe_adv_rx_desc)) % DBA_ALIGN) != 0 ||
474 ixgbe_rxd < MIN_TXD || ixgbe_rxd > MAX_TXD) {
475 device_printf(dev, "RXD config issue, using default!\n");
476 adapter->num_rx_desc = DEFAULT_RXD;
478 adapter->num_rx_desc = ixgbe_rxd;
480 /* Allocate our TX/RX Queues */
481 if (ixgbe_allocate_queues(adapter)) {
486 /* Allocate multicast array memory. */
487 adapter->mta = malloc(sizeof(u8) * IXGBE_ETH_LENGTH_OF_ADDRESS *
488 MAX_NUM_MULTICAST_ADDRESSES, M_DEVBUF, M_NOWAIT);
489 if (adapter->mta == NULL) {
490 device_printf(dev, "Can not allocate multicast setup array\n");
495 /* Initialize the shared code */
496 error = ixgbe_init_shared_code(hw);
497 if (error == IXGBE_ERR_SFP_NOT_PRESENT) {
499 ** No optics in this port, set up
500 ** so the timer routine will probe
501 ** for later insertion.
503 adapter->sfp_probe = TRUE;
505 } else if (error == IXGBE_ERR_SFP_NOT_SUPPORTED) {
506 device_printf(dev,"Unsupported SFP+ module detected!\n");
510 device_printf(dev,"Unable to initialize the shared code\n");
515 /* Make sure we have a good EEPROM before we read from it */
516 if (ixgbe_validate_eeprom_checksum(&adapter->hw, &csum) < 0) {
517 device_printf(dev,"The EEPROM Checksum Is Not Valid\n");
522 error = ixgbe_init_hw(hw);
524 case IXGBE_ERR_EEPROM_VERSION:
525 device_printf(dev, "This device is a pre-production adapter/"
526 "LOM. Please be aware there may be issues associated "
527 "with your hardware.\n If you are experiencing problems "
528 "please contact your Intel or hardware representative "
529 "who provided you with this hardware.\n");
531 case IXGBE_ERR_SFP_NOT_SUPPORTED:
532 device_printf(dev,"Unsupported SFP+ Module\n");
534 device_printf(dev,"Hardware Initialization Failure\n");
536 case IXGBE_ERR_SFP_NOT_PRESENT:
537 device_printf(dev,"No SFP+ Module found\n");
543 /* Detect and set physical type */
544 ixgbe_setup_optics(adapter);
546 if ((adapter->msix > 1) && (ixgbe_enable_msix))
547 error = ixgbe_allocate_msix(adapter);
549 error = ixgbe_allocate_legacy(adapter);
553 /* Setup OS specific network interface */
554 if (ixgbe_setup_interface(dev, adapter) != 0)
557 /* Sysctl for limiting the amount of work done in the taskqueue */
558 ixgbe_add_rx_process_limit(adapter, "rx_processing_limit",
559 "max number of rx packets to process", &adapter->rx_process_limit,
560 ixgbe_rx_process_limit);
562 /* Initialize statistics */
563 ixgbe_update_stats_counters(adapter);
565 /* Register for VLAN events */
566 adapter->vlan_attach = EVENTHANDLER_REGISTER(vlan_config,
567 ixgbe_register_vlan, adapter, EVENTHANDLER_PRI_FIRST);
568 adapter->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig,
569 ixgbe_unregister_vlan, adapter, EVENTHANDLER_PRI_FIRST);
571 /* Print PCIE bus type/speed/width info */
572 ixgbe_get_bus_info(hw);
573 device_printf(dev,"PCI Express Bus: Speed %s %s\n",
574 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
575 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
576 (hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
577 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
578 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
581 if ((hw->bus.width <= ixgbe_bus_width_pcie_x4) &&
582 (hw->bus.speed == ixgbe_bus_speed_2500)) {
583 device_printf(dev, "PCI-Express bandwidth available"
584 " for this card\n is not sufficient for"
585 " optimal performance.\n");
586 device_printf(dev, "For optimal performance a x8 "
587 "PCIE, or x4 PCIE 2 slot is required.\n");
590 /* let hardware know driver is loaded */
591 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
592 ctrl_ext |= IXGBE_CTRL_EXT_DRV_LOAD;
593 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
595 ixgbe_add_hw_stats(adapter);
598 ixgbe_netmap_attach(adapter);
599 #endif /* DEV_NETMAP */
600 INIT_DEBUGOUT("ixgbe_attach: end");
603 ixgbe_free_transmit_structures(adapter);
604 ixgbe_free_receive_structures(adapter);
606 if (adapter->ifp != NULL)
607 if_free(adapter->ifp);
608 ixgbe_free_pci_resources(adapter);
609 free(adapter->mta, M_DEVBUF);
614 /*********************************************************************
615 * Device removal routine
617 * The detach entry point is called when the driver is being removed.
618 * This routine stops the adapter and deallocates all the resources
619 * that were allocated for driver operation.
621 * return 0 on success, positive on failure
622 *********************************************************************/
625 ixgbe_detach(device_t dev)
627 struct adapter *adapter = device_get_softc(dev);
628 struct ix_queue *que = adapter->queues;
631 INIT_DEBUGOUT("ixgbe_detach: begin");
633 /* Make sure VLANS are not using driver */
634 if (adapter->ifp->if_vlantrunk != NULL) {
635 device_printf(dev,"Vlan in use, detach first\n");
639 IXGBE_CORE_LOCK(adapter);
641 IXGBE_CORE_UNLOCK(adapter);
643 for (int i = 0; i < adapter->num_queues; i++, que++) {
645 taskqueue_drain(que->tq, &que->que_task);
646 taskqueue_free(que->tq);
650 /* Drain the Link queue */
652 taskqueue_drain(adapter->tq, &adapter->link_task);
653 taskqueue_drain(adapter->tq, &adapter->mod_task);
654 taskqueue_drain(adapter->tq, &adapter->msf_task);
656 taskqueue_drain(adapter->tq, &adapter->fdir_task);
658 taskqueue_free(adapter->tq);
661 /* let hardware know driver is unloading */
662 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
663 ctrl_ext &= ~IXGBE_CTRL_EXT_DRV_LOAD;
664 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, ctrl_ext);
666 /* Unregister VLAN events */
667 if (adapter->vlan_attach != NULL)
668 EVENTHANDLER_DEREGISTER(vlan_config, adapter->vlan_attach);
669 if (adapter->vlan_detach != NULL)
670 EVENTHANDLER_DEREGISTER(vlan_unconfig, adapter->vlan_detach);
672 ether_ifdetach(adapter->ifp);
673 callout_drain(&adapter->timer);
675 netmap_detach(adapter->ifp);
676 #endif /* DEV_NETMAP */
677 ixgbe_free_pci_resources(adapter);
678 bus_generic_detach(dev);
679 if_free(adapter->ifp);
681 ixgbe_free_transmit_structures(adapter);
682 ixgbe_free_receive_structures(adapter);
683 free(adapter->mta, M_DEVBUF);
685 IXGBE_CORE_LOCK_DESTROY(adapter);
689 /*********************************************************************
691 * Shutdown entry point
693 **********************************************************************/
696 ixgbe_shutdown(device_t dev)
698 struct adapter *adapter = device_get_softc(dev);
699 IXGBE_CORE_LOCK(adapter);
701 IXGBE_CORE_UNLOCK(adapter);
706 /*********************************************************************
707 * Transmit entry point
709 * ixgbe_start is called by the stack to initiate a transmit.
710 * The driver will remain in this routine as long as there are
711 * packets to transmit and transmit resources are available.
712 * In case resources are not available stack is notified and
713 * the packet is requeued.
714 **********************************************************************/
717 ixgbe_start_locked(struct tx_ring *txr, struct ifnet * ifp)
720 struct adapter *adapter = txr->adapter;
722 IXGBE_TX_LOCK_ASSERT(txr);
724 if ((ifp->if_drv_flags & (IFF_DRV_RUNNING|IFF_DRV_OACTIVE)) !=
727 if (!adapter->link_active)
730 while (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
731 if (txr->tx_avail <= IXGBE_QUEUE_MIN_FREE) {
732 txr->queue_status |= IXGBE_QUEUE_DEPLETED;
736 IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
740 if (ixgbe_xmit(txr, &m_head)) {
742 IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
743 if (txr->tx_avail <= IXGBE_QUEUE_MIN_FREE)
744 txr->queue_status |= IXGBE_QUEUE_DEPLETED;
747 /* Send a copy of the frame to the BPF listener */
748 ETHER_BPF_MTAP(ifp, m_head);
750 /* Set watchdog on */
751 txr->watchdog_time = ticks;
752 txr->queue_status = IXGBE_QUEUE_WORKING;
759 * Legacy TX start - called by the stack, this
760 * always uses the first tx ring, and should
761 * not be used with multiqueue tx enabled.
764 ixgbe_start(struct ifnet *ifp)
766 struct adapter *adapter = ifp->if_softc;
767 struct tx_ring *txr = adapter->tx_rings;
769 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
771 ixgbe_start_locked(txr, ifp);
772 IXGBE_TX_UNLOCK(txr);
777 #if __FreeBSD_version >= 800000
779 ** Multiqueue Transmit driver
783 ixgbe_mq_start(struct ifnet *ifp, struct mbuf *m)
785 struct adapter *adapter = ifp->if_softc;
786 struct ix_queue *que;
790 /* Which queue to use */
791 if ((m->m_flags & M_FLOWID) != 0)
792 i = m->m_pkthdr.flowid % adapter->num_queues;
794 i = curcpu % adapter->num_queues;
796 txr = &adapter->tx_rings[i];
797 que = &adapter->queues[i];
799 if (((txr->queue_status & IXGBE_QUEUE_DEPLETED) == 0) &&
800 IXGBE_TX_TRYLOCK(txr)) {
801 err = ixgbe_mq_start_locked(ifp, txr, m);
802 IXGBE_TX_UNLOCK(txr);
804 err = drbr_enqueue(ifp, txr->br, m);
805 taskqueue_enqueue(que->tq, &que->que_task);
812 ixgbe_mq_start_locked(struct ifnet *ifp, struct tx_ring *txr, struct mbuf *m)
814 struct adapter *adapter = txr->adapter;
816 int enqueued, err = 0;
818 if (((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) ||
819 (txr->queue_status == IXGBE_QUEUE_DEPLETED) ||
820 adapter->link_active == 0) {
822 err = drbr_enqueue(ifp, txr->br, m);
828 next = drbr_dequeue(ifp, txr->br);
829 } else if (drbr_needs_enqueue(ifp, txr->br)) {
830 if ((err = drbr_enqueue(ifp, txr->br, m)) != 0)
832 next = drbr_dequeue(ifp, txr->br);
836 /* Process the queue */
837 while (next != NULL) {
838 if ((err = ixgbe_xmit(txr, &next)) != 0) {
840 err = drbr_enqueue(ifp, txr->br, next);
844 /* Send a copy of the frame to the BPF listener */
845 ETHER_BPF_MTAP(ifp, next);
846 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
848 if (txr->tx_avail < IXGBE_TX_OP_THRESHOLD)
850 if (txr->tx_avail < IXGBE_TX_OP_THRESHOLD) {
851 txr->queue_status |= IXGBE_QUEUE_DEPLETED;
854 next = drbr_dequeue(ifp, txr->br);
858 /* Set watchdog on */
859 txr->queue_status |= IXGBE_QUEUE_WORKING;
860 txr->watchdog_time = ticks;
863 if (txr->tx_avail < IXGBE_TX_CLEANUP_THRESHOLD)
870 ** Flush all ring buffers
873 ixgbe_qflush(struct ifnet *ifp)
875 struct adapter *adapter = ifp->if_softc;
876 struct tx_ring *txr = adapter->tx_rings;
879 for (int i = 0; i < adapter->num_queues; i++, txr++) {
881 while ((m = buf_ring_dequeue_sc(txr->br)) != NULL)
883 IXGBE_TX_UNLOCK(txr);
887 #endif /* __FreeBSD_version >= 800000 */
889 /*********************************************************************
892 * ixgbe_ioctl is called when the user wants to configure the
895 * return 0 on success, positive on failure
896 **********************************************************************/
899 ixgbe_ioctl(struct ifnet * ifp, u_long command, caddr_t data)
901 struct adapter *adapter = ifp->if_softc;
902 struct ifreq *ifr = (struct ifreq *) data;
903 #if defined(INET) || defined(INET6)
904 struct ifaddr *ifa = (struct ifaddr *)data;
905 bool avoid_reset = FALSE;
913 if (ifa->ifa_addr->sa_family == AF_INET)
917 if (ifa->ifa_addr->sa_family == AF_INET6)
920 #if defined(INET) || defined(INET6)
922 ** Calling init results in link renegotiation,
923 ** so we avoid doing it when possible.
926 ifp->if_flags |= IFF_UP;
927 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
929 if (!(ifp->if_flags & IFF_NOARP))
930 arp_ifinit(ifp, ifa);
932 error = ether_ioctl(ifp, command, data);
936 IOCTL_DEBUGOUT("ioctl: SIOCSIFMTU (Set Interface MTU)");
937 if (ifr->ifr_mtu > IXGBE_MAX_FRAME_SIZE - ETHER_HDR_LEN) {
940 IXGBE_CORE_LOCK(adapter);
941 ifp->if_mtu = ifr->ifr_mtu;
942 adapter->max_frame_size =
943 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
944 ixgbe_init_locked(adapter);
945 IXGBE_CORE_UNLOCK(adapter);
949 IOCTL_DEBUGOUT("ioctl: SIOCSIFFLAGS (Set Interface Flags)");
950 IXGBE_CORE_LOCK(adapter);
951 if (ifp->if_flags & IFF_UP) {
952 if ((ifp->if_drv_flags & IFF_DRV_RUNNING)) {
953 if ((ifp->if_flags ^ adapter->if_flags) &
954 (IFF_PROMISC | IFF_ALLMULTI)) {
955 ixgbe_set_promisc(adapter);
958 ixgbe_init_locked(adapter);
960 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
962 adapter->if_flags = ifp->if_flags;
963 IXGBE_CORE_UNLOCK(adapter);
967 IOCTL_DEBUGOUT("ioctl: SIOC(ADD|DEL)MULTI");
968 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
969 IXGBE_CORE_LOCK(adapter);
970 ixgbe_disable_intr(adapter);
971 ixgbe_set_multi(adapter);
972 ixgbe_enable_intr(adapter);
973 IXGBE_CORE_UNLOCK(adapter);
978 IOCTL_DEBUGOUT("ioctl: SIOCxIFMEDIA (Get/Set Interface Media)");
979 error = ifmedia_ioctl(ifp, ifr, &adapter->media, command);
983 int mask = ifr->ifr_reqcap ^ ifp->if_capenable;
984 IOCTL_DEBUGOUT("ioctl: SIOCSIFCAP (Set Capabilities)");
985 if (mask & IFCAP_HWCSUM)
986 ifp->if_capenable ^= IFCAP_HWCSUM;
987 if (mask & IFCAP_TSO4)
988 ifp->if_capenable ^= IFCAP_TSO4;
989 if (mask & IFCAP_LRO)
990 ifp->if_capenable ^= IFCAP_LRO;
991 if (mask & IFCAP_VLAN_HWTAGGING)
992 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
993 if (mask & IFCAP_VLAN_HWFILTER)
994 ifp->if_capenable ^= IFCAP_VLAN_HWFILTER;
995 if (mask & IFCAP_VLAN_HWTSO)
996 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
997 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
998 IXGBE_CORE_LOCK(adapter);
999 ixgbe_init_locked(adapter);
1000 IXGBE_CORE_UNLOCK(adapter);
1002 VLAN_CAPABILITIES(ifp);
1007 IOCTL_DEBUGOUT1("ioctl: UNKNOWN (0x%X)\n", (int)command);
1008 error = ether_ioctl(ifp, command, data);
1015 /*********************************************************************
1018 * This routine is used in two ways. It is used by the stack as
1019 * init entry point in network interface structure. It is also used
1020 * by the driver as a hw/sw initialization routine to get to a
1023 * return 0 on success, positive on failure
1024 **********************************************************************/
1025 #define IXGBE_MHADD_MFS_SHIFT 16
1028 ixgbe_init_locked(struct adapter *adapter)
1030 struct ifnet *ifp = adapter->ifp;
1031 device_t dev = adapter->dev;
1032 struct ixgbe_hw *hw = &adapter->hw;
1033 u32 k, txdctl, mhadd, gpie;
1036 mtx_assert(&adapter->core_mtx, MA_OWNED);
1037 INIT_DEBUGOUT("ixgbe_init: begin");
1038 hw->adapter_stopped = FALSE;
1039 ixgbe_stop_adapter(hw);
1040 callout_stop(&adapter->timer);
1042 /* reprogram the RAR[0] in case user changed it. */
1043 ixgbe_set_rar(hw, 0, adapter->hw.mac.addr, 0, IXGBE_RAH_AV);
1045 /* Get the latest mac address, User can use a LAA */
1046 bcopy(IF_LLADDR(adapter->ifp), hw->mac.addr,
1047 IXGBE_ETH_LENGTH_OF_ADDRESS);
1048 ixgbe_set_rar(hw, 0, hw->mac.addr, 0, 1);
1049 hw->addr_ctrl.rar_used_count = 1;
1051 /* Set the various hardware offload abilities */
1052 ifp->if_hwassist = 0;
1053 if (ifp->if_capenable & IFCAP_TSO4)
1054 ifp->if_hwassist |= CSUM_TSO;
1055 if (ifp->if_capenable & IFCAP_TXCSUM) {
1056 ifp->if_hwassist |= (CSUM_TCP | CSUM_UDP);
1057 #if __FreeBSD_version >= 800000
1058 if (hw->mac.type != ixgbe_mac_82598EB)
1059 ifp->if_hwassist |= CSUM_SCTP;
1063 /* Prepare transmit descriptors and buffers */
1064 if (ixgbe_setup_transmit_structures(adapter)) {
1065 device_printf(dev,"Could not setup transmit structures\n");
1066 ixgbe_stop(adapter);
1071 ixgbe_initialize_transmit_units(adapter);
1073 /* Setup Multicast table */
1074 ixgbe_set_multi(adapter);
1077 ** Determine the correct mbuf pool
1078 ** for doing jumbo/headersplit
1080 if (adapter->max_frame_size <= 2048)
1081 adapter->rx_mbuf_sz = MCLBYTES;
1082 else if (adapter->max_frame_size <= 4096)
1083 adapter->rx_mbuf_sz = MJUMPAGESIZE;
1084 else if (adapter->max_frame_size <= 9216)
1085 adapter->rx_mbuf_sz = MJUM9BYTES;
1087 adapter->rx_mbuf_sz = MJUM16BYTES;
1089 /* Prepare receive descriptors and buffers */
1090 if (ixgbe_setup_receive_structures(adapter)) {
1091 device_printf(dev,"Could not setup receive structures\n");
1092 ixgbe_stop(adapter);
1096 /* Configure RX settings */
1097 ixgbe_initialize_receive_units(adapter);
1099 gpie = IXGBE_READ_REG(&adapter->hw, IXGBE_GPIE);
1101 /* Enable Fan Failure Interrupt */
1102 gpie |= IXGBE_SDP1_GPIEN;
1104 /* Add for Module detection */
1105 if (hw->mac.type == ixgbe_mac_82599EB)
1106 gpie |= IXGBE_SDP2_GPIEN;
1108 /* Thermal Failure Detection */
1109 if (hw->mac.type == ixgbe_mac_X540)
1110 gpie |= IXGBE_SDP0_GPIEN;
1112 if (adapter->msix > 1) {
1113 /* Enable Enhanced MSIX mode */
1114 gpie |= IXGBE_GPIE_MSIX_MODE;
1115 gpie |= IXGBE_GPIE_EIAME | IXGBE_GPIE_PBA_SUPPORT |
1118 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
1121 if (ifp->if_mtu > ETHERMTU) {
1122 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
1123 mhadd &= ~IXGBE_MHADD_MFS_MASK;
1124 mhadd |= adapter->max_frame_size << IXGBE_MHADD_MFS_SHIFT;
1125 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
1128 /* Now enable all the queues */
1130 for (int i = 0; i < adapter->num_queues; i++) {
1131 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
1132 txdctl |= IXGBE_TXDCTL_ENABLE;
1133 /* Set WTHRESH to 8, burst writeback */
1134 txdctl |= (8 << 16);
1136 * When the internal queue falls below PTHRESH (32),
1137 * start prefetching as long as there are at least
1138 * HTHRESH (1) buffers ready. The values are taken
1139 * from the Intel linux driver 3.8.21.
1140 * Prefetching enables tx line rate even with 1 queue.
1142 txdctl |= (32 << 0) | (1 << 8);
1143 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), txdctl);
1146 for (int i = 0; i < adapter->num_queues; i++) {
1147 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
1148 if (hw->mac.type == ixgbe_mac_82598EB) {
1154 rxdctl &= ~0x3FFFFF;
1157 rxdctl |= IXGBE_RXDCTL_ENABLE;
1158 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), rxdctl);
1159 for (k = 0; k < 10; k++) {
1160 if (IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)) &
1161 IXGBE_RXDCTL_ENABLE)
1169 * In netmap mode, we must preserve the buffers made
1170 * available to userspace before the if_init()
1171 * (this is true by default on the TX side, because
1172 * init makes all buffers available to userspace).
1174 * netmap_reset() and the device specific routines
1175 * (e.g. ixgbe_setup_receive_rings()) map these
1176 * buffers at the end of the NIC ring, so here we
1177 * must set the RDT (tail) register to make sure
1178 * they are not overwritten.
1180 * In this driver the NIC ring starts at RDH = 0,
1181 * RDT points to the last slot available for reception (?),
1182 * so RDT = num_rx_desc - 1 means the whole ring is available.
1184 if (ifp->if_capenable & IFCAP_NETMAP) {
1185 struct netmap_adapter *na = NA(adapter->ifp);
1186 struct netmap_kring *kring = &na->rx_rings[i];
1187 int t = na->num_rx_desc - 1 - kring->nr_hwavail;
1189 IXGBE_WRITE_REG(hw, IXGBE_RDT(i), t);
1191 #endif /* DEV_NETMAP */
1192 IXGBE_WRITE_REG(hw, IXGBE_RDT(i), adapter->num_rx_desc - 1);
1195 /* Set up VLAN support and filter */
1196 ixgbe_setup_vlan_hw_support(adapter);
1198 /* Enable Receive engine */
1199 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1200 if (hw->mac.type == ixgbe_mac_82598EB)
1201 rxctrl |= IXGBE_RXCTRL_DMBYPS;
1202 rxctrl |= IXGBE_RXCTRL_RXEN;
1203 ixgbe_enable_rx_dma(hw, rxctrl);
1205 callout_reset(&adapter->timer, hz, ixgbe_local_timer, adapter);
1207 /* Set up MSI/X routing */
1208 if (ixgbe_enable_msix) {
1209 ixgbe_configure_ivars(adapter);
1210 /* Set up auto-mask */
1211 if (hw->mac.type == ixgbe_mac_82598EB)
1212 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
1214 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
1215 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
1217 } else { /* Simple settings for Legacy/MSI */
1218 ixgbe_set_ivar(adapter, 0, 0, 0);
1219 ixgbe_set_ivar(adapter, 0, 0, 1);
1220 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
1224 /* Init Flow director */
1225 if (hw->mac.type != ixgbe_mac_82598EB) {
1226 u32 hdrm = 32 << fdir_pballoc;
1228 hw->mac.ops.setup_rxpba(hw, 0, hdrm, PBA_STRATEGY_EQUAL);
1229 ixgbe_init_fdir_signature_82599(&adapter->hw, fdir_pballoc);
1234 ** Check on any SFP devices that
1235 ** need to be kick-started
1237 if (hw->phy.type == ixgbe_phy_none) {
1238 int err = hw->phy.ops.identify(hw);
1239 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
1241 "Unsupported SFP+ module type was detected.\n");
1246 /* Set moderation on the Link interrupt */
1247 IXGBE_WRITE_REG(hw, IXGBE_EITR(adapter->linkvec), IXGBE_LINK_ITR);
1249 /* Config/Enable Link */
1250 ixgbe_config_link(adapter);
1252 /* Hardware Packet Buffer & Flow Control setup */
1254 u32 rxpb, frame, size, tmp;
1256 frame = adapter->max_frame_size;
1258 /* Calculate High Water */
1259 if (hw->mac.type == ixgbe_mac_X540)
1260 tmp = IXGBE_DV_X540(frame, frame);
1262 tmp = IXGBE_DV(frame, frame);
1263 size = IXGBE_BT2KB(tmp);
1264 rxpb = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0)) >> 10;
1265 hw->fc.high_water[0] = rxpb - size;
1267 /* Now calculate Low Water */
1268 if (hw->mac.type == ixgbe_mac_X540)
1269 tmp = IXGBE_LOW_DV_X540(frame);
1271 tmp = IXGBE_LOW_DV(frame);
1272 hw->fc.low_water[0] = IXGBE_BT2KB(tmp);
1274 adapter->fc = hw->fc.requested_mode = ixgbe_fc_full;
1275 hw->fc.pause_time = IXGBE_FC_PAUSE;
1276 hw->fc.send_xon = TRUE;
1278 /* Initialize the FC settings */
1281 /* And now turn on interrupts */
1282 ixgbe_enable_intr(adapter);
1284 /* Now inform the stack we're ready */
1285 ifp->if_drv_flags |= IFF_DRV_RUNNING;
1286 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1292 ixgbe_init(void *arg)
1294 struct adapter *adapter = arg;
1296 IXGBE_CORE_LOCK(adapter);
1297 ixgbe_init_locked(adapter);
1298 IXGBE_CORE_UNLOCK(adapter);
1305 ** MSIX Interrupt Handlers and Tasklets
1310 ixgbe_enable_queue(struct adapter *adapter, u32 vector)
1312 struct ixgbe_hw *hw = &adapter->hw;
1313 u64 queue = (u64)(1 << vector);
1316 if (hw->mac.type == ixgbe_mac_82598EB) {
1317 mask = (IXGBE_EIMS_RTX_QUEUE & queue);
1318 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1320 mask = (queue & 0xFFFFFFFF);
1322 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
1323 mask = (queue >> 32);
1325 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1330 ixgbe_disable_queue(struct adapter *adapter, u32 vector)
1332 struct ixgbe_hw *hw = &adapter->hw;
1333 u64 queue = (u64)(1 << vector);
1336 if (hw->mac.type == ixgbe_mac_82598EB) {
1337 mask = (IXGBE_EIMS_RTX_QUEUE & queue);
1338 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1340 mask = (queue & 0xFFFFFFFF);
1342 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
1343 mask = (queue >> 32);
1345 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1350 ixgbe_rearm_queues(struct adapter *adapter, u64 queues)
1354 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1355 mask = (IXGBE_EIMS_RTX_QUEUE & queues);
1356 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
1358 mask = (queues & 0xFFFFFFFF);
1359 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
1360 mask = (queues >> 32);
1361 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
1367 ixgbe_handle_que(void *context, int pending)
1369 struct ix_queue *que = context;
1370 struct adapter *adapter = que->adapter;
1371 struct tx_ring *txr = que->txr;
1372 struct ifnet *ifp = adapter->ifp;
1375 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1376 more = ixgbe_rxeof(que, adapter->rx_process_limit);
1379 #if __FreeBSD_version >= 800000
1380 if (!drbr_empty(ifp, txr->br))
1381 ixgbe_mq_start_locked(ifp, txr, NULL);
1383 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1384 ixgbe_start_locked(txr, ifp);
1386 IXGBE_TX_UNLOCK(txr);
1388 taskqueue_enqueue(que->tq, &que->que_task);
1393 /* Reenable this interrupt */
1394 ixgbe_enable_queue(adapter, que->msix);
1399 /*********************************************************************
1401 * Legacy Interrupt Service routine
1403 **********************************************************************/
1406 ixgbe_legacy_irq(void *arg)
1408 struct ix_queue *que = arg;
1409 struct adapter *adapter = que->adapter;
1410 struct ixgbe_hw *hw = &adapter->hw;
1411 struct tx_ring *txr = adapter->tx_rings;
1412 bool more_tx, more_rx;
1413 u32 reg_eicr, loop = MAX_LOOP;
1416 reg_eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
1419 if (reg_eicr == 0) {
1420 ixgbe_enable_intr(adapter);
1424 more_rx = ixgbe_rxeof(que, adapter->rx_process_limit);
1428 more_tx = ixgbe_txeof(txr);
1429 } while (loop-- && more_tx);
1430 IXGBE_TX_UNLOCK(txr);
1432 if (more_rx || more_tx)
1433 taskqueue_enqueue(que->tq, &que->que_task);
1435 /* Check for fan failure */
1436 if ((hw->phy.media_type == ixgbe_media_type_copper) &&
1437 (reg_eicr & IXGBE_EICR_GPI_SDP1)) {
1438 device_printf(adapter->dev, "\nCRITICAL: FAN FAILURE!! "
1439 "REPLACE IMMEDIATELY!!\n");
1440 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EICR_GPI_SDP1);
1443 /* Link status change */
1444 if (reg_eicr & IXGBE_EICR_LSC)
1445 taskqueue_enqueue(adapter->tq, &adapter->link_task);
1447 ixgbe_enable_intr(adapter);
1452 /*********************************************************************
1454 * MSIX Queue Interrupt Service routine
1456 **********************************************************************/
1458 ixgbe_msix_que(void *arg)
1460 struct ix_queue *que = arg;
1461 struct adapter *adapter = que->adapter;
1462 struct tx_ring *txr = que->txr;
1463 struct rx_ring *rxr = que->rxr;
1464 bool more_tx, more_rx;
1467 ixgbe_disable_queue(adapter, que->msix);
1470 more_rx = ixgbe_rxeof(que, adapter->rx_process_limit);
1473 more_tx = ixgbe_txeof(txr);
1475 ** Make certain that if the stack
1476 ** has anything queued the task gets
1477 ** scheduled to handle it.
1479 #if __FreeBSD_version < 800000
1480 if (!IFQ_DRV_IS_EMPTY(&adapter->ifp->if_snd))
1482 if (!drbr_empty(adapter->ifp, txr->br))
1485 IXGBE_TX_UNLOCK(txr);
1489 if (ixgbe_enable_aim == FALSE)
1492 ** Do Adaptive Interrupt Moderation:
1493 ** - Write out last calculated setting
1494 ** - Calculate based on average size over
1495 ** the last interval.
1497 if (que->eitr_setting)
1498 IXGBE_WRITE_REG(&adapter->hw,
1499 IXGBE_EITR(que->msix), que->eitr_setting);
1501 que->eitr_setting = 0;
1503 /* Idle, do nothing */
1504 if ((txr->bytes == 0) && (rxr->bytes == 0))
1507 if ((txr->bytes) && (txr->packets))
1508 newitr = txr->bytes/txr->packets;
1509 if ((rxr->bytes) && (rxr->packets))
1510 newitr = max(newitr,
1511 (rxr->bytes / rxr->packets));
1512 newitr += 24; /* account for hardware frame, crc */
1514 /* set an upper boundary */
1515 newitr = min(newitr, 3000);
1517 /* Be nice to the mid range */
1518 if ((newitr > 300) && (newitr < 1200))
1519 newitr = (newitr / 3);
1521 newitr = (newitr / 2);
1523 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
1524 newitr |= newitr << 16;
1526 newitr |= IXGBE_EITR_CNT_WDIS;
1528 /* save for next interrupt */
1529 que->eitr_setting = newitr;
1538 if (more_tx || more_rx)
1539 taskqueue_enqueue(que->tq, &que->que_task);
1540 else /* Reenable this interrupt */
1541 ixgbe_enable_queue(adapter, que->msix);
1547 ixgbe_msix_link(void *arg)
1549 struct adapter *adapter = arg;
1550 struct ixgbe_hw *hw = &adapter->hw;
1553 ++adapter->link_irq;
1555 /* First get the cause */
1556 reg_eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1557 /* Clear interrupt with write */
1558 IXGBE_WRITE_REG(hw, IXGBE_EICR, reg_eicr);
1560 /* Link status change */
1561 if (reg_eicr & IXGBE_EICR_LSC)
1562 taskqueue_enqueue(adapter->tq, &adapter->link_task);
1564 if (adapter->hw.mac.type != ixgbe_mac_82598EB) {
1566 if (reg_eicr & IXGBE_EICR_FLOW_DIR) {
1567 /* This is probably overkill :) */
1568 if (!atomic_cmpset_int(&adapter->fdir_reinit, 0, 1))
1570 /* Disable the interrupt */
1571 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EICR_FLOW_DIR);
1572 taskqueue_enqueue(adapter->tq, &adapter->fdir_task);
1575 if (reg_eicr & IXGBE_EICR_ECC) {
1576 device_printf(adapter->dev, "\nCRITICAL: ECC ERROR!! "
1577 "Please Reboot!!\n");
1578 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
1581 if (reg_eicr & IXGBE_EICR_GPI_SDP1) {
1582 /* Clear the interrupt */
1583 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1584 taskqueue_enqueue(adapter->tq, &adapter->msf_task);
1585 } else if (reg_eicr & IXGBE_EICR_GPI_SDP2) {
1586 /* Clear the interrupt */
1587 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1588 taskqueue_enqueue(adapter->tq, &adapter->mod_task);
1592 /* Check for fan failure */
1593 if ((hw->device_id == IXGBE_DEV_ID_82598AT) &&
1594 (reg_eicr & IXGBE_EICR_GPI_SDP1)) {
1595 device_printf(adapter->dev, "\nCRITICAL: FAN FAILURE!! "
1596 "REPLACE IMMEDIATELY!!\n");
1597 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1600 /* Check for over temp condition */
1601 if ((hw->mac.type == ixgbe_mac_X540) &&
1602 (reg_eicr & IXGBE_EICR_GPI_SDP0)) {
1603 device_printf(adapter->dev, "\nCRITICAL: OVER TEMP!! "
1604 "PHY IS SHUT DOWN!!\n");
1605 device_printf(adapter->dev, "System shutdown required\n");
1606 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP0);
1609 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
1613 /*********************************************************************
1615 * Media Ioctl callback
1617 * This routine is called whenever the user queries the status of
1618 * the interface using ifconfig.
1620 **********************************************************************/
1622 ixgbe_media_status(struct ifnet * ifp, struct ifmediareq * ifmr)
1624 struct adapter *adapter = ifp->if_softc;
1626 INIT_DEBUGOUT("ixgbe_media_status: begin");
1627 IXGBE_CORE_LOCK(adapter);
1628 ixgbe_update_link_status(adapter);
1630 ifmr->ifm_status = IFM_AVALID;
1631 ifmr->ifm_active = IFM_ETHER;
1633 if (!adapter->link_active) {
1634 IXGBE_CORE_UNLOCK(adapter);
1638 ifmr->ifm_status |= IFM_ACTIVE;
1640 switch (adapter->link_speed) {
1641 case IXGBE_LINK_SPEED_100_FULL:
1642 ifmr->ifm_active |= IFM_100_TX | IFM_FDX;
1644 case IXGBE_LINK_SPEED_1GB_FULL:
1645 ifmr->ifm_active |= IFM_1000_T | IFM_FDX;
1647 case IXGBE_LINK_SPEED_10GB_FULL:
1648 ifmr->ifm_active |= adapter->optics | IFM_FDX;
1652 IXGBE_CORE_UNLOCK(adapter);
1657 /*********************************************************************
1659 * Media Ioctl callback
1661 * This routine is called when the user changes speed/duplex using
1662 * media/mediopt option with ifconfig.
1664 **********************************************************************/
1666 ixgbe_media_change(struct ifnet * ifp)
1668 struct adapter *adapter = ifp->if_softc;
1669 struct ifmedia *ifm = &adapter->media;
1671 INIT_DEBUGOUT("ixgbe_media_change: begin");
1673 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1676 switch (IFM_SUBTYPE(ifm->ifm_media)) {
1678 adapter->hw.phy.autoneg_advertised =
1679 IXGBE_LINK_SPEED_100_FULL |
1680 IXGBE_LINK_SPEED_1GB_FULL |
1681 IXGBE_LINK_SPEED_10GB_FULL;
1684 device_printf(adapter->dev, "Only auto media type\n");
1691 /*********************************************************************
1693 * This routine maps the mbufs to tx descriptors, allowing the
1694 * TX engine to transmit the packets.
1695 * - return 0 on success, positive on failure
1697 **********************************************************************/
1700 ixgbe_xmit(struct tx_ring *txr, struct mbuf **m_headp)
1702 struct adapter *adapter = txr->adapter;
1703 u32 olinfo_status = 0, cmd_type_len;
1705 int i, j, error, nsegs;
1706 int first, last = 0;
1707 struct mbuf *m_head;
1708 bus_dma_segment_t segs[adapter->num_segs];
1710 struct ixgbe_tx_buf *txbuf;
1711 union ixgbe_adv_tx_desc *txd = NULL;
1715 /* Basic descriptor defines */
1716 cmd_type_len = (IXGBE_ADVTXD_DTYP_DATA |
1717 IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT);
1719 if (m_head->m_flags & M_VLANTAG)
1720 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
1723 * Important to capture the first descriptor
1724 * used because it will contain the index of
1725 * the one we tell the hardware to report back
1727 first = txr->next_avail_desc;
1728 txbuf = &txr->tx_buffers[first];
1732 * Map the packet for DMA.
1734 error = bus_dmamap_load_mbuf_sg(txr->txtag, map,
1735 *m_headp, segs, &nsegs, BUS_DMA_NOWAIT);
1737 if (error == EFBIG) {
1740 m = m_defrag(*m_headp, M_DONTWAIT);
1742 adapter->mbuf_defrag_failed++;
1750 error = bus_dmamap_load_mbuf_sg(txr->txtag, map,
1751 *m_headp, segs, &nsegs, BUS_DMA_NOWAIT);
1753 if (error == ENOMEM) {
1754 adapter->no_tx_dma_setup++;
1756 } else if (error != 0) {
1757 adapter->no_tx_dma_setup++;
1762 } else if (error == ENOMEM) {
1763 adapter->no_tx_dma_setup++;
1765 } else if (error != 0) {
1766 adapter->no_tx_dma_setup++;
1772 /* Make certain there are enough descriptors */
1773 if (nsegs > txr->tx_avail - 2) {
1774 txr->no_desc_avail++;
1781 ** Set up the appropriate offload context
1782 ** this becomes the first descriptor of
1785 if (m_head->m_pkthdr.csum_flags & CSUM_TSO) {
1786 if (ixgbe_tso_setup(txr, m_head, &paylen)) {
1787 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
1788 olinfo_status |= IXGBE_TXD_POPTS_IXSM << 8;
1789 olinfo_status |= IXGBE_TXD_POPTS_TXSM << 8;
1790 olinfo_status |= paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
1794 } else if (ixgbe_tx_ctx_setup(txr, m_head))
1795 olinfo_status |= IXGBE_TXD_POPTS_TXSM << 8;
1797 #ifdef IXGBE_IEEE1588
1798 /* This is changing soon to an mtag detection */
1799 if (we detect this mbuf has a TSTAMP mtag)
1800 cmd_type_len |= IXGBE_ADVTXD_MAC_TSTAMP;
1804 /* Do the flow director magic */
1805 if ((txr->atr_sample) && (!adapter->fdir_reinit)) {
1807 if (txr->atr_count >= atr_sample_rate) {
1808 ixgbe_atr(txr, m_head);
1813 /* Record payload length */
1815 olinfo_status |= m_head->m_pkthdr.len <<
1816 IXGBE_ADVTXD_PAYLEN_SHIFT;
1818 i = txr->next_avail_desc;
1819 for (j = 0; j < nsegs; j++) {
1823 txbuf = &txr->tx_buffers[i];
1824 txd = &txr->tx_base[i];
1825 seglen = segs[j].ds_len;
1826 segaddr = htole64(segs[j].ds_addr);
1828 txd->read.buffer_addr = segaddr;
1829 txd->read.cmd_type_len = htole32(txr->txd_cmd |
1830 cmd_type_len |seglen);
1831 txd->read.olinfo_status = htole32(olinfo_status);
1832 last = i; /* descriptor that will get completion IRQ */
1834 if (++i == adapter->num_tx_desc)
1837 txbuf->m_head = NULL;
1838 txbuf->eop_index = -1;
1841 txd->read.cmd_type_len |=
1842 htole32(IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS);
1843 txr->tx_avail -= nsegs;
1844 txr->next_avail_desc = i;
1846 txbuf->m_head = m_head;
1847 /* Swap the dma map between the first and last descriptor */
1848 txr->tx_buffers[first].map = txbuf->map;
1850 bus_dmamap_sync(txr->txtag, map, BUS_DMASYNC_PREWRITE);
1852 /* Set the index of the descriptor that will be marked done */
1853 txbuf = &txr->tx_buffers[first];
1854 txbuf->eop_index = last;
1856 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
1857 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1859 * Advance the Transmit Descriptor Tail (Tdt), this tells the
1860 * hardware that this frame is available to transmit.
1862 ++txr->total_packets;
1863 IXGBE_WRITE_REG(&adapter->hw, IXGBE_TDT(txr->me), i);
1868 bus_dmamap_unload(txr->txtag, txbuf->map);
1874 ixgbe_set_promisc(struct adapter *adapter)
1877 struct ifnet *ifp = adapter->ifp;
1879 reg_rctl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1880 reg_rctl &= (~IXGBE_FCTRL_UPE);
1881 reg_rctl &= (~IXGBE_FCTRL_MPE);
1882 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, reg_rctl);
1884 if (ifp->if_flags & IFF_PROMISC) {
1885 reg_rctl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1886 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, reg_rctl);
1887 } else if (ifp->if_flags & IFF_ALLMULTI) {
1888 reg_rctl |= IXGBE_FCTRL_MPE;
1889 reg_rctl &= ~IXGBE_FCTRL_UPE;
1890 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, reg_rctl);
1896 /*********************************************************************
1899 * This routine is called whenever multicast address list is updated.
1901 **********************************************************************/
1902 #define IXGBE_RAR_ENTRIES 16
1905 ixgbe_set_multi(struct adapter *adapter)
1910 struct ifmultiaddr *ifma;
1912 struct ifnet *ifp = adapter->ifp;
1914 IOCTL_DEBUGOUT("ixgbe_set_multi: begin");
1917 bzero(mta, sizeof(u8) * IXGBE_ETH_LENGTH_OF_ADDRESS *
1918 MAX_NUM_MULTICAST_ADDRESSES);
1920 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1921 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1922 if (ifp->if_flags & IFF_PROMISC)
1923 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1924 else if (ifp->if_flags & IFF_ALLMULTI) {
1925 fctrl |= IXGBE_FCTRL_MPE;
1926 fctrl &= ~IXGBE_FCTRL_UPE;
1928 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1930 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1932 #if __FreeBSD_version < 800000
1935 if_maddr_rlock(ifp);
1937 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1938 if (ifma->ifma_addr->sa_family != AF_LINK)
1940 bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr),
1941 &mta[mcnt * IXGBE_ETH_LENGTH_OF_ADDRESS],
1942 IXGBE_ETH_LENGTH_OF_ADDRESS);
1945 #if __FreeBSD_version < 800000
1946 IF_ADDR_UNLOCK(ifp);
1948 if_maddr_runlock(ifp);
1952 ixgbe_update_mc_addr_list(&adapter->hw,
1953 update_ptr, mcnt, ixgbe_mc_array_itr, TRUE);
1959 * This is an iterator function now needed by the multicast
1960 * shared code. It simply feeds the shared code routine the
1961 * addresses in the array of ixgbe_set_multi() one by one.
1964 ixgbe_mc_array_itr(struct ixgbe_hw *hw, u8 **update_ptr, u32 *vmdq)
1966 u8 *addr = *update_ptr;
1970 newptr = addr + IXGBE_ETH_LENGTH_OF_ADDRESS;
1971 *update_ptr = newptr;
1976 /*********************************************************************
1979 * This routine checks for link status,updates statistics,
1980 * and runs the watchdog check.
1982 **********************************************************************/
1985 ixgbe_local_timer(void *arg)
1987 struct adapter *adapter = arg;
1988 device_t dev = adapter->dev;
1989 struct ifnet *ifp = adapter->ifp;
1990 struct ix_queue *que = adapter->queues;
1991 struct tx_ring *txr = adapter->tx_rings;
1992 int hung, busy, paused;
1994 mtx_assert(&adapter->core_mtx, MA_OWNED);
1995 hung = busy = paused = 0;
1997 /* Check for pluggable optics */
1998 if (adapter->sfp_probe)
1999 if (!ixgbe_sfp_probe(adapter))
2000 goto out; /* Nothing to do */
2002 ixgbe_update_link_status(adapter);
2003 ixgbe_update_stats_counters(adapter);
2006 * If the interface has been paused
2007 * then don't do the watchdog check
2009 if (IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)
2013 ** Check the TX queues status
2014 ** - central locked handling of OACTIVE
2015 ** - watchdog only if all queues show hung
2017 for (int i = 0; i < adapter->num_queues; i++, que++, txr++) {
2018 if ((txr->queue_status & IXGBE_QUEUE_HUNG) &&
2021 if (txr->queue_status & IXGBE_QUEUE_DEPLETED)
2023 if ((txr->queue_status & IXGBE_QUEUE_IDLE) == 0)
2024 taskqueue_enqueue(que->tq, &que->que_task);
2026 /* Only truely watchdog if all queues show hung */
2027 if (hung == adapter->num_queues)
2029 /* Only turn off the stack flow when ALL are depleted */
2030 if (busy == adapter->num_queues)
2031 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2032 else if ((ifp->if_drv_flags & IFF_DRV_OACTIVE) &&
2033 (busy < adapter->num_queues))
2034 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
2037 ixgbe_rearm_queues(adapter, adapter->que_mask);
2038 callout_reset(&adapter->timer, hz, ixgbe_local_timer, adapter);
2042 device_printf(adapter->dev, "Watchdog timeout -- resetting\n");
2043 device_printf(dev,"Queue(%d) tdh = %d, hw tdt = %d\n", txr->me,
2044 IXGBE_READ_REG(&adapter->hw, IXGBE_TDH(txr->me)),
2045 IXGBE_READ_REG(&adapter->hw, IXGBE_TDT(txr->me)));
2046 device_printf(dev,"TX(%d) desc avail = %d,"
2047 "Next TX to Clean = %d\n",
2048 txr->me, txr->tx_avail, txr->next_to_clean);
2049 adapter->ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
2050 adapter->watchdog_events++;
2051 ixgbe_init_locked(adapter);
2055 ** Note: this routine updates the OS on the link state
2056 ** the real check of the hardware only happens with
2057 ** a link interrupt.
2060 ixgbe_update_link_status(struct adapter *adapter)
2062 struct ifnet *ifp = adapter->ifp;
2063 struct tx_ring *txr = adapter->tx_rings;
2064 device_t dev = adapter->dev;
2067 if (adapter->link_up){
2068 if (adapter->link_active == FALSE) {
2070 device_printf(dev,"Link is up %d Gbps %s \n",
2071 ((adapter->link_speed == 128)? 10:1),
2073 adapter->link_active = TRUE;
2074 /* Update any Flow Control changes */
2075 ixgbe_fc_enable(&adapter->hw);
2076 if_link_state_change(ifp, LINK_STATE_UP);
2078 } else { /* Link down */
2079 if (adapter->link_active == TRUE) {
2081 device_printf(dev,"Link is Down\n");
2082 if_link_state_change(ifp, LINK_STATE_DOWN);
2083 adapter->link_active = FALSE;
2084 for (int i = 0; i < adapter->num_queues;
2086 txr->queue_status = IXGBE_QUEUE_IDLE;
2094 /*********************************************************************
2096 * This routine disables all traffic on the adapter by issuing a
2097 * global reset on the MAC and deallocates TX/RX buffers.
2099 **********************************************************************/
2102 ixgbe_stop(void *arg)
2105 struct adapter *adapter = arg;
2106 struct ixgbe_hw *hw = &adapter->hw;
2109 mtx_assert(&adapter->core_mtx, MA_OWNED);
2111 INIT_DEBUGOUT("ixgbe_stop: begin\n");
2112 ixgbe_disable_intr(adapter);
2113 callout_stop(&adapter->timer);
2115 /* Let the stack know...*/
2116 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
2117 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
2120 hw->adapter_stopped = FALSE;
2121 ixgbe_stop_adapter(hw);
2122 /* Turn off the laser */
2123 if (hw->phy.multispeed_fiber)
2124 ixgbe_disable_tx_laser(hw);
2126 /* reprogram the RAR[0] in case user changed it. */
2127 ixgbe_set_rar(&adapter->hw, 0, adapter->hw.mac.addr, 0, IXGBE_RAH_AV);
2133 /*********************************************************************
2135 * Determine hardware revision.
2137 **********************************************************************/
2139 ixgbe_identify_hardware(struct adapter *adapter)
2141 device_t dev = adapter->dev;
2142 struct ixgbe_hw *hw = &adapter->hw;
2144 /* Save off the information about this board */
2145 hw->vendor_id = pci_get_vendor(dev);
2146 hw->device_id = pci_get_device(dev);
2147 hw->revision_id = pci_read_config(dev, PCIR_REVID, 1);
2148 hw->subsystem_vendor_id =
2149 pci_read_config(dev, PCIR_SUBVEND_0, 2);
2150 hw->subsystem_device_id =
2151 pci_read_config(dev, PCIR_SUBDEV_0, 2);
2153 /* We need this here to set the num_segs below */
2154 ixgbe_set_mac_type(hw);
2156 /* Pick up the 82599 and VF settings */
2157 if (hw->mac.type != ixgbe_mac_82598EB) {
2158 hw->phy.smart_speed = ixgbe_smart_speed;
2159 adapter->num_segs = IXGBE_82599_SCATTER;
2161 adapter->num_segs = IXGBE_82598_SCATTER;
2166 /*********************************************************************
2168 * Determine optic type
2170 **********************************************************************/
2172 ixgbe_setup_optics(struct adapter *adapter)
2174 struct ixgbe_hw *hw = &adapter->hw;
2177 layer = ixgbe_get_supported_physical_layer(hw);
2179 if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_T) {
2180 adapter->optics = IFM_10G_T;
2184 if (layer & IXGBE_PHYSICAL_LAYER_1000BASE_T) {
2185 adapter->optics = IFM_1000_T;
2189 if (layer & (IXGBE_PHYSICAL_LAYER_10GBASE_LR |
2190 IXGBE_PHYSICAL_LAYER_10GBASE_LRM)) {
2191 adapter->optics = IFM_10G_LR;
2195 if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_SR) {
2196 adapter->optics = IFM_10G_SR;
2200 if (layer & IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU) {
2201 adapter->optics = IFM_10G_TWINAX;
2205 if (layer & (IXGBE_PHYSICAL_LAYER_10GBASE_KX4 |
2206 IXGBE_PHYSICAL_LAYER_10GBASE_CX4)) {
2207 adapter->optics = IFM_10G_CX4;
2211 /* If we get here just set the default */
2212 adapter->optics = IFM_ETHER | IFM_AUTO;
2216 /*********************************************************************
2218 * Setup the Legacy or MSI Interrupt handler
2220 **********************************************************************/
2222 ixgbe_allocate_legacy(struct adapter *adapter)
2224 device_t dev = adapter->dev;
2225 struct ix_queue *que = adapter->queues;
2229 if (adapter->msix == 1)
2232 /* We allocate a single interrupt resource */
2233 adapter->res = bus_alloc_resource_any(dev,
2234 SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE);
2235 if (adapter->res == NULL) {
2236 device_printf(dev, "Unable to allocate bus resource: "
2242 * Try allocating a fast interrupt and the associated deferred
2243 * processing contexts.
2245 TASK_INIT(&que->que_task, 0, ixgbe_handle_que, que);
2246 que->tq = taskqueue_create_fast("ixgbe_que", M_NOWAIT,
2247 taskqueue_thread_enqueue, &que->tq);
2248 taskqueue_start_threads(&que->tq, 1, PI_NET, "%s ixq",
2249 device_get_nameunit(adapter->dev));
2251 /* Tasklets for Link, SFP and Multispeed Fiber */
2252 TASK_INIT(&adapter->link_task, 0, ixgbe_handle_link, adapter);
2253 TASK_INIT(&adapter->mod_task, 0, ixgbe_handle_mod, adapter);
2254 TASK_INIT(&adapter->msf_task, 0, ixgbe_handle_msf, adapter);
2256 TASK_INIT(&adapter->fdir_task, 0, ixgbe_reinit_fdir, adapter);
2258 adapter->tq = taskqueue_create_fast("ixgbe_link", M_NOWAIT,
2259 taskqueue_thread_enqueue, &adapter->tq);
2260 taskqueue_start_threads(&adapter->tq, 1, PI_NET, "%s linkq",
2261 device_get_nameunit(adapter->dev));
2263 if ((error = bus_setup_intr(dev, adapter->res,
2264 INTR_TYPE_NET | INTR_MPSAFE, NULL, ixgbe_legacy_irq,
2265 que, &adapter->tag)) != 0) {
2266 device_printf(dev, "Failed to register fast interrupt "
2267 "handler: %d\n", error);
2268 taskqueue_free(que->tq);
2269 taskqueue_free(adapter->tq);
2274 /* For simplicity in the handlers */
2275 adapter->que_mask = IXGBE_EIMS_ENABLE_MASK;
2281 /*********************************************************************
2283 * Setup MSIX Interrupt resources and handlers
2285 **********************************************************************/
2287 ixgbe_allocate_msix(struct adapter *adapter)
2289 device_t dev = adapter->dev;
2290 struct ix_queue *que = adapter->queues;
2291 int error, rid, vector = 0;
2293 for (int i = 0; i < adapter->num_queues; i++, vector++, que++) {
2295 que->res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
2296 RF_SHAREABLE | RF_ACTIVE);
2297 if (que->res == NULL) {
2298 device_printf(dev,"Unable to allocate"
2299 " bus resource: que interrupt [%d]\n", vector);
2302 /* Set the handler function */
2303 error = bus_setup_intr(dev, que->res,
2304 INTR_TYPE_NET | INTR_MPSAFE, NULL,
2305 ixgbe_msix_que, que, &que->tag);
2308 device_printf(dev, "Failed to register QUE handler");
2311 #if __FreeBSD_version >= 800504
2312 bus_describe_intr(dev, que->res, que->tag, "que %d", i);
2315 adapter->que_mask |= (u64)(1 << que->msix);
2317 ** Bind the msix vector, and thus the
2318 ** ring to the corresponding cpu.
2320 if (adapter->num_queues > 1)
2321 bus_bind_intr(dev, que->res, i);
2323 TASK_INIT(&que->que_task, 0, ixgbe_handle_que, que);
2324 que->tq = taskqueue_create_fast("ixgbe_que", M_NOWAIT,
2325 taskqueue_thread_enqueue, &que->tq);
2326 taskqueue_start_threads(&que->tq, 1, PI_NET, "%s que",
2327 device_get_nameunit(adapter->dev));
2332 adapter->res = bus_alloc_resource_any(dev,
2333 SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE);
2334 if (!adapter->res) {
2335 device_printf(dev,"Unable to allocate"
2336 " bus resource: Link interrupt [%d]\n", rid);
2339 /* Set the link handler function */
2340 error = bus_setup_intr(dev, adapter->res,
2341 INTR_TYPE_NET | INTR_MPSAFE, NULL,
2342 ixgbe_msix_link, adapter, &adapter->tag);
2344 adapter->res = NULL;
2345 device_printf(dev, "Failed to register LINK handler");
2348 #if __FreeBSD_version >= 800504
2349 bus_describe_intr(dev, adapter->res, adapter->tag, "link");
2351 adapter->linkvec = vector;
2352 /* Tasklets for Link, SFP and Multispeed Fiber */
2353 TASK_INIT(&adapter->link_task, 0, ixgbe_handle_link, adapter);
2354 TASK_INIT(&adapter->mod_task, 0, ixgbe_handle_mod, adapter);
2355 TASK_INIT(&adapter->msf_task, 0, ixgbe_handle_msf, adapter);
2357 TASK_INIT(&adapter->fdir_task, 0, ixgbe_reinit_fdir, adapter);
2359 adapter->tq = taskqueue_create_fast("ixgbe_link", M_NOWAIT,
2360 taskqueue_thread_enqueue, &adapter->tq);
2361 taskqueue_start_threads(&adapter->tq, 1, PI_NET, "%s linkq",
2362 device_get_nameunit(adapter->dev));
2368 * Setup Either MSI/X or MSI
2371 ixgbe_setup_msix(struct adapter *adapter)
2373 device_t dev = adapter->dev;
2374 int rid, want, queues, msgs;
2376 /* Override by tuneable */
2377 if (ixgbe_enable_msix == 0)
2380 /* First try MSI/X */
2381 rid = PCIR_BAR(MSIX_82598_BAR);
2382 adapter->msix_mem = bus_alloc_resource_any(dev,
2383 SYS_RES_MEMORY, &rid, RF_ACTIVE);
2384 if (!adapter->msix_mem) {
2385 rid += 4; /* 82599 maps in higher BAR */
2386 adapter->msix_mem = bus_alloc_resource_any(dev,
2387 SYS_RES_MEMORY, &rid, RF_ACTIVE);
2389 if (!adapter->msix_mem) {
2390 /* May not be enabled */
2391 device_printf(adapter->dev,
2392 "Unable to map MSIX table \n");
2396 msgs = pci_msix_count(dev);
2397 if (msgs == 0) { /* system has msix disabled */
2398 bus_release_resource(dev, SYS_RES_MEMORY,
2399 rid, adapter->msix_mem);
2400 adapter->msix_mem = NULL;
2404 /* Figure out a reasonable auto config value */
2405 queues = (mp_ncpus > (msgs-1)) ? (msgs-1) : mp_ncpus;
2407 if (ixgbe_num_queues != 0)
2408 queues = ixgbe_num_queues;
2409 /* Set max queues to 8 when autoconfiguring */
2410 else if ((ixgbe_num_queues == 0) && (queues > 8))
2414 ** Want one vector (RX/TX pair) per queue
2415 ** plus an additional for Link.
2421 device_printf(adapter->dev,
2422 "MSIX Configuration Problem, "
2423 "%d vectors but %d queues wanted!\n",
2425 return (0); /* Will go to Legacy setup */
2427 if ((msgs) && pci_alloc_msix(dev, &msgs) == 0) {
2428 device_printf(adapter->dev,
2429 "Using MSIX interrupts with %d vectors\n", msgs);
2430 adapter->num_queues = queues;
2434 msgs = pci_msi_count(dev);
2435 if (msgs == 1 && pci_alloc_msi(dev, &msgs) == 0)
2436 device_printf(adapter->dev,"Using an MSI interrupt\n");
2438 device_printf(adapter->dev,"Using a Legacy interrupt\n");
2444 ixgbe_allocate_pci_resources(struct adapter *adapter)
2447 device_t dev = adapter->dev;
2450 adapter->pci_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
2453 if (!(adapter->pci_mem)) {
2454 device_printf(dev,"Unable to allocate bus resource: memory\n");
2458 adapter->osdep.mem_bus_space_tag =
2459 rman_get_bustag(adapter->pci_mem);
2460 adapter->osdep.mem_bus_space_handle =
2461 rman_get_bushandle(adapter->pci_mem);
2462 adapter->hw.hw_addr = (u8 *) &adapter->osdep.mem_bus_space_handle;
2464 /* Legacy defaults */
2465 adapter->num_queues = 1;
2466 adapter->hw.back = &adapter->osdep;
2469 ** Now setup MSI or MSI/X, should
2470 ** return us the number of supported
2471 ** vectors. (Will be 1 for MSI)
2473 adapter->msix = ixgbe_setup_msix(adapter);
2478 ixgbe_free_pci_resources(struct adapter * adapter)
2480 struct ix_queue *que = adapter->queues;
2481 device_t dev = adapter->dev;
2484 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
2485 memrid = PCIR_BAR(MSIX_82598_BAR);
2487 memrid = PCIR_BAR(MSIX_82599_BAR);
2490 ** There is a slight possibility of a failure mode
2491 ** in attach that will result in entering this function
2492 ** before interrupt resources have been initialized, and
2493 ** in that case we do not want to execute the loops below
2494 ** We can detect this reliably by the state of the adapter
2497 if (adapter->res == NULL)
2501 ** Release all msix queue resources:
2503 for (int i = 0; i < adapter->num_queues; i++, que++) {
2504 rid = que->msix + 1;
2505 if (que->tag != NULL) {
2506 bus_teardown_intr(dev, que->res, que->tag);
2509 if (que->res != NULL)
2510 bus_release_resource(dev, SYS_RES_IRQ, rid, que->res);
2514 /* Clean the Legacy or Link interrupt last */
2515 if (adapter->linkvec) /* we are doing MSIX */
2516 rid = adapter->linkvec + 1;
2518 (adapter->msix != 0) ? (rid = 1):(rid = 0);
2520 if (adapter->tag != NULL) {
2521 bus_teardown_intr(dev, adapter->res, adapter->tag);
2522 adapter->tag = NULL;
2524 if (adapter->res != NULL)
2525 bus_release_resource(dev, SYS_RES_IRQ, rid, adapter->res);
2529 pci_release_msi(dev);
2531 if (adapter->msix_mem != NULL)
2532 bus_release_resource(dev, SYS_RES_MEMORY,
2533 memrid, adapter->msix_mem);
2535 if (adapter->pci_mem != NULL)
2536 bus_release_resource(dev, SYS_RES_MEMORY,
2537 PCIR_BAR(0), adapter->pci_mem);
2542 /*********************************************************************
2544 * Setup networking device structure and register an interface.
2546 **********************************************************************/
2548 ixgbe_setup_interface(device_t dev, struct adapter *adapter)
2550 struct ixgbe_hw *hw = &adapter->hw;
2553 INIT_DEBUGOUT("ixgbe_setup_interface: begin");
2555 ifp = adapter->ifp = if_alloc(IFT_ETHER);
2557 device_printf(dev, "can not allocate ifnet structure\n");
2560 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
2561 ifp->if_baudrate = 1000000000;
2562 ifp->if_init = ixgbe_init;
2563 ifp->if_softc = adapter;
2564 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
2565 ifp->if_ioctl = ixgbe_ioctl;
2566 ifp->if_start = ixgbe_start;
2567 #if __FreeBSD_version >= 800000
2568 ifp->if_transmit = ixgbe_mq_start;
2569 ifp->if_qflush = ixgbe_qflush;
2571 ifp->if_snd.ifq_maxlen = adapter->num_tx_desc - 2;
2573 ether_ifattach(ifp, adapter->hw.mac.addr);
2575 adapter->max_frame_size =
2576 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
2579 * Tell the upper layer(s) we support long frames.
2581 ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
2583 ifp->if_capabilities |= IFCAP_HWCSUM | IFCAP_TSO4 | IFCAP_VLAN_HWCSUM;
2584 ifp->if_capabilities |= IFCAP_JUMBO_MTU;
2585 ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING
2588 ifp->if_capenable = ifp->if_capabilities;
2590 /* Don't enable LRO by default */
2591 ifp->if_capabilities |= IFCAP_LRO;
2594 ** Don't turn this on by default, if vlans are
2595 ** created on another pseudo device (eg. lagg)
2596 ** then vlan events are not passed thru, breaking
2597 ** operation, but with HW FILTER off it works. If
2598 ** using vlans directly on the ixgbe driver you can
2599 ** enable this and get full hardware tag filtering.
2601 ifp->if_capabilities |= IFCAP_VLAN_HWFILTER;
2604 * Specify the media types supported by this adapter and register
2605 * callbacks to update media and link information
2607 ifmedia_init(&adapter->media, IFM_IMASK, ixgbe_media_change,
2608 ixgbe_media_status);
2609 ifmedia_add(&adapter->media, IFM_ETHER | adapter->optics, 0, NULL);
2610 ifmedia_set(&adapter->media, IFM_ETHER | adapter->optics);
2611 if (hw->device_id == IXGBE_DEV_ID_82598AT) {
2612 ifmedia_add(&adapter->media,
2613 IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL);
2614 ifmedia_add(&adapter->media,
2615 IFM_ETHER | IFM_1000_T, 0, NULL);
2617 ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL);
2618 ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO);
2624 ixgbe_config_link(struct adapter *adapter)
2626 struct ixgbe_hw *hw = &adapter->hw;
2627 u32 autoneg, err = 0;
2628 bool sfp, negotiate;
2630 sfp = ixgbe_is_sfp(hw);
2633 if (hw->phy.multispeed_fiber) {
2634 hw->mac.ops.setup_sfp(hw);
2635 ixgbe_enable_tx_laser(hw);
2636 taskqueue_enqueue(adapter->tq, &adapter->msf_task);
2638 taskqueue_enqueue(adapter->tq, &adapter->mod_task);
2640 if (hw->mac.ops.check_link)
2641 err = ixgbe_check_link(hw, &autoneg,
2642 &adapter->link_up, FALSE);
2645 autoneg = hw->phy.autoneg_advertised;
2646 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
2647 err = hw->mac.ops.get_link_capabilities(hw,
2648 &autoneg, &negotiate);
2651 if (hw->mac.ops.setup_link)
2652 err = hw->mac.ops.setup_link(hw, autoneg,
2653 negotiate, adapter->link_up);
2659 /********************************************************************
2660 * Manage DMA'able memory.
2661 *******************************************************************/
2663 ixgbe_dmamap_cb(void *arg, bus_dma_segment_t * segs, int nseg, int error)
2667 *(bus_addr_t *) arg = segs->ds_addr;
2672 ixgbe_dma_malloc(struct adapter *adapter, bus_size_t size,
2673 struct ixgbe_dma_alloc *dma, int mapflags)
2675 device_t dev = adapter->dev;
2678 r = bus_dma_tag_create(bus_get_dma_tag(adapter->dev), /* parent */
2679 DBA_ALIGN, 0, /* alignment, bounds */
2680 BUS_SPACE_MAXADDR, /* lowaddr */
2681 BUS_SPACE_MAXADDR, /* highaddr */
2682 NULL, NULL, /* filter, filterarg */
2685 size, /* maxsegsize */
2686 BUS_DMA_ALLOCNOW, /* flags */
2687 NULL, /* lockfunc */
2688 NULL, /* lockfuncarg */
2691 device_printf(dev,"ixgbe_dma_malloc: bus_dma_tag_create failed; "
2695 r = bus_dmamem_alloc(dma->dma_tag, (void **)&dma->dma_vaddr,
2696 BUS_DMA_NOWAIT, &dma->dma_map);
2698 device_printf(dev,"ixgbe_dma_malloc: bus_dmamem_alloc failed; "
2702 r = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
2706 mapflags | BUS_DMA_NOWAIT);
2708 device_printf(dev,"ixgbe_dma_malloc: bus_dmamap_load failed; "
2712 dma->dma_size = size;
2715 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
2717 bus_dma_tag_destroy(dma->dma_tag);
2719 dma->dma_map = NULL;
2720 dma->dma_tag = NULL;
2725 ixgbe_dma_free(struct adapter *adapter, struct ixgbe_dma_alloc *dma)
2727 bus_dmamap_sync(dma->dma_tag, dma->dma_map,
2728 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
2729 bus_dmamap_unload(dma->dma_tag, dma->dma_map);
2730 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
2731 bus_dma_tag_destroy(dma->dma_tag);
2735 /*********************************************************************
2737 * Allocate memory for the transmit and receive rings, and then
2738 * the descriptors associated with each, called only once at attach.
2740 **********************************************************************/
2742 ixgbe_allocate_queues(struct adapter *adapter)
2744 device_t dev = adapter->dev;
2745 struct ix_queue *que;
2746 struct tx_ring *txr;
2747 struct rx_ring *rxr;
2748 int rsize, tsize, error = IXGBE_SUCCESS;
2749 int txconf = 0, rxconf = 0;
2751 /* First allocate the top level queue structs */
2752 if (!(adapter->queues =
2753 (struct ix_queue *) malloc(sizeof(struct ix_queue) *
2754 adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2755 device_printf(dev, "Unable to allocate queue memory\n");
2760 /* First allocate the TX ring struct memory */
2761 if (!(adapter->tx_rings =
2762 (struct tx_ring *) malloc(sizeof(struct tx_ring) *
2763 adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2764 device_printf(dev, "Unable to allocate TX ring memory\n");
2769 /* Next allocate the RX */
2770 if (!(adapter->rx_rings =
2771 (struct rx_ring *) malloc(sizeof(struct rx_ring) *
2772 adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2773 device_printf(dev, "Unable to allocate RX ring memory\n");
2778 /* For the ring itself */
2779 tsize = roundup2(adapter->num_tx_desc *
2780 sizeof(union ixgbe_adv_tx_desc), DBA_ALIGN);
2783 * Now set up the TX queues, txconf is needed to handle the
2784 * possibility that things fail midcourse and we need to
2785 * undo memory gracefully
2787 for (int i = 0; i < adapter->num_queues; i++, txconf++) {
2788 /* Set up some basics */
2789 txr = &adapter->tx_rings[i];
2790 txr->adapter = adapter;
2793 /* Initialize the TX side lock */
2794 snprintf(txr->mtx_name, sizeof(txr->mtx_name), "%s:tx(%d)",
2795 device_get_nameunit(dev), txr->me);
2796 mtx_init(&txr->tx_mtx, txr->mtx_name, NULL, MTX_DEF);
2798 if (ixgbe_dma_malloc(adapter, tsize,
2799 &txr->txdma, BUS_DMA_NOWAIT)) {
2801 "Unable to allocate TX Descriptor memory\n");
2805 txr->tx_base = (union ixgbe_adv_tx_desc *)txr->txdma.dma_vaddr;
2806 bzero((void *)txr->tx_base, tsize);
2808 /* Now allocate transmit buffers for the ring */
2809 if (ixgbe_allocate_transmit_buffers(txr)) {
2811 "Critical Failure setting up transmit buffers\n");
2815 #if __FreeBSD_version >= 800000
2816 /* Allocate a buf ring */
2817 txr->br = buf_ring_alloc(IXGBE_BR_SIZE, M_DEVBUF,
2818 M_WAITOK, &txr->tx_mtx);
2819 if (txr->br == NULL) {
2821 "Critical Failure setting up buf ring\n");
2829 * Next the RX queues...
2831 rsize = roundup2(adapter->num_rx_desc *
2832 sizeof(union ixgbe_adv_rx_desc), DBA_ALIGN);
2833 for (int i = 0; i < adapter->num_queues; i++, rxconf++) {
2834 rxr = &adapter->rx_rings[i];
2835 /* Set up some basics */
2836 rxr->adapter = adapter;
2839 /* Initialize the RX side lock */
2840 snprintf(rxr->mtx_name, sizeof(rxr->mtx_name), "%s:rx(%d)",
2841 device_get_nameunit(dev), rxr->me);
2842 mtx_init(&rxr->rx_mtx, rxr->mtx_name, NULL, MTX_DEF);
2844 if (ixgbe_dma_malloc(adapter, rsize,
2845 &rxr->rxdma, BUS_DMA_NOWAIT)) {
2847 "Unable to allocate RxDescriptor memory\n");
2851 rxr->rx_base = (union ixgbe_adv_rx_desc *)rxr->rxdma.dma_vaddr;
2852 bzero((void *)rxr->rx_base, rsize);
2854 /* Allocate receive buffers for the ring*/
2855 if (ixgbe_allocate_receive_buffers(rxr)) {
2857 "Critical Failure setting up receive buffers\n");
2864 ** Finally set up the queue holding structs
2866 for (int i = 0; i < adapter->num_queues; i++) {
2867 que = &adapter->queues[i];
2868 que->adapter = adapter;
2869 que->txr = &adapter->tx_rings[i];
2870 que->rxr = &adapter->rx_rings[i];
2876 for (rxr = adapter->rx_rings; rxconf > 0; rxr++, rxconf--)
2877 ixgbe_dma_free(adapter, &rxr->rxdma);
2879 for (txr = adapter->tx_rings; txconf > 0; txr++, txconf--)
2880 ixgbe_dma_free(adapter, &txr->txdma);
2881 free(adapter->rx_rings, M_DEVBUF);
2883 free(adapter->tx_rings, M_DEVBUF);
2885 free(adapter->queues, M_DEVBUF);
2890 /*********************************************************************
2892 * Allocate memory for tx_buffer structures. The tx_buffer stores all
2893 * the information needed to transmit a packet on the wire. This is
2894 * called only once at attach, setup is done every reset.
2896 **********************************************************************/
2898 ixgbe_allocate_transmit_buffers(struct tx_ring *txr)
2900 struct adapter *adapter = txr->adapter;
2901 device_t dev = adapter->dev;
2902 struct ixgbe_tx_buf *txbuf;
2906 * Setup DMA descriptor areas.
2908 if ((error = bus_dma_tag_create(
2909 bus_get_dma_tag(adapter->dev), /* parent */
2910 1, 0, /* alignment, bounds */
2911 BUS_SPACE_MAXADDR, /* lowaddr */
2912 BUS_SPACE_MAXADDR, /* highaddr */
2913 NULL, NULL, /* filter, filterarg */
2914 IXGBE_TSO_SIZE, /* maxsize */
2915 adapter->num_segs, /* nsegments */
2916 PAGE_SIZE, /* maxsegsize */
2918 NULL, /* lockfunc */
2919 NULL, /* lockfuncarg */
2921 device_printf(dev,"Unable to allocate TX DMA tag\n");
2925 if (!(txr->tx_buffers =
2926 (struct ixgbe_tx_buf *) malloc(sizeof(struct ixgbe_tx_buf) *
2927 adapter->num_tx_desc, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2928 device_printf(dev, "Unable to allocate tx_buffer memory\n");
2933 /* Create the descriptor buffer dma maps */
2934 txbuf = txr->tx_buffers;
2935 for (i = 0; i < adapter->num_tx_desc; i++, txbuf++) {
2936 error = bus_dmamap_create(txr->txtag, 0, &txbuf->map);
2938 device_printf(dev, "Unable to create TX DMA map\n");
2945 /* We free all, it handles case where we are in the middle */
2946 ixgbe_free_transmit_structures(adapter);
2950 /*********************************************************************
2952 * Initialize a transmit ring.
2954 **********************************************************************/
2956 ixgbe_setup_transmit_ring(struct tx_ring *txr)
2958 struct adapter *adapter = txr->adapter;
2959 struct ixgbe_tx_buf *txbuf;
2962 struct netmap_adapter *na = NA(adapter->ifp);
2963 struct netmap_slot *slot;
2964 #endif /* DEV_NETMAP */
2966 /* Clear the old ring contents */
2970 * (under lock): if in netmap mode, do some consistency
2971 * checks and set slot to entry 0 of the netmap ring.
2973 slot = netmap_reset(na, NR_TX, txr->me, 0);
2974 #endif /* DEV_NETMAP */
2975 bzero((void *)txr->tx_base,
2976 (sizeof(union ixgbe_adv_tx_desc)) * adapter->num_tx_desc);
2978 txr->next_avail_desc = 0;
2979 txr->next_to_clean = 0;
2981 /* Free any existing tx buffers. */
2982 txbuf = txr->tx_buffers;
2983 for (i = 0; i < adapter->num_tx_desc; i++, txbuf++) {
2984 if (txbuf->m_head != NULL) {
2985 bus_dmamap_sync(txr->txtag, txbuf->map,
2986 BUS_DMASYNC_POSTWRITE);
2987 bus_dmamap_unload(txr->txtag, txbuf->map);
2988 m_freem(txbuf->m_head);
2989 txbuf->m_head = NULL;
2993 * In netmap mode, set the map for the packet buffer.
2994 * NOTE: Some drivers (not this one) also need to set
2995 * the physical buffer address in the NIC ring.
2996 * Slots in the netmap ring (indexed by "si") are
2997 * kring->nkr_hwofs positions "ahead" wrt the
2998 * corresponding slot in the NIC ring. In some drivers
2999 * (not here) nkr_hwofs can be negative. Function
3000 * netmap_idx_n2k() handles wraparounds properly.
3003 int si = netmap_idx_n2k(&na->tx_rings[txr->me], i);
3004 netmap_load_map(txr->txtag, txbuf->map, NMB(slot + si));
3006 #endif /* DEV_NETMAP */
3007 /* Clear the EOP index */
3008 txbuf->eop_index = -1;
3012 /* Set the rate at which we sample packets */
3013 if (adapter->hw.mac.type != ixgbe_mac_82598EB)
3014 txr->atr_sample = atr_sample_rate;
3017 /* Set number of descriptors available */
3018 txr->tx_avail = adapter->num_tx_desc;
3020 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
3021 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
3022 IXGBE_TX_UNLOCK(txr);
3025 /*********************************************************************
3027 * Initialize all transmit rings.
3029 **********************************************************************/
3031 ixgbe_setup_transmit_structures(struct adapter *adapter)
3033 struct tx_ring *txr = adapter->tx_rings;
3035 for (int i = 0; i < adapter->num_queues; i++, txr++)
3036 ixgbe_setup_transmit_ring(txr);
3041 /*********************************************************************
3043 * Enable transmit unit.
3045 **********************************************************************/
3047 ixgbe_initialize_transmit_units(struct adapter *adapter)
3049 struct tx_ring *txr = adapter->tx_rings;
3050 struct ixgbe_hw *hw = &adapter->hw;
3052 /* Setup the Base and Length of the Tx Descriptor Ring */
3054 for (int i = 0; i < adapter->num_queues; i++, txr++) {
3055 u64 tdba = txr->txdma.dma_paddr;
3058 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(i),
3059 (tdba & 0x00000000ffffffffULL));
3060 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(i), (tdba >> 32));
3061 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(i),
3062 adapter->num_tx_desc * sizeof(struct ixgbe_legacy_tx_desc));
3064 /* Setup the HW Tx Head and Tail descriptor pointers */
3065 IXGBE_WRITE_REG(hw, IXGBE_TDH(i), 0);
3066 IXGBE_WRITE_REG(hw, IXGBE_TDT(i), 0);
3068 /* Setup Transmit Descriptor Cmd Settings */
3069 txr->txd_cmd = IXGBE_TXD_CMD_IFCS;
3070 txr->queue_status = IXGBE_QUEUE_IDLE;
3072 /* Disable Head Writeback */
3073 switch (hw->mac.type) {
3074 case ixgbe_mac_82598EB:
3075 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i));
3077 case ixgbe_mac_82599EB:
3078 case ixgbe_mac_X540:
3080 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
3083 txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
3084 switch (hw->mac.type) {
3085 case ixgbe_mac_82598EB:
3086 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(i), txctrl);
3088 case ixgbe_mac_82599EB:
3089 case ixgbe_mac_X540:
3091 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), txctrl);
3097 if (hw->mac.type != ixgbe_mac_82598EB) {
3098 u32 dmatxctl, rttdcs;
3099 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3100 dmatxctl |= IXGBE_DMATXCTL_TE;
3101 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3102 /* Disable arbiter to set MTQC */
3103 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3104 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3105 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3106 IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
3107 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3108 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3114 /*********************************************************************
3116 * Free all transmit rings.
3118 **********************************************************************/
3120 ixgbe_free_transmit_structures(struct adapter *adapter)
3122 struct tx_ring *txr = adapter->tx_rings;
3124 for (int i = 0; i < adapter->num_queues; i++, txr++) {
3126 ixgbe_free_transmit_buffers(txr);
3127 ixgbe_dma_free(adapter, &txr->txdma);
3128 IXGBE_TX_UNLOCK(txr);
3129 IXGBE_TX_LOCK_DESTROY(txr);
3131 free(adapter->tx_rings, M_DEVBUF);
3134 /*********************************************************************
3136 * Free transmit ring related data structures.
3138 **********************************************************************/
3140 ixgbe_free_transmit_buffers(struct tx_ring *txr)
3142 struct adapter *adapter = txr->adapter;
3143 struct ixgbe_tx_buf *tx_buffer;
3146 INIT_DEBUGOUT("free_transmit_ring: begin");
3148 if (txr->tx_buffers == NULL)
3151 tx_buffer = txr->tx_buffers;
3152 for (i = 0; i < adapter->num_tx_desc; i++, tx_buffer++) {
3153 if (tx_buffer->m_head != NULL) {
3154 bus_dmamap_sync(txr->txtag, tx_buffer->map,
3155 BUS_DMASYNC_POSTWRITE);
3156 bus_dmamap_unload(txr->txtag,
3158 m_freem(tx_buffer->m_head);
3159 tx_buffer->m_head = NULL;
3160 if (tx_buffer->map != NULL) {
3161 bus_dmamap_destroy(txr->txtag,
3163 tx_buffer->map = NULL;
3165 } else if (tx_buffer->map != NULL) {
3166 bus_dmamap_unload(txr->txtag,
3168 bus_dmamap_destroy(txr->txtag,
3170 tx_buffer->map = NULL;
3173 #if __FreeBSD_version >= 800000
3174 if (txr->br != NULL)
3175 buf_ring_free(txr->br, M_DEVBUF);
3177 if (txr->tx_buffers != NULL) {
3178 free(txr->tx_buffers, M_DEVBUF);
3179 txr->tx_buffers = NULL;
3181 if (txr->txtag != NULL) {
3182 bus_dma_tag_destroy(txr->txtag);
3188 /*********************************************************************
3190 * Advanced Context Descriptor setup for VLAN or CSUM
3192 **********************************************************************/
3195 ixgbe_tx_ctx_setup(struct tx_ring *txr, struct mbuf *mp)
3197 struct adapter *adapter = txr->adapter;
3198 struct ixgbe_adv_tx_context_desc *TXD;
3199 struct ixgbe_tx_buf *tx_buffer;
3200 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
3201 struct ether_vlan_header *eh;
3203 struct ip6_hdr *ip6;
3204 int ehdrlen, ip_hlen = 0;
3207 bool offload = TRUE;
3208 int ctxd = txr->next_avail_desc;
3212 if ((mp->m_pkthdr.csum_flags & CSUM_OFFLOAD) == 0)
3215 tx_buffer = &txr->tx_buffers[ctxd];
3216 TXD = (struct ixgbe_adv_tx_context_desc *) &txr->tx_base[ctxd];
3219 ** In advanced descriptors the vlan tag must
3220 ** be placed into the descriptor itself.
3222 if (mp->m_flags & M_VLANTAG) {
3223 vtag = htole16(mp->m_pkthdr.ether_vtag);
3224 vlan_macip_lens |= (vtag << IXGBE_ADVTXD_VLAN_SHIFT);
3225 } else if (offload == FALSE)
3229 * Determine where frame payload starts.
3230 * Jump over vlan headers if already present,
3231 * helpful for QinQ too.
3233 eh = mtod(mp, struct ether_vlan_header *);
3234 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
3235 etype = ntohs(eh->evl_proto);
3236 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
3238 etype = ntohs(eh->evl_encap_proto);
3239 ehdrlen = ETHER_HDR_LEN;
3242 /* Set the ether header length */
3243 vlan_macip_lens |= ehdrlen << IXGBE_ADVTXD_MACLEN_SHIFT;
3247 ip = (struct ip *)(mp->m_data + ehdrlen);
3248 ip_hlen = ip->ip_hl << 2;
3250 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3252 case ETHERTYPE_IPV6:
3253 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen);
3254 ip_hlen = sizeof(struct ip6_hdr);
3255 ipproto = ip6->ip6_nxt;
3256 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV6;
3263 vlan_macip_lens |= ip_hlen;
3264 type_tucmd_mlhl |= IXGBE_ADVTXD_DCMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
3268 if (mp->m_pkthdr.csum_flags & CSUM_TCP)
3269 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3273 if (mp->m_pkthdr.csum_flags & CSUM_UDP)
3274 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_UDP;
3277 #if __FreeBSD_version >= 800000
3279 if (mp->m_pkthdr.csum_flags & CSUM_SCTP)
3280 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
3288 /* Now copy bits into descriptor */
3289 TXD->vlan_macip_lens |= htole32(vlan_macip_lens);
3290 TXD->type_tucmd_mlhl |= htole32(type_tucmd_mlhl);
3291 TXD->seqnum_seed = htole32(0);
3292 TXD->mss_l4len_idx = htole32(0);
3294 tx_buffer->m_head = NULL;
3295 tx_buffer->eop_index = -1;
3297 /* We've consumed the first desc, adjust counters */
3298 if (++ctxd == adapter->num_tx_desc)
3300 txr->next_avail_desc = ctxd;
3306 /**********************************************************************
3308 * Setup work for hardware segmentation offload (TSO) on
3309 * adapters using advanced tx descriptors
3311 **********************************************************************/
3313 ixgbe_tso_setup(struct tx_ring *txr, struct mbuf *mp, u32 *paylen)
3315 struct adapter *adapter = txr->adapter;
3316 struct ixgbe_adv_tx_context_desc *TXD;
3317 struct ixgbe_tx_buf *tx_buffer;
3318 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
3319 u32 mss_l4len_idx = 0;
3321 int ctxd, ehdrlen, hdrlen, ip_hlen, tcp_hlen;
3322 struct ether_vlan_header *eh;
3328 * Determine where frame payload starts.
3329 * Jump over vlan headers if already present
3331 eh = mtod(mp, struct ether_vlan_header *);
3332 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN))
3333 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
3335 ehdrlen = ETHER_HDR_LEN;
3337 /* Ensure we have at least the IP+TCP header in the first mbuf. */
3338 if (mp->m_len < ehdrlen + sizeof(struct ip) + sizeof(struct tcphdr))
3341 ctxd = txr->next_avail_desc;
3342 tx_buffer = &txr->tx_buffers[ctxd];
3343 TXD = (struct ixgbe_adv_tx_context_desc *) &txr->tx_base[ctxd];
3345 ip = (struct ip *)(mp->m_data + ehdrlen);
3346 if (ip->ip_p != IPPROTO_TCP)
3347 return FALSE; /* 0 */
3349 ip_hlen = ip->ip_hl << 2;
3350 th = (struct tcphdr *)((caddr_t)ip + ip_hlen);
3351 th->th_sum = in_pseudo(ip->ip_src.s_addr,
3352 ip->ip_dst.s_addr, htons(IPPROTO_TCP));
3353 tcp_hlen = th->th_off << 2;
3354 hdrlen = ehdrlen + ip_hlen + tcp_hlen;
3356 /* This is used in the transmit desc in encap */
3357 *paylen = mp->m_pkthdr.len - hdrlen;
3359 /* VLAN MACLEN IPLEN */
3360 if (mp->m_flags & M_VLANTAG) {
3361 vtag = htole16(mp->m_pkthdr.ether_vtag);
3362 vlan_macip_lens |= (vtag << IXGBE_ADVTXD_VLAN_SHIFT);
3365 vlan_macip_lens |= ehdrlen << IXGBE_ADVTXD_MACLEN_SHIFT;
3366 vlan_macip_lens |= ip_hlen;
3367 TXD->vlan_macip_lens |= htole32(vlan_macip_lens);
3369 /* ADV DTYPE TUCMD */
3370 type_tucmd_mlhl |= IXGBE_ADVTXD_DCMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
3371 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3372 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3373 TXD->type_tucmd_mlhl |= htole32(type_tucmd_mlhl);
3377 mss_l4len_idx |= (mp->m_pkthdr.tso_segsz << IXGBE_ADVTXD_MSS_SHIFT);
3378 mss_l4len_idx |= (tcp_hlen << IXGBE_ADVTXD_L4LEN_SHIFT);
3379 TXD->mss_l4len_idx = htole32(mss_l4len_idx);
3381 TXD->seqnum_seed = htole32(0);
3382 tx_buffer->m_head = NULL;
3383 tx_buffer->eop_index = -1;
3385 if (++ctxd == adapter->num_tx_desc)
3389 txr->next_avail_desc = ctxd;
3395 ** This routine parses packet headers so that Flow
3396 ** Director can make a hashed filter table entry
3397 ** allowing traffic flows to be identified and kept
3398 ** on the same cpu. This would be a performance
3399 ** hit, but we only do it at IXGBE_FDIR_RATE of
3403 ixgbe_atr(struct tx_ring *txr, struct mbuf *mp)
3405 struct adapter *adapter = txr->adapter;
3406 struct ix_queue *que;
3410 struct ether_vlan_header *eh;
3411 union ixgbe_atr_hash_dword input = {.dword = 0};
3412 union ixgbe_atr_hash_dword common = {.dword = 0};
3413 int ehdrlen, ip_hlen;
3416 eh = mtod(mp, struct ether_vlan_header *);
3417 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
3418 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
3419 etype = eh->evl_proto;
3421 ehdrlen = ETHER_HDR_LEN;
3422 etype = eh->evl_encap_proto;
3425 /* Only handling IPv4 */
3426 if (etype != htons(ETHERTYPE_IP))
3429 ip = (struct ip *)(mp->m_data + ehdrlen);
3430 ip_hlen = ip->ip_hl << 2;
3432 /* check if we're UDP or TCP */
3435 th = (struct tcphdr *)((caddr_t)ip + ip_hlen);
3436 /* src and dst are inverted */
3437 common.port.dst ^= th->th_sport;
3438 common.port.src ^= th->th_dport;
3439 input.formatted.flow_type ^= IXGBE_ATR_FLOW_TYPE_TCPV4;
3442 uh = (struct udphdr *)((caddr_t)ip + ip_hlen);
3443 /* src and dst are inverted */
3444 common.port.dst ^= uh->uh_sport;
3445 common.port.src ^= uh->uh_dport;
3446 input.formatted.flow_type ^= IXGBE_ATR_FLOW_TYPE_UDPV4;
3452 input.formatted.vlan_id = htobe16(mp->m_pkthdr.ether_vtag);
3453 if (mp->m_pkthdr.ether_vtag)
3454 common.flex_bytes ^= htons(ETHERTYPE_VLAN);
3456 common.flex_bytes ^= etype;
3457 common.ip ^= ip->ip_src.s_addr ^ ip->ip_dst.s_addr;
3459 que = &adapter->queues[txr->me];
3461 ** This assumes the Rx queue and Tx
3462 ** queue are bound to the same CPU
3464 ixgbe_fdir_add_signature_filter_82599(&adapter->hw,
3465 input, common, que->msix);
3467 #endif /* IXGBE_FDIR */
3469 /**********************************************************************
3471 * Examine each tx_buffer in the used queue. If the hardware is done
3472 * processing the packet then free associated resources. The
3473 * tx_buffer is put back on the free queue.
3475 **********************************************************************/
3477 ixgbe_txeof(struct tx_ring *txr)
3479 struct adapter *adapter = txr->adapter;
3480 struct ifnet *ifp = adapter->ifp;
3481 u32 first, last, done, processed;
3482 struct ixgbe_tx_buf *tx_buffer;
3483 struct ixgbe_legacy_tx_desc *tx_desc, *eop_desc;
3485 mtx_assert(&txr->tx_mtx, MA_OWNED);
3488 if (ifp->if_capenable & IFCAP_NETMAP) {
3489 struct netmap_adapter *na = NA(ifp);
3490 struct netmap_kring *kring = &na->tx_rings[txr->me];
3492 tx_desc = (struct ixgbe_legacy_tx_desc *)txr->tx_base;
3494 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
3495 BUS_DMASYNC_POSTREAD);
3497 * In netmap mode, all the work is done in the context
3498 * of the client thread. Interrupt handlers only wake up
3499 * clients, which may be sleeping on individual rings
3500 * or on a global resource for all rings.
3501 * To implement tx interrupt mitigation, we wake up the client
3502 * thread roughly every half ring, even if the NIC interrupts
3503 * more frequently. This is implemented as follows:
3504 * - ixgbe_txsync() sets kring->nr_kflags with the index of
3505 * the slot that should wake up the thread (nkr_num_slots
3506 * means the user thread should not be woken up);
3507 * - the driver ignores tx interrupts unless netmap_mitigate=0
3508 * or the slot has the DD bit set.
3510 * When the driver has separate locks, we need to
3511 * release and re-acquire txlock to avoid deadlocks.
3512 * XXX see if we can find a better way.
3514 if (!netmap_mitigate ||
3515 (kring->nr_kflags < kring->nkr_num_slots &&
3516 tx_desc[kring->nr_kflags].upper.fields.status & IXGBE_TXD_STAT_DD)) {
3517 kring->nr_kflags = kring->nkr_num_slots;
3518 selwakeuppri(&na->tx_rings[txr->me].si, PI_NET);
3519 IXGBE_TX_UNLOCK(txr);
3520 IXGBE_CORE_LOCK(adapter);
3521 selwakeuppri(&na->tx_si, PI_NET);
3522 IXGBE_CORE_UNLOCK(adapter);
3527 #endif /* DEV_NETMAP */
3529 if (txr->tx_avail == adapter->num_tx_desc) {
3530 txr->queue_status = IXGBE_QUEUE_IDLE;
3535 first = txr->next_to_clean;
3536 tx_buffer = &txr->tx_buffers[first];
3537 /* For cleanup we just use legacy struct */
3538 tx_desc = (struct ixgbe_legacy_tx_desc *)&txr->tx_base[first];
3539 last = tx_buffer->eop_index;
3542 eop_desc = (struct ixgbe_legacy_tx_desc *)&txr->tx_base[last];
3545 ** Get the index of the first descriptor
3546 ** BEYOND the EOP and call that 'done'.
3547 ** I do this so the comparison in the
3548 ** inner while loop below can be simple
3550 if (++last == adapter->num_tx_desc) last = 0;
3553 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
3554 BUS_DMASYNC_POSTREAD);
3556 ** Only the EOP descriptor of a packet now has the DD
3557 ** bit set, this is what we look for...
3559 while (eop_desc->upper.fields.status & IXGBE_TXD_STAT_DD) {
3560 /* We clean the range of the packet */
3561 while (first != done) {
3562 tx_desc->upper.data = 0;
3563 tx_desc->lower.data = 0;
3564 tx_desc->buffer_addr = 0;
3568 if (tx_buffer->m_head) {
3570 tx_buffer->m_head->m_pkthdr.len;
3571 bus_dmamap_sync(txr->txtag,
3573 BUS_DMASYNC_POSTWRITE);
3574 bus_dmamap_unload(txr->txtag,
3576 m_freem(tx_buffer->m_head);
3577 tx_buffer->m_head = NULL;
3578 tx_buffer->map = NULL;
3580 tx_buffer->eop_index = -1;
3581 txr->watchdog_time = ticks;
3583 if (++first == adapter->num_tx_desc)
3586 tx_buffer = &txr->tx_buffers[first];
3588 (struct ixgbe_legacy_tx_desc *)&txr->tx_base[first];
3592 /* See if there is more work now */
3593 last = tx_buffer->eop_index;
3596 (struct ixgbe_legacy_tx_desc *)&txr->tx_base[last];
3597 /* Get next done point */
3598 if (++last == adapter->num_tx_desc) last = 0;
3603 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
3604 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
3606 txr->next_to_clean = first;
3609 ** Watchdog calculation, we know there's
3610 ** work outstanding or the first return
3611 ** would have been taken, so none processed
3612 ** for too long indicates a hang.
3614 if ((!processed) && ((ticks - txr->watchdog_time) > IXGBE_WATCHDOG))
3615 txr->queue_status = IXGBE_QUEUE_HUNG;
3617 /* With a minimum free clear the depleted state bit. */
3618 if (txr->tx_avail > IXGBE_TX_CLEANUP_THRESHOLD)
3619 txr->queue_status &= ~IXGBE_QUEUE_DEPLETED;
3621 if (txr->tx_avail == adapter->num_tx_desc) {
3622 txr->queue_status = IXGBE_QUEUE_IDLE;
3629 /*********************************************************************
3631 * Refresh mbuf buffers for RX descriptor rings
3632 * - now keeps its own state so discards due to resource
3633 * exhaustion are unnecessary, if an mbuf cannot be obtained
3634 * it just returns, keeping its placeholder, thus it can simply
3635 * be recalled to try again.
3637 **********************************************************************/
3639 ixgbe_refresh_mbufs(struct rx_ring *rxr, int limit)
3641 struct adapter *adapter = rxr->adapter;
3642 bus_dma_segment_t hseg[1];
3643 bus_dma_segment_t pseg[1];
3644 struct ixgbe_rx_buf *rxbuf;
3645 struct mbuf *mh, *mp;
3646 int i, j, nsegs, error;
3647 bool refreshed = FALSE;
3649 i = j = rxr->next_to_refresh;
3650 /* Control the loop with one beyond */
3651 if (++j == adapter->num_rx_desc)
3654 while (j != limit) {
3655 rxbuf = &rxr->rx_buffers[i];
3656 if (rxr->hdr_split == FALSE)
3659 if (rxbuf->m_head == NULL) {
3660 mh = m_gethdr(M_DONTWAIT, MT_DATA);
3666 mh->m_pkthdr.len = mh->m_len = MHLEN;
3668 mh->m_flags |= M_PKTHDR;
3669 /* Get the memory mapping */
3670 error = bus_dmamap_load_mbuf_sg(rxr->htag,
3671 rxbuf->hmap, mh, hseg, &nsegs, BUS_DMA_NOWAIT);
3673 printf("Refresh mbufs: hdr dmamap load"
3674 " failure - %d\n", error);
3676 rxbuf->m_head = NULL;
3680 bus_dmamap_sync(rxr->htag, rxbuf->hmap,
3681 BUS_DMASYNC_PREREAD);
3682 rxr->rx_base[i].read.hdr_addr =
3683 htole64(hseg[0].ds_addr);
3686 if (rxbuf->m_pack == NULL) {
3687 mp = m_getjcl(M_DONTWAIT, MT_DATA,
3688 M_PKTHDR, adapter->rx_mbuf_sz);
3694 mp->m_pkthdr.len = mp->m_len = adapter->rx_mbuf_sz;
3696 /* If we're dealing with an mbuf that was copied rather
3697 * than replaced, there's no need to go through busdma.
3699 if ((rxbuf->flags & IXGBE_RX_COPY) == 0) {
3700 /* Get the memory mapping */
3701 error = bus_dmamap_load_mbuf_sg(rxr->ptag,
3702 rxbuf->pmap, mp, pseg, &nsegs, BUS_DMA_NOWAIT);
3704 printf("Refresh mbufs: payload dmamap load"
3705 " failure - %d\n", error);
3707 rxbuf->m_pack = NULL;
3711 bus_dmamap_sync(rxr->ptag, rxbuf->pmap,
3712 BUS_DMASYNC_PREREAD);
3713 rxbuf->paddr = rxr->rx_base[i].read.pkt_addr =
3714 htole64(pseg[0].ds_addr);
3716 rxr->rx_base[i].read.pkt_addr = rxbuf->paddr;
3717 rxbuf->flags &= ~IXGBE_RX_COPY;
3721 /* Next is precalculated */
3723 rxr->next_to_refresh = i;
3724 if (++j == adapter->num_rx_desc)
3728 if (refreshed) /* Update hardware tail index */
3729 IXGBE_WRITE_REG(&adapter->hw,
3730 IXGBE_RDT(rxr->me), rxr->next_to_refresh);
3734 /*********************************************************************
3736 * Allocate memory for rx_buffer structures. Since we use one
3737 * rx_buffer per received packet, the maximum number of rx_buffer's
3738 * that we'll need is equal to the number of receive descriptors
3739 * that we've allocated.
3741 **********************************************************************/
3743 ixgbe_allocate_receive_buffers(struct rx_ring *rxr)
3745 struct adapter *adapter = rxr->adapter;
3746 device_t dev = adapter->dev;
3747 struct ixgbe_rx_buf *rxbuf;
3748 int i, bsize, error;
3750 bsize = sizeof(struct ixgbe_rx_buf) * adapter->num_rx_desc;
3751 if (!(rxr->rx_buffers =
3752 (struct ixgbe_rx_buf *) malloc(bsize,
3753 M_DEVBUF, M_NOWAIT | M_ZERO))) {
3754 device_printf(dev, "Unable to allocate rx_buffer memory\n");
3759 if ((error = bus_dma_tag_create(bus_get_dma_tag(dev), /* parent */
3760 1, 0, /* alignment, bounds */
3761 BUS_SPACE_MAXADDR, /* lowaddr */
3762 BUS_SPACE_MAXADDR, /* highaddr */
3763 NULL, NULL, /* filter, filterarg */
3764 MSIZE, /* maxsize */
3766 MSIZE, /* maxsegsize */
3768 NULL, /* lockfunc */
3769 NULL, /* lockfuncarg */
3771 device_printf(dev, "Unable to create RX DMA tag\n");
3775 if ((error = bus_dma_tag_create(bus_get_dma_tag(dev), /* parent */
3776 1, 0, /* alignment, bounds */
3777 BUS_SPACE_MAXADDR, /* lowaddr */
3778 BUS_SPACE_MAXADDR, /* highaddr */
3779 NULL, NULL, /* filter, filterarg */
3780 MJUM16BYTES, /* maxsize */
3782 MJUM16BYTES, /* maxsegsize */
3784 NULL, /* lockfunc */
3785 NULL, /* lockfuncarg */
3787 device_printf(dev, "Unable to create RX DMA tag\n");
3791 for (i = 0; i < adapter->num_rx_desc; i++, rxbuf++) {
3792 rxbuf = &rxr->rx_buffers[i];
3793 error = bus_dmamap_create(rxr->htag,
3794 BUS_DMA_NOWAIT, &rxbuf->hmap);
3796 device_printf(dev, "Unable to create RX head map\n");
3799 error = bus_dmamap_create(rxr->ptag,
3800 BUS_DMA_NOWAIT, &rxbuf->pmap);
3802 device_printf(dev, "Unable to create RX pkt map\n");
3810 /* Frees all, but can handle partial completion */
3811 ixgbe_free_receive_structures(adapter);
3816 ** Used to detect a descriptor that has
3817 ** been merged by Hardware RSC.
3820 ixgbe_rsc_count(union ixgbe_adv_rx_desc *rx)
3822 return (le32toh(rx->wb.lower.lo_dword.data) &
3823 IXGBE_RXDADV_RSCCNT_MASK) >> IXGBE_RXDADV_RSCCNT_SHIFT;
3826 /*********************************************************************
3828 * Initialize Hardware RSC (LRO) feature on 82599
3829 * for an RX ring, this is toggled by the LRO capability
3830 * even though it is transparent to the stack.
3832 **********************************************************************/
3834 ixgbe_setup_hw_rsc(struct rx_ring *rxr)
3836 struct adapter *adapter = rxr->adapter;
3837 struct ixgbe_hw *hw = &adapter->hw;
3838 u32 rscctrl, rdrxctl;
3840 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3841 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3842 #ifdef DEV_NETMAP /* crcstrip is optional in netmap */
3843 if (adapter->ifp->if_capenable & IFCAP_NETMAP && !ix_crcstrip)
3844 #endif /* DEV_NETMAP */
3845 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3846 rdrxctl |= IXGBE_RDRXCTL_RSCACKC;
3847 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3849 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(rxr->me));
3850 rscctrl |= IXGBE_RSCCTL_RSCEN;
3852 ** Limit the total number of descriptors that
3853 ** can be combined, so it does not exceed 64K
3855 if (adapter->rx_mbuf_sz == MCLBYTES)
3856 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
3857 else if (adapter->rx_mbuf_sz == MJUMPAGESIZE)
3858 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
3859 else if (adapter->rx_mbuf_sz == MJUM9BYTES)
3860 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
3861 else /* Using 16K cluster */
3862 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
3864 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(rxr->me), rscctrl);
3866 /* Enable TCP header recognition */
3867 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0),
3868 (IXGBE_READ_REG(hw, IXGBE_PSRTYPE(0)) |
3869 IXGBE_PSRTYPE_TCPHDR));
3871 /* Disable RSC for ACK packets */
3872 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3873 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3880 ixgbe_free_receive_ring(struct rx_ring *rxr)
3882 struct adapter *adapter;
3883 struct ixgbe_rx_buf *rxbuf;
3886 adapter = rxr->adapter;
3887 for (i = 0; i < adapter->num_rx_desc; i++) {
3888 rxbuf = &rxr->rx_buffers[i];
3889 if (rxbuf->m_head != NULL) {
3890 bus_dmamap_sync(rxr->htag, rxbuf->hmap,
3891 BUS_DMASYNC_POSTREAD);
3892 bus_dmamap_unload(rxr->htag, rxbuf->hmap);
3893 rxbuf->m_head->m_flags |= M_PKTHDR;
3894 m_freem(rxbuf->m_head);
3896 if (rxbuf->m_pack != NULL) {
3897 bus_dmamap_sync(rxr->ptag, rxbuf->pmap,
3898 BUS_DMASYNC_POSTREAD);
3899 bus_dmamap_unload(rxr->ptag, rxbuf->pmap);
3900 rxbuf->m_pack->m_flags |= M_PKTHDR;
3901 m_freem(rxbuf->m_pack);
3903 rxbuf->m_head = NULL;
3904 rxbuf->m_pack = NULL;
3909 /*********************************************************************
3911 * Initialize a receive ring and its buffers.
3913 **********************************************************************/
3915 ixgbe_setup_receive_ring(struct rx_ring *rxr)
3917 struct adapter *adapter;
3920 struct ixgbe_rx_buf *rxbuf;
3921 bus_dma_segment_t pseg[1], hseg[1];
3922 struct lro_ctrl *lro = &rxr->lro;
3923 int rsize, nsegs, error = 0;
3925 struct netmap_adapter *na = NA(rxr->adapter->ifp);
3926 struct netmap_slot *slot;
3927 #endif /* DEV_NETMAP */
3929 adapter = rxr->adapter;
3933 /* Clear the ring contents */
3936 /* same as in ixgbe_setup_transmit_ring() */
3937 slot = netmap_reset(na, NR_RX, rxr->me, 0);
3938 #endif /* DEV_NETMAP */
3939 rsize = roundup2(adapter->num_rx_desc *
3940 sizeof(union ixgbe_adv_rx_desc), DBA_ALIGN);
3941 bzero((void *)rxr->rx_base, rsize);
3943 /* Free current RX buffer structs and their mbufs */
3944 ixgbe_free_receive_ring(rxr);
3946 /* Configure header split? */
3947 if (ixgbe_header_split)
3948 rxr->hdr_split = TRUE;
3950 /* Now replenish the mbufs */
3951 for (int j = 0; j != adapter->num_rx_desc; ++j) {
3952 struct mbuf *mh, *mp;
3954 rxbuf = &rxr->rx_buffers[j];
3957 * In netmap mode, fill the map and set the buffer
3958 * address in the NIC ring, considering the offset
3959 * between the netmap and NIC rings (see comment in
3960 * ixgbe_setup_transmit_ring() ). No need to allocate
3961 * an mbuf, so end the block with a continue;
3964 int sj = netmap_idx_n2k(&na->rx_rings[rxr->me], j);
3968 addr = PNMB(slot + sj, &paddr);
3969 netmap_load_map(rxr->ptag, rxbuf->pmap, addr);
3970 /* Update descriptor */
3971 rxr->rx_base[j].read.pkt_addr = htole64(paddr);
3974 #endif /* DEV_NETMAP */
3976 ** Don't allocate mbufs if not
3977 ** doing header split, its wasteful
3979 if (rxr->hdr_split == FALSE)
3982 /* First the header */
3983 rxbuf->m_head = m_gethdr(M_NOWAIT, MT_DATA);
3984 if (rxbuf->m_head == NULL) {
3988 m_adj(rxbuf->m_head, ETHER_ALIGN);
3990 mh->m_len = mh->m_pkthdr.len = MHLEN;
3991 mh->m_flags |= M_PKTHDR;
3992 /* Get the memory mapping */
3993 error = bus_dmamap_load_mbuf_sg(rxr->htag,
3994 rxbuf->hmap, rxbuf->m_head, hseg,
3995 &nsegs, BUS_DMA_NOWAIT);
3996 if (error != 0) /* Nothing elegant to do here */
3998 bus_dmamap_sync(rxr->htag,
3999 rxbuf->hmap, BUS_DMASYNC_PREREAD);
4000 /* Update descriptor */
4001 rxr->rx_base[j].read.hdr_addr = htole64(hseg[0].ds_addr);
4004 /* Now the payload cluster */
4005 rxbuf->m_pack = m_getjcl(M_NOWAIT, MT_DATA,
4006 M_PKTHDR, adapter->rx_mbuf_sz);
4007 if (rxbuf->m_pack == NULL) {
4012 mp->m_pkthdr.len = mp->m_len = adapter->rx_mbuf_sz;
4013 /* Get the memory mapping */
4014 error = bus_dmamap_load_mbuf_sg(rxr->ptag,
4015 rxbuf->pmap, mp, pseg,
4016 &nsegs, BUS_DMA_NOWAIT);
4019 bus_dmamap_sync(rxr->ptag,
4020 rxbuf->pmap, BUS_DMASYNC_PREREAD);
4021 /* Update descriptor */
4022 rxr->rx_base[j].read.pkt_addr = htole64(pseg[0].ds_addr);
4026 /* Setup our descriptor indices */
4027 rxr->next_to_check = 0;
4028 rxr->next_to_refresh = 0;
4029 rxr->lro_enabled = FALSE;
4030 rxr->rx_split_packets = 0;
4033 rxr->discard = FALSE;
4034 rxr->vtag_strip = FALSE;
4036 bus_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
4037 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
4040 ** Now set up the LRO interface:
4041 ** 82598 uses software LRO, the
4042 ** 82599 and X540 use a hardware assist.
4044 if ((adapter->hw.mac.type != ixgbe_mac_82598EB) &&
4045 (ifp->if_capenable & IFCAP_RXCSUM) &&
4046 (ifp->if_capenable & IFCAP_LRO))
4047 ixgbe_setup_hw_rsc(rxr);
4048 else if (ifp->if_capenable & IFCAP_LRO) {
4049 int err = tcp_lro_init(lro);
4051 device_printf(dev, "LRO Initialization failed!\n");
4054 INIT_DEBUGOUT("RX Soft LRO Initialized\n");
4055 rxr->lro_enabled = TRUE;
4056 lro->ifp = adapter->ifp;
4059 IXGBE_RX_UNLOCK(rxr);
4063 ixgbe_free_receive_ring(rxr);
4064 IXGBE_RX_UNLOCK(rxr);
4068 /*********************************************************************
4070 * Initialize all receive rings.
4072 **********************************************************************/
4074 ixgbe_setup_receive_structures(struct adapter *adapter)
4076 struct rx_ring *rxr = adapter->rx_rings;
4079 for (j = 0; j < adapter->num_queues; j++, rxr++)
4080 if (ixgbe_setup_receive_ring(rxr))
4086 * Free RX buffers allocated so far, we will only handle
4087 * the rings that completed, the failing case will have
4088 * cleaned up for itself. 'j' failed, so its the terminus.
4090 for (int i = 0; i < j; ++i) {
4091 rxr = &adapter->rx_rings[i];
4092 ixgbe_free_receive_ring(rxr);
4098 /*********************************************************************
4100 * Setup receive registers and features.
4102 **********************************************************************/
4103 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
4105 #define BSIZEPKT_ROUNDUP ((1<<IXGBE_SRRCTL_BSIZEPKT_SHIFT)-1)
4108 ixgbe_initialize_receive_units(struct adapter *adapter)
4110 struct rx_ring *rxr = adapter->rx_rings;
4111 struct ixgbe_hw *hw = &adapter->hw;
4112 struct ifnet *ifp = adapter->ifp;
4113 u32 bufsz, rxctrl, fctrl, srrctl, rxcsum;
4114 u32 reta, mrqc = 0, hlreg, random[10];
4118 * Make sure receives are disabled while
4119 * setting up the descriptor ring
4121 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4122 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL,
4123 rxctrl & ~IXGBE_RXCTRL_RXEN);
4125 /* Enable broadcasts */
4126 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4127 fctrl |= IXGBE_FCTRL_BAM;
4128 fctrl |= IXGBE_FCTRL_DPF;
4129 fctrl |= IXGBE_FCTRL_PMCF;
4130 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4132 /* Set for Jumbo Frames? */
4133 hlreg = IXGBE_READ_REG(hw, IXGBE_HLREG0);
4134 if (ifp->if_mtu > ETHERMTU)
4135 hlreg |= IXGBE_HLREG0_JUMBOEN;
4137 hlreg &= ~IXGBE_HLREG0_JUMBOEN;
4139 /* crcstrip is conditional in netmap (in RDRXCTL too ?) */
4140 if (ifp->if_capenable & IFCAP_NETMAP && !ix_crcstrip)
4141 hlreg &= ~IXGBE_HLREG0_RXCRCSTRP;
4143 hlreg |= IXGBE_HLREG0_RXCRCSTRP;
4144 #endif /* DEV_NETMAP */
4145 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg);
4147 bufsz = (adapter->rx_mbuf_sz +
4148 BSIZEPKT_ROUNDUP) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
4150 for (int i = 0; i < adapter->num_queues; i++, rxr++) {
4151 u64 rdba = rxr->rxdma.dma_paddr;
4153 /* Setup the Base and Length of the Rx Descriptor Ring */
4154 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(i),
4155 (rdba & 0x00000000ffffffffULL));
4156 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(i), (rdba >> 32));
4157 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(i),
4158 adapter->num_rx_desc * sizeof(union ixgbe_adv_rx_desc));
4160 /* Set up the SRRCTL register */
4161 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
4162 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
4163 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
4165 if (rxr->hdr_split) {
4166 /* Use a standard mbuf for the header */
4167 srrctl |= ((IXGBE_RX_HDR <<
4168 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT)
4169 & IXGBE_SRRCTL_BSIZEHDR_MASK);
4170 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
4172 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
4173 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(i), srrctl);
4175 /* Setup the HW Rx Head and Tail Descriptor Pointers */
4176 IXGBE_WRITE_REG(hw, IXGBE_RDH(i), 0);
4177 IXGBE_WRITE_REG(hw, IXGBE_RDT(i), 0);
4180 if (adapter->hw.mac.type != ixgbe_mac_82598EB) {
4181 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
4182 IXGBE_PSRTYPE_UDPHDR |
4183 IXGBE_PSRTYPE_IPV4HDR |
4184 IXGBE_PSRTYPE_IPV6HDR;
4185 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
4188 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
4191 if (adapter->num_queues > 1) {
4195 /* set up random bits */
4196 arc4rand(&random, sizeof(random), 0);
4198 /* Set up the redirection table */
4199 for (i = 0, j = 0; i < 128; i++, j++) {
4200 if (j == adapter->num_queues) j = 0;
4201 reta = (reta << 8) | (j * 0x11);
4203 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
4206 /* Now fill our hash function seeds */
4207 for (int i = 0; i < 10; i++)
4208 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), random[i]);
4210 /* Perform hash on these packet types */
4211 mrqc = IXGBE_MRQC_RSSEN
4212 | IXGBE_MRQC_RSS_FIELD_IPV4
4213 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
4214 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
4215 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP
4216 | IXGBE_MRQC_RSS_FIELD_IPV6_EX
4217 | IXGBE_MRQC_RSS_FIELD_IPV6
4218 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
4219 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP
4220 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP;
4221 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
4223 /* RSS and RX IPP Checksum are mutually exclusive */
4224 rxcsum |= IXGBE_RXCSUM_PCSD;
4227 if (ifp->if_capenable & IFCAP_RXCSUM)
4228 rxcsum |= IXGBE_RXCSUM_PCSD;
4230 if (!(rxcsum & IXGBE_RXCSUM_PCSD))
4231 rxcsum |= IXGBE_RXCSUM_IPPCSE;
4233 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
4238 /*********************************************************************
4240 * Free all receive rings.
4242 **********************************************************************/
4244 ixgbe_free_receive_structures(struct adapter *adapter)
4246 struct rx_ring *rxr = adapter->rx_rings;
4248 for (int i = 0; i < adapter->num_queues; i++, rxr++) {
4249 struct lro_ctrl *lro = &rxr->lro;
4250 ixgbe_free_receive_buffers(rxr);
4251 /* Free LRO memory */
4253 /* Free the ring memory as well */
4254 ixgbe_dma_free(adapter, &rxr->rxdma);
4257 free(adapter->rx_rings, M_DEVBUF);
4261 /*********************************************************************
4263 * Free receive ring data structures
4265 **********************************************************************/
4267 ixgbe_free_receive_buffers(struct rx_ring *rxr)
4269 struct adapter *adapter = rxr->adapter;
4270 struct ixgbe_rx_buf *rxbuf;
4272 INIT_DEBUGOUT("free_receive_structures: begin");
4274 /* Cleanup any existing buffers */
4275 if (rxr->rx_buffers != NULL) {
4276 for (int i = 0; i < adapter->num_rx_desc; i++) {
4277 rxbuf = &rxr->rx_buffers[i];
4278 if (rxbuf->m_head != NULL) {
4279 bus_dmamap_sync(rxr->htag, rxbuf->hmap,
4280 BUS_DMASYNC_POSTREAD);
4281 bus_dmamap_unload(rxr->htag, rxbuf->hmap);
4282 rxbuf->m_head->m_flags |= M_PKTHDR;
4283 m_freem(rxbuf->m_head);
4285 if (rxbuf->m_pack != NULL) {
4286 bus_dmamap_sync(rxr->ptag, rxbuf->pmap,
4287 BUS_DMASYNC_POSTREAD);
4288 bus_dmamap_unload(rxr->ptag, rxbuf->pmap);
4289 rxbuf->m_pack->m_flags |= M_PKTHDR;
4290 m_freem(rxbuf->m_pack);
4292 rxbuf->m_head = NULL;
4293 rxbuf->m_pack = NULL;
4294 if (rxbuf->hmap != NULL) {
4295 bus_dmamap_destroy(rxr->htag, rxbuf->hmap);
4298 if (rxbuf->pmap != NULL) {
4299 bus_dmamap_destroy(rxr->ptag, rxbuf->pmap);
4303 if (rxr->rx_buffers != NULL) {
4304 free(rxr->rx_buffers, M_DEVBUF);
4305 rxr->rx_buffers = NULL;
4309 if (rxr->htag != NULL) {
4310 bus_dma_tag_destroy(rxr->htag);
4313 if (rxr->ptag != NULL) {
4314 bus_dma_tag_destroy(rxr->ptag);
4321 static __inline void
4322 ixgbe_rx_input(struct rx_ring *rxr, struct ifnet *ifp, struct mbuf *m, u32 ptype)
4326 * ATM LRO is only for IPv4/TCP packets and TCP checksum of the packet
4327 * should be computed by hardware. Also it should not have VLAN tag in
4330 if (rxr->lro_enabled &&
4331 (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) != 0 &&
4332 (ptype & IXGBE_RXDADV_PKTTYPE_ETQF) == 0 &&
4333 (ptype & (IXGBE_RXDADV_PKTTYPE_IPV4 | IXGBE_RXDADV_PKTTYPE_TCP)) ==
4334 (IXGBE_RXDADV_PKTTYPE_IPV4 | IXGBE_RXDADV_PKTTYPE_TCP) &&
4335 (m->m_pkthdr.csum_flags & (CSUM_DATA_VALID | CSUM_PSEUDO_HDR)) ==
4336 (CSUM_DATA_VALID | CSUM_PSEUDO_HDR)) {
4338 * Send to the stack if:
4339 ** - LRO not enabled, or
4340 ** - no LRO resources, or
4341 ** - lro enqueue fails
4343 if (rxr->lro.lro_cnt != 0)
4344 if (tcp_lro_rx(&rxr->lro, m, 0) == 0)
4347 IXGBE_RX_UNLOCK(rxr);
4348 (*ifp->if_input)(ifp, m);
4352 static __inline void
4353 ixgbe_rx_discard(struct rx_ring *rxr, int i)
4355 struct ixgbe_rx_buf *rbuf;
4357 rbuf = &rxr->rx_buffers[i];
4359 if (rbuf->fmp != NULL) {/* Partial chain ? */
4360 rbuf->fmp->m_flags |= M_PKTHDR;
4366 ** With advanced descriptors the writeback
4367 ** clobbers the buffer addrs, so its easier
4368 ** to just free the existing mbufs and take
4369 ** the normal refresh path to get new buffers
4373 m_free(rbuf->m_head);
4374 rbuf->m_head = NULL;
4378 m_free(rbuf->m_pack);
4379 rbuf->m_pack = NULL;
4386 /*********************************************************************
4388 * This routine executes in interrupt context. It replenishes
4389 * the mbufs in the descriptor and sends data which has been
4390 * dma'ed into host memory to upper layer.
4392 * We loop at most count times if count is > 0, or until done if
4395 * Return TRUE for more work, FALSE for all clean.
4396 *********************************************************************/
4398 ixgbe_rxeof(struct ix_queue *que, int count)
4400 struct adapter *adapter = que->adapter;
4401 struct rx_ring *rxr = que->rxr;
4402 struct ifnet *ifp = adapter->ifp;
4403 struct lro_ctrl *lro = &rxr->lro;
4404 struct lro_entry *queued;
4405 int i, nextp, processed = 0;
4407 union ixgbe_adv_rx_desc *cur;
4408 struct ixgbe_rx_buf *rbuf, *nbuf;
4413 if (ifp->if_capenable & IFCAP_NETMAP) {
4415 * Same as the txeof routine: only wakeup clients on intr.
4416 * NKR_PENDINTR in nr_kflags is used to implement interrupt
4417 * mitigation (ixgbe_rxsync() will not look for new packets
4418 * unless NKR_PENDINTR is set).
4420 struct netmap_adapter *na = NA(ifp);
4422 na->rx_rings[rxr->me].nr_kflags |= NKR_PENDINTR;
4423 selwakeuppri(&na->rx_rings[rxr->me].si, PI_NET);
4424 IXGBE_RX_UNLOCK(rxr);
4425 IXGBE_CORE_LOCK(adapter);
4426 selwakeuppri(&na->rx_si, PI_NET);
4427 IXGBE_CORE_UNLOCK(adapter);
4430 #endif /* DEV_NETMAP */
4431 for (i = rxr->next_to_check; count != 0;) {
4432 struct mbuf *sendmp, *mh, *mp;
4434 u16 hlen, plen, hdr;
4438 /* Sync the ring. */
4439 bus_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
4440 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
4442 cur = &rxr->rx_base[i];
4443 staterr = le32toh(cur->wb.upper.status_error);
4445 if ((staterr & IXGBE_RXD_STAT_DD) == 0)
4447 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
4454 cur->wb.upper.status_error = 0;
4455 rbuf = &rxr->rx_buffers[i];
4459 plen = le16toh(cur->wb.upper.length);
4460 ptype = le32toh(cur->wb.lower.lo_dword.data) &
4461 IXGBE_RXDADV_PKTTYPE_MASK;
4462 hdr = le16toh(cur->wb.lower.lo_dword.hs_rss.hdr_info);
4463 eop = ((staterr & IXGBE_RXD_STAT_EOP) != 0);
4465 /* Process vlan info */
4466 if ((rxr->vtag_strip) && (staterr & IXGBE_RXD_STAT_VP))
4467 vtag = le16toh(cur->wb.upper.vlan);
4469 /* Make sure bad packets are discarded */
4470 if (((staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) != 0) ||
4473 rxr->rx_discarded++;
4475 rxr->discard = FALSE;
4477 rxr->discard = TRUE;
4478 ixgbe_rx_discard(rxr, i);
4483 ** On 82599 which supports a hardware
4484 ** LRO (called HW RSC), packets need
4485 ** not be fragmented across sequential
4486 ** descriptors, rather the next descriptor
4487 ** is indicated in bits of the descriptor.
4488 ** This also means that we might proceses
4489 ** more than one packet at a time, something
4490 ** that has never been true before, it
4491 ** required eliminating global chain pointers
4492 ** in favor of what we are doing here. -jfv
4496 ** Figure out the next descriptor
4499 if (rxr->hw_rsc == TRUE) {
4500 rsc = ixgbe_rsc_count(cur);
4501 rxr->rsc_num += (rsc - 1);
4503 if (rsc) { /* Get hardware index */
4505 IXGBE_RXDADV_NEXTP_MASK) >>
4506 IXGBE_RXDADV_NEXTP_SHIFT);
4507 } else { /* Just sequential */
4509 if (nextp == adapter->num_rx_desc)
4512 nbuf = &rxr->rx_buffers[nextp];
4516 ** The header mbuf is ONLY used when header
4517 ** split is enabled, otherwise we get normal
4518 ** behavior, ie, both header and payload
4519 ** are DMA'd into the payload buffer.
4521 ** Rather than using the fmp/lmp global pointers
4522 ** we now keep the head of a packet chain in the
4523 ** buffer struct and pass this along from one
4524 ** descriptor to the next, until we get EOP.
4526 if (rxr->hdr_split && (rbuf->fmp == NULL)) {
4527 /* This must be an initial descriptor */
4528 hlen = (hdr & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
4529 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
4530 if (hlen > IXGBE_RX_HDR)
4531 hlen = IXGBE_RX_HDR;
4533 mh->m_flags |= M_PKTHDR;
4535 mh->m_pkthdr.len = mh->m_len;
4536 /* Null buf pointer so it is refreshed */
4537 rbuf->m_head = NULL;
4539 ** Check the payload length, this
4540 ** could be zero if its a small
4546 mp->m_flags &= ~M_PKTHDR;
4548 mh->m_pkthdr.len += mp->m_len;
4549 /* Null buf pointer so it is refreshed */
4550 rbuf->m_pack = NULL;
4551 rxr->rx_split_packets++;
4554 ** Now create the forward
4555 ** chain so when complete
4559 /* stash the chain head */
4561 /* Make forward chain */
4563 mp->m_next = nbuf->m_pack;
4565 mh->m_next = nbuf->m_pack;
4567 /* Singlet, prepare to send */
4569 /* If hardware handled vtag */
4571 sendmp->m_pkthdr.ether_vtag = vtag;
4572 sendmp->m_flags |= M_VLANTAG;
4577 ** Either no header split, or a
4578 ** secondary piece of a fragmented
4583 ** See if there is a stored head
4584 ** that determines what we are
4588 if (sendmp != NULL) { /* secondary frag */
4589 rbuf->m_pack = rbuf->fmp = NULL;
4590 mp->m_flags &= ~M_PKTHDR;
4591 sendmp->m_pkthdr.len += mp->m_len;
4594 * Optimize. This might be a small packet,
4595 * maybe just a TCP ACK. Do a fast copy that
4596 * is cache aligned into a new mbuf, and
4597 * leave the old mbuf+cluster for re-use.
4599 if (eop && plen <= IXGBE_RX_COPY_LEN) {
4600 sendmp = m_gethdr(M_DONTWAIT, MT_DATA);
4601 if (sendmp != NULL) {
4603 IXGBE_RX_COPY_ALIGN;
4604 ixgbe_bcopy(mp->m_data,
4605 sendmp->m_data, plen);
4606 sendmp->m_len = plen;
4608 rbuf->flags |= IXGBE_RX_COPY;
4611 if (sendmp == NULL) {
4612 rbuf->m_pack = rbuf->fmp = NULL;
4616 /* first desc of a non-ps chain */
4617 sendmp->m_flags |= M_PKTHDR;
4618 sendmp->m_pkthdr.len = mp->m_len;
4619 if (staterr & IXGBE_RXD_STAT_VP) {
4620 sendmp->m_pkthdr.ether_vtag = vtag;
4621 sendmp->m_flags |= M_VLANTAG;
4624 /* Pass the head pointer on */
4628 mp->m_next = nbuf->m_pack;
4632 /* Sending this frame? */
4634 sendmp->m_pkthdr.rcvif = ifp;
4637 /* capture data for AIM */
4638 rxr->bytes += sendmp->m_pkthdr.len;
4639 rxr->rx_bytes += sendmp->m_pkthdr.len;
4640 if ((ifp->if_capenable & IFCAP_RXCSUM) != 0)
4641 ixgbe_rx_checksum(staterr, sendmp, ptype);
4642 #if __FreeBSD_version >= 800000
4643 sendmp->m_pkthdr.flowid = que->msix;
4644 sendmp->m_flags |= M_FLOWID;
4648 bus_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
4649 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
4651 /* Advance our pointers to the next descriptor. */
4652 if (++i == adapter->num_rx_desc)
4655 /* Now send to the stack or do LRO */
4656 if (sendmp != NULL) {
4657 rxr->next_to_check = i;
4658 ixgbe_rx_input(rxr, ifp, sendmp, ptype);
4659 i = rxr->next_to_check;
4662 /* Every 8 descriptors we go to refresh mbufs */
4663 if (processed == 8) {
4664 ixgbe_refresh_mbufs(rxr, i);
4669 /* Refresh any remaining buf structs */
4670 if (ixgbe_rx_unrefreshed(rxr))
4671 ixgbe_refresh_mbufs(rxr, i);
4673 rxr->next_to_check = i;
4676 * Flush any outstanding LRO work
4678 while ((queued = SLIST_FIRST(&lro->lro_active)) != NULL) {
4679 SLIST_REMOVE_HEAD(&lro->lro_active, next);
4680 tcp_lro_flush(lro, queued);
4683 IXGBE_RX_UNLOCK(rxr);
4686 ** We still have cleaning to do?
4687 ** Schedule another interrupt if so.
4689 if ((staterr & IXGBE_RXD_STAT_DD) != 0) {
4690 ixgbe_rearm_queues(adapter, (u64)(1 << que->msix));
4698 /*********************************************************************
4700 * Verify that the hardware indicated that the checksum is valid.
4701 * Inform the stack about the status of checksum so that stack
4702 * doesn't spend time verifying the checksum.
4704 *********************************************************************/
4706 ixgbe_rx_checksum(u32 staterr, struct mbuf * mp, u32 ptype)
4708 u16 status = (u16) staterr;
4709 u8 errors = (u8) (staterr >> 24);
4712 if ((ptype & IXGBE_RXDADV_PKTTYPE_ETQF) == 0 &&
4713 (ptype & IXGBE_RXDADV_PKTTYPE_SCTP) != 0)
4716 if (status & IXGBE_RXD_STAT_IPCS) {
4717 if (!(errors & IXGBE_RXD_ERR_IPE)) {
4718 /* IP Checksum Good */
4719 mp->m_pkthdr.csum_flags = CSUM_IP_CHECKED;
4720 mp->m_pkthdr.csum_flags |= CSUM_IP_VALID;
4723 mp->m_pkthdr.csum_flags = 0;
4725 if (status & IXGBE_RXD_STAT_L4CS) {
4726 u16 type = (CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
4727 #if __FreeBSD_version >= 800000
4729 type = CSUM_SCTP_VALID;
4731 if (!(errors & IXGBE_RXD_ERR_TCPE)) {
4732 mp->m_pkthdr.csum_flags |= type;
4734 mp->m_pkthdr.csum_data = htons(0xffff);
4742 ** This routine is run via an vlan config EVENT,
4743 ** it enables us to use the HW Filter table since
4744 ** we can get the vlan id. This just creates the
4745 ** entry in the soft version of the VFTA, init will
4746 ** repopulate the real table.
4749 ixgbe_register_vlan(void *arg, struct ifnet *ifp, u16 vtag)
4751 struct adapter *adapter = ifp->if_softc;
4754 if (ifp->if_softc != arg) /* Not our event */
4757 if ((vtag == 0) || (vtag > 4095)) /* Invalid */
4760 IXGBE_CORE_LOCK(adapter);
4761 index = (vtag >> 5) & 0x7F;
4763 adapter->shadow_vfta[index] |= (1 << bit);
4764 ++adapter->num_vlans;
4765 ixgbe_init_locked(adapter);
4766 IXGBE_CORE_UNLOCK(adapter);
4770 ** This routine is run via an vlan
4771 ** unconfig EVENT, remove our entry
4772 ** in the soft vfta.
4775 ixgbe_unregister_vlan(void *arg, struct ifnet *ifp, u16 vtag)
4777 struct adapter *adapter = ifp->if_softc;
4780 if (ifp->if_softc != arg)
4783 if ((vtag == 0) || (vtag > 4095)) /* Invalid */
4786 IXGBE_CORE_LOCK(adapter);
4787 index = (vtag >> 5) & 0x7F;
4789 adapter->shadow_vfta[index] &= ~(1 << bit);
4790 --adapter->num_vlans;
4791 /* Re-init to load the changes */
4792 ixgbe_init_locked(adapter);
4793 IXGBE_CORE_UNLOCK(adapter);
4797 ixgbe_setup_vlan_hw_support(struct adapter *adapter)
4799 struct ifnet *ifp = adapter->ifp;
4800 struct ixgbe_hw *hw = &adapter->hw;
4801 struct rx_ring *rxr;
4806 ** We get here thru init_locked, meaning
4807 ** a soft reset, this has already cleared
4808 ** the VFTA and other state, so if there
4809 ** have been no vlan's registered do nothing.
4811 if (adapter->num_vlans == 0)
4815 ** A soft reset zero's out the VFTA, so
4816 ** we need to repopulate it now.
4818 for (int i = 0; i < IXGBE_VFTA_SIZE; i++)
4819 if (adapter->shadow_vfta[i] != 0)
4820 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i),
4821 adapter->shadow_vfta[i]);
4823 ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4824 /* Enable the Filter Table if enabled */
4825 if (ifp->if_capenable & IFCAP_VLAN_HWFILTER) {
4826 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
4827 ctrl |= IXGBE_VLNCTRL_VFE;
4829 if (hw->mac.type == ixgbe_mac_82598EB)
4830 ctrl |= IXGBE_VLNCTRL_VME;
4831 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
4833 /* Setup the queues for vlans */
4834 for (int i = 0; i < adapter->num_queues; i++) {
4835 rxr = &adapter->rx_rings[i];
4836 /* On 82599 the VLAN enable is per/queue in RXDCTL */
4837 if (hw->mac.type != ixgbe_mac_82598EB) {
4838 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
4839 ctrl |= IXGBE_RXDCTL_VME;
4840 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), ctrl);
4842 rxr->vtag_strip = TRUE;
4847 ixgbe_enable_intr(struct adapter *adapter)
4849 struct ixgbe_hw *hw = &adapter->hw;
4850 struct ix_queue *que = adapter->queues;
4851 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
4854 /* Enable Fan Failure detection */
4855 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4856 mask |= IXGBE_EIMS_GPI_SDP1;
4858 mask |= IXGBE_EIMS_ECC;
4859 mask |= IXGBE_EIMS_GPI_SDP0;
4860 mask |= IXGBE_EIMS_GPI_SDP1;
4861 mask |= IXGBE_EIMS_GPI_SDP2;
4863 mask |= IXGBE_EIMS_FLOW_DIR;
4867 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
4869 /* With RSS we use auto clear */
4870 if (adapter->msix_mem) {
4871 mask = IXGBE_EIMS_ENABLE_MASK;
4872 /* Don't autoclear Link */
4873 mask &= ~IXGBE_EIMS_OTHER;
4874 mask &= ~IXGBE_EIMS_LSC;
4875 IXGBE_WRITE_REG(hw, IXGBE_EIAC, mask);
4879 ** Now enable all queues, this is done separately to
4880 ** allow for handling the extended (beyond 32) MSIX
4881 ** vectors that can be used by 82599
4883 for (int i = 0; i < adapter->num_queues; i++, que++)
4884 ixgbe_enable_queue(adapter, que->msix);
4886 IXGBE_WRITE_FLUSH(hw);
4892 ixgbe_disable_intr(struct adapter *adapter)
4894 if (adapter->msix_mem)
4895 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, 0);
4896 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
4897 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
4899 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
4900 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
4901 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
4903 IXGBE_WRITE_FLUSH(&adapter->hw);
4908 ixgbe_read_pci_cfg(struct ixgbe_hw *hw, u32 reg)
4912 value = pci_read_config(((struct ixgbe_osdep *)hw->back)->dev,
4919 ixgbe_write_pci_cfg(struct ixgbe_hw *hw, u32 reg, u16 value)
4921 pci_write_config(((struct ixgbe_osdep *)hw->back)->dev,
4928 ** Setup the correct IVAR register for a particular MSIX interrupt
4929 ** (yes this is all very magic and confusing :)
4930 ** - entry is the register array entry
4931 ** - vector is the MSIX vector for this queue
4932 ** - type is RX/TX/MISC
4935 ixgbe_set_ivar(struct adapter *adapter, u8 entry, u8 vector, s8 type)
4937 struct ixgbe_hw *hw = &adapter->hw;
4940 vector |= IXGBE_IVAR_ALLOC_VAL;
4942 switch (hw->mac.type) {
4944 case ixgbe_mac_82598EB:
4946 entry = IXGBE_IVAR_OTHER_CAUSES_INDEX;
4948 entry += (type * 64);
4949 index = (entry >> 2) & 0x1F;
4950 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
4951 ivar &= ~(0xFF << (8 * (entry & 0x3)));
4952 ivar |= (vector << (8 * (entry & 0x3)));
4953 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR(index), ivar);
4956 case ixgbe_mac_82599EB:
4957 case ixgbe_mac_X540:
4958 if (type == -1) { /* MISC IVAR */
4959 index = (entry & 1) * 8;
4960 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR_MISC);
4961 ivar &= ~(0xFF << index);
4962 ivar |= (vector << index);
4963 IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, ivar);
4964 } else { /* RX/TX IVARS */
4965 index = (16 * (entry & 1)) + (8 * type);
4966 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(entry >> 1));
4967 ivar &= ~(0xFF << index);
4968 ivar |= (vector << index);
4969 IXGBE_WRITE_REG(hw, IXGBE_IVAR(entry >> 1), ivar);
4978 ixgbe_configure_ivars(struct adapter *adapter)
4980 struct ix_queue *que = adapter->queues;
4983 if (ixgbe_max_interrupt_rate > 0)
4984 newitr = (4000000 / ixgbe_max_interrupt_rate) & 0x0FF8;
4988 for (int i = 0; i < adapter->num_queues; i++, que++) {
4989 /* First the RX queue entry */
4990 ixgbe_set_ivar(adapter, i, que->msix, 0);
4991 /* ... and the TX */
4992 ixgbe_set_ivar(adapter, i, que->msix, 1);
4993 /* Set an Initial EITR value */
4994 IXGBE_WRITE_REG(&adapter->hw,
4995 IXGBE_EITR(que->msix), newitr);
4998 /* For the Link interrupt */
4999 ixgbe_set_ivar(adapter, 1, adapter->linkvec, -1);
5003 ** ixgbe_sfp_probe - called in the local timer to
5004 ** determine if a port had optics inserted.
5006 static bool ixgbe_sfp_probe(struct adapter *adapter)
5008 struct ixgbe_hw *hw = &adapter->hw;
5009 device_t dev = adapter->dev;
5010 bool result = FALSE;
5012 if ((hw->phy.type == ixgbe_phy_nl) &&
5013 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
5014 s32 ret = hw->phy.ops.identify_sfp(hw);
5017 ret = hw->phy.ops.reset(hw);
5018 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
5019 device_printf(dev,"Unsupported SFP+ module detected!");
5020 printf(" Reload driver with supported module.\n");
5021 adapter->sfp_probe = FALSE;
5024 device_printf(dev,"SFP+ module detected!\n");
5025 /* We now have supported optics */
5026 adapter->sfp_probe = FALSE;
5027 /* Set the optics type so system reports correctly */
5028 ixgbe_setup_optics(adapter);
5036 ** Tasklet handler for MSIX Link interrupts
5037 ** - do outside interrupt since it might sleep
5040 ixgbe_handle_link(void *context, int pending)
5042 struct adapter *adapter = context;
5044 ixgbe_check_link(&adapter->hw,
5045 &adapter->link_speed, &adapter->link_up, 0);
5046 ixgbe_update_link_status(adapter);
5050 ** Tasklet for handling SFP module interrupts
5053 ixgbe_handle_mod(void *context, int pending)
5055 struct adapter *adapter = context;
5056 struct ixgbe_hw *hw = &adapter->hw;
5057 device_t dev = adapter->dev;
5060 err = hw->phy.ops.identify_sfp(hw);
5061 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
5063 "Unsupported SFP+ module type was detected.\n");
5066 err = hw->mac.ops.setup_sfp(hw);
5067 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
5069 "Setup failure - unsupported SFP+ module type.\n");
5072 taskqueue_enqueue(adapter->tq, &adapter->msf_task);
5078 ** Tasklet for handling MSF (multispeed fiber) interrupts
5081 ixgbe_handle_msf(void *context, int pending)
5083 struct adapter *adapter = context;
5084 struct ixgbe_hw *hw = &adapter->hw;
5088 autoneg = hw->phy.autoneg_advertised;
5089 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
5090 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiate);
5091 if (hw->mac.ops.setup_link)
5092 hw->mac.ops.setup_link(hw, autoneg, negotiate, TRUE);
5098 ** Tasklet for reinitializing the Flow Director filter table
5101 ixgbe_reinit_fdir(void *context, int pending)
5103 struct adapter *adapter = context;
5104 struct ifnet *ifp = adapter->ifp;
5106 if (adapter->fdir_reinit != 1) /* Shouldn't happen */
5108 ixgbe_reinit_fdir_tables_82599(&adapter->hw);
5109 adapter->fdir_reinit = 0;
5110 /* re-enable flow director interrupts */
5111 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
5112 /* Restart the interface */
5113 ifp->if_drv_flags |= IFF_DRV_RUNNING;
5118 /**********************************************************************
5120 * Update the board statistics counters.
5122 **********************************************************************/
5124 ixgbe_update_stats_counters(struct adapter *adapter)
5126 struct ifnet *ifp = adapter->ifp;
5127 struct ixgbe_hw *hw = &adapter->hw;
5128 u32 missed_rx = 0, bprc, lxon, lxoff, total;
5129 u64 total_missed_rx = 0;
5131 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
5132 adapter->stats.illerrc += IXGBE_READ_REG(hw, IXGBE_ILLERRC);
5133 adapter->stats.errbc += IXGBE_READ_REG(hw, IXGBE_ERRBC);
5134 adapter->stats.mspdc += IXGBE_READ_REG(hw, IXGBE_MSPDC);
5136 for (int i = 0; i < 8; i++) {
5138 mp = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5139 /* missed_rx tallies misses for the gprc workaround */
5141 /* global total per queue */
5142 adapter->stats.mpc[i] += mp;
5143 /* Running comprehensive total for stats display */
5144 total_missed_rx += adapter->stats.mpc[i];
5145 if (hw->mac.type == ixgbe_mac_82598EB)
5146 adapter->stats.rnbc[i] +=
5147 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5148 adapter->stats.pxontxc[i] +=
5149 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5150 adapter->stats.pxonrxc[i] +=
5151 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
5152 adapter->stats.pxofftxc[i] +=
5153 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
5154 adapter->stats.pxoffrxc[i] +=
5155 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
5156 adapter->stats.pxon2offc[i] +=
5157 IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
5159 for (int i = 0; i < 16; i++) {
5160 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5161 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5162 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
5163 adapter->stats.qbrc[i] +=
5164 ((u64)IXGBE_READ_REG(hw, IXGBE_QBRC(i)) << 32);
5165 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5166 adapter->stats.qbtc[i] +=
5167 ((u64)IXGBE_READ_REG(hw, IXGBE_QBTC(i)) << 32);
5168 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
5170 adapter->stats.mlfc += IXGBE_READ_REG(hw, IXGBE_MLFC);
5171 adapter->stats.mrfc += IXGBE_READ_REG(hw, IXGBE_MRFC);
5172 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
5174 /* Hardware workaround, gprc counts missed packets */
5175 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
5176 adapter->stats.gprc -= missed_rx;
5178 if (hw->mac.type != ixgbe_mac_82598EB) {
5179 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL) +
5180 ((u64)IXGBE_READ_REG(hw, IXGBE_GORCH) << 32);
5181 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL) +
5182 ((u64)IXGBE_READ_REG(hw, IXGBE_GOTCH) << 32);
5183 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL) +
5184 ((u64)IXGBE_READ_REG(hw, IXGBE_TORH) << 32);
5185 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
5186 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
5188 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
5189 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
5190 /* 82598 only has a counter in the high register */
5191 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5192 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5193 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5197 * Workaround: mprc hardware is incorrectly counting
5198 * broadcasts, so for now we subtract those.
5200 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
5201 adapter->stats.bprc += bprc;
5202 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
5203 if (hw->mac.type == ixgbe_mac_82598EB)
5204 adapter->stats.mprc -= bprc;
5206 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5207 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5208 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5209 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5210 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5211 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5213 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
5214 adapter->stats.lxontxc += lxon;
5215 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
5216 adapter->stats.lxofftxc += lxoff;
5217 total = lxon + lxoff;
5219 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5220 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
5221 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5222 adapter->stats.gptc -= total;
5223 adapter->stats.mptc -= total;
5224 adapter->stats.ptc64 -= total;
5225 adapter->stats.gotc -= total * ETHER_MIN_LEN;
5227 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5228 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5229 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5230 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5231 adapter->stats.mngprc += IXGBE_READ_REG(hw, IXGBE_MNGPRC);
5232 adapter->stats.mngpdc += IXGBE_READ_REG(hw, IXGBE_MNGPDC);
5233 adapter->stats.mngptc += IXGBE_READ_REG(hw, IXGBE_MNGPTC);
5234 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5235 adapter->stats.tpt += IXGBE_READ_REG(hw, IXGBE_TPT);
5236 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5237 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5238 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5239 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5240 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5241 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
5242 adapter->stats.xec += IXGBE_READ_REG(hw, IXGBE_XEC);
5243 adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5244 adapter->stats.fclast += IXGBE_READ_REG(hw, IXGBE_FCLAST);
5245 /* Only read FCOE on 82599 */
5246 if (hw->mac.type != ixgbe_mac_82598EB) {
5247 adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5248 adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5249 adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5250 adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5251 adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
5254 /* Fill out the OS statistics structure */
5255 ifp->if_ipackets = adapter->stats.gprc;
5256 ifp->if_opackets = adapter->stats.gptc;
5257 ifp->if_ibytes = adapter->stats.gorc;
5258 ifp->if_obytes = adapter->stats.gotc;
5259 ifp->if_imcasts = adapter->stats.mprc;
5260 ifp->if_omcasts = adapter->stats.mptc;
5261 ifp->if_collisions = 0;
5264 ifp->if_ierrors = total_missed_rx + adapter->stats.crcerrs +
5265 adapter->stats.rlec;
5268 /** ixgbe_sysctl_tdh_handler - Handler function
5269 * Retrieves the TDH value from the hardware
5272 ixgbe_sysctl_tdh_handler(SYSCTL_HANDLER_ARGS)
5276 struct tx_ring *txr = ((struct tx_ring *)oidp->oid_arg1);
5279 unsigned val = IXGBE_READ_REG(&txr->adapter->hw, IXGBE_TDH(txr->me));
5280 error = sysctl_handle_int(oidp, &val, 0, req);
5281 if (error || !req->newptr)
5286 /** ixgbe_sysctl_tdt_handler - Handler function
5287 * Retrieves the TDT value from the hardware
5290 ixgbe_sysctl_tdt_handler(SYSCTL_HANDLER_ARGS)
5294 struct tx_ring *txr = ((struct tx_ring *)oidp->oid_arg1);
5297 unsigned val = IXGBE_READ_REG(&txr->adapter->hw, IXGBE_TDT(txr->me));
5298 error = sysctl_handle_int(oidp, &val, 0, req);
5299 if (error || !req->newptr)
5304 /** ixgbe_sysctl_rdh_handler - Handler function
5305 * Retrieves the RDH value from the hardware
5308 ixgbe_sysctl_rdh_handler(SYSCTL_HANDLER_ARGS)
5312 struct rx_ring *rxr = ((struct rx_ring *)oidp->oid_arg1);
5315 unsigned val = IXGBE_READ_REG(&rxr->adapter->hw, IXGBE_RDH(rxr->me));
5316 error = sysctl_handle_int(oidp, &val, 0, req);
5317 if (error || !req->newptr)
5322 /** ixgbe_sysctl_rdt_handler - Handler function
5323 * Retrieves the RDT value from the hardware
5326 ixgbe_sysctl_rdt_handler(SYSCTL_HANDLER_ARGS)
5330 struct rx_ring *rxr = ((struct rx_ring *)oidp->oid_arg1);
5333 unsigned val = IXGBE_READ_REG(&rxr->adapter->hw, IXGBE_RDT(rxr->me));
5334 error = sysctl_handle_int(oidp, &val, 0, req);
5335 if (error || !req->newptr)
5341 ixgbe_sysctl_interrupt_rate_handler(SYSCTL_HANDLER_ARGS)
5344 struct ix_queue *que = ((struct ix_queue *)oidp->oid_arg1);
5345 unsigned int reg, usec, rate;
5347 reg = IXGBE_READ_REG(&que->adapter->hw, IXGBE_EITR(que->msix));
5348 usec = ((reg & 0x0FF8) >> 3);
5350 rate = 500000 / usec;
5353 error = sysctl_handle_int(oidp, &rate, 0, req);
5354 if (error || !req->newptr)
5356 reg &= ~0xfff; /* default, no limitation */
5357 ixgbe_max_interrupt_rate = 0;
5358 if (rate > 0 && rate < 500000) {
5361 ixgbe_max_interrupt_rate = rate;
5362 reg |= ((4000000/rate) & 0xff8 );
5364 IXGBE_WRITE_REG(&que->adapter->hw, IXGBE_EITR(que->msix), reg);
5369 * Add sysctl variables, one per statistic, to the system.
5372 ixgbe_add_hw_stats(struct adapter *adapter)
5375 device_t dev = adapter->dev;
5377 struct tx_ring *txr = adapter->tx_rings;
5378 struct rx_ring *rxr = adapter->rx_rings;
5380 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(dev);
5381 struct sysctl_oid *tree = device_get_sysctl_tree(dev);
5382 struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
5383 struct ixgbe_hw_stats *stats = &adapter->stats;
5385 struct sysctl_oid *stat_node, *queue_node;
5386 struct sysctl_oid_list *stat_list, *queue_list;
5388 #define QUEUE_NAME_LEN 32
5389 char namebuf[QUEUE_NAME_LEN];
5391 /* Driver Statistics */
5392 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "dropped",
5393 CTLFLAG_RD, &adapter->dropped_pkts,
5394 "Driver dropped packets");
5395 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "mbuf_defrag_failed",
5396 CTLFLAG_RD, &adapter->mbuf_defrag_failed,
5397 "m_defrag() failed");
5398 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "no_tx_dma_setup",
5399 CTLFLAG_RD, &adapter->no_tx_dma_setup,
5400 "Driver tx dma failure in xmit");
5401 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "watchdog_events",
5402 CTLFLAG_RD, &adapter->watchdog_events,
5403 "Watchdog timeouts");
5404 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "tso_tx",
5405 CTLFLAG_RD, &adapter->tso_tx,
5407 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "link_irq",
5408 CTLFLAG_RD, &adapter->link_irq,
5409 "Link MSIX IRQ Handled");
5411 for (int i = 0; i < adapter->num_queues; i++, txr++) {
5412 snprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i);
5413 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf,
5414 CTLFLAG_RD, NULL, "Queue Name");
5415 queue_list = SYSCTL_CHILDREN(queue_node);
5417 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "interrupt_rate",
5418 CTLTYPE_UINT | CTLFLAG_RW, &adapter->queues[i],
5419 sizeof(&adapter->queues[i]),
5420 ixgbe_sysctl_interrupt_rate_handler, "IU",
5422 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "irqs",
5423 CTLFLAG_RD, &(adapter->queues[i].irqs),
5424 "irqs on this queue");
5425 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "txd_head",
5426 CTLTYPE_UINT | CTLFLAG_RD, txr, sizeof(txr),
5427 ixgbe_sysctl_tdh_handler, "IU",
5428 "Transmit Descriptor Head");
5429 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "txd_tail",
5430 CTLTYPE_UINT | CTLFLAG_RD, txr, sizeof(txr),
5431 ixgbe_sysctl_tdt_handler, "IU",
5432 "Transmit Descriptor Tail");
5433 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "no_desc_avail",
5434 CTLFLAG_RD, &txr->no_desc_avail,
5435 "Queue No Descriptor Available");
5436 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tx_packets",
5437 CTLFLAG_RD, &txr->total_packets,
5438 "Queue Packets Transmitted");
5441 for (int i = 0; i < adapter->num_queues; i++, rxr++) {
5442 snprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i);
5443 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf,
5444 CTLFLAG_RD, NULL, "Queue Name");
5445 queue_list = SYSCTL_CHILDREN(queue_node);
5447 struct lro_ctrl *lro = &rxr->lro;
5449 snprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i);
5450 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf,
5451 CTLFLAG_RD, NULL, "Queue Name");
5452 queue_list = SYSCTL_CHILDREN(queue_node);
5454 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "rxd_head",
5455 CTLTYPE_UINT | CTLFLAG_RD, rxr, sizeof(rxr),
5456 ixgbe_sysctl_rdh_handler, "IU",
5457 "Receive Descriptor Head");
5458 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "rxd_tail",
5459 CTLTYPE_UINT | CTLFLAG_RD, rxr, sizeof(rxr),
5460 ixgbe_sysctl_rdt_handler, "IU",
5461 "Receive Descriptor Tail");
5462 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_packets",
5463 CTLFLAG_RD, &rxr->rx_packets,
5464 "Queue Packets Received");
5465 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_bytes",
5466 CTLFLAG_RD, &rxr->rx_bytes,
5467 "Queue Bytes Received");
5468 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_copies",
5469 CTLFLAG_RD, &rxr->rx_copies,
5470 "Copied RX Frames");
5471 SYSCTL_ADD_INT(ctx, queue_list, OID_AUTO, "lro_queued",
5472 CTLFLAG_RD, &lro->lro_queued, 0,
5474 SYSCTL_ADD_INT(ctx, queue_list, OID_AUTO, "lro_flushed",
5475 CTLFLAG_RD, &lro->lro_flushed, 0,
5479 /* MAC stats get the own sub node */
5481 stat_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "mac_stats",
5482 CTLFLAG_RD, NULL, "MAC Statistics");
5483 stat_list = SYSCTL_CHILDREN(stat_node);
5485 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "crc_errs",
5486 CTLFLAG_RD, &stats->crcerrs,
5488 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "ill_errs",
5489 CTLFLAG_RD, &stats->illerrc,
5490 "Illegal Byte Errors");
5491 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "byte_errs",
5492 CTLFLAG_RD, &stats->errbc,
5494 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "short_discards",
5495 CTLFLAG_RD, &stats->mspdc,
5496 "MAC Short Packets Discarded");
5497 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "local_faults",
5498 CTLFLAG_RD, &stats->mlfc,
5499 "MAC Local Faults");
5500 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "remote_faults",
5501 CTLFLAG_RD, &stats->mrfc,
5502 "MAC Remote Faults");
5503 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rec_len_errs",
5504 CTLFLAG_RD, &stats->rlec,
5505 "Receive Length Errors");
5506 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "link_xon_txd",
5507 CTLFLAG_RD, &stats->lxontxc,
5508 "Link XON Transmitted");
5509 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "link_xon_rcvd",
5510 CTLFLAG_RD, &stats->lxonrxc,
5511 "Link XON Received");
5512 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "link_xoff_txd",
5513 CTLFLAG_RD, &stats->lxofftxc,
5514 "Link XOFF Transmitted");
5515 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "link_xoff_rcvd",
5516 CTLFLAG_RD, &stats->lxoffrxc,
5517 "Link XOFF Received");
5519 /* Packet Reception Stats */
5520 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "total_octets_rcvd",
5521 CTLFLAG_RD, &stats->tor,
5522 "Total Octets Received");
5523 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_octets_rcvd",
5524 CTLFLAG_RD, &stats->gorc,
5525 "Good Octets Received");
5526 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "total_pkts_rcvd",
5527 CTLFLAG_RD, &stats->tpr,
5528 "Total Packets Received");
5529 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_pkts_rcvd",
5530 CTLFLAG_RD, &stats->gprc,
5531 "Good Packets Received");
5532 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "mcast_pkts_rcvd",
5533 CTLFLAG_RD, &stats->mprc,
5534 "Multicast Packets Received");
5535 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "bcast_pkts_rcvd",
5536 CTLFLAG_RD, &stats->bprc,
5537 "Broadcast Packets Received");
5538 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_64",
5539 CTLFLAG_RD, &stats->prc64,
5540 "64 byte frames received ");
5541 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_65_127",
5542 CTLFLAG_RD, &stats->prc127,
5543 "65-127 byte frames received");
5544 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_128_255",
5545 CTLFLAG_RD, &stats->prc255,
5546 "128-255 byte frames received");
5547 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_256_511",
5548 CTLFLAG_RD, &stats->prc511,
5549 "256-511 byte frames received");
5550 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_512_1023",
5551 CTLFLAG_RD, &stats->prc1023,
5552 "512-1023 byte frames received");
5553 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_1024_1522",
5554 CTLFLAG_RD, &stats->prc1522,
5555 "1023-1522 byte frames received");
5556 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_undersized",
5557 CTLFLAG_RD, &stats->ruc,
5558 "Receive Undersized");
5559 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_fragmented",
5560 CTLFLAG_RD, &stats->rfc,
5561 "Fragmented Packets Received ");
5562 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_oversized",
5563 CTLFLAG_RD, &stats->roc,
5564 "Oversized Packets Received");
5565 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_jabberd",
5566 CTLFLAG_RD, &stats->rjc,
5568 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "management_pkts_rcvd",
5569 CTLFLAG_RD, &stats->mngprc,
5570 "Management Packets Received");
5571 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "management_pkts_drpd",
5572 CTLFLAG_RD, &stats->mngptc,
5573 "Management Packets Dropped");
5574 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "checksum_errs",
5575 CTLFLAG_RD, &stats->xec,
5578 /* Packet Transmission Stats */
5579 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_octets_txd",
5580 CTLFLAG_RD, &stats->gotc,
5581 "Good Octets Transmitted");
5582 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "total_pkts_txd",
5583 CTLFLAG_RD, &stats->tpt,
5584 "Total Packets Transmitted");
5585 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_pkts_txd",
5586 CTLFLAG_RD, &stats->gptc,
5587 "Good Packets Transmitted");
5588 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "bcast_pkts_txd",
5589 CTLFLAG_RD, &stats->bptc,
5590 "Broadcast Packets Transmitted");
5591 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "mcast_pkts_txd",
5592 CTLFLAG_RD, &stats->mptc,
5593 "Multicast Packets Transmitted");
5594 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "management_pkts_txd",
5595 CTLFLAG_RD, &stats->mngptc,
5596 "Management Packets Transmitted");
5597 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_64",
5598 CTLFLAG_RD, &stats->ptc64,
5599 "64 byte frames transmitted ");
5600 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_65_127",
5601 CTLFLAG_RD, &stats->ptc127,
5602 "65-127 byte frames transmitted");
5603 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_128_255",
5604 CTLFLAG_RD, &stats->ptc255,
5605 "128-255 byte frames transmitted");
5606 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_256_511",
5607 CTLFLAG_RD, &stats->ptc511,
5608 "256-511 byte frames transmitted");
5609 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_512_1023",
5610 CTLFLAG_RD, &stats->ptc1023,
5611 "512-1023 byte frames transmitted");
5612 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_1024_1522",
5613 CTLFLAG_RD, &stats->ptc1522,
5614 "1024-1522 byte frames transmitted");
5617 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "fc_crc",
5618 CTLFLAG_RD, &stats->fccrc,
5620 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "fc_last",
5621 CTLFLAG_RD, &stats->fclast,
5623 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "fc_drpd",
5624 CTLFLAG_RD, &stats->fcoerpdc,
5625 "FCoE Packets Dropped");
5626 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "fc_pkts_rcvd",
5627 CTLFLAG_RD, &stats->fcoeprc,
5628 "FCoE Packets Received");
5629 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "fc_pkts_txd",
5630 CTLFLAG_RD, &stats->fcoeptc,
5631 "FCoE Packets Transmitted");
5632 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "fc_dword_rcvd",
5633 CTLFLAG_RD, &stats->fcoedwrc,
5634 "FCoE DWords Received");
5635 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "fc_dword_txd",
5636 CTLFLAG_RD, &stats->fcoedwtc,
5637 "FCoE DWords Transmitted");
5641 ** Set flow control using sysctl:
5642 ** Flow control values:
5649 ixgbe_set_flowcntl(SYSCTL_HANDLER_ARGS)
5652 struct adapter *adapter = (struct adapter *) arg1;
5655 error = sysctl_handle_int(oidp, &adapter->fc, 0, req);
5656 if ((error) || (req->newptr == NULL))
5659 /* Don't bother if it's not changed */
5660 if (adapter->fc == last)
5663 switch (adapter->fc) {
5664 case ixgbe_fc_rx_pause:
5665 case ixgbe_fc_tx_pause:
5667 adapter->hw.fc.requested_mode = adapter->fc;
5671 adapter->hw.fc.requested_mode = ixgbe_fc_none;
5673 /* Don't autoneg if forcing a value */
5674 adapter->hw.fc.disable_fc_autoneg = TRUE;
5675 ixgbe_fc_enable(&adapter->hw);
5680 ixgbe_add_rx_process_limit(struct adapter *adapter, const char *name,
5681 const char *description, int *limit, int value)
5684 SYSCTL_ADD_INT(device_get_sysctl_ctx(adapter->dev),
5685 SYSCTL_CHILDREN(device_get_sysctl_tree(adapter->dev)),
5686 OID_AUTO, name, CTLTYPE_INT|CTLFLAG_RW, limit, value, description);
5690 ** Control link advertise speed:
5691 ** 1 - advertise only 1G
5692 ** 2 - advertise 100Mb
5693 ** 3 - advertise normal
5696 ixgbe_set_advertise(SYSCTL_HANDLER_ARGS)
5699 struct adapter *adapter;
5701 struct ixgbe_hw *hw;
5702 ixgbe_link_speed speed, last;
5704 adapter = (struct adapter *) arg1;
5707 last = adapter->advertise;
5709 error = sysctl_handle_int(oidp, &adapter->advertise, 0, req);
5710 if ((error) || (adapter->advertise == -1))
5713 if (adapter->advertise == last) /* no change */
5716 if (!((hw->phy.media_type == ixgbe_media_type_copper) ||
5717 (hw->phy.multispeed_fiber)))
5720 if ((adapter->advertise == 2) && (hw->mac.type != ixgbe_mac_X540)) {
5721 device_printf(dev, "Set Advertise: 100Mb on X540 only\n");
5725 if (adapter->advertise == 1)
5726 speed = IXGBE_LINK_SPEED_1GB_FULL;
5727 else if (adapter->advertise == 2)
5728 speed = IXGBE_LINK_SPEED_100_FULL;
5729 else if (adapter->advertise == 3)
5730 speed = IXGBE_LINK_SPEED_1GB_FULL |
5731 IXGBE_LINK_SPEED_10GB_FULL;
5732 else /* bogus value */
5735 hw->mac.autotry_restart = TRUE;
5736 hw->mac.ops.setup_link(hw, speed, TRUE, TRUE);
5742 ** Thermal Shutdown Trigger
5743 ** - cause a Thermal Overtemp IRQ
5746 ixgbe_set_thermal_test(SYSCTL_HANDLER_ARGS)
5748 int error, fire = 0;
5749 struct adapter *adapter = (struct adapter *) arg1;
5750 struct ixgbe_hw *hw = &adapter->hw;
5753 if (hw->mac.type != ixgbe_mac_X540)
5756 error = sysctl_handle_int(oidp, &fire, 0, req);
5757 if ((error) || (req->newptr == NULL))
5761 u32 reg = IXGBE_READ_REG(hw, IXGBE_EICS);
5762 reg |= IXGBE_EICR_TS;
5763 IXGBE_WRITE_REG(hw, IXGBE_EICS, reg);