1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 1999 - 2018 Intel Corporation. */
4 #include <linux/types.h>
5 #include <linux/module.h>
7 #include <linux/netdevice.h>
8 #include <linux/vmalloc.h>
9 #include <linux/string.h>
11 #include <linux/interrupt.h>
13 #include <linux/tcp.h>
14 #include <linux/sctp.h>
15 #include <linux/pkt_sched.h>
16 #include <linux/ipv6.h>
17 #include <linux/slab.h>
18 #include <net/checksum.h>
19 #include <net/ip6_checksum.h>
20 #include <linux/etherdevice.h>
21 #include <linux/ethtool.h>
23 #include <linux/if_vlan.h>
24 #include <linux/if_macvlan.h>
25 #include <linux/if_bridge.h>
26 #include <linux/prefetch.h>
27 #include <linux/bpf.h>
28 #include <linux/bpf_trace.h>
29 #include <linux/atomic.h>
30 #include <scsi/fc/fc_fcoe.h>
31 #include <net/udp_tunnel.h>
32 #include <net/pkt_cls.h>
33 #include <net/tc_act/tc_gact.h>
34 #include <net/tc_act/tc_mirred.h>
35 #include <net/vxlan.h>
40 #include "ixgbe_common.h"
41 #include "ixgbe_dcb_82599.h"
42 #include "ixgbe_sriov.h"
43 #include "ixgbe_model.h"
45 char ixgbe_driver_name[] = "ixgbe";
46 static const char ixgbe_driver_string[] =
47 "Intel(R) 10 Gigabit PCI Express Network Driver";
49 char ixgbe_default_device_descr[] =
50 "Intel(R) 10 Gigabit Network Connection";
52 static char ixgbe_default_device_descr[] =
53 "Intel(R) 10 Gigabit Network Connection";
55 #define DRV_VERSION "5.1.0-k"
56 const char ixgbe_driver_version[] = DRV_VERSION;
57 static const char ixgbe_copyright[] =
58 "Copyright (c) 1999-2016 Intel Corporation.";
60 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";
62 static const struct ixgbe_info *ixgbe_info_tbl[] = {
63 [board_82598] = &ixgbe_82598_info,
64 [board_82599] = &ixgbe_82599_info,
65 [board_X540] = &ixgbe_X540_info,
66 [board_X550] = &ixgbe_X550_info,
67 [board_X550EM_x] = &ixgbe_X550EM_x_info,
68 [board_x550em_x_fw] = &ixgbe_x550em_x_fw_info,
69 [board_x550em_a] = &ixgbe_x550em_a_info,
70 [board_x550em_a_fw] = &ixgbe_x550em_a_fw_info,
73 /* ixgbe_pci_tbl - PCI Device ID Table
75 * Wildcard entries (PCI_ANY_ID) should come last
76 * Last entry must be all 0s
78 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
79 * Class, Class Mask, private data (not used) }
81 static const struct pci_device_id ixgbe_pci_tbl[] = {
82 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
83 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
84 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
85 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
86 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
87 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550},
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550},
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x},
115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_XFI), board_X550EM_x},
116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x},
117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x},
118 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x},
119 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_1G_T), board_x550em_x_fw},
120 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a },
121 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR_L), board_x550em_a },
122 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP_N), board_x550em_a },
123 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a },
124 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII_L), board_x550em_a },
125 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_10G_T), board_x550em_a},
126 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a },
127 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T), board_x550em_a_fw },
128 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T_L), board_x550em_a_fw },
129 /* required last entry */
132 MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
134 #ifdef CONFIG_IXGBE_DCA
135 static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
137 static struct notifier_block dca_notifier = {
138 .notifier_call = ixgbe_notify_dca,
144 #ifdef CONFIG_PCI_IOV
145 static unsigned int max_vfs;
146 module_param(max_vfs, uint, 0);
147 MODULE_PARM_DESC(max_vfs,
148 "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63. (Deprecated)");
149 #endif /* CONFIG_PCI_IOV */
151 static unsigned int allow_unsupported_sfp;
152 module_param(allow_unsupported_sfp, uint, 0);
153 MODULE_PARM_DESC(allow_unsupported_sfp,
154 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
156 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
157 static int debug = -1;
158 module_param(debug, int, 0);
159 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
161 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
162 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
163 MODULE_LICENSE("GPL");
164 MODULE_VERSION(DRV_VERSION);
166 static struct workqueue_struct *ixgbe_wq;
168 static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
169 static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *);
171 static const struct net_device_ops ixgbe_netdev_ops;
173 static bool netif_is_ixgbe(struct net_device *dev)
175 return dev && (dev->netdev_ops == &ixgbe_netdev_ops);
178 static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
181 struct pci_dev *parent_dev;
182 struct pci_bus *parent_bus;
184 parent_bus = adapter->pdev->bus->parent;
188 parent_dev = parent_bus->self;
192 if (!pci_is_pcie(parent_dev))
195 pcie_capability_read_word(parent_dev, reg, value);
196 if (*value == IXGBE_FAILED_READ_CFG_WORD &&
197 ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
202 static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
204 struct ixgbe_hw *hw = &adapter->hw;
208 hw->bus.type = ixgbe_bus_type_pci_express;
210 /* Get the negotiated link width and speed from PCI config space of the
211 * parent, as this device is behind a switch
213 err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
215 /* assume caller will handle error case */
219 hw->bus.width = ixgbe_convert_bus_width(link_status);
220 hw->bus.speed = ixgbe_convert_bus_speed(link_status);
226 * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
227 * @hw: hw specific details
229 * This function is used by probe to determine whether a device's PCI-Express
230 * bandwidth details should be gathered from the parent bus instead of from the
231 * device. Used to ensure that various locations all have the correct device ID
234 static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
236 switch (hw->device_id) {
237 case IXGBE_DEV_ID_82599_SFP_SF_QP:
238 case IXGBE_DEV_ID_82599_QSFP_SF_QP:
245 static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
248 struct ixgbe_hw *hw = &adapter->hw;
249 struct pci_dev *pdev;
251 /* Some devices are not connected over PCIe and thus do not negotiate
252 * speed. These devices do not have valid bus info, and thus any report
253 * we generate may not be correct.
255 if (hw->bus.type == ixgbe_bus_type_internal)
258 /* determine whether to use the parent device */
259 if (ixgbe_pcie_from_parent(&adapter->hw))
260 pdev = adapter->pdev->bus->parent->self;
262 pdev = adapter->pdev;
264 pcie_print_link_status(pdev);
267 static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
269 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
270 !test_bit(__IXGBE_REMOVING, &adapter->state) &&
271 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
272 queue_work(ixgbe_wq, &adapter->service_task);
275 static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
277 struct ixgbe_adapter *adapter = hw->back;
282 e_dev_err("Adapter removed\n");
283 if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
284 ixgbe_service_event_schedule(adapter);
287 static u32 ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
289 u8 __iomem *reg_addr;
293 reg_addr = READ_ONCE(hw->hw_addr);
294 if (ixgbe_removed(reg_addr))
295 return IXGBE_FAILED_READ_REG;
297 /* Register read of 0xFFFFFFF can indicate the adapter has been removed,
298 * so perform several status register reads to determine if the adapter
301 for (i = 0; i < IXGBE_FAILED_READ_RETRIES; i++) {
302 value = readl(reg_addr + IXGBE_STATUS);
303 if (value != IXGBE_FAILED_READ_REG)
308 if (value == IXGBE_FAILED_READ_REG)
309 ixgbe_remove_adapter(hw);
311 value = readl(reg_addr + reg);
316 * ixgbe_read_reg - Read from device register
317 * @hw: hw specific details
318 * @reg: offset of register to read
320 * Returns : value read or IXGBE_FAILED_READ_REG if removed
322 * This function is used to read device registers. It checks for device
323 * removal by confirming any read that returns all ones by checking the
324 * status register value for all ones. This function avoids reading from
325 * the hardware if a removal was previously detected in which case it
326 * returns IXGBE_FAILED_READ_REG (all ones).
328 u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
330 u8 __iomem *reg_addr = READ_ONCE(hw->hw_addr);
333 if (ixgbe_removed(reg_addr))
334 return IXGBE_FAILED_READ_REG;
335 if (unlikely(hw->phy.nw_mng_if_sel &
336 IXGBE_NW_MNG_IF_SEL_SGMII_ENABLE)) {
337 struct ixgbe_adapter *adapter;
340 for (i = 0; i < 200; ++i) {
341 value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY);
343 goto writes_completed;
344 if (value == IXGBE_FAILED_READ_REG) {
345 ixgbe_remove_adapter(hw);
346 return IXGBE_FAILED_READ_REG;
352 e_warn(hw, "register writes incomplete %08x\n", value);
356 value = readl(reg_addr + reg);
357 if (unlikely(value == IXGBE_FAILED_READ_REG))
358 value = ixgbe_check_remove(hw, reg);
362 static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
366 pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
367 if (value == IXGBE_FAILED_READ_CFG_WORD) {
368 ixgbe_remove_adapter(hw);
374 u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
376 struct ixgbe_adapter *adapter = hw->back;
379 if (ixgbe_removed(hw->hw_addr))
380 return IXGBE_FAILED_READ_CFG_WORD;
381 pci_read_config_word(adapter->pdev, reg, &value);
382 if (value == IXGBE_FAILED_READ_CFG_WORD &&
383 ixgbe_check_cfg_remove(hw, adapter->pdev))
384 return IXGBE_FAILED_READ_CFG_WORD;
388 #ifdef CONFIG_PCI_IOV
389 static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
391 struct ixgbe_adapter *adapter = hw->back;
394 if (ixgbe_removed(hw->hw_addr))
395 return IXGBE_FAILED_READ_CFG_DWORD;
396 pci_read_config_dword(adapter->pdev, reg, &value);
397 if (value == IXGBE_FAILED_READ_CFG_DWORD &&
398 ixgbe_check_cfg_remove(hw, adapter->pdev))
399 return IXGBE_FAILED_READ_CFG_DWORD;
402 #endif /* CONFIG_PCI_IOV */
404 void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
406 struct ixgbe_adapter *adapter = hw->back;
408 if (ixgbe_removed(hw->hw_addr))
410 pci_write_config_word(adapter->pdev, reg, value);
413 static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
415 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
417 /* flush memory to make sure state is correct before next watchdog */
418 smp_mb__before_atomic();
419 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
422 struct ixgbe_reg_info {
427 static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
429 /* General Registers */
430 {IXGBE_CTRL, "CTRL"},
431 {IXGBE_STATUS, "STATUS"},
432 {IXGBE_CTRL_EXT, "CTRL_EXT"},
434 /* Interrupt Registers */
435 {IXGBE_EICR, "EICR"},
438 {IXGBE_SRRCTL(0), "SRRCTL"},
439 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
440 {IXGBE_RDLEN(0), "RDLEN"},
441 {IXGBE_RDH(0), "RDH"},
442 {IXGBE_RDT(0), "RDT"},
443 {IXGBE_RXDCTL(0), "RXDCTL"},
444 {IXGBE_RDBAL(0), "RDBAL"},
445 {IXGBE_RDBAH(0), "RDBAH"},
448 {IXGBE_TDBAL(0), "TDBAL"},
449 {IXGBE_TDBAH(0), "TDBAH"},
450 {IXGBE_TDLEN(0), "TDLEN"},
451 {IXGBE_TDH(0), "TDH"},
452 {IXGBE_TDT(0), "TDT"},
453 {IXGBE_TXDCTL(0), "TXDCTL"},
455 /* List Terminator */
461 * ixgbe_regdump - register printout routine
463 static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
469 switch (reginfo->ofs) {
470 case IXGBE_SRRCTL(0):
471 for (i = 0; i < 64; i++)
472 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
474 case IXGBE_DCA_RXCTRL(0):
475 for (i = 0; i < 64; i++)
476 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
479 for (i = 0; i < 64; i++)
480 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
483 for (i = 0; i < 64; i++)
484 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
487 for (i = 0; i < 64; i++)
488 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
490 case IXGBE_RXDCTL(0):
491 for (i = 0; i < 64; i++)
492 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
495 for (i = 0; i < 64; i++)
496 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
499 for (i = 0; i < 64; i++)
500 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
503 for (i = 0; i < 64; i++)
504 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
507 for (i = 0; i < 64; i++)
508 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
511 for (i = 0; i < 64; i++)
512 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
515 for (i = 0; i < 64; i++)
516 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
519 for (i = 0; i < 64; i++)
520 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
522 case IXGBE_TXDCTL(0):
523 for (i = 0; i < 64; i++)
524 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
527 pr_info("%-15s %08x\n",
528 reginfo->name, IXGBE_READ_REG(hw, reginfo->ofs));
538 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i, i + 7);
539 for (j = 0; j < 8; j++)
540 p += sprintf(p, " %08x", regs[i++]);
541 pr_err("%-15s%s\n", rname, buf);
546 static void ixgbe_print_buffer(struct ixgbe_ring *ring, int n)
548 struct ixgbe_tx_buffer *tx_buffer;
550 tx_buffer = &ring->tx_buffer_info[ring->next_to_clean];
551 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
552 n, ring->next_to_use, ring->next_to_clean,
553 (u64)dma_unmap_addr(tx_buffer, dma),
554 dma_unmap_len(tx_buffer, len),
555 tx_buffer->next_to_watch,
556 (u64)tx_buffer->time_stamp);
560 * ixgbe_dump - Print registers, tx-rings and rx-rings
562 static void ixgbe_dump(struct ixgbe_adapter *adapter)
564 struct net_device *netdev = adapter->netdev;
565 struct ixgbe_hw *hw = &adapter->hw;
566 struct ixgbe_reg_info *reginfo;
568 struct ixgbe_ring *ring;
569 struct ixgbe_tx_buffer *tx_buffer;
570 union ixgbe_adv_tx_desc *tx_desc;
571 struct my_u0 { u64 a; u64 b; } *u0;
572 struct ixgbe_ring *rx_ring;
573 union ixgbe_adv_rx_desc *rx_desc;
574 struct ixgbe_rx_buffer *rx_buffer_info;
577 if (!netif_msg_hw(adapter))
580 /* Print netdevice Info */
582 dev_info(&adapter->pdev->dev, "Net device Info\n");
583 pr_info("Device Name state "
585 pr_info("%-15s %016lX %016lX\n",
588 dev_trans_start(netdev));
591 /* Print Registers */
592 dev_info(&adapter->pdev->dev, "Register Dump\n");
593 pr_info(" Register Name Value\n");
594 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
595 reginfo->name; reginfo++) {
596 ixgbe_regdump(hw, reginfo);
599 /* Print TX Ring Summary */
600 if (!netdev || !netif_running(netdev))
603 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
604 pr_info(" %s %s %s %s\n",
605 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
606 "leng", "ntw", "timestamp");
607 for (n = 0; n < adapter->num_tx_queues; n++) {
608 ring = adapter->tx_ring[n];
609 ixgbe_print_buffer(ring, n);
612 for (n = 0; n < adapter->num_xdp_queues; n++) {
613 ring = adapter->xdp_ring[n];
614 ixgbe_print_buffer(ring, n);
618 if (!netif_msg_tx_done(adapter))
619 goto rx_ring_summary;
621 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
623 /* Transmit Descriptor Formats
625 * 82598 Advanced Transmit Descriptor
626 * +--------------------------------------------------------------+
627 * 0 | Buffer Address [63:0] |
628 * +--------------------------------------------------------------+
629 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
630 * +--------------------------------------------------------------+
631 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
633 * 82598 Advanced Transmit Descriptor (Write-Back Format)
634 * +--------------------------------------------------------------+
636 * +--------------------------------------------------------------+
637 * 8 | RSV | STA | NXTSEQ |
638 * +--------------------------------------------------------------+
641 * 82599+ Advanced Transmit Descriptor
642 * +--------------------------------------------------------------+
643 * 0 | Buffer Address [63:0] |
644 * +--------------------------------------------------------------+
645 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
646 * +--------------------------------------------------------------+
647 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
649 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
650 * +--------------------------------------------------------------+
652 * +--------------------------------------------------------------+
653 * 8 | RSV | STA | RSV |
654 * +--------------------------------------------------------------+
658 for (n = 0; n < adapter->num_tx_queues; n++) {
659 ring = adapter->tx_ring[n];
660 pr_info("------------------------------------\n");
661 pr_info("TX QUEUE INDEX = %d\n", ring->queue_index);
662 pr_info("------------------------------------\n");
663 pr_info("%s%s %s %s %s %s\n",
664 "T [desc] [address 63:0 ] ",
665 "[PlPOIdStDDt Ln] [bi->dma ] ",
666 "leng", "ntw", "timestamp", "bi->skb");
668 for (i = 0; ring->desc && (i < ring->count); i++) {
669 tx_desc = IXGBE_TX_DESC(ring, i);
670 tx_buffer = &ring->tx_buffer_info[i];
671 u0 = (struct my_u0 *)tx_desc;
672 if (dma_unmap_len(tx_buffer, len) > 0) {
673 const char *ring_desc;
675 if (i == ring->next_to_use &&
676 i == ring->next_to_clean)
677 ring_desc = " NTC/U";
678 else if (i == ring->next_to_use)
680 else if (i == ring->next_to_clean)
684 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p%s",
686 le64_to_cpu((__force __le64)u0->a),
687 le64_to_cpu((__force __le64)u0->b),
688 (u64)dma_unmap_addr(tx_buffer, dma),
689 dma_unmap_len(tx_buffer, len),
690 tx_buffer->next_to_watch,
691 (u64)tx_buffer->time_stamp,
695 if (netif_msg_pktdata(adapter) &&
697 print_hex_dump(KERN_INFO, "",
698 DUMP_PREFIX_ADDRESS, 16, 1,
699 tx_buffer->skb->data,
700 dma_unmap_len(tx_buffer, len),
706 /* Print RX Rings Summary */
708 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
709 pr_info("Queue [NTU] [NTC]\n");
710 for (n = 0; n < adapter->num_rx_queues; n++) {
711 rx_ring = adapter->rx_ring[n];
712 pr_info("%5d %5X %5X\n",
713 n, rx_ring->next_to_use, rx_ring->next_to_clean);
717 if (!netif_msg_rx_status(adapter))
720 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
722 /* Receive Descriptor Formats
724 * 82598 Advanced Receive Descriptor (Read) Format
726 * +-----------------------------------------------------+
727 * 0 | Packet Buffer Address [63:1] |A0/NSE|
728 * +----------------------------------------------+------+
729 * 8 | Header Buffer Address [63:1] | DD |
730 * +-----------------------------------------------------+
733 * 82598 Advanced Receive Descriptor (Write-Back) Format
735 * 63 48 47 32 31 30 21 20 16 15 4 3 0
736 * +------------------------------------------------------+
737 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
738 * | Packet | IP | | | | Type | Type |
739 * | Checksum | Ident | | | | | |
740 * +------------------------------------------------------+
741 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
742 * +------------------------------------------------------+
743 * 63 48 47 32 31 20 19 0
745 * 82599+ Advanced Receive Descriptor (Read) Format
747 * +-----------------------------------------------------+
748 * 0 | Packet Buffer Address [63:1] |A0/NSE|
749 * +----------------------------------------------+------+
750 * 8 | Header Buffer Address [63:1] | DD |
751 * +-----------------------------------------------------+
754 * 82599+ Advanced Receive Descriptor (Write-Back) Format
756 * 63 48 47 32 31 30 21 20 17 16 4 3 0
757 * +------------------------------------------------------+
758 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
759 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
760 * |/ Flow Dir Flt ID | | | | | |
761 * +------------------------------------------------------+
762 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
763 * +------------------------------------------------------+
764 * 63 48 47 32 31 20 19 0
767 for (n = 0; n < adapter->num_rx_queues; n++) {
768 rx_ring = adapter->rx_ring[n];
769 pr_info("------------------------------------\n");
770 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
771 pr_info("------------------------------------\n");
773 "R [desc] [ PktBuf A0] ",
774 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
775 "<-- Adv Rx Read format");
777 "RWB[desc] [PcsmIpSHl PtRs] ",
778 "[vl er S cks ln] ---------------- [bi->skb ] ",
779 "<-- Adv Rx Write-Back format");
781 for (i = 0; i < rx_ring->count; i++) {
782 const char *ring_desc;
784 if (i == rx_ring->next_to_use)
786 else if (i == rx_ring->next_to_clean)
791 rx_buffer_info = &rx_ring->rx_buffer_info[i];
792 rx_desc = IXGBE_RX_DESC(rx_ring, i);
793 u0 = (struct my_u0 *)rx_desc;
794 if (rx_desc->wb.upper.length) {
795 /* Descriptor Done */
796 pr_info("RWB[0x%03X] %016llX %016llX ---------------- %p%s\n",
798 le64_to_cpu((__force __le64)u0->a),
799 le64_to_cpu((__force __le64)u0->b),
803 pr_info("R [0x%03X] %016llX %016llX %016llX %p%s\n",
805 le64_to_cpu((__force __le64)u0->a),
806 le64_to_cpu((__force __le64)u0->b),
807 (u64)rx_buffer_info->dma,
811 if (netif_msg_pktdata(adapter) &&
812 rx_buffer_info->dma) {
813 print_hex_dump(KERN_INFO, "",
814 DUMP_PREFIX_ADDRESS, 16, 1,
815 page_address(rx_buffer_info->page) +
816 rx_buffer_info->page_offset,
817 ixgbe_rx_bufsz(rx_ring), true);
824 static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
828 /* Let firmware take over control of h/w */
829 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
830 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
831 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
834 static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
838 /* Let firmware know the driver has taken over */
839 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
840 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
841 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
845 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
846 * @adapter: pointer to adapter struct
847 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
848 * @queue: queue to map the corresponding interrupt to
849 * @msix_vector: the vector to map to the corresponding queue
852 static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
853 u8 queue, u8 msix_vector)
856 struct ixgbe_hw *hw = &adapter->hw;
857 switch (hw->mac.type) {
858 case ixgbe_mac_82598EB:
859 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
862 index = (((direction * 64) + queue) >> 2) & 0x1F;
863 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
864 ivar &= ~(0xFF << (8 * (queue & 0x3)));
865 ivar |= (msix_vector << (8 * (queue & 0x3)));
866 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
868 case ixgbe_mac_82599EB:
871 case ixgbe_mac_X550EM_x:
872 case ixgbe_mac_x550em_a:
873 if (direction == -1) {
875 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
876 index = ((queue & 1) * 8);
877 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
878 ivar &= ~(0xFF << index);
879 ivar |= (msix_vector << index);
880 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
883 /* tx or rx causes */
884 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
885 index = ((16 * (queue & 1)) + (8 * direction));
886 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
887 ivar &= ~(0xFF << index);
888 ivar |= (msix_vector << index);
889 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
897 static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
902 switch (adapter->hw.mac.type) {
903 case ixgbe_mac_82598EB:
904 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
905 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
907 case ixgbe_mac_82599EB:
910 case ixgbe_mac_X550EM_x:
911 case ixgbe_mac_x550em_a:
912 mask = (qmask & 0xFFFFFFFF);
913 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
914 mask = (qmask >> 32);
915 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
922 static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
924 struct ixgbe_hw *hw = &adapter->hw;
925 struct ixgbe_hw_stats *hwstats = &adapter->stats;
929 if ((hw->fc.current_mode != ixgbe_fc_full) &&
930 (hw->fc.current_mode != ixgbe_fc_rx_pause))
933 switch (hw->mac.type) {
934 case ixgbe_mac_82598EB:
935 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
938 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
940 hwstats->lxoffrxc += data;
942 /* refill credits (no tx hang) if we received xoff */
946 for (i = 0; i < adapter->num_tx_queues; i++)
947 clear_bit(__IXGBE_HANG_CHECK_ARMED,
948 &adapter->tx_ring[i]->state);
950 for (i = 0; i < adapter->num_xdp_queues; i++)
951 clear_bit(__IXGBE_HANG_CHECK_ARMED,
952 &adapter->xdp_ring[i]->state);
955 static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
957 struct ixgbe_hw *hw = &adapter->hw;
958 struct ixgbe_hw_stats *hwstats = &adapter->stats;
962 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
964 if (adapter->ixgbe_ieee_pfc)
965 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
967 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
968 ixgbe_update_xoff_rx_lfc(adapter);
972 /* update stats for each tc, only valid with PFC enabled */
973 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
976 switch (hw->mac.type) {
977 case ixgbe_mac_82598EB:
978 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
981 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
983 hwstats->pxoffrxc[i] += pxoffrxc;
984 /* Get the TC for given UP */
985 tc = netdev_get_prio_tc_map(adapter->netdev, i);
986 xoff[tc] += pxoffrxc;
989 /* disarm tx queues that have received xoff frames */
990 for (i = 0; i < adapter->num_tx_queues; i++) {
991 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
993 tc = tx_ring->dcb_tc;
995 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
998 for (i = 0; i < adapter->num_xdp_queues; i++) {
999 struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i];
1001 tc = xdp_ring->dcb_tc;
1003 clear_bit(__IXGBE_HANG_CHECK_ARMED, &xdp_ring->state);
1007 static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
1009 return ring->stats.packets;
1012 static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
1014 unsigned int head, tail;
1016 head = ring->next_to_clean;
1017 tail = ring->next_to_use;
1019 return ((head <= tail) ? tail : tail + ring->count) - head;
1022 static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
1024 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
1025 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
1026 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
1028 clear_check_for_tx_hang(tx_ring);
1031 * Check for a hung queue, but be thorough. This verifies
1032 * that a transmit has been completed since the previous
1033 * check AND there is at least one packet pending. The
1034 * ARMED bit is set to indicate a potential hang. The
1035 * bit is cleared if a pause frame is received to remove
1036 * false hang detection due to PFC or 802.3x frames. By
1037 * requiring this to fail twice we avoid races with
1038 * pfc clearing the ARMED bit and conditions where we
1039 * run the check_tx_hang logic with a transmit completion
1040 * pending but without time to complete it yet.
1042 if (tx_done_old == tx_done && tx_pending)
1043 /* make sure it is true for two checks in a row */
1044 return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
1046 /* update completed stats and continue */
1047 tx_ring->tx_stats.tx_done_old = tx_done;
1048 /* reset the countdown */
1049 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
1055 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1056 * @adapter: driver private struct
1058 static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
1061 /* Do the reset outside of interrupt context */
1062 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1063 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
1064 e_warn(drv, "initiating reset due to tx timeout\n");
1065 ixgbe_service_event_schedule(adapter);
1070 * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
1071 * @netdev: network interface device structure
1072 * @queue_index: Tx queue to set
1073 * @maxrate: desired maximum transmit bitrate
1075 static int ixgbe_tx_maxrate(struct net_device *netdev,
1076 int queue_index, u32 maxrate)
1078 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1079 struct ixgbe_hw *hw = &adapter->hw;
1080 u32 bcnrc_val = ixgbe_link_mbps(adapter);
1085 /* Calculate the rate factor values to set */
1086 bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
1087 bcnrc_val /= maxrate;
1089 /* clear everything but the rate factor */
1090 bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
1091 IXGBE_RTTBCNRC_RF_DEC_MASK;
1093 /* enable the rate scheduler */
1094 bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
1096 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index);
1097 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
1103 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
1104 * @q_vector: structure containing interrupt and ring information
1105 * @tx_ring: tx ring to clean
1106 * @napi_budget: Used to determine if we are in netpoll
1108 static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
1109 struct ixgbe_ring *tx_ring, int napi_budget)
1111 struct ixgbe_adapter *adapter = q_vector->adapter;
1112 struct ixgbe_tx_buffer *tx_buffer;
1113 union ixgbe_adv_tx_desc *tx_desc;
1114 unsigned int total_bytes = 0, total_packets = 0, total_ipsec = 0;
1115 unsigned int budget = q_vector->tx.work_limit;
1116 unsigned int i = tx_ring->next_to_clean;
1118 if (test_bit(__IXGBE_DOWN, &adapter->state))
1121 tx_buffer = &tx_ring->tx_buffer_info[i];
1122 tx_desc = IXGBE_TX_DESC(tx_ring, i);
1123 i -= tx_ring->count;
1126 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
1128 /* if next_to_watch is not set then there is no work pending */
1132 /* prevent any other reads prior to eop_desc */
1135 /* if DD is not set pending work has not been completed */
1136 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
1139 /* clear next_to_watch to prevent false hangs */
1140 tx_buffer->next_to_watch = NULL;
1142 /* update the statistics for this packet */
1143 total_bytes += tx_buffer->bytecount;
1144 total_packets += tx_buffer->gso_segs;
1145 if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_IPSEC)
1149 if (ring_is_xdp(tx_ring))
1150 xdp_return_frame(tx_buffer->xdpf);
1152 napi_consume_skb(tx_buffer->skb, napi_budget);
1154 /* unmap skb header data */
1155 dma_unmap_single(tx_ring->dev,
1156 dma_unmap_addr(tx_buffer, dma),
1157 dma_unmap_len(tx_buffer, len),
1160 /* clear tx_buffer data */
1161 dma_unmap_len_set(tx_buffer, len, 0);
1163 /* unmap remaining buffers */
1164 while (tx_desc != eop_desc) {
1169 i -= tx_ring->count;
1170 tx_buffer = tx_ring->tx_buffer_info;
1171 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1174 /* unmap any remaining paged data */
1175 if (dma_unmap_len(tx_buffer, len)) {
1176 dma_unmap_page(tx_ring->dev,
1177 dma_unmap_addr(tx_buffer, dma),
1178 dma_unmap_len(tx_buffer, len),
1180 dma_unmap_len_set(tx_buffer, len, 0);
1184 /* move us one more past the eop_desc for start of next pkt */
1189 i -= tx_ring->count;
1190 tx_buffer = tx_ring->tx_buffer_info;
1191 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1194 /* issue prefetch for next Tx descriptor */
1197 /* update budget accounting */
1199 } while (likely(budget));
1201 i += tx_ring->count;
1202 tx_ring->next_to_clean = i;
1203 u64_stats_update_begin(&tx_ring->syncp);
1204 tx_ring->stats.bytes += total_bytes;
1205 tx_ring->stats.packets += total_packets;
1206 u64_stats_update_end(&tx_ring->syncp);
1207 q_vector->tx.total_bytes += total_bytes;
1208 q_vector->tx.total_packets += total_packets;
1209 adapter->tx_ipsec += total_ipsec;
1211 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
1212 /* schedule immediate reset if we believe we hung */
1213 struct ixgbe_hw *hw = &adapter->hw;
1214 e_err(drv, "Detected Tx Unit Hang %s\n"
1216 " TDH, TDT <%x>, <%x>\n"
1217 " next_to_use <%x>\n"
1218 " next_to_clean <%x>\n"
1219 "tx_buffer_info[next_to_clean]\n"
1220 " time_stamp <%lx>\n"
1222 ring_is_xdp(tx_ring) ? "(XDP)" : "",
1223 tx_ring->queue_index,
1224 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
1225 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
1226 tx_ring->next_to_use, i,
1227 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
1229 if (!ring_is_xdp(tx_ring))
1230 netif_stop_subqueue(tx_ring->netdev,
1231 tx_ring->queue_index);
1234 "tx hang %d detected on queue %d, resetting adapter\n",
1235 adapter->tx_timeout_count + 1, tx_ring->queue_index);
1237 /* schedule immediate reset if we believe we hung */
1238 ixgbe_tx_timeout_reset(adapter);
1240 /* the adapter is about to reset, no point in enabling stuff */
1244 if (ring_is_xdp(tx_ring))
1247 netdev_tx_completed_queue(txring_txq(tx_ring),
1248 total_packets, total_bytes);
1250 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
1251 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
1252 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
1253 /* Make sure that anybody stopping the queue after this
1254 * sees the new next_to_clean.
1257 if (__netif_subqueue_stopped(tx_ring->netdev,
1258 tx_ring->queue_index)
1259 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1260 netif_wake_subqueue(tx_ring->netdev,
1261 tx_ring->queue_index);
1262 ++tx_ring->tx_stats.restart_queue;
1269 #ifdef CONFIG_IXGBE_DCA
1270 static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
1271 struct ixgbe_ring *tx_ring,
1274 struct ixgbe_hw *hw = &adapter->hw;
1278 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1279 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1281 switch (hw->mac.type) {
1282 case ixgbe_mac_82598EB:
1283 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
1285 case ixgbe_mac_82599EB:
1286 case ixgbe_mac_X540:
1287 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1288 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1291 /* for unknown hardware do not write register */
1296 * We can enable relaxed ordering for reads, but not writes when
1297 * DCA is enabled. This is due to a known issue in some chipsets
1298 * which will cause the DCA tag to be cleared.
1300 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1301 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1302 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1304 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1307 static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1308 struct ixgbe_ring *rx_ring,
1311 struct ixgbe_hw *hw = &adapter->hw;
1313 u8 reg_idx = rx_ring->reg_idx;
1315 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1316 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
1318 switch (hw->mac.type) {
1319 case ixgbe_mac_82599EB:
1320 case ixgbe_mac_X540:
1321 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
1328 * We can enable relaxed ordering for reads, but not writes when
1329 * DCA is enabled. This is due to a known issue in some chipsets
1330 * which will cause the DCA tag to be cleared.
1332 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
1333 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
1334 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1336 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
1339 static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1341 struct ixgbe_adapter *adapter = q_vector->adapter;
1342 struct ixgbe_ring *ring;
1343 int cpu = get_cpu();
1345 if (q_vector->cpu == cpu)
1348 ixgbe_for_each_ring(ring, q_vector->tx)
1349 ixgbe_update_tx_dca(adapter, ring, cpu);
1351 ixgbe_for_each_ring(ring, q_vector->rx)
1352 ixgbe_update_rx_dca(adapter, ring, cpu);
1354 q_vector->cpu = cpu;
1359 static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1363 /* always use CB2 mode, difference is masked in the CB driver */
1364 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1365 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1366 IXGBE_DCA_CTRL_DCA_MODE_CB2);
1368 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1369 IXGBE_DCA_CTRL_DCA_DISABLE);
1371 for (i = 0; i < adapter->num_q_vectors; i++) {
1372 adapter->q_vector[i]->cpu = -1;
1373 ixgbe_update_dca(adapter->q_vector[i]);
1377 static int __ixgbe_notify_dca(struct device *dev, void *data)
1379 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
1380 unsigned long event = *(unsigned long *)data;
1382 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
1386 case DCA_PROVIDER_ADD:
1387 /* if we're already enabled, don't do it again */
1388 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1390 if (dca_add_requester(dev) == 0) {
1391 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
1392 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1393 IXGBE_DCA_CTRL_DCA_MODE_CB2);
1396 /* fall through - DCA is disabled. */
1397 case DCA_PROVIDER_REMOVE:
1398 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1399 dca_remove_requester(dev);
1400 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1401 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1402 IXGBE_DCA_CTRL_DCA_DISABLE);
1410 #endif /* CONFIG_IXGBE_DCA */
1412 #define IXGBE_RSS_L4_TYPES_MASK \
1413 ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
1414 (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
1415 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
1416 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
1418 static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1419 union ixgbe_adv_rx_desc *rx_desc,
1420 struct sk_buff *skb)
1424 if (!(ring->netdev->features & NETIF_F_RXHASH))
1427 rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
1428 IXGBE_RXDADV_RSSTYPE_MASK;
1433 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
1434 (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
1435 PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
1440 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1441 * @ring: structure containing ring specific data
1442 * @rx_desc: advanced rx descriptor
1444 * Returns : true if it is FCoE pkt
1446 static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
1447 union ixgbe_adv_rx_desc *rx_desc)
1449 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1451 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
1452 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1453 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1454 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1457 #endif /* IXGBE_FCOE */
1459 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1460 * @ring: structure containing ring specific data
1461 * @rx_desc: current Rx descriptor being processed
1462 * @skb: skb currently being received and modified
1464 static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
1465 union ixgbe_adv_rx_desc *rx_desc,
1466 struct sk_buff *skb)
1468 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1469 bool encap_pkt = false;
1471 skb_checksum_none_assert(skb);
1473 /* Rx csum disabled */
1474 if (!(ring->netdev->features & NETIF_F_RXCSUM))
1477 /* check for VXLAN and Geneve packets */
1478 if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) {
1480 skb->encapsulation = 1;
1483 /* if IP and error */
1484 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1485 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
1486 ring->rx_stats.csum_err++;
1490 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
1493 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
1495 * 82599 errata, UDP frames with a 0 checksum can be marked as
1498 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1499 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
1502 ring->rx_stats.csum_err++;
1506 /* It must be a TCP or UDP packet with a valid checksum */
1507 skb->ip_summed = CHECKSUM_UNNECESSARY;
1509 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
1512 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
1513 skb->ip_summed = CHECKSUM_NONE;
1516 /* If we checked the outer header let the stack know */
1517 skb->csum_level = 1;
1521 static inline unsigned int ixgbe_rx_offset(struct ixgbe_ring *rx_ring)
1523 return ring_uses_build_skb(rx_ring) ? IXGBE_SKB_PAD : 0;
1526 static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1527 struct ixgbe_rx_buffer *bi)
1529 struct page *page = bi->page;
1532 /* since we are recycling buffers we should seldom need to alloc */
1536 /* alloc new page for storage */
1537 page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
1538 if (unlikely(!page)) {
1539 rx_ring->rx_stats.alloc_rx_page_failed++;
1543 /* map page for use */
1544 dma = dma_map_page_attrs(rx_ring->dev, page, 0,
1545 ixgbe_rx_pg_size(rx_ring),
1550 * if mapping failed free memory back to system since
1551 * there isn't much point in holding memory we can't use
1553 if (dma_mapping_error(rx_ring->dev, dma)) {
1554 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
1556 rx_ring->rx_stats.alloc_rx_page_failed++;
1562 bi->page_offset = ixgbe_rx_offset(rx_ring);
1563 page_ref_add(page, USHRT_MAX - 1);
1564 bi->pagecnt_bias = USHRT_MAX;
1565 rx_ring->rx_stats.alloc_rx_page++;
1571 * ixgbe_alloc_rx_buffers - Replace used receive buffers
1572 * @rx_ring: ring to place buffers on
1573 * @cleaned_count: number of buffers to replace
1575 void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
1577 union ixgbe_adv_rx_desc *rx_desc;
1578 struct ixgbe_rx_buffer *bi;
1579 u16 i = rx_ring->next_to_use;
1586 rx_desc = IXGBE_RX_DESC(rx_ring, i);
1587 bi = &rx_ring->rx_buffer_info[i];
1588 i -= rx_ring->count;
1590 bufsz = ixgbe_rx_bufsz(rx_ring);
1593 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
1596 /* sync the buffer for use by the device */
1597 dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
1598 bi->page_offset, bufsz,
1602 * Refresh the desc even if buffer_addrs didn't change
1603 * because each write-back erases this info.
1605 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
1611 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
1612 bi = rx_ring->rx_buffer_info;
1613 i -= rx_ring->count;
1616 /* clear the length for the next_to_use descriptor */
1617 rx_desc->wb.upper.length = 0;
1620 } while (cleaned_count);
1622 i += rx_ring->count;
1624 if (rx_ring->next_to_use != i) {
1625 rx_ring->next_to_use = i;
1627 /* update next to alloc since we have filled the ring */
1628 rx_ring->next_to_alloc = i;
1630 /* Force memory writes to complete before letting h/w
1631 * know there are new descriptors to fetch. (Only
1632 * applicable for weak-ordered memory model archs,
1636 writel(i, rx_ring->tail);
1640 static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1641 struct sk_buff *skb)
1643 u16 hdr_len = skb_headlen(skb);
1645 /* set gso_size to avoid messing up TCP MSS */
1646 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1647 IXGBE_CB(skb)->append_cnt);
1648 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1651 static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1652 struct sk_buff *skb)
1654 /* if append_cnt is 0 then frame is not RSC */
1655 if (!IXGBE_CB(skb)->append_cnt)
1658 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1659 rx_ring->rx_stats.rsc_flush++;
1661 ixgbe_set_rsc_gso_size(rx_ring, skb);
1663 /* gso_size is computed using append_cnt so always clear it last */
1664 IXGBE_CB(skb)->append_cnt = 0;
1668 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1669 * @rx_ring: rx descriptor ring packet is being transacted on
1670 * @rx_desc: pointer to the EOP Rx descriptor
1671 * @skb: pointer to current skb being populated
1673 * This function checks the ring, descriptor, and packet information in
1674 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1675 * other fields within the skb.
1677 static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1678 union ixgbe_adv_rx_desc *rx_desc,
1679 struct sk_buff *skb)
1681 struct net_device *dev = rx_ring->netdev;
1682 u32 flags = rx_ring->q_vector->adapter->flags;
1684 ixgbe_update_rsc_stats(rx_ring, skb);
1686 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1688 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1690 if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED))
1691 ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
1693 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
1694 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1695 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1696 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
1699 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_STAT_SECP))
1700 ixgbe_ipsec_rx(rx_ring, rx_desc, skb);
1702 /* record Rx queue, or update MACVLAN statistics */
1703 if (netif_is_ixgbe(dev))
1704 skb_record_rx_queue(skb, rx_ring->queue_index);
1706 macvlan_count_rx(netdev_priv(dev), skb->len + ETH_HLEN, true,
1709 skb->protocol = eth_type_trans(skb, dev);
1712 static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1713 struct sk_buff *skb)
1715 napi_gro_receive(&q_vector->napi, skb);
1719 * ixgbe_is_non_eop - process handling of non-EOP buffers
1720 * @rx_ring: Rx ring being processed
1721 * @rx_desc: Rx descriptor for current buffer
1722 * @skb: Current socket buffer containing buffer in progress
1724 * This function updates next to clean. If the buffer is an EOP buffer
1725 * this function exits returning false, otherwise it will place the
1726 * sk_buff in the next buffer to be chained and return true indicating
1727 * that this is in fact a non-EOP buffer.
1729 static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1730 union ixgbe_adv_rx_desc *rx_desc,
1731 struct sk_buff *skb)
1733 u32 ntc = rx_ring->next_to_clean + 1;
1735 /* fetch, update, and store next to clean */
1736 ntc = (ntc < rx_ring->count) ? ntc : 0;
1737 rx_ring->next_to_clean = ntc;
1739 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1741 /* update RSC append count if present */
1742 if (ring_is_rsc_enabled(rx_ring)) {
1743 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1744 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1746 if (unlikely(rsc_enabled)) {
1747 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1749 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1750 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1752 /* update ntc based on RSC value */
1753 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1754 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1755 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1759 /* if we are the last buffer then there is nothing else to do */
1760 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1763 /* place skb in next buffer to be received */
1764 rx_ring->rx_buffer_info[ntc].skb = skb;
1765 rx_ring->rx_stats.non_eop_descs++;
1771 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1772 * @rx_ring: rx descriptor ring packet is being transacted on
1773 * @skb: pointer to current skb being adjusted
1775 * This function is an ixgbe specific version of __pskb_pull_tail. The
1776 * main difference between this version and the original function is that
1777 * this function can make several assumptions about the state of things
1778 * that allow for significant optimizations versus the standard function.
1779 * As a result we can do things like drop a frag and maintain an accurate
1780 * truesize for the skb.
1782 static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1783 struct sk_buff *skb)
1785 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1787 unsigned int pull_len;
1790 * it is valid to use page_address instead of kmap since we are
1791 * working with pages allocated out of the lomem pool per
1792 * alloc_page(GFP_ATOMIC)
1794 va = skb_frag_address(frag);
1797 * we need the header to contain the greater of either ETH_HLEN or
1798 * 60 bytes if the skb->len is less than 60 for skb_pad.
1800 pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
1802 /* align pull length to size of long to optimize memcpy performance */
1803 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1805 /* update all of the pointers */
1806 skb_frag_size_sub(frag, pull_len);
1807 frag->page_offset += pull_len;
1808 skb->data_len -= pull_len;
1809 skb->tail += pull_len;
1813 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1814 * @rx_ring: rx descriptor ring packet is being transacted on
1815 * @skb: pointer to current skb being updated
1817 * This function provides a basic DMA sync up for the first fragment of an
1818 * skb. The reason for doing this is that the first fragment cannot be
1819 * unmapped until we have reached the end of packet descriptor for a buffer
1822 static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1823 struct sk_buff *skb)
1825 if (ring_uses_build_skb(rx_ring)) {
1826 unsigned long mask = (unsigned long)ixgbe_rx_pg_size(rx_ring) - 1;
1827 unsigned long offset = (unsigned long)(skb->data) & mask;
1829 dma_sync_single_range_for_cpu(rx_ring->dev,
1835 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1837 dma_sync_single_range_for_cpu(rx_ring->dev,
1840 skb_frag_size(frag),
1844 /* If the page was released, just unmap it. */
1845 if (unlikely(IXGBE_CB(skb)->page_released)) {
1846 dma_unmap_page_attrs(rx_ring->dev, IXGBE_CB(skb)->dma,
1847 ixgbe_rx_pg_size(rx_ring),
1854 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1855 * @rx_ring: rx descriptor ring packet is being transacted on
1856 * @rx_desc: pointer to the EOP Rx descriptor
1857 * @skb: pointer to current skb being fixed
1859 * Check if the skb is valid in the XDP case it will be an error pointer.
1860 * Return true in this case to abort processing and advance to next
1863 * Check for corrupted packet headers caused by senders on the local L2
1864 * embedded NIC switch not setting up their Tx Descriptors right. These
1865 * should be very rare.
1867 * Also address the case where we are pulling data in on pages only
1868 * and as such no data is present in the skb header.
1870 * In addition if skb is not at least 60 bytes we need to pad it so that
1871 * it is large enough to qualify as a valid Ethernet frame.
1873 * Returns true if an error was encountered and skb was freed.
1875 static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1876 union ixgbe_adv_rx_desc *rx_desc,
1877 struct sk_buff *skb)
1879 struct net_device *netdev = rx_ring->netdev;
1881 /* XDP packets use error pointer so abort at this point */
1885 /* Verify netdev is present, and that packet does not have any
1886 * errors that would be unacceptable to the netdev.
1889 (unlikely(ixgbe_test_staterr(rx_desc,
1890 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1891 !(netdev->features & NETIF_F_RXALL)))) {
1892 dev_kfree_skb_any(skb);
1896 /* place header in linear portion of buffer */
1897 if (!skb_headlen(skb))
1898 ixgbe_pull_tail(rx_ring, skb);
1901 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1902 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1906 /* if eth_skb_pad returns an error the skb was freed */
1907 if (eth_skb_pad(skb))
1914 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1915 * @rx_ring: rx descriptor ring to store buffers on
1916 * @old_buff: donor buffer to have page reused
1918 * Synchronizes page for reuse by the adapter
1920 static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1921 struct ixgbe_rx_buffer *old_buff)
1923 struct ixgbe_rx_buffer *new_buff;
1924 u16 nta = rx_ring->next_to_alloc;
1926 new_buff = &rx_ring->rx_buffer_info[nta];
1928 /* update, and store next to alloc */
1930 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1932 /* Transfer page from old buffer to new buffer.
1933 * Move each member individually to avoid possible store
1934 * forwarding stalls and unnecessary copy of skb.
1936 new_buff->dma = old_buff->dma;
1937 new_buff->page = old_buff->page;
1938 new_buff->page_offset = old_buff->page_offset;
1939 new_buff->pagecnt_bias = old_buff->pagecnt_bias;
1942 static inline bool ixgbe_page_is_reserved(struct page *page)
1944 return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
1947 static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer *rx_buffer,
1948 int rx_buffer_pgcnt)
1950 unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
1951 struct page *page = rx_buffer->page;
1953 /* avoid re-using remote pages */
1954 if (unlikely(ixgbe_page_is_reserved(page)))
1957 #if (PAGE_SIZE < 8192)
1958 /* if we are only owner of page we can reuse it */
1959 if (unlikely((rx_buffer_pgcnt - pagecnt_bias) > 1))
1962 /* The last offset is a bit aggressive in that we assume the
1963 * worst case of FCoE being enabled and using a 3K buffer.
1964 * However this should have minimal impact as the 1K extra is
1965 * still less than one buffer in size.
1967 #define IXGBE_LAST_OFFSET \
1968 (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K)
1969 if (rx_buffer->page_offset > IXGBE_LAST_OFFSET)
1973 /* If we have drained the page fragment pool we need to update
1974 * the pagecnt_bias and page count so that we fully restock the
1975 * number of references the driver holds.
1977 if (unlikely(pagecnt_bias == 1)) {
1978 page_ref_add(page, USHRT_MAX - 1);
1979 rx_buffer->pagecnt_bias = USHRT_MAX;
1986 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1987 * @rx_ring: rx descriptor ring to transact packets on
1988 * @rx_buffer: buffer containing page to add
1989 * @skb: sk_buff to place the data into
1990 * @size: size of data in rx_buffer
1992 * This function will add the data contained in rx_buffer->page to the skb.
1993 * This is done either through a direct copy if the data in the buffer is
1994 * less than the skb header size, otherwise it will just attach the page as
1995 * a frag to the skb.
1997 * The function will then update the page offset if necessary and return
1998 * true if the buffer can be reused by the adapter.
2000 static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
2001 struct ixgbe_rx_buffer *rx_buffer,
2002 struct sk_buff *skb,
2005 #if (PAGE_SIZE < 8192)
2006 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2008 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
2009 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
2010 SKB_DATA_ALIGN(size);
2012 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
2013 rx_buffer->page_offset, size, truesize);
2014 #if (PAGE_SIZE < 8192)
2015 rx_buffer->page_offset ^= truesize;
2017 rx_buffer->page_offset += truesize;
2021 static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring,
2022 union ixgbe_adv_rx_desc *rx_desc,
2023 struct sk_buff **skb,
2024 const unsigned int size,
2025 int *rx_buffer_pgcnt)
2027 struct ixgbe_rx_buffer *rx_buffer;
2029 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
2031 #if (PAGE_SIZE < 8192)
2032 page_count(rx_buffer->page);
2036 prefetchw(rx_buffer->page);
2037 *skb = rx_buffer->skb;
2039 /* Delay unmapping of the first packet. It carries the header
2040 * information, HW may still access the header after the writeback.
2041 * Only unmap it when EOP is reached
2043 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) {
2048 ixgbe_dma_sync_frag(rx_ring, *skb);
2051 /* we are reusing so sync this buffer for CPU use */
2052 dma_sync_single_range_for_cpu(rx_ring->dev,
2054 rx_buffer->page_offset,
2058 rx_buffer->pagecnt_bias--;
2063 static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring,
2064 struct ixgbe_rx_buffer *rx_buffer,
2065 struct sk_buff *skb,
2066 int rx_buffer_pgcnt)
2068 if (ixgbe_can_reuse_rx_page(rx_buffer, rx_buffer_pgcnt)) {
2069 /* hand second half of page back to the ring */
2070 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
2072 if (!IS_ERR(skb) && IXGBE_CB(skb)->dma == rx_buffer->dma) {
2073 /* the page has been released from the ring */
2074 IXGBE_CB(skb)->page_released = true;
2076 /* we are not reusing the buffer so unmap it */
2077 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
2078 ixgbe_rx_pg_size(rx_ring),
2082 __page_frag_cache_drain(rx_buffer->page,
2083 rx_buffer->pagecnt_bias);
2086 /* clear contents of rx_buffer */
2087 rx_buffer->page = NULL;
2088 rx_buffer->skb = NULL;
2091 static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring,
2092 struct ixgbe_rx_buffer *rx_buffer,
2093 struct xdp_buff *xdp,
2094 union ixgbe_adv_rx_desc *rx_desc)
2096 unsigned int size = xdp->data_end - xdp->data;
2097 #if (PAGE_SIZE < 8192)
2098 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2100 unsigned int truesize = SKB_DATA_ALIGN(xdp->data_end -
2101 xdp->data_hard_start);
2103 struct sk_buff *skb;
2105 /* prefetch first cache line of first page */
2106 prefetch(xdp->data);
2107 #if L1_CACHE_BYTES < 128
2108 prefetch(xdp->data + L1_CACHE_BYTES);
2110 /* Note, we get here by enabling legacy-rx via:
2112 * ethtool --set-priv-flags <dev> legacy-rx on
2114 * In this mode, we currently get 0 extra XDP headroom as
2115 * opposed to having legacy-rx off, where we process XDP
2116 * packets going to stack via ixgbe_build_skb(). The latter
2117 * provides us currently with 192 bytes of headroom.
2119 * For ixgbe_construct_skb() mode it means that the
2120 * xdp->data_meta will always point to xdp->data, since
2121 * the helper cannot expand the head. Should this ever
2122 * change in future for legacy-rx mode on, then lets also
2123 * add xdp->data_meta handling here.
2126 /* allocate a skb to store the frags */
2127 skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE);
2131 if (size > IXGBE_RX_HDR_SIZE) {
2132 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2133 IXGBE_CB(skb)->dma = rx_buffer->dma;
2135 skb_add_rx_frag(skb, 0, rx_buffer->page,
2136 xdp->data - page_address(rx_buffer->page),
2138 #if (PAGE_SIZE < 8192)
2139 rx_buffer->page_offset ^= truesize;
2141 rx_buffer->page_offset += truesize;
2144 memcpy(__skb_put(skb, size),
2145 xdp->data, ALIGN(size, sizeof(long)));
2146 rx_buffer->pagecnt_bias++;
2152 static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,
2153 struct ixgbe_rx_buffer *rx_buffer,
2154 struct xdp_buff *xdp,
2155 union ixgbe_adv_rx_desc *rx_desc)
2157 unsigned int metasize = xdp->data - xdp->data_meta;
2158 #if (PAGE_SIZE < 8192)
2159 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2161 unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
2162 SKB_DATA_ALIGN(xdp->data_end -
2163 xdp->data_hard_start);
2165 struct sk_buff *skb;
2167 /* Prefetch first cache line of first page. If xdp->data_meta
2168 * is unused, this points extactly as xdp->data, otherwise we
2169 * likely have a consumer accessing first few bytes of meta
2170 * data, and then actual data.
2172 prefetch(xdp->data_meta);
2173 #if L1_CACHE_BYTES < 128
2174 prefetch(xdp->data_meta + L1_CACHE_BYTES);
2177 /* build an skb to around the page buffer */
2178 skb = build_skb(xdp->data_hard_start, truesize);
2182 /* update pointers within the skb to store the data */
2183 skb_reserve(skb, xdp->data - xdp->data_hard_start);
2184 __skb_put(skb, xdp->data_end - xdp->data);
2186 skb_metadata_set(skb, metasize);
2188 /* record DMA address if this is the start of a chain of buffers */
2189 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2190 IXGBE_CB(skb)->dma = rx_buffer->dma;
2192 /* update buffer offset */
2193 #if (PAGE_SIZE < 8192)
2194 rx_buffer->page_offset ^= truesize;
2196 rx_buffer->page_offset += truesize;
2202 #define IXGBE_XDP_PASS 0
2203 #define IXGBE_XDP_CONSUMED BIT(0)
2204 #define IXGBE_XDP_TX BIT(1)
2205 #define IXGBE_XDP_REDIR BIT(2)
2207 static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
2208 struct xdp_frame *xdpf);
2210 static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter,
2211 struct ixgbe_ring *rx_ring,
2212 struct xdp_buff *xdp)
2214 int err, result = IXGBE_XDP_PASS;
2215 struct bpf_prog *xdp_prog;
2216 struct xdp_frame *xdpf;
2220 xdp_prog = READ_ONCE(rx_ring->xdp_prog);
2225 prefetchw(xdp->data_hard_start); /* xdp_frame write */
2227 act = bpf_prog_run_xdp(xdp_prog, xdp);
2232 xdpf = convert_to_xdp_frame(xdp);
2233 if (unlikely(!xdpf)) {
2234 result = IXGBE_XDP_CONSUMED;
2237 result = ixgbe_xmit_xdp_ring(adapter, xdpf);
2240 err = xdp_do_redirect(adapter->netdev, xdp, xdp_prog);
2242 result = IXGBE_XDP_REDIR;
2244 result = IXGBE_XDP_CONSUMED;
2247 bpf_warn_invalid_xdp_action(act);
2250 trace_xdp_exception(rx_ring->netdev, xdp_prog, act);
2251 /* fallthrough -- handle aborts by dropping packet */
2253 result = IXGBE_XDP_CONSUMED;
2258 return ERR_PTR(-result);
2261 static void ixgbe_rx_buffer_flip(struct ixgbe_ring *rx_ring,
2262 struct ixgbe_rx_buffer *rx_buffer,
2265 #if (PAGE_SIZE < 8192)
2266 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2268 rx_buffer->page_offset ^= truesize;
2270 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
2271 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) +
2272 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) :
2273 SKB_DATA_ALIGN(size);
2275 rx_buffer->page_offset += truesize;
2280 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2281 * @q_vector: structure containing interrupt and ring information
2282 * @rx_ring: rx descriptor ring to transact packets on
2283 * @budget: Total limit on number of packets to process
2285 * This function provides a "bounce buffer" approach to Rx interrupt
2286 * processing. The advantage to this is that on systems that have
2287 * expensive overhead for IOMMU access this provides a means of avoiding
2288 * it by maintaining the mapping of the page to the syste.
2290 * Returns amount of work completed
2292 static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
2293 struct ixgbe_ring *rx_ring,
2296 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
2297 struct ixgbe_adapter *adapter = q_vector->adapter;
2300 unsigned int mss = 0;
2301 #endif /* IXGBE_FCOE */
2302 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
2303 unsigned int xdp_xmit = 0;
2304 struct xdp_buff xdp;
2306 xdp.rxq = &rx_ring->xdp_rxq;
2308 while (likely(total_rx_packets < budget)) {
2309 union ixgbe_adv_rx_desc *rx_desc;
2310 struct ixgbe_rx_buffer *rx_buffer;
2311 struct sk_buff *skb;
2312 int rx_buffer_pgcnt;
2315 /* return some buffers to hardware, one at a time is too slow */
2316 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2317 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2321 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
2322 size = le16_to_cpu(rx_desc->wb.upper.length);
2326 /* This memory barrier is needed to keep us from reading
2327 * any other fields out of the rx_desc until we know the
2328 * descriptor has been written back
2332 rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size, &rx_buffer_pgcnt);
2334 /* retrieve a buffer from the ring */
2336 xdp.data = page_address(rx_buffer->page) +
2337 rx_buffer->page_offset;
2338 xdp.data_meta = xdp.data;
2339 xdp.data_hard_start = xdp.data -
2340 ixgbe_rx_offset(rx_ring);
2341 xdp.data_end = xdp.data + size;
2343 skb = ixgbe_run_xdp(adapter, rx_ring, &xdp);
2347 unsigned int xdp_res = -PTR_ERR(skb);
2349 if (xdp_res & (IXGBE_XDP_TX | IXGBE_XDP_REDIR)) {
2350 xdp_xmit |= xdp_res;
2351 ixgbe_rx_buffer_flip(rx_ring, rx_buffer, size);
2353 rx_buffer->pagecnt_bias++;
2356 total_rx_bytes += size;
2358 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size);
2359 } else if (ring_uses_build_skb(rx_ring)) {
2360 skb = ixgbe_build_skb(rx_ring, rx_buffer,
2363 skb = ixgbe_construct_skb(rx_ring, rx_buffer,
2367 /* exit if we failed to retrieve a buffer */
2369 rx_ring->rx_stats.alloc_rx_buff_failed++;
2370 rx_buffer->pagecnt_bias++;
2374 ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb, rx_buffer_pgcnt);
2377 /* place incomplete frames back on ring for completion */
2378 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2381 /* verify the packet layout is correct */
2382 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2385 /* probably a little skewed due to removing CRC */
2386 total_rx_bytes += skb->len;
2388 /* populate checksum, timestamp, VLAN, and protocol */
2389 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2392 /* if ddp, not passing to ULD unless for FCP_RSP or error */
2393 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
2394 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
2395 /* include DDPed FCoE data */
2396 if (ddp_bytes > 0) {
2398 mss = rx_ring->netdev->mtu -
2399 sizeof(struct fcoe_hdr) -
2400 sizeof(struct fc_frame_header) -
2401 sizeof(struct fcoe_crc_eof);
2405 total_rx_bytes += ddp_bytes;
2406 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2410 dev_kfree_skb_any(skb);
2415 #endif /* IXGBE_FCOE */
2416 ixgbe_rx_skb(q_vector, skb);
2418 /* update budget accounting */
2422 if (xdp_xmit & IXGBE_XDP_REDIR)
2425 if (xdp_xmit & IXGBE_XDP_TX) {
2426 struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
2428 /* Force memory writes to complete before letting h/w
2429 * know there are new descriptors to fetch.
2432 writel(ring->next_to_use, ring->tail);
2435 u64_stats_update_begin(&rx_ring->syncp);
2436 rx_ring->stats.packets += total_rx_packets;
2437 rx_ring->stats.bytes += total_rx_bytes;
2438 u64_stats_update_end(&rx_ring->syncp);
2439 q_vector->rx.total_packets += total_rx_packets;
2440 q_vector->rx.total_bytes += total_rx_bytes;
2442 return total_rx_packets;
2446 * ixgbe_configure_msix - Configure MSI-X hardware
2447 * @adapter: board private structure
2449 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2452 static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2454 struct ixgbe_q_vector *q_vector;
2458 /* Populate MSIX to EITR Select */
2459 if (adapter->num_vfs > 32) {
2460 u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
2461 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2465 * Populate the IVAR table and set the ITR values to the
2466 * corresponding register.
2468 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
2469 struct ixgbe_ring *ring;
2470 q_vector = adapter->q_vector[v_idx];
2472 ixgbe_for_each_ring(ring, q_vector->rx)
2473 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
2475 ixgbe_for_each_ring(ring, q_vector->tx)
2476 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
2478 ixgbe_write_eitr(q_vector);
2481 switch (adapter->hw.mac.type) {
2482 case ixgbe_mac_82598EB:
2483 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
2486 case ixgbe_mac_82599EB:
2487 case ixgbe_mac_X540:
2488 case ixgbe_mac_X550:
2489 case ixgbe_mac_X550EM_x:
2490 case ixgbe_mac_x550em_a:
2491 ixgbe_set_ivar(adapter, -1, 1, v_idx);
2496 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
2498 /* set up to autoclear timer, and the vectors */
2499 mask = IXGBE_EIMS_ENABLE_MASK;
2500 mask &= ~(IXGBE_EIMS_OTHER |
2501 IXGBE_EIMS_MAILBOX |
2504 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
2508 * ixgbe_update_itr - update the dynamic ITR value based on statistics
2509 * @q_vector: structure containing interrupt and ring information
2510 * @ring_container: structure containing ring performance data
2512 * Stores a new ITR value based on packets and byte
2513 * counts during the last interrupt. The advantage of per interrupt
2514 * computation is faster updates and more accurate ITR for the current
2515 * traffic pattern. Constants in this function were computed
2516 * based on theoretical maximum wire speed and thresholds were set based
2517 * on testing data as well as attempting to minimize response time
2518 * while increasing bulk throughput.
2520 static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2521 struct ixgbe_ring_container *ring_container)
2523 unsigned int itr = IXGBE_ITR_ADAPTIVE_MIN_USECS |
2524 IXGBE_ITR_ADAPTIVE_LATENCY;
2525 unsigned int avg_wire_size, packets, bytes;
2526 unsigned long next_update = jiffies;
2528 /* If we don't have any rings just leave ourselves set for maximum
2529 * possible latency so we take ourselves out of the equation.
2531 if (!ring_container->ring)
2534 /* If we didn't update within up to 1 - 2 jiffies we can assume
2535 * that either packets are coming in so slow there hasn't been
2536 * any work, or that there is so much work that NAPI is dealing
2537 * with interrupt moderation and we don't need to do anything.
2539 if (time_after(next_update, ring_container->next_update))
2542 packets = ring_container->total_packets;
2544 /* We have no packets to actually measure against. This means
2545 * either one of the other queues on this vector is active or
2546 * we are a Tx queue doing TSO with too high of an interrupt rate.
2548 * When this occurs just tick up our delay by the minimum value
2549 * and hope that this extra delay will prevent us from being called
2550 * without any work on our queue.
2553 itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
2554 if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
2555 itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
2556 itr += ring_container->itr & IXGBE_ITR_ADAPTIVE_LATENCY;
2560 bytes = ring_container->total_bytes;
2562 /* If packets are less than 4 or bytes are less than 9000 assume
2563 * insufficient data to use bulk rate limiting approach. We are
2564 * likely latency driven.
2566 if (packets < 4 && bytes < 9000) {
2567 itr = IXGBE_ITR_ADAPTIVE_LATENCY;
2568 goto adjust_by_size;
2571 /* Between 4 and 48 we can assume that our current interrupt delay
2572 * is only slightly too low. As such we should increase it by a small
2576 itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
2577 if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
2578 itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
2582 /* Between 48 and 96 is our "goldilocks" zone where we are working
2583 * out "just right". Just report that our current ITR is good for us.
2586 itr = q_vector->itr >> 2;
2590 /* If packet count is 96 or greater we are likely looking at a slight
2591 * overrun of the delay we want. Try halving our delay to see if that
2592 * will cut the number of packets in half per interrupt.
2594 if (packets < 256) {
2595 itr = q_vector->itr >> 3;
2596 if (itr < IXGBE_ITR_ADAPTIVE_MIN_USECS)
2597 itr = IXGBE_ITR_ADAPTIVE_MIN_USECS;
2601 /* The paths below assume we are dealing with a bulk ITR since number
2602 * of packets is 256 or greater. We are just going to have to compute
2603 * a value and try to bring the count under control, though for smaller
2604 * packet sizes there isn't much we can do as NAPI polling will likely
2605 * be kicking in sooner rather than later.
2607 itr = IXGBE_ITR_ADAPTIVE_BULK;
2610 /* If packet counts are 256 or greater we can assume we have a gross
2611 * overestimation of what the rate should be. Instead of trying to fine
2612 * tune it just use the formula below to try and dial in an exact value
2613 * give the current packet size of the frame.
2615 avg_wire_size = bytes / packets;
2617 /* The following is a crude approximation of:
2618 * wmem_default / (size + overhead) = desired_pkts_per_int
2619 * rate / bits_per_byte / (size + ethernet overhead) = pkt_rate
2620 * (desired_pkt_rate / pkt_rate) * usecs_per_sec = ITR value
2622 * Assuming wmem_default is 212992 and overhead is 640 bytes per
2623 * packet, (256 skb, 64 headroom, 320 shared info), we can reduce the
2626 * (170 * (size + 24)) / (size + 640) = ITR
2628 * We first do some math on the packet size and then finally bitshift
2629 * by 8 after rounding up. We also have to account for PCIe link speed
2630 * difference as ITR scales based on this.
2632 if (avg_wire_size <= 60) {
2633 /* Start at 50k ints/sec */
2634 avg_wire_size = 5120;
2635 } else if (avg_wire_size <= 316) {
2636 /* 50K ints/sec to 16K ints/sec */
2637 avg_wire_size *= 40;
2638 avg_wire_size += 2720;
2639 } else if (avg_wire_size <= 1084) {
2640 /* 16K ints/sec to 9.2K ints/sec */
2641 avg_wire_size *= 15;
2642 avg_wire_size += 11452;
2643 } else if (avg_wire_size < 1968) {
2644 /* 9.2K ints/sec to 8K ints/sec */
2646 avg_wire_size += 22420;
2648 /* plateau at a limit of 8K ints/sec */
2649 avg_wire_size = 32256;
2652 /* If we are in low latency mode half our delay which doubles the rate
2653 * to somewhere between 100K to 16K ints/sec
2655 if (itr & IXGBE_ITR_ADAPTIVE_LATENCY)
2656 avg_wire_size >>= 1;
2658 /* Resultant value is 256 times larger than it needs to be. This
2659 * gives us room to adjust the value as needed to either increase
2660 * or decrease the value based on link speeds of 10G, 2.5G, 1G, etc.
2662 * Use addition as we have already recorded the new latency flag
2663 * for the ITR value.
2665 switch (q_vector->adapter->link_speed) {
2666 case IXGBE_LINK_SPEED_10GB_FULL:
2667 case IXGBE_LINK_SPEED_100_FULL:
2669 itr += DIV_ROUND_UP(avg_wire_size,
2670 IXGBE_ITR_ADAPTIVE_MIN_INC * 256) *
2671 IXGBE_ITR_ADAPTIVE_MIN_INC;
2673 case IXGBE_LINK_SPEED_2_5GB_FULL:
2674 case IXGBE_LINK_SPEED_1GB_FULL:
2675 case IXGBE_LINK_SPEED_10_FULL:
2676 if (avg_wire_size > 8064)
2677 avg_wire_size = 8064;
2678 itr += DIV_ROUND_UP(avg_wire_size,
2679 IXGBE_ITR_ADAPTIVE_MIN_INC * 64) *
2680 IXGBE_ITR_ADAPTIVE_MIN_INC;
2685 /* write back value */
2686 ring_container->itr = itr;
2688 /* next update should occur within next jiffy */
2689 ring_container->next_update = next_update + 1;
2691 ring_container->total_bytes = 0;
2692 ring_container->total_packets = 0;
2696 * ixgbe_write_eitr - write EITR register in hardware specific way
2697 * @q_vector: structure containing interrupt and ring information
2699 * This function is made to be called by ethtool and by the driver
2700 * when it needs to update EITR registers at runtime. Hardware
2701 * specific quirks/differences are taken care of here.
2703 void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
2705 struct ixgbe_adapter *adapter = q_vector->adapter;
2706 struct ixgbe_hw *hw = &adapter->hw;
2707 int v_idx = q_vector->v_idx;
2708 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
2710 switch (adapter->hw.mac.type) {
2711 case ixgbe_mac_82598EB:
2712 /* must write high and low 16 bits to reset counter */
2713 itr_reg |= (itr_reg << 16);
2715 case ixgbe_mac_82599EB:
2716 case ixgbe_mac_X540:
2717 case ixgbe_mac_X550:
2718 case ixgbe_mac_X550EM_x:
2719 case ixgbe_mac_x550em_a:
2721 * set the WDIS bit to not clear the timer bits and cause an
2722 * immediate assertion of the interrupt
2724 itr_reg |= IXGBE_EITR_CNT_WDIS;
2729 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2732 static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
2736 ixgbe_update_itr(q_vector, &q_vector->tx);
2737 ixgbe_update_itr(q_vector, &q_vector->rx);
2739 /* use the smallest value of new ITR delay calculations */
2740 new_itr = min(q_vector->rx.itr, q_vector->tx.itr);
2742 /* Clear latency flag if set, shift into correct position */
2743 new_itr &= ~IXGBE_ITR_ADAPTIVE_LATENCY;
2746 if (new_itr != q_vector->itr) {
2747 /* save the algorithm value here */
2748 q_vector->itr = new_itr;
2750 ixgbe_write_eitr(q_vector);
2755 * ixgbe_check_overtemp_subtask - check for over temperature
2756 * @adapter: pointer to adapter
2758 static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
2760 struct ixgbe_hw *hw = &adapter->hw;
2761 u32 eicr = adapter->interrupt_event;
2764 if (test_bit(__IXGBE_DOWN, &adapter->state))
2767 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2770 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2772 switch (hw->device_id) {
2773 case IXGBE_DEV_ID_82599_T3_LOM:
2775 * Since the warning interrupt is for both ports
2776 * we don't have to check if:
2777 * - This interrupt wasn't for our port.
2778 * - We may have missed the interrupt so always have to
2779 * check if we got a LSC
2781 if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
2782 !(eicr & IXGBE_EICR_LSC))
2785 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
2787 bool link_up = false;
2789 hw->mac.ops.check_link(hw, &speed, &link_up, false);
2795 /* Check if this is not due to overtemp */
2796 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2800 case IXGBE_DEV_ID_X550EM_A_1G_T:
2801 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
2802 rc = hw->phy.ops.check_overtemp(hw);
2803 if (rc != IXGBE_ERR_OVERTEMP)
2807 if (adapter->hw.mac.type >= ixgbe_mac_X540)
2809 if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
2813 e_crit(drv, "%s\n", ixgbe_overheat_msg);
2815 adapter->interrupt_event = 0;
2818 static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2820 struct ixgbe_hw *hw = &adapter->hw;
2822 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2823 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
2824 e_crit(probe, "Fan has stopped, replace the adapter\n");
2825 /* write to clear the interrupt */
2826 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
2830 static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2832 struct ixgbe_hw *hw = &adapter->hw;
2834 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2837 switch (adapter->hw.mac.type) {
2838 case ixgbe_mac_82599EB:
2840 * Need to check link state so complete overtemp check
2843 if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
2844 (eicr & IXGBE_EICR_LSC)) &&
2845 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2846 adapter->interrupt_event = eicr;
2847 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2848 ixgbe_service_event_schedule(adapter);
2852 case ixgbe_mac_x550em_a:
2853 if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) {
2854 adapter->interrupt_event = eicr;
2855 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2856 ixgbe_service_event_schedule(adapter);
2857 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
2858 IXGBE_EICR_GPI_SDP0_X550EM_a);
2859 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR,
2860 IXGBE_EICR_GPI_SDP0_X550EM_a);
2863 case ixgbe_mac_X550:
2864 case ixgbe_mac_X540:
2865 if (!(eicr & IXGBE_EICR_TS))
2872 e_crit(drv, "%s\n", ixgbe_overheat_msg);
2875 static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2877 switch (hw->mac.type) {
2878 case ixgbe_mac_82598EB:
2879 if (hw->phy.type == ixgbe_phy_nl)
2882 case ixgbe_mac_82599EB:
2883 case ixgbe_mac_X550EM_x:
2884 case ixgbe_mac_x550em_a:
2885 switch (hw->mac.ops.get_media_type(hw)) {
2886 case ixgbe_media_type_fiber:
2887 case ixgbe_media_type_fiber_qsfp:
2897 static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2899 struct ixgbe_hw *hw = &adapter->hw;
2900 u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
2902 if (!ixgbe_is_sfp(hw))
2905 /* Later MAC's use different SDP */
2906 if (hw->mac.type >= ixgbe_mac_X540)
2907 eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
2909 if (eicr & eicr_mask) {
2910 /* Clear the interrupt */
2911 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
2912 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2913 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2914 adapter->sfp_poll_time = 0;
2915 ixgbe_service_event_schedule(adapter);
2919 if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
2920 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
2921 /* Clear the interrupt */
2922 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
2923 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2924 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2925 ixgbe_service_event_schedule(adapter);
2930 static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2932 struct ixgbe_hw *hw = &adapter->hw;
2935 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2936 adapter->link_check_timeout = jiffies;
2937 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2938 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
2939 IXGBE_WRITE_FLUSH(hw);
2940 ixgbe_service_event_schedule(adapter);
2944 static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2948 struct ixgbe_hw *hw = &adapter->hw;
2950 switch (hw->mac.type) {
2951 case ixgbe_mac_82598EB:
2952 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
2953 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2955 case ixgbe_mac_82599EB:
2956 case ixgbe_mac_X540:
2957 case ixgbe_mac_X550:
2958 case ixgbe_mac_X550EM_x:
2959 case ixgbe_mac_x550em_a:
2960 mask = (qmask & 0xFFFFFFFF);
2962 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
2963 mask = (qmask >> 32);
2965 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2970 /* skip the flush */
2973 static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
2977 struct ixgbe_hw *hw = &adapter->hw;
2979 switch (hw->mac.type) {
2980 case ixgbe_mac_82598EB:
2981 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
2982 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2984 case ixgbe_mac_82599EB:
2985 case ixgbe_mac_X540:
2986 case ixgbe_mac_X550:
2987 case ixgbe_mac_X550EM_x:
2988 case ixgbe_mac_x550em_a:
2989 mask = (qmask & 0xFFFFFFFF);
2991 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
2992 mask = (qmask >> 32);
2994 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2999 /* skip the flush */
3003 * ixgbe_irq_enable - Enable default interrupt generation settings
3004 * @adapter: board private structure
3005 * @queues: enable irqs for queues
3006 * @flush: flush register write
3008 static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
3011 struct ixgbe_hw *hw = &adapter->hw;
3012 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
3014 /* don't reenable LSC while waiting for link */
3015 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
3016 mask &= ~IXGBE_EIMS_LSC;
3018 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
3019 switch (adapter->hw.mac.type) {
3020 case ixgbe_mac_82599EB:
3021 mask |= IXGBE_EIMS_GPI_SDP0(hw);
3023 case ixgbe_mac_X540:
3024 case ixgbe_mac_X550:
3025 case ixgbe_mac_X550EM_x:
3026 case ixgbe_mac_x550em_a:
3027 mask |= IXGBE_EIMS_TS;
3032 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
3033 mask |= IXGBE_EIMS_GPI_SDP1(hw);
3034 switch (adapter->hw.mac.type) {
3035 case ixgbe_mac_82599EB:
3036 mask |= IXGBE_EIMS_GPI_SDP1(hw);
3037 mask |= IXGBE_EIMS_GPI_SDP2(hw);
3039 case ixgbe_mac_X540:
3040 case ixgbe_mac_X550:
3041 case ixgbe_mac_X550EM_x:
3042 case ixgbe_mac_x550em_a:
3043 if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
3044 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
3045 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
3046 mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
3047 if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
3048 mask |= IXGBE_EICR_GPI_SDP0_X540;
3049 mask |= IXGBE_EIMS_ECC;
3050 mask |= IXGBE_EIMS_MAILBOX;
3056 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
3057 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
3058 mask |= IXGBE_EIMS_FLOW_DIR;
3060 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
3062 ixgbe_irq_enable_queues(adapter, ~0);
3064 IXGBE_WRITE_FLUSH(&adapter->hw);
3067 static irqreturn_t ixgbe_msix_other(int irq, void *data)
3069 struct ixgbe_adapter *adapter = data;
3070 struct ixgbe_hw *hw = &adapter->hw;
3074 * Workaround for Silicon errata. Use clear-by-write instead
3075 * of clear-by-read. Reading with EICS will return the
3076 * interrupt causes without clearing, which later be done
3077 * with the write to EICR.
3079 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
3081 /* The lower 16bits of the EICR register are for the queue interrupts
3082 * which should be masked here in order to not accidentally clear them if
3083 * the bits are high when ixgbe_msix_other is called. There is a race
3084 * condition otherwise which results in possible performance loss
3085 * especially if the ixgbe_msix_other interrupt is triggering
3086 * consistently (as it would when PPS is turned on for the X540 device)
3090 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
3092 if (eicr & IXGBE_EICR_LSC)
3093 ixgbe_check_lsc(adapter);
3095 if (eicr & IXGBE_EICR_MAILBOX)
3096 ixgbe_msg_task(adapter);
3098 switch (hw->mac.type) {
3099 case ixgbe_mac_82599EB:
3100 case ixgbe_mac_X540:
3101 case ixgbe_mac_X550:
3102 case ixgbe_mac_X550EM_x:
3103 case ixgbe_mac_x550em_a:
3104 if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
3105 (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
3106 adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
3107 ixgbe_service_event_schedule(adapter);
3108 IXGBE_WRITE_REG(hw, IXGBE_EICR,
3109 IXGBE_EICR_GPI_SDP0_X540);
3111 if (eicr & IXGBE_EICR_ECC) {
3112 e_info(link, "Received ECC Err, initiating reset\n");
3113 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
3114 ixgbe_service_event_schedule(adapter);
3115 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3117 /* Handle Flow Director Full threshold interrupt */
3118 if (eicr & IXGBE_EICR_FLOW_DIR) {
3119 int reinit_count = 0;
3121 for (i = 0; i < adapter->num_tx_queues; i++) {
3122 struct ixgbe_ring *ring = adapter->tx_ring[i];
3123 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
3128 /* no more flow director interrupts until after init */
3129 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
3130 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
3131 ixgbe_service_event_schedule(adapter);
3134 ixgbe_check_sfp_event(adapter, eicr);
3135 ixgbe_check_overtemp_event(adapter, eicr);
3141 ixgbe_check_fan_failure(adapter, eicr);
3143 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
3144 ixgbe_ptp_check_pps_event(adapter);
3146 /* re-enable the original interrupt state, no lsc, no queues */
3147 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3148 ixgbe_irq_enable(adapter, false, false);
3153 static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
3155 struct ixgbe_q_vector *q_vector = data;
3157 /* EIAM disabled interrupts (on this vector) for us */
3159 if (q_vector->rx.ring || q_vector->tx.ring)
3160 napi_schedule_irqoff(&q_vector->napi);
3166 * ixgbe_poll - NAPI Rx polling callback
3167 * @napi: structure for representing this polling device
3168 * @budget: how many packets driver is allowed to clean
3170 * This function is used for legacy and MSI, NAPI mode
3172 int ixgbe_poll(struct napi_struct *napi, int budget)
3174 struct ixgbe_q_vector *q_vector =
3175 container_of(napi, struct ixgbe_q_vector, napi);
3176 struct ixgbe_adapter *adapter = q_vector->adapter;
3177 struct ixgbe_ring *ring;
3178 int per_ring_budget, work_done = 0;
3179 bool clean_complete = true;
3181 #ifdef CONFIG_IXGBE_DCA
3182 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
3183 ixgbe_update_dca(q_vector);
3186 ixgbe_for_each_ring(ring, q_vector->tx) {
3187 if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
3188 clean_complete = false;
3191 /* Exit if we are called by netpoll */
3195 /* attempt to distribute budget to each queue fairly, but don't allow
3196 * the budget to go below 1 because we'll exit polling */
3197 if (q_vector->rx.count > 1)
3198 per_ring_budget = max(budget/q_vector->rx.count, 1);
3200 per_ring_budget = budget;
3202 ixgbe_for_each_ring(ring, q_vector->rx) {
3203 int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
3206 work_done += cleaned;
3207 if (cleaned >= per_ring_budget)
3208 clean_complete = false;
3211 /* If all work not completed, return budget and keep polling */
3212 if (!clean_complete)
3215 /* all work done, exit the polling mode */
3216 if (likely(napi_complete_done(napi, work_done))) {
3217 if (adapter->rx_itr_setting & 1)
3218 ixgbe_set_itr(q_vector);
3219 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3220 ixgbe_irq_enable_queues(adapter,
3221 BIT_ULL(q_vector->v_idx));
3224 return min(work_done, budget - 1);
3228 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
3229 * @adapter: board private structure
3231 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
3232 * interrupts from the kernel.
3234 static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
3236 struct net_device *netdev = adapter->netdev;
3237 unsigned int ri = 0, ti = 0;
3240 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
3241 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
3242 struct msix_entry *entry = &adapter->msix_entries[vector];
3244 if (q_vector->tx.ring && q_vector->rx.ring) {
3245 snprintf(q_vector->name, sizeof(q_vector->name),
3246 "%s-TxRx-%u", netdev->name, ri++);
3248 } else if (q_vector->rx.ring) {
3249 snprintf(q_vector->name, sizeof(q_vector->name),
3250 "%s-rx-%u", netdev->name, ri++);
3251 } else if (q_vector->tx.ring) {
3252 snprintf(q_vector->name, sizeof(q_vector->name),
3253 "%s-tx-%u", netdev->name, ti++);
3255 /* skip this unused q_vector */
3258 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
3259 q_vector->name, q_vector);
3261 e_err(probe, "request_irq failed for MSIX interrupt "
3262 "Error: %d\n", err);
3263 goto free_queue_irqs;
3265 /* If Flow Director is enabled, set interrupt affinity */
3266 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3267 /* assign the mask for this irq */
3268 irq_set_affinity_hint(entry->vector,
3269 &q_vector->affinity_mask);
3273 err = request_irq(adapter->msix_entries[vector].vector,
3274 ixgbe_msix_other, 0, netdev->name, adapter);
3276 e_err(probe, "request_irq for msix_other failed: %d\n", err);
3277 goto free_queue_irqs;
3285 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
3287 free_irq(adapter->msix_entries[vector].vector,
3288 adapter->q_vector[vector]);
3290 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3291 pci_disable_msix(adapter->pdev);
3292 kfree(adapter->msix_entries);
3293 adapter->msix_entries = NULL;
3298 * ixgbe_intr - legacy mode Interrupt Handler
3299 * @irq: interrupt number
3300 * @data: pointer to a network interface device structure
3302 static irqreturn_t ixgbe_intr(int irq, void *data)
3304 struct ixgbe_adapter *adapter = data;
3305 struct ixgbe_hw *hw = &adapter->hw;
3306 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
3310 * Workaround for silicon errata #26 on 82598. Mask the interrupt
3311 * before the read of EICR.
3313 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
3315 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
3316 * therefore no explicit interrupt disable is necessary */
3317 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
3320 * shared interrupt alert!
3321 * make sure interrupts are enabled because the read will
3322 * have disabled interrupts due to EIAM
3323 * finish the workaround of silicon errata on 82598. Unmask
3324 * the interrupt that we masked before the EICR read.
3326 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3327 ixgbe_irq_enable(adapter, true, true);
3328 return IRQ_NONE; /* Not our interrupt */
3331 if (eicr & IXGBE_EICR_LSC)
3332 ixgbe_check_lsc(adapter);
3334 switch (hw->mac.type) {
3335 case ixgbe_mac_82599EB:
3336 ixgbe_check_sfp_event(adapter, eicr);
3338 case ixgbe_mac_X540:
3339 case ixgbe_mac_X550:
3340 case ixgbe_mac_X550EM_x:
3341 case ixgbe_mac_x550em_a:
3342 if (eicr & IXGBE_EICR_ECC) {
3343 e_info(link, "Received ECC Err, initiating reset\n");
3344 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
3345 ixgbe_service_event_schedule(adapter);
3346 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3348 ixgbe_check_overtemp_event(adapter, eicr);
3354 ixgbe_check_fan_failure(adapter, eicr);
3355 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
3356 ixgbe_ptp_check_pps_event(adapter);
3358 /* would disable interrupts here but EIAM disabled it */
3359 napi_schedule_irqoff(&q_vector->napi);
3362 * re-enable link(maybe) and non-queue interrupts, no flush.
3363 * ixgbe_poll will re-enable the queue interrupts
3365 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3366 ixgbe_irq_enable(adapter, false, false);
3372 * ixgbe_request_irq - initialize interrupts
3373 * @adapter: board private structure
3375 * Attempts to configure interrupts using the best available
3376 * capabilities of the hardware and kernel.
3378 static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
3380 struct net_device *netdev = adapter->netdev;
3383 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3384 err = ixgbe_request_msix_irqs(adapter);
3385 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
3386 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
3387 netdev->name, adapter);
3389 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
3390 netdev->name, adapter);
3393 e_err(probe, "request_irq failed, Error %d\n", err);
3398 static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
3402 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
3403 free_irq(adapter->pdev->irq, adapter);
3407 if (!adapter->msix_entries)
3410 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
3411 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
3412 struct msix_entry *entry = &adapter->msix_entries[vector];
3414 /* free only the irqs that were actually requested */
3415 if (!q_vector->rx.ring && !q_vector->tx.ring)
3418 /* clear the affinity_mask in the IRQ descriptor */
3419 irq_set_affinity_hint(entry->vector, NULL);
3421 free_irq(entry->vector, q_vector);
3424 free_irq(adapter->msix_entries[vector].vector, adapter);
3428 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
3429 * @adapter: board private structure
3431 static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
3433 switch (adapter->hw.mac.type) {
3434 case ixgbe_mac_82598EB:
3435 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
3437 case ixgbe_mac_82599EB:
3438 case ixgbe_mac_X540:
3439 case ixgbe_mac_X550:
3440 case ixgbe_mac_X550EM_x:
3441 case ixgbe_mac_x550em_a:
3442 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
3443 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
3444 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
3449 IXGBE_WRITE_FLUSH(&adapter->hw);
3450 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3453 for (vector = 0; vector < adapter->num_q_vectors; vector++)
3454 synchronize_irq(adapter->msix_entries[vector].vector);
3456 synchronize_irq(adapter->msix_entries[vector++].vector);
3458 synchronize_irq(adapter->pdev->irq);
3463 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3464 * @adapter: board private structure
3467 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
3469 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
3471 ixgbe_write_eitr(q_vector);
3473 ixgbe_set_ivar(adapter, 0, 0, 0);
3474 ixgbe_set_ivar(adapter, 1, 0, 0);
3476 e_info(hw, "Legacy interrupt IVAR setup done\n");
3480 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3481 * @adapter: board private structure
3482 * @ring: structure containing ring specific data
3484 * Configure the Tx descriptor ring after a reset.
3486 void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
3487 struct ixgbe_ring *ring)
3489 struct ixgbe_hw *hw = &adapter->hw;
3490 u64 tdba = ring->dma;
3492 u32 txdctl = IXGBE_TXDCTL_ENABLE;
3493 u8 reg_idx = ring->reg_idx;
3495 /* disable queue to avoid issues while updating state */
3496 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
3497 IXGBE_WRITE_FLUSH(hw);
3499 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
3500 (tdba & DMA_BIT_MASK(32)));
3501 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3502 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3503 ring->count * sizeof(union ixgbe_adv_tx_desc));
3504 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3505 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
3506 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
3509 * set WTHRESH to encourage burst writeback, it should not be set
3510 * higher than 1 when:
3511 * - ITR is 0 as it could cause false TX hangs
3512 * - ITR is set to > 100k int/sec and BQL is enabled
3514 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3515 * to or less than the number of on chip descriptors, which is
3518 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
3519 txdctl |= 1u << 16; /* WTHRESH = 1 */
3521 txdctl |= 8u << 16; /* WTHRESH = 8 */
3524 * Setting PTHRESH to 32 both improves performance
3525 * and avoids a TX hang with DFP enabled
3527 txdctl |= (1u << 8) | /* HTHRESH = 1 */
3528 32; /* PTHRESH = 32 */
3530 /* reinitialize flowdirector state */
3531 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3532 ring->atr_sample_rate = adapter->atr_sample_rate;
3533 ring->atr_count = 0;
3534 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3536 ring->atr_sample_rate = 0;
3539 /* initialize XPS */
3540 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3541 struct ixgbe_q_vector *q_vector = ring->q_vector;
3544 netif_set_xps_queue(ring->netdev,
3545 &q_vector->affinity_mask,
3549 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3551 /* reinitialize tx_buffer_info */
3552 memset(ring->tx_buffer_info, 0,
3553 sizeof(struct ixgbe_tx_buffer) * ring->count);
3556 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3558 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3559 if (hw->mac.type == ixgbe_mac_82598EB &&
3560 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3563 /* poll to verify queue is enabled */
3565 usleep_range(1000, 2000);
3566 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3567 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3569 hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx);
3572 static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3574 struct ixgbe_hw *hw = &adapter->hw;
3576 u8 tcs = adapter->hw_tcs;
3578 if (hw->mac.type == ixgbe_mac_82598EB)
3581 /* disable the arbiter while setting MTQC */
3582 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3583 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3584 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3586 /* set transmit pool layout */
3587 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3588 mtqc = IXGBE_MTQC_VT_ENA;
3590 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3592 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3593 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3594 IXGBE_82599_VMDQ_4Q_MASK)
3595 mtqc |= IXGBE_MTQC_32VF;
3597 mtqc |= IXGBE_MTQC_64VF;
3600 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3601 } else if (tcs > 1) {
3602 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3604 u8 max_txq = adapter->num_tx_queues +
3605 adapter->num_xdp_queues;
3607 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3609 mtqc = IXGBE_MTQC_64Q_1PB;
3613 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
3615 /* Enable Security TX Buffer IFG for multiple pb */
3617 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3618 sectx |= IXGBE_SECTX_DCB;
3619 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
3622 /* re-enable the arbiter */
3623 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3624 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3628 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
3629 * @adapter: board private structure
3631 * Configure the Tx unit of the MAC after a reset.
3633 static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3635 struct ixgbe_hw *hw = &adapter->hw;
3639 ixgbe_setup_mtqc(adapter);
3641 if (hw->mac.type != ixgbe_mac_82598EB) {
3642 /* DMATXCTL.EN must be before Tx queues are enabled */
3643 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3644 dmatxctl |= IXGBE_DMATXCTL_TE;
3645 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3648 /* Setup the HW Tx Head and Tail descriptor pointers */
3649 for (i = 0; i < adapter->num_tx_queues; i++)
3650 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
3651 for (i = 0; i < adapter->num_xdp_queues; i++)
3652 ixgbe_configure_tx_ring(adapter, adapter->xdp_ring[i]);
3655 static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3656 struct ixgbe_ring *ring)
3658 struct ixgbe_hw *hw = &adapter->hw;
3659 u8 reg_idx = ring->reg_idx;
3660 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3662 srrctl |= IXGBE_SRRCTL_DROP_EN;
3664 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3667 static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3668 struct ixgbe_ring *ring)
3670 struct ixgbe_hw *hw = &adapter->hw;
3671 u8 reg_idx = ring->reg_idx;
3672 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3674 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3676 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3679 #ifdef CONFIG_IXGBE_DCB
3680 void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3682 static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3686 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3688 if (adapter->ixgbe_ieee_pfc)
3689 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3692 * We should set the drop enable bit if:
3695 * Number of Rx queues > 1 and flow control is disabled
3697 * This allows us to avoid head of line blocking for security
3698 * and performance reasons.
3700 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3701 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3702 for (i = 0; i < adapter->num_rx_queues; i++)
3703 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3705 for (i = 0; i < adapter->num_rx_queues; i++)
3706 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3710 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
3712 static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
3713 struct ixgbe_ring *rx_ring)
3715 struct ixgbe_hw *hw = &adapter->hw;
3717 u8 reg_idx = rx_ring->reg_idx;
3719 if (hw->mac.type == ixgbe_mac_82598EB) {
3720 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3723 * if VMDq is not active we must program one srrctl register
3724 * per RSS queue since we have enabled RDRXCTL.MVMEN
3729 /* configure header buffer length, needed for RSC */
3730 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
3732 /* configure the packet buffer length */
3733 if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state))
3734 srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
3736 srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
3738 /* configure descriptor type */
3739 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
3741 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3745 * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
3746 * @adapter: device handle
3748 * - 82598/82599/X540: 128
3749 * - X550(non-SRIOV mode): 512
3750 * - X550(SRIOV mode): 64
3752 u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
3754 if (adapter->hw.mac.type < ixgbe_mac_X550)
3756 else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3763 * ixgbe_store_key - Write the RSS key to HW
3764 * @adapter: device handle
3766 * Write the RSS key stored in adapter.rss_key to HW.
3768 void ixgbe_store_key(struct ixgbe_adapter *adapter)
3770 struct ixgbe_hw *hw = &adapter->hw;
3773 for (i = 0; i < 10; i++)
3774 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
3778 * ixgbe_init_rss_key - Initialize adapter RSS key
3779 * @adapter: device handle
3781 * Allocates and initializes the RSS key if it is not allocated.
3783 static inline int ixgbe_init_rss_key(struct ixgbe_adapter *adapter)
3787 if (!adapter->rss_key) {
3788 rss_key = kzalloc(IXGBE_RSS_KEY_SIZE, GFP_KERNEL);
3789 if (unlikely(!rss_key))
3792 netdev_rss_key_fill(rss_key, IXGBE_RSS_KEY_SIZE);
3793 adapter->rss_key = rss_key;
3800 * ixgbe_store_reta - Write the RETA table to HW
3801 * @adapter: device handle
3803 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3805 void ixgbe_store_reta(struct ixgbe_adapter *adapter)
3807 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3808 struct ixgbe_hw *hw = &adapter->hw;
3811 u8 *indir_tbl = adapter->rss_indir_tbl;
3813 /* Fill out the redirection table as follows:
3814 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3816 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3817 * - X550: 8 bit wide entries containing 6 bit RSS index
3819 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3820 indices_multi = 0x11;
3822 indices_multi = 0x1;
3824 /* Write redirection table to HW */
3825 for (i = 0; i < reta_entries; i++) {
3826 reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
3829 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3831 IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
3839 * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
3840 * @adapter: device handle
3842 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3844 static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
3846 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3847 struct ixgbe_hw *hw = &adapter->hw;
3850 /* Write redirection table to HW */
3851 for (i = 0; i < reta_entries; i++) {
3852 u16 pool = adapter->num_rx_pools;
3854 vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
3860 IXGBE_PFVFRETA(i >> 2, VMDQ_P(pool)),
3866 static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
3869 u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3870 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3872 /* Program table for at least 4 queues w/ SR-IOV so that VFs can
3873 * make full use of any rings they may have. We will use the
3874 * PSRTYPE register to control how many rings we use within the PF.
3876 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4))
3879 /* Fill out hash function seeds */
3880 ixgbe_store_key(adapter);
3882 /* Fill out redirection table */
3883 memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
3885 for (i = 0, j = 0; i < reta_entries; i++, j++) {
3889 adapter->rss_indir_tbl[i] = j;
3892 ixgbe_store_reta(adapter);
3895 static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
3897 struct ixgbe_hw *hw = &adapter->hw;
3898 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3901 /* Fill out hash function seeds */
3902 for (i = 0; i < 10; i++) {
3903 u16 pool = adapter->num_rx_pools;
3907 IXGBE_PFVFRSSRK(i, VMDQ_P(pool)),
3908 *(adapter->rss_key + i));
3911 /* Fill out the redirection table */
3912 for (i = 0, j = 0; i < 64; i++, j++) {
3916 adapter->rss_indir_tbl[i] = j;
3919 ixgbe_store_vfreta(adapter);
3922 static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3924 struct ixgbe_hw *hw = &adapter->hw;
3925 u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
3928 /* Disable indicating checksum in descriptor, enables RSS hash */
3929 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3930 rxcsum |= IXGBE_RXCSUM_PCSD;
3931 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3933 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
3934 if (adapter->ring_feature[RING_F_RSS].mask)
3935 mrqc = IXGBE_MRQC_RSSEN;
3937 u8 tcs = adapter->hw_tcs;
3939 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3941 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3943 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3944 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3945 IXGBE_82599_VMDQ_4Q_MASK)
3946 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3948 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3950 /* Enable L3/L4 for Tx Switched packets only for X550,
3951 * older devices do not support this feature
3953 if (hw->mac.type >= ixgbe_mac_X550)
3954 mrqc |= IXGBE_MRQC_L3L4TXSWEN;
3957 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3959 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3961 mrqc = IXGBE_MRQC_RSSEN;
3965 /* Perform hash on these packet types */
3966 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3967 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3968 IXGBE_MRQC_RSS_FIELD_IPV6 |
3969 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
3971 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
3972 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3973 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
3974 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3976 if ((hw->mac.type >= ixgbe_mac_X550) &&
3977 (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
3978 u16 pool = adapter->num_rx_pools;
3980 /* Enable VF RSS mode */
3981 mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
3982 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3984 /* Setup RSS through the VF registers */
3985 ixgbe_setup_vfreta(adapter);
3986 vfmrqc = IXGBE_MRQC_RSSEN;
3987 vfmrqc |= rss_field;
3991 IXGBE_PFVFMRQC(VMDQ_P(pool)),
3994 ixgbe_setup_reta(adapter);
3996 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
4001 * ixgbe_configure_rscctl - enable RSC for the indicated ring
4002 * @adapter: address of board private structure
4003 * @ring: structure containing ring specific data
4005 static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
4006 struct ixgbe_ring *ring)
4008 struct ixgbe_hw *hw = &adapter->hw;
4010 u8 reg_idx = ring->reg_idx;
4012 if (!ring_is_rsc_enabled(ring))
4015 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
4016 rscctrl |= IXGBE_RSCCTL_RSCEN;
4018 * we must limit the number of descriptors so that the
4019 * total size of max desc * buf_len is not greater
4022 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
4023 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
4026 #define IXGBE_MAX_RX_DESC_POLL 10
4027 static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
4028 struct ixgbe_ring *ring)
4030 struct ixgbe_hw *hw = &adapter->hw;
4031 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
4033 u8 reg_idx = ring->reg_idx;
4035 if (ixgbe_removed(hw->hw_addr))
4037 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
4038 if (hw->mac.type == ixgbe_mac_82598EB &&
4039 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
4043 usleep_range(1000, 2000);
4044 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
4045 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
4048 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
4049 "the polling period\n", reg_idx);
4053 void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
4054 struct ixgbe_ring *ring)
4056 struct ixgbe_hw *hw = &adapter->hw;
4057 union ixgbe_adv_rx_desc *rx_desc;
4058 u64 rdba = ring->dma;
4060 u8 reg_idx = ring->reg_idx;
4062 /* disable queue to avoid use of these values while updating state */
4063 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
4064 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
4066 /* write value back with RXDCTL.ENABLE bit cleared */
4067 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
4068 IXGBE_WRITE_FLUSH(hw);
4070 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
4071 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
4072 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
4073 ring->count * sizeof(union ixgbe_adv_rx_desc));
4074 /* Force flushing of IXGBE_RDLEN to prevent MDD */
4075 IXGBE_WRITE_FLUSH(hw);
4077 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
4078 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
4079 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
4081 ixgbe_configure_srrctl(adapter, ring);
4082 ixgbe_configure_rscctl(adapter, ring);
4084 if (hw->mac.type == ixgbe_mac_82598EB) {
4086 * enable cache line friendly hardware writes:
4087 * PTHRESH=32 descriptors (half the internal cache),
4088 * this also removes ugly rx_no_buffer_count increment
4089 * HTHRESH=4 descriptors (to minimize latency on fetch)
4090 * WTHRESH=8 burst writeback up to two cache lines
4092 rxdctl &= ~0x3FFFFF;
4094 #if (PAGE_SIZE < 8192)
4095 /* RXDCTL.RLPML does not work on 82599 */
4096 } else if (hw->mac.type != ixgbe_mac_82599EB) {
4097 rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK |
4098 IXGBE_RXDCTL_RLPML_EN);
4100 /* Limit the maximum frame size so we don't overrun the skb.
4101 * This can happen in SRIOV mode when the MTU of the VF is
4102 * higher than the MTU of the PF.
4104 if (ring_uses_build_skb(ring) &&
4105 !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state))
4106 rxdctl |= IXGBE_MAX_2K_FRAME_BUILD_SKB |
4107 IXGBE_RXDCTL_RLPML_EN;
4111 /* initialize rx_buffer_info */
4112 memset(ring->rx_buffer_info, 0,
4113 sizeof(struct ixgbe_rx_buffer) * ring->count);
4115 /* initialize Rx descriptor 0 */
4116 rx_desc = IXGBE_RX_DESC(ring, 0);
4117 rx_desc->wb.upper.length = 0;
4119 /* enable receive descriptor ring */
4120 rxdctl |= IXGBE_RXDCTL_ENABLE;
4121 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
4123 ixgbe_rx_desc_queue_enable(adapter, ring);
4124 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
4127 static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
4129 struct ixgbe_hw *hw = &adapter->hw;
4130 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
4131 u16 pool = adapter->num_rx_pools;
4133 /* PSRTYPE must be initialized in non 82598 adapters */
4134 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
4135 IXGBE_PSRTYPE_UDPHDR |
4136 IXGBE_PSRTYPE_IPV4HDR |
4137 IXGBE_PSRTYPE_L2HDR |
4138 IXGBE_PSRTYPE_IPV6HDR;
4140 if (hw->mac.type == ixgbe_mac_82598EB)
4144 psrtype |= 2u << 29;
4146 psrtype |= 1u << 29;
4149 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
4152 static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
4154 struct ixgbe_hw *hw = &adapter->hw;
4155 u16 pool = adapter->num_rx_pools;
4156 u32 reg_offset, vf_shift, vmolr;
4157 u32 gcr_ext, vmdctl;
4160 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
4163 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
4164 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
4165 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
4166 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
4167 vmdctl |= IXGBE_VT_CTL_REPLEN;
4168 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
4170 /* accept untagged packets until a vlan tag is
4171 * specifically set for the VMDQ queue/pool
4173 vmolr = IXGBE_VMOLR_AUPE;
4175 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(pool)), vmolr);
4177 vf_shift = VMDQ_P(0) % 32;
4178 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
4180 /* Enable only the PF's pool for Tx/Rx */
4181 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift));
4182 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
4183 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift));
4184 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
4185 if (adapter->bridge_mode == BRIDGE_MODE_VEB)
4186 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
4188 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
4189 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
4191 /* clear VLAN promisc flag so VFTA will be updated if necessary */
4192 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4195 * Set up VF register offsets for selected VT Mode,
4196 * i.e. 32 or 64 VFs for SR-IOV
4198 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4199 case IXGBE_82599_VMDQ_8Q_MASK:
4200 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
4202 case IXGBE_82599_VMDQ_4Q_MASK:
4203 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
4206 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
4210 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
4212 for (i = 0; i < adapter->num_vfs; i++) {
4213 /* configure spoof checking */
4214 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i,
4215 adapter->vfinfo[i].spoofchk_enabled);
4217 /* Enable/Disable RSS query feature */
4218 ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
4219 adapter->vfinfo[i].rss_query_enabled);
4223 static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
4225 struct ixgbe_hw *hw = &adapter->hw;
4226 struct net_device *netdev = adapter->netdev;
4227 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
4228 struct ixgbe_ring *rx_ring;
4233 /* adjust max frame to be able to do baby jumbo for FCoE */
4234 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
4235 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
4236 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4238 #endif /* IXGBE_FCOE */
4240 /* adjust max frame to be at least the size of a standard frame */
4241 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
4242 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
4244 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
4245 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
4246 mhadd &= ~IXGBE_MHADD_MFS_MASK;
4247 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
4249 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
4252 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
4253 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
4254 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
4255 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
4258 * Setup the HW Rx Head and Tail Descriptor Pointers and
4259 * the Base and Length of the Rx Descriptor Ring
4261 for (i = 0; i < adapter->num_rx_queues; i++) {
4262 rx_ring = adapter->rx_ring[i];
4264 clear_ring_rsc_enabled(rx_ring);
4265 clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
4266 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
4268 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
4269 set_ring_rsc_enabled(rx_ring);
4271 if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state))
4272 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
4274 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
4275 if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY)
4278 set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
4280 #if (PAGE_SIZE < 8192)
4281 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
4282 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
4284 if (IXGBE_2K_TOO_SMALL_WITH_PADDING ||
4285 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
4286 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
4291 static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
4293 struct ixgbe_hw *hw = &adapter->hw;
4294 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
4296 switch (hw->mac.type) {
4297 case ixgbe_mac_82598EB:
4299 * For VMDq support of different descriptor types or
4300 * buffer sizes through the use of multiple SRRCTL
4301 * registers, RDRXCTL.MVMEN must be set to 1
4303 * also, the manual doesn't mention it clearly but DCA hints
4304 * will only use queue 0's tags unless this bit is set. Side
4305 * effects of setting this bit are only that SRRCTL must be
4306 * fully programmed [0..15]
4308 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
4310 case ixgbe_mac_X550:
4311 case ixgbe_mac_X550EM_x:
4312 case ixgbe_mac_x550em_a:
4313 if (adapter->num_vfs)
4314 rdrxctl |= IXGBE_RDRXCTL_PSP;
4316 case ixgbe_mac_82599EB:
4317 case ixgbe_mac_X540:
4318 /* Disable RSC for ACK packets */
4319 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
4320 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
4321 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
4322 /* hardware requires some bits to be set by default */
4323 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
4324 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
4327 /* We should do nothing since we don't know this hardware */
4331 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
4335 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
4336 * @adapter: board private structure
4338 * Configure the Rx unit of the MAC after a reset.
4340 static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
4342 struct ixgbe_hw *hw = &adapter->hw;
4346 /* disable receives while setting up the descriptors */
4347 hw->mac.ops.disable_rx(hw);
4349 ixgbe_setup_psrtype(adapter);
4350 ixgbe_setup_rdrxctl(adapter);
4353 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
4354 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
4355 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
4356 rfctl |= IXGBE_RFCTL_RSC_DIS;
4358 /* disable NFS filtering */
4359 rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS);
4360 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
4362 /* Program registers for the distribution of queues */
4363 ixgbe_setup_mrqc(adapter);
4365 /* set_rx_buffer_len must be called before ring initialization */
4366 ixgbe_set_rx_buffer_len(adapter);
4369 * Setup the HW Rx Head and Tail Descriptor Pointers and
4370 * the Base and Length of the Rx Descriptor Ring
4372 for (i = 0; i < adapter->num_rx_queues; i++)
4373 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
4375 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4376 /* disable drop enable for 82598 parts */
4377 if (hw->mac.type == ixgbe_mac_82598EB)
4378 rxctrl |= IXGBE_RXCTRL_DMBYPS;
4380 /* enable all receives */
4381 rxctrl |= IXGBE_RXCTRL_RXEN;
4382 hw->mac.ops.enable_rx_dma(hw, rxctrl);
4385 static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
4386 __be16 proto, u16 vid)
4388 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4389 struct ixgbe_hw *hw = &adapter->hw;
4391 /* add VID to filter table */
4392 if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4393 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
4395 set_bit(vid, adapter->active_vlans);
4400 static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
4405 /* short cut the special case */
4409 /* Search for the vlan id in the VLVF entries */
4410 for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
4411 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
4412 if ((vlvf & VLAN_VID_MASK) == vlan)
4419 void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
4421 struct ixgbe_hw *hw = &adapter->hw;
4425 idx = ixgbe_find_vlvf_entry(hw, vid);
4429 /* See if any other pools are set for this VLAN filter
4430 * entry other than the PF.
4432 word = idx * 2 + (VMDQ_P(0) / 32);
4433 bits = ~BIT(VMDQ_P(0) % 32);
4434 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4436 /* Disable the filter so this falls into the default pool. */
4437 if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
4438 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4439 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
4440 IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
4444 static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
4445 __be16 proto, u16 vid)
4447 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4448 struct ixgbe_hw *hw = &adapter->hw;
4450 /* remove VID from filter table */
4451 if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4452 hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
4454 clear_bit(vid, adapter->active_vlans);
4460 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
4461 * @adapter: driver data
4463 static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
4465 struct ixgbe_hw *hw = &adapter->hw;
4469 switch (hw->mac.type) {
4470 case ixgbe_mac_82598EB:
4471 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4472 vlnctrl &= ~IXGBE_VLNCTRL_VME;
4473 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4475 case ixgbe_mac_82599EB:
4476 case ixgbe_mac_X540:
4477 case ixgbe_mac_X550:
4478 case ixgbe_mac_X550EM_x:
4479 case ixgbe_mac_x550em_a:
4480 for (i = 0; i < adapter->num_rx_queues; i++) {
4481 struct ixgbe_ring *ring = adapter->rx_ring[i];
4483 if (!netif_is_ixgbe(ring->netdev))
4487 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4488 vlnctrl &= ~IXGBE_RXDCTL_VME;
4489 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4498 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
4499 * @adapter: driver data
4501 static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
4503 struct ixgbe_hw *hw = &adapter->hw;
4507 switch (hw->mac.type) {
4508 case ixgbe_mac_82598EB:
4509 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4510 vlnctrl |= IXGBE_VLNCTRL_VME;
4511 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4513 case ixgbe_mac_82599EB:
4514 case ixgbe_mac_X540:
4515 case ixgbe_mac_X550:
4516 case ixgbe_mac_X550EM_x:
4517 case ixgbe_mac_x550em_a:
4518 for (i = 0; i < adapter->num_rx_queues; i++) {
4519 struct ixgbe_ring *ring = adapter->rx_ring[i];
4521 if (!netif_is_ixgbe(ring->netdev))
4525 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4526 vlnctrl |= IXGBE_RXDCTL_VME;
4527 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4535 static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
4537 struct ixgbe_hw *hw = &adapter->hw;
4540 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4542 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
4543 /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
4544 vlnctrl |= IXGBE_VLNCTRL_VFE;
4545 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4547 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
4548 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4552 /* Nothing to do for 82598 */
4553 if (hw->mac.type == ixgbe_mac_82598EB)
4556 /* We are already in VLAN promisc, nothing to do */
4557 if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
4560 /* Set flag so we don't redo unnecessary work */
4561 adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
4563 /* Add PF to all active pools */
4564 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4565 u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
4566 u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
4568 vlvfb |= BIT(VMDQ_P(0) % 32);
4569 IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
4572 /* Set all bits in the VLAN filter table array */
4573 for (i = hw->mac.vft_size; i--;)
4574 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
4577 #define VFTA_BLOCK_SIZE 8
4578 static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
4580 struct ixgbe_hw *hw = &adapter->hw;
4581 u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
4582 u32 vid_start = vfta_offset * 32;
4583 u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
4584 u32 i, vid, word, bits;
4586 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4587 u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
4589 /* pull VLAN ID from VLVF */
4590 vid = vlvf & VLAN_VID_MASK;
4592 /* only concern outselves with a certain range */
4593 if (vid < vid_start || vid >= vid_end)
4597 /* record VLAN ID in VFTA */
4598 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
4600 /* if PF is part of this then continue */
4601 if (test_bit(vid, adapter->active_vlans))
4605 /* remove PF from the pool */
4606 word = i * 2 + VMDQ_P(0) / 32;
4607 bits = ~BIT(VMDQ_P(0) % 32);
4608 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4609 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
4612 /* extract values from active_vlans and write back to VFTA */
4613 for (i = VFTA_BLOCK_SIZE; i--;) {
4614 vid = (vfta_offset + i) * 32;
4615 word = vid / BITS_PER_LONG;
4616 bits = vid % BITS_PER_LONG;
4618 vfta[i] |= adapter->active_vlans[word] >> bits;
4620 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
4624 static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
4626 struct ixgbe_hw *hw = &adapter->hw;
4629 /* Set VLAN filtering to enabled */
4630 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4631 vlnctrl |= IXGBE_VLNCTRL_VFE;
4632 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4634 if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) ||
4635 hw->mac.type == ixgbe_mac_82598EB)
4638 /* We are not in VLAN promisc, nothing to do */
4639 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4642 /* Set flag so we don't redo unnecessary work */
4643 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4645 for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
4646 ixgbe_scrub_vfta(adapter, i);
4649 static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
4653 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
4655 for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
4656 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
4660 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
4661 * @netdev: network interface device structure
4663 * Writes multicast address list to the MTA hash table.
4664 * Returns: -ENOMEM on failure
4665 * 0 on no addresses written
4666 * X on writing X addresses to MTA
4668 static int ixgbe_write_mc_addr_list(struct net_device *netdev)
4670 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4671 struct ixgbe_hw *hw = &adapter->hw;
4673 if (!netif_running(netdev))
4676 if (hw->mac.ops.update_mc_addr_list)
4677 hw->mac.ops.update_mc_addr_list(hw, netdev);
4681 #ifdef CONFIG_PCI_IOV
4682 ixgbe_restore_vf_multicasts(adapter);
4685 return netdev_mc_count(netdev);
4688 #ifdef CONFIG_PCI_IOV
4689 void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
4691 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
4692 struct ixgbe_hw *hw = &adapter->hw;
4695 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4696 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4698 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4699 hw->mac.ops.set_rar(hw, i,
4704 hw->mac.ops.clear_rar(hw, i);
4709 static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
4711 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
4712 struct ixgbe_hw *hw = &adapter->hw;
4715 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4716 if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
4719 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4721 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4722 hw->mac.ops.set_rar(hw, i,
4727 hw->mac.ops.clear_rar(hw, i);
4731 static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
4733 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
4734 struct ixgbe_hw *hw = &adapter->hw;
4737 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4738 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4739 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
4742 ixgbe_sync_mac_table(adapter);
4745 static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
4747 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
4748 struct ixgbe_hw *hw = &adapter->hw;
4751 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4752 /* do not count default RAR as available */
4753 if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
4756 /* only count unused and addresses that belong to us */
4757 if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
4758 if (mac_table->pool != pool)
4768 /* this function destroys the first RAR entry */
4769 static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
4771 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
4772 struct ixgbe_hw *hw = &adapter->hw;
4774 memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
4775 mac_table->pool = VMDQ_P(0);
4777 mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
4779 hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
4783 int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
4784 const u8 *addr, u16 pool)
4786 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
4787 struct ixgbe_hw *hw = &adapter->hw;
4790 if (is_zero_ether_addr(addr))
4793 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4794 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4797 ether_addr_copy(mac_table->addr, addr);
4798 mac_table->pool = pool;
4800 mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
4801 IXGBE_MAC_STATE_IN_USE;
4803 ixgbe_sync_mac_table(adapter);
4811 int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
4812 const u8 *addr, u16 pool)
4814 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
4815 struct ixgbe_hw *hw = &adapter->hw;
4818 if (is_zero_ether_addr(addr))
4821 /* search table for addr, if found clear IN_USE flag and sync */
4822 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4823 /* we can only delete an entry if it is in use */
4824 if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
4826 /* we only care about entries that belong to the given pool */
4827 if (mac_table->pool != pool)
4829 /* we only care about a specific MAC address */
4830 if (!ether_addr_equal(addr, mac_table->addr))
4833 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4834 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
4836 ixgbe_sync_mac_table(adapter);
4844 static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
4846 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4849 ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
4851 return min_t(int, ret, 0);
4854 static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
4856 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4858 ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
4864 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
4865 * @netdev: network interface device structure
4867 * The set_rx_method entry point is called whenever the unicast/multicast
4868 * address list or the network interface flags are updated. This routine is
4869 * responsible for configuring the hardware for proper unicast, multicast and
4872 void ixgbe_set_rx_mode(struct net_device *netdev)
4874 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4875 struct ixgbe_hw *hw = &adapter->hw;
4876 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
4877 netdev_features_t features = netdev->features;
4880 /* Check for Promiscuous and All Multicast modes */
4881 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4883 /* set all bits that we expect to always be set */
4884 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
4885 fctrl |= IXGBE_FCTRL_BAM;
4886 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
4887 fctrl |= IXGBE_FCTRL_PMCF;
4889 /* clear the bits we are changing the status of */
4890 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
4891 if (netdev->flags & IFF_PROMISC) {
4892 hw->addr_ctrl.user_set_promisc = true;
4893 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
4894 vmolr |= IXGBE_VMOLR_MPE;
4895 features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
4897 if (netdev->flags & IFF_ALLMULTI) {
4898 fctrl |= IXGBE_FCTRL_MPE;
4899 vmolr |= IXGBE_VMOLR_MPE;
4901 hw->addr_ctrl.user_set_promisc = false;
4905 * Write addresses to available RAR registers, if there is not
4906 * sufficient space to store all the addresses then enable
4907 * unicast promiscuous mode
4909 if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
4910 fctrl |= IXGBE_FCTRL_UPE;
4911 vmolr |= IXGBE_VMOLR_ROPE;
4914 /* Write addresses to the MTA, if the attempt fails
4915 * then we should just turn on promiscuous mode so
4916 * that we can at least receive multicast traffic
4918 count = ixgbe_write_mc_addr_list(netdev);
4920 fctrl |= IXGBE_FCTRL_MPE;
4921 vmolr |= IXGBE_VMOLR_MPE;
4923 vmolr |= IXGBE_VMOLR_ROMPE;
4926 if (hw->mac.type != ixgbe_mac_82598EB) {
4927 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
4928 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
4930 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
4933 /* This is useful for sniffing bad packets. */
4934 if (features & NETIF_F_RXALL) {
4935 /* UPE and MPE will be handled by normal PROMISC logic
4936 * in e1000e_set_rx_mode */
4937 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
4938 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
4939 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
4941 fctrl &= ~(IXGBE_FCTRL_DPF);
4942 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4945 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4947 if (features & NETIF_F_HW_VLAN_CTAG_RX)
4948 ixgbe_vlan_strip_enable(adapter);
4950 ixgbe_vlan_strip_disable(adapter);
4952 if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
4953 ixgbe_vlan_promisc_disable(adapter);
4955 ixgbe_vlan_promisc_enable(adapter);
4958 static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4962 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
4963 napi_enable(&adapter->q_vector[q_idx]->napi);
4966 static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
4970 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
4971 napi_disable(&adapter->q_vector[q_idx]->napi);
4974 static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask)
4976 struct ixgbe_hw *hw = &adapter->hw;
4979 if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE |
4980 IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)))
4983 vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) & ~mask;
4984 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl);
4986 if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK)
4987 adapter->vxlan_port = 0;
4989 if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK)
4990 adapter->geneve_port = 0;
4993 #ifdef CONFIG_IXGBE_DCB
4995 * ixgbe_configure_dcb - Configure DCB hardware
4996 * @adapter: ixgbe adapter struct
4998 * This is called by the driver on open to configure the DCB hardware.
4999 * This is also called by the gennetlink interface when reconfiguring
5002 static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
5004 struct ixgbe_hw *hw = &adapter->hw;
5005 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
5007 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
5008 if (hw->mac.type == ixgbe_mac_82598EB)
5009 netif_set_gso_max_size(adapter->netdev, 65536);
5013 if (hw->mac.type == ixgbe_mac_82598EB)
5014 netif_set_gso_max_size(adapter->netdev, 32768);
5017 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
5018 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
5021 /* reconfigure the hardware */
5022 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
5023 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
5025 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
5027 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
5028 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
5029 ixgbe_dcb_hw_ets(&adapter->hw,
5030 adapter->ixgbe_ieee_ets,
5032 ixgbe_dcb_hw_pfc_config(&adapter->hw,
5033 adapter->ixgbe_ieee_pfc->pfc_en,
5034 adapter->ixgbe_ieee_ets->prio_tc);
5037 /* Enable RSS Hash per TC */
5038 if (hw->mac.type != ixgbe_mac_82598EB) {
5040 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
5047 /* write msb to all 8 TCs in one write */
5048 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
5053 /* Additional bittime to account for IXGBE framing */
5054 #define IXGBE_ETH_FRAMING 20
5057 * ixgbe_hpbthresh - calculate high water mark for flow control
5059 * @adapter: board private structure to calculate for
5060 * @pb: packet buffer to calculate
5062 static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
5064 struct ixgbe_hw *hw = &adapter->hw;
5065 struct net_device *dev = adapter->netdev;
5066 int link, tc, kb, marker;
5069 /* Calculate max LAN frame size */
5070 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
5073 /* FCoE traffic class uses FCOE jumbo frames */
5074 if ((dev->features & NETIF_F_FCOE_MTU) &&
5075 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
5076 (pb == ixgbe_fcoe_get_tc(adapter)))
5077 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
5080 /* Calculate delay value for device */
5081 switch (hw->mac.type) {
5082 case ixgbe_mac_X540:
5083 case ixgbe_mac_X550:
5084 case ixgbe_mac_X550EM_x:
5085 case ixgbe_mac_x550em_a:
5086 dv_id = IXGBE_DV_X540(link, tc);
5089 dv_id = IXGBE_DV(link, tc);
5093 /* Loopback switch introduces additional latency */
5094 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5095 dv_id += IXGBE_B2BT(tc);
5097 /* Delay value is calculated in bit times convert to KB */
5098 kb = IXGBE_BT2KB(dv_id);
5099 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
5101 marker = rx_pba - kb;
5103 /* It is possible that the packet buffer is not large enough
5104 * to provide required headroom. In this case throw an error
5105 * to user and a do the best we can.
5108 e_warn(drv, "Packet Buffer(%i) can not provide enough"
5109 "headroom to support flow control."
5110 "Decrease MTU or number of traffic classes\n", pb);
5118 * ixgbe_lpbthresh - calculate low water mark for for flow control
5120 * @adapter: board private structure to calculate for
5121 * @pb: packet buffer to calculate
5123 static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
5125 struct ixgbe_hw *hw = &adapter->hw;
5126 struct net_device *dev = adapter->netdev;
5130 /* Calculate max LAN frame size */
5131 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
5134 /* FCoE traffic class uses FCOE jumbo frames */
5135 if ((dev->features & NETIF_F_FCOE_MTU) &&
5136 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
5137 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
5138 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
5141 /* Calculate delay value for device */
5142 switch (hw->mac.type) {
5143 case ixgbe_mac_X540:
5144 case ixgbe_mac_X550:
5145 case ixgbe_mac_X550EM_x:
5146 case ixgbe_mac_x550em_a:
5147 dv_id = IXGBE_LOW_DV_X540(tc);
5150 dv_id = IXGBE_LOW_DV(tc);
5154 /* Delay value is calculated in bit times convert to KB */
5155 return IXGBE_BT2KB(dv_id);
5159 * ixgbe_pbthresh_setup - calculate and setup high low water marks
5161 static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
5163 struct ixgbe_hw *hw = &adapter->hw;
5164 int num_tc = adapter->hw_tcs;
5170 for (i = 0; i < num_tc; i++) {
5171 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
5172 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
5174 /* Low water marks must not be larger than high water marks */
5175 if (hw->fc.low_water[i] > hw->fc.high_water[i])
5176 hw->fc.low_water[i] = 0;
5179 for (; i < MAX_TRAFFIC_CLASS; i++)
5180 hw->fc.high_water[i] = 0;
5183 static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
5185 struct ixgbe_hw *hw = &adapter->hw;
5187 u8 tc = adapter->hw_tcs;
5189 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5190 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5191 hdrm = 32 << adapter->fdir_pballoc;
5195 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
5196 ixgbe_pbthresh_setup(adapter);
5199 static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
5201 struct ixgbe_hw *hw = &adapter->hw;
5202 struct hlist_node *node2;
5203 struct ixgbe_fdir_filter *filter;
5206 spin_lock(&adapter->fdir_perfect_lock);
5208 if (!hlist_empty(&adapter->fdir_filter_list))
5209 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
5211 hlist_for_each_entry_safe(filter, node2,
5212 &adapter->fdir_filter_list, fdir_node) {
5213 if (filter->action == IXGBE_FDIR_DROP_QUEUE) {
5214 queue = IXGBE_FDIR_DROP_QUEUE;
5216 u32 ring = ethtool_get_flow_spec_ring(filter->action);
5217 u8 vf = ethtool_get_flow_spec_ring_vf(filter->action);
5219 if (!vf && (ring >= adapter->num_rx_queues)) {
5220 e_err(drv, "FDIR restore failed without VF, ring: %u\n",
5224 ((vf > adapter->num_vfs) ||
5225 ring >= adapter->num_rx_queues_per_pool)) {
5226 e_err(drv, "FDIR restore failed with VF, vf: %hhu, ring: %u\n",
5231 /* Map the ring onto the absolute queue index */
5233 queue = adapter->rx_ring[ring]->reg_idx;
5236 adapter->num_rx_queues_per_pool) + ring;
5239 ixgbe_fdir_write_perfect_filter_82599(hw,
5240 &filter->filter, filter->sw_idx, queue);
5243 spin_unlock(&adapter->fdir_perfect_lock);
5247 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
5248 * @rx_ring: ring to free buffers from
5250 static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
5252 u16 i = rx_ring->next_to_clean;
5253 struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
5255 /* Free all the Rx ring sk_buffs */
5256 while (i != rx_ring->next_to_alloc) {
5257 if (rx_buffer->skb) {
5258 struct sk_buff *skb = rx_buffer->skb;
5259 if (IXGBE_CB(skb)->page_released)
5260 dma_unmap_page_attrs(rx_ring->dev,
5262 ixgbe_rx_pg_size(rx_ring),
5268 /* Invalidate cache lines that may have been written to by
5269 * device so that we avoid corrupting memory.
5271 dma_sync_single_range_for_cpu(rx_ring->dev,
5273 rx_buffer->page_offset,
5274 ixgbe_rx_bufsz(rx_ring),
5277 /* free resources associated with mapping */
5278 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
5279 ixgbe_rx_pg_size(rx_ring),
5282 __page_frag_cache_drain(rx_buffer->page,
5283 rx_buffer->pagecnt_bias);
5287 if (i == rx_ring->count) {
5289 rx_buffer = rx_ring->rx_buffer_info;
5293 rx_ring->next_to_alloc = 0;
5294 rx_ring->next_to_clean = 0;
5295 rx_ring->next_to_use = 0;
5298 static int ixgbe_fwd_ring_up(struct ixgbe_adapter *adapter,
5299 struct ixgbe_fwd_adapter *accel)
5301 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
5302 int num_tc = netdev_get_num_tc(adapter->netdev);
5303 struct net_device *vdev = accel->netdev;
5306 baseq = accel->pool * adapter->num_rx_queues_per_pool;
5307 netdev_dbg(vdev, "pool %i:%i queues %i:%i\n",
5308 accel->pool, adapter->num_rx_pools,
5309 baseq, baseq + adapter->num_rx_queues_per_pool);
5311 accel->rx_base_queue = baseq;
5312 accel->tx_base_queue = baseq;
5314 /* record configuration for macvlan interface in vdev */
5315 for (i = 0; i < num_tc; i++)
5316 netdev_bind_sb_channel_queue(adapter->netdev, vdev,
5317 i, rss_i, baseq + (rss_i * i));
5319 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
5320 adapter->rx_ring[baseq + i]->netdev = vdev;
5322 /* Guarantee all rings are updated before we update the
5323 * MAC address filter.
5327 /* ixgbe_add_mac_filter will return an index if it succeeds, so we
5328 * need to only treat it as an error value if it is negative.
5330 err = ixgbe_add_mac_filter(adapter, vdev->dev_addr,
5331 VMDQ_P(accel->pool));
5335 /* if we cannot add the MAC rule then disable the offload */
5336 macvlan_release_l2fw_offload(vdev);
5338 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
5339 adapter->rx_ring[baseq + i]->netdev = NULL;
5341 netdev_err(vdev, "L2FW offload disabled due to L2 filter error\n");
5343 /* unbind the queues and drop the subordinate channel config */
5344 netdev_unbind_sb_channel(adapter->netdev, vdev);
5345 netdev_set_sb_channel(vdev, 0);
5347 clear_bit(accel->pool, adapter->fwd_bitmask);
5353 static int ixgbe_macvlan_up(struct net_device *vdev, void *data)
5355 struct ixgbe_adapter *adapter = data;
5356 struct ixgbe_fwd_adapter *accel;
5358 if (!netif_is_macvlan(vdev))
5361 accel = macvlan_accel_priv(vdev);
5365 ixgbe_fwd_ring_up(adapter, accel);
5370 static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
5372 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5373 ixgbe_macvlan_up, adapter);
5376 static void ixgbe_configure(struct ixgbe_adapter *adapter)
5378 struct ixgbe_hw *hw = &adapter->hw;
5380 ixgbe_configure_pb(adapter);
5381 #ifdef CONFIG_IXGBE_DCB
5382 ixgbe_configure_dcb(adapter);
5385 * We must restore virtualization before VLANs or else
5386 * the VLVF registers will not be populated
5388 ixgbe_configure_virtualization(adapter);
5390 ixgbe_set_rx_mode(adapter->netdev);
5391 ixgbe_restore_vlan(adapter);
5392 ixgbe_ipsec_restore(adapter);
5394 switch (hw->mac.type) {
5395 case ixgbe_mac_82599EB:
5396 case ixgbe_mac_X540:
5397 hw->mac.ops.disable_rx_buff(hw);
5403 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
5404 ixgbe_init_fdir_signature_82599(&adapter->hw,
5405 adapter->fdir_pballoc);
5406 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
5407 ixgbe_init_fdir_perfect_82599(&adapter->hw,
5408 adapter->fdir_pballoc);
5409 ixgbe_fdir_filter_restore(adapter);
5412 switch (hw->mac.type) {
5413 case ixgbe_mac_82599EB:
5414 case ixgbe_mac_X540:
5415 hw->mac.ops.enable_rx_buff(hw);
5421 #ifdef CONFIG_IXGBE_DCA
5423 if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
5424 ixgbe_setup_dca(adapter);
5425 #endif /* CONFIG_IXGBE_DCA */
5428 /* configure FCoE L2 filters, redirection table, and Rx control */
5429 ixgbe_configure_fcoe(adapter);
5431 #endif /* IXGBE_FCOE */
5432 ixgbe_configure_tx(adapter);
5433 ixgbe_configure_rx(adapter);
5434 ixgbe_configure_dfwd(adapter);
5438 * ixgbe_sfp_link_config - set up SFP+ link
5439 * @adapter: pointer to private adapter struct
5441 static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
5444 * We are assuming the worst case scenario here, and that
5445 * is that an SFP was inserted/removed after the reset
5446 * but before SFP detection was enabled. As such the best
5447 * solution is to just start searching as soon as we start
5449 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5450 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5452 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
5453 adapter->sfp_poll_time = 0;
5457 * ixgbe_non_sfp_link_config - set up non-SFP+ link
5458 * @hw: pointer to private hardware struct
5460 * Returns 0 on success, negative on failure
5462 static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
5465 bool autoneg, link_up = false;
5466 int ret = IXGBE_ERR_LINK_SETUP;
5468 if (hw->mac.ops.check_link)
5469 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
5474 speed = hw->phy.autoneg_advertised;
5475 if ((!speed) && (hw->mac.ops.get_link_capabilities))
5476 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
5481 if (hw->mac.ops.setup_link)
5482 ret = hw->mac.ops.setup_link(hw, speed, link_up);
5487 static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
5489 struct ixgbe_hw *hw = &adapter->hw;
5492 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5493 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
5495 gpie |= IXGBE_GPIE_EIAME;
5497 * use EIAM to auto-mask when MSI-X interrupt is asserted
5498 * this saves a register write for every interrupt
5500 switch (hw->mac.type) {
5501 case ixgbe_mac_82598EB:
5502 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
5504 case ixgbe_mac_82599EB:
5505 case ixgbe_mac_X540:
5506 case ixgbe_mac_X550:
5507 case ixgbe_mac_X550EM_x:
5508 case ixgbe_mac_x550em_a:
5510 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5511 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5515 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
5516 * specifically only auto mask tx and rx interrupts */
5517 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
5520 /* XXX: to interrupt immediately for EICS writes, enable this */
5521 /* gpie |= IXGBE_GPIE_EIMEN; */
5523 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
5524 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
5526 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
5527 case IXGBE_82599_VMDQ_8Q_MASK:
5528 gpie |= IXGBE_GPIE_VTMODE_16;
5530 case IXGBE_82599_VMDQ_4Q_MASK:
5531 gpie |= IXGBE_GPIE_VTMODE_32;
5534 gpie |= IXGBE_GPIE_VTMODE_64;
5539 /* Enable Thermal over heat sensor interrupt */
5540 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
5541 switch (adapter->hw.mac.type) {
5542 case ixgbe_mac_82599EB:
5543 gpie |= IXGBE_SDP0_GPIEN_8259X;
5550 /* Enable fan failure interrupt */
5551 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
5552 gpie |= IXGBE_SDP1_GPIEN(hw);
5554 switch (hw->mac.type) {
5555 case ixgbe_mac_82599EB:
5556 gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
5558 case ixgbe_mac_X550EM_x:
5559 case ixgbe_mac_x550em_a:
5560 gpie |= IXGBE_SDP0_GPIEN_X540;
5566 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
5569 static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
5571 struct ixgbe_hw *hw = &adapter->hw;
5575 ixgbe_get_hw_control(adapter);
5576 ixgbe_setup_gpie(adapter);
5578 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
5579 ixgbe_configure_msix(adapter);
5581 ixgbe_configure_msi_and_legacy(adapter);
5583 /* enable the optics for 82599 SFP+ fiber */
5584 if (hw->mac.ops.enable_tx_laser)
5585 hw->mac.ops.enable_tx_laser(hw);
5587 if (hw->phy.ops.set_phy_power)
5588 hw->phy.ops.set_phy_power(hw, true);
5590 smp_mb__before_atomic();
5591 clear_bit(__IXGBE_DOWN, &adapter->state);
5592 ixgbe_napi_enable_all(adapter);
5594 if (ixgbe_is_sfp(hw)) {
5595 ixgbe_sfp_link_config(adapter);
5597 err = ixgbe_non_sfp_link_config(hw);
5599 e_err(probe, "link_config FAILED %d\n", err);
5602 /* clear any pending interrupts, may auto mask */
5603 IXGBE_READ_REG(hw, IXGBE_EICR);
5604 ixgbe_irq_enable(adapter, true, true);
5607 * If this adapter has a fan, check to see if we had a failure
5608 * before we enabled the interrupt.
5610 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5611 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5612 if (esdp & IXGBE_ESDP_SDP1)
5613 e_crit(drv, "Fan has stopped, replace the adapter\n");
5616 /* bring the link up in the watchdog, this could race with our first
5617 * link up interrupt but shouldn't be a problem */
5618 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5619 adapter->link_check_timeout = jiffies;
5620 mod_timer(&adapter->service_timer, jiffies);
5622 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
5623 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
5624 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
5625 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
5628 void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
5630 WARN_ON(in_interrupt());
5631 /* put off any impending NetWatchDogTimeout */
5632 netif_trans_update(adapter->netdev);
5634 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
5635 usleep_range(1000, 2000);
5636 if (adapter->hw.phy.type == ixgbe_phy_fw)
5637 ixgbe_watchdog_link_is_down(adapter);
5638 ixgbe_down(adapter);
5640 * If SR-IOV enabled then wait a bit before bringing the adapter
5641 * back up to give the VFs time to respond to the reset. The
5642 * two second wait is based upon the watchdog timer cycle in
5645 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5648 clear_bit(__IXGBE_RESETTING, &adapter->state);
5651 void ixgbe_up(struct ixgbe_adapter *adapter)
5653 /* hardware has been reset, we need to reload some things */
5654 ixgbe_configure(adapter);
5656 ixgbe_up_complete(adapter);
5659 static unsigned long ixgbe_get_completion_timeout(struct ixgbe_adapter *adapter)
5663 pcie_capability_read_word(adapter->pdev, PCI_EXP_DEVCTL2, &devctl2);
5665 switch (devctl2 & IXGBE_PCIDEVCTRL2_TIMEO_MASK) {
5666 case IXGBE_PCIDEVCTRL2_17_34s:
5667 case IXGBE_PCIDEVCTRL2_4_8s:
5668 /* For now we cap the upper limit on delay to 2 seconds
5669 * as we end up going up to 34 seconds of delay in worst
5670 * case timeout value.
5672 case IXGBE_PCIDEVCTRL2_1_2s:
5673 return 2000000ul; /* 2.0 s */
5674 case IXGBE_PCIDEVCTRL2_260_520ms:
5675 return 520000ul; /* 520 ms */
5676 case IXGBE_PCIDEVCTRL2_65_130ms:
5677 return 130000ul; /* 130 ms */
5678 case IXGBE_PCIDEVCTRL2_16_32ms:
5679 return 32000ul; /* 32 ms */
5680 case IXGBE_PCIDEVCTRL2_1_2ms:
5681 return 2000ul; /* 2 ms */
5682 case IXGBE_PCIDEVCTRL2_50_100us:
5683 return 100ul; /* 100 us */
5684 case IXGBE_PCIDEVCTRL2_16_32ms_def:
5685 return 32000ul; /* 32 ms */
5690 /* We shouldn't need to hit this path, but just in case default as
5691 * though completion timeout is not supported and support 32ms.
5696 void ixgbe_disable_rx(struct ixgbe_adapter *adapter)
5698 unsigned long wait_delay, delay_interval;
5699 struct ixgbe_hw *hw = &adapter->hw;
5703 /* disable receives */
5704 hw->mac.ops.disable_rx(hw);
5706 if (ixgbe_removed(hw->hw_addr))
5709 /* disable all enabled Rx queues */
5710 for (i = 0; i < adapter->num_rx_queues; i++) {
5711 struct ixgbe_ring *ring = adapter->rx_ring[i];
5712 u8 reg_idx = ring->reg_idx;
5714 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
5715 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
5716 rxdctl |= IXGBE_RXDCTL_SWFLSH;
5718 /* write value back with RXDCTL.ENABLE bit cleared */
5719 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
5722 /* RXDCTL.EN may not change on 82598 if link is down, so skip it */
5723 if (hw->mac.type == ixgbe_mac_82598EB &&
5724 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
5727 /* Determine our minimum delay interval. We will increase this value
5728 * with each subsequent test. This way if the device returns quickly
5729 * we should spend as little time as possible waiting, however as
5730 * the time increases we will wait for larger periods of time.
5732 * The trick here is that we increase the interval using the
5733 * following pattern: 1x 3x 5x 7x 9x 11x 13x 15x 17x 19x. The result
5734 * of that wait is that it totals up to 100x whatever interval we
5735 * choose. Since our minimum wait is 100us we can just divide the
5736 * total timeout by 100 to get our minimum delay interval.
5738 delay_interval = ixgbe_get_completion_timeout(adapter) / 100;
5740 wait_loop = IXGBE_MAX_RX_DESC_POLL;
5741 wait_delay = delay_interval;
5743 while (wait_loop--) {
5744 usleep_range(wait_delay, wait_delay + 10);
5745 wait_delay += delay_interval * 2;
5748 /* OR together the reading of all the active RXDCTL registers,
5749 * and then test the result. We need the disable to complete
5750 * before we start freeing the memory and invalidating the
5753 for (i = 0; i < adapter->num_rx_queues; i++) {
5754 struct ixgbe_ring *ring = adapter->rx_ring[i];
5755 u8 reg_idx = ring->reg_idx;
5757 rxdctl |= IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
5760 if (!(rxdctl & IXGBE_RXDCTL_ENABLE))
5765 "RXDCTL.ENABLE for one or more queues not cleared within the polling period\n");
5768 void ixgbe_disable_tx(struct ixgbe_adapter *adapter)
5770 unsigned long wait_delay, delay_interval;
5771 struct ixgbe_hw *hw = &adapter->hw;
5775 if (ixgbe_removed(hw->hw_addr))
5778 /* disable all enabled Tx queues */
5779 for (i = 0; i < adapter->num_tx_queues; i++) {
5780 struct ixgbe_ring *ring = adapter->tx_ring[i];
5781 u8 reg_idx = ring->reg_idx;
5783 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
5786 /* disable all enabled XDP Tx queues */
5787 for (i = 0; i < adapter->num_xdp_queues; i++) {
5788 struct ixgbe_ring *ring = adapter->xdp_ring[i];
5789 u8 reg_idx = ring->reg_idx;
5791 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
5794 /* If the link is not up there shouldn't be much in the way of
5795 * pending transactions. Those that are left will be flushed out
5796 * when the reset logic goes through the flush sequence to clean out
5797 * the pending Tx transactions.
5799 if (!(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
5800 goto dma_engine_disable;
5802 /* Determine our minimum delay interval. We will increase this value
5803 * with each subsequent test. This way if the device returns quickly
5804 * we should spend as little time as possible waiting, however as
5805 * the time increases we will wait for larger periods of time.
5807 * The trick here is that we increase the interval using the
5808 * following pattern: 1x 3x 5x 7x 9x 11x 13x 15x 17x 19x. The result
5809 * of that wait is that it totals up to 100x whatever interval we
5810 * choose. Since our minimum wait is 100us we can just divide the
5811 * total timeout by 100 to get our minimum delay interval.
5813 delay_interval = ixgbe_get_completion_timeout(adapter) / 100;
5815 wait_loop = IXGBE_MAX_RX_DESC_POLL;
5816 wait_delay = delay_interval;
5818 while (wait_loop--) {
5819 usleep_range(wait_delay, wait_delay + 10);
5820 wait_delay += delay_interval * 2;
5823 /* OR together the reading of all the active TXDCTL registers,
5824 * and then test the result. We need the disable to complete
5825 * before we start freeing the memory and invalidating the
5828 for (i = 0; i < adapter->num_tx_queues; i++) {
5829 struct ixgbe_ring *ring = adapter->tx_ring[i];
5830 u8 reg_idx = ring->reg_idx;
5832 txdctl |= IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
5834 for (i = 0; i < adapter->num_xdp_queues; i++) {
5835 struct ixgbe_ring *ring = adapter->xdp_ring[i];
5836 u8 reg_idx = ring->reg_idx;
5838 txdctl |= IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
5841 if (!(txdctl & IXGBE_TXDCTL_ENABLE))
5842 goto dma_engine_disable;
5846 "TXDCTL.ENABLE for one or more queues not cleared within the polling period\n");
5849 /* Disable the Tx DMA engine on 82599 and later MAC */
5850 switch (hw->mac.type) {
5851 case ixgbe_mac_82599EB:
5852 case ixgbe_mac_X540:
5853 case ixgbe_mac_X550:
5854 case ixgbe_mac_X550EM_x:
5855 case ixgbe_mac_x550em_a:
5856 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
5857 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
5858 ~IXGBE_DMATXCTL_TE));
5865 void ixgbe_reset(struct ixgbe_adapter *adapter)
5867 struct ixgbe_hw *hw = &adapter->hw;
5868 struct net_device *netdev = adapter->netdev;
5871 if (ixgbe_removed(hw->hw_addr))
5873 /* lock SFP init bit to prevent race conditions with the watchdog */
5874 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5875 usleep_range(1000, 2000);
5877 /* clear all SFP and link config related flags while holding SFP_INIT */
5878 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
5879 IXGBE_FLAG2_SFP_NEEDS_RESET);
5880 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5882 err = hw->mac.ops.init_hw(hw);
5885 case IXGBE_ERR_SFP_NOT_PRESENT:
5886 case IXGBE_ERR_SFP_NOT_SUPPORTED:
5888 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
5889 e_dev_err("master disable timed out\n");
5891 case IXGBE_ERR_EEPROM_VERSION:
5892 /* We are running on a pre-production device, log a warning */
5893 e_dev_warn("This device is a pre-production adapter/LOM. "
5894 "Please be aware there may be issues associated with "
5895 "your hardware. If you are experiencing problems "
5896 "please contact your Intel or hardware "
5897 "representative who provided you with this "
5901 e_dev_err("Hardware Error: %d\n", err);
5904 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5906 /* flush entries out of MAC table */
5907 ixgbe_flush_sw_mac_table(adapter);
5908 __dev_uc_unsync(netdev, NULL);
5910 /* do not flush user set addresses */
5911 ixgbe_mac_set_default_filter(adapter);
5913 /* update SAN MAC vmdq pool selection */
5914 if (hw->mac.san_mac_rar_index)
5915 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
5917 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
5918 ixgbe_ptp_reset(adapter);
5920 if (hw->phy.ops.set_phy_power) {
5921 if (!netif_running(adapter->netdev) && !adapter->wol)
5922 hw->phy.ops.set_phy_power(hw, false);
5924 hw->phy.ops.set_phy_power(hw, true);
5929 * ixgbe_clean_tx_ring - Free Tx Buffers
5930 * @tx_ring: ring to be cleaned
5932 static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
5934 u16 i = tx_ring->next_to_clean;
5935 struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
5937 while (i != tx_ring->next_to_use) {
5938 union ixgbe_adv_tx_desc *eop_desc, *tx_desc;
5940 /* Free all the Tx ring sk_buffs */
5941 if (ring_is_xdp(tx_ring))
5942 xdp_return_frame(tx_buffer->xdpf);
5944 dev_kfree_skb_any(tx_buffer->skb);
5946 /* unmap skb header data */
5947 dma_unmap_single(tx_ring->dev,
5948 dma_unmap_addr(tx_buffer, dma),
5949 dma_unmap_len(tx_buffer, len),
5952 /* check for eop_desc to determine the end of the packet */
5953 eop_desc = tx_buffer->next_to_watch;
5954 tx_desc = IXGBE_TX_DESC(tx_ring, i);
5956 /* unmap remaining buffers */
5957 while (tx_desc != eop_desc) {
5961 if (unlikely(i == tx_ring->count)) {
5963 tx_buffer = tx_ring->tx_buffer_info;
5964 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
5967 /* unmap any remaining paged data */
5968 if (dma_unmap_len(tx_buffer, len))
5969 dma_unmap_page(tx_ring->dev,
5970 dma_unmap_addr(tx_buffer, dma),
5971 dma_unmap_len(tx_buffer, len),
5975 /* move us one more past the eop_desc for start of next pkt */
5978 if (unlikely(i == tx_ring->count)) {
5980 tx_buffer = tx_ring->tx_buffer_info;
5984 /* reset BQL for queue */
5985 if (!ring_is_xdp(tx_ring))
5986 netdev_tx_reset_queue(txring_txq(tx_ring));
5988 /* reset next_to_use and next_to_clean */
5989 tx_ring->next_to_use = 0;
5990 tx_ring->next_to_clean = 0;
5994 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5995 * @adapter: board private structure
5997 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
6001 for (i = 0; i < adapter->num_rx_queues; i++)
6002 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
6006 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
6007 * @adapter: board private structure
6009 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
6013 for (i = 0; i < adapter->num_tx_queues; i++)
6014 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
6015 for (i = 0; i < adapter->num_xdp_queues; i++)
6016 ixgbe_clean_tx_ring(adapter->xdp_ring[i]);
6019 static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
6021 struct hlist_node *node2;
6022 struct ixgbe_fdir_filter *filter;
6024 spin_lock(&adapter->fdir_perfect_lock);
6026 hlist_for_each_entry_safe(filter, node2,
6027 &adapter->fdir_filter_list, fdir_node) {
6028 hlist_del(&filter->fdir_node);
6031 adapter->fdir_filter_count = 0;
6033 spin_unlock(&adapter->fdir_perfect_lock);
6036 void ixgbe_down(struct ixgbe_adapter *adapter)
6038 struct net_device *netdev = adapter->netdev;
6039 struct ixgbe_hw *hw = &adapter->hw;
6042 /* signal that we are down to the interrupt handler */
6043 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
6044 return; /* do nothing if already down */
6046 /* Shut off incoming Tx traffic */
6047 netif_tx_stop_all_queues(netdev);
6049 /* call carrier off first to avoid false dev_watchdog timeouts */
6050 netif_carrier_off(netdev);
6051 netif_tx_disable(netdev);
6054 ixgbe_disable_rx(adapter);
6056 /* synchronize_sched() needed for pending XDP buffers to drain */
6057 if (adapter->xdp_ring[0])
6058 synchronize_sched();
6060 ixgbe_irq_disable(adapter);
6062 ixgbe_napi_disable_all(adapter);
6064 clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
6065 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6066 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6068 del_timer_sync(&adapter->service_timer);
6070 if (adapter->num_vfs) {
6071 /* Clear EITR Select mapping */
6072 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
6074 /* Mark all the VFs as inactive */
6075 for (i = 0 ; i < adapter->num_vfs; i++)
6076 adapter->vfinfo[i].clear_to_send = false;
6078 /* ping all the active vfs to let them know we are going down */
6079 ixgbe_ping_all_vfs(adapter);
6081 /* Disable all VFTE/VFRE TX/RX */
6082 ixgbe_disable_tx_rx(adapter);
6085 /* disable transmits in the hardware now that interrupts are off */
6086 ixgbe_disable_tx(adapter);
6088 if (!pci_channel_offline(adapter->pdev))
6089 ixgbe_reset(adapter);
6091 /* power down the optics for 82599 SFP+ fiber */
6092 if (hw->mac.ops.disable_tx_laser)
6093 hw->mac.ops.disable_tx_laser(hw);
6095 ixgbe_clean_all_tx_rings(adapter);
6096 ixgbe_clean_all_rx_rings(adapter);
6100 * ixgbe_eee_capable - helper function to determine EEE support on X550
6101 * @adapter: board private structure
6103 static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter)
6105 struct ixgbe_hw *hw = &adapter->hw;
6107 switch (hw->device_id) {
6108 case IXGBE_DEV_ID_X550EM_A_1G_T:
6109 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
6110 if (!hw->phy.eee_speeds_supported)
6112 adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE;
6113 if (!hw->phy.eee_speeds_advertised)
6115 adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
6118 adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE;
6119 adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
6125 * ixgbe_tx_timeout - Respond to a Tx Hang
6126 * @netdev: network interface device structure
6128 static void ixgbe_tx_timeout(struct net_device *netdev)
6130 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6132 /* Do the reset outside of interrupt context */
6133 ixgbe_tx_timeout_reset(adapter);
6136 #ifdef CONFIG_IXGBE_DCB
6137 static void ixgbe_init_dcb(struct ixgbe_adapter *adapter)
6139 struct ixgbe_hw *hw = &adapter->hw;
6140 struct tc_configuration *tc;
6143 switch (hw->mac.type) {
6144 case ixgbe_mac_82598EB:
6145 case ixgbe_mac_82599EB:
6146 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
6147 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
6149 case ixgbe_mac_X540:
6150 case ixgbe_mac_X550:
6151 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
6152 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
6154 case ixgbe_mac_X550EM_x:
6155 case ixgbe_mac_x550em_a:
6157 adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS;
6158 adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS;
6162 /* Configure DCB traffic classes */
6163 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
6164 tc = &adapter->dcb_cfg.tc_config[j];
6165 tc->path[DCB_TX_CONFIG].bwg_id = 0;
6166 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
6167 tc->path[DCB_RX_CONFIG].bwg_id = 0;
6168 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
6169 tc->dcb_pfc = pfc_disabled;
6172 /* Initialize default user to priority mapping, UPx->TC0 */
6173 tc = &adapter->dcb_cfg.tc_config[0];
6174 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
6175 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
6177 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
6178 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
6179 adapter->dcb_cfg.pfc_mode_enable = false;
6180 adapter->dcb_set_bitmap = 0x00;
6181 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
6182 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
6183 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
6184 sizeof(adapter->temp_dcb_cfg));
6189 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
6190 * @adapter: board private structure to initialize
6191 * @ii: pointer to ixgbe_info for device
6193 * ixgbe_sw_init initializes the Adapter private data structure.
6194 * Fields are initialized based on PCI device information and
6195 * OS network device settings (MTU size).
6197 static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
6198 const struct ixgbe_info *ii)
6200 struct ixgbe_hw *hw = &adapter->hw;
6201 struct pci_dev *pdev = adapter->pdev;
6202 unsigned int rss, fdir;
6206 /* PCI config space info */
6208 hw->vendor_id = pdev->vendor;
6209 hw->device_id = pdev->device;
6210 hw->revision_id = pdev->revision;
6211 hw->subsystem_vendor_id = pdev->subsystem_vendor;
6212 hw->subsystem_device_id = pdev->subsystem_device;
6214 /* get_invariants needs the device IDs */
6215 ii->get_invariants(hw);
6217 /* Set common capability flags and settings */
6218 rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
6219 adapter->ring_feature[RING_F_RSS].limit = rss;
6220 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
6221 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
6222 adapter->atr_sample_rate = 20;
6223 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
6224 adapter->ring_feature[RING_F_FDIR].limit = fdir;
6225 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
6226 adapter->ring_feature[RING_F_VMDQ].limit = 1;
6227 #ifdef CONFIG_IXGBE_DCA
6228 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
6230 #ifdef CONFIG_IXGBE_DCB
6231 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
6232 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
6235 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
6236 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
6237 #ifdef CONFIG_IXGBE_DCB
6238 /* Default traffic class to use for FCoE */
6239 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
6240 #endif /* CONFIG_IXGBE_DCB */
6241 #endif /* IXGBE_FCOE */
6243 /* initialize static ixgbe jump table entries */
6244 adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]),
6246 if (!adapter->jump_tables[0])
6248 adapter->jump_tables[0]->mat = ixgbe_ipv4_fields;
6250 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++)
6251 adapter->jump_tables[i] = NULL;
6253 adapter->mac_table = kcalloc(hw->mac.num_rar_entries,
6254 sizeof(struct ixgbe_mac_addr),
6256 if (!adapter->mac_table)
6259 if (ixgbe_init_rss_key(adapter))
6262 /* Set MAC specific capability flags and exceptions */
6263 switch (hw->mac.type) {
6264 case ixgbe_mac_82598EB:
6265 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
6267 if (hw->device_id == IXGBE_DEV_ID_82598AT)
6268 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
6270 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
6271 adapter->ring_feature[RING_F_FDIR].limit = 0;
6272 adapter->atr_sample_rate = 0;
6273 adapter->fdir_pballoc = 0;
6275 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
6276 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
6277 #ifdef CONFIG_IXGBE_DCB
6278 adapter->fcoe.up = 0;
6279 #endif /* IXGBE_DCB */
6280 #endif /* IXGBE_FCOE */
6282 case ixgbe_mac_82599EB:
6283 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
6284 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
6286 case ixgbe_mac_X540:
6287 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
6288 if (fwsm & IXGBE_FWSM_TS_ENABLED)
6289 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
6291 case ixgbe_mac_x550em_a:
6292 adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE;
6293 switch (hw->device_id) {
6294 case IXGBE_DEV_ID_X550EM_A_1G_T:
6295 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
6296 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
6302 case ixgbe_mac_X550EM_x:
6303 #ifdef CONFIG_IXGBE_DCB
6304 adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE;
6307 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
6308 #ifdef CONFIG_IXGBE_DCB
6309 adapter->fcoe.up = 0;
6310 #endif /* IXGBE_DCB */
6311 #endif /* IXGBE_FCOE */
6313 case ixgbe_mac_X550:
6314 if (hw->mac.type == ixgbe_mac_X550)
6315 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
6316 #ifdef CONFIG_IXGBE_DCA
6317 adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
6319 adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
6326 /* FCoE support exists, always init the FCoE lock */
6327 spin_lock_init(&adapter->fcoe.lock);
6330 /* n-tuple support exists, always init our spinlock */
6331 spin_lock_init(&adapter->fdir_perfect_lock);
6333 #ifdef CONFIG_IXGBE_DCB
6334 ixgbe_init_dcb(adapter);
6336 ixgbe_init_ipsec_offload(adapter);
6338 /* default flow control settings */
6339 hw->fc.requested_mode = ixgbe_fc_full;
6340 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
6341 ixgbe_pbthresh_setup(adapter);
6342 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
6343 hw->fc.send_xon = true;
6344 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
6346 #ifdef CONFIG_PCI_IOV
6348 e_dev_warn("Enabling SR-IOV VFs using the max_vfs module parameter is deprecated - please use the pci sysfs interface instead.\n");
6350 /* assign number of SR-IOV VFs */
6351 if (hw->mac.type != ixgbe_mac_82598EB) {
6352 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
6354 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
6357 #endif /* CONFIG_PCI_IOV */
6359 /* enable itr by default in dynamic mode */
6360 adapter->rx_itr_setting = 1;
6361 adapter->tx_itr_setting = 1;
6363 /* set default ring sizes */
6364 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
6365 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
6367 /* set default work limits */
6368 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
6370 /* initialize eeprom parameters */
6371 if (ixgbe_init_eeprom_params_generic(hw)) {
6372 e_dev_err("EEPROM initialization failed\n");
6376 /* PF holds first pool slot */
6377 set_bit(0, adapter->fwd_bitmask);
6378 set_bit(__IXGBE_DOWN, &adapter->state);
6384 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
6385 * @tx_ring: tx descriptor ring (for a specific queue) to setup
6387 * Return 0 on success, negative on failure
6389 int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
6391 struct device *dev = tx_ring->dev;
6392 int orig_node = dev_to_node(dev);
6396 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
6398 if (tx_ring->q_vector)
6399 ring_node = tx_ring->q_vector->numa_node;
6401 tx_ring->tx_buffer_info = vmalloc_node(size, ring_node);
6402 if (!tx_ring->tx_buffer_info)
6403 tx_ring->tx_buffer_info = vmalloc(size);
6404 if (!tx_ring->tx_buffer_info)
6407 /* round up to nearest 4K */
6408 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
6409 tx_ring->size = ALIGN(tx_ring->size, 4096);
6411 set_dev_node(dev, ring_node);
6412 tx_ring->desc = dma_alloc_coherent(dev,
6416 set_dev_node(dev, orig_node);
6418 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
6419 &tx_ring->dma, GFP_KERNEL);
6423 tx_ring->next_to_use = 0;
6424 tx_ring->next_to_clean = 0;
6428 vfree(tx_ring->tx_buffer_info);
6429 tx_ring->tx_buffer_info = NULL;
6430 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
6435 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
6436 * @adapter: board private structure
6438 * If this function returns with an error, then it's possible one or
6439 * more of the rings is populated (while the rest are not). It is the
6440 * callers duty to clean those orphaned rings.
6442 * Return 0 on success, negative on failure
6444 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
6446 int i, j = 0, err = 0;
6448 for (i = 0; i < adapter->num_tx_queues; i++) {
6449 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
6453 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
6456 for (j = 0; j < adapter->num_xdp_queues; j++) {
6457 err = ixgbe_setup_tx_resources(adapter->xdp_ring[j]);
6461 e_err(probe, "Allocation for Tx Queue %u failed\n", j);
6467 /* rewind the index freeing the rings as we go */
6469 ixgbe_free_tx_resources(adapter->xdp_ring[j]);
6471 ixgbe_free_tx_resources(adapter->tx_ring[i]);
6476 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
6477 * @adapter: pointer to ixgbe_adapter
6478 * @rx_ring: rx descriptor ring (for a specific queue) to setup
6480 * Returns 0 on success, negative on failure
6482 int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
6483 struct ixgbe_ring *rx_ring)
6485 struct device *dev = rx_ring->dev;
6486 int orig_node = dev_to_node(dev);
6490 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
6492 if (rx_ring->q_vector)
6493 ring_node = rx_ring->q_vector->numa_node;
6495 rx_ring->rx_buffer_info = vmalloc_node(size, ring_node);
6496 if (!rx_ring->rx_buffer_info)
6497 rx_ring->rx_buffer_info = vmalloc(size);
6498 if (!rx_ring->rx_buffer_info)
6501 /* Round up to nearest 4K */
6502 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
6503 rx_ring->size = ALIGN(rx_ring->size, 4096);
6505 set_dev_node(dev, ring_node);
6506 rx_ring->desc = dma_alloc_coherent(dev,
6510 set_dev_node(dev, orig_node);
6512 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
6513 &rx_ring->dma, GFP_KERNEL);
6517 rx_ring->next_to_clean = 0;
6518 rx_ring->next_to_use = 0;
6520 /* XDP RX-queue info */
6521 if (xdp_rxq_info_reg(&rx_ring->xdp_rxq, adapter->netdev,
6522 rx_ring->queue_index) < 0)
6525 err = xdp_rxq_info_reg_mem_model(&rx_ring->xdp_rxq,
6526 MEM_TYPE_PAGE_SHARED, NULL);
6528 xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
6532 rx_ring->xdp_prog = adapter->xdp_prog;
6536 vfree(rx_ring->rx_buffer_info);
6537 rx_ring->rx_buffer_info = NULL;
6538 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
6543 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
6544 * @adapter: board private structure
6546 * If this function returns with an error, then it's possible one or
6547 * more of the rings is populated (while the rest are not). It is the
6548 * callers duty to clean those orphaned rings.
6550 * Return 0 on success, negative on failure
6552 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
6556 for (i = 0; i < adapter->num_rx_queues; i++) {
6557 err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]);
6561 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
6566 err = ixgbe_setup_fcoe_ddp_resources(adapter);
6571 /* rewind the index freeing the rings as we go */
6573 ixgbe_free_rx_resources(adapter->rx_ring[i]);
6578 * ixgbe_free_tx_resources - Free Tx Resources per Queue
6579 * @tx_ring: Tx descriptor ring for a specific queue
6581 * Free all transmit software resources
6583 void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
6585 ixgbe_clean_tx_ring(tx_ring);
6587 vfree(tx_ring->tx_buffer_info);
6588 tx_ring->tx_buffer_info = NULL;
6590 /* if not set, then don't free */
6594 dma_free_coherent(tx_ring->dev, tx_ring->size,
6595 tx_ring->desc, tx_ring->dma);
6597 tx_ring->desc = NULL;
6601 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
6602 * @adapter: board private structure
6604 * Free all transmit software resources
6606 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
6610 for (i = 0; i < adapter->num_tx_queues; i++)
6611 if (adapter->tx_ring[i]->desc)
6612 ixgbe_free_tx_resources(adapter->tx_ring[i]);
6613 for (i = 0; i < adapter->num_xdp_queues; i++)
6614 if (adapter->xdp_ring[i]->desc)
6615 ixgbe_free_tx_resources(adapter->xdp_ring[i]);
6619 * ixgbe_free_rx_resources - Free Rx Resources
6620 * @rx_ring: ring to clean the resources from
6622 * Free all receive software resources
6624 void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
6626 ixgbe_clean_rx_ring(rx_ring);
6628 rx_ring->xdp_prog = NULL;
6629 xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
6630 vfree(rx_ring->rx_buffer_info);
6631 rx_ring->rx_buffer_info = NULL;
6633 /* if not set, then don't free */
6637 dma_free_coherent(rx_ring->dev, rx_ring->size,
6638 rx_ring->desc, rx_ring->dma);
6640 rx_ring->desc = NULL;
6644 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
6645 * @adapter: board private structure
6647 * Free all receive software resources
6649 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
6654 ixgbe_free_fcoe_ddp_resources(adapter);
6657 for (i = 0; i < adapter->num_rx_queues; i++)
6658 if (adapter->rx_ring[i]->desc)
6659 ixgbe_free_rx_resources(adapter->rx_ring[i]);
6663 * ixgbe_change_mtu - Change the Maximum Transfer Unit
6664 * @netdev: network interface device structure
6665 * @new_mtu: new value for maximum frame size
6667 * Returns 0 on success, negative on failure
6669 static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
6671 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6673 if (adapter->xdp_prog) {
6674 int new_frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN +
6678 for (i = 0; i < adapter->num_rx_queues; i++) {
6679 struct ixgbe_ring *ring = adapter->rx_ring[i];
6681 if (new_frame_size > ixgbe_rx_bufsz(ring)) {
6682 e_warn(probe, "Requested MTU size is not supported with XDP\n");
6689 * For 82599EB we cannot allow legacy VFs to enable their receive
6690 * paths when MTU greater than 1500 is configured. So display a
6691 * warning that legacy VFs will be disabled.
6693 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
6694 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
6695 (new_mtu > ETH_DATA_LEN))
6696 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
6698 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
6700 /* must set new MTU before calling down or up */
6701 netdev->mtu = new_mtu;
6703 if (netif_running(netdev))
6704 ixgbe_reinit_locked(adapter);
6710 * ixgbe_open - Called when a network interface is made active
6711 * @netdev: network interface device structure
6713 * Returns 0 on success, negative value on failure
6715 * The open entry point is called when a network interface is made
6716 * active by the system (IFF_UP). At this point all resources needed
6717 * for transmit and receive operations are allocated, the interrupt
6718 * handler is registered with the OS, the watchdog timer is started,
6719 * and the stack is notified that the interface is ready.
6721 int ixgbe_open(struct net_device *netdev)
6723 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6724 struct ixgbe_hw *hw = &adapter->hw;
6727 /* disallow open during test */
6728 if (test_bit(__IXGBE_TESTING, &adapter->state))
6731 netif_carrier_off(netdev);
6733 /* allocate transmit descriptors */
6734 err = ixgbe_setup_all_tx_resources(adapter);
6738 /* allocate receive descriptors */
6739 err = ixgbe_setup_all_rx_resources(adapter);
6743 ixgbe_configure(adapter);
6745 err = ixgbe_request_irq(adapter);
6749 /* Notify the stack of the actual queue counts. */
6750 queues = adapter->num_tx_queues;
6751 err = netif_set_real_num_tx_queues(netdev, queues);
6753 goto err_set_queues;
6755 queues = adapter->num_rx_queues;
6756 err = netif_set_real_num_rx_queues(netdev, queues);
6758 goto err_set_queues;
6760 ixgbe_ptp_init(adapter);
6762 ixgbe_up_complete(adapter);
6764 ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK);
6765 udp_tunnel_get_rx_info(netdev);
6770 ixgbe_free_irq(adapter);
6772 ixgbe_free_all_rx_resources(adapter);
6773 if (hw->phy.ops.set_phy_power && !adapter->wol)
6774 hw->phy.ops.set_phy_power(&adapter->hw, false);
6776 ixgbe_free_all_tx_resources(adapter);
6778 ixgbe_reset(adapter);
6783 static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
6785 ixgbe_ptp_suspend(adapter);
6787 if (adapter->hw.phy.ops.enter_lplu) {
6788 adapter->hw.phy.reset_disable = true;
6789 ixgbe_down(adapter);
6790 adapter->hw.phy.ops.enter_lplu(&adapter->hw);
6791 adapter->hw.phy.reset_disable = false;
6793 ixgbe_down(adapter);
6796 ixgbe_free_irq(adapter);
6798 ixgbe_free_all_tx_resources(adapter);
6799 ixgbe_free_all_rx_resources(adapter);
6803 * ixgbe_close - Disables a network interface
6804 * @netdev: network interface device structure
6806 * Returns 0, this is not allowed to fail
6808 * The close entry point is called when an interface is de-activated
6809 * by the OS. The hardware is still under the drivers control, but
6810 * needs to be disabled. A global MAC reset is issued to stop the
6811 * hardware, and all transmit and receive resources are freed.
6813 int ixgbe_close(struct net_device *netdev)
6815 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6817 ixgbe_ptp_stop(adapter);
6819 if (netif_device_present(netdev))
6820 ixgbe_close_suspend(adapter);
6822 ixgbe_fdir_filter_exit(adapter);
6824 ixgbe_release_hw_control(adapter);
6830 static int ixgbe_resume(struct pci_dev *pdev)
6832 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6833 struct net_device *netdev = adapter->netdev;
6836 adapter->hw.hw_addr = adapter->io_addr;
6837 pci_set_power_state(pdev, PCI_D0);
6838 pci_restore_state(pdev);
6840 * pci_restore_state clears dev->state_saved so call
6841 * pci_save_state to restore it.
6843 pci_save_state(pdev);
6845 err = pci_enable_device_mem(pdev);
6847 e_dev_err("Cannot enable PCI device from suspend\n");
6850 smp_mb__before_atomic();
6851 clear_bit(__IXGBE_DISABLED, &adapter->state);
6852 pci_set_master(pdev);
6854 pci_wake_from_d3(pdev, false);
6856 ixgbe_reset(adapter);
6858 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
6861 err = ixgbe_init_interrupt_scheme(adapter);
6862 if (!err && netif_running(netdev))
6863 err = ixgbe_open(netdev);
6867 netif_device_attach(netdev);
6872 #endif /* CONFIG_PM */
6874 static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
6876 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6877 struct net_device *netdev = adapter->netdev;
6878 struct ixgbe_hw *hw = &adapter->hw;
6880 u32 wufc = adapter->wol;
6886 netif_device_detach(netdev);
6888 if (netif_running(netdev))
6889 ixgbe_close_suspend(adapter);
6891 ixgbe_clear_interrupt_scheme(adapter);
6895 retval = pci_save_state(pdev);
6900 if (hw->mac.ops.stop_link_on_d3)
6901 hw->mac.ops.stop_link_on_d3(hw);
6906 ixgbe_set_rx_mode(netdev);
6908 /* enable the optics for 82599 SFP+ fiber as we can WoL */
6909 if (hw->mac.ops.enable_tx_laser)
6910 hw->mac.ops.enable_tx_laser(hw);
6912 /* enable the reception of multicast packets */
6913 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6914 fctrl |= IXGBE_FCTRL_MPE;
6915 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
6917 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
6918 ctrl |= IXGBE_CTRL_GIO_DIS;
6919 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
6921 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
6923 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
6924 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
6927 switch (hw->mac.type) {
6928 case ixgbe_mac_82598EB:
6929 pci_wake_from_d3(pdev, false);
6931 case ixgbe_mac_82599EB:
6932 case ixgbe_mac_X540:
6933 case ixgbe_mac_X550:
6934 case ixgbe_mac_X550EM_x:
6935 case ixgbe_mac_x550em_a:
6936 pci_wake_from_d3(pdev, !!wufc);
6942 *enable_wake = !!wufc;
6943 if (hw->phy.ops.set_phy_power && !*enable_wake)
6944 hw->phy.ops.set_phy_power(hw, false);
6946 ixgbe_release_hw_control(adapter);
6948 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
6949 pci_disable_device(pdev);
6955 static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
6960 retval = __ixgbe_shutdown(pdev, &wake);
6965 pci_prepare_to_sleep(pdev);
6967 pci_wake_from_d3(pdev, false);
6968 pci_set_power_state(pdev, PCI_D3hot);
6973 #endif /* CONFIG_PM */
6975 static void ixgbe_shutdown(struct pci_dev *pdev)
6979 __ixgbe_shutdown(pdev, &wake);
6981 if (system_state == SYSTEM_POWER_OFF) {
6982 pci_wake_from_d3(pdev, wake);
6983 pci_set_power_state(pdev, PCI_D3hot);
6988 * ixgbe_update_stats - Update the board statistics counters.
6989 * @adapter: board private structure
6991 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
6993 struct net_device *netdev = adapter->netdev;
6994 struct ixgbe_hw *hw = &adapter->hw;
6995 struct ixgbe_hw_stats *hwstats = &adapter->stats;
6997 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
6998 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
6999 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
7000 u64 alloc_rx_page = 0;
7001 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
7003 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
7004 test_bit(__IXGBE_RESETTING, &adapter->state))
7007 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
7010 for (i = 0; i < adapter->num_rx_queues; i++) {
7011 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
7012 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
7014 adapter->rsc_total_count = rsc_count;
7015 adapter->rsc_total_flush = rsc_flush;
7018 for (i = 0; i < adapter->num_rx_queues; i++) {
7019 struct ixgbe_ring *rx_ring = READ_ONCE(adapter->rx_ring[i]);
7023 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
7024 alloc_rx_page += rx_ring->rx_stats.alloc_rx_page;
7025 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
7026 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
7027 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
7028 bytes += rx_ring->stats.bytes;
7029 packets += rx_ring->stats.packets;
7031 adapter->non_eop_descs = non_eop_descs;
7032 adapter->alloc_rx_page = alloc_rx_page;
7033 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
7034 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
7035 adapter->hw_csum_rx_error = hw_csum_rx_error;
7036 netdev->stats.rx_bytes = bytes;
7037 netdev->stats.rx_packets = packets;
7041 /* gather some stats to the adapter struct that are per queue */
7042 for (i = 0; i < adapter->num_tx_queues; i++) {
7043 struct ixgbe_ring *tx_ring = READ_ONCE(adapter->tx_ring[i]);
7047 restart_queue += tx_ring->tx_stats.restart_queue;
7048 tx_busy += tx_ring->tx_stats.tx_busy;
7049 bytes += tx_ring->stats.bytes;
7050 packets += tx_ring->stats.packets;
7052 for (i = 0; i < adapter->num_xdp_queues; i++) {
7053 struct ixgbe_ring *xdp_ring = READ_ONCE(adapter->xdp_ring[i]);
7057 restart_queue += xdp_ring->tx_stats.restart_queue;
7058 tx_busy += xdp_ring->tx_stats.tx_busy;
7059 bytes += xdp_ring->stats.bytes;
7060 packets += xdp_ring->stats.packets;
7062 adapter->restart_queue = restart_queue;
7063 adapter->tx_busy = tx_busy;
7064 netdev->stats.tx_bytes = bytes;
7065 netdev->stats.tx_packets = packets;
7067 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
7069 /* 8 register reads */
7070 for (i = 0; i < 8; i++) {
7071 /* for packet buffers not used, the register should read 0 */
7072 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
7074 hwstats->mpc[i] += mpc;
7075 total_mpc += hwstats->mpc[i];
7076 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
7077 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
7078 switch (hw->mac.type) {
7079 case ixgbe_mac_82598EB:
7080 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
7081 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
7082 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
7083 hwstats->pxonrxc[i] +=
7084 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
7086 case ixgbe_mac_82599EB:
7087 case ixgbe_mac_X540:
7088 case ixgbe_mac_X550:
7089 case ixgbe_mac_X550EM_x:
7090 case ixgbe_mac_x550em_a:
7091 hwstats->pxonrxc[i] +=
7092 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
7099 /*16 register reads */
7100 for (i = 0; i < 16; i++) {
7101 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
7102 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
7103 if ((hw->mac.type == ixgbe_mac_82599EB) ||
7104 (hw->mac.type == ixgbe_mac_X540) ||
7105 (hw->mac.type == ixgbe_mac_X550) ||
7106 (hw->mac.type == ixgbe_mac_X550EM_x) ||
7107 (hw->mac.type == ixgbe_mac_x550em_a)) {
7108 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
7109 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
7110 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
7111 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
7115 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
7116 /* work around hardware counting issue */
7117 hwstats->gprc -= missed_rx;
7119 ixgbe_update_xoff_received(adapter);
7121 /* 82598 hardware only has a 32 bit counter in the high register */
7122 switch (hw->mac.type) {
7123 case ixgbe_mac_82598EB:
7124 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
7125 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
7126 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
7127 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
7129 case ixgbe_mac_X540:
7130 case ixgbe_mac_X550:
7131 case ixgbe_mac_X550EM_x:
7132 case ixgbe_mac_x550em_a:
7133 /* OS2BMC stats are X540 and later */
7134 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
7135 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
7136 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
7137 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
7139 case ixgbe_mac_82599EB:
7140 for (i = 0; i < 16; i++)
7141 adapter->hw_rx_no_dma_resources +=
7142 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
7143 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
7144 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
7145 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
7146 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
7147 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
7148 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
7149 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
7150 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
7151 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
7153 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
7154 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
7155 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
7156 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
7157 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
7158 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
7159 /* Add up per cpu counters for total ddp aloc fail */
7160 if (adapter->fcoe.ddp_pool) {
7161 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
7162 struct ixgbe_fcoe_ddp_pool *ddp_pool;
7164 u64 noddp = 0, noddp_ext_buff = 0;
7165 for_each_possible_cpu(cpu) {
7166 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
7167 noddp += ddp_pool->noddp;
7168 noddp_ext_buff += ddp_pool->noddp_ext_buff;
7170 hwstats->fcoe_noddp = noddp;
7171 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
7173 #endif /* IXGBE_FCOE */
7178 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
7179 hwstats->bprc += bprc;
7180 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
7181 if (hw->mac.type == ixgbe_mac_82598EB)
7182 hwstats->mprc -= bprc;
7183 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
7184 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
7185 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
7186 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
7187 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
7188 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
7189 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
7190 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
7191 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
7192 hwstats->lxontxc += lxon;
7193 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
7194 hwstats->lxofftxc += lxoff;
7195 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
7196 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
7198 * 82598 errata - tx of flow control packets is included in tx counters
7200 xon_off_tot = lxon + lxoff;
7201 hwstats->gptc -= xon_off_tot;
7202 hwstats->mptc -= xon_off_tot;
7203 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
7204 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
7205 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
7206 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
7207 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
7208 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
7209 hwstats->ptc64 -= xon_off_tot;
7210 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
7211 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
7212 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
7213 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
7214 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
7215 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
7217 /* Fill out the OS statistics structure */
7218 netdev->stats.multicast = hwstats->mprc;
7221 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
7222 netdev->stats.rx_dropped = 0;
7223 netdev->stats.rx_length_errors = hwstats->rlec;
7224 netdev->stats.rx_crc_errors = hwstats->crcerrs;
7225 netdev->stats.rx_missed_errors = total_mpc;
7229 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
7230 * @adapter: pointer to the device adapter structure
7232 static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
7234 struct ixgbe_hw *hw = &adapter->hw;
7237 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
7240 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
7242 /* if interface is down do nothing */
7243 if (test_bit(__IXGBE_DOWN, &adapter->state))
7246 /* do nothing if we are not using signature filters */
7247 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
7250 adapter->fdir_overflow++;
7252 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
7253 for (i = 0; i < adapter->num_tx_queues; i++)
7254 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
7255 &(adapter->tx_ring[i]->state));
7256 for (i = 0; i < adapter->num_xdp_queues; i++)
7257 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
7258 &adapter->xdp_ring[i]->state);
7259 /* re-enable flow director interrupts */
7260 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
7262 e_err(probe, "failed to finish FDIR re-initialization, "
7263 "ignored adding FDIR ATR filters\n");
7268 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
7269 * @adapter: pointer to the device adapter structure
7271 * This function serves two purposes. First it strobes the interrupt lines
7272 * in order to make certain interrupts are occurring. Secondly it sets the
7273 * bits needed to check for TX hangs. As a result we should immediately
7274 * determine if a hang has occurred.
7276 static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
7278 struct ixgbe_hw *hw = &adapter->hw;
7282 /* If we're down, removing or resetting, just bail */
7283 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
7284 test_bit(__IXGBE_REMOVING, &adapter->state) ||
7285 test_bit(__IXGBE_RESETTING, &adapter->state))
7288 /* Force detection of hung controller */
7289 if (netif_carrier_ok(adapter->netdev)) {
7290 for (i = 0; i < adapter->num_tx_queues; i++)
7291 set_check_for_tx_hang(adapter->tx_ring[i]);
7292 for (i = 0; i < adapter->num_xdp_queues; i++)
7293 set_check_for_tx_hang(adapter->xdp_ring[i]);
7296 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
7298 * for legacy and MSI interrupts don't set any bits
7299 * that are enabled for EIAM, because this operation
7300 * would set *both* EIMS and EICS for any bit in EIAM
7302 IXGBE_WRITE_REG(hw, IXGBE_EICS,
7303 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
7305 /* get one bit for every active tx/rx interrupt vector */
7306 for (i = 0; i < adapter->num_q_vectors; i++) {
7307 struct ixgbe_q_vector *qv = adapter->q_vector[i];
7308 if (qv->rx.ring || qv->tx.ring)
7313 /* Cause software interrupt to ensure rings are cleaned */
7314 ixgbe_irq_rearm_queues(adapter, eics);
7318 * ixgbe_watchdog_update_link - update the link status
7319 * @adapter: pointer to the device adapter structure
7321 static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
7323 struct ixgbe_hw *hw = &adapter->hw;
7324 u32 link_speed = adapter->link_speed;
7325 bool link_up = adapter->link_up;
7326 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
7328 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
7331 if (hw->mac.ops.check_link) {
7332 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
7334 /* always assume link is up, if no check link function */
7335 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
7339 if (adapter->ixgbe_ieee_pfc)
7340 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
7342 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
7343 hw->mac.ops.fc_enable(hw);
7344 ixgbe_set_rx_drop_en(adapter);
7348 time_after(jiffies, (adapter->link_check_timeout +
7349 IXGBE_TRY_LINK_TIMEOUT))) {
7350 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
7351 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
7352 IXGBE_WRITE_FLUSH(hw);
7355 adapter->link_up = link_up;
7356 adapter->link_speed = link_speed;
7359 static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
7361 #ifdef CONFIG_IXGBE_DCB
7362 struct net_device *netdev = adapter->netdev;
7363 struct dcb_app app = {
7364 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
7369 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
7370 up = dcb_ieee_getapp_mask(netdev, &app);
7372 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
7377 * ixgbe_watchdog_link_is_up - update netif_carrier status and
7378 * print link up message
7379 * @adapter: pointer to the device adapter structure
7381 static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
7383 struct net_device *netdev = adapter->netdev;
7384 struct ixgbe_hw *hw = &adapter->hw;
7385 u32 link_speed = adapter->link_speed;
7386 const char *speed_str;
7387 bool flow_rx, flow_tx;
7389 /* only continue if link was previously down */
7390 if (netif_carrier_ok(netdev))
7393 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
7395 switch (hw->mac.type) {
7396 case ixgbe_mac_82598EB: {
7397 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
7398 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
7399 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
7400 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
7403 case ixgbe_mac_X540:
7404 case ixgbe_mac_X550:
7405 case ixgbe_mac_X550EM_x:
7406 case ixgbe_mac_x550em_a:
7407 case ixgbe_mac_82599EB: {
7408 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
7409 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
7410 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
7411 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
7420 adapter->last_rx_ptp_check = jiffies;
7422 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
7423 ixgbe_ptp_start_cyclecounter(adapter);
7425 switch (link_speed) {
7426 case IXGBE_LINK_SPEED_10GB_FULL:
7427 speed_str = "10 Gbps";
7429 case IXGBE_LINK_SPEED_5GB_FULL:
7430 speed_str = "5 Gbps";
7432 case IXGBE_LINK_SPEED_2_5GB_FULL:
7433 speed_str = "2.5 Gbps";
7435 case IXGBE_LINK_SPEED_1GB_FULL:
7436 speed_str = "1 Gbps";
7438 case IXGBE_LINK_SPEED_100_FULL:
7439 speed_str = "100 Mbps";
7441 case IXGBE_LINK_SPEED_10_FULL:
7442 speed_str = "10 Mbps";
7445 speed_str = "unknown speed";
7448 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
7449 ((flow_rx && flow_tx) ? "RX/TX" :
7451 (flow_tx ? "TX" : "None"))));
7453 netif_carrier_on(netdev);
7454 ixgbe_check_vf_rate_limit(adapter);
7456 /* enable transmits */
7457 netif_tx_wake_all_queues(adapter->netdev);
7459 /* update the default user priority for VFs */
7460 ixgbe_update_default_up(adapter);
7462 /* ping all the active vfs to let them know link has changed */
7463 ixgbe_ping_all_vfs(adapter);
7467 * ixgbe_watchdog_link_is_down - update netif_carrier status and
7468 * print link down message
7469 * @adapter: pointer to the adapter structure
7471 static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
7473 struct net_device *netdev = adapter->netdev;
7474 struct ixgbe_hw *hw = &adapter->hw;
7476 adapter->link_up = false;
7477 adapter->link_speed = 0;
7479 /* only continue if link was up previously */
7480 if (!netif_carrier_ok(netdev))
7483 /* poll for SFP+ cable when link is down */
7484 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
7485 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
7487 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
7488 ixgbe_ptp_start_cyclecounter(adapter);
7490 e_info(drv, "NIC Link is Down\n");
7491 netif_carrier_off(netdev);
7493 /* ping all the active vfs to let them know link has changed */
7494 ixgbe_ping_all_vfs(adapter);
7497 static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
7501 for (i = 0; i < adapter->num_tx_queues; i++) {
7502 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
7504 if (tx_ring->next_to_use != tx_ring->next_to_clean)
7508 for (i = 0; i < adapter->num_xdp_queues; i++) {
7509 struct ixgbe_ring *ring = adapter->xdp_ring[i];
7511 if (ring->next_to_use != ring->next_to_clean)
7518 static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
7520 struct ixgbe_hw *hw = &adapter->hw;
7521 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
7522 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
7526 if (!adapter->num_vfs)
7529 /* resetting the PF is only needed for MAC before X550 */
7530 if (hw->mac.type >= ixgbe_mac_X550)
7533 for (i = 0; i < adapter->num_vfs; i++) {
7534 for (j = 0; j < q_per_pool; j++) {
7537 h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
7538 t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
7549 * ixgbe_watchdog_flush_tx - flush queues on link down
7550 * @adapter: pointer to the device adapter structure
7552 static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
7554 if (!netif_carrier_ok(adapter->netdev)) {
7555 if (ixgbe_ring_tx_pending(adapter) ||
7556 ixgbe_vf_tx_pending(adapter)) {
7557 /* We've lost link, so the controller stops DMA,
7558 * but we've got queued Tx work that's never going
7559 * to get done, so reset controller to flush Tx.
7560 * (Do the reset outside of interrupt context).
7562 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
7563 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
7568 #ifdef CONFIG_PCI_IOV
7569 static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
7571 struct ixgbe_hw *hw = &adapter->hw;
7572 struct pci_dev *pdev = adapter->pdev;
7576 if (!(netif_carrier_ok(adapter->netdev)))
7579 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
7580 if (gpc) /* If incrementing then no need for the check below */
7582 /* Check to see if a bad DMA write target from an errant or
7583 * malicious VF has caused a PCIe error. If so then we can
7584 * issue a VFLR to the offending VF(s) and then resume without
7585 * requesting a full slot reset.
7591 /* check status reg for all VFs owned by this PF */
7592 for (vf = 0; vf < adapter->num_vfs; ++vf) {
7593 struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
7598 pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
7599 if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
7600 status_reg & PCI_STATUS_REC_MASTER_ABORT)
7605 static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
7609 /* Do not perform spoof check for 82598 or if not in IOV mode */
7610 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7611 adapter->num_vfs == 0)
7614 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
7617 * ssvpc register is cleared on read, if zero then no
7618 * spoofed packets in the last interval.
7623 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
7626 static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
7631 ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
7634 #endif /* CONFIG_PCI_IOV */
7638 * ixgbe_watchdog_subtask - check and bring link up
7639 * @adapter: pointer to the device adapter structure
7641 static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
7643 /* if interface is down, removing or resetting, do nothing */
7644 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
7645 test_bit(__IXGBE_REMOVING, &adapter->state) ||
7646 test_bit(__IXGBE_RESETTING, &adapter->state))
7649 ixgbe_watchdog_update_link(adapter);
7651 if (adapter->link_up)
7652 ixgbe_watchdog_link_is_up(adapter);
7654 ixgbe_watchdog_link_is_down(adapter);
7656 ixgbe_check_for_bad_vf(adapter);
7657 ixgbe_spoof_check(adapter);
7658 ixgbe_update_stats(adapter);
7660 ixgbe_watchdog_flush_tx(adapter);
7664 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
7665 * @adapter: the ixgbe adapter structure
7667 static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
7669 struct ixgbe_hw *hw = &adapter->hw;
7672 /* not searching for SFP so there is nothing to do here */
7673 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
7674 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7677 if (adapter->sfp_poll_time &&
7678 time_after(adapter->sfp_poll_time, jiffies))
7679 return; /* If not yet time to poll for SFP */
7681 /* someone else is in init, wait until next service event */
7682 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7685 adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
7687 err = hw->phy.ops.identify_sfp(hw);
7688 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7691 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
7692 /* If no cable is present, then we need to reset
7693 * the next time we find a good cable. */
7694 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
7701 /* exit if reset not needed */
7702 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7705 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
7708 * A module may be identified correctly, but the EEPROM may not have
7709 * support for that module. setup_sfp() will fail in that case, so
7710 * we should not allow that module to load.
7712 if (hw->mac.type == ixgbe_mac_82598EB)
7713 err = hw->phy.ops.reset(hw);
7715 err = hw->mac.ops.setup_sfp(hw);
7717 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7720 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
7721 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
7724 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7726 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
7727 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
7728 e_dev_err("failed to initialize because an unsupported "
7729 "SFP+ module type was detected.\n");
7730 e_dev_err("Reload the driver after installing a "
7731 "supported module.\n");
7732 unregister_netdev(adapter->netdev);
7737 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
7738 * @adapter: the ixgbe adapter structure
7740 static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
7742 struct ixgbe_hw *hw = &adapter->hw;
7745 bool autoneg = false;
7747 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
7750 /* someone else is in init, wait until next service event */
7751 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7754 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
7756 hw->mac.ops.get_link_capabilities(hw, &cap_speed, &autoneg);
7758 /* advertise highest capable link speed */
7759 if (!autoneg && (cap_speed & IXGBE_LINK_SPEED_10GB_FULL))
7760 speed = IXGBE_LINK_SPEED_10GB_FULL;
7762 speed = cap_speed & (IXGBE_LINK_SPEED_10GB_FULL |
7763 IXGBE_LINK_SPEED_1GB_FULL);
7765 if (hw->mac.ops.setup_link)
7766 hw->mac.ops.setup_link(hw, speed, true);
7768 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
7769 adapter->link_check_timeout = jiffies;
7770 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7774 * ixgbe_service_timer - Timer Call-back
7775 * @t: pointer to timer_list structure
7777 static void ixgbe_service_timer(struct timer_list *t)
7779 struct ixgbe_adapter *adapter = from_timer(adapter, t, service_timer);
7780 unsigned long next_event_offset;
7782 /* poll faster when waiting for link */
7783 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
7784 next_event_offset = HZ / 10;
7786 next_event_offset = HZ * 2;
7788 /* Reset the timer */
7789 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
7791 ixgbe_service_event_schedule(adapter);
7794 static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
7796 struct ixgbe_hw *hw = &adapter->hw;
7799 if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
7802 adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
7804 if (!hw->phy.ops.handle_lasi)
7807 status = hw->phy.ops.handle_lasi(&adapter->hw);
7808 if (status != IXGBE_ERR_OVERTEMP)
7811 e_crit(drv, "%s\n", ixgbe_overheat_msg);
7814 static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
7816 if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state))
7820 /* If we're already down, removing or resetting, just bail */
7821 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
7822 test_bit(__IXGBE_REMOVING, &adapter->state) ||
7823 test_bit(__IXGBE_RESETTING, &adapter->state)) {
7828 ixgbe_dump(adapter);
7829 netdev_err(adapter->netdev, "Reset adapter\n");
7830 adapter->tx_timeout_count++;
7832 ixgbe_reinit_locked(adapter);
7837 * ixgbe_service_task - manages and runs subtasks
7838 * @work: pointer to work_struct containing our data
7840 static void ixgbe_service_task(struct work_struct *work)
7842 struct ixgbe_adapter *adapter = container_of(work,
7843 struct ixgbe_adapter,
7845 if (ixgbe_removed(adapter->hw.hw_addr)) {
7846 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
7848 ixgbe_down(adapter);
7851 ixgbe_service_event_complete(adapter);
7854 if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) {
7856 adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
7857 udp_tunnel_get_rx_info(adapter->netdev);
7860 ixgbe_reset_subtask(adapter);
7861 ixgbe_phy_interrupt_subtask(adapter);
7862 ixgbe_sfp_detection_subtask(adapter);
7863 ixgbe_sfp_link_config_subtask(adapter);
7864 ixgbe_check_overtemp_subtask(adapter);
7865 ixgbe_watchdog_subtask(adapter);
7866 ixgbe_fdir_reinit_subtask(adapter);
7867 ixgbe_check_hang_subtask(adapter);
7869 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
7870 ixgbe_ptp_overflow_check(adapter);
7871 if (adapter->flags & IXGBE_FLAG_RX_HWTSTAMP_IN_REGISTER)
7872 ixgbe_ptp_rx_hang(adapter);
7873 ixgbe_ptp_tx_hang(adapter);
7876 ixgbe_service_event_complete(adapter);
7879 static int ixgbe_tso(struct ixgbe_ring *tx_ring,
7880 struct ixgbe_tx_buffer *first,
7882 struct ixgbe_ipsec_tx_data *itd)
7884 u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
7885 struct sk_buff *skb = first->skb;
7895 u32 paylen, l4_offset;
7896 u32 fceof_saidx = 0;
7899 if (skb->ip_summed != CHECKSUM_PARTIAL)
7902 if (!skb_is_gso(skb))
7905 err = skb_cow_head(skb, 0);
7909 if (eth_p_mpls(first->protocol))
7910 ip.hdr = skb_inner_network_header(skb);
7912 ip.hdr = skb_network_header(skb);
7913 l4.hdr = skb_checksum_start(skb);
7915 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
7916 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7918 /* initialize outer IP header fields */
7919 if (ip.v4->version == 4) {
7920 unsigned char *csum_start = skb_checksum_start(skb);
7921 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
7922 int len = csum_start - trans_start;
7924 /* IP header will have to cancel out any data that
7925 * is not a part of the outer IP header, so set to
7926 * a reverse csum if needed, else init check to 0.
7928 ip.v4->check = (skb_shinfo(skb)->gso_type & SKB_GSO_PARTIAL) ?
7929 csum_fold(csum_partial(trans_start,
7931 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
7934 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7935 IXGBE_TX_FLAGS_CSUM |
7936 IXGBE_TX_FLAGS_IPV4;
7938 ip.v6->payload_len = 0;
7939 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7940 IXGBE_TX_FLAGS_CSUM;
7943 /* determine offset of inner transport header */
7944 l4_offset = l4.hdr - skb->data;
7946 /* compute length of segmentation header */
7947 *hdr_len = (l4.tcp->doff * 4) + l4_offset;
7949 /* remove payload length from inner checksum */
7950 paylen = skb->len - l4_offset;
7951 csum_replace_by_diff(&l4.tcp->check, (__force __wsum)htonl(paylen));
7953 /* update gso size and bytecount with header size */
7954 first->gso_segs = skb_shinfo(skb)->gso_segs;
7955 first->bytecount += (first->gso_segs - 1) * *hdr_len;
7957 /* mss_l4len_id: use 0 as index for TSO */
7958 mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT;
7959 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
7961 fceof_saidx |= itd->sa_idx;
7962 type_tucmd |= itd->flags | itd->trailer_len;
7964 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
7965 vlan_macip_lens = l4.hdr - ip.hdr;
7966 vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
7967 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
7969 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd,
7975 static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
7977 unsigned int offset = 0;
7979 ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
7981 return offset == skb_checksum_start_offset(skb);
7984 static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
7985 struct ixgbe_tx_buffer *first,
7986 struct ixgbe_ipsec_tx_data *itd)
7988 struct sk_buff *skb = first->skb;
7989 u32 vlan_macip_lens = 0;
7990 u32 fceof_saidx = 0;
7993 if (skb->ip_summed != CHECKSUM_PARTIAL) {
7995 if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
7996 IXGBE_TX_FLAGS_CC)))
8001 switch (skb->csum_offset) {
8002 case offsetof(struct tcphdr, check):
8003 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
8005 case offsetof(struct udphdr, check):
8007 case offsetof(struct sctphdr, checksum):
8008 /* validate that this is actually an SCTP request */
8009 if (((first->protocol == htons(ETH_P_IP)) &&
8010 (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
8011 ((first->protocol == htons(ETH_P_IPV6)) &&
8012 ixgbe_ipv6_csum_is_sctp(skb))) {
8013 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
8018 skb_checksum_help(skb);
8022 /* update TX checksum flag */
8023 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
8024 vlan_macip_lens = skb_checksum_start_offset(skb) -
8025 skb_network_offset(skb);
8027 /* vlan_macip_lens: MACLEN, VLAN tag */
8028 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
8029 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
8031 fceof_saidx |= itd->sa_idx;
8032 type_tucmd |= itd->flags | itd->trailer_len;
8034 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd, 0);
8037 #define IXGBE_SET_FLAG(_input, _flag, _result) \
8038 ((_flag <= _result) ? \
8039 ((u32)(_input & _flag) * (_result / _flag)) : \
8040 ((u32)(_input & _flag) / (_flag / _result)))
8042 static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
8044 /* set type for advanced descriptor with frame checksum insertion */
8045 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
8046 IXGBE_ADVTXD_DCMD_DEXT |
8047 IXGBE_ADVTXD_DCMD_IFCS;
8049 /* set HW vlan bit if vlan is present */
8050 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
8051 IXGBE_ADVTXD_DCMD_VLE);
8053 /* set segmentation enable bits for TSO/FSO */
8054 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
8055 IXGBE_ADVTXD_DCMD_TSE);
8057 /* set timestamp bit if present */
8058 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
8059 IXGBE_ADVTXD_MAC_TSTAMP);
8061 /* insert frame checksum */
8062 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
8067 static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
8068 u32 tx_flags, unsigned int paylen)
8070 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
8072 /* enable L4 checksum for TSO and TX checksum offload */
8073 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
8074 IXGBE_TX_FLAGS_CSUM,
8075 IXGBE_ADVTXD_POPTS_TXSM);
8077 /* enable IPv4 checksum for TSO */
8078 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
8079 IXGBE_TX_FLAGS_IPV4,
8080 IXGBE_ADVTXD_POPTS_IXSM);
8083 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
8084 IXGBE_TX_FLAGS_IPSEC,
8085 IXGBE_ADVTXD_POPTS_IPSEC);
8088 * Check Context must be set if Tx switch is enabled, which it
8089 * always is for case where virtual functions are running
8091 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
8095 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
8098 static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
8100 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
8102 /* Herbert's original patch had:
8103 * smp_mb__after_netif_stop_queue();
8104 * but since that doesn't exist yet, just open code it.
8108 /* We need to check again in a case another CPU has just
8109 * made room available.
8111 if (likely(ixgbe_desc_unused(tx_ring) < size))
8114 /* A reprieve! - use start_queue because it doesn't call schedule */
8115 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
8116 ++tx_ring->tx_stats.restart_queue;
8120 static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
8122 if (likely(ixgbe_desc_unused(tx_ring) >= size))
8125 return __ixgbe_maybe_stop_tx(tx_ring, size);
8128 #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
8131 static int ixgbe_tx_map(struct ixgbe_ring *tx_ring,
8132 struct ixgbe_tx_buffer *first,
8135 struct sk_buff *skb = first->skb;
8136 struct ixgbe_tx_buffer *tx_buffer;
8137 union ixgbe_adv_tx_desc *tx_desc;
8138 struct skb_frag_struct *frag;
8140 unsigned int data_len, size;
8141 u32 tx_flags = first->tx_flags;
8142 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
8143 u16 i = tx_ring->next_to_use;
8145 tx_desc = IXGBE_TX_DESC(tx_ring, i);
8147 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
8149 size = skb_headlen(skb);
8150 data_len = skb->data_len;
8153 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
8154 if (data_len < sizeof(struct fcoe_crc_eof)) {
8155 size -= sizeof(struct fcoe_crc_eof) - data_len;
8158 data_len -= sizeof(struct fcoe_crc_eof);
8163 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
8167 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
8168 if (dma_mapping_error(tx_ring->dev, dma))
8171 /* record length, and DMA address */
8172 dma_unmap_len_set(tx_buffer, len, size);
8173 dma_unmap_addr_set(tx_buffer, dma, dma);
8175 tx_desc->read.buffer_addr = cpu_to_le64(dma);
8177 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
8178 tx_desc->read.cmd_type_len =
8179 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
8183 if (i == tx_ring->count) {
8184 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
8187 tx_desc->read.olinfo_status = 0;
8189 dma += IXGBE_MAX_DATA_PER_TXD;
8190 size -= IXGBE_MAX_DATA_PER_TXD;
8192 tx_desc->read.buffer_addr = cpu_to_le64(dma);
8195 if (likely(!data_len))
8198 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
8202 if (i == tx_ring->count) {
8203 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
8206 tx_desc->read.olinfo_status = 0;
8209 size = min_t(unsigned int, data_len, skb_frag_size(frag));
8211 size = skb_frag_size(frag);
8215 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
8218 tx_buffer = &tx_ring->tx_buffer_info[i];
8221 /* write last descriptor with RS and EOP bits */
8222 cmd_type |= size | IXGBE_TXD_CMD;
8223 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
8225 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
8227 /* set the timestamp */
8228 first->time_stamp = jiffies;
8231 * Force memory writes to complete before letting h/w know there
8232 * are new descriptors to fetch. (Only applicable for weak-ordered
8233 * memory model archs, such as IA-64).
8235 * We also need this memory barrier to make certain all of the
8236 * status bits have been updated before next_to_watch is written.
8240 /* set next_to_watch value indicating a packet is present */
8241 first->next_to_watch = tx_desc;
8244 if (i == tx_ring->count)
8247 tx_ring->next_to_use = i;
8249 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
8251 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
8252 writel(i, tx_ring->tail);
8254 /* we need this if more than one processor can write to our tail
8255 * at a time, it synchronizes IO on IA64/Altix systems
8262 dev_err(tx_ring->dev, "TX DMA map failed\n");
8264 /* clear dma mappings for failed tx_buffer_info map */
8266 tx_buffer = &tx_ring->tx_buffer_info[i];
8267 if (dma_unmap_len(tx_buffer, len))
8268 dma_unmap_page(tx_ring->dev,
8269 dma_unmap_addr(tx_buffer, dma),
8270 dma_unmap_len(tx_buffer, len),
8272 dma_unmap_len_set(tx_buffer, len, 0);
8273 if (tx_buffer == first)
8276 i += tx_ring->count;
8280 dev_kfree_skb_any(first->skb);
8283 tx_ring->next_to_use = i;
8288 static void ixgbe_atr(struct ixgbe_ring *ring,
8289 struct ixgbe_tx_buffer *first)
8291 struct ixgbe_q_vector *q_vector = ring->q_vector;
8292 union ixgbe_atr_hash_dword input = { .dword = 0 };
8293 union ixgbe_atr_hash_dword common = { .dword = 0 };
8295 unsigned char *network;
8297 struct ipv6hdr *ipv6;
8301 struct sk_buff *skb;
8305 /* if ring doesn't have a interrupt vector, cannot perform ATR */
8309 /* do nothing if sampling is disabled */
8310 if (!ring->atr_sample_rate)
8315 /* currently only IPv4/IPv6 with TCP is supported */
8316 if ((first->protocol != htons(ETH_P_IP)) &&
8317 (first->protocol != htons(ETH_P_IPV6)))
8320 /* snag network header to get L4 type and address */
8322 hdr.network = skb_network_header(skb);
8323 if (unlikely(hdr.network <= skb->data))
8325 if (skb->encapsulation &&
8326 first->protocol == htons(ETH_P_IP) &&
8327 hdr.ipv4->protocol == IPPROTO_UDP) {
8328 struct ixgbe_adapter *adapter = q_vector->adapter;
8330 if (unlikely(skb_tail_pointer(skb) < hdr.network +
8334 /* verify the port is recognized as VXLAN */
8335 if (adapter->vxlan_port &&
8336 udp_hdr(skb)->dest == adapter->vxlan_port)
8337 hdr.network = skb_inner_network_header(skb);
8339 if (adapter->geneve_port &&
8340 udp_hdr(skb)->dest == adapter->geneve_port)
8341 hdr.network = skb_inner_network_header(skb);
8344 /* Make sure we have at least [minimum IPv4 header + TCP]
8345 * or [IPv6 header] bytes
8347 if (unlikely(skb_tail_pointer(skb) < hdr.network + 40))
8350 /* Currently only IPv4/IPv6 with TCP is supported */
8351 switch (hdr.ipv4->version) {
8353 /* access ihl as u8 to avoid unaligned access on ia64 */
8354 hlen = (hdr.network[0] & 0x0F) << 2;
8355 l4_proto = hdr.ipv4->protocol;
8358 hlen = hdr.network - skb->data;
8359 l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
8360 hlen -= hdr.network - skb->data;
8366 if (l4_proto != IPPROTO_TCP)
8369 if (unlikely(skb_tail_pointer(skb) < hdr.network +
8370 hlen + sizeof(struct tcphdr)))
8373 th = (struct tcphdr *)(hdr.network + hlen);
8375 /* skip this packet since the socket is closing */
8379 /* sample on all syn packets or once every atr sample count */
8380 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
8383 /* reset sample count */
8384 ring->atr_count = 0;
8386 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
8389 * src and dst are inverted, think how the receiver sees them
8391 * The input is broken into two sections, a non-compressed section
8392 * containing vm_pool, vlan_id, and flow_type. The rest of the data
8393 * is XORed together and stored in the compressed dword.
8395 input.formatted.vlan_id = vlan_id;
8398 * since src port and flex bytes occupy the same word XOR them together
8399 * and write the value to source port portion of compressed dword
8401 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
8402 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
8404 common.port.src ^= th->dest ^ first->protocol;
8405 common.port.dst ^= th->source;
8407 switch (hdr.ipv4->version) {
8409 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
8410 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
8413 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
8414 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
8415 hdr.ipv6->saddr.s6_addr32[1] ^
8416 hdr.ipv6->saddr.s6_addr32[2] ^
8417 hdr.ipv6->saddr.s6_addr32[3] ^
8418 hdr.ipv6->daddr.s6_addr32[0] ^
8419 hdr.ipv6->daddr.s6_addr32[1] ^
8420 hdr.ipv6->daddr.s6_addr32[2] ^
8421 hdr.ipv6->daddr.s6_addr32[3];
8427 if (hdr.network != skb_network_header(skb))
8428 input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
8430 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
8431 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
8432 input, common, ring->queue_index);
8436 static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
8437 struct net_device *sb_dev,
8438 select_queue_fallback_t fallback)
8440 struct ixgbe_adapter *adapter;
8441 struct ixgbe_ring_feature *f;
8445 u8 tc = netdev_get_prio_tc_map(dev, skb->priority);
8446 struct net_device *vdev = sb_dev;
8448 txq = vdev->tc_to_txq[tc].offset;
8449 txq += reciprocal_scale(skb_get_hash(skb),
8450 vdev->tc_to_txq[tc].count);
8456 * only execute the code below if protocol is FCoE
8457 * or FIP and we have FCoE enabled on the adapter
8459 switch (vlan_get_protocol(skb)) {
8460 case htons(ETH_P_FCOE):
8461 case htons(ETH_P_FIP):
8462 adapter = netdev_priv(dev);
8464 if (!sb_dev && (adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
8468 return fallback(dev, skb, sb_dev);
8471 f = &adapter->ring_feature[RING_F_FCOE];
8473 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
8476 while (txq >= f->indices)
8479 return txq + f->offset;
8483 static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
8484 struct xdp_frame *xdpf)
8486 struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
8487 struct ixgbe_tx_buffer *tx_buffer;
8488 union ixgbe_adv_tx_desc *tx_desc;
8495 if (unlikely(!ixgbe_desc_unused(ring)))
8496 return IXGBE_XDP_CONSUMED;
8498 dma = dma_map_single(ring->dev, xdpf->data, len, DMA_TO_DEVICE);
8499 if (dma_mapping_error(ring->dev, dma))
8500 return IXGBE_XDP_CONSUMED;
8502 /* record the location of the first descriptor for this packet */
8503 tx_buffer = &ring->tx_buffer_info[ring->next_to_use];
8504 tx_buffer->bytecount = len;
8505 tx_buffer->gso_segs = 1;
8506 tx_buffer->protocol = 0;
8508 i = ring->next_to_use;
8509 tx_desc = IXGBE_TX_DESC(ring, i);
8511 dma_unmap_len_set(tx_buffer, len, len);
8512 dma_unmap_addr_set(tx_buffer, dma, dma);
8513 tx_buffer->xdpf = xdpf;
8515 tx_desc->read.buffer_addr = cpu_to_le64(dma);
8517 /* put descriptor type bits */
8518 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
8519 IXGBE_ADVTXD_DCMD_DEXT |
8520 IXGBE_ADVTXD_DCMD_IFCS;
8521 cmd_type |= len | IXGBE_TXD_CMD;
8522 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
8523 tx_desc->read.olinfo_status =
8524 cpu_to_le32(len << IXGBE_ADVTXD_PAYLEN_SHIFT);
8526 /* Avoid any potential race with xdp_xmit and cleanup */
8529 /* set next_to_watch value indicating a packet is present */
8531 if (i == ring->count)
8534 tx_buffer->next_to_watch = tx_desc;
8535 ring->next_to_use = i;
8537 return IXGBE_XDP_TX;
8540 netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
8541 struct ixgbe_adapter *adapter,
8542 struct ixgbe_ring *tx_ring)
8544 struct ixgbe_tx_buffer *first;
8548 u16 count = TXD_USE_COUNT(skb_headlen(skb));
8549 struct ixgbe_ipsec_tx_data ipsec_tx = { 0 };
8550 __be16 protocol = skb->protocol;
8554 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
8555 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
8556 * + 2 desc gap to keep tail from touching head,
8557 * + 1 desc for context descriptor,
8558 * otherwise try next time
8560 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
8561 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
8563 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
8564 tx_ring->tx_stats.tx_busy++;
8565 return NETDEV_TX_BUSY;
8568 /* record the location of the first descriptor for this packet */
8569 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
8571 first->bytecount = skb->len;
8572 first->gso_segs = 1;
8574 /* if we have a HW VLAN tag being added default to the HW one */
8575 if (skb_vlan_tag_present(skb)) {
8576 tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
8577 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8578 /* else if it is a SW VLAN check the next protocol and store the tag */
8579 } else if (protocol == htons(ETH_P_8021Q)) {
8580 struct vlan_hdr *vhdr, _vhdr;
8581 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
8585 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
8586 IXGBE_TX_FLAGS_VLAN_SHIFT;
8587 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
8589 protocol = vlan_get_protocol(skb);
8591 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
8592 adapter->ptp_clock) {
8593 if (adapter->tstamp_config.tx_type == HWTSTAMP_TX_ON &&
8594 !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
8596 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
8597 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
8599 /* schedule check for Tx timestamp */
8600 adapter->ptp_tx_skb = skb_get(skb);
8601 adapter->ptp_tx_start = jiffies;
8602 schedule_work(&adapter->ptp_tx_work);
8604 adapter->tx_hwtstamp_skipped++;
8608 skb_tx_timestamp(skb);
8610 #ifdef CONFIG_PCI_IOV
8612 * Use the l2switch_enable flag - would be false if the DMA
8613 * Tx switch had been disabled.
8615 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
8616 tx_flags |= IXGBE_TX_FLAGS_CC;
8619 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
8620 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
8621 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
8622 (skb->priority != TC_PRIO_CONTROL))) {
8623 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
8624 tx_flags |= (skb->priority & 0x7) <<
8625 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
8626 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
8627 struct vlan_ethhdr *vhdr;
8629 if (skb_cow_head(skb, 0))
8631 vhdr = (struct vlan_ethhdr *)skb->data;
8632 vhdr->h_vlan_TCI = htons(tx_flags >>
8633 IXGBE_TX_FLAGS_VLAN_SHIFT);
8635 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8639 /* record initial flags and protocol */
8640 first->tx_flags = tx_flags;
8641 first->protocol = protocol;
8644 /* setup tx offload for FCoE */
8645 if ((protocol == htons(ETH_P_FCOE)) &&
8646 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
8647 tso = ixgbe_fso(tx_ring, first, &hdr_len);
8654 #endif /* IXGBE_FCOE */
8656 #ifdef CONFIG_XFRM_OFFLOAD
8657 if (xfrm_offload(skb) &&
8658 !ixgbe_ipsec_tx(tx_ring, first, &ipsec_tx))
8661 tso = ixgbe_tso(tx_ring, first, &hdr_len, &ipsec_tx);
8665 ixgbe_tx_csum(tx_ring, first, &ipsec_tx);
8667 /* add the ATR filter if ATR is on */
8668 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
8669 ixgbe_atr(tx_ring, first);
8673 #endif /* IXGBE_FCOE */
8674 if (ixgbe_tx_map(tx_ring, first, hdr_len))
8675 goto cleanup_tx_timestamp;
8677 return NETDEV_TX_OK;
8680 dev_kfree_skb_any(first->skb);
8682 cleanup_tx_timestamp:
8683 if (unlikely(tx_flags & IXGBE_TX_FLAGS_TSTAMP)) {
8684 dev_kfree_skb_any(adapter->ptp_tx_skb);
8685 adapter->ptp_tx_skb = NULL;
8686 cancel_work_sync(&adapter->ptp_tx_work);
8687 clear_bit_unlock(__IXGBE_PTP_TX_IN_PROGRESS, &adapter->state);
8690 return NETDEV_TX_OK;
8693 static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
8694 struct net_device *netdev,
8695 struct ixgbe_ring *ring)
8697 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8698 struct ixgbe_ring *tx_ring;
8701 * The minimum packet size for olinfo paylen is 17 so pad the skb
8702 * in order to meet this minimum size requirement.
8704 if (skb_put_padto(skb, 17))
8705 return NETDEV_TX_OK;
8707 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
8709 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
8712 static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
8713 struct net_device *netdev)
8715 return __ixgbe_xmit_frame(skb, netdev, NULL);
8719 * ixgbe_set_mac - Change the Ethernet Address of the NIC
8720 * @netdev: network interface device structure
8721 * @p: pointer to an address structure
8723 * Returns 0 on success, negative on failure
8725 static int ixgbe_set_mac(struct net_device *netdev, void *p)
8727 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8728 struct ixgbe_hw *hw = &adapter->hw;
8729 struct sockaddr *addr = p;
8731 if (!is_valid_ether_addr(addr->sa_data))
8732 return -EADDRNOTAVAIL;
8734 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
8735 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
8737 ixgbe_mac_set_default_filter(adapter);
8743 ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
8745 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8746 struct ixgbe_hw *hw = &adapter->hw;
8750 if (prtad != hw->phy.mdio.prtad)
8752 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
8758 static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
8759 u16 addr, u16 value)
8761 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8762 struct ixgbe_hw *hw = &adapter->hw;
8764 if (prtad != hw->phy.mdio.prtad)
8766 return hw->phy.ops.write_reg(hw, addr, devad, value);
8769 static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
8771 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8775 return ixgbe_ptp_set_ts_config(adapter, req);
8777 return ixgbe_ptp_get_ts_config(adapter, req);
8779 if (!adapter->hw.phy.ops.read_reg)
8783 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
8788 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
8790 * @dev: network interface device structure
8792 * Returns non-zero on failure
8794 static int ixgbe_add_sanmac_netdev(struct net_device *dev)
8797 struct ixgbe_adapter *adapter = netdev_priv(dev);
8798 struct ixgbe_hw *hw = &adapter->hw;
8800 if (is_valid_ether_addr(hw->mac.san_addr)) {
8802 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
8805 /* update SAN MAC vmdq pool selection */
8806 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
8812 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
8814 * @dev: network interface device structure
8816 * Returns non-zero on failure
8818 static int ixgbe_del_sanmac_netdev(struct net_device *dev)
8821 struct ixgbe_adapter *adapter = netdev_priv(dev);
8822 struct ixgbe_mac_info *mac = &adapter->hw.mac;
8824 if (is_valid_ether_addr(mac->san_addr)) {
8826 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
8832 static void ixgbe_get_ring_stats64(struct rtnl_link_stats64 *stats,
8833 struct ixgbe_ring *ring)
8840 start = u64_stats_fetch_begin_irq(&ring->syncp);
8841 packets = ring->stats.packets;
8842 bytes = ring->stats.bytes;
8843 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
8844 stats->tx_packets += packets;
8845 stats->tx_bytes += bytes;
8849 static void ixgbe_get_stats64(struct net_device *netdev,
8850 struct rtnl_link_stats64 *stats)
8852 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8856 for (i = 0; i < adapter->num_rx_queues; i++) {
8857 struct ixgbe_ring *ring = READ_ONCE(adapter->rx_ring[i]);
8863 start = u64_stats_fetch_begin_irq(&ring->syncp);
8864 packets = ring->stats.packets;
8865 bytes = ring->stats.bytes;
8866 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
8867 stats->rx_packets += packets;
8868 stats->rx_bytes += bytes;
8872 for (i = 0; i < adapter->num_tx_queues; i++) {
8873 struct ixgbe_ring *ring = READ_ONCE(adapter->tx_ring[i]);
8875 ixgbe_get_ring_stats64(stats, ring);
8877 for (i = 0; i < adapter->num_xdp_queues; i++) {
8878 struct ixgbe_ring *ring = READ_ONCE(adapter->xdp_ring[i]);
8880 ixgbe_get_ring_stats64(stats, ring);
8884 /* following stats updated by ixgbe_watchdog_task() */
8885 stats->multicast = netdev->stats.multicast;
8886 stats->rx_errors = netdev->stats.rx_errors;
8887 stats->rx_length_errors = netdev->stats.rx_length_errors;
8888 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
8889 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
8892 #ifdef CONFIG_IXGBE_DCB
8894 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
8895 * @adapter: pointer to ixgbe_adapter
8896 * @tc: number of traffic classes currently enabled
8898 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
8899 * 802.1Q priority maps to a packet buffer that exists.
8901 static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
8903 struct ixgbe_hw *hw = &adapter->hw;
8907 /* 82598 have a static priority to TC mapping that can not
8908 * be changed so no validation is needed.
8910 if (hw->mac.type == ixgbe_mac_82598EB)
8913 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
8916 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
8917 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
8919 /* If up2tc is out of bounds default to zero */
8921 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
8925 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
8931 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
8932 * @adapter: Pointer to adapter struct
8934 * Populate the netdev user priority to tc map
8936 static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
8938 struct net_device *dev = adapter->netdev;
8939 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
8940 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
8943 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
8946 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
8947 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
8949 tc = ets->prio_tc[prio];
8951 netdev_set_prio_tc_map(dev, prio, tc);
8955 #endif /* CONFIG_IXGBE_DCB */
8956 static int ixgbe_reassign_macvlan_pool(struct net_device *vdev, void *data)
8958 struct ixgbe_adapter *adapter = data;
8959 struct ixgbe_fwd_adapter *accel;
8962 /* we only care about macvlans... */
8963 if (!netif_is_macvlan(vdev))
8966 /* that have hardware offload enabled... */
8967 accel = macvlan_accel_priv(vdev);
8971 /* If we can relocate to a different bit do so */
8972 pool = find_first_zero_bit(adapter->fwd_bitmask, adapter->num_rx_pools);
8973 if (pool < adapter->num_rx_pools) {
8974 set_bit(pool, adapter->fwd_bitmask);
8979 /* if we cannot find a free pool then disable the offload */
8980 netdev_err(vdev, "L2FW offload disabled due to lack of queue resources\n");
8981 macvlan_release_l2fw_offload(vdev);
8983 /* unbind the queues and drop the subordinate channel config */
8984 netdev_unbind_sb_channel(adapter->netdev, vdev);
8985 netdev_set_sb_channel(vdev, 0);
8992 static void ixgbe_defrag_macvlan_pools(struct net_device *dev)
8994 struct ixgbe_adapter *adapter = netdev_priv(dev);
8996 /* flush any stale bits out of the fwd bitmask */
8997 bitmap_clear(adapter->fwd_bitmask, 1, 63);
8999 /* walk through upper devices reassigning pools */
9000 netdev_walk_all_upper_dev_rcu(dev, ixgbe_reassign_macvlan_pool,
9005 * ixgbe_setup_tc - configure net_device for multiple traffic classes
9007 * @dev: net device to configure
9008 * @tc: number of traffic classes to enable
9010 int ixgbe_setup_tc(struct net_device *dev, u8 tc)
9012 struct ixgbe_adapter *adapter = netdev_priv(dev);
9013 struct ixgbe_hw *hw = &adapter->hw;
9015 /* Hardware supports up to 8 traffic classes */
9016 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
9019 if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
9022 /* Hardware has to reinitialize queues and interrupts to
9023 * match packet buffer alignment. Unfortunately, the
9024 * hardware is not flexible enough to do this dynamically.
9026 if (netif_running(dev))
9029 ixgbe_reset(adapter);
9031 ixgbe_clear_interrupt_scheme(adapter);
9033 #ifdef CONFIG_IXGBE_DCB
9035 if (adapter->xdp_prog) {
9036 e_warn(probe, "DCB is not supported with XDP\n");
9038 ixgbe_init_interrupt_scheme(adapter);
9039 if (netif_running(dev))
9044 netdev_set_num_tc(dev, tc);
9045 ixgbe_set_prio_tc_map(adapter);
9047 adapter->hw_tcs = tc;
9048 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
9050 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
9051 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
9052 adapter->hw.fc.requested_mode = ixgbe_fc_none;
9055 netdev_reset_tc(dev);
9057 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
9058 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
9060 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
9061 adapter->hw_tcs = tc;
9063 adapter->temp_dcb_cfg.pfc_mode_enable = false;
9064 adapter->dcb_cfg.pfc_mode_enable = false;
9067 ixgbe_validate_rtr(adapter, tc);
9069 #endif /* CONFIG_IXGBE_DCB */
9070 ixgbe_init_interrupt_scheme(adapter);
9072 ixgbe_defrag_macvlan_pools(dev);
9074 if (netif_running(dev))
9075 return ixgbe_open(dev);
9080 static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
9081 struct tc_cls_u32_offload *cls)
9083 u32 hdl = cls->knode.handle;
9084 u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
9085 u32 loc = cls->knode.handle & 0xfffff;
9087 struct ixgbe_jump_table *jump = NULL;
9089 if (loc > IXGBE_MAX_HW_ENTRIES)
9092 if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
9095 /* Clear this filter in the link data it is associated with */
9096 if (uhtid != 0x800) {
9097 jump = adapter->jump_tables[uhtid];
9100 if (!test_bit(loc - 1, jump->child_loc_map))
9102 clear_bit(loc - 1, jump->child_loc_map);
9105 /* Check if the filter being deleted is a link */
9106 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
9107 jump = adapter->jump_tables[i];
9108 if (jump && jump->link_hdl == hdl) {
9109 /* Delete filters in the hardware in the child hash
9110 * table associated with this link
9112 for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) {
9113 if (!test_bit(j, jump->child_loc_map))
9115 spin_lock(&adapter->fdir_perfect_lock);
9116 err = ixgbe_update_ethtool_fdir_entry(adapter,
9119 spin_unlock(&adapter->fdir_perfect_lock);
9120 clear_bit(j, jump->child_loc_map);
9122 /* Remove resources for this link */
9126 adapter->jump_tables[i] = NULL;
9131 spin_lock(&adapter->fdir_perfect_lock);
9132 err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
9133 spin_unlock(&adapter->fdir_perfect_lock);
9137 static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
9138 struct tc_cls_u32_offload *cls)
9140 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
9142 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
9145 /* This ixgbe devices do not support hash tables at the moment
9146 * so abort when given hash tables.
9148 if (cls->hnode.divisor > 0)
9151 set_bit(uhtid - 1, &adapter->tables);
9155 static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
9156 struct tc_cls_u32_offload *cls)
9158 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
9160 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
9163 clear_bit(uhtid - 1, &adapter->tables);
9167 #ifdef CONFIG_NET_CLS_ACT
9168 struct upper_walk_data {
9169 struct ixgbe_adapter *adapter;
9175 static int get_macvlan_queue(struct net_device *upper, void *_data)
9177 if (netif_is_macvlan(upper)) {
9178 struct ixgbe_fwd_adapter *vadapter = macvlan_accel_priv(upper);
9179 struct upper_walk_data *data = _data;
9180 struct ixgbe_adapter *adapter = data->adapter;
9181 int ifindex = data->ifindex;
9183 if (vadapter && upper->ifindex == ifindex) {
9184 data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
9185 data->action = data->queue;
9193 static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
9194 u8 *queue, u64 *action)
9196 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
9197 unsigned int num_vfs = adapter->num_vfs, vf;
9198 struct upper_walk_data data;
9199 struct net_device *upper;
9201 /* redirect to a SRIOV VF */
9202 for (vf = 0; vf < num_vfs; ++vf) {
9203 upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
9204 if (upper->ifindex == ifindex) {
9205 *queue = vf * __ALIGN_MASK(1, ~vmdq->mask);
9207 *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
9212 /* redirect to a offloaded macvlan netdev */
9213 data.adapter = adapter;
9214 data.ifindex = ifindex;
9217 if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
9218 get_macvlan_queue, &data)) {
9219 *action = data.action;
9220 *queue = data.queue;
9228 static int parse_tc_actions(struct ixgbe_adapter *adapter,
9229 struct tcf_exts *exts, u64 *action, u8 *queue)
9231 const struct tc_action *a;
9234 if (!tcf_exts_has_actions(exts))
9237 tcf_exts_for_each_action(i, a, exts) {
9239 if (is_tcf_gact_shot(a)) {
9240 *action = IXGBE_FDIR_DROP_QUEUE;
9241 *queue = IXGBE_FDIR_DROP_QUEUE;
9245 /* Redirect to a VF or a offloaded macvlan */
9246 if (is_tcf_mirred_egress_redirect(a)) {
9247 struct net_device *dev = tcf_mirred_dev(a);
9251 return handle_redirect_action(adapter, dev->ifindex,
9261 static int parse_tc_actions(struct ixgbe_adapter *adapter,
9262 struct tcf_exts *exts, u64 *action, u8 *queue)
9266 #endif /* CONFIG_NET_CLS_ACT */
9268 static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input,
9269 union ixgbe_atr_input *mask,
9270 struct tc_cls_u32_offload *cls,
9271 struct ixgbe_mat_field *field_ptr,
9272 struct ixgbe_nexthdr *nexthdr)
9276 bool found_entry = false, found_jump_field = false;
9278 for (i = 0; i < cls->knode.sel->nkeys; i++) {
9279 off = cls->knode.sel->keys[i].off;
9280 val = cls->knode.sel->keys[i].val;
9281 m = cls->knode.sel->keys[i].mask;
9283 for (j = 0; field_ptr[j].val; j++) {
9284 if (field_ptr[j].off == off) {
9285 field_ptr[j].val(input, mask, (__force u32)val,
9287 input->filter.formatted.flow_type |=
9294 if (nexthdr->off == cls->knode.sel->keys[i].off &&
9296 (__force u32)cls->knode.sel->keys[i].val &&
9298 (__force u32)cls->knode.sel->keys[i].mask)
9299 found_jump_field = true;
9305 if (nexthdr && !found_jump_field)
9311 mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
9312 IXGBE_ATR_L4TYPE_MASK;
9314 if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
9315 mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
9320 static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
9321 struct tc_cls_u32_offload *cls)
9323 __be16 protocol = cls->common.protocol;
9324 u32 loc = cls->knode.handle & 0xfffff;
9325 struct ixgbe_hw *hw = &adapter->hw;
9326 struct ixgbe_mat_field *field_ptr;
9327 struct ixgbe_fdir_filter *input = NULL;
9328 union ixgbe_atr_input *mask = NULL;
9329 struct ixgbe_jump_table *jump = NULL;
9330 int i, err = -EINVAL;
9332 u32 uhtid, link_uhtid;
9334 uhtid = TC_U32_USERHTID(cls->knode.handle);
9335 link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
9337 /* At the moment cls_u32 jumps to network layer and skips past
9338 * L2 headers. The canonical method to match L2 frames is to use
9339 * negative values. However this is error prone at best but really
9340 * just broken because there is no way to "know" what sort of hdr
9341 * is in front of the network layer. Fix cls_u32 to support L2
9342 * headers when needed.
9344 if (protocol != htons(ETH_P_IP))
9347 if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
9348 e_err(drv, "Location out of range\n");
9352 /* cls u32 is a graph starting at root node 0x800. The driver tracks
9353 * links and also the fields used to advance the parser across each
9354 * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
9355 * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
9356 * To add support for new nodes update ixgbe_model.h parse structures
9357 * this function _should_ be generic try not to hardcode values here.
9359 if (uhtid == 0x800) {
9360 field_ptr = (adapter->jump_tables[0])->mat;
9362 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
9364 if (!adapter->jump_tables[uhtid])
9366 field_ptr = (adapter->jump_tables[uhtid])->mat;
9372 /* At this point we know the field_ptr is valid and need to either
9373 * build cls_u32 link or attach filter. Because adding a link to
9374 * a handle that does not exist is invalid and the same for adding
9375 * rules to handles that don't exist.
9379 struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
9381 if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
9384 if (!test_bit(link_uhtid - 1, &adapter->tables))
9387 /* Multiple filters as links to the same hash table are not
9388 * supported. To add a new filter with the same next header
9389 * but different match/jump conditions, create a new hash table
9392 if (adapter->jump_tables[link_uhtid] &&
9393 (adapter->jump_tables[link_uhtid])->link_hdl) {
9394 e_err(drv, "Link filter exists for link: %x\n",
9399 for (i = 0; nexthdr[i].jump; i++) {
9400 if (nexthdr[i].o != cls->knode.sel->offoff ||
9401 nexthdr[i].s != cls->knode.sel->offshift ||
9403 (__force u32)cls->knode.sel->offmask)
9406 jump = kzalloc(sizeof(*jump), GFP_KERNEL);
9409 input = kzalloc(sizeof(*input), GFP_KERNEL);
9414 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
9419 jump->input = input;
9421 jump->link_hdl = cls->knode.handle;
9423 err = ixgbe_clsu32_build_input(input, mask, cls,
9424 field_ptr, &nexthdr[i]);
9426 jump->mat = nexthdr[i].jump;
9427 adapter->jump_tables[link_uhtid] = jump;
9434 input = kzalloc(sizeof(*input), GFP_KERNEL);
9437 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
9443 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) {
9444 if ((adapter->jump_tables[uhtid])->input)
9445 memcpy(input, (adapter->jump_tables[uhtid])->input,
9447 if ((adapter->jump_tables[uhtid])->mask)
9448 memcpy(mask, (adapter->jump_tables[uhtid])->mask,
9451 /* Lookup in all child hash tables if this location is already
9452 * filled with a filter
9454 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
9455 struct ixgbe_jump_table *link = adapter->jump_tables[i];
9457 if (link && (test_bit(loc - 1, link->child_loc_map))) {
9458 e_err(drv, "Filter exists in location: %x\n",
9465 err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL);
9469 err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
9474 input->sw_idx = loc;
9476 spin_lock(&adapter->fdir_perfect_lock);
9478 if (hlist_empty(&adapter->fdir_filter_list)) {
9479 memcpy(&adapter->fdir_mask, mask, sizeof(*mask));
9480 err = ixgbe_fdir_set_input_mask_82599(hw, mask);
9482 goto err_out_w_lock;
9483 } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) {
9485 goto err_out_w_lock;
9488 ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask);
9489 err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
9490 input->sw_idx, queue);
9492 goto err_out_w_lock;
9494 ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
9495 spin_unlock(&adapter->fdir_perfect_lock);
9497 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid]))
9498 set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map);
9503 spin_unlock(&adapter->fdir_perfect_lock);
9513 static int ixgbe_setup_tc_cls_u32(struct ixgbe_adapter *adapter,
9514 struct tc_cls_u32_offload *cls_u32)
9516 switch (cls_u32->command) {
9517 case TC_CLSU32_NEW_KNODE:
9518 case TC_CLSU32_REPLACE_KNODE:
9519 return ixgbe_configure_clsu32(adapter, cls_u32);
9520 case TC_CLSU32_DELETE_KNODE:
9521 return ixgbe_delete_clsu32(adapter, cls_u32);
9522 case TC_CLSU32_NEW_HNODE:
9523 case TC_CLSU32_REPLACE_HNODE:
9524 return ixgbe_configure_clsu32_add_hnode(adapter, cls_u32);
9525 case TC_CLSU32_DELETE_HNODE:
9526 return ixgbe_configure_clsu32_del_hnode(adapter, cls_u32);
9532 static int ixgbe_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
9535 struct ixgbe_adapter *adapter = cb_priv;
9537 if (!tc_cls_can_offload_and_chain0(adapter->netdev, type_data))
9541 case TC_SETUP_CLSU32:
9542 return ixgbe_setup_tc_cls_u32(adapter, type_data);
9548 static int ixgbe_setup_tc_block(struct net_device *dev,
9549 struct tc_block_offload *f)
9551 struct ixgbe_adapter *adapter = netdev_priv(dev);
9553 if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
9556 switch (f->command) {
9558 return tcf_block_cb_register(f->block, ixgbe_setup_tc_block_cb,
9559 adapter, adapter, f->extack);
9560 case TC_BLOCK_UNBIND:
9561 tcf_block_cb_unregister(f->block, ixgbe_setup_tc_block_cb,
9569 static int ixgbe_setup_tc_mqprio(struct net_device *dev,
9570 struct tc_mqprio_qopt *mqprio)
9572 mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
9573 return ixgbe_setup_tc(dev, mqprio->num_tc);
9576 static int __ixgbe_setup_tc(struct net_device *dev, enum tc_setup_type type,
9580 case TC_SETUP_BLOCK:
9581 return ixgbe_setup_tc_block(dev, type_data);
9582 case TC_SETUP_QDISC_MQPRIO:
9583 return ixgbe_setup_tc_mqprio(dev, type_data);
9589 #ifdef CONFIG_PCI_IOV
9590 void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
9592 struct net_device *netdev = adapter->netdev;
9595 ixgbe_setup_tc(netdev, adapter->hw_tcs);
9600 void ixgbe_do_reset(struct net_device *netdev)
9602 struct ixgbe_adapter *adapter = netdev_priv(netdev);
9604 if (netif_running(netdev))
9605 ixgbe_reinit_locked(adapter);
9607 ixgbe_reset(adapter);
9610 static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
9611 netdev_features_t features)
9613 struct ixgbe_adapter *adapter = netdev_priv(netdev);
9615 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
9616 if (!(features & NETIF_F_RXCSUM))
9617 features &= ~NETIF_F_LRO;
9619 /* Turn off LRO if not RSC capable */
9620 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
9621 features &= ~NETIF_F_LRO;
9623 if (adapter->xdp_prog && (features & NETIF_F_LRO)) {
9624 e_dev_err("LRO is not supported with XDP\n");
9625 features &= ~NETIF_F_LRO;
9631 static void ixgbe_reset_l2fw_offload(struct ixgbe_adapter *adapter)
9633 int rss = min_t(int, ixgbe_max_rss_indices(adapter),
9636 /* go back to full RSS if we're not running SR-IOV */
9637 if (!adapter->ring_feature[RING_F_VMDQ].offset)
9638 adapter->flags &= ~(IXGBE_FLAG_VMDQ_ENABLED |
9639 IXGBE_FLAG_SRIOV_ENABLED);
9641 adapter->ring_feature[RING_F_RSS].limit = rss;
9642 adapter->ring_feature[RING_F_VMDQ].limit = 1;
9644 ixgbe_setup_tc(adapter->netdev, adapter->hw_tcs);
9647 static int ixgbe_set_features(struct net_device *netdev,
9648 netdev_features_t features)
9650 struct ixgbe_adapter *adapter = netdev_priv(netdev);
9651 netdev_features_t changed = netdev->features ^ features;
9652 bool need_reset = false;
9654 /* Make sure RSC matches LRO, reset if change */
9655 if (!(features & NETIF_F_LRO)) {
9656 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
9658 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
9659 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
9660 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
9661 if (adapter->rx_itr_setting == 1 ||
9662 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
9663 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
9665 } else if ((changed ^ features) & NETIF_F_LRO) {
9666 e_info(probe, "rx-usecs set too low, "
9672 * Check if Flow Director n-tuple support or hw_tc support was
9673 * enabled or disabled. If the state changed, we need to reset.
9675 if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
9676 /* turn off ATR, enable perfect filters and reset */
9677 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
9680 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
9681 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
9683 /* turn off perfect filters, enable ATR and reset */
9684 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
9687 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
9689 /* We cannot enable ATR if SR-IOV is enabled */
9690 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
9691 /* We cannot enable ATR if we have 2 or more tcs */
9692 (adapter->hw_tcs > 1) ||
9693 /* We cannot enable ATR if RSS is disabled */
9694 (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
9695 /* A sample rate of 0 indicates ATR disabled */
9696 (!adapter->atr_sample_rate))
9697 ; /* do nothing not supported */
9698 else /* otherwise supported and set the flag */
9699 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
9702 if (changed & NETIF_F_RXALL)
9705 netdev->features = features;
9707 if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
9708 if (features & NETIF_F_RXCSUM) {
9709 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9711 u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9713 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9717 if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) {
9718 if (features & NETIF_F_RXCSUM) {
9719 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9721 u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9723 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9727 if ((changed & NETIF_F_HW_L2FW_DOFFLOAD) && adapter->num_rx_pools > 1)
9728 ixgbe_reset_l2fw_offload(adapter);
9729 else if (need_reset)
9730 ixgbe_do_reset(netdev);
9731 else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
9732 NETIF_F_HW_VLAN_CTAG_FILTER))
9733 ixgbe_set_rx_mode(netdev);
9739 * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports
9740 * @dev: The port's netdev
9741 * @ti: Tunnel endpoint information
9743 static void ixgbe_add_udp_tunnel_port(struct net_device *dev,
9744 struct udp_tunnel_info *ti)
9746 struct ixgbe_adapter *adapter = netdev_priv(dev);
9747 struct ixgbe_hw *hw = &adapter->hw;
9748 __be16 port = ti->port;
9752 if (ti->sa_family != AF_INET)
9756 case UDP_TUNNEL_TYPE_VXLAN:
9757 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9760 if (adapter->vxlan_port == port)
9763 if (adapter->vxlan_port) {
9765 "VXLAN port %d set, not adding port %d\n",
9766 ntohs(adapter->vxlan_port),
9771 adapter->vxlan_port = port;
9773 case UDP_TUNNEL_TYPE_GENEVE:
9774 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9777 if (adapter->geneve_port == port)
9780 if (adapter->geneve_port) {
9782 "GENEVE port %d set, not adding port %d\n",
9783 ntohs(adapter->geneve_port),
9788 port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT;
9789 adapter->geneve_port = port;
9795 reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift;
9796 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg);
9800 * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports
9801 * @dev: The port's netdev
9802 * @ti: Tunnel endpoint information
9804 static void ixgbe_del_udp_tunnel_port(struct net_device *dev,
9805 struct udp_tunnel_info *ti)
9807 struct ixgbe_adapter *adapter = netdev_priv(dev);
9810 if (ti->type != UDP_TUNNEL_TYPE_VXLAN &&
9811 ti->type != UDP_TUNNEL_TYPE_GENEVE)
9814 if (ti->sa_family != AF_INET)
9818 case UDP_TUNNEL_TYPE_VXLAN:
9819 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9822 if (adapter->vxlan_port != ti->port) {
9823 netdev_info(dev, "VXLAN port %d not found\n",
9828 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9830 case UDP_TUNNEL_TYPE_GENEVE:
9831 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9834 if (adapter->geneve_port != ti->port) {
9835 netdev_info(dev, "GENEVE port %d not found\n",
9840 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9846 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9847 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9850 static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
9851 struct net_device *dev,
9852 const unsigned char *addr, u16 vid,
9855 /* guarantee we can provide a unique filter for the unicast address */
9856 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
9857 struct ixgbe_adapter *adapter = netdev_priv(dev);
9858 u16 pool = VMDQ_P(0);
9860 if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
9864 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
9868 * ixgbe_configure_bridge_mode - set various bridge modes
9869 * @adapter: the private structure
9870 * @mode: requested bridge mode
9872 * Configure some settings require for various bridge modes.
9874 static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
9877 struct ixgbe_hw *hw = &adapter->hw;
9878 unsigned int p, num_pools;
9882 case BRIDGE_MODE_VEPA:
9883 /* disable Tx loopback, rely on switch hairpin mode */
9884 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
9886 /* must enable Rx switching replication to allow multicast
9887 * packet reception on all VFs, and to enable source address
9890 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9891 vmdctl |= IXGBE_VT_CTL_REPLEN;
9892 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9894 /* enable Rx source address pruning. Note, this requires
9895 * replication to be enabled or else it does nothing.
9897 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9898 for (p = 0; p < num_pools; p++) {
9899 if (hw->mac.ops.set_source_address_pruning)
9900 hw->mac.ops.set_source_address_pruning(hw,
9905 case BRIDGE_MODE_VEB:
9906 /* enable Tx loopback for internal VF/PF communication */
9907 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
9908 IXGBE_PFDTXGSWC_VT_LBEN);
9910 /* disable Rx switching replication unless we have SR-IOV
9913 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9914 if (!adapter->num_vfs)
9915 vmdctl &= ~IXGBE_VT_CTL_REPLEN;
9916 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9918 /* disable Rx source address pruning, since we don't expect to
9919 * be receiving external loopback of our transmitted frames.
9921 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9922 for (p = 0; p < num_pools; p++) {
9923 if (hw->mac.ops.set_source_address_pruning)
9924 hw->mac.ops.set_source_address_pruning(hw,
9933 adapter->bridge_mode = mode;
9935 e_info(drv, "enabling bridge mode: %s\n",
9936 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
9941 static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
9942 struct nlmsghdr *nlh, u16 flags)
9944 struct ixgbe_adapter *adapter = netdev_priv(dev);
9945 struct nlattr *attr, *br_spec;
9948 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9951 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
9955 nla_for_each_nested(attr, br_spec, rem) {
9959 if (nla_type(attr) != IFLA_BRIDGE_MODE)
9962 if (nla_len(attr) < sizeof(mode))
9965 mode = nla_get_u16(attr);
9966 status = ixgbe_configure_bridge_mode(adapter, mode);
9976 static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
9977 struct net_device *dev,
9978 u32 filter_mask, int nlflags)
9980 struct ixgbe_adapter *adapter = netdev_priv(dev);
9982 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9985 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
9986 adapter->bridge_mode, 0, 0, nlflags,
9990 static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
9992 struct ixgbe_adapter *adapter = netdev_priv(pdev);
9993 struct ixgbe_fwd_adapter *accel;
9994 int tcs = adapter->hw_tcs ? : 1;
9997 if (adapter->xdp_prog) {
9998 e_warn(probe, "L2FW offload is not supported with XDP\n");
9999 return ERR_PTR(-EINVAL);
10002 /* The hardware supported by ixgbe only filters on the destination MAC
10003 * address. In order to avoid issues we only support offloading modes
10004 * where the hardware can actually provide the functionality.
10006 if (!macvlan_supports_dest_filter(vdev))
10007 return ERR_PTR(-EMEDIUMTYPE);
10009 /* We need to lock down the macvlan to be a single queue device so that
10010 * we can reuse the tc_to_txq field in the macvlan netdev to represent
10011 * the queue mapping to our netdev.
10013 if (netif_is_multiqueue(vdev))
10014 return ERR_PTR(-ERANGE);
10016 pool = find_first_zero_bit(adapter->fwd_bitmask, adapter->num_rx_pools);
10017 if (pool == adapter->num_rx_pools) {
10018 u16 used_pools = adapter->num_vfs + adapter->num_rx_pools;
10019 u16 reserved_pools;
10021 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
10022 adapter->num_rx_pools >= (MAX_TX_QUEUES / tcs)) ||
10023 adapter->num_rx_pools > IXGBE_MAX_MACVLANS)
10024 return ERR_PTR(-EBUSY);
10026 /* Hardware has a limited number of available pools. Each VF,
10027 * and the PF require a pool. Check to ensure we don't
10028 * attempt to use more then the available number of pools.
10030 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
10031 return ERR_PTR(-EBUSY);
10033 /* Enable VMDq flag so device will be set in VM mode */
10034 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED |
10035 IXGBE_FLAG_SRIOV_ENABLED;
10037 /* Try to reserve as many queues per pool as possible,
10038 * we start with the configurations that support 4 queues
10039 * per pools, followed by 2, and then by just 1 per pool.
10041 if (used_pools < 32 && adapter->num_rx_pools < 16)
10042 reserved_pools = min_t(u16,
10044 16 - adapter->num_rx_pools);
10045 else if (adapter->num_rx_pools < 32)
10046 reserved_pools = min_t(u16,
10048 32 - adapter->num_rx_pools);
10050 reserved_pools = 64 - used_pools;
10053 if (!reserved_pools)
10054 return ERR_PTR(-EBUSY);
10056 adapter->ring_feature[RING_F_VMDQ].limit += reserved_pools;
10058 /* Force reinit of ring allocation with VMDQ enabled */
10059 err = ixgbe_setup_tc(pdev, adapter->hw_tcs);
10061 return ERR_PTR(err);
10063 if (pool >= adapter->num_rx_pools)
10064 return ERR_PTR(-ENOMEM);
10067 accel = kzalloc(sizeof(*accel), GFP_KERNEL);
10069 return ERR_PTR(-ENOMEM);
10071 set_bit(pool, adapter->fwd_bitmask);
10072 netdev_set_sb_channel(vdev, pool);
10073 accel->pool = pool;
10074 accel->netdev = vdev;
10076 if (!netif_running(pdev))
10079 err = ixgbe_fwd_ring_up(adapter, accel);
10081 return ERR_PTR(err);
10086 static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
10088 struct ixgbe_fwd_adapter *accel = priv;
10089 struct ixgbe_adapter *adapter = netdev_priv(pdev);
10090 unsigned int rxbase = accel->rx_base_queue;
10093 /* delete unicast filter associated with offloaded interface */
10094 ixgbe_del_mac_filter(adapter, accel->netdev->dev_addr,
10095 VMDQ_P(accel->pool));
10097 /* Allow remaining Rx packets to get flushed out of the
10098 * Rx FIFO before we drop the netdev for the ring.
10100 usleep_range(10000, 20000);
10102 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
10103 struct ixgbe_ring *ring = adapter->rx_ring[rxbase + i];
10104 struct ixgbe_q_vector *qv = ring->q_vector;
10106 /* Make sure we aren't processing any packets and clear
10107 * netdev to shut down the ring.
10109 if (netif_running(adapter->netdev))
10110 napi_synchronize(&qv->napi);
10111 ring->netdev = NULL;
10114 /* unbind the queues and drop the subordinate channel config */
10115 netdev_unbind_sb_channel(pdev, accel->netdev);
10116 netdev_set_sb_channel(accel->netdev, 0);
10118 clear_bit(accel->pool, adapter->fwd_bitmask);
10122 #define IXGBE_MAX_MAC_HDR_LEN 127
10123 #define IXGBE_MAX_NETWORK_HDR_LEN 511
10125 static netdev_features_t
10126 ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
10127 netdev_features_t features)
10129 unsigned int network_hdr_len, mac_hdr_len;
10131 /* Make certain the headers can be described by a context descriptor */
10132 mac_hdr_len = skb_network_header(skb) - skb->data;
10133 if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN))
10134 return features & ~(NETIF_F_HW_CSUM |
10136 NETIF_F_HW_VLAN_CTAG_TX |
10140 network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
10141 if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN))
10142 return features & ~(NETIF_F_HW_CSUM |
10147 /* We can only support IPV4 TSO in tunnels if we can mangle the
10148 * inner IP ID field, so strip TSO if MANGLEID is not supported.
10149 * IPsec offoad sets skb->encapsulation but still can handle
10150 * the TSO, so it's the exception.
10152 if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID)) {
10153 #ifdef CONFIG_XFRM_OFFLOAD
10156 features &= ~NETIF_F_TSO;
10162 static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)
10164 int i, frame_size = dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
10165 struct ixgbe_adapter *adapter = netdev_priv(dev);
10166 struct bpf_prog *old_prog;
10168 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
10171 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
10174 /* verify ixgbe ring attributes are sufficient for XDP */
10175 for (i = 0; i < adapter->num_rx_queues; i++) {
10176 struct ixgbe_ring *ring = adapter->rx_ring[i];
10178 if (ring_is_rsc_enabled(ring))
10181 if (frame_size > ixgbe_rx_bufsz(ring))
10185 if (nr_cpu_ids > MAX_XDP_QUEUES)
10188 old_prog = xchg(&adapter->xdp_prog, prog);
10190 /* If transitioning XDP modes reconfigure rings */
10191 if (!!prog != !!old_prog) {
10192 int err = ixgbe_setup_tc(dev, adapter->hw_tcs);
10195 rcu_assign_pointer(adapter->xdp_prog, old_prog);
10199 for (i = 0; i < adapter->num_rx_queues; i++)
10200 (void)xchg(&adapter->rx_ring[i]->xdp_prog,
10201 adapter->xdp_prog);
10205 bpf_prog_put(old_prog);
10210 static int ixgbe_xdp(struct net_device *dev, struct netdev_bpf *xdp)
10212 struct ixgbe_adapter *adapter = netdev_priv(dev);
10214 switch (xdp->command) {
10215 case XDP_SETUP_PROG:
10216 return ixgbe_xdp_setup(dev, xdp->prog);
10217 case XDP_QUERY_PROG:
10218 xdp->prog_id = adapter->xdp_prog ?
10219 adapter->xdp_prog->aux->id : 0;
10226 static void ixgbe_xdp_ring_update_tail(struct ixgbe_ring *ring)
10228 /* Force memory writes to complete before letting h/w know there
10229 * are new descriptors to fetch.
10232 writel(ring->next_to_use, ring->tail);
10235 static int ixgbe_xdp_xmit(struct net_device *dev, int n,
10236 struct xdp_frame **frames, u32 flags)
10238 struct ixgbe_adapter *adapter = netdev_priv(dev);
10239 struct ixgbe_ring *ring;
10243 if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state)))
10246 if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
10249 /* During program transitions its possible adapter->xdp_prog is assigned
10250 * but ring has not been configured yet. In this case simply abort xmit.
10252 ring = adapter->xdp_prog ? adapter->xdp_ring[smp_processor_id()] : NULL;
10253 if (unlikely(!ring))
10256 for (i = 0; i < n; i++) {
10257 struct xdp_frame *xdpf = frames[i];
10260 err = ixgbe_xmit_xdp_ring(adapter, xdpf);
10261 if (err != IXGBE_XDP_TX) {
10262 xdp_return_frame_rx_napi(xdpf);
10267 if (unlikely(flags & XDP_XMIT_FLUSH))
10268 ixgbe_xdp_ring_update_tail(ring);
10273 static const struct net_device_ops ixgbe_netdev_ops = {
10274 .ndo_open = ixgbe_open,
10275 .ndo_stop = ixgbe_close,
10276 .ndo_start_xmit = ixgbe_xmit_frame,
10277 .ndo_set_rx_mode = ixgbe_set_rx_mode,
10278 .ndo_validate_addr = eth_validate_addr,
10279 .ndo_set_mac_address = ixgbe_set_mac,
10280 .ndo_change_mtu = ixgbe_change_mtu,
10281 .ndo_tx_timeout = ixgbe_tx_timeout,
10282 .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
10283 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
10284 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
10285 .ndo_do_ioctl = ixgbe_ioctl,
10286 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
10287 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
10288 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
10289 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
10290 .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
10291 .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
10292 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
10293 .ndo_get_stats64 = ixgbe_get_stats64,
10294 .ndo_setup_tc = __ixgbe_setup_tc,
10296 .ndo_select_queue = ixgbe_select_queue,
10297 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
10298 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
10299 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
10300 .ndo_fcoe_enable = ixgbe_fcoe_enable,
10301 .ndo_fcoe_disable = ixgbe_fcoe_disable,
10302 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
10303 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
10304 #endif /* IXGBE_FCOE */
10305 .ndo_set_features = ixgbe_set_features,
10306 .ndo_fix_features = ixgbe_fix_features,
10307 .ndo_fdb_add = ixgbe_ndo_fdb_add,
10308 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
10309 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
10310 .ndo_dfwd_add_station = ixgbe_fwd_add,
10311 .ndo_dfwd_del_station = ixgbe_fwd_del,
10312 .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port,
10313 .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port,
10314 .ndo_features_check = ixgbe_features_check,
10315 .ndo_bpf = ixgbe_xdp,
10316 .ndo_xdp_xmit = ixgbe_xdp_xmit,
10320 * ixgbe_enumerate_functions - Get the number of ports this device has
10321 * @adapter: adapter structure
10323 * This function enumerates the phsyical functions co-located on a single slot,
10324 * in order to determine how many ports a device has. This is most useful in
10325 * determining the required GT/s of PCIe bandwidth necessary for optimal
10328 static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
10330 struct pci_dev *entry, *pdev = adapter->pdev;
10333 /* Some cards can not use the generic count PCIe functions method,
10334 * because they are behind a parent switch, so we hardcode these with
10335 * the correct number of functions.
10337 if (ixgbe_pcie_from_parent(&adapter->hw))
10340 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
10341 /* don't count virtual functions */
10342 if (entry->is_virtfn)
10345 /* When the devices on the bus don't all match our device ID,
10346 * we can't reliably determine the correct number of
10347 * functions. This can occur if a function has been direct
10348 * attached to a virtual machine using VT-d, for example. In
10349 * this case, simply return -1 to indicate this.
10351 if ((entry->vendor != pdev->vendor) ||
10352 (entry->device != pdev->device))
10362 * ixgbe_wol_supported - Check whether device supports WoL
10363 * @adapter: the adapter private structure
10364 * @device_id: the device ID
10365 * @subdevice_id: the subsystem device ID
10367 * This function is used by probe and ethtool to determine
10368 * which devices have WoL support
10371 bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
10374 struct ixgbe_hw *hw = &adapter->hw;
10375 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
10377 /* WOL not supported on 82598 */
10378 if (hw->mac.type == ixgbe_mac_82598EB)
10381 /* check eeprom to see if WOL is enabled for X540 and newer */
10382 if (hw->mac.type >= ixgbe_mac_X540) {
10383 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
10384 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
10385 (hw->bus.func == 0)))
10389 /* WOL is determined based on device IDs for 82599 MACs */
10390 switch (device_id) {
10391 case IXGBE_DEV_ID_82599_SFP:
10392 /* Only these subdevices could supports WOL */
10393 switch (subdevice_id) {
10394 case IXGBE_SUBDEV_ID_82599_560FLR:
10395 case IXGBE_SUBDEV_ID_82599_LOM_SNAP6:
10396 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
10397 case IXGBE_SUBDEV_ID_82599_SFP_2OCP:
10398 /* only support first port */
10399 if (hw->bus.func != 0)
10402 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
10403 case IXGBE_SUBDEV_ID_82599_SFP:
10404 case IXGBE_SUBDEV_ID_82599_RNDC:
10405 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
10406 case IXGBE_SUBDEV_ID_82599_SFP_1OCP:
10407 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1:
10408 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2:
10412 case IXGBE_DEV_ID_82599EN_SFP:
10413 /* Only these subdevices support WOL */
10414 switch (subdevice_id) {
10415 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
10419 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
10420 /* All except this subdevice support WOL */
10421 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
10424 case IXGBE_DEV_ID_82599_KX4:
10434 * ixgbe_set_fw_version - Set FW version
10435 * @adapter: the adapter private structure
10437 * This function is used by probe and ethtool to determine the FW version to
10438 * format to display. The FW version is taken from the EEPROM/NVM.
10440 static void ixgbe_set_fw_version(struct ixgbe_adapter *adapter)
10442 struct ixgbe_hw *hw = &adapter->hw;
10443 struct ixgbe_nvm_version nvm_ver;
10445 ixgbe_get_oem_prod_version(hw, &nvm_ver);
10446 if (nvm_ver.oem_valid) {
10447 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
10448 "%x.%x.%x", nvm_ver.oem_major, nvm_ver.oem_minor,
10449 nvm_ver.oem_release);
10453 ixgbe_get_etk_id(hw, &nvm_ver);
10454 ixgbe_get_orom_version(hw, &nvm_ver);
10456 if (nvm_ver.or_valid) {
10457 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
10458 "0x%08x, %d.%d.%d", nvm_ver.etk_id, nvm_ver.or_major,
10459 nvm_ver.or_build, nvm_ver.or_patch);
10463 /* Set ETrack ID format */
10464 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
10465 "0x%08x", nvm_ver.etk_id);
10469 * ixgbe_probe - Device Initialization Routine
10470 * @pdev: PCI device information struct
10471 * @ent: entry in ixgbe_pci_tbl
10473 * Returns 0 on success, negative on failure
10475 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
10476 * The OS initialization, configuring of the adapter private structure,
10477 * and a hardware reset occur.
10479 static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
10481 struct net_device *netdev;
10482 struct ixgbe_adapter *adapter = NULL;
10483 struct ixgbe_hw *hw;
10484 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
10485 int i, err, pci_using_dac, expected_gts;
10486 unsigned int indices = MAX_TX_QUEUES;
10487 u8 part_str[IXGBE_PBANUM_LENGTH];
10488 bool disable_dev = false;
10494 /* Catch broken hardware that put the wrong VF device ID in
10495 * the PCIe SR-IOV capability.
10497 if (pdev->is_virtfn) {
10498 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
10499 pci_name(pdev), pdev->vendor, pdev->device);
10503 err = pci_enable_device_mem(pdev);
10507 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
10510 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
10512 dev_err(&pdev->dev,
10513 "No usable DMA configuration, aborting\n");
10519 err = pci_request_mem_regions(pdev, ixgbe_driver_name);
10521 dev_err(&pdev->dev,
10522 "pci_request_selected_regions failed 0x%x\n", err);
10526 pci_enable_pcie_error_reporting(pdev);
10528 pci_set_master(pdev);
10529 pci_save_state(pdev);
10531 if (ii->mac == ixgbe_mac_82598EB) {
10532 #ifdef CONFIG_IXGBE_DCB
10533 /* 8 TC w/ 4 queues per TC */
10534 indices = 4 * MAX_TRAFFIC_CLASS;
10536 indices = IXGBE_MAX_RSS_INDICES;
10540 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
10543 goto err_alloc_etherdev;
10546 SET_NETDEV_DEV(netdev, &pdev->dev);
10548 adapter = netdev_priv(netdev);
10550 adapter->netdev = netdev;
10551 adapter->pdev = pdev;
10553 hw->back = adapter;
10554 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
10556 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
10557 pci_resource_len(pdev, 0));
10558 adapter->io_addr = hw->hw_addr;
10559 if (!hw->hw_addr) {
10564 netdev->netdev_ops = &ixgbe_netdev_ops;
10565 ixgbe_set_ethtool_ops(netdev);
10566 netdev->watchdog_timeo = 5 * HZ;
10567 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
10570 hw->mac.ops = *ii->mac_ops;
10571 hw->mac.type = ii->mac;
10572 hw->mvals = ii->mvals;
10574 hw->link.ops = *ii->link_ops;
10577 hw->eeprom.ops = *ii->eeprom_ops;
10578 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
10579 if (ixgbe_removed(hw->hw_addr)) {
10583 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
10584 if (!(eec & BIT(8)))
10585 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
10588 hw->phy.ops = *ii->phy_ops;
10589 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
10590 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
10591 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
10592 hw->phy.mdio.mmds = 0;
10593 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
10594 hw->phy.mdio.dev = netdev;
10595 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
10596 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
10598 /* setup the private structure */
10599 err = ixgbe_sw_init(adapter, ii);
10603 /* Make sure the SWFW semaphore is in a valid state */
10604 if (hw->mac.ops.init_swfw_sync)
10605 hw->mac.ops.init_swfw_sync(hw);
10607 /* Make it possible the adapter to be woken up via WOL */
10608 switch (adapter->hw.mac.type) {
10609 case ixgbe_mac_82599EB:
10610 case ixgbe_mac_X540:
10611 case ixgbe_mac_X550:
10612 case ixgbe_mac_X550EM_x:
10613 case ixgbe_mac_x550em_a:
10614 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
10621 * If there is a fan on this device and it has failed log the
10624 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
10625 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
10626 if (esdp & IXGBE_ESDP_SDP1)
10627 e_crit(probe, "Fan has stopped, replace the adapter\n");
10630 if (allow_unsupported_sfp)
10631 hw->allow_unsupported_sfp = allow_unsupported_sfp;
10633 /* reset_hw fills in the perm_addr as well */
10634 hw->phy.reset_if_overtemp = true;
10635 err = hw->mac.ops.reset_hw(hw);
10636 hw->phy.reset_if_overtemp = false;
10637 ixgbe_set_eee_capable(adapter);
10638 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
10640 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
10641 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
10642 e_dev_err("Reload the driver after installing a supported module.\n");
10645 e_dev_err("HW Init failed: %d\n", err);
10649 #ifdef CONFIG_PCI_IOV
10650 /* SR-IOV not supported on the 82598 */
10651 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
10654 ixgbe_init_mbx_params_pf(hw);
10655 hw->mbx.ops = ii->mbx_ops;
10656 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
10657 ixgbe_enable_sriov(adapter, max_vfs);
10661 netdev->features = NETIF_F_SG |
10668 #define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
10669 NETIF_F_GSO_GRE_CSUM | \
10670 NETIF_F_GSO_IPXIP4 | \
10671 NETIF_F_GSO_IPXIP6 | \
10672 NETIF_F_GSO_UDP_TUNNEL | \
10673 NETIF_F_GSO_UDP_TUNNEL_CSUM)
10675 netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES;
10676 netdev->features |= NETIF_F_GSO_PARTIAL |
10677 IXGBE_GSO_PARTIAL_FEATURES;
10679 if (hw->mac.type >= ixgbe_mac_82599EB)
10680 netdev->features |= NETIF_F_SCTP_CRC;
10682 #ifdef CONFIG_XFRM_OFFLOAD
10683 #define IXGBE_ESP_FEATURES (NETIF_F_HW_ESP | \
10684 NETIF_F_HW_ESP_TX_CSUM | \
10687 if (adapter->ipsec)
10688 netdev->features |= IXGBE_ESP_FEATURES;
10690 /* copy netdev features into list of user selectable features */
10691 netdev->hw_features |= netdev->features |
10692 NETIF_F_HW_VLAN_CTAG_FILTER |
10693 NETIF_F_HW_VLAN_CTAG_RX |
10694 NETIF_F_HW_VLAN_CTAG_TX |
10696 NETIF_F_HW_L2FW_DOFFLOAD;
10698 if (hw->mac.type >= ixgbe_mac_82599EB)
10699 netdev->hw_features |= NETIF_F_NTUPLE |
10703 netdev->features |= NETIF_F_HIGHDMA;
10705 netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
10706 netdev->hw_enc_features |= netdev->vlan_features;
10707 netdev->mpls_features |= NETIF_F_SG |
10711 netdev->mpls_features |= IXGBE_GSO_PARTIAL_FEATURES;
10713 /* set this bit last since it cannot be part of vlan_features */
10714 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
10715 NETIF_F_HW_VLAN_CTAG_RX |
10716 NETIF_F_HW_VLAN_CTAG_TX;
10718 netdev->priv_flags |= IFF_UNICAST_FLT;
10719 netdev->priv_flags |= IFF_SUPP_NOFCS;
10721 /* MTU range: 68 - 9710 */
10722 netdev->min_mtu = ETH_MIN_MTU;
10723 netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
10725 #ifdef CONFIG_IXGBE_DCB
10726 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
10727 netdev->dcbnl_ops = &ixgbe_dcbnl_ops;
10731 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
10732 unsigned int fcoe_l;
10734 if (hw->mac.ops.get_device_caps) {
10735 hw->mac.ops.get_device_caps(hw, &device_caps);
10736 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
10737 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
10741 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
10742 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
10744 netdev->features |= NETIF_F_FSO |
10747 netdev->vlan_features |= NETIF_F_FSO |
10751 #endif /* IXGBE_FCOE */
10752 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
10753 netdev->hw_features |= NETIF_F_LRO;
10754 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
10755 netdev->features |= NETIF_F_LRO;
10757 /* make sure the EEPROM is good */
10758 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
10759 e_dev_err("The EEPROM Checksum Is Not Valid\n");
10764 eth_platform_get_mac_address(&adapter->pdev->dev,
10765 adapter->hw.mac.perm_addr);
10767 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
10769 if (!is_valid_ether_addr(netdev->dev_addr)) {
10770 e_dev_err("invalid MAC address\n");
10775 /* Set hw->mac.addr to permanent MAC address */
10776 ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
10777 ixgbe_mac_set_default_filter(adapter);
10779 timer_setup(&adapter->service_timer, ixgbe_service_timer, 0);
10781 if (ixgbe_removed(hw->hw_addr)) {
10785 INIT_WORK(&adapter->service_task, ixgbe_service_task);
10786 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
10787 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
10789 err = ixgbe_init_interrupt_scheme(adapter);
10793 for (i = 0; i < adapter->num_rx_queues; i++)
10794 u64_stats_init(&adapter->rx_ring[i]->syncp);
10795 for (i = 0; i < adapter->num_tx_queues; i++)
10796 u64_stats_init(&adapter->tx_ring[i]->syncp);
10797 for (i = 0; i < adapter->num_xdp_queues; i++)
10798 u64_stats_init(&adapter->xdp_ring[i]->syncp);
10800 /* WOL not supported for all devices */
10802 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
10803 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
10804 pdev->subsystem_device);
10805 if (hw->wol_enabled)
10806 adapter->wol = IXGBE_WUFC_MAG;
10808 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
10810 /* save off EEPROM version number */
10811 ixgbe_set_fw_version(adapter);
10813 /* pick up the PCI bus settings for reporting later */
10814 if (ixgbe_pcie_from_parent(hw))
10815 ixgbe_get_parent_bus_info(adapter);
10817 hw->mac.ops.get_bus_info(hw);
10819 /* calculate the expected PCIe bandwidth required for optimal
10820 * performance. Note that some older parts will never have enough
10821 * bandwidth due to being older generation PCIe parts. We clamp these
10822 * parts to ensure no warning is displayed if it can't be fixed.
10824 switch (hw->mac.type) {
10825 case ixgbe_mac_82598EB:
10826 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
10829 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
10833 /* don't check link if we failed to enumerate functions */
10834 if (expected_gts > 0)
10835 ixgbe_check_minimum_link(adapter, expected_gts);
10837 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
10839 strlcpy(part_str, "Unknown", sizeof(part_str));
10840 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
10841 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
10842 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
10845 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
10846 hw->mac.type, hw->phy.type, part_str);
10848 e_dev_info("%pM\n", netdev->dev_addr);
10850 /* reset the hardware with the new settings */
10851 err = hw->mac.ops.start_hw(hw);
10852 if (err == IXGBE_ERR_EEPROM_VERSION) {
10853 /* We are running on a pre-production device, log a warning */
10854 e_dev_warn("This device is a pre-production adapter/LOM. "
10855 "Please be aware there may be issues associated "
10856 "with your hardware. If you are experiencing "
10857 "problems please contact your Intel or hardware "
10858 "representative who provided you with this "
10861 strcpy(netdev->name, "eth%d");
10862 pci_set_drvdata(pdev, adapter);
10863 err = register_netdev(netdev);
10868 /* power down the optics for 82599 SFP+ fiber */
10869 if (hw->mac.ops.disable_tx_laser)
10870 hw->mac.ops.disable_tx_laser(hw);
10872 /* carrier off reporting is important to ethtool even BEFORE open */
10873 netif_carrier_off(netdev);
10875 #ifdef CONFIG_IXGBE_DCA
10876 if (dca_add_requester(&pdev->dev) == 0) {
10877 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
10878 ixgbe_setup_dca(adapter);
10881 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
10882 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
10883 for (i = 0; i < adapter->num_vfs; i++)
10884 ixgbe_vf_configuration(pdev, (i | 0x10000000));
10887 /* firmware requires driver version to be 0xFFFFFFFF
10888 * since os does not support feature
10890 if (hw->mac.ops.set_fw_drv_ver)
10891 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF,
10892 sizeof(ixgbe_driver_version) - 1,
10893 ixgbe_driver_version);
10895 /* add san mac addr to netdev */
10896 ixgbe_add_sanmac_netdev(netdev);
10898 e_dev_info("%s\n", ixgbe_default_device_descr);
10900 #ifdef CONFIG_IXGBE_HWMON
10901 if (ixgbe_sysfs_init(adapter))
10902 e_err(probe, "failed to allocate sysfs resources\n");
10903 #endif /* CONFIG_IXGBE_HWMON */
10905 ixgbe_dbg_adapter_init(adapter);
10907 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
10908 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
10909 hw->mac.ops.setup_link(hw,
10910 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
10916 ixgbe_release_hw_control(adapter);
10917 ixgbe_clear_interrupt_scheme(adapter);
10919 ixgbe_disable_sriov(adapter);
10920 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
10921 iounmap(adapter->io_addr);
10922 kfree(adapter->jump_tables[0]);
10923 kfree(adapter->mac_table);
10924 kfree(adapter->rss_key);
10926 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
10927 free_netdev(netdev);
10928 err_alloc_etherdev:
10929 pci_disable_pcie_error_reporting(pdev);
10930 pci_release_mem_regions(pdev);
10933 if (!adapter || disable_dev)
10934 pci_disable_device(pdev);
10939 * ixgbe_remove - Device Removal Routine
10940 * @pdev: PCI device information struct
10942 * ixgbe_remove is called by the PCI subsystem to alert the driver
10943 * that it should release a PCI device. The could be caused by a
10944 * Hot-Plug event, or because the driver is going to be removed from
10947 static void ixgbe_remove(struct pci_dev *pdev)
10949 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10950 struct net_device *netdev;
10954 /* if !adapter then we already cleaned up in probe */
10958 netdev = adapter->netdev;
10959 ixgbe_dbg_adapter_exit(adapter);
10961 set_bit(__IXGBE_REMOVING, &adapter->state);
10962 cancel_work_sync(&adapter->service_task);
10965 #ifdef CONFIG_IXGBE_DCA
10966 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
10967 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
10968 dca_remove_requester(&pdev->dev);
10969 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
10970 IXGBE_DCA_CTRL_DCA_DISABLE);
10974 #ifdef CONFIG_IXGBE_HWMON
10975 ixgbe_sysfs_exit(adapter);
10976 #endif /* CONFIG_IXGBE_HWMON */
10978 /* remove the added san mac */
10979 ixgbe_del_sanmac_netdev(netdev);
10981 #ifdef CONFIG_PCI_IOV
10982 ixgbe_disable_sriov(adapter);
10984 if (netdev->reg_state == NETREG_REGISTERED)
10985 unregister_netdev(netdev);
10987 ixgbe_stop_ipsec_offload(adapter);
10988 ixgbe_clear_interrupt_scheme(adapter);
10990 ixgbe_release_hw_control(adapter);
10993 kfree(adapter->ixgbe_ieee_pfc);
10994 kfree(adapter->ixgbe_ieee_ets);
10997 iounmap(adapter->io_addr);
10998 pci_release_mem_regions(pdev);
11000 e_dev_info("complete\n");
11002 for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) {
11003 if (adapter->jump_tables[i]) {
11004 kfree(adapter->jump_tables[i]->input);
11005 kfree(adapter->jump_tables[i]->mask);
11007 kfree(adapter->jump_tables[i]);
11010 kfree(adapter->mac_table);
11011 kfree(adapter->rss_key);
11012 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
11013 free_netdev(netdev);
11015 pci_disable_pcie_error_reporting(pdev);
11018 pci_disable_device(pdev);
11022 * ixgbe_io_error_detected - called when PCI error is detected
11023 * @pdev: Pointer to PCI device
11024 * @state: The current pci connection state
11026 * This function is called after a PCI bus error affecting
11027 * this device has been detected.
11029 static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
11030 pci_channel_state_t state)
11032 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
11033 struct net_device *netdev = adapter->netdev;
11035 #ifdef CONFIG_PCI_IOV
11036 struct ixgbe_hw *hw = &adapter->hw;
11037 struct pci_dev *bdev, *vfdev;
11038 u32 dw0, dw1, dw2, dw3;
11040 u16 req_id, pf_func;
11042 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
11043 adapter->num_vfs == 0)
11044 goto skip_bad_vf_detection;
11046 bdev = pdev->bus->self;
11047 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
11048 bdev = bdev->bus->self;
11051 goto skip_bad_vf_detection;
11053 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
11055 goto skip_bad_vf_detection;
11057 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
11058 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
11059 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
11060 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
11061 if (ixgbe_removed(hw->hw_addr))
11062 goto skip_bad_vf_detection;
11064 req_id = dw1 >> 16;
11065 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
11066 if (!(req_id & 0x0080))
11067 goto skip_bad_vf_detection;
11069 pf_func = req_id & 0x01;
11070 if ((pf_func & 1) == (pdev->devfn & 1)) {
11071 unsigned int device_id;
11073 vf = (req_id & 0x7F) >> 1;
11074 e_dev_err("VF %d has caused a PCIe error\n", vf);
11075 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
11076 "%8.8x\tdw3: %8.8x\n",
11077 dw0, dw1, dw2, dw3);
11078 switch (adapter->hw.mac.type) {
11079 case ixgbe_mac_82599EB:
11080 device_id = IXGBE_82599_VF_DEVICE_ID;
11082 case ixgbe_mac_X540:
11083 device_id = IXGBE_X540_VF_DEVICE_ID;
11085 case ixgbe_mac_X550:
11086 device_id = IXGBE_DEV_ID_X550_VF;
11088 case ixgbe_mac_X550EM_x:
11089 device_id = IXGBE_DEV_ID_X550EM_X_VF;
11091 case ixgbe_mac_x550em_a:
11092 device_id = IXGBE_DEV_ID_X550EM_A_VF;
11099 /* Find the pci device of the offending VF */
11100 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
11102 if (vfdev->devfn == (req_id & 0xFF))
11104 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
11108 * There's a slim chance the VF could have been hot plugged,
11109 * so if it is no longer present we don't need to issue the
11110 * VFLR. Just clean up the AER in that case.
11114 /* Free device reference count */
11115 pci_dev_put(vfdev);
11118 pci_cleanup_aer_uncorrect_error_status(pdev);
11122 * Even though the error may have occurred on the other port
11123 * we still need to increment the vf error reference count for
11124 * both ports because the I/O resume function will be called
11125 * for both of them.
11127 adapter->vferr_refcount++;
11129 return PCI_ERS_RESULT_RECOVERED;
11131 skip_bad_vf_detection:
11132 #endif /* CONFIG_PCI_IOV */
11133 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
11134 return PCI_ERS_RESULT_DISCONNECT;
11136 if (!netif_device_present(netdev))
11137 return PCI_ERS_RESULT_DISCONNECT;
11140 netif_device_detach(netdev);
11142 if (netif_running(netdev))
11143 ixgbe_close_suspend(adapter);
11145 if (state == pci_channel_io_perm_failure) {
11147 return PCI_ERS_RESULT_DISCONNECT;
11150 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
11151 pci_disable_device(pdev);
11154 /* Request a slot reset. */
11155 return PCI_ERS_RESULT_NEED_RESET;
11159 * ixgbe_io_slot_reset - called after the pci bus has been reset.
11160 * @pdev: Pointer to PCI device
11162 * Restart the card from scratch, as if from a cold-boot.
11164 static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
11166 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
11167 pci_ers_result_t result;
11170 if (pci_enable_device_mem(pdev)) {
11171 e_err(probe, "Cannot re-enable PCI device after reset.\n");
11172 result = PCI_ERS_RESULT_DISCONNECT;
11174 smp_mb__before_atomic();
11175 clear_bit(__IXGBE_DISABLED, &adapter->state);
11176 adapter->hw.hw_addr = adapter->io_addr;
11177 pci_set_master(pdev);
11178 pci_restore_state(pdev);
11179 pci_save_state(pdev);
11181 pci_wake_from_d3(pdev, false);
11183 ixgbe_reset(adapter);
11184 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
11185 result = PCI_ERS_RESULT_RECOVERED;
11188 err = pci_cleanup_aer_uncorrect_error_status(pdev);
11190 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
11191 "failed 0x%0x\n", err);
11192 /* non-fatal, continue */
11199 * ixgbe_io_resume - called when traffic can start flowing again.
11200 * @pdev: Pointer to PCI device
11202 * This callback is called when the error recovery driver tells us that
11203 * its OK to resume normal operation.
11205 static void ixgbe_io_resume(struct pci_dev *pdev)
11207 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
11208 struct net_device *netdev = adapter->netdev;
11210 #ifdef CONFIG_PCI_IOV
11211 if (adapter->vferr_refcount) {
11212 e_info(drv, "Resuming after VF err\n");
11213 adapter->vferr_refcount--;
11219 if (netif_running(netdev))
11220 ixgbe_open(netdev);
11222 netif_device_attach(netdev);
11226 static const struct pci_error_handlers ixgbe_err_handler = {
11227 .error_detected = ixgbe_io_error_detected,
11228 .slot_reset = ixgbe_io_slot_reset,
11229 .resume = ixgbe_io_resume,
11232 static struct pci_driver ixgbe_driver = {
11233 .name = ixgbe_driver_name,
11234 .id_table = ixgbe_pci_tbl,
11235 .probe = ixgbe_probe,
11236 .remove = ixgbe_remove,
11238 .suspend = ixgbe_suspend,
11239 .resume = ixgbe_resume,
11241 .shutdown = ixgbe_shutdown,
11242 .sriov_configure = ixgbe_pci_sriov_configure,
11243 .err_handler = &ixgbe_err_handler
11247 * ixgbe_init_module - Driver Registration Routine
11249 * ixgbe_init_module is the first routine called when the driver is
11250 * loaded. All it does is register with the PCI subsystem.
11252 static int __init ixgbe_init_module(void)
11255 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
11256 pr_info("%s\n", ixgbe_copyright);
11258 ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
11260 pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
11266 ret = pci_register_driver(&ixgbe_driver);
11268 destroy_workqueue(ixgbe_wq);
11273 #ifdef CONFIG_IXGBE_DCA
11274 dca_register_notify(&dca_notifier);
11280 module_init(ixgbe_init_module);
11283 * ixgbe_exit_module - Driver Exit Cleanup Routine
11285 * ixgbe_exit_module is called just before the driver is removed
11288 static void __exit ixgbe_exit_module(void)
11290 #ifdef CONFIG_IXGBE_DCA
11291 dca_unregister_notify(&dca_notifier);
11293 pci_unregister_driver(&ixgbe_driver);
11297 destroy_workqueue(ixgbe_wq);
11302 #ifdef CONFIG_IXGBE_DCA
11303 static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
11308 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
11309 __ixgbe_notify_dca);
11311 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
11314 #endif /* CONFIG_IXGBE_DCA */
11316 module_exit(ixgbe_exit_module);