1 /******************************************************************************
3 Copyright (c) 2001-2013, 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.5.7 - STABLE/9";
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_82599_SFP_SF_QP, 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 #ifdef IXGBE_LEGACY_TX
108 static void ixgbe_start(struct ifnet *);
109 static void ixgbe_start_locked(struct tx_ring *, struct ifnet *);
110 #else /* ! IXGBE_LEGACY_TX */
111 static int ixgbe_mq_start(struct ifnet *, struct mbuf *);
112 static int ixgbe_mq_start_locked(struct ifnet *,
113 struct tx_ring *, struct mbuf *);
114 static void ixgbe_qflush(struct ifnet *);
115 static void ixgbe_deferred_mq_start(void *, int);
116 #endif /* IXGBE_LEGACY_TX */
117 static int ixgbe_ioctl(struct ifnet *, u_long, caddr_t);
118 static void ixgbe_init(void *);
119 static void ixgbe_init_locked(struct adapter *);
120 static void ixgbe_stop(void *);
121 static void ixgbe_media_status(struct ifnet *, struct ifmediareq *);
122 static int ixgbe_media_change(struct ifnet *);
123 static void ixgbe_identify_hardware(struct adapter *);
124 static int ixgbe_allocate_pci_resources(struct adapter *);
125 static int ixgbe_allocate_msix(struct adapter *);
126 static int ixgbe_allocate_legacy(struct adapter *);
127 static int ixgbe_allocate_queues(struct adapter *);
128 static int ixgbe_setup_msix(struct adapter *);
129 static void ixgbe_free_pci_resources(struct adapter *);
130 static void ixgbe_local_timer(void *);
131 static int ixgbe_setup_interface(device_t, struct adapter *);
132 static void ixgbe_config_link(struct adapter *);
134 static int ixgbe_allocate_transmit_buffers(struct tx_ring *);
135 static int ixgbe_setup_transmit_structures(struct adapter *);
136 static void ixgbe_setup_transmit_ring(struct tx_ring *);
137 static void ixgbe_initialize_transmit_units(struct adapter *);
138 static void ixgbe_free_transmit_structures(struct adapter *);
139 static void ixgbe_free_transmit_buffers(struct tx_ring *);
141 static int ixgbe_allocate_receive_buffers(struct rx_ring *);
142 static int ixgbe_setup_receive_structures(struct adapter *);
143 static int ixgbe_setup_receive_ring(struct rx_ring *);
144 static void ixgbe_initialize_receive_units(struct adapter *);
145 static void ixgbe_free_receive_structures(struct adapter *);
146 static void ixgbe_free_receive_buffers(struct rx_ring *);
147 static void ixgbe_setup_hw_rsc(struct rx_ring *);
149 static void ixgbe_enable_intr(struct adapter *);
150 static void ixgbe_disable_intr(struct adapter *);
151 static void ixgbe_update_stats_counters(struct adapter *);
152 static bool ixgbe_txeof(struct tx_ring *);
153 static bool ixgbe_rxeof(struct ix_queue *);
154 static void ixgbe_rx_checksum(u32, struct mbuf *, u32);
155 static void ixgbe_set_promisc(struct adapter *);
156 static void ixgbe_set_multi(struct adapter *);
157 static void ixgbe_update_link_status(struct adapter *);
158 static void ixgbe_refresh_mbufs(struct rx_ring *, int);
159 static int ixgbe_xmit(struct tx_ring *, struct mbuf **);
160 static int ixgbe_set_flowcntl(SYSCTL_HANDLER_ARGS);
161 static int ixgbe_set_advertise(SYSCTL_HANDLER_ARGS);
162 static int ixgbe_set_thermal_test(SYSCTL_HANDLER_ARGS);
163 static int ixgbe_dma_malloc(struct adapter *, bus_size_t,
164 struct ixgbe_dma_alloc *, int);
165 static void ixgbe_dma_free(struct adapter *, struct ixgbe_dma_alloc *);
166 static int ixgbe_tx_ctx_setup(struct tx_ring *,
167 struct mbuf *, u32 *, u32 *);
168 static int ixgbe_tso_setup(struct tx_ring *,
169 struct mbuf *, u32 *, u32 *);
170 static void ixgbe_set_ivar(struct adapter *, u8, u8, s8);
171 static void ixgbe_configure_ivars(struct adapter *);
172 static u8 * ixgbe_mc_array_itr(struct ixgbe_hw *, u8 **, u32 *);
174 static void ixgbe_setup_vlan_hw_support(struct adapter *);
175 static void ixgbe_register_vlan(void *, struct ifnet *, u16);
176 static void ixgbe_unregister_vlan(void *, struct ifnet *, u16);
178 static void ixgbe_add_hw_stats(struct adapter *adapter);
180 static __inline void ixgbe_rx_discard(struct rx_ring *, int);
181 static __inline void ixgbe_rx_input(struct rx_ring *, struct ifnet *,
184 static void ixgbe_enable_rx_drop(struct adapter *);
185 static void ixgbe_disable_rx_drop(struct adapter *);
187 /* Support for pluggable optic modules */
188 static bool ixgbe_sfp_probe(struct adapter *);
189 static void ixgbe_setup_optics(struct adapter *);
191 /* Legacy (single vector interrupt handler */
192 static void ixgbe_legacy_irq(void *);
194 /* The MSI/X Interrupt handlers */
195 static void ixgbe_msix_que(void *);
196 static void ixgbe_msix_link(void *);
198 /* Deferred interrupt tasklets */
199 static void ixgbe_handle_que(void *, int);
200 static void ixgbe_handle_link(void *, int);
201 static void ixgbe_handle_msf(void *, int);
202 static void ixgbe_handle_mod(void *, int);
205 static void ixgbe_atr(struct tx_ring *, struct mbuf *);
206 static void ixgbe_reinit_fdir(void *, int);
209 /*********************************************************************
210 * FreeBSD Device Interface Entry Points
211 *********************************************************************/
213 static device_method_t ixgbe_methods[] = {
214 /* Device interface */
215 DEVMETHOD(device_probe, ixgbe_probe),
216 DEVMETHOD(device_attach, ixgbe_attach),
217 DEVMETHOD(device_detach, ixgbe_detach),
218 DEVMETHOD(device_shutdown, ixgbe_shutdown),
222 static driver_t ixgbe_driver = {
223 "ix", ixgbe_methods, sizeof(struct adapter),
226 devclass_t ixgbe_devclass;
227 DRIVER_MODULE(ixgbe, pci, ixgbe_driver, ixgbe_devclass, 0, 0);
229 MODULE_DEPEND(ixgbe, pci, 1, 1, 1);
230 MODULE_DEPEND(ixgbe, ether, 1, 1, 1);
233 ** TUNEABLE PARAMETERS:
237 ** AIM: Adaptive Interrupt Moderation
238 ** which means that the interrupt rate
239 ** is varied over time based on the
240 ** traffic for that interrupt vector
242 static int ixgbe_enable_aim = TRUE;
243 TUNABLE_INT("hw.ixgbe.enable_aim", &ixgbe_enable_aim);
245 static int ixgbe_max_interrupt_rate = (4000000 / IXGBE_LOW_LATENCY);
246 TUNABLE_INT("hw.ixgbe.max_interrupt_rate", &ixgbe_max_interrupt_rate);
248 /* How many packets rxeof tries to clean at a time */
249 static int ixgbe_rx_process_limit = 256;
250 TUNABLE_INT("hw.ixgbe.rx_process_limit", &ixgbe_rx_process_limit);
252 /* How many packets txeof tries to clean at a time */
253 static int ixgbe_tx_process_limit = 256;
254 TUNABLE_INT("hw.ixgbe.tx_process_limit", &ixgbe_tx_process_limit);
257 ** Smart speed setting, default to on
258 ** this only works as a compile option
259 ** right now as its during attach, set
260 ** this to 'ixgbe_smart_speed_off' to
263 static int ixgbe_smart_speed = ixgbe_smart_speed_on;
266 * MSIX should be the default for best performance,
267 * but this allows it to be forced off for testing.
269 static int ixgbe_enable_msix = 1;
270 TUNABLE_INT("hw.ixgbe.enable_msix", &ixgbe_enable_msix);
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);
295 ** this feature only works with
296 ** IPv4, and only on 82599 and later.
297 ** Also this will cause IP forwarding to
298 ** fail and that can't be controlled by
299 ** the stack as LRO can. For all these
300 ** reasons I've deemed it best to leave
301 ** this off and not bother with a tuneable
302 ** interface, this would need to be compiled
305 static bool ixgbe_rsc_enable = FALSE;
307 /* Keep running tab on them for sanity check */
308 static int ixgbe_total_ports;
312 ** For Flow Director: this is the
313 ** number of TX packets we sample
314 ** for the filter pool, this means
315 ** every 20th packet will be probed.
317 ** This feature can be disabled by
318 ** setting this to 0.
320 static int atr_sample_rate = 20;
322 ** Flow Director actually 'steals'
323 ** part of the packet buffer as its
324 ** filter pool, this variable controls
326 ** 0 = 64K, 1 = 128K, 2 = 256K
328 static int fdir_pballoc = 1;
333 * The #ifdef DEV_NETMAP / #endif blocks in this file are meant to
334 * be a reference on how to implement netmap support in a driver.
335 * Additional comments are in ixgbe_netmap.h .
337 * <dev/netmap/ixgbe_netmap.h> contains functions for netmap support
338 * that extend the standard driver.
340 #include <dev/netmap/ixgbe_netmap.h>
341 #endif /* DEV_NETMAP */
343 /*********************************************************************
344 * Device identification routine
346 * ixgbe_probe determines if the driver should be loaded on
347 * adapter based on PCI vendor/device id of the adapter.
349 * return BUS_PROBE_DEFAULT on success, positive on failure
350 *********************************************************************/
353 ixgbe_probe(device_t dev)
355 ixgbe_vendor_info_t *ent;
357 u16 pci_vendor_id = 0;
358 u16 pci_device_id = 0;
359 u16 pci_subvendor_id = 0;
360 u16 pci_subdevice_id = 0;
361 char adapter_name[256];
363 INIT_DEBUGOUT("ixgbe_probe: begin");
365 pci_vendor_id = pci_get_vendor(dev);
366 if (pci_vendor_id != IXGBE_INTEL_VENDOR_ID)
369 pci_device_id = pci_get_device(dev);
370 pci_subvendor_id = pci_get_subvendor(dev);
371 pci_subdevice_id = pci_get_subdevice(dev);
373 ent = ixgbe_vendor_info_array;
374 while (ent->vendor_id != 0) {
375 if ((pci_vendor_id == ent->vendor_id) &&
376 (pci_device_id == ent->device_id) &&
378 ((pci_subvendor_id == ent->subvendor_id) ||
379 (ent->subvendor_id == 0)) &&
381 ((pci_subdevice_id == ent->subdevice_id) ||
382 (ent->subdevice_id == 0))) {
383 sprintf(adapter_name, "%s, Version - %s",
384 ixgbe_strings[ent->index],
385 ixgbe_driver_version);
386 device_set_desc_copy(dev, adapter_name);
388 return (BUS_PROBE_DEFAULT);
395 /*********************************************************************
396 * Device initialization routine
398 * The attach entry point is called when the driver is being loaded.
399 * This routine identifies the type of hardware, allocates all resources
400 * and initializes the hardware.
402 * return 0 on success, positive on failure
403 *********************************************************************/
406 ixgbe_attach(device_t dev)
408 struct adapter *adapter;
414 INIT_DEBUGOUT("ixgbe_attach: begin");
416 /* Allocate, clear, and link in our adapter structure */
417 adapter = device_get_softc(dev);
418 adapter->dev = adapter->osdep.dev = dev;
422 IXGBE_CORE_LOCK_INIT(adapter, device_get_nameunit(dev));
426 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
427 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
428 OID_AUTO, "fc", CTLTYPE_INT | CTLFLAG_RW,
429 adapter, 0, ixgbe_set_flowcntl, "I", "Flow Control");
431 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
432 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
433 OID_AUTO, "enable_aim", CTLTYPE_INT|CTLFLAG_RW,
434 &ixgbe_enable_aim, 1, "Interrupt Moderation");
437 ** Allow a kind of speed control by forcing the autoneg
438 ** advertised speed list to only a certain value, this
439 ** supports 1G on 82599 devices, and 100Mb on x540.
441 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
442 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
443 OID_AUTO, "advertise_speed", CTLTYPE_INT | CTLFLAG_RW,
444 adapter, 0, ixgbe_set_advertise, "I", "Link Speed");
446 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
447 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
448 OID_AUTO, "ts", CTLTYPE_INT | CTLFLAG_RW, adapter,
449 0, ixgbe_set_thermal_test, "I", "Thermal Test");
451 /* Set up the timer callout */
452 callout_init_mtx(&adapter->timer, &adapter->core_mtx, 0);
454 /* Determine hardware revision */
455 ixgbe_identify_hardware(adapter);
457 /* Do base PCI setup - map BAR0 */
458 if (ixgbe_allocate_pci_resources(adapter)) {
459 device_printf(dev, "Allocation of PCI resources failed\n");
464 /* Do descriptor calc and sanity checks */
465 if (((ixgbe_txd * sizeof(union ixgbe_adv_tx_desc)) % DBA_ALIGN) != 0 ||
466 ixgbe_txd < MIN_TXD || ixgbe_txd > MAX_TXD) {
467 device_printf(dev, "TXD config issue, using default!\n");
468 adapter->num_tx_desc = DEFAULT_TXD;
470 adapter->num_tx_desc = ixgbe_txd;
473 ** With many RX rings it is easy to exceed the
474 ** system mbuf allocation. Tuning nmbclusters
475 ** can alleviate this.
477 if (nmbclusters > 0 ) {
479 s = (ixgbe_rxd * adapter->num_queues) * ixgbe_total_ports;
480 if (s > nmbclusters) {
481 device_printf(dev, "RX Descriptors exceed "
482 "system mbuf max, using default instead!\n");
483 ixgbe_rxd = DEFAULT_RXD;
487 if (((ixgbe_rxd * sizeof(union ixgbe_adv_rx_desc)) % DBA_ALIGN) != 0 ||
488 ixgbe_rxd < MIN_TXD || ixgbe_rxd > MAX_TXD) {
489 device_printf(dev, "RXD config issue, using default!\n");
490 adapter->num_rx_desc = DEFAULT_RXD;
492 adapter->num_rx_desc = ixgbe_rxd;
494 /* Allocate our TX/RX Queues */
495 if (ixgbe_allocate_queues(adapter)) {
500 /* Allocate multicast array memory. */
501 adapter->mta = malloc(sizeof(u8) * IXGBE_ETH_LENGTH_OF_ADDRESS *
502 MAX_NUM_MULTICAST_ADDRESSES, M_DEVBUF, M_NOWAIT);
503 if (adapter->mta == NULL) {
504 device_printf(dev, "Can not allocate multicast setup array\n");
509 /* Initialize the shared code */
510 error = ixgbe_init_shared_code(hw);
511 if (error == IXGBE_ERR_SFP_NOT_PRESENT) {
513 ** No optics in this port, set up
514 ** so the timer routine will probe
515 ** for later insertion.
517 adapter->sfp_probe = TRUE;
519 } else if (error == IXGBE_ERR_SFP_NOT_SUPPORTED) {
520 device_printf(dev,"Unsupported SFP+ module detected!\n");
524 device_printf(dev,"Unable to initialize the shared code\n");
529 /* Make sure we have a good EEPROM before we read from it */
530 if (ixgbe_validate_eeprom_checksum(&adapter->hw, &csum) < 0) {
531 device_printf(dev,"The EEPROM Checksum Is Not Valid\n");
536 error = ixgbe_init_hw(hw);
538 case IXGBE_ERR_EEPROM_VERSION:
539 device_printf(dev, "This device is a pre-production adapter/"
540 "LOM. Please be aware there may be issues associated "
541 "with your hardware.\n If you are experiencing problems "
542 "please contact your Intel or hardware representative "
543 "who provided you with this hardware.\n");
545 case IXGBE_ERR_SFP_NOT_SUPPORTED:
546 device_printf(dev,"Unsupported SFP+ Module\n");
549 case IXGBE_ERR_SFP_NOT_PRESENT:
550 device_printf(dev,"No SFP+ Module found\n");
556 /* Detect and set physical type */
557 ixgbe_setup_optics(adapter);
559 if ((adapter->msix > 1) && (ixgbe_enable_msix))
560 error = ixgbe_allocate_msix(adapter);
562 error = ixgbe_allocate_legacy(adapter);
566 /* Setup OS specific network interface */
567 if (ixgbe_setup_interface(dev, adapter) != 0)
570 /* Initialize statistics */
571 ixgbe_update_stats_counters(adapter);
573 /* Register for VLAN events */
574 adapter->vlan_attach = EVENTHANDLER_REGISTER(vlan_config,
575 ixgbe_register_vlan, adapter, EVENTHANDLER_PRI_FIRST);
576 adapter->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig,
577 ixgbe_unregister_vlan, adapter, EVENTHANDLER_PRI_FIRST);
579 /* Print PCIE bus type/speed/width info */
580 ixgbe_get_bus_info(hw);
581 device_printf(dev,"PCI Express Bus: Speed %s %s\n",
582 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
583 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
584 (hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
585 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
586 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
589 if ((hw->bus.width <= ixgbe_bus_width_pcie_x4) &&
590 (hw->bus.speed == ixgbe_bus_speed_2500)) {
591 device_printf(dev, "PCI-Express bandwidth available"
592 " for this card\n is not sufficient for"
593 " optimal performance.\n");
594 device_printf(dev, "For optimal performance a x8 "
595 "PCIE, or x4 PCIE 2 slot is required.\n");
598 /* Set an initial default flow control value */
599 adapter->fc = ixgbe_fc_full;
601 /* let hardware know driver is loaded */
602 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
603 ctrl_ext |= IXGBE_CTRL_EXT_DRV_LOAD;
604 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
606 ixgbe_add_hw_stats(adapter);
609 ixgbe_netmap_attach(adapter);
610 #endif /* DEV_NETMAP */
611 INIT_DEBUGOUT("ixgbe_attach: end");
614 ixgbe_free_transmit_structures(adapter);
615 ixgbe_free_receive_structures(adapter);
617 if (adapter->ifp != NULL)
618 if_free(adapter->ifp);
619 ixgbe_free_pci_resources(adapter);
620 free(adapter->mta, M_DEVBUF);
625 /*********************************************************************
626 * Device removal routine
628 * The detach entry point is called when the driver is being removed.
629 * This routine stops the adapter and deallocates all the resources
630 * that were allocated for driver operation.
632 * return 0 on success, positive on failure
633 *********************************************************************/
636 ixgbe_detach(device_t dev)
638 struct adapter *adapter = device_get_softc(dev);
639 struct ix_queue *que = adapter->queues;
640 struct tx_ring *txr = adapter->tx_rings;
643 INIT_DEBUGOUT("ixgbe_detach: begin");
645 /* Make sure VLANS are not using driver */
646 if (adapter->ifp->if_vlantrunk != NULL) {
647 device_printf(dev,"Vlan in use, detach first\n");
651 IXGBE_CORE_LOCK(adapter);
653 IXGBE_CORE_UNLOCK(adapter);
655 for (int i = 0; i < adapter->num_queues; i++, que++, txr++) {
657 #ifndef IXGBE_LEGACY_TX
658 taskqueue_drain(que->tq, &txr->txq_task);
660 taskqueue_drain(que->tq, &que->que_task);
661 taskqueue_free(que->tq);
665 /* Drain the Link queue */
667 taskqueue_drain(adapter->tq, &adapter->link_task);
668 taskqueue_drain(adapter->tq, &adapter->mod_task);
669 taskqueue_drain(adapter->tq, &adapter->msf_task);
671 taskqueue_drain(adapter->tq, &adapter->fdir_task);
673 taskqueue_free(adapter->tq);
676 /* let hardware know driver is unloading */
677 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
678 ctrl_ext &= ~IXGBE_CTRL_EXT_DRV_LOAD;
679 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, ctrl_ext);
681 /* Unregister VLAN events */
682 if (adapter->vlan_attach != NULL)
683 EVENTHANDLER_DEREGISTER(vlan_config, adapter->vlan_attach);
684 if (adapter->vlan_detach != NULL)
685 EVENTHANDLER_DEREGISTER(vlan_unconfig, adapter->vlan_detach);
687 ether_ifdetach(adapter->ifp);
688 callout_drain(&adapter->timer);
690 netmap_detach(adapter->ifp);
691 #endif /* DEV_NETMAP */
692 ixgbe_free_pci_resources(adapter);
693 bus_generic_detach(dev);
694 if_free(adapter->ifp);
696 ixgbe_free_transmit_structures(adapter);
697 ixgbe_free_receive_structures(adapter);
698 free(adapter->mta, M_DEVBUF);
700 IXGBE_CORE_LOCK_DESTROY(adapter);
704 /*********************************************************************
706 * Shutdown entry point
708 **********************************************************************/
711 ixgbe_shutdown(device_t dev)
713 struct adapter *adapter = device_get_softc(dev);
714 IXGBE_CORE_LOCK(adapter);
716 IXGBE_CORE_UNLOCK(adapter);
721 #ifdef IXGBE_LEGACY_TX
722 /*********************************************************************
723 * Transmit entry point
725 * ixgbe_start is called by the stack to initiate a transmit.
726 * The driver will remain in this routine as long as there are
727 * packets to transmit and transmit resources are available.
728 * In case resources are not available stack is notified and
729 * the packet is requeued.
730 **********************************************************************/
733 ixgbe_start_locked(struct tx_ring *txr, struct ifnet * ifp)
736 struct adapter *adapter = txr->adapter;
738 IXGBE_TX_LOCK_ASSERT(txr);
740 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
742 if (!adapter->link_active)
745 while (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
746 if (txr->tx_avail <= IXGBE_QUEUE_MIN_FREE)
749 IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
753 if (ixgbe_xmit(txr, &m_head)) {
755 IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
758 /* Send a copy of the frame to the BPF listener */
759 ETHER_BPF_MTAP(ifp, m_head);
761 /* Set watchdog on */
762 txr->watchdog_time = ticks;
763 txr->queue_status = IXGBE_QUEUE_WORKING;
770 * Legacy TX start - called by the stack, this
771 * always uses the first tx ring, and should
772 * not be used with multiqueue tx enabled.
775 ixgbe_start(struct ifnet *ifp)
777 struct adapter *adapter = ifp->if_softc;
778 struct tx_ring *txr = adapter->tx_rings;
780 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
782 ixgbe_start_locked(txr, ifp);
783 IXGBE_TX_UNLOCK(txr);
788 #else /* ! IXGBE_LEGACY_TX */
791 ** Multiqueue Transmit driver
795 ixgbe_mq_start(struct ifnet *ifp, struct mbuf *m)
797 struct adapter *adapter = ifp->if_softc;
798 struct ix_queue *que;
802 /* Which queue to use */
803 if ((m->m_flags & M_FLOWID) != 0)
804 i = m->m_pkthdr.flowid % adapter->num_queues;
806 i = curcpu % adapter->num_queues;
808 txr = &adapter->tx_rings[i];
809 que = &adapter->queues[i];
811 if (IXGBE_TX_TRYLOCK(txr)) {
812 err = ixgbe_mq_start_locked(ifp, txr, m);
813 IXGBE_TX_UNLOCK(txr);
815 err = drbr_enqueue(ifp, txr->br, m);
816 taskqueue_enqueue(que->tq, &txr->txq_task);
823 ixgbe_mq_start_locked(struct ifnet *ifp, struct tx_ring *txr, struct mbuf *m)
825 struct adapter *adapter = txr->adapter;
827 int enqueued, err = 0;
829 if (((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) ||
830 adapter->link_active == 0) {
832 err = drbr_enqueue(ifp, txr->br, m);
838 err = drbr_enqueue(ifp, txr->br, m);
844 /* Process the queue */
845 while ((next = drbr_peek(ifp, txr->br)) != NULL) {
846 if ((err = ixgbe_xmit(txr, &next)) != 0) {
848 drbr_advance(ifp, txr->br);
850 drbr_putback(ifp, txr->br, next);
854 drbr_advance(ifp, txr->br);
856 /* Send a copy of the frame to the BPF listener */
857 ETHER_BPF_MTAP(ifp, next);
858 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
860 if (txr->tx_avail < IXGBE_TX_OP_THRESHOLD)
865 /* Set watchdog on */
866 txr->queue_status = IXGBE_QUEUE_WORKING;
867 txr->watchdog_time = ticks;
870 if (txr->tx_avail < IXGBE_TX_CLEANUP_THRESHOLD)
877 * Called from a taskqueue to drain queued transmit packets.
880 ixgbe_deferred_mq_start(void *arg, int pending)
882 struct tx_ring *txr = arg;
883 struct adapter *adapter = txr->adapter;
884 struct ifnet *ifp = adapter->ifp;
887 if (!drbr_empty(ifp, txr->br))
888 ixgbe_mq_start_locked(ifp, txr, NULL);
889 IXGBE_TX_UNLOCK(txr);
893 ** Flush all ring buffers
896 ixgbe_qflush(struct ifnet *ifp)
898 struct adapter *adapter = ifp->if_softc;
899 struct tx_ring *txr = adapter->tx_rings;
902 for (int i = 0; i < adapter->num_queues; i++, txr++) {
904 while ((m = buf_ring_dequeue_sc(txr->br)) != NULL)
906 IXGBE_TX_UNLOCK(txr);
910 #endif /* IXGBE_LEGACY_TX */
912 /*********************************************************************
915 * ixgbe_ioctl is called when the user wants to configure the
918 * return 0 on success, positive on failure
919 **********************************************************************/
922 ixgbe_ioctl(struct ifnet * ifp, u_long command, caddr_t data)
924 struct adapter *adapter = ifp->if_softc;
925 struct ixgbe_hw *hw = &adapter->hw;
926 struct ifreq *ifr = (struct ifreq *) data;
927 #if defined(INET) || defined(INET6)
928 struct ifaddr *ifa = (struct ifaddr *)data;
929 bool avoid_reset = FALSE;
937 if (ifa->ifa_addr->sa_family == AF_INET)
941 if (ifa->ifa_addr->sa_family == AF_INET6)
944 #if defined(INET) || defined(INET6)
946 ** Calling init results in link renegotiation,
947 ** so we avoid doing it when possible.
950 ifp->if_flags |= IFF_UP;
951 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
953 if (!(ifp->if_flags & IFF_NOARP))
954 arp_ifinit(ifp, ifa);
956 error = ether_ioctl(ifp, command, data);
960 IOCTL_DEBUGOUT("ioctl: SIOCSIFMTU (Set Interface MTU)");
961 if (ifr->ifr_mtu > IXGBE_MAX_FRAME_SIZE - ETHER_HDR_LEN) {
964 IXGBE_CORE_LOCK(adapter);
965 ifp->if_mtu = ifr->ifr_mtu;
966 adapter->max_frame_size =
967 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
968 ixgbe_init_locked(adapter);
969 IXGBE_CORE_UNLOCK(adapter);
973 IOCTL_DEBUGOUT("ioctl: SIOCSIFFLAGS (Set Interface Flags)");
974 IXGBE_CORE_LOCK(adapter);
975 if (ifp->if_flags & IFF_UP) {
976 if ((ifp->if_drv_flags & IFF_DRV_RUNNING)) {
977 if ((ifp->if_flags ^ adapter->if_flags) &
978 (IFF_PROMISC | IFF_ALLMULTI)) {
979 ixgbe_set_promisc(adapter);
982 ixgbe_init_locked(adapter);
984 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
986 adapter->if_flags = ifp->if_flags;
987 IXGBE_CORE_UNLOCK(adapter);
991 IOCTL_DEBUGOUT("ioctl: SIOC(ADD|DEL)MULTI");
992 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
993 IXGBE_CORE_LOCK(adapter);
994 ixgbe_disable_intr(adapter);
995 ixgbe_set_multi(adapter);
996 ixgbe_enable_intr(adapter);
997 IXGBE_CORE_UNLOCK(adapter);
1002 IOCTL_DEBUGOUT("ioctl: SIOCxIFMEDIA (Get/Set Interface Media)");
1003 error = ifmedia_ioctl(ifp, ifr, &adapter->media, command);
1007 int mask = ifr->ifr_reqcap ^ ifp->if_capenable;
1008 IOCTL_DEBUGOUT("ioctl: SIOCSIFCAP (Set Capabilities)");
1009 if (mask & IFCAP_HWCSUM)
1010 ifp->if_capenable ^= IFCAP_HWCSUM;
1011 if (mask & IFCAP_TSO4)
1012 ifp->if_capenable ^= IFCAP_TSO4;
1013 if (mask & IFCAP_TSO6)
1014 ifp->if_capenable ^= IFCAP_TSO6;
1015 if (mask & IFCAP_LRO)
1016 ifp->if_capenable ^= IFCAP_LRO;
1017 if (mask & IFCAP_VLAN_HWTAGGING)
1018 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
1019 if (mask & IFCAP_VLAN_HWFILTER)
1020 ifp->if_capenable ^= IFCAP_VLAN_HWFILTER;
1021 if (mask & IFCAP_VLAN_HWTSO)
1022 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
1023 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1024 IXGBE_CORE_LOCK(adapter);
1025 ixgbe_init_locked(adapter);
1026 IXGBE_CORE_UNLOCK(adapter);
1028 VLAN_CAPABILITIES(ifp);
1033 struct ixgbe_i2c_req i2c;
1034 IOCTL_DEBUGOUT("ioctl: SIOCGI2C (Get I2C Data)");
1035 error = copyin(ifr->ifr_data, &i2c, sizeof(i2c));
1038 if ((i2c.dev_addr != 0xA0) || (i2c.dev_addr != 0xA2)){
1042 hw->phy.ops.read_i2c_byte(hw, i2c.offset,
1043 i2c.dev_addr, i2c.data);
1044 error = copyout(&i2c, ifr->ifr_data, sizeof(i2c));
1048 IOCTL_DEBUGOUT1("ioctl: UNKNOWN (0x%X)\n", (int)command);
1049 error = ether_ioctl(ifp, command, data);
1056 /*********************************************************************
1059 * This routine is used in two ways. It is used by the stack as
1060 * init entry point in network interface structure. It is also used
1061 * by the driver as a hw/sw initialization routine to get to a
1064 * return 0 on success, positive on failure
1065 **********************************************************************/
1066 #define IXGBE_MHADD_MFS_SHIFT 16
1069 ixgbe_init_locked(struct adapter *adapter)
1071 struct ifnet *ifp = adapter->ifp;
1072 device_t dev = adapter->dev;
1073 struct ixgbe_hw *hw = &adapter->hw;
1074 u32 k, txdctl, mhadd, gpie;
1077 mtx_assert(&adapter->core_mtx, MA_OWNED);
1078 INIT_DEBUGOUT("ixgbe_init: begin");
1079 hw->adapter_stopped = FALSE;
1080 ixgbe_stop_adapter(hw);
1081 callout_stop(&adapter->timer);
1083 /* reprogram the RAR[0] in case user changed it. */
1084 ixgbe_set_rar(hw, 0, adapter->hw.mac.addr, 0, IXGBE_RAH_AV);
1086 /* Get the latest mac address, User can use a LAA */
1087 bcopy(IF_LLADDR(adapter->ifp), hw->mac.addr,
1088 IXGBE_ETH_LENGTH_OF_ADDRESS);
1089 ixgbe_set_rar(hw, 0, hw->mac.addr, 0, 1);
1090 hw->addr_ctrl.rar_used_count = 1;
1092 /* Set the various hardware offload abilities */
1093 ifp->if_hwassist = 0;
1094 if (ifp->if_capenable & IFCAP_TSO)
1095 ifp->if_hwassist |= CSUM_TSO;
1096 if (ifp->if_capenable & IFCAP_TXCSUM) {
1097 ifp->if_hwassist |= (CSUM_TCP | CSUM_UDP);
1098 #if __FreeBSD_version >= 800000
1099 if (hw->mac.type != ixgbe_mac_82598EB)
1100 ifp->if_hwassist |= CSUM_SCTP;
1104 /* Prepare transmit descriptors and buffers */
1105 if (ixgbe_setup_transmit_structures(adapter)) {
1106 device_printf(dev,"Could not setup transmit structures\n");
1107 ixgbe_stop(adapter);
1112 ixgbe_initialize_transmit_units(adapter);
1114 /* Setup Multicast table */
1115 ixgbe_set_multi(adapter);
1118 ** Determine the correct mbuf pool
1119 ** for doing jumbo frames
1121 if (adapter->max_frame_size <= 2048)
1122 adapter->rx_mbuf_sz = MCLBYTES;
1123 else if (adapter->max_frame_size <= 4096)
1124 adapter->rx_mbuf_sz = MJUMPAGESIZE;
1125 else if (adapter->max_frame_size <= 9216)
1126 adapter->rx_mbuf_sz = MJUM9BYTES;
1128 adapter->rx_mbuf_sz = MJUM16BYTES;
1130 /* Prepare receive descriptors and buffers */
1131 if (ixgbe_setup_receive_structures(adapter)) {
1132 device_printf(dev,"Could not setup receive structures\n");
1133 ixgbe_stop(adapter);
1137 /* Configure RX settings */
1138 ixgbe_initialize_receive_units(adapter);
1140 gpie = IXGBE_READ_REG(&adapter->hw, IXGBE_GPIE);
1142 /* Enable Fan Failure Interrupt */
1143 gpie |= IXGBE_SDP1_GPIEN;
1145 /* Add for Module detection */
1146 if (hw->mac.type == ixgbe_mac_82599EB)
1147 gpie |= IXGBE_SDP2_GPIEN;
1149 /* Thermal Failure Detection */
1150 if (hw->mac.type == ixgbe_mac_X540)
1151 gpie |= IXGBE_SDP0_GPIEN;
1153 if (adapter->msix > 1) {
1154 /* Enable Enhanced MSIX mode */
1155 gpie |= IXGBE_GPIE_MSIX_MODE;
1156 gpie |= IXGBE_GPIE_EIAME | IXGBE_GPIE_PBA_SUPPORT |
1159 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
1162 if (ifp->if_mtu > ETHERMTU) {
1163 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
1164 mhadd &= ~IXGBE_MHADD_MFS_MASK;
1165 mhadd |= adapter->max_frame_size << IXGBE_MHADD_MFS_SHIFT;
1166 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
1169 /* Now enable all the queues */
1171 for (int i = 0; i < adapter->num_queues; i++) {
1172 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
1173 txdctl |= IXGBE_TXDCTL_ENABLE;
1174 /* Set WTHRESH to 8, burst writeback */
1175 txdctl |= (8 << 16);
1177 * When the internal queue falls below PTHRESH (32),
1178 * start prefetching as long as there are at least
1179 * HTHRESH (1) buffers ready. The values are taken
1180 * from the Intel linux driver 3.8.21.
1181 * Prefetching enables tx line rate even with 1 queue.
1183 txdctl |= (32 << 0) | (1 << 8);
1184 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), txdctl);
1187 for (int i = 0; i < adapter->num_queues; i++) {
1188 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
1189 if (hw->mac.type == ixgbe_mac_82598EB) {
1195 rxdctl &= ~0x3FFFFF;
1198 rxdctl |= IXGBE_RXDCTL_ENABLE;
1199 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), rxdctl);
1200 for (k = 0; k < 10; k++) {
1201 if (IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)) &
1202 IXGBE_RXDCTL_ENABLE)
1210 * In netmap mode, we must preserve the buffers made
1211 * available to userspace before the if_init()
1212 * (this is true by default on the TX side, because
1213 * init makes all buffers available to userspace).
1215 * netmap_reset() and the device specific routines
1216 * (e.g. ixgbe_setup_receive_rings()) map these
1217 * buffers at the end of the NIC ring, so here we
1218 * must set the RDT (tail) register to make sure
1219 * they are not overwritten.
1221 * In this driver the NIC ring starts at RDH = 0,
1222 * RDT points to the last slot available for reception (?),
1223 * so RDT = num_rx_desc - 1 means the whole ring is available.
1225 if (ifp->if_capenable & IFCAP_NETMAP) {
1226 struct netmap_adapter *na = NA(adapter->ifp);
1227 struct netmap_kring *kring = &na->rx_rings[i];
1228 int t = na->num_rx_desc - 1 - kring->nr_hwavail;
1230 IXGBE_WRITE_REG(hw, IXGBE_RDT(i), t);
1232 #endif /* DEV_NETMAP */
1233 IXGBE_WRITE_REG(hw, IXGBE_RDT(i), adapter->num_rx_desc - 1);
1236 /* Set up VLAN support and filter */
1237 ixgbe_setup_vlan_hw_support(adapter);
1239 /* Enable Receive engine */
1240 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1241 if (hw->mac.type == ixgbe_mac_82598EB)
1242 rxctrl |= IXGBE_RXCTRL_DMBYPS;
1243 rxctrl |= IXGBE_RXCTRL_RXEN;
1244 ixgbe_enable_rx_dma(hw, rxctrl);
1246 callout_reset(&adapter->timer, hz, ixgbe_local_timer, adapter);
1248 /* Set up MSI/X routing */
1249 if (ixgbe_enable_msix) {
1250 ixgbe_configure_ivars(adapter);
1251 /* Set up auto-mask */
1252 if (hw->mac.type == ixgbe_mac_82598EB)
1253 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
1255 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
1256 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
1258 } else { /* Simple settings for Legacy/MSI */
1259 ixgbe_set_ivar(adapter, 0, 0, 0);
1260 ixgbe_set_ivar(adapter, 0, 0, 1);
1261 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
1265 /* Init Flow director */
1266 if (hw->mac.type != ixgbe_mac_82598EB) {
1267 u32 hdrm = 32 << fdir_pballoc;
1269 hw->mac.ops.setup_rxpba(hw, 0, hdrm, PBA_STRATEGY_EQUAL);
1270 ixgbe_init_fdir_signature_82599(&adapter->hw, fdir_pballoc);
1275 ** Check on any SFP devices that
1276 ** need to be kick-started
1278 if (hw->phy.type == ixgbe_phy_none) {
1279 int err = hw->phy.ops.identify(hw);
1280 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
1282 "Unsupported SFP+ module type was detected.\n");
1287 /* Set moderation on the Link interrupt */
1288 IXGBE_WRITE_REG(hw, IXGBE_EITR(adapter->linkvec), IXGBE_LINK_ITR);
1290 /* Config/Enable Link */
1291 ixgbe_config_link(adapter);
1293 /* Hardware Packet Buffer & Flow Control setup */
1295 u32 rxpb, frame, size, tmp;
1297 frame = adapter->max_frame_size;
1299 /* Calculate High Water */
1300 if (hw->mac.type == ixgbe_mac_X540)
1301 tmp = IXGBE_DV_X540(frame, frame);
1303 tmp = IXGBE_DV(frame, frame);
1304 size = IXGBE_BT2KB(tmp);
1305 rxpb = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0)) >> 10;
1306 hw->fc.high_water[0] = rxpb - size;
1308 /* Now calculate Low Water */
1309 if (hw->mac.type == ixgbe_mac_X540)
1310 tmp = IXGBE_LOW_DV_X540(frame);
1312 tmp = IXGBE_LOW_DV(frame);
1313 hw->fc.low_water[0] = IXGBE_BT2KB(tmp);
1315 hw->fc.requested_mode = adapter->fc;
1316 hw->fc.pause_time = IXGBE_FC_PAUSE;
1317 hw->fc.send_xon = TRUE;
1319 /* Initialize the FC settings */
1322 /* And now turn on interrupts */
1323 ixgbe_enable_intr(adapter);
1325 /* Now inform the stack we're ready */
1326 ifp->if_drv_flags |= IFF_DRV_RUNNING;
1332 ixgbe_init(void *arg)
1334 struct adapter *adapter = arg;
1336 IXGBE_CORE_LOCK(adapter);
1337 ixgbe_init_locked(adapter);
1338 IXGBE_CORE_UNLOCK(adapter);
1345 ** MSIX Interrupt Handlers and Tasklets
1350 ixgbe_enable_queue(struct adapter *adapter, u32 vector)
1352 struct ixgbe_hw *hw = &adapter->hw;
1353 u64 queue = (u64)(1 << vector);
1356 if (hw->mac.type == ixgbe_mac_82598EB) {
1357 mask = (IXGBE_EIMS_RTX_QUEUE & queue);
1358 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1360 mask = (queue & 0xFFFFFFFF);
1362 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
1363 mask = (queue >> 32);
1365 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1370 ixgbe_disable_queue(struct adapter *adapter, u32 vector)
1372 struct ixgbe_hw *hw = &adapter->hw;
1373 u64 queue = (u64)(1 << vector);
1376 if (hw->mac.type == ixgbe_mac_82598EB) {
1377 mask = (IXGBE_EIMS_RTX_QUEUE & queue);
1378 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1380 mask = (queue & 0xFFFFFFFF);
1382 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
1383 mask = (queue >> 32);
1385 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1390 ixgbe_rearm_queues(struct adapter *adapter, u64 queues)
1394 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1395 mask = (IXGBE_EIMS_RTX_QUEUE & queues);
1396 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
1398 mask = (queues & 0xFFFFFFFF);
1399 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
1400 mask = (queues >> 32);
1401 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
1407 ixgbe_handle_que(void *context, int pending)
1409 struct ix_queue *que = context;
1410 struct adapter *adapter = que->adapter;
1411 struct tx_ring *txr = que->txr;
1412 struct ifnet *ifp = adapter->ifp;
1415 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1416 more = ixgbe_rxeof(que);
1419 #ifndef IXGBE_LEGACY_TX
1420 if (!drbr_empty(ifp, txr->br))
1421 ixgbe_mq_start_locked(ifp, txr, NULL);
1423 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1424 ixgbe_start_locked(txr, ifp);
1426 IXGBE_TX_UNLOCK(txr);
1428 taskqueue_enqueue(que->tq, &que->que_task);
1433 /* Reenable this interrupt */
1434 ixgbe_enable_queue(adapter, que->msix);
1439 /*********************************************************************
1441 * Legacy Interrupt Service routine
1443 **********************************************************************/
1446 ixgbe_legacy_irq(void *arg)
1448 struct ix_queue *que = arg;
1449 struct adapter *adapter = que->adapter;
1450 struct ixgbe_hw *hw = &adapter->hw;
1451 struct tx_ring *txr = adapter->tx_rings;
1452 bool more_tx, more_rx;
1453 u32 reg_eicr, loop = MAX_LOOP;
1456 reg_eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
1459 if (reg_eicr == 0) {
1460 ixgbe_enable_intr(adapter);
1464 more_rx = ixgbe_rxeof(que);
1468 more_tx = ixgbe_txeof(txr);
1469 } while (loop-- && more_tx);
1470 IXGBE_TX_UNLOCK(txr);
1472 if (more_rx || more_tx)
1473 taskqueue_enqueue(que->tq, &que->que_task);
1475 /* Check for fan failure */
1476 if ((hw->phy.media_type == ixgbe_media_type_copper) &&
1477 (reg_eicr & IXGBE_EICR_GPI_SDP1)) {
1478 device_printf(adapter->dev, "\nCRITICAL: FAN FAILURE!! "
1479 "REPLACE IMMEDIATELY!!\n");
1480 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EICR_GPI_SDP1);
1483 /* Link status change */
1484 if (reg_eicr & IXGBE_EICR_LSC)
1485 taskqueue_enqueue(adapter->tq, &adapter->link_task);
1487 ixgbe_enable_intr(adapter);
1492 /*********************************************************************
1494 * MSIX Queue Interrupt Service routine
1496 **********************************************************************/
1498 ixgbe_msix_que(void *arg)
1500 struct ix_queue *que = arg;
1501 struct adapter *adapter = que->adapter;
1502 struct tx_ring *txr = que->txr;
1503 struct rx_ring *rxr = que->rxr;
1504 bool more_tx, more_rx;
1507 ixgbe_disable_queue(adapter, que->msix);
1510 more_rx = ixgbe_rxeof(que);
1513 more_tx = ixgbe_txeof(txr);
1515 ** Make certain that if the stack
1516 ** has anything queued the task gets
1517 ** scheduled to handle it.
1519 #ifdef IXGBE_LEGACY_TX
1520 if (!IFQ_DRV_IS_EMPTY(&adapter->ifp->if_snd))
1522 if (!drbr_empty(adapter->ifp, txr->br))
1525 IXGBE_TX_UNLOCK(txr);
1529 if (ixgbe_enable_aim == FALSE)
1532 ** Do Adaptive Interrupt Moderation:
1533 ** - Write out last calculated setting
1534 ** - Calculate based on average size over
1535 ** the last interval.
1537 if (que->eitr_setting)
1538 IXGBE_WRITE_REG(&adapter->hw,
1539 IXGBE_EITR(que->msix), que->eitr_setting);
1541 que->eitr_setting = 0;
1543 /* Idle, do nothing */
1544 if ((txr->bytes == 0) && (rxr->bytes == 0))
1547 if ((txr->bytes) && (txr->packets))
1548 newitr = txr->bytes/txr->packets;
1549 if ((rxr->bytes) && (rxr->packets))
1550 newitr = max(newitr,
1551 (rxr->bytes / rxr->packets));
1552 newitr += 24; /* account for hardware frame, crc */
1554 /* set an upper boundary */
1555 newitr = min(newitr, 3000);
1557 /* Be nice to the mid range */
1558 if ((newitr > 300) && (newitr < 1200))
1559 newitr = (newitr / 3);
1561 newitr = (newitr / 2);
1563 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
1564 newitr |= newitr << 16;
1566 newitr |= IXGBE_EITR_CNT_WDIS;
1568 /* save for next interrupt */
1569 que->eitr_setting = newitr;
1578 if (more_tx || more_rx)
1579 taskqueue_enqueue(que->tq, &que->que_task);
1580 else /* Reenable this interrupt */
1581 ixgbe_enable_queue(adapter, que->msix);
1587 ixgbe_msix_link(void *arg)
1589 struct adapter *adapter = arg;
1590 struct ixgbe_hw *hw = &adapter->hw;
1593 ++adapter->link_irq;
1595 /* First get the cause */
1596 reg_eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1597 /* Clear interrupt with write */
1598 IXGBE_WRITE_REG(hw, IXGBE_EICR, reg_eicr);
1600 /* Link status change */
1601 if (reg_eicr & IXGBE_EICR_LSC)
1602 taskqueue_enqueue(adapter->tq, &adapter->link_task);
1604 if (adapter->hw.mac.type != ixgbe_mac_82598EB) {
1606 if (reg_eicr & IXGBE_EICR_FLOW_DIR) {
1607 /* This is probably overkill :) */
1608 if (!atomic_cmpset_int(&adapter->fdir_reinit, 0, 1))
1610 /* Disable the interrupt */
1611 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EICR_FLOW_DIR);
1612 taskqueue_enqueue(adapter->tq, &adapter->fdir_task);
1615 if (reg_eicr & IXGBE_EICR_ECC) {
1616 device_printf(adapter->dev, "\nCRITICAL: ECC ERROR!! "
1617 "Please Reboot!!\n");
1618 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
1621 if (reg_eicr & IXGBE_EICR_GPI_SDP1) {
1622 /* Clear the interrupt */
1623 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1624 taskqueue_enqueue(adapter->tq, &adapter->msf_task);
1625 } else if (reg_eicr & IXGBE_EICR_GPI_SDP2) {
1626 /* Clear the interrupt */
1627 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1628 taskqueue_enqueue(adapter->tq, &adapter->mod_task);
1632 /* Check for fan failure */
1633 if ((hw->device_id == IXGBE_DEV_ID_82598AT) &&
1634 (reg_eicr & IXGBE_EICR_GPI_SDP1)) {
1635 device_printf(adapter->dev, "\nCRITICAL: FAN FAILURE!! "
1636 "REPLACE IMMEDIATELY!!\n");
1637 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1640 /* Check for over temp condition */
1641 if ((hw->mac.type == ixgbe_mac_X540) &&
1642 (reg_eicr & IXGBE_EICR_GPI_SDP0)) {
1643 device_printf(adapter->dev, "\nCRITICAL: OVER TEMP!! "
1644 "PHY IS SHUT DOWN!!\n");
1645 device_printf(adapter->dev, "System shutdown required\n");
1646 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP0);
1649 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
1653 /*********************************************************************
1655 * Media Ioctl callback
1657 * This routine is called whenever the user queries the status of
1658 * the interface using ifconfig.
1660 **********************************************************************/
1662 ixgbe_media_status(struct ifnet * ifp, struct ifmediareq * ifmr)
1664 struct adapter *adapter = ifp->if_softc;
1666 INIT_DEBUGOUT("ixgbe_media_status: begin");
1667 IXGBE_CORE_LOCK(adapter);
1668 ixgbe_update_link_status(adapter);
1670 ifmr->ifm_status = IFM_AVALID;
1671 ifmr->ifm_active = IFM_ETHER;
1673 if (!adapter->link_active) {
1674 IXGBE_CORE_UNLOCK(adapter);
1678 ifmr->ifm_status |= IFM_ACTIVE;
1680 switch (adapter->link_speed) {
1681 case IXGBE_LINK_SPEED_100_FULL:
1682 ifmr->ifm_active |= IFM_100_TX | IFM_FDX;
1684 case IXGBE_LINK_SPEED_1GB_FULL:
1685 ifmr->ifm_active |= IFM_1000_SX | IFM_FDX;
1687 case IXGBE_LINK_SPEED_10GB_FULL:
1688 ifmr->ifm_active |= adapter->optics | IFM_FDX;
1692 IXGBE_CORE_UNLOCK(adapter);
1697 /*********************************************************************
1699 * Media Ioctl callback
1701 * This routine is called when the user changes speed/duplex using
1702 * media/mediopt option with ifconfig.
1704 **********************************************************************/
1706 ixgbe_media_change(struct ifnet * ifp)
1708 struct adapter *adapter = ifp->if_softc;
1709 struct ifmedia *ifm = &adapter->media;
1711 INIT_DEBUGOUT("ixgbe_media_change: begin");
1713 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1716 switch (IFM_SUBTYPE(ifm->ifm_media)) {
1718 adapter->hw.phy.autoneg_advertised =
1719 IXGBE_LINK_SPEED_100_FULL |
1720 IXGBE_LINK_SPEED_1GB_FULL |
1721 IXGBE_LINK_SPEED_10GB_FULL;
1724 device_printf(adapter->dev, "Only auto media type\n");
1731 /*********************************************************************
1733 * This routine maps the mbufs to tx descriptors, allowing the
1734 * TX engine to transmit the packets.
1735 * - return 0 on success, positive on failure
1737 **********************************************************************/
1740 ixgbe_xmit(struct tx_ring *txr, struct mbuf **m_headp)
1742 struct adapter *adapter = txr->adapter;
1743 u32 olinfo_status = 0, cmd_type_len;
1744 int i, j, error, nsegs;
1747 struct mbuf *m_head;
1748 bus_dma_segment_t segs[adapter->num_segs];
1750 struct ixgbe_tx_buf *txbuf;
1751 union ixgbe_adv_tx_desc *txd = NULL;
1755 /* Basic descriptor defines */
1756 cmd_type_len = (IXGBE_ADVTXD_DTYP_DATA |
1757 IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT);
1759 if (m_head->m_flags & M_VLANTAG)
1760 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
1763 * Important to capture the first descriptor
1764 * used because it will contain the index of
1765 * the one we tell the hardware to report back
1767 first = txr->next_avail_desc;
1768 txbuf = &txr->tx_buffers[first];
1772 * Map the packet for DMA.
1775 error = bus_dmamap_load_mbuf_sg(txr->txtag, map,
1776 *m_headp, segs, &nsegs, BUS_DMA_NOWAIT);
1778 if (__predict_false(error)) {
1783 /* Try it again? - one try */
1784 if (remap == TRUE) {
1786 m = m_defrag(*m_headp, M_NOWAIT);
1788 adapter->mbuf_defrag_failed++;
1798 txr->no_tx_dma_setup++;
1801 txr->no_tx_dma_setup++;
1808 /* Make certain there are enough descriptors */
1809 if (nsegs > txr->tx_avail - 2) {
1810 txr->no_desc_avail++;
1811 bus_dmamap_unload(txr->txtag, map);
1817 ** Set up the appropriate offload context
1818 ** this will consume the first descriptor
1820 error = ixgbe_tx_ctx_setup(txr, m_head, &cmd_type_len, &olinfo_status);
1821 if (__predict_false(error)) {
1822 if (error == ENOBUFS)
1828 /* Do the flow director magic */
1829 if ((txr->atr_sample) && (!adapter->fdir_reinit)) {
1831 if (txr->atr_count >= atr_sample_rate) {
1832 ixgbe_atr(txr, m_head);
1838 i = txr->next_avail_desc;
1839 for (j = 0; j < nsegs; j++) {
1843 txbuf = &txr->tx_buffers[i];
1844 txd = &txr->tx_base[i];
1845 seglen = segs[j].ds_len;
1846 segaddr = htole64(segs[j].ds_addr);
1848 txd->read.buffer_addr = segaddr;
1849 txd->read.cmd_type_len = htole32(txr->txd_cmd |
1850 cmd_type_len |seglen);
1851 txd->read.olinfo_status = htole32(olinfo_status);
1853 if (++i == txr->num_desc)
1857 txd->read.cmd_type_len |=
1858 htole32(IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS);
1859 txr->tx_avail -= nsegs;
1860 txr->next_avail_desc = i;
1862 txbuf->m_head = m_head;
1864 ** Here we swap the map so the last descriptor,
1865 ** which gets the completion interrupt has the
1866 ** real map, and the first descriptor gets the
1867 ** unused map from this descriptor.
1869 txr->tx_buffers[first].map = txbuf->map;
1871 bus_dmamap_sync(txr->txtag, map, BUS_DMASYNC_PREWRITE);
1873 /* Set the EOP descriptor that will be marked done */
1874 txbuf = &txr->tx_buffers[first];
1877 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
1878 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1880 * Advance the Transmit Descriptor Tail (Tdt), this tells the
1881 * hardware that this frame is available to transmit.
1883 ++txr->total_packets;
1884 IXGBE_WRITE_REG(&adapter->hw, IXGBE_TDT(txr->me), i);
1891 ixgbe_set_promisc(struct adapter *adapter)
1894 struct ifnet *ifp = adapter->ifp;
1896 reg_rctl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1897 reg_rctl &= (~IXGBE_FCTRL_UPE);
1898 reg_rctl &= (~IXGBE_FCTRL_MPE);
1899 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, reg_rctl);
1901 if (ifp->if_flags & IFF_PROMISC) {
1902 reg_rctl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1903 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, reg_rctl);
1904 } else if (ifp->if_flags & IFF_ALLMULTI) {
1905 reg_rctl |= IXGBE_FCTRL_MPE;
1906 reg_rctl &= ~IXGBE_FCTRL_UPE;
1907 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, reg_rctl);
1913 /*********************************************************************
1916 * This routine is called whenever multicast address list is updated.
1918 **********************************************************************/
1919 #define IXGBE_RAR_ENTRIES 16
1922 ixgbe_set_multi(struct adapter *adapter)
1927 struct ifmultiaddr *ifma;
1929 struct ifnet *ifp = adapter->ifp;
1931 IOCTL_DEBUGOUT("ixgbe_set_multi: begin");
1934 bzero(mta, sizeof(u8) * IXGBE_ETH_LENGTH_OF_ADDRESS *
1935 MAX_NUM_MULTICAST_ADDRESSES);
1937 #if __FreeBSD_version < 800000
1940 if_maddr_rlock(ifp);
1942 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1943 if (ifma->ifma_addr->sa_family != AF_LINK)
1945 if (mcnt == MAX_NUM_MULTICAST_ADDRESSES)
1947 bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr),
1948 &mta[mcnt * IXGBE_ETH_LENGTH_OF_ADDRESS],
1949 IXGBE_ETH_LENGTH_OF_ADDRESS);
1952 #if __FreeBSD_version < 800000
1953 IF_ADDR_UNLOCK(ifp);
1955 if_maddr_runlock(ifp);
1958 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1959 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1960 if (ifp->if_flags & IFF_PROMISC)
1961 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1962 else if (mcnt >= MAX_NUM_MULTICAST_ADDRESSES ||
1963 ifp->if_flags & IFF_ALLMULTI) {
1964 fctrl |= IXGBE_FCTRL_MPE;
1965 fctrl &= ~IXGBE_FCTRL_UPE;
1967 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1969 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1971 if (mcnt < MAX_NUM_MULTICAST_ADDRESSES) {
1973 ixgbe_update_mc_addr_list(&adapter->hw,
1974 update_ptr, mcnt, ixgbe_mc_array_itr, TRUE);
1981 * This is an iterator function now needed by the multicast
1982 * shared code. It simply feeds the shared code routine the
1983 * addresses in the array of ixgbe_set_multi() one by one.
1986 ixgbe_mc_array_itr(struct ixgbe_hw *hw, u8 **update_ptr, u32 *vmdq)
1988 u8 *addr = *update_ptr;
1992 newptr = addr + IXGBE_ETH_LENGTH_OF_ADDRESS;
1993 *update_ptr = newptr;
1998 /*********************************************************************
2001 * This routine checks for link status,updates statistics,
2002 * and runs the watchdog check.
2004 **********************************************************************/
2007 ixgbe_local_timer(void *arg)
2009 struct adapter *adapter = arg;
2010 device_t dev = adapter->dev;
2011 struct ix_queue *que = adapter->queues;
2012 struct tx_ring *txr = adapter->tx_rings;
2013 int hung = 0, paused = 0;
2015 mtx_assert(&adapter->core_mtx, MA_OWNED);
2017 /* Check for pluggable optics */
2018 if (adapter->sfp_probe)
2019 if (!ixgbe_sfp_probe(adapter))
2020 goto out; /* Nothing to do */
2022 ixgbe_update_link_status(adapter);
2023 ixgbe_update_stats_counters(adapter);
2026 * If the interface has been paused
2027 * then don't do the watchdog check
2029 if (IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)
2033 ** Check the TX queues status
2034 ** - watchdog only if all queues show hung
2036 for (int i = 0; i < adapter->num_queues; i++, que++, txr++) {
2037 if ((txr->queue_status == IXGBE_QUEUE_HUNG) &&
2040 else if (txr->queue_status == IXGBE_QUEUE_WORKING)
2041 taskqueue_enqueue(que->tq, &que->que_task);
2043 /* Only truely watchdog if all queues show hung */
2044 if (hung == adapter->num_queues)
2048 ixgbe_rearm_queues(adapter, adapter->que_mask);
2049 callout_reset(&adapter->timer, hz, ixgbe_local_timer, adapter);
2053 device_printf(adapter->dev, "Watchdog timeout -- resetting\n");
2054 device_printf(dev,"Queue(%d) tdh = %d, hw tdt = %d\n", txr->me,
2055 IXGBE_READ_REG(&adapter->hw, IXGBE_TDH(txr->me)),
2056 IXGBE_READ_REG(&adapter->hw, IXGBE_TDT(txr->me)));
2057 device_printf(dev,"TX(%d) desc avail = %d,"
2058 "Next TX to Clean = %d\n",
2059 txr->me, txr->tx_avail, txr->next_to_clean);
2060 adapter->ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
2061 adapter->watchdog_events++;
2062 ixgbe_init_locked(adapter);
2066 ** Note: this routine updates the OS on the link state
2067 ** the real check of the hardware only happens with
2068 ** a link interrupt.
2071 ixgbe_update_link_status(struct adapter *adapter)
2073 struct ifnet *ifp = adapter->ifp;
2074 device_t dev = adapter->dev;
2077 if (adapter->link_up){
2078 if (adapter->link_active == FALSE) {
2080 device_printf(dev,"Link is up %d Gbps %s \n",
2081 ((adapter->link_speed == 128)? 10:1),
2083 adapter->link_active = TRUE;
2084 /* Update any Flow Control changes */
2085 ixgbe_fc_enable(&adapter->hw);
2086 if_link_state_change(ifp, LINK_STATE_UP);
2088 } else { /* Link down */
2089 if (adapter->link_active == TRUE) {
2091 device_printf(dev,"Link is Down\n");
2092 if_link_state_change(ifp, LINK_STATE_DOWN);
2093 adapter->link_active = FALSE;
2101 /*********************************************************************
2103 * This routine disables all traffic on the adapter by issuing a
2104 * global reset on the MAC and deallocates TX/RX buffers.
2106 **********************************************************************/
2109 ixgbe_stop(void *arg)
2112 struct adapter *adapter = arg;
2113 struct ixgbe_hw *hw = &adapter->hw;
2116 mtx_assert(&adapter->core_mtx, MA_OWNED);
2118 INIT_DEBUGOUT("ixgbe_stop: begin\n");
2119 ixgbe_disable_intr(adapter);
2120 callout_stop(&adapter->timer);
2122 /* Let the stack know...*/
2123 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
2126 hw->adapter_stopped = FALSE;
2127 ixgbe_stop_adapter(hw);
2128 /* Turn off the laser */
2129 if (hw->phy.multispeed_fiber)
2130 ixgbe_disable_tx_laser(hw);
2132 /* reprogram the RAR[0] in case user changed it. */
2133 ixgbe_set_rar(&adapter->hw, 0, adapter->hw.mac.addr, 0, IXGBE_RAH_AV);
2139 /*********************************************************************
2141 * Determine hardware revision.
2143 **********************************************************************/
2145 ixgbe_identify_hardware(struct adapter *adapter)
2147 device_t dev = adapter->dev;
2148 struct ixgbe_hw *hw = &adapter->hw;
2150 /* Save off the information about this board */
2151 hw->vendor_id = pci_get_vendor(dev);
2152 hw->device_id = pci_get_device(dev);
2153 hw->revision_id = pci_read_config(dev, PCIR_REVID, 1);
2154 hw->subsystem_vendor_id =
2155 pci_read_config(dev, PCIR_SUBVEND_0, 2);
2156 hw->subsystem_device_id =
2157 pci_read_config(dev, PCIR_SUBDEV_0, 2);
2159 /* We need this here to set the num_segs below */
2160 ixgbe_set_mac_type(hw);
2162 /* Pick up the 82599 and VF settings */
2163 if (hw->mac.type != ixgbe_mac_82598EB) {
2164 hw->phy.smart_speed = ixgbe_smart_speed;
2165 adapter->num_segs = IXGBE_82599_SCATTER;
2167 adapter->num_segs = IXGBE_82598_SCATTER;
2172 /*********************************************************************
2174 * Determine optic type
2176 **********************************************************************/
2178 ixgbe_setup_optics(struct adapter *adapter)
2180 struct ixgbe_hw *hw = &adapter->hw;
2183 layer = ixgbe_get_supported_physical_layer(hw);
2185 if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_T) {
2186 adapter->optics = IFM_10G_T;
2190 if (layer & IXGBE_PHYSICAL_LAYER_1000BASE_T) {
2191 adapter->optics = IFM_1000_T;
2195 if (layer & IXGBE_PHYSICAL_LAYER_1000BASE_SX) {
2196 adapter->optics = IFM_1000_SX;
2200 if (layer & (IXGBE_PHYSICAL_LAYER_10GBASE_LR |
2201 IXGBE_PHYSICAL_LAYER_10GBASE_LRM)) {
2202 adapter->optics = IFM_10G_LR;
2206 if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_SR) {
2207 adapter->optics = IFM_10G_SR;
2211 if (layer & IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU) {
2212 adapter->optics = IFM_10G_TWINAX;
2216 if (layer & (IXGBE_PHYSICAL_LAYER_10GBASE_KX4 |
2217 IXGBE_PHYSICAL_LAYER_10GBASE_CX4)) {
2218 adapter->optics = IFM_10G_CX4;
2222 /* If we get here just set the default */
2223 adapter->optics = IFM_ETHER | IFM_AUTO;
2227 /*********************************************************************
2229 * Setup the Legacy or MSI Interrupt handler
2231 **********************************************************************/
2233 ixgbe_allocate_legacy(struct adapter *adapter)
2235 device_t dev = adapter->dev;
2236 struct ix_queue *que = adapter->queues;
2237 #ifndef IXGBE_LEGACY_TX
2238 struct tx_ring *txr = adapter->tx_rings;
2243 if (adapter->msix == 1)
2246 /* We allocate a single interrupt resource */
2247 adapter->res = bus_alloc_resource_any(dev,
2248 SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE);
2249 if (adapter->res == NULL) {
2250 device_printf(dev, "Unable to allocate bus resource: "
2256 * Try allocating a fast interrupt and the associated deferred
2257 * processing contexts.
2259 #ifndef IXGBE_LEGACY_TX
2260 TASK_INIT(&txr->txq_task, 0, ixgbe_deferred_mq_start, txr);
2262 TASK_INIT(&que->que_task, 0, ixgbe_handle_que, que);
2263 que->tq = taskqueue_create_fast("ixgbe_que", M_NOWAIT,
2264 taskqueue_thread_enqueue, &que->tq);
2265 taskqueue_start_threads(&que->tq, 1, PI_NET, "%s ixq",
2266 device_get_nameunit(adapter->dev));
2268 /* Tasklets for Link, SFP and Multispeed Fiber */
2269 TASK_INIT(&adapter->link_task, 0, ixgbe_handle_link, adapter);
2270 TASK_INIT(&adapter->mod_task, 0, ixgbe_handle_mod, adapter);
2271 TASK_INIT(&adapter->msf_task, 0, ixgbe_handle_msf, adapter);
2273 TASK_INIT(&adapter->fdir_task, 0, ixgbe_reinit_fdir, adapter);
2275 adapter->tq = taskqueue_create_fast("ixgbe_link", M_NOWAIT,
2276 taskqueue_thread_enqueue, &adapter->tq);
2277 taskqueue_start_threads(&adapter->tq, 1, PI_NET, "%s linkq",
2278 device_get_nameunit(adapter->dev));
2280 if ((error = bus_setup_intr(dev, adapter->res,
2281 INTR_TYPE_NET | INTR_MPSAFE, NULL, ixgbe_legacy_irq,
2282 que, &adapter->tag)) != 0) {
2283 device_printf(dev, "Failed to register fast interrupt "
2284 "handler: %d\n", error);
2285 taskqueue_free(que->tq);
2286 taskqueue_free(adapter->tq);
2291 /* For simplicity in the handlers */
2292 adapter->que_mask = IXGBE_EIMS_ENABLE_MASK;
2298 /*********************************************************************
2300 * Setup MSIX Interrupt resources and handlers
2302 **********************************************************************/
2304 ixgbe_allocate_msix(struct adapter *adapter)
2306 device_t dev = adapter->dev;
2307 struct ix_queue *que = adapter->queues;
2308 struct tx_ring *txr = adapter->tx_rings;
2309 int error, rid, vector = 0;
2311 for (int i = 0; i < adapter->num_queues; i++, vector++, que++, txr++) {
2313 que->res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
2314 RF_SHAREABLE | RF_ACTIVE);
2315 if (que->res == NULL) {
2316 device_printf(dev,"Unable to allocate"
2317 " bus resource: que interrupt [%d]\n", vector);
2320 /* Set the handler function */
2321 error = bus_setup_intr(dev, que->res,
2322 INTR_TYPE_NET | INTR_MPSAFE, NULL,
2323 ixgbe_msix_que, que, &que->tag);
2326 device_printf(dev, "Failed to register QUE handler");
2329 #if __FreeBSD_version >= 800504
2330 bus_describe_intr(dev, que->res, que->tag, "que %d", i);
2333 adapter->que_mask |= (u64)(1 << que->msix);
2335 ** Bind the msix vector, and thus the
2336 ** ring to the corresponding cpu.
2338 if (adapter->num_queues > 1)
2339 bus_bind_intr(dev, que->res, i);
2341 #ifndef IXGBE_LEGACY_TX
2342 TASK_INIT(&txr->txq_task, 0, ixgbe_deferred_mq_start, txr);
2344 TASK_INIT(&que->que_task, 0, ixgbe_handle_que, que);
2345 que->tq = taskqueue_create_fast("ixgbe_que", M_NOWAIT,
2346 taskqueue_thread_enqueue, &que->tq);
2347 taskqueue_start_threads(&que->tq, 1, PI_NET, "%s que",
2348 device_get_nameunit(adapter->dev));
2353 adapter->res = bus_alloc_resource_any(dev,
2354 SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE);
2355 if (!adapter->res) {
2356 device_printf(dev,"Unable to allocate"
2357 " bus resource: Link interrupt [%d]\n", rid);
2360 /* Set the link handler function */
2361 error = bus_setup_intr(dev, adapter->res,
2362 INTR_TYPE_NET | INTR_MPSAFE, NULL,
2363 ixgbe_msix_link, adapter, &adapter->tag);
2365 adapter->res = NULL;
2366 device_printf(dev, "Failed to register LINK handler");
2369 #if __FreeBSD_version >= 800504
2370 bus_describe_intr(dev, adapter->res, adapter->tag, "link");
2372 adapter->linkvec = vector;
2373 /* Tasklets for Link, SFP and Multispeed Fiber */
2374 TASK_INIT(&adapter->link_task, 0, ixgbe_handle_link, adapter);
2375 TASK_INIT(&adapter->mod_task, 0, ixgbe_handle_mod, adapter);
2376 TASK_INIT(&adapter->msf_task, 0, ixgbe_handle_msf, adapter);
2378 TASK_INIT(&adapter->fdir_task, 0, ixgbe_reinit_fdir, adapter);
2380 adapter->tq = taskqueue_create_fast("ixgbe_link", M_NOWAIT,
2381 taskqueue_thread_enqueue, &adapter->tq);
2382 taskqueue_start_threads(&adapter->tq, 1, PI_NET, "%s linkq",
2383 device_get_nameunit(adapter->dev));
2389 * Setup Either MSI/X or MSI
2392 ixgbe_setup_msix(struct adapter *adapter)
2394 device_t dev = adapter->dev;
2395 int rid, want, queues, msgs;
2397 /* Override by tuneable */
2398 if (ixgbe_enable_msix == 0)
2401 /* First try MSI/X */
2402 rid = PCIR_BAR(MSIX_82598_BAR);
2403 adapter->msix_mem = bus_alloc_resource_any(dev,
2404 SYS_RES_MEMORY, &rid, RF_ACTIVE);
2405 if (!adapter->msix_mem) {
2406 rid += 4; /* 82599 maps in higher BAR */
2407 adapter->msix_mem = bus_alloc_resource_any(dev,
2408 SYS_RES_MEMORY, &rid, RF_ACTIVE);
2410 if (!adapter->msix_mem) {
2411 /* May not be enabled */
2412 device_printf(adapter->dev,
2413 "Unable to map MSIX table \n");
2417 msgs = pci_msix_count(dev);
2418 if (msgs == 0) { /* system has msix disabled */
2419 bus_release_resource(dev, SYS_RES_MEMORY,
2420 rid, adapter->msix_mem);
2421 adapter->msix_mem = NULL;
2425 /* Figure out a reasonable auto config value */
2426 queues = (mp_ncpus > (msgs-1)) ? (msgs-1) : mp_ncpus;
2428 if (ixgbe_num_queues != 0)
2429 queues = ixgbe_num_queues;
2430 /* Set max queues to 8 when autoconfiguring */
2431 else if ((ixgbe_num_queues == 0) && (queues > 8))
2435 ** Want one vector (RX/TX pair) per queue
2436 ** plus an additional for Link.
2442 device_printf(adapter->dev,
2443 "MSIX Configuration Problem, "
2444 "%d vectors but %d queues wanted!\n",
2446 return (0); /* Will go to Legacy setup */
2448 if ((msgs) && pci_alloc_msix(dev, &msgs) == 0) {
2449 device_printf(adapter->dev,
2450 "Using MSIX interrupts with %d vectors\n", msgs);
2451 adapter->num_queues = queues;
2455 msgs = pci_msi_count(dev);
2456 if (msgs == 1 && pci_alloc_msi(dev, &msgs) == 0)
2457 device_printf(adapter->dev,"Using an MSI interrupt\n");
2459 device_printf(adapter->dev,"Using a Legacy interrupt\n");
2465 ixgbe_allocate_pci_resources(struct adapter *adapter)
2468 device_t dev = adapter->dev;
2471 adapter->pci_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
2474 if (!(adapter->pci_mem)) {
2475 device_printf(dev,"Unable to allocate bus resource: memory\n");
2479 adapter->osdep.mem_bus_space_tag =
2480 rman_get_bustag(adapter->pci_mem);
2481 adapter->osdep.mem_bus_space_handle =
2482 rman_get_bushandle(adapter->pci_mem);
2483 adapter->hw.hw_addr = (u8 *) &adapter->osdep.mem_bus_space_handle;
2485 /* Legacy defaults */
2486 adapter->num_queues = 1;
2487 adapter->hw.back = &adapter->osdep;
2490 ** Now setup MSI or MSI/X, should
2491 ** return us the number of supported
2492 ** vectors. (Will be 1 for MSI)
2494 adapter->msix = ixgbe_setup_msix(adapter);
2499 ixgbe_free_pci_resources(struct adapter * adapter)
2501 struct ix_queue *que = adapter->queues;
2502 device_t dev = adapter->dev;
2505 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
2506 memrid = PCIR_BAR(MSIX_82598_BAR);
2508 memrid = PCIR_BAR(MSIX_82599_BAR);
2511 ** There is a slight possibility of a failure mode
2512 ** in attach that will result in entering this function
2513 ** before interrupt resources have been initialized, and
2514 ** in that case we do not want to execute the loops below
2515 ** We can detect this reliably by the state of the adapter
2518 if (adapter->res == NULL)
2522 ** Release all msix queue resources:
2524 for (int i = 0; i < adapter->num_queues; i++, que++) {
2525 rid = que->msix + 1;
2526 if (que->tag != NULL) {
2527 bus_teardown_intr(dev, que->res, que->tag);
2530 if (que->res != NULL)
2531 bus_release_resource(dev, SYS_RES_IRQ, rid, que->res);
2535 /* Clean the Legacy or Link interrupt last */
2536 if (adapter->linkvec) /* we are doing MSIX */
2537 rid = adapter->linkvec + 1;
2539 (adapter->msix != 0) ? (rid = 1):(rid = 0);
2541 if (adapter->tag != NULL) {
2542 bus_teardown_intr(dev, adapter->res, adapter->tag);
2543 adapter->tag = NULL;
2545 if (adapter->res != NULL)
2546 bus_release_resource(dev, SYS_RES_IRQ, rid, adapter->res);
2550 pci_release_msi(dev);
2552 if (adapter->msix_mem != NULL)
2553 bus_release_resource(dev, SYS_RES_MEMORY,
2554 memrid, adapter->msix_mem);
2556 if (adapter->pci_mem != NULL)
2557 bus_release_resource(dev, SYS_RES_MEMORY,
2558 PCIR_BAR(0), adapter->pci_mem);
2563 /*********************************************************************
2565 * Setup networking device structure and register an interface.
2567 **********************************************************************/
2569 ixgbe_setup_interface(device_t dev, struct adapter *adapter)
2571 struct ixgbe_hw *hw = &adapter->hw;
2574 INIT_DEBUGOUT("ixgbe_setup_interface: begin");
2576 ifp = adapter->ifp = if_alloc(IFT_ETHER);
2578 device_printf(dev, "can not allocate ifnet structure\n");
2581 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
2582 ifp->if_baudrate = 1000000000;
2583 ifp->if_init = ixgbe_init;
2584 ifp->if_softc = adapter;
2585 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
2586 ifp->if_ioctl = ixgbe_ioctl;
2587 #ifndef IXGBE_LEGACY_TX
2588 ifp->if_transmit = ixgbe_mq_start;
2589 ifp->if_qflush = ixgbe_qflush;
2591 ifp->if_start = ixgbe_start;
2592 IFQ_SET_MAXLEN(&ifp->if_snd, adapter->num_tx_desc - 2);
2595 ether_ifattach(ifp, adapter->hw.mac.addr);
2597 adapter->max_frame_size =
2598 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
2601 * Tell the upper layer(s) we support long frames.
2603 ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
2605 ifp->if_capabilities |= IFCAP_HWCSUM | IFCAP_TSO | IFCAP_VLAN_HWCSUM;
2606 ifp->if_capabilities |= IFCAP_JUMBO_MTU;
2607 ifp->if_capabilities |= IFCAP_LRO;
2608 ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING
2611 ifp->if_capenable = ifp->if_capabilities;
2614 ** Don't turn this on by default, if vlans are
2615 ** created on another pseudo device (eg. lagg)
2616 ** then vlan events are not passed thru, breaking
2617 ** operation, but with HW FILTER off it works. If
2618 ** using vlans directly on the ixgbe driver you can
2619 ** enable this and get full hardware tag filtering.
2621 ifp->if_capabilities |= IFCAP_VLAN_HWFILTER;
2624 * Specify the media types supported by this adapter and register
2625 * callbacks to update media and link information
2627 ifmedia_init(&adapter->media, IFM_IMASK, ixgbe_media_change,
2628 ixgbe_media_status);
2629 ifmedia_add(&adapter->media, IFM_ETHER | adapter->optics, 0, NULL);
2630 ifmedia_set(&adapter->media, IFM_ETHER | adapter->optics);
2631 if (hw->device_id == IXGBE_DEV_ID_82598AT) {
2632 ifmedia_add(&adapter->media,
2633 IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL);
2634 ifmedia_add(&adapter->media,
2635 IFM_ETHER | IFM_1000_T, 0, NULL);
2637 ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL);
2638 ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO);
2644 ixgbe_config_link(struct adapter *adapter)
2646 struct ixgbe_hw *hw = &adapter->hw;
2647 u32 autoneg, err = 0;
2648 bool sfp, negotiate;
2650 sfp = ixgbe_is_sfp(hw);
2653 if (hw->phy.multispeed_fiber) {
2654 hw->mac.ops.setup_sfp(hw);
2655 ixgbe_enable_tx_laser(hw);
2656 taskqueue_enqueue(adapter->tq, &adapter->msf_task);
2658 taskqueue_enqueue(adapter->tq, &adapter->mod_task);
2660 if (hw->mac.ops.check_link)
2661 err = ixgbe_check_link(hw, &adapter->link_speed,
2662 &adapter->link_up, FALSE);
2665 autoneg = hw->phy.autoneg_advertised;
2666 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
2667 err = hw->mac.ops.get_link_capabilities(hw,
2668 &autoneg, &negotiate);
2671 if (hw->mac.ops.setup_link)
2672 err = hw->mac.ops.setup_link(hw,
2673 autoneg, adapter->link_up);
2679 /********************************************************************
2680 * Manage DMA'able memory.
2681 *******************************************************************/
2683 ixgbe_dmamap_cb(void *arg, bus_dma_segment_t * segs, int nseg, int error)
2687 *(bus_addr_t *) arg = segs->ds_addr;
2692 ixgbe_dma_malloc(struct adapter *adapter, bus_size_t size,
2693 struct ixgbe_dma_alloc *dma, int mapflags)
2695 device_t dev = adapter->dev;
2698 r = bus_dma_tag_create(bus_get_dma_tag(adapter->dev), /* parent */
2699 DBA_ALIGN, 0, /* alignment, bounds */
2700 BUS_SPACE_MAXADDR, /* lowaddr */
2701 BUS_SPACE_MAXADDR, /* highaddr */
2702 NULL, NULL, /* filter, filterarg */
2705 size, /* maxsegsize */
2706 BUS_DMA_ALLOCNOW, /* flags */
2707 NULL, /* lockfunc */
2708 NULL, /* lockfuncarg */
2711 device_printf(dev,"ixgbe_dma_malloc: bus_dma_tag_create failed; "
2715 r = bus_dmamem_alloc(dma->dma_tag, (void **)&dma->dma_vaddr,
2716 BUS_DMA_NOWAIT, &dma->dma_map);
2718 device_printf(dev,"ixgbe_dma_malloc: bus_dmamem_alloc failed; "
2722 r = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
2726 mapflags | BUS_DMA_NOWAIT);
2728 device_printf(dev,"ixgbe_dma_malloc: bus_dmamap_load failed; "
2732 dma->dma_size = size;
2735 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
2737 bus_dma_tag_destroy(dma->dma_tag);
2739 dma->dma_map = NULL;
2740 dma->dma_tag = NULL;
2745 ixgbe_dma_free(struct adapter *adapter, struct ixgbe_dma_alloc *dma)
2747 bus_dmamap_sync(dma->dma_tag, dma->dma_map,
2748 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
2749 bus_dmamap_unload(dma->dma_tag, dma->dma_map);
2750 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
2751 bus_dma_tag_destroy(dma->dma_tag);
2755 /*********************************************************************
2757 * Allocate memory for the transmit and receive rings, and then
2758 * the descriptors associated with each, called only once at attach.
2760 **********************************************************************/
2762 ixgbe_allocate_queues(struct adapter *adapter)
2764 device_t dev = adapter->dev;
2765 struct ix_queue *que;
2766 struct tx_ring *txr;
2767 struct rx_ring *rxr;
2768 int rsize, tsize, error = IXGBE_SUCCESS;
2769 int txconf = 0, rxconf = 0;
2771 /* First allocate the top level queue structs */
2772 if (!(adapter->queues =
2773 (struct ix_queue *) malloc(sizeof(struct ix_queue) *
2774 adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2775 device_printf(dev, "Unable to allocate queue memory\n");
2780 /* First allocate the TX ring struct memory */
2781 if (!(adapter->tx_rings =
2782 (struct tx_ring *) malloc(sizeof(struct tx_ring) *
2783 adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2784 device_printf(dev, "Unable to allocate TX ring memory\n");
2789 /* Next allocate the RX */
2790 if (!(adapter->rx_rings =
2791 (struct rx_ring *) malloc(sizeof(struct rx_ring) *
2792 adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2793 device_printf(dev, "Unable to allocate RX ring memory\n");
2798 /* For the ring itself */
2799 tsize = roundup2(adapter->num_tx_desc *
2800 sizeof(union ixgbe_adv_tx_desc), DBA_ALIGN);
2803 * Now set up the TX queues, txconf is needed to handle the
2804 * possibility that things fail midcourse and we need to
2805 * undo memory gracefully
2807 for (int i = 0; i < adapter->num_queues; i++, txconf++) {
2808 /* Set up some basics */
2809 txr = &adapter->tx_rings[i];
2810 txr->adapter = adapter;
2812 txr->num_desc = adapter->num_tx_desc;
2814 /* Initialize the TX side lock */
2815 snprintf(txr->mtx_name, sizeof(txr->mtx_name), "%s:tx(%d)",
2816 device_get_nameunit(dev), txr->me);
2817 mtx_init(&txr->tx_mtx, txr->mtx_name, NULL, MTX_DEF);
2819 if (ixgbe_dma_malloc(adapter, tsize,
2820 &txr->txdma, BUS_DMA_NOWAIT)) {
2822 "Unable to allocate TX Descriptor memory\n");
2826 txr->tx_base = (union ixgbe_adv_tx_desc *)txr->txdma.dma_vaddr;
2827 bzero((void *)txr->tx_base, tsize);
2829 /* Now allocate transmit buffers for the ring */
2830 if (ixgbe_allocate_transmit_buffers(txr)) {
2832 "Critical Failure setting up transmit buffers\n");
2836 #ifndef IXGBE_LEGACY_TX
2837 /* Allocate a buf ring */
2838 txr->br = buf_ring_alloc(IXGBE_BR_SIZE, M_DEVBUF,
2839 M_WAITOK, &txr->tx_mtx);
2840 if (txr->br == NULL) {
2842 "Critical Failure setting up buf ring\n");
2850 * Next the RX queues...
2852 rsize = roundup2(adapter->num_rx_desc *
2853 sizeof(union ixgbe_adv_rx_desc), DBA_ALIGN);
2854 for (int i = 0; i < adapter->num_queues; i++, rxconf++) {
2855 rxr = &adapter->rx_rings[i];
2856 /* Set up some basics */
2857 rxr->adapter = adapter;
2859 rxr->num_desc = adapter->num_rx_desc;
2861 /* Initialize the RX side lock */
2862 snprintf(rxr->mtx_name, sizeof(rxr->mtx_name), "%s:rx(%d)",
2863 device_get_nameunit(dev), rxr->me);
2864 mtx_init(&rxr->rx_mtx, rxr->mtx_name, NULL, MTX_DEF);
2866 if (ixgbe_dma_malloc(adapter, rsize,
2867 &rxr->rxdma, BUS_DMA_NOWAIT)) {
2869 "Unable to allocate RxDescriptor memory\n");
2873 rxr->rx_base = (union ixgbe_adv_rx_desc *)rxr->rxdma.dma_vaddr;
2874 bzero((void *)rxr->rx_base, rsize);
2876 /* Allocate receive buffers for the ring*/
2877 if (ixgbe_allocate_receive_buffers(rxr)) {
2879 "Critical Failure setting up receive buffers\n");
2886 ** Finally set up the queue holding structs
2888 for (int i = 0; i < adapter->num_queues; i++) {
2889 que = &adapter->queues[i];
2890 que->adapter = adapter;
2891 que->txr = &adapter->tx_rings[i];
2892 que->rxr = &adapter->rx_rings[i];
2898 for (rxr = adapter->rx_rings; rxconf > 0; rxr++, rxconf--)
2899 ixgbe_dma_free(adapter, &rxr->rxdma);
2901 for (txr = adapter->tx_rings; txconf > 0; txr++, txconf--)
2902 ixgbe_dma_free(adapter, &txr->txdma);
2903 free(adapter->rx_rings, M_DEVBUF);
2905 free(adapter->tx_rings, M_DEVBUF);
2907 free(adapter->queues, M_DEVBUF);
2912 /*********************************************************************
2914 * Allocate memory for tx_buffer structures. The tx_buffer stores all
2915 * the information needed to transmit a packet on the wire. This is
2916 * called only once at attach, setup is done every reset.
2918 **********************************************************************/
2920 ixgbe_allocate_transmit_buffers(struct tx_ring *txr)
2922 struct adapter *adapter = txr->adapter;
2923 device_t dev = adapter->dev;
2924 struct ixgbe_tx_buf *txbuf;
2928 * Setup DMA descriptor areas.
2930 if ((error = bus_dma_tag_create(
2931 bus_get_dma_tag(adapter->dev), /* parent */
2932 1, 0, /* alignment, bounds */
2933 BUS_SPACE_MAXADDR, /* lowaddr */
2934 BUS_SPACE_MAXADDR, /* highaddr */
2935 NULL, NULL, /* filter, filterarg */
2936 IXGBE_TSO_SIZE, /* maxsize */
2937 adapter->num_segs, /* nsegments */
2938 PAGE_SIZE, /* maxsegsize */
2940 NULL, /* lockfunc */
2941 NULL, /* lockfuncarg */
2943 device_printf(dev,"Unable to allocate TX DMA tag\n");
2947 if (!(txr->tx_buffers =
2948 (struct ixgbe_tx_buf *) malloc(sizeof(struct ixgbe_tx_buf) *
2949 adapter->num_tx_desc, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2950 device_printf(dev, "Unable to allocate tx_buffer memory\n");
2955 /* Create the descriptor buffer dma maps */
2956 txbuf = txr->tx_buffers;
2957 for (i = 0; i < adapter->num_tx_desc; i++, txbuf++) {
2958 error = bus_dmamap_create(txr->txtag, 0, &txbuf->map);
2960 device_printf(dev, "Unable to create TX DMA map\n");
2967 /* We free all, it handles case where we are in the middle */
2968 ixgbe_free_transmit_structures(adapter);
2972 /*********************************************************************
2974 * Initialize a transmit ring.
2976 **********************************************************************/
2978 ixgbe_setup_transmit_ring(struct tx_ring *txr)
2980 struct adapter *adapter = txr->adapter;
2981 struct ixgbe_tx_buf *txbuf;
2984 struct netmap_adapter *na = NA(adapter->ifp);
2985 struct netmap_slot *slot;
2986 #endif /* DEV_NETMAP */
2988 /* Clear the old ring contents */
2992 * (under lock): if in netmap mode, do some consistency
2993 * checks and set slot to entry 0 of the netmap ring.
2995 slot = netmap_reset(na, NR_TX, txr->me, 0);
2996 #endif /* DEV_NETMAP */
2997 bzero((void *)txr->tx_base,
2998 (sizeof(union ixgbe_adv_tx_desc)) * adapter->num_tx_desc);
3000 txr->next_avail_desc = 0;
3001 txr->next_to_clean = 0;
3003 /* Free any existing tx buffers. */
3004 txbuf = txr->tx_buffers;
3005 for (i = 0; i < txr->num_desc; i++, txbuf++) {
3006 if (txbuf->m_head != NULL) {
3007 bus_dmamap_sync(txr->txtag, txbuf->map,
3008 BUS_DMASYNC_POSTWRITE);
3009 bus_dmamap_unload(txr->txtag, txbuf->map);
3010 m_freem(txbuf->m_head);
3011 txbuf->m_head = NULL;
3015 * In netmap mode, set the map for the packet buffer.
3016 * NOTE: Some drivers (not this one) also need to set
3017 * the physical buffer address in the NIC ring.
3018 * Slots in the netmap ring (indexed by "si") are
3019 * kring->nkr_hwofs positions "ahead" wrt the
3020 * corresponding slot in the NIC ring. In some drivers
3021 * (not here) nkr_hwofs can be negative. Function
3022 * netmap_idx_n2k() handles wraparounds properly.
3025 int si = netmap_idx_n2k(&na->tx_rings[txr->me], i);
3026 netmap_load_map(txr->txtag, txbuf->map, NMB(slot + si));
3028 #endif /* DEV_NETMAP */
3029 /* Clear the EOP descriptor pointer */
3034 /* Set the rate at which we sample packets */
3035 if (adapter->hw.mac.type != ixgbe_mac_82598EB)
3036 txr->atr_sample = atr_sample_rate;
3039 /* Set number of descriptors available */
3040 txr->tx_avail = adapter->num_tx_desc;
3042 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
3043 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
3044 IXGBE_TX_UNLOCK(txr);
3047 /*********************************************************************
3049 * Initialize all transmit rings.
3051 **********************************************************************/
3053 ixgbe_setup_transmit_structures(struct adapter *adapter)
3055 struct tx_ring *txr = adapter->tx_rings;
3057 for (int i = 0; i < adapter->num_queues; i++, txr++)
3058 ixgbe_setup_transmit_ring(txr);
3063 /*********************************************************************
3065 * Enable transmit unit.
3067 **********************************************************************/
3069 ixgbe_initialize_transmit_units(struct adapter *adapter)
3071 struct tx_ring *txr = adapter->tx_rings;
3072 struct ixgbe_hw *hw = &adapter->hw;
3074 /* Setup the Base and Length of the Tx Descriptor Ring */
3076 for (int i = 0; i < adapter->num_queues; i++, txr++) {
3077 u64 tdba = txr->txdma.dma_paddr;
3080 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(i),
3081 (tdba & 0x00000000ffffffffULL));
3082 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(i), (tdba >> 32));
3083 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(i),
3084 adapter->num_tx_desc * sizeof(union ixgbe_adv_tx_desc));
3086 /* Setup the HW Tx Head and Tail descriptor pointers */
3087 IXGBE_WRITE_REG(hw, IXGBE_TDH(i), 0);
3088 IXGBE_WRITE_REG(hw, IXGBE_TDT(i), 0);
3090 /* Setup Transmit Descriptor Cmd Settings */
3091 txr->txd_cmd = IXGBE_TXD_CMD_IFCS;
3092 txr->queue_status = IXGBE_QUEUE_IDLE;
3094 /* Set the processing limit */
3095 txr->process_limit = ixgbe_tx_process_limit;
3097 /* Disable Head Writeback */
3098 switch (hw->mac.type) {
3099 case ixgbe_mac_82598EB:
3100 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i));
3102 case ixgbe_mac_82599EB:
3103 case ixgbe_mac_X540:
3105 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
3108 txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
3109 switch (hw->mac.type) {
3110 case ixgbe_mac_82598EB:
3111 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(i), txctrl);
3113 case ixgbe_mac_82599EB:
3114 case ixgbe_mac_X540:
3116 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), txctrl);
3122 if (hw->mac.type != ixgbe_mac_82598EB) {
3123 u32 dmatxctl, rttdcs;
3124 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3125 dmatxctl |= IXGBE_DMATXCTL_TE;
3126 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3127 /* Disable arbiter to set MTQC */
3128 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3129 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3130 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3131 IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
3132 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3133 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3139 /*********************************************************************
3141 * Free all transmit rings.
3143 **********************************************************************/
3145 ixgbe_free_transmit_structures(struct adapter *adapter)
3147 struct tx_ring *txr = adapter->tx_rings;
3149 for (int i = 0; i < adapter->num_queues; i++, txr++) {
3151 ixgbe_free_transmit_buffers(txr);
3152 ixgbe_dma_free(adapter, &txr->txdma);
3153 IXGBE_TX_UNLOCK(txr);
3154 IXGBE_TX_LOCK_DESTROY(txr);
3156 free(adapter->tx_rings, M_DEVBUF);
3159 /*********************************************************************
3161 * Free transmit ring related data structures.
3163 **********************************************************************/
3165 ixgbe_free_transmit_buffers(struct tx_ring *txr)
3167 struct adapter *adapter = txr->adapter;
3168 struct ixgbe_tx_buf *tx_buffer;
3171 INIT_DEBUGOUT("free_transmit_ring: begin");
3173 if (txr->tx_buffers == NULL)
3176 tx_buffer = txr->tx_buffers;
3177 for (i = 0; i < adapter->num_tx_desc; i++, tx_buffer++) {
3178 if (tx_buffer->m_head != NULL) {
3179 bus_dmamap_sync(txr->txtag, tx_buffer->map,
3180 BUS_DMASYNC_POSTWRITE);
3181 bus_dmamap_unload(txr->txtag,
3183 m_freem(tx_buffer->m_head);
3184 tx_buffer->m_head = NULL;
3185 if (tx_buffer->map != NULL) {
3186 bus_dmamap_destroy(txr->txtag,
3188 tx_buffer->map = NULL;
3190 } else if (tx_buffer->map != NULL) {
3191 bus_dmamap_unload(txr->txtag,
3193 bus_dmamap_destroy(txr->txtag,
3195 tx_buffer->map = NULL;
3198 #ifdef IXGBE_LEGACY_TX
3199 if (txr->br != NULL)
3200 buf_ring_free(txr->br, M_DEVBUF);
3202 if (txr->tx_buffers != NULL) {
3203 free(txr->tx_buffers, M_DEVBUF);
3204 txr->tx_buffers = NULL;
3206 if (txr->txtag != NULL) {
3207 bus_dma_tag_destroy(txr->txtag);
3213 /*********************************************************************
3215 * Advanced Context Descriptor setup for VLAN, CSUM or TSO
3217 **********************************************************************/
3220 ixgbe_tx_ctx_setup(struct tx_ring *txr, struct mbuf *mp,
3221 u32 *cmd_type_len, u32 *olinfo_status)
3223 struct ixgbe_adv_tx_context_desc *TXD;
3224 struct ether_vlan_header *eh;
3226 struct ip6_hdr *ip6;
3227 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
3228 int ehdrlen, ip_hlen = 0;
3232 int ctxd = txr->next_avail_desc;
3235 /* First check if TSO is to be used */
3236 if (mp->m_pkthdr.csum_flags & CSUM_TSO)
3237 return (ixgbe_tso_setup(txr, mp, cmd_type_len, olinfo_status));
3239 if ((mp->m_pkthdr.csum_flags & CSUM_OFFLOAD) == 0)
3242 /* Indicate the whole packet as payload when not doing TSO */
3243 *olinfo_status |= mp->m_pkthdr.len << IXGBE_ADVTXD_PAYLEN_SHIFT;
3245 /* Now ready a context descriptor */
3246 TXD = (struct ixgbe_adv_tx_context_desc *) &txr->tx_base[ctxd];
3249 ** In advanced descriptors the vlan tag must
3250 ** be placed into the context descriptor. Hence
3251 ** we need to make one even if not doing offloads.
3253 if (mp->m_flags & M_VLANTAG) {
3254 vtag = htole16(mp->m_pkthdr.ether_vtag);
3255 vlan_macip_lens |= (vtag << IXGBE_ADVTXD_VLAN_SHIFT);
3256 } else if (offload == FALSE) /* ... no offload to do */
3260 * Determine where frame payload starts.
3261 * Jump over vlan headers if already present,
3262 * helpful for QinQ too.
3264 eh = mtod(mp, struct ether_vlan_header *);
3265 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
3266 etype = ntohs(eh->evl_proto);
3267 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
3269 etype = ntohs(eh->evl_encap_proto);
3270 ehdrlen = ETHER_HDR_LEN;
3273 /* Set the ether header length */
3274 vlan_macip_lens |= ehdrlen << IXGBE_ADVTXD_MACLEN_SHIFT;
3278 ip = (struct ip *)(mp->m_data + ehdrlen);
3279 ip_hlen = ip->ip_hl << 2;
3281 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3283 case ETHERTYPE_IPV6:
3284 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen);
3285 ip_hlen = sizeof(struct ip6_hdr);
3286 /* XXX-BZ this will go badly in case of ext hdrs. */
3287 ipproto = ip6->ip6_nxt;
3288 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV6;
3295 vlan_macip_lens |= ip_hlen;
3296 type_tucmd_mlhl |= IXGBE_ADVTXD_DCMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
3300 if (mp->m_pkthdr.csum_flags & CSUM_TCP)
3301 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3305 if (mp->m_pkthdr.csum_flags & CSUM_UDP)
3306 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_UDP;
3309 #if __FreeBSD_version >= 800000
3311 if (mp->m_pkthdr.csum_flags & CSUM_SCTP)
3312 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
3320 if (offload) /* For the TX descriptor setup */
3321 *olinfo_status |= IXGBE_TXD_POPTS_TXSM << 8;
3323 /* Now copy bits into descriptor */
3324 TXD->vlan_macip_lens = htole32(vlan_macip_lens);
3325 TXD->type_tucmd_mlhl = htole32(type_tucmd_mlhl);
3326 TXD->seqnum_seed = htole32(0);
3327 TXD->mss_l4len_idx = htole32(0);
3329 /* We've consumed the first desc, adjust counters */
3330 if (++ctxd == txr->num_desc)
3332 txr->next_avail_desc = ctxd;
3338 /**********************************************************************
3340 * Setup work for hardware segmentation offload (TSO) on
3341 * adapters using advanced tx descriptors
3343 **********************************************************************/
3345 ixgbe_tso_setup(struct tx_ring *txr, struct mbuf *mp,
3346 u32 *cmd_type_len, u32 *olinfo_status)
3348 struct ixgbe_adv_tx_context_desc *TXD;
3349 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
3350 u32 mss_l4len_idx = 0, paylen;
3351 u16 vtag = 0, eh_type;
3352 int ctxd, ehdrlen, ip_hlen, tcp_hlen;
3353 struct ether_vlan_header *eh;
3355 struct ip6_hdr *ip6;
3364 * Determine where frame payload starts.
3365 * Jump over vlan headers if already present
3367 eh = mtod(mp, struct ether_vlan_header *);
3368 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
3369 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
3370 eh_type = eh->evl_proto;
3372 ehdrlen = ETHER_HDR_LEN;
3373 eh_type = eh->evl_encap_proto;
3376 switch (ntohs(eh_type)) {
3378 case ETHERTYPE_IPV6:
3379 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen);
3380 /* XXX-BZ For now we do not pretend to support ext. hdrs. */
3381 if (ip6->ip6_nxt != IPPROTO_TCP)
3383 ip_hlen = sizeof(struct ip6_hdr);
3384 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen);
3385 th = (struct tcphdr *)((caddr_t)ip6 + ip_hlen);
3386 th->th_sum = in6_cksum_pseudo(ip6, 0, IPPROTO_TCP, 0);
3387 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV6;
3392 ip = (struct ip *)(mp->m_data + ehdrlen);
3393 if (ip->ip_p != IPPROTO_TCP)
3396 ip_hlen = ip->ip_hl << 2;
3397 th = (struct tcphdr *)((caddr_t)ip + ip_hlen);
3398 th->th_sum = in_pseudo(ip->ip_src.s_addr,
3399 ip->ip_dst.s_addr, htons(IPPROTO_TCP));
3400 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3401 /* Tell transmit desc to also do IPv4 checksum. */
3402 *olinfo_status |= IXGBE_TXD_POPTS_IXSM << 8;
3406 panic("%s: CSUM_TSO but no supported IP version (0x%04x)",
3407 __func__, ntohs(eh_type));
3411 ctxd = txr->next_avail_desc;
3412 TXD = (struct ixgbe_adv_tx_context_desc *) &txr->tx_base[ctxd];
3414 tcp_hlen = th->th_off << 2;
3416 /* This is used in the transmit desc in encap */
3417 paylen = mp->m_pkthdr.len - ehdrlen - ip_hlen - tcp_hlen;
3419 /* VLAN MACLEN IPLEN */
3420 if (mp->m_flags & M_VLANTAG) {
3421 vtag = htole16(mp->m_pkthdr.ether_vtag);
3422 vlan_macip_lens |= (vtag << IXGBE_ADVTXD_VLAN_SHIFT);
3425 vlan_macip_lens |= ehdrlen << IXGBE_ADVTXD_MACLEN_SHIFT;
3426 vlan_macip_lens |= ip_hlen;
3427 TXD->vlan_macip_lens = htole32(vlan_macip_lens);
3429 /* ADV DTYPE TUCMD */
3430 type_tucmd_mlhl |= IXGBE_ADVTXD_DCMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
3431 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3432 TXD->type_tucmd_mlhl = htole32(type_tucmd_mlhl);
3435 mss_l4len_idx |= (mp->m_pkthdr.tso_segsz << IXGBE_ADVTXD_MSS_SHIFT);
3436 mss_l4len_idx |= (tcp_hlen << IXGBE_ADVTXD_L4LEN_SHIFT);
3437 TXD->mss_l4len_idx = htole32(mss_l4len_idx);
3439 TXD->seqnum_seed = htole32(0);
3441 if (++ctxd == txr->num_desc)
3445 txr->next_avail_desc = ctxd;
3446 *cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
3447 *olinfo_status |= IXGBE_TXD_POPTS_TXSM << 8;
3448 *olinfo_status |= paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
3455 ** This routine parses packet headers so that Flow
3456 ** Director can make a hashed filter table entry
3457 ** allowing traffic flows to be identified and kept
3458 ** on the same cpu. This would be a performance
3459 ** hit, but we only do it at IXGBE_FDIR_RATE of
3463 ixgbe_atr(struct tx_ring *txr, struct mbuf *mp)
3465 struct adapter *adapter = txr->adapter;
3466 struct ix_queue *que;
3470 struct ether_vlan_header *eh;
3471 union ixgbe_atr_hash_dword input = {.dword = 0};
3472 union ixgbe_atr_hash_dword common = {.dword = 0};
3473 int ehdrlen, ip_hlen;
3476 eh = mtod(mp, struct ether_vlan_header *);
3477 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
3478 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
3479 etype = eh->evl_proto;
3481 ehdrlen = ETHER_HDR_LEN;
3482 etype = eh->evl_encap_proto;
3485 /* Only handling IPv4 */
3486 if (etype != htons(ETHERTYPE_IP))
3489 ip = (struct ip *)(mp->m_data + ehdrlen);
3490 ip_hlen = ip->ip_hl << 2;
3492 /* check if we're UDP or TCP */
3495 th = (struct tcphdr *)((caddr_t)ip + ip_hlen);
3496 /* src and dst are inverted */
3497 common.port.dst ^= th->th_sport;
3498 common.port.src ^= th->th_dport;
3499 input.formatted.flow_type ^= IXGBE_ATR_FLOW_TYPE_TCPV4;
3502 uh = (struct udphdr *)((caddr_t)ip + ip_hlen);
3503 /* src and dst are inverted */
3504 common.port.dst ^= uh->uh_sport;
3505 common.port.src ^= uh->uh_dport;
3506 input.formatted.flow_type ^= IXGBE_ATR_FLOW_TYPE_UDPV4;
3512 input.formatted.vlan_id = htobe16(mp->m_pkthdr.ether_vtag);
3513 if (mp->m_pkthdr.ether_vtag)
3514 common.flex_bytes ^= htons(ETHERTYPE_VLAN);
3516 common.flex_bytes ^= etype;
3517 common.ip ^= ip->ip_src.s_addr ^ ip->ip_dst.s_addr;
3519 que = &adapter->queues[txr->me];
3521 ** This assumes the Rx queue and Tx
3522 ** queue are bound to the same CPU
3524 ixgbe_fdir_add_signature_filter_82599(&adapter->hw,
3525 input, common, que->msix);
3527 #endif /* IXGBE_FDIR */
3529 /**********************************************************************
3531 * Examine each tx_buffer in the used queue. If the hardware is done
3532 * processing the packet then free associated resources. The
3533 * tx_buffer is put back on the free queue.
3535 **********************************************************************/
3537 ixgbe_txeof(struct tx_ring *txr)
3539 struct adapter *adapter = txr->adapter;
3540 struct ifnet *ifp = adapter->ifp;
3541 u32 work, processed = 0;
3542 u16 limit = txr->process_limit;
3543 struct ixgbe_tx_buf *buf;
3544 union ixgbe_adv_tx_desc *txd;
3546 mtx_assert(&txr->tx_mtx, MA_OWNED);
3549 if (ifp->if_capenable & IFCAP_NETMAP) {
3550 struct netmap_adapter *na = NA(ifp);
3551 struct netmap_kring *kring = &na->tx_rings[txr->me];
3553 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
3554 BUS_DMASYNC_POSTREAD);
3556 * In netmap mode, all the work is done in the context
3557 * of the client thread. Interrupt handlers only wake up
3558 * clients, which may be sleeping on individual rings
3559 * or on a global resource for all rings.
3560 * To implement tx interrupt mitigation, we wake up the client
3561 * thread roughly every half ring, even if the NIC interrupts
3562 * more frequently. This is implemented as follows:
3563 * - ixgbe_txsync() sets kring->nr_kflags with the index of
3564 * the slot that should wake up the thread (nkr_num_slots
3565 * means the user thread should not be woken up);
3566 * - the driver ignores tx interrupts unless netmap_mitigate=0
3567 * or the slot has the DD bit set.
3569 * When the driver has separate locks, we need to
3570 * release and re-acquire txlock to avoid deadlocks.
3571 * XXX see if we can find a better way.
3573 if (!netmap_mitigate ||
3574 (kring->nr_kflags < kring->nkr_num_slots &&
3575 txd[kring->nr_kflags].wb.status & IXGBE_TXD_STAT_DD)) {
3576 kring->nr_kflags = kring->nkr_num_slots;
3577 selwakeuppri(&na->tx_rings[txr->me].si, PI_NET);
3578 IXGBE_TX_UNLOCK(txr);
3579 IXGBE_CORE_LOCK(adapter);
3580 selwakeuppri(&na->tx_si, PI_NET);
3581 IXGBE_CORE_UNLOCK(adapter);
3586 #endif /* DEV_NETMAP */
3588 if (txr->tx_avail == txr->num_desc) {
3589 txr->queue_status = IXGBE_QUEUE_IDLE;
3593 /* Get work starting point */
3594 work = txr->next_to_clean;
3595 buf = &txr->tx_buffers[work];
3596 txd = &txr->tx_base[work];
3597 work -= txr->num_desc; /* The distance to ring end */
3598 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
3599 BUS_DMASYNC_POSTREAD);
3602 union ixgbe_adv_tx_desc *eop= buf->eop;
3603 if (eop == NULL) /* No work */
3606 if ((eop->wb.status & IXGBE_TXD_STAT_DD) == 0)
3607 break; /* I/O not complete */
3611 buf->m_head->m_pkthdr.len;
3612 bus_dmamap_sync(txr->txtag,
3614 BUS_DMASYNC_POSTWRITE);
3615 bus_dmamap_unload(txr->txtag,
3617 m_freem(buf->m_head);
3624 /* We clean the range if multi segment */
3625 while (txd != eop) {
3629 /* wrap the ring? */
3630 if (__predict_false(!work)) {
3631 work -= txr->num_desc;
3632 buf = txr->tx_buffers;
3637 buf->m_head->m_pkthdr.len;
3638 bus_dmamap_sync(txr->txtag,
3640 BUS_DMASYNC_POSTWRITE);
3641 bus_dmamap_unload(txr->txtag,
3643 m_freem(buf->m_head);
3654 txr->watchdog_time = ticks;
3656 /* Try the next packet */
3660 /* reset with a wrap */
3661 if (__predict_false(!work)) {
3662 work -= txr->num_desc;
3663 buf = txr->tx_buffers;
3667 } while (__predict_true(--limit));
3669 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
3670 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
3672 work += txr->num_desc;
3673 txr->next_to_clean = work;
3676 ** Watchdog calculation, we know there's
3677 ** work outstanding or the first return
3678 ** would have been taken, so none processed
3679 ** for too long indicates a hang.
3681 if ((!processed) && ((ticks - txr->watchdog_time) > IXGBE_WATCHDOG))
3682 txr->queue_status = IXGBE_QUEUE_HUNG;
3684 if (txr->tx_avail == txr->num_desc) {
3685 txr->queue_status = IXGBE_QUEUE_IDLE;
3692 /*********************************************************************
3694 * Refresh mbuf buffers for RX descriptor rings
3695 * - now keeps its own state so discards due to resource
3696 * exhaustion are unnecessary, if an mbuf cannot be obtained
3697 * it just returns, keeping its placeholder, thus it can simply
3698 * be recalled to try again.
3700 **********************************************************************/
3702 ixgbe_refresh_mbufs(struct rx_ring *rxr, int limit)
3704 struct adapter *adapter = rxr->adapter;
3705 bus_dma_segment_t seg[1];
3706 struct ixgbe_rx_buf *rxbuf;
3708 int i, j, nsegs, error;
3709 bool refreshed = FALSE;
3711 i = j = rxr->next_to_refresh;
3712 /* Control the loop with one beyond */
3713 if (++j == rxr->num_desc)
3716 while (j != limit) {
3717 rxbuf = &rxr->rx_buffers[i];
3718 if (rxbuf->buf == NULL) {
3719 mp = m_getjcl(M_NOWAIT, MT_DATA,
3720 M_PKTHDR, rxr->mbuf_sz);
3723 if (adapter->max_frame_size <= (MCLBYTES - ETHER_ALIGN))
3724 m_adj(mp, ETHER_ALIGN);
3728 mp->m_pkthdr.len = mp->m_len = rxr->mbuf_sz;
3730 /* If we're dealing with an mbuf that was copied rather
3731 * than replaced, there's no need to go through busdma.
3733 if ((rxbuf->flags & IXGBE_RX_COPY) == 0) {
3734 /* Get the memory mapping */
3735 error = bus_dmamap_load_mbuf_sg(rxr->ptag,
3736 rxbuf->pmap, mp, seg, &nsegs, BUS_DMA_NOWAIT);
3738 printf("Refresh mbufs: payload dmamap load"
3739 " failure - %d\n", error);
3745 bus_dmamap_sync(rxr->ptag, rxbuf->pmap,
3746 BUS_DMASYNC_PREREAD);
3747 rxbuf->addr = rxr->rx_base[i].read.pkt_addr =
3748 htole64(seg[0].ds_addr);
3750 rxr->rx_base[i].read.pkt_addr = rxbuf->addr;
3751 rxbuf->flags &= ~IXGBE_RX_COPY;
3755 /* Next is precalculated */
3757 rxr->next_to_refresh = i;
3758 if (++j == rxr->num_desc)
3762 if (refreshed) /* Update hardware tail index */
3763 IXGBE_WRITE_REG(&adapter->hw,
3764 IXGBE_RDT(rxr->me), rxr->next_to_refresh);
3768 /*********************************************************************
3770 * Allocate memory for rx_buffer structures. Since we use one
3771 * rx_buffer per received packet, the maximum number of rx_buffer's
3772 * that we'll need is equal to the number of receive descriptors
3773 * that we've allocated.
3775 **********************************************************************/
3777 ixgbe_allocate_receive_buffers(struct rx_ring *rxr)
3779 struct adapter *adapter = rxr->adapter;
3780 device_t dev = adapter->dev;
3781 struct ixgbe_rx_buf *rxbuf;
3782 int i, bsize, error;
3784 bsize = sizeof(struct ixgbe_rx_buf) * rxr->num_desc;
3785 if (!(rxr->rx_buffers =
3786 (struct ixgbe_rx_buf *) malloc(bsize,
3787 M_DEVBUF, M_NOWAIT | M_ZERO))) {
3788 device_printf(dev, "Unable to allocate rx_buffer memory\n");
3793 if ((error = bus_dma_tag_create(bus_get_dma_tag(dev), /* parent */
3794 1, 0, /* alignment, bounds */
3795 BUS_SPACE_MAXADDR, /* lowaddr */
3796 BUS_SPACE_MAXADDR, /* highaddr */
3797 NULL, NULL, /* filter, filterarg */
3798 MJUM16BYTES, /* maxsize */
3800 MJUM16BYTES, /* maxsegsize */
3802 NULL, /* lockfunc */
3803 NULL, /* lockfuncarg */
3805 device_printf(dev, "Unable to create RX DMA tag\n");
3809 for (i = 0; i < rxr->num_desc; i++, rxbuf++) {
3810 rxbuf = &rxr->rx_buffers[i];
3811 error = bus_dmamap_create(rxr->ptag,
3812 BUS_DMA_NOWAIT, &rxbuf->pmap);
3814 device_printf(dev, "Unable to create RX dma map\n");
3822 /* Frees all, but can handle partial completion */
3823 ixgbe_free_receive_structures(adapter);
3828 ** Used to detect a descriptor that has
3829 ** been merged by Hardware RSC.
3832 ixgbe_rsc_count(union ixgbe_adv_rx_desc *rx)
3834 return (le32toh(rx->wb.lower.lo_dword.data) &
3835 IXGBE_RXDADV_RSCCNT_MASK) >> IXGBE_RXDADV_RSCCNT_SHIFT;
3838 /*********************************************************************
3840 * Initialize Hardware RSC (LRO) feature on 82599
3841 * for an RX ring, this is toggled by the LRO capability
3842 * even though it is transparent to the stack.
3844 * NOTE: since this HW feature only works with IPV4 and
3845 * our testing has shown soft LRO to be as effective
3846 * I have decided to disable this by default.
3848 **********************************************************************/
3850 ixgbe_setup_hw_rsc(struct rx_ring *rxr)
3852 struct adapter *adapter = rxr->adapter;
3853 struct ixgbe_hw *hw = &adapter->hw;
3854 u32 rscctrl, rdrxctl;
3856 /* If turning LRO/RSC off we need to disable it */
3857 if ((adapter->ifp->if_capenable & IFCAP_LRO) == 0) {
3858 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(rxr->me));
3859 rscctrl &= ~IXGBE_RSCCTL_RSCEN;
3863 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3864 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3865 #ifdef DEV_NETMAP /* crcstrip is optional in netmap */
3866 if (adapter->ifp->if_capenable & IFCAP_NETMAP && !ix_crcstrip)
3867 #endif /* DEV_NETMAP */
3868 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3869 rdrxctl |= IXGBE_RDRXCTL_RSCACKC;
3870 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3872 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(rxr->me));
3873 rscctrl |= IXGBE_RSCCTL_RSCEN;
3875 ** Limit the total number of descriptors that
3876 ** can be combined, so it does not exceed 64K
3878 if (rxr->mbuf_sz == MCLBYTES)
3879 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
3880 else if (rxr->mbuf_sz == MJUMPAGESIZE)
3881 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
3882 else if (rxr->mbuf_sz == MJUM9BYTES)
3883 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
3884 else /* Using 16K cluster */
3885 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
3887 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(rxr->me), rscctrl);
3889 /* Enable TCP header recognition */
3890 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0),
3891 (IXGBE_READ_REG(hw, IXGBE_PSRTYPE(0)) |
3892 IXGBE_PSRTYPE_TCPHDR));
3894 /* Disable RSC for ACK packets */
3895 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3896 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3903 ixgbe_free_receive_ring(struct rx_ring *rxr)
3905 struct ixgbe_rx_buf *rxbuf;
3908 for (i = 0; i < rxr->num_desc; i++) {
3909 rxbuf = &rxr->rx_buffers[i];
3910 if (rxbuf->buf != NULL) {
3911 bus_dmamap_sync(rxr->ptag, rxbuf->pmap,
3912 BUS_DMASYNC_POSTREAD);
3913 bus_dmamap_unload(rxr->ptag, rxbuf->pmap);
3914 rxbuf->buf->m_flags |= M_PKTHDR;
3915 m_freem(rxbuf->buf);
3922 /*********************************************************************
3924 * Initialize a receive ring and its buffers.
3926 **********************************************************************/
3928 ixgbe_setup_receive_ring(struct rx_ring *rxr)
3930 struct adapter *adapter;
3933 struct ixgbe_rx_buf *rxbuf;
3934 bus_dma_segment_t seg[1];
3935 struct lro_ctrl *lro = &rxr->lro;
3936 int rsize, nsegs, error = 0;
3938 struct netmap_adapter *na = NA(rxr->adapter->ifp);
3939 struct netmap_slot *slot;
3940 #endif /* DEV_NETMAP */
3942 adapter = rxr->adapter;
3946 /* Clear the ring contents */
3949 /* same as in ixgbe_setup_transmit_ring() */
3950 slot = netmap_reset(na, NR_RX, rxr->me, 0);
3951 #endif /* DEV_NETMAP */
3952 rsize = roundup2(adapter->num_rx_desc *
3953 sizeof(union ixgbe_adv_rx_desc), DBA_ALIGN);
3954 bzero((void *)rxr->rx_base, rsize);
3955 /* Cache the size */
3956 rxr->mbuf_sz = adapter->rx_mbuf_sz;
3958 /* Free current RX buffer structs and their mbufs */
3959 ixgbe_free_receive_ring(rxr);
3961 /* Now replenish the mbufs */
3962 for (int j = 0; j != rxr->num_desc; ++j) {
3965 rxbuf = &rxr->rx_buffers[j];
3968 * In netmap mode, fill the map and set the buffer
3969 * address in the NIC ring, considering the offset
3970 * between the netmap and NIC rings (see comment in
3971 * ixgbe_setup_transmit_ring() ). No need to allocate
3972 * an mbuf, so end the block with a continue;
3975 int sj = netmap_idx_n2k(&na->rx_rings[rxr->me], j);
3979 addr = PNMB(slot + sj, &paddr);
3980 netmap_load_map(rxr->ptag, rxbuf->pmap, addr);
3981 /* Update descriptor */
3982 rxr->rx_base[j].read.pkt_addr = htole64(paddr);
3985 #endif /* DEV_NETMAP */
3986 rxbuf->buf = m_getjcl(M_NOWAIT, MT_DATA,
3987 M_PKTHDR, adapter->rx_mbuf_sz);
3988 if (rxbuf->buf == NULL) {
3993 mp->m_pkthdr.len = mp->m_len = rxr->mbuf_sz;
3994 /* Get the memory mapping */
3995 error = bus_dmamap_load_mbuf_sg(rxr->ptag,
3996 rxbuf->pmap, mp, seg,
3997 &nsegs, BUS_DMA_NOWAIT);
4000 bus_dmamap_sync(rxr->ptag,
4001 rxbuf->pmap, BUS_DMASYNC_PREREAD);
4002 /* Update descriptor */
4003 rxr->rx_base[j].read.pkt_addr = htole64(seg[0].ds_addr);
4007 /* Setup our descriptor indices */
4008 rxr->next_to_check = 0;
4009 rxr->next_to_refresh = 0;
4010 rxr->lro_enabled = FALSE;
4013 rxr->discard = FALSE;
4014 rxr->vtag_strip = FALSE;
4016 bus_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
4017 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
4020 ** Now set up the LRO interface:
4022 if (ixgbe_rsc_enable)
4023 ixgbe_setup_hw_rsc(rxr);
4024 else if (ifp->if_capenable & IFCAP_LRO) {
4025 int err = tcp_lro_init(lro);
4027 device_printf(dev, "LRO Initialization failed!\n");
4030 INIT_DEBUGOUT("RX Soft LRO Initialized\n");
4031 rxr->lro_enabled = TRUE;
4032 lro->ifp = adapter->ifp;
4035 IXGBE_RX_UNLOCK(rxr);
4039 ixgbe_free_receive_ring(rxr);
4040 IXGBE_RX_UNLOCK(rxr);
4044 /*********************************************************************
4046 * Initialize all receive rings.
4048 **********************************************************************/
4050 ixgbe_setup_receive_structures(struct adapter *adapter)
4052 struct rx_ring *rxr = adapter->rx_rings;
4055 for (j = 0; j < adapter->num_queues; j++, rxr++)
4056 if (ixgbe_setup_receive_ring(rxr))
4062 * Free RX buffers allocated so far, we will only handle
4063 * the rings that completed, the failing case will have
4064 * cleaned up for itself. 'j' failed, so its the terminus.
4066 for (int i = 0; i < j; ++i) {
4067 rxr = &adapter->rx_rings[i];
4068 ixgbe_free_receive_ring(rxr);
4074 /*********************************************************************
4076 * Setup receive registers and features.
4078 **********************************************************************/
4079 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
4081 #define BSIZEPKT_ROUNDUP ((1<<IXGBE_SRRCTL_BSIZEPKT_SHIFT)-1)
4084 ixgbe_initialize_receive_units(struct adapter *adapter)
4086 struct rx_ring *rxr = adapter->rx_rings;
4087 struct ixgbe_hw *hw = &adapter->hw;
4088 struct ifnet *ifp = adapter->ifp;
4089 u32 bufsz, rxctrl, fctrl, srrctl, rxcsum;
4090 u32 reta, mrqc = 0, hlreg, random[10];
4094 * Make sure receives are disabled while
4095 * setting up the descriptor ring
4097 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4098 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL,
4099 rxctrl & ~IXGBE_RXCTRL_RXEN);
4101 /* Enable broadcasts */
4102 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4103 fctrl |= IXGBE_FCTRL_BAM;
4104 fctrl |= IXGBE_FCTRL_DPF;
4105 fctrl |= IXGBE_FCTRL_PMCF;
4106 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4108 /* Set for Jumbo Frames? */
4109 hlreg = IXGBE_READ_REG(hw, IXGBE_HLREG0);
4110 if (ifp->if_mtu > ETHERMTU)
4111 hlreg |= IXGBE_HLREG0_JUMBOEN;
4113 hlreg &= ~IXGBE_HLREG0_JUMBOEN;
4115 /* crcstrip is conditional in netmap (in RDRXCTL too ?) */
4116 if (ifp->if_capenable & IFCAP_NETMAP && !ix_crcstrip)
4117 hlreg &= ~IXGBE_HLREG0_RXCRCSTRP;
4119 hlreg |= IXGBE_HLREG0_RXCRCSTRP;
4120 #endif /* DEV_NETMAP */
4121 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg);
4123 bufsz = (adapter->rx_mbuf_sz +
4124 BSIZEPKT_ROUNDUP) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
4126 for (int i = 0; i < adapter->num_queues; i++, rxr++) {
4127 u64 rdba = rxr->rxdma.dma_paddr;
4129 /* Setup the Base and Length of the Rx Descriptor Ring */
4130 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(i),
4131 (rdba & 0x00000000ffffffffULL));
4132 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(i), (rdba >> 32));
4133 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(i),
4134 adapter->num_rx_desc * sizeof(union ixgbe_adv_rx_desc));
4136 /* Set up the SRRCTL register */
4137 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
4138 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
4139 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
4141 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
4142 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(i), srrctl);
4144 /* Setup the HW Rx Head and Tail Descriptor Pointers */
4145 IXGBE_WRITE_REG(hw, IXGBE_RDH(i), 0);
4146 IXGBE_WRITE_REG(hw, IXGBE_RDT(i), 0);
4148 /* Set the processing limit */
4149 rxr->process_limit = ixgbe_rx_process_limit;
4152 if (adapter->hw.mac.type != ixgbe_mac_82598EB) {
4153 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
4154 IXGBE_PSRTYPE_UDPHDR |
4155 IXGBE_PSRTYPE_IPV4HDR |
4156 IXGBE_PSRTYPE_IPV6HDR;
4157 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
4160 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
4163 if (adapter->num_queues > 1) {
4167 /* set up random bits */
4168 arc4rand(&random, sizeof(random), 0);
4170 /* Set up the redirection table */
4171 for (i = 0, j = 0; i < 128; i++, j++) {
4172 if (j == adapter->num_queues) j = 0;
4173 reta = (reta << 8) | (j * 0x11);
4175 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
4178 /* Now fill our hash function seeds */
4179 for (int i = 0; i < 10; i++)
4180 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), random[i]);
4182 /* Perform hash on these packet types */
4183 mrqc = IXGBE_MRQC_RSSEN
4184 | IXGBE_MRQC_RSS_FIELD_IPV4
4185 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
4186 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
4187 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP
4188 | IXGBE_MRQC_RSS_FIELD_IPV6_EX
4189 | IXGBE_MRQC_RSS_FIELD_IPV6
4190 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
4191 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP
4192 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP;
4193 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
4195 /* RSS and RX IPP Checksum are mutually exclusive */
4196 rxcsum |= IXGBE_RXCSUM_PCSD;
4199 if (ifp->if_capenable & IFCAP_RXCSUM)
4200 rxcsum |= IXGBE_RXCSUM_PCSD;
4202 if (!(rxcsum & IXGBE_RXCSUM_PCSD))
4203 rxcsum |= IXGBE_RXCSUM_IPPCSE;
4205 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
4210 /*********************************************************************
4212 * Free all receive rings.
4214 **********************************************************************/
4216 ixgbe_free_receive_structures(struct adapter *adapter)
4218 struct rx_ring *rxr = adapter->rx_rings;
4220 for (int i = 0; i < adapter->num_queues; i++, rxr++) {
4221 struct lro_ctrl *lro = &rxr->lro;
4222 ixgbe_free_receive_buffers(rxr);
4223 /* Free LRO memory */
4225 /* Free the ring memory as well */
4226 ixgbe_dma_free(adapter, &rxr->rxdma);
4229 free(adapter->rx_rings, M_DEVBUF);
4233 /*********************************************************************
4235 * Free receive ring data structures
4237 **********************************************************************/
4239 ixgbe_free_receive_buffers(struct rx_ring *rxr)
4241 struct adapter *adapter = rxr->adapter;
4242 struct ixgbe_rx_buf *rxbuf;
4244 INIT_DEBUGOUT("free_receive_structures: begin");
4246 /* Cleanup any existing buffers */
4247 if (rxr->rx_buffers != NULL) {
4248 for (int i = 0; i < adapter->num_rx_desc; i++) {
4249 rxbuf = &rxr->rx_buffers[i];
4250 if (rxbuf->buf != NULL) {
4251 bus_dmamap_sync(rxr->ptag, rxbuf->pmap,
4252 BUS_DMASYNC_POSTREAD);
4253 bus_dmamap_unload(rxr->ptag, rxbuf->pmap);
4254 rxbuf->buf->m_flags |= M_PKTHDR;
4255 m_freem(rxbuf->buf);
4258 if (rxbuf->pmap != NULL) {
4259 bus_dmamap_destroy(rxr->ptag, rxbuf->pmap);
4263 if (rxr->rx_buffers != NULL) {
4264 free(rxr->rx_buffers, M_DEVBUF);
4265 rxr->rx_buffers = NULL;
4269 if (rxr->ptag != NULL) {
4270 bus_dma_tag_destroy(rxr->ptag);
4277 static __inline void
4278 ixgbe_rx_input(struct rx_ring *rxr, struct ifnet *ifp, struct mbuf *m, u32 ptype)
4282 * ATM LRO is only for IP/TCP packets and TCP checksum of the packet
4283 * should be computed by hardware. Also it should not have VLAN tag in
4284 * ethernet header. In case of IPv6 we do not yet support ext. hdrs.
4286 if (rxr->lro_enabled &&
4287 (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) != 0 &&
4288 (ptype & IXGBE_RXDADV_PKTTYPE_ETQF) == 0 &&
4289 ((ptype & (IXGBE_RXDADV_PKTTYPE_IPV4 | IXGBE_RXDADV_PKTTYPE_TCP)) ==
4290 (IXGBE_RXDADV_PKTTYPE_IPV4 | IXGBE_RXDADV_PKTTYPE_TCP) ||
4291 (ptype & (IXGBE_RXDADV_PKTTYPE_IPV6 | IXGBE_RXDADV_PKTTYPE_TCP)) ==
4292 (IXGBE_RXDADV_PKTTYPE_IPV6 | IXGBE_RXDADV_PKTTYPE_TCP)) &&
4293 (m->m_pkthdr.csum_flags & (CSUM_DATA_VALID | CSUM_PSEUDO_HDR)) ==
4294 (CSUM_DATA_VALID | CSUM_PSEUDO_HDR)) {
4296 * Send to the stack if:
4297 ** - LRO not enabled, or
4298 ** - no LRO resources, or
4299 ** - lro enqueue fails
4301 if (rxr->lro.lro_cnt != 0)
4302 if (tcp_lro_rx(&rxr->lro, m, 0) == 0)
4305 IXGBE_RX_UNLOCK(rxr);
4306 (*ifp->if_input)(ifp, m);
4310 static __inline void
4311 ixgbe_rx_discard(struct rx_ring *rxr, int i)
4313 struct ixgbe_rx_buf *rbuf;
4315 rbuf = &rxr->rx_buffers[i];
4317 if (rbuf->fmp != NULL) {/* Partial chain ? */
4318 rbuf->fmp->m_flags |= M_PKTHDR;
4324 ** With advanced descriptors the writeback
4325 ** clobbers the buffer addrs, so its easier
4326 ** to just free the existing mbufs and take
4327 ** the normal refresh path to get new buffers
4339 /*********************************************************************
4341 * This routine executes in interrupt context. It replenishes
4342 * the mbufs in the descriptor and sends data which has been
4343 * dma'ed into host memory to upper layer.
4345 * We loop at most count times if count is > 0, or until done if
4348 * Return TRUE for more work, FALSE for all clean.
4349 *********************************************************************/
4351 ixgbe_rxeof(struct ix_queue *que)
4353 struct adapter *adapter = que->adapter;
4354 struct rx_ring *rxr = que->rxr;
4355 struct ifnet *ifp = adapter->ifp;
4356 struct lro_ctrl *lro = &rxr->lro;
4357 struct lro_entry *queued;
4358 int i, nextp, processed = 0;
4360 u16 count = rxr->process_limit;
4361 union ixgbe_adv_rx_desc *cur;
4362 struct ixgbe_rx_buf *rbuf, *nbuf;
4367 if (ifp->if_capenable & IFCAP_NETMAP) {
4369 * Same as the txeof routine: only wakeup clients on intr.
4370 * NKR_PENDINTR in nr_kflags is used to implement interrupt
4371 * mitigation (ixgbe_rxsync() will not look for new packets
4372 * unless NKR_PENDINTR is set).
4374 struct netmap_adapter *na = NA(ifp);
4376 na->rx_rings[rxr->me].nr_kflags |= NKR_PENDINTR;
4377 selwakeuppri(&na->rx_rings[rxr->me].si, PI_NET);
4378 IXGBE_RX_UNLOCK(rxr);
4379 IXGBE_CORE_LOCK(adapter);
4380 selwakeuppri(&na->rx_si, PI_NET);
4381 IXGBE_CORE_UNLOCK(adapter);
4384 #endif /* DEV_NETMAP */
4385 for (i = rxr->next_to_check; count != 0;) {
4386 struct mbuf *sendmp, *mp;
4392 /* Sync the ring. */
4393 bus_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
4394 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
4396 cur = &rxr->rx_base[i];
4397 staterr = le32toh(cur->wb.upper.status_error);
4399 if ((staterr & IXGBE_RXD_STAT_DD) == 0)
4401 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
4408 cur->wb.upper.status_error = 0;
4409 rbuf = &rxr->rx_buffers[i];
4412 len = le16toh(cur->wb.upper.length);
4413 ptype = le32toh(cur->wb.lower.lo_dword.data) &
4414 IXGBE_RXDADV_PKTTYPE_MASK;
4415 eop = ((staterr & IXGBE_RXD_STAT_EOP) != 0);
4417 /* Make sure bad packets are discarded */
4418 if (((staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) != 0) ||
4420 rxr->rx_discarded++;
4422 rxr->discard = FALSE;
4424 rxr->discard = TRUE;
4425 ixgbe_rx_discard(rxr, i);
4430 ** On 82599 which supports a hardware
4431 ** LRO (called HW RSC), packets need
4432 ** not be fragmented across sequential
4433 ** descriptors, rather the next descriptor
4434 ** is indicated in bits of the descriptor.
4435 ** This also means that we might proceses
4436 ** more than one packet at a time, something
4437 ** that has never been true before, it
4438 ** required eliminating global chain pointers
4439 ** in favor of what we are doing here. -jfv
4443 ** Figure out the next descriptor
4446 if (rxr->hw_rsc == TRUE) {
4447 rsc = ixgbe_rsc_count(cur);
4448 rxr->rsc_num += (rsc - 1);
4450 if (rsc) { /* Get hardware index */
4452 IXGBE_RXDADV_NEXTP_MASK) >>
4453 IXGBE_RXDADV_NEXTP_SHIFT);
4454 } else { /* Just sequential */
4456 if (nextp == adapter->num_rx_desc)
4459 nbuf = &rxr->rx_buffers[nextp];
4463 ** Rather than using the fmp/lmp global pointers
4464 ** we now keep the head of a packet chain in the
4465 ** buffer struct and pass this along from one
4466 ** descriptor to the next, until we get EOP.
4470 ** See if there is a stored head
4471 ** that determines what we are
4474 if (sendmp != NULL) { /* secondary frag */
4475 rbuf->buf = rbuf->fmp = NULL;
4476 mp->m_flags &= ~M_PKTHDR;
4477 sendmp->m_pkthdr.len += mp->m_len;
4480 * Optimize. This might be a small packet,
4481 * maybe just a TCP ACK. Do a fast copy that
4482 * is cache aligned into a new mbuf, and
4483 * leave the old mbuf+cluster for re-use.
4485 if (eop && len <= IXGBE_RX_COPY_LEN) {
4486 sendmp = m_gethdr(M_NOWAIT, MT_DATA);
4487 if (sendmp != NULL) {
4489 IXGBE_RX_COPY_ALIGN;
4490 ixgbe_bcopy(mp->m_data,
4491 sendmp->m_data, len);
4492 sendmp->m_len = len;
4494 rbuf->flags |= IXGBE_RX_COPY;
4497 if (sendmp == NULL) {
4498 rbuf->buf = rbuf->fmp = NULL;
4502 /* first desc of a non-ps chain */
4503 sendmp->m_flags |= M_PKTHDR;
4504 sendmp->m_pkthdr.len = mp->m_len;
4508 /* Pass the head pointer on */
4512 mp->m_next = nbuf->buf;
4513 } else { /* Sending this frame */
4514 sendmp->m_pkthdr.rcvif = ifp;
4517 /* capture data for AIM */
4518 rxr->bytes += sendmp->m_pkthdr.len;
4519 rxr->rx_bytes += sendmp->m_pkthdr.len;
4520 /* Process vlan info */
4521 if ((rxr->vtag_strip) &&
4522 (staterr & IXGBE_RXD_STAT_VP))
4523 vtag = le16toh(cur->wb.upper.vlan);
4525 sendmp->m_pkthdr.ether_vtag = vtag;
4526 sendmp->m_flags |= M_VLANTAG;
4528 if ((ifp->if_capenable & IFCAP_RXCSUM) != 0)
4529 ixgbe_rx_checksum(staterr, sendmp, ptype);
4530 #if __FreeBSD_version >= 800000
4531 sendmp->m_pkthdr.flowid = que->msix;
4532 sendmp->m_flags |= M_FLOWID;
4536 bus_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
4537 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
4539 /* Advance our pointers to the next descriptor. */
4540 if (++i == rxr->num_desc)
4543 /* Now send to the stack or do LRO */
4544 if (sendmp != NULL) {
4545 rxr->next_to_check = i;
4546 ixgbe_rx_input(rxr, ifp, sendmp, ptype);
4547 i = rxr->next_to_check;
4550 /* Every 8 descriptors we go to refresh mbufs */
4551 if (processed == 8) {
4552 ixgbe_refresh_mbufs(rxr, i);
4557 /* Refresh any remaining buf structs */
4558 if (ixgbe_rx_unrefreshed(rxr))
4559 ixgbe_refresh_mbufs(rxr, i);
4561 rxr->next_to_check = i;
4564 * Flush any outstanding LRO work
4566 while ((queued = SLIST_FIRST(&lro->lro_active)) != NULL) {
4567 SLIST_REMOVE_HEAD(&lro->lro_active, next);
4568 tcp_lro_flush(lro, queued);
4571 IXGBE_RX_UNLOCK(rxr);
4574 ** We still have cleaning to do?
4575 ** Schedule another interrupt if so.
4577 if ((staterr & IXGBE_RXD_STAT_DD) != 0) {
4578 ixgbe_rearm_queues(adapter, (u64)(1 << que->msix));
4586 /*********************************************************************
4588 * Verify that the hardware indicated that the checksum is valid.
4589 * Inform the stack about the status of checksum so that stack
4590 * doesn't spend time verifying the checksum.
4592 *********************************************************************/
4594 ixgbe_rx_checksum(u32 staterr, struct mbuf * mp, u32 ptype)
4596 u16 status = (u16) staterr;
4597 u8 errors = (u8) (staterr >> 24);
4600 if ((ptype & IXGBE_RXDADV_PKTTYPE_ETQF) == 0 &&
4601 (ptype & IXGBE_RXDADV_PKTTYPE_SCTP) != 0)
4604 if (status & IXGBE_RXD_STAT_IPCS) {
4605 if (!(errors & IXGBE_RXD_ERR_IPE)) {
4606 /* IP Checksum Good */
4607 mp->m_pkthdr.csum_flags = CSUM_IP_CHECKED;
4608 mp->m_pkthdr.csum_flags |= CSUM_IP_VALID;
4611 mp->m_pkthdr.csum_flags = 0;
4613 if (status & IXGBE_RXD_STAT_L4CS) {
4614 u16 type = (CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
4615 #if __FreeBSD_version >= 800000
4617 type = CSUM_SCTP_VALID;
4619 if (!(errors & IXGBE_RXD_ERR_TCPE)) {
4620 mp->m_pkthdr.csum_flags |= type;
4622 mp->m_pkthdr.csum_data = htons(0xffff);
4630 ** This routine is run via an vlan config EVENT,
4631 ** it enables us to use the HW Filter table since
4632 ** we can get the vlan id. This just creates the
4633 ** entry in the soft version of the VFTA, init will
4634 ** repopulate the real table.
4637 ixgbe_register_vlan(void *arg, struct ifnet *ifp, u16 vtag)
4639 struct adapter *adapter = ifp->if_softc;
4642 if (ifp->if_softc != arg) /* Not our event */
4645 if ((vtag == 0) || (vtag > 4095)) /* Invalid */
4648 IXGBE_CORE_LOCK(adapter);
4649 index = (vtag >> 5) & 0x7F;
4651 adapter->shadow_vfta[index] |= (1 << bit);
4652 ++adapter->num_vlans;
4653 ixgbe_init_locked(adapter);
4654 IXGBE_CORE_UNLOCK(adapter);
4658 ** This routine is run via an vlan
4659 ** unconfig EVENT, remove our entry
4660 ** in the soft vfta.
4663 ixgbe_unregister_vlan(void *arg, struct ifnet *ifp, u16 vtag)
4665 struct adapter *adapter = ifp->if_softc;
4668 if (ifp->if_softc != arg)
4671 if ((vtag == 0) || (vtag > 4095)) /* Invalid */
4674 IXGBE_CORE_LOCK(adapter);
4675 index = (vtag >> 5) & 0x7F;
4677 adapter->shadow_vfta[index] &= ~(1 << bit);
4678 --adapter->num_vlans;
4679 /* Re-init to load the changes */
4680 ixgbe_init_locked(adapter);
4681 IXGBE_CORE_UNLOCK(adapter);
4685 ixgbe_setup_vlan_hw_support(struct adapter *adapter)
4687 struct ifnet *ifp = adapter->ifp;
4688 struct ixgbe_hw *hw = &adapter->hw;
4689 struct rx_ring *rxr;
4694 ** We get here thru init_locked, meaning
4695 ** a soft reset, this has already cleared
4696 ** the VFTA and other state, so if there
4697 ** have been no vlan's registered do nothing.
4699 if (adapter->num_vlans == 0)
4703 ** A soft reset zero's out the VFTA, so
4704 ** we need to repopulate it now.
4706 for (int i = 0; i < IXGBE_VFTA_SIZE; i++)
4707 if (adapter->shadow_vfta[i] != 0)
4708 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i),
4709 adapter->shadow_vfta[i]);
4711 ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4712 /* Enable the Filter Table if enabled */
4713 if (ifp->if_capenable & IFCAP_VLAN_HWFILTER) {
4714 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
4715 ctrl |= IXGBE_VLNCTRL_VFE;
4717 if (hw->mac.type == ixgbe_mac_82598EB)
4718 ctrl |= IXGBE_VLNCTRL_VME;
4719 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
4721 /* Setup the queues for vlans */
4722 for (int i = 0; i < adapter->num_queues; i++) {
4723 rxr = &adapter->rx_rings[i];
4724 /* On 82599 the VLAN enable is per/queue in RXDCTL */
4725 if (hw->mac.type != ixgbe_mac_82598EB) {
4726 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
4727 ctrl |= IXGBE_RXDCTL_VME;
4728 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), ctrl);
4730 rxr->vtag_strip = TRUE;
4735 ixgbe_enable_intr(struct adapter *adapter)
4737 struct ixgbe_hw *hw = &adapter->hw;
4738 struct ix_queue *que = adapter->queues;
4739 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
4742 /* Enable Fan Failure detection */
4743 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4744 mask |= IXGBE_EIMS_GPI_SDP1;
4746 switch (adapter->hw.mac.type) {
4747 case ixgbe_mac_82599EB:
4748 mask |= IXGBE_EIMS_ECC;
4749 mask |= IXGBE_EIMS_GPI_SDP0;
4750 mask |= IXGBE_EIMS_GPI_SDP1;
4751 mask |= IXGBE_EIMS_GPI_SDP2;
4753 mask |= IXGBE_EIMS_FLOW_DIR;
4756 case ixgbe_mac_X540:
4757 mask |= IXGBE_EIMS_ECC;
4759 mask |= IXGBE_EIMS_FLOW_DIR;
4766 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
4768 /* With RSS we use auto clear */
4769 if (adapter->msix_mem) {
4770 mask = IXGBE_EIMS_ENABLE_MASK;
4771 /* Don't autoclear Link */
4772 mask &= ~IXGBE_EIMS_OTHER;
4773 mask &= ~IXGBE_EIMS_LSC;
4774 IXGBE_WRITE_REG(hw, IXGBE_EIAC, mask);
4778 ** Now enable all queues, this is done separately to
4779 ** allow for handling the extended (beyond 32) MSIX
4780 ** vectors that can be used by 82599
4782 for (int i = 0; i < adapter->num_queues; i++, que++)
4783 ixgbe_enable_queue(adapter, que->msix);
4785 IXGBE_WRITE_FLUSH(hw);
4791 ixgbe_disable_intr(struct adapter *adapter)
4793 if (adapter->msix_mem)
4794 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, 0);
4795 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
4796 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
4798 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
4799 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
4800 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
4802 IXGBE_WRITE_FLUSH(&adapter->hw);
4807 ixgbe_read_pci_cfg(struct ixgbe_hw *hw, u32 reg)
4811 value = pci_read_config(((struct ixgbe_osdep *)hw->back)->dev,
4818 ixgbe_write_pci_cfg(struct ixgbe_hw *hw, u32 reg, u16 value)
4820 pci_write_config(((struct ixgbe_osdep *)hw->back)->dev,
4827 ** Setup the correct IVAR register for a particular MSIX interrupt
4828 ** (yes this is all very magic and confusing :)
4829 ** - entry is the register array entry
4830 ** - vector is the MSIX vector for this queue
4831 ** - type is RX/TX/MISC
4834 ixgbe_set_ivar(struct adapter *adapter, u8 entry, u8 vector, s8 type)
4836 struct ixgbe_hw *hw = &adapter->hw;
4839 vector |= IXGBE_IVAR_ALLOC_VAL;
4841 switch (hw->mac.type) {
4843 case ixgbe_mac_82598EB:
4845 entry = IXGBE_IVAR_OTHER_CAUSES_INDEX;
4847 entry += (type * 64);
4848 index = (entry >> 2) & 0x1F;
4849 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
4850 ivar &= ~(0xFF << (8 * (entry & 0x3)));
4851 ivar |= (vector << (8 * (entry & 0x3)));
4852 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR(index), ivar);
4855 case ixgbe_mac_82599EB:
4856 case ixgbe_mac_X540:
4857 if (type == -1) { /* MISC IVAR */
4858 index = (entry & 1) * 8;
4859 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR_MISC);
4860 ivar &= ~(0xFF << index);
4861 ivar |= (vector << index);
4862 IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, ivar);
4863 } else { /* RX/TX IVARS */
4864 index = (16 * (entry & 1)) + (8 * type);
4865 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(entry >> 1));
4866 ivar &= ~(0xFF << index);
4867 ivar |= (vector << index);
4868 IXGBE_WRITE_REG(hw, IXGBE_IVAR(entry >> 1), ivar);
4877 ixgbe_configure_ivars(struct adapter *adapter)
4879 struct ix_queue *que = adapter->queues;
4882 if (ixgbe_max_interrupt_rate > 0)
4883 newitr = (4000000 / ixgbe_max_interrupt_rate) & 0x0FF8;
4887 for (int i = 0; i < adapter->num_queues; i++, que++) {
4888 /* First the RX queue entry */
4889 ixgbe_set_ivar(adapter, i, que->msix, 0);
4890 /* ... and the TX */
4891 ixgbe_set_ivar(adapter, i, que->msix, 1);
4892 /* Set an Initial EITR value */
4893 IXGBE_WRITE_REG(&adapter->hw,
4894 IXGBE_EITR(que->msix), newitr);
4897 /* For the Link interrupt */
4898 ixgbe_set_ivar(adapter, 1, adapter->linkvec, -1);
4902 ** ixgbe_sfp_probe - called in the local timer to
4903 ** determine if a port had optics inserted.
4905 static bool ixgbe_sfp_probe(struct adapter *adapter)
4907 struct ixgbe_hw *hw = &adapter->hw;
4908 device_t dev = adapter->dev;
4909 bool result = FALSE;
4911 if ((hw->phy.type == ixgbe_phy_nl) &&
4912 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
4913 s32 ret = hw->phy.ops.identify_sfp(hw);
4916 ret = hw->phy.ops.reset(hw);
4917 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4918 device_printf(dev,"Unsupported SFP+ module detected!");
4919 printf(" Reload driver with supported module.\n");
4920 adapter->sfp_probe = FALSE;
4923 device_printf(dev,"SFP+ module detected!\n");
4924 /* We now have supported optics */
4925 adapter->sfp_probe = FALSE;
4926 /* Set the optics type so system reports correctly */
4927 ixgbe_setup_optics(adapter);
4935 ** Tasklet handler for MSIX Link interrupts
4936 ** - do outside interrupt since it might sleep
4939 ixgbe_handle_link(void *context, int pending)
4941 struct adapter *adapter = context;
4943 ixgbe_check_link(&adapter->hw,
4944 &adapter->link_speed, &adapter->link_up, 0);
4945 ixgbe_update_link_status(adapter);
4949 ** Tasklet for handling SFP module interrupts
4952 ixgbe_handle_mod(void *context, int pending)
4954 struct adapter *adapter = context;
4955 struct ixgbe_hw *hw = &adapter->hw;
4956 device_t dev = adapter->dev;
4959 err = hw->phy.ops.identify_sfp(hw);
4960 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4962 "Unsupported SFP+ module type was detected.\n");
4965 err = hw->mac.ops.setup_sfp(hw);
4966 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4968 "Setup failure - unsupported SFP+ module type.\n");
4971 taskqueue_enqueue(adapter->tq, &adapter->msf_task);
4977 ** Tasklet for handling MSF (multispeed fiber) interrupts
4980 ixgbe_handle_msf(void *context, int pending)
4982 struct adapter *adapter = context;
4983 struct ixgbe_hw *hw = &adapter->hw;
4987 autoneg = hw->phy.autoneg_advertised;
4988 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
4989 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiate);
4990 if (hw->mac.ops.setup_link)
4991 hw->mac.ops.setup_link(hw, autoneg, TRUE);
4997 ** Tasklet for reinitializing the Flow Director filter table
5000 ixgbe_reinit_fdir(void *context, int pending)
5002 struct adapter *adapter = context;
5003 struct ifnet *ifp = adapter->ifp;
5005 if (adapter->fdir_reinit != 1) /* Shouldn't happen */
5007 ixgbe_reinit_fdir_tables_82599(&adapter->hw);
5008 adapter->fdir_reinit = 0;
5009 /* re-enable flow director interrupts */
5010 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
5011 /* Restart the interface */
5012 ifp->if_drv_flags |= IFF_DRV_RUNNING;
5017 /**********************************************************************
5019 * Update the board statistics counters.
5021 **********************************************************************/
5023 ixgbe_update_stats_counters(struct adapter *adapter)
5025 struct ifnet *ifp = adapter->ifp;
5026 struct ixgbe_hw *hw = &adapter->hw;
5027 u32 missed_rx = 0, bprc, lxon, lxoff, total;
5028 u64 total_missed_rx = 0;
5030 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
5031 adapter->stats.illerrc += IXGBE_READ_REG(hw, IXGBE_ILLERRC);
5032 adapter->stats.errbc += IXGBE_READ_REG(hw, IXGBE_ERRBC);
5033 adapter->stats.mspdc += IXGBE_READ_REG(hw, IXGBE_MSPDC);
5036 ** Note: these are for the 8 possible traffic classes,
5037 ** which in current implementation is unused,
5038 ** therefore only 0 should read real data.
5040 for (int i = 0; i < 8; i++) {
5042 mp = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5043 /* missed_rx tallies misses for the gprc workaround */
5045 /* global total per queue */
5046 adapter->stats.mpc[i] += mp;
5047 /* Running comprehensive total for stats display */
5048 total_missed_rx += adapter->stats.mpc[i];
5049 if (hw->mac.type == ixgbe_mac_82598EB) {
5050 adapter->stats.rnbc[i] +=
5051 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5052 adapter->stats.qbtc[i] +=
5053 IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5054 adapter->stats.qbrc[i] +=
5055 IXGBE_READ_REG(hw, IXGBE_QBRC(i));
5056 adapter->stats.pxonrxc[i] +=
5057 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
5059 adapter->stats.pxonrxc[i] +=
5060 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
5061 adapter->stats.pxontxc[i] +=
5062 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5063 adapter->stats.pxofftxc[i] +=
5064 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
5065 adapter->stats.pxoffrxc[i] +=
5066 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
5067 adapter->stats.pxon2offc[i] +=
5068 IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
5070 for (int i = 0; i < 16; i++) {
5071 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5072 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5073 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
5075 adapter->stats.mlfc += IXGBE_READ_REG(hw, IXGBE_MLFC);
5076 adapter->stats.mrfc += IXGBE_READ_REG(hw, IXGBE_MRFC);
5077 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
5079 /* Hardware workaround, gprc counts missed packets */
5080 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
5081 adapter->stats.gprc -= missed_rx;
5083 if (hw->mac.type != ixgbe_mac_82598EB) {
5084 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL) +
5085 ((u64)IXGBE_READ_REG(hw, IXGBE_GORCH) << 32);
5086 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL) +
5087 ((u64)IXGBE_READ_REG(hw, IXGBE_GOTCH) << 32);
5088 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL) +
5089 ((u64)IXGBE_READ_REG(hw, IXGBE_TORH) << 32);
5090 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
5091 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
5093 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
5094 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
5095 /* 82598 only has a counter in the high register */
5096 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5097 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5098 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5102 * Workaround: mprc hardware is incorrectly counting
5103 * broadcasts, so for now we subtract those.
5105 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
5106 adapter->stats.bprc += bprc;
5107 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
5108 if (hw->mac.type == ixgbe_mac_82598EB)
5109 adapter->stats.mprc -= bprc;
5111 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5112 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5113 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5114 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5115 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5116 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5118 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
5119 adapter->stats.lxontxc += lxon;
5120 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
5121 adapter->stats.lxofftxc += lxoff;
5122 total = lxon + lxoff;
5124 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5125 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
5126 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5127 adapter->stats.gptc -= total;
5128 adapter->stats.mptc -= total;
5129 adapter->stats.ptc64 -= total;
5130 adapter->stats.gotc -= total * ETHER_MIN_LEN;
5132 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5133 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5134 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5135 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5136 adapter->stats.mngprc += IXGBE_READ_REG(hw, IXGBE_MNGPRC);
5137 adapter->stats.mngpdc += IXGBE_READ_REG(hw, IXGBE_MNGPDC);
5138 adapter->stats.mngptc += IXGBE_READ_REG(hw, IXGBE_MNGPTC);
5139 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5140 adapter->stats.tpt += IXGBE_READ_REG(hw, IXGBE_TPT);
5141 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5142 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5143 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5144 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5145 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5146 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
5147 adapter->stats.xec += IXGBE_READ_REG(hw, IXGBE_XEC);
5148 adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5149 adapter->stats.fclast += IXGBE_READ_REG(hw, IXGBE_FCLAST);
5150 /* Only read FCOE on 82599 */
5151 if (hw->mac.type != ixgbe_mac_82598EB) {
5152 adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5153 adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5154 adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5155 adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5156 adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
5159 /* Fill out the OS statistics structure */
5160 ifp->if_ipackets = adapter->stats.gprc;
5161 ifp->if_opackets = adapter->stats.gptc;
5162 ifp->if_ibytes = adapter->stats.gorc;
5163 ifp->if_obytes = adapter->stats.gotc;
5164 ifp->if_imcasts = adapter->stats.mprc;
5165 ifp->if_omcasts = adapter->stats.mptc;
5166 ifp->if_collisions = 0;
5169 ifp->if_iqdrops = total_missed_rx;
5170 ifp->if_ierrors = adapter->stats.crcerrs + adapter->stats.rlec;
5173 /** ixgbe_sysctl_tdh_handler - Handler function
5174 * Retrieves the TDH value from the hardware
5177 ixgbe_sysctl_tdh_handler(SYSCTL_HANDLER_ARGS)
5181 struct tx_ring *txr = ((struct tx_ring *)oidp->oid_arg1);
5184 unsigned val = IXGBE_READ_REG(&txr->adapter->hw, IXGBE_TDH(txr->me));
5185 error = sysctl_handle_int(oidp, &val, 0, req);
5186 if (error || !req->newptr)
5191 /** ixgbe_sysctl_tdt_handler - Handler function
5192 * Retrieves the TDT value from the hardware
5195 ixgbe_sysctl_tdt_handler(SYSCTL_HANDLER_ARGS)
5199 struct tx_ring *txr = ((struct tx_ring *)oidp->oid_arg1);
5202 unsigned val = IXGBE_READ_REG(&txr->adapter->hw, IXGBE_TDT(txr->me));
5203 error = sysctl_handle_int(oidp, &val, 0, req);
5204 if (error || !req->newptr)
5209 /** ixgbe_sysctl_rdh_handler - Handler function
5210 * Retrieves the RDH value from the hardware
5213 ixgbe_sysctl_rdh_handler(SYSCTL_HANDLER_ARGS)
5217 struct rx_ring *rxr = ((struct rx_ring *)oidp->oid_arg1);
5220 unsigned val = IXGBE_READ_REG(&rxr->adapter->hw, IXGBE_RDH(rxr->me));
5221 error = sysctl_handle_int(oidp, &val, 0, req);
5222 if (error || !req->newptr)
5227 /** ixgbe_sysctl_rdt_handler - Handler function
5228 * Retrieves the RDT value from the hardware
5231 ixgbe_sysctl_rdt_handler(SYSCTL_HANDLER_ARGS)
5235 struct rx_ring *rxr = ((struct rx_ring *)oidp->oid_arg1);
5238 unsigned val = IXGBE_READ_REG(&rxr->adapter->hw, IXGBE_RDT(rxr->me));
5239 error = sysctl_handle_int(oidp, &val, 0, req);
5240 if (error || !req->newptr)
5246 ixgbe_sysctl_interrupt_rate_handler(SYSCTL_HANDLER_ARGS)
5249 struct ix_queue *que = ((struct ix_queue *)oidp->oid_arg1);
5250 unsigned int reg, usec, rate;
5252 reg = IXGBE_READ_REG(&que->adapter->hw, IXGBE_EITR(que->msix));
5253 usec = ((reg & 0x0FF8) >> 3);
5255 rate = 500000 / usec;
5258 error = sysctl_handle_int(oidp, &rate, 0, req);
5259 if (error || !req->newptr)
5261 reg &= ~0xfff; /* default, no limitation */
5262 ixgbe_max_interrupt_rate = 0;
5263 if (rate > 0 && rate < 500000) {
5266 ixgbe_max_interrupt_rate = rate;
5267 reg |= ((4000000/rate) & 0xff8 );
5269 IXGBE_WRITE_REG(&que->adapter->hw, IXGBE_EITR(que->msix), reg);
5274 * Add sysctl variables, one per statistic, to the system.
5277 ixgbe_add_hw_stats(struct adapter *adapter)
5280 device_t dev = adapter->dev;
5282 struct tx_ring *txr = adapter->tx_rings;
5283 struct rx_ring *rxr = adapter->rx_rings;
5285 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(dev);
5286 struct sysctl_oid *tree = device_get_sysctl_tree(dev);
5287 struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
5288 struct ixgbe_hw_stats *stats = &adapter->stats;
5290 struct sysctl_oid *stat_node, *queue_node;
5291 struct sysctl_oid_list *stat_list, *queue_list;
5293 #define QUEUE_NAME_LEN 32
5294 char namebuf[QUEUE_NAME_LEN];
5296 /* Driver Statistics */
5297 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "dropped",
5298 CTLFLAG_RD, &adapter->dropped_pkts,
5299 "Driver dropped packets");
5300 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "mbuf_defrag_failed",
5301 CTLFLAG_RD, &adapter->mbuf_defrag_failed,
5302 "m_defrag() failed");
5303 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "watchdog_events",
5304 CTLFLAG_RD, &adapter->watchdog_events,
5305 "Watchdog timeouts");
5306 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "link_irq",
5307 CTLFLAG_RD, &adapter->link_irq,
5308 "Link MSIX IRQ Handled");
5310 for (int i = 0; i < adapter->num_queues; i++, txr++) {
5311 snprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i);
5312 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf,
5313 CTLFLAG_RD, NULL, "Queue Name");
5314 queue_list = SYSCTL_CHILDREN(queue_node);
5316 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "interrupt_rate",
5317 CTLTYPE_UINT | CTLFLAG_RW, &adapter->queues[i],
5318 sizeof(&adapter->queues[i]),
5319 ixgbe_sysctl_interrupt_rate_handler, "IU",
5321 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "irqs",
5322 CTLFLAG_RD, &(adapter->queues[i].irqs),
5323 "irqs on this queue");
5324 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "txd_head",
5325 CTLTYPE_UINT | CTLFLAG_RD, txr, sizeof(txr),
5326 ixgbe_sysctl_tdh_handler, "IU",
5327 "Transmit Descriptor Head");
5328 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "txd_tail",
5329 CTLTYPE_UINT | CTLFLAG_RD, txr, sizeof(txr),
5330 ixgbe_sysctl_tdt_handler, "IU",
5331 "Transmit Descriptor Tail");
5332 SYSCTL_ADD_ULONG(ctx, queue_list, OID_AUTO, "tso_tx",
5333 CTLFLAG_RD, &txr->tso_tx,
5335 SYSCTL_ADD_ULONG(ctx, queue_list, OID_AUTO, "no_tx_dma_setup",
5336 CTLFLAG_RD, &txr->no_tx_dma_setup,
5337 "Driver tx dma failure in xmit");
5338 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "no_desc_avail",
5339 CTLFLAG_RD, &txr->no_desc_avail,
5340 "Queue No Descriptor Available");
5341 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tx_packets",
5342 CTLFLAG_RD, &txr->total_packets,
5343 "Queue Packets Transmitted");
5346 for (int i = 0; i < adapter->num_queues; i++, rxr++) {
5347 snprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i);
5348 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf,
5349 CTLFLAG_RD, NULL, "Queue Name");
5350 queue_list = SYSCTL_CHILDREN(queue_node);
5352 struct lro_ctrl *lro = &rxr->lro;
5354 snprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i);
5355 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf,
5356 CTLFLAG_RD, NULL, "Queue Name");
5357 queue_list = SYSCTL_CHILDREN(queue_node);
5359 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "rxd_head",
5360 CTLTYPE_UINT | CTLFLAG_RD, rxr, sizeof(rxr),
5361 ixgbe_sysctl_rdh_handler, "IU",
5362 "Receive Descriptor Head");
5363 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "rxd_tail",
5364 CTLTYPE_UINT | CTLFLAG_RD, rxr, sizeof(rxr),
5365 ixgbe_sysctl_rdt_handler, "IU",
5366 "Receive Descriptor Tail");
5367 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_packets",
5368 CTLFLAG_RD, &rxr->rx_packets,
5369 "Queue Packets Received");
5370 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_bytes",
5371 CTLFLAG_RD, &rxr->rx_bytes,
5372 "Queue Bytes Received");
5373 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_copies",
5374 CTLFLAG_RD, &rxr->rx_copies,
5375 "Copied RX Frames");
5376 SYSCTL_ADD_INT(ctx, queue_list, OID_AUTO, "lro_queued",
5377 CTLFLAG_RD, &lro->lro_queued, 0,
5379 SYSCTL_ADD_INT(ctx, queue_list, OID_AUTO, "lro_flushed",
5380 CTLFLAG_RD, &lro->lro_flushed, 0,
5384 /* MAC stats get the own sub node */
5386 stat_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "mac_stats",
5387 CTLFLAG_RD, NULL, "MAC Statistics");
5388 stat_list = SYSCTL_CHILDREN(stat_node);
5390 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "crc_errs",
5391 CTLFLAG_RD, &stats->crcerrs,
5393 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "ill_errs",
5394 CTLFLAG_RD, &stats->illerrc,
5395 "Illegal Byte Errors");
5396 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "byte_errs",
5397 CTLFLAG_RD, &stats->errbc,
5399 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "short_discards",
5400 CTLFLAG_RD, &stats->mspdc,
5401 "MAC Short Packets Discarded");
5402 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "local_faults",
5403 CTLFLAG_RD, &stats->mlfc,
5404 "MAC Local Faults");
5405 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "remote_faults",
5406 CTLFLAG_RD, &stats->mrfc,
5407 "MAC Remote Faults");
5408 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rec_len_errs",
5409 CTLFLAG_RD, &stats->rlec,
5410 "Receive Length Errors");
5412 /* Flow Control stats */
5413 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "xon_txd",
5414 CTLFLAG_RD, &stats->lxontxc,
5415 "Link XON Transmitted");
5416 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "xon_recvd",
5417 CTLFLAG_RD, &stats->lxonrxc,
5418 "Link XON Received");
5419 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "xoff_txd",
5420 CTLFLAG_RD, &stats->lxofftxc,
5421 "Link XOFF Transmitted");
5422 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "xoff_recvd",
5423 CTLFLAG_RD, &stats->lxoffrxc,
5424 "Link XOFF Received");
5426 /* Packet Reception Stats */
5427 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "total_octets_rcvd",
5428 CTLFLAG_RD, &stats->tor,
5429 "Total Octets Received");
5430 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_octets_rcvd",
5431 CTLFLAG_RD, &stats->gorc,
5432 "Good Octets Received");
5433 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "total_pkts_rcvd",
5434 CTLFLAG_RD, &stats->tpr,
5435 "Total Packets Received");
5436 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_pkts_rcvd",
5437 CTLFLAG_RD, &stats->gprc,
5438 "Good Packets Received");
5439 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "mcast_pkts_rcvd",
5440 CTLFLAG_RD, &stats->mprc,
5441 "Multicast Packets Received");
5442 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "bcast_pkts_rcvd",
5443 CTLFLAG_RD, &stats->bprc,
5444 "Broadcast Packets Received");
5445 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_64",
5446 CTLFLAG_RD, &stats->prc64,
5447 "64 byte frames received ");
5448 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_65_127",
5449 CTLFLAG_RD, &stats->prc127,
5450 "65-127 byte frames received");
5451 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_128_255",
5452 CTLFLAG_RD, &stats->prc255,
5453 "128-255 byte frames received");
5454 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_256_511",
5455 CTLFLAG_RD, &stats->prc511,
5456 "256-511 byte frames received");
5457 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_512_1023",
5458 CTLFLAG_RD, &stats->prc1023,
5459 "512-1023 byte frames received");
5460 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_1024_1522",
5461 CTLFLAG_RD, &stats->prc1522,
5462 "1023-1522 byte frames received");
5463 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_undersized",
5464 CTLFLAG_RD, &stats->ruc,
5465 "Receive Undersized");
5466 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_fragmented",
5467 CTLFLAG_RD, &stats->rfc,
5468 "Fragmented Packets Received ");
5469 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_oversized",
5470 CTLFLAG_RD, &stats->roc,
5471 "Oversized Packets Received");
5472 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_jabberd",
5473 CTLFLAG_RD, &stats->rjc,
5475 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "management_pkts_rcvd",
5476 CTLFLAG_RD, &stats->mngprc,
5477 "Management Packets Received");
5478 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "management_pkts_drpd",
5479 CTLFLAG_RD, &stats->mngptc,
5480 "Management Packets Dropped");
5481 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "checksum_errs",
5482 CTLFLAG_RD, &stats->xec,
5485 /* Packet Transmission Stats */
5486 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_octets_txd",
5487 CTLFLAG_RD, &stats->gotc,
5488 "Good Octets Transmitted");
5489 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "total_pkts_txd",
5490 CTLFLAG_RD, &stats->tpt,
5491 "Total Packets Transmitted");
5492 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_pkts_txd",
5493 CTLFLAG_RD, &stats->gptc,
5494 "Good Packets Transmitted");
5495 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "bcast_pkts_txd",
5496 CTLFLAG_RD, &stats->bptc,
5497 "Broadcast Packets Transmitted");
5498 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "mcast_pkts_txd",
5499 CTLFLAG_RD, &stats->mptc,
5500 "Multicast Packets Transmitted");
5501 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "management_pkts_txd",
5502 CTLFLAG_RD, &stats->mngptc,
5503 "Management Packets Transmitted");
5504 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_64",
5505 CTLFLAG_RD, &stats->ptc64,
5506 "64 byte frames transmitted ");
5507 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_65_127",
5508 CTLFLAG_RD, &stats->ptc127,
5509 "65-127 byte frames transmitted");
5510 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_128_255",
5511 CTLFLAG_RD, &stats->ptc255,
5512 "128-255 byte frames transmitted");
5513 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_256_511",
5514 CTLFLAG_RD, &stats->ptc511,
5515 "256-511 byte frames transmitted");
5516 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_512_1023",
5517 CTLFLAG_RD, &stats->ptc1023,
5518 "512-1023 byte frames transmitted");
5519 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_1024_1522",
5520 CTLFLAG_RD, &stats->ptc1522,
5521 "1024-1522 byte frames transmitted");
5525 ** Set flow control using sysctl:
5526 ** Flow control values:
5533 ixgbe_set_flowcntl(SYSCTL_HANDLER_ARGS)
5536 struct adapter *adapter = (struct adapter *) arg1;
5539 error = sysctl_handle_int(oidp, &adapter->fc, 0, req);
5540 if ((error) || (req->newptr == NULL))
5543 /* Don't bother if it's not changed */
5544 if (adapter->fc == last)
5547 switch (adapter->fc) {
5548 case ixgbe_fc_rx_pause:
5549 case ixgbe_fc_tx_pause:
5551 adapter->hw.fc.requested_mode = adapter->fc;
5552 if (adapter->num_queues > 1)
5553 ixgbe_disable_rx_drop(adapter);
5556 adapter->hw.fc.requested_mode = ixgbe_fc_none;
5557 if (adapter->num_queues > 1)
5558 ixgbe_enable_rx_drop(adapter);
5564 /* Don't autoneg if forcing a value */
5565 adapter->hw.fc.disable_fc_autoneg = TRUE;
5566 ixgbe_fc_enable(&adapter->hw);
5571 ** Control link advertise speed:
5572 ** 1 - advertise only 1G
5573 ** 2 - advertise 100Mb
5574 ** 3 - advertise normal
5577 ixgbe_set_advertise(SYSCTL_HANDLER_ARGS)
5580 struct adapter *adapter;
5582 struct ixgbe_hw *hw;
5583 ixgbe_link_speed speed, last;
5585 adapter = (struct adapter *) arg1;
5588 last = adapter->advertise;
5590 error = sysctl_handle_int(oidp, &adapter->advertise, 0, req);
5591 if ((error) || (req->newptr == NULL))
5594 if (adapter->advertise == last) /* no change */
5597 if (!((hw->phy.media_type == ixgbe_media_type_copper) ||
5598 (hw->phy.multispeed_fiber)))
5601 if ((adapter->advertise == 2) && (hw->mac.type != ixgbe_mac_X540)) {
5602 device_printf(dev, "Set Advertise: 100Mb on X540 only\n");
5606 if (adapter->advertise == 1)
5607 speed = IXGBE_LINK_SPEED_1GB_FULL;
5608 else if (adapter->advertise == 2)
5609 speed = IXGBE_LINK_SPEED_100_FULL;
5610 else if (adapter->advertise == 3)
5611 speed = IXGBE_LINK_SPEED_1GB_FULL |
5612 IXGBE_LINK_SPEED_10GB_FULL;
5613 else { /* bogus value */
5614 adapter->advertise = last;
5618 hw->mac.autotry_restart = TRUE;
5619 hw->mac.ops.setup_link(hw, speed, TRUE);
5625 ** Thermal Shutdown Trigger
5626 ** - cause a Thermal Overtemp IRQ
5629 ixgbe_set_thermal_test(SYSCTL_HANDLER_ARGS)
5631 int error, fire = 0;
5632 struct adapter *adapter = (struct adapter *) arg1;
5633 struct ixgbe_hw *hw = &adapter->hw;
5636 if (hw->mac.type != ixgbe_mac_X540)
5639 error = sysctl_handle_int(oidp, &fire, 0, req);
5640 if ((error) || (req->newptr == NULL))
5644 u32 reg = IXGBE_READ_REG(hw, IXGBE_EICS);
5645 reg |= IXGBE_EICR_TS;
5646 IXGBE_WRITE_REG(hw, IXGBE_EICS, reg);
5653 ** Enable the hardware to drop packets when the buffer is
5654 ** full. This is useful when multiqueue,so that no single
5655 ** queue being full stalls the entire RX engine. We only
5656 ** enable this when Multiqueue AND when Flow Control is
5660 ixgbe_enable_rx_drop(struct adapter *adapter)
5662 struct ixgbe_hw *hw = &adapter->hw;
5664 for (int i = 0; i < adapter->num_queues; i++) {
5665 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
5666 srrctl |= IXGBE_SRRCTL_DROP_EN;
5667 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(i), srrctl);
5672 ixgbe_disable_rx_drop(struct adapter *adapter)
5674 struct ixgbe_hw *hw = &adapter->hw;
5676 for (int i = 0; i < adapter->num_queues; i++) {
5677 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
5678 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
5679 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(i), srrctl);