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";
69 #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
70 __stringify(BUILD) "-k"
71 const char ixgbe_driver_version[] = DRV_VERSION;
72 static const char ixgbe_copyright[] =
73 "Copyright (c) 1999-2012 Intel Corporation.";
75 static const struct ixgbe_info *ixgbe_info_tbl[] = {
76 [board_82598] = &ixgbe_82598_info,
77 [board_82599] = &ixgbe_82599_info,
78 [board_X540] = &ixgbe_X540_info,
81 /* ixgbe_pci_tbl - PCI Device ID Table
83 * Wildcard entries (PCI_ANY_ID) should come last
84 * Last entry must be all 0s
86 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
87 * Class, Class Mask, private data (not used) }
89 static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
118 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
119 /* required last entry */
122 MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
124 #ifdef CONFIG_IXGBE_DCA
125 static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
127 static struct notifier_block dca_notifier = {
128 .notifier_call = ixgbe_notify_dca,
134 #ifdef CONFIG_PCI_IOV
135 static unsigned int max_vfs;
136 module_param(max_vfs, uint, 0);
137 MODULE_PARM_DESC(max_vfs,
138 "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63");
139 #endif /* CONFIG_PCI_IOV */
141 static unsigned int allow_unsupported_sfp;
142 module_param(allow_unsupported_sfp, uint, 0);
143 MODULE_PARM_DESC(allow_unsupported_sfp,
144 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
146 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
147 static int debug = -1;
148 module_param(debug, int, 0);
149 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
151 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
152 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
153 MODULE_LICENSE("GPL");
154 MODULE_VERSION(DRV_VERSION);
156 static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
158 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
159 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
160 schedule_work(&adapter->service_task);
163 static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
165 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
167 /* flush memory to make sure state is correct before next watchdog */
168 smp_mb__before_clear_bit();
169 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
172 struct ixgbe_reg_info {
177 static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
179 /* General Registers */
180 {IXGBE_CTRL, "CTRL"},
181 {IXGBE_STATUS, "STATUS"},
182 {IXGBE_CTRL_EXT, "CTRL_EXT"},
184 /* Interrupt Registers */
185 {IXGBE_EICR, "EICR"},
188 {IXGBE_SRRCTL(0), "SRRCTL"},
189 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
190 {IXGBE_RDLEN(0), "RDLEN"},
191 {IXGBE_RDH(0), "RDH"},
192 {IXGBE_RDT(0), "RDT"},
193 {IXGBE_RXDCTL(0), "RXDCTL"},
194 {IXGBE_RDBAL(0), "RDBAL"},
195 {IXGBE_RDBAH(0), "RDBAH"},
198 {IXGBE_TDBAL(0), "TDBAL"},
199 {IXGBE_TDBAH(0), "TDBAH"},
200 {IXGBE_TDLEN(0), "TDLEN"},
201 {IXGBE_TDH(0), "TDH"},
202 {IXGBE_TDT(0), "TDT"},
203 {IXGBE_TXDCTL(0), "TXDCTL"},
205 /* List Terminator */
211 * ixgbe_regdump - register printout routine
213 static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
219 switch (reginfo->ofs) {
220 case IXGBE_SRRCTL(0):
221 for (i = 0; i < 64; i++)
222 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
224 case IXGBE_DCA_RXCTRL(0):
225 for (i = 0; i < 64; i++)
226 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
229 for (i = 0; i < 64; i++)
230 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
233 for (i = 0; i < 64; i++)
234 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
237 for (i = 0; i < 64; i++)
238 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
240 case IXGBE_RXDCTL(0):
241 for (i = 0; i < 64; i++)
242 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
245 for (i = 0; i < 64; i++)
246 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
249 for (i = 0; i < 64; i++)
250 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
253 for (i = 0; i < 64; i++)
254 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
257 for (i = 0; i < 64; i++)
258 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
261 for (i = 0; i < 64; i++)
262 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
265 for (i = 0; i < 64; i++)
266 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
269 for (i = 0; i < 64; i++)
270 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
272 case IXGBE_TXDCTL(0):
273 for (i = 0; i < 64; i++)
274 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
277 pr_info("%-15s %08x\n", reginfo->name,
278 IXGBE_READ_REG(hw, reginfo->ofs));
282 for (i = 0; i < 8; i++) {
283 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
284 pr_err("%-15s", rname);
285 for (j = 0; j < 8; j++)
286 pr_cont(" %08x", regs[i*8+j]);
293 * ixgbe_dump - Print registers, tx-rings and rx-rings
295 static void ixgbe_dump(struct ixgbe_adapter *adapter)
297 struct net_device *netdev = adapter->netdev;
298 struct ixgbe_hw *hw = &adapter->hw;
299 struct ixgbe_reg_info *reginfo;
301 struct ixgbe_ring *tx_ring;
302 struct ixgbe_tx_buffer *tx_buffer;
303 union ixgbe_adv_tx_desc *tx_desc;
304 struct my_u0 { u64 a; u64 b; } *u0;
305 struct ixgbe_ring *rx_ring;
306 union ixgbe_adv_rx_desc *rx_desc;
307 struct ixgbe_rx_buffer *rx_buffer_info;
311 if (!netif_msg_hw(adapter))
314 /* Print netdevice Info */
316 dev_info(&adapter->pdev->dev, "Net device Info\n");
317 pr_info("Device Name state "
318 "trans_start last_rx\n");
319 pr_info("%-15s %016lX %016lX %016lX\n",
326 /* Print Registers */
327 dev_info(&adapter->pdev->dev, "Register Dump\n");
328 pr_info(" Register Name Value\n");
329 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
330 reginfo->name; reginfo++) {
331 ixgbe_regdump(hw, reginfo);
334 /* Print TX Ring Summary */
335 if (!netdev || !netif_running(netdev))
338 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
339 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
340 for (n = 0; n < adapter->num_tx_queues; n++) {
341 tx_ring = adapter->tx_ring[n];
342 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
343 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
344 n, tx_ring->next_to_use, tx_ring->next_to_clean,
345 (u64)dma_unmap_addr(tx_buffer, dma),
346 dma_unmap_len(tx_buffer, len),
347 tx_buffer->next_to_watch,
348 (u64)tx_buffer->time_stamp);
352 if (!netif_msg_tx_done(adapter))
353 goto rx_ring_summary;
355 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
357 /* Transmit Descriptor Formats
359 * 82598 Advanced Transmit Descriptor
360 * +--------------------------------------------------------------+
361 * 0 | Buffer Address [63:0] |
362 * +--------------------------------------------------------------+
363 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
364 * +--------------------------------------------------------------+
365 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
367 * 82598 Advanced Transmit Descriptor (Write-Back Format)
368 * +--------------------------------------------------------------+
370 * +--------------------------------------------------------------+
371 * 8 | RSV | STA | NXTSEQ |
372 * +--------------------------------------------------------------+
375 * 82599+ Advanced Transmit Descriptor
376 * +--------------------------------------------------------------+
377 * 0 | Buffer Address [63:0] |
378 * +--------------------------------------------------------------+
379 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
380 * +--------------------------------------------------------------+
381 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
383 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
384 * +--------------------------------------------------------------+
386 * +--------------------------------------------------------------+
387 * 8 | RSV | STA | RSV |
388 * +--------------------------------------------------------------+
392 for (n = 0; n < adapter->num_tx_queues; n++) {
393 tx_ring = adapter->tx_ring[n];
394 pr_info("------------------------------------\n");
395 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
396 pr_info("------------------------------------\n");
397 pr_info("T [desc] [address 63:0 ] "
398 "[PlPOIdStDDt Ln] [bi->dma ] "
399 "leng ntw timestamp bi->skb\n");
401 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
402 tx_desc = IXGBE_TX_DESC(tx_ring, i);
403 tx_buffer = &tx_ring->tx_buffer_info[i];
404 u0 = (struct my_u0 *)tx_desc;
405 pr_info("T [0x%03X] %016llX %016llX %016llX"
406 " %04X %p %016llX %p", i,
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),
434 /* Print RX Rings Summary */
436 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
437 pr_info("Queue [NTU] [NTC]\n");
438 for (n = 0; n < adapter->num_rx_queues; n++) {
439 rx_ring = adapter->rx_ring[n];
440 pr_info("%5d %5X %5X\n",
441 n, rx_ring->next_to_use, rx_ring->next_to_clean);
445 if (!netif_msg_rx_status(adapter))
448 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
450 /* Receive Descriptor Formats
452 * 82598 Advanced Receive Descriptor (Read) Format
454 * +-----------------------------------------------------+
455 * 0 | Packet Buffer Address [63:1] |A0/NSE|
456 * +----------------------------------------------+------+
457 * 8 | Header Buffer Address [63:1] | DD |
458 * +-----------------------------------------------------+
461 * 82598 Advanced Receive Descriptor (Write-Back) Format
463 * 63 48 47 32 31 30 21 20 16 15 4 3 0
464 * +------------------------------------------------------+
465 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
466 * | Packet | IP | | | | Type | Type |
467 * | Checksum | Ident | | | | | |
468 * +------------------------------------------------------+
469 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
470 * +------------------------------------------------------+
471 * 63 48 47 32 31 20 19 0
473 * 82599+ Advanced Receive Descriptor (Read) Format
475 * +-----------------------------------------------------+
476 * 0 | Packet Buffer Address [63:1] |A0/NSE|
477 * +----------------------------------------------+------+
478 * 8 | Header Buffer Address [63:1] | DD |
479 * +-----------------------------------------------------+
482 * 82599+ Advanced Receive Descriptor (Write-Back) Format
484 * 63 48 47 32 31 30 21 20 17 16 4 3 0
485 * +------------------------------------------------------+
486 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
487 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
488 * |/ Flow Dir Flt ID | | | | | |
489 * +------------------------------------------------------+
490 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
491 * +------------------------------------------------------+
492 * 63 48 47 32 31 20 19 0
495 for (n = 0; n < adapter->num_rx_queues; n++) {
496 rx_ring = adapter->rx_ring[n];
497 pr_info("------------------------------------\n");
498 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
499 pr_info("------------------------------------\n");
500 pr_info("R [desc] [ PktBuf A0] "
501 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
502 "<-- Adv Rx Read format\n");
503 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
504 "[vl er S cks ln] ---------------- [bi->skb] "
505 "<-- Adv Rx Write-Back format\n");
507 for (i = 0; i < rx_ring->count; i++) {
508 rx_buffer_info = &rx_ring->rx_buffer_info[i];
509 rx_desc = IXGBE_RX_DESC(rx_ring, i);
510 u0 = (struct my_u0 *)rx_desc;
511 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
512 if (staterr & IXGBE_RXD_STAT_DD) {
513 /* Descriptor Done */
514 pr_info("RWB[0x%03X] %016llX "
515 "%016llX ---------------- %p", i,
518 rx_buffer_info->skb);
520 pr_info("R [0x%03X] %016llX "
521 "%016llX %016llX %p", i,
524 (u64)rx_buffer_info->dma,
525 rx_buffer_info->skb);
527 if (netif_msg_pktdata(adapter) &&
528 rx_buffer_info->dma) {
529 print_hex_dump(KERN_INFO, "",
530 DUMP_PREFIX_ADDRESS, 16, 1,
531 page_address(rx_buffer_info->page) +
532 rx_buffer_info->page_offset,
533 ixgbe_rx_bufsz(rx_ring), true);
537 if (i == rx_ring->next_to_use)
539 else if (i == rx_ring->next_to_clean)
551 static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
555 /* Let firmware take over control of h/w */
556 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
557 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
558 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
561 static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
565 /* Let firmware know the driver has taken over */
566 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
567 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
568 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
572 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
573 * @adapter: pointer to adapter struct
574 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
575 * @queue: queue to map the corresponding interrupt to
576 * @msix_vector: the vector to map to the corresponding queue
579 static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
580 u8 queue, u8 msix_vector)
583 struct ixgbe_hw *hw = &adapter->hw;
584 switch (hw->mac.type) {
585 case ixgbe_mac_82598EB:
586 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
589 index = (((direction * 64) + queue) >> 2) & 0x1F;
590 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
591 ivar &= ~(0xFF << (8 * (queue & 0x3)));
592 ivar |= (msix_vector << (8 * (queue & 0x3)));
593 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
595 case ixgbe_mac_82599EB:
597 if (direction == -1) {
599 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
600 index = ((queue & 1) * 8);
601 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
602 ivar &= ~(0xFF << index);
603 ivar |= (msix_vector << index);
604 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
607 /* tx or rx causes */
608 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
609 index = ((16 * (queue & 1)) + (8 * direction));
610 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
611 ivar &= ~(0xFF << index);
612 ivar |= (msix_vector << index);
613 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
621 static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
626 switch (adapter->hw.mac.type) {
627 case ixgbe_mac_82598EB:
628 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
629 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
631 case ixgbe_mac_82599EB:
633 mask = (qmask & 0xFFFFFFFF);
634 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
635 mask = (qmask >> 32);
636 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
643 void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
644 struct ixgbe_tx_buffer *tx_buffer)
646 if (tx_buffer->skb) {
647 dev_kfree_skb_any(tx_buffer->skb);
648 if (dma_unmap_len(tx_buffer, len))
649 dma_unmap_single(ring->dev,
650 dma_unmap_addr(tx_buffer, dma),
651 dma_unmap_len(tx_buffer, len),
653 } else if (dma_unmap_len(tx_buffer, len)) {
654 dma_unmap_page(ring->dev,
655 dma_unmap_addr(tx_buffer, dma),
656 dma_unmap_len(tx_buffer, len),
659 tx_buffer->next_to_watch = NULL;
660 tx_buffer->skb = NULL;
661 dma_unmap_len_set(tx_buffer, len, 0);
662 /* tx_buffer must be completely set up in the transmit path */
665 static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
667 struct ixgbe_hw *hw = &adapter->hw;
668 struct ixgbe_hw_stats *hwstats = &adapter->stats;
672 if ((hw->fc.current_mode != ixgbe_fc_full) &&
673 (hw->fc.current_mode != ixgbe_fc_rx_pause))
676 switch (hw->mac.type) {
677 case ixgbe_mac_82598EB:
678 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
681 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
683 hwstats->lxoffrxc += data;
685 /* refill credits (no tx hang) if we received xoff */
689 for (i = 0; i < adapter->num_tx_queues; i++)
690 clear_bit(__IXGBE_HANG_CHECK_ARMED,
691 &adapter->tx_ring[i]->state);
694 static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
696 struct ixgbe_hw *hw = &adapter->hw;
697 struct ixgbe_hw_stats *hwstats = &adapter->stats;
700 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
702 if (adapter->ixgbe_ieee_pfc)
703 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
705 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
706 ixgbe_update_xoff_rx_lfc(adapter);
710 /* update stats for each tc, only valid with PFC enabled */
711 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
712 switch (hw->mac.type) {
713 case ixgbe_mac_82598EB:
714 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
717 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
719 hwstats->pxoffrxc[i] += xoff[i];
722 /* disarm tx queues that have received xoff frames */
723 for (i = 0; i < adapter->num_tx_queues; i++) {
724 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
725 u8 tc = tx_ring->dcb_tc;
728 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
732 static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
734 return ring->stats.packets;
737 static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
739 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
740 struct ixgbe_hw *hw = &adapter->hw;
742 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
743 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
746 return (head < tail) ?
747 tail - head : (tail + ring->count - head);
752 static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
754 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
755 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
756 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
759 clear_check_for_tx_hang(tx_ring);
762 * Check for a hung queue, but be thorough. This verifies
763 * that a transmit has been completed since the previous
764 * check AND there is at least one packet pending. The
765 * ARMED bit is set to indicate a potential hang. The
766 * bit is cleared if a pause frame is received to remove
767 * false hang detection due to PFC or 802.3x frames. By
768 * requiring this to fail twice we avoid races with
769 * pfc clearing the ARMED bit and conditions where we
770 * run the check_tx_hang logic with a transmit completion
771 * pending but without time to complete it yet.
773 if ((tx_done_old == tx_done) && tx_pending) {
774 /* make sure it is true for two checks in a row */
775 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
778 /* update completed stats and continue */
779 tx_ring->tx_stats.tx_done_old = tx_done;
780 /* reset the countdown */
781 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
788 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
789 * @adapter: driver private struct
791 static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
794 /* Do the reset outside of interrupt context */
795 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
796 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
797 ixgbe_service_event_schedule(adapter);
802 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
803 * @q_vector: structure containing interrupt and ring information
804 * @tx_ring: tx ring to clean
806 static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
807 struct ixgbe_ring *tx_ring)
809 struct ixgbe_adapter *adapter = q_vector->adapter;
810 struct ixgbe_tx_buffer *tx_buffer;
811 union ixgbe_adv_tx_desc *tx_desc;
812 unsigned int total_bytes = 0, total_packets = 0;
813 unsigned int budget = q_vector->tx.work_limit;
814 unsigned int i = tx_ring->next_to_clean;
816 if (test_bit(__IXGBE_DOWN, &adapter->state))
819 tx_buffer = &tx_ring->tx_buffer_info[i];
820 tx_desc = IXGBE_TX_DESC(tx_ring, i);
824 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
826 /* if next_to_watch is not set then there is no work pending */
830 /* prevent any other reads prior to eop_desc */
833 /* if DD is not set pending work has not been completed */
834 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
837 /* clear next_to_watch to prevent false hangs */
838 tx_buffer->next_to_watch = NULL;
840 /* update the statistics for this packet */
841 total_bytes += tx_buffer->bytecount;
842 total_packets += tx_buffer->gso_segs;
844 if (unlikely(tx_buffer->tx_flags & IXGBE_TX_FLAGS_TSTAMP))
845 ixgbe_ptp_tx_hwtstamp(q_vector, tx_buffer->skb);
848 dev_kfree_skb_any(tx_buffer->skb);
850 /* unmap skb header data */
851 dma_unmap_single(tx_ring->dev,
852 dma_unmap_addr(tx_buffer, dma),
853 dma_unmap_len(tx_buffer, len),
856 /* clear tx_buffer data */
857 tx_buffer->skb = NULL;
858 dma_unmap_len_set(tx_buffer, len, 0);
860 /* unmap remaining buffers */
861 while (tx_desc != eop_desc) {
867 tx_buffer = tx_ring->tx_buffer_info;
868 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
871 /* unmap any remaining paged data */
872 if (dma_unmap_len(tx_buffer, len)) {
873 dma_unmap_page(tx_ring->dev,
874 dma_unmap_addr(tx_buffer, dma),
875 dma_unmap_len(tx_buffer, len),
877 dma_unmap_len_set(tx_buffer, len, 0);
881 /* move us one more past the eop_desc for start of next pkt */
887 tx_buffer = tx_ring->tx_buffer_info;
888 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
891 /* issue prefetch for next Tx descriptor */
894 /* update budget accounting */
896 } while (likely(budget));
899 tx_ring->next_to_clean = i;
900 u64_stats_update_begin(&tx_ring->syncp);
901 tx_ring->stats.bytes += total_bytes;
902 tx_ring->stats.packets += total_packets;
903 u64_stats_update_end(&tx_ring->syncp);
904 q_vector->tx.total_bytes += total_bytes;
905 q_vector->tx.total_packets += total_packets;
907 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
908 /* schedule immediate reset if we believe we hung */
909 struct ixgbe_hw *hw = &adapter->hw;
910 e_err(drv, "Detected Tx Unit Hang\n"
912 " TDH, TDT <%x>, <%x>\n"
913 " next_to_use <%x>\n"
914 " next_to_clean <%x>\n"
915 "tx_buffer_info[next_to_clean]\n"
916 " time_stamp <%lx>\n"
918 tx_ring->queue_index,
919 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
920 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
921 tx_ring->next_to_use, i,
922 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
924 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
927 "tx hang %d detected on queue %d, resetting adapter\n",
928 adapter->tx_timeout_count + 1, tx_ring->queue_index);
930 /* schedule immediate reset if we believe we hung */
931 ixgbe_tx_timeout_reset(adapter);
933 /* the adapter is about to reset, no point in enabling stuff */
937 netdev_tx_completed_queue(txring_txq(tx_ring),
938 total_packets, total_bytes);
940 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
941 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
942 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
943 /* Make sure that anybody stopping the queue after this
944 * sees the new next_to_clean.
947 if (__netif_subqueue_stopped(tx_ring->netdev,
948 tx_ring->queue_index)
949 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
950 netif_wake_subqueue(tx_ring->netdev,
951 tx_ring->queue_index);
952 ++tx_ring->tx_stats.restart_queue;
959 #ifdef CONFIG_IXGBE_DCA
960 static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
961 struct ixgbe_ring *tx_ring,
964 struct ixgbe_hw *hw = &adapter->hw;
965 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
968 switch (hw->mac.type) {
969 case ixgbe_mac_82598EB:
970 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
972 case ixgbe_mac_82599EB:
974 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
975 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
978 /* for unknown hardware do not write register */
983 * We can enable relaxed ordering for reads, but not writes when
984 * DCA is enabled. This is due to a known issue in some chipsets
985 * which will cause the DCA tag to be cleared.
987 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
988 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
989 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
991 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
994 static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
995 struct ixgbe_ring *rx_ring,
998 struct ixgbe_hw *hw = &adapter->hw;
999 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
1000 u8 reg_idx = rx_ring->reg_idx;
1003 switch (hw->mac.type) {
1004 case ixgbe_mac_82599EB:
1005 case ixgbe_mac_X540:
1006 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
1013 * We can enable relaxed ordering for reads, but not writes when
1014 * DCA is enabled. This is due to a known issue in some chipsets
1015 * which will cause the DCA tag to be cleared.
1017 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
1018 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
1019 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1021 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
1024 static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1026 struct ixgbe_adapter *adapter = q_vector->adapter;
1027 struct ixgbe_ring *ring;
1028 int cpu = get_cpu();
1030 if (q_vector->cpu == cpu)
1033 ixgbe_for_each_ring(ring, q_vector->tx)
1034 ixgbe_update_tx_dca(adapter, ring, cpu);
1036 ixgbe_for_each_ring(ring, q_vector->rx)
1037 ixgbe_update_rx_dca(adapter, ring, cpu);
1039 q_vector->cpu = cpu;
1044 static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1048 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1051 /* always use CB2 mode, difference is masked in the CB driver */
1052 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1054 for (i = 0; i < adapter->num_q_vectors; i++) {
1055 adapter->q_vector[i]->cpu = -1;
1056 ixgbe_update_dca(adapter->q_vector[i]);
1060 static int __ixgbe_notify_dca(struct device *dev, void *data)
1062 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
1063 unsigned long event = *(unsigned long *)data;
1065 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
1069 case DCA_PROVIDER_ADD:
1070 /* if we're already enabled, don't do it again */
1071 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1073 if (dca_add_requester(dev) == 0) {
1074 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
1075 ixgbe_setup_dca(adapter);
1078 /* Fall Through since DCA is disabled. */
1079 case DCA_PROVIDER_REMOVE:
1080 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1081 dca_remove_requester(dev);
1082 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1083 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1091 #endif /* CONFIG_IXGBE_DCA */
1092 static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1093 union ixgbe_adv_rx_desc *rx_desc,
1094 struct sk_buff *skb)
1096 if (ring->netdev->features & NETIF_F_RXHASH)
1097 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
1102 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1103 * @ring: structure containing ring specific data
1104 * @rx_desc: advanced rx descriptor
1106 * Returns : true if it is FCoE pkt
1108 static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
1109 union ixgbe_adv_rx_desc *rx_desc)
1111 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1113 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
1114 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1115 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1116 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1119 #endif /* IXGBE_FCOE */
1121 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1122 * @ring: structure containing ring specific data
1123 * @rx_desc: current Rx descriptor being processed
1124 * @skb: skb currently being received and modified
1126 static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
1127 union ixgbe_adv_rx_desc *rx_desc,
1128 struct sk_buff *skb)
1130 skb_checksum_none_assert(skb);
1132 /* Rx csum disabled */
1133 if (!(ring->netdev->features & NETIF_F_RXCSUM))
1136 /* if IP and error */
1137 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1138 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
1139 ring->rx_stats.csum_err++;
1143 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
1146 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
1147 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1150 * 82599 errata, UDP frames with a 0 checksum can be marked as
1153 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1154 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
1157 ring->rx_stats.csum_err++;
1161 /* It must be a TCP or UDP packet with a valid checksum */
1162 skb->ip_summed = CHECKSUM_UNNECESSARY;
1165 static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
1167 rx_ring->next_to_use = val;
1169 /* update next to alloc since we have filled the ring */
1170 rx_ring->next_to_alloc = val;
1172 * Force memory writes to complete before letting h/w
1173 * know there are new descriptors to fetch. (Only
1174 * applicable for weak-ordered memory model archs,
1178 writel(val, rx_ring->tail);
1181 static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1182 struct ixgbe_rx_buffer *bi)
1184 struct page *page = bi->page;
1185 dma_addr_t dma = bi->dma;
1187 /* since we are recycling buffers we should seldom need to alloc */
1191 /* alloc new page for storage */
1192 if (likely(!page)) {
1193 page = __skb_alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP,
1194 bi->skb, ixgbe_rx_pg_order(rx_ring));
1195 if (unlikely(!page)) {
1196 rx_ring->rx_stats.alloc_rx_page_failed++;
1202 /* map page for use */
1203 dma = dma_map_page(rx_ring->dev, page, 0,
1204 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1207 * if mapping failed free memory back to system since
1208 * there isn't much point in holding memory we can't use
1210 if (dma_mapping_error(rx_ring->dev, dma)) {
1211 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
1214 rx_ring->rx_stats.alloc_rx_page_failed++;
1219 bi->page_offset = 0;
1225 * ixgbe_alloc_rx_buffers - Replace used receive buffers
1226 * @rx_ring: ring to place buffers on
1227 * @cleaned_count: number of buffers to replace
1229 void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
1231 union ixgbe_adv_rx_desc *rx_desc;
1232 struct ixgbe_rx_buffer *bi;
1233 u16 i = rx_ring->next_to_use;
1239 rx_desc = IXGBE_RX_DESC(rx_ring, i);
1240 bi = &rx_ring->rx_buffer_info[i];
1241 i -= rx_ring->count;
1244 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
1248 * Refresh the desc even if buffer_addrs didn't change
1249 * because each write-back erases this info.
1251 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
1257 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
1258 bi = rx_ring->rx_buffer_info;
1259 i -= rx_ring->count;
1262 /* clear the hdr_addr for the next_to_use descriptor */
1263 rx_desc->read.hdr_addr = 0;
1266 } while (cleaned_count);
1268 i += rx_ring->count;
1270 if (rx_ring->next_to_use != i)
1271 ixgbe_release_rx_desc(rx_ring, i);
1275 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1276 * @data: pointer to the start of the headers
1277 * @max_len: total length of section to find headers in
1279 * This function is meant to determine the length of headers that will
1280 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1281 * motivation of doing this is to only perform one pull for IPv4 TCP
1282 * packets so that we can do basic things like calculating the gso_size
1283 * based on the average data per packet.
1285 static unsigned int ixgbe_get_headlen(unsigned char *data,
1286 unsigned int max_len)
1289 unsigned char *network;
1292 struct vlan_hdr *vlan;
1295 struct ipv6hdr *ipv6;
1298 u8 nexthdr = 0; /* default to not TCP */
1301 /* this should never happen, but better safe than sorry */
1302 if (max_len < ETH_HLEN)
1305 /* initialize network frame pointer */
1308 /* set first protocol and move network header forward */
1309 protocol = hdr.eth->h_proto;
1310 hdr.network += ETH_HLEN;
1312 /* handle any vlan tag if present */
1313 if (protocol == __constant_htons(ETH_P_8021Q)) {
1314 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1317 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1318 hdr.network += VLAN_HLEN;
1321 /* handle L3 protocols */
1322 if (protocol == __constant_htons(ETH_P_IP)) {
1323 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1326 /* access ihl as a u8 to avoid unaligned access on ia64 */
1327 hlen = (hdr.network[0] & 0x0F) << 2;
1329 /* verify hlen meets minimum size requirements */
1330 if (hlen < sizeof(struct iphdr))
1331 return hdr.network - data;
1333 /* record next protocol */
1334 nexthdr = hdr.ipv4->protocol;
1335 hdr.network += hlen;
1336 } else if (protocol == __constant_htons(ETH_P_IPV6)) {
1337 if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr)))
1340 /* record next protocol */
1341 nexthdr = hdr.ipv6->nexthdr;
1342 hdr.network += sizeof(struct ipv6hdr);
1344 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1345 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1347 hdr.network += FCOE_HEADER_LEN;
1350 return hdr.network - data;
1353 /* finally sort out TCP/UDP */
1354 if (nexthdr == IPPROTO_TCP) {
1355 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1358 /* access doff as a u8 to avoid unaligned access on ia64 */
1359 hlen = (hdr.network[12] & 0xF0) >> 2;
1361 /* verify hlen meets minimum size requirements */
1362 if (hlen < sizeof(struct tcphdr))
1363 return hdr.network - data;
1365 hdr.network += hlen;
1366 } else if (nexthdr == IPPROTO_UDP) {
1367 if ((hdr.network - data) > (max_len - sizeof(struct udphdr)))
1370 hdr.network += sizeof(struct udphdr);
1374 * If everything has gone correctly hdr.network should be the
1375 * data section of the packet and will be the end of the header.
1376 * If not then it probably represents the end of the last recognized
1379 if ((hdr.network - data) < max_len)
1380 return hdr.network - data;
1385 static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1386 struct sk_buff *skb)
1388 u16 hdr_len = skb_headlen(skb);
1390 /* set gso_size to avoid messing up TCP MSS */
1391 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1392 IXGBE_CB(skb)->append_cnt);
1395 static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1396 struct sk_buff *skb)
1398 /* if append_cnt is 0 then frame is not RSC */
1399 if (!IXGBE_CB(skb)->append_cnt)
1402 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1403 rx_ring->rx_stats.rsc_flush++;
1405 ixgbe_set_rsc_gso_size(rx_ring, skb);
1407 /* gso_size is computed using append_cnt so always clear it last */
1408 IXGBE_CB(skb)->append_cnt = 0;
1412 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1413 * @rx_ring: rx descriptor ring packet is being transacted on
1414 * @rx_desc: pointer to the EOP Rx descriptor
1415 * @skb: pointer to current skb being populated
1417 * This function checks the ring, descriptor, and packet information in
1418 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1419 * other fields within the skb.
1421 static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1422 union ixgbe_adv_rx_desc *rx_desc,
1423 struct sk_buff *skb)
1425 struct net_device *dev = rx_ring->netdev;
1427 ixgbe_update_rsc_stats(rx_ring, skb);
1429 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1431 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1433 ixgbe_ptp_rx_hwtstamp(rx_ring->q_vector, rx_desc, skb);
1435 if ((dev->features & NETIF_F_HW_VLAN_RX) &&
1436 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1437 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1438 __vlan_hwaccel_put_tag(skb, vid);
1441 skb_record_rx_queue(skb, rx_ring->queue_index);
1443 skb->protocol = eth_type_trans(skb, dev);
1446 static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1447 struct sk_buff *skb)
1449 struct ixgbe_adapter *adapter = q_vector->adapter;
1451 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1452 napi_gro_receive(&q_vector->napi, skb);
1458 * ixgbe_is_non_eop - process handling of non-EOP buffers
1459 * @rx_ring: Rx ring being processed
1460 * @rx_desc: Rx descriptor for current buffer
1461 * @skb: Current socket buffer containing buffer in progress
1463 * This function updates next to clean. If the buffer is an EOP buffer
1464 * this function exits returning false, otherwise it will place the
1465 * sk_buff in the next buffer to be chained and return true indicating
1466 * that this is in fact a non-EOP buffer.
1468 static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1469 union ixgbe_adv_rx_desc *rx_desc,
1470 struct sk_buff *skb)
1472 u32 ntc = rx_ring->next_to_clean + 1;
1474 /* fetch, update, and store next to clean */
1475 ntc = (ntc < rx_ring->count) ? ntc : 0;
1476 rx_ring->next_to_clean = ntc;
1478 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1480 /* update RSC append count if present */
1481 if (ring_is_rsc_enabled(rx_ring)) {
1482 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1483 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1485 if (unlikely(rsc_enabled)) {
1486 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1488 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1489 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1491 /* update ntc based on RSC value */
1492 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1493 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1494 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1498 /* if we are the last buffer then there is nothing else to do */
1499 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1502 /* place skb in next buffer to be received */
1503 rx_ring->rx_buffer_info[ntc].skb = skb;
1504 rx_ring->rx_stats.non_eop_descs++;
1510 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1511 * @rx_ring: rx descriptor ring packet is being transacted on
1512 * @skb: pointer to current skb being adjusted
1514 * This function is an ixgbe specific version of __pskb_pull_tail. The
1515 * main difference between this version and the original function is that
1516 * this function can make several assumptions about the state of things
1517 * that allow for significant optimizations versus the standard function.
1518 * As a result we can do things like drop a frag and maintain an accurate
1519 * truesize for the skb.
1521 static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1522 struct sk_buff *skb)
1524 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1526 unsigned int pull_len;
1529 * it is valid to use page_address instead of kmap since we are
1530 * working with pages allocated out of the lomem pool per
1531 * alloc_page(GFP_ATOMIC)
1533 va = skb_frag_address(frag);
1536 * we need the header to contain the greater of either ETH_HLEN or
1537 * 60 bytes if the skb->len is less than 60 for skb_pad.
1539 pull_len = ixgbe_get_headlen(va, IXGBE_RX_HDR_SIZE);
1541 /* align pull length to size of long to optimize memcpy performance */
1542 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1544 /* update all of the pointers */
1545 skb_frag_size_sub(frag, pull_len);
1546 frag->page_offset += pull_len;
1547 skb->data_len -= pull_len;
1548 skb->tail += pull_len;
1552 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1553 * @rx_ring: rx descriptor ring packet is being transacted on
1554 * @skb: pointer to current skb being updated
1556 * This function provides a basic DMA sync up for the first fragment of an
1557 * skb. The reason for doing this is that the first fragment cannot be
1558 * unmapped until we have reached the end of packet descriptor for a buffer
1561 static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1562 struct sk_buff *skb)
1564 /* if the page was released unmap it, else just sync our portion */
1565 if (unlikely(IXGBE_CB(skb)->page_released)) {
1566 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1567 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1568 IXGBE_CB(skb)->page_released = false;
1570 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1572 dma_sync_single_range_for_cpu(rx_ring->dev,
1575 ixgbe_rx_bufsz(rx_ring),
1578 IXGBE_CB(skb)->dma = 0;
1582 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1583 * @rx_ring: rx descriptor ring packet is being transacted on
1584 * @rx_desc: pointer to the EOP Rx descriptor
1585 * @skb: pointer to current skb being fixed
1587 * Check for corrupted packet headers caused by senders on the local L2
1588 * embedded NIC switch not setting up their Tx Descriptors right. These
1589 * should be very rare.
1591 * Also address the case where we are pulling data in on pages only
1592 * and as such no data is present in the skb header.
1594 * In addition if skb is not at least 60 bytes we need to pad it so that
1595 * it is large enough to qualify as a valid Ethernet frame.
1597 * Returns true if an error was encountered and skb was freed.
1599 static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1600 union ixgbe_adv_rx_desc *rx_desc,
1601 struct sk_buff *skb)
1603 struct net_device *netdev = rx_ring->netdev;
1605 /* verify that the packet does not have any known errors */
1606 if (unlikely(ixgbe_test_staterr(rx_desc,
1607 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1608 !(netdev->features & NETIF_F_RXALL))) {
1609 dev_kfree_skb_any(skb);
1613 /* place header in linear portion of buffer */
1614 if (skb_is_nonlinear(skb))
1615 ixgbe_pull_tail(rx_ring, skb);
1618 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1619 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1623 /* if skb_pad returns an error the skb was freed */
1624 if (unlikely(skb->len < 60)) {
1625 int pad_len = 60 - skb->len;
1627 if (skb_pad(skb, pad_len))
1629 __skb_put(skb, pad_len);
1636 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1637 * @rx_ring: rx descriptor ring to store buffers on
1638 * @old_buff: donor buffer to have page reused
1640 * Synchronizes page for reuse by the adapter
1642 static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1643 struct ixgbe_rx_buffer *old_buff)
1645 struct ixgbe_rx_buffer *new_buff;
1646 u16 nta = rx_ring->next_to_alloc;
1648 new_buff = &rx_ring->rx_buffer_info[nta];
1650 /* update, and store next to alloc */
1652 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1654 /* transfer page from old buffer to new buffer */
1655 new_buff->page = old_buff->page;
1656 new_buff->dma = old_buff->dma;
1657 new_buff->page_offset = old_buff->page_offset;
1659 /* sync the buffer for use by the device */
1660 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
1661 new_buff->page_offset,
1662 ixgbe_rx_bufsz(rx_ring),
1667 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1668 * @rx_ring: rx descriptor ring to transact packets on
1669 * @rx_buffer: buffer containing page to add
1670 * @rx_desc: descriptor containing length of buffer written by hardware
1671 * @skb: sk_buff to place the data into
1673 * This function will add the data contained in rx_buffer->page to the skb.
1674 * This is done either through a direct copy if the data in the buffer is
1675 * less than the skb header size, otherwise it will just attach the page as
1676 * a frag to the skb.
1678 * The function will then update the page offset if necessary and return
1679 * true if the buffer can be reused by the adapter.
1681 static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
1682 struct ixgbe_rx_buffer *rx_buffer,
1683 union ixgbe_adv_rx_desc *rx_desc,
1684 struct sk_buff *skb)
1686 struct page *page = rx_buffer->page;
1687 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
1688 #if (PAGE_SIZE < 8192)
1689 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
1691 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1692 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1693 ixgbe_rx_bufsz(rx_ring);
1696 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1697 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1699 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1701 /* we can reuse buffer as-is, just make sure it is local */
1702 if (likely(page_to_nid(page) == numa_node_id()))
1705 /* this page cannot be reused so discard it */
1710 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1711 rx_buffer->page_offset, size, truesize);
1713 /* avoid re-using remote pages */
1714 if (unlikely(page_to_nid(page) != numa_node_id()))
1717 #if (PAGE_SIZE < 8192)
1718 /* if we are only owner of page we can reuse it */
1719 if (unlikely(page_count(page) != 1))
1722 /* flip page offset to other buffer */
1723 rx_buffer->page_offset ^= truesize;
1726 * since we are the only owner of the page and we need to
1727 * increment it, just set the value to 2 in order to avoid
1728 * an unecessary locked operation
1730 atomic_set(&page->_count, 2);
1732 /* move offset up to the next cache line */
1733 rx_buffer->page_offset += truesize;
1735 if (rx_buffer->page_offset > last_offset)
1738 /* bump ref count on page before it is given to the stack */
1745 static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
1746 union ixgbe_adv_rx_desc *rx_desc)
1748 struct ixgbe_rx_buffer *rx_buffer;
1749 struct sk_buff *skb;
1752 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
1753 page = rx_buffer->page;
1756 skb = rx_buffer->skb;
1759 void *page_addr = page_address(page) +
1760 rx_buffer->page_offset;
1762 /* prefetch first cache line of first page */
1763 prefetch(page_addr);
1764 #if L1_CACHE_BYTES < 128
1765 prefetch(page_addr + L1_CACHE_BYTES);
1768 /* allocate a skb to store the frags */
1769 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1771 if (unlikely(!skb)) {
1772 rx_ring->rx_stats.alloc_rx_buff_failed++;
1777 * we will be copying header into skb->data in
1778 * pskb_may_pull so it is in our interest to prefetch
1779 * it now to avoid a possible cache miss
1781 prefetchw(skb->data);
1784 * Delay unmapping of the first packet. It carries the
1785 * header information, HW may still access the header
1786 * after the writeback. Only unmap it when EOP is
1789 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1792 IXGBE_CB(skb)->dma = rx_buffer->dma;
1794 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
1795 ixgbe_dma_sync_frag(rx_ring, skb);
1798 /* we are reusing so sync this buffer for CPU use */
1799 dma_sync_single_range_for_cpu(rx_ring->dev,
1801 rx_buffer->page_offset,
1802 ixgbe_rx_bufsz(rx_ring),
1806 /* pull page into skb */
1807 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
1808 /* hand second half of page back to the ring */
1809 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1810 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1811 /* the page has been released from the ring */
1812 IXGBE_CB(skb)->page_released = true;
1814 /* we are not reusing the buffer so unmap it */
1815 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1816 ixgbe_rx_pg_size(rx_ring),
1820 /* clear contents of buffer_info */
1821 rx_buffer->skb = NULL;
1823 rx_buffer->page = NULL;
1829 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1830 * @q_vector: structure containing interrupt and ring information
1831 * @rx_ring: rx descriptor ring to transact packets on
1832 * @budget: Total limit on number of packets to process
1834 * This function provides a "bounce buffer" approach to Rx interrupt
1835 * processing. The advantage to this is that on systems that have
1836 * expensive overhead for IOMMU access this provides a means of avoiding
1837 * it by maintaining the mapping of the page to the syste.
1839 * Returns true if all work is completed without reaching budget
1841 static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
1842 struct ixgbe_ring *rx_ring,
1845 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
1847 struct ixgbe_adapter *adapter = q_vector->adapter;
1849 unsigned int mss = 0;
1850 #endif /* IXGBE_FCOE */
1851 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
1854 union ixgbe_adv_rx_desc *rx_desc;
1855 struct sk_buff *skb;
1857 /* return some buffers to hardware, one at a time is too slow */
1858 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1859 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1863 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
1865 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1869 * This memory barrier is needed to keep us from reading
1870 * any other fields out of the rx_desc until we know the
1871 * RXD_STAT_DD bit is set
1875 /* retrieve a buffer from the ring */
1876 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
1878 /* exit if we failed to retrieve a buffer */
1884 /* place incomplete frames back on ring for completion */
1885 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1888 /* verify the packet layout is correct */
1889 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1892 /* probably a little skewed due to removing CRC */
1893 total_rx_bytes += skb->len;
1895 /* populate checksum, timestamp, VLAN, and protocol */
1896 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1899 /* if ddp, not passing to ULD unless for FCP_RSP or error */
1900 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
1901 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
1902 /* include DDPed FCoE data */
1903 if (ddp_bytes > 0) {
1905 mss = rx_ring->netdev->mtu -
1906 sizeof(struct fcoe_hdr) -
1907 sizeof(struct fc_frame_header) -
1908 sizeof(struct fcoe_crc_eof);
1912 total_rx_bytes += ddp_bytes;
1913 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
1917 dev_kfree_skb_any(skb);
1922 #endif /* IXGBE_FCOE */
1923 ixgbe_rx_skb(q_vector, skb);
1925 /* update budget accounting */
1927 } while (likely(total_rx_packets < budget));
1929 u64_stats_update_begin(&rx_ring->syncp);
1930 rx_ring->stats.packets += total_rx_packets;
1931 rx_ring->stats.bytes += total_rx_bytes;
1932 u64_stats_update_end(&rx_ring->syncp);
1933 q_vector->rx.total_packets += total_rx_packets;
1934 q_vector->rx.total_bytes += total_rx_bytes;
1937 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1939 return (total_rx_packets < budget);
1943 * ixgbe_configure_msix - Configure MSI-X hardware
1944 * @adapter: board private structure
1946 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1949 static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1951 struct ixgbe_q_vector *q_vector;
1955 /* Populate MSIX to EITR Select */
1956 if (adapter->num_vfs > 32) {
1957 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1958 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1962 * Populate the IVAR table and set the ITR values to the
1963 * corresponding register.
1965 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
1966 struct ixgbe_ring *ring;
1967 q_vector = adapter->q_vector[v_idx];
1969 ixgbe_for_each_ring(ring, q_vector->rx)
1970 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
1972 ixgbe_for_each_ring(ring, q_vector->tx)
1973 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
1975 ixgbe_write_eitr(q_vector);
1978 switch (adapter->hw.mac.type) {
1979 case ixgbe_mac_82598EB:
1980 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
1983 case ixgbe_mac_82599EB:
1984 case ixgbe_mac_X540:
1985 ixgbe_set_ivar(adapter, -1, 1, v_idx);
1990 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
1992 /* set up to autoclear timer, and the vectors */
1993 mask = IXGBE_EIMS_ENABLE_MASK;
1994 mask &= ~(IXGBE_EIMS_OTHER |
1995 IXGBE_EIMS_MAILBOX |
1998 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
2001 enum latency_range {
2005 latency_invalid = 255
2009 * ixgbe_update_itr - update the dynamic ITR value based on statistics
2010 * @q_vector: structure containing interrupt and ring information
2011 * @ring_container: structure containing ring performance data
2013 * Stores a new ITR value based on packets and byte
2014 * counts during the last interrupt. The advantage of per interrupt
2015 * computation is faster updates and more accurate ITR for the current
2016 * traffic pattern. Constants in this function were computed
2017 * based on theoretical maximum wire speed and thresholds were set based
2018 * on testing data as well as attempting to minimize response time
2019 * while increasing bulk throughput.
2020 * this functionality is controlled by the InterruptThrottleRate module
2021 * parameter (see ixgbe_param.c)
2023 static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2024 struct ixgbe_ring_container *ring_container)
2026 int bytes = ring_container->total_bytes;
2027 int packets = ring_container->total_packets;
2030 u8 itr_setting = ring_container->itr;
2035 /* simple throttlerate management
2036 * 0-10MB/s lowest (100000 ints/s)
2037 * 10-20MB/s low (20000 ints/s)
2038 * 20-1249MB/s bulk (8000 ints/s)
2040 /* what was last interrupt timeslice? */
2041 timepassed_us = q_vector->itr >> 2;
2042 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2044 switch (itr_setting) {
2045 case lowest_latency:
2046 if (bytes_perint > 10)
2047 itr_setting = low_latency;
2050 if (bytes_perint > 20)
2051 itr_setting = bulk_latency;
2052 else if (bytes_perint <= 10)
2053 itr_setting = lowest_latency;
2056 if (bytes_perint <= 20)
2057 itr_setting = low_latency;
2061 /* clear work counters since we have the values we need */
2062 ring_container->total_bytes = 0;
2063 ring_container->total_packets = 0;
2065 /* write updated itr to ring container */
2066 ring_container->itr = itr_setting;
2070 * ixgbe_write_eitr - write EITR register in hardware specific way
2071 * @q_vector: structure containing interrupt and ring information
2073 * This function is made to be called by ethtool and by the driver
2074 * when it needs to update EITR registers at runtime. Hardware
2075 * specific quirks/differences are taken care of here.
2077 void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
2079 struct ixgbe_adapter *adapter = q_vector->adapter;
2080 struct ixgbe_hw *hw = &adapter->hw;
2081 int v_idx = q_vector->v_idx;
2082 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
2084 switch (adapter->hw.mac.type) {
2085 case ixgbe_mac_82598EB:
2086 /* must write high and low 16 bits to reset counter */
2087 itr_reg |= (itr_reg << 16);
2089 case ixgbe_mac_82599EB:
2090 case ixgbe_mac_X540:
2092 * set the WDIS bit to not clear the timer bits and cause an
2093 * immediate assertion of the interrupt
2095 itr_reg |= IXGBE_EITR_CNT_WDIS;
2100 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2103 static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
2105 u32 new_itr = q_vector->itr;
2108 ixgbe_update_itr(q_vector, &q_vector->tx);
2109 ixgbe_update_itr(q_vector, &q_vector->rx);
2111 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
2113 switch (current_itr) {
2114 /* counts and packets in update_itr are dependent on these numbers */
2115 case lowest_latency:
2116 new_itr = IXGBE_100K_ITR;
2119 new_itr = IXGBE_20K_ITR;
2122 new_itr = IXGBE_8K_ITR;
2128 if (new_itr != q_vector->itr) {
2129 /* do an exponential smoothing */
2130 new_itr = (10 * new_itr * q_vector->itr) /
2131 ((9 * new_itr) + q_vector->itr);
2133 /* save the algorithm value here */
2134 q_vector->itr = new_itr;
2136 ixgbe_write_eitr(q_vector);
2141 * ixgbe_check_overtemp_subtask - check for over temperature
2142 * @adapter: pointer to adapter
2144 static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
2146 struct ixgbe_hw *hw = &adapter->hw;
2147 u32 eicr = adapter->interrupt_event;
2149 if (test_bit(__IXGBE_DOWN, &adapter->state))
2152 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2153 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2156 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2158 switch (hw->device_id) {
2159 case IXGBE_DEV_ID_82599_T3_LOM:
2161 * Since the warning interrupt is for both ports
2162 * we don't have to check if:
2163 * - This interrupt wasn't for our port.
2164 * - We may have missed the interrupt so always have to
2165 * check if we got a LSC
2167 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2168 !(eicr & IXGBE_EICR_LSC))
2171 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
2173 bool link_up = false;
2175 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2181 /* Check if this is not due to overtemp */
2182 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2187 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2192 "Network adapter has been stopped because it has over heated. "
2193 "Restart the computer. If the problem persists, "
2194 "power off the system and replace the adapter\n");
2196 adapter->interrupt_event = 0;
2199 static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2201 struct ixgbe_hw *hw = &adapter->hw;
2203 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2204 (eicr & IXGBE_EICR_GPI_SDP1)) {
2205 e_crit(probe, "Fan has stopped, replace the adapter\n");
2206 /* write to clear the interrupt */
2207 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2211 static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2213 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2216 switch (adapter->hw.mac.type) {
2217 case ixgbe_mac_82599EB:
2219 * Need to check link state so complete overtemp check
2222 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2223 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2224 adapter->interrupt_event = eicr;
2225 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2226 ixgbe_service_event_schedule(adapter);
2230 case ixgbe_mac_X540:
2231 if (!(eicr & IXGBE_EICR_TS))
2239 "Network adapter has been stopped because it has over heated. "
2240 "Restart the computer. If the problem persists, "
2241 "power off the system and replace the adapter\n");
2244 static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2246 struct ixgbe_hw *hw = &adapter->hw;
2248 if (eicr & IXGBE_EICR_GPI_SDP2) {
2249 /* Clear the interrupt */
2250 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
2251 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2252 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2253 ixgbe_service_event_schedule(adapter);
2257 if (eicr & IXGBE_EICR_GPI_SDP1) {
2258 /* Clear the interrupt */
2259 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2260 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2261 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2262 ixgbe_service_event_schedule(adapter);
2267 static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2269 struct ixgbe_hw *hw = &adapter->hw;
2272 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2273 adapter->link_check_timeout = jiffies;
2274 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2275 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
2276 IXGBE_WRITE_FLUSH(hw);
2277 ixgbe_service_event_schedule(adapter);
2281 static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2285 struct ixgbe_hw *hw = &adapter->hw;
2287 switch (hw->mac.type) {
2288 case ixgbe_mac_82598EB:
2289 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
2290 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2292 case ixgbe_mac_82599EB:
2293 case ixgbe_mac_X540:
2294 mask = (qmask & 0xFFFFFFFF);
2296 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
2297 mask = (qmask >> 32);
2299 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2304 /* skip the flush */
2307 static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
2311 struct ixgbe_hw *hw = &adapter->hw;
2313 switch (hw->mac.type) {
2314 case ixgbe_mac_82598EB:
2315 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
2316 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2318 case ixgbe_mac_82599EB:
2319 case ixgbe_mac_X540:
2320 mask = (qmask & 0xFFFFFFFF);
2322 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
2323 mask = (qmask >> 32);
2325 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2330 /* skip the flush */
2334 * ixgbe_irq_enable - Enable default interrupt generation settings
2335 * @adapter: board private structure
2337 static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2340 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
2342 /* don't reenable LSC while waiting for link */
2343 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2344 mask &= ~IXGBE_EIMS_LSC;
2346 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2347 switch (adapter->hw.mac.type) {
2348 case ixgbe_mac_82599EB:
2349 mask |= IXGBE_EIMS_GPI_SDP0;
2351 case ixgbe_mac_X540:
2352 mask |= IXGBE_EIMS_TS;
2357 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2358 mask |= IXGBE_EIMS_GPI_SDP1;
2359 switch (adapter->hw.mac.type) {
2360 case ixgbe_mac_82599EB:
2361 mask |= IXGBE_EIMS_GPI_SDP1;
2362 mask |= IXGBE_EIMS_GPI_SDP2;
2363 case ixgbe_mac_X540:
2364 mask |= IXGBE_EIMS_ECC;
2365 mask |= IXGBE_EIMS_MAILBOX;
2371 if (adapter->hw.mac.type == ixgbe_mac_X540)
2372 mask |= IXGBE_EIMS_TIMESYNC;
2374 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2375 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2376 mask |= IXGBE_EIMS_FLOW_DIR;
2378 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2380 ixgbe_irq_enable_queues(adapter, ~0);
2382 IXGBE_WRITE_FLUSH(&adapter->hw);
2385 static irqreturn_t ixgbe_msix_other(int irq, void *data)
2387 struct ixgbe_adapter *adapter = data;
2388 struct ixgbe_hw *hw = &adapter->hw;
2392 * Workaround for Silicon errata. Use clear-by-write instead
2393 * of clear-by-read. Reading with EICS will return the
2394 * interrupt causes without clearing, which later be done
2395 * with the write to EICR.
2397 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2398 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
2400 if (eicr & IXGBE_EICR_LSC)
2401 ixgbe_check_lsc(adapter);
2403 if (eicr & IXGBE_EICR_MAILBOX)
2404 ixgbe_msg_task(adapter);
2406 switch (hw->mac.type) {
2407 case ixgbe_mac_82599EB:
2408 case ixgbe_mac_X540:
2409 if (eicr & IXGBE_EICR_ECC)
2410 e_info(link, "Received unrecoverable ECC Err, please "
2412 /* Handle Flow Director Full threshold interrupt */
2413 if (eicr & IXGBE_EICR_FLOW_DIR) {
2414 int reinit_count = 0;
2416 for (i = 0; i < adapter->num_tx_queues; i++) {
2417 struct ixgbe_ring *ring = adapter->tx_ring[i];
2418 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2423 /* no more flow director interrupts until after init */
2424 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2425 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2426 ixgbe_service_event_schedule(adapter);
2429 ixgbe_check_sfp_event(adapter, eicr);
2430 ixgbe_check_overtemp_event(adapter, eicr);
2436 ixgbe_check_fan_failure(adapter, eicr);
2438 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2439 ixgbe_ptp_check_pps_event(adapter, eicr);
2441 /* re-enable the original interrupt state, no lsc, no queues */
2442 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2443 ixgbe_irq_enable(adapter, false, false);
2448 static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
2450 struct ixgbe_q_vector *q_vector = data;
2452 /* EIAM disabled interrupts (on this vector) for us */
2454 if (q_vector->rx.ring || q_vector->tx.ring)
2455 napi_schedule(&q_vector->napi);
2461 * ixgbe_poll - NAPI Rx polling callback
2462 * @napi: structure for representing this polling device
2463 * @budget: how many packets driver is allowed to clean
2465 * This function is used for legacy and MSI, NAPI mode
2467 int ixgbe_poll(struct napi_struct *napi, int budget)
2469 struct ixgbe_q_vector *q_vector =
2470 container_of(napi, struct ixgbe_q_vector, napi);
2471 struct ixgbe_adapter *adapter = q_vector->adapter;
2472 struct ixgbe_ring *ring;
2473 int per_ring_budget;
2474 bool clean_complete = true;
2476 #ifdef CONFIG_IXGBE_DCA
2477 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2478 ixgbe_update_dca(q_vector);
2481 ixgbe_for_each_ring(ring, q_vector->tx)
2482 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2484 /* attempt to distribute budget to each queue fairly, but don't allow
2485 * the budget to go below 1 because we'll exit polling */
2486 if (q_vector->rx.count > 1)
2487 per_ring_budget = max(budget/q_vector->rx.count, 1);
2489 per_ring_budget = budget;
2491 ixgbe_for_each_ring(ring, q_vector->rx)
2492 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
2495 /* If all work not completed, return budget and keep polling */
2496 if (!clean_complete)
2499 /* all work done, exit the polling mode */
2500 napi_complete(napi);
2501 if (adapter->rx_itr_setting & 1)
2502 ixgbe_set_itr(q_vector);
2503 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2504 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2510 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2511 * @adapter: board private structure
2513 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2514 * interrupts from the kernel.
2516 static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2518 struct net_device *netdev = adapter->netdev;
2522 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2523 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2524 struct msix_entry *entry = &adapter->msix_entries[vector];
2526 if (q_vector->tx.ring && q_vector->rx.ring) {
2527 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2528 "%s-%s-%d", netdev->name, "TxRx", ri++);
2530 } else if (q_vector->rx.ring) {
2531 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2532 "%s-%s-%d", netdev->name, "rx", ri++);
2533 } else if (q_vector->tx.ring) {
2534 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2535 "%s-%s-%d", netdev->name, "tx", ti++);
2537 /* skip this unused q_vector */
2540 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2541 q_vector->name, q_vector);
2543 e_err(probe, "request_irq failed for MSIX interrupt "
2544 "Error: %d\n", err);
2545 goto free_queue_irqs;
2547 /* If Flow Director is enabled, set interrupt affinity */
2548 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2549 /* assign the mask for this irq */
2550 irq_set_affinity_hint(entry->vector,
2551 &q_vector->affinity_mask);
2555 err = request_irq(adapter->msix_entries[vector].vector,
2556 ixgbe_msix_other, 0, netdev->name, adapter);
2558 e_err(probe, "request_irq for msix_other failed: %d\n", err);
2559 goto free_queue_irqs;
2567 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2569 free_irq(adapter->msix_entries[vector].vector,
2570 adapter->q_vector[vector]);
2572 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2573 pci_disable_msix(adapter->pdev);
2574 kfree(adapter->msix_entries);
2575 adapter->msix_entries = NULL;
2580 * ixgbe_intr - legacy mode Interrupt Handler
2581 * @irq: interrupt number
2582 * @data: pointer to a network interface device structure
2584 static irqreturn_t ixgbe_intr(int irq, void *data)
2586 struct ixgbe_adapter *adapter = data;
2587 struct ixgbe_hw *hw = &adapter->hw;
2588 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
2592 * Workaround for silicon errata #26 on 82598. Mask the interrupt
2593 * before the read of EICR.
2595 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2597 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2598 * therefore no explicit interrupt disable is necessary */
2599 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
2602 * shared interrupt alert!
2603 * make sure interrupts are enabled because the read will
2604 * have disabled interrupts due to EIAM
2605 * finish the workaround of silicon errata on 82598. Unmask
2606 * the interrupt that we masked before the EICR read.
2608 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2609 ixgbe_irq_enable(adapter, true, true);
2610 return IRQ_NONE; /* Not our interrupt */
2613 if (eicr & IXGBE_EICR_LSC)
2614 ixgbe_check_lsc(adapter);
2616 switch (hw->mac.type) {
2617 case ixgbe_mac_82599EB:
2618 ixgbe_check_sfp_event(adapter, eicr);
2620 case ixgbe_mac_X540:
2621 if (eicr & IXGBE_EICR_ECC)
2622 e_info(link, "Received unrecoverable ECC err, please "
2624 ixgbe_check_overtemp_event(adapter, eicr);
2630 ixgbe_check_fan_failure(adapter, eicr);
2631 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2632 ixgbe_ptp_check_pps_event(adapter, eicr);
2634 /* would disable interrupts here but EIAM disabled it */
2635 napi_schedule(&q_vector->napi);
2638 * re-enable link(maybe) and non-queue interrupts, no flush.
2639 * ixgbe_poll will re-enable the queue interrupts
2641 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2642 ixgbe_irq_enable(adapter, false, false);
2648 * ixgbe_request_irq - initialize interrupts
2649 * @adapter: board private structure
2651 * Attempts to configure interrupts using the best available
2652 * capabilities of the hardware and kernel.
2654 static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
2656 struct net_device *netdev = adapter->netdev;
2659 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2660 err = ixgbe_request_msix_irqs(adapter);
2661 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
2662 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
2663 netdev->name, adapter);
2665 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
2666 netdev->name, adapter);
2669 e_err(probe, "request_irq failed, Error %d\n", err);
2674 static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2678 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2679 free_irq(adapter->pdev->irq, adapter);
2683 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2684 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2685 struct msix_entry *entry = &adapter->msix_entries[vector];
2687 /* free only the irqs that were actually requested */
2688 if (!q_vector->rx.ring && !q_vector->tx.ring)
2691 /* clear the affinity_mask in the IRQ descriptor */
2692 irq_set_affinity_hint(entry->vector, NULL);
2694 free_irq(entry->vector, q_vector);
2697 free_irq(adapter->msix_entries[vector++].vector, adapter);
2701 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2702 * @adapter: board private structure
2704 static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2706 switch (adapter->hw.mac.type) {
2707 case ixgbe_mac_82598EB:
2708 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
2710 case ixgbe_mac_82599EB:
2711 case ixgbe_mac_X540:
2712 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2713 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
2714 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
2719 IXGBE_WRITE_FLUSH(&adapter->hw);
2720 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2723 for (vector = 0; vector < adapter->num_q_vectors; vector++)
2724 synchronize_irq(adapter->msix_entries[vector].vector);
2726 synchronize_irq(adapter->msix_entries[vector++].vector);
2728 synchronize_irq(adapter->pdev->irq);
2733 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2736 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2738 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
2740 ixgbe_write_eitr(q_vector);
2742 ixgbe_set_ivar(adapter, 0, 0, 0);
2743 ixgbe_set_ivar(adapter, 1, 0, 0);
2745 e_info(hw, "Legacy interrupt IVAR setup done\n");
2749 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2750 * @adapter: board private structure
2751 * @ring: structure containing ring specific data
2753 * Configure the Tx descriptor ring after a reset.
2755 void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2756 struct ixgbe_ring *ring)
2758 struct ixgbe_hw *hw = &adapter->hw;
2759 u64 tdba = ring->dma;
2761 u32 txdctl = IXGBE_TXDCTL_ENABLE;
2762 u8 reg_idx = ring->reg_idx;
2764 /* disable queue to avoid issues while updating state */
2765 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
2766 IXGBE_WRITE_FLUSH(hw);
2768 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
2769 (tdba & DMA_BIT_MASK(32)));
2770 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2771 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2772 ring->count * sizeof(union ixgbe_adv_tx_desc));
2773 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2774 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
2775 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
2778 * set WTHRESH to encourage burst writeback, it should not be set
2779 * higher than 1 when ITR is 0 as it could cause false TX hangs
2781 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2782 * to or less than the number of on chip descriptors, which is
2785 if (!ring->q_vector || (ring->q_vector->itr < 8))
2786 txdctl |= (1 << 16); /* WTHRESH = 1 */
2788 txdctl |= (8 << 16); /* WTHRESH = 8 */
2791 * Setting PTHRESH to 32 both improves performance
2792 * and avoids a TX hang with DFP enabled
2794 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2795 32; /* PTHRESH = 32 */
2797 /* reinitialize flowdirector state */
2798 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2799 ring->atr_sample_rate = adapter->atr_sample_rate;
2800 ring->atr_count = 0;
2801 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2803 ring->atr_sample_rate = 0;
2806 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2809 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2811 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2812 if (hw->mac.type == ixgbe_mac_82598EB &&
2813 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2816 /* poll to verify queue is enabled */
2818 usleep_range(1000, 2000);
2819 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2820 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2822 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
2825 static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2827 struct ixgbe_hw *hw = &adapter->hw;
2829 u8 tcs = netdev_get_num_tc(adapter->netdev);
2831 if (hw->mac.type == ixgbe_mac_82598EB)
2834 /* disable the arbiter while setting MTQC */
2835 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2836 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2837 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2839 /* set transmit pool layout */
2840 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
2841 mtqc = IXGBE_MTQC_VT_ENA;
2843 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2845 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2846 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
2847 mtqc |= IXGBE_MTQC_32VF;
2849 mtqc |= IXGBE_MTQC_64VF;
2852 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2854 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2856 mtqc = IXGBE_MTQC_64Q_1PB;
2859 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
2861 /* Enable Security TX Buffer IFG for multiple pb */
2863 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2864 sectx |= IXGBE_SECTX_DCB;
2865 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
2868 /* re-enable the arbiter */
2869 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2870 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2874 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
2875 * @adapter: board private structure
2877 * Configure the Tx unit of the MAC after a reset.
2879 static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2881 struct ixgbe_hw *hw = &adapter->hw;
2885 ixgbe_setup_mtqc(adapter);
2887 if (hw->mac.type != ixgbe_mac_82598EB) {
2888 /* DMATXCTL.EN must be before Tx queues are enabled */
2889 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2890 dmatxctl |= IXGBE_DMATXCTL_TE;
2891 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2894 /* Setup the HW Tx Head and Tail descriptor pointers */
2895 for (i = 0; i < adapter->num_tx_queues; i++)
2896 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
2899 static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
2900 struct ixgbe_ring *ring)
2902 struct ixgbe_hw *hw = &adapter->hw;
2903 u8 reg_idx = ring->reg_idx;
2904 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2906 srrctl |= IXGBE_SRRCTL_DROP_EN;
2908 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2911 static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
2912 struct ixgbe_ring *ring)
2914 struct ixgbe_hw *hw = &adapter->hw;
2915 u8 reg_idx = ring->reg_idx;
2916 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2918 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
2920 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2923 #ifdef CONFIG_IXGBE_DCB
2924 void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2926 static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2930 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
2932 if (adapter->ixgbe_ieee_pfc)
2933 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
2936 * We should set the drop enable bit if:
2939 * Number of Rx queues > 1 and flow control is disabled
2941 * This allows us to avoid head of line blocking for security
2942 * and performance reasons.
2944 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
2945 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
2946 for (i = 0; i < adapter->num_rx_queues; i++)
2947 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
2949 for (i = 0; i < adapter->num_rx_queues; i++)
2950 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
2954 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
2956 static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
2957 struct ixgbe_ring *rx_ring)
2959 struct ixgbe_hw *hw = &adapter->hw;
2961 u8 reg_idx = rx_ring->reg_idx;
2963 if (hw->mac.type == ixgbe_mac_82598EB) {
2964 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
2967 * if VMDq is not active we must program one srrctl register
2968 * per RSS queue since we have enabled RDRXCTL.MVMEN
2973 /* configure header buffer length, needed for RSC */
2974 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
2976 /* configure the packet buffer length */
2977 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2979 /* configure descriptor type */
2980 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
2982 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2985 static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
2987 struct ixgbe_hw *hw = &adapter->hw;
2988 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
2989 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2990 0x6A3E67EA, 0x14364D17, 0x3BED200D};
2991 u32 mrqc = 0, reta = 0;
2994 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
2997 * Program table for at least 2 queues w/ SR-IOV so that VFs can
2998 * make full use of any rings they may have. We will use the
2999 * PSRTYPE register to control how many rings we use within the PF.
3001 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
3004 /* Fill out hash function seeds */
3005 for (i = 0; i < 10; i++)
3006 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
3008 /* Fill out redirection table */
3009 for (i = 0, j = 0; i < 128; i++, j++) {
3012 /* reta = 4-byte sliding window of
3013 * 0x00..(indices-1)(indices-1)00..etc. */
3014 reta = (reta << 8) | (j * 0x11);
3016 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3019 /* Disable indicating checksum in descriptor, enables RSS hash */
3020 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3021 rxcsum |= IXGBE_RXCSUM_PCSD;
3022 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3024 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
3025 if (adapter->ring_feature[RING_F_RSS].mask)
3026 mrqc = IXGBE_MRQC_RSSEN;
3028 u8 tcs = netdev_get_num_tc(adapter->netdev);
3030 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3032 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3034 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3035 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3036 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3038 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3041 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3043 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3045 mrqc = IXGBE_MRQC_RSSEN;
3049 /* Perform hash on these packet types */
3050 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3051 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3052 IXGBE_MRQC_RSS_FIELD_IPV6 |
3053 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
3055 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
3056 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3057 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
3058 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3060 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3064 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3065 * @adapter: address of board private structure
3066 * @index: index of ring to set
3068 static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
3069 struct ixgbe_ring *ring)
3071 struct ixgbe_hw *hw = &adapter->hw;
3073 u8 reg_idx = ring->reg_idx;
3075 if (!ring_is_rsc_enabled(ring))
3078 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
3079 rscctrl |= IXGBE_RSCCTL_RSCEN;
3081 * we must limit the number of descriptors so that the
3082 * total size of max desc * buf_len is not greater
3085 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
3086 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
3089 #define IXGBE_MAX_RX_DESC_POLL 10
3090 static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3091 struct ixgbe_ring *ring)
3093 struct ixgbe_hw *hw = &adapter->hw;
3094 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3096 u8 reg_idx = ring->reg_idx;
3098 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3099 if (hw->mac.type == ixgbe_mac_82598EB &&
3100 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3104 usleep_range(1000, 2000);
3105 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3106 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3109 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3110 "the polling period\n", reg_idx);
3114 void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3115 struct ixgbe_ring *ring)
3117 struct ixgbe_hw *hw = &adapter->hw;
3118 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3120 u8 reg_idx = ring->reg_idx;
3122 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3123 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3125 /* write value back with RXDCTL.ENABLE bit cleared */
3126 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3128 if (hw->mac.type == ixgbe_mac_82598EB &&
3129 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3132 /* the hardware may take up to 100us to really disable the rx queue */
3135 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3136 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3139 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3140 "the polling period\n", reg_idx);
3144 void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3145 struct ixgbe_ring *ring)
3147 struct ixgbe_hw *hw = &adapter->hw;
3148 u64 rdba = ring->dma;
3150 u8 reg_idx = ring->reg_idx;
3152 /* disable queue to avoid issues while updating state */
3153 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3154 ixgbe_disable_rx_queue(adapter, ring);
3156 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3157 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3158 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3159 ring->count * sizeof(union ixgbe_adv_rx_desc));
3160 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3161 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
3162 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
3164 ixgbe_configure_srrctl(adapter, ring);
3165 ixgbe_configure_rscctl(adapter, ring);
3167 /* If operating in IOV mode set RLPML for X540 */
3168 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3169 hw->mac.type == ixgbe_mac_X540) {
3170 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3171 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3172 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3175 if (hw->mac.type == ixgbe_mac_82598EB) {
3177 * enable cache line friendly hardware writes:
3178 * PTHRESH=32 descriptors (half the internal cache),
3179 * this also removes ugly rx_no_buffer_count increment
3180 * HTHRESH=4 descriptors (to minimize latency on fetch)
3181 * WTHRESH=8 burst writeback up to two cache lines
3183 rxdctl &= ~0x3FFFFF;
3187 /* enable receive descriptor ring */
3188 rxdctl |= IXGBE_RXDCTL_ENABLE;
3189 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3191 ixgbe_rx_desc_queue_enable(adapter, ring);
3192 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
3195 static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3197 struct ixgbe_hw *hw = &adapter->hw;
3198 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
3201 /* PSRTYPE must be initialized in non 82598 adapters */
3202 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
3203 IXGBE_PSRTYPE_UDPHDR |
3204 IXGBE_PSRTYPE_IPV4HDR |
3205 IXGBE_PSRTYPE_L2HDR |
3206 IXGBE_PSRTYPE_IPV6HDR;
3208 if (hw->mac.type == ixgbe_mac_82598EB)
3216 for (p = 0; p < adapter->num_rx_pools; p++)
3217 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(p)),
3221 static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3223 struct ixgbe_hw *hw = &adapter->hw;
3224 u32 reg_offset, vf_shift;
3225 u32 gcr_ext, vmdctl;
3228 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3231 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3232 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3233 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
3234 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
3235 vmdctl |= IXGBE_VT_CTL_REPLEN;
3236 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
3238 vf_shift = VMDQ_P(0) % 32;
3239 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
3241 /* Enable only the PF's pool for Tx/Rx */
3242 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3243 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3244 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3245 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
3247 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3248 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
3251 * Set up VF register offsets for selected VT Mode,
3252 * i.e. 32 or 64 VFs for SR-IOV
3254 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3255 case IXGBE_82599_VMDQ_8Q_MASK:
3256 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3258 case IXGBE_82599_VMDQ_4Q_MASK:
3259 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3262 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3266 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3269 /* Enable MAC Anti-Spoofing */
3270 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
3272 /* For VFs that have spoof checking turned off */
3273 for (i = 0; i < adapter->num_vfs; i++) {
3274 if (!adapter->vfinfo[i].spoofchk_enabled)
3275 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3279 static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
3281 struct ixgbe_hw *hw = &adapter->hw;
3282 struct net_device *netdev = adapter->netdev;
3283 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3284 struct ixgbe_ring *rx_ring;
3289 /* adjust max frame to be able to do baby jumbo for FCoE */
3290 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3291 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3292 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3294 #endif /* IXGBE_FCOE */
3296 /* adjust max frame to be at least the size of a standard frame */
3297 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3298 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3300 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3301 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3302 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3303 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3305 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
3308 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
3309 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3310 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
3311 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3314 * Setup the HW Rx Head and Tail Descriptor Pointers and
3315 * the Base and Length of the Rx Descriptor Ring
3317 for (i = 0; i < adapter->num_rx_queues; i++) {
3318 rx_ring = adapter->rx_ring[i];
3319 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3320 set_ring_rsc_enabled(rx_ring);
3322 clear_ring_rsc_enabled(rx_ring);
3326 static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3328 struct ixgbe_hw *hw = &adapter->hw;
3329 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3331 switch (hw->mac.type) {
3332 case ixgbe_mac_82598EB:
3334 * For VMDq support of different descriptor types or
3335 * buffer sizes through the use of multiple SRRCTL
3336 * registers, RDRXCTL.MVMEN must be set to 1
3338 * also, the manual doesn't mention it clearly but DCA hints
3339 * will only use queue 0's tags unless this bit is set. Side
3340 * effects of setting this bit are only that SRRCTL must be
3341 * fully programmed [0..15]
3343 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3345 case ixgbe_mac_82599EB:
3346 case ixgbe_mac_X540:
3347 /* Disable RSC for ACK packets */
3348 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3349 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3350 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3351 /* hardware requires some bits to be set by default */
3352 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3353 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3356 /* We should do nothing since we don't know this hardware */
3360 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3364 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3365 * @adapter: board private structure
3367 * Configure the Rx unit of the MAC after a reset.
3369 static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3371 struct ixgbe_hw *hw = &adapter->hw;
3375 /* disable receives while setting up the descriptors */
3376 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3377 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3379 ixgbe_setup_psrtype(adapter);
3380 ixgbe_setup_rdrxctl(adapter);
3382 /* Program registers for the distribution of queues */
3383 ixgbe_setup_mrqc(adapter);
3385 /* set_rx_buffer_len must be called before ring initialization */
3386 ixgbe_set_rx_buffer_len(adapter);
3389 * Setup the HW Rx Head and Tail Descriptor Pointers and
3390 * the Base and Length of the Rx Descriptor Ring
3392 for (i = 0; i < adapter->num_rx_queues; i++)
3393 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
3395 /* disable drop enable for 82598 parts */
3396 if (hw->mac.type == ixgbe_mac_82598EB)
3397 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3399 /* enable all receives */
3400 rxctrl |= IXGBE_RXCTRL_RXEN;
3401 hw->mac.ops.enable_rx_dma(hw, rxctrl);
3404 static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3406 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3407 struct ixgbe_hw *hw = &adapter->hw;
3409 /* add VID to filter table */
3410 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
3411 set_bit(vid, adapter->active_vlans);
3416 static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3418 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3419 struct ixgbe_hw *hw = &adapter->hw;
3421 /* remove VID from filter table */
3422 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
3423 clear_bit(vid, adapter->active_vlans);
3429 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3430 * @adapter: driver data
3432 static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3434 struct ixgbe_hw *hw = &adapter->hw;
3437 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3438 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3439 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3443 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3444 * @adapter: driver data
3446 static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3448 struct ixgbe_hw *hw = &adapter->hw;
3451 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3452 vlnctrl |= IXGBE_VLNCTRL_VFE;
3453 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3454 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3458 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3459 * @adapter: driver data
3461 static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3463 struct ixgbe_hw *hw = &adapter->hw;
3467 switch (hw->mac.type) {
3468 case ixgbe_mac_82598EB:
3469 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3470 vlnctrl &= ~IXGBE_VLNCTRL_VME;
3471 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3473 case ixgbe_mac_82599EB:
3474 case ixgbe_mac_X540:
3475 for (i = 0; i < adapter->num_rx_queues; i++) {
3476 j = adapter->rx_ring[i]->reg_idx;
3477 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3478 vlnctrl &= ~IXGBE_RXDCTL_VME;
3479 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3488 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
3489 * @adapter: driver data
3491 static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
3493 struct ixgbe_hw *hw = &adapter->hw;
3497 switch (hw->mac.type) {
3498 case ixgbe_mac_82598EB:
3499 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3500 vlnctrl |= IXGBE_VLNCTRL_VME;
3501 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3503 case ixgbe_mac_82599EB:
3504 case ixgbe_mac_X540:
3505 for (i = 0; i < adapter->num_rx_queues; i++) {
3506 j = adapter->rx_ring[i]->reg_idx;
3507 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3508 vlnctrl |= IXGBE_RXDCTL_VME;
3509 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3517 static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3521 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3523 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3524 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
3528 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3529 * @netdev: network interface device structure
3531 * Writes unicast address list to the RAR table.
3532 * Returns: -ENOMEM on failure/insufficient address space
3533 * 0 on no addresses written
3534 * X on writing X addresses to the RAR table
3536 static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3538 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3539 struct ixgbe_hw *hw = &adapter->hw;
3540 unsigned int rar_entries = hw->mac.num_rar_entries - 1;
3543 /* In SR-IOV mode significantly less RAR entries are available */
3544 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3545 rar_entries = IXGBE_MAX_PF_MACVLANS - 1;
3547 /* return ENOMEM indicating insufficient memory for addresses */
3548 if (netdev_uc_count(netdev) > rar_entries)
3551 if (!netdev_uc_empty(netdev)) {
3552 struct netdev_hw_addr *ha;
3553 /* return error if we do not support writing to RAR table */
3554 if (!hw->mac.ops.set_rar)
3557 netdev_for_each_uc_addr(ha, netdev) {
3560 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3561 VMDQ_P(0), IXGBE_RAH_AV);
3565 /* write the addresses in reverse order to avoid write combining */
3566 for (; rar_entries > 0 ; rar_entries--)
3567 hw->mac.ops.clear_rar(hw, rar_entries);
3573 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
3574 * @netdev: network interface device structure
3576 * The set_rx_method entry point is called whenever the unicast/multicast
3577 * address list or the network interface flags are updated. This routine is
3578 * responsible for configuring the hardware for proper unicast, multicast and
3581 void ixgbe_set_rx_mode(struct net_device *netdev)
3583 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3584 struct ixgbe_hw *hw = &adapter->hw;
3585 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3588 /* Check for Promiscuous and All Multicast modes */
3590 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3592 /* set all bits that we expect to always be set */
3593 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
3594 fctrl |= IXGBE_FCTRL_BAM;
3595 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3596 fctrl |= IXGBE_FCTRL_PMCF;
3598 /* clear the bits we are changing the status of */
3599 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3601 if (netdev->flags & IFF_PROMISC) {
3602 hw->addr_ctrl.user_set_promisc = true;
3603 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3604 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
3605 /* don't hardware filter vlans in promisc mode */
3606 ixgbe_vlan_filter_disable(adapter);
3608 if (netdev->flags & IFF_ALLMULTI) {
3609 fctrl |= IXGBE_FCTRL_MPE;
3610 vmolr |= IXGBE_VMOLR_MPE;
3613 * Write addresses to the MTA, if the attempt fails
3614 * then we should just turn on promiscuous mode so
3615 * that we can at least receive multicast traffic
3617 hw->mac.ops.update_mc_addr_list(hw, netdev);
3618 vmolr |= IXGBE_VMOLR_ROMPE;
3620 ixgbe_vlan_filter_enable(adapter);
3621 hw->addr_ctrl.user_set_promisc = false;
3625 * Write addresses to available RAR registers, if there is not
3626 * sufficient space to store all the addresses then enable
3627 * unicast promiscuous mode
3629 count = ixgbe_write_uc_addr_list(netdev);
3631 fctrl |= IXGBE_FCTRL_UPE;
3632 vmolr |= IXGBE_VMOLR_ROPE;
3635 if (adapter->num_vfs)
3636 ixgbe_restore_vf_multicasts(adapter);
3638 if (hw->mac.type != ixgbe_mac_82598EB) {
3639 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
3640 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3642 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
3645 /* This is useful for sniffing bad packets. */
3646 if (adapter->netdev->features & NETIF_F_RXALL) {
3647 /* UPE and MPE will be handled by normal PROMISC logic
3648 * in e1000e_set_rx_mode */
3649 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3650 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3651 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3653 fctrl &= ~(IXGBE_FCTRL_DPF);
3654 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3657 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3659 if (netdev->features & NETIF_F_HW_VLAN_RX)
3660 ixgbe_vlan_strip_enable(adapter);
3662 ixgbe_vlan_strip_disable(adapter);
3665 static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3669 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
3670 napi_enable(&adapter->q_vector[q_idx]->napi);
3673 static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3677 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
3678 napi_disable(&adapter->q_vector[q_idx]->napi);
3681 #ifdef CONFIG_IXGBE_DCB
3683 * ixgbe_configure_dcb - Configure DCB hardware
3684 * @adapter: ixgbe adapter struct
3686 * This is called by the driver on open to configure the DCB hardware.
3687 * This is also called by the gennetlink interface when reconfiguring
3690 static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3692 struct ixgbe_hw *hw = &adapter->hw;
3693 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3695 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3696 if (hw->mac.type == ixgbe_mac_82598EB)
3697 netif_set_gso_max_size(adapter->netdev, 65536);
3701 if (hw->mac.type == ixgbe_mac_82598EB)
3702 netif_set_gso_max_size(adapter->netdev, 32768);
3705 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3706 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3709 /* reconfigure the hardware */
3710 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
3711 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3713 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3715 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3716 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3717 ixgbe_dcb_hw_ets(&adapter->hw,
3718 adapter->ixgbe_ieee_ets,
3720 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3721 adapter->ixgbe_ieee_pfc->pfc_en,
3722 adapter->ixgbe_ieee_ets->prio_tc);
3725 /* Enable RSS Hash per TC */
3726 if (hw->mac.type != ixgbe_mac_82598EB) {
3728 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
3735 /* write msb to all 8 TCs in one write */
3736 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
3741 /* Additional bittime to account for IXGBE framing */
3742 #define IXGBE_ETH_FRAMING 20
3745 * ixgbe_hpbthresh - calculate high water mark for flow control
3747 * @adapter: board private structure to calculate for
3748 * @pb: packet buffer to calculate
3750 static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3752 struct ixgbe_hw *hw = &adapter->hw;
3753 struct net_device *dev = adapter->netdev;
3754 int link, tc, kb, marker;
3757 /* Calculate max LAN frame size */
3758 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3761 /* FCoE traffic class uses FCOE jumbo frames */
3762 if ((dev->features & NETIF_F_FCOE_MTU) &&
3763 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
3764 (pb == ixgbe_fcoe_get_tc(adapter)))
3765 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3768 /* Calculate delay value for device */
3769 switch (hw->mac.type) {
3770 case ixgbe_mac_X540:
3771 dv_id = IXGBE_DV_X540(link, tc);
3774 dv_id = IXGBE_DV(link, tc);
3778 /* Loopback switch introduces additional latency */
3779 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3780 dv_id += IXGBE_B2BT(tc);
3782 /* Delay value is calculated in bit times convert to KB */
3783 kb = IXGBE_BT2KB(dv_id);
3784 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3786 marker = rx_pba - kb;
3788 /* It is possible that the packet buffer is not large enough
3789 * to provide required headroom. In this case throw an error
3790 * to user and a do the best we can.
3793 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3794 "headroom to support flow control."
3795 "Decrease MTU or number of traffic classes\n", pb);
3803 * ixgbe_lpbthresh - calculate low water mark for for flow control
3805 * @adapter: board private structure to calculate for
3806 * @pb: packet buffer to calculate
3808 static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3810 struct ixgbe_hw *hw = &adapter->hw;
3811 struct net_device *dev = adapter->netdev;
3815 /* Calculate max LAN frame size */
3816 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3818 /* Calculate delay value for device */
3819 switch (hw->mac.type) {
3820 case ixgbe_mac_X540:
3821 dv_id = IXGBE_LOW_DV_X540(tc);
3824 dv_id = IXGBE_LOW_DV(tc);
3828 /* Delay value is calculated in bit times convert to KB */
3829 return IXGBE_BT2KB(dv_id);
3833 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3835 static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3837 struct ixgbe_hw *hw = &adapter->hw;
3838 int num_tc = netdev_get_num_tc(adapter->netdev);
3844 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3846 for (i = 0; i < num_tc; i++) {
3847 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3849 /* Low water marks must not be larger than high water marks */
3850 if (hw->fc.low_water > hw->fc.high_water[i])
3851 hw->fc.low_water = 0;
3855 static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3857 struct ixgbe_hw *hw = &adapter->hw;
3859 u8 tc = netdev_get_num_tc(adapter->netdev);
3861 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3862 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3863 hdrm = 32 << adapter->fdir_pballoc;
3867 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
3868 ixgbe_pbthresh_setup(adapter);
3871 static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3873 struct ixgbe_hw *hw = &adapter->hw;
3874 struct hlist_node *node, *node2;
3875 struct ixgbe_fdir_filter *filter;
3877 spin_lock(&adapter->fdir_perfect_lock);
3879 if (!hlist_empty(&adapter->fdir_filter_list))
3880 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3882 hlist_for_each_entry_safe(filter, node, node2,
3883 &adapter->fdir_filter_list, fdir_node) {
3884 ixgbe_fdir_write_perfect_filter_82599(hw,
3887 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3888 IXGBE_FDIR_DROP_QUEUE :
3889 adapter->rx_ring[filter->action]->reg_idx);
3892 spin_unlock(&adapter->fdir_perfect_lock);
3895 static void ixgbe_configure(struct ixgbe_adapter *adapter)
3897 struct ixgbe_hw *hw = &adapter->hw;
3899 ixgbe_configure_pb(adapter);
3900 #ifdef CONFIG_IXGBE_DCB
3901 ixgbe_configure_dcb(adapter);
3904 * We must restore virtualization before VLANs or else
3905 * the VLVF registers will not be populated
3907 ixgbe_configure_virtualization(adapter);
3909 ixgbe_set_rx_mode(adapter->netdev);
3910 ixgbe_restore_vlan(adapter);
3912 switch (hw->mac.type) {
3913 case ixgbe_mac_82599EB:
3914 case ixgbe_mac_X540:
3915 hw->mac.ops.disable_rx_buff(hw);
3921 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3922 ixgbe_init_fdir_signature_82599(&adapter->hw,
3923 adapter->fdir_pballoc);
3924 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3925 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3926 adapter->fdir_pballoc);
3927 ixgbe_fdir_filter_restore(adapter);
3930 switch (hw->mac.type) {
3931 case ixgbe_mac_82599EB:
3932 case ixgbe_mac_X540:
3933 hw->mac.ops.enable_rx_buff(hw);
3940 /* configure FCoE L2 filters, redirection table, and Rx control */
3941 ixgbe_configure_fcoe(adapter);
3943 #endif /* IXGBE_FCOE */
3944 ixgbe_configure_tx(adapter);
3945 ixgbe_configure_rx(adapter);
3948 static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3950 switch (hw->phy.type) {
3951 case ixgbe_phy_sfp_avago:
3952 case ixgbe_phy_sfp_ftl:
3953 case ixgbe_phy_sfp_intel:
3954 case ixgbe_phy_sfp_unknown:
3955 case ixgbe_phy_sfp_passive_tyco:
3956 case ixgbe_phy_sfp_passive_unknown:
3957 case ixgbe_phy_sfp_active_unknown:
3958 case ixgbe_phy_sfp_ftl_active:
3961 if (hw->mac.type == ixgbe_mac_82598EB)
3969 * ixgbe_sfp_link_config - set up SFP+ link
3970 * @adapter: pointer to private adapter struct
3972 static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3975 * We are assuming the worst case scenario here, and that
3976 * is that an SFP was inserted/removed after the reset
3977 * but before SFP detection was enabled. As such the best
3978 * solution is to just start searching as soon as we start
3980 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3981 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
3983 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
3987 * ixgbe_non_sfp_link_config - set up non-SFP+ link
3988 * @hw: pointer to private hardware struct
3990 * Returns 0 on success, negative on failure
3992 static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
3995 bool negotiation, link_up = false;
3996 u32 ret = IXGBE_ERR_LINK_SETUP;
3998 if (hw->mac.ops.check_link)
3999 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
4004 autoneg = hw->phy.autoneg_advertised;
4005 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
4006 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
4011 if (hw->mac.ops.setup_link)
4012 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
4017 static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
4019 struct ixgbe_hw *hw = &adapter->hw;
4022 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4023 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
4025 gpie |= IXGBE_GPIE_EIAME;
4027 * use EIAM to auto-mask when MSI-X interrupt is asserted
4028 * this saves a register write for every interrupt
4030 switch (hw->mac.type) {
4031 case ixgbe_mac_82598EB:
4032 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4034 case ixgbe_mac_82599EB:
4035 case ixgbe_mac_X540:
4037 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4038 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4042 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
4043 * specifically only auto mask tx and rx interrupts */
4044 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4047 /* XXX: to interrupt immediately for EICS writes, enable this */
4048 /* gpie |= IXGBE_GPIE_EIMEN; */
4050 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
4051 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
4053 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4054 case IXGBE_82599_VMDQ_8Q_MASK:
4055 gpie |= IXGBE_GPIE_VTMODE_16;
4057 case IXGBE_82599_VMDQ_4Q_MASK:
4058 gpie |= IXGBE_GPIE_VTMODE_32;
4061 gpie |= IXGBE_GPIE_VTMODE_64;
4066 /* Enable Thermal over heat sensor interrupt */
4067 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
4068 switch (adapter->hw.mac.type) {
4069 case ixgbe_mac_82599EB:
4070 gpie |= IXGBE_SDP0_GPIEN;
4072 case ixgbe_mac_X540:
4073 gpie |= IXGBE_EIMS_TS;
4080 /* Enable fan failure interrupt */
4081 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
4082 gpie |= IXGBE_SDP1_GPIEN;
4084 if (hw->mac.type == ixgbe_mac_82599EB) {
4085 gpie |= IXGBE_SDP1_GPIEN;
4086 gpie |= IXGBE_SDP2_GPIEN;
4089 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4092 static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
4094 struct ixgbe_hw *hw = &adapter->hw;
4098 ixgbe_get_hw_control(adapter);
4099 ixgbe_setup_gpie(adapter);
4101 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4102 ixgbe_configure_msix(adapter);
4104 ixgbe_configure_msi_and_legacy(adapter);
4106 /* enable the optics for 82599 SFP+ fiber */
4107 if (hw->mac.ops.enable_tx_laser)
4108 hw->mac.ops.enable_tx_laser(hw);
4110 clear_bit(__IXGBE_DOWN, &adapter->state);
4111 ixgbe_napi_enable_all(adapter);
4113 if (ixgbe_is_sfp(hw)) {
4114 ixgbe_sfp_link_config(adapter);
4116 err = ixgbe_non_sfp_link_config(hw);
4118 e_err(probe, "link_config FAILED %d\n", err);
4121 /* clear any pending interrupts, may auto mask */
4122 IXGBE_READ_REG(hw, IXGBE_EICR);
4123 ixgbe_irq_enable(adapter, true, true);
4126 * If this adapter has a fan, check to see if we had a failure
4127 * before we enabled the interrupt.
4129 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
4130 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
4131 if (esdp & IXGBE_ESDP_SDP1)
4132 e_crit(drv, "Fan has stopped, replace the adapter\n");
4135 /* enable transmits */
4136 netif_tx_start_all_queues(adapter->netdev);
4138 /* bring the link up in the watchdog, this could race with our first
4139 * link up interrupt but shouldn't be a problem */
4140 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4141 adapter->link_check_timeout = jiffies;
4142 mod_timer(&adapter->service_timer, jiffies);
4144 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4145 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4146 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4147 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
4150 void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4152 WARN_ON(in_interrupt());
4153 /* put off any impending NetWatchDogTimeout */
4154 adapter->netdev->trans_start = jiffies;
4156 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
4157 usleep_range(1000, 2000);
4158 ixgbe_down(adapter);
4160 * If SR-IOV enabled then wait a bit before bringing the adapter
4161 * back up to give the VFs time to respond to the reset. The
4162 * two second wait is based upon the watchdog timer cycle in
4165 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4168 clear_bit(__IXGBE_RESETTING, &adapter->state);
4171 void ixgbe_up(struct ixgbe_adapter *adapter)
4173 /* hardware has been reset, we need to reload some things */
4174 ixgbe_configure(adapter);
4176 ixgbe_up_complete(adapter);
4179 void ixgbe_reset(struct ixgbe_adapter *adapter)
4181 struct ixgbe_hw *hw = &adapter->hw;
4184 /* lock SFP init bit to prevent race conditions with the watchdog */
4185 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4186 usleep_range(1000, 2000);
4188 /* clear all SFP and link config related flags while holding SFP_INIT */
4189 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4190 IXGBE_FLAG2_SFP_NEEDS_RESET);
4191 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4193 err = hw->mac.ops.init_hw(hw);
4196 case IXGBE_ERR_SFP_NOT_PRESENT:
4197 case IXGBE_ERR_SFP_NOT_SUPPORTED:
4199 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
4200 e_dev_err("master disable timed out\n");
4202 case IXGBE_ERR_EEPROM_VERSION:
4203 /* We are running on a pre-production device, log a warning */
4204 e_dev_warn("This device is a pre-production adapter/LOM. "
4205 "Please be aware there may be issues associated with "
4206 "your hardware. If you are experiencing problems "
4207 "please contact your Intel or hardware "
4208 "representative who provided you with this "
4212 e_dev_err("Hardware Error: %d\n", err);
4215 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4217 /* reprogram the RAR[0] in case user changed it. */
4218 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
4220 /* update SAN MAC vmdq pool selection */
4221 if (hw->mac.san_mac_rar_index)
4222 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
4224 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
4225 ixgbe_ptp_reset(adapter);
4229 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
4230 * @rx_ring: ring to free buffers from
4232 static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
4234 struct device *dev = rx_ring->dev;
4238 /* ring already cleared, nothing to do */
4239 if (!rx_ring->rx_buffer_info)
4242 /* Free all the Rx ring sk_buffs */
4243 for (i = 0; i < rx_ring->count; i++) {
4244 struct ixgbe_rx_buffer *rx_buffer;
4246 rx_buffer = &rx_ring->rx_buffer_info[i];
4247 if (rx_buffer->skb) {
4248 struct sk_buff *skb = rx_buffer->skb;
4249 if (IXGBE_CB(skb)->page_released) {
4252 ixgbe_rx_bufsz(rx_ring),
4254 IXGBE_CB(skb)->page_released = false;
4258 rx_buffer->skb = NULL;
4260 dma_unmap_page(dev, rx_buffer->dma,
4261 ixgbe_rx_pg_size(rx_ring),
4264 if (rx_buffer->page)
4265 __free_pages(rx_buffer->page,
4266 ixgbe_rx_pg_order(rx_ring));
4267 rx_buffer->page = NULL;
4270 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4271 memset(rx_ring->rx_buffer_info, 0, size);
4273 /* Zero out the descriptor ring */
4274 memset(rx_ring->desc, 0, rx_ring->size);
4276 rx_ring->next_to_alloc = 0;
4277 rx_ring->next_to_clean = 0;
4278 rx_ring->next_to_use = 0;
4282 * ixgbe_clean_tx_ring - Free Tx Buffers
4283 * @tx_ring: ring to be cleaned
4285 static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
4287 struct ixgbe_tx_buffer *tx_buffer_info;
4291 /* ring already cleared, nothing to do */
4292 if (!tx_ring->tx_buffer_info)
4295 /* Free all the Tx ring sk_buffs */
4296 for (i = 0; i < tx_ring->count; i++) {
4297 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4298 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
4301 netdev_tx_reset_queue(txring_txq(tx_ring));
4303 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4304 memset(tx_ring->tx_buffer_info, 0, size);
4306 /* Zero out the descriptor ring */
4307 memset(tx_ring->desc, 0, tx_ring->size);
4309 tx_ring->next_to_use = 0;
4310 tx_ring->next_to_clean = 0;
4314 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4315 * @adapter: board private structure
4317 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4321 for (i = 0; i < adapter->num_rx_queues; i++)
4322 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
4326 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4327 * @adapter: board private structure
4329 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4333 for (i = 0; i < adapter->num_tx_queues; i++)
4334 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
4337 static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4339 struct hlist_node *node, *node2;
4340 struct ixgbe_fdir_filter *filter;
4342 spin_lock(&adapter->fdir_perfect_lock);
4344 hlist_for_each_entry_safe(filter, node, node2,
4345 &adapter->fdir_filter_list, fdir_node) {
4346 hlist_del(&filter->fdir_node);
4349 adapter->fdir_filter_count = 0;
4351 spin_unlock(&adapter->fdir_perfect_lock);
4354 void ixgbe_down(struct ixgbe_adapter *adapter)
4356 struct net_device *netdev = adapter->netdev;
4357 struct ixgbe_hw *hw = &adapter->hw;
4361 /* signal that we are down to the interrupt handler */
4362 set_bit(__IXGBE_DOWN, &adapter->state);
4364 /* disable receives */
4365 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4366 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
4368 /* disable all enabled rx queues */
4369 for (i = 0; i < adapter->num_rx_queues; i++)
4370 /* this call also flushes the previous write */
4371 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4373 usleep_range(10000, 20000);
4375 netif_tx_stop_all_queues(netdev);
4377 /* call carrier off first to avoid false dev_watchdog timeouts */
4378 netif_carrier_off(netdev);
4379 netif_tx_disable(netdev);
4381 ixgbe_irq_disable(adapter);
4383 ixgbe_napi_disable_all(adapter);
4385 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4386 IXGBE_FLAG2_RESET_REQUESTED);
4387 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4389 del_timer_sync(&adapter->service_timer);
4391 if (adapter->num_vfs) {
4392 /* Clear EITR Select mapping */
4393 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4395 /* Mark all the VFs as inactive */
4396 for (i = 0 ; i < adapter->num_vfs; i++)
4397 adapter->vfinfo[i].clear_to_send = false;
4399 /* ping all the active vfs to let them know we are going down */
4400 ixgbe_ping_all_vfs(adapter);
4402 /* Disable all VFTE/VFRE TX/RX */
4403 ixgbe_disable_tx_rx(adapter);
4406 /* disable transmits in the hardware now that interrupts are off */
4407 for (i = 0; i < adapter->num_tx_queues; i++) {
4408 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
4409 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
4412 /* Disable the Tx DMA engine on 82599 and X540 */
4413 switch (hw->mac.type) {
4414 case ixgbe_mac_82599EB:
4415 case ixgbe_mac_X540:
4416 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
4417 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4418 ~IXGBE_DMATXCTL_TE));
4424 if (!pci_channel_offline(adapter->pdev))
4425 ixgbe_reset(adapter);
4427 /* power down the optics for 82599 SFP+ fiber */
4428 if (hw->mac.ops.disable_tx_laser)
4429 hw->mac.ops.disable_tx_laser(hw);
4431 ixgbe_clean_all_tx_rings(adapter);
4432 ixgbe_clean_all_rx_rings(adapter);
4434 #ifdef CONFIG_IXGBE_DCA
4435 /* since we reset the hardware DCA settings were cleared */
4436 ixgbe_setup_dca(adapter);
4441 * ixgbe_tx_timeout - Respond to a Tx Hang
4442 * @netdev: network interface device structure
4444 static void ixgbe_tx_timeout(struct net_device *netdev)
4446 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4448 /* Do the reset outside of interrupt context */
4449 ixgbe_tx_timeout_reset(adapter);
4453 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4454 * @adapter: board private structure to initialize
4456 * ixgbe_sw_init initializes the Adapter private data structure.
4457 * Fields are initialized based on PCI device information and
4458 * OS network device settings (MTU size).
4460 static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
4462 struct ixgbe_hw *hw = &adapter->hw;
4463 struct pci_dev *pdev = adapter->pdev;
4465 #ifdef CONFIG_IXGBE_DCB
4467 struct tc_configuration *tc;
4470 /* PCI config space info */
4472 hw->vendor_id = pdev->vendor;
4473 hw->device_id = pdev->device;
4474 hw->revision_id = pdev->revision;
4475 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4476 hw->subsystem_device_id = pdev->subsystem_device;
4478 /* Set capability flags */
4479 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
4480 adapter->ring_feature[RING_F_RSS].limit = rss;
4481 switch (hw->mac.type) {
4482 case ixgbe_mac_82598EB:
4483 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4484 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
4485 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
4487 case ixgbe_mac_X540:
4488 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
4489 case ixgbe_mac_82599EB:
4490 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
4491 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4492 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
4493 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4494 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
4495 /* Flow Director hash filters enabled */
4496 adapter->atr_sample_rate = 20;
4497 adapter->ring_feature[RING_F_FDIR].limit =
4498 IXGBE_MAX_FDIR_INDICES;
4499 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
4501 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4502 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
4503 #ifdef CONFIG_IXGBE_DCB
4504 /* Default traffic class to use for FCoE */
4505 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
4507 #endif /* IXGBE_FCOE */
4514 /* FCoE support exists, always init the FCoE lock */
4515 spin_lock_init(&adapter->fcoe.lock);
4518 /* n-tuple support exists, always init our spinlock */
4519 spin_lock_init(&adapter->fdir_perfect_lock);
4521 #ifdef CONFIG_IXGBE_DCB
4522 switch (hw->mac.type) {
4523 case ixgbe_mac_X540:
4524 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
4525 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
4528 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
4529 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
4533 /* Configure DCB traffic classes */
4534 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
4535 tc = &adapter->dcb_cfg.tc_config[j];
4536 tc->path[DCB_TX_CONFIG].bwg_id = 0;
4537 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
4538 tc->path[DCB_RX_CONFIG].bwg_id = 0;
4539 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
4540 tc->dcb_pfc = pfc_disabled;
4543 /* Initialize default user to priority mapping, UPx->TC0 */
4544 tc = &adapter->dcb_cfg.tc_config[0];
4545 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
4546 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
4548 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
4549 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
4550 adapter->dcb_cfg.pfc_mode_enable = false;
4551 adapter->dcb_set_bitmap = 0x00;
4552 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
4553 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
4554 sizeof(adapter->temp_dcb_cfg));
4558 /* default flow control settings */
4559 hw->fc.requested_mode = ixgbe_fc_full;
4560 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
4561 ixgbe_pbthresh_setup(adapter);
4562 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
4563 hw->fc.send_xon = true;
4564 hw->fc.disable_fc_autoneg = false;
4566 #ifdef CONFIG_PCI_IOV
4567 /* assign number of SR-IOV VFs */
4568 if (hw->mac.type != ixgbe_mac_82598EB)
4569 adapter->num_vfs = (max_vfs > 63) ? 0 : max_vfs;
4572 /* enable itr by default in dynamic mode */
4573 adapter->rx_itr_setting = 1;
4574 adapter->tx_itr_setting = 1;
4576 /* set default ring sizes */
4577 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4578 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4580 /* set default work limits */
4581 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
4583 /* initialize eeprom parameters */
4584 if (ixgbe_init_eeprom_params_generic(hw)) {
4585 e_dev_err("EEPROM initialization failed\n");
4589 set_bit(__IXGBE_DOWN, &adapter->state);
4595 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
4596 * @tx_ring: tx descriptor ring (for a specific queue) to setup
4598 * Return 0 on success, negative on failure
4600 int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
4602 struct device *dev = tx_ring->dev;
4603 int orig_node = dev_to_node(dev);
4607 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4609 if (tx_ring->q_vector)
4610 numa_node = tx_ring->q_vector->numa_node;
4612 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
4613 if (!tx_ring->tx_buffer_info)
4614 tx_ring->tx_buffer_info = vzalloc(size);
4615 if (!tx_ring->tx_buffer_info)
4618 /* round up to nearest 4K */
4619 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
4620 tx_ring->size = ALIGN(tx_ring->size, 4096);
4622 set_dev_node(dev, numa_node);
4623 tx_ring->desc = dma_alloc_coherent(dev,
4627 set_dev_node(dev, orig_node);
4629 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
4630 &tx_ring->dma, GFP_KERNEL);
4634 tx_ring->next_to_use = 0;
4635 tx_ring->next_to_clean = 0;
4639 vfree(tx_ring->tx_buffer_info);
4640 tx_ring->tx_buffer_info = NULL;
4641 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
4646 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4647 * @adapter: board private structure
4649 * If this function returns with an error, then it's possible one or
4650 * more of the rings is populated (while the rest are not). It is the
4651 * callers duty to clean those orphaned rings.
4653 * Return 0 on success, negative on failure
4655 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4659 for (i = 0; i < adapter->num_tx_queues; i++) {
4660 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
4664 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
4670 /* rewind the index freeing the rings as we go */
4672 ixgbe_free_tx_resources(adapter->tx_ring[i]);
4677 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
4678 * @rx_ring: rx descriptor ring (for a specific queue) to setup
4680 * Returns 0 on success, negative on failure
4682 int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
4684 struct device *dev = rx_ring->dev;
4685 int orig_node = dev_to_node(dev);
4689 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4691 if (rx_ring->q_vector)
4692 numa_node = rx_ring->q_vector->numa_node;
4694 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
4695 if (!rx_ring->rx_buffer_info)
4696 rx_ring->rx_buffer_info = vzalloc(size);
4697 if (!rx_ring->rx_buffer_info)
4700 /* Round up to nearest 4K */
4701 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4702 rx_ring->size = ALIGN(rx_ring->size, 4096);
4704 set_dev_node(dev, numa_node);
4705 rx_ring->desc = dma_alloc_coherent(dev,
4709 set_dev_node(dev, orig_node);
4711 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
4712 &rx_ring->dma, GFP_KERNEL);
4716 rx_ring->next_to_clean = 0;
4717 rx_ring->next_to_use = 0;
4721 vfree(rx_ring->rx_buffer_info);
4722 rx_ring->rx_buffer_info = NULL;
4723 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
4728 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4729 * @adapter: board private structure
4731 * If this function returns with an error, then it's possible one or
4732 * more of the rings is populated (while the rest are not). It is the
4733 * callers duty to clean those orphaned rings.
4735 * Return 0 on success, negative on failure
4737 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4741 for (i = 0; i < adapter->num_rx_queues; i++) {
4742 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
4746 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
4751 err = ixgbe_setup_fcoe_ddp_resources(adapter);
4756 /* rewind the index freeing the rings as we go */
4758 ixgbe_free_rx_resources(adapter->rx_ring[i]);
4763 * ixgbe_free_tx_resources - Free Tx Resources per Queue
4764 * @tx_ring: Tx descriptor ring for a specific queue
4766 * Free all transmit software resources
4768 void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
4770 ixgbe_clean_tx_ring(tx_ring);
4772 vfree(tx_ring->tx_buffer_info);
4773 tx_ring->tx_buffer_info = NULL;
4775 /* if not set, then don't free */
4779 dma_free_coherent(tx_ring->dev, tx_ring->size,
4780 tx_ring->desc, tx_ring->dma);
4782 tx_ring->desc = NULL;
4786 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4787 * @adapter: board private structure
4789 * Free all transmit software resources
4791 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4795 for (i = 0; i < adapter->num_tx_queues; i++)
4796 if (adapter->tx_ring[i]->desc)
4797 ixgbe_free_tx_resources(adapter->tx_ring[i]);
4801 * ixgbe_free_rx_resources - Free Rx Resources
4802 * @rx_ring: ring to clean the resources from
4804 * Free all receive software resources
4806 void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
4808 ixgbe_clean_rx_ring(rx_ring);
4810 vfree(rx_ring->rx_buffer_info);
4811 rx_ring->rx_buffer_info = NULL;
4813 /* if not set, then don't free */
4817 dma_free_coherent(rx_ring->dev, rx_ring->size,
4818 rx_ring->desc, rx_ring->dma);
4820 rx_ring->desc = NULL;
4824 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4825 * @adapter: board private structure
4827 * Free all receive software resources
4829 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4834 ixgbe_free_fcoe_ddp_resources(adapter);
4837 for (i = 0; i < adapter->num_rx_queues; i++)
4838 if (adapter->rx_ring[i]->desc)
4839 ixgbe_free_rx_resources(adapter->rx_ring[i]);
4843 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4844 * @netdev: network interface device structure
4845 * @new_mtu: new value for maximum frame size
4847 * Returns 0 on success, negative on failure
4849 static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4851 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4852 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4854 /* MTU < 68 is an error and causes problems on some kernels */
4855 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
4859 * For 82599EB we cannot allow legacy VFs to enable their receive
4860 * paths when MTU greater than 1500 is configured. So display a
4861 * warning that legacy VFs will be disabled.
4863 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
4864 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
4865 (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
4866 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
4868 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
4870 /* must set new MTU before calling down or up */
4871 netdev->mtu = new_mtu;
4873 if (netif_running(netdev))
4874 ixgbe_reinit_locked(adapter);
4880 * ixgbe_open - Called when a network interface is made active
4881 * @netdev: network interface device structure
4883 * Returns 0 on success, negative value on failure
4885 * The open entry point is called when a network interface is made
4886 * active by the system (IFF_UP). At this point all resources needed
4887 * for transmit and receive operations are allocated, the interrupt
4888 * handler is registered with the OS, the watchdog timer is started,
4889 * and the stack is notified that the interface is ready.
4891 static int ixgbe_open(struct net_device *netdev)
4893 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4896 /* disallow open during test */
4897 if (test_bit(__IXGBE_TESTING, &adapter->state))
4900 netif_carrier_off(netdev);
4902 /* allocate transmit descriptors */
4903 err = ixgbe_setup_all_tx_resources(adapter);
4907 /* allocate receive descriptors */
4908 err = ixgbe_setup_all_rx_resources(adapter);
4912 ixgbe_configure(adapter);
4914 err = ixgbe_request_irq(adapter);
4918 /* Notify the stack of the actual queue counts. */
4919 err = netif_set_real_num_tx_queues(netdev,
4920 adapter->num_rx_pools > 1 ? 1 :
4921 adapter->num_tx_queues);
4923 goto err_set_queues;
4926 err = netif_set_real_num_rx_queues(netdev,
4927 adapter->num_rx_pools > 1 ? 1 :
4928 adapter->num_rx_queues);
4930 goto err_set_queues;
4932 ixgbe_ptp_init(adapter);
4934 ixgbe_up_complete(adapter);
4939 ixgbe_free_irq(adapter);
4941 ixgbe_free_all_rx_resources(adapter);
4943 ixgbe_free_all_tx_resources(adapter);
4945 ixgbe_reset(adapter);
4951 * ixgbe_close - Disables a network interface
4952 * @netdev: network interface device structure
4954 * Returns 0, this is not allowed to fail
4956 * The close entry point is called when an interface is de-activated
4957 * by the OS. The hardware is still under the drivers control, but
4958 * needs to be disabled. A global MAC reset is issued to stop the
4959 * hardware, and all transmit and receive resources are freed.
4961 static int ixgbe_close(struct net_device *netdev)
4963 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4965 ixgbe_ptp_stop(adapter);
4967 ixgbe_down(adapter);
4968 ixgbe_free_irq(adapter);
4970 ixgbe_fdir_filter_exit(adapter);
4972 ixgbe_free_all_tx_resources(adapter);
4973 ixgbe_free_all_rx_resources(adapter);
4975 ixgbe_release_hw_control(adapter);
4981 static int ixgbe_resume(struct pci_dev *pdev)
4983 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
4984 struct net_device *netdev = adapter->netdev;
4987 pci_set_power_state(pdev, PCI_D0);
4988 pci_restore_state(pdev);
4990 * pci_restore_state clears dev->state_saved so call
4991 * pci_save_state to restore it.
4993 pci_save_state(pdev);
4995 err = pci_enable_device_mem(pdev);
4997 e_dev_err("Cannot enable PCI device from suspend\n");
5000 pci_set_master(pdev);
5002 pci_wake_from_d3(pdev, false);
5004 ixgbe_reset(adapter);
5006 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5009 err = ixgbe_init_interrupt_scheme(adapter);
5010 if (!err && netif_running(netdev))
5011 err = ixgbe_open(netdev);
5018 netif_device_attach(netdev);
5022 #endif /* CONFIG_PM */
5024 static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
5026 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5027 struct net_device *netdev = adapter->netdev;
5028 struct ixgbe_hw *hw = &adapter->hw;
5030 u32 wufc = adapter->wol;
5035 netif_device_detach(netdev);
5037 if (netif_running(netdev)) {
5039 ixgbe_down(adapter);
5040 ixgbe_free_irq(adapter);
5041 ixgbe_free_all_tx_resources(adapter);
5042 ixgbe_free_all_rx_resources(adapter);
5046 ixgbe_clear_interrupt_scheme(adapter);
5049 retval = pci_save_state(pdev);
5055 ixgbe_set_rx_mode(netdev);
5057 /* enable the optics for 82599 SFP+ fiber as we can WoL */
5058 if (hw->mac.ops.enable_tx_laser)
5059 hw->mac.ops.enable_tx_laser(hw);
5061 /* turn on all-multi mode if wake on multicast is enabled */
5062 if (wufc & IXGBE_WUFC_MC) {
5063 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5064 fctrl |= IXGBE_FCTRL_MPE;
5065 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5068 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5069 ctrl |= IXGBE_CTRL_GIO_DIS;
5070 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5072 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5074 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5075 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5078 switch (hw->mac.type) {
5079 case ixgbe_mac_82598EB:
5080 pci_wake_from_d3(pdev, false);
5082 case ixgbe_mac_82599EB:
5083 case ixgbe_mac_X540:
5084 pci_wake_from_d3(pdev, !!wufc);
5090 *enable_wake = !!wufc;
5092 ixgbe_release_hw_control(adapter);
5094 pci_disable_device(pdev);
5100 static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5105 retval = __ixgbe_shutdown(pdev, &wake);
5110 pci_prepare_to_sleep(pdev);
5112 pci_wake_from_d3(pdev, false);
5113 pci_set_power_state(pdev, PCI_D3hot);
5118 #endif /* CONFIG_PM */
5120 static void ixgbe_shutdown(struct pci_dev *pdev)
5124 __ixgbe_shutdown(pdev, &wake);
5126 if (system_state == SYSTEM_POWER_OFF) {
5127 pci_wake_from_d3(pdev, wake);
5128 pci_set_power_state(pdev, PCI_D3hot);
5133 * ixgbe_update_stats - Update the board statistics counters.
5134 * @adapter: board private structure
5136 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5138 struct net_device *netdev = adapter->netdev;
5139 struct ixgbe_hw *hw = &adapter->hw;
5140 struct ixgbe_hw_stats *hwstats = &adapter->stats;
5142 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
5143 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5144 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5145 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
5147 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5148 test_bit(__IXGBE_RESETTING, &adapter->state))
5151 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
5154 for (i = 0; i < adapter->num_rx_queues; i++) {
5155 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5156 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
5158 adapter->rsc_total_count = rsc_count;
5159 adapter->rsc_total_flush = rsc_flush;
5162 for (i = 0; i < adapter->num_rx_queues; i++) {
5163 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5164 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5165 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5166 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5167 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
5168 bytes += rx_ring->stats.bytes;
5169 packets += rx_ring->stats.packets;
5171 adapter->non_eop_descs = non_eop_descs;
5172 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5173 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5174 adapter->hw_csum_rx_error = hw_csum_rx_error;
5175 netdev->stats.rx_bytes = bytes;
5176 netdev->stats.rx_packets = packets;
5180 /* gather some stats to the adapter struct that are per queue */
5181 for (i = 0; i < adapter->num_tx_queues; i++) {
5182 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5183 restart_queue += tx_ring->tx_stats.restart_queue;
5184 tx_busy += tx_ring->tx_stats.tx_busy;
5185 bytes += tx_ring->stats.bytes;
5186 packets += tx_ring->stats.packets;
5188 adapter->restart_queue = restart_queue;
5189 adapter->tx_busy = tx_busy;
5190 netdev->stats.tx_bytes = bytes;
5191 netdev->stats.tx_packets = packets;
5193 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
5195 /* 8 register reads */
5196 for (i = 0; i < 8; i++) {
5197 /* for packet buffers not used, the register should read 0 */
5198 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5200 hwstats->mpc[i] += mpc;
5201 total_mpc += hwstats->mpc[i];
5202 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5203 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
5204 switch (hw->mac.type) {
5205 case ixgbe_mac_82598EB:
5206 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5207 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5208 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
5209 hwstats->pxonrxc[i] +=
5210 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
5212 case ixgbe_mac_82599EB:
5213 case ixgbe_mac_X540:
5214 hwstats->pxonrxc[i] +=
5215 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
5222 /*16 register reads */
5223 for (i = 0; i < 16; i++) {
5224 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5225 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5226 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5227 (hw->mac.type == ixgbe_mac_X540)) {
5228 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5229 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5230 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5231 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5235 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
5236 /* work around hardware counting issue */
5237 hwstats->gprc -= missed_rx;
5239 ixgbe_update_xoff_received(adapter);
5241 /* 82598 hardware only has a 32 bit counter in the high register */
5242 switch (hw->mac.type) {
5243 case ixgbe_mac_82598EB:
5244 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
5245 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5246 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5247 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5249 case ixgbe_mac_X540:
5250 /* OS2BMC stats are X540 only*/
5251 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5252 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5253 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5254 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5255 case ixgbe_mac_82599EB:
5256 for (i = 0; i < 16; i++)
5257 adapter->hw_rx_no_dma_resources +=
5258 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
5259 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
5260 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
5261 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
5262 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
5263 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
5264 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
5265 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
5266 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5267 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
5269 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5270 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5271 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5272 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5273 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5274 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
5275 /* Add up per cpu counters for total ddp aloc fail */
5276 if (adapter->fcoe.ddp_pool) {
5277 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5278 struct ixgbe_fcoe_ddp_pool *ddp_pool;
5280 u64 noddp = 0, noddp_ext_buff = 0;
5281 for_each_possible_cpu(cpu) {
5282 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
5283 noddp += ddp_pool->noddp;
5284 noddp_ext_buff += ddp_pool->noddp_ext_buff;
5286 hwstats->fcoe_noddp = noddp;
5287 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
5289 #endif /* IXGBE_FCOE */
5294 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
5295 hwstats->bprc += bprc;
5296 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
5297 if (hw->mac.type == ixgbe_mac_82598EB)
5298 hwstats->mprc -= bprc;
5299 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5300 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5301 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5302 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5303 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5304 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5305 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5306 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
5307 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
5308 hwstats->lxontxc += lxon;
5309 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
5310 hwstats->lxofftxc += lxoff;
5311 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5312 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
5314 * 82598 errata - tx of flow control packets is included in tx counters
5316 xon_off_tot = lxon + lxoff;
5317 hwstats->gptc -= xon_off_tot;
5318 hwstats->mptc -= xon_off_tot;
5319 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5320 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5321 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5322 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5323 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5324 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5325 hwstats->ptc64 -= xon_off_tot;
5326 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5327 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5328 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5329 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5330 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5331 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
5333 /* Fill out the OS statistics structure */
5334 netdev->stats.multicast = hwstats->mprc;
5337 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
5338 netdev->stats.rx_dropped = 0;
5339 netdev->stats.rx_length_errors = hwstats->rlec;
5340 netdev->stats.rx_crc_errors = hwstats->crcerrs;
5341 netdev->stats.rx_missed_errors = total_mpc;
5345 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5346 * @adapter: pointer to the device adapter structure
5348 static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
5350 struct ixgbe_hw *hw = &adapter->hw;
5353 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5356 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5358 /* if interface is down do nothing */
5359 if (test_bit(__IXGBE_DOWN, &adapter->state))
5362 /* do nothing if we are not using signature filters */
5363 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5366 adapter->fdir_overflow++;
5368 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5369 for (i = 0; i < adapter->num_tx_queues; i++)
5370 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
5371 &(adapter->tx_ring[i]->state));
5372 /* re-enable flow director interrupts */
5373 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
5375 e_err(probe, "failed to finish FDIR re-initialization, "
5376 "ignored adding FDIR ATR filters\n");
5381 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5382 * @adapter: pointer to the device adapter structure
5384 * This function serves two purposes. First it strobes the interrupt lines
5385 * in order to make certain interrupts are occurring. Secondly it sets the
5386 * bits needed to check for TX hangs. As a result we should immediately
5387 * determine if a hang has occurred.
5389 static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5391 struct ixgbe_hw *hw = &adapter->hw;
5395 /* If we're down or resetting, just bail */
5396 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5397 test_bit(__IXGBE_RESETTING, &adapter->state))
5400 /* Force detection of hung controller */
5401 if (netif_carrier_ok(adapter->netdev)) {
5402 for (i = 0; i < adapter->num_tx_queues; i++)
5403 set_check_for_tx_hang(adapter->tx_ring[i]);
5406 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
5408 * for legacy and MSI interrupts don't set any bits
5409 * that are enabled for EIAM, because this operation
5410 * would set *both* EIMS and EICS for any bit in EIAM
5412 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5413 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
5415 /* get one bit for every active tx/rx interrupt vector */
5416 for (i = 0; i < adapter->num_q_vectors; i++) {
5417 struct ixgbe_q_vector *qv = adapter->q_vector[i];
5418 if (qv->rx.ring || qv->tx.ring)
5419 eics |= ((u64)1 << i);
5423 /* Cause software interrupt to ensure rings are cleaned */
5424 ixgbe_irq_rearm_queues(adapter, eics);
5429 * ixgbe_watchdog_update_link - update the link status
5430 * @adapter: pointer to the device adapter structure
5431 * @link_speed: pointer to a u32 to store the link_speed
5433 static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
5435 struct ixgbe_hw *hw = &adapter->hw;
5436 u32 link_speed = adapter->link_speed;
5437 bool link_up = adapter->link_up;
5438 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
5440 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5443 if (hw->mac.ops.check_link) {
5444 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
5446 /* always assume link is up, if no check link function */
5447 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5451 if (adapter->ixgbe_ieee_pfc)
5452 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
5454 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
5455 hw->mac.ops.fc_enable(hw);
5456 ixgbe_set_rx_drop_en(adapter);
5460 time_after(jiffies, (adapter->link_check_timeout +
5461 IXGBE_TRY_LINK_TIMEOUT))) {
5462 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5463 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5464 IXGBE_WRITE_FLUSH(hw);
5467 adapter->link_up = link_up;
5468 adapter->link_speed = link_speed;
5471 static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
5473 #ifdef CONFIG_IXGBE_DCB
5474 struct net_device *netdev = adapter->netdev;
5475 struct dcb_app app = {
5476 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
5481 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
5482 up = dcb_ieee_getapp_mask(netdev, &app);
5484 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
5489 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5490 * print link up message
5491 * @adapter: pointer to the device adapter structure
5493 static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5495 struct net_device *netdev = adapter->netdev;
5496 struct ixgbe_hw *hw = &adapter->hw;
5497 u32 link_speed = adapter->link_speed;
5498 bool flow_rx, flow_tx;
5500 /* only continue if link was previously down */
5501 if (netif_carrier_ok(netdev))
5504 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5506 switch (hw->mac.type) {
5507 case ixgbe_mac_82598EB: {
5508 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5509 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5510 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5511 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5514 case ixgbe_mac_X540:
5515 case ixgbe_mac_82599EB: {
5516 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5517 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5518 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5519 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5528 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5529 ixgbe_ptp_start_cyclecounter(adapter);
5531 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5532 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5534 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5536 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5539 ((flow_rx && flow_tx) ? "RX/TX" :
5541 (flow_tx ? "TX" : "None"))));
5543 netif_carrier_on(netdev);
5544 ixgbe_check_vf_rate_limit(adapter);
5546 /* update the default user priority for VFs */
5547 ixgbe_update_default_up(adapter);
5549 /* ping all the active vfs to let them know link has changed */
5550 ixgbe_ping_all_vfs(adapter);
5554 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5555 * print link down message
5556 * @adapter: pointer to the adapter structure
5558 static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
5560 struct net_device *netdev = adapter->netdev;
5561 struct ixgbe_hw *hw = &adapter->hw;
5563 adapter->link_up = false;
5564 adapter->link_speed = 0;
5566 /* only continue if link was up previously */
5567 if (!netif_carrier_ok(netdev))
5570 /* poll for SFP+ cable when link is down */
5571 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5572 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5574 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5575 ixgbe_ptp_start_cyclecounter(adapter);
5577 e_info(drv, "NIC Link is Down\n");
5578 netif_carrier_off(netdev);
5580 /* ping all the active vfs to let them know link has changed */
5581 ixgbe_ping_all_vfs(adapter);
5585 * ixgbe_watchdog_flush_tx - flush queues on link down
5586 * @adapter: pointer to the device adapter structure
5588 static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5591 int some_tx_pending = 0;
5593 if (!netif_carrier_ok(adapter->netdev)) {
5594 for (i = 0; i < adapter->num_tx_queues; i++) {
5595 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5596 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5597 some_tx_pending = 1;
5602 if (some_tx_pending) {
5603 /* We've lost link, so the controller stops DMA,
5604 * but we've got queued Tx work that's never going
5605 * to get done, so reset controller to flush Tx.
5606 * (Do the reset outside of interrupt context).
5608 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
5613 static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
5617 /* Do not perform spoof check for 82598 or if not in IOV mode */
5618 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
5619 adapter->num_vfs == 0)
5622 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
5625 * ssvpc register is cleared on read, if zero then no
5626 * spoofed packets in the last interval.
5631 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
5635 * ixgbe_watchdog_subtask - check and bring link up
5636 * @adapter: pointer to the device adapter structure
5638 static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
5640 /* if interface is down do nothing */
5641 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5642 test_bit(__IXGBE_RESETTING, &adapter->state))
5645 ixgbe_watchdog_update_link(adapter);
5647 if (adapter->link_up)
5648 ixgbe_watchdog_link_is_up(adapter);
5650 ixgbe_watchdog_link_is_down(adapter);
5652 ixgbe_spoof_check(adapter);
5653 ixgbe_update_stats(adapter);
5655 ixgbe_watchdog_flush_tx(adapter);
5659 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
5660 * @adapter: the ixgbe adapter structure
5662 static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
5664 struct ixgbe_hw *hw = &adapter->hw;
5667 /* not searching for SFP so there is nothing to do here */
5668 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
5669 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5672 /* someone else is in init, wait until next service event */
5673 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5676 err = hw->phy.ops.identify_sfp(hw);
5677 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5680 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
5681 /* If no cable is present, then we need to reset
5682 * the next time we find a good cable. */
5683 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
5690 /* exit if reset not needed */
5691 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5694 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
5697 * A module may be identified correctly, but the EEPROM may not have
5698 * support for that module. setup_sfp() will fail in that case, so
5699 * we should not allow that module to load.
5701 if (hw->mac.type == ixgbe_mac_82598EB)
5702 err = hw->phy.ops.reset(hw);
5704 err = hw->mac.ops.setup_sfp(hw);
5706 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5709 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
5710 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
5713 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5715 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
5716 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
5717 e_dev_err("failed to initialize because an unsupported "
5718 "SFP+ module type was detected.\n");
5719 e_dev_err("Reload the driver after installing a "
5720 "supported module.\n");
5721 unregister_netdev(adapter->netdev);
5726 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
5727 * @adapter: the ixgbe adapter structure
5729 static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
5731 struct ixgbe_hw *hw = &adapter->hw;
5735 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
5738 /* someone else is in init, wait until next service event */
5739 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5742 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5744 autoneg = hw->phy.autoneg_advertised;
5745 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
5746 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
5747 if (hw->mac.ops.setup_link)
5748 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
5750 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5751 adapter->link_check_timeout = jiffies;
5752 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5755 #ifdef CONFIG_PCI_IOV
5756 static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
5759 struct ixgbe_hw *hw = &adapter->hw;
5760 struct net_device *netdev = adapter->netdev;
5764 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
5765 if (gpc) /* If incrementing then no need for the check below */
5768 * Check to see if a bad DMA write target from an errant or
5769 * malicious VF has caused a PCIe error. If so then we can
5770 * issue a VFLR to the offending VF(s) and then resume without
5771 * requesting a full slot reset.
5774 for (vf = 0; vf < adapter->num_vfs; vf++) {
5775 ciaa = (vf << 16) | 0x80000000;
5776 /* 32 bit read so align, we really want status at offset 6 */
5777 ciaa |= PCI_COMMAND;
5778 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5779 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
5781 /* disable debug mode asap after reading data */
5782 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5783 /* Get the upper 16 bits which will be the PCI status reg */
5785 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
5786 netdev_err(netdev, "VF %d Hung DMA\n", vf);
5788 ciaa = (vf << 16) | 0x80000000;
5790 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5791 ciad = 0x00008000; /* VFLR */
5792 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
5794 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5801 * ixgbe_service_timer - Timer Call-back
5802 * @data: pointer to adapter cast into an unsigned long
5804 static void ixgbe_service_timer(unsigned long data)
5806 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
5807 unsigned long next_event_offset;
5810 /* poll faster when waiting for link */
5811 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
5812 next_event_offset = HZ / 10;
5814 next_event_offset = HZ * 2;
5816 #ifdef CONFIG_PCI_IOV
5818 * don't bother with SR-IOV VF DMA hang check if there are
5819 * no VFs or the link is down
5821 if (!adapter->num_vfs ||
5822 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5823 goto normal_timer_service;
5825 /* If we have VFs allocated then we must check for DMA hangs */
5826 ixgbe_check_for_bad_vf(adapter);
5827 next_event_offset = HZ / 50;
5828 adapter->timer_event_accumulator++;
5830 if (adapter->timer_event_accumulator >= 100)
5831 adapter->timer_event_accumulator = 0;
5835 normal_timer_service:
5837 /* Reset the timer */
5838 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
5841 ixgbe_service_event_schedule(adapter);
5844 static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
5846 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
5849 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
5851 /* If we're already down or resetting, just bail */
5852 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5853 test_bit(__IXGBE_RESETTING, &adapter->state))
5856 ixgbe_dump(adapter);
5857 netdev_err(adapter->netdev, "Reset adapter\n");
5858 adapter->tx_timeout_count++;
5860 ixgbe_reinit_locked(adapter);
5864 * ixgbe_service_task - manages and runs subtasks
5865 * @work: pointer to work_struct containing our data
5867 static void ixgbe_service_task(struct work_struct *work)
5869 struct ixgbe_adapter *adapter = container_of(work,
5870 struct ixgbe_adapter,
5873 ixgbe_reset_subtask(adapter);
5874 ixgbe_sfp_detection_subtask(adapter);
5875 ixgbe_sfp_link_config_subtask(adapter);
5876 ixgbe_check_overtemp_subtask(adapter);
5877 ixgbe_watchdog_subtask(adapter);
5878 ixgbe_fdir_reinit_subtask(adapter);
5879 ixgbe_check_hang_subtask(adapter);
5880 ixgbe_ptp_overflow_check(adapter);
5882 ixgbe_service_event_complete(adapter);
5885 static int ixgbe_tso(struct ixgbe_ring *tx_ring,
5886 struct ixgbe_tx_buffer *first,
5889 struct sk_buff *skb = first->skb;
5890 u32 vlan_macip_lens, type_tucmd;
5891 u32 mss_l4len_idx, l4len;
5893 if (!skb_is_gso(skb))
5896 if (skb_header_cloned(skb)) {
5897 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
5902 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5903 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
5905 if (first->protocol == __constant_htons(ETH_P_IP)) {
5906 struct iphdr *iph = ip_hdr(skb);
5909 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
5913 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
5914 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5915 IXGBE_TX_FLAGS_CSUM |
5916 IXGBE_TX_FLAGS_IPV4;
5917 } else if (skb_is_gso_v6(skb)) {
5918 ipv6_hdr(skb)->payload_len = 0;
5919 tcp_hdr(skb)->check =
5920 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5921 &ipv6_hdr(skb)->daddr,
5923 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5924 IXGBE_TX_FLAGS_CSUM;
5927 /* compute header lengths */
5928 l4len = tcp_hdrlen(skb);
5929 *hdr_len = skb_transport_offset(skb) + l4len;
5931 /* update gso size and bytecount with header size */
5932 first->gso_segs = skb_shinfo(skb)->gso_segs;
5933 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5935 /* mss_l4len_id: use 1 as index for TSO */
5936 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
5937 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
5938 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
5940 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
5941 vlan_macip_lens = skb_network_header_len(skb);
5942 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
5943 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
5945 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
5951 static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
5952 struct ixgbe_tx_buffer *first)
5954 struct sk_buff *skb = first->skb;
5955 u32 vlan_macip_lens = 0;
5956 u32 mss_l4len_idx = 0;
5959 if (skb->ip_summed != CHECKSUM_PARTIAL) {
5960 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN)) {
5961 if (unlikely(skb->no_fcs))
5962 first->tx_flags |= IXGBE_TX_FLAGS_NO_IFCS;
5963 if (!(first->tx_flags & IXGBE_TX_FLAGS_TXSW))
5968 switch (first->protocol) {
5969 case __constant_htons(ETH_P_IP):
5970 vlan_macip_lens |= skb_network_header_len(skb);
5971 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
5972 l4_hdr = ip_hdr(skb)->protocol;
5974 case __constant_htons(ETH_P_IPV6):
5975 vlan_macip_lens |= skb_network_header_len(skb);
5976 l4_hdr = ipv6_hdr(skb)->nexthdr;
5979 if (unlikely(net_ratelimit())) {
5980 dev_warn(tx_ring->dev,
5981 "partial checksum but proto=%x!\n",
5989 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
5990 mss_l4len_idx = tcp_hdrlen(skb) <<
5991 IXGBE_ADVTXD_L4LEN_SHIFT;
5994 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
5995 mss_l4len_idx = sizeof(struct sctphdr) <<
5996 IXGBE_ADVTXD_L4LEN_SHIFT;
5999 mss_l4len_idx = sizeof(struct udphdr) <<
6000 IXGBE_ADVTXD_L4LEN_SHIFT;
6003 if (unlikely(net_ratelimit())) {
6004 dev_warn(tx_ring->dev,
6005 "partial checksum but l4 proto=%x!\n",
6011 /* update TX checksum flag */
6012 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
6015 /* vlan_macip_lens: MACLEN, VLAN tag */
6016 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6017 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6019 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6020 type_tucmd, mss_l4len_idx);
6023 static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6025 /* set type for advanced descriptor with frame checksum insertion */
6026 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6027 IXGBE_ADVTXD_DCMD_DEXT);
6029 /* set HW vlan bit if vlan is present */
6030 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
6031 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6033 if (tx_flags & IXGBE_TX_FLAGS_TSTAMP)
6034 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_MAC_TSTAMP);
6036 /* set segmentation enable bits for TSO/FSO */
6038 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO))
6040 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6042 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6044 /* insert frame checksum */
6045 if (!(tx_flags & IXGBE_TX_FLAGS_NO_IFCS))
6046 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS);
6051 static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
6052 u32 tx_flags, unsigned int paylen)
6054 __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
6056 /* enable L4 checksum for TSO and TX checksum offload */
6057 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6058 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6060 /* enble IPv4 checksum for TSO */
6061 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6062 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
6064 /* use index 1 context for TSO/FSO/FCOE */
6066 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE))
6068 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6070 olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT);
6073 * Check Context must be set if Tx switch is enabled, which it
6074 * always is for case where virtual functions are running
6077 if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE))
6079 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
6081 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6083 tx_desc->read.olinfo_status = olinfo_status;
6086 #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6089 static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
6090 struct ixgbe_tx_buffer *first,
6094 struct sk_buff *skb = first->skb;
6095 struct ixgbe_tx_buffer *tx_buffer;
6096 union ixgbe_adv_tx_desc *tx_desc;
6097 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
6098 unsigned int data_len = skb->data_len;
6099 unsigned int size = skb_headlen(skb);
6100 unsigned int paylen = skb->len - hdr_len;
6101 u32 tx_flags = first->tx_flags;
6103 u16 i = tx_ring->next_to_use;
6105 tx_desc = IXGBE_TX_DESC(tx_ring, i);
6107 ixgbe_tx_olinfo_status(tx_desc, tx_flags, paylen);
6108 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6111 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6112 if (data_len < sizeof(struct fcoe_crc_eof)) {
6113 size -= sizeof(struct fcoe_crc_eof) - data_len;
6116 data_len -= sizeof(struct fcoe_crc_eof);
6121 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
6122 if (dma_mapping_error(tx_ring->dev, dma))
6125 /* record length, and DMA address */
6126 dma_unmap_len_set(first, len, size);
6127 dma_unmap_addr_set(first, dma, dma);
6129 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6132 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
6133 tx_desc->read.cmd_type_len =
6134 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
6138 if (i == tx_ring->count) {
6139 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
6143 dma += IXGBE_MAX_DATA_PER_TXD;
6144 size -= IXGBE_MAX_DATA_PER_TXD;
6146 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6147 tx_desc->read.olinfo_status = 0;
6150 if (likely(!data_len))
6153 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
6157 if (i == tx_ring->count) {
6158 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
6163 size = min_t(unsigned int, data_len, skb_frag_size(frag));
6165 size = skb_frag_size(frag);
6169 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
6171 if (dma_mapping_error(tx_ring->dev, dma))
6174 tx_buffer = &tx_ring->tx_buffer_info[i];
6175 dma_unmap_len_set(tx_buffer, len, size);
6176 dma_unmap_addr_set(tx_buffer, dma, dma);
6178 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6179 tx_desc->read.olinfo_status = 0;
6184 /* write last descriptor with RS and EOP bits */
6185 cmd_type |= cpu_to_le32(size) | cpu_to_le32(IXGBE_TXD_CMD);
6186 tx_desc->read.cmd_type_len = cmd_type;
6188 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
6190 /* set the timestamp */
6191 first->time_stamp = jiffies;
6194 * Force memory writes to complete before letting h/w know there
6195 * are new descriptors to fetch. (Only applicable for weak-ordered
6196 * memory model archs, such as IA-64).
6198 * We also need this memory barrier to make certain all of the
6199 * status bits have been updated before next_to_watch is written.
6203 /* set next_to_watch value indicating a packet is present */
6204 first->next_to_watch = tx_desc;
6207 if (i == tx_ring->count)
6210 tx_ring->next_to_use = i;
6212 /* notify HW of packet */
6213 writel(i, tx_ring->tail);
6217 dev_err(tx_ring->dev, "TX DMA map failed\n");
6219 /* clear dma mappings for failed tx_buffer_info map */
6221 tx_buffer = &tx_ring->tx_buffer_info[i];
6222 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
6223 if (tx_buffer == first)
6230 tx_ring->next_to_use = i;
6233 static void ixgbe_atr(struct ixgbe_ring *ring,
6234 struct ixgbe_tx_buffer *first)
6236 struct ixgbe_q_vector *q_vector = ring->q_vector;
6237 union ixgbe_atr_hash_dword input = { .dword = 0 };
6238 union ixgbe_atr_hash_dword common = { .dword = 0 };
6240 unsigned char *network;
6242 struct ipv6hdr *ipv6;
6247 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6251 /* do nothing if sampling is disabled */
6252 if (!ring->atr_sample_rate)
6257 /* snag network header to get L4 type and address */
6258 hdr.network = skb_network_header(first->skb);
6260 /* Currently only IPv4/IPv6 with TCP is supported */
6261 if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
6262 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6263 (first->protocol != __constant_htons(ETH_P_IP) ||
6264 hdr.ipv4->protocol != IPPROTO_TCP))
6267 th = tcp_hdr(first->skb);
6269 /* skip this packet since it is invalid or the socket is closing */
6273 /* sample on all syn packets or once every atr sample count */
6274 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6277 /* reset sample count */
6278 ring->atr_count = 0;
6280 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6283 * src and dst are inverted, think how the receiver sees them
6285 * The input is broken into two sections, a non-compressed section
6286 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6287 * is XORed together and stored in the compressed dword.
6289 input.formatted.vlan_id = vlan_id;
6292 * since src port and flex bytes occupy the same word XOR them together
6293 * and write the value to source port portion of compressed dword
6295 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
6296 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6298 common.port.src ^= th->dest ^ first->protocol;
6299 common.port.dst ^= th->source;
6301 if (first->protocol == __constant_htons(ETH_P_IP)) {
6302 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6303 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6305 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6306 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6307 hdr.ipv6->saddr.s6_addr32[1] ^
6308 hdr.ipv6->saddr.s6_addr32[2] ^
6309 hdr.ipv6->saddr.s6_addr32[3] ^
6310 hdr.ipv6->daddr.s6_addr32[0] ^
6311 hdr.ipv6->daddr.s6_addr32[1] ^
6312 hdr.ipv6->daddr.s6_addr32[2] ^
6313 hdr.ipv6->daddr.s6_addr32[3];
6316 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
6317 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6318 input, common, ring->queue_index);
6321 static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
6323 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
6324 /* Herbert's original patch had:
6325 * smp_mb__after_netif_stop_queue();
6326 * but since that doesn't exist yet, just open code it. */
6329 /* We need to check again in a case another CPU has just
6330 * made room available. */
6331 if (likely(ixgbe_desc_unused(tx_ring) < size))
6334 /* A reprieve! - use start_queue because it doesn't call schedule */
6335 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
6336 ++tx_ring->tx_stats.restart_queue;
6340 static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
6342 if (likely(ixgbe_desc_unused(tx_ring) >= size))
6344 return __ixgbe_maybe_stop_tx(tx_ring, size);
6347 static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6349 struct ixgbe_adapter *adapter = netdev_priv(dev);
6350 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6353 __be16 protocol = vlan_get_protocol(skb);
6355 if (((protocol == htons(ETH_P_FCOE)) ||
6356 (protocol == htons(ETH_P_FIP))) &&
6357 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6358 struct ixgbe_ring_feature *f;
6360 f = &adapter->ring_feature[RING_F_FCOE];
6362 while (txq >= f->indices)
6364 txq += adapter->ring_feature[RING_F_FCOE].offset;
6370 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6371 while (unlikely(txq >= dev->real_num_tx_queues))
6372 txq -= dev->real_num_tx_queues;
6376 return skb_tx_hash(dev, skb);
6379 netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
6380 struct ixgbe_adapter *adapter,
6381 struct ixgbe_ring *tx_ring)
6383 struct ixgbe_tx_buffer *first;
6386 #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6389 u16 count = TXD_USE_COUNT(skb_headlen(skb));
6390 __be16 protocol = skb->protocol;
6394 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
6395 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
6396 * + 2 desc gap to keep tail from touching head,
6397 * + 1 desc for context descriptor,
6398 * otherwise try next time
6400 #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6401 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6402 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6404 count += skb_shinfo(skb)->nr_frags;
6406 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6407 tx_ring->tx_stats.tx_busy++;
6408 return NETDEV_TX_BUSY;
6411 /* record the location of the first descriptor for this packet */
6412 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6414 first->bytecount = skb->len;
6415 first->gso_segs = 1;
6417 /* if we have a HW VLAN tag being added default to the HW one */
6418 if (vlan_tx_tag_present(skb)) {
6419 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6420 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6421 /* else if it is a SW VLAN check the next protocol and store the tag */
6422 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6423 struct vlan_hdr *vhdr, _vhdr;
6424 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6428 protocol = vhdr->h_vlan_encapsulated_proto;
6429 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
6430 IXGBE_TX_FLAGS_VLAN_SHIFT;
6431 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
6434 skb_tx_timestamp(skb);
6436 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
6437 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
6438 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
6441 #ifdef CONFIG_PCI_IOV
6443 * Use the l2switch_enable flag - would be false if the DMA
6444 * Tx switch had been disabled.
6446 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6447 tx_flags |= IXGBE_TX_FLAGS_TXSW;
6450 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
6451 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
6452 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6453 (skb->priority != TC_PRIO_CONTROL))) {
6454 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
6455 tx_flags |= (skb->priority & 0x7) <<
6456 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
6457 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6458 struct vlan_ethhdr *vhdr;
6459 if (skb_header_cloned(skb) &&
6460 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6462 vhdr = (struct vlan_ethhdr *)skb->data;
6463 vhdr->h_vlan_TCI = htons(tx_flags >>
6464 IXGBE_TX_FLAGS_VLAN_SHIFT);
6466 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6470 /* record initial flags and protocol */
6471 first->tx_flags = tx_flags;
6472 first->protocol = protocol;
6475 /* setup tx offload for FCoE */
6476 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
6477 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
6478 tso = ixgbe_fso(tx_ring, first, &hdr_len);
6485 #endif /* IXGBE_FCOE */
6486 tso = ixgbe_tso(tx_ring, first, &hdr_len);
6490 ixgbe_tx_csum(tx_ring, first);
6492 /* add the ATR filter if ATR is on */
6493 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6494 ixgbe_atr(tx_ring, first);
6498 #endif /* IXGBE_FCOE */
6499 ixgbe_tx_map(tx_ring, first, hdr_len);
6501 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
6503 return NETDEV_TX_OK;
6506 dev_kfree_skb_any(first->skb);
6509 return NETDEV_TX_OK;
6512 static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
6513 struct net_device *netdev)
6515 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6516 struct ixgbe_ring *tx_ring;
6519 * The minimum packet size for olinfo paylen is 17 so pad the skb
6520 * in order to meet this minimum size requirement.
6522 if (unlikely(skb->len < 17)) {
6523 if (skb_pad(skb, 17 - skb->len))
6524 return NETDEV_TX_OK;
6526 skb_set_tail_pointer(skb, 17);
6529 tx_ring = adapter->tx_ring[skb->queue_mapping];
6530 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6534 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6535 * @netdev: network interface device structure
6536 * @p: pointer to an address structure
6538 * Returns 0 on success, negative on failure
6540 static int ixgbe_set_mac(struct net_device *netdev, void *p)
6542 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6543 struct ixgbe_hw *hw = &adapter->hw;
6544 struct sockaddr *addr = p;
6546 if (!is_valid_ether_addr(addr->sa_data))
6547 return -EADDRNOTAVAIL;
6549 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6550 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6552 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
6558 ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6560 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6561 struct ixgbe_hw *hw = &adapter->hw;
6565 if (prtad != hw->phy.mdio.prtad)
6567 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6573 static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6574 u16 addr, u16 value)
6576 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6577 struct ixgbe_hw *hw = &adapter->hw;
6579 if (prtad != hw->phy.mdio.prtad)
6581 return hw->phy.ops.write_reg(hw, addr, devad, value);
6584 static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6586 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6590 return ixgbe_ptp_hwtstamp_ioctl(adapter, req, cmd);
6592 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6597 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
6599 * @netdev: network interface device structure
6601 * Returns non-zero on failure
6603 static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6606 struct ixgbe_adapter *adapter = netdev_priv(dev);
6607 struct ixgbe_hw *hw = &adapter->hw;
6609 if (is_valid_ether_addr(hw->mac.san_addr)) {
6611 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
6614 /* update SAN MAC vmdq pool selection */
6615 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
6621 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
6623 * @netdev: network interface device structure
6625 * Returns non-zero on failure
6627 static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6630 struct ixgbe_adapter *adapter = netdev_priv(dev);
6631 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6633 if (is_valid_ether_addr(mac->san_addr)) {
6635 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6641 #ifdef CONFIG_NET_POLL_CONTROLLER
6643 * Polling 'interrupt' - used by things like netconsole to send skbs
6644 * without having to re-enable interrupts. It's not called while
6645 * the interrupt routine is executing.
6647 static void ixgbe_netpoll(struct net_device *netdev)
6649 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6652 /* if interface is down do nothing */
6653 if (test_bit(__IXGBE_DOWN, &adapter->state))
6656 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
6657 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
6658 for (i = 0; i < adapter->num_q_vectors; i++)
6659 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
6661 ixgbe_intr(adapter->pdev->irq, netdev);
6663 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
6667 static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6668 struct rtnl_link_stats64 *stats)
6670 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6674 for (i = 0; i < adapter->num_rx_queues; i++) {
6675 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
6681 start = u64_stats_fetch_begin_bh(&ring->syncp);
6682 packets = ring->stats.packets;
6683 bytes = ring->stats.bytes;
6684 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6685 stats->rx_packets += packets;
6686 stats->rx_bytes += bytes;
6690 for (i = 0; i < adapter->num_tx_queues; i++) {
6691 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
6697 start = u64_stats_fetch_begin_bh(&ring->syncp);
6698 packets = ring->stats.packets;
6699 bytes = ring->stats.bytes;
6700 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6701 stats->tx_packets += packets;
6702 stats->tx_bytes += bytes;
6706 /* following stats updated by ixgbe_watchdog_task() */
6707 stats->multicast = netdev->stats.multicast;
6708 stats->rx_errors = netdev->stats.rx_errors;
6709 stats->rx_length_errors = netdev->stats.rx_length_errors;
6710 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
6711 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
6715 #ifdef CONFIG_IXGBE_DCB
6717 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
6718 * @adapter: pointer to ixgbe_adapter
6719 * @tc: number of traffic classes currently enabled
6721 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
6722 * 802.1Q priority maps to a packet buffer that exists.
6724 static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
6726 struct ixgbe_hw *hw = &adapter->hw;
6730 /* 82598 have a static priority to TC mapping that can not
6731 * be changed so no validation is needed.
6733 if (hw->mac.type == ixgbe_mac_82598EB)
6736 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
6739 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
6740 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
6742 /* If up2tc is out of bounds default to zero */
6744 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
6748 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
6754 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
6755 * @adapter: Pointer to adapter struct
6757 * Populate the netdev user priority to tc map
6759 static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
6761 struct net_device *dev = adapter->netdev;
6762 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
6763 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
6766 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
6769 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
6770 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
6772 tc = ets->prio_tc[prio];
6774 netdev_set_prio_tc_map(dev, prio, tc);
6779 * ixgbe_setup_tc - configure net_device for multiple traffic classes
6781 * @netdev: net device to configure
6782 * @tc: number of traffic classes to enable
6784 int ixgbe_setup_tc(struct net_device *dev, u8 tc)
6786 struct ixgbe_adapter *adapter = netdev_priv(dev);
6787 struct ixgbe_hw *hw = &adapter->hw;
6789 /* Hardware supports up to 8 traffic classes */
6790 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
6791 (hw->mac.type == ixgbe_mac_82598EB &&
6792 tc < MAX_TRAFFIC_CLASS))
6795 /* Hardware has to reinitialize queues and interrupts to
6796 * match packet buffer alignment. Unfortunately, the
6797 * hardware is not flexible enough to do this dynamically.
6799 if (netif_running(dev))
6801 ixgbe_clear_interrupt_scheme(adapter);
6804 netdev_set_num_tc(dev, tc);
6805 ixgbe_set_prio_tc_map(adapter);
6807 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
6809 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
6810 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
6811 adapter->hw.fc.requested_mode = ixgbe_fc_none;
6814 netdev_reset_tc(dev);
6816 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6817 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
6819 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
6821 adapter->temp_dcb_cfg.pfc_mode_enable = false;
6822 adapter->dcb_cfg.pfc_mode_enable = false;
6825 ixgbe_init_interrupt_scheme(adapter);
6826 ixgbe_validate_rtr(adapter, tc);
6827 if (netif_running(dev))
6833 #endif /* CONFIG_IXGBE_DCB */
6834 void ixgbe_do_reset(struct net_device *netdev)
6836 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6838 if (netif_running(netdev))
6839 ixgbe_reinit_locked(adapter);
6841 ixgbe_reset(adapter);
6844 static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
6845 netdev_features_t features)
6847 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6849 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
6850 if (!(features & NETIF_F_RXCSUM))
6851 features &= ~NETIF_F_LRO;
6853 /* Turn off LRO if not RSC capable */
6854 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
6855 features &= ~NETIF_F_LRO;
6860 static int ixgbe_set_features(struct net_device *netdev,
6861 netdev_features_t features)
6863 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6864 netdev_features_t changed = netdev->features ^ features;
6865 bool need_reset = false;
6867 /* Make sure RSC matches LRO, reset if change */
6868 if (!(features & NETIF_F_LRO)) {
6869 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
6871 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
6872 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
6873 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
6874 if (adapter->rx_itr_setting == 1 ||
6875 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
6876 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
6878 } else if ((changed ^ features) & NETIF_F_LRO) {
6879 e_info(probe, "rx-usecs set too low, "
6885 * Check if Flow Director n-tuple support was enabled or disabled. If
6886 * the state changed, we need to reset.
6888 switch (features & NETIF_F_NTUPLE) {
6889 case NETIF_F_NTUPLE:
6890 /* turn off ATR, enable perfect filters and reset */
6891 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
6894 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
6895 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
6898 /* turn off perfect filters, enable ATR and reset */
6899 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
6902 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
6904 /* We cannot enable ATR if SR-IOV is enabled */
6905 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6908 /* We cannot enable ATR if we have 2 or more traffic classes */
6909 if (netdev_get_num_tc(netdev) > 1)
6912 /* We cannot enable ATR if RSS is disabled */
6913 if (adapter->ring_feature[RING_F_RSS].limit <= 1)
6916 /* A sample rate of 0 indicates ATR disabled */
6917 if (!adapter->atr_sample_rate)
6920 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
6924 if (features & NETIF_F_HW_VLAN_RX)
6925 ixgbe_vlan_strip_enable(adapter);
6927 ixgbe_vlan_strip_disable(adapter);
6929 if (changed & NETIF_F_RXALL)
6932 netdev->features = features;
6934 ixgbe_do_reset(netdev);
6939 static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
6940 struct net_device *dev,
6941 const unsigned char *addr,
6944 struct ixgbe_adapter *adapter = netdev_priv(dev);
6947 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
6950 if (ndm->ndm_state & NUD_PERMANENT) {
6951 pr_info("%s: FDB only supports static addresses\n",
6956 if (is_unicast_ether_addr(addr) || is_link_local(addr)) {
6957 u32 rar_uc_entries = IXGBE_MAX_PF_MACVLANS;
6959 if (netdev_uc_count(dev) < rar_uc_entries)
6960 err = dev_uc_add_excl(dev, addr);
6963 } else if (is_multicast_ether_addr(addr)) {
6964 err = dev_mc_add_excl(dev, addr);
6969 /* Only return duplicate errors if NLM_F_EXCL is set */
6970 if (err == -EEXIST && !(flags & NLM_F_EXCL))
6976 static int ixgbe_ndo_fdb_del(struct ndmsg *ndm,
6977 struct net_device *dev,
6978 const unsigned char *addr)
6980 struct ixgbe_adapter *adapter = netdev_priv(dev);
6981 int err = -EOPNOTSUPP;
6983 if (ndm->ndm_state & NUD_PERMANENT) {
6984 pr_info("%s: FDB only supports static addresses\n",
6989 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
6990 if (is_unicast_ether_addr(addr))
6991 err = dev_uc_del(dev, addr);
6992 else if (is_multicast_ether_addr(addr))
6993 err = dev_mc_del(dev, addr);
7001 static int ixgbe_ndo_fdb_dump(struct sk_buff *skb,
7002 struct netlink_callback *cb,
7003 struct net_device *dev,
7006 struct ixgbe_adapter *adapter = netdev_priv(dev);
7008 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7009 idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
7014 static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
7015 struct nlmsghdr *nlh)
7017 struct ixgbe_adapter *adapter = netdev_priv(dev);
7018 struct nlattr *attr, *br_spec;
7021 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7024 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
7026 nla_for_each_nested(attr, br_spec, rem) {
7030 if (nla_type(attr) != IFLA_BRIDGE_MODE)
7033 mode = nla_get_u16(attr);
7034 if (mode == BRIDGE_MODE_VEPA)
7036 else if (mode == BRIDGE_MODE_VEB)
7037 reg = IXGBE_PFDTXGSWC_VT_LBEN;
7041 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, reg);
7043 e_info(drv, "enabling bridge mode: %s\n",
7044 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
7050 static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
7051 struct net_device *dev)
7053 struct ixgbe_adapter *adapter = netdev_priv(dev);
7056 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7059 if (IXGBE_READ_REG(&adapter->hw, IXGBE_PFDTXGSWC) & 1)
7060 mode = BRIDGE_MODE_VEB;
7062 mode = BRIDGE_MODE_VEPA;
7064 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode);
7067 static const struct net_device_ops ixgbe_netdev_ops = {
7068 .ndo_open = ixgbe_open,
7069 .ndo_stop = ixgbe_close,
7070 .ndo_start_xmit = ixgbe_xmit_frame,
7071 .ndo_select_queue = ixgbe_select_queue,
7072 .ndo_set_rx_mode = ixgbe_set_rx_mode,
7073 .ndo_validate_addr = eth_validate_addr,
7074 .ndo_set_mac_address = ixgbe_set_mac,
7075 .ndo_change_mtu = ixgbe_change_mtu,
7076 .ndo_tx_timeout = ixgbe_tx_timeout,
7077 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7078 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
7079 .ndo_do_ioctl = ixgbe_ioctl,
7080 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7081 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7082 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7083 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
7084 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
7085 .ndo_get_stats64 = ixgbe_get_stats64,
7086 #ifdef CONFIG_IXGBE_DCB
7087 .ndo_setup_tc = ixgbe_setup_tc,
7089 #ifdef CONFIG_NET_POLL_CONTROLLER
7090 .ndo_poll_controller = ixgbe_netpoll,
7093 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
7094 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
7095 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
7096 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7097 .ndo_fcoe_disable = ixgbe_fcoe_disable,
7098 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
7099 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
7100 #endif /* IXGBE_FCOE */
7101 .ndo_set_features = ixgbe_set_features,
7102 .ndo_fix_features = ixgbe_fix_features,
7103 .ndo_fdb_add = ixgbe_ndo_fdb_add,
7104 .ndo_fdb_del = ixgbe_ndo_fdb_del,
7105 .ndo_fdb_dump = ixgbe_ndo_fdb_dump,
7106 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
7107 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
7111 * ixgbe_wol_supported - Check whether device supports WoL
7112 * @hw: hw specific details
7113 * @device_id: the device ID
7114 * @subdev_id: the subsystem device ID
7116 * This function is used by probe and ethtool to determine
7117 * which devices have WoL support
7120 int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
7123 struct ixgbe_hw *hw = &adapter->hw;
7124 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7125 int is_wol_supported = 0;
7127 switch (device_id) {
7128 case IXGBE_DEV_ID_82599_SFP:
7129 /* Only these subdevices could supports WOL */
7130 switch (subdevice_id) {
7131 case IXGBE_SUBDEV_ID_82599_560FLR:
7132 /* only support first port */
7133 if (hw->bus.func != 0)
7135 case IXGBE_SUBDEV_ID_82599_SFP:
7136 case IXGBE_SUBDEV_ID_82599_RNDC:
7137 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
7138 is_wol_supported = 1;
7142 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7143 /* All except this subdevice support WOL */
7144 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7145 is_wol_supported = 1;
7147 case IXGBE_DEV_ID_82599_KX4:
7148 is_wol_supported = 1;
7150 case IXGBE_DEV_ID_X540T:
7151 case IXGBE_DEV_ID_X540T1:
7152 /* check eeprom to see if enabled wol */
7153 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7154 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7155 (hw->bus.func == 0))) {
7156 is_wol_supported = 1;
7161 return is_wol_supported;
7165 * ixgbe_probe - Device Initialization Routine
7166 * @pdev: PCI device information struct
7167 * @ent: entry in ixgbe_pci_tbl
7169 * Returns 0 on success, negative on failure
7171 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7172 * The OS initialization, configuring of the adapter private structure,
7173 * and a hardware reset occur.
7175 static int __devinit ixgbe_probe(struct pci_dev *pdev,
7176 const struct pci_device_id *ent)
7178 struct net_device *netdev;
7179 struct ixgbe_adapter *adapter = NULL;
7180 struct ixgbe_hw *hw;
7181 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
7182 static int cards_found;
7183 int i, err, pci_using_dac;
7184 u8 part_str[IXGBE_PBANUM_LENGTH];
7185 unsigned int indices = num_possible_cpus();
7186 unsigned int dcb_max = 0;
7192 /* Catch broken hardware that put the wrong VF device ID in
7193 * the PCIe SR-IOV capability.
7195 if (pdev->is_virtfn) {
7196 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7197 pci_name(pdev), pdev->vendor, pdev->device);
7201 err = pci_enable_device_mem(pdev);
7205 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7206 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
7209 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
7211 err = dma_set_coherent_mask(&pdev->dev,
7215 "No usable DMA configuration, aborting\n");
7222 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
7223 IORESOURCE_MEM), ixgbe_driver_name);
7226 "pci_request_selected_regions failed 0x%x\n", err);
7230 pci_enable_pcie_error_reporting(pdev);
7232 pci_set_master(pdev);
7233 pci_save_state(pdev);
7235 #ifdef CONFIG_IXGBE_DCB
7236 if (ii->mac == ixgbe_mac_82598EB)
7237 dcb_max = min_t(unsigned int, indices * MAX_TRAFFIC_CLASS,
7238 IXGBE_MAX_RSS_INDICES);
7240 dcb_max = min_t(unsigned int, indices * MAX_TRAFFIC_CLASS,
7241 IXGBE_MAX_FDIR_INDICES);
7244 if (ii->mac == ixgbe_mac_82598EB)
7245 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7247 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7250 indices += min_t(unsigned int, num_possible_cpus(),
7251 IXGBE_MAX_FCOE_INDICES);
7253 indices = max_t(unsigned int, dcb_max, indices);
7254 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
7257 goto err_alloc_etherdev;
7260 SET_NETDEV_DEV(netdev, &pdev->dev);
7262 adapter = netdev_priv(netdev);
7263 pci_set_drvdata(pdev, adapter);
7265 adapter->netdev = netdev;
7266 adapter->pdev = pdev;
7269 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
7271 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
7272 pci_resource_len(pdev, 0));
7278 netdev->netdev_ops = &ixgbe_netdev_ops;
7279 ixgbe_set_ethtool_ops(netdev);
7280 netdev->watchdog_timeo = 5 * HZ;
7281 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
7283 adapter->bd_number = cards_found;
7286 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
7287 hw->mac.type = ii->mac;
7290 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7291 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7292 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7293 if (!(eec & (1 << 8)))
7294 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7297 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
7298 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
7299 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7300 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7301 hw->phy.mdio.mmds = 0;
7302 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7303 hw->phy.mdio.dev = netdev;
7304 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7305 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
7307 ii->get_invariants(hw);
7309 /* setup the private structure */
7310 err = ixgbe_sw_init(adapter);
7314 /* Make it possible the adapter to be woken up via WOL */
7315 switch (adapter->hw.mac.type) {
7316 case ixgbe_mac_82599EB:
7317 case ixgbe_mac_X540:
7318 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
7325 * If there is a fan on this device and it has failed log the
7328 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7329 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7330 if (esdp & IXGBE_ESDP_SDP1)
7331 e_crit(probe, "Fan has stopped, replace the adapter\n");
7334 if (allow_unsupported_sfp)
7335 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7337 /* reset_hw fills in the perm_addr as well */
7338 hw->phy.reset_if_overtemp = true;
7339 err = hw->mac.ops.reset_hw(hw);
7340 hw->phy.reset_if_overtemp = false;
7341 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7342 hw->mac.type == ixgbe_mac_82598EB) {
7344 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
7345 e_dev_err("failed to load because an unsupported SFP+ "
7346 "module type was detected.\n");
7347 e_dev_err("Reload the driver after installing a supported "
7351 e_dev_err("HW Init failed: %d\n", err);
7355 #ifdef CONFIG_PCI_IOV
7356 ixgbe_enable_sriov(adapter, ii);
7359 netdev->features = NETIF_F_SG |
7362 NETIF_F_HW_VLAN_TX |
7363 NETIF_F_HW_VLAN_RX |
7364 NETIF_F_HW_VLAN_FILTER |
7370 netdev->hw_features = netdev->features;
7372 switch (adapter->hw.mac.type) {
7373 case ixgbe_mac_82599EB:
7374 case ixgbe_mac_X540:
7375 netdev->features |= NETIF_F_SCTP_CSUM;
7376 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7383 netdev->hw_features |= NETIF_F_RXALL;
7385 netdev->vlan_features |= NETIF_F_TSO;
7386 netdev->vlan_features |= NETIF_F_TSO6;
7387 netdev->vlan_features |= NETIF_F_IP_CSUM;
7388 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
7389 netdev->vlan_features |= NETIF_F_SG;
7391 netdev->priv_flags |= IFF_UNICAST_FLT;
7392 netdev->priv_flags |= IFF_SUPP_NOFCS;
7394 #ifdef CONFIG_IXGBE_DCB
7395 netdev->dcbnl_ops = &dcbnl_ops;
7399 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7400 if (hw->mac.ops.get_device_caps) {
7401 hw->mac.ops.get_device_caps(hw, &device_caps);
7402 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7403 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
7406 adapter->ring_feature[RING_F_FCOE].limit = IXGBE_FCRETA_SIZE;
7408 netdev->features |= NETIF_F_FSO |
7411 netdev->vlan_features |= NETIF_F_FSO |
7415 #endif /* IXGBE_FCOE */
7416 if (pci_using_dac) {
7417 netdev->features |= NETIF_F_HIGHDMA;
7418 netdev->vlan_features |= NETIF_F_HIGHDMA;
7421 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7422 netdev->hw_features |= NETIF_F_LRO;
7423 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
7424 netdev->features |= NETIF_F_LRO;
7426 /* make sure the EEPROM is good */
7427 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
7428 e_dev_err("The EEPROM Checksum Is Not Valid\n");
7433 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7434 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7436 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
7437 e_dev_err("invalid MAC address\n");
7442 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7443 (unsigned long) adapter);
7445 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7446 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
7448 err = ixgbe_init_interrupt_scheme(adapter);
7452 /* WOL not supported for all devices */
7454 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7455 if (ixgbe_wol_supported(adapter, pdev->device, pdev->subsystem_device))
7456 adapter->wol = IXGBE_WUFC_MAG;
7458 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7460 /* save off EEPROM version number */
7461 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7462 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7464 /* pick up the PCI bus settings for reporting later */
7465 hw->mac.ops.get_bus_info(hw);
7467 /* print bus type/speed/width info */
7468 e_dev_info("(PCI Express:%s:%s) %pM\n",
7469 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7470 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
7472 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7473 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7474 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7478 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7480 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
7481 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
7482 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
7483 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
7486 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7487 hw->mac.type, hw->phy.type, part_str);
7489 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
7490 e_dev_warn("PCI-Express bandwidth available for this card is "
7491 "not sufficient for optimal performance.\n");
7492 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7496 /* reset the hardware with the new settings */
7497 err = hw->mac.ops.start_hw(hw);
7498 if (err == IXGBE_ERR_EEPROM_VERSION) {
7499 /* We are running on a pre-production device, log a warning */
7500 e_dev_warn("This device is a pre-production adapter/LOM. "
7501 "Please be aware there may be issues associated "
7502 "with your hardware. If you are experiencing "
7503 "problems please contact your Intel or hardware "
7504 "representative who provided you with this "
7507 strcpy(netdev->name, "eth%d");
7508 err = register_netdev(netdev);
7512 /* power down the optics for 82599 SFP+ fiber */
7513 if (hw->mac.ops.disable_tx_laser)
7514 hw->mac.ops.disable_tx_laser(hw);
7516 /* carrier off reporting is important to ethtool even BEFORE open */
7517 netif_carrier_off(netdev);
7519 #ifdef CONFIG_IXGBE_DCA
7520 if (dca_add_requester(&pdev->dev) == 0) {
7521 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
7522 ixgbe_setup_dca(adapter);
7525 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7526 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
7527 for (i = 0; i < adapter->num_vfs; i++)
7528 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7531 /* firmware requires driver version to be 0xFFFFFFFF
7532 * since os does not support feature
7534 if (hw->mac.ops.set_fw_drv_ver)
7535 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7538 /* add san mac addr to netdev */
7539 ixgbe_add_sanmac_netdev(netdev);
7541 e_dev_info("%s\n", ixgbe_default_device_descr);
7544 #ifdef CONFIG_IXGBE_HWMON
7545 if (ixgbe_sysfs_init(adapter))
7546 e_err(probe, "failed to allocate sysfs resources\n");
7547 #endif /* CONFIG_IXGBE_HWMON */
7549 #ifdef CONFIG_DEBUG_FS
7550 ixgbe_dbg_adapter_init(adapter);
7551 #endif /* CONFIG_DEBUG_FS */
7556 ixgbe_release_hw_control(adapter);
7557 ixgbe_clear_interrupt_scheme(adapter);
7559 ixgbe_disable_sriov(adapter);
7560 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
7561 iounmap(hw->hw_addr);
7563 free_netdev(netdev);
7565 pci_release_selected_regions(pdev,
7566 pci_select_bars(pdev, IORESOURCE_MEM));
7569 pci_disable_device(pdev);
7574 * ixgbe_remove - Device Removal Routine
7575 * @pdev: PCI device information struct
7577 * ixgbe_remove is called by the PCI subsystem to alert the driver
7578 * that it should release a PCI device. The could be caused by a
7579 * Hot-Plug event, or because the driver is going to be removed from
7582 static void __devexit ixgbe_remove(struct pci_dev *pdev)
7584 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7585 struct net_device *netdev = adapter->netdev;
7587 #ifdef CONFIG_DEBUG_FS
7588 ixgbe_dbg_adapter_exit(adapter);
7589 #endif /*CONFIG_DEBUG_FS */
7591 set_bit(__IXGBE_DOWN, &adapter->state);
7592 cancel_work_sync(&adapter->service_task);
7595 #ifdef CONFIG_IXGBE_DCA
7596 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7597 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7598 dca_remove_requester(&pdev->dev);
7599 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7603 #ifdef CONFIG_IXGBE_HWMON
7604 ixgbe_sysfs_exit(adapter);
7605 #endif /* CONFIG_IXGBE_HWMON */
7607 /* remove the added san mac */
7608 ixgbe_del_sanmac_netdev(netdev);
7610 if (netdev->reg_state == NETREG_REGISTERED)
7611 unregister_netdev(netdev);
7613 ixgbe_disable_sriov(adapter);
7615 ixgbe_clear_interrupt_scheme(adapter);
7617 ixgbe_release_hw_control(adapter);
7620 kfree(adapter->ixgbe_ieee_pfc);
7621 kfree(adapter->ixgbe_ieee_ets);
7624 iounmap(adapter->hw.hw_addr);
7625 pci_release_selected_regions(pdev, pci_select_bars(pdev,
7628 e_dev_info("complete\n");
7630 free_netdev(netdev);
7632 pci_disable_pcie_error_reporting(pdev);
7634 pci_disable_device(pdev);
7638 * ixgbe_io_error_detected - called when PCI error is detected
7639 * @pdev: Pointer to PCI device
7640 * @state: The current pci connection state
7642 * This function is called after a PCI bus error affecting
7643 * this device has been detected.
7645 static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
7646 pci_channel_state_t state)
7648 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7649 struct net_device *netdev = adapter->netdev;
7651 #ifdef CONFIG_PCI_IOV
7652 struct pci_dev *bdev, *vfdev;
7653 u32 dw0, dw1, dw2, dw3;
7655 u16 req_id, pf_func;
7657 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7658 adapter->num_vfs == 0)
7659 goto skip_bad_vf_detection;
7661 bdev = pdev->bus->self;
7662 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
7663 bdev = bdev->bus->self;
7666 goto skip_bad_vf_detection;
7668 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
7670 goto skip_bad_vf_detection;
7672 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
7673 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
7674 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
7675 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
7678 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
7679 if (!(req_id & 0x0080))
7680 goto skip_bad_vf_detection;
7682 pf_func = req_id & 0x01;
7683 if ((pf_func & 1) == (pdev->devfn & 1)) {
7684 unsigned int device_id;
7686 vf = (req_id & 0x7F) >> 1;
7687 e_dev_err("VF %d has caused a PCIe error\n", vf);
7688 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
7689 "%8.8x\tdw3: %8.8x\n",
7690 dw0, dw1, dw2, dw3);
7691 switch (adapter->hw.mac.type) {
7692 case ixgbe_mac_82599EB:
7693 device_id = IXGBE_82599_VF_DEVICE_ID;
7695 case ixgbe_mac_X540:
7696 device_id = IXGBE_X540_VF_DEVICE_ID;
7703 /* Find the pci device of the offending VF */
7704 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
7706 if (vfdev->devfn == (req_id & 0xFF))
7708 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
7712 * There's a slim chance the VF could have been hot plugged,
7713 * so if it is no longer present we don't need to issue the
7714 * VFLR. Just clean up the AER in that case.
7717 e_dev_err("Issuing VFLR to VF %d\n", vf);
7718 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
7721 pci_cleanup_aer_uncorrect_error_status(pdev);
7725 * Even though the error may have occurred on the other port
7726 * we still need to increment the vf error reference count for
7727 * both ports because the I/O resume function will be called
7730 adapter->vferr_refcount++;
7732 return PCI_ERS_RESULT_RECOVERED;
7734 skip_bad_vf_detection:
7735 #endif /* CONFIG_PCI_IOV */
7736 netif_device_detach(netdev);
7738 if (state == pci_channel_io_perm_failure)
7739 return PCI_ERS_RESULT_DISCONNECT;
7741 if (netif_running(netdev))
7742 ixgbe_down(adapter);
7743 pci_disable_device(pdev);
7745 /* Request a slot reset. */
7746 return PCI_ERS_RESULT_NEED_RESET;
7750 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7751 * @pdev: Pointer to PCI device
7753 * Restart the card from scratch, as if from a cold-boot.
7755 static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7757 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7758 pci_ers_result_t result;
7761 if (pci_enable_device_mem(pdev)) {
7762 e_err(probe, "Cannot re-enable PCI device after reset.\n");
7763 result = PCI_ERS_RESULT_DISCONNECT;
7765 pci_set_master(pdev);
7766 pci_restore_state(pdev);
7767 pci_save_state(pdev);
7769 pci_wake_from_d3(pdev, false);
7771 ixgbe_reset(adapter);
7772 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
7773 result = PCI_ERS_RESULT_RECOVERED;
7776 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7778 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7779 "failed 0x%0x\n", err);
7780 /* non-fatal, continue */
7787 * ixgbe_io_resume - called when traffic can start flowing again.
7788 * @pdev: Pointer to PCI device
7790 * This callback is called when the error recovery driver tells us that
7791 * its OK to resume normal operation.
7793 static void ixgbe_io_resume(struct pci_dev *pdev)
7795 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7796 struct net_device *netdev = adapter->netdev;
7798 #ifdef CONFIG_PCI_IOV
7799 if (adapter->vferr_refcount) {
7800 e_info(drv, "Resuming after VF err\n");
7801 adapter->vferr_refcount--;
7806 if (netif_running(netdev))
7809 netif_device_attach(netdev);
7812 static const struct pci_error_handlers ixgbe_err_handler = {
7813 .error_detected = ixgbe_io_error_detected,
7814 .slot_reset = ixgbe_io_slot_reset,
7815 .resume = ixgbe_io_resume,
7818 static struct pci_driver ixgbe_driver = {
7819 .name = ixgbe_driver_name,
7820 .id_table = ixgbe_pci_tbl,
7821 .probe = ixgbe_probe,
7822 .remove = __devexit_p(ixgbe_remove),
7824 .suspend = ixgbe_suspend,
7825 .resume = ixgbe_resume,
7827 .shutdown = ixgbe_shutdown,
7828 .err_handler = &ixgbe_err_handler
7832 * ixgbe_init_module - Driver Registration Routine
7834 * ixgbe_init_module is the first routine called when the driver is
7835 * loaded. All it does is register with the PCI subsystem.
7837 static int __init ixgbe_init_module(void)
7840 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
7841 pr_info("%s\n", ixgbe_copyright);
7843 #ifdef CONFIG_DEBUG_FS
7845 #endif /* CONFIG_DEBUG_FS */
7847 #ifdef CONFIG_IXGBE_DCA
7848 dca_register_notify(&dca_notifier);
7851 ret = pci_register_driver(&ixgbe_driver);
7855 module_init(ixgbe_init_module);
7858 * ixgbe_exit_module - Driver Exit Cleanup Routine
7860 * ixgbe_exit_module is called just before the driver is removed
7863 static void __exit ixgbe_exit_module(void)
7865 #ifdef CONFIG_IXGBE_DCA
7866 dca_unregister_notify(&dca_notifier);
7868 pci_unregister_driver(&ixgbe_driver);
7870 #ifdef CONFIG_DEBUG_FS
7872 #endif /* CONFIG_DEBUG_FS */
7874 rcu_barrier(); /* Wait for completion of call_rcu()'s */
7877 #ifdef CONFIG_IXGBE_DCA
7878 static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
7883 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
7884 __ixgbe_notify_dca);
7886 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7889 #endif /* CONFIG_IXGBE_DCA */
7891 module_exit(ixgbe_exit_module);