1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2012 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/if_bridge.h>
48 #include <linux/prefetch.h>
49 #include <scsi/fc/fc_fcoe.h>
52 #include "ixgbe_common.h"
53 #include "ixgbe_dcb_82599.h"
54 #include "ixgbe_sriov.h"
56 char ixgbe_driver_name[] = "ixgbe";
57 static const char ixgbe_driver_string[] =
58 "Intel(R) 10 Gigabit PCI Express Network Driver";
60 char ixgbe_default_device_descr[] =
61 "Intel(R) 10 Gigabit Network Connection";
63 static char ixgbe_default_device_descr[] =
64 "Intel(R) 10 Gigabit Network Connection";
66 #define DRV_VERSION "3.11.33-k"
67 const char ixgbe_driver_version[] = DRV_VERSION;
68 static const char ixgbe_copyright[] =
69 "Copyright (c) 1999-2012 Intel Corporation.";
71 static const struct ixgbe_info *ixgbe_info_tbl[] = {
72 [board_82598] = &ixgbe_82598_info,
73 [board_82599] = &ixgbe_82599_info,
74 [board_X540] = &ixgbe_X540_info,
77 /* ixgbe_pci_tbl - PCI Device ID Table
79 * Wildcard entries (PCI_ANY_ID) should come last
80 * Last entry must be all 0s
82 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
83 * Class, Class Mask, private data (not used) }
85 static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
86 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
87 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
115 /* required last entry */
118 MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
120 #ifdef CONFIG_IXGBE_DCA
121 static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
123 static struct notifier_block dca_notifier = {
124 .notifier_call = ixgbe_notify_dca,
130 #ifdef CONFIG_PCI_IOV
131 static unsigned int max_vfs;
132 module_param(max_vfs, uint, 0);
133 MODULE_PARM_DESC(max_vfs,
134 "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63");
135 #endif /* CONFIG_PCI_IOV */
137 static unsigned int allow_unsupported_sfp;
138 module_param(allow_unsupported_sfp, uint, 0);
139 MODULE_PARM_DESC(allow_unsupported_sfp,
140 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
142 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
143 static int debug = -1;
144 module_param(debug, int, 0);
145 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
147 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
148 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
149 MODULE_LICENSE("GPL");
150 MODULE_VERSION(DRV_VERSION);
152 static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
154 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
155 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
156 schedule_work(&adapter->service_task);
159 static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
161 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
163 /* flush memory to make sure state is correct before next watchdog */
164 smp_mb__before_clear_bit();
165 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
168 struct ixgbe_reg_info {
173 static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
175 /* General Registers */
176 {IXGBE_CTRL, "CTRL"},
177 {IXGBE_STATUS, "STATUS"},
178 {IXGBE_CTRL_EXT, "CTRL_EXT"},
180 /* Interrupt Registers */
181 {IXGBE_EICR, "EICR"},
184 {IXGBE_SRRCTL(0), "SRRCTL"},
185 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
186 {IXGBE_RDLEN(0), "RDLEN"},
187 {IXGBE_RDH(0), "RDH"},
188 {IXGBE_RDT(0), "RDT"},
189 {IXGBE_RXDCTL(0), "RXDCTL"},
190 {IXGBE_RDBAL(0), "RDBAL"},
191 {IXGBE_RDBAH(0), "RDBAH"},
194 {IXGBE_TDBAL(0), "TDBAL"},
195 {IXGBE_TDBAH(0), "TDBAH"},
196 {IXGBE_TDLEN(0), "TDLEN"},
197 {IXGBE_TDH(0), "TDH"},
198 {IXGBE_TDT(0), "TDT"},
199 {IXGBE_TXDCTL(0), "TXDCTL"},
201 /* List Terminator */
207 * ixgbe_regdump - register printout routine
209 static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
215 switch (reginfo->ofs) {
216 case IXGBE_SRRCTL(0):
217 for (i = 0; i < 64; i++)
218 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
220 case IXGBE_DCA_RXCTRL(0):
221 for (i = 0; i < 64; i++)
222 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
225 for (i = 0; i < 64; i++)
226 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
229 for (i = 0; i < 64; i++)
230 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
233 for (i = 0; i < 64; i++)
234 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
236 case IXGBE_RXDCTL(0):
237 for (i = 0; i < 64; i++)
238 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
241 for (i = 0; i < 64; i++)
242 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
245 for (i = 0; i < 64; i++)
246 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
249 for (i = 0; i < 64; i++)
250 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
253 for (i = 0; i < 64; i++)
254 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
257 for (i = 0; i < 64; i++)
258 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
261 for (i = 0; i < 64; i++)
262 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
265 for (i = 0; i < 64; i++)
266 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
268 case IXGBE_TXDCTL(0):
269 for (i = 0; i < 64; i++)
270 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
273 pr_info("%-15s %08x\n", reginfo->name,
274 IXGBE_READ_REG(hw, reginfo->ofs));
278 for (i = 0; i < 8; i++) {
279 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
280 pr_err("%-15s", rname);
281 for (j = 0; j < 8; j++)
282 pr_cont(" %08x", regs[i*8+j]);
289 * ixgbe_dump - Print registers, tx-rings and rx-rings
291 static void ixgbe_dump(struct ixgbe_adapter *adapter)
293 struct net_device *netdev = adapter->netdev;
294 struct ixgbe_hw *hw = &adapter->hw;
295 struct ixgbe_reg_info *reginfo;
297 struct ixgbe_ring *tx_ring;
298 struct ixgbe_tx_buffer *tx_buffer;
299 union ixgbe_adv_tx_desc *tx_desc;
300 struct my_u0 { u64 a; u64 b; } *u0;
301 struct ixgbe_ring *rx_ring;
302 union ixgbe_adv_rx_desc *rx_desc;
303 struct ixgbe_rx_buffer *rx_buffer_info;
307 if (!netif_msg_hw(adapter))
310 /* Print netdevice Info */
312 dev_info(&adapter->pdev->dev, "Net device Info\n");
313 pr_info("Device Name state "
314 "trans_start last_rx\n");
315 pr_info("%-15s %016lX %016lX %016lX\n",
322 /* Print Registers */
323 dev_info(&adapter->pdev->dev, "Register Dump\n");
324 pr_info(" Register Name Value\n");
325 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
326 reginfo->name; reginfo++) {
327 ixgbe_regdump(hw, reginfo);
330 /* Print TX Ring Summary */
331 if (!netdev || !netif_running(netdev))
334 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
335 pr_info(" %s %s %s %s\n",
336 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
337 "leng", "ntw", "timestamp");
338 for (n = 0; n < adapter->num_tx_queues; n++) {
339 tx_ring = adapter->tx_ring[n];
340 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
341 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
342 n, tx_ring->next_to_use, tx_ring->next_to_clean,
343 (u64)dma_unmap_addr(tx_buffer, dma),
344 dma_unmap_len(tx_buffer, len),
345 tx_buffer->next_to_watch,
346 (u64)tx_buffer->time_stamp);
350 if (!netif_msg_tx_done(adapter))
351 goto rx_ring_summary;
353 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
355 /* Transmit Descriptor Formats
357 * 82598 Advanced Transmit Descriptor
358 * +--------------------------------------------------------------+
359 * 0 | Buffer Address [63:0] |
360 * +--------------------------------------------------------------+
361 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
362 * +--------------------------------------------------------------+
363 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
365 * 82598 Advanced Transmit Descriptor (Write-Back Format)
366 * +--------------------------------------------------------------+
368 * +--------------------------------------------------------------+
369 * 8 | RSV | STA | NXTSEQ |
370 * +--------------------------------------------------------------+
373 * 82599+ Advanced Transmit Descriptor
374 * +--------------------------------------------------------------+
375 * 0 | Buffer Address [63:0] |
376 * +--------------------------------------------------------------+
377 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
378 * +--------------------------------------------------------------+
379 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
381 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
382 * +--------------------------------------------------------------+
384 * +--------------------------------------------------------------+
385 * 8 | RSV | STA | RSV |
386 * +--------------------------------------------------------------+
390 for (n = 0; n < adapter->num_tx_queues; n++) {
391 tx_ring = adapter->tx_ring[n];
392 pr_info("------------------------------------\n");
393 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
394 pr_info("------------------------------------\n");
395 pr_info("%s%s %s %s %s %s\n",
396 "T [desc] [address 63:0 ] ",
397 "[PlPOIdStDDt Ln] [bi->dma ] ",
398 "leng", "ntw", "timestamp", "bi->skb");
400 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
401 tx_desc = IXGBE_TX_DESC(tx_ring, i);
402 tx_buffer = &tx_ring->tx_buffer_info[i];
403 u0 = (struct my_u0 *)tx_desc;
404 if (dma_unmap_len(tx_buffer, len) > 0) {
405 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
409 (u64)dma_unmap_addr(tx_buffer, dma),
410 dma_unmap_len(tx_buffer, len),
411 tx_buffer->next_to_watch,
412 (u64)tx_buffer->time_stamp,
414 if (i == tx_ring->next_to_use &&
415 i == tx_ring->next_to_clean)
417 else if (i == tx_ring->next_to_use)
419 else if (i == tx_ring->next_to_clean)
424 if (netif_msg_pktdata(adapter) &&
426 print_hex_dump(KERN_INFO, "",
427 DUMP_PREFIX_ADDRESS, 16, 1,
428 tx_buffer->skb->data,
429 dma_unmap_len(tx_buffer, len),
435 /* Print RX Rings Summary */
437 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
438 pr_info("Queue [NTU] [NTC]\n");
439 for (n = 0; n < adapter->num_rx_queues; n++) {
440 rx_ring = adapter->rx_ring[n];
441 pr_info("%5d %5X %5X\n",
442 n, rx_ring->next_to_use, rx_ring->next_to_clean);
446 if (!netif_msg_rx_status(adapter))
449 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
451 /* Receive Descriptor Formats
453 * 82598 Advanced Receive Descriptor (Read) Format
455 * +-----------------------------------------------------+
456 * 0 | Packet Buffer Address [63:1] |A0/NSE|
457 * +----------------------------------------------+------+
458 * 8 | Header Buffer Address [63:1] | DD |
459 * +-----------------------------------------------------+
462 * 82598 Advanced Receive Descriptor (Write-Back) Format
464 * 63 48 47 32 31 30 21 20 16 15 4 3 0
465 * +------------------------------------------------------+
466 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
467 * | Packet | IP | | | | Type | Type |
468 * | Checksum | Ident | | | | | |
469 * +------------------------------------------------------+
470 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
471 * +------------------------------------------------------+
472 * 63 48 47 32 31 20 19 0
474 * 82599+ Advanced Receive Descriptor (Read) Format
476 * +-----------------------------------------------------+
477 * 0 | Packet Buffer Address [63:1] |A0/NSE|
478 * +----------------------------------------------+------+
479 * 8 | Header Buffer Address [63:1] | DD |
480 * +-----------------------------------------------------+
483 * 82599+ Advanced Receive Descriptor (Write-Back) Format
485 * 63 48 47 32 31 30 21 20 17 16 4 3 0
486 * +------------------------------------------------------+
487 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
488 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
489 * |/ Flow Dir Flt ID | | | | | |
490 * +------------------------------------------------------+
491 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
492 * +------------------------------------------------------+
493 * 63 48 47 32 31 20 19 0
496 for (n = 0; n < adapter->num_rx_queues; n++) {
497 rx_ring = adapter->rx_ring[n];
498 pr_info("------------------------------------\n");
499 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
500 pr_info("------------------------------------\n");
502 "R [desc] [ PktBuf A0] ",
503 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
504 "<-- Adv Rx Read format\n");
506 "RWB[desc] [PcsmIpSHl PtRs] ",
507 "[vl er S cks ln] ---------------- [bi->skb ] ",
508 "<-- Adv Rx Write-Back format\n");
510 for (i = 0; i < rx_ring->count; i++) {
511 rx_buffer_info = &rx_ring->rx_buffer_info[i];
512 rx_desc = IXGBE_RX_DESC(rx_ring, i);
513 u0 = (struct my_u0 *)rx_desc;
514 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
515 if (staterr & IXGBE_RXD_STAT_DD) {
516 /* Descriptor Done */
517 pr_info("RWB[0x%03X] %016llX "
518 "%016llX ---------------- %p", i,
521 rx_buffer_info->skb);
523 pr_info("R [0x%03X] %016llX "
524 "%016llX %016llX %p", i,
527 (u64)rx_buffer_info->dma,
528 rx_buffer_info->skb);
530 if (netif_msg_pktdata(adapter) &&
531 rx_buffer_info->dma) {
532 print_hex_dump(KERN_INFO, "",
533 DUMP_PREFIX_ADDRESS, 16, 1,
534 page_address(rx_buffer_info->page) +
535 rx_buffer_info->page_offset,
536 ixgbe_rx_bufsz(rx_ring), true);
540 if (i == rx_ring->next_to_use)
542 else if (i == rx_ring->next_to_clean)
554 static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
558 /* Let firmware take over control of h/w */
559 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
560 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
561 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
564 static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
568 /* Let firmware know the driver has taken over */
569 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
570 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
571 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
575 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
576 * @adapter: pointer to adapter struct
577 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
578 * @queue: queue to map the corresponding interrupt to
579 * @msix_vector: the vector to map to the corresponding queue
582 static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
583 u8 queue, u8 msix_vector)
586 struct ixgbe_hw *hw = &adapter->hw;
587 switch (hw->mac.type) {
588 case ixgbe_mac_82598EB:
589 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
592 index = (((direction * 64) + queue) >> 2) & 0x1F;
593 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
594 ivar &= ~(0xFF << (8 * (queue & 0x3)));
595 ivar |= (msix_vector << (8 * (queue & 0x3)));
596 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
598 case ixgbe_mac_82599EB:
600 if (direction == -1) {
602 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
603 index = ((queue & 1) * 8);
604 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
605 ivar &= ~(0xFF << index);
606 ivar |= (msix_vector << index);
607 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
610 /* tx or rx causes */
611 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
612 index = ((16 * (queue & 1)) + (8 * direction));
613 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
614 ivar &= ~(0xFF << index);
615 ivar |= (msix_vector << index);
616 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
624 static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
629 switch (adapter->hw.mac.type) {
630 case ixgbe_mac_82598EB:
631 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
632 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
634 case ixgbe_mac_82599EB:
636 mask = (qmask & 0xFFFFFFFF);
637 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
638 mask = (qmask >> 32);
639 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
646 void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
647 struct ixgbe_tx_buffer *tx_buffer)
649 if (tx_buffer->skb) {
650 dev_kfree_skb_any(tx_buffer->skb);
651 if (dma_unmap_len(tx_buffer, len))
652 dma_unmap_single(ring->dev,
653 dma_unmap_addr(tx_buffer, dma),
654 dma_unmap_len(tx_buffer, len),
656 } else if (dma_unmap_len(tx_buffer, len)) {
657 dma_unmap_page(ring->dev,
658 dma_unmap_addr(tx_buffer, dma),
659 dma_unmap_len(tx_buffer, len),
662 tx_buffer->next_to_watch = NULL;
663 tx_buffer->skb = NULL;
664 dma_unmap_len_set(tx_buffer, len, 0);
665 /* tx_buffer must be completely set up in the transmit path */
668 static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
670 struct ixgbe_hw *hw = &adapter->hw;
671 struct ixgbe_hw_stats *hwstats = &adapter->stats;
675 if ((hw->fc.current_mode != ixgbe_fc_full) &&
676 (hw->fc.current_mode != ixgbe_fc_rx_pause))
679 switch (hw->mac.type) {
680 case ixgbe_mac_82598EB:
681 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
684 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
686 hwstats->lxoffrxc += data;
688 /* refill credits (no tx hang) if we received xoff */
692 for (i = 0; i < adapter->num_tx_queues; i++)
693 clear_bit(__IXGBE_HANG_CHECK_ARMED,
694 &adapter->tx_ring[i]->state);
697 static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
699 struct ixgbe_hw *hw = &adapter->hw;
700 struct ixgbe_hw_stats *hwstats = &adapter->stats;
704 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
706 if (adapter->ixgbe_ieee_pfc)
707 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
709 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
710 ixgbe_update_xoff_rx_lfc(adapter);
714 /* update stats for each tc, only valid with PFC enabled */
715 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
718 switch (hw->mac.type) {
719 case ixgbe_mac_82598EB:
720 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
723 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
725 hwstats->pxoffrxc[i] += pxoffrxc;
726 /* Get the TC for given UP */
727 tc = netdev_get_prio_tc_map(adapter->netdev, i);
728 xoff[tc] += pxoffrxc;
731 /* disarm tx queues that have received xoff frames */
732 for (i = 0; i < adapter->num_tx_queues; i++) {
733 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
735 tc = tx_ring->dcb_tc;
737 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
741 static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
743 return ring->stats.packets;
746 static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
748 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
749 struct ixgbe_hw *hw = &adapter->hw;
751 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
752 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
755 return (head < tail) ?
756 tail - head : (tail + ring->count - head);
761 static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
763 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
764 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
765 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
768 clear_check_for_tx_hang(tx_ring);
771 * Check for a hung queue, but be thorough. This verifies
772 * that a transmit has been completed since the previous
773 * check AND there is at least one packet pending. The
774 * ARMED bit is set to indicate a potential hang. The
775 * bit is cleared if a pause frame is received to remove
776 * false hang detection due to PFC or 802.3x frames. By
777 * requiring this to fail twice we avoid races with
778 * pfc clearing the ARMED bit and conditions where we
779 * run the check_tx_hang logic with a transmit completion
780 * pending but without time to complete it yet.
782 if ((tx_done_old == tx_done) && tx_pending) {
783 /* make sure it is true for two checks in a row */
784 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
787 /* update completed stats and continue */
788 tx_ring->tx_stats.tx_done_old = tx_done;
789 /* reset the countdown */
790 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
797 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
798 * @adapter: driver private struct
800 static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
803 /* Do the reset outside of interrupt context */
804 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
805 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
806 ixgbe_service_event_schedule(adapter);
811 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
812 * @q_vector: structure containing interrupt and ring information
813 * @tx_ring: tx ring to clean
815 static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
816 struct ixgbe_ring *tx_ring)
818 struct ixgbe_adapter *adapter = q_vector->adapter;
819 struct ixgbe_tx_buffer *tx_buffer;
820 union ixgbe_adv_tx_desc *tx_desc;
821 unsigned int total_bytes = 0, total_packets = 0;
822 unsigned int budget = q_vector->tx.work_limit;
823 unsigned int i = tx_ring->next_to_clean;
825 if (test_bit(__IXGBE_DOWN, &adapter->state))
828 tx_buffer = &tx_ring->tx_buffer_info[i];
829 tx_desc = IXGBE_TX_DESC(tx_ring, i);
833 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
835 /* if next_to_watch is not set then there is no work pending */
839 /* prevent any other reads prior to eop_desc */
842 /* if DD is not set pending work has not been completed */
843 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
846 /* clear next_to_watch to prevent false hangs */
847 tx_buffer->next_to_watch = NULL;
849 /* update the statistics for this packet */
850 total_bytes += tx_buffer->bytecount;
851 total_packets += tx_buffer->gso_segs;
853 if (unlikely(tx_buffer->tx_flags & IXGBE_TX_FLAGS_TSTAMP))
854 ixgbe_ptp_tx_hwtstamp(q_vector, tx_buffer->skb);
857 dev_kfree_skb_any(tx_buffer->skb);
859 /* unmap skb header data */
860 dma_unmap_single(tx_ring->dev,
861 dma_unmap_addr(tx_buffer, dma),
862 dma_unmap_len(tx_buffer, len),
865 /* clear tx_buffer data */
866 tx_buffer->skb = NULL;
867 dma_unmap_len_set(tx_buffer, len, 0);
869 /* unmap remaining buffers */
870 while (tx_desc != eop_desc) {
876 tx_buffer = tx_ring->tx_buffer_info;
877 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
880 /* unmap any remaining paged data */
881 if (dma_unmap_len(tx_buffer, len)) {
882 dma_unmap_page(tx_ring->dev,
883 dma_unmap_addr(tx_buffer, dma),
884 dma_unmap_len(tx_buffer, len),
886 dma_unmap_len_set(tx_buffer, len, 0);
890 /* move us one more past the eop_desc for start of next pkt */
896 tx_buffer = tx_ring->tx_buffer_info;
897 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
900 /* issue prefetch for next Tx descriptor */
903 /* update budget accounting */
905 } while (likely(budget));
908 tx_ring->next_to_clean = i;
909 u64_stats_update_begin(&tx_ring->syncp);
910 tx_ring->stats.bytes += total_bytes;
911 tx_ring->stats.packets += total_packets;
912 u64_stats_update_end(&tx_ring->syncp);
913 q_vector->tx.total_bytes += total_bytes;
914 q_vector->tx.total_packets += total_packets;
916 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
917 /* schedule immediate reset if we believe we hung */
918 struct ixgbe_hw *hw = &adapter->hw;
919 e_err(drv, "Detected Tx Unit Hang\n"
921 " TDH, TDT <%x>, <%x>\n"
922 " next_to_use <%x>\n"
923 " next_to_clean <%x>\n"
924 "tx_buffer_info[next_to_clean]\n"
925 " time_stamp <%lx>\n"
927 tx_ring->queue_index,
928 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
929 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
930 tx_ring->next_to_use, i,
931 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
933 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
936 "tx hang %d detected on queue %d, resetting adapter\n",
937 adapter->tx_timeout_count + 1, tx_ring->queue_index);
939 /* schedule immediate reset if we believe we hung */
940 ixgbe_tx_timeout_reset(adapter);
942 /* the adapter is about to reset, no point in enabling stuff */
946 netdev_tx_completed_queue(txring_txq(tx_ring),
947 total_packets, total_bytes);
949 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
950 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
951 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
952 /* Make sure that anybody stopping the queue after this
953 * sees the new next_to_clean.
956 if (__netif_subqueue_stopped(tx_ring->netdev,
957 tx_ring->queue_index)
958 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
959 netif_wake_subqueue(tx_ring->netdev,
960 tx_ring->queue_index);
961 ++tx_ring->tx_stats.restart_queue;
968 #ifdef CONFIG_IXGBE_DCA
969 static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
970 struct ixgbe_ring *tx_ring,
973 struct ixgbe_hw *hw = &adapter->hw;
974 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
977 switch (hw->mac.type) {
978 case ixgbe_mac_82598EB:
979 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
981 case ixgbe_mac_82599EB:
983 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
984 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
987 /* for unknown hardware do not write register */
992 * We can enable relaxed ordering for reads, but not writes when
993 * DCA is enabled. This is due to a known issue in some chipsets
994 * which will cause the DCA tag to be cleared.
996 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
997 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
998 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1000 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1003 static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1004 struct ixgbe_ring *rx_ring,
1007 struct ixgbe_hw *hw = &adapter->hw;
1008 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
1009 u8 reg_idx = rx_ring->reg_idx;
1012 switch (hw->mac.type) {
1013 case ixgbe_mac_82599EB:
1014 case ixgbe_mac_X540:
1015 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
1022 * We can enable relaxed ordering for reads, but not writes when
1023 * DCA is enabled. This is due to a known issue in some chipsets
1024 * which will cause the DCA tag to be cleared.
1026 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
1027 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1029 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
1032 static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1034 struct ixgbe_adapter *adapter = q_vector->adapter;
1035 struct ixgbe_ring *ring;
1036 int cpu = get_cpu();
1038 if (q_vector->cpu == cpu)
1041 ixgbe_for_each_ring(ring, q_vector->tx)
1042 ixgbe_update_tx_dca(adapter, ring, cpu);
1044 ixgbe_for_each_ring(ring, q_vector->rx)
1045 ixgbe_update_rx_dca(adapter, ring, cpu);
1047 q_vector->cpu = cpu;
1052 static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1056 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1059 /* always use CB2 mode, difference is masked in the CB driver */
1060 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1062 for (i = 0; i < adapter->num_q_vectors; i++) {
1063 adapter->q_vector[i]->cpu = -1;
1064 ixgbe_update_dca(adapter->q_vector[i]);
1068 static int __ixgbe_notify_dca(struct device *dev, void *data)
1070 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
1071 unsigned long event = *(unsigned long *)data;
1073 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
1077 case DCA_PROVIDER_ADD:
1078 /* if we're already enabled, don't do it again */
1079 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1081 if (dca_add_requester(dev) == 0) {
1082 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
1083 ixgbe_setup_dca(adapter);
1086 /* Fall Through since DCA is disabled. */
1087 case DCA_PROVIDER_REMOVE:
1088 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1089 dca_remove_requester(dev);
1090 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1091 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1099 #endif /* CONFIG_IXGBE_DCA */
1100 static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1101 union ixgbe_adv_rx_desc *rx_desc,
1102 struct sk_buff *skb)
1104 if (ring->netdev->features & NETIF_F_RXHASH)
1105 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
1110 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1111 * @ring: structure containing ring specific data
1112 * @rx_desc: advanced rx descriptor
1114 * Returns : true if it is FCoE pkt
1116 static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
1117 union ixgbe_adv_rx_desc *rx_desc)
1119 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1121 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
1122 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1123 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1124 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1127 #endif /* IXGBE_FCOE */
1129 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1130 * @ring: structure containing ring specific data
1131 * @rx_desc: current Rx descriptor being processed
1132 * @skb: skb currently being received and modified
1134 static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
1135 union ixgbe_adv_rx_desc *rx_desc,
1136 struct sk_buff *skb)
1138 skb_checksum_none_assert(skb);
1140 /* Rx csum disabled */
1141 if (!(ring->netdev->features & NETIF_F_RXCSUM))
1144 /* if IP and error */
1145 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1146 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
1147 ring->rx_stats.csum_err++;
1151 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
1154 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
1155 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1158 * 82599 errata, UDP frames with a 0 checksum can be marked as
1161 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1162 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
1165 ring->rx_stats.csum_err++;
1169 /* It must be a TCP or UDP packet with a valid checksum */
1170 skb->ip_summed = CHECKSUM_UNNECESSARY;
1173 static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
1175 rx_ring->next_to_use = val;
1177 /* update next to alloc since we have filled the ring */
1178 rx_ring->next_to_alloc = val;
1180 * Force memory writes to complete before letting h/w
1181 * know there are new descriptors to fetch. (Only
1182 * applicable for weak-ordered memory model archs,
1186 writel(val, rx_ring->tail);
1189 static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1190 struct ixgbe_rx_buffer *bi)
1192 struct page *page = bi->page;
1193 dma_addr_t dma = bi->dma;
1195 /* since we are recycling buffers we should seldom need to alloc */
1199 /* alloc new page for storage */
1200 if (likely(!page)) {
1201 page = __skb_alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP,
1202 bi->skb, ixgbe_rx_pg_order(rx_ring));
1203 if (unlikely(!page)) {
1204 rx_ring->rx_stats.alloc_rx_page_failed++;
1210 /* map page for use */
1211 dma = dma_map_page(rx_ring->dev, page, 0,
1212 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1215 * if mapping failed free memory back to system since
1216 * there isn't much point in holding memory we can't use
1218 if (dma_mapping_error(rx_ring->dev, dma)) {
1219 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
1222 rx_ring->rx_stats.alloc_rx_page_failed++;
1227 bi->page_offset = 0;
1233 * ixgbe_alloc_rx_buffers - Replace used receive buffers
1234 * @rx_ring: ring to place buffers on
1235 * @cleaned_count: number of buffers to replace
1237 void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
1239 union ixgbe_adv_rx_desc *rx_desc;
1240 struct ixgbe_rx_buffer *bi;
1241 u16 i = rx_ring->next_to_use;
1247 rx_desc = IXGBE_RX_DESC(rx_ring, i);
1248 bi = &rx_ring->rx_buffer_info[i];
1249 i -= rx_ring->count;
1252 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
1256 * Refresh the desc even if buffer_addrs didn't change
1257 * because each write-back erases this info.
1259 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
1265 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
1266 bi = rx_ring->rx_buffer_info;
1267 i -= rx_ring->count;
1270 /* clear the hdr_addr for the next_to_use descriptor */
1271 rx_desc->read.hdr_addr = 0;
1274 } while (cleaned_count);
1276 i += rx_ring->count;
1278 if (rx_ring->next_to_use != i)
1279 ixgbe_release_rx_desc(rx_ring, i);
1283 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1284 * @data: pointer to the start of the headers
1285 * @max_len: total length of section to find headers in
1287 * This function is meant to determine the length of headers that will
1288 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1289 * motivation of doing this is to only perform one pull for IPv4 TCP
1290 * packets so that we can do basic things like calculating the gso_size
1291 * based on the average data per packet.
1293 static unsigned int ixgbe_get_headlen(unsigned char *data,
1294 unsigned int max_len)
1297 unsigned char *network;
1300 struct vlan_hdr *vlan;
1303 struct ipv6hdr *ipv6;
1306 u8 nexthdr = 0; /* default to not TCP */
1309 /* this should never happen, but better safe than sorry */
1310 if (max_len < ETH_HLEN)
1313 /* initialize network frame pointer */
1316 /* set first protocol and move network header forward */
1317 protocol = hdr.eth->h_proto;
1318 hdr.network += ETH_HLEN;
1320 /* handle any vlan tag if present */
1321 if (protocol == __constant_htons(ETH_P_8021Q)) {
1322 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1325 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1326 hdr.network += VLAN_HLEN;
1329 /* handle L3 protocols */
1330 if (protocol == __constant_htons(ETH_P_IP)) {
1331 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1334 /* access ihl as a u8 to avoid unaligned access on ia64 */
1335 hlen = (hdr.network[0] & 0x0F) << 2;
1337 /* verify hlen meets minimum size requirements */
1338 if (hlen < sizeof(struct iphdr))
1339 return hdr.network - data;
1341 /* record next protocol if header is present */
1342 if (!hdr.ipv4->frag_off)
1343 nexthdr = hdr.ipv4->protocol;
1344 } else if (protocol == __constant_htons(ETH_P_IPV6)) {
1345 if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr)))
1348 /* record next protocol */
1349 nexthdr = hdr.ipv6->nexthdr;
1350 hlen = sizeof(struct ipv6hdr);
1352 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1353 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1355 hlen = FCOE_HEADER_LEN;
1358 return hdr.network - data;
1361 /* relocate pointer to start of L4 header */
1362 hdr.network += hlen;
1364 /* finally sort out TCP/UDP */
1365 if (nexthdr == IPPROTO_TCP) {
1366 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1369 /* access doff as a u8 to avoid unaligned access on ia64 */
1370 hlen = (hdr.network[12] & 0xF0) >> 2;
1372 /* verify hlen meets minimum size requirements */
1373 if (hlen < sizeof(struct tcphdr))
1374 return hdr.network - data;
1376 hdr.network += hlen;
1377 } else if (nexthdr == IPPROTO_UDP) {
1378 if ((hdr.network - data) > (max_len - sizeof(struct udphdr)))
1381 hdr.network += sizeof(struct udphdr);
1385 * If everything has gone correctly hdr.network should be the
1386 * data section of the packet and will be the end of the header.
1387 * If not then it probably represents the end of the last recognized
1390 if ((hdr.network - data) < max_len)
1391 return hdr.network - data;
1396 static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1397 struct sk_buff *skb)
1399 u16 hdr_len = skb_headlen(skb);
1401 /* set gso_size to avoid messing up TCP MSS */
1402 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1403 IXGBE_CB(skb)->append_cnt);
1404 if (skb->protocol == __constant_htons(ETH_P_IPV6))
1405 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
1407 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1410 static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1411 struct sk_buff *skb)
1413 /* if append_cnt is 0 then frame is not RSC */
1414 if (!IXGBE_CB(skb)->append_cnt)
1417 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1418 rx_ring->rx_stats.rsc_flush++;
1420 ixgbe_set_rsc_gso_size(rx_ring, skb);
1422 /* gso_size is computed using append_cnt so always clear it last */
1423 IXGBE_CB(skb)->append_cnt = 0;
1427 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1428 * @rx_ring: rx descriptor ring packet is being transacted on
1429 * @rx_desc: pointer to the EOP Rx descriptor
1430 * @skb: pointer to current skb being populated
1432 * This function checks the ring, descriptor, and packet information in
1433 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1434 * other fields within the skb.
1436 static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1437 union ixgbe_adv_rx_desc *rx_desc,
1438 struct sk_buff *skb)
1440 struct net_device *dev = rx_ring->netdev;
1442 skb->protocol = eth_type_trans(skb, dev);
1444 ixgbe_update_rsc_stats(rx_ring, skb);
1446 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1448 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1450 ixgbe_ptp_rx_hwtstamp(rx_ring->q_vector, rx_desc, skb);
1452 if ((dev->features & NETIF_F_HW_VLAN_RX) &&
1453 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1454 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1455 __vlan_hwaccel_put_tag(skb, vid);
1458 skb_record_rx_queue(skb, rx_ring->queue_index);
1461 static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1462 struct sk_buff *skb)
1464 struct ixgbe_adapter *adapter = q_vector->adapter;
1466 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1467 napi_gro_receive(&q_vector->napi, skb);
1473 * ixgbe_is_non_eop - process handling of non-EOP buffers
1474 * @rx_ring: Rx ring being processed
1475 * @rx_desc: Rx descriptor for current buffer
1476 * @skb: Current socket buffer containing buffer in progress
1478 * This function updates next to clean. If the buffer is an EOP buffer
1479 * this function exits returning false, otherwise it will place the
1480 * sk_buff in the next buffer to be chained and return true indicating
1481 * that this is in fact a non-EOP buffer.
1483 static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1484 union ixgbe_adv_rx_desc *rx_desc,
1485 struct sk_buff *skb)
1487 u32 ntc = rx_ring->next_to_clean + 1;
1489 /* fetch, update, and store next to clean */
1490 ntc = (ntc < rx_ring->count) ? ntc : 0;
1491 rx_ring->next_to_clean = ntc;
1493 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1495 /* update RSC append count if present */
1496 if (ring_is_rsc_enabled(rx_ring)) {
1497 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1498 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1500 if (unlikely(rsc_enabled)) {
1501 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1503 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1504 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1506 /* update ntc based on RSC value */
1507 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1508 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1509 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1513 /* if we are the last buffer then there is nothing else to do */
1514 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1517 /* place skb in next buffer to be received */
1518 rx_ring->rx_buffer_info[ntc].skb = skb;
1519 rx_ring->rx_stats.non_eop_descs++;
1525 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1526 * @rx_ring: rx descriptor ring packet is being transacted on
1527 * @skb: pointer to current skb being adjusted
1529 * This function is an ixgbe specific version of __pskb_pull_tail. The
1530 * main difference between this version and the original function is that
1531 * this function can make several assumptions about the state of things
1532 * that allow for significant optimizations versus the standard function.
1533 * As a result we can do things like drop a frag and maintain an accurate
1534 * truesize for the skb.
1536 static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1537 struct sk_buff *skb)
1539 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1541 unsigned int pull_len;
1544 * it is valid to use page_address instead of kmap since we are
1545 * working with pages allocated out of the lomem pool per
1546 * alloc_page(GFP_ATOMIC)
1548 va = skb_frag_address(frag);
1551 * we need the header to contain the greater of either ETH_HLEN or
1552 * 60 bytes if the skb->len is less than 60 for skb_pad.
1554 pull_len = ixgbe_get_headlen(va, IXGBE_RX_HDR_SIZE);
1556 /* align pull length to size of long to optimize memcpy performance */
1557 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1559 /* update all of the pointers */
1560 skb_frag_size_sub(frag, pull_len);
1561 frag->page_offset += pull_len;
1562 skb->data_len -= pull_len;
1563 skb->tail += pull_len;
1567 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1568 * @rx_ring: rx descriptor ring packet is being transacted on
1569 * @skb: pointer to current skb being updated
1571 * This function provides a basic DMA sync up for the first fragment of an
1572 * skb. The reason for doing this is that the first fragment cannot be
1573 * unmapped until we have reached the end of packet descriptor for a buffer
1576 static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1577 struct sk_buff *skb)
1579 /* if the page was released unmap it, else just sync our portion */
1580 if (unlikely(IXGBE_CB(skb)->page_released)) {
1581 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1582 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1583 IXGBE_CB(skb)->page_released = false;
1585 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1587 dma_sync_single_range_for_cpu(rx_ring->dev,
1590 ixgbe_rx_bufsz(rx_ring),
1593 IXGBE_CB(skb)->dma = 0;
1597 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1598 * @rx_ring: rx descriptor ring packet is being transacted on
1599 * @rx_desc: pointer to the EOP Rx descriptor
1600 * @skb: pointer to current skb being fixed
1602 * Check for corrupted packet headers caused by senders on the local L2
1603 * embedded NIC switch not setting up their Tx Descriptors right. These
1604 * should be very rare.
1606 * Also address the case where we are pulling data in on pages only
1607 * and as such no data is present in the skb header.
1609 * In addition if skb is not at least 60 bytes we need to pad it so that
1610 * it is large enough to qualify as a valid Ethernet frame.
1612 * Returns true if an error was encountered and skb was freed.
1614 static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1615 union ixgbe_adv_rx_desc *rx_desc,
1616 struct sk_buff *skb)
1618 struct net_device *netdev = rx_ring->netdev;
1620 /* verify that the packet does not have any known errors */
1621 if (unlikely(ixgbe_test_staterr(rx_desc,
1622 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1623 !(netdev->features & NETIF_F_RXALL))) {
1624 dev_kfree_skb_any(skb);
1628 /* place header in linear portion of buffer */
1629 if (skb_is_nonlinear(skb))
1630 ixgbe_pull_tail(rx_ring, skb);
1633 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1634 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1638 /* if skb_pad returns an error the skb was freed */
1639 if (unlikely(skb->len < 60)) {
1640 int pad_len = 60 - skb->len;
1642 if (skb_pad(skb, pad_len))
1644 __skb_put(skb, pad_len);
1651 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1652 * @rx_ring: rx descriptor ring to store buffers on
1653 * @old_buff: donor buffer to have page reused
1655 * Synchronizes page for reuse by the adapter
1657 static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1658 struct ixgbe_rx_buffer *old_buff)
1660 struct ixgbe_rx_buffer *new_buff;
1661 u16 nta = rx_ring->next_to_alloc;
1663 new_buff = &rx_ring->rx_buffer_info[nta];
1665 /* update, and store next to alloc */
1667 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1669 /* transfer page from old buffer to new buffer */
1670 new_buff->page = old_buff->page;
1671 new_buff->dma = old_buff->dma;
1672 new_buff->page_offset = old_buff->page_offset;
1674 /* sync the buffer for use by the device */
1675 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
1676 new_buff->page_offset,
1677 ixgbe_rx_bufsz(rx_ring),
1682 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1683 * @rx_ring: rx descriptor ring to transact packets on
1684 * @rx_buffer: buffer containing page to add
1685 * @rx_desc: descriptor containing length of buffer written by hardware
1686 * @skb: sk_buff to place the data into
1688 * This function will add the data contained in rx_buffer->page to the skb.
1689 * This is done either through a direct copy if the data in the buffer is
1690 * less than the skb header size, otherwise it will just attach the page as
1691 * a frag to the skb.
1693 * The function will then update the page offset if necessary and return
1694 * true if the buffer can be reused by the adapter.
1696 static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
1697 struct ixgbe_rx_buffer *rx_buffer,
1698 union ixgbe_adv_rx_desc *rx_desc,
1699 struct sk_buff *skb)
1701 struct page *page = rx_buffer->page;
1702 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
1703 #if (PAGE_SIZE < 8192)
1704 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
1706 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1707 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1708 ixgbe_rx_bufsz(rx_ring);
1711 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1712 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1714 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1716 /* we can reuse buffer as-is, just make sure it is local */
1717 if (likely(page_to_nid(page) == numa_node_id()))
1720 /* this page cannot be reused so discard it */
1725 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1726 rx_buffer->page_offset, size, truesize);
1728 /* avoid re-using remote pages */
1729 if (unlikely(page_to_nid(page) != numa_node_id()))
1732 #if (PAGE_SIZE < 8192)
1733 /* if we are only owner of page we can reuse it */
1734 if (unlikely(page_count(page) != 1))
1737 /* flip page offset to other buffer */
1738 rx_buffer->page_offset ^= truesize;
1741 * since we are the only owner of the page and we need to
1742 * increment it, just set the value to 2 in order to avoid
1743 * an unecessary locked operation
1745 atomic_set(&page->_count, 2);
1747 /* move offset up to the next cache line */
1748 rx_buffer->page_offset += truesize;
1750 if (rx_buffer->page_offset > last_offset)
1753 /* bump ref count on page before it is given to the stack */
1760 static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
1761 union ixgbe_adv_rx_desc *rx_desc)
1763 struct ixgbe_rx_buffer *rx_buffer;
1764 struct sk_buff *skb;
1767 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
1768 page = rx_buffer->page;
1771 skb = rx_buffer->skb;
1774 void *page_addr = page_address(page) +
1775 rx_buffer->page_offset;
1777 /* prefetch first cache line of first page */
1778 prefetch(page_addr);
1779 #if L1_CACHE_BYTES < 128
1780 prefetch(page_addr + L1_CACHE_BYTES);
1783 /* allocate a skb to store the frags */
1784 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1786 if (unlikely(!skb)) {
1787 rx_ring->rx_stats.alloc_rx_buff_failed++;
1792 * we will be copying header into skb->data in
1793 * pskb_may_pull so it is in our interest to prefetch
1794 * it now to avoid a possible cache miss
1796 prefetchw(skb->data);
1799 * Delay unmapping of the first packet. It carries the
1800 * header information, HW may still access the header
1801 * after the writeback. Only unmap it when EOP is
1804 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1807 IXGBE_CB(skb)->dma = rx_buffer->dma;
1809 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
1810 ixgbe_dma_sync_frag(rx_ring, skb);
1813 /* we are reusing so sync this buffer for CPU use */
1814 dma_sync_single_range_for_cpu(rx_ring->dev,
1816 rx_buffer->page_offset,
1817 ixgbe_rx_bufsz(rx_ring),
1821 /* pull page into skb */
1822 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
1823 /* hand second half of page back to the ring */
1824 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1825 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1826 /* the page has been released from the ring */
1827 IXGBE_CB(skb)->page_released = true;
1829 /* we are not reusing the buffer so unmap it */
1830 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1831 ixgbe_rx_pg_size(rx_ring),
1835 /* clear contents of buffer_info */
1836 rx_buffer->skb = NULL;
1838 rx_buffer->page = NULL;
1844 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1845 * @q_vector: structure containing interrupt and ring information
1846 * @rx_ring: rx descriptor ring to transact packets on
1847 * @budget: Total limit on number of packets to process
1849 * This function provides a "bounce buffer" approach to Rx interrupt
1850 * processing. The advantage to this is that on systems that have
1851 * expensive overhead for IOMMU access this provides a means of avoiding
1852 * it by maintaining the mapping of the page to the syste.
1854 * Returns true if all work is completed without reaching budget
1856 static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
1857 struct ixgbe_ring *rx_ring,
1860 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1862 struct ixgbe_adapter *adapter = q_vector->adapter;
1864 unsigned int mss = 0;
1865 #endif /* IXGBE_FCOE */
1866 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
1869 union ixgbe_adv_rx_desc *rx_desc;
1870 struct sk_buff *skb;
1872 /* return some buffers to hardware, one at a time is too slow */
1873 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1874 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1878 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
1880 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1884 * This memory barrier is needed to keep us from reading
1885 * any other fields out of the rx_desc until we know the
1886 * RXD_STAT_DD bit is set
1890 /* retrieve a buffer from the ring */
1891 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
1893 /* exit if we failed to retrieve a buffer */
1899 /* place incomplete frames back on ring for completion */
1900 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1903 /* verify the packet layout is correct */
1904 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1907 /* probably a little skewed due to removing CRC */
1908 total_rx_bytes += skb->len;
1910 /* populate checksum, timestamp, VLAN, and protocol */
1911 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1914 /* if ddp, not passing to ULD unless for FCP_RSP or error */
1915 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
1916 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
1917 /* include DDPed FCoE data */
1918 if (ddp_bytes > 0) {
1920 mss = rx_ring->netdev->mtu -
1921 sizeof(struct fcoe_hdr) -
1922 sizeof(struct fc_frame_header) -
1923 sizeof(struct fcoe_crc_eof);
1927 total_rx_bytes += ddp_bytes;
1928 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
1932 dev_kfree_skb_any(skb);
1937 #endif /* IXGBE_FCOE */
1938 ixgbe_rx_skb(q_vector, skb);
1940 /* update budget accounting */
1942 } while (likely(total_rx_packets < budget));
1944 u64_stats_update_begin(&rx_ring->syncp);
1945 rx_ring->stats.packets += total_rx_packets;
1946 rx_ring->stats.bytes += total_rx_bytes;
1947 u64_stats_update_end(&rx_ring->syncp);
1948 q_vector->rx.total_packets += total_rx_packets;
1949 q_vector->rx.total_bytes += total_rx_bytes;
1952 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1954 return (total_rx_packets < budget);
1958 * ixgbe_configure_msix - Configure MSI-X hardware
1959 * @adapter: board private structure
1961 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1964 static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1966 struct ixgbe_q_vector *q_vector;
1970 /* Populate MSIX to EITR Select */
1971 if (adapter->num_vfs > 32) {
1972 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1973 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1977 * Populate the IVAR table and set the ITR values to the
1978 * corresponding register.
1980 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
1981 struct ixgbe_ring *ring;
1982 q_vector = adapter->q_vector[v_idx];
1984 ixgbe_for_each_ring(ring, q_vector->rx)
1985 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
1987 ixgbe_for_each_ring(ring, q_vector->tx)
1988 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
1990 ixgbe_write_eitr(q_vector);
1993 switch (adapter->hw.mac.type) {
1994 case ixgbe_mac_82598EB:
1995 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
1998 case ixgbe_mac_82599EB:
1999 case ixgbe_mac_X540:
2000 ixgbe_set_ivar(adapter, -1, 1, v_idx);
2005 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
2007 /* set up to autoclear timer, and the vectors */
2008 mask = IXGBE_EIMS_ENABLE_MASK;
2009 mask &= ~(IXGBE_EIMS_OTHER |
2010 IXGBE_EIMS_MAILBOX |
2013 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
2016 enum latency_range {
2020 latency_invalid = 255
2024 * ixgbe_update_itr - update the dynamic ITR value based on statistics
2025 * @q_vector: structure containing interrupt and ring information
2026 * @ring_container: structure containing ring performance data
2028 * Stores a new ITR value based on packets and byte
2029 * counts during the last interrupt. The advantage of per interrupt
2030 * computation is faster updates and more accurate ITR for the current
2031 * traffic pattern. Constants in this function were computed
2032 * based on theoretical maximum wire speed and thresholds were set based
2033 * on testing data as well as attempting to minimize response time
2034 * while increasing bulk throughput.
2035 * this functionality is controlled by the InterruptThrottleRate module
2036 * parameter (see ixgbe_param.c)
2038 static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2039 struct ixgbe_ring_container *ring_container)
2041 int bytes = ring_container->total_bytes;
2042 int packets = ring_container->total_packets;
2045 u8 itr_setting = ring_container->itr;
2050 /* simple throttlerate management
2051 * 0-10MB/s lowest (100000 ints/s)
2052 * 10-20MB/s low (20000 ints/s)
2053 * 20-1249MB/s bulk (8000 ints/s)
2055 /* what was last interrupt timeslice? */
2056 timepassed_us = q_vector->itr >> 2;
2057 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2059 switch (itr_setting) {
2060 case lowest_latency:
2061 if (bytes_perint > 10)
2062 itr_setting = low_latency;
2065 if (bytes_perint > 20)
2066 itr_setting = bulk_latency;
2067 else if (bytes_perint <= 10)
2068 itr_setting = lowest_latency;
2071 if (bytes_perint <= 20)
2072 itr_setting = low_latency;
2076 /* clear work counters since we have the values we need */
2077 ring_container->total_bytes = 0;
2078 ring_container->total_packets = 0;
2080 /* write updated itr to ring container */
2081 ring_container->itr = itr_setting;
2085 * ixgbe_write_eitr - write EITR register in hardware specific way
2086 * @q_vector: structure containing interrupt and ring information
2088 * This function is made to be called by ethtool and by the driver
2089 * when it needs to update EITR registers at runtime. Hardware
2090 * specific quirks/differences are taken care of here.
2092 void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
2094 struct ixgbe_adapter *adapter = q_vector->adapter;
2095 struct ixgbe_hw *hw = &adapter->hw;
2096 int v_idx = q_vector->v_idx;
2097 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
2099 switch (adapter->hw.mac.type) {
2100 case ixgbe_mac_82598EB:
2101 /* must write high and low 16 bits to reset counter */
2102 itr_reg |= (itr_reg << 16);
2104 case ixgbe_mac_82599EB:
2105 case ixgbe_mac_X540:
2107 * set the WDIS bit to not clear the timer bits and cause an
2108 * immediate assertion of the interrupt
2110 itr_reg |= IXGBE_EITR_CNT_WDIS;
2115 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2118 static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
2120 u32 new_itr = q_vector->itr;
2123 ixgbe_update_itr(q_vector, &q_vector->tx);
2124 ixgbe_update_itr(q_vector, &q_vector->rx);
2126 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
2128 switch (current_itr) {
2129 /* counts and packets in update_itr are dependent on these numbers */
2130 case lowest_latency:
2131 new_itr = IXGBE_100K_ITR;
2134 new_itr = IXGBE_20K_ITR;
2137 new_itr = IXGBE_8K_ITR;
2143 if (new_itr != q_vector->itr) {
2144 /* do an exponential smoothing */
2145 new_itr = (10 * new_itr * q_vector->itr) /
2146 ((9 * new_itr) + q_vector->itr);
2148 /* save the algorithm value here */
2149 q_vector->itr = new_itr;
2151 ixgbe_write_eitr(q_vector);
2156 * ixgbe_check_overtemp_subtask - check for over temperature
2157 * @adapter: pointer to adapter
2159 static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
2161 struct ixgbe_hw *hw = &adapter->hw;
2162 u32 eicr = adapter->interrupt_event;
2164 if (test_bit(__IXGBE_DOWN, &adapter->state))
2167 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2168 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2171 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2173 switch (hw->device_id) {
2174 case IXGBE_DEV_ID_82599_T3_LOM:
2176 * Since the warning interrupt is for both ports
2177 * we don't have to check if:
2178 * - This interrupt wasn't for our port.
2179 * - We may have missed the interrupt so always have to
2180 * check if we got a LSC
2182 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2183 !(eicr & IXGBE_EICR_LSC))
2186 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
2188 bool link_up = false;
2190 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2196 /* Check if this is not due to overtemp */
2197 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2202 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2207 "Network adapter has been stopped because it has over heated. "
2208 "Restart the computer. If the problem persists, "
2209 "power off the system and replace the adapter\n");
2211 adapter->interrupt_event = 0;
2214 static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2216 struct ixgbe_hw *hw = &adapter->hw;
2218 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2219 (eicr & IXGBE_EICR_GPI_SDP1)) {
2220 e_crit(probe, "Fan has stopped, replace the adapter\n");
2221 /* write to clear the interrupt */
2222 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2226 static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2228 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2231 switch (adapter->hw.mac.type) {
2232 case ixgbe_mac_82599EB:
2234 * Need to check link state so complete overtemp check
2237 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2238 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2239 adapter->interrupt_event = eicr;
2240 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2241 ixgbe_service_event_schedule(adapter);
2245 case ixgbe_mac_X540:
2246 if (!(eicr & IXGBE_EICR_TS))
2254 "Network adapter has been stopped because it has over heated. "
2255 "Restart the computer. If the problem persists, "
2256 "power off the system and replace the adapter\n");
2259 static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2261 struct ixgbe_hw *hw = &adapter->hw;
2263 if (eicr & IXGBE_EICR_GPI_SDP2) {
2264 /* Clear the interrupt */
2265 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
2266 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2267 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2268 ixgbe_service_event_schedule(adapter);
2272 if (eicr & IXGBE_EICR_GPI_SDP1) {
2273 /* Clear the interrupt */
2274 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2275 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2276 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2277 ixgbe_service_event_schedule(adapter);
2282 static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2284 struct ixgbe_hw *hw = &adapter->hw;
2287 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2288 adapter->link_check_timeout = jiffies;
2289 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2290 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
2291 IXGBE_WRITE_FLUSH(hw);
2292 ixgbe_service_event_schedule(adapter);
2296 static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2300 struct ixgbe_hw *hw = &adapter->hw;
2302 switch (hw->mac.type) {
2303 case ixgbe_mac_82598EB:
2304 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
2305 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2307 case ixgbe_mac_82599EB:
2308 case ixgbe_mac_X540:
2309 mask = (qmask & 0xFFFFFFFF);
2311 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
2312 mask = (qmask >> 32);
2314 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2319 /* skip the flush */
2322 static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
2326 struct ixgbe_hw *hw = &adapter->hw;
2328 switch (hw->mac.type) {
2329 case ixgbe_mac_82598EB:
2330 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
2331 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2333 case ixgbe_mac_82599EB:
2334 case ixgbe_mac_X540:
2335 mask = (qmask & 0xFFFFFFFF);
2337 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
2338 mask = (qmask >> 32);
2340 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2345 /* skip the flush */
2349 * ixgbe_irq_enable - Enable default interrupt generation settings
2350 * @adapter: board private structure
2352 static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2355 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
2357 /* don't reenable LSC while waiting for link */
2358 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2359 mask &= ~IXGBE_EIMS_LSC;
2361 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2362 switch (adapter->hw.mac.type) {
2363 case ixgbe_mac_82599EB:
2364 mask |= IXGBE_EIMS_GPI_SDP0;
2366 case ixgbe_mac_X540:
2367 mask |= IXGBE_EIMS_TS;
2372 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2373 mask |= IXGBE_EIMS_GPI_SDP1;
2374 switch (adapter->hw.mac.type) {
2375 case ixgbe_mac_82599EB:
2376 mask |= IXGBE_EIMS_GPI_SDP1;
2377 mask |= IXGBE_EIMS_GPI_SDP2;
2378 case ixgbe_mac_X540:
2379 mask |= IXGBE_EIMS_ECC;
2380 mask |= IXGBE_EIMS_MAILBOX;
2386 if (adapter->hw.mac.type == ixgbe_mac_X540)
2387 mask |= IXGBE_EIMS_TIMESYNC;
2389 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2390 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2391 mask |= IXGBE_EIMS_FLOW_DIR;
2393 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2395 ixgbe_irq_enable_queues(adapter, ~0);
2397 IXGBE_WRITE_FLUSH(&adapter->hw);
2400 static irqreturn_t ixgbe_msix_other(int irq, void *data)
2402 struct ixgbe_adapter *adapter = data;
2403 struct ixgbe_hw *hw = &adapter->hw;
2407 * Workaround for Silicon errata. Use clear-by-write instead
2408 * of clear-by-read. Reading with EICS will return the
2409 * interrupt causes without clearing, which later be done
2410 * with the write to EICR.
2412 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2413 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
2415 if (eicr & IXGBE_EICR_LSC)
2416 ixgbe_check_lsc(adapter);
2418 if (eicr & IXGBE_EICR_MAILBOX)
2419 ixgbe_msg_task(adapter);
2421 switch (hw->mac.type) {
2422 case ixgbe_mac_82599EB:
2423 case ixgbe_mac_X540:
2424 if (eicr & IXGBE_EICR_ECC)
2425 e_info(link, "Received unrecoverable ECC Err, please "
2427 /* Handle Flow Director Full threshold interrupt */
2428 if (eicr & IXGBE_EICR_FLOW_DIR) {
2429 int reinit_count = 0;
2431 for (i = 0; i < adapter->num_tx_queues; i++) {
2432 struct ixgbe_ring *ring = adapter->tx_ring[i];
2433 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2438 /* no more flow director interrupts until after init */
2439 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2440 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2441 ixgbe_service_event_schedule(adapter);
2444 ixgbe_check_sfp_event(adapter, eicr);
2445 ixgbe_check_overtemp_event(adapter, eicr);
2451 ixgbe_check_fan_failure(adapter, eicr);
2453 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2454 ixgbe_ptp_check_pps_event(adapter, eicr);
2456 /* re-enable the original interrupt state, no lsc, no queues */
2457 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2458 ixgbe_irq_enable(adapter, false, false);
2463 static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
2465 struct ixgbe_q_vector *q_vector = data;
2467 /* EIAM disabled interrupts (on this vector) for us */
2469 if (q_vector->rx.ring || q_vector->tx.ring)
2470 napi_schedule(&q_vector->napi);
2476 * ixgbe_poll - NAPI Rx polling callback
2477 * @napi: structure for representing this polling device
2478 * @budget: how many packets driver is allowed to clean
2480 * This function is used for legacy and MSI, NAPI mode
2482 int ixgbe_poll(struct napi_struct *napi, int budget)
2484 struct ixgbe_q_vector *q_vector =
2485 container_of(napi, struct ixgbe_q_vector, napi);
2486 struct ixgbe_adapter *adapter = q_vector->adapter;
2487 struct ixgbe_ring *ring;
2488 int per_ring_budget;
2489 bool clean_complete = true;
2491 #ifdef CONFIG_IXGBE_DCA
2492 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2493 ixgbe_update_dca(q_vector);
2496 ixgbe_for_each_ring(ring, q_vector->tx)
2497 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2499 /* attempt to distribute budget to each queue fairly, but don't allow
2500 * the budget to go below 1 because we'll exit polling */
2501 if (q_vector->rx.count > 1)
2502 per_ring_budget = max(budget/q_vector->rx.count, 1);
2504 per_ring_budget = budget;
2506 ixgbe_for_each_ring(ring, q_vector->rx)
2507 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
2510 /* If all work not completed, return budget and keep polling */
2511 if (!clean_complete)
2514 /* all work done, exit the polling mode */
2515 napi_complete(napi);
2516 if (adapter->rx_itr_setting & 1)
2517 ixgbe_set_itr(q_vector);
2518 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2519 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2525 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2526 * @adapter: board private structure
2528 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2529 * interrupts from the kernel.
2531 static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2533 struct net_device *netdev = adapter->netdev;
2537 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2538 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2539 struct msix_entry *entry = &adapter->msix_entries[vector];
2541 if (q_vector->tx.ring && q_vector->rx.ring) {
2542 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2543 "%s-%s-%d", netdev->name, "TxRx", ri++);
2545 } else if (q_vector->rx.ring) {
2546 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2547 "%s-%s-%d", netdev->name, "rx", ri++);
2548 } else if (q_vector->tx.ring) {
2549 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2550 "%s-%s-%d", netdev->name, "tx", ti++);
2552 /* skip this unused q_vector */
2555 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2556 q_vector->name, q_vector);
2558 e_err(probe, "request_irq failed for MSIX interrupt "
2559 "Error: %d\n", err);
2560 goto free_queue_irqs;
2562 /* If Flow Director is enabled, set interrupt affinity */
2563 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2564 /* assign the mask for this irq */
2565 irq_set_affinity_hint(entry->vector,
2566 &q_vector->affinity_mask);
2570 err = request_irq(adapter->msix_entries[vector].vector,
2571 ixgbe_msix_other, 0, netdev->name, adapter);
2573 e_err(probe, "request_irq for msix_other failed: %d\n", err);
2574 goto free_queue_irqs;
2582 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2584 free_irq(adapter->msix_entries[vector].vector,
2585 adapter->q_vector[vector]);
2587 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2588 pci_disable_msix(adapter->pdev);
2589 kfree(adapter->msix_entries);
2590 adapter->msix_entries = NULL;
2595 * ixgbe_intr - legacy mode Interrupt Handler
2596 * @irq: interrupt number
2597 * @data: pointer to a network interface device structure
2599 static irqreturn_t ixgbe_intr(int irq, void *data)
2601 struct ixgbe_adapter *adapter = data;
2602 struct ixgbe_hw *hw = &adapter->hw;
2603 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
2607 * Workaround for silicon errata #26 on 82598. Mask the interrupt
2608 * before the read of EICR.
2610 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2612 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2613 * therefore no explicit interrupt disable is necessary */
2614 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
2617 * shared interrupt alert!
2618 * make sure interrupts are enabled because the read will
2619 * have disabled interrupts due to EIAM
2620 * finish the workaround of silicon errata on 82598. Unmask
2621 * the interrupt that we masked before the EICR read.
2623 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2624 ixgbe_irq_enable(adapter, true, true);
2625 return IRQ_NONE; /* Not our interrupt */
2628 if (eicr & IXGBE_EICR_LSC)
2629 ixgbe_check_lsc(adapter);
2631 switch (hw->mac.type) {
2632 case ixgbe_mac_82599EB:
2633 ixgbe_check_sfp_event(adapter, eicr);
2635 case ixgbe_mac_X540:
2636 if (eicr & IXGBE_EICR_ECC)
2637 e_info(link, "Received unrecoverable ECC err, please "
2639 ixgbe_check_overtemp_event(adapter, eicr);
2645 ixgbe_check_fan_failure(adapter, eicr);
2646 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2647 ixgbe_ptp_check_pps_event(adapter, eicr);
2649 /* would disable interrupts here but EIAM disabled it */
2650 napi_schedule(&q_vector->napi);
2653 * re-enable link(maybe) and non-queue interrupts, no flush.
2654 * ixgbe_poll will re-enable the queue interrupts
2656 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2657 ixgbe_irq_enable(adapter, false, false);
2663 * ixgbe_request_irq - initialize interrupts
2664 * @adapter: board private structure
2666 * Attempts to configure interrupts using the best available
2667 * capabilities of the hardware and kernel.
2669 static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
2671 struct net_device *netdev = adapter->netdev;
2674 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2675 err = ixgbe_request_msix_irqs(adapter);
2676 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
2677 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
2678 netdev->name, adapter);
2680 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
2681 netdev->name, adapter);
2684 e_err(probe, "request_irq failed, Error %d\n", err);
2689 static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2693 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2694 free_irq(adapter->pdev->irq, adapter);
2698 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2699 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2700 struct msix_entry *entry = &adapter->msix_entries[vector];
2702 /* free only the irqs that were actually requested */
2703 if (!q_vector->rx.ring && !q_vector->tx.ring)
2706 /* clear the affinity_mask in the IRQ descriptor */
2707 irq_set_affinity_hint(entry->vector, NULL);
2709 free_irq(entry->vector, q_vector);
2712 free_irq(adapter->msix_entries[vector++].vector, adapter);
2716 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2717 * @adapter: board private structure
2719 static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2721 switch (adapter->hw.mac.type) {
2722 case ixgbe_mac_82598EB:
2723 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
2725 case ixgbe_mac_82599EB:
2726 case ixgbe_mac_X540:
2727 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2728 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
2729 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
2734 IXGBE_WRITE_FLUSH(&adapter->hw);
2735 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2738 for (vector = 0; vector < adapter->num_q_vectors; vector++)
2739 synchronize_irq(adapter->msix_entries[vector].vector);
2741 synchronize_irq(adapter->msix_entries[vector++].vector);
2743 synchronize_irq(adapter->pdev->irq);
2748 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2751 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2753 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
2755 ixgbe_write_eitr(q_vector);
2757 ixgbe_set_ivar(adapter, 0, 0, 0);
2758 ixgbe_set_ivar(adapter, 1, 0, 0);
2760 e_info(hw, "Legacy interrupt IVAR setup done\n");
2764 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2765 * @adapter: board private structure
2766 * @ring: structure containing ring specific data
2768 * Configure the Tx descriptor ring after a reset.
2770 void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2771 struct ixgbe_ring *ring)
2773 struct ixgbe_hw *hw = &adapter->hw;
2774 u64 tdba = ring->dma;
2776 u32 txdctl = IXGBE_TXDCTL_ENABLE;
2777 u8 reg_idx = ring->reg_idx;
2779 /* disable queue to avoid issues while updating state */
2780 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
2781 IXGBE_WRITE_FLUSH(hw);
2783 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
2784 (tdba & DMA_BIT_MASK(32)));
2785 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2786 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2787 ring->count * sizeof(union ixgbe_adv_tx_desc));
2788 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2789 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
2790 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
2793 * set WTHRESH to encourage burst writeback, it should not be set
2794 * higher than 1 when ITR is 0 as it could cause false TX hangs
2796 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2797 * to or less than the number of on chip descriptors, which is
2800 if (!ring->q_vector || (ring->q_vector->itr < 8))
2801 txdctl |= (1 << 16); /* WTHRESH = 1 */
2803 txdctl |= (8 << 16); /* WTHRESH = 8 */
2806 * Setting PTHRESH to 32 both improves performance
2807 * and avoids a TX hang with DFP enabled
2809 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2810 32; /* PTHRESH = 32 */
2812 /* reinitialize flowdirector state */
2813 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2814 ring->atr_sample_rate = adapter->atr_sample_rate;
2815 ring->atr_count = 0;
2816 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2818 ring->atr_sample_rate = 0;
2821 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2824 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2826 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2827 if (hw->mac.type == ixgbe_mac_82598EB &&
2828 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2831 /* poll to verify queue is enabled */
2833 usleep_range(1000, 2000);
2834 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2835 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2837 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
2840 static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2842 struct ixgbe_hw *hw = &adapter->hw;
2844 u8 tcs = netdev_get_num_tc(adapter->netdev);
2846 if (hw->mac.type == ixgbe_mac_82598EB)
2849 /* disable the arbiter while setting MTQC */
2850 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2851 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2852 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2854 /* set transmit pool layout */
2855 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
2856 mtqc = IXGBE_MTQC_VT_ENA;
2858 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2860 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2861 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
2862 mtqc |= IXGBE_MTQC_32VF;
2864 mtqc |= IXGBE_MTQC_64VF;
2867 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2869 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2871 mtqc = IXGBE_MTQC_64Q_1PB;
2874 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
2876 /* Enable Security TX Buffer IFG for multiple pb */
2878 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2879 sectx |= IXGBE_SECTX_DCB;
2880 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
2883 /* re-enable the arbiter */
2884 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2885 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2889 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
2890 * @adapter: board private structure
2892 * Configure the Tx unit of the MAC after a reset.
2894 static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2896 struct ixgbe_hw *hw = &adapter->hw;
2900 ixgbe_setup_mtqc(adapter);
2902 if (hw->mac.type != ixgbe_mac_82598EB) {
2903 /* DMATXCTL.EN must be before Tx queues are enabled */
2904 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2905 dmatxctl |= IXGBE_DMATXCTL_TE;
2906 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2909 /* Setup the HW Tx Head and Tail descriptor pointers */
2910 for (i = 0; i < adapter->num_tx_queues; i++)
2911 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
2914 static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
2915 struct ixgbe_ring *ring)
2917 struct ixgbe_hw *hw = &adapter->hw;
2918 u8 reg_idx = ring->reg_idx;
2919 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2921 srrctl |= IXGBE_SRRCTL_DROP_EN;
2923 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2926 static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
2927 struct ixgbe_ring *ring)
2929 struct ixgbe_hw *hw = &adapter->hw;
2930 u8 reg_idx = ring->reg_idx;
2931 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2933 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
2935 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2938 #ifdef CONFIG_IXGBE_DCB
2939 void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2941 static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2945 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
2947 if (adapter->ixgbe_ieee_pfc)
2948 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
2951 * We should set the drop enable bit if:
2954 * Number of Rx queues > 1 and flow control is disabled
2956 * This allows us to avoid head of line blocking for security
2957 * and performance reasons.
2959 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
2960 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
2961 for (i = 0; i < adapter->num_rx_queues; i++)
2962 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
2964 for (i = 0; i < adapter->num_rx_queues; i++)
2965 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
2969 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
2971 static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
2972 struct ixgbe_ring *rx_ring)
2974 struct ixgbe_hw *hw = &adapter->hw;
2976 u8 reg_idx = rx_ring->reg_idx;
2978 if (hw->mac.type == ixgbe_mac_82598EB) {
2979 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
2982 * if VMDq is not active we must program one srrctl register
2983 * per RSS queue since we have enabled RDRXCTL.MVMEN
2988 /* configure header buffer length, needed for RSC */
2989 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
2991 /* configure the packet buffer length */
2992 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2994 /* configure descriptor type */
2995 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
2997 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3000 static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3002 struct ixgbe_hw *hw = &adapter->hw;
3003 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
3004 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
3005 0x6A3E67EA, 0x14364D17, 0x3BED200D};
3006 u32 mrqc = 0, reta = 0;
3009 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3012 * Program table for at least 2 queues w/ SR-IOV so that VFs can
3013 * make full use of any rings they may have. We will use the
3014 * PSRTYPE register to control how many rings we use within the PF.
3016 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
3019 /* Fill out hash function seeds */
3020 for (i = 0; i < 10; i++)
3021 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
3023 /* Fill out redirection table */
3024 for (i = 0, j = 0; i < 128; i++, j++) {
3027 /* reta = 4-byte sliding window of
3028 * 0x00..(indices-1)(indices-1)00..etc. */
3029 reta = (reta << 8) | (j * 0x11);
3031 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3034 /* Disable indicating checksum in descriptor, enables RSS hash */
3035 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3036 rxcsum |= IXGBE_RXCSUM_PCSD;
3037 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3039 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
3040 if (adapter->ring_feature[RING_F_RSS].mask)
3041 mrqc = IXGBE_MRQC_RSSEN;
3043 u8 tcs = netdev_get_num_tc(adapter->netdev);
3045 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3047 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3049 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3050 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3051 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3053 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3056 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3058 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3060 mrqc = IXGBE_MRQC_RSSEN;
3064 /* Perform hash on these packet types */
3065 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3066 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3067 IXGBE_MRQC_RSS_FIELD_IPV6 |
3068 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
3070 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
3071 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3072 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
3073 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3075 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3079 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3080 * @adapter: address of board private structure
3081 * @index: index of ring to set
3083 static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
3084 struct ixgbe_ring *ring)
3086 struct ixgbe_hw *hw = &adapter->hw;
3088 u8 reg_idx = ring->reg_idx;
3090 if (!ring_is_rsc_enabled(ring))
3093 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
3094 rscctrl |= IXGBE_RSCCTL_RSCEN;
3096 * we must limit the number of descriptors so that the
3097 * total size of max desc * buf_len is not greater
3100 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
3101 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
3104 #define IXGBE_MAX_RX_DESC_POLL 10
3105 static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3106 struct ixgbe_ring *ring)
3108 struct ixgbe_hw *hw = &adapter->hw;
3109 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3111 u8 reg_idx = ring->reg_idx;
3113 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3114 if (hw->mac.type == ixgbe_mac_82598EB &&
3115 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3119 usleep_range(1000, 2000);
3120 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3121 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3124 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3125 "the polling period\n", reg_idx);
3129 void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3130 struct ixgbe_ring *ring)
3132 struct ixgbe_hw *hw = &adapter->hw;
3133 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3135 u8 reg_idx = ring->reg_idx;
3137 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3138 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3140 /* write value back with RXDCTL.ENABLE bit cleared */
3141 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3143 if (hw->mac.type == ixgbe_mac_82598EB &&
3144 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3147 /* the hardware may take up to 100us to really disable the rx queue */
3150 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3151 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3154 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3155 "the polling period\n", reg_idx);
3159 void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3160 struct ixgbe_ring *ring)
3162 struct ixgbe_hw *hw = &adapter->hw;
3163 u64 rdba = ring->dma;
3165 u8 reg_idx = ring->reg_idx;
3167 /* disable queue to avoid issues while updating state */
3168 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3169 ixgbe_disable_rx_queue(adapter, ring);
3171 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3172 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3173 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3174 ring->count * sizeof(union ixgbe_adv_rx_desc));
3175 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3176 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
3177 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
3179 ixgbe_configure_srrctl(adapter, ring);
3180 ixgbe_configure_rscctl(adapter, ring);
3182 if (hw->mac.type == ixgbe_mac_82598EB) {
3184 * enable cache line friendly hardware writes:
3185 * PTHRESH=32 descriptors (half the internal cache),
3186 * this also removes ugly rx_no_buffer_count increment
3187 * HTHRESH=4 descriptors (to minimize latency on fetch)
3188 * WTHRESH=8 burst writeback up to two cache lines
3190 rxdctl &= ~0x3FFFFF;
3194 /* enable receive descriptor ring */
3195 rxdctl |= IXGBE_RXDCTL_ENABLE;
3196 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3198 ixgbe_rx_desc_queue_enable(adapter, ring);
3199 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
3202 static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3204 struct ixgbe_hw *hw = &adapter->hw;
3205 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
3208 /* PSRTYPE must be initialized in non 82598 adapters */
3209 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
3210 IXGBE_PSRTYPE_UDPHDR |
3211 IXGBE_PSRTYPE_IPV4HDR |
3212 IXGBE_PSRTYPE_L2HDR |
3213 IXGBE_PSRTYPE_IPV6HDR;
3215 if (hw->mac.type == ixgbe_mac_82598EB)
3223 for (p = 0; p < adapter->num_rx_pools; p++)
3224 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(p)),
3228 static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3230 struct ixgbe_hw *hw = &adapter->hw;
3231 u32 reg_offset, vf_shift;
3232 u32 gcr_ext, vmdctl;
3235 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3238 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3239 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3240 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
3241 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
3242 vmdctl |= IXGBE_VT_CTL_REPLEN;
3243 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
3245 vf_shift = VMDQ_P(0) % 32;
3246 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
3248 /* Enable only the PF's pool for Tx/Rx */
3249 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3250 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3251 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3252 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
3253 if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
3254 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3256 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3257 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
3260 * Set up VF register offsets for selected VT Mode,
3261 * i.e. 32 or 64 VFs for SR-IOV
3263 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3264 case IXGBE_82599_VMDQ_8Q_MASK:
3265 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3267 case IXGBE_82599_VMDQ_4Q_MASK:
3268 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3271 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3275 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3278 /* Enable MAC Anti-Spoofing */
3279 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
3281 /* For VFs that have spoof checking turned off */
3282 for (i = 0; i < adapter->num_vfs; i++) {
3283 if (!adapter->vfinfo[i].spoofchk_enabled)
3284 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3288 static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
3290 struct ixgbe_hw *hw = &adapter->hw;
3291 struct net_device *netdev = adapter->netdev;
3292 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3293 struct ixgbe_ring *rx_ring;
3298 /* adjust max frame to be able to do baby jumbo for FCoE */
3299 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3300 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3301 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3303 #endif /* IXGBE_FCOE */
3305 /* adjust max frame to be at least the size of a standard frame */
3306 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3307 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3309 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3310 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3311 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3312 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3314 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
3317 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
3318 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3319 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
3320 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3323 * Setup the HW Rx Head and Tail Descriptor Pointers and
3324 * the Base and Length of the Rx Descriptor Ring
3326 for (i = 0; i < adapter->num_rx_queues; i++) {
3327 rx_ring = adapter->rx_ring[i];
3328 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3329 set_ring_rsc_enabled(rx_ring);
3331 clear_ring_rsc_enabled(rx_ring);
3335 static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3337 struct ixgbe_hw *hw = &adapter->hw;
3338 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3340 switch (hw->mac.type) {
3341 case ixgbe_mac_82598EB:
3343 * For VMDq support of different descriptor types or
3344 * buffer sizes through the use of multiple SRRCTL
3345 * registers, RDRXCTL.MVMEN must be set to 1
3347 * also, the manual doesn't mention it clearly but DCA hints
3348 * will only use queue 0's tags unless this bit is set. Side
3349 * effects of setting this bit are only that SRRCTL must be
3350 * fully programmed [0..15]
3352 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3354 case ixgbe_mac_82599EB:
3355 case ixgbe_mac_X540:
3356 /* Disable RSC for ACK packets */
3357 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3358 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3359 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3360 /* hardware requires some bits to be set by default */
3361 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3362 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3365 /* We should do nothing since we don't know this hardware */
3369 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3373 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3374 * @adapter: board private structure
3376 * Configure the Rx unit of the MAC after a reset.
3378 static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3380 struct ixgbe_hw *hw = &adapter->hw;
3384 /* disable receives while setting up the descriptors */
3385 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3386 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3388 ixgbe_setup_psrtype(adapter);
3389 ixgbe_setup_rdrxctl(adapter);
3391 /* Program registers for the distribution of queues */
3392 ixgbe_setup_mrqc(adapter);
3394 /* set_rx_buffer_len must be called before ring initialization */
3395 ixgbe_set_rx_buffer_len(adapter);
3398 * Setup the HW Rx Head and Tail Descriptor Pointers and
3399 * the Base and Length of the Rx Descriptor Ring
3401 for (i = 0; i < adapter->num_rx_queues; i++)
3402 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
3404 /* disable drop enable for 82598 parts */
3405 if (hw->mac.type == ixgbe_mac_82598EB)
3406 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3408 /* enable all receives */
3409 rxctrl |= IXGBE_RXCTRL_RXEN;
3410 hw->mac.ops.enable_rx_dma(hw, rxctrl);
3413 static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3415 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3416 struct ixgbe_hw *hw = &adapter->hw;
3418 /* add VID to filter table */
3419 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
3420 set_bit(vid, adapter->active_vlans);
3425 static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3427 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3428 struct ixgbe_hw *hw = &adapter->hw;
3430 /* remove VID from filter table */
3431 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
3432 clear_bit(vid, adapter->active_vlans);
3438 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3439 * @adapter: driver data
3441 static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3443 struct ixgbe_hw *hw = &adapter->hw;
3446 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3447 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3448 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3452 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3453 * @adapter: driver data
3455 static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3457 struct ixgbe_hw *hw = &adapter->hw;
3460 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3461 vlnctrl |= IXGBE_VLNCTRL_VFE;
3462 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3463 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3467 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3468 * @adapter: driver data
3470 static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3472 struct ixgbe_hw *hw = &adapter->hw;
3476 switch (hw->mac.type) {
3477 case ixgbe_mac_82598EB:
3478 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3479 vlnctrl &= ~IXGBE_VLNCTRL_VME;
3480 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3482 case ixgbe_mac_82599EB:
3483 case ixgbe_mac_X540:
3484 for (i = 0; i < adapter->num_rx_queues; i++) {
3485 j = adapter->rx_ring[i]->reg_idx;
3486 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3487 vlnctrl &= ~IXGBE_RXDCTL_VME;
3488 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3497 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
3498 * @adapter: driver data
3500 static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
3502 struct ixgbe_hw *hw = &adapter->hw;
3506 switch (hw->mac.type) {
3507 case ixgbe_mac_82598EB:
3508 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3509 vlnctrl |= IXGBE_VLNCTRL_VME;
3510 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3512 case ixgbe_mac_82599EB:
3513 case ixgbe_mac_X540:
3514 for (i = 0; i < adapter->num_rx_queues; i++) {
3515 j = adapter->rx_ring[i]->reg_idx;
3516 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3517 vlnctrl |= IXGBE_RXDCTL_VME;
3518 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3526 static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3530 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3532 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3533 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
3537 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3538 * @netdev: network interface device structure
3540 * Writes unicast address list to the RAR table.
3541 * Returns: -ENOMEM on failure/insufficient address space
3542 * 0 on no addresses written
3543 * X on writing X addresses to the RAR table
3545 static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3547 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3548 struct ixgbe_hw *hw = &adapter->hw;
3549 unsigned int rar_entries = hw->mac.num_rar_entries - 1;
3552 /* In SR-IOV mode significantly less RAR entries are available */
3553 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3554 rar_entries = IXGBE_MAX_PF_MACVLANS - 1;
3556 /* return ENOMEM indicating insufficient memory for addresses */
3557 if (netdev_uc_count(netdev) > rar_entries)
3560 if (!netdev_uc_empty(netdev)) {
3561 struct netdev_hw_addr *ha;
3562 /* return error if we do not support writing to RAR table */
3563 if (!hw->mac.ops.set_rar)
3566 netdev_for_each_uc_addr(ha, netdev) {
3569 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3570 VMDQ_P(0), IXGBE_RAH_AV);
3574 /* write the addresses in reverse order to avoid write combining */
3575 for (; rar_entries > 0 ; rar_entries--)
3576 hw->mac.ops.clear_rar(hw, rar_entries);
3582 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
3583 * @netdev: network interface device structure
3585 * The set_rx_method entry point is called whenever the unicast/multicast
3586 * address list or the network interface flags are updated. This routine is
3587 * responsible for configuring the hardware for proper unicast, multicast and
3590 void ixgbe_set_rx_mode(struct net_device *netdev)
3592 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3593 struct ixgbe_hw *hw = &adapter->hw;
3594 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3597 /* Check for Promiscuous and All Multicast modes */
3599 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3601 /* set all bits that we expect to always be set */
3602 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
3603 fctrl |= IXGBE_FCTRL_BAM;
3604 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3605 fctrl |= IXGBE_FCTRL_PMCF;
3607 /* clear the bits we are changing the status of */
3608 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3610 if (netdev->flags & IFF_PROMISC) {
3611 hw->addr_ctrl.user_set_promisc = true;
3612 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3613 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
3614 /* don't hardware filter vlans in promisc mode */
3615 ixgbe_vlan_filter_disable(adapter);
3617 if (netdev->flags & IFF_ALLMULTI) {
3618 fctrl |= IXGBE_FCTRL_MPE;
3619 vmolr |= IXGBE_VMOLR_MPE;
3622 * Write addresses to the MTA, if the attempt fails
3623 * then we should just turn on promiscuous mode so
3624 * that we can at least receive multicast traffic
3626 hw->mac.ops.update_mc_addr_list(hw, netdev);
3627 vmolr |= IXGBE_VMOLR_ROMPE;
3629 ixgbe_vlan_filter_enable(adapter);
3630 hw->addr_ctrl.user_set_promisc = false;
3634 * Write addresses to available RAR registers, if there is not
3635 * sufficient space to store all the addresses then enable
3636 * unicast promiscuous mode
3638 count = ixgbe_write_uc_addr_list(netdev);
3640 fctrl |= IXGBE_FCTRL_UPE;
3641 vmolr |= IXGBE_VMOLR_ROPE;
3644 if (adapter->num_vfs)
3645 ixgbe_restore_vf_multicasts(adapter);
3647 if (hw->mac.type != ixgbe_mac_82598EB) {
3648 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
3649 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3651 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
3654 /* This is useful for sniffing bad packets. */
3655 if (adapter->netdev->features & NETIF_F_RXALL) {
3656 /* UPE and MPE will be handled by normal PROMISC logic
3657 * in e1000e_set_rx_mode */
3658 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3659 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3660 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3662 fctrl &= ~(IXGBE_FCTRL_DPF);
3663 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3666 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3668 if (netdev->features & NETIF_F_HW_VLAN_RX)
3669 ixgbe_vlan_strip_enable(adapter);
3671 ixgbe_vlan_strip_disable(adapter);
3674 static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3678 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
3679 napi_enable(&adapter->q_vector[q_idx]->napi);
3682 static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3686 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
3687 napi_disable(&adapter->q_vector[q_idx]->napi);
3690 #ifdef CONFIG_IXGBE_DCB
3692 * ixgbe_configure_dcb - Configure DCB hardware
3693 * @adapter: ixgbe adapter struct
3695 * This is called by the driver on open to configure the DCB hardware.
3696 * This is also called by the gennetlink interface when reconfiguring
3699 static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3701 struct ixgbe_hw *hw = &adapter->hw;
3702 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3704 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3705 if (hw->mac.type == ixgbe_mac_82598EB)
3706 netif_set_gso_max_size(adapter->netdev, 65536);
3710 if (hw->mac.type == ixgbe_mac_82598EB)
3711 netif_set_gso_max_size(adapter->netdev, 32768);
3714 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3715 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3718 /* reconfigure the hardware */
3719 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
3720 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3722 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3724 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3725 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3726 ixgbe_dcb_hw_ets(&adapter->hw,
3727 adapter->ixgbe_ieee_ets,
3729 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3730 adapter->ixgbe_ieee_pfc->pfc_en,
3731 adapter->ixgbe_ieee_ets->prio_tc);
3734 /* Enable RSS Hash per TC */
3735 if (hw->mac.type != ixgbe_mac_82598EB) {
3737 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
3744 /* write msb to all 8 TCs in one write */
3745 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
3750 /* Additional bittime to account for IXGBE framing */
3751 #define IXGBE_ETH_FRAMING 20
3754 * ixgbe_hpbthresh - calculate high water mark for flow control
3756 * @adapter: board private structure to calculate for
3757 * @pb: packet buffer to calculate
3759 static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3761 struct ixgbe_hw *hw = &adapter->hw;
3762 struct net_device *dev = adapter->netdev;
3763 int link, tc, kb, marker;
3766 /* Calculate max LAN frame size */
3767 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3770 /* FCoE traffic class uses FCOE jumbo frames */
3771 if ((dev->features & NETIF_F_FCOE_MTU) &&
3772 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
3773 (pb == ixgbe_fcoe_get_tc(adapter)))
3774 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3777 /* Calculate delay value for device */
3778 switch (hw->mac.type) {
3779 case ixgbe_mac_X540:
3780 dv_id = IXGBE_DV_X540(link, tc);
3783 dv_id = IXGBE_DV(link, tc);
3787 /* Loopback switch introduces additional latency */
3788 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3789 dv_id += IXGBE_B2BT(tc);
3791 /* Delay value is calculated in bit times convert to KB */
3792 kb = IXGBE_BT2KB(dv_id);
3793 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3795 marker = rx_pba - kb;
3797 /* It is possible that the packet buffer is not large enough
3798 * to provide required headroom. In this case throw an error
3799 * to user and a do the best we can.
3802 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3803 "headroom to support flow control."
3804 "Decrease MTU or number of traffic classes\n", pb);
3812 * ixgbe_lpbthresh - calculate low water mark for for flow control
3814 * @adapter: board private structure to calculate for
3815 * @pb: packet buffer to calculate
3817 static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3819 struct ixgbe_hw *hw = &adapter->hw;
3820 struct net_device *dev = adapter->netdev;
3824 /* Calculate max LAN frame size */
3825 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3827 /* Calculate delay value for device */
3828 switch (hw->mac.type) {
3829 case ixgbe_mac_X540:
3830 dv_id = IXGBE_LOW_DV_X540(tc);
3833 dv_id = IXGBE_LOW_DV(tc);
3837 /* Delay value is calculated in bit times convert to KB */
3838 return IXGBE_BT2KB(dv_id);
3842 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3844 static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3846 struct ixgbe_hw *hw = &adapter->hw;
3847 int num_tc = netdev_get_num_tc(adapter->netdev);
3853 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3855 for (i = 0; i < num_tc; i++) {
3856 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3858 /* Low water marks must not be larger than high water marks */
3859 if (hw->fc.low_water > hw->fc.high_water[i])
3860 hw->fc.low_water = 0;
3864 static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3866 struct ixgbe_hw *hw = &adapter->hw;
3868 u8 tc = netdev_get_num_tc(adapter->netdev);
3870 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3871 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3872 hdrm = 32 << adapter->fdir_pballoc;
3876 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
3877 ixgbe_pbthresh_setup(adapter);
3880 static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3882 struct ixgbe_hw *hw = &adapter->hw;
3883 struct hlist_node *node, *node2;
3884 struct ixgbe_fdir_filter *filter;
3886 spin_lock(&adapter->fdir_perfect_lock);
3888 if (!hlist_empty(&adapter->fdir_filter_list))
3889 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3891 hlist_for_each_entry_safe(filter, node, node2,
3892 &adapter->fdir_filter_list, fdir_node) {
3893 ixgbe_fdir_write_perfect_filter_82599(hw,
3896 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3897 IXGBE_FDIR_DROP_QUEUE :
3898 adapter->rx_ring[filter->action]->reg_idx);
3901 spin_unlock(&adapter->fdir_perfect_lock);
3904 static void ixgbe_configure(struct ixgbe_adapter *adapter)
3906 struct ixgbe_hw *hw = &adapter->hw;
3908 ixgbe_configure_pb(adapter);
3909 #ifdef CONFIG_IXGBE_DCB
3910 ixgbe_configure_dcb(adapter);
3913 * We must restore virtualization before VLANs or else
3914 * the VLVF registers will not be populated
3916 ixgbe_configure_virtualization(adapter);
3918 ixgbe_set_rx_mode(adapter->netdev);
3919 ixgbe_restore_vlan(adapter);
3921 switch (hw->mac.type) {
3922 case ixgbe_mac_82599EB:
3923 case ixgbe_mac_X540:
3924 hw->mac.ops.disable_rx_buff(hw);
3930 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3931 ixgbe_init_fdir_signature_82599(&adapter->hw,
3932 adapter->fdir_pballoc);
3933 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3934 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3935 adapter->fdir_pballoc);
3936 ixgbe_fdir_filter_restore(adapter);
3939 switch (hw->mac.type) {
3940 case ixgbe_mac_82599EB:
3941 case ixgbe_mac_X540:
3942 hw->mac.ops.enable_rx_buff(hw);
3949 /* configure FCoE L2 filters, redirection table, and Rx control */
3950 ixgbe_configure_fcoe(adapter);
3952 #endif /* IXGBE_FCOE */
3953 ixgbe_configure_tx(adapter);
3954 ixgbe_configure_rx(adapter);
3957 static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3959 switch (hw->phy.type) {
3960 case ixgbe_phy_sfp_avago:
3961 case ixgbe_phy_sfp_ftl:
3962 case ixgbe_phy_sfp_intel:
3963 case ixgbe_phy_sfp_unknown:
3964 case ixgbe_phy_sfp_passive_tyco:
3965 case ixgbe_phy_sfp_passive_unknown:
3966 case ixgbe_phy_sfp_active_unknown:
3967 case ixgbe_phy_sfp_ftl_active:
3970 if (hw->mac.type == ixgbe_mac_82598EB)
3978 * ixgbe_sfp_link_config - set up SFP+ link
3979 * @adapter: pointer to private adapter struct
3981 static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3984 * We are assuming the worst case scenario here, and that
3985 * is that an SFP was inserted/removed after the reset
3986 * but before SFP detection was enabled. As such the best
3987 * solution is to just start searching as soon as we start
3989 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3990 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
3992 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
3996 * ixgbe_non_sfp_link_config - set up non-SFP+ link
3997 * @hw: pointer to private hardware struct
3999 * Returns 0 on success, negative on failure
4001 static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
4004 bool negotiation, link_up = false;
4005 u32 ret = IXGBE_ERR_LINK_SETUP;
4007 if (hw->mac.ops.check_link)
4008 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
4013 autoneg = hw->phy.autoneg_advertised;
4014 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
4015 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
4020 if (hw->mac.ops.setup_link)
4021 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
4026 static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
4028 struct ixgbe_hw *hw = &adapter->hw;
4031 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4032 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
4034 gpie |= IXGBE_GPIE_EIAME;
4036 * use EIAM to auto-mask when MSI-X interrupt is asserted
4037 * this saves a register write for every interrupt
4039 switch (hw->mac.type) {
4040 case ixgbe_mac_82598EB:
4041 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4043 case ixgbe_mac_82599EB:
4044 case ixgbe_mac_X540:
4046 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4047 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4051 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
4052 * specifically only auto mask tx and rx interrupts */
4053 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4056 /* XXX: to interrupt immediately for EICS writes, enable this */
4057 /* gpie |= IXGBE_GPIE_EIMEN; */
4059 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
4060 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
4062 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4063 case IXGBE_82599_VMDQ_8Q_MASK:
4064 gpie |= IXGBE_GPIE_VTMODE_16;
4066 case IXGBE_82599_VMDQ_4Q_MASK:
4067 gpie |= IXGBE_GPIE_VTMODE_32;
4070 gpie |= IXGBE_GPIE_VTMODE_64;
4075 /* Enable Thermal over heat sensor interrupt */
4076 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
4077 switch (adapter->hw.mac.type) {
4078 case ixgbe_mac_82599EB:
4079 gpie |= IXGBE_SDP0_GPIEN;
4081 case ixgbe_mac_X540:
4082 gpie |= IXGBE_EIMS_TS;
4089 /* Enable fan failure interrupt */
4090 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
4091 gpie |= IXGBE_SDP1_GPIEN;
4093 if (hw->mac.type == ixgbe_mac_82599EB) {
4094 gpie |= IXGBE_SDP1_GPIEN;
4095 gpie |= IXGBE_SDP2_GPIEN;
4098 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4101 static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
4103 struct ixgbe_hw *hw = &adapter->hw;
4107 ixgbe_get_hw_control(adapter);
4108 ixgbe_setup_gpie(adapter);
4110 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4111 ixgbe_configure_msix(adapter);
4113 ixgbe_configure_msi_and_legacy(adapter);
4115 /* enable the optics for 82599 SFP+ fiber */
4116 if (hw->mac.ops.enable_tx_laser)
4117 hw->mac.ops.enable_tx_laser(hw);
4119 clear_bit(__IXGBE_DOWN, &adapter->state);
4120 ixgbe_napi_enable_all(adapter);
4122 if (ixgbe_is_sfp(hw)) {
4123 ixgbe_sfp_link_config(adapter);
4125 err = ixgbe_non_sfp_link_config(hw);
4127 e_err(probe, "link_config FAILED %d\n", err);
4130 /* clear any pending interrupts, may auto mask */
4131 IXGBE_READ_REG(hw, IXGBE_EICR);
4132 ixgbe_irq_enable(adapter, true, true);
4135 * If this adapter has a fan, check to see if we had a failure
4136 * before we enabled the interrupt.
4138 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
4139 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
4140 if (esdp & IXGBE_ESDP_SDP1)
4141 e_crit(drv, "Fan has stopped, replace the adapter\n");
4144 /* enable transmits */
4145 netif_tx_start_all_queues(adapter->netdev);
4147 /* bring the link up in the watchdog, this could race with our first
4148 * link up interrupt but shouldn't be a problem */
4149 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4150 adapter->link_check_timeout = jiffies;
4151 mod_timer(&adapter->service_timer, jiffies);
4153 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4154 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4155 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4156 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
4159 void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4161 WARN_ON(in_interrupt());
4162 /* put off any impending NetWatchDogTimeout */
4163 adapter->netdev->trans_start = jiffies;
4165 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
4166 usleep_range(1000, 2000);
4167 ixgbe_down(adapter);
4169 * If SR-IOV enabled then wait a bit before bringing the adapter
4170 * back up to give the VFs time to respond to the reset. The
4171 * two second wait is based upon the watchdog timer cycle in
4174 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4177 clear_bit(__IXGBE_RESETTING, &adapter->state);
4180 void ixgbe_up(struct ixgbe_adapter *adapter)
4182 /* hardware has been reset, we need to reload some things */
4183 ixgbe_configure(adapter);
4185 ixgbe_up_complete(adapter);
4188 void ixgbe_reset(struct ixgbe_adapter *adapter)
4190 struct ixgbe_hw *hw = &adapter->hw;
4193 /* lock SFP init bit to prevent race conditions with the watchdog */
4194 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4195 usleep_range(1000, 2000);
4197 /* clear all SFP and link config related flags while holding SFP_INIT */
4198 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4199 IXGBE_FLAG2_SFP_NEEDS_RESET);
4200 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4202 err = hw->mac.ops.init_hw(hw);
4205 case IXGBE_ERR_SFP_NOT_PRESENT:
4206 case IXGBE_ERR_SFP_NOT_SUPPORTED:
4208 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
4209 e_dev_err("master disable timed out\n");
4211 case IXGBE_ERR_EEPROM_VERSION:
4212 /* We are running on a pre-production device, log a warning */
4213 e_dev_warn("This device is a pre-production adapter/LOM. "
4214 "Please be aware there may be issues associated with "
4215 "your hardware. If you are experiencing problems "
4216 "please contact your Intel or hardware "
4217 "representative who provided you with this "
4221 e_dev_err("Hardware Error: %d\n", err);
4224 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4226 /* reprogram the RAR[0] in case user changed it. */
4227 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
4229 /* update SAN MAC vmdq pool selection */
4230 if (hw->mac.san_mac_rar_index)
4231 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
4233 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
4234 ixgbe_ptp_reset(adapter);
4238 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
4239 * @rx_ring: ring to free buffers from
4241 static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
4243 struct device *dev = rx_ring->dev;
4247 /* ring already cleared, nothing to do */
4248 if (!rx_ring->rx_buffer_info)
4251 /* Free all the Rx ring sk_buffs */
4252 for (i = 0; i < rx_ring->count; i++) {
4253 struct ixgbe_rx_buffer *rx_buffer;
4255 rx_buffer = &rx_ring->rx_buffer_info[i];
4256 if (rx_buffer->skb) {
4257 struct sk_buff *skb = rx_buffer->skb;
4258 if (IXGBE_CB(skb)->page_released) {
4261 ixgbe_rx_bufsz(rx_ring),
4263 IXGBE_CB(skb)->page_released = false;
4267 rx_buffer->skb = NULL;
4269 dma_unmap_page(dev, rx_buffer->dma,
4270 ixgbe_rx_pg_size(rx_ring),
4273 if (rx_buffer->page)
4274 __free_pages(rx_buffer->page,
4275 ixgbe_rx_pg_order(rx_ring));
4276 rx_buffer->page = NULL;
4279 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4280 memset(rx_ring->rx_buffer_info, 0, size);
4282 /* Zero out the descriptor ring */
4283 memset(rx_ring->desc, 0, rx_ring->size);
4285 rx_ring->next_to_alloc = 0;
4286 rx_ring->next_to_clean = 0;
4287 rx_ring->next_to_use = 0;
4291 * ixgbe_clean_tx_ring - Free Tx Buffers
4292 * @tx_ring: ring to be cleaned
4294 static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
4296 struct ixgbe_tx_buffer *tx_buffer_info;
4300 /* ring already cleared, nothing to do */
4301 if (!tx_ring->tx_buffer_info)
4304 /* Free all the Tx ring sk_buffs */
4305 for (i = 0; i < tx_ring->count; i++) {
4306 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4307 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
4310 netdev_tx_reset_queue(txring_txq(tx_ring));
4312 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4313 memset(tx_ring->tx_buffer_info, 0, size);
4315 /* Zero out the descriptor ring */
4316 memset(tx_ring->desc, 0, tx_ring->size);
4318 tx_ring->next_to_use = 0;
4319 tx_ring->next_to_clean = 0;
4323 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4324 * @adapter: board private structure
4326 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4330 for (i = 0; i < adapter->num_rx_queues; i++)
4331 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
4335 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4336 * @adapter: board private structure
4338 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4342 for (i = 0; i < adapter->num_tx_queues; i++)
4343 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
4346 static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4348 struct hlist_node *node, *node2;
4349 struct ixgbe_fdir_filter *filter;
4351 spin_lock(&adapter->fdir_perfect_lock);
4353 hlist_for_each_entry_safe(filter, node, node2,
4354 &adapter->fdir_filter_list, fdir_node) {
4355 hlist_del(&filter->fdir_node);
4358 adapter->fdir_filter_count = 0;
4360 spin_unlock(&adapter->fdir_perfect_lock);
4363 void ixgbe_down(struct ixgbe_adapter *adapter)
4365 struct net_device *netdev = adapter->netdev;
4366 struct ixgbe_hw *hw = &adapter->hw;
4370 /* signal that we are down to the interrupt handler */
4371 set_bit(__IXGBE_DOWN, &adapter->state);
4373 /* disable receives */
4374 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4375 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
4377 /* disable all enabled rx queues */
4378 for (i = 0; i < adapter->num_rx_queues; i++)
4379 /* this call also flushes the previous write */
4380 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4382 usleep_range(10000, 20000);
4384 netif_tx_stop_all_queues(netdev);
4386 /* call carrier off first to avoid false dev_watchdog timeouts */
4387 netif_carrier_off(netdev);
4388 netif_tx_disable(netdev);
4390 ixgbe_irq_disable(adapter);
4392 ixgbe_napi_disable_all(adapter);
4394 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4395 IXGBE_FLAG2_RESET_REQUESTED);
4396 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4398 del_timer_sync(&adapter->service_timer);
4400 if (adapter->num_vfs) {
4401 /* Clear EITR Select mapping */
4402 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4404 /* Mark all the VFs as inactive */
4405 for (i = 0 ; i < adapter->num_vfs; i++)
4406 adapter->vfinfo[i].clear_to_send = false;
4408 /* ping all the active vfs to let them know we are going down */
4409 ixgbe_ping_all_vfs(adapter);
4411 /* Disable all VFTE/VFRE TX/RX */
4412 ixgbe_disable_tx_rx(adapter);
4415 /* disable transmits in the hardware now that interrupts are off */
4416 for (i = 0; i < adapter->num_tx_queues; i++) {
4417 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
4418 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
4421 /* Disable the Tx DMA engine on 82599 and X540 */
4422 switch (hw->mac.type) {
4423 case ixgbe_mac_82599EB:
4424 case ixgbe_mac_X540:
4425 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
4426 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4427 ~IXGBE_DMATXCTL_TE));
4433 if (!pci_channel_offline(adapter->pdev))
4434 ixgbe_reset(adapter);
4436 /* power down the optics for 82599 SFP+ fiber */
4437 if (hw->mac.ops.disable_tx_laser)
4438 hw->mac.ops.disable_tx_laser(hw);
4440 ixgbe_clean_all_tx_rings(adapter);
4441 ixgbe_clean_all_rx_rings(adapter);
4443 #ifdef CONFIG_IXGBE_DCA
4444 /* since we reset the hardware DCA settings were cleared */
4445 ixgbe_setup_dca(adapter);
4450 * ixgbe_tx_timeout - Respond to a Tx Hang
4451 * @netdev: network interface device structure
4453 static void ixgbe_tx_timeout(struct net_device *netdev)
4455 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4457 /* Do the reset outside of interrupt context */
4458 ixgbe_tx_timeout_reset(adapter);
4462 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4463 * @adapter: board private structure to initialize
4465 * ixgbe_sw_init initializes the Adapter private data structure.
4466 * Fields are initialized based on PCI device information and
4467 * OS network device settings (MTU size).
4469 static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
4471 struct ixgbe_hw *hw = &adapter->hw;
4472 struct pci_dev *pdev = adapter->pdev;
4475 #ifdef CONFIG_IXGBE_DCB
4477 struct tc_configuration *tc;
4480 /* PCI config space info */
4482 hw->vendor_id = pdev->vendor;
4483 hw->device_id = pdev->device;
4484 hw->revision_id = pdev->revision;
4485 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4486 hw->subsystem_device_id = pdev->subsystem_device;
4488 /* Set capability flags */
4489 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
4490 adapter->ring_feature[RING_F_RSS].limit = rss;
4491 switch (hw->mac.type) {
4492 case ixgbe_mac_82598EB:
4493 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4494 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
4495 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
4497 case ixgbe_mac_X540:
4498 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM);
4499 if (fwsm & IXGBE_FWSM_TS_ENABLED)
4500 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
4501 case ixgbe_mac_82599EB:
4502 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
4503 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4504 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
4505 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4506 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
4507 /* Flow Director hash filters enabled */
4508 adapter->atr_sample_rate = 20;
4509 adapter->ring_feature[RING_F_FDIR].limit =
4510 IXGBE_MAX_FDIR_INDICES;
4511 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
4513 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4514 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
4515 #ifdef CONFIG_IXGBE_DCB
4516 /* Default traffic class to use for FCoE */
4517 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
4519 #endif /* IXGBE_FCOE */
4526 /* FCoE support exists, always init the FCoE lock */
4527 spin_lock_init(&adapter->fcoe.lock);
4530 /* n-tuple support exists, always init our spinlock */
4531 spin_lock_init(&adapter->fdir_perfect_lock);
4533 #ifdef CONFIG_IXGBE_DCB
4534 switch (hw->mac.type) {
4535 case ixgbe_mac_X540:
4536 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
4537 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
4540 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
4541 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
4545 /* Configure DCB traffic classes */
4546 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
4547 tc = &adapter->dcb_cfg.tc_config[j];
4548 tc->path[DCB_TX_CONFIG].bwg_id = 0;
4549 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
4550 tc->path[DCB_RX_CONFIG].bwg_id = 0;
4551 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
4552 tc->dcb_pfc = pfc_disabled;
4555 /* Initialize default user to priority mapping, UPx->TC0 */
4556 tc = &adapter->dcb_cfg.tc_config[0];
4557 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
4558 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
4560 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
4561 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
4562 adapter->dcb_cfg.pfc_mode_enable = false;
4563 adapter->dcb_set_bitmap = 0x00;
4564 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
4565 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
4566 sizeof(adapter->temp_dcb_cfg));
4570 /* default flow control settings */
4571 hw->fc.requested_mode = ixgbe_fc_full;
4572 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
4573 ixgbe_pbthresh_setup(adapter);
4574 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
4575 hw->fc.send_xon = true;
4576 hw->fc.disable_fc_autoneg =
4577 (ixgbe_device_supports_autoneg_fc(hw) == 0) ? false : true;
4579 #ifdef CONFIG_PCI_IOV
4580 /* assign number of SR-IOV VFs */
4581 if (hw->mac.type != ixgbe_mac_82598EB)
4582 adapter->num_vfs = (max_vfs > 63) ? 0 : max_vfs;
4585 /* enable itr by default in dynamic mode */
4586 adapter->rx_itr_setting = 1;
4587 adapter->tx_itr_setting = 1;
4589 /* set default ring sizes */
4590 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4591 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4593 /* set default work limits */
4594 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
4596 /* initialize eeprom parameters */
4597 if (ixgbe_init_eeprom_params_generic(hw)) {
4598 e_dev_err("EEPROM initialization failed\n");
4602 set_bit(__IXGBE_DOWN, &adapter->state);
4608 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
4609 * @tx_ring: tx descriptor ring (for a specific queue) to setup
4611 * Return 0 on success, negative on failure
4613 int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
4615 struct device *dev = tx_ring->dev;
4616 int orig_node = dev_to_node(dev);
4620 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4622 if (tx_ring->q_vector)
4623 numa_node = tx_ring->q_vector->numa_node;
4625 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
4626 if (!tx_ring->tx_buffer_info)
4627 tx_ring->tx_buffer_info = vzalloc(size);
4628 if (!tx_ring->tx_buffer_info)
4631 /* round up to nearest 4K */
4632 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
4633 tx_ring->size = ALIGN(tx_ring->size, 4096);
4635 set_dev_node(dev, numa_node);
4636 tx_ring->desc = dma_alloc_coherent(dev,
4640 set_dev_node(dev, orig_node);
4642 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
4643 &tx_ring->dma, GFP_KERNEL);
4647 tx_ring->next_to_use = 0;
4648 tx_ring->next_to_clean = 0;
4652 vfree(tx_ring->tx_buffer_info);
4653 tx_ring->tx_buffer_info = NULL;
4654 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
4659 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4660 * @adapter: board private structure
4662 * If this function returns with an error, then it's possible one or
4663 * more of the rings is populated (while the rest are not). It is the
4664 * callers duty to clean those orphaned rings.
4666 * Return 0 on success, negative on failure
4668 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4672 for (i = 0; i < adapter->num_tx_queues; i++) {
4673 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
4677 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
4683 /* rewind the index freeing the rings as we go */
4685 ixgbe_free_tx_resources(adapter->tx_ring[i]);
4690 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
4691 * @rx_ring: rx descriptor ring (for a specific queue) to setup
4693 * Returns 0 on success, negative on failure
4695 int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
4697 struct device *dev = rx_ring->dev;
4698 int orig_node = dev_to_node(dev);
4702 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4704 if (rx_ring->q_vector)
4705 numa_node = rx_ring->q_vector->numa_node;
4707 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
4708 if (!rx_ring->rx_buffer_info)
4709 rx_ring->rx_buffer_info = vzalloc(size);
4710 if (!rx_ring->rx_buffer_info)
4713 /* Round up to nearest 4K */
4714 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4715 rx_ring->size = ALIGN(rx_ring->size, 4096);
4717 set_dev_node(dev, numa_node);
4718 rx_ring->desc = dma_alloc_coherent(dev,
4722 set_dev_node(dev, orig_node);
4724 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
4725 &rx_ring->dma, GFP_KERNEL);
4729 rx_ring->next_to_clean = 0;
4730 rx_ring->next_to_use = 0;
4734 vfree(rx_ring->rx_buffer_info);
4735 rx_ring->rx_buffer_info = NULL;
4736 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
4741 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4742 * @adapter: board private structure
4744 * If this function returns with an error, then it's possible one or
4745 * more of the rings is populated (while the rest are not). It is the
4746 * callers duty to clean those orphaned rings.
4748 * Return 0 on success, negative on failure
4750 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4754 for (i = 0; i < adapter->num_rx_queues; i++) {
4755 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
4759 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
4764 err = ixgbe_setup_fcoe_ddp_resources(adapter);
4769 /* rewind the index freeing the rings as we go */
4771 ixgbe_free_rx_resources(adapter->rx_ring[i]);
4776 * ixgbe_free_tx_resources - Free Tx Resources per Queue
4777 * @tx_ring: Tx descriptor ring for a specific queue
4779 * Free all transmit software resources
4781 void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
4783 ixgbe_clean_tx_ring(tx_ring);
4785 vfree(tx_ring->tx_buffer_info);
4786 tx_ring->tx_buffer_info = NULL;
4788 /* if not set, then don't free */
4792 dma_free_coherent(tx_ring->dev, tx_ring->size,
4793 tx_ring->desc, tx_ring->dma);
4795 tx_ring->desc = NULL;
4799 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4800 * @adapter: board private structure
4802 * Free all transmit software resources
4804 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4808 for (i = 0; i < adapter->num_tx_queues; i++)
4809 if (adapter->tx_ring[i]->desc)
4810 ixgbe_free_tx_resources(adapter->tx_ring[i]);
4814 * ixgbe_free_rx_resources - Free Rx Resources
4815 * @rx_ring: ring to clean the resources from
4817 * Free all receive software resources
4819 void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
4821 ixgbe_clean_rx_ring(rx_ring);
4823 vfree(rx_ring->rx_buffer_info);
4824 rx_ring->rx_buffer_info = NULL;
4826 /* if not set, then don't free */
4830 dma_free_coherent(rx_ring->dev, rx_ring->size,
4831 rx_ring->desc, rx_ring->dma);
4833 rx_ring->desc = NULL;
4837 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4838 * @adapter: board private structure
4840 * Free all receive software resources
4842 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4847 ixgbe_free_fcoe_ddp_resources(adapter);
4850 for (i = 0; i < adapter->num_rx_queues; i++)
4851 if (adapter->rx_ring[i]->desc)
4852 ixgbe_free_rx_resources(adapter->rx_ring[i]);
4856 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4857 * @netdev: network interface device structure
4858 * @new_mtu: new value for maximum frame size
4860 * Returns 0 on success, negative on failure
4862 static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4864 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4865 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4867 /* MTU < 68 is an error and causes problems on some kernels */
4868 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
4872 * For 82599EB we cannot allow legacy VFs to enable their receive
4873 * paths when MTU greater than 1500 is configured. So display a
4874 * warning that legacy VFs will be disabled.
4876 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
4877 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
4878 (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
4879 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
4881 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
4883 /* must set new MTU before calling down or up */
4884 netdev->mtu = new_mtu;
4886 if (netif_running(netdev))
4887 ixgbe_reinit_locked(adapter);
4893 * ixgbe_open - Called when a network interface is made active
4894 * @netdev: network interface device structure
4896 * Returns 0 on success, negative value on failure
4898 * The open entry point is called when a network interface is made
4899 * active by the system (IFF_UP). At this point all resources needed
4900 * for transmit and receive operations are allocated, the interrupt
4901 * handler is registered with the OS, the watchdog timer is started,
4902 * and the stack is notified that the interface is ready.
4904 static int ixgbe_open(struct net_device *netdev)
4906 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4909 /* disallow open during test */
4910 if (test_bit(__IXGBE_TESTING, &adapter->state))
4913 netif_carrier_off(netdev);
4915 /* allocate transmit descriptors */
4916 err = ixgbe_setup_all_tx_resources(adapter);
4920 /* allocate receive descriptors */
4921 err = ixgbe_setup_all_rx_resources(adapter);
4925 ixgbe_configure(adapter);
4927 err = ixgbe_request_irq(adapter);
4931 /* Notify the stack of the actual queue counts. */
4932 err = netif_set_real_num_tx_queues(netdev,
4933 adapter->num_rx_pools > 1 ? 1 :
4934 adapter->num_tx_queues);
4936 goto err_set_queues;
4939 err = netif_set_real_num_rx_queues(netdev,
4940 adapter->num_rx_pools > 1 ? 1 :
4941 adapter->num_rx_queues);
4943 goto err_set_queues;
4945 ixgbe_ptp_init(adapter);
4947 ixgbe_up_complete(adapter);
4952 ixgbe_free_irq(adapter);
4954 ixgbe_free_all_rx_resources(adapter);
4956 ixgbe_free_all_tx_resources(adapter);
4958 ixgbe_reset(adapter);
4964 * ixgbe_close - Disables a network interface
4965 * @netdev: network interface device structure
4967 * Returns 0, this is not allowed to fail
4969 * The close entry point is called when an interface is de-activated
4970 * by the OS. The hardware is still under the drivers control, but
4971 * needs to be disabled. A global MAC reset is issued to stop the
4972 * hardware, and all transmit and receive resources are freed.
4974 static int ixgbe_close(struct net_device *netdev)
4976 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4978 ixgbe_ptp_stop(adapter);
4980 ixgbe_down(adapter);
4981 ixgbe_free_irq(adapter);
4983 ixgbe_fdir_filter_exit(adapter);
4985 ixgbe_free_all_tx_resources(adapter);
4986 ixgbe_free_all_rx_resources(adapter);
4988 ixgbe_release_hw_control(adapter);
4994 static int ixgbe_resume(struct pci_dev *pdev)
4996 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
4997 struct net_device *netdev = adapter->netdev;
5000 pci_set_power_state(pdev, PCI_D0);
5001 pci_restore_state(pdev);
5003 * pci_restore_state clears dev->state_saved so call
5004 * pci_save_state to restore it.
5006 pci_save_state(pdev);
5008 err = pci_enable_device_mem(pdev);
5010 e_dev_err("Cannot enable PCI device from suspend\n");
5013 pci_set_master(pdev);
5015 pci_wake_from_d3(pdev, false);
5017 ixgbe_reset(adapter);
5019 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5022 err = ixgbe_init_interrupt_scheme(adapter);
5023 if (!err && netif_running(netdev))
5024 err = ixgbe_open(netdev);
5031 netif_device_attach(netdev);
5035 #endif /* CONFIG_PM */
5037 static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
5039 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5040 struct net_device *netdev = adapter->netdev;
5041 struct ixgbe_hw *hw = &adapter->hw;
5043 u32 wufc = adapter->wol;
5048 netif_device_detach(netdev);
5050 if (netif_running(netdev)) {
5052 ixgbe_down(adapter);
5053 ixgbe_free_irq(adapter);
5054 ixgbe_free_all_tx_resources(adapter);
5055 ixgbe_free_all_rx_resources(adapter);
5059 ixgbe_clear_interrupt_scheme(adapter);
5062 retval = pci_save_state(pdev);
5068 ixgbe_set_rx_mode(netdev);
5070 /* enable the optics for 82599 SFP+ fiber as we can WoL */
5071 if (hw->mac.ops.enable_tx_laser)
5072 hw->mac.ops.enable_tx_laser(hw);
5074 /* turn on all-multi mode if wake on multicast is enabled */
5075 if (wufc & IXGBE_WUFC_MC) {
5076 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5077 fctrl |= IXGBE_FCTRL_MPE;
5078 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5081 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5082 ctrl |= IXGBE_CTRL_GIO_DIS;
5083 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5085 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5087 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5088 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5091 switch (hw->mac.type) {
5092 case ixgbe_mac_82598EB:
5093 pci_wake_from_d3(pdev, false);
5095 case ixgbe_mac_82599EB:
5096 case ixgbe_mac_X540:
5097 pci_wake_from_d3(pdev, !!wufc);
5103 *enable_wake = !!wufc;
5105 ixgbe_release_hw_control(adapter);
5107 pci_disable_device(pdev);
5113 static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5118 retval = __ixgbe_shutdown(pdev, &wake);
5123 pci_prepare_to_sleep(pdev);
5125 pci_wake_from_d3(pdev, false);
5126 pci_set_power_state(pdev, PCI_D3hot);
5131 #endif /* CONFIG_PM */
5133 static void ixgbe_shutdown(struct pci_dev *pdev)
5137 __ixgbe_shutdown(pdev, &wake);
5139 if (system_state == SYSTEM_POWER_OFF) {
5140 pci_wake_from_d3(pdev, wake);
5141 pci_set_power_state(pdev, PCI_D3hot);
5146 * ixgbe_update_stats - Update the board statistics counters.
5147 * @adapter: board private structure
5149 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5151 struct net_device *netdev = adapter->netdev;
5152 struct ixgbe_hw *hw = &adapter->hw;
5153 struct ixgbe_hw_stats *hwstats = &adapter->stats;
5155 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
5156 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5157 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5158 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
5160 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5161 test_bit(__IXGBE_RESETTING, &adapter->state))
5164 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
5167 for (i = 0; i < adapter->num_rx_queues; i++) {
5168 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5169 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
5171 adapter->rsc_total_count = rsc_count;
5172 adapter->rsc_total_flush = rsc_flush;
5175 for (i = 0; i < adapter->num_rx_queues; i++) {
5176 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5177 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5178 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5179 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5180 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
5181 bytes += rx_ring->stats.bytes;
5182 packets += rx_ring->stats.packets;
5184 adapter->non_eop_descs = non_eop_descs;
5185 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5186 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5187 adapter->hw_csum_rx_error = hw_csum_rx_error;
5188 netdev->stats.rx_bytes = bytes;
5189 netdev->stats.rx_packets = packets;
5193 /* gather some stats to the adapter struct that are per queue */
5194 for (i = 0; i < adapter->num_tx_queues; i++) {
5195 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5196 restart_queue += tx_ring->tx_stats.restart_queue;
5197 tx_busy += tx_ring->tx_stats.tx_busy;
5198 bytes += tx_ring->stats.bytes;
5199 packets += tx_ring->stats.packets;
5201 adapter->restart_queue = restart_queue;
5202 adapter->tx_busy = tx_busy;
5203 netdev->stats.tx_bytes = bytes;
5204 netdev->stats.tx_packets = packets;
5206 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
5208 /* 8 register reads */
5209 for (i = 0; i < 8; i++) {
5210 /* for packet buffers not used, the register should read 0 */
5211 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5213 hwstats->mpc[i] += mpc;
5214 total_mpc += hwstats->mpc[i];
5215 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5216 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
5217 switch (hw->mac.type) {
5218 case ixgbe_mac_82598EB:
5219 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5220 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5221 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
5222 hwstats->pxonrxc[i] +=
5223 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
5225 case ixgbe_mac_82599EB:
5226 case ixgbe_mac_X540:
5227 hwstats->pxonrxc[i] +=
5228 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
5235 /*16 register reads */
5236 for (i = 0; i < 16; i++) {
5237 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5238 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5239 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5240 (hw->mac.type == ixgbe_mac_X540)) {
5241 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5242 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5243 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5244 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5248 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
5249 /* work around hardware counting issue */
5250 hwstats->gprc -= missed_rx;
5252 ixgbe_update_xoff_received(adapter);
5254 /* 82598 hardware only has a 32 bit counter in the high register */
5255 switch (hw->mac.type) {
5256 case ixgbe_mac_82598EB:
5257 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
5258 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5259 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5260 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5262 case ixgbe_mac_X540:
5263 /* OS2BMC stats are X540 only*/
5264 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5265 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5266 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5267 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5268 case ixgbe_mac_82599EB:
5269 for (i = 0; i < 16; i++)
5270 adapter->hw_rx_no_dma_resources +=
5271 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
5272 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
5273 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
5274 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
5275 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
5276 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
5277 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
5278 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
5279 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5280 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
5282 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5283 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5284 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5285 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5286 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5287 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
5288 /* Add up per cpu counters for total ddp aloc fail */
5289 if (adapter->fcoe.ddp_pool) {
5290 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5291 struct ixgbe_fcoe_ddp_pool *ddp_pool;
5293 u64 noddp = 0, noddp_ext_buff = 0;
5294 for_each_possible_cpu(cpu) {
5295 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
5296 noddp += ddp_pool->noddp;
5297 noddp_ext_buff += ddp_pool->noddp_ext_buff;
5299 hwstats->fcoe_noddp = noddp;
5300 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
5302 #endif /* IXGBE_FCOE */
5307 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
5308 hwstats->bprc += bprc;
5309 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
5310 if (hw->mac.type == ixgbe_mac_82598EB)
5311 hwstats->mprc -= bprc;
5312 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5313 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5314 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5315 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5316 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5317 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5318 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5319 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
5320 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
5321 hwstats->lxontxc += lxon;
5322 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
5323 hwstats->lxofftxc += lxoff;
5324 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5325 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
5327 * 82598 errata - tx of flow control packets is included in tx counters
5329 xon_off_tot = lxon + lxoff;
5330 hwstats->gptc -= xon_off_tot;
5331 hwstats->mptc -= xon_off_tot;
5332 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5333 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5334 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5335 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5336 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5337 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5338 hwstats->ptc64 -= xon_off_tot;
5339 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5340 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5341 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5342 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5343 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5344 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
5346 /* Fill out the OS statistics structure */
5347 netdev->stats.multicast = hwstats->mprc;
5350 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
5351 netdev->stats.rx_dropped = 0;
5352 netdev->stats.rx_length_errors = hwstats->rlec;
5353 netdev->stats.rx_crc_errors = hwstats->crcerrs;
5354 netdev->stats.rx_missed_errors = total_mpc;
5358 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5359 * @adapter: pointer to the device adapter structure
5361 static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
5363 struct ixgbe_hw *hw = &adapter->hw;
5366 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5369 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5371 /* if interface is down do nothing */
5372 if (test_bit(__IXGBE_DOWN, &adapter->state))
5375 /* do nothing if we are not using signature filters */
5376 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5379 adapter->fdir_overflow++;
5381 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5382 for (i = 0; i < adapter->num_tx_queues; i++)
5383 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
5384 &(adapter->tx_ring[i]->state));
5385 /* re-enable flow director interrupts */
5386 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
5388 e_err(probe, "failed to finish FDIR re-initialization, "
5389 "ignored adding FDIR ATR filters\n");
5394 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5395 * @adapter: pointer to the device adapter structure
5397 * This function serves two purposes. First it strobes the interrupt lines
5398 * in order to make certain interrupts are occurring. Secondly it sets the
5399 * bits needed to check for TX hangs. As a result we should immediately
5400 * determine if a hang has occurred.
5402 static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5404 struct ixgbe_hw *hw = &adapter->hw;
5408 /* If we're down or resetting, just bail */
5409 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5410 test_bit(__IXGBE_RESETTING, &adapter->state))
5413 /* Force detection of hung controller */
5414 if (netif_carrier_ok(adapter->netdev)) {
5415 for (i = 0; i < adapter->num_tx_queues; i++)
5416 set_check_for_tx_hang(adapter->tx_ring[i]);
5419 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
5421 * for legacy and MSI interrupts don't set any bits
5422 * that are enabled for EIAM, because this operation
5423 * would set *both* EIMS and EICS for any bit in EIAM
5425 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5426 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
5428 /* get one bit for every active tx/rx interrupt vector */
5429 for (i = 0; i < adapter->num_q_vectors; i++) {
5430 struct ixgbe_q_vector *qv = adapter->q_vector[i];
5431 if (qv->rx.ring || qv->tx.ring)
5432 eics |= ((u64)1 << i);
5436 /* Cause software interrupt to ensure rings are cleaned */
5437 ixgbe_irq_rearm_queues(adapter, eics);
5442 * ixgbe_watchdog_update_link - update the link status
5443 * @adapter: pointer to the device adapter structure
5444 * @link_speed: pointer to a u32 to store the link_speed
5446 static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
5448 struct ixgbe_hw *hw = &adapter->hw;
5449 u32 link_speed = adapter->link_speed;
5450 bool link_up = adapter->link_up;
5451 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
5453 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5456 if (hw->mac.ops.check_link) {
5457 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
5459 /* always assume link is up, if no check link function */
5460 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5464 if (adapter->ixgbe_ieee_pfc)
5465 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
5467 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
5468 hw->mac.ops.fc_enable(hw);
5469 ixgbe_set_rx_drop_en(adapter);
5473 time_after(jiffies, (adapter->link_check_timeout +
5474 IXGBE_TRY_LINK_TIMEOUT))) {
5475 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5476 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5477 IXGBE_WRITE_FLUSH(hw);
5480 adapter->link_up = link_up;
5481 adapter->link_speed = link_speed;
5484 static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
5486 #ifdef CONFIG_IXGBE_DCB
5487 struct net_device *netdev = adapter->netdev;
5488 struct dcb_app app = {
5489 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
5494 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
5495 up = dcb_ieee_getapp_mask(netdev, &app);
5497 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
5502 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5503 * print link up message
5504 * @adapter: pointer to the device adapter structure
5506 static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5508 struct net_device *netdev = adapter->netdev;
5509 struct ixgbe_hw *hw = &adapter->hw;
5510 u32 link_speed = adapter->link_speed;
5511 bool flow_rx, flow_tx;
5513 /* only continue if link was previously down */
5514 if (netif_carrier_ok(netdev))
5517 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5519 switch (hw->mac.type) {
5520 case ixgbe_mac_82598EB: {
5521 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5522 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5523 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5524 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5527 case ixgbe_mac_X540:
5528 case ixgbe_mac_82599EB: {
5529 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5530 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5531 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5532 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5541 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5542 ixgbe_ptp_start_cyclecounter(adapter);
5544 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5545 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5547 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5549 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5552 ((flow_rx && flow_tx) ? "RX/TX" :
5554 (flow_tx ? "TX" : "None"))));
5556 netif_carrier_on(netdev);
5557 ixgbe_check_vf_rate_limit(adapter);
5559 /* update the default user priority for VFs */
5560 ixgbe_update_default_up(adapter);
5562 /* ping all the active vfs to let them know link has changed */
5563 ixgbe_ping_all_vfs(adapter);
5567 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5568 * print link down message
5569 * @adapter: pointer to the adapter structure
5571 static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
5573 struct net_device *netdev = adapter->netdev;
5574 struct ixgbe_hw *hw = &adapter->hw;
5576 adapter->link_up = false;
5577 adapter->link_speed = 0;
5579 /* only continue if link was up previously */
5580 if (!netif_carrier_ok(netdev))
5583 /* poll for SFP+ cable when link is down */
5584 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5585 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5587 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5588 ixgbe_ptp_start_cyclecounter(adapter);
5590 e_info(drv, "NIC Link is Down\n");
5591 netif_carrier_off(netdev);
5593 /* ping all the active vfs to let them know link has changed */
5594 ixgbe_ping_all_vfs(adapter);
5598 * ixgbe_watchdog_flush_tx - flush queues on link down
5599 * @adapter: pointer to the device adapter structure
5601 static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5604 int some_tx_pending = 0;
5606 if (!netif_carrier_ok(adapter->netdev)) {
5607 for (i = 0; i < adapter->num_tx_queues; i++) {
5608 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5609 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5610 some_tx_pending = 1;
5615 if (some_tx_pending) {
5616 /* We've lost link, so the controller stops DMA,
5617 * but we've got queued Tx work that's never going
5618 * to get done, so reset controller to flush Tx.
5619 * (Do the reset outside of interrupt context).
5621 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
5626 static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
5630 /* Do not perform spoof check for 82598 or if not in IOV mode */
5631 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
5632 adapter->num_vfs == 0)
5635 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
5638 * ssvpc register is cleared on read, if zero then no
5639 * spoofed packets in the last interval.
5644 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
5648 * ixgbe_watchdog_subtask - check and bring link up
5649 * @adapter: pointer to the device adapter structure
5651 static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
5653 /* if interface is down do nothing */
5654 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5655 test_bit(__IXGBE_RESETTING, &adapter->state))
5658 ixgbe_watchdog_update_link(adapter);
5660 if (adapter->link_up)
5661 ixgbe_watchdog_link_is_up(adapter);
5663 ixgbe_watchdog_link_is_down(adapter);
5665 ixgbe_spoof_check(adapter);
5666 ixgbe_update_stats(adapter);
5668 ixgbe_watchdog_flush_tx(adapter);
5672 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
5673 * @adapter: the ixgbe adapter structure
5675 static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
5677 struct ixgbe_hw *hw = &adapter->hw;
5680 /* not searching for SFP so there is nothing to do here */
5681 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
5682 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5685 /* someone else is in init, wait until next service event */
5686 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5689 err = hw->phy.ops.identify_sfp(hw);
5690 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5693 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
5694 /* If no cable is present, then we need to reset
5695 * the next time we find a good cable. */
5696 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
5703 /* exit if reset not needed */
5704 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5707 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
5710 * A module may be identified correctly, but the EEPROM may not have
5711 * support for that module. setup_sfp() will fail in that case, so
5712 * we should not allow that module to load.
5714 if (hw->mac.type == ixgbe_mac_82598EB)
5715 err = hw->phy.ops.reset(hw);
5717 err = hw->mac.ops.setup_sfp(hw);
5719 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5722 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
5723 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
5726 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5728 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
5729 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
5730 e_dev_err("failed to initialize because an unsupported "
5731 "SFP+ module type was detected.\n");
5732 e_dev_err("Reload the driver after installing a "
5733 "supported module.\n");
5734 unregister_netdev(adapter->netdev);
5739 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
5740 * @adapter: the ixgbe adapter structure
5742 static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
5744 struct ixgbe_hw *hw = &adapter->hw;
5748 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
5751 /* someone else is in init, wait until next service event */
5752 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5755 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5757 autoneg = hw->phy.autoneg_advertised;
5758 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
5759 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
5760 if (hw->mac.ops.setup_link)
5761 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
5763 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5764 adapter->link_check_timeout = jiffies;
5765 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5768 #ifdef CONFIG_PCI_IOV
5769 static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
5772 struct ixgbe_hw *hw = &adapter->hw;
5773 struct net_device *netdev = adapter->netdev;
5777 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
5778 if (gpc) /* If incrementing then no need for the check below */
5781 * Check to see if a bad DMA write target from an errant or
5782 * malicious VF has caused a PCIe error. If so then we can
5783 * issue a VFLR to the offending VF(s) and then resume without
5784 * requesting a full slot reset.
5787 for (vf = 0; vf < adapter->num_vfs; vf++) {
5788 ciaa = (vf << 16) | 0x80000000;
5789 /* 32 bit read so align, we really want status at offset 6 */
5790 ciaa |= PCI_COMMAND;
5791 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5792 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
5794 /* disable debug mode asap after reading data */
5795 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5796 /* Get the upper 16 bits which will be the PCI status reg */
5798 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
5799 netdev_err(netdev, "VF %d Hung DMA\n", vf);
5801 ciaa = (vf << 16) | 0x80000000;
5803 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5804 ciad = 0x00008000; /* VFLR */
5805 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
5807 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5814 * ixgbe_service_timer - Timer Call-back
5815 * @data: pointer to adapter cast into an unsigned long
5817 static void ixgbe_service_timer(unsigned long data)
5819 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
5820 unsigned long next_event_offset;
5823 /* poll faster when waiting for link */
5824 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
5825 next_event_offset = HZ / 10;
5827 next_event_offset = HZ * 2;
5829 #ifdef CONFIG_PCI_IOV
5831 * don't bother with SR-IOV VF DMA hang check if there are
5832 * no VFs or the link is down
5834 if (!adapter->num_vfs ||
5835 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5836 goto normal_timer_service;
5838 /* If we have VFs allocated then we must check for DMA hangs */
5839 ixgbe_check_for_bad_vf(adapter);
5840 next_event_offset = HZ / 50;
5841 adapter->timer_event_accumulator++;
5843 if (adapter->timer_event_accumulator >= 100)
5844 adapter->timer_event_accumulator = 0;
5848 normal_timer_service:
5850 /* Reset the timer */
5851 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
5854 ixgbe_service_event_schedule(adapter);
5857 static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
5859 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
5862 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
5864 /* If we're already down or resetting, just bail */
5865 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5866 test_bit(__IXGBE_RESETTING, &adapter->state))
5869 ixgbe_dump(adapter);
5870 netdev_err(adapter->netdev, "Reset adapter\n");
5871 adapter->tx_timeout_count++;
5873 ixgbe_reinit_locked(adapter);
5877 * ixgbe_service_task - manages and runs subtasks
5878 * @work: pointer to work_struct containing our data
5880 static void ixgbe_service_task(struct work_struct *work)
5882 struct ixgbe_adapter *adapter = container_of(work,
5883 struct ixgbe_adapter,
5886 ixgbe_reset_subtask(adapter);
5887 ixgbe_sfp_detection_subtask(adapter);
5888 ixgbe_sfp_link_config_subtask(adapter);
5889 ixgbe_check_overtemp_subtask(adapter);
5890 ixgbe_watchdog_subtask(adapter);
5891 ixgbe_fdir_reinit_subtask(adapter);
5892 ixgbe_check_hang_subtask(adapter);
5893 ixgbe_ptp_overflow_check(adapter);
5895 ixgbe_service_event_complete(adapter);
5898 static int ixgbe_tso(struct ixgbe_ring *tx_ring,
5899 struct ixgbe_tx_buffer *first,
5902 struct sk_buff *skb = first->skb;
5903 u32 vlan_macip_lens, type_tucmd;
5904 u32 mss_l4len_idx, l4len;
5906 if (!skb_is_gso(skb))
5909 if (skb_header_cloned(skb)) {
5910 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
5915 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5916 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
5918 if (first->protocol == __constant_htons(ETH_P_IP)) {
5919 struct iphdr *iph = ip_hdr(skb);
5922 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
5926 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
5927 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5928 IXGBE_TX_FLAGS_CSUM |
5929 IXGBE_TX_FLAGS_IPV4;
5930 } else if (skb_is_gso_v6(skb)) {
5931 ipv6_hdr(skb)->payload_len = 0;
5932 tcp_hdr(skb)->check =
5933 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5934 &ipv6_hdr(skb)->daddr,
5936 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5937 IXGBE_TX_FLAGS_CSUM;
5940 /* compute header lengths */
5941 l4len = tcp_hdrlen(skb);
5942 *hdr_len = skb_transport_offset(skb) + l4len;
5944 /* update gso size and bytecount with header size */
5945 first->gso_segs = skb_shinfo(skb)->gso_segs;
5946 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5948 /* mss_l4len_id: use 1 as index for TSO */
5949 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
5950 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
5951 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
5953 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
5954 vlan_macip_lens = skb_network_header_len(skb);
5955 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
5956 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
5958 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
5964 static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
5965 struct ixgbe_tx_buffer *first)
5967 struct sk_buff *skb = first->skb;
5968 u32 vlan_macip_lens = 0;
5969 u32 mss_l4len_idx = 0;
5972 if (skb->ip_summed != CHECKSUM_PARTIAL) {
5973 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN)) {
5974 if (unlikely(skb->no_fcs))
5975 first->tx_flags |= IXGBE_TX_FLAGS_NO_IFCS;
5976 if (!(first->tx_flags & IXGBE_TX_FLAGS_TXSW))
5981 switch (first->protocol) {
5982 case __constant_htons(ETH_P_IP):
5983 vlan_macip_lens |= skb_network_header_len(skb);
5984 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
5985 l4_hdr = ip_hdr(skb)->protocol;
5987 case __constant_htons(ETH_P_IPV6):
5988 vlan_macip_lens |= skb_network_header_len(skb);
5989 l4_hdr = ipv6_hdr(skb)->nexthdr;
5992 if (unlikely(net_ratelimit())) {
5993 dev_warn(tx_ring->dev,
5994 "partial checksum but proto=%x!\n",
6002 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6003 mss_l4len_idx = tcp_hdrlen(skb) <<
6004 IXGBE_ADVTXD_L4LEN_SHIFT;
6007 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6008 mss_l4len_idx = sizeof(struct sctphdr) <<
6009 IXGBE_ADVTXD_L4LEN_SHIFT;
6012 mss_l4len_idx = sizeof(struct udphdr) <<
6013 IXGBE_ADVTXD_L4LEN_SHIFT;
6016 if (unlikely(net_ratelimit())) {
6017 dev_warn(tx_ring->dev,
6018 "partial checksum but l4 proto=%x!\n",
6024 /* update TX checksum flag */
6025 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
6028 /* vlan_macip_lens: MACLEN, VLAN tag */
6029 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6030 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6032 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6033 type_tucmd, mss_l4len_idx);
6036 static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6038 /* set type for advanced descriptor with frame checksum insertion */
6039 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6040 IXGBE_ADVTXD_DCMD_DEXT);
6042 /* set HW vlan bit if vlan is present */
6043 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
6044 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6046 if (tx_flags & IXGBE_TX_FLAGS_TSTAMP)
6047 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_MAC_TSTAMP);
6049 /* set segmentation enable bits for TSO/FSO */
6051 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO))
6053 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6055 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6057 /* insert frame checksum */
6058 if (!(tx_flags & IXGBE_TX_FLAGS_NO_IFCS))
6059 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS);
6064 static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
6065 u32 tx_flags, unsigned int paylen)
6067 __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
6069 /* enable L4 checksum for TSO and TX checksum offload */
6070 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6071 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6073 /* enble IPv4 checksum for TSO */
6074 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6075 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
6077 /* use index 1 context for TSO/FSO/FCOE */
6079 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE))
6081 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6083 olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT);
6086 * Check Context must be set if Tx switch is enabled, which it
6087 * always is for case where virtual functions are running
6090 if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE))
6092 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
6094 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6096 tx_desc->read.olinfo_status = olinfo_status;
6099 #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6102 static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
6103 struct ixgbe_tx_buffer *first,
6107 struct sk_buff *skb = first->skb;
6108 struct ixgbe_tx_buffer *tx_buffer;
6109 union ixgbe_adv_tx_desc *tx_desc;
6110 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
6111 unsigned int data_len = skb->data_len;
6112 unsigned int size = skb_headlen(skb);
6113 unsigned int paylen = skb->len - hdr_len;
6114 u32 tx_flags = first->tx_flags;
6116 u16 i = tx_ring->next_to_use;
6118 tx_desc = IXGBE_TX_DESC(tx_ring, i);
6120 ixgbe_tx_olinfo_status(tx_desc, tx_flags, paylen);
6121 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6124 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6125 if (data_len < sizeof(struct fcoe_crc_eof)) {
6126 size -= sizeof(struct fcoe_crc_eof) - data_len;
6129 data_len -= sizeof(struct fcoe_crc_eof);
6134 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
6135 if (dma_mapping_error(tx_ring->dev, dma))
6138 /* record length, and DMA address */
6139 dma_unmap_len_set(first, len, size);
6140 dma_unmap_addr_set(first, dma, dma);
6142 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6145 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
6146 tx_desc->read.cmd_type_len =
6147 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
6151 if (i == tx_ring->count) {
6152 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
6156 dma += IXGBE_MAX_DATA_PER_TXD;
6157 size -= IXGBE_MAX_DATA_PER_TXD;
6159 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6160 tx_desc->read.olinfo_status = 0;
6163 if (likely(!data_len))
6166 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
6170 if (i == tx_ring->count) {
6171 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
6176 size = min_t(unsigned int, data_len, skb_frag_size(frag));
6178 size = skb_frag_size(frag);
6182 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
6184 if (dma_mapping_error(tx_ring->dev, dma))
6187 tx_buffer = &tx_ring->tx_buffer_info[i];
6188 dma_unmap_len_set(tx_buffer, len, size);
6189 dma_unmap_addr_set(tx_buffer, dma, dma);
6191 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6192 tx_desc->read.olinfo_status = 0;
6197 /* write last descriptor with RS and EOP bits */
6198 cmd_type |= cpu_to_le32(size) | cpu_to_le32(IXGBE_TXD_CMD);
6199 tx_desc->read.cmd_type_len = cmd_type;
6201 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
6203 /* set the timestamp */
6204 first->time_stamp = jiffies;
6207 * Force memory writes to complete before letting h/w know there
6208 * are new descriptors to fetch. (Only applicable for weak-ordered
6209 * memory model archs, such as IA-64).
6211 * We also need this memory barrier to make certain all of the
6212 * status bits have been updated before next_to_watch is written.
6216 /* set next_to_watch value indicating a packet is present */
6217 first->next_to_watch = tx_desc;
6220 if (i == tx_ring->count)
6223 tx_ring->next_to_use = i;
6225 /* notify HW of packet */
6226 writel(i, tx_ring->tail);
6230 dev_err(tx_ring->dev, "TX DMA map failed\n");
6232 /* clear dma mappings for failed tx_buffer_info map */
6234 tx_buffer = &tx_ring->tx_buffer_info[i];
6235 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
6236 if (tx_buffer == first)
6243 tx_ring->next_to_use = i;
6246 static void ixgbe_atr(struct ixgbe_ring *ring,
6247 struct ixgbe_tx_buffer *first)
6249 struct ixgbe_q_vector *q_vector = ring->q_vector;
6250 union ixgbe_atr_hash_dword input = { .dword = 0 };
6251 union ixgbe_atr_hash_dword common = { .dword = 0 };
6253 unsigned char *network;
6255 struct ipv6hdr *ipv6;
6260 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6264 /* do nothing if sampling is disabled */
6265 if (!ring->atr_sample_rate)
6270 /* snag network header to get L4 type and address */
6271 hdr.network = skb_network_header(first->skb);
6273 /* Currently only IPv4/IPv6 with TCP is supported */
6274 if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
6275 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6276 (first->protocol != __constant_htons(ETH_P_IP) ||
6277 hdr.ipv4->protocol != IPPROTO_TCP))
6280 th = tcp_hdr(first->skb);
6282 /* skip this packet since it is invalid or the socket is closing */
6286 /* sample on all syn packets or once every atr sample count */
6287 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6290 /* reset sample count */
6291 ring->atr_count = 0;
6293 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6296 * src and dst are inverted, think how the receiver sees them
6298 * The input is broken into two sections, a non-compressed section
6299 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6300 * is XORed together and stored in the compressed dword.
6302 input.formatted.vlan_id = vlan_id;
6305 * since src port and flex bytes occupy the same word XOR them together
6306 * and write the value to source port portion of compressed dword
6308 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
6309 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6311 common.port.src ^= th->dest ^ first->protocol;
6312 common.port.dst ^= th->source;
6314 if (first->protocol == __constant_htons(ETH_P_IP)) {
6315 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6316 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6318 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6319 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6320 hdr.ipv6->saddr.s6_addr32[1] ^
6321 hdr.ipv6->saddr.s6_addr32[2] ^
6322 hdr.ipv6->saddr.s6_addr32[3] ^
6323 hdr.ipv6->daddr.s6_addr32[0] ^
6324 hdr.ipv6->daddr.s6_addr32[1] ^
6325 hdr.ipv6->daddr.s6_addr32[2] ^
6326 hdr.ipv6->daddr.s6_addr32[3];
6329 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
6330 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6331 input, common, ring->queue_index);
6334 static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
6336 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
6337 /* Herbert's original patch had:
6338 * smp_mb__after_netif_stop_queue();
6339 * but since that doesn't exist yet, just open code it. */
6342 /* We need to check again in a case another CPU has just
6343 * made room available. */
6344 if (likely(ixgbe_desc_unused(tx_ring) < size))
6347 /* A reprieve! - use start_queue because it doesn't call schedule */
6348 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
6349 ++tx_ring->tx_stats.restart_queue;
6353 static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
6355 if (likely(ixgbe_desc_unused(tx_ring) >= size))
6357 return __ixgbe_maybe_stop_tx(tx_ring, size);
6360 static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6362 struct ixgbe_adapter *adapter = netdev_priv(dev);
6363 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6366 __be16 protocol = vlan_get_protocol(skb);
6368 if (((protocol == htons(ETH_P_FCOE)) ||
6369 (protocol == htons(ETH_P_FIP))) &&
6370 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6371 struct ixgbe_ring_feature *f;
6373 f = &adapter->ring_feature[RING_F_FCOE];
6375 while (txq >= f->indices)
6377 txq += adapter->ring_feature[RING_F_FCOE].offset;
6383 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6384 while (unlikely(txq >= dev->real_num_tx_queues))
6385 txq -= dev->real_num_tx_queues;
6389 return skb_tx_hash(dev, skb);
6392 netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
6393 struct ixgbe_adapter *adapter,
6394 struct ixgbe_ring *tx_ring)
6396 struct ixgbe_tx_buffer *first;
6399 #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6402 u16 count = TXD_USE_COUNT(skb_headlen(skb));
6403 __be16 protocol = skb->protocol;
6407 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
6408 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
6409 * + 2 desc gap to keep tail from touching head,
6410 * + 1 desc for context descriptor,
6411 * otherwise try next time
6413 #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6414 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6415 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6417 count += skb_shinfo(skb)->nr_frags;
6419 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6420 tx_ring->tx_stats.tx_busy++;
6421 return NETDEV_TX_BUSY;
6424 /* record the location of the first descriptor for this packet */
6425 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6427 first->bytecount = skb->len;
6428 first->gso_segs = 1;
6430 /* if we have a HW VLAN tag being added default to the HW one */
6431 if (vlan_tx_tag_present(skb)) {
6432 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6433 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6434 /* else if it is a SW VLAN check the next protocol and store the tag */
6435 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6436 struct vlan_hdr *vhdr, _vhdr;
6437 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6441 protocol = vhdr->h_vlan_encapsulated_proto;
6442 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
6443 IXGBE_TX_FLAGS_VLAN_SHIFT;
6444 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
6447 skb_tx_timestamp(skb);
6449 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
6450 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
6451 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
6454 #ifdef CONFIG_PCI_IOV
6456 * Use the l2switch_enable flag - would be false if the DMA
6457 * Tx switch had been disabled.
6459 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6460 tx_flags |= IXGBE_TX_FLAGS_TXSW;
6463 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
6464 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
6465 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6466 (skb->priority != TC_PRIO_CONTROL))) {
6467 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
6468 tx_flags |= (skb->priority & 0x7) <<
6469 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
6470 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6471 struct vlan_ethhdr *vhdr;
6472 if (skb_header_cloned(skb) &&
6473 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6475 vhdr = (struct vlan_ethhdr *)skb->data;
6476 vhdr->h_vlan_TCI = htons(tx_flags >>
6477 IXGBE_TX_FLAGS_VLAN_SHIFT);
6479 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6483 /* record initial flags and protocol */
6484 first->tx_flags = tx_flags;
6485 first->protocol = protocol;
6488 /* setup tx offload for FCoE */
6489 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
6490 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
6491 tso = ixgbe_fso(tx_ring, first, &hdr_len);
6498 #endif /* IXGBE_FCOE */
6499 tso = ixgbe_tso(tx_ring, first, &hdr_len);
6503 ixgbe_tx_csum(tx_ring, first);
6505 /* add the ATR filter if ATR is on */
6506 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6507 ixgbe_atr(tx_ring, first);
6511 #endif /* IXGBE_FCOE */
6512 ixgbe_tx_map(tx_ring, first, hdr_len);
6514 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
6516 return NETDEV_TX_OK;
6519 dev_kfree_skb_any(first->skb);
6522 return NETDEV_TX_OK;
6525 static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
6526 struct net_device *netdev)
6528 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6529 struct ixgbe_ring *tx_ring;
6532 * The minimum packet size for olinfo paylen is 17 so pad the skb
6533 * in order to meet this minimum size requirement.
6535 if (unlikely(skb->len < 17)) {
6536 if (skb_pad(skb, 17 - skb->len))
6537 return NETDEV_TX_OK;
6539 skb_set_tail_pointer(skb, 17);
6542 tx_ring = adapter->tx_ring[skb->queue_mapping];
6543 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6547 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6548 * @netdev: network interface device structure
6549 * @p: pointer to an address structure
6551 * Returns 0 on success, negative on failure
6553 static int ixgbe_set_mac(struct net_device *netdev, void *p)
6555 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6556 struct ixgbe_hw *hw = &adapter->hw;
6557 struct sockaddr *addr = p;
6559 if (!is_valid_ether_addr(addr->sa_data))
6560 return -EADDRNOTAVAIL;
6562 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6563 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6565 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
6571 ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6573 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6574 struct ixgbe_hw *hw = &adapter->hw;
6578 if (prtad != hw->phy.mdio.prtad)
6580 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6586 static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6587 u16 addr, u16 value)
6589 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6590 struct ixgbe_hw *hw = &adapter->hw;
6592 if (prtad != hw->phy.mdio.prtad)
6594 return hw->phy.ops.write_reg(hw, addr, devad, value);
6597 static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6599 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6603 return ixgbe_ptp_hwtstamp_ioctl(adapter, req, cmd);
6605 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6610 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
6612 * @netdev: network interface device structure
6614 * Returns non-zero on failure
6616 static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6619 struct ixgbe_adapter *adapter = netdev_priv(dev);
6620 struct ixgbe_hw *hw = &adapter->hw;
6622 if (is_valid_ether_addr(hw->mac.san_addr)) {
6624 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
6627 /* update SAN MAC vmdq pool selection */
6628 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
6634 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
6636 * @netdev: network interface device structure
6638 * Returns non-zero on failure
6640 static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6643 struct ixgbe_adapter *adapter = netdev_priv(dev);
6644 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6646 if (is_valid_ether_addr(mac->san_addr)) {
6648 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6654 #ifdef CONFIG_NET_POLL_CONTROLLER
6656 * Polling 'interrupt' - used by things like netconsole to send skbs
6657 * without having to re-enable interrupts. It's not called while
6658 * the interrupt routine is executing.
6660 static void ixgbe_netpoll(struct net_device *netdev)
6662 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6665 /* if interface is down do nothing */
6666 if (test_bit(__IXGBE_DOWN, &adapter->state))
6669 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
6670 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
6671 for (i = 0; i < adapter->num_q_vectors; i++)
6672 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
6674 ixgbe_intr(adapter->pdev->irq, netdev);
6676 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
6680 static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6681 struct rtnl_link_stats64 *stats)
6683 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6687 for (i = 0; i < adapter->num_rx_queues; i++) {
6688 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
6694 start = u64_stats_fetch_begin_bh(&ring->syncp);
6695 packets = ring->stats.packets;
6696 bytes = ring->stats.bytes;
6697 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6698 stats->rx_packets += packets;
6699 stats->rx_bytes += bytes;
6703 for (i = 0; i < adapter->num_tx_queues; i++) {
6704 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
6710 start = u64_stats_fetch_begin_bh(&ring->syncp);
6711 packets = ring->stats.packets;
6712 bytes = ring->stats.bytes;
6713 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6714 stats->tx_packets += packets;
6715 stats->tx_bytes += bytes;
6719 /* following stats updated by ixgbe_watchdog_task() */
6720 stats->multicast = netdev->stats.multicast;
6721 stats->rx_errors = netdev->stats.rx_errors;
6722 stats->rx_length_errors = netdev->stats.rx_length_errors;
6723 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
6724 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
6728 #ifdef CONFIG_IXGBE_DCB
6730 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
6731 * @adapter: pointer to ixgbe_adapter
6732 * @tc: number of traffic classes currently enabled
6734 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
6735 * 802.1Q priority maps to a packet buffer that exists.
6737 static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
6739 struct ixgbe_hw *hw = &adapter->hw;
6743 /* 82598 have a static priority to TC mapping that can not
6744 * be changed so no validation is needed.
6746 if (hw->mac.type == ixgbe_mac_82598EB)
6749 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
6752 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
6753 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
6755 /* If up2tc is out of bounds default to zero */
6757 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
6761 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
6767 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
6768 * @adapter: Pointer to adapter struct
6770 * Populate the netdev user priority to tc map
6772 static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
6774 struct net_device *dev = adapter->netdev;
6775 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
6776 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
6779 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
6782 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
6783 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
6785 tc = ets->prio_tc[prio];
6787 netdev_set_prio_tc_map(dev, prio, tc);
6792 * ixgbe_setup_tc - configure net_device for multiple traffic classes
6794 * @netdev: net device to configure
6795 * @tc: number of traffic classes to enable
6797 int ixgbe_setup_tc(struct net_device *dev, u8 tc)
6799 struct ixgbe_adapter *adapter = netdev_priv(dev);
6800 struct ixgbe_hw *hw = &adapter->hw;
6802 /* Hardware supports up to 8 traffic classes */
6803 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
6804 (hw->mac.type == ixgbe_mac_82598EB &&
6805 tc < MAX_TRAFFIC_CLASS))
6808 /* Hardware has to reinitialize queues and interrupts to
6809 * match packet buffer alignment. Unfortunately, the
6810 * hardware is not flexible enough to do this dynamically.
6812 if (netif_running(dev))
6814 ixgbe_clear_interrupt_scheme(adapter);
6817 netdev_set_num_tc(dev, tc);
6818 ixgbe_set_prio_tc_map(adapter);
6820 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
6822 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
6823 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
6824 adapter->hw.fc.requested_mode = ixgbe_fc_none;
6827 netdev_reset_tc(dev);
6829 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6830 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
6832 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
6834 adapter->temp_dcb_cfg.pfc_mode_enable = false;
6835 adapter->dcb_cfg.pfc_mode_enable = false;
6838 ixgbe_init_interrupt_scheme(adapter);
6839 ixgbe_validate_rtr(adapter, tc);
6840 if (netif_running(dev))
6846 #endif /* CONFIG_IXGBE_DCB */
6847 void ixgbe_do_reset(struct net_device *netdev)
6849 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6851 if (netif_running(netdev))
6852 ixgbe_reinit_locked(adapter);
6854 ixgbe_reset(adapter);
6857 static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
6858 netdev_features_t features)
6860 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6862 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
6863 if (!(features & NETIF_F_RXCSUM))
6864 features &= ~NETIF_F_LRO;
6866 /* Turn off LRO if not RSC capable */
6867 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
6868 features &= ~NETIF_F_LRO;
6873 static int ixgbe_set_features(struct net_device *netdev,
6874 netdev_features_t features)
6876 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6877 netdev_features_t changed = netdev->features ^ features;
6878 bool need_reset = false;
6880 /* Make sure RSC matches LRO, reset if change */
6881 if (!(features & NETIF_F_LRO)) {
6882 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
6884 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
6885 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
6886 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
6887 if (adapter->rx_itr_setting == 1 ||
6888 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
6889 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
6891 } else if ((changed ^ features) & NETIF_F_LRO) {
6892 e_info(probe, "rx-usecs set too low, "
6898 * Check if Flow Director n-tuple support was enabled or disabled. If
6899 * the state changed, we need to reset.
6901 switch (features & NETIF_F_NTUPLE) {
6902 case NETIF_F_NTUPLE:
6903 /* turn off ATR, enable perfect filters and reset */
6904 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
6907 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
6908 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
6911 /* turn off perfect filters, enable ATR and reset */
6912 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
6915 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
6917 /* We cannot enable ATR if SR-IOV is enabled */
6918 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6921 /* We cannot enable ATR if we have 2 or more traffic classes */
6922 if (netdev_get_num_tc(netdev) > 1)
6925 /* We cannot enable ATR if RSS is disabled */
6926 if (adapter->ring_feature[RING_F_RSS].limit <= 1)
6929 /* A sample rate of 0 indicates ATR disabled */
6930 if (!adapter->atr_sample_rate)
6933 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
6937 if (features & NETIF_F_HW_VLAN_RX)
6938 ixgbe_vlan_strip_enable(adapter);
6940 ixgbe_vlan_strip_disable(adapter);
6942 if (changed & NETIF_F_RXALL)
6945 netdev->features = features;
6947 ixgbe_do_reset(netdev);
6952 static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
6953 struct net_device *dev,
6954 const unsigned char *addr,
6957 struct ixgbe_adapter *adapter = netdev_priv(dev);
6960 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
6963 /* Hardware does not support aging addresses so if a
6964 * ndm_state is given only allow permanent addresses
6966 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
6967 pr_info("%s: FDB only supports static addresses\n",
6972 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
6973 u32 rar_uc_entries = IXGBE_MAX_PF_MACVLANS;
6975 if (netdev_uc_count(dev) < rar_uc_entries)
6976 err = dev_uc_add_excl(dev, addr);
6979 } else if (is_multicast_ether_addr(addr)) {
6980 err = dev_mc_add_excl(dev, addr);
6985 /* Only return duplicate errors if NLM_F_EXCL is set */
6986 if (err == -EEXIST && !(flags & NLM_F_EXCL))
6992 static int ixgbe_ndo_fdb_del(struct ndmsg *ndm,
6993 struct net_device *dev,
6994 const unsigned char *addr)
6996 struct ixgbe_adapter *adapter = netdev_priv(dev);
6997 int err = -EOPNOTSUPP;
6999 if (ndm->ndm_state & NUD_PERMANENT) {
7000 pr_info("%s: FDB only supports static addresses\n",
7005 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7006 if (is_unicast_ether_addr(addr))
7007 err = dev_uc_del(dev, addr);
7008 else if (is_multicast_ether_addr(addr))
7009 err = dev_mc_del(dev, addr);
7017 static int ixgbe_ndo_fdb_dump(struct sk_buff *skb,
7018 struct netlink_callback *cb,
7019 struct net_device *dev,
7022 struct ixgbe_adapter *adapter = netdev_priv(dev);
7024 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7025 idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
7030 static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
7031 struct nlmsghdr *nlh)
7033 struct ixgbe_adapter *adapter = netdev_priv(dev);
7034 struct nlattr *attr, *br_spec;
7037 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7040 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
7042 nla_for_each_nested(attr, br_spec, rem) {
7046 if (nla_type(attr) != IFLA_BRIDGE_MODE)
7049 mode = nla_get_u16(attr);
7050 if (mode == BRIDGE_MODE_VEPA) {
7052 adapter->flags2 &= ~IXGBE_FLAG2_BRIDGE_MODE_VEB;
7053 } else if (mode == BRIDGE_MODE_VEB) {
7054 reg = IXGBE_PFDTXGSWC_VT_LBEN;
7055 adapter->flags2 |= IXGBE_FLAG2_BRIDGE_MODE_VEB;
7059 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, reg);
7061 e_info(drv, "enabling bridge mode: %s\n",
7062 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
7068 static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
7069 struct net_device *dev)
7071 struct ixgbe_adapter *adapter = netdev_priv(dev);
7074 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7077 if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
7078 mode = BRIDGE_MODE_VEB;
7080 mode = BRIDGE_MODE_VEPA;
7082 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode);
7085 static const struct net_device_ops ixgbe_netdev_ops = {
7086 .ndo_open = ixgbe_open,
7087 .ndo_stop = ixgbe_close,
7088 .ndo_start_xmit = ixgbe_xmit_frame,
7089 .ndo_select_queue = ixgbe_select_queue,
7090 .ndo_set_rx_mode = ixgbe_set_rx_mode,
7091 .ndo_validate_addr = eth_validate_addr,
7092 .ndo_set_mac_address = ixgbe_set_mac,
7093 .ndo_change_mtu = ixgbe_change_mtu,
7094 .ndo_tx_timeout = ixgbe_tx_timeout,
7095 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7096 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
7097 .ndo_do_ioctl = ixgbe_ioctl,
7098 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7099 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7100 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7101 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
7102 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
7103 .ndo_get_stats64 = ixgbe_get_stats64,
7104 #ifdef CONFIG_IXGBE_DCB
7105 .ndo_setup_tc = ixgbe_setup_tc,
7107 #ifdef CONFIG_NET_POLL_CONTROLLER
7108 .ndo_poll_controller = ixgbe_netpoll,
7111 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
7112 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
7113 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
7114 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7115 .ndo_fcoe_disable = ixgbe_fcoe_disable,
7116 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
7117 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
7118 #endif /* IXGBE_FCOE */
7119 .ndo_set_features = ixgbe_set_features,
7120 .ndo_fix_features = ixgbe_fix_features,
7121 .ndo_fdb_add = ixgbe_ndo_fdb_add,
7122 .ndo_fdb_del = ixgbe_ndo_fdb_del,
7123 .ndo_fdb_dump = ixgbe_ndo_fdb_dump,
7124 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
7125 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
7129 * ixgbe_wol_supported - Check whether device supports WoL
7130 * @hw: hw specific details
7131 * @device_id: the device ID
7132 * @subdev_id: the subsystem device ID
7134 * This function is used by probe and ethtool to determine
7135 * which devices have WoL support
7138 int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
7141 struct ixgbe_hw *hw = &adapter->hw;
7142 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7143 int is_wol_supported = 0;
7145 switch (device_id) {
7146 case IXGBE_DEV_ID_82599_SFP:
7147 /* Only these subdevices could supports WOL */
7148 switch (subdevice_id) {
7149 case IXGBE_SUBDEV_ID_82599_560FLR:
7150 /* only support first port */
7151 if (hw->bus.func != 0)
7153 case IXGBE_SUBDEV_ID_82599_SFP:
7154 case IXGBE_SUBDEV_ID_82599_RNDC:
7155 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
7156 is_wol_supported = 1;
7160 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7161 /* All except this subdevice support WOL */
7162 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7163 is_wol_supported = 1;
7165 case IXGBE_DEV_ID_82599_KX4:
7166 is_wol_supported = 1;
7168 case IXGBE_DEV_ID_X540T:
7169 case IXGBE_DEV_ID_X540T1:
7170 /* check eeprom to see if enabled wol */
7171 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7172 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7173 (hw->bus.func == 0))) {
7174 is_wol_supported = 1;
7179 return is_wol_supported;
7183 * ixgbe_probe - Device Initialization Routine
7184 * @pdev: PCI device information struct
7185 * @ent: entry in ixgbe_pci_tbl
7187 * Returns 0 on success, negative on failure
7189 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7190 * The OS initialization, configuring of the adapter private structure,
7191 * and a hardware reset occur.
7193 static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7195 struct net_device *netdev;
7196 struct ixgbe_adapter *adapter = NULL;
7197 struct ixgbe_hw *hw;
7198 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
7199 static int cards_found;
7200 int i, err, pci_using_dac;
7201 u8 part_str[IXGBE_PBANUM_LENGTH];
7202 unsigned int indices = num_possible_cpus();
7203 unsigned int dcb_max = 0;
7209 /* Catch broken hardware that put the wrong VF device ID in
7210 * the PCIe SR-IOV capability.
7212 if (pdev->is_virtfn) {
7213 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7214 pci_name(pdev), pdev->vendor, pdev->device);
7218 err = pci_enable_device_mem(pdev);
7222 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7223 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
7226 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
7228 err = dma_set_coherent_mask(&pdev->dev,
7232 "No usable DMA configuration, aborting\n");
7239 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
7240 IORESOURCE_MEM), ixgbe_driver_name);
7243 "pci_request_selected_regions failed 0x%x\n", err);
7247 pci_enable_pcie_error_reporting(pdev);
7249 pci_set_master(pdev);
7250 pci_save_state(pdev);
7252 #ifdef CONFIG_IXGBE_DCB
7253 if (ii->mac == ixgbe_mac_82598EB)
7254 dcb_max = min_t(unsigned int, indices * MAX_TRAFFIC_CLASS,
7255 IXGBE_MAX_RSS_INDICES);
7257 dcb_max = min_t(unsigned int, indices * MAX_TRAFFIC_CLASS,
7258 IXGBE_MAX_FDIR_INDICES);
7261 if (ii->mac == ixgbe_mac_82598EB)
7262 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7264 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7267 indices += min_t(unsigned int, num_possible_cpus(),
7268 IXGBE_MAX_FCOE_INDICES);
7270 indices = max_t(unsigned int, dcb_max, indices);
7271 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
7274 goto err_alloc_etherdev;
7277 SET_NETDEV_DEV(netdev, &pdev->dev);
7279 adapter = netdev_priv(netdev);
7280 pci_set_drvdata(pdev, adapter);
7282 adapter->netdev = netdev;
7283 adapter->pdev = pdev;
7286 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
7288 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
7289 pci_resource_len(pdev, 0));
7295 netdev->netdev_ops = &ixgbe_netdev_ops;
7296 ixgbe_set_ethtool_ops(netdev);
7297 netdev->watchdog_timeo = 5 * HZ;
7298 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
7300 adapter->bd_number = cards_found;
7303 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
7304 hw->mac.type = ii->mac;
7307 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7308 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7309 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7310 if (!(eec & (1 << 8)))
7311 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7314 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
7315 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
7316 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7317 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7318 hw->phy.mdio.mmds = 0;
7319 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7320 hw->phy.mdio.dev = netdev;
7321 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7322 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
7324 ii->get_invariants(hw);
7326 /* setup the private structure */
7327 err = ixgbe_sw_init(adapter);
7331 /* Make it possible the adapter to be woken up via WOL */
7332 switch (adapter->hw.mac.type) {
7333 case ixgbe_mac_82599EB:
7334 case ixgbe_mac_X540:
7335 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
7342 * If there is a fan on this device and it has failed log the
7345 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7346 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7347 if (esdp & IXGBE_ESDP_SDP1)
7348 e_crit(probe, "Fan has stopped, replace the adapter\n");
7351 if (allow_unsupported_sfp)
7352 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7354 /* reset_hw fills in the perm_addr as well */
7355 hw->phy.reset_if_overtemp = true;
7356 err = hw->mac.ops.reset_hw(hw);
7357 hw->phy.reset_if_overtemp = false;
7358 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7359 hw->mac.type == ixgbe_mac_82598EB) {
7361 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
7362 e_dev_err("failed to load because an unsupported SFP+ "
7363 "module type was detected.\n");
7364 e_dev_err("Reload the driver after installing a supported "
7368 e_dev_err("HW Init failed: %d\n", err);
7372 #ifdef CONFIG_PCI_IOV
7373 ixgbe_enable_sriov(adapter, ii);
7376 netdev->features = NETIF_F_SG |
7379 NETIF_F_HW_VLAN_TX |
7380 NETIF_F_HW_VLAN_RX |
7381 NETIF_F_HW_VLAN_FILTER |
7387 netdev->hw_features = netdev->features;
7389 switch (adapter->hw.mac.type) {
7390 case ixgbe_mac_82599EB:
7391 case ixgbe_mac_X540:
7392 netdev->features |= NETIF_F_SCTP_CSUM;
7393 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7400 netdev->hw_features |= NETIF_F_RXALL;
7402 netdev->vlan_features |= NETIF_F_TSO;
7403 netdev->vlan_features |= NETIF_F_TSO6;
7404 netdev->vlan_features |= NETIF_F_IP_CSUM;
7405 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
7406 netdev->vlan_features |= NETIF_F_SG;
7408 netdev->priv_flags |= IFF_UNICAST_FLT;
7409 netdev->priv_flags |= IFF_SUPP_NOFCS;
7411 #ifdef CONFIG_IXGBE_DCB
7412 netdev->dcbnl_ops = &dcbnl_ops;
7416 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7417 if (hw->mac.ops.get_device_caps) {
7418 hw->mac.ops.get_device_caps(hw, &device_caps);
7419 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7420 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
7423 adapter->ring_feature[RING_F_FCOE].limit = IXGBE_FCRETA_SIZE;
7425 netdev->features |= NETIF_F_FSO |
7428 netdev->vlan_features |= NETIF_F_FSO |
7432 #endif /* IXGBE_FCOE */
7433 if (pci_using_dac) {
7434 netdev->features |= NETIF_F_HIGHDMA;
7435 netdev->vlan_features |= NETIF_F_HIGHDMA;
7438 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7439 netdev->hw_features |= NETIF_F_LRO;
7440 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
7441 netdev->features |= NETIF_F_LRO;
7443 /* make sure the EEPROM is good */
7444 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
7445 e_dev_err("The EEPROM Checksum Is Not Valid\n");
7450 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7451 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7453 if (!is_valid_ether_addr(netdev->perm_addr)) {
7454 e_dev_err("invalid MAC address\n");
7459 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7460 (unsigned long) adapter);
7462 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7463 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
7465 err = ixgbe_init_interrupt_scheme(adapter);
7469 /* WOL not supported for all devices */
7471 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7472 if (ixgbe_wol_supported(adapter, pdev->device, pdev->subsystem_device))
7473 adapter->wol = IXGBE_WUFC_MAG;
7475 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7477 /* save off EEPROM version number */
7478 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7479 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7481 /* pick up the PCI bus settings for reporting later */
7482 hw->mac.ops.get_bus_info(hw);
7484 /* print bus type/speed/width info */
7485 e_dev_info("(PCI Express:%s:%s) %pM\n",
7486 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7487 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
7489 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7490 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7491 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7495 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7497 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
7498 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
7499 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
7500 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
7503 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7504 hw->mac.type, hw->phy.type, part_str);
7506 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
7507 e_dev_warn("PCI-Express bandwidth available for this card is "
7508 "not sufficient for optimal performance.\n");
7509 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7513 /* reset the hardware with the new settings */
7514 err = hw->mac.ops.start_hw(hw);
7515 if (err == IXGBE_ERR_EEPROM_VERSION) {
7516 /* We are running on a pre-production device, log a warning */
7517 e_dev_warn("This device is a pre-production adapter/LOM. "
7518 "Please be aware there may be issues associated "
7519 "with your hardware. If you are experiencing "
7520 "problems please contact your Intel or hardware "
7521 "representative who provided you with this "
7524 strcpy(netdev->name, "eth%d");
7525 err = register_netdev(netdev);
7529 /* power down the optics for 82599 SFP+ fiber */
7530 if (hw->mac.ops.disable_tx_laser)
7531 hw->mac.ops.disable_tx_laser(hw);
7533 /* carrier off reporting is important to ethtool even BEFORE open */
7534 netif_carrier_off(netdev);
7536 #ifdef CONFIG_IXGBE_DCA
7537 if (dca_add_requester(&pdev->dev) == 0) {
7538 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
7539 ixgbe_setup_dca(adapter);
7542 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7543 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
7544 for (i = 0; i < adapter->num_vfs; i++)
7545 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7548 /* firmware requires driver version to be 0xFFFFFFFF
7549 * since os does not support feature
7551 if (hw->mac.ops.set_fw_drv_ver)
7552 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7555 /* add san mac addr to netdev */
7556 ixgbe_add_sanmac_netdev(netdev);
7558 e_dev_info("%s\n", ixgbe_default_device_descr);
7561 #ifdef CONFIG_IXGBE_HWMON
7562 if (ixgbe_sysfs_init(adapter))
7563 e_err(probe, "failed to allocate sysfs resources\n");
7564 #endif /* CONFIG_IXGBE_HWMON */
7566 #ifdef CONFIG_DEBUG_FS
7567 ixgbe_dbg_adapter_init(adapter);
7568 #endif /* CONFIG_DEBUG_FS */
7573 ixgbe_release_hw_control(adapter);
7574 ixgbe_clear_interrupt_scheme(adapter);
7576 ixgbe_disable_sriov(adapter);
7577 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
7578 iounmap(hw->hw_addr);
7580 free_netdev(netdev);
7582 pci_release_selected_regions(pdev,
7583 pci_select_bars(pdev, IORESOURCE_MEM));
7586 pci_disable_device(pdev);
7591 * ixgbe_remove - Device Removal Routine
7592 * @pdev: PCI device information struct
7594 * ixgbe_remove is called by the PCI subsystem to alert the driver
7595 * that it should release a PCI device. The could be caused by a
7596 * Hot-Plug event, or because the driver is going to be removed from
7599 static void ixgbe_remove(struct pci_dev *pdev)
7601 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7602 struct net_device *netdev = adapter->netdev;
7604 #ifdef CONFIG_DEBUG_FS
7605 ixgbe_dbg_adapter_exit(adapter);
7606 #endif /*CONFIG_DEBUG_FS */
7608 set_bit(__IXGBE_DOWN, &adapter->state);
7609 cancel_work_sync(&adapter->service_task);
7612 #ifdef CONFIG_IXGBE_DCA
7613 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7614 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7615 dca_remove_requester(&pdev->dev);
7616 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7620 #ifdef CONFIG_IXGBE_HWMON
7621 ixgbe_sysfs_exit(adapter);
7622 #endif /* CONFIG_IXGBE_HWMON */
7624 /* remove the added san mac */
7625 ixgbe_del_sanmac_netdev(netdev);
7627 if (netdev->reg_state == NETREG_REGISTERED)
7628 unregister_netdev(netdev);
7630 ixgbe_disable_sriov(adapter);
7632 ixgbe_clear_interrupt_scheme(adapter);
7634 ixgbe_release_hw_control(adapter);
7637 kfree(adapter->ixgbe_ieee_pfc);
7638 kfree(adapter->ixgbe_ieee_ets);
7641 iounmap(adapter->hw.hw_addr);
7642 pci_release_selected_regions(pdev, pci_select_bars(pdev,
7645 e_dev_info("complete\n");
7647 free_netdev(netdev);
7649 pci_disable_pcie_error_reporting(pdev);
7651 pci_disable_device(pdev);
7655 * ixgbe_io_error_detected - called when PCI error is detected
7656 * @pdev: Pointer to PCI device
7657 * @state: The current pci connection state
7659 * This function is called after a PCI bus error affecting
7660 * this device has been detected.
7662 static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
7663 pci_channel_state_t state)
7665 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7666 struct net_device *netdev = adapter->netdev;
7668 #ifdef CONFIG_PCI_IOV
7669 struct pci_dev *bdev, *vfdev;
7670 u32 dw0, dw1, dw2, dw3;
7672 u16 req_id, pf_func;
7674 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7675 adapter->num_vfs == 0)
7676 goto skip_bad_vf_detection;
7678 bdev = pdev->bus->self;
7679 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
7680 bdev = bdev->bus->self;
7683 goto skip_bad_vf_detection;
7685 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
7687 goto skip_bad_vf_detection;
7689 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
7690 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
7691 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
7692 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
7695 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
7696 if (!(req_id & 0x0080))
7697 goto skip_bad_vf_detection;
7699 pf_func = req_id & 0x01;
7700 if ((pf_func & 1) == (pdev->devfn & 1)) {
7701 unsigned int device_id;
7703 vf = (req_id & 0x7F) >> 1;
7704 e_dev_err("VF %d has caused a PCIe error\n", vf);
7705 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
7706 "%8.8x\tdw3: %8.8x\n",
7707 dw0, dw1, dw2, dw3);
7708 switch (adapter->hw.mac.type) {
7709 case ixgbe_mac_82599EB:
7710 device_id = IXGBE_82599_VF_DEVICE_ID;
7712 case ixgbe_mac_X540:
7713 device_id = IXGBE_X540_VF_DEVICE_ID;
7720 /* Find the pci device of the offending VF */
7721 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
7723 if (vfdev->devfn == (req_id & 0xFF))
7725 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
7729 * There's a slim chance the VF could have been hot plugged,
7730 * so if it is no longer present we don't need to issue the
7731 * VFLR. Just clean up the AER in that case.
7734 e_dev_err("Issuing VFLR to VF %d\n", vf);
7735 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
7738 pci_cleanup_aer_uncorrect_error_status(pdev);
7742 * Even though the error may have occurred on the other port
7743 * we still need to increment the vf error reference count for
7744 * both ports because the I/O resume function will be called
7747 adapter->vferr_refcount++;
7749 return PCI_ERS_RESULT_RECOVERED;
7751 skip_bad_vf_detection:
7752 #endif /* CONFIG_PCI_IOV */
7753 netif_device_detach(netdev);
7755 if (state == pci_channel_io_perm_failure)
7756 return PCI_ERS_RESULT_DISCONNECT;
7758 if (netif_running(netdev))
7759 ixgbe_down(adapter);
7760 pci_disable_device(pdev);
7762 /* Request a slot reset. */
7763 return PCI_ERS_RESULT_NEED_RESET;
7767 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7768 * @pdev: Pointer to PCI device
7770 * Restart the card from scratch, as if from a cold-boot.
7772 static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7774 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7775 pci_ers_result_t result;
7778 if (pci_enable_device_mem(pdev)) {
7779 e_err(probe, "Cannot re-enable PCI device after reset.\n");
7780 result = PCI_ERS_RESULT_DISCONNECT;
7782 pci_set_master(pdev);
7783 pci_restore_state(pdev);
7784 pci_save_state(pdev);
7786 pci_wake_from_d3(pdev, false);
7788 ixgbe_reset(adapter);
7789 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
7790 result = PCI_ERS_RESULT_RECOVERED;
7793 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7795 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7796 "failed 0x%0x\n", err);
7797 /* non-fatal, continue */
7804 * ixgbe_io_resume - called when traffic can start flowing again.
7805 * @pdev: Pointer to PCI device
7807 * This callback is called when the error recovery driver tells us that
7808 * its OK to resume normal operation.
7810 static void ixgbe_io_resume(struct pci_dev *pdev)
7812 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7813 struct net_device *netdev = adapter->netdev;
7815 #ifdef CONFIG_PCI_IOV
7816 if (adapter->vferr_refcount) {
7817 e_info(drv, "Resuming after VF err\n");
7818 adapter->vferr_refcount--;
7823 if (netif_running(netdev))
7826 netif_device_attach(netdev);
7829 static const struct pci_error_handlers ixgbe_err_handler = {
7830 .error_detected = ixgbe_io_error_detected,
7831 .slot_reset = ixgbe_io_slot_reset,
7832 .resume = ixgbe_io_resume,
7835 static struct pci_driver ixgbe_driver = {
7836 .name = ixgbe_driver_name,
7837 .id_table = ixgbe_pci_tbl,
7838 .probe = ixgbe_probe,
7839 .remove = ixgbe_remove,
7841 .suspend = ixgbe_suspend,
7842 .resume = ixgbe_resume,
7844 .shutdown = ixgbe_shutdown,
7845 .err_handler = &ixgbe_err_handler
7849 * ixgbe_init_module - Driver Registration Routine
7851 * ixgbe_init_module is the first routine called when the driver is
7852 * loaded. All it does is register with the PCI subsystem.
7854 static int __init ixgbe_init_module(void)
7857 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
7858 pr_info("%s\n", ixgbe_copyright);
7860 #ifdef CONFIG_DEBUG_FS
7862 #endif /* CONFIG_DEBUG_FS */
7864 #ifdef CONFIG_IXGBE_DCA
7865 dca_register_notify(&dca_notifier);
7868 ret = pci_register_driver(&ixgbe_driver);
7872 module_init(ixgbe_init_module);
7875 * ixgbe_exit_module - Driver Exit Cleanup Routine
7877 * ixgbe_exit_module is called just before the driver is removed
7880 static void __exit ixgbe_exit_module(void)
7882 #ifdef CONFIG_IXGBE_DCA
7883 dca_unregister_notify(&dca_notifier);
7885 pci_unregister_driver(&ixgbe_driver);
7887 #ifdef CONFIG_DEBUG_FS
7889 #endif /* CONFIG_DEBUG_FS */
7891 rcu_barrier(); /* Wait for completion of call_rcu()'s */
7894 #ifdef CONFIG_IXGBE_DCA
7895 static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
7900 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
7901 __ixgbe_notify_dca);
7903 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7906 #endif /* CONFIG_IXGBE_DCA */
7908 module_exit(ixgbe_exit_module);