blob: 5c671b7401cd91294dcbab29f67b74ef9e73de1f [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Mark Rustad37689012016-01-07 10:13:03 -08004 Copyright(c) 1999 - 2016 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
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.
9
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
13 more details.
14
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.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Jacob Kellerb89aae72014-02-22 01:23:50 +000023 Linux NICS <linux.nics@intel.com>
Auke Kok9a799d72007-09-15 14:07:45 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
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>
35#include <linux/in.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000036#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070037#include <linux/ip.h>
38#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000039#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000040#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070041#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090042#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070043#include <net/checksum.h>
44#include <net/ip6_checksum.h>
Martin K Petersenc762dff2014-11-15 14:24:51 +000045#include <linux/etherdevice.h>
Auke Kok9a799d72007-09-15 14:07:45 -070046#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000047#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070048#include <linux/if_vlan.h>
John Fastabend2a47fa42013-11-06 09:54:52 -080049#include <linux/if_macvlan.h>
John Fastabend815cccb2012-10-24 08:13:09 +000050#include <linux/if_bridge.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040051#include <linux/prefetch.h>
John Fastabend92470802017-04-24 03:30:17 -070052#include <linux/bpf.h>
53#include <linux/bpf_trace.h>
54#include <linux/atomic.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000055#include <scsi/fc/fc_fcoe.h>
Alexander Duyckb3a49552016-06-16 12:22:19 -070056#include <net/udp_tunnel.h>
John Fastabendb82b17d2016-02-16 21:18:53 -080057#include <net/pkt_cls.h>
58#include <net/tc_act/tc_gact.h>
Sridhar Samudrala947f8a42016-04-05 10:39:07 -070059#include <net/tc_act/tc_mirred.h>
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -070060#include <net/vxlan.h>
Scott Peterson2a205252016-11-18 11:25:42 -080061#include <net/mpls.h>
Auke Kok9a799d72007-09-15 14:07:45 -070062
63#include "ixgbe.h"
64#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000065#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000066#include "ixgbe_sriov.h"
John Fastabendb82b17d2016-02-16 21:18:53 -080067#include "ixgbe_model.h"
Auke Kok9a799d72007-09-15 14:07:45 -070068
69char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070070static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000071 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000072#ifdef IXGBE_FCOE
Neerav Parikhea818752012-01-04 20:23:40 +000073char ixgbe_default_device_descr[] =
74 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000075#else
76static char ixgbe_default_device_descr[] =
77 "Intel(R) 10 Gigabit Network Connection";
78#endif
Mark Rustad17332842016-12-12 15:08:13 -080079#define DRV_VERSION "5.0.0-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070080const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000081static const char ixgbe_copyright[] =
Mark Rustad49425df2016-04-01 12:18:09 -070082 "Copyright (c) 1999-2016 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070083
Don Skidmoref44e7512015-06-09 16:36:23 -070084static 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";
85
Auke Kok9a799d72007-09-15 14:07:45 -070086static const struct ixgbe_info *ixgbe_info_tbl[] = {
Don Skidmore6a14ee02014-12-05 03:59:50 +000087 [board_82598] = &ixgbe_82598_info,
88 [board_82599] = &ixgbe_82599_info,
89 [board_X540] = &ixgbe_X540_info,
90 [board_X550] = &ixgbe_X550_info,
91 [board_X550EM_x] = &ixgbe_X550EM_x_info,
Paul Greenwalt8dc963e2017-04-13 08:07:07 -040092 [board_x550em_x_fw] = &ixgbe_x550em_x_fw_info,
Mark Rustad49425df2016-04-01 12:18:09 -070093 [board_x550em_a] = &ixgbe_x550em_a_info,
Mark Rustadb3eb4e12016-12-14 11:02:16 -080094 [board_x550em_a_fw] = &ixgbe_x550em_a_fw_info,
Auke Kok9a799d72007-09-15 14:07:45 -070095};
96
97/* ixgbe_pci_tbl - PCI Device ID Table
98 *
99 * Wildcard entries (PCI_ANY_ID) should come last
100 * Last entry must be all 0s
101 *
102 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
103 * Class, Class Mask, private data (not used) }
104 */
Benoit Taine9baa3c32014-08-08 15:56:03 +0200105static const struct pci_device_id ixgbe_pci_tbl[] = {
Alexander Duyck54239c62011-07-15 03:06:06 +0000106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
118 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
119 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
120 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
121 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
122 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
123 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
124 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
125 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
126 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
127 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
128 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
129 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
130 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
131 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Don Skidmore8f583322013-07-27 06:25:38 +0000132 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000133 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000134 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +0000135 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
Don Skidmore6a14ee02014-12-05 03:59:50 +0000136 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550},
Mark Rustada711ad82016-03-21 11:21:31 -0700137 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550},
Don Skidmore6a14ee02014-12-05 03:59:50 +0000138 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x},
Don Skidmore18e01ee2016-12-30 21:07:58 -0500139 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_XFI), board_X550EM_x},
Don Skidmore6a14ee02014-12-05 03:59:50 +0000140 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x},
Don Skidmorededa5622015-06-09 17:39:46 -0700141 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x},
Mark Rustad018d7142015-08-08 16:19:19 -0700142 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x},
Paul Greenwalt8dc963e2017-04-13 08:07:07 -0400143 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_1G_T), board_x550em_x_fw},
Mark Rustadf572b2c2016-04-01 12:18:46 -0700144 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a },
145 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR_L), board_x550em_a },
Mark Rustad49425df2016-04-01 12:18:09 -0700146 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP_N), board_x550em_a },
Mark Rustad200157c2016-04-01 12:18:40 -0700147 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a },
148 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII_L), board_x550em_a },
Don Skidmore92ed8432016-08-17 20:34:40 -0400149 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_10G_T), board_x550em_a},
Mark Rustad2d40cd12016-04-01 12:18:35 -0700150 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a },
Mark Rustadb3eb4e12016-12-14 11:02:16 -0800151 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T), board_x550em_a_fw },
152 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T_L), board_x550em_a_fw },
Auke Kok9a799d72007-09-15 14:07:45 -0700153 /* required last entry */
154 {0, }
155};
156MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
157
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400158#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800159static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000160 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800161static struct notifier_block dca_notifier = {
162 .notifier_call = ixgbe_notify_dca,
163 .next = NULL,
164 .priority = 0
165};
166#endif
167
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000168#ifdef CONFIG_PCI_IOV
169static unsigned int max_vfs;
170module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000171MODULE_PARM_DESC(max_vfs,
Jacob Keller170e8542013-11-09 04:52:32 -0800172 "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63. (Deprecated)");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000173#endif /* CONFIG_PCI_IOV */
174
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000175static unsigned int allow_unsupported_sfp;
176module_param(allow_unsupported_sfp, uint, 0);
177MODULE_PARM_DESC(allow_unsupported_sfp,
178 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
179
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000180#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
181static int debug = -1;
182module_param(debug, int, 0);
183MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
184
Auke Kok9a799d72007-09-15 14:07:45 -0700185MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
186MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
187MODULE_LICENSE("GPL");
188MODULE_VERSION(DRV_VERSION);
189
Mark Rustad780484d2015-10-21 17:21:10 -0700190static struct workqueue_struct *ixgbe_wq;
191
Mark Rustad14438462014-02-28 15:48:57 -0800192static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
Mark Rustadb3eb4e12016-12-14 11:02:16 -0800193static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *);
Mark Rustad14438462014-02-28 15:48:57 -0800194
Jacob Kellerb8e82002013-04-09 07:20:09 +0000195static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
196 u32 reg, u16 *value)
197{
Jacob Kellerb8e82002013-04-09 07:20:09 +0000198 struct pci_dev *parent_dev;
199 struct pci_bus *parent_bus;
200
201 parent_bus = adapter->pdev->bus->parent;
202 if (!parent_bus)
203 return -1;
204
205 parent_dev = parent_bus->self;
206 if (!parent_dev)
207 return -1;
208
Yijing Wangc0798ed2013-09-04 17:30:08 +0000209 if (!pci_is_pcie(parent_dev))
Jacob Kellerb8e82002013-04-09 07:20:09 +0000210 return -1;
211
Yijing Wangc0798ed2013-09-04 17:30:08 +0000212 pcie_capability_read_word(parent_dev, reg, value);
Mark Rustad14438462014-02-28 15:48:57 -0800213 if (*value == IXGBE_FAILED_READ_CFG_WORD &&
214 ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
215 return -1;
Jacob Kellerb8e82002013-04-09 07:20:09 +0000216 return 0;
217}
218
219static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
220{
221 struct ixgbe_hw *hw = &adapter->hw;
222 u16 link_status = 0;
223 int err;
224
225 hw->bus.type = ixgbe_bus_type_pci_express;
226
227 /* Get the negotiated link width and speed from PCI config space of the
228 * parent, as this device is behind a switch
229 */
230 err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
231
232 /* assume caller will handle error case */
233 if (err)
234 return err;
235
236 hw->bus.width = ixgbe_convert_bus_width(link_status);
237 hw->bus.speed = ixgbe_convert_bus_speed(link_status);
238
239 return 0;
240}
241
Jacob Kellere027d1a2013-07-31 06:53:31 +0000242/**
243 * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
244 * @hw: hw specific details
245 *
246 * This function is used by probe to determine whether a device's PCI-Express
247 * bandwidth details should be gathered from the parent bus instead of from the
248 * device. Used to ensure that various locations all have the correct device ID
249 * checks.
250 */
251static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
252{
253 switch (hw->device_id) {
254 case IXGBE_DEV_ID_82599_SFP_SF_QP:
Don Skidmore8f583322013-07-27 06:25:38 +0000255 case IXGBE_DEV_ID_82599_QSFP_SF_QP:
Jacob Kellere027d1a2013-07-31 06:53:31 +0000256 return true;
257 default:
258 return false;
259 }
260}
261
262static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
263 int expected_gts)
264{
Don Skidmoref9328bc2015-06-18 13:24:06 -0400265 struct ixgbe_hw *hw = &adapter->hw;
Jacob Kellere027d1a2013-07-31 06:53:31 +0000266 int max_gts = 0;
267 enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
268 enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
269 struct pci_dev *pdev;
270
Don Skidmoref9328bc2015-06-18 13:24:06 -0400271 /* Some devices are not connected over PCIe and thus do not negotiate
272 * speed. These devices do not have valid bus info, and thus any report
273 * we generate may not be correct.
274 */
275 if (hw->bus.type == ixgbe_bus_type_internal)
276 return;
277
Jacob Keller56d13922015-06-10 11:44:45 -0700278 /* determine whether to use the parent device */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000279 if (ixgbe_pcie_from_parent(&adapter->hw))
280 pdev = adapter->pdev->bus->parent->self;
281 else
282 pdev = adapter->pdev;
283
284 if (pcie_get_minimum_link(pdev, &speed, &width) ||
285 speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
286 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
287 return;
288 }
289
290 switch (speed) {
291 case PCIE_SPEED_2_5GT:
292 /* 8b/10b encoding reduces max throughput by 20% */
293 max_gts = 2 * width;
294 break;
295 case PCIE_SPEED_5_0GT:
296 /* 8b/10b encoding reduces max throughput by 20% */
297 max_gts = 4 * width;
298 break;
299 case PCIE_SPEED_8_0GT:
Jacob Keller9f0a4332013-10-18 05:09:19 +0000300 /* 128b/130b encoding reduces throughput by less than 2% */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000301 max_gts = 8 * width;
302 break;
303 default:
304 e_dev_warn("Unable to determine PCI Express bandwidth.\n");
305 return;
306 }
307
308 e_dev_info("PCI Express bandwidth of %dGT/s available\n",
309 max_gts);
310 e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n",
311 (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
312 speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
313 speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
314 "Unknown"),
315 width,
316 (speed == PCIE_SPEED_2_5GT ? "20%" :
317 speed == PCIE_SPEED_5_0GT ? "20%" :
Jacob Keller9f0a4332013-10-18 05:09:19 +0000318 speed == PCIE_SPEED_8_0GT ? "<2%" :
Jacob Kellere027d1a2013-07-31 06:53:31 +0000319 "Unknown"));
320
321 if (max_gts < expected_gts) {
322 e_dev_warn("This is not sufficient for optimal performance of this card.\n");
323 e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n",
324 expected_gts);
325 e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n");
326 }
327}
328
Alexander Duyck70864002011-04-27 09:13:56 +0000329static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
330{
331 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
Mark Rustad09f40ae2014-01-14 18:53:11 -0800332 !test_bit(__IXGBE_REMOVING, &adapter->state) &&
Alexander Duyck70864002011-04-27 09:13:56 +0000333 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
Mark Rustad780484d2015-10-21 17:21:10 -0700334 queue_work(ixgbe_wq, &adapter->service_task);
Alexander Duyck70864002011-04-27 09:13:56 +0000335}
336
Mark Rustad2a1a0912014-01-14 18:53:15 -0800337static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
338{
339 struct ixgbe_adapter *adapter = hw->back;
340
341 if (!hw->hw_addr)
342 return;
343 hw->hw_addr = NULL;
344 e_dev_err("Adapter removed\n");
Mark Rustad58cf6632014-03-12 00:38:40 +0000345 if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
346 ixgbe_service_event_schedule(adapter);
Mark Rustad2a1a0912014-01-14 18:53:15 -0800347}
348
Mark Rustadf8e24722014-03-18 07:03:40 +0000349static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
Mark Rustad2a1a0912014-01-14 18:53:15 -0800350{
351 u32 value;
352
353 /* The following check not only optimizes a bit by not
354 * performing a read on the status register when the
355 * register just read was a status register read that
356 * returned IXGBE_FAILED_READ_REG. It also blocks any
357 * potential recursion.
358 */
359 if (reg == IXGBE_STATUS) {
360 ixgbe_remove_adapter(hw);
361 return;
362 }
363 value = ixgbe_read_reg(hw, IXGBE_STATUS);
364 if (value == IXGBE_FAILED_READ_REG)
365 ixgbe_remove_adapter(hw);
366}
367
Mark Rustadf8e24722014-03-18 07:03:40 +0000368/**
369 * ixgbe_read_reg - Read from device register
370 * @hw: hw specific details
371 * @reg: offset of register to read
372 *
373 * Returns : value read or IXGBE_FAILED_READ_REG if removed
374 *
375 * This function is used to read device registers. It checks for device
376 * removal by confirming any read that returns all ones by checking the
377 * status register value for all ones. This function avoids reading from
378 * the hardware if a removal was previously detected in which case it
379 * returns IXGBE_FAILED_READ_REG (all ones).
380 */
381u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
382{
383 u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
384 u32 value;
385
386 if (ixgbe_removed(reg_addr))
387 return IXGBE_FAILED_READ_REG;
Mark Rustad2f2219b2016-04-07 10:43:50 -0700388 if (unlikely(hw->phy.nw_mng_if_sel &
389 IXGBE_NW_MNG_IF_SEL_ENABLE_10_100M)) {
390 struct ixgbe_adapter *adapter;
391 int i;
392
393 for (i = 0; i < 200; ++i) {
394 value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY);
395 if (likely(!value))
396 goto writes_completed;
397 if (value == IXGBE_FAILED_READ_REG) {
398 ixgbe_remove_adapter(hw);
399 return IXGBE_FAILED_READ_REG;
400 }
401 udelay(5);
402 }
403
404 adapter = hw->back;
405 e_warn(hw, "register writes incomplete %08x\n", value);
406 }
407
408writes_completed:
Mark Rustadf8e24722014-03-18 07:03:40 +0000409 value = readl(reg_addr + reg);
410 if (unlikely(value == IXGBE_FAILED_READ_REG))
411 ixgbe_check_remove(hw, reg);
412 return value;
413}
414
Mark Rustad14438462014-02-28 15:48:57 -0800415static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
416{
417 u16 value;
418
419 pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
420 if (value == IXGBE_FAILED_READ_CFG_WORD) {
421 ixgbe_remove_adapter(hw);
422 return true;
423 }
424 return false;
425}
426
427u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
428{
429 struct ixgbe_adapter *adapter = hw->back;
430 u16 value;
431
432 if (ixgbe_removed(hw->hw_addr))
433 return IXGBE_FAILED_READ_CFG_WORD;
434 pci_read_config_word(adapter->pdev, reg, &value);
435 if (value == IXGBE_FAILED_READ_CFG_WORD &&
436 ixgbe_check_cfg_remove(hw, adapter->pdev))
437 return IXGBE_FAILED_READ_CFG_WORD;
438 return value;
439}
440
441#ifdef CONFIG_PCI_IOV
442static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
443{
444 struct ixgbe_adapter *adapter = hw->back;
445 u32 value;
446
447 if (ixgbe_removed(hw->hw_addr))
448 return IXGBE_FAILED_READ_CFG_DWORD;
449 pci_read_config_dword(adapter->pdev, reg, &value);
450 if (value == IXGBE_FAILED_READ_CFG_DWORD &&
451 ixgbe_check_cfg_remove(hw, adapter->pdev))
452 return IXGBE_FAILED_READ_CFG_DWORD;
453 return value;
454}
455#endif /* CONFIG_PCI_IOV */
456
Jacob Kellered192312014-02-22 01:23:53 +0000457void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
458{
459 struct ixgbe_adapter *adapter = hw->back;
460
461 if (ixgbe_removed(hw->hw_addr))
462 return;
463 pci_write_config_word(adapter->pdev, reg, value);
464}
465
Alexander Duyck70864002011-04-27 09:13:56 +0000466static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
467{
468 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
469
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000470 /* flush memory to make sure state is correct before next watchdog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +0100471 smp_mb__before_atomic();
Alexander Duyck70864002011-04-27 09:13:56 +0000472 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
473}
474
Taku Izumidcd79ae2010-04-27 14:39:53 +0000475struct ixgbe_reg_info {
476 u32 ofs;
477 char *name;
478};
479
480static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
481
482 /* General Registers */
483 {IXGBE_CTRL, "CTRL"},
484 {IXGBE_STATUS, "STATUS"},
485 {IXGBE_CTRL_EXT, "CTRL_EXT"},
486
487 /* Interrupt Registers */
488 {IXGBE_EICR, "EICR"},
489
490 /* RX Registers */
491 {IXGBE_SRRCTL(0), "SRRCTL"},
492 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
493 {IXGBE_RDLEN(0), "RDLEN"},
494 {IXGBE_RDH(0), "RDH"},
495 {IXGBE_RDT(0), "RDT"},
496 {IXGBE_RXDCTL(0), "RXDCTL"},
497 {IXGBE_RDBAL(0), "RDBAL"},
498 {IXGBE_RDBAH(0), "RDBAH"},
499
500 /* TX Registers */
501 {IXGBE_TDBAL(0), "TDBAL"},
502 {IXGBE_TDBAH(0), "TDBAH"},
503 {IXGBE_TDLEN(0), "TDLEN"},
504 {IXGBE_TDH(0), "TDH"},
505 {IXGBE_TDT(0), "TDT"},
506 {IXGBE_TXDCTL(0), "TXDCTL"},
507
508 /* List Terminator */
Mark Rustadca8dfe22014-07-24 06:19:24 +0000509 { .name = NULL }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000510};
511
512
513/*
514 * ixgbe_regdump - register printout routine
515 */
516static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
517{
Joe Perches332f2352017-01-03 07:28:11 -0800518 int i;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000519 char rname[16];
520 u32 regs[64];
521
522 switch (reginfo->ofs) {
523 case IXGBE_SRRCTL(0):
524 for (i = 0; i < 64; i++)
525 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
526 break;
527 case IXGBE_DCA_RXCTRL(0):
528 for (i = 0; i < 64; i++)
529 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
530 break;
531 case IXGBE_RDLEN(0):
532 for (i = 0; i < 64; i++)
533 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
534 break;
535 case IXGBE_RDH(0):
536 for (i = 0; i < 64; i++)
537 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
538 break;
539 case IXGBE_RDT(0):
540 for (i = 0; i < 64; i++)
541 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
542 break;
543 case IXGBE_RXDCTL(0):
544 for (i = 0; i < 64; i++)
545 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
546 break;
547 case IXGBE_RDBAL(0):
548 for (i = 0; i < 64; i++)
549 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
550 break;
551 case IXGBE_RDBAH(0):
552 for (i = 0; i < 64; i++)
553 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
554 break;
555 case IXGBE_TDBAL(0):
556 for (i = 0; i < 64; i++)
557 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
558 break;
559 case IXGBE_TDBAH(0):
560 for (i = 0; i < 64; i++)
561 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
562 break;
563 case IXGBE_TDLEN(0):
564 for (i = 0; i < 64; i++)
565 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
566 break;
567 case IXGBE_TDH(0):
568 for (i = 0; i < 64; i++)
569 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
570 break;
571 case IXGBE_TDT(0):
572 for (i = 0; i < 64; i++)
573 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
574 break;
575 case IXGBE_TXDCTL(0):
576 for (i = 0; i < 64; i++)
577 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
578 break;
579 default:
Joe Perches332f2352017-01-03 07:28:11 -0800580 pr_info("%-15s %08x\n",
581 reginfo->name, IXGBE_READ_REG(hw, reginfo->ofs));
Taku Izumidcd79ae2010-04-27 14:39:53 +0000582 return;
583 }
584
Joe Perches332f2352017-01-03 07:28:11 -0800585 i = 0;
586 while (i < 64) {
587 int j;
588 char buf[9 * 8 + 1];
589 char *p = buf;
590
591 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i, i + 7);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000592 for (j = 0; j < 8; j++)
Joe Perches332f2352017-01-03 07:28:11 -0800593 p += sprintf(p, " %08x", regs[i++]);
594 pr_err("%-15s%s\n", rname, buf);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000595 }
596
597}
598
John Fastabend33fdc822017-04-24 03:30:18 -0700599static void ixgbe_print_buffer(struct ixgbe_ring *ring, int n)
600{
601 struct ixgbe_tx_buffer *tx_buffer;
602
603 tx_buffer = &ring->tx_buffer_info[ring->next_to_clean];
604 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
605 n, ring->next_to_use, ring->next_to_clean,
606 (u64)dma_unmap_addr(tx_buffer, dma),
607 dma_unmap_len(tx_buffer, len),
608 tx_buffer->next_to_watch,
609 (u64)tx_buffer->time_stamp);
610}
611
Taku Izumidcd79ae2010-04-27 14:39:53 +0000612/*
613 * ixgbe_dump - Print registers, tx-rings and rx-rings
614 */
615static void ixgbe_dump(struct ixgbe_adapter *adapter)
616{
617 struct net_device *netdev = adapter->netdev;
618 struct ixgbe_hw *hw = &adapter->hw;
619 struct ixgbe_reg_info *reginfo;
620 int n = 0;
John Fastabend33fdc822017-04-24 03:30:18 -0700621 struct ixgbe_ring *ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000622 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000623 union ixgbe_adv_tx_desc *tx_desc;
624 struct my_u0 { u64 a; u64 b; } *u0;
625 struct ixgbe_ring *rx_ring;
626 union ixgbe_adv_rx_desc *rx_desc;
627 struct ixgbe_rx_buffer *rx_buffer_info;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000628 int i = 0;
629
630 if (!netif_msg_hw(adapter))
631 return;
632
633 /* Print netdevice Info */
634 if (netdev) {
635 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000636 pr_info("Device Name state "
Tobias Klauser4a7c9722017-01-18 17:45:01 +0100637 "trans_start\n");
638 pr_info("%-15s %016lX %016lX\n",
Joe Perchesc7689572010-09-07 21:35:17 +0000639 netdev->name,
640 netdev->state,
Tobias Klauser4a7c9722017-01-18 17:45:01 +0100641 dev_trans_start(netdev));
Taku Izumidcd79ae2010-04-27 14:39:53 +0000642 }
643
644 /* Print Registers */
645 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000646 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000647 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
648 reginfo->name; reginfo++) {
649 ixgbe_regdump(hw, reginfo);
650 }
651
652 /* Print TX Ring Summary */
653 if (!netdev || !netif_running(netdev))
Mark Rustade90dd262014-07-22 06:51:08 +0000654 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000655
656 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000657 pr_info(" %s %s %s %s\n",
658 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
659 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000660 for (n = 0; n < adapter->num_tx_queues; n++) {
John Fastabend33fdc822017-04-24 03:30:18 -0700661 ring = adapter->tx_ring[n];
662 ixgbe_print_buffer(ring, n);
663 }
664
665 for (n = 0; n < adapter->num_xdp_queues; n++) {
666 ring = adapter->xdp_ring[n];
667 ixgbe_print_buffer(ring, n);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000668 }
669
670 /* Print TX Rings */
671 if (!netif_msg_tx_done(adapter))
672 goto rx_ring_summary;
673
674 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
675
676 /* Transmit Descriptor Formats
677 *
Josh Hay39ac8682012-09-26 05:59:36 +0000678 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000679 * +--------------------------------------------------------------+
680 * 0 | Buffer Address [63:0] |
681 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000682 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000683 * +--------------------------------------------------------------+
684 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000685 *
686 * 82598 Advanced Transmit Descriptor (Write-Back Format)
687 * +--------------------------------------------------------------+
688 * 0 | RSV [63:0] |
689 * +--------------------------------------------------------------+
690 * 8 | RSV | STA | NXTSEQ |
691 * +--------------------------------------------------------------+
692 * 63 36 35 32 31 0
693 *
694 * 82599+ Advanced Transmit Descriptor
695 * +--------------------------------------------------------------+
696 * 0 | Buffer Address [63:0] |
697 * +--------------------------------------------------------------+
698 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
699 * +--------------------------------------------------------------+
700 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
701 *
702 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
703 * +--------------------------------------------------------------+
704 * 0 | RSV [63:0] |
705 * +--------------------------------------------------------------+
706 * 8 | RSV | STA | RSV |
707 * +--------------------------------------------------------------+
708 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000709 */
710
711 for (n = 0; n < adapter->num_tx_queues; n++) {
John Fastabend33fdc822017-04-24 03:30:18 -0700712 ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000713 pr_info("------------------------------------\n");
John Fastabend33fdc822017-04-24 03:30:18 -0700714 pr_info("TX QUEUE INDEX = %d\n", ring->queue_index);
Joe Perchesc7689572010-09-07 21:35:17 +0000715 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000716 pr_info("%s%s %s %s %s %s\n",
717 "T [desc] [address 63:0 ] ",
718 "[PlPOIdStDDt Ln] [bi->dma ] ",
719 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000720
John Fastabend33fdc822017-04-24 03:30:18 -0700721 for (i = 0; ring->desc && (i < ring->count); i++) {
722 tx_desc = IXGBE_TX_DESC(ring, i);
723 tx_buffer = &ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000724 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000725 if (dma_unmap_len(tx_buffer, len) > 0) {
Joe Perches332f2352017-01-03 07:28:11 -0800726 const char *ring_desc;
727
John Fastabend33fdc822017-04-24 03:30:18 -0700728 if (i == ring->next_to_use &&
729 i == ring->next_to_clean)
Joe Perches332f2352017-01-03 07:28:11 -0800730 ring_desc = " NTC/U";
John Fastabend33fdc822017-04-24 03:30:18 -0700731 else if (i == ring->next_to_use)
Joe Perches332f2352017-01-03 07:28:11 -0800732 ring_desc = " NTU";
John Fastabend33fdc822017-04-24 03:30:18 -0700733 else if (i == ring->next_to_clean)
Joe Perches332f2352017-01-03 07:28:11 -0800734 ring_desc = " NTC";
735 else
736 ring_desc = "";
737 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p%s",
Josh Hay8ad88e32012-09-26 05:59:41 +0000738 i,
739 le64_to_cpu(u0->a),
740 le64_to_cpu(u0->b),
741 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000742 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000743 tx_buffer->next_to_watch,
744 (u64)tx_buffer->time_stamp,
Joe Perches332f2352017-01-03 07:28:11 -0800745 tx_buffer->skb,
746 ring_desc);
Josh Hay8ad88e32012-09-26 05:59:41 +0000747
748 if (netif_msg_pktdata(adapter) &&
749 tx_buffer->skb)
750 print_hex_dump(KERN_INFO, "",
751 DUMP_PREFIX_ADDRESS, 16, 1,
752 tx_buffer->skb->data,
753 dma_unmap_len(tx_buffer, len),
754 true);
755 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000756 }
757 }
758
759 /* Print RX Rings Summary */
760rx_ring_summary:
761 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000762 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000763 for (n = 0; n < adapter->num_rx_queues; n++) {
764 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000765 pr_info("%5d %5X %5X\n",
766 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000767 }
768
769 /* Print RX Rings */
770 if (!netif_msg_rx_status(adapter))
Mark Rustade90dd262014-07-22 06:51:08 +0000771 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000772
773 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
774
Josh Hay39ac8682012-09-26 05:59:36 +0000775 /* Receive Descriptor Formats
776 *
777 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000778 * 63 1 0
779 * +-----------------------------------------------------+
780 * 0 | Packet Buffer Address [63:1] |A0/NSE|
781 * +----------------------------------------------+------+
782 * 8 | Header Buffer Address [63:1] | DD |
783 * +-----------------------------------------------------+
784 *
785 *
Josh Hay39ac8682012-09-26 05:59:36 +0000786 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000787 *
788 * 63 48 47 32 31 30 21 20 16 15 4 3 0
789 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000790 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
791 * | Packet | IP | | | | Type | Type |
792 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000793 * +------------------------------------------------------+
794 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
795 * +------------------------------------------------------+
796 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000797 *
798 * 82599+ Advanced Receive Descriptor (Read) Format
799 * 63 1 0
800 * +-----------------------------------------------------+
801 * 0 | Packet Buffer Address [63:1] |A0/NSE|
802 * +----------------------------------------------+------+
803 * 8 | Header Buffer Address [63:1] | DD |
804 * +-----------------------------------------------------+
805 *
806 *
807 * 82599+ Advanced Receive Descriptor (Write-Back) Format
808 *
809 * 63 48 47 32 31 30 21 20 17 16 4 3 0
810 * +------------------------------------------------------+
811 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
812 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
813 * |/ Flow Dir Flt ID | | | | | |
814 * +------------------------------------------------------+
815 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
816 * +------------------------------------------------------+
817 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000818 */
Josh Hay39ac8682012-09-26 05:59:36 +0000819
Taku Izumidcd79ae2010-04-27 14:39:53 +0000820 for (n = 0; n < adapter->num_rx_queues; n++) {
821 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000822 pr_info("------------------------------------\n");
823 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
824 pr_info("------------------------------------\n");
Joe Perches332f2352017-01-03 07:28:11 -0800825 pr_info("%s%s%s\n",
Josh Hay8ad88e32012-09-26 05:59:41 +0000826 "R [desc] [ PktBuf A0] ",
827 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Joe Perches332f2352017-01-03 07:28:11 -0800828 "<-- Adv Rx Read format");
829 pr_info("%s%s%s\n",
Josh Hay8ad88e32012-09-26 05:59:41 +0000830 "RWB[desc] [PcsmIpSHl PtRs] ",
831 "[vl er S cks ln] ---------------- [bi->skb ] ",
Joe Perches332f2352017-01-03 07:28:11 -0800832 "<-- Adv Rx Write-Back format");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000833
834 for (i = 0; i < rx_ring->count; i++) {
Joe Perches332f2352017-01-03 07:28:11 -0800835 const char *ring_desc;
836
837 if (i == rx_ring->next_to_use)
838 ring_desc = " NTU";
839 else if (i == rx_ring->next_to_clean)
840 ring_desc = " NTC";
841 else
842 ring_desc = "";
843
Taku Izumidcd79ae2010-04-27 14:39:53 +0000844 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000845 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000846 u0 = (struct my_u0 *)rx_desc;
Alexander Duyck18a8cc92017-03-02 15:01:36 -0800847 if (rx_desc->wb.upper.length) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000848 /* Descriptor Done */
Joe Perches332f2352017-01-03 07:28:11 -0800849 pr_info("RWB[0x%03X] %016llX %016llX ---------------- %p%s\n",
850 i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000851 le64_to_cpu(u0->a),
852 le64_to_cpu(u0->b),
Joe Perches332f2352017-01-03 07:28:11 -0800853 rx_buffer_info->skb,
854 ring_desc);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000855 } else {
Joe Perches332f2352017-01-03 07:28:11 -0800856 pr_info("R [0x%03X] %016llX %016llX %016llX %p%s\n",
857 i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000858 le64_to_cpu(u0->a),
859 le64_to_cpu(u0->b),
860 (u64)rx_buffer_info->dma,
Joe Perches332f2352017-01-03 07:28:11 -0800861 rx_buffer_info->skb,
862 ring_desc);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000863
Emil Tantilov9c50c032012-07-26 01:21:24 +0000864 if (netif_msg_pktdata(adapter) &&
865 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000866 print_hex_dump(KERN_INFO, "",
867 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000868 page_address(rx_buffer_info->page) +
869 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000870 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000871 }
872 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000873 }
874 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000875}
876
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800877static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
878{
879 u32 ctrl_ext;
880
881 /* Let firmware take over control of h/w */
882 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
883 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000884 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800885}
886
887static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
888{
889 u32 ctrl_ext;
890
891 /* Let firmware know the driver has taken over */
892 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
893 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000894 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800895}
Auke Kok9a799d72007-09-15 14:07:45 -0700896
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000897/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000898 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
899 * @adapter: pointer to adapter struct
900 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
901 * @queue: queue to map the corresponding interrupt to
902 * @msix_vector: the vector to map to the corresponding queue
903 *
904 */
905static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000906 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700907{
908 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000909 struct ixgbe_hw *hw = &adapter->hw;
910 switch (hw->mac.type) {
911 case ixgbe_mac_82598EB:
912 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
913 if (direction == -1)
914 direction = 0;
915 index = (((direction * 64) + queue) >> 2) & 0x1F;
916 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
917 ivar &= ~(0xFF << (8 * (queue & 0x3)));
918 ivar |= (msix_vector << (8 * (queue & 0x3)));
919 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
920 break;
921 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800922 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000923 case ixgbe_mac_X550:
924 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700925 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000926 if (direction == -1) {
927 /* other causes */
928 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
929 index = ((queue & 1) * 8);
930 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
931 ivar &= ~(0xFF << index);
932 ivar |= (msix_vector << index);
933 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
934 break;
935 } else {
936 /* tx or rx causes */
937 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
938 index = ((16 * (queue & 1)) + (8 * direction));
939 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
940 ivar &= ~(0xFF << index);
941 ivar |= (msix_vector << index);
942 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
943 break;
944 }
945 default:
946 break;
947 }
Auke Kok9a799d72007-09-15 14:07:45 -0700948}
949
Alexander Duyckfe49f042009-06-04 16:00:09 +0000950static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000951 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000952{
953 u32 mask;
954
Alexander Duyckbd508172010-11-16 19:27:03 -0800955 switch (adapter->hw.mac.type) {
956 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000957 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
958 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800959 break;
960 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800961 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000962 case ixgbe_mac_X550:
963 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700964 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000965 mask = (qmask & 0xFFFFFFFF);
966 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
967 mask = (qmask >> 32);
968 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800969 break;
970 default:
971 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000972 }
973}
974
Alexander Duyck943561d2012-05-09 22:14:44 -0700975static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
976{
977 struct ixgbe_hw *hw = &adapter->hw;
978 struct ixgbe_hw_stats *hwstats = &adapter->stats;
979 int i;
980 u32 data;
981
982 if ((hw->fc.current_mode != ixgbe_fc_full) &&
983 (hw->fc.current_mode != ixgbe_fc_rx_pause))
984 return;
985
986 switch (hw->mac.type) {
987 case ixgbe_mac_82598EB:
988 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
989 break;
990 default:
991 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
992 }
993 hwstats->lxoffrxc += data;
994
995 /* refill credits (no tx hang) if we received xoff */
996 if (!data)
997 return;
998
999 for (i = 0; i < adapter->num_tx_queues; i++)
1000 clear_bit(__IXGBE_HANG_CHECK_ARMED,
1001 &adapter->tx_ring[i]->state);
John Fastabend33fdc822017-04-24 03:30:18 -07001002
1003 for (i = 0; i < adapter->num_xdp_queues; i++)
1004 clear_bit(__IXGBE_HANG_CHECK_ARMED,
1005 &adapter->xdp_ring[i]->state);
Alexander Duyck943561d2012-05-09 22:14:44 -07001006}
1007
John Fastabendc84d3242010-11-16 19:27:12 -08001008static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001009{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001010 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -08001011 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -08001012 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001013 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -08001014 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -07001015 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001016
Alexander Duyck943561d2012-05-09 22:14:44 -07001017 if (adapter->ixgbe_ieee_pfc)
1018 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -08001019
Alexander Duyck943561d2012-05-09 22:14:44 -07001020 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
1021 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -08001022 return;
Alexander Duyck943561d2012-05-09 22:14:44 -07001023 }
John Fastabendc84d3242010-11-16 19:27:12 -08001024
1025 /* update stats for each tc, only valid with PFC enabled */
1026 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001027 u32 pxoffrxc;
1028
John Fastabendc84d3242010-11-16 19:27:12 -08001029 switch (hw->mac.type) {
1030 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001031 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -08001032 break;
1033 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001034 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -08001035 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001036 hwstats->pxoffrxc[i] += pxoffrxc;
1037 /* Get the TC for given UP */
1038 tc = netdev_get_prio_tc_map(adapter->netdev, i);
1039 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -07001040 }
1041
John Fastabendc84d3242010-11-16 19:27:12 -08001042 /* disarm tx queues that have received xoff frames */
1043 for (i = 0; i < adapter->num_tx_queues; i++) {
1044 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -08001045
Parikh, Neerav2afaa002012-09-27 12:02:22 +00001046 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -08001047 if (xoff[tc])
1048 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
1049 }
John Fastabend33fdc822017-04-24 03:30:18 -07001050
1051 for (i = 0; i < adapter->num_xdp_queues; i++) {
1052 struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i];
1053
1054 tc = xdp_ring->dcb_tc;
1055 if (xoff[tc])
1056 clear_bit(__IXGBE_HANG_CHECK_ARMED, &xdp_ring->state);
1057 }
John Fastabendc84d3242010-11-16 19:27:12 -08001058}
1059
1060static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
1061{
Alexander Duyck7d7ce682012-02-08 07:50:51 +00001062 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -08001063}
1064
1065static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
1066{
John Fastabend2a47fa42013-11-06 09:54:52 -08001067 struct ixgbe_adapter *adapter;
1068 struct ixgbe_hw *hw;
1069 u32 head, tail;
John Fastabendc84d3242010-11-16 19:27:12 -08001070
John Fastabend2a47fa42013-11-06 09:54:52 -08001071 if (ring->l2_accel_priv)
1072 adapter = ring->l2_accel_priv->real_adapter;
1073 else
1074 adapter = netdev_priv(ring->netdev);
1075
1076 hw = &adapter->hw;
1077 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
1078 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
John Fastabendc84d3242010-11-16 19:27:12 -08001079
1080 if (head != tail)
1081 return (head < tail) ?
1082 tail - head : (tail + ring->count - head);
1083
1084 return 0;
1085}
1086
1087static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
1088{
1089 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
1090 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
1091 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
John Fastabendc84d3242010-11-16 19:27:12 -08001092
1093 clear_check_for_tx_hang(tx_ring);
1094
1095 /*
1096 * Check for a hung queue, but be thorough. This verifies
1097 * that a transmit has been completed since the previous
1098 * check AND there is at least one packet pending. The
1099 * ARMED bit is set to indicate a potential hang. The
1100 * bit is cleared if a pause frame is received to remove
1101 * false hang detection due to PFC or 802.3x frames. By
1102 * requiring this to fail twice we avoid races with
1103 * pfc clearing the ARMED bit and conditions where we
1104 * run the check_tx_hang logic with a transmit completion
1105 * pending but without time to complete it yet.
1106 */
Mark Rustade90dd262014-07-22 06:51:08 +00001107 if (tx_done_old == tx_done && tx_pending)
John Fastabendc84d3242010-11-16 19:27:12 -08001108 /* make sure it is true for two checks in a row */
Mark Rustade90dd262014-07-22 06:51:08 +00001109 return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
1110 &tx_ring->state);
1111 /* update completed stats and continue */
1112 tx_ring->tx_stats.tx_done_old = tx_done;
1113 /* reset the countdown */
1114 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
John Fastabendc84d3242010-11-16 19:27:12 -08001115
Mark Rustade90dd262014-07-22 06:51:08 +00001116 return false;
Auke Kok9a799d72007-09-15 14:07:45 -07001117}
1118
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001119/**
1120 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1121 * @adapter: driver private struct
1122 **/
1123static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
1124{
1125
1126 /* Do the reset outside of interrupt context */
1127 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
Emil Tantilov57ca2a42016-07-29 14:46:31 -07001128 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Jacob Keller12ff3f32012-12-01 07:57:17 +00001129 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001130 ixgbe_service_event_schedule(adapter);
1131 }
1132}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001133
Auke Kok9a799d72007-09-15 14:07:45 -07001134/**
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00001135 * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
1136 **/
1137static int ixgbe_tx_maxrate(struct net_device *netdev,
1138 int queue_index, u32 maxrate)
1139{
1140 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1141 struct ixgbe_hw *hw = &adapter->hw;
1142 u32 bcnrc_val = ixgbe_link_mbps(adapter);
1143
1144 if (!maxrate)
1145 return 0;
1146
1147 /* Calculate the rate factor values to set */
1148 bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
1149 bcnrc_val /= maxrate;
1150
1151 /* clear everything but the rate factor */
1152 bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
1153 IXGBE_RTTBCNRC_RF_DEC_MASK;
1154
1155 /* enable the rate scheduler */
1156 bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
1157
1158 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index);
1159 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
1160
1161 return 0;
1162}
1163
1164/**
Auke Kok9a799d72007-09-15 14:07:45 -07001165 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +00001166 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001167 * @tx_ring: tx ring to clean
Alexander Duyck8220bbc2016-03-07 09:30:09 -08001168 * @napi_budget: Used to determine if we are in netpoll
Auke Kok9a799d72007-09-15 14:07:45 -07001169 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +00001170static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Jesper Dangaard Brouera3a87492016-02-08 13:15:09 +01001171 struct ixgbe_ring *tx_ring, int napi_budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001172{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001173 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001174 struct ixgbe_tx_buffer *tx_buffer;
1175 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001176 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +00001177 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +00001178 unsigned int i = tx_ring->next_to_clean;
1179
1180 if (test_bit(__IXGBE_DOWN, &adapter->state))
1181 return true;
Auke Kok9a799d72007-09-15 14:07:45 -07001182
Alexander Duyckd3d00232011-07-15 02:31:25 +00001183 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +00001184 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +00001185 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001186
Alexander Duyck729739b2012-02-08 07:51:06 +00001187 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001188 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -07001189
Alexander Duyckd3d00232011-07-15 02:31:25 +00001190 /* if next_to_watch is not set then there is no work pending */
1191 if (!eop_desc)
1192 break;
1193
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001194 /* prevent any other reads prior to eop_desc */
Alexander Duyck7e63bf42013-01-08 07:00:58 +00001195 read_barrier_depends();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001196
Alexander Duyckd3d00232011-07-15 02:31:25 +00001197 /* if DD is not set pending work has not been completed */
1198 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
1199 break;
1200
Alexander Duyckd3d00232011-07-15 02:31:25 +00001201 /* clear next_to_watch to prevent false hangs */
1202 tx_buffer->next_to_watch = NULL;
1203
Alexander Duyck091a6242012-02-08 07:51:01 +00001204 /* update the statistics for this packet */
1205 total_bytes += tx_buffer->bytecount;
1206 total_packets += tx_buffer->gso_segs;
1207
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001208 /* free the skb */
John Fastabend33fdc822017-04-24 03:30:18 -07001209 if (ring_is_xdp(tx_ring))
1210 page_frag_free(tx_buffer->data);
1211 else
1212 napi_consume_skb(tx_buffer->skb, napi_budget);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001213
Alexander Duyck729739b2012-02-08 07:51:06 +00001214 /* unmap skb header data */
1215 dma_unmap_single(tx_ring->dev,
1216 dma_unmap_addr(tx_buffer, dma),
1217 dma_unmap_len(tx_buffer, len),
1218 DMA_TO_DEVICE);
1219
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001220 /* clear tx_buffer data */
Alexander Duyck729739b2012-02-08 07:51:06 +00001221 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001222
Alexander Duyck729739b2012-02-08 07:51:06 +00001223 /* unmap remaining buffers */
1224 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001225 tx_buffer++;
1226 tx_desc++;
1227 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00001228 if (unlikely(!i)) {
1229 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001230 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +00001231 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00001232 }
1233
Alexander Duyck729739b2012-02-08 07:51:06 +00001234 /* unmap any remaining paged data */
1235 if (dma_unmap_len(tx_buffer, len)) {
1236 dma_unmap_page(tx_ring->dev,
1237 dma_unmap_addr(tx_buffer, dma),
1238 dma_unmap_len(tx_buffer, len),
1239 DMA_TO_DEVICE);
1240 dma_unmap_len_set(tx_buffer, len, 0);
1241 }
1242 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001243
Alexander Duyck729739b2012-02-08 07:51:06 +00001244 /* move us one more past the eop_desc for start of next pkt */
1245 tx_buffer++;
1246 tx_desc++;
1247 i++;
1248 if (unlikely(!i)) {
1249 i -= tx_ring->count;
1250 tx_buffer = tx_ring->tx_buffer_info;
1251 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
1252 }
1253
1254 /* issue prefetch for next Tx descriptor */
1255 prefetch(tx_desc);
1256
1257 /* update budget accounting */
1258 budget--;
1259 } while (likely(budget));
1260
1261 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07001262 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001263 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -08001264 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +00001265 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001266 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001267 q_vector->tx.total_bytes += total_bytes;
1268 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -08001269
John Fastabendc84d3242010-11-16 19:27:12 -08001270 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -08001271 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -08001272 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend33fdc822017-04-24 03:30:18 -07001273 e_err(drv, "Detected Tx Unit Hang %s\n"
John Fastabendc84d3242010-11-16 19:27:12 -08001274 " Tx Queue <%d>\n"
1275 " TDH, TDT <%x>, <%x>\n"
1276 " next_to_use <%x>\n"
1277 " next_to_clean <%x>\n"
1278 "tx_buffer_info[next_to_clean]\n"
1279 " time_stamp <%lx>\n"
1280 " jiffies <%lx>\n",
John Fastabend33fdc822017-04-24 03:30:18 -07001281 ring_is_xdp(tx_ring) ? "(XDP)" : "",
John Fastabendc84d3242010-11-16 19:27:12 -08001282 tx_ring->queue_index,
1283 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
1284 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +00001285 tx_ring->next_to_use, i,
1286 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -08001287
John Fastabend33fdc822017-04-24 03:30:18 -07001288 if (!ring_is_xdp(tx_ring))
1289 netif_stop_subqueue(tx_ring->netdev,
1290 tx_ring->queue_index);
John Fastabendc84d3242010-11-16 19:27:12 -08001291
1292 e_info(probe,
1293 "tx hang %d detected on queue %d, resetting adapter\n",
1294 adapter->tx_timeout_count + 1, tx_ring->queue_index);
1295
1296 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001297 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -08001298
1299 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +00001300 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -08001301 }
Auke Kok9a799d72007-09-15 14:07:45 -07001302
John Fastabend33fdc822017-04-24 03:30:18 -07001303 if (ring_is_xdp(tx_ring))
1304 return !!budget;
1305
Alexander Duyckb2d96e02012-02-07 08:14:33 +00001306 netdev_tx_completed_queue(txring_txq(tx_ring),
1307 total_packets, total_bytes);
1308
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001309#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +00001310 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001311 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001312 /* Make sure that anybody stopping the queue after this
1313 * sees the new next_to_clean.
1314 */
1315 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +00001316 if (__netif_subqueue_stopped(tx_ring->netdev,
1317 tx_ring->queue_index)
1318 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
1319 netif_wake_subqueue(tx_ring->netdev,
1320 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08001321 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08001322 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001323 }
Auke Kok9a799d72007-09-15 14:07:45 -07001324
Alexander Duyck59224552011-08-31 00:01:06 +00001325 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001326}
1327
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001328#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001329static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001330 struct ixgbe_ring *tx_ring,
1331 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001332{
Don Skidmoreee5f7842009-11-06 12:56:20 +00001333 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001334 u32 txctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001335 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001336
Mark Rustad9de76052015-08-08 16:27:41 -07001337 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1338 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1339
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001340 switch (hw->mac.type) {
1341 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001342 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001343 break;
1344 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001345 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001346 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
1347 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
1348 break;
1349 default:
1350 /* for unknown hardware do not write register */
1351 return;
1352 }
1353
1354 /*
1355 * We can enable relaxed ordering for reads, but not writes when
1356 * DCA is enabled. This is due to a known issue in some chipsets
1357 * which will cause the DCA tag to be cleared.
1358 */
1359 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1360 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1361 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1362
1363 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1364}
1365
1366static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1367 struct ixgbe_ring *rx_ring,
1368 int cpu)
1369{
1370 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001371 u32 rxctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001372 u8 reg_idx = rx_ring->reg_idx;
1373
Mark Rustad9de76052015-08-08 16:27:41 -07001374 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1375 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001376
1377 switch (hw->mac.type) {
1378 case ixgbe_mac_82599EB:
1379 case ixgbe_mac_X540:
1380 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001381 break;
1382 default:
1383 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001384 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001385
1386 /*
1387 * We can enable relaxed ordering for reads, but not writes when
1388 * DCA is enabled. This is due to a known issue in some chipsets
1389 * which will cause the DCA tag to be cleared.
1390 */
1391 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Mark Rustad9de76052015-08-08 16:27:41 -07001392 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001393 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1394
1395 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001396}
1397
1398static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1399{
1400 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001401 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001402 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001403
1404 if (q_vector->cpu == cpu)
1405 goto out_no_update;
1406
Alexander Duycka5579282012-02-08 07:50:04 +00001407 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001408 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001409
Alexander Duycka5579282012-02-08 07:50:04 +00001410 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001411 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001412
1413 q_vector->cpu = cpu;
1414out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001415 put_cpu();
1416}
1417
1418static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1419{
1420 int i;
1421
Alexander Duycke35ec122009-05-21 13:07:12 +00001422 /* always use CB2 mode, difference is masked in the CB driver */
Mark Rustad9de76052015-08-08 16:27:41 -07001423 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1424 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1425 IXGBE_DCA_CTRL_DCA_MODE_CB2);
1426 else
1427 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1428 IXGBE_DCA_CTRL_DCA_DISABLE);
Alexander Duycke35ec122009-05-21 13:07:12 +00001429
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001430 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001431 adapter->q_vector[i]->cpu = -1;
1432 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001433 }
1434}
1435
1436static int __ixgbe_notify_dca(struct device *dev, void *data)
1437{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001438 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001439 unsigned long event = *(unsigned long *)data;
1440
Don Skidmore2a72c312011-07-20 02:27:05 +00001441 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001442 return 0;
1443
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001444 switch (event) {
1445 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001446 /* if we're already enabled, don't do it again */
1447 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1448 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001449 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001450 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001451 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1452 IXGBE_DCA_CTRL_DCA_MODE_CB2);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001453 break;
1454 }
1455 /* Fall Through since DCA is disabled. */
1456 case DCA_PROVIDER_REMOVE:
1457 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1458 dca_remove_requester(dev);
1459 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001460 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1461 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001462 }
1463 break;
1464 }
1465
Denis V. Lunev652f0932008-03-27 14:39:17 +03001466 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001467}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001468
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001469#endif /* CONFIG_IXGBE_DCA */
Fan Du7edda4b82015-04-29 10:57:39 +08001470
1471#define IXGBE_RSS_L4_TYPES_MASK \
1472 ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
1473 (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
1474 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
1475 (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
1476
Alexander Duyck8a0da212012-01-31 02:59:49 +00001477static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1478 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001479 struct sk_buff *skb)
1480{
Fan Du7edda4b82015-04-29 10:57:39 +08001481 u16 rss_type;
1482
1483 if (!(ring->netdev->features & NETIF_F_RXHASH))
1484 return;
1485
1486 rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
1487 IXGBE_RXDADV_RSSTYPE_MASK;
1488
1489 if (!rss_type)
1490 return;
1491
1492 skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
1493 (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
1494 PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001495}
1496
Alexander Duyckf8003262012-03-03 02:35:52 +00001497#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001498/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001499 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001500 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001501 * @rx_desc: advanced rx descriptor
1502 *
1503 * Returns : true if it is FCoE pkt
1504 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001505static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001506 union ixgbe_adv_rx_desc *rx_desc)
1507{
1508 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1509
Alexander Duyck57efd442012-06-25 21:54:46 +00001510 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001511 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1512 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1513 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1514}
1515
Alexander Duyckf8003262012-03-03 02:35:52 +00001516#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001517/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001518 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001519 * @ring: structure containing ring specific data
1520 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001521 * @skb: skb currently being received and modified
1522 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001523static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001524 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001525 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001526{
Don Skidmore3f207802014-12-23 07:40:34 +00001527 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore3f207802014-12-23 07:40:34 +00001528 bool encap_pkt = false;
1529
Alexander Duyck8a0da212012-01-31 02:59:49 +00001530 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001531
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001532 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001533 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001534 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001535
Emil Tantilova21d0822016-08-10 11:19:23 -07001536 /* check for VXLAN and Geneve packets */
1537 if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) {
Don Skidmore3f207802014-12-23 07:40:34 +00001538 encap_pkt = true;
1539 skb->encapsulation = 1;
Don Skidmore3f207802014-12-23 07:40:34 +00001540 }
1541
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001542 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001543 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1544 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001545 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001546 return;
1547 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001548
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001549 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001550 return;
1551
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001552 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001553 /*
1554 * 82599 errata, UDP frames with a 0 checksum can be marked as
1555 * checksum errors.
1556 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001557 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1558 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001559 return;
1560
Alexander Duyck8a0da212012-01-31 02:59:49 +00001561 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001562 return;
1563 }
1564
Auke Kok9a799d72007-09-15 14:07:45 -07001565 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001566 skb->ip_summed = CHECKSUM_UNNECESSARY;
Don Skidmore3f207802014-12-23 07:40:34 +00001567 if (encap_pkt) {
1568 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
1569 return;
1570
1571 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
Mark Rustadd4692512015-12-04 11:26:43 -08001572 skb->ip_summed = CHECKSUM_NONE;
Don Skidmore3f207802014-12-23 07:40:34 +00001573 return;
1574 }
1575 /* If we checked the outer header let the stack know */
1576 skb->csum_level = 1;
1577 }
Auke Kok9a799d72007-09-15 14:07:45 -07001578}
1579
Alexander Duyck2de6aa32017-01-17 08:36:54 -08001580static inline unsigned int ixgbe_rx_offset(struct ixgbe_ring *rx_ring)
1581{
1582 return ring_uses_build_skb(rx_ring) ? IXGBE_SKB_PAD : 0;
1583}
1584
Alexander Duyckf990b792012-01-31 02:59:34 +00001585static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1586 struct ixgbe_rx_buffer *bi)
1587{
1588 struct page *page = bi->page;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001589 dma_addr_t dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001590
Alexander Duyckf8003262012-03-03 02:35:52 +00001591 /* since we are recycling buffers we should seldom need to alloc */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001592 if (likely(page))
Alexander Duyckf990b792012-01-31 02:59:34 +00001593 return true;
1594
Alexander Duyckf8003262012-03-03 02:35:52 +00001595 /* alloc new page for storage */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001596 page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
1597 if (unlikely(!page)) {
1598 rx_ring->rx_stats.alloc_rx_page_failed++;
1599 return false;
Alexander Duyckf990b792012-01-31 02:59:34 +00001600 }
1601
Alexander Duyckf8003262012-03-03 02:35:52 +00001602 /* map page for use */
Alexander Duyckf3213d92017-01-17 08:35:54 -08001603 dma = dma_map_page_attrs(rx_ring->dev, page, 0,
1604 ixgbe_rx_pg_size(rx_ring),
1605 DMA_FROM_DEVICE,
1606 IXGBE_RX_DMA_ATTR);
Alexander Duyckf990b792012-01-31 02:59:34 +00001607
Alexander Duyckf8003262012-03-03 02:35:52 +00001608 /*
1609 * if mapping failed free memory back to system since
1610 * there isn't much point in holding memory we can't use
1611 */
1612 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001613 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001614
Alexander Duyckf990b792012-01-31 02:59:34 +00001615 rx_ring->rx_stats.alloc_rx_page_failed++;
1616 return false;
1617 }
1618
Alexander Duyckf8003262012-03-03 02:35:52 +00001619 bi->dma = dma;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001620 bi->page = page;
Alexander Duyck2de6aa32017-01-17 08:36:54 -08001621 bi->page_offset = ixgbe_rx_offset(rx_ring);
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001622 bi->pagecnt_bias = 1;
Alexander Duyckf8003262012-03-03 02:35:52 +00001623
Alexander Duyckf990b792012-01-31 02:59:34 +00001624 return true;
1625}
1626
Auke Kok9a799d72007-09-15 14:07:45 -07001627/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001628 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001629 * @rx_ring: ring to place buffers on
1630 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001631 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001632void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001633{
Auke Kok9a799d72007-09-15 14:07:45 -07001634 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001635 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001636 u16 i = rx_ring->next_to_use;
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001637 u16 bufsz;
Auke Kok9a799d72007-09-15 14:07:45 -07001638
Alexander Duyckf8003262012-03-03 02:35:52 +00001639 /* nothing to do */
1640 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001641 return;
1642
Alexander Duycke4f74022012-01-31 02:59:44 +00001643 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001644 bi = &rx_ring->rx_buffer_info[i];
1645 i -= rx_ring->count;
1646
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001647 bufsz = ixgbe_rx_bufsz(rx_ring);
1648
Alexander Duyckf8003262012-03-03 02:35:52 +00001649 do {
1650 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001651 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001652
Alexander Duyckf3213d92017-01-17 08:35:54 -08001653 /* sync the buffer for use by the device */
1654 dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001655 bi->page_offset, bufsz,
Alexander Duyckf3213d92017-01-17 08:35:54 -08001656 DMA_FROM_DEVICE);
1657
Alexander Duyckf8003262012-03-03 02:35:52 +00001658 /*
1659 * Refresh the desc even if buffer_addrs didn't change
1660 * because each write-back erases this info.
1661 */
1662 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001663
Alexander Duyckf990b792012-01-31 02:59:34 +00001664 rx_desc++;
1665 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001666 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001667 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001668 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001669 bi = rx_ring->rx_buffer_info;
1670 i -= rx_ring->count;
1671 }
1672
Alexander Duyckc3630cc2017-01-17 08:36:28 -08001673 /* clear the length for the next_to_use descriptor */
1674 rx_desc->wb.upper.length = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001675
1676 cleaned_count--;
1677 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001678
Alexander Duyckf990b792012-01-31 02:59:34 +00001679 i += rx_ring->count;
1680
Alexander Duyckad435ec2014-11-14 00:56:35 +00001681 if (rx_ring->next_to_use != i) {
1682 rx_ring->next_to_use = i;
1683
1684 /* update next to alloc since we have filled the ring */
1685 rx_ring->next_to_alloc = i;
1686
1687 /* Force memory writes to complete before letting h/w
1688 * know there are new descriptors to fetch. (Only
1689 * applicable for weak-ordered memory model archs,
1690 * such as IA-64).
1691 */
1692 wmb();
1693 writel(i, rx_ring->tail);
1694 }
Auke Kok9a799d72007-09-15 14:07:45 -07001695}
1696
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001697static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1698 struct sk_buff *skb)
1699{
Alexander Duyckf8003262012-03-03 02:35:52 +00001700 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001701
1702 /* set gso_size to avoid messing up TCP MSS */
1703 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1704 IXGBE_CB(skb)->append_cnt);
Alexander Duyck96be80a2013-02-12 09:45:44 +00001705 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001706}
1707
1708static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1709 struct sk_buff *skb)
1710{
1711 /* if append_cnt is 0 then frame is not RSC */
1712 if (!IXGBE_CB(skb)->append_cnt)
1713 return;
1714
1715 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1716 rx_ring->rx_stats.rsc_flush++;
1717
1718 ixgbe_set_rsc_gso_size(rx_ring, skb);
1719
1720 /* gso_size is computed using append_cnt so always clear it last */
1721 IXGBE_CB(skb)->append_cnt = 0;
1722}
1723
Alexander Duyck8a0da212012-01-31 02:59:49 +00001724/**
1725 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1726 * @rx_ring: rx descriptor ring packet is being transacted on
1727 * @rx_desc: pointer to the EOP Rx descriptor
1728 * @skb: pointer to current skb being populated
1729 *
1730 * This function checks the ring, descriptor, and packet information in
1731 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1732 * other fields within the skb.
1733 **/
1734static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1735 union ixgbe_adv_rx_desc *rx_desc,
1736 struct sk_buff *skb)
1737{
John Fastabend43e95f12012-05-15 06:12:17 +00001738 struct net_device *dev = rx_ring->netdev;
Mark Rustada9763f32015-10-27 09:58:07 -07001739 u32 flags = rx_ring->q_vector->adapter->flags;
John Fastabend43e95f12012-05-15 06:12:17 +00001740
Alexander Duyck8a0da212012-01-31 02:59:49 +00001741 ixgbe_update_rsc_stats(rx_ring, skb);
1742
1743 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1744
1745 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1746
Mark Rustada9763f32015-10-27 09:58:07 -07001747 if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED))
1748 ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001749
Patrick McHardyf6469682013-04-19 02:04:27 +00001750 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
John Fastabend43e95f12012-05-15 06:12:17 +00001751 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001752 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001753 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001754 }
1755
1756 skb_record_rx_queue(skb, rx_ring->queue_index);
1757
John Fastabend43e95f12012-05-15 06:12:17 +00001758 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001759}
1760
1761static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1762 struct sk_buff *skb)
1763{
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08001764 napi_gro_receive(&q_vector->napi, skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001765}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001766
Alexander Duyckf8003262012-03-03 02:35:52 +00001767/**
1768 * ixgbe_is_non_eop - process handling of non-EOP buffers
1769 * @rx_ring: Rx ring being processed
1770 * @rx_desc: Rx descriptor for current buffer
1771 * @skb: Current socket buffer containing buffer in progress
1772 *
1773 * This function updates next to clean. If the buffer is an EOP buffer
1774 * this function exits returning false, otherwise it will place the
1775 * sk_buff in the next buffer to be chained and return true indicating
1776 * that this is in fact a non-EOP buffer.
1777 **/
1778static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1779 union ixgbe_adv_rx_desc *rx_desc,
1780 struct sk_buff *skb)
1781{
1782 u32 ntc = rx_ring->next_to_clean + 1;
1783
1784 /* fetch, update, and store next to clean */
1785 ntc = (ntc < rx_ring->count) ? ntc : 0;
1786 rx_ring->next_to_clean = ntc;
1787
1788 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1789
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001790 /* update RSC append count if present */
1791 if (ring_is_rsc_enabled(rx_ring)) {
1792 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1793 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1794
1795 if (unlikely(rsc_enabled)) {
1796 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1797
1798 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1799 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1800
1801 /* update ntc based on RSC value */
1802 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1803 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1804 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1805 }
1806 }
1807
1808 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001809 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1810 return false;
1811
Alexander Duyckf8003262012-03-03 02:35:52 +00001812 /* place skb in next buffer to be received */
1813 rx_ring->rx_buffer_info[ntc].skb = skb;
1814 rx_ring->rx_stats.non_eop_descs++;
1815
1816 return true;
1817}
1818
1819/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001820 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1821 * @rx_ring: rx descriptor ring packet is being transacted on
1822 * @skb: pointer to current skb being adjusted
1823 *
1824 * This function is an ixgbe specific version of __pskb_pull_tail. The
1825 * main difference between this version and the original function is that
1826 * this function can make several assumptions about the state of things
1827 * that allow for significant optimizations versus the standard function.
1828 * As a result we can do things like drop a frag and maintain an accurate
1829 * truesize for the skb.
1830 */
1831static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1832 struct sk_buff *skb)
1833{
1834 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1835 unsigned char *va;
1836 unsigned int pull_len;
1837
1838 /*
1839 * it is valid to use page_address instead of kmap since we are
1840 * working with pages allocated out of the lomem pool per
1841 * alloc_page(GFP_ATOMIC)
1842 */
1843 va = skb_frag_address(frag);
1844
1845 /*
1846 * we need the header to contain the greater of either ETH_HLEN or
1847 * 60 bytes if the skb->len is less than 60 for skb_pad.
1848 */
Alexander Duyck8496e3382014-09-05 19:22:18 -04001849 pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001850
1851 /* align pull length to size of long to optimize memcpy performance */
1852 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1853
1854 /* update all of the pointers */
1855 skb_frag_size_sub(frag, pull_len);
1856 frag->page_offset += pull_len;
1857 skb->data_len -= pull_len;
1858 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001859}
1860
1861/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001862 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1863 * @rx_ring: rx descriptor ring packet is being transacted on
1864 * @skb: pointer to current skb being updated
1865 *
1866 * This function provides a basic DMA sync up for the first fragment of an
1867 * skb. The reason for doing this is that the first fragment cannot be
1868 * unmapped until we have reached the end of packet descriptor for a buffer
1869 * chain.
1870 */
1871static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1872 struct sk_buff *skb)
1873{
1874 /* if the page was released unmap it, else just sync our portion */
1875 if (unlikely(IXGBE_CB(skb)->page_released)) {
Alexander Duyckf3213d92017-01-17 08:35:54 -08001876 dma_unmap_page_attrs(rx_ring->dev, IXGBE_CB(skb)->dma,
1877 ixgbe_rx_pg_size(rx_ring),
1878 DMA_FROM_DEVICE,
1879 IXGBE_RX_DMA_ATTR);
Alexander Duyck42073d92012-07-20 08:08:28 +00001880 } else {
1881 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1882
1883 dma_sync_single_range_for_cpu(rx_ring->dev,
1884 IXGBE_CB(skb)->dma,
1885 frag->page_offset,
Alexander Duyckf215af82017-01-17 08:35:44 -08001886 skb_frag_size(frag),
Alexander Duyck42073d92012-07-20 08:08:28 +00001887 DMA_FROM_DEVICE);
1888 }
Alexander Duyck42073d92012-07-20 08:08:28 +00001889}
1890
1891/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001892 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1893 * @rx_ring: rx descriptor ring packet is being transacted on
1894 * @rx_desc: pointer to the EOP Rx descriptor
1895 * @skb: pointer to current skb being fixed
1896 *
John Fastabend92470802017-04-24 03:30:17 -07001897 * Check if the skb is valid in the XDP case it will be an error pointer.
1898 * Return true in this case to abort processing and advance to next
1899 * descriptor.
1900 *
Alexander Duyckf8003262012-03-03 02:35:52 +00001901 * Check for corrupted packet headers caused by senders on the local L2
1902 * embedded NIC switch not setting up their Tx Descriptors right. These
1903 * should be very rare.
1904 *
1905 * Also address the case where we are pulling data in on pages only
1906 * and as such no data is present in the skb header.
1907 *
1908 * In addition if skb is not at least 60 bytes we need to pad it so that
1909 * it is large enough to qualify as a valid Ethernet frame.
1910 *
1911 * Returns true if an error was encountered and skb was freed.
1912 **/
1913static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1914 union ixgbe_adv_rx_desc *rx_desc,
1915 struct sk_buff *skb)
1916{
Alexander Duyckf8003262012-03-03 02:35:52 +00001917 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001918
John Fastabend92470802017-04-24 03:30:17 -07001919 /* XDP packets use error pointer so abort at this point */
1920 if (IS_ERR(skb))
1921 return true;
1922
Alexander Duyckf8003262012-03-03 02:35:52 +00001923 /* verify that the packet does not have any known errors */
1924 if (unlikely(ixgbe_test_staterr(rx_desc,
1925 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1926 !(netdev->features & NETIF_F_RXALL))) {
1927 dev_kfree_skb_any(skb);
1928 return true;
1929 }
1930
Alexander Duyck19861ce2012-07-20 08:08:33 +00001931 /* place header in linear portion of buffer */
Alexander Duyck6f429222017-01-17 08:37:13 -08001932 if (!skb_headlen(skb))
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001933 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001934
Alexander Duyck57efd442012-06-25 21:54:46 +00001935#ifdef IXGBE_FCOE
1936 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1937 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1938 return false;
1939
1940#endif
Alexander Duycka94d9e22014-12-03 08:17:39 -08001941 /* if eth_skb_pad returns an error the skb was freed */
1942 if (eth_skb_pad(skb))
1943 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001944
1945 return false;
1946}
1947
1948/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001949 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1950 * @rx_ring: rx descriptor ring to store buffers on
1951 * @old_buff: donor buffer to have page reused
1952 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001953 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001954 **/
1955static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1956 struct ixgbe_rx_buffer *old_buff)
1957{
1958 struct ixgbe_rx_buffer *new_buff;
1959 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001960
1961 new_buff = &rx_ring->rx_buffer_info[nta];
1962
1963 /* update, and store next to alloc */
1964 nta++;
1965 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1966
Alexander Duyck3fd218762017-01-17 08:36:45 -08001967 /* Transfer page from old buffer to new buffer.
1968 * Move each member individually to avoid possible store
1969 * forwarding stalls and unnecessary copy of skb.
1970 */
1971 new_buff->dma = old_buff->dma;
1972 new_buff->page = old_buff->page;
1973 new_buff->page_offset = old_buff->page_offset;
1974 new_buff->pagecnt_bias = old_buff->pagecnt_bias;
Alexander Duyckf8003262012-03-03 02:35:52 +00001975}
1976
Alexander Duyck18cb6522014-11-14 00:56:29 +00001977static inline bool ixgbe_page_is_reserved(struct page *page)
1978{
Michal Hocko2f064f32015-08-21 14:11:51 -07001979 return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
Alexander Duyck18cb6522014-11-14 00:56:29 +00001980}
1981
Alexander Duyck3fd218762017-01-17 08:36:45 -08001982static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer *rx_buffer)
Alexander Duyckf8003262012-03-03 02:35:52 +00001983{
Alexander Duyck3fd218762017-01-17 08:36:45 -08001984 unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
1985 struct page *page = rx_buffer->page;
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001986
Alexander Duyck09816fb2012-07-20 08:08:23 +00001987 /* avoid re-using remote pages */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001988 if (unlikely(ixgbe_page_is_reserved(page)))
Alexander Duyck09816fb2012-07-20 08:08:23 +00001989 return false;
1990
1991#if (PAGE_SIZE < 8192)
1992 /* if we are only owner of page we can reuse it */
Alexander Duyck3fd218762017-01-17 08:36:45 -08001993 if (unlikely((page_ref_count(page) - pagecnt_bias) > 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001994 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001995#else
Alexander Duyck3fd218762017-01-17 08:36:45 -08001996 /* The last offset is a bit aggressive in that we assume the
1997 * worst case of FCoE being enabled and using a 3K buffer.
1998 * However this should have minimal impact as the 1K extra is
1999 * still less than one buffer in size.
2000 */
2001#define IXGBE_LAST_OFFSET \
2002 (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K)
2003 if (rx_buffer->page_offset > IXGBE_LAST_OFFSET)
Alexander Duyck09816fb2012-07-20 08:08:23 +00002004 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00002005#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00002006
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002007 /* If we have drained the page fragment pool we need to update
2008 * the pagecnt_bias and page count so that we fully restock the
2009 * number of references the driver holds.
Alexander Duyck18cb6522014-11-14 00:56:29 +00002010 */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002011 if (unlikely(!pagecnt_bias)) {
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002012 page_ref_add(page, USHRT_MAX);
2013 rx_buffer->pagecnt_bias = USHRT_MAX;
2014 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00002015
Alexander Duyck0549ae22012-07-20 08:08:18 +00002016 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00002017}
2018
Alexander Duyckaf43da02017-01-17 08:35:34 -08002019/**
2020 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
2021 * @rx_ring: rx descriptor ring to transact packets on
2022 * @rx_buffer: buffer containing page to add
2023 * @rx_desc: descriptor containing length of buffer written by hardware
2024 * @skb: sk_buff to place the data into
2025 *
2026 * This function will add the data contained in rx_buffer->page to the skb.
2027 * This is done either through a direct copy if the data in the buffer is
2028 * less than the skb header size, otherwise it will just attach the page as
2029 * a frag to the skb.
2030 *
2031 * The function will then update the page offset if necessary and return
2032 * true if the buffer can be reused by the adapter.
2033 **/
Alexander Duyck3fd218762017-01-17 08:36:45 -08002034static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckaf43da02017-01-17 08:35:34 -08002035 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck3fd218762017-01-17 08:36:45 -08002036 struct sk_buff *skb,
2037 unsigned int size)
Alexander Duyckaf43da02017-01-17 08:35:34 -08002038{
Alexander Duyckaf43da02017-01-17 08:35:34 -08002039#if (PAGE_SIZE < 8192)
Alexander Duyck4f4542b2017-01-17 08:36:14 -08002040 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
Alexander Duyckaf43da02017-01-17 08:35:34 -08002041#else
Alexander Duyck2de6aa32017-01-17 08:36:54 -08002042 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
2043 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
2044 SKB_DATA_ALIGN(size);
Alexander Duyckaf43da02017-01-17 08:35:34 -08002045#endif
Alexander Duyck3fd218762017-01-17 08:36:45 -08002046 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
Alexander Duyckaf43da02017-01-17 08:35:34 -08002047 rx_buffer->page_offset, size, truesize);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002048#if (PAGE_SIZE < 8192)
2049 rx_buffer->page_offset ^= truesize;
2050#else
2051 rx_buffer->page_offset += truesize;
2052#endif
Alexander Duyckaf43da02017-01-17 08:35:34 -08002053}
2054
Alexander Duyck3fd218762017-01-17 08:36:45 -08002055static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring,
2056 union ixgbe_adv_rx_desc *rx_desc,
2057 struct sk_buff **skb,
2058 const unsigned int size)
Alexander Duyck18806c92012-07-20 08:08:44 +00002059{
2060 struct ixgbe_rx_buffer *rx_buffer;
Alexander Duyck18806c92012-07-20 08:08:44 +00002061
2062 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
Alexander Duyck3fd218762017-01-17 08:36:45 -08002063 prefetchw(rx_buffer->page);
2064 *skb = rx_buffer->skb;
Alexander Duyck18806c92012-07-20 08:08:44 +00002065
Alexander Duyck3fd218762017-01-17 08:36:45 -08002066 /* Delay unmapping of the first packet. It carries the header
2067 * information, HW may still access the header after the writeback.
2068 * Only unmap it when EOP is reached
2069 */
2070 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) {
2071 if (!*skb)
2072 goto skip_sync;
Alexander Duyck18806c92012-07-20 08:08:44 +00002073 } else {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002074 if (*skb)
2075 ixgbe_dma_sync_frag(rx_ring, *skb);
Alexander Duyck18806c92012-07-20 08:08:44 +00002076 }
2077
Alexander Duyck3fd218762017-01-17 08:36:45 -08002078 /* we are reusing so sync this buffer for CPU use */
2079 dma_sync_single_range_for_cpu(rx_ring->dev,
2080 rx_buffer->dma,
2081 rx_buffer->page_offset,
2082 size,
2083 DMA_FROM_DEVICE);
2084skip_sync:
2085 rx_buffer->pagecnt_bias--;
2086
2087 return rx_buffer;
2088}
2089
2090static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring,
2091 struct ixgbe_rx_buffer *rx_buffer,
2092 struct sk_buff *skb)
2093{
2094 if (ixgbe_can_reuse_rx_page(rx_buffer)) {
Alexander Duyck18806c92012-07-20 08:08:44 +00002095 /* hand second half of page back to the ring */
2096 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
Alexander Duyck18806c92012-07-20 08:08:44 +00002097 } else {
John Fastabend92470802017-04-24 03:30:17 -07002098 if (!IS_ERR(skb) && IXGBE_CB(skb)->dma == rx_buffer->dma) {
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002099 /* the page has been released from the ring */
2100 IXGBE_CB(skb)->page_released = true;
2101 } else {
2102 /* we are not reusing the buffer so unmap it */
2103 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
2104 ixgbe_rx_pg_size(rx_ring),
2105 DMA_FROM_DEVICE,
2106 IXGBE_RX_DMA_ATTR);
2107 }
Alexander Duyck3fd218762017-01-17 08:36:45 -08002108 __page_frag_cache_drain(rx_buffer->page,
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002109 rx_buffer->pagecnt_bias);
Alexander Duyck18806c92012-07-20 08:08:44 +00002110 }
2111
Alexander Duyck3fd218762017-01-17 08:36:45 -08002112 /* clear contents of rx_buffer */
Alexander Duyck18806c92012-07-20 08:08:44 +00002113 rx_buffer->page = NULL;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002114 rx_buffer->skb = NULL;
2115}
2116
2117static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring,
2118 struct ixgbe_rx_buffer *rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002119 struct xdp_buff *xdp,
2120 union ixgbe_adv_rx_desc *rx_desc)
Alexander Duyck3fd218762017-01-17 08:36:45 -08002121{
John Fastabend92470802017-04-24 03:30:17 -07002122 unsigned int size = xdp->data_end - xdp->data;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002123#if (PAGE_SIZE < 8192)
2124 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2125#else
John Fastabend92470802017-04-24 03:30:17 -07002126 unsigned int truesize = SKB_DATA_ALIGN(xdp->data_end -
2127 xdp->data_hard_start);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002128#endif
2129 struct sk_buff *skb;
2130
2131 /* prefetch first cache line of first page */
John Fastabend92470802017-04-24 03:30:17 -07002132 prefetch(xdp->data);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002133#if L1_CACHE_BYTES < 128
John Fastabend92470802017-04-24 03:30:17 -07002134 prefetch(xdp->data + L1_CACHE_BYTES);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002135#endif
2136
2137 /* allocate a skb to store the frags */
2138 skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE);
2139 if (unlikely(!skb))
2140 return NULL;
2141
2142 if (size > IXGBE_RX_HDR_SIZE) {
2143 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2144 IXGBE_CB(skb)->dma = rx_buffer->dma;
2145
2146 skb_add_rx_frag(skb, 0, rx_buffer->page,
John Fastabend92470802017-04-24 03:30:17 -07002147 xdp->data - page_address(rx_buffer->page),
Alexander Duyck3fd218762017-01-17 08:36:45 -08002148 size, truesize);
2149#if (PAGE_SIZE < 8192)
2150 rx_buffer->page_offset ^= truesize;
2151#else
2152 rx_buffer->page_offset += truesize;
2153#endif
2154 } else {
John Fastabend92470802017-04-24 03:30:17 -07002155 memcpy(__skb_put(skb, size),
2156 xdp->data, ALIGN(size, sizeof(long)));
Alexander Duyck3fd218762017-01-17 08:36:45 -08002157 rx_buffer->pagecnt_bias++;
2158 }
Alexander Duyck18806c92012-07-20 08:08:44 +00002159
2160 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00002161}
2162
Alexander Duyck6f429222017-01-17 08:37:13 -08002163static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,
2164 struct ixgbe_rx_buffer *rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002165 struct xdp_buff *xdp,
2166 union ixgbe_adv_rx_desc *rx_desc)
Alexander Duyck6f429222017-01-17 08:37:13 -08002167{
Alexander Duyck6f429222017-01-17 08:37:13 -08002168#if (PAGE_SIZE < 8192)
2169 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2170#else
2171 unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
John Fastabend92470802017-04-24 03:30:17 -07002172 SKB_DATA_ALIGN(xdp->data_end -
2173 xdp->data_hard_start);
Alexander Duyck6f429222017-01-17 08:37:13 -08002174#endif
2175 struct sk_buff *skb;
2176
2177 /* prefetch first cache line of first page */
John Fastabend92470802017-04-24 03:30:17 -07002178 prefetch(xdp->data);
Alexander Duyck6f429222017-01-17 08:37:13 -08002179#if L1_CACHE_BYTES < 128
John Fastabend92470802017-04-24 03:30:17 -07002180 prefetch(xdp->data + L1_CACHE_BYTES);
Alexander Duyck6f429222017-01-17 08:37:13 -08002181#endif
2182
John Fastabend92470802017-04-24 03:30:17 -07002183 /* build an skb to around the page buffer */
2184 skb = build_skb(xdp->data_hard_start, truesize);
Alexander Duyck6f429222017-01-17 08:37:13 -08002185 if (unlikely(!skb))
2186 return NULL;
2187
2188 /* update pointers within the skb to store the data */
John Fastabend92470802017-04-24 03:30:17 -07002189 skb_reserve(skb, xdp->data - xdp->data_hard_start);
2190 __skb_put(skb, xdp->data_end - xdp->data);
Alexander Duyck6f429222017-01-17 08:37:13 -08002191
2192 /* record DMA address if this is the start of a chain of buffers */
2193 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
2194 IXGBE_CB(skb)->dma = rx_buffer->dma;
2195
2196 /* update buffer offset */
2197#if (PAGE_SIZE < 8192)
2198 rx_buffer->page_offset ^= truesize;
2199#else
2200 rx_buffer->page_offset += truesize;
2201#endif
2202
2203 return skb;
2204}
2205
John Fastabend92470802017-04-24 03:30:17 -07002206#define IXGBE_XDP_PASS 0
2207#define IXGBE_XDP_CONSUMED 1
John Fastabend33fdc822017-04-24 03:30:18 -07002208#define IXGBE_XDP_TX 2
John Fastabend92470802017-04-24 03:30:17 -07002209
John Fastabend33fdc822017-04-24 03:30:18 -07002210static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
2211 struct xdp_buff *xdp);
2212
2213static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter,
2214 struct ixgbe_ring *rx_ring,
John Fastabend92470802017-04-24 03:30:17 -07002215 struct xdp_buff *xdp)
2216{
2217 int result = IXGBE_XDP_PASS;
2218 struct bpf_prog *xdp_prog;
2219 u32 act;
2220
2221 rcu_read_lock();
2222 xdp_prog = READ_ONCE(rx_ring->xdp_prog);
2223
2224 if (!xdp_prog)
2225 goto xdp_out;
2226
2227 act = bpf_prog_run_xdp(xdp_prog, xdp);
2228 switch (act) {
2229 case XDP_PASS:
2230 break;
John Fastabend33fdc822017-04-24 03:30:18 -07002231 case XDP_TX:
2232 result = ixgbe_xmit_xdp_ring(adapter, xdp);
2233 break;
John Fastabend92470802017-04-24 03:30:17 -07002234 default:
2235 bpf_warn_invalid_xdp_action(act);
John Fastabend92470802017-04-24 03:30:17 -07002236 case XDP_ABORTED:
2237 trace_xdp_exception(rx_ring->netdev, xdp_prog, act);
2238 /* fallthrough -- handle aborts by dropping packet */
2239 case XDP_DROP:
2240 result = IXGBE_XDP_CONSUMED;
2241 break;
2242 }
2243xdp_out:
2244 rcu_read_unlock();
2245 return ERR_PTR(-result);
2246}
2247
John Fastabend33fdc822017-04-24 03:30:18 -07002248static void ixgbe_rx_buffer_flip(struct ixgbe_ring *rx_ring,
2249 struct ixgbe_rx_buffer *rx_buffer,
2250 unsigned int size)
2251{
2252#if (PAGE_SIZE < 8192)
2253 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2254
2255 rx_buffer->page_offset ^= truesize;
2256#else
2257 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
2258 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
2259 SKB_DATA_ALIGN(size);
2260
2261 rx_buffer->page_offset += truesize;
2262#endif
2263}
2264
Alexander Duyckf8003262012-03-03 02:35:52 +00002265/**
2266 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2267 * @q_vector: structure containing interrupt and ring information
2268 * @rx_ring: rx descriptor ring to transact packets on
2269 * @budget: Total limit on number of packets to process
2270 *
2271 * This function provides a "bounce buffer" approach to Rx interrupt
2272 * processing. The advantage to this is that on systems that have
2273 * expensive overhead for IOMMU access this provides a means of avoiding
2274 * it by maintaining the mapping of the page to the syste.
2275 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002276 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00002277 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002278static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002279 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002280 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002281{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002282 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00002283 struct ixgbe_adapter *adapter = q_vector->adapter;
John Fastabend33fdc822017-04-24 03:30:18 -07002284#ifdef IXGBE_FCOE
Mark Rustad4ffdf912012-07-18 06:05:50 +00002285 int ddp_bytes;
2286 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00002287#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00002288 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
John Fastabend7379f972017-03-28 09:47:03 -07002289 bool xdp_xmit = false;
Auke Kok9a799d72007-09-15 14:07:45 -07002290
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002291 while (likely(total_rx_packets < budget)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00002292 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002293 struct ixgbe_rx_buffer *rx_buffer;
Alexander Duyckf8003262012-03-03 02:35:52 +00002294 struct sk_buff *skb;
John Fastabend92470802017-04-24 03:30:17 -07002295 struct xdp_buff xdp;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002296 unsigned int size;
Auke Kok9a799d72007-09-15 14:07:45 -07002297
Alexander Duyckf8003262012-03-03 02:35:52 +00002298 /* return some buffers to hardware, one at a time is too slow */
2299 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2300 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2301 cleaned_count = 0;
2302 }
Auke Kok9a799d72007-09-15 14:07:45 -07002303
Alexander Duyck18806c92012-07-20 08:08:44 +00002304 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002305 size = le16_to_cpu(rx_desc->wb.upper.length);
2306 if (!size)
Alexander Duyckf8003262012-03-03 02:35:52 +00002307 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002308
Alexander Duyck124b74c2014-12-11 15:02:28 -08002309 /* This memory barrier is needed to keep us from reading
Alexander Duyckf8003262012-03-03 02:35:52 +00002310 * any other fields out of the rx_desc until we know the
Alexander Duyck124b74c2014-12-11 15:02:28 -08002311 * descriptor has been written back
Alexander Duyckf8003262012-03-03 02:35:52 +00002312 */
Alexander Duyck124b74c2014-12-11 15:02:28 -08002313 dma_rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002314
Alexander Duyck3fd218762017-01-17 08:36:45 -08002315 rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size);
2316
Alexander Duyck18806c92012-07-20 08:08:44 +00002317 /* retrieve a buffer from the ring */
John Fastabend92470802017-04-24 03:30:17 -07002318 if (!skb) {
2319 xdp.data = page_address(rx_buffer->page) +
2320 rx_buffer->page_offset;
2321 xdp.data_hard_start = xdp.data -
2322 ixgbe_rx_offset(rx_ring);
2323 xdp.data_end = xdp.data + size;
2324
John Fastabend33fdc822017-04-24 03:30:18 -07002325 skb = ixgbe_run_xdp(adapter, rx_ring, &xdp);
John Fastabend92470802017-04-24 03:30:17 -07002326 }
2327
2328 if (IS_ERR(skb)) {
John Fastabend7379f972017-03-28 09:47:03 -07002329 if (PTR_ERR(skb) == -IXGBE_XDP_TX) {
2330 xdp_xmit = true;
John Fastabend33fdc822017-04-24 03:30:18 -07002331 ixgbe_rx_buffer_flip(rx_ring, rx_buffer, size);
John Fastabend7379f972017-03-28 09:47:03 -07002332 } else {
John Fastabend33fdc822017-04-24 03:30:18 -07002333 rx_buffer->pagecnt_bias++;
John Fastabend7379f972017-03-28 09:47:03 -07002334 }
John Fastabend92470802017-04-24 03:30:17 -07002335 total_rx_packets++;
2336 total_rx_bytes += size;
John Fastabend92470802017-04-24 03:30:17 -07002337 } else if (skb) {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002338 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size);
John Fastabend92470802017-04-24 03:30:17 -07002339 } else if (ring_uses_build_skb(rx_ring)) {
Alexander Duyck6f429222017-01-17 08:37:13 -08002340 skb = ixgbe_build_skb(rx_ring, rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002341 &xdp, rx_desc);
2342 } else {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002343 skb = ixgbe_construct_skb(rx_ring, rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002344 &xdp, rx_desc);
2345 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002346
Alexander Duyck18806c92012-07-20 08:08:44 +00002347 /* exit if we failed to retrieve a buffer */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002348 if (!skb) {
2349 rx_ring->rx_stats.alloc_rx_buff_failed++;
2350 rx_buffer->pagecnt_bias++;
Alexander Duyck18806c92012-07-20 08:08:44 +00002351 break;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002352 }
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002353
Alexander Duyck3fd218762017-01-17 08:36:45 -08002354 ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002355 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002356
Alexander Duyckf8003262012-03-03 02:35:52 +00002357 /* place incomplete frames back on ring for completion */
2358 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2359 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002360
Alexander Duyckf8003262012-03-03 02:35:52 +00002361 /* verify the packet layout is correct */
2362 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2363 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002364
2365 /* probably a little skewed due to removing CRC */
2366 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002367
Alexander Duyck8a0da212012-01-31 02:59:49 +00002368 /* populate checksum, timestamp, VLAN, and protocol */
2369 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2370
Yi Zou332d4a72009-05-13 13:11:53 +00002371#ifdef IXGBE_FCOE
2372 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002373 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002374 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002375 /* include DDPed FCoE data */
2376 if (ddp_bytes > 0) {
2377 if (!mss) {
2378 mss = rx_ring->netdev->mtu -
2379 sizeof(struct fcoe_hdr) -
2380 sizeof(struct fc_frame_header) -
2381 sizeof(struct fcoe_crc_eof);
2382 if (mss > 512)
2383 mss &= ~511;
2384 }
2385 total_rx_bytes += ddp_bytes;
2386 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2387 mss);
2388 }
David S. Miller823dcd22011-08-20 10:39:12 -07002389 if (!ddp_bytes) {
2390 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002391 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002392 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002393 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002394
Yi Zou332d4a72009-05-13 13:11:53 +00002395#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00002396 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002397
Alexander Duyckf8003262012-03-03 02:35:52 +00002398 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002399 total_rx_packets++;
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002400 }
Auke Kok9a799d72007-09-15 14:07:45 -07002401
John Fastabend7379f972017-03-28 09:47:03 -07002402 if (xdp_xmit) {
2403 struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
2404
2405 /* Force memory writes to complete before letting h/w
2406 * know there are new descriptors to fetch.
2407 */
2408 wmb();
2409 writel(ring->next_to_use, ring->tail);
2410 }
2411
Alexander Duyckc267fc12010-11-16 19:27:00 -08002412 u64_stats_update_begin(&rx_ring->syncp);
2413 rx_ring->stats.packets += total_rx_packets;
2414 rx_ring->stats.bytes += total_rx_bytes;
2415 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002416 q_vector->rx.total_packets += total_rx_packets;
2417 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002418
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002419 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002420}
2421
Auke Kok9a799d72007-09-15 14:07:45 -07002422/**
2423 * ixgbe_configure_msix - Configure MSI-X hardware
2424 * @adapter: board private structure
2425 *
2426 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2427 * interrupts.
2428 **/
2429static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2430{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002431 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002432 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002433 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002434
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002435 /* Populate MSIX to EITR Select */
2436 if (adapter->num_vfs > 32) {
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002437 u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002438 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2439 }
2440
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002441 /*
2442 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002443 * corresponding register.
2444 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002445 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002446 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002447 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002448
Alexander Duycka5579282012-02-08 07:50:04 +00002449 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002450 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002451
Alexander Duycka5579282012-02-08 07:50:04 +00002452 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002453 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002454
Alexander Duyckfe49f042009-06-04 16:00:09 +00002455 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002456 }
2457
Alexander Duyckbd508172010-11-16 19:27:03 -08002458 switch (adapter->hw.mac.type) {
2459 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002460 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002461 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002462 break;
2463 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002464 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002465 case ixgbe_mac_X550:
2466 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002467 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002468 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002469 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002470 default:
2471 break;
2472 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002473 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002474
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002475 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002476 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002477 mask &= ~(IXGBE_EIMS_OTHER |
2478 IXGBE_EIMS_MAILBOX |
2479 IXGBE_EIMS_LSC);
2480
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002481 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002482}
2483
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002484enum latency_range {
2485 lowest_latency = 0,
2486 low_latency = 1,
2487 bulk_latency = 2,
2488 latency_invalid = 255
2489};
2490
2491/**
2492 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002493 * @q_vector: structure containing interrupt and ring information
2494 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002495 *
2496 * Stores a new ITR value based on packets and byte
2497 * counts during the last interrupt. The advantage of per interrupt
2498 * computation is faster updates and more accurate ITR for the current
2499 * traffic pattern. Constants in this function were computed
2500 * based on theoretical maximum wire speed and thresholds were set based
2501 * on testing data as well as attempting to minimize response time
2502 * while increasing bulk throughput.
2503 * this functionality is controlled by the InterruptThrottleRate module
2504 * parameter (see ixgbe_param.c)
2505 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002506static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2507 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002508{
Alexander Duyckbd198052011-06-11 01:45:08 +00002509 int bytes = ring_container->total_bytes;
2510 int packets = ring_container->total_packets;
2511 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002512 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002513 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002514
2515 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002516 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002517
2518 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002519 * 0-10MB/s lowest (100000 ints/s)
2520 * 10-20MB/s low (20000 ints/s)
Alexander Duyck8ac34f12015-07-30 15:19:28 -07002521 * 20-1249MB/s bulk (12000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002522 */
2523 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002524 timepassed_us = q_vector->itr >> 2;
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002525 if (timepassed_us == 0)
2526 return;
2527
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002528 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2529
2530 switch (itr_setting) {
2531 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002532 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002533 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002534 break;
2535 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002536 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002537 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002538 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002539 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002540 break;
2541 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002542 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002543 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002544 break;
2545 }
2546
Alexander Duyckbd198052011-06-11 01:45:08 +00002547 /* clear work counters since we have the values we need */
2548 ring_container->total_bytes = 0;
2549 ring_container->total_packets = 0;
2550
2551 /* write updated itr to ring container */
2552 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002553}
2554
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002555/**
2556 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002557 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002558 *
2559 * This function is made to be called by ethtool and by the driver
2560 * when it needs to update EITR registers at runtime. Hardware
2561 * specific quirks/differences are taken care of here.
2562 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002563void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002564{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002565 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002566 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002567 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002568 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002569
Alexander Duyckbd508172010-11-16 19:27:03 -08002570 switch (adapter->hw.mac.type) {
2571 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002572 /* must write high and low 16 bits to reset counter */
2573 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002574 break;
2575 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002576 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002577 case ixgbe_mac_X550:
2578 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002579 case ixgbe_mac_x550em_a:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002580 /*
2581 * set the WDIS bit to not clear the timer bits and cause an
2582 * immediate assertion of the interrupt
2583 */
2584 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002585 break;
2586 default:
2587 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002588 }
2589 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2590}
2591
Alexander Duyckbd198052011-06-11 01:45:08 +00002592static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002593{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002594 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002595 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002596
Alexander Duyckbd198052011-06-11 01:45:08 +00002597 ixgbe_update_itr(q_vector, &q_vector->tx);
2598 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002599
Alexander Duyck08c88332011-06-11 01:45:03 +00002600 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002601
2602 switch (current_itr) {
2603 /* counts and packets in update_itr are dependent on these numbers */
2604 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002605 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002606 break;
2607 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002608 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002609 break;
2610 case bulk_latency:
Alexander Duyck8ac34f12015-07-30 15:19:28 -07002611 new_itr = IXGBE_12K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002612 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002613 default:
2614 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002615 }
2616
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002617 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002618 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002619 new_itr = (10 * new_itr * q_vector->itr) /
2620 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002621
Alexander Duyckbd198052011-06-11 01:45:08 +00002622 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002623 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002624
2625 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002626 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002627}
2628
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002629/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002630 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002631 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002632 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002633static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002634{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002635 struct ixgbe_hw *hw = &adapter->hw;
2636 u32 eicr = adapter->interrupt_event;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002637 s32 rc;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002638
Alexander Duyckf0f97782011-04-22 04:08:09 +00002639 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002640 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002641
Mark Rustad22cb4ff2017-04-25 13:55:25 -07002642 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
Alexander Duyckf0f97782011-04-22 04:08:09 +00002643 return;
2644
2645 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2646
Joe Perches7ca647b2010-09-07 21:35:40 +00002647 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002648 case IXGBE_DEV_ID_82599_T3_LOM:
2649 /*
2650 * Since the warning interrupt is for both ports
2651 * we don't have to check if:
2652 * - This interrupt wasn't for our port.
2653 * - We may have missed the interrupt so always have to
2654 * check if we got a LSC
2655 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002656 if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
Alexander Duyckf0f97782011-04-22 04:08:09 +00002657 !(eicr & IXGBE_EICR_LSC))
2658 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002659
Alexander Duyckf0f97782011-04-22 04:08:09 +00002660 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002661 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002662 bool link_up = false;
2663
Josh Hay3d292262012-12-15 03:28:19 +00002664 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002665
Alexander Duyckf0f97782011-04-22 04:08:09 +00002666 if (link_up)
2667 return;
2668 }
2669
2670 /* Check if this is not due to overtemp */
2671 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2672 return;
2673
2674 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002675 case IXGBE_DEV_ID_X550EM_A_1G_T:
2676 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
2677 rc = hw->phy.ops.check_overtemp(hw);
2678 if (rc != IXGBE_ERR_OVERTEMP)
2679 return;
2680 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002681 default:
Don Skidmore597f22d2015-06-09 16:52:02 -07002682 if (adapter->hw.mac.type >= ixgbe_mac_X540)
2683 return;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002684 if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
Joe Perches7ca647b2010-09-07 21:35:40 +00002685 return;
2686 break;
2687 }
Don Skidmoref44e7512015-06-09 16:36:23 -07002688 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Alexander Duyckf0f97782011-04-22 04:08:09 +00002689
2690 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002691}
2692
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002693static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2694{
2695 struct ixgbe_hw *hw = &adapter->hw;
2696
2697 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
Don Skidmore9a900ec2015-06-09 17:15:01 -07002698 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002699 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002700 /* write to clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002701 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002702 }
2703}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002704
Jacob Keller4f51bf72011-08-20 04:49:45 +00002705static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2706{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002707 struct ixgbe_hw *hw = &adapter->hw;
2708
Jacob Keller4f51bf72011-08-20 04:49:45 +00002709 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2710 return;
2711
2712 switch (adapter->hw.mac.type) {
2713 case ixgbe_mac_82599EB:
2714 /*
2715 * Need to check link state so complete overtemp check
2716 * on service task
2717 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002718 if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
2719 (eicr & IXGBE_EICR_LSC)) &&
Jacob Keller4f51bf72011-08-20 04:49:45 +00002720 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2721 adapter->interrupt_event = eicr;
2722 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2723 ixgbe_service_event_schedule(adapter);
2724 return;
2725 }
2726 return;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002727 case ixgbe_mac_x550em_a:
2728 if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) {
2729 adapter->interrupt_event = eicr;
2730 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2731 ixgbe_service_event_schedule(adapter);
2732 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
2733 IXGBE_EICR_GPI_SDP0_X550EM_a);
2734 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR,
2735 IXGBE_EICR_GPI_SDP0_X550EM_a);
2736 }
2737 return;
2738 case ixgbe_mac_X550:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002739 case ixgbe_mac_X540:
2740 if (!(eicr & IXGBE_EICR_TS))
2741 return;
2742 break;
2743 default:
2744 return;
2745 }
2746
Don Skidmoref44e7512015-06-09 16:36:23 -07002747 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002748}
2749
Don Skidmore45788d22015-06-09 16:59:04 -07002750static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2751{
2752 switch (hw->mac.type) {
2753 case ixgbe_mac_82598EB:
2754 if (hw->phy.type == ixgbe_phy_nl)
2755 return true;
2756 return false;
2757 case ixgbe_mac_82599EB:
2758 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002759 case ixgbe_mac_x550em_a:
Don Skidmore45788d22015-06-09 16:59:04 -07002760 switch (hw->mac.ops.get_media_type(hw)) {
2761 case ixgbe_media_type_fiber:
2762 case ixgbe_media_type_fiber_qsfp:
2763 return true;
2764 default:
2765 return false;
2766 }
2767 default:
2768 return false;
2769 }
2770}
2771
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002772static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2773{
2774 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore4ccc6502015-09-02 13:47:54 -07002775 u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002776
Don Skidmore4ccc6502015-09-02 13:47:54 -07002777 if (!ixgbe_is_sfp(hw))
2778 return;
2779
2780 /* Later MAC's use different SDP */
2781 if (hw->mac.type >= ixgbe_mac_X540)
2782 eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
2783
2784 if (eicr & eicr_mask) {
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002785 /* Clear the interrupt */
Don Skidmore4ccc6502015-09-02 13:47:54 -07002786 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
Alexander Duyck70864002011-04-27 09:13:56 +00002787 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2788 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07002789 adapter->sfp_poll_time = 0;
Alexander Duyck70864002011-04-27 09:13:56 +00002790 ixgbe_service_event_schedule(adapter);
2791 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002792 }
2793
Don Skidmore4ccc6502015-09-02 13:47:54 -07002794 if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
2795 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002796 /* Clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002797 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Alexander Duyck70864002011-04-27 09:13:56 +00002798 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2799 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2800 ixgbe_service_event_schedule(adapter);
2801 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002802 }
2803}
2804
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002805static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2806{
2807 struct ixgbe_hw *hw = &adapter->hw;
2808
2809 adapter->lsc_int++;
2810 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2811 adapter->link_check_timeout = jiffies;
2812 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2813 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002814 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002815 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002816 }
2817}
2818
Alexander Duyckfe49f042009-06-04 16:00:09 +00002819static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2820 u64 qmask)
2821{
2822 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002823 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002824
Alexander Duyckbd508172010-11-16 19:27:03 -08002825 switch (hw->mac.type) {
2826 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002827 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002828 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2829 break;
2830 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002831 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002832 case ixgbe_mac_X550:
2833 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002834 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002835 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002836 if (mask)
2837 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002838 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002839 if (mask)
2840 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2841 break;
2842 default:
2843 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002844 }
2845 /* skip the flush */
2846}
2847
2848static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002849 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002850{
2851 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002852 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002853
Alexander Duyckbd508172010-11-16 19:27:03 -08002854 switch (hw->mac.type) {
2855 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002856 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002857 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2858 break;
2859 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002860 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002861 case ixgbe_mac_X550:
2862 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002863 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002864 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002865 if (mask)
2866 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002867 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002868 if (mask)
2869 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2870 break;
2871 default:
2872 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002873 }
2874 /* skip the flush */
2875}
2876
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002877/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002878 * ixgbe_irq_enable - Enable default interrupt generation settings
2879 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002880 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002881static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2882 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002883{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002884 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002885 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002886
Alexander Duyck2c4af692011-07-15 07:29:55 +00002887 /* don't reenable LSC while waiting for link */
2888 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2889 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002890
Alexander Duyck2c4af692011-07-15 07:29:55 +00002891 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002892 switch (adapter->hw.mac.type) {
2893 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002894 mask |= IXGBE_EIMS_GPI_SDP0(hw);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002895 break;
2896 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002897 case ixgbe_mac_X550:
2898 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002899 case ixgbe_mac_x550em_a:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002900 mask |= IXGBE_EIMS_TS;
2901 break;
2902 default:
2903 break;
2904 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002905 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07002906 mask |= IXGBE_EIMS_GPI_SDP1(hw);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002907 switch (adapter->hw.mac.type) {
2908 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07002909 mask |= IXGBE_EIMS_GPI_SDP1(hw);
2910 mask |= IXGBE_EIMS_GPI_SDP2(hw);
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002911 /* fall through */
Don Skidmore858bc082011-08-04 09:28:30 +00002912 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002913 case ixgbe_mac_X550:
2914 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002915 case ixgbe_mac_x550em_a:
2916 if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
Mark Rustad2d40cd12016-04-01 12:18:35 -07002917 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
Mark Rustad49425df2016-04-01 12:18:09 -07002918 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
Mark Rustadcbd45ec2015-08-08 16:17:51 -07002919 mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
Don Skidmore597f22d2015-06-09 16:52:02 -07002920 if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
2921 mask |= IXGBE_EICR_GPI_SDP0_X540;
Don Skidmore858bc082011-08-04 09:28:30 +00002922 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002923 mask |= IXGBE_EIMS_MAILBOX;
2924 break;
2925 default:
2926 break;
2927 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002928
Alexander Duyck2c4af692011-07-15 07:29:55 +00002929 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2930 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2931 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002932
Alexander Duyck2c4af692011-07-15 07:29:55 +00002933 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2934 if (queues)
2935 ixgbe_irq_enable_queues(adapter, ~0);
2936 if (flush)
2937 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002938}
2939
Alexander Duyck2c4af692011-07-15 07:29:55 +00002940static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002941{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002942 struct ixgbe_adapter *adapter = data;
2943 struct ixgbe_hw *hw = &adapter->hw;
2944 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002945
Alexander Duyck2c4af692011-07-15 07:29:55 +00002946 /*
2947 * Workaround for Silicon errata. Use clear-by-write instead
2948 * of clear-by-read. Reading with EICS will return the
2949 * interrupt causes without clearing, which later be done
2950 * with the write to EICR.
2951 */
2952 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00002953
2954 /* The lower 16bits of the EICR register are for the queue interrupts
Joe Perchesdbedd442015-03-06 20:49:12 -08002955 * which should be masked here in order to not accidentally clear them if
Jacob Kellerd87d8302013-03-02 07:51:42 +00002956 * the bits are high when ixgbe_msix_other is called. There is a race
2957 * condition otherwise which results in possible performance loss
2958 * especially if the ixgbe_msix_other interrupt is triggering
2959 * consistently (as it would when PPS is turned on for the X540 device)
2960 */
2961 eicr &= 0xFFFF0000;
2962
Alexander Duyck2c4af692011-07-15 07:29:55 +00002963 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002964
Alexander Duyck2c4af692011-07-15 07:29:55 +00002965 if (eicr & IXGBE_EICR_LSC)
2966 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002967
Alexander Duyck2c4af692011-07-15 07:29:55 +00002968 if (eicr & IXGBE_EICR_MAILBOX)
2969 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002970
Alexander Duyck2c4af692011-07-15 07:29:55 +00002971 switch (hw->mac.type) {
2972 case ixgbe_mac_82599EB:
2973 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002974 case ixgbe_mac_X550:
2975 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002976 case ixgbe_mac_x550em_a:
Don Skidmore597f22d2015-06-09 16:52:02 -07002977 if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
2978 (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
2979 adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
2980 ixgbe_service_event_schedule(adapter);
2981 IXGBE_WRITE_REG(hw, IXGBE_EICR,
2982 IXGBE_EICR_GPI_SDP0_X540);
2983 }
Don Skidmored773ce22014-02-25 17:58:53 -08002984 if (eicr & IXGBE_EICR_ECC) {
2985 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07002986 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08002987 ixgbe_service_event_schedule(adapter);
2988 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
2989 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002990 /* Handle Flow Director Full threshold interrupt */
2991 if (eicr & IXGBE_EICR_FLOW_DIR) {
2992 int reinit_count = 0;
2993 int i;
2994 for (i = 0; i < adapter->num_tx_queues; i++) {
2995 struct ixgbe_ring *ring = adapter->tx_ring[i];
2996 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2997 &ring->state))
2998 reinit_count++;
2999 }
3000 if (reinit_count) {
3001 /* no more flow director interrupts until after init */
3002 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
3003 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
3004 ixgbe_service_event_schedule(adapter);
3005 }
3006 }
3007 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00003008 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00003009 break;
3010 default:
3011 break;
Auke Kok9a799d72007-09-15 14:07:45 -07003012 }
3013
Alexander Duyck2c4af692011-07-15 07:29:55 +00003014 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003015
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003016 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003017 ixgbe_ptp_check_pps_event(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003018
Alexander Duyck2c4af692011-07-15 07:29:55 +00003019 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00003020 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00003021 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00003022
Alexander Duyck2c4af692011-07-15 07:29:55 +00003023 return IRQ_HANDLED;
3024}
3025
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003026static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07003027{
3028 struct ixgbe_q_vector *q_vector = data;
3029
Auke Kok9a799d72007-09-15 14:07:45 -07003030 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003031
3032 if (q_vector->rx.ring || q_vector->tx.ring)
Alexander Duyckef2662b2015-09-29 15:19:43 -07003033 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003034
3035 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003036}
3037
Auke Kok9a799d72007-09-15 14:07:45 -07003038/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00003039 * ixgbe_poll - NAPI Rx polling callback
3040 * @napi: structure for representing this polling device
3041 * @budget: how many packets driver is allowed to clean
3042 *
3043 * This function is used for legacy and MSI, NAPI mode
3044 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00003045int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00003046{
3047 struct ixgbe_q_vector *q_vector =
3048 container_of(napi, struct ixgbe_q_vector, napi);
3049 struct ixgbe_adapter *adapter = q_vector->adapter;
3050 struct ixgbe_ring *ring;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003051 int per_ring_budget, work_done = 0;
Alexander Duyckeb01b972012-02-08 07:51:27 +00003052 bool clean_complete = true;
3053
3054#ifdef CONFIG_IXGBE_DCA
3055 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
3056 ixgbe_update_dca(q_vector);
3057#endif
3058
Alexander Duyck8220bbc2016-03-07 09:30:09 -08003059 ixgbe_for_each_ring(ring, q_vector->tx) {
3060 if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
3061 clean_complete = false;
3062 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00003063
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08003064 /* Exit if we are called by netpoll */
3065 if (budget <= 0)
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003066 return budget;
3067
Alexander Duyckeb01b972012-02-08 07:51:27 +00003068 /* attempt to distribute budget to each queue fairly, but don't allow
3069 * the budget to go below 1 because we'll exit polling */
3070 if (q_vector->rx.count > 1)
3071 per_ring_budget = max(budget/q_vector->rx.count, 1);
3072 else
3073 per_ring_budget = budget;
3074
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003075 ixgbe_for_each_ring(ring, q_vector->rx) {
3076 int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
3077 per_ring_budget);
3078
3079 work_done += cleaned;
Alexander Duyck8220bbc2016-03-07 09:30:09 -08003080 if (cleaned >= per_ring_budget)
3081 clean_complete = false;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003082 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00003083
3084 /* If all work not completed, return budget and keep polling */
3085 if (!clean_complete)
3086 return budget;
3087
3088 /* all work done, exit the polling mode */
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003089 napi_complete_done(napi, work_done);
Alexander Duyckeb01b972012-02-08 07:51:27 +00003090 if (adapter->rx_itr_setting & 1)
3091 ixgbe_set_itr(q_vector);
3092 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003093 ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx));
Alexander Duyckeb01b972012-02-08 07:51:27 +00003094
Paolo Abeni4b732cd2016-06-15 15:37:59 +02003095 return min(work_done, budget - 1);
Alexander Duyckeb01b972012-02-08 07:51:27 +00003096}
3097
3098/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003099 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
3100 * @adapter: board private structure
3101 *
3102 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
3103 * interrupts from the kernel.
3104 **/
3105static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
3106{
3107 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00003108 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00003109 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003110
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003111 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08003112 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00003113 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08003114
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003115 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00003116 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003117 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08003118 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003119 } else if (q_vector->rx.ring) {
3120 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3121 "%s-%s-%d", netdev->name, "rx", ri++);
3122 } else if (q_vector->tx.ring) {
3123 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3124 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08003125 } else {
3126 /* skip this unused q_vector */
3127 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08003128 }
Alexander Duyck207867f2011-07-15 03:05:37 +00003129 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
3130 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003131 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00003132 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00003133 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003134 goto free_queue_irqs;
3135 }
Alexander Duyck207867f2011-07-15 03:05:37 +00003136 /* If Flow Director is enabled, set interrupt affinity */
3137 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3138 /* assign the mask for this irq */
3139 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00003140 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00003141 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003142 }
3143
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003144 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00003145 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003146 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00003147 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003148 goto free_queue_irqs;
3149 }
3150
3151 return 0;
3152
3153free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00003154 while (vector) {
3155 vector--;
3156 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
3157 NULL);
3158 free_irq(adapter->msix_entries[vector].vector,
3159 adapter->q_vector[vector]);
3160 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003161 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3162 pci_disable_msix(adapter->pdev);
3163 kfree(adapter->msix_entries);
3164 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003165 return err;
3166}
3167
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08003168/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003169 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07003170 * @irq: interrupt number
3171 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07003172 **/
3173static irqreturn_t ixgbe_intr(int irq, void *data)
3174{
Alexander Duycka65151ba22011-05-27 05:31:32 +00003175 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07003176 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003177 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003178 u32 eicr;
3179
Don Skidmore54037502009-02-21 15:42:56 -08003180 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00003181 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08003182 * before the read of EICR.
3183 */
3184 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
3185
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003186 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003187 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003188 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003189 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003190 /*
3191 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003192 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003193 * have disabled interrupts due to EIAM
3194 * finish the workaround of silicon errata on 82598. Unmask
3195 * the interrupt that we masked before the EICR read.
3196 */
3197 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3198 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003199 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003200 }
Auke Kok9a799d72007-09-15 14:07:45 -07003201
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003202 if (eicr & IXGBE_EICR_LSC)
3203 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003204
Alexander Duyckbd508172010-11-16 19:27:03 -08003205 switch (hw->mac.type) {
3206 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003207 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00003208 /* Fall through */
3209 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003210 case ixgbe_mac_X550:
3211 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003212 case ixgbe_mac_x550em_a:
Don Skidmored773ce22014-02-25 17:58:53 -08003213 if (eicr & IXGBE_EICR_ECC) {
3214 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07003215 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08003216 ixgbe_service_event_schedule(adapter);
3217 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3218 }
Jacob Keller4f51bf72011-08-20 04:49:45 +00003219 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08003220 break;
3221 default:
3222 break;
3223 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003224
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003225 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003226 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003227 ixgbe_ptp_check_pps_event(adapter);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003228
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00003229 /* would disable interrupts here but EIAM disabled it */
Alexander Duyckef2662b2015-09-29 15:19:43 -07003230 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003231
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003232 /*
3233 * re-enable link(maybe) and non-queue interrupts, no flush.
3234 * ixgbe_poll will re-enable the queue interrupts
3235 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003236 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3237 ixgbe_irq_enable(adapter, false, false);
3238
Auke Kok9a799d72007-09-15 14:07:45 -07003239 return IRQ_HANDLED;
3240}
3241
3242/**
3243 * ixgbe_request_irq - initialize interrupts
3244 * @adapter: board private structure
3245 *
3246 * Attempts to configure interrupts using the best available
3247 * capabilities of the hardware and kernel.
3248 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003249static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003250{
3251 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003252 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003253
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003254 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003255 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003256 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08003257 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003258 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003259 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08003260 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003261 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003262
Alexander Duyckde88eee2012-02-08 07:49:59 +00003263 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00003264 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07003265
Auke Kok9a799d72007-09-15 14:07:45 -07003266 return err;
3267}
3268
3269static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
3270{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003271 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07003272
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003273 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00003274 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003275 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003276 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003277
Mark Rustad1fa71252016-09-28 15:36:38 -07003278 if (!adapter->msix_entries)
3279 return;
3280
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003281 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
3282 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
3283 struct msix_entry *entry = &adapter->msix_entries[vector];
3284
3285 /* free only the irqs that were actually requested */
3286 if (!q_vector->rx.ring && !q_vector->tx.ring)
3287 continue;
3288
3289 /* clear the affinity_mask in the IRQ descriptor */
3290 irq_set_affinity_hint(entry->vector, NULL);
3291
3292 free_irq(entry->vector, q_vector);
3293 }
3294
Babu Moger90c6f872016-06-18 17:40:47 -07003295 free_irq(adapter->msix_entries[vector].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003296}
3297
3298/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003299 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
3300 * @adapter: board private structure
3301 **/
3302static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
3303{
Alexander Duyckbd508172010-11-16 19:27:03 -08003304 switch (adapter->hw.mac.type) {
3305 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003306 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003307 break;
3308 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003309 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003310 case ixgbe_mac_X550:
3311 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003312 case ixgbe_mac_x550em_a:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003313 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
3314 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003315 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003316 break;
3317 default:
3318 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003319 }
3320 IXGBE_WRITE_FLUSH(&adapter->hw);
3321 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003322 int vector;
3323
3324 for (vector = 0; vector < adapter->num_q_vectors; vector++)
3325 synchronize_irq(adapter->msix_entries[vector].vector);
3326
3327 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003328 } else {
3329 synchronize_irq(adapter->pdev->irq);
3330 }
3331}
3332
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003333/**
Auke Kok9a799d72007-09-15 14:07:45 -07003334 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
3335 *
3336 **/
3337static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
3338{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003339 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003340
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003341 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07003342
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003343 ixgbe_set_ivar(adapter, 0, 0, 0);
3344 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003345
Emil Tantilov396e7992010-07-01 20:05:12 +00003346 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07003347}
3348
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003349/**
3350 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3351 * @adapter: board private structure
3352 * @ring: structure containing ring specific data
3353 *
3354 * Configure the Tx descriptor ring after a reset.
3355 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00003356void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
3357 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003358{
3359 struct ixgbe_hw *hw = &adapter->hw;
3360 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003361 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003362 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003363 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003364
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003365 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003366 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003367 IXGBE_WRITE_FLUSH(hw);
3368
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003369 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00003370 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003371 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3372 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3373 ring->count * sizeof(union ixgbe_adv_tx_desc));
3374 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3375 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003376 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003377
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003378 /*
3379 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00003380 * higher than 1 when:
3381 * - ITR is 0 as it could cause false TX hangs
3382 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003383 *
3384 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3385 * to or less than the number of on chip descriptors, which is
3386 * currently 40.
3387 */
Emil Tantilov67da0972013-01-25 06:19:20 +00003388 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003389 txdctl |= 1u << 16; /* WTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003390 else
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003391 txdctl |= 8u << 16; /* WTHRESH = 8 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003392
Alexander Duycke954b372012-02-08 07:49:38 +00003393 /*
3394 * Setting PTHRESH to 32 both improves performance
3395 * and avoids a TX hang with DFP enabled
3396 */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003397 txdctl |= (1u << 8) | /* HTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003398 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003399
3400 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00003401 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08003402 ring->atr_sample_rate = adapter->atr_sample_rate;
3403 ring->atr_count = 0;
3404 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3405 } else {
3406 ring->atr_sample_rate = 0;
3407 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003408
Alexander Duyckfd786b72013-01-12 06:33:31 +00003409 /* initialize XPS */
3410 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3411 struct ixgbe_q_vector *q_vector = ring->q_vector;
3412
3413 if (q_vector)
John Fastabend2a47fa42013-11-06 09:54:52 -08003414 netif_set_xps_queue(ring->netdev,
Alexander Duyckfd786b72013-01-12 06:33:31 +00003415 &q_vector->affinity_mask,
3416 ring->queue_index);
3417 }
3418
John Fastabendc84d3242010-11-16 19:27:12 -08003419 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3420
Alexander Duyckffed21b2017-01-17 08:37:29 -08003421 /* reinitialize tx_buffer_info */
3422 memset(ring->tx_buffer_info, 0,
3423 sizeof(struct ixgbe_tx_buffer) * ring->count);
3424
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003425 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003426 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3427
3428 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3429 if (hw->mac.type == ixgbe_mac_82598EB &&
3430 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3431 return;
3432
3433 /* poll to verify queue is enabled */
3434 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003435 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003436 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3437 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3438 if (!wait_loop)
Emil Tantilova55defd2016-07-29 10:30:06 -07003439 hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003440}
3441
Alexander Duyck120ff942010-08-19 13:34:50 +00003442static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3443{
3444 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003445 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003446 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00003447
3448 if (hw->mac.type == ixgbe_mac_82598EB)
3449 return;
3450
3451 /* disable the arbiter while setting MTQC */
3452 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3453 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3454 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3455
3456 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003457 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3458 mtqc = IXGBE_MTQC_VT_ENA;
3459 if (tcs > 4)
3460 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3461 else if (tcs > 1)
3462 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
Alexander Duycke24fcf22016-09-07 20:28:24 -07003463 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3464 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003465 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003466 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003467 mtqc |= IXGBE_MTQC_64VF;
3468 } else {
3469 if (tcs > 4)
3470 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3471 else if (tcs > 1)
3472 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3473 else
3474 mtqc = IXGBE_MTQC_64Q_1PB;
3475 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003476
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003477 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003478
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003479 /* Enable Security TX Buffer IFG for multiple pb */
3480 if (tcs) {
3481 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3482 sectx |= IXGBE_SECTX_DCB;
3483 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003484 }
3485
3486 /* re-enable the arbiter */
3487 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3488 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3489}
3490
Auke Kok9a799d72007-09-15 14:07:45 -07003491/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003492 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003493 * @adapter: board private structure
3494 *
3495 * Configure the Tx unit of the MAC after a reset.
3496 **/
3497static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3498{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003499 struct ixgbe_hw *hw = &adapter->hw;
3500 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003501 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003502
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003503 ixgbe_setup_mtqc(adapter);
3504
3505 if (hw->mac.type != ixgbe_mac_82598EB) {
3506 /* DMATXCTL.EN must be before Tx queues are enabled */
3507 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3508 dmatxctl |= IXGBE_DMATXCTL_TE;
3509 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3510 }
3511
Auke Kok9a799d72007-09-15 14:07:45 -07003512 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003513 for (i = 0; i < adapter->num_tx_queues; i++)
3514 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07003515 for (i = 0; i < adapter->num_xdp_queues; i++)
3516 ixgbe_configure_tx_ring(adapter, adapter->xdp_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003517}
3518
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003519static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3520 struct ixgbe_ring *ring)
3521{
3522 struct ixgbe_hw *hw = &adapter->hw;
3523 u8 reg_idx = ring->reg_idx;
3524 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3525
3526 srrctl |= IXGBE_SRRCTL_DROP_EN;
3527
3528 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3529}
3530
3531static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3532 struct ixgbe_ring *ring)
3533{
3534 struct ixgbe_hw *hw = &adapter->hw;
3535 u8 reg_idx = ring->reg_idx;
3536 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3537
3538 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3539
3540 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3541}
3542
3543#ifdef CONFIG_IXGBE_DCB
3544void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3545#else
3546static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3547#endif
3548{
3549 int i;
3550 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3551
3552 if (adapter->ixgbe_ieee_pfc)
3553 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3554
3555 /*
3556 * We should set the drop enable bit if:
3557 * SR-IOV is enabled
3558 * or
3559 * Number of Rx queues > 1 and flow control is disabled
3560 *
3561 * This allows us to avoid head of line blocking for security
3562 * and performance reasons.
3563 */
3564 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3565 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3566 for (i = 0; i < adapter->num_rx_queues; i++)
3567 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3568 } else {
3569 for (i = 0; i < adapter->num_rx_queues; i++)
3570 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3571 }
3572}
3573
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003574#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003575
Yi Zoua6616b42009-08-06 13:05:23 +00003576static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003577 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003578{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003579 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003580 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003581 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003582
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003583 if (hw->mac.type == ixgbe_mac_82598EB) {
3584 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3585
3586 /*
3587 * if VMDq is not active we must program one srrctl register
3588 * per RSS queue since we have enabled RDRXCTL.MVMEN
3589 */
3590 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003591 }
3592
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003593 /* configure header buffer length, needed for RSC */
3594 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003595
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003596 /* configure the packet buffer length */
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003597 if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state))
3598 srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
3599 else
3600 srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003601
3602 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003603 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003604
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003605 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003606}
3607
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003608/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003609 * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003610 * @adapter: device handle
3611 *
3612 * - 82598/82599/X540: 128
3613 * - X550(non-SRIOV mode): 512
3614 * - X550(SRIOV mode): 64
3615 */
Vlad Zolotarov7f276ef2015-03-30 21:18:58 +03003616u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003617{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003618 if (adapter->hw.mac.type < ixgbe_mac_X550)
3619 return 128;
3620 else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3621 return 64;
3622 else
3623 return 512;
3624}
3625
3626/**
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003627 * ixgbe_store_key - Write the RSS key to HW
3628 * @adapter: device handle
3629 *
3630 * Write the RSS key stored in adapter.rss_key to HW.
3631 */
3632void ixgbe_store_key(struct ixgbe_adapter *adapter)
3633{
3634 struct ixgbe_hw *hw = &adapter->hw;
3635 int i;
3636
3637 for (i = 0; i < 10; i++)
3638 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
3639}
3640
3641/**
Tony Nguyen3dfbfc72017-04-13 07:26:05 -07003642 * ixgbe_init_rss_key - Initialize adapter RSS key
3643 * @adapter: device handle
3644 *
3645 * Allocates and initializes the RSS key if it is not allocated.
3646 **/
3647static inline int ixgbe_init_rss_key(struct ixgbe_adapter *adapter)
3648{
3649 u32 *rss_key;
3650
3651 if (!adapter->rss_key) {
3652 rss_key = kzalloc(IXGBE_RSS_KEY_SIZE, GFP_KERNEL);
3653 if (unlikely(!rss_key))
3654 return -ENOMEM;
3655
3656 netdev_rss_key_fill(rss_key, IXGBE_RSS_KEY_SIZE);
3657 adapter->rss_key = rss_key;
3658 }
3659
3660 return 0;
3661}
3662
3663/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003664 * ixgbe_store_reta - Write the RETA table to HW
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003665 * @adapter: device handle
3666 *
3667 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3668 */
Tom Barbette1c7cf072015-06-26 15:40:18 +02003669void ixgbe_store_reta(struct ixgbe_adapter *adapter)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003670{
3671 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
Alexander Duyck05abb122010-08-19 13:35:41 +00003672 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmored1b849b2014-11-09 06:42:57 +00003673 u32 reta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003674 u32 indices_multi;
3675 u8 *indir_tbl = adapter->rss_indir_tbl;
John Fastabend86b4db32011-04-26 07:26:19 +00003676
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003677 /* Fill out the redirection table as follows:
3678 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3679 * indices.
3680 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3681 * - X550: 8 bit wide entries containing 6 bit RSS index
3682 */
3683 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3684 indices_multi = 0x11;
3685 else
3686 indices_multi = 0x1;
3687
3688 /* Write redirection table to HW */
3689 for (i = 0; i < reta_entries; i++) {
3690 reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
3691 if ((i & 3) == 3) {
3692 if (i < 128)
3693 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3694 else
3695 IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
3696 reta);
3697 reta = 0;
3698 }
3699 }
3700}
3701
3702/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003703 * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003704 * @adapter: device handle
3705 *
3706 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3707 */
3708static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
3709{
3710 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3711 struct ixgbe_hw *hw = &adapter->hw;
3712 u32 vfreta = 0;
3713 unsigned int pf_pool = adapter->num_vfs;
3714
3715 /* Write redirection table to HW */
3716 for (i = 0; i < reta_entries; i++) {
3717 vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
3718 if ((i & 3) == 3) {
3719 IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool),
3720 vfreta);
3721 vfreta = 0;
3722 }
3723 }
3724}
3725
3726static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
3727{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003728 u32 i, j;
3729 u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3730 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3731
Alexander Duycke24fcf22016-09-07 20:28:24 -07003732 /* Program table for at least 4 queues w/ SR-IOV so that VFs can
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003733 * make full use of any rings they may have. We will use the
3734 * PSRTYPE register to control how many rings we use within the PF.
3735 */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003736 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4))
3737 rss_i = 4;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003738
Alexander Duyck05abb122010-08-19 13:35:41 +00003739 /* Fill out hash function seeds */
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003740 ixgbe_store_key(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003741
Alexander Duyck05abb122010-08-19 13:35:41 +00003742 /* Fill out redirection table */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003743 memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
3744
Don Skidmore0f9b2322014-11-18 09:35:08 +00003745 for (i = 0, j = 0; i < reta_entries; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003746 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003747 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003748
3749 adapter->rss_indir_tbl[i] = j;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003750 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003751
3752 ixgbe_store_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003753}
3754
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003755static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
Don Skidmore0f9b2322014-11-18 09:35:08 +00003756{
3757 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003758 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3759 unsigned int pf_pool = adapter->num_vfs;
3760 int i, j;
3761
3762 /* Fill out hash function seeds */
3763 for (i = 0; i < 10; i++)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003764 IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool),
Tony Nguyen3dfbfc72017-04-13 07:26:05 -07003765 *(adapter->rss_key + i));
Don Skidmore0f9b2322014-11-18 09:35:08 +00003766
3767 /* Fill out the redirection table */
3768 for (i = 0, j = 0; i < 64; i++, j++) {
3769 if (j == rss_i)
3770 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003771
3772 adapter->rss_indir_tbl[i] = j;
Alexander Duyck05abb122010-08-19 13:35:41 +00003773 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003774
3775 ixgbe_store_vfreta(adapter);
Don Skidmored1b849b2014-11-09 06:42:57 +00003776}
3777
3778static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3779{
3780 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003781 u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
Don Skidmored1b849b2014-11-09 06:42:57 +00003782 u32 rxcsum;
Alexander Duyck05abb122010-08-19 13:35:41 +00003783
3784 /* Disable indicating checksum in descriptor, enables RSS hash */
3785 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3786 rxcsum |= IXGBE_RXCSUM_PCSD;
3787 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3788
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003789 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003790 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003791 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003792 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003793 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003794
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003795 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3796 if (tcs > 4)
3797 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3798 else if (tcs > 1)
3799 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003800 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3801 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003802 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3803 else
3804 mrqc = IXGBE_MRQC_VMDQRSS64EN;
Emil Tantilove6b41c82017-04-25 11:31:06 -07003805
3806 /* Enable L3/L4 for Tx Switched packets */
3807 mrqc |= IXGBE_MRQC_L3L4TXSWEN;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003808 } else {
3809 if (tcs > 4)
3810 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3811 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003812 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3813 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003814 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003815 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003816 }
3817
Alexander Duyck05abb122010-08-19 13:35:41 +00003818 /* Perform hash on these packet types */
Don Skidmored1b849b2014-11-09 06:42:57 +00003819 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3820 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3821 IXGBE_MRQC_RSS_FIELD_IPV6 |
3822 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003823
Alexander Duyckef6afc02012-02-08 07:51:53 +00003824 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003825 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003826 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003827 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003828
Don Skidmore0f9b2322014-11-18 09:35:08 +00003829 if ((hw->mac.type >= ixgbe_mac_X550) &&
3830 (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
3831 unsigned int pf_pool = adapter->num_vfs;
3832
3833 /* Enable VF RSS mode */
3834 mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
3835 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3836
3837 /* Setup RSS through the VF registers */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003838 ixgbe_setup_vfreta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003839 vfmrqc = IXGBE_MRQC_RSSEN;
3840 vfmrqc |= rss_field;
3841 IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc);
3842 } else {
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003843 ixgbe_setup_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003844 mrqc |= rss_field;
3845 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3846 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003847}
3848
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003849/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003850 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3851 * @adapter: address of board private structure
3852 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003853 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003854static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003855 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003856{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003857 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003858 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003859 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003860
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003861 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003862 return;
3863
Alexander Duyck73670962010-08-19 13:38:34 +00003864 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003865 rscctrl |= IXGBE_RSCCTL_RSCEN;
3866 /*
3867 * we must limit the number of descriptors so that the
3868 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003869 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003870 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003871 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003872 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003873}
3874
Alexander Duyck9e10e042010-08-19 13:40:06 +00003875#define IXGBE_MAX_RX_DESC_POLL 10
3876static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3877 struct ixgbe_ring *ring)
3878{
3879 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003880 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3881 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003882 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003883
Mark Rustadb0483c82014-01-14 18:53:17 -08003884 if (ixgbe_removed(hw->hw_addr))
3885 return;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003886 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3887 if (hw->mac.type == ixgbe_mac_82598EB &&
3888 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3889 return;
3890
3891 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003892 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003893 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3894 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3895
3896 if (!wait_loop) {
3897 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3898 "the polling period\n", reg_idx);
3899 }
3900}
3901
Yi Zou2d39d572011-01-06 14:29:56 +00003902void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3903 struct ixgbe_ring *ring)
3904{
3905 struct ixgbe_hw *hw = &adapter->hw;
3906 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3907 u32 rxdctl;
3908 u8 reg_idx = ring->reg_idx;
3909
Mark Rustadb0483c82014-01-14 18:53:17 -08003910 if (ixgbe_removed(hw->hw_addr))
3911 return;
Yi Zou2d39d572011-01-06 14:29:56 +00003912 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3913 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3914
3915 /* write value back with RXDCTL.ENABLE bit cleared */
3916 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3917
3918 if (hw->mac.type == ixgbe_mac_82598EB &&
3919 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3920 return;
3921
3922 /* the hardware may take up to 100us to really disable the rx queue */
3923 do {
3924 udelay(10);
3925 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3926 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3927
3928 if (!wait_loop) {
3929 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3930 "the polling period\n", reg_idx);
3931 }
3932}
3933
Alexander Duyck84418e32010-08-19 13:40:54 +00003934void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3935 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003936{
3937 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc3630cc2017-01-17 08:36:28 -08003938 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyckacd37172010-08-19 13:36:05 +00003939 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003940 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003941 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003942
Alexander Duyck9e10e042010-08-19 13:40:06 +00003943 /* disable queue to avoid issues while updating state */
3944 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003945 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003946
Alexander Duyckacd37172010-08-19 13:36:05 +00003947 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3948 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3949 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3950 ring->count * sizeof(union ixgbe_adv_rx_desc));
Neerav Parikh8b754512015-12-08 22:13:58 -08003951 /* Force flushing of IXGBE_RDLEN to prevent MDD */
3952 IXGBE_WRITE_FLUSH(hw);
3953
Alexander Duyckacd37172010-08-19 13:36:05 +00003954 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3955 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003956 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003957
3958 ixgbe_configure_srrctl(adapter, ring);
3959 ixgbe_configure_rscctl(adapter, ring);
3960
3961 if (hw->mac.type == ixgbe_mac_82598EB) {
3962 /*
3963 * enable cache line friendly hardware writes:
3964 * PTHRESH=32 descriptors (half the internal cache),
3965 * this also removes ugly rx_no_buffer_count increment
3966 * HTHRESH=4 descriptors (to minimize latency on fetch)
3967 * WTHRESH=8 burst writeback up to two cache lines
3968 */
3969 rxdctl &= ~0x3FFFFF;
3970 rxdctl |= 0x080420;
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003971#if (PAGE_SIZE < 8192)
3972 } else {
3973 rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK |
3974 IXGBE_RXDCTL_RLPML_EN);
3975
3976 /* Limit the maximum frame size so we don't overrun the skb */
3977 if (ring_uses_build_skb(ring) &&
3978 !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state))
Alexander Duyck541ea692017-03-02 15:01:05 -08003979 rxdctl |= IXGBE_MAX_2K_FRAME_BUILD_SKB |
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003980 IXGBE_RXDCTL_RLPML_EN;
3981#endif
Alexander Duyck9e10e042010-08-19 13:40:06 +00003982 }
3983
Alexander Duyckffed21b2017-01-17 08:37:29 -08003984 /* initialize rx_buffer_info */
3985 memset(ring->rx_buffer_info, 0,
3986 sizeof(struct ixgbe_rx_buffer) * ring->count);
3987
Alexander Duyckc3630cc2017-01-17 08:36:28 -08003988 /* initialize Rx descriptor 0 */
3989 rx_desc = IXGBE_RX_DESC(ring, 0);
3990 rx_desc->wb.upper.length = 0;
3991
Alexander Duyck9e10e042010-08-19 13:40:06 +00003992 /* enable receive descriptor ring */
3993 rxdctl |= IXGBE_RXDCTL_ENABLE;
3994 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3995
3996 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003997 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003998}
3999
Alexander Duyck48654522010-08-19 13:36:27 +00004000static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
4001{
4002 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00004003 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend2a47fa42013-11-06 09:54:52 -08004004 u16 pool;
Alexander Duyck48654522010-08-19 13:36:27 +00004005
4006 /* PSRTYPE must be initialized in non 82598 adapters */
4007 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00004008 IXGBE_PSRTYPE_UDPHDR |
4009 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00004010 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00004011 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00004012
4013 if (hw->mac.type == ixgbe_mac_82598EB)
4014 return;
4015
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00004016 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004017 psrtype |= 2u << 29;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00004018 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004019 psrtype |= 1u << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00004020
John Fastabend2a47fa42013-11-06 09:54:52 -08004021 for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
4022 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
Alexander Duyck48654522010-08-19 13:36:27 +00004023}
4024
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004025static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
4026{
4027 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004028 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00004029 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00004030 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004031
4032 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
4033 return;
4034
4035 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00004036 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
4037 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004038 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00004039 vmdctl |= IXGBE_VT_CTL_REPLEN;
4040 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004041
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004042 vf_shift = VMDQ_P(0) % 32;
4043 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004044
4045 /* Enable only the PF's pool for Tx/Rx */
Emil Tantilov11f2b492016-05-04 15:01:27 -07004046 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00004047 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
Emil Tantilov11f2b492016-05-04 15:01:27 -07004048 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00004049 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07004050 if (adapter->bridge_mode == BRIDGE_MODE_VEB)
Greg Rose9b735982012-11-08 02:41:35 +00004051 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004052
4053 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004054 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004055
Alexander Duyck16369562015-11-02 17:10:13 -08004056 /* clear VLAN promisc flag so VFTA will be updated if necessary */
4057 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4058
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004059 /*
4060 * Set up VF register offsets for selected VT Mode,
4061 * i.e. 32 or 64 VFs for SR-IOV
4062 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00004063 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4064 case IXGBE_82599_VMDQ_8Q_MASK:
4065 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
4066 break;
4067 case IXGBE_82599_VMDQ_4Q_MASK:
4068 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
4069 break;
4070 default:
4071 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
4072 break;
4073 }
4074
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004075 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
4076
Greg Rosede4c7f62011-09-29 05:57:33 +00004077 for (i = 0; i < adapter->num_vfs; i++) {
Emil Tantilov77f192a2016-03-18 16:11:14 -07004078 /* configure spoof checking */
4079 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i,
4080 adapter->vfinfo[i].spoofchk_enabled);
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03004081
4082 /* Enable/Disable RSS query feature */
4083 ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
4084 adapter->vfinfo[i].rss_query_enabled);
Greg Rosede4c7f62011-09-29 05:57:33 +00004085 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004086}
4087
Alexander Duyck477de6e2010-08-19 13:38:11 +00004088static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004089{
Auke Kok9a799d72007-09-15 14:07:45 -07004090 struct ixgbe_hw *hw = &adapter->hw;
4091 struct net_device *netdev = adapter->netdev;
4092 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004093 struct ixgbe_ring *rx_ring;
4094 int i;
4095 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00004096
Alexander Duyck477de6e2010-08-19 13:38:11 +00004097#ifdef IXGBE_FCOE
4098 /* adjust max frame to be able to do baby jumbo for FCoE */
4099 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
4100 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
4101 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4102
4103#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00004104
4105 /* adjust max frame to be at least the size of a standard frame */
4106 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
4107 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
4108
Alexander Duyck477de6e2010-08-19 13:38:11 +00004109 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
4110 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
4111 mhadd &= ~IXGBE_MHADD_MFS_MASK;
4112 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
4113
4114 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07004115 }
4116
Auke Kok9a799d72007-09-15 14:07:45 -07004117 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004118 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
4119 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07004120 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
4121
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004122 /*
4123 * Setup the HW Rx Head and Tail Descriptor Pointers and
4124 * the Base and Length of the Rx Descriptor Ring
4125 */
Auke Kok9a799d72007-09-15 14:07:45 -07004126 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004127 rx_ring = adapter->rx_ring[i];
Alexander Duyck4f4542b2017-01-17 08:36:14 -08004128
4129 clear_ring_rsc_enabled(rx_ring);
4130 clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004131 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
Alexander Duyck4f4542b2017-01-17 08:36:14 -08004132
Alexander Duyck7d637bc2010-11-16 19:26:56 -08004133 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
4134 set_ring_rsc_enabled(rx_ring);
Alexander Duyck4f4542b2017-01-17 08:36:14 -08004135
4136 if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state))
4137 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004138
Alexander Duyck6f429222017-01-17 08:37:13 -08004139 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004140 if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY)
4141 continue;
4142
4143 set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
4144
4145#if (PAGE_SIZE < 8192)
4146 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
4147 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
4148
Alexander Duyck541ea692017-03-02 15:01:05 -08004149 if (IXGBE_2K_TOO_SMALL_WITH_PADDING ||
4150 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004151 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
4152#endif
Alexander Duyck477de6e2010-08-19 13:38:11 +00004153 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00004154}
4155
Alexander Duyck73670962010-08-19 13:38:34 +00004156static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
4157{
4158 struct ixgbe_hw *hw = &adapter->hw;
4159 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
4160
4161 switch (hw->mac.type) {
4162 case ixgbe_mac_82598EB:
4163 /*
4164 * For VMDq support of different descriptor types or
4165 * buffer sizes through the use of multiple SRRCTL
4166 * registers, RDRXCTL.MVMEN must be set to 1
4167 *
4168 * also, the manual doesn't mention it clearly but DCA hints
4169 * will only use queue 0's tags unless this bit is set. Side
4170 * effects of setting this bit are only that SRRCTL must be
4171 * fully programmed [0..15]
4172 */
4173 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
4174 break;
Mark Rustad052a1a72015-08-08 16:19:04 -07004175 case ixgbe_mac_X550:
4176 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004177 case ixgbe_mac_x550em_a:
Mark Rustadf961dda2015-08-08 16:19:09 -07004178 if (adapter->num_vfs)
4179 rdrxctl |= IXGBE_RDRXCTL_PSP;
4180 /* fall through for older HW */
Alexander Duyck73670962010-08-19 13:38:34 +00004181 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004182 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00004183 /* Disable RSC for ACK packets */
4184 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
4185 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
4186 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
4187 /* hardware requires some bits to be set by default */
4188 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
4189 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
4190 break;
4191 default:
4192 /* We should do nothing since we don't know this hardware */
4193 return;
4194 }
4195
4196 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
4197}
4198
Alexander Duyck477de6e2010-08-19 13:38:11 +00004199/**
4200 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
4201 * @adapter: board private structure
4202 *
4203 * Configure the Rx unit of the MAC after a reset.
4204 **/
4205static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
4206{
4207 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004208 int i;
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004209 u32 rxctrl, rfctl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004210
4211 /* disable receives while setting up the descriptors */
Don Skidmore1f9ac572015-03-13 13:54:30 -07004212 hw->mac.ops.disable_rx(hw);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004213
4214 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00004215 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004216
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004217 /* RSC Setup */
4218 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
4219 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
4220 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
4221 rfctl |= IXGBE_RFCTL_RSC_DIS;
Emil Tantilova21d0822016-08-10 11:19:23 -07004222
4223 /* disable NFS filtering */
4224 rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS);
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004225 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
4226
Alexander Duyck9e10e042010-08-19 13:40:06 +00004227 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004228 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004229
Alexander Duyck477de6e2010-08-19 13:38:11 +00004230 /* set_rx_buffer_len must be called before ring initialization */
4231 ixgbe_set_rx_buffer_len(adapter);
4232
4233 /*
4234 * Setup the HW Rx Head and Tail Descriptor Pointers and
4235 * the Base and Length of the Rx Descriptor Ring
4236 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00004237 for (i = 0; i < adapter->num_rx_queues; i++)
4238 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004239
Don Skidmore1f9ac572015-03-13 13:54:30 -07004240 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004241 /* disable drop enable for 82598 parts */
4242 if (hw->mac.type == ixgbe_mac_82598EB)
4243 rxctrl |= IXGBE_RXCTRL_DMBYPS;
4244
4245 /* enable all receives */
4246 rxctrl |= IXGBE_RXCTRL_RXEN;
4247 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07004248}
4249
Patrick McHardy80d5c362013-04-19 02:04:28 +00004250static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
4251 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004252{
4253 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004254 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004255
4256 /* add VID to filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004257 if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4258 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
4259
Jesse Grossf62bbb52010-10-20 13:56:10 +00004260 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004261
4262 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004263}
4264
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004265static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
4266{
4267 u32 vlvf;
4268 int idx;
4269
4270 /* short cut the special case */
4271 if (vlan == 0)
4272 return 0;
4273
4274 /* Search for the vlan id in the VLVF entries */
4275 for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
4276 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
4277 if ((vlvf & VLAN_VID_MASK) == vlan)
4278 break;
4279 }
4280
4281 return idx;
4282}
4283
4284void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
4285{
4286 struct ixgbe_hw *hw = &adapter->hw;
4287 u32 bits, word;
4288 int idx;
4289
4290 idx = ixgbe_find_vlvf_entry(hw, vid);
4291 if (!idx)
4292 return;
4293
4294 /* See if any other pools are set for this VLAN filter
4295 * entry other than the PF.
4296 */
4297 word = idx * 2 + (VMDQ_P(0) / 32);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004298 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004299 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4300
4301 /* Disable the filter so this falls into the default pool. */
4302 if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
4303 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4304 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
4305 IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
4306 }
4307}
4308
Patrick McHardy80d5c362013-04-19 02:04:28 +00004309static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
4310 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004311{
4312 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004313 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004314
Auke Kok9a799d72007-09-15 14:07:45 -07004315 /* remove VID from filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004316 if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004317 hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
4318
Jesse Grossf62bbb52010-10-20 13:56:10 +00004319 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004320
4321 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004322}
4323
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004324/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004325 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
4326 * @adapter: driver data
4327 */
4328static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
4329{
4330 struct ixgbe_hw *hw = &adapter->hw;
4331 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004332 int i, j;
4333
4334 switch (hw->mac.type) {
4335 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004336 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4337 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004338 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4339 break;
4340 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004341 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004342 case ixgbe_mac_X550:
4343 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004344 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004345 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004346 struct ixgbe_ring *ring = adapter->rx_ring[i];
4347
4348 if (ring->l2_accel_priv)
4349 continue;
4350 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004351 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4352 vlnctrl &= ~IXGBE_RXDCTL_VME;
4353 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4354 }
4355 break;
4356 default:
4357 break;
4358 }
4359}
4360
4361/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004362 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004363 * @adapter: driver data
4364 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00004365static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004366{
4367 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00004368 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004369 int i, j;
4370
4371 switch (hw->mac.type) {
4372 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004373 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4374 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004375 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4376 break;
4377 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004378 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004379 case ixgbe_mac_X550:
4380 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004381 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004382 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004383 struct ixgbe_ring *ring = adapter->rx_ring[i];
4384
4385 if (ring->l2_accel_priv)
4386 continue;
4387 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004388 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4389 vlnctrl |= IXGBE_RXDCTL_VME;
4390 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4391 }
4392 break;
4393 default:
4394 break;
4395 }
4396}
4397
Alexander Duyck16369562015-11-02 17:10:13 -08004398static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
4399{
4400 struct ixgbe_hw *hw = &adapter->hw;
4401 u32 vlnctrl, i;
4402
Alexander Duyckf60439b2016-08-11 14:51:56 -07004403 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4404
Emil Tantilov691e4122016-08-22 16:17:46 -07004405 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
4406 /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
4407 vlnctrl |= IXGBE_VLNCTRL_VFE;
4408 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4409 } else {
Alexander Duyckf60439b2016-08-11 14:51:56 -07004410 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Alexander Duyck16369562015-11-02 17:10:13 -08004411 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4412 return;
4413 }
4414
Emil Tantilov691e4122016-08-22 16:17:46 -07004415 /* Nothing to do for 82598 */
4416 if (hw->mac.type == ixgbe_mac_82598EB)
4417 return;
4418
Alexander Duyck16369562015-11-02 17:10:13 -08004419 /* We are already in VLAN promisc, nothing to do */
4420 if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
4421 return;
4422
4423 /* Set flag so we don't redo unnecessary work */
4424 adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
4425
4426 /* Add PF to all active pools */
4427 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4428 u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
4429 u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
4430
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004431 vlvfb |= BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004432 IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
4433 }
4434
4435 /* Set all bits in the VLAN filter table array */
4436 for (i = hw->mac.vft_size; i--;)
4437 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
4438}
4439
4440#define VFTA_BLOCK_SIZE 8
4441static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
4442{
4443 struct ixgbe_hw *hw = &adapter->hw;
4444 u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
4445 u32 vid_start = vfta_offset * 32;
4446 u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
4447 u32 i, vid, word, bits;
4448
4449 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4450 u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
4451
4452 /* pull VLAN ID from VLVF */
4453 vid = vlvf & VLAN_VID_MASK;
4454
4455 /* only concern outselves with a certain range */
4456 if (vid < vid_start || vid >= vid_end)
4457 continue;
4458
4459 if (vlvf) {
4460 /* record VLAN ID in VFTA */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004461 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004462
4463 /* if PF is part of this then continue */
4464 if (test_bit(vid, adapter->active_vlans))
4465 continue;
4466 }
4467
4468 /* remove PF from the pool */
4469 word = i * 2 + VMDQ_P(0) / 32;
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004470 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004471 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4472 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
4473 }
4474
4475 /* extract values from active_vlans and write back to VFTA */
4476 for (i = VFTA_BLOCK_SIZE; i--;) {
4477 vid = (vfta_offset + i) * 32;
4478 word = vid / BITS_PER_LONG;
4479 bits = vid % BITS_PER_LONG;
4480
4481 vfta[i] |= adapter->active_vlans[word] >> bits;
4482
4483 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
4484 }
4485}
4486
4487static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
4488{
4489 struct ixgbe_hw *hw = &adapter->hw;
4490 u32 vlnctrl, i;
4491
Alexander Duyckf60439b2016-08-11 14:51:56 -07004492 /* Set VLAN filtering to enabled */
4493 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4494 vlnctrl |= IXGBE_VLNCTRL_VFE;
4495 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4496
Emil Tantilov691e4122016-08-22 16:17:46 -07004497 if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) ||
4498 hw->mac.type == ixgbe_mac_82598EB)
Alexander Duyck16369562015-11-02 17:10:13 -08004499 return;
Alexander Duyck16369562015-11-02 17:10:13 -08004500
4501 /* We are not in VLAN promisc, nothing to do */
4502 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4503 return;
4504
4505 /* Set flag so we don't redo unnecessary work */
4506 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4507
4508 for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
4509 ixgbe_scrub_vfta(adapter, i);
4510}
4511
Auke Kok9a799d72007-09-15 14:07:45 -07004512static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
4513{
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004514 u16 vid = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07004515
Patrick McHardy80d5c362013-04-19 02:04:28 +00004516 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004517
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004518 for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004519 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07004520}
4521
4522/**
Jacob Kellerb335e752014-03-25 07:45:27 +00004523 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
4524 * @netdev: network interface device structure
4525 *
4526 * Writes multicast address list to the MTA hash table.
4527 * Returns: -ENOMEM on failure
4528 * 0 on no addresses written
4529 * X on writing X addresses to MTA
4530 **/
4531static int ixgbe_write_mc_addr_list(struct net_device *netdev)
4532{
4533 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4534 struct ixgbe_hw *hw = &adapter->hw;
4535
4536 if (!netif_running(netdev))
4537 return 0;
4538
4539 if (hw->mac.ops.update_mc_addr_list)
4540 hw->mac.ops.update_mc_addr_list(hw, netdev);
4541 else
4542 return -ENOMEM;
4543
4544#ifdef CONFIG_PCI_IOV
Jacob Keller5d7daa32014-03-29 06:51:25 +00004545 ixgbe_restore_vf_multicasts(adapter);
Jacob Kellerb335e752014-03-25 07:45:27 +00004546#endif
4547
4548 return netdev_mc_count(netdev);
4549}
4550
Jacob Keller5d7daa32014-03-29 06:51:25 +00004551#ifdef CONFIG_PCI_IOV
4552void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
4553{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004554 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004555 struct ixgbe_hw *hw = &adapter->hw;
4556 int i;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004557
4558 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4559 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4560
4561 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4562 hw->mac.ops.set_rar(hw, i,
4563 mac_table->addr,
4564 mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004565 IXGBE_RAH_AV);
4566 else
4567 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004568 }
4569}
Jacob Keller5d7daa32014-03-29 06:51:25 +00004570
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004571#endif
Jacob Keller5d7daa32014-03-29 06:51:25 +00004572static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
4573{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004574 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004575 struct ixgbe_hw *hw = &adapter->hw;
4576 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004577
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004578 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4579 if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
4580 continue;
4581
4582 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4583
4584 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4585 hw->mac.ops.set_rar(hw, i,
4586 mac_table->addr,
4587 mac_table->pool,
4588 IXGBE_RAH_AV);
4589 else
4590 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004591 }
4592}
4593
4594static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
4595{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004596 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004597 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004598 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004599
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004600 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4601 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4602 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004603 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004604
Jacob Keller5d7daa32014-03-29 06:51:25 +00004605 ixgbe_sync_mac_table(adapter);
4606}
4607
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004608static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004609{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004610 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004611 struct ixgbe_hw *hw = &adapter->hw;
4612 int i, count = 0;
4613
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004614 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4615 /* do not count default RAR as available */
4616 if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
4617 continue;
4618
4619 /* only count unused and addresses that belong to us */
4620 if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
4621 if (mac_table->pool != pool)
4622 continue;
4623 }
4624
4625 count++;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004626 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004627
Jacob Keller5d7daa32014-03-29 06:51:25 +00004628 return count;
4629}
4630
4631/* this function destroys the first RAR entry */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004632static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004633{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004634 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004635 struct ixgbe_hw *hw = &adapter->hw;
4636
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004637 memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
4638 mac_table->pool = VMDQ_P(0);
4639
4640 mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
4641
4642 hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004643 IXGBE_RAH_AV);
4644}
4645
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004646int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
4647 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004648{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004649 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004650 struct ixgbe_hw *hw = &adapter->hw;
4651 int i;
4652
4653 if (is_zero_ether_addr(addr))
4654 return -EINVAL;
4655
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004656 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4657 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004658 continue;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004659
4660 ether_addr_copy(mac_table->addr, addr);
4661 mac_table->pool = pool;
4662
4663 mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
4664 IXGBE_MAC_STATE_IN_USE;
4665
Jacob Keller5d7daa32014-03-29 06:51:25 +00004666 ixgbe_sync_mac_table(adapter);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004667
Jacob Keller5d7daa32014-03-29 06:51:25 +00004668 return i;
4669 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004670
Jacob Keller5d7daa32014-03-29 06:51:25 +00004671 return -ENOMEM;
4672}
4673
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004674int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
4675 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004676{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004677 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004678 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004679 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004680
4681 if (is_zero_ether_addr(addr))
4682 return -EINVAL;
4683
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004684 /* search table for addr, if found clear IN_USE flag and sync */
4685 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4686 /* we can only delete an entry if it is in use */
4687 if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
4688 continue;
4689 /* we only care about entries that belong to the given pool */
4690 if (mac_table->pool != pool)
4691 continue;
4692 /* we only care about a specific MAC address */
4693 if (!ether_addr_equal(addr, mac_table->addr))
4694 continue;
4695
4696 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4697 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
4698
4699 ixgbe_sync_mac_table(adapter);
4700
4701 return 0;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004702 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004703
Jacob Keller5d7daa32014-03-29 06:51:25 +00004704 return -ENOMEM;
4705}
Jacob Kellerb335e752014-03-25 07:45:27 +00004706/**
Alexander Duyck28500622010-06-15 09:25:48 +00004707 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
4708 * @netdev: network interface device structure
4709 *
4710 * Writes unicast address list to the RAR table.
4711 * Returns: -ENOMEM on failure/insufficient address space
4712 * 0 on no addresses written
4713 * X on writing X addresses to the RAR table
4714 **/
Jacob Keller5d7daa32014-03-29 06:51:25 +00004715static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
Alexander Duyck28500622010-06-15 09:25:48 +00004716{
4717 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck28500622010-06-15 09:25:48 +00004718 int count = 0;
4719
4720 /* return ENOMEM indicating insufficient memory for addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004721 if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn))
Alexander Duyck28500622010-06-15 09:25:48 +00004722 return -ENOMEM;
4723
John Fastabend95447462012-05-31 12:42:26 +00004724 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00004725 struct netdev_hw_addr *ha;
Alexander Duyck28500622010-06-15 09:25:48 +00004726 netdev_for_each_uc_addr(ha, netdev) {
Jacob Keller5d7daa32014-03-29 06:51:25 +00004727 ixgbe_del_mac_filter(adapter, ha->addr, vfn);
4728 ixgbe_add_mac_filter(adapter, ha->addr, vfn);
Alexander Duyck28500622010-06-15 09:25:48 +00004729 count++;
4730 }
4731 }
Alexander Duyck28500622010-06-15 09:25:48 +00004732 return count;
4733}
4734
Alexander Duyck0f079d22015-10-22 16:26:36 -07004735static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
4736{
4737 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4738 int ret;
4739
4740 ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
4741
4742 return min_t(int, ret, 0);
4743}
4744
4745static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
4746{
4747 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4748
4749 ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
4750
4751 return 0;
4752}
4753
Alexander Duyck28500622010-06-15 09:25:48 +00004754/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07004755 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07004756 * @netdev: network interface device structure
4757 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07004758 * The set_rx_method entry point is called whenever the unicast/multicast
4759 * address list or the network interface flags are updated. This routine is
4760 * responsible for configuring the hardware for proper unicast, multicast and
4761 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07004762 **/
Greg Rose7f870472010-01-09 02:25:29 +00004763void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07004764{
4765 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4766 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00004767 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004768 netdev_features_t features = netdev->features;
Alexander Duyck28500622010-06-15 09:25:48 +00004769 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07004770
4771 /* Check for Promiscuous and All Multicast modes */
Auke Kok9a799d72007-09-15 14:07:45 -07004772 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4773
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004774 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00004775 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004776 fctrl |= IXGBE_FCTRL_BAM;
4777 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
4778 fctrl |= IXGBE_FCTRL_PMCF;
4779
Alexander Duyck28500622010-06-15 09:25:48 +00004780 /* clear the bits we are changing the status of */
4781 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Auke Kok9a799d72007-09-15 14:07:45 -07004782 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00004783 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004784 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellerb335e752014-03-25 07:45:27 +00004785 vmolr |= IXGBE_VMOLR_MPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004786 features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004787 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07004788 if (netdev->flags & IFF_ALLMULTI) {
4789 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004790 vmolr |= IXGBE_VMOLR_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07004791 }
Emil Tantilove433ea12010-05-13 17:33:00 +00004792 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00004793 }
4794
4795 /*
4796 * Write addresses to available RAR registers, if there is not
4797 * sufficient space to store all the addresses then enable
4798 * unicast promiscuous mode
4799 */
Alexander Duyck0f079d22015-10-22 16:26:36 -07004800 if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
John Fastabend9dcb3732012-04-15 06:44:25 +00004801 fctrl |= IXGBE_FCTRL_UPE;
4802 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004803 }
4804
Emil Tantilovcf789592013-10-26 08:13:20 +00004805 /* Write addresses to the MTA, if the attempt fails
4806 * then we should just turn on promiscuous mode so
4807 * that we can at least receive multicast traffic
4808 */
Jacob Kellerb335e752014-03-25 07:45:27 +00004809 count = ixgbe_write_mc_addr_list(netdev);
4810 if (count < 0) {
4811 fctrl |= IXGBE_FCTRL_MPE;
4812 vmolr |= IXGBE_VMOLR_MPE;
4813 } else if (count) {
4814 vmolr |= IXGBE_VMOLR_ROMPE;
4815 }
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004816
4817 if (hw->mac.type != ixgbe_mac_82598EB) {
4818 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00004819 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
4820 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004821 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07004822 }
4823
Ben Greear3f2d1c02012-03-08 08:28:41 +00004824 /* This is useful for sniffing bad packets. */
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004825 if (features & NETIF_F_RXALL) {
Ben Greear3f2d1c02012-03-08 08:28:41 +00004826 /* UPE and MPE will be handled by normal PROMISC logic
4827 * in e1000e_set_rx_mode */
4828 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
4829 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
4830 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
4831
4832 fctrl &= ~(IXGBE_FCTRL_DPF);
4833 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4834 }
4835
Auke Kok9a799d72007-09-15 14:07:45 -07004836 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004837
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004838 if (features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00004839 ixgbe_vlan_strip_enable(adapter);
4840 else
4841 ixgbe_vlan_strip_disable(adapter);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004842
4843 if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
4844 ixgbe_vlan_promisc_disable(adapter);
4845 else
4846 ixgbe_vlan_promisc_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004847}
4848
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004849static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4850{
4851 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004852
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08004853 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004854 napi_enable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004855}
4856
4857static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
4858{
4859 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004860
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08004861 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004862 napi_disable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004863}
4864
Emil Tantilova21d0822016-08-10 11:19:23 -07004865static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask)
Mark Rustad67359c32015-06-15 11:33:25 -07004866{
Emil Tantilova21d0822016-08-10 11:19:23 -07004867 struct ixgbe_hw *hw = &adapter->hw;
4868 u32 vxlanctrl;
4869
4870 if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE |
4871 IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)))
4872 return;
4873
4874 vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) && ~mask;
4875 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl);
4876
4877 if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK)
Mark Rustad67359c32015-06-15 11:33:25 -07004878 adapter->vxlan_port = 0;
Emil Tantilova21d0822016-08-10 11:19:23 -07004879
4880 if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK)
4881 adapter->geneve_port = 0;
Mark Rustad67359c32015-06-15 11:33:25 -07004882}
4883
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004884#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004885/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08004886 * ixgbe_configure_dcb - Configure DCB hardware
4887 * @adapter: ixgbe adapter struct
4888 *
4889 * This is called by the driver on open to configure the DCB hardware.
4890 * This is also called by the gennetlink interface when reconfiguring
4891 * the DCB state.
4892 */
4893static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
4894{
4895 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00004896 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004897
Alexander Duyck67ebd792010-08-19 13:34:04 +00004898 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
4899 if (hw->mac.type == ixgbe_mac_82598EB)
4900 netif_set_gso_max_size(adapter->netdev, 65536);
4901 return;
4902 }
4903
4904 if (hw->mac.type == ixgbe_mac_82598EB)
4905 netif_set_gso_max_size(adapter->netdev, 32768);
4906
John Fastabendb1208182011-10-15 05:00:10 +00004907#ifdef IXGBE_FCOE
4908 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
4909 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
4910#endif
4911
Alexander Duyck01fa7d92010-11-16 19:26:53 -08004912 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00004913 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00004914 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4915 DCB_TX_CONFIG);
4916 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
4917 DCB_RX_CONFIG);
4918 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00004919 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
4920 ixgbe_dcb_hw_ets(&adapter->hw,
4921 adapter->ixgbe_ieee_ets,
4922 max_frame);
4923 ixgbe_dcb_hw_pfc_config(&adapter->hw,
4924 adapter->ixgbe_ieee_pfc->pfc_en,
4925 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00004926 }
John Fastabend8187cd42011-02-23 05:58:08 +00004927
4928 /* Enable RSS Hash per TC */
4929 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00004930 u32 msb = 0;
4931 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004932
Alexander Duyckd411a932012-06-30 00:14:01 +00004933 while (rss_i) {
4934 msb++;
4935 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00004936 }
Alexander Duyckd411a932012-06-30 00:14:01 +00004937
Alexander Duyck4ae63732012-06-22 06:46:33 +00004938 /* write msb to all 8 TCs in one write */
4939 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00004940 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004941}
John Fastabend9da712d2011-08-23 03:14:22 +00004942#endif
4943
4944/* Additional bittime to account for IXGBE framing */
4945#define IXGBE_ETH_FRAMING 20
4946
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004947/**
John Fastabend9da712d2011-08-23 03:14:22 +00004948 * ixgbe_hpbthresh - calculate high water mark for flow control
4949 *
4950 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004951 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00004952 */
4953static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
4954{
4955 struct ixgbe_hw *hw = &adapter->hw;
4956 struct net_device *dev = adapter->netdev;
4957 int link, tc, kb, marker;
4958 u32 dv_id, rx_pba;
4959
4960 /* Calculate max LAN frame size */
4961 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
4962
4963#ifdef IXGBE_FCOE
4964 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00004965 if ((dev->features & NETIF_F_FCOE_MTU) &&
4966 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
4967 (pb == ixgbe_fcoe_get_tc(adapter)))
4968 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004969#endif
Jacob Kellere5776622014-04-05 02:35:52 +00004970
John Fastabend9da712d2011-08-23 03:14:22 +00004971 /* Calculate delay value for device */
4972 switch (hw->mac.type) {
4973 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004974 case ixgbe_mac_X550:
4975 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004976 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00004977 dv_id = IXGBE_DV_X540(link, tc);
4978 break;
4979 default:
4980 dv_id = IXGBE_DV(link, tc);
4981 break;
4982 }
4983
4984 /* Loopback switch introduces additional latency */
4985 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4986 dv_id += IXGBE_B2BT(tc);
4987
4988 /* Delay value is calculated in bit times convert to KB */
4989 kb = IXGBE_BT2KB(dv_id);
4990 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
4991
4992 marker = rx_pba - kb;
4993
4994 /* It is possible that the packet buffer is not large enough
4995 * to provide required headroom. In this case throw an error
4996 * to user and a do the best we can.
4997 */
4998 if (marker < 0) {
4999 e_warn(drv, "Packet Buffer(%i) can not provide enough"
5000 "headroom to support flow control."
5001 "Decrease MTU or number of traffic classes\n", pb);
5002 marker = tc + 1;
5003 }
5004
5005 return marker;
5006}
5007
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005008/**
John Fastabend9da712d2011-08-23 03:14:22 +00005009 * ixgbe_lpbthresh - calculate low water mark for for flow control
5010 *
5011 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005012 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00005013 */
Jacob Kellere5776622014-04-05 02:35:52 +00005014static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
John Fastabend9da712d2011-08-23 03:14:22 +00005015{
5016 struct ixgbe_hw *hw = &adapter->hw;
5017 struct net_device *dev = adapter->netdev;
5018 int tc;
5019 u32 dv_id;
5020
5021 /* Calculate max LAN frame size */
5022 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
5023
Jacob Kellere5776622014-04-05 02:35:52 +00005024#ifdef IXGBE_FCOE
5025 /* FCoE traffic class uses FCOE jumbo frames */
5026 if ((dev->features & NETIF_F_FCOE_MTU) &&
5027 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
5028 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
5029 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
5030#endif
5031
John Fastabend9da712d2011-08-23 03:14:22 +00005032 /* Calculate delay value for device */
5033 switch (hw->mac.type) {
5034 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005035 case ixgbe_mac_X550:
5036 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005037 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00005038 dv_id = IXGBE_LOW_DV_X540(tc);
5039 break;
5040 default:
5041 dv_id = IXGBE_LOW_DV(tc);
5042 break;
5043 }
5044
5045 /* Delay value is calculated in bit times convert to KB */
5046 return IXGBE_BT2KB(dv_id);
5047}
5048
5049/*
5050 * ixgbe_pbthresh_setup - calculate and setup high low water marks
5051 */
5052static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
5053{
5054 struct ixgbe_hw *hw = &adapter->hw;
5055 int num_tc = netdev_get_num_tc(adapter->netdev);
5056 int i;
5057
5058 if (!num_tc)
5059 num_tc = 1;
5060
John Fastabend9da712d2011-08-23 03:14:22 +00005061 for (i = 0; i < num_tc; i++) {
5062 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
Jacob Kellere5776622014-04-05 02:35:52 +00005063 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
John Fastabend9da712d2011-08-23 03:14:22 +00005064
5065 /* Low water marks must not be larger than high water marks */
Jacob Kellere5776622014-04-05 02:35:52 +00005066 if (hw->fc.low_water[i] > hw->fc.high_water[i])
5067 hw->fc.low_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00005068 }
Jacob Kellere5776622014-04-05 02:35:52 +00005069
5070 for (; i < MAX_TRAFFIC_CLASS; i++)
5071 hw->fc.high_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00005072}
John Fastabend80605c652011-05-02 12:34:10 +00005073
5074static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
5075{
John Fastabend80605c652011-05-02 12:34:10 +00005076 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00005077 int hdrm;
5078 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00005079
5080 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5081 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00005082 hdrm = 32 << adapter->fdir_pballoc;
5083 else
5084 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00005085
Alexander Duyckf7e10272011-07-21 00:40:35 +00005086 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00005087 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00005088}
5089
Alexander Duycke4911d52011-05-11 07:18:52 +00005090static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
5091{
5092 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08005093 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005094 struct ixgbe_fdir_filter *filter;
5095
5096 spin_lock(&adapter->fdir_perfect_lock);
5097
5098 if (!hlist_empty(&adapter->fdir_filter_list))
5099 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
5100
Sasha Levinb67bfe02013-02-27 17:06:00 -08005101 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005102 &adapter->fdir_filter_list, fdir_node) {
5103 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00005104 &filter->filter,
5105 filter->sw_idx,
5106 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
5107 IXGBE_FDIR_DROP_QUEUE :
5108 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00005109 }
5110
5111 spin_unlock(&adapter->fdir_perfect_lock);
5112}
5113
John Fastabend2a47fa42013-11-06 09:54:52 -08005114static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
5115 struct ixgbe_adapter *adapter)
5116{
5117 struct ixgbe_hw *hw = &adapter->hw;
5118 u32 vmolr;
5119
5120 /* No unicast promiscuous support for VMDQ devices. */
5121 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
5122 vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
5123
5124 /* clear the affected bit */
5125 vmolr &= ~IXGBE_VMOLR_MPE;
5126
5127 if (dev->flags & IFF_ALLMULTI) {
5128 vmolr |= IXGBE_VMOLR_MPE;
5129 } else {
5130 vmolr |= IXGBE_VMOLR_ROMPE;
5131 hw->mac.ops.update_mc_addr_list(hw, dev);
5132 }
Jacob Keller5d7daa32014-03-29 06:51:25 +00005133 ixgbe_write_uc_addr_list(adapter->netdev, pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08005134 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
5135}
5136
John Fastabend2a47fa42013-11-06 09:54:52 -08005137static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
5138{
5139 struct ixgbe_adapter *adapter = vadapter->real_adapter;
John Fastabend219354d2013-11-08 00:50:32 -08005140 int rss_i = adapter->num_rx_queues_per_pool;
John Fastabend2a47fa42013-11-06 09:54:52 -08005141 struct ixgbe_hw *hw = &adapter->hw;
5142 u16 pool = vadapter->pool;
5143 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
5144 IXGBE_PSRTYPE_UDPHDR |
5145 IXGBE_PSRTYPE_IPV4HDR |
5146 IXGBE_PSRTYPE_L2HDR |
5147 IXGBE_PSRTYPE_IPV6HDR;
5148
5149 if (hw->mac.type == ixgbe_mac_82598EB)
5150 return;
5151
5152 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07005153 psrtype |= 2u << 29;
John Fastabend2a47fa42013-11-06 09:54:52 -08005154 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07005155 psrtype |= 1u << 29;
John Fastabend2a47fa42013-11-06 09:54:52 -08005156
5157 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
5158}
5159
5160/**
5161 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
5162 * @rx_ring: ring to free buffers from
5163 **/
5164static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
5165{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005166 u16 i = rx_ring->next_to_clean;
5167 struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
John Fastabend2a47fa42013-11-06 09:54:52 -08005168
5169 /* Free all the Rx ring sk_buffs */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005170 while (i != rx_ring->next_to_alloc) {
John Fastabend2a47fa42013-11-06 09:54:52 -08005171 if (rx_buffer->skb) {
5172 struct sk_buff *skb = rx_buffer->skb;
Alexander Duyck18cb6522014-11-14 00:56:29 +00005173 if (IXGBE_CB(skb)->page_released)
Alexander Duyckffed21b2017-01-17 08:37:29 -08005174 dma_unmap_page_attrs(rx_ring->dev,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005175 IXGBE_CB(skb)->dma,
5176 ixgbe_rx_pg_size(rx_ring),
5177 DMA_FROM_DEVICE,
5178 IXGBE_RX_DMA_ATTR);
John Fastabend2a47fa42013-11-06 09:54:52 -08005179 dev_kfree_skb(skb);
5180 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00005181
Alexander Duyckf3213d92017-01-17 08:35:54 -08005182 /* Invalidate cache lines that may have been written to by
5183 * device so that we avoid corrupting memory.
5184 */
5185 dma_sync_single_range_for_cpu(rx_ring->dev,
5186 rx_buffer->dma,
5187 rx_buffer->page_offset,
5188 ixgbe_rx_bufsz(rx_ring),
5189 DMA_FROM_DEVICE);
5190
5191 /* free resources associated with mapping */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005192 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005193 ixgbe_rx_pg_size(rx_ring),
5194 DMA_FROM_DEVICE,
5195 IXGBE_RX_DMA_ATTR);
Alexander Duyck1b56cf42017-01-17 08:36:03 -08005196 __page_frag_cache_drain(rx_buffer->page,
5197 rx_buffer->pagecnt_bias);
Alexander Duyck18cb6522014-11-14 00:56:29 +00005198
Alexander Duyckffed21b2017-01-17 08:37:29 -08005199 i++;
5200 rx_buffer++;
5201 if (i == rx_ring->count) {
5202 i = 0;
5203 rx_buffer = rx_ring->rx_buffer_info;
5204 }
John Fastabend2a47fa42013-11-06 09:54:52 -08005205 }
5206
John Fastabend2a47fa42013-11-06 09:54:52 -08005207 rx_ring->next_to_alloc = 0;
5208 rx_ring->next_to_clean = 0;
5209 rx_ring->next_to_use = 0;
5210}
5211
5212static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
5213 struct ixgbe_ring *rx_ring)
5214{
5215 struct ixgbe_adapter *adapter = vadapter->real_adapter;
5216 int index = rx_ring->queue_index + vadapter->rx_base_queue;
5217
5218 /* shutdown specific queue receive and wait for dma to settle */
5219 ixgbe_disable_rx_queue(adapter, rx_ring);
5220 usleep_range(10000, 20000);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07005221 ixgbe_irq_disable_queues(adapter, BIT_ULL(index));
John Fastabend2a47fa42013-11-06 09:54:52 -08005222 ixgbe_clean_rx_ring(rx_ring);
5223 rx_ring->l2_accel_priv = NULL;
5224}
5225
John Fastabendae72c8d2013-11-09 07:11:26 +00005226static int ixgbe_fwd_ring_down(struct net_device *vdev,
5227 struct ixgbe_fwd_adapter *accel)
John Fastabend2a47fa42013-11-06 09:54:52 -08005228{
5229 struct ixgbe_adapter *adapter = accel->real_adapter;
5230 unsigned int rxbase = accel->rx_base_queue;
5231 unsigned int txbase = accel->tx_base_queue;
5232 int i;
5233
5234 netif_tx_stop_all_queues(vdev);
5235
5236 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5237 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
5238 adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
5239 }
5240
5241 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5242 adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
5243 adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
5244 }
5245
5246
5247 return 0;
5248}
5249
5250static int ixgbe_fwd_ring_up(struct net_device *vdev,
5251 struct ixgbe_fwd_adapter *accel)
5252{
5253 struct ixgbe_adapter *adapter = accel->real_adapter;
5254 unsigned int rxbase, txbase, queues;
5255 int i, baseq, err = 0;
5256
5257 if (!test_bit(accel->pool, &adapter->fwd_bitmask))
5258 return 0;
5259
5260 baseq = accel->pool * adapter->num_rx_queues_per_pool;
5261 netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
5262 accel->pool, adapter->num_rx_pools,
5263 baseq, baseq + adapter->num_rx_queues_per_pool,
5264 adapter->fwd_bitmask);
5265
5266 accel->netdev = vdev;
5267 accel->rx_base_queue = rxbase = baseq;
5268 accel->tx_base_queue = txbase = baseq;
5269
5270 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
5271 ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
5272
5273 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5274 adapter->rx_ring[rxbase + i]->netdev = vdev;
5275 adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
5276 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
5277 }
5278
5279 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
5280 adapter->tx_ring[txbase + i]->netdev = vdev;
5281 adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
5282 }
5283
5284 queues = min_t(unsigned int,
5285 adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
5286 err = netif_set_real_num_tx_queues(vdev, queues);
5287 if (err)
5288 goto fwd_queue_err;
5289
John Fastabend2a47fa42013-11-06 09:54:52 -08005290 err = netif_set_real_num_rx_queues(vdev, queues);
5291 if (err)
5292 goto fwd_queue_err;
5293
5294 if (is_valid_ether_addr(vdev->dev_addr))
5295 ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool);
5296
5297 ixgbe_fwd_psrtype(accel);
5298 ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter);
5299 return err;
5300fwd_queue_err:
5301 ixgbe_fwd_ring_down(vdev, accel);
5302 return err;
5303}
5304
David Ahern1cd127f2016-10-17 19:15:48 -07005305static int ixgbe_upper_dev_walk(struct net_device *upper, void *data)
5306{
5307 if (netif_is_macvlan(upper)) {
5308 struct macvlan_dev *dfwd = netdev_priv(upper);
5309 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
5310
5311 if (dfwd->fwd_priv)
5312 ixgbe_fwd_ring_up(upper, vadapter);
5313 }
5314
5315 return 0;
5316}
5317
John Fastabend2a47fa42013-11-06 09:54:52 -08005318static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
5319{
David Ahern1cd127f2016-10-17 19:15:48 -07005320 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5321 ixgbe_upper_dev_walk, NULL);
John Fastabend2a47fa42013-11-06 09:54:52 -08005322}
5323
Auke Kok9a799d72007-09-15 14:07:45 -07005324static void ixgbe_configure(struct ixgbe_adapter *adapter)
5325{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005326 struct ixgbe_hw *hw = &adapter->hw;
5327
John Fastabend80605c652011-05-02 12:34:10 +00005328 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005329#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00005330 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005331#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00005332 /*
5333 * We must restore virtualization before VLANs or else
5334 * the VLVF registers will not be populated
5335 */
5336 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005337
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005338 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00005339 ixgbe_restore_vlan(adapter);
5340
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005341 switch (hw->mac.type) {
5342 case ixgbe_mac_82599EB:
5343 case ixgbe_mac_X540:
5344 hw->mac.ops.disable_rx_buff(hw);
5345 break;
5346 default:
5347 break;
5348 }
5349
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005350 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005351 ixgbe_init_fdir_signature_82599(&adapter->hw,
5352 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00005353 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
5354 ixgbe_init_fdir_perfect_82599(&adapter->hw,
5355 adapter->fdir_pballoc);
5356 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005357 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005358
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005359 switch (hw->mac.type) {
5360 case ixgbe_mac_82599EB:
5361 case ixgbe_mac_X540:
5362 hw->mac.ops.enable_rx_buff(hw);
5363 break;
5364 default:
5365 break;
5366 }
5367
Mark Rustad9de76052015-08-08 16:27:41 -07005368#ifdef CONFIG_IXGBE_DCA
5369 /* configure DCA */
5370 if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
5371 ixgbe_setup_dca(adapter);
5372#endif /* CONFIG_IXGBE_DCA */
5373
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005374#ifdef IXGBE_FCOE
5375 /* configure FCoE L2 filters, redirection table, and Rx control */
5376 ixgbe_configure_fcoe(adapter);
5377
5378#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005379 ixgbe_configure_tx(adapter);
5380 ixgbe_configure_rx(adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08005381 ixgbe_configure_dfwd(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005382}
5383
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005384/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005385 * ixgbe_sfp_link_config - set up SFP+ link
5386 * @adapter: pointer to private adapter struct
5387 **/
5388static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
5389{
Alexander Duyck70864002011-04-27 09:13:56 +00005390 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005391 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00005392 * is that an SFP was inserted/removed after the reset
5393 * but before SFP detection was enabled. As such the best
5394 * solution is to just start searching as soon as we start
5395 */
5396 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5397 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005398
Alexander Duyck70864002011-04-27 09:13:56 +00005399 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07005400 adapter->sfp_poll_time = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005401}
5402
5403/**
5404 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005405 * @hw: pointer to private hardware struct
5406 *
5407 * Returns 0 on success, negative on failure
5408 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005409static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005410{
Josh Hay3d292262012-12-15 03:28:19 +00005411 u32 speed;
5412 bool autoneg, link_up = false;
Mark Rustada1e869d2015-04-10 10:36:36 -07005413 int ret = IXGBE_ERR_LINK_SETUP;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005414
5415 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00005416 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005417
5418 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005419 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005420
Josh Hay3d292262012-12-15 03:28:19 +00005421 speed = hw->phy.autoneg_advertised;
5422 if ((!speed) && (hw->mac.ops.get_link_capabilities))
5423 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
5424 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005425 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005426 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005427
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00005428 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00005429 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Mark Rustade90dd262014-07-22 06:51:08 +00005430
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005431 return ret;
5432}
5433
Alexander Duycka34bcff2010-08-19 13:39:20 +00005434static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005435{
Auke Kok9a799d72007-09-15 14:07:45 -07005436 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005437 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005438
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005439 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00005440 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
5441 IXGBE_GPIE_OCD;
5442 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005443 /*
5444 * use EIAM to auto-mask when MSI-X interrupt is asserted
5445 * this saves a register write for every interrupt
5446 */
5447 switch (hw->mac.type) {
5448 case ixgbe_mac_82598EB:
5449 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
5450 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005451 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005452 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005453 case ixgbe_mac_X550:
5454 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005455 case ixgbe_mac_x550em_a:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005456 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005457 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5458 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5459 break;
5460 }
5461 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005462 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
5463 * specifically only auto mask tx and rx interrupts */
5464 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07005465 }
5466
Alexander Duycka34bcff2010-08-19 13:39:20 +00005467 /* XXX: to interrupt immediately for EICS writes, enable this */
5468 /* gpie |= IXGBE_GPIE_EIMEN; */
5469
5470 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
5471 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00005472
5473 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
5474 case IXGBE_82599_VMDQ_8Q_MASK:
5475 gpie |= IXGBE_GPIE_VTMODE_16;
5476 break;
5477 case IXGBE_82599_VMDQ_4Q_MASK:
5478 gpie |= IXGBE_GPIE_VTMODE_32;
5479 break;
5480 default:
5481 gpie |= IXGBE_GPIE_VTMODE_64;
5482 break;
5483 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005484 }
5485
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005486 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00005487 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
5488 switch (adapter->hw.mac.type) {
5489 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005490 gpie |= IXGBE_SDP0_GPIEN_8259X;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005491 break;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005492 default:
5493 break;
5494 }
5495 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005496
Alexander Duycka34bcff2010-08-19 13:39:20 +00005497 /* Enable fan failure interrupt */
5498 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07005499 gpie |= IXGBE_SDP1_GPIEN(hw);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07005500
Don Skidmorea023bbd2015-06-24 16:38:53 -04005501 switch (hw->mac.type) {
5502 case ixgbe_mac_82599EB:
5503 gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
5504 break;
5505 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005506 case ixgbe_mac_x550em_a:
Don Skidmorea023bbd2015-06-24 16:38:53 -04005507 gpie |= IXGBE_SDP0_GPIEN_X540;
5508 break;
5509 default:
5510 break;
Don Skidmore2698b202011-04-13 07:01:52 +00005511 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00005512
5513 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
5514}
5515
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005516static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00005517{
5518 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005519 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005520 u32 ctrl_ext;
5521
5522 ixgbe_get_hw_control(adapter);
5523 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005524
Auke Kok9a799d72007-09-15 14:07:45 -07005525 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
5526 ixgbe_configure_msix(adapter);
5527 else
5528 ixgbe_configure_msi_and_legacy(adapter);
5529
Emil Tantilovec74a472012-09-20 03:33:56 +00005530 /* enable the optics for 82599 SFP+ fiber */
5531 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00005532 hw->mac.ops.enable_tx_laser(hw);
5533
Don Skidmore961fac82015-06-09 16:09:47 -07005534 if (hw->phy.ops.set_phy_power)
5535 hw->phy.ops.set_phy_power(hw, true);
5536
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005537 smp_mb__before_atomic();
Auke Kok9a799d72007-09-15 14:07:45 -07005538 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005539 ixgbe_napi_enable_all(adapter);
5540
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08005541 if (ixgbe_is_sfp(hw)) {
5542 ixgbe_sfp_link_config(adapter);
5543 } else {
5544 err = ixgbe_non_sfp_link_config(hw);
5545 if (err)
5546 e_err(probe, "link_config FAILED %d\n", err);
5547 }
5548
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005549 /* clear any pending interrupts, may auto mask */
5550 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00005551 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07005552
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005553 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00005554 * If this adapter has a fan, check to see if we had a failure
5555 * before we enabled the interrupt.
5556 */
5557 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5558 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5559 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00005560 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00005561 }
5562
Auke Kok9a799d72007-09-15 14:07:45 -07005563 /* bring the link up in the watchdog, this could race with our first
5564 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005565 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5566 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00005567 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00005568
5569 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
5570 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
5571 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
5572 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07005573}
5574
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005575void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
5576{
5577 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00005578 /* put off any impending NetWatchDogTimeout */
Florian Westphal860e9532016-05-03 16:33:13 +02005579 netif_trans_update(adapter->netdev);
Alexander Duyck70864002011-04-27 09:13:56 +00005580
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005581 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00005582 usleep_range(1000, 2000);
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005583 if (adapter->hw.phy.type == ixgbe_phy_fw)
5584 ixgbe_watchdog_link_is_down(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005585 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00005586 /*
5587 * If SR-IOV enabled then wait a bit before bringing the adapter
5588 * back up to give the VFs time to respond to the reset. The
5589 * two second wait is based upon the watchdog timer cycle in
5590 * the VF driver.
5591 */
5592 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5593 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005594 ixgbe_up(adapter);
5595 clear_bit(__IXGBE_RESETTING, &adapter->state);
5596}
5597
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005598void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005599{
5600 /* hardware has been reset, we need to reload some things */
5601 ixgbe_configure(adapter);
5602
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005603 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005604}
5605
5606void ixgbe_reset(struct ixgbe_adapter *adapter)
5607{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005608 struct ixgbe_hw *hw = &adapter->hw;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005609 struct net_device *netdev = adapter->netdev;
Don Skidmore8ca783a2009-05-26 20:40:47 -07005610 int err;
5611
Mark Rustadb0483c82014-01-14 18:53:17 -08005612 if (ixgbe_removed(hw->hw_addr))
5613 return;
Alexander Duyck70864002011-04-27 09:13:56 +00005614 /* lock SFP init bit to prevent race conditions with the watchdog */
5615 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5616 usleep_range(1000, 2000);
5617
5618 /* clear all SFP and link config related flags while holding SFP_INIT */
5619 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
5620 IXGBE_FLAG2_SFP_NEEDS_RESET);
5621 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5622
Don Skidmore8ca783a2009-05-26 20:40:47 -07005623 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005624 switch (err) {
5625 case 0:
5626 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00005627 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005628 break;
5629 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00005630 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005631 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005632 case IXGBE_ERR_EEPROM_VERSION:
5633 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00005634 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005635 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00005636 "your hardware. If you are experiencing problems "
5637 "please contact your Intel or hardware "
5638 "representative who provided you with this "
5639 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005640 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005641 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00005642 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005643 }
Auke Kok9a799d72007-09-15 14:07:45 -07005644
Alexander Duyck70864002011-04-27 09:13:56 +00005645 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005646
5647 /* flush entries out of MAC table */
Jacob Keller5d7daa32014-03-29 06:51:25 +00005648 ixgbe_flush_sw_mac_table(adapter);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005649 __dev_uc_unsync(netdev, NULL);
5650
5651 /* do not flush user set addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07005652 ixgbe_mac_set_default_filter(adapter);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00005653
5654 /* update SAN MAC vmdq pool selection */
5655 if (hw->mac.san_mac_rar_index)
5656 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00005657
Jacob Keller8fecf672013-06-21 08:14:32 +00005658 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00005659 ixgbe_ptp_reset(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07005660
5661 if (hw->phy.ops.set_phy_power) {
5662 if (!netif_running(adapter->netdev) && !adapter->wol)
5663 hw->phy.ops.set_phy_power(hw, false);
5664 else
5665 hw->phy.ops.set_phy_power(hw, true);
5666 }
Auke Kok9a799d72007-09-15 14:07:45 -07005667}
5668
Auke Kok9a799d72007-09-15 14:07:45 -07005669/**
Auke Kok9a799d72007-09-15 14:07:45 -07005670 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07005671 * @tx_ring: ring to be cleaned
5672 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005673static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005674{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005675 u16 i = tx_ring->next_to_clean;
5676 struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07005677
Alexander Duyckffed21b2017-01-17 08:37:29 -08005678 while (i != tx_ring->next_to_use) {
5679 union ixgbe_adv_tx_desc *eop_desc, *tx_desc;
Auke Kok9a799d72007-09-15 14:07:45 -07005680
Alexander Duyckffed21b2017-01-17 08:37:29 -08005681 /* Free all the Tx ring sk_buffs */
John Fastabend33fdc822017-04-24 03:30:18 -07005682 if (ring_is_xdp(tx_ring))
5683 page_frag_free(tx_buffer->data);
5684 else
5685 dev_kfree_skb_any(tx_buffer->skb);
Alexander Duyckffed21b2017-01-17 08:37:29 -08005686
5687 /* unmap skb header data */
5688 dma_unmap_single(tx_ring->dev,
5689 dma_unmap_addr(tx_buffer, dma),
5690 dma_unmap_len(tx_buffer, len),
5691 DMA_TO_DEVICE);
5692
5693 /* check for eop_desc to determine the end of the packet */
5694 eop_desc = tx_buffer->next_to_watch;
5695 tx_desc = IXGBE_TX_DESC(tx_ring, i);
5696
5697 /* unmap remaining buffers */
5698 while (tx_desc != eop_desc) {
5699 tx_buffer++;
5700 tx_desc++;
5701 i++;
5702 if (unlikely(i == tx_ring->count)) {
5703 i = 0;
5704 tx_buffer = tx_ring->tx_buffer_info;
5705 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
5706 }
5707
5708 /* unmap any remaining paged data */
5709 if (dma_unmap_len(tx_buffer, len))
5710 dma_unmap_page(tx_ring->dev,
5711 dma_unmap_addr(tx_buffer, dma),
5712 dma_unmap_len(tx_buffer, len),
5713 DMA_TO_DEVICE);
5714 }
5715
5716 /* move us one more past the eop_desc for start of next pkt */
5717 tx_buffer++;
5718 i++;
5719 if (unlikely(i == tx_ring->count)) {
5720 i = 0;
5721 tx_buffer = tx_ring->tx_buffer_info;
5722 }
Auke Kok9a799d72007-09-15 14:07:45 -07005723 }
5724
Alexander Duyckffed21b2017-01-17 08:37:29 -08005725 /* reset BQL for queue */
John Fastabend33fdc822017-04-24 03:30:18 -07005726 if (!ring_is_xdp(tx_ring))
5727 netdev_tx_reset_queue(txring_txq(tx_ring));
John Fastabenddad8a3b2012-04-23 12:22:39 +00005728
Alexander Duyckffed21b2017-01-17 08:37:29 -08005729 /* reset next_to_use and next_to_clean */
Auke Kok9a799d72007-09-15 14:07:45 -07005730 tx_ring->next_to_use = 0;
5731 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005732}
5733
5734/**
Auke Kok9a799d72007-09-15 14:07:45 -07005735 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5736 * @adapter: board private structure
5737 **/
5738static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
5739{
5740 int i;
5741
5742 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005743 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005744}
5745
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005746/**
5747 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5748 * @adapter: board private structure
5749 **/
5750static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
5751{
5752 int i;
5753
5754 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005755 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07005756 for (i = 0; i < adapter->num_xdp_queues; i++)
5757 ixgbe_clean_tx_ring(adapter->xdp_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005758}
5759
Alexander Duycke4911d52011-05-11 07:18:52 +00005760static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
5761{
Sasha Levinb67bfe02013-02-27 17:06:00 -08005762 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005763 struct ixgbe_fdir_filter *filter;
5764
5765 spin_lock(&adapter->fdir_perfect_lock);
5766
Sasha Levinb67bfe02013-02-27 17:06:00 -08005767 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005768 &adapter->fdir_filter_list, fdir_node) {
5769 hlist_del(&filter->fdir_node);
5770 kfree(filter);
5771 }
5772 adapter->fdir_filter_count = 0;
5773
5774 spin_unlock(&adapter->fdir_perfect_lock);
5775}
5776
David Ahern1cd127f2016-10-17 19:15:48 -07005777static int ixgbe_disable_macvlan(struct net_device *upper, void *data)
5778{
5779 if (netif_is_macvlan(upper)) {
5780 struct macvlan_dev *vlan = netdev_priv(upper);
5781
5782 if (vlan->fwd_priv) {
5783 netif_tx_stop_all_queues(upper);
5784 netif_carrier_off(upper);
5785 netif_tx_disable(upper);
5786 }
5787 }
5788
5789 return 0;
5790}
5791
Auke Kok9a799d72007-09-15 14:07:45 -07005792void ixgbe_down(struct ixgbe_adapter *adapter)
5793{
5794 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005795 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005796 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005797
5798 /* signal that we are down to the interrupt handler */
Mark Rustadc3049c82014-01-14 18:53:12 -08005799 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
5800 return; /* do nothing if already down */
Auke Kok9a799d72007-09-15 14:07:45 -07005801
5802 /* disable receives */
Don Skidmore1f9ac572015-03-13 13:54:30 -07005803 hw->mac.ops.disable_rx(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005804
Yi Zou2d39d572011-01-06 14:29:56 +00005805 /* disable all enabled rx queues */
5806 for (i = 0; i < adapter->num_rx_queues; i++)
5807 /* this call also flushes the previous write */
5808 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
5809
Don Skidmore032b4322011-03-18 09:32:53 +00005810 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07005811
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005812 netif_tx_stop_all_queues(netdev);
5813
Alexander Duyck70864002011-04-27 09:13:56 +00005814 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00005815 netif_carrier_off(netdev);
5816 netif_tx_disable(netdev);
5817
John Fastabend2a47fa42013-11-06 09:54:52 -08005818 /* disable any upper devices */
David Ahern1cd127f2016-10-17 19:15:48 -07005819 netdev_walk_all_upper_dev_rcu(adapter->netdev,
5820 ixgbe_disable_macvlan, NULL);
John Fastabend2a47fa42013-11-06 09:54:52 -08005821
John Fastabendc0dfb902010-04-27 02:13:39 +00005822 ixgbe_irq_disable(adapter);
5823
5824 ixgbe_napi_disable_all(adapter);
5825
Emil Tantilov57ca2a42016-07-29 14:46:31 -07005826 clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
5827 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
Alexander Duyck70864002011-04-27 09:13:56 +00005828 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5829
5830 del_timer_sync(&adapter->service_timer);
5831
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005832 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005833 /* Clear EITR Select mapping */
5834 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
5835
5836 /* Mark all the VFs as inactive */
5837 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00005838 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005839
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005840 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07005841 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005842
Auke Kok9a799d72007-09-15 14:07:45 -07005843 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005844 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005845 }
5846
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005847 /* disable transmits in the hardware now that interrupts are off */
5848 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005849 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005850 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005851 }
John Fastabend33fdc822017-04-24 03:30:18 -07005852 for (i = 0; i < adapter->num_xdp_queues; i++) {
5853 u8 reg_idx = adapter->xdp_ring[i]->reg_idx;
5854
5855 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
5856 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005857
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005858 /* Disable the Tx DMA engine on 82599 and later MAC */
Alexander Duyckbd508172010-11-16 19:27:03 -08005859 switch (hw->mac.type) {
5860 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005861 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005862 case ixgbe_mac_X550:
5863 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005864 case ixgbe_mac_x550em_a:
PJ Waskiewicz88512532009-03-13 22:15:10 +00005865 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00005866 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
5867 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08005868 break;
5869 default:
5870 break;
5871 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005872
Paul Larson6f4a0e42008-06-24 17:00:56 -07005873 if (!pci_channel_offline(adapter->pdev))
5874 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00005875
Emil Tantilovec74a472012-09-20 03:33:56 +00005876 /* power down the optics for 82599 SFP+ fiber */
5877 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00005878 hw->mac.ops.disable_tx_laser(hw);
5879
Auke Kok9a799d72007-09-15 14:07:45 -07005880 ixgbe_clean_all_tx_rings(adapter);
5881 ixgbe_clean_all_rx_rings(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005882}
5883
Auke Kok9a799d72007-09-15 14:07:45 -07005884/**
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005885 * ixgbe_eee_capable - helper function to determine EEE support on X550
5886 * @adapter: board private structure
5887 */
5888static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter)
5889{
5890 struct ixgbe_hw *hw = &adapter->hw;
5891
5892 switch (hw->device_id) {
5893 case IXGBE_DEV_ID_X550EM_A_1G_T:
5894 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
5895 if (!hw->phy.eee_speeds_supported)
5896 break;
5897 adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE;
5898 if (!hw->phy.eee_speeds_advertised)
5899 break;
5900 adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
5901 break;
5902 default:
5903 adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE;
5904 adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
5905 break;
5906 }
5907}
5908
5909/**
Auke Kok9a799d72007-09-15 14:07:45 -07005910 * ixgbe_tx_timeout - Respond to a Tx Hang
5911 * @netdev: network interface device structure
5912 **/
5913static void ixgbe_tx_timeout(struct net_device *netdev)
5914{
5915 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5916
5917 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005918 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005919}
5920
Usha Ketineni88290092016-04-26 05:00:26 -07005921#ifdef CONFIG_IXGBE_DCB
5922static void ixgbe_init_dcb(struct ixgbe_adapter *adapter)
5923{
5924 struct ixgbe_hw *hw = &adapter->hw;
5925 struct tc_configuration *tc;
5926 int j;
5927
5928 switch (hw->mac.type) {
5929 case ixgbe_mac_82598EB:
5930 case ixgbe_mac_82599EB:
5931 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5932 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5933 break;
5934 case ixgbe_mac_X540:
5935 case ixgbe_mac_X550:
5936 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5937 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5938 break;
5939 case ixgbe_mac_X550EM_x:
5940 case ixgbe_mac_x550em_a:
5941 default:
5942 adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS;
5943 adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS;
5944 break;
5945 }
5946
5947 /* Configure DCB traffic classes */
5948 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5949 tc = &adapter->dcb_cfg.tc_config[j];
5950 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5951 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5952 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5953 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5954 tc->dcb_pfc = pfc_disabled;
5955 }
5956
5957 /* Initialize default user to priority mapping, UPx->TC0 */
5958 tc = &adapter->dcb_cfg.tc_config[0];
5959 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5960 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5961
5962 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5963 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5964 adapter->dcb_cfg.pfc_mode_enable = false;
5965 adapter->dcb_set_bitmap = 0x00;
5966 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
5967 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
5968 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
5969 sizeof(adapter->temp_dcb_cfg));
5970}
5971#endif
5972
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005973/**
Auke Kok9a799d72007-09-15 14:07:45 -07005974 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5975 * @adapter: board private structure to initialize
5976 *
5977 * ixgbe_sw_init initializes the Adapter private data structure.
5978 * Fields are initialized based on PCI device information and
5979 * OS network device settings (MTU size).
5980 **/
Emil Tantilov55570b62016-10-12 12:34:25 -07005981static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
5982 const struct ixgbe_info *ii)
Auke Kok9a799d72007-09-15 14:07:45 -07005983{
5984 struct ixgbe_hw *hw = &adapter->hw;
5985 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005986 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005987 u32 fwsm;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04005988 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005989
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005990 /* PCI config space info */
5991
5992 hw->vendor_id = pdev->vendor;
5993 hw->device_id = pdev->device;
5994 hw->revision_id = pdev->revision;
5995 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5996 hw->subsystem_device_id = pdev->subsystem_device;
5997
Emil Tantilov55570b62016-10-12 12:34:25 -07005998 /* get_invariants needs the device IDs */
5999 ii->get_invariants(hw);
6000
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006001 /* Set common capability flags and settings */
Don Skidmore0f9b2322014-11-18 09:35:08 +00006002 rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00006003 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006004 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006005 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
6006 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00006007 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
6008 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006009 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
6010#ifdef CONFIG_IXGBE_DCA
6011 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
6012#endif
Usha Ketineni88290092016-04-26 05:00:26 -07006013#ifdef CONFIG_IXGBE_DCB
6014 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
6015 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
6016#endif
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006017#ifdef IXGBE_FCOE
6018 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
6019 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
6020#ifdef CONFIG_IXGBE_DCB
6021 /* Default traffic class to use for FCoE */
6022 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
6023#endif /* CONFIG_IXGBE_DCB */
6024#endif /* IXGBE_FCOE */
6025
John Fastabendb82b17d2016-02-16 21:18:53 -08006026 /* initialize static ixgbe jump table entries */
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04006027 adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]),
6028 GFP_KERNEL);
6029 if (!adapter->jump_tables[0])
6030 return -ENOMEM;
6031 adapter->jump_tables[0]->mat = ixgbe_ipv4_fields;
6032
6033 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++)
6034 adapter->jump_tables[i] = NULL;
John Fastabendb82b17d2016-02-16 21:18:53 -08006035
Jacob Keller5d7daa32014-03-29 06:51:25 +00006036 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
6037 hw->mac.num_rar_entries,
6038 GFP_ATOMIC);
Alexander Duyck530fd822015-11-02 17:09:29 -08006039 if (!adapter->mac_table)
6040 return -ENOMEM;
Jacob Keller5d7daa32014-03-29 06:51:25 +00006041
Tony Nguyen3dfbfc72017-04-13 07:26:05 -07006042 if (ixgbe_init_rss_key(adapter))
6043 return -ENOMEM;
6044
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006045 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08006046 switch (hw->mac.type) {
6047 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006048 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006049
Don Skidmorebf069c92009-05-07 10:39:54 +00006050 if (hw->device_id == IXGBE_DEV_ID_82598AT)
6051 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006052
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006053 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006054 adapter->ring_feature[RING_F_FDIR].limit = 0;
6055 adapter->atr_sample_rate = 0;
6056 adapter->fdir_pballoc = 0;
6057#ifdef IXGBE_FCOE
6058 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
6059 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
6060#ifdef CONFIG_IXGBE_DCB
6061 adapter->fcoe.up = 0;
6062#endif /* IXGBE_DCB */
6063#endif /* IXGBE_FCOE */
6064 break;
6065 case ixgbe_mac_82599EB:
6066 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
6067 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08006068 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006069 case ixgbe_mac_X540:
Don Skidmore9a900ec2015-06-09 17:15:01 -07006070 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
Jacob Kellercb6d0f52012-12-04 06:03:14 +00006071 if (fwsm & IXGBE_FWSM_TS_ENABLED)
6072 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08006073 break;
Mark Rustad49425df2016-04-01 12:18:09 -07006074 case ixgbe_mac_x550em_a:
Emil Tantilova21d0822016-08-10 11:19:23 -07006075 adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006076 switch (hw->device_id) {
6077 case IXGBE_DEV_ID_X550EM_A_1G_T:
6078 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
6079 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
6080 break;
6081 default:
6082 break;
6083 }
Emil Tantilova21d0822016-08-10 11:19:23 -07006084 /* fall through */
6085 case ixgbe_mac_X550EM_x:
Usha Ketineni88290092016-04-26 05:00:26 -07006086#ifdef CONFIG_IXGBE_DCB
6087 adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE;
6088#endif
6089#ifdef IXGBE_FCOE
6090 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
6091#ifdef CONFIG_IXGBE_DCB
6092 adapter->fcoe.up = 0;
6093#endif /* IXGBE_DCB */
6094#endif /* IXGBE_FCOE */
6095 /* Fall Through */
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006096 case ixgbe_mac_X550:
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006097 if (hw->mac.type == ixgbe_mac_X550)
6098 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006099#ifdef CONFIG_IXGBE_DCA
6100 adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
6101#endif
Mark Rustad67359c32015-06-15 11:33:25 -07006102 adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006103 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08006104 default:
6105 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00006106 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08006107
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006108#ifdef IXGBE_FCOE
6109 /* FCoE support exists, always init the FCoE lock */
6110 spin_lock_init(&adapter->fcoe.lock);
6111
6112#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00006113 /* n-tuple support exists, always init our spinlock */
6114 spin_lock_init(&adapter->fdir_perfect_lock);
6115
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08006116#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -07006117 ixgbe_init_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006118#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006119
6120 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00006121 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00006122 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00006123 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07006124 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
6125 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00006126 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07006127
Alexander Duyck99d74482012-05-09 08:09:25 +00006128#ifdef CONFIG_PCI_IOV
Jacob Keller170e8542013-11-09 04:52:32 -08006129 if (max_vfs > 0)
6130 e_dev_warn("Enabling SR-IOV VFs using the max_vfs module parameter is deprecated - please use the pci sysfs interface instead.\n");
Alexander Duyck99d74482012-05-09 08:09:25 +00006131
Jacob Keller170e8542013-11-09 04:52:32 -08006132 /* assign number of SR-IOV VFs */
6133 if (hw->mac.type != ixgbe_mac_82598EB) {
ethan.zhaodcc23e32014-01-16 19:41:04 -08006134 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
Emil Tantilov5c11f002017-01-20 14:11:56 -08006135 max_vfs = 0;
Jacob Keller170e8542013-11-09 04:52:32 -08006136 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
Jacob Keller170e8542013-11-09 04:52:32 -08006137 }
6138 }
6139#endif /* CONFIG_PCI_IOV */
6140
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006141 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00006142 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00006143 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006144
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006145 /* set default ring sizes */
6146 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
6147 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
6148
Alexander Duyckbd198052011-06-11 01:45:08 +00006149 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00006150 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00006151
Auke Kok9a799d72007-09-15 14:07:45 -07006152 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006153 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006154 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006155 return -EIO;
6156 }
6157
John Fastabend2a47fa42013-11-06 09:54:52 -08006158 /* PF holds first pool slot */
6159 set_bit(0, &adapter->fwd_bitmask);
Auke Kok9a799d72007-09-15 14:07:45 -07006160 set_bit(__IXGBE_DOWN, &adapter->state);
6161
6162 return 0;
6163}
6164
6165/**
6166 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006167 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07006168 *
6169 * Return 0 on success, negative on failure
6170 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006171int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006172{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006173 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006174 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00006175 int ring_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07006176 int size;
6177
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006178 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006179
6180 if (tx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006181 ring_node = tx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006182
Alexander Duyckffed21b2017-01-17 08:37:29 -08006183 tx_ring->tx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006184 if (!tx_ring->tx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006185 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006186 if (!tx_ring->tx_buffer_info)
6187 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006188
6189 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08006190 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006191 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006192
Mark Rustadca8dfe22014-07-24 06:19:24 +00006193 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006194 tx_ring->desc = dma_alloc_coherent(dev,
6195 tx_ring->size,
6196 &tx_ring->dma,
6197 GFP_KERNEL);
6198 set_dev_node(dev, orig_node);
6199 if (!tx_ring->desc)
6200 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
6201 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006202 if (!tx_ring->desc)
6203 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006204
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006205 tx_ring->next_to_use = 0;
6206 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006207 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006208
6209err:
6210 vfree(tx_ring->tx_buffer_info);
6211 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006212 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006213 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006214}
6215
6216/**
Alexander Duyck69888672008-09-11 20:05:39 -07006217 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
6218 * @adapter: board private structure
6219 *
6220 * If this function returns with an error, then it's possible one or
6221 * more of the rings is populated (while the rest are not). It is the
6222 * callers duty to clean those orphaned rings.
6223 *
6224 * Return 0 on success, negative on failure
6225 **/
6226static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
6227{
John Fastabend33fdc822017-04-24 03:30:18 -07006228 int i, j = 0, err = 0;
Alexander Duyck69888672008-09-11 20:05:39 -07006229
6230 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006231 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006232 if (!err)
6233 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006234
Emil Tantilov396e7992010-07-01 20:05:12 +00006235 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006236 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07006237 }
John Fastabend33fdc822017-04-24 03:30:18 -07006238 for (j = 0; j < adapter->num_xdp_queues; j++) {
6239 err = ixgbe_setup_tx_resources(adapter->xdp_ring[j]);
6240 if (!err)
6241 continue;
6242
6243 e_err(probe, "Allocation for Tx Queue %u failed\n", j);
6244 goto err_setup_tx;
6245 }
Alexander Duyck69888672008-09-11 20:05:39 -07006246
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006247 return 0;
6248err_setup_tx:
6249 /* rewind the index freeing the rings as we go */
John Fastabend33fdc822017-04-24 03:30:18 -07006250 while (j--)
6251 ixgbe_free_tx_resources(adapter->xdp_ring[j]);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006252 while (i--)
6253 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006254 return err;
6255}
6256
6257/**
Auke Kok9a799d72007-09-15 14:07:45 -07006258 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006259 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07006260 *
6261 * Returns 0 on success, negative on failure
6262 **/
John Fastabend92470802017-04-24 03:30:17 -07006263int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
6264 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006265{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006266 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006267 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00006268 int ring_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006269 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07006270
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006271 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006272
6273 if (rx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006274 ring_node = rx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006275
Alexander Duyckffed21b2017-01-17 08:37:29 -08006276 rx_ring->rx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006277 if (!rx_ring->rx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006278 rx_ring->rx_buffer_info = vmalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006279 if (!rx_ring->rx_buffer_info)
6280 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006281
Auke Kok9a799d72007-09-15 14:07:45 -07006282 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006283 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
6284 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006285
Mark Rustadca8dfe22014-07-24 06:19:24 +00006286 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006287 rx_ring->desc = dma_alloc_coherent(dev,
6288 rx_ring->size,
6289 &rx_ring->dma,
6290 GFP_KERNEL);
6291 set_dev_node(dev, orig_node);
6292 if (!rx_ring->desc)
6293 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
6294 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006295 if (!rx_ring->desc)
6296 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006297
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006298 rx_ring->next_to_clean = 0;
6299 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006300
John Fastabend92470802017-04-24 03:30:17 -07006301 rx_ring->xdp_prog = adapter->xdp_prog;
6302
Auke Kok9a799d72007-09-15 14:07:45 -07006303 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006304err:
6305 vfree(rx_ring->rx_buffer_info);
6306 rx_ring->rx_buffer_info = NULL;
6307 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07006308 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006309}
6310
6311/**
Alexander Duyck69888672008-09-11 20:05:39 -07006312 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
6313 * @adapter: board private structure
6314 *
6315 * If this function returns with an error, then it's possible one or
6316 * more of the rings is populated (while the rest are not). It is the
6317 * callers duty to clean those orphaned rings.
6318 *
6319 * Return 0 on success, negative on failure
6320 **/
Alexander Duyck69888672008-09-11 20:05:39 -07006321static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
6322{
6323 int i, err = 0;
6324
6325 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend92470802017-04-24 03:30:17 -07006326 err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006327 if (!err)
6328 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006329
Emil Tantilov396e7992010-07-01 20:05:12 +00006330 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006331 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07006332 }
6333
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006334#ifdef IXGBE_FCOE
6335 err = ixgbe_setup_fcoe_ddp_resources(adapter);
6336 if (!err)
6337#endif
6338 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006339err_setup_rx:
6340 /* rewind the index freeing the rings as we go */
6341 while (i--)
6342 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006343 return err;
6344}
6345
6346/**
Auke Kok9a799d72007-09-15 14:07:45 -07006347 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07006348 * @tx_ring: Tx descriptor ring for a specific queue
6349 *
6350 * Free all transmit software resources
6351 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006352void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006353{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006354 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006355
6356 vfree(tx_ring->tx_buffer_info);
6357 tx_ring->tx_buffer_info = NULL;
6358
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006359 /* if not set, then don't free */
6360 if (!tx_ring->desc)
6361 return;
6362
6363 dma_free_coherent(tx_ring->dev, tx_ring->size,
6364 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006365
6366 tx_ring->desc = NULL;
6367}
6368
6369/**
6370 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
6371 * @adapter: board private structure
6372 *
6373 * Free all transmit software resources
6374 **/
6375static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
6376{
6377 int i;
6378
6379 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006380 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006381 ixgbe_free_tx_resources(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07006382 for (i = 0; i < adapter->num_xdp_queues; i++)
6383 if (adapter->xdp_ring[i]->desc)
6384 ixgbe_free_tx_resources(adapter->xdp_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006385}
6386
6387/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006388 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07006389 * @rx_ring: ring to clean the resources from
6390 *
6391 * Free all receive software resources
6392 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006393void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006394{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006395 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006396
John Fastabend92470802017-04-24 03:30:17 -07006397 rx_ring->xdp_prog = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07006398 vfree(rx_ring->rx_buffer_info);
6399 rx_ring->rx_buffer_info = NULL;
6400
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006401 /* if not set, then don't free */
6402 if (!rx_ring->desc)
6403 return;
6404
6405 dma_free_coherent(rx_ring->dev, rx_ring->size,
6406 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006407
6408 rx_ring->desc = NULL;
6409}
6410
6411/**
6412 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
6413 * @adapter: board private structure
6414 *
6415 * Free all receive software resources
6416 **/
6417static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
6418{
6419 int i;
6420
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006421#ifdef IXGBE_FCOE
6422 ixgbe_free_fcoe_ddp_resources(adapter);
6423
6424#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006425 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006426 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006427 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006428}
6429
6430/**
Auke Kok9a799d72007-09-15 14:07:45 -07006431 * ixgbe_change_mtu - Change the Maximum Transfer Unit
6432 * @netdev: network interface device structure
6433 * @new_mtu: new value for maximum frame size
6434 *
6435 * Returns 0 on success, negative on failure
6436 **/
6437static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
6438{
6439 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck655309e2012-02-08 07:50:35 +00006440
6441 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00006442 * For 82599EB we cannot allow legacy VFs to enable their receive
6443 * paths when MTU greater than 1500 is configured. So display a
6444 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00006445 */
6446 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
6447 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Jarod Wilson91c527a2016-10-17 15:54:05 -04006448 (new_mtu > ETH_DATA_LEN))
Alexander Duyck872844d2012-08-15 02:10:43 +00006449 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006450
Emil Tantilov396e7992010-07-01 20:05:12 +00006451 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00006452
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006453 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07006454 netdev->mtu = new_mtu;
6455
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08006456 if (netif_running(netdev))
6457 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006458
6459 return 0;
6460}
6461
6462/**
6463 * ixgbe_open - Called when a network interface is made active
6464 * @netdev: network interface device structure
6465 *
6466 * Returns 0 on success, negative value on failure
6467 *
6468 * The open entry point is called when a network interface is made
6469 * active by the system (IFF_UP). At this point all resources needed
6470 * for transmit and receive operations are allocated, the interrupt
6471 * handler is registered with the OS, the watchdog timer is started,
6472 * and the stack is notified that the interface is ready.
6473 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006474int ixgbe_open(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006475{
6476 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Don Skidmore961fac82015-06-09 16:09:47 -07006477 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08006478 int err, queues;
Auke Kok9a799d72007-09-15 14:07:45 -07006479
Auke Kok4bebfaa2008-02-11 09:26:01 -08006480 /* disallow open during test */
6481 if (test_bit(__IXGBE_TESTING, &adapter->state))
6482 return -EBUSY;
6483
Jesse Brandeburg54386462009-04-17 20:44:27 +00006484 netif_carrier_off(netdev);
6485
Auke Kok9a799d72007-09-15 14:07:45 -07006486 /* allocate transmit descriptors */
6487 err = ixgbe_setup_all_tx_resources(adapter);
6488 if (err)
6489 goto err_setup_tx;
6490
Auke Kok9a799d72007-09-15 14:07:45 -07006491 /* allocate receive descriptors */
6492 err = ixgbe_setup_all_rx_resources(adapter);
6493 if (err)
6494 goto err_setup_rx;
6495
6496 ixgbe_configure(adapter);
6497
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006498 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006499 if (err)
6500 goto err_req_irq;
6501
Alexander Duyckac802f52012-07-12 05:52:53 +00006502 /* Notify the stack of the actual queue counts. */
John Fastabend2a47fa42013-11-06 09:54:52 -08006503 if (adapter->num_rx_pools > 1)
6504 queues = adapter->num_rx_queues_per_pool;
6505 else
6506 queues = adapter->num_tx_queues;
6507
6508 err = netif_set_real_num_tx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006509 if (err)
6510 goto err_set_queues;
6511
John Fastabend2a47fa42013-11-06 09:54:52 -08006512 if (adapter->num_rx_pools > 1 &&
6513 adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
6514 queues = IXGBE_MAX_L2A_QUEUES;
6515 else
6516 queues = adapter->num_rx_queues;
6517 err = netif_set_real_num_rx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006518 if (err)
6519 goto err_set_queues;
6520
Jacob Keller1a71ab22012-08-25 03:54:19 +00006521 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006522
Alexander Duyckc7ccde02011-07-21 00:40:40 +00006523 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006524
Emil Tantilova21d0822016-08-10 11:19:23 -07006525 ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK);
Alexander Duyckb3a49552016-06-16 12:22:19 -07006526 udp_tunnel_get_rx_info(netdev);
Mark Rustad67359c32015-06-15 11:33:25 -07006527
Auke Kok9a799d72007-09-15 14:07:45 -07006528 return 0;
6529
Alexander Duyckac802f52012-07-12 05:52:53 +00006530err_set_queues:
6531 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006532err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006533 ixgbe_free_all_rx_resources(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07006534 if (hw->phy.ops.set_phy_power && !adapter->wol)
6535 hw->phy.ops.set_phy_power(&adapter->hw, false);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006536err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006537 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006538err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07006539 ixgbe_reset(adapter);
6540
6541 return err;
6542}
6543
Jacob Kellera0cccce2014-05-16 05:12:29 +00006544static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
6545{
6546 ixgbe_ptp_suspend(adapter);
6547
Don Skidmore6ac74392015-06-17 17:34:31 -04006548 if (adapter->hw.phy.ops.enter_lplu) {
6549 adapter->hw.phy.reset_disable = true;
6550 ixgbe_down(adapter);
6551 adapter->hw.phy.ops.enter_lplu(&adapter->hw);
6552 adapter->hw.phy.reset_disable = false;
6553 } else {
6554 ixgbe_down(adapter);
6555 }
6556
Jacob Kellera0cccce2014-05-16 05:12:29 +00006557 ixgbe_free_irq(adapter);
6558
6559 ixgbe_free_all_tx_resources(adapter);
6560 ixgbe_free_all_rx_resources(adapter);
6561}
6562
Auke Kok9a799d72007-09-15 14:07:45 -07006563/**
6564 * ixgbe_close - Disables a network interface
6565 * @netdev: network interface device structure
6566 *
6567 * Returns 0, this is not allowed to fail
6568 *
6569 * The close entry point is called when an interface is de-activated
6570 * by the OS. The hardware is still under the drivers control, but
6571 * needs to be disabled. A global MAC reset is issued to stop the
6572 * hardware, and all transmit and receive resources are freed.
6573 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006574int ixgbe_close(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006575{
6576 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006577
Jacob Keller1a71ab22012-08-25 03:54:19 +00006578 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006579
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006580 if (netif_device_present(netdev))
6581 ixgbe_close_suspend(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006582
Alexander Duycke4911d52011-05-11 07:18:52 +00006583 ixgbe_fdir_filter_exit(adapter);
6584
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08006585 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006586
6587 return 0;
6588}
6589
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006590#ifdef CONFIG_PM
6591static int ixgbe_resume(struct pci_dev *pdev)
6592{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006593 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6594 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006595 u32 err;
6596
Mark Rustad0391bbe2014-02-28 15:48:55 -08006597 adapter->hw.hw_addr = adapter->io_addr;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006598 pci_set_power_state(pdev, PCI_D0);
6599 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08006600 /*
6601 * pci_restore_state clears dev->state_saved so call
6602 * pci_save_state to restore it.
6603 */
6604 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00006605
6606 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006607 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006608 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006609 return err;
6610 }
Peter Zijlstra4e857c52014-03-17 18:06:10 +01006611 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00006612 clear_bit(__IXGBE_DISABLED, &adapter->state);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006613 pci_set_master(pdev);
6614
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006615 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006616
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006617 ixgbe_reset(adapter);
6618
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00006619 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
6620
Alexander Duyckac802f52012-07-12 05:52:53 +00006621 rtnl_lock();
6622 err = ixgbe_init_interrupt_scheme(adapter);
6623 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006624 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006625
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006626
6627 if (!err)
6628 netif_device_attach(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006629 rtnl_unlock();
6630
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006631 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006632}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006633#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006634
6635static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006636{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006637 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6638 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006639 struct ixgbe_hw *hw = &adapter->hw;
6640 u32 ctrl, fctrl;
6641 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006642#ifdef CONFIG_PM
6643 int retval = 0;
6644#endif
6645
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006646 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006647 netif_device_detach(netdev);
6648
Jacob Kellera0cccce2014-05-16 05:12:29 +00006649 if (netif_running(netdev))
6650 ixgbe_close_suspend(adapter);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006651
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006652 ixgbe_clear_interrupt_scheme(adapter);
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006653 rtnl_unlock();
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006654
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006655#ifdef CONFIG_PM
6656 retval = pci_save_state(pdev);
6657 if (retval)
6658 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00006659
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006660#endif
Jacob Kellerf4f10402013-06-25 07:59:23 +00006661 if (hw->mac.ops.stop_link_on_d3)
6662 hw->mac.ops.stop_link_on_d3(hw);
6663
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006664 if (wufc) {
6665 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006666
Emil Tantilovec74a472012-09-20 03:33:56 +00006667 /* enable the optics for 82599 SFP+ fiber as we can WoL */
6668 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00006669 hw->mac.ops.enable_tx_laser(hw);
6670
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006671 /* turn on all-multi mode if wake on multicast is enabled */
6672 if (wufc & IXGBE_WUFC_MC) {
6673 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6674 fctrl |= IXGBE_FCTRL_MPE;
6675 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
6676 }
6677
6678 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
6679 ctrl |= IXGBE_CTRL_GIO_DIS;
6680 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
6681
6682 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
6683 } else {
6684 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
6685 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
6686 }
6687
Alexander Duyckbd508172010-11-16 19:27:03 -08006688 switch (hw->mac.type) {
6689 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006690 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08006691 break;
6692 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006693 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006694 case ixgbe_mac_X550:
6695 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006696 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006697 pci_wake_from_d3(pdev, !!wufc);
6698 break;
6699 default:
6700 break;
6701 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006702
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006703 *enable_wake = !!wufc;
Don Skidmore961fac82015-06-09 16:09:47 -07006704 if (hw->phy.ops.set_phy_power && !*enable_wake)
6705 hw->phy.ops.set_phy_power(hw, false);
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006706
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006707 ixgbe_release_hw_control(adapter);
6708
Mark Rustad41c62842014-03-12 00:38:35 +00006709 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
6710 pci_disable_device(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006711
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006712 return 0;
6713}
6714
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006715#ifdef CONFIG_PM
6716static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
6717{
6718 int retval;
6719 bool wake;
6720
6721 retval = __ixgbe_shutdown(pdev, &wake);
6722 if (retval)
6723 return retval;
6724
6725 if (wake) {
6726 pci_prepare_to_sleep(pdev);
6727 } else {
6728 pci_wake_from_d3(pdev, false);
6729 pci_set_power_state(pdev, PCI_D3hot);
6730 }
6731
6732 return 0;
6733}
6734#endif /* CONFIG_PM */
6735
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006736static void ixgbe_shutdown(struct pci_dev *pdev)
6737{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006738 bool wake;
6739
6740 __ixgbe_shutdown(pdev, &wake);
6741
6742 if (system_state == SYSTEM_POWER_OFF) {
6743 pci_wake_from_d3(pdev, wake);
6744 pci_set_power_state(pdev, PCI_D3hot);
6745 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006746}
6747
6748/**
Auke Kok9a799d72007-09-15 14:07:45 -07006749 * ixgbe_update_stats - Update the board statistics counters.
6750 * @adapter: board private structure
6751 **/
6752void ixgbe_update_stats(struct ixgbe_adapter *adapter)
6753{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006754 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07006755 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006756 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006757 u64 total_mpc = 0;
6758 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006759 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
6760 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006761 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006762
Don Skidmored08935c2010-06-11 13:20:29 +00006763 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6764 test_bit(__IXGBE_RESETTING, &adapter->state))
6765 return;
6766
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006767 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00006768 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006769 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006770 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006771 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
6772 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006773 }
6774 adapter->rsc_total_count = rsc_count;
6775 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00006776 }
6777
Alexander Duyck5b7da512010-11-16 19:26:50 -08006778 for (i = 0; i < adapter->num_rx_queues; i++) {
6779 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
6780 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
6781 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
6782 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006783 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006784 bytes += rx_ring->stats.bytes;
6785 packets += rx_ring->stats.packets;
6786 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00006787 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006788 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
6789 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006790 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006791 netdev->stats.rx_bytes = bytes;
6792 netdev->stats.rx_packets = packets;
6793
6794 bytes = 0;
6795 packets = 0;
6796 /* gather some stats to the adapter struct that are per queue */
6797 for (i = 0; i < adapter->num_tx_queues; i++) {
6798 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6799 restart_queue += tx_ring->tx_stats.restart_queue;
6800 tx_busy += tx_ring->tx_stats.tx_busy;
6801 bytes += tx_ring->stats.bytes;
6802 packets += tx_ring->stats.packets;
6803 }
John Fastabend33fdc822017-04-24 03:30:18 -07006804 for (i = 0; i < adapter->num_xdp_queues; i++) {
6805 struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i];
6806
6807 restart_queue += xdp_ring->tx_stats.restart_queue;
6808 tx_busy += xdp_ring->tx_stats.tx_busy;
6809 bytes += xdp_ring->stats.bytes;
6810 packets += xdp_ring->stats.packets;
6811 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08006812 adapter->restart_queue = restart_queue;
6813 adapter->tx_busy = tx_busy;
6814 netdev->stats.tx_bytes = bytes;
6815 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00006816
Joe Perches7ca647b2010-09-07 21:35:40 +00006817 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006818
6819 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006820 for (i = 0; i < 8; i++) {
6821 /* for packet buffers not used, the register should read 0 */
6822 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
6823 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00006824 hwstats->mpc[i] += mpc;
6825 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006826 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
6827 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006828 switch (hw->mac.type) {
6829 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006830 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
6831 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
6832 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006833 hwstats->pxonrxc[i] +=
6834 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006835 break;
6836 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006837 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006838 case ixgbe_mac_X550:
6839 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006840 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006841 hwstats->pxonrxc[i] +=
6842 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006843 break;
6844 default:
6845 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006846 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006847 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006848
6849 /*16 register reads */
6850 for (i = 0; i < 16; i++) {
6851 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
6852 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
6853 if ((hw->mac.type == ixgbe_mac_82599EB) ||
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006854 (hw->mac.type == ixgbe_mac_X540) ||
6855 (hw->mac.type == ixgbe_mac_X550) ||
Mark Rustad49425df2016-04-01 12:18:09 -07006856 (hw->mac.type == ixgbe_mac_X550EM_x) ||
6857 (hw->mac.type == ixgbe_mac_x550em_a)) {
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006858 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
6859 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
6860 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
6861 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
6862 }
6863 }
6864
Joe Perches7ca647b2010-09-07 21:35:40 +00006865 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006866 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00006867 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07006868
John Fastabendc84d3242010-11-16 19:27:12 -08006869 ixgbe_update_xoff_received(adapter);
6870
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006871 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08006872 switch (hw->mac.type) {
6873 case ixgbe_mac_82598EB:
6874 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08006875 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
6876 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
6877 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
6878 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006879 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006880 case ixgbe_mac_X550:
6881 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006882 case ixgbe_mac_x550em_a:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006883 /* OS2BMC stats are X540 and later */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00006884 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
6885 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
6886 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
6887 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
6888 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00006889 for (i = 0; i < 16; i++)
6890 adapter->hw_rx_no_dma_resources +=
6891 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006892 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006893 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006894 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006895 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006896 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006897 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006898 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00006899 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
6900 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00006901#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00006902 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
6903 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
6904 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
6905 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
6906 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
6907 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00006908 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006909 if (adapter->fcoe.ddp_pool) {
6910 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
6911 struct ixgbe_fcoe_ddp_pool *ddp_pool;
6912 unsigned int cpu;
6913 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006914 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006915 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
6916 noddp += ddp_pool->noddp;
6917 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006918 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006919 hwstats->fcoe_noddp = noddp;
6920 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006921 }
Yi Zou6d455222009-05-13 13:12:16 +00006922#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08006923 break;
6924 default:
6925 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006926 }
Auke Kok9a799d72007-09-15 14:07:45 -07006927 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006928 hwstats->bprc += bprc;
6929 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006930 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00006931 hwstats->mprc -= bprc;
6932 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
6933 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
6934 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
6935 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
6936 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
6937 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
6938 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
6939 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006940 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006941 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006942 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006943 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006944 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
6945 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006946 /*
6947 * 82598 errata - tx of flow control packets is included in tx counters
6948 */
6949 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006950 hwstats->gptc -= xon_off_tot;
6951 hwstats->mptc -= xon_off_tot;
6952 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
6953 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
6954 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
6955 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
6956 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
6957 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
6958 hwstats->ptc64 -= xon_off_tot;
6959 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
6960 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
6961 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
6962 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
6963 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
6964 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07006965
6966 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00006967 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07006968
6969 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00006970 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006971 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006972 netdev->stats.rx_length_errors = hwstats->rlec;
6973 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006974 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07006975}
6976
6977/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00006978 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006979 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07006980 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00006981static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07006982{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006983 struct ixgbe_hw *hw = &adapter->hw;
6984 int i;
6985
Alexander Duyckd034acf2011-04-27 09:25:34 +00006986 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
6987 return;
6988
6989 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6990
6991 /* if interface is down do nothing */
6992 if (test_bit(__IXGBE_DOWN, &adapter->state))
6993 return;
6994
6995 /* do nothing if we are not using signature filters */
6996 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6997 return;
6998
6999 adapter->fdir_overflow++;
7000
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007001 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
7002 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08007003 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Jacob Kellere7cf7452014-04-09 06:03:10 +00007004 &(adapter->tx_ring[i]->state));
John Fastabend33fdc822017-04-24 03:30:18 -07007005 for (i = 0; i < adapter->num_xdp_queues; i++)
7006 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
7007 &adapter->xdp_ring[i]->state);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007008 /* re-enable flow director interrupts */
7009 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007010 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00007011 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00007012 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007013 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007014}
7015
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007016/**
7017 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007018 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007019 *
7020 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007021 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007022 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007023 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007024 */
7025static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
7026{
Auke Kok9a799d72007-09-15 14:07:45 -07007027 struct ixgbe_hw *hw = &adapter->hw;
7028 u64 eics = 0;
7029 int i;
7030
Mark Rustad09f40ae2014-01-14 18:53:11 -08007031 /* If we're down, removing or resetting, just bail */
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007032 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007033 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007034 test_bit(__IXGBE_RESETTING, &adapter->state))
7035 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00007036
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007037 /* Force detection of hung controller */
7038 if (netif_carrier_ok(adapter->netdev)) {
7039 for (i = 0; i < adapter->num_tx_queues; i++)
7040 set_check_for_tx_hang(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07007041 for (i = 0; i < adapter->num_xdp_queues; i++)
7042 set_check_for_tx_hang(adapter->xdp_ring[i]);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007043 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00007044
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00007045 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00007046 /*
7047 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00007048 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00007049 * would set *both* EIMS and EICS for any bit in EIAM
7050 */
7051 IXGBE_WRITE_REG(hw, IXGBE_EICS,
7052 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007053 } else {
7054 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00007055 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007056 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00007057 if (qv->rx.ring || qv->tx.ring)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07007058 eics |= BIT_ULL(i);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007059 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00007060 }
7061
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007062 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00007063 ixgbe_irq_rearm_queues(adapter, eics);
Alexander Duyckfe49f042009-06-04 16:00:09 +00007064}
7065
7066/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007067 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007068 * @adapter: pointer to the device adapter structure
7069 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007070 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007071static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007072{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007073 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007074 u32 link_speed = adapter->link_speed;
7075 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00007076 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007077
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007078 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
7079 return;
7080
7081 if (hw->mac.ops.check_link) {
7082 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007083 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007084 /* always assume link is up, if no check link function */
7085 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
7086 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007087 }
Alexander Duyck041441d2012-04-19 17:48:48 +00007088
7089 if (adapter->ixgbe_ieee_pfc)
7090 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
7091
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00007092 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00007093 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00007094 ixgbe_set_rx_drop_en(adapter);
7095 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007096
7097 if (link_up ||
7098 time_after(jiffies, (adapter->link_check_timeout +
7099 IXGBE_TRY_LINK_TIMEOUT))) {
7100 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
7101 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
7102 IXGBE_WRITE_FLUSH(hw);
7103 }
7104
7105 adapter->link_up = link_up;
7106 adapter->link_speed = link_speed;
7107}
7108
Alexander Duyck107d3012012-10-02 00:17:03 +00007109static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
7110{
7111#ifdef CONFIG_IXGBE_DCB
7112 struct net_device *netdev = adapter->netdev;
7113 struct dcb_app app = {
7114 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
7115 .protocol = 0,
7116 };
7117 u8 up = 0;
7118
7119 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
7120 up = dcb_ieee_getapp_mask(netdev, &app);
7121
7122 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
7123#endif
7124}
7125
David Ahern1cd127f2016-10-17 19:15:48 -07007126static int ixgbe_enable_macvlan(struct net_device *upper, void *data)
7127{
7128 if (netif_is_macvlan(upper)) {
7129 struct macvlan_dev *vlan = netdev_priv(upper);
7130
7131 if (vlan->fwd_priv)
7132 netif_tx_wake_all_queues(upper);
7133 }
7134
7135 return 0;
7136}
7137
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007138/**
7139 * ixgbe_watchdog_link_is_up - update netif_carrier status and
7140 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007141 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007142 **/
7143static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
7144{
7145 struct net_device *netdev = adapter->netdev;
7146 struct ixgbe_hw *hw = &adapter->hw;
7147 u32 link_speed = adapter->link_speed;
Mark Rustad454adb02015-07-10 14:19:22 -07007148 const char *speed_str;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007149 bool flow_rx, flow_tx;
7150
7151 /* only continue if link was previously down */
7152 if (netif_carrier_ok(netdev))
7153 return;
7154
7155 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
7156
7157 switch (hw->mac.type) {
7158 case ixgbe_mac_82598EB: {
7159 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
7160 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
7161 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
7162 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
7163 }
7164 break;
7165 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007166 case ixgbe_mac_X550:
7167 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07007168 case ixgbe_mac_x550em_a:
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007169 case ixgbe_mac_82599EB: {
7170 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
7171 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
7172 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
7173 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
7174 }
7175 break;
7176 default:
7177 flow_tx = false;
7178 flow_rx = false;
7179 break;
7180 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007181
Jacob Keller6cb562d2012-12-05 07:24:41 +00007182 adapter->last_rx_ptp_check = jiffies;
7183
Jacob Keller8fecf672013-06-21 08:14:32 +00007184 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00007185 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007186
Mark Rustad454adb02015-07-10 14:19:22 -07007187 switch (link_speed) {
7188 case IXGBE_LINK_SPEED_10GB_FULL:
7189 speed_str = "10 Gbps";
7190 break;
7191 case IXGBE_LINK_SPEED_2_5GB_FULL:
7192 speed_str = "2.5 Gbps";
7193 break;
7194 case IXGBE_LINK_SPEED_1GB_FULL:
7195 speed_str = "1 Gbps";
7196 break;
7197 case IXGBE_LINK_SPEED_100_FULL:
7198 speed_str = "100 Mbps";
7199 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08007200 case IXGBE_LINK_SPEED_10_FULL:
7201 speed_str = "10 Mbps";
7202 break;
Mark Rustad454adb02015-07-10 14:19:22 -07007203 default:
7204 speed_str = "unknown speed";
7205 break;
7206 }
7207 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007208 ((flow_rx && flow_tx) ? "RX/TX" :
7209 (flow_rx ? "RX" :
7210 (flow_tx ? "TX" : "None"))));
7211
7212 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007213 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007214
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00007215 /* enable transmits */
7216 netif_tx_wake_all_queues(adapter->netdev);
7217
7218 /* enable any upper devices */
7219 rtnl_lock();
David Ahern1cd127f2016-10-17 19:15:48 -07007220 netdev_walk_all_upper_dev_rcu(adapter->netdev,
7221 ixgbe_enable_macvlan, NULL);
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00007222 rtnl_unlock();
7223
Alexander Duyck107d3012012-10-02 00:17:03 +00007224 /* update the default user priority for VFs */
7225 ixgbe_update_default_up(adapter);
7226
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007227 /* ping all the active vfs to let them know link has changed */
7228 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007229}
7230
7231/**
7232 * ixgbe_watchdog_link_is_down - update netif_carrier status and
7233 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007234 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007235 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00007236static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007237{
7238 struct net_device *netdev = adapter->netdev;
7239 struct ixgbe_hw *hw = &adapter->hw;
7240
7241 adapter->link_up = false;
7242 adapter->link_speed = 0;
7243
7244 /* only continue if link was up previously */
7245 if (!netif_carrier_ok(netdev))
7246 return;
7247
7248 /* poll for SFP+ cable when link is down */
7249 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
7250 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
7251
Jacob Keller8fecf672013-06-21 08:14:32 +00007252 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00007253 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007254
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007255 e_info(drv, "NIC Link is Down\n");
7256 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007257
7258 /* ping all the active vfs to let them know link has changed */
7259 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007260}
7261
Emil Tantilov07923c12014-08-12 07:12:08 +00007262static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
7263{
7264 int i;
7265
7266 for (i = 0; i < adapter->num_tx_queues; i++) {
7267 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
7268
7269 if (tx_ring->next_to_use != tx_ring->next_to_clean)
7270 return true;
7271 }
7272
John Fastabend33fdc822017-04-24 03:30:18 -07007273 for (i = 0; i < adapter->num_xdp_queues; i++) {
7274 struct ixgbe_ring *ring = adapter->xdp_ring[i];
7275
7276 if (ring->next_to_use != ring->next_to_clean)
7277 return true;
7278 }
7279
Emil Tantilov07923c12014-08-12 07:12:08 +00007280 return false;
7281}
7282
7283static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
7284{
7285 struct ixgbe_hw *hw = &adapter->hw;
7286 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
7287 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
7288
7289 int i, j;
7290
7291 if (!adapter->num_vfs)
7292 return false;
7293
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007294 /* resetting the PF is only needed for MAC before X550 */
7295 if (hw->mac.type >= ixgbe_mac_X550)
7296 return false;
7297
Emil Tantilov07923c12014-08-12 07:12:08 +00007298 for (i = 0; i < adapter->num_vfs; i++) {
7299 for (j = 0; j < q_per_pool; j++) {
7300 u32 h, t;
7301
7302 h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
7303 t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
7304
7305 if (h != t)
7306 return true;
7307 }
7308 }
7309
7310 return false;
7311}
7312
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007313/**
7314 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007315 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007316 **/
7317static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
7318{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007319 if (!netif_carrier_ok(adapter->netdev)) {
Emil Tantilov07923c12014-08-12 07:12:08 +00007320 if (ixgbe_ring_tx_pending(adapter) ||
7321 ixgbe_vf_tx_pending(adapter)) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007322 /* We've lost link, so the controller stops DMA,
7323 * but we've got queued Tx work that's never going
7324 * to get done, so reset controller to flush Tx.
7325 * (Do the reset outside of interrupt context).
7326 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00007327 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007328 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007329 }
7330 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007331}
7332
Emil Tantilov9079e412014-11-19 03:18:19 +00007333#ifdef CONFIG_PCI_IOV
Emil Tantilov9079e412014-11-19 03:18:19 +00007334static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
7335{
7336 struct ixgbe_hw *hw = &adapter->hw;
7337 struct pci_dev *pdev = adapter->pdev;
Mark Rustad988d1302015-10-30 15:29:34 -07007338 unsigned int vf;
Emil Tantilov9079e412014-11-19 03:18:19 +00007339 u32 gpc;
Emil Tantilov9079e412014-11-19 03:18:19 +00007340
7341 if (!(netif_carrier_ok(adapter->netdev)))
7342 return;
7343
7344 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
7345 if (gpc) /* If incrementing then no need for the check below */
7346 return;
7347 /* Check to see if a bad DMA write target from an errant or
7348 * malicious VF has caused a PCIe error. If so then we can
7349 * issue a VFLR to the offending VF(s) and then resume without
7350 * requesting a full slot reset.
7351 */
7352
7353 if (!pdev)
7354 return;
7355
Emil Tantilov9079e412014-11-19 03:18:19 +00007356 /* check status reg for all VFs owned by this PF */
Mark Rustad988d1302015-10-30 15:29:34 -07007357 for (vf = 0; vf < adapter->num_vfs; ++vf) {
7358 struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
7359 u16 status_reg;
Emil Tantilov9079e412014-11-19 03:18:19 +00007360
Mark Rustad988d1302015-10-30 15:29:34 -07007361 if (!vfdev)
7362 continue;
7363 pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
7364 if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
7365 status_reg & PCI_STATUS_REC_MASTER_ABORT)
Christoph Hellwig63af8f72017-04-14 21:11:28 +02007366 pcie_flr(vfdev);
Emil Tantilov9079e412014-11-19 03:18:19 +00007367 }
7368}
7369
Greg Rosea985b6c32010-11-18 03:02:52 +00007370static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
7371{
7372 u32 ssvpc;
7373
Greg Rose0584d992012-08-08 00:00:58 +00007374 /* Do not perform spoof check for 82598 or if not in IOV mode */
7375 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7376 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00007377 return;
7378
7379 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
7380
7381 /*
7382 * ssvpc register is cleared on read, if zero then no
7383 * spoofed packets in the last interval.
7384 */
7385 if (!ssvpc)
7386 return;
7387
Emil Tantilovd6ea0752012-08-08 06:28:37 +00007388 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00007389}
Emil Tantilov9079e412014-11-19 03:18:19 +00007390#else
7391static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
7392{
7393}
7394
7395static void
7396ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
7397{
7398}
7399#endif /* CONFIG_PCI_IOV */
7400
Greg Rosea985b6c32010-11-18 03:02:52 +00007401
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007402/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007403 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007404 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007405 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007406static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007407{
Mark Rustad09f40ae2014-01-14 18:53:11 -08007408 /* if interface is down, removing or resetting, do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00007409 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007410 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Emil Tantilov7edebf92011-08-27 07:18:37 +00007411 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007412 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007413
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007414 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00007415
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007416 if (adapter->link_up)
7417 ixgbe_watchdog_link_is_up(adapter);
7418 else
7419 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00007420
Emil Tantilov9079e412014-11-19 03:18:19 +00007421 ixgbe_check_for_bad_vf(adapter);
Greg Rosea985b6c32010-11-18 03:02:52 +00007422 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007423 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007424
7425 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007426}
7427
Alexander Duyck70864002011-04-27 09:13:56 +00007428/**
7429 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007430 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007431 **/
7432static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
7433{
7434 struct ixgbe_hw *hw = &adapter->hw;
7435 s32 err;
7436
7437 /* not searching for SFP so there is nothing to do here */
7438 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
7439 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7440 return;
7441
Mark Rustad58e7cd22015-08-08 16:18:48 -07007442 if (adapter->sfp_poll_time &&
7443 time_after(adapter->sfp_poll_time, jiffies))
7444 return; /* If not yet time to poll for SFP */
7445
Alexander Duyck70864002011-04-27 09:13:56 +00007446 /* someone else is in init, wait until next service event */
7447 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7448 return;
7449
Mark Rustad58e7cd22015-08-08 16:18:48 -07007450 adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
7451
Alexander Duyck70864002011-04-27 09:13:56 +00007452 err = hw->phy.ops.identify_sfp(hw);
7453 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7454 goto sfp_out;
7455
7456 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
7457 /* If no cable is present, then we need to reset
7458 * the next time we find a good cable. */
7459 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
7460 }
7461
7462 /* exit on error */
7463 if (err)
7464 goto sfp_out;
7465
7466 /* exit if reset not needed */
7467 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7468 goto sfp_out;
7469
7470 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
7471
7472 /*
7473 * A module may be identified correctly, but the EEPROM may not have
7474 * support for that module. setup_sfp() will fail in that case, so
7475 * we should not allow that module to load.
7476 */
7477 if (hw->mac.type == ixgbe_mac_82598EB)
7478 err = hw->phy.ops.reset(hw);
7479 else
7480 err = hw->mac.ops.setup_sfp(hw);
7481
7482 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7483 goto sfp_out;
7484
7485 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
7486 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
7487
7488sfp_out:
7489 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7490
7491 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
7492 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
7493 e_dev_err("failed to initialize because an unsupported "
7494 "SFP+ module type was detected.\n");
7495 e_dev_err("Reload the driver after installing a "
7496 "supported module.\n");
7497 unregister_netdev(adapter->netdev);
7498 }
7499}
7500
7501/**
7502 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007503 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007504 **/
7505static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
7506{
7507 struct ixgbe_hw *hw = &adapter->hw;
Josh Hay3d292262012-12-15 03:28:19 +00007508 u32 speed;
7509 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00007510
7511 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
7512 return;
7513
7514 /* someone else is in init, wait until next service event */
7515 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7516 return;
7517
7518 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
7519
Josh Hay3d292262012-12-15 03:28:19 +00007520 speed = hw->phy.autoneg_advertised;
Emil Tantiloved33ff62013-08-30 07:55:24 +00007521 if ((!speed) && (hw->mac.ops.get_link_capabilities)) {
Josh Hay3d292262012-12-15 03:28:19 +00007522 hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
Emil Tantiloved33ff62013-08-30 07:55:24 +00007523
7524 /* setup the highest link when no autoneg */
7525 if (!autoneg) {
7526 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
7527 speed = IXGBE_LINK_SPEED_10GB_FULL;
7528 }
7529 }
7530
Alexander Duyck70864002011-04-27 09:13:56 +00007531 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00007532 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00007533
7534 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
7535 adapter->link_check_timeout = jiffies;
7536 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7537}
7538
7539/**
7540 * ixgbe_service_timer - Timer Call-back
7541 * @data: pointer to adapter cast into an unsigned long
7542 **/
7543static void ixgbe_service_timer(unsigned long data)
7544{
7545 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
7546 unsigned long next_event_offset;
7547
7548 /* poll faster when waiting for link */
7549 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
7550 next_event_offset = HZ / 10;
7551 else
7552 next_event_offset = HZ * 2;
7553
7554 /* Reset the timer */
7555 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
7556
Emil Tantilov9079e412014-11-19 03:18:19 +00007557 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007558}
7559
Don Skidmore597f22d2015-06-09 16:52:02 -07007560static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
7561{
7562 struct ixgbe_hw *hw = &adapter->hw;
7563 u32 status;
7564
7565 if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
7566 return;
7567
7568 adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
7569
7570 if (!hw->phy.ops.handle_lasi)
7571 return;
7572
7573 status = hw->phy.ops.handle_lasi(&adapter->hw);
7574 if (status != IXGBE_ERR_OVERTEMP)
7575 return;
7576
7577 e_crit(drv, "%s\n", ixgbe_overheat_msg);
7578}
7579
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007580static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
7581{
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007582 if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state))
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007583 return;
7584
Mark Rustad09f40ae2014-01-14 18:53:11 -08007585 /* If we're already down, removing or resetting, just bail */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007586 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007587 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007588 test_bit(__IXGBE_RESETTING, &adapter->state))
7589 return;
7590
7591 ixgbe_dump(adapter);
7592 netdev_err(adapter->netdev, "Reset adapter\n");
7593 adapter->tx_timeout_count++;
7594
John Fastabend8f4c5c92014-01-16 02:30:05 -08007595 rtnl_lock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007596 ixgbe_reinit_locked(adapter);
John Fastabend8f4c5c92014-01-16 02:30:05 -08007597 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007598}
7599
Alexander Duyck70864002011-04-27 09:13:56 +00007600/**
7601 * ixgbe_service_task - manages and runs subtasks
7602 * @work: pointer to work_struct containing our data
7603 **/
7604static void ixgbe_service_task(struct work_struct *work)
7605{
7606 struct ixgbe_adapter *adapter = container_of(work,
7607 struct ixgbe_adapter,
7608 service_task);
Mark Rustadb0483c82014-01-14 18:53:17 -08007609 if (ixgbe_removed(adapter->hw.hw_addr)) {
7610 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
7611 rtnl_lock();
7612 ixgbe_down(adapter);
7613 rtnl_unlock();
7614 }
7615 ixgbe_service_event_complete(adapter);
7616 return;
7617 }
Emil Tantilova21d0822016-08-10 11:19:23 -07007618 if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) {
Alexander Duyckb3a49552016-06-16 12:22:19 -07007619 rtnl_lock();
Emil Tantilova21d0822016-08-10 11:19:23 -07007620 adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Alexander Duyckb3a49552016-06-16 12:22:19 -07007621 udp_tunnel_get_rx_info(adapter->netdev);
7622 rtnl_unlock();
Mark Rustad67359c32015-06-15 11:33:25 -07007623 }
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007624 ixgbe_reset_subtask(adapter);
Don Skidmore597f22d2015-06-09 16:52:02 -07007625 ixgbe_phy_interrupt_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007626 ixgbe_sfp_detection_subtask(adapter);
7627 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00007628 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007629 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007630 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007631 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007632
Jacob Keller8fecf672013-06-21 08:14:32 +00007633 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
Jacob Keller891dc082012-12-05 07:24:46 +00007634 ixgbe_ptp_overflow_check(adapter);
7635 ixgbe_ptp_rx_hang(adapter);
7636 }
Alexander Duyck70864002011-04-27 09:13:56 +00007637
7638 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007639}
7640
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007641static int ixgbe_tso(struct ixgbe_ring *tx_ring,
7642 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007643 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00007644{
Alexander Duyckb83e3012016-04-14 17:19:31 -04007645 u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007646 struct sk_buff *skb = first->skb;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007647 union {
7648 struct iphdr *v4;
7649 struct ipv6hdr *v6;
7650 unsigned char *hdr;
7651 } ip;
7652 union {
7653 struct tcphdr *tcp;
7654 unsigned char *hdr;
7655 } l4;
7656 u32 paylen, l4_offset;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007657 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007658
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00007659 if (skb->ip_summed != CHECKSUM_PARTIAL)
7660 return 0;
7661
Alexander Duyck897ab152011-05-27 05:31:47 +00007662 if (!skb_is_gso(skb))
7663 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007664
Francois Romieu2049e1f2014-03-30 03:14:27 +00007665 err = skb_cow_head(skb, 0);
7666 if (err < 0)
7667 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00007668
Scott Peterson2a205252016-11-18 11:25:42 -08007669 if (eth_p_mpls(first->protocol))
7670 ip.hdr = skb_inner_network_header(skb);
7671 else
7672 ip.hdr = skb_network_header(skb);
Alexander Duyckb83e3012016-04-14 17:19:31 -04007673 l4.hdr = skb_checksum_start(skb);
7674
Alexander Duyck897ab152011-05-27 05:31:47 +00007675 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
7676 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7677
Alexander Duyckb83e3012016-04-14 17:19:31 -04007678 /* initialize outer IP header fields */
7679 if (ip.v4->version == 4) {
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007680 unsigned char *csum_start = skb_checksum_start(skb);
7681 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
7682
Alexander Duyckb83e3012016-04-14 17:19:31 -04007683 /* IP header will have to cancel out any data that
7684 * is not a part of the outer IP header
7685 */
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007686 ip.v4->check = csum_fold(csum_partial(trans_start,
7687 csum_start - trans_start,
7688 0));
Alexander Duyck897ab152011-05-27 05:31:47 +00007689 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007690
7691 ip.v4->tot_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007692 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7693 IXGBE_TX_FLAGS_CSUM |
7694 IXGBE_TX_FLAGS_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007695 } else {
7696 ip.v6->payload_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007697 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7698 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00007699 }
7700
Alexander Duyckb83e3012016-04-14 17:19:31 -04007701 /* determine offset of inner transport header */
7702 l4_offset = l4.hdr - skb->data;
7703
7704 /* compute length of segmentation header */
7705 *hdr_len = (l4.tcp->doff * 4) + l4_offset;
7706
7707 /* remove payload length from inner checksum */
7708 paylen = skb->len - l4_offset;
7709 csum_replace_by_diff(&l4.tcp->check, htonl(paylen));
Alexander Duyck897ab152011-05-27 05:31:47 +00007710
Alexander Duyck091a6242012-02-08 07:51:01 +00007711 /* update gso size and bytecount with header size */
7712 first->gso_segs = skb_shinfo(skb)->gso_segs;
7713 first->bytecount += (first->gso_segs - 1) * *hdr_len;
7714
Alexander Duyckc44f5f52012-10-30 06:01:45 +00007715 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007716 mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007717 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007718
7719 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007720 vlan_macip_lens = l4.hdr - ip.hdr;
7721 vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007722 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007723
7724 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007725 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00007726
7727 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00007728}
7729
Alexander Duyck49763de2016-01-13 07:31:11 -08007730static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
7731{
7732 unsigned int offset = 0;
7733
7734 ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
7735
7736 return offset == skb_checksum_start_offset(skb);
7737}
7738
Alexander Duyck244e27a2012-02-08 07:51:11 +00007739static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
7740 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07007741{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007742 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00007743 u32 vlan_macip_lens = 0;
Alexander Duyck897ab152011-05-27 05:31:47 +00007744 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007745
Alexander Duyck897ab152011-05-27 05:31:47 +00007746 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck49763de2016-01-13 07:31:11 -08007747csum_failed:
7748 if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
7749 IXGBE_TX_FLAGS_CC)))
Alexander Duyck472148c2012-11-07 02:34:28 +00007750 return;
Alexander Duyck49763de2016-01-13 07:31:11 -08007751 goto no_csum;
Auke Kok9a799d72007-09-15 14:07:45 -07007752 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07007753
Alexander Duyck49763de2016-01-13 07:31:11 -08007754 switch (skb->csum_offset) {
7755 case offsetof(struct tcphdr, check):
7756 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7757 /* fall through */
7758 case offsetof(struct udphdr, check):
7759 break;
7760 case offsetof(struct sctphdr, checksum):
7761 /* validate that this is actually an SCTP request */
7762 if (((first->protocol == htons(ETH_P_IP)) &&
7763 (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
7764 ((first->protocol == htons(ETH_P_IPV6)) &&
7765 ixgbe_ipv6_csum_is_sctp(skb))) {
7766 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
7767 break;
7768 }
7769 /* fall through */
7770 default:
7771 skb_checksum_help(skb);
7772 goto csum_failed;
7773 }
7774
7775 /* update TX checksum flag */
7776 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
7777 vlan_macip_lens = skb_checksum_start_offset(skb) -
7778 skb_network_offset(skb);
Mark Rustad36a92d72015-11-18 09:21:28 -08007779no_csum:
Alexander Duyck244e27a2012-02-08 07:51:11 +00007780 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck49763de2016-01-13 07:31:11 -08007781 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007782 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007783
Alexander Duyck49763de2016-01-13 07:31:11 -08007784 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07007785}
7786
Alexander Duyck472148c2012-11-07 02:34:28 +00007787#define IXGBE_SET_FLAG(_input, _flag, _result) \
7788 ((_flag <= _result) ? \
7789 ((u32)(_input & _flag) * (_result / _flag)) : \
7790 ((u32)(_input & _flag) / (_flag / _result)))
7791
7792static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007793{
7794 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00007795 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
7796 IXGBE_ADVTXD_DCMD_DEXT |
7797 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007798
7799 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00007800 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
7801 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007802
Alexander Duyckd3d00232011-07-15 02:31:25 +00007803 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007804 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
7805 IXGBE_ADVTXD_DCMD_TSE);
7806
7807 /* set timestamp bit if present */
7808 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
7809 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007810
Alexander Duyck62748b72012-07-20 08:09:01 +00007811 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00007812 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00007813
Alexander Duyckd3d00232011-07-15 02:31:25 +00007814 return cmd_type;
7815}
7816
Alexander Duyck729739b2012-02-08 07:51:06 +00007817static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
7818 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007819{
Alexander Duyck472148c2012-11-07 02:34:28 +00007820 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007821
7822 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00007823 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7824 IXGBE_TX_FLAGS_CSUM,
7825 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007826
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00007827 /* enble IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007828 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7829 IXGBE_TX_FLAGS_IPV4,
7830 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007831
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007832 /*
7833 * Check Context must be set if Tx switch is enabled, which it
7834 * always is for case where virtual functions are running
7835 */
Alexander Duyck472148c2012-11-07 02:34:28 +00007836 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7837 IXGBE_TX_FLAGS_CC,
7838 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007839
Alexander Duyck472148c2012-11-07 02:34:28 +00007840 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007841}
7842
Daniel Borkmann2367a172014-08-26 19:34:18 +02007843static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7844{
7845 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
7846
7847 /* Herbert's original patch had:
7848 * smp_mb__after_netif_stop_queue();
7849 * but since that doesn't exist yet, just open code it.
7850 */
7851 smp_mb();
7852
7853 /* We need to check again in a case another CPU has just
7854 * made room available.
7855 */
7856 if (likely(ixgbe_desc_unused(tx_ring) < size))
7857 return -EBUSY;
7858
7859 /* A reprieve! - use start_queue because it doesn't call schedule */
7860 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
7861 ++tx_ring->tx_stats.restart_queue;
7862 return 0;
7863}
7864
7865static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7866{
7867 if (likely(ixgbe_desc_unused(tx_ring) >= size))
7868 return 0;
7869
7870 return __ixgbe_maybe_stop_tx(tx_ring, size);
7871}
7872
Alexander Duyckd3d00232011-07-15 02:31:25 +00007873#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
7874 IXGBE_TXD_CMD_RS)
7875
7876static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007877 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00007878 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07007879{
Alexander Duyck729739b2012-02-08 07:51:06 +00007880 struct sk_buff *skb = first->skb;
7881 struct ixgbe_tx_buffer *tx_buffer;
7882 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00007883 struct skb_frag_struct *frag;
7884 dma_addr_t dma;
7885 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007886 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00007887 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007888 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07007889
Alexander Duyck729739b2012-02-08 07:51:06 +00007890 tx_desc = IXGBE_TX_DESC(tx_ring, i);
7891
Alexander Duyckec718252012-10-30 06:01:55 +00007892 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
7893
7894 size = skb_headlen(skb);
7895 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00007896
Alexander Duyckd3d00232011-07-15 02:31:25 +00007897#ifdef IXGBE_FCOE
7898 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00007899 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007900 size -= sizeof(struct fcoe_crc_eof) - data_len;
7901 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007902 } else {
7903 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00007904 }
Auke Kok9a799d72007-09-15 14:07:45 -07007905 }
7906
Alexander Duyckd3d00232011-07-15 02:31:25 +00007907#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00007908 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007909
Alexander Duyckec718252012-10-30 06:01:55 +00007910 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007911
Alexander Duyckec718252012-10-30 06:01:55 +00007912 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
7913 if (dma_mapping_error(tx_ring->dev, dma))
7914 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007915
Alexander Duyckec718252012-10-30 06:01:55 +00007916 /* record length, and DMA address */
7917 dma_unmap_len_set(tx_buffer, len, size);
7918 dma_unmap_addr_set(tx_buffer, dma, dma);
7919
7920 tx_desc->read.buffer_addr = cpu_to_le64(dma);
7921
Alexander Duyck729739b2012-02-08 07:51:06 +00007922 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007923 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00007924 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007925
Alexander Duyckd3d00232011-07-15 02:31:25 +00007926 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00007927 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007928 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00007929 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007930 i = 0;
7931 }
Alexander Duyckec718252012-10-30 06:01:55 +00007932 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007933
7934 dma += IXGBE_MAX_DATA_PER_TXD;
7935 size -= IXGBE_MAX_DATA_PER_TXD;
7936
7937 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007938 }
7939
Alexander Duyck729739b2012-02-08 07:51:06 +00007940 if (likely(!data_len))
7941 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007942
Alexander Duyck472148c2012-11-07 02:34:28 +00007943 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007944
Alexander Duyck729739b2012-02-08 07:51:06 +00007945 i++;
7946 tx_desc++;
7947 if (i == tx_ring->count) {
7948 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
7949 i = 0;
7950 }
Alexander Duyckec718252012-10-30 06:01:55 +00007951 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007952
Alexander Duyckd3d00232011-07-15 02:31:25 +00007953#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00007954 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00007955#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00007956 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007957#endif
7958 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07007959
Alexander Duyck729739b2012-02-08 07:51:06 +00007960 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
7961 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07007962
Alexander Duyck729739b2012-02-08 07:51:06 +00007963 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07007964 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00007965
Alexander Duyck729739b2012-02-08 07:51:06 +00007966 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00007967 cmd_type |= size | IXGBE_TXD_CMD;
7968 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007969
Alexander Duyck091a6242012-02-08 07:51:01 +00007970 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00007971
Alexander Duyckd3d00232011-07-15 02:31:25 +00007972 /* set the timestamp */
7973 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07007974
7975 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00007976 * Force memory writes to complete before letting h/w know there
7977 * are new descriptors to fetch. (Only applicable for weak-ordered
7978 * memory model archs, such as IA-64).
7979 *
7980 * We also need this memory barrier to make certain all of the
7981 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07007982 */
7983 wmb();
7984
Alexander Duyckd3d00232011-07-15 02:31:25 +00007985 /* set next_to_watch value indicating a packet is present */
7986 first->next_to_watch = tx_desc;
7987
Alexander Duyck729739b2012-02-08 07:51:06 +00007988 i++;
7989 if (i == tx_ring->count)
7990 i = 0;
7991
7992 tx_ring->next_to_use = i;
7993
Daniel Borkmann2367a172014-08-26 19:34:18 +02007994 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
7995
7996 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
Alexander Duyckad435ec2014-11-14 00:56:35 +00007997 writel(i, tx_ring->tail);
7998
7999 /* we need this if more than one processor can write to our tail
8000 * at a time, it synchronizes IO on IA64/Altix systems
8001 */
8002 mmiowb();
Daniel Borkmann9c938cd2014-08-24 15:42:16 +02008003 }
Daniel Borkmann2367a172014-08-26 19:34:18 +02008004
Alexander Duyckd3d00232011-07-15 02:31:25 +00008005 return;
8006dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00008007 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckffed21b2017-01-17 08:37:29 -08008008 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duyckd3d00232011-07-15 02:31:25 +00008009
8010 /* clear dma mappings for failed tx_buffer_info map */
Alexander Duyckffed21b2017-01-17 08:37:29 -08008011 while (tx_buffer != first) {
8012 if (dma_unmap_len(tx_buffer, len))
8013 dma_unmap_page(tx_ring->dev,
8014 dma_unmap_addr(tx_buffer, dma),
8015 dma_unmap_len(tx_buffer, len),
8016 DMA_TO_DEVICE);
8017 dma_unmap_len_set(tx_buffer, len, 0);
8018
8019 if (i--)
8020 i += tx_ring->count;
Alexander Duyck729739b2012-02-08 07:51:06 +00008021 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duyckd3d00232011-07-15 02:31:25 +00008022 }
8023
Alexander Duyckffed21b2017-01-17 08:37:29 -08008024 if (dma_unmap_len(tx_buffer, len))
8025 dma_unmap_single(tx_ring->dev,
8026 dma_unmap_addr(tx_buffer, dma),
8027 dma_unmap_len(tx_buffer, len),
8028 DMA_TO_DEVICE);
8029 dma_unmap_len_set(tx_buffer, len, 0);
8030
8031 dev_kfree_skb_any(first->skb);
8032 first->skb = NULL;
8033
Alexander Duyckd3d00232011-07-15 02:31:25 +00008034 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07008035}
8036
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008037static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00008038 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008039{
Alexander Duyck69830522011-01-06 14:29:58 +00008040 struct ixgbe_q_vector *q_vector = ring->q_vector;
8041 union ixgbe_atr_hash_dword input = { .dword = 0 };
8042 union ixgbe_atr_hash_dword common = { .dword = 0 };
8043 union {
8044 unsigned char *network;
8045 struct iphdr *ipv4;
8046 struct ipv6hdr *ipv6;
8047 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08008048 struct tcphdr *th;
Alexander Duycke2873d42016-01-25 19:39:40 -08008049 unsigned int hlen;
Mark Rustad67359c32015-06-15 11:33:25 -07008050 struct sk_buff *skb;
Alexander Duyck905e4a42011-01-06 14:29:57 +00008051 __be16 vlan_id;
Alexander Duycke2873d42016-01-25 19:39:40 -08008052 int l4_proto;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008053
Alexander Duyck69830522011-01-06 14:29:58 +00008054 /* if ring doesn't have a interrupt vector, cannot perform ATR */
8055 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00008056 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008057
Alexander Duyck69830522011-01-06 14:29:58 +00008058 /* do nothing if sampling is disabled */
8059 if (!ring->atr_sample_rate)
8060 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008061
Alexander Duyck69830522011-01-06 14:29:58 +00008062 ring->atr_count++;
8063
Alexander Duycke2873d42016-01-25 19:39:40 -08008064 /* currently only IPv4/IPv6 with TCP is supported */
8065 if ((first->protocol != htons(ETH_P_IP)) &&
8066 (first->protocol != htons(ETH_P_IPV6)))
8067 return;
8068
Alexander Duyck69830522011-01-06 14:29:58 +00008069 /* snag network header to get L4 type and address */
Mark Rustad67359c32015-06-15 11:33:25 -07008070 skb = first->skb;
8071 hdr.network = skb_network_header(skb);
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008072 if (unlikely(hdr.network <= skb->data))
8073 return;
Alexander Duyck9f12df92016-01-25 19:36:29 -08008074 if (skb->encapsulation &&
8075 first->protocol == htons(ETH_P_IP) &&
Sowmini Varadhan52028822016-10-24 15:36:38 -07008076 hdr.ipv4->protocol == IPPROTO_UDP) {
Mark Rustad67359c32015-06-15 11:33:25 -07008077 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck69830522011-01-06 14:29:58 +00008078
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008079 if (unlikely(skb_tail_pointer(skb) < hdr.network +
8080 VXLAN_HEADROOM))
8081 return;
8082
Alexander Duyck9f12df92016-01-25 19:36:29 -08008083 /* verify the port is recognized as VXLAN */
8084 if (adapter->vxlan_port &&
Alexander Duycke2873d42016-01-25 19:39:40 -08008085 udp_hdr(skb)->dest == adapter->vxlan_port)
Alexander Duyck9f12df92016-01-25 19:36:29 -08008086 hdr.network = skb_inner_network_header(skb);
Emil Tantilova21d0822016-08-10 11:19:23 -07008087
8088 if (adapter->geneve_port &&
8089 udp_hdr(skb)->dest == adapter->geneve_port)
8090 hdr.network = skb_inner_network_header(skb);
Mark Rustade19dcde2015-12-09 14:55:37 -08008091 }
8092
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008093 /* Make sure we have at least [minimum IPv4 header + TCP]
8094 * or [IPv6 header] bytes
8095 */
8096 if (unlikely(skb_tail_pointer(skb) < hdr.network + 40))
8097 return;
8098
Mark Rustade19dcde2015-12-09 14:55:37 -08008099 /* Currently only IPv4/IPv6 with TCP is supported */
8100 switch (hdr.ipv4->version) {
8101 case IPVERSION:
Alexander Duycke2873d42016-01-25 19:39:40 -08008102 /* access ihl as u8 to avoid unaligned access on ia64 */
8103 hlen = (hdr.network[0] & 0x0F) << 2;
8104 l4_proto = hdr.ipv4->protocol;
Mark Rustade19dcde2015-12-09 14:55:37 -08008105 break;
8106 case 6:
Alexander Duycke2873d42016-01-25 19:39:40 -08008107 hlen = hdr.network - skb->data;
8108 l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
8109 hlen -= hdr.network - skb->data;
Mark Rustade19dcde2015-12-09 14:55:37 -08008110 break;
8111 default:
8112 return;
Mark Rustad67359c32015-06-15 11:33:25 -07008113 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008114
Alexander Duycke2873d42016-01-25 19:39:40 -08008115 if (l4_proto != IPPROTO_TCP)
8116 return;
8117
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008118 if (unlikely(skb_tail_pointer(skb) < hdr.network +
8119 hlen + sizeof(struct tcphdr)))
8120 return;
8121
Alexander Duycke2873d42016-01-25 19:39:40 -08008122 th = (struct tcphdr *)(hdr.network + hlen);
8123
8124 /* skip this packet since the socket is closing */
8125 if (th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00008126 return;
8127
8128 /* sample on all syn packets or once every atr sample count */
8129 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
8130 return;
8131
8132 /* reset sample count */
8133 ring->atr_count = 0;
8134
Alexander Duyck244e27a2012-02-08 07:51:11 +00008135 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00008136
8137 /*
8138 * src and dst are inverted, think how the receiver sees them
8139 *
8140 * The input is broken into two sections, a non-compressed section
8141 * containing vm_pool, vlan_id, and flow_type. The rest of the data
8142 * is XORed together and stored in the compressed dword.
8143 */
8144 input.formatted.vlan_id = vlan_id;
8145
8146 /*
8147 * since src port and flex bytes occupy the same word XOR them together
8148 * and write the value to source port portion of compressed dword
8149 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008150 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Joe Perchesa1108ff2014-03-13 05:19:25 +00008151 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
Alexander Duyck69830522011-01-06 14:29:58 +00008152 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00008153 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00008154 common.port.dst ^= th->source;
8155
Mark Rustade19dcde2015-12-09 14:55:37 -08008156 switch (hdr.ipv4->version) {
8157 case IPVERSION:
Alexander Duyck69830522011-01-06 14:29:58 +00008158 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
8159 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
Mark Rustade19dcde2015-12-09 14:55:37 -08008160 break;
8161 case 6:
Alexander Duyck69830522011-01-06 14:29:58 +00008162 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
8163 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
8164 hdr.ipv6->saddr.s6_addr32[1] ^
8165 hdr.ipv6->saddr.s6_addr32[2] ^
8166 hdr.ipv6->saddr.s6_addr32[3] ^
8167 hdr.ipv6->daddr.s6_addr32[0] ^
8168 hdr.ipv6->daddr.s6_addr32[1] ^
8169 hdr.ipv6->daddr.s6_addr32[2] ^
8170 hdr.ipv6->daddr.s6_addr32[3];
Mark Rustade19dcde2015-12-09 14:55:37 -08008171 break;
8172 default:
8173 break;
Alexander Duyck69830522011-01-06 14:29:58 +00008174 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008175
Alexander Duyck9f12df92016-01-25 19:36:29 -08008176 if (hdr.network != skb_network_header(skb))
Mark Rustad67359c32015-06-15 11:33:25 -07008177 input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
Mark Rustad67359c32015-06-15 11:33:25 -07008178
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008179 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00008180 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
8181 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008182}
8183
Jason Wangf663dd92014-01-10 16:18:26 +08008184static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01008185 void *accel_priv, select_queue_fallback_t fallback)
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008186{
Jason Wangf663dd92014-01-10 16:18:26 +08008187 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
8188#ifdef IXGBE_FCOE
Alexander Duyck97488bd2013-01-12 06:33:37 +00008189 struct ixgbe_adapter *adapter;
8190 struct ixgbe_ring_feature *f;
8191 int txq;
Jason Wangf663dd92014-01-10 16:18:26 +08008192#endif
8193
8194 if (fwd_adapter)
8195 return skb->queue_mapping + fwd_adapter->tx_base_queue;
8196
8197#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00008198
Alexander Duyck97488bd2013-01-12 06:33:37 +00008199 /*
8200 * only execute the code below if protocol is FCoE
8201 * or FIP and we have FCoE enabled on the adapter
8202 */
8203 switch (vlan_get_protocol(skb)) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00008204 case htons(ETH_P_FCOE):
8205 case htons(ETH_P_FIP):
Alexander Duyck97488bd2013-01-12 06:33:37 +00008206 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00008207
Alexander Duyck97488bd2013-01-12 06:33:37 +00008208 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8209 break;
8210 default:
Daniel Borkmann99932d42014-02-16 15:55:20 +01008211 return fallback(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00008212 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008213
Alexander Duyck97488bd2013-01-12 06:33:37 +00008214 f = &adapter->ring_feature[RING_F_FCOE];
8215
8216 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
8217 smp_processor_id();
8218
8219 while (txq >= f->indices)
8220 txq -= f->indices;
8221
8222 return txq + f->offset;
Jason Wangf663dd92014-01-10 16:18:26 +08008223#else
Daniel Borkmann99932d42014-02-16 15:55:20 +01008224 return fallback(dev, skb);
Jason Wangf663dd92014-01-10 16:18:26 +08008225#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008226}
8227
John Fastabend33fdc822017-04-24 03:30:18 -07008228static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
8229 struct xdp_buff *xdp)
8230{
8231 struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
8232 struct ixgbe_tx_buffer *tx_buffer;
8233 union ixgbe_adv_tx_desc *tx_desc;
8234 u32 len, cmd_type;
8235 dma_addr_t dma;
8236 u16 i;
8237
8238 len = xdp->data_end - xdp->data;
8239
8240 if (unlikely(!ixgbe_desc_unused(ring)))
8241 return IXGBE_XDP_CONSUMED;
8242
8243 dma = dma_map_single(ring->dev, xdp->data, len, DMA_TO_DEVICE);
8244 if (dma_mapping_error(ring->dev, dma))
8245 return IXGBE_XDP_CONSUMED;
8246
8247 /* record the location of the first descriptor for this packet */
8248 tx_buffer = &ring->tx_buffer_info[ring->next_to_use];
8249 tx_buffer->bytecount = len;
8250 tx_buffer->gso_segs = 1;
8251 tx_buffer->protocol = 0;
8252
8253 i = ring->next_to_use;
8254 tx_desc = IXGBE_TX_DESC(ring, i);
8255
8256 dma_unmap_len_set(tx_buffer, len, len);
8257 dma_unmap_addr_set(tx_buffer, dma, dma);
8258 tx_buffer->data = xdp->data;
8259 tx_desc->read.buffer_addr = cpu_to_le64(dma);
8260
8261 /* put descriptor type bits */
8262 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
8263 IXGBE_ADVTXD_DCMD_DEXT |
8264 IXGBE_ADVTXD_DCMD_IFCS;
8265 cmd_type |= len | IXGBE_TXD_CMD;
8266 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
8267 tx_desc->read.olinfo_status =
8268 cpu_to_le32(len << IXGBE_ADVTXD_PAYLEN_SHIFT);
8269
John Fastabend7379f972017-03-28 09:47:03 -07008270 /* Avoid any potential race with xdp_xmit and cleanup */
8271 smp_wmb();
John Fastabend33fdc822017-04-24 03:30:18 -07008272
8273 /* set next_to_watch value indicating a packet is present */
8274 i++;
8275 if (i == ring->count)
8276 i = 0;
8277
8278 tx_buffer->next_to_watch = tx_desc;
8279 ring->next_to_use = i;
8280
John Fastabend33fdc822017-04-24 03:30:18 -07008281 return IXGBE_XDP_TX;
8282}
8283
Alexander Duyckfc77dc32010-11-16 19:26:51 -08008284netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00008285 struct ixgbe_adapter *adapter,
8286 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008287{
Alexander Duyckd3d00232011-07-15 02:31:25 +00008288 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00008289 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008290 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00008291 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00008292 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00008293 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00008294 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00008295
Alexander Duycka535c302011-05-27 05:31:52 +00008296 /*
8297 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00008298 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00008299 * + 2 desc gap to keep tail from touching head,
8300 * + 1 desc for context descriptor,
8301 * otherwise try next time
8302 */
Alexander Duycka535c302011-05-27 05:31:52 +00008303 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
8304 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00008305
Alexander Duycka535c302011-05-27 05:31:52 +00008306 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
8307 tx_ring->tx_stats.tx_busy++;
8308 return NETDEV_TX_BUSY;
8309 }
8310
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008311 /* record the location of the first descriptor for this packet */
8312 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
8313 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00008314 first->bytecount = skb->len;
8315 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008316
Alexander Duyck66f32a82011-06-29 05:43:22 +00008317 /* if we have a HW VLAN tag being added default to the HW one */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01008318 if (skb_vlan_tag_present(skb)) {
8319 tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008320 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8321 /* else if it is a SW VLAN check the next protocol and store the tag */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008322 } else if (protocol == htons(ETH_P_8021Q)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008323 struct vlan_hdr *vhdr, _vhdr;
8324 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
8325 if (!vhdr)
8326 goto out_drop;
8327
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008328 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
8329 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008330 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07008331 }
Toshiaki Makita02136682015-01-29 20:37:09 +09008332 protocol = vlan_get_protocol(skb);
Yi Zoueacd73f2009-05-13 13:11:06 +00008333
Mark Rustadd5234932014-08-09 07:02:09 +00008334 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
8335 adapter->ptp_clock &&
8336 !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
8337 &adapter->state)) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008338 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
8339 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00008340
8341 /* schedule check for Tx timestamp */
8342 adapter->ptp_tx_skb = skb_get(skb);
8343 adapter->ptp_tx_start = jiffies;
8344 schedule_work(&adapter->ptp_tx_work);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008345 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008346
Jakub Kicinskiff29a862014-03-15 14:55:16 +00008347 skb_tx_timestamp(skb);
8348
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008349#ifdef CONFIG_PCI_IOV
8350 /*
8351 * Use the l2switch_enable flag - would be false if the DMA
8352 * Tx switch had been disabled.
8353 */
8354 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00008355 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008356
8357#endif
John Fastabend32701dc2011-09-27 03:51:56 +00008358 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00008359 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00008360 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
8361 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008362 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00008363 tx_flags |= (skb->priority & 0x7) <<
8364 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008365 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
8366 struct vlan_ethhdr *vhdr;
Francois Romieu2049e1f2014-03-30 03:14:27 +00008367
8368 if (skb_cow_head(skb, 0))
Alexander Duyck66f32a82011-06-29 05:43:22 +00008369 goto out_drop;
8370 vhdr = (struct vlan_ethhdr *)skb->data;
8371 vhdr->h_vlan_TCI = htons(tx_flags >>
8372 IXGBE_TX_FLAGS_VLAN_SHIFT);
8373 } else {
8374 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8375 }
8376 }
Alexander Duycka535c302011-05-27 05:31:52 +00008377
Alexander Duyck244e27a2012-02-08 07:51:11 +00008378 /* record initial flags and protocol */
8379 first->tx_flags = tx_flags;
8380 first->protocol = protocol;
8381
Yi Zoueacd73f2009-05-13 13:11:06 +00008382#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00008383 /* setup tx offload for FCoE */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008384 if ((protocol == htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00008385 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00008386 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00008387 if (tso < 0)
8388 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07008389
Alexander Duyck66f32a82011-06-29 05:43:22 +00008390 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00008391 }
Auke Kok9a799d72007-09-15 14:07:45 -07008392
Auke Kok9a799d72007-09-15 14:07:45 -07008393#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008394 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008395 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07008396 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00008397 else if (!tso)
8398 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008399
8400 /* add the ATR filter if ATR is on */
8401 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00008402 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008403
8404#ifdef IXGBE_FCOE
8405xmit_fcoe:
8406#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008407 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00008408
Auke Kok9a799d72007-09-15 14:07:45 -07008409 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00008410
8411out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008412 dev_kfree_skb_any(first->skb);
8413 first->skb = NULL;
8414
Alexander Duyck897ab152011-05-27 05:31:47 +00008415 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07008416}
8417
John Fastabend2a47fa42013-11-06 09:54:52 -08008418static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
8419 struct net_device *netdev,
8420 struct ixgbe_ring *ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008421{
8422 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008423 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07008424
Alexander Duycka50c29d2012-02-08 07:50:40 +00008425 /*
8426 * The minimum packet size for olinfo paylen is 17 so pad the skb
8427 * in order to meet this minimum size requirement.
8428 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08008429 if (skb_put_padto(skb, 17))
8430 return NETDEV_TX_OK;
Alexander Duycka50c29d2012-02-08 07:50:40 +00008431
John Fastabend2a47fa42013-11-06 09:54:52 -08008432 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
8433
Auke Kok9a799d72007-09-15 14:07:45 -07008434 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
8435}
8436
John Fastabend2a47fa42013-11-06 09:54:52 -08008437static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
8438 struct net_device *netdev)
8439{
8440 return __ixgbe_xmit_frame(skb, netdev, NULL);
8441}
8442
Auke Kok9a799d72007-09-15 14:07:45 -07008443/**
8444 * ixgbe_set_mac - Change the Ethernet Address of the NIC
8445 * @netdev: network interface device structure
8446 * @p: pointer to an address structure
8447 *
8448 * Returns 0 on success, negative on failure
8449 **/
8450static int ixgbe_set_mac(struct net_device *netdev, void *p)
8451{
8452 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8453 struct ixgbe_hw *hw = &adapter->hw;
8454 struct sockaddr *addr = p;
8455
8456 if (!is_valid_ether_addr(addr->sa_data))
8457 return -EADDRNOTAVAIL;
8458
8459 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008460 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07008461
Alexander Duyckc9f53e62015-10-22 16:26:30 -07008462 ixgbe_mac_set_default_filter(adapter);
8463
8464 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008465}
8466
Ben Hutchings6b73e102009-04-29 08:08:58 +00008467static int
8468ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
8469{
8470 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8471 struct ixgbe_hw *hw = &adapter->hw;
8472 u16 value;
8473 int rc;
8474
8475 if (prtad != hw->phy.mdio.prtad)
8476 return -EINVAL;
8477 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
8478 if (!rc)
8479 rc = value;
8480 return rc;
8481}
8482
8483static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
8484 u16 addr, u16 value)
8485{
8486 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8487 struct ixgbe_hw *hw = &adapter->hw;
8488
8489 if (prtad != hw->phy.mdio.prtad)
8490 return -EINVAL;
8491 return hw->phy.ops.write_reg(hw, addr, devad, value);
8492}
8493
8494static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
8495{
8496 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8497
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008498 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008499 case SIOCSHWTSTAMP:
Jacob Keller93501d42014-02-28 15:48:58 -08008500 return ixgbe_ptp_set_ts_config(adapter, req);
8501 case SIOCGHWTSTAMP:
8502 return ixgbe_ptp_get_ts_config(adapter, req);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008503 default:
8504 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
8505 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00008506}
8507
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008508/**
8509 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008510 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008511 * @netdev: network interface device structure
8512 *
8513 * Returns non-zero on failure
8514 **/
8515static int ixgbe_add_sanmac_netdev(struct net_device *dev)
8516{
8517 int err = 0;
8518 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008519 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008520
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008521 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008522 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008523 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008524 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008525
8526 /* update SAN MAC vmdq pool selection */
8527 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008528 }
8529 return err;
8530}
8531
8532/**
8533 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008534 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008535 * @netdev: network interface device structure
8536 *
8537 * Returns non-zero on failure
8538 **/
8539static int ixgbe_del_sanmac_netdev(struct net_device *dev)
8540{
8541 int err = 0;
8542 struct ixgbe_adapter *adapter = netdev_priv(dev);
8543 struct ixgbe_mac_info *mac = &adapter->hw.mac;
8544
8545 if (is_valid_ether_addr(mac->san_addr)) {
8546 rtnl_lock();
8547 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
8548 rtnl_unlock();
8549 }
8550 return err;
8551}
8552
Auke Kok9a799d72007-09-15 14:07:45 -07008553#ifdef CONFIG_NET_POLL_CONTROLLER
8554/*
8555 * Polling 'interrupt' - used by things like netconsole to send skbs
8556 * without having to re-enable interrupts. It's not called while
8557 * the interrupt routine is executing.
8558 */
8559static void ixgbe_netpoll(struct net_device *netdev)
8560{
8561 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00008562 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07008563
Alexander Duyck1a647bd2010-01-13 01:49:13 +00008564 /* if interface is down do nothing */
8565 if (test_bit(__IXGBE_DOWN, &adapter->state))
8566 return;
8567
Alexander Duyck856f6062015-02-25 17:45:54 +00008568 /* loop through and schedule all active queues */
8569 for (i = 0; i < adapter->num_q_vectors; i++)
8570 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07008571}
Auke Kok9a799d72007-09-15 14:07:45 -07008572
Alexander Duyck581330b2012-02-08 07:51:47 +00008573#endif
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008574
John Fastabend33fdc822017-04-24 03:30:18 -07008575static void ixgbe_get_ring_stats64(struct rtnl_link_stats64 *stats,
8576 struct ixgbe_ring *ring)
8577{
8578 u64 bytes, packets;
8579 unsigned int start;
8580
8581 if (ring) {
8582 do {
8583 start = u64_stats_fetch_begin_irq(&ring->syncp);
8584 packets = ring->stats.packets;
8585 bytes = ring->stats.bytes;
8586 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
8587 stats->tx_packets += packets;
8588 stats->tx_bytes += bytes;
8589 }
8590}
8591
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008592static void ixgbe_get_stats64(struct net_device *netdev,
8593 struct rtnl_link_stats64 *stats)
Eric Dumazetde1036b2010-10-20 23:00:04 +00008594{
8595 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8596 int i;
8597
Eric Dumazet1a515022010-11-16 19:26:42 -08008598 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00008599 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08008600 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00008601 u64 bytes, packets;
8602 unsigned int start;
8603
Eric Dumazet1a515022010-11-16 19:26:42 -08008604 if (ring) {
8605 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008606 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1a515022010-11-16 19:26:42 -08008607 packets = ring->stats.packets;
8608 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008609 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1a515022010-11-16 19:26:42 -08008610 stats->rx_packets += packets;
8611 stats->rx_bytes += bytes;
8612 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00008613 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008614
8615 for (i = 0; i < adapter->num_tx_queues; i++) {
8616 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008617
John Fastabend33fdc822017-04-24 03:30:18 -07008618 ixgbe_get_ring_stats64(stats, ring);
8619 }
8620 for (i = 0; i < adapter->num_xdp_queues; i++) {
8621 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->xdp_ring[i]);
8622
8623 ixgbe_get_ring_stats64(stats, ring);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008624 }
Eric Dumazet1a515022010-11-16 19:26:42 -08008625 rcu_read_unlock();
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008626
Eric Dumazetde1036b2010-10-20 23:00:04 +00008627 /* following stats updated by ixgbe_watchdog_task() */
8628 stats->multicast = netdev->stats.multicast;
8629 stats->rx_errors = netdev->stats.rx_errors;
8630 stats->rx_length_errors = netdev->stats.rx_length_errors;
8631 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
8632 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
Eric Dumazetde1036b2010-10-20 23:00:04 +00008633}
8634
Jeff Kirsher8af3c332012-02-18 07:08:14 +00008635#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008636/**
8637 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
8638 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00008639 * @tc: number of traffic classes currently enabled
8640 *
8641 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
8642 * 802.1Q priority maps to a packet buffer that exists.
8643 */
8644static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
8645{
8646 struct ixgbe_hw *hw = &adapter->hw;
8647 u32 reg, rsave;
8648 int i;
8649
8650 /* 82598 have a static priority to TC mapping that can not
8651 * be changed so no validation is needed.
8652 */
8653 if (hw->mac.type == ixgbe_mac_82598EB)
8654 return;
8655
8656 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
8657 rsave = reg;
8658
8659 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
8660 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
8661
8662 /* If up2tc is out of bounds default to zero */
8663 if (up2tc > tc)
8664 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
8665 }
8666
8667 if (reg != rsave)
8668 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
8669
8670 return;
8671}
8672
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008673/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00008674 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
8675 * @adapter: Pointer to adapter struct
8676 *
8677 * Populate the netdev user priority to tc map
8678 */
8679static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
8680{
8681 struct net_device *dev = adapter->netdev;
8682 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
8683 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
8684 u8 prio;
8685
8686 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
8687 u8 tc = 0;
8688
8689 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
8690 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
8691 else if (ets)
8692 tc = ets->prio_tc[prio];
8693
8694 netdev_set_prio_tc_map(dev, prio, tc);
8695 }
8696}
8697
Alexander Duyckcca73c52013-01-12 06:33:44 +00008698#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck02debdc2012-05-18 06:33:31 +00008699/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008700 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00008701 *
8702 * @netdev: net device to configure
8703 * @tc: number of traffic classes to enable
8704 */
8705int ixgbe_setup_tc(struct net_device *dev, u8 tc)
8706{
John Fastabend8b1c0b22011-05-03 02:26:48 +00008707 struct ixgbe_adapter *adapter = netdev_priv(dev);
8708 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08008709 bool pools;
John Fastabend8b1c0b22011-05-03 02:26:48 +00008710
John Fastabend8b1c0b22011-05-03 02:26:48 +00008711 /* Hardware supports up to 8 traffic classes */
Emil Tantilov7e3f5c82015-07-09 12:28:59 -07008712 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
8713 return -EINVAL;
8714
8715 if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
John Fastabend8b1c0b22011-05-03 02:26:48 +00008716 return -EINVAL;
8717
John Fastabend2a47fa42013-11-06 09:54:52 -08008718 pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
8719 if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
8720 return -EBUSY;
8721
John Fastabend8b1c0b22011-05-03 02:26:48 +00008722 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00008723 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00008724 * hardware is not flexible enough to do this dynamically.
8725 */
8726 if (netif_running(dev))
8727 ixgbe_close(dev);
Alexander Duyckbf4d67d2015-10-20 13:28:17 -07008728 else
8729 ixgbe_reset(adapter);
8730
John Fastabend8b1c0b22011-05-03 02:26:48 +00008731 ixgbe_clear_interrupt_scheme(adapter);
8732
Alexander Duyckcca73c52013-01-12 06:33:44 +00008733#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00008734 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008735 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008736 ixgbe_set_prio_tc_map(adapter);
8737
John Fastabende7589ea2011-07-18 22:38:36 +00008738 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008739
Alexander Duyck943561d2012-05-09 22:14:44 -07008740 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
8741 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008742 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07008743 }
John Fastabende7589ea2011-07-18 22:38:36 +00008744 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008745 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008746
Alexander Duyck943561d2012-05-09 22:14:44 -07008747 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8748 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008749
8750 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008751
8752 adapter->temp_dcb_cfg.pfc_mode_enable = false;
8753 adapter->dcb_cfg.pfc_mode_enable = false;
8754 }
8755
John Fastabend8b1c0b22011-05-03 02:26:48 +00008756 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00008757
8758#endif /* CONFIG_IXGBE_DCB */
8759 ixgbe_init_interrupt_scheme(adapter);
8760
John Fastabend8b1c0b22011-05-03 02:26:48 +00008761 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00008762 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00008763
8764 return 0;
8765}
Eric Dumazetde1036b2010-10-20 23:00:04 +00008766
John Fastabendb82b17d2016-02-16 21:18:53 -08008767static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
8768 struct tc_cls_u32_offload *cls)
8769{
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008770 u32 hdl = cls->knode.handle;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008771 u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008772 u32 loc = cls->knode.handle & 0xfffff;
8773 int err = 0, i, j;
8774 struct ixgbe_jump_table *jump = NULL;
8775
8776 if (loc > IXGBE_MAX_HW_ENTRIES)
8777 return -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08008778
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008779 if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
8780 return -EINVAL;
8781
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008782 /* Clear this filter in the link data it is associated with */
8783 if (uhtid != 0x800) {
8784 jump = adapter->jump_tables[uhtid];
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008785 if (!jump)
8786 return -EINVAL;
8787 if (!test_bit(loc - 1, jump->child_loc_map))
8788 return -EINVAL;
8789 clear_bit(loc - 1, jump->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008790 }
8791
8792 /* Check if the filter being deleted is a link */
8793 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
8794 jump = adapter->jump_tables[i];
8795 if (jump && jump->link_hdl == hdl) {
8796 /* Delete filters in the hardware in the child hash
8797 * table associated with this link
8798 */
8799 for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) {
8800 if (!test_bit(j, jump->child_loc_map))
8801 continue;
8802 spin_lock(&adapter->fdir_perfect_lock);
8803 err = ixgbe_update_ethtool_fdir_entry(adapter,
8804 NULL,
8805 j + 1);
8806 spin_unlock(&adapter->fdir_perfect_lock);
8807 clear_bit(j, jump->child_loc_map);
8808 }
8809 /* Remove resources for this link */
8810 kfree(jump->input);
8811 kfree(jump->mask);
8812 kfree(jump);
8813 adapter->jump_tables[i] = NULL;
8814 return err;
8815 }
8816 }
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008817
John Fastabendb82b17d2016-02-16 21:18:53 -08008818 spin_lock(&adapter->fdir_perfect_lock);
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008819 err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
John Fastabendb82b17d2016-02-16 21:18:53 -08008820 spin_unlock(&adapter->fdir_perfect_lock);
8821 return err;
8822}
8823
John Fastabenddb956ae2016-02-16 21:19:19 -08008824static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
8825 __be16 protocol,
8826 struct tc_cls_u32_offload *cls)
8827{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008828 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8829
8830 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8831 return -EINVAL;
8832
John Fastabenddb956ae2016-02-16 21:19:19 -08008833 /* This ixgbe devices do not support hash tables at the moment
8834 * so abort when given hash tables.
8835 */
8836 if (cls->hnode.divisor > 0)
8837 return -EINVAL;
8838
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008839 set_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008840 return 0;
8841}
8842
8843static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
8844 struct tc_cls_u32_offload *cls)
8845{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008846 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8847
8848 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8849 return -EINVAL;
8850
8851 clear_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008852 return 0;
8853}
8854
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008855#ifdef CONFIG_NET_CLS_ACT
David Ahern1cd127f2016-10-17 19:15:48 -07008856struct upper_walk_data {
8857 struct ixgbe_adapter *adapter;
8858 u64 action;
8859 int ifindex;
8860 u8 queue;
8861};
8862
8863static int get_macvlan_queue(struct net_device *upper, void *_data)
8864{
8865 if (netif_is_macvlan(upper)) {
8866 struct macvlan_dev *dfwd = netdev_priv(upper);
8867 struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
8868 struct upper_walk_data *data = _data;
8869 struct ixgbe_adapter *adapter = data->adapter;
8870 int ifindex = data->ifindex;
8871
8872 if (vadapter && vadapter->netdev->ifindex == ifindex) {
8873 data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
8874 data->action = data->queue;
8875 return 1;
8876 }
8877 }
8878
8879 return 0;
8880}
8881
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008882static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
8883 u8 *queue, u64 *action)
8884{
8885 unsigned int num_vfs = adapter->num_vfs, vf;
David Ahern1cd127f2016-10-17 19:15:48 -07008886 struct upper_walk_data data;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008887 struct net_device *upper;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008888
8889 /* redirect to a SRIOV VF */
8890 for (vf = 0; vf < num_vfs; ++vf) {
8891 upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
8892 if (upper->ifindex == ifindex) {
8893 if (adapter->num_rx_pools > 1)
8894 *queue = vf * 2;
8895 else
8896 *queue = vf * adapter->num_rx_queues_per_pool;
8897
8898 *action = vf + 1;
8899 *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
8900 return 0;
8901 }
8902 }
8903
8904 /* redirect to a offloaded macvlan netdev */
David Ahern1cd127f2016-10-17 19:15:48 -07008905 data.adapter = adapter;
8906 data.ifindex = ifindex;
8907 data.action = 0;
8908 data.queue = 0;
8909 if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
8910 get_macvlan_queue, &data)) {
8911 *action = data.action;
8912 *queue = data.queue;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008913
David Ahern1cd127f2016-10-17 19:15:48 -07008914 return 0;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008915 }
8916
8917 return -EINVAL;
8918}
8919
8920static int parse_tc_actions(struct ixgbe_adapter *adapter,
8921 struct tcf_exts *exts, u64 *action, u8 *queue)
8922{
8923 const struct tc_action *a;
WANG Cong22dc13c2016-08-13 22:35:00 -07008924 LIST_HEAD(actions);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008925 int err;
8926
8927 if (tc_no_actions(exts))
8928 return -EINVAL;
8929
WANG Cong22dc13c2016-08-13 22:35:00 -07008930 tcf_exts_to_list(exts, &actions);
8931 list_for_each_entry(a, &actions, list) {
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008932
8933 /* Drop action */
8934 if (is_tcf_gact_shot(a)) {
8935 *action = IXGBE_FDIR_DROP_QUEUE;
8936 *queue = IXGBE_FDIR_DROP_QUEUE;
8937 return 0;
8938 }
8939
8940 /* Redirect to a VF or a offloaded macvlan */
Shmulik Ladkani5724b8b2016-10-13 09:06:43 +03008941 if (is_tcf_mirred_egress_redirect(a)) {
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008942 int ifindex = tcf_mirred_ifindex(a);
8943
8944 err = handle_redirect_action(adapter, ifindex, queue,
8945 action);
8946 if (err == 0)
8947 return err;
8948 }
8949 }
8950
8951 return -EINVAL;
8952}
8953#else
8954static int parse_tc_actions(struct ixgbe_adapter *adapter,
8955 struct tcf_exts *exts, u64 *action, u8 *queue)
8956{
8957 return -EINVAL;
8958}
8959#endif /* CONFIG_NET_CLS_ACT */
8960
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04008961static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input,
8962 union ixgbe_atr_input *mask,
8963 struct tc_cls_u32_offload *cls,
8964 struct ixgbe_mat_field *field_ptr,
8965 struct ixgbe_nexthdr *nexthdr)
8966{
8967 int i, j, off;
8968 __be32 val, m;
8969 bool found_entry = false, found_jump_field = false;
8970
8971 for (i = 0; i < cls->knode.sel->nkeys; i++) {
8972 off = cls->knode.sel->keys[i].off;
8973 val = cls->knode.sel->keys[i].val;
8974 m = cls->knode.sel->keys[i].mask;
8975
8976 for (j = 0; field_ptr[j].val; j++) {
8977 if (field_ptr[j].off == off) {
8978 field_ptr[j].val(input, mask, val, m);
8979 input->filter.formatted.flow_type |=
8980 field_ptr[j].type;
8981 found_entry = true;
8982 break;
8983 }
8984 }
8985 if (nexthdr) {
8986 if (nexthdr->off == cls->knode.sel->keys[i].off &&
8987 nexthdr->val == cls->knode.sel->keys[i].val &&
8988 nexthdr->mask == cls->knode.sel->keys[i].mask)
8989 found_jump_field = true;
8990 else
8991 continue;
8992 }
8993 }
8994
8995 if (nexthdr && !found_jump_field)
8996 return -EINVAL;
8997
8998 if (!found_entry)
8999 return 0;
9000
9001 mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
9002 IXGBE_ATR_L4TYPE_MASK;
9003
9004 if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
9005 mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
9006
9007 return 0;
9008}
9009
John Fastabendb82b17d2016-02-16 21:18:53 -08009010static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
9011 __be16 protocol,
9012 struct tc_cls_u32_offload *cls)
9013{
9014 u32 loc = cls->knode.handle & 0xfffff;
9015 struct ixgbe_hw *hw = &adapter->hw;
9016 struct ixgbe_mat_field *field_ptr;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009017 struct ixgbe_fdir_filter *input = NULL;
9018 union ixgbe_atr_input *mask = NULL;
9019 struct ixgbe_jump_table *jump = NULL;
9020 int i, err = -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08009021 u8 queue;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009022 u32 uhtid, link_uhtid;
John Fastabendb82b17d2016-02-16 21:18:53 -08009023
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009024 uhtid = TC_U32_USERHTID(cls->knode.handle);
9025 link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
John Fastabendb82b17d2016-02-16 21:18:53 -08009026
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009027 /* At the moment cls_u32 jumps to network layer and skips past
John Fastabendb82b17d2016-02-16 21:18:53 -08009028 * L2 headers. The canonical method to match L2 frames is to use
9029 * negative values. However this is error prone at best but really
9030 * just broken because there is no way to "know" what sort of hdr
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009031 * is in front of the network layer. Fix cls_u32 to support L2
John Fastabendb82b17d2016-02-16 21:18:53 -08009032 * headers when needed.
9033 */
9034 if (protocol != htons(ETH_P_IP))
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009035 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009036
9037 if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
9038 e_err(drv, "Location out of range\n");
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009039 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009040 }
9041
9042 /* cls u32 is a graph starting at root node 0x800. The driver tracks
9043 * links and also the fields used to advance the parser across each
9044 * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
9045 * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
9046 * To add support for new nodes update ixgbe_model.h parse structures
9047 * this function _should_ be generic try not to hardcode values here.
9048 */
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009049 if (uhtid == 0x800) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009050 field_ptr = (adapter->jump_tables[0])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08009051 } else {
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009052 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009053 return err;
9054 if (!adapter->jump_tables[uhtid])
9055 return err;
9056 field_ptr = (adapter->jump_tables[uhtid])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08009057 }
9058
9059 if (!field_ptr)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009060 return err;
9061
9062 /* At this point we know the field_ptr is valid and need to either
9063 * build cls_u32 link or attach filter. Because adding a link to
9064 * a handle that does not exist is invalid and the same for adding
9065 * rules to handles that don't exist.
9066 */
9067
9068 if (link_uhtid) {
9069 struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
9070
9071 if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
9072 return err;
9073
9074 if (!test_bit(link_uhtid - 1, &adapter->tables))
9075 return err;
9076
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009077 /* Multiple filters as links to the same hash table are not
9078 * supported. To add a new filter with the same next header
9079 * but different match/jump conditions, create a new hash table
9080 * and link to it.
9081 */
9082 if (adapter->jump_tables[link_uhtid] &&
9083 (adapter->jump_tables[link_uhtid])->link_hdl) {
9084 e_err(drv, "Link filter exists for link: %x\n",
9085 link_uhtid);
9086 return err;
9087 }
9088
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009089 for (i = 0; nexthdr[i].jump; i++) {
9090 if (nexthdr[i].o != cls->knode.sel->offoff ||
9091 nexthdr[i].s != cls->knode.sel->offshift ||
9092 nexthdr[i].m != cls->knode.sel->offmask)
9093 return err;
9094
9095 jump = kzalloc(sizeof(*jump), GFP_KERNEL);
9096 if (!jump)
9097 return -ENOMEM;
9098 input = kzalloc(sizeof(*input), GFP_KERNEL);
9099 if (!input) {
9100 err = -ENOMEM;
9101 goto free_jump;
9102 }
9103 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
9104 if (!mask) {
9105 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009106 goto free_input;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009107 }
9108 jump->input = input;
9109 jump->mask = mask;
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009110 jump->link_hdl = cls->knode.handle;
9111
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009112 err = ixgbe_clsu32_build_input(input, mask, cls,
9113 field_ptr, &nexthdr[i]);
9114 if (!err) {
9115 jump->mat = nexthdr[i].jump;
9116 adapter->jump_tables[link_uhtid] = jump;
9117 break;
9118 }
9119 }
9120 return 0;
9121 }
John Fastabendb82b17d2016-02-16 21:18:53 -08009122
9123 input = kzalloc(sizeof(*input), GFP_KERNEL);
9124 if (!input)
9125 return -ENOMEM;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009126 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
9127 if (!mask) {
9128 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009129 goto free_input;
John Fastabendb82b17d2016-02-16 21:18:53 -08009130 }
9131
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009132 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) {
9133 if ((adapter->jump_tables[uhtid])->input)
9134 memcpy(input, (adapter->jump_tables[uhtid])->input,
9135 sizeof(*input));
9136 if ((adapter->jump_tables[uhtid])->mask)
9137 memcpy(mask, (adapter->jump_tables[uhtid])->mask,
9138 sizeof(*mask));
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009139
9140 /* Lookup in all child hash tables if this location is already
9141 * filled with a filter
9142 */
9143 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
9144 struct ixgbe_jump_table *link = adapter->jump_tables[i];
9145
9146 if (link && (test_bit(loc - 1, link->child_loc_map))) {
9147 e_err(drv, "Filter exists in location: %x\n",
9148 loc);
9149 err = -EINVAL;
9150 goto err_out;
9151 }
9152 }
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009153 }
9154 err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL);
9155 if (err)
John Fastabendb82b17d2016-02-16 21:18:53 -08009156 goto err_out;
9157
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009158 err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
9159 &queue);
9160 if (err < 0)
John Fastabendb82b17d2016-02-16 21:18:53 -08009161 goto err_out;
John Fastabendb82b17d2016-02-16 21:18:53 -08009162
John Fastabendb82b17d2016-02-16 21:18:53 -08009163 input->sw_idx = loc;
9164
9165 spin_lock(&adapter->fdir_perfect_lock);
9166
9167 if (hlist_empty(&adapter->fdir_filter_list)) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009168 memcpy(&adapter->fdir_mask, mask, sizeof(*mask));
9169 err = ixgbe_fdir_set_input_mask_82599(hw, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009170 if (err)
9171 goto err_out_w_lock;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009172 } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) {
John Fastabendb82b17d2016-02-16 21:18:53 -08009173 err = -EINVAL;
9174 goto err_out_w_lock;
9175 }
9176
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009177 ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009178 err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
9179 input->sw_idx, queue);
9180 if (!err)
9181 ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
9182 spin_unlock(&adapter->fdir_perfect_lock);
9183
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009184 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid]))
9185 set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009186
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009187 kfree(mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009188 return err;
9189err_out_w_lock:
9190 spin_unlock(&adapter->fdir_perfect_lock);
9191err_out:
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009192 kfree(mask);
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009193free_input:
9194 kfree(input);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009195free_jump:
9196 kfree(jump);
9197 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009198}
9199
Emil Tantilov6e2a60b2016-02-17 15:55:06 -08009200static int __ixgbe_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
9201 struct tc_to_netdev *tc)
John Fastabende4c67342016-02-16 21:16:15 -08009202{
John Fastabendb82b17d2016-02-16 21:18:53 -08009203 struct ixgbe_adapter *adapter = netdev_priv(dev);
9204
9205 if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) &&
9206 tc->type == TC_SETUP_CLSU32) {
John Fastabendb82b17d2016-02-16 21:18:53 -08009207 switch (tc->cls_u32->command) {
9208 case TC_CLSU32_NEW_KNODE:
9209 case TC_CLSU32_REPLACE_KNODE:
9210 return ixgbe_configure_clsu32(adapter,
9211 proto, tc->cls_u32);
9212 case TC_CLSU32_DELETE_KNODE:
9213 return ixgbe_delete_clsu32(adapter, tc->cls_u32);
John Fastabenddb956ae2016-02-16 21:19:19 -08009214 case TC_CLSU32_NEW_HNODE:
9215 case TC_CLSU32_REPLACE_HNODE:
9216 return ixgbe_configure_clsu32_add_hnode(adapter, proto,
9217 tc->cls_u32);
9218 case TC_CLSU32_DELETE_HNODE:
9219 return ixgbe_configure_clsu32_del_hnode(adapter,
9220 tc->cls_u32);
John Fastabendb82b17d2016-02-16 21:18:53 -08009221 default:
9222 return -EINVAL;
9223 }
9224 }
9225
John Fastabend5eb4dce2016-02-29 11:26:13 -08009226 if (tc->type != TC_SETUP_MQPRIO)
John Fastabende4c67342016-02-16 21:16:15 -08009227 return -EINVAL;
9228
Amritha Nambiar56f36ac2017-03-15 10:39:25 -07009229 tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
9230
9231 return ixgbe_setup_tc(dev, tc->mqprio->num_tc);
John Fastabende4c67342016-02-16 21:16:15 -08009232}
9233
Greg Roseda36b642012-12-11 08:26:43 +00009234#ifdef CONFIG_PCI_IOV
9235void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
9236{
9237 struct net_device *netdev = adapter->netdev;
9238
9239 rtnl_lock();
Greg Roseda36b642012-12-11 08:26:43 +00009240 ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
Greg Roseda36b642012-12-11 08:26:43 +00009241 rtnl_unlock();
9242}
9243
9244#endif
Don Skidmore082757a2011-07-21 05:55:00 +00009245void ixgbe_do_reset(struct net_device *netdev)
9246{
9247 struct ixgbe_adapter *adapter = netdev_priv(netdev);
9248
9249 if (netif_running(netdev))
9250 ixgbe_reinit_locked(adapter);
9251 else
9252 ixgbe_reset(adapter);
9253}
9254
Michał Mirosławc8f44af2011-11-15 15:29:55 +00009255static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00009256 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00009257{
9258 struct ixgbe_adapter *adapter = netdev_priv(netdev);
9259
Don Skidmore082757a2011-07-21 05:55:00 +00009260 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00009261 if (!(features & NETIF_F_RXCSUM))
9262 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00009263
Alexander Duyck567d2de2012-02-11 07:18:57 +00009264 /* Turn off LRO if not RSC capable */
9265 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
9266 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009267
Alexander Duyck567d2de2012-02-11 07:18:57 +00009268 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00009269}
9270
Michał Mirosławc8f44af2011-11-15 15:29:55 +00009271static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00009272 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00009273{
9274 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00009275 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00009276 bool need_reset = false;
9277
Don Skidmore082757a2011-07-21 05:55:00 +00009278 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00009279 if (!(features & NETIF_F_LRO)) {
9280 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00009281 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00009282 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
9283 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
9284 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
9285 if (adapter->rx_itr_setting == 1 ||
9286 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
9287 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
9288 need_reset = true;
9289 } else if ((changed ^ features) & NETIF_F_LRO) {
9290 e_info(probe, "rx-usecs set too low, "
9291 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00009292 }
9293 }
9294
9295 /*
John Fastabendb82b17d2016-02-16 21:18:53 -08009296 * Check if Flow Director n-tuple support or hw_tc support was
9297 * enabled or disabled. If the state changed, we need to reset.
Don Skidmore082757a2011-07-21 05:55:00 +00009298 */
John Fastabendb82b17d2016-02-16 21:18:53 -08009299 if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
Alexander Duyck567d2de2012-02-11 07:18:57 +00009300 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00009301 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
9302 need_reset = true;
9303
Alexander Duyck567d2de2012-02-11 07:18:57 +00009304 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
9305 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
John Fastabendb82b17d2016-02-16 21:18:53 -08009306 } else {
Alexander Duyck39cb6812012-06-06 05:38:20 +00009307 /* turn off perfect filters, enable ATR and reset */
9308 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
9309 need_reset = true;
9310
9311 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
9312
9313 /* We cannot enable ATR if SR-IOV is enabled */
John Fastabendb82b17d2016-02-16 21:18:53 -08009314 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
9315 /* We cannot enable ATR if we have 2 or more tcs */
9316 (netdev_get_num_tc(netdev) > 1) ||
9317 /* We cannot enable ATR if RSS is disabled */
9318 (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
9319 /* A sample rate of 0 indicates ATR disabled */
9320 (!adapter->atr_sample_rate))
9321 ; /* do nothing not supported */
9322 else /* otherwise supported and set the flag */
9323 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00009324 }
9325
Ben Greear3f2d1c02012-03-08 08:28:41 +00009326 if (changed & NETIF_F_RXALL)
9327 need_reset = true;
9328
Alexander Duyck567d2de2012-02-11 07:18:57 +00009329 netdev->features = features;
Mark Rustad67359c32015-06-15 11:33:25 -07009330
Mark Rustad67359c32015-06-15 11:33:25 -07009331 if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
Emil Tantilova21d0822016-08-10 11:19:23 -07009332 if (features & NETIF_F_RXCSUM) {
9333 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9334 } else {
9335 u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9336
9337 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9338 }
9339 }
9340
9341 if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) {
9342 if (features & NETIF_F_RXCSUM) {
9343 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9344 } else {
9345 u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9346
9347 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9348 }
Mark Rustad67359c32015-06-15 11:33:25 -07009349 }
Mark Rustad67359c32015-06-15 11:33:25 -07009350
Don Skidmore082757a2011-07-21 05:55:00 +00009351 if (need_reset)
9352 ixgbe_do_reset(netdev);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08009353 else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
9354 NETIF_F_HW_VLAN_CTAG_FILTER))
9355 ixgbe_set_rx_mode(netdev);
Don Skidmore082757a2011-07-21 05:55:00 +00009356
9357 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00009358}
9359
Don Skidmore3f207802014-12-23 07:40:34 +00009360/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009361 * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009362 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009363 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009364 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009365static void ixgbe_add_udp_tunnel_port(struct net_device *dev,
9366 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009367{
9368 struct ixgbe_adapter *adapter = netdev_priv(dev);
9369 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckb3a49552016-06-16 12:22:19 -07009370 __be16 port = ti->port;
Emil Tantilova21d0822016-08-10 11:19:23 -07009371 u32 port_shift = 0;
9372 u32 reg;
Mark Rustad67359c32015-06-15 11:33:25 -07009373
Alexander Duyckb3a49552016-06-16 12:22:19 -07009374 if (ti->sa_family != AF_INET)
9375 return;
9376
Emil Tantilova21d0822016-08-10 11:19:23 -07009377 switch (ti->type) {
9378 case UDP_TUNNEL_TYPE_VXLAN:
9379 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9380 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009381
Emil Tantilova21d0822016-08-10 11:19:23 -07009382 if (adapter->vxlan_port == port)
9383 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009384
Emil Tantilova21d0822016-08-10 11:19:23 -07009385 if (adapter->vxlan_port) {
9386 netdev_info(dev,
9387 "VXLAN port %d set, not adding port %d\n",
9388 ntohs(adapter->vxlan_port),
9389 ntohs(port));
9390 return;
9391 }
9392
9393 adapter->vxlan_port = port;
9394 break;
9395 case UDP_TUNNEL_TYPE_GENEVE:
9396 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9397 return;
9398
9399 if (adapter->geneve_port == port)
9400 return;
9401
9402 if (adapter->geneve_port) {
9403 netdev_info(dev,
9404 "GENEVE port %d set, not adding port %d\n",
9405 ntohs(adapter->geneve_port),
9406 ntohs(port));
9407 return;
9408 }
9409
9410 port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT;
9411 adapter->geneve_port = port;
9412 break;
9413 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009414 return;
9415 }
9416
Emil Tantilova21d0822016-08-10 11:19:23 -07009417 reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift;
9418 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg);
Don Skidmore3f207802014-12-23 07:40:34 +00009419}
9420
9421/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009422 * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009423 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009424 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009425 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009426static void ixgbe_del_udp_tunnel_port(struct net_device *dev,
9427 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009428{
9429 struct ixgbe_adapter *adapter = netdev_priv(dev);
Emil Tantilova21d0822016-08-10 11:19:23 -07009430 u32 port_mask;
Don Skidmore3f207802014-12-23 07:40:34 +00009431
Emil Tantilova21d0822016-08-10 11:19:23 -07009432 if (ti->type != UDP_TUNNEL_TYPE_VXLAN &&
9433 ti->type != UDP_TUNNEL_TYPE_GENEVE)
Alexander Duyckb3a49552016-06-16 12:22:19 -07009434 return;
9435
9436 if (ti->sa_family != AF_INET)
9437 return;
9438
Emil Tantilova21d0822016-08-10 11:19:23 -07009439 switch (ti->type) {
9440 case UDP_TUNNEL_TYPE_VXLAN:
9441 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9442 return;
Mark Rustad67359c32015-06-15 11:33:25 -07009443
Emil Tantilova21d0822016-08-10 11:19:23 -07009444 if (adapter->vxlan_port != ti->port) {
9445 netdev_info(dev, "VXLAN port %d not found\n",
9446 ntohs(ti->port));
9447 return;
9448 }
9449
9450 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9451 break;
9452 case UDP_TUNNEL_TYPE_GENEVE:
9453 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9454 return;
9455
9456 if (adapter->geneve_port != ti->port) {
9457 netdev_info(dev, "GENEVE port %d not found\n",
9458 ntohs(ti->port));
9459 return;
9460 }
9461
9462 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9463 break;
9464 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009465 return;
9466 }
9467
Emil Tantilova21d0822016-08-10 11:19:23 -07009468 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9469 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Don Skidmore3f207802014-12-23 07:40:34 +00009470}
9471
stephen hemmingeredc7d572012-10-01 12:32:33 +00009472static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009473 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01009474 const unsigned char *addr, u16 vid,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009475 u16 flags)
9476{
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009477 /* guarantee we can provide a unique filter for the unicast address */
Ben Hutchings46acc462012-11-01 09:11:11 +00009478 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
Alexander Duyck2f9be162015-10-22 16:26:42 -07009479 struct ixgbe_adapter *adapter = netdev_priv(dev);
9480 u16 pool = VMDQ_P(0);
9481
9482 if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009483 return -ENOMEM;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009484 }
9485
Jiri Pirkof6f64242014-11-28 14:34:15 +01009486 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009487}
9488
Don Skidmore219efe92015-04-09 22:03:22 -07009489/**
9490 * ixgbe_configure_bridge_mode - set various bridge modes
9491 * @adapter - the private structure
9492 * @mode - requested bridge mode
9493 *
9494 * Configure some settings require for various bridge modes.
9495 **/
9496static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
9497 __u16 mode)
9498{
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009499 struct ixgbe_hw *hw = &adapter->hw;
9500 unsigned int p, num_pools;
9501 u32 vmdctl;
9502
Don Skidmore219efe92015-04-09 22:03:22 -07009503 switch (mode) {
9504 case BRIDGE_MODE_VEPA:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009505 /* disable Tx loopback, rely on switch hairpin mode */
Don Skidmore219efe92015-04-09 22:03:22 -07009506 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009507
9508 /* must enable Rx switching replication to allow multicast
9509 * packet reception on all VFs, and to enable source address
9510 * pruning.
9511 */
9512 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9513 vmdctl |= IXGBE_VT_CTL_REPLEN;
9514 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9515
9516 /* enable Rx source address pruning. Note, this requires
9517 * replication to be enabled or else it does nothing.
9518 */
9519 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9520 for (p = 0; p < num_pools; p++) {
9521 if (hw->mac.ops.set_source_address_pruning)
9522 hw->mac.ops.set_source_address_pruning(hw,
9523 true,
9524 p);
9525 }
Don Skidmore219efe92015-04-09 22:03:22 -07009526 break;
9527 case BRIDGE_MODE_VEB:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009528 /* enable Tx loopback for internal VF/PF communication */
Don Skidmore219efe92015-04-09 22:03:22 -07009529 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
9530 IXGBE_PFDTXGSWC_VT_LBEN);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009531
9532 /* disable Rx switching replication unless we have SR-IOV
9533 * virtual functions
9534 */
9535 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9536 if (!adapter->num_vfs)
9537 vmdctl &= ~IXGBE_VT_CTL_REPLEN;
9538 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9539
9540 /* disable Rx source address pruning, since we don't expect to
9541 * be receiving external loopback of our transmitted frames.
9542 */
9543 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9544 for (p = 0; p < num_pools; p++) {
9545 if (hw->mac.ops.set_source_address_pruning)
9546 hw->mac.ops.set_source_address_pruning(hw,
9547 false,
9548 p);
9549 }
Don Skidmore219efe92015-04-09 22:03:22 -07009550 break;
9551 default:
9552 return -EINVAL;
9553 }
9554
9555 adapter->bridge_mode = mode;
9556
9557 e_info(drv, "enabling bridge mode: %s\n",
9558 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
9559
9560 return 0;
9561}
9562
John Fastabend815cccb2012-10-24 08:13:09 +00009563static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
Roopa Prabhuadd511b2015-01-29 22:40:12 -08009564 struct nlmsghdr *nlh, u16 flags)
John Fastabend815cccb2012-10-24 08:13:09 +00009565{
9566 struct ixgbe_adapter *adapter = netdev_priv(dev);
9567 struct nlattr *attr, *br_spec;
9568 int rem;
9569
9570 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9571 return -EOPNOTSUPP;
9572
9573 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
Thomas Graf4ea85e82014-11-26 13:42:18 +01009574 if (!br_spec)
9575 return -EINVAL;
John Fastabend815cccb2012-10-24 08:13:09 +00009576
9577 nla_for_each_nested(attr, br_spec, rem) {
Mark Rustada1e869d2015-04-10 10:36:36 -07009578 int status;
John Fastabend815cccb2012-10-24 08:13:09 +00009579 __u16 mode;
John Fastabend815cccb2012-10-24 08:13:09 +00009580
9581 if (nla_type(attr) != IFLA_BRIDGE_MODE)
9582 continue;
9583
Thomas Grafb7c1a312014-11-26 13:42:17 +01009584 if (nla_len(attr) < sizeof(mode))
9585 return -EINVAL;
9586
John Fastabend815cccb2012-10-24 08:13:09 +00009587 mode = nla_get_u16(attr);
Don Skidmore219efe92015-04-09 22:03:22 -07009588 status = ixgbe_configure_bridge_mode(adapter, mode);
9589 if (status)
9590 return status;
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009591
9592 break;
John Fastabend815cccb2012-10-24 08:13:09 +00009593 }
9594
9595 return 0;
9596}
9597
9598static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00009599 struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02009600 u32 filter_mask, int nlflags)
John Fastabend815cccb2012-10-24 08:13:09 +00009601{
9602 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend815cccb2012-10-24 08:13:09 +00009603
9604 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9605 return 0;
9606
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009607 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
Scott Feldman7d4f8d82015-06-22 00:27:17 -07009608 adapter->bridge_mode, 0, 0, nlflags,
9609 filter_mask, NULL);
John Fastabend815cccb2012-10-24 08:13:09 +00009610}
9611
John Fastabend2a47fa42013-11-06 09:54:52 -08009612static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
9613{
9614 struct ixgbe_fwd_adapter *fwd_adapter = NULL;
9615 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009616 int used_pools = adapter->num_vfs + adapter->num_rx_pools;
John Fastabend51f37732013-11-08 00:51:10 -08009617 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08009618 int pool, err;
9619
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009620 /* Hardware has a limited number of available pools. Each VF, and the
9621 * PF require a pool. Check to ensure we don't attempt to use more
9622 * then the available number of pools.
9623 */
9624 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
9625 return ERR_PTR(-EINVAL);
9626
John Fastabend219354d2013-11-08 00:50:32 -08009627#ifdef CONFIG_RPS
9628 if (vdev->num_rx_queues != vdev->num_tx_queues) {
9629 netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
9630 vdev->name);
9631 return ERR_PTR(-EINVAL);
9632 }
9633#endif
John Fastabend2a47fa42013-11-06 09:54:52 -08009634 /* Check for hardware restriction on number of rx/tx queues */
John Fastabend219354d2013-11-08 00:50:32 -08009635 if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
John Fastabend2a47fa42013-11-06 09:54:52 -08009636 vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
9637 netdev_info(pdev,
9638 "%s: Supports RX/TX Queue counts 1,2, and 4\n",
9639 pdev->name);
9640 return ERR_PTR(-EINVAL);
9641 }
9642
9643 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
9644 adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
9645 (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
9646 return ERR_PTR(-EBUSY);
9647
Maninder Singhbc52f952015-06-19 09:37:55 +05309648 fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL);
John Fastabend2a47fa42013-11-06 09:54:52 -08009649 if (!fwd_adapter)
9650 return ERR_PTR(-ENOMEM);
9651
9652 pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
9653 adapter->num_rx_pools++;
9654 set_bit(pool, &adapter->fwd_bitmask);
John Fastabend51f37732013-11-08 00:51:10 -08009655 limit = find_last_bit(&adapter->fwd_bitmask, 32);
John Fastabend2a47fa42013-11-06 09:54:52 -08009656
9657 /* Enable VMDq flag so device will be set in VM mode */
9658 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
John Fastabend51f37732013-11-08 00:51:10 -08009659 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend219354d2013-11-08 00:50:32 -08009660 adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08009661
9662 /* Force reinit of ring allocation with VMDQ enabled */
9663 err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
9664 if (err)
9665 goto fwd_add_err;
9666 fwd_adapter->pool = pool;
9667 fwd_adapter->real_adapter = adapter;
Emil Tantilova3b8cb12016-09-22 15:06:52 -07009668
9669 if (netif_running(pdev)) {
9670 err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
9671 if (err)
9672 goto fwd_add_err;
9673 netif_tx_start_all_queues(vdev);
9674 }
9675
John Fastabend2a47fa42013-11-06 09:54:52 -08009676 return fwd_adapter;
9677fwd_add_err:
9678 /* unwind counter and free adapter struct */
9679 netdev_info(pdev,
9680 "%s: dfwd hardware acceleration failed\n", vdev->name);
9681 clear_bit(pool, &adapter->fwd_bitmask);
9682 adapter->num_rx_pools--;
9683 kfree(fwd_adapter);
9684 return ERR_PTR(err);
9685}
9686
9687static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
9688{
9689 struct ixgbe_fwd_adapter *fwd_adapter = priv;
9690 struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
John Fastabend51f37732013-11-08 00:51:10 -08009691 unsigned int limit;
John Fastabend2a47fa42013-11-06 09:54:52 -08009692
9693 clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
9694 adapter->num_rx_pools--;
9695
John Fastabend51f37732013-11-08 00:51:10 -08009696 limit = find_last_bit(&adapter->fwd_bitmask, 32);
9697 adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
John Fastabend2a47fa42013-11-06 09:54:52 -08009698 ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
9699 ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
9700 netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
9701 fwd_adapter->pool, adapter->num_rx_pools,
9702 fwd_adapter->rx_base_queue,
9703 fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
9704 adapter->fwd_bitmask);
9705 kfree(fwd_adapter);
9706}
9707
Alexander Duyckb83e3012016-04-14 17:19:31 -04009708#define IXGBE_MAX_MAC_HDR_LEN 127
9709#define IXGBE_MAX_NETWORK_HDR_LEN 511
9710
Mark Rustadf467bc02015-06-15 11:33:20 -07009711static netdev_features_t
9712ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
9713 netdev_features_t features)
9714{
Alexander Duyckb83e3012016-04-14 17:19:31 -04009715 unsigned int network_hdr_len, mac_hdr_len;
Mark Rustadf467bc02015-06-15 11:33:20 -07009716
Alexander Duyckb83e3012016-04-14 17:19:31 -04009717 /* Make certain the headers can be described by a context descriptor */
9718 mac_hdr_len = skb_network_header(skb) - skb->data;
9719 if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN))
9720 return features & ~(NETIF_F_HW_CSUM |
9721 NETIF_F_SCTP_CRC |
9722 NETIF_F_HW_VLAN_CTAG_TX |
9723 NETIF_F_TSO |
9724 NETIF_F_TSO6);
9725
9726 network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
9727 if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN))
9728 return features & ~(NETIF_F_HW_CSUM |
9729 NETIF_F_SCTP_CRC |
9730 NETIF_F_TSO |
9731 NETIF_F_TSO6);
9732
9733 /* We can only support IPV4 TSO in tunnels if we can mangle the
9734 * inner IP ID field, so strip TSO if MANGLEID is not supported.
9735 */
9736 if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID))
9737 features &= ~NETIF_F_TSO;
Mark Rustadf467bc02015-06-15 11:33:20 -07009738
9739 return features;
9740}
9741
John Fastabend92470802017-04-24 03:30:17 -07009742static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)
9743{
9744 int i, frame_size = dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
9745 struct ixgbe_adapter *adapter = netdev_priv(dev);
9746 struct bpf_prog *old_prog;
9747
9748 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
9749 return -EINVAL;
9750
9751 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
9752 return -EINVAL;
9753
9754 /* verify ixgbe ring attributes are sufficient for XDP */
9755 for (i = 0; i < adapter->num_rx_queues; i++) {
9756 struct ixgbe_ring *ring = adapter->rx_ring[i];
9757
9758 if (ring_is_rsc_enabled(ring))
9759 return -EINVAL;
9760
9761 if (frame_size > ixgbe_rx_bufsz(ring))
9762 return -EINVAL;
9763 }
9764
John Fastabend33fdc822017-04-24 03:30:18 -07009765 if (nr_cpu_ids > MAX_XDP_QUEUES)
9766 return -ENOMEM;
9767
John Fastabend92470802017-04-24 03:30:17 -07009768 old_prog = xchg(&adapter->xdp_prog, prog);
John Fastabend33fdc822017-04-24 03:30:18 -07009769
9770 /* If transitioning XDP modes reconfigure rings */
9771 if (!!prog != !!old_prog) {
9772 int err = ixgbe_setup_tc(dev, netdev_get_num_tc(dev));
9773
9774 if (err) {
9775 rcu_assign_pointer(adapter->xdp_prog, old_prog);
9776 return -EINVAL;
9777 }
9778 } else {
9779 for (i = 0; i < adapter->num_rx_queues; i++)
9780 xchg(&adapter->rx_ring[i]->xdp_prog, adapter->xdp_prog);
9781 }
John Fastabend92470802017-04-24 03:30:17 -07009782
9783 if (old_prog)
9784 bpf_prog_put(old_prog);
9785
9786 return 0;
9787}
9788
9789static int ixgbe_xdp(struct net_device *dev, struct netdev_xdp *xdp)
9790{
9791 struct ixgbe_adapter *adapter = netdev_priv(dev);
9792
9793 switch (xdp->command) {
9794 case XDP_SETUP_PROG:
9795 return ixgbe_xdp_setup(dev, xdp->prog);
9796 case XDP_QUERY_PROG:
9797 xdp->prog_attached = !!(adapter->xdp_prog);
9798 return 0;
9799 default:
9800 return -EINVAL;
9801 }
9802}
9803
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009804static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00009805 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009806 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08009807 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07009808 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00009809 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009810 .ndo_validate_addr = eth_validate_addr,
9811 .ndo_set_mac_address = ixgbe_set_mac,
9812 .ndo_change_mtu = ixgbe_change_mtu,
9813 .ndo_tx_timeout = ixgbe_tx_timeout,
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00009814 .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009815 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
9816 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00009817 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00009818 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
9819 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04009820 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00009821 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03009822 .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
Hiroshi Shimamoto54011e42015-08-28 06:58:33 +00009823 .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
Greg Rose7f016482010-05-04 22:12:06 +00009824 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00009825 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabende4c67342016-02-16 21:16:15 -08009826 .ndo_setup_tc = __ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009827#ifdef CONFIG_NET_POLL_CONTROLLER
9828 .ndo_poll_controller = ixgbe_netpoll,
9829#endif
Yi Zou332d4a72009-05-13 13:11:53 +00009830#ifdef IXGBE_FCOE
9831 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00009832 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00009833 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00009834 .ndo_fcoe_enable = ixgbe_fcoe_enable,
9835 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00009836 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00009837 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00009838#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00009839 .ndo_set_features = ixgbe_set_features,
9840 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009841 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +00009842 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
9843 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
John Fastabend2a47fa42013-11-06 09:54:52 -08009844 .ndo_dfwd_add_station = ixgbe_fwd_add,
9845 .ndo_dfwd_del_station = ixgbe_fwd_del,
Emil Tantilova21d0822016-08-10 11:19:23 -07009846 .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port,
9847 .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port,
Mark Rustadf467bc02015-06-15 11:33:20 -07009848 .ndo_features_check = ixgbe_features_check,
John Fastabend92470802017-04-24 03:30:17 -07009849 .ndo_xdp = ixgbe_xdp,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08009850};
9851
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07009852/**
Jacob Kellere027d1a2013-07-31 06:53:31 +00009853 * ixgbe_enumerate_functions - Get the number of ports this device has
9854 * @adapter: adapter structure
9855 *
9856 * This function enumerates the phsyical functions co-located on a single slot,
9857 * in order to determine how many ports a device has. This is most useful in
9858 * determining the required GT/s of PCIe bandwidth necessary for optimal
9859 * performance.
9860 **/
9861static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
9862{
Jacob Kellercaafb952014-07-19 07:17:17 +00009863 struct pci_dev *entry, *pdev = adapter->pdev;
Jacob Kellere027d1a2013-07-31 06:53:31 +00009864 int physfns = 0;
9865
Jacob Kellerf1f96572013-08-31 02:45:38 +00009866 /* Some cards can not use the generic count PCIe functions method,
9867 * because they are behind a parent switch, so we hardcode these with
9868 * the correct number of functions.
Jacob Kellere027d1a2013-07-31 06:53:31 +00009869 */
Jacob Keller88189702014-07-19 07:17:16 +00009870 if (ixgbe_pcie_from_parent(&adapter->hw))
Jacob Kellere027d1a2013-07-31 06:53:31 +00009871 physfns = 4;
Jacob Keller88189702014-07-19 07:17:16 +00009872
9873 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
9874 /* don't count virtual functions */
Jacob Kellercaafb952014-07-19 07:17:17 +00009875 if (entry->is_virtfn)
9876 continue;
9877
9878 /* When the devices on the bus don't all match our device ID,
9879 * we can't reliably determine the correct number of
9880 * functions. This can occur if a function has been direct
9881 * attached to a virtual machine using VT-d, for example. In
9882 * this case, simply return -1 to indicate this.
9883 */
9884 if ((entry->vendor != pdev->vendor) ||
9885 (entry->device != pdev->device))
9886 return -1;
9887
9888 physfns++;
Jacob Kellere027d1a2013-07-31 06:53:31 +00009889 }
9890
9891 return physfns;
9892}
9893
9894/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00009895 * ixgbe_wol_supported - Check whether device supports WoL
Emil Tantilov740234f2016-04-21 11:37:12 -07009896 * @adapter: the adapter private structure
Jacob Keller8e2813f2012-04-21 06:05:40 +00009897 * @device_id: the device ID
9898 * @subdev_id: the subsystem device ID
9899 *
9900 * This function is used by probe and ethtool to determine
9901 * which devices have WoL support
9902 *
9903 **/
Emil Tantilov740234f2016-04-21 11:37:12 -07009904bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
9905 u16 subdevice_id)
Jacob Keller8e2813f2012-04-21 06:05:40 +00009906{
9907 struct ixgbe_hw *hw = &adapter->hw;
9908 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009909
Emil Tantilov740234f2016-04-21 11:37:12 -07009910 /* WOL not supported on 82598 */
9911 if (hw->mac.type == ixgbe_mac_82598EB)
9912 return false;
9913
9914 /* check eeprom to see if WOL is enabled for X540 and newer */
9915 if (hw->mac.type >= ixgbe_mac_X540) {
9916 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
9917 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
9918 (hw->bus.func == 0)))
9919 return true;
9920 }
9921
9922 /* WOL is determined based on device IDs for 82599 MACs */
Jacob Keller8e2813f2012-04-21 06:05:40 +00009923 switch (device_id) {
9924 case IXGBE_DEV_ID_82599_SFP:
9925 /* Only these subdevices could supports WOL */
9926 switch (subdevice_id) {
9927 case IXGBE_SUBDEV_ID_82599_560FLR:
Emil Tantilov00103a6c2016-04-21 11:37:06 -07009928 case IXGBE_SUBDEV_ID_82599_LOM_SNAP6:
9929 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
9930 case IXGBE_SUBDEV_ID_82599_SFP_2OCP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009931 /* only support first port */
9932 if (hw->bus.func != 0)
9933 break;
Emil Tantilov5700ff22013-04-18 08:18:55 +00009934 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009935 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00009936 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00009937 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Emil Tantilov00103a6c2016-04-21 11:37:06 -07009938 case IXGBE_SUBDEV_ID_82599_SFP_1OCP:
9939 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1:
9940 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2:
Emil Tantilov740234f2016-04-21 11:37:12 -07009941 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009942 }
9943 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +00009944 case IXGBE_DEV_ID_82599EN_SFP:
Emil Tantilov740234f2016-04-21 11:37:12 -07009945 /* Only these subdevices support WOL */
Don Skidmore5daebbb2013-04-05 05:49:34 +00009946 switch (subdevice_id) {
9947 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
Emil Tantilov740234f2016-04-21 11:37:12 -07009948 return true;
Don Skidmore5daebbb2013-04-05 05:49:34 +00009949 }
9950 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009951 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
9952 /* All except this subdevice support WOL */
9953 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Emil Tantilov740234f2016-04-21 11:37:12 -07009954 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009955 break;
9956 case IXGBE_DEV_ID_82599_KX4:
Emil Tantilov740234f2016-04-21 11:37:12 -07009957 return true;
9958 default:
Jacob Keller8e2813f2012-04-21 06:05:40 +00009959 break;
9960 }
9961
Emil Tantilov740234f2016-04-21 11:37:12 -07009962 return false;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009963}
9964
9965/**
Auke Kok9a799d72007-09-15 14:07:45 -07009966 * ixgbe_probe - Device Initialization Routine
9967 * @pdev: PCI device information struct
9968 * @ent: entry in ixgbe_pci_tbl
9969 *
9970 * Returns 0 on success, negative on failure
9971 *
9972 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
9973 * The OS initialization, configuring of the adapter private structure,
9974 * and a hardware reset occur.
9975 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00009976static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07009977{
9978 struct net_device *netdev;
9979 struct ixgbe_adapter *adapter = NULL;
9980 struct ixgbe_hw *hw;
9981 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Jacob Kellere027d1a2013-07-31 06:53:31 +00009982 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00009983 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +00009984 u8 part_str[IXGBE_PBANUM_LENGTH];
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -08009985 bool disable_dev = false;
Yi Zoueacd73f2009-05-13 13:11:06 +00009986#ifdef IXGBE_FCOE
9987 u16 device_caps;
9988#endif
Don Skidmore289700db2010-12-03 03:32:58 +00009989 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07009990
Andy Gospodarekbded64a2010-07-21 06:40:31 +00009991 /* Catch broken hardware that put the wrong VF device ID in
9992 * the PCIe SR-IOV capability.
9993 */
9994 if (pdev->is_virtfn) {
9995 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
9996 pci_name(pdev), pdev->vendor, pdev->device);
9997 return -EINVAL;
9998 }
9999
gouji-new9ce77662009-05-06 10:44:45 +000010000 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010001 if (err)
10002 return err;
10003
Russell Kingf5f2eda2013-06-10 12:47:42 +010010004 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -070010005 pci_using_dac = 1;
10006 } else {
Russell Kingf5f2eda2013-06-10 12:47:42 +010010007 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -070010008 if (err) {
Russell Kingf5f2eda2013-06-10 12:47:42 +010010009 dev_err(&pdev->dev,
10010 "No usable DMA configuration, aborting\n");
10011 goto err_dma;
Auke Kok9a799d72007-09-15 14:07:45 -070010012 }
10013 pci_using_dac = 0;
10014 }
10015
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010016 err = pci_request_mem_regions(pdev, ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -070010017 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +000010018 dev_err(&pdev->dev,
10019 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -070010020 goto err_pci_reg;
10021 }
10022
Frans Pop19d5afd2009-10-02 10:04:12 -070010023 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010024
Auke Kok9a799d72007-09-15 14:07:45 -070010025 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -070010026 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010027
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010028 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +000010029#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010030 /* 8 TC w/ 4 queues per TC */
10031 indices = 4 * MAX_TRAFFIC_CLASS;
10032#else
10033 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +000010034#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010035 }
John Fastabende901acd2011-04-26 07:26:08 +000010036
John Fastabendc85a2612010-02-25 23:15:21 +000010037 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -070010038 if (!netdev) {
10039 err = -ENOMEM;
10040 goto err_alloc_etherdev;
10041 }
10042
Auke Kok9a799d72007-09-15 14:07:45 -070010043 SET_NETDEV_DEV(netdev, &pdev->dev);
10044
Auke Kok9a799d72007-09-15 14:07:45 -070010045 adapter = netdev_priv(netdev);
10046
10047 adapter->netdev = netdev;
10048 adapter->pdev = pdev;
10049 hw = &adapter->hw;
10050 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +000010051 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -070010052
Jeff Kirsher05857982008-09-11 19:57:00 -070010053 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +000010054 pci_resource_len(pdev, 0));
Mark Rustad2a1a0912014-01-14 18:53:15 -080010055 adapter->io_addr = hw->hw_addr;
Auke Kok9a799d72007-09-15 14:07:45 -070010056 if (!hw->hw_addr) {
10057 err = -EIO;
10058 goto err_ioremap;
10059 }
10060
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010061 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -070010062 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010063 netdev->watchdog_timeo = 5 * HZ;
Mark Rustad339de302014-06-06 01:57:06 +000010064 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kok9a799d72007-09-15 14:07:45 -070010065
Auke Kok9a799d72007-09-15 14:07:45 -070010066 /* Setup hw api */
Mark Rustad37689012016-01-07 10:13:03 -080010067 hw->mac.ops = *ii->mac_ops;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010068 hw->mac.type = ii->mac;
Don Skidmore9a900ec2015-06-09 17:15:01 -070010069 hw->mvals = ii->mvals;
Emil Tantilovb71f6c42016-10-10 14:54:03 -070010070 if (ii->link_ops)
10071 hw->link.ops = *ii->link_ops;
Auke Kok9a799d72007-09-15 14:07:45 -070010072
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010073 /* EEPROM */
Mark Rustad37689012016-01-07 10:13:03 -080010074 hw->eeprom.ops = *ii->eeprom_ops;
Don Skidmore9a900ec2015-06-09 17:15:01 -070010075 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Mark Rustad58cf6632014-03-12 00:38:40 +000010076 if (ixgbe_removed(hw->hw_addr)) {
10077 err = -EIO;
10078 goto err_ioremap;
10079 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010080 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
Jacob Kellerb4f47a42016-04-13 16:08:22 -070010081 if (!(eec & BIT(8)))
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010082 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
10083
10084 /* PHY */
Mark Rustad37689012016-01-07 10:13:03 -080010085 hw->phy.ops = *ii->phy_ops;
Donald Skidmorec4900be2008-11-20 21:11:42 -080010086 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +000010087 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
10088 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
10089 hw->phy.mdio.mmds = 0;
10090 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
10091 hw->phy.mdio.dev = netdev;
10092 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
10093 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -080010094
Auke Kok9a799d72007-09-15 14:07:45 -070010095 /* setup the private structure */
Emil Tantilov55570b62016-10-12 12:34:25 -070010096 err = ixgbe_sw_init(adapter, ii);
Auke Kok9a799d72007-09-15 14:07:45 -070010097 if (err)
10098 goto err_sw_init;
10099
Don Skidmoredbd15b82016-03-09 16:45:00 -050010100 /* Make sure the SWFW semaphore is in a valid state */
10101 if (hw->mac.ops.init_swfw_sync)
10102 hw->mac.ops.init_swfw_sync(hw);
10103
Don Skidmoree86bff02010-02-11 04:14:08 +000010104 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -080010105 switch (adapter->hw.mac.type) {
10106 case ixgbe_mac_82599EB:
10107 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +000010108 case ixgbe_mac_X550:
10109 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -070010110 case ixgbe_mac_x550em_a:
Don Skidmoree86bff02010-02-11 04:14:08 +000010111 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -080010112 break;
10113 default:
10114 break;
10115 }
Don Skidmoree86bff02010-02-11 04:14:08 +000010116
Don Skidmorebf069c92009-05-07 10:39:54 +000010117 /*
10118 * If there is a fan on this device and it has failed log the
10119 * failure.
10120 */
10121 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
10122 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
10123 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +000010124 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +000010125 }
10126
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +000010127 if (allow_unsupported_sfp)
10128 hw->allow_unsupported_sfp = allow_unsupported_sfp;
10129
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010130 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -070010131 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010132 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -070010133 hw->phy.reset_if_overtemp = false;
Mark Rustadb3eb4e12016-12-14 11:02:16 -080010134 ixgbe_set_eee_capable(adapter);
Mark Rustad29a8dca2015-08-08 16:17:46 -070010135 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
Don Skidmore8ca783a2009-05-26 20:40:47 -070010136 err = 0;
10137 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore1b1bf312013-07-31 05:27:04 +000010138 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
10139 e_dev_err("Reload the driver after installing a supported module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010140 goto err_sw_init;
10141 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010142 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010143 goto err_sw_init;
10144 }
10145
Alexander Duyck99d74482012-05-09 08:09:25 +000010146#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +000010147 /* SR-IOV not supported on the 82598 */
10148 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
10149 goto skip_sriov;
10150 /* Mailbox */
10151 ixgbe_init_mbx_params_pf(hw);
Mark Rustad37689012016-01-07 10:13:03 -080010152 hw->mbx.ops = ii->mbx_ops;
ethan.zhaodcc23e32014-01-16 19:41:04 -080010153 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
Emil Tantilov5c11f002017-01-20 14:11:56 -080010154 ixgbe_enable_sriov(adapter, max_vfs);
Greg Rose60a1a682012-12-11 08:26:33 +000010155skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010156
Alexander Duyck99d74482012-05-09 08:09:25 +000010157#endif
Emil Tantilov396e7992010-07-01 20:05:12 +000010158 netdev->features = NETIF_F_SG |
Don Skidmore082757a2011-07-21 05:55:00 +000010159 NETIF_F_TSO |
10160 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +000010161 NETIF_F_RXHASH |
Alexander Duyck49763de2016-01-13 07:31:11 -080010162 NETIF_F_RXCSUM |
Alexander Duyckb83e3012016-04-14 17:19:31 -040010163 NETIF_F_HW_CSUM;
10164
10165#define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
10166 NETIF_F_GSO_GRE_CSUM | \
Tom Herbert7e133182016-05-18 09:06:10 -070010167 NETIF_F_GSO_IPXIP4 | \
Alexander Duyckbf2d1df2016-05-18 10:44:53 -070010168 NETIF_F_GSO_IPXIP6 | \
Alexander Duyckb83e3012016-04-14 17:19:31 -040010169 NETIF_F_GSO_UDP_TUNNEL | \
10170 NETIF_F_GSO_UDP_TUNNEL_CSUM)
10171
10172 netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES;
10173 netdev->features |= NETIF_F_GSO_PARTIAL |
10174 IXGBE_GSO_PARTIAL_FEATURES;
Auke Kok9a799d72007-09-15 14:07:45 -070010175
Alexander Duyck49763de2016-01-13 07:31:11 -080010176 if (hw->mac.type >= ixgbe_mac_82599EB)
Tom Herbert53692b12015-12-14 11:19:41 -080010177 netdev->features |= NETIF_F_SCTP_CRC;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +000010178
Alexander Duyck49763de2016-01-13 07:31:11 -080010179 /* copy netdev features into list of user selectable features */
Alexander Duyckb83e3012016-04-14 17:19:31 -040010180 netdev->hw_features |= netdev->features |
Alexander Duyck3d951822016-08-12 09:53:39 -070010181 NETIF_F_HW_VLAN_CTAG_FILTER |
Alexander Duyckb83e3012016-04-14 17:19:31 -040010182 NETIF_F_HW_VLAN_CTAG_RX |
10183 NETIF_F_HW_VLAN_CTAG_TX |
10184 NETIF_F_RXALL |
Alexander Duyck49763de2016-01-13 07:31:11 -080010185 NETIF_F_HW_L2FW_DOFFLOAD;
10186
10187 if (hw->mac.type >= ixgbe_mac_82599EB)
10188 netdev->hw_features |= NETIF_F_NTUPLE |
10189 NETIF_F_HW_TC;
10190
Alexander Duyckb83e3012016-04-14 17:19:31 -040010191 if (pci_using_dac)
10192 netdev->features |= NETIF_F_HIGHDMA;
Jeff Kirsherad31c402008-06-05 04:05:30 -070010193
Alexander Duyck5eee87c2016-05-11 13:23:34 -070010194 netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
10195 netdev->hw_enc_features |= netdev->vlan_features;
Scott Peterson2a205252016-11-18 11:25:42 -080010196 netdev->mpls_features |= NETIF_F_SG |
10197 NETIF_F_TSO |
10198 NETIF_F_TSO6 |
10199 NETIF_F_HW_CSUM;
10200 netdev->mpls_features |= IXGBE_GSO_PARTIAL_FEATURES;
Alexander Duyck5eee87c2016-05-11 13:23:34 -070010201
Alexander Duyckb83e3012016-04-14 17:19:31 -040010202 /* set this bit last since it cannot be part of vlan_features */
10203 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
10204 NETIF_F_HW_VLAN_CTAG_RX |
10205 NETIF_F_HW_VLAN_CTAG_TX;
10206
Jiri Pirko01789342011-08-16 06:29:00 +000010207 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +000010208 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +000010209
Jarod Wilson91c527a2016-10-17 15:54:05 -040010210 /* MTU range: 68 - 9710 */
10211 netdev->min_mtu = ETH_MIN_MTU;
10212 netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
10213
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -080010214#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -070010215 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
Stephen Hemminger3f40c742016-11-21 09:52:40 -080010216 netdev->dcbnl_ops = &ixgbe_dcbnl_ops;
Alexander Duyck2f90b862008-11-20 20:52:10 -080010217#endif
10218
Yi Zoueacd73f2009-05-13 13:11:06 +000010219#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +000010220 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010221 unsigned int fcoe_l;
10222
Yi Zoueacd73f2009-05-13 13:11:06 +000010223 if (hw->mac.ops.get_device_caps) {
10224 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +000010225 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
10226 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +000010227 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010228
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010229
10230 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
10231 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010232
Alexander Duycka58915c2012-05-25 06:38:18 +000010233 netdev->features |= NETIF_F_FSO |
10234 NETIF_F_FCOE_CRC;
10235
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010236 netdev->vlan_features |= NETIF_F_FSO |
10237 NETIF_F_FCOE_CRC |
10238 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +000010239 }
Yi Zoueacd73f2009-05-13 13:11:06 +000010240#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -070010241
Don Skidmore082757a2011-07-21 05:55:00 +000010242 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
10243 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +000010244 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +000010245 netdev->features |= NETIF_F_LRO;
10246
Auke Kok9a799d72007-09-15 14:07:45 -070010247 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010248 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010249 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -070010250 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +000010251 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010252 }
10253
Sowmini Varadhanc7374b52016-01-12 19:32:30 -080010254 eth_platform_get_mac_address(&adapter->pdev->dev,
10255 adapter->hw.mac.perm_addr);
Martin K Petersenc762dff2014-11-15 14:24:51 +000010256
Auke Kok9a799d72007-09-15 14:07:45 -070010257 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -070010258
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +000010259 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010260 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -070010261 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +000010262 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010263 }
10264
Tushar Dave56768042016-01-07 14:17:03 -080010265 /* Set hw->mac.addr to permanent MAC address */
10266 ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
Alexander Duyckc9f53e62015-10-22 16:26:30 -070010267 ixgbe_mac_set_default_filter(adapter);
Jacob Keller5d7daa32014-03-29 06:51:25 +000010268
Alexander Duyck70864002011-04-27 09:13:56 +000010269 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +000010270 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010271
Mark Rustad58cf6632014-03-12 00:38:40 +000010272 if (ixgbe_removed(hw->hw_addr)) {
10273 err = -EIO;
10274 goto err_sw_init;
10275 }
Alexander Duyck70864002011-04-27 09:13:56 +000010276 INIT_WORK(&adapter->service_task, ixgbe_service_task);
Mark Rustad58cf6632014-03-12 00:38:40 +000010277 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +000010278 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010279
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010280 err = ixgbe_init_interrupt_scheme(adapter);
10281 if (err)
10282 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010283
Liwei Songb09457e2016-12-04 22:40:44 -050010284 for (i = 0; i < adapter->num_rx_queues; i++)
10285 u64_stats_init(&adapter->rx_ring[i]->syncp);
10286 for (i = 0; i < adapter->num_tx_queues; i++)
10287 u64_stats_init(&adapter->tx_ring[i]->syncp);
John Fastabend33fdc822017-04-24 03:30:18 -070010288 for (i = 0; i < adapter->num_xdp_queues; i++)
10289 u64_stats_init(&adapter->xdp_ring[i]->syncp);
10290
Jacob Keller8e2813f2012-04-21 06:05:40 +000010291 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +000010292 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010293 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +000010294 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +000010295 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +000010296 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +000010297 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +000010298
PJ Waskiewicze8e26352009-02-27 15:45:05 +000010299 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
10300
Emil Tantilov15e52092011-09-29 05:01:29 +000010301 /* save off EEPROM version number */
10302 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
10303 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
10304
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010305 /* pick up the PCI bus settings for reporting later */
Jacob Kellere027d1a2013-07-31 06:53:31 +000010306 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +000010307 ixgbe_get_parent_bus_info(adapter);
Don Skidmoref9328bc2015-06-18 13:24:06 -040010308 else
10309 hw->mac.ops.get_bus_info(hw);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010310
Jacob Kellere027d1a2013-07-31 06:53:31 +000010311 /* calculate the expected PCIe bandwidth required for optimal
10312 * performance. Note that some older parts will never have enough
10313 * bandwidth due to being older generation PCIe parts. We clamp these
10314 * parts to ensure no warning is displayed if it can't be fixed.
10315 */
10316 switch (hw->mac.type) {
10317 case ixgbe_mac_82598EB:
10318 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
10319 break;
10320 default:
10321 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
10322 break;
Auke Kok0c254d82008-02-11 09:25:56 -080010323 }
Jacob Kellercaafb952014-07-19 07:17:17 +000010324
10325 /* don't check link if we failed to enumerate functions */
10326 if (expected_gts > 0)
10327 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -080010328
Mark Rustad339de302014-06-06 01:57:06 +000010329 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +000010330 if (err)
Mark Rustad339de302014-06-06 01:57:06 +000010331 strlcpy(part_str, "Unknown", sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +000010332 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
10333 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
10334 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Jacob Kellere7cf7452014-04-09 06:03:10 +000010335 part_str);
Jacob Keller6a2aae52013-10-18 05:09:24 +000010336 else
10337 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
10338 hw->mac.type, hw->phy.type, part_str);
10339
10340 e_dev_info("%pM\n", netdev->dev_addr);
10341
Auke Kok9a799d72007-09-15 14:07:45 -070010342 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010343 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010344 if (err == IXGBE_ERR_EEPROM_VERSION) {
10345 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +000010346 e_dev_warn("This device is a pre-production adapter/LOM. "
10347 "Please be aware there may be issues associated "
10348 "with your hardware. If you are experiencing "
10349 "problems please contact your Intel or hardware "
10350 "representative who provided you with this "
10351 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010352 }
Auke Kok9a799d72007-09-15 14:07:45 -070010353 strcpy(netdev->name, "eth%d");
10354 err = register_netdev(netdev);
10355 if (err)
10356 goto err_register;
10357
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010358 pci_set_drvdata(pdev, adapter);
10359
Emil Tantilovec74a472012-09-20 03:33:56 +000010360 /* power down the optics for 82599 SFP+ fiber */
10361 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +000010362 hw->mac.ops.disable_tx_laser(hw);
10363
Jesse Brandeburg54386462009-04-17 20:44:27 +000010364 /* carrier off reporting is important to ethtool even BEFORE open */
10365 netif_carrier_off(netdev);
10366
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010367#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +030010368 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010369 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010370 ixgbe_setup_dca(adapter);
10371 }
10372#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010373 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010374 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010375 for (i = 0; i < adapter->num_vfs; i++)
10376 ixgbe_vf_configuration(pdev, (i | 0x10000000));
10377 }
10378
Jacob Keller2466dd92011-09-08 03:50:54 +000010379 /* firmware requires driver version to be 0xFFFFFFFF
10380 * since os does not support feature
10381 */
Emil Tantilov9612de92011-05-07 07:40:20 +000010382 if (hw->mac.ops.set_fw_drv_ver)
Tony Nguyencb8e0512016-10-26 16:25:18 -070010383 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF,
10384 sizeof(ixgbe_driver_version) - 1,
10385 ixgbe_driver_version);
Emil Tantilov9612de92011-05-07 07:40:20 +000010386
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010387 /* add san mac addr to netdev */
10388 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010389
Neerav Parikhea818752012-01-04 20:23:40 +000010390 e_dev_info("%s\n", ixgbe_default_device_descr);
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010391
Don Skidmore12109822012-05-04 06:07:08 +000010392#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010393 if (ixgbe_sysfs_init(adapter))
10394 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +000010395#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010396
Catherine Sullivan00949162012-08-10 01:59:10 +000010397 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010398
Emil Tantilovd1a35ee2014-05-13 08:24:00 +000010399 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
10400 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
Don Skidmore0b2679d2013-02-21 03:00:04 +000010401 hw->mac.ops.setup_link(hw,
10402 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
10403 true);
10404
Auke Kok9a799d72007-09-15 14:07:45 -070010405 return 0;
10406
10407err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010408 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +000010409 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010410err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +000010411 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +000010412 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Mark Rustad2a1a0912014-01-14 18:53:15 -080010413 iounmap(adapter->io_addr);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010414 kfree(adapter->jump_tables[0]);
Jacob Keller5d7daa32014-03-29 06:51:25 +000010415 kfree(adapter->mac_table);
Tony Nguyen3dfbfc72017-04-13 07:26:05 -070010416 kfree(adapter->rss_key);
Auke Kok9a799d72007-09-15 14:07:45 -070010417err_ioremap:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010418 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010419 free_netdev(netdev);
10420err_alloc_etherdev:
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010421 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010422err_pci_reg:
10423err_dma:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010424 if (!adapter || disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010425 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010426 return err;
10427}
10428
10429/**
10430 * ixgbe_remove - Device Removal Routine
10431 * @pdev: PCI device information struct
10432 *
10433 * ixgbe_remove is called by the PCI subsystem to alert the driver
10434 * that it should release a PCI device. The could be caused by a
10435 * Hot-Plug event, or because the driver is going to be removed from
10436 * memory.
10437 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010438static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -070010439{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010440 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010441 struct net_device *netdev;
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010442 bool disable_dev;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010443 int i;
Auke Kok9a799d72007-09-15 14:07:45 -070010444
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010445 /* if !adapter then we already cleaned up in probe */
10446 if (!adapter)
10447 return;
10448
10449 netdev = adapter->netdev;
Catherine Sullivan00949162012-08-10 01:59:10 +000010450 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010451
Mark Rustad09f40ae2014-01-14 18:53:11 -080010452 set_bit(__IXGBE_REMOVING, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +000010453 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -070010454
Jacob Keller3a6a4ed2012-05-01 05:24:58 +000010455
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010456#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010457 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
10458 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
10459 dca_remove_requester(&pdev->dev);
Mark Rustad9de76052015-08-08 16:27:41 -070010460 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
10461 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010462 }
10463
10464#endif
Don Skidmore12109822012-05-04 06:07:08 +000010465#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010466 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +000010467#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010468
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010469 /* remove the added san mac */
10470 ixgbe_del_sanmac_netdev(netdev);
10471
Greg Roseda36b642012-12-11 08:26:43 +000010472#ifdef CONFIG_PCI_IOV
Alex Williamson7837e282015-07-10 15:31:34 -060010473 ixgbe_disable_sriov(adapter);
Greg Roseda36b642012-12-11 08:26:43 +000010474#endif
Alex Williamson6b010e92015-07-29 14:38:21 -060010475 if (netdev->reg_state == NETREG_REGISTERED)
10476 unregister_netdev(netdev);
10477
Alexander Duyck7a921c92009-05-06 10:43:28 +000010478 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010479
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010480 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010481
Alexander Duyck2b1588c2012-03-17 02:39:16 +000010482#ifdef CONFIG_DCB
10483 kfree(adapter->ixgbe_ieee_pfc);
10484 kfree(adapter->ixgbe_ieee_ets);
10485
10486#endif
Mark Rustad2a1a0912014-01-14 18:53:15 -080010487 iounmap(adapter->io_addr);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010488 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010489
Emil Tantilov849c4542010-06-03 16:53:41 +000010490 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010491
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010492 for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) {
10493 if (adapter->jump_tables[i]) {
10494 kfree(adapter->jump_tables[i]->input);
10495 kfree(adapter->jump_tables[i]->mask);
10496 }
10497 kfree(adapter->jump_tables[i]);
10498 }
10499
Jacob Keller5d7daa32014-03-29 06:51:25 +000010500 kfree(adapter->mac_table);
Tony Nguyen3dfbfc72017-04-13 07:26:05 -070010501 kfree(adapter->rss_key);
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010502 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010503 free_netdev(netdev);
10504
Frans Pop19d5afd2009-10-02 10:04:12 -070010505 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010506
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010507 if (disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010508 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010509}
10510
10511/**
10512 * ixgbe_io_error_detected - called when PCI error is detected
10513 * @pdev: Pointer to PCI device
10514 * @state: The current pci connection state
10515 *
10516 * This function is called after a PCI bus error affecting
10517 * this device has been detected.
10518 */
10519static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +000010520 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -070010521{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010522 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10523 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010524
Greg Rose83c61fa2011-09-07 05:59:35 +000010525#ifdef CONFIG_PCI_IOV
Mark Rustad14438462014-02-28 15:48:57 -080010526 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose83c61fa2011-09-07 05:59:35 +000010527 struct pci_dev *bdev, *vfdev;
10528 u32 dw0, dw1, dw2, dw3;
10529 int vf, pos;
10530 u16 req_id, pf_func;
10531
10532 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
10533 adapter->num_vfs == 0)
10534 goto skip_bad_vf_detection;
10535
10536 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +080010537 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +000010538 bdev = bdev->bus->self;
10539
10540 if (!bdev)
10541 goto skip_bad_vf_detection;
10542
10543 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
10544 if (!pos)
10545 goto skip_bad_vf_detection;
10546
Mark Rustad14438462014-02-28 15:48:57 -080010547 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
10548 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
10549 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
10550 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
10551 if (ixgbe_removed(hw->hw_addr))
10552 goto skip_bad_vf_detection;
Greg Rose83c61fa2011-09-07 05:59:35 +000010553
10554 req_id = dw1 >> 16;
10555 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
10556 if (!(req_id & 0x0080))
10557 goto skip_bad_vf_detection;
10558
10559 pf_func = req_id & 0x01;
10560 if ((pf_func & 1) == (pdev->devfn & 1)) {
10561 unsigned int device_id;
10562
10563 vf = (req_id & 0x7F) >> 1;
10564 e_dev_err("VF %d has caused a PCIe error\n", vf);
10565 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
10566 "%8.8x\tdw3: %8.8x\n",
10567 dw0, dw1, dw2, dw3);
10568 switch (adapter->hw.mac.type) {
10569 case ixgbe_mac_82599EB:
10570 device_id = IXGBE_82599_VF_DEVICE_ID;
10571 break;
10572 case ixgbe_mac_X540:
10573 device_id = IXGBE_X540_VF_DEVICE_ID;
10574 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +000010575 case ixgbe_mac_X550:
10576 device_id = IXGBE_DEV_ID_X550_VF;
10577 break;
10578 case ixgbe_mac_X550EM_x:
10579 device_id = IXGBE_DEV_ID_X550EM_X_VF;
10580 break;
Mark Rustad49425df2016-04-01 12:18:09 -070010581 case ixgbe_mac_x550em_a:
10582 device_id = IXGBE_DEV_ID_X550EM_A_VF;
10583 break;
Greg Rose83c61fa2011-09-07 05:59:35 +000010584 default:
10585 device_id = 0;
10586 break;
10587 }
10588
10589 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +000010590 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +000010591 while (vfdev) {
10592 if (vfdev->devfn == (req_id & 0xFF))
10593 break;
Jon Mason36e90312012-07-19 21:02:09 +000010594 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +000010595 device_id, vfdev);
10596 }
10597 /*
10598 * There's a slim chance the VF could have been hot plugged,
10599 * so if it is no longer present we don't need to issue the
10600 * VFLR. Just clean up the AER in that case.
10601 */
10602 if (vfdev) {
Christoph Hellwig63af8f72017-04-14 21:11:28 +020010603 pcie_flr(vfdev);
Greg Roseb4fafbe2012-12-13 01:14:06 +000010604 /* Free device reference count */
10605 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +000010606 }
10607
10608 pci_cleanup_aer_uncorrect_error_status(pdev);
10609 }
10610
10611 /*
10612 * Even though the error may have occurred on the other port
10613 * we still need to increment the vf error reference count for
10614 * both ports because the I/O resume function will be called
10615 * for both of them.
10616 */
10617 adapter->vferr_refcount++;
10618
10619 return PCI_ERS_RESULT_RECOVERED;
10620
10621skip_bad_vf_detection:
10622#endif /* CONFIG_PCI_IOV */
Mark Rustad58cf6632014-03-12 00:38:40 +000010623 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
10624 return PCI_ERS_RESULT_DISCONNECT;
10625
Mark Rustad41c62842014-03-12 00:38:35 +000010626 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -070010627 netif_device_detach(netdev);
10628
Mark Rustad41c62842014-03-12 00:38:35 +000010629 if (state == pci_channel_io_perm_failure) {
10630 rtnl_unlock();
Breno Leitao3044b8d2009-05-06 10:44:26 +000010631 return PCI_ERS_RESULT_DISCONNECT;
Mark Rustad41c62842014-03-12 00:38:35 +000010632 }
Breno Leitao3044b8d2009-05-06 10:44:26 +000010633
Auke Kok9a799d72007-09-15 14:07:45 -070010634 if (netif_running(netdev))
Emil Tantilov126db132016-11-16 09:48:02 -080010635 ixgbe_close_suspend(adapter);
Mark Rustad41c62842014-03-12 00:38:35 +000010636
10637 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
10638 pci_disable_device(pdev);
10639 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010640
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070010641 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -070010642 return PCI_ERS_RESULT_NEED_RESET;
10643}
10644
10645/**
10646 * ixgbe_io_slot_reset - called after the pci bus has been reset.
10647 * @pdev: Pointer to PCI device
10648 *
10649 * Restart the card from scratch, as if from a cold-boot.
10650 */
10651static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
10652{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010653 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010654 pci_ers_result_t result;
10655 int err;
Auke Kok9a799d72007-09-15 14:07:45 -070010656
gouji-new9ce77662009-05-06 10:44:45 +000010657 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010658 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010659 result = PCI_ERS_RESULT_DISCONNECT;
10660 } else {
Peter Zijlstra4e857c52014-03-17 18:06:10 +010010661 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +000010662 clear_bit(__IXGBE_DISABLED, &adapter->state);
Mark Rustad0391bbe2014-02-28 15:48:55 -080010663 adapter->hw.hw_addr = adapter->io_addr;
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010664 pci_set_master(pdev);
10665 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +000010666 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010667
Don Skidmoredd4d8ca2009-04-29 00:22:31 -070010668 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010669
10670 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +000010671 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010672 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -070010673 }
Auke Kok9a799d72007-09-15 14:07:45 -070010674
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010675 err = pci_cleanup_aer_uncorrect_error_status(pdev);
10676 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010677 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
10678 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010679 /* non-fatal, continue */
10680 }
Auke Kok9a799d72007-09-15 14:07:45 -070010681
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010682 return result;
Auke Kok9a799d72007-09-15 14:07:45 -070010683}
10684
10685/**
10686 * ixgbe_io_resume - called when traffic can start flowing again.
10687 * @pdev: Pointer to PCI device
10688 *
10689 * This callback is called when the error recovery driver tells us that
10690 * its OK to resume normal operation.
10691 */
10692static void ixgbe_io_resume(struct pci_dev *pdev)
10693{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010694 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10695 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010696
Greg Rose83c61fa2011-09-07 05:59:35 +000010697#ifdef CONFIG_PCI_IOV
10698 if (adapter->vferr_refcount) {
10699 e_info(drv, "Resuming after VF err\n");
10700 adapter->vferr_refcount--;
10701 return;
10702 }
10703
10704#endif
Emil Tantilov126db132016-11-16 09:48:02 -080010705 rtnl_lock();
Alexander Duyckc7ccde02011-07-21 00:40:40 +000010706 if (netif_running(netdev))
Emil Tantilov126db132016-11-16 09:48:02 -080010707 ixgbe_open(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010708
10709 netif_device_attach(netdev);
Emil Tantilov126db132016-11-16 09:48:02 -080010710 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010711}
10712
Stephen Hemminger3646f0e2012-09-07 09:33:15 -070010713static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -070010714 .error_detected = ixgbe_io_error_detected,
10715 .slot_reset = ixgbe_io_slot_reset,
10716 .resume = ixgbe_io_resume,
10717};
10718
10719static struct pci_driver ixgbe_driver = {
10720 .name = ixgbe_driver_name,
10721 .id_table = ixgbe_pci_tbl,
10722 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010723 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -070010724#ifdef CONFIG_PM
10725 .suspend = ixgbe_suspend,
10726 .resume = ixgbe_resume,
10727#endif
10728 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +000010729 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -070010730 .err_handler = &ixgbe_err_handler
10731};
10732
10733/**
10734 * ixgbe_init_module - Driver Registration Routine
10735 *
10736 * ixgbe_init_module is the first routine called when the driver is
10737 * loaded. All it does is register with the PCI subsystem.
10738 **/
10739static int __init ixgbe_init_module(void)
10740{
10741 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +000010742 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +000010743 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -070010744
Mark Rustad780484d2015-10-21 17:21:10 -070010745 ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
10746 if (!ixgbe_wq) {
10747 pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
10748 return -ENOMEM;
10749 }
10750
Catherine Sullivan00949162012-08-10 01:59:10 +000010751 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +000010752
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010753 ret = pci_register_driver(&ixgbe_driver);
10754 if (ret) {
Wei Yongjun6b836872016-07-12 15:17:02 +000010755 destroy_workqueue(ixgbe_wq);
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010756 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010757 return ret;
10758 }
10759
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010760#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010761 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010762#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010763
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000010764 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -070010765}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070010766
Auke Kok9a799d72007-09-15 14:07:45 -070010767module_init(ixgbe_init_module);
10768
10769/**
10770 * ixgbe_exit_module - Driver Exit Cleanup Routine
10771 *
10772 * ixgbe_exit_module is called just before the driver is removed
10773 * from memory.
10774 **/
10775static void __exit ixgbe_exit_module(void)
10776{
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010777#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010778 dca_unregister_notify(&dca_notifier);
10779#endif
Auke Kok9a799d72007-09-15 14:07:45 -070010780 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +000010781
Catherine Sullivan00949162012-08-10 01:59:10 +000010782 ixgbe_dbg_exit();
Mark Rustad780484d2015-10-21 17:21:10 -070010783 if (ixgbe_wq) {
10784 destroy_workqueue(ixgbe_wq);
10785 ixgbe_wq = NULL;
10786 }
Auke Kok9a799d72007-09-15 14:07:45 -070010787}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010788
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010789#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010790static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +000010791 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010792{
10793 int ret_val;
10794
10795 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +000010796 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010797
10798 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
10799}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010800
Alexander Duyckb4533682009-03-31 21:32:42 +000010801#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +000010802
Auke Kok9a799d72007-09-15 14:07:45 -070010803module_exit(ixgbe_exit_module);
10804
10805/* ixgbe_main.c */