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 /* required last entry */
113 MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
115 #ifdef CONFIG_IXGBE_DCA
116 static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
118 static struct notifier_block dca_notifier = {
119 .notifier_call = ixgbe_notify_dca,
125 #ifdef CONFIG_PCI_IOV
126 static unsigned int max_vfs;
127 module_param(max_vfs, uint, 0);
128 MODULE_PARM_DESC(max_vfs,
129 "Maximum number of virtual functions to allocate per physical function");
130 #endif /* CONFIG_PCI_IOV */
132 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
133 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
134 MODULE_LICENSE("GPL");
135 MODULE_VERSION(DRV_VERSION);
137 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
139 static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
141 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
142 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
143 schedule_work(&adapter->service_task);
146 static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
148 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
150 /* flush memory to make sure state is correct before next watchog */
151 smp_mb__before_clear_bit();
152 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
155 struct ixgbe_reg_info {
160 static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
162 /* General Registers */
163 {IXGBE_CTRL, "CTRL"},
164 {IXGBE_STATUS, "STATUS"},
165 {IXGBE_CTRL_EXT, "CTRL_EXT"},
167 /* Interrupt Registers */
168 {IXGBE_EICR, "EICR"},
171 {IXGBE_SRRCTL(0), "SRRCTL"},
172 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
173 {IXGBE_RDLEN(0), "RDLEN"},
174 {IXGBE_RDH(0), "RDH"},
175 {IXGBE_RDT(0), "RDT"},
176 {IXGBE_RXDCTL(0), "RXDCTL"},
177 {IXGBE_RDBAL(0), "RDBAL"},
178 {IXGBE_RDBAH(0), "RDBAH"},
181 {IXGBE_TDBAL(0), "TDBAL"},
182 {IXGBE_TDBAH(0), "TDBAH"},
183 {IXGBE_TDLEN(0), "TDLEN"},
184 {IXGBE_TDH(0), "TDH"},
185 {IXGBE_TDT(0), "TDT"},
186 {IXGBE_TXDCTL(0), "TXDCTL"},
188 /* List Terminator */
194 * ixgbe_regdump - register printout routine
196 static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
202 switch (reginfo->ofs) {
203 case IXGBE_SRRCTL(0):
204 for (i = 0; i < 64; i++)
205 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
207 case IXGBE_DCA_RXCTRL(0):
208 for (i = 0; i < 64; i++)
209 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
212 for (i = 0; i < 64; i++)
213 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
216 for (i = 0; i < 64; i++)
217 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
220 for (i = 0; i < 64; i++)
221 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
223 case IXGBE_RXDCTL(0):
224 for (i = 0; i < 64; i++)
225 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
228 for (i = 0; i < 64; i++)
229 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
232 for (i = 0; i < 64; i++)
233 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
236 for (i = 0; i < 64; i++)
237 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
240 for (i = 0; i < 64; i++)
241 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
244 for (i = 0; i < 64; i++)
245 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
248 for (i = 0; i < 64; i++)
249 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
252 for (i = 0; i < 64; i++)
253 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
255 case IXGBE_TXDCTL(0):
256 for (i = 0; i < 64; i++)
257 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
260 pr_info("%-15s %08x\n", reginfo->name,
261 IXGBE_READ_REG(hw, reginfo->ofs));
265 for (i = 0; i < 8; i++) {
266 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
267 pr_err("%-15s", rname);
268 for (j = 0; j < 8; j++)
269 pr_cont(" %08x", regs[i*8+j]);
276 * ixgbe_dump - Print registers, tx-rings and rx-rings
278 static void ixgbe_dump(struct ixgbe_adapter *adapter)
280 struct net_device *netdev = adapter->netdev;
281 struct ixgbe_hw *hw = &adapter->hw;
282 struct ixgbe_reg_info *reginfo;
284 struct ixgbe_ring *tx_ring;
285 struct ixgbe_tx_buffer *tx_buffer_info;
286 union ixgbe_adv_tx_desc *tx_desc;
287 struct my_u0 { u64 a; u64 b; } *u0;
288 struct ixgbe_ring *rx_ring;
289 union ixgbe_adv_rx_desc *rx_desc;
290 struct ixgbe_rx_buffer *rx_buffer_info;
294 if (!netif_msg_hw(adapter))
297 /* Print netdevice Info */
299 dev_info(&adapter->pdev->dev, "Net device Info\n");
300 pr_info("Device Name state "
301 "trans_start last_rx\n");
302 pr_info("%-15s %016lX %016lX %016lX\n",
309 /* Print Registers */
310 dev_info(&adapter->pdev->dev, "Register Dump\n");
311 pr_info(" Register Name Value\n");
312 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
313 reginfo->name; reginfo++) {
314 ixgbe_regdump(hw, reginfo);
317 /* Print TX Ring Summary */
318 if (!netdev || !netif_running(netdev))
321 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
322 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
323 for (n = 0; n < adapter->num_tx_queues; n++) {
324 tx_ring = adapter->tx_ring[n];
326 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
327 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
328 n, tx_ring->next_to_use, tx_ring->next_to_clean,
329 (u64)tx_buffer_info->dma,
330 tx_buffer_info->length,
331 tx_buffer_info->next_to_watch,
332 (u64)tx_buffer_info->time_stamp);
336 if (!netif_msg_tx_done(adapter))
337 goto rx_ring_summary;
339 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
341 /* Transmit Descriptor Formats
343 * Advanced Transmit Descriptor
344 * +--------------------------------------------------------------+
345 * 0 | Buffer Address [63:0] |
346 * +--------------------------------------------------------------+
347 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
348 * +--------------------------------------------------------------+
349 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
352 for (n = 0; n < adapter->num_tx_queues; n++) {
353 tx_ring = adapter->tx_ring[n];
354 pr_info("------------------------------------\n");
355 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
356 pr_info("------------------------------------\n");
357 pr_info("T [desc] [address 63:0 ] "
358 "[PlPOIdStDDt Ln] [bi->dma ] "
359 "leng ntw timestamp bi->skb\n");
361 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
362 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
363 tx_buffer_info = &tx_ring->tx_buffer_info[i];
364 u0 = (struct my_u0 *)tx_desc;
365 pr_info("T [0x%03X] %016llX %016llX %016llX"
366 " %04X %p %016llX %p", i,
369 (u64)tx_buffer_info->dma,
370 tx_buffer_info->length,
371 tx_buffer_info->next_to_watch,
372 (u64)tx_buffer_info->time_stamp,
373 tx_buffer_info->skb);
374 if (i == tx_ring->next_to_use &&
375 i == tx_ring->next_to_clean)
377 else if (i == tx_ring->next_to_use)
379 else if (i == tx_ring->next_to_clean)
384 if (netif_msg_pktdata(adapter) &&
385 tx_buffer_info->dma != 0)
386 print_hex_dump(KERN_INFO, "",
387 DUMP_PREFIX_ADDRESS, 16, 1,
388 phys_to_virt(tx_buffer_info->dma),
389 tx_buffer_info->length, true);
393 /* Print RX Rings Summary */
395 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
396 pr_info("Queue [NTU] [NTC]\n");
397 for (n = 0; n < adapter->num_rx_queues; n++) {
398 rx_ring = adapter->rx_ring[n];
399 pr_info("%5d %5X %5X\n",
400 n, rx_ring->next_to_use, rx_ring->next_to_clean);
404 if (!netif_msg_rx_status(adapter))
407 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
409 /* Advanced Receive Descriptor (Read) Format
411 * +-----------------------------------------------------+
412 * 0 | Packet Buffer Address [63:1] |A0/NSE|
413 * +----------------------------------------------+------+
414 * 8 | Header Buffer Address [63:1] | DD |
415 * +-----------------------------------------------------+
418 * Advanced Receive Descriptor (Write-Back) Format
420 * 63 48 47 32 31 30 21 20 16 15 4 3 0
421 * +------------------------------------------------------+
422 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
423 * | Checksum Ident | | | | Type | Type |
424 * +------------------------------------------------------+
425 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
426 * +------------------------------------------------------+
427 * 63 48 47 32 31 20 19 0
429 for (n = 0; n < adapter->num_rx_queues; n++) {
430 rx_ring = adapter->rx_ring[n];
431 pr_info("------------------------------------\n");
432 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
433 pr_info("------------------------------------\n");
434 pr_info("R [desc] [ PktBuf A0] "
435 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
436 "<-- Adv Rx Read format\n");
437 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
438 "[vl er S cks ln] ---------------- [bi->skb] "
439 "<-- Adv Rx Write-Back format\n");
441 for (i = 0; i < rx_ring->count; i++) {
442 rx_buffer_info = &rx_ring->rx_buffer_info[i];
443 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
444 u0 = (struct my_u0 *)rx_desc;
445 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
446 if (staterr & IXGBE_RXD_STAT_DD) {
447 /* Descriptor Done */
448 pr_info("RWB[0x%03X] %016llX "
449 "%016llX ---------------- %p", i,
452 rx_buffer_info->skb);
454 pr_info("R [0x%03X] %016llX "
455 "%016llX %016llX %p", i,
458 (u64)rx_buffer_info->dma,
459 rx_buffer_info->skb);
461 if (netif_msg_pktdata(adapter)) {
462 print_hex_dump(KERN_INFO, "",
463 DUMP_PREFIX_ADDRESS, 16, 1,
464 phys_to_virt(rx_buffer_info->dma),
465 rx_ring->rx_buf_len, true);
467 if (rx_ring->rx_buf_len
469 print_hex_dump(KERN_INFO, "",
470 DUMP_PREFIX_ADDRESS, 16, 1,
472 rx_buffer_info->page_dma +
473 rx_buffer_info->page_offset
479 if (i == rx_ring->next_to_use)
481 else if (i == rx_ring->next_to_clean)
493 static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
497 /* Let firmware take over control of h/w */
498 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
499 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
500 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
503 static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
507 /* Let firmware know the driver has taken over */
508 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
509 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
510 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
514 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
515 * @adapter: pointer to adapter struct
516 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
517 * @queue: queue to map the corresponding interrupt to
518 * @msix_vector: the vector to map to the corresponding queue
521 static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
522 u8 queue, u8 msix_vector)
525 struct ixgbe_hw *hw = &adapter->hw;
526 switch (hw->mac.type) {
527 case ixgbe_mac_82598EB:
528 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
531 index = (((direction * 64) + queue) >> 2) & 0x1F;
532 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
533 ivar &= ~(0xFF << (8 * (queue & 0x3)));
534 ivar |= (msix_vector << (8 * (queue & 0x3)));
535 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
537 case ixgbe_mac_82599EB:
539 if (direction == -1) {
541 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
542 index = ((queue & 1) * 8);
543 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
544 ivar &= ~(0xFF << index);
545 ivar |= (msix_vector << index);
546 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
549 /* tx or rx causes */
550 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
551 index = ((16 * (queue & 1)) + (8 * direction));
552 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
553 ivar &= ~(0xFF << index);
554 ivar |= (msix_vector << index);
555 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
563 static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
568 switch (adapter->hw.mac.type) {
569 case ixgbe_mac_82598EB:
570 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
571 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
573 case ixgbe_mac_82599EB:
575 mask = (qmask & 0xFFFFFFFF);
576 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
577 mask = (qmask >> 32);
578 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
585 static inline void ixgbe_unmap_tx_resource(struct ixgbe_ring *ring,
586 struct ixgbe_tx_buffer *tx_buffer)
588 if (tx_buffer->dma) {
589 if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_MAPPED_AS_PAGE)
590 dma_unmap_page(ring->dev,
595 dma_unmap_single(ring->dev,
603 void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
604 struct ixgbe_tx_buffer *tx_buffer_info)
606 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
607 if (tx_buffer_info->skb)
608 dev_kfree_skb_any(tx_buffer_info->skb);
609 tx_buffer_info->skb = NULL;
610 /* tx_buffer_info must be completely set up in the transmit path */
613 static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
615 struct ixgbe_hw *hw = &adapter->hw;
616 struct ixgbe_hw_stats *hwstats = &adapter->stats;
621 if ((hw->fc.current_mode == ixgbe_fc_full) ||
622 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
623 switch (hw->mac.type) {
624 case ixgbe_mac_82598EB:
625 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
628 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
630 hwstats->lxoffrxc += data;
632 /* refill credits (no tx hang) if we received xoff */
636 for (i = 0; i < adapter->num_tx_queues; i++)
637 clear_bit(__IXGBE_HANG_CHECK_ARMED,
638 &adapter->tx_ring[i]->state);
640 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
643 /* update stats for each tc, only valid with PFC enabled */
644 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
645 switch (hw->mac.type) {
646 case ixgbe_mac_82598EB:
647 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
650 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
652 hwstats->pxoffrxc[i] += xoff[i];
655 /* disarm tx queues that have received xoff frames */
656 for (i = 0; i < adapter->num_tx_queues; i++) {
657 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
658 u8 tc = tx_ring->dcb_tc;
661 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
665 static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
667 return ring->tx_stats.completed;
670 static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
672 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
673 struct ixgbe_hw *hw = &adapter->hw;
675 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
676 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
679 return (head < tail) ?
680 tail - head : (tail + ring->count - head);
685 static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
687 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
688 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
689 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
692 clear_check_for_tx_hang(tx_ring);
695 * Check for a hung queue, but be thorough. This verifies
696 * that a transmit has been completed since the previous
697 * check AND there is at least one packet pending. The
698 * ARMED bit is set to indicate a potential hang. The
699 * bit is cleared if a pause frame is received to remove
700 * false hang detection due to PFC or 802.3x frames. By
701 * requiring this to fail twice we avoid races with
702 * pfc clearing the ARMED bit and conditions where we
703 * run the check_tx_hang logic with a transmit completion
704 * pending but without time to complete it yet.
706 if ((tx_done_old == tx_done) && tx_pending) {
707 /* make sure it is true for two checks in a row */
708 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
711 /* update completed stats and continue */
712 tx_ring->tx_stats.tx_done_old = tx_done;
713 /* reset the countdown */
714 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
721 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
722 * @adapter: driver private struct
724 static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
727 /* Do the reset outside of interrupt context */
728 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
729 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
730 ixgbe_service_event_schedule(adapter);
735 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
736 * @q_vector: structure containing interrupt and ring information
737 * @tx_ring: tx ring to clean
739 static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
740 struct ixgbe_ring *tx_ring)
742 struct ixgbe_adapter *adapter = q_vector->adapter;
743 struct ixgbe_tx_buffer *tx_buffer;
744 union ixgbe_adv_tx_desc *tx_desc;
745 unsigned int total_bytes = 0, total_packets = 0;
746 unsigned int budget = q_vector->tx.work_limit;
747 u16 i = tx_ring->next_to_clean;
749 tx_buffer = &tx_ring->tx_buffer_info[i];
750 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
752 for (; budget; budget--) {
753 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
755 /* if next_to_watch is not set then there is no work pending */
759 /* if DD is not set pending work has not been completed */
760 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
763 /* count the packet as being completed */
764 tx_ring->tx_stats.completed++;
766 /* clear next_to_watch to prevent false hangs */
767 tx_buffer->next_to_watch = NULL;
769 /* prevent any other reads prior to eop_desc being verified */
773 ixgbe_unmap_tx_resource(tx_ring, tx_buffer);
774 tx_desc->wb.status = 0;
775 if (likely(tx_desc == eop_desc)) {
777 dev_kfree_skb_any(tx_buffer->skb);
778 tx_buffer->skb = NULL;
780 total_bytes += tx_buffer->bytecount;
781 total_packets += tx_buffer->gso_segs;
787 if (unlikely(i == tx_ring->count)) {
790 tx_buffer = tx_ring->tx_buffer_info;
791 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
797 tx_ring->next_to_clean = i;
798 u64_stats_update_begin(&tx_ring->syncp);
799 tx_ring->stats.bytes += total_bytes;
800 tx_ring->stats.packets += total_packets;
801 u64_stats_update_end(&tx_ring->syncp);
802 q_vector->tx.total_bytes += total_bytes;
803 q_vector->tx.total_packets += total_packets;
805 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
806 /* schedule immediate reset if we believe we hung */
807 struct ixgbe_hw *hw = &adapter->hw;
808 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
809 e_err(drv, "Detected Tx Unit Hang\n"
811 " TDH, TDT <%x>, <%x>\n"
812 " next_to_use <%x>\n"
813 " next_to_clean <%x>\n"
814 "tx_buffer_info[next_to_clean]\n"
815 " time_stamp <%lx>\n"
817 tx_ring->queue_index,
818 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
819 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
820 tx_ring->next_to_use, i,
821 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
823 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
826 "tx hang %d detected on queue %d, resetting adapter\n",
827 adapter->tx_timeout_count + 1, tx_ring->queue_index);
829 /* schedule immediate reset if we believe we hung */
830 ixgbe_tx_timeout_reset(adapter);
832 /* the adapter is about to reset, no point in enabling stuff */
836 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
837 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
838 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
839 /* Make sure that anybody stopping the queue after this
840 * sees the new next_to_clean.
843 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
844 !test_bit(__IXGBE_DOWN, &adapter->state)) {
845 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
846 ++tx_ring->tx_stats.restart_queue;
853 #ifdef CONFIG_IXGBE_DCA
854 static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
855 struct ixgbe_ring *rx_ring,
858 struct ixgbe_hw *hw = &adapter->hw;
860 u8 reg_idx = rx_ring->reg_idx;
862 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
863 switch (hw->mac.type) {
864 case ixgbe_mac_82598EB:
865 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
866 rxctrl |= dca3_get_tag(rx_ring->dev, cpu);
868 case ixgbe_mac_82599EB:
870 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
871 rxctrl |= (dca3_get_tag(rx_ring->dev, cpu) <<
872 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
877 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
878 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
879 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
880 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
883 static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
884 struct ixgbe_ring *tx_ring,
887 struct ixgbe_hw *hw = &adapter->hw;
889 u8 reg_idx = tx_ring->reg_idx;
891 switch (hw->mac.type) {
892 case ixgbe_mac_82598EB:
893 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
894 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
895 txctrl |= dca3_get_tag(tx_ring->dev, cpu);
896 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
897 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
899 case ixgbe_mac_82599EB:
901 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
902 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
903 txctrl |= (dca3_get_tag(tx_ring->dev, cpu) <<
904 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
905 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
906 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
913 static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
915 struct ixgbe_adapter *adapter = q_vector->adapter;
916 struct ixgbe_ring *ring;
919 if (q_vector->cpu == cpu)
922 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
923 ixgbe_update_tx_dca(adapter, ring, cpu);
925 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
926 ixgbe_update_rx_dca(adapter, ring, cpu);
933 static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
938 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
941 /* always use CB2 mode, difference is masked in the CB driver */
942 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
944 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
945 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
949 for (i = 0; i < num_q_vectors; i++) {
950 adapter->q_vector[i]->cpu = -1;
951 ixgbe_update_dca(adapter->q_vector[i]);
955 static int __ixgbe_notify_dca(struct device *dev, void *data)
957 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
958 unsigned long event = *(unsigned long *)data;
960 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
964 case DCA_PROVIDER_ADD:
965 /* if we're already enabled, don't do it again */
966 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
968 if (dca_add_requester(dev) == 0) {
969 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
970 ixgbe_setup_dca(adapter);
973 /* Fall Through since DCA is disabled. */
974 case DCA_PROVIDER_REMOVE:
975 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
976 dca_remove_requester(dev);
977 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
978 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
985 #endif /* CONFIG_IXGBE_DCA */
987 static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
990 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
994 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
995 * @adapter: address of board private structure
996 * @rx_desc: advanced rx descriptor
998 * Returns : true if it is FCoE pkt
1000 static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1001 union ixgbe_adv_rx_desc *rx_desc)
1003 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1005 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1006 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1007 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1008 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1012 * ixgbe_receive_skb - Send a completed packet up the stack
1013 * @adapter: board private structure
1014 * @skb: packet to send up
1015 * @status: hardware indication of status of receive
1016 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1017 * @rx_desc: rx descriptor
1019 static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
1020 struct sk_buff *skb, u8 status,
1021 struct ixgbe_ring *ring,
1022 union ixgbe_adv_rx_desc *rx_desc)
1024 struct ixgbe_adapter *adapter = q_vector->adapter;
1025 struct napi_struct *napi = &q_vector->napi;
1026 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
1027 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
1029 if (is_vlan && (tag & VLAN_VID_MASK))
1030 __vlan_hwaccel_put_tag(skb, tag);
1032 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1033 napi_gro_receive(napi, skb);
1039 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1040 * @adapter: address of board private structure
1041 * @status_err: hardware indication of status of receive
1042 * @skb: skb currently being received and modified
1043 * @status_err: status error value of last descriptor in packet
1045 static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
1046 union ixgbe_adv_rx_desc *rx_desc,
1047 struct sk_buff *skb,
1050 skb->ip_summed = CHECKSUM_NONE;
1052 /* Rx csum disabled */
1053 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
1056 /* if IP and error */
1057 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
1058 (status_err & IXGBE_RXDADV_ERR_IPE)) {
1059 adapter->hw_csum_rx_error++;
1063 if (!(status_err & IXGBE_RXD_STAT_L4CS))
1066 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
1067 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1070 * 82599 errata, UDP frames with a 0 checksum can be marked as
1073 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1074 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1077 adapter->hw_csum_rx_error++;
1081 /* It must be a TCP or UDP packet with a valid checksum */
1082 skb->ip_summed = CHECKSUM_UNNECESSARY;
1085 static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
1088 * Force memory writes to complete before letting h/w
1089 * know there are new descriptors to fetch. (Only
1090 * applicable for weak-ordered memory model archs,
1094 writel(val, rx_ring->tail);
1098 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
1099 * @rx_ring: ring to place buffers on
1100 * @cleaned_count: number of buffers to replace
1102 void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
1104 union ixgbe_adv_rx_desc *rx_desc;
1105 struct ixgbe_rx_buffer *bi;
1106 struct sk_buff *skb;
1107 u16 i = rx_ring->next_to_use;
1109 /* do nothing if no valid netdev defined */
1110 if (!rx_ring->netdev)
1113 while (cleaned_count--) {
1114 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
1115 bi = &rx_ring->rx_buffer_info[i];
1119 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1120 rx_ring->rx_buf_len);
1122 rx_ring->rx_stats.alloc_rx_buff_failed++;
1125 /* initialize queue mapping */
1126 skb_record_rx_queue(skb, rx_ring->queue_index);
1131 bi->dma = dma_map_single(rx_ring->dev,
1133 rx_ring->rx_buf_len,
1135 if (dma_mapping_error(rx_ring->dev, bi->dma)) {
1136 rx_ring->rx_stats.alloc_rx_buff_failed++;
1142 if (ring_is_ps_enabled(rx_ring)) {
1144 bi->page = netdev_alloc_page(rx_ring->netdev);
1146 rx_ring->rx_stats.alloc_rx_page_failed++;
1151 if (!bi->page_dma) {
1152 /* use a half page if we're re-using */
1153 bi->page_offset ^= PAGE_SIZE / 2;
1154 bi->page_dma = dma_map_page(rx_ring->dev,
1159 if (dma_mapping_error(rx_ring->dev,
1161 rx_ring->rx_stats.alloc_rx_page_failed++;
1167 /* Refresh the desc even if buffer_addrs didn't change
1168 * because each write-back erases this info. */
1169 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
1170 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
1172 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
1173 rx_desc->read.hdr_addr = 0;
1177 if (i == rx_ring->count)
1182 if (rx_ring->next_to_use != i) {
1183 rx_ring->next_to_use = i;
1184 ixgbe_release_rx_desc(rx_ring, i);
1188 static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
1190 /* HW will not DMA in data larger than the given buffer, even if it
1191 * parses the (NFS, of course) header to be larger. In that case, it
1192 * fills the header buffer and spills the rest into the page.
1194 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1195 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1196 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1197 if (hlen > IXGBE_RX_HDR_SIZE)
1198 hlen = IXGBE_RX_HDR_SIZE;
1203 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1204 * @skb: pointer to the last skb in the rsc queue
1206 * This function changes a queue full of hw rsc buffers into a completed
1207 * packet. It uses the ->prev pointers to find the first packet and then
1208 * turns it into the frag list owner.
1210 static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
1212 unsigned int frag_list_size = 0;
1213 unsigned int skb_cnt = 1;
1216 struct sk_buff *prev = skb->prev;
1217 frag_list_size += skb->len;
1223 skb_shinfo(skb)->frag_list = skb->next;
1225 skb->len += frag_list_size;
1226 skb->data_len += frag_list_size;
1227 skb->truesize += frag_list_size;
1228 IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt;
1233 static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc)
1235 return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
1236 IXGBE_RXDADV_RSCCNT_MASK);
1239 static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
1240 struct ixgbe_ring *rx_ring,
1243 struct ixgbe_adapter *adapter = q_vector->adapter;
1244 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
1245 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
1246 struct sk_buff *skb;
1247 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1248 const int current_node = numa_node_id();
1251 #endif /* IXGBE_FCOE */
1254 u16 cleaned_count = 0;
1255 bool pkt_is_rsc = false;
1257 i = rx_ring->next_to_clean;
1258 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
1259 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1261 while (staterr & IXGBE_RXD_STAT_DD) {
1264 rmb(); /* read descriptor and rx_buffer_info after status DD */
1266 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1268 skb = rx_buffer_info->skb;
1269 rx_buffer_info->skb = NULL;
1270 prefetch(skb->data);
1272 if (ring_is_rsc_enabled(rx_ring))
1273 pkt_is_rsc = ixgbe_get_rsc_state(rx_desc);
1275 /* linear means we are building an skb from multiple pages */
1276 if (!skb_is_nonlinear(skb)) {
1279 !(staterr & IXGBE_RXD_STAT_EOP) &&
1282 * When HWRSC is enabled, delay unmapping
1283 * of the first packet. It carries the
1284 * header information, HW may still
1285 * access the header after the writeback.
1286 * Only unmap it when EOP is reached
1288 IXGBE_RSC_CB(skb)->delay_unmap = true;
1289 IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
1291 dma_unmap_single(rx_ring->dev,
1292 rx_buffer_info->dma,
1293 rx_ring->rx_buf_len,
1296 rx_buffer_info->dma = 0;
1298 if (ring_is_ps_enabled(rx_ring)) {
1299 hlen = ixgbe_get_hlen(rx_desc);
1300 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1302 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1307 /* assume packet split since header is unmapped */
1308 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1312 dma_unmap_page(rx_ring->dev,
1313 rx_buffer_info->page_dma,
1316 rx_buffer_info->page_dma = 0;
1317 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
1318 rx_buffer_info->page,
1319 rx_buffer_info->page_offset,
1322 if ((page_count(rx_buffer_info->page) == 1) &&
1323 (page_to_nid(rx_buffer_info->page) == current_node))
1324 get_page(rx_buffer_info->page);
1326 rx_buffer_info->page = NULL;
1328 skb->len += upper_len;
1329 skb->data_len += upper_len;
1330 skb->truesize += PAGE_SIZE / 2;
1334 if (i == rx_ring->count)
1337 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
1342 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
1343 IXGBE_RXDADV_NEXTP_SHIFT;
1344 next_buffer = &rx_ring->rx_buffer_info[nextp];
1346 next_buffer = &rx_ring->rx_buffer_info[i];
1349 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
1350 if (ring_is_ps_enabled(rx_ring)) {
1351 rx_buffer_info->skb = next_buffer->skb;
1352 rx_buffer_info->dma = next_buffer->dma;
1353 next_buffer->skb = skb;
1354 next_buffer->dma = 0;
1356 skb->next = next_buffer->skb;
1357 skb->next->prev = skb;
1359 rx_ring->rx_stats.non_eop_descs++;
1364 skb = ixgbe_transform_rsc_queue(skb);
1365 /* if we got here without RSC the packet is invalid */
1367 __pskb_trim(skb, 0);
1368 rx_buffer_info->skb = skb;
1373 if (ring_is_rsc_enabled(rx_ring)) {
1374 if (IXGBE_RSC_CB(skb)->delay_unmap) {
1375 dma_unmap_single(rx_ring->dev,
1376 IXGBE_RSC_CB(skb)->dma,
1377 rx_ring->rx_buf_len,
1379 IXGBE_RSC_CB(skb)->dma = 0;
1380 IXGBE_RSC_CB(skb)->delay_unmap = false;
1384 if (ring_is_ps_enabled(rx_ring))
1385 rx_ring->rx_stats.rsc_count +=
1386 skb_shinfo(skb)->nr_frags;
1388 rx_ring->rx_stats.rsc_count +=
1389 IXGBE_RSC_CB(skb)->skb_cnt;
1390 rx_ring->rx_stats.rsc_flush++;
1393 /* ERR_MASK will only have valid bits if EOP set */
1394 if (unlikely(staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)) {
1395 dev_kfree_skb_any(skb);
1399 ixgbe_rx_checksum(adapter, rx_desc, skb, staterr);
1400 if (adapter->netdev->features & NETIF_F_RXHASH)
1401 ixgbe_rx_hash(rx_desc, skb);
1403 /* probably a little skewed due to removing CRC */
1404 total_rx_bytes += skb->len;
1407 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
1409 /* if ddp, not passing to ULD unless for FCP_RSP or error */
1410 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
1411 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb,
1414 dev_kfree_skb_any(skb);
1418 #endif /* IXGBE_FCOE */
1419 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
1423 rx_desc->wb.upper.status_error = 0;
1428 /* return some buffers to hardware, one at a time is too slow */
1429 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1430 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1434 /* use prefetched values */
1436 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
1439 rx_ring->next_to_clean = i;
1440 cleaned_count = ixgbe_desc_unused(rx_ring);
1443 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1446 /* include DDPed FCoE data */
1447 if (ddp_bytes > 0) {
1450 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
1451 sizeof(struct fc_frame_header) -
1452 sizeof(struct fcoe_crc_eof);
1455 total_rx_bytes += ddp_bytes;
1456 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1458 #endif /* IXGBE_FCOE */
1460 u64_stats_update_begin(&rx_ring->syncp);
1461 rx_ring->stats.packets += total_rx_packets;
1462 rx_ring->stats.bytes += total_rx_bytes;
1463 u64_stats_update_end(&rx_ring->syncp);
1464 q_vector->rx.total_packets += total_rx_packets;
1465 q_vector->rx.total_bytes += total_rx_bytes;
1471 * ixgbe_configure_msix - Configure MSI-X hardware
1472 * @adapter: board private structure
1474 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1477 static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1479 struct ixgbe_q_vector *q_vector;
1480 int q_vectors, v_idx;
1483 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1485 /* Populate MSIX to EITR Select */
1486 if (adapter->num_vfs > 32) {
1487 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1488 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1492 * Populate the IVAR table and set the ITR values to the
1493 * corresponding register.
1495 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
1496 struct ixgbe_ring *ring;
1497 q_vector = adapter->q_vector[v_idx];
1499 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
1500 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
1502 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
1503 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
1505 if (q_vector->tx.ring && !q_vector->rx.ring) {
1506 /* tx only vector */
1507 if (adapter->tx_itr_setting == 1)
1508 q_vector->itr = IXGBE_10K_ITR;
1510 q_vector->itr = adapter->tx_itr_setting;
1512 /* rx or rx/tx vector */
1513 if (adapter->rx_itr_setting == 1)
1514 q_vector->itr = IXGBE_20K_ITR;
1516 q_vector->itr = adapter->rx_itr_setting;
1519 ixgbe_write_eitr(q_vector);
1522 switch (adapter->hw.mac.type) {
1523 case ixgbe_mac_82598EB:
1524 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
1527 case ixgbe_mac_82599EB:
1528 case ixgbe_mac_X540:
1529 ixgbe_set_ivar(adapter, -1, 1, v_idx);
1534 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
1536 /* set up to autoclear timer, and the vectors */
1537 mask = IXGBE_EIMS_ENABLE_MASK;
1538 mask &= ~(IXGBE_EIMS_OTHER |
1539 IXGBE_EIMS_MAILBOX |
1542 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
1545 enum latency_range {
1549 latency_invalid = 255
1553 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1554 * @q_vector: structure containing interrupt and ring information
1555 * @ring_container: structure containing ring performance data
1557 * Stores a new ITR value based on packets and byte
1558 * counts during the last interrupt. The advantage of per interrupt
1559 * computation is faster updates and more accurate ITR for the current
1560 * traffic pattern. Constants in this function were computed
1561 * based on theoretical maximum wire speed and thresholds were set based
1562 * on testing data as well as attempting to minimize response time
1563 * while increasing bulk throughput.
1564 * this functionality is controlled by the InterruptThrottleRate module
1565 * parameter (see ixgbe_param.c)
1567 static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1568 struct ixgbe_ring_container *ring_container)
1571 struct ixgbe_adapter *adapter = q_vector->adapter;
1572 int bytes = ring_container->total_bytes;
1573 int packets = ring_container->total_packets;
1575 u8 itr_setting = ring_container->itr;
1580 /* simple throttlerate management
1581 * 0-20MB/s lowest (100000 ints/s)
1582 * 20-100MB/s low (20000 ints/s)
1583 * 100-1249MB/s bulk (8000 ints/s)
1585 /* what was last interrupt timeslice? */
1586 timepassed_us = q_vector->itr >> 2;
1587 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1589 switch (itr_setting) {
1590 case lowest_latency:
1591 if (bytes_perint > adapter->eitr_low)
1592 itr_setting = low_latency;
1595 if (bytes_perint > adapter->eitr_high)
1596 itr_setting = bulk_latency;
1597 else if (bytes_perint <= adapter->eitr_low)
1598 itr_setting = lowest_latency;
1601 if (bytes_perint <= adapter->eitr_high)
1602 itr_setting = low_latency;
1606 /* clear work counters since we have the values we need */
1607 ring_container->total_bytes = 0;
1608 ring_container->total_packets = 0;
1610 /* write updated itr to ring container */
1611 ring_container->itr = itr_setting;
1615 * ixgbe_write_eitr - write EITR register in hardware specific way
1616 * @q_vector: structure containing interrupt and ring information
1618 * This function is made to be called by ethtool and by the driver
1619 * when it needs to update EITR registers at runtime. Hardware
1620 * specific quirks/differences are taken care of here.
1622 void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
1624 struct ixgbe_adapter *adapter = q_vector->adapter;
1625 struct ixgbe_hw *hw = &adapter->hw;
1626 int v_idx = q_vector->v_idx;
1627 u32 itr_reg = q_vector->itr;
1629 switch (adapter->hw.mac.type) {
1630 case ixgbe_mac_82598EB:
1631 /* must write high and low 16 bits to reset counter */
1632 itr_reg |= (itr_reg << 16);
1634 case ixgbe_mac_82599EB:
1635 case ixgbe_mac_X540:
1637 * set the WDIS bit to not clear the timer bits and cause an
1638 * immediate assertion of the interrupt
1640 itr_reg |= IXGBE_EITR_CNT_WDIS;
1645 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1648 static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
1650 u32 new_itr = q_vector->itr;
1653 ixgbe_update_itr(q_vector, &q_vector->tx);
1654 ixgbe_update_itr(q_vector, &q_vector->rx);
1656 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
1658 switch (current_itr) {
1659 /* counts and packets in update_itr are dependent on these numbers */
1660 case lowest_latency:
1661 new_itr = IXGBE_100K_ITR;
1664 new_itr = IXGBE_20K_ITR;
1667 new_itr = IXGBE_8K_ITR;
1673 if (new_itr != q_vector->itr) {
1674 /* do an exponential smoothing */
1675 new_itr = (10 * new_itr * q_vector->itr) /
1676 ((9 * new_itr) + q_vector->itr);
1678 /* save the algorithm value here */
1679 q_vector->itr = new_itr & IXGBE_MAX_EITR;
1681 ixgbe_write_eitr(q_vector);
1686 * ixgbe_check_overtemp_subtask - check for over tempurature
1687 * @adapter: pointer to adapter
1689 static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
1691 struct ixgbe_hw *hw = &adapter->hw;
1692 u32 eicr = adapter->interrupt_event;
1694 if (test_bit(__IXGBE_DOWN, &adapter->state))
1697 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1698 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1701 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1703 switch (hw->device_id) {
1704 case IXGBE_DEV_ID_82599_T3_LOM:
1706 * Since the warning interrupt is for both ports
1707 * we don't have to check if:
1708 * - This interrupt wasn't for our port.
1709 * - We may have missed the interrupt so always have to
1710 * check if we got a LSC
1712 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1713 !(eicr & IXGBE_EICR_LSC))
1716 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1718 bool link_up = false;
1720 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1726 /* Check if this is not due to overtemp */
1727 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1732 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1737 "Network adapter has been stopped because it has over heated. "
1738 "Restart the computer. If the problem persists, "
1739 "power off the system and replace the adapter\n");
1741 adapter->interrupt_event = 0;
1744 static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1746 struct ixgbe_hw *hw = &adapter->hw;
1748 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1749 (eicr & IXGBE_EICR_GPI_SDP1)) {
1750 e_crit(probe, "Fan has stopped, replace the adapter\n");
1751 /* write to clear the interrupt */
1752 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1756 static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
1758 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
1761 switch (adapter->hw.mac.type) {
1762 case ixgbe_mac_82599EB:
1764 * Need to check link state so complete overtemp check
1767 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
1768 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
1769 adapter->interrupt_event = eicr;
1770 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1771 ixgbe_service_event_schedule(adapter);
1775 case ixgbe_mac_X540:
1776 if (!(eicr & IXGBE_EICR_TS))
1784 "Network adapter has been stopped because it has over heated. "
1785 "Restart the computer. If the problem persists, "
1786 "power off the system and replace the adapter\n");
1789 static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1791 struct ixgbe_hw *hw = &adapter->hw;
1793 if (eicr & IXGBE_EICR_GPI_SDP2) {
1794 /* Clear the interrupt */
1795 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1796 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1797 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1798 ixgbe_service_event_schedule(adapter);
1802 if (eicr & IXGBE_EICR_GPI_SDP1) {
1803 /* Clear the interrupt */
1804 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1805 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1806 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1807 ixgbe_service_event_schedule(adapter);
1812 static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1814 struct ixgbe_hw *hw = &adapter->hw;
1817 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1818 adapter->link_check_timeout = jiffies;
1819 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1820 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
1821 IXGBE_WRITE_FLUSH(hw);
1822 ixgbe_service_event_schedule(adapter);
1826 static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1830 struct ixgbe_hw *hw = &adapter->hw;
1832 switch (hw->mac.type) {
1833 case ixgbe_mac_82598EB:
1834 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1835 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1837 case ixgbe_mac_82599EB:
1838 case ixgbe_mac_X540:
1839 mask = (qmask & 0xFFFFFFFF);
1841 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
1842 mask = (qmask >> 32);
1844 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1849 /* skip the flush */
1852 static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
1856 struct ixgbe_hw *hw = &adapter->hw;
1858 switch (hw->mac.type) {
1859 case ixgbe_mac_82598EB:
1860 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1861 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1863 case ixgbe_mac_82599EB:
1864 case ixgbe_mac_X540:
1865 mask = (qmask & 0xFFFFFFFF);
1867 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
1868 mask = (qmask >> 32);
1870 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1875 /* skip the flush */
1879 * ixgbe_irq_enable - Enable default interrupt generation settings
1880 * @adapter: board private structure
1882 static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
1885 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
1887 /* don't reenable LSC while waiting for link */
1888 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
1889 mask &= ~IXGBE_EIMS_LSC;
1891 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
1892 switch (adapter->hw.mac.type) {
1893 case ixgbe_mac_82599EB:
1894 mask |= IXGBE_EIMS_GPI_SDP0;
1896 case ixgbe_mac_X540:
1897 mask |= IXGBE_EIMS_TS;
1902 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1903 mask |= IXGBE_EIMS_GPI_SDP1;
1904 switch (adapter->hw.mac.type) {
1905 case ixgbe_mac_82599EB:
1906 mask |= IXGBE_EIMS_GPI_SDP1;
1907 mask |= IXGBE_EIMS_GPI_SDP2;
1908 case ixgbe_mac_X540:
1909 mask |= IXGBE_EIMS_ECC;
1910 mask |= IXGBE_EIMS_MAILBOX;
1915 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
1916 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
1917 mask |= IXGBE_EIMS_FLOW_DIR;
1919 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1921 ixgbe_irq_enable_queues(adapter, ~0);
1923 IXGBE_WRITE_FLUSH(&adapter->hw);
1926 static irqreturn_t ixgbe_msix_other(int irq, void *data)
1928 struct ixgbe_adapter *adapter = data;
1929 struct ixgbe_hw *hw = &adapter->hw;
1933 * Workaround for Silicon errata. Use clear-by-write instead
1934 * of clear-by-read. Reading with EICS will return the
1935 * interrupt causes without clearing, which later be done
1936 * with the write to EICR.
1938 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1939 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
1941 if (eicr & IXGBE_EICR_LSC)
1942 ixgbe_check_lsc(adapter);
1944 if (eicr & IXGBE_EICR_MAILBOX)
1945 ixgbe_msg_task(adapter);
1947 switch (hw->mac.type) {
1948 case ixgbe_mac_82599EB:
1949 case ixgbe_mac_X540:
1950 if (eicr & IXGBE_EICR_ECC)
1951 e_info(link, "Received unrecoverable ECC Err, please "
1953 /* Handle Flow Director Full threshold interrupt */
1954 if (eicr & IXGBE_EICR_FLOW_DIR) {
1955 int reinit_count = 0;
1957 for (i = 0; i < adapter->num_tx_queues; i++) {
1958 struct ixgbe_ring *ring = adapter->tx_ring[i];
1959 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
1964 /* no more flow director interrupts until after init */
1965 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
1966 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
1967 ixgbe_service_event_schedule(adapter);
1970 ixgbe_check_sfp_event(adapter, eicr);
1971 ixgbe_check_overtemp_event(adapter, eicr);
1977 ixgbe_check_fan_failure(adapter, eicr);
1979 /* re-enable the original interrupt state, no lsc, no queues */
1980 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1981 ixgbe_irq_enable(adapter, false, false);
1986 static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
1988 struct ixgbe_q_vector *q_vector = data;
1990 /* EIAM disabled interrupts (on this vector) for us */
1992 if (q_vector->rx.ring || q_vector->tx.ring)
1993 napi_schedule(&q_vector->napi);
1998 static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
2001 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
2002 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
2004 rx_ring->q_vector = q_vector;
2005 rx_ring->next = q_vector->rx.ring;
2006 q_vector->rx.ring = rx_ring;
2007 q_vector->rx.count++;
2010 static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
2013 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
2014 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
2016 tx_ring->q_vector = q_vector;
2017 tx_ring->next = q_vector->tx.ring;
2018 q_vector->tx.ring = tx_ring;
2019 q_vector->tx.count++;
2020 q_vector->tx.work_limit = a->tx_work_limit;
2024 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2025 * @adapter: board private structure to initialize
2027 * This function maps descriptor rings to the queue-specific vectors
2028 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2029 * one vector per ring/queue, but on a constrained vector budget, we
2030 * group the rings as "efficiently" as possible. You would add new
2031 * mapping configurations in here.
2033 static void ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
2035 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2036 int rxr_remaining = adapter->num_rx_queues, rxr_idx = 0;
2037 int txr_remaining = adapter->num_tx_queues, txr_idx = 0;
2040 /* only one q_vector if MSI-X is disabled. */
2041 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2045 * If we don't have enough vectors for a 1-to-1 mapping, we'll have to
2046 * group them so there are multiple queues per vector.
2048 * Re-adjusting *qpv takes care of the remainder.
2050 for (; v_start < q_vectors && rxr_remaining; v_start++) {
2051 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_start);
2052 for (; rqpv; rqpv--, rxr_idx++, rxr_remaining--)
2053 map_vector_to_rxq(adapter, v_start, rxr_idx);
2057 * If there are not enough q_vectors for each ring to have it's own
2058 * vector then we must pair up Rx/Tx on a each vector
2060 if ((v_start + txr_remaining) > q_vectors)
2063 for (; v_start < q_vectors && txr_remaining; v_start++) {
2064 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_start);
2065 for (; tqpv; tqpv--, txr_idx++, txr_remaining--)
2066 map_vector_to_txq(adapter, v_start, txr_idx);
2071 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2072 * @adapter: board private structure
2074 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2075 * interrupts from the kernel.
2077 static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2079 struct net_device *netdev = adapter->netdev;
2080 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2084 for (vector = 0; vector < q_vectors; vector++) {
2085 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2086 struct msix_entry *entry = &adapter->msix_entries[vector];
2088 if (q_vector->tx.ring && q_vector->rx.ring) {
2089 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2090 "%s-%s-%d", netdev->name, "TxRx", ri++);
2092 } else if (q_vector->rx.ring) {
2093 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2094 "%s-%s-%d", netdev->name, "rx", ri++);
2095 } else if (q_vector->tx.ring) {
2096 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2097 "%s-%s-%d", netdev->name, "tx", ti++);
2099 /* skip this unused q_vector */
2102 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2103 q_vector->name, q_vector);
2105 e_err(probe, "request_irq failed for MSIX interrupt "
2106 "Error: %d\n", err);
2107 goto free_queue_irqs;
2109 /* If Flow Director is enabled, set interrupt affinity */
2110 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2111 /* assign the mask for this irq */
2112 irq_set_affinity_hint(entry->vector,
2113 q_vector->affinity_mask);
2117 err = request_irq(adapter->msix_entries[vector].vector,
2118 ixgbe_msix_other, 0, netdev->name, adapter);
2120 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
2121 goto free_queue_irqs;
2129 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2131 free_irq(adapter->msix_entries[vector].vector,
2132 adapter->q_vector[vector]);
2134 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2135 pci_disable_msix(adapter->pdev);
2136 kfree(adapter->msix_entries);
2137 adapter->msix_entries = NULL;
2142 * ixgbe_intr - legacy mode Interrupt Handler
2143 * @irq: interrupt number
2144 * @data: pointer to a network interface device structure
2146 static irqreturn_t ixgbe_intr(int irq, void *data)
2148 struct ixgbe_adapter *adapter = data;
2149 struct ixgbe_hw *hw = &adapter->hw;
2150 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
2154 * Workaround for silicon errata on 82598. Mask the interrupts
2155 * before the read of EICR.
2157 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2159 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2160 * therefore no explict interrupt disable is necessary */
2161 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
2164 * shared interrupt alert!
2165 * make sure interrupts are enabled because the read will
2166 * have disabled interrupts due to EIAM
2167 * finish the workaround of silicon errata on 82598. Unmask
2168 * the interrupt that we masked before the EICR read.
2170 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2171 ixgbe_irq_enable(adapter, true, true);
2172 return IRQ_NONE; /* Not our interrupt */
2175 if (eicr & IXGBE_EICR_LSC)
2176 ixgbe_check_lsc(adapter);
2178 switch (hw->mac.type) {
2179 case ixgbe_mac_82599EB:
2180 ixgbe_check_sfp_event(adapter, eicr);
2182 case ixgbe_mac_X540:
2183 if (eicr & IXGBE_EICR_ECC)
2184 e_info(link, "Received unrecoverable ECC err, please "
2186 ixgbe_check_overtemp_event(adapter, eicr);
2192 ixgbe_check_fan_failure(adapter, eicr);
2194 if (napi_schedule_prep(&(q_vector->napi))) {
2195 /* would disable interrupts here but EIAM disabled it */
2196 __napi_schedule(&(q_vector->napi));
2200 * re-enable link(maybe) and non-queue interrupts, no flush.
2201 * ixgbe_poll will re-enable the queue interrupts
2204 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2205 ixgbe_irq_enable(adapter, false, false);
2210 static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2212 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2215 /* legacy and MSI only use one vector */
2216 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2219 for (i = 0; i < adapter->num_rx_queues; i++) {
2220 adapter->rx_ring[i]->q_vector = NULL;
2221 adapter->rx_ring[i]->next = NULL;
2223 for (i = 0; i < adapter->num_tx_queues; i++) {
2224 adapter->tx_ring[i]->q_vector = NULL;
2225 adapter->tx_ring[i]->next = NULL;
2228 for (i = 0; i < q_vectors; i++) {
2229 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
2230 memset(&q_vector->rx, 0, sizeof(struct ixgbe_ring_container));
2231 memset(&q_vector->tx, 0, sizeof(struct ixgbe_ring_container));
2236 * ixgbe_request_irq - initialize interrupts
2237 * @adapter: board private structure
2239 * Attempts to configure interrupts using the best available
2240 * capabilities of the hardware and kernel.
2242 static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
2244 struct net_device *netdev = adapter->netdev;
2247 /* map all of the rings to the q_vectors */
2248 ixgbe_map_rings_to_vectors(adapter);
2250 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2251 err = ixgbe_request_msix_irqs(adapter);
2252 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
2253 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
2254 netdev->name, adapter);
2256 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
2257 netdev->name, adapter);
2260 e_err(probe, "request_irq failed, Error %d\n", err);
2262 /* place q_vectors and rings back into a known good state */
2263 ixgbe_reset_q_vectors(adapter);
2269 static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2271 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2274 q_vectors = adapter->num_msix_vectors;
2276 free_irq(adapter->msix_entries[i].vector, adapter);
2279 for (; i >= 0; i--) {
2280 /* free only the irqs that were actually requested */
2281 if (!adapter->q_vector[i]->rx.ring &&
2282 !adapter->q_vector[i]->tx.ring)
2285 /* clear the affinity_mask in the IRQ descriptor */
2286 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2289 free_irq(adapter->msix_entries[i].vector,
2290 adapter->q_vector[i]);
2293 free_irq(adapter->pdev->irq, adapter);
2296 /* clear q_vector state information */
2297 ixgbe_reset_q_vectors(adapter);
2301 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2302 * @adapter: board private structure
2304 static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2306 switch (adapter->hw.mac.type) {
2307 case ixgbe_mac_82598EB:
2308 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
2310 case ixgbe_mac_82599EB:
2311 case ixgbe_mac_X540:
2312 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2313 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
2314 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
2319 IXGBE_WRITE_FLUSH(&adapter->hw);
2320 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2322 for (i = 0; i < adapter->num_msix_vectors; i++)
2323 synchronize_irq(adapter->msix_entries[i].vector);
2325 synchronize_irq(adapter->pdev->irq);
2330 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2333 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2335 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
2338 if (adapter->rx_itr_setting == 1)
2339 q_vector->itr = IXGBE_20K_ITR;
2341 q_vector->itr = adapter->rx_itr_setting;
2343 ixgbe_write_eitr(q_vector);
2345 ixgbe_set_ivar(adapter, 0, 0, 0);
2346 ixgbe_set_ivar(adapter, 1, 0, 0);
2348 e_info(hw, "Legacy interrupt IVAR setup done\n");
2352 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2353 * @adapter: board private structure
2354 * @ring: structure containing ring specific data
2356 * Configure the Tx descriptor ring after a reset.
2358 void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2359 struct ixgbe_ring *ring)
2361 struct ixgbe_hw *hw = &adapter->hw;
2362 u64 tdba = ring->dma;
2364 u32 txdctl = IXGBE_TXDCTL_ENABLE;
2365 u8 reg_idx = ring->reg_idx;
2367 /* disable queue to avoid issues while updating state */
2368 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
2369 IXGBE_WRITE_FLUSH(hw);
2371 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
2372 (tdba & DMA_BIT_MASK(32)));
2373 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2374 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2375 ring->count * sizeof(union ixgbe_adv_tx_desc));
2376 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2377 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
2378 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
2381 * set WTHRESH to encourage burst writeback, it should not be set
2382 * higher than 1 when ITR is 0 as it could cause false TX hangs
2384 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2385 * to or less than the number of on chip descriptors, which is
2388 if (!adapter->tx_itr_setting || !adapter->rx_itr_setting)
2389 txdctl |= (1 << 16); /* WTHRESH = 1 */
2391 txdctl |= (8 << 16); /* WTHRESH = 8 */
2393 /* PTHRESH=32 is needed to avoid a Tx hang with DFP enabled. */
2394 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2395 32; /* PTHRESH = 32 */
2397 /* reinitialize flowdirector state */
2398 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2399 adapter->atr_sample_rate) {
2400 ring->atr_sample_rate = adapter->atr_sample_rate;
2401 ring->atr_count = 0;
2402 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2404 ring->atr_sample_rate = 0;
2407 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2410 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2412 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2413 if (hw->mac.type == ixgbe_mac_82598EB &&
2414 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2417 /* poll to verify queue is enabled */
2419 usleep_range(1000, 2000);
2420 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2421 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2423 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
2426 static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2428 struct ixgbe_hw *hw = &adapter->hw;
2431 u8 tcs = netdev_get_num_tc(adapter->netdev);
2433 if (hw->mac.type == ixgbe_mac_82598EB)
2436 /* disable the arbiter while setting MTQC */
2437 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2438 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2439 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2441 /* set transmit pool layout */
2442 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
2443 case (IXGBE_FLAG_SRIOV_ENABLED):
2444 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2445 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2449 reg = IXGBE_MTQC_64Q_1PB;
2451 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2453 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2455 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2457 /* Enable Security TX Buffer IFG for multiple pb */
2459 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2460 reg |= IXGBE_SECTX_DCB;
2461 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2466 /* re-enable the arbiter */
2467 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2468 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2472 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
2473 * @adapter: board private structure
2475 * Configure the Tx unit of the MAC after a reset.
2477 static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2479 struct ixgbe_hw *hw = &adapter->hw;
2483 ixgbe_setup_mtqc(adapter);
2485 if (hw->mac.type != ixgbe_mac_82598EB) {
2486 /* DMATXCTL.EN must be before Tx queues are enabled */
2487 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2488 dmatxctl |= IXGBE_DMATXCTL_TE;
2489 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2492 /* Setup the HW Tx Head and Tail descriptor pointers */
2493 for (i = 0; i < adapter->num_tx_queues; i++)
2494 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
2497 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
2499 static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
2500 struct ixgbe_ring *rx_ring)
2503 u8 reg_idx = rx_ring->reg_idx;
2505 switch (adapter->hw.mac.type) {
2506 case ixgbe_mac_82598EB: {
2507 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2508 const int mask = feature[RING_F_RSS].mask;
2509 reg_idx = reg_idx & mask;
2512 case ixgbe_mac_82599EB:
2513 case ixgbe_mac_X540:
2518 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
2520 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2521 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
2522 if (adapter->num_vfs)
2523 srrctl |= IXGBE_SRRCTL_DROP_EN;
2525 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2526 IXGBE_SRRCTL_BSIZEHDR_MASK;
2528 if (ring_is_ps_enabled(rx_ring)) {
2529 #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2530 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2532 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2534 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
2536 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2537 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2538 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
2541 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
2544 static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
2546 struct ixgbe_hw *hw = &adapter->hw;
2547 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
2548 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2549 0x6A3E67EA, 0x14364D17, 0x3BED200D};
2550 u32 mrqc = 0, reta = 0;
2553 u8 tcs = netdev_get_num_tc(adapter->netdev);
2554 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2557 maxq = min(maxq, adapter->num_tx_queues / tcs);
2559 /* Fill out hash function seeds */
2560 for (i = 0; i < 10; i++)
2561 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
2563 /* Fill out redirection table */
2564 for (i = 0, j = 0; i < 128; i++, j++) {
2567 /* reta = 4-byte sliding window of
2568 * 0x00..(indices-1)(indices-1)00..etc. */
2569 reta = (reta << 8) | (j * 0x11);
2571 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2574 /* Disable indicating checksum in descriptor, enables RSS hash */
2575 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2576 rxcsum |= IXGBE_RXCSUM_PCSD;
2577 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2579 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2580 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
2581 mrqc = IXGBE_MRQC_RSSEN;
2583 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2584 | IXGBE_FLAG_SRIOV_ENABLED);
2587 case (IXGBE_FLAG_RSS_ENABLED):
2589 mrqc = IXGBE_MRQC_RSSEN;
2591 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2593 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2595 case (IXGBE_FLAG_SRIOV_ENABLED):
2596 mrqc = IXGBE_MRQC_VMDQEN;
2603 /* Perform hash on these packet types */
2604 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2605 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2606 | IXGBE_MRQC_RSS_FIELD_IPV6
2607 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2609 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
2613 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2614 * @adapter: address of board private structure
2615 * @index: index of ring to set
2617 static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
2618 struct ixgbe_ring *ring)
2620 struct ixgbe_hw *hw = &adapter->hw;
2623 u8 reg_idx = ring->reg_idx;
2625 if (!ring_is_rsc_enabled(ring))
2628 rx_buf_len = ring->rx_buf_len;
2629 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
2630 rscctrl |= IXGBE_RSCCTL_RSCEN;
2632 * we must limit the number of descriptors so that the
2633 * total size of max desc * buf_len is not greater
2636 if (ring_is_ps_enabled(ring)) {
2637 #if (MAX_SKB_FRAGS > 16)
2638 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2639 #elif (MAX_SKB_FRAGS > 8)
2640 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2641 #elif (MAX_SKB_FRAGS > 4)
2642 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2644 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2647 if (rx_buf_len < IXGBE_RXBUFFER_4K)
2648 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2649 else if (rx_buf_len < IXGBE_RXBUFFER_8K)
2650 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2652 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2654 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
2658 * ixgbe_set_uta - Set unicast filter table address
2659 * @adapter: board private structure
2661 * The unicast table address is a register array of 32-bit registers.
2662 * The table is meant to be used in a way similar to how the MTA is used
2663 * however due to certain limitations in the hardware it is necessary to
2664 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2665 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2667 static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2669 struct ixgbe_hw *hw = &adapter->hw;
2672 /* The UTA table only exists on 82599 hardware and newer */
2673 if (hw->mac.type < ixgbe_mac_82599EB)
2676 /* we only need to do this if VMDq is enabled */
2677 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2680 for (i = 0; i < 128; i++)
2681 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2684 #define IXGBE_MAX_RX_DESC_POLL 10
2685 static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2686 struct ixgbe_ring *ring)
2688 struct ixgbe_hw *hw = &adapter->hw;
2689 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2691 u8 reg_idx = ring->reg_idx;
2693 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2694 if (hw->mac.type == ixgbe_mac_82598EB &&
2695 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2699 usleep_range(1000, 2000);
2700 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2701 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2704 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2705 "the polling period\n", reg_idx);
2709 void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2710 struct ixgbe_ring *ring)
2712 struct ixgbe_hw *hw = &adapter->hw;
2713 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2715 u8 reg_idx = ring->reg_idx;
2717 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2718 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2720 /* write value back with RXDCTL.ENABLE bit cleared */
2721 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2723 if (hw->mac.type == ixgbe_mac_82598EB &&
2724 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2727 /* the hardware may take up to 100us to really disable the rx queue */
2730 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2731 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2734 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2735 "the polling period\n", reg_idx);
2739 void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2740 struct ixgbe_ring *ring)
2742 struct ixgbe_hw *hw = &adapter->hw;
2743 u64 rdba = ring->dma;
2745 u8 reg_idx = ring->reg_idx;
2747 /* disable queue to avoid issues while updating state */
2748 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2749 ixgbe_disable_rx_queue(adapter, ring);
2751 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
2752 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
2753 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
2754 ring->count * sizeof(union ixgbe_adv_rx_desc));
2755 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
2756 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
2757 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
2759 ixgbe_configure_srrctl(adapter, ring);
2760 ixgbe_configure_rscctl(adapter, ring);
2762 /* If operating in IOV mode set RLPML for X540 */
2763 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
2764 hw->mac.type == ixgbe_mac_X540) {
2765 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
2766 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
2767 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
2770 if (hw->mac.type == ixgbe_mac_82598EB) {
2772 * enable cache line friendly hardware writes:
2773 * PTHRESH=32 descriptors (half the internal cache),
2774 * this also removes ugly rx_no_buffer_count increment
2775 * HTHRESH=4 descriptors (to minimize latency on fetch)
2776 * WTHRESH=8 burst writeback up to two cache lines
2778 rxdctl &= ~0x3FFFFF;
2782 /* enable receive descriptor ring */
2783 rxdctl |= IXGBE_RXDCTL_ENABLE;
2784 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2786 ixgbe_rx_desc_queue_enable(adapter, ring);
2787 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
2790 static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
2792 struct ixgbe_hw *hw = &adapter->hw;
2795 /* PSRTYPE must be initialized in non 82598 adapters */
2796 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
2797 IXGBE_PSRTYPE_UDPHDR |
2798 IXGBE_PSRTYPE_IPV4HDR |
2799 IXGBE_PSRTYPE_L2HDR |
2800 IXGBE_PSRTYPE_IPV6HDR;
2802 if (hw->mac.type == ixgbe_mac_82598EB)
2805 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
2806 psrtype |= (adapter->num_rx_queues_per_pool << 29);
2808 for (p = 0; p < adapter->num_rx_pools; p++)
2809 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
2813 static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
2815 struct ixgbe_hw *hw = &adapter->hw;
2818 u32 reg_offset, vf_shift;
2822 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2825 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2826 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
2827 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
2828 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
2830 vf_shift = adapter->num_vfs % 32;
2831 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
2833 /* Enable only the PF's pool for Tx/Rx */
2834 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
2835 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
2836 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
2837 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
2838 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
2840 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
2841 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
2844 * Set up VF register offsets for selected VT Mode,
2845 * i.e. 32 or 64 VFs for SR-IOV
2847 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
2848 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
2849 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
2850 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
2852 /* enable Tx loopback for VF/PF communication */
2853 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
2854 /* Enable MAC Anti-Spoofing */
2855 hw->mac.ops.set_mac_anti_spoofing(hw,
2856 (adapter->num_vfs != 0),
2858 /* For VFs that have spoof checking turned off */
2859 for (i = 0; i < adapter->num_vfs; i++) {
2860 if (!adapter->vfinfo[i].spoofchk_enabled)
2861 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
2865 static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
2867 struct ixgbe_hw *hw = &adapter->hw;
2868 struct net_device *netdev = adapter->netdev;
2869 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
2871 struct ixgbe_ring *rx_ring;
2875 /* Decide whether to use packet split mode or not */
2877 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
2879 /* Do not use packet split if we're in SR-IOV Mode */
2880 if (adapter->num_vfs)
2881 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
2883 /* Disable packet split due to 82599 erratum #45 */
2884 if (hw->mac.type == ixgbe_mac_82599EB)
2885 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
2888 /* adjust max frame to be able to do baby jumbo for FCoE */
2889 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
2890 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
2891 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
2893 #endif /* IXGBE_FCOE */
2894 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
2895 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2896 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2897 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2899 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2902 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
2903 max_frame += VLAN_HLEN;
2905 /* Set the RX buffer length according to the mode */
2906 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
2907 rx_buf_len = IXGBE_RX_HDR_SIZE;
2909 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
2910 (netdev->mtu <= ETH_DATA_LEN))
2911 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
2913 * Make best use of allocation by using all but 1K of a
2914 * power of 2 allocation that will be used for skb->head.
2916 else if (max_frame <= IXGBE_RXBUFFER_3K)
2917 rx_buf_len = IXGBE_RXBUFFER_3K;
2918 else if (max_frame <= IXGBE_RXBUFFER_7K)
2919 rx_buf_len = IXGBE_RXBUFFER_7K;
2920 else if (max_frame <= IXGBE_RXBUFFER_15K)
2921 rx_buf_len = IXGBE_RXBUFFER_15K;
2923 rx_buf_len = IXGBE_MAX_RXBUFFER;
2926 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
2927 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
2928 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
2929 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
2932 * Setup the HW Rx Head and Tail Descriptor Pointers and
2933 * the Base and Length of the Rx Descriptor Ring
2935 for (i = 0; i < adapter->num_rx_queues; i++) {
2936 rx_ring = adapter->rx_ring[i];
2937 rx_ring->rx_buf_len = rx_buf_len;
2939 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
2940 set_ring_ps_enabled(rx_ring);
2942 clear_ring_ps_enabled(rx_ring);
2944 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
2945 set_ring_rsc_enabled(rx_ring);
2947 clear_ring_rsc_enabled(rx_ring);
2950 if (netdev->features & NETIF_F_FCOE_MTU) {
2951 struct ixgbe_ring_feature *f;
2952 f = &adapter->ring_feature[RING_F_FCOE];
2953 if ((i >= f->mask) && (i < f->mask + f->indices)) {
2954 clear_ring_ps_enabled(rx_ring);
2955 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
2956 rx_ring->rx_buf_len =
2957 IXGBE_FCOE_JUMBO_FRAME_SIZE;
2958 } else if (!ring_is_rsc_enabled(rx_ring) &&
2959 !ring_is_ps_enabled(rx_ring)) {
2960 rx_ring->rx_buf_len =
2961 IXGBE_FCOE_JUMBO_FRAME_SIZE;
2964 #endif /* IXGBE_FCOE */
2968 static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
2970 struct ixgbe_hw *hw = &adapter->hw;
2971 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2973 switch (hw->mac.type) {
2974 case ixgbe_mac_82598EB:
2976 * For VMDq support of different descriptor types or
2977 * buffer sizes through the use of multiple SRRCTL
2978 * registers, RDRXCTL.MVMEN must be set to 1
2980 * also, the manual doesn't mention it clearly but DCA hints
2981 * will only use queue 0's tags unless this bit is set. Side
2982 * effects of setting this bit are only that SRRCTL must be
2983 * fully programmed [0..15]
2985 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
2987 case ixgbe_mac_82599EB:
2988 case ixgbe_mac_X540:
2989 /* Disable RSC for ACK packets */
2990 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
2991 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
2992 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
2993 /* hardware requires some bits to be set by default */
2994 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
2995 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
2998 /* We should do nothing since we don't know this hardware */
3002 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3006 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3007 * @adapter: board private structure
3009 * Configure the Rx unit of the MAC after a reset.
3011 static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3013 struct ixgbe_hw *hw = &adapter->hw;
3017 /* disable receives while setting up the descriptors */
3018 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3019 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3021 ixgbe_setup_psrtype(adapter);
3022 ixgbe_setup_rdrxctl(adapter);
3024 /* Program registers for the distribution of queues */
3025 ixgbe_setup_mrqc(adapter);
3027 ixgbe_set_uta(adapter);
3029 /* set_rx_buffer_len must be called before ring initialization */
3030 ixgbe_set_rx_buffer_len(adapter);
3033 * Setup the HW Rx Head and Tail Descriptor Pointers and
3034 * the Base and Length of the Rx Descriptor Ring
3036 for (i = 0; i < adapter->num_rx_queues; i++)
3037 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
3039 /* disable drop enable for 82598 parts */
3040 if (hw->mac.type == ixgbe_mac_82598EB)
3041 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3043 /* enable all receives */
3044 rxctrl |= IXGBE_RXCTRL_RXEN;
3045 hw->mac.ops.enable_rx_dma(hw, rxctrl);
3048 static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3050 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3051 struct ixgbe_hw *hw = &adapter->hw;
3052 int pool_ndx = adapter->num_vfs;
3054 /* add VID to filter table */
3055 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
3056 set_bit(vid, adapter->active_vlans);
3059 static void ixgbe_vlan_rx_kill_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 /* remove VID from filter table */
3066 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
3067 clear_bit(vid, adapter->active_vlans);
3071 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3072 * @adapter: driver data
3074 static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3076 struct ixgbe_hw *hw = &adapter->hw;
3079 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3080 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3081 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3085 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3086 * @adapter: driver data
3088 static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3090 struct ixgbe_hw *hw = &adapter->hw;
3093 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3094 vlnctrl |= IXGBE_VLNCTRL_VFE;
3095 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3096 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3100 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3101 * @adapter: driver data
3103 static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3105 struct ixgbe_hw *hw = &adapter->hw;
3109 switch (hw->mac.type) {
3110 case ixgbe_mac_82598EB:
3111 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3112 vlnctrl &= ~IXGBE_VLNCTRL_VME;
3113 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3115 case ixgbe_mac_82599EB:
3116 case ixgbe_mac_X540:
3117 for (i = 0; i < adapter->num_rx_queues; i++) {
3118 j = adapter->rx_ring[i]->reg_idx;
3119 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3120 vlnctrl &= ~IXGBE_RXDCTL_VME;
3121 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3130 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
3131 * @adapter: driver data
3133 static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
3135 struct ixgbe_hw *hw = &adapter->hw;
3139 switch (hw->mac.type) {
3140 case ixgbe_mac_82598EB:
3141 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3142 vlnctrl |= IXGBE_VLNCTRL_VME;
3143 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3145 case ixgbe_mac_82599EB:
3146 case ixgbe_mac_X540:
3147 for (i = 0; i < adapter->num_rx_queues; i++) {
3148 j = adapter->rx_ring[i]->reg_idx;
3149 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3150 vlnctrl |= IXGBE_RXDCTL_VME;
3151 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3159 static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3163 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3165 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3166 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
3170 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3171 * @netdev: network interface device structure
3173 * Writes unicast address list to the RAR table.
3174 * Returns: -ENOMEM on failure/insufficient address space
3175 * 0 on no addresses written
3176 * X on writing X addresses to the RAR table
3178 static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3180 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3181 struct ixgbe_hw *hw = &adapter->hw;
3182 unsigned int vfn = adapter->num_vfs;
3183 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
3186 /* return ENOMEM indicating insufficient memory for addresses */
3187 if (netdev_uc_count(netdev) > rar_entries)
3190 if (!netdev_uc_empty(netdev) && rar_entries) {
3191 struct netdev_hw_addr *ha;
3192 /* return error if we do not support writing to RAR table */
3193 if (!hw->mac.ops.set_rar)
3196 netdev_for_each_uc_addr(ha, netdev) {
3199 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3204 /* write the addresses in reverse order to avoid write combining */
3205 for (; rar_entries > 0 ; rar_entries--)
3206 hw->mac.ops.clear_rar(hw, rar_entries);
3212 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
3213 * @netdev: network interface device structure
3215 * The set_rx_method entry point is called whenever the unicast/multicast
3216 * address list or the network interface flags are updated. This routine is
3217 * responsible for configuring the hardware for proper unicast, multicast and
3220 void ixgbe_set_rx_mode(struct net_device *netdev)
3222 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3223 struct ixgbe_hw *hw = &adapter->hw;
3224 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3227 /* Check for Promiscuous and All Multicast modes */
3229 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3231 /* set all bits that we expect to always be set */
3232 fctrl |= IXGBE_FCTRL_BAM;
3233 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3234 fctrl |= IXGBE_FCTRL_PMCF;
3236 /* clear the bits we are changing the status of */
3237 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3239 if (netdev->flags & IFF_PROMISC) {
3240 hw->addr_ctrl.user_set_promisc = true;
3241 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3242 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
3243 /* don't hardware filter vlans in promisc mode */
3244 ixgbe_vlan_filter_disable(adapter);
3246 if (netdev->flags & IFF_ALLMULTI) {
3247 fctrl |= IXGBE_FCTRL_MPE;
3248 vmolr |= IXGBE_VMOLR_MPE;
3251 * Write addresses to the MTA, if the attempt fails
3252 * then we should just turn on promiscuous mode so
3253 * that we can at least receive multicast traffic
3255 hw->mac.ops.update_mc_addr_list(hw, netdev);
3256 vmolr |= IXGBE_VMOLR_ROMPE;
3258 ixgbe_vlan_filter_enable(adapter);
3259 hw->addr_ctrl.user_set_promisc = false;
3261 * Write addresses to available RAR registers, if there is not
3262 * sufficient space to store all the addresses then enable
3263 * unicast promiscuous mode
3265 count = ixgbe_write_uc_addr_list(netdev);
3267 fctrl |= IXGBE_FCTRL_UPE;
3268 vmolr |= IXGBE_VMOLR_ROPE;
3272 if (adapter->num_vfs) {
3273 ixgbe_restore_vf_multicasts(adapter);
3274 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3275 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3277 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
3280 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3282 if (netdev->features & NETIF_F_HW_VLAN_RX)
3283 ixgbe_vlan_strip_enable(adapter);
3285 ixgbe_vlan_strip_disable(adapter);
3288 static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3291 struct ixgbe_q_vector *q_vector;
3292 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3294 /* legacy and MSI only use one vector */
3295 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3298 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3299 q_vector = adapter->q_vector[q_idx];
3300 napi_enable(&q_vector->napi);
3304 static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3307 struct ixgbe_q_vector *q_vector;
3308 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3310 /* legacy and MSI only use one vector */
3311 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3314 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3315 q_vector = adapter->q_vector[q_idx];
3316 napi_disable(&q_vector->napi);
3320 #ifdef CONFIG_IXGBE_DCB
3322 * ixgbe_configure_dcb - Configure DCB hardware
3323 * @adapter: ixgbe adapter struct
3325 * This is called by the driver on open to configure the DCB hardware.
3326 * This is also called by the gennetlink interface when reconfiguring
3329 static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3331 struct ixgbe_hw *hw = &adapter->hw;
3332 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3334 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3335 if (hw->mac.type == ixgbe_mac_82598EB)
3336 netif_set_gso_max_size(adapter->netdev, 65536);
3340 if (hw->mac.type == ixgbe_mac_82598EB)
3341 netif_set_gso_max_size(adapter->netdev, 32768);
3344 /* Enable VLAN tag insert/strip */
3345 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
3347 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
3350 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3351 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3354 /* reconfigure the hardware */
3355 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
3356 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3358 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3360 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3361 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3362 ixgbe_dcb_hw_ets(&adapter->hw,
3363 adapter->ixgbe_ieee_ets,
3365 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3366 adapter->ixgbe_ieee_pfc->pfc_en,
3367 adapter->ixgbe_ieee_ets->prio_tc);
3370 /* Enable RSS Hash per TC */
3371 if (hw->mac.type != ixgbe_mac_82598EB) {
3375 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3377 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3382 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3384 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3389 /* Additional bittime to account for IXGBE framing */
3390 #define IXGBE_ETH_FRAMING 20
3393 * ixgbe_hpbthresh - calculate high water mark for flow control
3395 * @adapter: board private structure to calculate for
3396 * @pb - packet buffer to calculate
3398 static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3400 struct ixgbe_hw *hw = &adapter->hw;
3401 struct net_device *dev = adapter->netdev;
3402 int link, tc, kb, marker;
3405 /* Calculate max LAN frame size */
3406 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3409 /* FCoE traffic class uses FCOE jumbo frames */
3410 if (dev->features & NETIF_F_FCOE_MTU) {
3413 #ifdef CONFIG_IXGBE_DCB
3414 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
3417 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3418 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3422 /* Calculate delay value for device */
3423 switch (hw->mac.type) {
3424 case ixgbe_mac_X540:
3425 dv_id = IXGBE_DV_X540(link, tc);
3428 dv_id = IXGBE_DV(link, tc);
3432 /* Loopback switch introduces additional latency */
3433 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3434 dv_id += IXGBE_B2BT(tc);
3436 /* Delay value is calculated in bit times convert to KB */
3437 kb = IXGBE_BT2KB(dv_id);
3438 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3440 marker = rx_pba - kb;
3442 /* It is possible that the packet buffer is not large enough
3443 * to provide required headroom. In this case throw an error
3444 * to user and a do the best we can.
3447 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3448 "headroom to support flow control."
3449 "Decrease MTU or number of traffic classes\n", pb);
3457 * ixgbe_lpbthresh - calculate low water mark for for flow control
3459 * @adapter: board private structure to calculate for
3460 * @pb - packet buffer to calculate
3462 static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3464 struct ixgbe_hw *hw = &adapter->hw;
3465 struct net_device *dev = adapter->netdev;
3469 /* Calculate max LAN frame size */
3470 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3472 /* Calculate delay value for device */
3473 switch (hw->mac.type) {
3474 case ixgbe_mac_X540:
3475 dv_id = IXGBE_LOW_DV_X540(tc);
3478 dv_id = IXGBE_LOW_DV(tc);
3482 /* Delay value is calculated in bit times convert to KB */
3483 return IXGBE_BT2KB(dv_id);
3487 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3489 static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3491 struct ixgbe_hw *hw = &adapter->hw;
3492 int num_tc = netdev_get_num_tc(adapter->netdev);
3498 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3500 for (i = 0; i < num_tc; i++) {
3501 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3503 /* Low water marks must not be larger than high water marks */
3504 if (hw->fc.low_water > hw->fc.high_water[i])
3505 hw->fc.low_water = 0;
3509 static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3511 struct ixgbe_hw *hw = &adapter->hw;
3513 u8 tc = netdev_get_num_tc(adapter->netdev);
3515 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3516 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3517 hdrm = 32 << adapter->fdir_pballoc;
3521 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
3522 ixgbe_pbthresh_setup(adapter);
3525 static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3527 struct ixgbe_hw *hw = &adapter->hw;
3528 struct hlist_node *node, *node2;
3529 struct ixgbe_fdir_filter *filter;
3531 spin_lock(&adapter->fdir_perfect_lock);
3533 if (!hlist_empty(&adapter->fdir_filter_list))
3534 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3536 hlist_for_each_entry_safe(filter, node, node2,
3537 &adapter->fdir_filter_list, fdir_node) {
3538 ixgbe_fdir_write_perfect_filter_82599(hw,
3541 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3542 IXGBE_FDIR_DROP_QUEUE :
3543 adapter->rx_ring[filter->action]->reg_idx);
3546 spin_unlock(&adapter->fdir_perfect_lock);
3549 static void ixgbe_configure(struct ixgbe_adapter *adapter)
3551 ixgbe_configure_pb(adapter);
3552 #ifdef CONFIG_IXGBE_DCB
3553 ixgbe_configure_dcb(adapter);
3556 ixgbe_set_rx_mode(adapter->netdev);
3557 ixgbe_restore_vlan(adapter);
3560 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3561 ixgbe_configure_fcoe(adapter);
3563 #endif /* IXGBE_FCOE */
3564 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3565 ixgbe_init_fdir_signature_82599(&adapter->hw,
3566 adapter->fdir_pballoc);
3567 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3568 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3569 adapter->fdir_pballoc);
3570 ixgbe_fdir_filter_restore(adapter);
3573 ixgbe_configure_virtualization(adapter);
3575 ixgbe_configure_tx(adapter);
3576 ixgbe_configure_rx(adapter);
3579 static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3581 switch (hw->phy.type) {
3582 case ixgbe_phy_sfp_avago:
3583 case ixgbe_phy_sfp_ftl:
3584 case ixgbe_phy_sfp_intel:
3585 case ixgbe_phy_sfp_unknown:
3586 case ixgbe_phy_sfp_passive_tyco:
3587 case ixgbe_phy_sfp_passive_unknown:
3588 case ixgbe_phy_sfp_active_unknown:
3589 case ixgbe_phy_sfp_ftl_active:
3592 if (hw->mac.type == ixgbe_mac_82598EB)
3600 * ixgbe_sfp_link_config - set up SFP+ link
3601 * @adapter: pointer to private adapter struct
3603 static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3606 * We are assuming the worst case scenerio here, and that
3607 * is that an SFP was inserted/removed after the reset
3608 * but before SFP detection was enabled. As such the best
3609 * solution is to just start searching as soon as we start
3611 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3612 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
3614 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
3618 * ixgbe_non_sfp_link_config - set up non-SFP+ link
3619 * @hw: pointer to private hardware struct
3621 * Returns 0 on success, negative on failure
3623 static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
3626 bool negotiation, link_up = false;
3627 u32 ret = IXGBE_ERR_LINK_SETUP;
3629 if (hw->mac.ops.check_link)
3630 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3635 autoneg = hw->phy.autoneg_advertised;
3636 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
3637 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3642 if (hw->mac.ops.setup_link)
3643 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
3648 static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
3650 struct ixgbe_hw *hw = &adapter->hw;
3653 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3654 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3656 gpie |= IXGBE_GPIE_EIAME;
3658 * use EIAM to auto-mask when MSI-X interrupt is asserted
3659 * this saves a register write for every interrupt
3661 switch (hw->mac.type) {
3662 case ixgbe_mac_82598EB:
3663 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3665 case ixgbe_mac_82599EB:
3666 case ixgbe_mac_X540:
3668 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3669 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3673 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3674 * specifically only auto mask tx and rx interrupts */
3675 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3678 /* XXX: to interrupt immediately for EICS writes, enable this */
3679 /* gpie |= IXGBE_GPIE_EIMEN; */
3681 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3682 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3683 gpie |= IXGBE_GPIE_VTMODE_64;
3686 /* Enable Thermal over heat sensor interrupt */
3687 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
3688 switch (adapter->hw.mac.type) {
3689 case ixgbe_mac_82599EB:
3690 gpie |= IXGBE_SDP0_GPIEN;
3692 case ixgbe_mac_X540:
3693 gpie |= IXGBE_EIMS_TS;
3700 /* Enable fan failure interrupt */
3701 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
3702 gpie |= IXGBE_SDP1_GPIEN;
3704 if (hw->mac.type == ixgbe_mac_82599EB) {
3705 gpie |= IXGBE_SDP1_GPIEN;
3706 gpie |= IXGBE_SDP2_GPIEN;
3709 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3712 static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
3714 struct ixgbe_hw *hw = &adapter->hw;
3718 ixgbe_get_hw_control(adapter);
3719 ixgbe_setup_gpie(adapter);
3721 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3722 ixgbe_configure_msix(adapter);
3724 ixgbe_configure_msi_and_legacy(adapter);
3726 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3727 if (hw->mac.ops.enable_tx_laser &&
3728 ((hw->phy.multispeed_fiber) ||
3729 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
3730 (hw->mac.type == ixgbe_mac_82599EB))))
3731 hw->mac.ops.enable_tx_laser(hw);
3733 clear_bit(__IXGBE_DOWN, &adapter->state);
3734 ixgbe_napi_enable_all(adapter);
3736 if (ixgbe_is_sfp(hw)) {
3737 ixgbe_sfp_link_config(adapter);
3739 err = ixgbe_non_sfp_link_config(hw);
3741 e_err(probe, "link_config FAILED %d\n", err);
3744 /* clear any pending interrupts, may auto mask */
3745 IXGBE_READ_REG(hw, IXGBE_EICR);
3746 ixgbe_irq_enable(adapter, true, true);
3749 * If this adapter has a fan, check to see if we had a failure
3750 * before we enabled the interrupt.
3752 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3753 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3754 if (esdp & IXGBE_ESDP_SDP1)
3755 e_crit(drv, "Fan has stopped, replace the adapter\n");
3758 /* enable transmits */
3759 netif_tx_start_all_queues(adapter->netdev);
3761 /* bring the link up in the watchdog, this could race with our first
3762 * link up interrupt but shouldn't be a problem */
3763 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3764 adapter->link_check_timeout = jiffies;
3765 mod_timer(&adapter->service_timer, jiffies);
3767 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3768 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3769 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3770 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3773 void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3775 WARN_ON(in_interrupt());
3776 /* put off any impending NetWatchDogTimeout */
3777 adapter->netdev->trans_start = jiffies;
3779 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
3780 usleep_range(1000, 2000);
3781 ixgbe_down(adapter);
3783 * If SR-IOV enabled then wait a bit before bringing the adapter
3784 * back up to give the VFs time to respond to the reset. The
3785 * two second wait is based upon the watchdog timer cycle in
3788 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3791 clear_bit(__IXGBE_RESETTING, &adapter->state);
3794 void ixgbe_up(struct ixgbe_adapter *adapter)
3796 /* hardware has been reset, we need to reload some things */
3797 ixgbe_configure(adapter);
3799 ixgbe_up_complete(adapter);
3802 void ixgbe_reset(struct ixgbe_adapter *adapter)
3804 struct ixgbe_hw *hw = &adapter->hw;
3807 /* lock SFP init bit to prevent race conditions with the watchdog */
3808 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
3809 usleep_range(1000, 2000);
3811 /* clear all SFP and link config related flags while holding SFP_INIT */
3812 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
3813 IXGBE_FLAG2_SFP_NEEDS_RESET);
3814 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3816 err = hw->mac.ops.init_hw(hw);
3819 case IXGBE_ERR_SFP_NOT_PRESENT:
3820 case IXGBE_ERR_SFP_NOT_SUPPORTED:
3822 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
3823 e_dev_err("master disable timed out\n");
3825 case IXGBE_ERR_EEPROM_VERSION:
3826 /* We are running on a pre-production device, log a warning */
3827 e_dev_warn("This device is a pre-production adapter/LOM. "
3828 "Please be aware there may be issuesassociated with "
3829 "your hardware. If you are experiencing problems "
3830 "please contact your Intel or hardware "
3831 "representative who provided you with this "
3835 e_dev_err("Hardware Error: %d\n", err);
3838 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
3840 /* reprogram the RAR[0] in case user changed it. */
3841 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
3846 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
3847 * @rx_ring: ring to free buffers from
3849 static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
3851 struct device *dev = rx_ring->dev;
3855 /* ring already cleared, nothing to do */
3856 if (!rx_ring->rx_buffer_info)
3859 /* Free all the Rx ring sk_buffs */
3860 for (i = 0; i < rx_ring->count; i++) {
3861 struct ixgbe_rx_buffer *rx_buffer_info;
3863 rx_buffer_info = &rx_ring->rx_buffer_info[i];
3864 if (rx_buffer_info->dma) {
3865 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
3866 rx_ring->rx_buf_len,
3868 rx_buffer_info->dma = 0;
3870 if (rx_buffer_info->skb) {
3871 struct sk_buff *skb = rx_buffer_info->skb;
3872 rx_buffer_info->skb = NULL;
3874 struct sk_buff *this = skb;
3875 if (IXGBE_RSC_CB(this)->delay_unmap) {
3876 dma_unmap_single(dev,
3877 IXGBE_RSC_CB(this)->dma,
3878 rx_ring->rx_buf_len,
3880 IXGBE_RSC_CB(this)->dma = 0;
3881 IXGBE_RSC_CB(skb)->delay_unmap = false;
3884 dev_kfree_skb(this);
3887 if (!rx_buffer_info->page)
3889 if (rx_buffer_info->page_dma) {
3890 dma_unmap_page(dev, rx_buffer_info->page_dma,
3891 PAGE_SIZE / 2, DMA_FROM_DEVICE);
3892 rx_buffer_info->page_dma = 0;
3894 put_page(rx_buffer_info->page);
3895 rx_buffer_info->page = NULL;
3896 rx_buffer_info->page_offset = 0;
3899 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
3900 memset(rx_ring->rx_buffer_info, 0, size);
3902 /* Zero out the descriptor ring */
3903 memset(rx_ring->desc, 0, rx_ring->size);
3905 rx_ring->next_to_clean = 0;
3906 rx_ring->next_to_use = 0;
3910 * ixgbe_clean_tx_ring - Free Tx Buffers
3911 * @tx_ring: ring to be cleaned
3913 static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
3915 struct ixgbe_tx_buffer *tx_buffer_info;
3919 /* ring already cleared, nothing to do */
3920 if (!tx_ring->tx_buffer_info)
3923 /* Free all the Tx ring sk_buffs */
3924 for (i = 0; i < tx_ring->count; i++) {
3925 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3926 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
3929 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
3930 memset(tx_ring->tx_buffer_info, 0, size);
3932 /* Zero out the descriptor ring */
3933 memset(tx_ring->desc, 0, tx_ring->size);
3935 tx_ring->next_to_use = 0;
3936 tx_ring->next_to_clean = 0;
3940 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
3941 * @adapter: board private structure
3943 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
3947 for (i = 0; i < adapter->num_rx_queues; i++)
3948 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
3952 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
3953 * @adapter: board private structure
3955 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
3959 for (i = 0; i < adapter->num_tx_queues; i++)
3960 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
3963 static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
3965 struct hlist_node *node, *node2;
3966 struct ixgbe_fdir_filter *filter;
3968 spin_lock(&adapter->fdir_perfect_lock);
3970 hlist_for_each_entry_safe(filter, node, node2,
3971 &adapter->fdir_filter_list, fdir_node) {
3972 hlist_del(&filter->fdir_node);
3975 adapter->fdir_filter_count = 0;
3977 spin_unlock(&adapter->fdir_perfect_lock);
3980 void ixgbe_down(struct ixgbe_adapter *adapter)
3982 struct net_device *netdev = adapter->netdev;
3983 struct ixgbe_hw *hw = &adapter->hw;
3987 /* signal that we are down to the interrupt handler */
3988 set_bit(__IXGBE_DOWN, &adapter->state);
3990 /* disable receives */
3991 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3992 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3994 /* disable all enabled rx queues */
3995 for (i = 0; i < adapter->num_rx_queues; i++)
3996 /* this call also flushes the previous write */
3997 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
3999 usleep_range(10000, 20000);
4001 netif_tx_stop_all_queues(netdev);
4003 /* call carrier off first to avoid false dev_watchdog timeouts */
4004 netif_carrier_off(netdev);
4005 netif_tx_disable(netdev);
4007 ixgbe_irq_disable(adapter);
4009 ixgbe_napi_disable_all(adapter);
4011 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4012 IXGBE_FLAG2_RESET_REQUESTED);
4013 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4015 del_timer_sync(&adapter->service_timer);
4017 if (adapter->num_vfs) {
4018 /* Clear EITR Select mapping */
4019 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4021 /* Mark all the VFs as inactive */
4022 for (i = 0 ; i < adapter->num_vfs; i++)
4023 adapter->vfinfo[i].clear_to_send = 0;
4025 /* ping all the active vfs to let them know we are going down */
4026 ixgbe_ping_all_vfs(adapter);
4028 /* Disable all VFTE/VFRE TX/RX */
4029 ixgbe_disable_tx_rx(adapter);
4032 /* disable transmits in the hardware now that interrupts are off */
4033 for (i = 0; i < adapter->num_tx_queues; i++) {
4034 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
4035 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
4038 /* Disable the Tx DMA engine on 82599 and X540 */
4039 switch (hw->mac.type) {
4040 case ixgbe_mac_82599EB:
4041 case ixgbe_mac_X540:
4042 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
4043 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4044 ~IXGBE_DMATXCTL_TE));
4050 if (!pci_channel_offline(adapter->pdev))
4051 ixgbe_reset(adapter);
4053 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4054 if (hw->mac.ops.disable_tx_laser &&
4055 ((hw->phy.multispeed_fiber) ||
4056 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
4057 (hw->mac.type == ixgbe_mac_82599EB))))
4058 hw->mac.ops.disable_tx_laser(hw);
4060 ixgbe_clean_all_tx_rings(adapter);
4061 ixgbe_clean_all_rx_rings(adapter);
4063 #ifdef CONFIG_IXGBE_DCA
4064 /* since we reset the hardware DCA settings were cleared */
4065 ixgbe_setup_dca(adapter);
4070 * ixgbe_poll - NAPI Rx polling callback
4071 * @napi: structure for representing this polling device
4072 * @budget: how many packets driver is allowed to clean
4074 * This function is used for legacy and MSI, NAPI mode
4076 static int ixgbe_poll(struct napi_struct *napi, int budget)
4078 struct ixgbe_q_vector *q_vector =
4079 container_of(napi, struct ixgbe_q_vector, napi);
4080 struct ixgbe_adapter *adapter = q_vector->adapter;
4081 struct ixgbe_ring *ring;
4082 int per_ring_budget;
4083 bool clean_complete = true;
4085 #ifdef CONFIG_IXGBE_DCA
4086 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4087 ixgbe_update_dca(q_vector);
4090 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
4091 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
4093 /* attempt to distribute budget to each queue fairly, but don't allow
4094 * the budget to go below 1 because we'll exit polling */
4095 if (q_vector->rx.count > 1)
4096 per_ring_budget = max(budget/q_vector->rx.count, 1);
4098 per_ring_budget = budget;
4100 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
4101 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
4104 /* If all work not completed, return budget and keep polling */
4105 if (!clean_complete)
4108 /* all work done, exit the polling mode */
4109 napi_complete(napi);
4110 if (adapter->rx_itr_setting & 1)
4111 ixgbe_set_itr(q_vector);
4112 if (!test_bit(__IXGBE_DOWN, &adapter->state))
4113 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
4119 * ixgbe_tx_timeout - Respond to a Tx Hang
4120 * @netdev: network interface device structure
4122 static void ixgbe_tx_timeout(struct net_device *netdev)
4124 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4126 /* Do the reset outside of interrupt context */
4127 ixgbe_tx_timeout_reset(adapter);
4131 * ixgbe_set_rss_queues: Allocate queues for RSS
4132 * @adapter: board private structure to initialize
4134 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4135 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4138 static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4141 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
4143 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4145 adapter->num_rx_queues = f->indices;
4146 adapter->num_tx_queues = f->indices;
4156 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4157 * @adapter: board private structure to initialize
4159 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4160 * to the original CPU that initiated the Tx session. This runs in addition
4161 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4162 * Rx load across CPUs using RSS.
4165 static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
4168 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4170 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4173 /* Flow Director must have RSS enabled */
4174 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4175 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
4176 adapter->num_tx_queues = f_fdir->indices;
4177 adapter->num_rx_queues = f_fdir->indices;
4180 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4187 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4188 * @adapter: board private structure to initialize
4190 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4191 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4192 * rx queues out of the max number of rx queues, instead, it is used as the
4193 * index of the first rx queue used by FCoE.
4196 static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4198 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4200 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4203 f->indices = min((int)num_online_cpus(), f->indices);
4205 adapter->num_rx_queues = 1;
4206 adapter->num_tx_queues = 1;
4208 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4209 e_info(probe, "FCoE enabled with RSS\n");
4210 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
4211 ixgbe_set_fdir_queues(adapter);
4213 ixgbe_set_rss_queues(adapter);
4216 /* adding FCoE rx rings to the end */
4217 f->mask = adapter->num_rx_queues;
4218 adapter->num_rx_queues += f->indices;
4219 adapter->num_tx_queues += f->indices;
4223 #endif /* IXGBE_FCOE */
4225 /* Artificial max queue cap per traffic class in DCB mode */
4226 #define DCB_QUEUE_CAP 8
4228 #ifdef CONFIG_IXGBE_DCB
4229 static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4231 int per_tc_q, q, i, offset = 0;
4232 struct net_device *dev = adapter->netdev;
4233 int tcs = netdev_get_num_tc(dev);
4238 /* Map queue offset and counts onto allocated tx queues */
4239 per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP);
4240 q = min((int)num_online_cpus(), per_tc_q);
4242 for (i = 0; i < tcs; i++) {
4243 netdev_set_tc_queue(dev, i, q, offset);
4247 adapter->num_tx_queues = q * tcs;
4248 adapter->num_rx_queues = q * tcs;
4251 /* FCoE enabled queues require special configuration indexed
4252 * by feature specific indices and mask. Here we map FCoE
4253 * indices onto the DCB queue pairs allowing FCoE to own
4254 * configuration later.
4256 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4258 struct ixgbe_ring_feature *f =
4259 &adapter->ring_feature[RING_F_FCOE];
4261 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4262 f->indices = dev->tc_to_txq[tc].count;
4263 f->mask = dev->tc_to_txq[tc].offset;
4272 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4273 * @adapter: board private structure to initialize
4275 * IOV doesn't actually use anything, so just NAK the
4276 * request for now and let the other queue routines
4277 * figure out what to do.
4279 static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4285 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
4286 * @adapter: board private structure to initialize
4288 * This is the top level queue allocation routine. The order here is very
4289 * important, starting with the "most" number of features turned on at once,
4290 * and ending with the smallest set of features. This way large combinations
4291 * can be allocated if they're turned on, and smaller combinations are the
4292 * fallthrough conditions.
4295 static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
4297 /* Start with base case */
4298 adapter->num_rx_queues = 1;
4299 adapter->num_tx_queues = 1;
4300 adapter->num_rx_pools = adapter->num_rx_queues;
4301 adapter->num_rx_queues_per_pool = 1;
4303 if (ixgbe_set_sriov_queues(adapter))
4306 #ifdef CONFIG_IXGBE_DCB
4307 if (ixgbe_set_dcb_queues(adapter))
4312 if (ixgbe_set_fcoe_queues(adapter))
4315 #endif /* IXGBE_FCOE */
4316 if (ixgbe_set_fdir_queues(adapter))
4319 if (ixgbe_set_rss_queues(adapter))
4322 /* fallback to base case */
4323 adapter->num_rx_queues = 1;
4324 adapter->num_tx_queues = 1;
4327 /* Notify the stack of the (possibly) reduced queue counts. */
4328 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
4329 return netif_set_real_num_rx_queues(adapter->netdev,
4330 adapter->num_rx_queues);
4333 static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
4336 int err, vector_threshold;
4338 /* We'll want at least 3 (vector_threshold):
4341 * 3) Other (Link Status Change, etc.)
4342 * 4) TCP Timer (optional)
4344 vector_threshold = MIN_MSIX_COUNT;
4346 /* The more we get, the more we will assign to Tx/Rx Cleanup
4347 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4348 * Right now, we simply care about how many we'll get; we'll
4349 * set them up later while requesting irq's.
4351 while (vectors >= vector_threshold) {
4352 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
4354 if (!err) /* Success in acquiring all requested vectors. */
4357 vectors = 0; /* Nasty failure, quit now */
4358 else /* err == number of vectors we should try again with */
4362 if (vectors < vector_threshold) {
4363 /* Can't allocate enough MSI-X interrupts? Oh well.
4364 * This just means we'll go with either a single MSI
4365 * vector or fall back to legacy interrupts.
4367 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4368 "Unable to allocate MSI-X interrupts\n");
4369 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4370 kfree(adapter->msix_entries);
4371 adapter->msix_entries = NULL;
4373 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
4375 * Adjust for only the vectors we'll use, which is minimum
4376 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4377 * vectors we were allocated.
4379 adapter->num_msix_vectors = min(vectors,
4380 adapter->max_msix_q_vectors + NON_Q_VECTORS);
4385 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
4386 * @adapter: board private structure to initialize
4388 * Cache the descriptor ring offsets for RSS to the assigned rings.
4391 static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
4395 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4398 for (i = 0; i < adapter->num_rx_queues; i++)
4399 adapter->rx_ring[i]->reg_idx = i;
4400 for (i = 0; i < adapter->num_tx_queues; i++)
4401 adapter->tx_ring[i]->reg_idx = i;
4406 #ifdef CONFIG_IXGBE_DCB
4408 /* ixgbe_get_first_reg_idx - Return first register index associated with ring */
4409 static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4410 unsigned int *tx, unsigned int *rx)
4412 struct net_device *dev = adapter->netdev;
4413 struct ixgbe_hw *hw = &adapter->hw;
4414 u8 num_tcs = netdev_get_num_tc(dev);
4419 switch (hw->mac.type) {
4420 case ixgbe_mac_82598EB:
4424 case ixgbe_mac_82599EB:
4425 case ixgbe_mac_X540:
4430 } else if (tc < 5) {
4431 *tx = ((tc + 2) << 4);
4433 } else if (tc < num_tcs) {
4434 *tx = ((tc + 8) << 3);
4463 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4464 * @adapter: board private structure to initialize
4466 * Cache the descriptor ring offsets for DCB to the assigned rings.
4469 static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4471 struct net_device *dev = adapter->netdev;
4473 u8 num_tcs = netdev_get_num_tc(dev);
4478 for (i = 0, k = 0; i < num_tcs; i++) {
4479 unsigned int tx_s, rx_s;
4480 u16 count = dev->tc_to_txq[i].count;
4482 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4483 for (j = 0; j < count; j++, k++) {
4484 adapter->tx_ring[k]->reg_idx = tx_s + j;
4485 adapter->rx_ring[k]->reg_idx = rx_s + j;
4486 adapter->tx_ring[k]->dcb_tc = i;
4487 adapter->rx_ring[k]->dcb_tc = i;
4496 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4497 * @adapter: board private structure to initialize
4499 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4502 static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
4507 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4508 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
4509 for (i = 0; i < adapter->num_rx_queues; i++)
4510 adapter->rx_ring[i]->reg_idx = i;
4511 for (i = 0; i < adapter->num_tx_queues; i++)
4512 adapter->tx_ring[i]->reg_idx = i;
4521 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4522 * @adapter: board private structure to initialize
4524 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4527 static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4529 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4531 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
4533 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4536 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4537 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
4538 ixgbe_cache_ring_fdir(adapter);
4540 ixgbe_cache_ring_rss(adapter);
4542 fcoe_rx_i = f->mask;
4543 fcoe_tx_i = f->mask;
4545 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4546 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4547 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4552 #endif /* IXGBE_FCOE */
4554 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4555 * @adapter: board private structure to initialize
4557 * SR-IOV doesn't use any descriptor rings but changes the default if
4558 * no other mapping is used.
4561 static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4563 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4564 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
4565 if (adapter->num_vfs)
4572 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4573 * @adapter: board private structure to initialize
4575 * Once we know the feature-set enabled for the device, we'll cache
4576 * the register offset the descriptor ring is assigned to.
4578 * Note, the order the various feature calls is important. It must start with
4579 * the "most" features enabled at the same time, then trickle down to the
4580 * least amount of features turned on at once.
4582 static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4584 /* start with default case */
4585 adapter->rx_ring[0]->reg_idx = 0;
4586 adapter->tx_ring[0]->reg_idx = 0;
4588 if (ixgbe_cache_ring_sriov(adapter))
4591 #ifdef CONFIG_IXGBE_DCB
4592 if (ixgbe_cache_ring_dcb(adapter))
4597 if (ixgbe_cache_ring_fcoe(adapter))
4599 #endif /* IXGBE_FCOE */
4601 if (ixgbe_cache_ring_fdir(adapter))
4604 if (ixgbe_cache_ring_rss(adapter))
4609 * ixgbe_alloc_queues - Allocate memory for all rings
4610 * @adapter: board private structure to initialize
4612 * We allocate one ring per queue at run-time since we don't know the
4613 * number of queues at compile-time. The polling_netdev array is
4614 * intended for Multiqueue, but should work fine with a single queue.
4616 static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
4618 int rx = 0, tx = 0, nid = adapter->node;
4620 if (nid < 0 || !node_online(nid))
4621 nid = first_online_node;
4623 for (; tx < adapter->num_tx_queues; tx++) {
4624 struct ixgbe_ring *ring;
4626 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
4628 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
4630 goto err_allocation;
4631 ring->count = adapter->tx_ring_count;
4632 ring->queue_index = tx;
4633 ring->numa_node = nid;
4634 ring->dev = &adapter->pdev->dev;
4635 ring->netdev = adapter->netdev;
4637 adapter->tx_ring[tx] = ring;
4640 for (; rx < adapter->num_rx_queues; rx++) {
4641 struct ixgbe_ring *ring;
4643 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
4645 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
4647 goto err_allocation;
4648 ring->count = adapter->rx_ring_count;
4649 ring->queue_index = rx;
4650 ring->numa_node = nid;
4651 ring->dev = &adapter->pdev->dev;
4652 ring->netdev = adapter->netdev;
4654 adapter->rx_ring[rx] = ring;
4657 ixgbe_cache_ring_register(adapter);
4663 kfree(adapter->tx_ring[--tx]);
4666 kfree(adapter->rx_ring[--rx]);
4671 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4672 * @adapter: board private structure to initialize
4674 * Attempt to configure the interrupts using the best available
4675 * capabilities of the hardware and the kernel.
4677 static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
4679 struct ixgbe_hw *hw = &adapter->hw;
4681 int vector, v_budget;
4684 * It's easy to be greedy for MSI-X vectors, but it really
4685 * doesn't do us much good if we have a lot more vectors
4686 * than CPU's. So let's be conservative and only ask for
4687 * (roughly) the same number of vectors as there are CPU's.
4689 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
4690 (int)num_online_cpus()) + NON_Q_VECTORS;
4693 * At the same time, hardware can only support a maximum of
4694 * hw.mac->max_msix_vectors vectors. With features
4695 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4696 * descriptor queues supported by our device. Thus, we cap it off in
4697 * those rare cases where the cpu count also exceeds our vector limit.
4699 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
4701 /* A failure in MSI-X entry allocation isn't fatal, but it does
4702 * mean we disable MSI-X capabilities of the adapter. */
4703 adapter->msix_entries = kcalloc(v_budget,
4704 sizeof(struct msix_entry), GFP_KERNEL);
4705 if (adapter->msix_entries) {
4706 for (vector = 0; vector < v_budget; vector++)
4707 adapter->msix_entries[vector].entry = vector;
4709 ixgbe_acquire_msix_vectors(adapter, v_budget);
4711 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4715 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4716 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
4717 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
4719 "ATR is not supported while multiple "
4720 "queues are disabled. Disabling Flow Director\n");
4722 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4723 adapter->atr_sample_rate = 0;
4724 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4725 ixgbe_disable_sriov(adapter);
4727 err = ixgbe_set_num_queues(adapter);
4731 err = pci_enable_msi(adapter->pdev);
4733 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4735 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4736 "Unable to allocate MSI interrupt, "
4737 "falling back to legacy. Error: %d\n", err);
4747 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4748 * @adapter: board private structure to initialize
4750 * We allocate one q_vector per queue interrupt. If allocation fails we
4753 static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4755 int v_idx, num_q_vectors;
4756 struct ixgbe_q_vector *q_vector;
4758 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4759 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
4763 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
4764 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
4765 GFP_KERNEL, adapter->node);
4767 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
4772 q_vector->adapter = adapter;
4773 q_vector->v_idx = v_idx;
4775 /* Allocate the affinity_hint cpumask, configure the mask */
4776 if (!alloc_cpumask_var(&q_vector->affinity_mask, GFP_KERNEL))
4778 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
4779 netif_napi_add(adapter->netdev, &q_vector->napi,
4781 adapter->q_vector[v_idx] = q_vector;
4789 q_vector = adapter->q_vector[v_idx];
4790 netif_napi_del(&q_vector->napi);
4791 free_cpumask_var(q_vector->affinity_mask);
4793 adapter->q_vector[v_idx] = NULL;
4799 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
4800 * @adapter: board private structure to initialize
4802 * This function frees the memory allocated to the q_vectors. In addition if
4803 * NAPI is enabled it will delete any references to the NAPI struct prior
4804 * to freeing the q_vector.
4806 static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
4808 int v_idx, num_q_vectors;
4810 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4811 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
4815 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
4816 struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx];
4817 adapter->q_vector[v_idx] = NULL;
4818 netif_napi_del(&q_vector->napi);
4819 free_cpumask_var(q_vector->affinity_mask);
4824 static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
4826 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4827 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4828 pci_disable_msix(adapter->pdev);
4829 kfree(adapter->msix_entries);
4830 adapter->msix_entries = NULL;
4831 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
4832 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
4833 pci_disable_msi(adapter->pdev);
4838 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
4839 * @adapter: board private structure to initialize
4841 * We determine which interrupt scheme to use based on...
4842 * - Kernel support (MSI, MSI-X)
4843 * - which can be user-defined (via MODULE_PARAM)
4844 * - Hardware queue count (num_*_queues)
4845 * - defined by miscellaneous hardware support/features (RSS, etc.)
4847 int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
4851 /* Number of supported queues */
4852 err = ixgbe_set_num_queues(adapter);
4856 err = ixgbe_set_interrupt_capability(adapter);
4858 e_dev_err("Unable to setup interrupt capabilities\n");
4859 goto err_set_interrupt;
4862 err = ixgbe_alloc_q_vectors(adapter);
4864 e_dev_err("Unable to allocate memory for queue vectors\n");
4865 goto err_alloc_q_vectors;
4868 err = ixgbe_alloc_queues(adapter);
4870 e_dev_err("Unable to allocate memory for queues\n");
4871 goto err_alloc_queues;
4874 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
4875 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
4876 adapter->num_rx_queues, adapter->num_tx_queues);
4878 set_bit(__IXGBE_DOWN, &adapter->state);
4883 ixgbe_free_q_vectors(adapter);
4884 err_alloc_q_vectors:
4885 ixgbe_reset_interrupt_capability(adapter);
4891 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
4892 * @adapter: board private structure to clear interrupt scheme on
4894 * We go through and clear interrupt specific resources and reset the structure
4895 * to pre-load conditions
4897 void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
4901 for (i = 0; i < adapter->num_tx_queues; i++) {
4902 kfree(adapter->tx_ring[i]);
4903 adapter->tx_ring[i] = NULL;
4905 for (i = 0; i < adapter->num_rx_queues; i++) {
4906 struct ixgbe_ring *ring = adapter->rx_ring[i];
4908 /* ixgbe_get_stats64() might access this ring, we must wait
4909 * a grace period before freeing it.
4911 kfree_rcu(ring, rcu);
4912 adapter->rx_ring[i] = NULL;
4915 adapter->num_tx_queues = 0;
4916 adapter->num_rx_queues = 0;
4918 ixgbe_free_q_vectors(adapter);
4919 ixgbe_reset_interrupt_capability(adapter);
4923 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4924 * @adapter: board private structure to initialize
4926 * ixgbe_sw_init initializes the Adapter private data structure.
4927 * Fields are initialized based on PCI device information and
4928 * OS network device settings (MTU size).
4930 static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
4932 struct ixgbe_hw *hw = &adapter->hw;
4933 struct pci_dev *pdev = adapter->pdev;
4935 #ifdef CONFIG_IXGBE_DCB
4937 struct tc_configuration *tc;
4940 /* PCI config space info */
4942 hw->vendor_id = pdev->vendor;
4943 hw->device_id = pdev->device;
4944 hw->revision_id = pdev->revision;
4945 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4946 hw->subsystem_device_id = pdev->subsystem_device;
4948 /* Set capability flags */
4949 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
4950 adapter->ring_feature[RING_F_RSS].indices = rss;
4951 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
4952 switch (hw->mac.type) {
4953 case ixgbe_mac_82598EB:
4954 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4955 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
4956 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
4958 case ixgbe_mac_X540:
4959 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
4960 case ixgbe_mac_82599EB:
4961 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
4962 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4963 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
4964 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4965 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
4966 /* Flow Director hash filters enabled */
4967 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
4968 adapter->atr_sample_rate = 20;
4969 adapter->ring_feature[RING_F_FDIR].indices =
4970 IXGBE_MAX_FDIR_INDICES;
4971 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
4973 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4974 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
4975 adapter->ring_feature[RING_F_FCOE].indices = 0;
4976 #ifdef CONFIG_IXGBE_DCB
4977 /* Default traffic class to use for FCoE */
4978 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
4980 #endif /* IXGBE_FCOE */
4986 /* n-tuple support exists, always init our spinlock */
4987 spin_lock_init(&adapter->fdir_perfect_lock);
4989 #ifdef CONFIG_IXGBE_DCB
4990 switch (hw->mac.type) {
4991 case ixgbe_mac_X540:
4992 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
4993 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
4996 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
4997 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5001 /* Configure DCB traffic classes */
5002 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5003 tc = &adapter->dcb_cfg.tc_config[j];
5004 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5005 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5006 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5007 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5008 tc->dcb_pfc = pfc_disabled;
5011 /* Initialize default user to priority mapping, UPx->TC0 */
5012 tc = &adapter->dcb_cfg.tc_config[0];
5013 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5014 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5016 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5017 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5018 adapter->dcb_cfg.pfc_mode_enable = false;
5019 adapter->dcb_set_bitmap = 0x00;
5020 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
5021 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
5026 /* default flow control settings */
5027 hw->fc.requested_mode = ixgbe_fc_full;
5028 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
5030 adapter->last_lfc_mode = hw->fc.current_mode;
5032 ixgbe_pbthresh_setup(adapter);
5033 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5034 hw->fc.send_xon = true;
5035 hw->fc.disable_fc_autoneg = false;
5037 /* enable itr by default in dynamic mode */
5038 adapter->rx_itr_setting = 1;
5039 adapter->tx_itr_setting = 1;
5041 /* set defaults for eitr in MegaBytes */
5042 adapter->eitr_low = 10;
5043 adapter->eitr_high = 20;
5045 /* set default ring sizes */
5046 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5047 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5049 /* set default work limits */
5050 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
5052 /* initialize eeprom parameters */
5053 if (ixgbe_init_eeprom_params_generic(hw)) {
5054 e_dev_err("EEPROM initialization failed\n");
5058 /* enable rx csum by default */
5059 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5061 /* get assigned NUMA node */
5062 adapter->node = dev_to_node(&pdev->dev);
5064 set_bit(__IXGBE_DOWN, &adapter->state);
5070 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
5071 * @tx_ring: tx descriptor ring (for a specific queue) to setup
5073 * Return 0 on success, negative on failure
5075 int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
5077 struct device *dev = tx_ring->dev;
5080 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
5081 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
5082 if (!tx_ring->tx_buffer_info)
5083 tx_ring->tx_buffer_info = vzalloc(size);
5084 if (!tx_ring->tx_buffer_info)
5087 /* round up to nearest 4K */
5088 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
5089 tx_ring->size = ALIGN(tx_ring->size, 4096);
5091 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5092 &tx_ring->dma, GFP_KERNEL);
5096 tx_ring->next_to_use = 0;
5097 tx_ring->next_to_clean = 0;
5101 vfree(tx_ring->tx_buffer_info);
5102 tx_ring->tx_buffer_info = NULL;
5103 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
5108 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5109 * @adapter: board private structure
5111 * If this function returns with an error, then it's possible one or
5112 * more of the rings is populated (while the rest are not). It is the
5113 * callers duty to clean those orphaned rings.
5115 * Return 0 on success, negative on failure
5117 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5121 for (i = 0; i < adapter->num_tx_queues; i++) {
5122 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
5125 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
5133 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
5134 * @rx_ring: rx descriptor ring (for a specific queue) to setup
5136 * Returns 0 on success, negative on failure
5138 int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
5140 struct device *dev = rx_ring->dev;
5143 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
5144 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
5145 if (!rx_ring->rx_buffer_info)
5146 rx_ring->rx_buffer_info = vzalloc(size);
5147 if (!rx_ring->rx_buffer_info)
5150 /* Round up to nearest 4K */
5151 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5152 rx_ring->size = ALIGN(rx_ring->size, 4096);
5154 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5155 &rx_ring->dma, GFP_KERNEL);
5160 rx_ring->next_to_clean = 0;
5161 rx_ring->next_to_use = 0;
5165 vfree(rx_ring->rx_buffer_info);
5166 rx_ring->rx_buffer_info = NULL;
5167 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
5172 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5173 * @adapter: board private structure
5175 * If this function returns with an error, then it's possible one or
5176 * more of the rings is populated (while the rest are not). It is the
5177 * callers duty to clean those orphaned rings.
5179 * Return 0 on success, negative on failure
5181 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5185 for (i = 0; i < adapter->num_rx_queues; i++) {
5186 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
5189 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
5197 * ixgbe_free_tx_resources - Free Tx Resources per Queue
5198 * @tx_ring: Tx descriptor ring for a specific queue
5200 * Free all transmit software resources
5202 void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
5204 ixgbe_clean_tx_ring(tx_ring);
5206 vfree(tx_ring->tx_buffer_info);
5207 tx_ring->tx_buffer_info = NULL;
5209 /* if not set, then don't free */
5213 dma_free_coherent(tx_ring->dev, tx_ring->size,
5214 tx_ring->desc, tx_ring->dma);
5216 tx_ring->desc = NULL;
5220 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5221 * @adapter: board private structure
5223 * Free all transmit software resources
5225 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5229 for (i = 0; i < adapter->num_tx_queues; i++)
5230 if (adapter->tx_ring[i]->desc)
5231 ixgbe_free_tx_resources(adapter->tx_ring[i]);
5235 * ixgbe_free_rx_resources - Free Rx Resources
5236 * @rx_ring: ring to clean the resources from
5238 * Free all receive software resources
5240 void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
5242 ixgbe_clean_rx_ring(rx_ring);
5244 vfree(rx_ring->rx_buffer_info);
5245 rx_ring->rx_buffer_info = NULL;
5247 /* if not set, then don't free */
5251 dma_free_coherent(rx_ring->dev, rx_ring->size,
5252 rx_ring->desc, rx_ring->dma);
5254 rx_ring->desc = NULL;
5258 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5259 * @adapter: board private structure
5261 * Free all receive software resources
5263 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5267 for (i = 0; i < adapter->num_rx_queues; i++)
5268 if (adapter->rx_ring[i]->desc)
5269 ixgbe_free_rx_resources(adapter->rx_ring[i]);
5273 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5274 * @netdev: network interface device structure
5275 * @new_mtu: new value for maximum frame size
5277 * Returns 0 on success, negative on failure
5279 static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5281 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5282 struct ixgbe_hw *hw = &adapter->hw;
5283 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5285 /* MTU < 68 is an error and causes problems on some kernels */
5286 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5287 hw->mac.type != ixgbe_mac_X540) {
5288 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5291 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5295 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5296 /* must set new MTU before calling down or up */
5297 netdev->mtu = new_mtu;
5299 if (netif_running(netdev))
5300 ixgbe_reinit_locked(adapter);
5306 * ixgbe_open - Called when a network interface is made active
5307 * @netdev: network interface device structure
5309 * Returns 0 on success, negative value on failure
5311 * The open entry point is called when a network interface is made
5312 * active by the system (IFF_UP). At this point all resources needed
5313 * for transmit and receive operations are allocated, the interrupt
5314 * handler is registered with the OS, the watchdog timer is started,
5315 * and the stack is notified that the interface is ready.
5317 static int ixgbe_open(struct net_device *netdev)
5319 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5322 /* disallow open during test */
5323 if (test_bit(__IXGBE_TESTING, &adapter->state))
5326 netif_carrier_off(netdev);
5328 /* allocate transmit descriptors */
5329 err = ixgbe_setup_all_tx_resources(adapter);
5333 /* allocate receive descriptors */
5334 err = ixgbe_setup_all_rx_resources(adapter);
5338 ixgbe_configure(adapter);
5340 err = ixgbe_request_irq(adapter);
5344 ixgbe_up_complete(adapter);
5350 ixgbe_free_all_rx_resources(adapter);
5352 ixgbe_free_all_tx_resources(adapter);
5353 ixgbe_reset(adapter);
5359 * ixgbe_close - Disables a network interface
5360 * @netdev: network interface device structure
5362 * Returns 0, this is not allowed to fail
5364 * The close entry point is called when an interface is de-activated
5365 * by the OS. The hardware is still under the drivers control, but
5366 * needs to be disabled. A global MAC reset is issued to stop the
5367 * hardware, and all transmit and receive resources are freed.
5369 static int ixgbe_close(struct net_device *netdev)
5371 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5373 ixgbe_down(adapter);
5374 ixgbe_free_irq(adapter);
5376 ixgbe_fdir_filter_exit(adapter);
5378 ixgbe_free_all_tx_resources(adapter);
5379 ixgbe_free_all_rx_resources(adapter);
5381 ixgbe_release_hw_control(adapter);
5387 static int ixgbe_resume(struct pci_dev *pdev)
5389 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5390 struct net_device *netdev = adapter->netdev;
5393 pci_set_power_state(pdev, PCI_D0);
5394 pci_restore_state(pdev);
5396 * pci_restore_state clears dev->state_saved so call
5397 * pci_save_state to restore it.
5399 pci_save_state(pdev);
5401 err = pci_enable_device_mem(pdev);
5403 e_dev_err("Cannot enable PCI device from suspend\n");
5406 pci_set_master(pdev);
5408 pci_wake_from_d3(pdev, false);
5410 err = ixgbe_init_interrupt_scheme(adapter);
5412 e_dev_err("Cannot initialize interrupts for device\n");
5416 ixgbe_reset(adapter);
5418 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5420 if (netif_running(netdev)) {
5421 err = ixgbe_open(netdev);
5426 netif_device_attach(netdev);
5430 #endif /* CONFIG_PM */
5432 static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
5434 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5435 struct net_device *netdev = adapter->netdev;
5436 struct ixgbe_hw *hw = &adapter->hw;
5438 u32 wufc = adapter->wol;
5443 netif_device_detach(netdev);
5445 if (netif_running(netdev)) {
5446 ixgbe_down(adapter);
5447 ixgbe_free_irq(adapter);
5448 ixgbe_free_all_tx_resources(adapter);
5449 ixgbe_free_all_rx_resources(adapter);
5452 ixgbe_clear_interrupt_scheme(adapter);
5454 kfree(adapter->ixgbe_ieee_pfc);
5455 kfree(adapter->ixgbe_ieee_ets);
5459 retval = pci_save_state(pdev);
5465 ixgbe_set_rx_mode(netdev);
5467 /* turn on all-multi mode if wake on multicast is enabled */
5468 if (wufc & IXGBE_WUFC_MC) {
5469 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5470 fctrl |= IXGBE_FCTRL_MPE;
5471 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5474 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5475 ctrl |= IXGBE_CTRL_GIO_DIS;
5476 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5478 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5480 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5481 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5484 switch (hw->mac.type) {
5485 case ixgbe_mac_82598EB:
5486 pci_wake_from_d3(pdev, false);
5488 case ixgbe_mac_82599EB:
5489 case ixgbe_mac_X540:
5490 pci_wake_from_d3(pdev, !!wufc);
5496 *enable_wake = !!wufc;
5498 ixgbe_release_hw_control(adapter);
5500 pci_disable_device(pdev);
5506 static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5511 retval = __ixgbe_shutdown(pdev, &wake);
5516 pci_prepare_to_sleep(pdev);
5518 pci_wake_from_d3(pdev, false);
5519 pci_set_power_state(pdev, PCI_D3hot);
5524 #endif /* CONFIG_PM */
5526 static void ixgbe_shutdown(struct pci_dev *pdev)
5530 __ixgbe_shutdown(pdev, &wake);
5532 if (system_state == SYSTEM_POWER_OFF) {
5533 pci_wake_from_d3(pdev, wake);
5534 pci_set_power_state(pdev, PCI_D3hot);
5539 * ixgbe_update_stats - Update the board statistics counters.
5540 * @adapter: board private structure
5542 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5544 struct net_device *netdev = adapter->netdev;
5545 struct ixgbe_hw *hw = &adapter->hw;
5546 struct ixgbe_hw_stats *hwstats = &adapter->stats;
5548 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
5549 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5550 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5551 u64 bytes = 0, packets = 0;
5553 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5555 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
5556 #endif /* IXGBE_FCOE */
5558 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5559 test_bit(__IXGBE_RESETTING, &adapter->state))
5562 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
5565 for (i = 0; i < 16; i++)
5566 adapter->hw_rx_no_dma_resources +=
5567 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
5568 for (i = 0; i < adapter->num_rx_queues; i++) {
5569 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5570 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
5572 adapter->rsc_total_count = rsc_count;
5573 adapter->rsc_total_flush = rsc_flush;
5576 for (i = 0; i < adapter->num_rx_queues; i++) {
5577 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5578 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5579 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5580 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5581 bytes += rx_ring->stats.bytes;
5582 packets += rx_ring->stats.packets;
5584 adapter->non_eop_descs = non_eop_descs;
5585 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5586 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5587 netdev->stats.rx_bytes = bytes;
5588 netdev->stats.rx_packets = packets;
5592 /* gather some stats to the adapter struct that are per queue */
5593 for (i = 0; i < adapter->num_tx_queues; i++) {
5594 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5595 restart_queue += tx_ring->tx_stats.restart_queue;
5596 tx_busy += tx_ring->tx_stats.tx_busy;
5597 bytes += tx_ring->stats.bytes;
5598 packets += tx_ring->stats.packets;
5600 adapter->restart_queue = restart_queue;
5601 adapter->tx_busy = tx_busy;
5602 netdev->stats.tx_bytes = bytes;
5603 netdev->stats.tx_packets = packets;
5605 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
5607 /* 8 register reads */
5608 for (i = 0; i < 8; i++) {
5609 /* for packet buffers not used, the register should read 0 */
5610 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5612 hwstats->mpc[i] += mpc;
5613 total_mpc += hwstats->mpc[i];
5614 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5615 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
5616 switch (hw->mac.type) {
5617 case ixgbe_mac_82598EB:
5618 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5619 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5620 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
5621 hwstats->pxonrxc[i] +=
5622 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
5624 case ixgbe_mac_82599EB:
5625 case ixgbe_mac_X540:
5626 hwstats->pxonrxc[i] +=
5627 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
5634 /*16 register reads */
5635 for (i = 0; i < 16; i++) {
5636 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5637 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5638 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5639 (hw->mac.type == ixgbe_mac_X540)) {
5640 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5641 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5642 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5643 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5647 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
5648 /* work around hardware counting issue */
5649 hwstats->gprc -= missed_rx;
5651 ixgbe_update_xoff_received(adapter);
5653 /* 82598 hardware only has a 32 bit counter in the high register */
5654 switch (hw->mac.type) {
5655 case ixgbe_mac_82598EB:
5656 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
5657 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5658 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5659 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5661 case ixgbe_mac_X540:
5662 /* OS2BMC stats are X540 only*/
5663 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5664 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5665 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5666 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5667 case ixgbe_mac_82599EB:
5668 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
5669 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
5670 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
5671 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
5672 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
5673 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
5674 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
5675 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5676 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
5678 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5679 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5680 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5681 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5682 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5683 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
5684 /* Add up per cpu counters for total ddp aloc fail */
5685 if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
5686 for_each_possible_cpu(cpu) {
5687 fcoe_noddp_counts_sum +=
5688 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
5689 fcoe_noddp_ext_buff_counts_sum +=
5691 pcpu_noddp_ext_buff, cpu);
5694 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
5695 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
5696 #endif /* IXGBE_FCOE */
5701 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
5702 hwstats->bprc += bprc;
5703 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
5704 if (hw->mac.type == ixgbe_mac_82598EB)
5705 hwstats->mprc -= bprc;
5706 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5707 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5708 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5709 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5710 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5711 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5712 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5713 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
5714 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
5715 hwstats->lxontxc += lxon;
5716 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
5717 hwstats->lxofftxc += lxoff;
5718 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5719 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
5721 * 82598 errata - tx of flow control packets is included in tx counters
5723 xon_off_tot = lxon + lxoff;
5724 hwstats->gptc -= xon_off_tot;
5725 hwstats->mptc -= xon_off_tot;
5726 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5727 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5728 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5729 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5730 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5731 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5732 hwstats->ptc64 -= xon_off_tot;
5733 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5734 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5735 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5736 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5737 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5738 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
5740 /* Fill out the OS statistics structure */
5741 netdev->stats.multicast = hwstats->mprc;
5744 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
5745 netdev->stats.rx_dropped = 0;
5746 netdev->stats.rx_length_errors = hwstats->rlec;
5747 netdev->stats.rx_crc_errors = hwstats->crcerrs;
5748 netdev->stats.rx_missed_errors = total_mpc;
5752 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5753 * @adapter - pointer to the device adapter structure
5755 static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
5757 struct ixgbe_hw *hw = &adapter->hw;
5760 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5763 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5765 /* if interface is down do nothing */
5766 if (test_bit(__IXGBE_DOWN, &adapter->state))
5769 /* do nothing if we are not using signature filters */
5770 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5773 adapter->fdir_overflow++;
5775 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5776 for (i = 0; i < adapter->num_tx_queues; i++)
5777 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
5778 &(adapter->tx_ring[i]->state));
5779 /* re-enable flow director interrupts */
5780 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
5782 e_err(probe, "failed to finish FDIR re-initialization, "
5783 "ignored adding FDIR ATR filters\n");
5788 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5789 * @adapter - pointer to the device adapter structure
5791 * This function serves two purposes. First it strobes the interrupt lines
5792 * in order to make certain interrupts are occuring. Secondly it sets the
5793 * bits needed to check for TX hangs. As a result we should immediately
5794 * determine if a hang has occured.
5796 static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5798 struct ixgbe_hw *hw = &adapter->hw;
5802 /* If we're down or resetting, just bail */
5803 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5804 test_bit(__IXGBE_RESETTING, &adapter->state))
5807 /* Force detection of hung controller */
5808 if (netif_carrier_ok(adapter->netdev)) {
5809 for (i = 0; i < adapter->num_tx_queues; i++)
5810 set_check_for_tx_hang(adapter->tx_ring[i]);
5813 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
5815 * for legacy and MSI interrupts don't set any bits
5816 * that are enabled for EIAM, because this operation
5817 * would set *both* EIMS and EICS for any bit in EIAM
5819 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5820 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
5822 /* get one bit for every active tx/rx interrupt vector */
5823 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5824 struct ixgbe_q_vector *qv = adapter->q_vector[i];
5825 if (qv->rx.ring || qv->tx.ring)
5826 eics |= ((u64)1 << i);
5830 /* Cause software interrupt to ensure rings are cleaned */
5831 ixgbe_irq_rearm_queues(adapter, eics);
5836 * ixgbe_watchdog_update_link - update the link status
5837 * @adapter - pointer to the device adapter structure
5838 * @link_speed - pointer to a u32 to store the link_speed
5840 static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
5842 struct ixgbe_hw *hw = &adapter->hw;
5843 u32 link_speed = adapter->link_speed;
5844 bool link_up = adapter->link_up;
5847 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5850 if (hw->mac.ops.check_link) {
5851 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
5853 /* always assume link is up, if no check link function */
5854 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5858 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5859 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
5860 hw->mac.ops.fc_enable(hw, i);
5862 hw->mac.ops.fc_enable(hw, 0);
5867 time_after(jiffies, (adapter->link_check_timeout +
5868 IXGBE_TRY_LINK_TIMEOUT))) {
5869 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5870 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5871 IXGBE_WRITE_FLUSH(hw);
5874 adapter->link_up = link_up;
5875 adapter->link_speed = link_speed;
5879 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5880 * print link up message
5881 * @adapter - pointer to the device adapter structure
5883 static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5885 struct net_device *netdev = adapter->netdev;
5886 struct ixgbe_hw *hw = &adapter->hw;
5887 u32 link_speed = adapter->link_speed;
5888 bool flow_rx, flow_tx;
5890 /* only continue if link was previously down */
5891 if (netif_carrier_ok(netdev))
5894 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5896 switch (hw->mac.type) {
5897 case ixgbe_mac_82598EB: {
5898 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5899 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5900 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5901 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5904 case ixgbe_mac_X540:
5905 case ixgbe_mac_82599EB: {
5906 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5907 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5908 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5909 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5917 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5918 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5920 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5922 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5925 ((flow_rx && flow_tx) ? "RX/TX" :
5927 (flow_tx ? "TX" : "None"))));
5929 netif_carrier_on(netdev);
5930 ixgbe_check_vf_rate_limit(adapter);
5934 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5935 * print link down message
5936 * @adapter - pointer to the adapter structure
5938 static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
5940 struct net_device *netdev = adapter->netdev;
5941 struct ixgbe_hw *hw = &adapter->hw;
5943 adapter->link_up = false;
5944 adapter->link_speed = 0;
5946 /* only continue if link was up previously */
5947 if (!netif_carrier_ok(netdev))
5950 /* poll for SFP+ cable when link is down */
5951 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5952 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5954 e_info(drv, "NIC Link is Down\n");
5955 netif_carrier_off(netdev);
5959 * ixgbe_watchdog_flush_tx - flush queues on link down
5960 * @adapter - pointer to the device adapter structure
5962 static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5965 int some_tx_pending = 0;
5967 if (!netif_carrier_ok(adapter->netdev)) {
5968 for (i = 0; i < adapter->num_tx_queues; i++) {
5969 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5970 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5971 some_tx_pending = 1;
5976 if (some_tx_pending) {
5977 /* We've lost link, so the controller stops DMA,
5978 * but we've got queued Tx work that's never going
5979 * to get done, so reset controller to flush Tx.
5980 * (Do the reset outside of interrupt context).
5982 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
5987 static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
5991 /* Do not perform spoof check for 82598 */
5992 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5995 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
5998 * ssvpc register is cleared on read, if zero then no
5999 * spoofed packets in the last interval.
6004 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6008 * ixgbe_watchdog_subtask - check and bring link up
6009 * @adapter - pointer to the device adapter structure
6011 static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
6013 /* if interface is down do nothing */
6014 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6015 test_bit(__IXGBE_RESETTING, &adapter->state))
6018 ixgbe_watchdog_update_link(adapter);
6020 if (adapter->link_up)
6021 ixgbe_watchdog_link_is_up(adapter);
6023 ixgbe_watchdog_link_is_down(adapter);
6025 ixgbe_spoof_check(adapter);
6026 ixgbe_update_stats(adapter);
6028 ixgbe_watchdog_flush_tx(adapter);
6032 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6033 * @adapter - the ixgbe adapter structure
6035 static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6037 struct ixgbe_hw *hw = &adapter->hw;
6040 /* not searching for SFP so there is nothing to do here */
6041 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6042 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6045 /* someone else is in init, wait until next service event */
6046 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6049 err = hw->phy.ops.identify_sfp(hw);
6050 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6053 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6054 /* If no cable is present, then we need to reset
6055 * the next time we find a good cable. */
6056 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6063 /* exit if reset not needed */
6064 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6067 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6070 * A module may be identified correctly, but the EEPROM may not have
6071 * support for that module. setup_sfp() will fail in that case, so
6072 * we should not allow that module to load.
6074 if (hw->mac.type == ixgbe_mac_82598EB)
6075 err = hw->phy.ops.reset(hw);
6077 err = hw->mac.ops.setup_sfp(hw);
6079 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6082 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6083 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6086 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6088 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6089 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6090 e_dev_err("failed to initialize because an unsupported "
6091 "SFP+ module type was detected.\n");
6092 e_dev_err("Reload the driver after installing a "
6093 "supported module.\n");
6094 unregister_netdev(adapter->netdev);
6099 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6100 * @adapter - the ixgbe adapter structure
6102 static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6104 struct ixgbe_hw *hw = &adapter->hw;
6108 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6111 /* someone else is in init, wait until next service event */
6112 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6115 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6117 autoneg = hw->phy.autoneg_advertised;
6118 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6119 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6120 if (hw->mac.ops.setup_link)
6121 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6123 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6124 adapter->link_check_timeout = jiffies;
6125 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6128 #ifdef CONFIG_PCI_IOV
6129 static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6132 struct ixgbe_hw *hw = &adapter->hw;
6133 struct net_device *netdev = adapter->netdev;
6137 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6138 if (gpc) /* If incrementing then no need for the check below */
6141 * Check to see if a bad DMA write target from an errant or
6142 * malicious VF has caused a PCIe error. If so then we can
6143 * issue a VFLR to the offending VF(s) and then resume without
6144 * requesting a full slot reset.
6147 for (vf = 0; vf < adapter->num_vfs; vf++) {
6148 ciaa = (vf << 16) | 0x80000000;
6149 /* 32 bit read so align, we really want status at offset 6 */
6150 ciaa |= PCI_COMMAND;
6151 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6152 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
6154 /* disable debug mode asap after reading data */
6155 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6156 /* Get the upper 16 bits which will be the PCI status reg */
6158 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
6159 netdev_err(netdev, "VF %d Hung DMA\n", vf);
6161 ciaa = (vf << 16) | 0x80000000;
6163 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6164 ciad = 0x00008000; /* VFLR */
6165 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
6167 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6174 * ixgbe_service_timer - Timer Call-back
6175 * @data: pointer to adapter cast into an unsigned long
6177 static void ixgbe_service_timer(unsigned long data)
6179 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6180 unsigned long next_event_offset;
6183 #ifdef CONFIG_PCI_IOV
6187 * don't bother with SR-IOV VF DMA hang check if there are
6188 * no VFs or the link is down
6190 if (!adapter->num_vfs ||
6191 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) {
6193 goto normal_timer_service;
6196 /* If we have VFs allocated then we must check for DMA hangs */
6197 ixgbe_check_for_bad_vf(adapter);
6198 next_event_offset = HZ / 50;
6199 adapter->timer_event_accumulator++;
6201 if (adapter->timer_event_accumulator >= 100) {
6203 adapter->timer_event_accumulator = 0;
6206 goto schedule_event;
6208 normal_timer_service:
6210 /* poll faster when waiting for link */
6211 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6212 next_event_offset = HZ / 10;
6214 next_event_offset = HZ * 2;
6216 #ifdef CONFIG_PCI_IOV
6219 /* Reset the timer */
6220 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6223 ixgbe_service_event_schedule(adapter);
6226 static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6228 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6231 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6233 /* If we're already down or resetting, just bail */
6234 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6235 test_bit(__IXGBE_RESETTING, &adapter->state))
6238 ixgbe_dump(adapter);
6239 netdev_err(adapter->netdev, "Reset adapter\n");
6240 adapter->tx_timeout_count++;
6242 ixgbe_reinit_locked(adapter);
6246 * ixgbe_service_task - manages and runs subtasks
6247 * @work: pointer to work_struct containing our data
6249 static void ixgbe_service_task(struct work_struct *work)
6251 struct ixgbe_adapter *adapter = container_of(work,
6252 struct ixgbe_adapter,
6255 ixgbe_reset_subtask(adapter);
6256 ixgbe_sfp_detection_subtask(adapter);
6257 ixgbe_sfp_link_config_subtask(adapter);
6258 ixgbe_check_overtemp_subtask(adapter);
6259 ixgbe_watchdog_subtask(adapter);
6260 ixgbe_fdir_reinit_subtask(adapter);
6261 ixgbe_check_hang_subtask(adapter);
6263 ixgbe_service_event_complete(adapter);
6266 void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6267 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
6269 struct ixgbe_adv_tx_context_desc *context_desc;
6270 u16 i = tx_ring->next_to_use;
6272 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
6275 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6277 /* set bits to identify this as an advanced context descriptor */
6278 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6280 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6281 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6282 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6283 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6286 static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6287 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6290 u32 vlan_macip_lens, type_tucmd;
6291 u32 mss_l4len_idx, l4len;
6293 if (!skb_is_gso(skb))
6296 if (skb_header_cloned(skb)) {
6297 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6302 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6303 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6305 if (protocol == __constant_htons(ETH_P_IP)) {
6306 struct iphdr *iph = ip_hdr(skb);
6309 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6313 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6314 } else if (skb_is_gso_v6(skb)) {
6315 ipv6_hdr(skb)->payload_len = 0;
6316 tcp_hdr(skb)->check =
6317 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6318 &ipv6_hdr(skb)->daddr,
6322 l4len = tcp_hdrlen(skb);
6323 *hdr_len = skb_transport_offset(skb) + l4len;
6325 /* mss_l4len_id: use 1 as index for TSO */
6326 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6327 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6328 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6330 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6331 vlan_macip_lens = skb_network_header_len(skb);
6332 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6333 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6335 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6341 static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
6342 struct sk_buff *skb, u32 tx_flags,
6345 u32 vlan_macip_lens = 0;
6346 u32 mss_l4len_idx = 0;
6349 if (skb->ip_summed != CHECKSUM_PARTIAL) {
6350 if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6351 !(tx_flags & IXGBE_TX_FLAGS_TXSW))
6356 case __constant_htons(ETH_P_IP):
6357 vlan_macip_lens |= skb_network_header_len(skb);
6358 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6359 l4_hdr = ip_hdr(skb)->protocol;
6361 case __constant_htons(ETH_P_IPV6):
6362 vlan_macip_lens |= skb_network_header_len(skb);
6363 l4_hdr = ipv6_hdr(skb)->nexthdr;
6366 if (unlikely(net_ratelimit())) {
6367 dev_warn(tx_ring->dev,
6368 "partial checksum but proto=%x!\n",
6376 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6377 mss_l4len_idx = tcp_hdrlen(skb) <<
6378 IXGBE_ADVTXD_L4LEN_SHIFT;
6381 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6382 mss_l4len_idx = sizeof(struct sctphdr) <<
6383 IXGBE_ADVTXD_L4LEN_SHIFT;
6386 mss_l4len_idx = sizeof(struct udphdr) <<
6387 IXGBE_ADVTXD_L4LEN_SHIFT;
6390 if (unlikely(net_ratelimit())) {
6391 dev_warn(tx_ring->dev,
6392 "partial checksum but l4 proto=%x!\n",
6399 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6400 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6402 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6403 type_tucmd, mss_l4len_idx);
6405 return (skb->ip_summed == CHECKSUM_PARTIAL);
6408 static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6410 /* set type for advanced descriptor with frame checksum insertion */
6411 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6412 IXGBE_ADVTXD_DCMD_IFCS |
6413 IXGBE_ADVTXD_DCMD_DEXT);
6415 /* set HW vlan bit if vlan is present */
6416 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
6417 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6419 /* set segmentation enable bits for TSO/FSO */
6421 if ((tx_flags & IXGBE_TX_FLAGS_TSO) || (tx_flags & IXGBE_TX_FLAGS_FSO))
6423 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6425 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6430 static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen)
6432 __le32 olinfo_status =
6433 cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
6435 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6436 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM |
6437 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6438 /* enble IPv4 checksum for TSO */
6439 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6440 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
6443 /* enable L4 checksum for TSO and TX checksum offload */
6444 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6445 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6448 /* use index 1 context for FCOE/FSO */
6449 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6450 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC |
6451 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6455 * Check Context must be set if Tx switch is enabled, which it
6456 * always is for case where virtual functions are running
6458 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
6459 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6461 return olinfo_status;
6464 #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6467 static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
6468 struct sk_buff *skb,
6469 struct ixgbe_tx_buffer *first,
6473 struct device *dev = tx_ring->dev;
6474 struct ixgbe_tx_buffer *tx_buffer_info;
6475 union ixgbe_adv_tx_desc *tx_desc;
6477 __le32 cmd_type, olinfo_status;
6478 struct skb_frag_struct *frag;
6480 unsigned int data_len = skb->data_len;
6481 unsigned int size = skb_headlen(skb);
6483 u32 paylen = skb->len - hdr_len;
6484 u16 i = tx_ring->next_to_use;
6488 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6489 if (data_len >= sizeof(struct fcoe_crc_eof)) {
6490 data_len -= sizeof(struct fcoe_crc_eof);
6492 size -= sizeof(struct fcoe_crc_eof) - data_len;
6498 dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE);
6499 if (dma_mapping_error(dev, dma))
6502 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6503 olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen);
6505 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
6508 while (size > IXGBE_MAX_DATA_PER_TXD) {
6509 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6510 tx_desc->read.cmd_type_len =
6511 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
6512 tx_desc->read.olinfo_status = olinfo_status;
6514 offset += IXGBE_MAX_DATA_PER_TXD;
6515 size -= IXGBE_MAX_DATA_PER_TXD;
6519 if (i == tx_ring->count) {
6520 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
6525 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6526 tx_buffer_info->length = offset + size;
6527 tx_buffer_info->tx_flags = tx_flags;
6528 tx_buffer_info->dma = dma;
6530 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6531 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
6532 tx_desc->read.olinfo_status = olinfo_status;
6537 frag = &skb_shinfo(skb)->frags[f];
6539 size = min_t(unsigned int, data_len, skb_frag_size(frag));
6541 size = skb_frag_size(frag);
6547 tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE;
6549 dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE);
6550 if (dma_mapping_error(dev, dma))
6555 if (i == tx_ring->count) {
6556 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
6561 tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD);
6564 if (i == tx_ring->count)
6567 tx_ring->next_to_use = i;
6569 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6570 gso_segs = skb_shinfo(skb)->gso_segs;
6572 /* adjust for FCoE Sequence Offload */
6573 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6574 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6575 skb_shinfo(skb)->gso_size);
6576 #endif /* IXGBE_FCOE */
6580 /* multiply data chunks by size of headers */
6581 tx_buffer_info->bytecount = paylen + (gso_segs * hdr_len);
6582 tx_buffer_info->gso_segs = gso_segs;
6583 tx_buffer_info->skb = skb;
6585 /* set the timestamp */
6586 first->time_stamp = jiffies;
6589 * Force memory writes to complete before letting h/w
6590 * know there are new descriptors to fetch. (Only
6591 * applicable for weak-ordered memory model archs,
6596 /* set next_to_watch value indicating a packet is present */
6597 first->next_to_watch = tx_desc;
6599 /* notify HW of packet */
6600 writel(i, tx_ring->tail);
6604 dev_err(dev, "TX DMA map failed\n");
6606 /* clear dma mappings for failed tx_buffer_info map */
6608 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6609 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
6610 if (tx_buffer_info == first)
6617 dev_kfree_skb_any(skb);
6619 tx_ring->next_to_use = i;
6622 static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6623 u32 tx_flags, __be16 protocol)
6625 struct ixgbe_q_vector *q_vector = ring->q_vector;
6626 union ixgbe_atr_hash_dword input = { .dword = 0 };
6627 union ixgbe_atr_hash_dword common = { .dword = 0 };
6629 unsigned char *network;
6631 struct ipv6hdr *ipv6;
6636 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6640 /* do nothing if sampling is disabled */
6641 if (!ring->atr_sample_rate)
6646 /* snag network header to get L4 type and address */
6647 hdr.network = skb_network_header(skb);
6649 /* Currently only IPv4/IPv6 with TCP is supported */
6650 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6651 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6652 (protocol != __constant_htons(ETH_P_IP) ||
6653 hdr.ipv4->protocol != IPPROTO_TCP))
6658 /* skip this packet since it is invalid or the socket is closing */
6662 /* sample on all syn packets or once every atr sample count */
6663 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6666 /* reset sample count */
6667 ring->atr_count = 0;
6669 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6672 * src and dst are inverted, think how the receiver sees them
6674 * The input is broken into two sections, a non-compressed section
6675 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6676 * is XORed together and stored in the compressed dword.
6678 input.formatted.vlan_id = vlan_id;
6681 * since src port and flex bytes occupy the same word XOR them together
6682 * and write the value to source port portion of compressed dword
6684 if (tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
6685 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6687 common.port.src ^= th->dest ^ protocol;
6688 common.port.dst ^= th->source;
6690 if (protocol == __constant_htons(ETH_P_IP)) {
6691 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6692 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6694 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6695 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6696 hdr.ipv6->saddr.s6_addr32[1] ^
6697 hdr.ipv6->saddr.s6_addr32[2] ^
6698 hdr.ipv6->saddr.s6_addr32[3] ^
6699 hdr.ipv6->daddr.s6_addr32[0] ^
6700 hdr.ipv6->daddr.s6_addr32[1] ^
6701 hdr.ipv6->daddr.s6_addr32[2] ^
6702 hdr.ipv6->daddr.s6_addr32[3];
6705 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
6706 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6707 input, common, ring->queue_index);
6710 static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
6712 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
6713 /* Herbert's original patch had:
6714 * smp_mb__after_netif_stop_queue();
6715 * but since that doesn't exist yet, just open code it. */
6718 /* We need to check again in a case another CPU has just
6719 * made room available. */
6720 if (likely(ixgbe_desc_unused(tx_ring) < size))
6723 /* A reprieve! - use start_queue because it doesn't call schedule */
6724 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
6725 ++tx_ring->tx_stats.restart_queue;
6729 static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
6731 if (likely(ixgbe_desc_unused(tx_ring) >= size))
6733 return __ixgbe_maybe_stop_tx(tx_ring, size);
6736 static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6738 struct ixgbe_adapter *adapter = netdev_priv(dev);
6739 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6742 __be16 protocol = vlan_get_protocol(skb);
6744 if (((protocol == htons(ETH_P_FCOE)) ||
6745 (protocol == htons(ETH_P_FIP))) &&
6746 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6747 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6748 txq += adapter->ring_feature[RING_F_FCOE].mask;
6753 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6754 while (unlikely(txq >= dev->real_num_tx_queues))
6755 txq -= dev->real_num_tx_queues;
6759 return skb_tx_hash(dev, skb);
6762 netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
6763 struct ixgbe_adapter *adapter,
6764 struct ixgbe_ring *tx_ring)
6766 struct ixgbe_tx_buffer *first;
6769 #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6772 u16 count = TXD_USE_COUNT(skb_headlen(skb));
6773 __be16 protocol = skb->protocol;
6777 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
6778 * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD,
6779 * + 2 desc gap to keep tail from touching head,
6780 * + 1 desc for context descriptor,
6781 * otherwise try next time
6783 #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6784 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6785 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6787 count += skb_shinfo(skb)->nr_frags;
6789 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6790 tx_ring->tx_stats.tx_busy++;
6791 return NETDEV_TX_BUSY;
6794 #ifdef CONFIG_PCI_IOV
6795 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6796 tx_flags |= IXGBE_TX_FLAGS_TXSW;
6799 /* if we have a HW VLAN tag being added default to the HW one */
6800 if (vlan_tx_tag_present(skb)) {
6801 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6802 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6803 /* else if it is a SW VLAN check the next protocol and store the tag */
6804 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6805 struct vlan_hdr *vhdr, _vhdr;
6806 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6810 protocol = vhdr->h_vlan_encapsulated_proto;
6811 tx_flags |= ntohs(vhdr->h_vlan_TCI) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6812 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
6815 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
6816 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
6817 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6818 (skb->priority != TC_PRIO_CONTROL))) {
6819 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
6820 tx_flags |= (skb->priority & 0x7) <<
6821 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
6822 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6823 struct vlan_ethhdr *vhdr;
6824 if (skb_header_cloned(skb) &&
6825 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6827 vhdr = (struct vlan_ethhdr *)skb->data;
6828 vhdr->h_vlan_TCI = htons(tx_flags >>
6829 IXGBE_TX_FLAGS_VLAN_SHIFT);
6831 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6835 /* record the location of the first descriptor for this packet */
6836 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6839 /* setup tx offload for FCoE */
6840 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
6841 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6842 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
6846 tx_flags |= IXGBE_TX_FLAGS_FSO |
6847 IXGBE_TX_FLAGS_FCOE;
6849 tx_flags |= IXGBE_TX_FLAGS_FCOE;
6854 #endif /* IXGBE_FCOE */
6855 /* setup IPv4/IPv6 offloads */
6856 if (protocol == __constant_htons(ETH_P_IP))
6857 tx_flags |= IXGBE_TX_FLAGS_IPV4;
6859 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
6863 tx_flags |= IXGBE_TX_FLAGS_TSO;
6864 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
6865 tx_flags |= IXGBE_TX_FLAGS_CSUM;
6867 /* add the ATR filter if ATR is on */
6868 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6869 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
6873 #endif /* IXGBE_FCOE */
6874 ixgbe_tx_map(tx_ring, skb, first, tx_flags, hdr_len);
6876 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
6878 return NETDEV_TX_OK;
6881 dev_kfree_skb_any(skb);
6882 return NETDEV_TX_OK;
6885 static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
6887 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6888 struct ixgbe_ring *tx_ring;
6890 tx_ring = adapter->tx_ring[skb->queue_mapping];
6891 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6895 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6896 * @netdev: network interface device structure
6897 * @p: pointer to an address structure
6899 * Returns 0 on success, negative on failure
6901 static int ixgbe_set_mac(struct net_device *netdev, void *p)
6903 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6904 struct ixgbe_hw *hw = &adapter->hw;
6905 struct sockaddr *addr = p;
6907 if (!is_valid_ether_addr(addr->sa_data))
6908 return -EADDRNOTAVAIL;
6910 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6911 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6913 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6920 ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6922 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6923 struct ixgbe_hw *hw = &adapter->hw;
6927 if (prtad != hw->phy.mdio.prtad)
6929 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6935 static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6936 u16 addr, u16 value)
6938 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6939 struct ixgbe_hw *hw = &adapter->hw;
6941 if (prtad != hw->phy.mdio.prtad)
6943 return hw->phy.ops.write_reg(hw, addr, devad, value);
6946 static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6948 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6950 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6954 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
6956 * @netdev: network interface device structure
6958 * Returns non-zero on failure
6960 static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6963 struct ixgbe_adapter *adapter = netdev_priv(dev);
6964 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6966 if (is_valid_ether_addr(mac->san_addr)) {
6968 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6975 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
6977 * @netdev: network interface device structure
6979 * Returns non-zero on failure
6981 static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6984 struct ixgbe_adapter *adapter = netdev_priv(dev);
6985 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6987 if (is_valid_ether_addr(mac->san_addr)) {
6989 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6995 #ifdef CONFIG_NET_POLL_CONTROLLER
6997 * Polling 'interrupt' - used by things like netconsole to send skbs
6998 * without having to re-enable interrupts. It's not called while
6999 * the interrupt routine is executing.
7001 static void ixgbe_netpoll(struct net_device *netdev)
7003 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7006 /* if interface is down do nothing */
7007 if (test_bit(__IXGBE_DOWN, &adapter->state))
7010 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
7011 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
7012 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
7013 for (i = 0; i < num_q_vectors; i++) {
7014 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
7015 ixgbe_msix_clean_rings(0, q_vector);
7018 ixgbe_intr(adapter->pdev->irq, netdev);
7020 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
7024 static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7025 struct rtnl_link_stats64 *stats)
7027 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7031 for (i = 0; i < adapter->num_rx_queues; i++) {
7032 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
7038 start = u64_stats_fetch_begin_bh(&ring->syncp);
7039 packets = ring->stats.packets;
7040 bytes = ring->stats.bytes;
7041 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7042 stats->rx_packets += packets;
7043 stats->rx_bytes += bytes;
7047 for (i = 0; i < adapter->num_tx_queues; i++) {
7048 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7054 start = u64_stats_fetch_begin_bh(&ring->syncp);
7055 packets = ring->stats.packets;
7056 bytes = ring->stats.bytes;
7057 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7058 stats->tx_packets += packets;
7059 stats->tx_bytes += bytes;
7063 /* following stats updated by ixgbe_watchdog_task() */
7064 stats->multicast = netdev->stats.multicast;
7065 stats->rx_errors = netdev->stats.rx_errors;
7066 stats->rx_length_errors = netdev->stats.rx_length_errors;
7067 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7068 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7072 /* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7073 * #adapter: pointer to ixgbe_adapter
7074 * @tc: number of traffic classes currently enabled
7076 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7077 * 802.1Q priority maps to a packet buffer that exists.
7079 static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7081 struct ixgbe_hw *hw = &adapter->hw;
7085 /* 82598 have a static priority to TC mapping that can not
7086 * be changed so no validation is needed.
7088 if (hw->mac.type == ixgbe_mac_82598EB)
7091 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7094 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7095 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7097 /* If up2tc is out of bounds default to zero */
7099 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7103 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7109 /* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7112 * @netdev: net device to configure
7113 * @tc: number of traffic classes to enable
7115 int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7117 struct ixgbe_adapter *adapter = netdev_priv(dev);
7118 struct ixgbe_hw *hw = &adapter->hw;
7120 /* Multiple traffic classes requires multiple queues */
7121 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
7122 e_err(drv, "Enable failed, needs MSI-X\n");
7126 /* Hardware supports up to 8 traffic classes */
7127 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
7128 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7131 /* Hardware has to reinitialize queues and interrupts to
7132 * match packet buffer alignment. Unfortunantly, the
7133 * hardware is not flexible enough to do this dynamically.
7135 if (netif_running(dev))
7137 ixgbe_clear_interrupt_scheme(adapter);
7140 netdev_set_num_tc(dev, tc);
7141 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
7143 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
7144 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7146 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7147 adapter->hw.fc.requested_mode = ixgbe_fc_none;
7149 netdev_reset_tc(dev);
7151 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
7153 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
7154 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7156 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7157 adapter->dcb_cfg.pfc_mode_enable = false;
7160 ixgbe_init_interrupt_scheme(adapter);
7161 ixgbe_validate_rtr(adapter, tc);
7162 if (netif_running(dev))
7168 void ixgbe_do_reset(struct net_device *netdev)
7170 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7172 if (netif_running(netdev))
7173 ixgbe_reinit_locked(adapter);
7175 ixgbe_reset(adapter);
7178 static u32 ixgbe_fix_features(struct net_device *netdev, u32 data)
7180 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7183 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7184 data &= ~NETIF_F_HW_VLAN_RX;
7187 /* return error if RXHASH is being enabled when RSS is not supported */
7188 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7189 data &= ~NETIF_F_RXHASH;
7191 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7192 if (!(data & NETIF_F_RXCSUM))
7193 data &= ~NETIF_F_LRO;
7195 /* Turn off LRO if not RSC capable or invalid ITR settings */
7196 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7197 data &= ~NETIF_F_LRO;
7198 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7199 (adapter->rx_itr_setting != 1 &&
7200 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7201 data &= ~NETIF_F_LRO;
7202 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7208 static int ixgbe_set_features(struct net_device *netdev, u32 data)
7210 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7211 bool need_reset = false;
7213 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7214 if (!(data & NETIF_F_RXCSUM))
7215 adapter->flags &= ~IXGBE_FLAG_RX_CSUM_ENABLED;
7217 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
7219 /* Make sure RSC matches LRO, reset if change */
7220 if (!!(data & NETIF_F_LRO) !=
7221 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7222 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7223 switch (adapter->hw.mac.type) {
7224 case ixgbe_mac_X540:
7225 case ixgbe_mac_82599EB:
7234 * Check if Flow Director n-tuple support was enabled or disabled. If
7235 * the state changed, we need to reset.
7237 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7238 /* turn off ATR, enable perfect filters and reset */
7239 if (data & NETIF_F_NTUPLE) {
7240 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7241 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7244 } else if (!(data & NETIF_F_NTUPLE)) {
7245 /* turn off Flow Director, set ATR and reset */
7246 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7247 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7248 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7249 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7254 ixgbe_do_reset(netdev);
7260 static const struct net_device_ops ixgbe_netdev_ops = {
7261 .ndo_open = ixgbe_open,
7262 .ndo_stop = ixgbe_close,
7263 .ndo_start_xmit = ixgbe_xmit_frame,
7264 .ndo_select_queue = ixgbe_select_queue,
7265 .ndo_set_rx_mode = ixgbe_set_rx_mode,
7266 .ndo_validate_addr = eth_validate_addr,
7267 .ndo_set_mac_address = ixgbe_set_mac,
7268 .ndo_change_mtu = ixgbe_change_mtu,
7269 .ndo_tx_timeout = ixgbe_tx_timeout,
7270 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7271 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
7272 .ndo_do_ioctl = ixgbe_ioctl,
7273 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7274 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7275 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7276 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
7277 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
7278 .ndo_get_stats64 = ixgbe_get_stats64,
7279 .ndo_setup_tc = ixgbe_setup_tc,
7280 #ifdef CONFIG_NET_POLL_CONTROLLER
7281 .ndo_poll_controller = ixgbe_netpoll,
7284 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
7285 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
7286 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
7287 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7288 .ndo_fcoe_disable = ixgbe_fcoe_disable,
7289 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
7290 #endif /* IXGBE_FCOE */
7291 .ndo_set_features = ixgbe_set_features,
7292 .ndo_fix_features = ixgbe_fix_features,
7295 static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7296 const struct ixgbe_info *ii)
7298 #ifdef CONFIG_PCI_IOV
7299 struct ixgbe_hw *hw = &adapter->hw;
7301 if (hw->mac.type == ixgbe_mac_82598EB)
7304 /* The 82599 supports up to 64 VFs per physical function
7305 * but this implementation limits allocation to 63 so that
7306 * basic networking resources are still available to the
7309 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7310 ixgbe_enable_sriov(adapter, ii);
7311 #endif /* CONFIG_PCI_IOV */
7315 * ixgbe_probe - Device Initialization Routine
7316 * @pdev: PCI device information struct
7317 * @ent: entry in ixgbe_pci_tbl
7319 * Returns 0 on success, negative on failure
7321 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7322 * The OS initialization, configuring of the adapter private structure,
7323 * and a hardware reset occur.
7325 static int __devinit ixgbe_probe(struct pci_dev *pdev,
7326 const struct pci_device_id *ent)
7328 struct net_device *netdev;
7329 struct ixgbe_adapter *adapter = NULL;
7330 struct ixgbe_hw *hw;
7331 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
7332 static int cards_found;
7333 int i, err, pci_using_dac;
7334 u8 part_str[IXGBE_PBANUM_LENGTH];
7335 unsigned int indices = num_possible_cpus();
7342 /* Catch broken hardware that put the wrong VF device ID in
7343 * the PCIe SR-IOV capability.
7345 if (pdev->is_virtfn) {
7346 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7347 pci_name(pdev), pdev->vendor, pdev->device);
7351 err = pci_enable_device_mem(pdev);
7355 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7356 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
7359 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
7361 err = dma_set_coherent_mask(&pdev->dev,
7365 "No usable DMA configuration, aborting\n");
7372 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
7373 IORESOURCE_MEM), ixgbe_driver_name);
7376 "pci_request_selected_regions failed 0x%x\n", err);
7380 pci_enable_pcie_error_reporting(pdev);
7382 pci_set_master(pdev);
7383 pci_save_state(pdev);
7385 #ifdef CONFIG_IXGBE_DCB
7386 indices *= MAX_TRAFFIC_CLASS;
7389 if (ii->mac == ixgbe_mac_82598EB)
7390 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7392 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7395 indices += min_t(unsigned int, num_possible_cpus(),
7396 IXGBE_MAX_FCOE_INDICES);
7398 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
7401 goto err_alloc_etherdev;
7404 SET_NETDEV_DEV(netdev, &pdev->dev);
7406 adapter = netdev_priv(netdev);
7407 pci_set_drvdata(pdev, adapter);
7409 adapter->netdev = netdev;
7410 adapter->pdev = pdev;
7413 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7415 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
7416 pci_resource_len(pdev, 0));
7422 for (i = 1; i <= 5; i++) {
7423 if (pci_resource_len(pdev, i) == 0)
7427 netdev->netdev_ops = &ixgbe_netdev_ops;
7428 ixgbe_set_ethtool_ops(netdev);
7429 netdev->watchdog_timeo = 5 * HZ;
7430 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
7432 adapter->bd_number = cards_found;
7435 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
7436 hw->mac.type = ii->mac;
7439 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7440 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7441 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7442 if (!(eec & (1 << 8)))
7443 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7446 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
7447 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
7448 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7449 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7450 hw->phy.mdio.mmds = 0;
7451 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7452 hw->phy.mdio.dev = netdev;
7453 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7454 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
7456 ii->get_invariants(hw);
7458 /* setup the private structure */
7459 err = ixgbe_sw_init(adapter);
7463 /* Make it possible the adapter to be woken up via WOL */
7464 switch (adapter->hw.mac.type) {
7465 case ixgbe_mac_82599EB:
7466 case ixgbe_mac_X540:
7467 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
7474 * If there is a fan on this device and it has failed log the
7477 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7478 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7479 if (esdp & IXGBE_ESDP_SDP1)
7480 e_crit(probe, "Fan has stopped, replace the adapter\n");
7483 /* reset_hw fills in the perm_addr as well */
7484 hw->phy.reset_if_overtemp = true;
7485 err = hw->mac.ops.reset_hw(hw);
7486 hw->phy.reset_if_overtemp = false;
7487 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7488 hw->mac.type == ixgbe_mac_82598EB) {
7490 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
7491 e_dev_err("failed to load because an unsupported SFP+ "
7492 "module type was detected.\n");
7493 e_dev_err("Reload the driver after installing a supported "
7497 e_dev_err("HW Init failed: %d\n", err);
7501 ixgbe_probe_vf(adapter, ii);
7503 netdev->features = NETIF_F_SG |
7506 NETIF_F_HW_VLAN_TX |
7507 NETIF_F_HW_VLAN_RX |
7508 NETIF_F_HW_VLAN_FILTER |
7514 netdev->hw_features = netdev->features;
7516 switch (adapter->hw.mac.type) {
7517 case ixgbe_mac_82599EB:
7518 case ixgbe_mac_X540:
7519 netdev->features |= NETIF_F_SCTP_CSUM;
7520 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7527 netdev->vlan_features |= NETIF_F_TSO;
7528 netdev->vlan_features |= NETIF_F_TSO6;
7529 netdev->vlan_features |= NETIF_F_IP_CSUM;
7530 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
7531 netdev->vlan_features |= NETIF_F_SG;
7533 netdev->priv_flags |= IFF_UNICAST_FLT;
7535 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7536 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7537 IXGBE_FLAG_DCB_ENABLED);
7539 #ifdef CONFIG_IXGBE_DCB
7540 netdev->dcbnl_ops = &dcbnl_ops;
7544 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7545 if (hw->mac.ops.get_device_caps) {
7546 hw->mac.ops.get_device_caps(hw, &device_caps);
7547 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7548 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
7551 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7552 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7553 netdev->vlan_features |= NETIF_F_FSO;
7554 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7556 #endif /* IXGBE_FCOE */
7557 if (pci_using_dac) {
7558 netdev->features |= NETIF_F_HIGHDMA;
7559 netdev->vlan_features |= NETIF_F_HIGHDMA;
7562 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7563 netdev->hw_features |= NETIF_F_LRO;
7564 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
7565 netdev->features |= NETIF_F_LRO;
7567 /* make sure the EEPROM is good */
7568 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
7569 e_dev_err("The EEPROM Checksum Is Not Valid\n");
7574 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7575 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7577 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
7578 e_dev_err("invalid MAC address\n");
7583 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7584 (unsigned long) adapter);
7586 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7587 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
7589 err = ixgbe_init_interrupt_scheme(adapter);
7593 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7594 netdev->hw_features &= ~NETIF_F_RXHASH;
7595 netdev->features &= ~NETIF_F_RXHASH;
7598 /* WOL not supported for all but the following */
7600 switch (pdev->device) {
7601 case IXGBE_DEV_ID_82599_SFP:
7602 /* Only this subdevice supports WOL */
7603 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
7604 adapter->wol = IXGBE_WUFC_MAG;
7606 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7607 /* All except this subdevice support WOL */
7608 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7609 adapter->wol = IXGBE_WUFC_MAG;
7611 case IXGBE_DEV_ID_82599_KX4:
7612 adapter->wol = IXGBE_WUFC_MAG;
7614 case IXGBE_DEV_ID_X540T:
7615 /* Check eeprom to see if it is enabled */
7616 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7617 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7619 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7620 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7621 (hw->bus.func == 0)))
7622 adapter->wol = IXGBE_WUFC_MAG;
7625 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7627 /* save off EEPROM version number */
7628 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7629 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7631 /* pick up the PCI bus settings for reporting later */
7632 hw->mac.ops.get_bus_info(hw);
7634 /* print bus type/speed/width info */
7635 e_dev_info("(PCI Express:%s:%s) %pM\n",
7636 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7637 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
7639 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7640 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7641 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7645 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7647 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
7648 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
7649 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
7650 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
7653 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7654 hw->mac.type, hw->phy.type, part_str);
7656 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
7657 e_dev_warn("PCI-Express bandwidth available for this card is "
7658 "not sufficient for optimal performance.\n");
7659 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7663 /* reset the hardware with the new settings */
7664 err = hw->mac.ops.start_hw(hw);
7666 if (err == IXGBE_ERR_EEPROM_VERSION) {
7667 /* We are running on a pre-production device, log a warning */
7668 e_dev_warn("This device is a pre-production adapter/LOM. "
7669 "Please be aware there may be issues associated "
7670 "with your hardware. If you are experiencing "
7671 "problems please contact your Intel or hardware "
7672 "representative who provided you with this "
7675 strcpy(netdev->name, "eth%d");
7676 err = register_netdev(netdev);
7680 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7681 if (hw->mac.ops.disable_tx_laser &&
7682 ((hw->phy.multispeed_fiber) ||
7683 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7684 (hw->mac.type == ixgbe_mac_82599EB))))
7685 hw->mac.ops.disable_tx_laser(hw);
7687 /* carrier off reporting is important to ethtool even BEFORE open */
7688 netif_carrier_off(netdev);
7690 #ifdef CONFIG_IXGBE_DCA
7691 if (dca_add_requester(&pdev->dev) == 0) {
7692 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
7693 ixgbe_setup_dca(adapter);
7696 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7697 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
7698 for (i = 0; i < adapter->num_vfs; i++)
7699 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7702 /* firmware requires driver version to be 0xFFFFFFFF
7703 * since os does not support feature
7705 if (hw->mac.ops.set_fw_drv_ver)
7706 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7709 /* add san mac addr to netdev */
7710 ixgbe_add_sanmac_netdev(netdev);
7712 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
7717 ixgbe_release_hw_control(adapter);
7718 ixgbe_clear_interrupt_scheme(adapter);
7721 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7722 ixgbe_disable_sriov(adapter);
7723 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
7724 iounmap(hw->hw_addr);
7726 free_netdev(netdev);
7728 pci_release_selected_regions(pdev,
7729 pci_select_bars(pdev, IORESOURCE_MEM));
7732 pci_disable_device(pdev);
7737 * ixgbe_remove - Device Removal Routine
7738 * @pdev: PCI device information struct
7740 * ixgbe_remove is called by the PCI subsystem to alert the driver
7741 * that it should release a PCI device. The could be caused by a
7742 * Hot-Plug event, or because the driver is going to be removed from
7745 static void __devexit ixgbe_remove(struct pci_dev *pdev)
7747 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7748 struct net_device *netdev = adapter->netdev;
7750 set_bit(__IXGBE_DOWN, &adapter->state);
7751 cancel_work_sync(&adapter->service_task);
7753 #ifdef CONFIG_IXGBE_DCA
7754 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7755 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7756 dca_remove_requester(&pdev->dev);
7757 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7762 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7763 ixgbe_cleanup_fcoe(adapter);
7765 #endif /* IXGBE_FCOE */
7767 /* remove the added san mac */
7768 ixgbe_del_sanmac_netdev(netdev);
7770 if (netdev->reg_state == NETREG_REGISTERED)
7771 unregister_netdev(netdev);
7773 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7774 if (!(ixgbe_check_vf_assignment(adapter)))
7775 ixgbe_disable_sriov(adapter);
7777 e_dev_warn("Unloading driver while VFs are assigned "
7778 "- VFs will not be deallocated\n");
7781 ixgbe_clear_interrupt_scheme(adapter);
7783 ixgbe_release_hw_control(adapter);
7785 iounmap(adapter->hw.hw_addr);
7786 pci_release_selected_regions(pdev, pci_select_bars(pdev,
7789 e_dev_info("complete\n");
7791 free_netdev(netdev);
7793 pci_disable_pcie_error_reporting(pdev);
7795 pci_disable_device(pdev);
7799 * ixgbe_io_error_detected - called when PCI error is detected
7800 * @pdev: Pointer to PCI device
7801 * @state: The current pci connection state
7803 * This function is called after a PCI bus error affecting
7804 * this device has been detected.
7806 static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
7807 pci_channel_state_t state)
7809 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7810 struct net_device *netdev = adapter->netdev;
7812 #ifdef CONFIG_PCI_IOV
7813 struct pci_dev *bdev, *vfdev;
7814 u32 dw0, dw1, dw2, dw3;
7816 u16 req_id, pf_func;
7818 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7819 adapter->num_vfs == 0)
7820 goto skip_bad_vf_detection;
7822 bdev = pdev->bus->self;
7823 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT))
7824 bdev = bdev->bus->self;
7827 goto skip_bad_vf_detection;
7829 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
7831 goto skip_bad_vf_detection;
7833 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
7834 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
7835 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
7836 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
7839 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
7840 if (!(req_id & 0x0080))
7841 goto skip_bad_vf_detection;
7843 pf_func = req_id & 0x01;
7844 if ((pf_func & 1) == (pdev->devfn & 1)) {
7845 unsigned int device_id;
7847 vf = (req_id & 0x7F) >> 1;
7848 e_dev_err("VF %d has caused a PCIe error\n", vf);
7849 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
7850 "%8.8x\tdw3: %8.8x\n",
7851 dw0, dw1, dw2, dw3);
7852 switch (adapter->hw.mac.type) {
7853 case ixgbe_mac_82599EB:
7854 device_id = IXGBE_82599_VF_DEVICE_ID;
7856 case ixgbe_mac_X540:
7857 device_id = IXGBE_X540_VF_DEVICE_ID;
7864 /* Find the pci device of the offending VF */
7865 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
7867 if (vfdev->devfn == (req_id & 0xFF))
7869 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
7873 * There's a slim chance the VF could have been hot plugged,
7874 * so if it is no longer present we don't need to issue the
7875 * VFLR. Just clean up the AER in that case.
7878 e_dev_err("Issuing VFLR to VF %d\n", vf);
7879 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
7882 pci_cleanup_aer_uncorrect_error_status(pdev);
7886 * Even though the error may have occurred on the other port
7887 * we still need to increment the vf error reference count for
7888 * both ports because the I/O resume function will be called
7891 adapter->vferr_refcount++;
7893 return PCI_ERS_RESULT_RECOVERED;
7895 skip_bad_vf_detection:
7896 #endif /* CONFIG_PCI_IOV */
7897 netif_device_detach(netdev);
7899 if (state == pci_channel_io_perm_failure)
7900 return PCI_ERS_RESULT_DISCONNECT;
7902 if (netif_running(netdev))
7903 ixgbe_down(adapter);
7904 pci_disable_device(pdev);
7906 /* Request a slot reset. */
7907 return PCI_ERS_RESULT_NEED_RESET;
7911 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7912 * @pdev: Pointer to PCI device
7914 * Restart the card from scratch, as if from a cold-boot.
7916 static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7918 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7919 pci_ers_result_t result;
7922 if (pci_enable_device_mem(pdev)) {
7923 e_err(probe, "Cannot re-enable PCI device after reset.\n");
7924 result = PCI_ERS_RESULT_DISCONNECT;
7926 pci_set_master(pdev);
7927 pci_restore_state(pdev);
7928 pci_save_state(pdev);
7930 pci_wake_from_d3(pdev, false);
7932 ixgbe_reset(adapter);
7933 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
7934 result = PCI_ERS_RESULT_RECOVERED;
7937 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7939 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7940 "failed 0x%0x\n", err);
7941 /* non-fatal, continue */
7948 * ixgbe_io_resume - called when traffic can start flowing again.
7949 * @pdev: Pointer to PCI device
7951 * This callback is called when the error recovery driver tells us that
7952 * its OK to resume normal operation.
7954 static void ixgbe_io_resume(struct pci_dev *pdev)
7956 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7957 struct net_device *netdev = adapter->netdev;
7959 #ifdef CONFIG_PCI_IOV
7960 if (adapter->vferr_refcount) {
7961 e_info(drv, "Resuming after VF err\n");
7962 adapter->vferr_refcount--;
7967 if (netif_running(netdev))
7970 netif_device_attach(netdev);
7973 static struct pci_error_handlers ixgbe_err_handler = {
7974 .error_detected = ixgbe_io_error_detected,
7975 .slot_reset = ixgbe_io_slot_reset,
7976 .resume = ixgbe_io_resume,
7979 static struct pci_driver ixgbe_driver = {
7980 .name = ixgbe_driver_name,
7981 .id_table = ixgbe_pci_tbl,
7982 .probe = ixgbe_probe,
7983 .remove = __devexit_p(ixgbe_remove),
7985 .suspend = ixgbe_suspend,
7986 .resume = ixgbe_resume,
7988 .shutdown = ixgbe_shutdown,
7989 .err_handler = &ixgbe_err_handler
7993 * ixgbe_init_module - Driver Registration Routine
7995 * ixgbe_init_module is the first routine called when the driver is
7996 * loaded. All it does is register with the PCI subsystem.
7998 static int __init ixgbe_init_module(void)
8001 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
8002 pr_info("%s\n", ixgbe_copyright);
8004 #ifdef CONFIG_IXGBE_DCA
8005 dca_register_notify(&dca_notifier);
8008 ret = pci_register_driver(&ixgbe_driver);
8012 module_init(ixgbe_init_module);
8015 * ixgbe_exit_module - Driver Exit Cleanup Routine
8017 * ixgbe_exit_module is called just before the driver is removed
8020 static void __exit ixgbe_exit_module(void)
8022 #ifdef CONFIG_IXGBE_DCA
8023 dca_unregister_notify(&dca_notifier);
8025 pci_unregister_driver(&ixgbe_driver);
8026 rcu_barrier(); /* Wait for completion of call_rcu()'s */
8029 #ifdef CONFIG_IXGBE_DCA
8030 static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
8035 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
8036 __ixgbe_notify_dca);
8038 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
8041 #endif /* CONFIG_IXGBE_DCA */
8043 module_exit(ixgbe_exit_module);