1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2016 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 #include <linux/types.h>
30 #include <linux/module.h>
31 #include <linux/pci.h>
32 #include <linux/netdevice.h>
33 #include <linux/vmalloc.h>
34 #include <linux/string.h>
36 #include <linux/interrupt.h>
38 #include <linux/tcp.h>
39 #include <linux/sctp.h>
40 #include <linux/pkt_sched.h>
41 #include <linux/ipv6.h>
42 #include <linux/slab.h>
43 #include <net/checksum.h>
44 #include <net/ip6_checksum.h>
45 #include <linux/etherdevice.h>
46 #include <linux/ethtool.h>
48 #include <linux/if_vlan.h>
49 #include <linux/if_macvlan.h>
50 #include <linux/if_bridge.h>
51 #include <linux/prefetch.h>
52 #include <scsi/fc/fc_fcoe.h>
53 #include <net/vxlan.h>
54 #include <net/pkt_cls.h>
55 #include <net/tc_act/tc_gact.h>
58 #include "ixgbe_common.h"
59 #include "ixgbe_dcb_82599.h"
60 #include "ixgbe_sriov.h"
61 #include "ixgbe_model.h"
63 char ixgbe_driver_name
[] = "ixgbe";
64 static const char ixgbe_driver_string
[] =
65 "Intel(R) 10 Gigabit PCI Express Network Driver";
67 char ixgbe_default_device_descr
[] =
68 "Intel(R) 10 Gigabit Network Connection";
70 static char ixgbe_default_device_descr
[] =
71 "Intel(R) 10 Gigabit Network Connection";
73 #define DRV_VERSION "4.2.1-k"
74 const char ixgbe_driver_version
[] = DRV_VERSION
;
75 static const char ixgbe_copyright
[] =
76 "Copyright (c) 1999-2015 Intel Corporation.";
78 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";
80 static const struct ixgbe_info
*ixgbe_info_tbl
[] = {
81 [board_82598
] = &ixgbe_82598_info
,
82 [board_82599
] = &ixgbe_82599_info
,
83 [board_X540
] = &ixgbe_X540_info
,
84 [board_X550
] = &ixgbe_X550_info
,
85 [board_X550EM_x
] = &ixgbe_X550EM_x_info
,
88 /* ixgbe_pci_tbl - PCI Device ID Table
90 * Wildcard entries (PCI_ANY_ID) should come last
91 * Last entry must be all 0s
93 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
94 * Class, Class Mask, private data (not used) }
96 static const struct pci_device_id ixgbe_pci_tbl
[] = {
97 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598
), board_82598
},
98 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AF_DUAL_PORT
), board_82598
},
99 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AF_SINGLE_PORT
), board_82598
},
100 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AT
), board_82598
},
101 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598AT2
), board_82598
},
102 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_CX4
), board_82598
},
103 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_CX4_DUAL_PORT
), board_82598
},
104 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_DA_DUAL_PORT
), board_82598
},
105 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM
), board_82598
},
106 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_XF_LR
), board_82598
},
107 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598EB_SFP_LOM
), board_82598
},
108 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82598_BX
), board_82598
},
109 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KX4
), board_82599
},
110 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_XAUI_LOM
), board_82599
},
111 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KR
), board_82599
},
112 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP
), board_82599
},
113 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP_EM
), board_82599
},
114 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_KX4_MEZZ
), board_82599
},
115 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_CX4
), board_82599
},
116 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_BACKPLANE_FCOE
), board_82599
},
117 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP_FCOE
), board_82599
},
118 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_T3_LOM
), board_82599
},
119 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_COMBO_BACKPLANE
), board_82599
},
120 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X540T
), board_X540
},
121 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP_SF2
), board_82599
},
122 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_LS
), board_82599
},
123 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_QSFP_SF_QP
), board_82599
},
124 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599EN_SFP
), board_82599
},
125 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_82599_SFP_SF_QP
), board_82599
},
126 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X540T1
), board_X540
},
127 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550T
), board_X550
},
128 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_X_KX4
), board_X550EM_x
},
129 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_X_KR
), board_X550EM_x
},
130 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_X_10G_T
), board_X550EM_x
},
131 {PCI_VDEVICE(INTEL
, IXGBE_DEV_ID_X550EM_X_SFP
), board_X550EM_x
},
132 /* required last entry */
135 MODULE_DEVICE_TABLE(pci
, ixgbe_pci_tbl
);
137 #ifdef CONFIG_IXGBE_DCA
138 static int ixgbe_notify_dca(struct notifier_block
*, unsigned long event
,
140 static struct notifier_block dca_notifier
= {
141 .notifier_call
= ixgbe_notify_dca
,
147 #ifdef CONFIG_PCI_IOV
148 static unsigned int max_vfs
;
149 module_param(max_vfs
, uint
, 0);
150 MODULE_PARM_DESC(max_vfs
,
151 "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63. (Deprecated)");
152 #endif /* CONFIG_PCI_IOV */
154 static unsigned int allow_unsupported_sfp
;
155 module_param(allow_unsupported_sfp
, uint
, 0);
156 MODULE_PARM_DESC(allow_unsupported_sfp
,
157 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
159 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
160 static int debug
= -1;
161 module_param(debug
, int, 0);
162 MODULE_PARM_DESC(debug
, "Debug level (0=none,...,16=all)");
164 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
165 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
166 MODULE_LICENSE("GPL");
167 MODULE_VERSION(DRV_VERSION
);
169 static struct workqueue_struct
*ixgbe_wq
;
171 static bool ixgbe_check_cfg_remove(struct ixgbe_hw
*hw
, struct pci_dev
*pdev
);
173 static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter
*adapter
,
176 struct pci_dev
*parent_dev
;
177 struct pci_bus
*parent_bus
;
179 parent_bus
= adapter
->pdev
->bus
->parent
;
183 parent_dev
= parent_bus
->self
;
187 if (!pci_is_pcie(parent_dev
))
190 pcie_capability_read_word(parent_dev
, reg
, value
);
191 if (*value
== IXGBE_FAILED_READ_CFG_WORD
&&
192 ixgbe_check_cfg_remove(&adapter
->hw
, parent_dev
))
197 static s32
ixgbe_get_parent_bus_info(struct ixgbe_adapter
*adapter
)
199 struct ixgbe_hw
*hw
= &adapter
->hw
;
203 hw
->bus
.type
= ixgbe_bus_type_pci_express
;
205 /* Get the negotiated link width and speed from PCI config space of the
206 * parent, as this device is behind a switch
208 err
= ixgbe_read_pci_cfg_word_parent(adapter
, 18, &link_status
);
210 /* assume caller will handle error case */
214 hw
->bus
.width
= ixgbe_convert_bus_width(link_status
);
215 hw
->bus
.speed
= ixgbe_convert_bus_speed(link_status
);
221 * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
222 * @hw: hw specific details
224 * This function is used by probe to determine whether a device's PCI-Express
225 * bandwidth details should be gathered from the parent bus instead of from the
226 * device. Used to ensure that various locations all have the correct device ID
229 static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw
*hw
)
231 switch (hw
->device_id
) {
232 case IXGBE_DEV_ID_82599_SFP_SF_QP
:
233 case IXGBE_DEV_ID_82599_QSFP_SF_QP
:
240 static void ixgbe_check_minimum_link(struct ixgbe_adapter
*adapter
,
243 struct ixgbe_hw
*hw
= &adapter
->hw
;
245 enum pci_bus_speed speed
= PCI_SPEED_UNKNOWN
;
246 enum pcie_link_width width
= PCIE_LNK_WIDTH_UNKNOWN
;
247 struct pci_dev
*pdev
;
249 /* Some devices are not connected over PCIe and thus do not negotiate
250 * speed. These devices do not have valid bus info, and thus any report
251 * we generate may not be correct.
253 if (hw
->bus
.type
== ixgbe_bus_type_internal
)
256 /* determine whether to use the parent device */
257 if (ixgbe_pcie_from_parent(&adapter
->hw
))
258 pdev
= adapter
->pdev
->bus
->parent
->self
;
260 pdev
= adapter
->pdev
;
262 if (pcie_get_minimum_link(pdev
, &speed
, &width
) ||
263 speed
== PCI_SPEED_UNKNOWN
|| width
== PCIE_LNK_WIDTH_UNKNOWN
) {
264 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
269 case PCIE_SPEED_2_5GT
:
270 /* 8b/10b encoding reduces max throughput by 20% */
273 case PCIE_SPEED_5_0GT
:
274 /* 8b/10b encoding reduces max throughput by 20% */
277 case PCIE_SPEED_8_0GT
:
278 /* 128b/130b encoding reduces throughput by less than 2% */
282 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
286 e_dev_info("PCI Express bandwidth of %dGT/s available\n",
288 e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n",
289 (speed
== PCIE_SPEED_8_0GT
? "8.0GT/s" :
290 speed
== PCIE_SPEED_5_0GT
? "5.0GT/s" :
291 speed
== PCIE_SPEED_2_5GT
? "2.5GT/s" :
294 (speed
== PCIE_SPEED_2_5GT
? "20%" :
295 speed
== PCIE_SPEED_5_0GT
? "20%" :
296 speed
== PCIE_SPEED_8_0GT
? "<2%" :
299 if (max_gts
< expected_gts
) {
300 e_dev_warn("This is not sufficient for optimal performance of this card.\n");
301 e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n",
303 e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n");
307 static void ixgbe_service_event_schedule(struct ixgbe_adapter
*adapter
)
309 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
) &&
310 !test_bit(__IXGBE_REMOVING
, &adapter
->state
) &&
311 !test_and_set_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
))
312 queue_work(ixgbe_wq
, &adapter
->service_task
);
315 static void ixgbe_remove_adapter(struct ixgbe_hw
*hw
)
317 struct ixgbe_adapter
*adapter
= hw
->back
;
322 e_dev_err("Adapter removed\n");
323 if (test_bit(__IXGBE_SERVICE_INITED
, &adapter
->state
))
324 ixgbe_service_event_schedule(adapter
);
327 static void ixgbe_check_remove(struct ixgbe_hw
*hw
, u32 reg
)
331 /* The following check not only optimizes a bit by not
332 * performing a read on the status register when the
333 * register just read was a status register read that
334 * returned IXGBE_FAILED_READ_REG. It also blocks any
335 * potential recursion.
337 if (reg
== IXGBE_STATUS
) {
338 ixgbe_remove_adapter(hw
);
341 value
= ixgbe_read_reg(hw
, IXGBE_STATUS
);
342 if (value
== IXGBE_FAILED_READ_REG
)
343 ixgbe_remove_adapter(hw
);
347 * ixgbe_read_reg - Read from device register
348 * @hw: hw specific details
349 * @reg: offset of register to read
351 * Returns : value read or IXGBE_FAILED_READ_REG if removed
353 * This function is used to read device registers. It checks for device
354 * removal by confirming any read that returns all ones by checking the
355 * status register value for all ones. This function avoids reading from
356 * the hardware if a removal was previously detected in which case it
357 * returns IXGBE_FAILED_READ_REG (all ones).
359 u32
ixgbe_read_reg(struct ixgbe_hw
*hw
, u32 reg
)
361 u8 __iomem
*reg_addr
= ACCESS_ONCE(hw
->hw_addr
);
364 if (ixgbe_removed(reg_addr
))
365 return IXGBE_FAILED_READ_REG
;
366 value
= readl(reg_addr
+ reg
);
367 if (unlikely(value
== IXGBE_FAILED_READ_REG
))
368 ixgbe_check_remove(hw
, reg
);
372 static bool ixgbe_check_cfg_remove(struct ixgbe_hw
*hw
, struct pci_dev
*pdev
)
376 pci_read_config_word(pdev
, PCI_VENDOR_ID
, &value
);
377 if (value
== IXGBE_FAILED_READ_CFG_WORD
) {
378 ixgbe_remove_adapter(hw
);
384 u16
ixgbe_read_pci_cfg_word(struct ixgbe_hw
*hw
, u32 reg
)
386 struct ixgbe_adapter
*adapter
= hw
->back
;
389 if (ixgbe_removed(hw
->hw_addr
))
390 return IXGBE_FAILED_READ_CFG_WORD
;
391 pci_read_config_word(adapter
->pdev
, reg
, &value
);
392 if (value
== IXGBE_FAILED_READ_CFG_WORD
&&
393 ixgbe_check_cfg_remove(hw
, adapter
->pdev
))
394 return IXGBE_FAILED_READ_CFG_WORD
;
398 #ifdef CONFIG_PCI_IOV
399 static u32
ixgbe_read_pci_cfg_dword(struct ixgbe_hw
*hw
, u32 reg
)
401 struct ixgbe_adapter
*adapter
= hw
->back
;
404 if (ixgbe_removed(hw
->hw_addr
))
405 return IXGBE_FAILED_READ_CFG_DWORD
;
406 pci_read_config_dword(adapter
->pdev
, reg
, &value
);
407 if (value
== IXGBE_FAILED_READ_CFG_DWORD
&&
408 ixgbe_check_cfg_remove(hw
, adapter
->pdev
))
409 return IXGBE_FAILED_READ_CFG_DWORD
;
412 #endif /* CONFIG_PCI_IOV */
414 void ixgbe_write_pci_cfg_word(struct ixgbe_hw
*hw
, u32 reg
, u16 value
)
416 struct ixgbe_adapter
*adapter
= hw
->back
;
418 if (ixgbe_removed(hw
->hw_addr
))
420 pci_write_config_word(adapter
->pdev
, reg
, value
);
423 static void ixgbe_service_event_complete(struct ixgbe_adapter
*adapter
)
425 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
));
427 /* flush memory to make sure state is correct before next watchdog */
428 smp_mb__before_atomic();
429 clear_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
);
432 struct ixgbe_reg_info
{
437 static const struct ixgbe_reg_info ixgbe_reg_info_tbl
[] = {
439 /* General Registers */
440 {IXGBE_CTRL
, "CTRL"},
441 {IXGBE_STATUS
, "STATUS"},
442 {IXGBE_CTRL_EXT
, "CTRL_EXT"},
444 /* Interrupt Registers */
445 {IXGBE_EICR
, "EICR"},
448 {IXGBE_SRRCTL(0), "SRRCTL"},
449 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
450 {IXGBE_RDLEN(0), "RDLEN"},
451 {IXGBE_RDH(0), "RDH"},
452 {IXGBE_RDT(0), "RDT"},
453 {IXGBE_RXDCTL(0), "RXDCTL"},
454 {IXGBE_RDBAL(0), "RDBAL"},
455 {IXGBE_RDBAH(0), "RDBAH"},
458 {IXGBE_TDBAL(0), "TDBAL"},
459 {IXGBE_TDBAH(0), "TDBAH"},
460 {IXGBE_TDLEN(0), "TDLEN"},
461 {IXGBE_TDH(0), "TDH"},
462 {IXGBE_TDT(0), "TDT"},
463 {IXGBE_TXDCTL(0), "TXDCTL"},
465 /* List Terminator */
471 * ixgbe_regdump - register printout routine
473 static void ixgbe_regdump(struct ixgbe_hw
*hw
, struct ixgbe_reg_info
*reginfo
)
479 switch (reginfo
->ofs
) {
480 case IXGBE_SRRCTL(0):
481 for (i
= 0; i
< 64; i
++)
482 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_SRRCTL(i
));
484 case IXGBE_DCA_RXCTRL(0):
485 for (i
= 0; i
< 64; i
++)
486 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_DCA_RXCTRL(i
));
489 for (i
= 0; i
< 64; i
++)
490 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDLEN(i
));
493 for (i
= 0; i
< 64; i
++)
494 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDH(i
));
497 for (i
= 0; i
< 64; i
++)
498 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDT(i
));
500 case IXGBE_RXDCTL(0):
501 for (i
= 0; i
< 64; i
++)
502 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RXDCTL(i
));
505 for (i
= 0; i
< 64; i
++)
506 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDBAL(i
));
509 for (i
= 0; i
< 64; i
++)
510 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_RDBAH(i
));
513 for (i
= 0; i
< 64; i
++)
514 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDBAL(i
));
517 for (i
= 0; i
< 64; i
++)
518 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDBAH(i
));
521 for (i
= 0; i
< 64; i
++)
522 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDLEN(i
));
525 for (i
= 0; i
< 64; i
++)
526 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDH(i
));
529 for (i
= 0; i
< 64; i
++)
530 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TDT(i
));
532 case IXGBE_TXDCTL(0):
533 for (i
= 0; i
< 64; i
++)
534 regs
[i
] = IXGBE_READ_REG(hw
, IXGBE_TXDCTL(i
));
537 pr_info("%-15s %08x\n", reginfo
->name
,
538 IXGBE_READ_REG(hw
, reginfo
->ofs
));
542 for (i
= 0; i
< 8; i
++) {
543 snprintf(rname
, 16, "%s[%d-%d]", reginfo
->name
, i
*8, i
*8+7);
544 pr_err("%-15s", rname
);
545 for (j
= 0; j
< 8; j
++)
546 pr_cont(" %08x", regs
[i
*8+j
]);
553 * ixgbe_dump - Print registers, tx-rings and rx-rings
555 static void ixgbe_dump(struct ixgbe_adapter
*adapter
)
557 struct net_device
*netdev
= adapter
->netdev
;
558 struct ixgbe_hw
*hw
= &adapter
->hw
;
559 struct ixgbe_reg_info
*reginfo
;
561 struct ixgbe_ring
*tx_ring
;
562 struct ixgbe_tx_buffer
*tx_buffer
;
563 union ixgbe_adv_tx_desc
*tx_desc
;
564 struct my_u0
{ u64 a
; u64 b
; } *u0
;
565 struct ixgbe_ring
*rx_ring
;
566 union ixgbe_adv_rx_desc
*rx_desc
;
567 struct ixgbe_rx_buffer
*rx_buffer_info
;
571 if (!netif_msg_hw(adapter
))
574 /* Print netdevice Info */
576 dev_info(&adapter
->pdev
->dev
, "Net device Info\n");
577 pr_info("Device Name state "
578 "trans_start last_rx\n");
579 pr_info("%-15s %016lX %016lX %016lX\n",
586 /* Print Registers */
587 dev_info(&adapter
->pdev
->dev
, "Register Dump\n");
588 pr_info(" Register Name Value\n");
589 for (reginfo
= (struct ixgbe_reg_info
*)ixgbe_reg_info_tbl
;
590 reginfo
->name
; reginfo
++) {
591 ixgbe_regdump(hw
, reginfo
);
594 /* Print TX Ring Summary */
595 if (!netdev
|| !netif_running(netdev
))
598 dev_info(&adapter
->pdev
->dev
, "TX Rings Summary\n");
599 pr_info(" %s %s %s %s\n",
600 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
601 "leng", "ntw", "timestamp");
602 for (n
= 0; n
< adapter
->num_tx_queues
; n
++) {
603 tx_ring
= adapter
->tx_ring
[n
];
604 tx_buffer
= &tx_ring
->tx_buffer_info
[tx_ring
->next_to_clean
];
605 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
606 n
, tx_ring
->next_to_use
, tx_ring
->next_to_clean
,
607 (u64
)dma_unmap_addr(tx_buffer
, dma
),
608 dma_unmap_len(tx_buffer
, len
),
609 tx_buffer
->next_to_watch
,
610 (u64
)tx_buffer
->time_stamp
);
614 if (!netif_msg_tx_done(adapter
))
615 goto rx_ring_summary
;
617 dev_info(&adapter
->pdev
->dev
, "TX Rings Dump\n");
619 /* Transmit Descriptor Formats
621 * 82598 Advanced Transmit Descriptor
622 * +--------------------------------------------------------------+
623 * 0 | Buffer Address [63:0] |
624 * +--------------------------------------------------------------+
625 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
626 * +--------------------------------------------------------------+
627 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
629 * 82598 Advanced Transmit Descriptor (Write-Back Format)
630 * +--------------------------------------------------------------+
632 * +--------------------------------------------------------------+
633 * 8 | RSV | STA | NXTSEQ |
634 * +--------------------------------------------------------------+
637 * 82599+ Advanced Transmit Descriptor
638 * +--------------------------------------------------------------+
639 * 0 | Buffer Address [63:0] |
640 * +--------------------------------------------------------------+
641 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
642 * +--------------------------------------------------------------+
643 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
645 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
646 * +--------------------------------------------------------------+
648 * +--------------------------------------------------------------+
649 * 8 | RSV | STA | RSV |
650 * +--------------------------------------------------------------+
654 for (n
= 0; n
< adapter
->num_tx_queues
; n
++) {
655 tx_ring
= adapter
->tx_ring
[n
];
656 pr_info("------------------------------------\n");
657 pr_info("TX QUEUE INDEX = %d\n", tx_ring
->queue_index
);
658 pr_info("------------------------------------\n");
659 pr_info("%s%s %s %s %s %s\n",
660 "T [desc] [address 63:0 ] ",
661 "[PlPOIdStDDt Ln] [bi->dma ] ",
662 "leng", "ntw", "timestamp", "bi->skb");
664 for (i
= 0; tx_ring
->desc
&& (i
< tx_ring
->count
); i
++) {
665 tx_desc
= IXGBE_TX_DESC(tx_ring
, i
);
666 tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
667 u0
= (struct my_u0
*)tx_desc
;
668 if (dma_unmap_len(tx_buffer
, len
) > 0) {
669 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
673 (u64
)dma_unmap_addr(tx_buffer
, dma
),
674 dma_unmap_len(tx_buffer
, len
),
675 tx_buffer
->next_to_watch
,
676 (u64
)tx_buffer
->time_stamp
,
678 if (i
== tx_ring
->next_to_use
&&
679 i
== tx_ring
->next_to_clean
)
681 else if (i
== tx_ring
->next_to_use
)
683 else if (i
== tx_ring
->next_to_clean
)
688 if (netif_msg_pktdata(adapter
) &&
690 print_hex_dump(KERN_INFO
, "",
691 DUMP_PREFIX_ADDRESS
, 16, 1,
692 tx_buffer
->skb
->data
,
693 dma_unmap_len(tx_buffer
, len
),
699 /* Print RX Rings Summary */
701 dev_info(&adapter
->pdev
->dev
, "RX Rings Summary\n");
702 pr_info("Queue [NTU] [NTC]\n");
703 for (n
= 0; n
< adapter
->num_rx_queues
; n
++) {
704 rx_ring
= adapter
->rx_ring
[n
];
705 pr_info("%5d %5X %5X\n",
706 n
, rx_ring
->next_to_use
, rx_ring
->next_to_clean
);
710 if (!netif_msg_rx_status(adapter
))
713 dev_info(&adapter
->pdev
->dev
, "RX Rings Dump\n");
715 /* Receive Descriptor Formats
717 * 82598 Advanced Receive Descriptor (Read) Format
719 * +-----------------------------------------------------+
720 * 0 | Packet Buffer Address [63:1] |A0/NSE|
721 * +----------------------------------------------+------+
722 * 8 | Header Buffer Address [63:1] | DD |
723 * +-----------------------------------------------------+
726 * 82598 Advanced Receive Descriptor (Write-Back) Format
728 * 63 48 47 32 31 30 21 20 16 15 4 3 0
729 * +------------------------------------------------------+
730 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
731 * | Packet | IP | | | | Type | Type |
732 * | Checksum | Ident | | | | | |
733 * +------------------------------------------------------+
734 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
735 * +------------------------------------------------------+
736 * 63 48 47 32 31 20 19 0
738 * 82599+ Advanced Receive Descriptor (Read) Format
740 * +-----------------------------------------------------+
741 * 0 | Packet Buffer Address [63:1] |A0/NSE|
742 * +----------------------------------------------+------+
743 * 8 | Header Buffer Address [63:1] | DD |
744 * +-----------------------------------------------------+
747 * 82599+ Advanced Receive Descriptor (Write-Back) Format
749 * 63 48 47 32 31 30 21 20 17 16 4 3 0
750 * +------------------------------------------------------+
751 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
752 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
753 * |/ Flow Dir Flt ID | | | | | |
754 * +------------------------------------------------------+
755 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
756 * +------------------------------------------------------+
757 * 63 48 47 32 31 20 19 0
760 for (n
= 0; n
< adapter
->num_rx_queues
; n
++) {
761 rx_ring
= adapter
->rx_ring
[n
];
762 pr_info("------------------------------------\n");
763 pr_info("RX QUEUE INDEX = %d\n", rx_ring
->queue_index
);
764 pr_info("------------------------------------\n");
766 "R [desc] [ PktBuf A0] ",
767 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
768 "<-- Adv Rx Read format\n");
770 "RWB[desc] [PcsmIpSHl PtRs] ",
771 "[vl er S cks ln] ---------------- [bi->skb ] ",
772 "<-- Adv Rx Write-Back format\n");
774 for (i
= 0; i
< rx_ring
->count
; i
++) {
775 rx_buffer_info
= &rx_ring
->rx_buffer_info
[i
];
776 rx_desc
= IXGBE_RX_DESC(rx_ring
, i
);
777 u0
= (struct my_u0
*)rx_desc
;
778 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
779 if (staterr
& IXGBE_RXD_STAT_DD
) {
780 /* Descriptor Done */
781 pr_info("RWB[0x%03X] %016llX "
782 "%016llX ---------------- %p", i
,
785 rx_buffer_info
->skb
);
787 pr_info("R [0x%03X] %016llX "
788 "%016llX %016llX %p", i
,
791 (u64
)rx_buffer_info
->dma
,
792 rx_buffer_info
->skb
);
794 if (netif_msg_pktdata(adapter
) &&
795 rx_buffer_info
->dma
) {
796 print_hex_dump(KERN_INFO
, "",
797 DUMP_PREFIX_ADDRESS
, 16, 1,
798 page_address(rx_buffer_info
->page
) +
799 rx_buffer_info
->page_offset
,
800 ixgbe_rx_bufsz(rx_ring
), true);
804 if (i
== rx_ring
->next_to_use
)
806 else if (i
== rx_ring
->next_to_clean
)
815 static void ixgbe_release_hw_control(struct ixgbe_adapter
*adapter
)
819 /* Let firmware take over control of h/w */
820 ctrl_ext
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_CTRL_EXT
);
821 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_CTRL_EXT
,
822 ctrl_ext
& ~IXGBE_CTRL_EXT_DRV_LOAD
);
825 static void ixgbe_get_hw_control(struct ixgbe_adapter
*adapter
)
829 /* Let firmware know the driver has taken over */
830 ctrl_ext
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_CTRL_EXT
);
831 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_CTRL_EXT
,
832 ctrl_ext
| IXGBE_CTRL_EXT_DRV_LOAD
);
836 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
837 * @adapter: pointer to adapter struct
838 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
839 * @queue: queue to map the corresponding interrupt to
840 * @msix_vector: the vector to map to the corresponding queue
843 static void ixgbe_set_ivar(struct ixgbe_adapter
*adapter
, s8 direction
,
844 u8 queue
, u8 msix_vector
)
847 struct ixgbe_hw
*hw
= &adapter
->hw
;
848 switch (hw
->mac
.type
) {
849 case ixgbe_mac_82598EB
:
850 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
853 index
= (((direction
* 64) + queue
) >> 2) & 0x1F;
854 ivar
= IXGBE_READ_REG(hw
, IXGBE_IVAR(index
));
855 ivar
&= ~(0xFF << (8 * (queue
& 0x3)));
856 ivar
|= (msix_vector
<< (8 * (queue
& 0x3)));
857 IXGBE_WRITE_REG(hw
, IXGBE_IVAR(index
), ivar
);
859 case ixgbe_mac_82599EB
:
862 case ixgbe_mac_X550EM_x
:
863 if (direction
== -1) {
865 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
866 index
= ((queue
& 1) * 8);
867 ivar
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_IVAR_MISC
);
868 ivar
&= ~(0xFF << index
);
869 ivar
|= (msix_vector
<< index
);
870 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_IVAR_MISC
, ivar
);
873 /* tx or rx causes */
874 msix_vector
|= IXGBE_IVAR_ALLOC_VAL
;
875 index
= ((16 * (queue
& 1)) + (8 * direction
));
876 ivar
= IXGBE_READ_REG(hw
, IXGBE_IVAR(queue
>> 1));
877 ivar
&= ~(0xFF << index
);
878 ivar
|= (msix_vector
<< index
);
879 IXGBE_WRITE_REG(hw
, IXGBE_IVAR(queue
>> 1), ivar
);
887 static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter
*adapter
,
892 switch (adapter
->hw
.mac
.type
) {
893 case ixgbe_mac_82598EB
:
894 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
895 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS
, mask
);
897 case ixgbe_mac_82599EB
:
900 case ixgbe_mac_X550EM_x
:
901 mask
= (qmask
& 0xFFFFFFFF);
902 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS_EX(0), mask
);
903 mask
= (qmask
>> 32);
904 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EICS_EX(1), mask
);
911 void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring
*ring
,
912 struct ixgbe_tx_buffer
*tx_buffer
)
914 if (tx_buffer
->skb
) {
915 dev_kfree_skb_any(tx_buffer
->skb
);
916 if (dma_unmap_len(tx_buffer
, len
))
917 dma_unmap_single(ring
->dev
,
918 dma_unmap_addr(tx_buffer
, dma
),
919 dma_unmap_len(tx_buffer
, len
),
921 } else if (dma_unmap_len(tx_buffer
, len
)) {
922 dma_unmap_page(ring
->dev
,
923 dma_unmap_addr(tx_buffer
, dma
),
924 dma_unmap_len(tx_buffer
, len
),
927 tx_buffer
->next_to_watch
= NULL
;
928 tx_buffer
->skb
= NULL
;
929 dma_unmap_len_set(tx_buffer
, len
, 0);
930 /* tx_buffer must be completely set up in the transmit path */
933 static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter
*adapter
)
935 struct ixgbe_hw
*hw
= &adapter
->hw
;
936 struct ixgbe_hw_stats
*hwstats
= &adapter
->stats
;
940 if ((hw
->fc
.current_mode
!= ixgbe_fc_full
) &&
941 (hw
->fc
.current_mode
!= ixgbe_fc_rx_pause
))
944 switch (hw
->mac
.type
) {
945 case ixgbe_mac_82598EB
:
946 data
= IXGBE_READ_REG(hw
, IXGBE_LXOFFRXC
);
949 data
= IXGBE_READ_REG(hw
, IXGBE_LXOFFRXCNT
);
951 hwstats
->lxoffrxc
+= data
;
953 /* refill credits (no tx hang) if we received xoff */
957 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
958 clear_bit(__IXGBE_HANG_CHECK_ARMED
,
959 &adapter
->tx_ring
[i
]->state
);
962 static void ixgbe_update_xoff_received(struct ixgbe_adapter
*adapter
)
964 struct ixgbe_hw
*hw
= &adapter
->hw
;
965 struct ixgbe_hw_stats
*hwstats
= &adapter
->stats
;
969 bool pfc_en
= adapter
->dcb_cfg
.pfc_mode_enable
;
971 if (adapter
->ixgbe_ieee_pfc
)
972 pfc_en
|= !!(adapter
->ixgbe_ieee_pfc
->pfc_en
);
974 if (!(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) || !pfc_en
) {
975 ixgbe_update_xoff_rx_lfc(adapter
);
979 /* update stats for each tc, only valid with PFC enabled */
980 for (i
= 0; i
< MAX_TX_PACKET_BUFFERS
; i
++) {
983 switch (hw
->mac
.type
) {
984 case ixgbe_mac_82598EB
:
985 pxoffrxc
= IXGBE_READ_REG(hw
, IXGBE_PXOFFRXC(i
));
988 pxoffrxc
= IXGBE_READ_REG(hw
, IXGBE_PXOFFRXCNT(i
));
990 hwstats
->pxoffrxc
[i
] += pxoffrxc
;
991 /* Get the TC for given UP */
992 tc
= netdev_get_prio_tc_map(adapter
->netdev
, i
);
993 xoff
[tc
] += pxoffrxc
;
996 /* disarm tx queues that have received xoff frames */
997 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
998 struct ixgbe_ring
*tx_ring
= adapter
->tx_ring
[i
];
1000 tc
= tx_ring
->dcb_tc
;
1002 clear_bit(__IXGBE_HANG_CHECK_ARMED
, &tx_ring
->state
);
1006 static u64
ixgbe_get_tx_completed(struct ixgbe_ring
*ring
)
1008 return ring
->stats
.packets
;
1011 static u64
ixgbe_get_tx_pending(struct ixgbe_ring
*ring
)
1013 struct ixgbe_adapter
*adapter
;
1014 struct ixgbe_hw
*hw
;
1017 if (ring
->l2_accel_priv
)
1018 adapter
= ring
->l2_accel_priv
->real_adapter
;
1020 adapter
= netdev_priv(ring
->netdev
);
1023 head
= IXGBE_READ_REG(hw
, IXGBE_TDH(ring
->reg_idx
));
1024 tail
= IXGBE_READ_REG(hw
, IXGBE_TDT(ring
->reg_idx
));
1027 return (head
< tail
) ?
1028 tail
- head
: (tail
+ ring
->count
- head
);
1033 static inline bool ixgbe_check_tx_hang(struct ixgbe_ring
*tx_ring
)
1035 u32 tx_done
= ixgbe_get_tx_completed(tx_ring
);
1036 u32 tx_done_old
= tx_ring
->tx_stats
.tx_done_old
;
1037 u32 tx_pending
= ixgbe_get_tx_pending(tx_ring
);
1039 clear_check_for_tx_hang(tx_ring
);
1042 * Check for a hung queue, but be thorough. This verifies
1043 * that a transmit has been completed since the previous
1044 * check AND there is at least one packet pending. The
1045 * ARMED bit is set to indicate a potential hang. The
1046 * bit is cleared if a pause frame is received to remove
1047 * false hang detection due to PFC or 802.3x frames. By
1048 * requiring this to fail twice we avoid races with
1049 * pfc clearing the ARMED bit and conditions where we
1050 * run the check_tx_hang logic with a transmit completion
1051 * pending but without time to complete it yet.
1053 if (tx_done_old
== tx_done
&& tx_pending
)
1054 /* make sure it is true for two checks in a row */
1055 return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED
,
1057 /* update completed stats and continue */
1058 tx_ring
->tx_stats
.tx_done_old
= tx_done
;
1059 /* reset the countdown */
1060 clear_bit(__IXGBE_HANG_CHECK_ARMED
, &tx_ring
->state
);
1066 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1067 * @adapter: driver private struct
1069 static void ixgbe_tx_timeout_reset(struct ixgbe_adapter
*adapter
)
1072 /* Do the reset outside of interrupt context */
1073 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
1074 adapter
->flags2
|= IXGBE_FLAG2_RESET_REQUESTED
;
1075 e_warn(drv
, "initiating reset due to tx timeout\n");
1076 ixgbe_service_event_schedule(adapter
);
1081 * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
1083 static int ixgbe_tx_maxrate(struct net_device
*netdev
,
1084 int queue_index
, u32 maxrate
)
1086 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
1087 struct ixgbe_hw
*hw
= &adapter
->hw
;
1088 u32 bcnrc_val
= ixgbe_link_mbps(adapter
);
1093 /* Calculate the rate factor values to set */
1094 bcnrc_val
<<= IXGBE_RTTBCNRC_RF_INT_SHIFT
;
1095 bcnrc_val
/= maxrate
;
1097 /* clear everything but the rate factor */
1098 bcnrc_val
&= IXGBE_RTTBCNRC_RF_INT_MASK
|
1099 IXGBE_RTTBCNRC_RF_DEC_MASK
;
1101 /* enable the rate scheduler */
1102 bcnrc_val
|= IXGBE_RTTBCNRC_RS_ENA
;
1104 IXGBE_WRITE_REG(hw
, IXGBE_RTTDQSEL
, queue_index
);
1105 IXGBE_WRITE_REG(hw
, IXGBE_RTTBCNRC
, bcnrc_val
);
1111 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
1112 * @q_vector: structure containing interrupt and ring information
1113 * @tx_ring: tx ring to clean
1114 * @napi_budget: Used to determine if we are in netpoll
1116 static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector
*q_vector
,
1117 struct ixgbe_ring
*tx_ring
, int napi_budget
)
1119 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1120 struct ixgbe_tx_buffer
*tx_buffer
;
1121 union ixgbe_adv_tx_desc
*tx_desc
;
1122 unsigned int total_bytes
= 0, total_packets
= 0;
1123 unsigned int budget
= q_vector
->tx
.work_limit
;
1124 unsigned int i
= tx_ring
->next_to_clean
;
1126 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
1129 tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
1130 tx_desc
= IXGBE_TX_DESC(tx_ring
, i
);
1131 i
-= tx_ring
->count
;
1134 union ixgbe_adv_tx_desc
*eop_desc
= tx_buffer
->next_to_watch
;
1136 /* if next_to_watch is not set then there is no work pending */
1140 /* prevent any other reads prior to eop_desc */
1141 read_barrier_depends();
1143 /* if DD is not set pending work has not been completed */
1144 if (!(eop_desc
->wb
.status
& cpu_to_le32(IXGBE_TXD_STAT_DD
)))
1147 /* clear next_to_watch to prevent false hangs */
1148 tx_buffer
->next_to_watch
= NULL
;
1150 /* update the statistics for this packet */
1151 total_bytes
+= tx_buffer
->bytecount
;
1152 total_packets
+= tx_buffer
->gso_segs
;
1155 napi_consume_skb(tx_buffer
->skb
, napi_budget
);
1157 /* unmap skb header data */
1158 dma_unmap_single(tx_ring
->dev
,
1159 dma_unmap_addr(tx_buffer
, dma
),
1160 dma_unmap_len(tx_buffer
, len
),
1163 /* clear tx_buffer data */
1164 tx_buffer
->skb
= NULL
;
1165 dma_unmap_len_set(tx_buffer
, len
, 0);
1167 /* unmap remaining buffers */
1168 while (tx_desc
!= eop_desc
) {
1173 i
-= tx_ring
->count
;
1174 tx_buffer
= tx_ring
->tx_buffer_info
;
1175 tx_desc
= IXGBE_TX_DESC(tx_ring
, 0);
1178 /* unmap any remaining paged data */
1179 if (dma_unmap_len(tx_buffer
, len
)) {
1180 dma_unmap_page(tx_ring
->dev
,
1181 dma_unmap_addr(tx_buffer
, dma
),
1182 dma_unmap_len(tx_buffer
, len
),
1184 dma_unmap_len_set(tx_buffer
, len
, 0);
1188 /* move us one more past the eop_desc for start of next pkt */
1193 i
-= tx_ring
->count
;
1194 tx_buffer
= tx_ring
->tx_buffer_info
;
1195 tx_desc
= IXGBE_TX_DESC(tx_ring
, 0);
1198 /* issue prefetch for next Tx descriptor */
1201 /* update budget accounting */
1203 } while (likely(budget
));
1205 i
+= tx_ring
->count
;
1206 tx_ring
->next_to_clean
= i
;
1207 u64_stats_update_begin(&tx_ring
->syncp
);
1208 tx_ring
->stats
.bytes
+= total_bytes
;
1209 tx_ring
->stats
.packets
+= total_packets
;
1210 u64_stats_update_end(&tx_ring
->syncp
);
1211 q_vector
->tx
.total_bytes
+= total_bytes
;
1212 q_vector
->tx
.total_packets
+= total_packets
;
1214 if (check_for_tx_hang(tx_ring
) && ixgbe_check_tx_hang(tx_ring
)) {
1215 /* schedule immediate reset if we believe we hung */
1216 struct ixgbe_hw
*hw
= &adapter
->hw
;
1217 e_err(drv
, "Detected Tx Unit Hang\n"
1219 " TDH, TDT <%x>, <%x>\n"
1220 " next_to_use <%x>\n"
1221 " next_to_clean <%x>\n"
1222 "tx_buffer_info[next_to_clean]\n"
1223 " time_stamp <%lx>\n"
1225 tx_ring
->queue_index
,
1226 IXGBE_READ_REG(hw
, IXGBE_TDH(tx_ring
->reg_idx
)),
1227 IXGBE_READ_REG(hw
, IXGBE_TDT(tx_ring
->reg_idx
)),
1228 tx_ring
->next_to_use
, i
,
1229 tx_ring
->tx_buffer_info
[i
].time_stamp
, jiffies
);
1231 netif_stop_subqueue(tx_ring
->netdev
, tx_ring
->queue_index
);
1234 "tx hang %d detected on queue %d, resetting adapter\n",
1235 adapter
->tx_timeout_count
+ 1, tx_ring
->queue_index
);
1237 /* schedule immediate reset if we believe we hung */
1238 ixgbe_tx_timeout_reset(adapter
);
1240 /* the adapter is about to reset, no point in enabling stuff */
1244 netdev_tx_completed_queue(txring_txq(tx_ring
),
1245 total_packets
, total_bytes
);
1247 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
1248 if (unlikely(total_packets
&& netif_carrier_ok(tx_ring
->netdev
) &&
1249 (ixgbe_desc_unused(tx_ring
) >= TX_WAKE_THRESHOLD
))) {
1250 /* Make sure that anybody stopping the queue after this
1251 * sees the new next_to_clean.
1254 if (__netif_subqueue_stopped(tx_ring
->netdev
,
1255 tx_ring
->queue_index
)
1256 && !test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
1257 netif_wake_subqueue(tx_ring
->netdev
,
1258 tx_ring
->queue_index
);
1259 ++tx_ring
->tx_stats
.restart_queue
;
1266 #ifdef CONFIG_IXGBE_DCA
1267 static void ixgbe_update_tx_dca(struct ixgbe_adapter
*adapter
,
1268 struct ixgbe_ring
*tx_ring
,
1271 struct ixgbe_hw
*hw
= &adapter
->hw
;
1275 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1276 txctrl
= dca3_get_tag(tx_ring
->dev
, cpu
);
1278 switch (hw
->mac
.type
) {
1279 case ixgbe_mac_82598EB
:
1280 reg_offset
= IXGBE_DCA_TXCTRL(tx_ring
->reg_idx
);
1282 case ixgbe_mac_82599EB
:
1283 case ixgbe_mac_X540
:
1284 reg_offset
= IXGBE_DCA_TXCTRL_82599(tx_ring
->reg_idx
);
1285 txctrl
<<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599
;
1288 /* for unknown hardware do not write register */
1293 * We can enable relaxed ordering for reads, but not writes when
1294 * DCA is enabled. This is due to a known issue in some chipsets
1295 * which will cause the DCA tag to be cleared.
1297 txctrl
|= IXGBE_DCA_TXCTRL_DESC_RRO_EN
|
1298 IXGBE_DCA_TXCTRL_DATA_RRO_EN
|
1299 IXGBE_DCA_TXCTRL_DESC_DCA_EN
;
1301 IXGBE_WRITE_REG(hw
, reg_offset
, txctrl
);
1304 static void ixgbe_update_rx_dca(struct ixgbe_adapter
*adapter
,
1305 struct ixgbe_ring
*rx_ring
,
1308 struct ixgbe_hw
*hw
= &adapter
->hw
;
1310 u8 reg_idx
= rx_ring
->reg_idx
;
1312 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1313 rxctrl
= dca3_get_tag(rx_ring
->dev
, cpu
);
1315 switch (hw
->mac
.type
) {
1316 case ixgbe_mac_82599EB
:
1317 case ixgbe_mac_X540
:
1318 rxctrl
<<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599
;
1325 * We can enable relaxed ordering for reads, but not writes when
1326 * DCA is enabled. This is due to a known issue in some chipsets
1327 * which will cause the DCA tag to be cleared.
1329 rxctrl
|= IXGBE_DCA_RXCTRL_DESC_RRO_EN
|
1330 IXGBE_DCA_RXCTRL_DATA_DCA_EN
|
1331 IXGBE_DCA_RXCTRL_DESC_DCA_EN
;
1333 IXGBE_WRITE_REG(hw
, IXGBE_DCA_RXCTRL(reg_idx
), rxctrl
);
1336 static void ixgbe_update_dca(struct ixgbe_q_vector
*q_vector
)
1338 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1339 struct ixgbe_ring
*ring
;
1340 int cpu
= get_cpu();
1342 if (q_vector
->cpu
== cpu
)
1345 ixgbe_for_each_ring(ring
, q_vector
->tx
)
1346 ixgbe_update_tx_dca(adapter
, ring
, cpu
);
1348 ixgbe_for_each_ring(ring
, q_vector
->rx
)
1349 ixgbe_update_rx_dca(adapter
, ring
, cpu
);
1351 q_vector
->cpu
= cpu
;
1356 static void ixgbe_setup_dca(struct ixgbe_adapter
*adapter
)
1360 /* always use CB2 mode, difference is masked in the CB driver */
1361 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1362 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
,
1363 IXGBE_DCA_CTRL_DCA_MODE_CB2
);
1365 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
,
1366 IXGBE_DCA_CTRL_DCA_DISABLE
);
1368 for (i
= 0; i
< adapter
->num_q_vectors
; i
++) {
1369 adapter
->q_vector
[i
]->cpu
= -1;
1370 ixgbe_update_dca(adapter
->q_vector
[i
]);
1374 static int __ixgbe_notify_dca(struct device
*dev
, void *data
)
1376 struct ixgbe_adapter
*adapter
= dev_get_drvdata(dev
);
1377 unsigned long event
= *(unsigned long *)data
;
1379 if (!(adapter
->flags
& IXGBE_FLAG_DCA_CAPABLE
))
1383 case DCA_PROVIDER_ADD
:
1384 /* if we're already enabled, don't do it again */
1385 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1387 if (dca_add_requester(dev
) == 0) {
1388 adapter
->flags
|= IXGBE_FLAG_DCA_ENABLED
;
1389 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
,
1390 IXGBE_DCA_CTRL_DCA_MODE_CB2
);
1393 /* Fall Through since DCA is disabled. */
1394 case DCA_PROVIDER_REMOVE
:
1395 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
1396 dca_remove_requester(dev
);
1397 adapter
->flags
&= ~IXGBE_FLAG_DCA_ENABLED
;
1398 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
,
1399 IXGBE_DCA_CTRL_DCA_DISABLE
);
1407 #endif /* CONFIG_IXGBE_DCA */
1409 #define IXGBE_RSS_L4_TYPES_MASK \
1410 ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
1411 (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
1412 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
1413 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
1415 static inline void ixgbe_rx_hash(struct ixgbe_ring
*ring
,
1416 union ixgbe_adv_rx_desc
*rx_desc
,
1417 struct sk_buff
*skb
)
1421 if (!(ring
->netdev
->features
& NETIF_F_RXHASH
))
1424 rss_type
= le16_to_cpu(rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
) &
1425 IXGBE_RXDADV_RSSTYPE_MASK
;
1430 skb_set_hash(skb
, le32_to_cpu(rx_desc
->wb
.lower
.hi_dword
.rss
),
1431 (IXGBE_RSS_L4_TYPES_MASK
& (1ul << rss_type
)) ?
1432 PKT_HASH_TYPE_L4
: PKT_HASH_TYPE_L3
);
1437 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1438 * @ring: structure containing ring specific data
1439 * @rx_desc: advanced rx descriptor
1441 * Returns : true if it is FCoE pkt
1443 static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring
*ring
,
1444 union ixgbe_adv_rx_desc
*rx_desc
)
1446 __le16 pkt_info
= rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
1448 return test_bit(__IXGBE_RX_FCOE
, &ring
->state
) &&
1449 ((pkt_info
& cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK
)) ==
1450 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE
<<
1451 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT
)));
1454 #endif /* IXGBE_FCOE */
1456 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1457 * @ring: structure containing ring specific data
1458 * @rx_desc: current Rx descriptor being processed
1459 * @skb: skb currently being received and modified
1461 static inline void ixgbe_rx_checksum(struct ixgbe_ring
*ring
,
1462 union ixgbe_adv_rx_desc
*rx_desc
,
1463 struct sk_buff
*skb
)
1465 __le16 pkt_info
= rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
1466 __le16 hdr_info
= rx_desc
->wb
.lower
.lo_dword
.hs_rss
.hdr_info
;
1467 bool encap_pkt
= false;
1469 skb_checksum_none_assert(skb
);
1471 /* Rx csum disabled */
1472 if (!(ring
->netdev
->features
& NETIF_F_RXCSUM
))
1475 if ((pkt_info
& cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN
)) &&
1476 (hdr_info
& cpu_to_le16(IXGBE_RXDADV_PKTTYPE_TUNNEL
>> 16))) {
1478 skb
->encapsulation
= 1;
1481 /* if IP and error */
1482 if (ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_IPCS
) &&
1483 ixgbe_test_staterr(rx_desc
, IXGBE_RXDADV_ERR_IPE
)) {
1484 ring
->rx_stats
.csum_err
++;
1488 if (!ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_L4CS
))
1491 if (ixgbe_test_staterr(rx_desc
, IXGBE_RXDADV_ERR_TCPE
)) {
1493 * 82599 errata, UDP frames with a 0 checksum can be marked as
1496 if ((pkt_info
& cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP
)) &&
1497 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR
, &ring
->state
))
1500 ring
->rx_stats
.csum_err
++;
1504 /* It must be a TCP or UDP packet with a valid checksum */
1505 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1507 if (!ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_OUTERIPCS
))
1510 if (ixgbe_test_staterr(rx_desc
, IXGBE_RXDADV_ERR_OUTERIPER
)) {
1511 skb
->ip_summed
= CHECKSUM_NONE
;
1514 /* If we checked the outer header let the stack know */
1515 skb
->csum_level
= 1;
1519 static bool ixgbe_alloc_mapped_page(struct ixgbe_ring
*rx_ring
,
1520 struct ixgbe_rx_buffer
*bi
)
1522 struct page
*page
= bi
->page
;
1525 /* since we are recycling buffers we should seldom need to alloc */
1529 /* alloc new page for storage */
1530 page
= dev_alloc_pages(ixgbe_rx_pg_order(rx_ring
));
1531 if (unlikely(!page
)) {
1532 rx_ring
->rx_stats
.alloc_rx_page_failed
++;
1536 /* map page for use */
1537 dma
= dma_map_page(rx_ring
->dev
, page
, 0,
1538 ixgbe_rx_pg_size(rx_ring
), DMA_FROM_DEVICE
);
1541 * if mapping failed free memory back to system since
1542 * there isn't much point in holding memory we can't use
1544 if (dma_mapping_error(rx_ring
->dev
, dma
)) {
1545 __free_pages(page
, ixgbe_rx_pg_order(rx_ring
));
1547 rx_ring
->rx_stats
.alloc_rx_page_failed
++;
1553 bi
->page_offset
= 0;
1559 * ixgbe_alloc_rx_buffers - Replace used receive buffers
1560 * @rx_ring: ring to place buffers on
1561 * @cleaned_count: number of buffers to replace
1563 void ixgbe_alloc_rx_buffers(struct ixgbe_ring
*rx_ring
, u16 cleaned_count
)
1565 union ixgbe_adv_rx_desc
*rx_desc
;
1566 struct ixgbe_rx_buffer
*bi
;
1567 u16 i
= rx_ring
->next_to_use
;
1573 rx_desc
= IXGBE_RX_DESC(rx_ring
, i
);
1574 bi
= &rx_ring
->rx_buffer_info
[i
];
1575 i
-= rx_ring
->count
;
1578 if (!ixgbe_alloc_mapped_page(rx_ring
, bi
))
1582 * Refresh the desc even if buffer_addrs didn't change
1583 * because each write-back erases this info.
1585 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->dma
+ bi
->page_offset
);
1591 rx_desc
= IXGBE_RX_DESC(rx_ring
, 0);
1592 bi
= rx_ring
->rx_buffer_info
;
1593 i
-= rx_ring
->count
;
1596 /* clear the status bits for the next_to_use descriptor */
1597 rx_desc
->wb
.upper
.status_error
= 0;
1600 } while (cleaned_count
);
1602 i
+= rx_ring
->count
;
1604 if (rx_ring
->next_to_use
!= i
) {
1605 rx_ring
->next_to_use
= i
;
1607 /* update next to alloc since we have filled the ring */
1608 rx_ring
->next_to_alloc
= i
;
1610 /* Force memory writes to complete before letting h/w
1611 * know there are new descriptors to fetch. (Only
1612 * applicable for weak-ordered memory model archs,
1616 writel(i
, rx_ring
->tail
);
1620 static void ixgbe_set_rsc_gso_size(struct ixgbe_ring
*ring
,
1621 struct sk_buff
*skb
)
1623 u16 hdr_len
= skb_headlen(skb
);
1625 /* set gso_size to avoid messing up TCP MSS */
1626 skb_shinfo(skb
)->gso_size
= DIV_ROUND_UP((skb
->len
- hdr_len
),
1627 IXGBE_CB(skb
)->append_cnt
);
1628 skb_shinfo(skb
)->gso_type
= SKB_GSO_TCPV4
;
1631 static void ixgbe_update_rsc_stats(struct ixgbe_ring
*rx_ring
,
1632 struct sk_buff
*skb
)
1634 /* if append_cnt is 0 then frame is not RSC */
1635 if (!IXGBE_CB(skb
)->append_cnt
)
1638 rx_ring
->rx_stats
.rsc_count
+= IXGBE_CB(skb
)->append_cnt
;
1639 rx_ring
->rx_stats
.rsc_flush
++;
1641 ixgbe_set_rsc_gso_size(rx_ring
, skb
);
1643 /* gso_size is computed using append_cnt so always clear it last */
1644 IXGBE_CB(skb
)->append_cnt
= 0;
1648 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1649 * @rx_ring: rx descriptor ring packet is being transacted on
1650 * @rx_desc: pointer to the EOP Rx descriptor
1651 * @skb: pointer to current skb being populated
1653 * This function checks the ring, descriptor, and packet information in
1654 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1655 * other fields within the skb.
1657 static void ixgbe_process_skb_fields(struct ixgbe_ring
*rx_ring
,
1658 union ixgbe_adv_rx_desc
*rx_desc
,
1659 struct sk_buff
*skb
)
1661 struct net_device
*dev
= rx_ring
->netdev
;
1662 u32 flags
= rx_ring
->q_vector
->adapter
->flags
;
1664 ixgbe_update_rsc_stats(rx_ring
, skb
);
1666 ixgbe_rx_hash(rx_ring
, rx_desc
, skb
);
1668 ixgbe_rx_checksum(rx_ring
, rx_desc
, skb
);
1670 if (unlikely(flags
& IXGBE_FLAG_RX_HWTSTAMP_ENABLED
))
1671 ixgbe_ptp_rx_hwtstamp(rx_ring
, rx_desc
, skb
);
1673 if ((dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
) &&
1674 ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_VP
)) {
1675 u16 vid
= le16_to_cpu(rx_desc
->wb
.upper
.vlan
);
1676 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), vid
);
1679 skb_record_rx_queue(skb
, rx_ring
->queue_index
);
1681 skb
->protocol
= eth_type_trans(skb
, dev
);
1684 static void ixgbe_rx_skb(struct ixgbe_q_vector
*q_vector
,
1685 struct sk_buff
*skb
)
1687 skb_mark_napi_id(skb
, &q_vector
->napi
);
1688 if (ixgbe_qv_busy_polling(q_vector
))
1689 netif_receive_skb(skb
);
1691 napi_gro_receive(&q_vector
->napi
, skb
);
1695 * ixgbe_is_non_eop - process handling of non-EOP buffers
1696 * @rx_ring: Rx ring being processed
1697 * @rx_desc: Rx descriptor for current buffer
1698 * @skb: Current socket buffer containing buffer in progress
1700 * This function updates next to clean. If the buffer is an EOP buffer
1701 * this function exits returning false, otherwise it will place the
1702 * sk_buff in the next buffer to be chained and return true indicating
1703 * that this is in fact a non-EOP buffer.
1705 static bool ixgbe_is_non_eop(struct ixgbe_ring
*rx_ring
,
1706 union ixgbe_adv_rx_desc
*rx_desc
,
1707 struct sk_buff
*skb
)
1709 u32 ntc
= rx_ring
->next_to_clean
+ 1;
1711 /* fetch, update, and store next to clean */
1712 ntc
= (ntc
< rx_ring
->count
) ? ntc
: 0;
1713 rx_ring
->next_to_clean
= ntc
;
1715 prefetch(IXGBE_RX_DESC(rx_ring
, ntc
));
1717 /* update RSC append count if present */
1718 if (ring_is_rsc_enabled(rx_ring
)) {
1719 __le32 rsc_enabled
= rx_desc
->wb
.lower
.lo_dword
.data
&
1720 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK
);
1722 if (unlikely(rsc_enabled
)) {
1723 u32 rsc_cnt
= le32_to_cpu(rsc_enabled
);
1725 rsc_cnt
>>= IXGBE_RXDADV_RSCCNT_SHIFT
;
1726 IXGBE_CB(skb
)->append_cnt
+= rsc_cnt
- 1;
1728 /* update ntc based on RSC value */
1729 ntc
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
1730 ntc
&= IXGBE_RXDADV_NEXTP_MASK
;
1731 ntc
>>= IXGBE_RXDADV_NEXTP_SHIFT
;
1735 /* if we are the last buffer then there is nothing else to do */
1736 if (likely(ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_EOP
)))
1739 /* place skb in next buffer to be received */
1740 rx_ring
->rx_buffer_info
[ntc
].skb
= skb
;
1741 rx_ring
->rx_stats
.non_eop_descs
++;
1747 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1748 * @rx_ring: rx descriptor ring packet is being transacted on
1749 * @skb: pointer to current skb being adjusted
1751 * This function is an ixgbe specific version of __pskb_pull_tail. The
1752 * main difference between this version and the original function is that
1753 * this function can make several assumptions about the state of things
1754 * that allow for significant optimizations versus the standard function.
1755 * As a result we can do things like drop a frag and maintain an accurate
1756 * truesize for the skb.
1758 static void ixgbe_pull_tail(struct ixgbe_ring
*rx_ring
,
1759 struct sk_buff
*skb
)
1761 struct skb_frag_struct
*frag
= &skb_shinfo(skb
)->frags
[0];
1763 unsigned int pull_len
;
1766 * it is valid to use page_address instead of kmap since we are
1767 * working with pages allocated out of the lomem pool per
1768 * alloc_page(GFP_ATOMIC)
1770 va
= skb_frag_address(frag
);
1773 * we need the header to contain the greater of either ETH_HLEN or
1774 * 60 bytes if the skb->len is less than 60 for skb_pad.
1776 pull_len
= eth_get_headlen(va
, IXGBE_RX_HDR_SIZE
);
1778 /* align pull length to size of long to optimize memcpy performance */
1779 skb_copy_to_linear_data(skb
, va
, ALIGN(pull_len
, sizeof(long)));
1781 /* update all of the pointers */
1782 skb_frag_size_sub(frag
, pull_len
);
1783 frag
->page_offset
+= pull_len
;
1784 skb
->data_len
-= pull_len
;
1785 skb
->tail
+= pull_len
;
1789 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1790 * @rx_ring: rx descriptor ring packet is being transacted on
1791 * @skb: pointer to current skb being updated
1793 * This function provides a basic DMA sync up for the first fragment of an
1794 * skb. The reason for doing this is that the first fragment cannot be
1795 * unmapped until we have reached the end of packet descriptor for a buffer
1798 static void ixgbe_dma_sync_frag(struct ixgbe_ring
*rx_ring
,
1799 struct sk_buff
*skb
)
1801 /* if the page was released unmap it, else just sync our portion */
1802 if (unlikely(IXGBE_CB(skb
)->page_released
)) {
1803 dma_unmap_page(rx_ring
->dev
, IXGBE_CB(skb
)->dma
,
1804 ixgbe_rx_pg_size(rx_ring
), DMA_FROM_DEVICE
);
1805 IXGBE_CB(skb
)->page_released
= false;
1807 struct skb_frag_struct
*frag
= &skb_shinfo(skb
)->frags
[0];
1809 dma_sync_single_range_for_cpu(rx_ring
->dev
,
1812 ixgbe_rx_bufsz(rx_ring
),
1815 IXGBE_CB(skb
)->dma
= 0;
1819 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1820 * @rx_ring: rx descriptor ring packet is being transacted on
1821 * @rx_desc: pointer to the EOP Rx descriptor
1822 * @skb: pointer to current skb being fixed
1824 * Check for corrupted packet headers caused by senders on the local L2
1825 * embedded NIC switch not setting up their Tx Descriptors right. These
1826 * should be very rare.
1828 * Also address the case where we are pulling data in on pages only
1829 * and as such no data is present in the skb header.
1831 * In addition if skb is not at least 60 bytes we need to pad it so that
1832 * it is large enough to qualify as a valid Ethernet frame.
1834 * Returns true if an error was encountered and skb was freed.
1836 static bool ixgbe_cleanup_headers(struct ixgbe_ring
*rx_ring
,
1837 union ixgbe_adv_rx_desc
*rx_desc
,
1838 struct sk_buff
*skb
)
1840 struct net_device
*netdev
= rx_ring
->netdev
;
1842 /* verify that the packet does not have any known errors */
1843 if (unlikely(ixgbe_test_staterr(rx_desc
,
1844 IXGBE_RXDADV_ERR_FRAME_ERR_MASK
) &&
1845 !(netdev
->features
& NETIF_F_RXALL
))) {
1846 dev_kfree_skb_any(skb
);
1850 /* place header in linear portion of buffer */
1851 if (skb_is_nonlinear(skb
))
1852 ixgbe_pull_tail(rx_ring
, skb
);
1855 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1856 if (ixgbe_rx_is_fcoe(rx_ring
, rx_desc
))
1860 /* if eth_skb_pad returns an error the skb was freed */
1861 if (eth_skb_pad(skb
))
1868 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1869 * @rx_ring: rx descriptor ring to store buffers on
1870 * @old_buff: donor buffer to have page reused
1872 * Synchronizes page for reuse by the adapter
1874 static void ixgbe_reuse_rx_page(struct ixgbe_ring
*rx_ring
,
1875 struct ixgbe_rx_buffer
*old_buff
)
1877 struct ixgbe_rx_buffer
*new_buff
;
1878 u16 nta
= rx_ring
->next_to_alloc
;
1880 new_buff
= &rx_ring
->rx_buffer_info
[nta
];
1882 /* update, and store next to alloc */
1884 rx_ring
->next_to_alloc
= (nta
< rx_ring
->count
) ? nta
: 0;
1886 /* transfer page from old buffer to new buffer */
1887 *new_buff
= *old_buff
;
1889 /* sync the buffer for use by the device */
1890 dma_sync_single_range_for_device(rx_ring
->dev
, new_buff
->dma
,
1891 new_buff
->page_offset
,
1892 ixgbe_rx_bufsz(rx_ring
),
1896 static inline bool ixgbe_page_is_reserved(struct page
*page
)
1898 return (page_to_nid(page
) != numa_mem_id()) || page_is_pfmemalloc(page
);
1902 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1903 * @rx_ring: rx descriptor ring to transact packets on
1904 * @rx_buffer: buffer containing page to add
1905 * @rx_desc: descriptor containing length of buffer written by hardware
1906 * @skb: sk_buff to place the data into
1908 * This function will add the data contained in rx_buffer->page to the skb.
1909 * This is done either through a direct copy if the data in the buffer is
1910 * less than the skb header size, otherwise it will just attach the page as
1911 * a frag to the skb.
1913 * The function will then update the page offset if necessary and return
1914 * true if the buffer can be reused by the adapter.
1916 static bool ixgbe_add_rx_frag(struct ixgbe_ring
*rx_ring
,
1917 struct ixgbe_rx_buffer
*rx_buffer
,
1918 union ixgbe_adv_rx_desc
*rx_desc
,
1919 struct sk_buff
*skb
)
1921 struct page
*page
= rx_buffer
->page
;
1922 unsigned int size
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
1923 #if (PAGE_SIZE < 8192)
1924 unsigned int truesize
= ixgbe_rx_bufsz(rx_ring
);
1926 unsigned int truesize
= ALIGN(size
, L1_CACHE_BYTES
);
1927 unsigned int last_offset
= ixgbe_rx_pg_size(rx_ring
) -
1928 ixgbe_rx_bufsz(rx_ring
);
1931 if ((size
<= IXGBE_RX_HDR_SIZE
) && !skb_is_nonlinear(skb
)) {
1932 unsigned char *va
= page_address(page
) + rx_buffer
->page_offset
;
1934 memcpy(__skb_put(skb
, size
), va
, ALIGN(size
, sizeof(long)));
1936 /* page is not reserved, we can reuse buffer as-is */
1937 if (likely(!ixgbe_page_is_reserved(page
)))
1940 /* this page cannot be reused so discard it */
1941 __free_pages(page
, ixgbe_rx_pg_order(rx_ring
));
1945 skb_add_rx_frag(skb
, skb_shinfo(skb
)->nr_frags
, page
,
1946 rx_buffer
->page_offset
, size
, truesize
);
1948 /* avoid re-using remote pages */
1949 if (unlikely(ixgbe_page_is_reserved(page
)))
1952 #if (PAGE_SIZE < 8192)
1953 /* if we are only owner of page we can reuse it */
1954 if (unlikely(page_count(page
) != 1))
1957 /* flip page offset to other buffer */
1958 rx_buffer
->page_offset
^= truesize
;
1960 /* move offset up to the next cache line */
1961 rx_buffer
->page_offset
+= truesize
;
1963 if (rx_buffer
->page_offset
> last_offset
)
1967 /* Even if we own the page, we are not allowed to use atomic_set()
1968 * This would break get_page_unless_zero() users.
1975 static struct sk_buff
*ixgbe_fetch_rx_buffer(struct ixgbe_ring
*rx_ring
,
1976 union ixgbe_adv_rx_desc
*rx_desc
)
1978 struct ixgbe_rx_buffer
*rx_buffer
;
1979 struct sk_buff
*skb
;
1982 rx_buffer
= &rx_ring
->rx_buffer_info
[rx_ring
->next_to_clean
];
1983 page
= rx_buffer
->page
;
1986 skb
= rx_buffer
->skb
;
1989 void *page_addr
= page_address(page
) +
1990 rx_buffer
->page_offset
;
1992 /* prefetch first cache line of first page */
1993 prefetch(page_addr
);
1994 #if L1_CACHE_BYTES < 128
1995 prefetch(page_addr
+ L1_CACHE_BYTES
);
1998 /* allocate a skb to store the frags */
1999 skb
= napi_alloc_skb(&rx_ring
->q_vector
->napi
,
2001 if (unlikely(!skb
)) {
2002 rx_ring
->rx_stats
.alloc_rx_buff_failed
++;
2007 * we will be copying header into skb->data in
2008 * pskb_may_pull so it is in our interest to prefetch
2009 * it now to avoid a possible cache miss
2011 prefetchw(skb
->data
);
2014 * Delay unmapping of the first packet. It carries the
2015 * header information, HW may still access the header
2016 * after the writeback. Only unmap it when EOP is
2019 if (likely(ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_EOP
)))
2022 IXGBE_CB(skb
)->dma
= rx_buffer
->dma
;
2024 if (ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_EOP
))
2025 ixgbe_dma_sync_frag(rx_ring
, skb
);
2028 /* we are reusing so sync this buffer for CPU use */
2029 dma_sync_single_range_for_cpu(rx_ring
->dev
,
2031 rx_buffer
->page_offset
,
2032 ixgbe_rx_bufsz(rx_ring
),
2035 rx_buffer
->skb
= NULL
;
2038 /* pull page into skb */
2039 if (ixgbe_add_rx_frag(rx_ring
, rx_buffer
, rx_desc
, skb
)) {
2040 /* hand second half of page back to the ring */
2041 ixgbe_reuse_rx_page(rx_ring
, rx_buffer
);
2042 } else if (IXGBE_CB(skb
)->dma
== rx_buffer
->dma
) {
2043 /* the page has been released from the ring */
2044 IXGBE_CB(skb
)->page_released
= true;
2046 /* we are not reusing the buffer so unmap it */
2047 dma_unmap_page(rx_ring
->dev
, rx_buffer
->dma
,
2048 ixgbe_rx_pg_size(rx_ring
),
2052 /* clear contents of buffer_info */
2053 rx_buffer
->page
= NULL
;
2059 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2060 * @q_vector: structure containing interrupt and ring information
2061 * @rx_ring: rx descriptor ring to transact packets on
2062 * @budget: Total limit on number of packets to process
2064 * This function provides a "bounce buffer" approach to Rx interrupt
2065 * processing. The advantage to this is that on systems that have
2066 * expensive overhead for IOMMU access this provides a means of avoiding
2067 * it by maintaining the mapping of the page to the syste.
2069 * Returns amount of work completed
2071 static int ixgbe_clean_rx_irq(struct ixgbe_q_vector
*q_vector
,
2072 struct ixgbe_ring
*rx_ring
,
2075 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
2077 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
2079 unsigned int mss
= 0;
2080 #endif /* IXGBE_FCOE */
2081 u16 cleaned_count
= ixgbe_desc_unused(rx_ring
);
2083 while (likely(total_rx_packets
< budget
)) {
2084 union ixgbe_adv_rx_desc
*rx_desc
;
2085 struct sk_buff
*skb
;
2087 /* return some buffers to hardware, one at a time is too slow */
2088 if (cleaned_count
>= IXGBE_RX_BUFFER_WRITE
) {
2089 ixgbe_alloc_rx_buffers(rx_ring
, cleaned_count
);
2093 rx_desc
= IXGBE_RX_DESC(rx_ring
, rx_ring
->next_to_clean
);
2095 if (!rx_desc
->wb
.upper
.status_error
)
2098 /* This memory barrier is needed to keep us from reading
2099 * any other fields out of the rx_desc until we know the
2100 * descriptor has been written back
2104 /* retrieve a buffer from the ring */
2105 skb
= ixgbe_fetch_rx_buffer(rx_ring
, rx_desc
);
2107 /* exit if we failed to retrieve a buffer */
2113 /* place incomplete frames back on ring for completion */
2114 if (ixgbe_is_non_eop(rx_ring
, rx_desc
, skb
))
2117 /* verify the packet layout is correct */
2118 if (ixgbe_cleanup_headers(rx_ring
, rx_desc
, skb
))
2121 /* probably a little skewed due to removing CRC */
2122 total_rx_bytes
+= skb
->len
;
2124 /* populate checksum, timestamp, VLAN, and protocol */
2125 ixgbe_process_skb_fields(rx_ring
, rx_desc
, skb
);
2128 /* if ddp, not passing to ULD unless for FCP_RSP or error */
2129 if (ixgbe_rx_is_fcoe(rx_ring
, rx_desc
)) {
2130 ddp_bytes
= ixgbe_fcoe_ddp(adapter
, rx_desc
, skb
);
2131 /* include DDPed FCoE data */
2132 if (ddp_bytes
> 0) {
2134 mss
= rx_ring
->netdev
->mtu
-
2135 sizeof(struct fcoe_hdr
) -
2136 sizeof(struct fc_frame_header
) -
2137 sizeof(struct fcoe_crc_eof
);
2141 total_rx_bytes
+= ddp_bytes
;
2142 total_rx_packets
+= DIV_ROUND_UP(ddp_bytes
,
2146 dev_kfree_skb_any(skb
);
2151 #endif /* IXGBE_FCOE */
2152 ixgbe_rx_skb(q_vector
, skb
);
2154 /* update budget accounting */
2158 u64_stats_update_begin(&rx_ring
->syncp
);
2159 rx_ring
->stats
.packets
+= total_rx_packets
;
2160 rx_ring
->stats
.bytes
+= total_rx_bytes
;
2161 u64_stats_update_end(&rx_ring
->syncp
);
2162 q_vector
->rx
.total_packets
+= total_rx_packets
;
2163 q_vector
->rx
.total_bytes
+= total_rx_bytes
;
2165 return total_rx_packets
;
2168 #ifdef CONFIG_NET_RX_BUSY_POLL
2169 /* must be called with local_bh_disable()d */
2170 static int ixgbe_low_latency_recv(struct napi_struct
*napi
)
2172 struct ixgbe_q_vector
*q_vector
=
2173 container_of(napi
, struct ixgbe_q_vector
, napi
);
2174 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
2175 struct ixgbe_ring
*ring
;
2178 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
2179 return LL_FLUSH_FAILED
;
2181 if (!ixgbe_qv_lock_poll(q_vector
))
2182 return LL_FLUSH_BUSY
;
2184 ixgbe_for_each_ring(ring
, q_vector
->rx
) {
2185 found
= ixgbe_clean_rx_irq(q_vector
, ring
, 4);
2186 #ifdef BP_EXTENDED_STATS
2188 ring
->stats
.cleaned
+= found
;
2190 ring
->stats
.misses
++;
2196 ixgbe_qv_unlock_poll(q_vector
);
2200 #endif /* CONFIG_NET_RX_BUSY_POLL */
2203 * ixgbe_configure_msix - Configure MSI-X hardware
2204 * @adapter: board private structure
2206 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2209 static void ixgbe_configure_msix(struct ixgbe_adapter
*adapter
)
2211 struct ixgbe_q_vector
*q_vector
;
2215 /* Populate MSIX to EITR Select */
2216 if (adapter
->num_vfs
> 32) {
2217 u32 eitrsel
= (1 << (adapter
->num_vfs
- 32)) - 1;
2218 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITRSEL
, eitrsel
);
2222 * Populate the IVAR table and set the ITR values to the
2223 * corresponding register.
2225 for (v_idx
= 0; v_idx
< adapter
->num_q_vectors
; v_idx
++) {
2226 struct ixgbe_ring
*ring
;
2227 q_vector
= adapter
->q_vector
[v_idx
];
2229 ixgbe_for_each_ring(ring
, q_vector
->rx
)
2230 ixgbe_set_ivar(adapter
, 0, ring
->reg_idx
, v_idx
);
2232 ixgbe_for_each_ring(ring
, q_vector
->tx
)
2233 ixgbe_set_ivar(adapter
, 1, ring
->reg_idx
, v_idx
);
2235 ixgbe_write_eitr(q_vector
);
2238 switch (adapter
->hw
.mac
.type
) {
2239 case ixgbe_mac_82598EB
:
2240 ixgbe_set_ivar(adapter
, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX
,
2243 case ixgbe_mac_82599EB
:
2244 case ixgbe_mac_X540
:
2245 case ixgbe_mac_X550
:
2246 case ixgbe_mac_X550EM_x
:
2247 ixgbe_set_ivar(adapter
, -1, 1, v_idx
);
2252 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITR(v_idx
), 1950);
2254 /* set up to autoclear timer, and the vectors */
2255 mask
= IXGBE_EIMS_ENABLE_MASK
;
2256 mask
&= ~(IXGBE_EIMS_OTHER
|
2257 IXGBE_EIMS_MAILBOX
|
2260 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIAC
, mask
);
2263 enum latency_range
{
2267 latency_invalid
= 255
2271 * ixgbe_update_itr - update the dynamic ITR value based on statistics
2272 * @q_vector: structure containing interrupt and ring information
2273 * @ring_container: structure containing ring performance data
2275 * Stores a new ITR value based on packets and byte
2276 * counts during the last interrupt. The advantage of per interrupt
2277 * computation is faster updates and more accurate ITR for the current
2278 * traffic pattern. Constants in this function were computed
2279 * based on theoretical maximum wire speed and thresholds were set based
2280 * on testing data as well as attempting to minimize response time
2281 * while increasing bulk throughput.
2282 * this functionality is controlled by the InterruptThrottleRate module
2283 * parameter (see ixgbe_param.c)
2285 static void ixgbe_update_itr(struct ixgbe_q_vector
*q_vector
,
2286 struct ixgbe_ring_container
*ring_container
)
2288 int bytes
= ring_container
->total_bytes
;
2289 int packets
= ring_container
->total_packets
;
2292 u8 itr_setting
= ring_container
->itr
;
2297 /* simple throttlerate management
2298 * 0-10MB/s lowest (100000 ints/s)
2299 * 10-20MB/s low (20000 ints/s)
2300 * 20-1249MB/s bulk (12000 ints/s)
2302 /* what was last interrupt timeslice? */
2303 timepassed_us
= q_vector
->itr
>> 2;
2304 if (timepassed_us
== 0)
2307 bytes_perint
= bytes
/ timepassed_us
; /* bytes/usec */
2309 switch (itr_setting
) {
2310 case lowest_latency
:
2311 if (bytes_perint
> 10)
2312 itr_setting
= low_latency
;
2315 if (bytes_perint
> 20)
2316 itr_setting
= bulk_latency
;
2317 else if (bytes_perint
<= 10)
2318 itr_setting
= lowest_latency
;
2321 if (bytes_perint
<= 20)
2322 itr_setting
= low_latency
;
2326 /* clear work counters since we have the values we need */
2327 ring_container
->total_bytes
= 0;
2328 ring_container
->total_packets
= 0;
2330 /* write updated itr to ring container */
2331 ring_container
->itr
= itr_setting
;
2335 * ixgbe_write_eitr - write EITR register in hardware specific way
2336 * @q_vector: structure containing interrupt and ring information
2338 * This function is made to be called by ethtool and by the driver
2339 * when it needs to update EITR registers at runtime. Hardware
2340 * specific quirks/differences are taken care of here.
2342 void ixgbe_write_eitr(struct ixgbe_q_vector
*q_vector
)
2344 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
2345 struct ixgbe_hw
*hw
= &adapter
->hw
;
2346 int v_idx
= q_vector
->v_idx
;
2347 u32 itr_reg
= q_vector
->itr
& IXGBE_MAX_EITR
;
2349 switch (adapter
->hw
.mac
.type
) {
2350 case ixgbe_mac_82598EB
:
2351 /* must write high and low 16 bits to reset counter */
2352 itr_reg
|= (itr_reg
<< 16);
2354 case ixgbe_mac_82599EB
:
2355 case ixgbe_mac_X540
:
2356 case ixgbe_mac_X550
:
2357 case ixgbe_mac_X550EM_x
:
2359 * set the WDIS bit to not clear the timer bits and cause an
2360 * immediate assertion of the interrupt
2362 itr_reg
|= IXGBE_EITR_CNT_WDIS
;
2367 IXGBE_WRITE_REG(hw
, IXGBE_EITR(v_idx
), itr_reg
);
2370 static void ixgbe_set_itr(struct ixgbe_q_vector
*q_vector
)
2372 u32 new_itr
= q_vector
->itr
;
2375 ixgbe_update_itr(q_vector
, &q_vector
->tx
);
2376 ixgbe_update_itr(q_vector
, &q_vector
->rx
);
2378 current_itr
= max(q_vector
->rx
.itr
, q_vector
->tx
.itr
);
2380 switch (current_itr
) {
2381 /* counts and packets in update_itr are dependent on these numbers */
2382 case lowest_latency
:
2383 new_itr
= IXGBE_100K_ITR
;
2386 new_itr
= IXGBE_20K_ITR
;
2389 new_itr
= IXGBE_12K_ITR
;
2395 if (new_itr
!= q_vector
->itr
) {
2396 /* do an exponential smoothing */
2397 new_itr
= (10 * new_itr
* q_vector
->itr
) /
2398 ((9 * new_itr
) + q_vector
->itr
);
2400 /* save the algorithm value here */
2401 q_vector
->itr
= new_itr
;
2403 ixgbe_write_eitr(q_vector
);
2408 * ixgbe_check_overtemp_subtask - check for over temperature
2409 * @adapter: pointer to adapter
2411 static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter
*adapter
)
2413 struct ixgbe_hw
*hw
= &adapter
->hw
;
2414 u32 eicr
= adapter
->interrupt_event
;
2416 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
2419 if (!(adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
) &&
2420 !(adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_EVENT
))
2423 adapter
->flags2
&= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT
;
2425 switch (hw
->device_id
) {
2426 case IXGBE_DEV_ID_82599_T3_LOM
:
2428 * Since the warning interrupt is for both ports
2429 * we don't have to check if:
2430 * - This interrupt wasn't for our port.
2431 * - We may have missed the interrupt so always have to
2432 * check if we got a LSC
2434 if (!(eicr
& IXGBE_EICR_GPI_SDP0_8259X
) &&
2435 !(eicr
& IXGBE_EICR_LSC
))
2438 if (!(eicr
& IXGBE_EICR_LSC
) && hw
->mac
.ops
.check_link
) {
2440 bool link_up
= false;
2442 hw
->mac
.ops
.check_link(hw
, &speed
, &link_up
, false);
2448 /* Check if this is not due to overtemp */
2449 if (hw
->phy
.ops
.check_overtemp(hw
) != IXGBE_ERR_OVERTEMP
)
2454 if (adapter
->hw
.mac
.type
>= ixgbe_mac_X540
)
2456 if (!(eicr
& IXGBE_EICR_GPI_SDP0(hw
)))
2460 e_crit(drv
, "%s\n", ixgbe_overheat_msg
);
2462 adapter
->interrupt_event
= 0;
2465 static void ixgbe_check_fan_failure(struct ixgbe_adapter
*adapter
, u32 eicr
)
2467 struct ixgbe_hw
*hw
= &adapter
->hw
;
2469 if ((adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) &&
2470 (eicr
& IXGBE_EICR_GPI_SDP1(hw
))) {
2471 e_crit(probe
, "Fan has stopped, replace the adapter\n");
2472 /* write to clear the interrupt */
2473 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP1(hw
));
2477 static void ixgbe_check_overtemp_event(struct ixgbe_adapter
*adapter
, u32 eicr
)
2479 struct ixgbe_hw
*hw
= &adapter
->hw
;
2481 if (!(adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
))
2484 switch (adapter
->hw
.mac
.type
) {
2485 case ixgbe_mac_82599EB
:
2487 * Need to check link state so complete overtemp check
2490 if (((eicr
& IXGBE_EICR_GPI_SDP0(hw
)) ||
2491 (eicr
& IXGBE_EICR_LSC
)) &&
2492 (!test_bit(__IXGBE_DOWN
, &adapter
->state
))) {
2493 adapter
->interrupt_event
= eicr
;
2494 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_EVENT
;
2495 ixgbe_service_event_schedule(adapter
);
2499 case ixgbe_mac_X540
:
2500 if (!(eicr
& IXGBE_EICR_TS
))
2507 e_crit(drv
, "%s\n", ixgbe_overheat_msg
);
2510 static inline bool ixgbe_is_sfp(struct ixgbe_hw
*hw
)
2512 switch (hw
->mac
.type
) {
2513 case ixgbe_mac_82598EB
:
2514 if (hw
->phy
.type
== ixgbe_phy_nl
)
2517 case ixgbe_mac_82599EB
:
2518 case ixgbe_mac_X550EM_x
:
2519 switch (hw
->mac
.ops
.get_media_type(hw
)) {
2520 case ixgbe_media_type_fiber
:
2521 case ixgbe_media_type_fiber_qsfp
:
2531 static void ixgbe_check_sfp_event(struct ixgbe_adapter
*adapter
, u32 eicr
)
2533 struct ixgbe_hw
*hw
= &adapter
->hw
;
2534 u32 eicr_mask
= IXGBE_EICR_GPI_SDP2(hw
);
2536 if (!ixgbe_is_sfp(hw
))
2539 /* Later MAC's use different SDP */
2540 if (hw
->mac
.type
>= ixgbe_mac_X540
)
2541 eicr_mask
= IXGBE_EICR_GPI_SDP0_X540
;
2543 if (eicr
& eicr_mask
) {
2544 /* Clear the interrupt */
2545 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, eicr_mask
);
2546 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
2547 adapter
->flags2
|= IXGBE_FLAG2_SFP_NEEDS_RESET
;
2548 adapter
->sfp_poll_time
= 0;
2549 ixgbe_service_event_schedule(adapter
);
2553 if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
&&
2554 (eicr
& IXGBE_EICR_GPI_SDP1(hw
))) {
2555 /* Clear the interrupt */
2556 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP1(hw
));
2557 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
2558 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_CONFIG
;
2559 ixgbe_service_event_schedule(adapter
);
2564 static void ixgbe_check_lsc(struct ixgbe_adapter
*adapter
)
2566 struct ixgbe_hw
*hw
= &adapter
->hw
;
2569 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
2570 adapter
->link_check_timeout
= jiffies
;
2571 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
2572 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_EIMC_LSC
);
2573 IXGBE_WRITE_FLUSH(hw
);
2574 ixgbe_service_event_schedule(adapter
);
2578 static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter
*adapter
,
2582 struct ixgbe_hw
*hw
= &adapter
->hw
;
2584 switch (hw
->mac
.type
) {
2585 case ixgbe_mac_82598EB
:
2586 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
2587 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, mask
);
2589 case ixgbe_mac_82599EB
:
2590 case ixgbe_mac_X540
:
2591 case ixgbe_mac_X550
:
2592 case ixgbe_mac_X550EM_x
:
2593 mask
= (qmask
& 0xFFFFFFFF);
2595 IXGBE_WRITE_REG(hw
, IXGBE_EIMS_EX(0), mask
);
2596 mask
= (qmask
>> 32);
2598 IXGBE_WRITE_REG(hw
, IXGBE_EIMS_EX(1), mask
);
2603 /* skip the flush */
2606 static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter
*adapter
,
2610 struct ixgbe_hw
*hw
= &adapter
->hw
;
2612 switch (hw
->mac
.type
) {
2613 case ixgbe_mac_82598EB
:
2614 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
2615 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, mask
);
2617 case ixgbe_mac_82599EB
:
2618 case ixgbe_mac_X540
:
2619 case ixgbe_mac_X550
:
2620 case ixgbe_mac_X550EM_x
:
2621 mask
= (qmask
& 0xFFFFFFFF);
2623 IXGBE_WRITE_REG(hw
, IXGBE_EIMC_EX(0), mask
);
2624 mask
= (qmask
>> 32);
2626 IXGBE_WRITE_REG(hw
, IXGBE_EIMC_EX(1), mask
);
2631 /* skip the flush */
2635 * ixgbe_irq_enable - Enable default interrupt generation settings
2636 * @adapter: board private structure
2638 static inline void ixgbe_irq_enable(struct ixgbe_adapter
*adapter
, bool queues
,
2641 struct ixgbe_hw
*hw
= &adapter
->hw
;
2642 u32 mask
= (IXGBE_EIMS_ENABLE_MASK
& ~IXGBE_EIMS_RTX_QUEUE
);
2644 /* don't reenable LSC while waiting for link */
2645 if (adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
)
2646 mask
&= ~IXGBE_EIMS_LSC
;
2648 if (adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
)
2649 switch (adapter
->hw
.mac
.type
) {
2650 case ixgbe_mac_82599EB
:
2651 mask
|= IXGBE_EIMS_GPI_SDP0(hw
);
2653 case ixgbe_mac_X540
:
2654 case ixgbe_mac_X550
:
2655 case ixgbe_mac_X550EM_x
:
2656 mask
|= IXGBE_EIMS_TS
;
2661 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
)
2662 mask
|= IXGBE_EIMS_GPI_SDP1(hw
);
2663 switch (adapter
->hw
.mac
.type
) {
2664 case ixgbe_mac_82599EB
:
2665 mask
|= IXGBE_EIMS_GPI_SDP1(hw
);
2666 mask
|= IXGBE_EIMS_GPI_SDP2(hw
);
2668 case ixgbe_mac_X540
:
2669 case ixgbe_mac_X550
:
2670 case ixgbe_mac_X550EM_x
:
2671 if (adapter
->hw
.device_id
== IXGBE_DEV_ID_X550EM_X_SFP
)
2672 mask
|= IXGBE_EIMS_GPI_SDP0(&adapter
->hw
);
2673 if (adapter
->hw
.phy
.type
== ixgbe_phy_x550em_ext_t
)
2674 mask
|= IXGBE_EICR_GPI_SDP0_X540
;
2675 mask
|= IXGBE_EIMS_ECC
;
2676 mask
|= IXGBE_EIMS_MAILBOX
;
2682 if ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) &&
2683 !(adapter
->flags2
& IXGBE_FLAG2_FDIR_REQUIRES_REINIT
))
2684 mask
|= IXGBE_EIMS_FLOW_DIR
;
2686 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS
, mask
);
2688 ixgbe_irq_enable_queues(adapter
, ~0);
2690 IXGBE_WRITE_FLUSH(&adapter
->hw
);
2693 static irqreturn_t
ixgbe_msix_other(int irq
, void *data
)
2695 struct ixgbe_adapter
*adapter
= data
;
2696 struct ixgbe_hw
*hw
= &adapter
->hw
;
2700 * Workaround for Silicon errata. Use clear-by-write instead
2701 * of clear-by-read. Reading with EICS will return the
2702 * interrupt causes without clearing, which later be done
2703 * with the write to EICR.
2705 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICS
);
2707 /* The lower 16bits of the EICR register are for the queue interrupts
2708 * which should be masked here in order to not accidentally clear them if
2709 * the bits are high when ixgbe_msix_other is called. There is a race
2710 * condition otherwise which results in possible performance loss
2711 * especially if the ixgbe_msix_other interrupt is triggering
2712 * consistently (as it would when PPS is turned on for the X540 device)
2716 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, eicr
);
2718 if (eicr
& IXGBE_EICR_LSC
)
2719 ixgbe_check_lsc(adapter
);
2721 if (eicr
& IXGBE_EICR_MAILBOX
)
2722 ixgbe_msg_task(adapter
);
2724 switch (hw
->mac
.type
) {
2725 case ixgbe_mac_82599EB
:
2726 case ixgbe_mac_X540
:
2727 case ixgbe_mac_X550
:
2728 case ixgbe_mac_X550EM_x
:
2729 if (hw
->phy
.type
== ixgbe_phy_x550em_ext_t
&&
2730 (eicr
& IXGBE_EICR_GPI_SDP0_X540
)) {
2731 adapter
->flags2
|= IXGBE_FLAG2_PHY_INTERRUPT
;
2732 ixgbe_service_event_schedule(adapter
);
2733 IXGBE_WRITE_REG(hw
, IXGBE_EICR
,
2734 IXGBE_EICR_GPI_SDP0_X540
);
2736 if (eicr
& IXGBE_EICR_ECC
) {
2737 e_info(link
, "Received ECC Err, initiating reset\n");
2738 adapter
->flags2
|= IXGBE_FLAG2_RESET_REQUESTED
;
2739 ixgbe_service_event_schedule(adapter
);
2740 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_ECC
);
2742 /* Handle Flow Director Full threshold interrupt */
2743 if (eicr
& IXGBE_EICR_FLOW_DIR
) {
2744 int reinit_count
= 0;
2746 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2747 struct ixgbe_ring
*ring
= adapter
->tx_ring
[i
];
2748 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE
,
2753 /* no more flow director interrupts until after init */
2754 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_EIMC_FLOW_DIR
);
2755 adapter
->flags2
|= IXGBE_FLAG2_FDIR_REQUIRES_REINIT
;
2756 ixgbe_service_event_schedule(adapter
);
2759 ixgbe_check_sfp_event(adapter
, eicr
);
2760 ixgbe_check_overtemp_event(adapter
, eicr
);
2766 ixgbe_check_fan_failure(adapter
, eicr
);
2768 if (unlikely(eicr
& IXGBE_EICR_TIMESYNC
))
2769 ixgbe_ptp_check_pps_event(adapter
);
2771 /* re-enable the original interrupt state, no lsc, no queues */
2772 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2773 ixgbe_irq_enable(adapter
, false, false);
2778 static irqreturn_t
ixgbe_msix_clean_rings(int irq
, void *data
)
2780 struct ixgbe_q_vector
*q_vector
= data
;
2782 /* EIAM disabled interrupts (on this vector) for us */
2784 if (q_vector
->rx
.ring
|| q_vector
->tx
.ring
)
2785 napi_schedule_irqoff(&q_vector
->napi
);
2791 * ixgbe_poll - NAPI Rx polling callback
2792 * @napi: structure for representing this polling device
2793 * @budget: how many packets driver is allowed to clean
2795 * This function is used for legacy and MSI, NAPI mode
2797 int ixgbe_poll(struct napi_struct
*napi
, int budget
)
2799 struct ixgbe_q_vector
*q_vector
=
2800 container_of(napi
, struct ixgbe_q_vector
, napi
);
2801 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
2802 struct ixgbe_ring
*ring
;
2803 int per_ring_budget
, work_done
= 0;
2804 bool clean_complete
= true;
2806 #ifdef CONFIG_IXGBE_DCA
2807 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
2808 ixgbe_update_dca(q_vector
);
2811 ixgbe_for_each_ring(ring
, q_vector
->tx
) {
2812 if (!ixgbe_clean_tx_irq(q_vector
, ring
, budget
))
2813 clean_complete
= false;
2816 /* Exit if we are called by netpoll or busy polling is active */
2817 if ((budget
<= 0) || !ixgbe_qv_lock_napi(q_vector
))
2820 /* attempt to distribute budget to each queue fairly, but don't allow
2821 * the budget to go below 1 because we'll exit polling */
2822 if (q_vector
->rx
.count
> 1)
2823 per_ring_budget
= max(budget
/q_vector
->rx
.count
, 1);
2825 per_ring_budget
= budget
;
2827 ixgbe_for_each_ring(ring
, q_vector
->rx
) {
2828 int cleaned
= ixgbe_clean_rx_irq(q_vector
, ring
,
2831 work_done
+= cleaned
;
2832 if (cleaned
>= per_ring_budget
)
2833 clean_complete
= false;
2836 ixgbe_qv_unlock_napi(q_vector
);
2837 /* If all work not completed, return budget and keep polling */
2838 if (!clean_complete
)
2841 /* all work done, exit the polling mode */
2842 napi_complete_done(napi
, work_done
);
2843 if (adapter
->rx_itr_setting
& 1)
2844 ixgbe_set_itr(q_vector
);
2845 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2846 ixgbe_irq_enable_queues(adapter
, ((u64
)1 << q_vector
->v_idx
));
2852 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2853 * @adapter: board private structure
2855 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2856 * interrupts from the kernel.
2858 static int ixgbe_request_msix_irqs(struct ixgbe_adapter
*adapter
)
2860 struct net_device
*netdev
= adapter
->netdev
;
2864 for (vector
= 0; vector
< adapter
->num_q_vectors
; vector
++) {
2865 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[vector
];
2866 struct msix_entry
*entry
= &adapter
->msix_entries
[vector
];
2868 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
2869 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2870 "%s-%s-%d", netdev
->name
, "TxRx", ri
++);
2872 } else if (q_vector
->rx
.ring
) {
2873 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2874 "%s-%s-%d", netdev
->name
, "rx", ri
++);
2875 } else if (q_vector
->tx
.ring
) {
2876 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2877 "%s-%s-%d", netdev
->name
, "tx", ti
++);
2879 /* skip this unused q_vector */
2882 err
= request_irq(entry
->vector
, &ixgbe_msix_clean_rings
, 0,
2883 q_vector
->name
, q_vector
);
2885 e_err(probe
, "request_irq failed for MSIX interrupt "
2886 "Error: %d\n", err
);
2887 goto free_queue_irqs
;
2889 /* If Flow Director is enabled, set interrupt affinity */
2890 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
2891 /* assign the mask for this irq */
2892 irq_set_affinity_hint(entry
->vector
,
2893 &q_vector
->affinity_mask
);
2897 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
2898 ixgbe_msix_other
, 0, netdev
->name
, adapter
);
2900 e_err(probe
, "request_irq for msix_other failed: %d\n", err
);
2901 goto free_queue_irqs
;
2909 irq_set_affinity_hint(adapter
->msix_entries
[vector
].vector
,
2911 free_irq(adapter
->msix_entries
[vector
].vector
,
2912 adapter
->q_vector
[vector
]);
2914 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
2915 pci_disable_msix(adapter
->pdev
);
2916 kfree(adapter
->msix_entries
);
2917 adapter
->msix_entries
= NULL
;
2922 * ixgbe_intr - legacy mode Interrupt Handler
2923 * @irq: interrupt number
2924 * @data: pointer to a network interface device structure
2926 static irqreturn_t
ixgbe_intr(int irq
, void *data
)
2928 struct ixgbe_adapter
*adapter
= data
;
2929 struct ixgbe_hw
*hw
= &adapter
->hw
;
2930 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[0];
2934 * Workaround for silicon errata #26 on 82598. Mask the interrupt
2935 * before the read of EICR.
2937 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_IRQ_CLEAR_MASK
);
2939 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2940 * therefore no explicit interrupt disable is necessary */
2941 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICR
);
2944 * shared interrupt alert!
2945 * make sure interrupts are enabled because the read will
2946 * have disabled interrupts due to EIAM
2947 * finish the workaround of silicon errata on 82598. Unmask
2948 * the interrupt that we masked before the EICR read.
2950 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2951 ixgbe_irq_enable(adapter
, true, true);
2952 return IRQ_NONE
; /* Not our interrupt */
2955 if (eicr
& IXGBE_EICR_LSC
)
2956 ixgbe_check_lsc(adapter
);
2958 switch (hw
->mac
.type
) {
2959 case ixgbe_mac_82599EB
:
2960 ixgbe_check_sfp_event(adapter
, eicr
);
2962 case ixgbe_mac_X540
:
2963 case ixgbe_mac_X550
:
2964 case ixgbe_mac_X550EM_x
:
2965 if (eicr
& IXGBE_EICR_ECC
) {
2966 e_info(link
, "Received ECC Err, initiating reset\n");
2967 adapter
->flags2
|= IXGBE_FLAG2_RESET_REQUESTED
;
2968 ixgbe_service_event_schedule(adapter
);
2969 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_ECC
);
2971 ixgbe_check_overtemp_event(adapter
, eicr
);
2977 ixgbe_check_fan_failure(adapter
, eicr
);
2978 if (unlikely(eicr
& IXGBE_EICR_TIMESYNC
))
2979 ixgbe_ptp_check_pps_event(adapter
);
2981 /* would disable interrupts here but EIAM disabled it */
2982 napi_schedule_irqoff(&q_vector
->napi
);
2985 * re-enable link(maybe) and non-queue interrupts, no flush.
2986 * ixgbe_poll will re-enable the queue interrupts
2988 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2989 ixgbe_irq_enable(adapter
, false, false);
2995 * ixgbe_request_irq - initialize interrupts
2996 * @adapter: board private structure
2998 * Attempts to configure interrupts using the best available
2999 * capabilities of the hardware and kernel.
3001 static int ixgbe_request_irq(struct ixgbe_adapter
*adapter
)
3003 struct net_device
*netdev
= adapter
->netdev
;
3006 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
3007 err
= ixgbe_request_msix_irqs(adapter
);
3008 else if (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
)
3009 err
= request_irq(adapter
->pdev
->irq
, ixgbe_intr
, 0,
3010 netdev
->name
, adapter
);
3012 err
= request_irq(adapter
->pdev
->irq
, ixgbe_intr
, IRQF_SHARED
,
3013 netdev
->name
, adapter
);
3016 e_err(probe
, "request_irq failed, Error %d\n", err
);
3021 static void ixgbe_free_irq(struct ixgbe_adapter
*adapter
)
3025 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)) {
3026 free_irq(adapter
->pdev
->irq
, adapter
);
3030 for (vector
= 0; vector
< adapter
->num_q_vectors
; vector
++) {
3031 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[vector
];
3032 struct msix_entry
*entry
= &adapter
->msix_entries
[vector
];
3034 /* free only the irqs that were actually requested */
3035 if (!q_vector
->rx
.ring
&& !q_vector
->tx
.ring
)
3038 /* clear the affinity_mask in the IRQ descriptor */
3039 irq_set_affinity_hint(entry
->vector
, NULL
);
3041 free_irq(entry
->vector
, q_vector
);
3044 free_irq(adapter
->msix_entries
[vector
++].vector
, adapter
);
3048 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
3049 * @adapter: board private structure
3051 static inline void ixgbe_irq_disable(struct ixgbe_adapter
*adapter
)
3053 switch (adapter
->hw
.mac
.type
) {
3054 case ixgbe_mac_82598EB
:
3055 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, ~0);
3057 case ixgbe_mac_82599EB
:
3058 case ixgbe_mac_X540
:
3059 case ixgbe_mac_X550
:
3060 case ixgbe_mac_X550EM_x
:
3061 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, 0xFFFF0000);
3062 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(0), ~0);
3063 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(1), ~0);
3068 IXGBE_WRITE_FLUSH(&adapter
->hw
);
3069 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
3072 for (vector
= 0; vector
< adapter
->num_q_vectors
; vector
++)
3073 synchronize_irq(adapter
->msix_entries
[vector
].vector
);
3075 synchronize_irq(adapter
->msix_entries
[vector
++].vector
);
3077 synchronize_irq(adapter
->pdev
->irq
);
3082 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3085 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter
*adapter
)
3087 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[0];
3089 ixgbe_write_eitr(q_vector
);
3091 ixgbe_set_ivar(adapter
, 0, 0, 0);
3092 ixgbe_set_ivar(adapter
, 1, 0, 0);
3094 e_info(hw
, "Legacy interrupt IVAR setup done\n");
3098 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3099 * @adapter: board private structure
3100 * @ring: structure containing ring specific data
3102 * Configure the Tx descriptor ring after a reset.
3104 void ixgbe_configure_tx_ring(struct ixgbe_adapter
*adapter
,
3105 struct ixgbe_ring
*ring
)
3107 struct ixgbe_hw
*hw
= &adapter
->hw
;
3108 u64 tdba
= ring
->dma
;
3110 u32 txdctl
= IXGBE_TXDCTL_ENABLE
;
3111 u8 reg_idx
= ring
->reg_idx
;
3113 /* disable queue to avoid issues while updating state */
3114 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
), 0);
3115 IXGBE_WRITE_FLUSH(hw
);
3117 IXGBE_WRITE_REG(hw
, IXGBE_TDBAL(reg_idx
),
3118 (tdba
& DMA_BIT_MASK(32)));
3119 IXGBE_WRITE_REG(hw
, IXGBE_TDBAH(reg_idx
), (tdba
>> 32));
3120 IXGBE_WRITE_REG(hw
, IXGBE_TDLEN(reg_idx
),
3121 ring
->count
* sizeof(union ixgbe_adv_tx_desc
));
3122 IXGBE_WRITE_REG(hw
, IXGBE_TDH(reg_idx
), 0);
3123 IXGBE_WRITE_REG(hw
, IXGBE_TDT(reg_idx
), 0);
3124 ring
->tail
= adapter
->io_addr
+ IXGBE_TDT(reg_idx
);
3127 * set WTHRESH to encourage burst writeback, it should not be set
3128 * higher than 1 when:
3129 * - ITR is 0 as it could cause false TX hangs
3130 * - ITR is set to > 100k int/sec and BQL is enabled
3132 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3133 * to or less than the number of on chip descriptors, which is
3136 if (!ring
->q_vector
|| (ring
->q_vector
->itr
< IXGBE_100K_ITR
))
3137 txdctl
|= (1 << 16); /* WTHRESH = 1 */
3139 txdctl
|= (8 << 16); /* WTHRESH = 8 */
3142 * Setting PTHRESH to 32 both improves performance
3143 * and avoids a TX hang with DFP enabled
3145 txdctl
|= (1 << 8) | /* HTHRESH = 1 */
3146 32; /* PTHRESH = 32 */
3148 /* reinitialize flowdirector state */
3149 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
3150 ring
->atr_sample_rate
= adapter
->atr_sample_rate
;
3151 ring
->atr_count
= 0;
3152 set_bit(__IXGBE_TX_FDIR_INIT_DONE
, &ring
->state
);
3154 ring
->atr_sample_rate
= 0;
3157 /* initialize XPS */
3158 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE
, &ring
->state
)) {
3159 struct ixgbe_q_vector
*q_vector
= ring
->q_vector
;
3162 netif_set_xps_queue(ring
->netdev
,
3163 &q_vector
->affinity_mask
,
3167 clear_bit(__IXGBE_HANG_CHECK_ARMED
, &ring
->state
);
3170 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
), txdctl
);
3172 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3173 if (hw
->mac
.type
== ixgbe_mac_82598EB
&&
3174 !(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
3177 /* poll to verify queue is enabled */
3179 usleep_range(1000, 2000);
3180 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(reg_idx
));
3181 } while (--wait_loop
&& !(txdctl
& IXGBE_TXDCTL_ENABLE
));
3183 e_err(drv
, "Could not enable Tx Queue %d\n", reg_idx
);
3186 static void ixgbe_setup_mtqc(struct ixgbe_adapter
*adapter
)
3188 struct ixgbe_hw
*hw
= &adapter
->hw
;
3190 u8 tcs
= netdev_get_num_tc(adapter
->netdev
);
3192 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
3195 /* disable the arbiter while setting MTQC */
3196 rttdcs
= IXGBE_READ_REG(hw
, IXGBE_RTTDCS
);
3197 rttdcs
|= IXGBE_RTTDCS_ARBDIS
;
3198 IXGBE_WRITE_REG(hw
, IXGBE_RTTDCS
, rttdcs
);
3200 /* set transmit pool layout */
3201 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
3202 mtqc
= IXGBE_MTQC_VT_ENA
;
3204 mtqc
|= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_8TC_8TQ
;
3206 mtqc
|= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_4TC_4TQ
;
3207 else if (adapter
->ring_feature
[RING_F_RSS
].indices
== 4)
3208 mtqc
|= IXGBE_MTQC_32VF
;
3210 mtqc
|= IXGBE_MTQC_64VF
;
3213 mtqc
= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_8TC_8TQ
;
3215 mtqc
= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_4TC_4TQ
;
3217 mtqc
= IXGBE_MTQC_64Q_1PB
;
3220 IXGBE_WRITE_REG(hw
, IXGBE_MTQC
, mtqc
);
3222 /* Enable Security TX Buffer IFG for multiple pb */
3224 u32 sectx
= IXGBE_READ_REG(hw
, IXGBE_SECTXMINIFG
);
3225 sectx
|= IXGBE_SECTX_DCB
;
3226 IXGBE_WRITE_REG(hw
, IXGBE_SECTXMINIFG
, sectx
);
3229 /* re-enable the arbiter */
3230 rttdcs
&= ~IXGBE_RTTDCS_ARBDIS
;
3231 IXGBE_WRITE_REG(hw
, IXGBE_RTTDCS
, rttdcs
);
3235 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
3236 * @adapter: board private structure
3238 * Configure the Tx unit of the MAC after a reset.
3240 static void ixgbe_configure_tx(struct ixgbe_adapter
*adapter
)
3242 struct ixgbe_hw
*hw
= &adapter
->hw
;
3246 ixgbe_setup_mtqc(adapter
);
3248 if (hw
->mac
.type
!= ixgbe_mac_82598EB
) {
3249 /* DMATXCTL.EN must be before Tx queues are enabled */
3250 dmatxctl
= IXGBE_READ_REG(hw
, IXGBE_DMATXCTL
);
3251 dmatxctl
|= IXGBE_DMATXCTL_TE
;
3252 IXGBE_WRITE_REG(hw
, IXGBE_DMATXCTL
, dmatxctl
);
3255 /* Setup the HW Tx Head and Tail descriptor pointers */
3256 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
3257 ixgbe_configure_tx_ring(adapter
, adapter
->tx_ring
[i
]);
3260 static void ixgbe_enable_rx_drop(struct ixgbe_adapter
*adapter
,
3261 struct ixgbe_ring
*ring
)
3263 struct ixgbe_hw
*hw
= &adapter
->hw
;
3264 u8 reg_idx
= ring
->reg_idx
;
3265 u32 srrctl
= IXGBE_READ_REG(hw
, IXGBE_SRRCTL(reg_idx
));
3267 srrctl
|= IXGBE_SRRCTL_DROP_EN
;
3269 IXGBE_WRITE_REG(hw
, IXGBE_SRRCTL(reg_idx
), srrctl
);
3272 static void ixgbe_disable_rx_drop(struct ixgbe_adapter
*adapter
,
3273 struct ixgbe_ring
*ring
)
3275 struct ixgbe_hw
*hw
= &adapter
->hw
;
3276 u8 reg_idx
= ring
->reg_idx
;
3277 u32 srrctl
= IXGBE_READ_REG(hw
, IXGBE_SRRCTL(reg_idx
));
3279 srrctl
&= ~IXGBE_SRRCTL_DROP_EN
;
3281 IXGBE_WRITE_REG(hw
, IXGBE_SRRCTL(reg_idx
), srrctl
);
3284 #ifdef CONFIG_IXGBE_DCB
3285 void ixgbe_set_rx_drop_en(struct ixgbe_adapter
*adapter
)
3287 static void ixgbe_set_rx_drop_en(struct ixgbe_adapter
*adapter
)
3291 bool pfc_en
= adapter
->dcb_cfg
.pfc_mode_enable
;
3293 if (adapter
->ixgbe_ieee_pfc
)
3294 pfc_en
|= !!(adapter
->ixgbe_ieee_pfc
->pfc_en
);
3297 * We should set the drop enable bit if:
3300 * Number of Rx queues > 1 and flow control is disabled
3302 * This allows us to avoid head of line blocking for security
3303 * and performance reasons.
3305 if (adapter
->num_vfs
|| (adapter
->num_rx_queues
> 1 &&
3306 !(adapter
->hw
.fc
.current_mode
& ixgbe_fc_tx_pause
) && !pfc_en
)) {
3307 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3308 ixgbe_enable_rx_drop(adapter
, adapter
->rx_ring
[i
]);
3310 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3311 ixgbe_disable_rx_drop(adapter
, adapter
->rx_ring
[i
]);
3315 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
3317 static void ixgbe_configure_srrctl(struct ixgbe_adapter
*adapter
,
3318 struct ixgbe_ring
*rx_ring
)
3320 struct ixgbe_hw
*hw
= &adapter
->hw
;
3322 u8 reg_idx
= rx_ring
->reg_idx
;
3324 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
3325 u16 mask
= adapter
->ring_feature
[RING_F_RSS
].mask
;
3328 * if VMDq is not active we must program one srrctl register
3329 * per RSS queue since we have enabled RDRXCTL.MVMEN
3334 /* configure header buffer length, needed for RSC */
3335 srrctl
= IXGBE_RX_HDR_SIZE
<< IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT
;
3337 /* configure the packet buffer length */
3338 srrctl
|= ixgbe_rx_bufsz(rx_ring
) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
3340 /* configure descriptor type */
3341 srrctl
|= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF
;
3343 IXGBE_WRITE_REG(hw
, IXGBE_SRRCTL(reg_idx
), srrctl
);
3347 * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
3348 * @adapter: device handle
3350 * - 82598/82599/X540: 128
3351 * - X550(non-SRIOV mode): 512
3352 * - X550(SRIOV mode): 64
3354 u32
ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter
*adapter
)
3356 if (adapter
->hw
.mac
.type
< ixgbe_mac_X550
)
3358 else if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
3365 * ixgbe_store_reta - Write the RETA table to HW
3366 * @adapter: device handle
3368 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3370 void ixgbe_store_reta(struct ixgbe_adapter
*adapter
)
3372 u32 i
, reta_entries
= ixgbe_rss_indir_tbl_entries(adapter
);
3373 struct ixgbe_hw
*hw
= &adapter
->hw
;
3376 u8
*indir_tbl
= adapter
->rss_indir_tbl
;
3378 /* Fill out the redirection table as follows:
3379 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3381 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3382 * - X550: 8 bit wide entries containing 6 bit RSS index
3384 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
3385 indices_multi
= 0x11;
3387 indices_multi
= 0x1;
3389 /* Write redirection table to HW */
3390 for (i
= 0; i
< reta_entries
; i
++) {
3391 reta
|= indices_multi
* indir_tbl
[i
] << (i
& 0x3) * 8;
3394 IXGBE_WRITE_REG(hw
, IXGBE_RETA(i
>> 2), reta
);
3396 IXGBE_WRITE_REG(hw
, IXGBE_ERETA((i
>> 2) - 32),
3404 * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
3405 * @adapter: device handle
3407 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3409 static void ixgbe_store_vfreta(struct ixgbe_adapter
*adapter
)
3411 u32 i
, reta_entries
= ixgbe_rss_indir_tbl_entries(adapter
);
3412 struct ixgbe_hw
*hw
= &adapter
->hw
;
3414 unsigned int pf_pool
= adapter
->num_vfs
;
3416 /* Write redirection table to HW */
3417 for (i
= 0; i
< reta_entries
; i
++) {
3418 vfreta
|= (u32
)adapter
->rss_indir_tbl
[i
] << (i
& 0x3) * 8;
3420 IXGBE_WRITE_REG(hw
, IXGBE_PFVFRETA(i
>> 2, pf_pool
),
3427 static void ixgbe_setup_reta(struct ixgbe_adapter
*adapter
)
3429 struct ixgbe_hw
*hw
= &adapter
->hw
;
3431 u32 reta_entries
= ixgbe_rss_indir_tbl_entries(adapter
);
3432 u16 rss_i
= adapter
->ring_feature
[RING_F_RSS
].indices
;
3434 /* Program table for at least 2 queues w/ SR-IOV so that VFs can
3435 * make full use of any rings they may have. We will use the
3436 * PSRTYPE register to control how many rings we use within the PF.
3438 if ((adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) && (rss_i
< 2))
3441 /* Fill out hash function seeds */
3442 for (i
= 0; i
< 10; i
++)
3443 IXGBE_WRITE_REG(hw
, IXGBE_RSSRK(i
), adapter
->rss_key
[i
]);
3445 /* Fill out redirection table */
3446 memset(adapter
->rss_indir_tbl
, 0, sizeof(adapter
->rss_indir_tbl
));
3448 for (i
= 0, j
= 0; i
< reta_entries
; i
++, j
++) {
3452 adapter
->rss_indir_tbl
[i
] = j
;
3455 ixgbe_store_reta(adapter
);
3458 static void ixgbe_setup_vfreta(struct ixgbe_adapter
*adapter
)
3460 struct ixgbe_hw
*hw
= &adapter
->hw
;
3461 u16 rss_i
= adapter
->ring_feature
[RING_F_RSS
].indices
;
3462 unsigned int pf_pool
= adapter
->num_vfs
;
3465 /* Fill out hash function seeds */
3466 for (i
= 0; i
< 10; i
++)
3467 IXGBE_WRITE_REG(hw
, IXGBE_PFVFRSSRK(i
, pf_pool
),
3468 adapter
->rss_key
[i
]);
3470 /* Fill out the redirection table */
3471 for (i
= 0, j
= 0; i
< 64; i
++, j
++) {
3475 adapter
->rss_indir_tbl
[i
] = j
;
3478 ixgbe_store_vfreta(adapter
);
3481 static void ixgbe_setup_mrqc(struct ixgbe_adapter
*adapter
)
3483 struct ixgbe_hw
*hw
= &adapter
->hw
;
3484 u32 mrqc
= 0, rss_field
= 0, vfmrqc
= 0;
3487 /* Disable indicating checksum in descriptor, enables RSS hash */
3488 rxcsum
= IXGBE_READ_REG(hw
, IXGBE_RXCSUM
);
3489 rxcsum
|= IXGBE_RXCSUM_PCSD
;
3490 IXGBE_WRITE_REG(hw
, IXGBE_RXCSUM
, rxcsum
);
3492 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
3493 if (adapter
->ring_feature
[RING_F_RSS
].mask
)
3494 mrqc
= IXGBE_MRQC_RSSEN
;
3496 u8 tcs
= netdev_get_num_tc(adapter
->netdev
);
3498 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
3500 mrqc
= IXGBE_MRQC_VMDQRT8TCEN
; /* 8 TCs */
3502 mrqc
= IXGBE_MRQC_VMDQRT4TCEN
; /* 4 TCs */
3503 else if (adapter
->ring_feature
[RING_F_RSS
].indices
== 4)
3504 mrqc
= IXGBE_MRQC_VMDQRSS32EN
;
3506 mrqc
= IXGBE_MRQC_VMDQRSS64EN
;
3509 mrqc
= IXGBE_MRQC_RTRSS8TCEN
;
3511 mrqc
= IXGBE_MRQC_RTRSS4TCEN
;
3513 mrqc
= IXGBE_MRQC_RSSEN
;
3517 /* Perform hash on these packet types */
3518 rss_field
|= IXGBE_MRQC_RSS_FIELD_IPV4
|
3519 IXGBE_MRQC_RSS_FIELD_IPV4_TCP
|
3520 IXGBE_MRQC_RSS_FIELD_IPV6
|
3521 IXGBE_MRQC_RSS_FIELD_IPV6_TCP
;
3523 if (adapter
->flags2
& IXGBE_FLAG2_RSS_FIELD_IPV4_UDP
)
3524 rss_field
|= IXGBE_MRQC_RSS_FIELD_IPV4_UDP
;
3525 if (adapter
->flags2
& IXGBE_FLAG2_RSS_FIELD_IPV6_UDP
)
3526 rss_field
|= IXGBE_MRQC_RSS_FIELD_IPV6_UDP
;
3528 netdev_rss_key_fill(adapter
->rss_key
, sizeof(adapter
->rss_key
));
3529 if ((hw
->mac
.type
>= ixgbe_mac_X550
) &&
3530 (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)) {
3531 unsigned int pf_pool
= adapter
->num_vfs
;
3533 /* Enable VF RSS mode */
3534 mrqc
|= IXGBE_MRQC_MULTIPLE_RSS
;
3535 IXGBE_WRITE_REG(hw
, IXGBE_MRQC
, mrqc
);
3537 /* Setup RSS through the VF registers */
3538 ixgbe_setup_vfreta(adapter
);
3539 vfmrqc
= IXGBE_MRQC_RSSEN
;
3540 vfmrqc
|= rss_field
;
3541 IXGBE_WRITE_REG(hw
, IXGBE_PFVFMRQC(pf_pool
), vfmrqc
);
3543 ixgbe_setup_reta(adapter
);
3545 IXGBE_WRITE_REG(hw
, IXGBE_MRQC
, mrqc
);
3550 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3551 * @adapter: address of board private structure
3552 * @index: index of ring to set
3554 static void ixgbe_configure_rscctl(struct ixgbe_adapter
*adapter
,
3555 struct ixgbe_ring
*ring
)
3557 struct ixgbe_hw
*hw
= &adapter
->hw
;
3559 u8 reg_idx
= ring
->reg_idx
;
3561 if (!ring_is_rsc_enabled(ring
))
3564 rscctrl
= IXGBE_READ_REG(hw
, IXGBE_RSCCTL(reg_idx
));
3565 rscctrl
|= IXGBE_RSCCTL_RSCEN
;
3567 * we must limit the number of descriptors so that the
3568 * total size of max desc * buf_len is not greater
3571 rscctrl
|= IXGBE_RSCCTL_MAXDESC_16
;
3572 IXGBE_WRITE_REG(hw
, IXGBE_RSCCTL(reg_idx
), rscctrl
);
3575 #define IXGBE_MAX_RX_DESC_POLL 10
3576 static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter
*adapter
,
3577 struct ixgbe_ring
*ring
)
3579 struct ixgbe_hw
*hw
= &adapter
->hw
;
3580 int wait_loop
= IXGBE_MAX_RX_DESC_POLL
;
3582 u8 reg_idx
= ring
->reg_idx
;
3584 if (ixgbe_removed(hw
->hw_addr
))
3586 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3587 if (hw
->mac
.type
== ixgbe_mac_82598EB
&&
3588 !(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
3592 usleep_range(1000, 2000);
3593 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
3594 } while (--wait_loop
&& !(rxdctl
& IXGBE_RXDCTL_ENABLE
));
3597 e_err(drv
, "RXDCTL.ENABLE on Rx queue %d not set within "
3598 "the polling period\n", reg_idx
);
3602 void ixgbe_disable_rx_queue(struct ixgbe_adapter
*adapter
,
3603 struct ixgbe_ring
*ring
)
3605 struct ixgbe_hw
*hw
= &adapter
->hw
;
3606 int wait_loop
= IXGBE_MAX_RX_DESC_POLL
;
3608 u8 reg_idx
= ring
->reg_idx
;
3610 if (ixgbe_removed(hw
->hw_addr
))
3612 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
3613 rxdctl
&= ~IXGBE_RXDCTL_ENABLE
;
3615 /* write value back with RXDCTL.ENABLE bit cleared */
3616 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(reg_idx
), rxdctl
);
3618 if (hw
->mac
.type
== ixgbe_mac_82598EB
&&
3619 !(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
3622 /* the hardware may take up to 100us to really disable the rx queue */
3625 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
3626 } while (--wait_loop
&& (rxdctl
& IXGBE_RXDCTL_ENABLE
));
3629 e_err(drv
, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3630 "the polling period\n", reg_idx
);
3634 void ixgbe_configure_rx_ring(struct ixgbe_adapter
*adapter
,
3635 struct ixgbe_ring
*ring
)
3637 struct ixgbe_hw
*hw
= &adapter
->hw
;
3638 u64 rdba
= ring
->dma
;
3640 u8 reg_idx
= ring
->reg_idx
;
3642 /* disable queue to avoid issues while updating state */
3643 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
3644 ixgbe_disable_rx_queue(adapter
, ring
);
3646 IXGBE_WRITE_REG(hw
, IXGBE_RDBAL(reg_idx
), (rdba
& DMA_BIT_MASK(32)));
3647 IXGBE_WRITE_REG(hw
, IXGBE_RDBAH(reg_idx
), (rdba
>> 32));
3648 IXGBE_WRITE_REG(hw
, IXGBE_RDLEN(reg_idx
),
3649 ring
->count
* sizeof(union ixgbe_adv_rx_desc
));
3650 /* Force flushing of IXGBE_RDLEN to prevent MDD */
3651 IXGBE_WRITE_FLUSH(hw
);
3653 IXGBE_WRITE_REG(hw
, IXGBE_RDH(reg_idx
), 0);
3654 IXGBE_WRITE_REG(hw
, IXGBE_RDT(reg_idx
), 0);
3655 ring
->tail
= adapter
->io_addr
+ IXGBE_RDT(reg_idx
);
3657 ixgbe_configure_srrctl(adapter
, ring
);
3658 ixgbe_configure_rscctl(adapter
, ring
);
3660 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
3662 * enable cache line friendly hardware writes:
3663 * PTHRESH=32 descriptors (half the internal cache),
3664 * this also removes ugly rx_no_buffer_count increment
3665 * HTHRESH=4 descriptors (to minimize latency on fetch)
3666 * WTHRESH=8 burst writeback up to two cache lines
3668 rxdctl
&= ~0x3FFFFF;
3672 /* enable receive descriptor ring */
3673 rxdctl
|= IXGBE_RXDCTL_ENABLE
;
3674 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(reg_idx
), rxdctl
);
3676 ixgbe_rx_desc_queue_enable(adapter
, ring
);
3677 ixgbe_alloc_rx_buffers(ring
, ixgbe_desc_unused(ring
));
3680 static void ixgbe_setup_psrtype(struct ixgbe_adapter
*adapter
)
3682 struct ixgbe_hw
*hw
= &adapter
->hw
;
3683 int rss_i
= adapter
->ring_feature
[RING_F_RSS
].indices
;
3686 /* PSRTYPE must be initialized in non 82598 adapters */
3687 u32 psrtype
= IXGBE_PSRTYPE_TCPHDR
|
3688 IXGBE_PSRTYPE_UDPHDR
|
3689 IXGBE_PSRTYPE_IPV4HDR
|
3690 IXGBE_PSRTYPE_L2HDR
|
3691 IXGBE_PSRTYPE_IPV6HDR
;
3693 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
3701 for_each_set_bit(pool
, &adapter
->fwd_bitmask
, 32)
3702 IXGBE_WRITE_REG(hw
, IXGBE_PSRTYPE(VMDQ_P(pool
)), psrtype
);
3705 static void ixgbe_configure_virtualization(struct ixgbe_adapter
*adapter
)
3707 struct ixgbe_hw
*hw
= &adapter
->hw
;
3708 u32 reg_offset
, vf_shift
;
3709 u32 gcr_ext
, vmdctl
;
3712 if (!(adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
))
3715 vmdctl
= IXGBE_READ_REG(hw
, IXGBE_VT_CTL
);
3716 vmdctl
|= IXGBE_VMD_CTL_VMDQ_EN
;
3717 vmdctl
&= ~IXGBE_VT_CTL_POOL_MASK
;
3718 vmdctl
|= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT
;
3719 vmdctl
|= IXGBE_VT_CTL_REPLEN
;
3720 IXGBE_WRITE_REG(hw
, IXGBE_VT_CTL
, vmdctl
);
3722 vf_shift
= VMDQ_P(0) % 32;
3723 reg_offset
= (VMDQ_P(0) >= 32) ? 1 : 0;
3725 /* Enable only the PF's pool for Tx/Rx */
3726 IXGBE_WRITE_REG(hw
, IXGBE_VFRE(reg_offset
), (~0) << vf_shift
);
3727 IXGBE_WRITE_REG(hw
, IXGBE_VFRE(reg_offset
^ 1), reg_offset
- 1);
3728 IXGBE_WRITE_REG(hw
, IXGBE_VFTE(reg_offset
), (~0) << vf_shift
);
3729 IXGBE_WRITE_REG(hw
, IXGBE_VFTE(reg_offset
^ 1), reg_offset
- 1);
3730 if (adapter
->bridge_mode
== BRIDGE_MODE_VEB
)
3731 IXGBE_WRITE_REG(hw
, IXGBE_PFDTXGSWC
, IXGBE_PFDTXGSWC_VT_LBEN
);
3733 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3734 hw
->mac
.ops
.set_vmdq(hw
, 0, VMDQ_P(0));
3736 /* clear VLAN promisc flag so VFTA will be updated if necessary */
3737 adapter
->flags2
&= ~IXGBE_FLAG2_VLAN_PROMISC
;
3740 * Set up VF register offsets for selected VT Mode,
3741 * i.e. 32 or 64 VFs for SR-IOV
3743 switch (adapter
->ring_feature
[RING_F_VMDQ
].mask
) {
3744 case IXGBE_82599_VMDQ_8Q_MASK
:
3745 gcr_ext
= IXGBE_GCR_EXT_VT_MODE_16
;
3747 case IXGBE_82599_VMDQ_4Q_MASK
:
3748 gcr_ext
= IXGBE_GCR_EXT_VT_MODE_32
;
3751 gcr_ext
= IXGBE_GCR_EXT_VT_MODE_64
;
3755 IXGBE_WRITE_REG(hw
, IXGBE_GCR_EXT
, gcr_ext
);
3758 /* Enable MAC Anti-Spoofing */
3759 hw
->mac
.ops
.set_mac_anti_spoofing(hw
, (adapter
->num_vfs
!= 0),
3762 /* Ensure LLDP and FC is set for Ethertype Antispoofing if we will be
3763 * calling set_ethertype_anti_spoofing for each VF in loop below
3765 if (hw
->mac
.ops
.set_ethertype_anti_spoofing
) {
3766 IXGBE_WRITE_REG(hw
, IXGBE_ETQF(IXGBE_ETQF_FILTER_LLDP
),
3767 (IXGBE_ETQF_FILTER_EN
|
3768 IXGBE_ETQF_TX_ANTISPOOF
|
3771 IXGBE_WRITE_REG(hw
, IXGBE_ETQF(IXGBE_ETQF_FILTER_FC
),
3772 (IXGBE_ETQF_FILTER_EN
|
3773 IXGBE_ETQF_TX_ANTISPOOF
|
3777 /* For VFs that have spoof checking turned off */
3778 for (i
= 0; i
< adapter
->num_vfs
; i
++) {
3779 if (!adapter
->vfinfo
[i
].spoofchk_enabled
)
3780 ixgbe_ndo_set_vf_spoofchk(adapter
->netdev
, i
, false);
3782 /* enable ethertype anti spoofing if hw supports it */
3783 if (hw
->mac
.ops
.set_ethertype_anti_spoofing
)
3784 hw
->mac
.ops
.set_ethertype_anti_spoofing(hw
, true, i
);
3786 /* Enable/Disable RSS query feature */
3787 ixgbe_ndo_set_vf_rss_query_en(adapter
->netdev
, i
,
3788 adapter
->vfinfo
[i
].rss_query_enabled
);
3792 static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter
*adapter
)
3794 struct ixgbe_hw
*hw
= &adapter
->hw
;
3795 struct net_device
*netdev
= adapter
->netdev
;
3796 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3797 struct ixgbe_ring
*rx_ring
;
3802 /* adjust max frame to be able to do baby jumbo for FCoE */
3803 if ((adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) &&
3804 (max_frame
< IXGBE_FCOE_JUMBO_FRAME_SIZE
))
3805 max_frame
= IXGBE_FCOE_JUMBO_FRAME_SIZE
;
3807 #endif /* IXGBE_FCOE */
3809 /* adjust max frame to be at least the size of a standard frame */
3810 if (max_frame
< (ETH_FRAME_LEN
+ ETH_FCS_LEN
))
3811 max_frame
= (ETH_FRAME_LEN
+ ETH_FCS_LEN
);
3813 mhadd
= IXGBE_READ_REG(hw
, IXGBE_MHADD
);
3814 if (max_frame
!= (mhadd
>> IXGBE_MHADD_MFS_SHIFT
)) {
3815 mhadd
&= ~IXGBE_MHADD_MFS_MASK
;
3816 mhadd
|= max_frame
<< IXGBE_MHADD_MFS_SHIFT
;
3818 IXGBE_WRITE_REG(hw
, IXGBE_MHADD
, mhadd
);
3821 hlreg0
= IXGBE_READ_REG(hw
, IXGBE_HLREG0
);
3822 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3823 hlreg0
|= IXGBE_HLREG0_JUMBOEN
;
3824 IXGBE_WRITE_REG(hw
, IXGBE_HLREG0
, hlreg0
);
3827 * Setup the HW Rx Head and Tail Descriptor Pointers and
3828 * the Base and Length of the Rx Descriptor Ring
3830 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
3831 rx_ring
= adapter
->rx_ring
[i
];
3832 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)
3833 set_ring_rsc_enabled(rx_ring
);
3835 clear_ring_rsc_enabled(rx_ring
);
3839 static void ixgbe_setup_rdrxctl(struct ixgbe_adapter
*adapter
)
3841 struct ixgbe_hw
*hw
= &adapter
->hw
;
3842 u32 rdrxctl
= IXGBE_READ_REG(hw
, IXGBE_RDRXCTL
);
3844 switch (hw
->mac
.type
) {
3845 case ixgbe_mac_82598EB
:
3847 * For VMDq support of different descriptor types or
3848 * buffer sizes through the use of multiple SRRCTL
3849 * registers, RDRXCTL.MVMEN must be set to 1
3851 * also, the manual doesn't mention it clearly but DCA hints
3852 * will only use queue 0's tags unless this bit is set. Side
3853 * effects of setting this bit are only that SRRCTL must be
3854 * fully programmed [0..15]
3856 rdrxctl
|= IXGBE_RDRXCTL_MVMEN
;
3858 case ixgbe_mac_X550
:
3859 case ixgbe_mac_X550EM_x
:
3860 if (adapter
->num_vfs
)
3861 rdrxctl
|= IXGBE_RDRXCTL_PSP
;
3862 /* fall through for older HW */
3863 case ixgbe_mac_82599EB
:
3864 case ixgbe_mac_X540
:
3865 /* Disable RSC for ACK packets */
3866 IXGBE_WRITE_REG(hw
, IXGBE_RSCDBU
,
3867 (IXGBE_RSCDBU_RSCACKDIS
| IXGBE_READ_REG(hw
, IXGBE_RSCDBU
)));
3868 rdrxctl
&= ~IXGBE_RDRXCTL_RSCFRSTSIZE
;
3869 /* hardware requires some bits to be set by default */
3870 rdrxctl
|= (IXGBE_RDRXCTL_RSCACKC
| IXGBE_RDRXCTL_FCOE_WRFIX
);
3871 rdrxctl
|= IXGBE_RDRXCTL_CRCSTRIP
;
3874 /* We should do nothing since we don't know this hardware */
3878 IXGBE_WRITE_REG(hw
, IXGBE_RDRXCTL
, rdrxctl
);
3882 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3883 * @adapter: board private structure
3885 * Configure the Rx unit of the MAC after a reset.
3887 static void ixgbe_configure_rx(struct ixgbe_adapter
*adapter
)
3889 struct ixgbe_hw
*hw
= &adapter
->hw
;
3893 /* disable receives while setting up the descriptors */
3894 hw
->mac
.ops
.disable_rx(hw
);
3896 ixgbe_setup_psrtype(adapter
);
3897 ixgbe_setup_rdrxctl(adapter
);
3900 rfctl
= IXGBE_READ_REG(hw
, IXGBE_RFCTL
);
3901 rfctl
&= ~IXGBE_RFCTL_RSC_DIS
;
3902 if (!(adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
))
3903 rfctl
|= IXGBE_RFCTL_RSC_DIS
;
3904 IXGBE_WRITE_REG(hw
, IXGBE_RFCTL
, rfctl
);
3906 /* Program registers for the distribution of queues */
3907 ixgbe_setup_mrqc(adapter
);
3909 /* set_rx_buffer_len must be called before ring initialization */
3910 ixgbe_set_rx_buffer_len(adapter
);
3913 * Setup the HW Rx Head and Tail Descriptor Pointers and
3914 * the Base and Length of the Rx Descriptor Ring
3916 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3917 ixgbe_configure_rx_ring(adapter
, adapter
->rx_ring
[i
]);
3919 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
3920 /* disable drop enable for 82598 parts */
3921 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
3922 rxctrl
|= IXGBE_RXCTRL_DMBYPS
;
3924 /* enable all receives */
3925 rxctrl
|= IXGBE_RXCTRL_RXEN
;
3926 hw
->mac
.ops
.enable_rx_dma(hw
, rxctrl
);
3929 static int ixgbe_vlan_rx_add_vid(struct net_device
*netdev
,
3930 __be16 proto
, u16 vid
)
3932 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
3933 struct ixgbe_hw
*hw
= &adapter
->hw
;
3935 /* add VID to filter table */
3936 if (!vid
|| !(adapter
->flags2
& IXGBE_FLAG2_VLAN_PROMISC
))
3937 hw
->mac
.ops
.set_vfta(&adapter
->hw
, vid
, VMDQ_P(0), true, !!vid
);
3939 set_bit(vid
, adapter
->active_vlans
);
3944 static int ixgbe_find_vlvf_entry(struct ixgbe_hw
*hw
, u32 vlan
)
3949 /* short cut the special case */
3953 /* Search for the vlan id in the VLVF entries */
3954 for (idx
= IXGBE_VLVF_ENTRIES
; --idx
;) {
3955 vlvf
= IXGBE_READ_REG(hw
, IXGBE_VLVF(idx
));
3956 if ((vlvf
& VLAN_VID_MASK
) == vlan
)
3963 void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter
*adapter
, u32 vid
)
3965 struct ixgbe_hw
*hw
= &adapter
->hw
;
3969 idx
= ixgbe_find_vlvf_entry(hw
, vid
);
3973 /* See if any other pools are set for this VLAN filter
3974 * entry other than the PF.
3976 word
= idx
* 2 + (VMDQ_P(0) / 32);
3977 bits
= ~(1 << (VMDQ_P(0)) % 32);
3978 bits
&= IXGBE_READ_REG(hw
, IXGBE_VLVFB(word
));
3980 /* Disable the filter so this falls into the default pool. */
3981 if (!bits
&& !IXGBE_READ_REG(hw
, IXGBE_VLVFB(word
^ 1))) {
3982 if (!(adapter
->flags2
& IXGBE_FLAG2_VLAN_PROMISC
))
3983 IXGBE_WRITE_REG(hw
, IXGBE_VLVFB(word
), 0);
3984 IXGBE_WRITE_REG(hw
, IXGBE_VLVF(idx
), 0);
3988 static int ixgbe_vlan_rx_kill_vid(struct net_device
*netdev
,
3989 __be16 proto
, u16 vid
)
3991 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
3992 struct ixgbe_hw
*hw
= &adapter
->hw
;
3994 /* remove VID from filter table */
3995 if (vid
&& !(adapter
->flags2
& IXGBE_FLAG2_VLAN_PROMISC
))
3996 hw
->mac
.ops
.set_vfta(hw
, vid
, VMDQ_P(0), false, true);
3998 clear_bit(vid
, adapter
->active_vlans
);
4004 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
4005 * @adapter: driver data
4007 static void ixgbe_vlan_strip_disable(struct ixgbe_adapter
*adapter
)
4009 struct ixgbe_hw
*hw
= &adapter
->hw
;
4013 switch (hw
->mac
.type
) {
4014 case ixgbe_mac_82598EB
:
4015 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
4016 vlnctrl
&= ~IXGBE_VLNCTRL_VME
;
4017 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
4019 case ixgbe_mac_82599EB
:
4020 case ixgbe_mac_X540
:
4021 case ixgbe_mac_X550
:
4022 case ixgbe_mac_X550EM_x
:
4023 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
4024 struct ixgbe_ring
*ring
= adapter
->rx_ring
[i
];
4026 if (ring
->l2_accel_priv
)
4029 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
4030 vlnctrl
&= ~IXGBE_RXDCTL_VME
;
4031 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), vlnctrl
);
4040 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
4041 * @adapter: driver data
4043 static void ixgbe_vlan_strip_enable(struct ixgbe_adapter
*adapter
)
4045 struct ixgbe_hw
*hw
= &adapter
->hw
;
4049 switch (hw
->mac
.type
) {
4050 case ixgbe_mac_82598EB
:
4051 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
4052 vlnctrl
|= IXGBE_VLNCTRL_VME
;
4053 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
4055 case ixgbe_mac_82599EB
:
4056 case ixgbe_mac_X540
:
4057 case ixgbe_mac_X550
:
4058 case ixgbe_mac_X550EM_x
:
4059 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
4060 struct ixgbe_ring
*ring
= adapter
->rx_ring
[i
];
4062 if (ring
->l2_accel_priv
)
4065 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
4066 vlnctrl
|= IXGBE_RXDCTL_VME
;
4067 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), vlnctrl
);
4075 static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter
*adapter
)
4077 struct ixgbe_hw
*hw
= &adapter
->hw
;
4080 switch (hw
->mac
.type
) {
4081 case ixgbe_mac_82599EB
:
4082 case ixgbe_mac_X540
:
4083 case ixgbe_mac_X550
:
4084 case ixgbe_mac_X550EM_x
:
4086 if (adapter
->flags
& IXGBE_FLAG_VMDQ_ENABLED
)
4089 case ixgbe_mac_82598EB
:
4090 /* legacy case, we can just disable VLAN filtering */
4091 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
4092 vlnctrl
&= ~(IXGBE_VLNCTRL_VFE
| IXGBE_VLNCTRL_CFIEN
);
4093 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
4097 /* We are already in VLAN promisc, nothing to do */
4098 if (adapter
->flags2
& IXGBE_FLAG2_VLAN_PROMISC
)
4101 /* Set flag so we don't redo unnecessary work */
4102 adapter
->flags2
|= IXGBE_FLAG2_VLAN_PROMISC
;
4104 /* Add PF to all active pools */
4105 for (i
= IXGBE_VLVF_ENTRIES
; --i
;) {
4106 u32 reg_offset
= IXGBE_VLVFB(i
* 2 + VMDQ_P(0) / 32);
4107 u32 vlvfb
= IXGBE_READ_REG(hw
, reg_offset
);
4109 vlvfb
|= 1 << (VMDQ_P(0) % 32);
4110 IXGBE_WRITE_REG(hw
, reg_offset
, vlvfb
);
4113 /* Set all bits in the VLAN filter table array */
4114 for (i
= hw
->mac
.vft_size
; i
--;)
4115 IXGBE_WRITE_REG(hw
, IXGBE_VFTA(i
), ~0U);
4118 #define VFTA_BLOCK_SIZE 8
4119 static void ixgbe_scrub_vfta(struct ixgbe_adapter
*adapter
, u32 vfta_offset
)
4121 struct ixgbe_hw
*hw
= &adapter
->hw
;
4122 u32 vfta
[VFTA_BLOCK_SIZE
] = { 0 };
4123 u32 vid_start
= vfta_offset
* 32;
4124 u32 vid_end
= vid_start
+ (VFTA_BLOCK_SIZE
* 32);
4125 u32 i
, vid
, word
, bits
;
4127 for (i
= IXGBE_VLVF_ENTRIES
; --i
;) {
4128 u32 vlvf
= IXGBE_READ_REG(hw
, IXGBE_VLVF(i
));
4130 /* pull VLAN ID from VLVF */
4131 vid
= vlvf
& VLAN_VID_MASK
;
4133 /* only concern outselves with a certain range */
4134 if (vid
< vid_start
|| vid
>= vid_end
)
4138 /* record VLAN ID in VFTA */
4139 vfta
[(vid
- vid_start
) / 32] |= 1 << (vid
% 32);
4141 /* if PF is part of this then continue */
4142 if (test_bit(vid
, adapter
->active_vlans
))
4146 /* remove PF from the pool */
4147 word
= i
* 2 + VMDQ_P(0) / 32;
4148 bits
= ~(1 << (VMDQ_P(0) % 32));
4149 bits
&= IXGBE_READ_REG(hw
, IXGBE_VLVFB(word
));
4150 IXGBE_WRITE_REG(hw
, IXGBE_VLVFB(word
), bits
);
4153 /* extract values from active_vlans and write back to VFTA */
4154 for (i
= VFTA_BLOCK_SIZE
; i
--;) {
4155 vid
= (vfta_offset
+ i
) * 32;
4156 word
= vid
/ BITS_PER_LONG
;
4157 bits
= vid
% BITS_PER_LONG
;
4159 vfta
[i
] |= adapter
->active_vlans
[word
] >> bits
;
4161 IXGBE_WRITE_REG(hw
, IXGBE_VFTA(vfta_offset
+ i
), vfta
[i
]);
4165 static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter
*adapter
)
4167 struct ixgbe_hw
*hw
= &adapter
->hw
;
4170 switch (hw
->mac
.type
) {
4171 case ixgbe_mac_82599EB
:
4172 case ixgbe_mac_X540
:
4173 case ixgbe_mac_X550
:
4174 case ixgbe_mac_X550EM_x
:
4176 if (adapter
->flags
& IXGBE_FLAG_VMDQ_ENABLED
)
4179 case ixgbe_mac_82598EB
:
4180 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
4181 vlnctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
4182 vlnctrl
|= IXGBE_VLNCTRL_VFE
;
4183 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
4187 /* We are not in VLAN promisc, nothing to do */
4188 if (!(adapter
->flags2
& IXGBE_FLAG2_VLAN_PROMISC
))
4191 /* Set flag so we don't redo unnecessary work */
4192 adapter
->flags2
&= ~IXGBE_FLAG2_VLAN_PROMISC
;
4194 for (i
= 0; i
< hw
->mac
.vft_size
; i
+= VFTA_BLOCK_SIZE
)
4195 ixgbe_scrub_vfta(adapter
, i
);
4198 static void ixgbe_restore_vlan(struct ixgbe_adapter
*adapter
)
4202 ixgbe_vlan_rx_add_vid(adapter
->netdev
, htons(ETH_P_8021Q
), 0);
4204 for_each_set_bit_from(vid
, adapter
->active_vlans
, VLAN_N_VID
)
4205 ixgbe_vlan_rx_add_vid(adapter
->netdev
, htons(ETH_P_8021Q
), vid
);
4209 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
4210 * @netdev: network interface device structure
4212 * Writes multicast address list to the MTA hash table.
4213 * Returns: -ENOMEM on failure
4214 * 0 on no addresses written
4215 * X on writing X addresses to MTA
4217 static int ixgbe_write_mc_addr_list(struct net_device
*netdev
)
4219 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4220 struct ixgbe_hw
*hw
= &adapter
->hw
;
4222 if (!netif_running(netdev
))
4225 if (hw
->mac
.ops
.update_mc_addr_list
)
4226 hw
->mac
.ops
.update_mc_addr_list(hw
, netdev
);
4230 #ifdef CONFIG_PCI_IOV
4231 ixgbe_restore_vf_multicasts(adapter
);
4234 return netdev_mc_count(netdev
);
4237 #ifdef CONFIG_PCI_IOV
4238 void ixgbe_full_sync_mac_table(struct ixgbe_adapter
*adapter
)
4240 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4241 struct ixgbe_hw
*hw
= &adapter
->hw
;
4244 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4245 mac_table
->state
&= ~IXGBE_MAC_STATE_MODIFIED
;
4247 if (mac_table
->state
& IXGBE_MAC_STATE_IN_USE
)
4248 hw
->mac
.ops
.set_rar(hw
, i
,
4253 hw
->mac
.ops
.clear_rar(hw
, i
);
4258 static void ixgbe_sync_mac_table(struct ixgbe_adapter
*adapter
)
4260 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4261 struct ixgbe_hw
*hw
= &adapter
->hw
;
4264 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4265 if (!(mac_table
->state
& IXGBE_MAC_STATE_MODIFIED
))
4268 mac_table
->state
&= ~IXGBE_MAC_STATE_MODIFIED
;
4270 if (mac_table
->state
& IXGBE_MAC_STATE_IN_USE
)
4271 hw
->mac
.ops
.set_rar(hw
, i
,
4276 hw
->mac
.ops
.clear_rar(hw
, i
);
4280 static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter
*adapter
)
4282 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4283 struct ixgbe_hw
*hw
= &adapter
->hw
;
4286 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4287 mac_table
->state
|= IXGBE_MAC_STATE_MODIFIED
;
4288 mac_table
->state
&= ~IXGBE_MAC_STATE_IN_USE
;
4291 ixgbe_sync_mac_table(adapter
);
4294 static int ixgbe_available_rars(struct ixgbe_adapter
*adapter
, u16 pool
)
4296 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4297 struct ixgbe_hw
*hw
= &adapter
->hw
;
4300 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4301 /* do not count default RAR as available */
4302 if (mac_table
->state
& IXGBE_MAC_STATE_DEFAULT
)
4305 /* only count unused and addresses that belong to us */
4306 if (mac_table
->state
& IXGBE_MAC_STATE_IN_USE
) {
4307 if (mac_table
->pool
!= pool
)
4317 /* this function destroys the first RAR entry */
4318 static void ixgbe_mac_set_default_filter(struct ixgbe_adapter
*adapter
)
4320 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4321 struct ixgbe_hw
*hw
= &adapter
->hw
;
4323 memcpy(&mac_table
->addr
, hw
->mac
.addr
, ETH_ALEN
);
4324 mac_table
->pool
= VMDQ_P(0);
4326 mac_table
->state
= IXGBE_MAC_STATE_DEFAULT
| IXGBE_MAC_STATE_IN_USE
;
4328 hw
->mac
.ops
.set_rar(hw
, 0, mac_table
->addr
, mac_table
->pool
,
4332 int ixgbe_add_mac_filter(struct ixgbe_adapter
*adapter
,
4333 const u8
*addr
, u16 pool
)
4335 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4336 struct ixgbe_hw
*hw
= &adapter
->hw
;
4339 if (is_zero_ether_addr(addr
))
4342 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4343 if (mac_table
->state
& IXGBE_MAC_STATE_IN_USE
)
4346 ether_addr_copy(mac_table
->addr
, addr
);
4347 mac_table
->pool
= pool
;
4349 mac_table
->state
|= IXGBE_MAC_STATE_MODIFIED
|
4350 IXGBE_MAC_STATE_IN_USE
;
4352 ixgbe_sync_mac_table(adapter
);
4360 int ixgbe_del_mac_filter(struct ixgbe_adapter
*adapter
,
4361 const u8
*addr
, u16 pool
)
4363 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4364 struct ixgbe_hw
*hw
= &adapter
->hw
;
4367 if (is_zero_ether_addr(addr
))
4370 /* search table for addr, if found clear IN_USE flag and sync */
4371 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4372 /* we can only delete an entry if it is in use */
4373 if (!(mac_table
->state
& IXGBE_MAC_STATE_IN_USE
))
4375 /* we only care about entries that belong to the given pool */
4376 if (mac_table
->pool
!= pool
)
4378 /* we only care about a specific MAC address */
4379 if (!ether_addr_equal(addr
, mac_table
->addr
))
4382 mac_table
->state
|= IXGBE_MAC_STATE_MODIFIED
;
4383 mac_table
->state
&= ~IXGBE_MAC_STATE_IN_USE
;
4385 ixgbe_sync_mac_table(adapter
);
4393 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
4394 * @netdev: network interface device structure
4396 * Writes unicast address list to the RAR table.
4397 * Returns: -ENOMEM on failure/insufficient address space
4398 * 0 on no addresses written
4399 * X on writing X addresses to the RAR table
4401 static int ixgbe_write_uc_addr_list(struct net_device
*netdev
, int vfn
)
4403 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4406 /* return ENOMEM indicating insufficient memory for addresses */
4407 if (netdev_uc_count(netdev
) > ixgbe_available_rars(adapter
, vfn
))
4410 if (!netdev_uc_empty(netdev
)) {
4411 struct netdev_hw_addr
*ha
;
4412 netdev_for_each_uc_addr(ha
, netdev
) {
4413 ixgbe_del_mac_filter(adapter
, ha
->addr
, vfn
);
4414 ixgbe_add_mac_filter(adapter
, ha
->addr
, vfn
);
4421 static int ixgbe_uc_sync(struct net_device
*netdev
, const unsigned char *addr
)
4423 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4426 ret
= ixgbe_add_mac_filter(adapter
, addr
, VMDQ_P(0));
4428 return min_t(int, ret
, 0);
4431 static int ixgbe_uc_unsync(struct net_device
*netdev
, const unsigned char *addr
)
4433 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4435 ixgbe_del_mac_filter(adapter
, addr
, VMDQ_P(0));
4441 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
4442 * @netdev: network interface device structure
4444 * The set_rx_method entry point is called whenever the unicast/multicast
4445 * address list or the network interface flags are updated. This routine is
4446 * responsible for configuring the hardware for proper unicast, multicast and
4449 void ixgbe_set_rx_mode(struct net_device
*netdev
)
4451 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4452 struct ixgbe_hw
*hw
= &adapter
->hw
;
4453 u32 fctrl
, vmolr
= IXGBE_VMOLR_BAM
| IXGBE_VMOLR_AUPE
;
4454 netdev_features_t features
= netdev
->features
;
4457 /* Check for Promiscuous and All Multicast modes */
4458 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
4460 /* set all bits that we expect to always be set */
4461 fctrl
&= ~IXGBE_FCTRL_SBP
; /* disable store-bad-packets */
4462 fctrl
|= IXGBE_FCTRL_BAM
;
4463 fctrl
|= IXGBE_FCTRL_DPF
; /* discard pause frames when FC enabled */
4464 fctrl
|= IXGBE_FCTRL_PMCF
;
4466 /* clear the bits we are changing the status of */
4467 fctrl
&= ~(IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
4468 if (netdev
->flags
& IFF_PROMISC
) {
4469 hw
->addr_ctrl
.user_set_promisc
= true;
4470 fctrl
|= (IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
4471 vmolr
|= IXGBE_VMOLR_MPE
;
4472 features
&= ~NETIF_F_HW_VLAN_CTAG_FILTER
;
4474 if (netdev
->flags
& IFF_ALLMULTI
) {
4475 fctrl
|= IXGBE_FCTRL_MPE
;
4476 vmolr
|= IXGBE_VMOLR_MPE
;
4478 hw
->addr_ctrl
.user_set_promisc
= false;
4482 * Write addresses to available RAR registers, if there is not
4483 * sufficient space to store all the addresses then enable
4484 * unicast promiscuous mode
4486 if (__dev_uc_sync(netdev
, ixgbe_uc_sync
, ixgbe_uc_unsync
)) {
4487 fctrl
|= IXGBE_FCTRL_UPE
;
4488 vmolr
|= IXGBE_VMOLR_ROPE
;
4491 /* Write addresses to the MTA, if the attempt fails
4492 * then we should just turn on promiscuous mode so
4493 * that we can at least receive multicast traffic
4495 count
= ixgbe_write_mc_addr_list(netdev
);
4497 fctrl
|= IXGBE_FCTRL_MPE
;
4498 vmolr
|= IXGBE_VMOLR_MPE
;
4500 vmolr
|= IXGBE_VMOLR_ROMPE
;
4503 if (hw
->mac
.type
!= ixgbe_mac_82598EB
) {
4504 vmolr
|= IXGBE_READ_REG(hw
, IXGBE_VMOLR(VMDQ_P(0))) &
4505 ~(IXGBE_VMOLR_MPE
| IXGBE_VMOLR_ROMPE
|
4507 IXGBE_WRITE_REG(hw
, IXGBE_VMOLR(VMDQ_P(0)), vmolr
);
4510 /* This is useful for sniffing bad packets. */
4511 if (features
& NETIF_F_RXALL
) {
4512 /* UPE and MPE will be handled by normal PROMISC logic
4513 * in e1000e_set_rx_mode */
4514 fctrl
|= (IXGBE_FCTRL_SBP
| /* Receive bad packets */
4515 IXGBE_FCTRL_BAM
| /* RX All Bcast Pkts */
4516 IXGBE_FCTRL_PMCF
); /* RX All MAC Ctrl Pkts */
4518 fctrl
&= ~(IXGBE_FCTRL_DPF
);
4519 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4522 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
4524 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
4525 ixgbe_vlan_strip_enable(adapter
);
4527 ixgbe_vlan_strip_disable(adapter
);
4529 if (features
& NETIF_F_HW_VLAN_CTAG_FILTER
)
4530 ixgbe_vlan_promisc_disable(adapter
);
4532 ixgbe_vlan_promisc_enable(adapter
);
4535 static void ixgbe_napi_enable_all(struct ixgbe_adapter
*adapter
)
4539 for (q_idx
= 0; q_idx
< adapter
->num_q_vectors
; q_idx
++) {
4540 ixgbe_qv_init_lock(adapter
->q_vector
[q_idx
]);
4541 napi_enable(&adapter
->q_vector
[q_idx
]->napi
);
4545 static void ixgbe_napi_disable_all(struct ixgbe_adapter
*adapter
)
4549 for (q_idx
= 0; q_idx
< adapter
->num_q_vectors
; q_idx
++) {
4550 napi_disable(&adapter
->q_vector
[q_idx
]->napi
);
4551 while (!ixgbe_qv_disable(adapter
->q_vector
[q_idx
])) {
4552 pr_info("QV %d locked\n", q_idx
);
4553 usleep_range(1000, 20000);
4558 static void ixgbe_clear_vxlan_port(struct ixgbe_adapter
*adapter
)
4560 switch (adapter
->hw
.mac
.type
) {
4561 case ixgbe_mac_X550
:
4562 case ixgbe_mac_X550EM_x
:
4563 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_VXLANCTRL
, 0);
4564 adapter
->vxlan_port
= 0;
4571 #ifdef CONFIG_IXGBE_DCB
4573 * ixgbe_configure_dcb - Configure DCB hardware
4574 * @adapter: ixgbe adapter struct
4576 * This is called by the driver on open to configure the DCB hardware.
4577 * This is also called by the gennetlink interface when reconfiguring
4580 static void ixgbe_configure_dcb(struct ixgbe_adapter
*adapter
)
4582 struct ixgbe_hw
*hw
= &adapter
->hw
;
4583 int max_frame
= adapter
->netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
4585 if (!(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
)) {
4586 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
4587 netif_set_gso_max_size(adapter
->netdev
, 65536);
4591 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
4592 netif_set_gso_max_size(adapter
->netdev
, 32768);
4595 if (adapter
->netdev
->features
& NETIF_F_FCOE_MTU
)
4596 max_frame
= max(max_frame
, IXGBE_FCOE_JUMBO_FRAME_SIZE
);
4599 /* reconfigure the hardware */
4600 if (adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
) {
4601 ixgbe_dcb_calculate_tc_credits(hw
, &adapter
->dcb_cfg
, max_frame
,
4603 ixgbe_dcb_calculate_tc_credits(hw
, &adapter
->dcb_cfg
, max_frame
,
4605 ixgbe_dcb_hw_config(hw
, &adapter
->dcb_cfg
);
4606 } else if (adapter
->ixgbe_ieee_ets
&& adapter
->ixgbe_ieee_pfc
) {
4607 ixgbe_dcb_hw_ets(&adapter
->hw
,
4608 adapter
->ixgbe_ieee_ets
,
4610 ixgbe_dcb_hw_pfc_config(&adapter
->hw
,
4611 adapter
->ixgbe_ieee_pfc
->pfc_en
,
4612 adapter
->ixgbe_ieee_ets
->prio_tc
);
4615 /* Enable RSS Hash per TC */
4616 if (hw
->mac
.type
!= ixgbe_mac_82598EB
) {
4618 u16 rss_i
= adapter
->ring_feature
[RING_F_RSS
].indices
- 1;
4625 /* write msb to all 8 TCs in one write */
4626 IXGBE_WRITE_REG(hw
, IXGBE_RQTC
, msb
* 0x11111111);
4631 /* Additional bittime to account for IXGBE framing */
4632 #define IXGBE_ETH_FRAMING 20
4635 * ixgbe_hpbthresh - calculate high water mark for flow control
4637 * @adapter: board private structure to calculate for
4638 * @pb: packet buffer to calculate
4640 static int ixgbe_hpbthresh(struct ixgbe_adapter
*adapter
, int pb
)
4642 struct ixgbe_hw
*hw
= &adapter
->hw
;
4643 struct net_device
*dev
= adapter
->netdev
;
4644 int link
, tc
, kb
, marker
;
4647 /* Calculate max LAN frame size */
4648 tc
= link
= dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ IXGBE_ETH_FRAMING
;
4651 /* FCoE traffic class uses FCOE jumbo frames */
4652 if ((dev
->features
& NETIF_F_FCOE_MTU
) &&
4653 (tc
< IXGBE_FCOE_JUMBO_FRAME_SIZE
) &&
4654 (pb
== ixgbe_fcoe_get_tc(adapter
)))
4655 tc
= IXGBE_FCOE_JUMBO_FRAME_SIZE
;
4658 /* Calculate delay value for device */
4659 switch (hw
->mac
.type
) {
4660 case ixgbe_mac_X540
:
4661 case ixgbe_mac_X550
:
4662 case ixgbe_mac_X550EM_x
:
4663 dv_id
= IXGBE_DV_X540(link
, tc
);
4666 dv_id
= IXGBE_DV(link
, tc
);
4670 /* Loopback switch introduces additional latency */
4671 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
4672 dv_id
+= IXGBE_B2BT(tc
);
4674 /* Delay value is calculated in bit times convert to KB */
4675 kb
= IXGBE_BT2KB(dv_id
);
4676 rx_pba
= IXGBE_READ_REG(hw
, IXGBE_RXPBSIZE(pb
)) >> 10;
4678 marker
= rx_pba
- kb
;
4680 /* It is possible that the packet buffer is not large enough
4681 * to provide required headroom. In this case throw an error
4682 * to user and a do the best we can.
4685 e_warn(drv
, "Packet Buffer(%i) can not provide enough"
4686 "headroom to support flow control."
4687 "Decrease MTU or number of traffic classes\n", pb
);
4695 * ixgbe_lpbthresh - calculate low water mark for for flow control
4697 * @adapter: board private structure to calculate for
4698 * @pb: packet buffer to calculate
4700 static int ixgbe_lpbthresh(struct ixgbe_adapter
*adapter
, int pb
)
4702 struct ixgbe_hw
*hw
= &adapter
->hw
;
4703 struct net_device
*dev
= adapter
->netdev
;
4707 /* Calculate max LAN frame size */
4708 tc
= dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
4711 /* FCoE traffic class uses FCOE jumbo frames */
4712 if ((dev
->features
& NETIF_F_FCOE_MTU
) &&
4713 (tc
< IXGBE_FCOE_JUMBO_FRAME_SIZE
) &&
4714 (pb
== netdev_get_prio_tc_map(dev
, adapter
->fcoe
.up
)))
4715 tc
= IXGBE_FCOE_JUMBO_FRAME_SIZE
;
4718 /* Calculate delay value for device */
4719 switch (hw
->mac
.type
) {
4720 case ixgbe_mac_X540
:
4721 case ixgbe_mac_X550
:
4722 case ixgbe_mac_X550EM_x
:
4723 dv_id
= IXGBE_LOW_DV_X540(tc
);
4726 dv_id
= IXGBE_LOW_DV(tc
);
4730 /* Delay value is calculated in bit times convert to KB */
4731 return IXGBE_BT2KB(dv_id
);
4735 * ixgbe_pbthresh_setup - calculate and setup high low water marks
4737 static void ixgbe_pbthresh_setup(struct ixgbe_adapter
*adapter
)
4739 struct ixgbe_hw
*hw
= &adapter
->hw
;
4740 int num_tc
= netdev_get_num_tc(adapter
->netdev
);
4746 for (i
= 0; i
< num_tc
; i
++) {
4747 hw
->fc
.high_water
[i
] = ixgbe_hpbthresh(adapter
, i
);
4748 hw
->fc
.low_water
[i
] = ixgbe_lpbthresh(adapter
, i
);
4750 /* Low water marks must not be larger than high water marks */
4751 if (hw
->fc
.low_water
[i
] > hw
->fc
.high_water
[i
])
4752 hw
->fc
.low_water
[i
] = 0;
4755 for (; i
< MAX_TRAFFIC_CLASS
; i
++)
4756 hw
->fc
.high_water
[i
] = 0;
4759 static void ixgbe_configure_pb(struct ixgbe_adapter
*adapter
)
4761 struct ixgbe_hw
*hw
= &adapter
->hw
;
4763 u8 tc
= netdev_get_num_tc(adapter
->netdev
);
4765 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
4766 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
4767 hdrm
= 32 << adapter
->fdir_pballoc
;
4771 hw
->mac
.ops
.set_rxpba(hw
, tc
, hdrm
, PBA_STRATEGY_EQUAL
);
4772 ixgbe_pbthresh_setup(adapter
);
4775 static void ixgbe_fdir_filter_restore(struct ixgbe_adapter
*adapter
)
4777 struct ixgbe_hw
*hw
= &adapter
->hw
;
4778 struct hlist_node
*node2
;
4779 struct ixgbe_fdir_filter
*filter
;
4781 spin_lock(&adapter
->fdir_perfect_lock
);
4783 if (!hlist_empty(&adapter
->fdir_filter_list
))
4784 ixgbe_fdir_set_input_mask_82599(hw
, &adapter
->fdir_mask
);
4786 hlist_for_each_entry_safe(filter
, node2
,
4787 &adapter
->fdir_filter_list
, fdir_node
) {
4788 ixgbe_fdir_write_perfect_filter_82599(hw
,
4791 (filter
->action
== IXGBE_FDIR_DROP_QUEUE
) ?
4792 IXGBE_FDIR_DROP_QUEUE
:
4793 adapter
->rx_ring
[filter
->action
]->reg_idx
);
4796 spin_unlock(&adapter
->fdir_perfect_lock
);
4799 static void ixgbe_macvlan_set_rx_mode(struct net_device
*dev
, unsigned int pool
,
4800 struct ixgbe_adapter
*adapter
)
4802 struct ixgbe_hw
*hw
= &adapter
->hw
;
4805 /* No unicast promiscuous support for VMDQ devices. */
4806 vmolr
= IXGBE_READ_REG(hw
, IXGBE_VMOLR(pool
));
4807 vmolr
|= (IXGBE_VMOLR_ROMPE
| IXGBE_VMOLR_BAM
| IXGBE_VMOLR_AUPE
);
4809 /* clear the affected bit */
4810 vmolr
&= ~IXGBE_VMOLR_MPE
;
4812 if (dev
->flags
& IFF_ALLMULTI
) {
4813 vmolr
|= IXGBE_VMOLR_MPE
;
4815 vmolr
|= IXGBE_VMOLR_ROMPE
;
4816 hw
->mac
.ops
.update_mc_addr_list(hw
, dev
);
4818 ixgbe_write_uc_addr_list(adapter
->netdev
, pool
);
4819 IXGBE_WRITE_REG(hw
, IXGBE_VMOLR(pool
), vmolr
);
4822 static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter
*vadapter
)
4824 struct ixgbe_adapter
*adapter
= vadapter
->real_adapter
;
4825 int rss_i
= adapter
->num_rx_queues_per_pool
;
4826 struct ixgbe_hw
*hw
= &adapter
->hw
;
4827 u16 pool
= vadapter
->pool
;
4828 u32 psrtype
= IXGBE_PSRTYPE_TCPHDR
|
4829 IXGBE_PSRTYPE_UDPHDR
|
4830 IXGBE_PSRTYPE_IPV4HDR
|
4831 IXGBE_PSRTYPE_L2HDR
|
4832 IXGBE_PSRTYPE_IPV6HDR
;
4834 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
4842 IXGBE_WRITE_REG(hw
, IXGBE_PSRTYPE(VMDQ_P(pool
)), psrtype
);
4846 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
4847 * @rx_ring: ring to free buffers from
4849 static void ixgbe_clean_rx_ring(struct ixgbe_ring
*rx_ring
)
4851 struct device
*dev
= rx_ring
->dev
;
4855 /* ring already cleared, nothing to do */
4856 if (!rx_ring
->rx_buffer_info
)
4859 /* Free all the Rx ring sk_buffs */
4860 for (i
= 0; i
< rx_ring
->count
; i
++) {
4861 struct ixgbe_rx_buffer
*rx_buffer
= &rx_ring
->rx_buffer_info
[i
];
4863 if (rx_buffer
->skb
) {
4864 struct sk_buff
*skb
= rx_buffer
->skb
;
4865 if (IXGBE_CB(skb
)->page_released
)
4868 ixgbe_rx_bufsz(rx_ring
),
4871 rx_buffer
->skb
= NULL
;
4874 if (!rx_buffer
->page
)
4877 dma_unmap_page(dev
, rx_buffer
->dma
,
4878 ixgbe_rx_pg_size(rx_ring
), DMA_FROM_DEVICE
);
4879 __free_pages(rx_buffer
->page
, ixgbe_rx_pg_order(rx_ring
));
4881 rx_buffer
->page
= NULL
;
4884 size
= sizeof(struct ixgbe_rx_buffer
) * rx_ring
->count
;
4885 memset(rx_ring
->rx_buffer_info
, 0, size
);
4887 /* Zero out the descriptor ring */
4888 memset(rx_ring
->desc
, 0, rx_ring
->size
);
4890 rx_ring
->next_to_alloc
= 0;
4891 rx_ring
->next_to_clean
= 0;
4892 rx_ring
->next_to_use
= 0;
4895 static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter
*vadapter
,
4896 struct ixgbe_ring
*rx_ring
)
4898 struct ixgbe_adapter
*adapter
= vadapter
->real_adapter
;
4899 int index
= rx_ring
->queue_index
+ vadapter
->rx_base_queue
;
4901 /* shutdown specific queue receive and wait for dma to settle */
4902 ixgbe_disable_rx_queue(adapter
, rx_ring
);
4903 usleep_range(10000, 20000);
4904 ixgbe_irq_disable_queues(adapter
, ((u64
)1 << index
));
4905 ixgbe_clean_rx_ring(rx_ring
);
4906 rx_ring
->l2_accel_priv
= NULL
;
4909 static int ixgbe_fwd_ring_down(struct net_device
*vdev
,
4910 struct ixgbe_fwd_adapter
*accel
)
4912 struct ixgbe_adapter
*adapter
= accel
->real_adapter
;
4913 unsigned int rxbase
= accel
->rx_base_queue
;
4914 unsigned int txbase
= accel
->tx_base_queue
;
4917 netif_tx_stop_all_queues(vdev
);
4919 for (i
= 0; i
< adapter
->num_rx_queues_per_pool
; i
++) {
4920 ixgbe_disable_fwd_ring(accel
, adapter
->rx_ring
[rxbase
+ i
]);
4921 adapter
->rx_ring
[rxbase
+ i
]->netdev
= adapter
->netdev
;
4924 for (i
= 0; i
< adapter
->num_rx_queues_per_pool
; i
++) {
4925 adapter
->tx_ring
[txbase
+ i
]->l2_accel_priv
= NULL
;
4926 adapter
->tx_ring
[txbase
+ i
]->netdev
= adapter
->netdev
;
4933 static int ixgbe_fwd_ring_up(struct net_device
*vdev
,
4934 struct ixgbe_fwd_adapter
*accel
)
4936 struct ixgbe_adapter
*adapter
= accel
->real_adapter
;
4937 unsigned int rxbase
, txbase
, queues
;
4938 int i
, baseq
, err
= 0;
4940 if (!test_bit(accel
->pool
, &adapter
->fwd_bitmask
))
4943 baseq
= accel
->pool
* adapter
->num_rx_queues_per_pool
;
4944 netdev_dbg(vdev
, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
4945 accel
->pool
, adapter
->num_rx_pools
,
4946 baseq
, baseq
+ adapter
->num_rx_queues_per_pool
,
4947 adapter
->fwd_bitmask
);
4949 accel
->netdev
= vdev
;
4950 accel
->rx_base_queue
= rxbase
= baseq
;
4951 accel
->tx_base_queue
= txbase
= baseq
;
4953 for (i
= 0; i
< adapter
->num_rx_queues_per_pool
; i
++)
4954 ixgbe_disable_fwd_ring(accel
, adapter
->rx_ring
[rxbase
+ i
]);
4956 for (i
= 0; i
< adapter
->num_rx_queues_per_pool
; i
++) {
4957 adapter
->rx_ring
[rxbase
+ i
]->netdev
= vdev
;
4958 adapter
->rx_ring
[rxbase
+ i
]->l2_accel_priv
= accel
;
4959 ixgbe_configure_rx_ring(adapter
, adapter
->rx_ring
[rxbase
+ i
]);
4962 for (i
= 0; i
< adapter
->num_rx_queues_per_pool
; i
++) {
4963 adapter
->tx_ring
[txbase
+ i
]->netdev
= vdev
;
4964 adapter
->tx_ring
[txbase
+ i
]->l2_accel_priv
= accel
;
4967 queues
= min_t(unsigned int,
4968 adapter
->num_rx_queues_per_pool
, vdev
->num_tx_queues
);
4969 err
= netif_set_real_num_tx_queues(vdev
, queues
);
4973 err
= netif_set_real_num_rx_queues(vdev
, queues
);
4977 if (is_valid_ether_addr(vdev
->dev_addr
))
4978 ixgbe_add_mac_filter(adapter
, vdev
->dev_addr
, accel
->pool
);
4980 ixgbe_fwd_psrtype(accel
);
4981 ixgbe_macvlan_set_rx_mode(vdev
, accel
->pool
, adapter
);
4984 ixgbe_fwd_ring_down(vdev
, accel
);
4988 static void ixgbe_configure_dfwd(struct ixgbe_adapter
*adapter
)
4990 struct net_device
*upper
;
4991 struct list_head
*iter
;
4994 netdev_for_each_all_upper_dev_rcu(adapter
->netdev
, upper
, iter
) {
4995 if (netif_is_macvlan(upper
)) {
4996 struct macvlan_dev
*dfwd
= netdev_priv(upper
);
4997 struct ixgbe_fwd_adapter
*vadapter
= dfwd
->fwd_priv
;
4999 if (dfwd
->fwd_priv
) {
5000 err
= ixgbe_fwd_ring_up(upper
, vadapter
);
5008 static void ixgbe_configure(struct ixgbe_adapter
*adapter
)
5010 struct ixgbe_hw
*hw
= &adapter
->hw
;
5012 ixgbe_configure_pb(adapter
);
5013 #ifdef CONFIG_IXGBE_DCB
5014 ixgbe_configure_dcb(adapter
);
5017 * We must restore virtualization before VLANs or else
5018 * the VLVF registers will not be populated
5020 ixgbe_configure_virtualization(adapter
);
5022 ixgbe_set_rx_mode(adapter
->netdev
);
5023 ixgbe_restore_vlan(adapter
);
5025 switch (hw
->mac
.type
) {
5026 case ixgbe_mac_82599EB
:
5027 case ixgbe_mac_X540
:
5028 hw
->mac
.ops
.disable_rx_buff(hw
);
5034 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
5035 ixgbe_init_fdir_signature_82599(&adapter
->hw
,
5036 adapter
->fdir_pballoc
);
5037 } else if (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
) {
5038 ixgbe_init_fdir_perfect_82599(&adapter
->hw
,
5039 adapter
->fdir_pballoc
);
5040 ixgbe_fdir_filter_restore(adapter
);
5043 switch (hw
->mac
.type
) {
5044 case ixgbe_mac_82599EB
:
5045 case ixgbe_mac_X540
:
5046 hw
->mac
.ops
.enable_rx_buff(hw
);
5052 #ifdef CONFIG_IXGBE_DCA
5054 if (adapter
->flags
& IXGBE_FLAG_DCA_CAPABLE
)
5055 ixgbe_setup_dca(adapter
);
5056 #endif /* CONFIG_IXGBE_DCA */
5059 /* configure FCoE L2 filters, redirection table, and Rx control */
5060 ixgbe_configure_fcoe(adapter
);
5062 #endif /* IXGBE_FCOE */
5063 ixgbe_configure_tx(adapter
);
5064 ixgbe_configure_rx(adapter
);
5065 ixgbe_configure_dfwd(adapter
);
5069 * ixgbe_sfp_link_config - set up SFP+ link
5070 * @adapter: pointer to private adapter struct
5072 static void ixgbe_sfp_link_config(struct ixgbe_adapter
*adapter
)
5075 * We are assuming the worst case scenario here, and that
5076 * is that an SFP was inserted/removed after the reset
5077 * but before SFP detection was enabled. As such the best
5078 * solution is to just start searching as soon as we start
5080 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
5081 adapter
->flags2
|= IXGBE_FLAG2_SEARCH_FOR_SFP
;
5083 adapter
->flags2
|= IXGBE_FLAG2_SFP_NEEDS_RESET
;
5084 adapter
->sfp_poll_time
= 0;
5088 * ixgbe_non_sfp_link_config - set up non-SFP+ link
5089 * @hw: pointer to private hardware struct
5091 * Returns 0 on success, negative on failure
5093 static int ixgbe_non_sfp_link_config(struct ixgbe_hw
*hw
)
5096 bool autoneg
, link_up
= false;
5097 int ret
= IXGBE_ERR_LINK_SETUP
;
5099 if (hw
->mac
.ops
.check_link
)
5100 ret
= hw
->mac
.ops
.check_link(hw
, &speed
, &link_up
, false);
5105 speed
= hw
->phy
.autoneg_advertised
;
5106 if ((!speed
) && (hw
->mac
.ops
.get_link_capabilities
))
5107 ret
= hw
->mac
.ops
.get_link_capabilities(hw
, &speed
,
5112 if (hw
->mac
.ops
.setup_link
)
5113 ret
= hw
->mac
.ops
.setup_link(hw
, speed
, link_up
);
5118 static void ixgbe_setup_gpie(struct ixgbe_adapter
*adapter
)
5120 struct ixgbe_hw
*hw
= &adapter
->hw
;
5123 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
5124 gpie
= IXGBE_GPIE_MSIX_MODE
| IXGBE_GPIE_PBA_SUPPORT
|
5126 gpie
|= IXGBE_GPIE_EIAME
;
5128 * use EIAM to auto-mask when MSI-X interrupt is asserted
5129 * this saves a register write for every interrupt
5131 switch (hw
->mac
.type
) {
5132 case ixgbe_mac_82598EB
:
5133 IXGBE_WRITE_REG(hw
, IXGBE_EIAM
, IXGBE_EICS_RTX_QUEUE
);
5135 case ixgbe_mac_82599EB
:
5136 case ixgbe_mac_X540
:
5137 case ixgbe_mac_X550
:
5138 case ixgbe_mac_X550EM_x
:
5140 IXGBE_WRITE_REG(hw
, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5141 IXGBE_WRITE_REG(hw
, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5145 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
5146 * specifically only auto mask tx and rx interrupts */
5147 IXGBE_WRITE_REG(hw
, IXGBE_EIAM
, IXGBE_EICS_RTX_QUEUE
);
5150 /* XXX: to interrupt immediately for EICS writes, enable this */
5151 /* gpie |= IXGBE_GPIE_EIMEN; */
5153 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
5154 gpie
&= ~IXGBE_GPIE_VTMODE_MASK
;
5156 switch (adapter
->ring_feature
[RING_F_VMDQ
].mask
) {
5157 case IXGBE_82599_VMDQ_8Q_MASK
:
5158 gpie
|= IXGBE_GPIE_VTMODE_16
;
5160 case IXGBE_82599_VMDQ_4Q_MASK
:
5161 gpie
|= IXGBE_GPIE_VTMODE_32
;
5164 gpie
|= IXGBE_GPIE_VTMODE_64
;
5169 /* Enable Thermal over heat sensor interrupt */
5170 if (adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
) {
5171 switch (adapter
->hw
.mac
.type
) {
5172 case ixgbe_mac_82599EB
:
5173 gpie
|= IXGBE_SDP0_GPIEN_8259X
;
5180 /* Enable fan failure interrupt */
5181 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
)
5182 gpie
|= IXGBE_SDP1_GPIEN(hw
);
5184 switch (hw
->mac
.type
) {
5185 case ixgbe_mac_82599EB
:
5186 gpie
|= IXGBE_SDP1_GPIEN_8259X
| IXGBE_SDP2_GPIEN_8259X
;
5188 case ixgbe_mac_X550EM_x
:
5189 gpie
|= IXGBE_SDP0_GPIEN_X540
;
5195 IXGBE_WRITE_REG(hw
, IXGBE_GPIE
, gpie
);
5198 static void ixgbe_up_complete(struct ixgbe_adapter
*adapter
)
5200 struct ixgbe_hw
*hw
= &adapter
->hw
;
5204 ixgbe_get_hw_control(adapter
);
5205 ixgbe_setup_gpie(adapter
);
5207 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
5208 ixgbe_configure_msix(adapter
);
5210 ixgbe_configure_msi_and_legacy(adapter
);
5212 /* enable the optics for 82599 SFP+ fiber */
5213 if (hw
->mac
.ops
.enable_tx_laser
)
5214 hw
->mac
.ops
.enable_tx_laser(hw
);
5216 if (hw
->phy
.ops
.set_phy_power
)
5217 hw
->phy
.ops
.set_phy_power(hw
, true);
5219 smp_mb__before_atomic();
5220 clear_bit(__IXGBE_DOWN
, &adapter
->state
);
5221 ixgbe_napi_enable_all(adapter
);
5223 if (ixgbe_is_sfp(hw
)) {
5224 ixgbe_sfp_link_config(adapter
);
5226 err
= ixgbe_non_sfp_link_config(hw
);
5228 e_err(probe
, "link_config FAILED %d\n", err
);
5231 /* clear any pending interrupts, may auto mask */
5232 IXGBE_READ_REG(hw
, IXGBE_EICR
);
5233 ixgbe_irq_enable(adapter
, true, true);
5236 * If this adapter has a fan, check to see if we had a failure
5237 * before we enabled the interrupt.
5239 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
5240 u32 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
5241 if (esdp
& IXGBE_ESDP_SDP1
)
5242 e_crit(drv
, "Fan has stopped, replace the adapter\n");
5245 /* bring the link up in the watchdog, this could race with our first
5246 * link up interrupt but shouldn't be a problem */
5247 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
5248 adapter
->link_check_timeout
= jiffies
;
5249 mod_timer(&adapter
->service_timer
, jiffies
);
5251 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
5252 ctrl_ext
= IXGBE_READ_REG(hw
, IXGBE_CTRL_EXT
);
5253 ctrl_ext
|= IXGBE_CTRL_EXT_PFRSTD
;
5254 IXGBE_WRITE_REG(hw
, IXGBE_CTRL_EXT
, ctrl_ext
);
5257 void ixgbe_reinit_locked(struct ixgbe_adapter
*adapter
)
5259 WARN_ON(in_interrupt());
5260 /* put off any impending NetWatchDogTimeout */
5261 adapter
->netdev
->trans_start
= jiffies
;
5263 while (test_and_set_bit(__IXGBE_RESETTING
, &adapter
->state
))
5264 usleep_range(1000, 2000);
5265 ixgbe_down(adapter
);
5267 * If SR-IOV enabled then wait a bit before bringing the adapter
5268 * back up to give the VFs time to respond to the reset. The
5269 * two second wait is based upon the watchdog timer cycle in
5272 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
5275 clear_bit(__IXGBE_RESETTING
, &adapter
->state
);
5278 void ixgbe_up(struct ixgbe_adapter
*adapter
)
5280 /* hardware has been reset, we need to reload some things */
5281 ixgbe_configure(adapter
);
5283 ixgbe_up_complete(adapter
);
5286 void ixgbe_reset(struct ixgbe_adapter
*adapter
)
5288 struct ixgbe_hw
*hw
= &adapter
->hw
;
5289 struct net_device
*netdev
= adapter
->netdev
;
5292 if (ixgbe_removed(hw
->hw_addr
))
5294 /* lock SFP init bit to prevent race conditions with the watchdog */
5295 while (test_and_set_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
))
5296 usleep_range(1000, 2000);
5298 /* clear all SFP and link config related flags while holding SFP_INIT */
5299 adapter
->flags2
&= ~(IXGBE_FLAG2_SEARCH_FOR_SFP
|
5300 IXGBE_FLAG2_SFP_NEEDS_RESET
);
5301 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_CONFIG
;
5303 err
= hw
->mac
.ops
.init_hw(hw
);
5306 case IXGBE_ERR_SFP_NOT_PRESENT
:
5307 case IXGBE_ERR_SFP_NOT_SUPPORTED
:
5309 case IXGBE_ERR_MASTER_REQUESTS_PENDING
:
5310 e_dev_err("master disable timed out\n");
5312 case IXGBE_ERR_EEPROM_VERSION
:
5313 /* We are running on a pre-production device, log a warning */
5314 e_dev_warn("This device is a pre-production adapter/LOM. "
5315 "Please be aware there may be issues associated with "
5316 "your hardware. If you are experiencing problems "
5317 "please contact your Intel or hardware "
5318 "representative who provided you with this "
5322 e_dev_err("Hardware Error: %d\n", err
);
5325 clear_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
);
5327 /* flush entries out of MAC table */
5328 ixgbe_flush_sw_mac_table(adapter
);
5329 __dev_uc_unsync(netdev
, NULL
);
5331 /* do not flush user set addresses */
5332 ixgbe_mac_set_default_filter(adapter
);
5334 /* update SAN MAC vmdq pool selection */
5335 if (hw
->mac
.san_mac_rar_index
)
5336 hw
->mac
.ops
.set_vmdq_san_mac(hw
, VMDQ_P(0));
5338 if (test_bit(__IXGBE_PTP_RUNNING
, &adapter
->state
))
5339 ixgbe_ptp_reset(adapter
);
5341 if (hw
->phy
.ops
.set_phy_power
) {
5342 if (!netif_running(adapter
->netdev
) && !adapter
->wol
)
5343 hw
->phy
.ops
.set_phy_power(hw
, false);
5345 hw
->phy
.ops
.set_phy_power(hw
, true);
5350 * ixgbe_clean_tx_ring - Free Tx Buffers
5351 * @tx_ring: ring to be cleaned
5353 static void ixgbe_clean_tx_ring(struct ixgbe_ring
*tx_ring
)
5355 struct ixgbe_tx_buffer
*tx_buffer_info
;
5359 /* ring already cleared, nothing to do */
5360 if (!tx_ring
->tx_buffer_info
)
5363 /* Free all the Tx ring sk_buffs */
5364 for (i
= 0; i
< tx_ring
->count
; i
++) {
5365 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
5366 ixgbe_unmap_and_free_tx_resource(tx_ring
, tx_buffer_info
);
5369 netdev_tx_reset_queue(txring_txq(tx_ring
));
5371 size
= sizeof(struct ixgbe_tx_buffer
) * tx_ring
->count
;
5372 memset(tx_ring
->tx_buffer_info
, 0, size
);
5374 /* Zero out the descriptor ring */
5375 memset(tx_ring
->desc
, 0, tx_ring
->size
);
5377 tx_ring
->next_to_use
= 0;
5378 tx_ring
->next_to_clean
= 0;
5382 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5383 * @adapter: board private structure
5385 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter
*adapter
)
5389 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
5390 ixgbe_clean_rx_ring(adapter
->rx_ring
[i
]);
5394 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5395 * @adapter: board private structure
5397 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter
*adapter
)
5401 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
5402 ixgbe_clean_tx_ring(adapter
->tx_ring
[i
]);
5405 static void ixgbe_fdir_filter_exit(struct ixgbe_adapter
*adapter
)
5407 struct hlist_node
*node2
;
5408 struct ixgbe_fdir_filter
*filter
;
5410 spin_lock(&adapter
->fdir_perfect_lock
);
5412 hlist_for_each_entry_safe(filter
, node2
,
5413 &adapter
->fdir_filter_list
, fdir_node
) {
5414 hlist_del(&filter
->fdir_node
);
5417 adapter
->fdir_filter_count
= 0;
5419 spin_unlock(&adapter
->fdir_perfect_lock
);
5422 void ixgbe_down(struct ixgbe_adapter
*adapter
)
5424 struct net_device
*netdev
= adapter
->netdev
;
5425 struct ixgbe_hw
*hw
= &adapter
->hw
;
5426 struct net_device
*upper
;
5427 struct list_head
*iter
;
5430 /* signal that we are down to the interrupt handler */
5431 if (test_and_set_bit(__IXGBE_DOWN
, &adapter
->state
))
5432 return; /* do nothing if already down */
5434 /* disable receives */
5435 hw
->mac
.ops
.disable_rx(hw
);
5437 /* disable all enabled rx queues */
5438 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
5439 /* this call also flushes the previous write */
5440 ixgbe_disable_rx_queue(adapter
, adapter
->rx_ring
[i
]);
5442 usleep_range(10000, 20000);
5444 netif_tx_stop_all_queues(netdev
);
5446 /* call carrier off first to avoid false dev_watchdog timeouts */
5447 netif_carrier_off(netdev
);
5448 netif_tx_disable(netdev
);
5450 /* disable any upper devices */
5451 netdev_for_each_all_upper_dev_rcu(adapter
->netdev
, upper
, iter
) {
5452 if (netif_is_macvlan(upper
)) {
5453 struct macvlan_dev
*vlan
= netdev_priv(upper
);
5455 if (vlan
->fwd_priv
) {
5456 netif_tx_stop_all_queues(upper
);
5457 netif_carrier_off(upper
);
5458 netif_tx_disable(upper
);
5463 ixgbe_irq_disable(adapter
);
5465 ixgbe_napi_disable_all(adapter
);
5467 adapter
->flags2
&= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT
|
5468 IXGBE_FLAG2_RESET_REQUESTED
);
5469 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_UPDATE
;
5471 del_timer_sync(&adapter
->service_timer
);
5473 if (adapter
->num_vfs
) {
5474 /* Clear EITR Select mapping */
5475 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITRSEL
, 0);
5477 /* Mark all the VFs as inactive */
5478 for (i
= 0 ; i
< adapter
->num_vfs
; i
++)
5479 adapter
->vfinfo
[i
].clear_to_send
= false;
5481 /* ping all the active vfs to let them know we are going down */
5482 ixgbe_ping_all_vfs(adapter
);
5484 /* Disable all VFTE/VFRE TX/RX */
5485 ixgbe_disable_tx_rx(adapter
);
5488 /* disable transmits in the hardware now that interrupts are off */
5489 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
5490 u8 reg_idx
= adapter
->tx_ring
[i
]->reg_idx
;
5491 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
), IXGBE_TXDCTL_SWFLSH
);
5494 /* Disable the Tx DMA engine on 82599 and later MAC */
5495 switch (hw
->mac
.type
) {
5496 case ixgbe_mac_82599EB
:
5497 case ixgbe_mac_X540
:
5498 case ixgbe_mac_X550
:
5499 case ixgbe_mac_X550EM_x
:
5500 IXGBE_WRITE_REG(hw
, IXGBE_DMATXCTL
,
5501 (IXGBE_READ_REG(hw
, IXGBE_DMATXCTL
) &
5502 ~IXGBE_DMATXCTL_TE
));
5508 if (!pci_channel_offline(adapter
->pdev
))
5509 ixgbe_reset(adapter
);
5511 /* power down the optics for 82599 SFP+ fiber */
5512 if (hw
->mac
.ops
.disable_tx_laser
)
5513 hw
->mac
.ops
.disable_tx_laser(hw
);
5515 ixgbe_clean_all_tx_rings(adapter
);
5516 ixgbe_clean_all_rx_rings(adapter
);
5520 * ixgbe_tx_timeout - Respond to a Tx Hang
5521 * @netdev: network interface device structure
5523 static void ixgbe_tx_timeout(struct net_device
*netdev
)
5525 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5527 /* Do the reset outside of interrupt context */
5528 ixgbe_tx_timeout_reset(adapter
);
5532 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5533 * @adapter: board private structure to initialize
5535 * ixgbe_sw_init initializes the Adapter private data structure.
5536 * Fields are initialized based on PCI device information and
5537 * OS network device settings (MTU size).
5539 static int ixgbe_sw_init(struct ixgbe_adapter
*adapter
)
5541 struct ixgbe_hw
*hw
= &adapter
->hw
;
5542 struct pci_dev
*pdev
= adapter
->pdev
;
5543 unsigned int rss
, fdir
;
5545 #ifdef CONFIG_IXGBE_DCB
5547 struct tc_configuration
*tc
;
5550 /* PCI config space info */
5552 hw
->vendor_id
= pdev
->vendor
;
5553 hw
->device_id
= pdev
->device
;
5554 hw
->revision_id
= pdev
->revision
;
5555 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
5556 hw
->subsystem_device_id
= pdev
->subsystem_device
;
5558 /* Set common capability flags and settings */
5559 rss
= min_t(int, ixgbe_max_rss_indices(adapter
), num_online_cpus());
5560 adapter
->ring_feature
[RING_F_RSS
].limit
= rss
;
5561 adapter
->flags2
|= IXGBE_FLAG2_RSC_CAPABLE
;
5562 adapter
->max_q_vectors
= MAX_Q_VECTORS_82599
;
5563 adapter
->atr_sample_rate
= 20;
5564 fdir
= min_t(int, IXGBE_MAX_FDIR_INDICES
, num_online_cpus());
5565 adapter
->ring_feature
[RING_F_FDIR
].limit
= fdir
;
5566 adapter
->fdir_pballoc
= IXGBE_FDIR_PBALLOC_64K
;
5567 #ifdef CONFIG_IXGBE_DCA
5568 adapter
->flags
|= IXGBE_FLAG_DCA_CAPABLE
;
5571 adapter
->flags
|= IXGBE_FLAG_FCOE_CAPABLE
;
5572 adapter
->flags
&= ~IXGBE_FLAG_FCOE_ENABLED
;
5573 #ifdef CONFIG_IXGBE_DCB
5574 /* Default traffic class to use for FCoE */
5575 adapter
->fcoe
.up
= IXGBE_FCOE_DEFTC
;
5576 #endif /* CONFIG_IXGBE_DCB */
5577 #endif /* IXGBE_FCOE */
5579 /* initialize static ixgbe jump table entries */
5580 adapter
->jump_tables
[0] = ixgbe_ipv4_fields
;
5582 adapter
->mac_table
= kzalloc(sizeof(struct ixgbe_mac_addr
) *
5583 hw
->mac
.num_rar_entries
,
5585 if (!adapter
->mac_table
)
5588 /* Set MAC specific capability flags and exceptions */
5589 switch (hw
->mac
.type
) {
5590 case ixgbe_mac_82598EB
:
5591 adapter
->flags2
&= ~IXGBE_FLAG2_RSC_CAPABLE
;
5593 if (hw
->device_id
== IXGBE_DEV_ID_82598AT
)
5594 adapter
->flags
|= IXGBE_FLAG_FAN_FAIL_CAPABLE
;
5596 adapter
->max_q_vectors
= MAX_Q_VECTORS_82598
;
5597 adapter
->ring_feature
[RING_F_FDIR
].limit
= 0;
5598 adapter
->atr_sample_rate
= 0;
5599 adapter
->fdir_pballoc
= 0;
5601 adapter
->flags
&= ~IXGBE_FLAG_FCOE_CAPABLE
;
5602 adapter
->flags
&= ~IXGBE_FLAG_FCOE_ENABLED
;
5603 #ifdef CONFIG_IXGBE_DCB
5604 adapter
->fcoe
.up
= 0;
5605 #endif /* IXGBE_DCB */
5606 #endif /* IXGBE_FCOE */
5608 case ixgbe_mac_82599EB
:
5609 if (hw
->device_id
== IXGBE_DEV_ID_82599_T3_LOM
)
5610 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
;
5612 case ixgbe_mac_X540
:
5613 fwsm
= IXGBE_READ_REG(hw
, IXGBE_FWSM(hw
));
5614 if (fwsm
& IXGBE_FWSM_TS_ENABLED
)
5615 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
;
5617 case ixgbe_mac_X550EM_x
:
5618 case ixgbe_mac_X550
:
5619 #ifdef CONFIG_IXGBE_DCA
5620 adapter
->flags
&= ~IXGBE_FLAG_DCA_CAPABLE
;
5622 #ifdef CONFIG_IXGBE_VXLAN
5623 adapter
->flags
|= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE
;
5631 /* FCoE support exists, always init the FCoE lock */
5632 spin_lock_init(&adapter
->fcoe
.lock
);
5635 /* n-tuple support exists, always init our spinlock */
5636 spin_lock_init(&adapter
->fdir_perfect_lock
);
5638 #ifdef CONFIG_IXGBE_DCB
5639 switch (hw
->mac
.type
) {
5640 case ixgbe_mac_X540
:
5641 case ixgbe_mac_X550
:
5642 case ixgbe_mac_X550EM_x
:
5643 adapter
->dcb_cfg
.num_tcs
.pg_tcs
= X540_TRAFFIC_CLASS
;
5644 adapter
->dcb_cfg
.num_tcs
.pfc_tcs
= X540_TRAFFIC_CLASS
;
5647 adapter
->dcb_cfg
.num_tcs
.pg_tcs
= MAX_TRAFFIC_CLASS
;
5648 adapter
->dcb_cfg
.num_tcs
.pfc_tcs
= MAX_TRAFFIC_CLASS
;
5652 /* Configure DCB traffic classes */
5653 for (j
= 0; j
< MAX_TRAFFIC_CLASS
; j
++) {
5654 tc
= &adapter
->dcb_cfg
.tc_config
[j
];
5655 tc
->path
[DCB_TX_CONFIG
].bwg_id
= 0;
5656 tc
->path
[DCB_TX_CONFIG
].bwg_percent
= 12 + (j
& 1);
5657 tc
->path
[DCB_RX_CONFIG
].bwg_id
= 0;
5658 tc
->path
[DCB_RX_CONFIG
].bwg_percent
= 12 + (j
& 1);
5659 tc
->dcb_pfc
= pfc_disabled
;
5662 /* Initialize default user to priority mapping, UPx->TC0 */
5663 tc
= &adapter
->dcb_cfg
.tc_config
[0];
5664 tc
->path
[DCB_TX_CONFIG
].up_to_tc_bitmap
= 0xFF;
5665 tc
->path
[DCB_RX_CONFIG
].up_to_tc_bitmap
= 0xFF;
5667 adapter
->dcb_cfg
.bw_percentage
[DCB_TX_CONFIG
][0] = 100;
5668 adapter
->dcb_cfg
.bw_percentage
[DCB_RX_CONFIG
][0] = 100;
5669 adapter
->dcb_cfg
.pfc_mode_enable
= false;
5670 adapter
->dcb_set_bitmap
= 0x00;
5671 adapter
->dcbx_cap
= DCB_CAP_DCBX_HOST
| DCB_CAP_DCBX_VER_CEE
;
5672 memcpy(&adapter
->temp_dcb_cfg
, &adapter
->dcb_cfg
,
5673 sizeof(adapter
->temp_dcb_cfg
));
5677 /* default flow control settings */
5678 hw
->fc
.requested_mode
= ixgbe_fc_full
;
5679 hw
->fc
.current_mode
= ixgbe_fc_full
; /* init for ethtool output */
5680 ixgbe_pbthresh_setup(adapter
);
5681 hw
->fc
.pause_time
= IXGBE_DEFAULT_FCPAUSE
;
5682 hw
->fc
.send_xon
= true;
5683 hw
->fc
.disable_fc_autoneg
= ixgbe_device_supports_autoneg_fc(hw
);
5685 #ifdef CONFIG_PCI_IOV
5687 e_dev_warn("Enabling SR-IOV VFs using the max_vfs module parameter is deprecated - please use the pci sysfs interface instead.\n");
5689 /* assign number of SR-IOV VFs */
5690 if (hw
->mac
.type
!= ixgbe_mac_82598EB
) {
5691 if (max_vfs
> IXGBE_MAX_VFS_DRV_LIMIT
) {
5692 adapter
->num_vfs
= 0;
5693 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
5695 adapter
->num_vfs
= max_vfs
;
5698 #endif /* CONFIG_PCI_IOV */
5700 /* enable itr by default in dynamic mode */
5701 adapter
->rx_itr_setting
= 1;
5702 adapter
->tx_itr_setting
= 1;
5704 /* set default ring sizes */
5705 adapter
->tx_ring_count
= IXGBE_DEFAULT_TXD
;
5706 adapter
->rx_ring_count
= IXGBE_DEFAULT_RXD
;
5708 /* set default work limits */
5709 adapter
->tx_work_limit
= IXGBE_DEFAULT_TX_WORK
;
5711 /* initialize eeprom parameters */
5712 if (ixgbe_init_eeprom_params_generic(hw
)) {
5713 e_dev_err("EEPROM initialization failed\n");
5717 /* PF holds first pool slot */
5718 set_bit(0, &adapter
->fwd_bitmask
);
5719 set_bit(__IXGBE_DOWN
, &adapter
->state
);
5725 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
5726 * @tx_ring: tx descriptor ring (for a specific queue) to setup
5728 * Return 0 on success, negative on failure
5730 int ixgbe_setup_tx_resources(struct ixgbe_ring
*tx_ring
)
5732 struct device
*dev
= tx_ring
->dev
;
5733 int orig_node
= dev_to_node(dev
);
5737 size
= sizeof(struct ixgbe_tx_buffer
) * tx_ring
->count
;
5739 if (tx_ring
->q_vector
)
5740 ring_node
= tx_ring
->q_vector
->numa_node
;
5742 tx_ring
->tx_buffer_info
= vzalloc_node(size
, ring_node
);
5743 if (!tx_ring
->tx_buffer_info
)
5744 tx_ring
->tx_buffer_info
= vzalloc(size
);
5745 if (!tx_ring
->tx_buffer_info
)
5748 u64_stats_init(&tx_ring
->syncp
);
5750 /* round up to nearest 4K */
5751 tx_ring
->size
= tx_ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
5752 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
5754 set_dev_node(dev
, ring_node
);
5755 tx_ring
->desc
= dma_alloc_coherent(dev
,
5759 set_dev_node(dev
, orig_node
);
5761 tx_ring
->desc
= dma_alloc_coherent(dev
, tx_ring
->size
,
5762 &tx_ring
->dma
, GFP_KERNEL
);
5766 tx_ring
->next_to_use
= 0;
5767 tx_ring
->next_to_clean
= 0;
5771 vfree(tx_ring
->tx_buffer_info
);
5772 tx_ring
->tx_buffer_info
= NULL
;
5773 dev_err(dev
, "Unable to allocate memory for the Tx descriptor ring\n");
5778 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5779 * @adapter: board private structure
5781 * If this function returns with an error, then it's possible one or
5782 * more of the rings is populated (while the rest are not). It is the
5783 * callers duty to clean those orphaned rings.
5785 * Return 0 on success, negative on failure
5787 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter
*adapter
)
5791 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
5792 err
= ixgbe_setup_tx_resources(adapter
->tx_ring
[i
]);
5796 e_err(probe
, "Allocation for Tx Queue %u failed\n", i
);
5802 /* rewind the index freeing the rings as we go */
5804 ixgbe_free_tx_resources(adapter
->tx_ring
[i
]);
5809 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
5810 * @rx_ring: rx descriptor ring (for a specific queue) to setup
5812 * Returns 0 on success, negative on failure
5814 int ixgbe_setup_rx_resources(struct ixgbe_ring
*rx_ring
)
5816 struct device
*dev
= rx_ring
->dev
;
5817 int orig_node
= dev_to_node(dev
);
5821 size
= sizeof(struct ixgbe_rx_buffer
) * rx_ring
->count
;
5823 if (rx_ring
->q_vector
)
5824 ring_node
= rx_ring
->q_vector
->numa_node
;
5826 rx_ring
->rx_buffer_info
= vzalloc_node(size
, ring_node
);
5827 if (!rx_ring
->rx_buffer_info
)
5828 rx_ring
->rx_buffer_info
= vzalloc(size
);
5829 if (!rx_ring
->rx_buffer_info
)
5832 u64_stats_init(&rx_ring
->syncp
);
5834 /* Round up to nearest 4K */
5835 rx_ring
->size
= rx_ring
->count
* sizeof(union ixgbe_adv_rx_desc
);
5836 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
5838 set_dev_node(dev
, ring_node
);
5839 rx_ring
->desc
= dma_alloc_coherent(dev
,
5843 set_dev_node(dev
, orig_node
);
5845 rx_ring
->desc
= dma_alloc_coherent(dev
, rx_ring
->size
,
5846 &rx_ring
->dma
, GFP_KERNEL
);
5850 rx_ring
->next_to_clean
= 0;
5851 rx_ring
->next_to_use
= 0;
5855 vfree(rx_ring
->rx_buffer_info
);
5856 rx_ring
->rx_buffer_info
= NULL
;
5857 dev_err(dev
, "Unable to allocate memory for the Rx descriptor ring\n");
5862 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5863 * @adapter: board private structure
5865 * If this function returns with an error, then it's possible one or
5866 * more of the rings is populated (while the rest are not). It is the
5867 * callers duty to clean those orphaned rings.
5869 * Return 0 on success, negative on failure
5871 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter
*adapter
)
5875 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
5876 err
= ixgbe_setup_rx_resources(adapter
->rx_ring
[i
]);
5880 e_err(probe
, "Allocation for Rx Queue %u failed\n", i
);
5885 err
= ixgbe_setup_fcoe_ddp_resources(adapter
);
5890 /* rewind the index freeing the rings as we go */
5892 ixgbe_free_rx_resources(adapter
->rx_ring
[i
]);
5897 * ixgbe_free_tx_resources - Free Tx Resources per Queue
5898 * @tx_ring: Tx descriptor ring for a specific queue
5900 * Free all transmit software resources
5902 void ixgbe_free_tx_resources(struct ixgbe_ring
*tx_ring
)
5904 ixgbe_clean_tx_ring(tx_ring
);
5906 vfree(tx_ring
->tx_buffer_info
);
5907 tx_ring
->tx_buffer_info
= NULL
;
5909 /* if not set, then don't free */
5913 dma_free_coherent(tx_ring
->dev
, tx_ring
->size
,
5914 tx_ring
->desc
, tx_ring
->dma
);
5916 tx_ring
->desc
= NULL
;
5920 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5921 * @adapter: board private structure
5923 * Free all transmit software resources
5925 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter
*adapter
)
5929 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
5930 if (adapter
->tx_ring
[i
]->desc
)
5931 ixgbe_free_tx_resources(adapter
->tx_ring
[i
]);
5935 * ixgbe_free_rx_resources - Free Rx Resources
5936 * @rx_ring: ring to clean the resources from
5938 * Free all receive software resources
5940 void ixgbe_free_rx_resources(struct ixgbe_ring
*rx_ring
)
5942 ixgbe_clean_rx_ring(rx_ring
);
5944 vfree(rx_ring
->rx_buffer_info
);
5945 rx_ring
->rx_buffer_info
= NULL
;
5947 /* if not set, then don't free */
5951 dma_free_coherent(rx_ring
->dev
, rx_ring
->size
,
5952 rx_ring
->desc
, rx_ring
->dma
);
5954 rx_ring
->desc
= NULL
;
5958 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5959 * @adapter: board private structure
5961 * Free all receive software resources
5963 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter
*adapter
)
5968 ixgbe_free_fcoe_ddp_resources(adapter
);
5971 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
5972 if (adapter
->rx_ring
[i
]->desc
)
5973 ixgbe_free_rx_resources(adapter
->rx_ring
[i
]);
5977 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5978 * @netdev: network interface device structure
5979 * @new_mtu: new value for maximum frame size
5981 * Returns 0 on success, negative on failure
5983 static int ixgbe_change_mtu(struct net_device
*netdev
, int new_mtu
)
5985 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5986 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
5988 /* MTU < 68 is an error and causes problems on some kernels */
5989 if ((new_mtu
< 68) || (max_frame
> IXGBE_MAX_JUMBO_FRAME_SIZE
))
5993 * For 82599EB we cannot allow legacy VFs to enable their receive
5994 * paths when MTU greater than 1500 is configured. So display a
5995 * warning that legacy VFs will be disabled.
5997 if ((adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) &&
5998 (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) &&
5999 (max_frame
> (ETH_FRAME_LEN
+ ETH_FCS_LEN
)))
6000 e_warn(probe
, "Setting MTU > 1500 will disable legacy VFs\n");
6002 e_info(probe
, "changing MTU from %d to %d\n", netdev
->mtu
, new_mtu
);
6004 /* must set new MTU before calling down or up */
6005 netdev
->mtu
= new_mtu
;
6007 if (netif_running(netdev
))
6008 ixgbe_reinit_locked(adapter
);
6014 * ixgbe_open - Called when a network interface is made active
6015 * @netdev: network interface device structure
6017 * Returns 0 on success, negative value on failure
6019 * The open entry point is called when a network interface is made
6020 * active by the system (IFF_UP). At this point all resources needed
6021 * for transmit and receive operations are allocated, the interrupt
6022 * handler is registered with the OS, the watchdog timer is started,
6023 * and the stack is notified that the interface is ready.
6025 int ixgbe_open(struct net_device
*netdev
)
6027 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6028 struct ixgbe_hw
*hw
= &adapter
->hw
;
6031 /* disallow open during test */
6032 if (test_bit(__IXGBE_TESTING
, &adapter
->state
))
6035 netif_carrier_off(netdev
);
6037 /* allocate transmit descriptors */
6038 err
= ixgbe_setup_all_tx_resources(adapter
);
6042 /* allocate receive descriptors */
6043 err
= ixgbe_setup_all_rx_resources(adapter
);
6047 ixgbe_configure(adapter
);
6049 err
= ixgbe_request_irq(adapter
);
6053 /* Notify the stack of the actual queue counts. */
6054 if (adapter
->num_rx_pools
> 1)
6055 queues
= adapter
->num_rx_queues_per_pool
;
6057 queues
= adapter
->num_tx_queues
;
6059 err
= netif_set_real_num_tx_queues(netdev
, queues
);
6061 goto err_set_queues
;
6063 if (adapter
->num_rx_pools
> 1 &&
6064 adapter
->num_rx_queues
> IXGBE_MAX_L2A_QUEUES
)
6065 queues
= IXGBE_MAX_L2A_QUEUES
;
6067 queues
= adapter
->num_rx_queues
;
6068 err
= netif_set_real_num_rx_queues(netdev
, queues
);
6070 goto err_set_queues
;
6072 ixgbe_ptp_init(adapter
);
6074 ixgbe_up_complete(adapter
);
6076 ixgbe_clear_vxlan_port(adapter
);
6077 #ifdef CONFIG_IXGBE_VXLAN
6078 vxlan_get_rx_port(netdev
);
6084 ixgbe_free_irq(adapter
);
6086 ixgbe_free_all_rx_resources(adapter
);
6087 if (hw
->phy
.ops
.set_phy_power
&& !adapter
->wol
)
6088 hw
->phy
.ops
.set_phy_power(&adapter
->hw
, false);
6090 ixgbe_free_all_tx_resources(adapter
);
6092 ixgbe_reset(adapter
);
6097 static void ixgbe_close_suspend(struct ixgbe_adapter
*adapter
)
6099 ixgbe_ptp_suspend(adapter
);
6101 if (adapter
->hw
.phy
.ops
.enter_lplu
) {
6102 adapter
->hw
.phy
.reset_disable
= true;
6103 ixgbe_down(adapter
);
6104 adapter
->hw
.phy
.ops
.enter_lplu(&adapter
->hw
);
6105 adapter
->hw
.phy
.reset_disable
= false;
6107 ixgbe_down(adapter
);
6110 ixgbe_free_irq(adapter
);
6112 ixgbe_free_all_tx_resources(adapter
);
6113 ixgbe_free_all_rx_resources(adapter
);
6117 * ixgbe_close - Disables a network interface
6118 * @netdev: network interface device structure
6120 * Returns 0, this is not allowed to fail
6122 * The close entry point is called when an interface is de-activated
6123 * by the OS. The hardware is still under the drivers control, but
6124 * needs to be disabled. A global MAC reset is issued to stop the
6125 * hardware, and all transmit and receive resources are freed.
6127 int ixgbe_close(struct net_device
*netdev
)
6129 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6131 ixgbe_ptp_stop(adapter
);
6133 ixgbe_close_suspend(adapter
);
6135 ixgbe_fdir_filter_exit(adapter
);
6137 ixgbe_release_hw_control(adapter
);
6143 static int ixgbe_resume(struct pci_dev
*pdev
)
6145 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
6146 struct net_device
*netdev
= adapter
->netdev
;
6149 adapter
->hw
.hw_addr
= adapter
->io_addr
;
6150 pci_set_power_state(pdev
, PCI_D0
);
6151 pci_restore_state(pdev
);
6153 * pci_restore_state clears dev->state_saved so call
6154 * pci_save_state to restore it.
6156 pci_save_state(pdev
);
6158 err
= pci_enable_device_mem(pdev
);
6160 e_dev_err("Cannot enable PCI device from suspend\n");
6163 smp_mb__before_atomic();
6164 clear_bit(__IXGBE_DISABLED
, &adapter
->state
);
6165 pci_set_master(pdev
);
6167 pci_wake_from_d3(pdev
, false);
6169 ixgbe_reset(adapter
);
6171 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
6174 err
= ixgbe_init_interrupt_scheme(adapter
);
6175 if (!err
&& netif_running(netdev
))
6176 err
= ixgbe_open(netdev
);
6183 netif_device_attach(netdev
);
6187 #endif /* CONFIG_PM */
6189 static int __ixgbe_shutdown(struct pci_dev
*pdev
, bool *enable_wake
)
6191 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
6192 struct net_device
*netdev
= adapter
->netdev
;
6193 struct ixgbe_hw
*hw
= &adapter
->hw
;
6195 u32 wufc
= adapter
->wol
;
6200 netif_device_detach(netdev
);
6203 if (netif_running(netdev
))
6204 ixgbe_close_suspend(adapter
);
6207 ixgbe_clear_interrupt_scheme(adapter
);
6210 retval
= pci_save_state(pdev
);
6215 if (hw
->mac
.ops
.stop_link_on_d3
)
6216 hw
->mac
.ops
.stop_link_on_d3(hw
);
6219 ixgbe_set_rx_mode(netdev
);
6221 /* enable the optics for 82599 SFP+ fiber as we can WoL */
6222 if (hw
->mac
.ops
.enable_tx_laser
)
6223 hw
->mac
.ops
.enable_tx_laser(hw
);
6225 /* turn on all-multi mode if wake on multicast is enabled */
6226 if (wufc
& IXGBE_WUFC_MC
) {
6227 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
6228 fctrl
|= IXGBE_FCTRL_MPE
;
6229 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
6232 ctrl
= IXGBE_READ_REG(hw
, IXGBE_CTRL
);
6233 ctrl
|= IXGBE_CTRL_GIO_DIS
;
6234 IXGBE_WRITE_REG(hw
, IXGBE_CTRL
, ctrl
);
6236 IXGBE_WRITE_REG(hw
, IXGBE_WUFC
, wufc
);
6238 IXGBE_WRITE_REG(hw
, IXGBE_WUC
, 0);
6239 IXGBE_WRITE_REG(hw
, IXGBE_WUFC
, 0);
6242 switch (hw
->mac
.type
) {
6243 case ixgbe_mac_82598EB
:
6244 pci_wake_from_d3(pdev
, false);
6246 case ixgbe_mac_82599EB
:
6247 case ixgbe_mac_X540
:
6248 case ixgbe_mac_X550
:
6249 case ixgbe_mac_X550EM_x
:
6250 pci_wake_from_d3(pdev
, !!wufc
);
6256 *enable_wake
= !!wufc
;
6257 if (hw
->phy
.ops
.set_phy_power
&& !*enable_wake
)
6258 hw
->phy
.ops
.set_phy_power(hw
, false);
6260 ixgbe_release_hw_control(adapter
);
6262 if (!test_and_set_bit(__IXGBE_DISABLED
, &adapter
->state
))
6263 pci_disable_device(pdev
);
6269 static int ixgbe_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6274 retval
= __ixgbe_shutdown(pdev
, &wake
);
6279 pci_prepare_to_sleep(pdev
);
6281 pci_wake_from_d3(pdev
, false);
6282 pci_set_power_state(pdev
, PCI_D3hot
);
6287 #endif /* CONFIG_PM */
6289 static void ixgbe_shutdown(struct pci_dev
*pdev
)
6293 __ixgbe_shutdown(pdev
, &wake
);
6295 if (system_state
== SYSTEM_POWER_OFF
) {
6296 pci_wake_from_d3(pdev
, wake
);
6297 pci_set_power_state(pdev
, PCI_D3hot
);
6302 * ixgbe_update_stats - Update the board statistics counters.
6303 * @adapter: board private structure
6305 void ixgbe_update_stats(struct ixgbe_adapter
*adapter
)
6307 struct net_device
*netdev
= adapter
->netdev
;
6308 struct ixgbe_hw
*hw
= &adapter
->hw
;
6309 struct ixgbe_hw_stats
*hwstats
= &adapter
->stats
;
6311 u32 i
, missed_rx
= 0, mpc
, bprc
, lxon
, lxoff
, xon_off_tot
;
6312 u64 non_eop_descs
= 0, restart_queue
= 0, tx_busy
= 0;
6313 u64 alloc_rx_page_failed
= 0, alloc_rx_buff_failed
= 0;
6314 u64 bytes
= 0, packets
= 0, hw_csum_rx_error
= 0;
6316 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
6317 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
6320 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
) {
6323 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
6324 rsc_count
+= adapter
->rx_ring
[i
]->rx_stats
.rsc_count
;
6325 rsc_flush
+= adapter
->rx_ring
[i
]->rx_stats
.rsc_flush
;
6327 adapter
->rsc_total_count
= rsc_count
;
6328 adapter
->rsc_total_flush
= rsc_flush
;
6331 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
6332 struct ixgbe_ring
*rx_ring
= adapter
->rx_ring
[i
];
6333 non_eop_descs
+= rx_ring
->rx_stats
.non_eop_descs
;
6334 alloc_rx_page_failed
+= rx_ring
->rx_stats
.alloc_rx_page_failed
;
6335 alloc_rx_buff_failed
+= rx_ring
->rx_stats
.alloc_rx_buff_failed
;
6336 hw_csum_rx_error
+= rx_ring
->rx_stats
.csum_err
;
6337 bytes
+= rx_ring
->stats
.bytes
;
6338 packets
+= rx_ring
->stats
.packets
;
6340 adapter
->non_eop_descs
= non_eop_descs
;
6341 adapter
->alloc_rx_page_failed
= alloc_rx_page_failed
;
6342 adapter
->alloc_rx_buff_failed
= alloc_rx_buff_failed
;
6343 adapter
->hw_csum_rx_error
= hw_csum_rx_error
;
6344 netdev
->stats
.rx_bytes
= bytes
;
6345 netdev
->stats
.rx_packets
= packets
;
6349 /* gather some stats to the adapter struct that are per queue */
6350 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
6351 struct ixgbe_ring
*tx_ring
= adapter
->tx_ring
[i
];
6352 restart_queue
+= tx_ring
->tx_stats
.restart_queue
;
6353 tx_busy
+= tx_ring
->tx_stats
.tx_busy
;
6354 bytes
+= tx_ring
->stats
.bytes
;
6355 packets
+= tx_ring
->stats
.packets
;
6357 adapter
->restart_queue
= restart_queue
;
6358 adapter
->tx_busy
= tx_busy
;
6359 netdev
->stats
.tx_bytes
= bytes
;
6360 netdev
->stats
.tx_packets
= packets
;
6362 hwstats
->crcerrs
+= IXGBE_READ_REG(hw
, IXGBE_CRCERRS
);
6364 /* 8 register reads */
6365 for (i
= 0; i
< 8; i
++) {
6366 /* for packet buffers not used, the register should read 0 */
6367 mpc
= IXGBE_READ_REG(hw
, IXGBE_MPC(i
));
6369 hwstats
->mpc
[i
] += mpc
;
6370 total_mpc
+= hwstats
->mpc
[i
];
6371 hwstats
->pxontxc
[i
] += IXGBE_READ_REG(hw
, IXGBE_PXONTXC(i
));
6372 hwstats
->pxofftxc
[i
] += IXGBE_READ_REG(hw
, IXGBE_PXOFFTXC(i
));
6373 switch (hw
->mac
.type
) {
6374 case ixgbe_mac_82598EB
:
6375 hwstats
->rnbc
[i
] += IXGBE_READ_REG(hw
, IXGBE_RNBC(i
));
6376 hwstats
->qbtc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBTC(i
));
6377 hwstats
->qbrc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBRC(i
));
6378 hwstats
->pxonrxc
[i
] +=
6379 IXGBE_READ_REG(hw
, IXGBE_PXONRXC(i
));
6381 case ixgbe_mac_82599EB
:
6382 case ixgbe_mac_X540
:
6383 case ixgbe_mac_X550
:
6384 case ixgbe_mac_X550EM_x
:
6385 hwstats
->pxonrxc
[i
] +=
6386 IXGBE_READ_REG(hw
, IXGBE_PXONRXCNT(i
));
6393 /*16 register reads */
6394 for (i
= 0; i
< 16; i
++) {
6395 hwstats
->qptc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPTC(i
));
6396 hwstats
->qprc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPRC(i
));
6397 if ((hw
->mac
.type
== ixgbe_mac_82599EB
) ||
6398 (hw
->mac
.type
== ixgbe_mac_X540
) ||
6399 (hw
->mac
.type
== ixgbe_mac_X550
) ||
6400 (hw
->mac
.type
== ixgbe_mac_X550EM_x
)) {
6401 hwstats
->qbtc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBTC_L(i
));
6402 IXGBE_READ_REG(hw
, IXGBE_QBTC_H(i
)); /* to clear */
6403 hwstats
->qbrc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBRC_L(i
));
6404 IXGBE_READ_REG(hw
, IXGBE_QBRC_H(i
)); /* to clear */
6408 hwstats
->gprc
+= IXGBE_READ_REG(hw
, IXGBE_GPRC
);
6409 /* work around hardware counting issue */
6410 hwstats
->gprc
-= missed_rx
;
6412 ixgbe_update_xoff_received(adapter
);
6414 /* 82598 hardware only has a 32 bit counter in the high register */
6415 switch (hw
->mac
.type
) {
6416 case ixgbe_mac_82598EB
:
6417 hwstats
->lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXC
);
6418 hwstats
->gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCH
);
6419 hwstats
->gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCH
);
6420 hwstats
->tor
+= IXGBE_READ_REG(hw
, IXGBE_TORH
);
6422 case ixgbe_mac_X540
:
6423 case ixgbe_mac_X550
:
6424 case ixgbe_mac_X550EM_x
:
6425 /* OS2BMC stats are X540 and later */
6426 hwstats
->o2bgptc
+= IXGBE_READ_REG(hw
, IXGBE_O2BGPTC
);
6427 hwstats
->o2bspc
+= IXGBE_READ_REG(hw
, IXGBE_O2BSPC
);
6428 hwstats
->b2ospc
+= IXGBE_READ_REG(hw
, IXGBE_B2OSPC
);
6429 hwstats
->b2ogprc
+= IXGBE_READ_REG(hw
, IXGBE_B2OGPRC
);
6430 case ixgbe_mac_82599EB
:
6431 for (i
= 0; i
< 16; i
++)
6432 adapter
->hw_rx_no_dma_resources
+=
6433 IXGBE_READ_REG(hw
, IXGBE_QPRDC(i
));
6434 hwstats
->gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCL
);
6435 IXGBE_READ_REG(hw
, IXGBE_GORCH
); /* to clear */
6436 hwstats
->gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCL
);
6437 IXGBE_READ_REG(hw
, IXGBE_GOTCH
); /* to clear */
6438 hwstats
->tor
+= IXGBE_READ_REG(hw
, IXGBE_TORL
);
6439 IXGBE_READ_REG(hw
, IXGBE_TORH
); /* to clear */
6440 hwstats
->lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXCNT
);
6441 hwstats
->fdirmatch
+= IXGBE_READ_REG(hw
, IXGBE_FDIRMATCH
);
6442 hwstats
->fdirmiss
+= IXGBE_READ_REG(hw
, IXGBE_FDIRMISS
);
6444 hwstats
->fccrc
+= IXGBE_READ_REG(hw
, IXGBE_FCCRC
);
6445 hwstats
->fcoerpdc
+= IXGBE_READ_REG(hw
, IXGBE_FCOERPDC
);
6446 hwstats
->fcoeprc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEPRC
);
6447 hwstats
->fcoeptc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEPTC
);
6448 hwstats
->fcoedwrc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEDWRC
);
6449 hwstats
->fcoedwtc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEDWTC
);
6450 /* Add up per cpu counters for total ddp aloc fail */
6451 if (adapter
->fcoe
.ddp_pool
) {
6452 struct ixgbe_fcoe
*fcoe
= &adapter
->fcoe
;
6453 struct ixgbe_fcoe_ddp_pool
*ddp_pool
;
6455 u64 noddp
= 0, noddp_ext_buff
= 0;
6456 for_each_possible_cpu(cpu
) {
6457 ddp_pool
= per_cpu_ptr(fcoe
->ddp_pool
, cpu
);
6458 noddp
+= ddp_pool
->noddp
;
6459 noddp_ext_buff
+= ddp_pool
->noddp_ext_buff
;
6461 hwstats
->fcoe_noddp
= noddp
;
6462 hwstats
->fcoe_noddp_ext_buff
= noddp_ext_buff
;
6464 #endif /* IXGBE_FCOE */
6469 bprc
= IXGBE_READ_REG(hw
, IXGBE_BPRC
);
6470 hwstats
->bprc
+= bprc
;
6471 hwstats
->mprc
+= IXGBE_READ_REG(hw
, IXGBE_MPRC
);
6472 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
6473 hwstats
->mprc
-= bprc
;
6474 hwstats
->roc
+= IXGBE_READ_REG(hw
, IXGBE_ROC
);
6475 hwstats
->prc64
+= IXGBE_READ_REG(hw
, IXGBE_PRC64
);
6476 hwstats
->prc127
+= IXGBE_READ_REG(hw
, IXGBE_PRC127
);
6477 hwstats
->prc255
+= IXGBE_READ_REG(hw
, IXGBE_PRC255
);
6478 hwstats
->prc511
+= IXGBE_READ_REG(hw
, IXGBE_PRC511
);
6479 hwstats
->prc1023
+= IXGBE_READ_REG(hw
, IXGBE_PRC1023
);
6480 hwstats
->prc1522
+= IXGBE_READ_REG(hw
, IXGBE_PRC1522
);
6481 hwstats
->rlec
+= IXGBE_READ_REG(hw
, IXGBE_RLEC
);
6482 lxon
= IXGBE_READ_REG(hw
, IXGBE_LXONTXC
);
6483 hwstats
->lxontxc
+= lxon
;
6484 lxoff
= IXGBE_READ_REG(hw
, IXGBE_LXOFFTXC
);
6485 hwstats
->lxofftxc
+= lxoff
;
6486 hwstats
->gptc
+= IXGBE_READ_REG(hw
, IXGBE_GPTC
);
6487 hwstats
->mptc
+= IXGBE_READ_REG(hw
, IXGBE_MPTC
);
6489 * 82598 errata - tx of flow control packets is included in tx counters
6491 xon_off_tot
= lxon
+ lxoff
;
6492 hwstats
->gptc
-= xon_off_tot
;
6493 hwstats
->mptc
-= xon_off_tot
;
6494 hwstats
->gotc
-= (xon_off_tot
* (ETH_ZLEN
+ ETH_FCS_LEN
));
6495 hwstats
->ruc
+= IXGBE_READ_REG(hw
, IXGBE_RUC
);
6496 hwstats
->rfc
+= IXGBE_READ_REG(hw
, IXGBE_RFC
);
6497 hwstats
->rjc
+= IXGBE_READ_REG(hw
, IXGBE_RJC
);
6498 hwstats
->tpr
+= IXGBE_READ_REG(hw
, IXGBE_TPR
);
6499 hwstats
->ptc64
+= IXGBE_READ_REG(hw
, IXGBE_PTC64
);
6500 hwstats
->ptc64
-= xon_off_tot
;
6501 hwstats
->ptc127
+= IXGBE_READ_REG(hw
, IXGBE_PTC127
);
6502 hwstats
->ptc255
+= IXGBE_READ_REG(hw
, IXGBE_PTC255
);
6503 hwstats
->ptc511
+= IXGBE_READ_REG(hw
, IXGBE_PTC511
);
6504 hwstats
->ptc1023
+= IXGBE_READ_REG(hw
, IXGBE_PTC1023
);
6505 hwstats
->ptc1522
+= IXGBE_READ_REG(hw
, IXGBE_PTC1522
);
6506 hwstats
->bptc
+= IXGBE_READ_REG(hw
, IXGBE_BPTC
);
6508 /* Fill out the OS statistics structure */
6509 netdev
->stats
.multicast
= hwstats
->mprc
;
6512 netdev
->stats
.rx_errors
= hwstats
->crcerrs
+ hwstats
->rlec
;
6513 netdev
->stats
.rx_dropped
= 0;
6514 netdev
->stats
.rx_length_errors
= hwstats
->rlec
;
6515 netdev
->stats
.rx_crc_errors
= hwstats
->crcerrs
;
6516 netdev
->stats
.rx_missed_errors
= total_mpc
;
6520 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
6521 * @adapter: pointer to the device adapter structure
6523 static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter
*adapter
)
6525 struct ixgbe_hw
*hw
= &adapter
->hw
;
6528 if (!(adapter
->flags2
& IXGBE_FLAG2_FDIR_REQUIRES_REINIT
))
6531 adapter
->flags2
&= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT
;
6533 /* if interface is down do nothing */
6534 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
6537 /* do nothing if we are not using signature filters */
6538 if (!(adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
))
6541 adapter
->fdir_overflow
++;
6543 if (ixgbe_reinit_fdir_tables_82599(hw
) == 0) {
6544 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
6545 set_bit(__IXGBE_TX_FDIR_INIT_DONE
,
6546 &(adapter
->tx_ring
[i
]->state
));
6547 /* re-enable flow director interrupts */
6548 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMS_FLOW_DIR
);
6550 e_err(probe
, "failed to finish FDIR re-initialization, "
6551 "ignored adding FDIR ATR filters\n");
6556 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
6557 * @adapter: pointer to the device adapter structure
6559 * This function serves two purposes. First it strobes the interrupt lines
6560 * in order to make certain interrupts are occurring. Secondly it sets the
6561 * bits needed to check for TX hangs. As a result we should immediately
6562 * determine if a hang has occurred.
6564 static void ixgbe_check_hang_subtask(struct ixgbe_adapter
*adapter
)
6566 struct ixgbe_hw
*hw
= &adapter
->hw
;
6570 /* If we're down, removing or resetting, just bail */
6571 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
6572 test_bit(__IXGBE_REMOVING
, &adapter
->state
) ||
6573 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
6576 /* Force detection of hung controller */
6577 if (netif_carrier_ok(adapter
->netdev
)) {
6578 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
6579 set_check_for_tx_hang(adapter
->tx_ring
[i
]);
6582 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)) {
6584 * for legacy and MSI interrupts don't set any bits
6585 * that are enabled for EIAM, because this operation
6586 * would set *both* EIMS and EICS for any bit in EIAM
6588 IXGBE_WRITE_REG(hw
, IXGBE_EICS
,
6589 (IXGBE_EICS_TCP_TIMER
| IXGBE_EICS_OTHER
));
6591 /* get one bit for every active tx/rx interrupt vector */
6592 for (i
= 0; i
< adapter
->num_q_vectors
; i
++) {
6593 struct ixgbe_q_vector
*qv
= adapter
->q_vector
[i
];
6594 if (qv
->rx
.ring
|| qv
->tx
.ring
)
6595 eics
|= ((u64
)1 << i
);
6599 /* Cause software interrupt to ensure rings are cleaned */
6600 ixgbe_irq_rearm_queues(adapter
, eics
);
6604 * ixgbe_watchdog_update_link - update the link status
6605 * @adapter: pointer to the device adapter structure
6606 * @link_speed: pointer to a u32 to store the link_speed
6608 static void ixgbe_watchdog_update_link(struct ixgbe_adapter
*adapter
)
6610 struct ixgbe_hw
*hw
= &adapter
->hw
;
6611 u32 link_speed
= adapter
->link_speed
;
6612 bool link_up
= adapter
->link_up
;
6613 bool pfc_en
= adapter
->dcb_cfg
.pfc_mode_enable
;
6615 if (!(adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
))
6618 if (hw
->mac
.ops
.check_link
) {
6619 hw
->mac
.ops
.check_link(hw
, &link_speed
, &link_up
, false);
6621 /* always assume link is up, if no check link function */
6622 link_speed
= IXGBE_LINK_SPEED_10GB_FULL
;
6626 if (adapter
->ixgbe_ieee_pfc
)
6627 pfc_en
|= !!(adapter
->ixgbe_ieee_pfc
->pfc_en
);
6629 if (link_up
&& !((adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) && pfc_en
)) {
6630 hw
->mac
.ops
.fc_enable(hw
);
6631 ixgbe_set_rx_drop_en(adapter
);
6635 time_after(jiffies
, (adapter
->link_check_timeout
+
6636 IXGBE_TRY_LINK_TIMEOUT
))) {
6637 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_UPDATE
;
6638 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMC_LSC
);
6639 IXGBE_WRITE_FLUSH(hw
);
6642 adapter
->link_up
= link_up
;
6643 adapter
->link_speed
= link_speed
;
6646 static void ixgbe_update_default_up(struct ixgbe_adapter
*adapter
)
6648 #ifdef CONFIG_IXGBE_DCB
6649 struct net_device
*netdev
= adapter
->netdev
;
6650 struct dcb_app app
= {
6651 .selector
= IEEE_8021QAZ_APP_SEL_ETHERTYPE
,
6656 if (adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
)
6657 up
= dcb_ieee_getapp_mask(netdev
, &app
);
6659 adapter
->default_up
= (up
> 1) ? (ffs(up
) - 1) : 0;
6664 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6665 * print link up message
6666 * @adapter: pointer to the device adapter structure
6668 static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter
*adapter
)
6670 struct net_device
*netdev
= adapter
->netdev
;
6671 struct ixgbe_hw
*hw
= &adapter
->hw
;
6672 struct net_device
*upper
;
6673 struct list_head
*iter
;
6674 u32 link_speed
= adapter
->link_speed
;
6675 const char *speed_str
;
6676 bool flow_rx
, flow_tx
;
6678 /* only continue if link was previously down */
6679 if (netif_carrier_ok(netdev
))
6682 adapter
->flags2
&= ~IXGBE_FLAG2_SEARCH_FOR_SFP
;
6684 switch (hw
->mac
.type
) {
6685 case ixgbe_mac_82598EB
: {
6686 u32 frctl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
6687 u32 rmcs
= IXGBE_READ_REG(hw
, IXGBE_RMCS
);
6688 flow_rx
= !!(frctl
& IXGBE_FCTRL_RFCE
);
6689 flow_tx
= !!(rmcs
& IXGBE_RMCS_TFCE_802_3X
);
6692 case ixgbe_mac_X540
:
6693 case ixgbe_mac_X550
:
6694 case ixgbe_mac_X550EM_x
:
6695 case ixgbe_mac_82599EB
: {
6696 u32 mflcn
= IXGBE_READ_REG(hw
, IXGBE_MFLCN
);
6697 u32 fccfg
= IXGBE_READ_REG(hw
, IXGBE_FCCFG
);
6698 flow_rx
= !!(mflcn
& IXGBE_MFLCN_RFCE
);
6699 flow_tx
= !!(fccfg
& IXGBE_FCCFG_TFCE_802_3X
);
6708 adapter
->last_rx_ptp_check
= jiffies
;
6710 if (test_bit(__IXGBE_PTP_RUNNING
, &adapter
->state
))
6711 ixgbe_ptp_start_cyclecounter(adapter
);
6713 switch (link_speed
) {
6714 case IXGBE_LINK_SPEED_10GB_FULL
:
6715 speed_str
= "10 Gbps";
6717 case IXGBE_LINK_SPEED_2_5GB_FULL
:
6718 speed_str
= "2.5 Gbps";
6720 case IXGBE_LINK_SPEED_1GB_FULL
:
6721 speed_str
= "1 Gbps";
6723 case IXGBE_LINK_SPEED_100_FULL
:
6724 speed_str
= "100 Mbps";
6727 speed_str
= "unknown speed";
6730 e_info(drv
, "NIC Link is Up %s, Flow Control: %s\n", speed_str
,
6731 ((flow_rx
&& flow_tx
) ? "RX/TX" :
6733 (flow_tx
? "TX" : "None"))));
6735 netif_carrier_on(netdev
);
6736 ixgbe_check_vf_rate_limit(adapter
);
6738 /* enable transmits */
6739 netif_tx_wake_all_queues(adapter
->netdev
);
6741 /* enable any upper devices */
6743 netdev_for_each_all_upper_dev_rcu(adapter
->netdev
, upper
, iter
) {
6744 if (netif_is_macvlan(upper
)) {
6745 struct macvlan_dev
*vlan
= netdev_priv(upper
);
6748 netif_tx_wake_all_queues(upper
);
6753 /* update the default user priority for VFs */
6754 ixgbe_update_default_up(adapter
);
6756 /* ping all the active vfs to let them know link has changed */
6757 ixgbe_ping_all_vfs(adapter
);
6761 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6762 * print link down message
6763 * @adapter: pointer to the adapter structure
6765 static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter
*adapter
)
6767 struct net_device
*netdev
= adapter
->netdev
;
6768 struct ixgbe_hw
*hw
= &adapter
->hw
;
6770 adapter
->link_up
= false;
6771 adapter
->link_speed
= 0;
6773 /* only continue if link was up previously */
6774 if (!netif_carrier_ok(netdev
))
6777 /* poll for SFP+ cable when link is down */
6778 if (ixgbe_is_sfp(hw
) && hw
->mac
.type
== ixgbe_mac_82598EB
)
6779 adapter
->flags2
|= IXGBE_FLAG2_SEARCH_FOR_SFP
;
6781 if (test_bit(__IXGBE_PTP_RUNNING
, &adapter
->state
))
6782 ixgbe_ptp_start_cyclecounter(adapter
);
6784 e_info(drv
, "NIC Link is Down\n");
6785 netif_carrier_off(netdev
);
6787 /* ping all the active vfs to let them know link has changed */
6788 ixgbe_ping_all_vfs(adapter
);
6791 static bool ixgbe_ring_tx_pending(struct ixgbe_adapter
*adapter
)
6795 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
6796 struct ixgbe_ring
*tx_ring
= adapter
->tx_ring
[i
];
6798 if (tx_ring
->next_to_use
!= tx_ring
->next_to_clean
)
6805 static bool ixgbe_vf_tx_pending(struct ixgbe_adapter
*adapter
)
6807 struct ixgbe_hw
*hw
= &adapter
->hw
;
6808 struct ixgbe_ring_feature
*vmdq
= &adapter
->ring_feature
[RING_F_VMDQ
];
6809 u32 q_per_pool
= __ALIGN_MASK(1, ~vmdq
->mask
);
6813 if (!adapter
->num_vfs
)
6816 /* resetting the PF is only needed for MAC before X550 */
6817 if (hw
->mac
.type
>= ixgbe_mac_X550
)
6820 for (i
= 0; i
< adapter
->num_vfs
; i
++) {
6821 for (j
= 0; j
< q_per_pool
; j
++) {
6824 h
= IXGBE_READ_REG(hw
, IXGBE_PVFTDHN(q_per_pool
, i
, j
));
6825 t
= IXGBE_READ_REG(hw
, IXGBE_PVFTDTN(q_per_pool
, i
, j
));
6836 * ixgbe_watchdog_flush_tx - flush queues on link down
6837 * @adapter: pointer to the device adapter structure
6839 static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter
*adapter
)
6841 if (!netif_carrier_ok(adapter
->netdev
)) {
6842 if (ixgbe_ring_tx_pending(adapter
) ||
6843 ixgbe_vf_tx_pending(adapter
)) {
6844 /* We've lost link, so the controller stops DMA,
6845 * but we've got queued Tx work that's never going
6846 * to get done, so reset controller to flush Tx.
6847 * (Do the reset outside of interrupt context).
6849 e_warn(drv
, "initiating reset to clear Tx work after link loss\n");
6850 adapter
->flags2
|= IXGBE_FLAG2_RESET_REQUESTED
;
6855 #ifdef CONFIG_PCI_IOV
6856 static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter
*adapter
,
6857 struct pci_dev
*vfdev
)
6859 if (!pci_wait_for_pending_transaction(vfdev
))
6860 e_dev_warn("Issuing VFLR with pending transactions\n");
6862 e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev
));
6863 pcie_capability_set_word(vfdev
, PCI_EXP_DEVCTL
, PCI_EXP_DEVCTL_BCR_FLR
);
6868 static void ixgbe_check_for_bad_vf(struct ixgbe_adapter
*adapter
)
6870 struct ixgbe_hw
*hw
= &adapter
->hw
;
6871 struct pci_dev
*pdev
= adapter
->pdev
;
6875 if (!(netif_carrier_ok(adapter
->netdev
)))
6878 gpc
= IXGBE_READ_REG(hw
, IXGBE_TXDGPC
);
6879 if (gpc
) /* If incrementing then no need for the check below */
6881 /* Check to see if a bad DMA write target from an errant or
6882 * malicious VF has caused a PCIe error. If so then we can
6883 * issue a VFLR to the offending VF(s) and then resume without
6884 * requesting a full slot reset.
6890 /* check status reg for all VFs owned by this PF */
6891 for (vf
= 0; vf
< adapter
->num_vfs
; ++vf
) {
6892 struct pci_dev
*vfdev
= adapter
->vfinfo
[vf
].vfdev
;
6897 pci_read_config_word(vfdev
, PCI_STATUS
, &status_reg
);
6898 if (status_reg
!= IXGBE_FAILED_READ_CFG_WORD
&&
6899 status_reg
& PCI_STATUS_REC_MASTER_ABORT
)
6900 ixgbe_issue_vf_flr(adapter
, vfdev
);
6904 static void ixgbe_spoof_check(struct ixgbe_adapter
*adapter
)
6908 /* Do not perform spoof check for 82598 or if not in IOV mode */
6909 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
||
6910 adapter
->num_vfs
== 0)
6913 ssvpc
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_SSVPC
);
6916 * ssvpc register is cleared on read, if zero then no
6917 * spoofed packets in the last interval.
6922 e_warn(drv
, "%u Spoofed packets detected\n", ssvpc
);
6925 static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused
*adapter
)
6930 ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused
*adapter
)
6933 #endif /* CONFIG_PCI_IOV */
6937 * ixgbe_watchdog_subtask - check and bring link up
6938 * @adapter: pointer to the device adapter structure
6940 static void ixgbe_watchdog_subtask(struct ixgbe_adapter
*adapter
)
6942 /* if interface is down, removing or resetting, do nothing */
6943 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
6944 test_bit(__IXGBE_REMOVING
, &adapter
->state
) ||
6945 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
6948 ixgbe_watchdog_update_link(adapter
);
6950 if (adapter
->link_up
)
6951 ixgbe_watchdog_link_is_up(adapter
);
6953 ixgbe_watchdog_link_is_down(adapter
);
6955 ixgbe_check_for_bad_vf(adapter
);
6956 ixgbe_spoof_check(adapter
);
6957 ixgbe_update_stats(adapter
);
6959 ixgbe_watchdog_flush_tx(adapter
);
6963 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6964 * @adapter: the ixgbe adapter structure
6966 static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter
*adapter
)
6968 struct ixgbe_hw
*hw
= &adapter
->hw
;
6971 /* not searching for SFP so there is nothing to do here */
6972 if (!(adapter
->flags2
& IXGBE_FLAG2_SEARCH_FOR_SFP
) &&
6973 !(adapter
->flags2
& IXGBE_FLAG2_SFP_NEEDS_RESET
))
6976 if (adapter
->sfp_poll_time
&&
6977 time_after(adapter
->sfp_poll_time
, jiffies
))
6978 return; /* If not yet time to poll for SFP */
6980 /* someone else is in init, wait until next service event */
6981 if (test_and_set_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
))
6984 adapter
->sfp_poll_time
= jiffies
+ IXGBE_SFP_POLL_JIFFIES
- 1;
6986 err
= hw
->phy
.ops
.identify_sfp(hw
);
6987 if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
)
6990 if (err
== IXGBE_ERR_SFP_NOT_PRESENT
) {
6991 /* If no cable is present, then we need to reset
6992 * the next time we find a good cable. */
6993 adapter
->flags2
|= IXGBE_FLAG2_SFP_NEEDS_RESET
;
7000 /* exit if reset not needed */
7001 if (!(adapter
->flags2
& IXGBE_FLAG2_SFP_NEEDS_RESET
))
7004 adapter
->flags2
&= ~IXGBE_FLAG2_SFP_NEEDS_RESET
;
7007 * A module may be identified correctly, but the EEPROM may not have
7008 * support for that module. setup_sfp() will fail in that case, so
7009 * we should not allow that module to load.
7011 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
7012 err
= hw
->phy
.ops
.reset(hw
);
7014 err
= hw
->mac
.ops
.setup_sfp(hw
);
7016 if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
)
7019 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_CONFIG
;
7020 e_info(probe
, "detected SFP+: %d\n", hw
->phy
.sfp_type
);
7023 clear_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
);
7025 if ((err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) &&
7026 (adapter
->netdev
->reg_state
== NETREG_REGISTERED
)) {
7027 e_dev_err("failed to initialize because an unsupported "
7028 "SFP+ module type was detected.\n");
7029 e_dev_err("Reload the driver after installing a "
7030 "supported module.\n");
7031 unregister_netdev(adapter
->netdev
);
7036 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
7037 * @adapter: the ixgbe adapter structure
7039 static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter
*adapter
)
7041 struct ixgbe_hw
*hw
= &adapter
->hw
;
7043 bool autoneg
= false;
7045 if (!(adapter
->flags
& IXGBE_FLAG_NEED_LINK_CONFIG
))
7048 /* someone else is in init, wait until next service event */
7049 if (test_and_set_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
))
7052 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_CONFIG
;
7054 speed
= hw
->phy
.autoneg_advertised
;
7055 if ((!speed
) && (hw
->mac
.ops
.get_link_capabilities
)) {
7056 hw
->mac
.ops
.get_link_capabilities(hw
, &speed
, &autoneg
);
7058 /* setup the highest link when no autoneg */
7060 if (speed
& IXGBE_LINK_SPEED_10GB_FULL
)
7061 speed
= IXGBE_LINK_SPEED_10GB_FULL
;
7065 if (hw
->mac
.ops
.setup_link
)
7066 hw
->mac
.ops
.setup_link(hw
, speed
, true);
7068 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
7069 adapter
->link_check_timeout
= jiffies
;
7070 clear_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
);
7074 * ixgbe_service_timer - Timer Call-back
7075 * @data: pointer to adapter cast into an unsigned long
7077 static void ixgbe_service_timer(unsigned long data
)
7079 struct ixgbe_adapter
*adapter
= (struct ixgbe_adapter
*)data
;
7080 unsigned long next_event_offset
;
7082 /* poll faster when waiting for link */
7083 if (adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
)
7084 next_event_offset
= HZ
/ 10;
7086 next_event_offset
= HZ
* 2;
7088 /* Reset the timer */
7089 mod_timer(&adapter
->service_timer
, next_event_offset
+ jiffies
);
7091 ixgbe_service_event_schedule(adapter
);
7094 static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter
*adapter
)
7096 struct ixgbe_hw
*hw
= &adapter
->hw
;
7099 if (!(adapter
->flags2
& IXGBE_FLAG2_PHY_INTERRUPT
))
7102 adapter
->flags2
&= ~IXGBE_FLAG2_PHY_INTERRUPT
;
7104 if (!hw
->phy
.ops
.handle_lasi
)
7107 status
= hw
->phy
.ops
.handle_lasi(&adapter
->hw
);
7108 if (status
!= IXGBE_ERR_OVERTEMP
)
7111 e_crit(drv
, "%s\n", ixgbe_overheat_msg
);
7114 static void ixgbe_reset_subtask(struct ixgbe_adapter
*adapter
)
7116 if (!(adapter
->flags2
& IXGBE_FLAG2_RESET_REQUESTED
))
7119 adapter
->flags2
&= ~IXGBE_FLAG2_RESET_REQUESTED
;
7121 /* If we're already down, removing or resetting, just bail */
7122 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
7123 test_bit(__IXGBE_REMOVING
, &adapter
->state
) ||
7124 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
7127 ixgbe_dump(adapter
);
7128 netdev_err(adapter
->netdev
, "Reset adapter\n");
7129 adapter
->tx_timeout_count
++;
7132 ixgbe_reinit_locked(adapter
);
7137 * ixgbe_service_task - manages and runs subtasks
7138 * @work: pointer to work_struct containing our data
7140 static void ixgbe_service_task(struct work_struct
*work
)
7142 struct ixgbe_adapter
*adapter
= container_of(work
,
7143 struct ixgbe_adapter
,
7145 if (ixgbe_removed(adapter
->hw
.hw_addr
)) {
7146 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
7148 ixgbe_down(adapter
);
7151 ixgbe_service_event_complete(adapter
);
7154 #ifdef CONFIG_IXGBE_VXLAN
7155 if (adapter
->flags2
& IXGBE_FLAG2_VXLAN_REREG_NEEDED
) {
7156 adapter
->flags2
&= ~IXGBE_FLAG2_VXLAN_REREG_NEEDED
;
7157 vxlan_get_rx_port(adapter
->netdev
);
7159 #endif /* CONFIG_IXGBE_VXLAN */
7160 ixgbe_reset_subtask(adapter
);
7161 ixgbe_phy_interrupt_subtask(adapter
);
7162 ixgbe_sfp_detection_subtask(adapter
);
7163 ixgbe_sfp_link_config_subtask(adapter
);
7164 ixgbe_check_overtemp_subtask(adapter
);
7165 ixgbe_watchdog_subtask(adapter
);
7166 ixgbe_fdir_reinit_subtask(adapter
);
7167 ixgbe_check_hang_subtask(adapter
);
7169 if (test_bit(__IXGBE_PTP_RUNNING
, &adapter
->state
)) {
7170 ixgbe_ptp_overflow_check(adapter
);
7171 ixgbe_ptp_rx_hang(adapter
);
7174 ixgbe_service_event_complete(adapter
);
7177 static int ixgbe_tso(struct ixgbe_ring
*tx_ring
,
7178 struct ixgbe_tx_buffer
*first
,
7181 struct sk_buff
*skb
= first
->skb
;
7182 u32 vlan_macip_lens
, type_tucmd
;
7183 u32 mss_l4len_idx
, l4len
;
7186 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
7189 if (!skb_is_gso(skb
))
7192 err
= skb_cow_head(skb
, 0);
7196 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
7197 type_tucmd
= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
7199 if (first
->protocol
== htons(ETH_P_IP
)) {
7200 struct iphdr
*iph
= ip_hdr(skb
);
7203 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
7207 type_tucmd
|= IXGBE_ADVTXD_TUCMD_IPV4
;
7208 first
->tx_flags
|= IXGBE_TX_FLAGS_TSO
|
7209 IXGBE_TX_FLAGS_CSUM
|
7210 IXGBE_TX_FLAGS_IPV4
;
7211 } else if (skb_is_gso_v6(skb
)) {
7212 ipv6_hdr(skb
)->payload_len
= 0;
7213 tcp_hdr(skb
)->check
=
7214 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
7215 &ipv6_hdr(skb
)->daddr
,
7217 first
->tx_flags
|= IXGBE_TX_FLAGS_TSO
|
7218 IXGBE_TX_FLAGS_CSUM
;
7221 /* compute header lengths */
7222 l4len
= tcp_hdrlen(skb
);
7223 *hdr_len
= skb_transport_offset(skb
) + l4len
;
7225 /* update gso size and bytecount with header size */
7226 first
->gso_segs
= skb_shinfo(skb
)->gso_segs
;
7227 first
->bytecount
+= (first
->gso_segs
- 1) * *hdr_len
;
7229 /* mss_l4len_id: use 0 as index for TSO */
7230 mss_l4len_idx
= l4len
<< IXGBE_ADVTXD_L4LEN_SHIFT
;
7231 mss_l4len_idx
|= skb_shinfo(skb
)->gso_size
<< IXGBE_ADVTXD_MSS_SHIFT
;
7233 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
7234 vlan_macip_lens
= skb_network_header_len(skb
);
7235 vlan_macip_lens
|= skb_network_offset(skb
) << IXGBE_ADVTXD_MACLEN_SHIFT
;
7236 vlan_macip_lens
|= first
->tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
;
7238 ixgbe_tx_ctxtdesc(tx_ring
, vlan_macip_lens
, 0, type_tucmd
,
7244 static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff
*skb
)
7246 unsigned int offset
= 0;
7248 ipv6_find_hdr(skb
, &offset
, IPPROTO_SCTP
, NULL
, NULL
);
7250 return offset
== skb_checksum_start_offset(skb
);
7253 static void ixgbe_tx_csum(struct ixgbe_ring
*tx_ring
,
7254 struct ixgbe_tx_buffer
*first
)
7256 struct sk_buff
*skb
= first
->skb
;
7257 u32 vlan_macip_lens
= 0;
7260 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
) {
7262 if (!(first
->tx_flags
& (IXGBE_TX_FLAGS_HW_VLAN
|
7263 IXGBE_TX_FLAGS_CC
)))
7268 switch (skb
->csum_offset
) {
7269 case offsetof(struct tcphdr
, check
):
7270 type_tucmd
= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
7272 case offsetof(struct udphdr
, check
):
7274 case offsetof(struct sctphdr
, checksum
):
7275 /* validate that this is actually an SCTP request */
7276 if (((first
->protocol
== htons(ETH_P_IP
)) &&
7277 (ip_hdr(skb
)->protocol
== IPPROTO_SCTP
)) ||
7278 ((first
->protocol
== htons(ETH_P_IPV6
)) &&
7279 ixgbe_ipv6_csum_is_sctp(skb
))) {
7280 type_tucmd
= IXGBE_ADVTXD_TUCMD_L4T_SCTP
;
7285 skb_checksum_help(skb
);
7289 /* update TX checksum flag */
7290 first
->tx_flags
|= IXGBE_TX_FLAGS_CSUM
;
7291 vlan_macip_lens
= skb_checksum_start_offset(skb
) -
7292 skb_network_offset(skb
);
7294 /* vlan_macip_lens: MACLEN, VLAN tag */
7295 vlan_macip_lens
|= skb_network_offset(skb
) << IXGBE_ADVTXD_MACLEN_SHIFT
;
7296 vlan_macip_lens
|= first
->tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
;
7298 ixgbe_tx_ctxtdesc(tx_ring
, vlan_macip_lens
, 0, type_tucmd
, 0);
7301 #define IXGBE_SET_FLAG(_input, _flag, _result) \
7302 ((_flag <= _result) ? \
7303 ((u32)(_input & _flag) * (_result / _flag)) : \
7304 ((u32)(_input & _flag) / (_flag / _result)))
7306 static u32
ixgbe_tx_cmd_type(struct sk_buff
*skb
, u32 tx_flags
)
7308 /* set type for advanced descriptor with frame checksum insertion */
7309 u32 cmd_type
= IXGBE_ADVTXD_DTYP_DATA
|
7310 IXGBE_ADVTXD_DCMD_DEXT
|
7311 IXGBE_ADVTXD_DCMD_IFCS
;
7313 /* set HW vlan bit if vlan is present */
7314 cmd_type
|= IXGBE_SET_FLAG(tx_flags
, IXGBE_TX_FLAGS_HW_VLAN
,
7315 IXGBE_ADVTXD_DCMD_VLE
);
7317 /* set segmentation enable bits for TSO/FSO */
7318 cmd_type
|= IXGBE_SET_FLAG(tx_flags
, IXGBE_TX_FLAGS_TSO
,
7319 IXGBE_ADVTXD_DCMD_TSE
);
7321 /* set timestamp bit if present */
7322 cmd_type
|= IXGBE_SET_FLAG(tx_flags
, IXGBE_TX_FLAGS_TSTAMP
,
7323 IXGBE_ADVTXD_MAC_TSTAMP
);
7325 /* insert frame checksum */
7326 cmd_type
^= IXGBE_SET_FLAG(skb
->no_fcs
, 1, IXGBE_ADVTXD_DCMD_IFCS
);
7331 static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc
*tx_desc
,
7332 u32 tx_flags
, unsigned int paylen
)
7334 u32 olinfo_status
= paylen
<< IXGBE_ADVTXD_PAYLEN_SHIFT
;
7336 /* enable L4 checksum for TSO and TX checksum offload */
7337 olinfo_status
|= IXGBE_SET_FLAG(tx_flags
,
7338 IXGBE_TX_FLAGS_CSUM
,
7339 IXGBE_ADVTXD_POPTS_TXSM
);
7341 /* enble IPv4 checksum for TSO */
7342 olinfo_status
|= IXGBE_SET_FLAG(tx_flags
,
7343 IXGBE_TX_FLAGS_IPV4
,
7344 IXGBE_ADVTXD_POPTS_IXSM
);
7347 * Check Context must be set if Tx switch is enabled, which it
7348 * always is for case where virtual functions are running
7350 olinfo_status
|= IXGBE_SET_FLAG(tx_flags
,
7354 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
7357 static int __ixgbe_maybe_stop_tx(struct ixgbe_ring
*tx_ring
, u16 size
)
7359 netif_stop_subqueue(tx_ring
->netdev
, tx_ring
->queue_index
);
7361 /* Herbert's original patch had:
7362 * smp_mb__after_netif_stop_queue();
7363 * but since that doesn't exist yet, just open code it.
7367 /* We need to check again in a case another CPU has just
7368 * made room available.
7370 if (likely(ixgbe_desc_unused(tx_ring
) < size
))
7373 /* A reprieve! - use start_queue because it doesn't call schedule */
7374 netif_start_subqueue(tx_ring
->netdev
, tx_ring
->queue_index
);
7375 ++tx_ring
->tx_stats
.restart_queue
;
7379 static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring
*tx_ring
, u16 size
)
7381 if (likely(ixgbe_desc_unused(tx_ring
) >= size
))
7384 return __ixgbe_maybe_stop_tx(tx_ring
, size
);
7387 #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
7390 static void ixgbe_tx_map(struct ixgbe_ring
*tx_ring
,
7391 struct ixgbe_tx_buffer
*first
,
7394 struct sk_buff
*skb
= first
->skb
;
7395 struct ixgbe_tx_buffer
*tx_buffer
;
7396 union ixgbe_adv_tx_desc
*tx_desc
;
7397 struct skb_frag_struct
*frag
;
7399 unsigned int data_len
, size
;
7400 u32 tx_flags
= first
->tx_flags
;
7401 u32 cmd_type
= ixgbe_tx_cmd_type(skb
, tx_flags
);
7402 u16 i
= tx_ring
->next_to_use
;
7404 tx_desc
= IXGBE_TX_DESC(tx_ring
, i
);
7406 ixgbe_tx_olinfo_status(tx_desc
, tx_flags
, skb
->len
- hdr_len
);
7408 size
= skb_headlen(skb
);
7409 data_len
= skb
->data_len
;
7412 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
) {
7413 if (data_len
< sizeof(struct fcoe_crc_eof
)) {
7414 size
-= sizeof(struct fcoe_crc_eof
) - data_len
;
7417 data_len
-= sizeof(struct fcoe_crc_eof
);
7422 dma
= dma_map_single(tx_ring
->dev
, skb
->data
, size
, DMA_TO_DEVICE
);
7426 for (frag
= &skb_shinfo(skb
)->frags
[0];; frag
++) {
7427 if (dma_mapping_error(tx_ring
->dev
, dma
))
7430 /* record length, and DMA address */
7431 dma_unmap_len_set(tx_buffer
, len
, size
);
7432 dma_unmap_addr_set(tx_buffer
, dma
, dma
);
7434 tx_desc
->read
.buffer_addr
= cpu_to_le64(dma
);
7436 while (unlikely(size
> IXGBE_MAX_DATA_PER_TXD
)) {
7437 tx_desc
->read
.cmd_type_len
=
7438 cpu_to_le32(cmd_type
^ IXGBE_MAX_DATA_PER_TXD
);
7442 if (i
== tx_ring
->count
) {
7443 tx_desc
= IXGBE_TX_DESC(tx_ring
, 0);
7446 tx_desc
->read
.olinfo_status
= 0;
7448 dma
+= IXGBE_MAX_DATA_PER_TXD
;
7449 size
-= IXGBE_MAX_DATA_PER_TXD
;
7451 tx_desc
->read
.buffer_addr
= cpu_to_le64(dma
);
7454 if (likely(!data_len
))
7457 tx_desc
->read
.cmd_type_len
= cpu_to_le32(cmd_type
^ size
);
7461 if (i
== tx_ring
->count
) {
7462 tx_desc
= IXGBE_TX_DESC(tx_ring
, 0);
7465 tx_desc
->read
.olinfo_status
= 0;
7468 size
= min_t(unsigned int, data_len
, skb_frag_size(frag
));
7470 size
= skb_frag_size(frag
);
7474 dma
= skb_frag_dma_map(tx_ring
->dev
, frag
, 0, size
,
7477 tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
7480 /* write last descriptor with RS and EOP bits */
7481 cmd_type
|= size
| IXGBE_TXD_CMD
;
7482 tx_desc
->read
.cmd_type_len
= cpu_to_le32(cmd_type
);
7484 netdev_tx_sent_queue(txring_txq(tx_ring
), first
->bytecount
);
7486 /* set the timestamp */
7487 first
->time_stamp
= jiffies
;
7490 * Force memory writes to complete before letting h/w know there
7491 * are new descriptors to fetch. (Only applicable for weak-ordered
7492 * memory model archs, such as IA-64).
7494 * We also need this memory barrier to make certain all of the
7495 * status bits have been updated before next_to_watch is written.
7499 /* set next_to_watch value indicating a packet is present */
7500 first
->next_to_watch
= tx_desc
;
7503 if (i
== tx_ring
->count
)
7506 tx_ring
->next_to_use
= i
;
7508 ixgbe_maybe_stop_tx(tx_ring
, DESC_NEEDED
);
7510 if (netif_xmit_stopped(txring_txq(tx_ring
)) || !skb
->xmit_more
) {
7511 writel(i
, tx_ring
->tail
);
7513 /* we need this if more than one processor can write to our tail
7514 * at a time, it synchronizes IO on IA64/Altix systems
7521 dev_err(tx_ring
->dev
, "TX DMA map failed\n");
7523 /* clear dma mappings for failed tx_buffer_info map */
7525 tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
7526 ixgbe_unmap_and_free_tx_resource(tx_ring
, tx_buffer
);
7527 if (tx_buffer
== first
)
7534 tx_ring
->next_to_use
= i
;
7537 static void ixgbe_atr(struct ixgbe_ring
*ring
,
7538 struct ixgbe_tx_buffer
*first
)
7540 struct ixgbe_q_vector
*q_vector
= ring
->q_vector
;
7541 union ixgbe_atr_hash_dword input
= { .dword
= 0 };
7542 union ixgbe_atr_hash_dword common
= { .dword
= 0 };
7544 unsigned char *network
;
7546 struct ipv6hdr
*ipv6
;
7550 struct sk_buff
*skb
;
7554 /* if ring doesn't have a interrupt vector, cannot perform ATR */
7558 /* do nothing if sampling is disabled */
7559 if (!ring
->atr_sample_rate
)
7564 /* currently only IPv4/IPv6 with TCP is supported */
7565 if ((first
->protocol
!= htons(ETH_P_IP
)) &&
7566 (first
->protocol
!= htons(ETH_P_IPV6
)))
7569 /* snag network header to get L4 type and address */
7571 hdr
.network
= skb_network_header(skb
);
7572 #ifdef CONFIG_IXGBE_VXLAN
7573 if (skb
->encapsulation
&&
7574 first
->protocol
== htons(ETH_P_IP
) &&
7575 hdr
.ipv4
->protocol
!= IPPROTO_UDP
) {
7576 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
7578 /* verify the port is recognized as VXLAN */
7579 if (adapter
->vxlan_port
&&
7580 udp_hdr(skb
)->dest
== adapter
->vxlan_port
)
7581 hdr
.network
= skb_inner_network_header(skb
);
7583 #endif /* CONFIG_IXGBE_VXLAN */
7585 /* Currently only IPv4/IPv6 with TCP is supported */
7586 switch (hdr
.ipv4
->version
) {
7588 /* access ihl as u8 to avoid unaligned access on ia64 */
7589 hlen
= (hdr
.network
[0] & 0x0F) << 2;
7590 l4_proto
= hdr
.ipv4
->protocol
;
7593 hlen
= hdr
.network
- skb
->data
;
7594 l4_proto
= ipv6_find_hdr(skb
, &hlen
, IPPROTO_TCP
, NULL
, NULL
);
7595 hlen
-= hdr
.network
- skb
->data
;
7601 if (l4_proto
!= IPPROTO_TCP
)
7604 th
= (struct tcphdr
*)(hdr
.network
+ hlen
);
7606 /* skip this packet since the socket is closing */
7610 /* sample on all syn packets or once every atr sample count */
7611 if (!th
->syn
&& (ring
->atr_count
< ring
->atr_sample_rate
))
7614 /* reset sample count */
7615 ring
->atr_count
= 0;
7617 vlan_id
= htons(first
->tx_flags
>> IXGBE_TX_FLAGS_VLAN_SHIFT
);
7620 * src and dst are inverted, think how the receiver sees them
7622 * The input is broken into two sections, a non-compressed section
7623 * containing vm_pool, vlan_id, and flow_type. The rest of the data
7624 * is XORed together and stored in the compressed dword.
7626 input
.formatted
.vlan_id
= vlan_id
;
7629 * since src port and flex bytes occupy the same word XOR them together
7630 * and write the value to source port portion of compressed dword
7632 if (first
->tx_flags
& (IXGBE_TX_FLAGS_SW_VLAN
| IXGBE_TX_FLAGS_HW_VLAN
))
7633 common
.port
.src
^= th
->dest
^ htons(ETH_P_8021Q
);
7635 common
.port
.src
^= th
->dest
^ first
->protocol
;
7636 common
.port
.dst
^= th
->source
;
7638 switch (hdr
.ipv4
->version
) {
7640 input
.formatted
.flow_type
= IXGBE_ATR_FLOW_TYPE_TCPV4
;
7641 common
.ip
^= hdr
.ipv4
->saddr
^ hdr
.ipv4
->daddr
;
7644 input
.formatted
.flow_type
= IXGBE_ATR_FLOW_TYPE_TCPV6
;
7645 common
.ip
^= hdr
.ipv6
->saddr
.s6_addr32
[0] ^
7646 hdr
.ipv6
->saddr
.s6_addr32
[1] ^
7647 hdr
.ipv6
->saddr
.s6_addr32
[2] ^
7648 hdr
.ipv6
->saddr
.s6_addr32
[3] ^
7649 hdr
.ipv6
->daddr
.s6_addr32
[0] ^
7650 hdr
.ipv6
->daddr
.s6_addr32
[1] ^
7651 hdr
.ipv6
->daddr
.s6_addr32
[2] ^
7652 hdr
.ipv6
->daddr
.s6_addr32
[3];
7658 if (hdr
.network
!= skb_network_header(skb
))
7659 input
.formatted
.flow_type
|= IXGBE_ATR_L4TYPE_TUNNEL_MASK
;
7661 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
7662 ixgbe_fdir_add_signature_filter_82599(&q_vector
->adapter
->hw
,
7663 input
, common
, ring
->queue_index
);
7666 static u16
ixgbe_select_queue(struct net_device
*dev
, struct sk_buff
*skb
,
7667 void *accel_priv
, select_queue_fallback_t fallback
)
7669 struct ixgbe_fwd_adapter
*fwd_adapter
= accel_priv
;
7671 struct ixgbe_adapter
*adapter
;
7672 struct ixgbe_ring_feature
*f
;
7677 return skb
->queue_mapping
+ fwd_adapter
->tx_base_queue
;
7682 * only execute the code below if protocol is FCoE
7683 * or FIP and we have FCoE enabled on the adapter
7685 switch (vlan_get_protocol(skb
)) {
7686 case htons(ETH_P_FCOE
):
7687 case htons(ETH_P_FIP
):
7688 adapter
= netdev_priv(dev
);
7690 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
7693 return fallback(dev
, skb
);
7696 f
= &adapter
->ring_feature
[RING_F_FCOE
];
7698 txq
= skb_rx_queue_recorded(skb
) ? skb_get_rx_queue(skb
) :
7701 while (txq
>= f
->indices
)
7704 return txq
+ f
->offset
;
7706 return fallback(dev
, skb
);
7710 netdev_tx_t
ixgbe_xmit_frame_ring(struct sk_buff
*skb
,
7711 struct ixgbe_adapter
*adapter
,
7712 struct ixgbe_ring
*tx_ring
)
7714 struct ixgbe_tx_buffer
*first
;
7718 u16 count
= TXD_USE_COUNT(skb_headlen(skb
));
7719 __be16 protocol
= skb
->protocol
;
7723 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
7724 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
7725 * + 2 desc gap to keep tail from touching head,
7726 * + 1 desc for context descriptor,
7727 * otherwise try next time
7729 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++)
7730 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
);
7732 if (ixgbe_maybe_stop_tx(tx_ring
, count
+ 3)) {
7733 tx_ring
->tx_stats
.tx_busy
++;
7734 return NETDEV_TX_BUSY
;
7737 /* record the location of the first descriptor for this packet */
7738 first
= &tx_ring
->tx_buffer_info
[tx_ring
->next_to_use
];
7740 first
->bytecount
= skb
->len
;
7741 first
->gso_segs
= 1;
7743 /* if we have a HW VLAN tag being added default to the HW one */
7744 if (skb_vlan_tag_present(skb
)) {
7745 tx_flags
|= skb_vlan_tag_get(skb
) << IXGBE_TX_FLAGS_VLAN_SHIFT
;
7746 tx_flags
|= IXGBE_TX_FLAGS_HW_VLAN
;
7747 /* else if it is a SW VLAN check the next protocol and store the tag */
7748 } else if (protocol
== htons(ETH_P_8021Q
)) {
7749 struct vlan_hdr
*vhdr
, _vhdr
;
7750 vhdr
= skb_header_pointer(skb
, ETH_HLEN
, sizeof(_vhdr
), &_vhdr
);
7754 tx_flags
|= ntohs(vhdr
->h_vlan_TCI
) <<
7755 IXGBE_TX_FLAGS_VLAN_SHIFT
;
7756 tx_flags
|= IXGBE_TX_FLAGS_SW_VLAN
;
7758 protocol
= vlan_get_protocol(skb
);
7760 if (unlikely(skb_shinfo(skb
)->tx_flags
& SKBTX_HW_TSTAMP
) &&
7761 adapter
->ptp_clock
&&
7762 !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS
,
7764 skb_shinfo(skb
)->tx_flags
|= SKBTX_IN_PROGRESS
;
7765 tx_flags
|= IXGBE_TX_FLAGS_TSTAMP
;
7767 /* schedule check for Tx timestamp */
7768 adapter
->ptp_tx_skb
= skb_get(skb
);
7769 adapter
->ptp_tx_start
= jiffies
;
7770 schedule_work(&adapter
->ptp_tx_work
);
7773 skb_tx_timestamp(skb
);
7775 #ifdef CONFIG_PCI_IOV
7777 * Use the l2switch_enable flag - would be false if the DMA
7778 * Tx switch had been disabled.
7780 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
7781 tx_flags
|= IXGBE_TX_FLAGS_CC
;
7784 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
7785 if ((adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) &&
7786 ((tx_flags
& (IXGBE_TX_FLAGS_HW_VLAN
| IXGBE_TX_FLAGS_SW_VLAN
)) ||
7787 (skb
->priority
!= TC_PRIO_CONTROL
))) {
7788 tx_flags
&= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK
;
7789 tx_flags
|= (skb
->priority
& 0x7) <<
7790 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT
;
7791 if (tx_flags
& IXGBE_TX_FLAGS_SW_VLAN
) {
7792 struct vlan_ethhdr
*vhdr
;
7794 if (skb_cow_head(skb
, 0))
7796 vhdr
= (struct vlan_ethhdr
*)skb
->data
;
7797 vhdr
->h_vlan_TCI
= htons(tx_flags
>>
7798 IXGBE_TX_FLAGS_VLAN_SHIFT
);
7800 tx_flags
|= IXGBE_TX_FLAGS_HW_VLAN
;
7804 /* record initial flags and protocol */
7805 first
->tx_flags
= tx_flags
;
7806 first
->protocol
= protocol
;
7809 /* setup tx offload for FCoE */
7810 if ((protocol
== htons(ETH_P_FCOE
)) &&
7811 (tx_ring
->netdev
->features
& (NETIF_F_FSO
| NETIF_F_FCOE_CRC
))) {
7812 tso
= ixgbe_fso(tx_ring
, first
, &hdr_len
);
7819 #endif /* IXGBE_FCOE */
7820 tso
= ixgbe_tso(tx_ring
, first
, &hdr_len
);
7824 ixgbe_tx_csum(tx_ring
, first
);
7826 /* add the ATR filter if ATR is on */
7827 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE
, &tx_ring
->state
))
7828 ixgbe_atr(tx_ring
, first
);
7832 #endif /* IXGBE_FCOE */
7833 ixgbe_tx_map(tx_ring
, first
, hdr_len
);
7835 return NETDEV_TX_OK
;
7838 dev_kfree_skb_any(first
->skb
);
7841 return NETDEV_TX_OK
;
7844 static netdev_tx_t
__ixgbe_xmit_frame(struct sk_buff
*skb
,
7845 struct net_device
*netdev
,
7846 struct ixgbe_ring
*ring
)
7848 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7849 struct ixgbe_ring
*tx_ring
;
7852 * The minimum packet size for olinfo paylen is 17 so pad the skb
7853 * in order to meet this minimum size requirement.
7855 if (skb_put_padto(skb
, 17))
7856 return NETDEV_TX_OK
;
7858 tx_ring
= ring
? ring
: adapter
->tx_ring
[skb
->queue_mapping
];
7860 return ixgbe_xmit_frame_ring(skb
, adapter
, tx_ring
);
7863 static netdev_tx_t
ixgbe_xmit_frame(struct sk_buff
*skb
,
7864 struct net_device
*netdev
)
7866 return __ixgbe_xmit_frame(skb
, netdev
, NULL
);
7870 * ixgbe_set_mac - Change the Ethernet Address of the NIC
7871 * @netdev: network interface device structure
7872 * @p: pointer to an address structure
7874 * Returns 0 on success, negative on failure
7876 static int ixgbe_set_mac(struct net_device
*netdev
, void *p
)
7878 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7879 struct ixgbe_hw
*hw
= &adapter
->hw
;
7880 struct sockaddr
*addr
= p
;
7882 if (!is_valid_ether_addr(addr
->sa_data
))
7883 return -EADDRNOTAVAIL
;
7885 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
7886 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
7888 ixgbe_mac_set_default_filter(adapter
);
7894 ixgbe_mdio_read(struct net_device
*netdev
, int prtad
, int devad
, u16 addr
)
7896 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7897 struct ixgbe_hw
*hw
= &adapter
->hw
;
7901 if (prtad
!= hw
->phy
.mdio
.prtad
)
7903 rc
= hw
->phy
.ops
.read_reg(hw
, addr
, devad
, &value
);
7909 static int ixgbe_mdio_write(struct net_device
*netdev
, int prtad
, int devad
,
7910 u16 addr
, u16 value
)
7912 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7913 struct ixgbe_hw
*hw
= &adapter
->hw
;
7915 if (prtad
!= hw
->phy
.mdio
.prtad
)
7917 return hw
->phy
.ops
.write_reg(hw
, addr
, devad
, value
);
7920 static int ixgbe_ioctl(struct net_device
*netdev
, struct ifreq
*req
, int cmd
)
7922 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7926 return ixgbe_ptp_set_ts_config(adapter
, req
);
7928 return ixgbe_ptp_get_ts_config(adapter
, req
);
7930 return mdio_mii_ioctl(&adapter
->hw
.phy
.mdio
, if_mii(req
), cmd
);
7935 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
7937 * @netdev: network interface device structure
7939 * Returns non-zero on failure
7941 static int ixgbe_add_sanmac_netdev(struct net_device
*dev
)
7944 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
7945 struct ixgbe_hw
*hw
= &adapter
->hw
;
7947 if (is_valid_ether_addr(hw
->mac
.san_addr
)) {
7949 err
= dev_addr_add(dev
, hw
->mac
.san_addr
, NETDEV_HW_ADDR_T_SAN
);
7952 /* update SAN MAC vmdq pool selection */
7953 hw
->mac
.ops
.set_vmdq_san_mac(hw
, VMDQ_P(0));
7959 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
7961 * @netdev: network interface device structure
7963 * Returns non-zero on failure
7965 static int ixgbe_del_sanmac_netdev(struct net_device
*dev
)
7968 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
7969 struct ixgbe_mac_info
*mac
= &adapter
->hw
.mac
;
7971 if (is_valid_ether_addr(mac
->san_addr
)) {
7973 err
= dev_addr_del(dev
, mac
->san_addr
, NETDEV_HW_ADDR_T_SAN
);
7979 #ifdef CONFIG_NET_POLL_CONTROLLER
7981 * Polling 'interrupt' - used by things like netconsole to send skbs
7982 * without having to re-enable interrupts. It's not called while
7983 * the interrupt routine is executing.
7985 static void ixgbe_netpoll(struct net_device
*netdev
)
7987 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7990 /* if interface is down do nothing */
7991 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
7994 /* loop through and schedule all active queues */
7995 for (i
= 0; i
< adapter
->num_q_vectors
; i
++)
7996 ixgbe_msix_clean_rings(0, adapter
->q_vector
[i
]);
8000 static struct rtnl_link_stats64
*ixgbe_get_stats64(struct net_device
*netdev
,
8001 struct rtnl_link_stats64
*stats
)
8003 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
8007 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
8008 struct ixgbe_ring
*ring
= ACCESS_ONCE(adapter
->rx_ring
[i
]);
8014 start
= u64_stats_fetch_begin_irq(&ring
->syncp
);
8015 packets
= ring
->stats
.packets
;
8016 bytes
= ring
->stats
.bytes
;
8017 } while (u64_stats_fetch_retry_irq(&ring
->syncp
, start
));
8018 stats
->rx_packets
+= packets
;
8019 stats
->rx_bytes
+= bytes
;
8023 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
8024 struct ixgbe_ring
*ring
= ACCESS_ONCE(adapter
->tx_ring
[i
]);
8030 start
= u64_stats_fetch_begin_irq(&ring
->syncp
);
8031 packets
= ring
->stats
.packets
;
8032 bytes
= ring
->stats
.bytes
;
8033 } while (u64_stats_fetch_retry_irq(&ring
->syncp
, start
));
8034 stats
->tx_packets
+= packets
;
8035 stats
->tx_bytes
+= bytes
;
8039 /* following stats updated by ixgbe_watchdog_task() */
8040 stats
->multicast
= netdev
->stats
.multicast
;
8041 stats
->rx_errors
= netdev
->stats
.rx_errors
;
8042 stats
->rx_length_errors
= netdev
->stats
.rx_length_errors
;
8043 stats
->rx_crc_errors
= netdev
->stats
.rx_crc_errors
;
8044 stats
->rx_missed_errors
= netdev
->stats
.rx_missed_errors
;
8048 #ifdef CONFIG_IXGBE_DCB
8050 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
8051 * @adapter: pointer to ixgbe_adapter
8052 * @tc: number of traffic classes currently enabled
8054 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
8055 * 802.1Q priority maps to a packet buffer that exists.
8057 static void ixgbe_validate_rtr(struct ixgbe_adapter
*adapter
, u8 tc
)
8059 struct ixgbe_hw
*hw
= &adapter
->hw
;
8063 /* 82598 have a static priority to TC mapping that can not
8064 * be changed so no validation is needed.
8066 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
8069 reg
= IXGBE_READ_REG(hw
, IXGBE_RTRUP2TC
);
8072 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
8073 u8 up2tc
= reg
>> (i
* IXGBE_RTRUP2TC_UP_SHIFT
);
8075 /* If up2tc is out of bounds default to zero */
8077 reg
&= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT
);
8081 IXGBE_WRITE_REG(hw
, IXGBE_RTRUP2TC
, reg
);
8087 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
8088 * @adapter: Pointer to adapter struct
8090 * Populate the netdev user priority to tc map
8092 static void ixgbe_set_prio_tc_map(struct ixgbe_adapter
*adapter
)
8094 struct net_device
*dev
= adapter
->netdev
;
8095 struct ixgbe_dcb_config
*dcb_cfg
= &adapter
->dcb_cfg
;
8096 struct ieee_ets
*ets
= adapter
->ixgbe_ieee_ets
;
8099 for (prio
= 0; prio
< MAX_USER_PRIORITY
; prio
++) {
8102 if (adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
)
8103 tc
= ixgbe_dcb_get_tc_from_up(dcb_cfg
, 0, prio
);
8105 tc
= ets
->prio_tc
[prio
];
8107 netdev_set_prio_tc_map(dev
, prio
, tc
);
8111 #endif /* CONFIG_IXGBE_DCB */
8113 * ixgbe_setup_tc - configure net_device for multiple traffic classes
8115 * @netdev: net device to configure
8116 * @tc: number of traffic classes to enable
8118 int ixgbe_setup_tc(struct net_device
*dev
, u8 tc
)
8120 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
8121 struct ixgbe_hw
*hw
= &adapter
->hw
;
8124 /* Hardware supports up to 8 traffic classes */
8125 if (tc
> adapter
->dcb_cfg
.num_tcs
.pg_tcs
)
8128 if (hw
->mac
.type
== ixgbe_mac_82598EB
&& tc
&& tc
< MAX_TRAFFIC_CLASS
)
8131 pools
= (find_first_zero_bit(&adapter
->fwd_bitmask
, 32) > 1);
8132 if (tc
&& pools
&& adapter
->num_rx_pools
> IXGBE_MAX_DCBMACVLANS
)
8135 /* Hardware has to reinitialize queues and interrupts to
8136 * match packet buffer alignment. Unfortunately, the
8137 * hardware is not flexible enough to do this dynamically.
8139 if (netif_running(dev
))
8142 ixgbe_reset(adapter
);
8144 ixgbe_clear_interrupt_scheme(adapter
);
8146 #ifdef CONFIG_IXGBE_DCB
8148 netdev_set_num_tc(dev
, tc
);
8149 ixgbe_set_prio_tc_map(adapter
);
8151 adapter
->flags
|= IXGBE_FLAG_DCB_ENABLED
;
8153 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
8154 adapter
->last_lfc_mode
= adapter
->hw
.fc
.requested_mode
;
8155 adapter
->hw
.fc
.requested_mode
= ixgbe_fc_none
;
8158 netdev_reset_tc(dev
);
8160 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
8161 adapter
->hw
.fc
.requested_mode
= adapter
->last_lfc_mode
;
8163 adapter
->flags
&= ~IXGBE_FLAG_DCB_ENABLED
;
8165 adapter
->temp_dcb_cfg
.pfc_mode_enable
= false;
8166 adapter
->dcb_cfg
.pfc_mode_enable
= false;
8169 ixgbe_validate_rtr(adapter
, tc
);
8171 #endif /* CONFIG_IXGBE_DCB */
8172 ixgbe_init_interrupt_scheme(adapter
);
8174 if (netif_running(dev
))
8175 return ixgbe_open(dev
);
8180 static int ixgbe_delete_clsu32(struct ixgbe_adapter
*adapter
,
8181 struct tc_cls_u32_offload
*cls
)
8183 u32 uhtid
= TC_U32_USERHTID(cls
->knode
.handle
);
8187 if ((uhtid
!= 0x800) && (uhtid
>= IXGBE_MAX_LINK_HANDLE
))
8190 loc
= cls
->knode
.handle
& 0xfffff;
8192 spin_lock(&adapter
->fdir_perfect_lock
);
8193 err
= ixgbe_update_ethtool_fdir_entry(adapter
, NULL
, loc
);
8194 spin_unlock(&adapter
->fdir_perfect_lock
);
8198 static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter
*adapter
,
8200 struct tc_cls_u32_offload
*cls
)
8202 u32 uhtid
= TC_U32_USERHTID(cls
->hnode
.handle
);
8204 if (uhtid
>= IXGBE_MAX_LINK_HANDLE
)
8207 /* This ixgbe devices do not support hash tables at the moment
8208 * so abort when given hash tables.
8210 if (cls
->hnode
.divisor
> 0)
8213 set_bit(uhtid
- 1, &adapter
->tables
);
8217 static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter
*adapter
,
8218 struct tc_cls_u32_offload
*cls
)
8220 u32 uhtid
= TC_U32_USERHTID(cls
->hnode
.handle
);
8222 if (uhtid
>= IXGBE_MAX_LINK_HANDLE
)
8225 clear_bit(uhtid
- 1, &adapter
->tables
);
8229 static int ixgbe_configure_clsu32(struct ixgbe_adapter
*adapter
,
8231 struct tc_cls_u32_offload
*cls
)
8233 u32 loc
= cls
->knode
.handle
& 0xfffff;
8234 struct ixgbe_hw
*hw
= &adapter
->hw
;
8235 struct ixgbe_mat_field
*field_ptr
;
8236 struct ixgbe_fdir_filter
*input
;
8237 union ixgbe_atr_input mask
;
8238 #ifdef CONFIG_NET_CLS_ACT
8239 const struct tc_action
*a
;
8243 u32 uhtid
, link_uhtid
;
8245 memset(&mask
, 0, sizeof(union ixgbe_atr_input
));
8246 uhtid
= TC_U32_USERHTID(cls
->knode
.handle
);
8247 link_uhtid
= TC_U32_USERHTID(cls
->knode
.link_handle
);
8249 /* At the moment cls_u32 jumps to network layer and skips past
8250 * L2 headers. The canonical method to match L2 frames is to use
8251 * negative values. However this is error prone at best but really
8252 * just broken because there is no way to "know" what sort of hdr
8253 * is in front of the network layer. Fix cls_u32 to support L2
8254 * headers when needed.
8256 if (protocol
!= htons(ETH_P_IP
))
8260 struct ixgbe_nexthdr
*nexthdr
= ixgbe_ipv4_jumps
;
8262 if (link_uhtid
>= IXGBE_MAX_LINK_HANDLE
)
8265 if (!test_bit(link_uhtid
- 1, &adapter
->tables
))
8268 for (i
= 0; nexthdr
[i
].jump
; i
++) {
8269 if (nexthdr
[i
].o
!= cls
->knode
.sel
->offoff
||
8270 nexthdr
[i
].s
!= cls
->knode
.sel
->offshift
||
8271 nexthdr
[i
].m
!= cls
->knode
.sel
->offmask
||
8272 /* do not support multiple key jumps its just mad */
8273 cls
->knode
.sel
->nkeys
> 1)
8276 if (nexthdr
[i
].off
== cls
->knode
.sel
->keys
[0].off
&&
8277 nexthdr
[i
].val
== cls
->knode
.sel
->keys
[0].val
&&
8278 nexthdr
[i
].mask
== cls
->knode
.sel
->keys
[0].mask
) {
8279 adapter
->jump_tables
[link_uhtid
] =
8287 if (loc
>= ((1024 << adapter
->fdir_pballoc
) - 2)) {
8288 e_err(drv
, "Location out of range\n");
8292 /* cls u32 is a graph starting at root node 0x800. The driver tracks
8293 * links and also the fields used to advance the parser across each
8294 * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
8295 * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
8296 * To add support for new nodes update ixgbe_model.h parse structures
8297 * this function _should_ be generic try not to hardcode values here.
8299 if (uhtid
== 0x800) {
8300 field_ptr
= adapter
->jump_tables
[0];
8302 if (uhtid
>= IXGBE_MAX_LINK_HANDLE
)
8305 field_ptr
= adapter
->jump_tables
[uhtid
];
8311 input
= kzalloc(sizeof(*input
), GFP_KERNEL
);
8315 for (i
= 0; i
< cls
->knode
.sel
->nkeys
; i
++) {
8316 int off
= cls
->knode
.sel
->keys
[i
].off
;
8317 __be32 val
= cls
->knode
.sel
->keys
[i
].val
;
8318 __be32 m
= cls
->knode
.sel
->keys
[i
].mask
;
8319 bool found_entry
= false;
8322 for (j
= 0; field_ptr
[j
].val
; j
++) {
8323 if (field_ptr
[j
].off
== off
) {
8324 field_ptr
[j
].val(input
, &mask
, val
, m
);
8325 input
->filter
.formatted
.flow_type
|=
8336 mask
.formatted
.flow_type
= IXGBE_ATR_L4TYPE_IPV6_MASK
|
8337 IXGBE_ATR_L4TYPE_MASK
;
8339 if (input
->filter
.formatted
.flow_type
== IXGBE_ATR_FLOW_TYPE_IPV4
)
8340 mask
.formatted
.flow_type
&= IXGBE_ATR_L4TYPE_IPV6_MASK
;
8342 #ifdef CONFIG_NET_CLS_ACT
8343 if (list_empty(&cls
->knode
.exts
->actions
))
8346 list_for_each_entry(a
, &cls
->knode
.exts
->actions
, list
) {
8347 if (!is_tcf_gact_shot(a
))
8352 input
->action
= IXGBE_FDIR_DROP_QUEUE
;
8353 queue
= IXGBE_FDIR_DROP_QUEUE
;
8354 input
->sw_idx
= loc
;
8356 spin_lock(&adapter
->fdir_perfect_lock
);
8358 if (hlist_empty(&adapter
->fdir_filter_list
)) {
8359 memcpy(&adapter
->fdir_mask
, &mask
, sizeof(mask
));
8360 err
= ixgbe_fdir_set_input_mask_82599(hw
, &mask
);
8362 goto err_out_w_lock
;
8363 } else if (memcmp(&adapter
->fdir_mask
, &mask
, sizeof(mask
))) {
8365 goto err_out_w_lock
;
8368 ixgbe_atr_compute_perfect_hash_82599(&input
->filter
, &mask
);
8369 err
= ixgbe_fdir_write_perfect_filter_82599(hw
, &input
->filter
,
8370 input
->sw_idx
, queue
);
8372 ixgbe_update_ethtool_fdir_entry(adapter
, input
, input
->sw_idx
);
8373 spin_unlock(&adapter
->fdir_perfect_lock
);
8377 spin_unlock(&adapter
->fdir_perfect_lock
);
8383 static int __ixgbe_setup_tc(struct net_device
*dev
, u32 handle
, __be16 proto
,
8384 struct tc_to_netdev
*tc
)
8386 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
8388 if (TC_H_MAJ(handle
) == TC_H_MAJ(TC_H_INGRESS
) &&
8389 tc
->type
== TC_SETUP_CLSU32
) {
8390 switch (tc
->cls_u32
->command
) {
8391 case TC_CLSU32_NEW_KNODE
:
8392 case TC_CLSU32_REPLACE_KNODE
:
8393 return ixgbe_configure_clsu32(adapter
,
8394 proto
, tc
->cls_u32
);
8395 case TC_CLSU32_DELETE_KNODE
:
8396 return ixgbe_delete_clsu32(adapter
, tc
->cls_u32
);
8397 case TC_CLSU32_NEW_HNODE
:
8398 case TC_CLSU32_REPLACE_HNODE
:
8399 return ixgbe_configure_clsu32_add_hnode(adapter
, proto
,
8401 case TC_CLSU32_DELETE_HNODE
:
8402 return ixgbe_configure_clsu32_del_hnode(adapter
,
8409 if (tc
->type
!= TC_SETUP_MQPRIO
)
8412 return ixgbe_setup_tc(dev
, tc
->tc
);
8415 #ifdef CONFIG_PCI_IOV
8416 void ixgbe_sriov_reinit(struct ixgbe_adapter
*adapter
)
8418 struct net_device
*netdev
= adapter
->netdev
;
8421 ixgbe_setup_tc(netdev
, netdev_get_num_tc(netdev
));
8426 void ixgbe_do_reset(struct net_device
*netdev
)
8428 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
8430 if (netif_running(netdev
))
8431 ixgbe_reinit_locked(adapter
);
8433 ixgbe_reset(adapter
);
8436 static netdev_features_t
ixgbe_fix_features(struct net_device
*netdev
,
8437 netdev_features_t features
)
8439 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
8441 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
8442 if (!(features
& NETIF_F_RXCSUM
))
8443 features
&= ~NETIF_F_LRO
;
8445 /* Turn off LRO if not RSC capable */
8446 if (!(adapter
->flags2
& IXGBE_FLAG2_RSC_CAPABLE
))
8447 features
&= ~NETIF_F_LRO
;
8452 static int ixgbe_set_features(struct net_device
*netdev
,
8453 netdev_features_t features
)
8455 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
8456 netdev_features_t changed
= netdev
->features
^ features
;
8457 bool need_reset
= false;
8459 /* Make sure RSC matches LRO, reset if change */
8460 if (!(features
& NETIF_F_LRO
)) {
8461 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)
8463 adapter
->flags2
&= ~IXGBE_FLAG2_RSC_ENABLED
;
8464 } else if ((adapter
->flags2
& IXGBE_FLAG2_RSC_CAPABLE
) &&
8465 !(adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)) {
8466 if (adapter
->rx_itr_setting
== 1 ||
8467 adapter
->rx_itr_setting
> IXGBE_MIN_RSC_ITR
) {
8468 adapter
->flags2
|= IXGBE_FLAG2_RSC_ENABLED
;
8470 } else if ((changed
^ features
) & NETIF_F_LRO
) {
8471 e_info(probe
, "rx-usecs set too low, "
8477 * Check if Flow Director n-tuple support or hw_tc support was
8478 * enabled or disabled. If the state changed, we need to reset.
8480 if ((features
& NETIF_F_NTUPLE
) || (features
& NETIF_F_HW_TC
)) {
8481 /* turn off ATR, enable perfect filters and reset */
8482 if (!(adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
))
8485 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
8486 adapter
->flags
|= IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
8488 /* turn off perfect filters, enable ATR and reset */
8489 if (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
8492 adapter
->flags
&= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
8494 /* We cannot enable ATR if SR-IOV is enabled */
8495 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
||
8496 /* We cannot enable ATR if we have 2 or more tcs */
8497 (netdev_get_num_tc(netdev
) > 1) ||
8498 /* We cannot enable ATR if RSS is disabled */
8499 (adapter
->ring_feature
[RING_F_RSS
].limit
<= 1) ||
8500 /* A sample rate of 0 indicates ATR disabled */
8501 (!adapter
->atr_sample_rate
))
8502 ; /* do nothing not supported */
8503 else /* otherwise supported and set the flag */
8504 adapter
->flags
|= IXGBE_FLAG_FDIR_HASH_CAPABLE
;
8507 if (changed
& NETIF_F_RXALL
)
8510 netdev
->features
= features
;
8512 #ifdef CONFIG_IXGBE_VXLAN
8513 if ((adapter
->flags
& IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE
)) {
8514 if (features
& NETIF_F_RXCSUM
)
8515 adapter
->flags2
|= IXGBE_FLAG2_VXLAN_REREG_NEEDED
;
8517 ixgbe_clear_vxlan_port(adapter
);
8519 #endif /* CONFIG_IXGBE_VXLAN */
8522 ixgbe_do_reset(netdev
);
8523 else if (changed
& (NETIF_F_HW_VLAN_CTAG_RX
|
8524 NETIF_F_HW_VLAN_CTAG_FILTER
))
8525 ixgbe_set_rx_mode(netdev
);
8530 #ifdef CONFIG_IXGBE_VXLAN
8532 * ixgbe_add_vxlan_port - Get notifications about VXLAN ports that come up
8533 * @dev: The port's netdev
8534 * @sa_family: Socket Family that VXLAN is notifiying us about
8535 * @port: New UDP port number that VXLAN started listening to
8537 static void ixgbe_add_vxlan_port(struct net_device
*dev
, sa_family_t sa_family
,
8540 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
8541 struct ixgbe_hw
*hw
= &adapter
->hw
;
8543 if (!(adapter
->flags
& IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE
))
8546 if (sa_family
== AF_INET6
)
8549 if (adapter
->vxlan_port
== port
)
8552 if (adapter
->vxlan_port
) {
8554 "Hit Max num of VXLAN ports, not adding port %d\n",
8559 adapter
->vxlan_port
= port
;
8560 IXGBE_WRITE_REG(hw
, IXGBE_VXLANCTRL
, ntohs(port
));
8564 * ixgbe_del_vxlan_port - Get notifications about VXLAN ports that go away
8565 * @dev: The port's netdev
8566 * @sa_family: Socket Family that VXLAN is notifying us about
8567 * @port: UDP port number that VXLAN stopped listening to
8569 static void ixgbe_del_vxlan_port(struct net_device
*dev
, sa_family_t sa_family
,
8572 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
8574 if (!(adapter
->flags
& IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE
))
8577 if (sa_family
== AF_INET6
)
8580 if (adapter
->vxlan_port
!= port
) {
8581 netdev_info(dev
, "Port %d was not found, not deleting\n",
8586 ixgbe_clear_vxlan_port(adapter
);
8587 adapter
->flags2
|= IXGBE_FLAG2_VXLAN_REREG_NEEDED
;
8589 #endif /* CONFIG_IXGBE_VXLAN */
8591 static int ixgbe_ndo_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
8592 struct net_device
*dev
,
8593 const unsigned char *addr
, u16 vid
,
8596 /* guarantee we can provide a unique filter for the unicast address */
8597 if (is_unicast_ether_addr(addr
) || is_link_local_ether_addr(addr
)) {
8598 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
8599 u16 pool
= VMDQ_P(0);
8601 if (netdev_uc_count(dev
) >= ixgbe_available_rars(adapter
, pool
))
8605 return ndo_dflt_fdb_add(ndm
, tb
, dev
, addr
, vid
, flags
);
8609 * ixgbe_configure_bridge_mode - set various bridge modes
8610 * @adapter - the private structure
8611 * @mode - requested bridge mode
8613 * Configure some settings require for various bridge modes.
8615 static int ixgbe_configure_bridge_mode(struct ixgbe_adapter
*adapter
,
8618 struct ixgbe_hw
*hw
= &adapter
->hw
;
8619 unsigned int p
, num_pools
;
8623 case BRIDGE_MODE_VEPA
:
8624 /* disable Tx loopback, rely on switch hairpin mode */
8625 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_PFDTXGSWC
, 0);
8627 /* must enable Rx switching replication to allow multicast
8628 * packet reception on all VFs, and to enable source address
8631 vmdctl
= IXGBE_READ_REG(hw
, IXGBE_VMD_CTL
);
8632 vmdctl
|= IXGBE_VT_CTL_REPLEN
;
8633 IXGBE_WRITE_REG(hw
, IXGBE_VMD_CTL
, vmdctl
);
8635 /* enable Rx source address pruning. Note, this requires
8636 * replication to be enabled or else it does nothing.
8638 num_pools
= adapter
->num_vfs
+ adapter
->num_rx_pools
;
8639 for (p
= 0; p
< num_pools
; p
++) {
8640 if (hw
->mac
.ops
.set_source_address_pruning
)
8641 hw
->mac
.ops
.set_source_address_pruning(hw
,
8646 case BRIDGE_MODE_VEB
:
8647 /* enable Tx loopback for internal VF/PF communication */
8648 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_PFDTXGSWC
,
8649 IXGBE_PFDTXGSWC_VT_LBEN
);
8651 /* disable Rx switching replication unless we have SR-IOV
8654 vmdctl
= IXGBE_READ_REG(hw
, IXGBE_VMD_CTL
);
8655 if (!adapter
->num_vfs
)
8656 vmdctl
&= ~IXGBE_VT_CTL_REPLEN
;
8657 IXGBE_WRITE_REG(hw
, IXGBE_VMD_CTL
, vmdctl
);
8659 /* disable Rx source address pruning, since we don't expect to
8660 * be receiving external loopback of our transmitted frames.
8662 num_pools
= adapter
->num_vfs
+ adapter
->num_rx_pools
;
8663 for (p
= 0; p
< num_pools
; p
++) {
8664 if (hw
->mac
.ops
.set_source_address_pruning
)
8665 hw
->mac
.ops
.set_source_address_pruning(hw
,
8674 adapter
->bridge_mode
= mode
;
8676 e_info(drv
, "enabling bridge mode: %s\n",
8677 mode
== BRIDGE_MODE_VEPA
? "VEPA" : "VEB");
8682 static int ixgbe_ndo_bridge_setlink(struct net_device
*dev
,
8683 struct nlmsghdr
*nlh
, u16 flags
)
8685 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
8686 struct nlattr
*attr
, *br_spec
;
8689 if (!(adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
))
8692 br_spec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
8696 nla_for_each_nested(attr
, br_spec
, rem
) {
8700 if (nla_type(attr
) != IFLA_BRIDGE_MODE
)
8703 if (nla_len(attr
) < sizeof(mode
))
8706 mode
= nla_get_u16(attr
);
8707 status
= ixgbe_configure_bridge_mode(adapter
, mode
);
8717 static int ixgbe_ndo_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
8718 struct net_device
*dev
,
8719 u32 filter_mask
, int nlflags
)
8721 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
8723 if (!(adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
))
8726 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
,
8727 adapter
->bridge_mode
, 0, 0, nlflags
,
8731 static void *ixgbe_fwd_add(struct net_device
*pdev
, struct net_device
*vdev
)
8733 struct ixgbe_fwd_adapter
*fwd_adapter
= NULL
;
8734 struct ixgbe_adapter
*adapter
= netdev_priv(pdev
);
8735 int used_pools
= adapter
->num_vfs
+ adapter
->num_rx_pools
;
8739 /* Hardware has a limited number of available pools. Each VF, and the
8740 * PF require a pool. Check to ensure we don't attempt to use more
8741 * then the available number of pools.
8743 if (used_pools
>= IXGBE_MAX_VF_FUNCTIONS
)
8744 return ERR_PTR(-EINVAL
);
8747 if (vdev
->num_rx_queues
!= vdev
->num_tx_queues
) {
8748 netdev_info(pdev
, "%s: Only supports a single queue count for TX and RX\n",
8750 return ERR_PTR(-EINVAL
);
8753 /* Check for hardware restriction on number of rx/tx queues */
8754 if (vdev
->num_tx_queues
> IXGBE_MAX_L2A_QUEUES
||
8755 vdev
->num_tx_queues
== IXGBE_BAD_L2A_QUEUE
) {
8757 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
8759 return ERR_PTR(-EINVAL
);
8762 if (((adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) &&
8763 adapter
->num_rx_pools
> IXGBE_MAX_DCBMACVLANS
- 1) ||
8764 (adapter
->num_rx_pools
> IXGBE_MAX_MACVLANS
))
8765 return ERR_PTR(-EBUSY
);
8767 fwd_adapter
= kzalloc(sizeof(*fwd_adapter
), GFP_KERNEL
);
8769 return ERR_PTR(-ENOMEM
);
8771 pool
= find_first_zero_bit(&adapter
->fwd_bitmask
, 32);
8772 adapter
->num_rx_pools
++;
8773 set_bit(pool
, &adapter
->fwd_bitmask
);
8774 limit
= find_last_bit(&adapter
->fwd_bitmask
, 32);
8776 /* Enable VMDq flag so device will be set in VM mode */
8777 adapter
->flags
|= IXGBE_FLAG_VMDQ_ENABLED
| IXGBE_FLAG_SRIOV_ENABLED
;
8778 adapter
->ring_feature
[RING_F_VMDQ
].limit
= limit
+ 1;
8779 adapter
->ring_feature
[RING_F_RSS
].limit
= vdev
->num_tx_queues
;
8781 /* Force reinit of ring allocation with VMDQ enabled */
8782 err
= ixgbe_setup_tc(pdev
, netdev_get_num_tc(pdev
));
8785 fwd_adapter
->pool
= pool
;
8786 fwd_adapter
->real_adapter
= adapter
;
8787 err
= ixgbe_fwd_ring_up(vdev
, fwd_adapter
);
8790 netif_tx_start_all_queues(vdev
);
8793 /* unwind counter and free adapter struct */
8795 "%s: dfwd hardware acceleration failed\n", vdev
->name
);
8796 clear_bit(pool
, &adapter
->fwd_bitmask
);
8797 adapter
->num_rx_pools
--;
8799 return ERR_PTR(err
);
8802 static void ixgbe_fwd_del(struct net_device
*pdev
, void *priv
)
8804 struct ixgbe_fwd_adapter
*fwd_adapter
= priv
;
8805 struct ixgbe_adapter
*adapter
= fwd_adapter
->real_adapter
;
8808 clear_bit(fwd_adapter
->pool
, &adapter
->fwd_bitmask
);
8809 adapter
->num_rx_pools
--;
8811 limit
= find_last_bit(&adapter
->fwd_bitmask
, 32);
8812 adapter
->ring_feature
[RING_F_VMDQ
].limit
= limit
+ 1;
8813 ixgbe_fwd_ring_down(fwd_adapter
->netdev
, fwd_adapter
);
8814 ixgbe_setup_tc(pdev
, netdev_get_num_tc(pdev
));
8815 netdev_dbg(pdev
, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
8816 fwd_adapter
->pool
, adapter
->num_rx_pools
,
8817 fwd_adapter
->rx_base_queue
,
8818 fwd_adapter
->rx_base_queue
+ adapter
->num_rx_queues_per_pool
,
8819 adapter
->fwd_bitmask
);
8823 #define IXGBE_MAX_TUNNEL_HDR_LEN 80
8824 static netdev_features_t
8825 ixgbe_features_check(struct sk_buff
*skb
, struct net_device
*dev
,
8826 netdev_features_t features
)
8828 if (!skb
->encapsulation
)
8831 if (unlikely(skb_inner_mac_header(skb
) - skb_transport_header(skb
) >
8832 IXGBE_MAX_TUNNEL_HDR_LEN
))
8833 return features
& ~NETIF_F_CSUM_MASK
;
8838 static const struct net_device_ops ixgbe_netdev_ops
= {
8839 .ndo_open
= ixgbe_open
,
8840 .ndo_stop
= ixgbe_close
,
8841 .ndo_start_xmit
= ixgbe_xmit_frame
,
8842 .ndo_select_queue
= ixgbe_select_queue
,
8843 .ndo_set_rx_mode
= ixgbe_set_rx_mode
,
8844 .ndo_validate_addr
= eth_validate_addr
,
8845 .ndo_set_mac_address
= ixgbe_set_mac
,
8846 .ndo_change_mtu
= ixgbe_change_mtu
,
8847 .ndo_tx_timeout
= ixgbe_tx_timeout
,
8848 .ndo_set_tx_maxrate
= ixgbe_tx_maxrate
,
8849 .ndo_vlan_rx_add_vid
= ixgbe_vlan_rx_add_vid
,
8850 .ndo_vlan_rx_kill_vid
= ixgbe_vlan_rx_kill_vid
,
8851 .ndo_do_ioctl
= ixgbe_ioctl
,
8852 .ndo_set_vf_mac
= ixgbe_ndo_set_vf_mac
,
8853 .ndo_set_vf_vlan
= ixgbe_ndo_set_vf_vlan
,
8854 .ndo_set_vf_rate
= ixgbe_ndo_set_vf_bw
,
8855 .ndo_set_vf_spoofchk
= ixgbe_ndo_set_vf_spoofchk
,
8856 .ndo_set_vf_rss_query_en
= ixgbe_ndo_set_vf_rss_query_en
,
8857 .ndo_set_vf_trust
= ixgbe_ndo_set_vf_trust
,
8858 .ndo_get_vf_config
= ixgbe_ndo_get_vf_config
,
8859 .ndo_get_stats64
= ixgbe_get_stats64
,
8860 .ndo_setup_tc
= __ixgbe_setup_tc
,
8861 #ifdef CONFIG_NET_POLL_CONTROLLER
8862 .ndo_poll_controller
= ixgbe_netpoll
,
8864 #ifdef CONFIG_NET_RX_BUSY_POLL
8865 .ndo_busy_poll
= ixgbe_low_latency_recv
,
8868 .ndo_fcoe_ddp_setup
= ixgbe_fcoe_ddp_get
,
8869 .ndo_fcoe_ddp_target
= ixgbe_fcoe_ddp_target
,
8870 .ndo_fcoe_ddp_done
= ixgbe_fcoe_ddp_put
,
8871 .ndo_fcoe_enable
= ixgbe_fcoe_enable
,
8872 .ndo_fcoe_disable
= ixgbe_fcoe_disable
,
8873 .ndo_fcoe_get_wwn
= ixgbe_fcoe_get_wwn
,
8874 .ndo_fcoe_get_hbainfo
= ixgbe_fcoe_get_hbainfo
,
8875 #endif /* IXGBE_FCOE */
8876 .ndo_set_features
= ixgbe_set_features
,
8877 .ndo_fix_features
= ixgbe_fix_features
,
8878 .ndo_fdb_add
= ixgbe_ndo_fdb_add
,
8879 .ndo_bridge_setlink
= ixgbe_ndo_bridge_setlink
,
8880 .ndo_bridge_getlink
= ixgbe_ndo_bridge_getlink
,
8881 .ndo_dfwd_add_station
= ixgbe_fwd_add
,
8882 .ndo_dfwd_del_station
= ixgbe_fwd_del
,
8883 #ifdef CONFIG_IXGBE_VXLAN
8884 .ndo_add_vxlan_port
= ixgbe_add_vxlan_port
,
8885 .ndo_del_vxlan_port
= ixgbe_del_vxlan_port
,
8886 #endif /* CONFIG_IXGBE_VXLAN */
8887 .ndo_features_check
= ixgbe_features_check
,
8891 * ixgbe_enumerate_functions - Get the number of ports this device has
8892 * @adapter: adapter structure
8894 * This function enumerates the phsyical functions co-located on a single slot,
8895 * in order to determine how many ports a device has. This is most useful in
8896 * determining the required GT/s of PCIe bandwidth necessary for optimal
8899 static inline int ixgbe_enumerate_functions(struct ixgbe_adapter
*adapter
)
8901 struct pci_dev
*entry
, *pdev
= adapter
->pdev
;
8904 /* Some cards can not use the generic count PCIe functions method,
8905 * because they are behind a parent switch, so we hardcode these with
8906 * the correct number of functions.
8908 if (ixgbe_pcie_from_parent(&adapter
->hw
))
8911 list_for_each_entry(entry
, &adapter
->pdev
->bus
->devices
, bus_list
) {
8912 /* don't count virtual functions */
8913 if (entry
->is_virtfn
)
8916 /* When the devices on the bus don't all match our device ID,
8917 * we can't reliably determine the correct number of
8918 * functions. This can occur if a function has been direct
8919 * attached to a virtual machine using VT-d, for example. In
8920 * this case, simply return -1 to indicate this.
8922 if ((entry
->vendor
!= pdev
->vendor
) ||
8923 (entry
->device
!= pdev
->device
))
8933 * ixgbe_wol_supported - Check whether device supports WoL
8934 * @hw: hw specific details
8935 * @device_id: the device ID
8936 * @subdev_id: the subsystem device ID
8938 * This function is used by probe and ethtool to determine
8939 * which devices have WoL support
8942 int ixgbe_wol_supported(struct ixgbe_adapter
*adapter
, u16 device_id
,
8945 struct ixgbe_hw
*hw
= &adapter
->hw
;
8946 u16 wol_cap
= adapter
->eeprom_cap
& IXGBE_DEVICE_CAPS_WOL_MASK
;
8947 int is_wol_supported
= 0;
8949 switch (device_id
) {
8950 case IXGBE_DEV_ID_82599_SFP
:
8951 /* Only these subdevices could supports WOL */
8952 switch (subdevice_id
) {
8953 case IXGBE_SUBDEV_ID_82599_SFP_WOL0
:
8954 case IXGBE_SUBDEV_ID_82599_560FLR
:
8955 /* only support first port */
8956 if (hw
->bus
.func
!= 0)
8958 case IXGBE_SUBDEV_ID_82599_SP_560FLR
:
8959 case IXGBE_SUBDEV_ID_82599_SFP
:
8960 case IXGBE_SUBDEV_ID_82599_RNDC
:
8961 case IXGBE_SUBDEV_ID_82599_ECNA_DP
:
8962 case IXGBE_SUBDEV_ID_82599_LOM_SFP
:
8963 is_wol_supported
= 1;
8967 case IXGBE_DEV_ID_82599EN_SFP
:
8968 /* Only this subdevice supports WOL */
8969 switch (subdevice_id
) {
8970 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1
:
8971 is_wol_supported
= 1;
8975 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE
:
8976 /* All except this subdevice support WOL */
8977 if (subdevice_id
!= IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ
)
8978 is_wol_supported
= 1;
8980 case IXGBE_DEV_ID_82599_KX4
:
8981 is_wol_supported
= 1;
8983 case IXGBE_DEV_ID_X540T
:
8984 case IXGBE_DEV_ID_X540T1
:
8985 case IXGBE_DEV_ID_X550T
:
8986 case IXGBE_DEV_ID_X550EM_X_KX4
:
8987 case IXGBE_DEV_ID_X550EM_X_KR
:
8988 case IXGBE_DEV_ID_X550EM_X_10G_T
:
8989 /* check eeprom to see if enabled wol */
8990 if ((wol_cap
== IXGBE_DEVICE_CAPS_WOL_PORT0_1
) ||
8991 ((wol_cap
== IXGBE_DEVICE_CAPS_WOL_PORT0
) &&
8992 (hw
->bus
.func
== 0))) {
8993 is_wol_supported
= 1;
8998 return is_wol_supported
;
9002 * ixgbe_probe - Device Initialization Routine
9003 * @pdev: PCI device information struct
9004 * @ent: entry in ixgbe_pci_tbl
9006 * Returns 0 on success, negative on failure
9008 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
9009 * The OS initialization, configuring of the adapter private structure,
9010 * and a hardware reset occur.
9012 static int ixgbe_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
9014 struct net_device
*netdev
;
9015 struct ixgbe_adapter
*adapter
= NULL
;
9016 struct ixgbe_hw
*hw
;
9017 const struct ixgbe_info
*ii
= ixgbe_info_tbl
[ent
->driver_data
];
9018 int i
, err
, pci_using_dac
, expected_gts
;
9019 unsigned int indices
= MAX_TX_QUEUES
;
9020 u8 part_str
[IXGBE_PBANUM_LENGTH
];
9021 bool disable_dev
= false;
9027 /* Catch broken hardware that put the wrong VF device ID in
9028 * the PCIe SR-IOV capability.
9030 if (pdev
->is_virtfn
) {
9031 WARN(1, KERN_ERR
"%s (%hx:%hx) should not be a VF!\n",
9032 pci_name(pdev
), pdev
->vendor
, pdev
->device
);
9036 err
= pci_enable_device_mem(pdev
);
9040 if (!dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64))) {
9043 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
9046 "No usable DMA configuration, aborting\n");
9052 err
= pci_request_selected_regions(pdev
, pci_select_bars(pdev
,
9053 IORESOURCE_MEM
), ixgbe_driver_name
);
9056 "pci_request_selected_regions failed 0x%x\n", err
);
9060 pci_enable_pcie_error_reporting(pdev
);
9062 pci_set_master(pdev
);
9063 pci_save_state(pdev
);
9065 if (ii
->mac
== ixgbe_mac_82598EB
) {
9066 #ifdef CONFIG_IXGBE_DCB
9067 /* 8 TC w/ 4 queues per TC */
9068 indices
= 4 * MAX_TRAFFIC_CLASS
;
9070 indices
= IXGBE_MAX_RSS_INDICES
;
9074 netdev
= alloc_etherdev_mq(sizeof(struct ixgbe_adapter
), indices
);
9077 goto err_alloc_etherdev
;
9080 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
9082 adapter
= netdev_priv(netdev
);
9084 adapter
->netdev
= netdev
;
9085 adapter
->pdev
= pdev
;
9088 adapter
->msg_enable
= netif_msg_init(debug
, DEFAULT_MSG_ENABLE
);
9090 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
9091 pci_resource_len(pdev
, 0));
9092 adapter
->io_addr
= hw
->hw_addr
;
9098 netdev
->netdev_ops
= &ixgbe_netdev_ops
;
9099 ixgbe_set_ethtool_ops(netdev
);
9100 netdev
->watchdog_timeo
= 5 * HZ
;
9101 strlcpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
));
9104 hw
->mac
.ops
= *ii
->mac_ops
;
9105 hw
->mac
.type
= ii
->mac
;
9106 hw
->mvals
= ii
->mvals
;
9109 hw
->eeprom
.ops
= *ii
->eeprom_ops
;
9110 eec
= IXGBE_READ_REG(hw
, IXGBE_EEC(hw
));
9111 if (ixgbe_removed(hw
->hw_addr
)) {
9115 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
9116 if (!(eec
& (1 << 8)))
9117 hw
->eeprom
.ops
.read
= &ixgbe_read_eeprom_bit_bang_generic
;
9120 hw
->phy
.ops
= *ii
->phy_ops
;
9121 hw
->phy
.sfp_type
= ixgbe_sfp_type_unknown
;
9122 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
9123 hw
->phy
.mdio
.prtad
= MDIO_PRTAD_NONE
;
9124 hw
->phy
.mdio
.mmds
= 0;
9125 hw
->phy
.mdio
.mode_support
= MDIO_SUPPORTS_C45
| MDIO_EMULATE_C22
;
9126 hw
->phy
.mdio
.dev
= netdev
;
9127 hw
->phy
.mdio
.mdio_read
= ixgbe_mdio_read
;
9128 hw
->phy
.mdio
.mdio_write
= ixgbe_mdio_write
;
9130 ii
->get_invariants(hw
);
9132 /* setup the private structure */
9133 err
= ixgbe_sw_init(adapter
);
9137 /* Make sure the SWFW semaphore is in a valid state */
9138 if (hw
->mac
.ops
.init_swfw_sync
)
9139 hw
->mac
.ops
.init_swfw_sync(hw
);
9141 /* Make it possible the adapter to be woken up via WOL */
9142 switch (adapter
->hw
.mac
.type
) {
9143 case ixgbe_mac_82599EB
:
9144 case ixgbe_mac_X540
:
9145 case ixgbe_mac_X550
:
9146 case ixgbe_mac_X550EM_x
:
9147 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
9154 * If there is a fan on this device and it has failed log the
9157 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
9158 u32 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
9159 if (esdp
& IXGBE_ESDP_SDP1
)
9160 e_crit(probe
, "Fan has stopped, replace the adapter\n");
9163 if (allow_unsupported_sfp
)
9164 hw
->allow_unsupported_sfp
= allow_unsupported_sfp
;
9166 /* reset_hw fills in the perm_addr as well */
9167 hw
->phy
.reset_if_overtemp
= true;
9168 err
= hw
->mac
.ops
.reset_hw(hw
);
9169 hw
->phy
.reset_if_overtemp
= false;
9170 if (err
== IXGBE_ERR_SFP_NOT_PRESENT
) {
9172 } else if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) {
9173 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
9174 e_dev_err("Reload the driver after installing a supported module.\n");
9177 e_dev_err("HW Init failed: %d\n", err
);
9181 #ifdef CONFIG_PCI_IOV
9182 /* SR-IOV not supported on the 82598 */
9183 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
9186 ixgbe_init_mbx_params_pf(hw
);
9187 hw
->mbx
.ops
= ii
->mbx_ops
;
9188 pci_sriov_set_totalvfs(pdev
, IXGBE_MAX_VFS_DRV_LIMIT
);
9189 ixgbe_enable_sriov(adapter
);
9193 netdev
->features
= NETIF_F_SG
|
9199 NETIF_F_HW_VLAN_CTAG_TX
|
9200 NETIF_F_HW_VLAN_CTAG_RX
|
9201 NETIF_F_HW_VLAN_CTAG_FILTER
;
9203 if (hw
->mac
.type
>= ixgbe_mac_82599EB
)
9204 netdev
->features
|= NETIF_F_SCTP_CRC
;
9206 /* copy netdev features into list of user selectable features */
9207 netdev
->hw_features
|= netdev
->features
;
9208 netdev
->hw_features
|= NETIF_F_RXALL
|
9209 NETIF_F_HW_L2FW_DOFFLOAD
;
9211 if (hw
->mac
.type
>= ixgbe_mac_82599EB
)
9212 netdev
->hw_features
|= NETIF_F_NTUPLE
|
9215 netdev
->vlan_features
|= NETIF_F_SG
|
9221 netdev
->mpls_features
|= NETIF_F_HW_CSUM
;
9222 netdev
->hw_enc_features
|= NETIF_F_HW_CSUM
;
9224 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
9225 netdev
->priv_flags
|= IFF_SUPP_NOFCS
;
9227 #ifdef CONFIG_IXGBE_DCB
9228 netdev
->dcbnl_ops
= &dcbnl_ops
;
9232 if (adapter
->flags
& IXGBE_FLAG_FCOE_CAPABLE
) {
9233 unsigned int fcoe_l
;
9235 if (hw
->mac
.ops
.get_device_caps
) {
9236 hw
->mac
.ops
.get_device_caps(hw
, &device_caps
);
9237 if (device_caps
& IXGBE_DEVICE_CAPS_FCOE_OFFLOADS
)
9238 adapter
->flags
&= ~IXGBE_FLAG_FCOE_CAPABLE
;
9242 fcoe_l
= min_t(int, IXGBE_FCRETA_SIZE
, num_online_cpus());
9243 adapter
->ring_feature
[RING_F_FCOE
].limit
= fcoe_l
;
9245 netdev
->features
|= NETIF_F_FSO
|
9248 netdev
->vlan_features
|= NETIF_F_FSO
|
9252 #endif /* IXGBE_FCOE */
9253 if (pci_using_dac
) {
9254 netdev
->features
|= NETIF_F_HIGHDMA
;
9255 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
9258 if (adapter
->flags2
& IXGBE_FLAG2_RSC_CAPABLE
)
9259 netdev
->hw_features
|= NETIF_F_LRO
;
9260 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)
9261 netdev
->features
|= NETIF_F_LRO
;
9263 /* make sure the EEPROM is good */
9264 if (hw
->eeprom
.ops
.validate_checksum(hw
, NULL
) < 0) {
9265 e_dev_err("The EEPROM Checksum Is Not Valid\n");
9270 eth_platform_get_mac_address(&adapter
->pdev
->dev
,
9271 adapter
->hw
.mac
.perm_addr
);
9273 memcpy(netdev
->dev_addr
, hw
->mac
.perm_addr
, netdev
->addr_len
);
9275 if (!is_valid_ether_addr(netdev
->dev_addr
)) {
9276 e_dev_err("invalid MAC address\n");
9281 /* Set hw->mac.addr to permanent MAC address */
9282 ether_addr_copy(hw
->mac
.addr
, hw
->mac
.perm_addr
);
9283 ixgbe_mac_set_default_filter(adapter
);
9285 setup_timer(&adapter
->service_timer
, &ixgbe_service_timer
,
9286 (unsigned long) adapter
);
9288 if (ixgbe_removed(hw
->hw_addr
)) {
9292 INIT_WORK(&adapter
->service_task
, ixgbe_service_task
);
9293 set_bit(__IXGBE_SERVICE_INITED
, &adapter
->state
);
9294 clear_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
);
9296 err
= ixgbe_init_interrupt_scheme(adapter
);
9300 /* WOL not supported for all devices */
9302 hw
->eeprom
.ops
.read(hw
, 0x2c, &adapter
->eeprom_cap
);
9303 hw
->wol_enabled
= ixgbe_wol_supported(adapter
, pdev
->device
,
9304 pdev
->subsystem_device
);
9305 if (hw
->wol_enabled
)
9306 adapter
->wol
= IXGBE_WUFC_MAG
;
9308 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
9310 /* save off EEPROM version number */
9311 hw
->eeprom
.ops
.read(hw
, 0x2e, &adapter
->eeprom_verh
);
9312 hw
->eeprom
.ops
.read(hw
, 0x2d, &adapter
->eeprom_verl
);
9314 /* pick up the PCI bus settings for reporting later */
9315 if (ixgbe_pcie_from_parent(hw
))
9316 ixgbe_get_parent_bus_info(adapter
);
9318 hw
->mac
.ops
.get_bus_info(hw
);
9320 /* calculate the expected PCIe bandwidth required for optimal
9321 * performance. Note that some older parts will never have enough
9322 * bandwidth due to being older generation PCIe parts. We clamp these
9323 * parts to ensure no warning is displayed if it can't be fixed.
9325 switch (hw
->mac
.type
) {
9326 case ixgbe_mac_82598EB
:
9327 expected_gts
= min(ixgbe_enumerate_functions(adapter
) * 10, 16);
9330 expected_gts
= ixgbe_enumerate_functions(adapter
) * 10;
9334 /* don't check link if we failed to enumerate functions */
9335 if (expected_gts
> 0)
9336 ixgbe_check_minimum_link(adapter
, expected_gts
);
9338 err
= ixgbe_read_pba_string_generic(hw
, part_str
, sizeof(part_str
));
9340 strlcpy(part_str
, "Unknown", sizeof(part_str
));
9341 if (ixgbe_is_sfp(hw
) && hw
->phy
.sfp_type
!= ixgbe_sfp_type_not_present
)
9342 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
9343 hw
->mac
.type
, hw
->phy
.type
, hw
->phy
.sfp_type
,
9346 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
9347 hw
->mac
.type
, hw
->phy
.type
, part_str
);
9349 e_dev_info("%pM\n", netdev
->dev_addr
);
9351 /* reset the hardware with the new settings */
9352 err
= hw
->mac
.ops
.start_hw(hw
);
9353 if (err
== IXGBE_ERR_EEPROM_VERSION
) {
9354 /* We are running on a pre-production device, log a warning */
9355 e_dev_warn("This device is a pre-production adapter/LOM. "
9356 "Please be aware there may be issues associated "
9357 "with your hardware. If you are experiencing "
9358 "problems please contact your Intel or hardware "
9359 "representative who provided you with this "
9362 strcpy(netdev
->name
, "eth%d");
9363 err
= register_netdev(netdev
);
9367 pci_set_drvdata(pdev
, adapter
);
9369 /* power down the optics for 82599 SFP+ fiber */
9370 if (hw
->mac
.ops
.disable_tx_laser
)
9371 hw
->mac
.ops
.disable_tx_laser(hw
);
9373 /* carrier off reporting is important to ethtool even BEFORE open */
9374 netif_carrier_off(netdev
);
9376 #ifdef CONFIG_IXGBE_DCA
9377 if (dca_add_requester(&pdev
->dev
) == 0) {
9378 adapter
->flags
|= IXGBE_FLAG_DCA_ENABLED
;
9379 ixgbe_setup_dca(adapter
);
9382 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
9383 e_info(probe
, "IOV is enabled with %d VFs\n", adapter
->num_vfs
);
9384 for (i
= 0; i
< adapter
->num_vfs
; i
++)
9385 ixgbe_vf_configuration(pdev
, (i
| 0x10000000));
9388 /* firmware requires driver version to be 0xFFFFFFFF
9389 * since os does not support feature
9391 if (hw
->mac
.ops
.set_fw_drv_ver
)
9392 hw
->mac
.ops
.set_fw_drv_ver(hw
, 0xFF, 0xFF, 0xFF,
9395 /* add san mac addr to netdev */
9396 ixgbe_add_sanmac_netdev(netdev
);
9398 e_dev_info("%s\n", ixgbe_default_device_descr
);
9400 #ifdef CONFIG_IXGBE_HWMON
9401 if (ixgbe_sysfs_init(adapter
))
9402 e_err(probe
, "failed to allocate sysfs resources\n");
9403 #endif /* CONFIG_IXGBE_HWMON */
9405 ixgbe_dbg_adapter_init(adapter
);
9407 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
9408 if (ixgbe_mng_enabled(hw
) && ixgbe_is_sfp(hw
) && hw
->mac
.ops
.setup_link
)
9409 hw
->mac
.ops
.setup_link(hw
,
9410 IXGBE_LINK_SPEED_10GB_FULL
| IXGBE_LINK_SPEED_1GB_FULL
,
9416 ixgbe_release_hw_control(adapter
);
9417 ixgbe_clear_interrupt_scheme(adapter
);
9419 ixgbe_disable_sriov(adapter
);
9420 adapter
->flags2
&= ~IXGBE_FLAG2_SEARCH_FOR_SFP
;
9421 iounmap(adapter
->io_addr
);
9422 kfree(adapter
->mac_table
);
9424 disable_dev
= !test_and_set_bit(__IXGBE_DISABLED
, &adapter
->state
);
9425 free_netdev(netdev
);
9427 pci_release_selected_regions(pdev
,
9428 pci_select_bars(pdev
, IORESOURCE_MEM
));
9431 if (!adapter
|| disable_dev
)
9432 pci_disable_device(pdev
);
9437 * ixgbe_remove - Device Removal Routine
9438 * @pdev: PCI device information struct
9440 * ixgbe_remove is called by the PCI subsystem to alert the driver
9441 * that it should release a PCI device. The could be caused by a
9442 * Hot-Plug event, or because the driver is going to be removed from
9445 static void ixgbe_remove(struct pci_dev
*pdev
)
9447 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
9448 struct net_device
*netdev
;
9451 /* if !adapter then we already cleaned up in probe */
9455 netdev
= adapter
->netdev
;
9456 ixgbe_dbg_adapter_exit(adapter
);
9458 set_bit(__IXGBE_REMOVING
, &adapter
->state
);
9459 cancel_work_sync(&adapter
->service_task
);
9462 #ifdef CONFIG_IXGBE_DCA
9463 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
9464 adapter
->flags
&= ~IXGBE_FLAG_DCA_ENABLED
;
9465 dca_remove_requester(&pdev
->dev
);
9466 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
,
9467 IXGBE_DCA_CTRL_DCA_DISABLE
);
9471 #ifdef CONFIG_IXGBE_HWMON
9472 ixgbe_sysfs_exit(adapter
);
9473 #endif /* CONFIG_IXGBE_HWMON */
9475 /* remove the added san mac */
9476 ixgbe_del_sanmac_netdev(netdev
);
9478 #ifdef CONFIG_PCI_IOV
9479 ixgbe_disable_sriov(adapter
);
9481 if (netdev
->reg_state
== NETREG_REGISTERED
)
9482 unregister_netdev(netdev
);
9484 ixgbe_clear_interrupt_scheme(adapter
);
9486 ixgbe_release_hw_control(adapter
);
9489 kfree(adapter
->ixgbe_ieee_pfc
);
9490 kfree(adapter
->ixgbe_ieee_ets
);
9493 iounmap(adapter
->io_addr
);
9494 pci_release_selected_regions(pdev
, pci_select_bars(pdev
,
9497 e_dev_info("complete\n");
9499 kfree(adapter
->mac_table
);
9500 disable_dev
= !test_and_set_bit(__IXGBE_DISABLED
, &adapter
->state
);
9501 free_netdev(netdev
);
9503 pci_disable_pcie_error_reporting(pdev
);
9506 pci_disable_device(pdev
);
9510 * ixgbe_io_error_detected - called when PCI error is detected
9511 * @pdev: Pointer to PCI device
9512 * @state: The current pci connection state
9514 * This function is called after a PCI bus error affecting
9515 * this device has been detected.
9517 static pci_ers_result_t
ixgbe_io_error_detected(struct pci_dev
*pdev
,
9518 pci_channel_state_t state
)
9520 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
9521 struct net_device
*netdev
= adapter
->netdev
;
9523 #ifdef CONFIG_PCI_IOV
9524 struct ixgbe_hw
*hw
= &adapter
->hw
;
9525 struct pci_dev
*bdev
, *vfdev
;
9526 u32 dw0
, dw1
, dw2
, dw3
;
9528 u16 req_id
, pf_func
;
9530 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
||
9531 adapter
->num_vfs
== 0)
9532 goto skip_bad_vf_detection
;
9534 bdev
= pdev
->bus
->self
;
9535 while (bdev
&& (pci_pcie_type(bdev
) != PCI_EXP_TYPE_ROOT_PORT
))
9536 bdev
= bdev
->bus
->self
;
9539 goto skip_bad_vf_detection
;
9541 pos
= pci_find_ext_capability(bdev
, PCI_EXT_CAP_ID_ERR
);
9543 goto skip_bad_vf_detection
;
9545 dw0
= ixgbe_read_pci_cfg_dword(hw
, pos
+ PCI_ERR_HEADER_LOG
);
9546 dw1
= ixgbe_read_pci_cfg_dword(hw
, pos
+ PCI_ERR_HEADER_LOG
+ 4);
9547 dw2
= ixgbe_read_pci_cfg_dword(hw
, pos
+ PCI_ERR_HEADER_LOG
+ 8);
9548 dw3
= ixgbe_read_pci_cfg_dword(hw
, pos
+ PCI_ERR_HEADER_LOG
+ 12);
9549 if (ixgbe_removed(hw
->hw_addr
))
9550 goto skip_bad_vf_detection
;
9553 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
9554 if (!(req_id
& 0x0080))
9555 goto skip_bad_vf_detection
;
9557 pf_func
= req_id
& 0x01;
9558 if ((pf_func
& 1) == (pdev
->devfn
& 1)) {
9559 unsigned int device_id
;
9561 vf
= (req_id
& 0x7F) >> 1;
9562 e_dev_err("VF %d has caused a PCIe error\n", vf
);
9563 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
9564 "%8.8x\tdw3: %8.8x\n",
9565 dw0
, dw1
, dw2
, dw3
);
9566 switch (adapter
->hw
.mac
.type
) {
9567 case ixgbe_mac_82599EB
:
9568 device_id
= IXGBE_82599_VF_DEVICE_ID
;
9570 case ixgbe_mac_X540
:
9571 device_id
= IXGBE_X540_VF_DEVICE_ID
;
9573 case ixgbe_mac_X550
:
9574 device_id
= IXGBE_DEV_ID_X550_VF
;
9576 case ixgbe_mac_X550EM_x
:
9577 device_id
= IXGBE_DEV_ID_X550EM_X_VF
;
9584 /* Find the pci device of the offending VF */
9585 vfdev
= pci_get_device(PCI_VENDOR_ID_INTEL
, device_id
, NULL
);
9587 if (vfdev
->devfn
== (req_id
& 0xFF))
9589 vfdev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
9593 * There's a slim chance the VF could have been hot plugged,
9594 * so if it is no longer present we don't need to issue the
9595 * VFLR. Just clean up the AER in that case.
9598 ixgbe_issue_vf_flr(adapter
, vfdev
);
9599 /* Free device reference count */
9603 pci_cleanup_aer_uncorrect_error_status(pdev
);
9607 * Even though the error may have occurred on the other port
9608 * we still need to increment the vf error reference count for
9609 * both ports because the I/O resume function will be called
9612 adapter
->vferr_refcount
++;
9614 return PCI_ERS_RESULT_RECOVERED
;
9616 skip_bad_vf_detection
:
9617 #endif /* CONFIG_PCI_IOV */
9618 if (!test_bit(__IXGBE_SERVICE_INITED
, &adapter
->state
))
9619 return PCI_ERS_RESULT_DISCONNECT
;
9622 netif_device_detach(netdev
);
9624 if (state
== pci_channel_io_perm_failure
) {
9626 return PCI_ERS_RESULT_DISCONNECT
;
9629 if (netif_running(netdev
))
9630 ixgbe_down(adapter
);
9632 if (!test_and_set_bit(__IXGBE_DISABLED
, &adapter
->state
))
9633 pci_disable_device(pdev
);
9636 /* Request a slot reset. */
9637 return PCI_ERS_RESULT_NEED_RESET
;
9641 * ixgbe_io_slot_reset - called after the pci bus has been reset.
9642 * @pdev: Pointer to PCI device
9644 * Restart the card from scratch, as if from a cold-boot.
9646 static pci_ers_result_t
ixgbe_io_slot_reset(struct pci_dev
*pdev
)
9648 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
9649 pci_ers_result_t result
;
9652 if (pci_enable_device_mem(pdev
)) {
9653 e_err(probe
, "Cannot re-enable PCI device after reset.\n");
9654 result
= PCI_ERS_RESULT_DISCONNECT
;
9656 smp_mb__before_atomic();
9657 clear_bit(__IXGBE_DISABLED
, &adapter
->state
);
9658 adapter
->hw
.hw_addr
= adapter
->io_addr
;
9659 pci_set_master(pdev
);
9660 pci_restore_state(pdev
);
9661 pci_save_state(pdev
);
9663 pci_wake_from_d3(pdev
, false);
9665 ixgbe_reset(adapter
);
9666 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
9667 result
= PCI_ERS_RESULT_RECOVERED
;
9670 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
9672 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
9673 "failed 0x%0x\n", err
);
9674 /* non-fatal, continue */
9681 * ixgbe_io_resume - called when traffic can start flowing again.
9682 * @pdev: Pointer to PCI device
9684 * This callback is called when the error recovery driver tells us that
9685 * its OK to resume normal operation.
9687 static void ixgbe_io_resume(struct pci_dev
*pdev
)
9689 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
9690 struct net_device
*netdev
= adapter
->netdev
;
9692 #ifdef CONFIG_PCI_IOV
9693 if (adapter
->vferr_refcount
) {
9694 e_info(drv
, "Resuming after VF err\n");
9695 adapter
->vferr_refcount
--;
9700 if (netif_running(netdev
))
9703 netif_device_attach(netdev
);
9706 static const struct pci_error_handlers ixgbe_err_handler
= {
9707 .error_detected
= ixgbe_io_error_detected
,
9708 .slot_reset
= ixgbe_io_slot_reset
,
9709 .resume
= ixgbe_io_resume
,
9712 static struct pci_driver ixgbe_driver
= {
9713 .name
= ixgbe_driver_name
,
9714 .id_table
= ixgbe_pci_tbl
,
9715 .probe
= ixgbe_probe
,
9716 .remove
= ixgbe_remove
,
9718 .suspend
= ixgbe_suspend
,
9719 .resume
= ixgbe_resume
,
9721 .shutdown
= ixgbe_shutdown
,
9722 .sriov_configure
= ixgbe_pci_sriov_configure
,
9723 .err_handler
= &ixgbe_err_handler
9727 * ixgbe_init_module - Driver Registration Routine
9729 * ixgbe_init_module is the first routine called when the driver is
9730 * loaded. All it does is register with the PCI subsystem.
9732 static int __init
ixgbe_init_module(void)
9735 pr_info("%s - version %s\n", ixgbe_driver_string
, ixgbe_driver_version
);
9736 pr_info("%s\n", ixgbe_copyright
);
9738 ixgbe_wq
= create_singlethread_workqueue(ixgbe_driver_name
);
9740 pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name
);
9746 ret
= pci_register_driver(&ixgbe_driver
);
9752 #ifdef CONFIG_IXGBE_DCA
9753 dca_register_notify(&dca_notifier
);
9759 module_init(ixgbe_init_module
);
9762 * ixgbe_exit_module - Driver Exit Cleanup Routine
9764 * ixgbe_exit_module is called just before the driver is removed
9767 static void __exit
ixgbe_exit_module(void)
9769 #ifdef CONFIG_IXGBE_DCA
9770 dca_unregister_notify(&dca_notifier
);
9772 pci_unregister_driver(&ixgbe_driver
);
9776 destroy_workqueue(ixgbe_wq
);
9781 #ifdef CONFIG_IXGBE_DCA
9782 static int ixgbe_notify_dca(struct notifier_block
*nb
, unsigned long event
,
9787 ret_val
= driver_for_each_device(&ixgbe_driver
.driver
, NULL
, &event
,
9788 __ixgbe_notify_dca
);
9790 return ret_val
? NOTIFY_BAD
: NOTIFY_DONE
;
9793 #endif /* CONFIG_IXGBE_DCA */
9795 module_exit(ixgbe_exit_module
);