1 /******************************************************************************
3 Copyright (c) 2001-2010, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ******************************************************************************/
35 #ifdef HAVE_KERNEL_OPTION_HEADERS
36 #include "opt_device_polling.h"
41 /*********************************************************************
42 * Set this to one to display debug statistics
43 *********************************************************************/
44 int ixgbe_display_debug_stats = 0;
46 /*********************************************************************
48 *********************************************************************/
49 char ixgbe_driver_version[] = "2.3.8";
51 /*********************************************************************
54 * Used by probe to select devices to load on
55 * Last field stores an index into ixgbe_strings
56 * Last entry must be all 0s
58 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index }
59 *********************************************************************/
61 static ixgbe_vendor_info_t ixgbe_vendor_info_array[] =
63 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AF_DUAL_PORT, 0, 0, 0},
64 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AF_SINGLE_PORT, 0, 0, 0},
65 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_CX4, 0, 0, 0},
66 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AT, 0, 0, 0},
67 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AT2, 0, 0, 0},
68 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598, 0, 0, 0},
69 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_DA_DUAL_PORT, 0, 0, 0},
70 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_CX4_DUAL_PORT, 0, 0, 0},
71 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_XF_LR, 0, 0, 0},
72 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM, 0, 0, 0},
73 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_SFP_LOM, 0, 0, 0},
74 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KX4, 0, 0, 0},
75 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KX4_MEZZ, 0, 0, 0},
76 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP, 0, 0, 0},
77 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_XAUI_LOM, 0, 0, 0},
78 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_CX4, 0, 0, 0},
79 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_T3_LOM, 0, 0, 0},
80 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_COMBO_BACKPLANE, 0, 0, 0},
81 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_BACKPLANE_FCOE, 0, 0, 0},
82 {IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_FCOE, 0, 0, 0},
83 /* required last entry */
87 /*********************************************************************
88 * Table of branding strings
89 *********************************************************************/
91 static char *ixgbe_strings[] = {
92 "Intel(R) PRO/10GbE PCI-Express Network Driver"
95 /*********************************************************************
97 *********************************************************************/
98 static int ixgbe_probe(device_t);
99 static int ixgbe_attach(device_t);
100 static int ixgbe_detach(device_t);
101 static int ixgbe_shutdown(device_t);
102 static void ixgbe_start(struct ifnet *);
103 static void ixgbe_start_locked(struct tx_ring *, struct ifnet *);
104 #if __FreeBSD_version >= 800000
105 static int ixgbe_mq_start(struct ifnet *, struct mbuf *);
106 static int ixgbe_mq_start_locked(struct ifnet *,
107 struct tx_ring *, struct mbuf *);
108 static void ixgbe_qflush(struct ifnet *);
110 static int ixgbe_ioctl(struct ifnet *, u_long, caddr_t);
111 static void ixgbe_init(void *);
112 static void ixgbe_init_locked(struct adapter *);
113 static void ixgbe_stop(void *);
114 static void ixgbe_media_status(struct ifnet *, struct ifmediareq *);
115 static int ixgbe_media_change(struct ifnet *);
116 static void ixgbe_identify_hardware(struct adapter *);
117 static int ixgbe_allocate_pci_resources(struct adapter *);
118 static int ixgbe_allocate_msix(struct adapter *);
119 static int ixgbe_allocate_legacy(struct adapter *);
120 static int ixgbe_allocate_queues(struct adapter *);
121 static int ixgbe_setup_msix(struct adapter *);
122 static void ixgbe_free_pci_resources(struct adapter *);
123 static void ixgbe_local_timer(void *);
124 static int ixgbe_setup_interface(device_t, struct adapter *);
125 static void ixgbe_config_link(struct adapter *);
127 static int ixgbe_allocate_transmit_buffers(struct tx_ring *);
128 static int ixgbe_setup_transmit_structures(struct adapter *);
129 static void ixgbe_setup_transmit_ring(struct tx_ring *);
130 static void ixgbe_initialize_transmit_units(struct adapter *);
131 static void ixgbe_free_transmit_structures(struct adapter *);
132 static void ixgbe_free_transmit_buffers(struct tx_ring *);
134 static int ixgbe_allocate_receive_buffers(struct rx_ring *);
135 static int ixgbe_setup_receive_structures(struct adapter *);
136 static int ixgbe_setup_receive_ring(struct rx_ring *);
137 static void ixgbe_initialize_receive_units(struct adapter *);
138 static void ixgbe_free_receive_structures(struct adapter *);
139 static void ixgbe_free_receive_buffers(struct rx_ring *);
140 static void ixgbe_setup_hw_rsc(struct rx_ring *);
142 static void ixgbe_enable_intr(struct adapter *);
143 static void ixgbe_disable_intr(struct adapter *);
144 static void ixgbe_update_stats_counters(struct adapter *);
145 static bool ixgbe_txeof(struct tx_ring *);
146 static bool ixgbe_rxeof(struct ix_queue *, int);
147 static void ixgbe_rx_checksum(u32, struct mbuf *, u32);
148 static void ixgbe_set_promisc(struct adapter *);
149 static void ixgbe_set_multi(struct adapter *);
150 static void ixgbe_update_link_status(struct adapter *);
151 static void ixgbe_refresh_mbufs(struct rx_ring *, int);
152 static int ixgbe_xmit(struct tx_ring *, struct mbuf **);
153 static int ixgbe_set_flowcntl(SYSCTL_HANDLER_ARGS);
154 static int ixgbe_set_advertise(SYSCTL_HANDLER_ARGS);
155 static int ixgbe_dma_malloc(struct adapter *, bus_size_t,
156 struct ixgbe_dma_alloc *, int);
157 static void ixgbe_dma_free(struct adapter *, struct ixgbe_dma_alloc *);
158 static void ixgbe_add_rx_process_limit(struct adapter *, const char *,
159 const char *, int *, int);
160 static bool ixgbe_tx_ctx_setup(struct tx_ring *, struct mbuf *);
161 static bool ixgbe_tso_setup(struct tx_ring *, struct mbuf *, u32 *);
162 static void ixgbe_set_ivar(struct adapter *, u8, u8, s8);
163 static void ixgbe_configure_ivars(struct adapter *);
164 static u8 * ixgbe_mc_array_itr(struct ixgbe_hw *, u8 **, u32 *);
166 static void ixgbe_setup_vlan_hw_support(struct adapter *);
167 static void ixgbe_register_vlan(void *, struct ifnet *, u16);
168 static void ixgbe_unregister_vlan(void *, struct ifnet *, u16);
170 static void ixgbe_add_hw_stats(struct adapter *adapter);
172 static __inline void ixgbe_rx_discard(struct rx_ring *, int);
173 static __inline void ixgbe_rx_input(struct rx_ring *, struct ifnet *,
176 /* Support for pluggable optic modules */
177 static bool ixgbe_sfp_probe(struct adapter *);
178 static void ixgbe_setup_optics(struct adapter *);
180 /* Legacy (single vector interrupt handler */
181 static void ixgbe_legacy_irq(void *);
183 /* The MSI/X Interrupt handlers */
184 static void ixgbe_msix_que(void *);
185 static void ixgbe_msix_link(void *);
187 /* Deferred interrupt tasklets */
188 static void ixgbe_handle_que(void *, int);
189 static void ixgbe_handle_link(void *, int);
190 static void ixgbe_handle_msf(void *, int);
191 static void ixgbe_handle_mod(void *, int);
194 static void ixgbe_atr(struct tx_ring *, struct mbuf *);
195 static void ixgbe_reinit_fdir(void *, int);
198 /*********************************************************************
199 * FreeBSD Device Interface Entry Points
200 *********************************************************************/
202 static device_method_t ixgbe_methods[] = {
203 /* Device interface */
204 DEVMETHOD(device_probe, ixgbe_probe),
205 DEVMETHOD(device_attach, ixgbe_attach),
206 DEVMETHOD(device_detach, ixgbe_detach),
207 DEVMETHOD(device_shutdown, ixgbe_shutdown),
211 static driver_t ixgbe_driver = {
212 "ix", ixgbe_methods, sizeof(struct adapter),
215 devclass_t ixgbe_devclass;
216 DRIVER_MODULE(ixgbe, pci, ixgbe_driver, ixgbe_devclass, 0, 0);
218 MODULE_DEPEND(ixgbe, pci, 1, 1, 1);
219 MODULE_DEPEND(ixgbe, ether, 1, 1, 1);
222 ** TUNEABLE PARAMETERS:
226 ** AIM: Adaptive Interrupt Moderation
227 ** which means that the interrupt rate
228 ** is varied over time based on the
229 ** traffic for that interrupt vector
231 static int ixgbe_enable_aim = TRUE;
232 TUNABLE_INT("hw.ixgbe.enable_aim", &ixgbe_enable_aim);
234 static int ixgbe_max_interrupt_rate = (8000000 / IXGBE_LOW_LATENCY);
235 TUNABLE_INT("hw.ixgbe.max_interrupt_rate", &ixgbe_max_interrupt_rate);
237 /* How many packets rxeof tries to clean at a time */
238 static int ixgbe_rx_process_limit = 128;
239 TUNABLE_INT("hw.ixgbe.rx_process_limit", &ixgbe_rx_process_limit);
241 /* Flow control setting, default to full */
242 static int ixgbe_flow_control = ixgbe_fc_full;
243 TUNABLE_INT("hw.ixgbe.flow_control", &ixgbe_flow_control);
246 ** Smart speed setting, default to on
247 ** this only works as a compile option
248 ** right now as its during attach, set
249 ** this to 'ixgbe_smart_speed_off' to
252 static int ixgbe_smart_speed = ixgbe_smart_speed_on;
255 * MSIX should be the default for best performance,
256 * but this allows it to be forced off for testing.
258 static int ixgbe_enable_msix = 1;
259 TUNABLE_INT("hw.ixgbe.enable_msix", &ixgbe_enable_msix);
262 * Header split: this causes the hardware to DMA
263 * the header into a separate mbuf from the payload,
264 * it can be a performance win in some workloads, but
265 * in others it actually hurts, its off by default.
267 static bool ixgbe_header_split = FALSE;
268 TUNABLE_INT("hw.ixgbe.hdr_split", &ixgbe_header_split);
271 * Number of Queues, can be set to 0,
272 * it then autoconfigures based on the
273 * number of cpus. Each queue is a pair
274 * of RX and TX rings with a msix vector
276 static int ixgbe_num_queues = 0;
277 TUNABLE_INT("hw.ixgbe.num_queues", &ixgbe_num_queues);
280 ** Number of TX descriptors per ring,
281 ** setting higher than RX as this seems
282 ** the better performing choice.
284 static int ixgbe_txd = PERFORM_TXD;
285 TUNABLE_INT("hw.ixgbe.txd", &ixgbe_txd);
287 /* Number of RX descriptors per ring */
288 static int ixgbe_rxd = PERFORM_RXD;
289 TUNABLE_INT("hw.ixgbe.rxd", &ixgbe_rxd);
291 /* Keep running tab on them for sanity check */
292 static int ixgbe_total_ports;
296 ** For Flow Director: this is the
297 ** number of TX packets we sample
298 ** for the filter pool, this means
299 ** every 20th packet will be probed.
301 ** This feature can be disabled by
302 ** setting this to 0.
304 static int atr_sample_rate = 20;
306 ** Flow Director actually 'steals'
307 ** part of the packet buffer as its
308 ** filter pool, this variable controls
310 ** 0 = 64K, 1 = 128K, 2 = 256K
312 static int fdir_pballoc = 1;
315 /*********************************************************************
316 * Device identification routine
318 * ixgbe_probe determines if the driver should be loaded on
319 * adapter based on PCI vendor/device id of the adapter.
321 * return 0 on success, positive on failure
322 *********************************************************************/
325 ixgbe_probe(device_t dev)
327 ixgbe_vendor_info_t *ent;
329 u16 pci_vendor_id = 0;
330 u16 pci_device_id = 0;
331 u16 pci_subvendor_id = 0;
332 u16 pci_subdevice_id = 0;
333 char adapter_name[256];
335 INIT_DEBUGOUT("ixgbe_probe: begin");
337 pci_vendor_id = pci_get_vendor(dev);
338 if (pci_vendor_id != IXGBE_INTEL_VENDOR_ID)
341 pci_device_id = pci_get_device(dev);
342 pci_subvendor_id = pci_get_subvendor(dev);
343 pci_subdevice_id = pci_get_subdevice(dev);
345 ent = ixgbe_vendor_info_array;
346 while (ent->vendor_id != 0) {
347 if ((pci_vendor_id == ent->vendor_id) &&
348 (pci_device_id == ent->device_id) &&
350 ((pci_subvendor_id == ent->subvendor_id) ||
351 (ent->subvendor_id == 0)) &&
353 ((pci_subdevice_id == ent->subdevice_id) ||
354 (ent->subdevice_id == 0))) {
355 sprintf(adapter_name, "%s, Version - %s",
356 ixgbe_strings[ent->index],
357 ixgbe_driver_version);
358 device_set_desc_copy(dev, adapter_name);
367 /*********************************************************************
368 * Device initialization routine
370 * The attach entry point is called when the driver is being loaded.
371 * This routine identifies the type of hardware, allocates all resources
372 * and initializes the hardware.
374 * return 0 on success, positive on failure
375 *********************************************************************/
378 ixgbe_attach(device_t dev)
380 struct adapter *adapter;
386 INIT_DEBUGOUT("ixgbe_attach: begin");
388 /* Allocate, clear, and link in our adapter structure */
389 adapter = device_get_softc(dev);
390 adapter->dev = adapter->osdep.dev = dev;
394 IXGBE_CORE_LOCK_INIT(adapter, device_get_nameunit(dev));
398 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
399 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
400 OID_AUTO, "flow_control", CTLTYPE_INT | CTLFLAG_RW,
401 adapter, 0, ixgbe_set_flowcntl, "I", "Flow Control");
403 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
404 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
405 OID_AUTO, "advertise_gig", CTLTYPE_INT | CTLFLAG_RW,
406 adapter, 0, ixgbe_set_advertise, "I", "1G Link");
408 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
409 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
410 OID_AUTO, "enable_aim", CTLTYPE_INT|CTLFLAG_RW,
411 &ixgbe_enable_aim, 1, "Interrupt Moderation");
413 /* Set up the timer callout */
414 callout_init_mtx(&adapter->timer, &adapter->core_mtx, 0);
416 /* Determine hardware revision */
417 ixgbe_identify_hardware(adapter);
419 /* Do base PCI setup - map BAR0 */
420 if (ixgbe_allocate_pci_resources(adapter)) {
421 device_printf(dev, "Allocation of PCI resources failed\n");
426 /* Do descriptor calc and sanity checks */
427 if (((ixgbe_txd * sizeof(union ixgbe_adv_tx_desc)) % DBA_ALIGN) != 0 ||
428 ixgbe_txd < MIN_TXD || ixgbe_txd > MAX_TXD) {
429 device_printf(dev, "TXD config issue, using default!\n");
430 adapter->num_tx_desc = DEFAULT_TXD;
432 adapter->num_tx_desc = ixgbe_txd;
435 ** With many RX rings it is easy to exceed the
436 ** system mbuf allocation. Tuning nmbclusters
437 ** can alleviate this.
439 if (nmbclusters > 0 ) {
441 s = (ixgbe_rxd * adapter->num_queues) * ixgbe_total_ports;
442 if (s > nmbclusters) {
443 device_printf(dev, "RX Descriptors exceed "
444 "system mbuf max, using default instead!\n");
445 ixgbe_rxd = DEFAULT_RXD;
449 if (((ixgbe_rxd * sizeof(union ixgbe_adv_rx_desc)) % DBA_ALIGN) != 0 ||
450 ixgbe_rxd < MIN_TXD || ixgbe_rxd > MAX_TXD) {
451 device_printf(dev, "RXD config issue, using default!\n");
452 adapter->num_rx_desc = DEFAULT_RXD;
454 adapter->num_rx_desc = ixgbe_rxd;
456 /* Allocate our TX/RX Queues */
457 if (ixgbe_allocate_queues(adapter)) {
462 /* Allocate multicast array memory. */
463 adapter->mta = malloc(sizeof(u8) * IXGBE_ETH_LENGTH_OF_ADDRESS *
464 MAX_NUM_MULTICAST_ADDRESSES, M_DEVBUF, M_NOWAIT);
465 if (adapter->mta == NULL) {
466 device_printf(dev, "Can not allocate multicast setup array\n");
471 /* Initialize the shared code */
472 error = ixgbe_init_shared_code(hw);
473 if (error == IXGBE_ERR_SFP_NOT_PRESENT) {
475 ** No optics in this port, set up
476 ** so the timer routine will probe
477 ** for later insertion.
479 adapter->sfp_probe = TRUE;
481 } else if (error == IXGBE_ERR_SFP_NOT_SUPPORTED) {
482 device_printf(dev,"Unsupported SFP+ module detected!\n");
486 device_printf(dev,"Unable to initialize the shared code\n");
491 /* Make sure we have a good EEPROM before we read from it */
492 if (ixgbe_validate_eeprom_checksum(&adapter->hw, &csum) < 0) {
493 device_printf(dev,"The EEPROM Checksum Is Not Valid\n");
498 /* Get Hardware Flow Control setting */
499 hw->fc.requested_mode = ixgbe_fc_full;
500 hw->fc.pause_time = IXGBE_FC_PAUSE;
501 hw->fc.low_water = IXGBE_FC_LO;
502 hw->fc.high_water = IXGBE_FC_HI;
503 hw->fc.send_xon = TRUE;
505 error = ixgbe_init_hw(hw);
506 if (error == IXGBE_ERR_EEPROM_VERSION) {
507 device_printf(dev, "This device is a pre-production adapter/"
508 "LOM. Please be aware there may be issues associated "
509 "with your hardware.\n If you are experiencing problems "
510 "please contact your Intel or hardware representative "
511 "who provided you with this hardware.\n");
512 } else if (error == IXGBE_ERR_SFP_NOT_SUPPORTED)
513 device_printf(dev,"Unsupported SFP+ Module\n");
517 device_printf(dev,"Hardware Initialization Failure\n");
521 /* Detect and set physical type */
522 ixgbe_setup_optics(adapter);
524 if ((adapter->msix > 1) && (ixgbe_enable_msix))
525 error = ixgbe_allocate_msix(adapter);
527 error = ixgbe_allocate_legacy(adapter);
531 /* Setup OS specific network interface */
532 if (ixgbe_setup_interface(dev, adapter) != 0)
535 /* Sysctl for limiting the amount of work done in the taskqueue */
536 ixgbe_add_rx_process_limit(adapter, "rx_processing_limit",
537 "max number of rx packets to process", &adapter->rx_process_limit,
538 ixgbe_rx_process_limit);
540 /* Initialize statistics */
541 ixgbe_update_stats_counters(adapter);
543 /* Register for VLAN events */
544 adapter->vlan_attach = EVENTHANDLER_REGISTER(vlan_config,
545 ixgbe_register_vlan, adapter, EVENTHANDLER_PRI_FIRST);
546 adapter->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig,
547 ixgbe_unregister_vlan, adapter, EVENTHANDLER_PRI_FIRST);
549 /* Print PCIE bus type/speed/width info */
550 ixgbe_get_bus_info(hw);
551 device_printf(dev,"PCI Express Bus: Speed %s %s\n",
552 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
553 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
554 (hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
555 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
556 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
559 if ((hw->bus.width <= ixgbe_bus_width_pcie_x4) &&
560 (hw->bus.speed == ixgbe_bus_speed_2500)) {
561 device_printf(dev, "PCI-Express bandwidth available"
562 " for this card\n is not sufficient for"
563 " optimal performance.\n");
564 device_printf(dev, "For optimal performance a x8 "
565 "PCIE, or x4 PCIE 2 slot is required.\n");
568 /* let hardware know driver is loaded */
569 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
570 ctrl_ext |= IXGBE_CTRL_EXT_DRV_LOAD;
571 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
573 ixgbe_add_hw_stats(adapter);
575 INIT_DEBUGOUT("ixgbe_attach: end");
578 ixgbe_free_transmit_structures(adapter);
579 ixgbe_free_receive_structures(adapter);
581 if (adapter->ifp != NULL)
582 if_free(adapter->ifp);
583 ixgbe_free_pci_resources(adapter);
584 free(adapter->mta, M_DEVBUF);
589 /*********************************************************************
590 * Device removal routine
592 * The detach entry point is called when the driver is being removed.
593 * This routine stops the adapter and deallocates all the resources
594 * that were allocated for driver operation.
596 * return 0 on success, positive on failure
597 *********************************************************************/
600 ixgbe_detach(device_t dev)
602 struct adapter *adapter = device_get_softc(dev);
603 struct ix_queue *que = adapter->queues;
606 INIT_DEBUGOUT("ixgbe_detach: begin");
608 /* Make sure VLANS are not using driver */
609 if (adapter->ifp->if_vlantrunk != NULL) {
610 device_printf(dev,"Vlan in use, detach first\n");
614 IXGBE_CORE_LOCK(adapter);
616 IXGBE_CORE_UNLOCK(adapter);
618 for (int i = 0; i < adapter->num_queues; i++, que++) {
620 taskqueue_drain(que->tq, &que->que_task);
621 taskqueue_free(que->tq);
625 /* Drain the Link queue */
627 taskqueue_drain(adapter->tq, &adapter->link_task);
628 taskqueue_drain(adapter->tq, &adapter->mod_task);
629 taskqueue_drain(adapter->tq, &adapter->msf_task);
631 taskqueue_drain(adapter->tq, &adapter->fdir_task);
633 taskqueue_free(adapter->tq);
636 /* let hardware know driver is unloading */
637 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
638 ctrl_ext &= ~IXGBE_CTRL_EXT_DRV_LOAD;
639 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, ctrl_ext);
641 /* Unregister VLAN events */
642 if (adapter->vlan_attach != NULL)
643 EVENTHANDLER_DEREGISTER(vlan_config, adapter->vlan_attach);
644 if (adapter->vlan_detach != NULL)
645 EVENTHANDLER_DEREGISTER(vlan_unconfig, adapter->vlan_detach);
647 ether_ifdetach(adapter->ifp);
648 callout_drain(&adapter->timer);
649 ixgbe_free_pci_resources(adapter);
650 bus_generic_detach(dev);
651 if_free(adapter->ifp);
653 ixgbe_free_transmit_structures(adapter);
654 ixgbe_free_receive_structures(adapter);
655 free(adapter->mta, M_DEVBUF);
657 IXGBE_CORE_LOCK_DESTROY(adapter);
661 /*********************************************************************
663 * Shutdown entry point
665 **********************************************************************/
668 ixgbe_shutdown(device_t dev)
670 struct adapter *adapter = device_get_softc(dev);
671 IXGBE_CORE_LOCK(adapter);
673 IXGBE_CORE_UNLOCK(adapter);
678 /*********************************************************************
679 * Transmit entry point
681 * ixgbe_start is called by the stack to initiate a transmit.
682 * The driver will remain in this routine as long as there are
683 * packets to transmit and transmit resources are available.
684 * In case resources are not available stack is notified and
685 * the packet is requeued.
686 **********************************************************************/
689 ixgbe_start_locked(struct tx_ring *txr, struct ifnet * ifp)
692 struct adapter *adapter = txr->adapter;
694 IXGBE_TX_LOCK_ASSERT(txr);
696 if ((ifp->if_drv_flags & (IFF_DRV_RUNNING|IFF_DRV_OACTIVE)) !=
699 if (!adapter->link_active)
702 while (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
704 IFQ_DRV_DEQUEUE(&ifp->if_snd, m_head);
708 if (ixgbe_xmit(txr, &m_head)) {
711 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
712 IFQ_DRV_PREPEND(&ifp->if_snd, m_head);
715 /* Send a copy of the frame to the BPF listener */
716 ETHER_BPF_MTAP(ifp, m_head);
718 /* Set watchdog on */
719 txr->watchdog_time = ticks;
720 txr->queue_status = IXGBE_QUEUE_WORKING;
727 * Legacy TX start - called by the stack, this
728 * always uses the first tx ring, and should
729 * not be used with multiqueue tx enabled.
732 ixgbe_start(struct ifnet *ifp)
734 struct adapter *adapter = ifp->if_softc;
735 struct tx_ring *txr = adapter->tx_rings;
737 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
739 ixgbe_start_locked(txr, ifp);
740 IXGBE_TX_UNLOCK(txr);
745 #if __FreeBSD_version >= 800000
747 ** Multiqueue Transmit driver
751 ixgbe_mq_start(struct ifnet *ifp, struct mbuf *m)
753 struct adapter *adapter = ifp->if_softc;
754 struct ix_queue *que;
758 /* Which queue to use */
759 if ((m->m_flags & M_FLOWID) != 0)
760 i = m->m_pkthdr.flowid % adapter->num_queues;
762 txr = &adapter->tx_rings[i];
763 que = &adapter->queues[i];
765 if (IXGBE_TX_TRYLOCK(txr)) {
766 err = ixgbe_mq_start_locked(ifp, txr, m);
767 IXGBE_TX_UNLOCK(txr);
769 err = drbr_enqueue(ifp, txr->br, m);
770 taskqueue_enqueue(que->tq, &que->que_task);
777 ixgbe_mq_start_locked(struct ifnet *ifp, struct tx_ring *txr, struct mbuf *m)
779 struct adapter *adapter = txr->adapter;
781 int enqueued, err = 0;
783 if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) !=
784 IFF_DRV_RUNNING || adapter->link_active == 0) {
786 err = drbr_enqueue(ifp, txr->br, m);
790 /* Call cleanup if number of TX descriptors low */
791 if (txr->tx_avail <= IXGBE_TX_CLEANUP_THRESHOLD)
796 next = drbr_dequeue(ifp, txr->br);
797 } else if (drbr_needs_enqueue(ifp, txr->br)) {
798 if ((err = drbr_enqueue(ifp, txr->br, m)) != 0)
800 next = drbr_dequeue(ifp, txr->br);
804 /* Process the queue */
805 while (next != NULL) {
806 if ((err = ixgbe_xmit(txr, &next)) != 0) {
808 err = drbr_enqueue(ifp, txr->br, next);
812 drbr_stats_update(ifp, next->m_pkthdr.len, next->m_flags);
813 /* Send a copy of the frame to the BPF listener */
814 ETHER_BPF_MTAP(ifp, next);
815 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
817 if (txr->tx_avail <= IXGBE_TX_OP_THRESHOLD) {
818 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
821 next = drbr_dequeue(ifp, txr->br);
825 /* Set watchdog on */
826 txr->queue_status = IXGBE_QUEUE_WORKING;
827 txr->watchdog_time = ticks;
834 ** Flush all ring buffers
837 ixgbe_qflush(struct ifnet *ifp)
839 struct adapter *adapter = ifp->if_softc;
840 struct tx_ring *txr = adapter->tx_rings;
843 for (int i = 0; i < adapter->num_queues; i++, txr++) {
845 while ((m = buf_ring_dequeue_sc(txr->br)) != NULL)
847 IXGBE_TX_UNLOCK(txr);
851 #endif /* __FreeBSD_version >= 800000 */
853 /*********************************************************************
856 * ixgbe_ioctl is called when the user wants to configure the
859 * return 0 on success, positive on failure
860 **********************************************************************/
863 ixgbe_ioctl(struct ifnet * ifp, u_long command, caddr_t data)
865 struct adapter *adapter = ifp->if_softc;
866 struct ifreq *ifr = (struct ifreq *) data;
872 IOCTL_DEBUGOUT("ioctl: SIOCSIFMTU (Set Interface MTU)");
873 if (ifr->ifr_mtu > IXGBE_MAX_FRAME_SIZE - ETHER_HDR_LEN) {
876 IXGBE_CORE_LOCK(adapter);
877 ifp->if_mtu = ifr->ifr_mtu;
878 adapter->max_frame_size =
879 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
880 ixgbe_init_locked(adapter);
881 IXGBE_CORE_UNLOCK(adapter);
885 IOCTL_DEBUGOUT("ioctl: SIOCSIFFLAGS (Set Interface Flags)");
886 IXGBE_CORE_LOCK(adapter);
887 if (ifp->if_flags & IFF_UP) {
888 if ((ifp->if_drv_flags & IFF_DRV_RUNNING)) {
889 if ((ifp->if_flags ^ adapter->if_flags) &
890 (IFF_PROMISC | IFF_ALLMULTI)) {
891 ixgbe_set_promisc(adapter);
894 ixgbe_init_locked(adapter);
896 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
898 adapter->if_flags = ifp->if_flags;
899 IXGBE_CORE_UNLOCK(adapter);
903 IOCTL_DEBUGOUT("ioctl: SIOC(ADD|DEL)MULTI");
904 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
905 IXGBE_CORE_LOCK(adapter);
906 ixgbe_disable_intr(adapter);
907 ixgbe_set_multi(adapter);
908 ixgbe_enable_intr(adapter);
909 IXGBE_CORE_UNLOCK(adapter);
914 IOCTL_DEBUGOUT("ioctl: SIOCxIFMEDIA (Get/Set Interface Media)");
915 error = ifmedia_ioctl(ifp, ifr, &adapter->media, command);
919 int mask = ifr->ifr_reqcap ^ ifp->if_capenable;
920 IOCTL_DEBUGOUT("ioctl: SIOCSIFCAP (Set Capabilities)");
921 if (mask & IFCAP_HWCSUM)
922 ifp->if_capenable ^= IFCAP_HWCSUM;
923 if (mask & IFCAP_TSO4)
924 ifp->if_capenable ^= IFCAP_TSO4;
925 if (mask & IFCAP_LRO)
926 ifp->if_capenable ^= IFCAP_LRO;
927 if (mask & IFCAP_VLAN_HWTAGGING)
928 ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
929 if (mask & IFCAP_VLAN_HWFILTER)
930 ifp->if_capenable ^= IFCAP_VLAN_HWFILTER;
931 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
932 IXGBE_CORE_LOCK(adapter);
933 ixgbe_init_locked(adapter);
934 IXGBE_CORE_UNLOCK(adapter);
936 VLAN_CAPABILITIES(ifp);
941 IOCTL_DEBUGOUT1("ioctl: UNKNOWN (0x%X)\n", (int)command);
942 error = ether_ioctl(ifp, command, data);
949 /*********************************************************************
952 * This routine is used in two ways. It is used by the stack as
953 * init entry point in network interface structure. It is also used
954 * by the driver as a hw/sw initialization routine to get to a
957 * return 0 on success, positive on failure
958 **********************************************************************/
959 #define IXGBE_MHADD_MFS_SHIFT 16
962 ixgbe_init_locked(struct adapter *adapter)
964 struct ifnet *ifp = adapter->ifp;
965 device_t dev = adapter->dev;
966 struct ixgbe_hw *hw = &adapter->hw;
967 u32 k, txdctl, mhadd, gpie;
970 mtx_assert(&adapter->core_mtx, MA_OWNED);
971 INIT_DEBUGOUT("ixgbe_init: begin");
972 hw->adapter_stopped = FALSE;
973 ixgbe_stop_adapter(hw);
974 callout_stop(&adapter->timer);
976 /* reprogram the RAR[0] in case user changed it. */
977 ixgbe_set_rar(hw, 0, adapter->hw.mac.addr, 0, IXGBE_RAH_AV);
979 /* Get the latest mac address, User can use a LAA */
980 bcopy(IF_LLADDR(adapter->ifp), hw->mac.addr,
981 IXGBE_ETH_LENGTH_OF_ADDRESS);
982 ixgbe_set_rar(hw, 0, hw->mac.addr, 0, 1);
983 hw->addr_ctrl.rar_used_count = 1;
985 /* Set the various hardware offload abilities */
986 ifp->if_hwassist = 0;
987 if (ifp->if_capenable & IFCAP_TSO4)
988 ifp->if_hwassist |= CSUM_TSO;
989 if (ifp->if_capenable & IFCAP_TXCSUM) {
990 ifp->if_hwassist |= (CSUM_TCP | CSUM_UDP);
991 #if __FreeBSD_version >= 800000
992 if (hw->mac.type == ixgbe_mac_82599EB)
993 ifp->if_hwassist |= CSUM_SCTP;
997 /* Prepare transmit descriptors and buffers */
998 if (ixgbe_setup_transmit_structures(adapter)) {
999 device_printf(dev,"Could not setup transmit structures\n");
1000 ixgbe_stop(adapter);
1005 ixgbe_initialize_transmit_units(adapter);
1007 /* Setup Multicast table */
1008 ixgbe_set_multi(adapter);
1011 ** Determine the correct mbuf pool
1012 ** for doing jumbo/headersplit
1014 if (adapter->max_frame_size <= 2048)
1015 adapter->rx_mbuf_sz = MCLBYTES;
1016 else if (adapter->max_frame_size <= 4096)
1017 adapter->rx_mbuf_sz = MJUMPAGESIZE;
1018 else if (adapter->max_frame_size <= 9216)
1019 adapter->rx_mbuf_sz = MJUM9BYTES;
1021 adapter->rx_mbuf_sz = MJUM16BYTES;
1023 /* Prepare receive descriptors and buffers */
1024 if (ixgbe_setup_receive_structures(adapter)) {
1025 device_printf(dev,"Could not setup receive structures\n");
1026 ixgbe_stop(adapter);
1030 /* Configure RX settings */
1031 ixgbe_initialize_receive_units(adapter);
1033 gpie = IXGBE_READ_REG(&adapter->hw, IXGBE_GPIE);
1035 if (hw->mac.type == ixgbe_mac_82599EB) {
1036 gpie |= IXGBE_SDP1_GPIEN;
1037 gpie |= IXGBE_SDP2_GPIEN;
1040 /* Enable Fan Failure Interrupt */
1041 if (hw->device_id == IXGBE_DEV_ID_82598AT)
1042 gpie |= IXGBE_SDP1_GPIEN;
1044 if (adapter->msix > 1) {
1045 /* Enable Enhanced MSIX mode */
1046 gpie |= IXGBE_GPIE_MSIX_MODE;
1047 gpie |= IXGBE_GPIE_EIAME | IXGBE_GPIE_PBA_SUPPORT |
1050 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
1053 if (ifp->if_mtu > ETHERMTU) {
1054 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
1055 mhadd &= ~IXGBE_MHADD_MFS_MASK;
1056 mhadd |= adapter->max_frame_size << IXGBE_MHADD_MFS_SHIFT;
1057 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
1060 /* Now enable all the queues */
1062 for (int i = 0; i < adapter->num_queues; i++) {
1063 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
1064 txdctl |= IXGBE_TXDCTL_ENABLE;
1065 /* Set WTHRESH to 8, burst writeback */
1066 txdctl |= (8 << 16);
1067 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), txdctl);
1070 for (int i = 0; i < adapter->num_queues; i++) {
1071 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
1072 if (hw->mac.type == ixgbe_mac_82598EB) {
1078 rxdctl &= ~0x3FFFFF;
1081 rxdctl |= IXGBE_RXDCTL_ENABLE;
1082 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), rxdctl);
1083 for (k = 0; k < 10; k++) {
1084 if (IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)) &
1085 IXGBE_RXDCTL_ENABLE)
1091 IXGBE_WRITE_REG(hw, IXGBE_RDT(i), adapter->num_rx_desc - 1);
1094 /* Set up VLAN support and filter */
1095 ixgbe_setup_vlan_hw_support(adapter);
1097 /* Enable Receive engine */
1098 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1099 if (hw->mac.type == ixgbe_mac_82598EB)
1100 rxctrl |= IXGBE_RXCTRL_DMBYPS;
1101 rxctrl |= IXGBE_RXCTRL_RXEN;
1102 ixgbe_enable_rx_dma(hw, rxctrl);
1104 callout_reset(&adapter->timer, hz, ixgbe_local_timer, adapter);
1106 /* Set up MSI/X routing */
1107 if (ixgbe_enable_msix) {
1108 ixgbe_configure_ivars(adapter);
1109 /* Set up auto-mask */
1110 if (hw->mac.type == ixgbe_mac_82598EB)
1111 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
1113 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
1114 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
1116 } else { /* Simple settings for Legacy/MSI */
1117 ixgbe_set_ivar(adapter, 0, 0, 0);
1118 ixgbe_set_ivar(adapter, 0, 0, 1);
1119 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
1123 /* Init Flow director */
1124 if (hw->mac.type == ixgbe_mac_82599EB)
1125 ixgbe_init_fdir_signature_82599(&adapter->hw, fdir_pballoc);
1129 ** Check on any SFP devices that
1130 ** need to be kick-started
1132 if (hw->phy.type == ixgbe_phy_none) {
1133 int err = hw->phy.ops.identify(hw);
1134 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
1136 "Unsupported SFP+ module type was detected.\n");
1141 /* Set moderation on the Link interrupt */
1142 IXGBE_WRITE_REG(hw, IXGBE_EITR(adapter->linkvec), IXGBE_LINK_ITR);
1144 /* Config/Enable Link */
1145 ixgbe_config_link(adapter);
1147 /* And now turn on interrupts */
1148 ixgbe_enable_intr(adapter);
1150 /* Now inform the stack we're ready */
1151 ifp->if_drv_flags |= IFF_DRV_RUNNING;
1152 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1158 ixgbe_init(void *arg)
1160 struct adapter *adapter = arg;
1162 IXGBE_CORE_LOCK(adapter);
1163 ixgbe_init_locked(adapter);
1164 IXGBE_CORE_UNLOCK(adapter);
1171 ** MSIX Interrupt Handlers and Tasklets
1176 ixgbe_enable_queue(struct adapter *adapter, u32 vector)
1178 struct ixgbe_hw *hw = &adapter->hw;
1179 u64 queue = (u64)(1 << vector);
1182 if (hw->mac.type == ixgbe_mac_82598EB) {
1183 mask = (IXGBE_EIMS_RTX_QUEUE & queue);
1184 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1186 mask = (queue & 0xFFFFFFFF);
1188 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
1189 mask = (queue >> 32);
1191 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1196 ixgbe_disable_queue(struct adapter *adapter, u32 vector)
1198 struct ixgbe_hw *hw = &adapter->hw;
1199 u64 queue = (u64)(1 << vector);
1202 if (hw->mac.type == ixgbe_mac_82598EB) {
1203 mask = (IXGBE_EIMS_RTX_QUEUE & queue);
1204 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1206 mask = (queue & 0xFFFFFFFF);
1208 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
1209 mask = (queue >> 32);
1211 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1216 ixgbe_rearm_queues(struct adapter *adapter, u64 queues)
1220 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1221 mask = (IXGBE_EIMS_RTX_QUEUE & queues);
1222 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
1224 mask = (queues & 0xFFFFFFFF);
1225 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
1226 mask = (queues >> 32);
1227 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
1233 ixgbe_handle_que(void *context, int pending)
1235 struct ix_queue *que = context;
1236 struct adapter *adapter = que->adapter;
1237 struct tx_ring *txr = que->txr;
1238 struct ifnet *ifp = adapter->ifp;
1241 if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
1242 more = ixgbe_rxeof(que, adapter->rx_process_limit);
1245 #if __FreeBSD_version >= 800000
1246 if (!drbr_empty(ifp, txr->br))
1247 ixgbe_mq_start_locked(ifp, txr, NULL);
1249 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
1250 ixgbe_start_locked(txr, ifp);
1252 IXGBE_TX_UNLOCK(txr);
1254 taskqueue_enqueue(que->tq, &que->que_task);
1259 /* Reenable this interrupt */
1260 ixgbe_enable_queue(adapter, que->msix);
1265 /*********************************************************************
1267 * Legacy Interrupt Service routine
1269 **********************************************************************/
1272 ixgbe_legacy_irq(void *arg)
1274 struct ix_queue *que = arg;
1275 struct adapter *adapter = que->adapter;
1276 struct ixgbe_hw *hw = &adapter->hw;
1277 struct tx_ring *txr = adapter->tx_rings;
1278 bool more_tx, more_rx;
1279 u32 reg_eicr, loop = MAX_LOOP;
1282 reg_eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
1285 if (reg_eicr == 0) {
1286 ixgbe_enable_intr(adapter);
1290 more_rx = ixgbe_rxeof(que, adapter->rx_process_limit);
1294 more_tx = ixgbe_txeof(txr);
1295 } while (loop-- && more_tx);
1296 IXGBE_TX_UNLOCK(txr);
1298 if (more_rx || more_tx)
1299 taskqueue_enqueue(que->tq, &que->que_task);
1301 /* Check for fan failure */
1302 if ((hw->phy.media_type == ixgbe_media_type_copper) &&
1303 (reg_eicr & IXGBE_EICR_GPI_SDP1)) {
1304 device_printf(adapter->dev, "\nCRITICAL: FAN FAILURE!! "
1305 "REPLACE IMMEDIATELY!!\n");
1306 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EICR_GPI_SDP1);
1309 /* Link status change */
1310 if (reg_eicr & IXGBE_EICR_LSC)
1311 taskqueue_enqueue(adapter->tq, &adapter->link_task);
1313 ixgbe_enable_intr(adapter);
1318 /*********************************************************************
1320 * MSI Queue Interrupt Service routine
1322 **********************************************************************/
1324 ixgbe_msix_que(void *arg)
1326 struct ix_queue *que = arg;
1327 struct adapter *adapter = que->adapter;
1328 struct tx_ring *txr = que->txr;
1329 struct rx_ring *rxr = que->rxr;
1330 bool more_tx, more_rx;
1335 more_rx = ixgbe_rxeof(que, adapter->rx_process_limit);
1338 more_tx = ixgbe_txeof(txr);
1339 IXGBE_TX_UNLOCK(txr);
1341 more_rx = ixgbe_rxeof(que, adapter->rx_process_limit);
1345 if (ixgbe_enable_aim == FALSE)
1348 ** Do Adaptive Interrupt Moderation:
1349 ** - Write out last calculated setting
1350 ** - Calculate based on average size over
1351 ** the last interval.
1353 if (que->eitr_setting)
1354 IXGBE_WRITE_REG(&adapter->hw,
1355 IXGBE_EITR(que->msix), que->eitr_setting);
1357 que->eitr_setting = 0;
1359 /* Idle, do nothing */
1360 if ((txr->bytes == 0) && (rxr->bytes == 0))
1363 if ((txr->bytes) && (txr->packets))
1364 newitr = txr->bytes/txr->packets;
1365 if ((rxr->bytes) && (rxr->packets))
1366 newitr = max(newitr,
1367 (rxr->bytes / rxr->packets));
1368 newitr += 24; /* account for hardware frame, crc */
1370 /* set an upper boundary */
1371 newitr = min(newitr, 3000);
1373 /* Be nice to the mid range */
1374 if ((newitr > 300) && (newitr < 1200))
1375 newitr = (newitr / 3);
1377 newitr = (newitr / 2);
1379 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
1380 newitr |= newitr << 16;
1382 newitr |= IXGBE_EITR_CNT_WDIS;
1384 /* save for next interrupt */
1385 que->eitr_setting = newitr;
1394 if (more_tx || more_rx)
1395 taskqueue_enqueue(que->tq, &que->que_task);
1396 else /* Reenable this interrupt */
1397 ixgbe_enable_queue(adapter, que->msix);
1403 ixgbe_msix_link(void *arg)
1405 struct adapter *adapter = arg;
1406 struct ixgbe_hw *hw = &adapter->hw;
1409 ++adapter->link_irq;
1411 /* First get the cause */
1412 reg_eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1413 /* Clear interrupt with write */
1414 IXGBE_WRITE_REG(hw, IXGBE_EICR, reg_eicr);
1416 /* Link status change */
1417 if (reg_eicr & IXGBE_EICR_LSC)
1418 taskqueue_enqueue(adapter->tq, &adapter->link_task);
1420 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1422 if (reg_eicr & IXGBE_EICR_FLOW_DIR) {
1423 /* This is probably overkill :) */
1424 if (!atomic_cmpset_int(&adapter->fdir_reinit, 0, 1))
1426 /* Clear the interrupt */
1427 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR);
1428 /* Turn off the interface */
1429 adapter->ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
1430 taskqueue_enqueue(adapter->tq, &adapter->fdir_task);
1433 if (reg_eicr & IXGBE_EICR_ECC) {
1434 device_printf(adapter->dev, "\nCRITICAL: ECC ERROR!! "
1435 "Please Reboot!!\n");
1436 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
1439 if (reg_eicr & IXGBE_EICR_GPI_SDP1) {
1440 /* Clear the interrupt */
1441 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1442 taskqueue_enqueue(adapter->tq, &adapter->msf_task);
1443 } else if (reg_eicr & IXGBE_EICR_GPI_SDP2) {
1444 /* Clear the interrupt */
1445 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1446 taskqueue_enqueue(adapter->tq, &adapter->mod_task);
1450 /* Check for fan failure */
1451 if ((hw->device_id == IXGBE_DEV_ID_82598AT) &&
1452 (reg_eicr & IXGBE_EICR_GPI_SDP1)) {
1453 device_printf(adapter->dev, "\nCRITICAL: FAN FAILURE!! "
1454 "REPLACE IMMEDIATELY!!\n");
1455 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1458 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
1462 /*********************************************************************
1464 * Media Ioctl callback
1466 * This routine is called whenever the user queries the status of
1467 * the interface using ifconfig.
1469 **********************************************************************/
1471 ixgbe_media_status(struct ifnet * ifp, struct ifmediareq * ifmr)
1473 struct adapter *adapter = ifp->if_softc;
1475 INIT_DEBUGOUT("ixgbe_media_status: begin");
1476 IXGBE_CORE_LOCK(adapter);
1477 ixgbe_update_link_status(adapter);
1479 ifmr->ifm_status = IFM_AVALID;
1480 ifmr->ifm_active = IFM_ETHER;
1482 if (!adapter->link_active) {
1483 IXGBE_CORE_UNLOCK(adapter);
1487 ifmr->ifm_status |= IFM_ACTIVE;
1489 switch (adapter->link_speed) {
1490 case IXGBE_LINK_SPEED_1GB_FULL:
1491 ifmr->ifm_active |= IFM_1000_T | IFM_FDX;
1493 case IXGBE_LINK_SPEED_10GB_FULL:
1494 ifmr->ifm_active |= adapter->optics | IFM_FDX;
1498 IXGBE_CORE_UNLOCK(adapter);
1503 /*********************************************************************
1505 * Media Ioctl callback
1507 * This routine is called when the user changes speed/duplex using
1508 * media/mediopt option with ifconfig.
1510 **********************************************************************/
1512 ixgbe_media_change(struct ifnet * ifp)
1514 struct adapter *adapter = ifp->if_softc;
1515 struct ifmedia *ifm = &adapter->media;
1517 INIT_DEBUGOUT("ixgbe_media_change: begin");
1519 if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
1522 switch (IFM_SUBTYPE(ifm->ifm_media)) {
1524 adapter->hw.phy.autoneg_advertised =
1525 IXGBE_LINK_SPEED_1GB_FULL | IXGBE_LINK_SPEED_10GB_FULL;
1528 device_printf(adapter->dev, "Only auto media type\n");
1535 /*********************************************************************
1537 * This routine maps the mbufs to tx descriptors, allowing the
1538 * TX engine to transmit the packets.
1539 * - return 0 on success, positive on failure
1541 **********************************************************************/
1544 ixgbe_xmit(struct tx_ring *txr, struct mbuf **m_headp)
1546 struct adapter *adapter = txr->adapter;
1547 u32 olinfo_status = 0, cmd_type_len;
1549 int i, j, error, nsegs;
1550 int first, last = 0;
1551 struct mbuf *m_head;
1552 bus_dma_segment_t segs[adapter->num_segs];
1554 struct ixgbe_tx_buf *txbuf, *txbuf_mapped;
1555 union ixgbe_adv_tx_desc *txd = NULL;
1559 /* Basic descriptor defines */
1560 cmd_type_len = (IXGBE_ADVTXD_DTYP_DATA |
1561 IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT);
1563 if (m_head->m_flags & M_VLANTAG)
1564 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
1567 * Important to capture the first descriptor
1568 * used because it will contain the index of
1569 * the one we tell the hardware to report back
1571 first = txr->next_avail_desc;
1572 txbuf = &txr->tx_buffers[first];
1573 txbuf_mapped = txbuf;
1577 * Map the packet for DMA.
1579 error = bus_dmamap_load_mbuf_sg(txr->txtag, map,
1580 *m_headp, segs, &nsegs, BUS_DMA_NOWAIT);
1582 if (error == EFBIG) {
1585 m = m_defrag(*m_headp, M_DONTWAIT);
1587 adapter->mbuf_defrag_failed++;
1595 error = bus_dmamap_load_mbuf_sg(txr->txtag, map,
1596 *m_headp, segs, &nsegs, BUS_DMA_NOWAIT);
1598 if (error == ENOMEM) {
1599 adapter->no_tx_dma_setup++;
1601 } else if (error != 0) {
1602 adapter->no_tx_dma_setup++;
1607 } else if (error == ENOMEM) {
1608 adapter->no_tx_dma_setup++;
1610 } else if (error != 0) {
1611 adapter->no_tx_dma_setup++;
1617 /* Make certain there are enough descriptors */
1618 if (nsegs > txr->tx_avail - 2) {
1619 txr->no_desc_avail++;
1626 ** Set up the appropriate offload context
1627 ** this becomes the first descriptor of
1630 if (m_head->m_pkthdr.csum_flags & CSUM_TSO) {
1631 if (ixgbe_tso_setup(txr, m_head, &paylen)) {
1632 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
1633 olinfo_status |= IXGBE_TXD_POPTS_IXSM << 8;
1634 olinfo_status |= IXGBE_TXD_POPTS_TXSM << 8;
1635 olinfo_status |= paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
1639 } else if (ixgbe_tx_ctx_setup(txr, m_head))
1640 olinfo_status |= IXGBE_TXD_POPTS_TXSM << 8;
1642 #ifdef IXGBE_IEEE1588
1643 /* This is changing soon to an mtag detection */
1644 if (we detect this mbuf has a TSTAMP mtag)
1645 cmd_type_len |= IXGBE_ADVTXD_MAC_TSTAMP;
1649 /* Do the flow director magic */
1650 if ((txr->atr_sample) && (!adapter->fdir_reinit)) {
1652 if (txr->atr_count >= atr_sample_rate) {
1653 ixgbe_atr(txr, m_head);
1658 /* Record payload length */
1660 olinfo_status |= m_head->m_pkthdr.len <<
1661 IXGBE_ADVTXD_PAYLEN_SHIFT;
1663 i = txr->next_avail_desc;
1664 for (j = 0; j < nsegs; j++) {
1668 txbuf = &txr->tx_buffers[i];
1669 txd = &txr->tx_base[i];
1670 seglen = segs[j].ds_len;
1671 segaddr = htole64(segs[j].ds_addr);
1673 txd->read.buffer_addr = segaddr;
1674 txd->read.cmd_type_len = htole32(txr->txd_cmd |
1675 cmd_type_len |seglen);
1676 txd->read.olinfo_status = htole32(olinfo_status);
1677 last = i; /* descriptor that will get completion IRQ */
1679 if (++i == adapter->num_tx_desc)
1682 txbuf->m_head = NULL;
1683 txbuf->eop_index = -1;
1686 txd->read.cmd_type_len |=
1687 htole32(IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS);
1688 txr->tx_avail -= nsegs;
1689 txr->next_avail_desc = i;
1691 txbuf->m_head = m_head;
1693 bus_dmamap_sync(txr->txtag, map, BUS_DMASYNC_PREWRITE);
1695 /* Set the index of the descriptor that will be marked done */
1696 txbuf = &txr->tx_buffers[first];
1697 txbuf->eop_index = last;
1699 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
1700 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1702 * Advance the Transmit Descriptor Tail (Tdt), this tells the
1703 * hardware that this frame is available to transmit.
1705 ++txr->total_packets;
1706 IXGBE_WRITE_REG(&adapter->hw, IXGBE_TDT(txr->me), i);
1711 bus_dmamap_unload(txr->txtag, txbuf->map);
1717 ixgbe_set_promisc(struct adapter *adapter)
1720 struct ifnet *ifp = adapter->ifp;
1722 reg_rctl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1723 reg_rctl &= (~IXGBE_FCTRL_UPE);
1724 reg_rctl &= (~IXGBE_FCTRL_MPE);
1725 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, reg_rctl);
1727 if (ifp->if_flags & IFF_PROMISC) {
1728 reg_rctl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1729 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, reg_rctl);
1730 } else if (ifp->if_flags & IFF_ALLMULTI) {
1731 reg_rctl |= IXGBE_FCTRL_MPE;
1732 reg_rctl &= ~IXGBE_FCTRL_UPE;
1733 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, reg_rctl);
1739 /*********************************************************************
1742 * This routine is called whenever multicast address list is updated.
1744 **********************************************************************/
1745 #define IXGBE_RAR_ENTRIES 16
1748 ixgbe_set_multi(struct adapter *adapter)
1753 struct ifmultiaddr *ifma;
1755 struct ifnet *ifp = adapter->ifp;
1757 IOCTL_DEBUGOUT("ixgbe_set_multi: begin");
1760 bzero(mta, sizeof(u8) * IXGBE_ETH_LENGTH_OF_ADDRESS *
1761 MAX_NUM_MULTICAST_ADDRESSES);
1763 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1764 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1765 if (ifp->if_flags & IFF_PROMISC)
1766 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1767 else if (ifp->if_flags & IFF_ALLMULTI) {
1768 fctrl |= IXGBE_FCTRL_MPE;
1769 fctrl &= ~IXGBE_FCTRL_UPE;
1771 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1773 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1775 #if __FreeBSD_version < 800000
1778 if_maddr_rlock(ifp);
1780 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1781 if (ifma->ifma_addr->sa_family != AF_LINK)
1783 bcopy(LLADDR((struct sockaddr_dl *) ifma->ifma_addr),
1784 &mta[mcnt * IXGBE_ETH_LENGTH_OF_ADDRESS],
1785 IXGBE_ETH_LENGTH_OF_ADDRESS);
1788 #if __FreeBSD_version < 800000
1789 IF_ADDR_UNLOCK(ifp);
1791 if_maddr_runlock(ifp);
1795 ixgbe_update_mc_addr_list(&adapter->hw,
1796 update_ptr, mcnt, ixgbe_mc_array_itr);
1802 * This is an iterator function now needed by the multicast
1803 * shared code. It simply feeds the shared code routine the
1804 * addresses in the array of ixgbe_set_multi() one by one.
1807 ixgbe_mc_array_itr(struct ixgbe_hw *hw, u8 **update_ptr, u32 *vmdq)
1809 u8 *addr = *update_ptr;
1813 newptr = addr + IXGBE_ETH_LENGTH_OF_ADDRESS;
1814 *update_ptr = newptr;
1819 /*********************************************************************
1822 * This routine checks for link status,updates statistics,
1823 * and runs the watchdog check.
1825 **********************************************************************/
1828 ixgbe_local_timer(void *arg)
1830 struct adapter *adapter = arg;
1831 device_t dev = adapter->dev;
1832 struct tx_ring *txr = adapter->tx_rings;
1834 mtx_assert(&adapter->core_mtx, MA_OWNED);
1836 /* Check for pluggable optics */
1837 if (adapter->sfp_probe)
1838 if (!ixgbe_sfp_probe(adapter))
1839 goto out; /* Nothing to do */
1841 ixgbe_update_link_status(adapter);
1842 ixgbe_update_stats_counters(adapter);
1845 * If the interface has been paused
1846 * then don't do the watchdog check
1848 if (IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)
1852 ** Check status on the TX queues for a hang
1854 for (int i = 0; i < adapter->num_queues; i++, txr++)
1855 if (txr->queue_status == IXGBE_QUEUE_HUNG)
1859 ixgbe_rearm_queues(adapter, adapter->que_mask);
1860 callout_reset(&adapter->timer, hz, ixgbe_local_timer, adapter);
1864 device_printf(adapter->dev, "Watchdog timeout -- resetting\n");
1865 device_printf(dev,"Queue(%d) tdh = %d, hw tdt = %d\n", txr->me,
1866 IXGBE_READ_REG(&adapter->hw, IXGBE_TDH(txr->me)),
1867 IXGBE_READ_REG(&adapter->hw, IXGBE_TDT(txr->me)));
1868 device_printf(dev,"TX(%d) desc avail = %d,"
1869 "Next TX to Clean = %d\n",
1870 txr->me, txr->tx_avail, txr->next_to_clean);
1871 adapter->ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
1872 adapter->watchdog_events++;
1873 ixgbe_init_locked(adapter);
1877 ** Note: this routine updates the OS on the link state
1878 ** the real check of the hardware only happens with
1879 ** a link interrupt.
1882 ixgbe_update_link_status(struct adapter *adapter)
1884 struct ifnet *ifp = adapter->ifp;
1885 struct tx_ring *txr = adapter->tx_rings;
1886 device_t dev = adapter->dev;
1889 if (adapter->link_up){
1890 if (adapter->link_active == FALSE) {
1892 device_printf(dev,"Link is up %d Gbps %s \n",
1893 ((adapter->link_speed == 128)? 10:1),
1895 adapter->link_active = TRUE;
1896 if_link_state_change(ifp, LINK_STATE_UP);
1898 } else { /* Link down */
1899 if (adapter->link_active == TRUE) {
1901 device_printf(dev,"Link is Down\n");
1902 if_link_state_change(ifp, LINK_STATE_DOWN);
1903 adapter->link_active = FALSE;
1904 for (int i = 0; i < adapter->num_queues;
1906 txr->queue_status = IXGBE_QUEUE_IDLE;
1914 /*********************************************************************
1916 * This routine disables all traffic on the adapter by issuing a
1917 * global reset on the MAC and deallocates TX/RX buffers.
1919 **********************************************************************/
1922 ixgbe_stop(void *arg)
1925 struct adapter *adapter = arg;
1926 struct ixgbe_hw *hw = &adapter->hw;
1929 mtx_assert(&adapter->core_mtx, MA_OWNED);
1931 INIT_DEBUGOUT("ixgbe_stop: begin\n");
1932 ixgbe_disable_intr(adapter);
1934 /* Tell the stack that the interface is no longer active */
1935 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
1938 hw->adapter_stopped = FALSE;
1939 ixgbe_stop_adapter(hw);
1940 /* Turn off the laser */
1941 if (hw->phy.multispeed_fiber)
1942 ixgbe_disable_tx_laser(hw);
1943 callout_stop(&adapter->timer);
1945 /* reprogram the RAR[0] in case user changed it. */
1946 ixgbe_set_rar(&adapter->hw, 0, adapter->hw.mac.addr, 0, IXGBE_RAH_AV);
1952 /*********************************************************************
1954 * Determine hardware revision.
1956 **********************************************************************/
1958 ixgbe_identify_hardware(struct adapter *adapter)
1960 device_t dev = adapter->dev;
1961 struct ixgbe_hw *hw = &adapter->hw;
1963 /* Save off the information about this board */
1964 hw->vendor_id = pci_get_vendor(dev);
1965 hw->device_id = pci_get_device(dev);
1966 hw->revision_id = pci_read_config(dev, PCIR_REVID, 1);
1967 hw->subsystem_vendor_id =
1968 pci_read_config(dev, PCIR_SUBVEND_0, 2);
1969 hw->subsystem_device_id =
1970 pci_read_config(dev, PCIR_SUBDEV_0, 2);
1972 /* We need this here to set the num_segs below */
1973 ixgbe_set_mac_type(hw);
1975 /* Pick up the 82599 and VF settings */
1976 if (hw->mac.type != ixgbe_mac_82598EB) {
1977 hw->phy.smart_speed = ixgbe_smart_speed;
1978 adapter->num_segs = IXGBE_82599_SCATTER;
1980 adapter->num_segs = IXGBE_82598_SCATTER;
1985 /*********************************************************************
1987 * Determine optic type
1989 **********************************************************************/
1991 ixgbe_setup_optics(struct adapter *adapter)
1993 struct ixgbe_hw *hw = &adapter->hw;
1996 layer = ixgbe_get_supported_physical_layer(hw);
1998 case IXGBE_PHYSICAL_LAYER_10GBASE_T:
1999 adapter->optics = IFM_10G_T;
2001 case IXGBE_PHYSICAL_LAYER_1000BASE_T:
2002 adapter->optics = IFM_1000_T;
2004 case IXGBE_PHYSICAL_LAYER_10GBASE_LR:
2005 case IXGBE_PHYSICAL_LAYER_10GBASE_LRM:
2006 adapter->optics = IFM_10G_LR;
2008 case IXGBE_PHYSICAL_LAYER_10GBASE_SR:
2009 adapter->optics = IFM_10G_SR;
2011 case IXGBE_PHYSICAL_LAYER_10GBASE_KX4:
2012 case IXGBE_PHYSICAL_LAYER_10GBASE_CX4:
2013 adapter->optics = IFM_10G_CX4;
2015 case IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU:
2016 adapter->optics = IFM_10G_TWINAX;
2018 case IXGBE_PHYSICAL_LAYER_1000BASE_KX:
2019 case IXGBE_PHYSICAL_LAYER_10GBASE_KR:
2020 case IXGBE_PHYSICAL_LAYER_10GBASE_XAUI:
2021 case IXGBE_PHYSICAL_LAYER_UNKNOWN:
2023 adapter->optics = IFM_ETHER | IFM_AUTO;
2029 /*********************************************************************
2031 * Setup the Legacy or MSI Interrupt handler
2033 **********************************************************************/
2035 ixgbe_allocate_legacy(struct adapter *adapter)
2037 device_t dev = adapter->dev;
2038 struct ix_queue *que = adapter->queues;
2042 if (adapter->msix == 1)
2045 /* We allocate a single interrupt resource */
2046 adapter->res = bus_alloc_resource_any(dev,
2047 SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE);
2048 if (adapter->res == NULL) {
2049 device_printf(dev, "Unable to allocate bus resource: "
2055 * Try allocating a fast interrupt and the associated deferred
2056 * processing contexts.
2058 TASK_INIT(&que->que_task, 0, ixgbe_handle_que, que);
2059 que->tq = taskqueue_create_fast("ixgbe_que", M_NOWAIT,
2060 taskqueue_thread_enqueue, &que->tq);
2061 taskqueue_start_threads(&que->tq, 1, PI_NET, "%s ixq",
2062 device_get_nameunit(adapter->dev));
2064 /* Tasklets for Link, SFP and Multispeed Fiber */
2065 TASK_INIT(&adapter->link_task, 0, ixgbe_handle_link, adapter);
2066 TASK_INIT(&adapter->mod_task, 0, ixgbe_handle_mod, adapter);
2067 TASK_INIT(&adapter->msf_task, 0, ixgbe_handle_msf, adapter);
2069 TASK_INIT(&adapter->fdir_task, 0, ixgbe_reinit_fdir, adapter);
2071 adapter->tq = taskqueue_create_fast("ixgbe_link", M_NOWAIT,
2072 taskqueue_thread_enqueue, &adapter->tq);
2073 taskqueue_start_threads(&adapter->tq, 1, PI_NET, "%s linkq",
2074 device_get_nameunit(adapter->dev));
2076 if ((error = bus_setup_intr(dev, adapter->res,
2077 INTR_TYPE_NET | INTR_MPSAFE, NULL, ixgbe_legacy_irq,
2078 que, &adapter->tag)) != 0) {
2079 device_printf(dev, "Failed to register fast interrupt "
2080 "handler: %d\n", error);
2081 taskqueue_free(que->tq);
2082 taskqueue_free(adapter->tq);
2087 /* For simplicity in the handlers */
2088 adapter->que_mask = IXGBE_EIMS_ENABLE_MASK;
2094 /*********************************************************************
2096 * Setup MSIX Interrupt resources and handlers
2098 **********************************************************************/
2100 ixgbe_allocate_msix(struct adapter *adapter)
2102 device_t dev = adapter->dev;
2103 struct ix_queue *que = adapter->queues;
2104 int error, rid, vector = 0;
2106 for (int i = 0; i < adapter->num_queues; i++, vector++, que++) {
2108 que->res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
2109 RF_SHAREABLE | RF_ACTIVE);
2110 if (que->res == NULL) {
2111 device_printf(dev,"Unable to allocate"
2112 " bus resource: que interrupt [%d]\n", vector);
2115 /* Set the handler function */
2116 error = bus_setup_intr(dev, que->res,
2117 INTR_TYPE_NET | INTR_MPSAFE, NULL,
2118 ixgbe_msix_que, que, &que->tag);
2121 device_printf(dev, "Failed to register QUE handler");
2124 #if __FreeBSD_version >= 800504
2125 bus_describe_intr(dev, que->res, que->tag, "que %d", i);
2128 adapter->que_mask |= (u64)(1 << que->msix);
2130 ** Bind the msix vector, and thus the
2131 ** ring to the corresponding cpu.
2133 if (adapter->num_queues > 1)
2134 bus_bind_intr(dev, que->res, i);
2136 TASK_INIT(&que->que_task, 0, ixgbe_handle_que, que);
2137 que->tq = taskqueue_create_fast("ixgbe_que", M_NOWAIT,
2138 taskqueue_thread_enqueue, &que->tq);
2139 taskqueue_start_threads(&que->tq, 1, PI_NET, "%s que",
2140 device_get_nameunit(adapter->dev));
2145 adapter->res = bus_alloc_resource_any(dev,
2146 SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE);
2147 if (!adapter->res) {
2148 device_printf(dev,"Unable to allocate"
2149 " bus resource: Link interrupt [%d]\n", rid);
2152 /* Set the link handler function */
2153 error = bus_setup_intr(dev, adapter->res,
2154 INTR_TYPE_NET | INTR_MPSAFE, NULL,
2155 ixgbe_msix_link, adapter, &adapter->tag);
2157 adapter->res = NULL;
2158 device_printf(dev, "Failed to register LINK handler");
2161 #if __FreeBSD_version >= 800504
2162 bus_describe_intr(dev, adapter->res, adapter->tag, "link");
2164 adapter->linkvec = vector;
2165 /* Tasklets for Link, SFP and Multispeed Fiber */
2166 TASK_INIT(&adapter->link_task, 0, ixgbe_handle_link, adapter);
2167 TASK_INIT(&adapter->mod_task, 0, ixgbe_handle_mod, adapter);
2168 TASK_INIT(&adapter->msf_task, 0, ixgbe_handle_msf, adapter);
2170 TASK_INIT(&adapter->fdir_task, 0, ixgbe_reinit_fdir, adapter);
2172 adapter->tq = taskqueue_create_fast("ixgbe_link", M_NOWAIT,
2173 taskqueue_thread_enqueue, &adapter->tq);
2174 taskqueue_start_threads(&adapter->tq, 1, PI_NET, "%s linkq",
2175 device_get_nameunit(adapter->dev));
2181 * Setup Either MSI/X or MSI
2184 ixgbe_setup_msix(struct adapter *adapter)
2186 device_t dev = adapter->dev;
2187 int rid, want, queues, msgs;
2189 /* Override by tuneable */
2190 if (ixgbe_enable_msix == 0)
2193 /* First try MSI/X */
2194 rid = PCIR_BAR(MSIX_82598_BAR);
2195 adapter->msix_mem = bus_alloc_resource_any(dev,
2196 SYS_RES_MEMORY, &rid, RF_ACTIVE);
2197 if (!adapter->msix_mem) {
2198 rid += 4; /* 82599 maps in higher BAR */
2199 adapter->msix_mem = bus_alloc_resource_any(dev,
2200 SYS_RES_MEMORY, &rid, RF_ACTIVE);
2202 if (!adapter->msix_mem) {
2203 /* May not be enabled */
2204 device_printf(adapter->dev,
2205 "Unable to map MSIX table \n");
2209 msgs = pci_msix_count(dev);
2210 if (msgs == 0) { /* system has msix disabled */
2211 bus_release_resource(dev, SYS_RES_MEMORY,
2212 rid, adapter->msix_mem);
2213 adapter->msix_mem = NULL;
2217 /* Figure out a reasonable auto config value */
2218 queues = (mp_ncpus > (msgs-1)) ? (msgs-1) : mp_ncpus;
2220 if (ixgbe_num_queues != 0)
2221 queues = ixgbe_num_queues;
2222 /* Set max queues to 8 when autoconfiguring */
2223 else if ((ixgbe_num_queues == 0) && (queues > 8))
2227 ** Want one vector (RX/TX pair) per queue
2228 ** plus an additional for Link.
2234 device_printf(adapter->dev,
2235 "MSIX Configuration Problem, "
2236 "%d vectors but %d queues wanted!\n",
2238 return (0); /* Will go to Legacy setup */
2240 if ((msgs) && pci_alloc_msix(dev, &msgs) == 0) {
2241 device_printf(adapter->dev,
2242 "Using MSIX interrupts with %d vectors\n", msgs);
2243 adapter->num_queues = queues;
2247 msgs = pci_msi_count(dev);
2248 if (msgs == 1 && pci_alloc_msi(dev, &msgs) == 0)
2249 device_printf(adapter->dev,"Using MSI interrupt\n");
2255 ixgbe_allocate_pci_resources(struct adapter *adapter)
2258 device_t dev = adapter->dev;
2261 adapter->pci_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
2264 if (!(adapter->pci_mem)) {
2265 device_printf(dev,"Unable to allocate bus resource: memory\n");
2269 adapter->osdep.mem_bus_space_tag =
2270 rman_get_bustag(adapter->pci_mem);
2271 adapter->osdep.mem_bus_space_handle =
2272 rman_get_bushandle(adapter->pci_mem);
2273 adapter->hw.hw_addr = (u8 *) &adapter->osdep.mem_bus_space_handle;
2275 /* Legacy defaults */
2276 adapter->num_queues = 1;
2277 adapter->hw.back = &adapter->osdep;
2280 ** Now setup MSI or MSI/X, should
2281 ** return us the number of supported
2282 ** vectors. (Will be 1 for MSI)
2284 adapter->msix = ixgbe_setup_msix(adapter);
2289 ixgbe_free_pci_resources(struct adapter * adapter)
2291 struct ix_queue *que = adapter->queues;
2292 device_t dev = adapter->dev;
2295 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
2296 memrid = PCIR_BAR(MSIX_82598_BAR);
2298 memrid = PCIR_BAR(MSIX_82599_BAR);
2301 ** There is a slight possibility of a failure mode
2302 ** in attach that will result in entering this function
2303 ** before interrupt resources have been initialized, and
2304 ** in that case we do not want to execute the loops below
2305 ** We can detect this reliably by the state of the adapter
2308 if (adapter->res == NULL)
2312 ** Release all msix queue resources:
2314 for (int i = 0; i < adapter->num_queues; i++, que++) {
2315 rid = que->msix + 1;
2316 if (que->tag != NULL) {
2317 bus_teardown_intr(dev, que->res, que->tag);
2320 if (que->res != NULL)
2321 bus_release_resource(dev, SYS_RES_IRQ, rid, que->res);
2325 /* Clean the Legacy or Link interrupt last */
2326 if (adapter->linkvec) /* we are doing MSIX */
2327 rid = adapter->linkvec + 1;
2329 (adapter->msix != 0) ? (rid = 1):(rid = 0);
2331 if (adapter->tag != NULL) {
2332 bus_teardown_intr(dev, adapter->res, adapter->tag);
2333 adapter->tag = NULL;
2335 if (adapter->res != NULL)
2336 bus_release_resource(dev, SYS_RES_IRQ, rid, adapter->res);
2340 pci_release_msi(dev);
2342 if (adapter->msix_mem != NULL)
2343 bus_release_resource(dev, SYS_RES_MEMORY,
2344 memrid, adapter->msix_mem);
2346 if (adapter->pci_mem != NULL)
2347 bus_release_resource(dev, SYS_RES_MEMORY,
2348 PCIR_BAR(0), adapter->pci_mem);
2353 /*********************************************************************
2355 * Setup networking device structure and register an interface.
2357 **********************************************************************/
2359 ixgbe_setup_interface(device_t dev, struct adapter *adapter)
2361 struct ixgbe_hw *hw = &adapter->hw;
2364 INIT_DEBUGOUT("ixgbe_setup_interface: begin");
2366 ifp = adapter->ifp = if_alloc(IFT_ETHER);
2368 device_printf(dev, "can not allocate ifnet structure\n");
2371 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
2372 ifp->if_mtu = ETHERMTU;
2373 ifp->if_baudrate = 1000000000;
2374 ifp->if_init = ixgbe_init;
2375 ifp->if_softc = adapter;
2376 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
2377 ifp->if_ioctl = ixgbe_ioctl;
2378 ifp->if_start = ixgbe_start;
2379 #if __FreeBSD_version >= 800000
2380 ifp->if_transmit = ixgbe_mq_start;
2381 ifp->if_qflush = ixgbe_qflush;
2383 ifp->if_snd.ifq_maxlen = adapter->num_tx_desc - 2;
2385 ether_ifattach(ifp, adapter->hw.mac.addr);
2387 adapter->max_frame_size =
2388 ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
2391 * Tell the upper layer(s) we support long frames.
2393 ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
2395 ifp->if_capabilities |= IFCAP_HWCSUM | IFCAP_TSO4 | IFCAP_VLAN_HWCSUM;
2396 ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_MTU;
2397 ifp->if_capabilities |= IFCAP_JUMBO_MTU;
2398 ifp->if_capenable = ifp->if_capabilities;
2400 /* Don't enable LRO by default */
2401 ifp->if_capabilities |= IFCAP_LRO;
2404 ** Dont turn this on by default, if vlans are
2405 ** created on another pseudo device (eg. lagg)
2406 ** then vlan events are not passed thru, breaking
2407 ** operation, but with HW FILTER off it works. If
2408 ** using vlans directly on the em driver you can
2409 ** enable this and get full hardware tag filtering.
2411 ifp->if_capabilities |= IFCAP_VLAN_HWFILTER;
2414 * Specify the media types supported by this adapter and register
2415 * callbacks to update media and link information
2417 ifmedia_init(&adapter->media, IFM_IMASK, ixgbe_media_change,
2418 ixgbe_media_status);
2419 ifmedia_add(&adapter->media, IFM_ETHER | adapter->optics, 0, NULL);
2420 ifmedia_set(&adapter->media, IFM_ETHER | adapter->optics);
2421 if (hw->device_id == IXGBE_DEV_ID_82598AT) {
2422 ifmedia_add(&adapter->media,
2423 IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL);
2424 ifmedia_add(&adapter->media,
2425 IFM_ETHER | IFM_1000_T, 0, NULL);
2427 ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL);
2428 ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO);
2434 ixgbe_config_link(struct adapter *adapter)
2436 struct ixgbe_hw *hw = &adapter->hw;
2437 u32 autoneg, err = 0;
2438 bool sfp, negotiate;
2440 sfp = ixgbe_is_sfp(hw);
2443 if (hw->phy.multispeed_fiber) {
2444 hw->mac.ops.setup_sfp(hw);
2445 ixgbe_enable_tx_laser(hw);
2446 taskqueue_enqueue(adapter->tq, &adapter->msf_task);
2448 taskqueue_enqueue(adapter->tq, &adapter->mod_task);
2450 if (hw->mac.ops.check_link)
2451 err = ixgbe_check_link(hw, &autoneg,
2452 &adapter->link_up, FALSE);
2455 autoneg = hw->phy.autoneg_advertised;
2456 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
2457 err = hw->mac.ops.get_link_capabilities(hw,
2458 &autoneg, &negotiate);
2461 if (hw->mac.ops.setup_link)
2462 err = hw->mac.ops.setup_link(hw, autoneg,
2463 negotiate, adapter->link_up);
2469 /********************************************************************
2470 * Manage DMA'able memory.
2471 *******************************************************************/
2473 ixgbe_dmamap_cb(void *arg, bus_dma_segment_t * segs, int nseg, int error)
2477 *(bus_addr_t *) arg = segs->ds_addr;
2482 ixgbe_dma_malloc(struct adapter *adapter, bus_size_t size,
2483 struct ixgbe_dma_alloc *dma, int mapflags)
2485 device_t dev = adapter->dev;
2488 r = bus_dma_tag_create(bus_get_dma_tag(adapter->dev), /* parent */
2489 DBA_ALIGN, 0, /* alignment, bounds */
2490 BUS_SPACE_MAXADDR, /* lowaddr */
2491 BUS_SPACE_MAXADDR, /* highaddr */
2492 NULL, NULL, /* filter, filterarg */
2495 size, /* maxsegsize */
2496 BUS_DMA_ALLOCNOW, /* flags */
2497 NULL, /* lockfunc */
2498 NULL, /* lockfuncarg */
2501 device_printf(dev,"ixgbe_dma_malloc: bus_dma_tag_create failed; "
2505 r = bus_dmamem_alloc(dma->dma_tag, (void **)&dma->dma_vaddr,
2506 BUS_DMA_NOWAIT, &dma->dma_map);
2508 device_printf(dev,"ixgbe_dma_malloc: bus_dmamem_alloc failed; "
2512 r = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
2516 mapflags | BUS_DMA_NOWAIT);
2518 device_printf(dev,"ixgbe_dma_malloc: bus_dmamap_load failed; "
2522 dma->dma_size = size;
2525 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
2527 bus_dma_tag_destroy(dma->dma_tag);
2529 dma->dma_map = NULL;
2530 dma->dma_tag = NULL;
2535 ixgbe_dma_free(struct adapter *adapter, struct ixgbe_dma_alloc *dma)
2537 bus_dmamap_sync(dma->dma_tag, dma->dma_map,
2538 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
2539 bus_dmamap_unload(dma->dma_tag, dma->dma_map);
2540 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
2541 bus_dma_tag_destroy(dma->dma_tag);
2545 /*********************************************************************
2547 * Allocate memory for the transmit and receive rings, and then
2548 * the descriptors associated with each, called only once at attach.
2550 **********************************************************************/
2552 ixgbe_allocate_queues(struct adapter *adapter)
2554 device_t dev = adapter->dev;
2555 struct ix_queue *que;
2556 struct tx_ring *txr;
2557 struct rx_ring *rxr;
2558 int rsize, tsize, error = IXGBE_SUCCESS;
2559 int txconf = 0, rxconf = 0;
2561 /* First allocate the top level queue structs */
2562 if (!(adapter->queues =
2563 (struct ix_queue *) malloc(sizeof(struct ix_queue) *
2564 adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2565 device_printf(dev, "Unable to allocate queue memory\n");
2570 /* First allocate the TX ring struct memory */
2571 if (!(adapter->tx_rings =
2572 (struct tx_ring *) malloc(sizeof(struct tx_ring) *
2573 adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2574 device_printf(dev, "Unable to allocate TX ring memory\n");
2579 /* Next allocate the RX */
2580 if (!(adapter->rx_rings =
2581 (struct rx_ring *) malloc(sizeof(struct rx_ring) *
2582 adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2583 device_printf(dev, "Unable to allocate RX ring memory\n");
2588 /* For the ring itself */
2589 tsize = roundup2(adapter->num_tx_desc *
2590 sizeof(union ixgbe_adv_tx_desc), DBA_ALIGN);
2593 * Now set up the TX queues, txconf is needed to handle the
2594 * possibility that things fail midcourse and we need to
2595 * undo memory gracefully
2597 for (int i = 0; i < adapter->num_queues; i++, txconf++) {
2598 /* Set up some basics */
2599 txr = &adapter->tx_rings[i];
2600 txr->adapter = adapter;
2603 /* Initialize the TX side lock */
2604 snprintf(txr->mtx_name, sizeof(txr->mtx_name), "%s:tx(%d)",
2605 device_get_nameunit(dev), txr->me);
2606 mtx_init(&txr->tx_mtx, txr->mtx_name, NULL, MTX_DEF);
2608 if (ixgbe_dma_malloc(adapter, tsize,
2609 &txr->txdma, BUS_DMA_NOWAIT)) {
2611 "Unable to allocate TX Descriptor memory\n");
2615 txr->tx_base = (union ixgbe_adv_tx_desc *)txr->txdma.dma_vaddr;
2616 bzero((void *)txr->tx_base, tsize);
2618 /* Now allocate transmit buffers for the ring */
2619 if (ixgbe_allocate_transmit_buffers(txr)) {
2621 "Critical Failure setting up transmit buffers\n");
2625 #if __FreeBSD_version >= 800000
2626 /* Allocate a buf ring */
2627 txr->br = buf_ring_alloc(IXGBE_BR_SIZE, M_DEVBUF,
2628 M_WAITOK, &txr->tx_mtx);
2629 if (txr->br == NULL) {
2631 "Critical Failure setting up buf ring\n");
2639 * Next the RX queues...
2641 rsize = roundup2(adapter->num_rx_desc *
2642 sizeof(union ixgbe_adv_rx_desc), DBA_ALIGN);
2643 for (int i = 0; i < adapter->num_queues; i++, rxconf++) {
2644 rxr = &adapter->rx_rings[i];
2645 /* Set up some basics */
2646 rxr->adapter = adapter;
2649 /* Initialize the RX side lock */
2650 snprintf(rxr->mtx_name, sizeof(rxr->mtx_name), "%s:rx(%d)",
2651 device_get_nameunit(dev), rxr->me);
2652 mtx_init(&rxr->rx_mtx, rxr->mtx_name, NULL, MTX_DEF);
2654 if (ixgbe_dma_malloc(adapter, rsize,
2655 &rxr->rxdma, BUS_DMA_NOWAIT)) {
2657 "Unable to allocate RxDescriptor memory\n");
2661 rxr->rx_base = (union ixgbe_adv_rx_desc *)rxr->rxdma.dma_vaddr;
2662 bzero((void *)rxr->rx_base, rsize);
2664 /* Allocate receive buffers for the ring*/
2665 if (ixgbe_allocate_receive_buffers(rxr)) {
2667 "Critical Failure setting up receive buffers\n");
2674 ** Finally set up the queue holding structs
2676 for (int i = 0; i < adapter->num_queues; i++) {
2677 que = &adapter->queues[i];
2678 que->adapter = adapter;
2679 que->txr = &adapter->tx_rings[i];
2680 que->rxr = &adapter->rx_rings[i];
2686 for (rxr = adapter->rx_rings; rxconf > 0; rxr++, rxconf--)
2687 ixgbe_dma_free(adapter, &rxr->rxdma);
2689 for (txr = adapter->tx_rings; txconf > 0; txr++, txconf--)
2690 ixgbe_dma_free(adapter, &txr->txdma);
2691 free(adapter->rx_rings, M_DEVBUF);
2693 free(adapter->tx_rings, M_DEVBUF);
2695 free(adapter->queues, M_DEVBUF);
2700 /*********************************************************************
2702 * Allocate memory for tx_buffer structures. The tx_buffer stores all
2703 * the information needed to transmit a packet on the wire. This is
2704 * called only once at attach, setup is done every reset.
2706 **********************************************************************/
2708 ixgbe_allocate_transmit_buffers(struct tx_ring *txr)
2710 struct adapter *adapter = txr->adapter;
2711 device_t dev = adapter->dev;
2712 struct ixgbe_tx_buf *txbuf;
2716 * Setup DMA descriptor areas.
2718 if ((error = bus_dma_tag_create(NULL, /* parent */
2719 1, 0, /* alignment, bounds */
2720 BUS_SPACE_MAXADDR, /* lowaddr */
2721 BUS_SPACE_MAXADDR, /* highaddr */
2722 NULL, NULL, /* filter, filterarg */
2723 IXGBE_TSO_SIZE, /* maxsize */
2724 adapter->num_segs, /* nsegments */
2725 PAGE_SIZE, /* maxsegsize */
2727 NULL, /* lockfunc */
2728 NULL, /* lockfuncarg */
2730 device_printf(dev,"Unable to allocate TX DMA tag\n");
2734 if (!(txr->tx_buffers =
2735 (struct ixgbe_tx_buf *) malloc(sizeof(struct ixgbe_tx_buf) *
2736 adapter->num_tx_desc, M_DEVBUF, M_NOWAIT | M_ZERO))) {
2737 device_printf(dev, "Unable to allocate tx_buffer memory\n");
2742 /* Create the descriptor buffer dma maps */
2743 txbuf = txr->tx_buffers;
2744 for (i = 0; i < adapter->num_tx_desc; i++, txbuf++) {
2745 error = bus_dmamap_create(txr->txtag, 0, &txbuf->map);
2747 device_printf(dev, "Unable to create TX DMA map\n");
2754 /* We free all, it handles case where we are in the middle */
2755 ixgbe_free_transmit_structures(adapter);
2759 /*********************************************************************
2761 * Initialize a transmit ring.
2763 **********************************************************************/
2765 ixgbe_setup_transmit_ring(struct tx_ring *txr)
2767 struct adapter *adapter = txr->adapter;
2768 struct ixgbe_tx_buf *txbuf;
2771 /* Clear the old ring contents */
2773 bzero((void *)txr->tx_base,
2774 (sizeof(union ixgbe_adv_tx_desc)) * adapter->num_tx_desc);
2776 txr->next_avail_desc = 0;
2777 txr->next_to_clean = 0;
2779 /* Free any existing tx buffers. */
2780 txbuf = txr->tx_buffers;
2781 for (i = 0; i < adapter->num_tx_desc; i++, txbuf++) {
2782 if (txbuf->m_head != NULL) {
2783 bus_dmamap_sync(txr->txtag, txbuf->map,
2784 BUS_DMASYNC_POSTWRITE);
2785 bus_dmamap_unload(txr->txtag, txbuf->map);
2786 m_freem(txbuf->m_head);
2787 txbuf->m_head = NULL;
2789 /* Clear the EOP index */
2790 txbuf->eop_index = -1;
2794 /* Set the rate at which we sample packets */
2795 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
2796 txr->atr_sample = atr_sample_rate;
2799 /* Set number of descriptors available */
2800 txr->tx_avail = adapter->num_tx_desc;
2802 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
2803 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
2804 IXGBE_TX_UNLOCK(txr);
2807 /*********************************************************************
2809 * Initialize all transmit rings.
2811 **********************************************************************/
2813 ixgbe_setup_transmit_structures(struct adapter *adapter)
2815 struct tx_ring *txr = adapter->tx_rings;
2817 for (int i = 0; i < adapter->num_queues; i++, txr++)
2818 ixgbe_setup_transmit_ring(txr);
2823 /*********************************************************************
2825 * Enable transmit unit.
2827 **********************************************************************/
2829 ixgbe_initialize_transmit_units(struct adapter *adapter)
2831 struct tx_ring *txr = adapter->tx_rings;
2832 struct ixgbe_hw *hw = &adapter->hw;
2834 /* Setup the Base and Length of the Tx Descriptor Ring */
2836 for (int i = 0; i < adapter->num_queues; i++, txr++) {
2837 u64 tdba = txr->txdma.dma_paddr;
2840 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(i),
2841 (tdba & 0x00000000ffffffffULL));
2842 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(i), (tdba >> 32));
2843 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(i),
2844 adapter->num_tx_desc * sizeof(struct ixgbe_legacy_tx_desc));
2846 /* Setup the HW Tx Head and Tail descriptor pointers */
2847 IXGBE_WRITE_REG(hw, IXGBE_TDH(i), 0);
2848 IXGBE_WRITE_REG(hw, IXGBE_TDT(i), 0);
2850 /* Setup Transmit Descriptor Cmd Settings */
2851 txr->txd_cmd = IXGBE_TXD_CMD_IFCS;
2852 txr->queue_status = IXGBE_QUEUE_IDLE;
2854 /* Disable Head Writeback */
2855 switch (hw->mac.type) {
2856 case ixgbe_mac_82598EB:
2857 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i));
2859 case ixgbe_mac_82599EB:
2861 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
2864 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
2865 switch (hw->mac.type) {
2866 case ixgbe_mac_82598EB:
2867 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(i), txctrl);
2869 case ixgbe_mac_82599EB:
2871 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), txctrl);
2877 if (hw->mac.type == ixgbe_mac_82599EB) {
2878 u32 dmatxctl, rttdcs;
2879 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2880 dmatxctl |= IXGBE_DMATXCTL_TE;
2881 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2882 /* Disable arbiter to set MTQC */
2883 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2884 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2885 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2886 IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
2887 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2888 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2894 /*********************************************************************
2896 * Free all transmit rings.
2898 **********************************************************************/
2900 ixgbe_free_transmit_structures(struct adapter *adapter)
2902 struct tx_ring *txr = adapter->tx_rings;
2904 for (int i = 0; i < adapter->num_queues; i++, txr++) {
2906 ixgbe_free_transmit_buffers(txr);
2907 ixgbe_dma_free(adapter, &txr->txdma);
2908 IXGBE_TX_UNLOCK(txr);
2909 IXGBE_TX_LOCK_DESTROY(txr);
2911 free(adapter->tx_rings, M_DEVBUF);
2914 /*********************************************************************
2916 * Free transmit ring related data structures.
2918 **********************************************************************/
2920 ixgbe_free_transmit_buffers(struct tx_ring *txr)
2922 struct adapter *adapter = txr->adapter;
2923 struct ixgbe_tx_buf *tx_buffer;
2926 INIT_DEBUGOUT("free_transmit_ring: begin");
2928 if (txr->tx_buffers == NULL)
2931 tx_buffer = txr->tx_buffers;
2932 for (i = 0; i < adapter->num_tx_desc; i++, tx_buffer++) {
2933 if (tx_buffer->m_head != NULL) {
2934 bus_dmamap_sync(txr->txtag, tx_buffer->map,
2935 BUS_DMASYNC_POSTWRITE);
2936 bus_dmamap_unload(txr->txtag,
2938 m_freem(tx_buffer->m_head);
2939 tx_buffer->m_head = NULL;
2940 if (tx_buffer->map != NULL) {
2941 bus_dmamap_destroy(txr->txtag,
2943 tx_buffer->map = NULL;
2945 } else if (tx_buffer->map != NULL) {
2946 bus_dmamap_unload(txr->txtag,
2948 bus_dmamap_destroy(txr->txtag,
2950 tx_buffer->map = NULL;
2953 #if __FreeBSD_version >= 800000
2954 if (txr->br != NULL)
2955 buf_ring_free(txr->br, M_DEVBUF);
2957 if (txr->tx_buffers != NULL) {
2958 free(txr->tx_buffers, M_DEVBUF);
2959 txr->tx_buffers = NULL;
2961 if (txr->txtag != NULL) {
2962 bus_dma_tag_destroy(txr->txtag);
2968 /*********************************************************************
2970 * Advanced Context Descriptor setup for VLAN or CSUM
2972 **********************************************************************/
2975 ixgbe_tx_ctx_setup(struct tx_ring *txr, struct mbuf *mp)
2977 struct adapter *adapter = txr->adapter;
2978 struct ixgbe_adv_tx_context_desc *TXD;
2979 struct ixgbe_tx_buf *tx_buffer;
2980 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
2981 struct ether_vlan_header *eh;
2983 struct ip6_hdr *ip6;
2984 int ehdrlen, ip_hlen = 0;
2987 bool offload = TRUE;
2988 int ctxd = txr->next_avail_desc;
2992 if ((mp->m_pkthdr.csum_flags & CSUM_OFFLOAD) == 0)
2995 tx_buffer = &txr->tx_buffers[ctxd];
2996 TXD = (struct ixgbe_adv_tx_context_desc *) &txr->tx_base[ctxd];
2999 ** In advanced descriptors the vlan tag must
3000 ** be placed into the descriptor itself.
3002 if (mp->m_flags & M_VLANTAG) {
3003 vtag = htole16(mp->m_pkthdr.ether_vtag);
3004 vlan_macip_lens |= (vtag << IXGBE_ADVTXD_VLAN_SHIFT);
3005 } else if (offload == FALSE)
3009 * Determine where frame payload starts.
3010 * Jump over vlan headers if already present,
3011 * helpful for QinQ too.
3013 eh = mtod(mp, struct ether_vlan_header *);
3014 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
3015 etype = ntohs(eh->evl_proto);
3016 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
3018 etype = ntohs(eh->evl_encap_proto);
3019 ehdrlen = ETHER_HDR_LEN;
3022 /* Set the ether header length */
3023 vlan_macip_lens |= ehdrlen << IXGBE_ADVTXD_MACLEN_SHIFT;
3027 ip = (struct ip *)(mp->m_data + ehdrlen);
3028 ip_hlen = ip->ip_hl << 2;
3030 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3032 case ETHERTYPE_IPV6:
3033 ip6 = (struct ip6_hdr *)(mp->m_data + ehdrlen);
3034 ip_hlen = sizeof(struct ip6_hdr);
3035 ipproto = ip6->ip6_nxt;
3036 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV6;
3043 vlan_macip_lens |= ip_hlen;
3044 type_tucmd_mlhl |= IXGBE_ADVTXD_DCMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
3048 if (mp->m_pkthdr.csum_flags & CSUM_TCP)
3049 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3053 if (mp->m_pkthdr.csum_flags & CSUM_UDP)
3054 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_UDP;
3057 #if __FreeBSD_version >= 800000
3059 if (mp->m_pkthdr.csum_flags & CSUM_SCTP)
3060 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
3068 /* Now copy bits into descriptor */
3069 TXD->vlan_macip_lens |= htole32(vlan_macip_lens);
3070 TXD->type_tucmd_mlhl |= htole32(type_tucmd_mlhl);
3071 TXD->seqnum_seed = htole32(0);
3072 TXD->mss_l4len_idx = htole32(0);
3074 tx_buffer->m_head = NULL;
3075 tx_buffer->eop_index = -1;
3077 /* We've consumed the first desc, adjust counters */
3078 if (++ctxd == adapter->num_tx_desc)
3080 txr->next_avail_desc = ctxd;
3086 /**********************************************************************
3088 * Setup work for hardware segmentation offload (TSO) on
3089 * adapters using advanced tx descriptors
3091 **********************************************************************/
3093 ixgbe_tso_setup(struct tx_ring *txr, struct mbuf *mp, u32 *paylen)
3095 struct adapter *adapter = txr->adapter;
3096 struct ixgbe_adv_tx_context_desc *TXD;
3097 struct ixgbe_tx_buf *tx_buffer;
3098 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
3099 u32 mss_l4len_idx = 0;
3101 int ctxd, ehdrlen, hdrlen, ip_hlen, tcp_hlen;
3102 struct ether_vlan_header *eh;
3108 * Determine where frame payload starts.
3109 * Jump over vlan headers if already present
3111 eh = mtod(mp, struct ether_vlan_header *);
3112 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN))
3113 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
3115 ehdrlen = ETHER_HDR_LEN;
3117 /* Ensure we have at least the IP+TCP header in the first mbuf. */
3118 if (mp->m_len < ehdrlen + sizeof(struct ip) + sizeof(struct tcphdr))
3121 ctxd = txr->next_avail_desc;
3122 tx_buffer = &txr->tx_buffers[ctxd];
3123 TXD = (struct ixgbe_adv_tx_context_desc *) &txr->tx_base[ctxd];
3125 ip = (struct ip *)(mp->m_data + ehdrlen);
3126 if (ip->ip_p != IPPROTO_TCP)
3127 return FALSE; /* 0 */
3129 ip_hlen = ip->ip_hl << 2;
3130 th = (struct tcphdr *)((caddr_t)ip + ip_hlen);
3131 th->th_sum = in_pseudo(ip->ip_src.s_addr,
3132 ip->ip_dst.s_addr, htons(IPPROTO_TCP));
3133 tcp_hlen = th->th_off << 2;
3134 hdrlen = ehdrlen + ip_hlen + tcp_hlen;
3136 /* This is used in the transmit desc in encap */
3137 *paylen = mp->m_pkthdr.len - hdrlen;
3139 /* VLAN MACLEN IPLEN */
3140 if (mp->m_flags & M_VLANTAG) {
3141 vtag = htole16(mp->m_pkthdr.ether_vtag);
3142 vlan_macip_lens |= (vtag << IXGBE_ADVTXD_VLAN_SHIFT);
3145 vlan_macip_lens |= ehdrlen << IXGBE_ADVTXD_MACLEN_SHIFT;
3146 vlan_macip_lens |= ip_hlen;
3147 TXD->vlan_macip_lens |= htole32(vlan_macip_lens);
3149 /* ADV DTYPE TUCMD */
3150 type_tucmd_mlhl |= IXGBE_ADVTXD_DCMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
3151 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3152 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3153 TXD->type_tucmd_mlhl |= htole32(type_tucmd_mlhl);
3157 mss_l4len_idx |= (mp->m_pkthdr.tso_segsz << IXGBE_ADVTXD_MSS_SHIFT);
3158 mss_l4len_idx |= (tcp_hlen << IXGBE_ADVTXD_L4LEN_SHIFT);
3159 TXD->mss_l4len_idx = htole32(mss_l4len_idx);
3161 TXD->seqnum_seed = htole32(0);
3162 tx_buffer->m_head = NULL;
3163 tx_buffer->eop_index = -1;
3165 if (++ctxd == adapter->num_tx_desc)
3169 txr->next_avail_desc = ctxd;
3175 ** This routine parses packet headers so that Flow
3176 ** Director can make a hashed filter table entry
3177 ** allowing traffic flows to be identified and kept
3178 ** on the same cpu. This would be a performance
3179 ** hit, but we only do it at IXGBE_FDIR_RATE of
3183 ixgbe_atr(struct tx_ring *txr, struct mbuf *mp)
3185 struct adapter *adapter = txr->adapter;
3186 struct ix_queue *que;
3190 struct ether_vlan_header *eh;
3191 union ixgbe_atr_hash_dword input = {.dword = 0};
3192 union ixgbe_atr_hash_dword common = {.dword = 0};
3193 int ehdrlen, ip_hlen;
3196 eh = mtod(mp, struct ether_vlan_header *);
3197 if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
3198 ehdrlen = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
3199 etype = eh->evl_proto;
3201 ehdrlen = ETHER_HDR_LEN;
3202 etype = eh->evl_encap_proto;
3205 /* Only handling IPv4 */
3206 if (etype != htons(ETHERTYPE_IP))
3209 ip = (struct ip *)(mp->m_data + ehdrlen);
3210 ip_hlen = ip->ip_hl << 2;
3212 /* check if we're UDP or TCP */
3215 th = (struct tcphdr *)((caddr_t)ip + ip_hlen);
3216 /* src and dst are inverted */
3217 common.port.dst ^= th->th_sport;
3218 common.port.src ^= th->th_dport;
3219 input.formatted.flow_type ^= IXGBE_ATR_FLOW_TYPE_TCPV4;
3222 uh = (struct udphdr *)((caddr_t)ip + ip_hlen);
3223 /* src and dst are inverted */
3224 common.port.dst ^= uh->uh_sport;
3225 common.port.src ^= uh->uh_dport;
3226 input.formatted.flow_type ^= IXGBE_ATR_FLOW_TYPE_UDPV4;
3232 input.formatted.vlan_id = htobe16(mp->m_pkthdr.ether_vtag);
3233 if (mp->m_pkthdr.ether_vtag)
3234 common.flex_bytes ^= htons(ETHERTYPE_VLAN);
3236 common.flex_bytes ^= etype;
3237 common.ip ^= ip->ip_src.s_addr ^ ip->ip_dst.s_addr;
3239 que = &adapter->queues[txr->me];
3241 ** This assumes the Rx queue and Tx
3242 ** queue are bound to the same CPU
3244 ixgbe_fdir_add_signature_filter_82599(&adapter->hw,
3245 input, common, que->msix);
3247 #endif /* IXGBE_FDIR */
3249 /**********************************************************************
3251 * Examine each tx_buffer in the used queue. If the hardware is done
3252 * processing the packet then free associated resources. The
3253 * tx_buffer is put back on the free queue.
3255 **********************************************************************/
3257 ixgbe_txeof(struct tx_ring *txr)
3259 struct adapter *adapter = txr->adapter;
3260 struct ifnet *ifp = adapter->ifp;
3261 u32 first, last, done, processed;
3262 struct ixgbe_tx_buf *tx_buffer;
3263 struct ixgbe_legacy_tx_desc *tx_desc, *eop_desc;
3265 mtx_assert(&txr->tx_mtx, MA_OWNED);
3267 if (txr->tx_avail == adapter->num_tx_desc) {
3268 txr->queue_status = IXGBE_QUEUE_IDLE;
3273 first = txr->next_to_clean;
3274 tx_buffer = &txr->tx_buffers[first];
3275 /* For cleanup we just use legacy struct */
3276 tx_desc = (struct ixgbe_legacy_tx_desc *)&txr->tx_base[first];
3277 last = tx_buffer->eop_index;
3280 eop_desc = (struct ixgbe_legacy_tx_desc *)&txr->tx_base[last];
3283 ** Get the index of the first descriptor
3284 ** BEYOND the EOP and call that 'done'.
3285 ** I do this so the comparison in the
3286 ** inner while loop below can be simple
3288 if (++last == adapter->num_tx_desc) last = 0;
3291 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
3292 BUS_DMASYNC_POSTREAD);
3294 ** Only the EOP descriptor of a packet now has the DD
3295 ** bit set, this is what we look for...
3297 while (eop_desc->upper.fields.status & IXGBE_TXD_STAT_DD) {
3298 /* We clean the range of the packet */
3299 while (first != done) {
3300 tx_desc->upper.data = 0;
3301 tx_desc->lower.data = 0;
3302 tx_desc->buffer_addr = 0;
3306 if (tx_buffer->m_head) {
3308 tx_buffer->m_head->m_pkthdr.len;
3309 bus_dmamap_sync(txr->txtag,
3311 BUS_DMASYNC_POSTWRITE);
3312 bus_dmamap_unload(txr->txtag,
3314 m_freem(tx_buffer->m_head);
3315 tx_buffer->m_head = NULL;
3316 tx_buffer->map = NULL;
3318 tx_buffer->eop_index = -1;
3319 txr->watchdog_time = ticks;
3321 if (++first == adapter->num_tx_desc)
3324 tx_buffer = &txr->tx_buffers[first];
3326 (struct ixgbe_legacy_tx_desc *)&txr->tx_base[first];
3330 /* See if there is more work now */
3331 last = tx_buffer->eop_index;
3334 (struct ixgbe_legacy_tx_desc *)&txr->tx_base[last];
3335 /* Get next done point */
3336 if (++last == adapter->num_tx_desc) last = 0;
3341 bus_dmamap_sync(txr->txdma.dma_tag, txr->txdma.dma_map,
3342 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
3344 txr->next_to_clean = first;
3347 ** Watchdog calculation, we know there's
3348 ** work outstanding or the first return
3349 ** would have been taken, so none processed
3350 ** for too long indicates a hang.
3352 if ((!processed) && ((ticks - txr->watchdog_time) > IXGBE_WATCHDOG))
3353 txr->queue_status = IXGBE_QUEUE_HUNG;
3356 * If we have enough room, clear IFF_DRV_OACTIVE to tell the stack that
3357 * it is OK to send packets. If there are no pending descriptors,
3358 * clear the timeout. Otherwise, if some descriptors have been freed,
3359 * restart the timeout.
3361 if (txr->tx_avail > IXGBE_TX_CLEANUP_THRESHOLD) {
3362 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
3363 if (txr->tx_avail == adapter->num_tx_desc) {
3364 txr->queue_status = IXGBE_QUEUE_IDLE;
3372 /*********************************************************************
3374 * Refresh mbuf buffers for RX descriptor rings
3375 * - now keeps its own state so discards due to resource
3376 * exhaustion are unnecessary, if an mbuf cannot be obtained
3377 * it just returns, keeping its placeholder, thus it can simply
3378 * be recalled to try again.
3380 **********************************************************************/
3382 ixgbe_refresh_mbufs(struct rx_ring *rxr, int limit)
3384 struct adapter *adapter = rxr->adapter;
3385 bus_dma_segment_t hseg[1];
3386 bus_dma_segment_t pseg[1];
3387 struct ixgbe_rx_buf *rxbuf;
3388 struct mbuf *mh, *mp;
3389 int i, nsegs, error, cleaned;
3391 i = rxr->next_to_refresh;
3392 cleaned = -1; /* Signify no completions */
3393 while (i != limit) {
3394 rxbuf = &rxr->rx_buffers[i];
3395 if (rxr->hdr_split == FALSE)
3398 if (rxbuf->m_head == NULL) {
3399 mh = m_gethdr(M_DONTWAIT, MT_DATA);
3405 mh->m_pkthdr.len = mh->m_len = MHLEN;
3407 mh->m_flags |= M_PKTHDR;
3408 /* Get the memory mapping */
3409 error = bus_dmamap_load_mbuf_sg(rxr->htag,
3410 rxbuf->hmap, mh, hseg, &nsegs, BUS_DMA_NOWAIT);
3412 printf("Refresh mbufs: hdr dmamap load"
3413 " failure - %d\n", error);
3415 rxbuf->m_head = NULL;
3419 bus_dmamap_sync(rxr->htag, rxbuf->hmap,
3420 BUS_DMASYNC_PREREAD);
3421 rxr->rx_base[i].read.hdr_addr = htole64(hseg[0].ds_addr);
3424 if (rxbuf->m_pack == NULL) {
3425 mp = m_getjcl(M_DONTWAIT, MT_DATA,
3426 M_PKTHDR, adapter->rx_mbuf_sz);
3432 mp->m_pkthdr.len = mp->m_len = adapter->rx_mbuf_sz;
3433 /* Get the memory mapping */
3434 error = bus_dmamap_load_mbuf_sg(rxr->ptag,
3435 rxbuf->pmap, mp, pseg, &nsegs, BUS_DMA_NOWAIT);
3437 printf("Refresh mbufs: payload dmamap load"
3438 " failure - %d\n", error);
3440 rxbuf->m_pack = NULL;
3444 bus_dmamap_sync(rxr->ptag, rxbuf->pmap,
3445 BUS_DMASYNC_PREREAD);
3446 rxr->rx_base[i].read.pkt_addr =
3447 htole64(pseg[0].ds_addr);
3450 /* Calculate next index */
3451 if (++i == adapter->num_rx_desc)
3453 /* This is the work marker for refresh */
3454 rxr->next_to_refresh = i;
3457 if (cleaned != -1) /* If we refreshed some, bump tail */
3458 IXGBE_WRITE_REG(&adapter->hw,
3459 IXGBE_RDT(rxr->me), cleaned);
3463 /*********************************************************************
3465 * Allocate memory for rx_buffer structures. Since we use one
3466 * rx_buffer per received packet, the maximum number of rx_buffer's
3467 * that we'll need is equal to the number of receive descriptors
3468 * that we've allocated.
3470 **********************************************************************/
3472 ixgbe_allocate_receive_buffers(struct rx_ring *rxr)
3474 struct adapter *adapter = rxr->adapter;
3475 device_t dev = adapter->dev;
3476 struct ixgbe_rx_buf *rxbuf;
3477 int i, bsize, error;
3479 bsize = sizeof(struct ixgbe_rx_buf) * adapter->num_rx_desc;
3480 if (!(rxr->rx_buffers =
3481 (struct ixgbe_rx_buf *) malloc(bsize,
3482 M_DEVBUF, M_NOWAIT | M_ZERO))) {
3483 device_printf(dev, "Unable to allocate rx_buffer memory\n");
3488 if ((error = bus_dma_tag_create(bus_get_dma_tag(dev), /* parent */
3489 1, 0, /* alignment, bounds */
3490 BUS_SPACE_MAXADDR, /* lowaddr */
3491 BUS_SPACE_MAXADDR, /* highaddr */
3492 NULL, NULL, /* filter, filterarg */
3493 MSIZE, /* maxsize */
3495 MSIZE, /* maxsegsize */
3497 NULL, /* lockfunc */
3498 NULL, /* lockfuncarg */
3500 device_printf(dev, "Unable to create RX DMA tag\n");
3504 if ((error = bus_dma_tag_create(bus_get_dma_tag(dev), /* parent */
3505 1, 0, /* alignment, bounds */
3506 BUS_SPACE_MAXADDR, /* lowaddr */
3507 BUS_SPACE_MAXADDR, /* highaddr */
3508 NULL, NULL, /* filter, filterarg */
3509 MJUM16BYTES, /* maxsize */
3511 MJUM16BYTES, /* maxsegsize */
3513 NULL, /* lockfunc */
3514 NULL, /* lockfuncarg */
3516 device_printf(dev, "Unable to create RX DMA tag\n");
3520 for (i = 0; i < adapter->num_rx_desc; i++, rxbuf++) {
3521 rxbuf = &rxr->rx_buffers[i];
3522 error = bus_dmamap_create(rxr->htag,
3523 BUS_DMA_NOWAIT, &rxbuf->hmap);
3525 device_printf(dev, "Unable to create RX head map\n");
3528 error = bus_dmamap_create(rxr->ptag,
3529 BUS_DMA_NOWAIT, &rxbuf->pmap);
3531 device_printf(dev, "Unable to create RX pkt map\n");
3539 /* Frees all, but can handle partial completion */
3540 ixgbe_free_receive_structures(adapter);
3545 ** Used to detect a descriptor that has
3546 ** been merged by Hardware RSC.
3549 ixgbe_rsc_count(union ixgbe_adv_rx_desc *rx)
3551 return (le32toh(rx->wb.lower.lo_dword.data) &
3552 IXGBE_RXDADV_RSCCNT_MASK) >> IXGBE_RXDADV_RSCCNT_SHIFT;
3555 /*********************************************************************
3557 * Initialize Hardware RSC (LRO) feature on 82599
3558 * for an RX ring, this is toggled by the LRO capability
3559 * even though it is transparent to the stack.
3561 **********************************************************************/
3563 ixgbe_setup_hw_rsc(struct rx_ring *rxr)
3565 struct adapter *adapter = rxr->adapter;
3566 struct ixgbe_hw *hw = &adapter->hw;
3567 u32 rscctrl, rdrxctl;
3569 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3570 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3571 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3572 rdrxctl |= IXGBE_RDRXCTL_RSCACKC;
3573 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3575 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(rxr->me));
3576 rscctrl |= IXGBE_RSCCTL_RSCEN;
3578 ** Limit the total number of descriptors that
3579 ** can be combined, so it does not exceed 64K
3581 if (adapter->rx_mbuf_sz == MCLBYTES)
3582 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
3583 else if (adapter->rx_mbuf_sz == MJUMPAGESIZE)
3584 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
3585 else if (adapter->rx_mbuf_sz == MJUM9BYTES)
3586 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
3587 else /* Using 16K cluster */
3588 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
3590 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(rxr->me), rscctrl);
3592 /* Enable TCP header recognition */
3593 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0),
3594 (IXGBE_READ_REG(hw, IXGBE_PSRTYPE(0)) |
3595 IXGBE_PSRTYPE_TCPHDR));
3597 /* Disable RSC for ACK packets */
3598 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3599 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3606 ixgbe_free_receive_ring(struct rx_ring *rxr)
3608 struct adapter *adapter;
3609 struct ixgbe_rx_buf *rxbuf;
3612 adapter = rxr->adapter;
3613 for (i = 0; i < adapter->num_rx_desc; i++) {
3614 rxbuf = &rxr->rx_buffers[i];
3615 if (rxbuf->m_head != NULL) {
3616 bus_dmamap_sync(rxr->htag, rxbuf->hmap,
3617 BUS_DMASYNC_POSTREAD);
3618 bus_dmamap_unload(rxr->htag, rxbuf->hmap);
3619 rxbuf->m_head->m_flags |= M_PKTHDR;
3620 m_freem(rxbuf->m_head);
3622 if (rxbuf->m_pack != NULL) {
3623 bus_dmamap_sync(rxr->ptag, rxbuf->pmap,
3624 BUS_DMASYNC_POSTREAD);
3625 bus_dmamap_unload(rxr->ptag, rxbuf->pmap);
3626 rxbuf->m_pack->m_flags |= M_PKTHDR;
3627 m_freem(rxbuf->m_pack);
3629 rxbuf->m_head = NULL;
3630 rxbuf->m_pack = NULL;
3635 /*********************************************************************
3637 * Initialize a receive ring and its buffers.
3639 **********************************************************************/
3641 ixgbe_setup_receive_ring(struct rx_ring *rxr)
3643 struct adapter *adapter;
3646 struct ixgbe_rx_buf *rxbuf;
3647 bus_dma_segment_t pseg[1], hseg[1];
3648 struct lro_ctrl *lro = &rxr->lro;
3649 int rsize, nsegs, error = 0;
3651 adapter = rxr->adapter;
3655 /* Clear the ring contents */
3657 rsize = roundup2(adapter->num_rx_desc *
3658 sizeof(union ixgbe_adv_rx_desc), DBA_ALIGN);
3659 bzero((void *)rxr->rx_base, rsize);
3661 /* Free current RX buffer structs and their mbufs */
3662 ixgbe_free_receive_ring(rxr);
3664 /* Configure header split? */
3665 if (ixgbe_header_split)
3666 rxr->hdr_split = TRUE;
3668 /* Now replenish the mbufs */
3669 for (int j = 0; j != adapter->num_rx_desc; ++j) {
3670 struct mbuf *mh, *mp;
3672 rxbuf = &rxr->rx_buffers[j];
3674 ** Don't allocate mbufs if not
3675 ** doing header split, its wasteful
3677 if (rxr->hdr_split == FALSE)
3680 /* First the header */
3681 rxbuf->m_head = m_gethdr(M_NOWAIT, MT_DATA);
3682 if (rxbuf->m_head == NULL) {
3686 m_adj(rxbuf->m_head, ETHER_ALIGN);
3688 mh->m_len = mh->m_pkthdr.len = MHLEN;
3689 mh->m_flags |= M_PKTHDR;
3690 /* Get the memory mapping */
3691 error = bus_dmamap_load_mbuf_sg(rxr->htag,
3692 rxbuf->hmap, rxbuf->m_head, hseg,
3693 &nsegs, BUS_DMA_NOWAIT);
3694 if (error != 0) /* Nothing elegant to do here */
3696 bus_dmamap_sync(rxr->htag,
3697 rxbuf->hmap, BUS_DMASYNC_PREREAD);
3698 /* Update descriptor */
3699 rxr->rx_base[j].read.hdr_addr = htole64(hseg[0].ds_addr);
3702 /* Now the payload cluster */
3703 rxbuf->m_pack = m_getjcl(M_NOWAIT, MT_DATA,
3704 M_PKTHDR, adapter->rx_mbuf_sz);
3705 if (rxbuf->m_pack == NULL) {
3710 mp->m_pkthdr.len = mp->m_len = adapter->rx_mbuf_sz;
3711 /* Get the memory mapping */
3712 error = bus_dmamap_load_mbuf_sg(rxr->ptag,
3713 rxbuf->pmap, mp, pseg,
3714 &nsegs, BUS_DMA_NOWAIT);
3717 bus_dmamap_sync(rxr->ptag,
3718 rxbuf->pmap, BUS_DMASYNC_PREREAD);
3719 /* Update descriptor */
3720 rxr->rx_base[j].read.pkt_addr = htole64(pseg[0].ds_addr);
3724 /* Setup our descriptor indices */
3725 rxr->next_to_check = 0;
3726 rxr->next_to_refresh = 0;
3727 rxr->lro_enabled = FALSE;
3728 rxr->rx_split_packets = 0;
3731 bus_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
3732 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
3735 ** Now set up the LRO interface:
3736 ** 82598 uses software LRO, the
3737 ** 82599 uses a hardware assist.
3739 if ((adapter->hw.mac.type == ixgbe_mac_82599EB) &&
3740 (ifp->if_capenable & IFCAP_RXCSUM) &&
3741 (ifp->if_capenable & IFCAP_LRO))
3742 ixgbe_setup_hw_rsc(rxr);
3743 else if (ifp->if_capenable & IFCAP_LRO) {
3744 int err = tcp_lro_init(lro);
3746 device_printf(dev, "LRO Initialization failed!\n");
3749 INIT_DEBUGOUT("RX Soft LRO Initialized\n");
3750 rxr->lro_enabled = TRUE;
3751 lro->ifp = adapter->ifp;
3754 IXGBE_RX_UNLOCK(rxr);
3758 ixgbe_free_receive_ring(rxr);
3759 IXGBE_RX_UNLOCK(rxr);
3763 /*********************************************************************
3765 * Initialize all receive rings.
3767 **********************************************************************/
3769 ixgbe_setup_receive_structures(struct adapter *adapter)
3771 struct rx_ring *rxr = adapter->rx_rings;
3774 for (j = 0; j < adapter->num_queues; j++, rxr++)
3775 if (ixgbe_setup_receive_ring(rxr))
3781 * Free RX buffers allocated so far, we will only handle
3782 * the rings that completed, the failing case will have
3783 * cleaned up for itself. 'j' failed, so its the terminus.
3785 for (int i = 0; i < j; ++i) {
3786 rxr = &adapter->rx_rings[i];
3787 ixgbe_free_receive_ring(rxr);
3793 /*********************************************************************
3795 * Setup receive registers and features.
3797 **********************************************************************/
3798 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
3801 ixgbe_initialize_receive_units(struct adapter *adapter)
3803 struct rx_ring *rxr = adapter->rx_rings;
3804 struct ixgbe_hw *hw = &adapter->hw;
3805 struct ifnet *ifp = adapter->ifp;
3806 u32 bufsz, rxctrl, fctrl, srrctl, rxcsum;
3807 u32 reta, mrqc = 0, hlreg, random[10];
3811 * Make sure receives are disabled while
3812 * setting up the descriptor ring
3814 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3815 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL,
3816 rxctrl & ~IXGBE_RXCTRL_RXEN);
3818 /* Enable broadcasts */
3819 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3820 fctrl |= IXGBE_FCTRL_BAM;
3821 fctrl |= IXGBE_FCTRL_DPF;
3822 fctrl |= IXGBE_FCTRL_PMCF;
3823 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3825 /* Set for Jumbo Frames? */
3826 hlreg = IXGBE_READ_REG(hw, IXGBE_HLREG0);
3827 if (ifp->if_mtu > ETHERMTU)
3828 hlreg |= IXGBE_HLREG0_JUMBOEN;
3830 hlreg &= ~IXGBE_HLREG0_JUMBOEN;
3831 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg);
3833 bufsz = adapter->rx_mbuf_sz >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
3835 for (int i = 0; i < adapter->num_queues; i++, rxr++) {
3836 u64 rdba = rxr->rxdma.dma_paddr;
3838 /* Setup the Base and Length of the Rx Descriptor Ring */
3839 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(i),
3840 (rdba & 0x00000000ffffffffULL));
3841 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(i), (rdba >> 32));
3842 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(i),
3843 adapter->num_rx_desc * sizeof(union ixgbe_adv_rx_desc));
3845 /* Set up the SRRCTL register */
3846 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
3847 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
3848 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
3850 if (rxr->hdr_split) {
3851 /* Use a standard mbuf for the header */
3852 srrctl |= ((IXGBE_RX_HDR <<
3853 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT)
3854 & IXGBE_SRRCTL_BSIZEHDR_MASK);
3855 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
3857 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
3858 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(i), srrctl);
3860 /* Setup the HW Rx Head and Tail Descriptor Pointers */
3861 IXGBE_WRITE_REG(hw, IXGBE_RDH(i), 0);
3862 IXGBE_WRITE_REG(hw, IXGBE_RDT(i), 0);
3865 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
3866 /* PSRTYPE must be initialized in 82599 */
3867 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
3868 IXGBE_PSRTYPE_UDPHDR |
3869 IXGBE_PSRTYPE_IPV4HDR |
3870 IXGBE_PSRTYPE_IPV6HDR;
3871 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
3874 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3877 if (adapter->num_queues > 1) {
3881 /* set up random bits */
3882 arc4rand(&random, sizeof(random), 0);
3884 /* Set up the redirection table */
3885 for (i = 0, j = 0; i < 128; i++, j++) {
3886 if (j == adapter->num_queues) j = 0;
3887 reta = (reta << 8) | (j * 0x11);
3889 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3892 /* Now fill our hash function seeds */
3893 for (int i = 0; i < 10; i++)
3894 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), random[i]);
3896 /* Perform hash on these packet types */
3897 mrqc = IXGBE_MRQC_RSSEN
3898 | IXGBE_MRQC_RSS_FIELD_IPV4
3899 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
3900 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
3901 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP
3902 | IXGBE_MRQC_RSS_FIELD_IPV6_EX
3903 | IXGBE_MRQC_RSS_FIELD_IPV6
3904 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
3905 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP
3906 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP;
3907 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3909 /* RSS and RX IPP Checksum are mutually exclusive */
3910 rxcsum |= IXGBE_RXCSUM_PCSD;
3913 if (ifp->if_capenable & IFCAP_RXCSUM)
3914 rxcsum |= IXGBE_RXCSUM_PCSD;
3916 if (!(rxcsum & IXGBE_RXCSUM_PCSD))
3917 rxcsum |= IXGBE_RXCSUM_IPPCSE;
3919 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3924 /*********************************************************************
3926 * Free all receive rings.
3928 **********************************************************************/
3930 ixgbe_free_receive_structures(struct adapter *adapter)
3932 struct rx_ring *rxr = adapter->rx_rings;
3934 for (int i = 0; i < adapter->num_queues; i++, rxr++) {
3935 struct lro_ctrl *lro = &rxr->lro;
3936 ixgbe_free_receive_buffers(rxr);
3937 /* Free LRO memory */
3939 /* Free the ring memory as well */
3940 ixgbe_dma_free(adapter, &rxr->rxdma);
3943 free(adapter->rx_rings, M_DEVBUF);
3947 /*********************************************************************
3949 * Free receive ring data structures
3951 **********************************************************************/
3953 ixgbe_free_receive_buffers(struct rx_ring *rxr)
3955 struct adapter *adapter = rxr->adapter;
3956 struct ixgbe_rx_buf *rxbuf;
3958 INIT_DEBUGOUT("free_receive_structures: begin");
3960 /* Cleanup any existing buffers */
3961 if (rxr->rx_buffers != NULL) {
3962 for (int i = 0; i < adapter->num_rx_desc; i++) {
3963 rxbuf = &rxr->rx_buffers[i];
3964 if (rxbuf->m_head != NULL) {
3965 bus_dmamap_sync(rxr->htag, rxbuf->hmap,
3966 BUS_DMASYNC_POSTREAD);
3967 bus_dmamap_unload(rxr->htag, rxbuf->hmap);
3968 rxbuf->m_head->m_flags |= M_PKTHDR;
3969 m_freem(rxbuf->m_head);
3971 if (rxbuf->m_pack != NULL) {
3972 bus_dmamap_sync(rxr->ptag, rxbuf->pmap,
3973 BUS_DMASYNC_POSTREAD);
3974 bus_dmamap_unload(rxr->ptag, rxbuf->pmap);
3975 rxbuf->m_pack->m_flags |= M_PKTHDR;
3976 m_freem(rxbuf->m_pack);
3978 rxbuf->m_head = NULL;
3979 rxbuf->m_pack = NULL;
3980 if (rxbuf->hmap != NULL) {
3981 bus_dmamap_destroy(rxr->htag, rxbuf->hmap);
3984 if (rxbuf->pmap != NULL) {
3985 bus_dmamap_destroy(rxr->ptag, rxbuf->pmap);
3989 if (rxr->rx_buffers != NULL) {
3990 free(rxr->rx_buffers, M_DEVBUF);
3991 rxr->rx_buffers = NULL;
3995 if (rxr->htag != NULL) {
3996 bus_dma_tag_destroy(rxr->htag);
3999 if (rxr->ptag != NULL) {
4000 bus_dma_tag_destroy(rxr->ptag);
4007 static __inline void
4008 ixgbe_rx_input(struct rx_ring *rxr, struct ifnet *ifp, struct mbuf *m, u32 ptype)
4012 * ATM LRO is only for IPv4/TCP packets and TCP checksum of the packet
4013 * should be computed by hardware. Also it should not have VLAN tag in
4016 if (rxr->lro_enabled &&
4017 (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) != 0 &&
4018 (ptype & IXGBE_RXDADV_PKTTYPE_ETQF) == 0 &&
4019 (ptype & (IXGBE_RXDADV_PKTTYPE_IPV4 | IXGBE_RXDADV_PKTTYPE_TCP)) ==
4020 (IXGBE_RXDADV_PKTTYPE_IPV4 | IXGBE_RXDADV_PKTTYPE_TCP) &&
4021 (m->m_pkthdr.csum_flags & (CSUM_DATA_VALID | CSUM_PSEUDO_HDR)) ==
4022 (CSUM_DATA_VALID | CSUM_PSEUDO_HDR)) {
4024 * Send to the stack if:
4025 ** - LRO not enabled, or
4026 ** - no LRO resources, or
4027 ** - lro enqueue fails
4029 if (rxr->lro.lro_cnt != 0)
4030 if (tcp_lro_rx(&rxr->lro, m, 0) == 0)
4033 IXGBE_RX_UNLOCK(rxr);
4034 (*ifp->if_input)(ifp, m);
4038 static __inline void
4039 ixgbe_rx_discard(struct rx_ring *rxr, int i)
4041 struct ixgbe_rx_buf *rbuf;
4043 rbuf = &rxr->rx_buffers[i];
4045 if (rbuf->fmp != NULL) {/* Partial chain ? */
4046 rbuf->fmp->m_flags |= M_PKTHDR;
4052 ** With advanced descriptors the writeback
4053 ** clobbers the buffer addrs, so its easier
4054 ** to just free the existing mbufs and take
4055 ** the normal refresh path to get new buffers
4059 m_free(rbuf->m_head);
4060 rbuf->m_head = NULL;
4064 m_free(rbuf->m_pack);
4065 rbuf->m_pack = NULL;
4072 /*********************************************************************
4074 * This routine executes in interrupt context. It replenishes
4075 * the mbufs in the descriptor and sends data which has been
4076 * dma'ed into host memory to upper layer.
4078 * We loop at most count times if count is > 0, or until done if
4081 * Return TRUE for more work, FALSE for all clean.
4082 *********************************************************************/
4084 ixgbe_rxeof(struct ix_queue *que, int count)
4086 struct adapter *adapter = que->adapter;
4087 struct rx_ring *rxr = que->rxr;
4088 struct ifnet *ifp = adapter->ifp;
4089 struct lro_ctrl *lro = &rxr->lro;
4090 struct lro_entry *queued;
4091 int i, nextp, processed = 0;
4093 union ixgbe_adv_rx_desc *cur;
4094 struct ixgbe_rx_buf *rbuf, *nbuf;
4098 for (i = rxr->next_to_check; count != 0;) {
4099 struct mbuf *sendmp, *mh, *mp;
4101 u16 hlen, plen, hdr, vtag;
4104 /* Sync the ring. */
4105 bus_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
4106 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
4108 cur = &rxr->rx_base[i];
4109 staterr = le32toh(cur->wb.upper.status_error);
4111 if ((staterr & IXGBE_RXD_STAT_DD) == 0)
4113 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
4120 cur->wb.upper.status_error = 0;
4121 rbuf = &rxr->rx_buffers[i];
4125 plen = le16toh(cur->wb.upper.length);
4126 ptype = le32toh(cur->wb.lower.lo_dword.data) &
4127 IXGBE_RXDADV_PKTTYPE_MASK;
4128 hdr = le16toh(cur->wb.lower.lo_dword.hs_rss.hdr_info);
4129 vtag = le16toh(cur->wb.upper.vlan);
4130 eop = ((staterr & IXGBE_RXD_STAT_EOP) != 0);
4132 /* Make sure bad packets are discarded */
4133 if (((staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) != 0) ||
4136 rxr->rx_discarded++;
4138 rxr->discard = FALSE;
4140 rxr->discard = TRUE;
4141 ixgbe_rx_discard(rxr, i);
4146 ** On 82599 which supports a hardware
4147 ** LRO (called HW RSC), packets need
4148 ** not be fragmented across sequential
4149 ** descriptors, rather the next descriptor
4150 ** is indicated in bits of the descriptor.
4151 ** This also means that we might proceses
4152 ** more than one packet at a time, something
4153 ** that has never been true before, it
4154 ** required eliminating global chain pointers
4155 ** in favor of what we are doing here. -jfv
4159 ** Figure out the next descriptor
4162 if (rxr->hw_rsc == TRUE) {
4163 rsc = ixgbe_rsc_count(cur);
4164 rxr->rsc_num += (rsc - 1);
4166 if (rsc) { /* Get hardware index */
4168 IXGBE_RXDADV_NEXTP_MASK) >>
4169 IXGBE_RXDADV_NEXTP_SHIFT);
4170 } else { /* Just sequential */
4172 if (nextp == adapter->num_rx_desc)
4175 nbuf = &rxr->rx_buffers[nextp];
4179 ** The header mbuf is ONLY used when header
4180 ** split is enabled, otherwise we get normal
4181 ** behavior, ie, both header and payload
4182 ** are DMA'd into the payload buffer.
4184 ** Rather than using the fmp/lmp global pointers
4185 ** we now keep the head of a packet chain in the
4186 ** buffer struct and pass this along from one
4187 ** descriptor to the next, until we get EOP.
4189 if (rxr->hdr_split && (rbuf->fmp == NULL)) {
4190 /* This must be an initial descriptor */
4191 hlen = (hdr & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
4192 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
4193 if (hlen > IXGBE_RX_HDR)
4194 hlen = IXGBE_RX_HDR;
4196 mh->m_flags |= M_PKTHDR;
4198 mh->m_pkthdr.len = mh->m_len;
4199 /* Null buf pointer so it is refreshed */
4200 rbuf->m_head = NULL;
4202 ** Check the payload length, this
4203 ** could be zero if its a small
4209 mp->m_flags &= ~M_PKTHDR;
4211 mh->m_pkthdr.len += mp->m_len;
4212 /* Null buf pointer so it is refreshed */
4213 rbuf->m_pack = NULL;
4214 rxr->rx_split_packets++;
4217 ** Now create the forward
4218 ** chain so when complete
4222 /* stash the chain head */
4224 /* Make forward chain */
4226 mp->m_next = nbuf->m_pack;
4228 mh->m_next = nbuf->m_pack;
4230 /* Singlet, prepare to send */
4232 if ((adapter->num_vlans) &&
4233 (staterr & IXGBE_RXD_STAT_VP)) {
4234 sendmp->m_pkthdr.ether_vtag = vtag;
4235 sendmp->m_flags |= M_VLANTAG;
4240 ** Either no header split, or a
4241 ** secondary piece of a fragmented
4246 ** See if there is a stored head
4247 ** that determines what we are
4250 rbuf->m_pack = rbuf->fmp = NULL;
4252 if (sendmp != NULL) /* secondary frag */
4253 sendmp->m_pkthdr.len += mp->m_len;
4255 /* first desc of a non-ps chain */
4257 sendmp->m_flags |= M_PKTHDR;
4258 sendmp->m_pkthdr.len = mp->m_len;
4259 if (staterr & IXGBE_RXD_STAT_VP) {
4260 sendmp->m_pkthdr.ether_vtag = vtag;
4261 sendmp->m_flags |= M_VLANTAG;
4264 /* Pass the head pointer on */
4268 mp->m_next = nbuf->m_pack;
4272 /* Sending this frame? */
4274 sendmp->m_pkthdr.rcvif = ifp;
4277 /* capture data for AIM */
4278 rxr->bytes += sendmp->m_pkthdr.len;
4279 rxr->rx_bytes += sendmp->m_pkthdr.len;
4280 if ((ifp->if_capenable & IFCAP_RXCSUM) != 0)
4281 ixgbe_rx_checksum(staterr, sendmp, ptype);
4282 #if __FreeBSD_version >= 800000
4283 sendmp->m_pkthdr.flowid = que->msix;
4284 sendmp->m_flags |= M_FLOWID;
4288 bus_dmamap_sync(rxr->rxdma.dma_tag, rxr->rxdma.dma_map,
4289 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
4291 /* Advance our pointers to the next descriptor. */
4292 if (++i == adapter->num_rx_desc)
4295 /* Now send to the stack or do LRO */
4296 if (sendmp != NULL) {
4297 rxr->next_to_check = i;
4298 ixgbe_rx_input(rxr, ifp, sendmp, ptype);
4299 i = rxr->next_to_check;
4302 /* Every 8 descriptors we go to refresh mbufs */
4303 if (processed == 8) {
4304 ixgbe_refresh_mbufs(rxr, i);
4309 /* Refresh any remaining buf structs */
4310 if (processed != 0) {
4311 ixgbe_refresh_mbufs(rxr, i);
4315 rxr->next_to_check = i;
4318 * Flush any outstanding LRO work
4320 while ((queued = SLIST_FIRST(&lro->lro_active)) != NULL) {
4321 SLIST_REMOVE_HEAD(&lro->lro_active, next);
4322 tcp_lro_flush(lro, queued);
4325 IXGBE_RX_UNLOCK(rxr);
4328 ** We still have cleaning to do?
4329 ** Schedule another interrupt if so.
4331 if ((staterr & IXGBE_RXD_STAT_DD) != 0) {
4332 ixgbe_rearm_queues(adapter, (u64)(1 << que->msix));
4340 /*********************************************************************
4342 * Verify that the hardware indicated that the checksum is valid.
4343 * Inform the stack about the status of checksum so that stack
4344 * doesn't spend time verifying the checksum.
4346 *********************************************************************/
4348 ixgbe_rx_checksum(u32 staterr, struct mbuf * mp, u32 ptype)
4350 u16 status = (u16) staterr;
4351 u8 errors = (u8) (staterr >> 24);
4354 if ((ptype & IXGBE_RXDADV_PKTTYPE_ETQF) == 0 &&
4355 (ptype & IXGBE_RXDADV_PKTTYPE_SCTP) != 0)
4358 if (status & IXGBE_RXD_STAT_IPCS) {
4359 if (!(errors & IXGBE_RXD_ERR_IPE)) {
4360 /* IP Checksum Good */
4361 mp->m_pkthdr.csum_flags = CSUM_IP_CHECKED;
4362 mp->m_pkthdr.csum_flags |= CSUM_IP_VALID;
4365 mp->m_pkthdr.csum_flags = 0;
4367 if (status & IXGBE_RXD_STAT_L4CS) {
4368 u16 type = (CSUM_DATA_VALID | CSUM_PSEUDO_HDR);
4369 #if __FreeBSD_version >= 800000
4371 type = CSUM_SCTP_VALID;
4373 if (!(errors & IXGBE_RXD_ERR_TCPE)) {
4374 mp->m_pkthdr.csum_flags |= type;
4376 mp->m_pkthdr.csum_data = htons(0xffff);
4384 ** This routine is run via an vlan config EVENT,
4385 ** it enables us to use the HW Filter table since
4386 ** we can get the vlan id. This just creates the
4387 ** entry in the soft version of the VFTA, init will
4388 ** repopulate the real table.
4391 ixgbe_register_vlan(void *arg, struct ifnet *ifp, u16 vtag)
4393 struct adapter *adapter = ifp->if_softc;
4396 if (ifp->if_softc != arg) /* Not our event */
4399 if ((vtag == 0) || (vtag > 4095)) /* Invalid */
4402 IXGBE_CORE_LOCK(adapter);
4403 index = (vtag >> 5) & 0x7F;
4405 adapter->shadow_vfta[index] |= (1 << bit);
4406 ++adapter->num_vlans;
4407 ixgbe_init_locked(adapter);
4408 IXGBE_CORE_UNLOCK(adapter);
4412 ** This routine is run via an vlan
4413 ** unconfig EVENT, remove our entry
4414 ** in the soft vfta.
4417 ixgbe_unregister_vlan(void *arg, struct ifnet *ifp, u16 vtag)
4419 struct adapter *adapter = ifp->if_softc;
4422 if (ifp->if_softc != arg)
4425 if ((vtag == 0) || (vtag > 4095)) /* Invalid */
4428 IXGBE_CORE_LOCK(adapter);
4429 index = (vtag >> 5) & 0x7F;
4431 adapter->shadow_vfta[index] &= ~(1 << bit);
4432 --adapter->num_vlans;
4433 /* Re-init to load the changes */
4434 ixgbe_init_locked(adapter);
4435 IXGBE_CORE_UNLOCK(adapter);
4439 ixgbe_setup_vlan_hw_support(struct adapter *adapter)
4441 struct ifnet *ifp = adapter->ifp;
4442 struct ixgbe_hw *hw = &adapter->hw;
4447 ** We get here thru init_locked, meaning
4448 ** a soft reset, this has already cleared
4449 ** the VFTA and other state, so if there
4450 ** have been no vlan's registered do nothing.
4452 if (adapter->num_vlans == 0)
4456 ** A soft reset zero's out the VFTA, so
4457 ** we need to repopulate it now.
4459 for (int i = 0; i < IXGBE_VFTA_SIZE; i++)
4460 if (adapter->shadow_vfta[i] != 0)
4461 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i),
4462 adapter->shadow_vfta[i]);
4464 ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4465 /* Enable the Filter Table if enabled */
4466 if (ifp->if_capenable & IFCAP_VLAN_HWFILTER) {
4467 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
4468 ctrl |= IXGBE_VLNCTRL_VFE;
4470 if (hw->mac.type == ixgbe_mac_82598EB)
4471 ctrl |= IXGBE_VLNCTRL_VME;
4472 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
4474 /* On 82599 the VLAN enable is per/queue in RXDCTL */
4475 if (hw->mac.type == ixgbe_mac_82599EB)
4476 for (int i = 0; i < adapter->num_queues; i++) {
4477 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
4478 ctrl |= IXGBE_RXDCTL_VME;
4479 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), ctrl);
4484 ixgbe_enable_intr(struct adapter *adapter)
4486 struct ixgbe_hw *hw = &adapter->hw;
4487 struct ix_queue *que = adapter->queues;
4488 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
4491 /* Enable Fan Failure detection */
4492 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4493 mask |= IXGBE_EIMS_GPI_SDP1;
4495 /* 82599 specific interrupts */
4496 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
4497 mask |= IXGBE_EIMS_ECC;
4498 mask |= IXGBE_EIMS_GPI_SDP1;
4499 mask |= IXGBE_EIMS_GPI_SDP2;
4501 mask |= IXGBE_EIMS_FLOW_DIR;
4505 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
4507 /* With RSS we use auto clear */
4508 if (adapter->msix_mem) {
4509 mask = IXGBE_EIMS_ENABLE_MASK;
4510 /* Don't autoclear Link */
4511 mask &= ~IXGBE_EIMS_OTHER;
4512 mask &= ~IXGBE_EIMS_LSC;
4513 IXGBE_WRITE_REG(hw, IXGBE_EIAC, mask);
4517 ** Now enable all queues, this is done separately to
4518 ** allow for handling the extended (beyond 32) MSIX
4519 ** vectors that can be used by 82599
4521 for (int i = 0; i < adapter->num_queues; i++, que++)
4522 ixgbe_enable_queue(adapter, que->msix);
4524 IXGBE_WRITE_FLUSH(hw);
4530 ixgbe_disable_intr(struct adapter *adapter)
4532 if (adapter->msix_mem)
4533 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, 0);
4534 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
4535 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
4537 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
4538 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
4539 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
4541 IXGBE_WRITE_FLUSH(&adapter->hw);
4546 ixgbe_read_pci_cfg(struct ixgbe_hw *hw, u32 reg)
4550 value = pci_read_config(((struct ixgbe_osdep *)hw->back)->dev,
4557 ixgbe_write_pci_cfg(struct ixgbe_hw *hw, u32 reg, u16 value)
4559 pci_write_config(((struct ixgbe_osdep *)hw->back)->dev,
4566 ** Setup the correct IVAR register for a particular MSIX interrupt
4567 ** (yes this is all very magic and confusing :)
4568 ** - entry is the register array entry
4569 ** - vector is the MSIX vector for this queue
4570 ** - type is RX/TX/MISC
4573 ixgbe_set_ivar(struct adapter *adapter, u8 entry, u8 vector, s8 type)
4575 struct ixgbe_hw *hw = &adapter->hw;
4578 vector |= IXGBE_IVAR_ALLOC_VAL;
4580 switch (hw->mac.type) {
4582 case ixgbe_mac_82598EB:
4584 entry = IXGBE_IVAR_OTHER_CAUSES_INDEX;
4586 entry += (type * 64);
4587 index = (entry >> 2) & 0x1F;
4588 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
4589 ivar &= ~(0xFF << (8 * (entry & 0x3)));
4590 ivar |= (vector << (8 * (entry & 0x3)));
4591 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR(index), ivar);
4594 case ixgbe_mac_82599EB:
4595 if (type == -1) { /* MISC IVAR */
4596 index = (entry & 1) * 8;
4597 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR_MISC);
4598 ivar &= ~(0xFF << index);
4599 ivar |= (vector << index);
4600 IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, ivar);
4601 } else { /* RX/TX IVARS */
4602 index = (16 * (entry & 1)) + (8 * type);
4603 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(entry >> 1));
4604 ivar &= ~(0xFF << index);
4605 ivar |= (vector << index);
4606 IXGBE_WRITE_REG(hw, IXGBE_IVAR(entry >> 1), ivar);
4615 ixgbe_configure_ivars(struct adapter *adapter)
4617 struct ix_queue *que = adapter->queues;
4620 if (ixgbe_max_interrupt_rate > 0)
4621 newitr = (8000000 / ixgbe_max_interrupt_rate) & 0x0FF8;
4625 for (int i = 0; i < adapter->num_queues; i++, que++) {
4626 /* First the RX queue entry */
4627 ixgbe_set_ivar(adapter, i, que->msix, 0);
4628 /* ... and the TX */
4629 ixgbe_set_ivar(adapter, i, que->msix, 1);
4630 /* Set an Initial EITR value */
4631 IXGBE_WRITE_REG(&adapter->hw,
4632 IXGBE_EITR(que->msix), newitr);
4635 /* For the Link interrupt */
4636 ixgbe_set_ivar(adapter, 1, adapter->linkvec, -1);
4640 ** ixgbe_sfp_probe - called in the local timer to
4641 ** determine if a port had optics inserted.
4643 static bool ixgbe_sfp_probe(struct adapter *adapter)
4645 struct ixgbe_hw *hw = &adapter->hw;
4646 device_t dev = adapter->dev;
4647 bool result = FALSE;
4649 if ((hw->phy.type == ixgbe_phy_nl) &&
4650 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
4651 s32 ret = hw->phy.ops.identify_sfp(hw);
4654 ret = hw->phy.ops.reset(hw);
4655 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4656 device_printf(dev,"Unsupported SFP+ module detected!");
4657 printf(" Reload driver with supported module.\n");
4658 adapter->sfp_probe = FALSE;
4661 device_printf(dev,"SFP+ module detected!\n");
4662 /* We now have supported optics */
4663 adapter->sfp_probe = FALSE;
4664 /* Set the optics type so system reports correctly */
4665 ixgbe_setup_optics(adapter);
4673 ** Tasklet handler for MSIX Link interrupts
4674 ** - do outside interrupt since it might sleep
4677 ixgbe_handle_link(void *context, int pending)
4679 struct adapter *adapter = context;
4681 ixgbe_check_link(&adapter->hw,
4682 &adapter->link_speed, &adapter->link_up, 0);
4683 ixgbe_update_link_status(adapter);
4687 ** Tasklet for handling SFP module interrupts
4690 ixgbe_handle_mod(void *context, int pending)
4692 struct adapter *adapter = context;
4693 struct ixgbe_hw *hw = &adapter->hw;
4694 device_t dev = adapter->dev;
4697 err = hw->phy.ops.identify_sfp(hw);
4698 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4700 "Unsupported SFP+ module type was detected.\n");
4703 err = hw->mac.ops.setup_sfp(hw);
4704 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4706 "Setup failure - unsupported SFP+ module type.\n");
4709 taskqueue_enqueue(adapter->tq, &adapter->msf_task);
4715 ** Tasklet for handling MSF (multispeed fiber) interrupts
4718 ixgbe_handle_msf(void *context, int pending)
4720 struct adapter *adapter = context;
4721 struct ixgbe_hw *hw = &adapter->hw;
4725 autoneg = hw->phy.autoneg_advertised;
4726 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
4727 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiate);
4728 if (hw->mac.ops.setup_link)
4729 hw->mac.ops.setup_link(hw, autoneg, negotiate, TRUE);
4735 ** Tasklet for reinitializing the Flow Director filter table
4738 ixgbe_reinit_fdir(void *context, int pending)
4740 struct adapter *adapter = context;
4741 struct ifnet *ifp = adapter->ifp;
4743 if (adapter->fdir_reinit != 1) /* Shouldn't happen */
4745 ixgbe_reinit_fdir_tables_82599(&adapter->hw);
4746 adapter->fdir_reinit = 0;
4747 /* Restart the interface */
4748 ifp->if_drv_flags |= IFF_DRV_RUNNING;
4753 /**********************************************************************
4755 * Update the board statistics counters.
4757 **********************************************************************/
4759 ixgbe_update_stats_counters(struct adapter *adapter)
4761 struct ifnet *ifp = adapter->ifp;
4762 struct ixgbe_hw *hw = &adapter->hw;
4763 u32 missed_rx = 0, bprc, lxon, lxoff, total;
4764 u64 total_missed_rx = 0;
4766 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
4767 adapter->stats.illerrc += IXGBE_READ_REG(hw, IXGBE_ILLERRC);
4768 adapter->stats.errbc += IXGBE_READ_REG(hw, IXGBE_ERRBC);
4769 adapter->stats.mspdc += IXGBE_READ_REG(hw, IXGBE_MSPDC);
4771 for (int i = 0; i < 8; i++) {
4773 mp = IXGBE_READ_REG(hw, IXGBE_MPC(i));
4774 /* missed_rx tallies misses for the gprc workaround */
4776 /* global total per queue */
4777 adapter->stats.mpc[i] += mp;
4778 /* Running comprehensive total for stats display */
4779 total_missed_rx += adapter->stats.mpc[i];
4780 if (hw->mac.type == ixgbe_mac_82598EB)
4781 adapter->stats.rnbc[i] +=
4782 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
4783 adapter->stats.pxontxc[i] +=
4784 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
4785 adapter->stats.pxonrxc[i] +=
4786 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
4787 adapter->stats.pxofftxc[i] +=
4788 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
4789 adapter->stats.pxoffrxc[i] +=
4790 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
4791 adapter->stats.pxon2offc[i] +=
4792 IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
4794 for (int i = 0; i < 16; i++) {
4795 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
4796 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
4797 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
4798 adapter->stats.qbrc[i] +=
4799 ((u64)IXGBE_READ_REG(hw, IXGBE_QBRC(i)) << 32);
4800 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
4801 adapter->stats.qbtc[i] +=
4802 ((u64)IXGBE_READ_REG(hw, IXGBE_QBTC(i)) << 32);
4803 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
4805 adapter->stats.mlfc += IXGBE_READ_REG(hw, IXGBE_MLFC);
4806 adapter->stats.mrfc += IXGBE_READ_REG(hw, IXGBE_MRFC);
4807 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
4809 /* Hardware workaround, gprc counts missed packets */
4810 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
4811 adapter->stats.gprc -= missed_rx;
4813 if (hw->mac.type == ixgbe_mac_82599EB) {
4814 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL) +
4815 ((u64)IXGBE_READ_REG(hw, IXGBE_GORCH) << 32);
4816 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL) +
4817 ((u64)IXGBE_READ_REG(hw, IXGBE_GOTCH) << 32);
4818 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL) +
4819 ((u64)IXGBE_READ_REG(hw, IXGBE_TORH) << 32);
4820 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
4821 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
4823 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
4824 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
4825 /* 82598 only has a counter in the high register */
4826 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
4827 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
4828 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
4832 * Workaround: mprc hardware is incorrectly counting
4833 * broadcasts, so for now we subtract those.
4835 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
4836 adapter->stats.bprc += bprc;
4837 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
4838 if (hw->mac.type == ixgbe_mac_82598EB)
4839 adapter->stats.mprc -= bprc;
4841 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
4842 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
4843 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
4844 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
4845 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
4846 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
4848 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
4849 adapter->stats.lxontxc += lxon;
4850 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
4851 adapter->stats.lxofftxc += lxoff;
4852 total = lxon + lxoff;
4854 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
4855 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
4856 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
4857 adapter->stats.gptc -= total;
4858 adapter->stats.mptc -= total;
4859 adapter->stats.ptc64 -= total;
4860 adapter->stats.gotc -= total * ETHER_MIN_LEN;
4862 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4863 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
4864 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
4865 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
4866 adapter->stats.mngprc += IXGBE_READ_REG(hw, IXGBE_MNGPRC);
4867 adapter->stats.mngpdc += IXGBE_READ_REG(hw, IXGBE_MNGPDC);
4868 adapter->stats.mngptc += IXGBE_READ_REG(hw, IXGBE_MNGPTC);
4869 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
4870 adapter->stats.tpt += IXGBE_READ_REG(hw, IXGBE_TPT);
4871 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
4872 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
4873 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
4874 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
4875 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
4876 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
4877 adapter->stats.xec += IXGBE_READ_REG(hw, IXGBE_XEC);
4878 adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
4879 adapter->stats.fclast += IXGBE_READ_REG(hw, IXGBE_FCLAST);
4880 /* Only read FCOE on 82599 */
4881 if (hw->mac.type == ixgbe_mac_82599EB) {
4882 adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
4883 adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
4884 adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
4885 adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
4886 adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
4889 /* Fill out the OS statistics structure */
4890 ifp->if_ipackets = adapter->stats.gprc;
4891 ifp->if_opackets = adapter->stats.gptc;
4892 ifp->if_ibytes = adapter->stats.gorc;
4893 ifp->if_obytes = adapter->stats.gotc;
4894 ifp->if_imcasts = adapter->stats.mprc;
4895 ifp->if_collisions = 0;
4898 ifp->if_ierrors = total_missed_rx + adapter->stats.crcerrs +
4899 adapter->stats.rlec;
4902 /** ixgbe_sysctl_tdh_handler - Handler function
4903 * Retrieves the TDH value from the hardware
4906 ixgbe_sysctl_tdh_handler(SYSCTL_HANDLER_ARGS)
4910 struct tx_ring *txr = ((struct tx_ring *)oidp->oid_arg1);
4913 unsigned val = IXGBE_READ_REG(&txr->adapter->hw, IXGBE_TDH(txr->me));
4914 error = sysctl_handle_int(oidp, &val, 0, req);
4915 if (error || !req->newptr)
4920 /** ixgbe_sysctl_tdt_handler - Handler function
4921 * Retrieves the TDT value from the hardware
4924 ixgbe_sysctl_tdt_handler(SYSCTL_HANDLER_ARGS)
4928 struct tx_ring *txr = ((struct tx_ring *)oidp->oid_arg1);
4931 unsigned val = IXGBE_READ_REG(&txr->adapter->hw, IXGBE_TDT(txr->me));
4932 error = sysctl_handle_int(oidp, &val, 0, req);
4933 if (error || !req->newptr)
4938 /** ixgbe_sysctl_rdh_handler - Handler function
4939 * Retrieves the RDH value from the hardware
4942 ixgbe_sysctl_rdh_handler(SYSCTL_HANDLER_ARGS)
4946 struct rx_ring *rxr = ((struct rx_ring *)oidp->oid_arg1);
4949 unsigned val = IXGBE_READ_REG(&rxr->adapter->hw, IXGBE_RDH(rxr->me));
4950 error = sysctl_handle_int(oidp, &val, 0, req);
4951 if (error || !req->newptr)
4956 /** ixgbe_sysctl_rdt_handler - Handler function
4957 * Retrieves the RDT value from the hardware
4960 ixgbe_sysctl_rdt_handler(SYSCTL_HANDLER_ARGS)
4964 struct rx_ring *rxr = ((struct rx_ring *)oidp->oid_arg1);
4967 unsigned val = IXGBE_READ_REG(&rxr->adapter->hw, IXGBE_RDT(rxr->me));
4968 error = sysctl_handle_int(oidp, &val, 0, req);
4969 if (error || !req->newptr)
4975 ixgbe_sysctl_interrupt_rate_handler(SYSCTL_HANDLER_ARGS)
4978 struct ix_queue *que = ((struct ix_queue *)oidp->oid_arg1);
4979 unsigned int reg, usec, rate;
4981 reg = IXGBE_READ_REG(&que->adapter->hw, IXGBE_EITR(que->msix));
4982 usec = ((reg & 0x0FF8) >> 3);
4984 rate = 1000000 / usec;
4987 error = sysctl_handle_int(oidp, &rate, 0, req);
4988 if (error || !req->newptr)
4994 * Add sysctl variables, one per statistic, to the system.
4997 ixgbe_add_hw_stats(struct adapter *adapter)
5000 device_t dev = adapter->dev;
5002 struct tx_ring *txr = adapter->tx_rings;
5003 struct rx_ring *rxr = adapter->rx_rings;
5005 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(dev);
5006 struct sysctl_oid *tree = device_get_sysctl_tree(dev);
5007 struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
5008 struct ixgbe_hw_stats *stats = &adapter->stats;
5010 struct sysctl_oid *stat_node, *queue_node;
5011 struct sysctl_oid_list *stat_list, *queue_list;
5013 #define QUEUE_NAME_LEN 32
5014 char namebuf[QUEUE_NAME_LEN];
5016 /* Driver Statistics */
5017 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "dropped",
5018 CTLFLAG_RD, &adapter->dropped_pkts,
5019 "Driver dropped packets");
5020 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "mbuf_defrag_failed",
5021 CTLFLAG_RD, &adapter->mbuf_defrag_failed,
5022 "m_defrag() failed");
5023 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "no_tx_dma_setup",
5024 CTLFLAG_RD, &adapter->no_tx_dma_setup,
5025 "Driver tx dma failure in xmit");
5026 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "watchdog_events",
5027 CTLFLAG_RD, &adapter->watchdog_events,
5028 "Watchdog timeouts");
5029 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "tso_tx",
5030 CTLFLAG_RD, &adapter->tso_tx,
5032 SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "link_irq",
5033 CTLFLAG_RD, &adapter->link_irq,
5034 "Link MSIX IRQ Handled");
5036 for (int i = 0; i < adapter->num_queues; i++, txr++) {
5037 snprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i);
5038 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf,
5039 CTLFLAG_RD, NULL, "Queue Name");
5040 queue_list = SYSCTL_CHILDREN(queue_node);
5042 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "interrupt_rate",
5043 CTLFLAG_RD, &adapter->queues[i], sizeof(&adapter->queues[i]),
5044 ixgbe_sysctl_interrupt_rate_handler, "IU",
5046 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "txd_head",
5047 CTLFLAG_RD, txr, sizeof(txr),
5048 ixgbe_sysctl_tdh_handler, "IU",
5049 "Transmit Descriptor Head");
5050 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "txd_tail",
5051 CTLFLAG_RD, txr, sizeof(txr),
5052 ixgbe_sysctl_tdt_handler, "IU",
5053 "Transmit Descriptor Tail");
5054 SYSCTL_ADD_QUAD(ctx, queue_list, OID_AUTO, "no_desc_avail",
5055 CTLFLAG_RD, &txr->no_desc_avail,
5056 "Queue No Descriptor Available");
5057 SYSCTL_ADD_QUAD(ctx, queue_list, OID_AUTO, "tx_packets",
5058 CTLFLAG_RD, &txr->total_packets,
5059 "Queue Packets Transmitted");
5062 for (int i = 0; i < adapter->num_queues; i++, rxr++) {
5063 snprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i);
5064 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf,
5065 CTLFLAG_RD, NULL, "Queue Name");
5066 queue_list = SYSCTL_CHILDREN(queue_node);
5068 struct lro_ctrl *lro = &rxr->lro;
5070 snprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i);
5071 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, namebuf,
5072 CTLFLAG_RD, NULL, "Queue Name");
5073 queue_list = SYSCTL_CHILDREN(queue_node);
5075 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "rxd_head",
5076 CTLFLAG_RD, rxr, sizeof(rxr),
5077 ixgbe_sysctl_rdh_handler, "IU",
5078 "Receive Descriptor Head");
5079 SYSCTL_ADD_PROC(ctx, queue_list, OID_AUTO, "rxd_tail",
5080 CTLFLAG_RD, rxr, sizeof(rxr),
5081 ixgbe_sysctl_rdt_handler, "IU",
5082 "Receive Descriptor Tail");
5083 SYSCTL_ADD_QUAD(ctx, queue_list, OID_AUTO, "rx_packets",
5084 CTLFLAG_RD, &rxr->rx_packets,
5085 "Queue Packets Received");
5086 SYSCTL_ADD_QUAD(ctx, queue_list, OID_AUTO, "rx_bytes",
5087 CTLFLAG_RD, &rxr->rx_bytes,
5088 "Queue Bytes Received");
5089 SYSCTL_ADD_UINT(ctx, queue_list, OID_AUTO, "lro_queued",
5090 CTLFLAG_RD, &lro->lro_queued, 0,
5092 SYSCTL_ADD_UINT(ctx, queue_list, OID_AUTO, "lro_flushed",
5093 CTLFLAG_RD, &lro->lro_flushed, 0,
5097 /* MAC stats get the own sub node */
5099 stat_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "mac_stats",
5100 CTLFLAG_RD, NULL, "MAC Statistics");
5101 stat_list = SYSCTL_CHILDREN(stat_node);
5103 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "crc_errs",
5104 CTLFLAG_RD, &stats->crcerrs,
5106 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "ill_errs",
5107 CTLFLAG_RD, &stats->illerrc,
5108 "Illegal Byte Errors");
5109 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "byte_errs",
5110 CTLFLAG_RD, &stats->errbc,
5112 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "short_discards",
5113 CTLFLAG_RD, &stats->mspdc,
5114 "MAC Short Packets Discarded");
5115 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "local_faults",
5116 CTLFLAG_RD, &stats->mlfc,
5117 "MAC Local Faults");
5118 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "remote_faults",
5119 CTLFLAG_RD, &stats->mrfc,
5120 "MAC Remote Faults");
5121 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "rec_len_errs",
5122 CTLFLAG_RD, &stats->rlec,
5123 "Receive Length Errors");
5124 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "link_xon_txd",
5125 CTLFLAG_RD, &stats->lxontxc,
5126 "Link XON Transmitted");
5127 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "link_xon_rcvd",
5128 CTLFLAG_RD, &stats->lxonrxc,
5129 "Link XON Received");
5130 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "link_xoff_txd",
5131 CTLFLAG_RD, &stats->lxofftxc,
5132 "Link XOFF Transmitted");
5133 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "link_xoff_rcvd",
5134 CTLFLAG_RD, &stats->lxoffrxc,
5135 "Link XOFF Received");
5137 /* Packet Reception Stats */
5138 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "total_octets_rcvd",
5139 CTLFLAG_RD, &stats->tor,
5140 "Total Octets Received");
5141 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "good_octets_rcvd",
5142 CTLFLAG_RD, &stats->gorc,
5143 "Good Octets Received");
5144 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "total_pkts_rcvd",
5145 CTLFLAG_RD, &stats->tpr,
5146 "Total Packets Received");
5147 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "good_pkts_rcvd",
5148 CTLFLAG_RD, &stats->gprc,
5149 "Good Packets Received");
5150 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "mcast_pkts_rcvd",
5151 CTLFLAG_RD, &stats->mprc,
5152 "Multicast Packets Received");
5153 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "bcast_pkts_rcvd",
5154 CTLFLAG_RD, &stats->bprc,
5155 "Broadcast Packets Received");
5156 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "rx_frames_64",
5157 CTLFLAG_RD, &stats->prc64,
5158 "64 byte frames received ");
5159 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "rx_frames_65_127",
5160 CTLFLAG_RD, &stats->prc127,
5161 "65-127 byte frames received");
5162 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "rx_frames_128_255",
5163 CTLFLAG_RD, &stats->prc255,
5164 "128-255 byte frames received");
5165 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "rx_frames_256_511",
5166 CTLFLAG_RD, &stats->prc511,
5167 "256-511 byte frames received");
5168 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "rx_frames_512_1023",
5169 CTLFLAG_RD, &stats->prc1023,
5170 "512-1023 byte frames received");
5171 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "rx_frames_1024_1522",
5172 CTLFLAG_RD, &stats->prc1522,
5173 "1023-1522 byte frames received");
5174 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "recv_undersized",
5175 CTLFLAG_RD, &stats->ruc,
5176 "Receive Undersized");
5177 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "recv_fragmented",
5178 CTLFLAG_RD, &stats->rfc,
5179 "Fragmented Packets Received ");
5180 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "recv_oversized",
5181 CTLFLAG_RD, &stats->roc,
5182 "Oversized Packets Received");
5183 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "recv_jabberd",
5184 CTLFLAG_RD, &stats->rjc,
5186 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "management_pkts_rcvd",
5187 CTLFLAG_RD, &stats->mngprc,
5188 "Management Packets Received");
5189 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "management_pkts_drpd",
5190 CTLFLAG_RD, &stats->mngptc,
5191 "Management Packets Dropped");
5192 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "checksum_errs",
5193 CTLFLAG_RD, &stats->xec,
5196 /* Packet Transmission Stats */
5197 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "good_octets_txd",
5198 CTLFLAG_RD, &stats->gotc,
5199 "Good Octets Transmitted");
5200 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "total_pkts_txd",
5201 CTLFLAG_RD, &stats->tpt,
5202 "Total Packets Transmitted");
5203 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "good_pkts_txd",
5204 CTLFLAG_RD, &stats->gptc,
5205 "Good Packets Transmitted");
5206 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "bcast_pkts_txd",
5207 CTLFLAG_RD, &stats->bptc,
5208 "Broadcast Packets Transmitted");
5209 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "mcast_pkts_txd",
5210 CTLFLAG_RD, &stats->mptc,
5211 "Multicast Packets Transmitted");
5212 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "management_pkts_txd",
5213 CTLFLAG_RD, &stats->mngptc,
5214 "Management Packets Transmitted");
5215 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "tx_frames_64",
5216 CTLFLAG_RD, &stats->ptc64,
5217 "64 byte frames transmitted ");
5218 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "tx_frames_65_127",
5219 CTLFLAG_RD, &stats->ptc127,
5220 "65-127 byte frames transmitted");
5221 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "tx_frames_128_255",
5222 CTLFLAG_RD, &stats->ptc255,
5223 "128-255 byte frames transmitted");
5224 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "tx_frames_256_511",
5225 CTLFLAG_RD, &stats->ptc511,
5226 "256-511 byte frames transmitted");
5227 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "tx_frames_512_1023",
5228 CTLFLAG_RD, &stats->ptc1023,
5229 "512-1023 byte frames transmitted");
5230 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "tx_frames_1024_1522",
5231 CTLFLAG_RD, &stats->ptc1522,
5232 "1024-1522 byte frames transmitted");
5235 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "fc_crc",
5236 CTLFLAG_RD, &stats->fccrc,
5238 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "fc_last",
5239 CTLFLAG_RD, &stats->fclast,
5241 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "fc_drpd",
5242 CTLFLAG_RD, &stats->fcoerpdc,
5243 "FCoE Packets Dropped");
5244 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "fc_pkts_rcvd",
5245 CTLFLAG_RD, &stats->fcoeprc,
5246 "FCoE Packets Received");
5247 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "fc_pkts_txd",
5248 CTLFLAG_RD, &stats->fcoeptc,
5249 "FCoE Packets Transmitted");
5250 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "fc_dword_rcvd",
5251 CTLFLAG_RD, &stats->fcoedwrc,
5252 "FCoE DWords Received");
5253 SYSCTL_ADD_QUAD(ctx, stat_list, OID_AUTO, "fc_dword_txd",
5254 CTLFLAG_RD, &stats->fcoedwtc,
5255 "FCoE DWords Transmitted");
5259 ** Set flow control using sysctl:
5260 ** Flow control values:
5267 ixgbe_set_flowcntl(SYSCTL_HANDLER_ARGS)
5270 int last = ixgbe_flow_control;
5271 struct adapter *adapter;
5273 error = sysctl_handle_int(oidp, &ixgbe_flow_control, 0, req);
5277 /* Don't bother if it's not changed */
5278 if (ixgbe_flow_control == last)
5281 adapter = (struct adapter *) arg1;
5282 switch (ixgbe_flow_control) {
5283 case ixgbe_fc_rx_pause:
5284 case ixgbe_fc_tx_pause:
5286 adapter->hw.fc.requested_mode = ixgbe_flow_control;
5290 adapter->hw.fc.requested_mode = ixgbe_fc_none;
5293 ixgbe_fc_enable(&adapter->hw, 0);
5298 ixgbe_add_rx_process_limit(struct adapter *adapter, const char *name,
5299 const char *description, int *limit, int value)
5302 SYSCTL_ADD_INT(device_get_sysctl_ctx(adapter->dev),
5303 SYSCTL_CHILDREN(device_get_sysctl_tree(adapter->dev)),
5304 OID_AUTO, name, CTLTYPE_INT|CTLFLAG_RW, limit, value, description);
5308 ** Control link advertise speed:
5310 ** 1 - advertise only 1G
5313 ixgbe_set_advertise(SYSCTL_HANDLER_ARGS)
5316 struct adapter *adapter;
5317 struct ixgbe_hw *hw;
5318 ixgbe_link_speed speed, last;
5320 adapter = (struct adapter *) arg1;
5322 last = hw->phy.autoneg_advertised;
5324 error = sysctl_handle_int(oidp, &adapter->advertise, 0, req);
5326 if ((error) || (adapter->advertise == -1))
5329 if (!((hw->phy.media_type == ixgbe_media_type_copper) ||
5330 (hw->phy.multispeed_fiber)))
5333 if (adapter->advertise == 1)
5334 speed = IXGBE_LINK_SPEED_1GB_FULL;
5336 speed = IXGBE_LINK_SPEED_1GB_FULL |
5337 IXGBE_LINK_SPEED_10GB_FULL;
5339 if (speed == last) /* no change */
5342 hw->mac.autotry_restart = TRUE;
5343 hw->mac.ops.setup_link(hw, speed, TRUE, TRUE);