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
1115 static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector
*q_vector
,
1116 struct ixgbe_ring
*tx_ring
, int napi_budget
)
1118 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1119 struct ixgbe_tx_buffer
*tx_buffer
;
1120 union ixgbe_adv_tx_desc
*tx_desc
;
1121 unsigned int total_bytes
= 0, total_packets
= 0;
1122 unsigned int budget
= q_vector
->tx
.work_limit
;
1123 unsigned int i
= tx_ring
->next_to_clean
;
1125 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
1128 tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
1129 tx_desc
= IXGBE_TX_DESC(tx_ring
, i
);
1130 i
-= tx_ring
->count
;
1133 union ixgbe_adv_tx_desc
*eop_desc
= tx_buffer
->next_to_watch
;
1135 /* if next_to_watch is not set then there is no work pending */
1139 /* prevent any other reads prior to eop_desc */
1140 read_barrier_depends();
1142 /* if DD is not set pending work has not been completed */
1143 if (!(eop_desc
->wb
.status
& cpu_to_le32(IXGBE_TXD_STAT_DD
)))
1146 /* clear next_to_watch to prevent false hangs */
1147 tx_buffer
->next_to_watch
= NULL
;
1149 /* update the statistics for this packet */
1150 total_bytes
+= tx_buffer
->bytecount
;
1151 total_packets
+= tx_buffer
->gso_segs
;
1154 napi_consume_skb(tx_buffer
->skb
, napi_budget
);
1156 /* unmap skb header data */
1157 dma_unmap_single(tx_ring
->dev
,
1158 dma_unmap_addr(tx_buffer
, dma
),
1159 dma_unmap_len(tx_buffer
, len
),
1162 /* clear tx_buffer data */
1163 tx_buffer
->skb
= NULL
;
1164 dma_unmap_len_set(tx_buffer
, len
, 0);
1166 /* unmap remaining buffers */
1167 while (tx_desc
!= eop_desc
) {
1172 i
-= tx_ring
->count
;
1173 tx_buffer
= tx_ring
->tx_buffer_info
;
1174 tx_desc
= IXGBE_TX_DESC(tx_ring
, 0);
1177 /* unmap any remaining paged data */
1178 if (dma_unmap_len(tx_buffer
, len
)) {
1179 dma_unmap_page(tx_ring
->dev
,
1180 dma_unmap_addr(tx_buffer
, dma
),
1181 dma_unmap_len(tx_buffer
, len
),
1183 dma_unmap_len_set(tx_buffer
, len
, 0);
1187 /* move us one more past the eop_desc for start of next pkt */
1192 i
-= tx_ring
->count
;
1193 tx_buffer
= tx_ring
->tx_buffer_info
;
1194 tx_desc
= IXGBE_TX_DESC(tx_ring
, 0);
1197 /* issue prefetch for next Tx descriptor */
1200 /* update budget accounting */
1202 } while (likely(budget
));
1204 i
+= tx_ring
->count
;
1205 tx_ring
->next_to_clean
= i
;
1206 u64_stats_update_begin(&tx_ring
->syncp
);
1207 tx_ring
->stats
.bytes
+= total_bytes
;
1208 tx_ring
->stats
.packets
+= total_packets
;
1209 u64_stats_update_end(&tx_ring
->syncp
);
1210 q_vector
->tx
.total_bytes
+= total_bytes
;
1211 q_vector
->tx
.total_packets
+= total_packets
;
1213 if (check_for_tx_hang(tx_ring
) && ixgbe_check_tx_hang(tx_ring
)) {
1214 /* schedule immediate reset if we believe we hung */
1215 struct ixgbe_hw
*hw
= &adapter
->hw
;
1216 e_err(drv
, "Detected Tx Unit Hang\n"
1218 " TDH, TDT <%x>, <%x>\n"
1219 " next_to_use <%x>\n"
1220 " next_to_clean <%x>\n"
1221 "tx_buffer_info[next_to_clean]\n"
1222 " time_stamp <%lx>\n"
1224 tx_ring
->queue_index
,
1225 IXGBE_READ_REG(hw
, IXGBE_TDH(tx_ring
->reg_idx
)),
1226 IXGBE_READ_REG(hw
, IXGBE_TDT(tx_ring
->reg_idx
)),
1227 tx_ring
->next_to_use
, i
,
1228 tx_ring
->tx_buffer_info
[i
].time_stamp
, jiffies
);
1230 netif_stop_subqueue(tx_ring
->netdev
, tx_ring
->queue_index
);
1233 "tx hang %d detected on queue %d, resetting adapter\n",
1234 adapter
->tx_timeout_count
+ 1, tx_ring
->queue_index
);
1236 /* schedule immediate reset if we believe we hung */
1237 ixgbe_tx_timeout_reset(adapter
);
1239 /* the adapter is about to reset, no point in enabling stuff */
1243 netdev_tx_completed_queue(txring_txq(tx_ring
),
1244 total_packets
, total_bytes
);
1246 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
1247 if (unlikely(total_packets
&& netif_carrier_ok(tx_ring
->netdev
) &&
1248 (ixgbe_desc_unused(tx_ring
) >= TX_WAKE_THRESHOLD
))) {
1249 /* Make sure that anybody stopping the queue after this
1250 * sees the new next_to_clean.
1253 if (__netif_subqueue_stopped(tx_ring
->netdev
,
1254 tx_ring
->queue_index
)
1255 && !test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
1256 netif_wake_subqueue(tx_ring
->netdev
,
1257 tx_ring
->queue_index
);
1258 ++tx_ring
->tx_stats
.restart_queue
;
1265 #ifdef CONFIG_IXGBE_DCA
1266 static void ixgbe_update_tx_dca(struct ixgbe_adapter
*adapter
,
1267 struct ixgbe_ring
*tx_ring
,
1270 struct ixgbe_hw
*hw
= &adapter
->hw
;
1274 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1275 txctrl
= dca3_get_tag(tx_ring
->dev
, cpu
);
1277 switch (hw
->mac
.type
) {
1278 case ixgbe_mac_82598EB
:
1279 reg_offset
= IXGBE_DCA_TXCTRL(tx_ring
->reg_idx
);
1281 case ixgbe_mac_82599EB
:
1282 case ixgbe_mac_X540
:
1283 reg_offset
= IXGBE_DCA_TXCTRL_82599(tx_ring
->reg_idx
);
1284 txctrl
<<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599
;
1287 /* for unknown hardware do not write register */
1292 * We can enable relaxed ordering for reads, but not writes when
1293 * DCA is enabled. This is due to a known issue in some chipsets
1294 * which will cause the DCA tag to be cleared.
1296 txctrl
|= IXGBE_DCA_TXCTRL_DESC_RRO_EN
|
1297 IXGBE_DCA_TXCTRL_DATA_RRO_EN
|
1298 IXGBE_DCA_TXCTRL_DESC_DCA_EN
;
1300 IXGBE_WRITE_REG(hw
, reg_offset
, txctrl
);
1303 static void ixgbe_update_rx_dca(struct ixgbe_adapter
*adapter
,
1304 struct ixgbe_ring
*rx_ring
,
1307 struct ixgbe_hw
*hw
= &adapter
->hw
;
1309 u8 reg_idx
= rx_ring
->reg_idx
;
1311 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1312 rxctrl
= dca3_get_tag(rx_ring
->dev
, cpu
);
1314 switch (hw
->mac
.type
) {
1315 case ixgbe_mac_82599EB
:
1316 case ixgbe_mac_X540
:
1317 rxctrl
<<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599
;
1324 * We can enable relaxed ordering for reads, but not writes when
1325 * DCA is enabled. This is due to a known issue in some chipsets
1326 * which will cause the DCA tag to be cleared.
1328 rxctrl
|= IXGBE_DCA_RXCTRL_DESC_RRO_EN
|
1329 IXGBE_DCA_RXCTRL_DATA_DCA_EN
|
1330 IXGBE_DCA_RXCTRL_DESC_DCA_EN
;
1332 IXGBE_WRITE_REG(hw
, IXGBE_DCA_RXCTRL(reg_idx
), rxctrl
);
1335 static void ixgbe_update_dca(struct ixgbe_q_vector
*q_vector
)
1337 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
1338 struct ixgbe_ring
*ring
;
1339 int cpu
= get_cpu();
1341 if (q_vector
->cpu
== cpu
)
1344 ixgbe_for_each_ring(ring
, q_vector
->tx
)
1345 ixgbe_update_tx_dca(adapter
, ring
, cpu
);
1347 ixgbe_for_each_ring(ring
, q_vector
->rx
)
1348 ixgbe_update_rx_dca(adapter
, ring
, cpu
);
1350 q_vector
->cpu
= cpu
;
1355 static void ixgbe_setup_dca(struct ixgbe_adapter
*adapter
)
1359 /* always use CB2 mode, difference is masked in the CB driver */
1360 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1361 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
,
1362 IXGBE_DCA_CTRL_DCA_MODE_CB2
);
1364 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
,
1365 IXGBE_DCA_CTRL_DCA_DISABLE
);
1367 for (i
= 0; i
< adapter
->num_q_vectors
; i
++) {
1368 adapter
->q_vector
[i
]->cpu
= -1;
1369 ixgbe_update_dca(adapter
->q_vector
[i
]);
1373 static int __ixgbe_notify_dca(struct device
*dev
, void *data
)
1375 struct ixgbe_adapter
*adapter
= dev_get_drvdata(dev
);
1376 unsigned long event
= *(unsigned long *)data
;
1378 if (!(adapter
->flags
& IXGBE_FLAG_DCA_CAPABLE
))
1382 case DCA_PROVIDER_ADD
:
1383 /* if we're already enabled, don't do it again */
1384 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
1386 if (dca_add_requester(dev
) == 0) {
1387 adapter
->flags
|= IXGBE_FLAG_DCA_ENABLED
;
1388 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
,
1389 IXGBE_DCA_CTRL_DCA_MODE_CB2
);
1392 /* Fall Through since DCA is disabled. */
1393 case DCA_PROVIDER_REMOVE
:
1394 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
1395 dca_remove_requester(dev
);
1396 adapter
->flags
&= ~IXGBE_FLAG_DCA_ENABLED
;
1397 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
,
1398 IXGBE_DCA_CTRL_DCA_DISABLE
);
1406 #endif /* CONFIG_IXGBE_DCA */
1408 #define IXGBE_RSS_L4_TYPES_MASK \
1409 ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
1410 (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
1411 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
1412 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
1414 static inline void ixgbe_rx_hash(struct ixgbe_ring
*ring
,
1415 union ixgbe_adv_rx_desc
*rx_desc
,
1416 struct sk_buff
*skb
)
1420 if (!(ring
->netdev
->features
& NETIF_F_RXHASH
))
1423 rss_type
= le16_to_cpu(rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
) &
1424 IXGBE_RXDADV_RSSTYPE_MASK
;
1429 skb_set_hash(skb
, le32_to_cpu(rx_desc
->wb
.lower
.hi_dword
.rss
),
1430 (IXGBE_RSS_L4_TYPES_MASK
& (1ul << rss_type
)) ?
1431 PKT_HASH_TYPE_L4
: PKT_HASH_TYPE_L3
);
1436 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1437 * @ring: structure containing ring specific data
1438 * @rx_desc: advanced rx descriptor
1440 * Returns : true if it is FCoE pkt
1442 static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring
*ring
,
1443 union ixgbe_adv_rx_desc
*rx_desc
)
1445 __le16 pkt_info
= rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
1447 return test_bit(__IXGBE_RX_FCOE
, &ring
->state
) &&
1448 ((pkt_info
& cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK
)) ==
1449 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE
<<
1450 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT
)));
1453 #endif /* IXGBE_FCOE */
1455 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1456 * @ring: structure containing ring specific data
1457 * @rx_desc: current Rx descriptor being processed
1458 * @skb: skb currently being received and modified
1460 static inline void ixgbe_rx_checksum(struct ixgbe_ring
*ring
,
1461 union ixgbe_adv_rx_desc
*rx_desc
,
1462 struct sk_buff
*skb
)
1464 __le16 pkt_info
= rx_desc
->wb
.lower
.lo_dword
.hs_rss
.pkt_info
;
1465 __le16 hdr_info
= rx_desc
->wb
.lower
.lo_dword
.hs_rss
.hdr_info
;
1466 bool encap_pkt
= false;
1468 skb_checksum_none_assert(skb
);
1470 /* Rx csum disabled */
1471 if (!(ring
->netdev
->features
& NETIF_F_RXCSUM
))
1474 if ((pkt_info
& cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN
)) &&
1475 (hdr_info
& cpu_to_le16(IXGBE_RXDADV_PKTTYPE_TUNNEL
>> 16))) {
1477 skb
->encapsulation
= 1;
1480 /* if IP and error */
1481 if (ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_IPCS
) &&
1482 ixgbe_test_staterr(rx_desc
, IXGBE_RXDADV_ERR_IPE
)) {
1483 ring
->rx_stats
.csum_err
++;
1487 if (!ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_L4CS
))
1490 if (ixgbe_test_staterr(rx_desc
, IXGBE_RXDADV_ERR_TCPE
)) {
1492 * 82599 errata, UDP frames with a 0 checksum can be marked as
1495 if ((pkt_info
& cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP
)) &&
1496 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR
, &ring
->state
))
1499 ring
->rx_stats
.csum_err
++;
1503 /* It must be a TCP or UDP packet with a valid checksum */
1504 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1506 if (!ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_OUTERIPCS
))
1509 if (ixgbe_test_staterr(rx_desc
, IXGBE_RXDADV_ERR_OUTERIPER
)) {
1510 skb
->ip_summed
= CHECKSUM_NONE
;
1513 /* If we checked the outer header let the stack know */
1514 skb
->csum_level
= 1;
1518 static bool ixgbe_alloc_mapped_page(struct ixgbe_ring
*rx_ring
,
1519 struct ixgbe_rx_buffer
*bi
)
1521 struct page
*page
= bi
->page
;
1524 /* since we are recycling buffers we should seldom need to alloc */
1528 /* alloc new page for storage */
1529 page
= dev_alloc_pages(ixgbe_rx_pg_order(rx_ring
));
1530 if (unlikely(!page
)) {
1531 rx_ring
->rx_stats
.alloc_rx_page_failed
++;
1535 /* map page for use */
1536 dma
= dma_map_page(rx_ring
->dev
, page
, 0,
1537 ixgbe_rx_pg_size(rx_ring
), DMA_FROM_DEVICE
);
1540 * if mapping failed free memory back to system since
1541 * there isn't much point in holding memory we can't use
1543 if (dma_mapping_error(rx_ring
->dev
, dma
)) {
1544 __free_pages(page
, ixgbe_rx_pg_order(rx_ring
));
1546 rx_ring
->rx_stats
.alloc_rx_page_failed
++;
1552 bi
->page_offset
= 0;
1558 * ixgbe_alloc_rx_buffers - Replace used receive buffers
1559 * @rx_ring: ring to place buffers on
1560 * @cleaned_count: number of buffers to replace
1562 void ixgbe_alloc_rx_buffers(struct ixgbe_ring
*rx_ring
, u16 cleaned_count
)
1564 union ixgbe_adv_rx_desc
*rx_desc
;
1565 struct ixgbe_rx_buffer
*bi
;
1566 u16 i
= rx_ring
->next_to_use
;
1572 rx_desc
= IXGBE_RX_DESC(rx_ring
, i
);
1573 bi
= &rx_ring
->rx_buffer_info
[i
];
1574 i
-= rx_ring
->count
;
1577 if (!ixgbe_alloc_mapped_page(rx_ring
, bi
))
1581 * Refresh the desc even if buffer_addrs didn't change
1582 * because each write-back erases this info.
1584 rx_desc
->read
.pkt_addr
= cpu_to_le64(bi
->dma
+ bi
->page_offset
);
1590 rx_desc
= IXGBE_RX_DESC(rx_ring
, 0);
1591 bi
= rx_ring
->rx_buffer_info
;
1592 i
-= rx_ring
->count
;
1595 /* clear the status bits for the next_to_use descriptor */
1596 rx_desc
->wb
.upper
.status_error
= 0;
1599 } while (cleaned_count
);
1601 i
+= rx_ring
->count
;
1603 if (rx_ring
->next_to_use
!= i
) {
1604 rx_ring
->next_to_use
= i
;
1606 /* update next to alloc since we have filled the ring */
1607 rx_ring
->next_to_alloc
= i
;
1609 /* Force memory writes to complete before letting h/w
1610 * know there are new descriptors to fetch. (Only
1611 * applicable for weak-ordered memory model archs,
1615 writel(i
, rx_ring
->tail
);
1619 static void ixgbe_set_rsc_gso_size(struct ixgbe_ring
*ring
,
1620 struct sk_buff
*skb
)
1622 u16 hdr_len
= skb_headlen(skb
);
1624 /* set gso_size to avoid messing up TCP MSS */
1625 skb_shinfo(skb
)->gso_size
= DIV_ROUND_UP((skb
->len
- hdr_len
),
1626 IXGBE_CB(skb
)->append_cnt
);
1627 skb_shinfo(skb
)->gso_type
= SKB_GSO_TCPV4
;
1630 static void ixgbe_update_rsc_stats(struct ixgbe_ring
*rx_ring
,
1631 struct sk_buff
*skb
)
1633 /* if append_cnt is 0 then frame is not RSC */
1634 if (!IXGBE_CB(skb
)->append_cnt
)
1637 rx_ring
->rx_stats
.rsc_count
+= IXGBE_CB(skb
)->append_cnt
;
1638 rx_ring
->rx_stats
.rsc_flush
++;
1640 ixgbe_set_rsc_gso_size(rx_ring
, skb
);
1642 /* gso_size is computed using append_cnt so always clear it last */
1643 IXGBE_CB(skb
)->append_cnt
= 0;
1647 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1648 * @rx_ring: rx descriptor ring packet is being transacted on
1649 * @rx_desc: pointer to the EOP Rx descriptor
1650 * @skb: pointer to current skb being populated
1652 * This function checks the ring, descriptor, and packet information in
1653 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1654 * other fields within the skb.
1656 static void ixgbe_process_skb_fields(struct ixgbe_ring
*rx_ring
,
1657 union ixgbe_adv_rx_desc
*rx_desc
,
1658 struct sk_buff
*skb
)
1660 struct net_device
*dev
= rx_ring
->netdev
;
1661 u32 flags
= rx_ring
->q_vector
->adapter
->flags
;
1663 ixgbe_update_rsc_stats(rx_ring
, skb
);
1665 ixgbe_rx_hash(rx_ring
, rx_desc
, skb
);
1667 ixgbe_rx_checksum(rx_ring
, rx_desc
, skb
);
1669 if (unlikely(flags
& IXGBE_FLAG_RX_HWTSTAMP_ENABLED
))
1670 ixgbe_ptp_rx_hwtstamp(rx_ring
, rx_desc
, skb
);
1672 if ((dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
) &&
1673 ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_VP
)) {
1674 u16 vid
= le16_to_cpu(rx_desc
->wb
.upper
.vlan
);
1675 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), vid
);
1678 skb_record_rx_queue(skb
, rx_ring
->queue_index
);
1680 skb
->protocol
= eth_type_trans(skb
, dev
);
1683 static void ixgbe_rx_skb(struct ixgbe_q_vector
*q_vector
,
1684 struct sk_buff
*skb
)
1686 skb_mark_napi_id(skb
, &q_vector
->napi
);
1687 if (ixgbe_qv_busy_polling(q_vector
))
1688 netif_receive_skb(skb
);
1690 napi_gro_receive(&q_vector
->napi
, skb
);
1694 * ixgbe_is_non_eop - process handling of non-EOP buffers
1695 * @rx_ring: Rx ring being processed
1696 * @rx_desc: Rx descriptor for current buffer
1697 * @skb: Current socket buffer containing buffer in progress
1699 * This function updates next to clean. If the buffer is an EOP buffer
1700 * this function exits returning false, otherwise it will place the
1701 * sk_buff in the next buffer to be chained and return true indicating
1702 * that this is in fact a non-EOP buffer.
1704 static bool ixgbe_is_non_eop(struct ixgbe_ring
*rx_ring
,
1705 union ixgbe_adv_rx_desc
*rx_desc
,
1706 struct sk_buff
*skb
)
1708 u32 ntc
= rx_ring
->next_to_clean
+ 1;
1710 /* fetch, update, and store next to clean */
1711 ntc
= (ntc
< rx_ring
->count
) ? ntc
: 0;
1712 rx_ring
->next_to_clean
= ntc
;
1714 prefetch(IXGBE_RX_DESC(rx_ring
, ntc
));
1716 /* update RSC append count if present */
1717 if (ring_is_rsc_enabled(rx_ring
)) {
1718 __le32 rsc_enabled
= rx_desc
->wb
.lower
.lo_dword
.data
&
1719 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK
);
1721 if (unlikely(rsc_enabled
)) {
1722 u32 rsc_cnt
= le32_to_cpu(rsc_enabled
);
1724 rsc_cnt
>>= IXGBE_RXDADV_RSCCNT_SHIFT
;
1725 IXGBE_CB(skb
)->append_cnt
+= rsc_cnt
- 1;
1727 /* update ntc based on RSC value */
1728 ntc
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
1729 ntc
&= IXGBE_RXDADV_NEXTP_MASK
;
1730 ntc
>>= IXGBE_RXDADV_NEXTP_SHIFT
;
1734 /* if we are the last buffer then there is nothing else to do */
1735 if (likely(ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_EOP
)))
1738 /* place skb in next buffer to be received */
1739 rx_ring
->rx_buffer_info
[ntc
].skb
= skb
;
1740 rx_ring
->rx_stats
.non_eop_descs
++;
1746 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1747 * @rx_ring: rx descriptor ring packet is being transacted on
1748 * @skb: pointer to current skb being adjusted
1750 * This function is an ixgbe specific version of __pskb_pull_tail. The
1751 * main difference between this version and the original function is that
1752 * this function can make several assumptions about the state of things
1753 * that allow for significant optimizations versus the standard function.
1754 * As a result we can do things like drop a frag and maintain an accurate
1755 * truesize for the skb.
1757 static void ixgbe_pull_tail(struct ixgbe_ring
*rx_ring
,
1758 struct sk_buff
*skb
)
1760 struct skb_frag_struct
*frag
= &skb_shinfo(skb
)->frags
[0];
1762 unsigned int pull_len
;
1765 * it is valid to use page_address instead of kmap since we are
1766 * working with pages allocated out of the lomem pool per
1767 * alloc_page(GFP_ATOMIC)
1769 va
= skb_frag_address(frag
);
1772 * we need the header to contain the greater of either ETH_HLEN or
1773 * 60 bytes if the skb->len is less than 60 for skb_pad.
1775 pull_len
= eth_get_headlen(va
, IXGBE_RX_HDR_SIZE
);
1777 /* align pull length to size of long to optimize memcpy performance */
1778 skb_copy_to_linear_data(skb
, va
, ALIGN(pull_len
, sizeof(long)));
1780 /* update all of the pointers */
1781 skb_frag_size_sub(frag
, pull_len
);
1782 frag
->page_offset
+= pull_len
;
1783 skb
->data_len
-= pull_len
;
1784 skb
->tail
+= pull_len
;
1788 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1789 * @rx_ring: rx descriptor ring packet is being transacted on
1790 * @skb: pointer to current skb being updated
1792 * This function provides a basic DMA sync up for the first fragment of an
1793 * skb. The reason for doing this is that the first fragment cannot be
1794 * unmapped until we have reached the end of packet descriptor for a buffer
1797 static void ixgbe_dma_sync_frag(struct ixgbe_ring
*rx_ring
,
1798 struct sk_buff
*skb
)
1800 /* if the page was released unmap it, else just sync our portion */
1801 if (unlikely(IXGBE_CB(skb
)->page_released
)) {
1802 dma_unmap_page(rx_ring
->dev
, IXGBE_CB(skb
)->dma
,
1803 ixgbe_rx_pg_size(rx_ring
), DMA_FROM_DEVICE
);
1804 IXGBE_CB(skb
)->page_released
= false;
1806 struct skb_frag_struct
*frag
= &skb_shinfo(skb
)->frags
[0];
1808 dma_sync_single_range_for_cpu(rx_ring
->dev
,
1811 ixgbe_rx_bufsz(rx_ring
),
1814 IXGBE_CB(skb
)->dma
= 0;
1818 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1819 * @rx_ring: rx descriptor ring packet is being transacted on
1820 * @rx_desc: pointer to the EOP Rx descriptor
1821 * @skb: pointer to current skb being fixed
1823 * Check for corrupted packet headers caused by senders on the local L2
1824 * embedded NIC switch not setting up their Tx Descriptors right. These
1825 * should be very rare.
1827 * Also address the case where we are pulling data in on pages only
1828 * and as such no data is present in the skb header.
1830 * In addition if skb is not at least 60 bytes we need to pad it so that
1831 * it is large enough to qualify as a valid Ethernet frame.
1833 * Returns true if an error was encountered and skb was freed.
1835 static bool ixgbe_cleanup_headers(struct ixgbe_ring
*rx_ring
,
1836 union ixgbe_adv_rx_desc
*rx_desc
,
1837 struct sk_buff
*skb
)
1839 struct net_device
*netdev
= rx_ring
->netdev
;
1841 /* verify that the packet does not have any known errors */
1842 if (unlikely(ixgbe_test_staterr(rx_desc
,
1843 IXGBE_RXDADV_ERR_FRAME_ERR_MASK
) &&
1844 !(netdev
->features
& NETIF_F_RXALL
))) {
1845 dev_kfree_skb_any(skb
);
1849 /* place header in linear portion of buffer */
1850 if (skb_is_nonlinear(skb
))
1851 ixgbe_pull_tail(rx_ring
, skb
);
1854 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1855 if (ixgbe_rx_is_fcoe(rx_ring
, rx_desc
))
1859 /* if eth_skb_pad returns an error the skb was freed */
1860 if (eth_skb_pad(skb
))
1867 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1868 * @rx_ring: rx descriptor ring to store buffers on
1869 * @old_buff: donor buffer to have page reused
1871 * Synchronizes page for reuse by the adapter
1873 static void ixgbe_reuse_rx_page(struct ixgbe_ring
*rx_ring
,
1874 struct ixgbe_rx_buffer
*old_buff
)
1876 struct ixgbe_rx_buffer
*new_buff
;
1877 u16 nta
= rx_ring
->next_to_alloc
;
1879 new_buff
= &rx_ring
->rx_buffer_info
[nta
];
1881 /* update, and store next to alloc */
1883 rx_ring
->next_to_alloc
= (nta
< rx_ring
->count
) ? nta
: 0;
1885 /* transfer page from old buffer to new buffer */
1886 *new_buff
= *old_buff
;
1888 /* sync the buffer for use by the device */
1889 dma_sync_single_range_for_device(rx_ring
->dev
, new_buff
->dma
,
1890 new_buff
->page_offset
,
1891 ixgbe_rx_bufsz(rx_ring
),
1895 static inline bool ixgbe_page_is_reserved(struct page
*page
)
1897 return (page_to_nid(page
) != numa_mem_id()) || page_is_pfmemalloc(page
);
1901 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1902 * @rx_ring: rx descriptor ring to transact packets on
1903 * @rx_buffer: buffer containing page to add
1904 * @rx_desc: descriptor containing length of buffer written by hardware
1905 * @skb: sk_buff to place the data into
1907 * This function will add the data contained in rx_buffer->page to the skb.
1908 * This is done either through a direct copy if the data in the buffer is
1909 * less than the skb header size, otherwise it will just attach the page as
1910 * a frag to the skb.
1912 * The function will then update the page offset if necessary and return
1913 * true if the buffer can be reused by the adapter.
1915 static bool ixgbe_add_rx_frag(struct ixgbe_ring
*rx_ring
,
1916 struct ixgbe_rx_buffer
*rx_buffer
,
1917 union ixgbe_adv_rx_desc
*rx_desc
,
1918 struct sk_buff
*skb
)
1920 struct page
*page
= rx_buffer
->page
;
1921 unsigned int size
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
1922 #if (PAGE_SIZE < 8192)
1923 unsigned int truesize
= ixgbe_rx_bufsz(rx_ring
);
1925 unsigned int truesize
= ALIGN(size
, L1_CACHE_BYTES
);
1926 unsigned int last_offset
= ixgbe_rx_pg_size(rx_ring
) -
1927 ixgbe_rx_bufsz(rx_ring
);
1930 if ((size
<= IXGBE_RX_HDR_SIZE
) && !skb_is_nonlinear(skb
)) {
1931 unsigned char *va
= page_address(page
) + rx_buffer
->page_offset
;
1933 memcpy(__skb_put(skb
, size
), va
, ALIGN(size
, sizeof(long)));
1935 /* page is not reserved, we can reuse buffer as-is */
1936 if (likely(!ixgbe_page_is_reserved(page
)))
1939 /* this page cannot be reused so discard it */
1940 __free_pages(page
, ixgbe_rx_pg_order(rx_ring
));
1944 skb_add_rx_frag(skb
, skb_shinfo(skb
)->nr_frags
, page
,
1945 rx_buffer
->page_offset
, size
, truesize
);
1947 /* avoid re-using remote pages */
1948 if (unlikely(ixgbe_page_is_reserved(page
)))
1951 #if (PAGE_SIZE < 8192)
1952 /* if we are only owner of page we can reuse it */
1953 if (unlikely(page_count(page
) != 1))
1956 /* flip page offset to other buffer */
1957 rx_buffer
->page_offset
^= truesize
;
1959 /* move offset up to the next cache line */
1960 rx_buffer
->page_offset
+= truesize
;
1962 if (rx_buffer
->page_offset
> last_offset
)
1966 /* Even if we own the page, we are not allowed to use atomic_set()
1967 * This would break get_page_unless_zero() users.
1974 static struct sk_buff
*ixgbe_fetch_rx_buffer(struct ixgbe_ring
*rx_ring
,
1975 union ixgbe_adv_rx_desc
*rx_desc
)
1977 struct ixgbe_rx_buffer
*rx_buffer
;
1978 struct sk_buff
*skb
;
1981 rx_buffer
= &rx_ring
->rx_buffer_info
[rx_ring
->next_to_clean
];
1982 page
= rx_buffer
->page
;
1985 skb
= rx_buffer
->skb
;
1988 void *page_addr
= page_address(page
) +
1989 rx_buffer
->page_offset
;
1991 /* prefetch first cache line of first page */
1992 prefetch(page_addr
);
1993 #if L1_CACHE_BYTES < 128
1994 prefetch(page_addr
+ L1_CACHE_BYTES
);
1997 /* allocate a skb to store the frags */
1998 skb
= napi_alloc_skb(&rx_ring
->q_vector
->napi
,
2000 if (unlikely(!skb
)) {
2001 rx_ring
->rx_stats
.alloc_rx_buff_failed
++;
2006 * we will be copying header into skb->data in
2007 * pskb_may_pull so it is in our interest to prefetch
2008 * it now to avoid a possible cache miss
2010 prefetchw(skb
->data
);
2013 * Delay unmapping of the first packet. It carries the
2014 * header information, HW may still access the header
2015 * after the writeback. Only unmap it when EOP is
2018 if (likely(ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_EOP
)))
2021 IXGBE_CB(skb
)->dma
= rx_buffer
->dma
;
2023 if (ixgbe_test_staterr(rx_desc
, IXGBE_RXD_STAT_EOP
))
2024 ixgbe_dma_sync_frag(rx_ring
, skb
);
2027 /* we are reusing so sync this buffer for CPU use */
2028 dma_sync_single_range_for_cpu(rx_ring
->dev
,
2030 rx_buffer
->page_offset
,
2031 ixgbe_rx_bufsz(rx_ring
),
2034 rx_buffer
->skb
= NULL
;
2037 /* pull page into skb */
2038 if (ixgbe_add_rx_frag(rx_ring
, rx_buffer
, rx_desc
, skb
)) {
2039 /* hand second half of page back to the ring */
2040 ixgbe_reuse_rx_page(rx_ring
, rx_buffer
);
2041 } else if (IXGBE_CB(skb
)->dma
== rx_buffer
->dma
) {
2042 /* the page has been released from the ring */
2043 IXGBE_CB(skb
)->page_released
= true;
2045 /* we are not reusing the buffer so unmap it */
2046 dma_unmap_page(rx_ring
->dev
, rx_buffer
->dma
,
2047 ixgbe_rx_pg_size(rx_ring
),
2051 /* clear contents of buffer_info */
2052 rx_buffer
->page
= NULL
;
2058 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2059 * @q_vector: structure containing interrupt and ring information
2060 * @rx_ring: rx descriptor ring to transact packets on
2061 * @budget: Total limit on number of packets to process
2063 * This function provides a "bounce buffer" approach to Rx interrupt
2064 * processing. The advantage to this is that on systems that have
2065 * expensive overhead for IOMMU access this provides a means of avoiding
2066 * it by maintaining the mapping of the page to the syste.
2068 * Returns amount of work completed
2070 static int ixgbe_clean_rx_irq(struct ixgbe_q_vector
*q_vector
,
2071 struct ixgbe_ring
*rx_ring
,
2074 unsigned int total_rx_bytes
= 0, total_rx_packets
= 0;
2076 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
2078 unsigned int mss
= 0;
2079 #endif /* IXGBE_FCOE */
2080 u16 cleaned_count
= ixgbe_desc_unused(rx_ring
);
2082 while (likely(total_rx_packets
< budget
)) {
2083 union ixgbe_adv_rx_desc
*rx_desc
;
2084 struct sk_buff
*skb
;
2086 /* return some buffers to hardware, one at a time is too slow */
2087 if (cleaned_count
>= IXGBE_RX_BUFFER_WRITE
) {
2088 ixgbe_alloc_rx_buffers(rx_ring
, cleaned_count
);
2092 rx_desc
= IXGBE_RX_DESC(rx_ring
, rx_ring
->next_to_clean
);
2094 if (!rx_desc
->wb
.upper
.status_error
)
2097 /* This memory barrier is needed to keep us from reading
2098 * any other fields out of the rx_desc until we know the
2099 * descriptor has been written back
2103 /* retrieve a buffer from the ring */
2104 skb
= ixgbe_fetch_rx_buffer(rx_ring
, rx_desc
);
2106 /* exit if we failed to retrieve a buffer */
2112 /* place incomplete frames back on ring for completion */
2113 if (ixgbe_is_non_eop(rx_ring
, rx_desc
, skb
))
2116 /* verify the packet layout is correct */
2117 if (ixgbe_cleanup_headers(rx_ring
, rx_desc
, skb
))
2120 /* probably a little skewed due to removing CRC */
2121 total_rx_bytes
+= skb
->len
;
2123 /* populate checksum, timestamp, VLAN, and protocol */
2124 ixgbe_process_skb_fields(rx_ring
, rx_desc
, skb
);
2127 /* if ddp, not passing to ULD unless for FCP_RSP or error */
2128 if (ixgbe_rx_is_fcoe(rx_ring
, rx_desc
)) {
2129 ddp_bytes
= ixgbe_fcoe_ddp(adapter
, rx_desc
, skb
);
2130 /* include DDPed FCoE data */
2131 if (ddp_bytes
> 0) {
2133 mss
= rx_ring
->netdev
->mtu
-
2134 sizeof(struct fcoe_hdr
) -
2135 sizeof(struct fc_frame_header
) -
2136 sizeof(struct fcoe_crc_eof
);
2140 total_rx_bytes
+= ddp_bytes
;
2141 total_rx_packets
+= DIV_ROUND_UP(ddp_bytes
,
2145 dev_kfree_skb_any(skb
);
2150 #endif /* IXGBE_FCOE */
2151 ixgbe_rx_skb(q_vector
, skb
);
2153 /* update budget accounting */
2157 u64_stats_update_begin(&rx_ring
->syncp
);
2158 rx_ring
->stats
.packets
+= total_rx_packets
;
2159 rx_ring
->stats
.bytes
+= total_rx_bytes
;
2160 u64_stats_update_end(&rx_ring
->syncp
);
2161 q_vector
->rx
.total_packets
+= total_rx_packets
;
2162 q_vector
->rx
.total_bytes
+= total_rx_bytes
;
2164 return total_rx_packets
;
2167 #ifdef CONFIG_NET_RX_BUSY_POLL
2168 /* must be called with local_bh_disable()d */
2169 static int ixgbe_low_latency_recv(struct napi_struct
*napi
)
2171 struct ixgbe_q_vector
*q_vector
=
2172 container_of(napi
, struct ixgbe_q_vector
, napi
);
2173 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
2174 struct ixgbe_ring
*ring
;
2177 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
2178 return LL_FLUSH_FAILED
;
2180 if (!ixgbe_qv_lock_poll(q_vector
))
2181 return LL_FLUSH_BUSY
;
2183 ixgbe_for_each_ring(ring
, q_vector
->rx
) {
2184 found
= ixgbe_clean_rx_irq(q_vector
, ring
, 4);
2185 #ifdef BP_EXTENDED_STATS
2187 ring
->stats
.cleaned
+= found
;
2189 ring
->stats
.misses
++;
2195 ixgbe_qv_unlock_poll(q_vector
);
2199 #endif /* CONFIG_NET_RX_BUSY_POLL */
2202 * ixgbe_configure_msix - Configure MSI-X hardware
2203 * @adapter: board private structure
2205 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2208 static void ixgbe_configure_msix(struct ixgbe_adapter
*adapter
)
2210 struct ixgbe_q_vector
*q_vector
;
2214 /* Populate MSIX to EITR Select */
2215 if (adapter
->num_vfs
> 32) {
2216 u32 eitrsel
= (1 << (adapter
->num_vfs
- 32)) - 1;
2217 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITRSEL
, eitrsel
);
2221 * Populate the IVAR table and set the ITR values to the
2222 * corresponding register.
2224 for (v_idx
= 0; v_idx
< adapter
->num_q_vectors
; v_idx
++) {
2225 struct ixgbe_ring
*ring
;
2226 q_vector
= adapter
->q_vector
[v_idx
];
2228 ixgbe_for_each_ring(ring
, q_vector
->rx
)
2229 ixgbe_set_ivar(adapter
, 0, ring
->reg_idx
, v_idx
);
2231 ixgbe_for_each_ring(ring
, q_vector
->tx
)
2232 ixgbe_set_ivar(adapter
, 1, ring
->reg_idx
, v_idx
);
2234 ixgbe_write_eitr(q_vector
);
2237 switch (adapter
->hw
.mac
.type
) {
2238 case ixgbe_mac_82598EB
:
2239 ixgbe_set_ivar(adapter
, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX
,
2242 case ixgbe_mac_82599EB
:
2243 case ixgbe_mac_X540
:
2244 case ixgbe_mac_X550
:
2245 case ixgbe_mac_X550EM_x
:
2246 ixgbe_set_ivar(adapter
, -1, 1, v_idx
);
2251 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITR(v_idx
), 1950);
2253 /* set up to autoclear timer, and the vectors */
2254 mask
= IXGBE_EIMS_ENABLE_MASK
;
2255 mask
&= ~(IXGBE_EIMS_OTHER
|
2256 IXGBE_EIMS_MAILBOX
|
2259 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIAC
, mask
);
2262 enum latency_range
{
2266 latency_invalid
= 255
2270 * ixgbe_update_itr - update the dynamic ITR value based on statistics
2271 * @q_vector: structure containing interrupt and ring information
2272 * @ring_container: structure containing ring performance data
2274 * Stores a new ITR value based on packets and byte
2275 * counts during the last interrupt. The advantage of per interrupt
2276 * computation is faster updates and more accurate ITR for the current
2277 * traffic pattern. Constants in this function were computed
2278 * based on theoretical maximum wire speed and thresholds were set based
2279 * on testing data as well as attempting to minimize response time
2280 * while increasing bulk throughput.
2281 * this functionality is controlled by the InterruptThrottleRate module
2282 * parameter (see ixgbe_param.c)
2284 static void ixgbe_update_itr(struct ixgbe_q_vector
*q_vector
,
2285 struct ixgbe_ring_container
*ring_container
)
2287 int bytes
= ring_container
->total_bytes
;
2288 int packets
= ring_container
->total_packets
;
2291 u8 itr_setting
= ring_container
->itr
;
2296 /* simple throttlerate management
2297 * 0-10MB/s lowest (100000 ints/s)
2298 * 10-20MB/s low (20000 ints/s)
2299 * 20-1249MB/s bulk (12000 ints/s)
2301 /* what was last interrupt timeslice? */
2302 timepassed_us
= q_vector
->itr
>> 2;
2303 if (timepassed_us
== 0)
2306 bytes_perint
= bytes
/ timepassed_us
; /* bytes/usec */
2308 switch (itr_setting
) {
2309 case lowest_latency
:
2310 if (bytes_perint
> 10)
2311 itr_setting
= low_latency
;
2314 if (bytes_perint
> 20)
2315 itr_setting
= bulk_latency
;
2316 else if (bytes_perint
<= 10)
2317 itr_setting
= lowest_latency
;
2320 if (bytes_perint
<= 20)
2321 itr_setting
= low_latency
;
2325 /* clear work counters since we have the values we need */
2326 ring_container
->total_bytes
= 0;
2327 ring_container
->total_packets
= 0;
2329 /* write updated itr to ring container */
2330 ring_container
->itr
= itr_setting
;
2334 * ixgbe_write_eitr - write EITR register in hardware specific way
2335 * @q_vector: structure containing interrupt and ring information
2337 * This function is made to be called by ethtool and by the driver
2338 * when it needs to update EITR registers at runtime. Hardware
2339 * specific quirks/differences are taken care of here.
2341 void ixgbe_write_eitr(struct ixgbe_q_vector
*q_vector
)
2343 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
2344 struct ixgbe_hw
*hw
= &adapter
->hw
;
2345 int v_idx
= q_vector
->v_idx
;
2346 u32 itr_reg
= q_vector
->itr
& IXGBE_MAX_EITR
;
2348 switch (adapter
->hw
.mac
.type
) {
2349 case ixgbe_mac_82598EB
:
2350 /* must write high and low 16 bits to reset counter */
2351 itr_reg
|= (itr_reg
<< 16);
2353 case ixgbe_mac_82599EB
:
2354 case ixgbe_mac_X540
:
2355 case ixgbe_mac_X550
:
2356 case ixgbe_mac_X550EM_x
:
2358 * set the WDIS bit to not clear the timer bits and cause an
2359 * immediate assertion of the interrupt
2361 itr_reg
|= IXGBE_EITR_CNT_WDIS
;
2366 IXGBE_WRITE_REG(hw
, IXGBE_EITR(v_idx
), itr_reg
);
2369 static void ixgbe_set_itr(struct ixgbe_q_vector
*q_vector
)
2371 u32 new_itr
= q_vector
->itr
;
2374 ixgbe_update_itr(q_vector
, &q_vector
->tx
);
2375 ixgbe_update_itr(q_vector
, &q_vector
->rx
);
2377 current_itr
= max(q_vector
->rx
.itr
, q_vector
->tx
.itr
);
2379 switch (current_itr
) {
2380 /* counts and packets in update_itr are dependent on these numbers */
2381 case lowest_latency
:
2382 new_itr
= IXGBE_100K_ITR
;
2385 new_itr
= IXGBE_20K_ITR
;
2388 new_itr
= IXGBE_12K_ITR
;
2394 if (new_itr
!= q_vector
->itr
) {
2395 /* do an exponential smoothing */
2396 new_itr
= (10 * new_itr
* q_vector
->itr
) /
2397 ((9 * new_itr
) + q_vector
->itr
);
2399 /* save the algorithm value here */
2400 q_vector
->itr
= new_itr
;
2402 ixgbe_write_eitr(q_vector
);
2407 * ixgbe_check_overtemp_subtask - check for over temperature
2408 * @adapter: pointer to adapter
2410 static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter
*adapter
)
2412 struct ixgbe_hw
*hw
= &adapter
->hw
;
2413 u32 eicr
= adapter
->interrupt_event
;
2415 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
2418 if (!(adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
) &&
2419 !(adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_EVENT
))
2422 adapter
->flags2
&= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT
;
2424 switch (hw
->device_id
) {
2425 case IXGBE_DEV_ID_82599_T3_LOM
:
2427 * Since the warning interrupt is for both ports
2428 * we don't have to check if:
2429 * - This interrupt wasn't for our port.
2430 * - We may have missed the interrupt so always have to
2431 * check if we got a LSC
2433 if (!(eicr
& IXGBE_EICR_GPI_SDP0_8259X
) &&
2434 !(eicr
& IXGBE_EICR_LSC
))
2437 if (!(eicr
& IXGBE_EICR_LSC
) && hw
->mac
.ops
.check_link
) {
2439 bool link_up
= false;
2441 hw
->mac
.ops
.check_link(hw
, &speed
, &link_up
, false);
2447 /* Check if this is not due to overtemp */
2448 if (hw
->phy
.ops
.check_overtemp(hw
) != IXGBE_ERR_OVERTEMP
)
2453 if (adapter
->hw
.mac
.type
>= ixgbe_mac_X540
)
2455 if (!(eicr
& IXGBE_EICR_GPI_SDP0(hw
)))
2459 e_crit(drv
, "%s\n", ixgbe_overheat_msg
);
2461 adapter
->interrupt_event
= 0;
2464 static void ixgbe_check_fan_failure(struct ixgbe_adapter
*adapter
, u32 eicr
)
2466 struct ixgbe_hw
*hw
= &adapter
->hw
;
2468 if ((adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) &&
2469 (eicr
& IXGBE_EICR_GPI_SDP1(hw
))) {
2470 e_crit(probe
, "Fan has stopped, replace the adapter\n");
2471 /* write to clear the interrupt */
2472 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP1(hw
));
2476 static void ixgbe_check_overtemp_event(struct ixgbe_adapter
*adapter
, u32 eicr
)
2478 struct ixgbe_hw
*hw
= &adapter
->hw
;
2480 if (!(adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
))
2483 switch (adapter
->hw
.mac
.type
) {
2484 case ixgbe_mac_82599EB
:
2486 * Need to check link state so complete overtemp check
2489 if (((eicr
& IXGBE_EICR_GPI_SDP0(hw
)) ||
2490 (eicr
& IXGBE_EICR_LSC
)) &&
2491 (!test_bit(__IXGBE_DOWN
, &adapter
->state
))) {
2492 adapter
->interrupt_event
= eicr
;
2493 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_EVENT
;
2494 ixgbe_service_event_schedule(adapter
);
2498 case ixgbe_mac_X540
:
2499 if (!(eicr
& IXGBE_EICR_TS
))
2506 e_crit(drv
, "%s\n", ixgbe_overheat_msg
);
2509 static inline bool ixgbe_is_sfp(struct ixgbe_hw
*hw
)
2511 switch (hw
->mac
.type
) {
2512 case ixgbe_mac_82598EB
:
2513 if (hw
->phy
.type
== ixgbe_phy_nl
)
2516 case ixgbe_mac_82599EB
:
2517 case ixgbe_mac_X550EM_x
:
2518 switch (hw
->mac
.ops
.get_media_type(hw
)) {
2519 case ixgbe_media_type_fiber
:
2520 case ixgbe_media_type_fiber_qsfp
:
2530 static void ixgbe_check_sfp_event(struct ixgbe_adapter
*adapter
, u32 eicr
)
2532 struct ixgbe_hw
*hw
= &adapter
->hw
;
2533 u32 eicr_mask
= IXGBE_EICR_GPI_SDP2(hw
);
2535 if (!ixgbe_is_sfp(hw
))
2538 /* Later MAC's use different SDP */
2539 if (hw
->mac
.type
>= ixgbe_mac_X540
)
2540 eicr_mask
= IXGBE_EICR_GPI_SDP0_X540
;
2542 if (eicr
& eicr_mask
) {
2543 /* Clear the interrupt */
2544 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, eicr_mask
);
2545 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
2546 adapter
->flags2
|= IXGBE_FLAG2_SFP_NEEDS_RESET
;
2547 adapter
->sfp_poll_time
= 0;
2548 ixgbe_service_event_schedule(adapter
);
2552 if (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
&&
2553 (eicr
& IXGBE_EICR_GPI_SDP1(hw
))) {
2554 /* Clear the interrupt */
2555 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_GPI_SDP1(hw
));
2556 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
2557 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_CONFIG
;
2558 ixgbe_service_event_schedule(adapter
);
2563 static void ixgbe_check_lsc(struct ixgbe_adapter
*adapter
)
2565 struct ixgbe_hw
*hw
= &adapter
->hw
;
2568 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
2569 adapter
->link_check_timeout
= jiffies
;
2570 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
2571 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_EIMC_LSC
);
2572 IXGBE_WRITE_FLUSH(hw
);
2573 ixgbe_service_event_schedule(adapter
);
2577 static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter
*adapter
,
2581 struct ixgbe_hw
*hw
= &adapter
->hw
;
2583 switch (hw
->mac
.type
) {
2584 case ixgbe_mac_82598EB
:
2585 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
2586 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, mask
);
2588 case ixgbe_mac_82599EB
:
2589 case ixgbe_mac_X540
:
2590 case ixgbe_mac_X550
:
2591 case ixgbe_mac_X550EM_x
:
2592 mask
= (qmask
& 0xFFFFFFFF);
2594 IXGBE_WRITE_REG(hw
, IXGBE_EIMS_EX(0), mask
);
2595 mask
= (qmask
>> 32);
2597 IXGBE_WRITE_REG(hw
, IXGBE_EIMS_EX(1), mask
);
2602 /* skip the flush */
2605 static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter
*adapter
,
2609 struct ixgbe_hw
*hw
= &adapter
->hw
;
2611 switch (hw
->mac
.type
) {
2612 case ixgbe_mac_82598EB
:
2613 mask
= (IXGBE_EIMS_RTX_QUEUE
& qmask
);
2614 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, mask
);
2616 case ixgbe_mac_82599EB
:
2617 case ixgbe_mac_X540
:
2618 case ixgbe_mac_X550
:
2619 case ixgbe_mac_X550EM_x
:
2620 mask
= (qmask
& 0xFFFFFFFF);
2622 IXGBE_WRITE_REG(hw
, IXGBE_EIMC_EX(0), mask
);
2623 mask
= (qmask
>> 32);
2625 IXGBE_WRITE_REG(hw
, IXGBE_EIMC_EX(1), mask
);
2630 /* skip the flush */
2634 * ixgbe_irq_enable - Enable default interrupt generation settings
2635 * @adapter: board private structure
2637 static inline void ixgbe_irq_enable(struct ixgbe_adapter
*adapter
, bool queues
,
2640 struct ixgbe_hw
*hw
= &adapter
->hw
;
2641 u32 mask
= (IXGBE_EIMS_ENABLE_MASK
& ~IXGBE_EIMS_RTX_QUEUE
);
2643 /* don't reenable LSC while waiting for link */
2644 if (adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
)
2645 mask
&= ~IXGBE_EIMS_LSC
;
2647 if (adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
)
2648 switch (adapter
->hw
.mac
.type
) {
2649 case ixgbe_mac_82599EB
:
2650 mask
|= IXGBE_EIMS_GPI_SDP0(hw
);
2652 case ixgbe_mac_X540
:
2653 case ixgbe_mac_X550
:
2654 case ixgbe_mac_X550EM_x
:
2655 mask
|= IXGBE_EIMS_TS
;
2660 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
)
2661 mask
|= IXGBE_EIMS_GPI_SDP1(hw
);
2662 switch (adapter
->hw
.mac
.type
) {
2663 case ixgbe_mac_82599EB
:
2664 mask
|= IXGBE_EIMS_GPI_SDP1(hw
);
2665 mask
|= IXGBE_EIMS_GPI_SDP2(hw
);
2667 case ixgbe_mac_X540
:
2668 case ixgbe_mac_X550
:
2669 case ixgbe_mac_X550EM_x
:
2670 if (adapter
->hw
.device_id
== IXGBE_DEV_ID_X550EM_X_SFP
)
2671 mask
|= IXGBE_EIMS_GPI_SDP0(&adapter
->hw
);
2672 if (adapter
->hw
.phy
.type
== ixgbe_phy_x550em_ext_t
)
2673 mask
|= IXGBE_EICR_GPI_SDP0_X540
;
2674 mask
|= IXGBE_EIMS_ECC
;
2675 mask
|= IXGBE_EIMS_MAILBOX
;
2681 if ((adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) &&
2682 !(adapter
->flags2
& IXGBE_FLAG2_FDIR_REQUIRES_REINIT
))
2683 mask
|= IXGBE_EIMS_FLOW_DIR
;
2685 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMS
, mask
);
2687 ixgbe_irq_enable_queues(adapter
, ~0);
2689 IXGBE_WRITE_FLUSH(&adapter
->hw
);
2692 static irqreturn_t
ixgbe_msix_other(int irq
, void *data
)
2694 struct ixgbe_adapter
*adapter
= data
;
2695 struct ixgbe_hw
*hw
= &adapter
->hw
;
2699 * Workaround for Silicon errata. Use clear-by-write instead
2700 * of clear-by-read. Reading with EICS will return the
2701 * interrupt causes without clearing, which later be done
2702 * with the write to EICR.
2704 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICS
);
2706 /* The lower 16bits of the EICR register are for the queue interrupts
2707 * which should be masked here in order to not accidentally clear them if
2708 * the bits are high when ixgbe_msix_other is called. There is a race
2709 * condition otherwise which results in possible performance loss
2710 * especially if the ixgbe_msix_other interrupt is triggering
2711 * consistently (as it would when PPS is turned on for the X540 device)
2715 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, eicr
);
2717 if (eicr
& IXGBE_EICR_LSC
)
2718 ixgbe_check_lsc(adapter
);
2720 if (eicr
& IXGBE_EICR_MAILBOX
)
2721 ixgbe_msg_task(adapter
);
2723 switch (hw
->mac
.type
) {
2724 case ixgbe_mac_82599EB
:
2725 case ixgbe_mac_X540
:
2726 case ixgbe_mac_X550
:
2727 case ixgbe_mac_X550EM_x
:
2728 if (hw
->phy
.type
== ixgbe_phy_x550em_ext_t
&&
2729 (eicr
& IXGBE_EICR_GPI_SDP0_X540
)) {
2730 adapter
->flags2
|= IXGBE_FLAG2_PHY_INTERRUPT
;
2731 ixgbe_service_event_schedule(adapter
);
2732 IXGBE_WRITE_REG(hw
, IXGBE_EICR
,
2733 IXGBE_EICR_GPI_SDP0_X540
);
2735 if (eicr
& IXGBE_EICR_ECC
) {
2736 e_info(link
, "Received ECC Err, initiating reset\n");
2737 adapter
->flags2
|= IXGBE_FLAG2_RESET_REQUESTED
;
2738 ixgbe_service_event_schedule(adapter
);
2739 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_ECC
);
2741 /* Handle Flow Director Full threshold interrupt */
2742 if (eicr
& IXGBE_EICR_FLOW_DIR
) {
2743 int reinit_count
= 0;
2745 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
2746 struct ixgbe_ring
*ring
= adapter
->tx_ring
[i
];
2747 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE
,
2752 /* no more flow director interrupts until after init */
2753 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_EIMC_FLOW_DIR
);
2754 adapter
->flags2
|= IXGBE_FLAG2_FDIR_REQUIRES_REINIT
;
2755 ixgbe_service_event_schedule(adapter
);
2758 ixgbe_check_sfp_event(adapter
, eicr
);
2759 ixgbe_check_overtemp_event(adapter
, eicr
);
2765 ixgbe_check_fan_failure(adapter
, eicr
);
2767 if (unlikely(eicr
& IXGBE_EICR_TIMESYNC
))
2768 ixgbe_ptp_check_pps_event(adapter
);
2770 /* re-enable the original interrupt state, no lsc, no queues */
2771 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2772 ixgbe_irq_enable(adapter
, false, false);
2777 static irqreturn_t
ixgbe_msix_clean_rings(int irq
, void *data
)
2779 struct ixgbe_q_vector
*q_vector
= data
;
2781 /* EIAM disabled interrupts (on this vector) for us */
2783 if (q_vector
->rx
.ring
|| q_vector
->tx
.ring
)
2784 napi_schedule_irqoff(&q_vector
->napi
);
2790 * ixgbe_poll - NAPI Rx polling callback
2791 * @napi: structure for representing this polling device
2792 * @budget: how many packets driver is allowed to clean
2794 * This function is used for legacy and MSI, NAPI mode
2796 int ixgbe_poll(struct napi_struct
*napi
, int budget
)
2798 struct ixgbe_q_vector
*q_vector
=
2799 container_of(napi
, struct ixgbe_q_vector
, napi
);
2800 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
2801 struct ixgbe_ring
*ring
;
2802 int per_ring_budget
, work_done
= 0;
2803 bool clean_complete
= true;
2805 #ifdef CONFIG_IXGBE_DCA
2806 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
)
2807 ixgbe_update_dca(q_vector
);
2810 ixgbe_for_each_ring(ring
, q_vector
->tx
)
2811 clean_complete
&= !!ixgbe_clean_tx_irq(q_vector
, ring
, budget
);
2813 /* Exit if we are called by netpoll or busy polling is active */
2814 if ((budget
<= 0) || !ixgbe_qv_lock_napi(q_vector
))
2817 /* attempt to distribute budget to each queue fairly, but don't allow
2818 * the budget to go below 1 because we'll exit polling */
2819 if (q_vector
->rx
.count
> 1)
2820 per_ring_budget
= max(budget
/q_vector
->rx
.count
, 1);
2822 per_ring_budget
= budget
;
2824 ixgbe_for_each_ring(ring
, q_vector
->rx
) {
2825 int cleaned
= ixgbe_clean_rx_irq(q_vector
, ring
,
2828 work_done
+= cleaned
;
2829 clean_complete
&= (cleaned
< per_ring_budget
);
2832 ixgbe_qv_unlock_napi(q_vector
);
2833 /* If all work not completed, return budget and keep polling */
2834 if (!clean_complete
)
2837 /* all work done, exit the polling mode */
2838 napi_complete_done(napi
, work_done
);
2839 if (adapter
->rx_itr_setting
& 1)
2840 ixgbe_set_itr(q_vector
);
2841 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2842 ixgbe_irq_enable_queues(adapter
, ((u64
)1 << q_vector
->v_idx
));
2848 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2849 * @adapter: board private structure
2851 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2852 * interrupts from the kernel.
2854 static int ixgbe_request_msix_irqs(struct ixgbe_adapter
*adapter
)
2856 struct net_device
*netdev
= adapter
->netdev
;
2860 for (vector
= 0; vector
< adapter
->num_q_vectors
; vector
++) {
2861 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[vector
];
2862 struct msix_entry
*entry
= &adapter
->msix_entries
[vector
];
2864 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
2865 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2866 "%s-%s-%d", netdev
->name
, "TxRx", ri
++);
2868 } else if (q_vector
->rx
.ring
) {
2869 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2870 "%s-%s-%d", netdev
->name
, "rx", ri
++);
2871 } else if (q_vector
->tx
.ring
) {
2872 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
2873 "%s-%s-%d", netdev
->name
, "tx", ti
++);
2875 /* skip this unused q_vector */
2878 err
= request_irq(entry
->vector
, &ixgbe_msix_clean_rings
, 0,
2879 q_vector
->name
, q_vector
);
2881 e_err(probe
, "request_irq failed for MSIX interrupt "
2882 "Error: %d\n", err
);
2883 goto free_queue_irqs
;
2885 /* If Flow Director is enabled, set interrupt affinity */
2886 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
2887 /* assign the mask for this irq */
2888 irq_set_affinity_hint(entry
->vector
,
2889 &q_vector
->affinity_mask
);
2893 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
2894 ixgbe_msix_other
, 0, netdev
->name
, adapter
);
2896 e_err(probe
, "request_irq for msix_other failed: %d\n", err
);
2897 goto free_queue_irqs
;
2905 irq_set_affinity_hint(adapter
->msix_entries
[vector
].vector
,
2907 free_irq(adapter
->msix_entries
[vector
].vector
,
2908 adapter
->q_vector
[vector
]);
2910 adapter
->flags
&= ~IXGBE_FLAG_MSIX_ENABLED
;
2911 pci_disable_msix(adapter
->pdev
);
2912 kfree(adapter
->msix_entries
);
2913 adapter
->msix_entries
= NULL
;
2918 * ixgbe_intr - legacy mode Interrupt Handler
2919 * @irq: interrupt number
2920 * @data: pointer to a network interface device structure
2922 static irqreturn_t
ixgbe_intr(int irq
, void *data
)
2924 struct ixgbe_adapter
*adapter
= data
;
2925 struct ixgbe_hw
*hw
= &adapter
->hw
;
2926 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[0];
2930 * Workaround for silicon errata #26 on 82598. Mask the interrupt
2931 * before the read of EICR.
2933 IXGBE_WRITE_REG(hw
, IXGBE_EIMC
, IXGBE_IRQ_CLEAR_MASK
);
2935 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2936 * therefore no explicit interrupt disable is necessary */
2937 eicr
= IXGBE_READ_REG(hw
, IXGBE_EICR
);
2940 * shared interrupt alert!
2941 * make sure interrupts are enabled because the read will
2942 * have disabled interrupts due to EIAM
2943 * finish the workaround of silicon errata on 82598. Unmask
2944 * the interrupt that we masked before the EICR read.
2946 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2947 ixgbe_irq_enable(adapter
, true, true);
2948 return IRQ_NONE
; /* Not our interrupt */
2951 if (eicr
& IXGBE_EICR_LSC
)
2952 ixgbe_check_lsc(adapter
);
2954 switch (hw
->mac
.type
) {
2955 case ixgbe_mac_82599EB
:
2956 ixgbe_check_sfp_event(adapter
, eicr
);
2958 case ixgbe_mac_X540
:
2959 case ixgbe_mac_X550
:
2960 case ixgbe_mac_X550EM_x
:
2961 if (eicr
& IXGBE_EICR_ECC
) {
2962 e_info(link
, "Received ECC Err, initiating reset\n");
2963 adapter
->flags2
|= IXGBE_FLAG2_RESET_REQUESTED
;
2964 ixgbe_service_event_schedule(adapter
);
2965 IXGBE_WRITE_REG(hw
, IXGBE_EICR
, IXGBE_EICR_ECC
);
2967 ixgbe_check_overtemp_event(adapter
, eicr
);
2973 ixgbe_check_fan_failure(adapter
, eicr
);
2974 if (unlikely(eicr
& IXGBE_EICR_TIMESYNC
))
2975 ixgbe_ptp_check_pps_event(adapter
);
2977 /* would disable interrupts here but EIAM disabled it */
2978 napi_schedule_irqoff(&q_vector
->napi
);
2981 * re-enable link(maybe) and non-queue interrupts, no flush.
2982 * ixgbe_poll will re-enable the queue interrupts
2984 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
))
2985 ixgbe_irq_enable(adapter
, false, false);
2991 * ixgbe_request_irq - initialize interrupts
2992 * @adapter: board private structure
2994 * Attempts to configure interrupts using the best available
2995 * capabilities of the hardware and kernel.
2997 static int ixgbe_request_irq(struct ixgbe_adapter
*adapter
)
2999 struct net_device
*netdev
= adapter
->netdev
;
3002 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
3003 err
= ixgbe_request_msix_irqs(adapter
);
3004 else if (adapter
->flags
& IXGBE_FLAG_MSI_ENABLED
)
3005 err
= request_irq(adapter
->pdev
->irq
, ixgbe_intr
, 0,
3006 netdev
->name
, adapter
);
3008 err
= request_irq(adapter
->pdev
->irq
, ixgbe_intr
, IRQF_SHARED
,
3009 netdev
->name
, adapter
);
3012 e_err(probe
, "request_irq failed, Error %d\n", err
);
3017 static void ixgbe_free_irq(struct ixgbe_adapter
*adapter
)
3021 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)) {
3022 free_irq(adapter
->pdev
->irq
, adapter
);
3026 for (vector
= 0; vector
< adapter
->num_q_vectors
; vector
++) {
3027 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[vector
];
3028 struct msix_entry
*entry
= &adapter
->msix_entries
[vector
];
3030 /* free only the irqs that were actually requested */
3031 if (!q_vector
->rx
.ring
&& !q_vector
->tx
.ring
)
3034 /* clear the affinity_mask in the IRQ descriptor */
3035 irq_set_affinity_hint(entry
->vector
, NULL
);
3037 free_irq(entry
->vector
, q_vector
);
3040 free_irq(adapter
->msix_entries
[vector
++].vector
, adapter
);
3044 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
3045 * @adapter: board private structure
3047 static inline void ixgbe_irq_disable(struct ixgbe_adapter
*adapter
)
3049 switch (adapter
->hw
.mac
.type
) {
3050 case ixgbe_mac_82598EB
:
3051 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, ~0);
3053 case ixgbe_mac_82599EB
:
3054 case ixgbe_mac_X540
:
3055 case ixgbe_mac_X550
:
3056 case ixgbe_mac_X550EM_x
:
3057 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC
, 0xFFFF0000);
3058 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(0), ~0);
3059 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EIMC_EX(1), ~0);
3064 IXGBE_WRITE_FLUSH(&adapter
->hw
);
3065 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
3068 for (vector
= 0; vector
< adapter
->num_q_vectors
; vector
++)
3069 synchronize_irq(adapter
->msix_entries
[vector
].vector
);
3071 synchronize_irq(adapter
->msix_entries
[vector
++].vector
);
3073 synchronize_irq(adapter
->pdev
->irq
);
3078 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3081 static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter
*adapter
)
3083 struct ixgbe_q_vector
*q_vector
= adapter
->q_vector
[0];
3085 ixgbe_write_eitr(q_vector
);
3087 ixgbe_set_ivar(adapter
, 0, 0, 0);
3088 ixgbe_set_ivar(adapter
, 1, 0, 0);
3090 e_info(hw
, "Legacy interrupt IVAR setup done\n");
3094 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3095 * @adapter: board private structure
3096 * @ring: structure containing ring specific data
3098 * Configure the Tx descriptor ring after a reset.
3100 void ixgbe_configure_tx_ring(struct ixgbe_adapter
*adapter
,
3101 struct ixgbe_ring
*ring
)
3103 struct ixgbe_hw
*hw
= &adapter
->hw
;
3104 u64 tdba
= ring
->dma
;
3106 u32 txdctl
= IXGBE_TXDCTL_ENABLE
;
3107 u8 reg_idx
= ring
->reg_idx
;
3109 /* disable queue to avoid issues while updating state */
3110 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
), 0);
3111 IXGBE_WRITE_FLUSH(hw
);
3113 IXGBE_WRITE_REG(hw
, IXGBE_TDBAL(reg_idx
),
3114 (tdba
& DMA_BIT_MASK(32)));
3115 IXGBE_WRITE_REG(hw
, IXGBE_TDBAH(reg_idx
), (tdba
>> 32));
3116 IXGBE_WRITE_REG(hw
, IXGBE_TDLEN(reg_idx
),
3117 ring
->count
* sizeof(union ixgbe_adv_tx_desc
));
3118 IXGBE_WRITE_REG(hw
, IXGBE_TDH(reg_idx
), 0);
3119 IXGBE_WRITE_REG(hw
, IXGBE_TDT(reg_idx
), 0);
3120 ring
->tail
= adapter
->io_addr
+ IXGBE_TDT(reg_idx
);
3123 * set WTHRESH to encourage burst writeback, it should not be set
3124 * higher than 1 when:
3125 * - ITR is 0 as it could cause false TX hangs
3126 * - ITR is set to > 100k int/sec and BQL is enabled
3128 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3129 * to or less than the number of on chip descriptors, which is
3132 if (!ring
->q_vector
|| (ring
->q_vector
->itr
< IXGBE_100K_ITR
))
3133 txdctl
|= (1 << 16); /* WTHRESH = 1 */
3135 txdctl
|= (8 << 16); /* WTHRESH = 8 */
3138 * Setting PTHRESH to 32 both improves performance
3139 * and avoids a TX hang with DFP enabled
3141 txdctl
|= (1 << 8) | /* HTHRESH = 1 */
3142 32; /* PTHRESH = 32 */
3144 /* reinitialize flowdirector state */
3145 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
3146 ring
->atr_sample_rate
= adapter
->atr_sample_rate
;
3147 ring
->atr_count
= 0;
3148 set_bit(__IXGBE_TX_FDIR_INIT_DONE
, &ring
->state
);
3150 ring
->atr_sample_rate
= 0;
3153 /* initialize XPS */
3154 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE
, &ring
->state
)) {
3155 struct ixgbe_q_vector
*q_vector
= ring
->q_vector
;
3158 netif_set_xps_queue(ring
->netdev
,
3159 &q_vector
->affinity_mask
,
3163 clear_bit(__IXGBE_HANG_CHECK_ARMED
, &ring
->state
);
3166 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
), txdctl
);
3168 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3169 if (hw
->mac
.type
== ixgbe_mac_82598EB
&&
3170 !(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
3173 /* poll to verify queue is enabled */
3175 usleep_range(1000, 2000);
3176 txdctl
= IXGBE_READ_REG(hw
, IXGBE_TXDCTL(reg_idx
));
3177 } while (--wait_loop
&& !(txdctl
& IXGBE_TXDCTL_ENABLE
));
3179 e_err(drv
, "Could not enable Tx Queue %d\n", reg_idx
);
3182 static void ixgbe_setup_mtqc(struct ixgbe_adapter
*adapter
)
3184 struct ixgbe_hw
*hw
= &adapter
->hw
;
3186 u8 tcs
= netdev_get_num_tc(adapter
->netdev
);
3188 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
3191 /* disable the arbiter while setting MTQC */
3192 rttdcs
= IXGBE_READ_REG(hw
, IXGBE_RTTDCS
);
3193 rttdcs
|= IXGBE_RTTDCS_ARBDIS
;
3194 IXGBE_WRITE_REG(hw
, IXGBE_RTTDCS
, rttdcs
);
3196 /* set transmit pool layout */
3197 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
3198 mtqc
= IXGBE_MTQC_VT_ENA
;
3200 mtqc
|= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_8TC_8TQ
;
3202 mtqc
|= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_4TC_4TQ
;
3203 else if (adapter
->ring_feature
[RING_F_RSS
].indices
== 4)
3204 mtqc
|= IXGBE_MTQC_32VF
;
3206 mtqc
|= IXGBE_MTQC_64VF
;
3209 mtqc
= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_8TC_8TQ
;
3211 mtqc
= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_4TC_4TQ
;
3213 mtqc
= IXGBE_MTQC_64Q_1PB
;
3216 IXGBE_WRITE_REG(hw
, IXGBE_MTQC
, mtqc
);
3218 /* Enable Security TX Buffer IFG for multiple pb */
3220 u32 sectx
= IXGBE_READ_REG(hw
, IXGBE_SECTXMINIFG
);
3221 sectx
|= IXGBE_SECTX_DCB
;
3222 IXGBE_WRITE_REG(hw
, IXGBE_SECTXMINIFG
, sectx
);
3225 /* re-enable the arbiter */
3226 rttdcs
&= ~IXGBE_RTTDCS_ARBDIS
;
3227 IXGBE_WRITE_REG(hw
, IXGBE_RTTDCS
, rttdcs
);
3231 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
3232 * @adapter: board private structure
3234 * Configure the Tx unit of the MAC after a reset.
3236 static void ixgbe_configure_tx(struct ixgbe_adapter
*adapter
)
3238 struct ixgbe_hw
*hw
= &adapter
->hw
;
3242 ixgbe_setup_mtqc(adapter
);
3244 if (hw
->mac
.type
!= ixgbe_mac_82598EB
) {
3245 /* DMATXCTL.EN must be before Tx queues are enabled */
3246 dmatxctl
= IXGBE_READ_REG(hw
, IXGBE_DMATXCTL
);
3247 dmatxctl
|= IXGBE_DMATXCTL_TE
;
3248 IXGBE_WRITE_REG(hw
, IXGBE_DMATXCTL
, dmatxctl
);
3251 /* Setup the HW Tx Head and Tail descriptor pointers */
3252 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
3253 ixgbe_configure_tx_ring(adapter
, adapter
->tx_ring
[i
]);
3256 static void ixgbe_enable_rx_drop(struct ixgbe_adapter
*adapter
,
3257 struct ixgbe_ring
*ring
)
3259 struct ixgbe_hw
*hw
= &adapter
->hw
;
3260 u8 reg_idx
= ring
->reg_idx
;
3261 u32 srrctl
= IXGBE_READ_REG(hw
, IXGBE_SRRCTL(reg_idx
));
3263 srrctl
|= IXGBE_SRRCTL_DROP_EN
;
3265 IXGBE_WRITE_REG(hw
, IXGBE_SRRCTL(reg_idx
), srrctl
);
3268 static void ixgbe_disable_rx_drop(struct ixgbe_adapter
*adapter
,
3269 struct ixgbe_ring
*ring
)
3271 struct ixgbe_hw
*hw
= &adapter
->hw
;
3272 u8 reg_idx
= ring
->reg_idx
;
3273 u32 srrctl
= IXGBE_READ_REG(hw
, IXGBE_SRRCTL(reg_idx
));
3275 srrctl
&= ~IXGBE_SRRCTL_DROP_EN
;
3277 IXGBE_WRITE_REG(hw
, IXGBE_SRRCTL(reg_idx
), srrctl
);
3280 #ifdef CONFIG_IXGBE_DCB
3281 void ixgbe_set_rx_drop_en(struct ixgbe_adapter
*adapter
)
3283 static void ixgbe_set_rx_drop_en(struct ixgbe_adapter
*adapter
)
3287 bool pfc_en
= adapter
->dcb_cfg
.pfc_mode_enable
;
3289 if (adapter
->ixgbe_ieee_pfc
)
3290 pfc_en
|= !!(adapter
->ixgbe_ieee_pfc
->pfc_en
);
3293 * We should set the drop enable bit if:
3296 * Number of Rx queues > 1 and flow control is disabled
3298 * This allows us to avoid head of line blocking for security
3299 * and performance reasons.
3301 if (adapter
->num_vfs
|| (adapter
->num_rx_queues
> 1 &&
3302 !(adapter
->hw
.fc
.current_mode
& ixgbe_fc_tx_pause
) && !pfc_en
)) {
3303 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3304 ixgbe_enable_rx_drop(adapter
, adapter
->rx_ring
[i
]);
3306 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3307 ixgbe_disable_rx_drop(adapter
, adapter
->rx_ring
[i
]);
3311 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
3313 static void ixgbe_configure_srrctl(struct ixgbe_adapter
*adapter
,
3314 struct ixgbe_ring
*rx_ring
)
3316 struct ixgbe_hw
*hw
= &adapter
->hw
;
3318 u8 reg_idx
= rx_ring
->reg_idx
;
3320 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
3321 u16 mask
= adapter
->ring_feature
[RING_F_RSS
].mask
;
3324 * if VMDq is not active we must program one srrctl register
3325 * per RSS queue since we have enabled RDRXCTL.MVMEN
3330 /* configure header buffer length, needed for RSC */
3331 srrctl
= IXGBE_RX_HDR_SIZE
<< IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT
;
3333 /* configure the packet buffer length */
3334 srrctl
|= ixgbe_rx_bufsz(rx_ring
) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT
;
3336 /* configure descriptor type */
3337 srrctl
|= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF
;
3339 IXGBE_WRITE_REG(hw
, IXGBE_SRRCTL(reg_idx
), srrctl
);
3343 * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
3344 * @adapter: device handle
3346 * - 82598/82599/X540: 128
3347 * - X550(non-SRIOV mode): 512
3348 * - X550(SRIOV mode): 64
3350 u32
ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter
*adapter
)
3352 if (adapter
->hw
.mac
.type
< ixgbe_mac_X550
)
3354 else if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
3361 * ixgbe_store_reta - Write the RETA table to HW
3362 * @adapter: device handle
3364 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3366 void ixgbe_store_reta(struct ixgbe_adapter
*adapter
)
3368 u32 i
, reta_entries
= ixgbe_rss_indir_tbl_entries(adapter
);
3369 struct ixgbe_hw
*hw
= &adapter
->hw
;
3372 u8
*indir_tbl
= adapter
->rss_indir_tbl
;
3374 /* Fill out the redirection table as follows:
3375 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3377 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3378 * - X550: 8 bit wide entries containing 6 bit RSS index
3380 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
3381 indices_multi
= 0x11;
3383 indices_multi
= 0x1;
3385 /* Write redirection table to HW */
3386 for (i
= 0; i
< reta_entries
; i
++) {
3387 reta
|= indices_multi
* indir_tbl
[i
] << (i
& 0x3) * 8;
3390 IXGBE_WRITE_REG(hw
, IXGBE_RETA(i
>> 2), reta
);
3392 IXGBE_WRITE_REG(hw
, IXGBE_ERETA((i
>> 2) - 32),
3400 * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
3401 * @adapter: device handle
3403 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3405 static void ixgbe_store_vfreta(struct ixgbe_adapter
*adapter
)
3407 u32 i
, reta_entries
= ixgbe_rss_indir_tbl_entries(adapter
);
3408 struct ixgbe_hw
*hw
= &adapter
->hw
;
3410 unsigned int pf_pool
= adapter
->num_vfs
;
3412 /* Write redirection table to HW */
3413 for (i
= 0; i
< reta_entries
; i
++) {
3414 vfreta
|= (u32
)adapter
->rss_indir_tbl
[i
] << (i
& 0x3) * 8;
3416 IXGBE_WRITE_REG(hw
, IXGBE_PFVFRETA(i
>> 2, pf_pool
),
3423 static void ixgbe_setup_reta(struct ixgbe_adapter
*adapter
)
3425 struct ixgbe_hw
*hw
= &adapter
->hw
;
3427 u32 reta_entries
= ixgbe_rss_indir_tbl_entries(adapter
);
3428 u16 rss_i
= adapter
->ring_feature
[RING_F_RSS
].indices
;
3430 /* Program table for at least 2 queues w/ SR-IOV so that VFs can
3431 * make full use of any rings they may have. We will use the
3432 * PSRTYPE register to control how many rings we use within the PF.
3434 if ((adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) && (rss_i
< 2))
3437 /* Fill out hash function seeds */
3438 for (i
= 0; i
< 10; i
++)
3439 IXGBE_WRITE_REG(hw
, IXGBE_RSSRK(i
), adapter
->rss_key
[i
]);
3441 /* Fill out redirection table */
3442 memset(adapter
->rss_indir_tbl
, 0, sizeof(adapter
->rss_indir_tbl
));
3444 for (i
= 0, j
= 0; i
< reta_entries
; i
++, j
++) {
3448 adapter
->rss_indir_tbl
[i
] = j
;
3451 ixgbe_store_reta(adapter
);
3454 static void ixgbe_setup_vfreta(struct ixgbe_adapter
*adapter
)
3456 struct ixgbe_hw
*hw
= &adapter
->hw
;
3457 u16 rss_i
= adapter
->ring_feature
[RING_F_RSS
].indices
;
3458 unsigned int pf_pool
= adapter
->num_vfs
;
3461 /* Fill out hash function seeds */
3462 for (i
= 0; i
< 10; i
++)
3463 IXGBE_WRITE_REG(hw
, IXGBE_PFVFRSSRK(i
, pf_pool
),
3464 adapter
->rss_key
[i
]);
3466 /* Fill out the redirection table */
3467 for (i
= 0, j
= 0; i
< 64; i
++, j
++) {
3471 adapter
->rss_indir_tbl
[i
] = j
;
3474 ixgbe_store_vfreta(adapter
);
3477 static void ixgbe_setup_mrqc(struct ixgbe_adapter
*adapter
)
3479 struct ixgbe_hw
*hw
= &adapter
->hw
;
3480 u32 mrqc
= 0, rss_field
= 0, vfmrqc
= 0;
3483 /* Disable indicating checksum in descriptor, enables RSS hash */
3484 rxcsum
= IXGBE_READ_REG(hw
, IXGBE_RXCSUM
);
3485 rxcsum
|= IXGBE_RXCSUM_PCSD
;
3486 IXGBE_WRITE_REG(hw
, IXGBE_RXCSUM
, rxcsum
);
3488 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
3489 if (adapter
->ring_feature
[RING_F_RSS
].mask
)
3490 mrqc
= IXGBE_MRQC_RSSEN
;
3492 u8 tcs
= netdev_get_num_tc(adapter
->netdev
);
3494 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
3496 mrqc
= IXGBE_MRQC_VMDQRT8TCEN
; /* 8 TCs */
3498 mrqc
= IXGBE_MRQC_VMDQRT4TCEN
; /* 4 TCs */
3499 else if (adapter
->ring_feature
[RING_F_RSS
].indices
== 4)
3500 mrqc
= IXGBE_MRQC_VMDQRSS32EN
;
3502 mrqc
= IXGBE_MRQC_VMDQRSS64EN
;
3505 mrqc
= IXGBE_MRQC_RTRSS8TCEN
;
3507 mrqc
= IXGBE_MRQC_RTRSS4TCEN
;
3509 mrqc
= IXGBE_MRQC_RSSEN
;
3513 /* Perform hash on these packet types */
3514 rss_field
|= IXGBE_MRQC_RSS_FIELD_IPV4
|
3515 IXGBE_MRQC_RSS_FIELD_IPV4_TCP
|
3516 IXGBE_MRQC_RSS_FIELD_IPV6
|
3517 IXGBE_MRQC_RSS_FIELD_IPV6_TCP
;
3519 if (adapter
->flags2
& IXGBE_FLAG2_RSS_FIELD_IPV4_UDP
)
3520 rss_field
|= IXGBE_MRQC_RSS_FIELD_IPV4_UDP
;
3521 if (adapter
->flags2
& IXGBE_FLAG2_RSS_FIELD_IPV6_UDP
)
3522 rss_field
|= IXGBE_MRQC_RSS_FIELD_IPV6_UDP
;
3524 netdev_rss_key_fill(adapter
->rss_key
, sizeof(adapter
->rss_key
));
3525 if ((hw
->mac
.type
>= ixgbe_mac_X550
) &&
3526 (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)) {
3527 unsigned int pf_pool
= adapter
->num_vfs
;
3529 /* Enable VF RSS mode */
3530 mrqc
|= IXGBE_MRQC_MULTIPLE_RSS
;
3531 IXGBE_WRITE_REG(hw
, IXGBE_MRQC
, mrqc
);
3533 /* Setup RSS through the VF registers */
3534 ixgbe_setup_vfreta(adapter
);
3535 vfmrqc
= IXGBE_MRQC_RSSEN
;
3536 vfmrqc
|= rss_field
;
3537 IXGBE_WRITE_REG(hw
, IXGBE_PFVFMRQC(pf_pool
), vfmrqc
);
3539 ixgbe_setup_reta(adapter
);
3541 IXGBE_WRITE_REG(hw
, IXGBE_MRQC
, mrqc
);
3546 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3547 * @adapter: address of board private structure
3548 * @index: index of ring to set
3550 static void ixgbe_configure_rscctl(struct ixgbe_adapter
*adapter
,
3551 struct ixgbe_ring
*ring
)
3553 struct ixgbe_hw
*hw
= &adapter
->hw
;
3555 u8 reg_idx
= ring
->reg_idx
;
3557 if (!ring_is_rsc_enabled(ring
))
3560 rscctrl
= IXGBE_READ_REG(hw
, IXGBE_RSCCTL(reg_idx
));
3561 rscctrl
|= IXGBE_RSCCTL_RSCEN
;
3563 * we must limit the number of descriptors so that the
3564 * total size of max desc * buf_len is not greater
3567 rscctrl
|= IXGBE_RSCCTL_MAXDESC_16
;
3568 IXGBE_WRITE_REG(hw
, IXGBE_RSCCTL(reg_idx
), rscctrl
);
3571 #define IXGBE_MAX_RX_DESC_POLL 10
3572 static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter
*adapter
,
3573 struct ixgbe_ring
*ring
)
3575 struct ixgbe_hw
*hw
= &adapter
->hw
;
3576 int wait_loop
= IXGBE_MAX_RX_DESC_POLL
;
3578 u8 reg_idx
= ring
->reg_idx
;
3580 if (ixgbe_removed(hw
->hw_addr
))
3582 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3583 if (hw
->mac
.type
== ixgbe_mac_82598EB
&&
3584 !(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
3588 usleep_range(1000, 2000);
3589 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
3590 } while (--wait_loop
&& !(rxdctl
& IXGBE_RXDCTL_ENABLE
));
3593 e_err(drv
, "RXDCTL.ENABLE on Rx queue %d not set within "
3594 "the polling period\n", reg_idx
);
3598 void ixgbe_disable_rx_queue(struct ixgbe_adapter
*adapter
,
3599 struct ixgbe_ring
*ring
)
3601 struct ixgbe_hw
*hw
= &adapter
->hw
;
3602 int wait_loop
= IXGBE_MAX_RX_DESC_POLL
;
3604 u8 reg_idx
= ring
->reg_idx
;
3606 if (ixgbe_removed(hw
->hw_addr
))
3608 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
3609 rxdctl
&= ~IXGBE_RXDCTL_ENABLE
;
3611 /* write value back with RXDCTL.ENABLE bit cleared */
3612 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(reg_idx
), rxdctl
);
3614 if (hw
->mac
.type
== ixgbe_mac_82598EB
&&
3615 !(IXGBE_READ_REG(hw
, IXGBE_LINKS
) & IXGBE_LINKS_UP
))
3618 /* the hardware may take up to 100us to really disable the rx queue */
3621 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
3622 } while (--wait_loop
&& (rxdctl
& IXGBE_RXDCTL_ENABLE
));
3625 e_err(drv
, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3626 "the polling period\n", reg_idx
);
3630 void ixgbe_configure_rx_ring(struct ixgbe_adapter
*adapter
,
3631 struct ixgbe_ring
*ring
)
3633 struct ixgbe_hw
*hw
= &adapter
->hw
;
3634 u64 rdba
= ring
->dma
;
3636 u8 reg_idx
= ring
->reg_idx
;
3638 /* disable queue to avoid issues while updating state */
3639 rxdctl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(reg_idx
));
3640 ixgbe_disable_rx_queue(adapter
, ring
);
3642 IXGBE_WRITE_REG(hw
, IXGBE_RDBAL(reg_idx
), (rdba
& DMA_BIT_MASK(32)));
3643 IXGBE_WRITE_REG(hw
, IXGBE_RDBAH(reg_idx
), (rdba
>> 32));
3644 IXGBE_WRITE_REG(hw
, IXGBE_RDLEN(reg_idx
),
3645 ring
->count
* sizeof(union ixgbe_adv_rx_desc
));
3646 /* Force flushing of IXGBE_RDLEN to prevent MDD */
3647 IXGBE_WRITE_FLUSH(hw
);
3649 IXGBE_WRITE_REG(hw
, IXGBE_RDH(reg_idx
), 0);
3650 IXGBE_WRITE_REG(hw
, IXGBE_RDT(reg_idx
), 0);
3651 ring
->tail
= adapter
->io_addr
+ IXGBE_RDT(reg_idx
);
3653 ixgbe_configure_srrctl(adapter
, ring
);
3654 ixgbe_configure_rscctl(adapter
, ring
);
3656 if (hw
->mac
.type
== ixgbe_mac_82598EB
) {
3658 * enable cache line friendly hardware writes:
3659 * PTHRESH=32 descriptors (half the internal cache),
3660 * this also removes ugly rx_no_buffer_count increment
3661 * HTHRESH=4 descriptors (to minimize latency on fetch)
3662 * WTHRESH=8 burst writeback up to two cache lines
3664 rxdctl
&= ~0x3FFFFF;
3668 /* enable receive descriptor ring */
3669 rxdctl
|= IXGBE_RXDCTL_ENABLE
;
3670 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(reg_idx
), rxdctl
);
3672 ixgbe_rx_desc_queue_enable(adapter
, ring
);
3673 ixgbe_alloc_rx_buffers(ring
, ixgbe_desc_unused(ring
));
3676 static void ixgbe_setup_psrtype(struct ixgbe_adapter
*adapter
)
3678 struct ixgbe_hw
*hw
= &adapter
->hw
;
3679 int rss_i
= adapter
->ring_feature
[RING_F_RSS
].indices
;
3682 /* PSRTYPE must be initialized in non 82598 adapters */
3683 u32 psrtype
= IXGBE_PSRTYPE_TCPHDR
|
3684 IXGBE_PSRTYPE_UDPHDR
|
3685 IXGBE_PSRTYPE_IPV4HDR
|
3686 IXGBE_PSRTYPE_L2HDR
|
3687 IXGBE_PSRTYPE_IPV6HDR
;
3689 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
3697 for_each_set_bit(pool
, &adapter
->fwd_bitmask
, 32)
3698 IXGBE_WRITE_REG(hw
, IXGBE_PSRTYPE(VMDQ_P(pool
)), psrtype
);
3701 static void ixgbe_configure_virtualization(struct ixgbe_adapter
*adapter
)
3703 struct ixgbe_hw
*hw
= &adapter
->hw
;
3704 u32 reg_offset
, vf_shift
;
3705 u32 gcr_ext
, vmdctl
;
3708 if (!(adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
))
3711 vmdctl
= IXGBE_READ_REG(hw
, IXGBE_VT_CTL
);
3712 vmdctl
|= IXGBE_VMD_CTL_VMDQ_EN
;
3713 vmdctl
&= ~IXGBE_VT_CTL_POOL_MASK
;
3714 vmdctl
|= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT
;
3715 vmdctl
|= IXGBE_VT_CTL_REPLEN
;
3716 IXGBE_WRITE_REG(hw
, IXGBE_VT_CTL
, vmdctl
);
3718 vf_shift
= VMDQ_P(0) % 32;
3719 reg_offset
= (VMDQ_P(0) >= 32) ? 1 : 0;
3721 /* Enable only the PF's pool for Tx/Rx */
3722 IXGBE_WRITE_REG(hw
, IXGBE_VFRE(reg_offset
), (~0) << vf_shift
);
3723 IXGBE_WRITE_REG(hw
, IXGBE_VFRE(reg_offset
^ 1), reg_offset
- 1);
3724 IXGBE_WRITE_REG(hw
, IXGBE_VFTE(reg_offset
), (~0) << vf_shift
);
3725 IXGBE_WRITE_REG(hw
, IXGBE_VFTE(reg_offset
^ 1), reg_offset
- 1);
3726 if (adapter
->bridge_mode
== BRIDGE_MODE_VEB
)
3727 IXGBE_WRITE_REG(hw
, IXGBE_PFDTXGSWC
, IXGBE_PFDTXGSWC_VT_LBEN
);
3729 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3730 hw
->mac
.ops
.set_vmdq(hw
, 0, VMDQ_P(0));
3732 /* clear VLAN promisc flag so VFTA will be updated if necessary */
3733 adapter
->flags2
&= ~IXGBE_FLAG2_VLAN_PROMISC
;
3736 * Set up VF register offsets for selected VT Mode,
3737 * i.e. 32 or 64 VFs for SR-IOV
3739 switch (adapter
->ring_feature
[RING_F_VMDQ
].mask
) {
3740 case IXGBE_82599_VMDQ_8Q_MASK
:
3741 gcr_ext
= IXGBE_GCR_EXT_VT_MODE_16
;
3743 case IXGBE_82599_VMDQ_4Q_MASK
:
3744 gcr_ext
= IXGBE_GCR_EXT_VT_MODE_32
;
3747 gcr_ext
= IXGBE_GCR_EXT_VT_MODE_64
;
3751 IXGBE_WRITE_REG(hw
, IXGBE_GCR_EXT
, gcr_ext
);
3754 /* Enable MAC Anti-Spoofing */
3755 hw
->mac
.ops
.set_mac_anti_spoofing(hw
, (adapter
->num_vfs
!= 0),
3758 /* Ensure LLDP and FC is set for Ethertype Antispoofing if we will be
3759 * calling set_ethertype_anti_spoofing for each VF in loop below
3761 if (hw
->mac
.ops
.set_ethertype_anti_spoofing
) {
3762 IXGBE_WRITE_REG(hw
, IXGBE_ETQF(IXGBE_ETQF_FILTER_LLDP
),
3763 (IXGBE_ETQF_FILTER_EN
|
3764 IXGBE_ETQF_TX_ANTISPOOF
|
3767 IXGBE_WRITE_REG(hw
, IXGBE_ETQF(IXGBE_ETQF_FILTER_FC
),
3768 (IXGBE_ETQF_FILTER_EN
|
3769 IXGBE_ETQF_TX_ANTISPOOF
|
3773 /* For VFs that have spoof checking turned off */
3774 for (i
= 0; i
< adapter
->num_vfs
; i
++) {
3775 if (!adapter
->vfinfo
[i
].spoofchk_enabled
)
3776 ixgbe_ndo_set_vf_spoofchk(adapter
->netdev
, i
, false);
3778 /* enable ethertype anti spoofing if hw supports it */
3779 if (hw
->mac
.ops
.set_ethertype_anti_spoofing
)
3780 hw
->mac
.ops
.set_ethertype_anti_spoofing(hw
, true, i
);
3782 /* Enable/Disable RSS query feature */
3783 ixgbe_ndo_set_vf_rss_query_en(adapter
->netdev
, i
,
3784 adapter
->vfinfo
[i
].rss_query_enabled
);
3788 static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter
*adapter
)
3790 struct ixgbe_hw
*hw
= &adapter
->hw
;
3791 struct net_device
*netdev
= adapter
->netdev
;
3792 int max_frame
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3793 struct ixgbe_ring
*rx_ring
;
3798 /* adjust max frame to be able to do baby jumbo for FCoE */
3799 if ((adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
) &&
3800 (max_frame
< IXGBE_FCOE_JUMBO_FRAME_SIZE
))
3801 max_frame
= IXGBE_FCOE_JUMBO_FRAME_SIZE
;
3803 #endif /* IXGBE_FCOE */
3805 /* adjust max frame to be at least the size of a standard frame */
3806 if (max_frame
< (ETH_FRAME_LEN
+ ETH_FCS_LEN
))
3807 max_frame
= (ETH_FRAME_LEN
+ ETH_FCS_LEN
);
3809 mhadd
= IXGBE_READ_REG(hw
, IXGBE_MHADD
);
3810 if (max_frame
!= (mhadd
>> IXGBE_MHADD_MFS_SHIFT
)) {
3811 mhadd
&= ~IXGBE_MHADD_MFS_MASK
;
3812 mhadd
|= max_frame
<< IXGBE_MHADD_MFS_SHIFT
;
3814 IXGBE_WRITE_REG(hw
, IXGBE_MHADD
, mhadd
);
3817 hlreg0
= IXGBE_READ_REG(hw
, IXGBE_HLREG0
);
3818 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3819 hlreg0
|= IXGBE_HLREG0_JUMBOEN
;
3820 IXGBE_WRITE_REG(hw
, IXGBE_HLREG0
, hlreg0
);
3823 * Setup the HW Rx Head and Tail Descriptor Pointers and
3824 * the Base and Length of the Rx Descriptor Ring
3826 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
3827 rx_ring
= adapter
->rx_ring
[i
];
3828 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)
3829 set_ring_rsc_enabled(rx_ring
);
3831 clear_ring_rsc_enabled(rx_ring
);
3835 static void ixgbe_setup_rdrxctl(struct ixgbe_adapter
*adapter
)
3837 struct ixgbe_hw
*hw
= &adapter
->hw
;
3838 u32 rdrxctl
= IXGBE_READ_REG(hw
, IXGBE_RDRXCTL
);
3840 switch (hw
->mac
.type
) {
3841 case ixgbe_mac_82598EB
:
3843 * For VMDq support of different descriptor types or
3844 * buffer sizes through the use of multiple SRRCTL
3845 * registers, RDRXCTL.MVMEN must be set to 1
3847 * also, the manual doesn't mention it clearly but DCA hints
3848 * will only use queue 0's tags unless this bit is set. Side
3849 * effects of setting this bit are only that SRRCTL must be
3850 * fully programmed [0..15]
3852 rdrxctl
|= IXGBE_RDRXCTL_MVMEN
;
3854 case ixgbe_mac_X550
:
3855 case ixgbe_mac_X550EM_x
:
3856 if (adapter
->num_vfs
)
3857 rdrxctl
|= IXGBE_RDRXCTL_PSP
;
3858 /* fall through for older HW */
3859 case ixgbe_mac_82599EB
:
3860 case ixgbe_mac_X540
:
3861 /* Disable RSC for ACK packets */
3862 IXGBE_WRITE_REG(hw
, IXGBE_RSCDBU
,
3863 (IXGBE_RSCDBU_RSCACKDIS
| IXGBE_READ_REG(hw
, IXGBE_RSCDBU
)));
3864 rdrxctl
&= ~IXGBE_RDRXCTL_RSCFRSTSIZE
;
3865 /* hardware requires some bits to be set by default */
3866 rdrxctl
|= (IXGBE_RDRXCTL_RSCACKC
| IXGBE_RDRXCTL_FCOE_WRFIX
);
3867 rdrxctl
|= IXGBE_RDRXCTL_CRCSTRIP
;
3870 /* We should do nothing since we don't know this hardware */
3874 IXGBE_WRITE_REG(hw
, IXGBE_RDRXCTL
, rdrxctl
);
3878 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3879 * @adapter: board private structure
3881 * Configure the Rx unit of the MAC after a reset.
3883 static void ixgbe_configure_rx(struct ixgbe_adapter
*adapter
)
3885 struct ixgbe_hw
*hw
= &adapter
->hw
;
3889 /* disable receives while setting up the descriptors */
3890 hw
->mac
.ops
.disable_rx(hw
);
3892 ixgbe_setup_psrtype(adapter
);
3893 ixgbe_setup_rdrxctl(adapter
);
3896 rfctl
= IXGBE_READ_REG(hw
, IXGBE_RFCTL
);
3897 rfctl
&= ~IXGBE_RFCTL_RSC_DIS
;
3898 if (!(adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
))
3899 rfctl
|= IXGBE_RFCTL_RSC_DIS
;
3900 IXGBE_WRITE_REG(hw
, IXGBE_RFCTL
, rfctl
);
3902 /* Program registers for the distribution of queues */
3903 ixgbe_setup_mrqc(adapter
);
3905 /* set_rx_buffer_len must be called before ring initialization */
3906 ixgbe_set_rx_buffer_len(adapter
);
3909 * Setup the HW Rx Head and Tail Descriptor Pointers and
3910 * the Base and Length of the Rx Descriptor Ring
3912 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3913 ixgbe_configure_rx_ring(adapter
, adapter
->rx_ring
[i
]);
3915 rxctrl
= IXGBE_READ_REG(hw
, IXGBE_RXCTRL
);
3916 /* disable drop enable for 82598 parts */
3917 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
3918 rxctrl
|= IXGBE_RXCTRL_DMBYPS
;
3920 /* enable all receives */
3921 rxctrl
|= IXGBE_RXCTRL_RXEN
;
3922 hw
->mac
.ops
.enable_rx_dma(hw
, rxctrl
);
3925 static int ixgbe_vlan_rx_add_vid(struct net_device
*netdev
,
3926 __be16 proto
, u16 vid
)
3928 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
3929 struct ixgbe_hw
*hw
= &adapter
->hw
;
3931 /* add VID to filter table */
3932 if (!vid
|| !(adapter
->flags2
& IXGBE_FLAG2_VLAN_PROMISC
))
3933 hw
->mac
.ops
.set_vfta(&adapter
->hw
, vid
, VMDQ_P(0), true, !!vid
);
3935 set_bit(vid
, adapter
->active_vlans
);
3940 static int ixgbe_find_vlvf_entry(struct ixgbe_hw
*hw
, u32 vlan
)
3945 /* short cut the special case */
3949 /* Search for the vlan id in the VLVF entries */
3950 for (idx
= IXGBE_VLVF_ENTRIES
; --idx
;) {
3951 vlvf
= IXGBE_READ_REG(hw
, IXGBE_VLVF(idx
));
3952 if ((vlvf
& VLAN_VID_MASK
) == vlan
)
3959 void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter
*adapter
, u32 vid
)
3961 struct ixgbe_hw
*hw
= &adapter
->hw
;
3965 idx
= ixgbe_find_vlvf_entry(hw
, vid
);
3969 /* See if any other pools are set for this VLAN filter
3970 * entry other than the PF.
3972 word
= idx
* 2 + (VMDQ_P(0) / 32);
3973 bits
= ~(1 << (VMDQ_P(0)) % 32);
3974 bits
&= IXGBE_READ_REG(hw
, IXGBE_VLVFB(word
));
3976 /* Disable the filter so this falls into the default pool. */
3977 if (!bits
&& !IXGBE_READ_REG(hw
, IXGBE_VLVFB(word
^ 1))) {
3978 if (!(adapter
->flags2
& IXGBE_FLAG2_VLAN_PROMISC
))
3979 IXGBE_WRITE_REG(hw
, IXGBE_VLVFB(word
), 0);
3980 IXGBE_WRITE_REG(hw
, IXGBE_VLVF(idx
), 0);
3984 static int ixgbe_vlan_rx_kill_vid(struct net_device
*netdev
,
3985 __be16 proto
, u16 vid
)
3987 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
3988 struct ixgbe_hw
*hw
= &adapter
->hw
;
3990 /* remove VID from filter table */
3991 if (vid
&& !(adapter
->flags2
& IXGBE_FLAG2_VLAN_PROMISC
))
3992 hw
->mac
.ops
.set_vfta(hw
, vid
, VMDQ_P(0), false, true);
3994 clear_bit(vid
, adapter
->active_vlans
);
4000 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
4001 * @adapter: driver data
4003 static void ixgbe_vlan_strip_disable(struct ixgbe_adapter
*adapter
)
4005 struct ixgbe_hw
*hw
= &adapter
->hw
;
4009 switch (hw
->mac
.type
) {
4010 case ixgbe_mac_82598EB
:
4011 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
4012 vlnctrl
&= ~IXGBE_VLNCTRL_VME
;
4013 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
4015 case ixgbe_mac_82599EB
:
4016 case ixgbe_mac_X540
:
4017 case ixgbe_mac_X550
:
4018 case ixgbe_mac_X550EM_x
:
4019 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
4020 struct ixgbe_ring
*ring
= adapter
->rx_ring
[i
];
4022 if (ring
->l2_accel_priv
)
4025 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
4026 vlnctrl
&= ~IXGBE_RXDCTL_VME
;
4027 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), vlnctrl
);
4036 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
4037 * @adapter: driver data
4039 static void ixgbe_vlan_strip_enable(struct ixgbe_adapter
*adapter
)
4041 struct ixgbe_hw
*hw
= &adapter
->hw
;
4045 switch (hw
->mac
.type
) {
4046 case ixgbe_mac_82598EB
:
4047 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
4048 vlnctrl
|= IXGBE_VLNCTRL_VME
;
4049 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
4051 case ixgbe_mac_82599EB
:
4052 case ixgbe_mac_X540
:
4053 case ixgbe_mac_X550
:
4054 case ixgbe_mac_X550EM_x
:
4055 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
4056 struct ixgbe_ring
*ring
= adapter
->rx_ring
[i
];
4058 if (ring
->l2_accel_priv
)
4061 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_RXDCTL(j
));
4062 vlnctrl
|= IXGBE_RXDCTL_VME
;
4063 IXGBE_WRITE_REG(hw
, IXGBE_RXDCTL(j
), vlnctrl
);
4071 static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter
*adapter
)
4073 struct ixgbe_hw
*hw
= &adapter
->hw
;
4076 switch (hw
->mac
.type
) {
4077 case ixgbe_mac_82599EB
:
4078 case ixgbe_mac_X540
:
4079 case ixgbe_mac_X550
:
4080 case ixgbe_mac_X550EM_x
:
4082 if (adapter
->flags
& IXGBE_FLAG_VMDQ_ENABLED
)
4085 case ixgbe_mac_82598EB
:
4086 /* legacy case, we can just disable VLAN filtering */
4087 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
4088 vlnctrl
&= ~(IXGBE_VLNCTRL_VFE
| IXGBE_VLNCTRL_CFIEN
);
4089 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
4093 /* We are already in VLAN promisc, nothing to do */
4094 if (adapter
->flags2
& IXGBE_FLAG2_VLAN_PROMISC
)
4097 /* Set flag so we don't redo unnecessary work */
4098 adapter
->flags2
|= IXGBE_FLAG2_VLAN_PROMISC
;
4100 /* Add PF to all active pools */
4101 for (i
= IXGBE_VLVF_ENTRIES
; --i
;) {
4102 u32 reg_offset
= IXGBE_VLVFB(i
* 2 + VMDQ_P(0) / 32);
4103 u32 vlvfb
= IXGBE_READ_REG(hw
, reg_offset
);
4105 vlvfb
|= 1 << (VMDQ_P(0) % 32);
4106 IXGBE_WRITE_REG(hw
, reg_offset
, vlvfb
);
4109 /* Set all bits in the VLAN filter table array */
4110 for (i
= hw
->mac
.vft_size
; i
--;)
4111 IXGBE_WRITE_REG(hw
, IXGBE_VFTA(i
), ~0U);
4114 #define VFTA_BLOCK_SIZE 8
4115 static void ixgbe_scrub_vfta(struct ixgbe_adapter
*adapter
, u32 vfta_offset
)
4117 struct ixgbe_hw
*hw
= &adapter
->hw
;
4118 u32 vfta
[VFTA_BLOCK_SIZE
] = { 0 };
4119 u32 vid_start
= vfta_offset
* 32;
4120 u32 vid_end
= vid_start
+ (VFTA_BLOCK_SIZE
* 32);
4121 u32 i
, vid
, word
, bits
;
4123 for (i
= IXGBE_VLVF_ENTRIES
; --i
;) {
4124 u32 vlvf
= IXGBE_READ_REG(hw
, IXGBE_VLVF(i
));
4126 /* pull VLAN ID from VLVF */
4127 vid
= vlvf
& VLAN_VID_MASK
;
4129 /* only concern outselves with a certain range */
4130 if (vid
< vid_start
|| vid
>= vid_end
)
4134 /* record VLAN ID in VFTA */
4135 vfta
[(vid
- vid_start
) / 32] |= 1 << (vid
% 32);
4137 /* if PF is part of this then continue */
4138 if (test_bit(vid
, adapter
->active_vlans
))
4142 /* remove PF from the pool */
4143 word
= i
* 2 + VMDQ_P(0) / 32;
4144 bits
= ~(1 << (VMDQ_P(0) % 32));
4145 bits
&= IXGBE_READ_REG(hw
, IXGBE_VLVFB(word
));
4146 IXGBE_WRITE_REG(hw
, IXGBE_VLVFB(word
), bits
);
4149 /* extract values from active_vlans and write back to VFTA */
4150 for (i
= VFTA_BLOCK_SIZE
; i
--;) {
4151 vid
= (vfta_offset
+ i
) * 32;
4152 word
= vid
/ BITS_PER_LONG
;
4153 bits
= vid
% BITS_PER_LONG
;
4155 vfta
[i
] |= adapter
->active_vlans
[word
] >> bits
;
4157 IXGBE_WRITE_REG(hw
, IXGBE_VFTA(vfta_offset
+ i
), vfta
[i
]);
4161 static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter
*adapter
)
4163 struct ixgbe_hw
*hw
= &adapter
->hw
;
4166 switch (hw
->mac
.type
) {
4167 case ixgbe_mac_82599EB
:
4168 case ixgbe_mac_X540
:
4169 case ixgbe_mac_X550
:
4170 case ixgbe_mac_X550EM_x
:
4172 if (adapter
->flags
& IXGBE_FLAG_VMDQ_ENABLED
)
4175 case ixgbe_mac_82598EB
:
4176 vlnctrl
= IXGBE_READ_REG(hw
, IXGBE_VLNCTRL
);
4177 vlnctrl
&= ~IXGBE_VLNCTRL_CFIEN
;
4178 vlnctrl
|= IXGBE_VLNCTRL_VFE
;
4179 IXGBE_WRITE_REG(hw
, IXGBE_VLNCTRL
, vlnctrl
);
4183 /* We are not in VLAN promisc, nothing to do */
4184 if (!(adapter
->flags2
& IXGBE_FLAG2_VLAN_PROMISC
))
4187 /* Set flag so we don't redo unnecessary work */
4188 adapter
->flags2
&= ~IXGBE_FLAG2_VLAN_PROMISC
;
4190 for (i
= 0; i
< hw
->mac
.vft_size
; i
+= VFTA_BLOCK_SIZE
)
4191 ixgbe_scrub_vfta(adapter
, i
);
4194 static void ixgbe_restore_vlan(struct ixgbe_adapter
*adapter
)
4198 ixgbe_vlan_rx_add_vid(adapter
->netdev
, htons(ETH_P_8021Q
), 0);
4200 for_each_set_bit_from(vid
, adapter
->active_vlans
, VLAN_N_VID
)
4201 ixgbe_vlan_rx_add_vid(adapter
->netdev
, htons(ETH_P_8021Q
), vid
);
4205 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
4206 * @netdev: network interface device structure
4208 * Writes multicast address list to the MTA hash table.
4209 * Returns: -ENOMEM on failure
4210 * 0 on no addresses written
4211 * X on writing X addresses to MTA
4213 static int ixgbe_write_mc_addr_list(struct net_device
*netdev
)
4215 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4216 struct ixgbe_hw
*hw
= &adapter
->hw
;
4218 if (!netif_running(netdev
))
4221 if (hw
->mac
.ops
.update_mc_addr_list
)
4222 hw
->mac
.ops
.update_mc_addr_list(hw
, netdev
);
4226 #ifdef CONFIG_PCI_IOV
4227 ixgbe_restore_vf_multicasts(adapter
);
4230 return netdev_mc_count(netdev
);
4233 #ifdef CONFIG_PCI_IOV
4234 void ixgbe_full_sync_mac_table(struct ixgbe_adapter
*adapter
)
4236 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4237 struct ixgbe_hw
*hw
= &adapter
->hw
;
4240 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4241 mac_table
->state
&= ~IXGBE_MAC_STATE_MODIFIED
;
4243 if (mac_table
->state
& IXGBE_MAC_STATE_IN_USE
)
4244 hw
->mac
.ops
.set_rar(hw
, i
,
4249 hw
->mac
.ops
.clear_rar(hw
, i
);
4254 static void ixgbe_sync_mac_table(struct ixgbe_adapter
*adapter
)
4256 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4257 struct ixgbe_hw
*hw
= &adapter
->hw
;
4260 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4261 if (!(mac_table
->state
& IXGBE_MAC_STATE_MODIFIED
))
4264 mac_table
->state
&= ~IXGBE_MAC_STATE_MODIFIED
;
4266 if (mac_table
->state
& IXGBE_MAC_STATE_IN_USE
)
4267 hw
->mac
.ops
.set_rar(hw
, i
,
4272 hw
->mac
.ops
.clear_rar(hw
, i
);
4276 static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter
*adapter
)
4278 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4279 struct ixgbe_hw
*hw
= &adapter
->hw
;
4282 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4283 mac_table
->state
|= IXGBE_MAC_STATE_MODIFIED
;
4284 mac_table
->state
&= ~IXGBE_MAC_STATE_IN_USE
;
4287 ixgbe_sync_mac_table(adapter
);
4290 static int ixgbe_available_rars(struct ixgbe_adapter
*adapter
, u16 pool
)
4292 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4293 struct ixgbe_hw
*hw
= &adapter
->hw
;
4296 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4297 /* do not count default RAR as available */
4298 if (mac_table
->state
& IXGBE_MAC_STATE_DEFAULT
)
4301 /* only count unused and addresses that belong to us */
4302 if (mac_table
->state
& IXGBE_MAC_STATE_IN_USE
) {
4303 if (mac_table
->pool
!= pool
)
4313 /* this function destroys the first RAR entry */
4314 static void ixgbe_mac_set_default_filter(struct ixgbe_adapter
*adapter
)
4316 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4317 struct ixgbe_hw
*hw
= &adapter
->hw
;
4319 memcpy(&mac_table
->addr
, hw
->mac
.addr
, ETH_ALEN
);
4320 mac_table
->pool
= VMDQ_P(0);
4322 mac_table
->state
= IXGBE_MAC_STATE_DEFAULT
| IXGBE_MAC_STATE_IN_USE
;
4324 hw
->mac
.ops
.set_rar(hw
, 0, mac_table
->addr
, mac_table
->pool
,
4328 int ixgbe_add_mac_filter(struct ixgbe_adapter
*adapter
,
4329 const u8
*addr
, u16 pool
)
4331 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4332 struct ixgbe_hw
*hw
= &adapter
->hw
;
4335 if (is_zero_ether_addr(addr
))
4338 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4339 if (mac_table
->state
& IXGBE_MAC_STATE_IN_USE
)
4342 ether_addr_copy(mac_table
->addr
, addr
);
4343 mac_table
->pool
= pool
;
4345 mac_table
->state
|= IXGBE_MAC_STATE_MODIFIED
|
4346 IXGBE_MAC_STATE_IN_USE
;
4348 ixgbe_sync_mac_table(adapter
);
4356 int ixgbe_del_mac_filter(struct ixgbe_adapter
*adapter
,
4357 const u8
*addr
, u16 pool
)
4359 struct ixgbe_mac_addr
*mac_table
= &adapter
->mac_table
[0];
4360 struct ixgbe_hw
*hw
= &adapter
->hw
;
4363 if (is_zero_ether_addr(addr
))
4366 /* search table for addr, if found clear IN_USE flag and sync */
4367 for (i
= 0; i
< hw
->mac
.num_rar_entries
; i
++, mac_table
++) {
4368 /* we can only delete an entry if it is in use */
4369 if (!(mac_table
->state
& IXGBE_MAC_STATE_IN_USE
))
4371 /* we only care about entries that belong to the given pool */
4372 if (mac_table
->pool
!= pool
)
4374 /* we only care about a specific MAC address */
4375 if (!ether_addr_equal(addr
, mac_table
->addr
))
4378 mac_table
->state
|= IXGBE_MAC_STATE_MODIFIED
;
4379 mac_table
->state
&= ~IXGBE_MAC_STATE_IN_USE
;
4381 ixgbe_sync_mac_table(adapter
);
4389 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
4390 * @netdev: network interface device structure
4392 * Writes unicast address list to the RAR table.
4393 * Returns: -ENOMEM on failure/insufficient address space
4394 * 0 on no addresses written
4395 * X on writing X addresses to the RAR table
4397 static int ixgbe_write_uc_addr_list(struct net_device
*netdev
, int vfn
)
4399 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4402 /* return ENOMEM indicating insufficient memory for addresses */
4403 if (netdev_uc_count(netdev
) > ixgbe_available_rars(adapter
, vfn
))
4406 if (!netdev_uc_empty(netdev
)) {
4407 struct netdev_hw_addr
*ha
;
4408 netdev_for_each_uc_addr(ha
, netdev
) {
4409 ixgbe_del_mac_filter(adapter
, ha
->addr
, vfn
);
4410 ixgbe_add_mac_filter(adapter
, ha
->addr
, vfn
);
4417 static int ixgbe_uc_sync(struct net_device
*netdev
, const unsigned char *addr
)
4419 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4422 ret
= ixgbe_add_mac_filter(adapter
, addr
, VMDQ_P(0));
4424 return min_t(int, ret
, 0);
4427 static int ixgbe_uc_unsync(struct net_device
*netdev
, const unsigned char *addr
)
4429 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4431 ixgbe_del_mac_filter(adapter
, addr
, VMDQ_P(0));
4437 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
4438 * @netdev: network interface device structure
4440 * The set_rx_method entry point is called whenever the unicast/multicast
4441 * address list or the network interface flags are updated. This routine is
4442 * responsible for configuring the hardware for proper unicast, multicast and
4445 void ixgbe_set_rx_mode(struct net_device
*netdev
)
4447 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
4448 struct ixgbe_hw
*hw
= &adapter
->hw
;
4449 u32 fctrl
, vmolr
= IXGBE_VMOLR_BAM
| IXGBE_VMOLR_AUPE
;
4450 netdev_features_t features
= netdev
->features
;
4453 /* Check for Promiscuous and All Multicast modes */
4454 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
4456 /* set all bits that we expect to always be set */
4457 fctrl
&= ~IXGBE_FCTRL_SBP
; /* disable store-bad-packets */
4458 fctrl
|= IXGBE_FCTRL_BAM
;
4459 fctrl
|= IXGBE_FCTRL_DPF
; /* discard pause frames when FC enabled */
4460 fctrl
|= IXGBE_FCTRL_PMCF
;
4462 /* clear the bits we are changing the status of */
4463 fctrl
&= ~(IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
4464 if (netdev
->flags
& IFF_PROMISC
) {
4465 hw
->addr_ctrl
.user_set_promisc
= true;
4466 fctrl
|= (IXGBE_FCTRL_UPE
| IXGBE_FCTRL_MPE
);
4467 vmolr
|= IXGBE_VMOLR_MPE
;
4468 features
&= ~NETIF_F_HW_VLAN_CTAG_FILTER
;
4470 if (netdev
->flags
& IFF_ALLMULTI
) {
4471 fctrl
|= IXGBE_FCTRL_MPE
;
4472 vmolr
|= IXGBE_VMOLR_MPE
;
4474 hw
->addr_ctrl
.user_set_promisc
= false;
4478 * Write addresses to available RAR registers, if there is not
4479 * sufficient space to store all the addresses then enable
4480 * unicast promiscuous mode
4482 if (__dev_uc_sync(netdev
, ixgbe_uc_sync
, ixgbe_uc_unsync
)) {
4483 fctrl
|= IXGBE_FCTRL_UPE
;
4484 vmolr
|= IXGBE_VMOLR_ROPE
;
4487 /* Write addresses to the MTA, if the attempt fails
4488 * then we should just turn on promiscuous mode so
4489 * that we can at least receive multicast traffic
4491 count
= ixgbe_write_mc_addr_list(netdev
);
4493 fctrl
|= IXGBE_FCTRL_MPE
;
4494 vmolr
|= IXGBE_VMOLR_MPE
;
4496 vmolr
|= IXGBE_VMOLR_ROMPE
;
4499 if (hw
->mac
.type
!= ixgbe_mac_82598EB
) {
4500 vmolr
|= IXGBE_READ_REG(hw
, IXGBE_VMOLR(VMDQ_P(0))) &
4501 ~(IXGBE_VMOLR_MPE
| IXGBE_VMOLR_ROMPE
|
4503 IXGBE_WRITE_REG(hw
, IXGBE_VMOLR(VMDQ_P(0)), vmolr
);
4506 /* This is useful for sniffing bad packets. */
4507 if (features
& NETIF_F_RXALL
) {
4508 /* UPE and MPE will be handled by normal PROMISC logic
4509 * in e1000e_set_rx_mode */
4510 fctrl
|= (IXGBE_FCTRL_SBP
| /* Receive bad packets */
4511 IXGBE_FCTRL_BAM
| /* RX All Bcast Pkts */
4512 IXGBE_FCTRL_PMCF
); /* RX All MAC Ctrl Pkts */
4514 fctrl
&= ~(IXGBE_FCTRL_DPF
);
4515 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4518 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
4520 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
4521 ixgbe_vlan_strip_enable(adapter
);
4523 ixgbe_vlan_strip_disable(adapter
);
4525 if (features
& NETIF_F_HW_VLAN_CTAG_FILTER
)
4526 ixgbe_vlan_promisc_disable(adapter
);
4528 ixgbe_vlan_promisc_enable(adapter
);
4531 static void ixgbe_napi_enable_all(struct ixgbe_adapter
*adapter
)
4535 for (q_idx
= 0; q_idx
< adapter
->num_q_vectors
; q_idx
++) {
4536 ixgbe_qv_init_lock(adapter
->q_vector
[q_idx
]);
4537 napi_enable(&adapter
->q_vector
[q_idx
]->napi
);
4541 static void ixgbe_napi_disable_all(struct ixgbe_adapter
*adapter
)
4545 for (q_idx
= 0; q_idx
< adapter
->num_q_vectors
; q_idx
++) {
4546 napi_disable(&adapter
->q_vector
[q_idx
]->napi
);
4547 while (!ixgbe_qv_disable(adapter
->q_vector
[q_idx
])) {
4548 pr_info("QV %d locked\n", q_idx
);
4549 usleep_range(1000, 20000);
4554 static void ixgbe_clear_vxlan_port(struct ixgbe_adapter
*adapter
)
4556 switch (adapter
->hw
.mac
.type
) {
4557 case ixgbe_mac_X550
:
4558 case ixgbe_mac_X550EM_x
:
4559 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_VXLANCTRL
, 0);
4560 adapter
->vxlan_port
= 0;
4567 #ifdef CONFIG_IXGBE_DCB
4569 * ixgbe_configure_dcb - Configure DCB hardware
4570 * @adapter: ixgbe adapter struct
4572 * This is called by the driver on open to configure the DCB hardware.
4573 * This is also called by the gennetlink interface when reconfiguring
4576 static void ixgbe_configure_dcb(struct ixgbe_adapter
*adapter
)
4578 struct ixgbe_hw
*hw
= &adapter
->hw
;
4579 int max_frame
= adapter
->netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
4581 if (!(adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
)) {
4582 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
4583 netif_set_gso_max_size(adapter
->netdev
, 65536);
4587 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
4588 netif_set_gso_max_size(adapter
->netdev
, 32768);
4591 if (adapter
->netdev
->features
& NETIF_F_FCOE_MTU
)
4592 max_frame
= max(max_frame
, IXGBE_FCOE_JUMBO_FRAME_SIZE
);
4595 /* reconfigure the hardware */
4596 if (adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
) {
4597 ixgbe_dcb_calculate_tc_credits(hw
, &adapter
->dcb_cfg
, max_frame
,
4599 ixgbe_dcb_calculate_tc_credits(hw
, &adapter
->dcb_cfg
, max_frame
,
4601 ixgbe_dcb_hw_config(hw
, &adapter
->dcb_cfg
);
4602 } else if (adapter
->ixgbe_ieee_ets
&& adapter
->ixgbe_ieee_pfc
) {
4603 ixgbe_dcb_hw_ets(&adapter
->hw
,
4604 adapter
->ixgbe_ieee_ets
,
4606 ixgbe_dcb_hw_pfc_config(&adapter
->hw
,
4607 adapter
->ixgbe_ieee_pfc
->pfc_en
,
4608 adapter
->ixgbe_ieee_ets
->prio_tc
);
4611 /* Enable RSS Hash per TC */
4612 if (hw
->mac
.type
!= ixgbe_mac_82598EB
) {
4614 u16 rss_i
= adapter
->ring_feature
[RING_F_RSS
].indices
- 1;
4621 /* write msb to all 8 TCs in one write */
4622 IXGBE_WRITE_REG(hw
, IXGBE_RQTC
, msb
* 0x11111111);
4627 /* Additional bittime to account for IXGBE framing */
4628 #define IXGBE_ETH_FRAMING 20
4631 * ixgbe_hpbthresh - calculate high water mark for flow control
4633 * @adapter: board private structure to calculate for
4634 * @pb: packet buffer to calculate
4636 static int ixgbe_hpbthresh(struct ixgbe_adapter
*adapter
, int pb
)
4638 struct ixgbe_hw
*hw
= &adapter
->hw
;
4639 struct net_device
*dev
= adapter
->netdev
;
4640 int link
, tc
, kb
, marker
;
4643 /* Calculate max LAN frame size */
4644 tc
= link
= dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
+ IXGBE_ETH_FRAMING
;
4647 /* FCoE traffic class uses FCOE jumbo frames */
4648 if ((dev
->features
& NETIF_F_FCOE_MTU
) &&
4649 (tc
< IXGBE_FCOE_JUMBO_FRAME_SIZE
) &&
4650 (pb
== ixgbe_fcoe_get_tc(adapter
)))
4651 tc
= IXGBE_FCOE_JUMBO_FRAME_SIZE
;
4654 /* Calculate delay value for device */
4655 switch (hw
->mac
.type
) {
4656 case ixgbe_mac_X540
:
4657 case ixgbe_mac_X550
:
4658 case ixgbe_mac_X550EM_x
:
4659 dv_id
= IXGBE_DV_X540(link
, tc
);
4662 dv_id
= IXGBE_DV(link
, tc
);
4666 /* Loopback switch introduces additional latency */
4667 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
4668 dv_id
+= IXGBE_B2BT(tc
);
4670 /* Delay value is calculated in bit times convert to KB */
4671 kb
= IXGBE_BT2KB(dv_id
);
4672 rx_pba
= IXGBE_READ_REG(hw
, IXGBE_RXPBSIZE(pb
)) >> 10;
4674 marker
= rx_pba
- kb
;
4676 /* It is possible that the packet buffer is not large enough
4677 * to provide required headroom. In this case throw an error
4678 * to user and a do the best we can.
4681 e_warn(drv
, "Packet Buffer(%i) can not provide enough"
4682 "headroom to support flow control."
4683 "Decrease MTU or number of traffic classes\n", pb
);
4691 * ixgbe_lpbthresh - calculate low water mark for for flow control
4693 * @adapter: board private structure to calculate for
4694 * @pb: packet buffer to calculate
4696 static int ixgbe_lpbthresh(struct ixgbe_adapter
*adapter
, int pb
)
4698 struct ixgbe_hw
*hw
= &adapter
->hw
;
4699 struct net_device
*dev
= adapter
->netdev
;
4703 /* Calculate max LAN frame size */
4704 tc
= dev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
4707 /* FCoE traffic class uses FCOE jumbo frames */
4708 if ((dev
->features
& NETIF_F_FCOE_MTU
) &&
4709 (tc
< IXGBE_FCOE_JUMBO_FRAME_SIZE
) &&
4710 (pb
== netdev_get_prio_tc_map(dev
, adapter
->fcoe
.up
)))
4711 tc
= IXGBE_FCOE_JUMBO_FRAME_SIZE
;
4714 /* Calculate delay value for device */
4715 switch (hw
->mac
.type
) {
4716 case ixgbe_mac_X540
:
4717 case ixgbe_mac_X550
:
4718 case ixgbe_mac_X550EM_x
:
4719 dv_id
= IXGBE_LOW_DV_X540(tc
);
4722 dv_id
= IXGBE_LOW_DV(tc
);
4726 /* Delay value is calculated in bit times convert to KB */
4727 return IXGBE_BT2KB(dv_id
);
4731 * ixgbe_pbthresh_setup - calculate and setup high low water marks
4733 static void ixgbe_pbthresh_setup(struct ixgbe_adapter
*adapter
)
4735 struct ixgbe_hw
*hw
= &adapter
->hw
;
4736 int num_tc
= netdev_get_num_tc(adapter
->netdev
);
4742 for (i
= 0; i
< num_tc
; i
++) {
4743 hw
->fc
.high_water
[i
] = ixgbe_hpbthresh(adapter
, i
);
4744 hw
->fc
.low_water
[i
] = ixgbe_lpbthresh(adapter
, i
);
4746 /* Low water marks must not be larger than high water marks */
4747 if (hw
->fc
.low_water
[i
] > hw
->fc
.high_water
[i
])
4748 hw
->fc
.low_water
[i
] = 0;
4751 for (; i
< MAX_TRAFFIC_CLASS
; i
++)
4752 hw
->fc
.high_water
[i
] = 0;
4755 static void ixgbe_configure_pb(struct ixgbe_adapter
*adapter
)
4757 struct ixgbe_hw
*hw
= &adapter
->hw
;
4759 u8 tc
= netdev_get_num_tc(adapter
->netdev
);
4761 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
||
4762 adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
4763 hdrm
= 32 << adapter
->fdir_pballoc
;
4767 hw
->mac
.ops
.set_rxpba(hw
, tc
, hdrm
, PBA_STRATEGY_EQUAL
);
4768 ixgbe_pbthresh_setup(adapter
);
4771 static void ixgbe_fdir_filter_restore(struct ixgbe_adapter
*adapter
)
4773 struct ixgbe_hw
*hw
= &adapter
->hw
;
4774 struct hlist_node
*node2
;
4775 struct ixgbe_fdir_filter
*filter
;
4777 spin_lock(&adapter
->fdir_perfect_lock
);
4779 if (!hlist_empty(&adapter
->fdir_filter_list
))
4780 ixgbe_fdir_set_input_mask_82599(hw
, &adapter
->fdir_mask
);
4782 hlist_for_each_entry_safe(filter
, node2
,
4783 &adapter
->fdir_filter_list
, fdir_node
) {
4784 ixgbe_fdir_write_perfect_filter_82599(hw
,
4787 (filter
->action
== IXGBE_FDIR_DROP_QUEUE
) ?
4788 IXGBE_FDIR_DROP_QUEUE
:
4789 adapter
->rx_ring
[filter
->action
]->reg_idx
);
4792 spin_unlock(&adapter
->fdir_perfect_lock
);
4795 static void ixgbe_macvlan_set_rx_mode(struct net_device
*dev
, unsigned int pool
,
4796 struct ixgbe_adapter
*adapter
)
4798 struct ixgbe_hw
*hw
= &adapter
->hw
;
4801 /* No unicast promiscuous support for VMDQ devices. */
4802 vmolr
= IXGBE_READ_REG(hw
, IXGBE_VMOLR(pool
));
4803 vmolr
|= (IXGBE_VMOLR_ROMPE
| IXGBE_VMOLR_BAM
| IXGBE_VMOLR_AUPE
);
4805 /* clear the affected bit */
4806 vmolr
&= ~IXGBE_VMOLR_MPE
;
4808 if (dev
->flags
& IFF_ALLMULTI
) {
4809 vmolr
|= IXGBE_VMOLR_MPE
;
4811 vmolr
|= IXGBE_VMOLR_ROMPE
;
4812 hw
->mac
.ops
.update_mc_addr_list(hw
, dev
);
4814 ixgbe_write_uc_addr_list(adapter
->netdev
, pool
);
4815 IXGBE_WRITE_REG(hw
, IXGBE_VMOLR(pool
), vmolr
);
4818 static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter
*vadapter
)
4820 struct ixgbe_adapter
*adapter
= vadapter
->real_adapter
;
4821 int rss_i
= adapter
->num_rx_queues_per_pool
;
4822 struct ixgbe_hw
*hw
= &adapter
->hw
;
4823 u16 pool
= vadapter
->pool
;
4824 u32 psrtype
= IXGBE_PSRTYPE_TCPHDR
|
4825 IXGBE_PSRTYPE_UDPHDR
|
4826 IXGBE_PSRTYPE_IPV4HDR
|
4827 IXGBE_PSRTYPE_L2HDR
|
4828 IXGBE_PSRTYPE_IPV6HDR
;
4830 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
4838 IXGBE_WRITE_REG(hw
, IXGBE_PSRTYPE(VMDQ_P(pool
)), psrtype
);
4842 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
4843 * @rx_ring: ring to free buffers from
4845 static void ixgbe_clean_rx_ring(struct ixgbe_ring
*rx_ring
)
4847 struct device
*dev
= rx_ring
->dev
;
4851 /* ring already cleared, nothing to do */
4852 if (!rx_ring
->rx_buffer_info
)
4855 /* Free all the Rx ring sk_buffs */
4856 for (i
= 0; i
< rx_ring
->count
; i
++) {
4857 struct ixgbe_rx_buffer
*rx_buffer
= &rx_ring
->rx_buffer_info
[i
];
4859 if (rx_buffer
->skb
) {
4860 struct sk_buff
*skb
= rx_buffer
->skb
;
4861 if (IXGBE_CB(skb
)->page_released
)
4864 ixgbe_rx_bufsz(rx_ring
),
4867 rx_buffer
->skb
= NULL
;
4870 if (!rx_buffer
->page
)
4873 dma_unmap_page(dev
, rx_buffer
->dma
,
4874 ixgbe_rx_pg_size(rx_ring
), DMA_FROM_DEVICE
);
4875 __free_pages(rx_buffer
->page
, ixgbe_rx_pg_order(rx_ring
));
4877 rx_buffer
->page
= NULL
;
4880 size
= sizeof(struct ixgbe_rx_buffer
) * rx_ring
->count
;
4881 memset(rx_ring
->rx_buffer_info
, 0, size
);
4883 /* Zero out the descriptor ring */
4884 memset(rx_ring
->desc
, 0, rx_ring
->size
);
4886 rx_ring
->next_to_alloc
= 0;
4887 rx_ring
->next_to_clean
= 0;
4888 rx_ring
->next_to_use
= 0;
4891 static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter
*vadapter
,
4892 struct ixgbe_ring
*rx_ring
)
4894 struct ixgbe_adapter
*adapter
= vadapter
->real_adapter
;
4895 int index
= rx_ring
->queue_index
+ vadapter
->rx_base_queue
;
4897 /* shutdown specific queue receive and wait for dma to settle */
4898 ixgbe_disable_rx_queue(adapter
, rx_ring
);
4899 usleep_range(10000, 20000);
4900 ixgbe_irq_disable_queues(adapter
, ((u64
)1 << index
));
4901 ixgbe_clean_rx_ring(rx_ring
);
4902 rx_ring
->l2_accel_priv
= NULL
;
4905 static int ixgbe_fwd_ring_down(struct net_device
*vdev
,
4906 struct ixgbe_fwd_adapter
*accel
)
4908 struct ixgbe_adapter
*adapter
= accel
->real_adapter
;
4909 unsigned int rxbase
= accel
->rx_base_queue
;
4910 unsigned int txbase
= accel
->tx_base_queue
;
4913 netif_tx_stop_all_queues(vdev
);
4915 for (i
= 0; i
< adapter
->num_rx_queues_per_pool
; i
++) {
4916 ixgbe_disable_fwd_ring(accel
, adapter
->rx_ring
[rxbase
+ i
]);
4917 adapter
->rx_ring
[rxbase
+ i
]->netdev
= adapter
->netdev
;
4920 for (i
= 0; i
< adapter
->num_rx_queues_per_pool
; i
++) {
4921 adapter
->tx_ring
[txbase
+ i
]->l2_accel_priv
= NULL
;
4922 adapter
->tx_ring
[txbase
+ i
]->netdev
= adapter
->netdev
;
4929 static int ixgbe_fwd_ring_up(struct net_device
*vdev
,
4930 struct ixgbe_fwd_adapter
*accel
)
4932 struct ixgbe_adapter
*adapter
= accel
->real_adapter
;
4933 unsigned int rxbase
, txbase
, queues
;
4934 int i
, baseq
, err
= 0;
4936 if (!test_bit(accel
->pool
, &adapter
->fwd_bitmask
))
4939 baseq
= accel
->pool
* adapter
->num_rx_queues_per_pool
;
4940 netdev_dbg(vdev
, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
4941 accel
->pool
, adapter
->num_rx_pools
,
4942 baseq
, baseq
+ adapter
->num_rx_queues_per_pool
,
4943 adapter
->fwd_bitmask
);
4945 accel
->netdev
= vdev
;
4946 accel
->rx_base_queue
= rxbase
= baseq
;
4947 accel
->tx_base_queue
= txbase
= baseq
;
4949 for (i
= 0; i
< adapter
->num_rx_queues_per_pool
; i
++)
4950 ixgbe_disable_fwd_ring(accel
, adapter
->rx_ring
[rxbase
+ i
]);
4952 for (i
= 0; i
< adapter
->num_rx_queues_per_pool
; i
++) {
4953 adapter
->rx_ring
[rxbase
+ i
]->netdev
= vdev
;
4954 adapter
->rx_ring
[rxbase
+ i
]->l2_accel_priv
= accel
;
4955 ixgbe_configure_rx_ring(adapter
, adapter
->rx_ring
[rxbase
+ i
]);
4958 for (i
= 0; i
< adapter
->num_rx_queues_per_pool
; i
++) {
4959 adapter
->tx_ring
[txbase
+ i
]->netdev
= vdev
;
4960 adapter
->tx_ring
[txbase
+ i
]->l2_accel_priv
= accel
;
4963 queues
= min_t(unsigned int,
4964 adapter
->num_rx_queues_per_pool
, vdev
->num_tx_queues
);
4965 err
= netif_set_real_num_tx_queues(vdev
, queues
);
4969 err
= netif_set_real_num_rx_queues(vdev
, queues
);
4973 if (is_valid_ether_addr(vdev
->dev_addr
))
4974 ixgbe_add_mac_filter(adapter
, vdev
->dev_addr
, accel
->pool
);
4976 ixgbe_fwd_psrtype(accel
);
4977 ixgbe_macvlan_set_rx_mode(vdev
, accel
->pool
, adapter
);
4980 ixgbe_fwd_ring_down(vdev
, accel
);
4984 static void ixgbe_configure_dfwd(struct ixgbe_adapter
*adapter
)
4986 struct net_device
*upper
;
4987 struct list_head
*iter
;
4990 netdev_for_each_all_upper_dev_rcu(adapter
->netdev
, upper
, iter
) {
4991 if (netif_is_macvlan(upper
)) {
4992 struct macvlan_dev
*dfwd
= netdev_priv(upper
);
4993 struct ixgbe_fwd_adapter
*vadapter
= dfwd
->fwd_priv
;
4995 if (dfwd
->fwd_priv
) {
4996 err
= ixgbe_fwd_ring_up(upper
, vadapter
);
5004 static void ixgbe_configure(struct ixgbe_adapter
*adapter
)
5006 struct ixgbe_hw
*hw
= &adapter
->hw
;
5008 ixgbe_configure_pb(adapter
);
5009 #ifdef CONFIG_IXGBE_DCB
5010 ixgbe_configure_dcb(adapter
);
5013 * We must restore virtualization before VLANs or else
5014 * the VLVF registers will not be populated
5016 ixgbe_configure_virtualization(adapter
);
5018 ixgbe_set_rx_mode(adapter
->netdev
);
5019 ixgbe_restore_vlan(adapter
);
5021 switch (hw
->mac
.type
) {
5022 case ixgbe_mac_82599EB
:
5023 case ixgbe_mac_X540
:
5024 hw
->mac
.ops
.disable_rx_buff(hw
);
5030 if (adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
) {
5031 ixgbe_init_fdir_signature_82599(&adapter
->hw
,
5032 adapter
->fdir_pballoc
);
5033 } else if (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
) {
5034 ixgbe_init_fdir_perfect_82599(&adapter
->hw
,
5035 adapter
->fdir_pballoc
);
5036 ixgbe_fdir_filter_restore(adapter
);
5039 switch (hw
->mac
.type
) {
5040 case ixgbe_mac_82599EB
:
5041 case ixgbe_mac_X540
:
5042 hw
->mac
.ops
.enable_rx_buff(hw
);
5048 #ifdef CONFIG_IXGBE_DCA
5050 if (adapter
->flags
& IXGBE_FLAG_DCA_CAPABLE
)
5051 ixgbe_setup_dca(adapter
);
5052 #endif /* CONFIG_IXGBE_DCA */
5055 /* configure FCoE L2 filters, redirection table, and Rx control */
5056 ixgbe_configure_fcoe(adapter
);
5058 #endif /* IXGBE_FCOE */
5059 ixgbe_configure_tx(adapter
);
5060 ixgbe_configure_rx(adapter
);
5061 ixgbe_configure_dfwd(adapter
);
5065 * ixgbe_sfp_link_config - set up SFP+ link
5066 * @adapter: pointer to private adapter struct
5068 static void ixgbe_sfp_link_config(struct ixgbe_adapter
*adapter
)
5071 * We are assuming the worst case scenario here, and that
5072 * is that an SFP was inserted/removed after the reset
5073 * but before SFP detection was enabled. As such the best
5074 * solution is to just start searching as soon as we start
5076 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
5077 adapter
->flags2
|= IXGBE_FLAG2_SEARCH_FOR_SFP
;
5079 adapter
->flags2
|= IXGBE_FLAG2_SFP_NEEDS_RESET
;
5080 adapter
->sfp_poll_time
= 0;
5084 * ixgbe_non_sfp_link_config - set up non-SFP+ link
5085 * @hw: pointer to private hardware struct
5087 * Returns 0 on success, negative on failure
5089 static int ixgbe_non_sfp_link_config(struct ixgbe_hw
*hw
)
5092 bool autoneg
, link_up
= false;
5093 int ret
= IXGBE_ERR_LINK_SETUP
;
5095 if (hw
->mac
.ops
.check_link
)
5096 ret
= hw
->mac
.ops
.check_link(hw
, &speed
, &link_up
, false);
5101 speed
= hw
->phy
.autoneg_advertised
;
5102 if ((!speed
) && (hw
->mac
.ops
.get_link_capabilities
))
5103 ret
= hw
->mac
.ops
.get_link_capabilities(hw
, &speed
,
5108 if (hw
->mac
.ops
.setup_link
)
5109 ret
= hw
->mac
.ops
.setup_link(hw
, speed
, link_up
);
5114 static void ixgbe_setup_gpie(struct ixgbe_adapter
*adapter
)
5116 struct ixgbe_hw
*hw
= &adapter
->hw
;
5119 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
) {
5120 gpie
= IXGBE_GPIE_MSIX_MODE
| IXGBE_GPIE_PBA_SUPPORT
|
5122 gpie
|= IXGBE_GPIE_EIAME
;
5124 * use EIAM to auto-mask when MSI-X interrupt is asserted
5125 * this saves a register write for every interrupt
5127 switch (hw
->mac
.type
) {
5128 case ixgbe_mac_82598EB
:
5129 IXGBE_WRITE_REG(hw
, IXGBE_EIAM
, IXGBE_EICS_RTX_QUEUE
);
5131 case ixgbe_mac_82599EB
:
5132 case ixgbe_mac_X540
:
5133 case ixgbe_mac_X550
:
5134 case ixgbe_mac_X550EM_x
:
5136 IXGBE_WRITE_REG(hw
, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5137 IXGBE_WRITE_REG(hw
, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5141 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
5142 * specifically only auto mask tx and rx interrupts */
5143 IXGBE_WRITE_REG(hw
, IXGBE_EIAM
, IXGBE_EICS_RTX_QUEUE
);
5146 /* XXX: to interrupt immediately for EICS writes, enable this */
5147 /* gpie |= IXGBE_GPIE_EIMEN; */
5149 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
5150 gpie
&= ~IXGBE_GPIE_VTMODE_MASK
;
5152 switch (adapter
->ring_feature
[RING_F_VMDQ
].mask
) {
5153 case IXGBE_82599_VMDQ_8Q_MASK
:
5154 gpie
|= IXGBE_GPIE_VTMODE_16
;
5156 case IXGBE_82599_VMDQ_4Q_MASK
:
5157 gpie
|= IXGBE_GPIE_VTMODE_32
;
5160 gpie
|= IXGBE_GPIE_VTMODE_64
;
5165 /* Enable Thermal over heat sensor interrupt */
5166 if (adapter
->flags2
& IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
) {
5167 switch (adapter
->hw
.mac
.type
) {
5168 case ixgbe_mac_82599EB
:
5169 gpie
|= IXGBE_SDP0_GPIEN_8259X
;
5176 /* Enable fan failure interrupt */
5177 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
)
5178 gpie
|= IXGBE_SDP1_GPIEN(hw
);
5180 switch (hw
->mac
.type
) {
5181 case ixgbe_mac_82599EB
:
5182 gpie
|= IXGBE_SDP1_GPIEN_8259X
| IXGBE_SDP2_GPIEN_8259X
;
5184 case ixgbe_mac_X550EM_x
:
5185 gpie
|= IXGBE_SDP0_GPIEN_X540
;
5191 IXGBE_WRITE_REG(hw
, IXGBE_GPIE
, gpie
);
5194 static void ixgbe_up_complete(struct ixgbe_adapter
*adapter
)
5196 struct ixgbe_hw
*hw
= &adapter
->hw
;
5200 ixgbe_get_hw_control(adapter
);
5201 ixgbe_setup_gpie(adapter
);
5203 if (adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)
5204 ixgbe_configure_msix(adapter
);
5206 ixgbe_configure_msi_and_legacy(adapter
);
5208 /* enable the optics for 82599 SFP+ fiber */
5209 if (hw
->mac
.ops
.enable_tx_laser
)
5210 hw
->mac
.ops
.enable_tx_laser(hw
);
5212 if (hw
->phy
.ops
.set_phy_power
)
5213 hw
->phy
.ops
.set_phy_power(hw
, true);
5215 smp_mb__before_atomic();
5216 clear_bit(__IXGBE_DOWN
, &adapter
->state
);
5217 ixgbe_napi_enable_all(adapter
);
5219 if (ixgbe_is_sfp(hw
)) {
5220 ixgbe_sfp_link_config(adapter
);
5222 err
= ixgbe_non_sfp_link_config(hw
);
5224 e_err(probe
, "link_config FAILED %d\n", err
);
5227 /* clear any pending interrupts, may auto mask */
5228 IXGBE_READ_REG(hw
, IXGBE_EICR
);
5229 ixgbe_irq_enable(adapter
, true, true);
5232 * If this adapter has a fan, check to see if we had a failure
5233 * before we enabled the interrupt.
5235 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
5236 u32 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
5237 if (esdp
& IXGBE_ESDP_SDP1
)
5238 e_crit(drv
, "Fan has stopped, replace the adapter\n");
5241 /* bring the link up in the watchdog, this could race with our first
5242 * link up interrupt but shouldn't be a problem */
5243 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
5244 adapter
->link_check_timeout
= jiffies
;
5245 mod_timer(&adapter
->service_timer
, jiffies
);
5247 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
5248 ctrl_ext
= IXGBE_READ_REG(hw
, IXGBE_CTRL_EXT
);
5249 ctrl_ext
|= IXGBE_CTRL_EXT_PFRSTD
;
5250 IXGBE_WRITE_REG(hw
, IXGBE_CTRL_EXT
, ctrl_ext
);
5253 void ixgbe_reinit_locked(struct ixgbe_adapter
*adapter
)
5255 WARN_ON(in_interrupt());
5256 /* put off any impending NetWatchDogTimeout */
5257 adapter
->netdev
->trans_start
= jiffies
;
5259 while (test_and_set_bit(__IXGBE_RESETTING
, &adapter
->state
))
5260 usleep_range(1000, 2000);
5261 ixgbe_down(adapter
);
5263 * If SR-IOV enabled then wait a bit before bringing the adapter
5264 * back up to give the VFs time to respond to the reset. The
5265 * two second wait is based upon the watchdog timer cycle in
5268 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
5271 clear_bit(__IXGBE_RESETTING
, &adapter
->state
);
5274 void ixgbe_up(struct ixgbe_adapter
*adapter
)
5276 /* hardware has been reset, we need to reload some things */
5277 ixgbe_configure(adapter
);
5279 ixgbe_up_complete(adapter
);
5282 void ixgbe_reset(struct ixgbe_adapter
*adapter
)
5284 struct ixgbe_hw
*hw
= &adapter
->hw
;
5285 struct net_device
*netdev
= adapter
->netdev
;
5288 if (ixgbe_removed(hw
->hw_addr
))
5290 /* lock SFP init bit to prevent race conditions with the watchdog */
5291 while (test_and_set_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
))
5292 usleep_range(1000, 2000);
5294 /* clear all SFP and link config related flags while holding SFP_INIT */
5295 adapter
->flags2
&= ~(IXGBE_FLAG2_SEARCH_FOR_SFP
|
5296 IXGBE_FLAG2_SFP_NEEDS_RESET
);
5297 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_CONFIG
;
5299 err
= hw
->mac
.ops
.init_hw(hw
);
5302 case IXGBE_ERR_SFP_NOT_PRESENT
:
5303 case IXGBE_ERR_SFP_NOT_SUPPORTED
:
5305 case IXGBE_ERR_MASTER_REQUESTS_PENDING
:
5306 e_dev_err("master disable timed out\n");
5308 case IXGBE_ERR_EEPROM_VERSION
:
5309 /* We are running on a pre-production device, log a warning */
5310 e_dev_warn("This device is a pre-production adapter/LOM. "
5311 "Please be aware there may be issues associated with "
5312 "your hardware. If you are experiencing problems "
5313 "please contact your Intel or hardware "
5314 "representative who provided you with this "
5318 e_dev_err("Hardware Error: %d\n", err
);
5321 clear_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
);
5323 /* flush entries out of MAC table */
5324 ixgbe_flush_sw_mac_table(adapter
);
5325 __dev_uc_unsync(netdev
, NULL
);
5327 /* do not flush user set addresses */
5328 ixgbe_mac_set_default_filter(adapter
);
5330 /* update SAN MAC vmdq pool selection */
5331 if (hw
->mac
.san_mac_rar_index
)
5332 hw
->mac
.ops
.set_vmdq_san_mac(hw
, VMDQ_P(0));
5334 if (test_bit(__IXGBE_PTP_RUNNING
, &adapter
->state
))
5335 ixgbe_ptp_reset(adapter
);
5337 if (hw
->phy
.ops
.set_phy_power
) {
5338 if (!netif_running(adapter
->netdev
) && !adapter
->wol
)
5339 hw
->phy
.ops
.set_phy_power(hw
, false);
5341 hw
->phy
.ops
.set_phy_power(hw
, true);
5346 * ixgbe_clean_tx_ring - Free Tx Buffers
5347 * @tx_ring: ring to be cleaned
5349 static void ixgbe_clean_tx_ring(struct ixgbe_ring
*tx_ring
)
5351 struct ixgbe_tx_buffer
*tx_buffer_info
;
5355 /* ring already cleared, nothing to do */
5356 if (!tx_ring
->tx_buffer_info
)
5359 /* Free all the Tx ring sk_buffs */
5360 for (i
= 0; i
< tx_ring
->count
; i
++) {
5361 tx_buffer_info
= &tx_ring
->tx_buffer_info
[i
];
5362 ixgbe_unmap_and_free_tx_resource(tx_ring
, tx_buffer_info
);
5365 netdev_tx_reset_queue(txring_txq(tx_ring
));
5367 size
= sizeof(struct ixgbe_tx_buffer
) * tx_ring
->count
;
5368 memset(tx_ring
->tx_buffer_info
, 0, size
);
5370 /* Zero out the descriptor ring */
5371 memset(tx_ring
->desc
, 0, tx_ring
->size
);
5373 tx_ring
->next_to_use
= 0;
5374 tx_ring
->next_to_clean
= 0;
5378 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5379 * @adapter: board private structure
5381 static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter
*adapter
)
5385 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
5386 ixgbe_clean_rx_ring(adapter
->rx_ring
[i
]);
5390 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5391 * @adapter: board private structure
5393 static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter
*adapter
)
5397 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
5398 ixgbe_clean_tx_ring(adapter
->tx_ring
[i
]);
5401 static void ixgbe_fdir_filter_exit(struct ixgbe_adapter
*adapter
)
5403 struct hlist_node
*node2
;
5404 struct ixgbe_fdir_filter
*filter
;
5406 spin_lock(&adapter
->fdir_perfect_lock
);
5408 hlist_for_each_entry_safe(filter
, node2
,
5409 &adapter
->fdir_filter_list
, fdir_node
) {
5410 hlist_del(&filter
->fdir_node
);
5413 adapter
->fdir_filter_count
= 0;
5415 spin_unlock(&adapter
->fdir_perfect_lock
);
5418 void ixgbe_down(struct ixgbe_adapter
*adapter
)
5420 struct net_device
*netdev
= adapter
->netdev
;
5421 struct ixgbe_hw
*hw
= &adapter
->hw
;
5422 struct net_device
*upper
;
5423 struct list_head
*iter
;
5426 /* signal that we are down to the interrupt handler */
5427 if (test_and_set_bit(__IXGBE_DOWN
, &adapter
->state
))
5428 return; /* do nothing if already down */
5430 /* disable receives */
5431 hw
->mac
.ops
.disable_rx(hw
);
5433 /* disable all enabled rx queues */
5434 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
5435 /* this call also flushes the previous write */
5436 ixgbe_disable_rx_queue(adapter
, adapter
->rx_ring
[i
]);
5438 usleep_range(10000, 20000);
5440 netif_tx_stop_all_queues(netdev
);
5442 /* call carrier off first to avoid false dev_watchdog timeouts */
5443 netif_carrier_off(netdev
);
5444 netif_tx_disable(netdev
);
5446 /* disable any upper devices */
5447 netdev_for_each_all_upper_dev_rcu(adapter
->netdev
, upper
, iter
) {
5448 if (netif_is_macvlan(upper
)) {
5449 struct macvlan_dev
*vlan
= netdev_priv(upper
);
5451 if (vlan
->fwd_priv
) {
5452 netif_tx_stop_all_queues(upper
);
5453 netif_carrier_off(upper
);
5454 netif_tx_disable(upper
);
5459 ixgbe_irq_disable(adapter
);
5461 ixgbe_napi_disable_all(adapter
);
5463 adapter
->flags2
&= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT
|
5464 IXGBE_FLAG2_RESET_REQUESTED
);
5465 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_UPDATE
;
5467 del_timer_sync(&adapter
->service_timer
);
5469 if (adapter
->num_vfs
) {
5470 /* Clear EITR Select mapping */
5471 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_EITRSEL
, 0);
5473 /* Mark all the VFs as inactive */
5474 for (i
= 0 ; i
< adapter
->num_vfs
; i
++)
5475 adapter
->vfinfo
[i
].clear_to_send
= false;
5477 /* ping all the active vfs to let them know we are going down */
5478 ixgbe_ping_all_vfs(adapter
);
5480 /* Disable all VFTE/VFRE TX/RX */
5481 ixgbe_disable_tx_rx(adapter
);
5484 /* disable transmits in the hardware now that interrupts are off */
5485 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
5486 u8 reg_idx
= adapter
->tx_ring
[i
]->reg_idx
;
5487 IXGBE_WRITE_REG(hw
, IXGBE_TXDCTL(reg_idx
), IXGBE_TXDCTL_SWFLSH
);
5490 /* Disable the Tx DMA engine on 82599 and later MAC */
5491 switch (hw
->mac
.type
) {
5492 case ixgbe_mac_82599EB
:
5493 case ixgbe_mac_X540
:
5494 case ixgbe_mac_X550
:
5495 case ixgbe_mac_X550EM_x
:
5496 IXGBE_WRITE_REG(hw
, IXGBE_DMATXCTL
,
5497 (IXGBE_READ_REG(hw
, IXGBE_DMATXCTL
) &
5498 ~IXGBE_DMATXCTL_TE
));
5504 if (!pci_channel_offline(adapter
->pdev
))
5505 ixgbe_reset(adapter
);
5507 /* power down the optics for 82599 SFP+ fiber */
5508 if (hw
->mac
.ops
.disable_tx_laser
)
5509 hw
->mac
.ops
.disable_tx_laser(hw
);
5511 ixgbe_clean_all_tx_rings(adapter
);
5512 ixgbe_clean_all_rx_rings(adapter
);
5516 * ixgbe_tx_timeout - Respond to a Tx Hang
5517 * @netdev: network interface device structure
5519 static void ixgbe_tx_timeout(struct net_device
*netdev
)
5521 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5523 /* Do the reset outside of interrupt context */
5524 ixgbe_tx_timeout_reset(adapter
);
5528 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5529 * @adapter: board private structure to initialize
5531 * ixgbe_sw_init initializes the Adapter private data structure.
5532 * Fields are initialized based on PCI device information and
5533 * OS network device settings (MTU size).
5535 static int ixgbe_sw_init(struct ixgbe_adapter
*adapter
)
5537 struct ixgbe_hw
*hw
= &adapter
->hw
;
5538 struct pci_dev
*pdev
= adapter
->pdev
;
5539 unsigned int rss
, fdir
;
5541 #ifdef CONFIG_IXGBE_DCB
5543 struct tc_configuration
*tc
;
5546 /* PCI config space info */
5548 hw
->vendor_id
= pdev
->vendor
;
5549 hw
->device_id
= pdev
->device
;
5550 hw
->revision_id
= pdev
->revision
;
5551 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
5552 hw
->subsystem_device_id
= pdev
->subsystem_device
;
5554 /* Set common capability flags and settings */
5555 rss
= min_t(int, ixgbe_max_rss_indices(adapter
), num_online_cpus());
5556 adapter
->ring_feature
[RING_F_RSS
].limit
= rss
;
5557 adapter
->flags2
|= IXGBE_FLAG2_RSC_CAPABLE
;
5558 adapter
->max_q_vectors
= MAX_Q_VECTORS_82599
;
5559 adapter
->atr_sample_rate
= 20;
5560 fdir
= min_t(int, IXGBE_MAX_FDIR_INDICES
, num_online_cpus());
5561 adapter
->ring_feature
[RING_F_FDIR
].limit
= fdir
;
5562 adapter
->fdir_pballoc
= IXGBE_FDIR_PBALLOC_64K
;
5563 #ifdef CONFIG_IXGBE_DCA
5564 adapter
->flags
|= IXGBE_FLAG_DCA_CAPABLE
;
5567 adapter
->flags
|= IXGBE_FLAG_FCOE_CAPABLE
;
5568 adapter
->flags
&= ~IXGBE_FLAG_FCOE_ENABLED
;
5569 #ifdef CONFIG_IXGBE_DCB
5570 /* Default traffic class to use for FCoE */
5571 adapter
->fcoe
.up
= IXGBE_FCOE_DEFTC
;
5572 #endif /* CONFIG_IXGBE_DCB */
5573 #endif /* IXGBE_FCOE */
5575 /* initialize static ixgbe jump table entries */
5576 adapter
->jump_tables
[0] = ixgbe_ipv4_fields
;
5578 adapter
->mac_table
= kzalloc(sizeof(struct ixgbe_mac_addr
) *
5579 hw
->mac
.num_rar_entries
,
5581 if (!adapter
->mac_table
)
5584 /* Set MAC specific capability flags and exceptions */
5585 switch (hw
->mac
.type
) {
5586 case ixgbe_mac_82598EB
:
5587 adapter
->flags2
&= ~IXGBE_FLAG2_RSC_CAPABLE
;
5589 if (hw
->device_id
== IXGBE_DEV_ID_82598AT
)
5590 adapter
->flags
|= IXGBE_FLAG_FAN_FAIL_CAPABLE
;
5592 adapter
->max_q_vectors
= MAX_Q_VECTORS_82598
;
5593 adapter
->ring_feature
[RING_F_FDIR
].limit
= 0;
5594 adapter
->atr_sample_rate
= 0;
5595 adapter
->fdir_pballoc
= 0;
5597 adapter
->flags
&= ~IXGBE_FLAG_FCOE_CAPABLE
;
5598 adapter
->flags
&= ~IXGBE_FLAG_FCOE_ENABLED
;
5599 #ifdef CONFIG_IXGBE_DCB
5600 adapter
->fcoe
.up
= 0;
5601 #endif /* IXGBE_DCB */
5602 #endif /* IXGBE_FCOE */
5604 case ixgbe_mac_82599EB
:
5605 if (hw
->device_id
== IXGBE_DEV_ID_82599_T3_LOM
)
5606 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
;
5608 case ixgbe_mac_X540
:
5609 fwsm
= IXGBE_READ_REG(hw
, IXGBE_FWSM(hw
));
5610 if (fwsm
& IXGBE_FWSM_TS_ENABLED
)
5611 adapter
->flags2
|= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE
;
5613 case ixgbe_mac_X550EM_x
:
5614 case ixgbe_mac_X550
:
5615 #ifdef CONFIG_IXGBE_DCA
5616 adapter
->flags
&= ~IXGBE_FLAG_DCA_CAPABLE
;
5618 #ifdef CONFIG_IXGBE_VXLAN
5619 adapter
->flags
|= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE
;
5627 /* FCoE support exists, always init the FCoE lock */
5628 spin_lock_init(&adapter
->fcoe
.lock
);
5631 /* n-tuple support exists, always init our spinlock */
5632 spin_lock_init(&adapter
->fdir_perfect_lock
);
5634 #ifdef CONFIG_IXGBE_DCB
5635 switch (hw
->mac
.type
) {
5636 case ixgbe_mac_X540
:
5637 case ixgbe_mac_X550
:
5638 case ixgbe_mac_X550EM_x
:
5639 adapter
->dcb_cfg
.num_tcs
.pg_tcs
= X540_TRAFFIC_CLASS
;
5640 adapter
->dcb_cfg
.num_tcs
.pfc_tcs
= X540_TRAFFIC_CLASS
;
5643 adapter
->dcb_cfg
.num_tcs
.pg_tcs
= MAX_TRAFFIC_CLASS
;
5644 adapter
->dcb_cfg
.num_tcs
.pfc_tcs
= MAX_TRAFFIC_CLASS
;
5648 /* Configure DCB traffic classes */
5649 for (j
= 0; j
< MAX_TRAFFIC_CLASS
; j
++) {
5650 tc
= &adapter
->dcb_cfg
.tc_config
[j
];
5651 tc
->path
[DCB_TX_CONFIG
].bwg_id
= 0;
5652 tc
->path
[DCB_TX_CONFIG
].bwg_percent
= 12 + (j
& 1);
5653 tc
->path
[DCB_RX_CONFIG
].bwg_id
= 0;
5654 tc
->path
[DCB_RX_CONFIG
].bwg_percent
= 12 + (j
& 1);
5655 tc
->dcb_pfc
= pfc_disabled
;
5658 /* Initialize default user to priority mapping, UPx->TC0 */
5659 tc
= &adapter
->dcb_cfg
.tc_config
[0];
5660 tc
->path
[DCB_TX_CONFIG
].up_to_tc_bitmap
= 0xFF;
5661 tc
->path
[DCB_RX_CONFIG
].up_to_tc_bitmap
= 0xFF;
5663 adapter
->dcb_cfg
.bw_percentage
[DCB_TX_CONFIG
][0] = 100;
5664 adapter
->dcb_cfg
.bw_percentage
[DCB_RX_CONFIG
][0] = 100;
5665 adapter
->dcb_cfg
.pfc_mode_enable
= false;
5666 adapter
->dcb_set_bitmap
= 0x00;
5667 adapter
->dcbx_cap
= DCB_CAP_DCBX_HOST
| DCB_CAP_DCBX_VER_CEE
;
5668 memcpy(&adapter
->temp_dcb_cfg
, &adapter
->dcb_cfg
,
5669 sizeof(adapter
->temp_dcb_cfg
));
5673 /* default flow control settings */
5674 hw
->fc
.requested_mode
= ixgbe_fc_full
;
5675 hw
->fc
.current_mode
= ixgbe_fc_full
; /* init for ethtool output */
5676 ixgbe_pbthresh_setup(adapter
);
5677 hw
->fc
.pause_time
= IXGBE_DEFAULT_FCPAUSE
;
5678 hw
->fc
.send_xon
= true;
5679 hw
->fc
.disable_fc_autoneg
= ixgbe_device_supports_autoneg_fc(hw
);
5681 #ifdef CONFIG_PCI_IOV
5683 e_dev_warn("Enabling SR-IOV VFs using the max_vfs module parameter is deprecated - please use the pci sysfs interface instead.\n");
5685 /* assign number of SR-IOV VFs */
5686 if (hw
->mac
.type
!= ixgbe_mac_82598EB
) {
5687 if (max_vfs
> IXGBE_MAX_VFS_DRV_LIMIT
) {
5688 adapter
->num_vfs
= 0;
5689 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
5691 adapter
->num_vfs
= max_vfs
;
5694 #endif /* CONFIG_PCI_IOV */
5696 /* enable itr by default in dynamic mode */
5697 adapter
->rx_itr_setting
= 1;
5698 adapter
->tx_itr_setting
= 1;
5700 /* set default ring sizes */
5701 adapter
->tx_ring_count
= IXGBE_DEFAULT_TXD
;
5702 adapter
->rx_ring_count
= IXGBE_DEFAULT_RXD
;
5704 /* set default work limits */
5705 adapter
->tx_work_limit
= IXGBE_DEFAULT_TX_WORK
;
5707 /* initialize eeprom parameters */
5708 if (ixgbe_init_eeprom_params_generic(hw
)) {
5709 e_dev_err("EEPROM initialization failed\n");
5713 /* PF holds first pool slot */
5714 set_bit(0, &adapter
->fwd_bitmask
);
5715 set_bit(__IXGBE_DOWN
, &adapter
->state
);
5721 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
5722 * @tx_ring: tx descriptor ring (for a specific queue) to setup
5724 * Return 0 on success, negative on failure
5726 int ixgbe_setup_tx_resources(struct ixgbe_ring
*tx_ring
)
5728 struct device
*dev
= tx_ring
->dev
;
5729 int orig_node
= dev_to_node(dev
);
5733 size
= sizeof(struct ixgbe_tx_buffer
) * tx_ring
->count
;
5735 if (tx_ring
->q_vector
)
5736 ring_node
= tx_ring
->q_vector
->numa_node
;
5738 tx_ring
->tx_buffer_info
= vzalloc_node(size
, ring_node
);
5739 if (!tx_ring
->tx_buffer_info
)
5740 tx_ring
->tx_buffer_info
= vzalloc(size
);
5741 if (!tx_ring
->tx_buffer_info
)
5744 u64_stats_init(&tx_ring
->syncp
);
5746 /* round up to nearest 4K */
5747 tx_ring
->size
= tx_ring
->count
* sizeof(union ixgbe_adv_tx_desc
);
5748 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
5750 set_dev_node(dev
, ring_node
);
5751 tx_ring
->desc
= dma_alloc_coherent(dev
,
5755 set_dev_node(dev
, orig_node
);
5757 tx_ring
->desc
= dma_alloc_coherent(dev
, tx_ring
->size
,
5758 &tx_ring
->dma
, GFP_KERNEL
);
5762 tx_ring
->next_to_use
= 0;
5763 tx_ring
->next_to_clean
= 0;
5767 vfree(tx_ring
->tx_buffer_info
);
5768 tx_ring
->tx_buffer_info
= NULL
;
5769 dev_err(dev
, "Unable to allocate memory for the Tx descriptor ring\n");
5774 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5775 * @adapter: board private structure
5777 * If this function returns with an error, then it's possible one or
5778 * more of the rings is populated (while the rest are not). It is the
5779 * callers duty to clean those orphaned rings.
5781 * Return 0 on success, negative on failure
5783 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter
*adapter
)
5787 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
5788 err
= ixgbe_setup_tx_resources(adapter
->tx_ring
[i
]);
5792 e_err(probe
, "Allocation for Tx Queue %u failed\n", i
);
5798 /* rewind the index freeing the rings as we go */
5800 ixgbe_free_tx_resources(adapter
->tx_ring
[i
]);
5805 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
5806 * @rx_ring: rx descriptor ring (for a specific queue) to setup
5808 * Returns 0 on success, negative on failure
5810 int ixgbe_setup_rx_resources(struct ixgbe_ring
*rx_ring
)
5812 struct device
*dev
= rx_ring
->dev
;
5813 int orig_node
= dev_to_node(dev
);
5817 size
= sizeof(struct ixgbe_rx_buffer
) * rx_ring
->count
;
5819 if (rx_ring
->q_vector
)
5820 ring_node
= rx_ring
->q_vector
->numa_node
;
5822 rx_ring
->rx_buffer_info
= vzalloc_node(size
, ring_node
);
5823 if (!rx_ring
->rx_buffer_info
)
5824 rx_ring
->rx_buffer_info
= vzalloc(size
);
5825 if (!rx_ring
->rx_buffer_info
)
5828 u64_stats_init(&rx_ring
->syncp
);
5830 /* Round up to nearest 4K */
5831 rx_ring
->size
= rx_ring
->count
* sizeof(union ixgbe_adv_rx_desc
);
5832 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
5834 set_dev_node(dev
, ring_node
);
5835 rx_ring
->desc
= dma_alloc_coherent(dev
,
5839 set_dev_node(dev
, orig_node
);
5841 rx_ring
->desc
= dma_alloc_coherent(dev
, rx_ring
->size
,
5842 &rx_ring
->dma
, GFP_KERNEL
);
5846 rx_ring
->next_to_clean
= 0;
5847 rx_ring
->next_to_use
= 0;
5851 vfree(rx_ring
->rx_buffer_info
);
5852 rx_ring
->rx_buffer_info
= NULL
;
5853 dev_err(dev
, "Unable to allocate memory for the Rx descriptor ring\n");
5858 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5859 * @adapter: board private structure
5861 * If this function returns with an error, then it's possible one or
5862 * more of the rings is populated (while the rest are not). It is the
5863 * callers duty to clean those orphaned rings.
5865 * Return 0 on success, negative on failure
5867 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter
*adapter
)
5871 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
5872 err
= ixgbe_setup_rx_resources(adapter
->rx_ring
[i
]);
5876 e_err(probe
, "Allocation for Rx Queue %u failed\n", i
);
5881 err
= ixgbe_setup_fcoe_ddp_resources(adapter
);
5886 /* rewind the index freeing the rings as we go */
5888 ixgbe_free_rx_resources(adapter
->rx_ring
[i
]);
5893 * ixgbe_free_tx_resources - Free Tx Resources per Queue
5894 * @tx_ring: Tx descriptor ring for a specific queue
5896 * Free all transmit software resources
5898 void ixgbe_free_tx_resources(struct ixgbe_ring
*tx_ring
)
5900 ixgbe_clean_tx_ring(tx_ring
);
5902 vfree(tx_ring
->tx_buffer_info
);
5903 tx_ring
->tx_buffer_info
= NULL
;
5905 /* if not set, then don't free */
5909 dma_free_coherent(tx_ring
->dev
, tx_ring
->size
,
5910 tx_ring
->desc
, tx_ring
->dma
);
5912 tx_ring
->desc
= NULL
;
5916 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5917 * @adapter: board private structure
5919 * Free all transmit software resources
5921 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter
*adapter
)
5925 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
5926 if (adapter
->tx_ring
[i
]->desc
)
5927 ixgbe_free_tx_resources(adapter
->tx_ring
[i
]);
5931 * ixgbe_free_rx_resources - Free Rx Resources
5932 * @rx_ring: ring to clean the resources from
5934 * Free all receive software resources
5936 void ixgbe_free_rx_resources(struct ixgbe_ring
*rx_ring
)
5938 ixgbe_clean_rx_ring(rx_ring
);
5940 vfree(rx_ring
->rx_buffer_info
);
5941 rx_ring
->rx_buffer_info
= NULL
;
5943 /* if not set, then don't free */
5947 dma_free_coherent(rx_ring
->dev
, rx_ring
->size
,
5948 rx_ring
->desc
, rx_ring
->dma
);
5950 rx_ring
->desc
= NULL
;
5954 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5955 * @adapter: board private structure
5957 * Free all receive software resources
5959 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter
*adapter
)
5964 ixgbe_free_fcoe_ddp_resources(adapter
);
5967 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
5968 if (adapter
->rx_ring
[i
]->desc
)
5969 ixgbe_free_rx_resources(adapter
->rx_ring
[i
]);
5973 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5974 * @netdev: network interface device structure
5975 * @new_mtu: new value for maximum frame size
5977 * Returns 0 on success, negative on failure
5979 static int ixgbe_change_mtu(struct net_device
*netdev
, int new_mtu
)
5981 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
5982 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
5984 /* MTU < 68 is an error and causes problems on some kernels */
5985 if ((new_mtu
< 68) || (max_frame
> IXGBE_MAX_JUMBO_FRAME_SIZE
))
5989 * For 82599EB we cannot allow legacy VFs to enable their receive
5990 * paths when MTU greater than 1500 is configured. So display a
5991 * warning that legacy VFs will be disabled.
5993 if ((adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) &&
5994 (adapter
->hw
.mac
.type
== ixgbe_mac_82599EB
) &&
5995 (max_frame
> (ETH_FRAME_LEN
+ ETH_FCS_LEN
)))
5996 e_warn(probe
, "Setting MTU > 1500 will disable legacy VFs\n");
5998 e_info(probe
, "changing MTU from %d to %d\n", netdev
->mtu
, new_mtu
);
6000 /* must set new MTU before calling down or up */
6001 netdev
->mtu
= new_mtu
;
6003 if (netif_running(netdev
))
6004 ixgbe_reinit_locked(adapter
);
6010 * ixgbe_open - Called when a network interface is made active
6011 * @netdev: network interface device structure
6013 * Returns 0 on success, negative value on failure
6015 * The open entry point is called when a network interface is made
6016 * active by the system (IFF_UP). At this point all resources needed
6017 * for transmit and receive operations are allocated, the interrupt
6018 * handler is registered with the OS, the watchdog timer is started,
6019 * and the stack is notified that the interface is ready.
6021 int ixgbe_open(struct net_device
*netdev
)
6023 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6024 struct ixgbe_hw
*hw
= &adapter
->hw
;
6027 /* disallow open during test */
6028 if (test_bit(__IXGBE_TESTING
, &adapter
->state
))
6031 netif_carrier_off(netdev
);
6033 /* allocate transmit descriptors */
6034 err
= ixgbe_setup_all_tx_resources(adapter
);
6038 /* allocate receive descriptors */
6039 err
= ixgbe_setup_all_rx_resources(adapter
);
6043 ixgbe_configure(adapter
);
6045 err
= ixgbe_request_irq(adapter
);
6049 /* Notify the stack of the actual queue counts. */
6050 if (adapter
->num_rx_pools
> 1)
6051 queues
= adapter
->num_rx_queues_per_pool
;
6053 queues
= adapter
->num_tx_queues
;
6055 err
= netif_set_real_num_tx_queues(netdev
, queues
);
6057 goto err_set_queues
;
6059 if (adapter
->num_rx_pools
> 1 &&
6060 adapter
->num_rx_queues
> IXGBE_MAX_L2A_QUEUES
)
6061 queues
= IXGBE_MAX_L2A_QUEUES
;
6063 queues
= adapter
->num_rx_queues
;
6064 err
= netif_set_real_num_rx_queues(netdev
, queues
);
6066 goto err_set_queues
;
6068 ixgbe_ptp_init(adapter
);
6070 ixgbe_up_complete(adapter
);
6072 ixgbe_clear_vxlan_port(adapter
);
6073 #ifdef CONFIG_IXGBE_VXLAN
6074 vxlan_get_rx_port(netdev
);
6080 ixgbe_free_irq(adapter
);
6082 ixgbe_free_all_rx_resources(adapter
);
6083 if (hw
->phy
.ops
.set_phy_power
&& !adapter
->wol
)
6084 hw
->phy
.ops
.set_phy_power(&adapter
->hw
, false);
6086 ixgbe_free_all_tx_resources(adapter
);
6088 ixgbe_reset(adapter
);
6093 static void ixgbe_close_suspend(struct ixgbe_adapter
*adapter
)
6095 ixgbe_ptp_suspend(adapter
);
6097 if (adapter
->hw
.phy
.ops
.enter_lplu
) {
6098 adapter
->hw
.phy
.reset_disable
= true;
6099 ixgbe_down(adapter
);
6100 adapter
->hw
.phy
.ops
.enter_lplu(&adapter
->hw
);
6101 adapter
->hw
.phy
.reset_disable
= false;
6103 ixgbe_down(adapter
);
6106 ixgbe_free_irq(adapter
);
6108 ixgbe_free_all_tx_resources(adapter
);
6109 ixgbe_free_all_rx_resources(adapter
);
6113 * ixgbe_close - Disables a network interface
6114 * @netdev: network interface device structure
6116 * Returns 0, this is not allowed to fail
6118 * The close entry point is called when an interface is de-activated
6119 * by the OS. The hardware is still under the drivers control, but
6120 * needs to be disabled. A global MAC reset is issued to stop the
6121 * hardware, and all transmit and receive resources are freed.
6123 int ixgbe_close(struct net_device
*netdev
)
6125 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
6127 ixgbe_ptp_stop(adapter
);
6129 ixgbe_close_suspend(adapter
);
6131 ixgbe_fdir_filter_exit(adapter
);
6133 ixgbe_release_hw_control(adapter
);
6139 static int ixgbe_resume(struct pci_dev
*pdev
)
6141 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
6142 struct net_device
*netdev
= adapter
->netdev
;
6145 adapter
->hw
.hw_addr
= adapter
->io_addr
;
6146 pci_set_power_state(pdev
, PCI_D0
);
6147 pci_restore_state(pdev
);
6149 * pci_restore_state clears dev->state_saved so call
6150 * pci_save_state to restore it.
6152 pci_save_state(pdev
);
6154 err
= pci_enable_device_mem(pdev
);
6156 e_dev_err("Cannot enable PCI device from suspend\n");
6159 smp_mb__before_atomic();
6160 clear_bit(__IXGBE_DISABLED
, &adapter
->state
);
6161 pci_set_master(pdev
);
6163 pci_wake_from_d3(pdev
, false);
6165 ixgbe_reset(adapter
);
6167 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
6170 err
= ixgbe_init_interrupt_scheme(adapter
);
6171 if (!err
&& netif_running(netdev
))
6172 err
= ixgbe_open(netdev
);
6179 netif_device_attach(netdev
);
6183 #endif /* CONFIG_PM */
6185 static int __ixgbe_shutdown(struct pci_dev
*pdev
, bool *enable_wake
)
6187 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
6188 struct net_device
*netdev
= adapter
->netdev
;
6189 struct ixgbe_hw
*hw
= &adapter
->hw
;
6191 u32 wufc
= adapter
->wol
;
6196 netif_device_detach(netdev
);
6199 if (netif_running(netdev
))
6200 ixgbe_close_suspend(adapter
);
6203 ixgbe_clear_interrupt_scheme(adapter
);
6206 retval
= pci_save_state(pdev
);
6211 if (hw
->mac
.ops
.stop_link_on_d3
)
6212 hw
->mac
.ops
.stop_link_on_d3(hw
);
6215 ixgbe_set_rx_mode(netdev
);
6217 /* enable the optics for 82599 SFP+ fiber as we can WoL */
6218 if (hw
->mac
.ops
.enable_tx_laser
)
6219 hw
->mac
.ops
.enable_tx_laser(hw
);
6221 /* turn on all-multi mode if wake on multicast is enabled */
6222 if (wufc
& IXGBE_WUFC_MC
) {
6223 fctrl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
6224 fctrl
|= IXGBE_FCTRL_MPE
;
6225 IXGBE_WRITE_REG(hw
, IXGBE_FCTRL
, fctrl
);
6228 ctrl
= IXGBE_READ_REG(hw
, IXGBE_CTRL
);
6229 ctrl
|= IXGBE_CTRL_GIO_DIS
;
6230 IXGBE_WRITE_REG(hw
, IXGBE_CTRL
, ctrl
);
6232 IXGBE_WRITE_REG(hw
, IXGBE_WUFC
, wufc
);
6234 IXGBE_WRITE_REG(hw
, IXGBE_WUC
, 0);
6235 IXGBE_WRITE_REG(hw
, IXGBE_WUFC
, 0);
6238 switch (hw
->mac
.type
) {
6239 case ixgbe_mac_82598EB
:
6240 pci_wake_from_d3(pdev
, false);
6242 case ixgbe_mac_82599EB
:
6243 case ixgbe_mac_X540
:
6244 case ixgbe_mac_X550
:
6245 case ixgbe_mac_X550EM_x
:
6246 pci_wake_from_d3(pdev
, !!wufc
);
6252 *enable_wake
= !!wufc
;
6253 if (hw
->phy
.ops
.set_phy_power
&& !*enable_wake
)
6254 hw
->phy
.ops
.set_phy_power(hw
, false);
6256 ixgbe_release_hw_control(adapter
);
6258 if (!test_and_set_bit(__IXGBE_DISABLED
, &adapter
->state
))
6259 pci_disable_device(pdev
);
6265 static int ixgbe_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6270 retval
= __ixgbe_shutdown(pdev
, &wake
);
6275 pci_prepare_to_sleep(pdev
);
6277 pci_wake_from_d3(pdev
, false);
6278 pci_set_power_state(pdev
, PCI_D3hot
);
6283 #endif /* CONFIG_PM */
6285 static void ixgbe_shutdown(struct pci_dev
*pdev
)
6289 __ixgbe_shutdown(pdev
, &wake
);
6291 if (system_state
== SYSTEM_POWER_OFF
) {
6292 pci_wake_from_d3(pdev
, wake
);
6293 pci_set_power_state(pdev
, PCI_D3hot
);
6298 * ixgbe_update_stats - Update the board statistics counters.
6299 * @adapter: board private structure
6301 void ixgbe_update_stats(struct ixgbe_adapter
*adapter
)
6303 struct net_device
*netdev
= adapter
->netdev
;
6304 struct ixgbe_hw
*hw
= &adapter
->hw
;
6305 struct ixgbe_hw_stats
*hwstats
= &adapter
->stats
;
6307 u32 i
, missed_rx
= 0, mpc
, bprc
, lxon
, lxoff
, xon_off_tot
;
6308 u64 non_eop_descs
= 0, restart_queue
= 0, tx_busy
= 0;
6309 u64 alloc_rx_page_failed
= 0, alloc_rx_buff_failed
= 0;
6310 u64 bytes
= 0, packets
= 0, hw_csum_rx_error
= 0;
6312 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
6313 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
6316 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
) {
6319 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
6320 rsc_count
+= adapter
->rx_ring
[i
]->rx_stats
.rsc_count
;
6321 rsc_flush
+= adapter
->rx_ring
[i
]->rx_stats
.rsc_flush
;
6323 adapter
->rsc_total_count
= rsc_count
;
6324 adapter
->rsc_total_flush
= rsc_flush
;
6327 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
6328 struct ixgbe_ring
*rx_ring
= adapter
->rx_ring
[i
];
6329 non_eop_descs
+= rx_ring
->rx_stats
.non_eop_descs
;
6330 alloc_rx_page_failed
+= rx_ring
->rx_stats
.alloc_rx_page_failed
;
6331 alloc_rx_buff_failed
+= rx_ring
->rx_stats
.alloc_rx_buff_failed
;
6332 hw_csum_rx_error
+= rx_ring
->rx_stats
.csum_err
;
6333 bytes
+= rx_ring
->stats
.bytes
;
6334 packets
+= rx_ring
->stats
.packets
;
6336 adapter
->non_eop_descs
= non_eop_descs
;
6337 adapter
->alloc_rx_page_failed
= alloc_rx_page_failed
;
6338 adapter
->alloc_rx_buff_failed
= alloc_rx_buff_failed
;
6339 adapter
->hw_csum_rx_error
= hw_csum_rx_error
;
6340 netdev
->stats
.rx_bytes
= bytes
;
6341 netdev
->stats
.rx_packets
= packets
;
6345 /* gather some stats to the adapter struct that are per queue */
6346 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
6347 struct ixgbe_ring
*tx_ring
= adapter
->tx_ring
[i
];
6348 restart_queue
+= tx_ring
->tx_stats
.restart_queue
;
6349 tx_busy
+= tx_ring
->tx_stats
.tx_busy
;
6350 bytes
+= tx_ring
->stats
.bytes
;
6351 packets
+= tx_ring
->stats
.packets
;
6353 adapter
->restart_queue
= restart_queue
;
6354 adapter
->tx_busy
= tx_busy
;
6355 netdev
->stats
.tx_bytes
= bytes
;
6356 netdev
->stats
.tx_packets
= packets
;
6358 hwstats
->crcerrs
+= IXGBE_READ_REG(hw
, IXGBE_CRCERRS
);
6360 /* 8 register reads */
6361 for (i
= 0; i
< 8; i
++) {
6362 /* for packet buffers not used, the register should read 0 */
6363 mpc
= IXGBE_READ_REG(hw
, IXGBE_MPC(i
));
6365 hwstats
->mpc
[i
] += mpc
;
6366 total_mpc
+= hwstats
->mpc
[i
];
6367 hwstats
->pxontxc
[i
] += IXGBE_READ_REG(hw
, IXGBE_PXONTXC(i
));
6368 hwstats
->pxofftxc
[i
] += IXGBE_READ_REG(hw
, IXGBE_PXOFFTXC(i
));
6369 switch (hw
->mac
.type
) {
6370 case ixgbe_mac_82598EB
:
6371 hwstats
->rnbc
[i
] += IXGBE_READ_REG(hw
, IXGBE_RNBC(i
));
6372 hwstats
->qbtc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBTC(i
));
6373 hwstats
->qbrc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBRC(i
));
6374 hwstats
->pxonrxc
[i
] +=
6375 IXGBE_READ_REG(hw
, IXGBE_PXONRXC(i
));
6377 case ixgbe_mac_82599EB
:
6378 case ixgbe_mac_X540
:
6379 case ixgbe_mac_X550
:
6380 case ixgbe_mac_X550EM_x
:
6381 hwstats
->pxonrxc
[i
] +=
6382 IXGBE_READ_REG(hw
, IXGBE_PXONRXCNT(i
));
6389 /*16 register reads */
6390 for (i
= 0; i
< 16; i
++) {
6391 hwstats
->qptc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPTC(i
));
6392 hwstats
->qprc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QPRC(i
));
6393 if ((hw
->mac
.type
== ixgbe_mac_82599EB
) ||
6394 (hw
->mac
.type
== ixgbe_mac_X540
) ||
6395 (hw
->mac
.type
== ixgbe_mac_X550
) ||
6396 (hw
->mac
.type
== ixgbe_mac_X550EM_x
)) {
6397 hwstats
->qbtc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBTC_L(i
));
6398 IXGBE_READ_REG(hw
, IXGBE_QBTC_H(i
)); /* to clear */
6399 hwstats
->qbrc
[i
] += IXGBE_READ_REG(hw
, IXGBE_QBRC_L(i
));
6400 IXGBE_READ_REG(hw
, IXGBE_QBRC_H(i
)); /* to clear */
6404 hwstats
->gprc
+= IXGBE_READ_REG(hw
, IXGBE_GPRC
);
6405 /* work around hardware counting issue */
6406 hwstats
->gprc
-= missed_rx
;
6408 ixgbe_update_xoff_received(adapter
);
6410 /* 82598 hardware only has a 32 bit counter in the high register */
6411 switch (hw
->mac
.type
) {
6412 case ixgbe_mac_82598EB
:
6413 hwstats
->lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXC
);
6414 hwstats
->gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCH
);
6415 hwstats
->gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCH
);
6416 hwstats
->tor
+= IXGBE_READ_REG(hw
, IXGBE_TORH
);
6418 case ixgbe_mac_X540
:
6419 case ixgbe_mac_X550
:
6420 case ixgbe_mac_X550EM_x
:
6421 /* OS2BMC stats are X540 and later */
6422 hwstats
->o2bgptc
+= IXGBE_READ_REG(hw
, IXGBE_O2BGPTC
);
6423 hwstats
->o2bspc
+= IXGBE_READ_REG(hw
, IXGBE_O2BSPC
);
6424 hwstats
->b2ospc
+= IXGBE_READ_REG(hw
, IXGBE_B2OSPC
);
6425 hwstats
->b2ogprc
+= IXGBE_READ_REG(hw
, IXGBE_B2OGPRC
);
6426 case ixgbe_mac_82599EB
:
6427 for (i
= 0; i
< 16; i
++)
6428 adapter
->hw_rx_no_dma_resources
+=
6429 IXGBE_READ_REG(hw
, IXGBE_QPRDC(i
));
6430 hwstats
->gorc
+= IXGBE_READ_REG(hw
, IXGBE_GORCL
);
6431 IXGBE_READ_REG(hw
, IXGBE_GORCH
); /* to clear */
6432 hwstats
->gotc
+= IXGBE_READ_REG(hw
, IXGBE_GOTCL
);
6433 IXGBE_READ_REG(hw
, IXGBE_GOTCH
); /* to clear */
6434 hwstats
->tor
+= IXGBE_READ_REG(hw
, IXGBE_TORL
);
6435 IXGBE_READ_REG(hw
, IXGBE_TORH
); /* to clear */
6436 hwstats
->lxonrxc
+= IXGBE_READ_REG(hw
, IXGBE_LXONRXCNT
);
6437 hwstats
->fdirmatch
+= IXGBE_READ_REG(hw
, IXGBE_FDIRMATCH
);
6438 hwstats
->fdirmiss
+= IXGBE_READ_REG(hw
, IXGBE_FDIRMISS
);
6440 hwstats
->fccrc
+= IXGBE_READ_REG(hw
, IXGBE_FCCRC
);
6441 hwstats
->fcoerpdc
+= IXGBE_READ_REG(hw
, IXGBE_FCOERPDC
);
6442 hwstats
->fcoeprc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEPRC
);
6443 hwstats
->fcoeptc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEPTC
);
6444 hwstats
->fcoedwrc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEDWRC
);
6445 hwstats
->fcoedwtc
+= IXGBE_READ_REG(hw
, IXGBE_FCOEDWTC
);
6446 /* Add up per cpu counters for total ddp aloc fail */
6447 if (adapter
->fcoe
.ddp_pool
) {
6448 struct ixgbe_fcoe
*fcoe
= &adapter
->fcoe
;
6449 struct ixgbe_fcoe_ddp_pool
*ddp_pool
;
6451 u64 noddp
= 0, noddp_ext_buff
= 0;
6452 for_each_possible_cpu(cpu
) {
6453 ddp_pool
= per_cpu_ptr(fcoe
->ddp_pool
, cpu
);
6454 noddp
+= ddp_pool
->noddp
;
6455 noddp_ext_buff
+= ddp_pool
->noddp_ext_buff
;
6457 hwstats
->fcoe_noddp
= noddp
;
6458 hwstats
->fcoe_noddp_ext_buff
= noddp_ext_buff
;
6460 #endif /* IXGBE_FCOE */
6465 bprc
= IXGBE_READ_REG(hw
, IXGBE_BPRC
);
6466 hwstats
->bprc
+= bprc
;
6467 hwstats
->mprc
+= IXGBE_READ_REG(hw
, IXGBE_MPRC
);
6468 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
6469 hwstats
->mprc
-= bprc
;
6470 hwstats
->roc
+= IXGBE_READ_REG(hw
, IXGBE_ROC
);
6471 hwstats
->prc64
+= IXGBE_READ_REG(hw
, IXGBE_PRC64
);
6472 hwstats
->prc127
+= IXGBE_READ_REG(hw
, IXGBE_PRC127
);
6473 hwstats
->prc255
+= IXGBE_READ_REG(hw
, IXGBE_PRC255
);
6474 hwstats
->prc511
+= IXGBE_READ_REG(hw
, IXGBE_PRC511
);
6475 hwstats
->prc1023
+= IXGBE_READ_REG(hw
, IXGBE_PRC1023
);
6476 hwstats
->prc1522
+= IXGBE_READ_REG(hw
, IXGBE_PRC1522
);
6477 hwstats
->rlec
+= IXGBE_READ_REG(hw
, IXGBE_RLEC
);
6478 lxon
= IXGBE_READ_REG(hw
, IXGBE_LXONTXC
);
6479 hwstats
->lxontxc
+= lxon
;
6480 lxoff
= IXGBE_READ_REG(hw
, IXGBE_LXOFFTXC
);
6481 hwstats
->lxofftxc
+= lxoff
;
6482 hwstats
->gptc
+= IXGBE_READ_REG(hw
, IXGBE_GPTC
);
6483 hwstats
->mptc
+= IXGBE_READ_REG(hw
, IXGBE_MPTC
);
6485 * 82598 errata - tx of flow control packets is included in tx counters
6487 xon_off_tot
= lxon
+ lxoff
;
6488 hwstats
->gptc
-= xon_off_tot
;
6489 hwstats
->mptc
-= xon_off_tot
;
6490 hwstats
->gotc
-= (xon_off_tot
* (ETH_ZLEN
+ ETH_FCS_LEN
));
6491 hwstats
->ruc
+= IXGBE_READ_REG(hw
, IXGBE_RUC
);
6492 hwstats
->rfc
+= IXGBE_READ_REG(hw
, IXGBE_RFC
);
6493 hwstats
->rjc
+= IXGBE_READ_REG(hw
, IXGBE_RJC
);
6494 hwstats
->tpr
+= IXGBE_READ_REG(hw
, IXGBE_TPR
);
6495 hwstats
->ptc64
+= IXGBE_READ_REG(hw
, IXGBE_PTC64
);
6496 hwstats
->ptc64
-= xon_off_tot
;
6497 hwstats
->ptc127
+= IXGBE_READ_REG(hw
, IXGBE_PTC127
);
6498 hwstats
->ptc255
+= IXGBE_READ_REG(hw
, IXGBE_PTC255
);
6499 hwstats
->ptc511
+= IXGBE_READ_REG(hw
, IXGBE_PTC511
);
6500 hwstats
->ptc1023
+= IXGBE_READ_REG(hw
, IXGBE_PTC1023
);
6501 hwstats
->ptc1522
+= IXGBE_READ_REG(hw
, IXGBE_PTC1522
);
6502 hwstats
->bptc
+= IXGBE_READ_REG(hw
, IXGBE_BPTC
);
6504 /* Fill out the OS statistics structure */
6505 netdev
->stats
.multicast
= hwstats
->mprc
;
6508 netdev
->stats
.rx_errors
= hwstats
->crcerrs
+ hwstats
->rlec
;
6509 netdev
->stats
.rx_dropped
= 0;
6510 netdev
->stats
.rx_length_errors
= hwstats
->rlec
;
6511 netdev
->stats
.rx_crc_errors
= hwstats
->crcerrs
;
6512 netdev
->stats
.rx_missed_errors
= total_mpc
;
6516 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
6517 * @adapter: pointer to the device adapter structure
6519 static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter
*adapter
)
6521 struct ixgbe_hw
*hw
= &adapter
->hw
;
6524 if (!(adapter
->flags2
& IXGBE_FLAG2_FDIR_REQUIRES_REINIT
))
6527 adapter
->flags2
&= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT
;
6529 /* if interface is down do nothing */
6530 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
6533 /* do nothing if we are not using signature filters */
6534 if (!(adapter
->flags
& IXGBE_FLAG_FDIR_HASH_CAPABLE
))
6537 adapter
->fdir_overflow
++;
6539 if (ixgbe_reinit_fdir_tables_82599(hw
) == 0) {
6540 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
6541 set_bit(__IXGBE_TX_FDIR_INIT_DONE
,
6542 &(adapter
->tx_ring
[i
]->state
));
6543 /* re-enable flow director interrupts */
6544 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMS_FLOW_DIR
);
6546 e_err(probe
, "failed to finish FDIR re-initialization, "
6547 "ignored adding FDIR ATR filters\n");
6552 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
6553 * @adapter: pointer to the device adapter structure
6555 * This function serves two purposes. First it strobes the interrupt lines
6556 * in order to make certain interrupts are occurring. Secondly it sets the
6557 * bits needed to check for TX hangs. As a result we should immediately
6558 * determine if a hang has occurred.
6560 static void ixgbe_check_hang_subtask(struct ixgbe_adapter
*adapter
)
6562 struct ixgbe_hw
*hw
= &adapter
->hw
;
6566 /* If we're down, removing or resetting, just bail */
6567 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
6568 test_bit(__IXGBE_REMOVING
, &adapter
->state
) ||
6569 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
6572 /* Force detection of hung controller */
6573 if (netif_carrier_ok(adapter
->netdev
)) {
6574 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
6575 set_check_for_tx_hang(adapter
->tx_ring
[i
]);
6578 if (!(adapter
->flags
& IXGBE_FLAG_MSIX_ENABLED
)) {
6580 * for legacy and MSI interrupts don't set any bits
6581 * that are enabled for EIAM, because this operation
6582 * would set *both* EIMS and EICS for any bit in EIAM
6584 IXGBE_WRITE_REG(hw
, IXGBE_EICS
,
6585 (IXGBE_EICS_TCP_TIMER
| IXGBE_EICS_OTHER
));
6587 /* get one bit for every active tx/rx interrupt vector */
6588 for (i
= 0; i
< adapter
->num_q_vectors
; i
++) {
6589 struct ixgbe_q_vector
*qv
= adapter
->q_vector
[i
];
6590 if (qv
->rx
.ring
|| qv
->tx
.ring
)
6591 eics
|= ((u64
)1 << i
);
6595 /* Cause software interrupt to ensure rings are cleaned */
6596 ixgbe_irq_rearm_queues(adapter
, eics
);
6600 * ixgbe_watchdog_update_link - update the link status
6601 * @adapter: pointer to the device adapter structure
6602 * @link_speed: pointer to a u32 to store the link_speed
6604 static void ixgbe_watchdog_update_link(struct ixgbe_adapter
*adapter
)
6606 struct ixgbe_hw
*hw
= &adapter
->hw
;
6607 u32 link_speed
= adapter
->link_speed
;
6608 bool link_up
= adapter
->link_up
;
6609 bool pfc_en
= adapter
->dcb_cfg
.pfc_mode_enable
;
6611 if (!(adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
))
6614 if (hw
->mac
.ops
.check_link
) {
6615 hw
->mac
.ops
.check_link(hw
, &link_speed
, &link_up
, false);
6617 /* always assume link is up, if no check link function */
6618 link_speed
= IXGBE_LINK_SPEED_10GB_FULL
;
6622 if (adapter
->ixgbe_ieee_pfc
)
6623 pfc_en
|= !!(adapter
->ixgbe_ieee_pfc
->pfc_en
);
6625 if (link_up
&& !((adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) && pfc_en
)) {
6626 hw
->mac
.ops
.fc_enable(hw
);
6627 ixgbe_set_rx_drop_en(adapter
);
6631 time_after(jiffies
, (adapter
->link_check_timeout
+
6632 IXGBE_TRY_LINK_TIMEOUT
))) {
6633 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_UPDATE
;
6634 IXGBE_WRITE_REG(hw
, IXGBE_EIMS
, IXGBE_EIMC_LSC
);
6635 IXGBE_WRITE_FLUSH(hw
);
6638 adapter
->link_up
= link_up
;
6639 adapter
->link_speed
= link_speed
;
6642 static void ixgbe_update_default_up(struct ixgbe_adapter
*adapter
)
6644 #ifdef CONFIG_IXGBE_DCB
6645 struct net_device
*netdev
= adapter
->netdev
;
6646 struct dcb_app app
= {
6647 .selector
= IEEE_8021QAZ_APP_SEL_ETHERTYPE
,
6652 if (adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_IEEE
)
6653 up
= dcb_ieee_getapp_mask(netdev
, &app
);
6655 adapter
->default_up
= (up
> 1) ? (ffs(up
) - 1) : 0;
6660 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6661 * print link up message
6662 * @adapter: pointer to the device adapter structure
6664 static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter
*adapter
)
6666 struct net_device
*netdev
= adapter
->netdev
;
6667 struct ixgbe_hw
*hw
= &adapter
->hw
;
6668 struct net_device
*upper
;
6669 struct list_head
*iter
;
6670 u32 link_speed
= adapter
->link_speed
;
6671 const char *speed_str
;
6672 bool flow_rx
, flow_tx
;
6674 /* only continue if link was previously down */
6675 if (netif_carrier_ok(netdev
))
6678 adapter
->flags2
&= ~IXGBE_FLAG2_SEARCH_FOR_SFP
;
6680 switch (hw
->mac
.type
) {
6681 case ixgbe_mac_82598EB
: {
6682 u32 frctl
= IXGBE_READ_REG(hw
, IXGBE_FCTRL
);
6683 u32 rmcs
= IXGBE_READ_REG(hw
, IXGBE_RMCS
);
6684 flow_rx
= !!(frctl
& IXGBE_FCTRL_RFCE
);
6685 flow_tx
= !!(rmcs
& IXGBE_RMCS_TFCE_802_3X
);
6688 case ixgbe_mac_X540
:
6689 case ixgbe_mac_X550
:
6690 case ixgbe_mac_X550EM_x
:
6691 case ixgbe_mac_82599EB
: {
6692 u32 mflcn
= IXGBE_READ_REG(hw
, IXGBE_MFLCN
);
6693 u32 fccfg
= IXGBE_READ_REG(hw
, IXGBE_FCCFG
);
6694 flow_rx
= !!(mflcn
& IXGBE_MFLCN_RFCE
);
6695 flow_tx
= !!(fccfg
& IXGBE_FCCFG_TFCE_802_3X
);
6704 adapter
->last_rx_ptp_check
= jiffies
;
6706 if (test_bit(__IXGBE_PTP_RUNNING
, &adapter
->state
))
6707 ixgbe_ptp_start_cyclecounter(adapter
);
6709 switch (link_speed
) {
6710 case IXGBE_LINK_SPEED_10GB_FULL
:
6711 speed_str
= "10 Gbps";
6713 case IXGBE_LINK_SPEED_2_5GB_FULL
:
6714 speed_str
= "2.5 Gbps";
6716 case IXGBE_LINK_SPEED_1GB_FULL
:
6717 speed_str
= "1 Gbps";
6719 case IXGBE_LINK_SPEED_100_FULL
:
6720 speed_str
= "100 Mbps";
6723 speed_str
= "unknown speed";
6726 e_info(drv
, "NIC Link is Up %s, Flow Control: %s\n", speed_str
,
6727 ((flow_rx
&& flow_tx
) ? "RX/TX" :
6729 (flow_tx
? "TX" : "None"))));
6731 netif_carrier_on(netdev
);
6732 ixgbe_check_vf_rate_limit(adapter
);
6734 /* enable transmits */
6735 netif_tx_wake_all_queues(adapter
->netdev
);
6737 /* enable any upper devices */
6739 netdev_for_each_all_upper_dev_rcu(adapter
->netdev
, upper
, iter
) {
6740 if (netif_is_macvlan(upper
)) {
6741 struct macvlan_dev
*vlan
= netdev_priv(upper
);
6744 netif_tx_wake_all_queues(upper
);
6749 /* update the default user priority for VFs */
6750 ixgbe_update_default_up(adapter
);
6752 /* ping all the active vfs to let them know link has changed */
6753 ixgbe_ping_all_vfs(adapter
);
6757 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6758 * print link down message
6759 * @adapter: pointer to the adapter structure
6761 static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter
*adapter
)
6763 struct net_device
*netdev
= adapter
->netdev
;
6764 struct ixgbe_hw
*hw
= &adapter
->hw
;
6766 adapter
->link_up
= false;
6767 adapter
->link_speed
= 0;
6769 /* only continue if link was up previously */
6770 if (!netif_carrier_ok(netdev
))
6773 /* poll for SFP+ cable when link is down */
6774 if (ixgbe_is_sfp(hw
) && hw
->mac
.type
== ixgbe_mac_82598EB
)
6775 adapter
->flags2
|= IXGBE_FLAG2_SEARCH_FOR_SFP
;
6777 if (test_bit(__IXGBE_PTP_RUNNING
, &adapter
->state
))
6778 ixgbe_ptp_start_cyclecounter(adapter
);
6780 e_info(drv
, "NIC Link is Down\n");
6781 netif_carrier_off(netdev
);
6783 /* ping all the active vfs to let them know link has changed */
6784 ixgbe_ping_all_vfs(adapter
);
6787 static bool ixgbe_ring_tx_pending(struct ixgbe_adapter
*adapter
)
6791 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
6792 struct ixgbe_ring
*tx_ring
= adapter
->tx_ring
[i
];
6794 if (tx_ring
->next_to_use
!= tx_ring
->next_to_clean
)
6801 static bool ixgbe_vf_tx_pending(struct ixgbe_adapter
*adapter
)
6803 struct ixgbe_hw
*hw
= &adapter
->hw
;
6804 struct ixgbe_ring_feature
*vmdq
= &adapter
->ring_feature
[RING_F_VMDQ
];
6805 u32 q_per_pool
= __ALIGN_MASK(1, ~vmdq
->mask
);
6809 if (!adapter
->num_vfs
)
6812 /* resetting the PF is only needed for MAC before X550 */
6813 if (hw
->mac
.type
>= ixgbe_mac_X550
)
6816 for (i
= 0; i
< adapter
->num_vfs
; i
++) {
6817 for (j
= 0; j
< q_per_pool
; j
++) {
6820 h
= IXGBE_READ_REG(hw
, IXGBE_PVFTDHN(q_per_pool
, i
, j
));
6821 t
= IXGBE_READ_REG(hw
, IXGBE_PVFTDTN(q_per_pool
, i
, j
));
6832 * ixgbe_watchdog_flush_tx - flush queues on link down
6833 * @adapter: pointer to the device adapter structure
6835 static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter
*adapter
)
6837 if (!netif_carrier_ok(adapter
->netdev
)) {
6838 if (ixgbe_ring_tx_pending(adapter
) ||
6839 ixgbe_vf_tx_pending(adapter
)) {
6840 /* We've lost link, so the controller stops DMA,
6841 * but we've got queued Tx work that's never going
6842 * to get done, so reset controller to flush Tx.
6843 * (Do the reset outside of interrupt context).
6845 e_warn(drv
, "initiating reset to clear Tx work after link loss\n");
6846 adapter
->flags2
|= IXGBE_FLAG2_RESET_REQUESTED
;
6851 #ifdef CONFIG_PCI_IOV
6852 static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter
*adapter
,
6853 struct pci_dev
*vfdev
)
6855 if (!pci_wait_for_pending_transaction(vfdev
))
6856 e_dev_warn("Issuing VFLR with pending transactions\n");
6858 e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev
));
6859 pcie_capability_set_word(vfdev
, PCI_EXP_DEVCTL
, PCI_EXP_DEVCTL_BCR_FLR
);
6864 static void ixgbe_check_for_bad_vf(struct ixgbe_adapter
*adapter
)
6866 struct ixgbe_hw
*hw
= &adapter
->hw
;
6867 struct pci_dev
*pdev
= adapter
->pdev
;
6871 if (!(netif_carrier_ok(adapter
->netdev
)))
6874 gpc
= IXGBE_READ_REG(hw
, IXGBE_TXDGPC
);
6875 if (gpc
) /* If incrementing then no need for the check below */
6877 /* Check to see if a bad DMA write target from an errant or
6878 * malicious VF has caused a PCIe error. If so then we can
6879 * issue a VFLR to the offending VF(s) and then resume without
6880 * requesting a full slot reset.
6886 /* check status reg for all VFs owned by this PF */
6887 for (vf
= 0; vf
< adapter
->num_vfs
; ++vf
) {
6888 struct pci_dev
*vfdev
= adapter
->vfinfo
[vf
].vfdev
;
6893 pci_read_config_word(vfdev
, PCI_STATUS
, &status_reg
);
6894 if (status_reg
!= IXGBE_FAILED_READ_CFG_WORD
&&
6895 status_reg
& PCI_STATUS_REC_MASTER_ABORT
)
6896 ixgbe_issue_vf_flr(adapter
, vfdev
);
6900 static void ixgbe_spoof_check(struct ixgbe_adapter
*adapter
)
6904 /* Do not perform spoof check for 82598 or if not in IOV mode */
6905 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
||
6906 adapter
->num_vfs
== 0)
6909 ssvpc
= IXGBE_READ_REG(&adapter
->hw
, IXGBE_SSVPC
);
6912 * ssvpc register is cleared on read, if zero then no
6913 * spoofed packets in the last interval.
6918 e_warn(drv
, "%u Spoofed packets detected\n", ssvpc
);
6921 static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused
*adapter
)
6926 ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused
*adapter
)
6929 #endif /* CONFIG_PCI_IOV */
6933 * ixgbe_watchdog_subtask - check and bring link up
6934 * @adapter: pointer to the device adapter structure
6936 static void ixgbe_watchdog_subtask(struct ixgbe_adapter
*adapter
)
6938 /* if interface is down, removing or resetting, do nothing */
6939 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
6940 test_bit(__IXGBE_REMOVING
, &adapter
->state
) ||
6941 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
6944 ixgbe_watchdog_update_link(adapter
);
6946 if (adapter
->link_up
)
6947 ixgbe_watchdog_link_is_up(adapter
);
6949 ixgbe_watchdog_link_is_down(adapter
);
6951 ixgbe_check_for_bad_vf(adapter
);
6952 ixgbe_spoof_check(adapter
);
6953 ixgbe_update_stats(adapter
);
6955 ixgbe_watchdog_flush_tx(adapter
);
6959 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6960 * @adapter: the ixgbe adapter structure
6962 static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter
*adapter
)
6964 struct ixgbe_hw
*hw
= &adapter
->hw
;
6967 /* not searching for SFP so there is nothing to do here */
6968 if (!(adapter
->flags2
& IXGBE_FLAG2_SEARCH_FOR_SFP
) &&
6969 !(adapter
->flags2
& IXGBE_FLAG2_SFP_NEEDS_RESET
))
6972 if (adapter
->sfp_poll_time
&&
6973 time_after(adapter
->sfp_poll_time
, jiffies
))
6974 return; /* If not yet time to poll for SFP */
6976 /* someone else is in init, wait until next service event */
6977 if (test_and_set_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
))
6980 adapter
->sfp_poll_time
= jiffies
+ IXGBE_SFP_POLL_JIFFIES
- 1;
6982 err
= hw
->phy
.ops
.identify_sfp(hw
);
6983 if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
)
6986 if (err
== IXGBE_ERR_SFP_NOT_PRESENT
) {
6987 /* If no cable is present, then we need to reset
6988 * the next time we find a good cable. */
6989 adapter
->flags2
|= IXGBE_FLAG2_SFP_NEEDS_RESET
;
6996 /* exit if reset not needed */
6997 if (!(adapter
->flags2
& IXGBE_FLAG2_SFP_NEEDS_RESET
))
7000 adapter
->flags2
&= ~IXGBE_FLAG2_SFP_NEEDS_RESET
;
7003 * A module may be identified correctly, but the EEPROM may not have
7004 * support for that module. setup_sfp() will fail in that case, so
7005 * we should not allow that module to load.
7007 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
7008 err
= hw
->phy
.ops
.reset(hw
);
7010 err
= hw
->mac
.ops
.setup_sfp(hw
);
7012 if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
)
7015 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_CONFIG
;
7016 e_info(probe
, "detected SFP+: %d\n", hw
->phy
.sfp_type
);
7019 clear_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
);
7021 if ((err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) &&
7022 (adapter
->netdev
->reg_state
== NETREG_REGISTERED
)) {
7023 e_dev_err("failed to initialize because an unsupported "
7024 "SFP+ module type was detected.\n");
7025 e_dev_err("Reload the driver after installing a "
7026 "supported module.\n");
7027 unregister_netdev(adapter
->netdev
);
7032 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
7033 * @adapter: the ixgbe adapter structure
7035 static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter
*adapter
)
7037 struct ixgbe_hw
*hw
= &adapter
->hw
;
7039 bool autoneg
= false;
7041 if (!(adapter
->flags
& IXGBE_FLAG_NEED_LINK_CONFIG
))
7044 /* someone else is in init, wait until next service event */
7045 if (test_and_set_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
))
7048 adapter
->flags
&= ~IXGBE_FLAG_NEED_LINK_CONFIG
;
7050 speed
= hw
->phy
.autoneg_advertised
;
7051 if ((!speed
) && (hw
->mac
.ops
.get_link_capabilities
)) {
7052 hw
->mac
.ops
.get_link_capabilities(hw
, &speed
, &autoneg
);
7054 /* setup the highest link when no autoneg */
7056 if (speed
& IXGBE_LINK_SPEED_10GB_FULL
)
7057 speed
= IXGBE_LINK_SPEED_10GB_FULL
;
7061 if (hw
->mac
.ops
.setup_link
)
7062 hw
->mac
.ops
.setup_link(hw
, speed
, true);
7064 adapter
->flags
|= IXGBE_FLAG_NEED_LINK_UPDATE
;
7065 adapter
->link_check_timeout
= jiffies
;
7066 clear_bit(__IXGBE_IN_SFP_INIT
, &adapter
->state
);
7070 * ixgbe_service_timer - Timer Call-back
7071 * @data: pointer to adapter cast into an unsigned long
7073 static void ixgbe_service_timer(unsigned long data
)
7075 struct ixgbe_adapter
*adapter
= (struct ixgbe_adapter
*)data
;
7076 unsigned long next_event_offset
;
7078 /* poll faster when waiting for link */
7079 if (adapter
->flags
& IXGBE_FLAG_NEED_LINK_UPDATE
)
7080 next_event_offset
= HZ
/ 10;
7082 next_event_offset
= HZ
* 2;
7084 /* Reset the timer */
7085 mod_timer(&adapter
->service_timer
, next_event_offset
+ jiffies
);
7087 ixgbe_service_event_schedule(adapter
);
7090 static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter
*adapter
)
7092 struct ixgbe_hw
*hw
= &adapter
->hw
;
7095 if (!(adapter
->flags2
& IXGBE_FLAG2_PHY_INTERRUPT
))
7098 adapter
->flags2
&= ~IXGBE_FLAG2_PHY_INTERRUPT
;
7100 if (!hw
->phy
.ops
.handle_lasi
)
7103 status
= hw
->phy
.ops
.handle_lasi(&adapter
->hw
);
7104 if (status
!= IXGBE_ERR_OVERTEMP
)
7107 e_crit(drv
, "%s\n", ixgbe_overheat_msg
);
7110 static void ixgbe_reset_subtask(struct ixgbe_adapter
*adapter
)
7112 if (!(adapter
->flags2
& IXGBE_FLAG2_RESET_REQUESTED
))
7115 adapter
->flags2
&= ~IXGBE_FLAG2_RESET_REQUESTED
;
7117 /* If we're already down, removing or resetting, just bail */
7118 if (test_bit(__IXGBE_DOWN
, &adapter
->state
) ||
7119 test_bit(__IXGBE_REMOVING
, &adapter
->state
) ||
7120 test_bit(__IXGBE_RESETTING
, &adapter
->state
))
7123 ixgbe_dump(adapter
);
7124 netdev_err(adapter
->netdev
, "Reset adapter\n");
7125 adapter
->tx_timeout_count
++;
7128 ixgbe_reinit_locked(adapter
);
7133 * ixgbe_service_task - manages and runs subtasks
7134 * @work: pointer to work_struct containing our data
7136 static void ixgbe_service_task(struct work_struct
*work
)
7138 struct ixgbe_adapter
*adapter
= container_of(work
,
7139 struct ixgbe_adapter
,
7141 if (ixgbe_removed(adapter
->hw
.hw_addr
)) {
7142 if (!test_bit(__IXGBE_DOWN
, &adapter
->state
)) {
7144 ixgbe_down(adapter
);
7147 ixgbe_service_event_complete(adapter
);
7150 #ifdef CONFIG_IXGBE_VXLAN
7151 if (adapter
->flags2
& IXGBE_FLAG2_VXLAN_REREG_NEEDED
) {
7152 adapter
->flags2
&= ~IXGBE_FLAG2_VXLAN_REREG_NEEDED
;
7153 vxlan_get_rx_port(adapter
->netdev
);
7155 #endif /* CONFIG_IXGBE_VXLAN */
7156 ixgbe_reset_subtask(adapter
);
7157 ixgbe_phy_interrupt_subtask(adapter
);
7158 ixgbe_sfp_detection_subtask(adapter
);
7159 ixgbe_sfp_link_config_subtask(adapter
);
7160 ixgbe_check_overtemp_subtask(adapter
);
7161 ixgbe_watchdog_subtask(adapter
);
7162 ixgbe_fdir_reinit_subtask(adapter
);
7163 ixgbe_check_hang_subtask(adapter
);
7165 if (test_bit(__IXGBE_PTP_RUNNING
, &adapter
->state
)) {
7166 ixgbe_ptp_overflow_check(adapter
);
7167 ixgbe_ptp_rx_hang(adapter
);
7170 ixgbe_service_event_complete(adapter
);
7173 static int ixgbe_tso(struct ixgbe_ring
*tx_ring
,
7174 struct ixgbe_tx_buffer
*first
,
7177 struct sk_buff
*skb
= first
->skb
;
7178 u32 vlan_macip_lens
, type_tucmd
;
7179 u32 mss_l4len_idx
, l4len
;
7182 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
7185 if (!skb_is_gso(skb
))
7188 err
= skb_cow_head(skb
, 0);
7192 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
7193 type_tucmd
= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
7195 if (first
->protocol
== htons(ETH_P_IP
)) {
7196 struct iphdr
*iph
= ip_hdr(skb
);
7199 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
7203 type_tucmd
|= IXGBE_ADVTXD_TUCMD_IPV4
;
7204 first
->tx_flags
|= IXGBE_TX_FLAGS_TSO
|
7205 IXGBE_TX_FLAGS_CSUM
|
7206 IXGBE_TX_FLAGS_IPV4
;
7207 } else if (skb_is_gso_v6(skb
)) {
7208 ipv6_hdr(skb
)->payload_len
= 0;
7209 tcp_hdr(skb
)->check
=
7210 ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
7211 &ipv6_hdr(skb
)->daddr
,
7213 first
->tx_flags
|= IXGBE_TX_FLAGS_TSO
|
7214 IXGBE_TX_FLAGS_CSUM
;
7217 /* compute header lengths */
7218 l4len
= tcp_hdrlen(skb
);
7219 *hdr_len
= skb_transport_offset(skb
) + l4len
;
7221 /* update gso size and bytecount with header size */
7222 first
->gso_segs
= skb_shinfo(skb
)->gso_segs
;
7223 first
->bytecount
+= (first
->gso_segs
- 1) * *hdr_len
;
7225 /* mss_l4len_id: use 0 as index for TSO */
7226 mss_l4len_idx
= l4len
<< IXGBE_ADVTXD_L4LEN_SHIFT
;
7227 mss_l4len_idx
|= skb_shinfo(skb
)->gso_size
<< IXGBE_ADVTXD_MSS_SHIFT
;
7229 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
7230 vlan_macip_lens
= skb_network_header_len(skb
);
7231 vlan_macip_lens
|= skb_network_offset(skb
) << IXGBE_ADVTXD_MACLEN_SHIFT
;
7232 vlan_macip_lens
|= first
->tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
;
7234 ixgbe_tx_ctxtdesc(tx_ring
, vlan_macip_lens
, 0, type_tucmd
,
7240 static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff
*skb
)
7242 unsigned int offset
= 0;
7244 ipv6_find_hdr(skb
, &offset
, IPPROTO_SCTP
, NULL
, NULL
);
7246 return offset
== skb_checksum_start_offset(skb
);
7249 static void ixgbe_tx_csum(struct ixgbe_ring
*tx_ring
,
7250 struct ixgbe_tx_buffer
*first
)
7252 struct sk_buff
*skb
= first
->skb
;
7253 u32 vlan_macip_lens
= 0;
7256 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
) {
7258 if (!(first
->tx_flags
& (IXGBE_TX_FLAGS_HW_VLAN
|
7259 IXGBE_TX_FLAGS_CC
)))
7264 switch (skb
->csum_offset
) {
7265 case offsetof(struct tcphdr
, check
):
7266 type_tucmd
= IXGBE_ADVTXD_TUCMD_L4T_TCP
;
7268 case offsetof(struct udphdr
, check
):
7270 case offsetof(struct sctphdr
, checksum
):
7271 /* validate that this is actually an SCTP request */
7272 if (((first
->protocol
== htons(ETH_P_IP
)) &&
7273 (ip_hdr(skb
)->protocol
== IPPROTO_SCTP
)) ||
7274 ((first
->protocol
== htons(ETH_P_IPV6
)) &&
7275 ixgbe_ipv6_csum_is_sctp(skb
))) {
7276 type_tucmd
= IXGBE_ADVTXD_TUCMD_L4T_SCTP
;
7281 skb_checksum_help(skb
);
7285 /* update TX checksum flag */
7286 first
->tx_flags
|= IXGBE_TX_FLAGS_CSUM
;
7287 vlan_macip_lens
= skb_checksum_start_offset(skb
) -
7288 skb_network_offset(skb
);
7290 /* vlan_macip_lens: MACLEN, VLAN tag */
7291 vlan_macip_lens
|= skb_network_offset(skb
) << IXGBE_ADVTXD_MACLEN_SHIFT
;
7292 vlan_macip_lens
|= first
->tx_flags
& IXGBE_TX_FLAGS_VLAN_MASK
;
7294 ixgbe_tx_ctxtdesc(tx_ring
, vlan_macip_lens
, 0, type_tucmd
, 0);
7297 #define IXGBE_SET_FLAG(_input, _flag, _result) \
7298 ((_flag <= _result) ? \
7299 ((u32)(_input & _flag) * (_result / _flag)) : \
7300 ((u32)(_input & _flag) / (_flag / _result)))
7302 static u32
ixgbe_tx_cmd_type(struct sk_buff
*skb
, u32 tx_flags
)
7304 /* set type for advanced descriptor with frame checksum insertion */
7305 u32 cmd_type
= IXGBE_ADVTXD_DTYP_DATA
|
7306 IXGBE_ADVTXD_DCMD_DEXT
|
7307 IXGBE_ADVTXD_DCMD_IFCS
;
7309 /* set HW vlan bit if vlan is present */
7310 cmd_type
|= IXGBE_SET_FLAG(tx_flags
, IXGBE_TX_FLAGS_HW_VLAN
,
7311 IXGBE_ADVTXD_DCMD_VLE
);
7313 /* set segmentation enable bits for TSO/FSO */
7314 cmd_type
|= IXGBE_SET_FLAG(tx_flags
, IXGBE_TX_FLAGS_TSO
,
7315 IXGBE_ADVTXD_DCMD_TSE
);
7317 /* set timestamp bit if present */
7318 cmd_type
|= IXGBE_SET_FLAG(tx_flags
, IXGBE_TX_FLAGS_TSTAMP
,
7319 IXGBE_ADVTXD_MAC_TSTAMP
);
7321 /* insert frame checksum */
7322 cmd_type
^= IXGBE_SET_FLAG(skb
->no_fcs
, 1, IXGBE_ADVTXD_DCMD_IFCS
);
7327 static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc
*tx_desc
,
7328 u32 tx_flags
, unsigned int paylen
)
7330 u32 olinfo_status
= paylen
<< IXGBE_ADVTXD_PAYLEN_SHIFT
;
7332 /* enable L4 checksum for TSO and TX checksum offload */
7333 olinfo_status
|= IXGBE_SET_FLAG(tx_flags
,
7334 IXGBE_TX_FLAGS_CSUM
,
7335 IXGBE_ADVTXD_POPTS_TXSM
);
7337 /* enble IPv4 checksum for TSO */
7338 olinfo_status
|= IXGBE_SET_FLAG(tx_flags
,
7339 IXGBE_TX_FLAGS_IPV4
,
7340 IXGBE_ADVTXD_POPTS_IXSM
);
7343 * Check Context must be set if Tx switch is enabled, which it
7344 * always is for case where virtual functions are running
7346 olinfo_status
|= IXGBE_SET_FLAG(tx_flags
,
7350 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
7353 static int __ixgbe_maybe_stop_tx(struct ixgbe_ring
*tx_ring
, u16 size
)
7355 netif_stop_subqueue(tx_ring
->netdev
, tx_ring
->queue_index
);
7357 /* Herbert's original patch had:
7358 * smp_mb__after_netif_stop_queue();
7359 * but since that doesn't exist yet, just open code it.
7363 /* We need to check again in a case another CPU has just
7364 * made room available.
7366 if (likely(ixgbe_desc_unused(tx_ring
) < size
))
7369 /* A reprieve! - use start_queue because it doesn't call schedule */
7370 netif_start_subqueue(tx_ring
->netdev
, tx_ring
->queue_index
);
7371 ++tx_ring
->tx_stats
.restart_queue
;
7375 static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring
*tx_ring
, u16 size
)
7377 if (likely(ixgbe_desc_unused(tx_ring
) >= size
))
7380 return __ixgbe_maybe_stop_tx(tx_ring
, size
);
7383 #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
7386 static void ixgbe_tx_map(struct ixgbe_ring
*tx_ring
,
7387 struct ixgbe_tx_buffer
*first
,
7390 struct sk_buff
*skb
= first
->skb
;
7391 struct ixgbe_tx_buffer
*tx_buffer
;
7392 union ixgbe_adv_tx_desc
*tx_desc
;
7393 struct skb_frag_struct
*frag
;
7395 unsigned int data_len
, size
;
7396 u32 tx_flags
= first
->tx_flags
;
7397 u32 cmd_type
= ixgbe_tx_cmd_type(skb
, tx_flags
);
7398 u16 i
= tx_ring
->next_to_use
;
7400 tx_desc
= IXGBE_TX_DESC(tx_ring
, i
);
7402 ixgbe_tx_olinfo_status(tx_desc
, tx_flags
, skb
->len
- hdr_len
);
7404 size
= skb_headlen(skb
);
7405 data_len
= skb
->data_len
;
7408 if (tx_flags
& IXGBE_TX_FLAGS_FCOE
) {
7409 if (data_len
< sizeof(struct fcoe_crc_eof
)) {
7410 size
-= sizeof(struct fcoe_crc_eof
) - data_len
;
7413 data_len
-= sizeof(struct fcoe_crc_eof
);
7418 dma
= dma_map_single(tx_ring
->dev
, skb
->data
, size
, DMA_TO_DEVICE
);
7422 for (frag
= &skb_shinfo(skb
)->frags
[0];; frag
++) {
7423 if (dma_mapping_error(tx_ring
->dev
, dma
))
7426 /* record length, and DMA address */
7427 dma_unmap_len_set(tx_buffer
, len
, size
);
7428 dma_unmap_addr_set(tx_buffer
, dma
, dma
);
7430 tx_desc
->read
.buffer_addr
= cpu_to_le64(dma
);
7432 while (unlikely(size
> IXGBE_MAX_DATA_PER_TXD
)) {
7433 tx_desc
->read
.cmd_type_len
=
7434 cpu_to_le32(cmd_type
^ IXGBE_MAX_DATA_PER_TXD
);
7438 if (i
== tx_ring
->count
) {
7439 tx_desc
= IXGBE_TX_DESC(tx_ring
, 0);
7442 tx_desc
->read
.olinfo_status
= 0;
7444 dma
+= IXGBE_MAX_DATA_PER_TXD
;
7445 size
-= IXGBE_MAX_DATA_PER_TXD
;
7447 tx_desc
->read
.buffer_addr
= cpu_to_le64(dma
);
7450 if (likely(!data_len
))
7453 tx_desc
->read
.cmd_type_len
= cpu_to_le32(cmd_type
^ size
);
7457 if (i
== tx_ring
->count
) {
7458 tx_desc
= IXGBE_TX_DESC(tx_ring
, 0);
7461 tx_desc
->read
.olinfo_status
= 0;
7464 size
= min_t(unsigned int, data_len
, skb_frag_size(frag
));
7466 size
= skb_frag_size(frag
);
7470 dma
= skb_frag_dma_map(tx_ring
->dev
, frag
, 0, size
,
7473 tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
7476 /* write last descriptor with RS and EOP bits */
7477 cmd_type
|= size
| IXGBE_TXD_CMD
;
7478 tx_desc
->read
.cmd_type_len
= cpu_to_le32(cmd_type
);
7480 netdev_tx_sent_queue(txring_txq(tx_ring
), first
->bytecount
);
7482 /* set the timestamp */
7483 first
->time_stamp
= jiffies
;
7486 * Force memory writes to complete before letting h/w know there
7487 * are new descriptors to fetch. (Only applicable for weak-ordered
7488 * memory model archs, such as IA-64).
7490 * We also need this memory barrier to make certain all of the
7491 * status bits have been updated before next_to_watch is written.
7495 /* set next_to_watch value indicating a packet is present */
7496 first
->next_to_watch
= tx_desc
;
7499 if (i
== tx_ring
->count
)
7502 tx_ring
->next_to_use
= i
;
7504 ixgbe_maybe_stop_tx(tx_ring
, DESC_NEEDED
);
7506 if (netif_xmit_stopped(txring_txq(tx_ring
)) || !skb
->xmit_more
) {
7507 writel(i
, tx_ring
->tail
);
7509 /* we need this if more than one processor can write to our tail
7510 * at a time, it synchronizes IO on IA64/Altix systems
7517 dev_err(tx_ring
->dev
, "TX DMA map failed\n");
7519 /* clear dma mappings for failed tx_buffer_info map */
7521 tx_buffer
= &tx_ring
->tx_buffer_info
[i
];
7522 ixgbe_unmap_and_free_tx_resource(tx_ring
, tx_buffer
);
7523 if (tx_buffer
== first
)
7530 tx_ring
->next_to_use
= i
;
7533 static void ixgbe_atr(struct ixgbe_ring
*ring
,
7534 struct ixgbe_tx_buffer
*first
)
7536 struct ixgbe_q_vector
*q_vector
= ring
->q_vector
;
7537 union ixgbe_atr_hash_dword input
= { .dword
= 0 };
7538 union ixgbe_atr_hash_dword common
= { .dword
= 0 };
7540 unsigned char *network
;
7542 struct ipv6hdr
*ipv6
;
7546 struct sk_buff
*skb
;
7550 /* if ring doesn't have a interrupt vector, cannot perform ATR */
7554 /* do nothing if sampling is disabled */
7555 if (!ring
->atr_sample_rate
)
7560 /* currently only IPv4/IPv6 with TCP is supported */
7561 if ((first
->protocol
!= htons(ETH_P_IP
)) &&
7562 (first
->protocol
!= htons(ETH_P_IPV6
)))
7565 /* snag network header to get L4 type and address */
7567 hdr
.network
= skb_network_header(skb
);
7568 #ifdef CONFIG_IXGBE_VXLAN
7569 if (skb
->encapsulation
&&
7570 first
->protocol
== htons(ETH_P_IP
) &&
7571 hdr
.ipv4
->protocol
!= IPPROTO_UDP
) {
7572 struct ixgbe_adapter
*adapter
= q_vector
->adapter
;
7574 /* verify the port is recognized as VXLAN */
7575 if (adapter
->vxlan_port
&&
7576 udp_hdr(skb
)->dest
== adapter
->vxlan_port
)
7577 hdr
.network
= skb_inner_network_header(skb
);
7579 #endif /* CONFIG_IXGBE_VXLAN */
7581 /* Currently only IPv4/IPv6 with TCP is supported */
7582 switch (hdr
.ipv4
->version
) {
7584 /* access ihl as u8 to avoid unaligned access on ia64 */
7585 hlen
= (hdr
.network
[0] & 0x0F) << 2;
7586 l4_proto
= hdr
.ipv4
->protocol
;
7589 hlen
= hdr
.network
- skb
->data
;
7590 l4_proto
= ipv6_find_hdr(skb
, &hlen
, IPPROTO_TCP
, NULL
, NULL
);
7591 hlen
-= hdr
.network
- skb
->data
;
7597 if (l4_proto
!= IPPROTO_TCP
)
7600 th
= (struct tcphdr
*)(hdr
.network
+ hlen
);
7602 /* skip this packet since the socket is closing */
7606 /* sample on all syn packets or once every atr sample count */
7607 if (!th
->syn
&& (ring
->atr_count
< ring
->atr_sample_rate
))
7610 /* reset sample count */
7611 ring
->atr_count
= 0;
7613 vlan_id
= htons(first
->tx_flags
>> IXGBE_TX_FLAGS_VLAN_SHIFT
);
7616 * src and dst are inverted, think how the receiver sees them
7618 * The input is broken into two sections, a non-compressed section
7619 * containing vm_pool, vlan_id, and flow_type. The rest of the data
7620 * is XORed together and stored in the compressed dword.
7622 input
.formatted
.vlan_id
= vlan_id
;
7625 * since src port and flex bytes occupy the same word XOR them together
7626 * and write the value to source port portion of compressed dword
7628 if (first
->tx_flags
& (IXGBE_TX_FLAGS_SW_VLAN
| IXGBE_TX_FLAGS_HW_VLAN
))
7629 common
.port
.src
^= th
->dest
^ htons(ETH_P_8021Q
);
7631 common
.port
.src
^= th
->dest
^ first
->protocol
;
7632 common
.port
.dst
^= th
->source
;
7634 switch (hdr
.ipv4
->version
) {
7636 input
.formatted
.flow_type
= IXGBE_ATR_FLOW_TYPE_TCPV4
;
7637 common
.ip
^= hdr
.ipv4
->saddr
^ hdr
.ipv4
->daddr
;
7640 input
.formatted
.flow_type
= IXGBE_ATR_FLOW_TYPE_TCPV6
;
7641 common
.ip
^= hdr
.ipv6
->saddr
.s6_addr32
[0] ^
7642 hdr
.ipv6
->saddr
.s6_addr32
[1] ^
7643 hdr
.ipv6
->saddr
.s6_addr32
[2] ^
7644 hdr
.ipv6
->saddr
.s6_addr32
[3] ^
7645 hdr
.ipv6
->daddr
.s6_addr32
[0] ^
7646 hdr
.ipv6
->daddr
.s6_addr32
[1] ^
7647 hdr
.ipv6
->daddr
.s6_addr32
[2] ^
7648 hdr
.ipv6
->daddr
.s6_addr32
[3];
7654 if (hdr
.network
!= skb_network_header(skb
))
7655 input
.formatted
.flow_type
|= IXGBE_ATR_L4TYPE_TUNNEL_MASK
;
7657 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
7658 ixgbe_fdir_add_signature_filter_82599(&q_vector
->adapter
->hw
,
7659 input
, common
, ring
->queue_index
);
7662 static u16
ixgbe_select_queue(struct net_device
*dev
, struct sk_buff
*skb
,
7663 void *accel_priv
, select_queue_fallback_t fallback
)
7665 struct ixgbe_fwd_adapter
*fwd_adapter
= accel_priv
;
7667 struct ixgbe_adapter
*adapter
;
7668 struct ixgbe_ring_feature
*f
;
7673 return skb
->queue_mapping
+ fwd_adapter
->tx_base_queue
;
7678 * only execute the code below if protocol is FCoE
7679 * or FIP and we have FCoE enabled on the adapter
7681 switch (vlan_get_protocol(skb
)) {
7682 case htons(ETH_P_FCOE
):
7683 case htons(ETH_P_FIP
):
7684 adapter
= netdev_priv(dev
);
7686 if (adapter
->flags
& IXGBE_FLAG_FCOE_ENABLED
)
7689 return fallback(dev
, skb
);
7692 f
= &adapter
->ring_feature
[RING_F_FCOE
];
7694 txq
= skb_rx_queue_recorded(skb
) ? skb_get_rx_queue(skb
) :
7697 while (txq
>= f
->indices
)
7700 return txq
+ f
->offset
;
7702 return fallback(dev
, skb
);
7706 netdev_tx_t
ixgbe_xmit_frame_ring(struct sk_buff
*skb
,
7707 struct ixgbe_adapter
*adapter
,
7708 struct ixgbe_ring
*tx_ring
)
7710 struct ixgbe_tx_buffer
*first
;
7714 u16 count
= TXD_USE_COUNT(skb_headlen(skb
));
7715 __be16 protocol
= skb
->protocol
;
7719 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
7720 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
7721 * + 2 desc gap to keep tail from touching head,
7722 * + 1 desc for context descriptor,
7723 * otherwise try next time
7725 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++)
7726 count
+= TXD_USE_COUNT(skb_shinfo(skb
)->frags
[f
].size
);
7728 if (ixgbe_maybe_stop_tx(tx_ring
, count
+ 3)) {
7729 tx_ring
->tx_stats
.tx_busy
++;
7730 return NETDEV_TX_BUSY
;
7733 /* record the location of the first descriptor for this packet */
7734 first
= &tx_ring
->tx_buffer_info
[tx_ring
->next_to_use
];
7736 first
->bytecount
= skb
->len
;
7737 first
->gso_segs
= 1;
7739 /* if we have a HW VLAN tag being added default to the HW one */
7740 if (skb_vlan_tag_present(skb
)) {
7741 tx_flags
|= skb_vlan_tag_get(skb
) << IXGBE_TX_FLAGS_VLAN_SHIFT
;
7742 tx_flags
|= IXGBE_TX_FLAGS_HW_VLAN
;
7743 /* else if it is a SW VLAN check the next protocol and store the tag */
7744 } else if (protocol
== htons(ETH_P_8021Q
)) {
7745 struct vlan_hdr
*vhdr
, _vhdr
;
7746 vhdr
= skb_header_pointer(skb
, ETH_HLEN
, sizeof(_vhdr
), &_vhdr
);
7750 tx_flags
|= ntohs(vhdr
->h_vlan_TCI
) <<
7751 IXGBE_TX_FLAGS_VLAN_SHIFT
;
7752 tx_flags
|= IXGBE_TX_FLAGS_SW_VLAN
;
7754 protocol
= vlan_get_protocol(skb
);
7756 if (unlikely(skb_shinfo(skb
)->tx_flags
& SKBTX_HW_TSTAMP
) &&
7757 adapter
->ptp_clock
&&
7758 !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS
,
7760 skb_shinfo(skb
)->tx_flags
|= SKBTX_IN_PROGRESS
;
7761 tx_flags
|= IXGBE_TX_FLAGS_TSTAMP
;
7763 /* schedule check for Tx timestamp */
7764 adapter
->ptp_tx_skb
= skb_get(skb
);
7765 adapter
->ptp_tx_start
= jiffies
;
7766 schedule_work(&adapter
->ptp_tx_work
);
7769 skb_tx_timestamp(skb
);
7771 #ifdef CONFIG_PCI_IOV
7773 * Use the l2switch_enable flag - would be false if the DMA
7774 * Tx switch had been disabled.
7776 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
)
7777 tx_flags
|= IXGBE_TX_FLAGS_CC
;
7780 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
7781 if ((adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) &&
7782 ((tx_flags
& (IXGBE_TX_FLAGS_HW_VLAN
| IXGBE_TX_FLAGS_SW_VLAN
)) ||
7783 (skb
->priority
!= TC_PRIO_CONTROL
))) {
7784 tx_flags
&= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK
;
7785 tx_flags
|= (skb
->priority
& 0x7) <<
7786 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT
;
7787 if (tx_flags
& IXGBE_TX_FLAGS_SW_VLAN
) {
7788 struct vlan_ethhdr
*vhdr
;
7790 if (skb_cow_head(skb
, 0))
7792 vhdr
= (struct vlan_ethhdr
*)skb
->data
;
7793 vhdr
->h_vlan_TCI
= htons(tx_flags
>>
7794 IXGBE_TX_FLAGS_VLAN_SHIFT
);
7796 tx_flags
|= IXGBE_TX_FLAGS_HW_VLAN
;
7800 /* record initial flags and protocol */
7801 first
->tx_flags
= tx_flags
;
7802 first
->protocol
= protocol
;
7805 /* setup tx offload for FCoE */
7806 if ((protocol
== htons(ETH_P_FCOE
)) &&
7807 (tx_ring
->netdev
->features
& (NETIF_F_FSO
| NETIF_F_FCOE_CRC
))) {
7808 tso
= ixgbe_fso(tx_ring
, first
, &hdr_len
);
7815 #endif /* IXGBE_FCOE */
7816 tso
= ixgbe_tso(tx_ring
, first
, &hdr_len
);
7820 ixgbe_tx_csum(tx_ring
, first
);
7822 /* add the ATR filter if ATR is on */
7823 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE
, &tx_ring
->state
))
7824 ixgbe_atr(tx_ring
, first
);
7828 #endif /* IXGBE_FCOE */
7829 ixgbe_tx_map(tx_ring
, first
, hdr_len
);
7831 return NETDEV_TX_OK
;
7834 dev_kfree_skb_any(first
->skb
);
7837 return NETDEV_TX_OK
;
7840 static netdev_tx_t
__ixgbe_xmit_frame(struct sk_buff
*skb
,
7841 struct net_device
*netdev
,
7842 struct ixgbe_ring
*ring
)
7844 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7845 struct ixgbe_ring
*tx_ring
;
7848 * The minimum packet size for olinfo paylen is 17 so pad the skb
7849 * in order to meet this minimum size requirement.
7851 if (skb_put_padto(skb
, 17))
7852 return NETDEV_TX_OK
;
7854 tx_ring
= ring
? ring
: adapter
->tx_ring
[skb
->queue_mapping
];
7856 return ixgbe_xmit_frame_ring(skb
, adapter
, tx_ring
);
7859 static netdev_tx_t
ixgbe_xmit_frame(struct sk_buff
*skb
,
7860 struct net_device
*netdev
)
7862 return __ixgbe_xmit_frame(skb
, netdev
, NULL
);
7866 * ixgbe_set_mac - Change the Ethernet Address of the NIC
7867 * @netdev: network interface device structure
7868 * @p: pointer to an address structure
7870 * Returns 0 on success, negative on failure
7872 static int ixgbe_set_mac(struct net_device
*netdev
, void *p
)
7874 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7875 struct ixgbe_hw
*hw
= &adapter
->hw
;
7876 struct sockaddr
*addr
= p
;
7878 if (!is_valid_ether_addr(addr
->sa_data
))
7879 return -EADDRNOTAVAIL
;
7881 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
7882 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
7884 ixgbe_mac_set_default_filter(adapter
);
7890 ixgbe_mdio_read(struct net_device
*netdev
, int prtad
, int devad
, u16 addr
)
7892 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7893 struct ixgbe_hw
*hw
= &adapter
->hw
;
7897 if (prtad
!= hw
->phy
.mdio
.prtad
)
7899 rc
= hw
->phy
.ops
.read_reg(hw
, addr
, devad
, &value
);
7905 static int ixgbe_mdio_write(struct net_device
*netdev
, int prtad
, int devad
,
7906 u16 addr
, u16 value
)
7908 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7909 struct ixgbe_hw
*hw
= &adapter
->hw
;
7911 if (prtad
!= hw
->phy
.mdio
.prtad
)
7913 return hw
->phy
.ops
.write_reg(hw
, addr
, devad
, value
);
7916 static int ixgbe_ioctl(struct net_device
*netdev
, struct ifreq
*req
, int cmd
)
7918 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7922 return ixgbe_ptp_set_ts_config(adapter
, req
);
7924 return ixgbe_ptp_get_ts_config(adapter
, req
);
7926 return mdio_mii_ioctl(&adapter
->hw
.phy
.mdio
, if_mii(req
), cmd
);
7931 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
7933 * @netdev: network interface device structure
7935 * Returns non-zero on failure
7937 static int ixgbe_add_sanmac_netdev(struct net_device
*dev
)
7940 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
7941 struct ixgbe_hw
*hw
= &adapter
->hw
;
7943 if (is_valid_ether_addr(hw
->mac
.san_addr
)) {
7945 err
= dev_addr_add(dev
, hw
->mac
.san_addr
, NETDEV_HW_ADDR_T_SAN
);
7948 /* update SAN MAC vmdq pool selection */
7949 hw
->mac
.ops
.set_vmdq_san_mac(hw
, VMDQ_P(0));
7955 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
7957 * @netdev: network interface device structure
7959 * Returns non-zero on failure
7961 static int ixgbe_del_sanmac_netdev(struct net_device
*dev
)
7964 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
7965 struct ixgbe_mac_info
*mac
= &adapter
->hw
.mac
;
7967 if (is_valid_ether_addr(mac
->san_addr
)) {
7969 err
= dev_addr_del(dev
, mac
->san_addr
, NETDEV_HW_ADDR_T_SAN
);
7975 #ifdef CONFIG_NET_POLL_CONTROLLER
7977 * Polling 'interrupt' - used by things like netconsole to send skbs
7978 * without having to re-enable interrupts. It's not called while
7979 * the interrupt routine is executing.
7981 static void ixgbe_netpoll(struct net_device
*netdev
)
7983 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
7986 /* if interface is down do nothing */
7987 if (test_bit(__IXGBE_DOWN
, &adapter
->state
))
7990 /* loop through and schedule all active queues */
7991 for (i
= 0; i
< adapter
->num_q_vectors
; i
++)
7992 ixgbe_msix_clean_rings(0, adapter
->q_vector
[i
]);
7996 static struct rtnl_link_stats64
*ixgbe_get_stats64(struct net_device
*netdev
,
7997 struct rtnl_link_stats64
*stats
)
7999 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
8003 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
8004 struct ixgbe_ring
*ring
= ACCESS_ONCE(adapter
->rx_ring
[i
]);
8010 start
= u64_stats_fetch_begin_irq(&ring
->syncp
);
8011 packets
= ring
->stats
.packets
;
8012 bytes
= ring
->stats
.bytes
;
8013 } while (u64_stats_fetch_retry_irq(&ring
->syncp
, start
));
8014 stats
->rx_packets
+= packets
;
8015 stats
->rx_bytes
+= bytes
;
8019 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
8020 struct ixgbe_ring
*ring
= ACCESS_ONCE(adapter
->tx_ring
[i
]);
8026 start
= u64_stats_fetch_begin_irq(&ring
->syncp
);
8027 packets
= ring
->stats
.packets
;
8028 bytes
= ring
->stats
.bytes
;
8029 } while (u64_stats_fetch_retry_irq(&ring
->syncp
, start
));
8030 stats
->tx_packets
+= packets
;
8031 stats
->tx_bytes
+= bytes
;
8035 /* following stats updated by ixgbe_watchdog_task() */
8036 stats
->multicast
= netdev
->stats
.multicast
;
8037 stats
->rx_errors
= netdev
->stats
.rx_errors
;
8038 stats
->rx_length_errors
= netdev
->stats
.rx_length_errors
;
8039 stats
->rx_crc_errors
= netdev
->stats
.rx_crc_errors
;
8040 stats
->rx_missed_errors
= netdev
->stats
.rx_missed_errors
;
8044 #ifdef CONFIG_IXGBE_DCB
8046 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
8047 * @adapter: pointer to ixgbe_adapter
8048 * @tc: number of traffic classes currently enabled
8050 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
8051 * 802.1Q priority maps to a packet buffer that exists.
8053 static void ixgbe_validate_rtr(struct ixgbe_adapter
*adapter
, u8 tc
)
8055 struct ixgbe_hw
*hw
= &adapter
->hw
;
8059 /* 82598 have a static priority to TC mapping that can not
8060 * be changed so no validation is needed.
8062 if (hw
->mac
.type
== ixgbe_mac_82598EB
)
8065 reg
= IXGBE_READ_REG(hw
, IXGBE_RTRUP2TC
);
8068 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
8069 u8 up2tc
= reg
>> (i
* IXGBE_RTRUP2TC_UP_SHIFT
);
8071 /* If up2tc is out of bounds default to zero */
8073 reg
&= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT
);
8077 IXGBE_WRITE_REG(hw
, IXGBE_RTRUP2TC
, reg
);
8083 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
8084 * @adapter: Pointer to adapter struct
8086 * Populate the netdev user priority to tc map
8088 static void ixgbe_set_prio_tc_map(struct ixgbe_adapter
*adapter
)
8090 struct net_device
*dev
= adapter
->netdev
;
8091 struct ixgbe_dcb_config
*dcb_cfg
= &adapter
->dcb_cfg
;
8092 struct ieee_ets
*ets
= adapter
->ixgbe_ieee_ets
;
8095 for (prio
= 0; prio
< MAX_USER_PRIORITY
; prio
++) {
8098 if (adapter
->dcbx_cap
& DCB_CAP_DCBX_VER_CEE
)
8099 tc
= ixgbe_dcb_get_tc_from_up(dcb_cfg
, 0, prio
);
8101 tc
= ets
->prio_tc
[prio
];
8103 netdev_set_prio_tc_map(dev
, prio
, tc
);
8107 #endif /* CONFIG_IXGBE_DCB */
8109 * ixgbe_setup_tc - configure net_device for multiple traffic classes
8111 * @netdev: net device to configure
8112 * @tc: number of traffic classes to enable
8114 int ixgbe_setup_tc(struct net_device
*dev
, u8 tc
)
8116 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
8117 struct ixgbe_hw
*hw
= &adapter
->hw
;
8120 /* Hardware supports up to 8 traffic classes */
8121 if (tc
> adapter
->dcb_cfg
.num_tcs
.pg_tcs
)
8124 if (hw
->mac
.type
== ixgbe_mac_82598EB
&& tc
&& tc
< MAX_TRAFFIC_CLASS
)
8127 pools
= (find_first_zero_bit(&adapter
->fwd_bitmask
, 32) > 1);
8128 if (tc
&& pools
&& adapter
->num_rx_pools
> IXGBE_MAX_DCBMACVLANS
)
8131 /* Hardware has to reinitialize queues and interrupts to
8132 * match packet buffer alignment. Unfortunately, the
8133 * hardware is not flexible enough to do this dynamically.
8135 if (netif_running(dev
))
8138 ixgbe_reset(adapter
);
8140 ixgbe_clear_interrupt_scheme(adapter
);
8142 #ifdef CONFIG_IXGBE_DCB
8144 netdev_set_num_tc(dev
, tc
);
8145 ixgbe_set_prio_tc_map(adapter
);
8147 adapter
->flags
|= IXGBE_FLAG_DCB_ENABLED
;
8149 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
) {
8150 adapter
->last_lfc_mode
= adapter
->hw
.fc
.requested_mode
;
8151 adapter
->hw
.fc
.requested_mode
= ixgbe_fc_none
;
8154 netdev_reset_tc(dev
);
8156 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
8157 adapter
->hw
.fc
.requested_mode
= adapter
->last_lfc_mode
;
8159 adapter
->flags
&= ~IXGBE_FLAG_DCB_ENABLED
;
8161 adapter
->temp_dcb_cfg
.pfc_mode_enable
= false;
8162 adapter
->dcb_cfg
.pfc_mode_enable
= false;
8165 ixgbe_validate_rtr(adapter
, tc
);
8167 #endif /* CONFIG_IXGBE_DCB */
8168 ixgbe_init_interrupt_scheme(adapter
);
8170 if (netif_running(dev
))
8171 return ixgbe_open(dev
);
8176 static int ixgbe_delete_clsu32(struct ixgbe_adapter
*adapter
,
8177 struct tc_cls_u32_offload
*cls
)
8179 u32 uhtid
= TC_U32_USERHTID(cls
->knode
.handle
);
8183 if ((uhtid
!= 0x800) && (uhtid
>= IXGBE_MAX_LINK_HANDLE
))
8186 loc
= cls
->knode
.handle
& 0xfffff;
8188 spin_lock(&adapter
->fdir_perfect_lock
);
8189 err
= ixgbe_update_ethtool_fdir_entry(adapter
, NULL
, loc
);
8190 spin_unlock(&adapter
->fdir_perfect_lock
);
8194 static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter
*adapter
,
8196 struct tc_cls_u32_offload
*cls
)
8198 u32 uhtid
= TC_U32_USERHTID(cls
->hnode
.handle
);
8200 if (uhtid
>= IXGBE_MAX_LINK_HANDLE
)
8203 /* This ixgbe devices do not support hash tables at the moment
8204 * so abort when given hash tables.
8206 if (cls
->hnode
.divisor
> 0)
8209 set_bit(uhtid
- 1, &adapter
->tables
);
8213 static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter
*adapter
,
8214 struct tc_cls_u32_offload
*cls
)
8216 u32 uhtid
= TC_U32_USERHTID(cls
->hnode
.handle
);
8218 if (uhtid
>= IXGBE_MAX_LINK_HANDLE
)
8221 clear_bit(uhtid
- 1, &adapter
->tables
);
8225 static int ixgbe_configure_clsu32(struct ixgbe_adapter
*adapter
,
8227 struct tc_cls_u32_offload
*cls
)
8229 u32 loc
= cls
->knode
.handle
& 0xfffff;
8230 struct ixgbe_hw
*hw
= &adapter
->hw
;
8231 struct ixgbe_mat_field
*field_ptr
;
8232 struct ixgbe_fdir_filter
*input
;
8233 union ixgbe_atr_input mask
;
8234 #ifdef CONFIG_NET_CLS_ACT
8235 const struct tc_action
*a
;
8239 u32 uhtid
, link_uhtid
;
8241 memset(&mask
, 0, sizeof(union ixgbe_atr_input
));
8242 uhtid
= TC_U32_USERHTID(cls
->knode
.handle
);
8243 link_uhtid
= TC_U32_USERHTID(cls
->knode
.link_handle
);
8245 /* At the moment cls_u32 jumps to network layer and skips past
8246 * L2 headers. The canonical method to match L2 frames is to use
8247 * negative values. However this is error prone at best but really
8248 * just broken because there is no way to "know" what sort of hdr
8249 * is in front of the network layer. Fix cls_u32 to support L2
8250 * headers when needed.
8252 if (protocol
!= htons(ETH_P_IP
))
8256 struct ixgbe_nexthdr
*nexthdr
= ixgbe_ipv4_jumps
;
8258 if (link_uhtid
>= IXGBE_MAX_LINK_HANDLE
)
8261 if (!test_bit(link_uhtid
- 1, &adapter
->tables
))
8264 for (i
= 0; nexthdr
[i
].jump
; i
++) {
8265 if (nexthdr
[i
].o
!= cls
->knode
.sel
->offoff
||
8266 nexthdr
[i
].s
!= cls
->knode
.sel
->offshift
||
8267 nexthdr
[i
].m
!= cls
->knode
.sel
->offmask
||
8268 /* do not support multiple key jumps its just mad */
8269 cls
->knode
.sel
->nkeys
> 1)
8272 if (nexthdr
[i
].off
== cls
->knode
.sel
->keys
[0].off
&&
8273 nexthdr
[i
].val
== cls
->knode
.sel
->keys
[0].val
&&
8274 nexthdr
[i
].mask
== cls
->knode
.sel
->keys
[0].mask
) {
8275 adapter
->jump_tables
[link_uhtid
] =
8283 if (loc
>= ((1024 << adapter
->fdir_pballoc
) - 2)) {
8284 e_err(drv
, "Location out of range\n");
8288 /* cls u32 is a graph starting at root node 0x800. The driver tracks
8289 * links and also the fields used to advance the parser across each
8290 * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
8291 * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
8292 * To add support for new nodes update ixgbe_model.h parse structures
8293 * this function _should_ be generic try not to hardcode values here.
8295 if (uhtid
== 0x800) {
8296 field_ptr
= adapter
->jump_tables
[0];
8298 if (uhtid
>= IXGBE_MAX_LINK_HANDLE
)
8301 field_ptr
= adapter
->jump_tables
[uhtid
];
8307 input
= kzalloc(sizeof(*input
), GFP_KERNEL
);
8311 for (i
= 0; i
< cls
->knode
.sel
->nkeys
; i
++) {
8312 int off
= cls
->knode
.sel
->keys
[i
].off
;
8313 __be32 val
= cls
->knode
.sel
->keys
[i
].val
;
8314 __be32 m
= cls
->knode
.sel
->keys
[i
].mask
;
8315 bool found_entry
= false;
8318 for (j
= 0; field_ptr
[j
].val
; j
++) {
8319 if (field_ptr
[j
].off
== off
) {
8320 field_ptr
[j
].val(input
, &mask
, val
, m
);
8321 input
->filter
.formatted
.flow_type
|=
8332 mask
.formatted
.flow_type
= IXGBE_ATR_L4TYPE_IPV6_MASK
|
8333 IXGBE_ATR_L4TYPE_MASK
;
8335 if (input
->filter
.formatted
.flow_type
== IXGBE_ATR_FLOW_TYPE_IPV4
)
8336 mask
.formatted
.flow_type
&= IXGBE_ATR_L4TYPE_IPV6_MASK
;
8338 #ifdef CONFIG_NET_CLS_ACT
8339 if (list_empty(&cls
->knode
.exts
->actions
))
8342 list_for_each_entry(a
, &cls
->knode
.exts
->actions
, list
) {
8343 if (!is_tcf_gact_shot(a
))
8348 input
->action
= IXGBE_FDIR_DROP_QUEUE
;
8349 queue
= IXGBE_FDIR_DROP_QUEUE
;
8350 input
->sw_idx
= loc
;
8352 spin_lock(&adapter
->fdir_perfect_lock
);
8354 if (hlist_empty(&adapter
->fdir_filter_list
)) {
8355 memcpy(&adapter
->fdir_mask
, &mask
, sizeof(mask
));
8356 err
= ixgbe_fdir_set_input_mask_82599(hw
, &mask
);
8358 goto err_out_w_lock
;
8359 } else if (memcmp(&adapter
->fdir_mask
, &mask
, sizeof(mask
))) {
8361 goto err_out_w_lock
;
8364 ixgbe_atr_compute_perfect_hash_82599(&input
->filter
, &mask
);
8365 err
= ixgbe_fdir_write_perfect_filter_82599(hw
, &input
->filter
,
8366 input
->sw_idx
, queue
);
8368 ixgbe_update_ethtool_fdir_entry(adapter
, input
, input
->sw_idx
);
8369 spin_unlock(&adapter
->fdir_perfect_lock
);
8373 spin_unlock(&adapter
->fdir_perfect_lock
);
8379 static int __ixgbe_setup_tc(struct net_device
*dev
, u32 handle
, __be16 proto
,
8380 struct tc_to_netdev
*tc
)
8382 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
8384 if (TC_H_MAJ(handle
) == TC_H_MAJ(TC_H_INGRESS
) &&
8385 tc
->type
== TC_SETUP_CLSU32
) {
8386 switch (tc
->cls_u32
->command
) {
8387 case TC_CLSU32_NEW_KNODE
:
8388 case TC_CLSU32_REPLACE_KNODE
:
8389 return ixgbe_configure_clsu32(adapter
,
8390 proto
, tc
->cls_u32
);
8391 case TC_CLSU32_DELETE_KNODE
:
8392 return ixgbe_delete_clsu32(adapter
, tc
->cls_u32
);
8393 case TC_CLSU32_NEW_HNODE
:
8394 case TC_CLSU32_REPLACE_HNODE
:
8395 return ixgbe_configure_clsu32_add_hnode(adapter
, proto
,
8397 case TC_CLSU32_DELETE_HNODE
:
8398 return ixgbe_configure_clsu32_del_hnode(adapter
,
8405 if (tc
->type
!= TC_SETUP_MQPRIO
)
8408 return ixgbe_setup_tc(dev
, tc
->tc
);
8411 #ifdef CONFIG_PCI_IOV
8412 void ixgbe_sriov_reinit(struct ixgbe_adapter
*adapter
)
8414 struct net_device
*netdev
= adapter
->netdev
;
8417 ixgbe_setup_tc(netdev
, netdev_get_num_tc(netdev
));
8422 void ixgbe_do_reset(struct net_device
*netdev
)
8424 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
8426 if (netif_running(netdev
))
8427 ixgbe_reinit_locked(adapter
);
8429 ixgbe_reset(adapter
);
8432 static netdev_features_t
ixgbe_fix_features(struct net_device
*netdev
,
8433 netdev_features_t features
)
8435 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
8437 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
8438 if (!(features
& NETIF_F_RXCSUM
))
8439 features
&= ~NETIF_F_LRO
;
8441 /* Turn off LRO if not RSC capable */
8442 if (!(adapter
->flags2
& IXGBE_FLAG2_RSC_CAPABLE
))
8443 features
&= ~NETIF_F_LRO
;
8448 static int ixgbe_set_features(struct net_device
*netdev
,
8449 netdev_features_t features
)
8451 struct ixgbe_adapter
*adapter
= netdev_priv(netdev
);
8452 netdev_features_t changed
= netdev
->features
^ features
;
8453 bool need_reset
= false;
8455 /* Make sure RSC matches LRO, reset if change */
8456 if (!(features
& NETIF_F_LRO
)) {
8457 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)
8459 adapter
->flags2
&= ~IXGBE_FLAG2_RSC_ENABLED
;
8460 } else if ((adapter
->flags2
& IXGBE_FLAG2_RSC_CAPABLE
) &&
8461 !(adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)) {
8462 if (adapter
->rx_itr_setting
== 1 ||
8463 adapter
->rx_itr_setting
> IXGBE_MIN_RSC_ITR
) {
8464 adapter
->flags2
|= IXGBE_FLAG2_RSC_ENABLED
;
8466 } else if ((changed
^ features
) & NETIF_F_LRO
) {
8467 e_info(probe
, "rx-usecs set too low, "
8473 * Check if Flow Director n-tuple support or hw_tc support was
8474 * enabled or disabled. If the state changed, we need to reset.
8476 if ((features
& NETIF_F_NTUPLE
) || (features
& NETIF_F_HW_TC
)) {
8477 /* turn off ATR, enable perfect filters and reset */
8478 if (!(adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
))
8481 adapter
->flags
&= ~IXGBE_FLAG_FDIR_HASH_CAPABLE
;
8482 adapter
->flags
|= IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
8484 /* turn off perfect filters, enable ATR and reset */
8485 if (adapter
->flags
& IXGBE_FLAG_FDIR_PERFECT_CAPABLE
)
8488 adapter
->flags
&= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE
;
8490 /* We cannot enable ATR if SR-IOV is enabled */
8491 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
||
8492 /* We cannot enable ATR if we have 2 or more tcs */
8493 (netdev_get_num_tc(netdev
) > 1) ||
8494 /* We cannot enable ATR if RSS is disabled */
8495 (adapter
->ring_feature
[RING_F_RSS
].limit
<= 1) ||
8496 /* A sample rate of 0 indicates ATR disabled */
8497 (!adapter
->atr_sample_rate
))
8498 ; /* do nothing not supported */
8499 else /* otherwise supported and set the flag */
8500 adapter
->flags
|= IXGBE_FLAG_FDIR_HASH_CAPABLE
;
8503 if (changed
& NETIF_F_RXALL
)
8506 netdev
->features
= features
;
8508 #ifdef CONFIG_IXGBE_VXLAN
8509 if ((adapter
->flags
& IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE
)) {
8510 if (features
& NETIF_F_RXCSUM
)
8511 adapter
->flags2
|= IXGBE_FLAG2_VXLAN_REREG_NEEDED
;
8513 ixgbe_clear_vxlan_port(adapter
);
8515 #endif /* CONFIG_IXGBE_VXLAN */
8518 ixgbe_do_reset(netdev
);
8519 else if (changed
& (NETIF_F_HW_VLAN_CTAG_RX
|
8520 NETIF_F_HW_VLAN_CTAG_FILTER
))
8521 ixgbe_set_rx_mode(netdev
);
8526 #ifdef CONFIG_IXGBE_VXLAN
8528 * ixgbe_add_vxlan_port - Get notifications about VXLAN ports that come up
8529 * @dev: The port's netdev
8530 * @sa_family: Socket Family that VXLAN is notifiying us about
8531 * @port: New UDP port number that VXLAN started listening to
8533 static void ixgbe_add_vxlan_port(struct net_device
*dev
, sa_family_t sa_family
,
8536 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
8537 struct ixgbe_hw
*hw
= &adapter
->hw
;
8539 if (!(adapter
->flags
& IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE
))
8542 if (sa_family
== AF_INET6
)
8545 if (adapter
->vxlan_port
== port
)
8548 if (adapter
->vxlan_port
) {
8550 "Hit Max num of VXLAN ports, not adding port %d\n",
8555 adapter
->vxlan_port
= port
;
8556 IXGBE_WRITE_REG(hw
, IXGBE_VXLANCTRL
, ntohs(port
));
8560 * ixgbe_del_vxlan_port - Get notifications about VXLAN ports that go away
8561 * @dev: The port's netdev
8562 * @sa_family: Socket Family that VXLAN is notifying us about
8563 * @port: UDP port number that VXLAN stopped listening to
8565 static void ixgbe_del_vxlan_port(struct net_device
*dev
, sa_family_t sa_family
,
8568 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
8570 if (!(adapter
->flags
& IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE
))
8573 if (sa_family
== AF_INET6
)
8576 if (adapter
->vxlan_port
!= port
) {
8577 netdev_info(dev
, "Port %d was not found, not deleting\n",
8582 ixgbe_clear_vxlan_port(adapter
);
8583 adapter
->flags2
|= IXGBE_FLAG2_VXLAN_REREG_NEEDED
;
8585 #endif /* CONFIG_IXGBE_VXLAN */
8587 static int ixgbe_ndo_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
8588 struct net_device
*dev
,
8589 const unsigned char *addr
, u16 vid
,
8592 /* guarantee we can provide a unique filter for the unicast address */
8593 if (is_unicast_ether_addr(addr
) || is_link_local_ether_addr(addr
)) {
8594 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
8595 u16 pool
= VMDQ_P(0);
8597 if (netdev_uc_count(dev
) >= ixgbe_available_rars(adapter
, pool
))
8601 return ndo_dflt_fdb_add(ndm
, tb
, dev
, addr
, vid
, flags
);
8605 * ixgbe_configure_bridge_mode - set various bridge modes
8606 * @adapter - the private structure
8607 * @mode - requested bridge mode
8609 * Configure some settings require for various bridge modes.
8611 static int ixgbe_configure_bridge_mode(struct ixgbe_adapter
*adapter
,
8614 struct ixgbe_hw
*hw
= &adapter
->hw
;
8615 unsigned int p
, num_pools
;
8619 case BRIDGE_MODE_VEPA
:
8620 /* disable Tx loopback, rely on switch hairpin mode */
8621 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_PFDTXGSWC
, 0);
8623 /* must enable Rx switching replication to allow multicast
8624 * packet reception on all VFs, and to enable source address
8627 vmdctl
= IXGBE_READ_REG(hw
, IXGBE_VMD_CTL
);
8628 vmdctl
|= IXGBE_VT_CTL_REPLEN
;
8629 IXGBE_WRITE_REG(hw
, IXGBE_VMD_CTL
, vmdctl
);
8631 /* enable Rx source address pruning. Note, this requires
8632 * replication to be enabled or else it does nothing.
8634 num_pools
= adapter
->num_vfs
+ adapter
->num_rx_pools
;
8635 for (p
= 0; p
< num_pools
; p
++) {
8636 if (hw
->mac
.ops
.set_source_address_pruning
)
8637 hw
->mac
.ops
.set_source_address_pruning(hw
,
8642 case BRIDGE_MODE_VEB
:
8643 /* enable Tx loopback for internal VF/PF communication */
8644 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_PFDTXGSWC
,
8645 IXGBE_PFDTXGSWC_VT_LBEN
);
8647 /* disable Rx switching replication unless we have SR-IOV
8650 vmdctl
= IXGBE_READ_REG(hw
, IXGBE_VMD_CTL
);
8651 if (!adapter
->num_vfs
)
8652 vmdctl
&= ~IXGBE_VT_CTL_REPLEN
;
8653 IXGBE_WRITE_REG(hw
, IXGBE_VMD_CTL
, vmdctl
);
8655 /* disable Rx source address pruning, since we don't expect to
8656 * be receiving external loopback of our transmitted frames.
8658 num_pools
= adapter
->num_vfs
+ adapter
->num_rx_pools
;
8659 for (p
= 0; p
< num_pools
; p
++) {
8660 if (hw
->mac
.ops
.set_source_address_pruning
)
8661 hw
->mac
.ops
.set_source_address_pruning(hw
,
8670 adapter
->bridge_mode
= mode
;
8672 e_info(drv
, "enabling bridge mode: %s\n",
8673 mode
== BRIDGE_MODE_VEPA
? "VEPA" : "VEB");
8678 static int ixgbe_ndo_bridge_setlink(struct net_device
*dev
,
8679 struct nlmsghdr
*nlh
, u16 flags
)
8681 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
8682 struct nlattr
*attr
, *br_spec
;
8685 if (!(adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
))
8688 br_spec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
8692 nla_for_each_nested(attr
, br_spec
, rem
) {
8696 if (nla_type(attr
) != IFLA_BRIDGE_MODE
)
8699 if (nla_len(attr
) < sizeof(mode
))
8702 mode
= nla_get_u16(attr
);
8703 status
= ixgbe_configure_bridge_mode(adapter
, mode
);
8713 static int ixgbe_ndo_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
8714 struct net_device
*dev
,
8715 u32 filter_mask
, int nlflags
)
8717 struct ixgbe_adapter
*adapter
= netdev_priv(dev
);
8719 if (!(adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
))
8722 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
,
8723 adapter
->bridge_mode
, 0, 0, nlflags
,
8727 static void *ixgbe_fwd_add(struct net_device
*pdev
, struct net_device
*vdev
)
8729 struct ixgbe_fwd_adapter
*fwd_adapter
= NULL
;
8730 struct ixgbe_adapter
*adapter
= netdev_priv(pdev
);
8731 int used_pools
= adapter
->num_vfs
+ adapter
->num_rx_pools
;
8735 /* Hardware has a limited number of available pools. Each VF, and the
8736 * PF require a pool. Check to ensure we don't attempt to use more
8737 * then the available number of pools.
8739 if (used_pools
>= IXGBE_MAX_VF_FUNCTIONS
)
8740 return ERR_PTR(-EINVAL
);
8743 if (vdev
->num_rx_queues
!= vdev
->num_tx_queues
) {
8744 netdev_info(pdev
, "%s: Only supports a single queue count for TX and RX\n",
8746 return ERR_PTR(-EINVAL
);
8749 /* Check for hardware restriction on number of rx/tx queues */
8750 if (vdev
->num_tx_queues
> IXGBE_MAX_L2A_QUEUES
||
8751 vdev
->num_tx_queues
== IXGBE_BAD_L2A_QUEUE
) {
8753 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
8755 return ERR_PTR(-EINVAL
);
8758 if (((adapter
->flags
& IXGBE_FLAG_DCB_ENABLED
) &&
8759 adapter
->num_rx_pools
> IXGBE_MAX_DCBMACVLANS
- 1) ||
8760 (adapter
->num_rx_pools
> IXGBE_MAX_MACVLANS
))
8761 return ERR_PTR(-EBUSY
);
8763 fwd_adapter
= kzalloc(sizeof(*fwd_adapter
), GFP_KERNEL
);
8765 return ERR_PTR(-ENOMEM
);
8767 pool
= find_first_zero_bit(&adapter
->fwd_bitmask
, 32);
8768 adapter
->num_rx_pools
++;
8769 set_bit(pool
, &adapter
->fwd_bitmask
);
8770 limit
= find_last_bit(&adapter
->fwd_bitmask
, 32);
8772 /* Enable VMDq flag so device will be set in VM mode */
8773 adapter
->flags
|= IXGBE_FLAG_VMDQ_ENABLED
| IXGBE_FLAG_SRIOV_ENABLED
;
8774 adapter
->ring_feature
[RING_F_VMDQ
].limit
= limit
+ 1;
8775 adapter
->ring_feature
[RING_F_RSS
].limit
= vdev
->num_tx_queues
;
8777 /* Force reinit of ring allocation with VMDQ enabled */
8778 err
= ixgbe_setup_tc(pdev
, netdev_get_num_tc(pdev
));
8781 fwd_adapter
->pool
= pool
;
8782 fwd_adapter
->real_adapter
= adapter
;
8783 err
= ixgbe_fwd_ring_up(vdev
, fwd_adapter
);
8786 netif_tx_start_all_queues(vdev
);
8789 /* unwind counter and free adapter struct */
8791 "%s: dfwd hardware acceleration failed\n", vdev
->name
);
8792 clear_bit(pool
, &adapter
->fwd_bitmask
);
8793 adapter
->num_rx_pools
--;
8795 return ERR_PTR(err
);
8798 static void ixgbe_fwd_del(struct net_device
*pdev
, void *priv
)
8800 struct ixgbe_fwd_adapter
*fwd_adapter
= priv
;
8801 struct ixgbe_adapter
*adapter
= fwd_adapter
->real_adapter
;
8804 clear_bit(fwd_adapter
->pool
, &adapter
->fwd_bitmask
);
8805 adapter
->num_rx_pools
--;
8807 limit
= find_last_bit(&adapter
->fwd_bitmask
, 32);
8808 adapter
->ring_feature
[RING_F_VMDQ
].limit
= limit
+ 1;
8809 ixgbe_fwd_ring_down(fwd_adapter
->netdev
, fwd_adapter
);
8810 ixgbe_setup_tc(pdev
, netdev_get_num_tc(pdev
));
8811 netdev_dbg(pdev
, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
8812 fwd_adapter
->pool
, adapter
->num_rx_pools
,
8813 fwd_adapter
->rx_base_queue
,
8814 fwd_adapter
->rx_base_queue
+ adapter
->num_rx_queues_per_pool
,
8815 adapter
->fwd_bitmask
);
8819 #define IXGBE_MAX_TUNNEL_HDR_LEN 80
8820 static netdev_features_t
8821 ixgbe_features_check(struct sk_buff
*skb
, struct net_device
*dev
,
8822 netdev_features_t features
)
8824 if (!skb
->encapsulation
)
8827 if (unlikely(skb_inner_mac_header(skb
) - skb_transport_header(skb
) >
8828 IXGBE_MAX_TUNNEL_HDR_LEN
))
8829 return features
& ~NETIF_F_CSUM_MASK
;
8834 static const struct net_device_ops ixgbe_netdev_ops
= {
8835 .ndo_open
= ixgbe_open
,
8836 .ndo_stop
= ixgbe_close
,
8837 .ndo_start_xmit
= ixgbe_xmit_frame
,
8838 .ndo_select_queue
= ixgbe_select_queue
,
8839 .ndo_set_rx_mode
= ixgbe_set_rx_mode
,
8840 .ndo_validate_addr
= eth_validate_addr
,
8841 .ndo_set_mac_address
= ixgbe_set_mac
,
8842 .ndo_change_mtu
= ixgbe_change_mtu
,
8843 .ndo_tx_timeout
= ixgbe_tx_timeout
,
8844 .ndo_set_tx_maxrate
= ixgbe_tx_maxrate
,
8845 .ndo_vlan_rx_add_vid
= ixgbe_vlan_rx_add_vid
,
8846 .ndo_vlan_rx_kill_vid
= ixgbe_vlan_rx_kill_vid
,
8847 .ndo_do_ioctl
= ixgbe_ioctl
,
8848 .ndo_set_vf_mac
= ixgbe_ndo_set_vf_mac
,
8849 .ndo_set_vf_vlan
= ixgbe_ndo_set_vf_vlan
,
8850 .ndo_set_vf_rate
= ixgbe_ndo_set_vf_bw
,
8851 .ndo_set_vf_spoofchk
= ixgbe_ndo_set_vf_spoofchk
,
8852 .ndo_set_vf_rss_query_en
= ixgbe_ndo_set_vf_rss_query_en
,
8853 .ndo_set_vf_trust
= ixgbe_ndo_set_vf_trust
,
8854 .ndo_get_vf_config
= ixgbe_ndo_get_vf_config
,
8855 .ndo_get_stats64
= ixgbe_get_stats64
,
8856 .ndo_setup_tc
= __ixgbe_setup_tc
,
8857 #ifdef CONFIG_NET_POLL_CONTROLLER
8858 .ndo_poll_controller
= ixgbe_netpoll
,
8860 #ifdef CONFIG_NET_RX_BUSY_POLL
8861 .ndo_busy_poll
= ixgbe_low_latency_recv
,
8864 .ndo_fcoe_ddp_setup
= ixgbe_fcoe_ddp_get
,
8865 .ndo_fcoe_ddp_target
= ixgbe_fcoe_ddp_target
,
8866 .ndo_fcoe_ddp_done
= ixgbe_fcoe_ddp_put
,
8867 .ndo_fcoe_enable
= ixgbe_fcoe_enable
,
8868 .ndo_fcoe_disable
= ixgbe_fcoe_disable
,
8869 .ndo_fcoe_get_wwn
= ixgbe_fcoe_get_wwn
,
8870 .ndo_fcoe_get_hbainfo
= ixgbe_fcoe_get_hbainfo
,
8871 #endif /* IXGBE_FCOE */
8872 .ndo_set_features
= ixgbe_set_features
,
8873 .ndo_fix_features
= ixgbe_fix_features
,
8874 .ndo_fdb_add
= ixgbe_ndo_fdb_add
,
8875 .ndo_bridge_setlink
= ixgbe_ndo_bridge_setlink
,
8876 .ndo_bridge_getlink
= ixgbe_ndo_bridge_getlink
,
8877 .ndo_dfwd_add_station
= ixgbe_fwd_add
,
8878 .ndo_dfwd_del_station
= ixgbe_fwd_del
,
8879 #ifdef CONFIG_IXGBE_VXLAN
8880 .ndo_add_vxlan_port
= ixgbe_add_vxlan_port
,
8881 .ndo_del_vxlan_port
= ixgbe_del_vxlan_port
,
8882 #endif /* CONFIG_IXGBE_VXLAN */
8883 .ndo_features_check
= ixgbe_features_check
,
8887 * ixgbe_enumerate_functions - Get the number of ports this device has
8888 * @adapter: adapter structure
8890 * This function enumerates the phsyical functions co-located on a single slot,
8891 * in order to determine how many ports a device has. This is most useful in
8892 * determining the required GT/s of PCIe bandwidth necessary for optimal
8895 static inline int ixgbe_enumerate_functions(struct ixgbe_adapter
*adapter
)
8897 struct pci_dev
*entry
, *pdev
= adapter
->pdev
;
8900 /* Some cards can not use the generic count PCIe functions method,
8901 * because they are behind a parent switch, so we hardcode these with
8902 * the correct number of functions.
8904 if (ixgbe_pcie_from_parent(&adapter
->hw
))
8907 list_for_each_entry(entry
, &adapter
->pdev
->bus
->devices
, bus_list
) {
8908 /* don't count virtual functions */
8909 if (entry
->is_virtfn
)
8912 /* When the devices on the bus don't all match our device ID,
8913 * we can't reliably determine the correct number of
8914 * functions. This can occur if a function has been direct
8915 * attached to a virtual machine using VT-d, for example. In
8916 * this case, simply return -1 to indicate this.
8918 if ((entry
->vendor
!= pdev
->vendor
) ||
8919 (entry
->device
!= pdev
->device
))
8929 * ixgbe_wol_supported - Check whether device supports WoL
8930 * @hw: hw specific details
8931 * @device_id: the device ID
8932 * @subdev_id: the subsystem device ID
8934 * This function is used by probe and ethtool to determine
8935 * which devices have WoL support
8938 int ixgbe_wol_supported(struct ixgbe_adapter
*adapter
, u16 device_id
,
8941 struct ixgbe_hw
*hw
= &adapter
->hw
;
8942 u16 wol_cap
= adapter
->eeprom_cap
& IXGBE_DEVICE_CAPS_WOL_MASK
;
8943 int is_wol_supported
= 0;
8945 switch (device_id
) {
8946 case IXGBE_DEV_ID_82599_SFP
:
8947 /* Only these subdevices could supports WOL */
8948 switch (subdevice_id
) {
8949 case IXGBE_SUBDEV_ID_82599_SFP_WOL0
:
8950 case IXGBE_SUBDEV_ID_82599_560FLR
:
8951 /* only support first port */
8952 if (hw
->bus
.func
!= 0)
8954 case IXGBE_SUBDEV_ID_82599_SP_560FLR
:
8955 case IXGBE_SUBDEV_ID_82599_SFP
:
8956 case IXGBE_SUBDEV_ID_82599_RNDC
:
8957 case IXGBE_SUBDEV_ID_82599_ECNA_DP
:
8958 case IXGBE_SUBDEV_ID_82599_LOM_SFP
:
8959 is_wol_supported
= 1;
8963 case IXGBE_DEV_ID_82599EN_SFP
:
8964 /* Only this subdevice supports WOL */
8965 switch (subdevice_id
) {
8966 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1
:
8967 is_wol_supported
= 1;
8971 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE
:
8972 /* All except this subdevice support WOL */
8973 if (subdevice_id
!= IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ
)
8974 is_wol_supported
= 1;
8976 case IXGBE_DEV_ID_82599_KX4
:
8977 is_wol_supported
= 1;
8979 case IXGBE_DEV_ID_X540T
:
8980 case IXGBE_DEV_ID_X540T1
:
8981 case IXGBE_DEV_ID_X550T
:
8982 case IXGBE_DEV_ID_X550EM_X_KX4
:
8983 case IXGBE_DEV_ID_X550EM_X_KR
:
8984 case IXGBE_DEV_ID_X550EM_X_10G_T
:
8985 /* check eeprom to see if enabled wol */
8986 if ((wol_cap
== IXGBE_DEVICE_CAPS_WOL_PORT0_1
) ||
8987 ((wol_cap
== IXGBE_DEVICE_CAPS_WOL_PORT0
) &&
8988 (hw
->bus
.func
== 0))) {
8989 is_wol_supported
= 1;
8994 return is_wol_supported
;
8998 * ixgbe_probe - Device Initialization Routine
8999 * @pdev: PCI device information struct
9000 * @ent: entry in ixgbe_pci_tbl
9002 * Returns 0 on success, negative on failure
9004 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
9005 * The OS initialization, configuring of the adapter private structure,
9006 * and a hardware reset occur.
9008 static int ixgbe_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
9010 struct net_device
*netdev
;
9011 struct ixgbe_adapter
*adapter
= NULL
;
9012 struct ixgbe_hw
*hw
;
9013 const struct ixgbe_info
*ii
= ixgbe_info_tbl
[ent
->driver_data
];
9014 int i
, err
, pci_using_dac
, expected_gts
;
9015 unsigned int indices
= MAX_TX_QUEUES
;
9016 u8 part_str
[IXGBE_PBANUM_LENGTH
];
9017 bool disable_dev
= false;
9023 /* Catch broken hardware that put the wrong VF device ID in
9024 * the PCIe SR-IOV capability.
9026 if (pdev
->is_virtfn
) {
9027 WARN(1, KERN_ERR
"%s (%hx:%hx) should not be a VF!\n",
9028 pci_name(pdev
), pdev
->vendor
, pdev
->device
);
9032 err
= pci_enable_device_mem(pdev
);
9036 if (!dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64))) {
9039 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
9042 "No usable DMA configuration, aborting\n");
9048 err
= pci_request_selected_regions(pdev
, pci_select_bars(pdev
,
9049 IORESOURCE_MEM
), ixgbe_driver_name
);
9052 "pci_request_selected_regions failed 0x%x\n", err
);
9056 pci_enable_pcie_error_reporting(pdev
);
9058 pci_set_master(pdev
);
9059 pci_save_state(pdev
);
9061 if (ii
->mac
== ixgbe_mac_82598EB
) {
9062 #ifdef CONFIG_IXGBE_DCB
9063 /* 8 TC w/ 4 queues per TC */
9064 indices
= 4 * MAX_TRAFFIC_CLASS
;
9066 indices
= IXGBE_MAX_RSS_INDICES
;
9070 netdev
= alloc_etherdev_mq(sizeof(struct ixgbe_adapter
), indices
);
9073 goto err_alloc_etherdev
;
9076 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
9078 adapter
= netdev_priv(netdev
);
9080 adapter
->netdev
= netdev
;
9081 adapter
->pdev
= pdev
;
9084 adapter
->msg_enable
= netif_msg_init(debug
, DEFAULT_MSG_ENABLE
);
9086 hw
->hw_addr
= ioremap(pci_resource_start(pdev
, 0),
9087 pci_resource_len(pdev
, 0));
9088 adapter
->io_addr
= hw
->hw_addr
;
9094 netdev
->netdev_ops
= &ixgbe_netdev_ops
;
9095 ixgbe_set_ethtool_ops(netdev
);
9096 netdev
->watchdog_timeo
= 5 * HZ
;
9097 strlcpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
));
9100 hw
->mac
.ops
= *ii
->mac_ops
;
9101 hw
->mac
.type
= ii
->mac
;
9102 hw
->mvals
= ii
->mvals
;
9105 hw
->eeprom
.ops
= *ii
->eeprom_ops
;
9106 eec
= IXGBE_READ_REG(hw
, IXGBE_EEC(hw
));
9107 if (ixgbe_removed(hw
->hw_addr
)) {
9111 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
9112 if (!(eec
& (1 << 8)))
9113 hw
->eeprom
.ops
.read
= &ixgbe_read_eeprom_bit_bang_generic
;
9116 hw
->phy
.ops
= *ii
->phy_ops
;
9117 hw
->phy
.sfp_type
= ixgbe_sfp_type_unknown
;
9118 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
9119 hw
->phy
.mdio
.prtad
= MDIO_PRTAD_NONE
;
9120 hw
->phy
.mdio
.mmds
= 0;
9121 hw
->phy
.mdio
.mode_support
= MDIO_SUPPORTS_C45
| MDIO_EMULATE_C22
;
9122 hw
->phy
.mdio
.dev
= netdev
;
9123 hw
->phy
.mdio
.mdio_read
= ixgbe_mdio_read
;
9124 hw
->phy
.mdio
.mdio_write
= ixgbe_mdio_write
;
9126 ii
->get_invariants(hw
);
9128 /* setup the private structure */
9129 err
= ixgbe_sw_init(adapter
);
9133 /* Make sure the SWFW semaphore is in a valid state */
9134 if (hw
->mac
.ops
.init_swfw_sync
)
9135 hw
->mac
.ops
.init_swfw_sync(hw
);
9137 /* Make it possible the adapter to be woken up via WOL */
9138 switch (adapter
->hw
.mac
.type
) {
9139 case ixgbe_mac_82599EB
:
9140 case ixgbe_mac_X540
:
9141 case ixgbe_mac_X550
:
9142 case ixgbe_mac_X550EM_x
:
9143 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
9150 * If there is a fan on this device and it has failed log the
9153 if (adapter
->flags
& IXGBE_FLAG_FAN_FAIL_CAPABLE
) {
9154 u32 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
9155 if (esdp
& IXGBE_ESDP_SDP1
)
9156 e_crit(probe
, "Fan has stopped, replace the adapter\n");
9159 if (allow_unsupported_sfp
)
9160 hw
->allow_unsupported_sfp
= allow_unsupported_sfp
;
9162 /* reset_hw fills in the perm_addr as well */
9163 hw
->phy
.reset_if_overtemp
= true;
9164 err
= hw
->mac
.ops
.reset_hw(hw
);
9165 hw
->phy
.reset_if_overtemp
= false;
9166 if (err
== IXGBE_ERR_SFP_NOT_PRESENT
) {
9168 } else if (err
== IXGBE_ERR_SFP_NOT_SUPPORTED
) {
9169 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
9170 e_dev_err("Reload the driver after installing a supported module.\n");
9173 e_dev_err("HW Init failed: %d\n", err
);
9177 #ifdef CONFIG_PCI_IOV
9178 /* SR-IOV not supported on the 82598 */
9179 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
)
9182 ixgbe_init_mbx_params_pf(hw
);
9183 hw
->mbx
.ops
= ii
->mbx_ops
;
9184 pci_sriov_set_totalvfs(pdev
, IXGBE_MAX_VFS_DRV_LIMIT
);
9185 ixgbe_enable_sriov(adapter
);
9189 netdev
->features
= NETIF_F_SG
|
9195 NETIF_F_HW_VLAN_CTAG_TX
|
9196 NETIF_F_HW_VLAN_CTAG_RX
|
9197 NETIF_F_HW_VLAN_CTAG_FILTER
;
9199 if (hw
->mac
.type
>= ixgbe_mac_82599EB
)
9200 netdev
->features
|= NETIF_F_SCTP_CRC
;
9202 /* copy netdev features into list of user selectable features */
9203 netdev
->hw_features
|= netdev
->features
;
9204 netdev
->hw_features
|= NETIF_F_RXALL
|
9205 NETIF_F_HW_L2FW_DOFFLOAD
;
9207 if (hw
->mac
.type
>= ixgbe_mac_82599EB
)
9208 netdev
->hw_features
|= NETIF_F_NTUPLE
|
9211 netdev
->vlan_features
|= NETIF_F_SG
|
9217 netdev
->mpls_features
|= NETIF_F_HW_CSUM
;
9218 netdev
->hw_enc_features
|= NETIF_F_HW_CSUM
;
9220 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
9221 netdev
->priv_flags
|= IFF_SUPP_NOFCS
;
9223 #ifdef CONFIG_IXGBE_DCB
9224 netdev
->dcbnl_ops
= &dcbnl_ops
;
9228 if (adapter
->flags
& IXGBE_FLAG_FCOE_CAPABLE
) {
9229 unsigned int fcoe_l
;
9231 if (hw
->mac
.ops
.get_device_caps
) {
9232 hw
->mac
.ops
.get_device_caps(hw
, &device_caps
);
9233 if (device_caps
& IXGBE_DEVICE_CAPS_FCOE_OFFLOADS
)
9234 adapter
->flags
&= ~IXGBE_FLAG_FCOE_CAPABLE
;
9238 fcoe_l
= min_t(int, IXGBE_FCRETA_SIZE
, num_online_cpus());
9239 adapter
->ring_feature
[RING_F_FCOE
].limit
= fcoe_l
;
9241 netdev
->features
|= NETIF_F_FSO
|
9244 netdev
->vlan_features
|= NETIF_F_FSO
|
9248 #endif /* IXGBE_FCOE */
9249 if (pci_using_dac
) {
9250 netdev
->features
|= NETIF_F_HIGHDMA
;
9251 netdev
->vlan_features
|= NETIF_F_HIGHDMA
;
9254 if (adapter
->flags2
& IXGBE_FLAG2_RSC_CAPABLE
)
9255 netdev
->hw_features
|= NETIF_F_LRO
;
9256 if (adapter
->flags2
& IXGBE_FLAG2_RSC_ENABLED
)
9257 netdev
->features
|= NETIF_F_LRO
;
9259 /* make sure the EEPROM is good */
9260 if (hw
->eeprom
.ops
.validate_checksum(hw
, NULL
) < 0) {
9261 e_dev_err("The EEPROM Checksum Is Not Valid\n");
9266 eth_platform_get_mac_address(&adapter
->pdev
->dev
,
9267 adapter
->hw
.mac
.perm_addr
);
9269 memcpy(netdev
->dev_addr
, hw
->mac
.perm_addr
, netdev
->addr_len
);
9271 if (!is_valid_ether_addr(netdev
->dev_addr
)) {
9272 e_dev_err("invalid MAC address\n");
9277 /* Set hw->mac.addr to permanent MAC address */
9278 ether_addr_copy(hw
->mac
.addr
, hw
->mac
.perm_addr
);
9279 ixgbe_mac_set_default_filter(adapter
);
9281 setup_timer(&adapter
->service_timer
, &ixgbe_service_timer
,
9282 (unsigned long) adapter
);
9284 if (ixgbe_removed(hw
->hw_addr
)) {
9288 INIT_WORK(&adapter
->service_task
, ixgbe_service_task
);
9289 set_bit(__IXGBE_SERVICE_INITED
, &adapter
->state
);
9290 clear_bit(__IXGBE_SERVICE_SCHED
, &adapter
->state
);
9292 err
= ixgbe_init_interrupt_scheme(adapter
);
9296 /* WOL not supported for all devices */
9298 hw
->eeprom
.ops
.read(hw
, 0x2c, &adapter
->eeprom_cap
);
9299 hw
->wol_enabled
= ixgbe_wol_supported(adapter
, pdev
->device
,
9300 pdev
->subsystem_device
);
9301 if (hw
->wol_enabled
)
9302 adapter
->wol
= IXGBE_WUFC_MAG
;
9304 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
9306 /* save off EEPROM version number */
9307 hw
->eeprom
.ops
.read(hw
, 0x2e, &adapter
->eeprom_verh
);
9308 hw
->eeprom
.ops
.read(hw
, 0x2d, &adapter
->eeprom_verl
);
9310 /* pick up the PCI bus settings for reporting later */
9311 if (ixgbe_pcie_from_parent(hw
))
9312 ixgbe_get_parent_bus_info(adapter
);
9314 hw
->mac
.ops
.get_bus_info(hw
);
9316 /* calculate the expected PCIe bandwidth required for optimal
9317 * performance. Note that some older parts will never have enough
9318 * bandwidth due to being older generation PCIe parts. We clamp these
9319 * parts to ensure no warning is displayed if it can't be fixed.
9321 switch (hw
->mac
.type
) {
9322 case ixgbe_mac_82598EB
:
9323 expected_gts
= min(ixgbe_enumerate_functions(adapter
) * 10, 16);
9326 expected_gts
= ixgbe_enumerate_functions(adapter
) * 10;
9330 /* don't check link if we failed to enumerate functions */
9331 if (expected_gts
> 0)
9332 ixgbe_check_minimum_link(adapter
, expected_gts
);
9334 err
= ixgbe_read_pba_string_generic(hw
, part_str
, sizeof(part_str
));
9336 strlcpy(part_str
, "Unknown", sizeof(part_str
));
9337 if (ixgbe_is_sfp(hw
) && hw
->phy
.sfp_type
!= ixgbe_sfp_type_not_present
)
9338 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
9339 hw
->mac
.type
, hw
->phy
.type
, hw
->phy
.sfp_type
,
9342 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
9343 hw
->mac
.type
, hw
->phy
.type
, part_str
);
9345 e_dev_info("%pM\n", netdev
->dev_addr
);
9347 /* reset the hardware with the new settings */
9348 err
= hw
->mac
.ops
.start_hw(hw
);
9349 if (err
== IXGBE_ERR_EEPROM_VERSION
) {
9350 /* We are running on a pre-production device, log a warning */
9351 e_dev_warn("This device is a pre-production adapter/LOM. "
9352 "Please be aware there may be issues associated "
9353 "with your hardware. If you are experiencing "
9354 "problems please contact your Intel or hardware "
9355 "representative who provided you with this "
9358 strcpy(netdev
->name
, "eth%d");
9359 err
= register_netdev(netdev
);
9363 pci_set_drvdata(pdev
, adapter
);
9365 /* power down the optics for 82599 SFP+ fiber */
9366 if (hw
->mac
.ops
.disable_tx_laser
)
9367 hw
->mac
.ops
.disable_tx_laser(hw
);
9369 /* carrier off reporting is important to ethtool even BEFORE open */
9370 netif_carrier_off(netdev
);
9372 #ifdef CONFIG_IXGBE_DCA
9373 if (dca_add_requester(&pdev
->dev
) == 0) {
9374 adapter
->flags
|= IXGBE_FLAG_DCA_ENABLED
;
9375 ixgbe_setup_dca(adapter
);
9378 if (adapter
->flags
& IXGBE_FLAG_SRIOV_ENABLED
) {
9379 e_info(probe
, "IOV is enabled with %d VFs\n", adapter
->num_vfs
);
9380 for (i
= 0; i
< adapter
->num_vfs
; i
++)
9381 ixgbe_vf_configuration(pdev
, (i
| 0x10000000));
9384 /* firmware requires driver version to be 0xFFFFFFFF
9385 * since os does not support feature
9387 if (hw
->mac
.ops
.set_fw_drv_ver
)
9388 hw
->mac
.ops
.set_fw_drv_ver(hw
, 0xFF, 0xFF, 0xFF,
9391 /* add san mac addr to netdev */
9392 ixgbe_add_sanmac_netdev(netdev
);
9394 e_dev_info("%s\n", ixgbe_default_device_descr
);
9396 #ifdef CONFIG_IXGBE_HWMON
9397 if (ixgbe_sysfs_init(adapter
))
9398 e_err(probe
, "failed to allocate sysfs resources\n");
9399 #endif /* CONFIG_IXGBE_HWMON */
9401 ixgbe_dbg_adapter_init(adapter
);
9403 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
9404 if (ixgbe_mng_enabled(hw
) && ixgbe_is_sfp(hw
) && hw
->mac
.ops
.setup_link
)
9405 hw
->mac
.ops
.setup_link(hw
,
9406 IXGBE_LINK_SPEED_10GB_FULL
| IXGBE_LINK_SPEED_1GB_FULL
,
9412 ixgbe_release_hw_control(adapter
);
9413 ixgbe_clear_interrupt_scheme(adapter
);
9415 ixgbe_disable_sriov(adapter
);
9416 adapter
->flags2
&= ~IXGBE_FLAG2_SEARCH_FOR_SFP
;
9417 iounmap(adapter
->io_addr
);
9418 kfree(adapter
->mac_table
);
9420 disable_dev
= !test_and_set_bit(__IXGBE_DISABLED
, &adapter
->state
);
9421 free_netdev(netdev
);
9423 pci_release_selected_regions(pdev
,
9424 pci_select_bars(pdev
, IORESOURCE_MEM
));
9427 if (!adapter
|| disable_dev
)
9428 pci_disable_device(pdev
);
9433 * ixgbe_remove - Device Removal Routine
9434 * @pdev: PCI device information struct
9436 * ixgbe_remove is called by the PCI subsystem to alert the driver
9437 * that it should release a PCI device. The could be caused by a
9438 * Hot-Plug event, or because the driver is going to be removed from
9441 static void ixgbe_remove(struct pci_dev
*pdev
)
9443 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
9444 struct net_device
*netdev
;
9447 /* if !adapter then we already cleaned up in probe */
9451 netdev
= adapter
->netdev
;
9452 ixgbe_dbg_adapter_exit(adapter
);
9454 set_bit(__IXGBE_REMOVING
, &adapter
->state
);
9455 cancel_work_sync(&adapter
->service_task
);
9458 #ifdef CONFIG_IXGBE_DCA
9459 if (adapter
->flags
& IXGBE_FLAG_DCA_ENABLED
) {
9460 adapter
->flags
&= ~IXGBE_FLAG_DCA_ENABLED
;
9461 dca_remove_requester(&pdev
->dev
);
9462 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_DCA_CTRL
,
9463 IXGBE_DCA_CTRL_DCA_DISABLE
);
9467 #ifdef CONFIG_IXGBE_HWMON
9468 ixgbe_sysfs_exit(adapter
);
9469 #endif /* CONFIG_IXGBE_HWMON */
9471 /* remove the added san mac */
9472 ixgbe_del_sanmac_netdev(netdev
);
9474 #ifdef CONFIG_PCI_IOV
9475 ixgbe_disable_sriov(adapter
);
9477 if (netdev
->reg_state
== NETREG_REGISTERED
)
9478 unregister_netdev(netdev
);
9480 ixgbe_clear_interrupt_scheme(adapter
);
9482 ixgbe_release_hw_control(adapter
);
9485 kfree(adapter
->ixgbe_ieee_pfc
);
9486 kfree(adapter
->ixgbe_ieee_ets
);
9489 iounmap(adapter
->io_addr
);
9490 pci_release_selected_regions(pdev
, pci_select_bars(pdev
,
9493 e_dev_info("complete\n");
9495 kfree(adapter
->mac_table
);
9496 disable_dev
= !test_and_set_bit(__IXGBE_DISABLED
, &adapter
->state
);
9497 free_netdev(netdev
);
9499 pci_disable_pcie_error_reporting(pdev
);
9502 pci_disable_device(pdev
);
9506 * ixgbe_io_error_detected - called when PCI error is detected
9507 * @pdev: Pointer to PCI device
9508 * @state: The current pci connection state
9510 * This function is called after a PCI bus error affecting
9511 * this device has been detected.
9513 static pci_ers_result_t
ixgbe_io_error_detected(struct pci_dev
*pdev
,
9514 pci_channel_state_t state
)
9516 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
9517 struct net_device
*netdev
= adapter
->netdev
;
9519 #ifdef CONFIG_PCI_IOV
9520 struct ixgbe_hw
*hw
= &adapter
->hw
;
9521 struct pci_dev
*bdev
, *vfdev
;
9522 u32 dw0
, dw1
, dw2
, dw3
;
9524 u16 req_id
, pf_func
;
9526 if (adapter
->hw
.mac
.type
== ixgbe_mac_82598EB
||
9527 adapter
->num_vfs
== 0)
9528 goto skip_bad_vf_detection
;
9530 bdev
= pdev
->bus
->self
;
9531 while (bdev
&& (pci_pcie_type(bdev
) != PCI_EXP_TYPE_ROOT_PORT
))
9532 bdev
= bdev
->bus
->self
;
9535 goto skip_bad_vf_detection
;
9537 pos
= pci_find_ext_capability(bdev
, PCI_EXT_CAP_ID_ERR
);
9539 goto skip_bad_vf_detection
;
9541 dw0
= ixgbe_read_pci_cfg_dword(hw
, pos
+ PCI_ERR_HEADER_LOG
);
9542 dw1
= ixgbe_read_pci_cfg_dword(hw
, pos
+ PCI_ERR_HEADER_LOG
+ 4);
9543 dw2
= ixgbe_read_pci_cfg_dword(hw
, pos
+ PCI_ERR_HEADER_LOG
+ 8);
9544 dw3
= ixgbe_read_pci_cfg_dword(hw
, pos
+ PCI_ERR_HEADER_LOG
+ 12);
9545 if (ixgbe_removed(hw
->hw_addr
))
9546 goto skip_bad_vf_detection
;
9549 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
9550 if (!(req_id
& 0x0080))
9551 goto skip_bad_vf_detection
;
9553 pf_func
= req_id
& 0x01;
9554 if ((pf_func
& 1) == (pdev
->devfn
& 1)) {
9555 unsigned int device_id
;
9557 vf
= (req_id
& 0x7F) >> 1;
9558 e_dev_err("VF %d has caused a PCIe error\n", vf
);
9559 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
9560 "%8.8x\tdw3: %8.8x\n",
9561 dw0
, dw1
, dw2
, dw3
);
9562 switch (adapter
->hw
.mac
.type
) {
9563 case ixgbe_mac_82599EB
:
9564 device_id
= IXGBE_82599_VF_DEVICE_ID
;
9566 case ixgbe_mac_X540
:
9567 device_id
= IXGBE_X540_VF_DEVICE_ID
;
9569 case ixgbe_mac_X550
:
9570 device_id
= IXGBE_DEV_ID_X550_VF
;
9572 case ixgbe_mac_X550EM_x
:
9573 device_id
= IXGBE_DEV_ID_X550EM_X_VF
;
9580 /* Find the pci device of the offending VF */
9581 vfdev
= pci_get_device(PCI_VENDOR_ID_INTEL
, device_id
, NULL
);
9583 if (vfdev
->devfn
== (req_id
& 0xFF))
9585 vfdev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
9589 * There's a slim chance the VF could have been hot plugged,
9590 * so if it is no longer present we don't need to issue the
9591 * VFLR. Just clean up the AER in that case.
9594 ixgbe_issue_vf_flr(adapter
, vfdev
);
9595 /* Free device reference count */
9599 pci_cleanup_aer_uncorrect_error_status(pdev
);
9603 * Even though the error may have occurred on the other port
9604 * we still need to increment the vf error reference count for
9605 * both ports because the I/O resume function will be called
9608 adapter
->vferr_refcount
++;
9610 return PCI_ERS_RESULT_RECOVERED
;
9612 skip_bad_vf_detection
:
9613 #endif /* CONFIG_PCI_IOV */
9614 if (!test_bit(__IXGBE_SERVICE_INITED
, &adapter
->state
))
9615 return PCI_ERS_RESULT_DISCONNECT
;
9618 netif_device_detach(netdev
);
9620 if (state
== pci_channel_io_perm_failure
) {
9622 return PCI_ERS_RESULT_DISCONNECT
;
9625 if (netif_running(netdev
))
9626 ixgbe_down(adapter
);
9628 if (!test_and_set_bit(__IXGBE_DISABLED
, &adapter
->state
))
9629 pci_disable_device(pdev
);
9632 /* Request a slot reset. */
9633 return PCI_ERS_RESULT_NEED_RESET
;
9637 * ixgbe_io_slot_reset - called after the pci bus has been reset.
9638 * @pdev: Pointer to PCI device
9640 * Restart the card from scratch, as if from a cold-boot.
9642 static pci_ers_result_t
ixgbe_io_slot_reset(struct pci_dev
*pdev
)
9644 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
9645 pci_ers_result_t result
;
9648 if (pci_enable_device_mem(pdev
)) {
9649 e_err(probe
, "Cannot re-enable PCI device after reset.\n");
9650 result
= PCI_ERS_RESULT_DISCONNECT
;
9652 smp_mb__before_atomic();
9653 clear_bit(__IXGBE_DISABLED
, &adapter
->state
);
9654 adapter
->hw
.hw_addr
= adapter
->io_addr
;
9655 pci_set_master(pdev
);
9656 pci_restore_state(pdev
);
9657 pci_save_state(pdev
);
9659 pci_wake_from_d3(pdev
, false);
9661 ixgbe_reset(adapter
);
9662 IXGBE_WRITE_REG(&adapter
->hw
, IXGBE_WUS
, ~0);
9663 result
= PCI_ERS_RESULT_RECOVERED
;
9666 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
9668 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
9669 "failed 0x%0x\n", err
);
9670 /* non-fatal, continue */
9677 * ixgbe_io_resume - called when traffic can start flowing again.
9678 * @pdev: Pointer to PCI device
9680 * This callback is called when the error recovery driver tells us that
9681 * its OK to resume normal operation.
9683 static void ixgbe_io_resume(struct pci_dev
*pdev
)
9685 struct ixgbe_adapter
*adapter
= pci_get_drvdata(pdev
);
9686 struct net_device
*netdev
= adapter
->netdev
;
9688 #ifdef CONFIG_PCI_IOV
9689 if (adapter
->vferr_refcount
) {
9690 e_info(drv
, "Resuming after VF err\n");
9691 adapter
->vferr_refcount
--;
9696 if (netif_running(netdev
))
9699 netif_device_attach(netdev
);
9702 static const struct pci_error_handlers ixgbe_err_handler
= {
9703 .error_detected
= ixgbe_io_error_detected
,
9704 .slot_reset
= ixgbe_io_slot_reset
,
9705 .resume
= ixgbe_io_resume
,
9708 static struct pci_driver ixgbe_driver
= {
9709 .name
= ixgbe_driver_name
,
9710 .id_table
= ixgbe_pci_tbl
,
9711 .probe
= ixgbe_probe
,
9712 .remove
= ixgbe_remove
,
9714 .suspend
= ixgbe_suspend
,
9715 .resume
= ixgbe_resume
,
9717 .shutdown
= ixgbe_shutdown
,
9718 .sriov_configure
= ixgbe_pci_sriov_configure
,
9719 .err_handler
= &ixgbe_err_handler
9723 * ixgbe_init_module - Driver Registration Routine
9725 * ixgbe_init_module is the first routine called when the driver is
9726 * loaded. All it does is register with the PCI subsystem.
9728 static int __init
ixgbe_init_module(void)
9731 pr_info("%s - version %s\n", ixgbe_driver_string
, ixgbe_driver_version
);
9732 pr_info("%s\n", ixgbe_copyright
);
9734 ixgbe_wq
= create_singlethread_workqueue(ixgbe_driver_name
);
9736 pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name
);
9742 ret
= pci_register_driver(&ixgbe_driver
);
9748 #ifdef CONFIG_IXGBE_DCA
9749 dca_register_notify(&dca_notifier
);
9755 module_init(ixgbe_init_module
);
9758 * ixgbe_exit_module - Driver Exit Cleanup Routine
9760 * ixgbe_exit_module is called just before the driver is removed
9763 static void __exit
ixgbe_exit_module(void)
9765 #ifdef CONFIG_IXGBE_DCA
9766 dca_unregister_notify(&dca_notifier
);
9768 pci_unregister_driver(&ixgbe_driver
);
9772 destroy_workqueue(ixgbe_wq
);
9777 #ifdef CONFIG_IXGBE_DCA
9778 static int ixgbe_notify_dca(struct notifier_block
*nb
, unsigned long event
,
9783 ret_val
= driver_for_each_device(&ixgbe_driver
.driver
, NULL
, &event
,
9784 __ixgbe_notify_dca
);
9786 return ret_val
? NOTIFY_BAD
: NOTIFY_DONE
;
9789 #endif /* CONFIG_IXGBE_DCA */
9791 module_exit(ixgbe_exit_module
);