1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2014 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 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 #include <linux/types.h>
30 #include <linux/module.h>
31 #include <linux/pci.h>
32 #include <linux/netdevice.h>
33 #include <linux/vmalloc.h>
34 #include <linux/string.h>
36 #include <linux/interrupt.h>
38 #include <linux/tcp.h>
39 #include <linux/sctp.h>
40 #include <linux/pkt_sched.h>
41 #include <linux/ipv6.h>
42 #include <linux/slab.h>
43 #include <net/checksum.h>
44 #include <net/ip6_checksum.h>
45 #include <linux/etherdevice.h>
46 #include <linux/ethtool.h>
48 #include <linux/if_vlan.h>
49 #include <linux/if_macvlan.h>
50 #include <linux/if_bridge.h>
51 #include <linux/prefetch.h>
52 #include <scsi/fc/fc_fcoe.h>
53 #include <net/vxlan.h>
56 #include <linux/of_net.h>
60 #include <asm/idprom.h>
65 #include "ixgbe_common.h"
66 #include "ixgbe_dcb_82599.h"
67 #include "ixgbe_sriov.h"
69 char ixgbe_driver_name[] = "ixgbe";
70 static const char ixgbe_driver_string[] =
71 "Intel(R) 10 Gigabit PCI Express Network Driver";
73 char ixgbe_default_device_descr[] =
74 "Intel(R) 10 Gigabit Network Connection";
76 static char ixgbe_default_device_descr[] =
77 "Intel(R) 10 Gigabit Network Connection";
79 #define DRV_VERSION "4.0.1-k"
80 const char ixgbe_driver_version[] = DRV_VERSION;
81 static const char ixgbe_copyright[] =
82 "Copyright (c) 1999-2014 Intel Corporation.";
84 static const char ixgbe_overheat_msg[] = "Network adapter has been stopped because it has over heated. Restart the computer. If the problem persists, power off the system and replace the adapter";
86 static const struct ixgbe_info *ixgbe_info_tbl[] = {
87 [board_82598] = &ixgbe_82598_info,
88 [board_82599] = &ixgbe_82599_info,
89 [board_X540] = &ixgbe_X540_info,
90 [board_X550] = &ixgbe_X550_info,
91 [board_X550EM_x] = &ixgbe_X550EM_x_info,
94 /* ixgbe_pci_tbl - PCI Device ID Table
96 * Wildcard entries (PCI_ANY_ID) should come last
97 * Last entry must be all 0s
99 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
100 * Class, Class Mask, private data (not used) }
102 static const struct pci_device_id ixgbe_pci_tbl[] = {
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
118 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
119 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
120 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
121 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
122 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
123 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
124 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
125 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
126 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
127 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
128 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
129 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 },
130 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
131 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
132 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
133 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550},
134 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x},
135 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x},
136 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x},
137 /* required last entry */
140 MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
142 #ifdef CONFIG_IXGBE_DCA
143 static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
145 static struct notifier_block dca_notifier = {
146 .notifier_call = ixgbe_notify_dca,
152 #ifdef CONFIG_PCI_IOV
153 static unsigned int max_vfs;
154 module_param(max_vfs, uint, 0);
155 MODULE_PARM_DESC(max_vfs,
156 "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63. (Deprecated)");
157 #endif /* CONFIG_PCI_IOV */
159 static unsigned int allow_unsupported_sfp;
160 module_param(allow_unsupported_sfp, uint, 0);
161 MODULE_PARM_DESC(allow_unsupported_sfp,
162 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
164 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
165 static int debug = -1;
166 module_param(debug, int, 0);
167 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
169 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
170 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
171 MODULE_LICENSE("GPL");
172 MODULE_VERSION(DRV_VERSION);
174 static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
176 static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
179 struct pci_dev *parent_dev;
180 struct pci_bus *parent_bus;
182 parent_bus = adapter->pdev->bus->parent;
186 parent_dev = parent_bus->self;
190 if (!pci_is_pcie(parent_dev))
193 pcie_capability_read_word(parent_dev, reg, value);
194 if (*value == IXGBE_FAILED_READ_CFG_WORD &&
195 ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
200 static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
202 struct ixgbe_hw *hw = &adapter->hw;
206 hw->bus.type = ixgbe_bus_type_pci_express;
208 /* Get the negotiated link width and speed from PCI config space of the
209 * parent, as this device is behind a switch
211 err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
213 /* assume caller will handle error case */
217 hw->bus.width = ixgbe_convert_bus_width(link_status);
218 hw->bus.speed = ixgbe_convert_bus_speed(link_status);
224 * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
225 * @hw: hw specific details
227 * This function is used by probe to determine whether a device's PCI-Express
228 * bandwidth details should be gathered from the parent bus instead of from the
229 * device. Used to ensure that various locations all have the correct device ID
232 static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
234 switch (hw->device_id) {
235 case IXGBE_DEV_ID_82599_SFP_SF_QP:
236 case IXGBE_DEV_ID_82599_QSFP_SF_QP:
243 static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
247 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
248 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
249 struct pci_dev *pdev;
251 /* determine whether to use the parent device */
252 if (ixgbe_pcie_from_parent(&adapter->hw))
253 pdev = adapter->pdev->bus->parent->self;
255 pdev = adapter->pdev;
257 if (pcie_get_minimum_link(pdev, &speed, &width) ||
258 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
259 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
264 case PCIE_SPEED_2_5GT:
265 /* 8b/10b encoding reduces max throughput by 20% */
268 case PCIE_SPEED_5_0GT:
269 /* 8b/10b encoding reduces max throughput by 20% */
272 case PCIE_SPEED_8_0GT:
273 /* 128b/130b encoding reduces throughput by less than 2% */
277 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
281 e_dev_info("PCI Express bandwidth of %dGT/s available\n",
283 e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n",
284 (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
285 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
286 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
289 (speed == PCIE_SPEED_2_5GT ? "20%" :
290 speed == PCIE_SPEED_5_0GT ? "20%" :
291 speed == PCIE_SPEED_8_0GT ? "<2%" :
294 if (max_gts < expected_gts) {
295 e_dev_warn("This is not sufficient for optimal performance of this card.\n");
296 e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n",
298 e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n");
302 static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
304 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
305 !test_bit(__IXGBE_REMOVING, &adapter->state) &&
306 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
307 schedule_work(&adapter->service_task);
310 static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
312 struct ixgbe_adapter *adapter = hw->back;
317 e_dev_err("Adapter removed\n");
318 if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
319 ixgbe_service_event_schedule(adapter);
322 static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
326 /* The following check not only optimizes a bit by not
327 * performing a read on the status register when the
328 * register just read was a status register read that
329 * returned IXGBE_FAILED_READ_REG. It also blocks any
330 * potential recursion.
332 if (reg == IXGBE_STATUS) {
333 ixgbe_remove_adapter(hw);
336 value = ixgbe_read_reg(hw, IXGBE_STATUS);
337 if (value == IXGBE_FAILED_READ_REG)
338 ixgbe_remove_adapter(hw);
342 * ixgbe_read_reg - Read from device register
343 * @hw: hw specific details
344 * @reg: offset of register to read
346 * Returns : value read or IXGBE_FAILED_READ_REG if removed
348 * This function is used to read device registers. It checks for device
349 * removal by confirming any read that returns all ones by checking the
350 * status register value for all ones. This function avoids reading from
351 * the hardware if a removal was previously detected in which case it
352 * returns IXGBE_FAILED_READ_REG (all ones).
354 u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
356 u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
359 if (ixgbe_removed(reg_addr))
360 return IXGBE_FAILED_READ_REG;
361 value = readl(reg_addr + reg);
362 if (unlikely(value == IXGBE_FAILED_READ_REG))
363 ixgbe_check_remove(hw, reg);
367 static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
371 pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
372 if (value == IXGBE_FAILED_READ_CFG_WORD) {
373 ixgbe_remove_adapter(hw);
379 u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
381 struct ixgbe_adapter *adapter = hw->back;
384 if (ixgbe_removed(hw->hw_addr))
385 return IXGBE_FAILED_READ_CFG_WORD;
386 pci_read_config_word(adapter->pdev, reg, &value);
387 if (value == IXGBE_FAILED_READ_CFG_WORD &&
388 ixgbe_check_cfg_remove(hw, adapter->pdev))
389 return IXGBE_FAILED_READ_CFG_WORD;
393 #ifdef CONFIG_PCI_IOV
394 static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
396 struct ixgbe_adapter *adapter = hw->back;
399 if (ixgbe_removed(hw->hw_addr))
400 return IXGBE_FAILED_READ_CFG_DWORD;
401 pci_read_config_dword(adapter->pdev, reg, &value);
402 if (value == IXGBE_FAILED_READ_CFG_DWORD &&
403 ixgbe_check_cfg_remove(hw, adapter->pdev))
404 return IXGBE_FAILED_READ_CFG_DWORD;
407 #endif /* CONFIG_PCI_IOV */
409 void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
411 struct ixgbe_adapter *adapter = hw->back;
413 if (ixgbe_removed(hw->hw_addr))
415 pci_write_config_word(adapter->pdev, reg, value);
418 static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
420 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
422 /* flush memory to make sure state is correct before next watchdog */
423 smp_mb__before_atomic();
424 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
427 struct ixgbe_reg_info {
432 static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
434 /* General Registers */
435 {IXGBE_CTRL, "CTRL"},
436 {IXGBE_STATUS, "STATUS"},
437 {IXGBE_CTRL_EXT, "CTRL_EXT"},
439 /* Interrupt Registers */
440 {IXGBE_EICR, "EICR"},
443 {IXGBE_SRRCTL(0), "SRRCTL"},
444 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
445 {IXGBE_RDLEN(0), "RDLEN"},
446 {IXGBE_RDH(0), "RDH"},
447 {IXGBE_RDT(0), "RDT"},
448 {IXGBE_RXDCTL(0), "RXDCTL"},
449 {IXGBE_RDBAL(0), "RDBAL"},
450 {IXGBE_RDBAH(0), "RDBAH"},
453 {IXGBE_TDBAL(0), "TDBAL"},
454 {IXGBE_TDBAH(0), "TDBAH"},
455 {IXGBE_TDLEN(0), "TDLEN"},
456 {IXGBE_TDH(0), "TDH"},
457 {IXGBE_TDT(0), "TDT"},
458 {IXGBE_TXDCTL(0), "TXDCTL"},
460 /* List Terminator */
466 * ixgbe_regdump - register printout routine
468 static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
474 switch (reginfo->ofs) {
475 case IXGBE_SRRCTL(0):
476 for (i = 0; i < 64; i++)
477 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
479 case IXGBE_DCA_RXCTRL(0):
480 for (i = 0; i < 64; i++)
481 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
484 for (i = 0; i < 64; i++)
485 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
488 for (i = 0; i < 64; i++)
489 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
492 for (i = 0; i < 64; i++)
493 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
495 case IXGBE_RXDCTL(0):
496 for (i = 0; i < 64; i++)
497 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
500 for (i = 0; i < 64; i++)
501 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
504 for (i = 0; i < 64; i++)
505 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
508 for (i = 0; i < 64; i++)
509 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
512 for (i = 0; i < 64; i++)
513 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
516 for (i = 0; i < 64; i++)
517 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
520 for (i = 0; i < 64; i++)
521 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
524 for (i = 0; i < 64; i++)
525 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
527 case IXGBE_TXDCTL(0):
528 for (i = 0; i < 64; i++)
529 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
532 pr_info("%-15s %08x\n", reginfo->name,
533 IXGBE_READ_REG(hw, reginfo->ofs));
537 for (i = 0; i < 8; i++) {
538 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
539 pr_err("%-15s", rname);
540 for (j = 0; j < 8; j++)
541 pr_cont(" %08x", regs[i*8+j]);
548 * ixgbe_dump - Print registers, tx-rings and rx-rings
550 static void ixgbe_dump(struct ixgbe_adapter *adapter)
552 struct net_device *netdev = adapter->netdev;
553 struct ixgbe_hw *hw = &adapter->hw;
554 struct ixgbe_reg_info *reginfo;
556 struct ixgbe_ring *tx_ring;
557 struct ixgbe_tx_buffer *tx_buffer;
558 union ixgbe_adv_tx_desc *tx_desc;
559 struct my_u0 { u64 a; u64 b; } *u0;
560 struct ixgbe_ring *rx_ring;
561 union ixgbe_adv_rx_desc *rx_desc;
562 struct ixgbe_rx_buffer *rx_buffer_info;
566 if (!netif_msg_hw(adapter))
569 /* Print netdevice Info */
571 dev_info(&adapter->pdev->dev, "Net device Info\n");
572 pr_info("Device Name state "
573 "trans_start last_rx\n");
574 pr_info("%-15s %016lX %016lX %016lX\n",
581 /* Print Registers */
582 dev_info(&adapter->pdev->dev, "Register Dump\n");
583 pr_info(" Register Name Value\n");
584 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
585 reginfo->name; reginfo++) {
586 ixgbe_regdump(hw, reginfo);
589 /* Print TX Ring Summary */
590 if (!netdev || !netif_running(netdev))
593 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
594 pr_info(" %s %s %s %s\n",
595 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
596 "leng", "ntw", "timestamp");
597 for (n = 0; n < adapter->num_tx_queues; n++) {
598 tx_ring = adapter->tx_ring[n];
599 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
600 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
601 n, tx_ring->next_to_use, tx_ring->next_to_clean,
602 (u64)dma_unmap_addr(tx_buffer, dma),
603 dma_unmap_len(tx_buffer, len),
604 tx_buffer->next_to_watch,
605 (u64)tx_buffer->time_stamp);
609 if (!netif_msg_tx_done(adapter))
610 goto rx_ring_summary;
612 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
614 /* Transmit Descriptor Formats
616 * 82598 Advanced Transmit Descriptor
617 * +--------------------------------------------------------------+
618 * 0 | Buffer Address [63:0] |
619 * +--------------------------------------------------------------+
620 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
621 * +--------------------------------------------------------------+
622 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
624 * 82598 Advanced Transmit Descriptor (Write-Back Format)
625 * +--------------------------------------------------------------+
627 * +--------------------------------------------------------------+
628 * 8 | RSV | STA | NXTSEQ |
629 * +--------------------------------------------------------------+
632 * 82599+ Advanced Transmit Descriptor
633 * +--------------------------------------------------------------+
634 * 0 | Buffer Address [63:0] |
635 * +--------------------------------------------------------------+
636 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
637 * +--------------------------------------------------------------+
638 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
640 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
641 * +--------------------------------------------------------------+
643 * +--------------------------------------------------------------+
644 * 8 | RSV | STA | RSV |
645 * +--------------------------------------------------------------+
649 for (n = 0; n < adapter->num_tx_queues; n++) {
650 tx_ring = adapter->tx_ring[n];
651 pr_info("------------------------------------\n");
652 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
653 pr_info("------------------------------------\n");
654 pr_info("%s%s %s %s %s %s\n",
655 "T [desc] [address 63:0 ] ",
656 "[PlPOIdStDDt Ln] [bi->dma ] ",
657 "leng", "ntw", "timestamp", "bi->skb");
659 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
660 tx_desc = IXGBE_TX_DESC(tx_ring, i);
661 tx_buffer = &tx_ring->tx_buffer_info[i];
662 u0 = (struct my_u0 *)tx_desc;
663 if (dma_unmap_len(tx_buffer, len) > 0) {
664 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
668 (u64)dma_unmap_addr(tx_buffer, dma),
669 dma_unmap_len(tx_buffer, len),
670 tx_buffer->next_to_watch,
671 (u64)tx_buffer->time_stamp,
673 if (i == tx_ring->next_to_use &&
674 i == tx_ring->next_to_clean)
676 else if (i == tx_ring->next_to_use)
678 else if (i == tx_ring->next_to_clean)
683 if (netif_msg_pktdata(adapter) &&
685 print_hex_dump(KERN_INFO, "",
686 DUMP_PREFIX_ADDRESS, 16, 1,
687 tx_buffer->skb->data,
688 dma_unmap_len(tx_buffer, len),
694 /* Print RX Rings Summary */
696 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
697 pr_info("Queue [NTU] [NTC]\n");
698 for (n = 0; n < adapter->num_rx_queues; n++) {
699 rx_ring = adapter->rx_ring[n];
700 pr_info("%5d %5X %5X\n",
701 n, rx_ring->next_to_use, rx_ring->next_to_clean);
705 if (!netif_msg_rx_status(adapter))
708 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
710 /* Receive Descriptor Formats
712 * 82598 Advanced Receive Descriptor (Read) Format
714 * +-----------------------------------------------------+
715 * 0 | Packet Buffer Address [63:1] |A0/NSE|
716 * +----------------------------------------------+------+
717 * 8 | Header Buffer Address [63:1] | DD |
718 * +-----------------------------------------------------+
721 * 82598 Advanced Receive Descriptor (Write-Back) Format
723 * 63 48 47 32 31 30 21 20 16 15 4 3 0
724 * +------------------------------------------------------+
725 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
726 * | Packet | IP | | | | Type | Type |
727 * | Checksum | Ident | | | | | |
728 * +------------------------------------------------------+
729 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
730 * +------------------------------------------------------+
731 * 63 48 47 32 31 20 19 0
733 * 82599+ Advanced Receive Descriptor (Read) Format
735 * +-----------------------------------------------------+
736 * 0 | Packet Buffer Address [63:1] |A0/NSE|
737 * +----------------------------------------------+------+
738 * 8 | Header Buffer Address [63:1] | DD |
739 * +-----------------------------------------------------+
742 * 82599+ Advanced Receive Descriptor (Write-Back) Format
744 * 63 48 47 32 31 30 21 20 17 16 4 3 0
745 * +------------------------------------------------------+
746 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
747 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
748 * |/ Flow Dir Flt ID | | | | | |
749 * +------------------------------------------------------+
750 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
751 * +------------------------------------------------------+
752 * 63 48 47 32 31 20 19 0
755 for (n = 0; n < adapter->num_rx_queues; n++) {
756 rx_ring = adapter->rx_ring[n];
757 pr_info("------------------------------------\n");
758 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
759 pr_info("------------------------------------\n");
761 "R [desc] [ PktBuf A0] ",
762 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
763 "<-- Adv Rx Read format\n");
765 "RWB[desc] [PcsmIpSHl PtRs] ",
766 "[vl er S cks ln] ---------------- [bi->skb ] ",
767 "<-- Adv Rx Write-Back format\n");
769 for (i = 0; i < rx_ring->count; i++) {
770 rx_buffer_info = &rx_ring->rx_buffer_info[i];
771 rx_desc = IXGBE_RX_DESC(rx_ring, i);
772 u0 = (struct my_u0 *)rx_desc;
773 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
774 if (staterr & IXGBE_RXD_STAT_DD) {
775 /* Descriptor Done */
776 pr_info("RWB[0x%03X] %016llX "
777 "%016llX ---------------- %p", i,
780 rx_buffer_info->skb);
782 pr_info("R [0x%03X] %016llX "
783 "%016llX %016llX %p", i,
786 (u64)rx_buffer_info->dma,
787 rx_buffer_info->skb);
789 if (netif_msg_pktdata(adapter) &&
790 rx_buffer_info->dma) {
791 print_hex_dump(KERN_INFO, "",
792 DUMP_PREFIX_ADDRESS, 16, 1,
793 page_address(rx_buffer_info->page) +
794 rx_buffer_info->page_offset,
795 ixgbe_rx_bufsz(rx_ring), true);
799 if (i == rx_ring->next_to_use)
801 else if (i == rx_ring->next_to_clean)
810 static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
814 /* Let firmware take over control of h/w */
815 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
816 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
817 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
820 static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
824 /* Let firmware know the driver has taken over */
825 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
826 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
827 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
831 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
832 * @adapter: pointer to adapter struct
833 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
834 * @queue: queue to map the corresponding interrupt to
835 * @msix_vector: the vector to map to the corresponding queue
838 static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
839 u8 queue, u8 msix_vector)
842 struct ixgbe_hw *hw = &adapter->hw;
843 switch (hw->mac.type) {
844 case ixgbe_mac_82598EB:
845 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
848 index = (((direction * 64) + queue) >> 2) & 0x1F;
849 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
850 ivar &= ~(0xFF << (8 * (queue & 0x3)));
851 ivar |= (msix_vector << (8 * (queue & 0x3)));
852 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
854 case ixgbe_mac_82599EB:
857 case ixgbe_mac_X550EM_x:
858 if (direction == -1) {
860 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
861 index = ((queue & 1) * 8);
862 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
863 ivar &= ~(0xFF << index);
864 ivar |= (msix_vector << index);
865 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
868 /* tx or rx causes */
869 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
870 index = ((16 * (queue & 1)) + (8 * direction));
871 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
872 ivar &= ~(0xFF << index);
873 ivar |= (msix_vector << index);
874 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
882 static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
887 switch (adapter->hw.mac.type) {
888 case ixgbe_mac_82598EB:
889 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
890 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
892 case ixgbe_mac_82599EB:
895 case ixgbe_mac_X550EM_x:
896 mask = (qmask & 0xFFFFFFFF);
897 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
898 mask = (qmask >> 32);
899 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
906 void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
907 struct ixgbe_tx_buffer *tx_buffer)
909 if (tx_buffer->skb) {
910 dev_kfree_skb_any(tx_buffer->skb);
911 if (dma_unmap_len(tx_buffer, len))
912 dma_unmap_single(ring->dev,
913 dma_unmap_addr(tx_buffer, dma),
914 dma_unmap_len(tx_buffer, len),
916 } else if (dma_unmap_len(tx_buffer, len)) {
917 dma_unmap_page(ring->dev,
918 dma_unmap_addr(tx_buffer, dma),
919 dma_unmap_len(tx_buffer, len),
922 tx_buffer->next_to_watch = NULL;
923 tx_buffer->skb = NULL;
924 dma_unmap_len_set(tx_buffer, len, 0);
925 /* tx_buffer must be completely set up in the transmit path */
928 static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
930 struct ixgbe_hw *hw = &adapter->hw;
931 struct ixgbe_hw_stats *hwstats = &adapter->stats;
935 if ((hw->fc.current_mode != ixgbe_fc_full) &&
936 (hw->fc.current_mode != ixgbe_fc_rx_pause))
939 switch (hw->mac.type) {
940 case ixgbe_mac_82598EB:
941 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
944 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
946 hwstats->lxoffrxc += data;
948 /* refill credits (no tx hang) if we received xoff */
952 for (i = 0; i < adapter->num_tx_queues; i++)
953 clear_bit(__IXGBE_HANG_CHECK_ARMED,
954 &adapter->tx_ring[i]->state);
957 static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
959 struct ixgbe_hw *hw = &adapter->hw;
960 struct ixgbe_hw_stats *hwstats = &adapter->stats;
964 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
966 if (adapter->ixgbe_ieee_pfc)
967 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
969 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
970 ixgbe_update_xoff_rx_lfc(adapter);
974 /* update stats for each tc, only valid with PFC enabled */
975 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
978 switch (hw->mac.type) {
979 case ixgbe_mac_82598EB:
980 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
983 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
985 hwstats->pxoffrxc[i] += pxoffrxc;
986 /* Get the TC for given UP */
987 tc = netdev_get_prio_tc_map(adapter->netdev, i);
988 xoff[tc] += pxoffrxc;
991 /* disarm tx queues that have received xoff frames */
992 for (i = 0; i < adapter->num_tx_queues; i++) {
993 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
995 tc = tx_ring->dcb_tc;
997 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
1001 static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
1003 return ring->stats.packets;
1006 static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
1008 struct ixgbe_adapter *adapter;
1009 struct ixgbe_hw *hw;
1012 if (ring->l2_accel_priv)
1013 adapter = ring->l2_accel_priv->real_adapter;
1015 adapter = netdev_priv(ring->netdev);
1018 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
1019 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
1022 return (head < tail) ?
1023 tail - head : (tail + ring->count - head);
1028 static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
1030 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
1031 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
1032 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
1034 clear_check_for_tx_hang(tx_ring);
1037 * Check for a hung queue, but be thorough. This verifies
1038 * that a transmit has been completed since the previous
1039 * check AND there is at least one packet pending. The
1040 * ARMED bit is set to indicate a potential hang. The
1041 * bit is cleared if a pause frame is received to remove
1042 * false hang detection due to PFC or 802.3x frames. By
1043 * requiring this to fail twice we avoid races with
1044 * pfc clearing the ARMED bit and conditions where we
1045 * run the check_tx_hang logic with a transmit completion
1046 * pending but without time to complete it yet.
1048 if (tx_done_old == tx_done && tx_pending)
1049 /* make sure it is true for two checks in a row */
1050 return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
1052 /* update completed stats and continue */
1053 tx_ring->tx_stats.tx_done_old = tx_done;
1054 /* reset the countdown */
1055 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
1061 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1062 * @adapter: driver private struct
1064 static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
1067 /* Do the reset outside of interrupt context */
1068 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1069 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
1070 e_warn(drv, "initiating reset due to tx timeout\n");
1071 ixgbe_service_event_schedule(adapter);
1076 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
1077 * @q_vector: structure containing interrupt and ring information
1078 * @tx_ring: tx ring to clean
1080 static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
1081 struct ixgbe_ring *tx_ring)
1083 struct ixgbe_adapter *adapter = q_vector->adapter;
1084 struct ixgbe_tx_buffer *tx_buffer;
1085 union ixgbe_adv_tx_desc *tx_desc;
1086 unsigned int total_bytes = 0, total_packets = 0;
1087 unsigned int budget = q_vector->tx.work_limit;
1088 unsigned int i = tx_ring->next_to_clean;
1090 if (test_bit(__IXGBE_DOWN, &adapter->state))
1093 tx_buffer = &tx_ring->tx_buffer_info[i];
1094 tx_desc = IXGBE_TX_DESC(tx_ring, i);
1095 i -= tx_ring->count;
1098 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
1100 /* if next_to_watch is not set then there is no work pending */
1104 /* prevent any other reads prior to eop_desc */
1105 read_barrier_depends();
1107 /* if DD is not set pending work has not been completed */
1108 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
1111 /* clear next_to_watch to prevent false hangs */
1112 tx_buffer->next_to_watch = NULL;
1114 /* update the statistics for this packet */
1115 total_bytes += tx_buffer->bytecount;
1116 total_packets += tx_buffer->gso_segs;
1119 dev_consume_skb_any(tx_buffer->skb);
1121 /* unmap skb header data */
1122 dma_unmap_single(tx_ring->dev,
1123 dma_unmap_addr(tx_buffer, dma),
1124 dma_unmap_len(tx_buffer, len),
1127 /* clear tx_buffer data */
1128 tx_buffer->skb = NULL;
1129 dma_unmap_len_set(tx_buffer, len, 0);
1131 /* unmap remaining buffers */
1132 while (tx_desc != eop_desc) {
1137 i -= tx_ring->count;
1138 tx_buffer = tx_ring->tx_buffer_info;
1139 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1142 /* unmap any remaining paged data */
1143 if (dma_unmap_len(tx_buffer, len)) {
1144 dma_unmap_page(tx_ring->dev,
1145 dma_unmap_addr(tx_buffer, dma),
1146 dma_unmap_len(tx_buffer, len),
1148 dma_unmap_len_set(tx_buffer, len, 0);
1152 /* move us one more past the eop_desc for start of next pkt */
1157 i -= tx_ring->count;
1158 tx_buffer = tx_ring->tx_buffer_info;
1159 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1162 /* issue prefetch for next Tx descriptor */
1165 /* update budget accounting */
1167 } while (likely(budget));
1169 i += tx_ring->count;
1170 tx_ring->next_to_clean = i;
1171 u64_stats_update_begin(&tx_ring->syncp);
1172 tx_ring->stats.bytes += total_bytes;
1173 tx_ring->stats.packets += total_packets;
1174 u64_stats_update_end(&tx_ring->syncp);
1175 q_vector->tx.total_bytes += total_bytes;
1176 q_vector->tx.total_packets += total_packets;
1178 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
1179 /* schedule immediate reset if we believe we hung */
1180 struct ixgbe_hw *hw = &adapter->hw;
1181 e_err(drv, "Detected Tx Unit Hang\n"
1183 " TDH, TDT <%x>, <%x>\n"
1184 " next_to_use <%x>\n"
1185 " next_to_clean <%x>\n"
1186 "tx_buffer_info[next_to_clean]\n"
1187 " time_stamp <%lx>\n"
1189 tx_ring->queue_index,
1190 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
1191 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
1192 tx_ring->next_to_use, i,
1193 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
1195 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
1198 "tx hang %d detected on queue %d, resetting adapter\n",
1199 adapter->tx_timeout_count + 1, tx_ring->queue_index);
1201 /* schedule immediate reset if we believe we hung */
1202 ixgbe_tx_timeout_reset(adapter);
1204 /* the adapter is about to reset, no point in enabling stuff */
1208 netdev_tx_completed_queue(txring_txq(tx_ring),
1209 total_packets, total_bytes);
1211 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
1212 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
1213 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
1214 /* Make sure that anybody stopping the queue after this
1215 * sees the new next_to_clean.
1218 if (__netif_subqueue_stopped(tx_ring->netdev,
1219 tx_ring->queue_index)
1220 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1221 netif_wake_subqueue(tx_ring->netdev,
1222 tx_ring->queue_index);
1223 ++tx_ring->tx_stats.restart_queue;
1230 #ifdef CONFIG_IXGBE_DCA
1231 static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
1232 struct ixgbe_ring *tx_ring,
1235 struct ixgbe_hw *hw = &adapter->hw;
1236 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1239 switch (hw->mac.type) {
1240 case ixgbe_mac_82598EB:
1241 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
1243 case ixgbe_mac_82599EB:
1244 case ixgbe_mac_X540:
1245 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1246 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1249 /* for unknown hardware do not write register */
1254 * We can enable relaxed ordering for reads, but not writes when
1255 * DCA is enabled. This is due to a known issue in some chipsets
1256 * which will cause the DCA tag to be cleared.
1258 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1259 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1260 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1262 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1265 static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1266 struct ixgbe_ring *rx_ring,
1269 struct ixgbe_hw *hw = &adapter->hw;
1270 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
1271 u8 reg_idx = rx_ring->reg_idx;
1274 switch (hw->mac.type) {
1275 case ixgbe_mac_82599EB:
1276 case ixgbe_mac_X540:
1277 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
1284 * We can enable relaxed ordering for reads, but not writes when
1285 * DCA is enabled. This is due to a known issue in some chipsets
1286 * which will cause the DCA tag to be cleared.
1288 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
1289 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1291 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
1294 static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1296 struct ixgbe_adapter *adapter = q_vector->adapter;
1297 struct ixgbe_ring *ring;
1298 int cpu = get_cpu();
1300 if (q_vector->cpu == cpu)
1303 ixgbe_for_each_ring(ring, q_vector->tx)
1304 ixgbe_update_tx_dca(adapter, ring, cpu);
1306 ixgbe_for_each_ring(ring, q_vector->rx)
1307 ixgbe_update_rx_dca(adapter, ring, cpu);
1309 q_vector->cpu = cpu;
1314 static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1318 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1321 /* always use CB2 mode, difference is masked in the CB driver */
1322 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1324 for (i = 0; i < adapter->num_q_vectors; i++) {
1325 adapter->q_vector[i]->cpu = -1;
1326 ixgbe_update_dca(adapter->q_vector[i]);
1330 static int __ixgbe_notify_dca(struct device *dev, void *data)
1332 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
1333 unsigned long event = *(unsigned long *)data;
1335 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
1339 case DCA_PROVIDER_ADD:
1340 /* if we're already enabled, don't do it again */
1341 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1343 if (dca_add_requester(dev) == 0) {
1344 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
1345 ixgbe_setup_dca(adapter);
1348 /* Fall Through since DCA is disabled. */
1349 case DCA_PROVIDER_REMOVE:
1350 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1351 dca_remove_requester(dev);
1352 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1353 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1361 #endif /* CONFIG_IXGBE_DCA */
1363 #define IXGBE_RSS_L4_TYPES_MASK \
1364 ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
1365 (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
1366 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
1367 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
1369 static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1370 union ixgbe_adv_rx_desc *rx_desc,
1371 struct sk_buff *skb)
1375 if (!(ring->netdev->features & NETIF_F_RXHASH))
1378 rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
1379 IXGBE_RXDADV_RSSTYPE_MASK;
1384 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
1385 (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
1386 PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
1391 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1392 * @ring: structure containing ring specific data
1393 * @rx_desc: advanced rx descriptor
1395 * Returns : true if it is FCoE pkt
1397 static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
1398 union ixgbe_adv_rx_desc *rx_desc)
1400 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1402 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
1403 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1404 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1405 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1408 #endif /* IXGBE_FCOE */
1410 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1411 * @ring: structure containing ring specific data
1412 * @rx_desc: current Rx descriptor being processed
1413 * @skb: skb currently being received and modified
1415 static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
1416 union ixgbe_adv_rx_desc *rx_desc,
1417 struct sk_buff *skb)
1419 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1420 __le16 hdr_info = rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
1421 bool encap_pkt = false;
1423 skb_checksum_none_assert(skb);
1425 /* Rx csum disabled */
1426 if (!(ring->netdev->features & NETIF_F_RXCSUM))
1429 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) &&
1430 (hdr_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_TUNNEL >> 16))) {
1432 skb->encapsulation = 1;
1433 skb->ip_summed = CHECKSUM_NONE;
1436 /* if IP and error */
1437 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1438 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
1439 ring->rx_stats.csum_err++;
1443 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
1446 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
1448 * 82599 errata, UDP frames with a 0 checksum can be marked as
1451 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1452 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
1455 ring->rx_stats.csum_err++;
1459 /* It must be a TCP or UDP packet with a valid checksum */
1460 skb->ip_summed = CHECKSUM_UNNECESSARY;
1462 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
1465 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
1466 ring->rx_stats.csum_err++;
1469 /* If we checked the outer header let the stack know */
1470 skb->csum_level = 1;
1474 static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1475 struct ixgbe_rx_buffer *bi)
1477 struct page *page = bi->page;
1480 /* since we are recycling buffers we should seldom need to alloc */
1484 /* alloc new page for storage */
1485 page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
1486 if (unlikely(!page)) {
1487 rx_ring->rx_stats.alloc_rx_page_failed++;
1491 /* map page for use */
1492 dma = dma_map_page(rx_ring->dev, page, 0,
1493 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1496 * if mapping failed free memory back to system since
1497 * there isn't much point in holding memory we can't use
1499 if (dma_mapping_error(rx_ring->dev, dma)) {
1500 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
1502 rx_ring->rx_stats.alloc_rx_page_failed++;
1508 bi->page_offset = 0;
1514 * ixgbe_alloc_rx_buffers - Replace used receive buffers
1515 * @rx_ring: ring to place buffers on
1516 * @cleaned_count: number of buffers to replace
1518 void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
1520 union ixgbe_adv_rx_desc *rx_desc;
1521 struct ixgbe_rx_buffer *bi;
1522 u16 i = rx_ring->next_to_use;
1528 rx_desc = IXGBE_RX_DESC(rx_ring, i);
1529 bi = &rx_ring->rx_buffer_info[i];
1530 i -= rx_ring->count;
1533 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
1537 * Refresh the desc even if buffer_addrs didn't change
1538 * because each write-back erases this info.
1540 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
1546 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
1547 bi = rx_ring->rx_buffer_info;
1548 i -= rx_ring->count;
1551 /* clear the status bits for the next_to_use descriptor */
1552 rx_desc->wb.upper.status_error = 0;
1555 } while (cleaned_count);
1557 i += rx_ring->count;
1559 if (rx_ring->next_to_use != i) {
1560 rx_ring->next_to_use = i;
1562 /* update next to alloc since we have filled the ring */
1563 rx_ring->next_to_alloc = i;
1565 /* Force memory writes to complete before letting h/w
1566 * know there are new descriptors to fetch. (Only
1567 * applicable for weak-ordered memory model archs,
1571 writel(i, rx_ring->tail);
1575 static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1576 struct sk_buff *skb)
1578 u16 hdr_len = skb_headlen(skb);
1580 /* set gso_size to avoid messing up TCP MSS */
1581 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1582 IXGBE_CB(skb)->append_cnt);
1583 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1586 static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1587 struct sk_buff *skb)
1589 /* if append_cnt is 0 then frame is not RSC */
1590 if (!IXGBE_CB(skb)->append_cnt)
1593 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1594 rx_ring->rx_stats.rsc_flush++;
1596 ixgbe_set_rsc_gso_size(rx_ring, skb);
1598 /* gso_size is computed using append_cnt so always clear it last */
1599 IXGBE_CB(skb)->append_cnt = 0;
1603 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1604 * @rx_ring: rx descriptor ring packet is being transacted on
1605 * @rx_desc: pointer to the EOP Rx descriptor
1606 * @skb: pointer to current skb being populated
1608 * This function checks the ring, descriptor, and packet information in
1609 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1610 * other fields within the skb.
1612 static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1613 union ixgbe_adv_rx_desc *rx_desc,
1614 struct sk_buff *skb)
1616 struct net_device *dev = rx_ring->netdev;
1618 ixgbe_update_rsc_stats(rx_ring, skb);
1620 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1622 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1624 if (unlikely(ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_STAT_TS)))
1625 ixgbe_ptp_rx_hwtstamp(rx_ring->q_vector->adapter, skb);
1627 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
1628 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1629 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1630 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
1633 skb_record_rx_queue(skb, rx_ring->queue_index);
1635 skb->protocol = eth_type_trans(skb, dev);
1638 static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1639 struct sk_buff *skb)
1641 if (ixgbe_qv_busy_polling(q_vector))
1642 netif_receive_skb(skb);
1644 napi_gro_receive(&q_vector->napi, skb);
1648 * ixgbe_is_non_eop - process handling of non-EOP buffers
1649 * @rx_ring: Rx ring being processed
1650 * @rx_desc: Rx descriptor for current buffer
1651 * @skb: Current socket buffer containing buffer in progress
1653 * This function updates next to clean. If the buffer is an EOP buffer
1654 * this function exits returning false, otherwise it will place the
1655 * sk_buff in the next buffer to be chained and return true indicating
1656 * that this is in fact a non-EOP buffer.
1658 static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1659 union ixgbe_adv_rx_desc *rx_desc,
1660 struct sk_buff *skb)
1662 u32 ntc = rx_ring->next_to_clean + 1;
1664 /* fetch, update, and store next to clean */
1665 ntc = (ntc < rx_ring->count) ? ntc : 0;
1666 rx_ring->next_to_clean = ntc;
1668 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1670 /* update RSC append count if present */
1671 if (ring_is_rsc_enabled(rx_ring)) {
1672 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1673 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1675 if (unlikely(rsc_enabled)) {
1676 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1678 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1679 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1681 /* update ntc based on RSC value */
1682 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1683 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1684 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1688 /* if we are the last buffer then there is nothing else to do */
1689 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1692 /* place skb in next buffer to be received */
1693 rx_ring->rx_buffer_info[ntc].skb = skb;
1694 rx_ring->rx_stats.non_eop_descs++;
1700 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1701 * @rx_ring: rx descriptor ring packet is being transacted on
1702 * @skb: pointer to current skb being adjusted
1704 * This function is an ixgbe specific version of __pskb_pull_tail. The
1705 * main difference between this version and the original function is that
1706 * this function can make several assumptions about the state of things
1707 * that allow for significant optimizations versus the standard function.
1708 * As a result we can do things like drop a frag and maintain an accurate
1709 * truesize for the skb.
1711 static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1712 struct sk_buff *skb)
1714 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1716 unsigned int pull_len;
1719 * it is valid to use page_address instead of kmap since we are
1720 * working with pages allocated out of the lomem pool per
1721 * alloc_page(GFP_ATOMIC)
1723 va = skb_frag_address(frag);
1726 * we need the header to contain the greater of either ETH_HLEN or
1727 * 60 bytes if the skb->len is less than 60 for skb_pad.
1729 pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
1731 /* align pull length to size of long to optimize memcpy performance */
1732 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1734 /* update all of the pointers */
1735 skb_frag_size_sub(frag, pull_len);
1736 frag->page_offset += pull_len;
1737 skb->data_len -= pull_len;
1738 skb->tail += pull_len;
1742 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1743 * @rx_ring: rx descriptor ring packet is being transacted on
1744 * @skb: pointer to current skb being updated
1746 * This function provides a basic DMA sync up for the first fragment of an
1747 * skb. The reason for doing this is that the first fragment cannot be
1748 * unmapped until we have reached the end of packet descriptor for a buffer
1751 static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1752 struct sk_buff *skb)
1754 /* if the page was released unmap it, else just sync our portion */
1755 if (unlikely(IXGBE_CB(skb)->page_released)) {
1756 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1757 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1758 IXGBE_CB(skb)->page_released = false;
1760 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1762 dma_sync_single_range_for_cpu(rx_ring->dev,
1765 ixgbe_rx_bufsz(rx_ring),
1768 IXGBE_CB(skb)->dma = 0;
1772 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1773 * @rx_ring: rx descriptor ring packet is being transacted on
1774 * @rx_desc: pointer to the EOP Rx descriptor
1775 * @skb: pointer to current skb being fixed
1777 * Check for corrupted packet headers caused by senders on the local L2
1778 * embedded NIC switch not setting up their Tx Descriptors right. These
1779 * should be very rare.
1781 * Also address the case where we are pulling data in on pages only
1782 * and as such no data is present in the skb header.
1784 * In addition if skb is not at least 60 bytes we need to pad it so that
1785 * it is large enough to qualify as a valid Ethernet frame.
1787 * Returns true if an error was encountered and skb was freed.
1789 static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1790 union ixgbe_adv_rx_desc *rx_desc,
1791 struct sk_buff *skb)
1793 struct net_device *netdev = rx_ring->netdev;
1795 /* verify that the packet does not have any known errors */
1796 if (unlikely(ixgbe_test_staterr(rx_desc,
1797 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1798 !(netdev->features & NETIF_F_RXALL))) {
1799 dev_kfree_skb_any(skb);
1803 /* place header in linear portion of buffer */
1804 if (skb_is_nonlinear(skb))
1805 ixgbe_pull_tail(rx_ring, skb);
1808 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1809 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1813 /* if eth_skb_pad returns an error the skb was freed */
1814 if (eth_skb_pad(skb))
1821 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1822 * @rx_ring: rx descriptor ring to store buffers on
1823 * @old_buff: donor buffer to have page reused
1825 * Synchronizes page for reuse by the adapter
1827 static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1828 struct ixgbe_rx_buffer *old_buff)
1830 struct ixgbe_rx_buffer *new_buff;
1831 u16 nta = rx_ring->next_to_alloc;
1833 new_buff = &rx_ring->rx_buffer_info[nta];
1835 /* update, and store next to alloc */
1837 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1839 /* transfer page from old buffer to new buffer */
1840 *new_buff = *old_buff;
1842 /* sync the buffer for use by the device */
1843 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
1844 new_buff->page_offset,
1845 ixgbe_rx_bufsz(rx_ring),
1849 static inline bool ixgbe_page_is_reserved(struct page *page)
1851 return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
1855 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1856 * @rx_ring: rx descriptor ring to transact packets on
1857 * @rx_buffer: buffer containing page to add
1858 * @rx_desc: descriptor containing length of buffer written by hardware
1859 * @skb: sk_buff to place the data into
1861 * This function will add the data contained in rx_buffer->page to the skb.
1862 * This is done either through a direct copy if the data in the buffer is
1863 * less than the skb header size, otherwise it will just attach the page as
1864 * a frag to the skb.
1866 * The function will then update the page offset if necessary and return
1867 * true if the buffer can be reused by the adapter.
1869 static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
1870 struct ixgbe_rx_buffer *rx_buffer,
1871 union ixgbe_adv_rx_desc *rx_desc,
1872 struct sk_buff *skb)
1874 struct page *page = rx_buffer->page;
1875 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
1876 #if (PAGE_SIZE < 8192)
1877 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
1879 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1880 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1881 ixgbe_rx_bufsz(rx_ring);
1884 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1885 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1887 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1889 /* page is not reserved, we can reuse buffer as-is */
1890 if (likely(!ixgbe_page_is_reserved(page)))
1893 /* this page cannot be reused so discard it */
1894 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
1898 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1899 rx_buffer->page_offset, size, truesize);
1901 /* avoid re-using remote pages */
1902 if (unlikely(ixgbe_page_is_reserved(page)))
1905 #if (PAGE_SIZE < 8192)
1906 /* if we are only owner of page we can reuse it */
1907 if (unlikely(page_count(page) != 1))
1910 /* flip page offset to other buffer */
1911 rx_buffer->page_offset ^= truesize;
1913 /* move offset up to the next cache line */
1914 rx_buffer->page_offset += truesize;
1916 if (rx_buffer->page_offset > last_offset)
1920 /* Even if we own the page, we are not allowed to use atomic_set()
1921 * This would break get_page_unless_zero() users.
1923 atomic_inc(&page->_count);
1928 static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
1929 union ixgbe_adv_rx_desc *rx_desc)
1931 struct ixgbe_rx_buffer *rx_buffer;
1932 struct sk_buff *skb;
1935 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
1936 page = rx_buffer->page;
1939 skb = rx_buffer->skb;
1942 void *page_addr = page_address(page) +
1943 rx_buffer->page_offset;
1945 /* prefetch first cache line of first page */
1946 prefetch(page_addr);
1947 #if L1_CACHE_BYTES < 128
1948 prefetch(page_addr + L1_CACHE_BYTES);
1951 /* allocate a skb to store the frags */
1952 skb = napi_alloc_skb(&rx_ring->q_vector->napi,
1954 if (unlikely(!skb)) {
1955 rx_ring->rx_stats.alloc_rx_buff_failed++;
1960 * we will be copying header into skb->data in
1961 * pskb_may_pull so it is in our interest to prefetch
1962 * it now to avoid a possible cache miss
1964 prefetchw(skb->data);
1967 * Delay unmapping of the first packet. It carries the
1968 * header information, HW may still access the header
1969 * after the writeback. Only unmap it when EOP is
1972 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1975 IXGBE_CB(skb)->dma = rx_buffer->dma;
1977 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
1978 ixgbe_dma_sync_frag(rx_ring, skb);
1981 /* we are reusing so sync this buffer for CPU use */
1982 dma_sync_single_range_for_cpu(rx_ring->dev,
1984 rx_buffer->page_offset,
1985 ixgbe_rx_bufsz(rx_ring),
1988 rx_buffer->skb = NULL;
1991 /* pull page into skb */
1992 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
1993 /* hand second half of page back to the ring */
1994 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1995 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1996 /* the page has been released from the ring */
1997 IXGBE_CB(skb)->page_released = true;
1999 /* we are not reusing the buffer so unmap it */
2000 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
2001 ixgbe_rx_pg_size(rx_ring),
2005 /* clear contents of buffer_info */
2006 rx_buffer->page = NULL;
2012 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2013 * @q_vector: structure containing interrupt and ring information
2014 * @rx_ring: rx descriptor ring to transact packets on
2015 * @budget: Total limit on number of packets to process
2017 * This function provides a "bounce buffer" approach to Rx interrupt
2018 * processing. The advantage to this is that on systems that have
2019 * expensive overhead for IOMMU access this provides a means of avoiding
2020 * it by maintaining the mapping of the page to the syste.
2022 * Returns amount of work completed
2024 static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
2025 struct ixgbe_ring *rx_ring,
2028 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
2030 struct ixgbe_adapter *adapter = q_vector->adapter;
2032 unsigned int mss = 0;
2033 #endif /* IXGBE_FCOE */
2034 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
2036 while (likely(total_rx_packets < budget)) {
2037 union ixgbe_adv_rx_desc *rx_desc;
2038 struct sk_buff *skb;
2040 /* return some buffers to hardware, one at a time is too slow */
2041 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2042 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2046 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
2048 if (!rx_desc->wb.upper.status_error)
2051 /* This memory barrier is needed to keep us from reading
2052 * any other fields out of the rx_desc until we know the
2053 * descriptor has been written back
2057 /* retrieve a buffer from the ring */
2058 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
2060 /* exit if we failed to retrieve a buffer */
2066 /* place incomplete frames back on ring for completion */
2067 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2070 /* verify the packet layout is correct */
2071 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2074 /* probably a little skewed due to removing CRC */
2075 total_rx_bytes += skb->len;
2077 /* populate checksum, timestamp, VLAN, and protocol */
2078 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2081 /* if ddp, not passing to ULD unless for FCP_RSP or error */
2082 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
2083 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
2084 /* include DDPed FCoE data */
2085 if (ddp_bytes > 0) {
2087 mss = rx_ring->netdev->mtu -
2088 sizeof(struct fcoe_hdr) -
2089 sizeof(struct fc_frame_header) -
2090 sizeof(struct fcoe_crc_eof);
2094 total_rx_bytes += ddp_bytes;
2095 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2099 dev_kfree_skb_any(skb);
2104 #endif /* IXGBE_FCOE */
2105 skb_mark_napi_id(skb, &q_vector->napi);
2106 ixgbe_rx_skb(q_vector, skb);
2108 /* update budget accounting */
2112 u64_stats_update_begin(&rx_ring->syncp);
2113 rx_ring->stats.packets += total_rx_packets;
2114 rx_ring->stats.bytes += total_rx_bytes;
2115 u64_stats_update_end(&rx_ring->syncp);
2116 q_vector->rx.total_packets += total_rx_packets;
2117 q_vector->rx.total_bytes += total_rx_bytes;
2119 return total_rx_packets;
2122 #ifdef CONFIG_NET_RX_BUSY_POLL
2123 /* must be called with local_bh_disable()d */
2124 static int ixgbe_low_latency_recv(struct napi_struct *napi)
2126 struct ixgbe_q_vector *q_vector =
2127 container_of(napi, struct ixgbe_q_vector, napi);
2128 struct ixgbe_adapter *adapter = q_vector->adapter;
2129 struct ixgbe_ring *ring;
2132 if (test_bit(__IXGBE_DOWN, &adapter->state))
2133 return LL_FLUSH_FAILED;
2135 if (!ixgbe_qv_lock_poll(q_vector))
2136 return LL_FLUSH_BUSY;
2138 ixgbe_for_each_ring(ring, q_vector->rx) {
2139 found = ixgbe_clean_rx_irq(q_vector, ring, 4);
2140 #ifdef BP_EXTENDED_STATS
2142 ring->stats.cleaned += found;
2144 ring->stats.misses++;
2150 ixgbe_qv_unlock_poll(q_vector);
2154 #endif /* CONFIG_NET_RX_BUSY_POLL */
2157 * ixgbe_configure_msix - Configure MSI-X hardware
2158 * @adapter: board private structure
2160 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2163 static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2165 struct ixgbe_q_vector *q_vector;
2169 /* Populate MSIX to EITR Select */
2170 if (adapter->num_vfs > 32) {
2171 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2172 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2176 * Populate the IVAR table and set the ITR values to the
2177 * corresponding register.
2179 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
2180 struct ixgbe_ring *ring;
2181 q_vector = adapter->q_vector[v_idx];
2183 ixgbe_for_each_ring(ring, q_vector->rx)
2184 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
2186 ixgbe_for_each_ring(ring, q_vector->tx)
2187 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
2189 ixgbe_write_eitr(q_vector);
2192 switch (adapter->hw.mac.type) {
2193 case ixgbe_mac_82598EB:
2194 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
2197 case ixgbe_mac_82599EB:
2198 case ixgbe_mac_X540:
2199 case ixgbe_mac_X550:
2200 case ixgbe_mac_X550EM_x:
2201 ixgbe_set_ivar(adapter, -1, 1, v_idx);
2206 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
2208 /* set up to autoclear timer, and the vectors */
2209 mask = IXGBE_EIMS_ENABLE_MASK;
2210 mask &= ~(IXGBE_EIMS_OTHER |
2211 IXGBE_EIMS_MAILBOX |
2214 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
2217 enum latency_range {
2221 latency_invalid = 255
2225 * ixgbe_update_itr - update the dynamic ITR value based on statistics
2226 * @q_vector: structure containing interrupt and ring information
2227 * @ring_container: structure containing ring performance data
2229 * Stores a new ITR value based on packets and byte
2230 * counts during the last interrupt. The advantage of per interrupt
2231 * computation is faster updates and more accurate ITR for the current
2232 * traffic pattern. Constants in this function were computed
2233 * based on theoretical maximum wire speed and thresholds were set based
2234 * on testing data as well as attempting to minimize response time
2235 * while increasing bulk throughput.
2236 * this functionality is controlled by the InterruptThrottleRate module
2237 * parameter (see ixgbe_param.c)
2239 static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2240 struct ixgbe_ring_container *ring_container)
2242 int bytes = ring_container->total_bytes;
2243 int packets = ring_container->total_packets;
2246 u8 itr_setting = ring_container->itr;
2251 /* simple throttlerate management
2252 * 0-10MB/s lowest (100000 ints/s)
2253 * 10-20MB/s low (20000 ints/s)
2254 * 20-1249MB/s bulk (8000 ints/s)
2256 /* what was last interrupt timeslice? */
2257 timepassed_us = q_vector->itr >> 2;
2258 if (timepassed_us == 0)
2261 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2263 switch (itr_setting) {
2264 case lowest_latency:
2265 if (bytes_perint > 10)
2266 itr_setting = low_latency;
2269 if (bytes_perint > 20)
2270 itr_setting = bulk_latency;
2271 else if (bytes_perint <= 10)
2272 itr_setting = lowest_latency;
2275 if (bytes_perint <= 20)
2276 itr_setting = low_latency;
2280 /* clear work counters since we have the values we need */
2281 ring_container->total_bytes = 0;
2282 ring_container->total_packets = 0;
2284 /* write updated itr to ring container */
2285 ring_container->itr = itr_setting;
2289 * ixgbe_write_eitr - write EITR register in hardware specific way
2290 * @q_vector: structure containing interrupt and ring information
2292 * This function is made to be called by ethtool and by the driver
2293 * when it needs to update EITR registers at runtime. Hardware
2294 * specific quirks/differences are taken care of here.
2296 void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
2298 struct ixgbe_adapter *adapter = q_vector->adapter;
2299 struct ixgbe_hw *hw = &adapter->hw;
2300 int v_idx = q_vector->v_idx;
2301 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
2303 switch (adapter->hw.mac.type) {
2304 case ixgbe_mac_82598EB:
2305 /* must write high and low 16 bits to reset counter */
2306 itr_reg |= (itr_reg << 16);
2308 case ixgbe_mac_82599EB:
2309 case ixgbe_mac_X540:
2310 case ixgbe_mac_X550:
2311 case ixgbe_mac_X550EM_x:
2313 * set the WDIS bit to not clear the timer bits and cause an
2314 * immediate assertion of the interrupt
2316 itr_reg |= IXGBE_EITR_CNT_WDIS;
2321 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2324 static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
2326 u32 new_itr = q_vector->itr;
2329 ixgbe_update_itr(q_vector, &q_vector->tx);
2330 ixgbe_update_itr(q_vector, &q_vector->rx);
2332 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
2334 switch (current_itr) {
2335 /* counts and packets in update_itr are dependent on these numbers */
2336 case lowest_latency:
2337 new_itr = IXGBE_100K_ITR;
2340 new_itr = IXGBE_20K_ITR;
2343 new_itr = IXGBE_8K_ITR;
2349 if (new_itr != q_vector->itr) {
2350 /* do an exponential smoothing */
2351 new_itr = (10 * new_itr * q_vector->itr) /
2352 ((9 * new_itr) + q_vector->itr);
2354 /* save the algorithm value here */
2355 q_vector->itr = new_itr;
2357 ixgbe_write_eitr(q_vector);
2362 * ixgbe_check_overtemp_subtask - check for over temperature
2363 * @adapter: pointer to adapter
2365 static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
2367 struct ixgbe_hw *hw = &adapter->hw;
2368 u32 eicr = adapter->interrupt_event;
2370 if (test_bit(__IXGBE_DOWN, &adapter->state))
2373 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2374 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2377 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2379 switch (hw->device_id) {
2380 case IXGBE_DEV_ID_82599_T3_LOM:
2382 * Since the warning interrupt is for both ports
2383 * we don't have to check if:
2384 * - This interrupt wasn't for our port.
2385 * - We may have missed the interrupt so always have to
2386 * check if we got a LSC
2388 if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
2389 !(eicr & IXGBE_EICR_LSC))
2392 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
2394 bool link_up = false;
2396 hw->mac.ops.check_link(hw, &speed, &link_up, false);
2402 /* Check if this is not due to overtemp */
2403 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2408 if (adapter->hw.mac.type >= ixgbe_mac_X540)
2410 if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
2414 e_crit(drv, "%s\n", ixgbe_overheat_msg);
2416 adapter->interrupt_event = 0;
2419 static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2421 struct ixgbe_hw *hw = &adapter->hw;
2423 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2424 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
2425 e_crit(probe, "Fan has stopped, replace the adapter\n");
2426 /* write to clear the interrupt */
2427 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
2431 static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2433 struct ixgbe_hw *hw = &adapter->hw;
2435 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2438 switch (adapter->hw.mac.type) {
2439 case ixgbe_mac_82599EB:
2441 * Need to check link state so complete overtemp check
2444 if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
2445 (eicr & IXGBE_EICR_LSC)) &&
2446 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2447 adapter->interrupt_event = eicr;
2448 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2449 ixgbe_service_event_schedule(adapter);
2453 case ixgbe_mac_X540:
2454 if (!(eicr & IXGBE_EICR_TS))
2461 e_crit(drv, "%s\n", ixgbe_overheat_msg);
2464 static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2466 switch (hw->mac.type) {
2467 case ixgbe_mac_82598EB:
2468 if (hw->phy.type == ixgbe_phy_nl)
2471 case ixgbe_mac_82599EB:
2472 case ixgbe_mac_X550EM_x:
2473 switch (hw->mac.ops.get_media_type(hw)) {
2474 case ixgbe_media_type_fiber:
2475 case ixgbe_media_type_fiber_qsfp:
2485 static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2487 struct ixgbe_hw *hw = &adapter->hw;
2489 if (eicr & IXGBE_EICR_GPI_SDP2(hw)) {
2490 /* Clear the interrupt */
2491 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2(hw));
2492 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2493 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2494 ixgbe_service_event_schedule(adapter);
2498 if (eicr & IXGBE_EICR_GPI_SDP1(hw)) {
2499 /* Clear the interrupt */
2500 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
2501 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2502 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2503 ixgbe_service_event_schedule(adapter);
2508 static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2510 struct ixgbe_hw *hw = &adapter->hw;
2513 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2514 adapter->link_check_timeout = jiffies;
2515 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2516 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
2517 IXGBE_WRITE_FLUSH(hw);
2518 ixgbe_service_event_schedule(adapter);
2522 static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2526 struct ixgbe_hw *hw = &adapter->hw;
2528 switch (hw->mac.type) {
2529 case ixgbe_mac_82598EB:
2530 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
2531 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2533 case ixgbe_mac_82599EB:
2534 case ixgbe_mac_X540:
2535 case ixgbe_mac_X550:
2536 case ixgbe_mac_X550EM_x:
2537 mask = (qmask & 0xFFFFFFFF);
2539 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
2540 mask = (qmask >> 32);
2542 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2547 /* skip the flush */
2550 static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
2554 struct ixgbe_hw *hw = &adapter->hw;
2556 switch (hw->mac.type) {
2557 case ixgbe_mac_82598EB:
2558 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
2559 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2561 case ixgbe_mac_82599EB:
2562 case ixgbe_mac_X540:
2563 case ixgbe_mac_X550:
2564 case ixgbe_mac_X550EM_x:
2565 mask = (qmask & 0xFFFFFFFF);
2567 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
2568 mask = (qmask >> 32);
2570 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2575 /* skip the flush */
2579 * ixgbe_irq_enable - Enable default interrupt generation settings
2580 * @adapter: board private structure
2582 static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2585 struct ixgbe_hw *hw = &adapter->hw;
2586 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
2588 /* don't reenable LSC while waiting for link */
2589 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2590 mask &= ~IXGBE_EIMS_LSC;
2592 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2593 switch (adapter->hw.mac.type) {
2594 case ixgbe_mac_82599EB:
2595 mask |= IXGBE_EIMS_GPI_SDP0(hw);
2597 case ixgbe_mac_X540:
2598 case ixgbe_mac_X550:
2599 case ixgbe_mac_X550EM_x:
2600 mask |= IXGBE_EIMS_TS;
2605 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2606 mask |= IXGBE_EIMS_GPI_SDP1(hw);
2607 switch (adapter->hw.mac.type) {
2608 case ixgbe_mac_82599EB:
2609 mask |= IXGBE_EIMS_GPI_SDP1(hw);
2610 mask |= IXGBE_EIMS_GPI_SDP2(hw);
2612 case ixgbe_mac_X540:
2613 case ixgbe_mac_X550:
2614 case ixgbe_mac_X550EM_x:
2615 if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
2616 mask |= IXGBE_EICR_GPI_SDP0_X540;
2617 mask |= IXGBE_EIMS_ECC;
2618 mask |= IXGBE_EIMS_MAILBOX;
2624 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2625 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2626 mask |= IXGBE_EIMS_FLOW_DIR;
2628 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2630 ixgbe_irq_enable_queues(adapter, ~0);
2632 IXGBE_WRITE_FLUSH(&adapter->hw);
2635 static irqreturn_t ixgbe_msix_other(int irq, void *data)
2637 struct ixgbe_adapter *adapter = data;
2638 struct ixgbe_hw *hw = &adapter->hw;
2642 * Workaround for Silicon errata. Use clear-by-write instead
2643 * of clear-by-read. Reading with EICS will return the
2644 * interrupt causes without clearing, which later be done
2645 * with the write to EICR.
2647 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2649 /* The lower 16bits of the EICR register are for the queue interrupts
2650 * which should be masked here in order to not accidentally clear them if
2651 * the bits are high when ixgbe_msix_other is called. There is a race
2652 * condition otherwise which results in possible performance loss
2653 * especially if the ixgbe_msix_other interrupt is triggering
2654 * consistently (as it would when PPS is turned on for the X540 device)
2658 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
2660 if (eicr & IXGBE_EICR_LSC)
2661 ixgbe_check_lsc(adapter);
2663 if (eicr & IXGBE_EICR_MAILBOX)
2664 ixgbe_msg_task(adapter);
2666 switch (hw->mac.type) {
2667 case ixgbe_mac_82599EB:
2668 case ixgbe_mac_X540:
2669 case ixgbe_mac_X550:
2670 case ixgbe_mac_X550EM_x:
2671 if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
2672 (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
2673 adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
2674 ixgbe_service_event_schedule(adapter);
2675 IXGBE_WRITE_REG(hw, IXGBE_EICR,
2676 IXGBE_EICR_GPI_SDP0_X540);
2678 if (eicr & IXGBE_EICR_ECC) {
2679 e_info(link, "Received ECC Err, initiating reset\n");
2680 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
2681 ixgbe_service_event_schedule(adapter);
2682 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2684 /* Handle Flow Director Full threshold interrupt */
2685 if (eicr & IXGBE_EICR_FLOW_DIR) {
2686 int reinit_count = 0;
2688 for (i = 0; i < adapter->num_tx_queues; i++) {
2689 struct ixgbe_ring *ring = adapter->tx_ring[i];
2690 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2695 /* no more flow director interrupts until after init */
2696 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2697 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2698 ixgbe_service_event_schedule(adapter);
2701 ixgbe_check_sfp_event(adapter, eicr);
2702 ixgbe_check_overtemp_event(adapter, eicr);
2708 ixgbe_check_fan_failure(adapter, eicr);
2710 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2711 ixgbe_ptp_check_pps_event(adapter, eicr);
2713 /* re-enable the original interrupt state, no lsc, no queues */
2714 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2715 ixgbe_irq_enable(adapter, false, false);
2720 static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
2722 struct ixgbe_q_vector *q_vector = data;
2724 /* EIAM disabled interrupts (on this vector) for us */
2726 if (q_vector->rx.ring || q_vector->tx.ring)
2727 napi_schedule(&q_vector->napi);
2733 * ixgbe_poll - NAPI Rx polling callback
2734 * @napi: structure for representing this polling device
2735 * @budget: how many packets driver is allowed to clean
2737 * This function is used for legacy and MSI, NAPI mode
2739 int ixgbe_poll(struct napi_struct *napi, int budget)
2741 struct ixgbe_q_vector *q_vector =
2742 container_of(napi, struct ixgbe_q_vector, napi);
2743 struct ixgbe_adapter *adapter = q_vector->adapter;
2744 struct ixgbe_ring *ring;
2745 int per_ring_budget;
2746 bool clean_complete = true;
2748 #ifdef CONFIG_IXGBE_DCA
2749 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2750 ixgbe_update_dca(q_vector);
2753 ixgbe_for_each_ring(ring, q_vector->tx)
2754 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2756 if (!ixgbe_qv_lock_napi(q_vector))
2759 /* attempt to distribute budget to each queue fairly, but don't allow
2760 * the budget to go below 1 because we'll exit polling */
2761 if (q_vector->rx.count > 1)
2762 per_ring_budget = max(budget/q_vector->rx.count, 1);
2764 per_ring_budget = budget;
2766 ixgbe_for_each_ring(ring, q_vector->rx)
2767 clean_complete &= (ixgbe_clean_rx_irq(q_vector, ring,
2768 per_ring_budget) < per_ring_budget);
2770 ixgbe_qv_unlock_napi(q_vector);
2771 /* If all work not completed, return budget and keep polling */
2772 if (!clean_complete)
2775 /* all work done, exit the polling mode */
2776 napi_complete(napi);
2777 if (adapter->rx_itr_setting & 1)
2778 ixgbe_set_itr(q_vector);
2779 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2780 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2786 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2787 * @adapter: board private structure
2789 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2790 * interrupts from the kernel.
2792 static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2794 struct net_device *netdev = adapter->netdev;
2798 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2799 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2800 struct msix_entry *entry = &adapter->msix_entries[vector];
2802 if (q_vector->tx.ring && q_vector->rx.ring) {
2803 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2804 "%s-%s-%d", netdev->name, "TxRx", ri++);
2806 } else if (q_vector->rx.ring) {
2807 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2808 "%s-%s-%d", netdev->name, "rx", ri++);
2809 } else if (q_vector->tx.ring) {
2810 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2811 "%s-%s-%d", netdev->name, "tx", ti++);
2813 /* skip this unused q_vector */
2816 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2817 q_vector->name, q_vector);
2819 e_err(probe, "request_irq failed for MSIX interrupt "
2820 "Error: %d\n", err);
2821 goto free_queue_irqs;
2823 /* If Flow Director is enabled, set interrupt affinity */
2824 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2825 /* assign the mask for this irq */
2826 irq_set_affinity_hint(entry->vector,
2827 &q_vector->affinity_mask);
2831 err = request_irq(adapter->msix_entries[vector].vector,
2832 ixgbe_msix_other, 0, netdev->name, adapter);
2834 e_err(probe, "request_irq for msix_other failed: %d\n", err);
2835 goto free_queue_irqs;
2843 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2845 free_irq(adapter->msix_entries[vector].vector,
2846 adapter->q_vector[vector]);
2848 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2849 pci_disable_msix(adapter->pdev);
2850 kfree(adapter->msix_entries);
2851 adapter->msix_entries = NULL;
2856 * ixgbe_intr - legacy mode Interrupt Handler
2857 * @irq: interrupt number
2858 * @data: pointer to a network interface device structure
2860 static irqreturn_t ixgbe_intr(int irq, void *data)
2862 struct ixgbe_adapter *adapter = data;
2863 struct ixgbe_hw *hw = &adapter->hw;
2864 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
2868 * Workaround for silicon errata #26 on 82598. Mask the interrupt
2869 * before the read of EICR.
2871 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2873 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2874 * therefore no explicit interrupt disable is necessary */
2875 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
2878 * shared interrupt alert!
2879 * make sure interrupts are enabled because the read will
2880 * have disabled interrupts due to EIAM
2881 * finish the workaround of silicon errata on 82598. Unmask
2882 * the interrupt that we masked before the EICR read.
2884 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2885 ixgbe_irq_enable(adapter, true, true);
2886 return IRQ_NONE; /* Not our interrupt */
2889 if (eicr & IXGBE_EICR_LSC)
2890 ixgbe_check_lsc(adapter);
2892 switch (hw->mac.type) {
2893 case ixgbe_mac_82599EB:
2894 ixgbe_check_sfp_event(adapter, eicr);
2896 case ixgbe_mac_X540:
2897 case ixgbe_mac_X550:
2898 case ixgbe_mac_X550EM_x:
2899 if (eicr & IXGBE_EICR_ECC) {
2900 e_info(link, "Received ECC Err, initiating reset\n");
2901 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
2902 ixgbe_service_event_schedule(adapter);
2903 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2905 ixgbe_check_overtemp_event(adapter, eicr);
2911 ixgbe_check_fan_failure(adapter, eicr);
2912 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2913 ixgbe_ptp_check_pps_event(adapter, eicr);
2915 /* would disable interrupts here but EIAM disabled it */
2916 napi_schedule(&q_vector->napi);
2919 * re-enable link(maybe) and non-queue interrupts, no flush.
2920 * ixgbe_poll will re-enable the queue interrupts
2922 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2923 ixgbe_irq_enable(adapter, false, false);
2929 * ixgbe_request_irq - initialize interrupts
2930 * @adapter: board private structure
2932 * Attempts to configure interrupts using the best available
2933 * capabilities of the hardware and kernel.
2935 static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
2937 struct net_device *netdev = adapter->netdev;
2940 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2941 err = ixgbe_request_msix_irqs(adapter);
2942 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
2943 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
2944 netdev->name, adapter);
2946 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
2947 netdev->name, adapter);
2950 e_err(probe, "request_irq failed, Error %d\n", err);
2955 static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2959 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2960 free_irq(adapter->pdev->irq, adapter);
2964 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2965 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2966 struct msix_entry *entry = &adapter->msix_entries[vector];
2968 /* free only the irqs that were actually requested */
2969 if (!q_vector->rx.ring && !q_vector->tx.ring)
2972 /* clear the affinity_mask in the IRQ descriptor */
2973 irq_set_affinity_hint(entry->vector, NULL);
2975 free_irq(entry->vector, q_vector);
2978 free_irq(adapter->msix_entries[vector++].vector, adapter);
2982 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2983 * @adapter: board private structure
2985 static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2987 switch (adapter->hw.mac.type) {
2988 case ixgbe_mac_82598EB:
2989 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
2991 case ixgbe_mac_82599EB:
2992 case ixgbe_mac_X540:
2993 case ixgbe_mac_X550:
2994 case ixgbe_mac_X550EM_x:
2995 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2996 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
2997 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
3002 IXGBE_WRITE_FLUSH(&adapter->hw);
3003 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3006 for (vector = 0; vector < adapter->num_q_vectors; vector++)
3007 synchronize_irq(adapter->msix_entries[vector].vector);
3009 synchronize_irq(adapter->msix_entries[vector++].vector);
3011 synchronize_irq(adapter->pdev->irq);
3016 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3019 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
3021 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
3023 ixgbe_write_eitr(q_vector);
3025 ixgbe_set_ivar(adapter, 0, 0, 0);
3026 ixgbe_set_ivar(adapter, 1, 0, 0);
3028 e_info(hw, "Legacy interrupt IVAR setup done\n");
3032 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3033 * @adapter: board private structure
3034 * @ring: structure containing ring specific data
3036 * Configure the Tx descriptor ring after a reset.
3038 void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
3039 struct ixgbe_ring *ring)
3041 struct ixgbe_hw *hw = &adapter->hw;
3042 u64 tdba = ring->dma;
3044 u32 txdctl = IXGBE_TXDCTL_ENABLE;
3045 u8 reg_idx = ring->reg_idx;
3047 /* disable queue to avoid issues while updating state */
3048 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
3049 IXGBE_WRITE_FLUSH(hw);
3051 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
3052 (tdba & DMA_BIT_MASK(32)));
3053 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3054 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3055 ring->count * sizeof(union ixgbe_adv_tx_desc));
3056 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3057 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
3058 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
3061 * set WTHRESH to encourage burst writeback, it should not be set
3062 * higher than 1 when:
3063 * - ITR is 0 as it could cause false TX hangs
3064 * - ITR is set to > 100k int/sec and BQL is enabled
3066 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3067 * to or less than the number of on chip descriptors, which is
3070 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
3071 txdctl |= (1 << 16); /* WTHRESH = 1 */
3073 txdctl |= (8 << 16); /* WTHRESH = 8 */
3076 * Setting PTHRESH to 32 both improves performance
3077 * and avoids a TX hang with DFP enabled
3079 txdctl |= (1 << 8) | /* HTHRESH = 1 */
3080 32; /* PTHRESH = 32 */
3082 /* reinitialize flowdirector state */
3083 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3084 ring->atr_sample_rate = adapter->atr_sample_rate;
3085 ring->atr_count = 0;
3086 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3088 ring->atr_sample_rate = 0;
3091 /* initialize XPS */
3092 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3093 struct ixgbe_q_vector *q_vector = ring->q_vector;
3096 netif_set_xps_queue(ring->netdev,
3097 &q_vector->affinity_mask,
3101 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3104 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3106 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3107 if (hw->mac.type == ixgbe_mac_82598EB &&
3108 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3111 /* poll to verify queue is enabled */
3113 usleep_range(1000, 2000);
3114 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3115 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3117 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
3120 static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3122 struct ixgbe_hw *hw = &adapter->hw;
3124 u8 tcs = netdev_get_num_tc(adapter->netdev);
3126 if (hw->mac.type == ixgbe_mac_82598EB)
3129 /* disable the arbiter while setting MTQC */
3130 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3131 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3132 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3134 /* set transmit pool layout */
3135 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3136 mtqc = IXGBE_MTQC_VT_ENA;
3138 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3140 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3141 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3142 mtqc |= IXGBE_MTQC_32VF;
3144 mtqc |= IXGBE_MTQC_64VF;
3147 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3149 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3151 mtqc = IXGBE_MTQC_64Q_1PB;
3154 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
3156 /* Enable Security TX Buffer IFG for multiple pb */
3158 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3159 sectx |= IXGBE_SECTX_DCB;
3160 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
3163 /* re-enable the arbiter */
3164 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3165 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3169 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
3170 * @adapter: board private structure
3172 * Configure the Tx unit of the MAC after a reset.
3174 static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3176 struct ixgbe_hw *hw = &adapter->hw;
3180 ixgbe_setup_mtqc(adapter);
3182 if (hw->mac.type != ixgbe_mac_82598EB) {
3183 /* DMATXCTL.EN must be before Tx queues are enabled */
3184 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3185 dmatxctl |= IXGBE_DMATXCTL_TE;
3186 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3189 /* Setup the HW Tx Head and Tail descriptor pointers */
3190 for (i = 0; i < adapter->num_tx_queues; i++)
3191 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
3194 static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3195 struct ixgbe_ring *ring)
3197 struct ixgbe_hw *hw = &adapter->hw;
3198 u8 reg_idx = ring->reg_idx;
3199 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3201 srrctl |= IXGBE_SRRCTL_DROP_EN;
3203 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3206 static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3207 struct ixgbe_ring *ring)
3209 struct ixgbe_hw *hw = &adapter->hw;
3210 u8 reg_idx = ring->reg_idx;
3211 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3213 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3215 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3218 #ifdef CONFIG_IXGBE_DCB
3219 void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3221 static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3225 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3227 if (adapter->ixgbe_ieee_pfc)
3228 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3231 * We should set the drop enable bit if:
3234 * Number of Rx queues > 1 and flow control is disabled
3236 * This allows us to avoid head of line blocking for security
3237 * and performance reasons.
3239 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3240 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3241 for (i = 0; i < adapter->num_rx_queues; i++)
3242 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3244 for (i = 0; i < adapter->num_rx_queues; i++)
3245 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3249 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
3251 static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
3252 struct ixgbe_ring *rx_ring)
3254 struct ixgbe_hw *hw = &adapter->hw;
3256 u8 reg_idx = rx_ring->reg_idx;
3258 if (hw->mac.type == ixgbe_mac_82598EB) {
3259 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3262 * if VMDq is not active we must program one srrctl register
3263 * per RSS queue since we have enabled RDRXCTL.MVMEN
3268 /* configure header buffer length, needed for RSC */
3269 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
3271 /* configure the packet buffer length */
3272 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
3274 /* configure descriptor type */
3275 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
3277 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3281 * Return a number of entries in the RSS indirection table
3283 * @adapter: device handle
3285 * - 82598/82599/X540: 128
3286 * - X550(non-SRIOV mode): 512
3287 * - X550(SRIOV mode): 64
3289 u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
3291 if (adapter->hw.mac.type < ixgbe_mac_X550)
3293 else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3300 * Write the RETA table to HW
3302 * @adapter: device handle
3304 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3306 static void ixgbe_store_reta(struct ixgbe_adapter *adapter)
3308 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3309 struct ixgbe_hw *hw = &adapter->hw;
3312 u8 *indir_tbl = adapter->rss_indir_tbl;
3314 /* Fill out the redirection table as follows:
3315 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3317 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3318 * - X550: 8 bit wide entries containing 6 bit RSS index
3320 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3321 indices_multi = 0x11;
3323 indices_multi = 0x1;
3325 /* Write redirection table to HW */
3326 for (i = 0; i < reta_entries; i++) {
3327 reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
3330 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3332 IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
3340 * Write the RETA table to HW (for x550 devices in SRIOV mode)
3342 * @adapter: device handle
3344 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3346 static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
3348 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3349 struct ixgbe_hw *hw = &adapter->hw;
3351 unsigned int pf_pool = adapter->num_vfs;
3353 /* Write redirection table to HW */
3354 for (i = 0; i < reta_entries; i++) {
3355 vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
3357 IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool),
3364 static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
3366 struct ixgbe_hw *hw = &adapter->hw;
3368 u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3369 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3371 /* Program table for at least 2 queues w/ SR-IOV so that VFs can
3372 * make full use of any rings they may have. We will use the
3373 * PSRTYPE register to control how many rings we use within the PF.
3375 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
3378 /* Fill out hash function seeds */
3379 for (i = 0; i < 10; i++)
3380 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
3382 /* Fill out redirection table */
3383 memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
3385 for (i = 0, j = 0; i < reta_entries; i++, j++) {
3389 adapter->rss_indir_tbl[i] = j;
3392 ixgbe_store_reta(adapter);
3395 static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
3397 struct ixgbe_hw *hw = &adapter->hw;
3398 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3399 unsigned int pf_pool = adapter->num_vfs;
3402 /* Fill out hash function seeds */
3403 for (i = 0; i < 10; i++)
3404 IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool),
3405 adapter->rss_key[i]);
3407 /* Fill out the redirection table */
3408 for (i = 0, j = 0; i < 64; i++, j++) {
3412 adapter->rss_indir_tbl[i] = j;
3415 ixgbe_store_vfreta(adapter);
3418 static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3420 struct ixgbe_hw *hw = &adapter->hw;
3421 u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
3424 /* Disable indicating checksum in descriptor, enables RSS hash */
3425 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3426 rxcsum |= IXGBE_RXCSUM_PCSD;
3427 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3429 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
3430 if (adapter->ring_feature[RING_F_RSS].mask)
3431 mrqc = IXGBE_MRQC_RSSEN;
3433 u8 tcs = netdev_get_num_tc(adapter->netdev);
3435 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3437 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3439 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3440 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3441 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3443 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3446 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3448 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3450 mrqc = IXGBE_MRQC_RSSEN;
3454 /* Perform hash on these packet types */
3455 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3456 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3457 IXGBE_MRQC_RSS_FIELD_IPV6 |
3458 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
3460 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
3461 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3462 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
3463 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3465 netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key));
3466 if ((hw->mac.type >= ixgbe_mac_X550) &&
3467 (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
3468 unsigned int pf_pool = adapter->num_vfs;
3470 /* Enable VF RSS mode */
3471 mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
3472 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3474 /* Setup RSS through the VF registers */
3475 ixgbe_setup_vfreta(adapter);
3476 vfmrqc = IXGBE_MRQC_RSSEN;
3477 vfmrqc |= rss_field;
3478 IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc);
3480 ixgbe_setup_reta(adapter);
3482 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3487 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3488 * @adapter: address of board private structure
3489 * @index: index of ring to set
3491 static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
3492 struct ixgbe_ring *ring)
3494 struct ixgbe_hw *hw = &adapter->hw;
3496 u8 reg_idx = ring->reg_idx;
3498 if (!ring_is_rsc_enabled(ring))
3501 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
3502 rscctrl |= IXGBE_RSCCTL_RSCEN;
3504 * we must limit the number of descriptors so that the
3505 * total size of max desc * buf_len is not greater
3508 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
3509 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
3512 #define IXGBE_MAX_RX_DESC_POLL 10
3513 static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3514 struct ixgbe_ring *ring)
3516 struct ixgbe_hw *hw = &adapter->hw;
3517 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3519 u8 reg_idx = ring->reg_idx;
3521 if (ixgbe_removed(hw->hw_addr))
3523 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3524 if (hw->mac.type == ixgbe_mac_82598EB &&
3525 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3529 usleep_range(1000, 2000);
3530 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3531 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3534 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3535 "the polling period\n", reg_idx);
3539 void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3540 struct ixgbe_ring *ring)
3542 struct ixgbe_hw *hw = &adapter->hw;
3543 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3545 u8 reg_idx = ring->reg_idx;
3547 if (ixgbe_removed(hw->hw_addr))
3549 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3550 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3552 /* write value back with RXDCTL.ENABLE bit cleared */
3553 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3555 if (hw->mac.type == ixgbe_mac_82598EB &&
3556 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3559 /* the hardware may take up to 100us to really disable the rx queue */
3562 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3563 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3566 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3567 "the polling period\n", reg_idx);
3571 void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3572 struct ixgbe_ring *ring)
3574 struct ixgbe_hw *hw = &adapter->hw;
3575 u64 rdba = ring->dma;
3577 u8 reg_idx = ring->reg_idx;
3579 /* disable queue to avoid issues while updating state */
3580 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3581 ixgbe_disable_rx_queue(adapter, ring);
3583 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3584 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3585 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3586 ring->count * sizeof(union ixgbe_adv_rx_desc));
3587 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3588 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
3589 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
3591 ixgbe_configure_srrctl(adapter, ring);
3592 ixgbe_configure_rscctl(adapter, ring);
3594 if (hw->mac.type == ixgbe_mac_82598EB) {
3596 * enable cache line friendly hardware writes:
3597 * PTHRESH=32 descriptors (half the internal cache),
3598 * this also removes ugly rx_no_buffer_count increment
3599 * HTHRESH=4 descriptors (to minimize latency on fetch)
3600 * WTHRESH=8 burst writeback up to two cache lines
3602 rxdctl &= ~0x3FFFFF;
3606 /* enable receive descriptor ring */
3607 rxdctl |= IXGBE_RXDCTL_ENABLE;
3608 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3610 ixgbe_rx_desc_queue_enable(adapter, ring);
3611 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
3614 static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3616 struct ixgbe_hw *hw = &adapter->hw;
3617 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
3620 /* PSRTYPE must be initialized in non 82598 adapters */
3621 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
3622 IXGBE_PSRTYPE_UDPHDR |
3623 IXGBE_PSRTYPE_IPV4HDR |
3624 IXGBE_PSRTYPE_L2HDR |
3625 IXGBE_PSRTYPE_IPV6HDR;
3627 if (hw->mac.type == ixgbe_mac_82598EB)
3635 for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
3636 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
3639 static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3641 struct ixgbe_hw *hw = &adapter->hw;
3642 u32 reg_offset, vf_shift;
3643 u32 gcr_ext, vmdctl;
3646 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3649 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3650 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3651 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
3652 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
3653 vmdctl |= IXGBE_VT_CTL_REPLEN;
3654 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
3656 vf_shift = VMDQ_P(0) % 32;
3657 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
3659 /* Enable only the PF's pool for Tx/Rx */
3660 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3661 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3662 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3663 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
3664 if (adapter->bridge_mode == BRIDGE_MODE_VEB)
3665 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3667 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3668 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
3671 * Set up VF register offsets for selected VT Mode,
3672 * i.e. 32 or 64 VFs for SR-IOV
3674 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3675 case IXGBE_82599_VMDQ_8Q_MASK:
3676 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3678 case IXGBE_82599_VMDQ_4Q_MASK:
3679 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3682 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3686 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3689 /* Enable MAC Anti-Spoofing */
3690 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
3693 /* Ensure LLDP is set for Ethertype Antispoofing if we will be
3694 * calling set_ethertype_anti_spoofing for each VF in loop below
3696 if (hw->mac.ops.set_ethertype_anti_spoofing)
3697 IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_LLDP),
3698 (IXGBE_ETQF_FILTER_EN | /* enable filter */
3699 IXGBE_ETQF_TX_ANTISPOOF | /* tx antispoof */
3700 IXGBE_ETH_P_LLDP)); /* LLDP eth type */
3702 /* For VFs that have spoof checking turned off */
3703 for (i = 0; i < adapter->num_vfs; i++) {
3704 if (!adapter->vfinfo[i].spoofchk_enabled)
3705 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3707 /* enable ethertype anti spoofing if hw supports it */
3708 if (hw->mac.ops.set_ethertype_anti_spoofing)
3709 hw->mac.ops.set_ethertype_anti_spoofing(hw, true, i);
3711 /* Enable/Disable RSS query feature */
3712 ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
3713 adapter->vfinfo[i].rss_query_enabled);
3717 static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
3719 struct ixgbe_hw *hw = &adapter->hw;
3720 struct net_device *netdev = adapter->netdev;
3721 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
3722 struct ixgbe_ring *rx_ring;
3727 /* adjust max frame to be able to do baby jumbo for FCoE */
3728 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3729 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3730 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3732 #endif /* IXGBE_FCOE */
3734 /* adjust max frame to be at least the size of a standard frame */
3735 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3736 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3738 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3739 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3740 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3741 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3743 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
3746 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
3747 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3748 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
3749 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3752 * Setup the HW Rx Head and Tail Descriptor Pointers and
3753 * the Base and Length of the Rx Descriptor Ring
3755 for (i = 0; i < adapter->num_rx_queues; i++) {
3756 rx_ring = adapter->rx_ring[i];
3757 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3758 set_ring_rsc_enabled(rx_ring);
3760 clear_ring_rsc_enabled(rx_ring);
3764 static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3766 struct ixgbe_hw *hw = &adapter->hw;
3767 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3769 switch (hw->mac.type) {
3770 case ixgbe_mac_X550:
3771 case ixgbe_mac_X550EM_x:
3772 case ixgbe_mac_82598EB:
3774 * For VMDq support of different descriptor types or
3775 * buffer sizes through the use of multiple SRRCTL
3776 * registers, RDRXCTL.MVMEN must be set to 1
3778 * also, the manual doesn't mention it clearly but DCA hints
3779 * will only use queue 0's tags unless this bit is set. Side
3780 * effects of setting this bit are only that SRRCTL must be
3781 * fully programmed [0..15]
3783 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3785 case ixgbe_mac_82599EB:
3786 case ixgbe_mac_X540:
3787 /* Disable RSC for ACK packets */
3788 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3789 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3790 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3791 /* hardware requires some bits to be set by default */
3792 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3793 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3796 /* We should do nothing since we don't know this hardware */
3800 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3804 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3805 * @adapter: board private structure
3807 * Configure the Rx unit of the MAC after a reset.
3809 static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3811 struct ixgbe_hw *hw = &adapter->hw;
3815 /* disable receives while setting up the descriptors */
3816 hw->mac.ops.disable_rx(hw);
3818 ixgbe_setup_psrtype(adapter);
3819 ixgbe_setup_rdrxctl(adapter);
3822 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
3823 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
3824 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
3825 rfctl |= IXGBE_RFCTL_RSC_DIS;
3826 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
3828 /* Program registers for the distribution of queues */
3829 ixgbe_setup_mrqc(adapter);
3831 /* set_rx_buffer_len must be called before ring initialization */
3832 ixgbe_set_rx_buffer_len(adapter);
3835 * Setup the HW Rx Head and Tail Descriptor Pointers and
3836 * the Base and Length of the Rx Descriptor Ring
3838 for (i = 0; i < adapter->num_rx_queues; i++)
3839 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
3841 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3842 /* disable drop enable for 82598 parts */
3843 if (hw->mac.type == ixgbe_mac_82598EB)
3844 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3846 /* enable all receives */
3847 rxctrl |= IXGBE_RXCTRL_RXEN;
3848 hw->mac.ops.enable_rx_dma(hw, rxctrl);
3851 static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
3852 __be16 proto, u16 vid)
3854 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3855 struct ixgbe_hw *hw = &adapter->hw;
3857 /* add VID to filter table */
3858 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
3859 set_bit(vid, adapter->active_vlans);
3864 static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
3865 __be16 proto, u16 vid)
3867 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3868 struct ixgbe_hw *hw = &adapter->hw;
3870 /* remove VID from filter table */
3871 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
3872 clear_bit(vid, adapter->active_vlans);
3878 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3879 * @adapter: driver data
3881 static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3883 struct ixgbe_hw *hw = &adapter->hw;
3887 switch (hw->mac.type) {
3888 case ixgbe_mac_82598EB:
3889 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3890 vlnctrl &= ~IXGBE_VLNCTRL_VME;
3891 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3893 case ixgbe_mac_82599EB:
3894 case ixgbe_mac_X540:
3895 case ixgbe_mac_X550:
3896 case ixgbe_mac_X550EM_x:
3897 for (i = 0; i < adapter->num_rx_queues; i++) {
3898 struct ixgbe_ring *ring = adapter->rx_ring[i];
3900 if (ring->l2_accel_priv)
3903 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3904 vlnctrl &= ~IXGBE_RXDCTL_VME;
3905 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3914 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
3915 * @adapter: driver data
3917 static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
3919 struct ixgbe_hw *hw = &adapter->hw;
3923 switch (hw->mac.type) {
3924 case ixgbe_mac_82598EB:
3925 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3926 vlnctrl |= IXGBE_VLNCTRL_VME;
3927 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3929 case ixgbe_mac_82599EB:
3930 case ixgbe_mac_X540:
3931 case ixgbe_mac_X550:
3932 case ixgbe_mac_X550EM_x:
3933 for (i = 0; i < adapter->num_rx_queues; i++) {
3934 struct ixgbe_ring *ring = adapter->rx_ring[i];
3936 if (ring->l2_accel_priv)
3939 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3940 vlnctrl |= IXGBE_RXDCTL_VME;
3941 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3949 static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3953 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
3955 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3956 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
3960 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
3961 * @netdev: network interface device structure
3963 * Writes multicast address list to the MTA hash table.
3964 * Returns: -ENOMEM on failure
3965 * 0 on no addresses written
3966 * X on writing X addresses to MTA
3968 static int ixgbe_write_mc_addr_list(struct net_device *netdev)
3970 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3971 struct ixgbe_hw *hw = &adapter->hw;
3973 if (!netif_running(netdev))
3976 if (hw->mac.ops.update_mc_addr_list)
3977 hw->mac.ops.update_mc_addr_list(hw, netdev);
3981 #ifdef CONFIG_PCI_IOV
3982 ixgbe_restore_vf_multicasts(adapter);
3985 return netdev_mc_count(netdev);
3988 #ifdef CONFIG_PCI_IOV
3989 void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
3991 struct ixgbe_hw *hw = &adapter->hw;
3993 for (i = 0; i < hw->mac.num_rar_entries; i++) {
3994 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE)
3995 hw->mac.ops.set_rar(hw, i, adapter->mac_table[i].addr,
3996 adapter->mac_table[i].queue,
3999 hw->mac.ops.clear_rar(hw, i);
4001 adapter->mac_table[i].state &= ~(IXGBE_MAC_STATE_MODIFIED);
4006 static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
4008 struct ixgbe_hw *hw = &adapter->hw;
4010 for (i = 0; i < hw->mac.num_rar_entries; i++) {
4011 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_MODIFIED) {
4012 if (adapter->mac_table[i].state &
4013 IXGBE_MAC_STATE_IN_USE)
4014 hw->mac.ops.set_rar(hw, i,
4015 adapter->mac_table[i].addr,
4016 adapter->mac_table[i].queue,
4019 hw->mac.ops.clear_rar(hw, i);
4021 adapter->mac_table[i].state &=
4022 ~(IXGBE_MAC_STATE_MODIFIED);
4027 static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
4030 struct ixgbe_hw *hw = &adapter->hw;
4032 for (i = 0; i < hw->mac.num_rar_entries; i++) {
4033 adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED;
4034 adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE;
4035 eth_zero_addr(adapter->mac_table[i].addr);
4036 adapter->mac_table[i].queue = 0;
4038 ixgbe_sync_mac_table(adapter);
4041 static int ixgbe_available_rars(struct ixgbe_adapter *adapter)
4043 struct ixgbe_hw *hw = &adapter->hw;
4046 for (i = 0; i < hw->mac.num_rar_entries; i++) {
4047 if (adapter->mac_table[i].state == 0)
4053 /* this function destroys the first RAR entry */
4054 static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter,
4057 struct ixgbe_hw *hw = &adapter->hw;
4059 memcpy(&adapter->mac_table[0].addr, addr, ETH_ALEN);
4060 adapter->mac_table[0].queue = VMDQ_P(0);
4061 adapter->mac_table[0].state = (IXGBE_MAC_STATE_DEFAULT |
4062 IXGBE_MAC_STATE_IN_USE);
4063 hw->mac.ops.set_rar(hw, 0, adapter->mac_table[0].addr,
4064 adapter->mac_table[0].queue,
4068 int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, u8 *addr, u16 queue)
4070 struct ixgbe_hw *hw = &adapter->hw;
4073 if (is_zero_ether_addr(addr))
4076 for (i = 0; i < hw->mac.num_rar_entries; i++) {
4077 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE)
4079 adapter->mac_table[i].state |= (IXGBE_MAC_STATE_MODIFIED |
4080 IXGBE_MAC_STATE_IN_USE);
4081 ether_addr_copy(adapter->mac_table[i].addr, addr);
4082 adapter->mac_table[i].queue = queue;
4083 ixgbe_sync_mac_table(adapter);
4089 int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter, u8 *addr, u16 queue)
4091 /* search table for addr, if found, set to 0 and sync */
4093 struct ixgbe_hw *hw = &adapter->hw;
4095 if (is_zero_ether_addr(addr))
4098 for (i = 0; i < hw->mac.num_rar_entries; i++) {
4099 if (ether_addr_equal(addr, adapter->mac_table[i].addr) &&
4100 adapter->mac_table[i].queue == queue) {
4101 adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED;
4102 adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE;
4103 eth_zero_addr(adapter->mac_table[i].addr);
4104 adapter->mac_table[i].queue = 0;
4105 ixgbe_sync_mac_table(adapter);
4112 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
4113 * @netdev: network interface device structure
4115 * Writes unicast address list to the RAR table.
4116 * Returns: -ENOMEM on failure/insufficient address space
4117 * 0 on no addresses written
4118 * X on writing X addresses to the RAR table
4120 static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
4122 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4125 /* return ENOMEM indicating insufficient memory for addresses */
4126 if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter))
4129 if (!netdev_uc_empty(netdev)) {
4130 struct netdev_hw_addr *ha;
4131 netdev_for_each_uc_addr(ha, netdev) {
4132 ixgbe_del_mac_filter(adapter, ha->addr, vfn);
4133 ixgbe_add_mac_filter(adapter, ha->addr, vfn);
4141 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
4142 * @netdev: network interface device structure
4144 * The set_rx_method entry point is called whenever the unicast/multicast
4145 * address list or the network interface flags are updated. This routine is
4146 * responsible for configuring the hardware for proper unicast, multicast and
4149 void ixgbe_set_rx_mode(struct net_device *netdev)
4151 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4152 struct ixgbe_hw *hw = &adapter->hw;
4153 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
4157 /* Check for Promiscuous and All Multicast modes */
4158 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4159 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4161 /* set all bits that we expect to always be set */
4162 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
4163 fctrl |= IXGBE_FCTRL_BAM;
4164 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
4165 fctrl |= IXGBE_FCTRL_PMCF;
4167 /* clear the bits we are changing the status of */
4168 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
4169 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
4170 if (netdev->flags & IFF_PROMISC) {
4171 hw->addr_ctrl.user_set_promisc = true;
4172 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
4173 vmolr |= IXGBE_VMOLR_MPE;
4174 /* Only disable hardware filter vlans in promiscuous mode
4175 * if SR-IOV and VMDQ are disabled - otherwise ensure
4176 * that hardware VLAN filters remain enabled.
4178 if (adapter->flags & (IXGBE_FLAG_VMDQ_ENABLED |
4179 IXGBE_FLAG_SRIOV_ENABLED))
4180 vlnctrl |= (IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
4182 if (netdev->flags & IFF_ALLMULTI) {
4183 fctrl |= IXGBE_FCTRL_MPE;
4184 vmolr |= IXGBE_VMOLR_MPE;
4186 vlnctrl |= IXGBE_VLNCTRL_VFE;
4187 hw->addr_ctrl.user_set_promisc = false;
4191 * Write addresses to available RAR registers, if there is not
4192 * sufficient space to store all the addresses then enable
4193 * unicast promiscuous mode
4195 count = ixgbe_write_uc_addr_list(netdev, VMDQ_P(0));
4197 fctrl |= IXGBE_FCTRL_UPE;
4198 vmolr |= IXGBE_VMOLR_ROPE;
4201 /* Write addresses to the MTA, if the attempt fails
4202 * then we should just turn on promiscuous mode so
4203 * that we can at least receive multicast traffic
4205 count = ixgbe_write_mc_addr_list(netdev);
4207 fctrl |= IXGBE_FCTRL_MPE;
4208 vmolr |= IXGBE_VMOLR_MPE;
4210 vmolr |= IXGBE_VMOLR_ROMPE;
4213 if (hw->mac.type != ixgbe_mac_82598EB) {
4214 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
4215 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
4217 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
4220 /* This is useful for sniffing bad packets. */
4221 if (adapter->netdev->features & NETIF_F_RXALL) {
4222 /* UPE and MPE will be handled by normal PROMISC logic
4223 * in e1000e_set_rx_mode */
4224 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
4225 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
4226 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
4228 fctrl &= ~(IXGBE_FCTRL_DPF);
4229 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4232 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4233 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4235 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
4236 ixgbe_vlan_strip_enable(adapter);
4238 ixgbe_vlan_strip_disable(adapter);
4241 static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4245 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
4246 ixgbe_qv_init_lock(adapter->q_vector[q_idx]);
4247 napi_enable(&adapter->q_vector[q_idx]->napi);
4251 static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
4255 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
4256 napi_disable(&adapter->q_vector[q_idx]->napi);
4257 while (!ixgbe_qv_disable(adapter->q_vector[q_idx])) {
4258 pr_info("QV %d locked\n", q_idx);
4259 usleep_range(1000, 20000);
4264 #ifdef CONFIG_IXGBE_DCB
4266 * ixgbe_configure_dcb - Configure DCB hardware
4267 * @adapter: ixgbe adapter struct
4269 * This is called by the driver on open to configure the DCB hardware.
4270 * This is also called by the gennetlink interface when reconfiguring
4273 static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
4275 struct ixgbe_hw *hw = &adapter->hw;
4276 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
4278 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
4279 if (hw->mac.type == ixgbe_mac_82598EB)
4280 netif_set_gso_max_size(adapter->netdev, 65536);
4284 if (hw->mac.type == ixgbe_mac_82598EB)
4285 netif_set_gso_max_size(adapter->netdev, 32768);
4288 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
4289 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
4292 /* reconfigure the hardware */
4293 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
4294 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4296 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4298 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
4299 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
4300 ixgbe_dcb_hw_ets(&adapter->hw,
4301 adapter->ixgbe_ieee_ets,
4303 ixgbe_dcb_hw_pfc_config(&adapter->hw,
4304 adapter->ixgbe_ieee_pfc->pfc_en,
4305 adapter->ixgbe_ieee_ets->prio_tc);
4308 /* Enable RSS Hash per TC */
4309 if (hw->mac.type != ixgbe_mac_82598EB) {
4311 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
4318 /* write msb to all 8 TCs in one write */
4319 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
4324 /* Additional bittime to account for IXGBE framing */
4325 #define IXGBE_ETH_FRAMING 20
4328 * ixgbe_hpbthresh - calculate high water mark for flow control
4330 * @adapter: board private structure to calculate for
4331 * @pb: packet buffer to calculate
4333 static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
4335 struct ixgbe_hw *hw = &adapter->hw;
4336 struct net_device *dev = adapter->netdev;
4337 int link, tc, kb, marker;
4340 /* Calculate max LAN frame size */
4341 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
4344 /* FCoE traffic class uses FCOE jumbo frames */
4345 if ((dev->features & NETIF_F_FCOE_MTU) &&
4346 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4347 (pb == ixgbe_fcoe_get_tc(adapter)))
4348 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4351 /* Calculate delay value for device */
4352 switch (hw->mac.type) {
4353 case ixgbe_mac_X540:
4354 case ixgbe_mac_X550:
4355 case ixgbe_mac_X550EM_x:
4356 dv_id = IXGBE_DV_X540(link, tc);
4359 dv_id = IXGBE_DV(link, tc);
4363 /* Loopback switch introduces additional latency */
4364 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4365 dv_id += IXGBE_B2BT(tc);
4367 /* Delay value is calculated in bit times convert to KB */
4368 kb = IXGBE_BT2KB(dv_id);
4369 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
4371 marker = rx_pba - kb;
4373 /* It is possible that the packet buffer is not large enough
4374 * to provide required headroom. In this case throw an error
4375 * to user and a do the best we can.
4378 e_warn(drv, "Packet Buffer(%i) can not provide enough"
4379 "headroom to support flow control."
4380 "Decrease MTU or number of traffic classes\n", pb);
4388 * ixgbe_lpbthresh - calculate low water mark for for flow control
4390 * @adapter: board private structure to calculate for
4391 * @pb: packet buffer to calculate
4393 static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
4395 struct ixgbe_hw *hw = &adapter->hw;
4396 struct net_device *dev = adapter->netdev;
4400 /* Calculate max LAN frame size */
4401 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
4404 /* FCoE traffic class uses FCOE jumbo frames */
4405 if ((dev->features & NETIF_F_FCOE_MTU) &&
4406 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4407 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
4408 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4411 /* Calculate delay value for device */
4412 switch (hw->mac.type) {
4413 case ixgbe_mac_X540:
4414 case ixgbe_mac_X550:
4415 case ixgbe_mac_X550EM_x:
4416 dv_id = IXGBE_LOW_DV_X540(tc);
4419 dv_id = IXGBE_LOW_DV(tc);
4423 /* Delay value is calculated in bit times convert to KB */
4424 return IXGBE_BT2KB(dv_id);
4428 * ixgbe_pbthresh_setup - calculate and setup high low water marks
4430 static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
4432 struct ixgbe_hw *hw = &adapter->hw;
4433 int num_tc = netdev_get_num_tc(adapter->netdev);
4439 for (i = 0; i < num_tc; i++) {
4440 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
4441 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
4443 /* Low water marks must not be larger than high water marks */
4444 if (hw->fc.low_water[i] > hw->fc.high_water[i])
4445 hw->fc.low_water[i] = 0;
4448 for (; i < MAX_TRAFFIC_CLASS; i++)
4449 hw->fc.high_water[i] = 0;
4452 static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
4454 struct ixgbe_hw *hw = &adapter->hw;
4456 u8 tc = netdev_get_num_tc(adapter->netdev);
4458 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4459 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
4460 hdrm = 32 << adapter->fdir_pballoc;
4464 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
4465 ixgbe_pbthresh_setup(adapter);
4468 static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
4470 struct ixgbe_hw *hw = &adapter->hw;
4471 struct hlist_node *node2;
4472 struct ixgbe_fdir_filter *filter;
4474 spin_lock(&adapter->fdir_perfect_lock);
4476 if (!hlist_empty(&adapter->fdir_filter_list))
4477 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
4479 hlist_for_each_entry_safe(filter, node2,
4480 &adapter->fdir_filter_list, fdir_node) {
4481 ixgbe_fdir_write_perfect_filter_82599(hw,
4484 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
4485 IXGBE_FDIR_DROP_QUEUE :
4486 adapter->rx_ring[filter->action]->reg_idx);
4489 spin_unlock(&adapter->fdir_perfect_lock);
4492 static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
4493 struct ixgbe_adapter *adapter)
4495 struct ixgbe_hw *hw = &adapter->hw;
4498 /* No unicast promiscuous support for VMDQ devices. */
4499 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
4500 vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
4502 /* clear the affected bit */
4503 vmolr &= ~IXGBE_VMOLR_MPE;
4505 if (dev->flags & IFF_ALLMULTI) {
4506 vmolr |= IXGBE_VMOLR_MPE;
4508 vmolr |= IXGBE_VMOLR_ROMPE;
4509 hw->mac.ops.update_mc_addr_list(hw, dev);
4511 ixgbe_write_uc_addr_list(adapter->netdev, pool);
4512 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
4515 static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
4517 struct ixgbe_adapter *adapter = vadapter->real_adapter;
4518 int rss_i = adapter->num_rx_queues_per_pool;
4519 struct ixgbe_hw *hw = &adapter->hw;
4520 u16 pool = vadapter->pool;
4521 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
4522 IXGBE_PSRTYPE_UDPHDR |
4523 IXGBE_PSRTYPE_IPV4HDR |
4524 IXGBE_PSRTYPE_L2HDR |
4525 IXGBE_PSRTYPE_IPV6HDR;
4527 if (hw->mac.type == ixgbe_mac_82598EB)
4535 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
4539 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
4540 * @rx_ring: ring to free buffers from
4542 static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
4544 struct device *dev = rx_ring->dev;
4548 /* ring already cleared, nothing to do */
4549 if (!rx_ring->rx_buffer_info)
4552 /* Free all the Rx ring sk_buffs */
4553 for (i = 0; i < rx_ring->count; i++) {
4554 struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
4556 if (rx_buffer->skb) {
4557 struct sk_buff *skb = rx_buffer->skb;
4558 if (IXGBE_CB(skb)->page_released)
4561 ixgbe_rx_bufsz(rx_ring),
4564 rx_buffer->skb = NULL;
4567 if (!rx_buffer->page)
4570 dma_unmap_page(dev, rx_buffer->dma,
4571 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
4572 __free_pages(rx_buffer->page, ixgbe_rx_pg_order(rx_ring));
4574 rx_buffer->page = NULL;
4577 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4578 memset(rx_ring->rx_buffer_info, 0, size);
4580 /* Zero out the descriptor ring */
4581 memset(rx_ring->desc, 0, rx_ring->size);
4583 rx_ring->next_to_alloc = 0;
4584 rx_ring->next_to_clean = 0;
4585 rx_ring->next_to_use = 0;
4588 static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
4589 struct ixgbe_ring *rx_ring)
4591 struct ixgbe_adapter *adapter = vadapter->real_adapter;
4592 int index = rx_ring->queue_index + vadapter->rx_base_queue;
4594 /* shutdown specific queue receive and wait for dma to settle */
4595 ixgbe_disable_rx_queue(adapter, rx_ring);
4596 usleep_range(10000, 20000);
4597 ixgbe_irq_disable_queues(adapter, ((u64)1 << index));
4598 ixgbe_clean_rx_ring(rx_ring);
4599 rx_ring->l2_accel_priv = NULL;
4602 static int ixgbe_fwd_ring_down(struct net_device *vdev,
4603 struct ixgbe_fwd_adapter *accel)
4605 struct ixgbe_adapter *adapter = accel->real_adapter;
4606 unsigned int rxbase = accel->rx_base_queue;
4607 unsigned int txbase = accel->tx_base_queue;
4610 netif_tx_stop_all_queues(vdev);
4612 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4613 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
4614 adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
4617 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4618 adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
4619 adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
4626 static int ixgbe_fwd_ring_up(struct net_device *vdev,
4627 struct ixgbe_fwd_adapter *accel)
4629 struct ixgbe_adapter *adapter = accel->real_adapter;
4630 unsigned int rxbase, txbase, queues;
4631 int i, baseq, err = 0;
4633 if (!test_bit(accel->pool, &adapter->fwd_bitmask))
4636 baseq = accel->pool * adapter->num_rx_queues_per_pool;
4637 netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
4638 accel->pool, adapter->num_rx_pools,
4639 baseq, baseq + adapter->num_rx_queues_per_pool,
4640 adapter->fwd_bitmask);
4642 accel->netdev = vdev;
4643 accel->rx_base_queue = rxbase = baseq;
4644 accel->tx_base_queue = txbase = baseq;
4646 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
4647 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
4649 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4650 adapter->rx_ring[rxbase + i]->netdev = vdev;
4651 adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
4652 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
4655 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
4656 adapter->tx_ring[txbase + i]->netdev = vdev;
4657 adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
4660 queues = min_t(unsigned int,
4661 adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
4662 err = netif_set_real_num_tx_queues(vdev, queues);
4666 err = netif_set_real_num_rx_queues(vdev, queues);
4670 if (is_valid_ether_addr(vdev->dev_addr))
4671 ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool);
4673 ixgbe_fwd_psrtype(accel);
4674 ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter);
4677 ixgbe_fwd_ring_down(vdev, accel);
4681 static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
4683 struct net_device *upper;
4684 struct list_head *iter;
4687 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
4688 if (netif_is_macvlan(upper)) {
4689 struct macvlan_dev *dfwd = netdev_priv(upper);
4690 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
4692 if (dfwd->fwd_priv) {
4693 err = ixgbe_fwd_ring_up(upper, vadapter);
4701 static void ixgbe_configure(struct ixgbe_adapter *adapter)
4703 struct ixgbe_hw *hw = &adapter->hw;
4705 ixgbe_configure_pb(adapter);
4706 #ifdef CONFIG_IXGBE_DCB
4707 ixgbe_configure_dcb(adapter);
4710 * We must restore virtualization before VLANs or else
4711 * the VLVF registers will not be populated
4713 ixgbe_configure_virtualization(adapter);
4715 ixgbe_set_rx_mode(adapter->netdev);
4716 ixgbe_restore_vlan(adapter);
4718 switch (hw->mac.type) {
4719 case ixgbe_mac_82599EB:
4720 case ixgbe_mac_X540:
4721 hw->mac.ops.disable_rx_buff(hw);
4727 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
4728 ixgbe_init_fdir_signature_82599(&adapter->hw,
4729 adapter->fdir_pballoc);
4730 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
4731 ixgbe_init_fdir_perfect_82599(&adapter->hw,
4732 adapter->fdir_pballoc);
4733 ixgbe_fdir_filter_restore(adapter);
4736 switch (hw->mac.type) {
4737 case ixgbe_mac_82599EB:
4738 case ixgbe_mac_X540:
4739 hw->mac.ops.enable_rx_buff(hw);
4746 /* configure FCoE L2 filters, redirection table, and Rx control */
4747 ixgbe_configure_fcoe(adapter);
4749 #endif /* IXGBE_FCOE */
4750 ixgbe_configure_tx(adapter);
4751 ixgbe_configure_rx(adapter);
4752 ixgbe_configure_dfwd(adapter);
4756 * ixgbe_sfp_link_config - set up SFP+ link
4757 * @adapter: pointer to private adapter struct
4759 static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
4762 * We are assuming the worst case scenario here, and that
4763 * is that an SFP was inserted/removed after the reset
4764 * but before SFP detection was enabled. As such the best
4765 * solution is to just start searching as soon as we start
4767 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
4768 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
4770 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
4774 * ixgbe_non_sfp_link_config - set up non-SFP+ link
4775 * @hw: pointer to private hardware struct
4777 * Returns 0 on success, negative on failure
4779 static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
4782 bool autoneg, link_up = false;
4783 int ret = IXGBE_ERR_LINK_SETUP;
4785 if (hw->mac.ops.check_link)
4786 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
4791 speed = hw->phy.autoneg_advertised;
4792 if ((!speed) && (hw->mac.ops.get_link_capabilities))
4793 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
4798 if (hw->mac.ops.setup_link)
4799 ret = hw->mac.ops.setup_link(hw, speed, link_up);
4804 static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
4806 struct ixgbe_hw *hw = &adapter->hw;
4809 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4810 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
4812 gpie |= IXGBE_GPIE_EIAME;
4814 * use EIAM to auto-mask when MSI-X interrupt is asserted
4815 * this saves a register write for every interrupt
4817 switch (hw->mac.type) {
4818 case ixgbe_mac_82598EB:
4819 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4821 case ixgbe_mac_82599EB:
4822 case ixgbe_mac_X540:
4823 case ixgbe_mac_X550:
4824 case ixgbe_mac_X550EM_x:
4826 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4827 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4831 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
4832 * specifically only auto mask tx and rx interrupts */
4833 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4836 /* XXX: to interrupt immediately for EICS writes, enable this */
4837 /* gpie |= IXGBE_GPIE_EIMEN; */
4839 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
4840 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
4842 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4843 case IXGBE_82599_VMDQ_8Q_MASK:
4844 gpie |= IXGBE_GPIE_VTMODE_16;
4846 case IXGBE_82599_VMDQ_4Q_MASK:
4847 gpie |= IXGBE_GPIE_VTMODE_32;
4850 gpie |= IXGBE_GPIE_VTMODE_64;
4855 /* Enable Thermal over heat sensor interrupt */
4856 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
4857 switch (adapter->hw.mac.type) {
4858 case ixgbe_mac_82599EB:
4859 gpie |= IXGBE_SDP0_GPIEN_8259X;
4861 case ixgbe_mac_X540:
4862 gpie |= IXGBE_EIMS_TS;
4869 /* Enable fan failure interrupt */
4870 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
4871 gpie |= IXGBE_SDP1_GPIEN(hw);
4873 if (hw->mac.type == ixgbe_mac_82599EB) {
4874 gpie |= IXGBE_SDP1_GPIEN_8259X;
4875 gpie |= IXGBE_SDP2_GPIEN_8259X;
4878 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4881 static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
4883 struct ixgbe_hw *hw = &adapter->hw;
4887 ixgbe_get_hw_control(adapter);
4888 ixgbe_setup_gpie(adapter);
4890 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4891 ixgbe_configure_msix(adapter);
4893 ixgbe_configure_msi_and_legacy(adapter);
4895 /* enable the optics for 82599 SFP+ fiber */
4896 if (hw->mac.ops.enable_tx_laser)
4897 hw->mac.ops.enable_tx_laser(hw);
4899 if (hw->phy.ops.set_phy_power)
4900 hw->phy.ops.set_phy_power(hw, true);
4902 smp_mb__before_atomic();
4903 clear_bit(__IXGBE_DOWN, &adapter->state);
4904 ixgbe_napi_enable_all(adapter);
4906 if (ixgbe_is_sfp(hw)) {
4907 ixgbe_sfp_link_config(adapter);
4909 err = ixgbe_non_sfp_link_config(hw);
4911 e_err(probe, "link_config FAILED %d\n", err);
4914 /* clear any pending interrupts, may auto mask */
4915 IXGBE_READ_REG(hw, IXGBE_EICR);
4916 ixgbe_irq_enable(adapter, true, true);
4919 * If this adapter has a fan, check to see if we had a failure
4920 * before we enabled the interrupt.
4922 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
4923 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
4924 if (esdp & IXGBE_ESDP_SDP1)
4925 e_crit(drv, "Fan has stopped, replace the adapter\n");
4928 /* bring the link up in the watchdog, this could race with our first
4929 * link up interrupt but shouldn't be a problem */
4930 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4931 adapter->link_check_timeout = jiffies;
4932 mod_timer(&adapter->service_timer, jiffies);
4934 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4935 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4936 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4937 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
4940 void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4942 WARN_ON(in_interrupt());
4943 /* put off any impending NetWatchDogTimeout */
4944 adapter->netdev->trans_start = jiffies;
4946 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
4947 usleep_range(1000, 2000);
4948 ixgbe_down(adapter);
4950 * If SR-IOV enabled then wait a bit before bringing the adapter
4951 * back up to give the VFs time to respond to the reset. The
4952 * two second wait is based upon the watchdog timer cycle in
4955 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4958 clear_bit(__IXGBE_RESETTING, &adapter->state);
4961 void ixgbe_up(struct ixgbe_adapter *adapter)
4963 /* hardware has been reset, we need to reload some things */
4964 ixgbe_configure(adapter);
4966 ixgbe_up_complete(adapter);
4969 void ixgbe_reset(struct ixgbe_adapter *adapter)
4971 struct ixgbe_hw *hw = &adapter->hw;
4972 struct net_device *netdev = adapter->netdev;
4974 u8 old_addr[ETH_ALEN];
4976 if (ixgbe_removed(hw->hw_addr))
4978 /* lock SFP init bit to prevent race conditions with the watchdog */
4979 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4980 usleep_range(1000, 2000);
4982 /* clear all SFP and link config related flags while holding SFP_INIT */
4983 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4984 IXGBE_FLAG2_SFP_NEEDS_RESET);
4985 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4987 err = hw->mac.ops.init_hw(hw);
4990 case IXGBE_ERR_SFP_NOT_PRESENT:
4991 case IXGBE_ERR_SFP_NOT_SUPPORTED:
4993 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
4994 e_dev_err("master disable timed out\n");
4996 case IXGBE_ERR_EEPROM_VERSION:
4997 /* We are running on a pre-production device, log a warning */
4998 e_dev_warn("This device is a pre-production adapter/LOM. "
4999 "Please be aware there may be issues associated with "
5000 "your hardware. If you are experiencing problems "
5001 "please contact your Intel or hardware "
5002 "representative who provided you with this "
5006 e_dev_err("Hardware Error: %d\n", err);
5009 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5010 /* do not flush user set addresses */
5011 memcpy(old_addr, &adapter->mac_table[0].addr, netdev->addr_len);
5012 ixgbe_flush_sw_mac_table(adapter);
5013 ixgbe_mac_set_default_filter(adapter, old_addr);
5015 /* update SAN MAC vmdq pool selection */
5016 if (hw->mac.san_mac_rar_index)
5017 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
5019 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
5020 ixgbe_ptp_reset(adapter);
5022 if (hw->phy.ops.set_phy_power) {
5023 if (!netif_running(adapter->netdev) && !adapter->wol)
5024 hw->phy.ops.set_phy_power(hw, false);
5026 hw->phy.ops.set_phy_power(hw, true);
5031 * ixgbe_clean_tx_ring - Free Tx Buffers
5032 * @tx_ring: ring to be cleaned
5034 static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
5036 struct ixgbe_tx_buffer *tx_buffer_info;
5040 /* ring already cleared, nothing to do */
5041 if (!tx_ring->tx_buffer_info)
5044 /* Free all the Tx ring sk_buffs */
5045 for (i = 0; i < tx_ring->count; i++) {
5046 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5047 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
5050 netdev_tx_reset_queue(txring_txq(tx_ring));
5052 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
5053 memset(tx_ring->tx_buffer_info, 0, size);
5055 /* Zero out the descriptor ring */
5056 memset(tx_ring->desc, 0, tx_ring->size);
5058 tx_ring->next_to_use = 0;
5059 tx_ring->next_to_clean = 0;
5063 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5064 * @adapter: board private structure
5066 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
5070 for (i = 0; i < adapter->num_rx_queues; i++)
5071 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
5075 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5076 * @adapter: board private structure
5078 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
5082 for (i = 0; i < adapter->num_tx_queues; i++)
5083 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
5086 static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
5088 struct hlist_node *node2;
5089 struct ixgbe_fdir_filter *filter;
5091 spin_lock(&adapter->fdir_perfect_lock);
5093 hlist_for_each_entry_safe(filter, node2,
5094 &adapter->fdir_filter_list, fdir_node) {
5095 hlist_del(&filter->fdir_node);
5098 adapter->fdir_filter_count = 0;
5100 spin_unlock(&adapter->fdir_perfect_lock);
5103 void ixgbe_down(struct ixgbe_adapter *adapter)
5105 struct net_device *netdev = adapter->netdev;
5106 struct ixgbe_hw *hw = &adapter->hw;
5107 struct net_device *upper;
5108 struct list_head *iter;
5111 /* signal that we are down to the interrupt handler */
5112 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
5113 return; /* do nothing if already down */
5115 /* disable receives */
5116 hw->mac.ops.disable_rx(hw);
5118 /* disable all enabled rx queues */
5119 for (i = 0; i < adapter->num_rx_queues; i++)
5120 /* this call also flushes the previous write */
5121 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
5123 usleep_range(10000, 20000);
5125 netif_tx_stop_all_queues(netdev);
5127 /* call carrier off first to avoid false dev_watchdog timeouts */
5128 netif_carrier_off(netdev);
5129 netif_tx_disable(netdev);
5131 /* disable any upper devices */
5132 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
5133 if (netif_is_macvlan(upper)) {
5134 struct macvlan_dev *vlan = netdev_priv(upper);
5136 if (vlan->fwd_priv) {
5137 netif_tx_stop_all_queues(upper);
5138 netif_carrier_off(upper);
5139 netif_tx_disable(upper);
5144 ixgbe_irq_disable(adapter);
5146 ixgbe_napi_disable_all(adapter);
5148 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
5149 IXGBE_FLAG2_RESET_REQUESTED);
5150 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5152 del_timer_sync(&adapter->service_timer);
5154 if (adapter->num_vfs) {
5155 /* Clear EITR Select mapping */
5156 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
5158 /* Mark all the VFs as inactive */
5159 for (i = 0 ; i < adapter->num_vfs; i++)
5160 adapter->vfinfo[i].clear_to_send = false;
5162 /* ping all the active vfs to let them know we are going down */
5163 ixgbe_ping_all_vfs(adapter);
5165 /* Disable all VFTE/VFRE TX/RX */
5166 ixgbe_disable_tx_rx(adapter);
5169 /* disable transmits in the hardware now that interrupts are off */
5170 for (i = 0; i < adapter->num_tx_queues; i++) {
5171 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
5172 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
5175 /* Disable the Tx DMA engine on 82599 and later MAC */
5176 switch (hw->mac.type) {
5177 case ixgbe_mac_82599EB:
5178 case ixgbe_mac_X540:
5179 case ixgbe_mac_X550:
5180 case ixgbe_mac_X550EM_x:
5181 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
5182 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
5183 ~IXGBE_DMATXCTL_TE));
5189 if (!pci_channel_offline(adapter->pdev))
5190 ixgbe_reset(adapter);
5192 /* power down the optics for 82599 SFP+ fiber */
5193 if (hw->mac.ops.disable_tx_laser)
5194 hw->mac.ops.disable_tx_laser(hw);
5196 ixgbe_clean_all_tx_rings(adapter);
5197 ixgbe_clean_all_rx_rings(adapter);
5199 #ifdef CONFIG_IXGBE_DCA
5200 /* since we reset the hardware DCA settings were cleared */
5201 ixgbe_setup_dca(adapter);
5206 * ixgbe_tx_timeout - Respond to a Tx Hang
5207 * @netdev: network interface device structure
5209 static void ixgbe_tx_timeout(struct net_device *netdev)
5211 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5213 /* Do the reset outside of interrupt context */
5214 ixgbe_tx_timeout_reset(adapter);
5218 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5219 * @adapter: board private structure to initialize
5221 * ixgbe_sw_init initializes the Adapter private data structure.
5222 * Fields are initialized based on PCI device information and
5223 * OS network device settings (MTU size).
5225 static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
5227 struct ixgbe_hw *hw = &adapter->hw;
5228 struct pci_dev *pdev = adapter->pdev;
5229 unsigned int rss, fdir;
5231 #ifdef CONFIG_IXGBE_DCB
5233 struct tc_configuration *tc;
5236 /* PCI config space info */
5238 hw->vendor_id = pdev->vendor;
5239 hw->device_id = pdev->device;
5240 hw->revision_id = pdev->revision;
5241 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5242 hw->subsystem_device_id = pdev->subsystem_device;
5244 /* Set common capability flags and settings */
5245 rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
5246 adapter->ring_feature[RING_F_RSS].limit = rss;
5247 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5248 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
5249 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
5250 adapter->atr_sample_rate = 20;
5251 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
5252 adapter->ring_feature[RING_F_FDIR].limit = fdir;
5253 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
5254 #ifdef CONFIG_IXGBE_DCA
5255 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
5258 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5259 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5260 #ifdef CONFIG_IXGBE_DCB
5261 /* Default traffic class to use for FCoE */
5262 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
5263 #endif /* CONFIG_IXGBE_DCB */
5264 #endif /* IXGBE_FCOE */
5266 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
5267 hw->mac.num_rar_entries,
5270 /* Set MAC specific capability flags and exceptions */
5271 switch (hw->mac.type) {
5272 case ixgbe_mac_82598EB:
5273 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
5274 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
5276 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5277 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
5279 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
5280 adapter->ring_feature[RING_F_FDIR].limit = 0;
5281 adapter->atr_sample_rate = 0;
5282 adapter->fdir_pballoc = 0;
5284 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
5285 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5286 #ifdef CONFIG_IXGBE_DCB
5287 adapter->fcoe.up = 0;
5288 #endif /* IXGBE_DCB */
5289 #endif /* IXGBE_FCOE */
5291 case ixgbe_mac_82599EB:
5292 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5293 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5295 case ixgbe_mac_X540:
5296 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
5297 if (fwsm & IXGBE_FWSM_TS_ENABLED)
5298 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5300 case ixgbe_mac_X550EM_x:
5301 case ixgbe_mac_X550:
5302 #ifdef CONFIG_IXGBE_DCA
5303 adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
5311 /* FCoE support exists, always init the FCoE lock */
5312 spin_lock_init(&adapter->fcoe.lock);
5315 /* n-tuple support exists, always init our spinlock */
5316 spin_lock_init(&adapter->fdir_perfect_lock);
5318 #ifdef CONFIG_IXGBE_DCB
5319 switch (hw->mac.type) {
5320 case ixgbe_mac_X540:
5321 case ixgbe_mac_X550:
5322 case ixgbe_mac_X550EM_x:
5323 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5324 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5327 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5328 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5332 /* Configure DCB traffic classes */
5333 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5334 tc = &adapter->dcb_cfg.tc_config[j];
5335 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5336 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5337 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5338 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5339 tc->dcb_pfc = pfc_disabled;
5342 /* Initialize default user to priority mapping, UPx->TC0 */
5343 tc = &adapter->dcb_cfg.tc_config[0];
5344 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5345 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5347 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5348 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5349 adapter->dcb_cfg.pfc_mode_enable = false;
5350 adapter->dcb_set_bitmap = 0x00;
5351 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
5352 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
5353 sizeof(adapter->temp_dcb_cfg));
5357 /* default flow control settings */
5358 hw->fc.requested_mode = ixgbe_fc_full;
5359 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
5360 ixgbe_pbthresh_setup(adapter);
5361 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5362 hw->fc.send_xon = true;
5363 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
5365 #ifdef CONFIG_PCI_IOV
5367 e_dev_warn("Enabling SR-IOV VFs using the max_vfs module parameter is deprecated - please use the pci sysfs interface instead.\n");
5369 /* assign number of SR-IOV VFs */
5370 if (hw->mac.type != ixgbe_mac_82598EB) {
5371 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
5372 adapter->num_vfs = 0;
5373 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
5375 adapter->num_vfs = max_vfs;
5378 #endif /* CONFIG_PCI_IOV */
5380 /* enable itr by default in dynamic mode */
5381 adapter->rx_itr_setting = 1;
5382 adapter->tx_itr_setting = 1;
5384 /* set default ring sizes */
5385 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5386 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5388 /* set default work limits */
5389 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
5391 /* initialize eeprom parameters */
5392 if (ixgbe_init_eeprom_params_generic(hw)) {
5393 e_dev_err("EEPROM initialization failed\n");
5397 /* PF holds first pool slot */
5398 set_bit(0, &adapter->fwd_bitmask);
5399 set_bit(__IXGBE_DOWN, &adapter->state);
5405 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
5406 * @tx_ring: tx descriptor ring (for a specific queue) to setup
5408 * Return 0 on success, negative on failure
5410 int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
5412 struct device *dev = tx_ring->dev;
5413 int orig_node = dev_to_node(dev);
5417 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
5419 if (tx_ring->q_vector)
5420 ring_node = tx_ring->q_vector->numa_node;
5422 tx_ring->tx_buffer_info = vzalloc_node(size, ring_node);
5423 if (!tx_ring->tx_buffer_info)
5424 tx_ring->tx_buffer_info = vzalloc(size);
5425 if (!tx_ring->tx_buffer_info)
5428 u64_stats_init(&tx_ring->syncp);
5430 /* round up to nearest 4K */
5431 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
5432 tx_ring->size = ALIGN(tx_ring->size, 4096);
5434 set_dev_node(dev, ring_node);
5435 tx_ring->desc = dma_alloc_coherent(dev,
5439 set_dev_node(dev, orig_node);
5441 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5442 &tx_ring->dma, GFP_KERNEL);
5446 tx_ring->next_to_use = 0;
5447 tx_ring->next_to_clean = 0;
5451 vfree(tx_ring->tx_buffer_info);
5452 tx_ring->tx_buffer_info = NULL;
5453 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
5458 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5459 * @adapter: board private structure
5461 * If this function returns with an error, then it's possible one or
5462 * more of the rings is populated (while the rest are not). It is the
5463 * callers duty to clean those orphaned rings.
5465 * Return 0 on success, negative on failure
5467 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5471 for (i = 0; i < adapter->num_tx_queues; i++) {
5472 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
5476 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
5482 /* rewind the index freeing the rings as we go */
5484 ixgbe_free_tx_resources(adapter->tx_ring[i]);
5489 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
5490 * @rx_ring: rx descriptor ring (for a specific queue) to setup
5492 * Returns 0 on success, negative on failure
5494 int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
5496 struct device *dev = rx_ring->dev;
5497 int orig_node = dev_to_node(dev);
5501 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
5503 if (rx_ring->q_vector)
5504 ring_node = rx_ring->q_vector->numa_node;
5506 rx_ring->rx_buffer_info = vzalloc_node(size, ring_node);
5507 if (!rx_ring->rx_buffer_info)
5508 rx_ring->rx_buffer_info = vzalloc(size);
5509 if (!rx_ring->rx_buffer_info)
5512 u64_stats_init(&rx_ring->syncp);
5514 /* Round up to nearest 4K */
5515 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5516 rx_ring->size = ALIGN(rx_ring->size, 4096);
5518 set_dev_node(dev, ring_node);
5519 rx_ring->desc = dma_alloc_coherent(dev,
5523 set_dev_node(dev, orig_node);
5525 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5526 &rx_ring->dma, GFP_KERNEL);
5530 rx_ring->next_to_clean = 0;
5531 rx_ring->next_to_use = 0;
5535 vfree(rx_ring->rx_buffer_info);
5536 rx_ring->rx_buffer_info = NULL;
5537 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
5542 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5543 * @adapter: board private structure
5545 * If this function returns with an error, then it's possible one or
5546 * more of the rings is populated (while the rest are not). It is the
5547 * callers duty to clean those orphaned rings.
5549 * Return 0 on success, negative on failure
5551 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5555 for (i = 0; i < adapter->num_rx_queues; i++) {
5556 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
5560 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
5565 err = ixgbe_setup_fcoe_ddp_resources(adapter);
5570 /* rewind the index freeing the rings as we go */
5572 ixgbe_free_rx_resources(adapter->rx_ring[i]);
5577 * ixgbe_free_tx_resources - Free Tx Resources per Queue
5578 * @tx_ring: Tx descriptor ring for a specific queue
5580 * Free all transmit software resources
5582 void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
5584 ixgbe_clean_tx_ring(tx_ring);
5586 vfree(tx_ring->tx_buffer_info);
5587 tx_ring->tx_buffer_info = NULL;
5589 /* if not set, then don't free */
5593 dma_free_coherent(tx_ring->dev, tx_ring->size,
5594 tx_ring->desc, tx_ring->dma);
5596 tx_ring->desc = NULL;
5600 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5601 * @adapter: board private structure
5603 * Free all transmit software resources
5605 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5609 for (i = 0; i < adapter->num_tx_queues; i++)
5610 if (adapter->tx_ring[i]->desc)
5611 ixgbe_free_tx_resources(adapter->tx_ring[i]);
5615 * ixgbe_free_rx_resources - Free Rx Resources
5616 * @rx_ring: ring to clean the resources from
5618 * Free all receive software resources
5620 void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
5622 ixgbe_clean_rx_ring(rx_ring);
5624 vfree(rx_ring->rx_buffer_info);
5625 rx_ring->rx_buffer_info = NULL;
5627 /* if not set, then don't free */
5631 dma_free_coherent(rx_ring->dev, rx_ring->size,
5632 rx_ring->desc, rx_ring->dma);
5634 rx_ring->desc = NULL;
5638 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5639 * @adapter: board private structure
5641 * Free all receive software resources
5643 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5648 ixgbe_free_fcoe_ddp_resources(adapter);
5651 for (i = 0; i < adapter->num_rx_queues; i++)
5652 if (adapter->rx_ring[i]->desc)
5653 ixgbe_free_rx_resources(adapter->rx_ring[i]);
5657 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5658 * @netdev: network interface device structure
5659 * @new_mtu: new value for maximum frame size
5661 * Returns 0 on success, negative on failure
5663 static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5665 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5666 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5668 /* MTU < 68 is an error and causes problems on some kernels */
5669 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5673 * For 82599EB we cannot allow legacy VFs to enable their receive
5674 * paths when MTU greater than 1500 is configured. So display a
5675 * warning that legacy VFs will be disabled.
5677 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
5678 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
5679 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
5680 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
5682 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
5684 /* must set new MTU before calling down or up */
5685 netdev->mtu = new_mtu;
5687 if (netif_running(netdev))
5688 ixgbe_reinit_locked(adapter);
5694 * ixgbe_open - Called when a network interface is made active
5695 * @netdev: network interface device structure
5697 * Returns 0 on success, negative value on failure
5699 * The open entry point is called when a network interface is made
5700 * active by the system (IFF_UP). At this point all resources needed
5701 * for transmit and receive operations are allocated, the interrupt
5702 * handler is registered with the OS, the watchdog timer is started,
5703 * and the stack is notified that the interface is ready.
5705 static int ixgbe_open(struct net_device *netdev)
5707 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5708 struct ixgbe_hw *hw = &adapter->hw;
5711 /* disallow open during test */
5712 if (test_bit(__IXGBE_TESTING, &adapter->state))
5715 netif_carrier_off(netdev);
5717 /* allocate transmit descriptors */
5718 err = ixgbe_setup_all_tx_resources(adapter);
5722 /* allocate receive descriptors */
5723 err = ixgbe_setup_all_rx_resources(adapter);
5727 ixgbe_configure(adapter);
5729 err = ixgbe_request_irq(adapter);
5733 /* Notify the stack of the actual queue counts. */
5734 if (adapter->num_rx_pools > 1)
5735 queues = adapter->num_rx_queues_per_pool;
5737 queues = adapter->num_tx_queues;
5739 err = netif_set_real_num_tx_queues(netdev, queues);
5741 goto err_set_queues;
5743 if (adapter->num_rx_pools > 1 &&
5744 adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
5745 queues = IXGBE_MAX_L2A_QUEUES;
5747 queues = adapter->num_rx_queues;
5748 err = netif_set_real_num_rx_queues(netdev, queues);
5750 goto err_set_queues;
5752 ixgbe_ptp_init(adapter);
5754 ixgbe_up_complete(adapter);
5756 #if IS_ENABLED(CONFIG_IXGBE_VXLAN)
5757 vxlan_get_rx_port(netdev);
5763 ixgbe_free_irq(adapter);
5765 ixgbe_free_all_rx_resources(adapter);
5766 if (hw->phy.ops.set_phy_power && !adapter->wol)
5767 hw->phy.ops.set_phy_power(&adapter->hw, false);
5769 ixgbe_free_all_tx_resources(adapter);
5771 ixgbe_reset(adapter);
5776 static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
5778 ixgbe_ptp_suspend(adapter);
5780 ixgbe_down(adapter);
5781 ixgbe_free_irq(adapter);
5783 ixgbe_free_all_tx_resources(adapter);
5784 ixgbe_free_all_rx_resources(adapter);
5788 * ixgbe_close - Disables a network interface
5789 * @netdev: network interface device structure
5791 * Returns 0, this is not allowed to fail
5793 * The close entry point is called when an interface is de-activated
5794 * by the OS. The hardware is still under the drivers control, but
5795 * needs to be disabled. A global MAC reset is issued to stop the
5796 * hardware, and all transmit and receive resources are freed.
5798 static int ixgbe_close(struct net_device *netdev)
5800 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5802 ixgbe_ptp_stop(adapter);
5804 ixgbe_close_suspend(adapter);
5806 ixgbe_fdir_filter_exit(adapter);
5808 ixgbe_release_hw_control(adapter);
5814 static int ixgbe_resume(struct pci_dev *pdev)
5816 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5817 struct net_device *netdev = adapter->netdev;
5820 adapter->hw.hw_addr = adapter->io_addr;
5821 pci_set_power_state(pdev, PCI_D0);
5822 pci_restore_state(pdev);
5824 * pci_restore_state clears dev->state_saved so call
5825 * pci_save_state to restore it.
5827 pci_save_state(pdev);
5829 err = pci_enable_device_mem(pdev);
5831 e_dev_err("Cannot enable PCI device from suspend\n");
5834 smp_mb__before_atomic();
5835 clear_bit(__IXGBE_DISABLED, &adapter->state);
5836 pci_set_master(pdev);
5838 pci_wake_from_d3(pdev, false);
5840 ixgbe_reset(adapter);
5842 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5845 err = ixgbe_init_interrupt_scheme(adapter);
5846 if (!err && netif_running(netdev))
5847 err = ixgbe_open(netdev);
5854 netif_device_attach(netdev);
5858 #endif /* CONFIG_PM */
5860 static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
5862 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5863 struct net_device *netdev = adapter->netdev;
5864 struct ixgbe_hw *hw = &adapter->hw;
5866 u32 wufc = adapter->wol;
5871 netif_device_detach(netdev);
5874 if (netif_running(netdev))
5875 ixgbe_close_suspend(adapter);
5878 ixgbe_clear_interrupt_scheme(adapter);
5881 retval = pci_save_state(pdev);
5886 if (hw->mac.ops.stop_link_on_d3)
5887 hw->mac.ops.stop_link_on_d3(hw);
5890 ixgbe_set_rx_mode(netdev);
5892 /* enable the optics for 82599 SFP+ fiber as we can WoL */
5893 if (hw->mac.ops.enable_tx_laser)
5894 hw->mac.ops.enable_tx_laser(hw);
5896 /* turn on all-multi mode if wake on multicast is enabled */
5897 if (wufc & IXGBE_WUFC_MC) {
5898 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5899 fctrl |= IXGBE_FCTRL_MPE;
5900 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5903 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5904 ctrl |= IXGBE_CTRL_GIO_DIS;
5905 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5907 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5909 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5910 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5913 switch (hw->mac.type) {
5914 case ixgbe_mac_82598EB:
5915 pci_wake_from_d3(pdev, false);
5917 case ixgbe_mac_82599EB:
5918 case ixgbe_mac_X540:
5919 case ixgbe_mac_X550:
5920 case ixgbe_mac_X550EM_x:
5921 pci_wake_from_d3(pdev, !!wufc);
5927 *enable_wake = !!wufc;
5928 if (hw->phy.ops.set_phy_power && !*enable_wake)
5929 hw->phy.ops.set_phy_power(hw, false);
5931 ixgbe_release_hw_control(adapter);
5933 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
5934 pci_disable_device(pdev);
5940 static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5945 retval = __ixgbe_shutdown(pdev, &wake);
5950 pci_prepare_to_sleep(pdev);
5952 pci_wake_from_d3(pdev, false);
5953 pci_set_power_state(pdev, PCI_D3hot);
5958 #endif /* CONFIG_PM */
5960 static void ixgbe_shutdown(struct pci_dev *pdev)
5964 __ixgbe_shutdown(pdev, &wake);
5966 if (system_state == SYSTEM_POWER_OFF) {
5967 pci_wake_from_d3(pdev, wake);
5968 pci_set_power_state(pdev, PCI_D3hot);
5973 * ixgbe_update_stats - Update the board statistics counters.
5974 * @adapter: board private structure
5976 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5978 struct net_device *netdev = adapter->netdev;
5979 struct ixgbe_hw *hw = &adapter->hw;
5980 struct ixgbe_hw_stats *hwstats = &adapter->stats;
5982 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
5983 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5984 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5985 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
5987 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5988 test_bit(__IXGBE_RESETTING, &adapter->state))
5991 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
5994 for (i = 0; i < adapter->num_rx_queues; i++) {
5995 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5996 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
5998 adapter->rsc_total_count = rsc_count;
5999 adapter->rsc_total_flush = rsc_flush;
6002 for (i = 0; i < adapter->num_rx_queues; i++) {
6003 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
6004 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
6005 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
6006 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
6007 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
6008 bytes += rx_ring->stats.bytes;
6009 packets += rx_ring->stats.packets;
6011 adapter->non_eop_descs = non_eop_descs;
6012 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
6013 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
6014 adapter->hw_csum_rx_error = hw_csum_rx_error;
6015 netdev->stats.rx_bytes = bytes;
6016 netdev->stats.rx_packets = packets;
6020 /* gather some stats to the adapter struct that are per queue */
6021 for (i = 0; i < adapter->num_tx_queues; i++) {
6022 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6023 restart_queue += tx_ring->tx_stats.restart_queue;
6024 tx_busy += tx_ring->tx_stats.tx_busy;
6025 bytes += tx_ring->stats.bytes;
6026 packets += tx_ring->stats.packets;
6028 adapter->restart_queue = restart_queue;
6029 adapter->tx_busy = tx_busy;
6030 netdev->stats.tx_bytes = bytes;
6031 netdev->stats.tx_packets = packets;
6033 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
6035 /* 8 register reads */
6036 for (i = 0; i < 8; i++) {
6037 /* for packet buffers not used, the register should read 0 */
6038 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
6040 hwstats->mpc[i] += mpc;
6041 total_mpc += hwstats->mpc[i];
6042 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
6043 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
6044 switch (hw->mac.type) {
6045 case ixgbe_mac_82598EB:
6046 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
6047 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
6048 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
6049 hwstats->pxonrxc[i] +=
6050 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
6052 case ixgbe_mac_82599EB:
6053 case ixgbe_mac_X540:
6054 case ixgbe_mac_X550:
6055 case ixgbe_mac_X550EM_x:
6056 hwstats->pxonrxc[i] +=
6057 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
6064 /*16 register reads */
6065 for (i = 0; i < 16; i++) {
6066 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
6067 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
6068 if ((hw->mac.type == ixgbe_mac_82599EB) ||
6069 (hw->mac.type == ixgbe_mac_X540) ||
6070 (hw->mac.type == ixgbe_mac_X550) ||
6071 (hw->mac.type == ixgbe_mac_X550EM_x)) {
6072 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
6073 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
6074 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
6075 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
6079 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
6080 /* work around hardware counting issue */
6081 hwstats->gprc -= missed_rx;
6083 ixgbe_update_xoff_received(adapter);
6085 /* 82598 hardware only has a 32 bit counter in the high register */
6086 switch (hw->mac.type) {
6087 case ixgbe_mac_82598EB:
6088 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
6089 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
6090 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
6091 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
6093 case ixgbe_mac_X540:
6094 case ixgbe_mac_X550:
6095 case ixgbe_mac_X550EM_x:
6096 /* OS2BMC stats are X540 and later */
6097 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
6098 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
6099 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
6100 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
6101 case ixgbe_mac_82599EB:
6102 for (i = 0; i < 16; i++)
6103 adapter->hw_rx_no_dma_resources +=
6104 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
6105 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
6106 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
6107 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
6108 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
6109 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
6110 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
6111 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
6112 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
6113 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
6115 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
6116 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
6117 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
6118 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
6119 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
6120 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
6121 /* Add up per cpu counters for total ddp aloc fail */
6122 if (adapter->fcoe.ddp_pool) {
6123 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
6124 struct ixgbe_fcoe_ddp_pool *ddp_pool;
6126 u64 noddp = 0, noddp_ext_buff = 0;
6127 for_each_possible_cpu(cpu) {
6128 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
6129 noddp += ddp_pool->noddp;
6130 noddp_ext_buff += ddp_pool->noddp_ext_buff;
6132 hwstats->fcoe_noddp = noddp;
6133 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
6135 #endif /* IXGBE_FCOE */
6140 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
6141 hwstats->bprc += bprc;
6142 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
6143 if (hw->mac.type == ixgbe_mac_82598EB)
6144 hwstats->mprc -= bprc;
6145 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
6146 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
6147 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
6148 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
6149 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
6150 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
6151 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
6152 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
6153 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
6154 hwstats->lxontxc += lxon;
6155 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
6156 hwstats->lxofftxc += lxoff;
6157 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
6158 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
6160 * 82598 errata - tx of flow control packets is included in tx counters
6162 xon_off_tot = lxon + lxoff;
6163 hwstats->gptc -= xon_off_tot;
6164 hwstats->mptc -= xon_off_tot;
6165 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
6166 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
6167 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
6168 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
6169 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
6170 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
6171 hwstats->ptc64 -= xon_off_tot;
6172 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
6173 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
6174 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
6175 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
6176 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
6177 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
6179 /* Fill out the OS statistics structure */
6180 netdev->stats.multicast = hwstats->mprc;
6183 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
6184 netdev->stats.rx_dropped = 0;
6185 netdev->stats.rx_length_errors = hwstats->rlec;
6186 netdev->stats.rx_crc_errors = hwstats->crcerrs;
6187 netdev->stats.rx_missed_errors = total_mpc;
6191 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
6192 * @adapter: pointer to the device adapter structure
6194 static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
6196 struct ixgbe_hw *hw = &adapter->hw;
6199 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
6202 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6204 /* if interface is down do nothing */
6205 if (test_bit(__IXGBE_DOWN, &adapter->state))
6208 /* do nothing if we are not using signature filters */
6209 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6212 adapter->fdir_overflow++;
6214 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6215 for (i = 0; i < adapter->num_tx_queues; i++)
6216 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
6217 &(adapter->tx_ring[i]->state));
6218 /* re-enable flow director interrupts */
6219 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
6221 e_err(probe, "failed to finish FDIR re-initialization, "
6222 "ignored adding FDIR ATR filters\n");
6227 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
6228 * @adapter: pointer to the device adapter structure
6230 * This function serves two purposes. First it strobes the interrupt lines
6231 * in order to make certain interrupts are occurring. Secondly it sets the
6232 * bits needed to check for TX hangs. As a result we should immediately
6233 * determine if a hang has occurred.
6235 static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6237 struct ixgbe_hw *hw = &adapter->hw;
6241 /* If we're down, removing or resetting, just bail */
6242 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6243 test_bit(__IXGBE_REMOVING, &adapter->state) ||
6244 test_bit(__IXGBE_RESETTING, &adapter->state))
6247 /* Force detection of hung controller */
6248 if (netif_carrier_ok(adapter->netdev)) {
6249 for (i = 0; i < adapter->num_tx_queues; i++)
6250 set_check_for_tx_hang(adapter->tx_ring[i]);
6253 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
6255 * for legacy and MSI interrupts don't set any bits
6256 * that are enabled for EIAM, because this operation
6257 * would set *both* EIMS and EICS for any bit in EIAM
6259 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6260 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
6262 /* get one bit for every active tx/rx interrupt vector */
6263 for (i = 0; i < adapter->num_q_vectors; i++) {
6264 struct ixgbe_q_vector *qv = adapter->q_vector[i];
6265 if (qv->rx.ring || qv->tx.ring)
6266 eics |= ((u64)1 << i);
6270 /* Cause software interrupt to ensure rings are cleaned */
6271 ixgbe_irq_rearm_queues(adapter, eics);
6275 * ixgbe_watchdog_update_link - update the link status
6276 * @adapter: pointer to the device adapter structure
6277 * @link_speed: pointer to a u32 to store the link_speed
6279 static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
6281 struct ixgbe_hw *hw = &adapter->hw;
6282 u32 link_speed = adapter->link_speed;
6283 bool link_up = adapter->link_up;
6284 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
6286 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6289 if (hw->mac.ops.check_link) {
6290 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
6292 /* always assume link is up, if no check link function */
6293 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6297 if (adapter->ixgbe_ieee_pfc)
6298 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
6300 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
6301 hw->mac.ops.fc_enable(hw);
6302 ixgbe_set_rx_drop_en(adapter);
6306 time_after(jiffies, (adapter->link_check_timeout +
6307 IXGBE_TRY_LINK_TIMEOUT))) {
6308 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6309 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6310 IXGBE_WRITE_FLUSH(hw);
6313 adapter->link_up = link_up;
6314 adapter->link_speed = link_speed;
6317 static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
6319 #ifdef CONFIG_IXGBE_DCB
6320 struct net_device *netdev = adapter->netdev;
6321 struct dcb_app app = {
6322 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
6327 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
6328 up = dcb_ieee_getapp_mask(netdev, &app);
6330 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
6335 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6336 * print link up message
6337 * @adapter: pointer to the device adapter structure
6339 static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6341 struct net_device *netdev = adapter->netdev;
6342 struct ixgbe_hw *hw = &adapter->hw;
6343 struct net_device *upper;
6344 struct list_head *iter;
6345 u32 link_speed = adapter->link_speed;
6346 bool flow_rx, flow_tx;
6348 /* only continue if link was previously down */
6349 if (netif_carrier_ok(netdev))
6352 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6354 switch (hw->mac.type) {
6355 case ixgbe_mac_82598EB: {
6356 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6357 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6358 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6359 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6362 case ixgbe_mac_X540:
6363 case ixgbe_mac_X550:
6364 case ixgbe_mac_X550EM_x:
6365 case ixgbe_mac_82599EB: {
6366 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6367 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6368 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6369 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6378 adapter->last_rx_ptp_check = jiffies;
6380 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
6381 ixgbe_ptp_start_cyclecounter(adapter);
6383 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6384 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6386 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6388 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6391 ((flow_rx && flow_tx) ? "RX/TX" :
6393 (flow_tx ? "TX" : "None"))));
6395 netif_carrier_on(netdev);
6396 ixgbe_check_vf_rate_limit(adapter);
6398 /* enable transmits */
6399 netif_tx_wake_all_queues(adapter->netdev);
6401 /* enable any upper devices */
6403 netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
6404 if (netif_is_macvlan(upper)) {
6405 struct macvlan_dev *vlan = netdev_priv(upper);
6408 netif_tx_wake_all_queues(upper);
6413 /* update the default user priority for VFs */
6414 ixgbe_update_default_up(adapter);
6416 /* ping all the active vfs to let them know link has changed */
6417 ixgbe_ping_all_vfs(adapter);
6421 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6422 * print link down message
6423 * @adapter: pointer to the adapter structure
6425 static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
6427 struct net_device *netdev = adapter->netdev;
6428 struct ixgbe_hw *hw = &adapter->hw;
6430 adapter->link_up = false;
6431 adapter->link_speed = 0;
6433 /* only continue if link was up previously */
6434 if (!netif_carrier_ok(netdev))
6437 /* poll for SFP+ cable when link is down */
6438 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6439 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6441 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
6442 ixgbe_ptp_start_cyclecounter(adapter);
6444 e_info(drv, "NIC Link is Down\n");
6445 netif_carrier_off(netdev);
6447 /* ping all the active vfs to let them know link has changed */
6448 ixgbe_ping_all_vfs(adapter);
6451 static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
6455 for (i = 0; i < adapter->num_tx_queues; i++) {
6456 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6458 if (tx_ring->next_to_use != tx_ring->next_to_clean)
6465 static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
6467 struct ixgbe_hw *hw = &adapter->hw;
6468 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
6469 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
6473 if (!adapter->num_vfs)
6476 /* resetting the PF is only needed for MAC before X550 */
6477 if (hw->mac.type >= ixgbe_mac_X550)
6480 for (i = 0; i < adapter->num_vfs; i++) {
6481 for (j = 0; j < q_per_pool; j++) {
6484 h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
6485 t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
6496 * ixgbe_watchdog_flush_tx - flush queues on link down
6497 * @adapter: pointer to the device adapter structure
6499 static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6501 if (!netif_carrier_ok(adapter->netdev)) {
6502 if (ixgbe_ring_tx_pending(adapter) ||
6503 ixgbe_vf_tx_pending(adapter)) {
6504 /* We've lost link, so the controller stops DMA,
6505 * but we've got queued Tx work that's never going
6506 * to get done, so reset controller to flush Tx.
6507 * (Do the reset outside of interrupt context).
6509 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
6510 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
6515 #ifdef CONFIG_PCI_IOV
6516 static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter,
6517 struct pci_dev *vfdev)
6519 if (!pci_wait_for_pending_transaction(vfdev))
6520 e_dev_warn("Issuing VFLR with pending transactions\n");
6522 e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev));
6523 pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
6528 static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6530 struct ixgbe_hw *hw = &adapter->hw;
6531 struct pci_dev *pdev = adapter->pdev;
6532 struct pci_dev *vfdev;
6535 unsigned short vf_id;
6537 if (!(netif_carrier_ok(adapter->netdev)))
6540 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6541 if (gpc) /* If incrementing then no need for the check below */
6543 /* Check to see if a bad DMA write target from an errant or
6544 * malicious VF has caused a PCIe error. If so then we can
6545 * issue a VFLR to the offending VF(s) and then resume without
6546 * requesting a full slot reset.
6552 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
6556 /* get the device ID for the VF */
6557 pci_read_config_word(pdev, pos + PCI_SRIOV_VF_DID, &vf_id);
6559 /* check status reg for all VFs owned by this PF */
6560 vfdev = pci_get_device(pdev->vendor, vf_id, NULL);
6562 if (vfdev->is_virtfn && (vfdev->physfn == pdev)) {
6565 pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
6566 if (status_reg & PCI_STATUS_REC_MASTER_ABORT)
6568 ixgbe_issue_vf_flr(adapter, vfdev);
6571 vfdev = pci_get_device(pdev->vendor, vf_id, vfdev);
6575 static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6579 /* Do not perform spoof check for 82598 or if not in IOV mode */
6580 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
6581 adapter->num_vfs == 0)
6584 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6587 * ssvpc register is cleared on read, if zero then no
6588 * spoofed packets in the last interval.
6593 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
6596 static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
6601 ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
6604 #endif /* CONFIG_PCI_IOV */
6608 * ixgbe_watchdog_subtask - check and bring link up
6609 * @adapter: pointer to the device adapter structure
6611 static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
6613 /* if interface is down, removing or resetting, do nothing */
6614 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6615 test_bit(__IXGBE_REMOVING, &adapter->state) ||
6616 test_bit(__IXGBE_RESETTING, &adapter->state))
6619 ixgbe_watchdog_update_link(adapter);
6621 if (adapter->link_up)
6622 ixgbe_watchdog_link_is_up(adapter);
6624 ixgbe_watchdog_link_is_down(adapter);
6626 ixgbe_check_for_bad_vf(adapter);
6627 ixgbe_spoof_check(adapter);
6628 ixgbe_update_stats(adapter);
6630 ixgbe_watchdog_flush_tx(adapter);
6634 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6635 * @adapter: the ixgbe adapter structure
6637 static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6639 struct ixgbe_hw *hw = &adapter->hw;
6642 /* not searching for SFP so there is nothing to do here */
6643 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6644 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6647 /* someone else is in init, wait until next service event */
6648 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6651 err = hw->phy.ops.identify_sfp(hw);
6652 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6655 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6656 /* If no cable is present, then we need to reset
6657 * the next time we find a good cable. */
6658 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6665 /* exit if reset not needed */
6666 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6669 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6672 * A module may be identified correctly, but the EEPROM may not have
6673 * support for that module. setup_sfp() will fail in that case, so
6674 * we should not allow that module to load.
6676 if (hw->mac.type == ixgbe_mac_82598EB)
6677 err = hw->phy.ops.reset(hw);
6679 err = hw->mac.ops.setup_sfp(hw);
6681 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6684 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6685 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6688 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6690 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6691 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6692 e_dev_err("failed to initialize because an unsupported "
6693 "SFP+ module type was detected.\n");
6694 e_dev_err("Reload the driver after installing a "
6695 "supported module.\n");
6696 unregister_netdev(adapter->netdev);
6701 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6702 * @adapter: the ixgbe adapter structure
6704 static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6706 struct ixgbe_hw *hw = &adapter->hw;
6708 bool autoneg = false;
6710 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6713 /* someone else is in init, wait until next service event */
6714 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6717 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6719 speed = hw->phy.autoneg_advertised;
6720 if ((!speed) && (hw->mac.ops.get_link_capabilities)) {
6721 hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
6723 /* setup the highest link when no autoneg */
6725 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
6726 speed = IXGBE_LINK_SPEED_10GB_FULL;
6730 if (hw->mac.ops.setup_link)
6731 hw->mac.ops.setup_link(hw, speed, true);
6733 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6734 adapter->link_check_timeout = jiffies;
6735 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6739 * ixgbe_service_timer - Timer Call-back
6740 * @data: pointer to adapter cast into an unsigned long
6742 static void ixgbe_service_timer(unsigned long data)
6744 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6745 unsigned long next_event_offset;
6747 /* poll faster when waiting for link */
6748 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6749 next_event_offset = HZ / 10;
6751 next_event_offset = HZ * 2;
6753 /* Reset the timer */
6754 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6756 ixgbe_service_event_schedule(adapter);
6759 static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
6761 struct ixgbe_hw *hw = &adapter->hw;
6764 if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
6767 adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
6769 if (!hw->phy.ops.handle_lasi)
6772 status = hw->phy.ops.handle_lasi(&adapter->hw);
6773 if (status != IXGBE_ERR_OVERTEMP)
6776 e_crit(drv, "%s\n", ixgbe_overheat_msg);
6779 static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6781 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6784 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6786 /* If we're already down, removing or resetting, just bail */
6787 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6788 test_bit(__IXGBE_REMOVING, &adapter->state) ||
6789 test_bit(__IXGBE_RESETTING, &adapter->state))
6792 ixgbe_dump(adapter);
6793 netdev_err(adapter->netdev, "Reset adapter\n");
6794 adapter->tx_timeout_count++;
6797 ixgbe_reinit_locked(adapter);
6802 * ixgbe_service_task - manages and runs subtasks
6803 * @work: pointer to work_struct containing our data
6805 static void ixgbe_service_task(struct work_struct *work)
6807 struct ixgbe_adapter *adapter = container_of(work,
6808 struct ixgbe_adapter,
6810 if (ixgbe_removed(adapter->hw.hw_addr)) {
6811 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
6813 ixgbe_down(adapter);
6816 ixgbe_service_event_complete(adapter);
6819 ixgbe_reset_subtask(adapter);
6820 ixgbe_phy_interrupt_subtask(adapter);
6821 ixgbe_sfp_detection_subtask(adapter);
6822 ixgbe_sfp_link_config_subtask(adapter);
6823 ixgbe_check_overtemp_subtask(adapter);
6824 ixgbe_watchdog_subtask(adapter);
6825 ixgbe_fdir_reinit_subtask(adapter);
6826 ixgbe_check_hang_subtask(adapter);
6828 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
6829 ixgbe_ptp_overflow_check(adapter);
6830 ixgbe_ptp_rx_hang(adapter);
6833 ixgbe_service_event_complete(adapter);
6836 static int ixgbe_tso(struct ixgbe_ring *tx_ring,
6837 struct ixgbe_tx_buffer *first,
6840 struct sk_buff *skb = first->skb;
6841 u32 vlan_macip_lens, type_tucmd;
6842 u32 mss_l4len_idx, l4len;
6845 if (skb->ip_summed != CHECKSUM_PARTIAL)
6848 if (!skb_is_gso(skb))
6851 err = skb_cow_head(skb, 0);
6855 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6856 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6858 if (first->protocol == htons(ETH_P_IP)) {
6859 struct iphdr *iph = ip_hdr(skb);
6862 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6866 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6867 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
6868 IXGBE_TX_FLAGS_CSUM |
6869 IXGBE_TX_FLAGS_IPV4;
6870 } else if (skb_is_gso_v6(skb)) {
6871 ipv6_hdr(skb)->payload_len = 0;
6872 tcp_hdr(skb)->check =
6873 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6874 &ipv6_hdr(skb)->daddr,
6876 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
6877 IXGBE_TX_FLAGS_CSUM;
6880 /* compute header lengths */
6881 l4len = tcp_hdrlen(skb);
6882 *hdr_len = skb_transport_offset(skb) + l4len;
6884 /* update gso size and bytecount with header size */
6885 first->gso_segs = skb_shinfo(skb)->gso_segs;
6886 first->bytecount += (first->gso_segs - 1) * *hdr_len;
6888 /* mss_l4len_id: use 0 as index for TSO */
6889 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6890 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6892 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6893 vlan_macip_lens = skb_network_header_len(skb);
6894 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6895 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6897 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6903 static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
6904 struct ixgbe_tx_buffer *first)
6906 struct sk_buff *skb = first->skb;
6907 u32 vlan_macip_lens = 0;
6908 u32 mss_l4len_idx = 0;
6911 if (skb->ip_summed != CHECKSUM_PARTIAL) {
6912 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6913 !(first->tx_flags & IXGBE_TX_FLAGS_CC))
6917 switch (first->protocol) {
6918 case htons(ETH_P_IP):
6919 vlan_macip_lens |= skb_network_header_len(skb);
6920 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6921 l4_hdr = ip_hdr(skb)->protocol;
6923 case htons(ETH_P_IPV6):
6924 vlan_macip_lens |= skb_network_header_len(skb);
6925 l4_hdr = ipv6_hdr(skb)->nexthdr;
6928 if (unlikely(net_ratelimit())) {
6929 dev_warn(tx_ring->dev,
6930 "partial checksum but proto=%x!\n",
6938 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6939 mss_l4len_idx = tcp_hdrlen(skb) <<
6940 IXGBE_ADVTXD_L4LEN_SHIFT;
6943 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6944 mss_l4len_idx = sizeof(struct sctphdr) <<
6945 IXGBE_ADVTXD_L4LEN_SHIFT;
6948 mss_l4len_idx = sizeof(struct udphdr) <<
6949 IXGBE_ADVTXD_L4LEN_SHIFT;
6952 if (unlikely(net_ratelimit())) {
6953 dev_warn(tx_ring->dev,
6954 "partial checksum but l4 proto=%x!\n",
6960 /* update TX checksum flag */
6961 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
6964 /* vlan_macip_lens: MACLEN, VLAN tag */
6965 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6966 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6968 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6969 type_tucmd, mss_l4len_idx);
6972 #define IXGBE_SET_FLAG(_input, _flag, _result) \
6973 ((_flag <= _result) ? \
6974 ((u32)(_input & _flag) * (_result / _flag)) : \
6975 ((u32)(_input & _flag) / (_flag / _result)))
6977 static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
6979 /* set type for advanced descriptor with frame checksum insertion */
6980 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
6981 IXGBE_ADVTXD_DCMD_DEXT |
6982 IXGBE_ADVTXD_DCMD_IFCS;
6984 /* set HW vlan bit if vlan is present */
6985 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
6986 IXGBE_ADVTXD_DCMD_VLE);
6988 /* set segmentation enable bits for TSO/FSO */
6989 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
6990 IXGBE_ADVTXD_DCMD_TSE);
6992 /* set timestamp bit if present */
6993 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
6994 IXGBE_ADVTXD_MAC_TSTAMP);
6996 /* insert frame checksum */
6997 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
7002 static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
7003 u32 tx_flags, unsigned int paylen)
7005 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
7007 /* enable L4 checksum for TSO and TX checksum offload */
7008 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7009 IXGBE_TX_FLAGS_CSUM,
7010 IXGBE_ADVTXD_POPTS_TXSM);
7012 /* enble IPv4 checksum for TSO */
7013 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7014 IXGBE_TX_FLAGS_IPV4,
7015 IXGBE_ADVTXD_POPTS_IXSM);
7018 * Check Context must be set if Tx switch is enabled, which it
7019 * always is for case where virtual functions are running
7021 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7025 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
7028 static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7030 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
7032 /* Herbert's original patch had:
7033 * smp_mb__after_netif_stop_queue();
7034 * but since that doesn't exist yet, just open code it.
7038 /* We need to check again in a case another CPU has just
7039 * made room available.
7041 if (likely(ixgbe_desc_unused(tx_ring) < size))
7044 /* A reprieve! - use start_queue because it doesn't call schedule */
7045 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
7046 ++tx_ring->tx_stats.restart_queue;
7050 static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7052 if (likely(ixgbe_desc_unused(tx_ring) >= size))
7055 return __ixgbe_maybe_stop_tx(tx_ring, size);
7058 #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
7061 static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
7062 struct ixgbe_tx_buffer *first,
7065 struct sk_buff *skb = first->skb;
7066 struct ixgbe_tx_buffer *tx_buffer;
7067 union ixgbe_adv_tx_desc *tx_desc;
7068 struct skb_frag_struct *frag;
7070 unsigned int data_len, size;
7071 u32 tx_flags = first->tx_flags;
7072 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
7073 u16 i = tx_ring->next_to_use;
7075 tx_desc = IXGBE_TX_DESC(tx_ring, i);
7077 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
7079 size = skb_headlen(skb);
7080 data_len = skb->data_len;
7083 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
7084 if (data_len < sizeof(struct fcoe_crc_eof)) {
7085 size -= sizeof(struct fcoe_crc_eof) - data_len;
7088 data_len -= sizeof(struct fcoe_crc_eof);
7093 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
7097 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
7098 if (dma_mapping_error(tx_ring->dev, dma))
7101 /* record length, and DMA address */
7102 dma_unmap_len_set(tx_buffer, len, size);
7103 dma_unmap_addr_set(tx_buffer, dma, dma);
7105 tx_desc->read.buffer_addr = cpu_to_le64(dma);
7107 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
7108 tx_desc->read.cmd_type_len =
7109 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
7113 if (i == tx_ring->count) {
7114 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
7117 tx_desc->read.olinfo_status = 0;
7119 dma += IXGBE_MAX_DATA_PER_TXD;
7120 size -= IXGBE_MAX_DATA_PER_TXD;
7122 tx_desc->read.buffer_addr = cpu_to_le64(dma);
7125 if (likely(!data_len))
7128 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
7132 if (i == tx_ring->count) {
7133 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
7136 tx_desc->read.olinfo_status = 0;
7139 size = min_t(unsigned int, data_len, skb_frag_size(frag));
7141 size = skb_frag_size(frag);
7145 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
7148 tx_buffer = &tx_ring->tx_buffer_info[i];
7151 /* write last descriptor with RS and EOP bits */
7152 cmd_type |= size | IXGBE_TXD_CMD;
7153 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
7155 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
7157 /* set the timestamp */
7158 first->time_stamp = jiffies;
7161 * Force memory writes to complete before letting h/w know there
7162 * are new descriptors to fetch. (Only applicable for weak-ordered
7163 * memory model archs, such as IA-64).
7165 * We also need this memory barrier to make certain all of the
7166 * status bits have been updated before next_to_watch is written.
7170 /* set next_to_watch value indicating a packet is present */
7171 first->next_to_watch = tx_desc;
7174 if (i == tx_ring->count)
7177 tx_ring->next_to_use = i;
7179 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
7181 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
7182 writel(i, tx_ring->tail);
7184 /* we need this if more than one processor can write to our tail
7185 * at a time, it synchronizes IO on IA64/Altix systems
7192 dev_err(tx_ring->dev, "TX DMA map failed\n");
7194 /* clear dma mappings for failed tx_buffer_info map */
7196 tx_buffer = &tx_ring->tx_buffer_info[i];
7197 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
7198 if (tx_buffer == first)
7205 tx_ring->next_to_use = i;
7208 static void ixgbe_atr(struct ixgbe_ring *ring,
7209 struct ixgbe_tx_buffer *first)
7211 struct ixgbe_q_vector *q_vector = ring->q_vector;
7212 union ixgbe_atr_hash_dword input = { .dword = 0 };
7213 union ixgbe_atr_hash_dword common = { .dword = 0 };
7215 unsigned char *network;
7217 struct ipv6hdr *ipv6;
7222 /* if ring doesn't have a interrupt vector, cannot perform ATR */
7226 /* do nothing if sampling is disabled */
7227 if (!ring->atr_sample_rate)
7232 /* snag network header to get L4 type and address */
7233 hdr.network = skb_network_header(first->skb);
7235 /* Currently only IPv4/IPv6 with TCP is supported */
7236 if ((first->protocol != htons(ETH_P_IPV6) ||
7237 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
7238 (first->protocol != htons(ETH_P_IP) ||
7239 hdr.ipv4->protocol != IPPROTO_TCP))
7242 th = tcp_hdr(first->skb);
7244 /* skip this packet since it is invalid or the socket is closing */
7248 /* sample on all syn packets or once every atr sample count */
7249 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
7252 /* reset sample count */
7253 ring->atr_count = 0;
7255 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
7258 * src and dst are inverted, think how the receiver sees them
7260 * The input is broken into two sections, a non-compressed section
7261 * containing vm_pool, vlan_id, and flow_type. The rest of the data
7262 * is XORed together and stored in the compressed dword.
7264 input.formatted.vlan_id = vlan_id;
7267 * since src port and flex bytes occupy the same word XOR them together
7268 * and write the value to source port portion of compressed dword
7270 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
7271 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
7273 common.port.src ^= th->dest ^ first->protocol;
7274 common.port.dst ^= th->source;
7276 if (first->protocol == htons(ETH_P_IP)) {
7277 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
7278 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
7280 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
7281 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
7282 hdr.ipv6->saddr.s6_addr32[1] ^
7283 hdr.ipv6->saddr.s6_addr32[2] ^
7284 hdr.ipv6->saddr.s6_addr32[3] ^
7285 hdr.ipv6->daddr.s6_addr32[0] ^
7286 hdr.ipv6->daddr.s6_addr32[1] ^
7287 hdr.ipv6->daddr.s6_addr32[2] ^
7288 hdr.ipv6->daddr.s6_addr32[3];
7291 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
7292 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
7293 input, common, ring->queue_index);
7296 static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
7297 void *accel_priv, select_queue_fallback_t fallback)
7299 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
7301 struct ixgbe_adapter *adapter;
7302 struct ixgbe_ring_feature *f;
7307 return skb->queue_mapping + fwd_adapter->tx_base_queue;
7312 * only execute the code below if protocol is FCoE
7313 * or FIP and we have FCoE enabled on the adapter
7315 switch (vlan_get_protocol(skb)) {
7316 case htons(ETH_P_FCOE):
7317 case htons(ETH_P_FIP):
7318 adapter = netdev_priv(dev);
7320 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7323 return fallback(dev, skb);
7326 f = &adapter->ring_feature[RING_F_FCOE];
7328 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
7331 while (txq >= f->indices)
7334 return txq + f->offset;
7336 return fallback(dev, skb);
7340 netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
7341 struct ixgbe_adapter *adapter,
7342 struct ixgbe_ring *tx_ring)
7344 struct ixgbe_tx_buffer *first;
7348 u16 count = TXD_USE_COUNT(skb_headlen(skb));
7349 __be16 protocol = skb->protocol;
7353 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
7354 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
7355 * + 2 desc gap to keep tail from touching head,
7356 * + 1 desc for context descriptor,
7357 * otherwise try next time
7359 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
7360 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
7362 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
7363 tx_ring->tx_stats.tx_busy++;
7364 return NETDEV_TX_BUSY;
7367 /* record the location of the first descriptor for this packet */
7368 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
7370 first->bytecount = skb->len;
7371 first->gso_segs = 1;
7373 /* if we have a HW VLAN tag being added default to the HW one */
7374 if (skb_vlan_tag_present(skb)) {
7375 tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
7376 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7377 /* else if it is a SW VLAN check the next protocol and store the tag */
7378 } else if (protocol == htons(ETH_P_8021Q)) {
7379 struct vlan_hdr *vhdr, _vhdr;
7380 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7384 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
7385 IXGBE_TX_FLAGS_VLAN_SHIFT;
7386 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
7388 protocol = vlan_get_protocol(skb);
7390 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
7391 adapter->ptp_clock &&
7392 !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
7394 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
7395 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
7397 /* schedule check for Tx timestamp */
7398 adapter->ptp_tx_skb = skb_get(skb);
7399 adapter->ptp_tx_start = jiffies;
7400 schedule_work(&adapter->ptp_tx_work);
7403 skb_tx_timestamp(skb);
7405 #ifdef CONFIG_PCI_IOV
7407 * Use the l2switch_enable flag - would be false if the DMA
7408 * Tx switch had been disabled.
7410 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7411 tx_flags |= IXGBE_TX_FLAGS_CC;
7414 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
7415 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
7416 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7417 (skb->priority != TC_PRIO_CONTROL))) {
7418 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
7419 tx_flags |= (skb->priority & 0x7) <<
7420 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
7421 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7422 struct vlan_ethhdr *vhdr;
7424 if (skb_cow_head(skb, 0))
7426 vhdr = (struct vlan_ethhdr *)skb->data;
7427 vhdr->h_vlan_TCI = htons(tx_flags >>
7428 IXGBE_TX_FLAGS_VLAN_SHIFT);
7430 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7434 /* record initial flags and protocol */
7435 first->tx_flags = tx_flags;
7436 first->protocol = protocol;
7439 /* setup tx offload for FCoE */
7440 if ((protocol == htons(ETH_P_FCOE)) &&
7441 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
7442 tso = ixgbe_fso(tx_ring, first, &hdr_len);
7449 #endif /* IXGBE_FCOE */
7450 tso = ixgbe_tso(tx_ring, first, &hdr_len);
7454 ixgbe_tx_csum(tx_ring, first);
7456 /* add the ATR filter if ATR is on */
7457 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
7458 ixgbe_atr(tx_ring, first);
7462 #endif /* IXGBE_FCOE */
7463 ixgbe_tx_map(tx_ring, first, hdr_len);
7465 return NETDEV_TX_OK;
7468 dev_kfree_skb_any(first->skb);
7471 return NETDEV_TX_OK;
7474 static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
7475 struct net_device *netdev,
7476 struct ixgbe_ring *ring)
7478 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7479 struct ixgbe_ring *tx_ring;
7482 * The minimum packet size for olinfo paylen is 17 so pad the skb
7483 * in order to meet this minimum size requirement.
7485 if (skb_put_padto(skb, 17))
7486 return NETDEV_TX_OK;
7488 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
7490 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7493 static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
7494 struct net_device *netdev)
7496 return __ixgbe_xmit_frame(skb, netdev, NULL);
7500 * ixgbe_set_mac - Change the Ethernet Address of the NIC
7501 * @netdev: network interface device structure
7502 * @p: pointer to an address structure
7504 * Returns 0 on success, negative on failure
7506 static int ixgbe_set_mac(struct net_device *netdev, void *p)
7508 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7509 struct ixgbe_hw *hw = &adapter->hw;
7510 struct sockaddr *addr = p;
7513 if (!is_valid_ether_addr(addr->sa_data))
7514 return -EADDRNOTAVAIL;
7516 ixgbe_del_mac_filter(adapter, hw->mac.addr, VMDQ_P(0));
7517 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
7518 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
7520 ret = ixgbe_add_mac_filter(adapter, hw->mac.addr, VMDQ_P(0));
7521 return ret > 0 ? 0 : ret;
7525 ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7527 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7528 struct ixgbe_hw *hw = &adapter->hw;
7532 if (prtad != hw->phy.mdio.prtad)
7534 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7540 static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7541 u16 addr, u16 value)
7543 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7544 struct ixgbe_hw *hw = &adapter->hw;
7546 if (prtad != hw->phy.mdio.prtad)
7548 return hw->phy.ops.write_reg(hw, addr, devad, value);
7551 static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7553 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7557 return ixgbe_ptp_set_ts_config(adapter, req);
7559 return ixgbe_ptp_get_ts_config(adapter, req);
7561 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7566 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
7568 * @netdev: network interface device structure
7570 * Returns non-zero on failure
7572 static int ixgbe_add_sanmac_netdev(struct net_device *dev)
7575 struct ixgbe_adapter *adapter = netdev_priv(dev);
7576 struct ixgbe_hw *hw = &adapter->hw;
7578 if (is_valid_ether_addr(hw->mac.san_addr)) {
7580 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
7583 /* update SAN MAC vmdq pool selection */
7584 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
7590 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
7592 * @netdev: network interface device structure
7594 * Returns non-zero on failure
7596 static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7599 struct ixgbe_adapter *adapter = netdev_priv(dev);
7600 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7602 if (is_valid_ether_addr(mac->san_addr)) {
7604 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7610 #ifdef CONFIG_NET_POLL_CONTROLLER
7612 * Polling 'interrupt' - used by things like netconsole to send skbs
7613 * without having to re-enable interrupts. It's not called while
7614 * the interrupt routine is executing.
7616 static void ixgbe_netpoll(struct net_device *netdev)
7618 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7621 /* if interface is down do nothing */
7622 if (test_bit(__IXGBE_DOWN, &adapter->state))
7625 /* loop through and schedule all active queues */
7626 for (i = 0; i < adapter->num_q_vectors; i++)
7627 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
7631 static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7632 struct rtnl_link_stats64 *stats)
7634 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7638 for (i = 0; i < adapter->num_rx_queues; i++) {
7639 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
7645 start = u64_stats_fetch_begin_irq(&ring->syncp);
7646 packets = ring->stats.packets;
7647 bytes = ring->stats.bytes;
7648 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
7649 stats->rx_packets += packets;
7650 stats->rx_bytes += bytes;
7654 for (i = 0; i < adapter->num_tx_queues; i++) {
7655 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7661 start = u64_stats_fetch_begin_irq(&ring->syncp);
7662 packets = ring->stats.packets;
7663 bytes = ring->stats.bytes;
7664 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
7665 stats->tx_packets += packets;
7666 stats->tx_bytes += bytes;
7670 /* following stats updated by ixgbe_watchdog_task() */
7671 stats->multicast = netdev->stats.multicast;
7672 stats->rx_errors = netdev->stats.rx_errors;
7673 stats->rx_length_errors = netdev->stats.rx_length_errors;
7674 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7675 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7679 #ifdef CONFIG_IXGBE_DCB
7681 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7682 * @adapter: pointer to ixgbe_adapter
7683 * @tc: number of traffic classes currently enabled
7685 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7686 * 802.1Q priority maps to a packet buffer that exists.
7688 static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7690 struct ixgbe_hw *hw = &adapter->hw;
7694 /* 82598 have a static priority to TC mapping that can not
7695 * be changed so no validation is needed.
7697 if (hw->mac.type == ixgbe_mac_82598EB)
7700 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7703 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7704 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7706 /* If up2tc is out of bounds default to zero */
7708 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7712 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7718 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
7719 * @adapter: Pointer to adapter struct
7721 * Populate the netdev user priority to tc map
7723 static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
7725 struct net_device *dev = adapter->netdev;
7726 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
7727 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
7730 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
7733 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
7734 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
7736 tc = ets->prio_tc[prio];
7738 netdev_set_prio_tc_map(dev, prio, tc);
7742 #endif /* CONFIG_IXGBE_DCB */
7744 * ixgbe_setup_tc - configure net_device for multiple traffic classes
7746 * @netdev: net device to configure
7747 * @tc: number of traffic classes to enable
7749 int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7751 struct ixgbe_adapter *adapter = netdev_priv(dev);
7752 struct ixgbe_hw *hw = &adapter->hw;
7755 /* Hardware supports up to 8 traffic classes */
7756 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
7757 (hw->mac.type == ixgbe_mac_82598EB &&
7758 tc < MAX_TRAFFIC_CLASS))
7761 pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
7762 if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
7765 /* Hardware has to reinitialize queues and interrupts to
7766 * match packet buffer alignment. Unfortunately, the
7767 * hardware is not flexible enough to do this dynamically.
7769 if (netif_running(dev))
7771 ixgbe_clear_interrupt_scheme(adapter);
7773 #ifdef CONFIG_IXGBE_DCB
7775 netdev_set_num_tc(dev, tc);
7776 ixgbe_set_prio_tc_map(adapter);
7778 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
7780 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
7781 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
7782 adapter->hw.fc.requested_mode = ixgbe_fc_none;
7785 netdev_reset_tc(dev);
7787 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7788 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
7790 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
7792 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7793 adapter->dcb_cfg.pfc_mode_enable = false;
7796 ixgbe_validate_rtr(adapter, tc);
7798 #endif /* CONFIG_IXGBE_DCB */
7799 ixgbe_init_interrupt_scheme(adapter);
7801 if (netif_running(dev))
7802 return ixgbe_open(dev);
7807 #ifdef CONFIG_PCI_IOV
7808 void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
7810 struct net_device *netdev = adapter->netdev;
7813 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
7818 void ixgbe_do_reset(struct net_device *netdev)
7820 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7822 if (netif_running(netdev))
7823 ixgbe_reinit_locked(adapter);
7825 ixgbe_reset(adapter);
7828 static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
7829 netdev_features_t features)
7831 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7833 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7834 if (!(features & NETIF_F_RXCSUM))
7835 features &= ~NETIF_F_LRO;
7837 /* Turn off LRO if not RSC capable */
7838 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
7839 features &= ~NETIF_F_LRO;
7844 static int ixgbe_set_features(struct net_device *netdev,
7845 netdev_features_t features)
7847 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7848 netdev_features_t changed = netdev->features ^ features;
7849 bool need_reset = false;
7851 /* Make sure RSC matches LRO, reset if change */
7852 if (!(features & NETIF_F_LRO)) {
7853 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
7855 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
7856 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
7857 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7858 if (adapter->rx_itr_setting == 1 ||
7859 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
7860 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
7862 } else if ((changed ^ features) & NETIF_F_LRO) {
7863 e_info(probe, "rx-usecs set too low, "
7869 * Check if Flow Director n-tuple support was enabled or disabled. If
7870 * the state changed, we need to reset.
7872 switch (features & NETIF_F_NTUPLE) {
7873 case NETIF_F_NTUPLE:
7874 /* turn off ATR, enable perfect filters and reset */
7875 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
7878 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7879 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7882 /* turn off perfect filters, enable ATR and reset */
7883 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
7886 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7888 /* We cannot enable ATR if SR-IOV is enabled */
7889 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7892 /* We cannot enable ATR if we have 2 or more traffic classes */
7893 if (netdev_get_num_tc(netdev) > 1)
7896 /* We cannot enable ATR if RSS is disabled */
7897 if (adapter->ring_feature[RING_F_RSS].limit <= 1)
7900 /* A sample rate of 0 indicates ATR disabled */
7901 if (!adapter->atr_sample_rate)
7904 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7908 if (features & NETIF_F_HW_VLAN_CTAG_RX)
7909 ixgbe_vlan_strip_enable(adapter);
7911 ixgbe_vlan_strip_disable(adapter);
7913 if (changed & NETIF_F_RXALL)
7916 netdev->features = features;
7918 ixgbe_do_reset(netdev);
7924 * ixgbe_add_vxlan_port - Get notifications about VXLAN ports that come up
7925 * @dev: The port's netdev
7926 * @sa_family: Socket Family that VXLAN is notifiying us about
7927 * @port: New UDP port number that VXLAN started listening to
7929 static void ixgbe_add_vxlan_port(struct net_device *dev, sa_family_t sa_family,
7932 struct ixgbe_adapter *adapter = netdev_priv(dev);
7933 struct ixgbe_hw *hw = &adapter->hw;
7934 u16 new_port = ntohs(port);
7936 if (sa_family == AF_INET6)
7939 if (adapter->vxlan_port == new_port) {
7940 netdev_info(dev, "Port %d already offloaded\n", new_port);
7944 if (adapter->vxlan_port) {
7946 "Hit Max num of UDP ports, not adding port %d\n",
7951 adapter->vxlan_port = new_port;
7952 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, new_port);
7956 * ixgbe_del_vxlan_port - Get notifications about VXLAN ports that go away
7957 * @dev: The port's netdev
7958 * @sa_family: Socket Family that VXLAN is notifying us about
7959 * @port: UDP port number that VXLAN stopped listening to
7961 static void ixgbe_del_vxlan_port(struct net_device *dev, sa_family_t sa_family,
7964 struct ixgbe_adapter *adapter = netdev_priv(dev);
7965 struct ixgbe_hw *hw = &adapter->hw;
7966 u16 new_port = ntohs(port);
7968 if (sa_family == AF_INET6)
7971 if (adapter->vxlan_port != new_port) {
7972 netdev_info(dev, "Port %d was not found, not deleting\n",
7977 adapter->vxlan_port = 0;
7978 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, 0);
7981 static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
7982 struct net_device *dev,
7983 const unsigned char *addr, u16 vid,
7986 /* guarantee we can provide a unique filter for the unicast address */
7987 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
7988 if (IXGBE_MAX_PF_MACVLANS <= netdev_uc_count(dev))
7992 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
7996 * ixgbe_configure_bridge_mode - set various bridge modes
7997 * @adapter - the private structure
7998 * @mode - requested bridge mode
8000 * Configure some settings require for various bridge modes.
8002 static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
8005 struct ixgbe_hw *hw = &adapter->hw;
8006 unsigned int p, num_pools;
8010 case BRIDGE_MODE_VEPA:
8011 /* disable Tx loopback, rely on switch hairpin mode */
8012 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
8014 /* must enable Rx switching replication to allow multicast
8015 * packet reception on all VFs, and to enable source address
8018 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
8019 vmdctl |= IXGBE_VT_CTL_REPLEN;
8020 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
8022 /* enable Rx source address pruning. Note, this requires
8023 * replication to be enabled or else it does nothing.
8025 num_pools = adapter->num_vfs + adapter->num_rx_pools;
8026 for (p = 0; p < num_pools; p++) {
8027 if (hw->mac.ops.set_source_address_pruning)
8028 hw->mac.ops.set_source_address_pruning(hw,
8033 case BRIDGE_MODE_VEB:
8034 /* enable Tx loopback for internal VF/PF communication */
8035 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
8036 IXGBE_PFDTXGSWC_VT_LBEN);
8038 /* disable Rx switching replication unless we have SR-IOV
8041 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
8042 if (!adapter->num_vfs)
8043 vmdctl &= ~IXGBE_VT_CTL_REPLEN;
8044 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
8046 /* disable Rx source address pruning, since we don't expect to
8047 * be receiving external loopback of our transmitted frames.
8049 num_pools = adapter->num_vfs + adapter->num_rx_pools;
8050 for (p = 0; p < num_pools; p++) {
8051 if (hw->mac.ops.set_source_address_pruning)
8052 hw->mac.ops.set_source_address_pruning(hw,
8061 adapter->bridge_mode = mode;
8063 e_info(drv, "enabling bridge mode: %s\n",
8064 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
8069 static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
8070 struct nlmsghdr *nlh, u16 flags)
8072 struct ixgbe_adapter *adapter = netdev_priv(dev);
8073 struct nlattr *attr, *br_spec;
8076 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
8079 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
8083 nla_for_each_nested(attr, br_spec, rem) {
8087 if (nla_type(attr) != IFLA_BRIDGE_MODE)
8090 if (nla_len(attr) < sizeof(mode))
8093 mode = nla_get_u16(attr);
8094 status = ixgbe_configure_bridge_mode(adapter, mode);
8104 static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
8105 struct net_device *dev,
8106 u32 filter_mask, int nlflags)
8108 struct ixgbe_adapter *adapter = netdev_priv(dev);
8110 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
8113 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
8114 adapter->bridge_mode, 0, 0, nlflags,
8118 static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
8120 struct ixgbe_fwd_adapter *fwd_adapter = NULL;
8121 struct ixgbe_adapter *adapter = netdev_priv(pdev);
8122 int used_pools = adapter->num_vfs + adapter->num_rx_pools;
8126 /* Hardware has a limited number of available pools. Each VF, and the
8127 * PF require a pool. Check to ensure we don't attempt to use more
8128 * then the available number of pools.
8130 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
8131 return ERR_PTR(-EINVAL);
8134 if (vdev->num_rx_queues != vdev->num_tx_queues) {
8135 netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
8137 return ERR_PTR(-EINVAL);
8140 /* Check for hardware restriction on number of rx/tx queues */
8141 if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
8142 vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
8144 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
8146 return ERR_PTR(-EINVAL);
8149 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
8150 adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
8151 (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
8152 return ERR_PTR(-EBUSY);
8154 fwd_adapter = kcalloc(1, sizeof(struct ixgbe_fwd_adapter), GFP_KERNEL);
8156 return ERR_PTR(-ENOMEM);
8158 pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
8159 adapter->num_rx_pools++;
8160 set_bit(pool, &adapter->fwd_bitmask);
8161 limit = find_last_bit(&adapter->fwd_bitmask, 32);
8163 /* Enable VMDq flag so device will be set in VM mode */
8164 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
8165 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
8166 adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
8168 /* Force reinit of ring allocation with VMDQ enabled */
8169 err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
8172 fwd_adapter->pool = pool;
8173 fwd_adapter->real_adapter = adapter;
8174 err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
8177 netif_tx_start_all_queues(vdev);
8180 /* unwind counter and free adapter struct */
8182 "%s: dfwd hardware acceleration failed\n", vdev->name);
8183 clear_bit(pool, &adapter->fwd_bitmask);
8184 adapter->num_rx_pools--;
8186 return ERR_PTR(err);
8189 static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
8191 struct ixgbe_fwd_adapter *fwd_adapter = priv;
8192 struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
8195 clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
8196 adapter->num_rx_pools--;
8198 limit = find_last_bit(&adapter->fwd_bitmask, 32);
8199 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
8200 ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
8201 ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
8202 netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
8203 fwd_adapter->pool, adapter->num_rx_pools,
8204 fwd_adapter->rx_base_queue,
8205 fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
8206 adapter->fwd_bitmask);
8210 static const struct net_device_ops ixgbe_netdev_ops = {
8211 .ndo_open = ixgbe_open,
8212 .ndo_stop = ixgbe_close,
8213 .ndo_start_xmit = ixgbe_xmit_frame,
8214 .ndo_select_queue = ixgbe_select_queue,
8215 .ndo_set_rx_mode = ixgbe_set_rx_mode,
8216 .ndo_validate_addr = eth_validate_addr,
8217 .ndo_set_mac_address = ixgbe_set_mac,
8218 .ndo_change_mtu = ixgbe_change_mtu,
8219 .ndo_tx_timeout = ixgbe_tx_timeout,
8220 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
8221 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
8222 .ndo_do_ioctl = ixgbe_ioctl,
8223 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
8224 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
8225 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
8226 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
8227 .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
8228 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
8229 .ndo_get_stats64 = ixgbe_get_stats64,
8230 #ifdef CONFIG_IXGBE_DCB
8231 .ndo_setup_tc = ixgbe_setup_tc,
8233 #ifdef CONFIG_NET_POLL_CONTROLLER
8234 .ndo_poll_controller = ixgbe_netpoll,
8236 #ifdef CONFIG_NET_RX_BUSY_POLL
8237 .ndo_busy_poll = ixgbe_low_latency_recv,
8240 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
8241 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
8242 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
8243 .ndo_fcoe_enable = ixgbe_fcoe_enable,
8244 .ndo_fcoe_disable = ixgbe_fcoe_disable,
8245 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
8246 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
8247 #endif /* IXGBE_FCOE */
8248 .ndo_set_features = ixgbe_set_features,
8249 .ndo_fix_features = ixgbe_fix_features,
8250 .ndo_fdb_add = ixgbe_ndo_fdb_add,
8251 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
8252 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
8253 .ndo_dfwd_add_station = ixgbe_fwd_add,
8254 .ndo_dfwd_del_station = ixgbe_fwd_del,
8255 .ndo_add_vxlan_port = ixgbe_add_vxlan_port,
8256 .ndo_del_vxlan_port = ixgbe_del_vxlan_port,
8260 * ixgbe_enumerate_functions - Get the number of ports this device has
8261 * @adapter: adapter structure
8263 * This function enumerates the phsyical functions co-located on a single slot,
8264 * in order to determine how many ports a device has. This is most useful in
8265 * determining the required GT/s of PCIe bandwidth necessary for optimal
8268 static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
8270 struct pci_dev *entry, *pdev = adapter->pdev;
8273 /* Some cards can not use the generic count PCIe functions method,
8274 * because they are behind a parent switch, so we hardcode these with
8275 * the correct number of functions.
8277 if (ixgbe_pcie_from_parent(&adapter->hw))
8280 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
8281 /* don't count virtual functions */
8282 if (entry->is_virtfn)
8285 /* When the devices on the bus don't all match our device ID,
8286 * we can't reliably determine the correct number of
8287 * functions. This can occur if a function has been direct
8288 * attached to a virtual machine using VT-d, for example. In
8289 * this case, simply return -1 to indicate this.
8291 if ((entry->vendor != pdev->vendor) ||
8292 (entry->device != pdev->device))
8302 * ixgbe_wol_supported - Check whether device supports WoL
8303 * @hw: hw specific details
8304 * @device_id: the device ID
8305 * @subdev_id: the subsystem device ID
8307 * This function is used by probe and ethtool to determine
8308 * which devices have WoL support
8311 int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
8314 struct ixgbe_hw *hw = &adapter->hw;
8315 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
8316 int is_wol_supported = 0;
8318 switch (device_id) {
8319 case IXGBE_DEV_ID_82599_SFP:
8320 /* Only these subdevices could supports WOL */
8321 switch (subdevice_id) {
8322 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
8323 case IXGBE_SUBDEV_ID_82599_560FLR:
8324 /* only support first port */
8325 if (hw->bus.func != 0)
8327 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
8328 case IXGBE_SUBDEV_ID_82599_SFP:
8329 case IXGBE_SUBDEV_ID_82599_RNDC:
8330 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
8331 case IXGBE_SUBDEV_ID_82599_LOM_SFP:
8332 is_wol_supported = 1;
8336 case IXGBE_DEV_ID_82599EN_SFP:
8337 /* Only this subdevice supports WOL */
8338 switch (subdevice_id) {
8339 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
8340 is_wol_supported = 1;
8344 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
8345 /* All except this subdevice support WOL */
8346 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
8347 is_wol_supported = 1;
8349 case IXGBE_DEV_ID_82599_KX4:
8350 is_wol_supported = 1;
8352 case IXGBE_DEV_ID_X540T:
8353 case IXGBE_DEV_ID_X540T1:
8354 case IXGBE_DEV_ID_X550T:
8355 case IXGBE_DEV_ID_X550EM_X_KX4:
8356 case IXGBE_DEV_ID_X550EM_X_KR:
8357 case IXGBE_DEV_ID_X550EM_X_10G_T:
8358 /* check eeprom to see if enabled wol */
8359 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
8360 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
8361 (hw->bus.func == 0))) {
8362 is_wol_supported = 1;
8367 return is_wol_supported;
8371 * ixgbe_get_platform_mac_addr - Look up MAC address in Open Firmware / IDPROM
8372 * @adapter: Pointer to adapter struct
8374 static void ixgbe_get_platform_mac_addr(struct ixgbe_adapter *adapter)
8377 struct device_node *dp = pci_device_to_OF_node(adapter->pdev);
8378 struct ixgbe_hw *hw = &adapter->hw;
8379 const unsigned char *addr;
8381 addr = of_get_mac_address(dp);
8383 ether_addr_copy(hw->mac.perm_addr, addr);
8386 #endif /* CONFIG_OF */
8389 ether_addr_copy(hw->mac.perm_addr, idprom->id_ethaddr);
8390 #endif /* CONFIG_SPARC */
8394 * ixgbe_probe - Device Initialization Routine
8395 * @pdev: PCI device information struct
8396 * @ent: entry in ixgbe_pci_tbl
8398 * Returns 0 on success, negative on failure
8400 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
8401 * The OS initialization, configuring of the adapter private structure,
8402 * and a hardware reset occur.
8404 static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
8406 struct net_device *netdev;
8407 struct ixgbe_adapter *adapter = NULL;
8408 struct ixgbe_hw *hw;
8409 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
8410 int i, err, pci_using_dac, expected_gts;
8411 unsigned int indices = MAX_TX_QUEUES;
8412 u8 part_str[IXGBE_PBANUM_LENGTH];
8413 bool disable_dev = false;
8419 /* Catch broken hardware that put the wrong VF device ID in
8420 * the PCIe SR-IOV capability.
8422 if (pdev->is_virtfn) {
8423 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
8424 pci_name(pdev), pdev->vendor, pdev->device);
8428 err = pci_enable_device_mem(pdev);
8432 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
8435 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
8438 "No usable DMA configuration, aborting\n");
8444 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
8445 IORESOURCE_MEM), ixgbe_driver_name);
8448 "pci_request_selected_regions failed 0x%x\n", err);
8452 pci_enable_pcie_error_reporting(pdev);
8454 pci_set_master(pdev);
8455 pci_save_state(pdev);
8457 if (ii->mac == ixgbe_mac_82598EB) {
8458 #ifdef CONFIG_IXGBE_DCB
8459 /* 8 TC w/ 4 queues per TC */
8460 indices = 4 * MAX_TRAFFIC_CLASS;
8462 indices = IXGBE_MAX_RSS_INDICES;
8466 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
8469 goto err_alloc_etherdev;
8472 SET_NETDEV_DEV(netdev, &pdev->dev);
8474 adapter = netdev_priv(netdev);
8476 adapter->netdev = netdev;
8477 adapter->pdev = pdev;
8480 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
8482 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
8483 pci_resource_len(pdev, 0));
8484 adapter->io_addr = hw->hw_addr;
8490 netdev->netdev_ops = &ixgbe_netdev_ops;
8491 ixgbe_set_ethtool_ops(netdev);
8492 netdev->watchdog_timeo = 5 * HZ;
8493 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
8496 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
8497 hw->mac.type = ii->mac;
8498 hw->mvals = ii->mvals;
8501 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
8502 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
8503 if (ixgbe_removed(hw->hw_addr)) {
8507 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
8508 if (!(eec & (1 << 8)))
8509 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
8512 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
8513 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
8514 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
8515 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
8516 hw->phy.mdio.mmds = 0;
8517 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
8518 hw->phy.mdio.dev = netdev;
8519 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
8520 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
8522 ii->get_invariants(hw);
8524 /* setup the private structure */
8525 err = ixgbe_sw_init(adapter);
8529 /* Make it possible the adapter to be woken up via WOL */
8530 switch (adapter->hw.mac.type) {
8531 case ixgbe_mac_82599EB:
8532 case ixgbe_mac_X540:
8533 case ixgbe_mac_X550:
8534 case ixgbe_mac_X550EM_x:
8535 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
8542 * If there is a fan on this device and it has failed log the
8545 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
8546 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
8547 if (esdp & IXGBE_ESDP_SDP1)
8548 e_crit(probe, "Fan has stopped, replace the adapter\n");
8551 if (allow_unsupported_sfp)
8552 hw->allow_unsupported_sfp = allow_unsupported_sfp;
8554 /* reset_hw fills in the perm_addr as well */
8555 hw->phy.reset_if_overtemp = true;
8556 err = hw->mac.ops.reset_hw(hw);
8557 hw->phy.reset_if_overtemp = false;
8558 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
8559 hw->mac.type == ixgbe_mac_82598EB) {
8561 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
8562 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
8563 e_dev_err("Reload the driver after installing a supported module.\n");
8566 e_dev_err("HW Init failed: %d\n", err);
8570 #ifdef CONFIG_PCI_IOV
8571 /* SR-IOV not supported on the 82598 */
8572 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8575 ixgbe_init_mbx_params_pf(hw);
8576 memcpy(&hw->mbx.ops, ii->mbx_ops, sizeof(hw->mbx.ops));
8577 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
8578 ixgbe_enable_sriov(adapter);
8582 netdev->features = NETIF_F_SG |
8585 NETIF_F_HW_VLAN_CTAG_TX |
8586 NETIF_F_HW_VLAN_CTAG_RX |
8592 netdev->hw_features = netdev->features | NETIF_F_HW_L2FW_DOFFLOAD;
8594 switch (adapter->hw.mac.type) {
8595 case ixgbe_mac_82599EB:
8596 case ixgbe_mac_X540:
8597 case ixgbe_mac_X550:
8598 case ixgbe_mac_X550EM_x:
8599 netdev->features |= NETIF_F_SCTP_CSUM;
8600 netdev->hw_features |= NETIF_F_SCTP_CSUM |
8607 netdev->hw_features |= NETIF_F_RXALL;
8608 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
8610 netdev->vlan_features |= NETIF_F_TSO;
8611 netdev->vlan_features |= NETIF_F_TSO6;
8612 netdev->vlan_features |= NETIF_F_IP_CSUM;
8613 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
8614 netdev->vlan_features |= NETIF_F_SG;
8616 netdev->priv_flags |= IFF_UNICAST_FLT;
8617 netdev->priv_flags |= IFF_SUPP_NOFCS;
8619 switch (adapter->hw.mac.type) {
8620 case ixgbe_mac_X550:
8621 case ixgbe_mac_X550EM_x:
8622 netdev->hw_enc_features |= NETIF_F_RXCSUM;
8628 #ifdef CONFIG_IXGBE_DCB
8629 netdev->dcbnl_ops = &dcbnl_ops;
8633 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
8634 unsigned int fcoe_l;
8636 if (hw->mac.ops.get_device_caps) {
8637 hw->mac.ops.get_device_caps(hw, &device_caps);
8638 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
8639 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
8643 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
8644 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
8646 netdev->features |= NETIF_F_FSO |
8649 netdev->vlan_features |= NETIF_F_FSO |
8653 #endif /* IXGBE_FCOE */
8654 if (pci_using_dac) {
8655 netdev->features |= NETIF_F_HIGHDMA;
8656 netdev->vlan_features |= NETIF_F_HIGHDMA;
8659 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
8660 netdev->hw_features |= NETIF_F_LRO;
8661 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
8662 netdev->features |= NETIF_F_LRO;
8664 /* make sure the EEPROM is good */
8665 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
8666 e_dev_err("The EEPROM Checksum Is Not Valid\n");
8671 ixgbe_get_platform_mac_addr(adapter);
8673 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
8675 if (!is_valid_ether_addr(netdev->dev_addr)) {
8676 e_dev_err("invalid MAC address\n");
8681 ixgbe_mac_set_default_filter(adapter, hw->mac.perm_addr);
8683 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
8684 (unsigned long) adapter);
8686 if (ixgbe_removed(hw->hw_addr)) {
8690 INIT_WORK(&adapter->service_task, ixgbe_service_task);
8691 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
8692 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
8694 err = ixgbe_init_interrupt_scheme(adapter);
8698 /* WOL not supported for all devices */
8700 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
8701 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
8702 pdev->subsystem_device);
8703 if (hw->wol_enabled)
8704 adapter->wol = IXGBE_WUFC_MAG;
8706 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
8708 /* save off EEPROM version number */
8709 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
8710 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
8712 /* pick up the PCI bus settings for reporting later */
8713 hw->mac.ops.get_bus_info(hw);
8714 if (ixgbe_pcie_from_parent(hw))
8715 ixgbe_get_parent_bus_info(adapter);
8717 /* calculate the expected PCIe bandwidth required for optimal
8718 * performance. Note that some older parts will never have enough
8719 * bandwidth due to being older generation PCIe parts. We clamp these
8720 * parts to ensure no warning is displayed if it can't be fixed.
8722 switch (hw->mac.type) {
8723 case ixgbe_mac_82598EB:
8724 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
8727 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
8731 /* don't check link if we failed to enumerate functions */
8732 if (expected_gts > 0)
8733 ixgbe_check_minimum_link(adapter, expected_gts);
8735 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
8737 strlcpy(part_str, "Unknown", sizeof(part_str));
8738 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
8739 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
8740 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
8743 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
8744 hw->mac.type, hw->phy.type, part_str);
8746 e_dev_info("%pM\n", netdev->dev_addr);
8748 /* reset the hardware with the new settings */
8749 err = hw->mac.ops.start_hw(hw);
8750 if (err == IXGBE_ERR_EEPROM_VERSION) {
8751 /* We are running on a pre-production device, log a warning */
8752 e_dev_warn("This device is a pre-production adapter/LOM. "
8753 "Please be aware there may be issues associated "
8754 "with your hardware. If you are experiencing "
8755 "problems please contact your Intel or hardware "
8756 "representative who provided you with this "
8759 strcpy(netdev->name, "eth%d");
8760 err = register_netdev(netdev);
8764 pci_set_drvdata(pdev, adapter);
8766 /* power down the optics for 82599 SFP+ fiber */
8767 if (hw->mac.ops.disable_tx_laser)
8768 hw->mac.ops.disable_tx_laser(hw);
8770 /* carrier off reporting is important to ethtool even BEFORE open */
8771 netif_carrier_off(netdev);
8773 #ifdef CONFIG_IXGBE_DCA
8774 if (dca_add_requester(&pdev->dev) == 0) {
8775 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
8776 ixgbe_setup_dca(adapter);
8779 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
8780 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
8781 for (i = 0; i < adapter->num_vfs; i++)
8782 ixgbe_vf_configuration(pdev, (i | 0x10000000));
8785 /* firmware requires driver version to be 0xFFFFFFFF
8786 * since os does not support feature
8788 if (hw->mac.ops.set_fw_drv_ver)
8789 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
8792 /* add san mac addr to netdev */
8793 ixgbe_add_sanmac_netdev(netdev);
8795 e_dev_info("%s\n", ixgbe_default_device_descr);
8797 #ifdef CONFIG_IXGBE_HWMON
8798 if (ixgbe_sysfs_init(adapter))
8799 e_err(probe, "failed to allocate sysfs resources\n");
8800 #endif /* CONFIG_IXGBE_HWMON */
8802 ixgbe_dbg_adapter_init(adapter);
8804 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
8805 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
8806 hw->mac.ops.setup_link(hw,
8807 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
8813 ixgbe_release_hw_control(adapter);
8814 ixgbe_clear_interrupt_scheme(adapter);
8816 ixgbe_disable_sriov(adapter);
8817 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
8818 iounmap(adapter->io_addr);
8819 kfree(adapter->mac_table);
8821 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
8822 free_netdev(netdev);
8824 pci_release_selected_regions(pdev,
8825 pci_select_bars(pdev, IORESOURCE_MEM));
8828 if (!adapter || disable_dev)
8829 pci_disable_device(pdev);
8834 * ixgbe_remove - Device Removal Routine
8835 * @pdev: PCI device information struct
8837 * ixgbe_remove is called by the PCI subsystem to alert the driver
8838 * that it should release a PCI device. The could be caused by a
8839 * Hot-Plug event, or because the driver is going to be removed from
8842 static void ixgbe_remove(struct pci_dev *pdev)
8844 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8845 struct net_device *netdev;
8848 /* if !adapter then we already cleaned up in probe */
8852 netdev = adapter->netdev;
8853 ixgbe_dbg_adapter_exit(adapter);
8855 set_bit(__IXGBE_REMOVING, &adapter->state);
8856 cancel_work_sync(&adapter->service_task);
8859 #ifdef CONFIG_IXGBE_DCA
8860 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
8861 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
8862 dca_remove_requester(&pdev->dev);
8863 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
8867 #ifdef CONFIG_IXGBE_HWMON
8868 ixgbe_sysfs_exit(adapter);
8869 #endif /* CONFIG_IXGBE_HWMON */
8871 /* remove the added san mac */
8872 ixgbe_del_sanmac_netdev(netdev);
8874 if (netdev->reg_state == NETREG_REGISTERED)
8875 unregister_netdev(netdev);
8877 #ifdef CONFIG_PCI_IOV
8879 * Only disable SR-IOV on unload if the user specified the now
8880 * deprecated max_vfs module parameter.
8883 ixgbe_disable_sriov(adapter);
8885 ixgbe_clear_interrupt_scheme(adapter);
8887 ixgbe_release_hw_control(adapter);
8890 kfree(adapter->ixgbe_ieee_pfc);
8891 kfree(adapter->ixgbe_ieee_ets);
8894 iounmap(adapter->io_addr);
8895 pci_release_selected_regions(pdev, pci_select_bars(pdev,
8898 e_dev_info("complete\n");
8900 kfree(adapter->mac_table);
8901 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
8902 free_netdev(netdev);
8904 pci_disable_pcie_error_reporting(pdev);
8907 pci_disable_device(pdev);
8911 * ixgbe_io_error_detected - called when PCI error is detected
8912 * @pdev: Pointer to PCI device
8913 * @state: The current pci connection state
8915 * This function is called after a PCI bus error affecting
8916 * this device has been detected.
8918 static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
8919 pci_channel_state_t state)
8921 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8922 struct net_device *netdev = adapter->netdev;
8924 #ifdef CONFIG_PCI_IOV
8925 struct ixgbe_hw *hw = &adapter->hw;
8926 struct pci_dev *bdev, *vfdev;
8927 u32 dw0, dw1, dw2, dw3;
8929 u16 req_id, pf_func;
8931 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
8932 adapter->num_vfs == 0)
8933 goto skip_bad_vf_detection;
8935 bdev = pdev->bus->self;
8936 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
8937 bdev = bdev->bus->self;
8940 goto skip_bad_vf_detection;
8942 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
8944 goto skip_bad_vf_detection;
8946 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
8947 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
8948 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
8949 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
8950 if (ixgbe_removed(hw->hw_addr))
8951 goto skip_bad_vf_detection;
8954 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
8955 if (!(req_id & 0x0080))
8956 goto skip_bad_vf_detection;
8958 pf_func = req_id & 0x01;
8959 if ((pf_func & 1) == (pdev->devfn & 1)) {
8960 unsigned int device_id;
8962 vf = (req_id & 0x7F) >> 1;
8963 e_dev_err("VF %d has caused a PCIe error\n", vf);
8964 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
8965 "%8.8x\tdw3: %8.8x\n",
8966 dw0, dw1, dw2, dw3);
8967 switch (adapter->hw.mac.type) {
8968 case ixgbe_mac_82599EB:
8969 device_id = IXGBE_82599_VF_DEVICE_ID;
8971 case ixgbe_mac_X540:
8972 device_id = IXGBE_X540_VF_DEVICE_ID;
8974 case ixgbe_mac_X550:
8975 device_id = IXGBE_DEV_ID_X550_VF;
8977 case ixgbe_mac_X550EM_x:
8978 device_id = IXGBE_DEV_ID_X550EM_X_VF;
8985 /* Find the pci device of the offending VF */
8986 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
8988 if (vfdev->devfn == (req_id & 0xFF))
8990 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
8994 * There's a slim chance the VF could have been hot plugged,
8995 * so if it is no longer present we don't need to issue the
8996 * VFLR. Just clean up the AER in that case.
8999 ixgbe_issue_vf_flr(adapter, vfdev);
9000 /* Free device reference count */
9004 pci_cleanup_aer_uncorrect_error_status(pdev);
9008 * Even though the error may have occurred on the other port
9009 * we still need to increment the vf error reference count for
9010 * both ports because the I/O resume function will be called
9013 adapter->vferr_refcount++;
9015 return PCI_ERS_RESULT_RECOVERED;
9017 skip_bad_vf_detection:
9018 #endif /* CONFIG_PCI_IOV */
9019 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
9020 return PCI_ERS_RESULT_DISCONNECT;
9023 netif_device_detach(netdev);
9025 if (state == pci_channel_io_perm_failure) {
9027 return PCI_ERS_RESULT_DISCONNECT;
9030 if (netif_running(netdev))
9031 ixgbe_down(adapter);
9033 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
9034 pci_disable_device(pdev);
9037 /* Request a slot reset. */
9038 return PCI_ERS_RESULT_NEED_RESET;
9042 * ixgbe_io_slot_reset - called after the pci bus has been reset.
9043 * @pdev: Pointer to PCI device
9045 * Restart the card from scratch, as if from a cold-boot.
9047 static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
9049 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
9050 pci_ers_result_t result;
9053 if (pci_enable_device_mem(pdev)) {
9054 e_err(probe, "Cannot re-enable PCI device after reset.\n");
9055 result = PCI_ERS_RESULT_DISCONNECT;
9057 smp_mb__before_atomic();
9058 clear_bit(__IXGBE_DISABLED, &adapter->state);
9059 adapter->hw.hw_addr = adapter->io_addr;
9060 pci_set_master(pdev);
9061 pci_restore_state(pdev);
9062 pci_save_state(pdev);
9064 pci_wake_from_d3(pdev, false);
9066 ixgbe_reset(adapter);
9067 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
9068 result = PCI_ERS_RESULT_RECOVERED;
9071 err = pci_cleanup_aer_uncorrect_error_status(pdev);
9073 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
9074 "failed 0x%0x\n", err);
9075 /* non-fatal, continue */
9082 * ixgbe_io_resume - called when traffic can start flowing again.
9083 * @pdev: Pointer to PCI device
9085 * This callback is called when the error recovery driver tells us that
9086 * its OK to resume normal operation.
9088 static void ixgbe_io_resume(struct pci_dev *pdev)
9090 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
9091 struct net_device *netdev = adapter->netdev;
9093 #ifdef CONFIG_PCI_IOV
9094 if (adapter->vferr_refcount) {
9095 e_info(drv, "Resuming after VF err\n");
9096 adapter->vferr_refcount--;
9101 if (netif_running(netdev))
9104 netif_device_attach(netdev);
9107 static const struct pci_error_handlers ixgbe_err_handler = {
9108 .error_detected = ixgbe_io_error_detected,
9109 .slot_reset = ixgbe_io_slot_reset,
9110 .resume = ixgbe_io_resume,
9113 static struct pci_driver ixgbe_driver = {
9114 .name = ixgbe_driver_name,
9115 .id_table = ixgbe_pci_tbl,
9116 .probe = ixgbe_probe,
9117 .remove = ixgbe_remove,
9119 .suspend = ixgbe_suspend,
9120 .resume = ixgbe_resume,
9122 .shutdown = ixgbe_shutdown,
9123 .sriov_configure = ixgbe_pci_sriov_configure,
9124 .err_handler = &ixgbe_err_handler
9128 * ixgbe_init_module - Driver Registration Routine
9130 * ixgbe_init_module is the first routine called when the driver is
9131 * loaded. All it does is register with the PCI subsystem.
9133 static int __init ixgbe_init_module(void)
9136 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
9137 pr_info("%s\n", ixgbe_copyright);
9141 ret = pci_register_driver(&ixgbe_driver);
9147 #ifdef CONFIG_IXGBE_DCA
9148 dca_register_notify(&dca_notifier);
9154 module_init(ixgbe_init_module);
9157 * ixgbe_exit_module - Driver Exit Cleanup Routine
9159 * ixgbe_exit_module is called just before the driver is removed
9162 static void __exit ixgbe_exit_module(void)
9164 #ifdef CONFIG_IXGBE_DCA
9165 dca_unregister_notify(&dca_notifier);
9167 pci_unregister_driver(&ixgbe_driver);
9172 #ifdef CONFIG_IXGBE_DCA
9173 static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
9178 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
9179 __ixgbe_notify_dca);
9181 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
9184 #endif /* CONFIG_IXGBE_DCA */
9186 module_exit(ixgbe_exit_module);