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 <linux/numa.h>
31 #include <generated/utsrelease.h>
32 #include <scsi/fc/fc_fcoe.h>
33 #include <net/udp_tunnel.h>
34 #include <net/pkt_cls.h>
35 #include <net/tc_act/tc_gact.h>
36 #include <net/tc_act/tc_mirred.h>
37 #include <net/vxlan.h>
39 #include <net/netdev_queues.h>
40 #include <net/xdp_sock_drv.h>
44 #include "ixgbe_common.h"
45 #include "ixgbe_dcb_82599.h"
46 #include "ixgbe_mbx.h"
47 #include "ixgbe_phy.h"
48 #include "ixgbe_sriov.h"
49 #include "ixgbe_model.h"
50 #include "ixgbe_txrx_common.h"
52 char ixgbe_driver_name
[] = "ixgbe";
53 static const char ixgbe_driver_string
[] =
54 "Intel(R) 10 Gigabit PCI Express Network Driver";
56 char ixgbe_default_device_descr
[] =
57 "Intel(R) 10 Gigabit Network Connection";
59 static char ixgbe_default_device_descr
[] =
60 "Intel(R) 10 Gigabit Network Connection";
62 static const char ixgbe_copyright
[] =
63 "Copyright (c) 1999-2016 Intel Corporation.";
65 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";
67 static const struct ixgbe_info
*ixgbe_info_tbl
[] = {
68 [board_82598
] = &ixgbe_82598_info
,
69 [board_82599
] = &ixgbe_82599_info
,
70 [board_X540
] = &ixgbe_X540_info
,
71 [board_X550
] = &ixgbe_X550_info
,
72 [board_X550EM_x
] = &ixgbe_X550EM_x_info
,
73 [board_x550em_x_fw
] = &ixgbe_x550em_x_fw_info
,
74 [board_x550em_a
] = &ixgbe_x550em_a_info
,
75 [board_x550em_a_fw
] = &ixgbe_x550em_a_fw_info
,
78 /* ixgbe_pci_tbl - PCI Device ID Table
80 * Wildcard entries (PCI_ANY_ID) should come last
81 * Last entry must be all 0s
83 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
84 * Class, Class Mask, private data (not used) }
86 static const struct pci_device_id ixgbe_pci_tbl
[] = {
87 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598
), board_82598
},
88 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AF_DUAL_PORT
), board_82598
},
89 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AF_SINGLE_PORT
), board_82598
},
90 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AT
), board_82598
},
91 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AT2
), board_82598
},
92 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_CX4
), board_82598
},
93 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_CX4_DUAL_PORT
), board_82598
},
94 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_DA_DUAL_PORT
), board_82598
},
95 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM
), board_82598
},
96 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_XF_LR
), board_82598
},
97 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_SFP_LOM
), board_82598
},
98 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_BX
), board_82598
},
99 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KX4
), board_82599
},
100 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_XAUI_LOM
), board_82599
},
101 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KR
), board_82599
},
102 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP
), board_82599
},
103 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP_EM
), board_82599
},
104 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KX4_MEZZ
), board_82599
},
105 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_CX4
), board_82599
},
106 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_BACKPLANE_FCOE
), board_82599
},
107 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP_FCOE
), board_82599
},
108 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_T3_LOM
), board_82599
},
109 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_COMBO_BACKPLANE
), board_82599
},
110 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X540T
), board_X540
},
111 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP_SF2
), board_82599
},
112 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_LS
), board_82599
},
113 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_QSFP_SF_QP
), board_82599
},
114 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599EN_SFP
), board_82599
},
115 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP_SF_QP
), board_82599
},
116 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X540T1
), board_X540
},
117 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550T
), board_X550
},
118 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550T1
), board_X550
},
119 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_X_KX4
), board_X550EM_x
},
120 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_X_XFI
), board_X550EM_x
},
121 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_X_KR
), board_X550EM_x
},
122 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_X_10G_T
), board_X550EM_x
},
123 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_X_SFP
), board_X550EM_x
},
124 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_X_1G_T
), board_x550em_x_fw
},
125 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_A_KR
), board_x550em_a
},
126 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_A_KR_L
), board_x550em_a
},
127 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_A_SFP_N
), board_x550em_a
},
128 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_A_SGMII
), board_x550em_a
},
129 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_A_SGMII_L
), board_x550em_a
},
130 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_A_10G_T
), board_x550em_a
},
131 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_A_SFP
), board_x550em_a
},
132 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_A_1G_T
), board_x550em_a_fw
},
133 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_A_1G_T_L
), board_x550em_a_fw
},
134 /* required last entry */
137 MODULE_DEVICE_TABLE(pci
, ixgbe_pci_tbl
);
139 #ifdef CONFIG_IXGBE_DCA
140 static int ixgbe_notify_dca(struct notifier_block
*, unsigned long event
,
142 static struct notifier_block dca_notifier
= {
143 .notifier_call
= ixgbe_notify_dca
,
149 #ifdef CONFIG_PCI_IOV
150 static unsigned int max_vfs
;
151 module_param(max_vfs
, uint
, 0);
152 MODULE_PARM_DESC(max_vfs
,
153 "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63. (Deprecated)");
154 #endif /* CONFIG_PCI_IOV */
156 static bool allow_unsupported_sfp
;
157 module_param(allow_unsupported_sfp
, bool, 0444);
158 MODULE_PARM_DESC(allow_unsupported_sfp
,
159 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
161 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
162 static int debug
= -1;
163 module_param(debug
, int, 0);
164 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
166 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
167 MODULE_LICENSE("GPL v2");
169 DEFINE_STATIC_KEY_FALSE(ixgbe_xdp_locking_key
);
170 EXPORT_SYMBOL(ixgbe_xdp_locking_key
);
172 static struct workqueue_struct
*ixgbe_wq
;
174 static bool ixgbe_check_cfg_remove(struct ixgbe_hw
*hw
, struct pci_dev
*pdev
);
175 static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter
*);
177 static const struct net_device_ops ixgbe_netdev_ops
;
179 static bool netif_is_ixgbe(struct net_device
*dev
)
181 return dev
&& (dev
->netdev_ops
== &ixgbe_netdev_ops
);
184 static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter
*adapter
,
187 struct pci_dev
*parent_dev
;
188 struct pci_bus
*parent_bus
;
190 parent_bus
= adapter
->pdev
->bus
->parent
;
194 parent_dev
= parent_bus
->self
;
198 if (!pci_is_pcie(parent_dev
))
201 pcie_capability_read_word(parent_dev
, reg
, value
);
202 if (*value
== IXGBE_FAILED_READ_CFG_WORD
&&
203 ixgbe_check_cfg_remove(&adapter
->hw
, parent_dev
))
208 static int ixgbe_get_parent_bus_info(struct ixgbe_adapter
*adapter
)
210 struct ixgbe_hw
*hw
= &adapter
->hw
;
214 hw
->bus
.type
= ixgbe_bus_type_pci_express
;
216 /* Get the negotiated link width and speed from PCI config space of the
217 * parent, as this device is behind a switch
219 err
= ixgbe_read_pci_cfg_word_parent(adapter
, 18, &link_status
);
221 /* assume caller will handle error case */
225 hw
->bus
.width
= ixgbe_convert_bus_width(link_status
);
226 hw
->bus
.speed
= ixgbe_convert_bus_speed(link_status
);
232 * ixgbe_pcie_from_parent - Determine whether PCIe info should come from parent
233 * @hw: hw specific details
235 * This function is used by probe to determine whether a device's PCI-Express
236 * bandwidth details should be gathered from the parent bus instead of from the
237 * device. Used to ensure that various locations all have the correct device ID
240 static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw
*hw
)
242 switch (hw
->device_id
) {
243 case IXGBE_DEV_ID_82599_SFP_SF_QP
:
244 case IXGBE_DEV_ID_82599_QSFP_SF_QP
:
251 static void ixgbe_check_minimum_link(struct ixgbe_adapter
*adapter
,
254 struct ixgbe_hw
*hw
= &adapter
->hw
;
255 struct pci_dev
*pdev
;
257 /* Some devices are not connected over PCIe and thus do not negotiate
258 * speed. These devices do not have valid bus info, and thus any report
259 * we generate may not be correct.
261 if (hw
->bus
.type
== ixgbe_bus_type_internal
)
264 /* determine whether to use the parent device */
265 if (ixgbe_pcie_from_parent(&adapter
->hw
))
266 pdev
= adapter
->pdev
->bus
->parent
->self
;
268 pdev
= adapter
->pdev
;
270 pcie_print_link_status(pdev
);
273 static void ixgbe_service_event_schedule(struct ixgbe_adapter
*adapter
)
275 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
) &&
276 !test_bit(__IXGBE_REMOVING
, &adapter
->state
) &&
277 !test_and_set_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
))
278 queue_work(ixgbe_wq
, &adapter
->service_task
);
281 static void ixgbe_remove_adapter(struct ixgbe_hw
*hw
)
283 struct ixgbe_adapter
*adapter
= hw
->back
;
288 e_dev_err("Adapter removed\n");
289 if (test_bit(__IXGBE_SERVICE_INITED
, &adapter
->state
))
290 ixgbe_service_event_schedule(adapter
);
293 static u32
ixgbe_check_remove(struct ixgbe_hw
*hw
, u32 reg
)
295 u8 __iomem
*reg_addr
;
299 reg_addr
= READ_ONCE(hw
->hw_addr
);
300 if (ixgbe_removed(reg_addr
))
301 return IXGBE_FAILED_READ_REG
;
303 /* Register read of 0xFFFFFFF can indicate the adapter has been removed,
304 * so perform several status register reads to determine if the adapter
307 for (i
= 0; i
< IXGBE_FAILED_READ_RETRIES
; i
++) {
308 value
= readl(reg_addr
+ IXGBE_STATUS
);
309 if (value
!= IXGBE_FAILED_READ_REG
)
314 if (value
== IXGBE_FAILED_READ_REG
)
315 ixgbe_remove_adapter(hw
);
317 value
= readl(reg_addr
+ reg
);
322 * ixgbe_read_reg - Read from device register
323 * @hw: hw specific details
324 * @reg: offset of register to read
326 * Returns : value read or IXGBE_FAILED_READ_REG if removed
328 * This function is used to read device registers. It checks for device
329 * removal by confirming any read that returns all ones by checking the
330 * status register value for all ones. This function avoids reading from
331 * the hardware if a removal was previously detected in which case it
332 * returns IXGBE_FAILED_READ_REG (all ones).
334 u32
ixgbe_read_reg(struct ixgbe_hw
*hw
, u32 reg
)
336 u8 __iomem
*reg_addr
= READ_ONCE(hw
->hw_addr
);
339 if (ixgbe_removed(reg_addr
))
340 return IXGBE_FAILED_READ_REG
;
341 if (unlikely(hw
->phy
.nw_mng_if_sel
&
342 IXGBE_NW_MNG_IF_SEL_SGMII_ENABLE
)) {
343 struct ixgbe_adapter
*adapter
;
346 for (i
= 0; i
< 200; ++i
) {
347 value
= readl(reg_addr
+ IXGBE_MAC_SGMII_BUSY
);
349 goto writes_completed
;
350 if (value
== IXGBE_FAILED_READ_REG
) {
351 ixgbe_remove_adapter(hw
);
352 return IXGBE_FAILED_READ_REG
;
358 e_warn(hw
, "register writes incomplete %08x\n", value
);
362 value
= readl(reg_addr
+ reg
);
363 if (unlikely(value
== IXGBE_FAILED_READ_REG
))
364 value
= ixgbe_check_remove(hw
, reg
);
368 static bool ixgbe_check_cfg_remove(struct ixgbe_hw
*hw
, struct pci_dev
*pdev
)
372 pci_read_config_word(pdev
, PCI_VENDOR_ID
, &value
);
373 if (value
== IXGBE_FAILED_READ_CFG_WORD
) {
374 ixgbe_remove_adapter(hw
);
380 u16
ixgbe_read_pci_cfg_word(struct ixgbe_hw
*hw
, u32 reg
)
382 struct ixgbe_adapter
*adapter
= hw
->back
;
385 if (ixgbe_removed(hw
->hw_addr
))
386 return IXGBE_FAILED_READ_CFG_WORD
;
387 pci_read_config_word(adapter
->pdev
, reg
, &value
);
388 if (value
== IXGBE_FAILED_READ_CFG_WORD
&&
389 ixgbe_check_cfg_remove(hw
, adapter
->pdev
))
390 return IXGBE_FAILED_READ_CFG_WORD
;
394 #ifdef CONFIG_PCI_IOV
395 static u32
ixgbe_read_pci_cfg_dword(struct ixgbe_hw
*hw
, u32 reg
)
397 struct ixgbe_adapter
*adapter
= hw
->back
;
400 if (ixgbe_removed(hw
->hw_addr
))
401 return IXGBE_FAILED_READ_CFG_DWORD
;
402 pci_read_config_dword(adapter
->pdev
, reg
, &value
);
403 if (value
== IXGBE_FAILED_READ_CFG_DWORD
&&
404 ixgbe_check_cfg_remove(hw
, adapter
->pdev
))
405 return IXGBE_FAILED_READ_CFG_DWORD
;
408 #endif /* CONFIG_PCI_IOV */
410 void ixgbe_write_pci_cfg_word(struct ixgbe_hw
*hw
, u32 reg
, u16 value
)
412 struct ixgbe_adapter
*adapter
= hw
->back
;
414 if (ixgbe_removed(hw
->hw_addr
))
416 pci_write_config_word(adapter
->pdev
, reg
, value
);
419 static void ixgbe_service_event_complete(struct ixgbe_adapter
*adapter
)
421 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
));
423 /* flush memory to make sure state is correct before next watchdog */
424 smp_mb__before_atomic();
425 clear_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
);
428 struct ixgbe_reg_info
{
433 static const struct ixgbe_reg_info ixgbe_reg_info_tbl
[] = {
435 /* General Registers */
436 {IXGBE_CTRL
, "CTRL"},
437 {IXGBE_STATUS
, "STATUS"},
438 {IXGBE_CTRL_EXT
, "CTRL_EXT"},
440 /* Interrupt Registers */
441 {IXGBE_EICR
, "EICR"},
444 {IXGBE_SRRCTL(0), "SRRCTL"},
445 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
446 {IXGBE_RDLEN(0), "RDLEN"},
447 {IXGBE_RDH(0), "RDH"},
448 {IXGBE_RDT(0), "RDT"},
449 {IXGBE_RXDCTL(0), "RXDCTL"},
450 {IXGBE_RDBAL(0), "RDBAL"},
451 {IXGBE_RDBAH(0), "RDBAH"},
454 {IXGBE_TDBAL(0), "TDBAL"},
455 {IXGBE_TDBAH(0), "TDBAH"},
456 {IXGBE_TDLEN(0), "TDLEN"},
457 {IXGBE_TDH(0), "TDH"},
458 {IXGBE_TDT(0), "TDT"},
459 {IXGBE_TXDCTL(0), "TXDCTL"},
461 /* List Terminator */
467 * ixgbe_regdump - register printout routine
469 static void ixgbe_regdump(struct ixgbe_hw
*hw
, struct ixgbe_reg_info
*reginfo
)
475 switch (reginfo
->ofs
) {
476 case IXGBE_SRRCTL(0):
477 for (i
= 0; i
< 64; i
++)
478 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_SRRCTL(i
));
480 case IXGBE_DCA_RXCTRL(0):
481 for (i
= 0; i
< 64; i
++)
482 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_DCA_RXCTRL(i
));
485 for (i
= 0; i
< 64; i
++)
486 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDLEN(i
));
489 for (i
= 0; i
< 64; i
++)
490 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDH(i
));
493 for (i
= 0; i
< 64; i
++)
494 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDT(i
));
496 case IXGBE_RXDCTL(0):
497 for (i
= 0; i
< 64; i
++)
498 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RXDCTL(i
));
501 for (i
= 0; i
< 64; i
++)
502 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDBAL(i
));
505 for (i
= 0; i
< 64; i
++)
506 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDBAH(i
));
509 for (i
= 0; i
< 64; i
++)
510 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDBAL(i
));
513 for (i
= 0; i
< 64; i
++)
514 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDBAH(i
));
517 for (i
= 0; i
< 64; i
++)
518 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDLEN(i
));
521 for (i
= 0; i
< 64; i
++)
522 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDH(i
));
525 for (i
= 0; i
< 64; i
++)
526 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDT(i
));
528 case IXGBE_TXDCTL(0):
529 for (i
= 0; i
< 64; i
++)
530 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TXDCTL(i
));
533 pr_info("%-15s %08x\n",
534 reginfo
->name
, IXGBE_READ_REG(hw
, reginfo
->ofs
));
544 snprintf(rname
, 16, "%s[%d-%d]", reginfo
->name
, i
, i
+ 7);
545 for (j
= 0; j
< 8; j
++)
546 p
+= sprintf(p
, " %08x", regs
[i
++]);
547 pr_err("%-15s%s\n", rname
, buf
);
552 static void ixgbe_print_buffer(struct ixgbe_ring
*ring
, int n
)
554 struct ixgbe_tx_buffer
*tx_buffer
;
556 tx_buffer
= &ring
->tx_buffer_info
[ring
->next_to_clean
];
557 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
558 n
, ring
->next_to_use
, ring
->next_to_clean
,
559 (u64
)dma_unmap_addr(tx_buffer
, dma
),
560 dma_unmap_len(tx_buffer
, len
),
561 tx_buffer
->next_to_watch
,
562 (u64
)tx_buffer
->time_stamp
);
566 * ixgbe_dump - Print registers, tx-rings and rx-rings
568 static void ixgbe_dump(struct ixgbe_adapter
*adapter
)
570 struct net_device
*netdev
= adapter
->netdev
;
571 struct ixgbe_hw
*hw
= &adapter
->hw
;
572 struct ixgbe_reg_info
*reginfo
;
574 struct ixgbe_ring
*ring
;
575 struct ixgbe_tx_buffer
*tx_buffer
;
576 union ixgbe_adv_tx_desc
*tx_desc
;
577 struct my_u0
{ u64 a
; u64 b
; } *u0
;
578 struct ixgbe_ring
*rx_ring
;
579 union ixgbe_adv_rx_desc
*rx_desc
;
580 struct ixgbe_rx_buffer
*rx_buffer_info
;
583 if (!netif_msg_hw(adapter
))
586 /* Print netdevice Info */
588 dev_info(&adapter
->pdev
->dev
, "Net device Info\n");
589 pr_info("Device Name state "
591 pr_info("%-15s %016lX %016lX\n",
594 dev_trans_start(netdev
));
597 /* Print Registers */
598 dev_info(&adapter
->pdev
->dev
, "Register Dump\n");
599 pr_info(" Register Name Value\n");
600 for (reginfo
= (struct ixgbe_reg_info
*)ixgbe_reg_info_tbl
;
601 reginfo
->name
; reginfo
++) {
602 ixgbe_regdump(hw
, reginfo
);
605 /* Print TX Ring Summary */
606 if (!netdev
|| !netif_running(netdev
))
609 dev_info(&adapter
->pdev
->dev
, "TX Rings Summary\n");
610 pr_info(" %s %s %s %s\n",
611 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
612 "leng", "ntw", "timestamp");
613 for (n
= 0; n
< adapter
->num_tx_queues
; n
++) {
614 ring
= adapter
->tx_ring
[n
];
615 ixgbe_print_buffer(ring
, n
);
618 for (n
= 0; n
< adapter
->num_xdp_queues
; n
++) {
619 ring
= adapter
->xdp_ring
[n
];
620 ixgbe_print_buffer(ring
, n
);
624 if (!netif_msg_tx_done(adapter
))
625 goto rx_ring_summary
;
627 dev_info(&adapter
->pdev
->dev
, "TX Rings Dump\n");
629 /* Transmit Descriptor Formats
631 * 82598 Advanced Transmit Descriptor
632 * +--------------------------------------------------------------+
633 * 0 | Buffer Address [63:0] |
634 * +--------------------------------------------------------------+
635 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
636 * +--------------------------------------------------------------+
637 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
639 * 82598 Advanced Transmit Descriptor (Write-Back Format)
640 * +--------------------------------------------------------------+
642 * +--------------------------------------------------------------+
643 * 8 | RSV | STA | NXTSEQ |
644 * +--------------------------------------------------------------+
647 * 82599+ Advanced Transmit Descriptor
648 * +--------------------------------------------------------------+
649 * 0 | Buffer Address [63:0] |
650 * +--------------------------------------------------------------+
651 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
652 * +--------------------------------------------------------------+
653 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
655 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
656 * +--------------------------------------------------------------+
658 * +--------------------------------------------------------------+
659 * 8 | RSV | STA | RSV |
660 * +--------------------------------------------------------------+
664 for (n
= 0; n
< adapter
->num_tx_queues
; n
++) {
665 ring
= adapter
->tx_ring
[n
];
666 pr_info("------------------------------------\n");
667 pr_info("TX QUEUE INDEX = %d\n", ring
->queue_index
);
668 pr_info("------------------------------------\n");
669 pr_info("%s%s %s %s %s %s\n",
670 "T [desc] [address 63:0 ] ",
671 "[PlPOIdStDDt Ln] [bi->dma ] ",
672 "leng", "ntw", "timestamp", "bi->skb");
674 for (i
= 0; ring
->desc
&& (i
< ring
->count
); i
++) {
675 tx_desc
= IXGBE_TX_DESC(ring
, i
);
676 tx_buffer
= &ring
->tx_buffer_info
[i
];
677 u0
= (struct my_u0
*)tx_desc
;
678 if (dma_unmap_len(tx_buffer
, len
) > 0) {
679 const char *ring_desc
;
681 if (i
== ring
->next_to_use
&&
682 i
== ring
->next_to_clean
)
683 ring_desc
= " NTC/U";
684 else if (i
== ring
->next_to_use
)
686 else if (i
== ring
->next_to_clean
)
690 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p%s",
692 le64_to_cpu((__force __le64
)u0
->a
),
693 le64_to_cpu((__force __le64
)u0
->b
),
694 (u64
)dma_unmap_addr(tx_buffer
, dma
),
695 dma_unmap_len(tx_buffer
, len
),
696 tx_buffer
->next_to_watch
,
697 (u64
)tx_buffer
->time_stamp
,
701 if (netif_msg_pktdata(adapter
) &&
703 print_hex_dump(KERN_INFO
, "",
704 DUMP_PREFIX_ADDRESS
, 16, 1,
705 tx_buffer
->skb
->data
,
706 dma_unmap_len(tx_buffer
, len
),
712 /* Print RX Rings Summary */
714 dev_info(&adapter
->pdev
->dev
, "RX Rings Summary\n");
715 pr_info("Queue [NTU] [NTC]\n");
716 for (n
= 0; n
< adapter
->num_rx_queues
; n
++) {
717 rx_ring
= adapter
->rx_ring
[n
];
718 pr_info("%5d %5X %5X\n",
719 n
, rx_ring
->next_to_use
, rx_ring
->next_to_clean
);
723 if (!netif_msg_rx_status(adapter
))
726 dev_info(&adapter
->pdev
->dev
, "RX Rings Dump\n");
728 /* Receive Descriptor Formats
730 * 82598 Advanced Receive Descriptor (Read) Format
732 * +-----------------------------------------------------+
733 * 0 | Packet Buffer Address [63:1] |A0/NSE|
734 * +----------------------------------------------+------+
735 * 8 | Header Buffer Address [63:1] | DD |
736 * +-----------------------------------------------------+
739 * 82598 Advanced Receive Descriptor (Write-Back) Format
741 * 63 48 47 32 31 30 21 20 16 15 4 3 0
742 * +------------------------------------------------------+
743 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
744 * | Packet | IP | | | | Type | Type |
745 * | Checksum | Ident | | | | | |
746 * +------------------------------------------------------+
747 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
748 * +------------------------------------------------------+
749 * 63 48 47 32 31 20 19 0
751 * 82599+ Advanced Receive Descriptor (Read) Format
753 * +-----------------------------------------------------+
754 * 0 | Packet Buffer Address [63:1] |A0/NSE|
755 * +----------------------------------------------+------+
756 * 8 | Header Buffer Address [63:1] | DD |
757 * +-----------------------------------------------------+
760 * 82599+ Advanced Receive Descriptor (Write-Back) Format
762 * 63 48 47 32 31 30 21 20 17 16 4 3 0
763 * +------------------------------------------------------+
764 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
765 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
766 * |/ Flow Dir Flt ID | | | | | |
767 * +------------------------------------------------------+
768 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
769 * +------------------------------------------------------+
770 * 63 48 47 32 31 20 19 0
773 for (n
= 0; n
< adapter
->num_rx_queues
; n
++) {
774 rx_ring
= adapter
->rx_ring
[n
];
775 pr_info("------------------------------------\n");
776 pr_info("RX QUEUE INDEX = %d\n", rx_ring
->queue_index
);
777 pr_info("------------------------------------\n");
779 "R [desc] [ PktBuf A0] ",
780 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
781 "<-- Adv Rx Read format");
783 "RWB[desc] [PcsmIpSHl PtRs] ",
784 "[vl er S cks ln] ---------------- [bi->skb ] ",
785 "<-- Adv Rx Write-Back format");
787 for (i
= 0; i
< rx_ring
->count
; i
++) {
788 const char *ring_desc
;
790 if (i
== rx_ring
->next_to_use
)
792 else if (i
== rx_ring
->next_to_clean
)
797 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
798 rx_desc
= IXGBE_RX_DESC(rx_ring
, i
);
799 u0
= (struct my_u0
*)rx_desc
;
800 if (rx_desc
->wb
.upper
.length
) {
801 /* Descriptor Done */
802 pr_info("RWB[0x%03X] %016llX %016llX ---------------- %p%s\n",
804 le64_to_cpu((__force __le64
)u0
->a
),
805 le64_to_cpu((__force __le64
)u0
->b
),
809 pr_info("R [0x%03X] %016llX %016llX %016llX %p%s\n",
811 le64_to_cpu((__force __le64
)u0
->a
),
812 le64_to_cpu((__force __le64
)u0
->b
),
813 (u64
)rx_buffer_info
->dma
,
817 if (netif_msg_pktdata(adapter
) &&
818 rx_buffer_info
->dma
) {
819 print_hex_dump(KERN_INFO
, "",
820 DUMP_PREFIX_ADDRESS
, 16, 1,
821 page_address(rx_buffer_info
->page
) +
822 rx_buffer_info
->page_offset
,
823 ixgbe_rx_bufsz(rx_ring
), true);
830 static void ixgbe_release_hw_control(struct ixgbe_adapter
*adapter
)
834 /* Let firmware take over control of h/w */
835 ctrl_ext
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_CTRL_EXT
);
836 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_CTRL_EXT
,
837 ctrl_ext
& ~IXGBE_CTRL_EXT_DRV_LOAD
);
840 static void ixgbe_get_hw_control(struct ixgbe_adapter
*adapter
)
844 /* Let firmware know the driver has taken over */
845 ctrl_ext
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_CTRL_EXT
);
846 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_CTRL_EXT
,
847 ctrl_ext
| IXGBE_CTRL_EXT_DRV_LOAD
);
851 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
852 * @adapter: pointer to adapter struct
853 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
854 * @queue: queue to map the corresponding interrupt to
855 * @msix_vector: the vector to map to the corresponding queue
858 static void ixgbe_set_ivar(struct ixgbe_adapter
*adapter
, s8 direction
,
859 u8 queue
, u8 msix_vector
)
862 struct ixgbe_hw
*hw
= &adapter
->hw
;
863 switch (hw
->mac
.type
) {
864 case ixgbe_mac_82598EB
:
865 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
868 index
= (((direction
* 64) + queue
) >> 2) & 0x1F;
869 ivar
= IXGBE_READ_REG(hw
, IXGBE_IVAR(index
));
870 ivar
&= ~(0xFF << (8 * (queue
& 0x3)));
871 ivar
|= (msix_vector
<< (8 * (queue
& 0x3)));
872 IXGBE_WRITE_REG(hw
, IXGBE_IVAR(index
), ivar
);
874 case ixgbe_mac_82599EB
:
877 case ixgbe_mac_X550EM_x
:
878 case ixgbe_mac_x550em_a
:
879 if (direction
== -1) {
881 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
882 index
= ((queue
& 1) * 8);
883 ivar
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_IVAR_MISC
);
884 ivar
&= ~(0xFF << index
);
885 ivar
|= (msix_vector
<< index
);
886 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_IVAR_MISC
, ivar
);
889 /* tx or rx causes */
890 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
891 index
= ((16 * (queue
& 1)) + (8 * direction
));
892 ivar
= IXGBE_READ_REG(hw
, IXGBE_IVAR(queue
>> 1));
893 ivar
&= ~(0xFF << index
);
894 ivar
|= (msix_vector
<< index
);
895 IXGBE_WRITE_REG(hw
, IXGBE_IVAR(queue
>> 1), ivar
);
903 void ixgbe_irq_rearm_queues(struct ixgbe_adapter
*adapter
,
908 switch (adapter
->hw
.mac
.type
) {
909 case ixgbe_mac_82598EB
:
910 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
911 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS
, mask
);
913 case ixgbe_mac_82599EB
:
916 case ixgbe_mac_X550EM_x
:
917 case ixgbe_mac_x550em_a
:
918 mask
= (qmask
& 0xFFFFFFFF);
919 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS_EX(0), mask
);
920 mask
= (qmask
>> 32);
921 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS_EX(1), mask
);
928 static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter
*adapter
)
930 struct ixgbe_hw
*hw
= &adapter
->hw
;
931 struct ixgbe_hw_stats
*hwstats
= &adapter
->stats
;
935 if ((hw
->fc
.current_mode
!= ixgbe_fc_full
) &&
936 (hw
->fc
.current_mode
!= ixgbe_fc_rx_pause
))
939 switch (hw
->mac
.type
) {
940 case ixgbe_mac_82598EB
:
941 data
= IXGBE_READ_REG(hw
, IXGBE_LXOFFRXC
);
944 data
= IXGBE_READ_REG(hw
, IXGBE_LXOFFRXCNT
);
946 hwstats
->lxoffrxc
+= data
;
948 /* refill credits (no tx hang) if we received xoff */
952 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
953 clear_bit(__IXGBE_HANG_CHECK_ARMED
,
954 &adapter
->tx_ring
[i
]->state
);
956 for (i
= 0; i
< adapter
->num_xdp_queues
; i
++)
957 clear_bit(__IXGBE_HANG_CHECK_ARMED
,
958 &adapter
->xdp_ring
[i
]->state
);
961 static void ixgbe_update_xoff_received(struct ixgbe_adapter
*adapter
)
963 struct ixgbe_hw
*hw
= &adapter
->hw
;
964 struct ixgbe_hw_stats
*hwstats
= &adapter
->stats
;
968 bool pfc_en
= adapter
->dcb_cfg
.pfc_mode_enable
;
970 if (adapter
->ixgbe_ieee_pfc
)
971 pfc_en
|= !!(adapter
->ixgbe_ieee_pfc
->pfc_en
);
973 if (!(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) || !pfc_en
) {
974 ixgbe_update_xoff_rx_lfc(adapter
);
978 /* update stats for each tc, only valid with PFC enabled */
979 for (i
= 0; i
< MAX_TX_PACKET_BUFFERS
; i
++) {
982 switch (hw
->mac
.type
) {
983 case ixgbe_mac_82598EB
:
984 pxoffrxc
= IXGBE_READ_REG(hw
, IXGBE_PXOFFRXC(i
));
987 pxoffrxc
= IXGBE_READ_REG(hw
, IXGBE_PXOFFRXCNT(i
));
989 hwstats
->pxoffrxc
[i
] += pxoffrxc
;
990 /* Get the TC for given UP */
991 tc
= netdev_get_prio_tc_map(adapter
->netdev
, i
);
992 xoff
[tc
] += pxoffrxc
;
995 /* disarm tx queues that have received xoff frames */
996 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
997 struct ixgbe_ring
*tx_ring
= adapter
->tx_ring
[i
];
999 tc
= tx_ring
->dcb_tc
;
1001 clear_bit(__IXGBE_HANG_CHECK_ARMED
, &tx_ring
->state
);
1004 for (i
= 0; i
< adapter
->num_xdp_queues
; i
++) {
1005 struct ixgbe_ring
*xdp_ring
= adapter
->xdp_ring
[i
];
1007 tc
= xdp_ring
->dcb_tc
;
1009 clear_bit(__IXGBE_HANG_CHECK_ARMED
, &xdp_ring
->state
);
1013 static u64
ixgbe_get_tx_completed(struct ixgbe_ring
*ring
)
1015 return ring
->stats
.packets
;
1018 static u64
ixgbe_get_tx_pending(struct ixgbe_ring
*ring
)
1020 unsigned int head
, tail
;
1022 head
= ring
->next_to_clean
;
1023 tail
= ring
->next_to_use
;
1025 return ((head
<= tail
) ? tail
: tail
+ ring
->count
) - head
;
1028 static inline bool ixgbe_check_tx_hang(struct ixgbe_ring
*tx_ring
)
1030 u32 tx_done
= ixgbe_get_tx_completed(tx_ring
);
1031 u32 tx_done_old
= tx_ring
->tx_stats
.tx_done_old
;
1032 u32 tx_pending
= ixgbe_get_tx_pending(tx_ring
);
1034 clear_check_for_tx_hang(tx_ring
);
1037 * Check for a hung queue, but be thorough. This verifies
1038 * that a transmit has been completed since the previous
1039 * check AND there is at least one packet pending. The
1040 * ARMED bit is set to indicate a potential hang. The
1041 * bit is cleared if a pause frame is received to remove
1042 * false hang detection due to PFC or 802.3x frames. By
1043 * requiring this to fail twice we avoid races with
1044 * pfc clearing the ARMED bit and conditions where we
1045 * run the check_tx_hang logic with a transmit completion
1046 * pending but without time to complete it yet.
1048 if (tx_done_old
== tx_done
&& tx_pending
)
1049 /* make sure it is true for two checks in a row */
1050 return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED
,
1052 /* update completed stats and continue */
1053 tx_ring
->tx_stats
.tx_done_old
= tx_done
;
1054 /* reset the countdown */
1055 clear_bit(__IXGBE_HANG_CHECK_ARMED
, &tx_ring
->state
);
1061 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1062 * @adapter: driver private struct
1064 static void ixgbe_tx_timeout_reset(struct ixgbe_adapter
*adapter
)
1067 /* Do the reset outside of interrupt context */
1068 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
1069 set_bit(__IXGBE_RESET_REQUESTED
, &adapter
->state
);
1070 e_warn(drv
, "initiating reset due to tx timeout\n");
1071 ixgbe_service_event_schedule(adapter
);
1076 * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
1077 * @netdev: network interface device structure
1078 * @queue_index: Tx queue to set
1079 * @maxrate: desired maximum transmit bitrate
1081 static int ixgbe_tx_maxrate(struct net_device
*netdev
,
1082 int queue_index
, u32 maxrate
)
1084 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1085 struct ixgbe_hw
*hw
= &adapter
->hw
;
1086 u32 bcnrc_val
= ixgbe_link_mbps(adapter
);
1091 /* Calculate the rate factor values to set */
1092 bcnrc_val
<<= IXGBE_RTTBCNRC_RF_INT_SHIFT
;
1093 bcnrc_val
/= maxrate
;
1095 /* clear everything but the rate factor */
1096 bcnrc_val
&= IXGBE_RTTBCNRC_RF_INT_MASK
|
1097 IXGBE_RTTBCNRC_RF_DEC_MASK
;
1099 /* enable the rate scheduler */
1100 bcnrc_val
|= IXGBE_RTTBCNRC_RS_ENA
;
1102 IXGBE_WRITE_REG(hw
, IXGBE_RTTDQSEL
, queue_index
);
1103 IXGBE_WRITE_REG(hw
, IXGBE_RTTBCNRC
, bcnrc_val
);
1109 * ixgbe_update_tx_ring_stats - Update Tx ring specific counters
1110 * @tx_ring: ring to update
1111 * @q_vector: queue vector ring belongs to
1112 * @pkts: number of processed packets
1113 * @bytes: number of processed bytes
1115 void ixgbe_update_tx_ring_stats(struct ixgbe_ring
*tx_ring
,
1116 struct ixgbe_q_vector
*q_vector
, u64 pkts
,
1119 u64_stats_update_begin(&tx_ring
->syncp
);
1120 tx_ring
->stats
.bytes
+= bytes
;
1121 tx_ring
->stats
.packets
+= pkts
;
1122 u64_stats_update_end(&tx_ring
->syncp
);
1123 q_vector
->tx
.total_bytes
+= bytes
;
1124 q_vector
->tx
.total_packets
+= pkts
;
1128 * ixgbe_update_rx_ring_stats - Update Rx ring specific counters
1129 * @rx_ring: ring to update
1130 * @q_vector: queue vector ring belongs to
1131 * @pkts: number of processed packets
1132 * @bytes: number of processed bytes
1134 void ixgbe_update_rx_ring_stats(struct ixgbe_ring
*rx_ring
,
1135 struct ixgbe_q_vector
*q_vector
, u64 pkts
,
1138 u64_stats_update_begin(&rx_ring
->syncp
);
1139 rx_ring
->stats
.bytes
+= bytes
;
1140 rx_ring
->stats
.packets
+= pkts
;
1141 u64_stats_update_end(&rx_ring
->syncp
);
1142 q_vector
->rx
.total_bytes
+= bytes
;
1143 q_vector
->rx
.total_packets
+= pkts
;
1147 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
1148 * @q_vector: structure containing interrupt and ring information
1149 * @tx_ring: tx ring to clean
1150 * @napi_budget: Used to determine if we are in netpoll
1152 static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector
*q_vector
,
1153 struct ixgbe_ring
*tx_ring
, int napi_budget
)
1155 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1156 struct ixgbe_tx_buffer
*tx_buffer
;
1157 union ixgbe_adv_tx_desc
*tx_desc
;
1158 unsigned int total_bytes
= 0, total_packets
= 0, total_ipsec
= 0;
1159 unsigned int budget
= q_vector
->tx
.work_limit
;
1160 unsigned int i
= tx_ring
->next_to_clean
;
1161 struct netdev_queue
*txq
;
1163 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
1166 tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
1167 tx_desc
= IXGBE_TX_DESC(tx_ring
, i
);
1168 i
-= tx_ring
->count
;
1171 union ixgbe_adv_tx_desc
*eop_desc
= tx_buffer
->next_to_watch
;
1173 /* if next_to_watch is not set then there is no work pending */
1177 /* prevent any other reads prior to eop_desc */
1180 /* if DD is not set pending work has not been completed */
1181 if (!(eop_desc
->wb
.status
& cpu_to_le32(IXGBE_TXD_STAT_DD
)))
1184 /* clear next_to_watch to prevent false hangs */
1185 tx_buffer
->next_to_watch
= NULL
;
1187 /* update the statistics for this packet */
1188 total_bytes
+= tx_buffer
->bytecount
;
1189 total_packets
+= tx_buffer
->gso_segs
;
1190 if (tx_buffer
->tx_flags
& IXGBE_TX_FLAGS_IPSEC
)
1194 if (ring_is_xdp(tx_ring
))
1195 xdp_return_frame(tx_buffer
->xdpf
);
1197 napi_consume_skb(tx_buffer
->skb
, napi_budget
);
1199 /* unmap skb header data */
1200 dma_unmap_single(tx_ring
->dev
,
1201 dma_unmap_addr(tx_buffer
, dma
),
1202 dma_unmap_len(tx_buffer
, len
),
1205 /* clear tx_buffer data */
1206 dma_unmap_len_set(tx_buffer
, len
, 0);
1208 /* unmap remaining buffers */
1209 while (tx_desc
!= eop_desc
) {
1214 i
-= tx_ring
->count
;
1215 tx_buffer
= tx_ring
->tx_buffer_info
;
1216 tx_desc
= IXGBE_TX_DESC(tx_ring
, 0);
1219 /* unmap any remaining paged data */
1220 if (dma_unmap_len(tx_buffer
, len
)) {
1221 dma_unmap_page(tx_ring
->dev
,
1222 dma_unmap_addr(tx_buffer
, dma
),
1223 dma_unmap_len(tx_buffer
, len
),
1225 dma_unmap_len_set(tx_buffer
, len
, 0);
1229 /* move us one more past the eop_desc for start of next pkt */
1234 i
-= tx_ring
->count
;
1235 tx_buffer
= tx_ring
->tx_buffer_info
;
1236 tx_desc
= IXGBE_TX_DESC(tx_ring
, 0);
1239 /* issue prefetch for next Tx descriptor */
1242 /* update budget accounting */
1244 } while (likely(budget
));
1246 i
+= tx_ring
->count
;
1247 tx_ring
->next_to_clean
= i
;
1248 ixgbe_update_tx_ring_stats(tx_ring
, q_vector
, total_packets
,
1250 adapter
->tx_ipsec
+= total_ipsec
;
1252 if (check_for_tx_hang(tx_ring
) && ixgbe_check_tx_hang(tx_ring
)) {
1253 /* schedule immediate reset if we believe we hung */
1254 struct ixgbe_hw
*hw
= &adapter
->hw
;
1255 e_err(drv
, "Detected Tx Unit Hang %s\n"
1257 " TDH, TDT <%x>, <%x>\n"
1258 " next_to_use <%x>\n"
1259 " next_to_clean <%x>\n"
1260 "tx_buffer_info[next_to_clean]\n"
1261 " time_stamp <%lx>\n"
1263 ring_is_xdp(tx_ring
) ? "(XDP)" : "",
1264 tx_ring
->queue_index
,
1265 IXGBE_READ_REG(hw
, IXGBE_TDH(tx_ring
->reg_idx
)),
1266 IXGBE_READ_REG(hw
, IXGBE_TDT(tx_ring
->reg_idx
)),
1267 tx_ring
->next_to_use
, i
,
1268 tx_ring
->tx_buffer_info
[i
].time_stamp
, jiffies
);
1270 if (!ring_is_xdp(tx_ring
))
1271 netif_stop_subqueue(tx_ring
->netdev
,
1272 tx_ring
->queue_index
);
1275 "tx hang %d detected on queue %d, resetting adapter\n",
1276 adapter
->tx_timeout_count
+ 1, tx_ring
->queue_index
);
1278 /* schedule immediate reset if we believe we hung */
1279 ixgbe_tx_timeout_reset(adapter
);
1281 /* the adapter is about to reset, no point in enabling stuff */
1285 if (ring_is_xdp(tx_ring
))
1288 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
1289 txq
= netdev_get_tx_queue(tx_ring
->netdev
, tx_ring
->queue_index
);
1290 if (!__netif_txq_completed_wake(txq
, total_packets
, total_bytes
,
1291 ixgbe_desc_unused(tx_ring
),
1293 !netif_carrier_ok(tx_ring
->netdev
) ||
1294 test_bit(__IXGBE_DOWN
, &adapter
->state
)))
1295 ++tx_ring
->tx_stats
.restart_queue
;
1300 #ifdef CONFIG_IXGBE_DCA
1301 static void ixgbe_update_tx_dca(struct ixgbe_adapter
*adapter
,
1302 struct ixgbe_ring
*tx_ring
,
1305 struct ixgbe_hw
*hw
= &adapter
->hw
;
1309 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1310 txctrl
= dca3_get_tag(tx_ring
->dev
, cpu
);
1312 switch (hw
->mac
.type
) {
1313 case ixgbe_mac_82598EB
:
1314 reg_offset
= IXGBE_DCA_TXCTRL(tx_ring
->reg_idx
);
1316 case ixgbe_mac_82599EB
:
1317 case ixgbe_mac_X540
:
1318 reg_offset
= IXGBE_DCA_TXCTRL_82599(tx_ring
->reg_idx
);
1319 txctrl
<<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599
;
1322 /* for unknown hardware do not write register */
1327 * We can enable relaxed ordering for reads, but not writes when
1328 * DCA is enabled. This is due to a known issue in some chipsets
1329 * which will cause the DCA tag to be cleared.
1331 txctrl
|= IXGBE_DCA_TXCTRL_DESC_RRO_EN
|
1332 IXGBE_DCA_TXCTRL_DATA_RRO_EN
|
1333 IXGBE_DCA_TXCTRL_DESC_DCA_EN
;
1335 IXGBE_WRITE_REG(hw
, reg_offset
, txctrl
);
1338 static void ixgbe_update_rx_dca(struct ixgbe_adapter
*adapter
,
1339 struct ixgbe_ring
*rx_ring
,
1342 struct ixgbe_hw
*hw
= &adapter
->hw
;
1344 u8 reg_idx
= rx_ring
->reg_idx
;
1346 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1347 rxctrl
= dca3_get_tag(rx_ring
->dev
, cpu
);
1349 switch (hw
->mac
.type
) {
1350 case ixgbe_mac_82599EB
:
1351 case ixgbe_mac_X540
:
1352 rxctrl
<<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599
;
1359 * We can enable relaxed ordering for reads, but not writes when
1360 * DCA is enabled. This is due to a known issue in some chipsets
1361 * which will cause the DCA tag to be cleared.
1363 rxctrl
|= IXGBE_DCA_RXCTRL_DESC_RRO_EN
|
1364 IXGBE_DCA_RXCTRL_DATA_DCA_EN
|
1365 IXGBE_DCA_RXCTRL_DESC_DCA_EN
;
1367 IXGBE_WRITE_REG(hw
, IXGBE_DCA_RXCTRL(reg_idx
), rxctrl
);
1370 static void ixgbe_update_dca(struct ixgbe_q_vector
*q_vector
)
1372 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1373 struct ixgbe_ring
*ring
;
1374 int cpu
= get_cpu();
1376 if (q_vector
->cpu
== cpu
)
1379 ixgbe_for_each_ring(ring
, q_vector
->tx
)
1380 ixgbe_update_tx_dca(adapter
, ring
, cpu
);
1382 ixgbe_for_each_ring(ring
, q_vector
->rx
)
1383 ixgbe_update_rx_dca(adapter
, ring
, cpu
);
1385 q_vector
->cpu
= cpu
;
1390 static void ixgbe_setup_dca(struct ixgbe_adapter
*adapter
)
1394 /* always use CB2 mode, difference is masked in the CB driver */
1395 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1396 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
,
1397 IXGBE_DCA_CTRL_DCA_MODE_CB2
);
1399 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
,
1400 IXGBE_DCA_CTRL_DCA_DISABLE
);
1402 for (i
= 0; i
< adapter
->num_q_vectors
; i
++) {
1403 adapter
->q_vector
[i
]->cpu
= -1;
1404 ixgbe_update_dca(adapter
->q_vector
[i
]);
1408 static int __ixgbe_notify_dca(struct device
*dev
, void *data
)
1410 struct ixgbe_adapter
*adapter
= dev_get_drvdata(dev
);
1411 unsigned long event
= *(unsigned long *)data
;
1413 if (!(adapter
->flags
& IXGBE_FLAG_DCA_CAPABLE
))
1417 case DCA_PROVIDER_ADD
:
1418 /* if we're already enabled, don't do it again */
1419 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1421 if (dca_add_requester(dev
) == 0) {
1422 adapter
->flags
|= IXGBE_FLAG_DCA_ENABLED
;
1423 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
,
1424 IXGBE_DCA_CTRL_DCA_MODE_CB2
);
1427 fallthrough
; /* DCA is disabled. */
1428 case DCA_PROVIDER_REMOVE
:
1429 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
1430 dca_remove_requester(dev
);
1431 adapter
->flags
&= ~IXGBE_FLAG_DCA_ENABLED
;
1432 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
,
1433 IXGBE_DCA_CTRL_DCA_DISABLE
);
1441 #endif /* CONFIG_IXGBE_DCA */
1443 #define IXGBE_RSS_L4_TYPES_MASK \
1444 ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
1445 (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
1446 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
1447 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
1449 static inline void ixgbe_rx_hash(struct ixgbe_ring
*ring
,
1450 union ixgbe_adv_rx_desc
*rx_desc
,
1451 struct sk_buff
*skb
)
1455 if (!(ring
->netdev
->features
& NETIF_F_RXHASH
))
1458 rss_type
= le16_to_cpu(rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
) &
1459 IXGBE_RXDADV_RSSTYPE_MASK
;
1464 skb_set_hash(skb
, le32_to_cpu(rx_desc
->wb
.lower
.hi_dword
.rss
),
1465 (IXGBE_RSS_L4_TYPES_MASK
& (1ul << rss_type
)) ?
1466 PKT_HASH_TYPE_L4
: PKT_HASH_TYPE_L3
);
1471 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1472 * @ring: structure containing ring specific data
1473 * @rx_desc: advanced rx descriptor
1475 * Returns : true if it is FCoE pkt
1477 static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring
*ring
,
1478 union ixgbe_adv_rx_desc
*rx_desc
)
1480 __le16 pkt_info
= rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
1482 return test_bit(__IXGBE_RX_FCOE
, &ring
->state
) &&
1483 ((pkt_info
& cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK
)) ==
1484 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE
<<
1485 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT
)));
1488 #endif /* IXGBE_FCOE */
1490 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1491 * @ring: structure containing ring specific data
1492 * @rx_desc: current Rx descriptor being processed
1493 * @skb: skb currently being received and modified
1495 static inline void ixgbe_rx_checksum(struct ixgbe_ring
*ring
,
1496 union ixgbe_adv_rx_desc
*rx_desc
,
1497 struct sk_buff
*skb
)
1499 __le16 pkt_info
= rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
1500 bool encap_pkt
= false;
1502 skb_checksum_none_assert(skb
);
1504 /* Rx csum disabled */
1505 if (!(ring
->netdev
->features
& NETIF_F_RXCSUM
))
1508 /* check for VXLAN and Geneve packets */
1509 if (pkt_info
& cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN
)) {
1511 skb
->encapsulation
= 1;
1514 /* if IP and error */
1515 if (ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_IPCS
) &&
1516 ixgbe_test_staterr(rx_desc
, IXGBE_RXDADV_ERR_IPE
)) {
1517 ring
->rx_stats
.csum_err
++;
1521 if (!ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_L4CS
))
1524 if (ixgbe_test_staterr(rx_desc
, IXGBE_RXDADV_ERR_TCPE
)) {
1526 * 82599 errata, UDP frames with a 0 checksum can be marked as
1529 if ((pkt_info
& cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP
)) &&
1530 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR
, &ring
->state
))
1533 ring
->rx_stats
.csum_err
++;
1537 /* It must be a TCP or UDP packet with a valid checksum */
1538 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1540 if (!ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_OUTERIPCS
))
1543 if (ixgbe_test_staterr(rx_desc
, IXGBE_RXDADV_ERR_OUTERIPER
)) {
1544 skb
->ip_summed
= CHECKSUM_NONE
;
1547 /* If we checked the outer header let the stack know */
1548 skb
->csum_level
= 1;
1552 static unsigned int ixgbe_rx_offset(struct ixgbe_ring
*rx_ring
)
1554 return ring_uses_build_skb(rx_ring
) ? IXGBE_SKB_PAD
: 0;
1557 static bool ixgbe_alloc_mapped_page(struct ixgbe_ring
*rx_ring
,
1558 struct ixgbe_rx_buffer
*bi
)
1560 struct page
*page
= bi
->page
;
1563 /* since we are recycling buffers we should seldom need to alloc */
1567 /* alloc new page for storage */
1568 page
= dev_alloc_pages(ixgbe_rx_pg_order(rx_ring
));
1569 if (unlikely(!page
)) {
1570 rx_ring
->rx_stats
.alloc_rx_page_failed
++;
1574 /* map page for use */
1575 dma
= dma_map_page_attrs(rx_ring
->dev
, page
, 0,
1576 ixgbe_rx_pg_size(rx_ring
),
1581 * if mapping failed free memory back to system since
1582 * there isn't much point in holding memory we can't use
1584 if (dma_mapping_error(rx_ring
->dev
, dma
)) {
1585 __free_pages(page
, ixgbe_rx_pg_order(rx_ring
));
1587 rx_ring
->rx_stats
.alloc_rx_page_failed
++;
1593 bi
->page_offset
= rx_ring
->rx_offset
;
1594 page_ref_add(page
, USHRT_MAX
- 1);
1595 bi
->pagecnt_bias
= USHRT_MAX
;
1596 rx_ring
->rx_stats
.alloc_rx_page
++;
1602 * ixgbe_alloc_rx_buffers - Replace used receive buffers
1603 * @rx_ring: ring to place buffers on
1604 * @cleaned_count: number of buffers to replace
1606 void ixgbe_alloc_rx_buffers(struct ixgbe_ring
*rx_ring
, u16 cleaned_count
)
1608 union ixgbe_adv_rx_desc
*rx_desc
;
1609 struct ixgbe_rx_buffer
*bi
;
1610 u16 i
= rx_ring
->next_to_use
;
1617 rx_desc
= IXGBE_RX_DESC(rx_ring
, i
);
1618 bi
= &rx_ring
->rx_buffer_info
[i
];
1619 i
-= rx_ring
->count
;
1621 bufsz
= ixgbe_rx_bufsz(rx_ring
);
1624 if (!ixgbe_alloc_mapped_page(rx_ring
, bi
))
1627 /* sync the buffer for use by the device */
1628 dma_sync_single_range_for_device(rx_ring
->dev
, bi
->dma
,
1629 bi
->page_offset
, bufsz
,
1633 * Refresh the desc even if buffer_addrs didn't change
1634 * because each write-back erases this info.
1636 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->dma
+ bi
->page_offset
);
1642 rx_desc
= IXGBE_RX_DESC(rx_ring
, 0);
1643 bi
= rx_ring
->rx_buffer_info
;
1644 i
-= rx_ring
->count
;
1647 /* clear the length for the next_to_use descriptor */
1648 rx_desc
->wb
.upper
.length
= 0;
1651 } while (cleaned_count
);
1653 i
+= rx_ring
->count
;
1655 if (rx_ring
->next_to_use
!= i
) {
1656 rx_ring
->next_to_use
= i
;
1658 /* update next to alloc since we have filled the ring */
1659 rx_ring
->next_to_alloc
= i
;
1661 /* Force memory writes to complete before letting h/w
1662 * know there are new descriptors to fetch. (Only
1663 * applicable for weak-ordered memory model archs,
1667 writel(i
, rx_ring
->tail
);
1671 static void ixgbe_set_rsc_gso_size(struct ixgbe_ring
*ring
,
1672 struct sk_buff
*skb
)
1674 u16 hdr_len
= skb_headlen(skb
);
1676 /* set gso_size to avoid messing up TCP MSS */
1677 skb_shinfo(skb
)->gso_size
= DIV_ROUND_UP((skb
->len
- hdr_len
),
1678 IXGBE_CB(skb
)->append_cnt
);
1679 skb_shinfo(skb
)->gso_type
= SKB_GSO_TCPV4
;
1682 static void ixgbe_update_rsc_stats(struct ixgbe_ring
*rx_ring
,
1683 struct sk_buff
*skb
)
1685 /* if append_cnt is 0 then frame is not RSC */
1686 if (!IXGBE_CB(skb
)->append_cnt
)
1689 rx_ring
->rx_stats
.rsc_count
+= IXGBE_CB(skb
)->append_cnt
;
1690 rx_ring
->rx_stats
.rsc_flush
++;
1692 ixgbe_set_rsc_gso_size(rx_ring
, skb
);
1694 /* gso_size is computed using append_cnt so always clear it last */
1695 IXGBE_CB(skb
)->append_cnt
= 0;
1699 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1700 * @rx_ring: rx descriptor ring packet is being transacted on
1701 * @rx_desc: pointer to the EOP Rx descriptor
1702 * @skb: pointer to current skb being populated
1704 * This function checks the ring, descriptor, and packet information in
1705 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1706 * other fields within the skb.
1708 void ixgbe_process_skb_fields(struct ixgbe_ring
*rx_ring
,
1709 union ixgbe_adv_rx_desc
*rx_desc
,
1710 struct sk_buff
*skb
)
1712 struct net_device
*dev
= rx_ring
->netdev
;
1713 u32 flags
= rx_ring
->q_vector
->adapter
->flags
;
1715 ixgbe_update_rsc_stats(rx_ring
, skb
);
1717 ixgbe_rx_hash(rx_ring
, rx_desc
, skb
);
1719 ixgbe_rx_checksum(rx_ring
, rx_desc
, skb
);
1721 if (unlikely(flags
& IXGBE_FLAG_RX_HWTSTAMP_ENABLED
))
1722 ixgbe_ptp_rx_hwtstamp(rx_ring
, rx_desc
, skb
);
1724 if ((dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
) &&
1725 ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_VP
)) {
1726 u16 vid
= le16_to_cpu(rx_desc
->wb
.upper
.vlan
);
1727 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), vid
);
1730 if (ixgbe_test_staterr(rx_desc
, IXGBE_RXDADV_STAT_SECP
))
1731 ixgbe_ipsec_rx(rx_ring
, rx_desc
, skb
);
1733 /* record Rx queue, or update MACVLAN statistics */
1734 if (netif_is_ixgbe(dev
))
1735 skb_record_rx_queue(skb
, rx_ring
->queue_index
);
1737 macvlan_count_rx(netdev_priv(dev
), skb
->len
+ ETH_HLEN
, true,
1740 skb
->protocol
= eth_type_trans(skb
, dev
);
1743 void ixgbe_rx_skb(struct ixgbe_q_vector
*q_vector
,
1744 struct sk_buff
*skb
)
1746 napi_gro_receive(&q_vector
->napi
, skb
);
1750 * ixgbe_is_non_eop - process handling of non-EOP buffers
1751 * @rx_ring: Rx ring being processed
1752 * @rx_desc: Rx descriptor for current buffer
1753 * @skb: Current socket buffer containing buffer in progress
1755 * This function updates next to clean. If the buffer is an EOP buffer
1756 * this function exits returning false, otherwise it will place the
1757 * sk_buff in the next buffer to be chained and return true indicating
1758 * that this is in fact a non-EOP buffer.
1760 static bool ixgbe_is_non_eop(struct ixgbe_ring
*rx_ring
,
1761 union ixgbe_adv_rx_desc
*rx_desc
,
1762 struct sk_buff
*skb
)
1764 u32 ntc
= rx_ring
->next_to_clean
+ 1;
1766 /* fetch, update, and store next to clean */
1767 ntc
= (ntc
< rx_ring
->count
) ? ntc
: 0;
1768 rx_ring
->next_to_clean
= ntc
;
1770 prefetch(IXGBE_RX_DESC(rx_ring
, ntc
));
1772 /* update RSC append count if present */
1773 if (ring_is_rsc_enabled(rx_ring
)) {
1774 __le32 rsc_enabled
= rx_desc
->wb
.lower
.lo_dword
.data
&
1775 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK
);
1777 if (unlikely(rsc_enabled
)) {
1778 u32 rsc_cnt
= le32_to_cpu(rsc_enabled
);
1780 rsc_cnt
>>= IXGBE_RXDADV_RSCCNT_SHIFT
;
1781 IXGBE_CB(skb
)->append_cnt
+= rsc_cnt
- 1;
1783 /* update ntc based on RSC value */
1784 ntc
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
1785 ntc
&= IXGBE_RXDADV_NEXTP_MASK
;
1786 ntc
>>= IXGBE_RXDADV_NEXTP_SHIFT
;
1790 /* if we are the last buffer then there is nothing else to do */
1791 if (likely(ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_EOP
)))
1794 /* place skb in next buffer to be received */
1795 rx_ring
->rx_buffer_info
[ntc
].skb
= skb
;
1796 rx_ring
->rx_stats
.non_eop_descs
++;
1802 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1803 * @rx_ring: rx descriptor ring packet is being transacted on
1804 * @skb: pointer to current skb being adjusted
1806 * This function is an ixgbe specific version of __pskb_pull_tail. The
1807 * main difference between this version and the original function is that
1808 * this function can make several assumptions about the state of things
1809 * that allow for significant optimizations versus the standard function.
1810 * As a result we can do things like drop a frag and maintain an accurate
1811 * truesize for the skb.
1813 static void ixgbe_pull_tail(struct ixgbe_ring
*rx_ring
,
1814 struct sk_buff
*skb
)
1816 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[0];
1818 unsigned int pull_len
;
1821 * it is valid to use page_address instead of kmap since we are
1822 * working with pages allocated out of the lomem pool per
1823 * alloc_page(GFP_ATOMIC)
1825 va
= skb_frag_address(frag
);
1828 * we need the header to contain the greater of either ETH_HLEN or
1829 * 60 bytes if the skb->len is less than 60 for skb_pad.
1831 pull_len
= eth_get_headlen(skb
->dev
, va
, IXGBE_RX_HDR_SIZE
);
1833 /* align pull length to size of long to optimize memcpy performance */
1834 skb_copy_to_linear_data(skb
, va
, ALIGN(pull_len
, sizeof(long)));
1836 /* update all of the pointers */
1837 skb_frag_size_sub(frag
, pull_len
);
1838 skb_frag_off_add(frag
, pull_len
);
1839 skb
->data_len
-= pull_len
;
1840 skb
->tail
+= pull_len
;
1844 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1845 * @rx_ring: rx descriptor ring packet is being transacted on
1846 * @skb: pointer to current skb being updated
1848 * This function provides a basic DMA sync up for the first fragment of an
1849 * skb. The reason for doing this is that the first fragment cannot be
1850 * unmapped until we have reached the end of packet descriptor for a buffer
1853 static void ixgbe_dma_sync_frag(struct ixgbe_ring
*rx_ring
,
1854 struct sk_buff
*skb
)
1856 if (ring_uses_build_skb(rx_ring
)) {
1857 unsigned long mask
= (unsigned long)ixgbe_rx_pg_size(rx_ring
) - 1;
1858 unsigned long offset
= (unsigned long)(skb
->data
) & mask
;
1860 dma_sync_single_range_for_cpu(rx_ring
->dev
,
1866 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[0];
1868 dma_sync_single_range_for_cpu(rx_ring
->dev
,
1871 skb_frag_size(frag
),
1875 /* If the page was released, just unmap it. */
1876 if (unlikely(IXGBE_CB(skb
)->page_released
)) {
1877 dma_unmap_page_attrs(rx_ring
->dev
, IXGBE_CB(skb
)->dma
,
1878 ixgbe_rx_pg_size(rx_ring
),
1885 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1886 * @rx_ring: rx descriptor ring packet is being transacted on
1887 * @rx_desc: pointer to the EOP Rx descriptor
1888 * @skb: pointer to current skb being fixed
1890 * Check if the skb is valid in the XDP case it will be an error pointer.
1891 * Return true in this case to abort processing and advance to next
1894 * Check for corrupted packet headers caused by senders on the local L2
1895 * embedded NIC switch not setting up their Tx Descriptors right. These
1896 * should be very rare.
1898 * Also address the case where we are pulling data in on pages only
1899 * and as such no data is present in the skb header.
1901 * In addition if skb is not at least 60 bytes we need to pad it so that
1902 * it is large enough to qualify as a valid Ethernet frame.
1904 * Returns true if an error was encountered and skb was freed.
1906 bool ixgbe_cleanup_headers(struct ixgbe_ring
*rx_ring
,
1907 union ixgbe_adv_rx_desc
*rx_desc
,
1908 struct sk_buff
*skb
)
1910 struct net_device
*netdev
= rx_ring
->netdev
;
1912 /* XDP packets use error pointer so abort at this point */
1916 /* Verify netdev is present, and that packet does not have any
1917 * errors that would be unacceptable to the netdev.
1920 (unlikely(ixgbe_test_staterr(rx_desc
,
1921 IXGBE_RXDADV_ERR_FRAME_ERR_MASK
) &&
1922 !(netdev
->features
& NETIF_F_RXALL
)))) {
1923 dev_kfree_skb_any(skb
);
1927 /* place header in linear portion of buffer */
1928 if (!skb_headlen(skb
))
1929 ixgbe_pull_tail(rx_ring
, skb
);
1932 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1933 if (ixgbe_rx_is_fcoe(rx_ring
, rx_desc
))
1937 /* if eth_skb_pad returns an error the skb was freed */
1938 if (eth_skb_pad(skb
))
1945 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1946 * @rx_ring: rx descriptor ring to store buffers on
1947 * @old_buff: donor buffer to have page reused
1949 * Synchronizes page for reuse by the adapter
1951 static void ixgbe_reuse_rx_page(struct ixgbe_ring
*rx_ring
,
1952 struct ixgbe_rx_buffer
*old_buff
)
1954 struct ixgbe_rx_buffer
*new_buff
;
1955 u16 nta
= rx_ring
->next_to_alloc
;
1957 new_buff
= &rx_ring
->rx_buffer_info
[nta
];
1959 /* update, and store next to alloc */
1961 rx_ring
->next_to_alloc
= (nta
< rx_ring
->count
) ? nta
: 0;
1963 /* Transfer page from old buffer to new buffer.
1964 * Move each member individually to avoid possible store
1965 * forwarding stalls and unnecessary copy of skb.
1967 new_buff
->dma
= old_buff
->dma
;
1968 new_buff
->page
= old_buff
->page
;
1969 new_buff
->page_offset
= old_buff
->page_offset
;
1970 new_buff
->pagecnt_bias
= old_buff
->pagecnt_bias
;
1973 static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer
*rx_buffer
,
1974 int rx_buffer_pgcnt
)
1976 unsigned int pagecnt_bias
= rx_buffer
->pagecnt_bias
;
1977 struct page
*page
= rx_buffer
->page
;
1979 /* avoid re-using remote and pfmemalloc pages */
1980 if (!dev_page_is_reusable(page
))
1983 #if (PAGE_SIZE < 8192)
1984 /* if we are only owner of page we can reuse it */
1985 if (unlikely((rx_buffer_pgcnt
- pagecnt_bias
) > 1))
1988 /* The last offset is a bit aggressive in that we assume the
1989 * worst case of FCoE being enabled and using a 3K buffer.
1990 * However this should have minimal impact as the 1K extra is
1991 * still less than one buffer in size.
1993 #define IXGBE_LAST_OFFSET \
1994 (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K)
1995 if (rx_buffer
->page_offset
> IXGBE_LAST_OFFSET
)
1999 /* If we have drained the page fragment pool we need to update
2000 * the pagecnt_bias and page count so that we fully restock the
2001 * number of references the driver holds.
2003 if (unlikely(pagecnt_bias
== 1)) {
2004 page_ref_add(page
, USHRT_MAX
- 1);
2005 rx_buffer
->pagecnt_bias
= USHRT_MAX
;
2012 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
2013 * @rx_ring: rx descriptor ring to transact packets on
2014 * @rx_buffer: buffer containing page to add
2015 * @skb: sk_buff to place the data into
2016 * @size: size of data in rx_buffer
2018 * This function will add the data contained in rx_buffer->page to the skb.
2019 * This is done either through a direct copy if the data in the buffer is
2020 * less than the skb header size, otherwise it will just attach the page as
2021 * a frag to the skb.
2023 * The function will then update the page offset if necessary and return
2024 * true if the buffer can be reused by the adapter.
2026 static void ixgbe_add_rx_frag(struct ixgbe_ring
*rx_ring
,
2027 struct ixgbe_rx_buffer
*rx_buffer
,
2028 struct sk_buff
*skb
,
2031 #if (PAGE_SIZE < 8192)
2032 unsigned int truesize
= ixgbe_rx_pg_size(rx_ring
) / 2;
2034 unsigned int truesize
= rx_ring
->rx_offset
?
2035 SKB_DATA_ALIGN(rx_ring
->rx_offset
+ size
) :
2036 SKB_DATA_ALIGN(size
);
2038 skb_add_rx_frag(skb
, skb_shinfo(skb
)->nr_frags
, rx_buffer
->page
,
2039 rx_buffer
->page_offset
, size
, truesize
);
2040 #if (PAGE_SIZE < 8192)
2041 rx_buffer
->page_offset
^= truesize
;
2043 rx_buffer
->page_offset
+= truesize
;
2047 static struct ixgbe_rx_buffer
*ixgbe_get_rx_buffer(struct ixgbe_ring
*rx_ring
,
2048 union ixgbe_adv_rx_desc
*rx_desc
,
2049 struct sk_buff
**skb
,
2050 const unsigned int size
,
2051 int *rx_buffer_pgcnt
)
2053 struct ixgbe_rx_buffer
*rx_buffer
;
2055 rx_buffer
= &rx_ring
->rx_buffer_info
[rx_ring
->next_to_clean
];
2057 #if (PAGE_SIZE < 8192)
2058 page_count(rx_buffer
->page
);
2062 prefetchw(rx_buffer
->page
);
2063 *skb
= rx_buffer
->skb
;
2065 /* Delay unmapping of the first packet. It carries the header
2066 * information, HW may still access the header after the writeback.
2067 * Only unmap it when EOP is reached
2069 if (!ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_EOP
)) {
2074 ixgbe_dma_sync_frag(rx_ring
, *skb
);
2077 /* we are reusing so sync this buffer for CPU use */
2078 dma_sync_single_range_for_cpu(rx_ring
->dev
,
2080 rx_buffer
->page_offset
,
2084 rx_buffer
->pagecnt_bias
--;
2089 static void ixgbe_put_rx_buffer(struct ixgbe_ring
*rx_ring
,
2090 struct ixgbe_rx_buffer
*rx_buffer
,
2091 struct sk_buff
*skb
,
2092 int rx_buffer_pgcnt
)
2094 if (ixgbe_can_reuse_rx_page(rx_buffer
, rx_buffer_pgcnt
)) {
2095 /* hand second half of page back to the ring */
2096 ixgbe_reuse_rx_page(rx_ring
, rx_buffer
);
2098 if (!IS_ERR(skb
) && IXGBE_CB(skb
)->dma
== rx_buffer
->dma
) {
2099 /* the page has been released from the ring */
2100 IXGBE_CB(skb
)->page_released
= true;
2102 /* we are not reusing the buffer so unmap it */
2103 dma_unmap_page_attrs(rx_ring
->dev
, rx_buffer
->dma
,
2104 ixgbe_rx_pg_size(rx_ring
),
2108 __page_frag_cache_drain(rx_buffer
->page
,
2109 rx_buffer
->pagecnt_bias
);
2112 /* clear contents of rx_buffer */
2113 rx_buffer
->page
= NULL
;
2114 rx_buffer
->skb
= NULL
;
2117 static struct sk_buff
*ixgbe_construct_skb(struct ixgbe_ring
*rx_ring
,
2118 struct ixgbe_rx_buffer
*rx_buffer
,
2119 struct xdp_buff
*xdp
,
2120 union ixgbe_adv_rx_desc
*rx_desc
)
2122 unsigned int size
= xdp
->data_end
- xdp
->data
;
2123 #if (PAGE_SIZE < 8192)
2124 unsigned int truesize
= ixgbe_rx_pg_size(rx_ring
) / 2;
2126 unsigned int truesize
= SKB_DATA_ALIGN(xdp
->data_end
-
2127 xdp
->data_hard_start
);
2129 struct sk_buff
*skb
;
2131 /* prefetch first cache line of first page */
2132 net_prefetch(xdp
->data
);
2134 /* Note, we get here by enabling legacy-rx via:
2136 * ethtool --set-priv-flags <dev> legacy-rx on
2138 * In this mode, we currently get 0 extra XDP headroom as
2139 * opposed to having legacy-rx off, where we process XDP
2140 * packets going to stack via ixgbe_build_skb(). The latter
2141 * provides us currently with 192 bytes of headroom.
2143 * For ixgbe_construct_skb() mode it means that the
2144 * xdp->data_meta will always point to xdp->data, since
2145 * the helper cannot expand the head. Should this ever
2146 * change in future for legacy-rx mode on, then lets also
2147 * add xdp->data_meta handling here.
2150 /* allocate a skb to store the frags */
2151 skb
= napi_alloc_skb(&rx_ring
->q_vector
->napi
, IXGBE_RX_HDR_SIZE
);
2155 if (size
> IXGBE_RX_HDR_SIZE
) {
2156 if (!ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_EOP
))
2157 IXGBE_CB(skb
)->dma
= rx_buffer
->dma
;
2159 skb_add_rx_frag(skb
, 0, rx_buffer
->page
,
2160 xdp
->data
- page_address(rx_buffer
->page
),
2162 #if (PAGE_SIZE < 8192)
2163 rx_buffer
->page_offset
^= truesize
;
2165 rx_buffer
->page_offset
+= truesize
;
2168 memcpy(__skb_put(skb
, size
),
2169 xdp
->data
, ALIGN(size
, sizeof(long)));
2170 rx_buffer
->pagecnt_bias
++;
2176 static struct sk_buff
*ixgbe_build_skb(struct ixgbe_ring
*rx_ring
,
2177 struct ixgbe_rx_buffer
*rx_buffer
,
2178 struct xdp_buff
*xdp
,
2179 union ixgbe_adv_rx_desc
*rx_desc
)
2181 unsigned int metasize
= xdp
->data
- xdp
->data_meta
;
2182 #if (PAGE_SIZE < 8192)
2183 unsigned int truesize
= ixgbe_rx_pg_size(rx_ring
) / 2;
2185 unsigned int truesize
= SKB_DATA_ALIGN(sizeof(struct skb_shared_info
)) +
2186 SKB_DATA_ALIGN(xdp
->data_end
-
2187 xdp
->data_hard_start
);
2189 struct sk_buff
*skb
;
2191 /* Prefetch first cache line of first page. If xdp->data_meta
2192 * is unused, this points extactly as xdp->data, otherwise we
2193 * likely have a consumer accessing first few bytes of meta
2194 * data, and then actual data.
2196 net_prefetch(xdp
->data_meta
);
2198 /* build an skb to around the page buffer */
2199 skb
= napi_build_skb(xdp
->data_hard_start
, truesize
);
2203 /* update pointers within the skb to store the data */
2204 skb_reserve(skb
, xdp
->data
- xdp
->data_hard_start
);
2205 __skb_put(skb
, xdp
->data_end
- xdp
->data
);
2207 skb_metadata_set(skb
, metasize
);
2209 /* record DMA address if this is the start of a chain of buffers */
2210 if (!ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_EOP
))
2211 IXGBE_CB(skb
)->dma
= rx_buffer
->dma
;
2213 /* update buffer offset */
2214 #if (PAGE_SIZE < 8192)
2215 rx_buffer
->page_offset
^= truesize
;
2217 rx_buffer
->page_offset
+= truesize
;
2223 static struct sk_buff
*ixgbe_run_xdp(struct ixgbe_adapter
*adapter
,
2224 struct ixgbe_ring
*rx_ring
,
2225 struct xdp_buff
*xdp
)
2227 int err
, result
= IXGBE_XDP_PASS
;
2228 struct bpf_prog
*xdp_prog
;
2229 struct ixgbe_ring
*ring
;
2230 struct xdp_frame
*xdpf
;
2233 xdp_prog
= READ_ONCE(rx_ring
->xdp_prog
);
2238 prefetchw(xdp
->data_hard_start
); /* xdp_frame write */
2240 act
= bpf_prog_run_xdp(xdp_prog
, xdp
);
2245 xdpf
= xdp_convert_buff_to_frame(xdp
);
2246 if (unlikely(!xdpf
))
2248 ring
= ixgbe_determine_xdp_ring(adapter
);
2249 if (static_branch_unlikely(&ixgbe_xdp_locking_key
))
2250 spin_lock(&ring
->tx_lock
);
2251 result
= ixgbe_xmit_xdp_ring(ring
, xdpf
);
2252 if (static_branch_unlikely(&ixgbe_xdp_locking_key
))
2253 spin_unlock(&ring
->tx_lock
);
2254 if (result
== IXGBE_XDP_CONSUMED
)
2258 err
= xdp_do_redirect(adapter
->netdev
, xdp
, xdp_prog
);
2261 result
= IXGBE_XDP_REDIR
;
2264 bpf_warn_invalid_xdp_action(rx_ring
->netdev
, xdp_prog
, act
);
2268 trace_xdp_exception(rx_ring
->netdev
, xdp_prog
, act
);
2269 fallthrough
; /* handle aborts by dropping packet */
2271 result
= IXGBE_XDP_CONSUMED
;
2275 return ERR_PTR(-result
);
2278 static unsigned int ixgbe_rx_frame_truesize(struct ixgbe_ring
*rx_ring
,
2281 unsigned int truesize
;
2283 #if (PAGE_SIZE < 8192)
2284 truesize
= ixgbe_rx_pg_size(rx_ring
) / 2; /* Must be power-of-2 */
2286 truesize
= rx_ring
->rx_offset
?
2287 SKB_DATA_ALIGN(rx_ring
->rx_offset
+ size
) +
2288 SKB_DATA_ALIGN(sizeof(struct skb_shared_info
)) :
2289 SKB_DATA_ALIGN(size
);
2294 static void ixgbe_rx_buffer_flip(struct ixgbe_ring
*rx_ring
,
2295 struct ixgbe_rx_buffer
*rx_buffer
,
2298 unsigned int truesize
= ixgbe_rx_frame_truesize(rx_ring
, size
);
2299 #if (PAGE_SIZE < 8192)
2300 rx_buffer
->page_offset
^= truesize
;
2302 rx_buffer
->page_offset
+= truesize
;
2307 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2308 * @q_vector: structure containing interrupt and ring information
2309 * @rx_ring: rx descriptor ring to transact packets on
2310 * @budget: Total limit on number of packets to process
2312 * This function provides a "bounce buffer" approach to Rx interrupt
2313 * processing. The advantage to this is that on systems that have
2314 * expensive overhead for IOMMU access this provides a means of avoiding
2315 * it by maintaining the mapping of the page to the syste.
2317 * Returns amount of work completed
2319 static int ixgbe_clean_rx_irq(struct ixgbe_q_vector
*q_vector
,
2320 struct ixgbe_ring
*rx_ring
,
2323 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0, frame_sz
= 0;
2324 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
2327 unsigned int mss
= 0;
2328 #endif /* IXGBE_FCOE */
2329 u16 cleaned_count
= ixgbe_desc_unused(rx_ring
);
2330 unsigned int offset
= rx_ring
->rx_offset
;
2331 unsigned int xdp_xmit
= 0;
2332 struct xdp_buff xdp
;
2334 /* Frame size depend on rx_ring setup when PAGE_SIZE=4K */
2335 #if (PAGE_SIZE < 8192)
2336 frame_sz
= ixgbe_rx_frame_truesize(rx_ring
, 0);
2338 xdp_init_buff(&xdp
, frame_sz
, &rx_ring
->xdp_rxq
);
2340 while (likely(total_rx_packets
< budget
)) {
2341 union ixgbe_adv_rx_desc
*rx_desc
;
2342 struct ixgbe_rx_buffer
*rx_buffer
;
2343 struct sk_buff
*skb
;
2344 int rx_buffer_pgcnt
;
2347 /* return some buffers to hardware, one at a time is too slow */
2348 if (cleaned_count
>= IXGBE_RX_BUFFER_WRITE
) {
2349 ixgbe_alloc_rx_buffers(rx_ring
, cleaned_count
);
2353 rx_desc
= IXGBE_RX_DESC(rx_ring
, rx_ring
->next_to_clean
);
2354 size
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
2358 /* This memory barrier is needed to keep us from reading
2359 * any other fields out of the rx_desc until we know the
2360 * descriptor has been written back
2364 rx_buffer
= ixgbe_get_rx_buffer(rx_ring
, rx_desc
, &skb
, size
, &rx_buffer_pgcnt
);
2366 /* retrieve a buffer from the ring */
2368 unsigned char *hard_start
;
2370 hard_start
= page_address(rx_buffer
->page
) +
2371 rx_buffer
->page_offset
- offset
;
2372 xdp_prepare_buff(&xdp
, hard_start
, offset
, size
, true);
2373 xdp_buff_clear_frags_flag(&xdp
);
2374 #if (PAGE_SIZE > 4096)
2375 /* At larger PAGE_SIZE, frame_sz depend on len size */
2376 xdp
.frame_sz
= ixgbe_rx_frame_truesize(rx_ring
, size
);
2378 skb
= ixgbe_run_xdp(adapter
, rx_ring
, &xdp
);
2382 unsigned int xdp_res
= -PTR_ERR(skb
);
2384 if (xdp_res
& (IXGBE_XDP_TX
| IXGBE_XDP_REDIR
)) {
2385 xdp_xmit
|= xdp_res
;
2386 ixgbe_rx_buffer_flip(rx_ring
, rx_buffer
, size
);
2388 rx_buffer
->pagecnt_bias
++;
2391 total_rx_bytes
+= size
;
2393 ixgbe_add_rx_frag(rx_ring
, rx_buffer
, skb
, size
);
2394 } else if (ring_uses_build_skb(rx_ring
)) {
2395 skb
= ixgbe_build_skb(rx_ring
, rx_buffer
,
2398 skb
= ixgbe_construct_skb(rx_ring
, rx_buffer
,
2402 /* exit if we failed to retrieve a buffer */
2404 rx_ring
->rx_stats
.alloc_rx_buff_failed
++;
2405 rx_buffer
->pagecnt_bias
++;
2409 ixgbe_put_rx_buffer(rx_ring
, rx_buffer
, skb
, rx_buffer_pgcnt
);
2412 /* place incomplete frames back on ring for completion */
2413 if (ixgbe_is_non_eop(rx_ring
, rx_desc
, skb
))
2416 /* verify the packet layout is correct */
2417 if (ixgbe_cleanup_headers(rx_ring
, rx_desc
, skb
))
2420 /* probably a little skewed due to removing CRC */
2421 total_rx_bytes
+= skb
->len
;
2423 /* populate checksum, timestamp, VLAN, and protocol */
2424 ixgbe_process_skb_fields(rx_ring
, rx_desc
, skb
);
2427 /* if ddp, not passing to ULD unless for FCP_RSP or error */
2428 if (ixgbe_rx_is_fcoe(rx_ring
, rx_desc
)) {
2429 ddp_bytes
= ixgbe_fcoe_ddp(adapter
, rx_desc
, skb
);
2430 /* include DDPed FCoE data */
2431 if (ddp_bytes
> 0) {
2433 mss
= rx_ring
->netdev
->mtu
-
2434 sizeof(struct fcoe_hdr
) -
2435 sizeof(struct fc_frame_header
) -
2436 sizeof(struct fcoe_crc_eof
);
2440 total_rx_bytes
+= ddp_bytes
;
2441 total_rx_packets
+= DIV_ROUND_UP(ddp_bytes
,
2445 dev_kfree_skb_any(skb
);
2450 #endif /* IXGBE_FCOE */
2451 ixgbe_rx_skb(q_vector
, skb
);
2453 /* update budget accounting */
2457 if (xdp_xmit
& IXGBE_XDP_REDIR
)
2460 if (xdp_xmit
& IXGBE_XDP_TX
) {
2461 struct ixgbe_ring
*ring
= ixgbe_determine_xdp_ring(adapter
);
2463 ixgbe_xdp_ring_update_tail_locked(ring
);
2466 ixgbe_update_rx_ring_stats(rx_ring
, q_vector
, total_rx_packets
,
2469 return total_rx_packets
;
2473 * ixgbe_configure_msix - Configure MSI-X hardware
2474 * @adapter: board private structure
2476 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2479 static void ixgbe_configure_msix(struct ixgbe_adapter
*adapter
)
2481 struct ixgbe_q_vector
*q_vector
;
2485 /* Populate MSIX to EITR Select */
2486 if (adapter
->num_vfs
> 32) {
2487 u32 eitrsel
= BIT(adapter
->num_vfs
- 32) - 1;
2488 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITRSEL
, eitrsel
);
2492 * Populate the IVAR table and set the ITR values to the
2493 * corresponding register.
2495 for (v_idx
= 0; v_idx
< adapter
->num_q_vectors
; v_idx
++) {
2496 struct ixgbe_ring
*ring
;
2497 q_vector
= adapter
->q_vector
[v_idx
];
2499 ixgbe_for_each_ring(ring
, q_vector
->rx
)
2500 ixgbe_set_ivar(adapter
, 0, ring
->reg_idx
, v_idx
);
2502 ixgbe_for_each_ring(ring
, q_vector
->tx
)
2503 ixgbe_set_ivar(adapter
, 1, ring
->reg_idx
, v_idx
);
2505 ixgbe_write_eitr(q_vector
);
2508 switch (adapter
->hw
.mac
.type
) {
2509 case ixgbe_mac_82598EB
:
2510 ixgbe_set_ivar(adapter
, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX
,
2513 case ixgbe_mac_82599EB
:
2514 case ixgbe_mac_X540
:
2515 case ixgbe_mac_X550
:
2516 case ixgbe_mac_X550EM_x
:
2517 case ixgbe_mac_x550em_a
:
2518 ixgbe_set_ivar(adapter
, -1, 1, v_idx
);
2523 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITR(v_idx
), 1950);
2525 /* set up to autoclear timer, and the vectors */
2526 mask
= IXGBE_EIMS_ENABLE_MASK
;
2527 mask
&= ~(IXGBE_EIMS_OTHER
|
2528 IXGBE_EIMS_MAILBOX
|
2531 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIAC
, mask
);
2535 * ixgbe_update_itr - update the dynamic ITR value based on statistics
2536 * @q_vector: structure containing interrupt and ring information
2537 * @ring_container: structure containing ring performance data
2539 * Stores a new ITR value based on packets and byte
2540 * counts during the last interrupt. The advantage of per interrupt
2541 * computation is faster updates and more accurate ITR for the current
2542 * traffic pattern. Constants in this function were computed
2543 * based on theoretical maximum wire speed and thresholds were set based
2544 * on testing data as well as attempting to minimize response time
2545 * while increasing bulk throughput.
2547 static void ixgbe_update_itr(struct ixgbe_q_vector
*q_vector
,
2548 struct ixgbe_ring_container
*ring_container
)
2550 unsigned int itr
= IXGBE_ITR_ADAPTIVE_MIN_USECS
|
2551 IXGBE_ITR_ADAPTIVE_LATENCY
;
2552 unsigned int avg_wire_size
, packets
, bytes
;
2553 unsigned long next_update
= jiffies
;
2555 /* If we don't have any rings just leave ourselves set for maximum
2556 * possible latency so we take ourselves out of the equation.
2558 if (!ring_container
->ring
)
2561 /* If we didn't update within up to 1 - 2 jiffies we can assume
2562 * that either packets are coming in so slow there hasn't been
2563 * any work, or that there is so much work that NAPI is dealing
2564 * with interrupt moderation and we don't need to do anything.
2566 if (time_after(next_update
, ring_container
->next_update
))
2569 packets
= ring_container
->total_packets
;
2571 /* We have no packets to actually measure against. This means
2572 * either one of the other queues on this vector is active or
2573 * we are a Tx queue doing TSO with too high of an interrupt rate.
2575 * When this occurs just tick up our delay by the minimum value
2576 * and hope that this extra delay will prevent us from being called
2577 * without any work on our queue.
2580 itr
= (q_vector
->itr
>> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC
;
2581 if (itr
> IXGBE_ITR_ADAPTIVE_MAX_USECS
)
2582 itr
= IXGBE_ITR_ADAPTIVE_MAX_USECS
;
2583 itr
+= ring_container
->itr
& IXGBE_ITR_ADAPTIVE_LATENCY
;
2587 bytes
= ring_container
->total_bytes
;
2589 /* If packets are less than 4 or bytes are less than 9000 assume
2590 * insufficient data to use bulk rate limiting approach. We are
2591 * likely latency driven.
2593 if (packets
< 4 && bytes
< 9000) {
2594 itr
= IXGBE_ITR_ADAPTIVE_LATENCY
;
2595 goto adjust_by_size
;
2598 /* Between 4 and 48 we can assume that our current interrupt delay
2599 * is only slightly too low. As such we should increase it by a small
2603 itr
= (q_vector
->itr
>> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC
;
2604 if (itr
> IXGBE_ITR_ADAPTIVE_MAX_USECS
)
2605 itr
= IXGBE_ITR_ADAPTIVE_MAX_USECS
;
2609 /* Between 48 and 96 is our "goldilocks" zone where we are working
2610 * out "just right". Just report that our current ITR is good for us.
2613 itr
= q_vector
->itr
>> 2;
2617 /* If packet count is 96 or greater we are likely looking at a slight
2618 * overrun of the delay we want. Try halving our delay to see if that
2619 * will cut the number of packets in half per interrupt.
2621 if (packets
< 256) {
2622 itr
= q_vector
->itr
>> 3;
2623 if (itr
< IXGBE_ITR_ADAPTIVE_MIN_USECS
)
2624 itr
= IXGBE_ITR_ADAPTIVE_MIN_USECS
;
2628 /* The paths below assume we are dealing with a bulk ITR since number
2629 * of packets is 256 or greater. We are just going to have to compute
2630 * a value and try to bring the count under control, though for smaller
2631 * packet sizes there isn't much we can do as NAPI polling will likely
2632 * be kicking in sooner rather than later.
2634 itr
= IXGBE_ITR_ADAPTIVE_BULK
;
2637 /* If packet counts are 256 or greater we can assume we have a gross
2638 * overestimation of what the rate should be. Instead of trying to fine
2639 * tune it just use the formula below to try and dial in an exact value
2640 * give the current packet size of the frame.
2642 avg_wire_size
= bytes
/ packets
;
2644 /* The following is a crude approximation of:
2645 * wmem_default / (size + overhead) = desired_pkts_per_int
2646 * rate / bits_per_byte / (size + ethernet overhead) = pkt_rate
2647 * (desired_pkt_rate / pkt_rate) * usecs_per_sec = ITR value
2649 * Assuming wmem_default is 212992 and overhead is 640 bytes per
2650 * packet, (256 skb, 64 headroom, 320 shared info), we can reduce the
2653 * (170 * (size + 24)) / (size + 640) = ITR
2655 * We first do some math on the packet size and then finally bitshift
2656 * by 8 after rounding up. We also have to account for PCIe link speed
2657 * difference as ITR scales based on this.
2659 if (avg_wire_size
<= 60) {
2660 /* Start at 50k ints/sec */
2661 avg_wire_size
= 5120;
2662 } else if (avg_wire_size
<= 316) {
2663 /* 50K ints/sec to 16K ints/sec */
2664 avg_wire_size
*= 40;
2665 avg_wire_size
+= 2720;
2666 } else if (avg_wire_size
<= 1084) {
2667 /* 16K ints/sec to 9.2K ints/sec */
2668 avg_wire_size
*= 15;
2669 avg_wire_size
+= 11452;
2670 } else if (avg_wire_size
< 1968) {
2671 /* 9.2K ints/sec to 8K ints/sec */
2673 avg_wire_size
+= 22420;
2675 /* plateau at a limit of 8K ints/sec */
2676 avg_wire_size
= 32256;
2679 /* If we are in low latency mode half our delay which doubles the rate
2680 * to somewhere between 100K to 16K ints/sec
2682 if (itr
& IXGBE_ITR_ADAPTIVE_LATENCY
)
2683 avg_wire_size
>>= 1;
2685 /* Resultant value is 256 times larger than it needs to be. This
2686 * gives us room to adjust the value as needed to either increase
2687 * or decrease the value based on link speeds of 10G, 2.5G, 1G, etc.
2689 * Use addition as we have already recorded the new latency flag
2690 * for the ITR value.
2692 switch (q_vector
->adapter
->link_speed
) {
2693 case IXGBE_LINK_SPEED_10GB_FULL
:
2694 case IXGBE_LINK_SPEED_100_FULL
:
2696 itr
+= DIV_ROUND_UP(avg_wire_size
,
2697 IXGBE_ITR_ADAPTIVE_MIN_INC
* 256) *
2698 IXGBE_ITR_ADAPTIVE_MIN_INC
;
2700 case IXGBE_LINK_SPEED_2_5GB_FULL
:
2701 case IXGBE_LINK_SPEED_1GB_FULL
:
2702 case IXGBE_LINK_SPEED_10_FULL
:
2703 if (avg_wire_size
> 8064)
2704 avg_wire_size
= 8064;
2705 itr
+= DIV_ROUND_UP(avg_wire_size
,
2706 IXGBE_ITR_ADAPTIVE_MIN_INC
* 64) *
2707 IXGBE_ITR_ADAPTIVE_MIN_INC
;
2712 /* write back value */
2713 ring_container
->itr
= itr
;
2715 /* next update should occur within next jiffy */
2716 ring_container
->next_update
= next_update
+ 1;
2718 ring_container
->total_bytes
= 0;
2719 ring_container
->total_packets
= 0;
2723 * ixgbe_write_eitr - write EITR register in hardware specific way
2724 * @q_vector: structure containing interrupt and ring information
2726 * This function is made to be called by ethtool and by the driver
2727 * when it needs to update EITR registers at runtime. Hardware
2728 * specific quirks/differences are taken care of here.
2730 void ixgbe_write_eitr(struct ixgbe_q_vector
*q_vector
)
2732 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
2733 struct ixgbe_hw
*hw
= &adapter
->hw
;
2734 int v_idx
= q_vector
->v_idx
;
2735 u32 itr_reg
= q_vector
->itr
& IXGBE_MAX_EITR
;
2737 switch (adapter
->hw
.mac
.type
) {
2738 case ixgbe_mac_82598EB
:
2739 /* must write high and low 16 bits to reset counter */
2740 itr_reg
|= (itr_reg
<< 16);
2742 case ixgbe_mac_82599EB
:
2743 case ixgbe_mac_X540
:
2744 case ixgbe_mac_X550
:
2745 case ixgbe_mac_X550EM_x
:
2746 case ixgbe_mac_x550em_a
:
2748 * set the WDIS bit to not clear the timer bits and cause an
2749 * immediate assertion of the interrupt
2751 itr_reg
|= IXGBE_EITR_CNT_WDIS
;
2756 IXGBE_WRITE_REG(hw
, IXGBE_EITR(v_idx
), itr_reg
);
2759 static void ixgbe_set_itr(struct ixgbe_q_vector
*q_vector
)
2763 ixgbe_update_itr(q_vector
, &q_vector
->tx
);
2764 ixgbe_update_itr(q_vector
, &q_vector
->rx
);
2766 /* use the smallest value of new ITR delay calculations */
2767 new_itr
= min(q_vector
->rx
.itr
, q_vector
->tx
.itr
);
2769 /* Clear latency flag if set, shift into correct position */
2770 new_itr
&= ~IXGBE_ITR_ADAPTIVE_LATENCY
;
2773 if (new_itr
!= q_vector
->itr
) {
2774 /* save the algorithm value here */
2775 q_vector
->itr
= new_itr
;
2777 ixgbe_write_eitr(q_vector
);
2782 * ixgbe_check_overtemp_subtask - check for over temperature
2783 * @adapter: pointer to adapter
2785 static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter
*adapter
)
2787 struct ixgbe_hw
*hw
= &adapter
->hw
;
2788 u32 eicr
= adapter
->interrupt_event
;
2790 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
2793 if (!(adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_EVENT
))
2796 adapter
->flags2
&= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT
;
2798 switch (hw
->device_id
) {
2799 case IXGBE_DEV_ID_82599_T3_LOM
:
2801 * Since the warning interrupt is for both ports
2802 * we don't have to check if:
2803 * - This interrupt wasn't for our port.
2804 * - We may have missed the interrupt so always have to
2805 * check if we got a LSC
2807 if (!(eicr
& IXGBE_EICR_GPI_SDP0_8259X
) &&
2808 !(eicr
& IXGBE_EICR_LSC
))
2811 if (!(eicr
& IXGBE_EICR_LSC
) && hw
->mac
.ops
.check_link
) {
2813 bool link_up
= false;
2815 hw
->mac
.ops
.check_link(hw
, &speed
, &link_up
, false);
2821 /* Check if this is not due to overtemp */
2822 if (!hw
->phy
.ops
.check_overtemp(hw
))
2826 case IXGBE_DEV_ID_X550EM_A_1G_T
:
2827 case IXGBE_DEV_ID_X550EM_A_1G_T_L
:
2828 if (!hw
->phy
.ops
.check_overtemp(hw
))
2832 if (adapter
->hw
.mac
.type
>= ixgbe_mac_X540
)
2834 if (!(eicr
& IXGBE_EICR_GPI_SDP0(hw
)))
2838 e_crit(drv
, "%s\n", ixgbe_overheat_msg
);
2840 adapter
->interrupt_event
= 0;
2843 static void ixgbe_check_fan_failure(struct ixgbe_adapter
*adapter
, u32 eicr
)
2845 struct ixgbe_hw
*hw
= &adapter
->hw
;
2847 if ((adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) &&
2848 (eicr
& IXGBE_EICR_GPI_SDP1(hw
))) {
2849 e_crit(probe
, "Fan has stopped, replace the adapter\n");
2850 /* write to clear the interrupt */
2851 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP1(hw
));
2855 static void ixgbe_check_overtemp_event(struct ixgbe_adapter
*adapter
, u32 eicr
)
2857 struct ixgbe_hw
*hw
= &adapter
->hw
;
2859 if (!(adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
))
2862 switch (adapter
->hw
.mac
.type
) {
2863 case ixgbe_mac_82599EB
:
2865 * Need to check link state so complete overtemp check
2868 if (((eicr
& IXGBE_EICR_GPI_SDP0(hw
)) ||
2869 (eicr
& IXGBE_EICR_LSC
)) &&
2870 (!test_bit(__IXGBE_DOWN
, &adapter
->state
))) {
2871 adapter
->interrupt_event
= eicr
;
2872 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_EVENT
;
2873 ixgbe_service_event_schedule(adapter
);
2877 case ixgbe_mac_x550em_a
:
2878 if (eicr
& IXGBE_EICR_GPI_SDP0_X550EM_a
) {
2879 adapter
->interrupt_event
= eicr
;
2880 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_EVENT
;
2881 ixgbe_service_event_schedule(adapter
);
2882 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
,
2883 IXGBE_EICR_GPI_SDP0_X550EM_a
);
2884 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICR
,
2885 IXGBE_EICR_GPI_SDP0_X550EM_a
);
2888 case ixgbe_mac_X550
:
2889 case ixgbe_mac_X540
:
2890 if (!(eicr
& IXGBE_EICR_TS
))
2897 e_crit(drv
, "%s\n", ixgbe_overheat_msg
);
2900 static inline bool ixgbe_is_sfp(struct ixgbe_hw
*hw
)
2902 switch (hw
->mac
.type
) {
2903 case ixgbe_mac_82598EB
:
2904 if (hw
->phy
.type
== ixgbe_phy_nl
)
2907 case ixgbe_mac_82599EB
:
2908 case ixgbe_mac_X550EM_x
:
2909 case ixgbe_mac_x550em_a
:
2910 switch (hw
->mac
.ops
.get_media_type(hw
)) {
2911 case ixgbe_media_type_fiber
:
2912 case ixgbe_media_type_fiber_qsfp
:
2922 static void ixgbe_check_sfp_event(struct ixgbe_adapter
*adapter
, u32 eicr
)
2924 struct ixgbe_hw
*hw
= &adapter
->hw
;
2925 u32 eicr_mask
= IXGBE_EICR_GPI_SDP2(hw
);
2927 if (!ixgbe_is_sfp(hw
))
2930 /* Later MAC's use different SDP */
2931 if (hw
->mac
.type
>= ixgbe_mac_X540
)
2932 eicr_mask
= IXGBE_EICR_GPI_SDP0_X540
;
2934 if (eicr
& eicr_mask
) {
2935 /* Clear the interrupt */
2936 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, eicr_mask
);
2937 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
2938 adapter
->flags2
|= IXGBE_FLAG2_SFP_NEEDS_RESET
;
2939 adapter
->sfp_poll_time
= 0;
2940 ixgbe_service_event_schedule(adapter
);
2944 if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
&&
2945 (eicr
& IXGBE_EICR_GPI_SDP1(hw
))) {
2946 /* Clear the interrupt */
2947 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP1(hw
));
2948 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
2949 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_CONFIG
;
2950 ixgbe_service_event_schedule(adapter
);
2955 static void ixgbe_check_lsc(struct ixgbe_adapter
*adapter
)
2957 struct ixgbe_hw
*hw
= &adapter
->hw
;
2960 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
2961 adapter
->link_check_timeout
= jiffies
;
2962 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
2963 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_EIMC_LSC
);
2964 IXGBE_WRITE_FLUSH(hw
);
2965 ixgbe_service_event_schedule(adapter
);
2969 static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter
*adapter
,
2972 struct ixgbe_hw
*hw
= &adapter
->hw
;
2975 switch (hw
->mac
.type
) {
2976 case ixgbe_mac_82598EB
:
2977 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
2978 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, mask
);
2980 case ixgbe_mac_82599EB
:
2981 case ixgbe_mac_X540
:
2982 case ixgbe_mac_X550
:
2983 case ixgbe_mac_X550EM_x
:
2984 case ixgbe_mac_x550em_a
:
2985 mask
= (qmask
& 0xFFFFFFFF);
2987 IXGBE_WRITE_REG(hw
, IXGBE_EIMS_EX(0), mask
);
2988 mask
= (qmask
>> 32);
2990 IXGBE_WRITE_REG(hw
, IXGBE_EIMS_EX(1), mask
);
2995 /* skip the flush */
2999 * ixgbe_irq_enable - Enable default interrupt generation settings
3000 * @adapter: board private structure
3001 * @queues: enable irqs for queues
3002 * @flush: flush register write
3004 static inline void ixgbe_irq_enable(struct ixgbe_adapter
*adapter
, bool queues
,
3007 struct ixgbe_hw
*hw
= &adapter
->hw
;
3008 u32 mask
= (IXGBE_EIMS_ENABLE_MASK
& ~IXGBE_EIMS_RTX_QUEUE
);
3010 /* don't reenable LSC while waiting for link */
3011 if (adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
)
3012 mask
&= ~IXGBE_EIMS_LSC
;
3014 if (adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
)
3015 switch (adapter
->hw
.mac
.type
) {
3016 case ixgbe_mac_82599EB
:
3017 mask
|= IXGBE_EIMS_GPI_SDP0(hw
);
3019 case ixgbe_mac_X540
:
3020 case ixgbe_mac_X550
:
3021 case ixgbe_mac_X550EM_x
:
3022 case ixgbe_mac_x550em_a
:
3023 mask
|= IXGBE_EIMS_TS
;
3028 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
)
3029 mask
|= IXGBE_EIMS_GPI_SDP1(hw
);
3030 switch (adapter
->hw
.mac
.type
) {
3031 case ixgbe_mac_82599EB
:
3032 mask
|= IXGBE_EIMS_GPI_SDP1(hw
);
3033 mask
|= IXGBE_EIMS_GPI_SDP2(hw
);
3035 case ixgbe_mac_X540
:
3036 case ixgbe_mac_X550
:
3037 case ixgbe_mac_X550EM_x
:
3038 case ixgbe_mac_x550em_a
:
3039 if (adapter
->hw
.device_id
== IXGBE_DEV_ID_X550EM_X_SFP
||
3040 adapter
->hw
.device_id
== IXGBE_DEV_ID_X550EM_A_SFP
||
3041 adapter
->hw
.device_id
== IXGBE_DEV_ID_X550EM_A_SFP_N
)
3042 mask
|= IXGBE_EIMS_GPI_SDP0(&adapter
->hw
);
3043 if (adapter
->hw
.phy
.type
== ixgbe_phy_x550em_ext_t
)
3044 mask
|= IXGBE_EICR_GPI_SDP0_X540
;
3045 mask
|= IXGBE_EIMS_ECC
;
3046 mask
|= IXGBE_EIMS_MAILBOX
;
3052 if ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) &&
3053 !(adapter
->flags2
& IXGBE_FLAG2_FDIR_REQUIRES_REINIT
))
3054 mask
|= IXGBE_EIMS_FLOW_DIR
;
3056 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS
, mask
);
3058 ixgbe_irq_enable_queues(adapter
, ~0);
3060 IXGBE_WRITE_FLUSH(&adapter
->hw
);
3063 static irqreturn_t
ixgbe_msix_other(int irq
, void *data
)
3065 struct ixgbe_adapter
*adapter
= data
;
3066 struct ixgbe_hw
*hw
= &adapter
->hw
;
3070 * Workaround for Silicon errata. Use clear-by-write instead
3071 * of clear-by-read. Reading with EICS will return the
3072 * interrupt causes without clearing, which later be done
3073 * with the write to EICR.
3075 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICS
);
3077 /* The lower 16bits of the EICR register are for the queue interrupts
3078 * which should be masked here in order to not accidentally clear them if
3079 * the bits are high when ixgbe_msix_other is called. There is a race
3080 * condition otherwise which results in possible performance loss
3081 * especially if the ixgbe_msix_other interrupt is triggering
3082 * consistently (as it would when PPS is turned on for the X540 device)
3086 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, eicr
);
3088 if (eicr
& IXGBE_EICR_LSC
)
3089 ixgbe_check_lsc(adapter
);
3091 if (eicr
& IXGBE_EICR_MAILBOX
)
3092 ixgbe_msg_task(adapter
);
3094 switch (hw
->mac
.type
) {
3095 case ixgbe_mac_82599EB
:
3096 case ixgbe_mac_X540
:
3097 case ixgbe_mac_X550
:
3098 case ixgbe_mac_X550EM_x
:
3099 case ixgbe_mac_x550em_a
:
3100 if (hw
->phy
.type
== ixgbe_phy_x550em_ext_t
&&
3101 (eicr
& IXGBE_EICR_GPI_SDP0_X540
)) {
3102 adapter
->flags2
|= IXGBE_FLAG2_PHY_INTERRUPT
;
3103 ixgbe_service_event_schedule(adapter
);
3104 IXGBE_WRITE_REG(hw
, IXGBE_EICR
,
3105 IXGBE_EICR_GPI_SDP0_X540
);
3107 if (eicr
& IXGBE_EICR_ECC
) {
3108 e_info(link
, "Received ECC Err, initiating reset\n");
3109 set_bit(__IXGBE_RESET_REQUESTED
, &adapter
->state
);
3110 ixgbe_service_event_schedule(adapter
);
3111 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_ECC
);
3113 /* Handle Flow Director Full threshold interrupt */
3114 if (eicr
& IXGBE_EICR_FLOW_DIR
) {
3115 int reinit_count
= 0;
3117 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
3118 struct ixgbe_ring
*ring
= adapter
->tx_ring
[i
];
3119 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE
,
3124 /* no more flow director interrupts until after init */
3125 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_EIMC_FLOW_DIR
);
3126 adapter
->flags2
|= IXGBE_FLAG2_FDIR_REQUIRES_REINIT
;
3127 ixgbe_service_event_schedule(adapter
);
3130 ixgbe_check_sfp_event(adapter
, eicr
);
3131 ixgbe_check_overtemp_event(adapter
, eicr
);
3137 ixgbe_check_fan_failure(adapter
, eicr
);
3139 if (unlikely(eicr
& IXGBE_EICR_TIMESYNC
))
3140 ixgbe_ptp_check_pps_event(adapter
);
3142 /* re-enable the original interrupt state, no lsc, no queues */
3143 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
3144 ixgbe_irq_enable(adapter
, false, false);
3149 static irqreturn_t
ixgbe_msix_clean_rings(int irq
, void *data
)
3151 struct ixgbe_q_vector
*q_vector
= data
;
3153 /* EIAM disabled interrupts (on this vector) for us */
3155 if (q_vector
->rx
.ring
|| q_vector
->tx
.ring
)
3156 napi_schedule_irqoff(&q_vector
->napi
);
3162 * ixgbe_poll - NAPI Rx polling callback
3163 * @napi: structure for representing this polling device
3164 * @budget: how many packets driver is allowed to clean
3166 * This function is used for legacy and MSI, NAPI mode
3168 int ixgbe_poll(struct napi_struct
*napi
, int budget
)
3170 struct ixgbe_q_vector
*q_vector
=
3171 container_of(napi
, struct ixgbe_q_vector
, napi
);
3172 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
3173 struct ixgbe_ring
*ring
;
3174 int per_ring_budget
, work_done
= 0;
3175 bool clean_complete
= true;
3177 #ifdef CONFIG_IXGBE_DCA
3178 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
3179 ixgbe_update_dca(q_vector
);
3182 ixgbe_for_each_ring(ring
, q_vector
->tx
) {
3183 bool wd
= ring
->xsk_pool
?
3184 ixgbe_clean_xdp_tx_irq(q_vector
, ring
, budget
) :
3185 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
= ring
->xsk_pool
?
3204 ixgbe_clean_rx_irq_zc(q_vector
, ring
,
3206 ixgbe_clean_rx_irq(q_vector
, ring
,
3209 work_done
+= cleaned
;
3210 if (cleaned
>= per_ring_budget
)
3211 clean_complete
= false;
3214 /* If all work not completed, return budget and keep polling */
3215 if (!clean_complete
)
3218 /* all work done, exit the polling mode */
3219 if (likely(napi_complete_done(napi
, work_done
))) {
3220 if (adapter
->rx_itr_setting
& 1)
3221 ixgbe_set_itr(q_vector
);
3222 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
3223 ixgbe_irq_enable_queues(adapter
,
3224 BIT_ULL(q_vector
->v_idx
));
3227 return min(work_done
, budget
- 1);
3231 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
3232 * @adapter: board private structure
3234 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
3235 * interrupts from the kernel.
3237 static int ixgbe_request_msix_irqs(struct ixgbe_adapter
*adapter
)
3239 struct net_device
*netdev
= adapter
->netdev
;
3240 unsigned int ri
= 0, ti
= 0;
3243 for (vector
= 0; vector
< adapter
->num_q_vectors
; vector
++) {
3244 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[vector
];
3245 struct msix_entry
*entry
= &adapter
->msix_entries
[vector
];
3247 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
3248 snprintf(q_vector
->name
, sizeof(q_vector
->name
),
3249 "%s-TxRx-%u", netdev
->name
, ri
++);
3251 } else if (q_vector
->rx
.ring
) {
3252 snprintf(q_vector
->name
, sizeof(q_vector
->name
),
3253 "%s-rx-%u", netdev
->name
, ri
++);
3254 } else if (q_vector
->tx
.ring
) {
3255 snprintf(q_vector
->name
, sizeof(q_vector
->name
),
3256 "%s-tx-%u", netdev
->name
, ti
++);
3258 /* skip this unused q_vector */
3261 err
= request_irq(entry
->vector
, &ixgbe_msix_clean_rings
, 0,
3262 q_vector
->name
, q_vector
);
3264 e_err(probe
, "request_irq failed for MSIX interrupt "
3265 "Error: %d\n", err
);
3266 goto free_queue_irqs
;
3268 /* If Flow Director is enabled, set interrupt affinity */
3269 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
3270 /* assign the mask for this irq */
3271 irq_update_affinity_hint(entry
->vector
,
3272 &q_vector
->affinity_mask
);
3276 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
3277 ixgbe_msix_other
, 0, netdev
->name
, adapter
);
3279 e_err(probe
, "request_irq for msix_other failed: %d\n", err
);
3280 goto free_queue_irqs
;
3288 irq_update_affinity_hint(adapter
->msix_entries
[vector
].vector
,
3290 free_irq(adapter
->msix_entries
[vector
].vector
,
3291 adapter
->q_vector
[vector
]);
3293 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
3294 pci_disable_msix(adapter
->pdev
);
3295 kfree(adapter
->msix_entries
);
3296 adapter
->msix_entries
= NULL
;
3301 * ixgbe_intr - legacy mode Interrupt Handler
3302 * @irq: interrupt number
3303 * @data: pointer to a network interface device structure
3305 static irqreturn_t
ixgbe_intr(int irq
, void *data
)
3307 struct ixgbe_adapter
*adapter
= data
;
3308 struct ixgbe_hw
*hw
= &adapter
->hw
;
3309 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[0];
3313 * Workaround for silicon errata #26 on 82598. Mask the interrupt
3314 * before the read of EICR.
3316 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_IRQ_CLEAR_MASK
);
3318 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
3319 * therefore no explicit interrupt disable is necessary */
3320 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICR
);
3323 * shared interrupt alert!
3324 * make sure interrupts are enabled because the read will
3325 * have disabled interrupts due to EIAM
3326 * finish the workaround of silicon errata on 82598. Unmask
3327 * the interrupt that we masked before the EICR read.
3329 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
3330 ixgbe_irq_enable(adapter
, true, true);
3331 return IRQ_NONE
; /* Not our interrupt */
3334 if (eicr
& IXGBE_EICR_LSC
)
3335 ixgbe_check_lsc(adapter
);
3337 switch (hw
->mac
.type
) {
3338 case ixgbe_mac_82599EB
:
3339 ixgbe_check_sfp_event(adapter
, eicr
);
3341 case ixgbe_mac_X540
:
3342 case ixgbe_mac_X550
:
3343 case ixgbe_mac_X550EM_x
:
3344 case ixgbe_mac_x550em_a
:
3345 if (eicr
& IXGBE_EICR_ECC
) {
3346 e_info(link
, "Received ECC Err, initiating reset\n");
3347 set_bit(__IXGBE_RESET_REQUESTED
, &adapter
->state
);
3348 ixgbe_service_event_schedule(adapter
);
3349 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_ECC
);
3351 ixgbe_check_overtemp_event(adapter
, eicr
);
3357 ixgbe_check_fan_failure(adapter
, eicr
);
3358 if (unlikely(eicr
& IXGBE_EICR_TIMESYNC
))
3359 ixgbe_ptp_check_pps_event(adapter
);
3361 /* would disable interrupts here but EIAM disabled it */
3362 napi_schedule_irqoff(&q_vector
->napi
);
3365 * re-enable link(maybe) and non-queue interrupts, no flush.
3366 * ixgbe_poll will re-enable the queue interrupts
3368 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
3369 ixgbe_irq_enable(adapter
, false, false);
3375 * ixgbe_request_irq - initialize interrupts
3376 * @adapter: board private structure
3378 * Attempts to configure interrupts using the best available
3379 * capabilities of the hardware and kernel.
3381 static int ixgbe_request_irq(struct ixgbe_adapter
*adapter
)
3383 struct net_device
*netdev
= adapter
->netdev
;
3386 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
3387 err
= ixgbe_request_msix_irqs(adapter
);
3388 else if (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
)
3389 err
= request_irq(adapter
->pdev
->irq
, ixgbe_intr
, 0,
3390 netdev
->name
, adapter
);
3392 err
= request_irq(adapter
->pdev
->irq
, ixgbe_intr
, IRQF_SHARED
,
3393 netdev
->name
, adapter
);
3396 e_err(probe
, "request_irq failed, Error %d\n", err
);
3401 static void ixgbe_free_irq(struct ixgbe_adapter
*adapter
)
3405 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)) {
3406 free_irq(adapter
->pdev
->irq
, adapter
);
3410 if (!adapter
->msix_entries
)
3413 for (vector
= 0; vector
< adapter
->num_q_vectors
; vector
++) {
3414 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[vector
];
3415 struct msix_entry
*entry
= &adapter
->msix_entries
[vector
];
3417 /* free only the irqs that were actually requested */
3418 if (!q_vector
->rx
.ring
&& !q_vector
->tx
.ring
)
3421 /* clear the affinity_mask in the IRQ descriptor */
3422 irq_update_affinity_hint(entry
->vector
, NULL
);
3424 free_irq(entry
->vector
, q_vector
);
3427 free_irq(adapter
->msix_entries
[vector
].vector
, adapter
);
3431 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
3432 * @adapter: board private structure
3434 static inline void ixgbe_irq_disable(struct ixgbe_adapter
*adapter
)
3436 switch (adapter
->hw
.mac
.type
) {
3437 case ixgbe_mac_82598EB
:
3438 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, ~0);
3440 case ixgbe_mac_82599EB
:
3441 case ixgbe_mac_X540
:
3442 case ixgbe_mac_X550
:
3443 case ixgbe_mac_X550EM_x
:
3444 case ixgbe_mac_x550em_a
:
3445 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, 0xFFFF0000);
3446 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(0), ~0);
3447 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(1), ~0);
3452 IXGBE_WRITE_FLUSH(&adapter
->hw
);
3453 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
3456 for (vector
= 0; vector
< adapter
->num_q_vectors
; vector
++)
3457 synchronize_irq(adapter
->msix_entries
[vector
].vector
);
3459 synchronize_irq(adapter
->msix_entries
[vector
++].vector
);
3461 synchronize_irq(adapter
->pdev
->irq
);
3466 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3467 * @adapter: board private structure
3470 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter
*adapter
)
3472 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[0];
3474 ixgbe_write_eitr(q_vector
);
3476 ixgbe_set_ivar(adapter
, 0, 0, 0);
3477 ixgbe_set_ivar(adapter
, 1, 0, 0);
3479 e_info(hw
, "Legacy interrupt IVAR setup done\n");
3483 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3484 * @adapter: board private structure
3485 * @ring: structure containing ring specific data
3487 * Configure the Tx descriptor ring after a reset.
3489 void ixgbe_configure_tx_ring(struct ixgbe_adapter
*adapter
,
3490 struct ixgbe_ring
*ring
)
3492 struct ixgbe_hw
*hw
= &adapter
->hw
;
3493 u64 tdba
= ring
->dma
;
3495 u32 txdctl
= IXGBE_TXDCTL_ENABLE
;
3496 u8 reg_idx
= ring
->reg_idx
;
3498 ring
->xsk_pool
= NULL
;
3499 if (ring_is_xdp(ring
))
3500 ring
->xsk_pool
= ixgbe_xsk_pool(adapter
, ring
);
3502 /* disable queue to avoid issues while updating state */
3503 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
), 0);
3504 IXGBE_WRITE_FLUSH(hw
);
3506 IXGBE_WRITE_REG(hw
, IXGBE_TDBAL(reg_idx
),
3507 (tdba
& DMA_BIT_MASK(32)));
3508 IXGBE_WRITE_REG(hw
, IXGBE_TDBAH(reg_idx
), (tdba
>> 32));
3509 IXGBE_WRITE_REG(hw
, IXGBE_TDLEN(reg_idx
),
3510 ring
->count
* sizeof(union ixgbe_adv_tx_desc
));
3511 IXGBE_WRITE_REG(hw
, IXGBE_TDH(reg_idx
), 0);
3512 IXGBE_WRITE_REG(hw
, IXGBE_TDT(reg_idx
), 0);
3513 ring
->tail
= adapter
->io_addr
+ IXGBE_TDT(reg_idx
);
3516 * set WTHRESH to encourage burst writeback, it should not be set
3517 * higher than 1 when:
3518 * - ITR is 0 as it could cause false TX hangs
3519 * - ITR is set to > 100k int/sec and BQL is enabled
3521 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3522 * to or less than the number of on chip descriptors, which is
3525 if (!ring
->q_vector
|| (ring
->q_vector
->itr
< IXGBE_100K_ITR
))
3526 txdctl
|= 1u << 16; /* WTHRESH = 1 */
3528 txdctl
|= 8u << 16; /* WTHRESH = 8 */
3531 * Setting PTHRESH to 32 both improves performance
3532 * and avoids a TX hang with DFP enabled
3534 txdctl
|= (1u << 8) | /* HTHRESH = 1 */
3535 32; /* PTHRESH = 32 */
3537 /* reinitialize flowdirector state */
3538 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
3539 ring
->atr_sample_rate
= adapter
->atr_sample_rate
;
3540 ring
->atr_count
= 0;
3541 set_bit(__IXGBE_TX_FDIR_INIT_DONE
, &ring
->state
);
3543 ring
->atr_sample_rate
= 0;
3546 /* initialize XPS */
3547 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE
, &ring
->state
)) {
3548 struct ixgbe_q_vector
*q_vector
= ring
->q_vector
;
3551 netif_set_xps_queue(ring
->netdev
,
3552 &q_vector
->affinity_mask
,
3556 clear_bit(__IXGBE_HANG_CHECK_ARMED
, &ring
->state
);
3558 /* reinitialize tx_buffer_info */
3559 memset(ring
->tx_buffer_info
, 0,
3560 sizeof(struct ixgbe_tx_buffer
) * ring
->count
);
3563 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
), txdctl
);
3565 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3566 if (hw
->mac
.type
== ixgbe_mac_82598EB
&&
3567 !(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
3570 /* poll to verify queue is enabled */
3572 usleep_range(1000, 2000);
3573 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(reg_idx
));
3574 } while (--wait_loop
&& !(txdctl
& IXGBE_TXDCTL_ENABLE
));
3576 hw_dbg(hw
, "Could not enable Tx Queue %d\n", reg_idx
);
3579 static void ixgbe_setup_mtqc(struct ixgbe_adapter
*adapter
)
3581 struct ixgbe_hw
*hw
= &adapter
->hw
;
3583 u8 tcs
= adapter
->hw_tcs
;
3585 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
3588 /* disable the arbiter while setting MTQC */
3589 rttdcs
= IXGBE_READ_REG(hw
, IXGBE_RTTDCS
);
3590 rttdcs
|= IXGBE_RTTDCS_ARBDIS
;
3591 IXGBE_WRITE_REG(hw
, IXGBE_RTTDCS
, rttdcs
);
3593 /* set transmit pool layout */
3594 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
3595 mtqc
= IXGBE_MTQC_VT_ENA
;
3597 mtqc
|= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_8TC_8TQ
;
3599 mtqc
|= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_4TC_4TQ
;
3600 else if (adapter
->ring_feature
[RING_F_VMDQ
].mask
==
3601 IXGBE_82599_VMDQ_4Q_MASK
)
3602 mtqc
|= IXGBE_MTQC_32VF
;
3604 mtqc
|= IXGBE_MTQC_64VF
;
3607 mtqc
= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_8TC_8TQ
;
3608 } else if (tcs
> 1) {
3609 mtqc
= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_4TC_4TQ
;
3611 u8 max_txq
= adapter
->num_tx_queues
+
3612 adapter
->num_xdp_queues
;
3614 mtqc
= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_4TC_4TQ
;
3616 mtqc
= IXGBE_MTQC_64Q_1PB
;
3620 IXGBE_WRITE_REG(hw
, IXGBE_MTQC
, mtqc
);
3622 /* Enable Security TX Buffer IFG for multiple pb */
3624 u32 sectx
= IXGBE_READ_REG(hw
, IXGBE_SECTXMINIFG
);
3625 sectx
|= IXGBE_SECTX_DCB
;
3626 IXGBE_WRITE_REG(hw
, IXGBE_SECTXMINIFG
, sectx
);
3629 /* re-enable the arbiter */
3630 rttdcs
&= ~IXGBE_RTTDCS_ARBDIS
;
3631 IXGBE_WRITE_REG(hw
, IXGBE_RTTDCS
, rttdcs
);
3635 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
3636 * @adapter: board private structure
3638 * Configure the Tx unit of the MAC after a reset.
3640 static void ixgbe_configure_tx(struct ixgbe_adapter
*adapter
)
3642 struct ixgbe_hw
*hw
= &adapter
->hw
;
3646 ixgbe_setup_mtqc(adapter
);
3648 if (hw
->mac
.type
!= ixgbe_mac_82598EB
) {
3649 /* DMATXCTL.EN must be before Tx queues are enabled */
3650 dmatxctl
= IXGBE_READ_REG(hw
, IXGBE_DMATXCTL
);
3651 dmatxctl
|= IXGBE_DMATXCTL_TE
;
3652 IXGBE_WRITE_REG(hw
, IXGBE_DMATXCTL
, dmatxctl
);
3655 /* Setup the HW Tx Head and Tail descriptor pointers */
3656 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
3657 ixgbe_configure_tx_ring(adapter
, adapter
->tx_ring
[i
]);
3658 for (i
= 0; i
< adapter
->num_xdp_queues
; i
++)
3659 ixgbe_configure_tx_ring(adapter
, adapter
->xdp_ring
[i
]);
3662 static void ixgbe_enable_rx_drop(struct ixgbe_adapter
*adapter
,
3663 struct ixgbe_ring
*ring
)
3665 struct ixgbe_hw
*hw
= &adapter
->hw
;
3666 u8 reg_idx
= ring
->reg_idx
;
3667 u32 srrctl
= IXGBE_READ_REG(hw
, IXGBE_SRRCTL(reg_idx
));
3669 srrctl
|= IXGBE_SRRCTL_DROP_EN
;
3671 IXGBE_WRITE_REG(hw
, IXGBE_SRRCTL(reg_idx
), srrctl
);
3674 static void ixgbe_disable_rx_drop(struct ixgbe_adapter
*adapter
,
3675 struct ixgbe_ring
*ring
)
3677 struct ixgbe_hw
*hw
= &adapter
->hw
;
3678 u8 reg_idx
= ring
->reg_idx
;
3679 u32 srrctl
= IXGBE_READ_REG(hw
, IXGBE_SRRCTL(reg_idx
));
3681 srrctl
&= ~IXGBE_SRRCTL_DROP_EN
;
3683 IXGBE_WRITE_REG(hw
, IXGBE_SRRCTL(reg_idx
), srrctl
);
3686 #ifdef CONFIG_IXGBE_DCB
3687 void ixgbe_set_rx_drop_en(struct ixgbe_adapter
*adapter
)
3689 static void ixgbe_set_rx_drop_en(struct ixgbe_adapter
*adapter
)
3693 bool pfc_en
= adapter
->dcb_cfg
.pfc_mode_enable
;
3695 if (adapter
->ixgbe_ieee_pfc
)
3696 pfc_en
|= !!(adapter
->ixgbe_ieee_pfc
->pfc_en
);
3699 * We should set the drop enable bit if:
3702 * Number of Rx queues > 1 and flow control is disabled
3704 * This allows us to avoid head of line blocking for security
3705 * and performance reasons.
3707 if (adapter
->num_vfs
|| (adapter
->num_rx_queues
> 1 &&
3708 !(adapter
->hw
.fc
.current_mode
& ixgbe_fc_tx_pause
) && !pfc_en
)) {
3709 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3710 ixgbe_enable_rx_drop(adapter
, adapter
->rx_ring
[i
]);
3712 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3713 ixgbe_disable_rx_drop(adapter
, adapter
->rx_ring
[i
]);
3717 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
3719 static void ixgbe_configure_srrctl(struct ixgbe_adapter
*adapter
,
3720 struct ixgbe_ring
*rx_ring
)
3722 struct ixgbe_hw
*hw
= &adapter
->hw
;
3724 u8 reg_idx
= rx_ring
->reg_idx
;
3726 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
3727 u16 mask
= adapter
->ring_feature
[RING_F_RSS
].mask
;
3730 * if VMDq is not active we must program one srrctl register
3731 * per RSS queue since we have enabled RDRXCTL.MVMEN
3736 /* configure header buffer length, needed for RSC */
3737 srrctl
= IXGBE_RX_HDR_SIZE
<< IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT
;
3739 /* configure the packet buffer length */
3740 if (rx_ring
->xsk_pool
) {
3741 u32 xsk_buf_len
= xsk_pool_get_rx_frame_size(rx_ring
->xsk_pool
);
3743 /* If the MAC support setting RXDCTL.RLPML, the
3744 * SRRCTL[n].BSIZEPKT is set to PAGE_SIZE and
3745 * RXDCTL.RLPML is set to the actual UMEM buffer
3746 * size. If not, then we are stuck with a 1k buffer
3747 * size resolution. In this case frames larger than
3748 * the UMEM buffer size viewed in a 1k resolution will
3751 if (hw
->mac
.type
!= ixgbe_mac_82599EB
)
3752 srrctl
|= PAGE_SIZE
>> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
3754 srrctl
|= xsk_buf_len
>> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
3755 } else if (test_bit(__IXGBE_RX_3K_BUFFER
, &rx_ring
->state
)) {
3756 srrctl
|= IXGBE_RXBUFFER_3K
>> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
3758 srrctl
|= IXGBE_RXBUFFER_2K
>> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
3761 /* configure descriptor type */
3762 srrctl
|= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF
;
3764 IXGBE_WRITE_REG(hw
, IXGBE_SRRCTL(reg_idx
), srrctl
);
3768 * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
3769 * @adapter: device handle
3771 * - 82598/82599/X540: 128
3772 * - X550(non-SRIOV mode): 512
3773 * - X550(SRIOV mode): 64
3775 u32
ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter
*adapter
)
3777 if (adapter
->hw
.mac
.type
< ixgbe_mac_X550
)
3779 else if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
3786 * ixgbe_store_key - Write the RSS key to HW
3787 * @adapter: device handle
3789 * Write the RSS key stored in adapter.rss_key to HW.
3791 void ixgbe_store_key(struct ixgbe_adapter
*adapter
)
3793 struct ixgbe_hw
*hw
= &adapter
->hw
;
3796 for (i
= 0; i
< 10; i
++)
3797 IXGBE_WRITE_REG(hw
, IXGBE_RSSRK(i
), adapter
->rss_key
[i
]);
3801 * ixgbe_init_rss_key - Initialize adapter RSS key
3802 * @adapter: device handle
3804 * Allocates and initializes the RSS key if it is not allocated.
3806 static inline int ixgbe_init_rss_key(struct ixgbe_adapter
*adapter
)
3810 if (!adapter
->rss_key
) {
3811 rss_key
= kzalloc(IXGBE_RSS_KEY_SIZE
, GFP_KERNEL
);
3812 if (unlikely(!rss_key
))
3815 netdev_rss_key_fill(rss_key
, IXGBE_RSS_KEY_SIZE
);
3816 adapter
->rss_key
= rss_key
;
3823 * ixgbe_store_reta - Write the RETA table to HW
3824 * @adapter: device handle
3826 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3828 void ixgbe_store_reta(struct ixgbe_adapter
*adapter
)
3830 u32 i
, reta_entries
= ixgbe_rss_indir_tbl_entries(adapter
);
3831 struct ixgbe_hw
*hw
= &adapter
->hw
;
3834 u8
*indir_tbl
= adapter
->rss_indir_tbl
;
3836 /* Fill out the redirection table as follows:
3837 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3839 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3840 * - X550: 8 bit wide entries containing 6 bit RSS index
3842 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
3843 indices_multi
= 0x11;
3845 indices_multi
= 0x1;
3847 /* Write redirection table to HW */
3848 for (i
= 0; i
< reta_entries
; i
++) {
3849 reta
|= indices_multi
* indir_tbl
[i
] << (i
& 0x3) * 8;
3852 IXGBE_WRITE_REG(hw
, IXGBE_RETA(i
>> 2), reta
);
3854 IXGBE_WRITE_REG(hw
, IXGBE_ERETA((i
>> 2) - 32),
3862 * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
3863 * @adapter: device handle
3865 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3867 static void ixgbe_store_vfreta(struct ixgbe_adapter
*adapter
)
3869 u32 i
, reta_entries
= ixgbe_rss_indir_tbl_entries(adapter
);
3870 struct ixgbe_hw
*hw
= &adapter
->hw
;
3873 /* Write redirection table to HW */
3874 for (i
= 0; i
< reta_entries
; i
++) {
3875 u16 pool
= adapter
->num_rx_pools
;
3877 vfreta
|= (u32
)adapter
->rss_indir_tbl
[i
] << (i
& 0x3) * 8;
3883 IXGBE_PFVFRETA(i
>> 2, VMDQ_P(pool
)),
3889 static void ixgbe_setup_reta(struct ixgbe_adapter
*adapter
)
3892 u32 reta_entries
= ixgbe_rss_indir_tbl_entries(adapter
);
3893 u16 rss_i
= adapter
->ring_feature
[RING_F_RSS
].indices
;
3895 /* Program table for at least 4 queues w/ SR-IOV so that VFs can
3896 * make full use of any rings they may have. We will use the
3897 * PSRTYPE register to control how many rings we use within the PF.
3899 if ((adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) && (rss_i
< 4))
3902 /* Fill out hash function seeds */
3903 ixgbe_store_key(adapter
);
3905 /* Fill out redirection table */
3906 memset(adapter
->rss_indir_tbl
, 0, sizeof(adapter
->rss_indir_tbl
));
3908 for (i
= 0, j
= 0; i
< reta_entries
; i
++, j
++) {
3912 adapter
->rss_indir_tbl
[i
] = j
;
3915 ixgbe_store_reta(adapter
);
3918 static void ixgbe_setup_vfreta(struct ixgbe_adapter
*adapter
)
3920 struct ixgbe_hw
*hw
= &adapter
->hw
;
3921 u16 rss_i
= adapter
->ring_feature
[RING_F_RSS
].indices
;
3924 /* Fill out hash function seeds */
3925 for (i
= 0; i
< 10; i
++) {
3926 u16 pool
= adapter
->num_rx_pools
;
3930 IXGBE_PFVFRSSRK(i
, VMDQ_P(pool
)),
3931 *(adapter
->rss_key
+ i
));
3934 /* Fill out the redirection table */
3935 for (i
= 0, j
= 0; i
< 64; i
++, j
++) {
3939 adapter
->rss_indir_tbl
[i
] = j
;
3942 ixgbe_store_vfreta(adapter
);
3945 static void ixgbe_setup_mrqc(struct ixgbe_adapter
*adapter
)
3947 struct ixgbe_hw
*hw
= &adapter
->hw
;
3948 u32 mrqc
= 0, rss_field
= 0, vfmrqc
= 0;
3951 /* Disable indicating checksum in descriptor, enables RSS hash */
3952 rxcsum
= IXGBE_READ_REG(hw
, IXGBE_RXCSUM
);
3953 rxcsum
|= IXGBE_RXCSUM_PCSD
;
3954 IXGBE_WRITE_REG(hw
, IXGBE_RXCSUM
, rxcsum
);
3956 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
3957 if (adapter
->ring_feature
[RING_F_RSS
].mask
)
3958 mrqc
= IXGBE_MRQC_RSSEN
;
3960 u8 tcs
= adapter
->hw_tcs
;
3962 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
3964 mrqc
= IXGBE_MRQC_VMDQRT8TCEN
; /* 8 TCs */
3966 mrqc
= IXGBE_MRQC_VMDQRT4TCEN
; /* 4 TCs */
3967 else if (adapter
->ring_feature
[RING_F_VMDQ
].mask
==
3968 IXGBE_82599_VMDQ_4Q_MASK
)
3969 mrqc
= IXGBE_MRQC_VMDQRSS32EN
;
3971 mrqc
= IXGBE_MRQC_VMDQRSS64EN
;
3973 /* Enable L3/L4 for Tx Switched packets only for X550,
3974 * older devices do not support this feature
3976 if (hw
->mac
.type
>= ixgbe_mac_X550
)
3977 mrqc
|= IXGBE_MRQC_L3L4TXSWEN
;
3980 mrqc
= IXGBE_MRQC_RTRSS8TCEN
;
3982 mrqc
= IXGBE_MRQC_RTRSS4TCEN
;
3984 mrqc
= IXGBE_MRQC_RSSEN
;
3988 /* Perform hash on these packet types */
3989 rss_field
|= IXGBE_MRQC_RSS_FIELD_IPV4
|
3990 IXGBE_MRQC_RSS_FIELD_IPV4_TCP
|
3991 IXGBE_MRQC_RSS_FIELD_IPV6
|
3992 IXGBE_MRQC_RSS_FIELD_IPV6_TCP
;
3994 if (adapter
->flags2
& IXGBE_FLAG2_RSS_FIELD_IPV4_UDP
)
3995 rss_field
|= IXGBE_MRQC_RSS_FIELD_IPV4_UDP
;
3996 if (adapter
->flags2
& IXGBE_FLAG2_RSS_FIELD_IPV6_UDP
)
3997 rss_field
|= IXGBE_MRQC_RSS_FIELD_IPV6_UDP
;
3999 if ((hw
->mac
.type
>= ixgbe_mac_X550
) &&
4000 (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)) {
4001 u16 pool
= adapter
->num_rx_pools
;
4003 /* Enable VF RSS mode */
4004 mrqc
|= IXGBE_MRQC_MULTIPLE_RSS
;
4005 IXGBE_WRITE_REG(hw
, IXGBE_MRQC
, mrqc
);
4007 /* Setup RSS through the VF registers */
4008 ixgbe_setup_vfreta(adapter
);
4009 vfmrqc
= IXGBE_MRQC_RSSEN
;
4010 vfmrqc
|= rss_field
;
4014 IXGBE_PFVFMRQC(VMDQ_P(pool
)),
4017 ixgbe_setup_reta(adapter
);
4019 IXGBE_WRITE_REG(hw
, IXGBE_MRQC
, mrqc
);
4024 * ixgbe_configure_rscctl - enable RSC for the indicated ring
4025 * @adapter: address of board private structure
4026 * @ring: structure containing ring specific data
4028 static void ixgbe_configure_rscctl(struct ixgbe_adapter
*adapter
,
4029 struct ixgbe_ring
*ring
)
4031 struct ixgbe_hw
*hw
= &adapter
->hw
;
4033 u8 reg_idx
= ring
->reg_idx
;
4035 if (!ring_is_rsc_enabled(ring
))
4038 rscctrl
= IXGBE_READ_REG(hw
, IXGBE_RSCCTL(reg_idx
));
4039 rscctrl
|= IXGBE_RSCCTL_RSCEN
;
4041 * we must limit the number of descriptors so that the
4042 * total size of max desc * buf_len is not greater
4045 rscctrl
|= IXGBE_RSCCTL_MAXDESC_16
;
4046 IXGBE_WRITE_REG(hw
, IXGBE_RSCCTL(reg_idx
), rscctrl
);
4049 #define IXGBE_MAX_RX_DESC_POLL 10
4050 static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter
*adapter
,
4051 struct ixgbe_ring
*ring
)
4053 struct ixgbe_hw
*hw
= &adapter
->hw
;
4054 int wait_loop
= IXGBE_MAX_RX_DESC_POLL
;
4056 u8 reg_idx
= ring
->reg_idx
;
4058 if (ixgbe_removed(hw
->hw_addr
))
4060 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
4061 if (hw
->mac
.type
== ixgbe_mac_82598EB
&&
4062 !(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
4066 usleep_range(1000, 2000);
4067 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
4068 } while (--wait_loop
&& !(rxdctl
& IXGBE_RXDCTL_ENABLE
));
4071 e_err(drv
, "RXDCTL.ENABLE on Rx queue %d not set within "
4072 "the polling period\n", reg_idx
);
4076 void ixgbe_configure_rx_ring(struct ixgbe_adapter
*adapter
,
4077 struct ixgbe_ring
*ring
)
4079 struct ixgbe_hw
*hw
= &adapter
->hw
;
4080 union ixgbe_adv_rx_desc
*rx_desc
;
4081 u64 rdba
= ring
->dma
;
4083 u8 reg_idx
= ring
->reg_idx
;
4085 xdp_rxq_info_unreg_mem_model(&ring
->xdp_rxq
);
4086 ring
->xsk_pool
= ixgbe_xsk_pool(adapter
, ring
);
4087 if (ring
->xsk_pool
) {
4088 WARN_ON(xdp_rxq_info_reg_mem_model(&ring
->xdp_rxq
,
4089 MEM_TYPE_XSK_BUFF_POOL
,
4091 xsk_pool_set_rxq_info(ring
->xsk_pool
, &ring
->xdp_rxq
);
4093 WARN_ON(xdp_rxq_info_reg_mem_model(&ring
->xdp_rxq
,
4094 MEM_TYPE_PAGE_SHARED
, NULL
));
4097 /* disable queue to avoid use of these values while updating state */
4098 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
4099 rxdctl
&= ~IXGBE_RXDCTL_ENABLE
;
4101 /* write value back with RXDCTL.ENABLE bit cleared */
4102 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(reg_idx
), rxdctl
);
4103 IXGBE_WRITE_FLUSH(hw
);
4105 IXGBE_WRITE_REG(hw
, IXGBE_RDBAL(reg_idx
), (rdba
& DMA_BIT_MASK(32)));
4106 IXGBE_WRITE_REG(hw
, IXGBE_RDBAH(reg_idx
), (rdba
>> 32));
4107 IXGBE_WRITE_REG(hw
, IXGBE_RDLEN(reg_idx
),
4108 ring
->count
* sizeof(union ixgbe_adv_rx_desc
));
4109 /* Force flushing of IXGBE_RDLEN to prevent MDD */
4110 IXGBE_WRITE_FLUSH(hw
);
4112 IXGBE_WRITE_REG(hw
, IXGBE_RDH(reg_idx
), 0);
4113 IXGBE_WRITE_REG(hw
, IXGBE_RDT(reg_idx
), 0);
4114 ring
->tail
= adapter
->io_addr
+ IXGBE_RDT(reg_idx
);
4116 ixgbe_configure_srrctl(adapter
, ring
);
4117 ixgbe_configure_rscctl(adapter
, ring
);
4119 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
4121 * enable cache line friendly hardware writes:
4122 * PTHRESH=32 descriptors (half the internal cache),
4123 * this also removes ugly rx_no_buffer_count increment
4124 * HTHRESH=4 descriptors (to minimize latency on fetch)
4125 * WTHRESH=8 burst writeback up to two cache lines
4127 rxdctl
&= ~0x3FFFFF;
4129 #if (PAGE_SIZE < 8192)
4130 /* RXDCTL.RLPML does not work on 82599 */
4131 } else if (hw
->mac
.type
!= ixgbe_mac_82599EB
) {
4132 rxdctl
&= ~(IXGBE_RXDCTL_RLPMLMASK
|
4133 IXGBE_RXDCTL_RLPML_EN
);
4135 /* Limit the maximum frame size so we don't overrun the skb.
4136 * This can happen in SRIOV mode when the MTU of the VF is
4137 * higher than the MTU of the PF.
4139 if (ring_uses_build_skb(ring
) &&
4140 !test_bit(__IXGBE_RX_3K_BUFFER
, &ring
->state
))
4141 rxdctl
|= IXGBE_MAX_2K_FRAME_BUILD_SKB
|
4142 IXGBE_RXDCTL_RLPML_EN
;
4146 ring
->rx_offset
= ixgbe_rx_offset(ring
);
4148 if (ring
->xsk_pool
&& hw
->mac
.type
!= ixgbe_mac_82599EB
) {
4149 u32 xsk_buf_len
= xsk_pool_get_rx_frame_size(ring
->xsk_pool
);
4151 rxdctl
&= ~(IXGBE_RXDCTL_RLPMLMASK
|
4152 IXGBE_RXDCTL_RLPML_EN
);
4153 rxdctl
|= xsk_buf_len
| IXGBE_RXDCTL_RLPML_EN
;
4155 ring
->rx_buf_len
= xsk_buf_len
;
4158 /* initialize rx_buffer_info */
4159 memset(ring
->rx_buffer_info
, 0,
4160 sizeof(struct ixgbe_rx_buffer
) * ring
->count
);
4162 /* initialize Rx descriptor 0 */
4163 rx_desc
= IXGBE_RX_DESC(ring
, 0);
4164 rx_desc
->wb
.upper
.length
= 0;
4166 /* enable receive descriptor ring */
4167 rxdctl
|= IXGBE_RXDCTL_ENABLE
;
4168 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(reg_idx
), rxdctl
);
4170 ixgbe_rx_desc_queue_enable(adapter
, ring
);
4172 ixgbe_alloc_rx_buffers_zc(ring
, ixgbe_desc_unused(ring
));
4174 ixgbe_alloc_rx_buffers(ring
, ixgbe_desc_unused(ring
));
4177 static void ixgbe_setup_psrtype(struct ixgbe_adapter
*adapter
)
4179 struct ixgbe_hw
*hw
= &adapter
->hw
;
4180 int rss_i
= adapter
->ring_feature
[RING_F_RSS
].indices
;
4181 u16 pool
= adapter
->num_rx_pools
;
4183 /* PSRTYPE must be initialized in non 82598 adapters */
4184 u32 psrtype
= IXGBE_PSRTYPE_TCPHDR
|
4185 IXGBE_PSRTYPE_UDPHDR
|
4186 IXGBE_PSRTYPE_IPV4HDR
|
4187 IXGBE_PSRTYPE_L2HDR
|
4188 IXGBE_PSRTYPE_IPV6HDR
;
4190 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
4194 psrtype
|= 2u << 29;
4196 psrtype
|= 1u << 29;
4199 IXGBE_WRITE_REG(hw
, IXGBE_PSRTYPE(VMDQ_P(pool
)), psrtype
);
4202 static void ixgbe_configure_virtualization(struct ixgbe_adapter
*adapter
)
4204 struct ixgbe_hw
*hw
= &adapter
->hw
;
4205 u16 pool
= adapter
->num_rx_pools
;
4206 u32 reg_offset
, vf_shift
, vmolr
;
4207 u32 gcr_ext
, vmdctl
;
4210 if (!(adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
))
4213 vmdctl
= IXGBE_READ_REG(hw
, IXGBE_VT_CTL
);
4214 vmdctl
|= IXGBE_VMD_CTL_VMDQ_EN
;
4215 vmdctl
&= ~IXGBE_VT_CTL_POOL_MASK
;
4216 vmdctl
|= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT
;
4217 vmdctl
|= IXGBE_VT_CTL_REPLEN
;
4218 IXGBE_WRITE_REG(hw
, IXGBE_VT_CTL
, vmdctl
);
4220 /* accept untagged packets until a vlan tag is
4221 * specifically set for the VMDQ queue/pool
4223 vmolr
= IXGBE_VMOLR_AUPE
;
4225 IXGBE_WRITE_REG(hw
, IXGBE_VMOLR(VMDQ_P(pool
)), vmolr
);
4227 vf_shift
= VMDQ_P(0) % 32;
4228 reg_offset
= (VMDQ_P(0) >= 32) ? 1 : 0;
4230 /* Enable only the PF's pool for Tx/Rx */
4231 IXGBE_WRITE_REG(hw
, IXGBE_VFRE(reg_offset
), GENMASK(31, vf_shift
));
4232 IXGBE_WRITE_REG(hw
, IXGBE_VFRE(reg_offset
^ 1), reg_offset
- 1);
4233 IXGBE_WRITE_REG(hw
, IXGBE_VFTE(reg_offset
), GENMASK(31, vf_shift
));
4234 IXGBE_WRITE_REG(hw
, IXGBE_VFTE(reg_offset
^ 1), reg_offset
- 1);
4235 if (adapter
->bridge_mode
== BRIDGE_MODE_VEB
)
4236 IXGBE_WRITE_REG(hw
, IXGBE_PFDTXGSWC
, IXGBE_PFDTXGSWC_VT_LBEN
);
4238 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
4239 hw
->mac
.ops
.set_vmdq(hw
, 0, VMDQ_P(0));
4241 /* clear VLAN promisc flag so VFTA will be updated if necessary */
4242 adapter
->flags2
&= ~IXGBE_FLAG2_VLAN_PROMISC
;
4245 * Set up VF register offsets for selected VT Mode,
4246 * i.e. 32 or 64 VFs for SR-IOV
4248 switch (adapter
->ring_feature
[RING_F_VMDQ
].mask
) {
4249 case IXGBE_82599_VMDQ_8Q_MASK
:
4250 gcr_ext
= IXGBE_GCR_EXT_VT_MODE_16
;
4252 case IXGBE_82599_VMDQ_4Q_MASK
:
4253 gcr_ext
= IXGBE_GCR_EXT_VT_MODE_32
;
4256 gcr_ext
= IXGBE_GCR_EXT_VT_MODE_64
;
4260 IXGBE_WRITE_REG(hw
, IXGBE_GCR_EXT
, gcr_ext
);
4262 for (i
= 0; i
< adapter
->num_vfs
; i
++) {
4263 /* configure spoof checking */
4264 ixgbe_ndo_set_vf_spoofchk(adapter
->netdev
, i
,
4265 adapter
->vfinfo
[i
].spoofchk_enabled
);
4267 /* Enable/Disable RSS query feature */
4268 ixgbe_ndo_set_vf_rss_query_en(adapter
->netdev
, i
,
4269 adapter
->vfinfo
[i
].rss_query_enabled
);
4273 static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter
*adapter
)
4275 struct ixgbe_hw
*hw
= &adapter
->hw
;
4276 struct net_device
*netdev
= adapter
->netdev
;
4277 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
4278 struct ixgbe_ring
*rx_ring
;
4283 /* adjust max frame to be able to do baby jumbo for FCoE */
4284 if ((adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) &&
4285 (max_frame
< IXGBE_FCOE_JUMBO_FRAME_SIZE
))
4286 max_frame
= IXGBE_FCOE_JUMBO_FRAME_SIZE
;
4288 #endif /* IXGBE_FCOE */
4290 /* adjust max frame to be at least the size of a standard frame */
4291 if (max_frame
< (ETH_FRAME_LEN
+ ETH_FCS_LEN
))
4292 max_frame
= (ETH_FRAME_LEN
+ ETH_FCS_LEN
);
4294 mhadd
= IXGBE_READ_REG(hw
, IXGBE_MHADD
);
4295 if (max_frame
!= (mhadd
>> IXGBE_MHADD_MFS_SHIFT
)) {
4296 mhadd
&= ~IXGBE_MHADD_MFS_MASK
;
4297 mhadd
|= max_frame
<< IXGBE_MHADD_MFS_SHIFT
;
4299 IXGBE_WRITE_REG(hw
, IXGBE_MHADD
, mhadd
);
4302 hlreg0
= IXGBE_READ_REG(hw
, IXGBE_HLREG0
);
4303 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
4304 hlreg0
|= IXGBE_HLREG0_JUMBOEN
;
4305 IXGBE_WRITE_REG(hw
, IXGBE_HLREG0
, hlreg0
);
4308 * Setup the HW Rx Head and Tail Descriptor Pointers and
4309 * the Base and Length of the Rx Descriptor Ring
4311 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
4312 rx_ring
= adapter
->rx_ring
[i
];
4314 clear_ring_rsc_enabled(rx_ring
);
4315 clear_bit(__IXGBE_RX_3K_BUFFER
, &rx_ring
->state
);
4316 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED
, &rx_ring
->state
);
4318 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)
4319 set_ring_rsc_enabled(rx_ring
);
4321 if (test_bit(__IXGBE_RX_FCOE
, &rx_ring
->state
))
4322 set_bit(__IXGBE_RX_3K_BUFFER
, &rx_ring
->state
);
4324 if (adapter
->flags2
& IXGBE_FLAG2_RX_LEGACY
)
4327 set_bit(__IXGBE_RX_BUILD_SKB_ENABLED
, &rx_ring
->state
);
4329 #if (PAGE_SIZE < 8192)
4330 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)
4331 set_bit(__IXGBE_RX_3K_BUFFER
, &rx_ring
->state
);
4333 if (IXGBE_2K_TOO_SMALL_WITH_PADDING
||
4334 (max_frame
> (ETH_FRAME_LEN
+ ETH_FCS_LEN
)))
4335 set_bit(__IXGBE_RX_3K_BUFFER
, &rx_ring
->state
);
4340 static void ixgbe_setup_rdrxctl(struct ixgbe_adapter
*adapter
)
4342 struct ixgbe_hw
*hw
= &adapter
->hw
;
4343 u32 rdrxctl
= IXGBE_READ_REG(hw
, IXGBE_RDRXCTL
);
4345 switch (hw
->mac
.type
) {
4346 case ixgbe_mac_82598EB
:
4348 * For VMDq support of different descriptor types or
4349 * buffer sizes through the use of multiple SRRCTL
4350 * registers, RDRXCTL.MVMEN must be set to 1
4352 * also, the manual doesn't mention it clearly but DCA hints
4353 * will only use queue 0's tags unless this bit is set. Side
4354 * effects of setting this bit are only that SRRCTL must be
4355 * fully programmed [0..15]
4357 rdrxctl
|= IXGBE_RDRXCTL_MVMEN
;
4359 case ixgbe_mac_X550
:
4360 case ixgbe_mac_X550EM_x
:
4361 case ixgbe_mac_x550em_a
:
4362 if (adapter
->num_vfs
)
4363 rdrxctl
|= IXGBE_RDRXCTL_PSP
;
4365 case ixgbe_mac_82599EB
:
4366 case ixgbe_mac_X540
:
4367 /* Disable RSC for ACK packets */
4368 IXGBE_WRITE_REG(hw
, IXGBE_RSCDBU
,
4369 (IXGBE_RSCDBU_RSCACKDIS
| IXGBE_READ_REG(hw
, IXGBE_RSCDBU
)));
4370 rdrxctl
&= ~IXGBE_RDRXCTL_RSCFRSTSIZE
;
4371 /* hardware requires some bits to be set by default */
4372 rdrxctl
|= (IXGBE_RDRXCTL_RSCACKC
| IXGBE_RDRXCTL_FCOE_WRFIX
);
4373 rdrxctl
|= IXGBE_RDRXCTL_CRCSTRIP
;
4376 /* We should do nothing since we don't know this hardware */
4380 IXGBE_WRITE_REG(hw
, IXGBE_RDRXCTL
, rdrxctl
);
4384 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
4385 * @adapter: board private structure
4387 * Configure the Rx unit of the MAC after a reset.
4389 static void ixgbe_configure_rx(struct ixgbe_adapter
*adapter
)
4391 struct ixgbe_hw
*hw
= &adapter
->hw
;
4395 /* disable receives while setting up the descriptors */
4396 hw
->mac
.ops
.disable_rx(hw
);
4398 ixgbe_setup_psrtype(adapter
);
4399 ixgbe_setup_rdrxctl(adapter
);
4402 rfctl
= IXGBE_READ_REG(hw
, IXGBE_RFCTL
);
4403 rfctl
&= ~IXGBE_RFCTL_RSC_DIS
;
4404 if (!(adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
))
4405 rfctl
|= IXGBE_RFCTL_RSC_DIS
;
4407 /* disable NFS filtering */
4408 rfctl
|= (IXGBE_RFCTL_NFSW_DIS
| IXGBE_RFCTL_NFSR_DIS
);
4409 IXGBE_WRITE_REG(hw
, IXGBE_RFCTL
, rfctl
);
4411 /* Program registers for the distribution of queues */
4412 ixgbe_setup_mrqc(adapter
);
4414 /* set_rx_buffer_len must be called before ring initialization */
4415 ixgbe_set_rx_buffer_len(adapter
);
4418 * Setup the HW Rx Head and Tail Descriptor Pointers and
4419 * the Base and Length of the Rx Descriptor Ring
4421 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
4422 ixgbe_configure_rx_ring(adapter
, adapter
->rx_ring
[i
]);
4424 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
4425 /* disable drop enable for 82598 parts */
4426 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
4427 rxctrl
|= IXGBE_RXCTRL_DMBYPS
;
4429 /* enable all receives */
4430 rxctrl
|= IXGBE_RXCTRL_RXEN
;
4431 hw
->mac
.ops
.enable_rx_dma(hw
, rxctrl
);
4434 static int ixgbe_vlan_rx_add_vid(struct net_device
*netdev
,
4435 __be16 proto
, u16 vid
)
4437 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4438 struct ixgbe_hw
*hw
= &adapter
->hw
;
4440 /* add VID to filter table */
4441 if (!vid
|| !(adapter
->flags2
& IXGBE_FLAG2_VLAN_PROMISC
))
4442 hw
->mac
.ops
.set_vfta(&adapter
->hw
, vid
, VMDQ_P(0), true, !!vid
);
4444 set_bit(vid
, adapter
->active_vlans
);
4449 static int ixgbe_find_vlvf_entry(struct ixgbe_hw
*hw
, u32 vlan
)
4454 /* short cut the special case */
4458 /* Search for the vlan id in the VLVF entries */
4459 for (idx
= IXGBE_VLVF_ENTRIES
; --idx
;) {
4460 vlvf
= IXGBE_READ_REG(hw
, IXGBE_VLVF(idx
));
4461 if ((vlvf
& VLAN_VID_MASK
) == vlan
)
4468 void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter
*adapter
, u32 vid
)
4470 struct ixgbe_hw
*hw
= &adapter
->hw
;
4474 idx
= ixgbe_find_vlvf_entry(hw
, vid
);
4478 /* See if any other pools are set for this VLAN filter
4479 * entry other than the PF.
4481 word
= idx
* 2 + (VMDQ_P(0) / 32);
4482 bits
= ~BIT(VMDQ_P(0) % 32);
4483 bits
&= IXGBE_READ_REG(hw
, IXGBE_VLVFB(word
));
4485 /* Disable the filter so this falls into the default pool. */
4486 if (!bits
&& !IXGBE_READ_REG(hw
, IXGBE_VLVFB(word
^ 1))) {
4487 if (!(adapter
->flags2
& IXGBE_FLAG2_VLAN_PROMISC
))
4488 IXGBE_WRITE_REG(hw
, IXGBE_VLVFB(word
), 0);
4489 IXGBE_WRITE_REG(hw
, IXGBE_VLVF(idx
), 0);
4493 static int ixgbe_vlan_rx_kill_vid(struct net_device
*netdev
,
4494 __be16 proto
, u16 vid
)
4496 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4497 struct ixgbe_hw
*hw
= &adapter
->hw
;
4499 /* remove VID from filter table */
4500 if (vid
&& !(adapter
->flags2
& IXGBE_FLAG2_VLAN_PROMISC
))
4501 hw
->mac
.ops
.set_vfta(hw
, vid
, VMDQ_P(0), false, true);
4503 clear_bit(vid
, adapter
->active_vlans
);
4509 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
4510 * @adapter: driver data
4512 static void ixgbe_vlan_strip_disable(struct ixgbe_adapter
*adapter
)
4514 struct ixgbe_hw
*hw
= &adapter
->hw
;
4518 switch (hw
->mac
.type
) {
4519 case ixgbe_mac_82598EB
:
4520 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
4521 vlnctrl
&= ~IXGBE_VLNCTRL_VME
;
4522 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
4524 case ixgbe_mac_82599EB
:
4525 case ixgbe_mac_X540
:
4526 case ixgbe_mac_X550
:
4527 case ixgbe_mac_X550EM_x
:
4528 case ixgbe_mac_x550em_a
:
4529 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
4530 struct ixgbe_ring
*ring
= adapter
->rx_ring
[i
];
4532 if (!netif_is_ixgbe(ring
->netdev
))
4536 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
4537 vlnctrl
&= ~IXGBE_RXDCTL_VME
;
4538 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), vlnctrl
);
4547 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
4548 * @adapter: driver data
4550 static void ixgbe_vlan_strip_enable(struct ixgbe_adapter
*adapter
)
4552 struct ixgbe_hw
*hw
= &adapter
->hw
;
4556 switch (hw
->mac
.type
) {
4557 case ixgbe_mac_82598EB
:
4558 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
4559 vlnctrl
|= IXGBE_VLNCTRL_VME
;
4560 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
4562 case ixgbe_mac_82599EB
:
4563 case ixgbe_mac_X540
:
4564 case ixgbe_mac_X550
:
4565 case ixgbe_mac_X550EM_x
:
4566 case ixgbe_mac_x550em_a
:
4567 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
4568 struct ixgbe_ring
*ring
= adapter
->rx_ring
[i
];
4570 if (!netif_is_ixgbe(ring
->netdev
))
4574 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
4575 vlnctrl
|= IXGBE_RXDCTL_VME
;
4576 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), vlnctrl
);
4584 static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter
*adapter
)
4586 struct ixgbe_hw
*hw
= &adapter
->hw
;
4589 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
4591 if (adapter
->flags
& IXGBE_FLAG_VMDQ_ENABLED
) {
4592 /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
4593 vlnctrl
|= IXGBE_VLNCTRL_VFE
;
4594 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
4596 vlnctrl
&= ~IXGBE_VLNCTRL_VFE
;
4597 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
4601 /* Nothing to do for 82598 */
4602 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
4605 /* We are already in VLAN promisc, nothing to do */
4606 if (adapter
->flags2
& IXGBE_FLAG2_VLAN_PROMISC
)
4609 /* Set flag so we don't redo unnecessary work */
4610 adapter
->flags2
|= IXGBE_FLAG2_VLAN_PROMISC
;
4612 /* Add PF to all active pools */
4613 for (i
= IXGBE_VLVF_ENTRIES
; --i
;) {
4614 u32 reg_offset
= IXGBE_VLVFB(i
* 2 + VMDQ_P(0) / 32);
4615 u32 vlvfb
= IXGBE_READ_REG(hw
, reg_offset
);
4617 vlvfb
|= BIT(VMDQ_P(0) % 32);
4618 IXGBE_WRITE_REG(hw
, reg_offset
, vlvfb
);
4621 /* Set all bits in the VLAN filter table array */
4622 for (i
= hw
->mac
.vft_size
; i
--;)
4623 IXGBE_WRITE_REG(hw
, IXGBE_VFTA(i
), ~0U);
4626 #define VFTA_BLOCK_SIZE 8
4627 static void ixgbe_scrub_vfta(struct ixgbe_adapter
*adapter
, u32 vfta_offset
)
4629 struct ixgbe_hw
*hw
= &adapter
->hw
;
4630 u32 vfta
[VFTA_BLOCK_SIZE
] = { 0 };
4631 u32 vid_start
= vfta_offset
* 32;
4632 u32 vid_end
= vid_start
+ (VFTA_BLOCK_SIZE
* 32);
4633 u32 i
, vid
, word
, bits
;
4635 for (i
= IXGBE_VLVF_ENTRIES
; --i
;) {
4636 u32 vlvf
= IXGBE_READ_REG(hw
, IXGBE_VLVF(i
));
4638 /* pull VLAN ID from VLVF */
4639 vid
= vlvf
& VLAN_VID_MASK
;
4641 /* only concern outselves with a certain range */
4642 if (vid
< vid_start
|| vid
>= vid_end
)
4646 /* record VLAN ID in VFTA */
4647 vfta
[(vid
- vid_start
) / 32] |= BIT(vid
% 32);
4649 /* if PF is part of this then continue */
4650 if (test_bit(vid
, adapter
->active_vlans
))
4654 /* remove PF from the pool */
4655 word
= i
* 2 + VMDQ_P(0) / 32;
4656 bits
= ~BIT(VMDQ_P(0) % 32);
4657 bits
&= IXGBE_READ_REG(hw
, IXGBE_VLVFB(word
));
4658 IXGBE_WRITE_REG(hw
, IXGBE_VLVFB(word
), bits
);
4661 /* extract values from active_vlans and write back to VFTA */
4662 for (i
= VFTA_BLOCK_SIZE
; i
--;) {
4663 vid
= (vfta_offset
+ i
) * 32;
4664 word
= vid
/ BITS_PER_LONG
;
4665 bits
= vid
% BITS_PER_LONG
;
4667 vfta
[i
] |= adapter
->active_vlans
[word
] >> bits
;
4669 IXGBE_WRITE_REG(hw
, IXGBE_VFTA(vfta_offset
+ i
), vfta
[i
]);
4673 static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter
*adapter
)
4675 struct ixgbe_hw
*hw
= &adapter
->hw
;
4678 /* Set VLAN filtering to enabled */
4679 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
4680 vlnctrl
|= IXGBE_VLNCTRL_VFE
;
4681 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
4683 if (!(adapter
->flags
& IXGBE_FLAG_VMDQ_ENABLED
) ||
4684 hw
->mac
.type
== ixgbe_mac_82598EB
)
4687 /* We are not in VLAN promisc, nothing to do */
4688 if (!(adapter
->flags2
& IXGBE_FLAG2_VLAN_PROMISC
))
4691 /* Set flag so we don't redo unnecessary work */
4692 adapter
->flags2
&= ~IXGBE_FLAG2_VLAN_PROMISC
;
4694 for (i
= 0; i
< hw
->mac
.vft_size
; i
+= VFTA_BLOCK_SIZE
)
4695 ixgbe_scrub_vfta(adapter
, i
);
4698 static void ixgbe_restore_vlan(struct ixgbe_adapter
*adapter
)
4702 ixgbe_vlan_rx_add_vid(adapter
->netdev
, htons(ETH_P_8021Q
), 0);
4704 for_each_set_bit_from(vid
, adapter
->active_vlans
, VLAN_N_VID
)
4705 ixgbe_vlan_rx_add_vid(adapter
->netdev
, htons(ETH_P_8021Q
), vid
);
4709 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
4710 * @netdev: network interface device structure
4712 * Writes multicast address list to the MTA hash table.
4713 * Returns: -ENOMEM on failure
4714 * 0 on no addresses written
4715 * X on writing X addresses to MTA
4717 static int ixgbe_write_mc_addr_list(struct net_device
*netdev
)
4719 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4720 struct ixgbe_hw
*hw
= &adapter
->hw
;
4722 if (!netif_running(netdev
))
4725 if (hw
->mac
.ops
.update_mc_addr_list
)
4726 hw
->mac
.ops
.update_mc_addr_list(hw
, netdev
);
4730 #ifdef CONFIG_PCI_IOV
4731 ixgbe_restore_vf_multicasts(adapter
);
4734 return netdev_mc_count(netdev
);
4737 #ifdef CONFIG_PCI_IOV
4738 void ixgbe_full_sync_mac_table(struct ixgbe_adapter
*adapter
)
4740 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4741 struct ixgbe_hw
*hw
= &adapter
->hw
;
4744 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4745 mac_table
->state
&= ~IXGBE_MAC_STATE_MODIFIED
;
4747 if (mac_table
->state
& IXGBE_MAC_STATE_IN_USE
)
4748 hw
->mac
.ops
.set_rar(hw
, i
,
4753 hw
->mac
.ops
.clear_rar(hw
, i
);
4758 static void ixgbe_sync_mac_table(struct ixgbe_adapter
*adapter
)
4760 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4761 struct ixgbe_hw
*hw
= &adapter
->hw
;
4764 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4765 if (!(mac_table
->state
& IXGBE_MAC_STATE_MODIFIED
))
4768 mac_table
->state
&= ~IXGBE_MAC_STATE_MODIFIED
;
4770 if (mac_table
->state
& IXGBE_MAC_STATE_IN_USE
)
4771 hw
->mac
.ops
.set_rar(hw
, i
,
4776 hw
->mac
.ops
.clear_rar(hw
, i
);
4780 static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter
*adapter
)
4782 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4783 struct ixgbe_hw
*hw
= &adapter
->hw
;
4786 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4787 mac_table
->state
|= IXGBE_MAC_STATE_MODIFIED
;
4788 mac_table
->state
&= ~IXGBE_MAC_STATE_IN_USE
;
4791 ixgbe_sync_mac_table(adapter
);
4794 static int ixgbe_available_rars(struct ixgbe_adapter
*adapter
, u16 pool
)
4796 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4797 struct ixgbe_hw
*hw
= &adapter
->hw
;
4800 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4801 /* do not count default RAR as available */
4802 if (mac_table
->state
& IXGBE_MAC_STATE_DEFAULT
)
4805 /* only count unused and addresses that belong to us */
4806 if (mac_table
->state
& IXGBE_MAC_STATE_IN_USE
) {
4807 if (mac_table
->pool
!= pool
)
4817 /* this function destroys the first RAR entry */
4818 static void ixgbe_mac_set_default_filter(struct ixgbe_adapter
*adapter
)
4820 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4821 struct ixgbe_hw
*hw
= &adapter
->hw
;
4823 memcpy(&mac_table
->addr
, hw
->mac
.addr
, ETH_ALEN
);
4824 mac_table
->pool
= VMDQ_P(0);
4826 mac_table
->state
= IXGBE_MAC_STATE_DEFAULT
| IXGBE_MAC_STATE_IN_USE
;
4828 hw
->mac
.ops
.set_rar(hw
, 0, mac_table
->addr
, mac_table
->pool
,
4832 int ixgbe_add_mac_filter(struct ixgbe_adapter
*adapter
,
4833 const u8
*addr
, u16 pool
)
4835 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4836 struct ixgbe_hw
*hw
= &adapter
->hw
;
4839 if (is_zero_ether_addr(addr
))
4842 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4843 if (mac_table
->state
& IXGBE_MAC_STATE_IN_USE
)
4846 ether_addr_copy(mac_table
->addr
, addr
);
4847 mac_table
->pool
= pool
;
4849 mac_table
->state
|= IXGBE_MAC_STATE_MODIFIED
|
4850 IXGBE_MAC_STATE_IN_USE
;
4852 ixgbe_sync_mac_table(adapter
);
4860 int ixgbe_del_mac_filter(struct ixgbe_adapter
*adapter
,
4861 const u8
*addr
, u16 pool
)
4863 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4864 struct ixgbe_hw
*hw
= &adapter
->hw
;
4867 if (is_zero_ether_addr(addr
))
4870 /* search table for addr, if found clear IN_USE flag and sync */
4871 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4872 /* we can only delete an entry if it is in use */
4873 if (!(mac_table
->state
& IXGBE_MAC_STATE_IN_USE
))
4875 /* we only care about entries that belong to the given pool */
4876 if (mac_table
->pool
!= pool
)
4878 /* we only care about a specific MAC address */
4879 if (!ether_addr_equal(addr
, mac_table
->addr
))
4882 mac_table
->state
|= IXGBE_MAC_STATE_MODIFIED
;
4883 mac_table
->state
&= ~IXGBE_MAC_STATE_IN_USE
;
4885 ixgbe_sync_mac_table(adapter
);
4893 static int ixgbe_uc_sync(struct net_device
*netdev
, const unsigned char *addr
)
4895 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4898 ret
= ixgbe_add_mac_filter(adapter
, addr
, VMDQ_P(0));
4900 return min_t(int, ret
, 0);
4903 static int ixgbe_uc_unsync(struct net_device
*netdev
, const unsigned char *addr
)
4905 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4907 ixgbe_del_mac_filter(adapter
, addr
, VMDQ_P(0));
4913 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
4914 * @netdev: network interface device structure
4916 * The set_rx_method entry point is called whenever the unicast/multicast
4917 * address list or the network interface flags are updated. This routine is
4918 * responsible for configuring the hardware for proper unicast, multicast and
4921 void ixgbe_set_rx_mode(struct net_device
*netdev
)
4923 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4924 struct ixgbe_hw
*hw
= &adapter
->hw
;
4925 u32 fctrl
, vmolr
= IXGBE_VMOLR_BAM
| IXGBE_VMOLR_AUPE
;
4926 netdev_features_t features
= netdev
->features
;
4929 /* Check for Promiscuous and All Multicast modes */
4930 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
4932 /* set all bits that we expect to always be set */
4933 fctrl
&= ~IXGBE_FCTRL_SBP
; /* disable store-bad-packets */
4934 fctrl
|= IXGBE_FCTRL_BAM
;
4935 fctrl
|= IXGBE_FCTRL_DPF
; /* discard pause frames when FC enabled */
4936 fctrl
|= IXGBE_FCTRL_PMCF
;
4938 /* clear the bits we are changing the status of */
4939 fctrl
&= ~(IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
4940 if (netdev
->flags
& IFF_PROMISC
) {
4941 hw
->addr_ctrl
.user_set_promisc
= true;
4942 fctrl
|= (IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
4943 vmolr
|= IXGBE_VMOLR_MPE
;
4944 features
&= ~NETIF_F_HW_VLAN_CTAG_FILTER
;
4946 if (netdev
->flags
& IFF_ALLMULTI
) {
4947 fctrl
|= IXGBE_FCTRL_MPE
;
4948 vmolr
|= IXGBE_VMOLR_MPE
;
4950 hw
->addr_ctrl
.user_set_promisc
= false;
4954 * Write addresses to available RAR registers, if there is not
4955 * sufficient space to store all the addresses then enable
4956 * unicast promiscuous mode
4958 if (__dev_uc_sync(netdev
, ixgbe_uc_sync
, ixgbe_uc_unsync
)) {
4959 fctrl
|= IXGBE_FCTRL_UPE
;
4960 vmolr
|= IXGBE_VMOLR_ROPE
;
4963 /* Write addresses to the MTA, if the attempt fails
4964 * then we should just turn on promiscuous mode so
4965 * that we can at least receive multicast traffic
4967 count
= ixgbe_write_mc_addr_list(netdev
);
4969 fctrl
|= IXGBE_FCTRL_MPE
;
4970 vmolr
|= IXGBE_VMOLR_MPE
;
4972 vmolr
|= IXGBE_VMOLR_ROMPE
;
4975 if (hw
->mac
.type
!= ixgbe_mac_82598EB
) {
4976 vmolr
|= IXGBE_READ_REG(hw
, IXGBE_VMOLR(VMDQ_P(0))) &
4977 ~(IXGBE_VMOLR_MPE
| IXGBE_VMOLR_ROMPE
|
4979 IXGBE_WRITE_REG(hw
, IXGBE_VMOLR(VMDQ_P(0)), vmolr
);
4982 /* This is useful for sniffing bad packets. */
4983 if (features
& NETIF_F_RXALL
) {
4984 /* UPE and MPE will be handled by normal PROMISC logic
4985 * in e1000e_set_rx_mode */
4986 fctrl
|= (IXGBE_FCTRL_SBP
| /* Receive bad packets */
4987 IXGBE_FCTRL_BAM
| /* RX All Bcast Pkts */
4988 IXGBE_FCTRL_PMCF
); /* RX All MAC Ctrl Pkts */
4990 fctrl
&= ~(IXGBE_FCTRL_DPF
);
4991 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4994 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
4996 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
4997 ixgbe_vlan_strip_enable(adapter
);
4999 ixgbe_vlan_strip_disable(adapter
);
5001 if (features
& NETIF_F_HW_VLAN_CTAG_FILTER
)
5002 ixgbe_vlan_promisc_disable(adapter
);
5004 ixgbe_vlan_promisc_enable(adapter
);
5007 static void ixgbe_napi_enable_all(struct ixgbe_adapter
*adapter
)
5011 for (q_idx
= 0; q_idx
< adapter
->num_q_vectors
; q_idx
++)
5012 napi_enable(&adapter
->q_vector
[q_idx
]->napi
);
5015 static void ixgbe_napi_disable_all(struct ixgbe_adapter
*adapter
)
5019 for (q_idx
= 0; q_idx
< adapter
->num_q_vectors
; q_idx
++)
5020 napi_disable(&adapter
->q_vector
[q_idx
]->napi
);
5023 static int ixgbe_udp_tunnel_sync(struct net_device
*dev
, unsigned int table
)
5025 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
5026 struct ixgbe_hw
*hw
= &adapter
->hw
;
5027 struct udp_tunnel_info ti
;
5029 udp_tunnel_nic_get_port(dev
, table
, 0, &ti
);
5030 if (ti
.type
== UDP_TUNNEL_TYPE_VXLAN
)
5031 adapter
->vxlan_port
= ti
.port
;
5033 adapter
->geneve_port
= ti
.port
;
5035 IXGBE_WRITE_REG(hw
, IXGBE_VXLANCTRL
,
5036 ntohs(adapter
->vxlan_port
) |
5037 ntohs(adapter
->geneve_port
) <<
5038 IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT
);
5042 static const struct udp_tunnel_nic_info ixgbe_udp_tunnels_x550
= {
5043 .sync_table
= ixgbe_udp_tunnel_sync
,
5044 .flags
= UDP_TUNNEL_NIC_INFO_IPV4_ONLY
,
5046 { .n_entries
= 1, .tunnel_types
= UDP_TUNNEL_TYPE_VXLAN
, },
5050 static const struct udp_tunnel_nic_info ixgbe_udp_tunnels_x550em_a
= {
5051 .sync_table
= ixgbe_udp_tunnel_sync
,
5052 .flags
= UDP_TUNNEL_NIC_INFO_IPV4_ONLY
,
5054 { .n_entries
= 1, .tunnel_types
= UDP_TUNNEL_TYPE_VXLAN
, },
5055 { .n_entries
= 1, .tunnel_types
= UDP_TUNNEL_TYPE_GENEVE
, },
5059 #ifdef CONFIG_IXGBE_DCB
5061 * ixgbe_configure_dcb - Configure DCB hardware
5062 * @adapter: ixgbe adapter struct
5064 * This is called by the driver on open to configure the DCB hardware.
5065 * This is also called by the gennetlink interface when reconfiguring
5068 static void ixgbe_configure_dcb(struct ixgbe_adapter
*adapter
)
5070 struct ixgbe_hw
*hw
= &adapter
->hw
;
5071 int max_frame
= adapter
->netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
5073 if (!(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
)) {
5074 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
5075 netif_set_tso_max_size(adapter
->netdev
, 65536);
5079 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
5080 netif_set_tso_max_size(adapter
->netdev
, 32768);
5083 if (adapter
->netdev
->fcoe_mtu
)
5084 max_frame
= max(max_frame
, IXGBE_FCOE_JUMBO_FRAME_SIZE
);
5087 /* reconfigure the hardware */
5088 if (adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
) {
5089 ixgbe_dcb_calculate_tc_credits(hw
, &adapter
->dcb_cfg
, max_frame
,
5091 ixgbe_dcb_calculate_tc_credits(hw
, &adapter
->dcb_cfg
, max_frame
,
5093 ixgbe_dcb_hw_config(hw
, &adapter
->dcb_cfg
);
5094 } else if (adapter
->ixgbe_ieee_ets
&& adapter
->ixgbe_ieee_pfc
) {
5095 ixgbe_dcb_hw_ets(&adapter
->hw
,
5096 adapter
->ixgbe_ieee_ets
,
5098 ixgbe_dcb_hw_pfc_config(&adapter
->hw
,
5099 adapter
->ixgbe_ieee_pfc
->pfc_en
,
5100 adapter
->ixgbe_ieee_ets
->prio_tc
);
5103 /* Enable RSS Hash per TC */
5104 if (hw
->mac
.type
!= ixgbe_mac_82598EB
) {
5106 u16 rss_i
= adapter
->ring_feature
[RING_F_RSS
].indices
- 1;
5113 /* write msb to all 8 TCs in one write */
5114 IXGBE_WRITE_REG(hw
, IXGBE_RQTC
, msb
* 0x11111111);
5119 /* Additional bittime to account for IXGBE framing */
5120 #define IXGBE_ETH_FRAMING 20
5123 * ixgbe_hpbthresh - calculate high water mark for flow control
5125 * @adapter: board private structure to calculate for
5126 * @pb: packet buffer to calculate
5128 static int ixgbe_hpbthresh(struct ixgbe_adapter
*adapter
, int pb
)
5130 struct ixgbe_hw
*hw
= &adapter
->hw
;
5131 struct net_device
*dev
= adapter
->netdev
;
5132 int link
, tc
, kb
, marker
;
5135 /* Calculate max LAN frame size */
5136 tc
= link
= dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ IXGBE_ETH_FRAMING
;
5139 /* FCoE traffic class uses FCOE jumbo frames */
5140 if (dev
->fcoe_mtu
&& tc
< IXGBE_FCOE_JUMBO_FRAME_SIZE
&&
5141 (pb
== ixgbe_fcoe_get_tc(adapter
)))
5142 tc
= IXGBE_FCOE_JUMBO_FRAME_SIZE
;
5145 /* Calculate delay value for device */
5146 switch (hw
->mac
.type
) {
5147 case ixgbe_mac_X540
:
5148 case ixgbe_mac_X550
:
5149 case ixgbe_mac_X550EM_x
:
5150 case ixgbe_mac_x550em_a
:
5151 dv_id
= IXGBE_DV_X540(link
, tc
);
5154 dv_id
= IXGBE_DV(link
, tc
);
5158 /* Loopback switch introduces additional latency */
5159 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
5160 dv_id
+= IXGBE_B2BT(tc
);
5162 /* Delay value is calculated in bit times convert to KB */
5163 kb
= IXGBE_BT2KB(dv_id
);
5164 rx_pba
= IXGBE_READ_REG(hw
, IXGBE_RXPBSIZE(pb
)) >> 10;
5166 marker
= rx_pba
- kb
;
5168 /* It is possible that the packet buffer is not large enough
5169 * to provide required headroom. In this case throw an error
5170 * to user and a do the best we can.
5173 e_warn(drv
, "Packet Buffer(%i) can not provide enough"
5174 "headroom to support flow control."
5175 "Decrease MTU or number of traffic classes\n", pb
);
5183 * ixgbe_lpbthresh - calculate low water mark for flow control
5185 * @adapter: board private structure to calculate for
5186 * @pb: packet buffer to calculate
5188 static int ixgbe_lpbthresh(struct ixgbe_adapter
*adapter
, int pb
)
5190 struct ixgbe_hw
*hw
= &adapter
->hw
;
5191 struct net_device
*dev
= adapter
->netdev
;
5195 /* Calculate max LAN frame size */
5196 tc
= dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
5199 /* FCoE traffic class uses FCOE jumbo frames */
5200 if (dev
->fcoe_mtu
&& tc
< IXGBE_FCOE_JUMBO_FRAME_SIZE
&&
5201 (pb
== netdev_get_prio_tc_map(dev
, adapter
->fcoe
.up
)))
5202 tc
= IXGBE_FCOE_JUMBO_FRAME_SIZE
;
5205 /* Calculate delay value for device */
5206 switch (hw
->mac
.type
) {
5207 case ixgbe_mac_X540
:
5208 case ixgbe_mac_X550
:
5209 case ixgbe_mac_X550EM_x
:
5210 case ixgbe_mac_x550em_a
:
5211 dv_id
= IXGBE_LOW_DV_X540(tc
);
5214 dv_id
= IXGBE_LOW_DV(tc
);
5218 /* Delay value is calculated in bit times convert to KB */
5219 return IXGBE_BT2KB(dv_id
);
5223 * ixgbe_pbthresh_setup - calculate and setup high low water marks
5225 static void ixgbe_pbthresh_setup(struct ixgbe_adapter
*adapter
)
5227 struct ixgbe_hw
*hw
= &adapter
->hw
;
5228 int num_tc
= adapter
->hw_tcs
;
5234 for (i
= 0; i
< num_tc
; i
++) {
5235 hw
->fc
.high_water
[i
] = ixgbe_hpbthresh(adapter
, i
);
5236 hw
->fc
.low_water
[i
] = ixgbe_lpbthresh(adapter
, i
);
5238 /* Low water marks must not be larger than high water marks */
5239 if (hw
->fc
.low_water
[i
] > hw
->fc
.high_water
[i
])
5240 hw
->fc
.low_water
[i
] = 0;
5243 for (; i
< MAX_TRAFFIC_CLASS
; i
++)
5244 hw
->fc
.high_water
[i
] = 0;
5247 static void ixgbe_configure_pb(struct ixgbe_adapter
*adapter
)
5249 struct ixgbe_hw
*hw
= &adapter
->hw
;
5251 u8 tc
= adapter
->hw_tcs
;
5253 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
5254 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
5255 hdrm
= 32 << adapter
->fdir_pballoc
;
5259 hw
->mac
.ops
.set_rxpba(hw
, tc
, hdrm
, PBA_STRATEGY_EQUAL
);
5260 ixgbe_pbthresh_setup(adapter
);
5263 static void ixgbe_fdir_filter_restore(struct ixgbe_adapter
*adapter
)
5265 struct ixgbe_hw
*hw
= &adapter
->hw
;
5266 struct hlist_node
*node2
;
5267 struct ixgbe_fdir_filter
*filter
;
5270 spin_lock(&adapter
->fdir_perfect_lock
);
5272 if (!hlist_empty(&adapter
->fdir_filter_list
))
5273 ixgbe_fdir_set_input_mask_82599(hw
, &adapter
->fdir_mask
);
5275 hlist_for_each_entry_safe(filter
, node2
,
5276 &adapter
->fdir_filter_list
, fdir_node
) {
5277 if (filter
->action
== IXGBE_FDIR_DROP_QUEUE
) {
5278 queue
= IXGBE_FDIR_DROP_QUEUE
;
5280 u32 ring
= ethtool_get_flow_spec_ring(filter
->action
);
5281 u8 vf
= ethtool_get_flow_spec_ring_vf(filter
->action
);
5283 if (!vf
&& (ring
>= adapter
->num_rx_queues
)) {
5284 e_err(drv
, "FDIR restore failed without VF, ring: %u\n",
5288 ((vf
> adapter
->num_vfs
) ||
5289 ring
>= adapter
->num_rx_queues_per_pool
)) {
5290 e_err(drv
, "FDIR restore failed with VF, vf: %hhu, ring: %u\n",
5295 /* Map the ring onto the absolute queue index */
5297 queue
= adapter
->rx_ring
[ring
]->reg_idx
;
5300 adapter
->num_rx_queues_per_pool
) + ring
;
5303 ixgbe_fdir_write_perfect_filter_82599(hw
,
5304 &filter
->filter
, filter
->sw_idx
, queue
);
5307 spin_unlock(&adapter
->fdir_perfect_lock
);
5311 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
5312 * @rx_ring: ring to free buffers from
5314 static void ixgbe_clean_rx_ring(struct ixgbe_ring
*rx_ring
)
5316 u16 i
= rx_ring
->next_to_clean
;
5317 struct ixgbe_rx_buffer
*rx_buffer
= &rx_ring
->rx_buffer_info
[i
];
5319 if (rx_ring
->xsk_pool
) {
5320 ixgbe_xsk_clean_rx_ring(rx_ring
);
5324 /* Free all the Rx ring sk_buffs */
5325 while (i
!= rx_ring
->next_to_alloc
) {
5326 if (rx_buffer
->skb
) {
5327 struct sk_buff
*skb
= rx_buffer
->skb
;
5328 if (IXGBE_CB(skb
)->page_released
)
5329 dma_unmap_page_attrs(rx_ring
->dev
,
5331 ixgbe_rx_pg_size(rx_ring
),
5337 /* Invalidate cache lines that may have been written to by
5338 * device so that we avoid corrupting memory.
5340 dma_sync_single_range_for_cpu(rx_ring
->dev
,
5342 rx_buffer
->page_offset
,
5343 ixgbe_rx_bufsz(rx_ring
),
5346 /* free resources associated with mapping */
5347 dma_unmap_page_attrs(rx_ring
->dev
, rx_buffer
->dma
,
5348 ixgbe_rx_pg_size(rx_ring
),
5351 __page_frag_cache_drain(rx_buffer
->page
,
5352 rx_buffer
->pagecnt_bias
);
5356 if (i
== rx_ring
->count
) {
5358 rx_buffer
= rx_ring
->rx_buffer_info
;
5363 rx_ring
->next_to_alloc
= 0;
5364 rx_ring
->next_to_clean
= 0;
5365 rx_ring
->next_to_use
= 0;
5368 static int ixgbe_fwd_ring_up(struct ixgbe_adapter
*adapter
,
5369 struct ixgbe_fwd_adapter
*accel
)
5371 u16 rss_i
= adapter
->ring_feature
[RING_F_RSS
].indices
;
5372 int num_tc
= netdev_get_num_tc(adapter
->netdev
);
5373 struct net_device
*vdev
= accel
->netdev
;
5376 baseq
= accel
->pool
* adapter
->num_rx_queues_per_pool
;
5377 netdev_dbg(vdev
, "pool %i:%i queues %i:%i\n",
5378 accel
->pool
, adapter
->num_rx_pools
,
5379 baseq
, baseq
+ adapter
->num_rx_queues_per_pool
);
5381 accel
->rx_base_queue
= baseq
;
5382 accel
->tx_base_queue
= baseq
;
5384 /* record configuration for macvlan interface in vdev */
5385 for (i
= 0; i
< num_tc
; i
++)
5386 netdev_bind_sb_channel_queue(adapter
->netdev
, vdev
,
5387 i
, rss_i
, baseq
+ (rss_i
* i
));
5389 for (i
= 0; i
< adapter
->num_rx_queues_per_pool
; i
++)
5390 adapter
->rx_ring
[baseq
+ i
]->netdev
= vdev
;
5392 /* Guarantee all rings are updated before we update the
5393 * MAC address filter.
5397 /* ixgbe_add_mac_filter will return an index if it succeeds, so we
5398 * need to only treat it as an error value if it is negative.
5400 err
= ixgbe_add_mac_filter(adapter
, vdev
->dev_addr
,
5401 VMDQ_P(accel
->pool
));
5405 /* if we cannot add the MAC rule then disable the offload */
5406 macvlan_release_l2fw_offload(vdev
);
5408 for (i
= 0; i
< adapter
->num_rx_queues_per_pool
; i
++)
5409 adapter
->rx_ring
[baseq
+ i
]->netdev
= NULL
;
5411 netdev_err(vdev
, "L2FW offload disabled due to L2 filter error\n");
5413 /* unbind the queues and drop the subordinate channel config */
5414 netdev_unbind_sb_channel(adapter
->netdev
, vdev
);
5415 netdev_set_sb_channel(vdev
, 0);
5417 clear_bit(accel
->pool
, adapter
->fwd_bitmask
);
5423 static int ixgbe_macvlan_up(struct net_device
*vdev
,
5424 struct netdev_nested_priv
*priv
)
5426 struct ixgbe_adapter
*adapter
= (struct ixgbe_adapter
*)priv
->data
;
5427 struct ixgbe_fwd_adapter
*accel
;
5429 if (!netif_is_macvlan(vdev
))
5432 accel
= macvlan_accel_priv(vdev
);
5436 ixgbe_fwd_ring_up(adapter
, accel
);
5441 static void ixgbe_configure_dfwd(struct ixgbe_adapter
*adapter
)
5443 struct netdev_nested_priv priv
= {
5444 .data
= (void *)adapter
,
5447 netdev_walk_all_upper_dev_rcu(adapter
->netdev
,
5448 ixgbe_macvlan_up
, &priv
);
5451 static void ixgbe_configure(struct ixgbe_adapter
*adapter
)
5453 struct ixgbe_hw
*hw
= &adapter
->hw
;
5455 ixgbe_configure_pb(adapter
);
5456 #ifdef CONFIG_IXGBE_DCB
5457 ixgbe_configure_dcb(adapter
);
5460 * We must restore virtualization before VLANs or else
5461 * the VLVF registers will not be populated
5463 ixgbe_configure_virtualization(adapter
);
5465 ixgbe_set_rx_mode(adapter
->netdev
);
5466 ixgbe_restore_vlan(adapter
);
5467 ixgbe_ipsec_restore(adapter
);
5469 switch (hw
->mac
.type
) {
5470 case ixgbe_mac_82599EB
:
5471 case ixgbe_mac_X540
:
5472 hw
->mac
.ops
.disable_rx_buff(hw
);
5478 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
5479 ixgbe_init_fdir_signature_82599(&adapter
->hw
,
5480 adapter
->fdir_pballoc
);
5481 } else if (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
) {
5482 ixgbe_init_fdir_perfect_82599(&adapter
->hw
,
5483 adapter
->fdir_pballoc
);
5484 ixgbe_fdir_filter_restore(adapter
);
5487 switch (hw
->mac
.type
) {
5488 case ixgbe_mac_82599EB
:
5489 case ixgbe_mac_X540
:
5490 hw
->mac
.ops
.enable_rx_buff(hw
);
5496 #ifdef CONFIG_IXGBE_DCA
5498 if (adapter
->flags
& IXGBE_FLAG_DCA_CAPABLE
)
5499 ixgbe_setup_dca(adapter
);
5500 #endif /* CONFIG_IXGBE_DCA */
5503 /* configure FCoE L2 filters, redirection table, and Rx control */
5504 ixgbe_configure_fcoe(adapter
);
5506 #endif /* IXGBE_FCOE */
5507 ixgbe_configure_tx(adapter
);
5508 ixgbe_configure_rx(adapter
);
5509 ixgbe_configure_dfwd(adapter
);
5513 * ixgbe_sfp_link_config - set up SFP+ link
5514 * @adapter: pointer to private adapter struct
5516 static void ixgbe_sfp_link_config(struct ixgbe_adapter
*adapter
)
5519 * We are assuming the worst case scenario here, and that
5520 * is that an SFP was inserted/removed after the reset
5521 * but before SFP detection was enabled. As such the best
5522 * solution is to just start searching as soon as we start
5524 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
5525 adapter
->flags2
|= IXGBE_FLAG2_SEARCH_FOR_SFP
;
5527 adapter
->flags2
|= IXGBE_FLAG2_SFP_NEEDS_RESET
;
5528 adapter
->sfp_poll_time
= 0;
5532 * ixgbe_non_sfp_link_config - set up non-SFP+ link
5533 * @hw: pointer to private hardware struct
5535 * Returns 0 on success, negative on failure
5537 static int ixgbe_non_sfp_link_config(struct ixgbe_hw
*hw
)
5540 bool autoneg
, link_up
= false;
5543 if (hw
->mac
.ops
.check_link
)
5544 ret
= hw
->mac
.ops
.check_link(hw
, &speed
, &link_up
, false);
5549 speed
= hw
->phy
.autoneg_advertised
;
5550 if (!speed
&& hw
->mac
.ops
.get_link_capabilities
) {
5551 ret
= hw
->mac
.ops
.get_link_capabilities(hw
, &speed
,
5553 /* remove NBASE-T speeds from default autonegotiation
5554 * to accommodate broken network switches in the field
5555 * which cannot cope with advertised NBASE-T speeds
5557 speed
&= ~(IXGBE_LINK_SPEED_5GB_FULL
|
5558 IXGBE_LINK_SPEED_2_5GB_FULL
);
5564 if (hw
->mac
.ops
.setup_link
)
5565 ret
= hw
->mac
.ops
.setup_link(hw
, speed
, link_up
);
5571 * ixgbe_clear_vf_stats_counters - Clear out VF stats after reset
5572 * @adapter: board private structure
5574 * On a reset we need to clear out the VF stats or accounting gets
5575 * messed up because they're not clear on read.
5577 static void ixgbe_clear_vf_stats_counters(struct ixgbe_adapter
*adapter
)
5579 struct ixgbe_hw
*hw
= &adapter
->hw
;
5582 for (i
= 0; i
< adapter
->num_vfs
; i
++) {
5583 adapter
->vfinfo
[i
].last_vfstats
.gprc
=
5584 IXGBE_READ_REG(hw
, IXGBE_PVFGPRC(i
));
5585 adapter
->vfinfo
[i
].saved_rst_vfstats
.gprc
+=
5586 adapter
->vfinfo
[i
].vfstats
.gprc
;
5587 adapter
->vfinfo
[i
].vfstats
.gprc
= 0;
5588 adapter
->vfinfo
[i
].last_vfstats
.gptc
=
5589 IXGBE_READ_REG(hw
, IXGBE_PVFGPTC(i
));
5590 adapter
->vfinfo
[i
].saved_rst_vfstats
.gptc
+=
5591 adapter
->vfinfo
[i
].vfstats
.gptc
;
5592 adapter
->vfinfo
[i
].vfstats
.gptc
= 0;
5593 adapter
->vfinfo
[i
].last_vfstats
.gorc
=
5594 IXGBE_READ_REG(hw
, IXGBE_PVFGORC_LSB(i
));
5595 adapter
->vfinfo
[i
].saved_rst_vfstats
.gorc
+=
5596 adapter
->vfinfo
[i
].vfstats
.gorc
;
5597 adapter
->vfinfo
[i
].vfstats
.gorc
= 0;
5598 adapter
->vfinfo
[i
].last_vfstats
.gotc
=
5599 IXGBE_READ_REG(hw
, IXGBE_PVFGOTC_LSB(i
));
5600 adapter
->vfinfo
[i
].saved_rst_vfstats
.gotc
+=
5601 adapter
->vfinfo
[i
].vfstats
.gotc
;
5602 adapter
->vfinfo
[i
].vfstats
.gotc
= 0;
5603 adapter
->vfinfo
[i
].last_vfstats
.mprc
=
5604 IXGBE_READ_REG(hw
, IXGBE_PVFMPRC(i
));
5605 adapter
->vfinfo
[i
].saved_rst_vfstats
.mprc
+=
5606 adapter
->vfinfo
[i
].vfstats
.mprc
;
5607 adapter
->vfinfo
[i
].vfstats
.mprc
= 0;
5611 static void ixgbe_setup_gpie(struct ixgbe_adapter
*adapter
)
5613 struct ixgbe_hw
*hw
= &adapter
->hw
;
5616 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
5617 gpie
= IXGBE_GPIE_MSIX_MODE
| IXGBE_GPIE_PBA_SUPPORT
|
5619 gpie
|= IXGBE_GPIE_EIAME
;
5621 * use EIAM to auto-mask when MSI-X interrupt is asserted
5622 * this saves a register write for every interrupt
5624 switch (hw
->mac
.type
) {
5625 case ixgbe_mac_82598EB
:
5626 IXGBE_WRITE_REG(hw
, IXGBE_EIAM
, IXGBE_EICS_RTX_QUEUE
);
5628 case ixgbe_mac_82599EB
:
5629 case ixgbe_mac_X540
:
5630 case ixgbe_mac_X550
:
5631 case ixgbe_mac_X550EM_x
:
5632 case ixgbe_mac_x550em_a
:
5634 IXGBE_WRITE_REG(hw
, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5635 IXGBE_WRITE_REG(hw
, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5639 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
5640 * specifically only auto mask tx and rx interrupts */
5641 IXGBE_WRITE_REG(hw
, IXGBE_EIAM
, IXGBE_EICS_RTX_QUEUE
);
5644 /* XXX: to interrupt immediately for EICS writes, enable this */
5645 /* gpie |= IXGBE_GPIE_EIMEN; */
5647 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
5648 gpie
&= ~IXGBE_GPIE_VTMODE_MASK
;
5650 switch (adapter
->ring_feature
[RING_F_VMDQ
].mask
) {
5651 case IXGBE_82599_VMDQ_8Q_MASK
:
5652 gpie
|= IXGBE_GPIE_VTMODE_16
;
5654 case IXGBE_82599_VMDQ_4Q_MASK
:
5655 gpie
|= IXGBE_GPIE_VTMODE_32
;
5658 gpie
|= IXGBE_GPIE_VTMODE_64
;
5663 /* Enable Thermal over heat sensor interrupt */
5664 if (adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
) {
5665 switch (adapter
->hw
.mac
.type
) {
5666 case ixgbe_mac_82599EB
:
5667 gpie
|= IXGBE_SDP0_GPIEN_8259X
;
5674 /* Enable fan failure interrupt */
5675 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
)
5676 gpie
|= IXGBE_SDP1_GPIEN(hw
);
5678 switch (hw
->mac
.type
) {
5679 case ixgbe_mac_82599EB
:
5680 gpie
|= IXGBE_SDP1_GPIEN_8259X
| IXGBE_SDP2_GPIEN_8259X
;
5682 case ixgbe_mac_X550EM_x
:
5683 case ixgbe_mac_x550em_a
:
5684 gpie
|= IXGBE_SDP0_GPIEN_X540
;
5690 IXGBE_WRITE_REG(hw
, IXGBE_GPIE
, gpie
);
5693 static void ixgbe_up_complete(struct ixgbe_adapter
*adapter
)
5695 struct ixgbe_hw
*hw
= &adapter
->hw
;
5699 ixgbe_get_hw_control(adapter
);
5700 ixgbe_setup_gpie(adapter
);
5702 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
5703 ixgbe_configure_msix(adapter
);
5705 ixgbe_configure_msi_and_legacy(adapter
);
5707 /* enable the optics for 82599 SFP+ fiber */
5708 if (hw
->mac
.ops
.enable_tx_laser
)
5709 hw
->mac
.ops
.enable_tx_laser(hw
);
5711 if (hw
->phy
.ops
.set_phy_power
)
5712 hw
->phy
.ops
.set_phy_power(hw
, true);
5714 smp_mb__before_atomic();
5715 clear_bit(__IXGBE_DOWN
, &adapter
->state
);
5716 ixgbe_napi_enable_all(adapter
);
5718 if (ixgbe_is_sfp(hw
)) {
5719 ixgbe_sfp_link_config(adapter
);
5721 err
= ixgbe_non_sfp_link_config(hw
);
5723 e_err(probe
, "link_config FAILED %d\n", err
);
5726 /* clear any pending interrupts, may auto mask */
5727 IXGBE_READ_REG(hw
, IXGBE_EICR
);
5728 ixgbe_irq_enable(adapter
, true, true);
5731 * If this adapter has a fan, check to see if we had a failure
5732 * before we enabled the interrupt.
5734 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
5735 u32 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
5736 if (esdp
& IXGBE_ESDP_SDP1
)
5737 e_crit(drv
, "Fan has stopped, replace the adapter\n");
5740 /* bring the link up in the watchdog, this could race with our first
5741 * link up interrupt but shouldn't be a problem */
5742 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
5743 adapter
->link_check_timeout
= jiffies
;
5744 mod_timer(&adapter
->service_timer
, jiffies
);
5746 ixgbe_clear_vf_stats_counters(adapter
);
5747 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
5748 ctrl_ext
= IXGBE_READ_REG(hw
, IXGBE_CTRL_EXT
);
5749 ctrl_ext
|= IXGBE_CTRL_EXT_PFRSTD
;
5750 IXGBE_WRITE_REG(hw
, IXGBE_CTRL_EXT
, ctrl_ext
);
5752 /* update setting rx tx for all active vfs */
5753 ixgbe_set_all_vfs(adapter
);
5756 void ixgbe_reinit_locked(struct ixgbe_adapter
*adapter
)
5758 /* put off any impending NetWatchDogTimeout */
5759 netif_trans_update(adapter
->netdev
);
5761 while (test_and_set_bit(__IXGBE_RESETTING
, &adapter
->state
))
5762 usleep_range(1000, 2000);
5763 if (adapter
->hw
.phy
.type
== ixgbe_phy_fw
)
5764 ixgbe_watchdog_link_is_down(adapter
);
5765 ixgbe_down(adapter
);
5767 * If SR-IOV enabled then wait a bit before bringing the adapter
5768 * back up to give the VFs time to respond to the reset. The
5769 * two second wait is based upon the watchdog timer cycle in
5772 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
5775 clear_bit(__IXGBE_RESETTING
, &adapter
->state
);
5778 void ixgbe_up(struct ixgbe_adapter
*adapter
)
5780 /* hardware has been reset, we need to reload some things */
5781 ixgbe_configure(adapter
);
5783 ixgbe_up_complete(adapter
);
5786 static unsigned long ixgbe_get_completion_timeout(struct ixgbe_adapter
*adapter
)
5790 pcie_capability_read_word(adapter
->pdev
, PCI_EXP_DEVCTL2
, &devctl2
);
5792 switch (devctl2
& IXGBE_PCIDEVCTRL2_TIMEO_MASK
) {
5793 case IXGBE_PCIDEVCTRL2_17_34s
:
5794 case IXGBE_PCIDEVCTRL2_4_8s
:
5795 /* For now we cap the upper limit on delay to 2 seconds
5796 * as we end up going up to 34 seconds of delay in worst
5797 * case timeout value.
5799 case IXGBE_PCIDEVCTRL2_1_2s
:
5800 return 2000000ul; /* 2.0 s */
5801 case IXGBE_PCIDEVCTRL2_260_520ms
:
5802 return 520000ul; /* 520 ms */
5803 case IXGBE_PCIDEVCTRL2_65_130ms
:
5804 return 130000ul; /* 130 ms */
5805 case IXGBE_PCIDEVCTRL2_16_32ms
:
5806 return 32000ul; /* 32 ms */
5807 case IXGBE_PCIDEVCTRL2_1_2ms
:
5808 return 2000ul; /* 2 ms */
5809 case IXGBE_PCIDEVCTRL2_50_100us
:
5810 return 100ul; /* 100 us */
5811 case IXGBE_PCIDEVCTRL2_16_32ms_def
:
5812 return 32000ul; /* 32 ms */
5817 /* We shouldn't need to hit this path, but just in case default as
5818 * though completion timeout is not supported and support 32ms.
5823 void ixgbe_disable_rx(struct ixgbe_adapter
*adapter
)
5825 unsigned long wait_delay
, delay_interval
;
5826 struct ixgbe_hw
*hw
= &adapter
->hw
;
5830 /* disable receives */
5831 hw
->mac
.ops
.disable_rx(hw
);
5833 if (ixgbe_removed(hw
->hw_addr
))
5836 /* disable all enabled Rx queues */
5837 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
5838 struct ixgbe_ring
*ring
= adapter
->rx_ring
[i
];
5839 u8 reg_idx
= ring
->reg_idx
;
5841 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
5842 rxdctl
&= ~IXGBE_RXDCTL_ENABLE
;
5843 rxdctl
|= IXGBE_RXDCTL_SWFLSH
;
5845 /* write value back with RXDCTL.ENABLE bit cleared */
5846 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(reg_idx
), rxdctl
);
5849 /* RXDCTL.EN may not change on 82598 if link is down, so skip it */
5850 if (hw
->mac
.type
== ixgbe_mac_82598EB
&&
5851 !(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
5854 /* Determine our minimum delay interval. We will increase this value
5855 * with each subsequent test. This way if the device returns quickly
5856 * we should spend as little time as possible waiting, however as
5857 * the time increases we will wait for larger periods of time.
5859 * The trick here is that we increase the interval using the
5860 * following pattern: 1x 3x 5x 7x 9x 11x 13x 15x 17x 19x. The result
5861 * of that wait is that it totals up to 100x whatever interval we
5862 * choose. Since our minimum wait is 100us we can just divide the
5863 * total timeout by 100 to get our minimum delay interval.
5865 delay_interval
= ixgbe_get_completion_timeout(adapter
) / 100;
5867 wait_loop
= IXGBE_MAX_RX_DESC_POLL
;
5868 wait_delay
= delay_interval
;
5870 while (wait_loop
--) {
5871 usleep_range(wait_delay
, wait_delay
+ 10);
5872 wait_delay
+= delay_interval
* 2;
5875 /* OR together the reading of all the active RXDCTL registers,
5876 * and then test the result. We need the disable to complete
5877 * before we start freeing the memory and invalidating the
5880 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
5881 struct ixgbe_ring
*ring
= adapter
->rx_ring
[i
];
5882 u8 reg_idx
= ring
->reg_idx
;
5884 rxdctl
|= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
5887 if (!(rxdctl
& IXGBE_RXDCTL_ENABLE
))
5892 "RXDCTL.ENABLE for one or more queues not cleared within the polling period\n");
5895 void ixgbe_disable_tx(struct ixgbe_adapter
*adapter
)
5897 unsigned long wait_delay
, delay_interval
;
5898 struct ixgbe_hw
*hw
= &adapter
->hw
;
5902 if (ixgbe_removed(hw
->hw_addr
))
5905 /* disable all enabled Tx queues */
5906 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
5907 struct ixgbe_ring
*ring
= adapter
->tx_ring
[i
];
5908 u8 reg_idx
= ring
->reg_idx
;
5910 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
), IXGBE_TXDCTL_SWFLSH
);
5913 /* disable all enabled XDP Tx queues */
5914 for (i
= 0; i
< adapter
->num_xdp_queues
; i
++) {
5915 struct ixgbe_ring
*ring
= adapter
->xdp_ring
[i
];
5916 u8 reg_idx
= ring
->reg_idx
;
5918 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
), IXGBE_TXDCTL_SWFLSH
);
5921 /* If the link is not up there shouldn't be much in the way of
5922 * pending transactions. Those that are left will be flushed out
5923 * when the reset logic goes through the flush sequence to clean out
5924 * the pending Tx transactions.
5926 if (!(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
5927 goto dma_engine_disable
;
5929 /* Determine our minimum delay interval. We will increase this value
5930 * with each subsequent test. This way if the device returns quickly
5931 * we should spend as little time as possible waiting, however as
5932 * the time increases we will wait for larger periods of time.
5934 * The trick here is that we increase the interval using the
5935 * following pattern: 1x 3x 5x 7x 9x 11x 13x 15x 17x 19x. The result
5936 * of that wait is that it totals up to 100x whatever interval we
5937 * choose. Since our minimum wait is 100us we can just divide the
5938 * total timeout by 100 to get our minimum delay interval.
5940 delay_interval
= ixgbe_get_completion_timeout(adapter
) / 100;
5942 wait_loop
= IXGBE_MAX_RX_DESC_POLL
;
5943 wait_delay
= delay_interval
;
5945 while (wait_loop
--) {
5946 usleep_range(wait_delay
, wait_delay
+ 10);
5947 wait_delay
+= delay_interval
* 2;
5950 /* OR together the reading of all the active TXDCTL registers,
5951 * and then test the result. We need the disable to complete
5952 * before we start freeing the memory and invalidating the
5955 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
5956 struct ixgbe_ring
*ring
= adapter
->tx_ring
[i
];
5957 u8 reg_idx
= ring
->reg_idx
;
5959 txdctl
|= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(reg_idx
));
5961 for (i
= 0; i
< adapter
->num_xdp_queues
; i
++) {
5962 struct ixgbe_ring
*ring
= adapter
->xdp_ring
[i
];
5963 u8 reg_idx
= ring
->reg_idx
;
5965 txdctl
|= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(reg_idx
));
5968 if (!(txdctl
& IXGBE_TXDCTL_ENABLE
))
5969 goto dma_engine_disable
;
5973 "TXDCTL.ENABLE for one or more queues not cleared within the polling period\n");
5976 /* Disable the Tx DMA engine on 82599 and later MAC */
5977 switch (hw
->mac
.type
) {
5978 case ixgbe_mac_82599EB
:
5979 case ixgbe_mac_X540
:
5980 case ixgbe_mac_X550
:
5981 case ixgbe_mac_X550EM_x
:
5982 case ixgbe_mac_x550em_a
:
5983 IXGBE_WRITE_REG(hw
, IXGBE_DMATXCTL
,
5984 (IXGBE_READ_REG(hw
, IXGBE_DMATXCTL
) &
5985 ~IXGBE_DMATXCTL_TE
));
5992 void ixgbe_reset(struct ixgbe_adapter
*adapter
)
5994 struct ixgbe_hw
*hw
= &adapter
->hw
;
5995 struct net_device
*netdev
= adapter
->netdev
;
5998 if (ixgbe_removed(hw
->hw_addr
))
6000 /* lock SFP init bit to prevent race conditions with the watchdog */
6001 while (test_and_set_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
))
6002 usleep_range(1000, 2000);
6004 /* clear all SFP and link config related flags while holding SFP_INIT */
6005 adapter
->flags2
&= ~(IXGBE_FLAG2_SEARCH_FOR_SFP
|
6006 IXGBE_FLAG2_SFP_NEEDS_RESET
);
6007 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_CONFIG
;
6009 err
= hw
->mac
.ops
.init_hw(hw
);
6016 e_dev_err("primary disable timed out\n");
6019 /* We are running on a pre-production device, log a warning */
6020 e_dev_warn("This device is a pre-production adapter/LOM. "
6021 "Please be aware there may be issues associated with "
6022 "your hardware. If you are experiencing problems "
6023 "please contact your Intel or hardware "
6024 "representative who provided you with this "
6028 e_dev_err("Hardware Error: %d\n", err
);
6031 clear_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
);
6033 /* flush entries out of MAC table */
6034 ixgbe_flush_sw_mac_table(adapter
);
6035 __dev_uc_unsync(netdev
, NULL
);
6037 /* do not flush user set addresses */
6038 ixgbe_mac_set_default_filter(adapter
);
6040 /* update SAN MAC vmdq pool selection */
6041 if (hw
->mac
.san_mac_rar_index
)
6042 hw
->mac
.ops
.set_vmdq_san_mac(hw
, VMDQ_P(0));
6044 if (test_bit(__IXGBE_PTP_RUNNING
, &adapter
->state
))
6045 ixgbe_ptp_reset(adapter
);
6047 if (hw
->phy
.ops
.set_phy_power
) {
6048 if (!netif_running(adapter
->netdev
) && !adapter
->wol
)
6049 hw
->phy
.ops
.set_phy_power(hw
, false);
6051 hw
->phy
.ops
.set_phy_power(hw
, true);
6056 * ixgbe_clean_tx_ring - Free Tx Buffers
6057 * @tx_ring: ring to be cleaned
6059 static void ixgbe_clean_tx_ring(struct ixgbe_ring
*tx_ring
)
6061 u16 i
= tx_ring
->next_to_clean
;
6062 struct ixgbe_tx_buffer
*tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
6064 if (tx_ring
->xsk_pool
) {
6065 ixgbe_xsk_clean_tx_ring(tx_ring
);
6069 while (i
!= tx_ring
->next_to_use
) {
6070 union ixgbe_adv_tx_desc
*eop_desc
, *tx_desc
;
6072 /* Free all the Tx ring sk_buffs */
6073 if (ring_is_xdp(tx_ring
))
6074 xdp_return_frame(tx_buffer
->xdpf
);
6076 dev_kfree_skb_any(tx_buffer
->skb
);
6078 /* unmap skb header data */
6079 dma_unmap_single(tx_ring
->dev
,
6080 dma_unmap_addr(tx_buffer
, dma
),
6081 dma_unmap_len(tx_buffer
, len
),
6084 /* check for eop_desc to determine the end of the packet */
6085 eop_desc
= tx_buffer
->next_to_watch
;
6086 tx_desc
= IXGBE_TX_DESC(tx_ring
, i
);
6088 /* unmap remaining buffers */
6089 while (tx_desc
!= eop_desc
) {
6093 if (unlikely(i
== tx_ring
->count
)) {
6095 tx_buffer
= tx_ring
->tx_buffer_info
;
6096 tx_desc
= IXGBE_TX_DESC(tx_ring
, 0);
6099 /* unmap any remaining paged data */
6100 if (dma_unmap_len(tx_buffer
, len
))
6101 dma_unmap_page(tx_ring
->dev
,
6102 dma_unmap_addr(tx_buffer
, dma
),
6103 dma_unmap_len(tx_buffer
, len
),
6107 /* move us one more past the eop_desc for start of next pkt */
6110 if (unlikely(i
== tx_ring
->count
)) {
6112 tx_buffer
= tx_ring
->tx_buffer_info
;
6116 /* reset BQL for queue */
6117 if (!ring_is_xdp(tx_ring
))
6118 netdev_tx_reset_queue(txring_txq(tx_ring
));
6121 /* reset next_to_use and next_to_clean */
6122 tx_ring
->next_to_use
= 0;
6123 tx_ring
->next_to_clean
= 0;
6127 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
6128 * @adapter: board private structure
6130 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter
*adapter
)
6134 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
6135 ixgbe_clean_rx_ring(adapter
->rx_ring
[i
]);
6139 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
6140 * @adapter: board private structure
6142 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter
*adapter
)
6146 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
6147 ixgbe_clean_tx_ring(adapter
->tx_ring
[i
]);
6148 for (i
= 0; i
< adapter
->num_xdp_queues
; i
++)
6149 ixgbe_clean_tx_ring(adapter
->xdp_ring
[i
]);
6152 static void ixgbe_fdir_filter_exit(struct ixgbe_adapter
*adapter
)
6154 struct hlist_node
*node2
;
6155 struct ixgbe_fdir_filter
*filter
;
6157 spin_lock(&adapter
->fdir_perfect_lock
);
6159 hlist_for_each_entry_safe(filter
, node2
,
6160 &adapter
->fdir_filter_list
, fdir_node
) {
6161 hlist_del(&filter
->fdir_node
);
6164 adapter
->fdir_filter_count
= 0;
6166 spin_unlock(&adapter
->fdir_perfect_lock
);
6169 void ixgbe_down(struct ixgbe_adapter
*adapter
)
6171 struct net_device
*netdev
= adapter
->netdev
;
6172 struct ixgbe_hw
*hw
= &adapter
->hw
;
6175 /* signal that we are down to the interrupt handler */
6176 if (test_and_set_bit(__IXGBE_DOWN
, &adapter
->state
))
6177 return; /* do nothing if already down */
6179 /* Shut off incoming Tx traffic */
6180 netif_tx_stop_all_queues(netdev
);
6182 /* call carrier off first to avoid false dev_watchdog timeouts */
6183 netif_carrier_off(netdev
);
6184 netif_tx_disable(netdev
);
6187 ixgbe_disable_rx(adapter
);
6189 /* synchronize_rcu() needed for pending XDP buffers to drain */
6190 if (adapter
->xdp_ring
[0])
6193 ixgbe_irq_disable(adapter
);
6195 ixgbe_napi_disable_all(adapter
);
6197 clear_bit(__IXGBE_RESET_REQUESTED
, &adapter
->state
);
6198 adapter
->flags2
&= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT
;
6199 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_UPDATE
;
6201 del_timer_sync(&adapter
->service_timer
);
6203 if (adapter
->num_vfs
) {
6204 /* Clear EITR Select mapping */
6205 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITRSEL
, 0);
6207 /* Mark all the VFs as inactive */
6208 for (i
= 0 ; i
< adapter
->num_vfs
; i
++)
6209 adapter
->vfinfo
[i
].clear_to_send
= false;
6211 /* update setting rx tx for all active vfs */
6212 ixgbe_set_all_vfs(adapter
);
6215 /* disable transmits in the hardware now that interrupts are off */
6216 ixgbe_disable_tx(adapter
);
6218 if (!pci_channel_offline(adapter
->pdev
))
6219 ixgbe_reset(adapter
);
6221 /* power down the optics for 82599 SFP+ fiber */
6222 if (hw
->mac
.ops
.disable_tx_laser
)
6223 hw
->mac
.ops
.disable_tx_laser(hw
);
6225 ixgbe_clean_all_tx_rings(adapter
);
6226 ixgbe_clean_all_rx_rings(adapter
);
6230 * ixgbe_set_eee_capable - helper function to determine EEE support on X550
6231 * @adapter: board private structure
6233 static void ixgbe_set_eee_capable(struct ixgbe_adapter
*adapter
)
6235 struct ixgbe_hw
*hw
= &adapter
->hw
;
6237 switch (hw
->device_id
) {
6238 case IXGBE_DEV_ID_X550EM_A_1G_T
:
6239 case IXGBE_DEV_ID_X550EM_A_1G_T_L
:
6240 if (!hw
->phy
.eee_speeds_supported
)
6242 adapter
->flags2
|= IXGBE_FLAG2_EEE_CAPABLE
;
6243 if (!hw
->phy
.eee_speeds_advertised
)
6245 adapter
->flags2
|= IXGBE_FLAG2_EEE_ENABLED
;
6248 adapter
->flags2
&= ~IXGBE_FLAG2_EEE_CAPABLE
;
6249 adapter
->flags2
&= ~IXGBE_FLAG2_EEE_ENABLED
;
6255 * ixgbe_tx_timeout - Respond to a Tx Hang
6256 * @netdev: network interface device structure
6257 * @txqueue: queue number that timed out
6259 static void ixgbe_tx_timeout(struct net_device
*netdev
, unsigned int __always_unused txqueue
)
6261 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6263 /* Do the reset outside of interrupt context */
6264 ixgbe_tx_timeout_reset(adapter
);
6267 #ifdef CONFIG_IXGBE_DCB
6268 static void ixgbe_init_dcb(struct ixgbe_adapter
*adapter
)
6270 struct ixgbe_hw
*hw
= &adapter
->hw
;
6271 struct tc_configuration
*tc
;
6274 switch (hw
->mac
.type
) {
6275 case ixgbe_mac_82598EB
:
6276 case ixgbe_mac_82599EB
:
6277 adapter
->dcb_cfg
.num_tcs
.pg_tcs
= MAX_TRAFFIC_CLASS
;
6278 adapter
->dcb_cfg
.num_tcs
.pfc_tcs
= MAX_TRAFFIC_CLASS
;
6280 case ixgbe_mac_X540
:
6281 case ixgbe_mac_X550
:
6282 adapter
->dcb_cfg
.num_tcs
.pg_tcs
= X540_TRAFFIC_CLASS
;
6283 adapter
->dcb_cfg
.num_tcs
.pfc_tcs
= X540_TRAFFIC_CLASS
;
6285 case ixgbe_mac_X550EM_x
:
6286 case ixgbe_mac_x550em_a
:
6288 adapter
->dcb_cfg
.num_tcs
.pg_tcs
= DEF_TRAFFIC_CLASS
;
6289 adapter
->dcb_cfg
.num_tcs
.pfc_tcs
= DEF_TRAFFIC_CLASS
;
6293 /* Configure DCB traffic classes */
6294 for (j
= 0; j
< MAX_TRAFFIC_CLASS
; j
++) {
6295 tc
= &adapter
->dcb_cfg
.tc_config
[j
];
6296 tc
->path
[DCB_TX_CONFIG
].bwg_id
= 0;
6297 tc
->path
[DCB_TX_CONFIG
].bwg_percent
= 12 + (j
& 1);
6298 tc
->path
[DCB_RX_CONFIG
].bwg_id
= 0;
6299 tc
->path
[DCB_RX_CONFIG
].bwg_percent
= 12 + (j
& 1);
6300 tc
->dcb_pfc
= pfc_disabled
;
6303 /* Initialize default user to priority mapping, UPx->TC0 */
6304 tc
= &adapter
->dcb_cfg
.tc_config
[0];
6305 tc
->path
[DCB_TX_CONFIG
].up_to_tc_bitmap
= 0xFF;
6306 tc
->path
[DCB_RX_CONFIG
].up_to_tc_bitmap
= 0xFF;
6308 adapter
->dcb_cfg
.bw_percentage
[DCB_TX_CONFIG
][0] = 100;
6309 adapter
->dcb_cfg
.bw_percentage
[DCB_RX_CONFIG
][0] = 100;
6310 adapter
->dcb_cfg
.pfc_mode_enable
= false;
6311 adapter
->dcb_set_bitmap
= 0x00;
6312 if (adapter
->flags
& IXGBE_FLAG_DCB_CAPABLE
)
6313 adapter
->dcbx_cap
= DCB_CAP_DCBX_HOST
| DCB_CAP_DCBX_VER_CEE
;
6314 memcpy(&adapter
->temp_dcb_cfg
, &adapter
->dcb_cfg
,
6315 sizeof(adapter
->temp_dcb_cfg
));
6320 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
6321 * @adapter: board private structure to initialize
6322 * @ii: pointer to ixgbe_info for device
6324 * ixgbe_sw_init initializes the Adapter private data structure.
6325 * Fields are initialized based on PCI device information and
6326 * OS network device settings (MTU size).
6328 static int ixgbe_sw_init(struct ixgbe_adapter
*adapter
,
6329 const struct ixgbe_info
*ii
)
6331 struct ixgbe_hw
*hw
= &adapter
->hw
;
6332 struct pci_dev
*pdev
= adapter
->pdev
;
6333 unsigned int rss
, fdir
;
6337 /* PCI config space info */
6339 hw
->vendor_id
= pdev
->vendor
;
6340 hw
->device_id
= pdev
->device
;
6341 hw
->revision_id
= pdev
->revision
;
6342 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
6343 hw
->subsystem_device_id
= pdev
->subsystem_device
;
6345 /* get_invariants needs the device IDs */
6346 ii
->get_invariants(hw
);
6348 /* Set common capability flags and settings */
6349 rss
= min_t(int, ixgbe_max_rss_indices(adapter
), num_online_cpus());
6350 adapter
->ring_feature
[RING_F_RSS
].limit
= rss
;
6351 adapter
->flags2
|= IXGBE_FLAG2_RSC_CAPABLE
;
6352 adapter
->max_q_vectors
= MAX_Q_VECTORS_82599
;
6353 adapter
->atr_sample_rate
= 20;
6354 fdir
= min_t(int, IXGBE_MAX_FDIR_INDICES
, num_online_cpus());
6355 adapter
->ring_feature
[RING_F_FDIR
].limit
= fdir
;
6356 adapter
->fdir_pballoc
= IXGBE_FDIR_PBALLOC_64K
;
6357 adapter
->ring_feature
[RING_F_VMDQ
].limit
= 1;
6358 #ifdef CONFIG_IXGBE_DCA
6359 adapter
->flags
|= IXGBE_FLAG_DCA_CAPABLE
;
6361 #ifdef CONFIG_IXGBE_DCB
6362 adapter
->flags
|= IXGBE_FLAG_DCB_CAPABLE
;
6363 adapter
->flags
&= ~IXGBE_FLAG_DCB_ENABLED
;
6366 adapter
->flags
|= IXGBE_FLAG_FCOE_CAPABLE
;
6367 adapter
->flags
&= ~IXGBE_FLAG_FCOE_ENABLED
;
6368 #ifdef CONFIG_IXGBE_DCB
6369 /* Default traffic class to use for FCoE */
6370 adapter
->fcoe
.up
= IXGBE_FCOE_DEFTC
;
6371 #endif /* CONFIG_IXGBE_DCB */
6372 #endif /* IXGBE_FCOE */
6374 /* initialize static ixgbe jump table entries */
6375 adapter
->jump_tables
[0] = kzalloc(sizeof(*adapter
->jump_tables
[0]),
6377 if (!adapter
->jump_tables
[0])
6379 adapter
->jump_tables
[0]->mat
= ixgbe_ipv4_fields
;
6381 for (i
= 1; i
< IXGBE_MAX_LINK_HANDLE
; i
++)
6382 adapter
->jump_tables
[i
] = NULL
;
6384 adapter
->mac_table
= kcalloc(hw
->mac
.num_rar_entries
,
6385 sizeof(struct ixgbe_mac_addr
),
6387 if (!adapter
->mac_table
)
6390 if (ixgbe_init_rss_key(adapter
))
6393 adapter
->af_xdp_zc_qps
= bitmap_zalloc(IXGBE_MAX_XDP_QS
, GFP_KERNEL
);
6394 if (!adapter
->af_xdp_zc_qps
)
6397 /* Set MAC specific capability flags and exceptions */
6398 switch (hw
->mac
.type
) {
6399 case ixgbe_mac_82598EB
:
6400 adapter
->flags2
&= ~IXGBE_FLAG2_RSC_CAPABLE
;
6402 if (hw
->device_id
== IXGBE_DEV_ID_82598AT
)
6403 adapter
->flags
|= IXGBE_FLAG_FAN_FAIL_CAPABLE
;
6405 adapter
->max_q_vectors
= MAX_Q_VECTORS_82598
;
6406 adapter
->ring_feature
[RING_F_FDIR
].limit
= 0;
6407 adapter
->atr_sample_rate
= 0;
6408 adapter
->fdir_pballoc
= 0;
6410 adapter
->flags
&= ~IXGBE_FLAG_FCOE_CAPABLE
;
6411 adapter
->flags
&= ~IXGBE_FLAG_FCOE_ENABLED
;
6412 #ifdef CONFIG_IXGBE_DCB
6413 adapter
->fcoe
.up
= 0;
6414 #endif /* IXGBE_DCB */
6415 #endif /* IXGBE_FCOE */
6417 case ixgbe_mac_82599EB
:
6418 if (hw
->device_id
== IXGBE_DEV_ID_82599_T3_LOM
)
6419 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
;
6421 case ixgbe_mac_X540
:
6422 fwsm
= IXGBE_READ_REG(hw
, IXGBE_FWSM(hw
));
6423 if (fwsm
& IXGBE_FWSM_TS_ENABLED
)
6424 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
;
6426 case ixgbe_mac_x550em_a
:
6427 switch (hw
->device_id
) {
6428 case IXGBE_DEV_ID_X550EM_A_1G_T
:
6429 case IXGBE_DEV_ID_X550EM_A_1G_T_L
:
6430 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
;
6436 case ixgbe_mac_X550EM_x
:
6437 #ifdef CONFIG_IXGBE_DCB
6438 adapter
->flags
&= ~IXGBE_FLAG_DCB_CAPABLE
;
6441 adapter
->flags
&= ~IXGBE_FLAG_FCOE_CAPABLE
;
6442 #ifdef CONFIG_IXGBE_DCB
6443 adapter
->fcoe
.up
= 0;
6444 #endif /* IXGBE_DCB */
6445 #endif /* IXGBE_FCOE */
6447 case ixgbe_mac_X550
:
6448 if (hw
->mac
.type
== ixgbe_mac_X550
)
6449 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
;
6450 #ifdef CONFIG_IXGBE_DCA
6451 adapter
->flags
&= ~IXGBE_FLAG_DCA_CAPABLE
;
6459 /* FCoE support exists, always init the FCoE lock */
6460 spin_lock_init(&adapter
->fcoe
.lock
);
6463 /* n-tuple support exists, always init our spinlock */
6464 spin_lock_init(&adapter
->fdir_perfect_lock
);
6466 /* init spinlock to avoid concurrency of VF resources */
6467 spin_lock_init(&adapter
->vfs_lock
);
6469 #ifdef CONFIG_IXGBE_DCB
6470 ixgbe_init_dcb(adapter
);
6472 ixgbe_init_ipsec_offload(adapter
);
6474 /* default flow control settings */
6475 hw
->fc
.requested_mode
= ixgbe_fc_full
;
6476 hw
->fc
.current_mode
= ixgbe_fc_full
; /* init for ethtool output */
6477 ixgbe_pbthresh_setup(adapter
);
6478 hw
->fc
.pause_time
= IXGBE_DEFAULT_FCPAUSE
;
6479 hw
->fc
.send_xon
= true;
6480 hw
->fc
.disable_fc_autoneg
= ixgbe_device_supports_autoneg_fc(hw
);
6482 #ifdef CONFIG_PCI_IOV
6484 e_dev_warn("Enabling SR-IOV VFs using the max_vfs module parameter is deprecated - please use the pci sysfs interface instead.\n");
6486 /* assign number of SR-IOV VFs */
6487 if (hw
->mac
.type
!= ixgbe_mac_82598EB
) {
6488 if (max_vfs
> IXGBE_MAX_VFS_DRV_LIMIT
) {
6490 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
6493 #endif /* CONFIG_PCI_IOV */
6495 /* enable itr by default in dynamic mode */
6496 adapter
->rx_itr_setting
= 1;
6497 adapter
->tx_itr_setting
= 1;
6499 /* set default ring sizes */
6500 adapter
->tx_ring_count
= IXGBE_DEFAULT_TXD
;
6501 adapter
->rx_ring_count
= IXGBE_DEFAULT_RXD
;
6503 /* set default work limits */
6504 adapter
->tx_work_limit
= IXGBE_DEFAULT_TX_WORK
;
6506 /* initialize eeprom parameters */
6507 if (ixgbe_init_eeprom_params_generic(hw
)) {
6508 e_dev_err("EEPROM initialization failed\n");
6512 /* PF holds first pool slot */
6513 set_bit(0, adapter
->fwd_bitmask
);
6514 set_bit(__IXGBE_DOWN
, &adapter
->state
);
6516 /* enable locking for XDP_TX if we have more CPUs than queues */
6517 if (nr_cpu_ids
> IXGBE_MAX_XDP_QS
)
6518 static_branch_enable(&ixgbe_xdp_locking_key
);
6524 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
6525 * @tx_ring: tx descriptor ring (for a specific queue) to setup
6527 * Return 0 on success, negative on failure
6529 int ixgbe_setup_tx_resources(struct ixgbe_ring
*tx_ring
)
6531 struct device
*dev
= tx_ring
->dev
;
6532 int orig_node
= dev_to_node(dev
);
6533 int ring_node
= NUMA_NO_NODE
;
6536 size
= sizeof(struct ixgbe_tx_buffer
) * tx_ring
->count
;
6538 if (tx_ring
->q_vector
)
6539 ring_node
= tx_ring
->q_vector
->numa_node
;
6541 tx_ring
->tx_buffer_info
= vmalloc_node(size
, ring_node
);
6542 if (!tx_ring
->tx_buffer_info
)
6543 tx_ring
->tx_buffer_info
= vmalloc(size
);
6544 if (!tx_ring
->tx_buffer_info
)
6547 /* round up to nearest 4K */
6548 tx_ring
->size
= tx_ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
6549 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
6551 set_dev_node(dev
, ring_node
);
6552 tx_ring
->desc
= dma_alloc_coherent(dev
,
6556 set_dev_node(dev
, orig_node
);
6558 tx_ring
->desc
= dma_alloc_coherent(dev
, tx_ring
->size
,
6559 &tx_ring
->dma
, GFP_KERNEL
);
6563 tx_ring
->next_to_use
= 0;
6564 tx_ring
->next_to_clean
= 0;
6568 vfree(tx_ring
->tx_buffer_info
);
6569 tx_ring
->tx_buffer_info
= NULL
;
6570 dev_err(dev
, "Unable to allocate memory for the Tx descriptor ring\n");
6575 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
6576 * @adapter: board private structure
6578 * If this function returns with an error, then it's possible one or
6579 * more of the rings is populated (while the rest are not). It is the
6580 * callers duty to clean those orphaned rings.
6582 * Return 0 on success, negative on failure
6584 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter
*adapter
)
6586 int i
, j
= 0, err
= 0;
6588 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
6589 err
= ixgbe_setup_tx_resources(adapter
->tx_ring
[i
]);
6593 e_err(probe
, "Allocation for Tx Queue %u failed\n", i
);
6596 for (j
= 0; j
< adapter
->num_xdp_queues
; j
++) {
6597 err
= ixgbe_setup_tx_resources(adapter
->xdp_ring
[j
]);
6601 e_err(probe
, "Allocation for Tx Queue %u failed\n", j
);
6607 /* rewind the index freeing the rings as we go */
6609 ixgbe_free_tx_resources(adapter
->xdp_ring
[j
]);
6611 ixgbe_free_tx_resources(adapter
->tx_ring
[i
]);
6615 static int ixgbe_rx_napi_id(struct ixgbe_ring
*rx_ring
)
6617 struct ixgbe_q_vector
*q_vector
= rx_ring
->q_vector
;
6619 return q_vector
? q_vector
->napi
.napi_id
: 0;
6623 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
6624 * @adapter: pointer to ixgbe_adapter
6625 * @rx_ring: rx descriptor ring (for a specific queue) to setup
6627 * Returns 0 on success, negative on failure
6629 int ixgbe_setup_rx_resources(struct ixgbe_adapter
*adapter
,
6630 struct ixgbe_ring
*rx_ring
)
6632 struct device
*dev
= rx_ring
->dev
;
6633 int orig_node
= dev_to_node(dev
);
6634 int ring_node
= NUMA_NO_NODE
;
6637 size
= sizeof(struct ixgbe_rx_buffer
) * rx_ring
->count
;
6639 if (rx_ring
->q_vector
)
6640 ring_node
= rx_ring
->q_vector
->numa_node
;
6642 rx_ring
->rx_buffer_info
= vmalloc_node(size
, ring_node
);
6643 if (!rx_ring
->rx_buffer_info
)
6644 rx_ring
->rx_buffer_info
= vmalloc(size
);
6645 if (!rx_ring
->rx_buffer_info
)
6648 /* Round up to nearest 4K */
6649 rx_ring
->size
= rx_ring
->count
* sizeof(union ixgbe_adv_rx_desc
);
6650 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
6652 set_dev_node(dev
, ring_node
);
6653 rx_ring
->desc
= dma_alloc_coherent(dev
,
6657 set_dev_node(dev
, orig_node
);
6659 rx_ring
->desc
= dma_alloc_coherent(dev
, rx_ring
->size
,
6660 &rx_ring
->dma
, GFP_KERNEL
);
6664 rx_ring
->next_to_clean
= 0;
6665 rx_ring
->next_to_use
= 0;
6667 /* XDP RX-queue info */
6668 if (xdp_rxq_info_reg(&rx_ring
->xdp_rxq
, adapter
->netdev
,
6669 rx_ring
->queue_index
, ixgbe_rx_napi_id(rx_ring
)) < 0)
6672 WRITE_ONCE(rx_ring
->xdp_prog
, adapter
->xdp_prog
);
6676 vfree(rx_ring
->rx_buffer_info
);
6677 rx_ring
->rx_buffer_info
= NULL
;
6678 dev_err(dev
, "Unable to allocate memory for the Rx descriptor ring\n");
6683 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
6684 * @adapter: board private structure
6686 * If this function returns with an error, then it's possible one or
6687 * more of the rings is populated (while the rest are not). It is the
6688 * callers duty to clean those orphaned rings.
6690 * Return 0 on success, negative on failure
6692 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter
*adapter
)
6696 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
6697 err
= ixgbe_setup_rx_resources(adapter
, adapter
->rx_ring
[i
]);
6701 e_err(probe
, "Allocation for Rx Queue %u failed\n", i
);
6706 err
= ixgbe_setup_fcoe_ddp_resources(adapter
);
6711 /* rewind the index freeing the rings as we go */
6713 ixgbe_free_rx_resources(adapter
->rx_ring
[i
]);
6718 * ixgbe_free_tx_resources - Free Tx Resources per Queue
6719 * @tx_ring: Tx descriptor ring for a specific queue
6721 * Free all transmit software resources
6723 void ixgbe_free_tx_resources(struct ixgbe_ring
*tx_ring
)
6725 ixgbe_clean_tx_ring(tx_ring
);
6727 vfree(tx_ring
->tx_buffer_info
);
6728 tx_ring
->tx_buffer_info
= NULL
;
6730 /* if not set, then don't free */
6734 dma_free_coherent(tx_ring
->dev
, tx_ring
->size
,
6735 tx_ring
->desc
, tx_ring
->dma
);
6737 tx_ring
->desc
= NULL
;
6741 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
6742 * @adapter: board private structure
6744 * Free all transmit software resources
6746 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter
*adapter
)
6750 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
6751 if (adapter
->tx_ring
[i
]->desc
)
6752 ixgbe_free_tx_resources(adapter
->tx_ring
[i
]);
6753 for (i
= 0; i
< adapter
->num_xdp_queues
; i
++)
6754 if (adapter
->xdp_ring
[i
]->desc
)
6755 ixgbe_free_tx_resources(adapter
->xdp_ring
[i
]);
6759 * ixgbe_free_rx_resources - Free Rx Resources
6760 * @rx_ring: ring to clean the resources from
6762 * Free all receive software resources
6764 void ixgbe_free_rx_resources(struct ixgbe_ring
*rx_ring
)
6766 ixgbe_clean_rx_ring(rx_ring
);
6768 rx_ring
->xdp_prog
= NULL
;
6769 xdp_rxq_info_unreg(&rx_ring
->xdp_rxq
);
6770 vfree(rx_ring
->rx_buffer_info
);
6771 rx_ring
->rx_buffer_info
= NULL
;
6773 /* if not set, then don't free */
6777 dma_free_coherent(rx_ring
->dev
, rx_ring
->size
,
6778 rx_ring
->desc
, rx_ring
->dma
);
6780 rx_ring
->desc
= NULL
;
6784 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
6785 * @adapter: board private structure
6787 * Free all receive software resources
6789 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter
*adapter
)
6794 ixgbe_free_fcoe_ddp_resources(adapter
);
6797 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
6798 if (adapter
->rx_ring
[i
]->desc
)
6799 ixgbe_free_rx_resources(adapter
->rx_ring
[i
]);
6803 * ixgbe_max_xdp_frame_size - returns the maximum allowed frame size for XDP
6804 * @adapter: device handle, pointer to adapter
6806 static int ixgbe_max_xdp_frame_size(struct ixgbe_adapter
*adapter
)
6808 if (PAGE_SIZE
>= 8192 || adapter
->flags2
& IXGBE_FLAG2_RX_LEGACY
)
6809 return IXGBE_RXBUFFER_2K
;
6811 return IXGBE_RXBUFFER_3K
;
6815 * ixgbe_change_mtu - Change the Maximum Transfer Unit
6816 * @netdev: network interface device structure
6817 * @new_mtu: new value for maximum frame size
6819 * Returns 0 on success, negative on failure
6821 static int ixgbe_change_mtu(struct net_device
*netdev
, int new_mtu
)
6823 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6825 if (ixgbe_enabled_xdp_adapter(adapter
)) {
6826 int new_frame_size
= new_mtu
+ IXGBE_PKT_HDR_PAD
;
6828 if (new_frame_size
> ixgbe_max_xdp_frame_size(adapter
)) {
6829 e_warn(probe
, "Requested MTU size is not supported with XDP\n");
6835 * For 82599EB we cannot allow legacy VFs to enable their receive
6836 * paths when MTU greater than 1500 is configured. So display a
6837 * warning that legacy VFs will be disabled.
6839 if ((adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) &&
6840 (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) &&
6841 (new_mtu
> ETH_DATA_LEN
))
6842 e_warn(probe
, "Setting MTU > 1500 will disable legacy VFs\n");
6844 netdev_dbg(netdev
, "changing MTU from %d to %d\n",
6845 netdev
->mtu
, new_mtu
);
6847 /* must set new MTU before calling down or up */
6848 WRITE_ONCE(netdev
->mtu
, new_mtu
);
6850 if (netif_running(netdev
))
6851 ixgbe_reinit_locked(adapter
);
6857 * ixgbe_open - Called when a network interface is made active
6858 * @netdev: network interface device structure
6860 * Returns 0 on success, negative value on failure
6862 * The open entry point is called when a network interface is made
6863 * active by the system (IFF_UP). At this point all resources needed
6864 * for transmit and receive operations are allocated, the interrupt
6865 * handler is registered with the OS, the watchdog timer is started,
6866 * and the stack is notified that the interface is ready.
6868 int ixgbe_open(struct net_device
*netdev
)
6870 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6871 struct ixgbe_hw
*hw
= &adapter
->hw
;
6874 /* disallow open during test */
6875 if (test_bit(__IXGBE_TESTING
, &adapter
->state
))
6878 netif_carrier_off(netdev
);
6880 /* allocate transmit descriptors */
6881 err
= ixgbe_setup_all_tx_resources(adapter
);
6885 /* allocate receive descriptors */
6886 err
= ixgbe_setup_all_rx_resources(adapter
);
6890 ixgbe_configure(adapter
);
6892 err
= ixgbe_request_irq(adapter
);
6896 /* Notify the stack of the actual queue counts. */
6897 queues
= adapter
->num_tx_queues
;
6898 err
= netif_set_real_num_tx_queues(netdev
, queues
);
6900 goto err_set_queues
;
6902 queues
= adapter
->num_rx_queues
;
6903 err
= netif_set_real_num_rx_queues(netdev
, queues
);
6905 goto err_set_queues
;
6907 ixgbe_ptp_init(adapter
);
6909 ixgbe_up_complete(adapter
);
6911 udp_tunnel_nic_reset_ntf(netdev
);
6916 ixgbe_free_irq(adapter
);
6918 ixgbe_free_all_rx_resources(adapter
);
6919 if (hw
->phy
.ops
.set_phy_power
&& !adapter
->wol
)
6920 hw
->phy
.ops
.set_phy_power(&adapter
->hw
, false);
6922 ixgbe_free_all_tx_resources(adapter
);
6924 ixgbe_reset(adapter
);
6929 static void ixgbe_close_suspend(struct ixgbe_adapter
*adapter
)
6931 ixgbe_ptp_suspend(adapter
);
6933 if (adapter
->hw
.phy
.ops
.enter_lplu
) {
6934 adapter
->hw
.phy
.reset_disable
= true;
6935 ixgbe_down(adapter
);
6936 adapter
->hw
.phy
.ops
.enter_lplu(&adapter
->hw
);
6937 adapter
->hw
.phy
.reset_disable
= false;
6939 ixgbe_down(adapter
);
6942 ixgbe_free_irq(adapter
);
6944 ixgbe_free_all_tx_resources(adapter
);
6945 ixgbe_free_all_rx_resources(adapter
);
6949 * ixgbe_close - Disables a network interface
6950 * @netdev: network interface device structure
6952 * Returns 0, this is not allowed to fail
6954 * The close entry point is called when an interface is de-activated
6955 * by the OS. The hardware is still under the drivers control, but
6956 * needs to be disabled. A global MAC reset is issued to stop the
6957 * hardware, and all transmit and receive resources are freed.
6959 int ixgbe_close(struct net_device
*netdev
)
6961 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6963 ixgbe_ptp_stop(adapter
);
6965 if (netif_device_present(netdev
))
6966 ixgbe_close_suspend(adapter
);
6968 ixgbe_fdir_filter_exit(adapter
);
6970 ixgbe_release_hw_control(adapter
);
6975 static int ixgbe_resume(struct device
*dev_d
)
6977 struct pci_dev
*pdev
= to_pci_dev(dev_d
);
6978 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
6979 struct net_device
*netdev
= adapter
->netdev
;
6982 adapter
->hw
.hw_addr
= adapter
->io_addr
;
6984 err
= pci_enable_device_mem(pdev
);
6986 e_dev_err("Cannot enable PCI device from suspend\n");
6989 smp_mb__before_atomic();
6990 clear_bit(__IXGBE_DISABLED
, &adapter
->state
);
6991 pci_set_master(pdev
);
6993 device_wakeup_disable(dev_d
);
6995 ixgbe_reset(adapter
);
6997 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
7000 err
= ixgbe_init_interrupt_scheme(adapter
);
7001 if (!err
&& netif_running(netdev
))
7002 err
= ixgbe_open(netdev
);
7006 netif_device_attach(netdev
);
7012 static int __ixgbe_shutdown(struct pci_dev
*pdev
, bool *enable_wake
)
7014 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
7015 struct net_device
*netdev
= adapter
->netdev
;
7016 struct ixgbe_hw
*hw
= &adapter
->hw
;
7018 u32 wufc
= adapter
->wol
;
7021 netif_device_detach(netdev
);
7023 if (netif_running(netdev
))
7024 ixgbe_close_suspend(adapter
);
7026 ixgbe_clear_interrupt_scheme(adapter
);
7029 if (hw
->mac
.ops
.stop_link_on_d3
)
7030 hw
->mac
.ops
.stop_link_on_d3(hw
);
7035 ixgbe_set_rx_mode(netdev
);
7037 /* enable the optics for 82599 SFP+ fiber as we can WoL */
7038 if (hw
->mac
.ops
.enable_tx_laser
)
7039 hw
->mac
.ops
.enable_tx_laser(hw
);
7041 /* enable the reception of multicast packets */
7042 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
7043 fctrl
|= IXGBE_FCTRL_MPE
;
7044 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
7046 ctrl
= IXGBE_READ_REG(hw
, IXGBE_CTRL
);
7047 ctrl
|= IXGBE_CTRL_GIO_DIS
;
7048 IXGBE_WRITE_REG(hw
, IXGBE_CTRL
, ctrl
);
7050 IXGBE_WRITE_REG(hw
, IXGBE_WUFC
, wufc
);
7052 IXGBE_WRITE_REG(hw
, IXGBE_WUC
, 0);
7053 IXGBE_WRITE_REG(hw
, IXGBE_WUFC
, 0);
7056 switch (hw
->mac
.type
) {
7057 case ixgbe_mac_82598EB
:
7058 pci_wake_from_d3(pdev
, false);
7060 case ixgbe_mac_82599EB
:
7061 case ixgbe_mac_X540
:
7062 case ixgbe_mac_X550
:
7063 case ixgbe_mac_X550EM_x
:
7064 case ixgbe_mac_x550em_a
:
7065 pci_wake_from_d3(pdev
, !!wufc
);
7071 *enable_wake
= !!wufc
;
7072 if (hw
->phy
.ops
.set_phy_power
&& !*enable_wake
)
7073 hw
->phy
.ops
.set_phy_power(hw
, false);
7075 ixgbe_release_hw_control(adapter
);
7077 if (!test_and_set_bit(__IXGBE_DISABLED
, &adapter
->state
))
7078 pci_disable_device(pdev
);
7083 static int ixgbe_suspend(struct device
*dev_d
)
7085 struct pci_dev
*pdev
= to_pci_dev(dev_d
);
7089 retval
= __ixgbe_shutdown(pdev
, &wake
);
7091 device_set_wakeup_enable(dev_d
, wake
);
7096 static void ixgbe_shutdown(struct pci_dev
*pdev
)
7100 __ixgbe_shutdown(pdev
, &wake
);
7102 if (system_state
== SYSTEM_POWER_OFF
) {
7103 pci_wake_from_d3(pdev
, wake
);
7104 pci_set_power_state(pdev
, PCI_D3hot
);
7109 * ixgbe_update_stats - Update the board statistics counters.
7110 * @adapter: board private structure
7112 void ixgbe_update_stats(struct ixgbe_adapter
*adapter
)
7114 struct net_device
*netdev
= adapter
->netdev
;
7115 struct ixgbe_hw
*hw
= &adapter
->hw
;
7116 struct ixgbe_hw_stats
*hwstats
= &adapter
->stats
;
7118 u32 i
, missed_rx
= 0, mpc
, bprc
, lxon
, lxoff
, xon_off_tot
;
7119 u64 non_eop_descs
= 0, restart_queue
= 0, tx_busy
= 0;
7120 u64 alloc_rx_page_failed
= 0, alloc_rx_buff_failed
= 0;
7121 u64 alloc_rx_page
= 0;
7122 u64 bytes
= 0, packets
= 0, hw_csum_rx_error
= 0;
7124 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
7125 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
7128 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
) {
7131 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
7132 rsc_count
+= adapter
->rx_ring
[i
]->rx_stats
.rsc_count
;
7133 rsc_flush
+= adapter
->rx_ring
[i
]->rx_stats
.rsc_flush
;
7135 adapter
->rsc_total_count
= rsc_count
;
7136 adapter
->rsc_total_flush
= rsc_flush
;
7139 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
7140 struct ixgbe_ring
*rx_ring
= READ_ONCE(adapter
->rx_ring
[i
]);
7144 non_eop_descs
+= rx_ring
->rx_stats
.non_eop_descs
;
7145 alloc_rx_page
+= rx_ring
->rx_stats
.alloc_rx_page
;
7146 alloc_rx_page_failed
+= rx_ring
->rx_stats
.alloc_rx_page_failed
;
7147 alloc_rx_buff_failed
+= rx_ring
->rx_stats
.alloc_rx_buff_failed
;
7148 hw_csum_rx_error
+= rx_ring
->rx_stats
.csum_err
;
7149 bytes
+= rx_ring
->stats
.bytes
;
7150 packets
+= rx_ring
->stats
.packets
;
7152 adapter
->non_eop_descs
= non_eop_descs
;
7153 adapter
->alloc_rx_page
= alloc_rx_page
;
7154 adapter
->alloc_rx_page_failed
= alloc_rx_page_failed
;
7155 adapter
->alloc_rx_buff_failed
= alloc_rx_buff_failed
;
7156 adapter
->hw_csum_rx_error
= hw_csum_rx_error
;
7157 netdev
->stats
.rx_bytes
= bytes
;
7158 netdev
->stats
.rx_packets
= packets
;
7162 /* gather some stats to the adapter struct that are per queue */
7163 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
7164 struct ixgbe_ring
*tx_ring
= READ_ONCE(adapter
->tx_ring
[i
]);
7168 restart_queue
+= tx_ring
->tx_stats
.restart_queue
;
7169 tx_busy
+= tx_ring
->tx_stats
.tx_busy
;
7170 bytes
+= tx_ring
->stats
.bytes
;
7171 packets
+= tx_ring
->stats
.packets
;
7173 for (i
= 0; i
< adapter
->num_xdp_queues
; i
++) {
7174 struct ixgbe_ring
*xdp_ring
= READ_ONCE(adapter
->xdp_ring
[i
]);
7178 restart_queue
+= xdp_ring
->tx_stats
.restart_queue
;
7179 tx_busy
+= xdp_ring
->tx_stats
.tx_busy
;
7180 bytes
+= xdp_ring
->stats
.bytes
;
7181 packets
+= xdp_ring
->stats
.packets
;
7183 adapter
->restart_queue
= restart_queue
;
7184 adapter
->tx_busy
= tx_busy
;
7185 netdev
->stats
.tx_bytes
= bytes
;
7186 netdev
->stats
.tx_packets
= packets
;
7188 hwstats
->crcerrs
+= IXGBE_READ_REG(hw
, IXGBE_CRCERRS
);
7190 /* 8 register reads */
7191 for (i
= 0; i
< 8; i
++) {
7192 /* for packet buffers not used, the register should read 0 */
7193 mpc
= IXGBE_READ_REG(hw
, IXGBE_MPC(i
));
7195 hwstats
->mpc
[i
] += mpc
;
7196 total_mpc
+= hwstats
->mpc
[i
];
7197 hwstats
->pxontxc
[i
] += IXGBE_READ_REG(hw
, IXGBE_PXONTXC(i
));
7198 hwstats
->pxofftxc
[i
] += IXGBE_READ_REG(hw
, IXGBE_PXOFFTXC(i
));
7199 switch (hw
->mac
.type
) {
7200 case ixgbe_mac_82598EB
:
7201 hwstats
->rnbc
[i
] += IXGBE_READ_REG(hw
, IXGBE_RNBC(i
));
7202 hwstats
->qbtc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBTC(i
));
7203 hwstats
->qbrc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBRC(i
));
7204 hwstats
->pxonrxc
[i
] +=
7205 IXGBE_READ_REG(hw
, IXGBE_PXONRXC(i
));
7207 case ixgbe_mac_82599EB
:
7208 case ixgbe_mac_X540
:
7209 case ixgbe_mac_X550
:
7210 case ixgbe_mac_X550EM_x
:
7211 case ixgbe_mac_x550em_a
:
7212 hwstats
->pxonrxc
[i
] +=
7213 IXGBE_READ_REG(hw
, IXGBE_PXONRXCNT(i
));
7220 /*16 register reads */
7221 for (i
= 0; i
< 16; i
++) {
7222 hwstats
->qptc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPTC(i
));
7223 hwstats
->qprc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPRC(i
));
7224 if ((hw
->mac
.type
== ixgbe_mac_82599EB
) ||
7225 (hw
->mac
.type
== ixgbe_mac_X540
) ||
7226 (hw
->mac
.type
== ixgbe_mac_X550
) ||
7227 (hw
->mac
.type
== ixgbe_mac_X550EM_x
) ||
7228 (hw
->mac
.type
== ixgbe_mac_x550em_a
)) {
7229 hwstats
->qbtc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBTC_L(i
));
7230 IXGBE_READ_REG(hw
, IXGBE_QBTC_H(i
)); /* to clear */
7231 hwstats
->qbrc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBRC_L(i
));
7232 IXGBE_READ_REG(hw
, IXGBE_QBRC_H(i
)); /* to clear */
7236 hwstats
->gprc
+= IXGBE_READ_REG(hw
, IXGBE_GPRC
);
7237 /* work around hardware counting issue */
7238 hwstats
->gprc
-= missed_rx
;
7240 ixgbe_update_xoff_received(adapter
);
7242 /* 82598 hardware only has a 32 bit counter in the high register */
7243 switch (hw
->mac
.type
) {
7244 case ixgbe_mac_82598EB
:
7245 hwstats
->lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXC
);
7246 hwstats
->gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCH
);
7247 hwstats
->gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCH
);
7248 hwstats
->tor
+= IXGBE_READ_REG(hw
, IXGBE_TORH
);
7250 case ixgbe_mac_X540
:
7251 case ixgbe_mac_X550
:
7252 case ixgbe_mac_X550EM_x
:
7253 case ixgbe_mac_x550em_a
:
7254 /* OS2BMC stats are X540 and later */
7255 hwstats
->o2bgptc
+= IXGBE_READ_REG(hw
, IXGBE_O2BGPTC
);
7256 hwstats
->o2bspc
+= IXGBE_READ_REG(hw
, IXGBE_O2BSPC
);
7257 hwstats
->b2ospc
+= IXGBE_READ_REG(hw
, IXGBE_B2OSPC
);
7258 hwstats
->b2ogprc
+= IXGBE_READ_REG(hw
, IXGBE_B2OGPRC
);
7260 case ixgbe_mac_82599EB
:
7261 for (i
= 0; i
< 16; i
++)
7262 adapter
->hw_rx_no_dma_resources
+=
7263 IXGBE_READ_REG(hw
, IXGBE_QPRDC(i
));
7264 hwstats
->gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCL
);
7265 IXGBE_READ_REG(hw
, IXGBE_GORCH
); /* to clear */
7266 hwstats
->gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCL
);
7267 IXGBE_READ_REG(hw
, IXGBE_GOTCH
); /* to clear */
7268 hwstats
->tor
+= IXGBE_READ_REG(hw
, IXGBE_TORL
);
7269 IXGBE_READ_REG(hw
, IXGBE_TORH
); /* to clear */
7270 hwstats
->lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXCNT
);
7271 hwstats
->fdirmatch
+= IXGBE_READ_REG(hw
, IXGBE_FDIRMATCH
);
7272 hwstats
->fdirmiss
+= IXGBE_READ_REG(hw
, IXGBE_FDIRMISS
);
7274 hwstats
->fccrc
+= IXGBE_READ_REG(hw
, IXGBE_FCCRC
);
7275 hwstats
->fcoerpdc
+= IXGBE_READ_REG(hw
, IXGBE_FCOERPDC
);
7276 hwstats
->fcoeprc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEPRC
);
7277 hwstats
->fcoeptc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEPTC
);
7278 hwstats
->fcoedwrc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEDWRC
);
7279 hwstats
->fcoedwtc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEDWTC
);
7280 /* Add up per cpu counters for total ddp aloc fail */
7281 if (adapter
->fcoe
.ddp_pool
) {
7282 struct ixgbe_fcoe
*fcoe
= &adapter
->fcoe
;
7283 struct ixgbe_fcoe_ddp_pool
*ddp_pool
;
7285 u64 noddp
= 0, noddp_ext_buff
= 0;
7286 for_each_possible_cpu(cpu
) {
7287 ddp_pool
= per_cpu_ptr(fcoe
->ddp_pool
, cpu
);
7288 noddp
+= ddp_pool
->noddp
;
7289 noddp_ext_buff
+= ddp_pool
->noddp_ext_buff
;
7291 hwstats
->fcoe_noddp
= noddp
;
7292 hwstats
->fcoe_noddp_ext_buff
= noddp_ext_buff
;
7294 #endif /* IXGBE_FCOE */
7299 bprc
= IXGBE_READ_REG(hw
, IXGBE_BPRC
);
7300 hwstats
->bprc
+= bprc
;
7301 hwstats
->mprc
+= IXGBE_READ_REG(hw
, IXGBE_MPRC
);
7302 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
7303 hwstats
->mprc
-= bprc
;
7304 hwstats
->roc
+= IXGBE_READ_REG(hw
, IXGBE_ROC
);
7305 hwstats
->prc64
+= IXGBE_READ_REG(hw
, IXGBE_PRC64
);
7306 hwstats
->prc127
+= IXGBE_READ_REG(hw
, IXGBE_PRC127
);
7307 hwstats
->prc255
+= IXGBE_READ_REG(hw
, IXGBE_PRC255
);
7308 hwstats
->prc511
+= IXGBE_READ_REG(hw
, IXGBE_PRC511
);
7309 hwstats
->prc1023
+= IXGBE_READ_REG(hw
, IXGBE_PRC1023
);
7310 hwstats
->prc1522
+= IXGBE_READ_REG(hw
, IXGBE_PRC1522
);
7311 hwstats
->rlec
+= IXGBE_READ_REG(hw
, IXGBE_RLEC
);
7312 lxon
= IXGBE_READ_REG(hw
, IXGBE_LXONTXC
);
7313 hwstats
->lxontxc
+= lxon
;
7314 lxoff
= IXGBE_READ_REG(hw
, IXGBE_LXOFFTXC
);
7315 hwstats
->lxofftxc
+= lxoff
;
7316 hwstats
->gptc
+= IXGBE_READ_REG(hw
, IXGBE_GPTC
);
7317 hwstats
->mptc
+= IXGBE_READ_REG(hw
, IXGBE_MPTC
);
7319 * 82598 errata - tx of flow control packets is included in tx counters
7321 xon_off_tot
= lxon
+ lxoff
;
7322 hwstats
->gptc
-= xon_off_tot
;
7323 hwstats
->mptc
-= xon_off_tot
;
7324 hwstats
->gotc
-= (xon_off_tot
* (ETH_ZLEN
+ ETH_FCS_LEN
));
7325 hwstats
->ruc
+= IXGBE_READ_REG(hw
, IXGBE_RUC
);
7326 hwstats
->rfc
+= IXGBE_READ_REG(hw
, IXGBE_RFC
);
7327 hwstats
->rjc
+= IXGBE_READ_REG(hw
, IXGBE_RJC
);
7328 hwstats
->tpr
+= IXGBE_READ_REG(hw
, IXGBE_TPR
);
7329 hwstats
->ptc64
+= IXGBE_READ_REG(hw
, IXGBE_PTC64
);
7330 hwstats
->ptc64
-= xon_off_tot
;
7331 hwstats
->ptc127
+= IXGBE_READ_REG(hw
, IXGBE_PTC127
);
7332 hwstats
->ptc255
+= IXGBE_READ_REG(hw
, IXGBE_PTC255
);
7333 hwstats
->ptc511
+= IXGBE_READ_REG(hw
, IXGBE_PTC511
);
7334 hwstats
->ptc1023
+= IXGBE_READ_REG(hw
, IXGBE_PTC1023
);
7335 hwstats
->ptc1522
+= IXGBE_READ_REG(hw
, IXGBE_PTC1522
);
7336 hwstats
->bptc
+= IXGBE_READ_REG(hw
, IXGBE_BPTC
);
7338 /* Fill out the OS statistics structure */
7339 netdev
->stats
.multicast
= hwstats
->mprc
;
7342 netdev
->stats
.rx_errors
= hwstats
->crcerrs
+ hwstats
->rlec
;
7343 netdev
->stats
.rx_dropped
= 0;
7344 netdev
->stats
.rx_length_errors
= hwstats
->rlec
;
7345 netdev
->stats
.rx_crc_errors
= hwstats
->crcerrs
;
7346 netdev
->stats
.rx_missed_errors
= total_mpc
;
7348 /* VF Stats Collection - skip while resetting because these
7349 * are not clear on read and otherwise you'll sometimes get
7352 if (!test_bit(__IXGBE_RESETTING
, &adapter
->state
)) {
7353 for (i
= 0; i
< adapter
->num_vfs
; i
++) {
7354 UPDATE_VF_COUNTER_32bit(IXGBE_PVFGPRC(i
),
7355 adapter
->vfinfo
[i
].last_vfstats
.gprc
,
7356 adapter
->vfinfo
[i
].vfstats
.gprc
);
7357 UPDATE_VF_COUNTER_32bit(IXGBE_PVFGPTC(i
),
7358 adapter
->vfinfo
[i
].last_vfstats
.gptc
,
7359 adapter
->vfinfo
[i
].vfstats
.gptc
);
7360 UPDATE_VF_COUNTER_36bit(IXGBE_PVFGORC_LSB(i
),
7361 IXGBE_PVFGORC_MSB(i
),
7362 adapter
->vfinfo
[i
].last_vfstats
.gorc
,
7363 adapter
->vfinfo
[i
].vfstats
.gorc
);
7364 UPDATE_VF_COUNTER_36bit(IXGBE_PVFGOTC_LSB(i
),
7365 IXGBE_PVFGOTC_MSB(i
),
7366 adapter
->vfinfo
[i
].last_vfstats
.gotc
,
7367 adapter
->vfinfo
[i
].vfstats
.gotc
);
7368 UPDATE_VF_COUNTER_32bit(IXGBE_PVFMPRC(i
),
7369 adapter
->vfinfo
[i
].last_vfstats
.mprc
,
7370 adapter
->vfinfo
[i
].vfstats
.mprc
);
7376 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
7377 * @adapter: pointer to the device adapter structure
7379 static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter
*adapter
)
7381 struct ixgbe_hw
*hw
= &adapter
->hw
;
7384 if (!(adapter
->flags2
& IXGBE_FLAG2_FDIR_REQUIRES_REINIT
))
7387 adapter
->flags2
&= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT
;
7389 /* if interface is down do nothing */
7390 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
7393 /* do nothing if we are not using signature filters */
7394 if (!(adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
))
7397 adapter
->fdir_overflow
++;
7399 if (ixgbe_reinit_fdir_tables_82599(hw
) == 0) {
7400 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
7401 set_bit(__IXGBE_TX_FDIR_INIT_DONE
,
7402 &(adapter
->tx_ring
[i
]->state
));
7403 for (i
= 0; i
< adapter
->num_xdp_queues
; i
++)
7404 set_bit(__IXGBE_TX_FDIR_INIT_DONE
,
7405 &adapter
->xdp_ring
[i
]->state
);
7406 /* re-enable flow director interrupts */
7407 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMS_FLOW_DIR
);
7409 e_err(probe
, "failed to finish FDIR re-initialization, "
7410 "ignored adding FDIR ATR filters\n");
7415 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
7416 * @adapter: pointer to the device adapter structure
7418 * This function serves two purposes. First it strobes the interrupt lines
7419 * in order to make certain interrupts are occurring. Secondly it sets the
7420 * bits needed to check for TX hangs. As a result we should immediately
7421 * determine if a hang has occurred.
7423 static void ixgbe_check_hang_subtask(struct ixgbe_adapter
*adapter
)
7425 struct ixgbe_hw
*hw
= &adapter
->hw
;
7429 /* If we're down, removing or resetting, just bail */
7430 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
7431 test_bit(__IXGBE_REMOVING
, &adapter
->state
) ||
7432 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
7435 /* Force detection of hung controller */
7436 if (netif_carrier_ok(adapter
->netdev
)) {
7437 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
7438 set_check_for_tx_hang(adapter
->tx_ring
[i
]);
7439 for (i
= 0; i
< adapter
->num_xdp_queues
; i
++)
7440 set_check_for_tx_hang(adapter
->xdp_ring
[i
]);
7443 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)) {
7445 * for legacy and MSI interrupts don't set any bits
7446 * that are enabled for EIAM, because this operation
7447 * would set *both* EIMS and EICS for any bit in EIAM
7449 IXGBE_WRITE_REG(hw
, IXGBE_EICS
,
7450 (IXGBE_EICS_TCP_TIMER
| IXGBE_EICS_OTHER
));
7452 /* get one bit for every active tx/rx interrupt vector */
7453 for (i
= 0; i
< adapter
->num_q_vectors
; i
++) {
7454 struct ixgbe_q_vector
*qv
= adapter
->q_vector
[i
];
7455 if (qv
->rx
.ring
|| qv
->tx
.ring
)
7460 /* Cause software interrupt to ensure rings are cleaned */
7461 ixgbe_irq_rearm_queues(adapter
, eics
);
7465 * ixgbe_watchdog_update_link - update the link status
7466 * @adapter: pointer to the device adapter structure
7468 static void ixgbe_watchdog_update_link(struct ixgbe_adapter
*adapter
)
7470 struct ixgbe_hw
*hw
= &adapter
->hw
;
7471 u32 link_speed
= adapter
->link_speed
;
7472 bool link_up
= adapter
->link_up
;
7473 bool pfc_en
= adapter
->dcb_cfg
.pfc_mode_enable
;
7475 if (!(adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
))
7478 if (hw
->mac
.ops
.check_link
) {
7479 hw
->mac
.ops
.check_link(hw
, &link_speed
, &link_up
, false);
7481 /* always assume link is up, if no check link function */
7482 link_speed
= IXGBE_LINK_SPEED_10GB_FULL
;
7486 if (adapter
->ixgbe_ieee_pfc
)
7487 pfc_en
|= !!(adapter
->ixgbe_ieee_pfc
->pfc_en
);
7489 if (link_up
&& !((adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) && pfc_en
)) {
7490 hw
->mac
.ops
.fc_enable(hw
);
7491 ixgbe_set_rx_drop_en(adapter
);
7495 time_after(jiffies
, (adapter
->link_check_timeout
+
7496 IXGBE_TRY_LINK_TIMEOUT
))) {
7497 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_UPDATE
;
7498 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMC_LSC
);
7499 IXGBE_WRITE_FLUSH(hw
);
7502 adapter
->link_up
= link_up
;
7503 adapter
->link_speed
= link_speed
;
7506 static void ixgbe_update_default_up(struct ixgbe_adapter
*adapter
)
7508 #ifdef CONFIG_IXGBE_DCB
7509 struct net_device
*netdev
= adapter
->netdev
;
7510 struct dcb_app app
= {
7511 .selector
= IEEE_8021QAZ_APP_SEL_ETHERTYPE
,
7516 if (adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
)
7517 up
= dcb_ieee_getapp_mask(netdev
, &app
);
7519 adapter
->default_up
= (up
> 1) ? (ffs(up
) - 1) : 0;
7524 * ixgbe_watchdog_link_is_up - update netif_carrier status and
7525 * print link up message
7526 * @adapter: pointer to the device adapter structure
7528 static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter
*adapter
)
7530 struct net_device
*netdev
= adapter
->netdev
;
7531 struct ixgbe_hw
*hw
= &adapter
->hw
;
7532 u32 link_speed
= adapter
->link_speed
;
7533 const char *speed_str
;
7534 bool flow_rx
, flow_tx
;
7536 /* only continue if link was previously down */
7537 if (netif_carrier_ok(netdev
))
7540 adapter
->flags2
&= ~IXGBE_FLAG2_SEARCH_FOR_SFP
;
7542 switch (hw
->mac
.type
) {
7543 case ixgbe_mac_82598EB
: {
7544 u32 frctl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
7545 u32 rmcs
= IXGBE_READ_REG(hw
, IXGBE_RMCS
);
7546 flow_rx
= !!(frctl
& IXGBE_FCTRL_RFCE
);
7547 flow_tx
= !!(rmcs
& IXGBE_RMCS_TFCE_802_3X
);
7550 case ixgbe_mac_X540
:
7551 case ixgbe_mac_X550
:
7552 case ixgbe_mac_X550EM_x
:
7553 case ixgbe_mac_x550em_a
:
7554 case ixgbe_mac_82599EB
: {
7555 u32 mflcn
= IXGBE_READ_REG(hw
, IXGBE_MFLCN
);
7556 u32 fccfg
= IXGBE_READ_REG(hw
, IXGBE_FCCFG
);
7557 flow_rx
= !!(mflcn
& IXGBE_MFLCN_RFCE
);
7558 flow_tx
= !!(fccfg
& IXGBE_FCCFG_TFCE_802_3X
);
7567 adapter
->last_rx_ptp_check
= jiffies
;
7569 if (test_bit(__IXGBE_PTP_RUNNING
, &adapter
->state
))
7570 ixgbe_ptp_start_cyclecounter(adapter
);
7572 switch (link_speed
) {
7573 case IXGBE_LINK_SPEED_10GB_FULL
:
7574 speed_str
= "10 Gbps";
7576 case IXGBE_LINK_SPEED_5GB_FULL
:
7577 speed_str
= "5 Gbps";
7579 case IXGBE_LINK_SPEED_2_5GB_FULL
:
7580 speed_str
= "2.5 Gbps";
7582 case IXGBE_LINK_SPEED_1GB_FULL
:
7583 speed_str
= "1 Gbps";
7585 case IXGBE_LINK_SPEED_100_FULL
:
7586 speed_str
= "100 Mbps";
7588 case IXGBE_LINK_SPEED_10_FULL
:
7589 speed_str
= "10 Mbps";
7592 speed_str
= "unknown speed";
7595 e_info(drv
, "NIC Link is Up %s, Flow Control: %s\n", speed_str
,
7596 ((flow_rx
&& flow_tx
) ? "RX/TX" :
7598 (flow_tx
? "TX" : "None"))));
7600 netif_carrier_on(netdev
);
7601 ixgbe_check_vf_rate_limit(adapter
);
7603 /* enable transmits */
7604 netif_tx_wake_all_queues(adapter
->netdev
);
7606 /* update the default user priority for VFs */
7607 ixgbe_update_default_up(adapter
);
7609 /* ping all the active vfs to let them know link has changed */
7610 ixgbe_ping_all_vfs(adapter
);
7614 * ixgbe_watchdog_link_is_down - update netif_carrier status and
7615 * print link down message
7616 * @adapter: pointer to the adapter structure
7618 static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter
*adapter
)
7620 struct net_device
*netdev
= adapter
->netdev
;
7621 struct ixgbe_hw
*hw
= &adapter
->hw
;
7623 adapter
->link_up
= false;
7624 adapter
->link_speed
= 0;
7626 /* only continue if link was up previously */
7627 if (!netif_carrier_ok(netdev
))
7630 /* poll for SFP+ cable when link is down */
7631 if (ixgbe_is_sfp(hw
) && hw
->mac
.type
== ixgbe_mac_82598EB
)
7632 adapter
->flags2
|= IXGBE_FLAG2_SEARCH_FOR_SFP
;
7634 if (test_bit(__IXGBE_PTP_RUNNING
, &adapter
->state
))
7635 ixgbe_ptp_start_cyclecounter(adapter
);
7637 e_info(drv
, "NIC Link is Down\n");
7638 netif_carrier_off(netdev
);
7640 /* ping all the active vfs to let them know link has changed */
7641 ixgbe_ping_all_vfs(adapter
);
7644 static bool ixgbe_ring_tx_pending(struct ixgbe_adapter
*adapter
)
7648 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
7649 struct ixgbe_ring
*tx_ring
= adapter
->tx_ring
[i
];
7651 if (tx_ring
->next_to_use
!= tx_ring
->next_to_clean
)
7655 for (i
= 0; i
< adapter
->num_xdp_queues
; i
++) {
7656 struct ixgbe_ring
*ring
= adapter
->xdp_ring
[i
];
7658 if (ring
->next_to_use
!= ring
->next_to_clean
)
7665 static bool ixgbe_vf_tx_pending(struct ixgbe_adapter
*adapter
)
7667 struct ixgbe_hw
*hw
= &adapter
->hw
;
7668 struct ixgbe_ring_feature
*vmdq
= &adapter
->ring_feature
[RING_F_VMDQ
];
7669 u32 q_per_pool
= __ALIGN_MASK(1, ~vmdq
->mask
);
7673 if (!adapter
->num_vfs
)
7676 /* resetting the PF is only needed for MAC before X550 */
7677 if (hw
->mac
.type
>= ixgbe_mac_X550
)
7680 for (i
= 0; i
< adapter
->num_vfs
; i
++) {
7681 for (j
= 0; j
< q_per_pool
; j
++) {
7684 h
= IXGBE_READ_REG(hw
, IXGBE_PVFTDHN(q_per_pool
, i
, j
));
7685 t
= IXGBE_READ_REG(hw
, IXGBE_PVFTDTN(q_per_pool
, i
, j
));
7696 * ixgbe_watchdog_flush_tx - flush queues on link down
7697 * @adapter: pointer to the device adapter structure
7699 static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter
*adapter
)
7701 if (!netif_carrier_ok(adapter
->netdev
)) {
7702 if (ixgbe_ring_tx_pending(adapter
) ||
7703 ixgbe_vf_tx_pending(adapter
)) {
7704 /* We've lost link, so the controller stops DMA,
7705 * but we've got queued Tx work that's never going
7706 * to get done, so reset controller to flush Tx.
7707 * (Do the reset outside of interrupt context).
7709 e_warn(drv
, "initiating reset to clear Tx work after link loss\n");
7710 set_bit(__IXGBE_RESET_REQUESTED
, &adapter
->state
);
7715 #ifdef CONFIG_PCI_IOV
7716 static void ixgbe_bad_vf_abort(struct ixgbe_adapter
*adapter
, u32 vf
)
7718 struct ixgbe_hw
*hw
= &adapter
->hw
;
7720 if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
&&
7721 adapter
->flags2
& IXGBE_FLAG2_AUTO_DISABLE_VF
) {
7722 adapter
->vfinfo
[vf
].primary_abort_count
++;
7723 if (adapter
->vfinfo
[vf
].primary_abort_count
==
7724 IXGBE_PRIMARY_ABORT_LIMIT
) {
7725 ixgbe_set_vf_link_state(adapter
, vf
,
7726 IFLA_VF_LINK_STATE_DISABLE
);
7727 adapter
->vfinfo
[vf
].primary_abort_count
= 0;
7730 "Malicious Driver Detection event detected on PF %d VF %d MAC: %pM mdd-disable-vf=on",
7732 adapter
->vfinfo
[vf
].vf_mac_addresses
);
7737 static void ixgbe_check_for_bad_vf(struct ixgbe_adapter
*adapter
)
7739 struct ixgbe_hw
*hw
= &adapter
->hw
;
7740 struct pci_dev
*pdev
= adapter
->pdev
;
7744 if (!(netif_carrier_ok(adapter
->netdev
)))
7747 gpc
= IXGBE_READ_REG(hw
, IXGBE_TXDGPC
);
7748 if (gpc
) /* If incrementing then no need for the check below */
7750 /* Check to see if a bad DMA write target from an errant or
7751 * malicious VF has caused a PCIe error. If so then we can
7752 * issue a VFLR to the offending VF(s) and then resume without
7753 * requesting a full slot reset.
7759 /* check status reg for all VFs owned by this PF */
7760 for (vf
= 0; vf
< adapter
->num_vfs
; ++vf
) {
7761 struct pci_dev
*vfdev
= adapter
->vfinfo
[vf
].vfdev
;
7766 pci_read_config_word(vfdev
, PCI_STATUS
, &status_reg
);
7767 if (status_reg
!= IXGBE_FAILED_READ_CFG_WORD
&&
7768 status_reg
& PCI_STATUS_REC_MASTER_ABORT
) {
7769 ixgbe_bad_vf_abort(adapter
, vf
);
7775 static void ixgbe_spoof_check(struct ixgbe_adapter
*adapter
)
7779 /* Do not perform spoof check for 82598 or if not in IOV mode */
7780 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
||
7781 adapter
->num_vfs
== 0)
7784 ssvpc
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_SSVPC
);
7787 * ssvpc register is cleared on read, if zero then no
7788 * spoofed packets in the last interval.
7793 e_warn(drv
, "%u Spoofed packets detected\n", ssvpc
);
7796 static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused
*adapter
)
7801 ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused
*adapter
)
7804 #endif /* CONFIG_PCI_IOV */
7808 * ixgbe_watchdog_subtask - check and bring link up
7809 * @adapter: pointer to the device adapter structure
7811 static void ixgbe_watchdog_subtask(struct ixgbe_adapter
*adapter
)
7813 /* if interface is down, removing or resetting, do nothing */
7814 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
7815 test_bit(__IXGBE_REMOVING
, &adapter
->state
) ||
7816 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
7819 ixgbe_watchdog_update_link(adapter
);
7821 if (adapter
->link_up
)
7822 ixgbe_watchdog_link_is_up(adapter
);
7824 ixgbe_watchdog_link_is_down(adapter
);
7826 ixgbe_check_for_bad_vf(adapter
);
7827 ixgbe_spoof_check(adapter
);
7828 ixgbe_update_stats(adapter
);
7830 ixgbe_watchdog_flush_tx(adapter
);
7834 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
7835 * @adapter: the ixgbe adapter structure
7837 static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter
*adapter
)
7839 struct ixgbe_hw
*hw
= &adapter
->hw
;
7842 /* not searching for SFP so there is nothing to do here */
7843 if (!(adapter
->flags2
& IXGBE_FLAG2_SEARCH_FOR_SFP
) &&
7844 !(adapter
->flags2
& IXGBE_FLAG2_SFP_NEEDS_RESET
))
7847 if (adapter
->sfp_poll_time
&&
7848 time_after(adapter
->sfp_poll_time
, jiffies
))
7849 return; /* If not yet time to poll for SFP */
7851 /* someone else is in init, wait until next service event */
7852 if (test_and_set_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
))
7855 adapter
->sfp_poll_time
= jiffies
+ IXGBE_SFP_POLL_JIFFIES
- 1;
7857 err
= hw
->phy
.ops
.identify_sfp(hw
);
7858 if (err
== -EOPNOTSUPP
)
7861 if (err
== -ENOENT
) {
7862 /* If no cable is present, then we need to reset
7863 * the next time we find a good cable. */
7864 adapter
->flags2
|= IXGBE_FLAG2_SFP_NEEDS_RESET
;
7871 /* exit if reset not needed */
7872 if (!(adapter
->flags2
& IXGBE_FLAG2_SFP_NEEDS_RESET
))
7875 adapter
->flags2
&= ~IXGBE_FLAG2_SFP_NEEDS_RESET
;
7878 * A module may be identified correctly, but the EEPROM may not have
7879 * support for that module. setup_sfp() will fail in that case, so
7880 * we should not allow that module to load.
7882 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
7883 err
= hw
->phy
.ops
.reset(hw
);
7885 err
= hw
->mac
.ops
.setup_sfp(hw
);
7887 if (err
== -EOPNOTSUPP
)
7890 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_CONFIG
;
7891 e_info(probe
, "detected SFP+: %d\n", hw
->phy
.sfp_type
);
7894 clear_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
);
7896 if (err
== -EOPNOTSUPP
&&
7897 adapter
->netdev
->reg_state
== NETREG_REGISTERED
) {
7898 e_dev_err("failed to initialize because an unsupported "
7899 "SFP+ module type was detected.\n");
7900 e_dev_err("Reload the driver after installing a "
7901 "supported module.\n");
7902 unregister_netdev(adapter
->netdev
);
7907 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
7908 * @adapter: the ixgbe adapter structure
7910 static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter
*adapter
)
7912 struct ixgbe_hw
*hw
= &adapter
->hw
;
7915 bool autoneg
= false;
7917 if (!(adapter
->flags
& IXGBE_FLAG_NEED_LINK_CONFIG
))
7920 /* someone else is in init, wait until next service event */
7921 if (test_and_set_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
))
7924 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_CONFIG
;
7926 hw
->mac
.ops
.get_link_capabilities(hw
, &cap_speed
, &autoneg
);
7928 /* advertise highest capable link speed */
7929 if (!autoneg
&& (cap_speed
& IXGBE_LINK_SPEED_10GB_FULL
))
7930 speed
= IXGBE_LINK_SPEED_10GB_FULL
;
7932 speed
= cap_speed
& (IXGBE_LINK_SPEED_10GB_FULL
|
7933 IXGBE_LINK_SPEED_1GB_FULL
);
7935 if (hw
->mac
.ops
.setup_link
)
7936 hw
->mac
.ops
.setup_link(hw
, speed
, true);
7938 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
7939 adapter
->link_check_timeout
= jiffies
;
7940 clear_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
);
7944 * ixgbe_service_timer - Timer Call-back
7945 * @t: pointer to timer_list structure
7947 static void ixgbe_service_timer(struct timer_list
*t
)
7949 struct ixgbe_adapter
*adapter
= from_timer(adapter
, t
, service_timer
);
7950 unsigned long next_event_offset
;
7952 /* poll faster when waiting for link */
7953 if (adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
)
7954 next_event_offset
= HZ
/ 10;
7956 next_event_offset
= HZ
* 2;
7958 /* Reset the timer */
7959 mod_timer(&adapter
->service_timer
, next_event_offset
+ jiffies
);
7961 ixgbe_service_event_schedule(adapter
);
7964 static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter
*adapter
)
7966 struct ixgbe_hw
*hw
= &adapter
->hw
;
7969 if (!(adapter
->flags2
& IXGBE_FLAG2_PHY_INTERRUPT
))
7972 adapter
->flags2
&= ~IXGBE_FLAG2_PHY_INTERRUPT
;
7974 if (!hw
->phy
.ops
.handle_lasi
)
7977 hw
->phy
.ops
.handle_lasi(&adapter
->hw
, &overtemp
);
7979 e_crit(drv
, "%s\n", ixgbe_overheat_msg
);
7982 static void ixgbe_reset_subtask(struct ixgbe_adapter
*adapter
)
7984 if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED
, &adapter
->state
))
7988 /* If we're already down, removing or resetting, just bail */
7989 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
7990 test_bit(__IXGBE_REMOVING
, &adapter
->state
) ||
7991 test_bit(__IXGBE_RESETTING
, &adapter
->state
)) {
7996 ixgbe_dump(adapter
);
7997 netdev_err(adapter
->netdev
, "Reset adapter\n");
7998 adapter
->tx_timeout_count
++;
8000 ixgbe_reinit_locked(adapter
);
8005 * ixgbe_check_fw_error - Check firmware for errors
8006 * @adapter: the adapter private structure
8008 * Check firmware errors in register FWSM
8010 static bool ixgbe_check_fw_error(struct ixgbe_adapter
*adapter
)
8012 struct ixgbe_hw
*hw
= &adapter
->hw
;
8015 /* read fwsm.ext_err_ind register and log errors */
8016 fwsm
= IXGBE_READ_REG(hw
, IXGBE_FWSM(hw
));
8018 if (fwsm
& IXGBE_FWSM_EXT_ERR_IND_MASK
||
8019 !(fwsm
& IXGBE_FWSM_FW_VAL_BIT
))
8020 e_dev_warn("Warning firmware error detected FWSM: 0x%08X\n",
8023 if (hw
->mac
.ops
.fw_recovery_mode
&& hw
->mac
.ops
.fw_recovery_mode(hw
)) {
8024 e_dev_err("Firmware recovery mode detected. Limiting functionality. Refer to the Intel(R) Ethernet Adapters and Devices User Guide for details on firmware recovery mode.\n");
8032 * ixgbe_service_task - manages and runs subtasks
8033 * @work: pointer to work_struct containing our data
8035 static void ixgbe_service_task(struct work_struct
*work
)
8037 struct ixgbe_adapter
*adapter
= container_of(work
,
8038 struct ixgbe_adapter
,
8040 if (ixgbe_removed(adapter
->hw
.hw_addr
)) {
8041 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
8043 ixgbe_down(adapter
);
8046 ixgbe_service_event_complete(adapter
);
8049 if (ixgbe_check_fw_error(adapter
)) {
8050 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
8051 unregister_netdev(adapter
->netdev
);
8052 ixgbe_service_event_complete(adapter
);
8055 ixgbe_reset_subtask(adapter
);
8056 ixgbe_phy_interrupt_subtask(adapter
);
8057 ixgbe_sfp_detection_subtask(adapter
);
8058 ixgbe_sfp_link_config_subtask(adapter
);
8059 ixgbe_check_overtemp_subtask(adapter
);
8060 ixgbe_watchdog_subtask(adapter
);
8061 ixgbe_fdir_reinit_subtask(adapter
);
8062 ixgbe_check_hang_subtask(adapter
);
8064 if (test_bit(__IXGBE_PTP_RUNNING
, &adapter
->state
)) {
8065 ixgbe_ptp_overflow_check(adapter
);
8066 if (adapter
->flags
& IXGBE_FLAG_RX_HWTSTAMP_IN_REGISTER
)
8067 ixgbe_ptp_rx_hang(adapter
);
8068 ixgbe_ptp_tx_hang(adapter
);
8071 ixgbe_service_event_complete(adapter
);
8074 static int ixgbe_tso(struct ixgbe_ring
*tx_ring
,
8075 struct ixgbe_tx_buffer
*first
,
8077 struct ixgbe_ipsec_tx_data
*itd
)
8079 u32 vlan_macip_lens
, type_tucmd
, mss_l4len_idx
;
8080 struct sk_buff
*skb
= first
->skb
;
8091 u32 paylen
, l4_offset
;
8092 u32 fceof_saidx
= 0;
8095 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
8098 if (!skb_is_gso(skb
))
8101 err
= skb_cow_head(skb
, 0);
8105 if (eth_p_mpls(first
->protocol
))
8106 ip
.hdr
= skb_inner_network_header(skb
);
8108 ip
.hdr
= skb_network_header(skb
);
8109 l4
.hdr
= skb_checksum_start(skb
);
8111 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
8112 type_tucmd
= (skb_shinfo(skb
)->gso_type
& SKB_GSO_UDP_L4
) ?
8113 IXGBE_ADVTXD_TUCMD_L4T_UDP
: IXGBE_ADVTXD_TUCMD_L4T_TCP
;
8115 /* initialize outer IP header fields */
8116 if (ip
.v4
->version
== 4) {
8117 unsigned char *csum_start
= skb_checksum_start(skb
);
8118 unsigned char *trans_start
= ip
.hdr
+ (ip
.v4
->ihl
* 4);
8119 int len
= csum_start
- trans_start
;
8121 /* IP header will have to cancel out any data that
8122 * is not a part of the outer IP header, so set to
8123 * a reverse csum if needed, else init check to 0.
8125 ip
.v4
->check
= (skb_shinfo(skb
)->gso_type
& SKB_GSO_PARTIAL
) ?
8126 csum_fold(csum_partial(trans_start
,
8128 type_tucmd
|= IXGBE_ADVTXD_TUCMD_IPV4
;
8131 first
->tx_flags
|= IXGBE_TX_FLAGS_TSO
|
8132 IXGBE_TX_FLAGS_CSUM
|
8133 IXGBE_TX_FLAGS_IPV4
;
8135 ip
.v6
->payload_len
= 0;
8136 first
->tx_flags
|= IXGBE_TX_FLAGS_TSO
|
8137 IXGBE_TX_FLAGS_CSUM
;
8140 /* determine offset of inner transport header */
8141 l4_offset
= l4
.hdr
- skb
->data
;
8143 /* remove payload length from inner checksum */
8144 paylen
= skb
->len
- l4_offset
;
8146 if (type_tucmd
& IXGBE_ADVTXD_TUCMD_L4T_TCP
) {
8147 /* compute length of segmentation header */
8148 *hdr_len
= (l4
.tcp
->doff
* 4) + l4_offset
;
8149 csum_replace_by_diff(&l4
.tcp
->check
,
8150 (__force __wsum
)htonl(paylen
));
8152 /* compute length of segmentation header */
8153 *hdr_len
= sizeof(*l4
.udp
) + l4_offset
;
8154 csum_replace_by_diff(&l4
.udp
->check
,
8155 (__force __wsum
)htonl(paylen
));
8158 /* update gso size and bytecount with header size */
8159 first
->gso_segs
= skb_shinfo(skb
)->gso_segs
;
8160 first
->bytecount
+= (first
->gso_segs
- 1) * *hdr_len
;
8162 /* mss_l4len_id: use 0 as index for TSO */
8163 mss_l4len_idx
= (*hdr_len
- l4_offset
) << IXGBE_ADVTXD_L4LEN_SHIFT
;
8164 mss_l4len_idx
|= skb_shinfo(skb
)->gso_size
<< IXGBE_ADVTXD_MSS_SHIFT
;
8166 fceof_saidx
|= itd
->sa_idx
;
8167 type_tucmd
|= itd
->flags
| itd
->trailer_len
;
8169 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
8170 vlan_macip_lens
= l4
.hdr
- ip
.hdr
;
8171 vlan_macip_lens
|= (ip
.hdr
- skb
->data
) << IXGBE_ADVTXD_MACLEN_SHIFT
;
8172 vlan_macip_lens
|= first
->tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
;
8174 ixgbe_tx_ctxtdesc(tx_ring
, vlan_macip_lens
, fceof_saidx
, type_tucmd
,
8180 static void ixgbe_tx_csum(struct ixgbe_ring
*tx_ring
,
8181 struct ixgbe_tx_buffer
*first
,
8182 struct ixgbe_ipsec_tx_data
*itd
)
8184 struct sk_buff
*skb
= first
->skb
;
8185 u32 vlan_macip_lens
= 0;
8186 u32 fceof_saidx
= 0;
8189 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
) {
8191 if (!(first
->tx_flags
& (IXGBE_TX_FLAGS_HW_VLAN
|
8192 IXGBE_TX_FLAGS_CC
)))
8197 switch (skb
->csum_offset
) {
8198 case offsetof(struct tcphdr
, check
):
8199 type_tucmd
= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
8201 case offsetof(struct udphdr
, check
):
8203 case offsetof(struct sctphdr
, checksum
):
8204 /* validate that this is actually an SCTP request */
8205 if (skb_csum_is_sctp(skb
)) {
8206 type_tucmd
= IXGBE_ADVTXD_TUCMD_L4T_SCTP
;
8211 skb_checksum_help(skb
);
8215 /* update TX checksum flag */
8216 first
->tx_flags
|= IXGBE_TX_FLAGS_CSUM
;
8217 vlan_macip_lens
= skb_checksum_start_offset(skb
) -
8218 skb_network_offset(skb
);
8220 /* vlan_macip_lens: MACLEN, VLAN tag */
8221 vlan_macip_lens
|= skb_network_offset(skb
) << IXGBE_ADVTXD_MACLEN_SHIFT
;
8222 vlan_macip_lens
|= first
->tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
;
8224 fceof_saidx
|= itd
->sa_idx
;
8225 type_tucmd
|= itd
->flags
| itd
->trailer_len
;
8227 ixgbe_tx_ctxtdesc(tx_ring
, vlan_macip_lens
, fceof_saidx
, type_tucmd
, 0);
8230 #define IXGBE_SET_FLAG(_input, _flag, _result) \
8231 ((_flag <= _result) ? \
8232 ((u32)(_input & _flag) * (_result / _flag)) : \
8233 ((u32)(_input & _flag) / (_flag / _result)))
8235 static u32
ixgbe_tx_cmd_type(struct sk_buff
*skb
, u32 tx_flags
)
8237 /* set type for advanced descriptor with frame checksum insertion */
8238 u32 cmd_type
= IXGBE_ADVTXD_DTYP_DATA
|
8239 IXGBE_ADVTXD_DCMD_DEXT
|
8240 IXGBE_ADVTXD_DCMD_IFCS
;
8242 /* set HW vlan bit if vlan is present */
8243 cmd_type
|= IXGBE_SET_FLAG(tx_flags
, IXGBE_TX_FLAGS_HW_VLAN
,
8244 IXGBE_ADVTXD_DCMD_VLE
);
8246 /* set segmentation enable bits for TSO/FSO */
8247 cmd_type
|= IXGBE_SET_FLAG(tx_flags
, IXGBE_TX_FLAGS_TSO
,
8248 IXGBE_ADVTXD_DCMD_TSE
);
8250 /* set timestamp bit if present */
8251 cmd_type
|= IXGBE_SET_FLAG(tx_flags
, IXGBE_TX_FLAGS_TSTAMP
,
8252 IXGBE_ADVTXD_MAC_TSTAMP
);
8254 /* insert frame checksum */
8255 cmd_type
^= IXGBE_SET_FLAG(skb
->no_fcs
, 1, IXGBE_ADVTXD_DCMD_IFCS
);
8260 static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc
*tx_desc
,
8261 u32 tx_flags
, unsigned int paylen
)
8263 u32 olinfo_status
= paylen
<< IXGBE_ADVTXD_PAYLEN_SHIFT
;
8265 /* enable L4 checksum for TSO and TX checksum offload */
8266 olinfo_status
|= IXGBE_SET_FLAG(tx_flags
,
8267 IXGBE_TX_FLAGS_CSUM
,
8268 IXGBE_ADVTXD_POPTS_TXSM
);
8270 /* enable IPv4 checksum for TSO */
8271 olinfo_status
|= IXGBE_SET_FLAG(tx_flags
,
8272 IXGBE_TX_FLAGS_IPV4
,
8273 IXGBE_ADVTXD_POPTS_IXSM
);
8276 olinfo_status
|= IXGBE_SET_FLAG(tx_flags
,
8277 IXGBE_TX_FLAGS_IPSEC
,
8278 IXGBE_ADVTXD_POPTS_IPSEC
);
8281 * Check Context must be set if Tx switch is enabled, which it
8282 * always is for case where virtual functions are running
8284 olinfo_status
|= IXGBE_SET_FLAG(tx_flags
,
8288 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
8291 static int __ixgbe_maybe_stop_tx(struct ixgbe_ring
*tx_ring
, u16 size
)
8293 if (!netif_subqueue_try_stop(tx_ring
->netdev
, tx_ring
->queue_index
,
8294 ixgbe_desc_unused(tx_ring
), size
))
8297 ++tx_ring
->tx_stats
.restart_queue
;
8301 static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring
*tx_ring
, u16 size
)
8303 if (likely(ixgbe_desc_unused(tx_ring
) >= size
))
8306 return __ixgbe_maybe_stop_tx(tx_ring
, size
);
8309 static int ixgbe_tx_map(struct ixgbe_ring
*tx_ring
,
8310 struct ixgbe_tx_buffer
*first
,
8313 struct sk_buff
*skb
= first
->skb
;
8314 struct ixgbe_tx_buffer
*tx_buffer
;
8315 union ixgbe_adv_tx_desc
*tx_desc
;
8318 unsigned int data_len
, size
;
8319 u32 tx_flags
= first
->tx_flags
;
8320 u32 cmd_type
= ixgbe_tx_cmd_type(skb
, tx_flags
);
8321 u16 i
= tx_ring
->next_to_use
;
8323 tx_desc
= IXGBE_TX_DESC(tx_ring
, i
);
8325 ixgbe_tx_olinfo_status(tx_desc
, tx_flags
, skb
->len
- hdr_len
);
8327 size
= skb_headlen(skb
);
8328 data_len
= skb
->data_len
;
8331 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
) {
8332 if (data_len
< sizeof(struct fcoe_crc_eof
)) {
8333 size
-= sizeof(struct fcoe_crc_eof
) - data_len
;
8336 data_len
-= sizeof(struct fcoe_crc_eof
);
8341 dma
= dma_map_single(tx_ring
->dev
, skb
->data
, size
, DMA_TO_DEVICE
);
8345 for (frag
= &skb_shinfo(skb
)->frags
[0];; frag
++) {
8346 if (dma_mapping_error(tx_ring
->dev
, dma
))
8349 /* record length, and DMA address */
8350 dma_unmap_len_set(tx_buffer
, len
, size
);
8351 dma_unmap_addr_set(tx_buffer
, dma
, dma
);
8353 tx_desc
->read
.buffer_addr
= cpu_to_le64(dma
);
8355 while (unlikely(size
> IXGBE_MAX_DATA_PER_TXD
)) {
8356 tx_desc
->read
.cmd_type_len
=
8357 cpu_to_le32(cmd_type
^ IXGBE_MAX_DATA_PER_TXD
);
8361 if (i
== tx_ring
->count
) {
8362 tx_desc
= IXGBE_TX_DESC(tx_ring
, 0);
8365 tx_desc
->read
.olinfo_status
= 0;
8367 dma
+= IXGBE_MAX_DATA_PER_TXD
;
8368 size
-= IXGBE_MAX_DATA_PER_TXD
;
8370 tx_desc
->read
.buffer_addr
= cpu_to_le64(dma
);
8373 if (likely(!data_len
))
8376 tx_desc
->read
.cmd_type_len
= cpu_to_le32(cmd_type
^ size
);
8380 if (i
== tx_ring
->count
) {
8381 tx_desc
= IXGBE_TX_DESC(tx_ring
, 0);
8384 tx_desc
->read
.olinfo_status
= 0;
8387 size
= min_t(unsigned int, data_len
, skb_frag_size(frag
));
8389 size
= skb_frag_size(frag
);
8393 dma
= skb_frag_dma_map(tx_ring
->dev
, frag
, 0, size
,
8396 tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
8399 /* write last descriptor with RS and EOP bits */
8400 cmd_type
|= size
| IXGBE_TXD_CMD
;
8401 tx_desc
->read
.cmd_type_len
= cpu_to_le32(cmd_type
);
8403 netdev_tx_sent_queue(txring_txq(tx_ring
), first
->bytecount
);
8405 /* set the timestamp */
8406 first
->time_stamp
= jiffies
;
8408 skb_tx_timestamp(skb
);
8411 * Force memory writes to complete before letting h/w know there
8412 * are new descriptors to fetch. (Only applicable for weak-ordered
8413 * memory model archs, such as IA-64).
8415 * We also need this memory barrier to make certain all of the
8416 * status bits have been updated before next_to_watch is written.
8420 /* set next_to_watch value indicating a packet is present */
8421 first
->next_to_watch
= tx_desc
;
8424 if (i
== tx_ring
->count
)
8427 tx_ring
->next_to_use
= i
;
8429 ixgbe_maybe_stop_tx(tx_ring
, DESC_NEEDED
);
8431 if (netif_xmit_stopped(txring_txq(tx_ring
)) || !netdev_xmit_more()) {
8432 writel(i
, tx_ring
->tail
);
8437 dev_err(tx_ring
->dev
, "TX DMA map failed\n");
8439 /* clear dma mappings for failed tx_buffer_info map */
8441 tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
8442 if (dma_unmap_len(tx_buffer
, len
))
8443 dma_unmap_page(tx_ring
->dev
,
8444 dma_unmap_addr(tx_buffer
, dma
),
8445 dma_unmap_len(tx_buffer
, len
),
8447 dma_unmap_len_set(tx_buffer
, len
, 0);
8448 if (tx_buffer
== first
)
8451 i
+= tx_ring
->count
;
8455 dev_kfree_skb_any(first
->skb
);
8458 tx_ring
->next_to_use
= i
;
8463 static void ixgbe_atr(struct ixgbe_ring
*ring
,
8464 struct ixgbe_tx_buffer
*first
)
8466 struct ixgbe_q_vector
*q_vector
= ring
->q_vector
;
8467 union ixgbe_atr_hash_dword input
= { .dword
= 0 };
8468 union ixgbe_atr_hash_dword common
= { .dword
= 0 };
8470 unsigned char *network
;
8472 struct ipv6hdr
*ipv6
;
8476 struct sk_buff
*skb
;
8480 /* if ring doesn't have a interrupt vector, cannot perform ATR */
8484 /* do nothing if sampling is disabled */
8485 if (!ring
->atr_sample_rate
)
8490 /* currently only IPv4/IPv6 with TCP is supported */
8491 if ((first
->protocol
!= htons(ETH_P_IP
)) &&
8492 (first
->protocol
!= htons(ETH_P_IPV6
)))
8495 /* snag network header to get L4 type and address */
8497 hdr
.network
= skb_network_header(skb
);
8498 if (unlikely(hdr
.network
<= skb
->data
))
8500 if (skb
->encapsulation
&&
8501 first
->protocol
== htons(ETH_P_IP
) &&
8502 hdr
.ipv4
->protocol
== IPPROTO_UDP
) {
8503 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
8505 if (unlikely(skb_tail_pointer(skb
) < hdr
.network
+
8509 /* verify the port is recognized as VXLAN */
8510 if (adapter
->vxlan_port
&&
8511 udp_hdr(skb
)->dest
== adapter
->vxlan_port
)
8512 hdr
.network
= skb_inner_network_header(skb
);
8514 if (adapter
->geneve_port
&&
8515 udp_hdr(skb
)->dest
== adapter
->geneve_port
)
8516 hdr
.network
= skb_inner_network_header(skb
);
8519 /* Make sure we have at least [minimum IPv4 header + TCP]
8520 * or [IPv6 header] bytes
8522 if (unlikely(skb_tail_pointer(skb
) < hdr
.network
+ 40))
8525 /* Currently only IPv4/IPv6 with TCP is supported */
8526 switch (hdr
.ipv4
->version
) {
8528 /* access ihl as u8 to avoid unaligned access on ia64 */
8529 hlen
= (hdr
.network
[0] & 0x0F) << 2;
8530 l4_proto
= hdr
.ipv4
->protocol
;
8533 hlen
= hdr
.network
- skb
->data
;
8534 l4_proto
= ipv6_find_hdr(skb
, &hlen
, IPPROTO_TCP
, NULL
, NULL
);
8535 hlen
-= hdr
.network
- skb
->data
;
8541 if (l4_proto
!= IPPROTO_TCP
)
8544 if (unlikely(skb_tail_pointer(skb
) < hdr
.network
+
8545 hlen
+ sizeof(struct tcphdr
)))
8548 th
= (struct tcphdr
*)(hdr
.network
+ hlen
);
8550 /* skip this packet since the socket is closing */
8554 /* sample on all syn packets or once every atr sample count */
8555 if (!th
->syn
&& (ring
->atr_count
< ring
->atr_sample_rate
))
8558 /* reset sample count */
8559 ring
->atr_count
= 0;
8561 vlan_id
= htons(first
->tx_flags
>> IXGBE_TX_FLAGS_VLAN_SHIFT
);
8564 * src and dst are inverted, think how the receiver sees them
8566 * The input is broken into two sections, a non-compressed section
8567 * containing vm_pool, vlan_id, and flow_type. The rest of the data
8568 * is XORed together and stored in the compressed dword.
8570 input
.formatted
.vlan_id
= vlan_id
;
8573 * since src port and flex bytes occupy the same word XOR them together
8574 * and write the value to source port portion of compressed dword
8576 if (first
->tx_flags
& (IXGBE_TX_FLAGS_SW_VLAN
| IXGBE_TX_FLAGS_HW_VLAN
))
8577 common
.port
.src
^= th
->dest
^ htons(ETH_P_8021Q
);
8579 common
.port
.src
^= th
->dest
^ first
->protocol
;
8580 common
.port
.dst
^= th
->source
;
8582 switch (hdr
.ipv4
->version
) {
8584 input
.formatted
.flow_type
= IXGBE_ATR_FLOW_TYPE_TCPV4
;
8585 common
.ip
^= hdr
.ipv4
->saddr
^ hdr
.ipv4
->daddr
;
8588 input
.formatted
.flow_type
= IXGBE_ATR_FLOW_TYPE_TCPV6
;
8589 common
.ip
^= hdr
.ipv6
->saddr
.s6_addr32
[0] ^
8590 hdr
.ipv6
->saddr
.s6_addr32
[1] ^
8591 hdr
.ipv6
->saddr
.s6_addr32
[2] ^
8592 hdr
.ipv6
->saddr
.s6_addr32
[3] ^
8593 hdr
.ipv6
->daddr
.s6_addr32
[0] ^
8594 hdr
.ipv6
->daddr
.s6_addr32
[1] ^
8595 hdr
.ipv6
->daddr
.s6_addr32
[2] ^
8596 hdr
.ipv6
->daddr
.s6_addr32
[3];
8602 if (hdr
.network
!= skb_network_header(skb
))
8603 input
.formatted
.flow_type
|= IXGBE_ATR_L4TYPE_TUNNEL_MASK
;
8605 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
8606 ixgbe_fdir_add_signature_filter_82599(&q_vector
->adapter
->hw
,
8607 input
, common
, ring
->queue_index
);
8611 static u16
ixgbe_select_queue(struct net_device
*dev
, struct sk_buff
*skb
,
8612 struct net_device
*sb_dev
)
8614 struct ixgbe_adapter
*adapter
;
8615 struct ixgbe_ring_feature
*f
;
8619 u8 tc
= netdev_get_prio_tc_map(dev
, skb
->priority
);
8620 struct net_device
*vdev
= sb_dev
;
8622 txq
= vdev
->tc_to_txq
[tc
].offset
;
8623 txq
+= reciprocal_scale(skb_get_hash(skb
),
8624 vdev
->tc_to_txq
[tc
].count
);
8630 * only execute the code below if protocol is FCoE
8631 * or FIP and we have FCoE enabled on the adapter
8633 switch (vlan_get_protocol(skb
)) {
8634 case htons(ETH_P_FCOE
):
8635 case htons(ETH_P_FIP
):
8636 adapter
= netdev_priv(dev
);
8638 if (!sb_dev
&& (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
))
8642 return netdev_pick_tx(dev
, skb
, sb_dev
);
8645 f
= &adapter
->ring_feature
[RING_F_FCOE
];
8647 txq
= skb_rx_queue_recorded(skb
) ? skb_get_rx_queue(skb
) :
8650 while (txq
>= f
->indices
)
8653 return txq
+ f
->offset
;
8657 int ixgbe_xmit_xdp_ring(struct ixgbe_ring
*ring
,
8658 struct xdp_frame
*xdpf
)
8660 struct skb_shared_info
*sinfo
= xdp_get_shared_info_from_frame(xdpf
);
8661 u8 nr_frags
= unlikely(xdp_frame_has_frags(xdpf
)) ? sinfo
->nr_frags
: 0;
8662 u16 i
= 0, index
= ring
->next_to_use
;
8663 struct ixgbe_tx_buffer
*tx_head
= &ring
->tx_buffer_info
[index
];
8664 struct ixgbe_tx_buffer
*tx_buff
= tx_head
;
8665 union ixgbe_adv_tx_desc
*tx_desc
= IXGBE_TX_DESC(ring
, index
);
8666 u32 cmd_type
, len
= xdpf
->len
;
8667 void *data
= xdpf
->data
;
8669 if (unlikely(ixgbe_desc_unused(ring
) < 1 + nr_frags
))
8670 return IXGBE_XDP_CONSUMED
;
8672 tx_head
->bytecount
= xdp_get_frame_len(xdpf
);
8673 tx_head
->gso_segs
= 1;
8674 tx_head
->xdpf
= xdpf
;
8676 tx_desc
->read
.olinfo_status
=
8677 cpu_to_le32(tx_head
->bytecount
<< IXGBE_ADVTXD_PAYLEN_SHIFT
);
8682 dma
= dma_map_single(ring
->dev
, data
, len
, DMA_TO_DEVICE
);
8683 if (dma_mapping_error(ring
->dev
, dma
))
8686 dma_unmap_len_set(tx_buff
, len
, len
);
8687 dma_unmap_addr_set(tx_buff
, dma
, dma
);
8689 cmd_type
= IXGBE_ADVTXD_DTYP_DATA
| IXGBE_ADVTXD_DCMD_DEXT
|
8690 IXGBE_ADVTXD_DCMD_IFCS
| len
;
8691 tx_desc
->read
.cmd_type_len
= cpu_to_le32(cmd_type
);
8692 tx_desc
->read
.buffer_addr
= cpu_to_le64(dma
);
8693 tx_buff
->protocol
= 0;
8695 if (++index
== ring
->count
)
8701 tx_buff
= &ring
->tx_buffer_info
[index
];
8702 tx_desc
= IXGBE_TX_DESC(ring
, index
);
8703 tx_desc
->read
.olinfo_status
= 0;
8705 data
= skb_frag_address(&sinfo
->frags
[i
]);
8706 len
= skb_frag_size(&sinfo
->frags
[i
]);
8709 /* put descriptor type bits */
8710 tx_desc
->read
.cmd_type_len
|= cpu_to_le32(IXGBE_TXD_CMD
);
8712 /* Avoid any potential race with xdp_xmit and cleanup */
8715 tx_head
->next_to_watch
= tx_desc
;
8716 ring
->next_to_use
= index
;
8718 return IXGBE_XDP_TX
;
8722 tx_buff
= &ring
->tx_buffer_info
[index
];
8723 if (dma_unmap_len(tx_buff
, len
))
8724 dma_unmap_page(ring
->dev
, dma_unmap_addr(tx_buff
, dma
),
8725 dma_unmap_len(tx_buff
, len
),
8727 dma_unmap_len_set(tx_buff
, len
, 0);
8728 if (tx_buff
== tx_head
)
8732 index
+= ring
->count
;
8736 return IXGBE_XDP_CONSUMED
;
8739 netdev_tx_t
ixgbe_xmit_frame_ring(struct sk_buff
*skb
,
8740 struct ixgbe_adapter
*adapter
,
8741 struct ixgbe_ring
*tx_ring
)
8743 struct ixgbe_tx_buffer
*first
;
8747 u16 count
= TXD_USE_COUNT(skb_headlen(skb
));
8748 struct ixgbe_ipsec_tx_data ipsec_tx
= { 0 };
8749 __be16 protocol
= skb
->protocol
;
8753 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
8754 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
8755 * + 2 desc gap to keep tail from touching head,
8756 * + 1 desc for context descriptor,
8757 * otherwise try next time
8759 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++)
8760 count
+= TXD_USE_COUNT(skb_frag_size(
8761 &skb_shinfo(skb
)->frags
[f
]));
8763 if (ixgbe_maybe_stop_tx(tx_ring
, count
+ 3)) {
8764 tx_ring
->tx_stats
.tx_busy
++;
8765 return NETDEV_TX_BUSY
;
8768 /* record the location of the first descriptor for this packet */
8769 first
= &tx_ring
->tx_buffer_info
[tx_ring
->next_to_use
];
8771 first
->bytecount
= skb
->len
;
8772 first
->gso_segs
= 1;
8774 /* if we have a HW VLAN tag being added default to the HW one */
8775 if (skb_vlan_tag_present(skb
)) {
8776 tx_flags
|= skb_vlan_tag_get(skb
) << IXGBE_TX_FLAGS_VLAN_SHIFT
;
8777 tx_flags
|= IXGBE_TX_FLAGS_HW_VLAN
;
8778 /* else if it is a SW VLAN check the next protocol and store the tag */
8779 } else if (protocol
== htons(ETH_P_8021Q
)) {
8780 struct vlan_hdr
*vhdr
, _vhdr
;
8781 vhdr
= skb_header_pointer(skb
, ETH_HLEN
, sizeof(_vhdr
), &_vhdr
);
8785 tx_flags
|= ntohs(vhdr
->h_vlan_TCI
) <<
8786 IXGBE_TX_FLAGS_VLAN_SHIFT
;
8787 tx_flags
|= IXGBE_TX_FLAGS_SW_VLAN
;
8789 protocol
= vlan_get_protocol(skb
);
8791 if (unlikely(skb_shinfo(skb
)->tx_flags
& SKBTX_HW_TSTAMP
) &&
8792 adapter
->ptp_clock
) {
8793 if (adapter
->tstamp_config
.tx_type
== HWTSTAMP_TX_ON
&&
8794 !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS
,
8796 skb_shinfo(skb
)->tx_flags
|= SKBTX_IN_PROGRESS
;
8797 tx_flags
|= IXGBE_TX_FLAGS_TSTAMP
;
8799 /* schedule check for Tx timestamp */
8800 adapter
->ptp_tx_skb
= skb_get(skb
);
8801 adapter
->ptp_tx_start
= jiffies
;
8802 schedule_work(&adapter
->ptp_tx_work
);
8804 adapter
->tx_hwtstamp_skipped
++;
8808 #ifdef CONFIG_PCI_IOV
8810 * Use the l2switch_enable flag - would be false if the DMA
8811 * Tx switch had been disabled.
8813 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
8814 tx_flags
|= IXGBE_TX_FLAGS_CC
;
8817 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
8818 if ((adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) &&
8819 ((tx_flags
& (IXGBE_TX_FLAGS_HW_VLAN
| IXGBE_TX_FLAGS_SW_VLAN
)) ||
8820 (skb
->priority
!= TC_PRIO_CONTROL
))) {
8821 tx_flags
&= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK
;
8822 tx_flags
|= (skb
->priority
& 0x7) <<
8823 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT
;
8824 if (tx_flags
& IXGBE_TX_FLAGS_SW_VLAN
) {
8825 struct vlan_ethhdr
*vhdr
;
8827 if (skb_cow_head(skb
, 0))
8829 vhdr
= skb_vlan_eth_hdr(skb
);
8830 vhdr
->h_vlan_TCI
= htons(tx_flags
>>
8831 IXGBE_TX_FLAGS_VLAN_SHIFT
);
8833 tx_flags
|= IXGBE_TX_FLAGS_HW_VLAN
;
8837 /* record initial flags and protocol */
8838 first
->tx_flags
= tx_flags
;
8839 first
->protocol
= protocol
;
8842 /* setup tx offload for FCoE */
8843 if ((protocol
== htons(ETH_P_FCOE
)) &&
8844 (tx_ring
->netdev
->features
& (NETIF_F_FSO
| NETIF_F_FCOE_CRC
))) {
8845 tso
= ixgbe_fso(tx_ring
, first
, &hdr_len
);
8852 #endif /* IXGBE_FCOE */
8854 #ifdef CONFIG_IXGBE_IPSEC
8855 if (xfrm_offload(skb
) &&
8856 !ixgbe_ipsec_tx(tx_ring
, first
, &ipsec_tx
))
8859 tso
= ixgbe_tso(tx_ring
, first
, &hdr_len
, &ipsec_tx
);
8863 ixgbe_tx_csum(tx_ring
, first
, &ipsec_tx
);
8865 /* add the ATR filter if ATR is on */
8866 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE
, &tx_ring
->state
))
8867 ixgbe_atr(tx_ring
, first
);
8871 #endif /* IXGBE_FCOE */
8872 if (ixgbe_tx_map(tx_ring
, first
, hdr_len
))
8873 goto cleanup_tx_timestamp
;
8875 return NETDEV_TX_OK
;
8878 dev_kfree_skb_any(first
->skb
);
8880 cleanup_tx_timestamp
:
8881 if (unlikely(tx_flags
& IXGBE_TX_FLAGS_TSTAMP
)) {
8882 dev_kfree_skb_any(adapter
->ptp_tx_skb
);
8883 adapter
->ptp_tx_skb
= NULL
;
8884 cancel_work_sync(&adapter
->ptp_tx_work
);
8885 clear_bit_unlock(__IXGBE_PTP_TX_IN_PROGRESS
, &adapter
->state
);
8888 return NETDEV_TX_OK
;
8891 static netdev_tx_t
__ixgbe_xmit_frame(struct sk_buff
*skb
,
8892 struct net_device
*netdev
,
8893 struct ixgbe_ring
*ring
)
8895 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
8896 struct ixgbe_ring
*tx_ring
;
8899 * The minimum packet size for olinfo paylen is 17 so pad the skb
8900 * in order to meet this minimum size requirement.
8902 if (skb_put_padto(skb
, 17))
8903 return NETDEV_TX_OK
;
8905 tx_ring
= ring
? ring
: adapter
->tx_ring
[skb_get_queue_mapping(skb
)];
8906 if (unlikely(test_bit(__IXGBE_TX_DISABLED
, &tx_ring
->state
)))
8907 return NETDEV_TX_BUSY
;
8909 return ixgbe_xmit_frame_ring(skb
, adapter
, tx_ring
);
8912 static netdev_tx_t
ixgbe_xmit_frame(struct sk_buff
*skb
,
8913 struct net_device
*netdev
)
8915 return __ixgbe_xmit_frame(skb
, netdev
, NULL
);
8919 * ixgbe_set_mac - Change the Ethernet Address of the NIC
8920 * @netdev: network interface device structure
8921 * @p: pointer to an address structure
8923 * Returns 0 on success, negative on failure
8925 static int ixgbe_set_mac(struct net_device
*netdev
, void *p
)
8927 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
8928 struct ixgbe_hw
*hw
= &adapter
->hw
;
8929 struct sockaddr
*addr
= p
;
8931 if (!is_valid_ether_addr(addr
->sa_data
))
8932 return -EADDRNOTAVAIL
;
8934 eth_hw_addr_set(netdev
, addr
->sa_data
);
8935 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
8937 ixgbe_mac_set_default_filter(adapter
);
8943 ixgbe_mdio_read(struct net_device
*netdev
, int prtad
, int devad
, u16 addr
)
8945 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
8946 struct ixgbe_hw
*hw
= &adapter
->hw
;
8950 if (adapter
->mii_bus
) {
8953 if (devad
!= MDIO_DEVAD_NONE
)
8954 return mdiobus_c45_read(adapter
->mii_bus
, prtad
,
8957 return mdiobus_read(adapter
->mii_bus
, prtad
, regnum
);
8960 if (prtad
!= hw
->phy
.mdio
.prtad
)
8962 rc
= hw
->phy
.ops
.read_reg(hw
, addr
, devad
, &value
);
8968 static int ixgbe_mdio_write(struct net_device
*netdev
, int prtad
, int devad
,
8969 u16 addr
, u16 value
)
8971 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
8972 struct ixgbe_hw
*hw
= &adapter
->hw
;
8974 if (adapter
->mii_bus
) {
8977 if (devad
!= MDIO_DEVAD_NONE
)
8978 return mdiobus_c45_write(adapter
->mii_bus
, prtad
, devad
,
8981 return mdiobus_write(adapter
->mii_bus
, prtad
, regnum
, value
);
8984 if (prtad
!= hw
->phy
.mdio
.prtad
)
8986 return hw
->phy
.ops
.write_reg(hw
, addr
, devad
, value
);
8989 static int ixgbe_ioctl(struct net_device
*netdev
, struct ifreq
*req
, int cmd
)
8991 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
8995 return ixgbe_ptp_set_ts_config(adapter
, req
);
8997 return ixgbe_ptp_get_ts_config(adapter
, req
);
8999 if (!adapter
->hw
.phy
.ops
.read_reg
)
9003 return mdio_mii_ioctl(&adapter
->hw
.phy
.mdio
, if_mii(req
), cmd
);
9008 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
9010 * @dev: network interface device structure
9012 * Returns non-zero on failure
9014 static int ixgbe_add_sanmac_netdev(struct net_device
*dev
)
9017 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
9018 struct ixgbe_hw
*hw
= &adapter
->hw
;
9020 if (is_valid_ether_addr(hw
->mac
.san_addr
)) {
9022 err
= dev_addr_add(dev
, hw
->mac
.san_addr
, NETDEV_HW_ADDR_T_SAN
);
9025 /* update SAN MAC vmdq pool selection */
9026 hw
->mac
.ops
.set_vmdq_san_mac(hw
, VMDQ_P(0));
9032 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
9034 * @dev: network interface device structure
9036 * Returns non-zero on failure
9038 static int ixgbe_del_sanmac_netdev(struct net_device
*dev
)
9041 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
9042 struct ixgbe_mac_info
*mac
= &adapter
->hw
.mac
;
9044 if (is_valid_ether_addr(mac
->san_addr
)) {
9046 err
= dev_addr_del(dev
, mac
->san_addr
, NETDEV_HW_ADDR_T_SAN
);
9052 static void ixgbe_get_ring_stats64(struct rtnl_link_stats64
*stats
,
9053 struct ixgbe_ring
*ring
)
9060 start
= u64_stats_fetch_begin(&ring
->syncp
);
9061 packets
= ring
->stats
.packets
;
9062 bytes
= ring
->stats
.bytes
;
9063 } while (u64_stats_fetch_retry(&ring
->syncp
, start
));
9064 stats
->tx_packets
+= packets
;
9065 stats
->tx_bytes
+= bytes
;
9069 static void ixgbe_get_stats64(struct net_device
*netdev
,
9070 struct rtnl_link_stats64
*stats
)
9072 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
9076 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
9077 struct ixgbe_ring
*ring
= READ_ONCE(adapter
->rx_ring
[i
]);
9083 start
= u64_stats_fetch_begin(&ring
->syncp
);
9084 packets
= ring
->stats
.packets
;
9085 bytes
= ring
->stats
.bytes
;
9086 } while (u64_stats_fetch_retry(&ring
->syncp
, start
));
9087 stats
->rx_packets
+= packets
;
9088 stats
->rx_bytes
+= bytes
;
9092 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
9093 struct ixgbe_ring
*ring
= READ_ONCE(adapter
->tx_ring
[i
]);
9095 ixgbe_get_ring_stats64(stats
, ring
);
9097 for (i
= 0; i
< adapter
->num_xdp_queues
; i
++) {
9098 struct ixgbe_ring
*ring
= READ_ONCE(adapter
->xdp_ring
[i
]);
9100 ixgbe_get_ring_stats64(stats
, ring
);
9104 /* following stats updated by ixgbe_watchdog_task() */
9105 stats
->multicast
= netdev
->stats
.multicast
;
9106 stats
->rx_errors
= netdev
->stats
.rx_errors
;
9107 stats
->rx_length_errors
= netdev
->stats
.rx_length_errors
;
9108 stats
->rx_crc_errors
= netdev
->stats
.rx_crc_errors
;
9109 stats
->rx_missed_errors
= netdev
->stats
.rx_missed_errors
;
9112 static int ixgbe_ndo_get_vf_stats(struct net_device
*netdev
, int vf
,
9113 struct ifla_vf_stats
*vf_stats
)
9115 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
9117 if (vf
< 0 || vf
>= adapter
->num_vfs
)
9120 vf_stats
->rx_packets
= adapter
->vfinfo
[vf
].vfstats
.gprc
;
9121 vf_stats
->rx_bytes
= adapter
->vfinfo
[vf
].vfstats
.gorc
;
9122 vf_stats
->tx_packets
= adapter
->vfinfo
[vf
].vfstats
.gptc
;
9123 vf_stats
->tx_bytes
= adapter
->vfinfo
[vf
].vfstats
.gotc
;
9124 vf_stats
->multicast
= adapter
->vfinfo
[vf
].vfstats
.mprc
;
9129 #ifdef CONFIG_IXGBE_DCB
9131 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
9132 * @adapter: pointer to ixgbe_adapter
9133 * @tc: number of traffic classes currently enabled
9135 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
9136 * 802.1Q priority maps to a packet buffer that exists.
9138 static void ixgbe_validate_rtr(struct ixgbe_adapter
*adapter
, u8 tc
)
9140 struct ixgbe_hw
*hw
= &adapter
->hw
;
9144 /* 82598 have a static priority to TC mapping that can not
9145 * be changed so no validation is needed.
9147 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
9150 reg
= IXGBE_READ_REG(hw
, IXGBE_RTRUP2TC
);
9153 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
9154 u8 up2tc
= reg
>> (i
* IXGBE_RTRUP2TC_UP_SHIFT
);
9156 /* If up2tc is out of bounds default to zero */
9158 reg
&= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT
);
9162 IXGBE_WRITE_REG(hw
, IXGBE_RTRUP2TC
, reg
);
9168 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
9169 * @adapter: Pointer to adapter struct
9171 * Populate the netdev user priority to tc map
9173 static void ixgbe_set_prio_tc_map(struct ixgbe_adapter
*adapter
)
9175 struct net_device
*dev
= adapter
->netdev
;
9176 struct ixgbe_dcb_config
*dcb_cfg
= &adapter
->dcb_cfg
;
9177 struct ieee_ets
*ets
= adapter
->ixgbe_ieee_ets
;
9180 for (prio
= 0; prio
< MAX_USER_PRIORITY
; prio
++) {
9183 if (adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
)
9184 tc
= ixgbe_dcb_get_tc_from_up(dcb_cfg
, 0, prio
);
9186 tc
= ets
->prio_tc
[prio
];
9188 netdev_set_prio_tc_map(dev
, prio
, tc
);
9192 #endif /* CONFIG_IXGBE_DCB */
9193 static int ixgbe_reassign_macvlan_pool(struct net_device
*vdev
,
9194 struct netdev_nested_priv
*priv
)
9196 struct ixgbe_adapter
*adapter
= (struct ixgbe_adapter
*)priv
->data
;
9197 struct ixgbe_fwd_adapter
*accel
;
9200 /* we only care about macvlans... */
9201 if (!netif_is_macvlan(vdev
))
9204 /* that have hardware offload enabled... */
9205 accel
= macvlan_accel_priv(vdev
);
9209 /* If we can relocate to a different bit do so */
9210 pool
= find_first_zero_bit(adapter
->fwd_bitmask
, adapter
->num_rx_pools
);
9211 if (pool
< adapter
->num_rx_pools
) {
9212 set_bit(pool
, adapter
->fwd_bitmask
);
9217 /* if we cannot find a free pool then disable the offload */
9218 netdev_err(vdev
, "L2FW offload disabled due to lack of queue resources\n");
9219 macvlan_release_l2fw_offload(vdev
);
9221 /* unbind the queues and drop the subordinate channel config */
9222 netdev_unbind_sb_channel(adapter
->netdev
, vdev
);
9223 netdev_set_sb_channel(vdev
, 0);
9230 static void ixgbe_defrag_macvlan_pools(struct net_device
*dev
)
9232 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
9233 struct netdev_nested_priv priv
= {
9234 .data
= (void *)adapter
,
9237 /* flush any stale bits out of the fwd bitmask */
9238 bitmap_clear(adapter
->fwd_bitmask
, 1, 63);
9240 /* walk through upper devices reassigning pools */
9241 netdev_walk_all_upper_dev_rcu(dev
, ixgbe_reassign_macvlan_pool
,
9246 * ixgbe_setup_tc - configure net_device for multiple traffic classes
9248 * @dev: net device to configure
9249 * @tc: number of traffic classes to enable
9251 int ixgbe_setup_tc(struct net_device
*dev
, u8 tc
)
9253 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
9254 struct ixgbe_hw
*hw
= &adapter
->hw
;
9256 /* Hardware supports up to 8 traffic classes */
9257 if (tc
> adapter
->dcb_cfg
.num_tcs
.pg_tcs
)
9260 if (hw
->mac
.type
== ixgbe_mac_82598EB
&& tc
&& tc
< MAX_TRAFFIC_CLASS
)
9263 /* Hardware has to reinitialize queues and interrupts to
9264 * match packet buffer alignment. Unfortunately, the
9265 * hardware is not flexible enough to do this dynamically.
9267 if (netif_running(dev
))
9270 ixgbe_reset(adapter
);
9272 ixgbe_clear_interrupt_scheme(adapter
);
9274 #ifdef CONFIG_IXGBE_DCB
9276 if (adapter
->xdp_prog
) {
9277 e_warn(probe
, "DCB is not supported with XDP\n");
9279 ixgbe_init_interrupt_scheme(adapter
);
9280 if (netif_running(dev
))
9285 netdev_set_num_tc(dev
, tc
);
9286 ixgbe_set_prio_tc_map(adapter
);
9288 adapter
->hw_tcs
= tc
;
9289 adapter
->flags
|= IXGBE_FLAG_DCB_ENABLED
;
9291 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
9292 adapter
->last_lfc_mode
= adapter
->hw
.fc
.requested_mode
;
9293 adapter
->hw
.fc
.requested_mode
= ixgbe_fc_none
;
9296 netdev_reset_tc(dev
);
9298 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
9299 adapter
->hw
.fc
.requested_mode
= adapter
->last_lfc_mode
;
9301 adapter
->flags
&= ~IXGBE_FLAG_DCB_ENABLED
;
9302 adapter
->hw_tcs
= tc
;
9304 adapter
->temp_dcb_cfg
.pfc_mode_enable
= false;
9305 adapter
->dcb_cfg
.pfc_mode_enable
= false;
9308 ixgbe_validate_rtr(adapter
, tc
);
9310 #endif /* CONFIG_IXGBE_DCB */
9311 ixgbe_init_interrupt_scheme(adapter
);
9313 ixgbe_defrag_macvlan_pools(dev
);
9315 if (netif_running(dev
))
9316 return ixgbe_open(dev
);
9321 static int ixgbe_delete_clsu32(struct ixgbe_adapter
*adapter
,
9322 struct tc_cls_u32_offload
*cls
)
9324 u32 hdl
= cls
->knode
.handle
;
9325 u32 uhtid
= TC_U32_USERHTID(cls
->knode
.handle
);
9326 u32 loc
= cls
->knode
.handle
& 0xfffff;
9328 struct ixgbe_jump_table
*jump
= NULL
;
9330 if (loc
> IXGBE_MAX_HW_ENTRIES
)
9333 if ((uhtid
!= 0x800) && (uhtid
>= IXGBE_MAX_LINK_HANDLE
))
9336 /* Clear this filter in the link data it is associated with */
9337 if (uhtid
!= 0x800) {
9338 jump
= adapter
->jump_tables
[uhtid
];
9341 if (!test_bit(loc
- 1, jump
->child_loc_map
))
9343 clear_bit(loc
- 1, jump
->child_loc_map
);
9346 /* Check if the filter being deleted is a link */
9347 for (i
= 1; i
< IXGBE_MAX_LINK_HANDLE
; i
++) {
9348 jump
= adapter
->jump_tables
[i
];
9349 if (jump
&& jump
->link_hdl
== hdl
) {
9350 /* Delete filters in the hardware in the child hash
9351 * table associated with this link
9353 for (j
= 0; j
< IXGBE_MAX_HW_ENTRIES
; j
++) {
9354 if (!test_bit(j
, jump
->child_loc_map
))
9356 spin_lock(&adapter
->fdir_perfect_lock
);
9357 err
= ixgbe_update_ethtool_fdir_entry(adapter
,
9360 spin_unlock(&adapter
->fdir_perfect_lock
);
9361 clear_bit(j
, jump
->child_loc_map
);
9363 /* Remove resources for this link */
9367 adapter
->jump_tables
[i
] = NULL
;
9372 spin_lock(&adapter
->fdir_perfect_lock
);
9373 err
= ixgbe_update_ethtool_fdir_entry(adapter
, NULL
, loc
);
9374 spin_unlock(&adapter
->fdir_perfect_lock
);
9378 static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter
*adapter
,
9379 struct tc_cls_u32_offload
*cls
)
9381 u32 uhtid
= TC_U32_USERHTID(cls
->hnode
.handle
);
9383 if (uhtid
>= IXGBE_MAX_LINK_HANDLE
)
9386 /* This ixgbe devices do not support hash tables at the moment
9387 * so abort when given hash tables.
9389 if (cls
->hnode
.divisor
> 0)
9392 set_bit(uhtid
- 1, &adapter
->tables
);
9396 static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter
*adapter
,
9397 struct tc_cls_u32_offload
*cls
)
9399 u32 uhtid
= TC_U32_USERHTID(cls
->hnode
.handle
);
9401 if (uhtid
>= IXGBE_MAX_LINK_HANDLE
)
9404 clear_bit(uhtid
- 1, &adapter
->tables
);
9408 #ifdef CONFIG_NET_CLS_ACT
9409 struct upper_walk_data
{
9410 struct ixgbe_adapter
*adapter
;
9416 static int get_macvlan_queue(struct net_device
*upper
,
9417 struct netdev_nested_priv
*priv
)
9419 if (netif_is_macvlan(upper
)) {
9420 struct ixgbe_fwd_adapter
*vadapter
= macvlan_accel_priv(upper
);
9421 struct ixgbe_adapter
*adapter
;
9422 struct upper_walk_data
*data
;
9425 data
= (struct upper_walk_data
*)priv
->data
;
9426 ifindex
= data
->ifindex
;
9427 adapter
= data
->adapter
;
9428 if (vadapter
&& upper
->ifindex
== ifindex
) {
9429 data
->queue
= adapter
->rx_ring
[vadapter
->rx_base_queue
]->reg_idx
;
9430 data
->action
= data
->queue
;
9438 static int handle_redirect_action(struct ixgbe_adapter
*adapter
, int ifindex
,
9439 u8
*queue
, u64
*action
)
9441 struct ixgbe_ring_feature
*vmdq
= &adapter
->ring_feature
[RING_F_VMDQ
];
9442 unsigned int num_vfs
= adapter
->num_vfs
, vf
;
9443 struct netdev_nested_priv priv
;
9444 struct upper_walk_data data
;
9445 struct net_device
*upper
;
9447 /* redirect to a SRIOV VF */
9448 for (vf
= 0; vf
< num_vfs
; ++vf
) {
9449 upper
= pci_get_drvdata(adapter
->vfinfo
[vf
].vfdev
);
9450 if (upper
->ifindex
== ifindex
) {
9451 *queue
= vf
* __ALIGN_MASK(1, ~vmdq
->mask
);
9453 *action
<<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF
;
9458 /* redirect to a offloaded macvlan netdev */
9459 data
.adapter
= adapter
;
9460 data
.ifindex
= ifindex
;
9463 priv
.data
= (void *)&data
;
9464 if (netdev_walk_all_upper_dev_rcu(adapter
->netdev
,
9465 get_macvlan_queue
, &priv
)) {
9466 *action
= data
.action
;
9467 *queue
= data
.queue
;
9475 static int parse_tc_actions(struct ixgbe_adapter
*adapter
,
9476 struct tcf_exts
*exts
, u64
*action
, u8
*queue
)
9478 const struct tc_action
*a
;
9481 if (!tcf_exts_has_actions(exts
))
9484 tcf_exts_for_each_action(i
, a
, exts
) {
9486 if (is_tcf_gact_shot(a
)) {
9487 *action
= IXGBE_FDIR_DROP_QUEUE
;
9488 *queue
= IXGBE_FDIR_DROP_QUEUE
;
9492 /* Redirect to a VF or a offloaded macvlan */
9493 if (is_tcf_mirred_egress_redirect(a
)) {
9494 struct net_device
*dev
= tcf_mirred_dev(a
);
9498 return handle_redirect_action(adapter
, dev
->ifindex
,
9508 static int parse_tc_actions(struct ixgbe_adapter
*adapter
,
9509 struct tcf_exts
*exts
, u64
*action
, u8
*queue
)
9513 #endif /* CONFIG_NET_CLS_ACT */
9515 static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter
*input
,
9516 union ixgbe_atr_input
*mask
,
9517 struct tc_cls_u32_offload
*cls
,
9518 struct ixgbe_mat_field
*field_ptr
,
9519 struct ixgbe_nexthdr
*nexthdr
)
9523 bool found_entry
= false, found_jump_field
= false;
9525 for (i
= 0; i
< cls
->knode
.sel
->nkeys
; i
++) {
9526 off
= cls
->knode
.sel
->keys
[i
].off
;
9527 val
= cls
->knode
.sel
->keys
[i
].val
;
9528 m
= cls
->knode
.sel
->keys
[i
].mask
;
9530 for (j
= 0; field_ptr
[j
].val
; j
++) {
9531 if (field_ptr
[j
].off
== off
) {
9532 field_ptr
[j
].val(input
, mask
, (__force u32
)val
,
9534 input
->filter
.formatted
.flow_type
|=
9541 if (nexthdr
->off
== cls
->knode
.sel
->keys
[i
].off
&&
9543 (__force u32
)cls
->knode
.sel
->keys
[i
].val
&&
9545 (__force u32
)cls
->knode
.sel
->keys
[i
].mask
)
9546 found_jump_field
= true;
9552 if (nexthdr
&& !found_jump_field
)
9558 mask
->formatted
.flow_type
= IXGBE_ATR_L4TYPE_IPV6_MASK
|
9559 IXGBE_ATR_L4TYPE_MASK
;
9561 if (input
->filter
.formatted
.flow_type
== IXGBE_ATR_FLOW_TYPE_IPV4
)
9562 mask
->formatted
.flow_type
&= IXGBE_ATR_L4TYPE_IPV6_MASK
;
9567 static int ixgbe_configure_clsu32(struct ixgbe_adapter
*adapter
,
9568 struct tc_cls_u32_offload
*cls
)
9570 __be16 protocol
= cls
->common
.protocol
;
9571 u32 loc
= cls
->knode
.handle
& 0xfffff;
9572 struct ixgbe_hw
*hw
= &adapter
->hw
;
9573 struct ixgbe_mat_field
*field_ptr
;
9574 struct ixgbe_fdir_filter
*input
= NULL
;
9575 union ixgbe_atr_input
*mask
= NULL
;
9576 struct ixgbe_jump_table
*jump
= NULL
;
9577 int i
, err
= -EINVAL
;
9579 u32 uhtid
, link_uhtid
;
9581 uhtid
= TC_U32_USERHTID(cls
->knode
.handle
);
9582 link_uhtid
= TC_U32_USERHTID(cls
->knode
.link_handle
);
9584 /* At the moment cls_u32 jumps to network layer and skips past
9585 * L2 headers. The canonical method to match L2 frames is to use
9586 * negative values. However this is error prone at best but really
9587 * just broken because there is no way to "know" what sort of hdr
9588 * is in front of the network layer. Fix cls_u32 to support L2
9589 * headers when needed.
9591 if (protocol
!= htons(ETH_P_IP
))
9594 if (loc
>= ((1024 << adapter
->fdir_pballoc
) - 2)) {
9595 e_err(drv
, "Location out of range\n");
9599 /* cls u32 is a graph starting at root node 0x800. The driver tracks
9600 * links and also the fields used to advance the parser across each
9601 * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
9602 * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
9603 * To add support for new nodes update ixgbe_model.h parse structures
9604 * this function _should_ be generic try not to hardcode values here.
9606 if (uhtid
== 0x800) {
9607 field_ptr
= (adapter
->jump_tables
[0])->mat
;
9609 if (uhtid
>= IXGBE_MAX_LINK_HANDLE
)
9611 if (!adapter
->jump_tables
[uhtid
])
9613 field_ptr
= (adapter
->jump_tables
[uhtid
])->mat
;
9619 /* At this point we know the field_ptr is valid and need to either
9620 * build cls_u32 link or attach filter. Because adding a link to
9621 * a handle that does not exist is invalid and the same for adding
9622 * rules to handles that don't exist.
9626 struct ixgbe_nexthdr
*nexthdr
= ixgbe_ipv4_jumps
;
9628 if (link_uhtid
>= IXGBE_MAX_LINK_HANDLE
)
9631 if (!test_bit(link_uhtid
- 1, &adapter
->tables
))
9634 /* Multiple filters as links to the same hash table are not
9635 * supported. To add a new filter with the same next header
9636 * but different match/jump conditions, create a new hash table
9639 if (adapter
->jump_tables
[link_uhtid
] &&
9640 (adapter
->jump_tables
[link_uhtid
])->link_hdl
) {
9641 e_err(drv
, "Link filter exists for link: %x\n",
9646 for (i
= 0; nexthdr
[i
].jump
; i
++) {
9647 if (nexthdr
[i
].o
!= cls
->knode
.sel
->offoff
||
9648 nexthdr
[i
].s
!= cls
->knode
.sel
->offshift
||
9650 (__force u32
)cls
->knode
.sel
->offmask
)
9653 jump
= kzalloc(sizeof(*jump
), GFP_KERNEL
);
9656 input
= kzalloc(sizeof(*input
), GFP_KERNEL
);
9661 mask
= kzalloc(sizeof(*mask
), GFP_KERNEL
);
9666 jump
->input
= input
;
9668 jump
->link_hdl
= cls
->knode
.handle
;
9670 err
= ixgbe_clsu32_build_input(input
, mask
, cls
,
9671 field_ptr
, &nexthdr
[i
]);
9673 jump
->mat
= nexthdr
[i
].jump
;
9674 adapter
->jump_tables
[link_uhtid
] = jump
;
9685 input
= kzalloc(sizeof(*input
), GFP_KERNEL
);
9688 mask
= kzalloc(sizeof(*mask
), GFP_KERNEL
);
9694 if ((uhtid
!= 0x800) && (adapter
->jump_tables
[uhtid
])) {
9695 if ((adapter
->jump_tables
[uhtid
])->input
)
9696 memcpy(input
, (adapter
->jump_tables
[uhtid
])->input
,
9698 if ((adapter
->jump_tables
[uhtid
])->mask
)
9699 memcpy(mask
, (adapter
->jump_tables
[uhtid
])->mask
,
9702 /* Lookup in all child hash tables if this location is already
9703 * filled with a filter
9705 for (i
= 1; i
< IXGBE_MAX_LINK_HANDLE
; i
++) {
9706 struct ixgbe_jump_table
*link
= adapter
->jump_tables
[i
];
9708 if (link
&& (test_bit(loc
- 1, link
->child_loc_map
))) {
9709 e_err(drv
, "Filter exists in location: %x\n",
9716 err
= ixgbe_clsu32_build_input(input
, mask
, cls
, field_ptr
, NULL
);
9720 err
= parse_tc_actions(adapter
, cls
->knode
.exts
, &input
->action
,
9725 input
->sw_idx
= loc
;
9727 spin_lock(&adapter
->fdir_perfect_lock
);
9729 if (hlist_empty(&adapter
->fdir_filter_list
)) {
9730 memcpy(&adapter
->fdir_mask
, mask
, sizeof(*mask
));
9731 err
= ixgbe_fdir_set_input_mask_82599(hw
, mask
);
9733 goto err_out_w_lock
;
9734 } else if (memcmp(&adapter
->fdir_mask
, mask
, sizeof(*mask
))) {
9736 goto err_out_w_lock
;
9739 ixgbe_atr_compute_perfect_hash_82599(&input
->filter
, mask
);
9740 err
= ixgbe_fdir_write_perfect_filter_82599(hw
, &input
->filter
,
9741 input
->sw_idx
, queue
);
9743 goto err_out_w_lock
;
9745 ixgbe_update_ethtool_fdir_entry(adapter
, input
, input
->sw_idx
);
9746 spin_unlock(&adapter
->fdir_perfect_lock
);
9748 if ((uhtid
!= 0x800) && (adapter
->jump_tables
[uhtid
]))
9749 set_bit(loc
- 1, (adapter
->jump_tables
[uhtid
])->child_loc_map
);
9754 spin_unlock(&adapter
->fdir_perfect_lock
);
9764 static int ixgbe_setup_tc_cls_u32(struct ixgbe_adapter
*adapter
,
9765 struct tc_cls_u32_offload
*cls_u32
)
9767 switch (cls_u32
->command
) {
9768 case TC_CLSU32_NEW_KNODE
:
9769 case TC_CLSU32_REPLACE_KNODE
:
9770 return ixgbe_configure_clsu32(adapter
, cls_u32
);
9771 case TC_CLSU32_DELETE_KNODE
:
9772 return ixgbe_delete_clsu32(adapter
, cls_u32
);
9773 case TC_CLSU32_NEW_HNODE
:
9774 case TC_CLSU32_REPLACE_HNODE
:
9775 return ixgbe_configure_clsu32_add_hnode(adapter
, cls_u32
);
9776 case TC_CLSU32_DELETE_HNODE
:
9777 return ixgbe_configure_clsu32_del_hnode(adapter
, cls_u32
);
9783 static int ixgbe_setup_tc_block_cb(enum tc_setup_type type
, void *type_data
,
9786 struct ixgbe_adapter
*adapter
= cb_priv
;
9788 if (!tc_cls_can_offload_and_chain0(adapter
->netdev
, type_data
))
9792 case TC_SETUP_CLSU32
:
9793 return ixgbe_setup_tc_cls_u32(adapter
, type_data
);
9799 static int ixgbe_setup_tc_mqprio(struct net_device
*dev
,
9800 struct tc_mqprio_qopt
*mqprio
)
9802 mqprio
->hw
= TC_MQPRIO_HW_OFFLOAD_TCS
;
9803 return ixgbe_setup_tc(dev
, mqprio
->num_tc
);
9806 static LIST_HEAD(ixgbe_block_cb_list
);
9808 static int __ixgbe_setup_tc(struct net_device
*dev
, enum tc_setup_type type
,
9811 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
9814 case TC_SETUP_BLOCK
:
9815 return flow_block_cb_setup_simple(type_data
,
9816 &ixgbe_block_cb_list
,
9817 ixgbe_setup_tc_block_cb
,
9818 adapter
, adapter
, true);
9819 case TC_SETUP_QDISC_MQPRIO
:
9820 return ixgbe_setup_tc_mqprio(dev
, type_data
);
9826 #ifdef CONFIG_PCI_IOV
9827 void ixgbe_sriov_reinit(struct ixgbe_adapter
*adapter
)
9829 struct net_device
*netdev
= adapter
->netdev
;
9832 ixgbe_setup_tc(netdev
, adapter
->hw_tcs
);
9837 void ixgbe_do_reset(struct net_device
*netdev
)
9839 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
9841 if (netif_running(netdev
))
9842 ixgbe_reinit_locked(adapter
);
9844 ixgbe_reset(adapter
);
9847 static netdev_features_t
ixgbe_fix_features(struct net_device
*netdev
,
9848 netdev_features_t features
)
9850 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
9852 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
9853 if (!(features
& NETIF_F_RXCSUM
))
9854 features
&= ~NETIF_F_LRO
;
9856 /* Turn off LRO if not RSC capable */
9857 if (!(adapter
->flags2
& IXGBE_FLAG2_RSC_CAPABLE
))
9858 features
&= ~NETIF_F_LRO
;
9860 if (adapter
->xdp_prog
&& (features
& NETIF_F_LRO
)) {
9861 e_dev_err("LRO is not supported with XDP\n");
9862 features
&= ~NETIF_F_LRO
;
9868 static void ixgbe_reset_l2fw_offload(struct ixgbe_adapter
*adapter
)
9870 int rss
= min_t(int, ixgbe_max_rss_indices(adapter
),
9873 /* go back to full RSS if we're not running SR-IOV */
9874 if (!adapter
->ring_feature
[RING_F_VMDQ
].offset
)
9875 adapter
->flags
&= ~(IXGBE_FLAG_VMDQ_ENABLED
|
9876 IXGBE_FLAG_SRIOV_ENABLED
);
9878 adapter
->ring_feature
[RING_F_RSS
].limit
= rss
;
9879 adapter
->ring_feature
[RING_F_VMDQ
].limit
= 1;
9881 ixgbe_setup_tc(adapter
->netdev
, adapter
->hw_tcs
);
9884 static int ixgbe_set_features(struct net_device
*netdev
,
9885 netdev_features_t features
)
9887 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
9888 netdev_features_t changed
= netdev
->features
^ features
;
9889 bool need_reset
= false;
9891 /* Make sure RSC matches LRO, reset if change */
9892 if (!(features
& NETIF_F_LRO
)) {
9893 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)
9895 adapter
->flags2
&= ~IXGBE_FLAG2_RSC_ENABLED
;
9896 } else if ((adapter
->flags2
& IXGBE_FLAG2_RSC_CAPABLE
) &&
9897 !(adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)) {
9898 if (adapter
->rx_itr_setting
== 1 ||
9899 adapter
->rx_itr_setting
> IXGBE_MIN_RSC_ITR
) {
9900 adapter
->flags2
|= IXGBE_FLAG2_RSC_ENABLED
;
9902 } else if ((changed
^ features
) & NETIF_F_LRO
) {
9903 e_info(probe
, "rx-usecs set too low, "
9909 * Check if Flow Director n-tuple support or hw_tc support was
9910 * enabled or disabled. If the state changed, we need to reset.
9912 if ((features
& NETIF_F_NTUPLE
) || (features
& NETIF_F_HW_TC
)) {
9913 /* turn off ATR, enable perfect filters and reset */
9914 if (!(adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
))
9917 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
9918 adapter
->flags
|= IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
9920 /* turn off perfect filters, enable ATR and reset */
9921 if (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
9924 adapter
->flags
&= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
9926 /* We cannot enable ATR if SR-IOV is enabled */
9927 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
||
9928 /* We cannot enable ATR if we have 2 or more tcs */
9929 (adapter
->hw_tcs
> 1) ||
9930 /* We cannot enable ATR if RSS is disabled */
9931 (adapter
->ring_feature
[RING_F_RSS
].limit
<= 1) ||
9932 /* A sample rate of 0 indicates ATR disabled */
9933 (!adapter
->atr_sample_rate
))
9934 ; /* do nothing not supported */
9935 else /* otherwise supported and set the flag */
9936 adapter
->flags
|= IXGBE_FLAG_FDIR_HASH_CAPABLE
;
9939 if (changed
& NETIF_F_RXALL
)
9942 netdev
->features
= features
;
9944 if ((changed
& NETIF_F_HW_L2FW_DOFFLOAD
) && adapter
->num_rx_pools
> 1)
9945 ixgbe_reset_l2fw_offload(adapter
);
9946 else if (need_reset
)
9947 ixgbe_do_reset(netdev
);
9948 else if (changed
& (NETIF_F_HW_VLAN_CTAG_RX
|
9949 NETIF_F_HW_VLAN_CTAG_FILTER
))
9950 ixgbe_set_rx_mode(netdev
);
9955 static int ixgbe_ndo_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
9956 struct net_device
*dev
,
9957 const unsigned char *addr
, u16 vid
,
9958 u16 flags
, bool *notified
,
9959 struct netlink_ext_ack
*extack
)
9961 /* guarantee we can provide a unique filter for the unicast address */
9962 if (is_unicast_ether_addr(addr
) || is_link_local_ether_addr(addr
)) {
9963 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
9964 u16 pool
= VMDQ_P(0);
9966 if (netdev_uc_count(dev
) >= ixgbe_available_rars(adapter
, pool
))
9970 return ndo_dflt_fdb_add(ndm
, tb
, dev
, addr
, vid
, flags
);
9974 * ixgbe_configure_bridge_mode - set various bridge modes
9975 * @adapter: the private structure
9976 * @mode: requested bridge mode
9978 * Configure some settings require for various bridge modes.
9980 static int ixgbe_configure_bridge_mode(struct ixgbe_adapter
*adapter
,
9983 struct ixgbe_hw
*hw
= &adapter
->hw
;
9984 unsigned int p
, num_pools
;
9988 case BRIDGE_MODE_VEPA
:
9989 /* disable Tx loopback, rely on switch hairpin mode */
9990 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_PFDTXGSWC
, 0);
9992 /* must enable Rx switching replication to allow multicast
9993 * packet reception on all VFs, and to enable source address
9996 vmdctl
= IXGBE_READ_REG(hw
, IXGBE_VMD_CTL
);
9997 vmdctl
|= IXGBE_VT_CTL_REPLEN
;
9998 IXGBE_WRITE_REG(hw
, IXGBE_VMD_CTL
, vmdctl
);
10000 /* enable Rx source address pruning. Note, this requires
10001 * replication to be enabled or else it does nothing.
10003 num_pools
= adapter
->num_vfs
+ adapter
->num_rx_pools
;
10004 for (p
= 0; p
< num_pools
; p
++) {
10005 if (hw
->mac
.ops
.set_source_address_pruning
)
10006 hw
->mac
.ops
.set_source_address_pruning(hw
,
10011 case BRIDGE_MODE_VEB
:
10012 /* enable Tx loopback for internal VF/PF communication */
10013 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_PFDTXGSWC
,
10014 IXGBE_PFDTXGSWC_VT_LBEN
);
10016 /* disable Rx switching replication unless we have SR-IOV
10017 * virtual functions
10019 vmdctl
= IXGBE_READ_REG(hw
, IXGBE_VMD_CTL
);
10020 if (!adapter
->num_vfs
)
10021 vmdctl
&= ~IXGBE_VT_CTL_REPLEN
;
10022 IXGBE_WRITE_REG(hw
, IXGBE_VMD_CTL
, vmdctl
);
10024 /* disable Rx source address pruning, since we don't expect to
10025 * be receiving external loopback of our transmitted frames.
10027 num_pools
= adapter
->num_vfs
+ adapter
->num_rx_pools
;
10028 for (p
= 0; p
< num_pools
; p
++) {
10029 if (hw
->mac
.ops
.set_source_address_pruning
)
10030 hw
->mac
.ops
.set_source_address_pruning(hw
,
10039 adapter
->bridge_mode
= mode
;
10041 e_info(drv
, "enabling bridge mode: %s\n",
10042 mode
== BRIDGE_MODE_VEPA
? "VEPA" : "VEB");
10047 static int ixgbe_ndo_bridge_setlink(struct net_device
*dev
,
10048 struct nlmsghdr
*nlh
, u16 flags
,
10049 struct netlink_ext_ack
*extack
)
10051 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
10052 struct nlattr
*attr
, *br_spec
;
10055 if (!(adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
))
10056 return -EOPNOTSUPP
;
10058 br_spec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
10062 nla_for_each_nested_type(attr
, IFLA_BRIDGE_MODE
, br_spec
, rem
) {
10063 __u16 mode
= nla_get_u16(attr
);
10064 int status
= ixgbe_configure_bridge_mode(adapter
, mode
);
10075 static int ixgbe_ndo_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
10076 struct net_device
*dev
,
10077 u32 filter_mask
, int nlflags
)
10079 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
10081 if (!(adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
))
10084 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
,
10085 adapter
->bridge_mode
, 0, 0, nlflags
,
10086 filter_mask
, NULL
);
10089 static void *ixgbe_fwd_add(struct net_device
*pdev
, struct net_device
*vdev
)
10091 struct ixgbe_adapter
*adapter
= netdev_priv(pdev
);
10092 struct ixgbe_fwd_adapter
*accel
;
10093 int tcs
= adapter
->hw_tcs
? : 1;
10096 if (adapter
->xdp_prog
) {
10097 e_warn(probe
, "L2FW offload is not supported with XDP\n");
10098 return ERR_PTR(-EINVAL
);
10101 /* The hardware supported by ixgbe only filters on the destination MAC
10102 * address. In order to avoid issues we only support offloading modes
10103 * where the hardware can actually provide the functionality.
10105 if (!macvlan_supports_dest_filter(vdev
))
10106 return ERR_PTR(-EMEDIUMTYPE
);
10108 /* We need to lock down the macvlan to be a single queue device so that
10109 * we can reuse the tc_to_txq field in the macvlan netdev to represent
10110 * the queue mapping to our netdev.
10112 if (netif_is_multiqueue(vdev
))
10113 return ERR_PTR(-ERANGE
);
10115 pool
= find_first_zero_bit(adapter
->fwd_bitmask
, adapter
->num_rx_pools
);
10116 if (pool
== adapter
->num_rx_pools
) {
10117 u16 used_pools
= adapter
->num_vfs
+ adapter
->num_rx_pools
;
10118 u16 reserved_pools
;
10120 if (((adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) &&
10121 adapter
->num_rx_pools
>= (MAX_TX_QUEUES
/ tcs
)) ||
10122 adapter
->num_rx_pools
> IXGBE_MAX_MACVLANS
)
10123 return ERR_PTR(-EBUSY
);
10125 /* Hardware has a limited number of available pools. Each VF,
10126 * and the PF require a pool. Check to ensure we don't
10127 * attempt to use more then the available number of pools.
10129 if (used_pools
>= IXGBE_MAX_VF_FUNCTIONS
)
10130 return ERR_PTR(-EBUSY
);
10132 /* Enable VMDq flag so device will be set in VM mode */
10133 adapter
->flags
|= IXGBE_FLAG_VMDQ_ENABLED
|
10134 IXGBE_FLAG_SRIOV_ENABLED
;
10136 /* Try to reserve as many queues per pool as possible,
10137 * we start with the configurations that support 4 queues
10138 * per pools, followed by 2, and then by just 1 per pool.
10140 if (used_pools
< 32 && adapter
->num_rx_pools
< 16)
10141 reserved_pools
= min_t(u16
,
10143 16 - adapter
->num_rx_pools
);
10144 else if (adapter
->num_rx_pools
< 32)
10145 reserved_pools
= min_t(u16
,
10147 32 - adapter
->num_rx_pools
);
10149 reserved_pools
= 64 - used_pools
;
10152 if (!reserved_pools
)
10153 return ERR_PTR(-EBUSY
);
10155 adapter
->ring_feature
[RING_F_VMDQ
].limit
+= reserved_pools
;
10157 /* Force reinit of ring allocation with VMDQ enabled */
10158 err
= ixgbe_setup_tc(pdev
, adapter
->hw_tcs
);
10160 return ERR_PTR(err
);
10162 if (pool
>= adapter
->num_rx_pools
)
10163 return ERR_PTR(-ENOMEM
);
10166 accel
= kzalloc(sizeof(*accel
), GFP_KERNEL
);
10168 return ERR_PTR(-ENOMEM
);
10170 set_bit(pool
, adapter
->fwd_bitmask
);
10171 netdev_set_sb_channel(vdev
, pool
);
10172 accel
->pool
= pool
;
10173 accel
->netdev
= vdev
;
10175 if (!netif_running(pdev
))
10178 err
= ixgbe_fwd_ring_up(adapter
, accel
);
10180 return ERR_PTR(err
);
10185 static void ixgbe_fwd_del(struct net_device
*pdev
, void *priv
)
10187 struct ixgbe_fwd_adapter
*accel
= priv
;
10188 struct ixgbe_adapter
*adapter
= netdev_priv(pdev
);
10189 unsigned int rxbase
= accel
->rx_base_queue
;
10192 /* delete unicast filter associated with offloaded interface */
10193 ixgbe_del_mac_filter(adapter
, accel
->netdev
->dev_addr
,
10194 VMDQ_P(accel
->pool
));
10196 /* Allow remaining Rx packets to get flushed out of the
10197 * Rx FIFO before we drop the netdev for the ring.
10199 usleep_range(10000, 20000);
10201 for (i
= 0; i
< adapter
->num_rx_queues_per_pool
; i
++) {
10202 struct ixgbe_ring
*ring
= adapter
->rx_ring
[rxbase
+ i
];
10203 struct ixgbe_q_vector
*qv
= ring
->q_vector
;
10205 /* Make sure we aren't processing any packets and clear
10206 * netdev to shut down the ring.
10208 if (netif_running(adapter
->netdev
))
10209 napi_synchronize(&qv
->napi
);
10210 ring
->netdev
= NULL
;
10213 /* unbind the queues and drop the subordinate channel config */
10214 netdev_unbind_sb_channel(pdev
, accel
->netdev
);
10215 netdev_set_sb_channel(accel
->netdev
, 0);
10217 clear_bit(accel
->pool
, adapter
->fwd_bitmask
);
10221 #define IXGBE_MAX_MAC_HDR_LEN 127
10222 #define IXGBE_MAX_NETWORK_HDR_LEN 511
10224 static netdev_features_t
10225 ixgbe_features_check(struct sk_buff
*skb
, struct net_device
*dev
,
10226 netdev_features_t features
)
10228 unsigned int network_hdr_len
, mac_hdr_len
;
10230 /* Make certain the headers can be described by a context descriptor */
10231 mac_hdr_len
= skb_network_offset(skb
);
10232 if (unlikely(mac_hdr_len
> IXGBE_MAX_MAC_HDR_LEN
))
10233 return features
& ~(NETIF_F_HW_CSUM
|
10235 NETIF_F_GSO_UDP_L4
|
10236 NETIF_F_HW_VLAN_CTAG_TX
|
10240 network_hdr_len
= skb_checksum_start(skb
) - skb_network_header(skb
);
10241 if (unlikely(network_hdr_len
> IXGBE_MAX_NETWORK_HDR_LEN
))
10242 return features
& ~(NETIF_F_HW_CSUM
|
10244 NETIF_F_GSO_UDP_L4
|
10248 /* We can only support IPV4 TSO in tunnels if we can mangle the
10249 * inner IP ID field, so strip TSO if MANGLEID is not supported.
10250 * IPsec offoad sets skb->encapsulation but still can handle
10251 * the TSO, so it's the exception.
10253 if (skb
->encapsulation
&& !(features
& NETIF_F_TSO_MANGLEID
)) {
10254 #ifdef CONFIG_IXGBE_IPSEC
10255 if (!secpath_exists(skb
))
10257 features
&= ~NETIF_F_TSO
;
10263 static int ixgbe_xdp_setup(struct net_device
*dev
, struct bpf_prog
*prog
)
10265 int i
, frame_size
= dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
10266 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
10267 struct bpf_prog
*old_prog
;
10271 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
10274 if (adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
)
10277 /* verify ixgbe ring attributes are sufficient for XDP */
10278 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
10279 struct ixgbe_ring
*ring
= adapter
->rx_ring
[i
];
10281 if (ring_is_rsc_enabled(ring
))
10284 if (frame_size
> ixgbe_rx_bufsz(ring
))
10288 /* if the number of cpus is much larger than the maximum of queues,
10289 * we should stop it and then return with ENOMEM like before.
10291 if (nr_cpu_ids
> IXGBE_MAX_XDP_QS
* 2)
10294 old_prog
= xchg(&adapter
->xdp_prog
, prog
);
10295 need_reset
= (!!prog
!= !!old_prog
);
10297 /* If transitioning XDP modes reconfigure rings */
10302 /* Wait until ndo_xsk_wakeup completes. */
10304 err
= ixgbe_setup_tc(dev
, adapter
->hw_tcs
);
10309 xdp_features_clear_redirect_target(dev
);
10311 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
10312 WRITE_ONCE(adapter
->rx_ring
[i
]->xdp_prog
,
10313 adapter
->xdp_prog
);
10318 bpf_prog_put(old_prog
);
10320 /* Kick start the NAPI context if there is an AF_XDP socket open
10321 * on that queue id. This so that receiving will start.
10323 if (need_reset
&& prog
) {
10324 num_queues
= min_t(int, adapter
->num_rx_queues
,
10325 adapter
->num_xdp_queues
);
10326 for (i
= 0; i
< num_queues
; i
++)
10327 if (adapter
->xdp_ring
[i
]->xsk_pool
)
10328 (void)ixgbe_xsk_wakeup(adapter
->netdev
, i
,
10330 xdp_features_set_redirect_target(dev
, true);
10336 static int ixgbe_xdp(struct net_device
*dev
, struct netdev_bpf
*xdp
)
10338 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
10340 switch (xdp
->command
) {
10341 case XDP_SETUP_PROG
:
10342 return ixgbe_xdp_setup(dev
, xdp
->prog
);
10343 case XDP_SETUP_XSK_POOL
:
10344 return ixgbe_xsk_pool_setup(adapter
, xdp
->xsk
.pool
,
10345 xdp
->xsk
.queue_id
);
10352 void ixgbe_xdp_ring_update_tail(struct ixgbe_ring
*ring
)
10354 /* Force memory writes to complete before letting h/w know there
10355 * are new descriptors to fetch.
10358 writel(ring
->next_to_use
, ring
->tail
);
10361 void ixgbe_xdp_ring_update_tail_locked(struct ixgbe_ring
*ring
)
10363 if (static_branch_unlikely(&ixgbe_xdp_locking_key
))
10364 spin_lock(&ring
->tx_lock
);
10365 ixgbe_xdp_ring_update_tail(ring
);
10366 if (static_branch_unlikely(&ixgbe_xdp_locking_key
))
10367 spin_unlock(&ring
->tx_lock
);
10370 static int ixgbe_xdp_xmit(struct net_device
*dev
, int n
,
10371 struct xdp_frame
**frames
, u32 flags
)
10373 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
10374 struct ixgbe_ring
*ring
;
10378 if (unlikely(test_bit(__IXGBE_DOWN
, &adapter
->state
)))
10381 if (unlikely(flags
& ~XDP_XMIT_FLAGS_MASK
))
10384 /* During program transitions its possible adapter->xdp_prog is assigned
10385 * but ring has not been configured yet. In this case simply abort xmit.
10387 ring
= adapter
->xdp_prog
? ixgbe_determine_xdp_ring(adapter
) : NULL
;
10388 if (unlikely(!ring
))
10391 if (unlikely(test_bit(__IXGBE_TX_DISABLED
, &ring
->state
)))
10394 if (static_branch_unlikely(&ixgbe_xdp_locking_key
))
10395 spin_lock(&ring
->tx_lock
);
10397 for (i
= 0; i
< n
; i
++) {
10398 struct xdp_frame
*xdpf
= frames
[i
];
10401 err
= ixgbe_xmit_xdp_ring(ring
, xdpf
);
10402 if (err
!= IXGBE_XDP_TX
)
10407 if (unlikely(flags
& XDP_XMIT_FLUSH
))
10408 ixgbe_xdp_ring_update_tail(ring
);
10410 if (static_branch_unlikely(&ixgbe_xdp_locking_key
))
10411 spin_unlock(&ring
->tx_lock
);
10416 static const struct net_device_ops ixgbe_netdev_ops
= {
10417 .ndo_open
= ixgbe_open
,
10418 .ndo_stop
= ixgbe_close
,
10419 .ndo_start_xmit
= ixgbe_xmit_frame
,
10420 .ndo_set_rx_mode
= ixgbe_set_rx_mode
,
10421 .ndo_validate_addr
= eth_validate_addr
,
10422 .ndo_set_mac_address
= ixgbe_set_mac
,
10423 .ndo_change_mtu
= ixgbe_change_mtu
,
10424 .ndo_tx_timeout
= ixgbe_tx_timeout
,
10425 .ndo_set_tx_maxrate
= ixgbe_tx_maxrate
,
10426 .ndo_vlan_rx_add_vid
= ixgbe_vlan_rx_add_vid
,
10427 .ndo_vlan_rx_kill_vid
= ixgbe_vlan_rx_kill_vid
,
10428 .ndo_eth_ioctl
= ixgbe_ioctl
,
10429 .ndo_set_vf_mac
= ixgbe_ndo_set_vf_mac
,
10430 .ndo_set_vf_vlan
= ixgbe_ndo_set_vf_vlan
,
10431 .ndo_set_vf_rate
= ixgbe_ndo_set_vf_bw
,
10432 .ndo_set_vf_spoofchk
= ixgbe_ndo_set_vf_spoofchk
,
10433 .ndo_set_vf_link_state
= ixgbe_ndo_set_vf_link_state
,
10434 .ndo_set_vf_rss_query_en
= ixgbe_ndo_set_vf_rss_query_en
,
10435 .ndo_set_vf_trust
= ixgbe_ndo_set_vf_trust
,
10436 .ndo_get_vf_config
= ixgbe_ndo_get_vf_config
,
10437 .ndo_get_vf_stats
= ixgbe_ndo_get_vf_stats
,
10438 .ndo_get_stats64
= ixgbe_get_stats64
,
10439 .ndo_setup_tc
= __ixgbe_setup_tc
,
10441 .ndo_select_queue
= ixgbe_select_queue
,
10442 .ndo_fcoe_ddp_setup
= ixgbe_fcoe_ddp_get
,
10443 .ndo_fcoe_ddp_target
= ixgbe_fcoe_ddp_target
,
10444 .ndo_fcoe_ddp_done
= ixgbe_fcoe_ddp_put
,
10445 .ndo_fcoe_enable
= ixgbe_fcoe_enable
,
10446 .ndo_fcoe_disable
= ixgbe_fcoe_disable
,
10447 .ndo_fcoe_get_wwn
= ixgbe_fcoe_get_wwn
,
10448 .ndo_fcoe_get_hbainfo
= ixgbe_fcoe_get_hbainfo
,
10449 #endif /* IXGBE_FCOE */
10450 .ndo_set_features
= ixgbe_set_features
,
10451 .ndo_fix_features
= ixgbe_fix_features
,
10452 .ndo_fdb_add
= ixgbe_ndo_fdb_add
,
10453 .ndo_bridge_setlink
= ixgbe_ndo_bridge_setlink
,
10454 .ndo_bridge_getlink
= ixgbe_ndo_bridge_getlink
,
10455 .ndo_dfwd_add_station
= ixgbe_fwd_add
,
10456 .ndo_dfwd_del_station
= ixgbe_fwd_del
,
10457 .ndo_features_check
= ixgbe_features_check
,
10458 .ndo_bpf
= ixgbe_xdp
,
10459 .ndo_xdp_xmit
= ixgbe_xdp_xmit
,
10460 .ndo_xsk_wakeup
= ixgbe_xsk_wakeup
,
10463 static void ixgbe_disable_txr_hw(struct ixgbe_adapter
*adapter
,
10464 struct ixgbe_ring
*tx_ring
)
10466 unsigned long wait_delay
, delay_interval
;
10467 struct ixgbe_hw
*hw
= &adapter
->hw
;
10468 u8 reg_idx
= tx_ring
->reg_idx
;
10472 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
), IXGBE_TXDCTL_SWFLSH
);
10474 /* delay mechanism from ixgbe_disable_tx */
10475 delay_interval
= ixgbe_get_completion_timeout(adapter
) / 100;
10477 wait_loop
= IXGBE_MAX_RX_DESC_POLL
;
10478 wait_delay
= delay_interval
;
10480 while (wait_loop
--) {
10481 usleep_range(wait_delay
, wait_delay
+ 10);
10482 wait_delay
+= delay_interval
* 2;
10483 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(reg_idx
));
10485 if (!(txdctl
& IXGBE_TXDCTL_ENABLE
))
10489 e_err(drv
, "TXDCTL.ENABLE not cleared within the polling period\n");
10492 static void ixgbe_disable_txr(struct ixgbe_adapter
*adapter
,
10493 struct ixgbe_ring
*tx_ring
)
10495 set_bit(__IXGBE_TX_DISABLED
, &tx_ring
->state
);
10496 ixgbe_disable_txr_hw(adapter
, tx_ring
);
10499 static void ixgbe_disable_rxr_hw(struct ixgbe_adapter
*adapter
,
10500 struct ixgbe_ring
*rx_ring
)
10502 unsigned long wait_delay
, delay_interval
;
10503 struct ixgbe_hw
*hw
= &adapter
->hw
;
10504 u8 reg_idx
= rx_ring
->reg_idx
;
10508 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
10509 rxdctl
&= ~IXGBE_RXDCTL_ENABLE
;
10510 rxdctl
|= IXGBE_RXDCTL_SWFLSH
;
10512 /* write value back with RXDCTL.ENABLE bit cleared */
10513 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(reg_idx
), rxdctl
);
10515 /* RXDCTL.EN may not change on 82598 if link is down, so skip it */
10516 if (hw
->mac
.type
== ixgbe_mac_82598EB
&&
10517 !(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
10520 /* delay mechanism from ixgbe_disable_rx */
10521 delay_interval
= ixgbe_get_completion_timeout(adapter
) / 100;
10523 wait_loop
= IXGBE_MAX_RX_DESC_POLL
;
10524 wait_delay
= delay_interval
;
10526 while (wait_loop
--) {
10527 usleep_range(wait_delay
, wait_delay
+ 10);
10528 wait_delay
+= delay_interval
* 2;
10529 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
10531 if (!(rxdctl
& IXGBE_RXDCTL_ENABLE
))
10535 e_err(drv
, "RXDCTL.ENABLE not cleared within the polling period\n");
10538 static void ixgbe_reset_txr_stats(struct ixgbe_ring
*tx_ring
)
10540 memset(&tx_ring
->stats
, 0, sizeof(tx_ring
->stats
));
10541 memset(&tx_ring
->tx_stats
, 0, sizeof(tx_ring
->tx_stats
));
10544 static void ixgbe_reset_rxr_stats(struct ixgbe_ring
*rx_ring
)
10546 memset(&rx_ring
->stats
, 0, sizeof(rx_ring
->stats
));
10547 memset(&rx_ring
->rx_stats
, 0, sizeof(rx_ring
->rx_stats
));
10551 * ixgbe_irq_disable_single - Disable single IRQ vector
10552 * @adapter: adapter structure
10553 * @ring: ring index
10555 static void ixgbe_irq_disable_single(struct ixgbe_adapter
*adapter
, u32 ring
)
10557 struct ixgbe_hw
*hw
= &adapter
->hw
;
10558 u64 qmask
= BIT_ULL(ring
);
10561 switch (adapter
->hw
.mac
.type
) {
10562 case ixgbe_mac_82598EB
:
10563 mask
= qmask
& IXGBE_EIMC_RTX_QUEUE
;
10564 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, mask
);
10566 case ixgbe_mac_82599EB
:
10567 case ixgbe_mac_X540
:
10568 case ixgbe_mac_X550
:
10569 case ixgbe_mac_X550EM_x
:
10570 case ixgbe_mac_x550em_a
:
10571 mask
= (qmask
& 0xFFFFFFFF);
10573 IXGBE_WRITE_REG(hw
, IXGBE_EIMS_EX(0), mask
);
10574 mask
= (qmask
>> 32);
10576 IXGBE_WRITE_REG(hw
, IXGBE_EIMS_EX(1), mask
);
10581 IXGBE_WRITE_FLUSH(&adapter
->hw
);
10582 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
10583 synchronize_irq(adapter
->msix_entries
[ring
].vector
);
10585 synchronize_irq(adapter
->pdev
->irq
);
10589 * ixgbe_txrx_ring_disable - Disable Rx/Tx/XDP Tx rings
10590 * @adapter: adapter structure
10591 * @ring: ring index
10593 * This function disables a certain Rx/Tx/XDP Tx ring. The function
10594 * assumes that the netdev is running.
10596 void ixgbe_txrx_ring_disable(struct ixgbe_adapter
*adapter
, int ring
)
10598 struct ixgbe_ring
*rx_ring
, *tx_ring
, *xdp_ring
;
10600 rx_ring
= adapter
->rx_ring
[ring
];
10601 tx_ring
= adapter
->tx_ring
[ring
];
10602 xdp_ring
= adapter
->xdp_ring
[ring
];
10604 ixgbe_irq_disable_single(adapter
, ring
);
10606 /* Rx/Tx/XDP Tx share the same napi context. */
10607 napi_disable(&rx_ring
->q_vector
->napi
);
10609 ixgbe_disable_txr(adapter
, tx_ring
);
10611 ixgbe_disable_txr(adapter
, xdp_ring
);
10612 ixgbe_disable_rxr_hw(adapter
, rx_ring
);
10617 ixgbe_clean_tx_ring(tx_ring
);
10619 ixgbe_clean_tx_ring(xdp_ring
);
10620 ixgbe_clean_rx_ring(rx_ring
);
10622 ixgbe_reset_txr_stats(tx_ring
);
10624 ixgbe_reset_txr_stats(xdp_ring
);
10625 ixgbe_reset_rxr_stats(rx_ring
);
10629 * ixgbe_txrx_ring_enable - Enable Rx/Tx/XDP Tx rings
10630 * @adapter: adapter structure
10631 * @ring: ring index
10633 * This function enables a certain Rx/Tx/XDP Tx ring. The function
10634 * assumes that the netdev is running.
10636 void ixgbe_txrx_ring_enable(struct ixgbe_adapter
*adapter
, int ring
)
10638 struct ixgbe_ring
*rx_ring
, *tx_ring
, *xdp_ring
;
10640 rx_ring
= adapter
->rx_ring
[ring
];
10641 tx_ring
= adapter
->tx_ring
[ring
];
10642 xdp_ring
= adapter
->xdp_ring
[ring
];
10644 ixgbe_configure_tx_ring(adapter
, tx_ring
);
10646 ixgbe_configure_tx_ring(adapter
, xdp_ring
);
10647 ixgbe_configure_rx_ring(adapter
, rx_ring
);
10649 clear_bit(__IXGBE_TX_DISABLED
, &tx_ring
->state
);
10651 clear_bit(__IXGBE_TX_DISABLED
, &xdp_ring
->state
);
10653 /* Rx/Tx/XDP Tx share the same napi context. */
10654 napi_enable(&rx_ring
->q_vector
->napi
);
10655 ixgbe_irq_enable_queues(adapter
, BIT_ULL(ring
));
10656 IXGBE_WRITE_FLUSH(&adapter
->hw
);
10660 * ixgbe_enumerate_functions - Get the number of ports this device has
10661 * @adapter: adapter structure
10663 * This function enumerates the phsyical functions co-located on a single slot,
10664 * in order to determine how many ports a device has. This is most useful in
10665 * determining the required GT/s of PCIe bandwidth necessary for optimal
10668 static inline int ixgbe_enumerate_functions(struct ixgbe_adapter
*adapter
)
10670 struct pci_dev
*entry
, *pdev
= adapter
->pdev
;
10673 /* Some cards can not use the generic count PCIe functions method,
10674 * because they are behind a parent switch, so we hardcode these with
10675 * the correct number of functions.
10677 if (ixgbe_pcie_from_parent(&adapter
->hw
))
10680 list_for_each_entry(entry
, &adapter
->pdev
->bus
->devices
, bus_list
) {
10681 /* don't count virtual functions */
10682 if (entry
->is_virtfn
)
10685 /* When the devices on the bus don't all match our device ID,
10686 * we can't reliably determine the correct number of
10687 * functions. This can occur if a function has been direct
10688 * attached to a virtual machine using VT-d, for example. In
10689 * this case, simply return -1 to indicate this.
10691 if ((entry
->vendor
!= pdev
->vendor
) ||
10692 (entry
->device
!= pdev
->device
))
10702 * ixgbe_wol_supported - Check whether device supports WoL
10703 * @adapter: the adapter private structure
10704 * @device_id: the device ID
10705 * @subdevice_id: the subsystem device ID
10707 * This function is used by probe and ethtool to determine
10708 * which devices have WoL support
10711 bool ixgbe_wol_supported(struct ixgbe_adapter
*adapter
, u16 device_id
,
10714 struct ixgbe_hw
*hw
= &adapter
->hw
;
10715 u16 wol_cap
= adapter
->eeprom_cap
& IXGBE_DEVICE_CAPS_WOL_MASK
;
10717 /* WOL not supported on 82598 */
10718 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
10721 /* check eeprom to see if WOL is enabled for X540 and newer */
10722 if (hw
->mac
.type
>= ixgbe_mac_X540
) {
10723 if ((wol_cap
== IXGBE_DEVICE_CAPS_WOL_PORT0_1
) ||
10724 ((wol_cap
== IXGBE_DEVICE_CAPS_WOL_PORT0
) &&
10725 (hw
->bus
.func
== 0)))
10729 /* WOL is determined based on device IDs for 82599 MACs */
10730 switch (device_id
) {
10731 case IXGBE_DEV_ID_82599_SFP
:
10732 /* Only these subdevices could supports WOL */
10733 switch (subdevice_id
) {
10734 case IXGBE_SUBDEV_ID_82599_560FLR
:
10735 case IXGBE_SUBDEV_ID_82599_LOM_SNAP6
:
10736 case IXGBE_SUBDEV_ID_82599_SFP_WOL0
:
10737 case IXGBE_SUBDEV_ID_82599_SFP_2OCP
:
10738 /* only support first port */
10739 if (hw
->bus
.func
!= 0)
10742 case IXGBE_SUBDEV_ID_82599_SP_560FLR
:
10743 case IXGBE_SUBDEV_ID_82599_SFP
:
10744 case IXGBE_SUBDEV_ID_82599_RNDC
:
10745 case IXGBE_SUBDEV_ID_82599_ECNA_DP
:
10746 case IXGBE_SUBDEV_ID_82599_SFP_1OCP
:
10747 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1
:
10748 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2
:
10752 case IXGBE_DEV_ID_82599EN_SFP
:
10753 /* Only these subdevices support WOL */
10754 switch (subdevice_id
) {
10755 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1
:
10759 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE
:
10760 /* All except this subdevice support WOL */
10761 if (subdevice_id
!= IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ
)
10764 case IXGBE_DEV_ID_82599_KX4
:
10774 * ixgbe_set_fw_version - Set FW version
10775 * @adapter: the adapter private structure
10777 * This function is used by probe and ethtool to determine the FW version to
10778 * format to display. The FW version is taken from the EEPROM/NVM.
10780 static void ixgbe_set_fw_version(struct ixgbe_adapter
*adapter
)
10782 struct ixgbe_hw
*hw
= &adapter
->hw
;
10783 struct ixgbe_nvm_version nvm_ver
;
10785 ixgbe_get_oem_prod_version(hw
, &nvm_ver
);
10786 if (nvm_ver
.oem_valid
) {
10787 snprintf(adapter
->eeprom_id
, sizeof(adapter
->eeprom_id
),
10788 "%x.%x.%x", nvm_ver
.oem_major
, nvm_ver
.oem_minor
,
10789 nvm_ver
.oem_release
);
10793 ixgbe_get_etk_id(hw
, &nvm_ver
);
10794 ixgbe_get_orom_version(hw
, &nvm_ver
);
10796 if (nvm_ver
.or_valid
) {
10797 snprintf(adapter
->eeprom_id
, sizeof(adapter
->eeprom_id
),
10798 "0x%08x, %d.%d.%d", nvm_ver
.etk_id
, nvm_ver
.or_major
,
10799 nvm_ver
.or_build
, nvm_ver
.or_patch
);
10803 /* Set ETrack ID format */
10804 snprintf(adapter
->eeprom_id
, sizeof(adapter
->eeprom_id
),
10805 "0x%08x", nvm_ver
.etk_id
);
10809 * ixgbe_probe - Device Initialization Routine
10810 * @pdev: PCI device information struct
10811 * @ent: entry in ixgbe_pci_tbl
10813 * Returns 0 on success, negative on failure
10815 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
10816 * The OS initialization, configuring of the adapter private structure,
10817 * and a hardware reset occur.
10819 static int ixgbe_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
10821 struct net_device
*netdev
;
10822 struct ixgbe_adapter
*adapter
= NULL
;
10823 struct ixgbe_hw
*hw
;
10824 const struct ixgbe_info
*ii
= ixgbe_info_tbl
[ent
->driver_data
];
10825 unsigned int indices
= MAX_TX_QUEUES
;
10826 u8 part_str
[IXGBE_PBANUM_LENGTH
];
10827 int i
, err
, expected_gts
;
10828 bool disable_dev
= false;
10834 /* Catch broken hardware that put the wrong VF device ID in
10835 * the PCIe SR-IOV capability.
10837 if (pdev
->is_virtfn
) {
10838 WARN(1, KERN_ERR
"%s (%hx:%hx) should not be a VF!\n",
10839 pci_name(pdev
), pdev
->vendor
, pdev
->device
);
10843 err
= pci_enable_device_mem(pdev
);
10847 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
10849 dev_err(&pdev
->dev
,
10850 "No usable DMA configuration, aborting\n");
10854 err
= pci_request_mem_regions(pdev
, ixgbe_driver_name
);
10856 dev_err(&pdev
->dev
,
10857 "pci_request_selected_regions failed 0x%x\n", err
);
10861 pci_set_master(pdev
);
10862 pci_save_state(pdev
);
10864 if (ii
->mac
== ixgbe_mac_82598EB
) {
10865 #ifdef CONFIG_IXGBE_DCB
10866 /* 8 TC w/ 4 queues per TC */
10867 indices
= 4 * MAX_TRAFFIC_CLASS
;
10869 indices
= IXGBE_MAX_RSS_INDICES
;
10873 netdev
= alloc_etherdev_mq(sizeof(struct ixgbe_adapter
), indices
);
10876 goto err_alloc_etherdev
;
10879 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
10881 adapter
= netdev_priv(netdev
);
10883 adapter
->netdev
= netdev
;
10884 adapter
->pdev
= pdev
;
10886 hw
->back
= adapter
;
10887 adapter
->msg_enable
= netif_msg_init(debug
, DEFAULT_MSG_ENABLE
);
10889 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
10890 pci_resource_len(pdev
, 0));
10891 adapter
->io_addr
= hw
->hw_addr
;
10892 if (!hw
->hw_addr
) {
10897 netdev
->netdev_ops
= &ixgbe_netdev_ops
;
10898 ixgbe_set_ethtool_ops(netdev
);
10899 netdev
->watchdog_timeo
= 5 * HZ
;
10900 strscpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
));
10903 hw
->mac
.ops
= *ii
->mac_ops
;
10904 hw
->mac
.type
= ii
->mac
;
10905 hw
->mvals
= ii
->mvals
;
10907 hw
->link
.ops
= *ii
->link_ops
;
10910 hw
->eeprom
.ops
= *ii
->eeprom_ops
;
10911 eec
= IXGBE_READ_REG(hw
, IXGBE_EEC(hw
));
10912 if (ixgbe_removed(hw
->hw_addr
)) {
10916 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
10917 if (!(eec
& BIT(8)))
10918 hw
->eeprom
.ops
.read
= &ixgbe_read_eeprom_bit_bang_generic
;
10921 hw
->phy
.ops
= *ii
->phy_ops
;
10922 hw
->phy
.sfp_type
= ixgbe_sfp_type_unknown
;
10923 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
10924 hw
->phy
.mdio
.prtad
= MDIO_PRTAD_NONE
;
10925 hw
->phy
.mdio
.mmds
= 0;
10926 hw
->phy
.mdio
.mode_support
= MDIO_SUPPORTS_C45
| MDIO_EMULATE_C22
;
10927 hw
->phy
.mdio
.dev
= netdev
;
10928 hw
->phy
.mdio
.mdio_read
= ixgbe_mdio_read
;
10929 hw
->phy
.mdio
.mdio_write
= ixgbe_mdio_write
;
10931 /* setup the private structure */
10932 err
= ixgbe_sw_init(adapter
, ii
);
10936 if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
)
10937 adapter
->flags2
|= IXGBE_FLAG2_AUTO_DISABLE_VF
;
10939 switch (adapter
->hw
.mac
.type
) {
10940 case ixgbe_mac_X550
:
10941 case ixgbe_mac_X550EM_x
:
10942 netdev
->udp_tunnel_nic_info
= &ixgbe_udp_tunnels_x550
;
10944 case ixgbe_mac_x550em_a
:
10945 netdev
->udp_tunnel_nic_info
= &ixgbe_udp_tunnels_x550em_a
;
10951 /* Make sure the SWFW semaphore is in a valid state */
10952 if (hw
->mac
.ops
.init_swfw_sync
)
10953 hw
->mac
.ops
.init_swfw_sync(hw
);
10955 /* Make it possible the adapter to be woken up via WOL */
10956 switch (adapter
->hw
.mac
.type
) {
10957 case ixgbe_mac_82599EB
:
10958 case ixgbe_mac_X540
:
10959 case ixgbe_mac_X550
:
10960 case ixgbe_mac_X550EM_x
:
10961 case ixgbe_mac_x550em_a
:
10962 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
10969 * If there is a fan on this device and it has failed log the
10972 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
10973 u32 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
10974 if (esdp
& IXGBE_ESDP_SDP1
)
10975 e_crit(probe
, "Fan has stopped, replace the adapter\n");
10978 if (allow_unsupported_sfp
)
10979 hw
->allow_unsupported_sfp
= allow_unsupported_sfp
;
10981 /* reset_hw fills in the perm_addr as well */
10982 hw
->phy
.reset_if_overtemp
= true;
10983 err
= hw
->mac
.ops
.reset_hw(hw
);
10984 hw
->phy
.reset_if_overtemp
= false;
10985 ixgbe_set_eee_capable(adapter
);
10986 if (err
== -ENOENT
) {
10988 } else if (err
== -EOPNOTSUPP
) {
10989 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
10990 e_dev_err("Reload the driver after installing a supported module.\n");
10993 e_dev_err("HW Init failed: %d\n", err
);
10997 #ifdef CONFIG_PCI_IOV
10998 /* SR-IOV not supported on the 82598 */
10999 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
11002 ixgbe_init_mbx_params_pf(hw
);
11003 hw
->mbx
.ops
= ii
->mbx_ops
;
11004 pci_sriov_set_totalvfs(pdev
, IXGBE_MAX_VFS_DRV_LIMIT
);
11005 ixgbe_enable_sriov(adapter
, max_vfs
);
11009 netdev
->features
= NETIF_F_SG
|
11016 #define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
11017 NETIF_F_GSO_GRE_CSUM | \
11018 NETIF_F_GSO_IPXIP4 | \
11019 NETIF_F_GSO_IPXIP6 | \
11020 NETIF_F_GSO_UDP_TUNNEL | \
11021 NETIF_F_GSO_UDP_TUNNEL_CSUM)
11023 netdev
->gso_partial_features
= IXGBE_GSO_PARTIAL_FEATURES
;
11024 netdev
->features
|= NETIF_F_GSO_PARTIAL
|
11025 IXGBE_GSO_PARTIAL_FEATURES
;
11027 if (hw
->mac
.type
>= ixgbe_mac_82599EB
)
11028 netdev
->features
|= NETIF_F_SCTP_CRC
| NETIF_F_GSO_UDP_L4
;
11030 #ifdef CONFIG_IXGBE_IPSEC
11031 #define IXGBE_ESP_FEATURES (NETIF_F_HW_ESP | \
11032 NETIF_F_HW_ESP_TX_CSUM | \
11035 if (adapter
->ipsec
)
11036 netdev
->features
|= IXGBE_ESP_FEATURES
;
11038 /* copy netdev features into list of user selectable features */
11039 netdev
->hw_features
|= netdev
->features
|
11040 NETIF_F_HW_VLAN_CTAG_FILTER
|
11041 NETIF_F_HW_VLAN_CTAG_RX
|
11042 NETIF_F_HW_VLAN_CTAG_TX
|
11044 NETIF_F_HW_L2FW_DOFFLOAD
;
11046 if (hw
->mac
.type
>= ixgbe_mac_82599EB
)
11047 netdev
->hw_features
|= NETIF_F_NTUPLE
|
11050 netdev
->features
|= NETIF_F_HIGHDMA
;
11052 netdev
->vlan_features
|= netdev
->features
| NETIF_F_TSO_MANGLEID
;
11053 netdev
->hw_enc_features
|= netdev
->vlan_features
;
11054 netdev
->mpls_features
|= NETIF_F_SG
|
11058 netdev
->mpls_features
|= IXGBE_GSO_PARTIAL_FEATURES
;
11060 /* set this bit last since it cannot be part of vlan_features */
11061 netdev
->features
|= NETIF_F_HW_VLAN_CTAG_FILTER
|
11062 NETIF_F_HW_VLAN_CTAG_RX
|
11063 NETIF_F_HW_VLAN_CTAG_TX
;
11065 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
11066 netdev
->priv_flags
|= IFF_SUPP_NOFCS
;
11068 netdev
->xdp_features
= NETDEV_XDP_ACT_BASIC
| NETDEV_XDP_ACT_REDIRECT
|
11069 NETDEV_XDP_ACT_XSK_ZEROCOPY
;
11071 /* MTU range: 68 - 9710 */
11072 netdev
->min_mtu
= ETH_MIN_MTU
;
11073 netdev
->max_mtu
= IXGBE_MAX_JUMBO_FRAME_SIZE
- (ETH_HLEN
+ ETH_FCS_LEN
);
11075 #ifdef CONFIG_IXGBE_DCB
11076 if (adapter
->flags
& IXGBE_FLAG_DCB_CAPABLE
)
11077 netdev
->dcbnl_ops
= &ixgbe_dcbnl_ops
;
11081 if (adapter
->flags
& IXGBE_FLAG_FCOE_CAPABLE
) {
11082 unsigned int fcoe_l
;
11084 if (hw
->mac
.ops
.get_device_caps
) {
11085 hw
->mac
.ops
.get_device_caps(hw
, &device_caps
);
11086 if (device_caps
& IXGBE_DEVICE_CAPS_FCOE_OFFLOADS
)
11087 adapter
->flags
&= ~IXGBE_FLAG_FCOE_CAPABLE
;
11091 fcoe_l
= min_t(int, IXGBE_FCRETA_SIZE
, num_online_cpus());
11092 adapter
->ring_feature
[RING_F_FCOE
].limit
= fcoe_l
;
11094 netdev
->features
|= NETIF_F_FSO
|
11097 netdev
->vlan_features
|= NETIF_F_FSO
|
11100 #endif /* IXGBE_FCOE */
11101 if (adapter
->flags2
& IXGBE_FLAG2_RSC_CAPABLE
)
11102 netdev
->hw_features
|= NETIF_F_LRO
;
11103 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)
11104 netdev
->features
|= NETIF_F_LRO
;
11106 if (ixgbe_check_fw_error(adapter
)) {
11111 /* make sure the EEPROM is good */
11112 if (hw
->eeprom
.ops
.validate_checksum(hw
, NULL
) < 0) {
11113 e_dev_err("The EEPROM Checksum Is Not Valid\n");
11118 eth_platform_get_mac_address(&adapter
->pdev
->dev
,
11119 adapter
->hw
.mac
.perm_addr
);
11121 eth_hw_addr_set(netdev
, hw
->mac
.perm_addr
);
11123 if (!is_valid_ether_addr(netdev
->dev_addr
)) {
11124 e_dev_err("invalid MAC address\n");
11129 /* Set hw->mac.addr to permanent MAC address */
11130 ether_addr_copy(hw
->mac
.addr
, hw
->mac
.perm_addr
);
11131 ixgbe_mac_set_default_filter(adapter
);
11133 timer_setup(&adapter
->service_timer
, ixgbe_service_timer
, 0);
11135 if (ixgbe_removed(hw
->hw_addr
)) {
11139 INIT_WORK(&adapter
->service_task
, ixgbe_service_task
);
11140 set_bit(__IXGBE_SERVICE_INITED
, &adapter
->state
);
11141 clear_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
);
11143 err
= ixgbe_init_interrupt_scheme(adapter
);
11147 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
11148 u64_stats_init(&adapter
->rx_ring
[i
]->syncp
);
11149 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
11150 u64_stats_init(&adapter
->tx_ring
[i
]->syncp
);
11151 for (i
= 0; i
< adapter
->num_xdp_queues
; i
++)
11152 u64_stats_init(&adapter
->xdp_ring
[i
]->syncp
);
11154 /* WOL not supported for all devices */
11156 hw
->eeprom
.ops
.read(hw
, 0x2c, &adapter
->eeprom_cap
);
11157 hw
->wol_enabled
= ixgbe_wol_supported(adapter
, pdev
->device
,
11158 pdev
->subsystem_device
);
11159 if (hw
->wol_enabled
)
11160 adapter
->wol
= IXGBE_WUFC_MAG
;
11162 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
11164 /* save off EEPROM version number */
11165 ixgbe_set_fw_version(adapter
);
11167 /* pick up the PCI bus settings for reporting later */
11168 if (ixgbe_pcie_from_parent(hw
))
11169 ixgbe_get_parent_bus_info(adapter
);
11171 hw
->mac
.ops
.get_bus_info(hw
);
11173 /* calculate the expected PCIe bandwidth required for optimal
11174 * performance. Note that some older parts will never have enough
11175 * bandwidth due to being older generation PCIe parts. We clamp these
11176 * parts to ensure no warning is displayed if it can't be fixed.
11178 switch (hw
->mac
.type
) {
11179 case ixgbe_mac_82598EB
:
11180 expected_gts
= min(ixgbe_enumerate_functions(adapter
) * 10, 16);
11183 expected_gts
= ixgbe_enumerate_functions(adapter
) * 10;
11187 /* don't check link if we failed to enumerate functions */
11188 if (expected_gts
> 0)
11189 ixgbe_check_minimum_link(adapter
, expected_gts
);
11191 err
= ixgbe_read_pba_string_generic(hw
, part_str
, sizeof(part_str
));
11193 strscpy(part_str
, "Unknown", sizeof(part_str
));
11194 if (ixgbe_is_sfp(hw
) && hw
->phy
.sfp_type
!= ixgbe_sfp_type_not_present
)
11195 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
11196 hw
->mac
.type
, hw
->phy
.type
, hw
->phy
.sfp_type
,
11199 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
11200 hw
->mac
.type
, hw
->phy
.type
, part_str
);
11202 e_dev_info("%pM\n", netdev
->dev_addr
);
11204 /* reset the hardware with the new settings */
11205 err
= hw
->mac
.ops
.start_hw(hw
);
11206 if (err
== -EACCES
) {
11207 /* We are running on a pre-production device, log a warning */
11208 e_dev_warn("This device is a pre-production adapter/LOM. "
11209 "Please be aware there may be issues associated "
11210 "with your hardware. If you are experiencing "
11211 "problems please contact your Intel or hardware "
11212 "representative who provided you with this "
11215 strcpy(netdev
->name
, "eth%d");
11216 pci_set_drvdata(pdev
, adapter
);
11217 err
= register_netdev(netdev
);
11222 /* power down the optics for 82599 SFP+ fiber */
11223 if (hw
->mac
.ops
.disable_tx_laser
)
11224 hw
->mac
.ops
.disable_tx_laser(hw
);
11226 /* carrier off reporting is important to ethtool even BEFORE open */
11227 netif_carrier_off(netdev
);
11229 #ifdef CONFIG_IXGBE_DCA
11230 if (dca_add_requester(&pdev
->dev
) == 0) {
11231 adapter
->flags
|= IXGBE_FLAG_DCA_ENABLED
;
11232 ixgbe_setup_dca(adapter
);
11235 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
11236 e_info(probe
, "IOV is enabled with %d VFs\n", adapter
->num_vfs
);
11237 for (i
= 0; i
< adapter
->num_vfs
; i
++)
11238 ixgbe_vf_configuration(pdev
, (i
| 0x10000000));
11241 /* firmware requires driver version to be 0xFFFFFFFF
11242 * since os does not support feature
11244 if (hw
->mac
.ops
.set_fw_drv_ver
)
11245 hw
->mac
.ops
.set_fw_drv_ver(hw
, 0xFF, 0xFF, 0xFF, 0xFF,
11246 sizeof(UTS_RELEASE
) - 1,
11249 /* add san mac addr to netdev */
11250 ixgbe_add_sanmac_netdev(netdev
);
11252 e_dev_info("%s\n", ixgbe_default_device_descr
);
11254 #ifdef CONFIG_IXGBE_HWMON
11255 if (ixgbe_sysfs_init(adapter
))
11256 e_err(probe
, "failed to allocate sysfs resources\n");
11257 #endif /* CONFIG_IXGBE_HWMON */
11259 ixgbe_dbg_adapter_init(adapter
);
11261 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
11262 if (ixgbe_mng_enabled(hw
) && ixgbe_is_sfp(hw
) && hw
->mac
.ops
.setup_link
)
11263 hw
->mac
.ops
.setup_link(hw
,
11264 IXGBE_LINK_SPEED_10GB_FULL
| IXGBE_LINK_SPEED_1GB_FULL
,
11267 err
= ixgbe_mii_bus_init(hw
);
11274 unregister_netdev(netdev
);
11276 ixgbe_release_hw_control(adapter
);
11277 ixgbe_clear_interrupt_scheme(adapter
);
11279 ixgbe_disable_sriov(adapter
);
11280 adapter
->flags2
&= ~IXGBE_FLAG2_SEARCH_FOR_SFP
;
11281 iounmap(adapter
->io_addr
);
11282 kfree(adapter
->jump_tables
[0]);
11283 kfree(adapter
->mac_table
);
11284 kfree(adapter
->rss_key
);
11285 bitmap_free(adapter
->af_xdp_zc_qps
);
11287 disable_dev
= !test_and_set_bit(__IXGBE_DISABLED
, &adapter
->state
);
11288 free_netdev(netdev
);
11289 err_alloc_etherdev
:
11290 pci_release_mem_regions(pdev
);
11293 if (!adapter
|| disable_dev
)
11294 pci_disable_device(pdev
);
11299 * ixgbe_remove - Device Removal Routine
11300 * @pdev: PCI device information struct
11302 * ixgbe_remove is called by the PCI subsystem to alert the driver
11303 * that it should release a PCI device. The could be caused by a
11304 * Hot-Plug event, or because the driver is going to be removed from
11307 static void ixgbe_remove(struct pci_dev
*pdev
)
11309 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
11310 struct net_device
*netdev
;
11314 /* if !adapter then we already cleaned up in probe */
11318 netdev
= adapter
->netdev
;
11319 ixgbe_dbg_adapter_exit(adapter
);
11321 set_bit(__IXGBE_REMOVING
, &adapter
->state
);
11322 cancel_work_sync(&adapter
->service_task
);
11324 if (adapter
->mii_bus
)
11325 mdiobus_unregister(adapter
->mii_bus
);
11327 #ifdef CONFIG_IXGBE_DCA
11328 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
11329 adapter
->flags
&= ~IXGBE_FLAG_DCA_ENABLED
;
11330 dca_remove_requester(&pdev
->dev
);
11331 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
,
11332 IXGBE_DCA_CTRL_DCA_DISABLE
);
11336 #ifdef CONFIG_IXGBE_HWMON
11337 ixgbe_sysfs_exit(adapter
);
11338 #endif /* CONFIG_IXGBE_HWMON */
11340 /* remove the added san mac */
11341 ixgbe_del_sanmac_netdev(netdev
);
11343 #ifdef CONFIG_PCI_IOV
11344 ixgbe_disable_sriov(adapter
);
11346 if (netdev
->reg_state
== NETREG_REGISTERED
)
11347 unregister_netdev(netdev
);
11349 ixgbe_stop_ipsec_offload(adapter
);
11350 ixgbe_clear_interrupt_scheme(adapter
);
11352 ixgbe_release_hw_control(adapter
);
11355 kfree(adapter
->ixgbe_ieee_pfc
);
11356 kfree(adapter
->ixgbe_ieee_ets
);
11359 iounmap(adapter
->io_addr
);
11360 pci_release_mem_regions(pdev
);
11362 e_dev_info("complete\n");
11364 for (i
= 0; i
< IXGBE_MAX_LINK_HANDLE
; i
++) {
11365 if (adapter
->jump_tables
[i
]) {
11366 kfree(adapter
->jump_tables
[i
]->input
);
11367 kfree(adapter
->jump_tables
[i
]->mask
);
11369 kfree(adapter
->jump_tables
[i
]);
11372 kfree(adapter
->mac_table
);
11373 kfree(adapter
->rss_key
);
11374 bitmap_free(adapter
->af_xdp_zc_qps
);
11375 disable_dev
= !test_and_set_bit(__IXGBE_DISABLED
, &adapter
->state
);
11376 free_netdev(netdev
);
11379 pci_disable_device(pdev
);
11383 * ixgbe_io_error_detected - called when PCI error is detected
11384 * @pdev: Pointer to PCI device
11385 * @state: The current pci connection state
11387 * This function is called after a PCI bus error affecting
11388 * this device has been detected.
11390 static pci_ers_result_t
ixgbe_io_error_detected(struct pci_dev
*pdev
,
11391 pci_channel_state_t state
)
11393 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
11394 struct net_device
*netdev
= adapter
->netdev
;
11396 #ifdef CONFIG_PCI_IOV
11397 struct ixgbe_hw
*hw
= &adapter
->hw
;
11398 struct pci_dev
*bdev
, *vfdev
;
11399 u32 dw0
, dw1
, dw2
, dw3
;
11401 u16 req_id
, pf_func
;
11403 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
||
11404 adapter
->num_vfs
== 0)
11405 goto skip_bad_vf_detection
;
11407 bdev
= pdev
->bus
->self
;
11408 while (bdev
&& (pci_pcie_type(bdev
) != PCI_EXP_TYPE_ROOT_PORT
))
11409 bdev
= bdev
->bus
->self
;
11412 goto skip_bad_vf_detection
;
11414 pos
= pci_find_ext_capability(bdev
, PCI_EXT_CAP_ID_ERR
);
11416 goto skip_bad_vf_detection
;
11418 dw0
= ixgbe_read_pci_cfg_dword(hw
, pos
+ PCI_ERR_HEADER_LOG
);
11419 dw1
= ixgbe_read_pci_cfg_dword(hw
, pos
+ PCI_ERR_HEADER_LOG
+ 4);
11420 dw2
= ixgbe_read_pci_cfg_dword(hw
, pos
+ PCI_ERR_HEADER_LOG
+ 8);
11421 dw3
= ixgbe_read_pci_cfg_dword(hw
, pos
+ PCI_ERR_HEADER_LOG
+ 12);
11422 if (ixgbe_removed(hw
->hw_addr
))
11423 goto skip_bad_vf_detection
;
11425 req_id
= dw1
>> 16;
11426 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
11427 if (!(req_id
& 0x0080))
11428 goto skip_bad_vf_detection
;
11430 pf_func
= req_id
& 0x01;
11431 if ((pf_func
& 1) == (pdev
->devfn
& 1)) {
11432 unsigned int device_id
;
11434 vf
= FIELD_GET(0x7F, req_id
);
11435 e_dev_err("VF %d has caused a PCIe error\n", vf
);
11436 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
11437 "%8.8x\tdw3: %8.8x\n",
11438 dw0
, dw1
, dw2
, dw3
);
11439 switch (adapter
->hw
.mac
.type
) {
11440 case ixgbe_mac_82599EB
:
11441 device_id
= IXGBE_82599_VF_DEVICE_ID
;
11443 case ixgbe_mac_X540
:
11444 device_id
= IXGBE_X540_VF_DEVICE_ID
;
11446 case ixgbe_mac_X550
:
11447 device_id
= IXGBE_DEV_ID_X550_VF
;
11449 case ixgbe_mac_X550EM_x
:
11450 device_id
= IXGBE_DEV_ID_X550EM_X_VF
;
11452 case ixgbe_mac_x550em_a
:
11453 device_id
= IXGBE_DEV_ID_X550EM_A_VF
;
11460 /* Find the pci device of the offending VF */
11461 vfdev
= pci_get_device(PCI_VENDOR_ID_INTEL
, device_id
, NULL
);
11463 if (vfdev
->devfn
== (req_id
& 0xFF))
11465 vfdev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
11469 * There's a slim chance the VF could have been hot plugged,
11470 * so if it is no longer present we don't need to issue the
11471 * VFLR. Just clean up the AER in that case.
11475 /* Free device reference count */
11476 pci_dev_put(vfdev
);
11481 * Even though the error may have occurred on the other port
11482 * we still need to increment the vf error reference count for
11483 * both ports because the I/O resume function will be called
11484 * for both of them.
11486 adapter
->vferr_refcount
++;
11488 return PCI_ERS_RESULT_RECOVERED
;
11490 skip_bad_vf_detection
:
11491 #endif /* CONFIG_PCI_IOV */
11492 if (!test_bit(__IXGBE_SERVICE_INITED
, &adapter
->state
))
11493 return PCI_ERS_RESULT_DISCONNECT
;
11495 if (!netif_device_present(netdev
))
11496 return PCI_ERS_RESULT_DISCONNECT
;
11499 netif_device_detach(netdev
);
11501 if (netif_running(netdev
))
11502 ixgbe_close_suspend(adapter
);
11504 if (state
== pci_channel_io_perm_failure
) {
11506 return PCI_ERS_RESULT_DISCONNECT
;
11509 if (!test_and_set_bit(__IXGBE_DISABLED
, &adapter
->state
))
11510 pci_disable_device(pdev
);
11513 /* Request a slot reset. */
11514 return PCI_ERS_RESULT_NEED_RESET
;
11518 * ixgbe_io_slot_reset - called after the pci bus has been reset.
11519 * @pdev: Pointer to PCI device
11521 * Restart the card from scratch, as if from a cold-boot.
11523 static pci_ers_result_t
ixgbe_io_slot_reset(struct pci_dev
*pdev
)
11525 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
11526 pci_ers_result_t result
;
11528 if (pci_enable_device_mem(pdev
)) {
11529 e_err(probe
, "Cannot re-enable PCI device after reset.\n");
11530 result
= PCI_ERS_RESULT_DISCONNECT
;
11532 smp_mb__before_atomic();
11533 clear_bit(__IXGBE_DISABLED
, &adapter
->state
);
11534 adapter
->hw
.hw_addr
= adapter
->io_addr
;
11535 pci_set_master(pdev
);
11536 pci_restore_state(pdev
);
11537 pci_save_state(pdev
);
11539 pci_wake_from_d3(pdev
, false);
11541 ixgbe_reset(adapter
);
11542 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
11543 result
= PCI_ERS_RESULT_RECOVERED
;
11550 * ixgbe_io_resume - called when traffic can start flowing again.
11551 * @pdev: Pointer to PCI device
11553 * This callback is called when the error recovery driver tells us that
11554 * its OK to resume normal operation.
11556 static void ixgbe_io_resume(struct pci_dev
*pdev
)
11558 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
11559 struct net_device
*netdev
= adapter
->netdev
;
11561 #ifdef CONFIG_PCI_IOV
11562 if (adapter
->vferr_refcount
) {
11563 e_info(drv
, "Resuming after VF err\n");
11564 adapter
->vferr_refcount
--;
11570 if (netif_running(netdev
))
11571 ixgbe_open(netdev
);
11573 netif_device_attach(netdev
);
11577 static const struct pci_error_handlers ixgbe_err_handler
= {
11578 .error_detected
= ixgbe_io_error_detected
,
11579 .slot_reset
= ixgbe_io_slot_reset
,
11580 .resume
= ixgbe_io_resume
,
11583 static DEFINE_SIMPLE_DEV_PM_OPS(ixgbe_pm_ops
, ixgbe_suspend
, ixgbe_resume
);
11585 static struct pci_driver ixgbe_driver
= {
11586 .name
= ixgbe_driver_name
,
11587 .id_table
= ixgbe_pci_tbl
,
11588 .probe
= ixgbe_probe
,
11589 .remove
= ixgbe_remove
,
11590 .driver
.pm
= pm_sleep_ptr(&ixgbe_pm_ops
),
11591 .shutdown
= ixgbe_shutdown
,
11592 .sriov_configure
= ixgbe_pci_sriov_configure
,
11593 .err_handler
= &ixgbe_err_handler
11597 * ixgbe_init_module - Driver Registration Routine
11599 * ixgbe_init_module is the first routine called when the driver is
11600 * loaded. All it does is register with the PCI subsystem.
11602 static int __init
ixgbe_init_module(void)
11605 pr_info("%s\n", ixgbe_driver_string
);
11606 pr_info("%s\n", ixgbe_copyright
);
11608 ixgbe_wq
= create_singlethread_workqueue(ixgbe_driver_name
);
11610 pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name
);
11616 ret
= pci_register_driver(&ixgbe_driver
);
11618 destroy_workqueue(ixgbe_wq
);
11623 #ifdef CONFIG_IXGBE_DCA
11624 dca_register_notify(&dca_notifier
);
11630 module_init(ixgbe_init_module
);
11633 * ixgbe_exit_module - Driver Exit Cleanup Routine
11635 * ixgbe_exit_module is called just before the driver is removed
11638 static void __exit
ixgbe_exit_module(void)
11640 #ifdef CONFIG_IXGBE_DCA
11641 dca_unregister_notify(&dca_notifier
);
11643 pci_unregister_driver(&ixgbe_driver
);
11647 destroy_workqueue(ixgbe_wq
);
11652 #ifdef CONFIG_IXGBE_DCA
11653 static int ixgbe_notify_dca(struct notifier_block
*nb
, unsigned long event
,
11658 ret_val
= driver_for_each_device(&ixgbe_driver
.driver
, NULL
, &event
,
11659 __ixgbe_notify_dca
);
11661 return ret_val
? NOTIFY_BAD
: NOTIFY_DONE
;
11664 #endif /* CONFIG_IXGBE_DCA */
11666 module_exit(ixgbe_exit_module
);