1 /******************************************************************************
3 Copyright (c) 2001-2012, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ******************************************************************************/
33 /*$FreeBSD: src/sys/dev/ixgbe/ixgbe.c,v 1.70 2012/07/05 20:51:44 jfv Exp $*/
36 #include "opt_inet6.h"
40 /*********************************************************************
41 * Set this to one to display debug statistics
42 *********************************************************************/
43 int ixgbe_display_debug_stats = 0;
45 /*********************************************************************
47 *********************************************************************/
48 char ixgbe_driver_version[] = "2.4.8";
50 /*********************************************************************
53 * Used by probe to select devices to load on
54 * Last field stores an index into ixgbe_strings
55 * Last entry must be all 0s
57 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index }
58 *********************************************************************/
60 static ixgbe_vendor_info_t ixgbe_vendor_info_array[] =
62 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AF_DUAL_PORT, 0, 0, 0},
63 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AF_SINGLE_PORT, 0, 0, 0},
64 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_CX4, 0, 0, 0},
65 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AT, 0, 0, 0},
66 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AT2, 0, 0, 0},
67 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598, 0, 0, 0},
68 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_DA_DUAL_PORT, 0, 0, 0},
69 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_CX4_DUAL_PORT, 0, 0, 0},
70 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_XF_LR, 0, 0, 0},
71 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM, 0, 0, 0},
72 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_SFP_LOM, 0, 0, 0},
73 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KX4, 0, 0, 0},
74 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KX4_MEZZ, 0, 0, 0},
75 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP, 0, 0, 0},
76 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_XAUI_LOM, 0, 0, 0},
77 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_CX4, 0, 0, 0},
78 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_T3_LOM, 0, 0, 0},
79 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_COMBO_BACKPLANE, 0, 0, 0},
80 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_BACKPLANE_FCOE, 0, 0, 0},
81 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_SF2, 0, 0, 0},
82 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_FCOE, 0, 0, 0},
83 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599EN_SFP, 0, 0, 0},
84 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540T1, 0, 0, 0},
85 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540T, 0, 0, 0},
86 /* required last entry */
90 /*********************************************************************
91 * Table of branding strings
92 *********************************************************************/
94 static char *ixgbe_strings[] = {
95 "Intel(R) PRO/10GbE PCI-Express Network Driver"
98 /*********************************************************************
100 *********************************************************************/
101 static int ixgbe_probe(device_t);
102 static int ixgbe_attach(device_t);
103 static int ixgbe_detach(device_t);
104 static int ixgbe_shutdown(device_t);
105 static void ixgbe_start(struct ifnet *);
106 static void ixgbe_start_locked(struct tx_ring *, struct ifnet *);
107 #if 0 /* __FreeBSD_version >= 800000 */
108 static int ixgbe_mq_start(struct ifnet *, struct mbuf *);
109 static int ixgbe_mq_start_locked(struct ifnet *,
110 struct tx_ring *, struct mbuf *);
111 static void ixgbe_qflush(struct ifnet *);
113 static int ixgbe_ioctl(struct ifnet *, u_long, caddr_t, struct ucred *);
114 static void ixgbe_init(void *);
115 static void ixgbe_init_locked(struct adapter *);
116 static void ixgbe_stop(void *);
117 static void ixgbe_media_status(struct ifnet *, struct ifmediareq *);
118 static int ixgbe_media_change(struct ifnet *);
119 static void ixgbe_identify_hardware(struct adapter *);
120 static int ixgbe_allocate_pci_resources(struct adapter *);
121 static int ixgbe_allocate_msix(struct adapter *);
122 static int ixgbe_allocate_legacy(struct adapter *);
123 static int ixgbe_allocate_queues(struct adapter *);
124 #if 0 /* HAVE_MSIX */
125 static int ixgbe_setup_msix(struct adapter *);
127 static void ixgbe_free_pci_resources(struct adapter *);
128 static void ixgbe_local_timer(void *);
129 static int ixgbe_setup_interface(device_t, struct adapter *);
130 static void ixgbe_config_link(struct adapter *);
132 static int ixgbe_allocate_transmit_buffers(struct tx_ring *);
133 static int ixgbe_setup_transmit_structures(struct adapter *);
134 static void ixgbe_setup_transmit_ring(struct tx_ring *);
135 static void ixgbe_initialize_transmit_units(struct adapter *);
136 static void ixgbe_free_transmit_structures(struct adapter *);
137 static void ixgbe_free_transmit_buffers(struct tx_ring *);
139 static int ixgbe_allocate_receive_buffers(struct rx_ring *);
140 static int ixgbe_setup_receive_structures(struct adapter *);
141 static int ixgbe_setup_receive_ring(struct rx_ring *);
142 static void ixgbe_initialize_receive_units(struct adapter *);
143 static void ixgbe_free_receive_structures(struct adapter *);
144 static void ixgbe_free_receive_buffers(struct rx_ring *);
146 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 *, int);
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 void ixgbe_add_rx_process_limit(struct adapter *, const char *,
167 const char *, int *, int);
168 static bool ixgbe_tx_ctx_setup(struct tx_ring *, struct mbuf *);
169 static bool ixgbe_tso_setup(struct tx_ring *, 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 /* Support for pluggable optic modules */
185 static bool ixgbe_sfp_probe(struct adapter *);
186 static void ixgbe_setup_optics(struct adapter *);
188 /* Legacy (single vector interrupt handler */
189 static void ixgbe_legacy_irq(void *);
191 /* The MSI/X Interrupt handlers */
192 static void ixgbe_msix_que(void *);
193 static void ixgbe_msix_link(void *);
195 /* Deferred interrupt tasklets */
196 static void ixgbe_handle_que(void *, int);
197 static void ixgbe_handle_link(void *, int);
198 static void ixgbe_handle_msf(void *, int);
199 static void ixgbe_handle_mod(void *, int);
202 static void ixgbe_atr(struct tx_ring *, struct mbuf *);
203 static void ixgbe_reinit_fdir(void *, int);
206 /*********************************************************************
207 * FreeBSD Device Interface Entry Points
208 *********************************************************************/
210 static device_method_t ixgbe_methods[] = {
211 /* Device interface */
212 DEVMETHOD(device_probe, ixgbe_probe),
213 DEVMETHOD(device_attach, ixgbe_attach),
214 DEVMETHOD(device_detach, ixgbe_detach),
215 DEVMETHOD(device_shutdown, ixgbe_shutdown),
219 static driver_t ixgbe_driver = {
220 "ix", ixgbe_methods, sizeof(struct adapter),
223 devclass_t ixgbe_devclass;
224 DRIVER_MODULE(ixgbe, pci, ixgbe_driver, ixgbe_devclass, 0, 0);
226 MODULE_DEPEND(ixgbe, pci, 1, 1, 1);
227 MODULE_DEPEND(ixgbe, ether, 1, 1, 1);
230 ** TUNEABLE PARAMETERS:
234 ** AIM: Adaptive Interrupt Moderation
235 ** which means that the interrupt rate
236 ** is varied over time based on the
237 ** traffic for that interrupt vector
239 static int ixgbe_enable_aim = TRUE;
240 TUNABLE_INT("hw.ixgbe.enable_aim", &ixgbe_enable_aim);
242 static int ixgbe_max_interrupt_rate = (4000000 / IXGBE_LOW_LATENCY);
243 TUNABLE_INT("hw.ixgbe.max_interrupt_rate", &ixgbe_max_interrupt_rate);
245 /* How many packets rxeof tries to clean at a time */
246 static int ixgbe_rx_process_limit = 128;
247 TUNABLE_INT("hw.ixgbe.rx_process_limit", &ixgbe_rx_process_limit);
250 ** Smart speed setting, default to on
251 ** this only works as a compile option
252 ** right now as its during attach, set
253 ** this to 'ixgbe_smart_speed_off' to
256 static int ixgbe_smart_speed = ixgbe_smart_speed_on;
258 static int ixgbe_msi_enable = 1;
259 TUNABLE_INT("hw.ixgbe.msi.enable", &ixgbe_msi_enable);
262 * MSIX should be the default for best performance,
263 * but this allows it to be forced off for testing.
265 static int ixgbe_enable_msix = 1;
266 TUNABLE_INT("hw.ixgbe.enable_msix", &ixgbe_enable_msix);
269 * Header split: this causes the hardware to DMA
270 * the header into a separate mbuf from the payload,
271 * it can be a performance win in some workloads, but
272 * in others it actually hurts, its off by default.
274 static int ixgbe_header_split = FALSE;
275 TUNABLE_INT("hw.ixgbe.hdr_split", &ixgbe_header_split);
278 * Number of Queues, can be set to 0,
279 * it then autoconfigures based on the
280 * number of cpus with a max of 8. This
281 * can be overriden manually here.
283 static int ixgbe_num_queues = 0;
284 TUNABLE_INT("hw.ixgbe.num_queues", &ixgbe_num_queues);
287 ** Number of TX descriptors per ring,
288 ** setting higher than RX as this seems
289 ** the better performing choice.
291 static int ixgbe_txd = PERFORM_TXD;
292 TUNABLE_INT("hw.ixgbe.txd", &ixgbe_txd);
294 /* Number of RX descriptors per ring */
295 static int ixgbe_rxd = PERFORM_RXD;
296 TUNABLE_INT("hw.ixgbe.rxd", &ixgbe_rxd);
298 /* Keep running tab on them for sanity check */
299 static int ixgbe_total_ports;
303 ** For Flow Director: this is the
304 ** number of TX packets we sample
305 ** for the filter pool, this means
306 ** every 20th packet will be probed.
308 ** This feature can be disabled by
309 ** setting this to 0.
311 static int atr_sample_rate = 20;
313 ** Flow Director actually 'steals'
314 ** part of the packet buffer as its
315 ** filter pool, this variable controls
317 ** 0 = 64K, 1 = 128K, 2 = 256K
319 static int fdir_pballoc = 1;
324 * The #ifdef DEV_NETMAP / #endif blocks in this file are meant to
325 * be a reference on how to implement netmap support in a driver.
326 * Additional comments are in ixgbe_netmap.h .
328 * <dev/netmap/ixgbe_netmap.h> contains functions for netmap support
329 * that extend the standard driver.
331 #include <dev/netmap/ixgbe_netmap.h>
332 #endif /* DEV_NETMAP */
334 /*********************************************************************
335 * Device identification routine
337 * ixgbe_probe determines if the driver should be loaded on
338 * adapter based on PCI vendor/device id of the adapter.
340 * return BUS_PROBE_DEFAULT on success, positive on failure
341 *********************************************************************/
344 ixgbe_probe(device_t dev)
346 ixgbe_vendor_info_t *ent;
348 u16 pci_vendor_id = 0;
349 u16 pci_device_id = 0;
350 u16 pci_subvendor_id = 0;
351 u16 pci_subdevice_id = 0;
352 char adapter_name[256];
354 INIT_DEBUGOUT("ixgbe_probe: begin");
356 pci_vendor_id = pci_get_vendor(dev);
357 if (pci_vendor_id != IXGBE_INTEL_VENDOR_ID)
360 pci_device_id = pci_get_device(dev);
361 pci_subvendor_id = pci_get_subvendor(dev);
362 pci_subdevice_id = pci_get_subdevice(dev);
364 ent = ixgbe_vendor_info_array;
365 while (ent->vendor_id != 0) {
366 if ((pci_vendor_id == ent->vendor_id) &&
367 (pci_device_id == ent->device_id) &&
369 ((pci_subvendor_id == ent->subvendor_id) ||
370 (ent->subvendor_id == 0)) &&
372 ((pci_subdevice_id == ent->subdevice_id) ||
373 (ent->subdevice_id == 0))) {
374 ksprintf(adapter_name, "%s, Version - %s",
375 ixgbe_strings[ent->index],
376 ixgbe_driver_version);
377 device_set_desc_copy(dev, adapter_name);
379 return (BUS_PROBE_DEFAULT);
386 /*********************************************************************
387 * Device initialization routine
389 * The attach entry point is called when the driver is being loaded.
390 * This routine identifies the type of hardware, allocates all resources
391 * and initializes the hardware.
393 * return 0 on success, positive on failure
394 *********************************************************************/
397 ixgbe_attach(device_t dev)
399 struct adapter *adapter;
405 INIT_DEBUGOUT("ixgbe_attach: begin");
407 if (resource_disabled("ixgbe", device_get_unit(dev))) {
408 device_printf(dev, "Disabled by device hint\n");
412 /* Allocate, clear, and link in our adapter structure */
413 adapter = device_get_softc(dev);
414 adapter->dev = adapter->osdep.dev = dev;
418 IXGBE_CORE_LOCK_INIT(adapter, device_get_nameunit(dev));
422 sysctl_ctx_init(&adapter->sysctl_ctx);
423 adapter->sysctl_tree = SYSCTL_ADD_NODE(&adapter->sysctl_ctx,
424 SYSCTL_STATIC_CHILDREN(_hw), OID_AUTO,
425 device_get_nameunit(adapter->dev), CTLFLAG_RD, 0, "");
426 if (adapter->sysctl_tree == NULL) {
427 device_printf(adapter->dev, "can't add sysctl node\n");
430 SYSCTL_ADD_PROC(&adapter->sysctl_ctx,
431 SYSCTL_CHILDREN(adapter->sysctl_tree),
432 OID_AUTO, "fc", CTLTYPE_INT | CTLFLAG_RW,
433 adapter, 0, ixgbe_set_flowcntl, "I", "Flow Control");
435 SYSCTL_ADD_INT(&adapter->sysctl_ctx,
436 SYSCTL_CHILDREN(adapter->sysctl_tree),
437 OID_AUTO, "enable_aim", CTLTYPE_INT|CTLFLAG_RW,
438 &ixgbe_enable_aim, 1, "Interrupt Moderation");
441 ** Allow a kind of speed control by forcing the autoneg
442 ** advertised speed list to only a certain value, this
443 ** supports 1G on 82599 devices, and 100Mb on x540.
445 SYSCTL_ADD_PROC(&adapter->sysctl_ctx,
446 SYSCTL_CHILDREN(adapter->sysctl_tree),
447 OID_AUTO, "advertise_speed", CTLTYPE_INT | CTLFLAG_RW,
448 adapter, 0, ixgbe_set_advertise, "I", "Link Speed");
450 SYSCTL_ADD_PROC(&adapter->sysctl_ctx,
451 SYSCTL_CHILDREN(adapter->sysctl_tree),
452 OID_AUTO, "ts", CTLTYPE_INT | CTLFLAG_RW, adapter,
453 0, ixgbe_set_thermal_test, "I", "Thermal Test");
455 /* Set up the timer callout */
456 callout_init_mp(&adapter->timer);
458 /* Determine hardware revision */
459 ixgbe_identify_hardware(adapter);
461 /* Do base PCI setup - map BAR0 */
462 if (ixgbe_allocate_pci_resources(adapter)) {
463 device_printf(dev, "Allocation of PCI resources failed\n");
468 /* Do descriptor calc and sanity checks */
469 if (((ixgbe_txd * sizeof(union ixgbe_adv_tx_desc)) % DBA_ALIGN) != 0 ||
470 ixgbe_txd < MIN_TXD || ixgbe_txd > MAX_TXD) {
471 device_printf(dev, "TXD config issue, using default!\n");
472 adapter->num_tx_desc = DEFAULT_TXD;
474 adapter->num_tx_desc = ixgbe_txd;
477 ** With many RX rings it is easy to exceed the
478 ** system mbuf allocation. Tuning nmbclusters
479 ** can alleviate this.
481 if (nmbclusters > 0 ) {
483 s = (ixgbe_rxd * adapter->num_queues) * ixgbe_total_ports;
484 if (s > nmbclusters) {
485 device_printf(dev, "RX Descriptors exceed "
486 "system mbuf max, using default instead!\n");
487 ixgbe_rxd = DEFAULT_RXD;
491 if (((ixgbe_rxd * sizeof(union ixgbe_adv_rx_desc)) % DBA_ALIGN) != 0 ||
492 ixgbe_rxd < MIN_TXD || ixgbe_rxd > MAX_TXD) {
493 device_printf(dev, "RXD config issue, using default!\n");
494 adapter->num_rx_desc = DEFAULT_RXD;
496 adapter->num_rx_desc = ixgbe_rxd;
498 /* Allocate our TX/RX Queues */
499 if (ixgbe_allocate_queues(adapter)) {
504 /* Allocate multicast array memory. */
505 adapter->mta = kmalloc(sizeof(u8) * IXGBE_ETH_LENGTH_OF_ADDRESS *
506 MAX_NUM_MULTICAST_ADDRESSES, M_DEVBUF, M_NOWAIT);
507 if (adapter->mta == NULL) {
508 device_printf(dev, "Can not allocate multicast setup array\n");
513 /* Initialize the shared code */
514 error = ixgbe_init_shared_code(hw);
515 if (error == IXGBE_ERR_SFP_NOT_PRESENT) {
517 ** No optics in this port, set up
518 ** so the timer routine will probe
519 ** for later insertion.
521 adapter->sfp_probe = TRUE;
523 } else if (error == IXGBE_ERR_SFP_NOT_SUPPORTED) {
524 device_printf(dev,"Unsupported SFP+ module detected!\n");
528 device_printf(dev,"Unable to initialize the shared code\n");
533 /* Make sure we have a good EEPROM before we read from it */
534 if (ixgbe_validate_eeprom_checksum(&adapter->hw, &csum) < 0) {
535 device_printf(dev,"The EEPROM Checksum Is Not Valid\n");
540 error = ixgbe_init_hw(hw);
542 case IXGBE_ERR_EEPROM_VERSION:
543 device_printf(dev, "This device is a pre-production adapter/"
544 "LOM. Please be aware there may be issues associated "
545 "with your hardware.\n If you are experiencing problems "
546 "please contact your Intel or hardware representative "
547 "who provided you with this hardware.\n");
549 case IXGBE_ERR_SFP_NOT_SUPPORTED:
550 device_printf(dev,"Unsupported SFP+ Module\n");
552 device_printf(dev,"Hardware Initialization Failure\n");
554 case IXGBE_ERR_SFP_NOT_PRESENT:
555 device_printf(dev,"No SFP+ Module found\n");
561 /* Detect and set physical type */
562 ixgbe_setup_optics(adapter);
564 if ((adapter->msix > 1) && (ixgbe_enable_msix))
565 error = ixgbe_allocate_msix(adapter);
567 error = ixgbe_allocate_legacy(adapter);
571 /* Setup OS specific network interface */
572 if (ixgbe_setup_interface(dev, adapter) != 0)
575 /* Sysctl for limiting the amount of work done in the taskqueue */
576 ixgbe_add_rx_process_limit(adapter, "rx_processing_limit",
577 "max number of rx packets to process", &adapter->rx_process_limit,
578 ixgbe_rx_process_limit);
580 /* Initialize statistics */
581 ixgbe_update_stats_counters(adapter);
583 /* Register for VLAN events */
584 adapter->vlan_attach = EVENTHANDLER_REGISTER(vlan_config,
585 ixgbe_register_vlan, adapter, EVENTHANDLER_PRI_FIRST);
586 adapter->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig,
587 ixgbe_unregister_vlan, adapter, EVENTHANDLER_PRI_FIRST);
589 /* Print PCIE bus type/speed/width info */
590 ixgbe_get_bus_info(hw);
591 device_printf(dev,"PCI Express Bus: Speed %s %s\n",
592 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
593 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
594 (hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
595 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
596 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
599 if ((hw->bus.width <= ixgbe_bus_width_pcie_x4) &&
600 (hw->bus.speed == ixgbe_bus_speed_2500)) {
601 device_printf(dev, "PCI-Express bandwidth available"
602 " for this card\n is not sufficient for"
603 " optimal performance.\n");
604 device_printf(dev, "For optimal performance a x8 "
605 "PCIE, or x4 PCIE 2 slot is required.\n");
608 /* let hardware know driver is loaded */
609 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
610 ctrl_ext |= IXGBE_CTRL_EXT_DRV_LOAD;
611 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
613 ixgbe_add_hw_stats(adapter);
616 ixgbe_netmap_attach(adapter);
617 #endif /* DEV_NETMAP */
618 INIT_DEBUGOUT("ixgbe_attach: end");
621 ixgbe_free_transmit_structures(adapter);
622 ixgbe_free_receive_structures(adapter);
624 if (adapter->ifp != NULL)
625 if_free(adapter->ifp);
626 ixgbe_free_pci_resources(adapter);
627 kfree(adapter->mta, M_DEVBUF);
632 /*********************************************************************
633 * Device removal routine
635 * The detach entry point is called when the driver is being removed.
636 * This routine stops the adapter and deallocates all the resources
637 * that were allocated for driver operation.
639 * return 0 on success, positive on failure
640 *********************************************************************/
643 ixgbe_detach(device_t dev)
645 struct adapter *adapter = device_get_softc(dev);
646 struct ix_queue *que = adapter->queues;
649 INIT_DEBUGOUT("ixgbe_detach: begin");
651 /* Make sure VLANS are not using driver */
652 if (adapter->ifp->if_vlantrunks != NULL) {
653 device_printf(dev,"Vlan in use, detach first\n");
657 IXGBE_CORE_LOCK(adapter);
659 IXGBE_CORE_UNLOCK(adapter);
661 for (int i = 0; i < adapter->num_queues; i++, que++) {
663 taskqueue_drain(que->tq, &que->que_task);
664 taskqueue_free(que->tq);
668 /* Drain the Link queue */
670 taskqueue_drain(adapter->tq, &adapter->link_task);
671 taskqueue_drain(adapter->tq, &adapter->mod_task);
672 taskqueue_drain(adapter->tq, &adapter->msf_task);
674 taskqueue_drain(adapter->tq, &adapter->fdir_task);
676 taskqueue_free(adapter->tq);
679 /* let hardware know driver is unloading */
680 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
681 ctrl_ext &= ~IXGBE_CTRL_EXT_DRV_LOAD;
682 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, ctrl_ext);
684 /* Unregister VLAN events */
685 if (adapter->vlan_attach != NULL)
686 EVENTHANDLER_DEREGISTER(vlan_config, adapter->vlan_attach);
687 if (adapter->vlan_detach != NULL)
688 EVENTHANDLER_DEREGISTER(vlan_unconfig, adapter->vlan_detach);
690 ether_ifdetach(adapter->ifp);
691 callout_stop(&adapter->timer);
693 netmap_detach(adapter->ifp);
694 #endif /* DEV_NETMAP */
695 ixgbe_free_pci_resources(adapter);
696 bus_generic_detach(dev);
697 if_free(adapter->ifp);
699 ixgbe_free_transmit_structures(adapter);
700 ixgbe_free_receive_structures(adapter);
701 kfree(adapter->mta, M_DEVBUF);
702 sysctl_ctx_free(&adapter->sysctl_ctx);
704 IXGBE_CORE_LOCK_DESTROY(adapter);
708 /*********************************************************************
710 * Shutdown entry point
712 **********************************************************************/
715 ixgbe_shutdown(device_t dev)
717 struct adapter *adapter = device_get_softc(dev);
718 IXGBE_CORE_LOCK(adapter);
720 IXGBE_CORE_UNLOCK(adapter);
725 /*********************************************************************
726 * Transmit entry point
728 * ixgbe_start is called by the stack to initiate a transmit.
729 * The driver will remain in this routine as long as there are
730 * packets to transmit and transmit resources are available.
731 * In case resources are not available stack is notified and
732 * the packet is requeued.
733 **********************************************************************/
736 ixgbe_start_locked(struct tx_ring *txr, struct ifnet * ifp)
739 struct adapter *adapter = txr->adapter;
741 IXGBE_TX_LOCK_ASSERT(txr);
743 if ((ifp->if_flags & (IFF_RUNNING|IFF_OACTIVE)) != IFF_RUNNING)
745 if (!adapter->link_active)
748 while (!ifq_is_empty(&ifp->if_snd)) {
749 if (txr->tx_avail <= IXGBE_QUEUE_MIN_FREE) {
750 txr->queue_status |= IXGBE_QUEUE_DEPLETED;
754 m_head = ifq_dequeue(&ifp->if_snd, NULL);
758 if (ixgbe_xmit(txr, &m_head)) {
759 #if 0 /* XXX: prepend to an ALTQ queue ? */
761 IF_PREPEND(&ifp->if_snd, m_head);
763 if (txr->tx_avail <= IXGBE_QUEUE_MIN_FREE)
764 txr->queue_status |= IXGBE_QUEUE_DEPLETED;
767 /* Send a copy of the frame to the BPF listener */
768 ETHER_BPF_MTAP(ifp, m_head);
770 /* Set watchdog on */
771 txr->watchdog_time = ticks;
772 txr->queue_status = IXGBE_QUEUE_WORKING;
779 * Legacy TX start - called by the stack, this
780 * always uses the first tx ring, and should
781 * not be used with multiqueue tx enabled.
784 ixgbe_start(struct ifnet *ifp)
786 struct adapter *adapter = ifp->if_softc;
787 struct tx_ring *txr = adapter->tx_rings;
789 if (ifp->if_flags & IFF_RUNNING) {
791 ixgbe_start_locked(txr, ifp);
792 IXGBE_TX_UNLOCK(txr);
797 #if 0 /* __FreeBSD_version >= 800000 */
799 ** Multiqueue Transmit driver
803 ixgbe_mq_start(struct ifnet *ifp, struct mbuf *m)
805 struct adapter *adapter = ifp->if_softc;
806 struct ix_queue *que;
810 /* Which queue to use */
811 if ((m->m_flags & M_FLOWID) != 0)
812 i = m->m_pkthdr.flowid % adapter->num_queues;
814 i = curcpu % adapter->num_queues;
816 txr = &adapter->tx_rings[i];
817 que = &adapter->queues[i];
819 if (((txr->queue_status & IXGBE_QUEUE_DEPLETED) == 0) &&
820 IXGBE_TX_TRYLOCK(txr)) {
821 err = ixgbe_mq_start_locked(ifp, txr, m);
822 IXGBE_TX_UNLOCK(txr);
824 err = drbr_enqueue(ifp, txr->br, m);
825 taskqueue_enqueue(que->tq, &que->que_task);
832 ixgbe_mq_start_locked(struct ifnet *ifp, struct tx_ring *txr, struct mbuf *m)
834 struct adapter *adapter = txr->adapter;
836 int enqueued, err = 0;
838 if (((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) ||
839 (txr->queue_status == IXGBE_QUEUE_DEPLETED) ||
840 adapter->link_active == 0) {
842 err = drbr_enqueue(ifp, txr->br, m);
848 next = drbr_dequeue(ifp, txr->br);
849 } else if (drbr_needs_enqueue(ifp, txr->br)) {
850 if ((err = drbr_enqueue(ifp, txr->br, m)) != 0)
852 next = drbr_dequeue(ifp, txr->br);
856 /* Process the queue */
857 while (next != NULL) {
858 if ((err = ixgbe_xmit(txr, &next)) != 0) {
860 err = drbr_enqueue(ifp, txr->br, next);
864 drbr_stats_update(ifp, next->m_pkthdr.len, next->m_flags);
865 /* Send a copy of the frame to the BPF listener */
866 ETHER_BPF_MTAP(ifp, next);
867 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
869 if (txr->tx_avail < IXGBE_TX_OP_THRESHOLD)
871 if (txr->tx_avail < IXGBE_TX_OP_THRESHOLD) {
872 txr->queue_status |= IXGBE_QUEUE_DEPLETED;
875 next = drbr_dequeue(ifp, txr->br);
879 /* Set watchdog on */
880 txr->queue_status |= IXGBE_QUEUE_WORKING;
881 txr->watchdog_time = ticks;
884 if (txr->tx_avail < IXGBE_TX_CLEANUP_THRESHOLD)
891 ** Flush all ring buffers
894 ixgbe_qflush(struct ifnet *ifp)
896 struct adapter *adapter = ifp->if_softc;
897 struct tx_ring *txr = adapter->tx_rings;
900 for (int i = 0; i < adapter->num_queues; i++, txr++) {
902 while ((m = buf_ring_dequeue_sc(txr->br)) != NULL)
904 IXGBE_TX_UNLOCK(txr);
908 #endif /* __FreeBSD_version >= 800000 */
910 /*********************************************************************
913 * ixgbe_ioctl is called when the user wants to configure the
916 * return 0 on success, positive on failure
917 **********************************************************************/
920 ixgbe_ioctl(struct ifnet *ifp, u_long command, caddr_t data, struct ucred *cr)
922 struct adapter *adapter = ifp->if_softc;
923 struct ifreq *ifr = (struct ifreq *) data;
924 #if defined(INET) || defined(INET6)
925 struct ifaddr *ifa = (struct ifaddr *)data;
926 bool avoid_reset = FALSE;
934 if (ifa->ifa_addr->sa_family == AF_INET)
938 if (ifa->ifa_addr->sa_family == AF_INET6)
941 #if defined(INET) || defined(INET6)
943 ** Calling init results in link renegotiation,
944 ** so we avoid doing it when possible.
947 ifp->if_flags |= IFF_UP;
948 if (!(ifp->if_flags & IFF_RUNNING))
950 if (!(ifp->if_flags & IFF_NOARP))
951 arp_ifinit(ifp, ifa);
953 error = ether_ioctl(ifp, command, data);
957 IOCTL_DEBUGOUT("ioctl: SIOCSIFMTU (Set Interface MTU)");
958 if (ifr->ifr_mtu > IXGBE_MAX_FRAME_SIZE - ETHER_HDR_LEN) {
961 IXGBE_CORE_LOCK(adapter);
962 ifp->if_mtu = ifr->ifr_mtu;
963 adapter->max_frame_size =
964 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
965 ixgbe_init_locked(adapter);
966 IXGBE_CORE_UNLOCK(adapter);
970 IOCTL_DEBUGOUT("ioctl: SIOCSIFFLAGS (Set Interface Flags)");
971 IXGBE_CORE_LOCK(adapter);
972 if (ifp->if_flags & IFF_UP) {
973 if ((ifp->if_flags & IFF_RUNNING)) {
974 if ((ifp->if_flags ^ adapter->if_flags) &
975 (IFF_PROMISC | IFF_ALLMULTI)) {
976 ixgbe_set_promisc(adapter);
979 ixgbe_init_locked(adapter);
981 if (ifp->if_flags & IFF_RUNNING)
983 adapter->if_flags = ifp->if_flags;
984 IXGBE_CORE_UNLOCK(adapter);
988 IOCTL_DEBUGOUT("ioctl: SIOC(ADD|DEL)MULTI");
989 if (ifp->if_flags & IFF_RUNNING) {
990 IXGBE_CORE_LOCK(adapter);
991 ixgbe_disable_intr(adapter);
992 ixgbe_set_multi(adapter);
993 ixgbe_enable_intr(adapter);
994 IXGBE_CORE_UNLOCK(adapter);
999 IOCTL_DEBUGOUT("ioctl: SIOCxIFMEDIA (Get/Set Interface Media)");
1000 error = ifmedia_ioctl(ifp, ifr, &adapter->media, command);
1004 int mask = ifr->ifr_reqcap ^ ifp->if_capenable;
1005 IOCTL_DEBUGOUT("ioctl: SIOCSIFCAP (Set Capabilities)");
1006 if (mask & IFCAP_HWCSUM)
1007 ifp->if_capenable ^= IFCAP_HWCSUM;
1008 if (mask & IFCAP_TSO4)
1009 ifp->if_capenable ^= IFCAP_TSO4;
1010 if (mask & IFCAP_TSO6)
1011 ifp->if_capenable ^= IFCAP_TSO6;
1013 if (mask & IFCAP_LRO)
1014 ifp->if_capenable ^= IFCAP_LRO;
1016 if (mask & IFCAP_VLAN_HWTAGGING)
1017 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
1018 if (mask & IFCAP_VLAN_HWFILTER)
1019 ifp->if_capenable ^= IFCAP_VLAN_HWFILTER;
1021 if (mask & IFCAP_VLAN_HWTSO)
1022 ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
1024 if (ifp->if_flags & IFF_RUNNING) {
1025 IXGBE_CORE_LOCK(adapter);
1026 ixgbe_init_locked(adapter);
1027 IXGBE_CORE_UNLOCK(adapter);
1030 VLAN_CAPABILITIES(ifp);
1036 IOCTL_DEBUGOUT1("ioctl: UNKNOWN (0x%X)\n", (int)command);
1037 error = ether_ioctl(ifp, command, data);
1044 /*********************************************************************
1047 * This routine is used in two ways. It is used by the stack as
1048 * init entry point in network interface structure. It is also used
1049 * by the driver as a hw/sw initialization routine to get to a
1052 * return 0 on success, positive on failure
1053 **********************************************************************/
1054 #define IXGBE_MHADD_MFS_SHIFT 16
1057 ixgbe_init_locked(struct adapter *adapter)
1059 struct ifnet *ifp = adapter->ifp;
1060 device_t dev = adapter->dev;
1061 struct ixgbe_hw *hw = &adapter->hw;
1062 u32 k, txdctl, mhadd, gpie;
1065 KKASSERT(lockstatus(&adapter->core_lock, curthread) != 0);
1066 INIT_DEBUGOUT("ixgbe_init: begin");
1067 hw->adapter_stopped = FALSE;
1068 ixgbe_stop_adapter(hw);
1069 callout_stop(&adapter->timer);
1071 /* reprogram the RAR[0] in case user changed it. */
1072 ixgbe_set_rar(hw, 0, adapter->hw.mac.addr, 0, IXGBE_RAH_AV);
1074 /* Get the latest mac address, User can use a LAA */
1075 bcopy(IF_LLADDR(adapter->ifp), hw->mac.addr,
1076 IXGBE_ETH_LENGTH_OF_ADDRESS);
1077 ixgbe_set_rar(hw, 0, hw->mac.addr, 0, 1);
1078 hw->addr_ctrl.rar_used_count = 1;
1080 /* Set the various hardware offload abilities */
1081 ifp->if_hwassist = 0;
1082 if (ifp->if_capenable & IFCAP_TSO)
1083 ifp->if_hwassist |= CSUM_TSO;
1084 if (ifp->if_capenable & IFCAP_TXCSUM) {
1085 ifp->if_hwassist |= (CSUM_TCP | CSUM_UDP);
1087 if (hw->mac.type != ixgbe_mac_82598EB)
1088 ifp->if_hwassist |= CSUM_SCTP;
1092 /* Prepare transmit descriptors and buffers */
1093 if (ixgbe_setup_transmit_structures(adapter)) {
1094 device_printf(dev,"Could not setup transmit structures\n");
1095 ixgbe_stop(adapter);
1100 ixgbe_initialize_transmit_units(adapter);
1102 /* Setup Multicast table */
1103 ixgbe_set_multi(adapter);
1106 ** Determine the correct mbuf pool
1107 ** for doing jumbo/headersplit
1109 if (adapter->max_frame_size <= 2048)
1110 adapter->rx_mbuf_sz = MCLBYTES;
1111 else if (adapter->max_frame_size <= 4096)
1112 adapter->rx_mbuf_sz = MJUMPAGESIZE;
1113 else if (adapter->max_frame_size <= 9216)
1114 adapter->rx_mbuf_sz = MJUM9BYTES;
1116 adapter->rx_mbuf_sz = MJUM16BYTES;
1118 /* Prepare receive descriptors and buffers */
1119 if (ixgbe_setup_receive_structures(adapter)) {
1120 device_printf(dev,"Could not setup receive structures\n");
1121 ixgbe_stop(adapter);
1125 /* Configure RX settings */
1126 ixgbe_initialize_receive_units(adapter);
1128 gpie = IXGBE_READ_REG(&adapter->hw, IXGBE_GPIE);
1130 /* Enable Fan Failure Interrupt */
1131 gpie |= IXGBE_SDP1_GPIEN;
1133 /* Add for Module detection */
1134 if (hw->mac.type == ixgbe_mac_82599EB)
1135 gpie |= IXGBE_SDP2_GPIEN;
1137 /* Thermal Failure Detection */
1138 if (hw->mac.type == ixgbe_mac_X540)
1139 gpie |= IXGBE_SDP0_GPIEN;
1141 if (adapter->msix > 1) {
1142 /* Enable Enhanced MSIX mode */
1143 gpie |= IXGBE_GPIE_MSIX_MODE;
1144 gpie |= IXGBE_GPIE_EIAME | IXGBE_GPIE_PBA_SUPPORT |
1147 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
1150 if (ifp->if_mtu > ETHERMTU) {
1151 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
1152 mhadd &= ~IXGBE_MHADD_MFS_MASK;
1153 mhadd |= adapter->max_frame_size << IXGBE_MHADD_MFS_SHIFT;
1154 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
1157 /* Now enable all the queues */
1159 for (int i = 0; i < adapter->num_queues; i++) {
1160 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
1161 txdctl |= IXGBE_TXDCTL_ENABLE;
1162 /* Set WTHRESH to 8, burst writeback */
1163 txdctl |= (8 << 16);
1165 * When the internal queue falls below PTHRESH (32),
1166 * start prefetching as long as there are at least
1167 * HTHRESH (1) buffers ready. The values are taken
1168 * from the Intel linux driver 3.8.21.
1169 * Prefetching enables tx line rate even with 1 queue.
1171 txdctl |= (32 << 0) | (1 << 8);
1172 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), txdctl);
1175 for (int i = 0; i < adapter->num_queues; i++) {
1176 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
1177 if (hw->mac.type == ixgbe_mac_82598EB) {
1183 rxdctl &= ~0x3FFFFF;
1186 rxdctl |= IXGBE_RXDCTL_ENABLE;
1187 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), rxdctl);
1188 for (k = 0; k < 10; k++) {
1189 if (IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)) &
1190 IXGBE_RXDCTL_ENABLE)
1198 * In netmap mode, we must preserve the buffers made
1199 * available to userspace before the if_init()
1200 * (this is true by default on the TX side, because
1201 * init makes all buffers available to userspace).
1203 * netmap_reset() and the device specific routines
1204 * (e.g. ixgbe_setup_receive_rings()) map these
1205 * buffers at the end of the NIC ring, so here we
1206 * must set the RDT (tail) register to make sure
1207 * they are not overwritten.
1209 * In this driver the NIC ring starts at RDH = 0,
1210 * RDT points to the last slot available for reception (?),
1211 * so RDT = num_rx_desc - 1 means the whole ring is available.
1213 if (ifp->if_capenable & IFCAP_NETMAP) {
1214 struct netmap_adapter *na = NA(adapter->ifp);
1215 struct netmap_kring *kring = &na->rx_rings[i];
1216 int t = na->num_rx_desc - 1 - kring->nr_hwavail;
1218 IXGBE_WRITE_REG(hw, IXGBE_RDT(i), t);
1220 #endif /* DEV_NETMAP */
1221 IXGBE_WRITE_REG(hw, IXGBE_RDT(i), adapter->num_rx_desc - 1);
1224 /* Set up VLAN support and filter */
1225 ixgbe_setup_vlan_hw_support(adapter);
1227 /* Enable Receive engine */
1228 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1229 if (hw->mac.type == ixgbe_mac_82598EB)
1230 rxctrl |= IXGBE_RXCTRL_DMBYPS;
1231 rxctrl |= IXGBE_RXCTRL_RXEN;
1232 ixgbe_enable_rx_dma(hw, rxctrl);
1234 callout_reset(&adapter->timer, hz, ixgbe_local_timer, adapter);
1236 /* Set up MSI/X routing */
1237 if (ixgbe_enable_msix) {
1238 ixgbe_configure_ivars(adapter);
1239 /* Set up auto-mask */
1240 if (hw->mac.type == ixgbe_mac_82598EB)
1241 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
1243 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
1244 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
1246 } else { /* Simple settings for Legacy/MSI */
1247 ixgbe_set_ivar(adapter, 0, 0, 0);
1248 ixgbe_set_ivar(adapter, 0, 0, 1);
1249 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
1253 /* Init Flow director */
1254 if (hw->mac.type != ixgbe_mac_82598EB) {
1255 u32 hdrm = 32 << fdir_pballoc;
1257 hw->mac.ops.setup_rxpba(hw, 0, hdrm, PBA_STRATEGY_EQUAL);
1258 ixgbe_init_fdir_signature_82599(&adapter->hw, fdir_pballoc);
1263 ** Check on any SFP devices that
1264 ** need to be kick-started
1266 if (hw->phy.type == ixgbe_phy_none) {
1267 int err = hw->phy.ops.identify(hw);
1268 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
1270 "Unsupported SFP+ module type was detected.\n");
1275 /* Set moderation on the Link interrupt */
1276 IXGBE_WRITE_REG(hw, IXGBE_EITR(adapter->linkvec), IXGBE_LINK_ITR);
1278 /* Config/Enable Link */
1279 ixgbe_config_link(adapter);
1281 /* Hardware Packet Buffer & Flow Control setup */
1283 u32 rxpb, frame, size, tmp;
1285 frame = adapter->max_frame_size;
1287 /* Calculate High Water */
1288 if (hw->mac.type == ixgbe_mac_X540)
1289 tmp = IXGBE_DV_X540(frame, frame);
1291 tmp = IXGBE_DV(frame, frame);
1292 size = IXGBE_BT2KB(tmp);
1293 rxpb = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0)) >> 10;
1294 hw->fc.high_water[0] = rxpb - size;
1296 /* Now calculate Low Water */
1297 if (hw->mac.type == ixgbe_mac_X540)
1298 tmp = IXGBE_LOW_DV_X540(frame);
1300 tmp = IXGBE_LOW_DV(frame);
1301 hw->fc.low_water[0] = IXGBE_BT2KB(tmp);
1303 adapter->fc = hw->fc.requested_mode = ixgbe_fc_full;
1304 hw->fc.pause_time = IXGBE_FC_PAUSE;
1305 hw->fc.send_xon = TRUE;
1307 /* Initialize the FC settings */
1310 /* And now turn on interrupts */
1311 ixgbe_enable_intr(adapter);
1313 /* Now inform the stack we're ready */
1314 ifp->if_flags |= IFF_RUNNING;
1315 ifp->if_flags &= ~IFF_OACTIVE;
1321 ixgbe_init(void *arg)
1323 struct adapter *adapter = arg;
1325 IXGBE_CORE_LOCK(adapter);
1326 ixgbe_init_locked(adapter);
1327 IXGBE_CORE_UNLOCK(adapter);
1334 ** MSIX Interrupt Handlers and Tasklets
1339 ixgbe_enable_queue(struct adapter *adapter, u32 vector)
1341 struct ixgbe_hw *hw = &adapter->hw;
1342 u64 queue = (u64)(1 << vector);
1345 if (hw->mac.type == ixgbe_mac_82598EB) {
1346 mask = (IXGBE_EIMS_RTX_QUEUE & queue);
1347 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1349 mask = (queue & 0xFFFFFFFF);
1351 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
1352 mask = (queue >> 32);
1354 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1359 ixgbe_disable_queue(struct adapter *adapter, u32 vector)
1361 struct ixgbe_hw *hw = &adapter->hw;
1362 u64 queue = (u64)(1 << vector);
1365 if (hw->mac.type == ixgbe_mac_82598EB) {
1366 mask = (IXGBE_EIMS_RTX_QUEUE & queue);
1367 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1369 mask = (queue & 0xFFFFFFFF);
1371 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
1372 mask = (queue >> 32);
1374 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1379 ixgbe_rearm_queues(struct adapter *adapter, u64 queues)
1383 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1384 mask = (IXGBE_EIMS_RTX_QUEUE & queues);
1385 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
1387 mask = (queues & 0xFFFFFFFF);
1388 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
1389 mask = (queues >> 32);
1390 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
1396 ixgbe_handle_que(void *context, int pending)
1398 struct ix_queue *que = context;
1399 struct adapter *adapter = que->adapter;
1400 struct tx_ring *txr = que->txr;
1401 struct ifnet *ifp = adapter->ifp;
1404 if (ifp->if_flags & IFF_RUNNING) {
1405 more = ixgbe_rxeof(que, adapter->rx_process_limit);
1408 #if 0 /*__FreeBSD_version >= 800000*/
1409 if (!drbr_empty(ifp, txr->br))
1410 ixgbe_mq_start_locked(ifp, txr, NULL);
1412 if (!ifq_is_empty(&ifp->if_snd))
1413 ixgbe_start_locked(txr, ifp);
1415 IXGBE_TX_UNLOCK(txr);
1417 taskqueue_enqueue(que->tq, &que->que_task);
1422 /* Reenable this interrupt */
1423 ixgbe_enable_queue(adapter, que->msix);
1428 /*********************************************************************
1430 * Legacy Interrupt Service routine
1432 **********************************************************************/
1435 ixgbe_legacy_irq(void *arg)
1437 struct ix_queue *que = arg;
1438 struct adapter *adapter = que->adapter;
1439 struct ixgbe_hw *hw = &adapter->hw;
1440 struct tx_ring *txr = adapter->tx_rings;
1441 bool more_tx, more_rx;
1442 u32 reg_eicr, loop = MAX_LOOP;
1445 reg_eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
1448 if (reg_eicr == 0) {
1449 ixgbe_enable_intr(adapter);
1453 more_rx = ixgbe_rxeof(que, adapter->rx_process_limit);
1457 more_tx = ixgbe_txeof(txr);
1458 } while (loop-- && more_tx);
1459 IXGBE_TX_UNLOCK(txr);
1461 if (more_rx || more_tx)
1462 taskqueue_enqueue(que->tq, &que->que_task);
1464 /* Check for fan failure */
1465 if ((hw->phy.media_type == ixgbe_media_type_copper) &&
1466 (reg_eicr & IXGBE_EICR_GPI_SDP1)) {
1467 device_printf(adapter->dev, "\nCRITICAL: FAN FAILURE!! "
1468 "REPLACE IMMEDIATELY!!\n");
1469 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EICR_GPI_SDP1);
1472 /* Link status change */
1473 if (reg_eicr & IXGBE_EICR_LSC)
1474 taskqueue_enqueue(adapter->tq, &adapter->link_task);
1476 ixgbe_enable_intr(adapter);
1481 /*********************************************************************
1483 * MSIX Queue Interrupt Service routine
1485 **********************************************************************/
1487 ixgbe_msix_que(void *arg)
1489 struct ix_queue *que = arg;
1490 struct adapter *adapter = que->adapter;
1491 struct tx_ring *txr = que->txr;
1492 struct rx_ring *rxr = que->rxr;
1493 bool more_tx, more_rx;
1496 ixgbe_disable_queue(adapter, que->msix);
1499 more_rx = ixgbe_rxeof(que, adapter->rx_process_limit);
1502 more_tx = ixgbe_txeof(txr);
1504 ** Make certain that if the stack
1505 ** has anything queued the task gets
1506 ** scheduled to handle it.
1509 #if __FreeBSD_version < 800000
1510 if (!IFQ_DRV_IS_EMPTY(&adapter->ifp->if_snd))
1512 if (!drbr_empty(adapter->ifp, txr->br))
1515 if (!ifq_is_empty(&adapter->ifp->if_snd))
1517 IXGBE_TX_UNLOCK(txr);
1521 if (ixgbe_enable_aim == FALSE)
1524 ** Do Adaptive Interrupt Moderation:
1525 ** - Write out last calculated setting
1526 ** - Calculate based on average size over
1527 ** the last interval.
1529 if (que->eitr_setting)
1530 IXGBE_WRITE_REG(&adapter->hw,
1531 IXGBE_EITR(que->msix), que->eitr_setting);
1533 que->eitr_setting = 0;
1535 /* Idle, do nothing */
1536 if ((txr->bytes == 0) && (rxr->bytes == 0))
1539 if ((txr->bytes) && (txr->packets))
1540 newitr = txr->bytes/txr->packets;
1541 if ((rxr->bytes) && (rxr->packets))
1542 newitr = max(newitr,
1543 (rxr->bytes / rxr->packets));
1544 newitr += 24; /* account for hardware frame, crc */
1546 /* set an upper boundary */
1547 newitr = min(newitr, 3000);
1549 /* Be nice to the mid range */
1550 if ((newitr > 300) && (newitr < 1200))
1551 newitr = (newitr / 3);
1553 newitr = (newitr / 2);
1555 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
1556 newitr |= newitr << 16;
1558 newitr |= IXGBE_EITR_CNT_WDIS;
1560 /* save for next interrupt */
1561 que->eitr_setting = newitr;
1570 if (more_tx || more_rx)
1571 taskqueue_enqueue(que->tq, &que->que_task);
1572 else /* Reenable this interrupt */
1573 ixgbe_enable_queue(adapter, que->msix);
1579 ixgbe_msix_link(void *arg)
1581 struct adapter *adapter = arg;
1582 struct ixgbe_hw *hw = &adapter->hw;
1585 ++adapter->link_irq;
1587 /* First get the cause */
1588 reg_eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1589 /* Clear interrupt with write */
1590 IXGBE_WRITE_REG(hw, IXGBE_EICR, reg_eicr);
1592 /* Link status change */
1593 if (reg_eicr & IXGBE_EICR_LSC)
1594 taskqueue_enqueue(adapter->tq, &adapter->link_task);
1596 if (adapter->hw.mac.type != ixgbe_mac_82598EB) {
1598 if (reg_eicr & IXGBE_EICR_FLOW_DIR) {
1599 /* This is probably overkill :) */
1600 if (!atomic_cmpset_int(&adapter->fdir_reinit, 0, 1))
1602 /* Disable the interrupt */
1603 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EICR_FLOW_DIR);
1604 taskqueue_enqueue(adapter->tq, &adapter->fdir_task);
1607 if (reg_eicr & IXGBE_EICR_ECC) {
1608 device_printf(adapter->dev, "\nCRITICAL: ECC ERROR!! "
1609 "Please Reboot!!\n");
1610 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
1613 if (reg_eicr & IXGBE_EICR_GPI_SDP1) {
1614 /* Clear the interrupt */
1615 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1616 taskqueue_enqueue(adapter->tq, &adapter->msf_task);
1617 } else if (reg_eicr & IXGBE_EICR_GPI_SDP2) {
1618 /* Clear the interrupt */
1619 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1620 taskqueue_enqueue(adapter->tq, &adapter->mod_task);
1624 /* Check for fan failure */
1625 if ((hw->device_id == IXGBE_DEV_ID_82598AT) &&
1626 (reg_eicr & IXGBE_EICR_GPI_SDP1)) {
1627 device_printf(adapter->dev, "\nCRITICAL: FAN FAILURE!! "
1628 "REPLACE IMMEDIATELY!!\n");
1629 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1632 /* Check for over temp condition */
1633 if ((hw->mac.type == ixgbe_mac_X540) &&
1634 (reg_eicr & IXGBE_EICR_GPI_SDP0)) {
1635 device_printf(adapter->dev, "\nCRITICAL: OVER TEMP!! "
1636 "PHY IS SHUT DOWN!!\n");
1637 device_printf(adapter->dev, "System shutdown required\n");
1638 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP0);
1641 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
1645 /*********************************************************************
1647 * Media Ioctl callback
1649 * This routine is called whenever the user queries the status of
1650 * the interface using ifconfig.
1652 **********************************************************************/
1654 ixgbe_media_status(struct ifnet * ifp, struct ifmediareq * ifmr)
1656 struct adapter *adapter = ifp->if_softc;
1658 INIT_DEBUGOUT("ixgbe_media_status: begin");
1659 IXGBE_CORE_LOCK(adapter);
1660 ixgbe_update_link_status(adapter);
1662 ifmr->ifm_status = IFM_AVALID;
1663 ifmr->ifm_active = IFM_ETHER;
1665 if (!adapter->link_active) {
1666 IXGBE_CORE_UNLOCK(adapter);
1670 ifmr->ifm_status |= IFM_ACTIVE;
1672 switch (adapter->link_speed) {
1673 case IXGBE_LINK_SPEED_100_FULL:
1674 ifmr->ifm_active |= IFM_100_TX | IFM_FDX;
1676 case IXGBE_LINK_SPEED_1GB_FULL:
1677 ifmr->ifm_active |= IFM_1000_T | IFM_FDX;
1679 case IXGBE_LINK_SPEED_10GB_FULL:
1680 ifmr->ifm_active |= adapter->optics | IFM_FDX;
1684 IXGBE_CORE_UNLOCK(adapter);
1689 /*********************************************************************
1691 * Media Ioctl callback
1693 * This routine is called when the user changes speed/duplex using
1694 * media/mediopt option with ifconfig.
1696 **********************************************************************/
1698 ixgbe_media_change(struct ifnet * ifp)
1700 struct adapter *adapter = ifp->if_softc;
1701 struct ifmedia *ifm = &adapter->media;
1703 INIT_DEBUGOUT("ixgbe_media_change: begin");
1705 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1708 switch (IFM_SUBTYPE(ifm->ifm_media)) {
1710 adapter->hw.phy.autoneg_advertised =
1711 IXGBE_LINK_SPEED_100_FULL |
1712 IXGBE_LINK_SPEED_1GB_FULL |
1713 IXGBE_LINK_SPEED_10GB_FULL;
1716 device_printf(adapter->dev, "Only auto media type\n");
1723 /*********************************************************************
1725 * This routine maps the mbufs to tx descriptors, allowing the
1726 * TX engine to transmit the packets.
1727 * - return 0 on success, positive on failure
1729 **********************************************************************/
1732 ixgbe_xmit(struct tx_ring *txr, struct mbuf **m_headp)
1734 struct adapter *adapter = txr->adapter;
1735 u32 olinfo_status = 0, cmd_type_len;
1737 int i, j, error, nsegs, maxsegs;
1738 int first, last = 0;
1739 struct mbuf *m_head;
1740 bus_dma_segment_t segs[adapter->num_segs];
1742 struct ixgbe_tx_buf *txbuf;
1743 union ixgbe_adv_tx_desc *txd = NULL;
1747 /* Basic descriptor defines */
1748 cmd_type_len = (IXGBE_ADVTXD_DTYP_DATA |
1749 IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT);
1751 if (m_head->m_flags & M_VLANTAG)
1752 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
1755 * Important to capture the first descriptor
1756 * used because it will contain the index of
1757 * the one we tell the hardware to report back
1759 first = txr->next_avail_desc;
1760 txbuf = &txr->tx_buffers[first];
1764 * Map the packet for DMA.
1766 maxsegs = txr->tx_avail - IXGBE_TX_RESERVED;
1767 if (maxsegs > adapter->num_segs)
1768 maxsegs = adapter->num_segs;
1770 error = bus_dmamap_load_mbuf_defrag(txr->txtag, map, m_headp,
1771 segs, maxsegs, &nsegs, BUS_DMA_NOWAIT);
1773 if (error == ENOBUFS)
1774 adapter->mbuf_defrag_failed++;
1776 adapter->no_tx_dma_setup++;
1783 /* Make certain there are enough descriptors */
1784 if (nsegs > txr->tx_avail - 2) {
1785 txr->no_desc_avail++;
1792 ** Set up the appropriate offload context
1793 ** this becomes the first descriptor of
1796 if (m_head->m_pkthdr.csum_flags & CSUM_TSO) {
1797 if (ixgbe_tso_setup(txr, m_head, &paylen, &olinfo_status)) {
1798 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
1799 olinfo_status |= IXGBE_TXD_POPTS_TXSM << 8;
1800 olinfo_status |= paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
1804 } else if (ixgbe_tx_ctx_setup(txr, m_head))
1805 olinfo_status |= IXGBE_TXD_POPTS_TXSM << 8;
1807 #ifdef IXGBE_IEEE1588
1808 /* This is changing soon to an mtag detection */
1809 if (we detect this mbuf has a TSTAMP mtag)
1810 cmd_type_len |= IXGBE_ADVTXD_MAC_TSTAMP;
1814 /* Do the flow director magic */
1815 if ((txr->atr_sample) && (!adapter->fdir_reinit)) {
1817 if (txr->atr_count >= atr_sample_rate) {
1818 ixgbe_atr(txr, m_head);
1823 /* Record payload length */
1825 olinfo_status |= m_head->m_pkthdr.len <<
1826 IXGBE_ADVTXD_PAYLEN_SHIFT;
1828 i = txr->next_avail_desc;
1829 for (j = 0; j < nsegs; j++) {
1833 txbuf = &txr->tx_buffers[i];
1834 txd = &txr->tx_base[i];
1835 seglen = segs[j].ds_len;
1836 segaddr = htole64(segs[j].ds_addr);
1838 txd->read.buffer_addr = segaddr;
1839 txd->read.cmd_type_len = htole32(txr->txd_cmd |
1840 cmd_type_len |seglen);
1841 txd->read.olinfo_status = htole32(olinfo_status);
1842 last = i; /* descriptor that will get completion IRQ */
1844 if (++i == adapter->num_tx_desc)
1847 txbuf->m_head = NULL;
1848 txbuf->eop_index = -1;
1851 txd->read.cmd_type_len |=
1852 htole32(IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS);
1853 txr->tx_avail -= nsegs;
1854 txr->next_avail_desc = i;
1856 txbuf->m_head = m_head;
1857 /* Swap the dma map between the first and last descriptor */
1858 txr->tx_buffers[first].map = txbuf->map;
1860 bus_dmamap_sync(txr->txtag, map, BUS_DMASYNC_PREWRITE);
1862 /* Set the index of the descriptor that will be marked done */
1863 txbuf = &txr->tx_buffers[first];
1864 txbuf->eop_index = last;
1866 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
1867 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1869 * Advance the Transmit Descriptor Tail (Tdt), this tells the
1870 * hardware that this frame is available to transmit.
1872 ++txr->total_packets;
1873 IXGBE_WRITE_REG(&adapter->hw, IXGBE_TDT(txr->me), i);
1878 bus_dmamap_unload(txr->txtag, txbuf->map);
1884 ixgbe_set_promisc(struct adapter *adapter)
1887 struct ifnet *ifp = adapter->ifp;
1889 reg_rctl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1890 reg_rctl &= (~IXGBE_FCTRL_UPE);
1891 reg_rctl &= (~IXGBE_FCTRL_MPE);
1892 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, reg_rctl);
1894 if (ifp->if_flags & IFF_PROMISC) {
1895 reg_rctl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1896 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, reg_rctl);
1897 } else if (ifp->if_flags & IFF_ALLMULTI) {
1898 reg_rctl |= IXGBE_FCTRL_MPE;
1899 reg_rctl &= ~IXGBE_FCTRL_UPE;
1900 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, reg_rctl);
1906 /*********************************************************************
1909 * This routine is called whenever multicast address list is updated.
1911 **********************************************************************/
1912 #define IXGBE_RAR_ENTRIES 16
1915 ixgbe_set_multi(struct adapter *adapter)
1920 struct ifmultiaddr *ifma;
1922 struct ifnet *ifp = adapter->ifp;
1924 IOCTL_DEBUGOUT("ixgbe_set_multi: begin");
1927 bzero(mta, sizeof(u8) * IXGBE_ETH_LENGTH_OF_ADDRESS *
1928 MAX_NUM_MULTICAST_ADDRESSES);
1930 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1931 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1932 if (ifp->if_flags & IFF_PROMISC)
1933 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1934 else if (ifp->if_flags & IFF_ALLMULTI) {
1935 fctrl |= IXGBE_FCTRL_MPE;
1936 fctrl &= ~IXGBE_FCTRL_UPE;
1938 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1940 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1942 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1943 if (ifma->ifma_addr->sa_family != AF_LINK)
1945 bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr),
1946 &mta[mcnt * IXGBE_ETH_LENGTH_OF_ADDRESS],
1947 IXGBE_ETH_LENGTH_OF_ADDRESS);
1952 ixgbe_update_mc_addr_list(&adapter->hw,
1953 update_ptr, mcnt, ixgbe_mc_array_itr, TRUE);
1959 * This is an iterator function now needed by the multicast
1960 * shared code. It simply feeds the shared code routine the
1961 * addresses in the array of ixgbe_set_multi() one by one.
1964 ixgbe_mc_array_itr(struct ixgbe_hw *hw, u8 **update_ptr, u32 *vmdq)
1966 u8 *addr = *update_ptr;
1970 newptr = addr + IXGBE_ETH_LENGTH_OF_ADDRESS;
1971 *update_ptr = newptr;
1976 /*********************************************************************
1979 * This routine checks for link status,updates statistics,
1980 * and runs the watchdog check.
1982 **********************************************************************/
1985 ixgbe_local_timer(void *arg)
1987 struct adapter *adapter = arg;
1988 device_t dev = adapter->dev;
1989 struct ifnet *ifp = adapter->ifp;
1990 struct ix_queue *que = adapter->queues;
1991 struct tx_ring *txr = adapter->tx_rings;
1992 int hung, busy, paused;
1994 IXGBE_CORE_LOCK(adapter);
1995 hung = busy = paused = 0;
1997 /* Check for pluggable optics */
1998 if (adapter->sfp_probe)
1999 if (!ixgbe_sfp_probe(adapter))
2000 goto out; /* Nothing to do */
2002 ixgbe_update_link_status(adapter);
2003 ixgbe_update_stats_counters(adapter);
2006 * If the interface has been paused
2007 * then don't do the watchdog check
2009 if (IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)
2013 ** Check the TX queues status
2014 ** - central locked handling of OACTIVE
2015 ** - watchdog only if all queues show hung
2017 for (int i = 0; i < adapter->num_queues; i++, que++, txr++) {
2018 if ((txr->queue_status & IXGBE_QUEUE_HUNG) &&
2021 if (txr->queue_status & IXGBE_QUEUE_DEPLETED)
2023 if ((txr->queue_status & IXGBE_QUEUE_IDLE) == 0)
2024 taskqueue_enqueue(que->tq, &que->que_task);
2026 /* Only truely watchdog if all queues show hung */
2027 if (hung == adapter->num_queues)
2029 /* Only turn off the stack flow when ALL are depleted */
2030 if (busy == adapter->num_queues)
2031 ifp->if_flags |= IFF_OACTIVE;
2032 else if ((ifp->if_flags & IFF_OACTIVE) &&
2033 (busy < adapter->num_queues))
2034 ifp->if_flags &= ~IFF_OACTIVE;
2037 ixgbe_rearm_queues(adapter, adapter->que_mask);
2038 callout_reset(&adapter->timer, hz, ixgbe_local_timer, adapter);
2039 IXGBE_CORE_UNLOCK(adapter);
2043 device_printf(adapter->dev, "Watchdog timeout -- resetting\n");
2044 device_printf(dev,"Queue(%d) tdh = %d, hw tdt = %d\n", txr->me,
2045 IXGBE_READ_REG(&adapter->hw, IXGBE_TDH(txr->me)),
2046 IXGBE_READ_REG(&adapter->hw, IXGBE_TDT(txr->me)));
2047 device_printf(dev,"TX(%d) desc avail = %d,"
2048 "Next TX to Clean = %d\n",
2049 txr->me, txr->tx_avail, txr->next_to_clean);
2050 adapter->ifp->if_flags &= ~IFF_RUNNING;
2051 adapter->watchdog_events++;
2052 ixgbe_init_locked(adapter);
2054 IXGBE_CORE_UNLOCK(adapter);
2058 ** Note: this routine updates the OS on the link state
2059 ** the real check of the hardware only happens with
2060 ** a link interrupt.
2063 ixgbe_update_link_status(struct adapter *adapter)
2065 struct ifnet *ifp = adapter->ifp;
2066 struct tx_ring *txr = adapter->tx_rings;
2067 device_t dev = adapter->dev;
2070 if (adapter->link_up){
2071 if (adapter->link_active == FALSE) {
2073 device_printf(dev,"Link is up %d Gbps %s \n",
2074 ((adapter->link_speed == 128)? 10:1),
2076 adapter->link_active = TRUE;
2077 /* Update any Flow Control changes */
2078 ixgbe_fc_enable(&adapter->hw);
2079 ifp->if_link_state = LINK_STATE_UP;
2080 if_link_state_change(ifp);
2082 } else { /* Link down */
2083 if (adapter->link_active == TRUE) {
2085 device_printf(dev,"Link is Down\n");
2086 ifp->if_link_state = LINK_STATE_DOWN;
2087 if_link_state_change(ifp);
2088 adapter->link_active = FALSE;
2089 for (int i = 0; i < adapter->num_queues;
2091 txr->queue_status = IXGBE_QUEUE_IDLE;
2099 /*********************************************************************
2101 * This routine disables all traffic on the adapter by issuing a
2102 * global reset on the MAC and deallocates TX/RX buffers.
2104 **********************************************************************/
2107 ixgbe_stop(void *arg)
2110 struct adapter *adapter = arg;
2111 struct ixgbe_hw *hw = &adapter->hw;
2114 KKASSERT(lockstatus(&adapter->core_lock, curthread) != 0);
2116 INIT_DEBUGOUT("ixgbe_stop: begin\n");
2117 ixgbe_disable_intr(adapter);
2118 callout_stop(&adapter->timer);
2120 /* Let the stack know...*/
2121 ifp->if_flags &= ~IFF_RUNNING;
2122 ifp->if_flags |= IFF_OACTIVE;
2125 hw->adapter_stopped = FALSE;
2126 ixgbe_stop_adapter(hw);
2127 /* Turn off the laser */
2128 if (hw->phy.multispeed_fiber)
2129 ixgbe_disable_tx_laser(hw);
2131 /* reprogram the RAR[0] in case user changed it. */
2132 ixgbe_set_rar(&adapter->hw, 0, adapter->hw.mac.addr, 0, IXGBE_RAH_AV);
2138 /*********************************************************************
2140 * Determine hardware revision.
2142 **********************************************************************/
2144 ixgbe_identify_hardware(struct adapter *adapter)
2146 device_t dev = adapter->dev;
2147 struct ixgbe_hw *hw = &adapter->hw;
2149 /* Save off the information about this board */
2150 hw->vendor_id = pci_get_vendor(dev);
2151 hw->device_id = pci_get_device(dev);
2152 hw->revision_id = pci_read_config(dev, PCIR_REVID, 1);
2153 hw->subsystem_vendor_id =
2154 pci_read_config(dev, PCIR_SUBVEND_0, 2);
2155 hw->subsystem_device_id =
2156 pci_read_config(dev, PCIR_SUBDEV_0, 2);
2158 /* We need this here to set the num_segs below */
2159 ixgbe_set_mac_type(hw);
2161 /* Pick up the 82599 and VF settings */
2162 if (hw->mac.type != ixgbe_mac_82598EB) {
2163 hw->phy.smart_speed = ixgbe_smart_speed;
2164 adapter->num_segs = IXGBE_82599_SCATTER;
2166 adapter->num_segs = IXGBE_82598_SCATTER;
2171 /*********************************************************************
2173 * Determine optic type
2175 **********************************************************************/
2177 ixgbe_setup_optics(struct adapter *adapter)
2179 struct ixgbe_hw *hw = &adapter->hw;
2182 layer = ixgbe_get_supported_physical_layer(hw);
2184 if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_T) {
2185 adapter->optics = IFM_10G_T;
2189 if (layer & IXGBE_PHYSICAL_LAYER_1000BASE_T) {
2190 adapter->optics = IFM_1000_T;
2194 if (layer & (IXGBE_PHYSICAL_LAYER_10GBASE_LR |
2195 IXGBE_PHYSICAL_LAYER_10GBASE_LRM)) {
2196 adapter->optics = IFM_10G_LR;
2200 if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_SR) {
2201 adapter->optics = IFM_10G_SR;
2205 if (layer & IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU) {
2206 adapter->optics = IFM_10G_TWINAX;
2210 if (layer & (IXGBE_PHYSICAL_LAYER_10GBASE_KX4 |
2211 IXGBE_PHYSICAL_LAYER_10GBASE_CX4)) {
2212 adapter->optics = IFM_10G_CX4;
2216 /* If we get here just set the default */
2217 adapter->optics = IFM_ETHER | IFM_AUTO;
2221 /*********************************************************************
2223 * Setup the Legacy or MSI Interrupt handler
2225 **********************************************************************/
2227 ixgbe_allocate_legacy(struct adapter *adapter)
2229 device_t dev = adapter->dev;
2230 struct ix_queue *que = adapter->queues;
2232 unsigned int intr_flags;
2235 if (adapter->msix == 1)
2238 /* Try allocating a MSI interrupt first */
2239 adapter->intr_type = pci_alloc_1intr(dev, ixgbe_msi_enable,
2242 /* We allocate a single interrupt resource */
2243 adapter->res = bus_alloc_resource_any(dev,
2244 SYS_RES_IRQ, &rid, intr_flags);
2245 if (adapter->res == NULL) {
2246 device_printf(dev, "Unable to allocate bus resource: "
2252 * Try allocating a fast interrupt and the associated deferred
2253 * processing contexts.
2255 TASK_INIT(&que->que_task, 0, ixgbe_handle_que, que);
2256 que->tq = taskqueue_create("ixgbe_que", M_NOWAIT,
2257 taskqueue_thread_enqueue, &que->tq);
2258 taskqueue_start_threads(&que->tq, 1, PI_NET, -1, "%s ixq",
2259 device_get_nameunit(adapter->dev));
2261 /* Tasklets for Link, SFP and Multispeed Fiber */
2262 TASK_INIT(&adapter->link_task, 0, ixgbe_handle_link, adapter);
2263 TASK_INIT(&adapter->mod_task, 0, ixgbe_handle_mod, adapter);
2264 TASK_INIT(&adapter->msf_task, 0, ixgbe_handle_msf, adapter);
2266 TASK_INIT(&adapter->fdir_task, 0, ixgbe_reinit_fdir, adapter);
2268 adapter->tq = taskqueue_create("ixgbe_link", M_NOWAIT,
2269 taskqueue_thread_enqueue, &adapter->tq);
2270 taskqueue_start_threads(&adapter->tq, 1, PI_NET, -1, "%s linkq",
2271 device_get_nameunit(adapter->dev));
2273 if ((error = bus_setup_intr(dev, adapter->res, INTR_MPSAFE,
2274 ixgbe_legacy_irq, que, &adapter->tag, &adapter->serializer)) != 0) {
2275 device_printf(dev, "Failed to register fast interrupt "
2276 "handler: %d\n", error);
2277 taskqueue_free(que->tq);
2278 taskqueue_free(adapter->tq);
2283 /* For simplicity in the handlers */
2284 adapter->que_mask = IXGBE_EIMS_ENABLE_MASK;
2290 /*********************************************************************
2292 * Setup MSIX Interrupt resources and handlers
2294 **********************************************************************/
2296 ixgbe_allocate_msix(struct adapter *adapter)
2298 device_t dev = adapter->dev;
2299 struct ix_queue *que = adapter->queues;
2300 int error, rid, vector = 0;
2302 for (int i = 0; i < adapter->num_queues; i++, vector++, que++) {
2304 que->res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
2305 RF_SHAREABLE | RF_ACTIVE);
2306 if (que->res == NULL) {
2307 device_printf(dev,"Unable to allocate"
2308 " bus resource: que interrupt [%d]\n", vector);
2311 /* Set the handler function */
2312 error = bus_setup_intr(dev, que->res, INTR_MPSAFE,
2313 ixgbe_msix_que, que, &que->tag, &que->serializer);
2316 device_printf(dev, "Failed to register QUE handler");
2319 #if 0 /* __FreeBSD_version >= 800504 */
2320 bus_describe_intr(dev, que->res, que->tag, "que %d", i);
2323 adapter->que_mask |= (u64)(1 << que->msix);
2325 ** Bind the msix vector, and thus the
2326 ** ring to the corresponding cpu.
2329 if (adapter->num_queues > 1)
2330 bus_bind_intr(dev, que->res, i);
2333 TASK_INIT(&que->que_task, 0, ixgbe_handle_que, que);
2334 que->tq = taskqueue_create("ixgbe_que", M_NOWAIT,
2335 taskqueue_thread_enqueue, &que->tq);
2336 taskqueue_start_threads(&que->tq, 1, PI_NET, -1, "%s que",
2337 device_get_nameunit(adapter->dev));
2342 adapter->res = bus_alloc_resource_any(dev,
2343 SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE);
2344 if (!adapter->res) {
2345 device_printf(dev,"Unable to allocate"
2346 " bus resource: Link interrupt [%d]\n", rid);
2349 /* Set the link handler function */
2350 error = bus_setup_intr(dev, adapter->res, INTR_MPSAFE,
2351 ixgbe_msix_link, adapter, &adapter->tag, &adapter->serializer);
2353 adapter->res = NULL;
2354 device_printf(dev, "Failed to register LINK handler");
2357 #if 0 /* __FreeBSD_version >= 800504 */
2358 bus_describe_intr(dev, adapter->res, adapter->tag, "link");
2360 adapter->linkvec = vector;
2361 /* Tasklets for Link, SFP and Multispeed Fiber */
2362 TASK_INIT(&adapter->link_task, 0, ixgbe_handle_link, adapter);
2363 TASK_INIT(&adapter->mod_task, 0, ixgbe_handle_mod, adapter);
2364 TASK_INIT(&adapter->msf_task, 0, ixgbe_handle_msf, adapter);
2366 TASK_INIT(&adapter->fdir_task, 0, ixgbe_reinit_fdir, adapter);
2368 adapter->tq = taskqueue_create("ixgbe_link", M_NOWAIT,
2369 taskqueue_thread_enqueue, &adapter->tq);
2370 taskqueue_start_threads(&adapter->tq, 1, PI_NET, -1, "%s linkq",
2371 device_get_nameunit(adapter->dev));
2376 #if 0 /* HAVE_MSIX */
2378 * Setup Either MSI/X or MSI
2381 ixgbe_setup_msix(struct adapter *adapter)
2383 device_t dev = adapter->dev;
2384 int rid, want, queues, msgs;
2386 /* Override by tuneable */
2387 if (ixgbe_enable_msix == 0)
2390 /* First try MSI/X */
2391 rid = PCIR_BAR(MSIX_82598_BAR);
2392 adapter->msix_mem = bus_alloc_resource_any(dev,
2393 SYS_RES_MEMORY, &rid, RF_ACTIVE);
2394 if (!adapter->msix_mem) {
2395 rid += 4; /* 82599 maps in higher BAR */
2396 adapter->msix_mem = bus_alloc_resource_any(dev,
2397 SYS_RES_MEMORY, &rid, RF_ACTIVE);
2399 if (!adapter->msix_mem) {
2400 /* May not be enabled */
2401 device_printf(adapter->dev,
2402 "Unable to map MSIX table \n");
2406 msgs = pci_msix_count(dev);
2407 if (msgs == 0) { /* system has msix disabled */
2408 bus_release_resource(dev, SYS_RES_MEMORY,
2409 rid, adapter->msix_mem);
2410 adapter->msix_mem = NULL;
2414 /* Figure out a reasonable auto config value */
2415 queues = (mp_ncpus > (msgs-1)) ? (msgs-1) : mp_ncpus;
2417 if (ixgbe_num_queues != 0)
2418 queues = ixgbe_num_queues;
2419 /* Set max queues to 8 when autoconfiguring */
2420 else if ((ixgbe_num_queues == 0) && (queues > 8))
2424 ** Want one vector (RX/TX pair) per queue
2425 ** plus an additional for Link.
2431 device_printf(adapter->dev,
2432 "MSIX Configuration Problem, "
2433 "%d vectors but %d queues wanted!\n",
2435 return (0); /* Will go to Legacy setup */
2437 if ((msgs) && pci_alloc_msix(dev, &msgs) == 0) {
2438 device_printf(adapter->dev,
2439 "Using MSIX interrupts with %d vectors\n", msgs);
2440 adapter->num_queues = queues;
2444 msgs = pci_msi_count(dev);
2445 if (msgs == 1 && pci_alloc_msi(dev, &msgs) == 0)
2446 device_printf(adapter->dev,"Using an MSI interrupt\n");
2448 device_printf(adapter->dev,"Using a Legacy interrupt\n");
2455 ixgbe_allocate_pci_resources(struct adapter *adapter)
2458 device_t dev = adapter->dev;
2461 adapter->pci_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
2464 if (!(adapter->pci_mem)) {
2465 device_printf(dev,"Unable to allocate bus resource: memory\n");
2469 adapter->osdep.mem_bus_space_tag =
2470 rman_get_bustag(adapter->pci_mem);
2471 adapter->osdep.mem_bus_space_handle =
2472 rman_get_bushandle(adapter->pci_mem);
2473 adapter->hw.hw_addr = (u8 *) &adapter->osdep.mem_bus_space_handle;
2475 /* Legacy defaults */
2476 adapter->num_queues = 1;
2477 adapter->hw.back = &adapter->osdep;
2480 ** Now setup MSI or MSI/X, should
2481 ** return us the number of supported
2482 ** vectors. (Will be 1 for MSI)
2484 #if 0 /* HAVE_MSIX */
2485 adapter->msix = ixgbe_setup_msix(adapter);
2491 ixgbe_free_pci_resources(struct adapter * adapter)
2493 struct ix_queue *que = adapter->queues;
2494 device_t dev = adapter->dev;
2497 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
2498 memrid = PCIR_BAR(MSIX_82598_BAR);
2500 memrid = PCIR_BAR(MSIX_82599_BAR);
2503 ** There is a slight possibility of a failure mode
2504 ** in attach that will result in entering this function
2505 ** before interrupt resources have been initialized, and
2506 ** in that case we do not want to execute the loops below
2507 ** We can detect this reliably by the state of the adapter
2510 if (adapter->res == NULL)
2514 ** Release all msix queue resources:
2516 for (int i = 0; i < adapter->num_queues; i++, que++) {
2517 rid = que->msix + 1;
2518 if (que->tag != NULL) {
2519 bus_teardown_intr(dev, que->res, que->tag);
2522 if (que->res != NULL)
2523 bus_release_resource(dev, SYS_RES_IRQ, rid, que->res);
2527 /* Clean the Legacy or Link interrupt last */
2528 if (adapter->linkvec) /* we are doing MSIX */
2529 rid = adapter->linkvec + 1;
2531 (adapter->msix != 0) ? (rid = 1):(rid = 0);
2533 if (adapter->tag != NULL) {
2534 bus_teardown_intr(dev, adapter->res, adapter->tag);
2535 adapter->tag = NULL;
2537 if (adapter->res != NULL)
2538 bus_release_resource(dev, SYS_RES_IRQ, rid, adapter->res);
2539 if (adapter->intr_type == PCI_INTR_TYPE_MSI)
2540 pci_release_msi(adapter->dev);
2544 pci_release_msi(dev);
2546 if (adapter->msix_mem != NULL)
2547 bus_release_resource(dev, SYS_RES_MEMORY,
2548 memrid, adapter->msix_mem);
2550 if (adapter->pci_mem != NULL)
2551 bus_release_resource(dev, SYS_RES_MEMORY,
2552 PCIR_BAR(0), adapter->pci_mem);
2557 /*********************************************************************
2559 * Setup networking device structure and register an interface.
2561 **********************************************************************/
2563 ixgbe_setup_interface(device_t dev, struct adapter *adapter)
2565 struct ixgbe_hw *hw = &adapter->hw;
2568 INIT_DEBUGOUT("ixgbe_setup_interface: begin");
2570 ifp = adapter->ifp = if_alloc(IFT_ETHER);
2572 device_printf(dev, "can not allocate ifnet structure\n");
2575 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
2576 ifp->if_baudrate = 1000000000;
2577 ifp->if_init = ixgbe_init;
2578 ifp->if_softc = adapter;
2579 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
2580 ifp->if_ioctl = ixgbe_ioctl;
2581 ifp->if_start = ixgbe_start;
2582 #if 0 /* __FreeBSD_version >= 800000 */
2583 ifp->if_transmit = ixgbe_mq_start;
2584 ifp->if_qflush = ixgbe_qflush;
2586 ifp->if_snd.ifq_maxlen = adapter->num_tx_desc - 2;
2588 ether_ifattach(ifp, adapter->hw.mac.addr, NULL);
2590 adapter->max_frame_size =
2591 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
2594 * Tell the upper layer(s) we support long frames.
2596 ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
2598 ifp->if_capabilities |= IFCAP_HWCSUM | IFCAP_TSO | IFCAP_VLAN_HWCSUM;
2599 ifp->if_capabilities |= IFCAP_JUMBO_MTU;
2600 ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING
2605 ifp->if_capenable = ifp->if_capabilities;
2607 /* Don't enable LRO by default */
2609 ifp->if_capabilities |= IFCAP_LRO;
2613 ** Don't turn this on by default, if vlans are
2614 ** created on another pseudo device (eg. lagg)
2615 ** then vlan events are not passed thru, breaking
2616 ** operation, but with HW FILTER off it works. If
2617 ** using vlans directly on the ixgbe driver you can
2618 ** enable this and get full hardware tag filtering.
2620 ifp->if_capabilities |= IFCAP_VLAN_HWFILTER;
2623 * Specify the media types supported by this adapter and register
2624 * callbacks to update media and link information
2626 ifmedia_init(&adapter->media, IFM_IMASK, ixgbe_media_change,
2627 ixgbe_media_status);
2628 ifmedia_add(&adapter->media, IFM_ETHER | adapter->optics, 0, NULL);
2629 ifmedia_set(&adapter->media, IFM_ETHER | adapter->optics);
2630 if (hw->device_id == IXGBE_DEV_ID_82598AT) {
2631 ifmedia_add(&adapter->media,
2632 IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL);
2633 ifmedia_add(&adapter->media,
2634 IFM_ETHER | IFM_1000_T, 0, NULL);
2636 ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL);
2637 ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO);
2643 ixgbe_config_link(struct adapter *adapter)
2645 struct ixgbe_hw *hw = &adapter->hw;
2646 u32 autoneg, err = 0;
2647 bool sfp, negotiate;
2649 sfp = ixgbe_is_sfp(hw);
2652 if (hw->phy.multispeed_fiber) {
2653 hw->mac.ops.setup_sfp(hw);
2654 ixgbe_enable_tx_laser(hw);
2655 taskqueue_enqueue(adapter->tq, &adapter->msf_task);
2657 taskqueue_enqueue(adapter->tq, &adapter->mod_task);
2659 if (hw->mac.ops.check_link)
2660 err = ixgbe_check_link(hw, &autoneg,
2661 &adapter->link_up, FALSE);
2664 autoneg = hw->phy.autoneg_advertised;
2665 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
2666 err = hw->mac.ops.get_link_capabilities(hw,
2667 &autoneg, &negotiate);
2670 if (hw->mac.ops.setup_link)
2671 err = hw->mac.ops.setup_link(hw, autoneg,
2672 negotiate, adapter->link_up);
2678 /********************************************************************
2679 * Manage DMA'able memory.
2680 *******************************************************************/
2682 ixgbe_dmamap_cb(void *arg, bus_dma_segment_t * segs, int nseg, int error)
2686 *(bus_addr_t *) arg = segs->ds_addr;
2691 ixgbe_dma_malloc(struct adapter *adapter, bus_size_t size,
2692 struct ixgbe_dma_alloc *dma, int mapflags)
2694 device_t dev = adapter->dev;
2697 r = bus_dma_tag_create(NULL, /* parent */
2698 DBA_ALIGN, 0, /* alignment, bounds */
2699 BUS_SPACE_MAXADDR, /* lowaddr */
2700 BUS_SPACE_MAXADDR, /* highaddr */
2701 NULL, NULL, /* filter, filterarg */
2704 size, /* maxsegsize */
2705 BUS_DMA_ALLOCNOW, /* flags */
2708 device_printf(dev,"ixgbe_dma_malloc: bus_dma_tag_create failed; "
2712 r = bus_dmamem_alloc(dma->dma_tag, (void **)&dma->dma_vaddr,
2713 BUS_DMA_NOWAIT, &dma->dma_map);
2715 device_printf(dev,"ixgbe_dma_malloc: bus_dmamem_alloc failed; "
2719 r = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
2723 mapflags | BUS_DMA_NOWAIT);
2725 device_printf(dev,"ixgbe_dma_malloc: bus_dmamap_load failed; "
2729 dma->dma_size = size;
2732 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
2734 bus_dma_tag_destroy(dma->dma_tag);
2736 dma->dma_map = NULL;
2737 dma->dma_tag = NULL;
2742 ixgbe_dma_free(struct adapter *adapter, struct ixgbe_dma_alloc *dma)
2744 bus_dmamap_sync(dma->dma_tag, dma->dma_map,
2745 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
2746 bus_dmamap_unload(dma->dma_tag, dma->dma_map);
2747 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
2748 bus_dma_tag_destroy(dma->dma_tag);
2752 /*********************************************************************
2754 * Allocate memory for the transmit and receive rings, and then
2755 * the descriptors associated with each, called only once at attach.
2757 **********************************************************************/
2759 ixgbe_allocate_queues(struct adapter *adapter)
2761 device_t dev = adapter->dev;
2762 struct ix_queue *que;
2763 struct tx_ring *txr;
2764 struct rx_ring *rxr;
2765 int rsize, tsize, error = IXGBE_SUCCESS;
2766 int txconf = 0, rxconf = 0;
2768 /* First allocate the top level queue structs */
2769 if (!(adapter->queues =
2770 (struct ix_queue *) kmalloc(sizeof(struct ix_queue) *
2771 adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2772 device_printf(dev, "Unable to allocate queue memory\n");
2777 /* First allocate the TX ring struct memory */
2778 if (!(adapter->tx_rings =
2779 (struct tx_ring *) kmalloc(sizeof(struct tx_ring) *
2780 adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2781 device_printf(dev, "Unable to allocate TX ring memory\n");
2786 /* Next allocate the RX */
2787 if (!(adapter->rx_rings =
2788 (struct rx_ring *) kmalloc(sizeof(struct rx_ring) *
2789 adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2790 device_printf(dev, "Unable to allocate RX ring memory\n");
2795 /* For the ring itself */
2796 tsize = roundup2(adapter->num_tx_desc *
2797 sizeof(union ixgbe_adv_tx_desc), DBA_ALIGN);
2800 * Now set up the TX queues, txconf is needed to handle the
2801 * possibility that things fail midcourse and we need to
2802 * undo memory gracefully
2804 for (int i = 0; i < adapter->num_queues; i++, txconf++) {
2805 /* Set up some basics */
2806 txr = &adapter->tx_rings[i];
2807 txr->adapter = adapter;
2810 /* Initialize the TX side lock */
2811 ksnprintf(txr->lock_name, sizeof(txr->lock_name), "%s:tx(%d)",
2812 device_get_nameunit(dev), txr->me);
2813 lockinit(&txr->tx_lock, txr->lock_name, 0, LK_CANRECURSE);
2815 if (ixgbe_dma_malloc(adapter, tsize,
2816 &txr->txdma, BUS_DMA_NOWAIT)) {
2818 "Unable to allocate TX Descriptor memory\n");
2822 txr->tx_base = (union ixgbe_adv_tx_desc *)txr->txdma.dma_vaddr;
2823 bzero((void *)txr->tx_base, tsize);
2825 /* Now allocate transmit buffers for the ring */
2826 if (ixgbe_allocate_transmit_buffers(txr)) {
2828 "Critical Failure setting up transmit buffers\n");
2832 #if 0 /* __FreeBSD_version >= 800000 */
2833 /* Allocate a buf ring */
2834 txr->br = buf_ring_alloc(IXGBE_BR_SIZE, M_DEVBUF,
2835 M_WAITOK, &txr->tx_mtx);
2836 if (txr->br == NULL) {
2838 "Critical Failure setting up buf ring\n");
2846 * Next the RX queues...
2848 rsize = roundup2(adapter->num_rx_desc *
2849 sizeof(union ixgbe_adv_rx_desc), DBA_ALIGN);
2850 for (int i = 0; i < adapter->num_queues; i++, rxconf++) {
2851 rxr = &adapter->rx_rings[i];
2852 /* Set up some basics */
2853 rxr->adapter = adapter;
2856 /* Initialize the RX side lock */
2857 ksnprintf(rxr->lock_name, sizeof(rxr->lock_name), "%s:rx(%d)",
2858 device_get_nameunit(dev), rxr->me);
2859 lockinit(&rxr->rx_lock, rxr->lock_name, 0, LK_CANRECURSE);
2861 if (ixgbe_dma_malloc(adapter, rsize,
2862 &rxr->rxdma, BUS_DMA_NOWAIT)) {
2864 "Unable to allocate RxDescriptor memory\n");
2868 rxr->rx_base = (union ixgbe_adv_rx_desc *)rxr->rxdma.dma_vaddr;
2869 bzero((void *)rxr->rx_base, rsize);
2871 /* Allocate receive buffers for the ring*/
2872 if (ixgbe_allocate_receive_buffers(rxr)) {
2874 "Critical Failure setting up receive buffers\n");
2881 ** Finally set up the queue holding structs
2883 for (int i = 0; i < adapter->num_queues; i++) {
2884 que = &adapter->queues[i];
2885 que->adapter = adapter;
2886 que->txr = &adapter->tx_rings[i];
2887 que->rxr = &adapter->rx_rings[i];
2893 for (rxr = adapter->rx_rings; rxconf > 0; rxr++, rxconf--)
2894 ixgbe_dma_free(adapter, &rxr->rxdma);
2896 for (txr = adapter->tx_rings; txconf > 0; txr++, txconf--)
2897 ixgbe_dma_free(adapter, &txr->txdma);
2898 kfree(adapter->rx_rings, M_DEVBUF);
2900 kfree(adapter->tx_rings, M_DEVBUF);
2902 kfree(adapter->queues, M_DEVBUF);
2907 /*********************************************************************
2909 * Allocate memory for tx_buffer structures. The tx_buffer stores all
2910 * the information needed to transmit a packet on the wire. This is
2911 * called only once at attach, setup is done every reset.
2913 **********************************************************************/
2915 ixgbe_allocate_transmit_buffers(struct tx_ring *txr)
2917 struct adapter *adapter = txr->adapter;
2918 device_t dev = adapter->dev;
2919 struct ixgbe_tx_buf *txbuf;
2923 * Setup DMA descriptor areas.
2925 if ((error = bus_dma_tag_create(
2927 1, 0, /* alignment, bounds */
2928 BUS_SPACE_MAXADDR, /* lowaddr */
2929 BUS_SPACE_MAXADDR, /* highaddr */
2930 NULL, NULL, /* filter, filterarg */
2931 IXGBE_TSO_SIZE, /* maxsize */
2932 adapter->num_segs, /* nsegments */
2933 PAGE_SIZE, /* maxsegsize */
2936 device_printf(dev,"Unable to allocate TX DMA tag\n");
2940 if (!(txr->tx_buffers =
2941 (struct ixgbe_tx_buf *) kmalloc(sizeof(struct ixgbe_tx_buf) *
2942 adapter->num_tx_desc, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2943 device_printf(dev, "Unable to allocate tx_buffer memory\n");
2948 /* Create the descriptor buffer dma maps */
2949 txbuf = txr->tx_buffers;
2950 for (i = 0; i < adapter->num_tx_desc; i++, txbuf++) {
2951 error = bus_dmamap_create(txr->txtag, 0, &txbuf->map);
2953 device_printf(dev, "Unable to create TX DMA map\n");
2960 /* We free all, it handles case where we are in the middle */
2961 ixgbe_free_transmit_structures(adapter);
2965 /*********************************************************************
2967 * Initialize a transmit ring.
2969 **********************************************************************/
2971 ixgbe_setup_transmit_ring(struct tx_ring *txr)
2973 struct adapter *adapter = txr->adapter;
2974 struct ixgbe_tx_buf *txbuf;
2977 struct netmap_adapter *na = NA(adapter->ifp);
2978 struct netmap_slot *slot;
2979 #endif /* DEV_NETMAP */
2981 /* Clear the old ring contents */
2985 * (under lock): if in netmap mode, do some consistency
2986 * checks and set slot to entry 0 of the netmap ring.
2988 slot = netmap_reset(na, NR_TX, txr->me, 0);
2989 #endif /* DEV_NETMAP */
2990 bzero((void *)txr->tx_base,
2991 (sizeof(union ixgbe_adv_tx_desc)) * adapter->num_tx_desc);
2993 txr->next_avail_desc = 0;
2994 txr->next_to_clean = 0;
2996 /* Free any existing tx buffers. */
2997 txbuf = txr->tx_buffers;
2998 for (i = 0; i < adapter->num_tx_desc; i++, txbuf++) {
2999 if (txbuf->m_head != NULL) {
3000 bus_dmamap_sync(txr->txtag, txbuf->map,
3001 BUS_DMASYNC_POSTWRITE);
3002 bus_dmamap_unload(txr->txtag, txbuf->map);
3003 m_freem(txbuf->m_head);
3004 txbuf->m_head = NULL;
3008 * In netmap mode, set the map for the packet buffer.
3009 * NOTE: Some drivers (not this one) also need to set
3010 * the physical buffer address in the NIC ring.
3011 * Slots in the netmap ring (indexed by "si") are
3012 * kring->nkr_hwofs positions "ahead" wrt the
3013 * corresponding slot in the NIC ring. In some drivers
3014 * (not here) nkr_hwofs can be negative. Function
3015 * netmap_idx_n2k() handles wraparounds properly.
3018 int si = netmap_idx_n2k(&na->tx_rings[txr->me], i);
3019 netmap_load_map(txr->txtag, txbuf->map, NMB(slot + si));
3021 #endif /* DEV_NETMAP */
3022 /* Clear the EOP index */
3023 txbuf->eop_index = -1;
3027 /* Set the rate at which we sample packets */
3028 if (adapter->hw.mac.type != ixgbe_mac_82598EB)
3029 txr->atr_sample = atr_sample_rate;
3032 /* Set number of descriptors available */
3033 txr->tx_avail = adapter->num_tx_desc;
3035 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
3036 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
3037 IXGBE_TX_UNLOCK(txr);
3040 /*********************************************************************
3042 * Initialize all transmit rings.
3044 **********************************************************************/
3046 ixgbe_setup_transmit_structures(struct adapter *adapter)
3048 struct tx_ring *txr = adapter->tx_rings;
3050 for (int i = 0; i < adapter->num_queues; i++, txr++)
3051 ixgbe_setup_transmit_ring(txr);
3056 /*********************************************************************
3058 * Enable transmit unit.
3060 **********************************************************************/
3062 ixgbe_initialize_transmit_units(struct adapter *adapter)
3064 struct tx_ring *txr = adapter->tx_rings;
3065 struct ixgbe_hw *hw = &adapter->hw;
3067 /* Setup the Base and Length of the Tx Descriptor Ring */
3069 for (int i = 0; i < adapter->num_queues; i++, txr++) {
3070 u64 tdba = txr->txdma.dma_paddr;
3073 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(i),
3074 (tdba & 0x00000000ffffffffULL));
3075 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(i), (tdba >> 32));
3076 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(i),
3077 adapter->num_tx_desc * sizeof(struct ixgbe_legacy_tx_desc));
3079 /* Setup the HW Tx Head and Tail descriptor pointers */
3080 IXGBE_WRITE_REG(hw, IXGBE_TDH(i), 0);
3081 IXGBE_WRITE_REG(hw, IXGBE_TDT(i), 0);
3083 /* Setup Transmit Descriptor Cmd Settings */
3084 txr->txd_cmd = IXGBE_TXD_CMD_IFCS;
3085 txr->queue_status = IXGBE_QUEUE_IDLE;
3087 /* Disable Head Writeback */
3088 switch (hw->mac.type) {
3089 case ixgbe_mac_82598EB:
3090 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i));
3092 case ixgbe_mac_82599EB:
3093 case ixgbe_mac_X540:
3095 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
3098 txctrl &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
3099 switch (hw->mac.type) {
3100 case ixgbe_mac_82598EB:
3101 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(i), txctrl);
3103 case ixgbe_mac_82599EB:
3104 case ixgbe_mac_X540:
3106 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), txctrl);
3112 if (hw->mac.type != ixgbe_mac_82598EB) {
3113 u32 dmatxctl, rttdcs;
3114 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3115 dmatxctl |= IXGBE_DMATXCTL_TE;
3116 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3117 /* Disable arbiter to set MTQC */
3118 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3119 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3120 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3121 IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
3122 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3123 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3129 /*********************************************************************
3131 * Free all transmit rings.
3133 **********************************************************************/
3135 ixgbe_free_transmit_structures(struct adapter *adapter)
3137 struct tx_ring *txr = adapter->tx_rings;
3139 for (int i = 0; i < adapter->num_queues; i++, txr++) {
3141 ixgbe_free_transmit_buffers(txr);
3142 ixgbe_dma_free(adapter, &txr->txdma);
3143 IXGBE_TX_UNLOCK(txr);
3144 IXGBE_TX_LOCK_DESTROY(txr);
3146 kfree(adapter->tx_rings, M_DEVBUF);
3149 /*********************************************************************
3151 * Free transmit ring related data structures.
3153 **********************************************************************/
3155 ixgbe_free_transmit_buffers(struct tx_ring *txr)
3157 struct adapter *adapter = txr->adapter;
3158 struct ixgbe_tx_buf *tx_buffer;
3161 INIT_DEBUGOUT("free_transmit_ring: begin");
3163 if (txr->tx_buffers == NULL)
3166 tx_buffer = txr->tx_buffers;
3167 for (i = 0; i < adapter->num_tx_desc; i++, tx_buffer++) {
3168 if (tx_buffer->m_head != NULL) {
3169 bus_dmamap_sync(txr->txtag, tx_buffer->map,
3170 BUS_DMASYNC_POSTWRITE);
3171 bus_dmamap_unload(txr->txtag,
3173 m_freem(tx_buffer->m_head);
3174 tx_buffer->m_head = NULL;
3175 if (tx_buffer->map != NULL) {
3176 bus_dmamap_destroy(txr->txtag,
3178 tx_buffer->map = NULL;
3180 } else if (tx_buffer->map != NULL) {
3181 bus_dmamap_unload(txr->txtag,
3183 bus_dmamap_destroy(txr->txtag,
3185 tx_buffer->map = NULL;
3188 #if 0 /* __FreeBSD_version >= 800000 */
3189 if (txr->br != NULL)
3190 buf_ring_free(txr->br, M_DEVBUF);
3192 if (txr->tx_buffers != NULL) {
3193 kfree(txr->tx_buffers, M_DEVBUF);
3194 txr->tx_buffers = NULL;
3196 if (txr->txtag != NULL) {
3197 bus_dma_tag_destroy(txr->txtag);
3203 /*********************************************************************
3205 * Advanced Context Descriptor setup for VLAN or CSUM
3207 **********************************************************************/
3210 ixgbe_tx_ctx_setup(struct tx_ring *txr, struct mbuf *mp)
3212 struct adapter *adapter = txr->adapter;
3213 struct ixgbe_adv_tx_context_desc *TXD;
3214 struct ixgbe_tx_buf *tx_buffer;
3215 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
3216 struct ether_vlan_header *eh;
3218 struct ip6_hdr *ip6;
3219 int ehdrlen, ip_hlen = 0;
3222 bool offload = TRUE;
3223 int ctxd = txr->next_avail_desc;
3227 if ((mp->m_pkthdr.csum_flags & CSUM_OFFLOAD) == 0)
3230 tx_buffer = &txr->tx_buffers[ctxd];
3231 TXD = (struct ixgbe_adv_tx_context_desc *) &txr->tx_base[ctxd];
3234 ** In advanced descriptors the vlan tag must
3235 ** be placed into the descriptor itself.
3237 if (mp->m_flags & M_VLANTAG) {
3238 vtag = htole16(mp->m_pkthdr.ether_vlantag);
3239 vlan_macip_lens |= (vtag << IXGBE_ADVTXD_VLAN_SHIFT);
3240 } else if (offload == FALSE)
3244 * Determine where frame payload starts.
3245 * Jump over vlan headers if already present,
3246 * helpful for QinQ too.
3248 eh = mtod(mp, struct ether_vlan_header *);
3249 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
3250 etype = ntohs(eh->evl_proto);
3251 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
3253 etype = ntohs(eh->evl_encap_proto);
3254 ehdrlen = ETHER_HDR_LEN;
3257 /* Set the ether header length */
3258 vlan_macip_lens |= ehdrlen << IXGBE_ADVTXD_MACLEN_SHIFT;
3262 ip = (struct ip *)(mp->m_data + ehdrlen);
3263 ip_hlen = ip->ip_hl << 2;
3265 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3267 case ETHERTYPE_IPV6:
3268 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen);
3269 ip_hlen = sizeof(struct ip6_hdr);
3270 /* XXX-BZ this will go badly in case of ext hdrs. */
3271 ipproto = ip6->ip6_nxt;
3272 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV6;
3279 vlan_macip_lens |= ip_hlen;
3280 type_tucmd_mlhl |= IXGBE_ADVTXD_DCMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
3284 if (mp->m_pkthdr.csum_flags & CSUM_TCP)
3285 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3289 if (mp->m_pkthdr.csum_flags & CSUM_UDP)
3290 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_UDP;
3295 if (mp->m_pkthdr.csum_flags & CSUM_SCTP)
3296 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
3304 /* Now copy bits into descriptor */
3305 TXD->vlan_macip_lens |= htole32(vlan_macip_lens);
3306 TXD->type_tucmd_mlhl |= htole32(type_tucmd_mlhl);
3307 TXD->seqnum_seed = htole32(0);
3308 TXD->mss_l4len_idx = htole32(0);
3310 tx_buffer->m_head = NULL;
3311 tx_buffer->eop_index = -1;
3313 /* We've consumed the first desc, adjust counters */
3314 if (++ctxd == adapter->num_tx_desc)
3316 txr->next_avail_desc = ctxd;
3322 /**********************************************************************
3324 * Setup work for hardware segmentation offload (TSO) on
3325 * adapters using advanced tx descriptors
3327 **********************************************************************/
3329 ixgbe_tso_setup(struct tx_ring *txr, struct mbuf *mp, u32 *paylen,
3332 struct adapter *adapter = txr->adapter;
3333 struct ixgbe_adv_tx_context_desc *TXD;
3334 struct ixgbe_tx_buf *tx_buffer;
3335 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
3336 u16 vtag = 0, eh_type;
3337 u32 mss_l4len_idx = 0, len;
3338 int ctxd, ehdrlen, ip_hlen, tcp_hlen;
3339 struct ether_vlan_header *eh;
3340 #if 0 /* IPv6 TSO */
3342 struct ip6_hdr *ip6;
3352 * Determine where frame payload starts.
3353 * Jump over vlan headers if already present
3355 eh = mtod(mp, struct ether_vlan_header *);
3356 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
3357 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
3358 eh_type = eh->evl_proto;
3360 ehdrlen = ETHER_HDR_LEN;
3361 eh_type = eh->evl_encap_proto;
3364 /* Ensure we have at least the IP+TCP header in the first mbuf. */
3365 len = ehdrlen + sizeof(struct tcphdr);
3366 switch (ntohs(eh_type)) {
3367 #if 0 /* IPv6 TSO */
3369 case ETHERTYPE_IPV6:
3370 if (mp->m_len < len + sizeof(struct ip6_hdr))
3372 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen);
3373 /* XXX-BZ For now we do not pretend to support ext. hdrs. */
3374 if (ip6->ip6_nxt != IPPROTO_TCP)
3376 ip_hlen = sizeof(struct ip6_hdr);
3377 th = (struct tcphdr *)((caddr_t)ip6 + ip_hlen);
3378 th->th_sum = in6_cksum_pseudo(ip6, 0, IPPROTO_TCP, 0);
3379 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV6;
3385 if (mp->m_len < len + sizeof(struct ip))
3387 ip = (struct ip *)(mp->m_data + ehdrlen);
3388 if (ip->ip_p != IPPROTO_TCP)
3391 ip_hlen = ip->ip_hl << 2;
3392 th = (struct tcphdr *)((caddr_t)ip + ip_hlen);
3393 th->th_sum = in_pseudo(ip->ip_src.s_addr,
3394 ip->ip_dst.s_addr, htons(IPPROTO_TCP));
3395 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3396 /* Tell transmit desc to also do IPv4 checksum. */
3397 *olinfo_status |= IXGBE_TXD_POPTS_IXSM << 8;
3401 panic("%s: CSUM_TSO but no supported IP version (0x%04x)",
3402 __func__, ntohs(eh_type));
3406 ctxd = txr->next_avail_desc;
3407 tx_buffer = &txr->tx_buffers[ctxd];
3408 TXD = (struct ixgbe_adv_tx_context_desc *) &txr->tx_base[ctxd];
3410 tcp_hlen = th->th_off << 2;
3412 /* This is used in the transmit desc in encap */
3413 *paylen = mp->m_pkthdr.len - ehdrlen - ip_hlen - tcp_hlen;
3415 /* VLAN MACLEN IPLEN */
3416 if (mp->m_flags & M_VLANTAG) {
3417 vtag = htole16(mp->m_pkthdr.ether_vlantag);
3418 vlan_macip_lens |= (vtag << IXGBE_ADVTXD_VLAN_SHIFT);
3421 vlan_macip_lens |= ehdrlen << IXGBE_ADVTXD_MACLEN_SHIFT;
3422 vlan_macip_lens |= ip_hlen;
3423 TXD->vlan_macip_lens |= htole32(vlan_macip_lens);
3425 /* ADV DTYPE TUCMD */
3426 type_tucmd_mlhl |= IXGBE_ADVTXD_DCMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
3427 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3428 TXD->type_tucmd_mlhl |= htole32(type_tucmd_mlhl);
3431 mss_l4len_idx |= (mp->m_pkthdr.tso_segsz << IXGBE_ADVTXD_MSS_SHIFT);
3432 mss_l4len_idx |= (tcp_hlen << IXGBE_ADVTXD_L4LEN_SHIFT);
3433 TXD->mss_l4len_idx = htole32(mss_l4len_idx);
3435 TXD->seqnum_seed = htole32(0);
3436 tx_buffer->m_head = NULL;
3437 tx_buffer->eop_index = -1;
3439 if (++ctxd == adapter->num_tx_desc)
3443 txr->next_avail_desc = ctxd;
3449 ** This routine parses packet headers so that Flow
3450 ** Director can make a hashed filter table entry
3451 ** allowing traffic flows to be identified and kept
3452 ** on the same cpu. This would be a performance
3453 ** hit, but we only do it at IXGBE_FDIR_RATE of
3457 ixgbe_atr(struct tx_ring *txr, struct mbuf *mp)
3459 struct adapter *adapter = txr->adapter;
3460 struct ix_queue *que;
3464 struct ether_vlan_header *eh;
3465 union ixgbe_atr_hash_dword input = {.dword = 0};
3466 union ixgbe_atr_hash_dword common = {.dword = 0};
3467 int ehdrlen, ip_hlen;
3470 eh = mtod(mp, struct ether_vlan_header *);
3471 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
3472 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
3473 etype = eh->evl_proto;
3475 ehdrlen = ETHER_HDR_LEN;
3476 etype = eh->evl_encap_proto;
3479 /* Only handling IPv4 */
3480 if (etype != htons(ETHERTYPE_IP))
3483 ip = (struct ip *)(mp->m_data + ehdrlen);
3484 ip_hlen = ip->ip_hl << 2;
3486 /* check if we're UDP or TCP */
3489 th = (struct tcphdr *)((caddr_t)ip + ip_hlen);
3490 /* src and dst are inverted */
3491 common.port.dst ^= th->th_sport;
3492 common.port.src ^= th->th_dport;
3493 input.formatted.flow_type ^= IXGBE_ATR_FLOW_TYPE_TCPV4;
3496 uh = (struct udphdr *)((caddr_t)ip + ip_hlen);
3497 /* src and dst are inverted */
3498 common.port.dst ^= uh->uh_sport;
3499 common.port.src ^= uh->uh_dport;
3500 input.formatted.flow_type ^= IXGBE_ATR_FLOW_TYPE_UDPV4;
3506 input.formatted.vlan_id = htobe16(mp->m_pkthdr.ether_vtag);
3507 if (mp->m_pkthdr.ether_vtag)
3508 common.flex_bytes ^= htons(ETHERTYPE_VLAN);
3510 common.flex_bytes ^= etype;
3511 common.ip ^= ip->ip_src.s_addr ^ ip->ip_dst.s_addr;
3513 que = &adapter->queues[txr->me];
3515 ** This assumes the Rx queue and Tx
3516 ** queue are bound to the same CPU
3518 ixgbe_fdir_add_signature_filter_82599(&adapter->hw,
3519 input, common, que->msix);
3521 #endif /* IXGBE_FDIR */
3523 /**********************************************************************
3525 * Examine each tx_buffer in the used queue. If the hardware is done
3526 * processing the packet then free associated resources. The
3527 * tx_buffer is put back on the free queue.
3529 **********************************************************************/
3531 ixgbe_txeof(struct tx_ring *txr)
3533 struct adapter *adapter = txr->adapter;
3534 struct ifnet *ifp = adapter->ifp;
3535 u32 first, last, done, processed;
3536 struct ixgbe_tx_buf *tx_buffer;
3537 struct ixgbe_legacy_tx_desc *tx_desc, *eop_desc;
3539 KKASSERT(lockstatus(&txr->tx_lock, curthread) != 0);
3542 if (ifp->if_capenable & IFCAP_NETMAP) {
3543 struct netmap_adapter *na = NA(ifp);
3544 struct netmap_kring *kring = &na->tx_rings[txr->me];
3546 tx_desc = (struct ixgbe_legacy_tx_desc *)txr->tx_base;
3548 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
3549 BUS_DMASYNC_POSTREAD);
3551 * In netmap mode, all the work is done in the context
3552 * of the client thread. Interrupt handlers only wake up
3553 * clients, which may be sleeping on individual rings
3554 * or on a global resource for all rings.
3555 * To implement tx interrupt mitigation, we wake up the client
3556 * thread roughly every half ring, even if the NIC interrupts
3557 * more frequently. This is implemented as follows:
3558 * - ixgbe_txsync() sets kring->nr_kflags with the index of
3559 * the slot that should wake up the thread (nkr_num_slots
3560 * means the user thread should not be woken up);
3561 * - the driver ignores tx interrupts unless netmap_mitigate=0
3562 * or the slot has the DD bit set.
3564 * When the driver has separate locks, we need to
3565 * release and re-acquire txlock to avoid deadlocks.
3566 * XXX see if we can find a better way.
3568 if (!netmap_mitigate ||
3569 (kring->nr_kflags < kring->nkr_num_slots &&
3570 tx_desc[kring->nr_kflags].upper.fields.status & IXGBE_TXD_STAT_DD)) {
3571 kring->nr_kflags = kring->nkr_num_slots;
3572 selwakeuppri(&na->tx_rings[txr->me].si, PI_NET);
3573 IXGBE_TX_UNLOCK(txr);
3574 IXGBE_CORE_LOCK(adapter);
3575 selwakeuppri(&na->tx_si, PI_NET);
3576 IXGBE_CORE_UNLOCK(adapter);
3581 #endif /* DEV_NETMAP */
3583 if (txr->tx_avail == adapter->num_tx_desc) {
3584 txr->queue_status = IXGBE_QUEUE_IDLE;
3589 first = txr->next_to_clean;
3590 tx_buffer = &txr->tx_buffers[first];
3591 /* For cleanup we just use legacy struct */
3592 tx_desc = (struct ixgbe_legacy_tx_desc *)&txr->tx_base[first];
3593 last = tx_buffer->eop_index;
3596 eop_desc = (struct ixgbe_legacy_tx_desc *)&txr->tx_base[last];
3599 ** Get the index of the first descriptor
3600 ** BEYOND the EOP and call that 'done'.
3601 ** I do this so the comparison in the
3602 ** inner while loop below can be simple
3604 if (++last == adapter->num_tx_desc) last = 0;
3607 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
3608 BUS_DMASYNC_POSTREAD);
3610 ** Only the EOP descriptor of a packet now has the DD
3611 ** bit set, this is what we look for...
3613 while (eop_desc->upper.fields.status & IXGBE_TXD_STAT_DD) {
3614 /* We clean the range of the packet */
3615 while (first != done) {
3616 tx_desc->upper.data = 0;
3617 tx_desc->lower.data = 0;
3618 tx_desc->buffer_addr = 0;
3622 if (tx_buffer->m_head) {
3624 tx_buffer->m_head->m_pkthdr.len;
3625 bus_dmamap_sync(txr->txtag,
3627 BUS_DMASYNC_POSTWRITE);
3628 bus_dmamap_unload(txr->txtag,
3630 m_freem(tx_buffer->m_head);
3631 tx_buffer->m_head = NULL;
3632 tx_buffer->map = NULL;
3634 tx_buffer->eop_index = -1;
3635 txr->watchdog_time = ticks;
3637 if (++first == adapter->num_tx_desc)
3640 tx_buffer = &txr->tx_buffers[first];
3642 (struct ixgbe_legacy_tx_desc *)&txr->tx_base[first];
3646 /* See if there is more work now */
3647 last = tx_buffer->eop_index;
3650 (struct ixgbe_legacy_tx_desc *)&txr->tx_base[last];
3651 /* Get next done point */
3652 if (++last == adapter->num_tx_desc) last = 0;
3657 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
3658 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
3660 txr->next_to_clean = first;
3663 ** Watchdog calculation, we know there's
3664 ** work outstanding or the first return
3665 ** would have been taken, so none processed
3666 ** for too long indicates a hang.
3668 if ((!processed) && ((ticks - txr->watchdog_time) > IXGBE_WATCHDOG))
3669 txr->queue_status = IXGBE_QUEUE_HUNG;
3671 /* With a minimum free clear the depleted state bit. */
3672 if (txr->tx_avail > IXGBE_TX_CLEANUP_THRESHOLD)
3673 txr->queue_status &= ~IXGBE_QUEUE_DEPLETED;
3675 if (txr->tx_avail == adapter->num_tx_desc) {
3676 txr->queue_status = IXGBE_QUEUE_IDLE;
3683 /*********************************************************************
3685 * Refresh mbuf buffers for RX descriptor rings
3686 * - now keeps its own state so discards due to resource
3687 * exhaustion are unnecessary, if an mbuf cannot be obtained
3688 * it just returns, keeping its placeholder, thus it can simply
3689 * be recalled to try again.
3691 **********************************************************************/
3693 ixgbe_refresh_mbufs(struct rx_ring *rxr, int limit)
3695 struct adapter *adapter = rxr->adapter;
3696 bus_dma_segment_t hseg[1];
3697 bus_dma_segment_t pseg[1];
3698 struct ixgbe_rx_buf *rxbuf;
3699 struct mbuf *mh, *mp;
3700 int i, j, nsegs, error;
3701 bool refreshed = FALSE;
3703 i = j = rxr->next_to_refresh;
3704 /* Control the loop with one beyond */
3705 if (++j == adapter->num_rx_desc)
3708 while (j != limit) {
3709 rxbuf = &rxr->rx_buffers[i];
3710 if (rxr->hdr_split == FALSE)
3713 if (rxbuf->m_head == NULL) {
3714 mh = m_gethdr(MB_DONTWAIT, MT_DATA);
3720 mh->m_pkthdr.len = mh->m_len = MHLEN;
3722 mh->m_flags |= M_PKTHDR;
3723 /* Get the memory mapping */
3724 error = bus_dmamap_load_mbuf_segment(rxr->htag,
3725 rxbuf->hmap, mh, hseg, 1, &nsegs, BUS_DMA_NOWAIT);
3727 kprintf("Refresh mbufs: hdr dmamap load"
3728 " failure - %d\n", error);
3730 rxbuf->m_head = NULL;
3734 bus_dmamap_sync(rxr->htag, rxbuf->hmap,
3735 BUS_DMASYNC_PREREAD);
3736 rxr->rx_base[i].read.hdr_addr =
3737 htole64(hseg[0].ds_addr);
3740 if (rxbuf->m_pack == NULL) {
3741 mp = m_getjcl(MB_DONTWAIT, MT_DATA,
3742 M_PKTHDR, adapter->rx_mbuf_sz);
3748 mp->m_pkthdr.len = mp->m_len = adapter->rx_mbuf_sz;
3749 /* Get the memory mapping */
3750 error = bus_dmamap_load_mbuf_segment(rxr->ptag,
3751 rxbuf->pmap, mp, pseg, 1, &nsegs, BUS_DMA_NOWAIT);
3753 kprintf("Refresh mbufs: payload dmamap load"
3754 " failure - %d\n", error);
3756 rxbuf->m_pack = NULL;
3760 bus_dmamap_sync(rxr->ptag, rxbuf->pmap,
3761 BUS_DMASYNC_PREREAD);
3762 rxr->rx_base[i].read.pkt_addr =
3763 htole64(pseg[0].ds_addr);
3766 /* Next is precalculated */
3768 rxr->next_to_refresh = i;
3769 if (++j == adapter->num_rx_desc)
3773 if (refreshed) /* Update hardware tail index */
3774 IXGBE_WRITE_REG(&adapter->hw,
3775 IXGBE_RDT(rxr->me), rxr->next_to_refresh);
3779 /*********************************************************************
3781 * Allocate memory for rx_buffer structures. Since we use one
3782 * rx_buffer per received packet, the maximum number of rx_buffer's
3783 * that we'll need is equal to the number of receive descriptors
3784 * that we've allocated.
3786 **********************************************************************/
3788 ixgbe_allocate_receive_buffers(struct rx_ring *rxr)
3790 struct adapter *adapter = rxr->adapter;
3791 device_t dev = adapter->dev;
3792 struct ixgbe_rx_buf *rxbuf;
3793 int i, bsize, error;
3795 bsize = sizeof(struct ixgbe_rx_buf) * adapter->num_rx_desc;
3796 if (!(rxr->rx_buffers =
3797 (struct ixgbe_rx_buf *) kmalloc(bsize,
3798 M_DEVBUF, M_NOWAIT | M_ZERO))) {
3799 device_printf(dev, "Unable to allocate rx_buffer memory\n");
3804 if ((error = bus_dma_tag_create(NULL, /* parent */
3805 1, 0, /* alignment, bounds */
3806 BUS_SPACE_MAXADDR, /* lowaddr */
3807 BUS_SPACE_MAXADDR, /* highaddr */
3808 NULL, NULL, /* filter, filterarg */
3809 MSIZE, /* maxsize */
3811 MSIZE, /* maxsegsize */
3814 device_printf(dev, "Unable to create RX DMA tag\n");
3818 if ((error = bus_dma_tag_create(NULL, /* parent */
3819 1, 0, /* alignment, bounds */
3820 BUS_SPACE_MAXADDR, /* lowaddr */
3821 BUS_SPACE_MAXADDR, /* highaddr */
3822 NULL, NULL, /* filter, filterarg */
3823 MJUM16BYTES, /* maxsize */
3825 MJUM16BYTES, /* maxsegsize */
3828 device_printf(dev, "Unable to create RX DMA tag\n");
3832 for (i = 0; i < adapter->num_rx_desc; i++, rxbuf++) {
3833 rxbuf = &rxr->rx_buffers[i];
3834 error = bus_dmamap_create(rxr->htag,
3835 BUS_DMA_NOWAIT, &rxbuf->hmap);
3837 device_printf(dev, "Unable to create RX head map\n");
3840 error = bus_dmamap_create(rxr->ptag,
3841 BUS_DMA_NOWAIT, &rxbuf->pmap);
3843 device_printf(dev, "Unable to create RX pkt map\n");
3851 /* Frees all, but can handle partial completion */
3852 ixgbe_free_receive_structures(adapter);
3857 ** Used to detect a descriptor that has
3858 ** been merged by Hardware RSC.
3861 ixgbe_rsc_count(union ixgbe_adv_rx_desc *rx)
3863 return (le32toh(rx->wb.lower.lo_dword.data) &
3864 IXGBE_RXDADV_RSCCNT_MASK) >> IXGBE_RXDADV_RSCCNT_SHIFT;
3867 /*********************************************************************
3869 * Initialize Hardware RSC (LRO) feature on 82599
3870 * for an RX ring, this is toggled by the LRO capability
3871 * even though it is transparent to the stack.
3873 **********************************************************************/
3876 ixgbe_setup_hw_rsc(struct rx_ring *rxr)
3878 struct adapter *adapter = rxr->adapter;
3879 struct ixgbe_hw *hw = &adapter->hw;
3880 u32 rscctrl, rdrxctl;
3882 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3883 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3884 #ifdef DEV_NETMAP /* crcstrip is optional in netmap */
3885 if (adapter->ifp->if_capenable & IFCAP_NETMAP && !ix_crcstrip)
3886 #endif /* DEV_NETMAP */
3887 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3888 rdrxctl |= IXGBE_RDRXCTL_RSCACKC;
3889 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3891 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(rxr->me));
3892 rscctrl |= IXGBE_RSCCTL_RSCEN;
3894 ** Limit the total number of descriptors that
3895 ** can be combined, so it does not exceed 64K
3897 if (adapter->rx_mbuf_sz == MCLBYTES)
3898 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
3899 else if (adapter->rx_mbuf_sz == MJUMPAGESIZE)
3900 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
3901 else if (adapter->rx_mbuf_sz == MJUM9BYTES)
3902 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
3903 else /* Using 16K cluster */
3904 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
3906 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(rxr->me), rscctrl);
3908 /* Enable TCP header recognition */
3909 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0),
3910 (IXGBE_READ_REG(hw, IXGBE_PSRTYPE(0)) |
3911 IXGBE_PSRTYPE_TCPHDR));
3913 /* Disable RSC for ACK packets */
3914 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3915 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3922 ixgbe_free_receive_ring(struct rx_ring *rxr)
3924 struct adapter *adapter;
3925 struct ixgbe_rx_buf *rxbuf;
3928 adapter = rxr->adapter;
3929 for (i = 0; i < adapter->num_rx_desc; i++) {
3930 rxbuf = &rxr->rx_buffers[i];
3931 if (rxbuf->m_head != NULL) {
3932 bus_dmamap_sync(rxr->htag, rxbuf->hmap,
3933 BUS_DMASYNC_POSTREAD);
3934 bus_dmamap_unload(rxr->htag, rxbuf->hmap);
3935 rxbuf->m_head->m_flags |= M_PKTHDR;
3936 m_freem(rxbuf->m_head);
3938 if (rxbuf->m_pack != NULL) {
3939 bus_dmamap_sync(rxr->ptag, rxbuf->pmap,
3940 BUS_DMASYNC_POSTREAD);
3941 bus_dmamap_unload(rxr->ptag, rxbuf->pmap);
3942 rxbuf->m_pack->m_flags |= M_PKTHDR;
3943 m_freem(rxbuf->m_pack);
3945 rxbuf->m_head = NULL;
3946 rxbuf->m_pack = NULL;
3951 /*********************************************************************
3953 * Initialize a receive ring and its buffers.
3955 **********************************************************************/
3957 ixgbe_setup_receive_ring(struct rx_ring *rxr)
3959 struct adapter *adapter;
3962 struct ixgbe_rx_buf *rxbuf;
3963 bus_dma_segment_t pseg[1], hseg[1];
3965 struct lro_ctrl *lro = &rxr->lro;
3967 int rsize, nsegs, error = 0;
3969 struct netmap_adapter *na = NA(rxr->adapter->ifp);
3970 struct netmap_slot *slot;
3971 #endif /* DEV_NETMAP */
3973 adapter = rxr->adapter;
3977 /* Clear the ring contents */
3980 /* same as in ixgbe_setup_transmit_ring() */
3981 slot = netmap_reset(na, NR_RX, rxr->me, 0);
3982 #endif /* DEV_NETMAP */
3983 rsize = roundup2(adapter->num_rx_desc *
3984 sizeof(union ixgbe_adv_rx_desc), DBA_ALIGN);
3985 bzero((void *)rxr->rx_base, rsize);
3987 /* Free current RX buffer structs and their mbufs */
3988 ixgbe_free_receive_ring(rxr);
3990 /* Configure header split? */
3991 if (ixgbe_header_split)
3992 rxr->hdr_split = TRUE;
3994 /* Now replenish the mbufs */
3995 for (int j = 0; j != adapter->num_rx_desc; ++j) {
3996 struct mbuf *mh, *mp;
3998 rxbuf = &rxr->rx_buffers[j];
4001 * In netmap mode, fill the map and set the buffer
4002 * address in the NIC ring, considering the offset
4003 * between the netmap and NIC rings (see comment in
4004 * ixgbe_setup_transmit_ring() ). No need to allocate
4005 * an mbuf, so end the block with a continue;
4008 int sj = netmap_idx_n2k(&na->rx_rings[rxr->me], j);
4012 addr = PNMB(slot + sj, &paddr);
4013 netmap_load_map(rxr->ptag, rxbuf->pmap, addr);
4014 /* Update descriptor */
4015 rxr->rx_base[j].read.pkt_addr = htole64(paddr);
4018 #endif /* DEV_NETMAP */
4020 ** Don't allocate mbufs if not
4021 ** doing header split, its wasteful
4023 if (rxr->hdr_split == FALSE)
4026 /* First the header */
4027 rxbuf->m_head = m_gethdr(M_NOWAIT, MT_DATA);
4028 if (rxbuf->m_head == NULL) {
4032 m_adj(rxbuf->m_head, ETHER_ALIGN);
4034 mh->m_len = mh->m_pkthdr.len = MHLEN;
4035 mh->m_flags |= M_PKTHDR;
4036 /* Get the memory mapping */
4037 error = bus_dmamap_load_mbuf_segment(rxr->htag,
4038 rxbuf->hmap, rxbuf->m_head, hseg, 1,
4039 &nsegs, BUS_DMA_NOWAIT);
4041 if (error != 0) /* Nothing elegant to do here */
4043 bus_dmamap_sync(rxr->htag,
4044 rxbuf->hmap, BUS_DMASYNC_PREREAD);
4045 /* Update descriptor */
4046 rxr->rx_base[j].read.hdr_addr = htole64(hseg[0].ds_addr);
4049 /* Now the payload cluster */
4050 rxbuf->m_pack = m_getjcl(M_NOWAIT, MT_DATA,
4051 M_PKTHDR, adapter->rx_mbuf_sz);
4052 if (rxbuf->m_pack == NULL) {
4057 mp->m_pkthdr.len = mp->m_len = adapter->rx_mbuf_sz;
4058 /* Get the memory mapping */
4059 error = bus_dmamap_load_mbuf_segment(rxr->ptag,
4060 rxbuf->pmap, mp, hseg, 1,
4061 &nsegs, BUS_DMA_NOWAIT);
4064 bus_dmamap_sync(rxr->ptag,
4065 rxbuf->pmap, BUS_DMASYNC_PREREAD);
4066 /* Update descriptor */
4067 rxr->rx_base[j].read.pkt_addr = htole64(pseg[0].ds_addr);
4071 /* Setup our descriptor indices */
4072 rxr->next_to_check = 0;
4073 rxr->next_to_refresh = 0;
4074 rxr->lro_enabled = FALSE;
4075 rxr->rx_split_packets = 0;
4077 rxr->discard = FALSE;
4078 rxr->vtag_strip = FALSE;
4080 bus_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
4081 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
4084 ** Now set up the LRO interface:
4085 ** 82598 uses software LRO, the
4086 ** 82599 and X540 use a hardware assist.
4089 if ((adapter->hw.mac.type != ixgbe_mac_82598EB) &&
4090 (ifp->if_capenable & IFCAP_RXCSUM) &&
4091 (ifp->if_capenable & IFCAP_LRO))
4092 ixgbe_setup_hw_rsc(rxr);
4093 else if (ifp->if_capenable & IFCAP_LRO) {
4094 int err = tcp_lro_init(lro);
4096 device_printf(dev, "LRO Initialization failed!\n");
4099 INIT_DEBUGOUT("RX Soft LRO Initialized\n");
4100 rxr->lro_enabled = TRUE;
4101 lro->ifp = adapter->ifp;
4105 IXGBE_RX_UNLOCK(rxr);
4109 ixgbe_free_receive_ring(rxr);
4110 IXGBE_RX_UNLOCK(rxr);
4114 /*********************************************************************
4116 * Initialize all receive rings.
4118 **********************************************************************/
4120 ixgbe_setup_receive_structures(struct adapter *adapter)
4122 struct rx_ring *rxr = adapter->rx_rings;
4125 for (j = 0; j < adapter->num_queues; j++, rxr++)
4126 if (ixgbe_setup_receive_ring(rxr))
4132 * Free RX buffers allocated so far, we will only handle
4133 * the rings that completed, the failing case will have
4134 * cleaned up for itself. 'j' failed, so its the terminus.
4136 for (int i = 0; i < j; ++i) {
4137 rxr = &adapter->rx_rings[i];
4138 ixgbe_free_receive_ring(rxr);
4144 /*********************************************************************
4146 * Setup receive registers and features.
4148 **********************************************************************/
4149 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
4151 #define BSIZEPKT_ROUNDUP ((1<<IXGBE_SRRCTL_BSIZEPKT_SHIFT)-1)
4154 ixgbe_initialize_receive_units(struct adapter *adapter)
4156 struct rx_ring *rxr = adapter->rx_rings;
4157 struct ixgbe_hw *hw = &adapter->hw;
4158 struct ifnet *ifp = adapter->ifp;
4159 u32 bufsz, rxctrl, fctrl, srrctl, rxcsum;
4160 u32 reta, mrqc = 0, hlreg, random[10];
4164 * Make sure receives are disabled while
4165 * setting up the descriptor ring
4167 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4168 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL,
4169 rxctrl & ~IXGBE_RXCTRL_RXEN);
4171 /* Enable broadcasts */
4172 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4173 fctrl |= IXGBE_FCTRL_BAM;
4174 fctrl |= IXGBE_FCTRL_DPF;
4175 fctrl |= IXGBE_FCTRL_PMCF;
4176 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4178 /* Set for Jumbo Frames? */
4179 hlreg = IXGBE_READ_REG(hw, IXGBE_HLREG0);
4180 if (ifp->if_mtu > ETHERMTU)
4181 hlreg |= IXGBE_HLREG0_JUMBOEN;
4183 hlreg &= ~IXGBE_HLREG0_JUMBOEN;
4185 /* crcstrip is conditional in netmap (in RDRXCTL too ?) */
4186 if (ifp->if_capenable & IFCAP_NETMAP && !ix_crcstrip)
4187 hlreg &= ~IXGBE_HLREG0_RXCRCSTRP;
4189 hlreg |= IXGBE_HLREG0_RXCRCSTRP;
4190 #endif /* DEV_NETMAP */
4191 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg);
4193 bufsz = (adapter->rx_mbuf_sz +
4194 BSIZEPKT_ROUNDUP) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
4196 for (int i = 0; i < adapter->num_queues; i++, rxr++) {
4197 u64 rdba = rxr->rxdma.dma_paddr;
4199 /* Setup the Base and Length of the Rx Descriptor Ring */
4200 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(i),
4201 (rdba & 0x00000000ffffffffULL));
4202 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(i), (rdba >> 32));
4203 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(i),
4204 adapter->num_rx_desc * sizeof(union ixgbe_adv_rx_desc));
4206 /* Set up the SRRCTL register */
4207 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
4208 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
4209 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
4211 if (rxr->hdr_split) {
4212 /* Use a standard mbuf for the header */
4213 srrctl |= ((IXGBE_RX_HDR <<
4214 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT)
4215 & IXGBE_SRRCTL_BSIZEHDR_MASK);
4216 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
4218 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
4219 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(i), srrctl);
4221 /* Setup the HW Rx Head and Tail Descriptor Pointers */
4222 IXGBE_WRITE_REG(hw, IXGBE_RDH(i), 0);
4223 IXGBE_WRITE_REG(hw, IXGBE_RDT(i), 0);
4226 if (adapter->hw.mac.type != ixgbe_mac_82598EB) {
4227 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
4228 IXGBE_PSRTYPE_UDPHDR |
4229 IXGBE_PSRTYPE_IPV4HDR |
4230 IXGBE_PSRTYPE_IPV6HDR;
4231 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
4234 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
4237 if (adapter->num_queues > 1) {
4241 /* set up random bits */
4242 karc4rand(&random, sizeof(random));
4244 /* Set up the redirection table */
4245 for (i = 0, j = 0; i < 128; i++, j++) {
4246 if (j == adapter->num_queues) j = 0;
4247 reta = (reta << 8) | (j * 0x11);
4249 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
4252 /* Now fill our hash function seeds */
4253 for (int i = 0; i < 10; i++)
4254 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), random[i]);
4256 /* Perform hash on these packet types */
4257 mrqc = IXGBE_MRQC_RSSEN
4258 | IXGBE_MRQC_RSS_FIELD_IPV4
4259 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
4260 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
4261 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP
4262 | IXGBE_MRQC_RSS_FIELD_IPV6_EX
4263 | IXGBE_MRQC_RSS_FIELD_IPV6
4264 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
4265 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP
4266 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP;
4267 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
4269 /* RSS and RX IPP Checksum are mutually exclusive */
4270 rxcsum |= IXGBE_RXCSUM_PCSD;
4273 if (ifp->if_capenable & IFCAP_RXCSUM)
4274 rxcsum |= IXGBE_RXCSUM_PCSD;
4276 if (!(rxcsum & IXGBE_RXCSUM_PCSD))
4277 rxcsum |= IXGBE_RXCSUM_IPPCSE;
4279 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
4284 /*********************************************************************
4286 * Free all receive rings.
4288 **********************************************************************/
4290 ixgbe_free_receive_structures(struct adapter *adapter)
4292 struct rx_ring *rxr = adapter->rx_rings;
4294 for (int i = 0; i < adapter->num_queues; i++, rxr++) {
4296 struct lro_ctrl *lro = &rxr->lro;
4298 ixgbe_free_receive_buffers(rxr);
4299 /* Free LRO memory */
4303 /* Free the ring memory as well */
4304 ixgbe_dma_free(adapter, &rxr->rxdma);
4307 kfree(adapter->rx_rings, M_DEVBUF);
4311 /*********************************************************************
4313 * Free receive ring data structures
4315 **********************************************************************/
4317 ixgbe_free_receive_buffers(struct rx_ring *rxr)
4319 struct adapter *adapter = rxr->adapter;
4320 struct ixgbe_rx_buf *rxbuf;
4322 INIT_DEBUGOUT("free_receive_structures: begin");
4324 /* Cleanup any existing buffers */
4325 if (rxr->rx_buffers != NULL) {
4326 for (int i = 0; i < adapter->num_rx_desc; i++) {
4327 rxbuf = &rxr->rx_buffers[i];
4328 if (rxbuf->m_head != NULL) {
4329 bus_dmamap_sync(rxr->htag, rxbuf->hmap,
4330 BUS_DMASYNC_POSTREAD);
4331 bus_dmamap_unload(rxr->htag, rxbuf->hmap);
4332 rxbuf->m_head->m_flags |= M_PKTHDR;
4333 m_freem(rxbuf->m_head);
4335 if (rxbuf->m_pack != NULL) {
4336 bus_dmamap_sync(rxr->ptag, rxbuf->pmap,
4337 BUS_DMASYNC_POSTREAD);
4338 bus_dmamap_unload(rxr->ptag, rxbuf->pmap);
4339 rxbuf->m_pack->m_flags |= M_PKTHDR;
4340 m_freem(rxbuf->m_pack);
4342 rxbuf->m_head = NULL;
4343 rxbuf->m_pack = NULL;
4344 if (rxbuf->hmap != NULL) {
4345 bus_dmamap_destroy(rxr->htag, rxbuf->hmap);
4348 if (rxbuf->pmap != NULL) {
4349 bus_dmamap_destroy(rxr->ptag, rxbuf->pmap);
4353 if (rxr->rx_buffers != NULL) {
4354 kfree(rxr->rx_buffers, M_DEVBUF);
4355 rxr->rx_buffers = NULL;
4359 if (rxr->htag != NULL) {
4360 bus_dma_tag_destroy(rxr->htag);
4363 if (rxr->ptag != NULL) {
4364 bus_dma_tag_destroy(rxr->ptag);
4371 static __inline void
4372 ixgbe_rx_input(struct rx_ring *rxr, struct ifnet *ifp, struct mbuf *m, u32 ptype)
4376 * ATM LRO is only for IP/TCP packets and TCP checksum of the packet
4377 * should be computed by hardware. Also it should not have VLAN tag in
4378 * ethernet header. In case of IPv6 we do not yet support ext. hdrs.
4381 if (rxr->lro_enabled &&
4382 (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) != 0 &&
4383 (ptype & IXGBE_RXDADV_PKTTYPE_ETQF) == 0 &&
4384 ((ptype & (IXGBE_RXDADV_PKTTYPE_IPV4 | IXGBE_RXDADV_PKTTYPE_TCP)) ==
4385 (IXGBE_RXDADV_PKTTYPE_IPV4 | IXGBE_RXDADV_PKTTYPE_TCP) ||
4386 (ptype & (IXGBE_RXDADV_PKTTYPE_IPV6 | IXGBE_RXDADV_PKTTYPE_TCP)) ==
4387 (IXGBE_RXDADV_PKTTYPE_IPV6 | IXGBE_RXDADV_PKTTYPE_TCP)) &&
4388 (m->m_pkthdr.csum_flags & (CSUM_DATA_VALID | CSUM_PSEUDO_HDR)) ==
4389 (CSUM_DATA_VALID | CSUM_PSEUDO_HDR)) {
4391 * Send to the stack if:
4392 ** - LRO not enabled, or
4393 ** - no LRO resources, or
4394 ** - lro enqueue fails
4396 if (rxr->lro.lro_cnt != 0)
4397 if (tcp_lro_rx(&rxr->lro, m, 0) == 0)
4401 IXGBE_RX_UNLOCK(rxr);
4402 (*ifp->if_input)(ifp, m);
4406 static __inline void
4407 ixgbe_rx_discard(struct rx_ring *rxr, int i)
4409 struct ixgbe_rx_buf *rbuf;
4411 rbuf = &rxr->rx_buffers[i];
4413 if (rbuf->fmp != NULL) {/* Partial chain ? */
4414 rbuf->fmp->m_flags |= M_PKTHDR;
4420 ** With advanced descriptors the writeback
4421 ** clobbers the buffer addrs, so its easier
4422 ** to just free the existing mbufs and take
4423 ** the normal refresh path to get new buffers
4427 m_free(rbuf->m_head);
4428 rbuf->m_head = NULL;
4432 m_free(rbuf->m_pack);
4433 rbuf->m_pack = NULL;
4440 /*********************************************************************
4442 * This routine executes in interrupt context. It replenishes
4443 * the mbufs in the descriptor and sends data which has been
4444 * dma'ed into host memory to upper layer.
4446 * We loop at most count times if count is > 0, or until done if
4449 * Return TRUE for more work, FALSE for all clean.
4450 *********************************************************************/
4452 ixgbe_rxeof(struct ix_queue *que, int count)
4454 struct adapter *adapter = que->adapter;
4455 struct rx_ring *rxr = que->rxr;
4456 struct ifnet *ifp = adapter->ifp;
4458 struct lro_ctrl *lro = &rxr->lro;
4459 struct lro_entry *queued;
4461 int i, nextp, processed = 0;
4463 union ixgbe_adv_rx_desc *cur;
4464 struct ixgbe_rx_buf *rbuf, *nbuf;
4469 if (ifp->if_capenable & IFCAP_NETMAP) {
4471 * Same as the txeof routine: only wakeup clients on intr.
4472 * NKR_PENDINTR in nr_kflags is used to implement interrupt
4473 * mitigation (ixgbe_rxsync() will not look for new packets
4474 * unless NKR_PENDINTR is set).
4476 struct netmap_adapter *na = NA(ifp);
4478 na->rx_rings[rxr->me].nr_kflags |= NKR_PENDINTR;
4479 selwakeuppri(&na->rx_rings[rxr->me].si, PI_NET);
4480 IXGBE_RX_UNLOCK(rxr);
4481 IXGBE_CORE_LOCK(adapter);
4482 selwakeuppri(&na->rx_si, PI_NET);
4483 IXGBE_CORE_UNLOCK(adapter);
4486 #endif /* DEV_NETMAP */
4487 for (i = rxr->next_to_check; count != 0;) {
4488 struct mbuf *sendmp, *mh, *mp;
4490 u16 hlen, plen, hdr;
4494 /* Sync the ring. */
4495 bus_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
4496 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
4498 cur = &rxr->rx_base[i];
4499 staterr = le32toh(cur->wb.upper.status_error);
4501 if ((staterr & IXGBE_RXD_STAT_DD) == 0)
4503 if ((ifp->if_flags & IFF_RUNNING) == 0)
4510 cur->wb.upper.status_error = 0;
4511 rbuf = &rxr->rx_buffers[i];
4515 plen = le16toh(cur->wb.upper.length);
4516 ptype = le32toh(cur->wb.lower.lo_dword.data) &
4517 IXGBE_RXDADV_PKTTYPE_MASK;
4518 hdr = le16toh(cur->wb.lower.lo_dword.hs_rss.hdr_info);
4519 eop = ((staterr & IXGBE_RXD_STAT_EOP) != 0);
4521 /* Process vlan info */
4522 if ((rxr->vtag_strip) && (staterr & IXGBE_RXD_STAT_VP))
4523 vtag = le16toh(cur->wb.upper.vlan);
4525 /* Make sure bad packets are discarded */
4526 if (((staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) != 0) ||
4529 rxr->rx_discarded++;
4531 rxr->discard = FALSE;
4533 rxr->discard = TRUE;
4534 ixgbe_rx_discard(rxr, i);
4539 ** On 82599 which supports a hardware
4540 ** LRO (called HW RSC), packets need
4541 ** not be fragmented across sequential
4542 ** descriptors, rather the next descriptor
4543 ** is indicated in bits of the descriptor.
4544 ** This also means that we might proceses
4545 ** more than one packet at a time, something
4546 ** that has never been true before, it
4547 ** required eliminating global chain pointers
4548 ** in favor of what we are doing here. -jfv
4552 ** Figure out the next descriptor
4555 if (rxr->hw_rsc == TRUE) {
4556 rsc = ixgbe_rsc_count(cur);
4557 rxr->rsc_num += (rsc - 1);
4559 if (rsc) { /* Get hardware index */
4561 IXGBE_RXDADV_NEXTP_MASK) >>
4562 IXGBE_RXDADV_NEXTP_SHIFT);
4563 } else { /* Just sequential */
4565 if (nextp == adapter->num_rx_desc)
4568 nbuf = &rxr->rx_buffers[nextp];
4572 ** The header mbuf is ONLY used when header
4573 ** split is enabled, otherwise we get normal
4574 ** behavior, ie, both header and payload
4575 ** are DMA'd into the payload buffer.
4577 ** Rather than using the fmp/lmp global pointers
4578 ** we now keep the head of a packet chain in the
4579 ** buffer struct and pass this along from one
4580 ** descriptor to the next, until we get EOP.
4582 if (rxr->hdr_split && (rbuf->fmp == NULL)) {
4583 /* This must be an initial descriptor */
4584 hlen = (hdr & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
4585 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
4586 if (hlen > IXGBE_RX_HDR)
4587 hlen = IXGBE_RX_HDR;
4589 mh->m_flags |= M_PKTHDR;
4591 mh->m_pkthdr.len = mh->m_len;
4592 /* Null buf pointer so it is refreshed */
4593 rbuf->m_head = NULL;
4595 ** Check the payload length, this
4596 ** could be zero if its a small
4602 mp->m_flags &= ~M_PKTHDR;
4604 mh->m_pkthdr.len += mp->m_len;
4605 /* Null buf pointer so it is refreshed */
4606 rbuf->m_pack = NULL;
4607 rxr->rx_split_packets++;
4610 ** Now create the forward
4611 ** chain so when complete
4615 /* stash the chain head */
4617 /* Make forward chain */
4619 mp->m_next = nbuf->m_pack;
4621 mh->m_next = nbuf->m_pack;
4623 /* Singlet, prepare to send */
4625 /* If hardware handled vtag */
4627 sendmp->m_pkthdr.ether_vlantag = vtag;
4628 sendmp->m_flags |= M_VLANTAG;
4633 ** Either no header split, or a
4634 ** secondary piece of a fragmented
4639 ** See if there is a stored head
4640 ** that determines what we are
4643 rbuf->m_pack = rbuf->fmp = NULL;
4645 if (sendmp != NULL) { /* secondary frag */
4646 mp->m_flags &= ~M_PKTHDR;
4647 sendmp->m_pkthdr.len += mp->m_len;
4649 /* first desc of a non-ps chain */
4651 sendmp->m_flags |= M_PKTHDR;
4652 sendmp->m_pkthdr.len = mp->m_len;
4653 if (staterr & IXGBE_RXD_STAT_VP) {
4654 sendmp->m_pkthdr.ether_vlantag = vtag;
4655 sendmp->m_flags |= M_VLANTAG;
4658 /* Pass the head pointer on */
4662 mp->m_next = nbuf->m_pack;
4666 /* Sending this frame? */
4668 sendmp->m_pkthdr.rcvif = ifp;
4671 /* capture data for AIM */
4672 rxr->bytes += sendmp->m_pkthdr.len;
4673 rxr->rx_bytes += sendmp->m_pkthdr.len;
4674 if ((ifp->if_capenable & IFCAP_RXCSUM) != 0)
4675 ixgbe_rx_checksum(staterr, sendmp, ptype);
4676 #if 0 /* __FreeBSD_version >= 800000 */
4677 sendmp->m_pkthdr.flowid = que->msix;
4678 sendmp->m_flags |= M_FLOWID;
4682 bus_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
4683 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
4685 /* Advance our pointers to the next descriptor. */
4686 if (++i == adapter->num_rx_desc)
4689 /* Now send to the stack or do LRO */
4690 if (sendmp != NULL) {
4691 rxr->next_to_check = i;
4692 ixgbe_rx_input(rxr, ifp, sendmp, ptype);
4693 i = rxr->next_to_check;
4696 /* Every 8 descriptors we go to refresh mbufs */
4697 if (processed == 8) {
4698 ixgbe_refresh_mbufs(rxr, i);
4703 /* Refresh any remaining buf structs */
4704 if (ixgbe_rx_unrefreshed(rxr))
4705 ixgbe_refresh_mbufs(rxr, i);
4707 rxr->next_to_check = i;
4710 * Flush any outstanding LRO work
4713 while ((queued = SLIST_FIRST(&lro->lro_active)) != NULL) {
4714 SLIST_REMOVE_HEAD(&lro->lro_active, next);
4715 tcp_lro_flush(lro, queued);
4719 IXGBE_RX_UNLOCK(rxr);
4722 ** We still have cleaning to do?
4723 ** Schedule another interrupt if so.
4725 if ((staterr & IXGBE_RXD_STAT_DD) != 0) {
4726 ixgbe_rearm_queues(adapter, (u64)(1 << que->msix));
4734 /*********************************************************************
4736 * Verify that the hardware indicated that the checksum is valid.
4737 * Inform the stack about the status of checksum so that stack
4738 * doesn't spend time verifying the checksum.
4740 *********************************************************************/
4742 ixgbe_rx_checksum(u32 staterr, struct mbuf * mp, u32 ptype)
4744 u16 status = (u16) staterr;
4745 u8 errors = (u8) (staterr >> 24);
4748 if ((ptype & IXGBE_RXDADV_PKTTYPE_ETQF) == 0 &&
4749 (ptype & IXGBE_RXDADV_PKTTYPE_SCTP) != 0)
4752 if (status & IXGBE_RXD_STAT_IPCS) {
4753 if (!(errors & IXGBE_RXD_ERR_IPE)) {
4754 /* IP Checksum Good */
4755 mp->m_pkthdr.csum_flags = CSUM_IP_CHECKED;
4756 mp->m_pkthdr.csum_flags |= CSUM_IP_VALID;
4759 mp->m_pkthdr.csum_flags = 0;
4761 if (status & IXGBE_RXD_STAT_L4CS) {
4762 u16 type = (CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
4765 type = CSUM_SCTP_VALID;
4767 if (!(errors & IXGBE_RXD_ERR_TCPE)) {
4768 mp->m_pkthdr.csum_flags |= type;
4770 mp->m_pkthdr.csum_data = htons(0xffff);
4778 ** This routine is run via an vlan config EVENT,
4779 ** it enables us to use the HW Filter table since
4780 ** we can get the vlan id. This just creates the
4781 ** entry in the soft version of the VFTA, init will
4782 ** repopulate the real table.
4785 ixgbe_register_vlan(void *arg, struct ifnet *ifp, u16 vtag)
4787 struct adapter *adapter = ifp->if_softc;
4790 if (ifp->if_softc != arg) /* Not our event */
4793 if ((vtag == 0) || (vtag > 4095)) /* Invalid */
4796 IXGBE_CORE_LOCK(adapter);
4797 index = (vtag >> 5) & 0x7F;
4799 adapter->shadow_vfta[index] |= (1 << bit);
4800 ++adapter->num_vlans;
4801 ixgbe_init_locked(adapter);
4802 IXGBE_CORE_UNLOCK(adapter);
4806 ** This routine is run via an vlan
4807 ** unconfig EVENT, remove our entry
4808 ** in the soft vfta.
4811 ixgbe_unregister_vlan(void *arg, struct ifnet *ifp, u16 vtag)
4813 struct adapter *adapter = ifp->if_softc;
4816 if (ifp->if_softc != arg)
4819 if ((vtag == 0) || (vtag > 4095)) /* Invalid */
4822 IXGBE_CORE_LOCK(adapter);
4823 index = (vtag >> 5) & 0x7F;
4825 adapter->shadow_vfta[index] &= ~(1 << bit);
4826 --adapter->num_vlans;
4827 /* Re-init to load the changes */
4828 ixgbe_init_locked(adapter);
4829 IXGBE_CORE_UNLOCK(adapter);
4833 ixgbe_setup_vlan_hw_support(struct adapter *adapter)
4835 struct ifnet *ifp = adapter->ifp;
4836 struct ixgbe_hw *hw = &adapter->hw;
4837 struct rx_ring *rxr;
4841 ** We get here thru init_locked, meaning
4842 ** a soft reset, this has already cleared
4843 ** the VFTA and other state, so if there
4844 ** have been no vlan's registered do nothing.
4846 if (adapter->num_vlans == 0)
4850 ** A soft reset zero's out the VFTA, so
4851 ** we need to repopulate it now.
4853 for (int i = 0; i < IXGBE_VFTA_SIZE; i++)
4854 if (adapter->shadow_vfta[i] != 0)
4855 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i),
4856 adapter->shadow_vfta[i]);
4858 ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4859 /* Enable the Filter Table if enabled */
4860 if (ifp->if_capenable & IFCAP_VLAN_HWFILTER) {
4861 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
4862 ctrl |= IXGBE_VLNCTRL_VFE;
4864 if (hw->mac.type == ixgbe_mac_82598EB)
4865 ctrl |= IXGBE_VLNCTRL_VME;
4866 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
4868 /* Setup the queues for vlans */
4869 for (int i = 0; i < adapter->num_queues; i++) {
4870 rxr = &adapter->rx_rings[i];
4871 /* On 82599 the VLAN enable is per/queue in RXDCTL */
4872 if (hw->mac.type != ixgbe_mac_82598EB) {
4873 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
4874 ctrl |= IXGBE_RXDCTL_VME;
4875 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), ctrl);
4877 rxr->vtag_strip = TRUE;
4882 ixgbe_enable_intr(struct adapter *adapter)
4884 struct ixgbe_hw *hw = &adapter->hw;
4885 struct ix_queue *que = adapter->queues;
4886 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
4889 /* Enable Fan Failure detection */
4890 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4891 mask |= IXGBE_EIMS_GPI_SDP1;
4893 mask |= IXGBE_EIMS_ECC;
4894 mask |= IXGBE_EIMS_GPI_SDP0;
4895 mask |= IXGBE_EIMS_GPI_SDP1;
4896 mask |= IXGBE_EIMS_GPI_SDP2;
4898 mask |= IXGBE_EIMS_FLOW_DIR;
4902 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
4904 /* With RSS we use auto clear */
4905 if (adapter->msix_mem) {
4906 mask = IXGBE_EIMS_ENABLE_MASK;
4907 /* Don't autoclear Link */
4908 mask &= ~IXGBE_EIMS_OTHER;
4909 mask &= ~IXGBE_EIMS_LSC;
4910 IXGBE_WRITE_REG(hw, IXGBE_EIAC, mask);
4914 ** Now enable all queues, this is done separately to
4915 ** allow for handling the extended (beyond 32) MSIX
4916 ** vectors that can be used by 82599
4918 for (int i = 0; i < adapter->num_queues; i++, que++)
4919 ixgbe_enable_queue(adapter, que->msix);
4921 IXGBE_WRITE_FLUSH(hw);
4927 ixgbe_disable_intr(struct adapter *adapter)
4929 if (adapter->msix_mem)
4930 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, 0);
4931 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
4932 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
4934 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
4935 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
4936 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
4938 IXGBE_WRITE_FLUSH(&adapter->hw);
4943 ixgbe_read_pci_cfg(struct ixgbe_hw *hw, u32 reg)
4947 value = pci_read_config(((struct ixgbe_osdep *)hw->back)->dev,
4954 ixgbe_write_pci_cfg(struct ixgbe_hw *hw, u32 reg, u16 value)
4956 pci_write_config(((struct ixgbe_osdep *)hw->back)->dev,
4963 ** Setup the correct IVAR register for a particular MSIX interrupt
4964 ** (yes this is all very magic and confusing :)
4965 ** - entry is the register array entry
4966 ** - vector is the MSIX vector for this queue
4967 ** - type is RX/TX/MISC
4970 ixgbe_set_ivar(struct adapter *adapter, u8 entry, u8 vector, s8 type)
4972 struct ixgbe_hw *hw = &adapter->hw;
4975 vector |= IXGBE_IVAR_ALLOC_VAL;
4977 switch (hw->mac.type) {
4979 case ixgbe_mac_82598EB:
4981 entry = IXGBE_IVAR_OTHER_CAUSES_INDEX;
4983 entry += (type * 64);
4984 index = (entry >> 2) & 0x1F;
4985 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
4986 ivar &= ~(0xFF << (8 * (entry & 0x3)));
4987 ivar |= (vector << (8 * (entry & 0x3)));
4988 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR(index), ivar);
4991 case ixgbe_mac_82599EB:
4992 case ixgbe_mac_X540:
4993 if (type == -1) { /* MISC IVAR */
4994 index = (entry & 1) * 8;
4995 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR_MISC);
4996 ivar &= ~(0xFF << index);
4997 ivar |= (vector << index);
4998 IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, ivar);
4999 } else { /* RX/TX IVARS */
5000 index = (16 * (entry & 1)) + (8 * type);
5001 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(entry >> 1));
5002 ivar &= ~(0xFF << index);
5003 ivar |= (vector << index);
5004 IXGBE_WRITE_REG(hw, IXGBE_IVAR(entry >> 1), ivar);
5013 ixgbe_configure_ivars(struct adapter *adapter)
5015 struct ix_queue *que = adapter->queues;
5018 if (ixgbe_max_interrupt_rate > 0)
5019 newitr = (4000000 / ixgbe_max_interrupt_rate) & 0x0FF8;
5023 for (int i = 0; i < adapter->num_queues; i++, que++) {
5024 /* First the RX queue entry */
5025 ixgbe_set_ivar(adapter, i, que->msix, 0);
5026 /* ... and the TX */
5027 ixgbe_set_ivar(adapter, i, que->msix, 1);
5028 /* Set an Initial EITR value */
5029 IXGBE_WRITE_REG(&adapter->hw,
5030 IXGBE_EITR(que->msix), newitr);
5033 /* For the Link interrupt */
5034 ixgbe_set_ivar(adapter, 1, adapter->linkvec, -1);
5038 ** ixgbe_sfp_probe - called in the local timer to
5039 ** determine if a port had optics inserted.
5041 static bool ixgbe_sfp_probe(struct adapter *adapter)
5043 struct ixgbe_hw *hw = &adapter->hw;
5044 device_t dev = adapter->dev;
5045 bool result = FALSE;
5047 if ((hw->phy.type == ixgbe_phy_nl) &&
5048 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
5049 s32 ret = hw->phy.ops.identify_sfp(hw);
5052 ret = hw->phy.ops.reset(hw);
5053 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
5054 device_printf(dev,"Unsupported SFP+ module detected!");
5055 kprintf(" Reload driver with supported module.\n");
5056 adapter->sfp_probe = FALSE;
5059 device_printf(dev,"SFP+ module detected!\n");
5060 /* We now have supported optics */
5061 adapter->sfp_probe = FALSE;
5062 /* Set the optics type so system reports correctly */
5063 ixgbe_setup_optics(adapter);
5071 ** Tasklet handler for MSIX Link interrupts
5072 ** - do outside interrupt since it might sleep
5075 ixgbe_handle_link(void *context, int pending)
5077 struct adapter *adapter = context;
5079 ixgbe_check_link(&adapter->hw,
5080 &adapter->link_speed, &adapter->link_up, 0);
5081 ixgbe_update_link_status(adapter);
5085 ** Tasklet for handling SFP module interrupts
5088 ixgbe_handle_mod(void *context, int pending)
5090 struct adapter *adapter = context;
5091 struct ixgbe_hw *hw = &adapter->hw;
5092 device_t dev = adapter->dev;
5095 err = hw->phy.ops.identify_sfp(hw);
5096 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
5098 "Unsupported SFP+ module type was detected.\n");
5101 err = hw->mac.ops.setup_sfp(hw);
5102 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
5104 "Setup failure - unsupported SFP+ module type.\n");
5107 taskqueue_enqueue(adapter->tq, &adapter->msf_task);
5113 ** Tasklet for handling MSF (multispeed fiber) interrupts
5116 ixgbe_handle_msf(void *context, int pending)
5118 struct adapter *adapter = context;
5119 struct ixgbe_hw *hw = &adapter->hw;
5123 autoneg = hw->phy.autoneg_advertised;
5124 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
5125 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiate);
5126 if (hw->mac.ops.setup_link)
5127 hw->mac.ops.setup_link(hw, autoneg, negotiate, TRUE);
5133 ** Tasklet for reinitializing the Flow Director filter table
5136 ixgbe_reinit_fdir(void *context, int pending)
5138 struct adapter *adapter = context;
5139 struct ifnet *ifp = adapter->ifp;
5141 if (adapter->fdir_reinit != 1) /* Shouldn't happen */
5143 ixgbe_reinit_fdir_tables_82599(&adapter->hw);
5144 adapter->fdir_reinit = 0;
5145 /* re-enable flow director interrupts */
5146 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
5147 /* Restart the interface */
5148 ifp->if_drv_flags |= IFF_DRV_RUNNING;
5153 /**********************************************************************
5155 * Update the board statistics counters.
5157 **********************************************************************/
5159 ixgbe_update_stats_counters(struct adapter *adapter)
5161 struct ifnet *ifp = adapter->ifp;
5162 struct ixgbe_hw *hw = &adapter->hw;
5163 u32 missed_rx = 0, bprc, lxon, lxoff, total;
5164 u64 total_missed_rx = 0;
5166 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
5167 adapter->stats.illerrc += IXGBE_READ_REG(hw, IXGBE_ILLERRC);
5168 adapter->stats.errbc += IXGBE_READ_REG(hw, IXGBE_ERRBC);
5169 adapter->stats.mspdc += IXGBE_READ_REG(hw, IXGBE_MSPDC);
5171 for (int i = 0; i < 8; i++) {
5173 mp = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5174 /* missed_rx tallies misses for the gprc workaround */
5176 /* global total per queue */
5177 adapter->stats.mpc[i] += mp;
5178 /* Running comprehensive total for stats display */
5179 total_missed_rx += adapter->stats.mpc[i];
5180 if (hw->mac.type == ixgbe_mac_82598EB)
5181 adapter->stats.rnbc[i] +=
5182 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5183 adapter->stats.pxontxc[i] +=
5184 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5185 adapter->stats.pxonrxc[i] +=
5186 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
5187 adapter->stats.pxofftxc[i] +=
5188 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
5189 adapter->stats.pxoffrxc[i] +=
5190 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
5191 adapter->stats.pxon2offc[i] +=
5192 IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
5194 for (int i = 0; i < 16; i++) {
5195 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5196 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5197 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
5198 adapter->stats.qbrc[i] +=
5199 ((u64)IXGBE_READ_REG(hw, IXGBE_QBRC(i)) << 32);
5200 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5201 adapter->stats.qbtc[i] +=
5202 ((u64)IXGBE_READ_REG(hw, IXGBE_QBTC(i)) << 32);
5203 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
5205 adapter->stats.mlfc += IXGBE_READ_REG(hw, IXGBE_MLFC);
5206 adapter->stats.mrfc += IXGBE_READ_REG(hw, IXGBE_MRFC);
5207 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
5209 /* Hardware workaround, gprc counts missed packets */
5210 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
5211 adapter->stats.gprc -= missed_rx;
5213 if (hw->mac.type != ixgbe_mac_82598EB) {
5214 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL) +
5215 ((u64)IXGBE_READ_REG(hw, IXGBE_GORCH) << 32);
5216 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL) +
5217 ((u64)IXGBE_READ_REG(hw, IXGBE_GOTCH) << 32);
5218 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL) +
5219 ((u64)IXGBE_READ_REG(hw, IXGBE_TORH) << 32);
5220 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
5221 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
5223 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
5224 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
5225 /* 82598 only has a counter in the high register */
5226 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5227 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5228 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5232 * Workaround: mprc hardware is incorrectly counting
5233 * broadcasts, so for now we subtract those.
5235 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
5236 adapter->stats.bprc += bprc;
5237 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
5238 if (hw->mac.type == ixgbe_mac_82598EB)
5239 adapter->stats.mprc -= bprc;
5241 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5242 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5243 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5244 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5245 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5246 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5248 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
5249 adapter->stats.lxontxc += lxon;
5250 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
5251 adapter->stats.lxofftxc += lxoff;
5252 total = lxon + lxoff;
5254 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5255 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
5256 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5257 adapter->stats.gptc -= total;
5258 adapter->stats.mptc -= total;
5259 adapter->stats.ptc64 -= total;
5260 adapter->stats.gotc -= total * ETHER_MIN_LEN;
5262 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5263 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5264 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5265 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5266 adapter->stats.mngprc += IXGBE_READ_REG(hw, IXGBE_MNGPRC);
5267 adapter->stats.mngpdc += IXGBE_READ_REG(hw, IXGBE_MNGPDC);
5268 adapter->stats.mngptc += IXGBE_READ_REG(hw, IXGBE_MNGPTC);
5269 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5270 adapter->stats.tpt += IXGBE_READ_REG(hw, IXGBE_TPT);
5271 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5272 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5273 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5274 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5275 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5276 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
5277 adapter->stats.xec += IXGBE_READ_REG(hw, IXGBE_XEC);
5278 adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5279 adapter->stats.fclast += IXGBE_READ_REG(hw, IXGBE_FCLAST);
5280 /* Only read FCOE on 82599 */
5281 if (hw->mac.type != ixgbe_mac_82598EB) {
5282 adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5283 adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5284 adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5285 adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5286 adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
5289 /* Fill out the OS statistics structure */
5290 ifp->if_ipackets = adapter->stats.gprc;
5291 ifp->if_opackets = adapter->stats.gptc;
5292 ifp->if_ibytes = adapter->stats.gorc;
5293 ifp->if_obytes = adapter->stats.gotc;
5294 ifp->if_imcasts = adapter->stats.mprc;
5295 ifp->if_collisions = 0;
5298 ifp->if_ierrors = total_missed_rx + adapter->stats.crcerrs +
5299 adapter->stats.rlec;
5302 /** ixgbe_sysctl_tdh_handler - Handler function
5303 * Retrieves the TDH value from the hardware
5306 ixgbe_sysctl_tdh_handler(SYSCTL_HANDLER_ARGS)
5310 struct tx_ring *txr = ((struct tx_ring *)oidp->oid_arg1);
5313 unsigned val = IXGBE_READ_REG(&txr->adapter->hw, IXGBE_TDH(txr->me));
5314 error = sysctl_handle_int(oidp, &val, 0, req);
5315 if (error || !req->newptr)
5320 /** ixgbe_sysctl_tdt_handler - Handler function
5321 * Retrieves the TDT value from the hardware
5324 ixgbe_sysctl_tdt_handler(SYSCTL_HANDLER_ARGS)
5328 struct tx_ring *txr = ((struct tx_ring *)oidp->oid_arg1);
5331 unsigned val = IXGBE_READ_REG(&txr->adapter->hw, IXGBE_TDT(txr->me));
5332 error = sysctl_handle_int(oidp, &val, 0, req);
5333 if (error || !req->newptr)
5338 /** ixgbe_sysctl_rdh_handler - Handler function
5339 * Retrieves the RDH value from the hardware
5342 ixgbe_sysctl_rdh_handler(SYSCTL_HANDLER_ARGS)
5346 struct rx_ring *rxr = ((struct rx_ring *)oidp->oid_arg1);
5349 unsigned val = IXGBE_READ_REG(&rxr->adapter->hw, IXGBE_RDH(rxr->me));
5350 error = sysctl_handle_int(oidp, &val, 0, req);
5351 if (error || !req->newptr)
5356 /** ixgbe_sysctl_rdt_handler - Handler function
5357 * Retrieves the RDT value from the hardware
5360 ixgbe_sysctl_rdt_handler(SYSCTL_HANDLER_ARGS)
5364 struct rx_ring *rxr = ((struct rx_ring *)oidp->oid_arg1);
5367 unsigned val = IXGBE_READ_REG(&rxr->adapter->hw, IXGBE_RDT(rxr->me));
5368 error = sysctl_handle_int(oidp, &val, 0, req);
5369 if (error || !req->newptr)
5375 ixgbe_sysctl_interrupt_rate_handler(SYSCTL_HANDLER_ARGS)
5378 struct ix_queue *que = ((struct ix_queue *)oidp->oid_arg1);
5379 unsigned int reg, usec, rate;
5381 reg = IXGBE_READ_REG(&que->adapter->hw, IXGBE_EITR(que->msix));
5382 usec = ((reg & 0x0FF8) >> 3);
5384 rate = 500000 / usec;
5387 error = sysctl_handle_int(oidp, &rate, 0, req);
5388 if (error || !req->newptr)
5390 reg &= ~0xfff; /* default, no limitation */
5391 ixgbe_max_interrupt_rate = 0;
5392 if (rate > 0 && rate < 500000) {
5395 ixgbe_max_interrupt_rate = rate;
5396 reg |= ((4000000/rate) & 0xff8 );
5398 IXGBE_WRITE_REG(&que->adapter->hw, IXGBE_EITR(que->msix), reg);
5403 * Add sysctl variables, one per statistic, to the system.
5406 ixgbe_add_hw_stats(struct adapter *adapter)
5408 struct tx_ring *txr = adapter->tx_rings;
5409 struct rx_ring *rxr = adapter->rx_rings;
5411 struct sysctl_ctx_list *ctx = &adapter->sysctl_ctx;
5412 struct sysctl_oid *tree = adapter->sysctl_tree;
5413 struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
5414 struct ixgbe_hw_stats *stats = &adapter->stats;
5416 struct sysctl_oid *stat_node, *queue_node;
5417 struct sysctl_oid_list *stat_list, *queue_list;
5419 #define QUEUE_NAME_LEN 32
5420 char namebuf[QUEUE_NAME_LEN];
5422 /* Driver Statistics */
5423 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "dropped",
5424 CTLFLAG_RD, &adapter->dropped_pkts,
5425 "Driver dropped packets");
5426 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "mbuf_defrag_failed",
5427 CTLFLAG_RD, &adapter->mbuf_defrag_failed,
5428 "m_defrag() failed");
5429 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "no_tx_dma_setup",
5430 CTLFLAG_RD, &adapter->no_tx_dma_setup,
5431 "Driver tx dma failure in xmit");
5432 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "watchdog_events",
5433 CTLFLAG_RD, &adapter->watchdog_events,
5434 "Watchdog timeouts");
5435 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "tso_tx",
5436 CTLFLAG_RD, &adapter->tso_tx,
5438 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "link_irq",
5439 CTLFLAG_RD, &adapter->link_irq,
5440 "Link MSIX IRQ Handled");
5442 for (int i = 0; i < adapter->num_queues; i++, txr++) {
5443 ksnprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i);
5444 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf,
5445 CTLFLAG_RD, NULL, "Queue Name");
5446 queue_list = SYSCTL_CHILDREN(queue_node);
5448 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "interrupt_rate",
5449 CTLTYPE_UINT | CTLFLAG_RW, &adapter->queues[i],
5450 sizeof(&adapter->queues[i]),
5451 ixgbe_sysctl_interrupt_rate_handler, "IU",
5453 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "irqs",
5454 CTLFLAG_RD, &(adapter->queues[i].irqs), 0,
5455 "irqs on this queue");
5456 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "txd_head",
5457 CTLTYPE_UINT | CTLFLAG_RD, txr, sizeof(txr),
5458 ixgbe_sysctl_tdh_handler, "IU",
5459 "Transmit Descriptor Head");
5460 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "txd_tail",
5461 CTLTYPE_UINT | CTLFLAG_RD, txr, sizeof(txr),
5462 ixgbe_sysctl_tdt_handler, "IU",
5463 "Transmit Descriptor Tail");
5464 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "no_desc_avail",
5465 CTLFLAG_RD, &txr->no_desc_avail, 0,
5466 "Queue No Descriptor Available");
5467 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "tx_packets",
5468 CTLFLAG_RD, &txr->total_packets, 0,
5469 "Queue Packets Transmitted");
5472 for (int i = 0; i < adapter->num_queues; i++, rxr++) {
5473 ksnprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i);
5474 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf,
5475 CTLFLAG_RD, NULL, "Queue Name");
5476 queue_list = SYSCTL_CHILDREN(queue_node);
5479 struct lro_ctrl *lro = &rxr->lro;
5482 ksnprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i);
5483 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf,
5484 CTLFLAG_RD, NULL, "Queue Name");
5485 queue_list = SYSCTL_CHILDREN(queue_node);
5487 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "rxd_head",
5488 CTLTYPE_UINT | CTLFLAG_RD, rxr, sizeof(rxr),
5489 ixgbe_sysctl_rdh_handler, "IU",
5490 "Receive Descriptor Head");
5491 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "rxd_tail",
5492 CTLTYPE_UINT | CTLFLAG_RD, rxr, sizeof(rxr),
5493 ixgbe_sysctl_rdt_handler, "IU",
5494 "Receive Descriptor Tail");
5495 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_packets",
5496 CTLFLAG_RD, &rxr->rx_packets, 0,
5497 "Queue Packets Received");
5498 SYSCTL_ADD_UQUAD(ctx, queue_list, OID_AUTO, "rx_bytes",
5499 CTLFLAG_RD, &rxr->rx_bytes, 0,
5500 "Queue Bytes Received");
5502 SYSCTL_ADD_INT(ctx, queue_list, OID_AUTO, "lro_queued",
5503 CTLFLAG_RD, &lro->lro_queued, 0,
5505 SYSCTL_ADD_INT(ctx, queue_list, OID_AUTO, "lro_flushed",
5506 CTLFLAG_RD, &lro->lro_flushed, 0,
5511 /* MAC stats get the own sub node */
5513 stat_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "mac_stats",
5514 CTLFLAG_RD, NULL, "MAC Statistics");
5515 stat_list = SYSCTL_CHILDREN(stat_node);
5517 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "crc_errs",
5518 CTLFLAG_RD, &stats->crcerrs, 0,
5520 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "ill_errs",
5521 CTLFLAG_RD, &stats->illerrc, 0,
5522 "Illegal Byte Errors");
5523 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "byte_errs",
5524 CTLFLAG_RD, &stats->errbc, 0,
5526 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "short_discards",
5527 CTLFLAG_RD, &stats->mspdc, 0,
5528 "MAC Short Packets Discarded");
5529 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "local_faults",
5530 CTLFLAG_RD, &stats->mlfc, 0,
5531 "MAC Local Faults");
5532 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "remote_faults",
5533 CTLFLAG_RD, &stats->mrfc, 0,
5534 "MAC Remote Faults");
5535 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rec_len_errs",
5536 CTLFLAG_RD, &stats->rlec, 0,
5537 "Receive Length Errors");
5538 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "link_xon_txd",
5539 CTLFLAG_RD, &stats->lxontxc, 0,
5540 "Link XON Transmitted");
5541 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "link_xon_rcvd",
5542 CTLFLAG_RD, &stats->lxonrxc, 0,
5543 "Link XON Received");
5544 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "link_xoff_txd",
5545 CTLFLAG_RD, &stats->lxofftxc, 0,
5546 "Link XOFF Transmitted");
5547 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "link_xoff_rcvd",
5548 CTLFLAG_RD, &stats->lxoffrxc, 0,
5549 "Link XOFF Received");
5551 /* Packet Reception Stats */
5552 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "total_octets_rcvd",
5553 CTLFLAG_RD, &stats->tor, 0,
5554 "Total Octets Received");
5555 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_octets_rcvd",
5556 CTLFLAG_RD, &stats->gorc, 0,
5557 "Good Octets Received");
5558 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "total_pkts_rcvd",
5559 CTLFLAG_RD, &stats->tpr, 0,
5560 "Total Packets Received");
5561 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_pkts_rcvd",
5562 CTLFLAG_RD, &stats->gprc, 0,
5563 "Good Packets Received");
5564 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "mcast_pkts_rcvd",
5565 CTLFLAG_RD, &stats->mprc, 0,
5566 "Multicast Packets Received");
5567 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "bcast_pkts_rcvd",
5568 CTLFLAG_RD, &stats->bprc, 0,
5569 "Broadcast Packets Received");
5570 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_64",
5571 CTLFLAG_RD, &stats->prc64, 0,
5572 "64 byte frames received ");
5573 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_65_127",
5574 CTLFLAG_RD, &stats->prc127, 0,
5575 "65-127 byte frames received");
5576 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_128_255",
5577 CTLFLAG_RD, &stats->prc255, 0,
5578 "128-255 byte frames received");
5579 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_256_511",
5580 CTLFLAG_RD, &stats->prc511, 0,
5581 "256-511 byte frames received");
5582 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_512_1023",
5583 CTLFLAG_RD, &stats->prc1023, 0,
5584 "512-1023 byte frames received");
5585 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "rx_frames_1024_1522",
5586 CTLFLAG_RD, &stats->prc1522, 0,
5587 "1023-1522 byte frames received");
5588 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_undersized",
5589 CTLFLAG_RD, &stats->ruc, 0,
5590 "Receive Undersized");
5591 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_fragmented",
5592 CTLFLAG_RD, &stats->rfc, 0,
5593 "Fragmented Packets Received ");
5594 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_oversized",
5595 CTLFLAG_RD, &stats->roc, 0,
5596 "Oversized Packets Received");
5597 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "recv_jabberd",
5598 CTLFLAG_RD, &stats->rjc, 0,
5600 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "management_pkts_rcvd",
5601 CTLFLAG_RD, &stats->mngprc, 0,
5602 "Management Packets Received");
5603 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "management_pkts_drpd",
5604 CTLFLAG_RD, &stats->mngptc, 0,
5605 "Management Packets Dropped");
5606 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "checksum_errs",
5607 CTLFLAG_RD, &stats->xec, 0,
5610 /* Packet Transmission Stats */
5611 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_octets_txd",
5612 CTLFLAG_RD, &stats->gotc, 0,
5613 "Good Octets Transmitted");
5614 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "total_pkts_txd",
5615 CTLFLAG_RD, &stats->tpt, 0,
5616 "Total Packets Transmitted");
5617 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "good_pkts_txd",
5618 CTLFLAG_RD, &stats->gptc, 0,
5619 "Good Packets Transmitted");
5620 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "bcast_pkts_txd",
5621 CTLFLAG_RD, &stats->bptc, 0,
5622 "Broadcast Packets Transmitted");
5623 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "mcast_pkts_txd",
5624 CTLFLAG_RD, &stats->mptc, 0,
5625 "Multicast Packets Transmitted");
5626 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "management_pkts_txd",
5627 CTLFLAG_RD, &stats->mngptc, 0,
5628 "Management Packets Transmitted");
5629 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_64",
5630 CTLFLAG_RD, &stats->ptc64, 0,
5631 "64 byte frames transmitted ");
5632 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_65_127",
5633 CTLFLAG_RD, &stats->ptc127, 0,
5634 "65-127 byte frames transmitted");
5635 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_128_255",
5636 CTLFLAG_RD, &stats->ptc255, 0,
5637 "128-255 byte frames transmitted");
5638 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_256_511",
5639 CTLFLAG_RD, &stats->ptc511, 0,
5640 "256-511 byte frames transmitted");
5641 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_512_1023",
5642 CTLFLAG_RD, &stats->ptc1023, 0,
5643 "512-1023 byte frames transmitted");
5644 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "tx_frames_1024_1522",
5645 CTLFLAG_RD, &stats->ptc1522, 0,
5646 "1024-1522 byte frames transmitted");
5649 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "fc_crc",
5650 CTLFLAG_RD, &stats->fccrc, 0,
5652 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "fc_last",
5653 CTLFLAG_RD, &stats->fclast, 0,
5655 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "fc_drpd",
5656 CTLFLAG_RD, &stats->fcoerpdc, 0,
5657 "FCoE Packets Dropped");
5658 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "fc_pkts_rcvd",
5659 CTLFLAG_RD, &stats->fcoeprc, 0,
5660 "FCoE Packets Received");
5661 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "fc_pkts_txd",
5662 CTLFLAG_RD, &stats->fcoeptc, 0,
5663 "FCoE Packets Transmitted");
5664 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "fc_dword_rcvd",
5665 CTLFLAG_RD, &stats->fcoedwrc, 0,
5666 "FCoE DWords Received");
5667 SYSCTL_ADD_UQUAD(ctx, stat_list, OID_AUTO, "fc_dword_txd",
5668 CTLFLAG_RD, &stats->fcoedwtc, 0,
5669 "FCoE DWords Transmitted");
5673 ** Set flow control using sysctl:
5674 ** Flow control values:
5681 ixgbe_set_flowcntl(SYSCTL_HANDLER_ARGS)
5684 struct adapter *adapter = (struct adapter *) arg1;
5687 error = sysctl_handle_int(oidp, &adapter->fc, 0, req);
5688 if ((error) || (req->newptr == NULL))
5691 /* Don't bother if it's not changed */
5692 if (adapter->fc == last)
5695 switch (adapter->fc) {
5696 case ixgbe_fc_rx_pause:
5697 case ixgbe_fc_tx_pause:
5699 adapter->hw.fc.requested_mode = adapter->fc;
5703 adapter->hw.fc.requested_mode = ixgbe_fc_none;
5705 /* Don't autoneg if forcing a value */
5706 adapter->hw.fc.disable_fc_autoneg = TRUE;
5707 ixgbe_fc_enable(&adapter->hw);
5712 ixgbe_add_rx_process_limit(struct adapter *adapter, const char *name,
5713 const char *description, int *limit, int value)
5716 SYSCTL_ADD_INT(&adapter->sysctl_ctx,
5717 SYSCTL_CHILDREN(adapter->sysctl_tree),
5718 OID_AUTO, name, CTLTYPE_INT|CTLFLAG_RW, limit, value, description);
5722 ** Control link advertise speed:
5723 ** 1 - advertise only 1G
5724 ** 2 - advertise 100Mb
5725 ** 3 - advertise normal
5728 ixgbe_set_advertise(SYSCTL_HANDLER_ARGS)
5731 struct adapter *adapter;
5733 struct ixgbe_hw *hw;
5734 ixgbe_link_speed speed, last;
5736 adapter = (struct adapter *) arg1;
5739 last = adapter->advertise;
5741 error = sysctl_handle_int(oidp, &adapter->advertise, 0, req);
5742 if ((error) || (adapter->advertise == -1))
5745 if (adapter->advertise == last) /* no change */
5748 if (!((hw->phy.media_type == ixgbe_media_type_copper) ||
5749 (hw->phy.multispeed_fiber)))
5752 if ((adapter->advertise == 2) && (hw->mac.type != ixgbe_mac_X540)) {
5753 device_printf(dev, "Set Advertise: 100Mb on X540 only\n");
5757 if (adapter->advertise == 1)
5758 speed = IXGBE_LINK_SPEED_1GB_FULL;
5759 else if (adapter->advertise == 2)
5760 speed = IXGBE_LINK_SPEED_100_FULL;
5761 else if (adapter->advertise == 3)
5762 speed = IXGBE_LINK_SPEED_1GB_FULL |
5763 IXGBE_LINK_SPEED_10GB_FULL;
5764 else /* bogus value */
5767 hw->mac.autotry_restart = TRUE;
5768 hw->mac.ops.setup_link(hw, speed, TRUE, TRUE);
5774 ** Thermal Shutdown Trigger
5775 ** - cause a Thermal Overtemp IRQ
5778 ixgbe_set_thermal_test(SYSCTL_HANDLER_ARGS)
5780 int error, fire = 0;
5781 struct adapter *adapter = (struct adapter *) arg1;
5782 struct ixgbe_hw *hw = &adapter->hw;
5785 if (hw->mac.type != ixgbe_mac_X540)
5788 error = sysctl_handle_int(oidp, &fire, 0, req);
5789 if ((error) || (req->newptr == NULL))
5793 u32 reg = IXGBE_READ_REG(hw, IXGBE_EICS);
5794 reg |= IXGBE_EICR_TS;
5795 IXGBE_WRITE_REG(hw, IXGBE_EICS, reg);