1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2011 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
28 #include <linux/types.h>
29 #include <linux/module.h>
30 #include <linux/pci.h>
31 #include <linux/netdevice.h>
32 #include <linux/vmalloc.h>
33 #include <linux/string.h>
35 #include <linux/interrupt.h>
37 #include <linux/tcp.h>
38 #include <linux/sctp.h>
39 #include <linux/pkt_sched.h>
40 #include <linux/ipv6.h>
41 #include <linux/slab.h>
42 #include <net/checksum.h>
43 #include <net/ip6_checksum.h>
44 #include <linux/ethtool.h>
46 #include <linux/if_vlan.h>
47 #include <linux/prefetch.h>
48 #include <scsi/fc/fc_fcoe.h>
51 #include "ixgbe_common.h"
52 #include "ixgbe_dcb_82599.h"
53 #include "ixgbe_sriov.h"
55 char ixgbe_driver_name[] = "ixgbe";
56 static const char ixgbe_driver_string[] =
57 "Intel(R) 10 Gigabit PCI Express Network Driver";
61 #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
62 __stringify(BUILD) "-k"
63 const char ixgbe_driver_version[] = DRV_VERSION;
64 static const char ixgbe_copyright[] =
65 "Copyright (c) 1999-2011 Intel Corporation.";
67 static const struct ixgbe_info *ixgbe_info_tbl[] = {
68 [board_82598] = &ixgbe_82598_info,
69 [board_82599] = &ixgbe_82599_info,
70 [board_X540] = &ixgbe_X540_info,
73 /* ixgbe_pci_tbl - PCI Device ID Table
75 * Wildcard entries (PCI_ANY_ID) should come last
76 * Last entry must be all 0s
78 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
79 * Class, Class Mask, private data (not used) }
81 static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
82 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
83 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
84 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
85 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
86 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
87 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
111 /* required last entry */
114 MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
116 #ifdef CONFIG_IXGBE_DCA
117 static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
119 static struct notifier_block dca_notifier = {
120 .notifier_call = ixgbe_notify_dca,
126 #ifdef CONFIG_PCI_IOV
127 static unsigned int max_vfs;
128 module_param(max_vfs, uint, 0);
129 MODULE_PARM_DESC(max_vfs,
130 "Maximum number of virtual functions to allocate per physical function");
131 #endif /* CONFIG_PCI_IOV */
133 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
134 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
135 MODULE_LICENSE("GPL");
136 MODULE_VERSION(DRV_VERSION);
138 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
140 static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
142 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
143 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
144 schedule_work(&adapter->service_task);
147 static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
149 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
151 /* flush memory to make sure state is correct before next watchog */
152 smp_mb__before_clear_bit();
153 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
156 struct ixgbe_reg_info {
161 static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
163 /* General Registers */
164 {IXGBE_CTRL, "CTRL"},
165 {IXGBE_STATUS, "STATUS"},
166 {IXGBE_CTRL_EXT, "CTRL_EXT"},
168 /* Interrupt Registers */
169 {IXGBE_EICR, "EICR"},
172 {IXGBE_SRRCTL(0), "SRRCTL"},
173 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
174 {IXGBE_RDLEN(0), "RDLEN"},
175 {IXGBE_RDH(0), "RDH"},
176 {IXGBE_RDT(0), "RDT"},
177 {IXGBE_RXDCTL(0), "RXDCTL"},
178 {IXGBE_RDBAL(0), "RDBAL"},
179 {IXGBE_RDBAH(0), "RDBAH"},
182 {IXGBE_TDBAL(0), "TDBAL"},
183 {IXGBE_TDBAH(0), "TDBAH"},
184 {IXGBE_TDLEN(0), "TDLEN"},
185 {IXGBE_TDH(0), "TDH"},
186 {IXGBE_TDT(0), "TDT"},
187 {IXGBE_TXDCTL(0), "TXDCTL"},
189 /* List Terminator */
195 * ixgbe_regdump - register printout routine
197 static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
203 switch (reginfo->ofs) {
204 case IXGBE_SRRCTL(0):
205 for (i = 0; i < 64; i++)
206 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
208 case IXGBE_DCA_RXCTRL(0):
209 for (i = 0; i < 64; i++)
210 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
213 for (i = 0; i < 64; i++)
214 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
217 for (i = 0; i < 64; i++)
218 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
221 for (i = 0; i < 64; i++)
222 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
224 case IXGBE_RXDCTL(0):
225 for (i = 0; i < 64; i++)
226 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
229 for (i = 0; i < 64; i++)
230 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
233 for (i = 0; i < 64; i++)
234 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
237 for (i = 0; i < 64; i++)
238 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
241 for (i = 0; i < 64; i++)
242 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
245 for (i = 0; i < 64; i++)
246 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
249 for (i = 0; i < 64; i++)
250 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
253 for (i = 0; i < 64; i++)
254 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
256 case IXGBE_TXDCTL(0):
257 for (i = 0; i < 64; i++)
258 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
261 pr_info("%-15s %08x\n", reginfo->name,
262 IXGBE_READ_REG(hw, reginfo->ofs));
266 for (i = 0; i < 8; i++) {
267 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
268 pr_err("%-15s", rname);
269 for (j = 0; j < 8; j++)
270 pr_cont(" %08x", regs[i*8+j]);
277 * ixgbe_dump - Print registers, tx-rings and rx-rings
279 static void ixgbe_dump(struct ixgbe_adapter *adapter)
281 struct net_device *netdev = adapter->netdev;
282 struct ixgbe_hw *hw = &adapter->hw;
283 struct ixgbe_reg_info *reginfo;
285 struct ixgbe_ring *tx_ring;
286 struct ixgbe_tx_buffer *tx_buffer_info;
287 union ixgbe_adv_tx_desc *tx_desc;
288 struct my_u0 { u64 a; u64 b; } *u0;
289 struct ixgbe_ring *rx_ring;
290 union ixgbe_adv_rx_desc *rx_desc;
291 struct ixgbe_rx_buffer *rx_buffer_info;
295 if (!netif_msg_hw(adapter))
298 /* Print netdevice Info */
300 dev_info(&adapter->pdev->dev, "Net device Info\n");
301 pr_info("Device Name state "
302 "trans_start last_rx\n");
303 pr_info("%-15s %016lX %016lX %016lX\n",
310 /* Print Registers */
311 dev_info(&adapter->pdev->dev, "Register Dump\n");
312 pr_info(" Register Name Value\n");
313 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
314 reginfo->name; reginfo++) {
315 ixgbe_regdump(hw, reginfo);
318 /* Print TX Ring Summary */
319 if (!netdev || !netif_running(netdev))
322 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
323 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
324 for (n = 0; n < adapter->num_tx_queues; n++) {
325 tx_ring = adapter->tx_ring[n];
327 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
328 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
329 n, tx_ring->next_to_use, tx_ring->next_to_clean,
330 (u64)tx_buffer_info->dma,
331 tx_buffer_info->length,
332 tx_buffer_info->next_to_watch,
333 (u64)tx_buffer_info->time_stamp);
337 if (!netif_msg_tx_done(adapter))
338 goto rx_ring_summary;
340 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
342 /* Transmit Descriptor Formats
344 * Advanced Transmit Descriptor
345 * +--------------------------------------------------------------+
346 * 0 | Buffer Address [63:0] |
347 * +--------------------------------------------------------------+
348 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
349 * +--------------------------------------------------------------+
350 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
353 for (n = 0; n < adapter->num_tx_queues; n++) {
354 tx_ring = adapter->tx_ring[n];
355 pr_info("------------------------------------\n");
356 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
357 pr_info("------------------------------------\n");
358 pr_info("T [desc] [address 63:0 ] "
359 "[PlPOIdStDDt Ln] [bi->dma ] "
360 "leng ntw timestamp bi->skb\n");
362 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
363 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
364 tx_buffer_info = &tx_ring->tx_buffer_info[i];
365 u0 = (struct my_u0 *)tx_desc;
366 pr_info("T [0x%03X] %016llX %016llX %016llX"
367 " %04X %p %016llX %p", i,
370 (u64)tx_buffer_info->dma,
371 tx_buffer_info->length,
372 tx_buffer_info->next_to_watch,
373 (u64)tx_buffer_info->time_stamp,
374 tx_buffer_info->skb);
375 if (i == tx_ring->next_to_use &&
376 i == tx_ring->next_to_clean)
378 else if (i == tx_ring->next_to_use)
380 else if (i == tx_ring->next_to_clean)
385 if (netif_msg_pktdata(adapter) &&
386 tx_buffer_info->dma != 0)
387 print_hex_dump(KERN_INFO, "",
388 DUMP_PREFIX_ADDRESS, 16, 1,
389 phys_to_virt(tx_buffer_info->dma),
390 tx_buffer_info->length, true);
394 /* Print RX Rings Summary */
396 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
397 pr_info("Queue [NTU] [NTC]\n");
398 for (n = 0; n < adapter->num_rx_queues; n++) {
399 rx_ring = adapter->rx_ring[n];
400 pr_info("%5d %5X %5X\n",
401 n, rx_ring->next_to_use, rx_ring->next_to_clean);
405 if (!netif_msg_rx_status(adapter))
408 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
410 /* Advanced Receive Descriptor (Read) Format
412 * +-----------------------------------------------------+
413 * 0 | Packet Buffer Address [63:1] |A0/NSE|
414 * +----------------------------------------------+------+
415 * 8 | Header Buffer Address [63:1] | DD |
416 * +-----------------------------------------------------+
419 * Advanced Receive Descriptor (Write-Back) Format
421 * 63 48 47 32 31 30 21 20 16 15 4 3 0
422 * +------------------------------------------------------+
423 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
424 * | Checksum Ident | | | | Type | Type |
425 * +------------------------------------------------------+
426 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
427 * +------------------------------------------------------+
428 * 63 48 47 32 31 20 19 0
430 for (n = 0; n < adapter->num_rx_queues; n++) {
431 rx_ring = adapter->rx_ring[n];
432 pr_info("------------------------------------\n");
433 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
434 pr_info("------------------------------------\n");
435 pr_info("R [desc] [ PktBuf A0] "
436 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
437 "<-- Adv Rx Read format\n");
438 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
439 "[vl er S cks ln] ---------------- [bi->skb] "
440 "<-- Adv Rx Write-Back format\n");
442 for (i = 0; i < rx_ring->count; i++) {
443 rx_buffer_info = &rx_ring->rx_buffer_info[i];
444 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
445 u0 = (struct my_u0 *)rx_desc;
446 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
447 if (staterr & IXGBE_RXD_STAT_DD) {
448 /* Descriptor Done */
449 pr_info("RWB[0x%03X] %016llX "
450 "%016llX ---------------- %p", i,
453 rx_buffer_info->skb);
455 pr_info("R [0x%03X] %016llX "
456 "%016llX %016llX %p", i,
459 (u64)rx_buffer_info->dma,
460 rx_buffer_info->skb);
462 if (netif_msg_pktdata(adapter)) {
463 print_hex_dump(KERN_INFO, "",
464 DUMP_PREFIX_ADDRESS, 16, 1,
465 phys_to_virt(rx_buffer_info->dma),
466 rx_ring->rx_buf_len, true);
468 if (rx_ring->rx_buf_len
470 print_hex_dump(KERN_INFO, "",
471 DUMP_PREFIX_ADDRESS, 16, 1,
473 rx_buffer_info->page_dma +
474 rx_buffer_info->page_offset
480 if (i == rx_ring->next_to_use)
482 else if (i == rx_ring->next_to_clean)
494 static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
498 /* Let firmware take over control of h/w */
499 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
500 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
501 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
504 static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
508 /* Let firmware know the driver has taken over */
509 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
510 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
511 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
515 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
516 * @adapter: pointer to adapter struct
517 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
518 * @queue: queue to map the corresponding interrupt to
519 * @msix_vector: the vector to map to the corresponding queue
522 static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
523 u8 queue, u8 msix_vector)
526 struct ixgbe_hw *hw = &adapter->hw;
527 switch (hw->mac.type) {
528 case ixgbe_mac_82598EB:
529 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
532 index = (((direction * 64) + queue) >> 2) & 0x1F;
533 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
534 ivar &= ~(0xFF << (8 * (queue & 0x3)));
535 ivar |= (msix_vector << (8 * (queue & 0x3)));
536 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
538 case ixgbe_mac_82599EB:
540 if (direction == -1) {
542 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
543 index = ((queue & 1) * 8);
544 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
545 ivar &= ~(0xFF << index);
546 ivar |= (msix_vector << index);
547 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
550 /* tx or rx causes */
551 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
552 index = ((16 * (queue & 1)) + (8 * direction));
553 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
554 ivar &= ~(0xFF << index);
555 ivar |= (msix_vector << index);
556 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
564 static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
569 switch (adapter->hw.mac.type) {
570 case ixgbe_mac_82598EB:
571 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
572 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
574 case ixgbe_mac_82599EB:
576 mask = (qmask & 0xFFFFFFFF);
577 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
578 mask = (qmask >> 32);
579 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
586 static inline void ixgbe_unmap_tx_resource(struct ixgbe_ring *ring,
587 struct ixgbe_tx_buffer *tx_buffer)
589 if (tx_buffer->dma) {
590 if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_MAPPED_AS_PAGE)
591 dma_unmap_page(ring->dev,
596 dma_unmap_single(ring->dev,
604 void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
605 struct ixgbe_tx_buffer *tx_buffer_info)
607 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
608 if (tx_buffer_info->skb)
609 dev_kfree_skb_any(tx_buffer_info->skb);
610 tx_buffer_info->skb = NULL;
611 /* tx_buffer_info must be completely set up in the transmit path */
614 static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
616 struct ixgbe_hw *hw = &adapter->hw;
617 struct ixgbe_hw_stats *hwstats = &adapter->stats;
622 if ((hw->fc.current_mode == ixgbe_fc_full) ||
623 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
624 switch (hw->mac.type) {
625 case ixgbe_mac_82598EB:
626 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
629 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
631 hwstats->lxoffrxc += data;
633 /* refill credits (no tx hang) if we received xoff */
637 for (i = 0; i < adapter->num_tx_queues; i++)
638 clear_bit(__IXGBE_HANG_CHECK_ARMED,
639 &adapter->tx_ring[i]->state);
641 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
644 /* update stats for each tc, only valid with PFC enabled */
645 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
646 switch (hw->mac.type) {
647 case ixgbe_mac_82598EB:
648 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
651 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
653 hwstats->pxoffrxc[i] += xoff[i];
656 /* disarm tx queues that have received xoff frames */
657 for (i = 0; i < adapter->num_tx_queues; i++) {
658 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
659 u8 tc = tx_ring->dcb_tc;
662 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
666 static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
668 return ring->tx_stats.completed;
671 static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
673 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
674 struct ixgbe_hw *hw = &adapter->hw;
676 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
677 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
680 return (head < tail) ?
681 tail - head : (tail + ring->count - head);
686 static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
688 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
689 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
690 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
693 clear_check_for_tx_hang(tx_ring);
696 * Check for a hung queue, but be thorough. This verifies
697 * that a transmit has been completed since the previous
698 * check AND there is at least one packet pending. The
699 * ARMED bit is set to indicate a potential hang. The
700 * bit is cleared if a pause frame is received to remove
701 * false hang detection due to PFC or 802.3x frames. By
702 * requiring this to fail twice we avoid races with
703 * pfc clearing the ARMED bit and conditions where we
704 * run the check_tx_hang logic with a transmit completion
705 * pending but without time to complete it yet.
707 if ((tx_done_old == tx_done) && tx_pending) {
708 /* make sure it is true for two checks in a row */
709 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
712 /* update completed stats and continue */
713 tx_ring->tx_stats.tx_done_old = tx_done;
714 /* reset the countdown */
715 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
722 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
723 * @adapter: driver private struct
725 static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
728 /* Do the reset outside of interrupt context */
729 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
730 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
731 ixgbe_service_event_schedule(adapter);
736 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
737 * @q_vector: structure containing interrupt and ring information
738 * @tx_ring: tx ring to clean
740 static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
741 struct ixgbe_ring *tx_ring)
743 struct ixgbe_adapter *adapter = q_vector->adapter;
744 struct ixgbe_tx_buffer *tx_buffer;
745 union ixgbe_adv_tx_desc *tx_desc;
746 unsigned int total_bytes = 0, total_packets = 0;
747 unsigned int budget = q_vector->tx.work_limit;
748 u16 i = tx_ring->next_to_clean;
750 tx_buffer = &tx_ring->tx_buffer_info[i];
751 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
753 for (; budget; budget--) {
754 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
756 /* if next_to_watch is not set then there is no work pending */
760 /* if DD is not set pending work has not been completed */
761 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
764 /* count the packet as being completed */
765 tx_ring->tx_stats.completed++;
767 /* clear next_to_watch to prevent false hangs */
768 tx_buffer->next_to_watch = NULL;
770 /* prevent any other reads prior to eop_desc being verified */
774 ixgbe_unmap_tx_resource(tx_ring, tx_buffer);
775 tx_desc->wb.status = 0;
776 if (likely(tx_desc == eop_desc)) {
778 dev_kfree_skb_any(tx_buffer->skb);
779 tx_buffer->skb = NULL;
781 total_bytes += tx_buffer->bytecount;
782 total_packets += tx_buffer->gso_segs;
788 if (unlikely(i == tx_ring->count)) {
791 tx_buffer = tx_ring->tx_buffer_info;
792 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
798 tx_ring->next_to_clean = i;
799 u64_stats_update_begin(&tx_ring->syncp);
800 tx_ring->stats.bytes += total_bytes;
801 tx_ring->stats.packets += total_packets;
802 u64_stats_update_end(&tx_ring->syncp);
803 q_vector->tx.total_bytes += total_bytes;
804 q_vector->tx.total_packets += total_packets;
806 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
807 /* schedule immediate reset if we believe we hung */
808 struct ixgbe_hw *hw = &adapter->hw;
809 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
810 e_err(drv, "Detected Tx Unit Hang\n"
812 " TDH, TDT <%x>, <%x>\n"
813 " next_to_use <%x>\n"
814 " next_to_clean <%x>\n"
815 "tx_buffer_info[next_to_clean]\n"
816 " time_stamp <%lx>\n"
818 tx_ring->queue_index,
819 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
820 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
821 tx_ring->next_to_use, i,
822 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
824 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
827 "tx hang %d detected on queue %d, resetting adapter\n",
828 adapter->tx_timeout_count + 1, tx_ring->queue_index);
830 /* schedule immediate reset if we believe we hung */
831 ixgbe_tx_timeout_reset(adapter);
833 /* the adapter is about to reset, no point in enabling stuff */
837 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
838 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
839 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
840 /* Make sure that anybody stopping the queue after this
841 * sees the new next_to_clean.
844 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
845 !test_bit(__IXGBE_DOWN, &adapter->state)) {
846 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
847 ++tx_ring->tx_stats.restart_queue;
854 #ifdef CONFIG_IXGBE_DCA
855 static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
856 struct ixgbe_ring *rx_ring,
859 struct ixgbe_hw *hw = &adapter->hw;
861 u8 reg_idx = rx_ring->reg_idx;
863 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
864 switch (hw->mac.type) {
865 case ixgbe_mac_82598EB:
866 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
867 rxctrl |= dca3_get_tag(rx_ring->dev, cpu);
869 case ixgbe_mac_82599EB:
871 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
872 rxctrl |= (dca3_get_tag(rx_ring->dev, cpu) <<
873 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
878 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
879 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
880 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
881 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
884 static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
885 struct ixgbe_ring *tx_ring,
888 struct ixgbe_hw *hw = &adapter->hw;
890 u8 reg_idx = tx_ring->reg_idx;
892 switch (hw->mac.type) {
893 case ixgbe_mac_82598EB:
894 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
895 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
896 txctrl |= dca3_get_tag(tx_ring->dev, cpu);
897 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
898 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
900 case ixgbe_mac_82599EB:
902 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
903 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
904 txctrl |= (dca3_get_tag(tx_ring->dev, cpu) <<
905 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
906 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
907 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
914 static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
916 struct ixgbe_adapter *adapter = q_vector->adapter;
917 struct ixgbe_ring *ring;
920 if (q_vector->cpu == cpu)
923 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
924 ixgbe_update_tx_dca(adapter, ring, cpu);
926 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
927 ixgbe_update_rx_dca(adapter, ring, cpu);
934 static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
939 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
942 /* always use CB2 mode, difference is masked in the CB driver */
943 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
945 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
946 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
950 for (i = 0; i < num_q_vectors; i++) {
951 adapter->q_vector[i]->cpu = -1;
952 ixgbe_update_dca(adapter->q_vector[i]);
956 static int __ixgbe_notify_dca(struct device *dev, void *data)
958 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
959 unsigned long event = *(unsigned long *)data;
961 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
965 case DCA_PROVIDER_ADD:
966 /* if we're already enabled, don't do it again */
967 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
969 if (dca_add_requester(dev) == 0) {
970 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
971 ixgbe_setup_dca(adapter);
974 /* Fall Through since DCA is disabled. */
975 case DCA_PROVIDER_REMOVE:
976 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
977 dca_remove_requester(dev);
978 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
979 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
986 #endif /* CONFIG_IXGBE_DCA */
988 static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
991 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
995 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
996 * @adapter: address of board private structure
997 * @rx_desc: advanced rx descriptor
999 * Returns : true if it is FCoE pkt
1001 static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1002 union ixgbe_adv_rx_desc *rx_desc)
1004 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1006 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1007 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1008 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1009 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1013 * ixgbe_receive_skb - Send a completed packet up the stack
1014 * @adapter: board private structure
1015 * @skb: packet to send up
1016 * @status: hardware indication of status of receive
1017 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1018 * @rx_desc: rx descriptor
1020 static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
1021 struct sk_buff *skb, u8 status,
1022 struct ixgbe_ring *ring,
1023 union ixgbe_adv_rx_desc *rx_desc)
1025 struct ixgbe_adapter *adapter = q_vector->adapter;
1026 struct napi_struct *napi = &q_vector->napi;
1027 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
1028 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
1030 if (is_vlan && (tag & VLAN_VID_MASK))
1031 __vlan_hwaccel_put_tag(skb, tag);
1033 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1034 napi_gro_receive(napi, skb);
1040 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1041 * @adapter: address of board private structure
1042 * @status_err: hardware indication of status of receive
1043 * @skb: skb currently being received and modified
1044 * @status_err: status error value of last descriptor in packet
1046 static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
1047 union ixgbe_adv_rx_desc *rx_desc,
1048 struct sk_buff *skb,
1051 skb->ip_summed = CHECKSUM_NONE;
1053 /* Rx csum disabled */
1054 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
1057 /* if IP and error */
1058 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
1059 (status_err & IXGBE_RXDADV_ERR_IPE)) {
1060 adapter->hw_csum_rx_error++;
1064 if (!(status_err & IXGBE_RXD_STAT_L4CS))
1067 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
1068 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1071 * 82599 errata, UDP frames with a 0 checksum can be marked as
1074 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1075 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1078 adapter->hw_csum_rx_error++;
1082 /* It must be a TCP or UDP packet with a valid checksum */
1083 skb->ip_summed = CHECKSUM_UNNECESSARY;
1086 static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
1089 * Force memory writes to complete before letting h/w
1090 * know there are new descriptors to fetch. (Only
1091 * applicable for weak-ordered memory model archs,
1095 writel(val, rx_ring->tail);
1099 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
1100 * @rx_ring: ring to place buffers on
1101 * @cleaned_count: number of buffers to replace
1103 void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
1105 union ixgbe_adv_rx_desc *rx_desc;
1106 struct ixgbe_rx_buffer *bi;
1107 struct sk_buff *skb;
1108 u16 i = rx_ring->next_to_use;
1110 /* do nothing if no valid netdev defined */
1111 if (!rx_ring->netdev)
1114 while (cleaned_count--) {
1115 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
1116 bi = &rx_ring->rx_buffer_info[i];
1120 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1121 rx_ring->rx_buf_len);
1123 rx_ring->rx_stats.alloc_rx_buff_failed++;
1126 /* initialize queue mapping */
1127 skb_record_rx_queue(skb, rx_ring->queue_index);
1132 bi->dma = dma_map_single(rx_ring->dev,
1134 rx_ring->rx_buf_len,
1136 if (dma_mapping_error(rx_ring->dev, bi->dma)) {
1137 rx_ring->rx_stats.alloc_rx_buff_failed++;
1143 if (ring_is_ps_enabled(rx_ring)) {
1145 bi->page = netdev_alloc_page(rx_ring->netdev);
1147 rx_ring->rx_stats.alloc_rx_page_failed++;
1152 if (!bi->page_dma) {
1153 /* use a half page if we're re-using */
1154 bi->page_offset ^= PAGE_SIZE / 2;
1155 bi->page_dma = dma_map_page(rx_ring->dev,
1160 if (dma_mapping_error(rx_ring->dev,
1162 rx_ring->rx_stats.alloc_rx_page_failed++;
1168 /* Refresh the desc even if buffer_addrs didn't change
1169 * because each write-back erases this info. */
1170 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
1171 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
1173 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
1174 rx_desc->read.hdr_addr = 0;
1178 if (i == rx_ring->count)
1183 if (rx_ring->next_to_use != i) {
1184 rx_ring->next_to_use = i;
1185 ixgbe_release_rx_desc(rx_ring, i);
1189 static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
1191 /* HW will not DMA in data larger than the given buffer, even if it
1192 * parses the (NFS, of course) header to be larger. In that case, it
1193 * fills the header buffer and spills the rest into the page.
1195 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1196 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1197 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1198 if (hlen > IXGBE_RX_HDR_SIZE)
1199 hlen = IXGBE_RX_HDR_SIZE;
1204 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1205 * @skb: pointer to the last skb in the rsc queue
1207 * This function changes a queue full of hw rsc buffers into a completed
1208 * packet. It uses the ->prev pointers to find the first packet and then
1209 * turns it into the frag list owner.
1211 static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
1213 unsigned int frag_list_size = 0;
1214 unsigned int skb_cnt = 1;
1217 struct sk_buff *prev = skb->prev;
1218 frag_list_size += skb->len;
1224 skb_shinfo(skb)->frag_list = skb->next;
1226 skb->len += frag_list_size;
1227 skb->data_len += frag_list_size;
1228 skb->truesize += frag_list_size;
1229 IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt;
1234 static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc)
1236 return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
1237 IXGBE_RXDADV_RSCCNT_MASK);
1240 static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
1241 struct ixgbe_ring *rx_ring,
1244 struct ixgbe_adapter *adapter = q_vector->adapter;
1245 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
1246 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
1247 struct sk_buff *skb;
1248 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1249 const int current_node = numa_node_id();
1252 #endif /* IXGBE_FCOE */
1255 u16 cleaned_count = 0;
1256 bool pkt_is_rsc = false;
1258 i = rx_ring->next_to_clean;
1259 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
1260 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1262 while (staterr & IXGBE_RXD_STAT_DD) {
1265 rmb(); /* read descriptor and rx_buffer_info after status DD */
1267 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1269 skb = rx_buffer_info->skb;
1270 rx_buffer_info->skb = NULL;
1271 prefetch(skb->data);
1273 if (ring_is_rsc_enabled(rx_ring))
1274 pkt_is_rsc = ixgbe_get_rsc_state(rx_desc);
1276 /* linear means we are building an skb from multiple pages */
1277 if (!skb_is_nonlinear(skb)) {
1280 !(staterr & IXGBE_RXD_STAT_EOP) &&
1283 * When HWRSC is enabled, delay unmapping
1284 * of the first packet. It carries the
1285 * header information, HW may still
1286 * access the header after the writeback.
1287 * Only unmap it when EOP is reached
1289 IXGBE_RSC_CB(skb)->delay_unmap = true;
1290 IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
1292 dma_unmap_single(rx_ring->dev,
1293 rx_buffer_info->dma,
1294 rx_ring->rx_buf_len,
1297 rx_buffer_info->dma = 0;
1299 if (ring_is_ps_enabled(rx_ring)) {
1300 hlen = ixgbe_get_hlen(rx_desc);
1301 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1303 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1308 /* assume packet split since header is unmapped */
1309 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1313 dma_unmap_page(rx_ring->dev,
1314 rx_buffer_info->page_dma,
1317 rx_buffer_info->page_dma = 0;
1318 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
1319 rx_buffer_info->page,
1320 rx_buffer_info->page_offset,
1323 if ((page_count(rx_buffer_info->page) == 1) &&
1324 (page_to_nid(rx_buffer_info->page) == current_node))
1325 get_page(rx_buffer_info->page);
1327 rx_buffer_info->page = NULL;
1329 skb->len += upper_len;
1330 skb->data_len += upper_len;
1331 skb->truesize += PAGE_SIZE / 2;
1335 if (i == rx_ring->count)
1338 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
1343 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
1344 IXGBE_RXDADV_NEXTP_SHIFT;
1345 next_buffer = &rx_ring->rx_buffer_info[nextp];
1347 next_buffer = &rx_ring->rx_buffer_info[i];
1350 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
1351 if (ring_is_ps_enabled(rx_ring)) {
1352 rx_buffer_info->skb = next_buffer->skb;
1353 rx_buffer_info->dma = next_buffer->dma;
1354 next_buffer->skb = skb;
1355 next_buffer->dma = 0;
1357 skb->next = next_buffer->skb;
1358 skb->next->prev = skb;
1360 rx_ring->rx_stats.non_eop_descs++;
1365 skb = ixgbe_transform_rsc_queue(skb);
1366 /* if we got here without RSC the packet is invalid */
1368 __pskb_trim(skb, 0);
1369 rx_buffer_info->skb = skb;
1374 if (ring_is_rsc_enabled(rx_ring)) {
1375 if (IXGBE_RSC_CB(skb)->delay_unmap) {
1376 dma_unmap_single(rx_ring->dev,
1377 IXGBE_RSC_CB(skb)->dma,
1378 rx_ring->rx_buf_len,
1380 IXGBE_RSC_CB(skb)->dma = 0;
1381 IXGBE_RSC_CB(skb)->delay_unmap = false;
1385 if (ring_is_ps_enabled(rx_ring))
1386 rx_ring->rx_stats.rsc_count +=
1387 skb_shinfo(skb)->nr_frags;
1389 rx_ring->rx_stats.rsc_count +=
1390 IXGBE_RSC_CB(skb)->skb_cnt;
1391 rx_ring->rx_stats.rsc_flush++;
1394 /* ERR_MASK will only have valid bits if EOP set */
1395 if (unlikely(staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)) {
1396 dev_kfree_skb_any(skb);
1400 ixgbe_rx_checksum(adapter, rx_desc, skb, staterr);
1401 if (adapter->netdev->features & NETIF_F_RXHASH)
1402 ixgbe_rx_hash(rx_desc, skb);
1404 /* probably a little skewed due to removing CRC */
1405 total_rx_bytes += skb->len;
1408 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
1410 /* if ddp, not passing to ULD unless for FCP_RSP or error */
1411 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
1412 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb,
1415 dev_kfree_skb_any(skb);
1419 #endif /* IXGBE_FCOE */
1420 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
1424 rx_desc->wb.upper.status_error = 0;
1429 /* return some buffers to hardware, one at a time is too slow */
1430 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1431 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1435 /* use prefetched values */
1437 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1440 rx_ring->next_to_clean = i;
1441 cleaned_count = ixgbe_desc_unused(rx_ring);
1444 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1447 /* include DDPed FCoE data */
1448 if (ddp_bytes > 0) {
1451 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
1452 sizeof(struct fc_frame_header) -
1453 sizeof(struct fcoe_crc_eof);
1456 total_rx_bytes += ddp_bytes;
1457 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1459 #endif /* IXGBE_FCOE */
1461 u64_stats_update_begin(&rx_ring->syncp);
1462 rx_ring->stats.packets += total_rx_packets;
1463 rx_ring->stats.bytes += total_rx_bytes;
1464 u64_stats_update_end(&rx_ring->syncp);
1465 q_vector->rx.total_packets += total_rx_packets;
1466 q_vector->rx.total_bytes += total_rx_bytes;
1472 * ixgbe_configure_msix - Configure MSI-X hardware
1473 * @adapter: board private structure
1475 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1478 static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1480 struct ixgbe_q_vector *q_vector;
1481 int q_vectors, v_idx;
1484 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1486 /* Populate MSIX to EITR Select */
1487 if (adapter->num_vfs > 32) {
1488 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1489 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1493 * Populate the IVAR table and set the ITR values to the
1494 * corresponding register.
1496 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
1497 struct ixgbe_ring *ring;
1498 q_vector = adapter->q_vector[v_idx];
1500 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
1501 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
1503 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
1504 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
1506 if (q_vector->tx.ring && !q_vector->rx.ring) {
1507 /* tx only vector */
1508 if (adapter->tx_itr_setting == 1)
1509 q_vector->itr = IXGBE_10K_ITR;
1511 q_vector->itr = adapter->tx_itr_setting;
1513 /* rx or rx/tx vector */
1514 if (adapter->rx_itr_setting == 1)
1515 q_vector->itr = IXGBE_20K_ITR;
1517 q_vector->itr = adapter->rx_itr_setting;
1520 ixgbe_write_eitr(q_vector);
1523 switch (adapter->hw.mac.type) {
1524 case ixgbe_mac_82598EB:
1525 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
1528 case ixgbe_mac_82599EB:
1529 case ixgbe_mac_X540:
1530 ixgbe_set_ivar(adapter, -1, 1, v_idx);
1535 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
1537 /* set up to autoclear timer, and the vectors */
1538 mask = IXGBE_EIMS_ENABLE_MASK;
1539 mask &= ~(IXGBE_EIMS_OTHER |
1540 IXGBE_EIMS_MAILBOX |
1543 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
1546 enum latency_range {
1550 latency_invalid = 255
1554 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1555 * @q_vector: structure containing interrupt and ring information
1556 * @ring_container: structure containing ring performance data
1558 * Stores a new ITR value based on packets and byte
1559 * counts during the last interrupt. The advantage of per interrupt
1560 * computation is faster updates and more accurate ITR for the current
1561 * traffic pattern. Constants in this function were computed
1562 * based on theoretical maximum wire speed and thresholds were set based
1563 * on testing data as well as attempting to minimize response time
1564 * while increasing bulk throughput.
1565 * this functionality is controlled by the InterruptThrottleRate module
1566 * parameter (see ixgbe_param.c)
1568 static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1569 struct ixgbe_ring_container *ring_container)
1572 struct ixgbe_adapter *adapter = q_vector->adapter;
1573 int bytes = ring_container->total_bytes;
1574 int packets = ring_container->total_packets;
1576 u8 itr_setting = ring_container->itr;
1581 /* simple throttlerate management
1582 * 0-20MB/s lowest (100000 ints/s)
1583 * 20-100MB/s low (20000 ints/s)
1584 * 100-1249MB/s bulk (8000 ints/s)
1586 /* what was last interrupt timeslice? */
1587 timepassed_us = q_vector->itr >> 2;
1588 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1590 switch (itr_setting) {
1591 case lowest_latency:
1592 if (bytes_perint > adapter->eitr_low)
1593 itr_setting = low_latency;
1596 if (bytes_perint > adapter->eitr_high)
1597 itr_setting = bulk_latency;
1598 else if (bytes_perint <= adapter->eitr_low)
1599 itr_setting = lowest_latency;
1602 if (bytes_perint <= adapter->eitr_high)
1603 itr_setting = low_latency;
1607 /* clear work counters since we have the values we need */
1608 ring_container->total_bytes = 0;
1609 ring_container->total_packets = 0;
1611 /* write updated itr to ring container */
1612 ring_container->itr = itr_setting;
1616 * ixgbe_write_eitr - write EITR register in hardware specific way
1617 * @q_vector: structure containing interrupt and ring information
1619 * This function is made to be called by ethtool and by the driver
1620 * when it needs to update EITR registers at runtime. Hardware
1621 * specific quirks/differences are taken care of here.
1623 void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
1625 struct ixgbe_adapter *adapter = q_vector->adapter;
1626 struct ixgbe_hw *hw = &adapter->hw;
1627 int v_idx = q_vector->v_idx;
1628 u32 itr_reg = q_vector->itr;
1630 switch (adapter->hw.mac.type) {
1631 case ixgbe_mac_82598EB:
1632 /* must write high and low 16 bits to reset counter */
1633 itr_reg |= (itr_reg << 16);
1635 case ixgbe_mac_82599EB:
1636 case ixgbe_mac_X540:
1638 * set the WDIS bit to not clear the timer bits and cause an
1639 * immediate assertion of the interrupt
1641 itr_reg |= IXGBE_EITR_CNT_WDIS;
1646 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1649 static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
1651 u32 new_itr = q_vector->itr;
1654 ixgbe_update_itr(q_vector, &q_vector->tx);
1655 ixgbe_update_itr(q_vector, &q_vector->rx);
1657 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
1659 switch (current_itr) {
1660 /* counts and packets in update_itr are dependent on these numbers */
1661 case lowest_latency:
1662 new_itr = IXGBE_100K_ITR;
1665 new_itr = IXGBE_20K_ITR;
1668 new_itr = IXGBE_8K_ITR;
1674 if (new_itr != q_vector->itr) {
1675 /* do an exponential smoothing */
1676 new_itr = (10 * new_itr * q_vector->itr) /
1677 ((9 * new_itr) + q_vector->itr);
1679 /* save the algorithm value here */
1680 q_vector->itr = new_itr & IXGBE_MAX_EITR;
1682 ixgbe_write_eitr(q_vector);
1687 * ixgbe_check_overtemp_subtask - check for over tempurature
1688 * @adapter: pointer to adapter
1690 static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
1692 struct ixgbe_hw *hw = &adapter->hw;
1693 u32 eicr = adapter->interrupt_event;
1695 if (test_bit(__IXGBE_DOWN, &adapter->state))
1698 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1699 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1702 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1704 switch (hw->device_id) {
1705 case IXGBE_DEV_ID_82599_T3_LOM:
1707 * Since the warning interrupt is for both ports
1708 * we don't have to check if:
1709 * - This interrupt wasn't for our port.
1710 * - We may have missed the interrupt so always have to
1711 * check if we got a LSC
1713 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1714 !(eicr & IXGBE_EICR_LSC))
1717 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1719 bool link_up = false;
1721 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1727 /* Check if this is not due to overtemp */
1728 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1733 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1738 "Network adapter has been stopped because it has over heated. "
1739 "Restart the computer. If the problem persists, "
1740 "power off the system and replace the adapter\n");
1742 adapter->interrupt_event = 0;
1745 static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1747 struct ixgbe_hw *hw = &adapter->hw;
1749 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1750 (eicr & IXGBE_EICR_GPI_SDP1)) {
1751 e_crit(probe, "Fan has stopped, replace the adapter\n");
1752 /* write to clear the interrupt */
1753 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1757 static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
1759 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
1762 switch (adapter->hw.mac.type) {
1763 case ixgbe_mac_82599EB:
1765 * Need to check link state so complete overtemp check
1768 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
1769 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
1770 adapter->interrupt_event = eicr;
1771 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1772 ixgbe_service_event_schedule(adapter);
1776 case ixgbe_mac_X540:
1777 if (!(eicr & IXGBE_EICR_TS))
1785 "Network adapter has been stopped because it has over heated. "
1786 "Restart the computer. If the problem persists, "
1787 "power off the system and replace the adapter\n");
1790 static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1792 struct ixgbe_hw *hw = &adapter->hw;
1794 if (eicr & IXGBE_EICR_GPI_SDP2) {
1795 /* Clear the interrupt */
1796 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1797 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1798 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1799 ixgbe_service_event_schedule(adapter);
1803 if (eicr & IXGBE_EICR_GPI_SDP1) {
1804 /* Clear the interrupt */
1805 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1806 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1807 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1808 ixgbe_service_event_schedule(adapter);
1813 static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1815 struct ixgbe_hw *hw = &adapter->hw;
1818 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1819 adapter->link_check_timeout = jiffies;
1820 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1821 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
1822 IXGBE_WRITE_FLUSH(hw);
1823 ixgbe_service_event_schedule(adapter);
1827 static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1831 struct ixgbe_hw *hw = &adapter->hw;
1833 switch (hw->mac.type) {
1834 case ixgbe_mac_82598EB:
1835 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1836 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1838 case ixgbe_mac_82599EB:
1839 case ixgbe_mac_X540:
1840 mask = (qmask & 0xFFFFFFFF);
1842 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
1843 mask = (qmask >> 32);
1845 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1850 /* skip the flush */
1853 static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
1857 struct ixgbe_hw *hw = &adapter->hw;
1859 switch (hw->mac.type) {
1860 case ixgbe_mac_82598EB:
1861 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1862 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1864 case ixgbe_mac_82599EB:
1865 case ixgbe_mac_X540:
1866 mask = (qmask & 0xFFFFFFFF);
1868 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
1869 mask = (qmask >> 32);
1871 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1876 /* skip the flush */
1880 * ixgbe_irq_enable - Enable default interrupt generation settings
1881 * @adapter: board private structure
1883 static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
1886 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
1888 /* don't reenable LSC while waiting for link */
1889 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
1890 mask &= ~IXGBE_EIMS_LSC;
1892 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
1893 switch (adapter->hw.mac.type) {
1894 case ixgbe_mac_82599EB:
1895 mask |= IXGBE_EIMS_GPI_SDP0;
1897 case ixgbe_mac_X540:
1898 mask |= IXGBE_EIMS_TS;
1903 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1904 mask |= IXGBE_EIMS_GPI_SDP1;
1905 switch (adapter->hw.mac.type) {
1906 case ixgbe_mac_82599EB:
1907 mask |= IXGBE_EIMS_GPI_SDP1;
1908 mask |= IXGBE_EIMS_GPI_SDP2;
1909 case ixgbe_mac_X540:
1910 mask |= IXGBE_EIMS_ECC;
1911 mask |= IXGBE_EIMS_MAILBOX;
1916 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
1917 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
1918 mask |= IXGBE_EIMS_FLOW_DIR;
1920 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1922 ixgbe_irq_enable_queues(adapter, ~0);
1924 IXGBE_WRITE_FLUSH(&adapter->hw);
1927 static irqreturn_t ixgbe_msix_other(int irq, void *data)
1929 struct ixgbe_adapter *adapter = data;
1930 struct ixgbe_hw *hw = &adapter->hw;
1934 * Workaround for Silicon errata. Use clear-by-write instead
1935 * of clear-by-read. Reading with EICS will return the
1936 * interrupt causes without clearing, which later be done
1937 * with the write to EICR.
1939 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1941 /* The lower 16bits of the EICR register are for the queue interrupts
1942 * which should be masked here in order to not accidently clear them if
1943 * the bits are high when ixgbe_msix_other is called. There is a race
1944 * condition otherwise which results in possible performance loss
1945 * especially if the ixgbe_msix_other interrupt is triggering
1946 * consistently (as it would when PPS is turned on for the X540 device)
1950 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
1952 if (eicr & IXGBE_EICR_LSC)
1953 ixgbe_check_lsc(adapter);
1955 if (eicr & IXGBE_EICR_MAILBOX)
1956 ixgbe_msg_task(adapter);
1958 switch (hw->mac.type) {
1959 case ixgbe_mac_82599EB:
1960 case ixgbe_mac_X540:
1961 if (eicr & IXGBE_EICR_ECC)
1962 e_info(link, "Received unrecoverable ECC Err, please "
1964 /* Handle Flow Director Full threshold interrupt */
1965 if (eicr & IXGBE_EICR_FLOW_DIR) {
1966 int reinit_count = 0;
1968 for (i = 0; i < adapter->num_tx_queues; i++) {
1969 struct ixgbe_ring *ring = adapter->tx_ring[i];
1970 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
1975 /* no more flow director interrupts until after init */
1976 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
1977 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
1978 ixgbe_service_event_schedule(adapter);
1981 ixgbe_check_sfp_event(adapter, eicr);
1982 ixgbe_check_overtemp_event(adapter, eicr);
1988 ixgbe_check_fan_failure(adapter, eicr);
1990 /* re-enable the original interrupt state, no lsc, no queues */
1991 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1992 ixgbe_irq_enable(adapter, false, false);
1997 static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
1999 struct ixgbe_q_vector *q_vector = data;
2001 /* EIAM disabled interrupts (on this vector) for us */
2003 if (q_vector->rx.ring || q_vector->tx.ring)
2004 napi_schedule(&q_vector->napi);
2009 static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
2012 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
2013 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
2015 rx_ring->q_vector = q_vector;
2016 rx_ring->next = q_vector->rx.ring;
2017 q_vector->rx.ring = rx_ring;
2018 q_vector->rx.count++;
2021 static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
2024 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
2025 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
2027 tx_ring->q_vector = q_vector;
2028 tx_ring->next = q_vector->tx.ring;
2029 q_vector->tx.ring = tx_ring;
2030 q_vector->tx.count++;
2031 q_vector->tx.work_limit = a->tx_work_limit;
2035 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2036 * @adapter: board private structure to initialize
2038 * This function maps descriptor rings to the queue-specific vectors
2039 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2040 * one vector per ring/queue, but on a constrained vector budget, we
2041 * group the rings as "efficiently" as possible. You would add new
2042 * mapping configurations in here.
2044 static void ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
2046 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2047 int rxr_remaining = adapter->num_rx_queues, rxr_idx = 0;
2048 int txr_remaining = adapter->num_tx_queues, txr_idx = 0;
2051 /* only one q_vector if MSI-X is disabled. */
2052 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2056 * If we don't have enough vectors for a 1-to-1 mapping, we'll have to
2057 * group them so there are multiple queues per vector.
2059 * Re-adjusting *qpv takes care of the remainder.
2061 for (; v_start < q_vectors && rxr_remaining; v_start++) {
2062 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_start);
2063 for (; rqpv; rqpv--, rxr_idx++, rxr_remaining--)
2064 map_vector_to_rxq(adapter, v_start, rxr_idx);
2068 * If there are not enough q_vectors for each ring to have it's own
2069 * vector then we must pair up Rx/Tx on a each vector
2071 if ((v_start + txr_remaining) > q_vectors)
2074 for (; v_start < q_vectors && txr_remaining; v_start++) {
2075 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_start);
2076 for (; tqpv; tqpv--, txr_idx++, txr_remaining--)
2077 map_vector_to_txq(adapter, v_start, txr_idx);
2082 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2083 * @adapter: board private structure
2085 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2086 * interrupts from the kernel.
2088 static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2090 struct net_device *netdev = adapter->netdev;
2091 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2095 for (vector = 0; vector < q_vectors; vector++) {
2096 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2097 struct msix_entry *entry = &adapter->msix_entries[vector];
2099 if (q_vector->tx.ring && q_vector->rx.ring) {
2100 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2101 "%s-%s-%d", netdev->name, "TxRx", ri++);
2103 } else if (q_vector->rx.ring) {
2104 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2105 "%s-%s-%d", netdev->name, "rx", ri++);
2106 } else if (q_vector->tx.ring) {
2107 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2108 "%s-%s-%d", netdev->name, "tx", ti++);
2110 /* skip this unused q_vector */
2113 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2114 q_vector->name, q_vector);
2116 e_err(probe, "request_irq failed for MSIX interrupt "
2117 "Error: %d\n", err);
2118 goto free_queue_irqs;
2120 /* If Flow Director is enabled, set interrupt affinity */
2121 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2122 /* assign the mask for this irq */
2123 irq_set_affinity_hint(entry->vector,
2124 q_vector->affinity_mask);
2128 err = request_irq(adapter->msix_entries[vector].vector,
2129 ixgbe_msix_other, 0, netdev->name, adapter);
2131 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
2132 goto free_queue_irqs;
2140 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2142 free_irq(adapter->msix_entries[vector].vector,
2143 adapter->q_vector[vector]);
2145 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2146 pci_disable_msix(adapter->pdev);
2147 kfree(adapter->msix_entries);
2148 adapter->msix_entries = NULL;
2153 * ixgbe_intr - legacy mode Interrupt Handler
2154 * @irq: interrupt number
2155 * @data: pointer to a network interface device structure
2157 static irqreturn_t ixgbe_intr(int irq, void *data)
2159 struct ixgbe_adapter *adapter = data;
2160 struct ixgbe_hw *hw = &adapter->hw;
2161 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
2165 * Workaround for silicon errata on 82598. Mask the interrupts
2166 * before the read of EICR.
2168 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2170 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2171 * therefore no explict interrupt disable is necessary */
2172 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
2175 * shared interrupt alert!
2176 * make sure interrupts are enabled because the read will
2177 * have disabled interrupts due to EIAM
2178 * finish the workaround of silicon errata on 82598. Unmask
2179 * the interrupt that we masked before the EICR read.
2181 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2182 ixgbe_irq_enable(adapter, true, true);
2183 return IRQ_NONE; /* Not our interrupt */
2186 if (eicr & IXGBE_EICR_LSC)
2187 ixgbe_check_lsc(adapter);
2189 switch (hw->mac.type) {
2190 case ixgbe_mac_82599EB:
2191 ixgbe_check_sfp_event(adapter, eicr);
2193 case ixgbe_mac_X540:
2194 if (eicr & IXGBE_EICR_ECC)
2195 e_info(link, "Received unrecoverable ECC err, please "
2197 ixgbe_check_overtemp_event(adapter, eicr);
2203 ixgbe_check_fan_failure(adapter, eicr);
2205 if (napi_schedule_prep(&(q_vector->napi))) {
2206 /* would disable interrupts here but EIAM disabled it */
2207 __napi_schedule(&(q_vector->napi));
2211 * re-enable link(maybe) and non-queue interrupts, no flush.
2212 * ixgbe_poll will re-enable the queue interrupts
2215 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2216 ixgbe_irq_enable(adapter, false, false);
2221 static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2223 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2226 /* legacy and MSI only use one vector */
2227 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2230 for (i = 0; i < adapter->num_rx_queues; i++) {
2231 adapter->rx_ring[i]->q_vector = NULL;
2232 adapter->rx_ring[i]->next = NULL;
2234 for (i = 0; i < adapter->num_tx_queues; i++) {
2235 adapter->tx_ring[i]->q_vector = NULL;
2236 adapter->tx_ring[i]->next = NULL;
2239 for (i = 0; i < q_vectors; i++) {
2240 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
2241 memset(&q_vector->rx, 0, sizeof(struct ixgbe_ring_container));
2242 memset(&q_vector->tx, 0, sizeof(struct ixgbe_ring_container));
2247 * ixgbe_request_irq - initialize interrupts
2248 * @adapter: board private structure
2250 * Attempts to configure interrupts using the best available
2251 * capabilities of the hardware and kernel.
2253 static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
2255 struct net_device *netdev = adapter->netdev;
2258 /* map all of the rings to the q_vectors */
2259 ixgbe_map_rings_to_vectors(adapter);
2261 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2262 err = ixgbe_request_msix_irqs(adapter);
2263 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
2264 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
2265 netdev->name, adapter);
2267 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
2268 netdev->name, adapter);
2271 e_err(probe, "request_irq failed, Error %d\n", err);
2273 /* place q_vectors and rings back into a known good state */
2274 ixgbe_reset_q_vectors(adapter);
2280 static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2282 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2285 q_vectors = adapter->num_msix_vectors;
2287 free_irq(adapter->msix_entries[i].vector, adapter);
2290 for (; i >= 0; i--) {
2291 /* free only the irqs that were actually requested */
2292 if (!adapter->q_vector[i]->rx.ring &&
2293 !adapter->q_vector[i]->tx.ring)
2296 /* clear the affinity_mask in the IRQ descriptor */
2297 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2300 free_irq(adapter->msix_entries[i].vector,
2301 adapter->q_vector[i]);
2304 free_irq(adapter->pdev->irq, adapter);
2307 /* clear q_vector state information */
2308 ixgbe_reset_q_vectors(adapter);
2312 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2313 * @adapter: board private structure
2315 static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2317 switch (adapter->hw.mac.type) {
2318 case ixgbe_mac_82598EB:
2319 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
2321 case ixgbe_mac_82599EB:
2322 case ixgbe_mac_X540:
2323 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2324 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
2325 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
2330 IXGBE_WRITE_FLUSH(&adapter->hw);
2331 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2333 for (i = 0; i < adapter->num_msix_vectors; i++)
2334 synchronize_irq(adapter->msix_entries[i].vector);
2336 synchronize_irq(adapter->pdev->irq);
2341 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2344 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2346 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
2349 if (adapter->rx_itr_setting == 1)
2350 q_vector->itr = IXGBE_20K_ITR;
2352 q_vector->itr = adapter->rx_itr_setting;
2354 ixgbe_write_eitr(q_vector);
2356 ixgbe_set_ivar(adapter, 0, 0, 0);
2357 ixgbe_set_ivar(adapter, 1, 0, 0);
2359 e_info(hw, "Legacy interrupt IVAR setup done\n");
2363 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2364 * @adapter: board private structure
2365 * @ring: structure containing ring specific data
2367 * Configure the Tx descriptor ring after a reset.
2369 void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2370 struct ixgbe_ring *ring)
2372 struct ixgbe_hw *hw = &adapter->hw;
2373 u64 tdba = ring->dma;
2375 u32 txdctl = IXGBE_TXDCTL_ENABLE;
2376 u8 reg_idx = ring->reg_idx;
2378 /* disable queue to avoid issues while updating state */
2379 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
2380 IXGBE_WRITE_FLUSH(hw);
2382 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
2383 (tdba & DMA_BIT_MASK(32)));
2384 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2385 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2386 ring->count * sizeof(union ixgbe_adv_tx_desc));
2387 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2388 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
2389 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
2392 * set WTHRESH to encourage burst writeback, it should not be set
2393 * higher than 1 when ITR is 0 as it could cause false TX hangs
2395 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2396 * to or less than the number of on chip descriptors, which is
2399 if (!adapter->tx_itr_setting || !adapter->rx_itr_setting)
2400 txdctl |= (1 << 16); /* WTHRESH = 1 */
2402 txdctl |= (8 << 16); /* WTHRESH = 8 */
2404 /* PTHRESH=32 is needed to avoid a Tx hang with DFP enabled. */
2405 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2406 32; /* PTHRESH = 32 */
2408 /* reinitialize flowdirector state */
2409 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2410 adapter->atr_sample_rate) {
2411 ring->atr_sample_rate = adapter->atr_sample_rate;
2412 ring->atr_count = 0;
2413 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2415 ring->atr_sample_rate = 0;
2418 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2421 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2423 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2424 if (hw->mac.type == ixgbe_mac_82598EB &&
2425 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2428 /* poll to verify queue is enabled */
2430 usleep_range(1000, 2000);
2431 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2432 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2434 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
2437 static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2439 struct ixgbe_hw *hw = &adapter->hw;
2442 u8 tcs = netdev_get_num_tc(adapter->netdev);
2444 if (hw->mac.type == ixgbe_mac_82598EB)
2447 /* disable the arbiter while setting MTQC */
2448 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2449 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2450 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2452 /* set transmit pool layout */
2453 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
2454 case (IXGBE_FLAG_SRIOV_ENABLED):
2455 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2456 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2460 reg = IXGBE_MTQC_64Q_1PB;
2462 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2464 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2466 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2468 /* Enable Security TX Buffer IFG for multiple pb */
2470 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2471 reg |= IXGBE_SECTX_DCB;
2472 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2477 /* re-enable the arbiter */
2478 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2479 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2483 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
2484 * @adapter: board private structure
2486 * Configure the Tx unit of the MAC after a reset.
2488 static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2490 struct ixgbe_hw *hw = &adapter->hw;
2494 ixgbe_setup_mtqc(adapter);
2496 if (hw->mac.type != ixgbe_mac_82598EB) {
2497 /* DMATXCTL.EN must be before Tx queues are enabled */
2498 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2499 dmatxctl |= IXGBE_DMATXCTL_TE;
2500 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2503 /* Setup the HW Tx Head and Tail descriptor pointers */
2504 for (i = 0; i < adapter->num_tx_queues; i++)
2505 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
2508 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
2510 static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
2511 struct ixgbe_ring *rx_ring)
2514 u8 reg_idx = rx_ring->reg_idx;
2516 switch (adapter->hw.mac.type) {
2517 case ixgbe_mac_82598EB: {
2518 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2519 const int mask = feature[RING_F_RSS].mask;
2520 reg_idx = reg_idx & mask;
2523 case ixgbe_mac_82599EB:
2524 case ixgbe_mac_X540:
2529 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
2531 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2532 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
2533 if (adapter->num_vfs)
2534 srrctl |= IXGBE_SRRCTL_DROP_EN;
2536 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2537 IXGBE_SRRCTL_BSIZEHDR_MASK;
2539 if (ring_is_ps_enabled(rx_ring)) {
2540 #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2541 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2543 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2545 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
2547 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2548 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2549 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
2552 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
2555 static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
2557 struct ixgbe_hw *hw = &adapter->hw;
2558 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
2559 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2560 0x6A3E67EA, 0x14364D17, 0x3BED200D};
2561 u32 mrqc = 0, reta = 0;
2564 u8 tcs = netdev_get_num_tc(adapter->netdev);
2565 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2568 maxq = min(maxq, adapter->num_tx_queues / tcs);
2570 /* Fill out hash function seeds */
2571 for (i = 0; i < 10; i++)
2572 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
2574 /* Fill out redirection table */
2575 for (i = 0, j = 0; i < 128; i++, j++) {
2578 /* reta = 4-byte sliding window of
2579 * 0x00..(indices-1)(indices-1)00..etc. */
2580 reta = (reta << 8) | (j * 0x11);
2582 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2585 /* Disable indicating checksum in descriptor, enables RSS hash */
2586 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2587 rxcsum |= IXGBE_RXCSUM_PCSD;
2588 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2590 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2591 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
2592 mrqc = IXGBE_MRQC_RSSEN;
2594 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2595 | IXGBE_FLAG_SRIOV_ENABLED);
2598 case (IXGBE_FLAG_RSS_ENABLED):
2600 mrqc = IXGBE_MRQC_RSSEN;
2602 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2604 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2606 case (IXGBE_FLAG_SRIOV_ENABLED):
2607 mrqc = IXGBE_MRQC_VMDQEN;
2614 /* Perform hash on these packet types */
2615 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2616 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2617 | IXGBE_MRQC_RSS_FIELD_IPV6
2618 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2620 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
2624 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2625 * @adapter: address of board private structure
2626 * @index: index of ring to set
2628 static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
2629 struct ixgbe_ring *ring)
2631 struct ixgbe_hw *hw = &adapter->hw;
2634 u8 reg_idx = ring->reg_idx;
2636 if (!ring_is_rsc_enabled(ring))
2639 rx_buf_len = ring->rx_buf_len;
2640 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
2641 rscctrl |= IXGBE_RSCCTL_RSCEN;
2643 * we must limit the number of descriptors so that the
2644 * total size of max desc * buf_len is not greater
2647 if (ring_is_ps_enabled(ring)) {
2648 #if (MAX_SKB_FRAGS > 16)
2649 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2650 #elif (MAX_SKB_FRAGS > 8)
2651 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2652 #elif (MAX_SKB_FRAGS > 4)
2653 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2655 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2658 if (rx_buf_len < IXGBE_RXBUFFER_4K)
2659 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2660 else if (rx_buf_len < IXGBE_RXBUFFER_8K)
2661 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2663 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2665 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
2669 * ixgbe_set_uta - Set unicast filter table address
2670 * @adapter: board private structure
2672 * The unicast table address is a register array of 32-bit registers.
2673 * The table is meant to be used in a way similar to how the MTA is used
2674 * however due to certain limitations in the hardware it is necessary to
2675 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2676 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2678 static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2680 struct ixgbe_hw *hw = &adapter->hw;
2683 /* The UTA table only exists on 82599 hardware and newer */
2684 if (hw->mac.type < ixgbe_mac_82599EB)
2687 /* we only need to do this if VMDq is enabled */
2688 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2691 for (i = 0; i < 128; i++)
2692 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2695 #define IXGBE_MAX_RX_DESC_POLL 10
2696 static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2697 struct ixgbe_ring *ring)
2699 struct ixgbe_hw *hw = &adapter->hw;
2700 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2702 u8 reg_idx = ring->reg_idx;
2704 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2705 if (hw->mac.type == ixgbe_mac_82598EB &&
2706 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2710 usleep_range(1000, 2000);
2711 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2712 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2715 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2716 "the polling period\n", reg_idx);
2720 void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2721 struct ixgbe_ring *ring)
2723 struct ixgbe_hw *hw = &adapter->hw;
2724 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2726 u8 reg_idx = ring->reg_idx;
2728 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2729 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2731 /* write value back with RXDCTL.ENABLE bit cleared */
2732 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2734 if (hw->mac.type == ixgbe_mac_82598EB &&
2735 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2738 /* the hardware may take up to 100us to really disable the rx queue */
2741 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2742 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2745 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2746 "the polling period\n", reg_idx);
2750 void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2751 struct ixgbe_ring *ring)
2753 struct ixgbe_hw *hw = &adapter->hw;
2754 u64 rdba = ring->dma;
2756 u8 reg_idx = ring->reg_idx;
2758 /* disable queue to avoid issues while updating state */
2759 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2760 ixgbe_disable_rx_queue(adapter, ring);
2762 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
2763 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
2764 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
2765 ring->count * sizeof(union ixgbe_adv_rx_desc));
2766 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
2767 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
2768 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
2770 ixgbe_configure_srrctl(adapter, ring);
2771 ixgbe_configure_rscctl(adapter, ring);
2773 /* If operating in IOV mode set RLPML for X540 */
2774 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
2775 hw->mac.type == ixgbe_mac_X540) {
2776 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
2777 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
2778 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
2781 if (hw->mac.type == ixgbe_mac_82598EB) {
2783 * enable cache line friendly hardware writes:
2784 * PTHRESH=32 descriptors (half the internal cache),
2785 * this also removes ugly rx_no_buffer_count increment
2786 * HTHRESH=4 descriptors (to minimize latency on fetch)
2787 * WTHRESH=8 burst writeback up to two cache lines
2789 rxdctl &= ~0x3FFFFF;
2793 /* enable receive descriptor ring */
2794 rxdctl |= IXGBE_RXDCTL_ENABLE;
2795 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2797 ixgbe_rx_desc_queue_enable(adapter, ring);
2798 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
2801 static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
2803 struct ixgbe_hw *hw = &adapter->hw;
2806 /* PSRTYPE must be initialized in non 82598 adapters */
2807 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
2808 IXGBE_PSRTYPE_UDPHDR |
2809 IXGBE_PSRTYPE_IPV4HDR |
2810 IXGBE_PSRTYPE_L2HDR |
2811 IXGBE_PSRTYPE_IPV6HDR;
2813 if (hw->mac.type == ixgbe_mac_82598EB)
2816 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
2817 psrtype |= (adapter->num_rx_queues_per_pool << 29);
2819 for (p = 0; p < adapter->num_rx_pools; p++)
2820 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
2824 static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
2826 struct ixgbe_hw *hw = &adapter->hw;
2829 u32 reg_offset, vf_shift;
2833 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2836 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2837 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
2838 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
2839 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
2841 vf_shift = adapter->num_vfs % 32;
2842 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
2844 /* Enable only the PF's pool for Tx/Rx */
2845 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
2846 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
2847 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
2848 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
2849 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
2851 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
2852 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
2855 * Set up VF register offsets for selected VT Mode,
2856 * i.e. 32 or 64 VFs for SR-IOV
2858 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
2859 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
2860 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
2861 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
2863 /* enable Tx loopback for VF/PF communication */
2864 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
2865 /* Enable MAC Anti-Spoofing */
2866 hw->mac.ops.set_mac_anti_spoofing(hw,
2867 (adapter->num_vfs != 0),
2869 /* For VFs that have spoof checking turned off */
2870 for (i = 0; i < adapter->num_vfs; i++) {
2871 if (!adapter->vfinfo[i].spoofchk_enabled)
2872 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
2876 static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
2878 struct ixgbe_hw *hw = &adapter->hw;
2879 struct net_device *netdev = adapter->netdev;
2880 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
2882 struct ixgbe_ring *rx_ring;
2886 /* Decide whether to use packet split mode or not */
2888 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
2890 /* Do not use packet split if we're in SR-IOV Mode */
2891 if (adapter->num_vfs)
2892 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
2894 /* Disable packet split due to 82599 erratum #45 */
2895 if (hw->mac.type == ixgbe_mac_82599EB)
2896 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
2899 /* adjust max frame to be able to do baby jumbo for FCoE */
2900 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
2901 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
2902 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
2904 #endif /* IXGBE_FCOE */
2905 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
2906 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2907 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2908 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2910 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2913 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
2914 max_frame += VLAN_HLEN;
2916 /* Set the RX buffer length according to the mode */
2917 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
2918 rx_buf_len = IXGBE_RX_HDR_SIZE;
2920 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
2921 (netdev->mtu <= ETH_DATA_LEN))
2922 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
2924 * Make best use of allocation by using all but 1K of a
2925 * power of 2 allocation that will be used for skb->head.
2927 else if (max_frame <= IXGBE_RXBUFFER_3K)
2928 rx_buf_len = IXGBE_RXBUFFER_3K;
2929 else if (max_frame <= IXGBE_RXBUFFER_7K)
2930 rx_buf_len = IXGBE_RXBUFFER_7K;
2931 else if (max_frame <= IXGBE_RXBUFFER_15K)
2932 rx_buf_len = IXGBE_RXBUFFER_15K;
2934 rx_buf_len = IXGBE_MAX_RXBUFFER;
2937 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
2938 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
2939 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
2940 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
2943 * Setup the HW Rx Head and Tail Descriptor Pointers and
2944 * the Base and Length of the Rx Descriptor Ring
2946 for (i = 0; i < adapter->num_rx_queues; i++) {
2947 rx_ring = adapter->rx_ring[i];
2948 rx_ring->rx_buf_len = rx_buf_len;
2950 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
2951 set_ring_ps_enabled(rx_ring);
2953 clear_ring_ps_enabled(rx_ring);
2955 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
2956 set_ring_rsc_enabled(rx_ring);
2958 clear_ring_rsc_enabled(rx_ring);
2961 if (netdev->features & NETIF_F_FCOE_MTU) {
2962 struct ixgbe_ring_feature *f;
2963 f = &adapter->ring_feature[RING_F_FCOE];
2964 if ((i >= f->mask) && (i < f->mask + f->indices)) {
2965 clear_ring_ps_enabled(rx_ring);
2966 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
2967 rx_ring->rx_buf_len =
2968 IXGBE_FCOE_JUMBO_FRAME_SIZE;
2969 } else if (!ring_is_rsc_enabled(rx_ring) &&
2970 !ring_is_ps_enabled(rx_ring)) {
2971 rx_ring->rx_buf_len =
2972 IXGBE_FCOE_JUMBO_FRAME_SIZE;
2975 #endif /* IXGBE_FCOE */
2979 static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
2981 struct ixgbe_hw *hw = &adapter->hw;
2982 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2984 switch (hw->mac.type) {
2985 case ixgbe_mac_82598EB:
2987 * For VMDq support of different descriptor types or
2988 * buffer sizes through the use of multiple SRRCTL
2989 * registers, RDRXCTL.MVMEN must be set to 1
2991 * also, the manual doesn't mention it clearly but DCA hints
2992 * will only use queue 0's tags unless this bit is set. Side
2993 * effects of setting this bit are only that SRRCTL must be
2994 * fully programmed [0..15]
2996 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
2998 case ixgbe_mac_82599EB:
2999 case ixgbe_mac_X540:
3000 /* Disable RSC for ACK packets */
3001 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3002 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3003 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3004 /* hardware requires some bits to be set by default */
3005 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3006 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3009 /* We should do nothing since we don't know this hardware */
3013 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3017 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3018 * @adapter: board private structure
3020 * Configure the Rx unit of the MAC after a reset.
3022 static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3024 struct ixgbe_hw *hw = &adapter->hw;
3028 /* disable receives while setting up the descriptors */
3029 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3030 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3032 ixgbe_setup_psrtype(adapter);
3033 ixgbe_setup_rdrxctl(adapter);
3035 /* Program registers for the distribution of queues */
3036 ixgbe_setup_mrqc(adapter);
3038 ixgbe_set_uta(adapter);
3040 /* set_rx_buffer_len must be called before ring initialization */
3041 ixgbe_set_rx_buffer_len(adapter);
3044 * Setup the HW Rx Head and Tail Descriptor Pointers and
3045 * the Base and Length of the Rx Descriptor Ring
3047 for (i = 0; i < adapter->num_rx_queues; i++)
3048 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
3050 /* disable drop enable for 82598 parts */
3051 if (hw->mac.type == ixgbe_mac_82598EB)
3052 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3054 /* enable all receives */
3055 rxctrl |= IXGBE_RXCTRL_RXEN;
3056 hw->mac.ops.enable_rx_dma(hw, rxctrl);
3059 static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3061 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3062 struct ixgbe_hw *hw = &adapter->hw;
3063 int pool_ndx = adapter->num_vfs;
3065 /* add VID to filter table */
3066 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
3067 set_bit(vid, adapter->active_vlans);
3070 static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3072 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3073 struct ixgbe_hw *hw = &adapter->hw;
3074 int pool_ndx = adapter->num_vfs;
3076 /* remove VID from filter table */
3077 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
3078 clear_bit(vid, adapter->active_vlans);
3082 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3083 * @adapter: driver data
3085 static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3087 struct ixgbe_hw *hw = &adapter->hw;
3090 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3091 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3092 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3096 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3097 * @adapter: driver data
3099 static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3101 struct ixgbe_hw *hw = &adapter->hw;
3104 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3105 vlnctrl |= IXGBE_VLNCTRL_VFE;
3106 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3107 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3111 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3112 * @adapter: driver data
3114 static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3116 struct ixgbe_hw *hw = &adapter->hw;
3120 switch (hw->mac.type) {
3121 case ixgbe_mac_82598EB:
3122 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3123 vlnctrl &= ~IXGBE_VLNCTRL_VME;
3124 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3126 case ixgbe_mac_82599EB:
3127 case ixgbe_mac_X540:
3128 for (i = 0; i < adapter->num_rx_queues; i++) {
3129 j = adapter->rx_ring[i]->reg_idx;
3130 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3131 vlnctrl &= ~IXGBE_RXDCTL_VME;
3132 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3141 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
3142 * @adapter: driver data
3144 static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
3146 struct ixgbe_hw *hw = &adapter->hw;
3150 switch (hw->mac.type) {
3151 case ixgbe_mac_82598EB:
3152 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3153 vlnctrl |= IXGBE_VLNCTRL_VME;
3154 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3156 case ixgbe_mac_82599EB:
3157 case ixgbe_mac_X540:
3158 for (i = 0; i < adapter->num_rx_queues; i++) {
3159 j = adapter->rx_ring[i]->reg_idx;
3160 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3161 vlnctrl |= IXGBE_RXDCTL_VME;
3162 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3170 static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3174 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3176 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3177 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
3181 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3182 * @netdev: network interface device structure
3184 * Writes unicast address list to the RAR table.
3185 * Returns: -ENOMEM on failure/insufficient address space
3186 * 0 on no addresses written
3187 * X on writing X addresses to the RAR table
3189 static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3191 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3192 struct ixgbe_hw *hw = &adapter->hw;
3193 unsigned int vfn = adapter->num_vfs;
3194 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
3197 /* return ENOMEM indicating insufficient memory for addresses */
3198 if (netdev_uc_count(netdev) > rar_entries)
3201 if (!netdev_uc_empty(netdev) && rar_entries) {
3202 struct netdev_hw_addr *ha;
3203 /* return error if we do not support writing to RAR table */
3204 if (!hw->mac.ops.set_rar)
3207 netdev_for_each_uc_addr(ha, netdev) {
3210 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3215 /* write the addresses in reverse order to avoid write combining */
3216 for (; rar_entries > 0 ; rar_entries--)
3217 hw->mac.ops.clear_rar(hw, rar_entries);
3223 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
3224 * @netdev: network interface device structure
3226 * The set_rx_method entry point is called whenever the unicast/multicast
3227 * address list or the network interface flags are updated. This routine is
3228 * responsible for configuring the hardware for proper unicast, multicast and
3231 void ixgbe_set_rx_mode(struct net_device *netdev)
3233 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3234 struct ixgbe_hw *hw = &adapter->hw;
3235 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3238 /* Check for Promiscuous and All Multicast modes */
3240 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3242 /* set all bits that we expect to always be set */
3243 fctrl |= IXGBE_FCTRL_BAM;
3244 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3245 fctrl |= IXGBE_FCTRL_PMCF;
3247 /* clear the bits we are changing the status of */
3248 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3250 if (netdev->flags & IFF_PROMISC) {
3251 hw->addr_ctrl.user_set_promisc = true;
3252 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3253 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
3254 /* don't hardware filter vlans in promisc mode */
3255 ixgbe_vlan_filter_disable(adapter);
3257 if (netdev->flags & IFF_ALLMULTI) {
3258 fctrl |= IXGBE_FCTRL_MPE;
3259 vmolr |= IXGBE_VMOLR_MPE;
3262 * Write addresses to the MTA, if the attempt fails
3263 * then we should just turn on promiscuous mode so
3264 * that we can at least receive multicast traffic
3266 hw->mac.ops.update_mc_addr_list(hw, netdev);
3267 vmolr |= IXGBE_VMOLR_ROMPE;
3269 ixgbe_vlan_filter_enable(adapter);
3270 hw->addr_ctrl.user_set_promisc = false;
3272 * Write addresses to available RAR registers, if there is not
3273 * sufficient space to store all the addresses then enable
3274 * unicast promiscuous mode
3276 count = ixgbe_write_uc_addr_list(netdev);
3278 fctrl |= IXGBE_FCTRL_UPE;
3279 vmolr |= IXGBE_VMOLR_ROPE;
3283 if (adapter->num_vfs) {
3284 ixgbe_restore_vf_multicasts(adapter);
3285 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3286 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3288 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
3291 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3293 if (netdev->features & NETIF_F_HW_VLAN_RX)
3294 ixgbe_vlan_strip_enable(adapter);
3296 ixgbe_vlan_strip_disable(adapter);
3299 static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3302 struct ixgbe_q_vector *q_vector;
3303 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3305 /* legacy and MSI only use one vector */
3306 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3309 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3310 q_vector = adapter->q_vector[q_idx];
3311 napi_enable(&q_vector->napi);
3315 static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3318 struct ixgbe_q_vector *q_vector;
3319 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3321 /* legacy and MSI only use one vector */
3322 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3325 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3326 q_vector = adapter->q_vector[q_idx];
3327 napi_disable(&q_vector->napi);
3331 #ifdef CONFIG_IXGBE_DCB
3333 * ixgbe_configure_dcb - Configure DCB hardware
3334 * @adapter: ixgbe adapter struct
3336 * This is called by the driver on open to configure the DCB hardware.
3337 * This is also called by the gennetlink interface when reconfiguring
3340 static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3342 struct ixgbe_hw *hw = &adapter->hw;
3343 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3345 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3346 if (hw->mac.type == ixgbe_mac_82598EB)
3347 netif_set_gso_max_size(adapter->netdev, 65536);
3351 if (hw->mac.type == ixgbe_mac_82598EB)
3352 netif_set_gso_max_size(adapter->netdev, 32768);
3355 /* Enable VLAN tag insert/strip */
3356 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
3358 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
3361 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3362 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3365 /* reconfigure the hardware */
3366 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
3367 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3369 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3371 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3372 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3373 ixgbe_dcb_hw_ets(&adapter->hw,
3374 adapter->ixgbe_ieee_ets,
3376 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3377 adapter->ixgbe_ieee_pfc->pfc_en,
3378 adapter->ixgbe_ieee_ets->prio_tc);
3381 /* Enable RSS Hash per TC */
3382 if (hw->mac.type != ixgbe_mac_82598EB) {
3386 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3388 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3393 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3395 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3400 /* Additional bittime to account for IXGBE framing */
3401 #define IXGBE_ETH_FRAMING 20
3404 * ixgbe_hpbthresh - calculate high water mark for flow control
3406 * @adapter: board private structure to calculate for
3407 * @pb - packet buffer to calculate
3409 static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3411 struct ixgbe_hw *hw = &adapter->hw;
3412 struct net_device *dev = adapter->netdev;
3413 int link, tc, kb, marker;
3416 /* Calculate max LAN frame size */
3417 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3420 /* FCoE traffic class uses FCOE jumbo frames */
3421 if (dev->features & NETIF_F_FCOE_MTU) {
3424 #ifdef CONFIG_IXGBE_DCB
3425 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
3428 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3429 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3433 /* Calculate delay value for device */
3434 switch (hw->mac.type) {
3435 case ixgbe_mac_X540:
3436 dv_id = IXGBE_DV_X540(link, tc);
3439 dv_id = IXGBE_DV(link, tc);
3443 /* Loopback switch introduces additional latency */
3444 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3445 dv_id += IXGBE_B2BT(tc);
3447 /* Delay value is calculated in bit times convert to KB */
3448 kb = IXGBE_BT2KB(dv_id);
3449 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3451 marker = rx_pba - kb;
3453 /* It is possible that the packet buffer is not large enough
3454 * to provide required headroom. In this case throw an error
3455 * to user and a do the best we can.
3458 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3459 "headroom to support flow control."
3460 "Decrease MTU or number of traffic classes\n", pb);
3468 * ixgbe_lpbthresh - calculate low water mark for for flow control
3470 * @adapter: board private structure to calculate for
3471 * @pb - packet buffer to calculate
3473 static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3475 struct ixgbe_hw *hw = &adapter->hw;
3476 struct net_device *dev = adapter->netdev;
3480 /* Calculate max LAN frame size */
3481 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3483 /* Calculate delay value for device */
3484 switch (hw->mac.type) {
3485 case ixgbe_mac_X540:
3486 dv_id = IXGBE_LOW_DV_X540(tc);
3489 dv_id = IXGBE_LOW_DV(tc);
3493 /* Delay value is calculated in bit times convert to KB */
3494 return IXGBE_BT2KB(dv_id);
3498 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3500 static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3502 struct ixgbe_hw *hw = &adapter->hw;
3503 int num_tc = netdev_get_num_tc(adapter->netdev);
3509 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3511 for (i = 0; i < num_tc; i++) {
3512 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3514 /* Low water marks must not be larger than high water marks */
3515 if (hw->fc.low_water > hw->fc.high_water[i])
3516 hw->fc.low_water = 0;
3520 static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3522 struct ixgbe_hw *hw = &adapter->hw;
3524 u8 tc = netdev_get_num_tc(adapter->netdev);
3526 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3527 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3528 hdrm = 32 << adapter->fdir_pballoc;
3532 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
3533 ixgbe_pbthresh_setup(adapter);
3536 static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3538 struct ixgbe_hw *hw = &adapter->hw;
3539 struct hlist_node *node, *node2;
3540 struct ixgbe_fdir_filter *filter;
3542 spin_lock(&adapter->fdir_perfect_lock);
3544 if (!hlist_empty(&adapter->fdir_filter_list))
3545 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3547 hlist_for_each_entry_safe(filter, node, node2,
3548 &adapter->fdir_filter_list, fdir_node) {
3549 ixgbe_fdir_write_perfect_filter_82599(hw,
3552 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3553 IXGBE_FDIR_DROP_QUEUE :
3554 adapter->rx_ring[filter->action]->reg_idx);
3557 spin_unlock(&adapter->fdir_perfect_lock);
3560 static void ixgbe_configure(struct ixgbe_adapter *adapter)
3562 ixgbe_configure_pb(adapter);
3563 #ifdef CONFIG_IXGBE_DCB
3564 ixgbe_configure_dcb(adapter);
3567 ixgbe_set_rx_mode(adapter->netdev);
3568 ixgbe_restore_vlan(adapter);
3571 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3572 ixgbe_configure_fcoe(adapter);
3574 #endif /* IXGBE_FCOE */
3575 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3576 ixgbe_init_fdir_signature_82599(&adapter->hw,
3577 adapter->fdir_pballoc);
3578 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3579 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3580 adapter->fdir_pballoc);
3581 ixgbe_fdir_filter_restore(adapter);
3584 ixgbe_configure_virtualization(adapter);
3586 ixgbe_configure_tx(adapter);
3587 ixgbe_configure_rx(adapter);
3590 static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3592 switch (hw->phy.type) {
3593 case ixgbe_phy_sfp_avago:
3594 case ixgbe_phy_sfp_ftl:
3595 case ixgbe_phy_sfp_intel:
3596 case ixgbe_phy_sfp_unknown:
3597 case ixgbe_phy_sfp_passive_tyco:
3598 case ixgbe_phy_sfp_passive_unknown:
3599 case ixgbe_phy_sfp_active_unknown:
3600 case ixgbe_phy_sfp_ftl_active:
3603 if (hw->mac.type == ixgbe_mac_82598EB)
3611 * ixgbe_sfp_link_config - set up SFP+ link
3612 * @adapter: pointer to private adapter struct
3614 static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3617 * We are assuming the worst case scenerio here, and that
3618 * is that an SFP was inserted/removed after the reset
3619 * but before SFP detection was enabled. As such the best
3620 * solution is to just start searching as soon as we start
3622 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3623 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
3625 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
3629 * ixgbe_non_sfp_link_config - set up non-SFP+ link
3630 * @hw: pointer to private hardware struct
3632 * Returns 0 on success, negative on failure
3634 static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
3637 bool negotiation, link_up = false;
3638 u32 ret = IXGBE_ERR_LINK_SETUP;
3640 if (hw->mac.ops.check_link)
3641 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3646 autoneg = hw->phy.autoneg_advertised;
3647 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
3648 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3653 if (hw->mac.ops.setup_link)
3654 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
3659 static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
3661 struct ixgbe_hw *hw = &adapter->hw;
3664 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3665 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3667 gpie |= IXGBE_GPIE_EIAME;
3669 * use EIAM to auto-mask when MSI-X interrupt is asserted
3670 * this saves a register write for every interrupt
3672 switch (hw->mac.type) {
3673 case ixgbe_mac_82598EB:
3674 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3676 case ixgbe_mac_82599EB:
3677 case ixgbe_mac_X540:
3679 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3680 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3684 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3685 * specifically only auto mask tx and rx interrupts */
3686 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3689 /* XXX: to interrupt immediately for EICS writes, enable this */
3690 /* gpie |= IXGBE_GPIE_EIMEN; */
3692 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3693 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3694 gpie |= IXGBE_GPIE_VTMODE_64;
3697 /* Enable Thermal over heat sensor interrupt */
3698 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
3699 switch (adapter->hw.mac.type) {
3700 case ixgbe_mac_82599EB:
3701 gpie |= IXGBE_SDP0_GPIEN;
3703 case ixgbe_mac_X540:
3704 gpie |= IXGBE_EIMS_TS;
3711 /* Enable fan failure interrupt */
3712 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
3713 gpie |= IXGBE_SDP1_GPIEN;
3715 if (hw->mac.type == ixgbe_mac_82599EB) {
3716 gpie |= IXGBE_SDP1_GPIEN;
3717 gpie |= IXGBE_SDP2_GPIEN;
3720 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3723 static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
3725 struct ixgbe_hw *hw = &adapter->hw;
3729 ixgbe_get_hw_control(adapter);
3730 ixgbe_setup_gpie(adapter);
3732 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3733 ixgbe_configure_msix(adapter);
3735 ixgbe_configure_msi_and_legacy(adapter);
3737 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3738 if (hw->mac.ops.enable_tx_laser &&
3739 ((hw->phy.multispeed_fiber) ||
3740 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
3741 (hw->mac.type == ixgbe_mac_82599EB))))
3742 hw->mac.ops.enable_tx_laser(hw);
3744 clear_bit(__IXGBE_DOWN, &adapter->state);
3745 ixgbe_napi_enable_all(adapter);
3747 if (ixgbe_is_sfp(hw)) {
3748 ixgbe_sfp_link_config(adapter);
3750 err = ixgbe_non_sfp_link_config(hw);
3752 e_err(probe, "link_config FAILED %d\n", err);
3755 /* clear any pending interrupts, may auto mask */
3756 IXGBE_READ_REG(hw, IXGBE_EICR);
3757 ixgbe_irq_enable(adapter, true, true);
3760 * If this adapter has a fan, check to see if we had a failure
3761 * before we enabled the interrupt.
3763 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3764 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3765 if (esdp & IXGBE_ESDP_SDP1)
3766 e_crit(drv, "Fan has stopped, replace the adapter\n");
3769 /* enable transmits */
3770 netif_tx_start_all_queues(adapter->netdev);
3772 /* bring the link up in the watchdog, this could race with our first
3773 * link up interrupt but shouldn't be a problem */
3774 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3775 adapter->link_check_timeout = jiffies;
3776 mod_timer(&adapter->service_timer, jiffies);
3778 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3779 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3780 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3781 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3784 void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3786 WARN_ON(in_interrupt());
3787 /* put off any impending NetWatchDogTimeout */
3788 adapter->netdev->trans_start = jiffies;
3790 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
3791 usleep_range(1000, 2000);
3792 ixgbe_down(adapter);
3794 * If SR-IOV enabled then wait a bit before bringing the adapter
3795 * back up to give the VFs time to respond to the reset. The
3796 * two second wait is based upon the watchdog timer cycle in
3799 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3802 clear_bit(__IXGBE_RESETTING, &adapter->state);
3805 void ixgbe_up(struct ixgbe_adapter *adapter)
3807 /* hardware has been reset, we need to reload some things */
3808 ixgbe_configure(adapter);
3810 ixgbe_up_complete(adapter);
3813 void ixgbe_reset(struct ixgbe_adapter *adapter)
3815 struct ixgbe_hw *hw = &adapter->hw;
3818 /* lock SFP init bit to prevent race conditions with the watchdog */
3819 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
3820 usleep_range(1000, 2000);
3822 /* clear all SFP and link config related flags while holding SFP_INIT */
3823 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
3824 IXGBE_FLAG2_SFP_NEEDS_RESET);
3825 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3827 err = hw->mac.ops.init_hw(hw);
3830 case IXGBE_ERR_SFP_NOT_PRESENT:
3831 case IXGBE_ERR_SFP_NOT_SUPPORTED:
3833 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
3834 e_dev_err("master disable timed out\n");
3836 case IXGBE_ERR_EEPROM_VERSION:
3837 /* We are running on a pre-production device, log a warning */
3838 e_dev_warn("This device is a pre-production adapter/LOM. "
3839 "Please be aware there may be issuesassociated with "
3840 "your hardware. If you are experiencing problems "
3841 "please contact your Intel or hardware "
3842 "representative who provided you with this "
3846 e_dev_err("Hardware Error: %d\n", err);
3849 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
3851 /* reprogram the RAR[0] in case user changed it. */
3852 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
3857 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
3858 * @rx_ring: ring to free buffers from
3860 static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
3862 struct device *dev = rx_ring->dev;
3866 /* ring already cleared, nothing to do */
3867 if (!rx_ring->rx_buffer_info)
3870 /* Free all the Rx ring sk_buffs */
3871 for (i = 0; i < rx_ring->count; i++) {
3872 struct ixgbe_rx_buffer *rx_buffer_info;
3874 rx_buffer_info = &rx_ring->rx_buffer_info[i];
3875 if (rx_buffer_info->dma) {
3876 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
3877 rx_ring->rx_buf_len,
3879 rx_buffer_info->dma = 0;
3881 if (rx_buffer_info->skb) {
3882 struct sk_buff *skb = rx_buffer_info->skb;
3883 rx_buffer_info->skb = NULL;
3885 struct sk_buff *this = skb;
3886 if (IXGBE_RSC_CB(this)->delay_unmap) {
3887 dma_unmap_single(dev,
3888 IXGBE_RSC_CB(this)->dma,
3889 rx_ring->rx_buf_len,
3891 IXGBE_RSC_CB(this)->dma = 0;
3892 IXGBE_RSC_CB(skb)->delay_unmap = false;
3895 dev_kfree_skb(this);
3898 if (!rx_buffer_info->page)
3900 if (rx_buffer_info->page_dma) {
3901 dma_unmap_page(dev, rx_buffer_info->page_dma,
3902 PAGE_SIZE / 2, DMA_FROM_DEVICE);
3903 rx_buffer_info->page_dma = 0;
3905 put_page(rx_buffer_info->page);
3906 rx_buffer_info->page = NULL;
3907 rx_buffer_info->page_offset = 0;
3910 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
3911 memset(rx_ring->rx_buffer_info, 0, size);
3913 /* Zero out the descriptor ring */
3914 memset(rx_ring->desc, 0, rx_ring->size);
3916 rx_ring->next_to_clean = 0;
3917 rx_ring->next_to_use = 0;
3921 * ixgbe_clean_tx_ring - Free Tx Buffers
3922 * @tx_ring: ring to be cleaned
3924 static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
3926 struct ixgbe_tx_buffer *tx_buffer_info;
3930 /* ring already cleared, nothing to do */
3931 if (!tx_ring->tx_buffer_info)
3934 /* Free all the Tx ring sk_buffs */
3935 for (i = 0; i < tx_ring->count; i++) {
3936 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3937 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
3940 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
3941 memset(tx_ring->tx_buffer_info, 0, size);
3943 /* Zero out the descriptor ring */
3944 memset(tx_ring->desc, 0, tx_ring->size);
3946 tx_ring->next_to_use = 0;
3947 tx_ring->next_to_clean = 0;
3951 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
3952 * @adapter: board private structure
3954 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
3958 for (i = 0; i < adapter->num_rx_queues; i++)
3959 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
3963 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
3964 * @adapter: board private structure
3966 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
3970 for (i = 0; i < adapter->num_tx_queues; i++)
3971 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
3974 static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
3976 struct hlist_node *node, *node2;
3977 struct ixgbe_fdir_filter *filter;
3979 spin_lock(&adapter->fdir_perfect_lock);
3981 hlist_for_each_entry_safe(filter, node, node2,
3982 &adapter->fdir_filter_list, fdir_node) {
3983 hlist_del(&filter->fdir_node);
3986 adapter->fdir_filter_count = 0;
3988 spin_unlock(&adapter->fdir_perfect_lock);
3991 void ixgbe_down(struct ixgbe_adapter *adapter)
3993 struct net_device *netdev = adapter->netdev;
3994 struct ixgbe_hw *hw = &adapter->hw;
3998 /* signal that we are down to the interrupt handler */
3999 set_bit(__IXGBE_DOWN, &adapter->state);
4001 /* disable receives */
4002 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4003 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
4005 /* disable all enabled rx queues */
4006 for (i = 0; i < adapter->num_rx_queues; i++)
4007 /* this call also flushes the previous write */
4008 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4010 usleep_range(10000, 20000);
4012 netif_tx_stop_all_queues(netdev);
4014 /* call carrier off first to avoid false dev_watchdog timeouts */
4015 netif_carrier_off(netdev);
4016 netif_tx_disable(netdev);
4018 ixgbe_irq_disable(adapter);
4020 ixgbe_napi_disable_all(adapter);
4022 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4023 IXGBE_FLAG2_RESET_REQUESTED);
4024 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4026 del_timer_sync(&adapter->service_timer);
4028 if (adapter->num_vfs) {
4029 /* Clear EITR Select mapping */
4030 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4032 /* Mark all the VFs as inactive */
4033 for (i = 0 ; i < adapter->num_vfs; i++)
4034 adapter->vfinfo[i].clear_to_send = 0;
4036 /* ping all the active vfs to let them know we are going down */
4037 ixgbe_ping_all_vfs(adapter);
4039 /* Disable all VFTE/VFRE TX/RX */
4040 ixgbe_disable_tx_rx(adapter);
4043 /* disable transmits in the hardware now that interrupts are off */
4044 for (i = 0; i < adapter->num_tx_queues; i++) {
4045 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
4046 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
4049 /* Disable the Tx DMA engine on 82599 and X540 */
4050 switch (hw->mac.type) {
4051 case ixgbe_mac_82599EB:
4052 case ixgbe_mac_X540:
4053 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
4054 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4055 ~IXGBE_DMATXCTL_TE));
4061 if (!pci_channel_offline(adapter->pdev))
4062 ixgbe_reset(adapter);
4064 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4065 if (hw->mac.ops.disable_tx_laser &&
4066 ((hw->phy.multispeed_fiber) ||
4067 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
4068 (hw->mac.type == ixgbe_mac_82599EB))))
4069 hw->mac.ops.disable_tx_laser(hw);
4071 ixgbe_clean_all_tx_rings(adapter);
4072 ixgbe_clean_all_rx_rings(adapter);
4074 #ifdef CONFIG_IXGBE_DCA
4075 /* since we reset the hardware DCA settings were cleared */
4076 ixgbe_setup_dca(adapter);
4081 * ixgbe_poll - NAPI Rx polling callback
4082 * @napi: structure for representing this polling device
4083 * @budget: how many packets driver is allowed to clean
4085 * This function is used for legacy and MSI, NAPI mode
4087 static int ixgbe_poll(struct napi_struct *napi, int budget)
4089 struct ixgbe_q_vector *q_vector =
4090 container_of(napi, struct ixgbe_q_vector, napi);
4091 struct ixgbe_adapter *adapter = q_vector->adapter;
4092 struct ixgbe_ring *ring;
4093 int per_ring_budget;
4094 bool clean_complete = true;
4096 #ifdef CONFIG_IXGBE_DCA
4097 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4098 ixgbe_update_dca(q_vector);
4101 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
4102 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
4104 /* attempt to distribute budget to each queue fairly, but don't allow
4105 * the budget to go below 1 because we'll exit polling */
4106 if (q_vector->rx.count > 1)
4107 per_ring_budget = max(budget/q_vector->rx.count, 1);
4109 per_ring_budget = budget;
4111 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
4112 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
4115 /* If all work not completed, return budget and keep polling */
4116 if (!clean_complete)
4119 /* all work done, exit the polling mode */
4120 napi_complete(napi);
4121 if (adapter->rx_itr_setting & 1)
4122 ixgbe_set_itr(q_vector);
4123 if (!test_bit(__IXGBE_DOWN, &adapter->state))
4124 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
4130 * ixgbe_tx_timeout - Respond to a Tx Hang
4131 * @netdev: network interface device structure
4133 static void ixgbe_tx_timeout(struct net_device *netdev)
4135 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4137 /* Do the reset outside of interrupt context */
4138 ixgbe_tx_timeout_reset(adapter);
4142 * ixgbe_set_rss_queues: Allocate queues for RSS
4143 * @adapter: board private structure to initialize
4145 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4146 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4149 static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4152 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
4154 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4156 adapter->num_rx_queues = f->indices;
4157 adapter->num_tx_queues = f->indices;
4167 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4168 * @adapter: board private structure to initialize
4170 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4171 * to the original CPU that initiated the Tx session. This runs in addition
4172 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4173 * Rx load across CPUs using RSS.
4176 static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
4179 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4181 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4184 /* Flow Director must have RSS enabled */
4185 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4186 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
4187 adapter->num_tx_queues = f_fdir->indices;
4188 adapter->num_rx_queues = f_fdir->indices;
4191 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4198 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4199 * @adapter: board private structure to initialize
4201 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4202 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4203 * rx queues out of the max number of rx queues, instead, it is used as the
4204 * index of the first rx queue used by FCoE.
4207 static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4209 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4211 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4214 f->indices = min((int)num_online_cpus(), f->indices);
4216 adapter->num_rx_queues = 1;
4217 adapter->num_tx_queues = 1;
4219 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4220 e_info(probe, "FCoE enabled with RSS\n");
4221 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
4222 ixgbe_set_fdir_queues(adapter);
4224 ixgbe_set_rss_queues(adapter);
4227 /* adding FCoE rx rings to the end */
4228 f->mask = adapter->num_rx_queues;
4229 adapter->num_rx_queues += f->indices;
4230 adapter->num_tx_queues += f->indices;
4234 #endif /* IXGBE_FCOE */
4236 /* Artificial max queue cap per traffic class in DCB mode */
4237 #define DCB_QUEUE_CAP 8
4239 #ifdef CONFIG_IXGBE_DCB
4240 static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4242 int per_tc_q, q, i, offset = 0;
4243 struct net_device *dev = adapter->netdev;
4244 int tcs = netdev_get_num_tc(dev);
4249 /* Map queue offset and counts onto allocated tx queues */
4250 per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP);
4251 q = min((int)num_online_cpus(), per_tc_q);
4253 for (i = 0; i < tcs; i++) {
4254 netdev_set_tc_queue(dev, i, q, offset);
4258 adapter->num_tx_queues = q * tcs;
4259 adapter->num_rx_queues = q * tcs;
4262 /* FCoE enabled queues require special configuration indexed
4263 * by feature specific indices and mask. Here we map FCoE
4264 * indices onto the DCB queue pairs allowing FCoE to own
4265 * configuration later.
4267 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4269 struct ixgbe_ring_feature *f =
4270 &adapter->ring_feature[RING_F_FCOE];
4272 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4273 f->indices = dev->tc_to_txq[tc].count;
4274 f->mask = dev->tc_to_txq[tc].offset;
4283 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4284 * @adapter: board private structure to initialize
4286 * IOV doesn't actually use anything, so just NAK the
4287 * request for now and let the other queue routines
4288 * figure out what to do.
4290 static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4296 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
4297 * @adapter: board private structure to initialize
4299 * This is the top level queue allocation routine. The order here is very
4300 * important, starting with the "most" number of features turned on at once,
4301 * and ending with the smallest set of features. This way large combinations
4302 * can be allocated if they're turned on, and smaller combinations are the
4303 * fallthrough conditions.
4306 static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
4308 /* Start with base case */
4309 adapter->num_rx_queues = 1;
4310 adapter->num_tx_queues = 1;
4311 adapter->num_rx_pools = adapter->num_rx_queues;
4312 adapter->num_rx_queues_per_pool = 1;
4314 if (ixgbe_set_sriov_queues(adapter))
4317 #ifdef CONFIG_IXGBE_DCB
4318 if (ixgbe_set_dcb_queues(adapter))
4323 if (ixgbe_set_fcoe_queues(adapter))
4326 #endif /* IXGBE_FCOE */
4327 if (ixgbe_set_fdir_queues(adapter))
4330 if (ixgbe_set_rss_queues(adapter))
4333 /* fallback to base case */
4334 adapter->num_rx_queues = 1;
4335 adapter->num_tx_queues = 1;
4338 /* Notify the stack of the (possibly) reduced queue counts. */
4339 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
4340 return netif_set_real_num_rx_queues(adapter->netdev,
4341 adapter->num_rx_queues);
4344 static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
4347 int err, vector_threshold;
4349 /* We'll want at least 3 (vector_threshold):
4352 * 3) Other (Link Status Change, etc.)
4353 * 4) TCP Timer (optional)
4355 vector_threshold = MIN_MSIX_COUNT;
4357 /* The more we get, the more we will assign to Tx/Rx Cleanup
4358 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4359 * Right now, we simply care about how many we'll get; we'll
4360 * set them up later while requesting irq's.
4362 while (vectors >= vector_threshold) {
4363 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
4365 if (!err) /* Success in acquiring all requested vectors. */
4368 vectors = 0; /* Nasty failure, quit now */
4369 else /* err == number of vectors we should try again with */
4373 if (vectors < vector_threshold) {
4374 /* Can't allocate enough MSI-X interrupts? Oh well.
4375 * This just means we'll go with either a single MSI
4376 * vector or fall back to legacy interrupts.
4378 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4379 "Unable to allocate MSI-X interrupts\n");
4380 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4381 kfree(adapter->msix_entries);
4382 adapter->msix_entries = NULL;
4384 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
4386 * Adjust for only the vectors we'll use, which is minimum
4387 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4388 * vectors we were allocated.
4390 adapter->num_msix_vectors = min(vectors,
4391 adapter->max_msix_q_vectors + NON_Q_VECTORS);
4396 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
4397 * @adapter: board private structure to initialize
4399 * Cache the descriptor ring offsets for RSS to the assigned rings.
4402 static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
4406 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4409 for (i = 0; i < adapter->num_rx_queues; i++)
4410 adapter->rx_ring[i]->reg_idx = i;
4411 for (i = 0; i < adapter->num_tx_queues; i++)
4412 adapter->tx_ring[i]->reg_idx = i;
4417 #ifdef CONFIG_IXGBE_DCB
4419 /* ixgbe_get_first_reg_idx - Return first register index associated with ring */
4420 static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4421 unsigned int *tx, unsigned int *rx)
4423 struct net_device *dev = adapter->netdev;
4424 struct ixgbe_hw *hw = &adapter->hw;
4425 u8 num_tcs = netdev_get_num_tc(dev);
4430 switch (hw->mac.type) {
4431 case ixgbe_mac_82598EB:
4435 case ixgbe_mac_82599EB:
4436 case ixgbe_mac_X540:
4441 } else if (tc < 5) {
4442 *tx = ((tc + 2) << 4);
4444 } else if (tc < num_tcs) {
4445 *tx = ((tc + 8) << 3);
4474 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4475 * @adapter: board private structure to initialize
4477 * Cache the descriptor ring offsets for DCB to the assigned rings.
4480 static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4482 struct net_device *dev = adapter->netdev;
4484 u8 num_tcs = netdev_get_num_tc(dev);
4489 for (i = 0, k = 0; i < num_tcs; i++) {
4490 unsigned int tx_s, rx_s;
4491 u16 count = dev->tc_to_txq[i].count;
4493 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4494 for (j = 0; j < count; j++, k++) {
4495 adapter->tx_ring[k]->reg_idx = tx_s + j;
4496 adapter->rx_ring[k]->reg_idx = rx_s + j;
4497 adapter->tx_ring[k]->dcb_tc = i;
4498 adapter->rx_ring[k]->dcb_tc = i;
4507 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4508 * @adapter: board private structure to initialize
4510 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4513 static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
4518 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4519 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
4520 for (i = 0; i < adapter->num_rx_queues; i++)
4521 adapter->rx_ring[i]->reg_idx = i;
4522 for (i = 0; i < adapter->num_tx_queues; i++)
4523 adapter->tx_ring[i]->reg_idx = i;
4532 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4533 * @adapter: board private structure to initialize
4535 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4538 static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4540 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4542 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
4544 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4547 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4548 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
4549 ixgbe_cache_ring_fdir(adapter);
4551 ixgbe_cache_ring_rss(adapter);
4553 fcoe_rx_i = f->mask;
4554 fcoe_tx_i = f->mask;
4556 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4557 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4558 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4563 #endif /* IXGBE_FCOE */
4565 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4566 * @adapter: board private structure to initialize
4568 * SR-IOV doesn't use any descriptor rings but changes the default if
4569 * no other mapping is used.
4572 static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4574 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4575 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
4576 if (adapter->num_vfs)
4583 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4584 * @adapter: board private structure to initialize
4586 * Once we know the feature-set enabled for the device, we'll cache
4587 * the register offset the descriptor ring is assigned to.
4589 * Note, the order the various feature calls is important. It must start with
4590 * the "most" features enabled at the same time, then trickle down to the
4591 * least amount of features turned on at once.
4593 static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4595 /* start with default case */
4596 adapter->rx_ring[0]->reg_idx = 0;
4597 adapter->tx_ring[0]->reg_idx = 0;
4599 if (ixgbe_cache_ring_sriov(adapter))
4602 #ifdef CONFIG_IXGBE_DCB
4603 if (ixgbe_cache_ring_dcb(adapter))
4608 if (ixgbe_cache_ring_fcoe(adapter))
4610 #endif /* IXGBE_FCOE */
4612 if (ixgbe_cache_ring_fdir(adapter))
4615 if (ixgbe_cache_ring_rss(adapter))
4620 * ixgbe_alloc_queues - Allocate memory for all rings
4621 * @adapter: board private structure to initialize
4623 * We allocate one ring per queue at run-time since we don't know the
4624 * number of queues at compile-time. The polling_netdev array is
4625 * intended for Multiqueue, but should work fine with a single queue.
4627 static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
4629 int rx = 0, tx = 0, nid = adapter->node;
4631 if (nid < 0 || !node_online(nid))
4632 nid = first_online_node;
4634 for (; tx < adapter->num_tx_queues; tx++) {
4635 struct ixgbe_ring *ring;
4637 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
4639 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
4641 goto err_allocation;
4642 ring->count = adapter->tx_ring_count;
4643 ring->queue_index = tx;
4644 ring->numa_node = nid;
4645 ring->dev = &adapter->pdev->dev;
4646 ring->netdev = adapter->netdev;
4648 adapter->tx_ring[tx] = ring;
4651 for (; rx < adapter->num_rx_queues; rx++) {
4652 struct ixgbe_ring *ring;
4654 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
4656 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
4658 goto err_allocation;
4659 ring->count = adapter->rx_ring_count;
4660 ring->queue_index = rx;
4661 ring->numa_node = nid;
4662 ring->dev = &adapter->pdev->dev;
4663 ring->netdev = adapter->netdev;
4665 adapter->rx_ring[rx] = ring;
4668 ixgbe_cache_ring_register(adapter);
4674 kfree(adapter->tx_ring[--tx]);
4677 kfree(adapter->rx_ring[--rx]);
4682 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4683 * @adapter: board private structure to initialize
4685 * Attempt to configure the interrupts using the best available
4686 * capabilities of the hardware and the kernel.
4688 static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
4690 struct ixgbe_hw *hw = &adapter->hw;
4692 int vector, v_budget;
4695 * It's easy to be greedy for MSI-X vectors, but it really
4696 * doesn't do us much good if we have a lot more vectors
4697 * than CPU's. So let's be conservative and only ask for
4698 * (roughly) the same number of vectors as there are CPU's.
4700 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
4701 (int)num_online_cpus()) + NON_Q_VECTORS;
4704 * At the same time, hardware can only support a maximum of
4705 * hw.mac->max_msix_vectors vectors. With features
4706 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4707 * descriptor queues supported by our device. Thus, we cap it off in
4708 * those rare cases where the cpu count also exceeds our vector limit.
4710 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
4712 /* A failure in MSI-X entry allocation isn't fatal, but it does
4713 * mean we disable MSI-X capabilities of the adapter. */
4714 adapter->msix_entries = kcalloc(v_budget,
4715 sizeof(struct msix_entry), GFP_KERNEL);
4716 if (adapter->msix_entries) {
4717 for (vector = 0; vector < v_budget; vector++)
4718 adapter->msix_entries[vector].entry = vector;
4720 ixgbe_acquire_msix_vectors(adapter, v_budget);
4722 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4726 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4727 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
4728 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
4730 "ATR is not supported while multiple "
4731 "queues are disabled. Disabling Flow Director\n");
4733 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4734 adapter->atr_sample_rate = 0;
4735 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4736 ixgbe_disable_sriov(adapter);
4738 err = ixgbe_set_num_queues(adapter);
4742 err = pci_enable_msi(adapter->pdev);
4744 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4746 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4747 "Unable to allocate MSI interrupt, "
4748 "falling back to legacy. Error: %d\n", err);
4758 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4759 * @adapter: board private structure to initialize
4761 * We allocate one q_vector per queue interrupt. If allocation fails we
4764 static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4766 int v_idx, num_q_vectors;
4767 struct ixgbe_q_vector *q_vector;
4769 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4770 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
4774 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
4775 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
4776 GFP_KERNEL, adapter->node);
4778 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
4783 q_vector->adapter = adapter;
4784 q_vector->v_idx = v_idx;
4786 /* Allocate the affinity_hint cpumask, configure the mask */
4787 if (!alloc_cpumask_var(&q_vector->affinity_mask, GFP_KERNEL))
4789 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
4790 netif_napi_add(adapter->netdev, &q_vector->napi,
4792 adapter->q_vector[v_idx] = q_vector;
4800 q_vector = adapter->q_vector[v_idx];
4801 netif_napi_del(&q_vector->napi);
4802 free_cpumask_var(q_vector->affinity_mask);
4804 adapter->q_vector[v_idx] = NULL;
4810 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
4811 * @adapter: board private structure to initialize
4813 * This function frees the memory allocated to the q_vectors. In addition if
4814 * NAPI is enabled it will delete any references to the NAPI struct prior
4815 * to freeing the q_vector.
4817 static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
4819 int v_idx, num_q_vectors;
4821 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4822 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
4826 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
4827 struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx];
4828 adapter->q_vector[v_idx] = NULL;
4829 netif_napi_del(&q_vector->napi);
4830 free_cpumask_var(q_vector->affinity_mask);
4835 static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
4837 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4838 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4839 pci_disable_msix(adapter->pdev);
4840 kfree(adapter->msix_entries);
4841 adapter->msix_entries = NULL;
4842 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
4843 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
4844 pci_disable_msi(adapter->pdev);
4849 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
4850 * @adapter: board private structure to initialize
4852 * We determine which interrupt scheme to use based on...
4853 * - Kernel support (MSI, MSI-X)
4854 * - which can be user-defined (via MODULE_PARAM)
4855 * - Hardware queue count (num_*_queues)
4856 * - defined by miscellaneous hardware support/features (RSS, etc.)
4858 int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
4862 /* Number of supported queues */
4863 err = ixgbe_set_num_queues(adapter);
4867 err = ixgbe_set_interrupt_capability(adapter);
4869 e_dev_err("Unable to setup interrupt capabilities\n");
4870 goto err_set_interrupt;
4873 err = ixgbe_alloc_q_vectors(adapter);
4875 e_dev_err("Unable to allocate memory for queue vectors\n");
4876 goto err_alloc_q_vectors;
4879 err = ixgbe_alloc_queues(adapter);
4881 e_dev_err("Unable to allocate memory for queues\n");
4882 goto err_alloc_queues;
4885 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
4886 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
4887 adapter->num_rx_queues, adapter->num_tx_queues);
4889 set_bit(__IXGBE_DOWN, &adapter->state);
4894 ixgbe_free_q_vectors(adapter);
4895 err_alloc_q_vectors:
4896 ixgbe_reset_interrupt_capability(adapter);
4902 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
4903 * @adapter: board private structure to clear interrupt scheme on
4905 * We go through and clear interrupt specific resources and reset the structure
4906 * to pre-load conditions
4908 void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
4912 for (i = 0; i < adapter->num_tx_queues; i++) {
4913 kfree(adapter->tx_ring[i]);
4914 adapter->tx_ring[i] = NULL;
4916 for (i = 0; i < adapter->num_rx_queues; i++) {
4917 struct ixgbe_ring *ring = adapter->rx_ring[i];
4919 /* ixgbe_get_stats64() might access this ring, we must wait
4920 * a grace period before freeing it.
4922 kfree_rcu(ring, rcu);
4923 adapter->rx_ring[i] = NULL;
4926 adapter->num_tx_queues = 0;
4927 adapter->num_rx_queues = 0;
4929 ixgbe_free_q_vectors(adapter);
4930 ixgbe_reset_interrupt_capability(adapter);
4934 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4935 * @adapter: board private structure to initialize
4937 * ixgbe_sw_init initializes the Adapter private data structure.
4938 * Fields are initialized based on PCI device information and
4939 * OS network device settings (MTU size).
4941 static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
4943 struct ixgbe_hw *hw = &adapter->hw;
4944 struct pci_dev *pdev = adapter->pdev;
4946 #ifdef CONFIG_IXGBE_DCB
4948 struct tc_configuration *tc;
4951 /* PCI config space info */
4953 hw->vendor_id = pdev->vendor;
4954 hw->device_id = pdev->device;
4955 hw->revision_id = pdev->revision;
4956 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4957 hw->subsystem_device_id = pdev->subsystem_device;
4959 /* Set capability flags */
4960 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
4961 adapter->ring_feature[RING_F_RSS].indices = rss;
4962 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
4963 switch (hw->mac.type) {
4964 case ixgbe_mac_82598EB:
4965 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4966 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
4967 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
4969 case ixgbe_mac_X540:
4970 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
4971 case ixgbe_mac_82599EB:
4972 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
4973 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4974 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
4975 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4976 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
4977 /* Flow Director hash filters enabled */
4978 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
4979 adapter->atr_sample_rate = 20;
4980 adapter->ring_feature[RING_F_FDIR].indices =
4981 IXGBE_MAX_FDIR_INDICES;
4982 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
4984 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4985 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
4986 adapter->ring_feature[RING_F_FCOE].indices = 0;
4987 #ifdef CONFIG_IXGBE_DCB
4988 /* Default traffic class to use for FCoE */
4989 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
4991 #endif /* IXGBE_FCOE */
4997 /* n-tuple support exists, always init our spinlock */
4998 spin_lock_init(&adapter->fdir_perfect_lock);
5000 #ifdef CONFIG_IXGBE_DCB
5001 switch (hw->mac.type) {
5002 case ixgbe_mac_X540:
5003 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5004 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5007 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5008 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5012 /* Configure DCB traffic classes */
5013 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5014 tc = &adapter->dcb_cfg.tc_config[j];
5015 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5016 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5017 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5018 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5019 tc->dcb_pfc = pfc_disabled;
5022 /* Initialize default user to priority mapping, UPx->TC0 */
5023 tc = &adapter->dcb_cfg.tc_config[0];
5024 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5025 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5027 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5028 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5029 adapter->dcb_cfg.pfc_mode_enable = false;
5030 adapter->dcb_set_bitmap = 0x00;
5031 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
5032 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
5037 /* default flow control settings */
5038 hw->fc.requested_mode = ixgbe_fc_full;
5039 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
5041 adapter->last_lfc_mode = hw->fc.current_mode;
5043 ixgbe_pbthresh_setup(adapter);
5044 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5045 hw->fc.send_xon = true;
5046 hw->fc.disable_fc_autoneg = false;
5048 /* enable itr by default in dynamic mode */
5049 adapter->rx_itr_setting = 1;
5050 adapter->tx_itr_setting = 1;
5052 /* set defaults for eitr in MegaBytes */
5053 adapter->eitr_low = 10;
5054 adapter->eitr_high = 20;
5056 /* set default ring sizes */
5057 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5058 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5060 /* set default work limits */
5061 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
5063 /* initialize eeprom parameters */
5064 if (ixgbe_init_eeprom_params_generic(hw)) {
5065 e_dev_err("EEPROM initialization failed\n");
5069 /* enable rx csum by default */
5070 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5072 /* get assigned NUMA node */
5073 adapter->node = dev_to_node(&pdev->dev);
5075 set_bit(__IXGBE_DOWN, &adapter->state);
5081 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
5082 * @tx_ring: tx descriptor ring (for a specific queue) to setup
5084 * Return 0 on success, negative on failure
5086 int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
5088 struct device *dev = tx_ring->dev;
5091 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
5092 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
5093 if (!tx_ring->tx_buffer_info)
5094 tx_ring->tx_buffer_info = vzalloc(size);
5095 if (!tx_ring->tx_buffer_info)
5098 /* round up to nearest 4K */
5099 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
5100 tx_ring->size = ALIGN(tx_ring->size, 4096);
5102 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5103 &tx_ring->dma, GFP_KERNEL);
5107 tx_ring->next_to_use = 0;
5108 tx_ring->next_to_clean = 0;
5112 vfree(tx_ring->tx_buffer_info);
5113 tx_ring->tx_buffer_info = NULL;
5114 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
5119 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5120 * @adapter: board private structure
5122 * If this function returns with an error, then it's possible one or
5123 * more of the rings is populated (while the rest are not). It is the
5124 * callers duty to clean those orphaned rings.
5126 * Return 0 on success, negative on failure
5128 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5132 for (i = 0; i < adapter->num_tx_queues; i++) {
5133 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
5136 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
5144 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
5145 * @rx_ring: rx descriptor ring (for a specific queue) to setup
5147 * Returns 0 on success, negative on failure
5149 int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
5151 struct device *dev = rx_ring->dev;
5154 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
5155 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
5156 if (!rx_ring->rx_buffer_info)
5157 rx_ring->rx_buffer_info = vzalloc(size);
5158 if (!rx_ring->rx_buffer_info)
5161 /* Round up to nearest 4K */
5162 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5163 rx_ring->size = ALIGN(rx_ring->size, 4096);
5165 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5166 &rx_ring->dma, GFP_KERNEL);
5171 rx_ring->next_to_clean = 0;
5172 rx_ring->next_to_use = 0;
5176 vfree(rx_ring->rx_buffer_info);
5177 rx_ring->rx_buffer_info = NULL;
5178 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
5183 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5184 * @adapter: board private structure
5186 * If this function returns with an error, then it's possible one or
5187 * more of the rings is populated (while the rest are not). It is the
5188 * callers duty to clean those orphaned rings.
5190 * Return 0 on success, negative on failure
5192 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5196 for (i = 0; i < adapter->num_rx_queues; i++) {
5197 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
5200 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
5208 * ixgbe_free_tx_resources - Free Tx Resources per Queue
5209 * @tx_ring: Tx descriptor ring for a specific queue
5211 * Free all transmit software resources
5213 void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
5215 ixgbe_clean_tx_ring(tx_ring);
5217 vfree(tx_ring->tx_buffer_info);
5218 tx_ring->tx_buffer_info = NULL;
5220 /* if not set, then don't free */
5224 dma_free_coherent(tx_ring->dev, tx_ring->size,
5225 tx_ring->desc, tx_ring->dma);
5227 tx_ring->desc = NULL;
5231 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5232 * @adapter: board private structure
5234 * Free all transmit software resources
5236 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5240 for (i = 0; i < adapter->num_tx_queues; i++)
5241 if (adapter->tx_ring[i]->desc)
5242 ixgbe_free_tx_resources(adapter->tx_ring[i]);
5246 * ixgbe_free_rx_resources - Free Rx Resources
5247 * @rx_ring: ring to clean the resources from
5249 * Free all receive software resources
5251 void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
5253 ixgbe_clean_rx_ring(rx_ring);
5255 vfree(rx_ring->rx_buffer_info);
5256 rx_ring->rx_buffer_info = NULL;
5258 /* if not set, then don't free */
5262 dma_free_coherent(rx_ring->dev, rx_ring->size,
5263 rx_ring->desc, rx_ring->dma);
5265 rx_ring->desc = NULL;
5269 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5270 * @adapter: board private structure
5272 * Free all receive software resources
5274 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5278 for (i = 0; i < adapter->num_rx_queues; i++)
5279 if (adapter->rx_ring[i]->desc)
5280 ixgbe_free_rx_resources(adapter->rx_ring[i]);
5284 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5285 * @netdev: network interface device structure
5286 * @new_mtu: new value for maximum frame size
5288 * Returns 0 on success, negative on failure
5290 static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5292 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5293 struct ixgbe_hw *hw = &adapter->hw;
5294 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5296 /* MTU < 68 is an error and causes problems on some kernels */
5297 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5298 hw->mac.type != ixgbe_mac_X540) {
5299 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5302 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5306 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5307 /* must set new MTU before calling down or up */
5308 netdev->mtu = new_mtu;
5310 if (netif_running(netdev))
5311 ixgbe_reinit_locked(adapter);
5317 * ixgbe_open - Called when a network interface is made active
5318 * @netdev: network interface device structure
5320 * Returns 0 on success, negative value on failure
5322 * The open entry point is called when a network interface is made
5323 * active by the system (IFF_UP). At this point all resources needed
5324 * for transmit and receive operations are allocated, the interrupt
5325 * handler is registered with the OS, the watchdog timer is started,
5326 * and the stack is notified that the interface is ready.
5328 static int ixgbe_open(struct net_device *netdev)
5330 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5333 /* disallow open during test */
5334 if (test_bit(__IXGBE_TESTING, &adapter->state))
5337 netif_carrier_off(netdev);
5339 /* allocate transmit descriptors */
5340 err = ixgbe_setup_all_tx_resources(adapter);
5344 /* allocate receive descriptors */
5345 err = ixgbe_setup_all_rx_resources(adapter);
5349 ixgbe_configure(adapter);
5351 err = ixgbe_request_irq(adapter);
5355 ixgbe_up_complete(adapter);
5361 ixgbe_free_all_rx_resources(adapter);
5363 ixgbe_free_all_tx_resources(adapter);
5364 ixgbe_reset(adapter);
5370 * ixgbe_close - Disables a network interface
5371 * @netdev: network interface device structure
5373 * Returns 0, this is not allowed to fail
5375 * The close entry point is called when an interface is de-activated
5376 * by the OS. The hardware is still under the drivers control, but
5377 * needs to be disabled. A global MAC reset is issued to stop the
5378 * hardware, and all transmit and receive resources are freed.
5380 static int ixgbe_close(struct net_device *netdev)
5382 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5384 ixgbe_down(adapter);
5385 ixgbe_free_irq(adapter);
5387 ixgbe_fdir_filter_exit(adapter);
5389 ixgbe_free_all_tx_resources(adapter);
5390 ixgbe_free_all_rx_resources(adapter);
5392 ixgbe_release_hw_control(adapter);
5398 static int ixgbe_resume(struct pci_dev *pdev)
5400 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5401 struct net_device *netdev = adapter->netdev;
5404 pci_set_power_state(pdev, PCI_D0);
5405 pci_restore_state(pdev);
5407 * pci_restore_state clears dev->state_saved so call
5408 * pci_save_state to restore it.
5410 pci_save_state(pdev);
5412 err = pci_enable_device_mem(pdev);
5414 e_dev_err("Cannot enable PCI device from suspend\n");
5417 pci_set_master(pdev);
5419 pci_wake_from_d3(pdev, false);
5422 err = ixgbe_init_interrupt_scheme(adapter);
5425 e_dev_err("Cannot initialize interrupts for device\n");
5429 ixgbe_reset(adapter);
5431 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5433 if (netif_running(netdev)) {
5434 err = ixgbe_open(netdev);
5439 netif_device_attach(netdev);
5443 #endif /* CONFIG_PM */
5445 static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
5447 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5448 struct net_device *netdev = adapter->netdev;
5449 struct ixgbe_hw *hw = &adapter->hw;
5451 u32 wufc = adapter->wol;
5456 netif_device_detach(netdev);
5458 if (netif_running(netdev)) {
5459 ixgbe_down(adapter);
5460 ixgbe_free_irq(adapter);
5461 ixgbe_free_all_tx_resources(adapter);
5462 ixgbe_free_all_rx_resources(adapter);
5465 ixgbe_clear_interrupt_scheme(adapter);
5467 kfree(adapter->ixgbe_ieee_pfc);
5468 kfree(adapter->ixgbe_ieee_ets);
5472 retval = pci_save_state(pdev);
5478 ixgbe_set_rx_mode(netdev);
5480 /* turn on all-multi mode if wake on multicast is enabled */
5481 if (wufc & IXGBE_WUFC_MC) {
5482 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5483 fctrl |= IXGBE_FCTRL_MPE;
5484 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5487 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5488 ctrl |= IXGBE_CTRL_GIO_DIS;
5489 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5491 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5493 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5494 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5497 switch (hw->mac.type) {
5498 case ixgbe_mac_82598EB:
5499 pci_wake_from_d3(pdev, false);
5501 case ixgbe_mac_82599EB:
5502 case ixgbe_mac_X540:
5503 pci_wake_from_d3(pdev, !!wufc);
5509 *enable_wake = !!wufc;
5511 ixgbe_release_hw_control(adapter);
5513 pci_disable_device(pdev);
5519 static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5524 retval = __ixgbe_shutdown(pdev, &wake);
5529 pci_prepare_to_sleep(pdev);
5531 pci_wake_from_d3(pdev, false);
5532 pci_set_power_state(pdev, PCI_D3hot);
5537 #endif /* CONFIG_PM */
5539 static void ixgbe_shutdown(struct pci_dev *pdev)
5543 __ixgbe_shutdown(pdev, &wake);
5545 if (system_state == SYSTEM_POWER_OFF) {
5546 pci_wake_from_d3(pdev, wake);
5547 pci_set_power_state(pdev, PCI_D3hot);
5552 * ixgbe_update_stats - Update the board statistics counters.
5553 * @adapter: board private structure
5555 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5557 struct net_device *netdev = adapter->netdev;
5558 struct ixgbe_hw *hw = &adapter->hw;
5559 struct ixgbe_hw_stats *hwstats = &adapter->stats;
5561 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
5562 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5563 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5564 u64 bytes = 0, packets = 0;
5566 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5568 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
5569 #endif /* IXGBE_FCOE */
5571 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5572 test_bit(__IXGBE_RESETTING, &adapter->state))
5575 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
5578 for (i = 0; i < 16; i++)
5579 adapter->hw_rx_no_dma_resources +=
5580 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
5581 for (i = 0; i < adapter->num_rx_queues; i++) {
5582 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5583 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
5585 adapter->rsc_total_count = rsc_count;
5586 adapter->rsc_total_flush = rsc_flush;
5589 for (i = 0; i < adapter->num_rx_queues; i++) {
5590 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5591 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5592 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5593 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5594 bytes += rx_ring->stats.bytes;
5595 packets += rx_ring->stats.packets;
5597 adapter->non_eop_descs = non_eop_descs;
5598 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5599 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5600 netdev->stats.rx_bytes = bytes;
5601 netdev->stats.rx_packets = packets;
5605 /* gather some stats to the adapter struct that are per queue */
5606 for (i = 0; i < adapter->num_tx_queues; i++) {
5607 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5608 restart_queue += tx_ring->tx_stats.restart_queue;
5609 tx_busy += tx_ring->tx_stats.tx_busy;
5610 bytes += tx_ring->stats.bytes;
5611 packets += tx_ring->stats.packets;
5613 adapter->restart_queue = restart_queue;
5614 adapter->tx_busy = tx_busy;
5615 netdev->stats.tx_bytes = bytes;
5616 netdev->stats.tx_packets = packets;
5618 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
5620 /* 8 register reads */
5621 for (i = 0; i < 8; i++) {
5622 /* for packet buffers not used, the register should read 0 */
5623 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5625 hwstats->mpc[i] += mpc;
5626 total_mpc += hwstats->mpc[i];
5627 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5628 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
5629 switch (hw->mac.type) {
5630 case ixgbe_mac_82598EB:
5631 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5632 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5633 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
5634 hwstats->pxonrxc[i] +=
5635 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
5637 case ixgbe_mac_82599EB:
5638 case ixgbe_mac_X540:
5639 hwstats->pxonrxc[i] +=
5640 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
5647 /*16 register reads */
5648 for (i = 0; i < 16; i++) {
5649 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5650 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5651 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5652 (hw->mac.type == ixgbe_mac_X540)) {
5653 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5654 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5655 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5656 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5660 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
5661 /* work around hardware counting issue */
5662 hwstats->gprc -= missed_rx;
5664 ixgbe_update_xoff_received(adapter);
5666 /* 82598 hardware only has a 32 bit counter in the high register */
5667 switch (hw->mac.type) {
5668 case ixgbe_mac_82598EB:
5669 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
5670 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5671 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5672 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5674 case ixgbe_mac_X540:
5675 /* OS2BMC stats are X540 only*/
5676 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5677 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5678 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5679 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5680 case ixgbe_mac_82599EB:
5681 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
5682 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
5683 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
5684 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
5685 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
5686 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
5687 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
5688 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5689 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
5691 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5692 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5693 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5694 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5695 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5696 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
5697 /* Add up per cpu counters for total ddp aloc fail */
5698 if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
5699 for_each_possible_cpu(cpu) {
5700 fcoe_noddp_counts_sum +=
5701 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
5702 fcoe_noddp_ext_buff_counts_sum +=
5704 pcpu_noddp_ext_buff, cpu);
5707 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
5708 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
5709 #endif /* IXGBE_FCOE */
5714 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
5715 hwstats->bprc += bprc;
5716 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
5717 if (hw->mac.type == ixgbe_mac_82598EB)
5718 hwstats->mprc -= bprc;
5719 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5720 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5721 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5722 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5723 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5724 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5725 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5726 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
5727 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
5728 hwstats->lxontxc += lxon;
5729 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
5730 hwstats->lxofftxc += lxoff;
5731 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5732 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
5734 * 82598 errata - tx of flow control packets is included in tx counters
5736 xon_off_tot = lxon + lxoff;
5737 hwstats->gptc -= xon_off_tot;
5738 hwstats->mptc -= xon_off_tot;
5739 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5740 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5741 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5742 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5743 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5744 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5745 hwstats->ptc64 -= xon_off_tot;
5746 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5747 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5748 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5749 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5750 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5751 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
5753 /* Fill out the OS statistics structure */
5754 netdev->stats.multicast = hwstats->mprc;
5757 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
5758 netdev->stats.rx_dropped = 0;
5759 netdev->stats.rx_length_errors = hwstats->rlec;
5760 netdev->stats.rx_crc_errors = hwstats->crcerrs;
5761 netdev->stats.rx_missed_errors = total_mpc;
5765 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5766 * @adapter - pointer to the device adapter structure
5768 static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
5770 struct ixgbe_hw *hw = &adapter->hw;
5773 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5776 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5778 /* if interface is down do nothing */
5779 if (test_bit(__IXGBE_DOWN, &adapter->state))
5782 /* do nothing if we are not using signature filters */
5783 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5786 adapter->fdir_overflow++;
5788 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5789 for (i = 0; i < adapter->num_tx_queues; i++)
5790 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
5791 &(adapter->tx_ring[i]->state));
5792 /* re-enable flow director interrupts */
5793 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
5795 e_err(probe, "failed to finish FDIR re-initialization, "
5796 "ignored adding FDIR ATR filters\n");
5801 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5802 * @adapter - pointer to the device adapter structure
5804 * This function serves two purposes. First it strobes the interrupt lines
5805 * in order to make certain interrupts are occuring. Secondly it sets the
5806 * bits needed to check for TX hangs. As a result we should immediately
5807 * determine if a hang has occured.
5809 static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5811 struct ixgbe_hw *hw = &adapter->hw;
5815 /* If we're down or resetting, just bail */
5816 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5817 test_bit(__IXGBE_RESETTING, &adapter->state))
5820 /* Force detection of hung controller */
5821 if (netif_carrier_ok(adapter->netdev)) {
5822 for (i = 0; i < adapter->num_tx_queues; i++)
5823 set_check_for_tx_hang(adapter->tx_ring[i]);
5826 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
5828 * for legacy and MSI interrupts don't set any bits
5829 * that are enabled for EIAM, because this operation
5830 * would set *both* EIMS and EICS for any bit in EIAM
5832 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5833 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
5835 /* get one bit for every active tx/rx interrupt vector */
5836 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5837 struct ixgbe_q_vector *qv = adapter->q_vector[i];
5838 if (qv->rx.ring || qv->tx.ring)
5839 eics |= ((u64)1 << i);
5843 /* Cause software interrupt to ensure rings are cleaned */
5844 ixgbe_irq_rearm_queues(adapter, eics);
5849 * ixgbe_watchdog_update_link - update the link status
5850 * @adapter - pointer to the device adapter structure
5851 * @link_speed - pointer to a u32 to store the link_speed
5853 static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
5855 struct ixgbe_hw *hw = &adapter->hw;
5856 u32 link_speed = adapter->link_speed;
5857 bool link_up = adapter->link_up;
5860 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5863 if (hw->mac.ops.check_link) {
5864 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
5866 /* always assume link is up, if no check link function */
5867 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5871 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5872 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
5873 hw->mac.ops.fc_enable(hw, i);
5875 hw->mac.ops.fc_enable(hw, 0);
5880 time_after(jiffies, (adapter->link_check_timeout +
5881 IXGBE_TRY_LINK_TIMEOUT))) {
5882 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5883 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5884 IXGBE_WRITE_FLUSH(hw);
5887 adapter->link_up = link_up;
5888 adapter->link_speed = link_speed;
5892 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5893 * print link up message
5894 * @adapter - pointer to the device adapter structure
5896 static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5898 struct net_device *netdev = adapter->netdev;
5899 struct ixgbe_hw *hw = &adapter->hw;
5900 u32 link_speed = adapter->link_speed;
5901 bool flow_rx, flow_tx;
5903 /* only continue if link was previously down */
5904 if (netif_carrier_ok(netdev))
5907 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5909 switch (hw->mac.type) {
5910 case ixgbe_mac_82598EB: {
5911 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5912 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5913 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5914 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5917 case ixgbe_mac_X540:
5918 case ixgbe_mac_82599EB: {
5919 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5920 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5921 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5922 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5930 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5931 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5933 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5935 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5938 ((flow_rx && flow_tx) ? "RX/TX" :
5940 (flow_tx ? "TX" : "None"))));
5942 netif_carrier_on(netdev);
5943 ixgbe_check_vf_rate_limit(adapter);
5947 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5948 * print link down message
5949 * @adapter - pointer to the adapter structure
5951 static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
5953 struct net_device *netdev = adapter->netdev;
5954 struct ixgbe_hw *hw = &adapter->hw;
5956 adapter->link_up = false;
5957 adapter->link_speed = 0;
5959 /* only continue if link was up previously */
5960 if (!netif_carrier_ok(netdev))
5963 /* poll for SFP+ cable when link is down */
5964 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5965 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5967 e_info(drv, "NIC Link is Down\n");
5968 netif_carrier_off(netdev);
5972 * ixgbe_watchdog_flush_tx - flush queues on link down
5973 * @adapter - pointer to the device adapter structure
5975 static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5978 int some_tx_pending = 0;
5980 if (!netif_carrier_ok(adapter->netdev)) {
5981 for (i = 0; i < adapter->num_tx_queues; i++) {
5982 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5983 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5984 some_tx_pending = 1;
5989 if (some_tx_pending) {
5990 /* We've lost link, so the controller stops DMA,
5991 * but we've got queued Tx work that's never going
5992 * to get done, so reset controller to flush Tx.
5993 * (Do the reset outside of interrupt context).
5995 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
6000 static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6004 /* Do not perform spoof check for 82598 */
6005 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6008 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6011 * ssvpc register is cleared on read, if zero then no
6012 * spoofed packets in the last interval.
6017 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6021 * ixgbe_watchdog_subtask - check and bring link up
6022 * @adapter - pointer to the device adapter structure
6024 static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
6026 /* if interface is down do nothing */
6027 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6028 test_bit(__IXGBE_RESETTING, &adapter->state))
6031 ixgbe_watchdog_update_link(adapter);
6033 if (adapter->link_up)
6034 ixgbe_watchdog_link_is_up(adapter);
6036 ixgbe_watchdog_link_is_down(adapter);
6038 ixgbe_spoof_check(adapter);
6039 ixgbe_update_stats(adapter);
6041 ixgbe_watchdog_flush_tx(adapter);
6045 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6046 * @adapter - the ixgbe adapter structure
6048 static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6050 struct ixgbe_hw *hw = &adapter->hw;
6053 /* not searching for SFP so there is nothing to do here */
6054 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6055 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6058 /* someone else is in init, wait until next service event */
6059 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6062 err = hw->phy.ops.identify_sfp(hw);
6063 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6066 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6067 /* If no cable is present, then we need to reset
6068 * the next time we find a good cable. */
6069 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6076 /* exit if reset not needed */
6077 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6080 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6083 * A module may be identified correctly, but the EEPROM may not have
6084 * support for that module. setup_sfp() will fail in that case, so
6085 * we should not allow that module to load.
6087 if (hw->mac.type == ixgbe_mac_82598EB)
6088 err = hw->phy.ops.reset(hw);
6090 err = hw->mac.ops.setup_sfp(hw);
6092 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6095 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6096 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6099 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6101 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6102 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6103 e_dev_err("failed to initialize because an unsupported "
6104 "SFP+ module type was detected.\n");
6105 e_dev_err("Reload the driver after installing a "
6106 "supported module.\n");
6107 unregister_netdev(adapter->netdev);
6112 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6113 * @adapter - the ixgbe adapter structure
6115 static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6117 struct ixgbe_hw *hw = &adapter->hw;
6121 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6124 /* someone else is in init, wait until next service event */
6125 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6128 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6130 autoneg = hw->phy.autoneg_advertised;
6131 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6132 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6133 if (hw->mac.ops.setup_link)
6134 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6136 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6137 adapter->link_check_timeout = jiffies;
6138 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6141 #ifdef CONFIG_PCI_IOV
6142 static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6145 struct ixgbe_hw *hw = &adapter->hw;
6146 struct net_device *netdev = adapter->netdev;
6150 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6151 if (gpc) /* If incrementing then no need for the check below */
6154 * Check to see if a bad DMA write target from an errant or
6155 * malicious VF has caused a PCIe error. If so then we can
6156 * issue a VFLR to the offending VF(s) and then resume without
6157 * requesting a full slot reset.
6160 for (vf = 0; vf < adapter->num_vfs; vf++) {
6161 ciaa = (vf << 16) | 0x80000000;
6162 /* 32 bit read so align, we really want status at offset 6 */
6163 ciaa |= PCI_COMMAND;
6164 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6165 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
6167 /* disable debug mode asap after reading data */
6168 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6169 /* Get the upper 16 bits which will be the PCI status reg */
6171 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
6172 netdev_err(netdev, "VF %d Hung DMA\n", vf);
6174 ciaa = (vf << 16) | 0x80000000;
6176 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6177 ciad = 0x00008000; /* VFLR */
6178 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
6180 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6187 * ixgbe_service_timer - Timer Call-back
6188 * @data: pointer to adapter cast into an unsigned long
6190 static void ixgbe_service_timer(unsigned long data)
6192 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6193 unsigned long next_event_offset;
6196 #ifdef CONFIG_PCI_IOV
6200 * don't bother with SR-IOV VF DMA hang check if there are
6201 * no VFs or the link is down
6203 if (!adapter->num_vfs ||
6204 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) {
6206 goto normal_timer_service;
6209 /* If we have VFs allocated then we must check for DMA hangs */
6210 ixgbe_check_for_bad_vf(adapter);
6211 next_event_offset = HZ / 50;
6212 adapter->timer_event_accumulator++;
6214 if (adapter->timer_event_accumulator >= 100) {
6216 adapter->timer_event_accumulator = 0;
6219 goto schedule_event;
6221 normal_timer_service:
6223 /* poll faster when waiting for link */
6224 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6225 next_event_offset = HZ / 10;
6227 next_event_offset = HZ * 2;
6229 #ifdef CONFIG_PCI_IOV
6232 /* Reset the timer */
6233 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6236 ixgbe_service_event_schedule(adapter);
6239 static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6241 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6244 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6246 /* If we're already down or resetting, just bail */
6247 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6248 test_bit(__IXGBE_RESETTING, &adapter->state))
6251 ixgbe_dump(adapter);
6252 netdev_err(adapter->netdev, "Reset adapter\n");
6253 adapter->tx_timeout_count++;
6255 ixgbe_reinit_locked(adapter);
6259 * ixgbe_service_task - manages and runs subtasks
6260 * @work: pointer to work_struct containing our data
6262 static void ixgbe_service_task(struct work_struct *work)
6264 struct ixgbe_adapter *adapter = container_of(work,
6265 struct ixgbe_adapter,
6268 ixgbe_reset_subtask(adapter);
6269 ixgbe_sfp_detection_subtask(adapter);
6270 ixgbe_sfp_link_config_subtask(adapter);
6271 ixgbe_check_overtemp_subtask(adapter);
6272 ixgbe_watchdog_subtask(adapter);
6273 ixgbe_fdir_reinit_subtask(adapter);
6274 ixgbe_check_hang_subtask(adapter);
6276 ixgbe_service_event_complete(adapter);
6279 void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6280 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
6282 struct ixgbe_adv_tx_context_desc *context_desc;
6283 u16 i = tx_ring->next_to_use;
6285 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
6288 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6290 /* set bits to identify this as an advanced context descriptor */
6291 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6293 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6294 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6295 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6296 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6299 static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6300 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6303 u32 vlan_macip_lens, type_tucmd;
6304 u32 mss_l4len_idx, l4len;
6306 if (!skb_is_gso(skb))
6309 if (skb_header_cloned(skb)) {
6310 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6315 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6316 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6318 if (protocol == __constant_htons(ETH_P_IP)) {
6319 struct iphdr *iph = ip_hdr(skb);
6322 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6326 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6327 } else if (skb_is_gso_v6(skb)) {
6328 ipv6_hdr(skb)->payload_len = 0;
6329 tcp_hdr(skb)->check =
6330 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6331 &ipv6_hdr(skb)->daddr,
6335 l4len = tcp_hdrlen(skb);
6336 *hdr_len = skb_transport_offset(skb) + l4len;
6338 /* mss_l4len_id: use 1 as index for TSO */
6339 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6340 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6341 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6343 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6344 vlan_macip_lens = skb_network_header_len(skb);
6345 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6346 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6348 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6354 static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
6355 struct sk_buff *skb, u32 tx_flags,
6358 u32 vlan_macip_lens = 0;
6359 u32 mss_l4len_idx = 0;
6362 if (skb->ip_summed != CHECKSUM_PARTIAL) {
6363 if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6364 !(tx_flags & IXGBE_TX_FLAGS_TXSW))
6369 case __constant_htons(ETH_P_IP):
6370 vlan_macip_lens |= skb_network_header_len(skb);
6371 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6372 l4_hdr = ip_hdr(skb)->protocol;
6374 case __constant_htons(ETH_P_IPV6):
6375 vlan_macip_lens |= skb_network_header_len(skb);
6376 l4_hdr = ipv6_hdr(skb)->nexthdr;
6379 if (unlikely(net_ratelimit())) {
6380 dev_warn(tx_ring->dev,
6381 "partial checksum but proto=%x!\n",
6389 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6390 mss_l4len_idx = tcp_hdrlen(skb) <<
6391 IXGBE_ADVTXD_L4LEN_SHIFT;
6394 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6395 mss_l4len_idx = sizeof(struct sctphdr) <<
6396 IXGBE_ADVTXD_L4LEN_SHIFT;
6399 mss_l4len_idx = sizeof(struct udphdr) <<
6400 IXGBE_ADVTXD_L4LEN_SHIFT;
6403 if (unlikely(net_ratelimit())) {
6404 dev_warn(tx_ring->dev,
6405 "partial checksum but l4 proto=%x!\n",
6412 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6413 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6415 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6416 type_tucmd, mss_l4len_idx);
6418 return (skb->ip_summed == CHECKSUM_PARTIAL);
6421 static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6423 /* set type for advanced descriptor with frame checksum insertion */
6424 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6425 IXGBE_ADVTXD_DCMD_IFCS |
6426 IXGBE_ADVTXD_DCMD_DEXT);
6428 /* set HW vlan bit if vlan is present */
6429 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
6430 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6432 /* set segmentation enable bits for TSO/FSO */
6434 if ((tx_flags & IXGBE_TX_FLAGS_TSO) || (tx_flags & IXGBE_TX_FLAGS_FSO))
6436 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6438 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6443 static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen)
6445 __le32 olinfo_status =
6446 cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
6448 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6449 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM |
6450 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6451 /* enble IPv4 checksum for TSO */
6452 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6453 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
6456 /* enable L4 checksum for TSO and TX checksum offload */
6457 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6458 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6461 /* use index 1 context for FCOE/FSO */
6462 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6463 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC |
6464 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6468 * Check Context must be set if Tx switch is enabled, which it
6469 * always is for case where virtual functions are running
6471 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
6472 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6474 return olinfo_status;
6477 #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6480 static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
6481 struct sk_buff *skb,
6482 struct ixgbe_tx_buffer *first,
6486 struct device *dev = tx_ring->dev;
6487 struct ixgbe_tx_buffer *tx_buffer_info;
6488 union ixgbe_adv_tx_desc *tx_desc;
6490 __le32 cmd_type, olinfo_status;
6491 struct skb_frag_struct *frag;
6493 unsigned int data_len = skb->data_len;
6494 unsigned int size = skb_headlen(skb);
6496 u32 paylen = skb->len - hdr_len;
6497 u16 i = tx_ring->next_to_use;
6501 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6502 if (data_len >= sizeof(struct fcoe_crc_eof)) {
6503 data_len -= sizeof(struct fcoe_crc_eof);
6505 size -= sizeof(struct fcoe_crc_eof) - data_len;
6511 dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE);
6512 if (dma_mapping_error(dev, dma))
6515 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6516 olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen);
6518 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
6521 while (size > IXGBE_MAX_DATA_PER_TXD) {
6522 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6523 tx_desc->read.cmd_type_len =
6524 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
6525 tx_desc->read.olinfo_status = olinfo_status;
6527 offset += IXGBE_MAX_DATA_PER_TXD;
6528 size -= IXGBE_MAX_DATA_PER_TXD;
6532 if (i == tx_ring->count) {
6533 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
6538 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6539 tx_buffer_info->length = offset + size;
6540 tx_buffer_info->tx_flags = tx_flags;
6541 tx_buffer_info->dma = dma;
6543 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6544 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
6545 tx_desc->read.olinfo_status = olinfo_status;
6550 frag = &skb_shinfo(skb)->frags[f];
6552 size = min_t(unsigned int, data_len, skb_frag_size(frag));
6554 size = skb_frag_size(frag);
6560 tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE;
6562 dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE);
6563 if (dma_mapping_error(dev, dma))
6568 if (i == tx_ring->count) {
6569 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
6574 tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD);
6577 if (i == tx_ring->count)
6580 tx_ring->next_to_use = i;
6582 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6583 gso_segs = skb_shinfo(skb)->gso_segs;
6585 /* adjust for FCoE Sequence Offload */
6586 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6587 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6588 skb_shinfo(skb)->gso_size);
6589 #endif /* IXGBE_FCOE */
6593 /* multiply data chunks by size of headers */
6594 tx_buffer_info->bytecount = paylen + (gso_segs * hdr_len);
6595 tx_buffer_info->gso_segs = gso_segs;
6596 tx_buffer_info->skb = skb;
6598 /* set the timestamp */
6599 first->time_stamp = jiffies;
6602 * Force memory writes to complete before letting h/w
6603 * know there are new descriptors to fetch. (Only
6604 * applicable for weak-ordered memory model archs,
6609 /* set next_to_watch value indicating a packet is present */
6610 first->next_to_watch = tx_desc;
6612 /* notify HW of packet */
6613 writel(i, tx_ring->tail);
6617 dev_err(dev, "TX DMA map failed\n");
6619 /* clear dma mappings for failed tx_buffer_info map */
6621 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6622 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
6623 if (tx_buffer_info == first)
6630 dev_kfree_skb_any(skb);
6632 tx_ring->next_to_use = i;
6635 static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6636 u32 tx_flags, __be16 protocol)
6638 struct ixgbe_q_vector *q_vector = ring->q_vector;
6639 union ixgbe_atr_hash_dword input = { .dword = 0 };
6640 union ixgbe_atr_hash_dword common = { .dword = 0 };
6642 unsigned char *network;
6644 struct ipv6hdr *ipv6;
6649 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6653 /* do nothing if sampling is disabled */
6654 if (!ring->atr_sample_rate)
6659 /* snag network header to get L4 type and address */
6660 hdr.network = skb_network_header(skb);
6662 /* Currently only IPv4/IPv6 with TCP is supported */
6663 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6664 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6665 (protocol != __constant_htons(ETH_P_IP) ||
6666 hdr.ipv4->protocol != IPPROTO_TCP))
6671 /* skip this packet since it is invalid or the socket is closing */
6675 /* sample on all syn packets or once every atr sample count */
6676 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6679 /* reset sample count */
6680 ring->atr_count = 0;
6682 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6685 * src and dst are inverted, think how the receiver sees them
6687 * The input is broken into two sections, a non-compressed section
6688 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6689 * is XORed together and stored in the compressed dword.
6691 input.formatted.vlan_id = vlan_id;
6694 * since src port and flex bytes occupy the same word XOR them together
6695 * and write the value to source port portion of compressed dword
6697 if (tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
6698 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6700 common.port.src ^= th->dest ^ protocol;
6701 common.port.dst ^= th->source;
6703 if (protocol == __constant_htons(ETH_P_IP)) {
6704 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6705 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6707 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6708 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6709 hdr.ipv6->saddr.s6_addr32[1] ^
6710 hdr.ipv6->saddr.s6_addr32[2] ^
6711 hdr.ipv6->saddr.s6_addr32[3] ^
6712 hdr.ipv6->daddr.s6_addr32[0] ^
6713 hdr.ipv6->daddr.s6_addr32[1] ^
6714 hdr.ipv6->daddr.s6_addr32[2] ^
6715 hdr.ipv6->daddr.s6_addr32[3];
6718 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
6719 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6720 input, common, ring->queue_index);
6723 static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
6725 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
6726 /* Herbert's original patch had:
6727 * smp_mb__after_netif_stop_queue();
6728 * but since that doesn't exist yet, just open code it. */
6731 /* We need to check again in a case another CPU has just
6732 * made room available. */
6733 if (likely(ixgbe_desc_unused(tx_ring) < size))
6736 /* A reprieve! - use start_queue because it doesn't call schedule */
6737 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
6738 ++tx_ring->tx_stats.restart_queue;
6742 static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
6744 if (likely(ixgbe_desc_unused(tx_ring) >= size))
6746 return __ixgbe_maybe_stop_tx(tx_ring, size);
6749 static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6751 struct ixgbe_adapter *adapter = netdev_priv(dev);
6752 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6755 __be16 protocol = vlan_get_protocol(skb);
6757 if (((protocol == htons(ETH_P_FCOE)) ||
6758 (protocol == htons(ETH_P_FIP))) &&
6759 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6760 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6761 txq += adapter->ring_feature[RING_F_FCOE].mask;
6766 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6767 while (unlikely(txq >= dev->real_num_tx_queues))
6768 txq -= dev->real_num_tx_queues;
6772 return skb_tx_hash(dev, skb);
6775 netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
6776 struct ixgbe_adapter *adapter,
6777 struct ixgbe_ring *tx_ring)
6779 struct ixgbe_tx_buffer *first;
6782 #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6785 u16 count = TXD_USE_COUNT(skb_headlen(skb));
6786 __be16 protocol = skb->protocol;
6790 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
6791 * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD,
6792 * + 2 desc gap to keep tail from touching head,
6793 * + 1 desc for context descriptor,
6794 * otherwise try next time
6796 #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6797 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6798 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6800 count += skb_shinfo(skb)->nr_frags;
6802 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6803 tx_ring->tx_stats.tx_busy++;
6804 return NETDEV_TX_BUSY;
6807 #ifdef CONFIG_PCI_IOV
6808 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6809 tx_flags |= IXGBE_TX_FLAGS_TXSW;
6812 /* if we have a HW VLAN tag being added default to the HW one */
6813 if (vlan_tx_tag_present(skb)) {
6814 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6815 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6816 /* else if it is a SW VLAN check the next protocol and store the tag */
6817 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6818 struct vlan_hdr *vhdr, _vhdr;
6819 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6823 protocol = vhdr->h_vlan_encapsulated_proto;
6824 tx_flags |= ntohs(vhdr->h_vlan_TCI) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6825 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
6828 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
6829 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
6830 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6831 (skb->priority != TC_PRIO_CONTROL))) {
6832 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
6833 tx_flags |= (skb->priority & 0x7) <<
6834 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
6835 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6836 struct vlan_ethhdr *vhdr;
6837 if (skb_header_cloned(skb) &&
6838 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6840 vhdr = (struct vlan_ethhdr *)skb->data;
6841 vhdr->h_vlan_TCI = htons(tx_flags >>
6842 IXGBE_TX_FLAGS_VLAN_SHIFT);
6844 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6848 /* record the location of the first descriptor for this packet */
6849 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6852 /* setup tx offload for FCoE */
6853 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
6854 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6855 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
6859 tx_flags |= IXGBE_TX_FLAGS_FSO |
6860 IXGBE_TX_FLAGS_FCOE;
6862 tx_flags |= IXGBE_TX_FLAGS_FCOE;
6867 #endif /* IXGBE_FCOE */
6868 /* setup IPv4/IPv6 offloads */
6869 if (protocol == __constant_htons(ETH_P_IP))
6870 tx_flags |= IXGBE_TX_FLAGS_IPV4;
6872 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
6876 tx_flags |= IXGBE_TX_FLAGS_TSO;
6877 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
6878 tx_flags |= IXGBE_TX_FLAGS_CSUM;
6880 /* add the ATR filter if ATR is on */
6881 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6882 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
6886 #endif /* IXGBE_FCOE */
6887 ixgbe_tx_map(tx_ring, skb, first, tx_flags, hdr_len);
6889 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
6891 return NETDEV_TX_OK;
6894 dev_kfree_skb_any(skb);
6895 return NETDEV_TX_OK;
6898 static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
6900 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6901 struct ixgbe_ring *tx_ring;
6903 tx_ring = adapter->tx_ring[skb->queue_mapping];
6904 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6908 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6909 * @netdev: network interface device structure
6910 * @p: pointer to an address structure
6912 * Returns 0 on success, negative on failure
6914 static int ixgbe_set_mac(struct net_device *netdev, void *p)
6916 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6917 struct ixgbe_hw *hw = &adapter->hw;
6918 struct sockaddr *addr = p;
6920 if (!is_valid_ether_addr(addr->sa_data))
6921 return -EADDRNOTAVAIL;
6923 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6924 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6926 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6933 ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6935 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6936 struct ixgbe_hw *hw = &adapter->hw;
6940 if (prtad != hw->phy.mdio.prtad)
6942 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6948 static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6949 u16 addr, u16 value)
6951 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6952 struct ixgbe_hw *hw = &adapter->hw;
6954 if (prtad != hw->phy.mdio.prtad)
6956 return hw->phy.ops.write_reg(hw, addr, devad, value);
6959 static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6961 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6963 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6967 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
6969 * @netdev: network interface device structure
6971 * Returns non-zero on failure
6973 static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6976 struct ixgbe_adapter *adapter = netdev_priv(dev);
6977 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6979 if (is_valid_ether_addr(mac->san_addr)) {
6981 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6988 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
6990 * @netdev: network interface device structure
6992 * Returns non-zero on failure
6994 static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6997 struct ixgbe_adapter *adapter = netdev_priv(dev);
6998 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7000 if (is_valid_ether_addr(mac->san_addr)) {
7002 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7008 #ifdef CONFIG_NET_POLL_CONTROLLER
7010 * Polling 'interrupt' - used by things like netconsole to send skbs
7011 * without having to re-enable interrupts. It's not called while
7012 * the interrupt routine is executing.
7014 static void ixgbe_netpoll(struct net_device *netdev)
7016 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7019 /* if interface is down do nothing */
7020 if (test_bit(__IXGBE_DOWN, &adapter->state))
7023 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
7024 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
7025 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
7026 for (i = 0; i < num_q_vectors; i++) {
7027 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
7028 ixgbe_msix_clean_rings(0, q_vector);
7031 ixgbe_intr(adapter->pdev->irq, netdev);
7033 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
7037 static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7038 struct rtnl_link_stats64 *stats)
7040 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7044 for (i = 0; i < adapter->num_rx_queues; i++) {
7045 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
7051 start = u64_stats_fetch_begin_bh(&ring->syncp);
7052 packets = ring->stats.packets;
7053 bytes = ring->stats.bytes;
7054 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7055 stats->rx_packets += packets;
7056 stats->rx_bytes += bytes;
7060 for (i = 0; i < adapter->num_tx_queues; i++) {
7061 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7067 start = u64_stats_fetch_begin_bh(&ring->syncp);
7068 packets = ring->stats.packets;
7069 bytes = ring->stats.bytes;
7070 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7071 stats->tx_packets += packets;
7072 stats->tx_bytes += bytes;
7076 /* following stats updated by ixgbe_watchdog_task() */
7077 stats->multicast = netdev->stats.multicast;
7078 stats->rx_errors = netdev->stats.rx_errors;
7079 stats->rx_length_errors = netdev->stats.rx_length_errors;
7080 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7081 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7085 /* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7086 * #adapter: pointer to ixgbe_adapter
7087 * @tc: number of traffic classes currently enabled
7089 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7090 * 802.1Q priority maps to a packet buffer that exists.
7092 static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7094 struct ixgbe_hw *hw = &adapter->hw;
7098 /* 82598 have a static priority to TC mapping that can not
7099 * be changed so no validation is needed.
7101 if (hw->mac.type == ixgbe_mac_82598EB)
7104 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7107 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7108 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7110 /* If up2tc is out of bounds default to zero */
7112 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7116 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7122 /* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7125 * @netdev: net device to configure
7126 * @tc: number of traffic classes to enable
7128 int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7130 struct ixgbe_adapter *adapter = netdev_priv(dev);
7131 struct ixgbe_hw *hw = &adapter->hw;
7133 /* Multiple traffic classes requires multiple queues */
7134 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
7135 e_err(drv, "Enable failed, needs MSI-X\n");
7139 /* Hardware supports up to 8 traffic classes */
7140 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
7141 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7144 /* Hardware has to reinitialize queues and interrupts to
7145 * match packet buffer alignment. Unfortunantly, the
7146 * hardware is not flexible enough to do this dynamically.
7148 if (netif_running(dev))
7150 ixgbe_clear_interrupt_scheme(adapter);
7153 netdev_set_num_tc(dev, tc);
7154 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
7156 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
7157 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7159 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7160 adapter->hw.fc.requested_mode = ixgbe_fc_none;
7162 netdev_reset_tc(dev);
7164 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
7166 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
7167 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7169 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7170 adapter->dcb_cfg.pfc_mode_enable = false;
7173 ixgbe_init_interrupt_scheme(adapter);
7174 ixgbe_validate_rtr(adapter, tc);
7175 if (netif_running(dev))
7181 void ixgbe_do_reset(struct net_device *netdev)
7183 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7185 if (netif_running(netdev))
7186 ixgbe_reinit_locked(adapter);
7188 ixgbe_reset(adapter);
7191 static u32 ixgbe_fix_features(struct net_device *netdev, u32 data)
7193 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7196 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7197 data &= ~NETIF_F_HW_VLAN_RX;
7200 /* return error if RXHASH is being enabled when RSS is not supported */
7201 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7202 data &= ~NETIF_F_RXHASH;
7204 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7205 if (!(data & NETIF_F_RXCSUM))
7206 data &= ~NETIF_F_LRO;
7208 /* Turn off LRO if not RSC capable or invalid ITR settings */
7209 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7210 data &= ~NETIF_F_LRO;
7211 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7212 (adapter->rx_itr_setting != 1 &&
7213 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7214 data &= ~NETIF_F_LRO;
7215 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7221 static int ixgbe_set_features(struct net_device *netdev, u32 data)
7223 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7224 bool need_reset = false;
7226 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7227 if (!(data & NETIF_F_RXCSUM))
7228 adapter->flags &= ~IXGBE_FLAG_RX_CSUM_ENABLED;
7230 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
7232 /* Make sure RSC matches LRO, reset if change */
7233 if (!!(data & NETIF_F_LRO) !=
7234 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7235 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7236 switch (adapter->hw.mac.type) {
7237 case ixgbe_mac_X540:
7238 case ixgbe_mac_82599EB:
7247 * Check if Flow Director n-tuple support was enabled or disabled. If
7248 * the state changed, we need to reset.
7250 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7251 /* turn off ATR, enable perfect filters and reset */
7252 if (data & NETIF_F_NTUPLE) {
7253 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7254 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7257 } else if (!(data & NETIF_F_NTUPLE)) {
7258 /* turn off Flow Director, set ATR and reset */
7259 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7260 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7261 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7262 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7267 ixgbe_do_reset(netdev);
7273 static const struct net_device_ops ixgbe_netdev_ops = {
7274 .ndo_open = ixgbe_open,
7275 .ndo_stop = ixgbe_close,
7276 .ndo_start_xmit = ixgbe_xmit_frame,
7277 .ndo_select_queue = ixgbe_select_queue,
7278 .ndo_set_rx_mode = ixgbe_set_rx_mode,
7279 .ndo_validate_addr = eth_validate_addr,
7280 .ndo_set_mac_address = ixgbe_set_mac,
7281 .ndo_change_mtu = ixgbe_change_mtu,
7282 .ndo_tx_timeout = ixgbe_tx_timeout,
7283 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7284 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
7285 .ndo_do_ioctl = ixgbe_ioctl,
7286 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7287 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7288 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7289 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
7290 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
7291 .ndo_get_stats64 = ixgbe_get_stats64,
7292 .ndo_setup_tc = ixgbe_setup_tc,
7293 #ifdef CONFIG_NET_POLL_CONTROLLER
7294 .ndo_poll_controller = ixgbe_netpoll,
7297 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
7298 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
7299 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
7300 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7301 .ndo_fcoe_disable = ixgbe_fcoe_disable,
7302 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
7303 #endif /* IXGBE_FCOE */
7304 .ndo_set_features = ixgbe_set_features,
7305 .ndo_fix_features = ixgbe_fix_features,
7308 static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7309 const struct ixgbe_info *ii)
7311 #ifdef CONFIG_PCI_IOV
7312 struct ixgbe_hw *hw = &adapter->hw;
7314 if (hw->mac.type == ixgbe_mac_82598EB)
7317 /* The 82599 supports up to 64 VFs per physical function
7318 * but this implementation limits allocation to 63 so that
7319 * basic networking resources are still available to the
7322 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7323 ixgbe_enable_sriov(adapter, ii);
7324 #endif /* CONFIG_PCI_IOV */
7328 * ixgbe_probe - Device Initialization Routine
7329 * @pdev: PCI device information struct
7330 * @ent: entry in ixgbe_pci_tbl
7332 * Returns 0 on success, negative on failure
7334 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7335 * The OS initialization, configuring of the adapter private structure,
7336 * and a hardware reset occur.
7338 static int __devinit ixgbe_probe(struct pci_dev *pdev,
7339 const struct pci_device_id *ent)
7341 struct net_device *netdev;
7342 struct ixgbe_adapter *adapter = NULL;
7343 struct ixgbe_hw *hw;
7344 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
7345 static int cards_found;
7346 int i, err, pci_using_dac;
7347 u8 part_str[IXGBE_PBANUM_LENGTH];
7348 unsigned int indices = num_possible_cpus();
7355 /* Catch broken hardware that put the wrong VF device ID in
7356 * the PCIe SR-IOV capability.
7358 if (pdev->is_virtfn) {
7359 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7360 pci_name(pdev), pdev->vendor, pdev->device);
7364 err = pci_enable_device_mem(pdev);
7368 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7369 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
7372 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
7374 err = dma_set_coherent_mask(&pdev->dev,
7378 "No usable DMA configuration, aborting\n");
7385 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
7386 IORESOURCE_MEM), ixgbe_driver_name);
7389 "pci_request_selected_regions failed 0x%x\n", err);
7393 pci_enable_pcie_error_reporting(pdev);
7395 pci_set_master(pdev);
7396 pci_save_state(pdev);
7398 #ifdef CONFIG_IXGBE_DCB
7399 indices *= MAX_TRAFFIC_CLASS;
7402 if (ii->mac == ixgbe_mac_82598EB)
7403 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7405 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7408 indices += min_t(unsigned int, num_possible_cpus(),
7409 IXGBE_MAX_FCOE_INDICES);
7411 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
7414 goto err_alloc_etherdev;
7417 SET_NETDEV_DEV(netdev, &pdev->dev);
7419 adapter = netdev_priv(netdev);
7420 pci_set_drvdata(pdev, adapter);
7422 adapter->netdev = netdev;
7423 adapter->pdev = pdev;
7426 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7428 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
7429 pci_resource_len(pdev, 0));
7435 for (i = 1; i <= 5; i++) {
7436 if (pci_resource_len(pdev, i) == 0)
7440 netdev->netdev_ops = &ixgbe_netdev_ops;
7441 ixgbe_set_ethtool_ops(netdev);
7442 netdev->watchdog_timeo = 5 * HZ;
7443 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
7445 adapter->bd_number = cards_found;
7448 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
7449 hw->mac.type = ii->mac;
7452 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7453 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7454 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7455 if (!(eec & (1 << 8)))
7456 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7459 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
7460 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
7461 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7462 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7463 hw->phy.mdio.mmds = 0;
7464 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7465 hw->phy.mdio.dev = netdev;
7466 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7467 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
7469 ii->get_invariants(hw);
7471 /* setup the private structure */
7472 err = ixgbe_sw_init(adapter);
7476 /* Make it possible the adapter to be woken up via WOL */
7477 switch (adapter->hw.mac.type) {
7478 case ixgbe_mac_82599EB:
7479 case ixgbe_mac_X540:
7480 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
7487 * If there is a fan on this device and it has failed log the
7490 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7491 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7492 if (esdp & IXGBE_ESDP_SDP1)
7493 e_crit(probe, "Fan has stopped, replace the adapter\n");
7496 /* reset_hw fills in the perm_addr as well */
7497 hw->phy.reset_if_overtemp = true;
7498 err = hw->mac.ops.reset_hw(hw);
7499 hw->phy.reset_if_overtemp = false;
7500 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7501 hw->mac.type == ixgbe_mac_82598EB) {
7503 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
7504 e_dev_err("failed to load because an unsupported SFP+ "
7505 "module type was detected.\n");
7506 e_dev_err("Reload the driver after installing a supported "
7510 e_dev_err("HW Init failed: %d\n", err);
7514 ixgbe_probe_vf(adapter, ii);
7516 netdev->features = NETIF_F_SG |
7519 NETIF_F_HW_VLAN_TX |
7520 NETIF_F_HW_VLAN_RX |
7521 NETIF_F_HW_VLAN_FILTER |
7527 netdev->hw_features = netdev->features;
7529 switch (adapter->hw.mac.type) {
7530 case ixgbe_mac_82599EB:
7531 case ixgbe_mac_X540:
7532 netdev->features |= NETIF_F_SCTP_CSUM;
7533 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7540 netdev->vlan_features |= NETIF_F_TSO;
7541 netdev->vlan_features |= NETIF_F_TSO6;
7542 netdev->vlan_features |= NETIF_F_IP_CSUM;
7543 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
7544 netdev->vlan_features |= NETIF_F_SG;
7546 netdev->priv_flags |= IFF_UNICAST_FLT;
7548 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7549 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7550 IXGBE_FLAG_DCB_ENABLED);
7552 #ifdef CONFIG_IXGBE_DCB
7553 netdev->dcbnl_ops = &dcbnl_ops;
7557 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7558 if (hw->mac.ops.get_device_caps) {
7559 hw->mac.ops.get_device_caps(hw, &device_caps);
7560 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7561 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
7564 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7565 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7566 netdev->vlan_features |= NETIF_F_FSO;
7567 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7569 #endif /* IXGBE_FCOE */
7570 if (pci_using_dac) {
7571 netdev->features |= NETIF_F_HIGHDMA;
7572 netdev->vlan_features |= NETIF_F_HIGHDMA;
7575 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7576 netdev->hw_features |= NETIF_F_LRO;
7577 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
7578 netdev->features |= NETIF_F_LRO;
7580 /* make sure the EEPROM is good */
7581 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
7582 e_dev_err("The EEPROM Checksum Is Not Valid\n");
7587 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7588 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7590 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
7591 e_dev_err("invalid MAC address\n");
7596 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7597 (unsigned long) adapter);
7599 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7600 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
7602 err = ixgbe_init_interrupt_scheme(adapter);
7606 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7607 netdev->hw_features &= ~NETIF_F_RXHASH;
7608 netdev->features &= ~NETIF_F_RXHASH;
7611 /* WOL not supported for all but the following */
7613 switch (pdev->device) {
7614 case IXGBE_DEV_ID_82599_SFP:
7615 /* Only this subdevice supports WOL */
7616 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
7617 adapter->wol = IXGBE_WUFC_MAG;
7619 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7620 /* All except this subdevice support WOL */
7621 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7622 adapter->wol = IXGBE_WUFC_MAG;
7624 case IXGBE_DEV_ID_82599_KX4:
7625 adapter->wol = IXGBE_WUFC_MAG;
7627 case IXGBE_DEV_ID_X540T:
7628 case IXGBE_DEV_ID_X540T1:
7629 /* Check eeprom to see if it is enabled */
7630 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7631 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7633 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7634 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7635 (hw->bus.func == 0)))
7636 adapter->wol = IXGBE_WUFC_MAG;
7639 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7641 /* save off EEPROM version number */
7642 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7643 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7645 /* pick up the PCI bus settings for reporting later */
7646 hw->mac.ops.get_bus_info(hw);
7648 /* print bus type/speed/width info */
7649 e_dev_info("(PCI Express:%s:%s) %pM\n",
7650 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7651 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
7653 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7654 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7655 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7659 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7661 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
7662 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
7663 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
7664 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
7667 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7668 hw->mac.type, hw->phy.type, part_str);
7670 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
7671 e_dev_warn("PCI-Express bandwidth available for this card is "
7672 "not sufficient for optimal performance.\n");
7673 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7677 /* reset the hardware with the new settings */
7678 err = hw->mac.ops.start_hw(hw);
7680 if (err == IXGBE_ERR_EEPROM_VERSION) {
7681 /* We are running on a pre-production device, log a warning */
7682 e_dev_warn("This device is a pre-production adapter/LOM. "
7683 "Please be aware there may be issues associated "
7684 "with your hardware. If you are experiencing "
7685 "problems please contact your Intel or hardware "
7686 "representative who provided you with this "
7689 strcpy(netdev->name, "eth%d");
7690 err = register_netdev(netdev);
7694 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7695 if (hw->mac.ops.disable_tx_laser &&
7696 ((hw->phy.multispeed_fiber) ||
7697 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7698 (hw->mac.type == ixgbe_mac_82599EB))))
7699 hw->mac.ops.disable_tx_laser(hw);
7701 /* carrier off reporting is important to ethtool even BEFORE open */
7702 netif_carrier_off(netdev);
7704 #ifdef CONFIG_IXGBE_DCA
7705 if (dca_add_requester(&pdev->dev) == 0) {
7706 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
7707 ixgbe_setup_dca(adapter);
7710 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7711 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
7712 for (i = 0; i < adapter->num_vfs; i++)
7713 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7716 /* firmware requires driver version to be 0xFFFFFFFF
7717 * since os does not support feature
7719 if (hw->mac.ops.set_fw_drv_ver)
7720 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7723 /* add san mac addr to netdev */
7724 ixgbe_add_sanmac_netdev(netdev);
7726 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
7731 ixgbe_release_hw_control(adapter);
7732 ixgbe_clear_interrupt_scheme(adapter);
7735 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7736 ixgbe_disable_sriov(adapter);
7737 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
7738 iounmap(hw->hw_addr);
7740 free_netdev(netdev);
7742 pci_release_selected_regions(pdev,
7743 pci_select_bars(pdev, IORESOURCE_MEM));
7746 pci_disable_device(pdev);
7751 * ixgbe_remove - Device Removal Routine
7752 * @pdev: PCI device information struct
7754 * ixgbe_remove is called by the PCI subsystem to alert the driver
7755 * that it should release a PCI device. The could be caused by a
7756 * Hot-Plug event, or because the driver is going to be removed from
7759 static void __devexit ixgbe_remove(struct pci_dev *pdev)
7761 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7762 struct net_device *netdev = adapter->netdev;
7764 set_bit(__IXGBE_DOWN, &adapter->state);
7765 cancel_work_sync(&adapter->service_task);
7767 #ifdef CONFIG_IXGBE_DCA
7768 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7769 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7770 dca_remove_requester(&pdev->dev);
7771 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7776 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7777 ixgbe_cleanup_fcoe(adapter);
7779 #endif /* IXGBE_FCOE */
7781 /* remove the added san mac */
7782 ixgbe_del_sanmac_netdev(netdev);
7784 if (netdev->reg_state == NETREG_REGISTERED)
7785 unregister_netdev(netdev);
7787 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7788 if (!(ixgbe_check_vf_assignment(adapter)))
7789 ixgbe_disable_sriov(adapter);
7791 e_dev_warn("Unloading driver while VFs are assigned "
7792 "- VFs will not be deallocated\n");
7795 ixgbe_clear_interrupt_scheme(adapter);
7797 ixgbe_release_hw_control(adapter);
7799 iounmap(adapter->hw.hw_addr);
7800 pci_release_selected_regions(pdev, pci_select_bars(pdev,
7803 e_dev_info("complete\n");
7805 free_netdev(netdev);
7807 pci_disable_pcie_error_reporting(pdev);
7809 pci_disable_device(pdev);
7813 * ixgbe_io_error_detected - called when PCI error is detected
7814 * @pdev: Pointer to PCI device
7815 * @state: The current pci connection state
7817 * This function is called after a PCI bus error affecting
7818 * this device has been detected.
7820 static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
7821 pci_channel_state_t state)
7823 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7824 struct net_device *netdev = adapter->netdev;
7826 #ifdef CONFIG_PCI_IOV
7827 struct pci_dev *bdev, *vfdev;
7828 u32 dw0, dw1, dw2, dw3;
7830 u16 req_id, pf_func;
7832 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7833 adapter->num_vfs == 0)
7834 goto skip_bad_vf_detection;
7836 bdev = pdev->bus->self;
7837 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT))
7838 bdev = bdev->bus->self;
7841 goto skip_bad_vf_detection;
7843 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
7845 goto skip_bad_vf_detection;
7847 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
7848 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
7849 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
7850 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
7853 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
7854 if (!(req_id & 0x0080))
7855 goto skip_bad_vf_detection;
7857 pf_func = req_id & 0x01;
7858 if ((pf_func & 1) == (pdev->devfn & 1)) {
7859 unsigned int device_id;
7861 vf = (req_id & 0x7F) >> 1;
7862 e_dev_err("VF %d has caused a PCIe error\n", vf);
7863 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
7864 "%8.8x\tdw3: %8.8x\n",
7865 dw0, dw1, dw2, dw3);
7866 switch (adapter->hw.mac.type) {
7867 case ixgbe_mac_82599EB:
7868 device_id = IXGBE_82599_VF_DEVICE_ID;
7870 case ixgbe_mac_X540:
7871 device_id = IXGBE_X540_VF_DEVICE_ID;
7878 /* Find the pci device of the offending VF */
7879 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
7881 if (vfdev->devfn == (req_id & 0xFF))
7883 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
7887 * There's a slim chance the VF could have been hot plugged,
7888 * so if it is no longer present we don't need to issue the
7889 * VFLR. Just clean up the AER in that case.
7892 e_dev_err("Issuing VFLR to VF %d\n", vf);
7893 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
7896 pci_cleanup_aer_uncorrect_error_status(pdev);
7900 * Even though the error may have occurred on the other port
7901 * we still need to increment the vf error reference count for
7902 * both ports because the I/O resume function will be called
7905 adapter->vferr_refcount++;
7907 return PCI_ERS_RESULT_RECOVERED;
7909 skip_bad_vf_detection:
7910 #endif /* CONFIG_PCI_IOV */
7911 netif_device_detach(netdev);
7913 if (state == pci_channel_io_perm_failure)
7914 return PCI_ERS_RESULT_DISCONNECT;
7916 if (netif_running(netdev))
7917 ixgbe_down(adapter);
7918 pci_disable_device(pdev);
7920 /* Request a slot reset. */
7921 return PCI_ERS_RESULT_NEED_RESET;
7925 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7926 * @pdev: Pointer to PCI device
7928 * Restart the card from scratch, as if from a cold-boot.
7930 static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7932 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7933 pci_ers_result_t result;
7936 if (pci_enable_device_mem(pdev)) {
7937 e_err(probe, "Cannot re-enable PCI device after reset.\n");
7938 result = PCI_ERS_RESULT_DISCONNECT;
7940 pci_set_master(pdev);
7941 pci_restore_state(pdev);
7942 pci_save_state(pdev);
7944 pci_wake_from_d3(pdev, false);
7946 ixgbe_reset(adapter);
7947 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
7948 result = PCI_ERS_RESULT_RECOVERED;
7951 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7953 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7954 "failed 0x%0x\n", err);
7955 /* non-fatal, continue */
7962 * ixgbe_io_resume - called when traffic can start flowing again.
7963 * @pdev: Pointer to PCI device
7965 * This callback is called when the error recovery driver tells us that
7966 * its OK to resume normal operation.
7968 static void ixgbe_io_resume(struct pci_dev *pdev)
7970 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7971 struct net_device *netdev = adapter->netdev;
7973 #ifdef CONFIG_PCI_IOV
7974 if (adapter->vferr_refcount) {
7975 e_info(drv, "Resuming after VF err\n");
7976 adapter->vferr_refcount--;
7981 if (netif_running(netdev))
7984 netif_device_attach(netdev);
7987 static struct pci_error_handlers ixgbe_err_handler = {
7988 .error_detected = ixgbe_io_error_detected,
7989 .slot_reset = ixgbe_io_slot_reset,
7990 .resume = ixgbe_io_resume,
7993 static struct pci_driver ixgbe_driver = {
7994 .name = ixgbe_driver_name,
7995 .id_table = ixgbe_pci_tbl,
7996 .probe = ixgbe_probe,
7997 .remove = __devexit_p(ixgbe_remove),
7999 .suspend = ixgbe_suspend,
8000 .resume = ixgbe_resume,
8002 .shutdown = ixgbe_shutdown,
8003 .err_handler = &ixgbe_err_handler
8007 * ixgbe_init_module - Driver Registration Routine
8009 * ixgbe_init_module is the first routine called when the driver is
8010 * loaded. All it does is register with the PCI subsystem.
8012 static int __init ixgbe_init_module(void)
8015 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
8016 pr_info("%s\n", ixgbe_copyright);
8018 ret = pci_register_driver(&ixgbe_driver);
8022 #ifdef CONFIG_IXGBE_DCA
8023 dca_register_notify(&dca_notifier);
8029 module_init(ixgbe_init_module);
8032 * ixgbe_exit_module - Driver Exit Cleanup Routine
8034 * ixgbe_exit_module is called just before the driver is removed
8037 static void __exit ixgbe_exit_module(void)
8039 #ifdef CONFIG_IXGBE_DCA
8040 dca_unregister_notify(&dca_notifier);
8042 pci_unregister_driver(&ixgbe_driver);
8043 rcu_barrier(); /* Wait for completion of call_rcu()'s */
8046 #ifdef CONFIG_IXGBE_DCA
8047 static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
8052 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
8053 __ixgbe_notify_dca);
8055 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
8058 #endif /* CONFIG_IXGBE_DCA */
8060 module_exit(ixgbe_exit_module);